package androidx.compose.runtime.snapshots;

import B.C0053c;
import D.C0135f;
import E3.v;
import androidx.compose.runtime.ComposerKt;
import androidx.compose.runtime.DerivedState;
import androidx.compose.runtime.DerivedStateObserver;
import androidx.compose.runtime.PreconditionsKt;
import androidx.compose.runtime.SnapshotMutationPolicy;
import androidx.compose.runtime.SnapshotStateKt;
import androidx.compose.runtime.collection.MutableVector;
import androidx.compose.runtime.collection.ScatterSetWrapper;
import androidx.compose.runtime.collection.ScopeMap;
import androidx.compose.runtime.internal.StabilityInferred;
import androidx.compose.runtime.internal.Thread_jvmKt;
import androidx.compose.runtime.snapshots.Snapshot;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import kotlin.jvm.internal.F;
import kotlin.jvm.internal.o;
import n.C2571F;
import n.N;
import n.O;
import n.S;
import n.Z;
import n2.AbstractC2612c;
import w4.C3137A;
import w4.InterfaceC3141c;
import x4.AbstractC3250p;
import x4.AbstractC3251q;
import x4.AbstractC3252r;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 0)
public final class SnapshotStateObserver {
    public static final int $stable = 8;
    private ObserverHandle applyUnsubscribe;
    private ObservedScopeMap currentMap;
    private boolean isPaused;
    private final J4.c onChangedExecutor;
    private boolean sendingNotifications;
    private final AtomicReference<Object> pendingChanges = new AtomicReference<>(null);
    private final J4.e applyObserver = new C0053c(this, 15);
    private final J4.c readObserver = new e(this, 0);
    private final MutableVector<ObservedScopeMap> observedScopeMaps = new MutableVector<>(new ObservedScopeMap[16], 0);
    private final Object observedScopeMapsLock = new Object();
    private long currentMapThreadId = -1;

    public SnapshotStateObserver(J4.c cVar) {
        this.onChangedExecutor = cVar;
    }

    /* JADX WARN: Multi-variable type inference failed */
    private final void addChanges(Set<? extends Object> set) {
        Set<? extends Object> setS0;
        while (true) {
            Object obj = this.pendingChanges.get();
            if (obj == null) {
                setS0 = set;
            } else if (obj instanceof Set) {
                setS0 = AbstractC3252r.B(obj, set);
            } else {
                if (!(obj instanceof List)) {
                    report();
                    throw new v();
                }
                setS0 = AbstractC3251q.s0(AbstractC2612c.q(set), (Collection) obj);
            }
            AtomicReference<Object> atomicReference = this.pendingChanges;
            while (!atomicReference.compareAndSet(obj, setS0)) {
                if (atomicReference.get() != obj) {
                    break;
                }
            }
            return;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final C3137A applyObserver$lambda$0(SnapshotStateObserver snapshotStateObserver, Set set, Snapshot snapshot) {
        snapshotStateObserver.addChanges(set);
        if (snapshotStateObserver.drainChanges()) {
            snapshotStateObserver.sendNotifications();
        }
        return C3137A.f25453a;
    }

    private final boolean drainChanges() {
        boolean z6;
        synchronized (this.observedScopeMapsLock) {
            z6 = this.sendingNotifications;
        }
        if (z6) {
            return false;
        }
        boolean z7 = false;
        while (true) {
            Set<? extends Object> setRemoveChanges = removeChanges();
            if (setRemoveChanges == null) {
                return z7;
            }
            synchronized (this.observedScopeMapsLock) {
                MutableVector<ObservedScopeMap> mutableVector = this.observedScopeMaps;
                ObservedScopeMap[] observedScopeMapArr = mutableVector.content;
                int size = mutableVector.getSize();
                for (int i6 = 0; i6 < size; i6++) {
                    z7 = observedScopeMapArr[i6].recordInvalidation(setRemoveChanges) || z7;
                }
            }
        }
    }

    private final <T> ObservedScopeMap ensureMap(J4.c cVar) {
        ObservedScopeMap observedScopeMap;
        MutableVector<ObservedScopeMap> mutableVector = this.observedScopeMaps;
        ObservedScopeMap[] observedScopeMapArr = mutableVector.content;
        int size = mutableVector.getSize();
        int i6 = 0;
        while (true) {
            if (i6 >= size) {
                observedScopeMap = null;
                break;
            }
            observedScopeMap = observedScopeMapArr[i6];
            if (observedScopeMap.getOnChanged() == cVar) {
                break;
            }
            i6++;
        }
        ObservedScopeMap observedScopeMap2 = observedScopeMap;
        if (observedScopeMap2 != null) {
            return observedScopeMap2;
        }
        o.f(cVar, "null cannot be cast to non-null type kotlin.Function1<kotlin.Any, kotlin.Unit>");
        F.c(1, cVar);
        ObservedScopeMap observedScopeMap3 = new ObservedScopeMap(cVar);
        this.observedScopeMaps.add(observedScopeMap3);
        return observedScopeMap3;
    }

    private final void forEachScopeMap(J4.c cVar) {
        synchronized (this.observedScopeMapsLock) {
            MutableVector<ObservedScopeMap> mutableVector = this.observedScopeMaps;
            ObservedScopeMap[] observedScopeMapArr = mutableVector.content;
            int size = mutableVector.getSize();
            for (int i6 = 0; i6 < size; i6++) {
                cVar.invoke(observedScopeMapArr[i6]);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final C3137A readObserver$lambda$0(SnapshotStateObserver snapshotStateObserver, Object obj) {
        if (!snapshotStateObserver.isPaused) {
            synchronized (snapshotStateObserver.observedScopeMapsLock) {
                ObservedScopeMap observedScopeMap = snapshotStateObserver.currentMap;
                o.e(observedScopeMap);
                observedScopeMap.recordRead(obj);
            }
        }
        return C3137A.f25453a;
    }

    private final Set<Object> removeChanges() {
        Set<Object> set;
        while (true) {
            Object obj = this.pendingChanges.get();
            Object objSubList = null;
            if (obj == null) {
                return null;
            }
            if (obj instanceof Set) {
                set = (Set) obj;
            } else {
                if (!(obj instanceof List)) {
                    report();
                    throw new v();
                }
                List list = (List) obj;
                Set<Object> set2 = (Set) list.get(0);
                if (list.size() == 2) {
                    objSubList = list.get(1);
                } else if (list.size() > 2) {
                    objSubList = list.subList(1, list.size());
                }
                set = set2;
            }
            AtomicReference<Object> atomicReference = this.pendingChanges;
            while (!atomicReference.compareAndSet(obj, objSubList)) {
                if (atomicReference.get() != obj) {
                    break;
                }
            }
            return set;
        }
    }

    private final void removeScopeMapIf(J4.c cVar) {
        synchronized (this.observedScopeMapsLock) {
            try {
                MutableVector<ObservedScopeMap> mutableVector = this.observedScopeMaps;
                int size = mutableVector.getSize();
                int i6 = 0;
                for (int i7 = 0; i7 < size; i7++) {
                    if (((Boolean) cVar.invoke(mutableVector.content[i7])).booleanValue()) {
                        i6++;
                    } else if (i6 > 0) {
                        ObservedScopeMap[] observedScopeMapArr = mutableVector.content;
                        observedScopeMapArr[i7 - i6] = observedScopeMapArr[i7];
                    }
                }
                int i8 = size - i6;
                AbstractC3250p.H(mutableVector.content, null, i8, size);
                mutableVector.setSize(i8);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    private final Void report() {
        ComposerKt.composeRuntimeError("Unexpected notification");
        throw new v();
    }

    private final void sendNotifications() {
        this.onChangedExecutor.invoke(new C0135f(this, 25));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final C3137A sendNotifications$lambda$0(SnapshotStateObserver snapshotStateObserver) {
        do {
            synchronized (snapshotStateObserver.observedScopeMapsLock) {
                try {
                    if (!snapshotStateObserver.sendingNotifications) {
                        snapshotStateObserver.sendingNotifications = true;
                        try {
                            MutableVector<ObservedScopeMap> mutableVector = snapshotStateObserver.observedScopeMaps;
                            ObservedScopeMap[] observedScopeMapArr = mutableVector.content;
                            int size = mutableVector.getSize();
                            for (int i6 = 0; i6 < size; i6++) {
                                observedScopeMapArr[i6].notifyInvalidatedScopes();
                            }
                            snapshotStateObserver.sendingNotifications = false;
                        } finally {
                        }
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        } while (snapshotStateObserver.drainChanges());
        return C3137A.f25453a;
    }

    public final void clear(Object obj) {
        synchronized (this.observedScopeMapsLock) {
            try {
                MutableVector<ObservedScopeMap> mutableVector = this.observedScopeMaps;
                int size = mutableVector.getSize();
                int i6 = 0;
                for (int i7 = 0; i7 < size; i7++) {
                    ObservedScopeMap observedScopeMap = mutableVector.content[i7];
                    observedScopeMap.clearScopeObservations(obj);
                    if (!observedScopeMap.hasScopeObservations()) {
                        i6++;
                    } else if (i6 > 0) {
                        ObservedScopeMap[] observedScopeMapArr = mutableVector.content;
                        observedScopeMapArr[i7 - i6] = observedScopeMapArr[i7];
                    }
                }
                int i8 = size - i6;
                AbstractC3250p.H(mutableVector.content, null, i8, size);
                mutableVector.setSize(i8);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void clearIf(J4.c cVar) {
        synchronized (this.observedScopeMapsLock) {
            try {
                MutableVector<ObservedScopeMap> mutableVector = this.observedScopeMaps;
                int size = mutableVector.getSize();
                int i6 = 0;
                for (int i7 = 0; i7 < size; i7++) {
                    ObservedScopeMap observedScopeMap = mutableVector.content[i7];
                    observedScopeMap.removeScopeIf(cVar);
                    if (!observedScopeMap.hasScopeObservations()) {
                        i6++;
                    } else if (i6 > 0) {
                        ObservedScopeMap[] observedScopeMapArr = mutableVector.content;
                        observedScopeMapArr[i7 - i6] = observedScopeMapArr[i7];
                    }
                }
                int i8 = size - i6;
                AbstractC3250p.H(mutableVector.content, null, i8, size);
                mutableVector.setSize(i8);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void notifyChanges(Set<? extends Object> set, Snapshot snapshot) {
        this.applyObserver.invoke(set, snapshot);
    }

    /* JADX WARN: Removed duplicated region for block: B:47:0x0134  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final <T> void observeReads(T t6, J4.c cVar, J4.a aVar) throws Throwable {
        ObservedScopeMap observedScopeMapEnsureMap;
        long j4;
        J4.c cVar2;
        Object obj;
        C2571F c2571f;
        int i6;
        MutableVector<DerivedStateObserver> mutableVectorDerivedStateObservers;
        MutableVector<DerivedStateObserver> mutableVector;
        long j6;
        Snapshot transparentObserverMutableSnapshot;
        synchronized (this.observedScopeMapsLock) {
            observedScopeMapEnsureMap = ensureMap(cVar);
        }
        boolean z6 = this.isPaused;
        ObservedScopeMap observedScopeMap = this.currentMap;
        long j7 = this.currentMapThreadId;
        if (j7 != -1) {
            if (!(j7 == Thread_jvmKt.currentThreadId())) {
                PreconditionsKt.throwIllegalArgumentException("Detected multithreaded access to SnapshotStateObserver: previousThreadId=" + j7 + "), currentThread={id=" + Thread_jvmKt.currentThreadId() + ", name=" + Thread_jvmKt.currentThreadName() + "}. Note that observation on multiple threads in layout/draw is not supported. Make sure your measure/layout/draw for each Owner (AndroidComposeView) is executed on the same thread.");
            }
        }
        try {
            this.isPaused = false;
            this.currentMap = observedScopeMapEnsureMap;
            this.currentMapThreadId = Thread_jvmKt.currentThreadId();
            cVar2 = this.readObserver;
            obj = observedScopeMapEnsureMap.currentScope;
            c2571f = observedScopeMapEnsureMap.currentScopeReads;
            i6 = observedScopeMapEnsureMap.currentToken;
            observedScopeMapEnsureMap.currentScope = t6;
            observedScopeMapEnsureMap.currentScopeReads = (C2571F) observedScopeMapEnsureMap.scopeToValues.d(t6);
            if (observedScopeMapEnsureMap.currentToken == -1) {
                observedScopeMapEnsureMap.currentToken = Long.hashCode(SnapshotKt.currentSnapshot().getSnapshotId());
            }
            DerivedStateObserver derivedStateObserver = observedScopeMapEnsureMap.getDerivedStateObserver();
            mutableVectorDerivedStateObservers = SnapshotStateKt.derivedStateObservers();
            try {
                mutableVectorDerivedStateObservers.add(derivedStateObserver);
                Snapshot.Companion companion = Snapshot.Companion;
            } catch (Throwable th) {
                th = th;
                j4 = j7;
                mutableVector = mutableVectorDerivedStateObservers;
            }
        } catch (Throwable th2) {
            th = th2;
            j4 = j7;
        }
        if (cVar2 != null) {
            Snapshot snapshot = (Snapshot) SnapshotKt.threadSnapshot.get();
            try {
                if (snapshot instanceof TransparentObserverMutableSnapshot) {
                    try {
                        if (((TransparentObserverMutableSnapshot) snapshot).getThreadId$runtime() == Thread_jvmKt.currentThreadId()) {
                            J4.c readObserver$runtime = ((TransparentObserverMutableSnapshot) snapshot).getReadObserver();
                            J4.c writeObserver$runtime = ((TransparentObserverMutableSnapshot) snapshot).getWriteObserver$runtime();
                            try {
                                j6 = j7;
                                try {
                                    ((TransparentObserverMutableSnapshot) snapshot).setReadObserver$runtime(SnapshotKt.mergedReadObserver$default(cVar2, readObserver$runtime, false, 4, null));
                                    ((TransparentObserverMutableSnapshot) snapshot).setWriteObserver$runtime(SnapshotKt.mergedWriteObserver(null, writeObserver$runtime));
                                    aVar.invoke();
                                    ((TransparentObserverMutableSnapshot) snapshot).setReadObserver$runtime(readObserver$runtime);
                                    ((TransparentObserverMutableSnapshot) snapshot).setWriteObserver$runtime(writeObserver$runtime);
                                    mutableVector = mutableVectorDerivedStateObservers;
                                } catch (Throwable th3) {
                                    th = th3;
                                    ((TransparentObserverMutableSnapshot) snapshot).setReadObserver$runtime(readObserver$runtime);
                                    ((TransparentObserverMutableSnapshot) snapshot).setWriteObserver$runtime(writeObserver$runtime);
                                    throw th;
                                }
                            } catch (Throwable th4) {
                                th = th4;
                            }
                        } else {
                            j6 = j7;
                            if (snapshot == null || (snapshot instanceof MutableSnapshot)) {
                                mutableVector = mutableVectorDerivedStateObservers;
                                try {
                                    transparentObserverMutableSnapshot = new TransparentObserverMutableSnapshot(snapshot instanceof MutableSnapshot ? (MutableSnapshot) snapshot : null, cVar2, null, true, false);
                                } catch (Throwable th5) {
                                    th = th5;
                                    j4 = j6;
                                    try {
                                        mutableVector.removeAt(mutableVector.getSize() - 1);
                                        throw th;
                                    } catch (Throwable th6) {
                                        th = th6;
                                    }
                                }
                            } else {
                                transparentObserverMutableSnapshot = snapshot.takeNestedSnapshot(cVar2);
                                mutableVector = mutableVectorDerivedStateObservers;
                            }
                            try {
                                Snapshot snapshotMakeCurrent = transparentObserverMutableSnapshot.makeCurrent();
                                try {
                                    aVar.invoke();
                                    transparentObserverMutableSnapshot.restoreCurrent(snapshotMakeCurrent);
                                    transparentObserverMutableSnapshot.dispose();
                                } catch (Throwable th7) {
                                    j4 = j6;
                                    try {
                                        transparentObserverMutableSnapshot.restoreCurrent(snapshotMakeCurrent);
                                        throw th7;
                                    } catch (Throwable th8) {
                                        th = th8;
                                        try {
                                            transparentObserverMutableSnapshot.dispose();
                                            throw th;
                                        } catch (Throwable th9) {
                                            th = th9;
                                            mutableVector.removeAt(mutableVector.getSize() - 1);
                                            throw th;
                                        }
                                    }
                                }
                            } catch (Throwable th10) {
                                th = th10;
                                j4 = j6;
                            }
                        }
                    } catch (Throwable th11) {
                        th = th11;
                        j6 = j7;
                        mutableVector = mutableVectorDerivedStateObservers;
                        j4 = j6;
                        mutableVector.removeAt(mutableVector.getSize() - 1);
                        throw th;
                    }
                }
            } catch (Throwable th12) {
                th = th12;
            }
            this.currentMap = observedScopeMap;
            this.isPaused = z6;
            this.currentMapThreadId = j4;
            throw th;
        }
        aVar.invoke();
        j6 = j7;
        mutableVector = mutableVectorDerivedStateObservers;
        try {
            mutableVector.removeAt(mutableVector.getSize() - 1);
            Object obj2 = observedScopeMapEnsureMap.currentScope;
            o.e(obj2);
            observedScopeMapEnsureMap.clearObsoleteStateReads(obj2);
            observedScopeMapEnsureMap.currentScope = obj;
            observedScopeMapEnsureMap.currentScopeReads = c2571f;
            observedScopeMapEnsureMap.currentToken = i6;
            this.currentMap = observedScopeMap;
            this.isPaused = z6;
            this.currentMapThreadId = j6;
        } catch (Throwable th13) {
            th = th13;
            j4 = j6;
        }
    }

    public final void start() {
        this.applyUnsubscribe = Snapshot.Companion.registerApplyObserver(this.applyObserver);
    }

    public final void stop() {
        ObserverHandle observerHandle = this.applyUnsubscribe;
        if (observerHandle != null) {
            observerHandle.dispose();
        }
    }

    @InterfaceC3141c
    public final void withNoObservations(J4.a aVar) {
        boolean z6 = this.isPaused;
        this.isPaused = true;
        try {
            aVar.invoke();
        } finally {
            this.isPaused = z6;
        }
    }

    public static final class ObservedScopeMap {
        private Object currentScope;
        private C2571F currentScopeReads;
        private int deriveStateScopeCount;
        private final J4.c onChanged;
        private boolean readingDerivedStates;
        private int currentToken = -1;
        private final N valueToScopes = ScopeMap.m183constructorimpl$default(null, 1, null);
        private final N scopeToValues = new N();
        private final O invalidated = new O();
        private final MutableVector<DerivedState<?>> statesToReread = new MutableVector<>(new DerivedState[16], 0);
        private final DerivedStateObserver derivedStateObserver = new DerivedStateObserver() { // from class: androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap$derivedStateObserver$1
            @Override // androidx.compose.runtime.DerivedStateObserver
            public void done(DerivedState<?> derivedState) {
                this.this$0.deriveStateScopeCount--;
            }

            @Override // androidx.compose.runtime.DerivedStateObserver
            public void start(DerivedState<?> derivedState) {
                this.this$0.deriveStateScopeCount++;
            }
        };
        private final N dependencyToDerivedStates = ScopeMap.m183constructorimpl$default(null, 1, null);
        private final HashMap<DerivedState<?>, Object> recordedDerivedStateValues = new HashMap<>();

        public ObservedScopeMap(J4.c cVar) {
            this.onChanged = cVar;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final void clearObsoleteStateReads(Object obj) {
            int i6 = this.currentToken;
            C2571F c2571f = this.currentScopeReads;
            if (c2571f == null) {
                return;
            }
            long[] jArr = c2571f.f21370a;
            int length = jArr.length - 2;
            if (length < 0) {
                return;
            }
            int i7 = 0;
            while (true) {
                long j4 = jArr[i7];
                if ((((~j4) << 7) & j4 & (-9187201950435737472L)) != -9187201950435737472L) {
                    int i8 = 8 - ((~(i7 - length)) >>> 31);
                    for (int i9 = 0; i9 < i8; i9++) {
                        if ((255 & j4) < 128) {
                            int i10 = (i7 << 3) + i9;
                            Object obj2 = c2571f.f21371b[i10];
                            boolean z6 = c2571f.f21372c[i10] != i6;
                            if (z6) {
                                removeObservation(obj, obj2);
                            }
                            if (z6) {
                                c2571f.f(i10);
                            }
                        }
                        j4 >>= 8;
                    }
                    if (i8 != 8) {
                        return;
                    }
                }
                if (i7 == length) {
                    return;
                } else {
                    i7++;
                }
            }
        }

        private final void removeObservation(Object obj, Object obj2) {
            ScopeMap.m190removeimpl(this.valueToScopes, obj2, obj);
            if (!(obj2 instanceof DerivedState) || ScopeMap.m184containsimpl(this.valueToScopes, obj2)) {
                return;
            }
            ScopeMap.m192removeScopeimpl(this.dependencyToDerivedStates, obj2);
            this.recordedDerivedStateValues.remove(obj2);
        }

        public final void clear() {
            ScopeMap.m181clearimpl(this.valueToScopes);
            this.scopeToValues.f();
            ScopeMap.m181clearimpl(this.dependencyToDerivedStates);
            this.recordedDerivedStateValues.clear();
        }

        public final void clearScopeObservations(Object obj) {
            C2571F c2571f = (C2571F) this.scopeToValues.j(obj);
            if (c2571f == null) {
                return;
            }
            Object[] objArr = c2571f.f21371b;
            int[] iArr = c2571f.f21372c;
            long[] jArr = c2571f.f21370a;
            int length = jArr.length - 2;
            if (length < 0) {
                return;
            }
            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) {
                            int i9 = (i6 << 3) + i8;
                            Object obj2 = objArr[i9];
                            int i10 = iArr[i9];
                            removeObservation(obj, obj2);
                        }
                        j4 >>= 8;
                    }
                    if (i7 != 8) {
                        return;
                    }
                }
                if (i6 == length) {
                    return;
                } else {
                    i6++;
                }
            }
        }

        public final DerivedStateObserver getDerivedStateObserver() {
            return this.derivedStateObserver;
        }

        public final J4.c getOnChanged() {
            return this.onChanged;
        }

        public final boolean getReadingDerivedStates() {
            return this.readingDerivedStates;
        }

        public final boolean hasScopeObservations() {
            return this.scopeToValues.f21385e != 0;
        }

        /* JADX WARN: Removed duplicated region for block: B:14:0x0044  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final void notifyInvalidatedScopes() {
            O o6 = this.invalidated;
            J4.c cVar = this.onChanged;
            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) {
                                cVar.invoke(objArr[(i6 << 3) + i8]);
                            }
                            j4 >>= 8;
                        }
                        if (i7 != 8) {
                            break;
                        } else if (i6 == length) {
                            break;
                        } else {
                            i6++;
                        }
                    }
                }
            }
            o6.e();
        }

        public final void observe(Object obj, J4.c cVar, J4.a aVar) {
            Snapshot transparentObserverMutableSnapshot;
            Object obj2 = this.currentScope;
            C2571F c2571f = this.currentScopeReads;
            int i6 = this.currentToken;
            this.currentScope = obj;
            this.currentScopeReads = (C2571F) this.scopeToValues.d(obj);
            if (this.currentToken == -1) {
                this.currentToken = Long.hashCode(SnapshotKt.currentSnapshot().getSnapshotId());
            }
            DerivedStateObserver derivedStateObserver = getDerivedStateObserver();
            MutableVector<DerivedStateObserver> mutableVectorDerivedStateObservers = SnapshotStateKt.derivedStateObservers();
            try {
                mutableVectorDerivedStateObservers.add(derivedStateObserver);
                Snapshot.Companion companion = Snapshot.Companion;
                if (cVar == null) {
                    aVar.invoke();
                } else {
                    Snapshot snapshot = (Snapshot) SnapshotKt.threadSnapshot.get();
                    if ((snapshot instanceof TransparentObserverMutableSnapshot) && ((TransparentObserverMutableSnapshot) snapshot).getThreadId$runtime() == Thread_jvmKt.currentThreadId()) {
                        J4.c readObserver$runtime = ((TransparentObserverMutableSnapshot) snapshot).getReadObserver();
                        J4.c writeObserver$runtime = ((TransparentObserverMutableSnapshot) snapshot).getWriteObserver$runtime();
                        try {
                            ((TransparentObserverMutableSnapshot) snapshot).setReadObserver$runtime(SnapshotKt.mergedReadObserver$default(cVar, readObserver$runtime, false, 4, null));
                            ((TransparentObserverMutableSnapshot) snapshot).setWriteObserver$runtime(SnapshotKt.mergedWriteObserver(null, writeObserver$runtime));
                            aVar.invoke();
                            ((TransparentObserverMutableSnapshot) snapshot).setReadObserver$runtime(readObserver$runtime);
                            ((TransparentObserverMutableSnapshot) snapshot).setWriteObserver$runtime(writeObserver$runtime);
                        } catch (Throwable th) {
                            ((TransparentObserverMutableSnapshot) snapshot).setReadObserver$runtime(readObserver$runtime);
                            ((TransparentObserverMutableSnapshot) snapshot).setWriteObserver$runtime(writeObserver$runtime);
                            throw th;
                        }
                    } else {
                        if (snapshot == null || (snapshot instanceof MutableSnapshot)) {
                            transparentObserverMutableSnapshot = new TransparentObserverMutableSnapshot(snapshot instanceof MutableSnapshot ? (MutableSnapshot) snapshot : null, cVar, null, true, false);
                        } else {
                            transparentObserverMutableSnapshot = snapshot.takeNestedSnapshot(cVar);
                        }
                        try {
                            Snapshot snapshotMakeCurrent = transparentObserverMutableSnapshot.makeCurrent();
                            try {
                                aVar.invoke();
                                transparentObserverMutableSnapshot.restoreCurrent(snapshotMakeCurrent);
                                transparentObserverMutableSnapshot.dispose();
                            } catch (Throwable th2) {
                                transparentObserverMutableSnapshot.restoreCurrent(snapshotMakeCurrent);
                                throw th2;
                            }
                        } catch (Throwable th3) {
                            transparentObserverMutableSnapshot.dispose();
                            throw th3;
                        }
                    }
                }
                mutableVectorDerivedStateObservers.removeAt(mutableVectorDerivedStateObservers.getSize() - 1);
                Object obj3 = this.currentScope;
                o.e(obj3);
                clearObsoleteStateReads(obj3);
                this.currentScope = obj2;
                this.currentScopeReads = c2571f;
                this.currentToken = i6;
            } catch (Throwable th4) {
                mutableVectorDerivedStateObservers.removeAt(mutableVectorDerivedStateObservers.getSize() - 1);
                throw th4;
            }
        }

        /* JADX WARN: Removed duplicated region for block: B:127:0x029b A[PHI: r21
          0x029b: PHI (r21v12 boolean) = (r21v11 boolean), (r21v13 boolean) binds: [B:118:0x0273, B:126:0x0299] A[DONT_GENERATE, DONT_INLINE]] */
        /* JADX WARN: Removed duplicated region for block: B:234:0x04cd A[PHI: r26
          0x04cd: PHI (r26v13 boolean) = (r26v12 boolean), (r26v14 boolean) binds: [B:225:0x04a5, B:233:0x04cb] A[DONT_GENERATE, DONT_INLINE]] */
        /* JADX WARN: Removed duplicated region for block: B:239:0x04de  */
        /* JADX WARN: Removed duplicated region for block: B:266:0x054a  */
        /* JADX WARN: Removed duplicated region for block: B:62:0x014a A[PHI: r21
          0x014a: PHI (r21v29 boolean) = (r21v28 boolean), (r21v30 boolean) binds: [B:52:0x011f, B:61:0x0148] A[DONT_GENERATE, DONT_INLINE]] */
        /* JADX WARN: Removed duplicated region for block: B:64:0x0155  */
        /* JADX WARN: Removed duplicated region for block: B:99:0x0221 A[PHI: r21
          0x0221: PHI (r21v19 boolean) = (r21v18 boolean), (r21v20 boolean) binds: [B:90:0x01f9, B:98:0x021f] A[DONT_GENERATE, DONT_INLINE]] */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final boolean recordInvalidation(Set<? extends Object> set) {
            boolean z6;
            Iterator it;
            N n6;
            String str;
            int i6;
            boolean z7;
            Object[] objArr;
            Iterator it2;
            N n7;
            String str2;
            int i7;
            Object[] objArr2;
            long j4;
            long[] jArr;
            long[] jArr2;
            long[] jArr3;
            Object[] objArr3;
            int i8;
            long[] jArr4;
            Object[] objArr4;
            int i9;
            int i10;
            int i11;
            long j6;
            int i12;
            int i13;
            int i14;
            int i15;
            int i16;
            long j7;
            int i17;
            N n8 = this.dependencyToDerivedStates;
            HashMap<DerivedState<?>, Object> map = this.recordedDerivedStateValues;
            N n9 = this.valueToScopes;
            O o6 = this.invalidated;
            String str3 = "null cannot be cast to non-null type androidx.compose.runtime.DerivedState<kotlin.Any?>";
            int i18 = 8;
            if (set instanceof ScatterSetWrapper) {
                Z set$runtime = ((ScatterSetWrapper) set).getSet$runtime();
                Object[] objArr5 = set$runtime.f21389b;
                long[] jArr5 = set$runtime.f21388a;
                int length = jArr5.length - 2;
                if (length >= 0) {
                    int i19 = 0;
                    z6 = false;
                    while (true) {
                        long j8 = jArr5[i19];
                        int i20 = length;
                        if ((((~j8) << 7) & j8 & (-9187201950435737472L)) != -9187201950435737472L) {
                            int i21 = 8 - ((~(i19 - i20)) >>> 31);
                            int i22 = 0;
                            while (i22 < i21) {
                                if ((j8 & 255) < 128) {
                                    Object obj = objArr5[(i19 << 3) + i22];
                                    int i23 = i18;
                                    if (!(obj instanceof StateObjectImpl) || ((StateObjectImpl) obj).m269isReadInh_f27i8$runtime(ReaderKind.m257constructorimpl(2))) {
                                        if (this.readingDerivedStates || !ScopeMap.m184containsimpl(n8, obj)) {
                                            jArr4 = jArr5;
                                            objArr4 = objArr5;
                                            i9 = i21;
                                            i10 = i22;
                                            i11 = i19;
                                            j6 = j8;
                                        } else {
                                            this.readingDerivedStates = true;
                                            try {
                                                Object objD = n8.d(obj);
                                                if (objD != null) {
                                                    if (objD instanceof O) {
                                                        O o7 = (O) objD;
                                                        Object[] objArr6 = o7.f21389b;
                                                        long[] jArr6 = o7.f21388a;
                                                        jArr4 = jArr5;
                                                        int length2 = jArr6.length - 2;
                                                        objArr4 = objArr5;
                                                        if (length2 >= 0) {
                                                            j6 = j8;
                                                            int i24 = 0;
                                                            while (true) {
                                                                long j9 = jArr6[i24];
                                                                long[] jArr7 = jArr6;
                                                                Object[] objArr7 = objArr6;
                                                                if ((((~j9) << 7) & j9 & (-9187201950435737472L)) != -9187201950435737472L) {
                                                                    int i25 = 8 - ((~(i24 - length2)) >>> 31);
                                                                    int i26 = 0;
                                                                    while (i26 < i25) {
                                                                        if ((j9 & 255) < 128) {
                                                                            i13 = i26;
                                                                            DerivedState<?> derivedState = (DerivedState) objArr7[(i24 << 3) + i26];
                                                                            o.f(derivedState, "null cannot be cast to non-null type androidx.compose.runtime.DerivedState<kotlin.Any?>");
                                                                            i15 = i22;
                                                                            Object obj2 = map.get(derivedState);
                                                                            SnapshotMutationPolicy<?> policy = derivedState.getPolicy();
                                                                            if (policy == null) {
                                                                                policy = SnapshotStateKt.structuralEqualityPolicy();
                                                                            }
                                                                            j7 = j9;
                                                                            if (policy.equivalent(derivedState.getCurrentRecord().getCurrentValue(), obj2)) {
                                                                                i14 = i21;
                                                                                i16 = i19;
                                                                                this.statesToReread.add(derivedState);
                                                                            } else {
                                                                                Object objD2 = n9.d(derivedState);
                                                                                if (objD2 == null) {
                                                                                    i14 = i21;
                                                                                    i16 = i19;
                                                                                } else if (objD2 instanceof O) {
                                                                                    O o8 = (O) objD2;
                                                                                    Object[] objArr8 = o8.f21389b;
                                                                                    long[] jArr8 = o8.f21388a;
                                                                                    int length3 = jArr8.length - 2;
                                                                                    if (length3 >= 0) {
                                                                                        i16 = i19;
                                                                                        int i27 = 0;
                                                                                        while (true) {
                                                                                            long j10 = jArr8[i27];
                                                                                            long[] jArr9 = jArr8;
                                                                                            i14 = i21;
                                                                                            if ((((~j10) << 7) & j10 & (-9187201950435737472L)) != -9187201950435737472L) {
                                                                                                int i28 = 8 - ((~(i27 - length3)) >>> 31);
                                                                                                int i29 = 0;
                                                                                                while (i29 < i28) {
                                                                                                    if ((j10 & 255) < 128) {
                                                                                                        i17 = i29;
                                                                                                        o6.d(objArr8[(i27 << 3) + i29]);
                                                                                                        z6 = true;
                                                                                                    } else {
                                                                                                        i17 = i29;
                                                                                                    }
                                                                                                    j10 >>= i23;
                                                                                                    i29 = i17 + 1;
                                                                                                }
                                                                                                if (i28 != i23) {
                                                                                                    break;
                                                                                                }
                                                                                                if (i27 == length3) {
                                                                                                    break;
                                                                                                }
                                                                                                i27++;
                                                                                                i21 = i14;
                                                                                                jArr8 = jArr9;
                                                                                                i23 = 8;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                } else {
                                                                                    i14 = i21;
                                                                                    i16 = i19;
                                                                                    o6.d(objD2);
                                                                                    z6 = true;
                                                                                }
                                                                            }
                                                                        } else {
                                                                            i13 = i26;
                                                                            i14 = i21;
                                                                            i15 = i22;
                                                                            i16 = i19;
                                                                            j7 = j9;
                                                                        }
                                                                        j9 = j7 >> 8;
                                                                        i26 = i13 + 1;
                                                                        i23 = 8;
                                                                        i22 = i15;
                                                                        i19 = i16;
                                                                        i21 = i14;
                                                                    }
                                                                    i9 = i21;
                                                                    i10 = i22;
                                                                    i11 = i19;
                                                                    if (i25 != i23) {
                                                                        break;
                                                                    }
                                                                } else {
                                                                    i9 = i21;
                                                                    i10 = i22;
                                                                    i11 = i19;
                                                                }
                                                                if (i24 == length2) {
                                                                    break;
                                                                }
                                                                i24++;
                                                                objArr6 = objArr7;
                                                                jArr6 = jArr7;
                                                                i22 = i10;
                                                                i19 = i11;
                                                                i21 = i9;
                                                                i23 = 8;
                                                            }
                                                        }
                                                    } else {
                                                        jArr4 = jArr5;
                                                        objArr4 = objArr5;
                                                        i9 = i21;
                                                        i10 = i22;
                                                        i11 = i19;
                                                        j6 = j8;
                                                        DerivedState<?> derivedState2 = (DerivedState) objD;
                                                        Object obj3 = map.get(derivedState2);
                                                        SnapshotMutationPolicy<?> policy2 = derivedState2.getPolicy();
                                                        if (policy2 == null) {
                                                            policy2 = SnapshotStateKt.structuralEqualityPolicy();
                                                        }
                                                        if (policy2.equivalent(derivedState2.getCurrentRecord().getCurrentValue(), obj3)) {
                                                            this.statesToReread.add(derivedState2);
                                                        } else {
                                                            Object objD3 = n9.d(derivedState2);
                                                            if (objD3 != null) {
                                                                if (objD3 instanceof O) {
                                                                    O o9 = (O) objD3;
                                                                    Object[] objArr9 = o9.f21389b;
                                                                    long[] jArr10 = o9.f21388a;
                                                                    int length4 = jArr10.length - 2;
                                                                    if (length4 >= 0) {
                                                                        int i30 = 0;
                                                                        while (true) {
                                                                            long j11 = jArr10[i30];
                                                                            if ((((~j11) << 7) & j11 & (-9187201950435737472L)) != -9187201950435737472L) {
                                                                                int i31 = 8 - ((~(i30 - length4)) >>> 31);
                                                                                for (int i32 = 0; i32 < i31; i32++) {
                                                                                    if ((j11 & 255) < 128) {
                                                                                        o6.d(objArr9[(i30 << 3) + i32]);
                                                                                        z6 = true;
                                                                                    }
                                                                                    j11 >>= 8;
                                                                                }
                                                                                if (i31 != 8) {
                                                                                    break;
                                                                                }
                                                                                if (i30 == length4) {
                                                                                    break;
                                                                                }
                                                                                i30++;
                                                                            }
                                                                        }
                                                                    }
                                                                } else {
                                                                    o6.d(objD3);
                                                                    z6 = true;
                                                                }
                                                            }
                                                        }
                                                    }
                                                    this.readingDerivedStates = false;
                                                } else {
                                                    jArr4 = jArr5;
                                                    objArr4 = objArr5;
                                                }
                                                i9 = i21;
                                                i10 = i22;
                                                i11 = i19;
                                                j6 = j8;
                                                this.readingDerivedStates = false;
                                            } finally {
                                            }
                                        }
                                        Object objD4 = n9.d(obj);
                                        if (objD4 != null) {
                                            if (objD4 instanceof O) {
                                                O o10 = (O) objD4;
                                                Object[] objArr10 = o10.f21389b;
                                                long[] jArr11 = o10.f21388a;
                                                int length5 = jArr11.length - 2;
                                                if (length5 >= 0) {
                                                    int i33 = 0;
                                                    while (true) {
                                                        long j12 = jArr11[i33];
                                                        if ((((~j12) << 7) & j12 & (-9187201950435737472L)) != -9187201950435737472L) {
                                                            int i34 = 8 - ((~(i33 - length5)) >>> 31);
                                                            for (int i35 = 0; i35 < i34; i35++) {
                                                                if ((j12 & 255) < 128) {
                                                                    o6.d(objArr10[(i33 << 3) + i35]);
                                                                    z6 = true;
                                                                }
                                                                j12 >>= 8;
                                                            }
                                                            if (i34 != 8) {
                                                                break;
                                                            }
                                                            if (i33 == length5) {
                                                                break;
                                                            }
                                                            i33++;
                                                        }
                                                    }
                                                }
                                            } else {
                                                o6.d(objD4);
                                                z6 = true;
                                            }
                                        }
                                    } else {
                                        jArr4 = jArr5;
                                        objArr4 = objArr5;
                                        i9 = i21;
                                        i10 = i22;
                                        i11 = i19;
                                        j6 = j8;
                                    }
                                    i12 = 8;
                                } else {
                                    jArr4 = jArr5;
                                    objArr4 = objArr5;
                                    i9 = i21;
                                    i10 = i22;
                                    i11 = i19;
                                    j6 = j8;
                                    i12 = i18;
                                }
                                j8 = j6 >> i12;
                                i22 = i10 + 1;
                                i18 = i12;
                                jArr5 = jArr4;
                                objArr5 = objArr4;
                                i19 = i11;
                                i21 = i9;
                            }
                            jArr3 = jArr5;
                            objArr3 = objArr5;
                            int i36 = i19;
                            if (i21 != i18) {
                                break;
                            }
                            i8 = i36;
                        } else {
                            jArr3 = jArr5;
                            objArr3 = objArr5;
                            i8 = i19;
                        }
                        length = i20;
                        if (i8 == length) {
                            break;
                        }
                        i19 = i8 + 1;
                        jArr5 = jArr3;
                        objArr5 = objArr3;
                        i18 = 8;
                    }
                } else {
                    z6 = false;
                }
            } else {
                Iterator it3 = set.iterator();
                boolean z8 = false;
                while (it3.hasNext()) {
                    Object next = it3.next();
                    if (!(next instanceof StateObjectImpl) || ((StateObjectImpl) next).m269isReadInh_f27i8$runtime(ReaderKind.m257constructorimpl(2))) {
                        if (this.readingDerivedStates || !ScopeMap.m184containsimpl(n8, next)) {
                            it = it3;
                            n6 = n8;
                            str = str3;
                            i6 = 0;
                        } else {
                            this.readingDerivedStates = true;
                            try {
                                Object objD5 = n8.d(next);
                                if (objD5 == null) {
                                    it = it3;
                                    n6 = n8;
                                    str = str3;
                                    i6 = 0;
                                    this.readingDerivedStates = false;
                                } else {
                                    if (objD5 instanceof O) {
                                        O o11 = (O) objD5;
                                        Object[] objArr11 = o11.f21389b;
                                        long[] jArr12 = o11.f21388a;
                                        int length6 = jArr12.length - 2;
                                        if (length6 >= 0) {
                                            int i37 = 0;
                                            while (true) {
                                                long j13 = jArr12[i37];
                                                long[] jArr13 = jArr12;
                                                if ((((~j13) << 7) & j13 & (-9187201950435737472L)) != -9187201950435737472L) {
                                                    int i38 = 8 - ((~(i37 - length6)) >>> 31);
                                                    int i39 = 0;
                                                    while (i39 < i38) {
                                                        if ((j13 & 255) < 128) {
                                                            DerivedState<?> derivedState3 = (DerivedState) objArr11[(i37 << 3) + i39];
                                                            o.f(derivedState3, str3);
                                                            it2 = it3;
                                                            Object obj4 = map.get(derivedState3);
                                                            SnapshotMutationPolicy<?> policy3 = derivedState3.getPolicy();
                                                            if (policy3 == null) {
                                                                policy3 = SnapshotStateKt.structuralEqualityPolicy();
                                                            }
                                                            n7 = n8;
                                                            str2 = str3;
                                                            if (policy3.equivalent(derivedState3.getCurrentRecord().getCurrentValue(), obj4)) {
                                                                i7 = i39;
                                                                objArr2 = objArr11;
                                                                j4 = j13;
                                                                this.statesToReread.add(derivedState3);
                                                            } else {
                                                                Object objD6 = n9.d(derivedState3);
                                                                if (objD6 != null) {
                                                                    if (objD6 instanceof O) {
                                                                        O o12 = (O) objD6;
                                                                        Object[] objArr12 = o12.f21389b;
                                                                        long[] jArr14 = o12.f21388a;
                                                                        int length7 = jArr14.length - 2;
                                                                        if (length7 >= 0) {
                                                                            i7 = i39;
                                                                            objArr2 = objArr11;
                                                                            int i40 = 0;
                                                                            while (true) {
                                                                                long j14 = jArr14[i40];
                                                                                j4 = j13;
                                                                                if ((((~j14) << 7) & j14 & (-9187201950435737472L)) != -9187201950435737472L) {
                                                                                    int i41 = 8 - ((~(i40 - length7)) >>> 31);
                                                                                    int i42 = 0;
                                                                                    while (i42 < i41) {
                                                                                        if ((j14 & 255) < 128) {
                                                                                            jArr2 = jArr14;
                                                                                            o6.d(objArr12[(i40 << 3) + i42]);
                                                                                            z8 = true;
                                                                                        } else {
                                                                                            jArr2 = jArr14;
                                                                                        }
                                                                                        j14 >>= 8;
                                                                                        i42++;
                                                                                        jArr14 = jArr2;
                                                                                    }
                                                                                    jArr = jArr14;
                                                                                    if (i41 != 8) {
                                                                                        break;
                                                                                    }
                                                                                } else {
                                                                                    jArr = jArr14;
                                                                                }
                                                                                if (i40 == length7) {
                                                                                    break;
                                                                                }
                                                                                i40++;
                                                                                j13 = j4;
                                                                                jArr14 = jArr;
                                                                            }
                                                                        }
                                                                    } else {
                                                                        i7 = i39;
                                                                        objArr2 = objArr11;
                                                                        j4 = j13;
                                                                        o6.d(objD6);
                                                                        z8 = true;
                                                                    }
                                                                }
                                                            }
                                                            j13 = j4 >> 8;
                                                            i39 = i7 + 1;
                                                            objArr11 = objArr2;
                                                            n8 = n7;
                                                            str3 = str2;
                                                            it3 = it2;
                                                        } else {
                                                            it2 = it3;
                                                            n7 = n8;
                                                            str2 = str3;
                                                        }
                                                        i7 = i39;
                                                        objArr2 = objArr11;
                                                        j4 = j13;
                                                        j13 = j4 >> 8;
                                                        i39 = i7 + 1;
                                                        objArr11 = objArr2;
                                                        n8 = n7;
                                                        str3 = str2;
                                                        it3 = it2;
                                                    }
                                                    it = it3;
                                                    n6 = n8;
                                                    str = str3;
                                                    objArr = objArr11;
                                                    if (i38 != 8) {
                                                        break;
                                                    }
                                                } else {
                                                    it = it3;
                                                    n6 = n8;
                                                    str = str3;
                                                    objArr = objArr11;
                                                }
                                                if (i37 == length6) {
                                                    break;
                                                }
                                                i37++;
                                                it3 = it;
                                                jArr12 = jArr13;
                                                objArr11 = objArr;
                                                n8 = n6;
                                                str3 = str;
                                            }
                                        }
                                    } else {
                                        it = it3;
                                        n6 = n8;
                                        str = str3;
                                        DerivedState<?> derivedState4 = (DerivedState) objD5;
                                        Object obj5 = map.get(derivedState4);
                                        SnapshotMutationPolicy<?> policy4 = derivedState4.getPolicy();
                                        if (policy4 == null) {
                                            policy4 = SnapshotStateKt.structuralEqualityPolicy();
                                        }
                                        if (policy4.equivalent(derivedState4.getCurrentRecord().getCurrentValue(), obj5)) {
                                            this.statesToReread.add(derivedState4);
                                        } else {
                                            Object objD7 = n9.d(derivedState4);
                                            if (objD7 != null) {
                                                if (objD7 instanceof O) {
                                                    O o13 = (O) objD7;
                                                    Object[] objArr13 = o13.f21389b;
                                                    long[] jArr15 = o13.f21388a;
                                                    int length8 = jArr15.length - 2;
                                                    if (length8 >= 0) {
                                                        int i43 = 0;
                                                        while (true) {
                                                            long j15 = jArr15[i43];
                                                            if ((((~j15) << 7) & j15 & (-9187201950435737472L)) != -9187201950435737472L) {
                                                                int i44 = 8 - ((~(i43 - length8)) >>> 31);
                                                                for (int i45 = 0; i45 < i44; i45++) {
                                                                    if ((j15 & 255) < 128) {
                                                                        o6.d(objArr13[(i43 << 3) + i45]);
                                                                        z8 = true;
                                                                    }
                                                                    j15 >>= 8;
                                                                }
                                                                if (i44 != 8) {
                                                                    break;
                                                                }
                                                                if (i43 == length8) {
                                                                    break;
                                                                }
                                                                i43++;
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    o6.d(objD7);
                                                    z8 = true;
                                                }
                                            }
                                        }
                                    }
                                    i6 = 0;
                                    this.readingDerivedStates = false;
                                }
                            } finally {
                            }
                        }
                        Object objD8 = n9.d(next);
                        if (objD8 == null) {
                            z7 = z8;
                            z8 = z7;
                        } else if (objD8 instanceof O) {
                            O o14 = (O) objD8;
                            Object[] objArr14 = o14.f21389b;
                            long[] jArr16 = o14.f21388a;
                            int length9 = jArr16.length - 2;
                            if (length9 >= 0) {
                                int i46 = i6;
                                while (true) {
                                    long j16 = jArr16[i46];
                                    if ((((~j16) << 7) & j16 & (-9187201950435737472L)) != -9187201950435737472L) {
                                        int i47 = 8 - ((~(i46 - length9)) >>> 31);
                                        for (int i48 = i6; i48 < i47; i48++) {
                                            if ((j16 & 255) < 128) {
                                                o6.d(objArr14[(i46 << 3) + i48]);
                                                z8 = true;
                                            }
                                            j16 >>= 8;
                                        }
                                        if (i47 != 8) {
                                            break;
                                        }
                                    }
                                    if (i46 == length9) {
                                        break;
                                    }
                                    i46++;
                                }
                            }
                            z7 = z8;
                            z8 = z7;
                        } else {
                            o6.d(objD8);
                            z7 = true;
                            z8 = z7;
                        }
                    } else {
                        it = it3;
                        n6 = n8;
                        str = str3;
                    }
                    it3 = it;
                    n8 = n6;
                    str3 = str;
                }
                z6 = z8;
            }
            if (!this.readingDerivedStates && this.statesToReread.getSize() != 0) {
                MutableVector<DerivedState<?>> mutableVector = this.statesToReread;
                DerivedState<?>[] derivedStateArr = mutableVector.content;
                int size = mutableVector.getSize();
                for (int i49 = 0; i49 < size; i49++) {
                    rereadDerivedState(derivedStateArr[i49]);
                }
                this.statesToReread.clear();
            }
            return z6;
        }

        public final void recordRead(Object obj) {
            Object obj2 = this.currentScope;
            o.e(obj2);
            int i6 = this.currentToken;
            C2571F c2571f = this.currentScopeReads;
            if (c2571f == null) {
                c2571f = new C2571F();
                this.currentScopeReads = c2571f;
                this.scopeToValues.l(obj2, c2571f);
            }
            recordRead(obj, i6, obj2, c2571f);
        }

        /* JADX WARN: Removed duplicated region for block: B:27:0x009d  */
        /* JADX WARN: Removed duplicated region for block: B:29:0x00a8  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final void removeScopeIf(J4.c cVar) {
            long[] jArr;
            long[] jArr2;
            long j4;
            char c6;
            long j6;
            int i6;
            long j7;
            N n6 = this.scopeToValues;
            long[] jArr3 = n6.f21381a;
            int length = jArr3.length - 2;
            if (length < 0) {
                return;
            }
            int i7 = 0;
            while (true) {
                long j8 = jArr3[i7];
                char c7 = 7;
                long j9 = -9187201950435737472L;
                if ((((~j8) << 7) & j8 & (-9187201950435737472L)) != -9187201950435737472L) {
                    int i8 = 8;
                    int i9 = 8 - ((~(i7 - length)) >>> 31);
                    int i10 = 0;
                    while (i10 < i9) {
                        if ((j8 & 255) < 128) {
                            int i11 = (i7 << 3) + i10;
                            c6 = c7;
                            Object obj = n6.f21382b[i11];
                            j6 = j9;
                            C2571F c2571f = (C2571F) n6.f21383c[i11];
                            Boolean bool = (Boolean) cVar.invoke(obj);
                            if (bool.booleanValue()) {
                                Object[] objArr = c2571f.f21371b;
                                int[] iArr = c2571f.f21372c;
                                long[] jArr4 = c2571f.f21370a;
                                int i12 = i8;
                                int length2 = jArr4.length - 2;
                                if (length2 >= 0) {
                                    jArr2 = jArr3;
                                    j4 = j8;
                                    int i13 = 0;
                                    while (true) {
                                        long j10 = jArr4[i13];
                                        long[] jArr5 = jArr4;
                                        if ((((~j10) << c6) & j10 & j6) != j6) {
                                            int i14 = 8 - ((~(i13 - length2)) >>> 31);
                                            for (int i15 = 0; i15 < i14; i15++) {
                                                if ((j10 & 255) < 128) {
                                                    int i16 = (i13 << 3) + i15;
                                                    j7 = j10;
                                                    Object obj2 = objArr[i16];
                                                    int i17 = iArr[i16];
                                                    removeObservation(obj, obj2);
                                                } else {
                                                    j7 = j10;
                                                }
                                                j10 = j7 >> i12;
                                            }
                                            if (i14 != i12) {
                                                break;
                                            }
                                            if (i13 == length2) {
                                                break;
                                            }
                                            i13++;
                                            jArr4 = jArr5;
                                            i12 = 8;
                                        }
                                    }
                                } else {
                                    jArr2 = jArr3;
                                    j4 = j8;
                                }
                                if (bool.booleanValue()) {
                                    n6.k(i11);
                                }
                                i6 = 8;
                            }
                        } else {
                            jArr2 = jArr3;
                            j4 = j8;
                            c6 = c7;
                            j6 = j9;
                            i6 = i8;
                        }
                        i10++;
                        i8 = i6;
                        j8 = j4 >> i6;
                        c7 = c6;
                        j9 = j6;
                        jArr3 = jArr2;
                    }
                    jArr = jArr3;
                    if (i9 != i8) {
                        return;
                    }
                } else {
                    jArr = jArr3;
                }
                if (i7 == length) {
                    return;
                }
                i7++;
                jArr3 = jArr;
            }
        }

        public final void rereadDerivedState(DerivedState<?> derivedState) {
            N n6 = this.scopeToValues;
            int iHashCode = Long.hashCode(SnapshotKt.currentSnapshot().getSnapshotId());
            Object objD = this.valueToScopes.d(derivedState);
            if (objD == null) {
                return;
            }
            if (!(objD instanceof O)) {
                C2571F c2571f = (C2571F) n6.d(objD);
                if (c2571f == null) {
                    c2571f = new C2571F();
                    n6.l(objD, c2571f);
                }
                recordRead(derivedState, iHashCode, objD, c2571f);
                return;
            }
            O o6 = (O) objD;
            Object[] objArr = o6.f21389b;
            long[] jArr = o6.f21388a;
            int length = jArr.length - 2;
            if (length < 0) {
                return;
            }
            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) {
                            Object obj = objArr[(i6 << 3) + i8];
                            C2571F c2571f2 = (C2571F) n6.d(obj);
                            if (c2571f2 == null) {
                                c2571f2 = new C2571F();
                                n6.l(obj, c2571f2);
                            }
                            recordRead(derivedState, iHashCode, obj, c2571f2);
                        }
                        j4 >>= 8;
                    }
                    if (i7 != 8) {
                        return;
                    }
                }
                if (i6 == length) {
                    return;
                } else {
                    i6++;
                }
            }
        }

        public final void setReadingDerivedStates(boolean z6) {
            this.readingDerivedStates = z6;
        }

        /* JADX WARN: Removed duplicated region for block: B:34:0x00a8  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        private final void recordRead(Object obj, int i6, Object obj2, C2571F c2571f) {
            int i7;
            int i8;
            int i9;
            if (this.deriveStateScopeCount > 0) {
                return;
            }
            int iD = c2571f.d(obj);
            if (iD < 0) {
                iD = ~iD;
                i7 = -1;
            } else {
                i7 = c2571f.f21372c[iD];
            }
            c2571f.f21371b[iD] = obj;
            c2571f.f21372c[iD] = i6;
            int i10 = 2;
            if (!(obj instanceof DerivedState) || i7 == i6) {
                i8 = 2;
            } else {
                DerivedState.Record currentRecord = ((DerivedState) obj).getCurrentRecord();
                this.recordedDerivedStateValues.put(obj, currentRecord.getCurrentValue());
                S dependencies = currentRecord.getDependencies();
                N n6 = this.dependencyToDerivedStates;
                ScopeMap.m192removeScopeimpl(n6, obj);
                Object[] objArr = dependencies.f21371b;
                long[] jArr = dependencies.f21370a;
                int length = jArr.length - 2;
                if (length >= 0) {
                    int i11 = 0;
                    while (true) {
                        long j4 = jArr[i11];
                        if ((((~j4) << 7) & j4 & (-9187201950435737472L)) != -9187201950435737472L) {
                            int i12 = 8 - ((~(i11 - length)) >>> 31);
                            int i13 = 0;
                            while (i13 < i12) {
                                if ((j4 & 255) < 128) {
                                    i9 = i10;
                                    StateObject stateObject = (StateObject) objArr[(i11 << 3) + i13];
                                    if (stateObject instanceof StateObjectImpl) {
                                        ((StateObjectImpl) stateObject).m270recordReadInh_f27i8$runtime(ReaderKind.m257constructorimpl(i9));
                                    }
                                    ScopeMap.m177addimpl(n6, stateObject, obj);
                                } else {
                                    i9 = i10;
                                }
                                j4 >>= 8;
                                i13++;
                                i10 = i9;
                            }
                            i8 = i10;
                            if (i12 != 8) {
                                break;
                            }
                        } else {
                            i8 = i10;
                        }
                        if (i11 == length) {
                            break;
                        }
                        i11++;
                        i10 = i8;
                    }
                }
            }
            if (i7 == -1) {
                if (obj instanceof StateObjectImpl) {
                    ((StateObjectImpl) obj).m270recordReadInh_f27i8$runtime(ReaderKind.m257constructorimpl(i8));
                }
                ScopeMap.m177addimpl(this.valueToScopes, obj, obj2);
            }
        }
    }

    public final void clear() {
        synchronized (this.observedScopeMapsLock) {
            MutableVector<ObservedScopeMap> mutableVector = this.observedScopeMaps;
            ObservedScopeMap[] observedScopeMapArr = mutableVector.content;
            int size = mutableVector.getSize();
            for (int i6 = 0; i6 < size; i6++) {
                observedScopeMapArr[i6].clear();
            }
        }
    }
}
