package b0;

/* JADX INFO: loaded from: classes.dex */
public final class s {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public byte[] f3088a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private int f3089b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private int f3090c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private int f3091d;

    public s() {
    }

    private void a() {
        int i2;
        int i3;
        int i4 = this.f3089b;
        AbstractC0399d.e(i4 >= 0 && (i2 = this.f3090c) >= 0 && i2 < 8 && (i4 < (i3 = this.f3091d) || (i4 == i3 && i2 == 0)));
    }

    private int f() {
        int i2 = 0;
        while (!d()) {
            i2++;
        }
        return ((1 << i2) - 1) + (i2 > 0 ? e(i2) : 0);
    }

    public int b() {
        return ((this.f3091d - this.f3089b) * 8) - this.f3090c;
    }

    public boolean c() {
        int i2 = this.f3089b;
        int i3 = this.f3090c;
        int i4 = 0;
        while (this.f3089b < this.f3091d && !d()) {
            i4++;
        }
        boolean z2 = this.f3089b == this.f3091d;
        this.f3089b = i2;
        this.f3090c = i3;
        return !z2 && b() >= (i4 * 2) + 1;
    }

    public boolean d() {
        return e(1) == 1;
    }

    public int e(int i2) {
        int i3;
        int i4;
        if (i2 == 0) {
            return 0;
        }
        int i5 = i2 / 8;
        int i6 = 0;
        for (int i7 = 0; i7 < i5; i7++) {
            int i8 = this.f3090c;
            if (i8 != 0) {
                byte[] bArr = this.f3088a;
                int i9 = this.f3089b;
                i4 = ((bArr[i9 + 1] & 255) >>> (8 - i8)) | ((bArr[i9] & 255) << i8);
            } else {
                i4 = this.f3088a[this.f3089b];
            }
            i2 -= 8;
            i6 |= (255 & i4) << i2;
            this.f3089b++;
        }
        if (i2 > 0) {
            int i10 = this.f3090c + i2;
            byte b2 = (byte) (255 >> (8 - i2));
            if (i10 > 8) {
                byte[] bArr2 = this.f3088a;
                int i11 = this.f3089b;
                i3 = (b2 & (((255 & bArr2[i11 + 1]) >> (16 - i10)) | ((bArr2[i11] & 255) << (i10 - 8)))) | i6;
                this.f3089b = i11 + 1;
            } else {
                byte[] bArr3 = this.f3088a;
                int i12 = this.f3089b;
                i3 = (b2 & ((255 & bArr3[i12]) >> (8 - i10))) | i6;
                if (i10 == 8) {
                    this.f3089b = i12 + 1;
                }
            }
            i6 = i3;
            this.f3090c = i10 % 8;
        }
        a();
        return i6;
    }

    public int g() {
        int iF = f();
        return (iF % 2 == 0 ? -1 : 1) * ((iF + 1) / 2);
    }

    public int h() {
        return f();
    }

    public void i(byte[] bArr) {
        j(bArr, bArr.length);
    }

    public void j(byte[] bArr, int i2) {
        this.f3088a = bArr;
        this.f3089b = 0;
        this.f3090c = 0;
        this.f3091d = i2;
    }

    public void k(int i2) {
        int i3 = i2 / 8;
        this.f3089b = i3;
        this.f3090c = i2 - (i3 * 8);
        a();
    }

    public void l(int i2) {
        int i3 = this.f3089b + (i2 / 8);
        this.f3089b = i3;
        int i4 = this.f3090c + (i2 % 8);
        this.f3090c = i4;
        if (i4 > 7) {
            this.f3089b = i3 + 1;
            this.f3090c = i4 - 8;
        }
        a();
    }

    public s(byte[] bArr) {
        this(bArr, bArr.length);
    }

    public s(byte[] bArr, int i2) {
        this.f3088a = bArr;
        this.f3091d = i2;
    }
}
