package E1;

import Z6.B0;
import Z6.C0375o;
import Z6.C0377q;
import android.os.Bundle;
import b7.AbstractC0558h;
import b7.C0556f;
import b7.C0561k;
import b7.C0562l;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import n4.u0;

/* JADX INFO: renamed from: E1.o, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0108o extends P6.h implements O6.l {

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final /* synthetic */ int f2111r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final /* synthetic */ Object f2112s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final /* synthetic */ Object f2113t;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ C0108o(Object obj, int i, Object obj2) {
        super(1);
        this.f2111r = i;
        this.f2112s = obj;
        this.f2113t = obj2;
    }

    /* JADX WARN: Removed duplicated region for block: B:120:0x00f2 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:123:0x009b A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00b0  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00ce  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00d1  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00ef  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x00f3 A[LOOP:0: B:5:0x0021->B:53:0x00f3, LOOP_END] */
    @Override // O6.l
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object b(Object obj) throws Throwable {
        S s8;
        Bundle bundle;
        A aC;
        Object c0561k;
        Throwable th;
        Object objC;
        A6.n nVar;
        A6.n nVar2 = A6.n.f457a;
        boolean z8 = true;
        Object obj2 = this.f2113t;
        Object obj3 = this.f2112s;
        switch (this.f2111r) {
            case u0.f15495q /* 0 */:
                I i = (I) obj;
                P6.g.e(i, "$this$navOptions");
                A7.a aVar = i.f2033a;
                aVar.f460a = 0;
                aVar.f461b = 0;
                A a3 = (A) obj3;
                if (a3 instanceof D) {
                    int i5 = A.f1977z;
                    Iterator it = W6.j.H(a3, C0096c.f2068w).iterator();
                    while (true) {
                        F f3 = (F) obj2;
                        if (it.hasNext()) {
                            A a8 = (A) it.next();
                            A aE = f3.e();
                            if (P6.g.a(a8, aE != null ? aE.f1979r : null)) {
                            }
                        } else {
                            int i8 = D.D;
                            D d8 = f3.f1999c;
                            if (d8 == null) {
                                throw new IllegalStateException("You must call setGraph() before calling getGraph()");
                            }
                            Iterator it2 = W6.j.H(d8.i(d8.f1991B, true), C0096c.f2069x).iterator();
                            if (!it2.hasNext()) {
                                throw new NoSuchElementException("Sequence is empty.");
                            }
                            Object next = it2.next();
                            while (it2.hasNext()) {
                                next = it2.next();
                            }
                            i.f2035c = ((A) next).f1985x;
                            i.f2036d = true;
                        }
                    }
                }
                return nVar2;
            case 1:
                C0103j c0103j = (C0103j) obj;
                P6.g.e(c0103j, "backStackEntry");
                A a9 = c0103j.f2087r;
                if (!(a9 != null)) {
                    a9 = null;
                }
                if (a9 == null || (aC = (s8 = (S) obj3).c(a9, (bundle = c0103j.f2088s), (H) obj2)) == null) {
                    return null;
                }
                if (aC.equals(a9)) {
                    return c0103j;
                }
                C0107n c0107nB = s8.b();
                Bundle bundleB = aC.b(bundle);
                F f7 = c0107nB.f2110h;
                return x3.e.o(f7.f1997a, aC, bundleB, f7.f(), f7.f2010o);
            case 2:
                Throwable th2 = (Throwable) obj;
                s.i iVar = (s.i) obj3;
                if (th2 == null) {
                    Object objD = ((Z6.D) obj2).D();
                    iVar.f16735d = true;
                    s.k kVar = iVar.f16733b;
                    if (kVar != null && kVar.f16738r.j(objD)) {
                        iVar.f16732a = null;
                        iVar.f16733b = null;
                        iVar.f16734c = null;
                    }
                } else if (th2 instanceof CancellationException) {
                    iVar.f16735d = true;
                    s.k kVar2 = iVar.f16733b;
                    if (kVar2 != null && kVar2.f16738r.cancel(true)) {
                        iVar.f16732a = null;
                        iVar.f16733b = null;
                        iVar.f16734c = null;
                    }
                } else {
                    iVar.f16735d = true;
                    s.k kVar3 = iVar.f16733b;
                    if (kVar3 != null && kVar3.f16738r.k(th2)) {
                        iVar.f16732a = null;
                        iVar.f16733b = null;
                        iVar.f16734c = null;
                    }
                }
                return nVar2;
            default:
                Throwable th3 = (Throwable) obj;
                ((C0111s) obj3).b(th3);
                C2.a aVar2 = (C2.a) obj2;
                ((C0556f) aVar2.f1159t).g(th3, false);
                while (true) {
                    C0556f c0556f = (C0556f) aVar2.f1159t;
                    c0556f.getClass();
                    AtomicLongFieldUpdater atomicLongFieldUpdater = C0556f.f9231s;
                    long j8 = atomicLongFieldUpdater.get(c0556f);
                    long j9 = C0556f.f9230r.get(c0556f);
                    if (c0556f.s(j9, z8)) {
                        c0561k = new C0561k(c0556f.n());
                    } else {
                        long j10 = j9 & 1152921504606846975L;
                        C0562l c0562l = b7.m.f9263b;
                        if (j8 >= j10) {
                            th = th3;
                        } else {
                            Object obj4 = AbstractC0558h.f9250k;
                            b7.n nVar3 = (b7.n) C0556f.f9235w.get(c0556f);
                            while (!c0556f.t()) {
                                long andIncrement = atomicLongFieldUpdater.getAndIncrement(c0556f);
                                th = th3;
                                long j11 = AbstractC0558h.f9242b;
                                long j12 = andIncrement / j11;
                                int i9 = (int) (andIncrement % j11);
                                if (nVar3.f12574s == j12) {
                                    objC = c0556f.C(nVar3, i9, andIncrement, obj4);
                                    if (objC != AbstractC0558h.f9252m) {
                                        B0 b02 = obj4 instanceof B0 ? (B0) obj4 : null;
                                        if (b02 != null) {
                                            b02.a(nVar3, i9);
                                        }
                                        c0556f.E(andIncrement);
                                        nVar3.i();
                                    } else if (objC == AbstractC0558h.f9254o) {
                                        if (andIncrement < c0556f.q()) {
                                            nVar3.a();
                                        }
                                        th3 = th;
                                    } else {
                                        if (objC == AbstractC0558h.f9253n) {
                                            throw new IllegalStateException("unexpected");
                                        }
                                        nVar3.a();
                                        c0561k = objC;
                                    }
                                } else {
                                    b7.n nVarM = c0556f.m(j12, nVar3);
                                    if (nVarM == null) {
                                        continue;
                                        th3 = th;
                                    } else {
                                        nVar3 = nVarM;
                                        objC = c0556f.C(nVar3, i9, andIncrement, obj4);
                                        if (objC != AbstractC0558h.f9252m) {
                                        }
                                    }
                                }
                                if (c0561k instanceof C0562l) {
                                    c0561k = null;
                                }
                                if (c0561k != null) {
                                    W.M m8 = (W.M) c0561k;
                                    Throwable cancellationException = th == null ? new CancellationException("DataStore scope was cancelled before updateData could complete") : th;
                                    C0375o c0375o = m8.f6948b;
                                    c0375o.getClass();
                                    c0375o.R(new C0377q(cancellationException, false));
                                    nVar = nVar2;
                                } else {
                                    nVar = null;
                                }
                                if (nVar == null) {
                                    return nVar2;
                                }
                                th3 = th;
                                z8 = true;
                            }
                            c0561k = new C0561k(c0556f.n());
                        }
                        c0561k = c0562l;
                        if (c0561k instanceof C0562l) {
                        }
                        if (c0561k != null) {
                        }
                        if (nVar == null) {
                        }
                    }
                    th = th3;
                    if (c0561k instanceof C0562l) {
                    }
                    if (c0561k != null) {
                    }
                    if (nVar == null) {
                    }
                }
                break;
        }
    }
}
