package kotlinx.coroutines.internal;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: compiled from: LockFreeLinkedList.kt */
/* JADX INFO: loaded from: classes.dex */
public class o {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    static final /* synthetic */ AtomicReferenceFieldUpdater f5219e = AtomicReferenceFieldUpdater.newUpdater(o.class, Object.class, "_next");

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    static final /* synthetic */ AtomicReferenceFieldUpdater f5220f = AtomicReferenceFieldUpdater.newUpdater(o.class, Object.class, "_prev");

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private static final /* synthetic */ AtomicReferenceFieldUpdater f5221g = AtomicReferenceFieldUpdater.newUpdater(o.class, Object.class, "_removedRef");
    volatile /* synthetic */ Object _next = this;
    volatile /* synthetic */ Object _prev = this;
    private volatile /* synthetic */ Object _removedRef = null;

    /* JADX INFO: compiled from: LockFreeLinkedList.kt */
    public static abstract class a extends c<o> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final o f5222b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public o f5223c;

        public a(o oVar) {
            this.f5222b = oVar;
        }

        @Override // kotlinx.coroutines.internal.c
        /* JADX INFO: renamed from: h, reason: merged with bridge method [inline-methods] */
        public void d(o oVar, Object obj) {
            boolean z2 = obj == null;
            o oVar2 = z2 ? this.f5222b : this.f5223c;
            if (oVar2 != null && o.f5219e.compareAndSet(oVar, this, oVar2) && z2) {
                o oVar3 = this.f5222b;
                o oVar4 = this.f5223c;
                w1.g.b(oVar4);
                oVar3.j(oVar4);
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:28:0x0048, code lost:
    
        if (kotlinx.coroutines.internal.o.f5219e.compareAndSet(r3, r2, ((kotlinx.coroutines.internal.x) r4).f5240a) != false) goto L30;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private final kotlinx.coroutines.internal.o h(kotlinx.coroutines.internal.w r8) {
        /*
            r7 = this;
        L0:
            java.lang.Object r0 = r7._prev
            kotlinx.coroutines.internal.o r0 = (kotlinx.coroutines.internal.o) r0
            r1 = 0
            r2 = r0
        L6:
            r3 = r1
        L7:
            java.lang.Object r4 = r2._next
            if (r4 != r7) goto L18
            if (r0 != r2) goto Le
            return r2
        Le:
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r1 = kotlinx.coroutines.internal.o.f5220f
            boolean r0 = r1.compareAndSet(r7, r0, r2)
            if (r0 != 0) goto L17
            goto L0
        L17:
            return r2
        L18:
            boolean r5 = r7.n()
            if (r5 == 0) goto L1f
            return r1
        L1f:
            if (r4 != r8) goto L22
            return r2
        L22:
            boolean r5 = r4 instanceof kotlinx.coroutines.internal.w
            if (r5 == 0) goto L38
            if (r8 == 0) goto L32
            r0 = r4
            kotlinx.coroutines.internal.w r0 = (kotlinx.coroutines.internal.w) r0
            boolean r0 = r8.b(r0)
            if (r0 == 0) goto L32
            return r1
        L32:
            kotlinx.coroutines.internal.w r4 = (kotlinx.coroutines.internal.w) r4
            r4.c(r2)
            goto L0
        L38:
            boolean r5 = r4 instanceof kotlinx.coroutines.internal.x
            if (r5 == 0) goto L52
            if (r3 == 0) goto L4d
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r5 = kotlinx.coroutines.internal.o.f5219e
            kotlinx.coroutines.internal.x r4 = (kotlinx.coroutines.internal.x) r4
            kotlinx.coroutines.internal.o r4 = r4.f5240a
            boolean r2 = r5.compareAndSet(r3, r2, r4)
            if (r2 != 0) goto L4b
            goto L0
        L4b:
            r2 = r3
            goto L6
        L4d:
            java.lang.Object r2 = r2._prev
            kotlinx.coroutines.internal.o r2 = (kotlinx.coroutines.internal.o) r2
            goto L7
        L52:
            r3 = r4
            kotlinx.coroutines.internal.o r3 = (kotlinx.coroutines.internal.o) r3
            r6 = r3
            r3 = r2
            r2 = r6
            goto L7
        */
        throw new UnsupportedOperationException("Method not decompiled: kotlinx.coroutines.internal.o.h(kotlinx.coroutines.internal.w):kotlinx.coroutines.internal.o");
    }

    private final o i(o oVar) {
        while (oVar.n()) {
            oVar = (o) oVar._prev;
        }
        return oVar;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void j(o oVar) {
        o oVar2;
        do {
            oVar2 = (o) oVar._prev;
            if (k() != oVar) {
                return;
            }
        } while (!f5220f.compareAndSet(oVar, oVar2, this));
        if (n()) {
            oVar.h(null);
        }
    }

    private final x q() {
        x xVar = (x) this._removedRef;
        if (xVar != null) {
            return xVar;
        }
        x xVar2 = new x(this);
        f5221g.lazySet(this, xVar2);
        return xVar2;
    }

    public final boolean g(o oVar) {
        f5220f.lazySet(oVar, this);
        f5219e.lazySet(oVar, this);
        while (k() == this) {
            if (f5219e.compareAndSet(this, this, oVar)) {
                oVar.j(this);
                return true;
            }
        }
        return false;
    }

    public final Object k() {
        while (true) {
            Object obj = this._next;
            if (!(obj instanceof w)) {
                return obj;
            }
            ((w) obj).c(this);
        }
    }

    public final o l() {
        return n.b(k());
    }

    public final o m() {
        o oVarH = h(null);
        return oVarH == null ? i((o) this._prev) : oVarH;
    }

    public boolean n() {
        return k() instanceof x;
    }

    public boolean o() {
        return p() == null;
    }

    public final o p() {
        Object objK;
        o oVar;
        do {
            objK = k();
            if (objK instanceof x) {
                return ((x) objK).f5240a;
            }
            if (objK == this) {
                return (o) objK;
            }
            oVar = (o) objK;
        } while (!f5219e.compareAndSet(this, objK, oVar.q()));
        oVar.h(null);
        return null;
    }

    public final int r(o oVar, o oVar2, a aVar) {
        f5220f.lazySet(oVar, this);
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f5219e;
        atomicReferenceFieldUpdater.lazySet(oVar, oVar2);
        aVar.f5223c = oVar2;
        if (atomicReferenceFieldUpdater.compareAndSet(this, oVar2, aVar)) {
            return aVar.c(this) == null ? 1 : 2;
        }
        return 0;
    }

    public String toString() {
        return new w1.k(this) { // from class: kotlinx.coroutines.internal.o.b
            @Override // a2.d
            public Object b() {
                return d2.d0.a(this.f5879f);
            }
        } + '@' + d2.d0.b(this);
    }
}
