package o;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.locks.LockSupport;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Pw, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public abstract class AbstractC0411Pw extends AbstractC0437Qw implements InterfaceC0405Pq {
    public static final /* synthetic */ AtomicReferenceFieldUpdater p = AtomicReferenceFieldUpdater.newUpdater(AbstractC0411Pw.class, Object.class, "_queue$volatile");
    public static final /* synthetic */ AtomicReferenceFieldUpdater q = AtomicReferenceFieldUpdater.newUpdater(AbstractC0411Pw.class, Object.class, "_delayed$volatile");
    public static final /* synthetic */ AtomicIntegerFieldUpdater r = AtomicIntegerFieldUpdater.newUpdater(AbstractC0411Pw.class, "_isCompleted$volatile");
    private volatile /* synthetic */ Object _delayed$volatile;
    private volatile /* synthetic */ int _isCompleted$volatile = 0;
    private volatile /* synthetic */ Object _queue$volatile;

    @Override // o.InterfaceC0405Pq
    public final void G(long j, C2448sg c2448sg) {
        long j2 = j > 0 ? j >= 9223372036854L ? Long.MAX_VALUE : 1000000 * j : 0L;
        if (j2 < 4611686018427387903L) {
            long jNanoTime = System.nanoTime();
            C0307Lw c0307Lw = new C0307Lw(this, j2 + jNanoTime, c2448sg);
            i0(jNanoTime, c0307Lw);
            c2448sg.x(new C1499ig(2, c0307Lw));
        }
    }

    @Override // o.AbstractC2842wn
    public final void T(InterfaceC2747vn interfaceC2747vn, Runnable runnable) {
        e0(runnable);
    }

    /* JADX WARN: Code restructure failed: missing block: B:8:0x0018, code lost:
    
        r7 = null;
     */
    @Override // o.AbstractC0437Qw
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final long b0() {
        /*
            r10 = this;
            o.xq r0 = o.IJ.c
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r1 = o.AbstractC0411Pw.p
            boolean r2 = r10.c0()
            r3 = 0
            if (r2 == 0) goto Le
            goto Lb4
        Le:
            r10.f0()
        L11:
            java.lang.Object r2 = r1.get(r10)
            r5 = 0
            if (r2 != 0) goto L1a
        L18:
            r7 = r5
            goto L4a
        L1a:
            boolean r6 = r2 instanceof o.C2992yM
            if (r6 == 0) goto L3e
            r6 = r2
            o.yM r6 = (o.C2992yM) r6
            java.lang.Object r7 = r6.d()
            o.xq r8 = o.C2992yM.g
            if (r7 == r8) goto L2c
            java.lang.Runnable r7 = (java.lang.Runnable) r7
            goto L4a
        L2c:
            o.yM r6 = r6.c()
        L30:
            boolean r5 = r1.compareAndSet(r10, r2, r6)
            if (r5 == 0) goto L37
            goto L11
        L37:
            java.lang.Object r5 = r1.get(r10)
            if (r5 == r2) goto L30
            goto L11
        L3e:
            if (r2 != r0) goto L41
            goto L18
        L41:
            boolean r6 = r1.compareAndSet(r10, r2, r5)
            if (r6 == 0) goto Lb9
            r7 = r2
            java.lang.Runnable r7 = (java.lang.Runnable) r7
        L4a:
            if (r7 == 0) goto L50
            r7.run()
            return r3
        L50:
            o.f9 r2 = r10.f305o
            r6 = 9223372036854775807(0x7fffffffffffffff, double:NaN)
            if (r2 != 0) goto L5b
        L59:
            r8 = r6
            goto L63
        L5b:
            boolean r2 = r2.isEmpty()
            if (r2 == 0) goto L62
            goto L59
        L62:
            r8 = r3
        L63:
            int r2 = (r8 > r3 ? 1 : (r8 == r3 ? 0 : -1))
            if (r2 != 0) goto L68
            goto Lb4
        L68:
            java.lang.Object r1 = r1.get(r10)
            if (r1 == 0) goto L90
            boolean r2 = r1 instanceof o.C2992yM
            if (r2 == 0) goto L8d
            o.yM r1 = (o.C2992yM) r1
            java.util.concurrent.atomic.AtomicLongFieldUpdater r0 = o.C2992yM.f
            long r0 = r0.get(r1)
            r8 = 1073741823(0x3fffffff, double:5.304989472E-315)
            long r8 = r8 & r0
            int r2 = (int) r8
            r8 = 1152921503533105152(0xfffffffc0000000, double:1.2882296003504729E-231)
            long r0 = r0 & r8
            r8 = 30
            long r0 = r0 >> r8
            int r0 = (int) r0
            if (r2 != r0) goto L8c
            goto L90
        L8c:
            return r3
        L8d:
            if (r1 != r0) goto Lb4
            goto Lb8
        L90:
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r0 = o.AbstractC0411Pw.q
            java.lang.Object r0 = r0.get(r10)
            o.Ow r0 = (o.C0385Ow) r0
            if (r0 == 0) goto Lb8
            monitor-enter(r0)
            o.Nw[] r1 = r0.a     // Catch: java.lang.Throwable -> La3
            if (r1 == 0) goto La5
            r2 = 0
            r5 = r1[r2]     // Catch: java.lang.Throwable -> La3
            goto La5
        La3:
            r1 = move-exception
            goto Lb6
        La5:
            monitor-exit(r0)
            if (r5 != 0) goto La9
            goto Lb8
        La9:
            long r0 = r5.l
            long r5 = java.lang.System.nanoTime()
            long r0 = r0 - r5
            int r2 = (r0 > r3 ? 1 : (r0 == r3 ? 0 : -1))
            if (r2 >= 0) goto Lb5
        Lb4:
            return r3
        Lb5:
            return r0
        Lb6:
            monitor-exit(r0)
            throw r1
        Lb8:
            return r6
        Lb9:
            java.lang.Object r6 = r1.get(r10)
            if (r6 == r2) goto L41
            goto L11
        */
        throw new UnsupportedOperationException("Method not decompiled: o.AbstractC0411Pw.b0():long");
    }

    public void e0(Runnable runnable) {
        f0();
        if (!g0(runnable)) {
            RunnableC0534Up.s.e0(runnable);
            return;
        }
        Thread threadZ = Z();
        if (Thread.currentThread() != threadZ) {
            LockSupport.unpark(threadZ);
        }
    }

    public final void f0() {
        AbstractRunnableC0359Nw abstractRunnableC0359NwB;
        C0385Ow c0385Ow = (C0385Ow) q.get(this);
        if (c0385Ow == null || C1878mf0.b.get(c0385Ow) == 0) {
            return;
        }
        long jNanoTime = System.nanoTime();
        do {
            synchronized (c0385Ow) {
                try {
                    AbstractRunnableC0359Nw[] abstractRunnableC0359NwArr = c0385Ow.a;
                    AbstractRunnableC0359Nw abstractRunnableC0359Nw = abstractRunnableC0359NwArr != null ? abstractRunnableC0359NwArr[0] : null;
                    if (abstractRunnableC0359Nw != null) {
                        abstractRunnableC0359NwB = ((jNanoTime - abstractRunnableC0359Nw.l) > 0L ? 1 : ((jNanoTime - abstractRunnableC0359Nw.l) == 0L ? 0 : -1)) >= 0 ? g0(abstractRunnableC0359Nw) : false ? c0385Ow.b(0) : null;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        } while (abstractRunnableC0359NwB != null);
    }

    /* JADX WARN: Code restructure failed: missing block: B:30:0x004b, code lost:
    
        return false;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean g0(java.lang.Runnable r7) {
        /*
            r6 = this;
        L0:
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r0 = o.AbstractC0411Pw.p
            java.lang.Object r1 = r0.get(r6)
            java.util.concurrent.atomic.AtomicIntegerFieldUpdater r2 = o.AbstractC0411Pw.r
            int r2 = r2.get(r6)
            r3 = 0
            if (r2 == 0) goto L10
            return r3
        L10:
            r2 = 1
            if (r1 != 0) goto L22
        L13:
            r1 = 0
            boolean r1 = r0.compareAndSet(r6, r1, r7)
            if (r1 == 0) goto L1b
            goto L62
        L1b:
            java.lang.Object r1 = r0.get(r6)
            if (r1 == 0) goto L13
            goto L0
        L22:
            boolean r4 = r1 instanceof o.C2992yM
            if (r4 == 0) goto L47
            r4 = r1
            o.yM r4 = (o.C2992yM) r4
            int r5 = r4.a(r7)
            if (r5 == 0) goto L62
            if (r5 == r2) goto L35
            r0 = 2
            if (r5 == r0) goto L4b
            goto L0
        L35:
            o.yM r3 = r4.c()
        L39:
            boolean r2 = r0.compareAndSet(r6, r1, r3)
            if (r2 == 0) goto L40
            goto L0
        L40:
            java.lang.Object r2 = r0.get(r6)
            if (r2 == r1) goto L39
            goto L0
        L47:
            o.xq r4 = o.IJ.c
            if (r1 != r4) goto L4c
        L4b:
            return r3
        L4c:
            o.yM r3 = new o.yM
            r4 = 8
            r3.<init>(r4, r2)
            r4 = r1
            java.lang.Runnable r4 = (java.lang.Runnable) r4
            r3.a(r4)
            r3.a(r7)
        L5c:
            boolean r4 = r0.compareAndSet(r6, r1, r3)
            if (r4 == 0) goto L63
        L62:
            return r2
        L63:
            java.lang.Object r4 = r0.get(r6)
            if (r4 == r1) goto L5c
            goto L0
        */
        throw new UnsupportedOperationException("Method not decompiled: o.AbstractC0411Pw.g0(java.lang.Runnable):boolean");
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0027  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean h0() {
        /*
            r7 = this;
            o.f9 r0 = r7.f305o
            r1 = 1
            if (r0 == 0) goto La
            boolean r0 = r0.isEmpty()
            goto Lb
        La:
            r0 = r1
        Lb:
            r2 = 0
            if (r0 != 0) goto Lf
            goto L54
        Lf:
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r0 = o.AbstractC0411Pw.q
            java.lang.Object r0 = r0.get(r7)
            o.Ow r0 = (o.C0385Ow) r0
            if (r0 == 0) goto L27
            java.util.concurrent.atomic.AtomicIntegerFieldUpdater r3 = o.C1878mf0.b
            int r0 = r3.get(r0)
            if (r0 != 0) goto L23
            r0 = r1
            goto L24
        L23:
            r0 = r2
        L24:
            if (r0 != 0) goto L27
            goto L54
        L27:
            java.util.concurrent.atomic.AtomicReferenceFieldUpdater r0 = o.AbstractC0411Pw.p
            java.lang.Object r0 = r0.get(r7)
            if (r0 != 0) goto L30
            goto L53
        L30:
            boolean r3 = r0 instanceof o.C2992yM
            if (r3 == 0) goto L4f
            o.yM r0 = (o.C2992yM) r0
            java.util.concurrent.atomic.AtomicLongFieldUpdater r3 = o.C2992yM.f
            long r3 = r3.get(r0)
            r5 = 1073741823(0x3fffffff, double:5.304989472E-315)
            long r5 = r5 & r3
            int r0 = (int) r5
            r5 = 1152921503533105152(0xfffffffc0000000, double:1.2882296003504729E-231)
            long r3 = r3 & r5
            r5 = 30
            long r3 = r3 >> r5
            int r3 = (int) r3
            if (r0 != r3) goto L4e
            return r1
        L4e:
            return r2
        L4f:
            o.xq r3 = o.IJ.c
            if (r0 != r3) goto L54
        L53:
            return r1
        L54:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: o.AbstractC0411Pw.h0():boolean");
    }

    public final void i0(long j, AbstractRunnableC0359Nw abstractRunnableC0359Nw) {
        int iB;
        Thread threadZ;
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = q;
        if (r.get(this) != 0) {
            iB = 1;
        } else {
            C0385Ow c0385Ow = (C0385Ow) atomicReferenceFieldUpdater.get(this);
            if (c0385Ow == null) {
                C0385Ow c0385Ow2 = new C0385Ow();
                c0385Ow2.c = j;
                while (!atomicReferenceFieldUpdater.compareAndSet(this, null, c0385Ow2) && atomicReferenceFieldUpdater.get(this) == null) {
                }
                c0385Ow = (C0385Ow) atomicReferenceFieldUpdater.get(this);
            }
            iB = abstractRunnableC0359Nw.b(j, c0385Ow, this);
        }
        if (iB != 0) {
            if (iB == 1) {
                d0(j, abstractRunnableC0359Nw);
                return;
            } else {
                if (iB != 2) {
                    throw new IllegalStateException("unexpected result");
                }
                return;
            }
        }
        C0385Ow c0385Ow3 = (C0385Ow) atomicReferenceFieldUpdater.get(this);
        if (c0385Ow3 != null) {
            synchronized (c0385Ow3) {
                AbstractRunnableC0359Nw[] abstractRunnableC0359NwArr = c0385Ow3.a;
                abstractRunnableC0359Nw = abstractRunnableC0359NwArr != null ? abstractRunnableC0359NwArr[0] : null;
            }
        }
        if (abstractRunnableC0359Nw != abstractRunnableC0359Nw || Thread.currentThread() == (threadZ = Z())) {
            return;
        }
        LockSupport.unpark(threadZ);
    }

    @Override // o.AbstractC0437Qw
    public void shutdown() {
        AbstractRunnableC0359Nw abstractRunnableC0359NwB;
        AbstractC1688kf0.a.set(null);
        r.set(this, 1);
        C2943xq c2943xq = IJ.c;
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = p;
        loop0: while (true) {
            Object obj = atomicReferenceFieldUpdater.get(this);
            if (obj != null) {
                if (!(obj instanceof C2992yM)) {
                    if (obj != c2943xq) {
                        C2992yM c2992yM = new C2992yM(8, true);
                        c2992yM.a((Runnable) obj);
                        while (!atomicReferenceFieldUpdater.compareAndSet(this, obj, c2992yM)) {
                            if (atomicReferenceFieldUpdater.get(this) != obj) {
                                break;
                            }
                        }
                        break loop0;
                    }
                    break;
                }
                ((C2992yM) obj).b();
                break;
            }
            while (!atomicReferenceFieldUpdater.compareAndSet(this, null, c2943xq)) {
                if (atomicReferenceFieldUpdater.get(this) != null) {
                    break;
                }
            }
            break loop0;
        }
        while (b0() <= 0) {
        }
        long jNanoTime = System.nanoTime();
        while (true) {
            C0385Ow c0385Ow = (C0385Ow) q.get(this);
            if (c0385Ow == null) {
                return;
            }
            synchronized (c0385Ow) {
                abstractRunnableC0359NwB = C1878mf0.b.get(c0385Ow) > 0 ? c0385Ow.b(0) : null;
            }
            if (abstractRunnableC0359NwB == null) {
                return;
            } else {
                d0(jNanoTime, abstractRunnableC0359NwB);
            }
        }
    }

    @Override // o.InterfaceC0405Pq
    public InterfaceC2567ts u(long j, Ef0 ef0, InterfaceC2747vn interfaceC2747vn) {
        return AbstractC0560Vp.a.u(j, ef0, interfaceC2747vn);
    }
}
