package defpackage;

import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0005\b\u0016\u0018\u00002\u00020\u0001:\u0004\u0002\u0003\u0004\u0005¨\u0006\u0006"}, d2 = {"Lag5;", "", "c", "b", "d", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "ktor-utils"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public class ag5 {
    public static final /* synthetic */ AtomicReferenceFieldUpdater a = AtomicReferenceFieldUpdater.newUpdater(ag5.class, Object.class, "_next");
    public static final /* synthetic */ AtomicReferenceFieldUpdater b = AtomicReferenceFieldUpdater.newUpdater(ag5.class, Object.class, "_prev");
    public static final /* synthetic */ AtomicReferenceFieldUpdater c = AtomicReferenceFieldUpdater.newUpdater(ag5.class, Object.class, "removedRef");

    @kp6
    volatile /* synthetic */ Object _next = this;

    @kp6
    volatile /* synthetic */ Object _prev = this;

    @kp6
    private volatile /* synthetic */ Object removedRef = null;

    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b&\u0018\u00002\u00020\u0001:\u0001\u0002¨\u0006\u0003"}, d2 = {"Lag5$a;", "Lgw;", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "ktor-utils"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static abstract class a extends gw {

        /* JADX INFO: renamed from: ag5$a$a, reason: collision with other inner class name */
        @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0002\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Lag5$a$a;", "Lyw6;", "ktor-utils"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
        public static final class C0001a extends yw6 {
            @Override // defpackage.yw6
            public final Object a(ag5 ag5Var) {
                throw null;
            }
        }
    }

    @Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0016\u0018\u0000*\f\b\u0000\u0010\u0003*\u00060\u0001j\u0002`\u00022\u00020\u0004¨\u0006\u0005"}, d2 = {"Lag5$b;", "Lag5;", "Lio/ktor/util/internal/Node;", "T", "Lag5$a;", "ktor-utils"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static class b<T extends ag5> extends a {

        @kp6
        private volatile /* synthetic */ Object _affectedNode;

        static {
            AtomicReferenceFieldUpdater.newUpdater(b.class, Object.class, "_affectedNode");
        }
    }

    @Metadata(d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b!\u0018\u00002\f\u0012\b\u0012\u00060\u0002j\u0002`\u00030\u0001¨\u0006\u0004"}, d2 = {"Lag5$c;", "Lvw;", "Lag5;", "Lio/ktor/util/internal/Node;", "ktor-utils"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @wl7
    public static abstract class c extends vw<ag5> {
        @Override // defpackage.vw
        public final void b(ag5 ag5Var) {
        }
    }

    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0016\u0018\u0000*\u0004\b\u0000\u0010\u00012\u00020\u0002¨\u0006\u0003"}, d2 = {"Lag5$d;", "T", "Lag5$a;", "ktor-utils"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static class d<T> extends a {

        @kp6
        private volatile /* synthetic */ Object _affectedNode;

        @kp6
        private volatile /* synthetic */ Object _originalNext;

        static {
            AtomicReferenceFieldUpdater.newUpdater(d.class, Object.class, "_affectedNode");
            AtomicReferenceFieldUpdater.newUpdater(d.class, Object.class, "_originalNext");
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:13:0x0017, code lost:
    
        r7.e();
        r3 = defpackage.ag5.a;
        r2 = ((defpackage.ry7) r2).a;
     */
    /* JADX WARN: Code restructure failed: missing block: B:15:0x0024, code lost:
    
        if (r3.compareAndSet(r1, r7, r2) == false) goto L17;
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x002b, code lost:
    
        if (r3.get(r1) == r7) goto L58;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void b(ag5 ag5Var) {
        while (true) {
            ag5 ag5Var2 = null;
            while (true) {
                Object obj = ag5Var._next;
                if (obj == null) {
                    return;
                }
                if (obj instanceof yw6) {
                    ((yw6) obj).a(ag5Var);
                } else if (!(obj instanceof ry7)) {
                    Object obj2 = this._prev;
                    if (obj2 instanceof ry7) {
                        return;
                    }
                    if (obj != this) {
                        cr4.e(obj, "null cannot be cast to non-null type io.ktor.util.internal.LockFreeLinkedListNode");
                        ag5Var2 = ag5Var;
                        ag5Var = (ag5) obj;
                    } else {
                        if (obj2 == ag5Var) {
                            return;
                        }
                        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = b;
                        while (true) {
                            if (atomicReferenceFieldUpdater.compareAndSet(this, obj2, ag5Var)) {
                                if (!(ag5Var._prev instanceof ry7)) {
                                    return;
                                }
                            } else if (atomicReferenceFieldUpdater.get(this) != obj2) {
                                break;
                            }
                        }
                    }
                } else if (ag5Var2 != null) {
                    break;
                } else {
                    ag5Var = zf5.a(ag5Var._prev);
                }
            }
            ag5Var = ag5Var2;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:21:0x005b, code lost:
    
        r6.e();
        r3 = defpackage.ag5.a;
        r0 = ((defpackage.ry7) r0).a;
     */
    /* JADX WARN: Code restructure failed: missing block: B:23:0x0068, code lost:
    
        if (r3.compareAndSet(r8, r6, r0) == false) goto L25;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x006f, code lost:
    
        if (r3.get(r8) == r6) goto L66;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void c() {
        ag5 ag5VarA;
        while (true) {
            Object objD = d();
            if ((objD instanceof ry7) || objD == this) {
                return;
            }
            cr4.e(objD, "null cannot be cast to non-null type io.ktor.util.internal.LockFreeLinkedListNode");
            ag5 ag5Var = (ag5) objD;
            ry7 ry7Var = (ry7) ag5Var.removedRef;
            if (ry7Var == null) {
                ry7Var = new ry7(ag5Var);
                c.lazySet(ag5Var, ry7Var);
            }
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = a;
            while (!atomicReferenceFieldUpdater.compareAndSet(this, objD, ry7Var)) {
                if (atomicReferenceFieldUpdater.get(this) != objD) {
                    break;
                }
            }
            ag5 ag5VarE = e();
            Object obj = this._next;
            cr4.e(obj, "null cannot be cast to non-null type io.ktor.util.internal.Removed");
            ag5 ag5Var2 = ag5VarE;
            ag5 ag5Var3 = ((ry7) obj).a;
            loop2: while (true) {
                ag5 ag5Var4 = null;
                while (true) {
                    Object objD2 = ag5Var3.d();
                    if (objD2 instanceof ry7) {
                        ag5Var3.e();
                        ag5Var3 = ((ry7) objD2).a;
                    } else {
                        Object objD3 = ag5Var2.d();
                        if (!(objD3 instanceof ry7)) {
                            if (objD3 == this) {
                                AtomicReferenceFieldUpdater atomicReferenceFieldUpdater2 = a;
                                while (!atomicReferenceFieldUpdater2.compareAndSet(ag5Var2, this, ag5Var3)) {
                                    if (atomicReferenceFieldUpdater2.get(ag5Var2) != this) {
                                        break;
                                    }
                                }
                                break loop2;
                            }
                            cr4.e(objD3, "null cannot be cast to non-null type io.ktor.util.internal.LockFreeLinkedListNode");
                            ag5VarA = (ag5) objD3;
                            if (ag5VarA == ag5Var3) {
                                break loop2;
                            } else {
                                ag5Var4 = ag5Var2;
                            }
                        } else if (ag5Var4 != null) {
                            break;
                        } else {
                            ag5VarA = zf5.a(ag5Var2._prev);
                        }
                        ag5Var2 = ag5VarA;
                    }
                }
                ag5Var2 = ag5Var4;
            }
            ag5Var.b(zf5.a(this._prev));
            return;
        }
    }

    public final Object d() {
        while (true) {
            Object obj = this._next;
            if (!(obj instanceof yw6)) {
                return obj;
            }
            ((yw6) obj).a(this);
        }
    }

    public final ag5 e() {
        ag5 ag5VarA;
        while (true) {
            Object obj = this._prev;
            if (obj instanceof ry7) {
                return ((ry7) obj).a;
            }
            if (obj == this) {
                ag5VarA = this;
                while (!(ag5VarA instanceof xf5)) {
                    ag5VarA = zf5.a(ag5VarA.d());
                    if (ag5VarA == this) {
                        throw new IllegalStateException("Cannot loop to this while looking for list head");
                    }
                }
            } else {
                cr4.e(obj, "null cannot be cast to non-null type io.ktor.util.internal.LockFreeLinkedListNode");
                ag5VarA = (ag5) obj;
            }
            ry7 ry7Var = (ry7) ag5VarA.removedRef;
            if (ry7Var == null) {
                ry7Var = new ry7(ag5VarA);
                c.lazySet(ag5VarA, ry7Var);
            }
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = b;
            while (!atomicReferenceFieldUpdater.compareAndSet(this, obj, ry7Var)) {
                if (atomicReferenceFieldUpdater.get(this) != obj) {
                    break;
                }
            }
            return (ag5) obj;
        }
    }

    public final String toString() {
        return iw7.a.getOrCreateKotlinClass(getClass()).getSimpleName() + '@' + hashCode();
    }
}
