package com.google.protobuf;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;

/* JADX INFO: renamed from: com.google.protobuf.p, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C1324p extends AbstractC1329s {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Iterator f14324d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public ByteBuffer f14325e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f14326f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f14327g;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public int f14329i;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public long f14331k;
    public long l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public long f14332m;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f14328h = Integer.MAX_VALUE;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f14330j = 0;

    public C1324p(int i6, ArrayList arrayList) {
        this.f14326f = i6;
        this.f14324d = arrayList.iterator();
        if (i6 != 0) {
            N();
            return;
        }
        this.f14325e = Z.f14236c;
        this.f14331k = 0L;
        this.l = 0L;
        this.f14332m = 0L;
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int A() {
        return I();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final long B() {
        return J();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final boolean C(int i6) throws C1297b0 {
        int iZ;
        int i7 = i6 & 7;
        if (i7 == 0) {
            for (int i8 = 0; i8 < 10; i8++) {
                if (E() >= 0) {
                    return true;
                }
            }
            throw C1297b0.e();
        }
        if (i7 == 1) {
            M(8);
            return true;
        }
        if (i7 == 2) {
            M(I());
            return true;
        }
        if (i7 != 3) {
            if (i7 == 4) {
                return false;
            }
            if (i7 != 5) {
                throw C1297b0.d();
            }
            M(4);
            return true;
        }
        do {
            iZ = z();
            if (iZ == 0) {
                break;
            }
        } while (C(iZ));
        a(((i6 >>> 3) << 3) | 4);
        return true;
    }

    public final long D() {
        return this.f14332m - this.f14331k;
    }

    public final byte E() throws C1297b0 {
        if (D() == 0) {
            if (!this.f14324d.hasNext()) {
                throw C1297b0.h();
            }
            N();
        }
        long j4 = this.f14331k;
        this.f14331k = 1 + j4;
        return c1.f14251c.e(j4);
    }

    public final void F(byte[] bArr, int i6) throws C1297b0 {
        if (i6 < 0 || i6 > L()) {
            if (i6 > 0) {
                throw C1297b0.h();
            }
            if (i6 != 0) {
                throw C1297b0.f();
            }
            return;
        }
        int i7 = i6;
        while (i7 > 0) {
            if (D() == 0) {
                if (!this.f14324d.hasNext()) {
                    throw C1297b0.h();
                }
                N();
            }
            int iMin = Math.min(i7, (int) D());
            long j4 = iMin;
            byte[] bArr2 = bArr;
            c1.f14251c.c(this.f14331k, bArr2, i6 - i7, j4);
            i7 -= iMin;
            this.f14331k += j4;
            bArr = bArr2;
        }
    }

    public final int G() {
        if (D() < 4) {
            return (E() & 255) | ((E() & 255) << 8) | ((E() & 255) << 16) | ((E() & 255) << 24);
        }
        long j4 = this.f14331k;
        this.f14331k = 4 + j4;
        b1 b1Var = c1.f14251c;
        return ((b1Var.e(j4 + 3) & 255) << 24) | (b1Var.e(j4) & 255) | ((b1Var.e(1 + j4) & 255) << 8) | ((b1Var.e(2 + j4) & 255) << 16);
    }

    public final long H() {
        if (D() < 8) {
            return (((long) E()) & 255) | ((((long) E()) & 255) << 8) | ((((long) E()) & 255) << 16) | ((((long) E()) & 255) << 24) | ((((long) E()) & 255) << 32) | ((((long) E()) & 255) << 40) | ((((long) E()) & 255) << 48) | ((((long) E()) & 255) << 56);
        }
        long j4 = this.f14331k;
        this.f14331k = 8 + j4;
        b1 b1Var = c1.f14251c;
        return (((long) b1Var.e(j4)) & 255) | ((((long) b1Var.e(j4 + 1)) & 255) << 8) | ((((long) b1Var.e(j4 + 2)) & 255) << 16) | ((((long) b1Var.e(3 + j4)) & 255) << 24) | ((((long) b1Var.e(4 + j4)) & 255) << 32) | ((((long) b1Var.e(5 + j4)) & 255) << 40) | ((((long) b1Var.e(6 + j4)) & 255) << 48) | ((((long) b1Var.e(j4 + 7)) & 255) << 56);
    }

    public final int I() {
        int i6;
        long j4 = this.f14331k;
        if (this.f14332m != j4) {
            long j6 = j4 + 1;
            b1 b1Var = c1.f14251c;
            byte bE = b1Var.e(j4);
            if (bE >= 0) {
                this.f14331k++;
                return bE;
            }
            if (this.f14332m - this.f14331k >= 10) {
                long j7 = 2 + j4;
                int iE = (b1Var.e(j6) << 7) ^ bE;
                if (iE < 0) {
                    i6 = iE ^ (-128);
                } else {
                    long j8 = 3 + j4;
                    int iE2 = (b1Var.e(j7) << 14) ^ iE;
                    if (iE2 >= 0) {
                        i6 = iE2 ^ 16256;
                    } else {
                        long j9 = 4 + j4;
                        int iE3 = iE2 ^ (b1Var.e(j8) << 21);
                        if (iE3 < 0) {
                            i6 = (-2080896) ^ iE3;
                        } else {
                            j8 = 5 + j4;
                            byte bE2 = b1Var.e(j9);
                            int i7 = (iE3 ^ (bE2 << 28)) ^ 266354560;
                            if (bE2 < 0) {
                                j9 = 6 + j4;
                                if (b1Var.e(j8) < 0) {
                                    j8 = 7 + j4;
                                    if (b1Var.e(j9) < 0) {
                                        j9 = 8 + j4;
                                        if (b1Var.e(j8) < 0) {
                                            j8 = 9 + j4;
                                            if (b1Var.e(j9) < 0) {
                                                long j10 = j4 + 10;
                                                if (b1Var.e(j8) >= 0) {
                                                    i6 = i7;
                                                    j7 = j10;
                                                }
                                            }
                                        }
                                    }
                                }
                                i6 = i7;
                            }
                            i6 = i7;
                        }
                        j7 = j9;
                    }
                    j7 = j8;
                }
                this.f14331k = j7;
                return i6;
            }
        }
        return (int) K();
    }

    public final long J() {
        long j4;
        long j6;
        long j7;
        long j8 = this.f14331k;
        if (this.f14332m != j8) {
            long j9 = j8 + 1;
            b1 b1Var = c1.f14251c;
            byte bE = b1Var.e(j8);
            if (bE >= 0) {
                this.f14331k++;
                return bE;
            }
            if (this.f14332m - this.f14331k >= 10) {
                long j10 = 2 + j8;
                int iE = (b1Var.e(j9) << 7) ^ bE;
                if (iE < 0) {
                    j4 = iE ^ (-128);
                } else {
                    long j11 = 3 + j8;
                    int iE2 = (b1Var.e(j10) << 14) ^ iE;
                    if (iE2 >= 0) {
                        j4 = iE2 ^ 16256;
                    } else {
                        long j12 = 4 + j8;
                        int iE3 = iE2 ^ (b1Var.e(j11) << 21);
                        if (iE3 < 0) {
                            j4 = (-2080896) ^ iE3;
                            j10 = j12;
                        } else {
                            long j13 = 5 + j8;
                            long jE = (((long) b1Var.e(j12)) << 28) ^ ((long) iE3);
                            if (jE >= 0) {
                                j7 = 266354560;
                            } else {
                                j11 = 6 + j8;
                                long jE2 = jE ^ (((long) b1Var.e(j13)) << 35);
                                if (jE2 < 0) {
                                    j6 = -34093383808L;
                                } else {
                                    j13 = 7 + j8;
                                    jE = jE2 ^ (((long) b1Var.e(j11)) << 42);
                                    if (jE >= 0) {
                                        j7 = 4363953127296L;
                                    } else {
                                        j11 = 8 + j8;
                                        jE2 = jE ^ (((long) b1Var.e(j13)) << 49);
                                        if (jE2 < 0) {
                                            j6 = -558586000294016L;
                                        } else {
                                            j13 = 9 + j8;
                                            long jE3 = (jE2 ^ (((long) b1Var.e(j11)) << 56)) ^ 71499008037633920L;
                                            if (jE3 < 0) {
                                                long j14 = j8 + 10;
                                                if (b1Var.e(j13) >= 0) {
                                                    j10 = j14;
                                                    j4 = jE3;
                                                }
                                            } else {
                                                j4 = jE3;
                                                j10 = j13;
                                            }
                                        }
                                    }
                                }
                                j4 = j6 ^ jE2;
                            }
                            j4 = j7 ^ jE;
                            j10 = j13;
                        }
                    }
                    j10 = j11;
                }
                this.f14331k = j10;
                return j4;
            }
        }
        return K();
    }

    public final long K() throws C1297b0 {
        long j4 = 0;
        for (int i6 = 0; i6 < 64; i6 += 7) {
            byte bE = E();
            j4 |= ((long) (bE & 127)) << i6;
            if ((bE & 128) == 0) {
                return j4;
            }
        }
        throw C1297b0.e();
    }

    public final int L() {
        return (int) ((((long) (this.f14326f - this.f14330j)) - this.f14331k) + this.l);
    }

    public final void M(int i6) throws C1297b0 {
        if (i6 < 0 || i6 > (((long) (this.f14326f - this.f14330j)) - this.f14331k) + this.l) {
            if (i6 >= 0) {
                throw C1297b0.h();
            }
            throw C1297b0.f();
        }
        while (i6 > 0) {
            if (D() == 0) {
                if (!this.f14324d.hasNext()) {
                    throw C1297b0.h();
                }
                N();
            }
            int iMin = Math.min(i6, (int) D());
            i6 -= iMin;
            this.f14331k += (long) iMin;
        }
    }

    public final void N() {
        ByteBuffer byteBuffer = (ByteBuffer) this.f14324d.next();
        this.f14325e = byteBuffer;
        this.f14330j += (int) (this.f14331k - this.l);
        long jPosition = byteBuffer.position();
        this.f14331k = jPosition;
        this.l = jPosition;
        this.f14332m = this.f14325e.limit();
        long j4 = c1.f14251c.j(c1.f14255g, this.f14325e);
        this.f14331k += j4;
        this.l += j4;
        this.f14332m += j4;
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final void a(int i6) throws C1297b0 {
        if (this.f14329i != i6) {
            throw C1297b0.a();
        }
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int d() {
        return (int) ((((long) this.f14330j) + this.f14331k) - this.l);
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final boolean e() {
        return (((long) this.f14330j) + this.f14331k) - this.l == ((long) this.f14326f);
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final void h(int i6) {
        this.f14328h = i6;
        int i7 = this.f14326f + this.f14327g;
        this.f14326f = i7;
        if (i7 <= i6) {
            this.f14327g = 0;
            return;
        }
        int i8 = i7 - i6;
        this.f14327g = i8;
        this.f14326f = i7 - i8;
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int i(int i6) throws C1297b0 {
        if (i6 < 0) {
            throw C1297b0.f();
        }
        int iD = d() + i6;
        int i7 = this.f14328h;
        if (iD > i7) {
            throw C1297b0.h();
        }
        this.f14328h = iD;
        int i8 = this.f14326f + this.f14327g;
        this.f14326f = i8;
        if (i8 <= iD) {
            this.f14327g = 0;
            return i7;
        }
        int i9 = i8 - iD;
        this.f14327g = i9;
        this.f14326f = i8 - i9;
        return i7;
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final boolean j() {
        return J() != 0;
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final C1318m k() throws C1297b0 {
        int I5 = I();
        if (I5 > 0) {
            long j4 = I5;
            long j6 = this.f14332m;
            long j7 = this.f14331k;
            if (j4 <= j6 - j7) {
                byte[] bArr = new byte[I5];
                c1.f14251c.c(j7, bArr, 0L, j4);
                this.f14331k += j4;
                C1318m c1318m = AbstractC1320n.f14310b;
                return new C1318m(bArr);
            }
        }
        if (I5 > 0 && I5 <= L()) {
            byte[] bArr2 = new byte[I5];
            F(bArr2, I5);
            C1318m c1318m2 = AbstractC1320n.f14310b;
            return new C1318m(bArr2);
        }
        if (I5 == 0) {
            return AbstractC1320n.f14310b;
        }
        if (I5 < 0) {
            throw C1297b0.f();
        }
        throw C1297b0.h();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final double l() {
        return Double.longBitsToDouble(H());
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int m() {
        return I();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int n() {
        return G();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final long o() {
        return H();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final float p() {
        return Float.intBitsToFloat(G());
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int q() {
        return I();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final long r() {
        return J();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int t() {
        return G();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final long u() {
        return H();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int v() {
        return AbstractC1329s.b(I());
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final long w() {
        return AbstractC1329s.c(J());
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final String x() throws C1297b0 {
        int I5 = I();
        if (I5 > 0) {
            long j4 = I5;
            long j6 = this.f14332m;
            long j7 = this.f14331k;
            if (j4 <= j6 - j7) {
                byte[] bArr = new byte[I5];
                c1.f14251c.c(j7, bArr, 0L, j4);
                String str = new String(bArr, Z.f14234a);
                this.f14331k += j4;
                return str;
            }
        }
        if (I5 > 0 && I5 <= L()) {
            byte[] bArr2 = new byte[I5];
            F(bArr2, I5);
            return new String(bArr2, Z.f14234a);
        }
        if (I5 == 0) {
            return "";
        }
        if (I5 < 0) {
            throw C1297b0.f();
        }
        throw C1297b0.h();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final String y() throws C1297b0 {
        int I5 = I();
        if (I5 > 0) {
            long j4 = I5;
            long j6 = this.f14332m;
            long j7 = this.f14331k;
            if (j4 <= j6 - j7) {
                String strB = f1.b(this.f14325e, (int) (j7 - this.l), I5);
                this.f14331k += j4;
                return strB;
            }
        }
        if (I5 >= 0 && I5 <= L()) {
            byte[] bArr = new byte[I5];
            F(bArr, I5);
            return f1.f14272a.j(bArr, 0, I5);
        }
        if (I5 == 0) {
            return "";
        }
        if (I5 <= 0) {
            throw C1297b0.f();
        }
        throw C1297b0.h();
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final int z() throws C1297b0 {
        if (e()) {
            this.f14329i = 0;
            return 0;
        }
        int I5 = I();
        this.f14329i = I5;
        if ((I5 >>> 3) != 0) {
            return I5;
        }
        throw C1297b0.b();
    }
}
