package y0;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import y0.m;

/* loaded from: classes.dex */
public final class d3 {

    /* renamed from: y, reason: collision with root package name */
    public static final a f51507y = new a(null);

    /* renamed from: z, reason: collision with root package name */
    public static final int f51508z = 8;

    /* renamed from: a, reason: collision with root package name */
    private final a3 f51509a;

    /* renamed from: b, reason: collision with root package name */
    private int[] f51510b;

    /* renamed from: c, reason: collision with root package name */
    private Object[] f51511c;

    /* renamed from: d, reason: collision with root package name */
    private ArrayList f51512d;

    /* renamed from: e, reason: collision with root package name */
    private HashMap f51513e;

    /* renamed from: f, reason: collision with root package name */
    private androidx.collection.y f51514f;

    /* renamed from: g, reason: collision with root package name */
    private int f51515g;

    /* renamed from: h, reason: collision with root package name */
    private int f51516h;

    /* renamed from: i, reason: collision with root package name */
    private int f51517i;

    /* renamed from: j, reason: collision with root package name */
    private int f51518j;

    /* renamed from: k, reason: collision with root package name */
    private int f51519k;

    /* renamed from: l, reason: collision with root package name */
    private int f51520l;

    /* renamed from: m, reason: collision with root package name */
    private int f51521m;

    /* renamed from: n, reason: collision with root package name */
    private int f51522n;

    /* renamed from: o, reason: collision with root package name */
    private int f51523o;

    /* renamed from: s, reason: collision with root package name */
    private androidx.collection.y f51527s;

    /* renamed from: t, reason: collision with root package name */
    private int f51528t;

    /* renamed from: u, reason: collision with root package name */
    private int f51529u;

    /* renamed from: w, reason: collision with root package name */
    private boolean f51531w;

    /* renamed from: x, reason: collision with root package name */
    private e2 f51532x;

    /* renamed from: p, reason: collision with root package name */
    private final v0 f51524p = new v0();

    /* renamed from: q, reason: collision with root package name */
    private final v0 f51525q = new v0();

    /* renamed from: r, reason: collision with root package name */
    private final v0 f51526r = new v0();

    /* renamed from: v, reason: collision with root package name */
    private int f51530v = -1;

    /* loaded from: classes.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }

        /* JADX INFO: Access modifiers changed from: private */
        /* JADX WARN: Multi-variable type inference failed */
        public final List b(d3 d3Var, int i10, d3 d3Var2, boolean z10, boolean z11, boolean z12) {
            boolean z13;
            List list;
            int i11;
            int k02 = d3Var.k0(i10);
            int i12 = i10 + k02;
            int P = d3Var.P(i10);
            int P2 = d3Var.P(i12);
            int i13 = P2 - P;
            boolean M = d3Var.M(i10);
            d3Var2.o0(k02);
            d3Var2.p0(i13, d3Var2.a0());
            if (d3Var.f51515g < i12) {
                d3Var.x0(i12);
            }
            if (d3Var.f51519k < P2) {
                d3Var.z0(P2, i12);
            }
            int[] iArr = d3Var2.f51510b;
            int a02 = d3Var2.a0();
            sm.l.j(d3Var.f51510b, iArr, a02 * 5, i10 * 5, i12 * 5);
            Object[] objArr = d3Var2.f51511c;
            int i14 = d3Var2.f51517i;
            sm.l.l(d3Var.f51511c, objArr, i14, P, P2);
            int c02 = d3Var2.c0();
            c3.A(iArr, a02, c02);
            int i15 = a02 - i10;
            int i16 = a02 + k02;
            int Q = i14 - d3Var2.Q(iArr, a02);
            int i17 = d3Var2.f51521m;
            int i18 = d3Var2.f51520l;
            int length = objArr.length;
            int i19 = i17;
            int i20 = a02;
            while (true) {
                z13 = 0;
                if (i20 >= i16) {
                    break;
                }
                if (i20 != a02) {
                    i11 = i16;
                    c3.A(iArr, i20, c3.s(iArr, i20) + i15);
                } else {
                    i11 = i16;
                }
                int i21 = Q;
                c3.w(iArr, i20, d3Var2.S(d3Var2.Q(iArr, i20) + Q, i19 >= i20 ? d3Var2.f51519k : 0, i18, length));
                if (i20 == i19) {
                    i19++;
                }
                i20++;
                Q = i21;
                i16 = i11;
            }
            int i22 = i16;
            d3Var2.f51521m = i19;
            int o10 = c3.o(d3Var.f51512d, i10, d3Var.d0());
            int o11 = c3.o(d3Var.f51512d, i12, d3Var.d0());
            if (o10 < o11) {
                ArrayList arrayList = d3Var.f51512d;
                ArrayList arrayList2 = new ArrayList(o11 - o10);
                for (int i23 = o10; i23 < o11; i23++) {
                    d dVar = (d) arrayList.get(i23);
                    dVar.c(dVar.a() + i15);
                    arrayList2.add(dVar);
                }
                d3Var2.f51512d.addAll(c3.o(d3Var2.f51512d, d3Var2.a0(), d3Var2.d0()), arrayList2);
                arrayList.subList(o10, o11).clear();
                list = arrayList2;
            } else {
                list = sm.s.k();
            }
            if (!list.isEmpty()) {
                HashMap hashMap = d3Var.f51513e;
                HashMap hashMap2 = d3Var2.f51513e;
                if (hashMap != null && hashMap2 != null) {
                    int size = list.size();
                    for (int i24 = 0; i24 < size; i24++) {
                        d dVar2 = (d) list.get(i24);
                        u0 u0Var = (u0) hashMap.get(dVar2);
                        if (u0Var != null) {
                            hashMap.remove(dVar2);
                            hashMap2.put(dVar2, u0Var);
                        }
                    }
                }
            }
            int c03 = d3Var2.c0();
            u0 e12 = d3Var2.e1(c02);
            if (e12 != null) {
                int i25 = c03 + 1;
                int a03 = d3Var2.a0();
                int i26 = -1;
                while (i25 < a03) {
                    i26 = i25;
                    i25 = c3.h(d3Var2.f51510b, i25) + i25;
                }
                e12.a(d3Var2, i26, a03);
            }
            int E0 = d3Var.E0(i10);
            if (z12) {
                if (z10) {
                    boolean z14 = E0 >= 0;
                    if (z14) {
                        d3Var.g1();
                        d3Var.D(E0 - d3Var.a0());
                        d3Var.g1();
                    }
                    d3Var.D(i10 - d3Var.a0());
                    boolean L0 = d3Var.L0();
                    if (z14) {
                        d3Var.W0();
                        d3Var.T();
                        d3Var.W0();
                        d3Var.T();
                    }
                    z13 = L0;
                } else {
                    boolean M0 = d3Var.M0(i10, k02);
                    d3Var.N0(P, i13, i10 - 1);
                    z13 = M0;
                }
            }
            if ((!z13) == 0) {
                p.r("Unexpectedly removed anchors");
            }
            d3Var2.f51523o += c3.m(iArr, a02) ? 1 : c3.p(iArr, a02);
            if (z11) {
                d3Var2.f51528t = i22;
                d3Var2.f51517i = i14 + i13;
            }
            if (M) {
                d3Var2.p1(c02);
            }
            return list;
        }

        static /* synthetic */ List c(a aVar, d3 d3Var, int i10, d3 d3Var2, boolean z10, boolean z11, boolean z12, int i11, Object obj) {
            if ((i11 & 32) != 0) {
                z12 = true;
            }
            return aVar.b(d3Var, i10, d3Var2, z10, z11, z12);
        }
    }

    public d3(a3 a3Var) {
        this.f51509a = a3Var;
        this.f51510b = a3Var.D();
        this.f51511c = a3Var.F();
        this.f51512d = a3Var.B();
        this.f51513e = a3Var.H();
        this.f51514f = a3Var.C();
        this.f51515g = a3Var.E();
        this.f51516h = (this.f51510b.length / 5) - a3Var.E();
        this.f51519k = a3Var.G();
        this.f51520l = this.f51511c.length - a3Var.G();
        this.f51521m = a3Var.E();
        this.f51529u = a3Var.E();
    }

    private final int D0(int[] iArr, int i10) {
        return Q(iArr, i10);
    }

    private final int F0(int[] iArr, int i10) {
        return G0(c3.s(iArr, h0(i10)));
    }

    private final int G0(int i10) {
        return i10 > -2 ? i10 : d0() + i10 + 2;
    }

    private final int H(int[] iArr, int i10) {
        return Q(iArr, i10) + c3.d(c3.g(iArr, i10) >> 29);
    }

    private final int H0(int i10, int i11) {
        return i10 < i11 ? i10 : -((d0() - i10) + 2);
    }

    private final Object I0(Object obj) {
        Object U0 = U0();
        T0(obj);
        return U0;
    }

    private final boolean J(int i10) {
        int i11 = i10 + 1;
        int k02 = i10 + k0(i10);
        while (i11 < k02) {
            if (c3.b(this.f51510b, h0(i11))) {
                return true;
            }
            i11 += k0(i11);
        }
        return false;
    }

    private final void J0() {
        e2 e2Var = this.f51532x;
        if (e2Var != null) {
            while (e2Var.b()) {
                q1(e2Var.d(), e2Var);
            }
        }
    }

    private final void K() {
        int i10 = this.f51519k;
        sm.l.v(this.f51511c, null, i10, this.f51520l + i10);
    }

    private final boolean K0(int i10, int i11, HashMap hashMap) {
        int i12 = i11 + i10;
        int o10 = c3.o(this.f51512d, i12, Y() - this.f51516h);
        if (o10 >= this.f51512d.size()) {
            o10--;
        }
        int i13 = o10 + 1;
        int i14 = 0;
        while (o10 >= 0) {
            d dVar = (d) this.f51512d.get(o10);
            int F = F(dVar);
            if (F < i10) {
                break;
            }
            if (F < i12) {
                dVar.c(Integer.MIN_VALUE);
                if (hashMap != null) {
                }
                if (i14 == 0) {
                    i14 = o10 + 1;
                }
                i13 = o10;
            }
            o10--;
        }
        boolean z10 = i13 < i14;
        if (z10) {
            this.f51512d.subList(i13, i14).clear();
        }
        return z10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean M(int i10) {
        return i10 >= 0 && c3.b(this.f51510b, h0(i10));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean M0(int i10, int i11) {
        if (i11 > 0) {
            ArrayList arrayList = this.f51512d;
            x0(i10);
            r0 = arrayList.isEmpty() ^ true ? K0(i10, i11, this.f51513e) : false;
            this.f51515g = i10;
            this.f51516h += i11;
            int i12 = this.f51521m;
            if (i12 > i10) {
                this.f51521m = Math.max(i10, i12 - i11);
            }
            int i13 = this.f51529u;
            if (i13 >= this.f51515g) {
                this.f51529u = i13 - i11;
            }
            int i14 = this.f51530v;
            if (N(i14)) {
                p1(i14);
            }
        }
        return r0;
    }

    private final boolean N(int i10) {
        return i10 >= 0 && c3.c(this.f51510b, h0(i10));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void N0(int i10, int i11, int i12) {
        if (i11 > 0) {
            int i13 = this.f51520l;
            int i14 = i10 + i11;
            z0(i14, i12);
            this.f51519k = i10;
            this.f51520l = i13 + i11;
            sm.l.v(this.f51511c, null, i10, i14);
            int i15 = this.f51518j;
            if (i15 >= i10) {
                this.f51518j = i15 - i11;
            }
        }
    }

    private final int O(int i10, int i11, int i12) {
        return i10 < 0 ? (i12 - i11) + i10 + 1 : i10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int P(int i10) {
        return Q(this.f51510b, h0(i10));
    }

    private final int P0() {
        int Y = (Y() - this.f51516h) - this.f51525q.i();
        this.f51529u = Y;
        return Y;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int Q(int[] iArr, int i10) {
        return i10 >= Y() ? this.f51511c.length - this.f51520l : O(c3.e(iArr, i10), this.f51520l, this.f51511c.length);
    }

    private final void Q0() {
        this.f51525q.j((Y() - this.f51516h) - this.f51529u);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int R(int i10) {
        return i10 < this.f51519k ? i10 : i10 + this.f51520l;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int S(int i10, int i11, int i12, int i13) {
        return i10 > i11 ? -(((i13 - i12) - i10) + 1) : i10;
    }

    private final void X(int i10, int i11, int i12) {
        int H0 = H0(i10, this.f51515g);
        while (i12 < i11) {
            c3.A(this.f51510b, h0(i12), H0);
            int h10 = c3.h(this.f51510b, h0(i12)) + i12;
            X(i12, h10, i12 + 1);
            i12 = h10;
        }
    }

    private final int Y() {
        return this.f51510b.length / 5;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int Z0(int[] iArr, int i10) {
        return i10 >= Y() ? this.f51511c.length - this.f51520l : O(c3.u(iArr, i10), this.f51520l, this.f51511c.length);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final u0 e1(int i10) {
        d l12;
        HashMap hashMap = this.f51513e;
        if (hashMap == null || (l12 = l1(i10)) == null) {
            return null;
        }
        return (u0) hashMap.get(l12);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int h0(int i10) {
        return i10 < this.f51515g ? i10 : i10 + this.f51516h;
    }

    /* JADX WARN: Multi-variable type inference failed */
    private final void i1(int i10, Object obj, boolean z10, Object obj2) {
        int h10;
        u0 e12;
        int i11 = this.f51530v;
        Object[] objArr = this.f51522n > 0;
        this.f51526r.j(this.f51523o);
        if (objArr == true) {
            int i12 = this.f51528t;
            int Q = Q(this.f51510b, h0(i12));
            o0(1);
            this.f51517i = Q;
            this.f51518j = Q;
            int h02 = h0(i12);
            m.a aVar = m.f51621a;
            int i13 = obj != aVar.a() ? 1 : 0;
            int i14 = (z10 || obj2 == aVar.a()) ? 0 : 1;
            int S = S(Q, this.f51519k, this.f51520l, this.f51511c.length);
            if (S >= 0 && this.f51521m < i12) {
                S = -(((this.f51511c.length - this.f51520l) - S) + 1);
            }
            c3.l(this.f51510b, h02, i10, z10, i13, i14, this.f51530v, S);
            int i15 = (z10 ? 1 : 0) + i13 + i14;
            if (i15 > 0) {
                p0(i15, i12);
                Object[] objArr2 = this.f51511c;
                int i16 = this.f51517i;
                if (z10) {
                    objArr2[i16] = obj2;
                    i16++;
                }
                if (i13 != 0) {
                    objArr2[i16] = obj;
                    i16++;
                }
                if (i14 != 0) {
                    objArr2[i16] = obj2;
                    i16++;
                }
                this.f51517i = i16;
            }
            this.f51523o = 0;
            h10 = i12 + 1;
            this.f51530v = i12;
            this.f51528t = h10;
            if (i11 >= 0 && (e12 = e1(i11)) != null) {
                e12.f(this, i12);
            }
        } else {
            this.f51524p.j(i11);
            Q0();
            int i17 = this.f51528t;
            int h03 = h0(i17);
            if (!kotlin.jvm.internal.t.b(obj2, m.f51621a.a())) {
                if (z10) {
                    s1(obj2);
                } else {
                    o1(obj2);
                }
            }
            this.f51517i = Z0(this.f51510b, h03);
            this.f51518j = Q(this.f51510b, h0(this.f51528t + 1));
            this.f51523o = c3.p(this.f51510b, h03);
            this.f51530v = i17;
            this.f51528t = i17 + 1;
            h10 = i17 + c3.h(this.f51510b, h03);
        }
        this.f51529u = h10;
    }

    private final void n1(int i10, int i11) {
        d dVar;
        int a10;
        d dVar2;
        int a11;
        int i12;
        int Y = Y() - this.f51516h;
        if (i10 >= i11) {
            for (int o10 = c3.o(this.f51512d, i11, Y); o10 < this.f51512d.size() && (a10 = (dVar = (d) this.f51512d.get(o10)).a()) >= 0; o10++) {
                dVar.c(-(Y - a10));
            }
            return;
        }
        for (int o11 = c3.o(this.f51512d, i10, Y); o11 < this.f51512d.size() && (a11 = (dVar2 = (d) this.f51512d.get(o11)).a()) < 0 && (i12 = a11 + Y) < i11; o11++) {
            dVar2.c(i12);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void o0(int i10) {
        if (i10 > 0) {
            int i11 = this.f51528t;
            x0(i11);
            int i12 = this.f51515g;
            int i13 = this.f51516h;
            int[] iArr = this.f51510b;
            int length = iArr.length / 5;
            int i14 = length - i13;
            if (i13 < i10) {
                int max = Math.max(Math.max(length * 2, i14 + i10), 32);
                int[] iArr2 = new int[max * 5];
                int i15 = max - i14;
                sm.l.j(iArr, iArr2, 0, 0, i12 * 5);
                sm.l.j(iArr, iArr2, (i12 + i15) * 5, (i13 + i12) * 5, length * 5);
                this.f51510b = iArr2;
                i13 = i15;
            }
            int i16 = this.f51529u;
            if (i16 >= i12) {
                this.f51529u = i16 + i10;
            }
            int i17 = i12 + i10;
            this.f51515g = i17;
            this.f51516h = i13 - i10;
            int S = S(i14 > 0 ? P(i11 + i10) : 0, this.f51521m >= i12 ? this.f51519k : 0, this.f51520l, this.f51511c.length);
            for (int i18 = i12; i18 < i17; i18++) {
                c3.w(this.f51510b, i18, S);
            }
            int i19 = this.f51521m;
            if (i19 >= i12) {
                this.f51521m = i19 + i10;
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void p0(int i10, int i11) {
        if (i10 > 0) {
            z0(this.f51517i, i11);
            int i12 = this.f51519k;
            int i13 = this.f51520l;
            if (i13 < i10) {
                Object[] objArr = this.f51511c;
                int length = objArr.length;
                int i14 = length - i13;
                int max = Math.max(Math.max(length * 2, i14 + i10), 32);
                Object[] objArr2 = new Object[max];
                for (int i15 = 0; i15 < max; i15++) {
                    objArr2[i15] = null;
                }
                int i16 = max - i14;
                sm.l.l(objArr, objArr2, 0, 0, i12);
                sm.l.l(objArr, objArr2, i12 + i16, i13 + i12, length);
                this.f51511c = objArr2;
                i13 = i16;
            }
            int i17 = this.f51518j;
            if (i17 >= i12) {
                this.f51518j = i17 + i10;
            }
            this.f51519k = i12 + i10;
            this.f51520l = i13 - i10;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    public final void p1(int i10) {
        if (i10 >= 0) {
            e2 e2Var = this.f51532x;
            if (e2Var == null) {
                e2Var = new e2(null, 1, 0 == true ? 1 : 0);
                this.f51532x = e2Var;
            }
            e2Var.a(i10);
        }
    }

    private final void q1(int i10, e2 e2Var) {
        int h02 = h0(i10);
        boolean J = J(i10);
        if (c3.c(this.f51510b, h02) != J) {
            c3.v(this.f51510b, h02, J);
            int E0 = E0(i10);
            if (E0 >= 0) {
                e2Var.a(E0);
            }
        }
    }

    private final void r1(int[] iArr, int i10, int i11) {
        c3.w(iArr, i10, S(i11, this.f51519k, this.f51520l, this.f51511c.length));
    }

    public static /* synthetic */ void t0(d3 d3Var, int i10, int i11, Object obj) {
        if ((i11 & 1) != 0) {
            i10 = d3Var.f51530v;
        }
        d3Var.s0(i10);
    }

    private final void u0(int i10, int i11, int i12) {
        d dVar;
        int F;
        int i13 = i12 + i10;
        int d02 = d0();
        int o10 = c3.o(this.f51512d, i10, d02);
        ArrayList arrayList = new ArrayList();
        if (o10 >= 0) {
            while (o10 < this.f51512d.size() && (F = F((dVar = (d) this.f51512d.get(o10)))) >= i10 && F < i13) {
                arrayList.add(dVar);
                this.f51512d.remove(o10);
            }
        }
        int i14 = i11 - i10;
        int size = arrayList.size();
        for (int i15 = 0; i15 < size; i15++) {
            d dVar2 = (d) arrayList.get(i15);
            int F2 = F(dVar2) + i14;
            if (F2 >= this.f51515g) {
                dVar2.c(-(d02 - F2));
            } else {
                dVar2.c(F2);
            }
            this.f51512d.add(c3.o(this.f51512d, F2, d02), dVar2);
        }
    }

    private final void u1(int i10, Object obj) {
        int h02 = h0(i10);
        int[] iArr = this.f51510b;
        if (!(h02 < iArr.length && c3.m(iArr, h02))) {
            p.r("Updating the node of a group at " + i10 + " that was not created with as a node group");
        }
        this.f51511c[R(D0(this.f51510b, h02))] = obj;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void x0(int i10) {
        int i11 = this.f51516h;
        int i12 = this.f51515g;
        if (i12 != i10) {
            if (!this.f51512d.isEmpty()) {
                n1(i12, i10);
            }
            if (i11 > 0) {
                int[] iArr = this.f51510b;
                int i13 = i10 * 5;
                int i14 = i11 * 5;
                int i15 = i12 * 5;
                if (i10 < i12) {
                    sm.l.j(iArr, iArr, i14 + i13, i13, i15);
                } else {
                    sm.l.j(iArr, iArr, i15, i15 + i14, i13 + i14);
                }
            }
            if (i10 < i12) {
                i12 = i10 + i11;
            }
            int Y = Y();
            p.O(i12 < Y);
            while (i12 < Y) {
                int s10 = c3.s(this.f51510b, i12);
                int H0 = H0(G0(s10), i10);
                if (H0 != s10) {
                    c3.A(this.f51510b, i12, H0);
                }
                i12++;
                if (i12 == i10) {
                    i12 += i11;
                }
            }
        }
        this.f51515g = i10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void z0(int i10, int i11) {
        int i12 = this.f51520l;
        int i13 = this.f51519k;
        int i14 = this.f51521m;
        if (i13 != i10) {
            Object[] objArr = this.f51511c;
            if (i10 < i13) {
                sm.l.l(objArr, objArr, i10 + i12, i10, i13);
            } else {
                sm.l.l(objArr, objArr, i13, i13 + i12, i10 + i12);
            }
        }
        int min = Math.min(i11 + 1, d0());
        if (i14 != min) {
            int length = this.f51511c.length - i12;
            if (min < i14) {
                int h02 = h0(min);
                int h03 = h0(i14);
                int i15 = this.f51515g;
                while (h02 < h03) {
                    int e10 = c3.e(this.f51510b, h02);
                    if (!(e10 >= 0)) {
                        p.r("Unexpected anchor value, expected a positive anchor");
                    }
                    c3.w(this.f51510b, h02, -((length - e10) + 1));
                    h02++;
                    if (h02 == i15) {
                        h02 += this.f51516h;
                    }
                }
            } else {
                int h04 = h0(i14);
                int h05 = h0(min);
                while (h04 < h05) {
                    int e11 = c3.e(this.f51510b, h04);
                    if (!(e11 < 0)) {
                        p.r("Unexpected anchor value, expected a negative anchor");
                    }
                    c3.w(this.f51510b, h04, e11 + length + 1);
                    h04++;
                    if (h04 == this.f51515g) {
                        h04 += this.f51516h;
                    }
                }
            }
            this.f51521m = min;
        }
        this.f51519k = i10;
    }

    public final Object A0(int i10) {
        int h02 = h0(i10);
        if (c3.m(this.f51510b, h02)) {
            return this.f51511c[R(D0(this.f51510b, h02))];
        }
        return null;
    }

    public final Object B0(d dVar) {
        return A0(dVar.e(this));
    }

    public final int C0(int i10) {
        return c3.p(this.f51510b, h0(i10));
    }

    public final void D(int i10) {
        if (!(i10 >= 0)) {
            p.r("Cannot seek backwards");
        }
        if (!(this.f51522n <= 0)) {
            b2.b("Cannot call seek() while inserting");
        }
        if (i10 == 0) {
            return;
        }
        int i11 = this.f51528t + i10;
        if (!(i11 >= this.f51530v && i11 <= this.f51529u)) {
            p.r("Cannot seek outside the current group (" + this.f51530v + '-' + this.f51529u + ')');
        }
        this.f51528t = i11;
        int Q = Q(this.f51510b, h0(i11));
        this.f51517i = Q;
        this.f51518j = Q;
    }

    public final d E(int i10) {
        ArrayList arrayList = this.f51512d;
        int t10 = c3.t(arrayList, i10, d0());
        if (t10 >= 0) {
            return (d) arrayList.get(t10);
        }
        if (i10 > this.f51515g) {
            i10 = -(d0() - i10);
        }
        d dVar = new d(i10);
        arrayList.add(-(t10 + 1), dVar);
        return dVar;
    }

    public final int E0(int i10) {
        return F0(this.f51510b, i10);
    }

    public final int F(d dVar) {
        int a10 = dVar.a();
        return a10 < 0 ? a10 + d0() : a10;
    }

    public final void G(d dVar, Object obj) {
        if (!(this.f51522n == 0)) {
            p.r("Can only append a slot if not current inserting");
        }
        int i10 = this.f51517i;
        int i11 = this.f51518j;
        int F = F(dVar);
        int Q = Q(this.f51510b, h0(F + 1));
        this.f51517i = Q;
        this.f51518j = Q;
        p0(1, F);
        if (i10 >= Q) {
            i10++;
            i11++;
        }
        this.f51511c[Q] = obj;
        this.f51517i = i10;
        this.f51518j = i11;
    }

    public final void I() {
        int i10 = this.f51522n;
        this.f51522n = i10 + 1;
        if (i10 == 0) {
            Q0();
        }
    }

    public final void L(boolean z10) {
        this.f51531w = true;
        if (z10 && this.f51524p.d()) {
            x0(d0());
            z0(this.f51511c.length - this.f51520l, this.f51515g);
            K();
            J0();
        }
        this.f51509a.m(this, this.f51510b, this.f51515g, this.f51511c, this.f51519k, this.f51512d, this.f51513e, this.f51514f);
    }

    public final boolean L0() {
        d l12;
        if (!(this.f51522n == 0)) {
            p.r("Cannot remove group while inserting");
        }
        int i10 = this.f51528t;
        int i11 = this.f51517i;
        int Q = Q(this.f51510b, h0(i10));
        int V0 = V0();
        u0 e12 = e1(this.f51530v);
        if (e12 != null && (l12 = l1(i10)) != null) {
            e12.d(l12);
        }
        e2 e2Var = this.f51532x;
        if (e2Var != null) {
            while (e2Var.b() && e2Var.c() >= i10) {
                e2Var.d();
            }
        }
        boolean M0 = M0(i10, this.f51528t - i10);
        N0(Q, this.f51517i - Q, i10 - 1);
        this.f51528t = i10;
        this.f51517i = i11;
        this.f51523o -= V0;
        return M0;
    }

    public final void O0() {
        if (!(this.f51522n == 0)) {
            p.r("Cannot reset when inserting");
        }
        J0();
        this.f51528t = 0;
        this.f51529u = Y() - this.f51516h;
        this.f51517i = 0;
        this.f51518j = 0;
        this.f51523o = 0;
    }

    public final Object R0(int i10, int i11, Object obj) {
        int R = R(a1(i10, i11));
        Object[] objArr = this.f51511c;
        Object obj2 = objArr[R];
        objArr[R] = obj;
        return obj2;
    }

    public final Object S0(int i10, Object obj) {
        return R0(this.f51528t, i10, obj);
    }

    public final int T() {
        androidx.collection.e0 e0Var;
        boolean z10 = this.f51522n > 0;
        int i10 = this.f51528t;
        int i11 = this.f51529u;
        int i12 = this.f51530v;
        int h02 = h0(i12);
        int i13 = this.f51523o;
        int i14 = i10 - i12;
        boolean m10 = c3.m(this.f51510b, h02);
        if (z10) {
            androidx.collection.y yVar = this.f51527s;
            if (yVar != null && (e0Var = (androidx.collection.e0) yVar.c(i12)) != null) {
                Object[] objArr = e0Var.f1343a;
                int i15 = e0Var.f1344b;
                for (int i16 = 0; i16 < i15; i16++) {
                    I0(objArr[i16]);
                }
            }
            c3.x(this.f51510b, h02, i14);
            c3.z(this.f51510b, h02, i13);
            this.f51523o = this.f51526r.i() + (m10 ? 1 : i13);
            int F0 = F0(this.f51510b, i12);
            this.f51530v = F0;
            int d02 = F0 < 0 ? d0() : h0(F0 + 1);
            int Q = d02 >= 0 ? Q(this.f51510b, d02) : 0;
            this.f51517i = Q;
            this.f51518j = Q;
        } else {
            if (!(i10 == i11)) {
                p.r("Expected to be at the end of a group");
            }
            int h10 = c3.h(this.f51510b, h02);
            int p10 = c3.p(this.f51510b, h02);
            c3.x(this.f51510b, h02, i14);
            c3.z(this.f51510b, h02, i13);
            int i17 = this.f51524p.i();
            P0();
            this.f51530v = i17;
            int F02 = F0(this.f51510b, i12);
            int i18 = this.f51526r.i();
            this.f51523o = i18;
            if (F02 == i17) {
                this.f51523o = i18 + (m10 ? 0 : i13 - p10);
            } else {
                int i19 = i14 - h10;
                int i20 = m10 ? 0 : i13 - p10;
                if (i19 != 0 || i20 != 0) {
                    while (F02 != 0 && F02 != i17 && (i20 != 0 || i19 != 0)) {
                        int h03 = h0(F02);
                        if (i19 != 0) {
                            c3.x(this.f51510b, h03, c3.h(this.f51510b, h03) + i19);
                        }
                        if (i20 != 0) {
                            int[] iArr = this.f51510b;
                            c3.z(iArr, h03, c3.p(iArr, h03) + i20);
                        }
                        if (c3.m(this.f51510b, h03)) {
                            i20 = 0;
                        }
                        F02 = F0(this.f51510b, F02);
                    }
                }
                this.f51523o += i20;
            }
        }
        return i13;
    }

    public final void T0(Object obj) {
        if (!(this.f51517i <= this.f51518j)) {
            p.r("Writing to an invalid slot");
        }
        this.f51511c[R(this.f51517i - 1)] = obj;
    }

    public final void U() {
        if (!(this.f51522n > 0)) {
            b2.b("Unbalanced begin/end insert");
        }
        int i10 = this.f51522n - 1;
        this.f51522n = i10;
        if (i10 == 0) {
            if (!(this.f51526r.b() == this.f51524p.b())) {
                p.r("startGroup/endGroup mismatch while inserting");
            }
            P0();
        }
    }

    public final Object U0() {
        if (this.f51522n > 0) {
            p0(1, this.f51530v);
        }
        Object[] objArr = this.f51511c;
        int i10 = this.f51517i;
        this.f51517i = i10 + 1;
        return objArr[R(i10)];
    }

    public final void V(int i10) {
        if (!(this.f51522n <= 0)) {
            p.r("Cannot call ensureStarted() while inserting");
        }
        int i11 = this.f51530v;
        if (i11 != i10) {
            if (!(i10 >= i11 && i10 < this.f51529u)) {
                p.r("Started group at " + i10 + " must be a subgroup of the group at " + i11);
            }
            int i12 = this.f51528t;
            int i13 = this.f51517i;
            int i14 = this.f51518j;
            this.f51528t = i10;
            g1();
            this.f51528t = i12;
            this.f51517i = i13;
            this.f51518j = i14;
        }
    }

    public final int V0() {
        int h02 = h0(this.f51528t);
        int h10 = this.f51528t + c3.h(this.f51510b, h02);
        this.f51528t = h10;
        this.f51517i = Q(this.f51510b, h0(h10));
        if (c3.m(this.f51510b, h02)) {
            return 1;
        }
        return c3.p(this.f51510b, h02);
    }

    public final void W(d dVar) {
        V(dVar.e(this));
    }

    public final void W0() {
        int i10 = this.f51529u;
        this.f51528t = i10;
        this.f51517i = Q(this.f51510b, h0(i10));
    }

    public final Object X0(int i10, int i11) {
        int Z0 = Z0(this.f51510b, h0(i10));
        int i12 = i11 + Z0;
        if (Z0 <= i12 && i12 < Q(this.f51510b, h0(i10 + 1))) {
            return this.f51511c[R(i12)];
        }
        return m.f51621a.a();
    }

    public final Object Y0(d dVar, int i10) {
        return X0(F(dVar), i10);
    }

    public final boolean Z() {
        return this.f51531w;
    }

    public final int a0() {
        return this.f51528t;
    }

    public final int a1(int i10, int i11) {
        int Z0 = Z0(this.f51510b, h0(i10));
        int i12 = Z0 + i11;
        if (!(i12 >= Z0 && i12 < Q(this.f51510b, h0(i10 + 1)))) {
            p.r("Write to an invalid slot index " + i11 + " for group " + i10);
        }
        return i12;
    }

    public final int b0() {
        return this.f51529u;
    }

    public final int b1(int i10) {
        return Q(this.f51510b, h0(i10 + k0(i10)));
    }

    public final int c0() {
        return this.f51530v;
    }

    public final int c1(int i10) {
        return Q(this.f51510b, h0(i10 + 1));
    }

    public final int d0() {
        return Y() - this.f51516h;
    }

    public final int d1(int i10) {
        return Z0(this.f51510b, h0(i10));
    }

    public final int e0() {
        return this.f51511c.length - this.f51520l;
    }

    public final a3 f0() {
        return this.f51509a;
    }

    public final void f1(int i10, Object obj, Object obj2) {
        i1(i10, obj, false, obj2);
    }

    public final Object g0(int i10) {
        int h02 = h0(i10);
        return c3.i(this.f51510b, h02) ? this.f51511c[H(this.f51510b, h02)] : m.f51621a.a();
    }

    public final void g1() {
        if (!(this.f51522n == 0)) {
            p.r("Key must be supplied when inserting");
        }
        m.a aVar = m.f51621a;
        i1(0, aVar.a(), false, aVar.a());
    }

    public final void h1(int i10, Object obj) {
        i1(i10, obj, false, m.f51621a.a());
    }

    public final int i0(int i10) {
        return c3.n(this.f51510b, h0(i10));
    }

    public final Object j0(int i10) {
        int h02 = h0(i10);
        if (c3.k(this.f51510b, h02)) {
            return this.f51511c[c3.r(this.f51510b, h02)];
        }
        return null;
    }

    public final void j1(int i10, Object obj) {
        i1(i10, obj, true, m.f51621a.a());
    }

    public final int k0(int i10) {
        return c3.h(this.f51510b, h0(i10));
    }

    public final void k1(int i10) {
        p.O(i10 > 0);
        int i11 = this.f51530v;
        int Z0 = Z0(this.f51510b, h0(i11));
        int Q = Q(this.f51510b, h0(i11 + 1)) - i10;
        p.O(Q >= Z0);
        N0(Q, i10, i11);
        int i12 = this.f51517i;
        if (i12 >= Z0) {
            this.f51517i = i12 - i10;
        }
    }

    public final boolean l0(int i10) {
        return m0(i10, this.f51528t);
    }

    public final d l1(int i10) {
        boolean z10 = false;
        if (i10 >= 0 && i10 < d0()) {
            z10 = true;
        }
        if (z10) {
            return c3.f(this.f51512d, i10, d0());
        }
        return null;
    }

    public final boolean m0(int i10, int i11) {
        int Y;
        int k02;
        if (i11 == this.f51530v) {
            Y = this.f51529u;
        } else {
            if (i11 > this.f51524p.h(0)) {
                k02 = k0(i11);
            } else {
                int c10 = this.f51524p.c(i11);
                if (c10 < 0) {
                    k02 = k0(i11);
                } else {
                    Y = (Y() - this.f51516h) - this.f51525q.f(c10);
                }
            }
            Y = k02 + i11;
        }
        return i10 > i11 && i10 < Y;
    }

    public final Object m1(Object obj) {
        if (this.f51522n <= 0 || this.f51517i == this.f51519k) {
            return I0(obj);
        }
        androidx.collection.y yVar = this.f51527s;
        kotlin.jvm.internal.k kVar = null;
        int i10 = 1;
        int i11 = 0;
        if (yVar == null) {
            yVar = new androidx.collection.y(i11, i10, kVar);
        }
        this.f51527s = yVar;
        int i12 = this.f51530v;
        Object c10 = yVar.c(i12);
        if (c10 == null) {
            c10 = new androidx.collection.e0(i11, i10, kVar);
            yVar.t(i12, c10);
        }
        ((androidx.collection.e0) c10).e(obj);
        return m.f51621a.a();
    }

    public final boolean n0(int i10) {
        int i11 = this.f51530v;
        return (i10 > i11 && i10 < this.f51529u) || (i11 == 0 && i10 == 0);
    }

    public final void o1(Object obj) {
        int h02 = h0(this.f51528t);
        if (!c3.i(this.f51510b, h02)) {
            p.r("Updating the data of a group that was not created with a data slot");
        }
        this.f51511c[R(H(this.f51510b, h02))] = obj;
    }

    public final boolean q0() {
        int i10 = this.f51528t;
        return i10 < this.f51529u && c3.m(this.f51510b, h0(i10));
    }

    public final boolean r0(int i10) {
        return c3.m(this.f51510b, h0(i10));
    }

    public final void s0(int i10) {
        int h02 = h0(i10);
        if (c3.j(this.f51510b, h02)) {
            return;
        }
        c3.y(this.f51510b, h02, true);
        if (c3.c(this.f51510b, h02)) {
            return;
        }
        p1(E0(i10));
    }

    public final void s1(Object obj) {
        u1(this.f51528t, obj);
    }

    public final void t1(d dVar, Object obj) {
        u1(dVar.e(this), obj);
    }

    public String toString() {
        return "SlotWriter(current = " + this.f51528t + " end=" + this.f51529u + " size = " + d0() + " gap=" + this.f51515g + '-' + (this.f51515g + this.f51516h) + ')';
    }

    public final List v0(a3 a3Var, int i10, boolean z10) {
        p.O(this.f51522n > 0);
        if (i10 != 0 || this.f51528t != 0 || this.f51509a.E() != 0 || c3.h(a3Var.D(), i10) != a3Var.E()) {
            d3 O = a3Var.O();
            try {
                List b10 = f51507y.b(O, i10, this, true, true, z10);
                O.L(true);
                return b10;
            } catch (Throwable th2) {
                O.L(false);
                throw th2;
            }
        }
        int[] iArr = this.f51510b;
        Object[] objArr = this.f51511c;
        ArrayList arrayList = this.f51512d;
        HashMap hashMap = this.f51513e;
        androidx.collection.y yVar = this.f51514f;
        int[] D = a3Var.D();
        int E = a3Var.E();
        Object[] F = a3Var.F();
        int G = a3Var.G();
        HashMap H = a3Var.H();
        androidx.collection.y C = a3Var.C();
        this.f51510b = D;
        this.f51511c = F;
        this.f51512d = a3Var.B();
        this.f51515g = E;
        this.f51516h = (D.length / 5) - E;
        this.f51519k = G;
        this.f51520l = F.length - G;
        this.f51521m = E;
        this.f51513e = H;
        this.f51514f = C;
        a3Var.Q(iArr, 0, objArr, 0, arrayList, hashMap, yVar);
        return this.f51512d;
    }

    public final void v1() {
        this.f51513e = this.f51509a.H();
        this.f51514f = this.f51509a.C();
    }

    public final void w0(int i10) {
        if (!(this.f51522n == 0)) {
            p.r("Cannot move a group while inserting");
        }
        if (!(i10 >= 0)) {
            p.r("Parameter offset is out of bounds");
        }
        if (i10 == 0) {
            return;
        }
        int i11 = this.f51528t;
        int i12 = this.f51530v;
        int i13 = this.f51529u;
        int i14 = i11;
        for (int i15 = i10; i15 > 0; i15--) {
            i14 += c3.h(this.f51510b, h0(i14));
            if (!(i14 <= i13)) {
                p.r("Parameter offset is out of bounds");
            }
        }
        int h10 = c3.h(this.f51510b, h0(i14));
        int Q = Q(this.f51510b, h0(this.f51528t));
        int Q2 = Q(this.f51510b, h0(i14));
        int i16 = i14 + h10;
        int Q3 = Q(this.f51510b, h0(i16));
        int i17 = Q3 - Q2;
        p0(i17, Math.max(this.f51528t - 1, 0));
        o0(h10);
        int[] iArr = this.f51510b;
        int h02 = h0(i16) * 5;
        sm.l.j(iArr, iArr, h0(i11) * 5, h02, (h10 * 5) + h02);
        if (i17 > 0) {
            Object[] objArr = this.f51511c;
            sm.l.l(objArr, objArr, Q, R(Q2 + i17), R(Q3 + i17));
        }
        int i18 = Q2 + i17;
        int i19 = i18 - Q;
        int i20 = this.f51519k;
        int i21 = this.f51520l;
        int length = this.f51511c.length;
        int i22 = this.f51521m;
        int i23 = i11 + h10;
        int i24 = i11;
        while (i24 < i23) {
            int h03 = h0(i24);
            int i25 = i20;
            int i26 = i19;
            r1(iArr, h03, S(Q(iArr, h03) - i19, i22 < h03 ? 0 : i25, i21, length));
            i24++;
            i20 = i25;
            i19 = i26;
        }
        u0(i16, i11, h10);
        if (!(!M0(i16, h10))) {
            p.r("Unexpectedly removed anchors");
        }
        X(i12, this.f51529u, i11);
        if (i17 > 0) {
            N0(i18, i17, i16 - 1);
        }
    }

    public final List y0(int i10, a3 a3Var, int i11) {
        p.O(this.f51522n <= 0 && k0(this.f51528t + i10) == 1);
        int i12 = this.f51528t;
        int i13 = this.f51517i;
        int i14 = this.f51518j;
        D(i10);
        g1();
        I();
        d3 O = a3Var.O();
        try {
            List c10 = a.c(f51507y, O, i11, this, false, true, false, 32, null);
            O.L(true);
            U();
            T();
            this.f51528t = i12;
            this.f51517i = i13;
            this.f51518j = i14;
            return c10;
        } catch (Throwable th2) {
            O.L(false);
            throw th2;
        }
    }
}
