package X4;

import I2.C0317a;
import V4.C0772m;
import V4.E;
import V4.N0;
import a.AbstractC0872a;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import m3.AbstractC2467b;

/* JADX INFO: loaded from: classes3.dex */
public final class b implements N0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Object f8644a = g.f8677p;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public C0772m f8645b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ e f8646c;

    public b(e eVar) {
        this.f8646c = eVar;
    }

    @Override // V4.N0
    public final void a(a5.q qVar, int i6) {
        C0772m c0772m = this.f8645b;
        if (c0772m != null) {
            c0772m.a(qVar, i6);
        }
    }

    public final Object b(C4.c cVar) throws Throwable {
        m mVarN;
        Boolean bool;
        Object obj = this.f8644a;
        boolean z6 = true;
        if (obj == g.f8677p || obj == g.l) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = e.f8658j;
            e eVar = this.f8646c;
            m mVar = (m) atomicReferenceFieldUpdater.get(eVar);
            while (true) {
                if (eVar.u()) {
                    this.f8644a = g.l;
                    Throwable thO = eVar.o();
                    if (thO != null) {
                        int i6 = a5.r.f10850a;
                        throw thO;
                    }
                    z6 = false;
                } else {
                    long andIncrement = e.f8654c.getAndIncrement(eVar);
                    long j4 = g.f8664b;
                    long j6 = andIncrement / j4;
                    int i7 = (int) (andIncrement % j4);
                    if (mVar.f10849c != j6) {
                        mVarN = eVar.n(j6, mVar);
                        if (mVarN == null) {
                            continue;
                        }
                    } else {
                        mVarN = mVar;
                    }
                    Object objF = eVar.F(mVarN, i7, andIncrement, null);
                    C0317a c0317a = g.f8674m;
                    if (objF == c0317a) {
                        throw new IllegalStateException("unreachable");
                    }
                    C0317a c0317a2 = g.f8676o;
                    if (objF == c0317a2) {
                        if (andIncrement < eVar.r()) {
                            mVarN.b();
                        }
                        mVar = mVarN;
                    } else {
                        if (objF == g.f8675n) {
                            e eVar2 = this.f8646c;
                            C0772m c0772mR = E.r(AbstractC0872a.V(cVar));
                            try {
                                this.f8645b = c0772mR;
                                Object objF2 = eVar2.F(mVarN, i7, andIncrement, this);
                                if (objF2 == c0317a) {
                                    a(mVarN, i7);
                                } else {
                                    if (objF2 == c0317a2) {
                                        if (andIncrement < eVar2.r()) {
                                            mVarN.b();
                                        }
                                        m mVar2 = (m) e.f8658j.get(eVar2);
                                        while (true) {
                                            if (eVar2.u()) {
                                                C0772m c0772m = this.f8645b;
                                                kotlin.jvm.internal.o.e(c0772m);
                                                this.f8645b = null;
                                                this.f8644a = g.l;
                                                Throwable thO2 = eVar.o();
                                                if (thO2 == null) {
                                                    c0772m.resumeWith(Boolean.FALSE);
                                                } else {
                                                    c0772m.resumeWith(AbstractC2467b.d(thO2));
                                                }
                                            } else {
                                                long andIncrement2 = e.f8654c.getAndIncrement(eVar2);
                                                long j7 = g.f8664b;
                                                long j8 = andIncrement2 / j7;
                                                int i8 = (int) (andIncrement2 % j7);
                                                if (mVar2.f10849c != j8) {
                                                    m mVarN2 = eVar2.n(j8, mVar2);
                                                    if (mVarN2 != null) {
                                                        mVar2 = mVarN2;
                                                    }
                                                }
                                                Object objF3 = eVar2.F(mVar2, i8, andIncrement2, this);
                                                if (objF3 == g.f8674m) {
                                                    a(mVar2, i8);
                                                    break;
                                                }
                                                if (objF3 == g.f8676o) {
                                                    if (andIncrement2 < eVar2.r()) {
                                                        mVar2.b();
                                                    }
                                                } else {
                                                    if (objF3 == g.f8675n) {
                                                        throw new IllegalStateException("unexpected");
                                                    }
                                                    mVar2.b();
                                                    this.f8644a = objF3;
                                                    this.f8645b = null;
                                                    bool = Boolean.TRUE;
                                                }
                                            }
                                        }
                                    } else {
                                        mVarN.b();
                                        this.f8644a = objF2;
                                        this.f8645b = null;
                                        bool = Boolean.TRUE;
                                    }
                                    c0772mR.k(bool, null);
                                }
                                Object objR = c0772mR.r();
                                B4.a aVar = B4.a.f492a;
                                return objR;
                            } catch (Throwable th) {
                                c0772mR.z();
                                throw th;
                            }
                        }
                        mVarN.b();
                        this.f8644a = objF;
                    }
                }
            }
        }
        return Boolean.valueOf(z6);
    }

    public final Object c() throws Throwable {
        Object obj = this.f8644a;
        C0317a c0317a = g.f8677p;
        if (obj == c0317a) {
            throw new IllegalStateException("`hasNext()` has not been invoked");
        }
        this.f8644a = c0317a;
        if (obj != g.l) {
            return obj;
        }
        Throwable thP = this.f8646c.p();
        int i6 = a5.r.f10850a;
        throw thP;
    }
}
