package com.google.crypto.tink.shaded.protobuf;

import java.util.logging.Logger;

/* JADX INFO: renamed from: com.google.crypto.tink.shaded.protobuf.l, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C1264l extends W.d {
    public static final Logger l = Logger.getLogger(C1264l.class.getName());

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public static final boolean f13808m = o0.f13823e;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public L f13809h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final byte[] f13810i;

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

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

    public C1264l(byte[] bArr, int i6) {
        if (((bArr.length - i6) | i6) < 0) {
            throw new IllegalArgumentException(String.format("Array range is invalid. Buffer.length=%d, offset=%d, length=%d", Integer.valueOf(bArr.length), 0, Integer.valueOf(i6)));
        }
        this.f13810i = bArr;
        this.f13812k = 0;
        this.f13811j = i6;
    }

    public static int I(int i6, AbstractC1261i abstractC1261i) {
        return J(abstractC1261i) + P(i6);
    }

    public static int J(AbstractC1261i abstractC1261i) {
        int size = abstractC1261i.size();
        return Q(size) + size;
    }

    public static int K(int i6) {
        return P(i6) + 4;
    }

    public static int L(int i6) {
        return P(i6) + 8;
    }

    public static int M(int i6, AbstractC1253a abstractC1253a, c0 c0Var) {
        return abstractC1253a.a(c0Var) + (P(i6) * 2);
    }

    public static int N(int i6) {
        if (i6 >= 0) {
            return Q(i6);
        }
        return 10;
    }

    public static int O(String str) {
        int length;
        try {
            length = r0.b(str);
        } catch (q0 unused) {
            length = str.getBytes(A.f13714a).length;
        }
        return Q(length) + length;
    }

    public static int P(int i6) {
        return Q(i6 << 3);
    }

    public static int Q(int i6) {
        if ((i6 & (-128)) == 0) {
            return 1;
        }
        if ((i6 & (-16384)) == 0) {
            return 2;
        }
        if (((-2097152) & i6) == 0) {
            return 3;
        }
        return (i6 & (-268435456)) == 0 ? 4 : 5;
    }

    public static int R(long j4) {
        int i6;
        if (((-128) & j4) == 0) {
            return 1;
        }
        if (j4 < 0) {
            return 10;
        }
        if (((-34359738368L) & j4) != 0) {
            j4 >>>= 28;
            i6 = 6;
        } else {
            i6 = 2;
        }
        if (((-2097152) & j4) != 0) {
            i6 += 2;
            j4 >>>= 14;
        }
        return (j4 & (-16384)) != 0 ? i6 + 1 : i6;
    }

    public final void S(byte b5) throws H4.c {
        try {
            byte[] bArr = this.f13810i;
            int i6 = this.f13812k;
            this.f13812k = i6 + 1;
            bArr[i6] = b5;
        } catch (IndexOutOfBoundsException e6) {
            throw new H4.c(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f13812k), Integer.valueOf(this.f13811j), 1), e6, 2);
        }
    }

    public final void T(byte[] bArr, int i6, int i7) throws H4.c {
        try {
            System.arraycopy(bArr, i6, this.f13810i, this.f13812k, i7);
            this.f13812k += i7;
        } catch (IndexOutOfBoundsException e6) {
            throw new H4.c(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f13812k), Integer.valueOf(this.f13811j), Integer.valueOf(i7)), e6, 2);
        }
    }

    public final void U(int i6, int i7) throws H4.c {
        Z(i6, 5);
        V(i7);
    }

    public final void V(int i6) throws H4.c {
        try {
            byte[] bArr = this.f13810i;
            int i7 = this.f13812k;
            int i8 = i7 + 1;
            this.f13812k = i8;
            bArr[i7] = (byte) (i6 & 255);
            int i9 = i7 + 2;
            this.f13812k = i9;
            bArr[i8] = (byte) ((i6 >> 8) & 255);
            int i10 = i7 + 3;
            this.f13812k = i10;
            bArr[i9] = (byte) ((i6 >> 16) & 255);
            this.f13812k = i7 + 4;
            bArr[i10] = (byte) ((i6 >> 24) & 255);
        } catch (IndexOutOfBoundsException e6) {
            throw new H4.c(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f13812k), Integer.valueOf(this.f13811j), 1), e6, 2);
        }
    }

    public final void W(int i6, long j4) throws H4.c {
        Z(i6, 1);
        X(j4);
    }

    public final void X(long j4) throws H4.c {
        try {
            byte[] bArr = this.f13810i;
            int i6 = this.f13812k;
            int i7 = i6 + 1;
            this.f13812k = i7;
            bArr[i6] = (byte) (((int) j4) & 255);
            int i8 = i6 + 2;
            this.f13812k = i8;
            bArr[i7] = (byte) (((int) (j4 >> 8)) & 255);
            int i9 = i6 + 3;
            this.f13812k = i9;
            bArr[i8] = (byte) (((int) (j4 >> 16)) & 255);
            int i10 = i6 + 4;
            this.f13812k = i10;
            bArr[i9] = (byte) (((int) (j4 >> 24)) & 255);
            int i11 = i6 + 5;
            this.f13812k = i11;
            bArr[i10] = (byte) (((int) (j4 >> 32)) & 255);
            int i12 = i6 + 6;
            this.f13812k = i12;
            bArr[i11] = (byte) (((int) (j4 >> 40)) & 255);
            int i13 = i6 + 7;
            this.f13812k = i13;
            bArr[i12] = (byte) (((int) (j4 >> 48)) & 255);
            this.f13812k = i6 + 8;
            bArr[i13] = (byte) (((int) (j4 >> 56)) & 255);
        } catch (IndexOutOfBoundsException e6) {
            throw new H4.c(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f13812k), Integer.valueOf(this.f13811j), 1), e6, 2);
        }
    }

    public final void Y(int i6) throws H4.c {
        if (i6 >= 0) {
            a0(i6);
        } else {
            c0(i6);
        }
    }

    public final void Z(int i6, int i7) throws H4.c {
        a0((i6 << 3) | i7);
    }

    public final void a0(int i6) throws H4.c {
        while (true) {
            int i7 = i6 & (-128);
            byte[] bArr = this.f13810i;
            if (i7 == 0) {
                int i8 = this.f13812k;
                this.f13812k = i8 + 1;
                bArr[i8] = (byte) i6;
                return;
            } else {
                try {
                    int i9 = this.f13812k;
                    this.f13812k = i9 + 1;
                    bArr[i9] = (byte) ((i6 & 127) | 128);
                    i6 >>>= 7;
                } catch (IndexOutOfBoundsException e6) {
                    throw new H4.c(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f13812k), Integer.valueOf(this.f13811j), 1), e6, 2);
                }
            }
            throw new H4.c(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f13812k), Integer.valueOf(this.f13811j), 1), e6, 2);
        }
    }

    public final void b0(int i6, long j4) throws H4.c {
        Z(i6, 0);
        c0(j4);
    }

    public final void c0(long j4) throws H4.c {
        byte[] bArr = this.f13810i;
        boolean z6 = f13808m;
        int i6 = this.f13811j;
        if (z6 && i6 - this.f13812k >= 10) {
            while ((j4 & (-128)) != 0) {
                int i7 = this.f13812k;
                this.f13812k = i7 + 1;
                o0.k(bArr, i7, (byte) ((((int) j4) & 127) | 128));
                j4 >>>= 7;
            }
            int i8 = this.f13812k;
            this.f13812k = i8 + 1;
            o0.k(bArr, i8, (byte) j4);
            return;
        }
        while ((j4 & (-128)) != 0) {
            try {
                int i9 = this.f13812k;
                this.f13812k = i9 + 1;
                bArr[i9] = (byte) ((((int) j4) & 127) | 128);
                j4 >>>= 7;
            } catch (IndexOutOfBoundsException e6) {
                throw new H4.c(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f13812k), Integer.valueOf(i6), 1), e6, 2);
            }
        }
        int i10 = this.f13812k;
        this.f13812k = i10 + 1;
        bArr[i10] = (byte) j4;
    }
}
