package androidx.compose.runtime.snapshots;

import A4.g;
import C4.i;
import R4.m;
import androidx.compose.runtime.Immutable;
import java.util.ArrayList;
import java.util.Iterator;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;
import m3.AbstractC2467b;
import w4.C3137A;
import x4.AbstractC3253s;

/* JADX INFO: loaded from: classes.dex */
@Immutable
public final class SnapshotIdSet implements Iterable<Long>, K4.a {
    public static final int $stable = 0;
    public static final Companion Companion = new Companion(null);
    private static final SnapshotIdSet EMPTY = new SnapshotIdSet(0, 0, 0, null);
    private final long[] belowBound;
    private final long lowerBound;
    private final long lowerSet;
    private final long upperSet;

    public static final class Companion {
        public /* synthetic */ Companion(h hVar) {
            this();
        }

        public final SnapshotIdSet getEMPTY() {
            return SnapshotIdSet.EMPTY;
        }

        private Companion() {
        }
    }

    /* JADX INFO: renamed from: androidx.compose.runtime.snapshots.SnapshotIdSet$iterator$1, reason: invalid class name */
    @C4.e(c = "androidx.compose.runtime.snapshots.SnapshotIdSet$iterator$1", f = "SnapshotIdSet.kt", l = {252, 256, 263}, m = "invokeSuspend", v = 1)
    public static final class AnonymousClass1 extends i implements J4.e {
        int I$0;
        int I$1;
        private /* synthetic */ Object L$0;
        Object L$1;
        int label;

        public AnonymousClass1(A4.d dVar) {
            super(2, dVar);
        }

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

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

        /* JADX WARN: Removed duplicated region for block: B:20:0x007b  */
        /* JADX WARN: Removed duplicated region for block: B:22:0x007f  */
        /* JADX WARN: Removed duplicated region for block: B:27:0x00aa  */
        /* JADX WARN: Removed duplicated region for block: B:30:0x00b5  */
        /* JADX WARN: Removed duplicated region for block: B:32:0x00b8  */
        /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:23:0x008b -> B:26:0x00a8). Please report as a decompilation issue!!! */
        /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:36:0x00e2 -> B:37:0x00e3). Please report as a decompilation issue!!! */
        @Override // C4.a
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            m mVar;
            long[] jArr;
            int length;
            int i6;
            int i7;
            m mVar2;
            m mVar3;
            B4.a aVar = B4.a.f492a;
            int i8 = this.label;
            int i9 = 0;
            if (i8 == 0) {
                AbstractC2467b.l(obj);
                mVar = (m) this.L$0;
                jArr = SnapshotIdSet.this.belowBound;
                if (jArr != null) {
                    length = jArr.length;
                    i6 = 0;
                }
                if (SnapshotIdSet.this.lowerSet != 0) {
                    i7 = 0;
                    mVar2 = mVar;
                    if (i7 >= 64) {
                    }
                }
                if (SnapshotIdSet.this.upperSet != 0) {
                }
                return C3137A.f25453a;
            }
            if (i8 == 1) {
                length = this.I$1;
                int i10 = this.I$0;
                jArr = (long[]) this.L$1;
                mVar = (m) this.L$0;
                AbstractC2467b.l(obj);
                i6 = i10 + 1;
            } else {
                if (i8 != 2) {
                    if (i8 != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    int i11 = this.I$0;
                    mVar3 = (m) this.L$0;
                    AbstractC2467b.l(obj);
                    i9 = i11 + 1;
                    if (i9 < 64) {
                        if ((SnapshotIdSet.this.upperSet & (1 << i9)) != 0) {
                            Long l = new Long(SnapshotIdSet.this.lowerBound + ((long) i9) + ((long) 64));
                            this.L$0 = mVar3;
                            this.L$1 = null;
                            this.I$0 = i9;
                            this.label = 3;
                            mVar3.a(this, l);
                            B4.a aVar2 = B4.a.f492a;
                            return aVar;
                        }
                        i11 = i9;
                        i9 = i11 + 1;
                        if (i9 < 64) {
                        }
                    }
                    return C3137A.f25453a;
                }
                i7 = this.I$0;
                mVar2 = (m) this.L$0;
                AbstractC2467b.l(obj);
                i7++;
                if (i7 >= 64) {
                    mVar = mVar2;
                    if (SnapshotIdSet.this.upperSet != 0) {
                        mVar3 = mVar;
                        if (i9 < 64) {
                        }
                    }
                    return C3137A.f25453a;
                }
                if ((SnapshotIdSet.this.lowerSet & (1 << i7)) != 0) {
                    Long l6 = new Long(SnapshotIdSet.this.lowerBound + ((long) i7));
                    this.L$0 = mVar2;
                    this.L$1 = null;
                    this.I$0 = i7;
                    this.label = 2;
                    mVar2.a(this, l6);
                    B4.a aVar3 = B4.a.f492a;
                    return aVar;
                }
                i7++;
                if (i7 >= 64) {
                }
            }
            if (i6 < length) {
                Long l7 = new Long(jArr[i6]);
                this.L$0 = mVar;
                this.L$1 = jArr;
                this.I$0 = i6;
                this.I$1 = length;
                this.label = 1;
                mVar.a(this, l7);
                return aVar;
            }
            if (SnapshotIdSet.this.lowerSet != 0) {
            }
            if (SnapshotIdSet.this.upperSet != 0) {
            }
            return C3137A.f25453a;
        }
    }

    private SnapshotIdSet(long j4, long j6, long j7, long[] jArr) {
        this.upperSet = j4;
        this.lowerSet = j6;
        this.lowerBound = j7;
        this.belowBound = jArr;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r12v0, types: [androidx.compose.runtime.snapshots.SnapshotIdSet] */
    /* JADX WARN: Type inference failed for: r12v1 */
    /* JADX WARN: Type inference failed for: r12v10, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r12v11, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r12v13 */
    /* JADX WARN: Type inference failed for: r12v14 */
    /* JADX WARN: Type inference failed for: r12v15 */
    /* JADX WARN: Type inference failed for: r12v16 */
    /* JADX WARN: Type inference failed for: r12v17 */
    /* JADX WARN: Type inference failed for: r12v18 */
    /* JADX WARN: Type inference failed for: r12v2 */
    /* JADX WARN: Type inference failed for: r12v3 */
    /* JADX WARN: Type inference failed for: r12v5, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r12v6 */
    /* JADX WARN: Type inference failed for: r12v7, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r12v8, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r12v9 */
    /* JADX WARN: Type inference failed for: r13v0, types: [J4.e] */
    private final SnapshotIdSet fastFold(SnapshotIdSet snapshotIdSet, J4.e eVar) {
        long[] jArr = this.belowBound;
        int i6 = 0;
        if (jArr != null) {
            int length = jArr.length;
            int i7 = 0;
            snapshotIdSet = snapshotIdSet;
            while (i7 < length) {
                Object objInvoke = eVar.invoke(snapshotIdSet, Long.valueOf(jArr[i7]));
                i7++;
                snapshotIdSet = objInvoke;
            }
        }
        if (this.lowerSet != 0) {
            int i8 = 0;
            snapshotIdSet = snapshotIdSet;
            while (i8 < 64) {
                if ((this.lowerSet & (1 << i8)) != 0) {
                    snapshotIdSet = eVar.invoke(snapshotIdSet, Long.valueOf(this.lowerBound + ((long) i8)));
                }
                i8++;
                snapshotIdSet = snapshotIdSet;
            }
        }
        snapshotIdSet = snapshotIdSet;
        if (this.upperSet != 0) {
            while (i6 < 64) {
                if ((this.upperSet & (1 << i6)) != 0) {
                    snapshotIdSet = eVar.invoke(snapshotIdSet, Long.valueOf(this.lowerBound + ((long) i6) + ((long) 64)));
                }
                i6++;
                snapshotIdSet = snapshotIdSet;
            }
        }
        return (SnapshotIdSet) snapshotIdSet;
    }

    public final SnapshotIdSet and(SnapshotIdSet snapshotIdSet) {
        SnapshotIdSet snapshotIdSet2 = EMPTY;
        if (o.c(snapshotIdSet, snapshotIdSet2) || equals(snapshotIdSet2)) {
            return snapshotIdSet2;
        }
        long j4 = snapshotIdSet.lowerBound;
        long j6 = this.lowerBound;
        if (j4 == j6) {
            long[] jArr = snapshotIdSet.belowBound;
            long[] jArr2 = this.belowBound;
            if (jArr == jArr2) {
                long j7 = this.upperSet;
                long j8 = snapshotIdSet.upperSet;
                long j9 = j7 & j8;
                long j10 = this.lowerSet;
                long j11 = snapshotIdSet.lowerSet;
                return (j9 == 0 && (j10 & j11) == 0 && jArr2 == null) ? snapshotIdSet2 : new SnapshotIdSet(j7 & j8, j10 & j11, j6, jArr2);
            }
        }
        SnapshotIdSet snapshotIdSet3 = snapshotIdSet2;
        int i6 = 0;
        if (this.belowBound == null) {
            long[] jArr3 = this.belowBound;
            if (jArr3 != null) {
                for (long j12 : jArr3) {
                    if (snapshotIdSet.get(j12)) {
                        snapshotIdSet3 = snapshotIdSet3.set(j12);
                    }
                }
            }
            SnapshotIdSet snapshotIdSet4 = snapshotIdSet3;
            if (this.lowerSet != 0) {
                for (int i7 = 0; i7 < 64; i7++) {
                    if ((this.lowerSet & (1 << i7)) != 0) {
                        long j13 = this.lowerBound + ((long) i7);
                        if (snapshotIdSet.get(j13)) {
                            snapshotIdSet4 = snapshotIdSet4.set(j13);
                        }
                    }
                }
            }
            if (this.upperSet != 0) {
                while (i6 < 64) {
                    if ((this.upperSet & (1 << i6)) != 0) {
                        long j14 = this.lowerBound + ((long) i6) + ((long) 64);
                        if (snapshotIdSet.get(j14)) {
                            snapshotIdSet4 = snapshotIdSet4.set(j14);
                        }
                    }
                    i6++;
                }
            }
            return snapshotIdSet4;
        }
        long[] jArr4 = snapshotIdSet.belowBound;
        if (jArr4 != null) {
            for (long j15 : jArr4) {
                if (get(j15)) {
                    snapshotIdSet3 = snapshotIdSet3.set(j15);
                }
            }
        }
        SnapshotIdSet snapshotIdSet5 = snapshotIdSet3;
        if (snapshotIdSet.lowerSet != 0) {
            for (int i8 = 0; i8 < 64; i8++) {
                if ((snapshotIdSet.lowerSet & (1 << i8)) != 0) {
                    long j16 = snapshotIdSet.lowerBound + ((long) i8);
                    if (get(j16)) {
                        snapshotIdSet5 = snapshotIdSet5.set(j16);
                    }
                }
            }
        }
        if (snapshotIdSet.upperSet != 0) {
            while (i6 < 64) {
                if ((snapshotIdSet.upperSet & (1 << i6)) != 0) {
                    long j17 = snapshotIdSet.lowerBound + ((long) i6) + ((long) 64);
                    if (get(j17)) {
                        snapshotIdSet5 = snapshotIdSet5.set(j17);
                    }
                }
                i6++;
            }
        }
        return snapshotIdSet5;
    }

    public final SnapshotIdSet andNot(SnapshotIdSet snapshotIdSet) {
        SnapshotIdSet snapshotIdSetClear;
        SnapshotIdSet snapshotIdSet2 = EMPTY;
        if (snapshotIdSet == snapshotIdSet2) {
            return this;
        }
        if (this == snapshotIdSet2) {
            return snapshotIdSet2;
        }
        long j4 = snapshotIdSet.lowerBound;
        long j6 = this.lowerBound;
        if (j4 == j6) {
            long[] jArr = snapshotIdSet.belowBound;
            long[] jArr2 = this.belowBound;
            if (jArr == jArr2) {
                return new SnapshotIdSet((~snapshotIdSet.upperSet) & this.upperSet, (~snapshotIdSet.lowerSet) & this.lowerSet, j6, jArr2);
            }
        }
        long[] jArr3 = snapshotIdSet.belowBound;
        if (jArr3 != null) {
            snapshotIdSetClear = this;
            for (long j7 : jArr3) {
                snapshotIdSetClear = snapshotIdSetClear.clear(j7);
            }
        } else {
            snapshotIdSetClear = this;
        }
        if (snapshotIdSet.lowerSet != 0) {
            for (int i6 = 0; i6 < 64; i6++) {
                if ((snapshotIdSet.lowerSet & (1 << i6)) != 0) {
                    snapshotIdSetClear = snapshotIdSetClear.clear(snapshotIdSet.lowerBound + ((long) i6));
                }
            }
        }
        if (snapshotIdSet.upperSet != 0) {
            for (int i7 = 0; i7 < 64; i7++) {
                if ((snapshotIdSet.upperSet & (1 << i7)) != 0) {
                    snapshotIdSetClear = snapshotIdSetClear.clear(snapshotIdSet.lowerBound + ((long) i7) + ((long) 64));
                }
            }
        }
        return snapshotIdSetClear;
    }

    public final SnapshotIdSet clear(long j4) {
        long[] jArr;
        int iBinarySearch;
        long j6 = j4 - this.lowerBound;
        long j7 = 0;
        if (o.j(j6, j7) >= 0 && o.j(j6, 64) < 0) {
            long j8 = 1 << ((int) j6);
            long j9 = this.lowerSet;
            if ((j9 & j8) != 0) {
                return new SnapshotIdSet(this.upperSet, j9 & (~j8), this.lowerBound, this.belowBound);
            }
        } else if (o.j(j6, 64) >= 0 && o.j(j6, 128) < 0) {
            long j10 = 1 << (((int) j6) - 64);
            long j11 = this.upperSet;
            if ((j11 & j10) != 0) {
                return new SnapshotIdSet(j11 & (~j10), this.lowerSet, this.lowerBound, this.belowBound);
            }
        } else if (o.j(j6, j7) < 0 && (jArr = this.belowBound) != null && (iBinarySearch = SnapshotId_jvmKt.binarySearch(jArr, j4)) >= 0) {
            return new SnapshotIdSet(this.upperSet, this.lowerSet, this.lowerBound, SnapshotId_jvmKt.withIdRemovedAt(jArr, iBinarySearch));
        }
        return this;
    }

    public final void fastForEach(J4.c cVar) {
        long[] jArr = this.belowBound;
        if (jArr != null) {
            for (long j4 : jArr) {
                cVar.invoke(Long.valueOf(j4));
            }
        }
        if (this.lowerSet != 0) {
            for (int i6 = 0; i6 < 64; i6++) {
                if ((this.lowerSet & (1 << i6)) != 0) {
                    cVar.invoke(Long.valueOf(this.lowerBound + ((long) i6)));
                }
            }
        }
        if (this.upperSet != 0) {
            for (int i7 = 0; i7 < 64; i7++) {
                if ((this.upperSet & (1 << i7)) != 0) {
                    cVar.invoke(Long.valueOf(this.lowerBound + ((long) i7) + ((long) 64)));
                }
            }
        }
    }

    public final boolean get(long j4) {
        long[] jArr;
        long j6 = j4 - this.lowerBound;
        long j7 = 0;
        return (o.j(j6, j7) < 0 || o.j(j6, (long) 64) >= 0) ? (o.j(j6, (long) 64) < 0 || o.j(j6, (long) 128) >= 0) ? o.j(j6, j7) <= 0 && (jArr = this.belowBound) != null && SnapshotId_jvmKt.binarySearch(jArr, j4) >= 0 : ((1 << (((int) j6) - 64)) & this.upperSet) != 0 : ((1 << ((int) j6)) & this.lowerSet) != 0;
    }

    @Override // java.lang.Iterable
    public Iterator<Long> iterator() {
        return g.L(new AnonymousClass1(null));
    }

    public final long lowest(long j4) {
        long[] jArr = this.belowBound;
        if (jArr != null) {
            return jArr[0];
        }
        long j6 = this.lowerSet;
        if (j6 != 0) {
            return this.lowerBound + ((long) Long.numberOfTrailingZeros(j6));
        }
        long j7 = this.upperSet;
        return j7 != 0 ? this.lowerBound + ((long) 64) + ((long) Long.numberOfTrailingZeros(j7)) : j4;
    }

    public final SnapshotIdSet or(SnapshotIdSet snapshotIdSet) {
        SnapshotIdSet snapshotIdSet2;
        SnapshotIdSet snapshotIdSet3 = EMPTY;
        if (snapshotIdSet == snapshotIdSet3) {
            return this;
        }
        if (this == snapshotIdSet3) {
            return snapshotIdSet;
        }
        long j4 = snapshotIdSet.lowerBound;
        long j6 = this.lowerBound;
        if (j4 == j6) {
            long[] jArr = snapshotIdSet.belowBound;
            long[] jArr2 = this.belowBound;
            if (jArr == jArr2) {
                return new SnapshotIdSet(snapshotIdSet.upperSet | this.upperSet, snapshotIdSet.lowerSet | this.lowerSet, j6, jArr2);
            }
        }
        int i6 = 0;
        if (this.belowBound == null) {
            long[] jArr3 = this.belowBound;
            if (jArr3 != null) {
                for (long j7 : jArr3) {
                    snapshotIdSet = snapshotIdSet.set(j7);
                }
            }
            if (this.lowerSet != 0) {
                for (int i7 = 0; i7 < 64; i7++) {
                    if ((this.lowerSet & (1 << i7)) != 0) {
                        snapshotIdSet = snapshotIdSet.set(this.lowerBound + ((long) i7));
                    }
                }
            }
            if (this.upperSet != 0) {
                while (i6 < 64) {
                    if ((this.upperSet & (1 << i6)) != 0) {
                        snapshotIdSet = snapshotIdSet.set(this.lowerBound + ((long) i6) + ((long) 64));
                    }
                    i6++;
                }
            }
            return snapshotIdSet;
        }
        long[] jArr4 = snapshotIdSet.belowBound;
        if (jArr4 != null) {
            snapshotIdSet2 = this;
            for (long j8 : jArr4) {
                snapshotIdSet2 = snapshotIdSet2.set(j8);
            }
        } else {
            snapshotIdSet2 = this;
        }
        if (snapshotIdSet.lowerSet != 0) {
            for (int i8 = 0; i8 < 64; i8++) {
                if ((snapshotIdSet.lowerSet & (1 << i8)) != 0) {
                    snapshotIdSet2 = snapshotIdSet2.set(snapshotIdSet.lowerBound + ((long) i8));
                }
            }
        }
        if (snapshotIdSet.upperSet != 0) {
            while (i6 < 64) {
                if ((snapshotIdSet.upperSet & (1 << i6)) != 0) {
                    snapshotIdSet2 = snapshotIdSet2.set(snapshotIdSet.lowerBound + ((long) i6) + ((long) 64));
                }
                i6++;
            }
        }
        return snapshotIdSet2;
    }

    public final SnapshotIdSet set(long j4) {
        long j6;
        long j7;
        long[] array;
        long j8 = j4 - this.lowerBound;
        long j9 = 0;
        if (o.j(j8, j9) < 0 || o.j(j8, 64) >= 0) {
            long j10 = 64;
            if (o.j(j8, j10) < 0 || o.j(j8, 128) >= 0) {
                long j11 = 128;
                if (o.j(j8, j11) < 0) {
                    long[] jArr = this.belowBound;
                    if (jArr == null) {
                        return new SnapshotIdSet(this.upperSet, this.lowerSet, this.lowerBound, new long[]{j4});
                    }
                    int iBinarySearch = SnapshotId_jvmKt.binarySearch(jArr, j4);
                    if (iBinarySearch < 0) {
                        return new SnapshotIdSet(this.upperSet, this.lowerSet, this.lowerBound, SnapshotId_jvmKt.withIdInsertedAt(jArr, -(iBinarySearch + 1), j4));
                    }
                } else if (!get(j4)) {
                    long j12 = this.upperSet;
                    long j13 = this.lowerSet;
                    long j14 = this.lowerBound;
                    long j15 = 1;
                    long j16 = ((j4 + j15) / j10) * j10;
                    if (o.j(j16, j9) < 0) {
                        j16 = (Long.MAX_VALUE - j11) + j15;
                    }
                    SnapshotIdArrayBuilder snapshotIdArrayBuilder = null;
                    long j17 = j12;
                    while (true) {
                        if (o.j(j14, j16) >= 0) {
                            j6 = j14;
                            j7 = j13;
                            break;
                        }
                        if (j13 != 0) {
                            if (snapshotIdArrayBuilder == null) {
                                snapshotIdArrayBuilder = new SnapshotIdArrayBuilder(this.belowBound);
                            }
                            for (int i6 = 0; i6 < 64; i6++) {
                                if (((1 << i6) & j13) != 0) {
                                    snapshotIdArrayBuilder.add(((long) i6) + j14);
                                }
                            }
                        }
                        if (j17 == 0) {
                            j6 = j16;
                            j7 = 0;
                            break;
                        }
                        j14 += j10;
                        j13 = j17;
                        j17 = 0;
                    }
                    if (snapshotIdArrayBuilder == null || (array = snapshotIdArrayBuilder.toArray()) == null) {
                        array = this.belowBound;
                    }
                    return new SnapshotIdSet(j17, j7, j6, array).set(j4);
                }
            } else {
                long j18 = 1 << (((int) j8) - 64);
                long j19 = this.upperSet;
                if ((j19 & j18) == 0) {
                    return new SnapshotIdSet(j19 | j18, this.lowerSet, this.lowerBound, this.belowBound);
                }
            }
        } else {
            long j20 = 1 << ((int) j8);
            long j21 = this.lowerSet;
            if ((j21 & j20) == 0) {
                return new SnapshotIdSet(this.upperSet, j21 | j20, this.lowerBound, this.belowBound);
            }
        }
        return this;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        sb.append(" [");
        ArrayList arrayList = new ArrayList(AbstractC3253s.G(this, 10));
        Iterator<Long> it = iterator();
        while (it.hasNext()) {
            arrayList.add(String.valueOf(it.next().longValue()));
        }
        return Z0.o.r(sb, ListUtilsKt.fastJoinToString$default(arrayList, null, null, null, 0, null, null, 63, null), ']');
    }
}
