package h7;

import A6.n;
import B6.k;
import O6.l;
import O6.p;
import O6.q;
import Z6.B0;
import Z6.C0369i;
import Z6.InterfaceC0366f;
import Z6.InterfaceC0367g;
import com.google.android.gms.internal.measurement.C1;
import e7.r;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: renamed from: h7.e, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1040e implements InterfaceC0366f, InterfaceC1041f, B0 {

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f13458v = AtomicReferenceFieldUpdater.newUpdater(C1040e.class, Object.class, "state$volatile");

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final E6.i f13459q;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Object f13461s;
    private volatile /* synthetic */ Object state$volatile = AbstractC1043h.f13465a;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public ArrayList f13460r = new ArrayList(2);

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public int f13462t = -1;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public Object f13463u = AbstractC1043h.f13468d;

    public C1040e(E6.i iVar) {
        this.f13459q = iVar;
    }

    @Override // Z6.B0
    public final void a(r rVar, int i) {
        this.f13461s = rVar;
        this.f13462t = i;
    }

    @Override // Z6.InterfaceC0366f
    public final void b(Throwable th) {
        while (true) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f13458v;
            Object obj = atomicReferenceFieldUpdater.get(this);
            if (obj == AbstractC1043h.f13466b) {
                return;
            }
            B3.f fVar = AbstractC1043h.f13467c;
            while (!atomicReferenceFieldUpdater.compareAndSet(this, obj, fVar)) {
                if (atomicReferenceFieldUpdater.get(this) != obj) {
                    break;
                }
            }
            ArrayList arrayList = this.f13460r;
            if (arrayList == null) {
                return;
            }
            int size = arrayList.size();
            int i = 0;
            while (i < size) {
                Object obj2 = arrayList.get(i);
                i++;
                ((C1038c) obj2).b();
            }
            this.f13463u = AbstractC1043h.f13468d;
            this.f13460r = null;
            return;
        }
    }

    public final Object c(G6.c cVar) {
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f13458v;
        Object obj = atomicReferenceFieldUpdater.get(this);
        P6.g.c(obj, "null cannot be cast to non-null type kotlinx.coroutines.selects.SelectImplementation.ClauseData<R of kotlinx.coroutines.selects.SelectImplementation>");
        C1038c c1038c = (C1038c) obj;
        Object obj2 = this.f13463u;
        ArrayList arrayList = this.f13460r;
        if (arrayList != null) {
            int size = arrayList.size();
            int i = 0;
            while (i < size) {
                Object obj3 = arrayList.get(i);
                i++;
                C1038c c1038c2 = (C1038c) obj3;
                if (c1038c2 != c1038c) {
                    c1038c2.b();
                }
            }
            atomicReferenceFieldUpdater.set(this, AbstractC1043h.f13466b);
            this.f13463u = AbstractC1043h.f13468d;
            this.f13460r = null;
        }
        Object objJ = c1038c.f13448c.j(c1038c.f13446a, c1038c.f13449d, obj2);
        B3.f fVar = AbstractC1043h.f13469e;
        G6.d dVar = c1038c.f13450e;
        return c1038c.f13449d == fVar ? ((l) dVar).b(cVar) : ((p) dVar).k(objJ, cVar);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object d(G6.c cVar) throws Throwable {
        C1039d c1039d;
        Object obj;
        C1040e c1040e;
        if (cVar instanceof C1039d) {
            c1039d = (C1039d) cVar;
            int i = c1039d.f13457w;
            if ((i & Integer.MIN_VALUE) != 0) {
                c1039d.f13457w = i - Integer.MIN_VALUE;
            } else {
                c1039d = new C1039d(this, cVar);
            }
        }
        Object obj2 = c1039d.f13455u;
        F6.a aVar = F6.a.f2580q;
        int i5 = c1039d.f13457w;
        if (i5 == 0) {
            C1.N(obj2);
            c1039d.f13454t = this;
            c1039d.f13457w = 1;
            C0369i c0369i = new C0369i(1, C1.A(c1039d));
            c0369i.v();
            loop0: while (true) {
                AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f13458v;
                Object obj3 = atomicReferenceFieldUpdater.get(this);
                B3.f fVar = AbstractC1043h.f13465a;
                obj = n.f457a;
                if (obj3 == fVar) {
                    while (!atomicReferenceFieldUpdater.compareAndSet(this, obj3, c0369i)) {
                        if (atomicReferenceFieldUpdater.get(this) != obj3) {
                            break;
                        }
                    }
                    c0369i.y(this);
                    break loop0;
                }
                if (obj3 instanceof List) {
                    while (true) {
                        if (atomicReferenceFieldUpdater.compareAndSet(this, obj3, fVar)) {
                            Iterator it = ((Iterable) obj3).iterator();
                            while (it.hasNext()) {
                                C1038c c1038cE = e(it.next());
                                P6.g.b(c1038cE);
                                c1038cE.f13451f = null;
                                c1038cE.f13452g = -1;
                                f(c1038cE, true);
                            }
                        } else if (atomicReferenceFieldUpdater.get(this) != obj3) {
                            break;
                        }
                    }
                } else {
                    if (!(obj3 instanceof C1038c)) {
                        throw new IllegalStateException(("unexpected state: " + obj3).toString());
                    }
                    c0369i.c(obj, ((C1038c) obj3).a(this, this.f13463u));
                }
            }
            Object objU = c0369i.u();
            if (objU == aVar) {
                obj = objU;
            }
            if (obj != aVar) {
                c1040e = this;
            }
        }
        if (i5 != 1) {
            if (i5 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            C1.N(obj2);
            return obj2;
        }
        c1040e = c1039d.f13454t;
        C1.N(obj2);
        c1039d.f13454t = null;
        c1039d.f13457w = 2;
        Object objC = c1040e.c(c1039d);
        return objC == aVar ? aVar : objC;
    }

    public final C1038c e(Object obj) {
        ArrayList arrayList = this.f13460r;
        Object obj2 = null;
        if (arrayList == null) {
            return null;
        }
        int size = arrayList.size();
        int i = 0;
        while (true) {
            if (i >= size) {
                break;
            }
            Object obj3 = arrayList.get(i);
            i++;
            if (((C1038c) obj3).f13446a == obj) {
                obj2 = obj3;
                break;
            }
        }
        C1038c c1038c = (C1038c) obj2;
        if (c1038c != null) {
            return c1038c;
        }
        throw new IllegalStateException(("Clause with object " + obj + " is not found").toString());
    }

    /* JADX WARN: Type inference failed for: r2v0, types: [O6.q, P6.f] */
    public final void f(C1038c c1038c, boolean z8) {
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f13458v;
        if (atomicReferenceFieldUpdater.get(this) instanceof C1038c) {
            return;
        }
        Object obj = c1038c.f13446a;
        if (!z8) {
            ArrayList arrayList = this.f13460r;
            P6.g.b(arrayList);
            if (!arrayList.isEmpty()) {
                int size = arrayList.size();
                int i = 0;
                while (i < size) {
                    Object obj2 = arrayList.get(i);
                    i++;
                    if (((C1038c) obj2).f13446a == obj) {
                        throw new IllegalStateException(I1.a.n(obj, "Cannot use select clauses on the same object: ").toString());
                    }
                }
            }
        }
        c1038c.f13447b.j(obj, this, c1038c.f13449d);
        if (this.f13463u != AbstractC1043h.f13468d) {
            atomicReferenceFieldUpdater.set(this, c1038c);
            return;
        }
        if (!z8) {
            ArrayList arrayList2 = this.f13460r;
            P6.g.b(arrayList2);
            arrayList2.add(c1038c);
        }
        c1038c.f13451f = this.f13461s;
        c1038c.f13452g = this.f13462t;
        this.f13461s = null;
        this.f13462t = -1;
    }

    public final boolean g(Object obj, Object obj2) {
        return h(obj, obj2) == 0;
    }

    public final int h(Object obj, Object obj2) {
        while (true) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f13458v;
            Object obj3 = atomicReferenceFieldUpdater.get(this);
            if (!(obj3 instanceof InterfaceC0367g)) {
                if (P6.g.a(obj3, AbstractC1043h.f13466b) || (obj3 instanceof C1038c)) {
                    return 3;
                }
                if (P6.g.a(obj3, AbstractC1043h.f13467c)) {
                    return 2;
                }
                if (P6.g.a(obj3, AbstractC1043h.f13465a)) {
                    List listC = C1.C(obj);
                    while (!atomicReferenceFieldUpdater.compareAndSet(this, obj3, listC)) {
                        if (atomicReferenceFieldUpdater.get(this) != obj3) {
                            break;
                        }
                    }
                    return 1;
                }
                if (!(obj3 instanceof List)) {
                    throw new IllegalStateException(("Unexpected state: " + obj3).toString());
                }
                ArrayList arrayListR0 = k.r0((Collection) obj3, obj);
                while (!atomicReferenceFieldUpdater.compareAndSet(this, obj3, arrayListR0)) {
                    if (atomicReferenceFieldUpdater.get(this) != obj3) {
                        break;
                    }
                }
                return 1;
            }
            C1038c c1038cE = e(obj);
            if (c1038cE != null) {
                q qVarA = c1038cE.a(this, obj2);
                while (!atomicReferenceFieldUpdater.compareAndSet(this, obj3, c1038cE)) {
                    if (atomicReferenceFieldUpdater.get(this) != obj3) {
                        break;
                    }
                }
                InterfaceC0367g interfaceC0367g = (InterfaceC0367g) obj3;
                this.f13463u = obj2;
                B3.f fVarD = interfaceC0367g.d(n.f457a, qVarA);
                if (fVarD == null) {
                    this.f13463u = AbstractC1043h.f13468d;
                    return 2;
                }
                interfaceC0367g.o(fVarD);
                return 0;
            }
            continue;
        }
    }
}
