package androidx.compose.runtime;

import androidx.compose.runtime.Composer;
import androidx.compose.runtime.internal.StabilityInferred;
import androidx.media3.common.C;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import n.AbstractC2589p;
import n.C2566A;
import n.C2567B;
import n.C2598z;
import n.J;
import o.AbstractC2628a;
import x4.AbstractC3250p;
import x4.AbstractC3251q;
import x4.y;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 0)
public final class SlotWriter {
    private ArrayList<Anchor> anchors;
    private C2566A calledByMap;
    private boolean closed;
    private int currentGroup;
    private int currentGroupEnd;
    private int currentSlot;
    private int currentSlotEnd;
    private C2566A deferredSlotWrites;
    private int groupGapLen;
    private int groupGapStart;
    private int[] groups;
    private int insertCount;
    private int nodeCount;
    private C2598z pendingRecalculateMarks;
    private Object[] slots;
    private int slotsGapLen;
    private int slotsGapOwner;
    private int slotsGapStart;
    private HashMap<Anchor, GroupSourceInformation> sourceInformationMap;
    private final SlotTable table;
    public static final Companion Companion = new Companion(null);
    public static final int $stable = 8;
    private final IntStack startStack = new IntStack();
    private final IntStack endStack = new IntStack();
    private final IntStack nodeCountStack = new IntStack();
    private int parent = -1;

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

        /* JADX INFO: Access modifiers changed from: private */
        public final List<Anchor> moveGroup(SlotWriter slotWriter, int i6, SlotWriter slotWriter2, boolean z6, boolean z7, boolean z8) {
            boolean zRemoveGroups;
            List<Anchor> list;
            int iGroupSize = slotWriter.groupSize(i6);
            int i7 = i6 + iGroupSize;
            int iDataIndex = slotWriter.dataIndex(i6);
            int iDataIndex2 = slotWriter.dataIndex(i7);
            int i8 = iDataIndex2 - iDataIndex;
            boolean zContainsAnyGroupMarks = slotWriter.containsAnyGroupMarks(i6);
            slotWriter2.insertGroups(iGroupSize);
            slotWriter2.insertSlots(i8, slotWriter2.getCurrentGroup());
            if (slotWriter.groupGapStart < i7) {
                slotWriter.moveGroupGapTo(i7);
            }
            if (slotWriter.slotsGapStart < iDataIndex2) {
                slotWriter.moveSlotGapTo(iDataIndex2, i7);
            }
            int[] iArr = slotWriter2.groups;
            int currentGroup = slotWriter2.getCurrentGroup();
            int i9 = currentGroup * 5;
            AbstractC3250p.x(i9, i6 * 5, i7 * 5, slotWriter.groups, iArr);
            Object[] objArr = slotWriter2.slots;
            int i10 = slotWriter2.currentSlot;
            System.arraycopy(slotWriter.slots, iDataIndex, objArr, i10, i8);
            int parent = slotWriter2.getParent();
            iArr[i9 + 2] = parent;
            int i11 = currentGroup - i6;
            int i12 = currentGroup + iGroupSize;
            int iDataIndex3 = i10 - slotWriter2.dataIndex(iArr, currentGroup);
            int i13 = slotWriter2.slotsGapOwner;
            int i14 = slotWriter2.slotsGapLen;
            int length = objArr.length;
            int i15 = i13;
            int i16 = currentGroup;
            while (true) {
                zRemoveGroups = false;
                if (i16 >= i12) {
                    break;
                }
                if (i16 != currentGroup) {
                    int i17 = (i16 * 5) + 2;
                    iArr[i17] = iArr[i17] + i11;
                }
                int[] iArr2 = iArr;
                int i18 = currentGroup;
                iArr2[(i16 * 5) + 4] = slotWriter2.dataIndexToDataAnchor(slotWriter2.dataIndex(iArr, i16) + iDataIndex3, i15 >= i16 ? slotWriter2.slotsGapStart : 0, i14, length);
                if (i16 == i15) {
                    i15++;
                }
                i16++;
                currentGroup = i18;
                iArr = iArr2;
            }
            int[] iArr3 = iArr;
            slotWriter2.slotsGapOwner = i15;
            int iLocationOf = SlotTableKt.locationOf(slotWriter.anchors, i6, slotWriter.getSize$runtime());
            int iLocationOf2 = SlotTableKt.locationOf(slotWriter.anchors, i7, slotWriter.getSize$runtime());
            if (iLocationOf < iLocationOf2) {
                ArrayList arrayList = slotWriter.anchors;
                ArrayList arrayList2 = new ArrayList(iLocationOf2 - iLocationOf);
                for (int i19 = iLocationOf; i19 < iLocationOf2; i19++) {
                    Anchor anchor = (Anchor) arrayList.get(i19);
                    anchor.setLocation$runtime(anchor.getLocation$runtime() + i11);
                    arrayList2.add(anchor);
                }
                slotWriter2.anchors.addAll(SlotTableKt.locationOf(slotWriter2.anchors, slotWriter2.getCurrentGroup(), slotWriter2.getSize$runtime()), arrayList2);
                arrayList.subList(iLocationOf, iLocationOf2).clear();
                list = arrayList2;
            } else {
                list = y.f26065a;
            }
            if (!list.isEmpty()) {
                HashMap map = slotWriter.sourceInformationMap;
                HashMap map2 = slotWriter2.sourceInformationMap;
                if (map != null && map2 != null) {
                    int size = list.size();
                    for (int i20 = 0; i20 < size; i20++) {
                        Anchor anchor2 = list.get(i20);
                        GroupSourceInformation groupSourceInformation = (GroupSourceInformation) map.get(anchor2);
                        if (groupSourceInformation != null) {
                            map.remove(anchor2);
                            map2.put(anchor2, groupSourceInformation);
                        }
                    }
                }
            }
            int parent2 = slotWriter2.getParent();
            GroupSourceInformation groupSourceInformationSourceInformationOf$runtime = slotWriter2.sourceInformationOf$runtime(parent);
            if (groupSourceInformationSourceInformationOf$runtime != null) {
                int iGroupSize2 = parent2 + 1;
                int currentGroup2 = slotWriter2.getCurrentGroup();
                int i21 = -1;
                while (iGroupSize2 < currentGroup2) {
                    i21 = iGroupSize2;
                    iGroupSize2 = SlotTableKt.groupSize(slotWriter2.groups, iGroupSize2) + iGroupSize2;
                }
                groupSourceInformationSourceInformationOf$runtime.addGroupAfter(slotWriter2, i21, currentGroup2);
            }
            int iParent = slotWriter.parent(i6);
            if (z8) {
                if (z6) {
                    boolean z9 = iParent >= 0;
                    if (z9) {
                        slotWriter.startGroup();
                        slotWriter.advanceBy(iParent - slotWriter.getCurrentGroup());
                        slotWriter.startGroup();
                    }
                    slotWriter.advanceBy(i6 - slotWriter.getCurrentGroup());
                    boolean zRemoveGroup = slotWriter.removeGroup();
                    if (z9) {
                        slotWriter.skipToGroupEnd();
                        slotWriter.endGroup();
                        slotWriter.skipToGroupEnd();
                        slotWriter.endGroup();
                    }
                    zRemoveGroups = zRemoveGroup;
                } else {
                    zRemoveGroups = slotWriter.removeGroups(i6, iGroupSize);
                    slotWriter.removeSlots(iDataIndex, i8, i6 - 1);
                }
            }
            if (zRemoveGroups) {
                ComposerKt.composeImmediateRuntimeError("Unexpectedly removed anchors");
            }
            int i22 = slotWriter2.nodeCount;
            int i23 = iArr3[i9 + 1];
            slotWriter2.nodeCount = i22 + ((1073741824 & i23) == 0 ? i23 & 67108863 : 1);
            if (z7) {
                slotWriter2.currentGroup = i12;
                slotWriter2.currentSlot = i10 + i8;
            }
            if (zContainsAnyGroupMarks) {
                slotWriter2.updateContainsMark(parent);
            }
            return list;
        }

        public static /* synthetic */ List moveGroup$default(Companion companion, SlotWriter slotWriter, int i6, SlotWriter slotWriter2, boolean z6, boolean z7, boolean z8, int i7, Object obj) {
            if ((i7 & 32) != 0) {
                z8 = true;
            }
            return companion.moveGroup(slotWriter, i6, slotWriter2, z6, z7, z8);
        }

        private Companion() {
        }
    }

    /* JADX INFO: renamed from: androidx.compose.runtime.SlotWriter$groupSlots$1, reason: invalid class name */
    public static final class AnonymousClass1 implements Iterator<Object>, K4.a {
        final /* synthetic */ int $end;
        private int current;
        final /* synthetic */ SlotWriter this$0;

        public AnonymousClass1(int i6, int i7, SlotWriter slotWriter) {
            this.$end = i7;
            this.this$0 = slotWriter;
            this.current = i6;
        }

        public final int getCurrent() {
            return this.current;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            return this.current < this.$end;
        }

        @Override // java.util.Iterator
        public Object next() {
            if (!hasNext()) {
                return null;
            }
            Object[] objArr = this.this$0.slots;
            SlotWriter slotWriter = this.this$0;
            int i6 = this.current;
            this.current = i6 + 1;
            return objArr[slotWriter.dataIndexToDataAddress(i6)];
        }

        @Override // java.util.Iterator
        public void remove() {
            throw new UnsupportedOperationException("Operation is not supported for read-only collection");
        }

        public final void setCurrent(int i6) {
            this.current = i6;
        }
    }

    public SlotWriter(SlotTable slotTable) {
        this.table = slotTable;
        this.groups = slotTable.getGroups();
        this.slots = slotTable.getSlots();
        this.anchors = slotTable.getAnchors$runtime();
        this.sourceInformationMap = slotTable.getSourceInformationMap$runtime();
        this.calledByMap = slotTable.getCalledByMap$runtime();
        this.groupGapStart = slotTable.getGroupsSize();
        this.groupGapLen = (this.groups.length / 5) - slotTable.getGroupsSize();
        this.slotsGapStart = slotTable.getSlotsSize();
        this.slotsGapLen = this.slots.length - slotTable.getSlotsSize();
        this.slotsGapOwner = slotTable.getGroupsSize();
        this.currentGroupEnd = slotTable.getGroupsSize();
    }

    public static /* synthetic */ Anchor anchor$default(SlotWriter slotWriter, int i6, int i7, Object obj) {
        if ((i7 & 1) != 0) {
            i6 = slotWriter.currentGroup;
        }
        return slotWriter.anchor(i6);
    }

    private final int auxIndex(int[] iArr, int i6) {
        return Integer.bitCount(iArr[(i6 * 5) + 1] >> 29) + dataIndex(iArr, i6);
    }

    private final boolean childContainsAnyMarks(int i6) {
        int iGroupSize = i6 + 1;
        int iGroupSize2 = groupSize(i6) + i6;
        while (iGroupSize < iGroupSize2) {
            if ((this.groups[(groupIndexToAddress(iGroupSize) * 5) + 1] & 201326592) != 0) {
                return true;
            }
            iGroupSize += groupSize(iGroupSize);
        }
        return false;
    }

    private final int childGroupAtIndex(int i6, int i7) {
        int iGroupSize = groupSize(i6) + i6;
        int iGroupSize2 = i6 + 1;
        int i8 = 0;
        while (iGroupSize2 < iGroupSize && i8 < i7) {
            int iGroupIndexToAddress = groupIndexToAddress(iGroupSize2);
            iGroupSize2 += SlotTableKt.groupSize(this.groups, iGroupIndexToAddress);
            if (iGroupSize2 < iGroupSize && (this.groups[(iGroupIndexToAddress * 5) + 1] & C.BUFFER_FLAG_LAST_SAMPLE) == 0) {
                i8++;
            }
        }
        return iGroupSize2;
    }

    private final void clearSlotGap() {
        int i6 = this.slotsGapStart;
        AbstractC3250p.H(this.slots, null, i6, this.slotsGapLen + i6);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean containsAnyGroupMarks(int i6) {
        return i6 >= 0 && (this.groups[(groupIndexToAddress(i6) * 5) + 1] & 201326592) != 0;
    }

    private final boolean containsGroupMark(int i6) {
        return i6 >= 0 && (this.groups[(groupIndexToAddress(i6) * 5) + 1] & 67108864) != 0;
    }

    private final int dataAnchorToDataIndex(int i6, int i7, int i8) {
        return i6 < 0 ? (i8 - i7) + i6 + 1 : i6;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int dataIndex(int i6) {
        return dataIndex(this.groups, groupIndexToAddress(i6));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int dataIndexToDataAddress(int i6) {
        return (this.slotsGapLen * (i6 < this.slotsGapStart ? 0 : 1)) + i6;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int dataIndexToDataAnchor(int i6, int i7, int i8, int i9) {
        return i6 > i7 ? -(((i9 - i8) - i6) + 1) : i6;
    }

    private final List<Integer> dataIndexes(int[] iArr) {
        List listDataAnchors$default = SlotTableKt.dataAnchors$default(this.groups, 0, 1, null);
        ArrayList arrayListS0 = AbstractC3251q.s0(AbstractC3251q.v0(listDataAnchors$default, L4.a.l0(this.groupGapStart + this.groupGapLen, iArr.length / 5)), AbstractC3251q.v0(listDataAnchors$default, L4.a.l0(0, this.groupGapStart)));
        ArrayList arrayList = new ArrayList(arrayListS0.size());
        int size = arrayListS0.size();
        for (int i6 = 0; i6 < size; i6++) {
            arrayList.add(Integer.valueOf(dataAnchorToDataIndex(((Number) arrayListS0.get(i6)).intValue(), this.slotsGapLen, this.slots.length)));
        }
        return arrayList;
    }

    private final void fixParentAnchorsFor(int i6, int i7, int i8) {
        int iParentIndexToAnchor = parentIndexToAnchor(i6, this.groupGapStart);
        while (i8 < i7) {
            this.groups[(groupIndexToAddress(i8) * 5) + 2] = iParentIndexToAnchor;
            int iGroupSize = SlotTableKt.groupSize(this.groups, groupIndexToAddress(i8)) + i8;
            fixParentAnchorsFor(i8, iGroupSize, i8 + 1);
            i8 = iGroupSize;
        }
    }

    private final int getCapacity() {
        return this.groups.length / 5;
    }

    private final int getCurrentGroupSlotIndex() {
        return groupSlotIndex(this.parent);
    }

    private final void groupAsString(StringBuilder sb, int i6) {
        int iGroupIndexToAddress = groupIndexToAddress(i6);
        sb.append("Group(");
        if (i6 < 10) {
            sb.append(' ');
        }
        if (i6 < 100) {
            sb.append(' ');
        }
        if (i6 < 1000) {
            sb.append(' ');
        }
        sb.append(i6);
        if (iGroupIndexToAddress != i6) {
            sb.append("(");
            sb.append(iGroupIndexToAddress);
            sb.append(")");
        }
        sb.append('#');
        sb.append(SlotTableKt.groupSize(this.groups, iGroupIndexToAddress));
        sb.append('^');
        int i7 = iGroupIndexToAddress * 5;
        int i8 = i7 + 2;
        sb.append(parentAnchorToIndex(this.groups[i8]));
        sb.append(": key=");
        sb.append(this.groups[i7]);
        sb.append(", nodes=");
        int i9 = i7 + 1;
        sb.append(this.groups[i9] & 67108863);
        sb.append(", dataAnchor=");
        sb.append(this.groups[i7 + 4]);
        sb.append(", parentAnchor=");
        sb.append(this.groups[i8]);
        if ((this.groups[i9] & 1073741824) != 0) {
            sb.append(", node=" + SlotTableKt.summarize(String.valueOf(this.slots[dataIndexToDataAddress(nodeIndex(this.groups, iGroupIndexToAddress))]), 10));
        }
        int iSlotIndex = slotIndex(this.groups, iGroupIndexToAddress);
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(i6 + 1));
        if (iDataIndex > iSlotIndex) {
            sb.append(", [");
            for (int i10 = iSlotIndex; i10 < iDataIndex; i10++) {
                if (i10 != iSlotIndex) {
                    sb.append(", ");
                }
                sb.append(SlotTableKt.summarize(String.valueOf(this.slots[dataIndexToDataAddress(i10)]), 10));
            }
            sb.append(']');
        }
        sb.append(")");
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int groupIndexToAddress(int i6) {
        return (this.groupGapLen * (i6 < this.groupGapStart ? 0 : 1)) + i6;
    }

    private final GroupSourceInformation groupSourceInformationFor(int i6, String str) {
        HashMap<Anchor, GroupSourceInformation> map = this.sourceInformationMap;
        if (map == null) {
            return null;
        }
        Anchor anchor = anchor(i6);
        GroupSourceInformation groupSourceInformation = map.get(anchor);
        if (groupSourceInformation == null) {
            groupSourceInformation = new GroupSourceInformation(0, str, 0);
            if (str == null) {
                int iGroupSize = i6 + 1;
                int i7 = this.currentGroup;
                while (iGroupSize < i7) {
                    groupSourceInformation.reportGroup(this, iGroupSize);
                    iGroupSize += SlotTableKt.groupSize(this.groups, iGroupSize);
                }
            }
            map.put(anchor, groupSourceInformation);
        }
        return groupSourceInformation;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void insertGroups(int i6) {
        if (i6 > 0) {
            int i7 = this.currentGroup;
            moveGroupGapTo(i7);
            int i8 = this.groupGapStart;
            int i9 = this.groupGapLen;
            int[] iArr = this.groups;
            int length = iArr.length / 5;
            int i10 = length - i9;
            if (i9 < i6) {
                int iMax = Math.max(Math.max(length * 2, i10 + i6), 32);
                int[] iArr2 = new int[iMax * 5];
                int i11 = iMax - i10;
                AbstractC3250p.x(0, 0, i8 * 5, iArr, iArr2);
                AbstractC3250p.x((i8 + i11) * 5, (i9 + i8) * 5, length * 5, iArr, iArr2);
                this.groups = iArr2;
                i9 = i11;
            }
            int i12 = this.currentGroupEnd;
            if (i12 >= i8) {
                this.currentGroupEnd = i12 + i6;
            }
            int i13 = i8 + i6;
            this.groupGapStart = i13;
            this.groupGapLen = i9 - i6;
            int iDataIndexToDataAnchor = dataIndexToDataAnchor(i10 > 0 ? dataIndex(i7 + i6) : 0, this.slotsGapOwner >= i8 ? this.slotsGapStart : 0, this.slotsGapLen, this.slots.length);
            for (int i14 = i8; i14 < i13; i14++) {
                this.groups[(i14 * 5) + 4] = iDataIndexToDataAnchor;
            }
            int i15 = this.slotsGapOwner;
            if (i15 >= i8) {
                this.slotsGapOwner = i15 + i6;
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void insertSlots(int i6, int i7) {
        if (i6 > 0) {
            moveSlotGapTo(this.currentSlot, i7);
            int i8 = this.slotsGapStart;
            int i9 = this.slotsGapLen;
            if (i9 < i6) {
                Object[] objArr = this.slots;
                int length = objArr.length;
                int i10 = length - i9;
                int iMax = Math.max(Math.max(length * 2, i10 + i6), 32);
                Object[] objArr2 = new Object[iMax];
                for (int i11 = 0; i11 < iMax; i11++) {
                    objArr2[i11] = null;
                }
                int i12 = iMax - i10;
                int i13 = i9 + i8;
                System.arraycopy(objArr, 0, objArr2, 0, i8);
                System.arraycopy(objArr, i13, objArr2, i8 + i12, length - i13);
                this.slots = objArr2;
                i9 = i12;
            }
            int i14 = this.currentSlotEnd;
            if (i14 >= i8) {
                this.currentSlotEnd = i14 + i6;
            }
            this.slotsGapStart = i8 + i6;
            this.slotsGapLen = i9 - i6;
        }
    }

    private final List<Integer> keys() {
        List listKeys$default = SlotTableKt.keys$default(this.groups, 0, 1, null);
        ArrayList arrayList = new ArrayList(listKeys$default.size());
        int size = listKeys$default.size();
        for (int i6 = 0; i6 < size; i6++) {
            Object obj = listKeys$default.get(i6);
            ((Number) obj).intValue();
            int i7 = this.groupGapStart;
            if (i6 < i7 || i6 >= i7 + this.groupGapLen) {
                arrayList.add(obj);
            }
        }
        return arrayList;
    }

    public static /* synthetic */ void markGroup$default(SlotWriter slotWriter, int i6, int i7, Object obj) {
        if ((i7 & 1) != 0) {
            i6 = slotWriter.parent;
        }
        slotWriter.markGroup(i6);
    }

    private final void moveAnchors(int i6, int i7, int i8) {
        Anchor anchor;
        int iAnchorIndex;
        int i9 = i8 + i6;
        int size$runtime = getSize$runtime();
        int iLocationOf = SlotTableKt.locationOf(this.anchors, i6, size$runtime);
        ArrayList arrayList = new ArrayList();
        if (iLocationOf >= 0) {
            while (iLocationOf < this.anchors.size() && (iAnchorIndex = anchorIndex((anchor = this.anchors.get(iLocationOf)))) >= i6 && iAnchorIndex < i9) {
                arrayList.add(anchor);
                this.anchors.remove(iLocationOf);
            }
        }
        int i10 = i7 - i6;
        int size = arrayList.size();
        for (int i11 = 0; i11 < size; i11++) {
            Anchor anchor2 = (Anchor) arrayList.get(i11);
            int iAnchorIndex2 = anchorIndex(anchor2) + i10;
            if (iAnchorIndex2 >= this.groupGapStart) {
                anchor2.setLocation$runtime(-(size$runtime - iAnchorIndex2));
            } else {
                anchor2.setLocation$runtime(iAnchorIndex2);
            }
            this.anchors.add(SlotTableKt.locationOf(this.anchors, iAnchorIndex2, size$runtime), anchor2);
        }
    }

    public static /* synthetic */ List moveFrom$default(SlotWriter slotWriter, SlotTable slotTable, int i6, boolean z6, int i7, Object obj) {
        if ((i7 & 4) != 0) {
            z6 = true;
        }
        return slotWriter.moveFrom(slotTable, i6, z6);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void moveGroupGapTo(int i6) {
        int i7 = this.groupGapLen;
        int i8 = this.groupGapStart;
        if (i8 != i6) {
            if (!this.anchors.isEmpty()) {
                updateAnchors(i8, i6);
            }
            if (i7 > 0) {
                int[] iArr = this.groups;
                int i9 = i6 * 5;
                int i10 = i7 * 5;
                int i11 = i8 * 5;
                if (i6 < i8) {
                    AbstractC3250p.x(i10 + i9, i9, i11, iArr, iArr);
                } else {
                    AbstractC3250p.x(i11, i11 + i10, i9 + i10, iArr, iArr);
                }
            }
            if (i6 < i8) {
                i8 = i6 + i7;
            }
            int capacity = getCapacity();
            if (i8 >= capacity) {
                ComposerKt.composeImmediateRuntimeError("Check failed");
            }
            while (i8 < capacity) {
                int i12 = (i8 * 5) + 2;
                int i13 = this.groups[i12];
                int iParentIndexToAnchor = parentIndexToAnchor(parentAnchorToIndex(i13), i6);
                if (iParentIndexToAnchor != i13) {
                    this.groups[i12] = iParentIndexToAnchor;
                }
                i8++;
                if (i8 == i6) {
                    i8 += i7;
                }
            }
        }
        this.groupGapStart = i6;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void moveSlotGapTo(int i6, int i7) {
        int i8 = this.slotsGapLen;
        int i9 = this.slotsGapStart;
        int i10 = this.slotsGapOwner;
        if (i9 != i6) {
            Object[] objArr = this.slots;
            if (i6 < i9) {
                System.arraycopy(objArr, i6, objArr, i6 + i8, i9 - i6);
            } else {
                int i11 = i9 + i8;
                System.arraycopy(objArr, i11, objArr, i9, (i6 + i8) - i11);
            }
        }
        int iMin = Math.min(i7 + 1, getSize$runtime());
        if (i10 != iMin) {
            int length = this.slots.length - i8;
            if (iMin < i10) {
                int iGroupIndexToAddress = groupIndexToAddress(iMin);
                int iGroupIndexToAddress2 = groupIndexToAddress(i10);
                int i12 = this.groupGapStart;
                while (iGroupIndexToAddress < iGroupIndexToAddress2) {
                    int i13 = (iGroupIndexToAddress * 5) + 4;
                    int i14 = this.groups[i13];
                    if (!(i14 >= 0)) {
                        ComposerKt.composeImmediateRuntimeError("Unexpected anchor value, expected a positive anchor");
                    }
                    this.groups[i13] = -((length - i14) + 1);
                    iGroupIndexToAddress++;
                    if (iGroupIndexToAddress == i12) {
                        iGroupIndexToAddress += this.groupGapLen;
                    }
                }
            } else {
                int iGroupIndexToAddress3 = groupIndexToAddress(i10);
                int iGroupIndexToAddress4 = groupIndexToAddress(iMin);
                while (iGroupIndexToAddress3 < iGroupIndexToAddress4) {
                    int i15 = (iGroupIndexToAddress3 * 5) + 4;
                    int i16 = this.groups[i15];
                    if (!(i16 < 0)) {
                        ComposerKt.composeImmediateRuntimeError("Unexpected anchor value, expected a negative anchor");
                    }
                    this.groups[i15] = i16 + length + 1;
                    iGroupIndexToAddress3++;
                    if (iGroupIndexToAddress3 == this.groupGapStart) {
                        iGroupIndexToAddress3 += this.groupGapLen;
                    }
                }
            }
            this.slotsGapOwner = iMin;
        }
        this.slotsGapStart = i6;
    }

    private final int nodeIndex(int[] iArr, int i6) {
        return dataIndex(iArr, i6);
    }

    private final int parentAnchorToIndex(int i6) {
        return i6 > -2 ? i6 : (getSize$runtime() + i6) - (-2);
    }

    private final int parentIndexToAnchor(int i6, int i7) {
        return i6 < i7 ? i6 : -((getSize$runtime() - i6) + 2);
    }

    private final Object rawUpdate(Object obj) {
        Object objSkip = skip();
        set(obj);
        return objSkip;
    }

    private final void recalculateMarks() {
        C2598z c2598z = this.pendingRecalculateMarks;
        if (c2598z != null) {
            while (PrioritySet.m48isNotEmptyimpl(c2598z)) {
                m62updateContainsMarkNowXpTMRCE(PrioritySet.m50takeMaximpl(c2598z), c2598z);
            }
        }
    }

    private final boolean removeAnchors(int i6, int i7, HashMap<Anchor, GroupSourceInformation> map) {
        int i8 = i7 + i6;
        int iLocationOf = SlotTableKt.locationOf(this.anchors, i8, getCapacity() - this.groupGapLen);
        if (iLocationOf >= this.anchors.size()) {
            iLocationOf--;
        }
        int i9 = iLocationOf + 1;
        int i10 = 0;
        while (iLocationOf >= 0) {
            Anchor anchor = this.anchors.get(iLocationOf);
            int iAnchorIndex = anchorIndex(anchor);
            if (iAnchorIndex < i6) {
                break;
            }
            if (iAnchorIndex < i8) {
                anchor.setLocation$runtime(Integer.MIN_VALUE);
                if (map != null) {
                    map.remove(anchor);
                }
                if (i10 == 0) {
                    i10 = iLocationOf + 1;
                }
                i9 = iLocationOf;
            }
            iLocationOf--;
        }
        boolean z6 = i9 < i10;
        if (z6) {
            this.anchors.subList(i9, i10).clear();
        }
        return z6;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean removeGroups(int i6, int i7) {
        if (i7 > 0) {
            ArrayList<Anchor> arrayList = this.anchors;
            moveGroupGapTo(i6);
            zRemoveAnchors = arrayList.isEmpty() ? false : removeAnchors(i6, i7, this.sourceInformationMap);
            this.groupGapStart = i6;
            this.groupGapLen += i7;
            int i8 = this.slotsGapOwner;
            if (i8 > i6) {
                this.slotsGapOwner = Math.max(i6, i8 - i7);
            }
            int i9 = this.currentGroupEnd;
            if (i9 >= this.groupGapStart) {
                this.currentGroupEnd = i9 - i7;
            }
            int i10 = this.parent;
            if (containsGroupMark(i10)) {
                updateContainsMark(i10);
            }
        }
        return zRemoveAnchors;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void removeSlots(int i6, int i7, int i8) {
        if (i7 > 0) {
            int i9 = this.slotsGapLen;
            int i10 = i6 + i7;
            moveSlotGapTo(i10, i8);
            this.slotsGapStart = i6;
            this.slotsGapLen = i9 + i7;
            AbstractC3250p.H(this.slots, null, i6, i10);
            int i11 = this.currentSlotEnd;
            if (i11 >= i6) {
                this.currentSlotEnd = i11 - i7;
            }
        }
    }

    private final int restoreCurrentGroupEnd() {
        int capacity = (getCapacity() - this.groupGapLen) - this.endStack.pop();
        this.currentGroupEnd = capacity;
        return capacity;
    }

    private final void saveCurrentGroupEnd() {
        this.endStack.push((getCapacity() - this.groupGapLen) - this.currentGroupEnd);
    }

    private final int slotIndex(int[] iArr, int i6) {
        return i6 >= getCapacity() ? this.slots.length - this.slotsGapLen : dataAnchorToDataIndex(SlotTableKt.slotAnchor(iArr, i6), this.slotsGapLen, this.slots.length);
    }

    private final void updateAnchors(int i6, int i7) {
        Anchor anchor;
        int location$runtime;
        Anchor anchor2;
        int location$runtime2;
        int i8;
        int capacity = getCapacity() - this.groupGapLen;
        if (i6 >= i7) {
            for (int iLocationOf = SlotTableKt.locationOf(this.anchors, i7, capacity); iLocationOf < this.anchors.size() && (location$runtime = (anchor = this.anchors.get(iLocationOf)).getLocation$runtime()) >= 0; iLocationOf++) {
                anchor.setLocation$runtime(-(capacity - location$runtime));
            }
            return;
        }
        for (int iLocationOf2 = SlotTableKt.locationOf(this.anchors, i6, capacity); iLocationOf2 < this.anchors.size() && (location$runtime2 = (anchor2 = this.anchors.get(iLocationOf2)).getLocation$runtime()) < 0 && (i8 = location$runtime2 + capacity) < i7; iLocationOf2++) {
            anchor2.setLocation$runtime(i8);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void updateContainsMark(int i6) {
        if (i6 >= 0) {
            C2598z c2598zM43constructorimpl$default = this.pendingRecalculateMarks;
            if (c2598zM43constructorimpl$default == null) {
                c2598zM43constructorimpl$default = PrioritySet.m43constructorimpl$default(null, 1, null);
                this.pendingRecalculateMarks = c2598zM43constructorimpl$default;
            }
            PrioritySet.m40addimpl(c2598zM43constructorimpl$default, i6);
        }
    }

    /* JADX INFO: renamed from: updateContainsMarkNow-XpTMRCE, reason: not valid java name */
    private final void m62updateContainsMarkNowXpTMRCE(int i6, C2598z c2598z) {
        int iGroupIndexToAddress = groupIndexToAddress(i6);
        boolean zChildContainsAnyMarks = childContainsAnyMarks(i6);
        int[] iArr = this.groups;
        if (((iArr[(iGroupIndexToAddress * 5) + 1] & 67108864) != 0) != zChildContainsAnyMarks) {
            SlotTableKt.updateContainsMark(iArr, iGroupIndexToAddress, zChildContainsAnyMarks);
            int iParent = parent(i6);
            if (iParent >= 0) {
                PrioritySet.m40addimpl(c2598z, iParent);
            }
        }
    }

    private final void updateDataIndex(int[] iArr, int i6, int i7) {
        iArr[(i6 * 5) + 4] = dataIndexToDataAnchor(i7, this.slotsGapStart, this.slotsGapLen, this.slots.length);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0015  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final void updateNodeOfGroup(int i6, Object obj) {
        boolean z6;
        int iGroupIndexToAddress = groupIndexToAddress(i6);
        int[] iArr = this.groups;
        if (iGroupIndexToAddress < iArr.length) {
            z6 = (iArr[(iGroupIndexToAddress * 5) + 1] & 1073741824) != 0;
        }
        if (!z6) {
            ComposerKt.composeImmediateRuntimeError("Updating the node of a group at " + i6 + " that was not created with as a node group");
        }
        this.slots[dataIndexToDataAddress(nodeIndex(this.groups, iGroupIndexToAddress))] = obj;
    }

    public final void advanceBy(int i6) {
        boolean z6 = false;
        if (!(i6 >= 0)) {
            ComposerKt.composeImmediateRuntimeError("Cannot seek backwards");
        }
        if (!(this.insertCount <= 0)) {
            PreconditionsKt.throwIllegalStateException("Cannot call seek() while inserting");
        }
        if (i6 == 0) {
            return;
        }
        int i7 = this.currentGroup + i6;
        if (i7 >= this.parent && i7 <= this.currentGroupEnd) {
            z6 = true;
        }
        if (!z6) {
            ComposerKt.composeImmediateRuntimeError("Cannot seek outside the current group (" + this.parent + '-' + this.currentGroupEnd + ')');
        }
        this.currentGroup = i7;
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(i7));
        this.currentSlot = iDataIndex;
        this.currentSlotEnd = iDataIndex;
    }

    public final Anchor anchor(int i6) {
        ArrayList<Anchor> arrayList = this.anchors;
        int iSearch = SlotTableKt.search(arrayList, i6, getSize$runtime());
        if (iSearch >= 0) {
            return arrayList.get(iSearch);
        }
        if (i6 > this.groupGapStart) {
            i6 = -(getSize$runtime() - i6);
        }
        Anchor anchor = new Anchor(i6);
        arrayList.add(-(iSearch + 1), anchor);
        return anchor;
    }

    public final int anchorIndex(Anchor anchor) {
        int location$runtime = anchor.getLocation$runtime();
        return location$runtime < 0 ? getSize$runtime() + location$runtime : location$runtime;
    }

    public final void appendSlot(Anchor anchor, Object obj) {
        if (!(this.insertCount == 0)) {
            ComposerKt.composeImmediateRuntimeError("Can only append a slot if not current inserting");
        }
        int i6 = this.currentSlot;
        int i7 = this.currentSlotEnd;
        int iAnchorIndex = anchorIndex(anchor);
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(iAnchorIndex + 1));
        this.currentSlot = iDataIndex;
        this.currentSlotEnd = iDataIndex;
        insertSlots(1, iAnchorIndex);
        if (i6 >= iDataIndex) {
            i6++;
            i7++;
        }
        this.slots[iDataIndex] = obj;
        this.currentSlot = i6;
        this.currentSlotEnd = i7;
    }

    public final void bashCurrentGroup() {
        SlotTableKt.updateGroupKey(this.groups, this.currentGroup, -3);
    }

    public final void beginInsert() {
        int i6 = this.insertCount;
        this.insertCount = i6 + 1;
        if (i6 == 0) {
            saveCurrentGroupEnd();
        }
    }

    public final Object clear(int i6) {
        int iDataIndexToDataAddress = dataIndexToDataAddress(i6);
        Object[] objArr = this.slots;
        Object obj = objArr[iDataIndexToDataAddress];
        objArr[iDataIndexToDataAddress] = Composer.Companion.getEmpty();
        return obj;
    }

    public final void close(boolean z6) {
        this.closed = true;
        if (z6 && this.startStack.tos == 0) {
            moveGroupGapTo(getSize$runtime());
            moveSlotGapTo(this.slots.length - this.slotsGapLen, this.groupGapStart);
            clearSlotGap();
            recalculateMarks();
        }
        this.table.close$runtime(this, this.groups, this.groupGapStart, this.slots, this.slotsGapStart, this.anchors, this.sourceInformationMap, this.calledByMap);
    }

    public final int endGroup() {
        J j4;
        boolean z6 = this.insertCount > 0;
        int i6 = this.currentGroup;
        int i7 = this.currentGroupEnd;
        int i8 = this.parent;
        int iGroupIndexToAddress = groupIndexToAddress(i8);
        int i9 = this.nodeCount;
        int i10 = i6 - i8;
        int i11 = (iGroupIndexToAddress * 5) + 1;
        boolean z7 = (this.groups[i11] & 1073741824) != 0;
        if (z6) {
            C2566A c2566a = this.deferredSlotWrites;
            if (c2566a != null && (j4 = (J) c2566a.b(i8)) != null) {
                Object[] objArr = j4.f21376a;
                int i12 = j4.f21377b;
                for (int i13 = 0; i13 < i12; i13++) {
                    rawUpdate(objArr[i13]);
                }
            }
            SlotTableKt.updateGroupSize(this.groups, iGroupIndexToAddress, i10);
            SlotTableKt.updateNodeCount(this.groups, iGroupIndexToAddress, i9);
            this.nodeCount = this.nodeCountStack.pop() + (z7 ? 1 : i9);
            int iParent = parent(this.groups, i8);
            this.parent = iParent;
            int size$runtime = iParent < 0 ? getSize$runtime() : groupIndexToAddress(iParent + 1);
            int iDataIndex = size$runtime >= 0 ? dataIndex(this.groups, size$runtime) : 0;
            this.currentSlot = iDataIndex;
            this.currentSlotEnd = iDataIndex;
            return i9;
        }
        if (!(i6 == i7)) {
            ComposerKt.composeImmediateRuntimeError("Expected to be at the end of a group");
        }
        int iGroupSize = SlotTableKt.groupSize(this.groups, iGroupIndexToAddress);
        int[] iArr = this.groups;
        int i14 = iArr[i11] & 67108863;
        SlotTableKt.updateGroupSize(iArr, iGroupIndexToAddress, i10);
        SlotTableKt.updateNodeCount(this.groups, iGroupIndexToAddress, i9);
        int iPop = this.startStack.pop();
        restoreCurrentGroupEnd();
        this.parent = iPop;
        int iParent2 = parent(this.groups, i8);
        int iPop2 = this.nodeCountStack.pop();
        this.nodeCount = iPop2;
        if (iParent2 == iPop) {
            this.nodeCount = iPop2 + (z7 ? 0 : i9 - i14);
            return i9;
        }
        int i15 = i10 - iGroupSize;
        int i16 = z7 ? 0 : i9 - i14;
        if (i15 != 0 || i16 != 0) {
            while (iParent2 != 0 && iParent2 != iPop && (i16 != 0 || i15 != 0)) {
                int iGroupIndexToAddress2 = groupIndexToAddress(iParent2);
                if (i15 != 0) {
                    SlotTableKt.updateGroupSize(this.groups, iGroupIndexToAddress2, SlotTableKt.groupSize(this.groups, iGroupIndexToAddress2) + i15);
                }
                if (i16 != 0) {
                    int[] iArr2 = this.groups;
                    SlotTableKt.updateNodeCount(iArr2, iGroupIndexToAddress2, (iArr2[(iGroupIndexToAddress2 * 5) + 1] & 67108863) + i16);
                }
                int[] iArr3 = this.groups;
                if ((iArr3[(iGroupIndexToAddress2 * 5) + 1] & 1073741824) != 0) {
                    i16 = 0;
                }
                iParent2 = parent(iArr3, iParent2);
            }
        }
        this.nodeCount += i16;
        return i9;
    }

    public final void endInsert() {
        if (!(this.insertCount > 0)) {
            PreconditionsKt.throwIllegalStateException("Unbalanced begin/end insert");
        }
        int i6 = this.insertCount - 1;
        this.insertCount = i6;
        if (i6 == 0) {
            if (!(this.nodeCountStack.tos == this.startStack.tos)) {
                ComposerKt.composeImmediateRuntimeError("startGroup/endGroup mismatch while inserting");
            }
            restoreCurrentGroupEnd();
        }
    }

    public final void ensureStarted(int i6) {
        boolean z6 = false;
        if (!(this.insertCount <= 0)) {
            ComposerKt.composeImmediateRuntimeError("Cannot call ensureStarted() while inserting");
        }
        int i7 = this.parent;
        if (i7 != i6) {
            if (i6 >= i7 && i6 < this.currentGroupEnd) {
                z6 = true;
            }
            if (!z6) {
                ComposerKt.composeImmediateRuntimeError("Started group at " + i6 + " must be a subgroup of the group at " + i7);
            }
            int i8 = this.currentGroup;
            int i9 = this.currentSlot;
            int i10 = this.currentSlotEnd;
            this.currentGroup = i6;
            startGroup();
            this.currentGroup = i8;
            this.currentSlot = i9;
            this.currentSlotEnd = i10;
        }
    }

    public final void forAllData(int i6, J4.e eVar) {
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(groupSize(getCurrentGroup()) + getCurrentGroup()));
        for (int iDataIndex2 = dataIndex(this.groups, groupIndexToAddress(i6)); iDataIndex2 < iDataIndex; iDataIndex2++) {
            eVar.invoke(Integer.valueOf(iDataIndex2), this.slots[dataIndexToDataAddress(iDataIndex2)]);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:49:0x00e3, code lost:
    
        o.AbstractC2628a.d("Index must be between 0 and size");
     */
    /* JADX WARN: Code restructure failed: missing block: B:50:0x00e8, code lost:
    
        throw null;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void forAllDataInRememberOrder(int i6, J4.e eVar) {
        int i7;
        int i8;
        int afterGroupIndex;
        J4.e eVar2 = eVar;
        int iParent = parent(i6);
        int size$runtime = getSize$runtime();
        int iGroupSize = groupSize(i6) + i6;
        int i9 = i6;
        C2567B c2567b = null;
        C2598z c2598z = null;
        loop0: while (i9 < iGroupSize) {
            int i10 = i9 + 1;
            int iDataIndex = dataIndex(i10);
            for (int iDataIndex2 = dataIndex(i9); iDataIndex2 < iDataIndex; iDataIndex2++) {
                Object obj = this.slots[dataIndexToDataAddress(iDataIndex2)];
                if (!(obj instanceof RememberObserverHolder) || (afterGroupIndex = ((RememberObserverHolder) obj).getAfterGroupIndex()) < 0) {
                    eVar2.invoke(Integer.valueOf(iDataIndex2), obj);
                } else {
                    int iChildGroupAtIndex = childGroupAtIndex(i9, afterGroupIndex);
                    if (c2567b == null) {
                        int[] iArr = AbstractC2589p.f21462a;
                        c2567b = new C2567B();
                    }
                    if (c2598z == null) {
                        c2598z = new C2598z();
                    }
                    c2567b.a(iChildGroupAtIndex);
                    c2598z.c(iChildGroupAtIndex);
                    c2598z.c(iDataIndex2);
                }
            }
            int iParent2 = i10 < size$runtime ? parent(i10) : -1;
            if (iParent2 != i9) {
                while (true) {
                    if (c2598z == null || c2567b == null || !c2567b.f(i9)) {
                        i7 = size$runtime;
                    } else {
                        int i11 = c2598z.f21454b;
                        int i12 = i11 / 2;
                        int i13 = 0;
                        int i14 = 0;
                        while (i13 < i12) {
                            int i15 = i13 * 2;
                            int i16 = size$runtime;
                            int iA = c2598z.a(i15);
                            if (iA == i9) {
                                int iA2 = c2598z.a(i15 + 1);
                                eVar2.invoke(Integer.valueOf(iA2), this.slots[dataIndexToDataAddress(iA2)]);
                            } else if (i15 != i14) {
                                int i17 = i14 + 1;
                                c2598z.f(i14, iA);
                                i14 += 2;
                                c2598z.f(i17, c2598z.a(i15 + 1));
                            } else {
                                i14 += 2;
                            }
                            i13++;
                            eVar2 = eVar;
                            size$runtime = i16;
                        }
                        i7 = size$runtime;
                        if (i14 != i11) {
                            if (i14 < 0 || i14 > (i8 = c2598z.f21454b) || i11 < 0 || i11 > i8) {
                                break loop0;
                            }
                            if (i11 < i14) {
                                AbstractC2628a.c("The end index must be < start index");
                                throw null;
                            }
                            if (i11 != i14) {
                                if (i11 < i8) {
                                    int[] iArr2 = c2598z.f21453a;
                                    AbstractC3250p.x(i14, i11, i8, iArr2, iArr2);
                                }
                                c2598z.f21454b -= i11 - i14;
                            }
                        }
                    }
                    if (i9 == i6 || iParent == iParent2) {
                        break;
                    }
                    i9 = iParent;
                    size$runtime = i7;
                    iParent = parent(iParent);
                    eVar2 = eVar;
                }
            } else {
                i7 = size$runtime;
            }
            eVar2 = eVar;
            iParent = iParent2;
            i9 = i10;
            size$runtime = i7;
        }
    }

    public final void forEachTailSlot(int i6, int i7, J4.e eVar) {
        int iSlotsStartIndex$runtime = slotsStartIndex$runtime(i6);
        int iSlotsEndIndex$runtime = slotsEndIndex$runtime(i6);
        for (int iMax = Math.max(iSlotsStartIndex$runtime, iSlotsEndIndex$runtime - i7); iMax < iSlotsEndIndex$runtime; iMax++) {
            eVar.invoke(Integer.valueOf(iMax), this.slots[dataIndexToDataAddress(iMax)]);
        }
    }

    public final boolean getClosed() {
        return this.closed;
    }

    public final boolean getCollectingCalledInformation() {
        return this.calledByMap != null;
    }

    public final boolean getCollectingSourceInformation() {
        return this.sourceInformationMap != null;
    }

    public final int getCurrentGroup() {
        return this.currentGroup;
    }

    public final int getCurrentGroupEnd() {
        return this.currentGroupEnd;
    }

    public final int getParent() {
        return this.parent;
    }

    public final int getSize$runtime() {
        return getCapacity() - this.groupGapLen;
    }

    public final int getSlotsSize() {
        return this.slots.length - this.slotsGapLen;
    }

    public final SlotTable getTable$runtime() {
        return this.table;
    }

    public final Object groupAux(int i6) {
        int iGroupIndexToAddress = groupIndexToAddress(i6);
        int[] iArr = this.groups;
        return (iArr[(iGroupIndexToAddress * 5) + 1] & 268435456) != 0 ? this.slots[auxIndex(iArr, iGroupIndexToAddress)] : Composer.Companion.getEmpty();
    }

    public final int groupKey(int i6) {
        return this.groups[groupIndexToAddress(i6) * 5];
    }

    public final Object groupObjectKey(int i6) {
        int iGroupIndexToAddress = groupIndexToAddress(i6);
        int[] iArr = this.groups;
        if ((iArr[(iGroupIndexToAddress * 5) + 1] & C.BUFFER_FLAG_LAST_SAMPLE) != 0) {
            return this.slots[SlotTableKt.objectKeyIndex(iArr, iGroupIndexToAddress)];
        }
        return null;
    }

    public final int groupSize(int i6) {
        return SlotTableKt.groupSize(this.groups, groupIndexToAddress(i6));
    }

    public final int groupSlotIndex(int i6) {
        J j4;
        int iSlotsStartIndex$runtime = this.currentSlot - slotsStartIndex$runtime(i6);
        C2566A c2566a = this.deferredSlotWrites;
        return iSlotsStartIndex$runtime + ((c2566a == null || (j4 = (J) c2566a.b(i6)) == null) ? 0 : j4.f21377b);
    }

    public final Iterator<Object> groupSlots() {
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(this.currentGroup));
        int[] iArr = this.groups;
        int i6 = this.currentGroup;
        return new AnonymousClass1(iDataIndex, dataIndex(iArr, groupIndexToAddress(groupSize(i6) + i6)), this);
    }

    public final boolean hasObjectKey(int i6) {
        return (this.groups[(groupIndexToAddress(i6) * 5) + 1] & C.BUFFER_FLAG_LAST_SAMPLE) != 0;
    }

    public final boolean inGroup(Anchor anchor, Anchor anchor2) {
        int iAnchorIndex = anchorIndex(anchor);
        int iGroupSize = SlotTableKt.groupSize(this.groups, iAnchorIndex) + iAnchorIndex;
        int location$runtime = anchor2.getLocation$runtime();
        return iAnchorIndex <= location$runtime && location$runtime < iGroupSize;
    }

    public final boolean indexInCurrentGroup(int i6) {
        return indexInGroup(i6, this.currentGroup);
    }

    public final boolean indexInGroup(int i6, int i7) {
        int iIndexOf;
        int capacity;
        if (i7 == this.parent) {
            capacity = this.currentGroupEnd;
        } else if (i7 <= this.startStack.peekOr(0) && (iIndexOf = this.startStack.indexOf(i7)) >= 0) {
            capacity = (getCapacity() - this.groupGapLen) - this.endStack.peek(iIndexOf);
        } else {
            int iGroupSize = groupSize(i7);
            capacity = iGroupSize + i7;
        }
        return i6 > i7 && i6 < capacity;
    }

    public final boolean indexInParent(int i6) {
        int i7 = this.parent;
        if (i6 <= i7 || i6 >= this.currentGroupEnd) {
            return i7 == 0 && i6 == 0;
        }
        return true;
    }

    public final void insertAux(Object obj) {
        if (!(this.insertCount >= 0)) {
            ComposerKt.composeImmediateRuntimeError("Cannot insert auxiliary data when not inserting");
        }
        int i6 = this.parent;
        int iGroupIndexToAddress = groupIndexToAddress(i6);
        if ((this.groups[(iGroupIndexToAddress * 5) + 1] & 268435456) != 0) {
            ComposerKt.composeImmediateRuntimeError("Group already has auxiliary data");
        }
        insertSlots(1, i6);
        int iAuxIndex = auxIndex(this.groups, iGroupIndexToAddress);
        int iDataIndexToDataAddress = dataIndexToDataAddress(iAuxIndex);
        int i7 = this.currentSlot;
        if (i7 > iAuxIndex) {
            int i8 = i7 - iAuxIndex;
            if (!(i8 < 3)) {
                PreconditionsKt.throwIllegalStateException("Moving more than two slot not supported");
            }
            if (i8 > 1) {
                Object[] objArr = this.slots;
                objArr[iDataIndexToDataAddress + 2] = objArr[iDataIndexToDataAddress + 1];
            }
            Object[] objArr2 = this.slots;
            objArr2[iDataIndexToDataAddress + 1] = objArr2[iDataIndexToDataAddress];
        }
        SlotTableKt.addAux(this.groups, iGroupIndexToAddress);
        this.slots[iDataIndexToDataAddress] = obj;
        this.currentSlot++;
    }

    public final boolean isGroupEnd() {
        return this.currentGroup == this.currentGroupEnd;
    }

    public final boolean isNode() {
        int i6 = this.currentGroup;
        return i6 < this.currentGroupEnd && (this.groups[(groupIndexToAddress(i6) * 5) + 1] & 1073741824) != 0;
    }

    public final boolean isValid(int i6) {
        return groupIndexToAddress(i6) * 5 < this.groups.length;
    }

    public final void markGroup(int i6) {
        int iGroupIndexToAddress = groupIndexToAddress(i6);
        int[] iArr = this.groups;
        int i7 = (iGroupIndexToAddress * 5) + 1;
        if ((iArr[i7] & C.BUFFER_FLAG_FIRST_SAMPLE) != 0) {
            return;
        }
        SlotTableKt.updateMark(iArr, iGroupIndexToAddress, true);
        if ((this.groups[i7] & 67108864) != 0) {
            return;
        }
        updateContainsMark(parent(i6));
    }

    public final List<Anchor> moveFrom(SlotTable slotTable, int i6, boolean z6) {
        if (!(this.insertCount > 0)) {
            ComposerKt.composeImmediateRuntimeError("Check failed");
        }
        if (i6 != 0 || this.currentGroup != 0 || this.table.getGroupsSize() != 0 || SlotTableKt.groupSize(slotTable.getGroups(), i6) != slotTable.getGroupsSize()) {
            SlotWriter slotWriterOpenWriter = slotTable.openWriter();
            try {
                List<Anchor> listMoveGroup = Companion.moveGroup(slotWriterOpenWriter, i6, this, true, true, z6);
                slotWriterOpenWriter.close(true);
                return listMoveGroup;
            } catch (Throwable th) {
                slotWriterOpenWriter.close(false);
                throw th;
            }
        }
        int[] iArr = this.groups;
        Object[] objArr = this.slots;
        ArrayList<Anchor> arrayList = this.anchors;
        HashMap<Anchor, GroupSourceInformation> map = this.sourceInformationMap;
        C2566A c2566a = this.calledByMap;
        int[] groups = slotTable.getGroups();
        int groupsSize = slotTable.getGroupsSize();
        Object[] slots = slotTable.getSlots();
        int slotsSize = slotTable.getSlotsSize();
        HashMap<Anchor, GroupSourceInformation> sourceInformationMap$runtime = slotTable.getSourceInformationMap$runtime();
        C2566A calledByMap$runtime = slotTable.getCalledByMap$runtime();
        this.groups = groups;
        this.slots = slots;
        this.anchors = slotTable.getAnchors$runtime();
        this.groupGapStart = groupsSize;
        this.groupGapLen = (groups.length / 5) - groupsSize;
        this.slotsGapStart = slotsSize;
        this.slotsGapLen = slots.length - slotsSize;
        this.slotsGapOwner = groupsSize;
        this.sourceInformationMap = sourceInformationMap$runtime;
        this.calledByMap = calledByMap$runtime;
        slotTable.setTo$runtime(iArr, 0, objArr, 0, arrayList, map, c2566a);
        return this.anchors;
    }

    public final void moveGroup(int i6) {
        if (this.insertCount != 0) {
            ComposerKt.composeImmediateRuntimeError("Cannot move a group while inserting");
        }
        boolean z6 = true;
        if (!(i6 >= 0)) {
            ComposerKt.composeImmediateRuntimeError("Parameter offset is out of bounds");
        }
        if (i6 == 0) {
            return;
        }
        int i7 = this.currentGroup;
        int i8 = this.parent;
        int i9 = this.currentGroupEnd;
        int iGroupSize = i7;
        for (int i10 = i6; i10 > 0; i10--) {
            iGroupSize += SlotTableKt.groupSize(this.groups, groupIndexToAddress(iGroupSize));
            if (iGroupSize > i9) {
                ComposerKt.composeImmediateRuntimeError("Parameter offset is out of bounds");
            }
        }
        int iGroupSize2 = SlotTableKt.groupSize(this.groups, groupIndexToAddress(iGroupSize));
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(this.currentGroup));
        int iDataIndex2 = dataIndex(this.groups, groupIndexToAddress(iGroupSize));
        int i11 = iGroupSize + iGroupSize2;
        int iDataIndex3 = dataIndex(this.groups, groupIndexToAddress(i11));
        int i12 = iDataIndex3 - iDataIndex2;
        insertSlots(i12, Math.max(this.currentGroup - 1, 0));
        insertGroups(iGroupSize2);
        int[] iArr = this.groups;
        int iGroupIndexToAddress = groupIndexToAddress(i11) * 5;
        AbstractC3250p.x(groupIndexToAddress(i7) * 5, iGroupIndexToAddress, (iGroupSize2 * 5) + iGroupIndexToAddress, iArr, iArr);
        if (i12 > 0) {
            Object[] objArr = this.slots;
            int iDataIndexToDataAddress = dataIndexToDataAddress(iDataIndex2 + i12);
            System.arraycopy(objArr, iDataIndexToDataAddress, objArr, iDataIndex, dataIndexToDataAddress(iDataIndex3 + i12) - iDataIndexToDataAddress);
        }
        int i13 = iDataIndex2 + i12;
        int i14 = i13 - iDataIndex;
        int i15 = this.slotsGapStart;
        int i16 = this.slotsGapLen;
        int length = this.slots.length;
        int i17 = this.slotsGapOwner;
        int i18 = i7 + iGroupSize2;
        int i19 = i7;
        while (i19 < i18) {
            boolean z7 = z6;
            int iGroupIndexToAddress2 = groupIndexToAddress(i19);
            int i20 = i19;
            int i21 = i14;
            updateDataIndex(iArr, iGroupIndexToAddress2, dataIndexToDataAnchor(dataIndex(iArr, iGroupIndexToAddress2) - i14, i17 < iGroupIndexToAddress2 ? 0 : i15, i16, length));
            i19 = i20 + 1;
            z6 = z7;
            i14 = i21;
        }
        moveAnchors(i11, i7, iGroupSize2);
        if (removeGroups(i11, iGroupSize2)) {
            ComposerKt.composeImmediateRuntimeError("Unexpectedly removed anchors");
        }
        fixParentAnchorsFor(i8, this.currentGroupEnd, i7);
        if (i12 > 0) {
            removeSlots(i13, i12, i11 - 1);
        }
    }

    public final List<Anchor> moveIntoGroupFrom(int i6, SlotTable slotTable, int i7) {
        if (!(this.insertCount <= 0 && groupSize(this.currentGroup + i6) == 1)) {
            ComposerKt.composeImmediateRuntimeError("Check failed");
        }
        int i8 = this.currentGroup;
        int i9 = this.currentSlot;
        int i10 = this.currentSlotEnd;
        advanceBy(i6);
        startGroup();
        beginInsert();
        SlotWriter slotWriterOpenWriter = slotTable.openWriter();
        try {
            List<Anchor> listMoveGroup$default = Companion.moveGroup$default(Companion, slotWriterOpenWriter, i7, this, false, true, false, 32, null);
            slotWriterOpenWriter.close(true);
            endInsert();
            endGroup();
            this.currentGroup = i8;
            this.currentSlot = i9;
            this.currentSlotEnd = i10;
            return listMoveGroup$default;
        } catch (Throwable th) {
            slotWriterOpenWriter.close(false);
            throw th;
        }
    }

    public final List<Anchor> moveTo(Anchor anchor, int i6, SlotWriter slotWriter) {
        if (!(slotWriter.insertCount > 0)) {
            ComposerKt.composeImmediateRuntimeError("Check failed");
        }
        if (!(this.insertCount == 0)) {
            ComposerKt.composeImmediateRuntimeError("Check failed");
        }
        if (!anchor.getValid()) {
            ComposerKt.composeImmediateRuntimeError("Check failed");
        }
        int iAnchorIndex = anchorIndex(anchor) + i6;
        int i7 = this.currentGroup;
        if (!(i7 <= iAnchorIndex && iAnchorIndex < this.currentGroupEnd)) {
            ComposerKt.composeImmediateRuntimeError("Check failed");
        }
        int iParent = parent(iAnchorIndex);
        int iGroupSize = groupSize(iAnchorIndex);
        int iNodeCount = isNode(iAnchorIndex) ? 1 : nodeCount(iAnchorIndex);
        List<Anchor> listMoveGroup$default = Companion.moveGroup$default(Companion, this, iAnchorIndex, slotWriter, false, false, false, 32, null);
        updateContainsMark(iParent);
        boolean z6 = iNodeCount > 0;
        while (iParent >= i7) {
            int iGroupIndexToAddress = groupIndexToAddress(iParent);
            int[] iArr = this.groups;
            SlotTableKt.updateGroupSize(iArr, iGroupIndexToAddress, SlotTableKt.groupSize(iArr, iGroupIndexToAddress) - iGroupSize);
            if (z6) {
                int[] iArr2 = this.groups;
                int i8 = iArr2[(iGroupIndexToAddress * 5) + 1];
                if ((1073741824 & i8) != 0) {
                    z6 = false;
                } else {
                    SlotTableKt.updateNodeCount(iArr2, iGroupIndexToAddress, (i8 & 67108863) - iNodeCount);
                }
            }
            iParent = parent(iParent);
        }
        if (z6) {
            if (!(this.nodeCount >= iNodeCount)) {
                ComposerKt.composeImmediateRuntimeError("Check failed");
            }
            this.nodeCount -= iNodeCount;
        }
        return listMoveGroup$default;
    }

    public final Object node(int i6) {
        int iGroupIndexToAddress = groupIndexToAddress(i6);
        int[] iArr = this.groups;
        if ((iArr[(iGroupIndexToAddress * 5) + 1] & 1073741824) != 0) {
            return this.slots[dataIndexToDataAddress(nodeIndex(iArr, iGroupIndexToAddress))];
        }
        return null;
    }

    public final int nodeCount(int i6) {
        return this.groups[(groupIndexToAddress(i6) * 5) + 1] & 67108863;
    }

    public final int parent(int i6) {
        return parent(this.groups, i6);
    }

    public final void recordGroupSourceInformation(String str) {
        if (this.insertCount > 0) {
            groupSourceInformationFor(this.parent, str);
        }
    }

    public final void recordGrouplessCallSourceInformationEnd() {
        GroupSourceInformation groupSourceInformationGroupSourceInformationFor;
        if (this.insertCount <= 0 || (groupSourceInformationGroupSourceInformationFor = groupSourceInformationFor(this.parent, null)) == null) {
            return;
        }
        groupSourceInformationGroupSourceInformationFor.endGrouplessCall(getCurrentGroupSlotIndex());
    }

    public final void recordGrouplessCallSourceInformationStart(int i6, String str) {
        if (this.insertCount > 0) {
            C2566A c2566a = this.calledByMap;
            if (c2566a != null) {
                SlotTableKt.add(c2566a, i6, groupKey(this.parent));
            }
            GroupSourceInformation groupSourceInformationGroupSourceInformationFor = groupSourceInformationFor(this.parent, null);
            if (groupSourceInformationGroupSourceInformationFor != null) {
                groupSourceInformationGroupSourceInformationFor.startGrouplessCall(i6, str, getCurrentGroupSlotIndex());
            }
        }
    }

    public final boolean removeGroup() {
        Anchor anchorTryAnchor$runtime;
        if (!(this.insertCount == 0)) {
            ComposerKt.composeImmediateRuntimeError("Cannot remove group while inserting");
        }
        int i6 = this.currentGroup;
        int i7 = this.currentSlot;
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(i6));
        int iSkipGroup = skipGroup();
        GroupSourceInformation groupSourceInformationSourceInformationOf$runtime = sourceInformationOf$runtime(this.parent);
        if (groupSourceInformationSourceInformationOf$runtime != null && (anchorTryAnchor$runtime = tryAnchor$runtime(i6)) != null) {
            groupSourceInformationSourceInformationOf$runtime.removeAnchor(anchorTryAnchor$runtime);
        }
        C2598z c2598z = this.pendingRecalculateMarks;
        if (c2598z != null) {
            while (PrioritySet.m48isNotEmptyimpl(c2598z) && PrioritySet.m49peekimpl(c2598z) >= i6) {
                PrioritySet.m50takeMaximpl(c2598z);
            }
        }
        boolean zRemoveGroups = removeGroups(i6, this.currentGroup - i6);
        removeSlots(iDataIndex, this.currentSlot - iDataIndex, i6 - 1);
        this.currentGroup = i6;
        this.currentSlot = i7;
        this.nodeCount -= iSkipGroup;
        return zRemoveGroups;
    }

    public final void reset() {
        if (!(this.insertCount == 0)) {
            ComposerKt.composeImmediateRuntimeError("Cannot reset when inserting");
        }
        recalculateMarks();
        this.currentGroup = 0;
        this.currentGroupEnd = getCapacity() - this.groupGapLen;
        this.currentSlot = 0;
        this.currentSlotEnd = 0;
        this.nodeCount = 0;
    }

    public final void seek(Anchor anchor) {
        advanceBy(anchor.toIndexFor(this) - this.currentGroup);
    }

    public final void set(Object obj) {
        if (!(this.currentSlot <= this.currentSlotEnd)) {
            ComposerKt.composeImmediateRuntimeError("Writing to an invalid slot");
        }
        this.slots[dataIndexToDataAddress(this.currentSlot - 1)] = obj;
    }

    public final Object skip() {
        if (this.insertCount > 0) {
            insertSlots(1, this.parent);
        }
        Object[] objArr = this.slots;
        int i6 = this.currentSlot;
        this.currentSlot = i6 + 1;
        return objArr[dataIndexToDataAddress(i6)];
    }

    public final int skipGroup() {
        int iGroupIndexToAddress = groupIndexToAddress(this.currentGroup);
        int iGroupSize = SlotTableKt.groupSize(this.groups, iGroupIndexToAddress) + this.currentGroup;
        this.currentGroup = iGroupSize;
        this.currentSlot = dataIndex(this.groups, groupIndexToAddress(iGroupSize));
        int i6 = this.groups[(iGroupIndexToAddress * 5) + 1];
        if ((1073741824 & i6) != 0) {
            return 1;
        }
        return i6 & 67108863;
    }

    public final void skipToGroupEnd() {
        int i6 = this.currentGroupEnd;
        this.currentGroup = i6;
        this.currentSlot = dataIndex(this.groups, groupIndexToAddress(i6));
    }

    public final Object slot(Anchor anchor, int i6) {
        return slot(anchorIndex(anchor), i6);
    }

    public final int slotIndexOfGroupSlotIndex(int i6, int i7) {
        int iSlotIndex = slotIndex(this.groups, groupIndexToAddress(i6));
        int i8 = iSlotIndex + i7;
        if (!(i8 >= iSlotIndex && i8 < dataIndex(this.groups, groupIndexToAddress(i6 + 1)))) {
            ComposerKt.composeImmediateRuntimeError("Write to an invalid slot index " + i7 + " for group " + i6);
        }
        return i8;
    }

    public final int slotsEndAllIndex$runtime(int i6) {
        return dataIndex(this.groups, groupIndexToAddress(groupSize(i6) + i6));
    }

    public final int slotsEndIndex$runtime(int i6) {
        return dataIndex(this.groups, groupIndexToAddress(i6 + 1));
    }

    public final int slotsStartIndex$runtime(int i6) {
        return slotIndex(this.groups, groupIndexToAddress(i6));
    }

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

    public final void startData(int i6, Object obj, Object obj2) {
        startGroup(i6, obj, false, obj2);
    }

    public final void startGroup() {
        if (!(this.insertCount == 0)) {
            ComposerKt.composeImmediateRuntimeError("Key must be supplied when inserting");
        }
        Composer.Companion companion = Composer.Companion;
        startGroup(0, companion.getEmpty(), false, companion.getEmpty());
    }

    public final void startNode(int i6, Object obj) {
        startGroup(i6, obj, true, Composer.Companion.getEmpty());
    }

    public final String toDebugString() {
        StringBuilder sb = new StringBuilder();
        sb.append(toString());
        sb.append('\n');
        sb.append("  parent:    " + this.parent);
        sb.append('\n');
        sb.append("  current:   " + this.currentGroup);
        sb.append('\n');
        sb.append("  group gap: " + this.groupGapStart + '-' + (this.groupGapStart + this.groupGapLen) + '(' + this.groupGapLen + ')');
        sb.append('\n');
        sb.append("  slots gap: " + this.slotsGapStart + '-' + (this.slotsGapStart + this.slotsGapLen) + '(' + this.slotsGapLen + ')');
        sb.append('\n');
        StringBuilder sb2 = new StringBuilder("  gap owner: ");
        sb2.append(this.slotsGapOwner);
        sb.append(sb2.toString());
        sb.append('\n');
        int size$runtime = getSize$runtime();
        for (int i6 = 0; i6 < size$runtime; i6++) {
            groupAsString(sb, i6);
            sb.append('\n');
        }
        String string = sb.toString();
        kotlin.jvm.internal.o.g(string, "toString(...)");
        return string;
    }

    public String toString() {
        return "SlotWriter(current = " + this.currentGroup + " end=" + this.currentGroupEnd + " size = " + getSize$runtime() + " gap=" + this.groupGapStart + '-' + (this.groupGapStart + this.groupGapLen) + ')';
    }

    public final void traverseGroupAndChildren(int i6, J4.c cVar, J4.c cVar2) {
        int iParent = parent(i6);
        int size$runtime = getSize$runtime();
        int iGroupSize = groupSize(i6) + i6;
        int i7 = i6;
        while (i7 < iGroupSize) {
            cVar.invoke(Integer.valueOf(i7));
            int i8 = i7 + 1;
            int iParent2 = i8 < size$runtime ? parent(i8) : -1;
            if (iParent2 != i7) {
                while (true) {
                    cVar2.invoke(Integer.valueOf(i7));
                    if (i7 == i6 || iParent == iParent2) {
                        break;
                    }
                    i7 = iParent;
                    iParent = parent(iParent);
                }
            }
            i7 = i8;
            iParent = iParent2;
        }
    }

    public final void trimTailSlots(int i6) {
        if (!(i6 > 0)) {
            ComposerKt.composeImmediateRuntimeError("Check failed");
        }
        int i7 = this.parent;
        int iSlotIndex = slotIndex(this.groups, groupIndexToAddress(i7));
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(i7 + 1)) - i6;
        if (!(iDataIndex >= iSlotIndex)) {
            ComposerKt.composeImmediateRuntimeError("Check failed");
        }
        removeSlots(iDataIndex, i6, i7);
        int i8 = this.currentSlot;
        if (i8 >= iSlotIndex) {
            this.currentSlot = i8 - i6;
        }
    }

    public final Anchor tryAnchor$runtime(int i6) {
        if (i6 < 0 || i6 >= getSize$runtime()) {
            return null;
        }
        return SlotTableKt.find(this.anchors, i6, getSize$runtime());
    }

    public final Object update(Object obj) {
        if (this.insertCount <= 0 || this.currentSlot == this.slotsGapStart) {
            return rawUpdate(obj);
        }
        C2566A c2566a = this.deferredSlotWrites;
        if (c2566a == null) {
            c2566a = new C2566A();
        }
        this.deferredSlotWrites = c2566a;
        int i6 = this.parent;
        Object objB = c2566a.b(i6);
        if (objB == null) {
            objB = new J();
            c2566a.i(i6, objB);
        }
        ((J) objB).g(obj);
        return Composer.Companion.getEmpty();
    }

    public final void updateAux(Object obj) {
        int iGroupIndexToAddress = groupIndexToAddress(this.currentGroup);
        if (!((this.groups[(iGroupIndexToAddress * 5) + 1] & 268435456) != 0)) {
            ComposerKt.composeImmediateRuntimeError("Updating the data of a group that was not created with a data slot");
        }
        this.slots[dataIndexToDataAddress(auxIndex(this.groups, iGroupIndexToAddress))] = obj;
    }

    public final void updateNode(Object obj) {
        updateNodeOfGroup(this.currentGroup, obj);
    }

    public final void updateParentNode(Object obj) {
        updateNodeOfGroup(this.parent, obj);
    }

    public final void updateToTableMaps() {
        this.sourceInformationMap = this.table.getSourceInformationMap$runtime();
        this.calledByMap = this.table.getCalledByMap$runtime();
    }

    public final void verifyDataAnchors$runtime() {
        int i6 = this.slotsGapOwner;
        int length = this.slots.length - this.slotsGapLen;
        int size$runtime = getSize$runtime();
        int i7 = 0;
        int i8 = 0;
        boolean z6 = false;
        while (i7 < size$runtime) {
            int iGroupIndexToAddress = groupIndexToAddress(i7);
            int[] iArr = this.groups;
            int i9 = iArr[(iGroupIndexToAddress * 5) + 4];
            int iDataIndex = dataIndex(iArr, iGroupIndexToAddress);
            if (!(iDataIndex >= i8)) {
                StringBuilder sbQ = com.google.android.recaptcha.internal.a.q(i7, i8, "Data index out of order at ", ", previous = ", ", current = ");
                sbQ.append(iDataIndex);
                PreconditionsKt.throwIllegalStateException(sbQ.toString());
            }
            if (!(iDataIndex <= length)) {
                PreconditionsKt.throwIllegalStateException("Data index, " + iDataIndex + ", out of bound at " + i7);
            }
            if (i9 < 0 && !z6) {
                if (!(i6 == i7)) {
                    PreconditionsKt.throwIllegalStateException("Expected the slot gap owner to be " + i6 + " found gap at " + i7);
                }
                z6 = true;
            }
            i7++;
            i8 = iDataIndex;
        }
    }

    public final void verifyParentAnchors$runtime() {
        int i6 = this.groupGapStart;
        int i7 = this.groupGapLen;
        int capacity = getCapacity();
        int i8 = 0;
        while (true) {
            if (i8 >= i6) {
                break;
            }
            if (!(this.groups[(i8 * 5) + 2] > -2)) {
                PreconditionsKt.throwIllegalStateException("Expected a start relative anchor at " + i8);
            }
            i8++;
        }
        for (int i9 = i7 + i6; i9 < capacity; i9++) {
            int i10 = this.groups[(i9 * 5) + 2];
            if (parentAnchorToIndex(i10) < i6) {
                if (!(i10 > -2)) {
                    PreconditionsKt.throwIllegalStateException("Expected a start relative anchor at " + i9);
                }
            } else if (!(i10 <= -2)) {
                PreconditionsKt.throwIllegalStateException("Expected an end relative anchor at " + i9);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int dataIndex(int[] iArr, int i6) {
        return i6 >= getCapacity() ? this.slots.length - this.slotsGapLen : dataAnchorToDataIndex(iArr[(i6 * 5) + 4], this.slotsGapLen, this.slots.length);
    }

    public final int parent(Anchor anchor) {
        if (anchor.getValid()) {
            return parent(this.groups, anchorIndex(anchor));
        }
        return -1;
    }

    public final Object slot(int i6, int i7) {
        int iSlotIndex = slotIndex(this.groups, groupIndexToAddress(i6));
        int iDataIndex = dataIndex(this.groups, groupIndexToAddress(i6 + 1));
        int i8 = i7 + iSlotIndex;
        if (iSlotIndex > i8 || i8 >= iDataIndex) {
            return Composer.Companion.getEmpty();
        }
        return this.slots[dataIndexToDataAddress(i8)];
    }

    public final void startData(int i6, Object obj) {
        startGroup(i6, Composer.Companion.getEmpty(), false, obj);
    }

    public final void startNode(int i6, Object obj, Object obj2) {
        startGroup(i6, obj, true, obj2);
    }

    public final void updateNode(Anchor anchor, Object obj) {
        updateNodeOfGroup(anchor.toIndexFor(this), obj);
    }

    private final int parent(int[] iArr, int i6) {
        return parentAnchorToIndex(iArr[(groupIndexToAddress(i6) * 5) + 2]);
    }

    public final boolean isNode(int i6) {
        return (this.groups[(groupIndexToAddress(i6) * 5) + 1] & 1073741824) != 0;
    }

    public final Object set(int i6, Object obj) {
        return set(getCurrentGroup(), i6, obj);
    }

    public final void startGroup(int i6) {
        Composer.Companion companion = Composer.Companion;
        startGroup(i6, companion.getEmpty(), false, companion.getEmpty());
    }

    public final Object node(Anchor anchor) {
        return node(anchor.toIndexFor(this));
    }

    public final Object set(int i6, int i7, Object obj) {
        int iDataIndexToDataAddress = dataIndexToDataAddress(slotIndexOfGroupSlotIndex(i6, i7));
        Object[] objArr = this.slots;
        Object obj2 = objArr[iDataIndexToDataAddress];
        objArr[iDataIndexToDataAddress] = obj;
        return obj2;
    }

    public final void startGroup(int i6, Object obj) {
        startGroup(i6, obj, false, Composer.Companion.getEmpty());
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r12v0 */
    /* JADX WARN: Type inference failed for: r12v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r12v2 */
    /* JADX WARN: Type inference failed for: r13v0 */
    /* JADX WARN: Type inference failed for: r13v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r13v2 */
    private final void startGroup(int i6, Object obj, boolean z6, Object obj2) {
        int iGroupSize;
        GroupSourceInformation groupSourceInformationSourceInformationOf$runtime;
        int i7 = this.parent;
        Object[] objArr = this.insertCount > 0;
        this.nodeCountStack.push(this.nodeCount);
        if (objArr != false) {
            int i8 = this.currentGroup;
            int iDataIndex = dataIndex(this.groups, groupIndexToAddress(i8));
            insertGroups(1);
            this.currentSlot = iDataIndex;
            this.currentSlotEnd = iDataIndex;
            int iGroupIndexToAddress = groupIndexToAddress(i8);
            Composer.Companion companion = Composer.Companion;
            ?? r12 = obj != companion.getEmpty() ? 1 : 0;
            ?? r13 = (z6 || obj2 == companion.getEmpty()) ? 0 : 1;
            int iDataIndexToDataAnchor = dataIndexToDataAnchor(iDataIndex, this.slotsGapStart, this.slotsGapLen, this.slots.length);
            if (iDataIndexToDataAnchor >= 0 && this.slotsGapOwner < i8) {
                iDataIndexToDataAnchor = -(((this.slots.length - this.slotsGapLen) - iDataIndexToDataAnchor) + 1);
            }
            SlotTableKt.initGroup(this.groups, iGroupIndexToAddress, i6, z6, r12, r13, this.parent, iDataIndexToDataAnchor);
            int i9 = (z6 ? 1 : 0) + r12 + r13;
            if (i9 > 0) {
                insertSlots(i9, i8);
                Object[] objArr2 = this.slots;
                int i10 = this.currentSlot;
                if (z6) {
                    objArr2[i10] = obj2;
                    i10++;
                }
                if (r12 != 0) {
                    objArr2[i10] = obj;
                    i10++;
                }
                if (r13 != 0) {
                    objArr2[i10] = obj2;
                    i10++;
                }
                this.currentSlot = i10;
            }
            this.nodeCount = 0;
            iGroupSize = i8 + 1;
            this.parent = i8;
            this.currentGroup = iGroupSize;
            if (i7 >= 0 && (groupSourceInformationSourceInformationOf$runtime = sourceInformationOf$runtime(i7)) != null) {
                groupSourceInformationSourceInformationOf$runtime.reportGroup(this, i8);
            }
        } else {
            this.startStack.push(i7);
            saveCurrentGroupEnd();
            int i11 = this.currentGroup;
            int iGroupIndexToAddress2 = groupIndexToAddress(i11);
            if (!kotlin.jvm.internal.o.c(obj2, Composer.Companion.getEmpty())) {
                if (z6) {
                    updateNode(obj2);
                } else {
                    updateAux(obj2);
                }
            }
            this.currentSlot = slotIndex(this.groups, iGroupIndexToAddress2);
            this.currentSlotEnd = dataIndex(this.groups, groupIndexToAddress(this.currentGroup + 1));
            int[] iArr = this.groups;
            this.nodeCount = iArr[(iGroupIndexToAddress2 * 5) + 1] & 67108863;
            this.parent = i11;
            this.currentGroup = i11 + 1;
            iGroupSize = i11 + SlotTableKt.groupSize(iArr, iGroupIndexToAddress2);
        }
        this.currentGroupEnd = iGroupSize;
    }

    public final void ensureStarted(Anchor anchor) {
        ensureStarted(anchor.toIndexFor(this));
    }
}
