package androidx.compose.runtime;

import S4.w;
import androidx.compose.runtime.internal.StabilityInferred;
import androidx.compose.runtime.tooling.CompositionData;
import androidx.compose.runtime.tooling.CompositionGroup;
import androidx.media3.common.C;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.jvm.internal.A;
import kotlin.jvm.internal.y;
import n.C2566A;
import n.C2567B;
import x4.AbstractC3250p;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 0)
public final class SlotTable implements CompositionData, Iterable<CompositionGroup>, K4.a {
    public static final int $stable = 8;
    private C2566A calledByMap;
    private int groupsSize;
    private int readers;
    private int slotsSize;
    private HashMap<Anchor, GroupSourceInformation> sourceInformationMap;
    private int version;
    private boolean writer;
    private int[] groups = new int[0];
    private Object[] slots = new Object[0];
    private final Object lock = new Object();
    private ArrayList<Anchor> anchors = new ArrayList<>();

    private final List<Integer> dataIndexes() {
        return SlotTableKt.dataAnchors(this.groups, this.groupsSize * 5);
    }

    private final int emitGroup(StringBuilder sb, int i6, int i7) {
        String sourceInformation;
        for (int i8 = 0; i8 < i7; i8++) {
            sb.append(' ');
        }
        sb.append("Group(");
        sb.append(i6);
        sb.append(")");
        GroupSourceInformation groupSourceInformationSourceInformationOf = sourceInformationOf(i6);
        if (groupSourceInformationSourceInformationOf != null && (sourceInformation = groupSourceInformationSourceInformationOf.getSourceInformation()) != null && (w.A0(sourceInformation, "C(", false) || w.A0(sourceInformation, "CC(", false))) {
            int iO0 = S4.p.O0(sourceInformation, "(", 0, false, 6) + 1;
            int iN0 = S4.p.N0(sourceInformation, ')', 0, 6);
            sb.append(" ");
            String strSubstring = sourceInformation.substring(iO0, iN0);
            kotlin.jvm.internal.o.g(strSubstring, "substring(...)");
            sb.append(strSubstring);
            sb.append("()");
        }
        sb.append(" key=");
        int i9 = i6 * 5;
        sb.append(this.groups[i9]);
        int iGroupSize = SlotTableKt.groupSize(this.groups, i6);
        sb.append(", nodes=");
        int i10 = i9 + 1;
        sb.append(this.groups[i10] & 67108863);
        sb.append(", size=");
        sb.append(iGroupSize);
        if ((this.groups[i10] & C.BUFFER_FLAG_FIRST_SAMPLE) != 0) {
            sb.append(", mark");
        }
        if ((this.groups[i10] & 67108864) != 0) {
            sb.append(", contains mark");
        }
        int iEmitGroup$dataIndex = emitGroup$dataIndex(this, i6);
        int iEmitGroup = i6 + 1;
        int iEmitGroup$dataIndex2 = emitGroup$dataIndex(this, iEmitGroup);
        if (iEmitGroup$dataIndex < 0 || iEmitGroup$dataIndex > iEmitGroup$dataIndex2 || iEmitGroup$dataIndex2 > this.slotsSize) {
            sb.append(", *invalid data offsets " + iEmitGroup$dataIndex + '-' + iEmitGroup$dataIndex2 + '*');
        } else {
            if ((this.groups[i10] & C.BUFFER_FLAG_LAST_SAMPLE) != 0) {
                sb.append(" objectKey=" + SlotTableKt.summarize(String.valueOf(this.slots[SlotTableKt.objectKeyIndex(this.groups, i6)]), 10));
            }
            if ((this.groups[i10] & 1073741824) != 0) {
                sb.append(" node=" + SlotTableKt.summarize(String.valueOf(this.slots[this.groups[i9 + 4]]), 10));
            }
            if ((this.groups[i10] & 268435456) != 0) {
                sb.append(" aux=" + SlotTableKt.summarize(String.valueOf(this.slots[SlotTableKt.auxIndex(this.groups, i6)]), 10));
            }
            int iSlotAnchor = SlotTableKt.slotAnchor(this.groups, i6);
            if (iSlotAnchor < iEmitGroup$dataIndex2) {
                sb.append(", slots=[");
                sb.append(iSlotAnchor);
                sb.append(": ");
                for (int i11 = iSlotAnchor; i11 < iEmitGroup$dataIndex2; i11++) {
                    if (i11 != iSlotAnchor) {
                        sb.append(", ");
                    }
                    sb.append(SlotTableKt.summarize(String.valueOf(this.slots[i11]), 10));
                }
                sb.append("]");
            }
        }
        sb.append('\n');
        int i12 = i6 + iGroupSize;
        while (iEmitGroup < i12) {
            iEmitGroup += emitGroup(sb, iEmitGroup, i7 + 1);
        }
        return iGroupSize;
    }

    private static final int emitGroup$dataIndex(SlotTable slotTable, int i6) {
        return i6 >= slotTable.groupsSize ? slotTable.slotsSize : slotTable.groups[(i6 * 5) + 4];
    }

    private final RecomposeScopeImpl findEffectiveRecomposeScope(int i6) {
        int i7 = i6;
        while (i7 > 0) {
            for (Object obj : new DataIterator(this, i7)) {
                if (obj instanceof RecomposeScopeImpl) {
                    RecomposeScopeImpl recomposeScopeImpl = (RecomposeScopeImpl) obj;
                    if (recomposeScopeImpl.getUsed() && i7 != i6) {
                        return recomposeScopeImpl;
                    }
                    recomposeScopeImpl.setForcedRecompose(true);
                }
            }
            i7 = this.groups[(i7 * 5) + 2];
        }
        return null;
    }

    private final List<Integer> groupSizes() {
        return SlotTableKt.groupSizes(this.groups, this.groupsSize * 5);
    }

    private static final void invalidateGroupsWithKey$lambda$2$scanGroup(SlotReader slotReader, C2567B c2567b, List<Anchor> list, y yVar, SlotTable slotTable, List<RecomposeScopeImpl> list2) {
        RecomposeScopeImpl recomposeScopeImplFindEffectiveRecomposeScope;
        int groupKey = slotReader.getGroupKey();
        if (!c2567b.b(groupKey)) {
            slotReader.startGroup();
            while (!slotReader.isGroupEnd()) {
                invalidateGroupsWithKey$lambda$2$scanGroup(slotReader, c2567b, list, yVar, slotTable, list2);
            }
            slotReader.endGroup();
            return;
        }
        if (groupKey != -3) {
            list.add(SlotReader.anchor$default(slotReader, 0, 1, null));
        }
        if (yVar.f20130a) {
            RecomposeScopeImpl recomposeScopeImplFindEffectiveRecomposeScope2 = slotTable.findEffectiveRecomposeScope(slotReader.getCurrentGroup());
            if (recomposeScopeImplFindEffectiveRecomposeScope2 != null) {
                list2.add(recomposeScopeImplFindEffectiveRecomposeScope2);
                Anchor anchor = recomposeScopeImplFindEffectiveRecomposeScope2.getAnchor();
                if (anchor != null && anchor.getLocation$runtime() == slotReader.getCurrentGroup() && (recomposeScopeImplFindEffectiveRecomposeScope = slotTable.findEffectiveRecomposeScope(slotReader.getParent())) != null) {
                    list2.add(recomposeScopeImplFindEffectiveRecomposeScope);
                }
            } else {
                yVar.f20130a = false;
                list2.clear();
            }
        }
        slotReader.skipGroup();
    }

    private final List<Integer> keys() {
        return SlotTableKt.keys(this.groups, this.groupsSize * 5);
    }

    private final List<Integer> nodes() {
        return SlotTableKt.nodeCounts(this.groups, this.groupsSize * 5);
    }

    private final List<Integer> parentIndexes() {
        return SlotTableKt.parentAnchors(this.groups, this.groupsSize * 5);
    }

    private final Anchor tryAnchor(int i6) {
        int i7;
        if (this.writer) {
            ComposerKt.composeImmediateRuntimeError("use active SlotWriter to crate an anchor for location instead");
        }
        if (i6 < 0 || i6 >= (i7 = this.groupsSize)) {
            return null;
        }
        return SlotTableKt.find(this.anchors, i6, i7);
    }

    private static final int verifyWellFormed$validateGroup(A a6, SlotTable slotTable, int i6, int i7) {
        int i8 = a6.f20113a;
        int i9 = i8 + 1;
        a6.f20113a = i9;
        int i10 = i8 * 5;
        int i11 = slotTable.groups[i10 + 2];
        if (!(i11 == i6)) {
            StringBuilder sbQ = com.google.android.recaptcha.internal.a.q(i8, i6, "Invalid parent index detected at ", ", expected parent index to be ", " found ");
            sbQ.append(i11);
            PreconditionsKt.throwIllegalStateException(sbQ.toString());
        }
        int iGroupSize = SlotTableKt.groupSize(slotTable.groups, i8) + i8;
        if (!(iGroupSize <= slotTable.groupsSize)) {
            PreconditionsKt.throwIllegalStateException("A group extends past the end of the table at " + i8);
        }
        if (!(iGroupSize <= i7)) {
            PreconditionsKt.throwIllegalStateException("A group extends past its parent group at " + i8);
        }
        int[] iArr = slotTable.groups;
        int i12 = i10 + 4;
        int i13 = iArr[i12];
        int i14 = i8 >= slotTable.groupsSize - 1 ? slotTable.slotsSize : iArr[(i9 * 5) + 4];
        if (!(i14 <= slotTable.slots.length)) {
            PreconditionsKt.throwIllegalStateException("Slots for " + i8 + " extend past the end of the slot table");
        }
        if (!(i13 <= i14)) {
            PreconditionsKt.throwIllegalStateException("Invalid data anchor at " + i8);
        }
        if (!(SlotTableKt.slotAnchor(slotTable.groups, i8) <= i14)) {
            PreconditionsKt.throwIllegalStateException("Slots start out of range at " + i8);
        }
        int i15 = i10 + 1;
        int i16 = slotTable.groups[i15];
        if (!(i14 - i13 >= (((i16 & 1073741824) != 0 ? 1 : 0) + ((536870912 & i16) != 0 ? 1 : 0)) + ((i16 & 268435456) != 0 ? 1 : 0))) {
            PreconditionsKt.throwIllegalStateException("Not enough slots added for group " + i8);
        }
        int[] iArr2 = slotTable.groups;
        boolean z6 = (iArr2[i15] & 1073741824) != 0;
        if (!((z6 && slotTable.slots[iArr2[i12]] == null) ? false : true)) {
            PreconditionsKt.throwIllegalStateException("No node recorded for a node group at " + i8);
        }
        int iVerifyWellFormed$validateGroup = 0;
        while (a6.f20113a < iGroupSize) {
            iVerifyWellFormed$validateGroup += verifyWellFormed$validateGroup(a6, slotTable, i8, iGroupSize);
        }
        int[] iArr3 = slotTable.groups;
        int i17 = iArr3[i15] & 67108863;
        int iGroupSize2 = SlotTableKt.groupSize(iArr3, i8);
        if (!(i17 == iVerifyWellFormed$validateGroup)) {
            StringBuilder sbQ2 = com.google.android.recaptcha.internal.a.q(i8, i17, "Incorrect node count detected at ", ", expected ", ", received ");
            sbQ2.append(iVerifyWellFormed$validateGroup);
            PreconditionsKt.throwIllegalStateException(sbQ2.toString());
        }
        int i18 = a6.f20113a - i8;
        if (!(iGroupSize2 == i18)) {
            StringBuilder sbQ3 = com.google.android.recaptcha.internal.a.q(i8, iGroupSize2, "Incorrect slot count detected at ", ", expected ", ", received ");
            sbQ3.append(i18);
            PreconditionsKt.throwIllegalStateException(sbQ3.toString());
        }
        int[] iArr4 = slotTable.groups;
        if ((iArr4[i15] & 201326592) != 0) {
            if (!(i8 <= 0 || (iArr4[(i6 * 5) + 1] & 67108864) != 0)) {
                PreconditionsKt.throwIllegalStateException("Expected group " + i6 + " to record it contains a mark because " + i8 + " does");
            }
        }
        if (z6) {
            return 1;
        }
        return iVerifyWellFormed$validateGroup;
    }

    private static final void verifyWellFormed$verifySourceGroup(SlotTable slotTable, GroupSourceInformation groupSourceInformation) {
        ArrayList<Object> groups = groupSourceInformation.getGroups();
        if (groups != null) {
            int size = groups.size();
            for (int i6 = 0; i6 < size; i6++) {
                Object obj = groups.get(i6);
                if (obj instanceof Anchor) {
                    Anchor anchor = (Anchor) obj;
                    if (!anchor.getValid()) {
                        PreconditionsKt.throwIllegalArgumentException("Source map contains invalid anchor");
                    }
                    if (!slotTable.ownsAnchor(anchor)) {
                        PreconditionsKt.throwIllegalArgumentException("Source map anchor is not owned by the slot table");
                    }
                } else if (obj instanceof GroupSourceInformation) {
                    verifyWellFormed$verifySourceGroup(slotTable, (GroupSourceInformation) obj);
                }
            }
        }
    }

    public final Anchor anchor(int i6) {
        if (this.writer) {
            ComposerKt.composeImmediateRuntimeError("use active SlotWriter to create an anchor location instead");
        }
        boolean z6 = false;
        if (i6 >= 0 && i6 < this.groupsSize) {
            z6 = true;
        }
        if (!z6) {
            PreconditionsKt.throwIllegalArgumentException("Parameter index is out of range");
        }
        ArrayList<Anchor> arrayList = this.anchors;
        int iSearch = SlotTableKt.search(arrayList, i6, this.groupsSize);
        if (iSearch >= 0) {
            return arrayList.get(iSearch);
        }
        Anchor anchor = new Anchor(i6);
        arrayList.add(-(iSearch + 1), anchor);
        return anchor;
    }

    public final int anchorIndex(Anchor anchor) {
        if (this.writer) {
            ComposerKt.composeImmediateRuntimeError("Use active SlotWriter to determine anchor location instead");
        }
        if (!anchor.getValid()) {
            PreconditionsKt.throwIllegalArgumentException("Anchor refers to a group that was removed");
        }
        return anchor.getLocation$runtime();
    }

    public final void close$runtime(SlotReader slotReader, HashMap<Anchor, GroupSourceInformation> map) {
        if (!(slotReader.getTable$runtime() == this && this.readers > 0)) {
            ComposerKt.composeImmediateRuntimeError("Unexpected reader close()");
        }
        this.readers--;
        if (map != null) {
            synchronized (this.lock) {
                try {
                    HashMap<Anchor, GroupSourceInformation> map2 = this.sourceInformationMap;
                    if (map2 != null) {
                        map2.putAll(map);
                    } else {
                        this.sourceInformationMap = map;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
    }

    public final void collectCalledByInformation() {
        this.calledByMap = new C2566A();
    }

    public final void collectSourceInformation() {
        this.sourceInformationMap = new HashMap<>();
    }

    public final boolean containsMark() {
        return this.groupsSize > 0 && (this.groups[1] & 67108864) != 0;
    }

    @Override // androidx.compose.runtime.tooling.CompositionData
    public CompositionGroup find(Object obj) {
        return new SlotTableGroup(this, 0, 0, 4, null).find(obj);
    }

    public final ArrayList<Anchor> getAnchors$runtime() {
        return this.anchors;
    }

    public final C2566A getCalledByMap$runtime() {
        return this.calledByMap;
    }

    @Override // androidx.compose.runtime.tooling.CompositionData
    public Iterable<CompositionGroup> getCompositionGroups() {
        return this;
    }

    public final int[] getGroups() {
        return this.groups;
    }

    public final int getGroupsSize() {
        return this.groupsSize;
    }

    public final Object[] getSlots() {
        return this.slots;
    }

    public final int getSlotsSize() {
        return this.slotsSize;
    }

    public final HashMap<Anchor, GroupSourceInformation> getSourceInformationMap$runtime() {
        return this.sourceInformationMap;
    }

    public final int getVersion$runtime() {
        return this.version;
    }

    public final boolean getWriter$runtime() {
        return this.writer;
    }

    public final boolean groupContainsAnchor(int i6, Anchor anchor) {
        if (this.writer) {
            ComposerKt.composeImmediateRuntimeError("Writer is active");
        }
        if (!(i6 >= 0 && i6 < this.groupsSize)) {
            ComposerKt.composeImmediateRuntimeError("Invalid group index");
        }
        if (ownsAnchor(anchor)) {
            int iGroupSize = SlotTableKt.groupSize(this.groups, i6) + i6;
            int location$runtime = anchor.getLocation$runtime();
            if (i6 <= location$runtime && location$runtime < iGroupSize) {
                return true;
            }
        }
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:18:0x0073  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final List<RecomposeScopeImpl> invalidateGroupsWithKey$runtime(int i6) {
        C2567B c2567b;
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        y yVar = new y();
        yVar.f20130a = true;
        C2567B c2567b2 = new C2567B();
        c2567b2.a(i6);
        c2567b2.a(-3);
        C2566A c2566a = this.calledByMap;
        if (c2566a != null && (c2567b = (C2567B) c2566a.b(i6)) != null) {
            int[] iArr = c2567b.f21313b;
            long[] jArr = c2567b.f21312a;
            int length = jArr.length - 2;
            if (length >= 0) {
                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 ((j4 & 255) < 128) {
                                int i10 = iArr[(i7 << 3) + i9];
                                c2567b2.f21313b[c2567b2.c(i10)] = i10;
                            }
                            j4 >>= 8;
                        }
                        if (i8 != 8) {
                            break;
                        }
                        if (i7 == length) {
                            break;
                        }
                        i7++;
                    }
                }
            }
        }
        SlotReader slotReaderOpenReader = openReader();
        try {
            invalidateGroupsWithKey$lambda$2$scanGroup(slotReaderOpenReader, c2567b2, arrayList, yVar, this, arrayList2);
            slotReaderOpenReader.close();
            SlotWriter slotWriterOpenWriter = openWriter();
            try {
                slotWriterOpenWriter.startGroup();
                int size = arrayList.size();
                for (int i11 = 0; i11 < size; i11++) {
                    Anchor anchor = (Anchor) arrayList.get(i11);
                    if (anchor.toIndexFor(slotWriterOpenWriter) >= slotWriterOpenWriter.getCurrentGroup()) {
                        slotWriterOpenWriter.seek(anchor);
                        slotWriterOpenWriter.bashCurrentGroup();
                    }
                }
                slotWriterOpenWriter.skipToGroupEnd();
                slotWriterOpenWriter.endGroup();
                slotWriterOpenWriter.close(true);
                if (yVar.f20130a) {
                    return arrayList2;
                }
                return null;
            } catch (Throwable th) {
                slotWriterOpenWriter.close(false);
                throw th;
            }
        } catch (Throwable th2) {
            slotReaderOpenReader.close();
            throw th2;
        }
    }

    @Override // androidx.compose.runtime.tooling.CompositionData
    public boolean isEmpty() {
        return this.groupsSize == 0;
    }

    @Override // java.lang.Iterable
    public Iterator<CompositionGroup> iterator() {
        return new GroupIterator(this, 0, this.groupsSize);
    }

    public final SlotReader openReader() {
        if (this.writer) {
            throw new IllegalStateException("Cannot read while a writer is pending");
        }
        this.readers++;
        return new SlotReader(this);
    }

    public final SlotWriter openWriter() {
        if (this.writer) {
            ComposerKt.composeImmediateRuntimeError("Cannot start a writer when another writer is pending");
        }
        if (!(this.readers <= 0)) {
            ComposerKt.composeImmediateRuntimeError("Cannot start a writer when a reader is pending");
        }
        this.writer = true;
        this.version++;
        return new SlotWriter(this);
    }

    public final boolean ownsAnchor(Anchor anchor) {
        int iSearch;
        return anchor.getValid() && (iSearch = SlotTableKt.search(this.anchors, anchor.getLocation$runtime(), this.groupsSize)) >= 0 && kotlin.jvm.internal.o.c(this.anchors.get(iSearch), anchor);
    }

    public final <T> T read(J4.c cVar) {
        SlotReader slotReaderOpenReader = openReader();
        try {
            return (T) cVar.invoke(slotReaderOpenReader);
        } finally {
            slotReaderOpenReader.close();
        }
    }

    public final void setAnchors$runtime(ArrayList<Anchor> arrayList) {
        this.anchors = arrayList;
    }

    public final void setCalledByMap$runtime(C2566A c2566a) {
        this.calledByMap = c2566a;
    }

    public final void setSourceInformationMap$runtime(HashMap<Anchor, GroupSourceInformation> map) {
        this.sourceInformationMap = map;
    }

    public final void setTo$runtime(int[] iArr, int i6, Object[] objArr, int i7, ArrayList<Anchor> arrayList, HashMap<Anchor, GroupSourceInformation> map, C2566A c2566a) {
        this.groups = iArr;
        this.groupsSize = i6;
        this.slots = objArr;
        this.slotsSize = i7;
        this.anchors = arrayList;
        this.sourceInformationMap = map;
        this.calledByMap = c2566a;
    }

    public final void setVersion$runtime(int i6) {
        this.version = i6;
    }

    public final Object slot$runtime(int i6, int i7) {
        int iSlotAnchor = SlotTableKt.slotAnchor(this.groups, i6);
        int i8 = i6 + 1;
        return (i7 < 0 || i7 >= (i8 < this.groupsSize ? this.groups[(i8 * 5) + 4] : this.slots.length) - iSlotAnchor) ? Composer.Companion.getEmpty() : this.slots[iSlotAnchor + i7];
    }

    public final List<Object> slotsOf$runtime(int i6) {
        int[] iArr = this.groups;
        int i7 = iArr[(i6 * 5) + 4];
        int i8 = i6 + 1;
        return AbstractC3250p.X(this.slots).subList(i7, i8 < this.groupsSize ? iArr[(i8 * 5) + 4] : this.slots.length);
    }

    public final GroupSourceInformation sourceInformationOf(int i6) {
        Anchor anchorTryAnchor;
        HashMap<Anchor, GroupSourceInformation> map = this.sourceInformationMap;
        if (map == null || (anchorTryAnchor = tryAnchor(i6)) == null) {
            return null;
        }
        return map.get(anchorTryAnchor);
    }

    public final String toDebugString() {
        if (this.writer) {
            return toString();
        }
        StringBuilder sb = new StringBuilder();
        sb.append(toString());
        sb.append('\n');
        int i6 = this.groupsSize;
        if (i6 > 0) {
            int iEmitGroup = 0;
            while (iEmitGroup < i6) {
                iEmitGroup += emitGroup(sb, iEmitGroup, 0);
            }
        } else {
            sb.append("<EMPTY>");
        }
        String string = sb.toString();
        kotlin.jvm.internal.o.g(string, "toString(...)");
        return string;
    }

    public final void verifyWellFormed() {
        int i6;
        int i7;
        A a6 = new A();
        int i8 = -1;
        if (this.groupsSize > 0) {
            while (true) {
                i6 = a6.f20113a;
                i7 = this.groupsSize;
                if (i6 >= i7) {
                    break;
                } else {
                    verifyWellFormed$validateGroup(a6, this, -1, SlotTableKt.groupSize(this.groups, i6) + i6);
                }
            }
            if (!(i6 == i7)) {
                PreconditionsKt.throwIllegalStateException("Incomplete group at root " + a6.f20113a + " expected to be " + this.groupsSize);
            }
        }
        int length = this.slots.length;
        for (int i9 = this.slotsSize; i9 < length; i9++) {
            if (!(this.slots[i9] == null)) {
                PreconditionsKt.throwIllegalStateException("Non null value in the slot gap at index " + i9);
            }
        }
        ArrayList<Anchor> arrayList = this.anchors;
        int size = arrayList.size();
        int i10 = 0;
        while (i10 < size) {
            int indexFor = arrayList.get(i10).toIndexFor(this);
            if (!(indexFor >= 0 && indexFor <= this.groupsSize)) {
                PreconditionsKt.throwIllegalArgumentException("Invalid anchor, location out of bound");
            }
            if (!(i8 < indexFor)) {
                PreconditionsKt.throwIllegalArgumentException("Anchor is out of order");
            }
            i10++;
            i8 = indexFor;
        }
        HashMap<Anchor, GroupSourceInformation> map = this.sourceInformationMap;
        if (map != null) {
            for (Map.Entry<Anchor, GroupSourceInformation> entry : map.entrySet()) {
                Anchor key = entry.getKey();
                GroupSourceInformation value = entry.getValue();
                if (!key.getValid()) {
                    PreconditionsKt.throwIllegalArgumentException("Source map contains invalid anchor");
                }
                if (!ownsAnchor(key)) {
                    PreconditionsKt.throwIllegalArgumentException("Source map anchor is not owned by the slot table");
                }
                verifyWellFormed$verifySourceGroup(this, value);
            }
        }
    }

    public final <T> T write(J4.c cVar) {
        SlotWriter slotWriterOpenWriter = openWriter();
        try {
            T t6 = (T) cVar.invoke(slotWriterOpenWriter);
            slotWriterOpenWriter.close(true);
            return t6;
        } catch (Throwable th) {
            slotWriterOpenWriter.close(false);
            throw th;
        }
    }

    public final void close$runtime(SlotWriter slotWriter, int[] iArr, int i6, Object[] objArr, int i7, ArrayList<Anchor> arrayList, HashMap<Anchor, GroupSourceInformation> map, C2566A c2566a) {
        if (!(slotWriter.getTable$runtime() == this && this.writer)) {
            PreconditionsKt.throwIllegalArgumentException("Unexpected writer close()");
        }
        this.writer = false;
        setTo$runtime(iArr, i6, objArr, i7, arrayList, map, c2566a);
    }
}
