package androidx.compose.runtime;

import V2.y3;
import Y4.InterfaceC0843i;
import Y4.InterfaceC0844j;
import Y4.a0;
import androidx.compose.runtime.collection.ScatterSetWrapper;
import androidx.compose.runtime.snapshots.ObserverHandle;
import androidx.compose.runtime.snapshots.ReaderKind;
import androidx.compose.runtime.snapshots.Snapshot;
import androidx.compose.runtime.snapshots.StateObjectImpl;
import java.util.Collection;
import java.util.Set;
import m3.AbstractC2467b;
import n.O;
import n.Z;
import w4.C3137A;

/* JADX INFO: loaded from: classes.dex */
final /* synthetic */ class SnapshotStateKt__SnapshotFlowKt {

    /* JADX INFO: renamed from: androidx.compose.runtime.SnapshotStateKt__SnapshotFlowKt$snapshotFlow$1, reason: invalid class name */
    @C4.e(c = "androidx.compose.runtime.SnapshotStateKt__SnapshotFlowKt$snapshotFlow$1", f = "SnapshotFlow.kt", l = {143, 147, 170}, m = "invokeSuspend", v = 1)
    public static final class AnonymousClass1 extends C4.j implements J4.e {
        final /* synthetic */ J4.a $block;
        int I$0;
        private /* synthetic */ Object L$0;
        Object L$1;
        Object L$2;
        Object L$3;
        Object L$4;
        Object L$5;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public AnonymousClass1(J4.a aVar, A4.d dVar) {
            super(2, dVar);
            this.$block = aVar;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static final C3137A invokeSuspend$lambda$0(O o6, Object obj) {
            if (obj instanceof StateObjectImpl) {
                ((StateObjectImpl) obj).m270recordReadInh_f27i8$runtime(ReaderKind.m257constructorimpl(4));
            }
            o6.d(obj);
            return C3137A.f25453a;
        }

        /* JADX INFO: Access modifiers changed from: private */
        /* JADX WARN: Removed duplicated region for block: B:20:0x005a  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public static final C3137A invokeSuspend$lambda$1(X4.i iVar, Set set, Snapshot snapshot) {
            if (set instanceof ScatterSetWrapper) {
                Z set$runtime = ((ScatterSetWrapper) set).getSet$runtime();
                Object[] objArr = set$runtime.f21389b;
                long[] jArr = set$runtime.f21388a;
                int length = jArr.length - 2;
                if (length >= 0) {
                    int i6 = 0;
                    loop0: while (true) {
                        long j4 = jArr[i6];
                        if ((((~j4) << 7) & j4 & (-9187201950435737472L)) != -9187201950435737472L) {
                            int i7 = 8 - ((~(i6 - length)) >>> 31);
                            for (int i8 = 0; i8 < i7; i8++) {
                                if ((255 & j4) < 128) {
                                    Object obj = objArr[(i6 << 3) + i8];
                                    if (!(obj instanceof StateObjectImpl) || ((StateObjectImpl) obj).m269isReadInh_f27i8$runtime(ReaderKind.m257constructorimpl(4))) {
                                        break loop0;
                                    }
                                }
                                j4 >>= 8;
                            }
                            if (i7 != 8) {
                                break;
                            }
                            if (i6 == length) {
                                break;
                            }
                            i6++;
                        }
                    }
                }
            } else {
                Set set2 = set;
                if (!(set2 instanceof Collection) || !set2.isEmpty()) {
                    for (Object obj2 : set2) {
                        if (!(obj2 instanceof StateObjectImpl) || ((StateObjectImpl) obj2).m269isReadInh_f27i8$runtime(ReaderKind.m257constructorimpl(4))) {
                            iVar.f(set);
                        }
                    }
                }
            }
            return C3137A.f25453a;
        }

        @Override // C4.a
        public final A4.d create(Object obj, A4.d dVar) {
            AnonymousClass1 anonymousClass1 = new AnonymousClass1(this.$block, dVar);
            anonymousClass1.L$0 = obj;
            return anonymousClass1;
        }

        @Override // J4.e
        public final Object invoke(InterfaceC0844j interfaceC0844j, A4.d dVar) {
            return ((AnonymousClass1) create(interfaceC0844j, dVar)).invokeSuspend(C3137A.f25453a);
        }

        /* JADX WARN: Path cross not found for [B:34:0x00e2, B:38:0x00eb], limit reached: 75 */
        /* JADX WARN: Path cross not found for [B:42:0x00fa, B:58:0x0139], limit reached: 75 */
        /* JADX WARN: Path cross not found for [B:58:0x0139, B:42:0x00fa], limit reached: 75 */
        /* JADX WARN: Removed duplicated region for block: B:31:0x00d7  */
        /* JADX WARN: Removed duplicated region for block: B:42:0x00fa A[Catch: all -> 0x0053, TRY_LEAVE, TryCatch #3 {all -> 0x0053, blocks: (B:32:0x00de, B:34:0x00e2, B:39:0x00ec, B:42:0x00fa, B:46:0x0110, B:48:0x0119, B:56:0x0135, B:57:0x0138, B:15:0x004e, B:43:0x0105, B:45:0x010d, B:54:0x0131, B:55:0x0134), top: B:74:0x004e, inners: #5 }] */
        @Override // C4.a
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) throws Throwable {
            ObserverHandle observerHandleRegisterApplyObserver;
            InterfaceC0844j interfaceC0844j;
            O o6;
            J4.c pVar;
            X4.i iVarI;
            Snapshot snapshotTakeSnapshot;
            Snapshot snapshotMakeCurrent;
            Object objInvoke;
            ObserverHandle observerHandle;
            InterfaceC0844j interfaceC0844j2;
            O o7;
            J4.c cVar;
            X4.i iVar;
            Object obj2;
            int i6;
            Set set;
            B4.a aVar = B4.a.f492a;
            int i7 = this.label;
            try {
                if (i7 == 0) {
                    AbstractC2467b.l(obj);
                    interfaceC0844j = (InterfaceC0844j) this.L$0;
                    o6 = new O();
                    pVar = new p(o6, 1);
                    iVarI = W.a.I(Integer.MAX_VALUE, 6, null);
                    Snapshot.Companion companion = Snapshot.Companion;
                    observerHandleRegisterApplyObserver = companion.registerApplyObserver(new t(iVarI, 1));
                    snapshotTakeSnapshot = companion.takeSnapshot(pVar);
                    J4.a aVar2 = this.$block;
                    try {
                        snapshotMakeCurrent = snapshotTakeSnapshot.makeCurrent();
                        try {
                            objInvoke = aVar2.invoke();
                            snapshotTakeSnapshot.dispose();
                            this.L$0 = interfaceC0844j;
                            this.L$1 = o6;
                            this.L$2 = pVar;
                            this.L$3 = iVarI;
                            this.L$4 = observerHandleRegisterApplyObserver;
                            this.L$5 = objInvoke;
                            this.label = 1;
                            if (interfaceC0844j.emit(objInvoke, this) == aVar) {
                            }
                            return aVar;
                        } finally {
                        }
                    } finally {
                    }
                }
                if (i7 == 1) {
                    objInvoke = this.L$5;
                    observerHandleRegisterApplyObserver = (ObserverHandle) this.L$4;
                    iVarI = (X4.i) this.L$3;
                    pVar = (J4.c) this.L$2;
                    o6 = (O) this.L$1;
                    interfaceC0844j = (InterfaceC0844j) this.L$0;
                } else if (i7 == 2) {
                    i6 = this.I$0;
                    obj2 = this.L$5;
                    observerHandle = (ObserverHandle) this.L$4;
                    iVar = (X4.i) this.L$3;
                    cVar = (J4.c) this.L$2;
                    o7 = (O) this.L$1;
                    interfaceC0844j2 = (InterfaceC0844j) this.L$0;
                    try {
                        AbstractC2467b.l(obj);
                        set = (Set) obj;
                        do {
                            i6 = (i6 == 0 || SnapshotStateKt__SnapshotFlowKt.intersects$SnapshotStateKt__SnapshotFlowKt(o7, set)) ? 1 : 0;
                            set = (Set) X4.l.a(iVar.c());
                        } while (set != null);
                        if (i6 != 0) {
                            o7.e();
                            snapshotTakeSnapshot = Snapshot.Companion.takeSnapshot(cVar);
                            J4.a aVar3 = this.$block;
                            try {
                                try {
                                    objInvoke = aVar3.invoke();
                                    snapshotTakeSnapshot.dispose();
                                    if (!kotlin.jvm.internal.o.c(objInvoke, obj2)) {
                                        this.L$0 = interfaceC0844j2;
                                        this.L$1 = o7;
                                        this.L$2 = cVar;
                                        this.L$3 = iVar;
                                        this.L$4 = observerHandle;
                                        this.L$5 = objInvoke;
                                        this.label = 3;
                                        if (interfaceC0844j2.emit(objInvoke, this) != aVar) {
                                            observerHandleRegisterApplyObserver = observerHandle;
                                            iVarI = iVar;
                                            pVar = cVar;
                                            o6 = o7;
                                            interfaceC0844j = interfaceC0844j2;
                                        }
                                        return aVar;
                                    }
                                } finally {
                                }
                                snapshotMakeCurrent = snapshotTakeSnapshot.makeCurrent();
                            } finally {
                            }
                        }
                        objInvoke = obj2;
                        observerHandleRegisterApplyObserver = observerHandle;
                        iVarI = iVar;
                        pVar = cVar;
                        o6 = o7;
                        interfaceC0844j = interfaceC0844j2;
                    } catch (Throwable th) {
                        th = th;
                        observerHandleRegisterApplyObserver = observerHandle;
                        observerHandleRegisterApplyObserver.dispose();
                        throw th;
                    }
                } else {
                    if (i7 != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    objInvoke = this.L$5;
                    observerHandleRegisterApplyObserver = (ObserverHandle) this.L$4;
                    iVarI = (X4.i) this.L$3;
                    pVar = (J4.c) this.L$2;
                    o6 = (O) this.L$1;
                    interfaceC0844j = (InterfaceC0844j) this.L$0;
                }
                AbstractC2467b.l(obj);
                this.L$0 = interfaceC0844j;
                this.L$1 = o6;
                this.L$2 = pVar;
                this.L$3 = iVarI;
                this.L$4 = observerHandleRegisterApplyObserver;
                this.L$5 = objInvoke;
                this.I$0 = 0;
                this.label = 2;
                obj = iVarI.e(this);
                if (obj != aVar) {
                    interfaceC0844j2 = interfaceC0844j;
                    o7 = o6;
                    cVar = pVar;
                    iVar = iVarI;
                    observerHandle = observerHandleRegisterApplyObserver;
                    obj2 = objInvoke;
                    i6 = 0;
                    set = (Set) obj;
                    do {
                        if (i6 == 0) {
                        }
                        set = (Set) X4.l.a(iVar.c());
                    } while (set != null);
                    if (i6 != 0) {
                    }
                    objInvoke = obj2;
                    observerHandleRegisterApplyObserver = observerHandle;
                    iVarI = iVar;
                    pVar = cVar;
                    o6 = o7;
                    interfaceC0844j = interfaceC0844j2;
                    this.L$0 = interfaceC0844j;
                    this.L$1 = o6;
                    this.L$2 = pVar;
                    this.L$3 = iVarI;
                    this.L$4 = observerHandleRegisterApplyObserver;
                    this.L$5 = objInvoke;
                    this.I$0 = 0;
                    this.label = 2;
                    obj = iVarI.e(this);
                    if (obj != aVar) {
                    }
                }
                return aVar;
            } catch (Throwable th2) {
                th = th2;
                observerHandleRegisterApplyObserver.dispose();
                throw th;
            }
        }
    }

    @Composable
    public static final <T> State<T> collectAsState(a0 a0Var, A4.j jVar, Composer composer, int i6, int i7) {
        if ((i7 & 1) != 0) {
            jVar = A4.k.f106a;
        }
        A4.j jVar2 = jVar;
        if (ComposerKt.isTraceInProgress()) {
            ComposerKt.traceEventStart(-1439883919, i6, -1, "androidx.compose.runtime.collectAsState (SnapshotFlow.kt:49)");
        }
        State<T> stateCollectAsState = SnapshotStateKt.collectAsState(a0Var, a0Var.getValue(), jVar2, composer, (i6 & 14) | ((i6 << 3) & 896), 0);
        if (ComposerKt.isTraceInProgress()) {
            ComposerKt.traceEventEnd();
        }
        return stateCollectAsState;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:17:0x0043  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final boolean intersects$SnapshotStateKt__SnapshotFlowKt(O o6, Set<? extends Object> set) {
        Object[] objArr = o6.f21389b;
        long[] jArr = o6.f21388a;
        int length = jArr.length - 2;
        if (length >= 0) {
            int i6 = 0;
            while (true) {
                long j4 = jArr[i6];
                if ((((~j4) << 7) & j4 & (-9187201950435737472L)) != -9187201950435737472L) {
                    int i7 = 8 - ((~(i6 - length)) >>> 31);
                    for (int i8 = 0; i8 < i7; i8++) {
                        if ((255 & j4) < 128 && set.contains(objArr[(i6 << 3) + i8])) {
                            return true;
                        }
                        j4 >>= 8;
                    }
                    if (i7 != 8) {
                        break;
                    }
                    if (i6 == length) {
                        break;
                    }
                    i6++;
                }
            }
        }
        return false;
    }

    public static final <T> InterfaceC0843i snapshotFlow(J4.a aVar) {
        return new y3(new AnonymousClass1(aVar, null));
    }

    @Composable
    public static final <T extends R, R> State<R> collectAsState(InterfaceC0843i interfaceC0843i, R r5, A4.j jVar, Composer composer, int i6, int i7) {
        if ((i7 & 2) != 0) {
            jVar = A4.k.f106a;
        }
        A4.j jVar2 = jVar;
        if (ComposerKt.isTraceInProgress()) {
            ComposerKt.traceEventStart(-606625098, i6, -1, "androidx.compose.runtime.collectAsState (SnapshotFlow.kt:65)");
        }
        boolean zChangedInstance = composer.changedInstance(jVar2) | composer.changedInstance(interfaceC0843i);
        Object objRememberedValue = composer.rememberedValue();
        if (zChangedInstance || objRememberedValue == Composer.Companion.getEmpty()) {
            objRememberedValue = new SnapshotStateKt__SnapshotFlowKt$collectAsState$1$1(jVar2, interfaceC0843i, null);
            composer.updateRememberedValue(objRememberedValue);
        }
        State<R> stateProduceState = SnapshotStateKt.produceState(r5, interfaceC0843i, jVar2, (J4.e) objRememberedValue, composer, ((i6 >> 3) & 14) | ((i6 << 3) & 112) | (i6 & 896));
        if (ComposerKt.isTraceInProgress()) {
            ComposerKt.traceEventEnd();
        }
        return stateProduceState;
    }
}
