package o;

import java.io.IOException;
import java.util.ArrayList;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.rF, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2320rF {
    public final C1822m00 c;
    public int f;
    public int g;
    public int a = 4096;
    public final ArrayList b = new ArrayList();
    public JE[] d = new JE[8];
    public int e = 7;

    public C2320rF(MF mf) {
        this.c = new C1822m00(mf);
    }

    public final int a(int i) {
        int i2;
        int i3 = 0;
        if (i > 0) {
            int length = this.d.length;
            while (true) {
                length--;
                i2 = this.e;
                if (length < i2 || i <= 0) {
                    break;
                }
                int i4 = this.d[length].c;
                i -= i4;
                this.g -= i4;
                this.f--;
                i3++;
            }
            JE[] jeArr = this.d;
            System.arraycopy(jeArr, i2 + 1, jeArr, i2 + 1 + i3, this.f);
            this.e += i3;
        }
        return i3;
    }

    public final C0135Ff b(int i) throws IOException {
        if (i >= 0) {
            JE[] jeArr = AbstractC2510tF.a;
            if (i <= jeArr.length - 1) {
                return jeArr[i].a;
            }
        }
        int length = this.e + 1 + (i - AbstractC2510tF.a.length);
        if (length >= 0) {
            JE[] jeArr2 = this.d;
            if (length < jeArr2.length) {
                return jeArr2[length].a;
            }
        }
        throw new IOException("Header index too large " + (i + 1));
    }

    public final void c(JE je) {
        this.b.add(je);
        int i = je.c;
        int i2 = this.a;
        if (i > i2) {
            AbstractC2219q9.P(this.d, null);
            this.e = this.d.length - 1;
            this.f = 0;
            this.g = 0;
            return;
        }
        a((this.g + i) - i2);
        int i3 = this.f + 1;
        JE[] jeArr = this.d;
        if (i3 > jeArr.length) {
            JE[] jeArr2 = new JE[jeArr.length * 2];
            System.arraycopy(jeArr, 0, jeArr2, jeArr.length, jeArr.length);
            this.e = this.d.length - 1;
            this.d = jeArr2;
        }
        int i4 = this.e;
        this.e = i4 - 1;
        this.d[i4] = je;
        this.f++;
        this.g += i;
    }

    public final C0135Ff d() {
        C1822m00 c1822m00 = this.c;
        byte b = c1822m00.readByte();
        byte[] bArr = AbstractC2264qi0.a;
        int i = b & 255;
        int i2 = 0;
        boolean z = (b & 128) == 128;
        long jE = e(i, 127);
        if (!z) {
            return c1822m00.i(jE);
        }
        C0732af c0732af = new C0732af();
        C3111zf c3111zf = AbstractC0702aG.c;
        C3111zf c3111zf2 = c3111zf;
        int i3 = 0;
        for (long j = 0; j < jE; j++) {
            byte b2 = c1822m00.readByte();
            byte[] bArr2 = AbstractC2264qi0.a;
            i2 = (i2 << 8) | (b2 & 255);
            i3 += 8;
            while (i3 >= 8) {
                c3111zf2 = ((C3111zf[]) c3111zf2.f826o)[(i2 >>> (i3 - 8)) & 255];
                if (((C3111zf[]) c3111zf2.f826o) == null) {
                    c0732af.G(c3111zf2.m);
                    i3 -= c3111zf2.n;
                    c3111zf2 = c3111zf;
                } else {
                    i3 -= 8;
                }
            }
        }
        while (i3 > 0) {
            C3111zf c3111zf3 = ((C3111zf[]) c3111zf2.f826o)[(i2 << (8 - i3)) & 255];
            C3111zf[] c3111zfArr = (C3111zf[]) c3111zf3.f826o;
            int i4 = c3111zf3.n;
            if (c3111zfArr != null || i4 > i3) {
                break;
            }
            c0732af.G(c3111zf3.m);
            i3 -= i4;
            c3111zf2 = c3111zf;
        }
        return c0732af.i(c0732af.m);
    }

    public final int e(int i, int i2) {
        int i3 = i & i2;
        if (i3 < i2) {
            return i3;
        }
        int i4 = 0;
        while (true) {
            byte b = this.c.readByte();
            byte[] bArr = AbstractC2264qi0.a;
            int i5 = b & 255;
            if ((b & 128) == 0) {
                return i2 + (i5 << i4);
            }
            i2 += (b & Byte.MAX_VALUE) << i4;
            i4 += 7;
        }
    }
}
