package kotlinx.coroutines.internal;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: loaded from: classes.dex */
public class i {

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

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

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

    public static abstract class a extends c {

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

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

        public a(i iVar) {
            this.f5158b = iVar;
        }

        @Override // kotlinx.coroutines.internal.c
        /* JADX INFO: renamed from: h, reason: merged with bridge method [inline-methods] */
        public void d(i iVar, Object obj) {
            boolean z2 = obj == null;
            i iVar2 = z2 ? this.f5158b : this.f5159c;
            if (iVar2 != null && androidx.concurrent.futures.a.a(i.f5155b, iVar, this, iVar2) && z2) {
                i iVar3 = this.f5158b;
                i iVar4 = this.f5159c;
                kotlin.jvm.internal.l.b(iVar4);
                iVar3.g(iVar4);
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:28:0x0048, code lost:
    
        if (androidx.concurrent.futures.a.a(kotlinx.coroutines.internal.i.f5155b, r3, r2, ((kotlinx.coroutines.internal.p) r4).f5172a) != 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.i e(kotlinx.coroutines.internal.o r8) {
        /*
            r7 = this;
        L0:
            java.lang.Object r0 = r7._prev
            kotlinx.coroutines.internal.i r0 = (kotlinx.coroutines.internal.i) 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.i.f5156g
            boolean r0 = androidx.concurrent.futures.a.a(r1, r7, r0, r2)
            if (r0 != 0) goto L17
            goto L0
        L17:
            return r2
        L18:
            boolean r5 = r7.k()
            if (r5 == 0) goto L1f
            return r1
        L1f:
            if (r4 != r8) goto L22
            return r2
        L22:
            boolean r5 = r4 instanceof kotlinx.coroutines.internal.o
            if (r5 == 0) goto L38
            if (r8 == 0) goto L32
            r0 = r4
            kotlinx.coroutines.internal.o r0 = (kotlinx.coroutines.internal.o) r0
            boolean r0 = r8.b(r0)
            if (r0 == 0) goto L32
            return r1
        L32:
            kotlinx.coroutines.internal.o r4 = (kotlinx.coroutines.internal.o) r4
            r4.c(r2)
            goto L0
        L38:
            boolean r5 = r4 instanceof kotlinx.coroutines.internal.p
            if (r5 == 0) goto L52
            if (r3 == 0) goto L4d
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r5 = kotlinx.coroutines.internal.i.f5155b
            kotlinx.coroutines.internal.p r4 = (kotlinx.coroutines.internal.p) r4
            kotlinx.coroutines.internal.i r4 = r4.f5172a
            boolean r2 = androidx.concurrent.futures.a.a(r5, 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.i r2 = (kotlinx.coroutines.internal.i) r2
            goto L7
        L52:
            r3 = r4
            kotlinx.coroutines.internal.i r3 = (kotlinx.coroutines.internal.i) r3
            r6 = r3
            r3 = r2
            r2 = r6
            goto L7
        */
        throw new UnsupportedOperationException("Method not decompiled: kotlinx.coroutines.internal.i.e(kotlinx.coroutines.internal.o):kotlinx.coroutines.internal.i");
    }

    private final i f(i iVar) {
        while (iVar.k()) {
            iVar = (i) iVar._prev;
        }
        return iVar;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void g(i iVar) {
        i iVar2;
        do {
            iVar2 = (i) iVar._prev;
            if (h() != iVar) {
                return;
            }
        } while (!androidx.concurrent.futures.a.a(f5156g, iVar, iVar2, this));
        if (k()) {
            iVar.e(null);
        }
    }

    private final p n() {
        p pVar = (p) this._removedRef;
        if (pVar != null) {
            return pVar;
        }
        p pVar2 = new p(this);
        f5157r.lazySet(this, pVar2);
        return pVar2;
    }

    public final boolean d(i iVar) {
        f5156g.lazySet(iVar, this);
        f5155b.lazySet(iVar, this);
        while (h() == this) {
            if (androidx.concurrent.futures.a.a(f5155b, this, this, iVar)) {
                iVar.g(this);
                return true;
            }
        }
        return false;
    }

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

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

    public final i j() {
        i iVarE = e(null);
        return iVarE == null ? f((i) this._prev) : iVarE;
    }

    public boolean k() {
        return h() instanceof p;
    }

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

    public final i m() {
        Object objH;
        i iVar;
        do {
            objH = h();
            if (objH instanceof p) {
                return ((p) objH).f5172a;
            }
            if (objH == this) {
                return (i) objH;
            }
            iVar = (i) objH;
        } while (!androidx.concurrent.futures.a.a(f5155b, this, objH, iVar.n()));
        iVar.e(null);
        return null;
    }

    public final int o(i iVar, i iVar2, a aVar) {
        f5156g.lazySet(iVar, this);
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f5155b;
        atomicReferenceFieldUpdater.lazySet(iVar, iVar2);
        aVar.f5159c = iVar2;
        if (androidx.concurrent.futures.a.a(atomicReferenceFieldUpdater, this, iVar2, 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();
    }
}
