package kotlinx.coroutines.o2;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: compiled from: LockFreeLinkedList.kt */
/* JADX INFO: loaded from: classes.dex */
public class j {
    static final /* synthetic */ AtomicReferenceFieldUpdater b = AtomicReferenceFieldUpdater.newUpdater(j.class, Object.class, "_next");

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static final /* synthetic */ AtomicReferenceFieldUpdater f1111f = AtomicReferenceFieldUpdater.newUpdater(j.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<j> {
        public final j b;

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

        public a(j jVar) {
            this.b = jVar;
        }

        @Override // kotlinx.coroutines.o2.c
        /* JADX INFO: renamed from: h, reason: merged with bridge method [inline-methods] */
        public void d(j jVar, Object obj) {
            boolean z = obj == null;
            j jVar2 = z ? this.b : this.f1112c;
            if (jVar2 != null && j.b.compareAndSet(jVar, this, jVar2) && z) {
                j jVar3 = this.b;
                j jVar4 = this.f1112c;
                h.x.d.k.b(jVar4);
                jVar3.h(jVar4);
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:28:0x0048, code lost:
    
        if (kotlinx.coroutines.o2.j.b.compareAndSet(r3, r2, ((kotlinx.coroutines.o2.n) r4).a) != false) goto L30;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private final kotlinx.coroutines.o2.j f(kotlinx.coroutines.o2.m r8) {
        /*
            r7 = this;
        L0:
            java.lang.Object r0 = r7._prev
            kotlinx.coroutines.o2.j r0 = (kotlinx.coroutines.o2.j) 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.o2.j.f1110e
            boolean r0 = r1.compareAndSet(r7, r0, r2)
            if (r0 != 0) goto L17
            goto L0
        L17:
            return r2
        L18:
            boolean r5 = r7.l()
            if (r5 == 0) goto L1f
            return r1
        L1f:
            if (r4 != r8) goto L22
            return r2
        L22:
            boolean r5 = r4 instanceof kotlinx.coroutines.o2.m
            if (r5 == 0) goto L38
            if (r8 == 0) goto L32
            r0 = r4
            kotlinx.coroutines.o2.m r0 = (kotlinx.coroutines.o2.m) r0
            boolean r0 = r8.b(r0)
            if (r0 == 0) goto L32
            return r1
        L32:
            kotlinx.coroutines.o2.m r4 = (kotlinx.coroutines.o2.m) r4
            r4.c(r2)
            goto L0
        L38:
            boolean r5 = r4 instanceof kotlinx.coroutines.o2.n
            if (r5 == 0) goto L52
            if (r3 == 0) goto L4d
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r5 = kotlinx.coroutines.o2.j.b
            kotlinx.coroutines.o2.n r4 = (kotlinx.coroutines.o2.n) r4
            kotlinx.coroutines.o2.j r4 = r4.a
            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.o2.j r2 = (kotlinx.coroutines.o2.j) r2
            goto L7
        L52:
            r3 = r4
            kotlinx.coroutines.o2.j r3 = (kotlinx.coroutines.o2.j) r3
            r6 = r3
            r3 = r2
            r2 = r6
            goto L7
        */
        throw new UnsupportedOperationException("Method not decompiled: kotlinx.coroutines.o2.j.f(kotlinx.coroutines.o2.m):kotlinx.coroutines.o2.j");
    }

    private final j g(j jVar) {
        while (jVar.l()) {
            jVar = (j) jVar._prev;
        }
        return jVar;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void h(j jVar) {
        j jVar2;
        do {
            jVar2 = (j) jVar._prev;
            if (i() != jVar) {
                return;
            }
        } while (!f1110e.compareAndSet(jVar, jVar2, this));
        if (l()) {
            jVar.f(null);
        }
    }

    private final n o() {
        n nVar = (n) this._removedRef;
        if (nVar != null) {
            return nVar;
        }
        n nVar2 = new n(this);
        f1111f.lazySet(this, nVar2);
        return nVar2;
    }

    public final boolean e(j jVar) {
        f1110e.lazySet(jVar, this);
        b.lazySet(jVar, this);
        while (i() == this) {
            if (b.compareAndSet(this, this, jVar)) {
                jVar.h(this);
                return true;
            }
        }
        return false;
    }

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

    public final j j() {
        return i.b(i());
    }

    public final j k() {
        j jVarF = f(null);
        return jVarF == null ? g((j) this._prev) : jVarF;
    }

    public boolean l() {
        return i() instanceof n;
    }

    public boolean m() {
        return n() == null;
    }

    public final j n() {
        Object objI;
        j jVar;
        do {
            objI = i();
            if (objI instanceof n) {
                return ((n) objI).a;
            }
            if (objI == this) {
                return (j) objI;
            }
            jVar = (j) objI;
        } while (!b.compareAndSet(this, objI, jVar.o()));
        jVar.f(null);
        return null;
    }

    public final int p(j jVar, j jVar2, a aVar) {
        f1110e.lazySet(jVar, this);
        b.lazySet(jVar, jVar2);
        aVar.f1112c = jVar2;
        if (b.compareAndSet(this, jVar2, aVar)) {
            return aVar.c(this) == null ? 1 : 2;
        }
        return 0;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append((Object) getClass().getSimpleName());
        sb.append('@');
        sb.append((Object) Integer.toHexString(System.identityHashCode(this)));
        return sb.toString();
    }
}
