package com.google.protobuf;

import java.nio.ByteBuffer;

/* JADX INFO: loaded from: classes3.dex */
public final class r extends AbstractC1329s {

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final long f14344e;

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final long f14347h;

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

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

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

    public r(ByteBuffer byteBuffer, boolean z6) {
        this.f14343d = byteBuffer;
        long j4 = c1.f14251c.j(c1.f14255g, byteBuffer);
        this.f14344e = j4;
        this.f14345f = ((long) byteBuffer.limit()) + j4;
        long jPosition = j4 + ((long) byteBuffer.position());
        this.f14346g = jPosition;
        this.f14347h = jPosition;
    }

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

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

    @Override // com.google.protobuf.AbstractC1329s
    public final boolean C(int i6) throws C1297b0 {
        int iZ;
        int i7 = i6 & 7;
        int i8 = 0;
        if (i7 == 0) {
            if (((int) (this.f14345f - this.f14346g)) >= 10) {
                while (i8 < 10) {
                    long j4 = this.f14346g;
                    this.f14346g = j4 + 1;
                    if (c1.f14251c.e(j4) < 0) {
                        i8++;
                    }
                }
                throw C1297b0.e();
            }
            while (i8 < 10) {
                long j6 = this.f14346g;
                if (j6 == this.f14345f) {
                    throw C1297b0.h();
                }
                this.f14346g = j6 + 1;
                if (c1.f14251c.e(j6) < 0) {
                    i8++;
                }
            }
            throw C1297b0.e();
            return true;
        }
        if (i7 == 1) {
            J(8);
            return true;
        }
        if (i7 == 2) {
            J(F());
            return true;
        }
        if (i7 != 3) {
            if (i7 == 4) {
                return false;
            }
            if (i7 != 5) {
                throw C1297b0.d();
            }
            J(4);
            return true;
        }
        do {
            iZ = z();
            if (iZ == 0) {
                break;
            }
        } while (C(iZ));
        a(((i6 >>> 3) << 3) | 4);
        return true;
    }

    public final int D() throws C1297b0 {
        long j4 = this.f14346g;
        if (this.f14345f - j4 < 4) {
            throw C1297b0.h();
        }
        this.f14346g = 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 E() throws C1297b0 {
        long j4 = this.f14346g;
        if (this.f14345f - j4 < 8) {
            throw C1297b0.h();
        }
        this.f14346g = 8 + j4;
        b1 b1Var = c1.f14251c;
        return ((((long) b1Var.e(j4 + 7)) & 255) << 56) | (((long) b1Var.e(j4)) & 255) | ((((long) b1Var.e(1 + j4)) & 255) << 8) | ((((long) b1Var.e(2 + j4)) & 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);
    }

    /* JADX WARN: Code restructure failed: missing block: B:33:0x0091, code lost:
    
        if (r4.e(r8) < 0) goto L34;
     */
    /* JADX WARN: Removed duplicated region for block: B:36:0x0099 A[PHI: r6
      0x0099: PHI (r6v7 long) = (r6v6 long), (r6v8 long), (r6v10 long) binds: [B:25:0x006d, B:29:0x0080, B:33:0x0091] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int F() {
        int i6;
        long j4 = this.f14346g;
        if (this.f14345f != j4) {
            long j6 = 1 + j4;
            b1 b1Var = c1.f14251c;
            byte bE = b1Var.e(j4);
            if (bE >= 0) {
                this.f14346g = j6;
                return bE;
            }
            if (this.f14345f - j6 >= 9) {
                long j7 = 2 + j4;
                int iE = (b1Var.e(j6) << 7) ^ bE;
                if (iE < 0) {
                    i6 = iE ^ (-128);
                } else {
                    long j8 = 3 + j4;
                    int iE2 = iE ^ (b1Var.e(j7) << 14);
                    if (iE2 >= 0) {
                        i6 = iE2 ^ 16256;
                    } else {
                        j7 = j4 + 4;
                        int iE3 = iE2 ^ (b1Var.e(j8) << 21);
                        if (iE3 < 0) {
                            i6 = (-2080896) ^ iE3;
                        } else {
                            j8 = 5 + j4;
                            byte bE2 = b1Var.e(j7);
                            int i7 = (iE3 ^ (bE2 << 28)) ^ 266354560;
                            if (bE2 < 0) {
                                j7 = j4 + 6;
                                if (b1Var.e(j8) < 0) {
                                    j8 = 7 + j4;
                                    if (b1Var.e(j7) < 0) {
                                        j7 = j4 + 8;
                                        if (b1Var.e(j8) < 0) {
                                            long j9 = 9 + j4;
                                            if (b1Var.e(j7) < 0) {
                                                j7 = j4 + 10;
                                            } else {
                                                i6 = i7;
                                                j7 = j9;
                                            }
                                        } else {
                                            i6 = i7;
                                        }
                                    }
                                }
                            }
                            i6 = i7;
                        }
                    }
                    j7 = j8;
                }
                this.f14346g = j7;
                return i6;
            }
        }
        return (int) H();
    }

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

    public final long H() throws C1297b0 {
        long j4 = 0;
        for (int i6 = 0; i6 < 64; i6 += 7) {
            long j6 = this.f14346g;
            if (j6 == this.f14345f) {
                throw C1297b0.h();
            }
            this.f14346g = 1 + j6;
            byte bE = c1.f14251c.e(j6);
            j4 |= ((long) (bE & 127)) << i6;
            if ((bE & 128) == 0) {
                return j4;
            }
        }
        throw C1297b0.e();
    }

    public final void I() {
        long j4 = this.f14345f + ((long) this.f14348i);
        this.f14345f = j4;
        int i6 = (int) (j4 - this.f14347h);
        int i7 = this.f14350k;
        if (i6 <= i7) {
            this.f14348i = 0;
            return;
        }
        int i8 = i6 - i7;
        this.f14348i = i8;
        this.f14345f = j4 - ((long) i8);
    }

    public final void J(int i6) throws C1297b0 {
        if (i6 >= 0) {
            long j4 = this.f14345f;
            long j6 = this.f14346g;
            if (i6 <= ((int) (j4 - j6))) {
                this.f14346g = j6 + ((long) i6);
                return;
            }
        }
        if (i6 >= 0) {
            throw C1297b0.h();
        }
        throw C1297b0.f();
    }

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

    @Override // com.google.protobuf.AbstractC1329s
    public final int d() {
        return (int) (this.f14346g - this.f14347h);
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final boolean e() {
        return this.f14346g == this.f14345f;
    }

    @Override // com.google.protobuf.AbstractC1329s
    public final void h(int i6) {
        this.f14350k = i6;
        I();
    }

    @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.f14350k;
        if (iD > i7) {
            throw C1297b0.h();
        }
        this.f14350k = iD;
        I();
        return i7;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    @Override // com.google.protobuf.AbstractC1329s
    public final String y() throws C1297b0 {
        int iF = F();
        if (iF > 0) {
            long j4 = this.f14345f;
            long j6 = this.f14346g;
            if (iF <= ((int) (j4 - j6))) {
                String strB = f1.b(this.f14343d, (int) (j6 - this.f14344e), iF);
                this.f14346g += (long) iF;
                return strB;
            }
        }
        if (iF == 0) {
            return "";
        }
        if (iF <= 0) {
            throw C1297b0.f();
        }
        throw C1297b0.h();
    }

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