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

import defpackage.AbstractC0793;
import defpackage.AbstractC1130;
import defpackage.AbstractC2638;
import defpackage.AbstractC4613;
import defpackage.AbstractC4937;
import defpackage.C1236;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;

/* JADX INFO: renamed from: com.google.crypto.tink.shaded.protobuf.ːˏᵟᵯ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0020 extends AbstractC2638 {

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public int f1081;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final ByteArrayInputStream f1082;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public int f1083;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public int f1084 = Integer.MAX_VALUE;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public int f1085;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final byte[] f1086;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public int f1087;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public int f1088;

    public C0020(ByteArrayInputStream byteArrayInputStream) {
        Charset charset = AbstractC1130.f4831;
        this.f1082 = byteArrayInputStream;
        this.f1086 = new byte[4096];
        this.f1083 = 0;
        this.f1085 = 0;
        this.f1087 = 0;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ʽˈˋ */
    public final void mo99(int i) throws InvalidProtocolBufferException {
        if (this.f1081 != i) {
            throw new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
        }
    }

    /* JADX INFO: renamed from: ʽᵡᵢᵾ, reason: contains not printable characters */
    public final long m859() throws InvalidProtocolBufferException {
        long j = 0;
        for (int i = 0; i < 64; i += 7) {
            if (this.f1085 == this.f1083) {
                m869(1);
            }
            int i2 = this.f1085;
            this.f1085 = i2 + 1;
            byte b = this.f1086[i2];
            j |= ((long) (b & 127)) << i;
            if ((b & 128) == 0) {
                return j;
            }
        }
        throw InvalidProtocolBufferException.m840();
    }

    /* JADX INFO: renamed from: ˀᵭ, reason: contains not printable characters */
    public final byte[] m860(int i) throws IOException {
        if (i == 0) {
            return AbstractC1130.f4830;
        }
        if (i < 0) {
            throw InvalidProtocolBufferException.m837();
        }
        int i2 = this.f1087;
        int i3 = this.f1085;
        int i4 = i2 + i3 + i;
        if (i4 - Integer.MAX_VALUE > 0) {
            throw new InvalidProtocolBufferException("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit. If reading multiple messages, consider resetting the counter between each message using CodedInputStream.resetSizeCounter().");
        }
        int i5 = this.f1084;
        if (i4 > i5) {
            m868((i5 - i2) - i3);
            throw InvalidProtocolBufferException.m839();
        }
        int i6 = this.f1083 - i3;
        int i7 = i - i6;
        ByteArrayInputStream byteArrayInputStream = this.f1082;
        if (i7 >= 4096) {
            try {
                if (i7 > byteArrayInputStream.available()) {
                    return null;
                }
            } catch (InvalidProtocolBufferException e) {
                e.f1070 = true;
                throw e;
            }
        }
        byte[] bArr = new byte[i];
        System.arraycopy(this.f1086, this.f1085, bArr, 0, i6);
        this.f1087 += this.f1083;
        this.f1085 = 0;
        this.f1083 = 0;
        while (i6 < i) {
            try {
                int i8 = byteArrayInputStream.read(bArr, i6, i - i6);
                if (i8 == -1) {
                    throw InvalidProtocolBufferException.m839();
                }
                this.f1087 += i8;
                i6 += i8;
            } catch (InvalidProtocolBufferException e2) {
                e2.f1070 = true;
                throw e2;
            }
        }
        return bArr;
    }

    /* JADX INFO: renamed from: ˁˌᵩ, reason: contains not printable characters */
    public final byte[] m861(int i) throws IOException {
        byte[] bArrM860 = m860(i);
        if (bArrM860 != null) {
            return bArrM860;
        }
        int i2 = this.f1085;
        int i3 = this.f1083;
        int length = i3 - i2;
        this.f1087 += i3;
        this.f1085 = 0;
        this.f1083 = 0;
        ArrayList arrayListM865 = m865(i - length);
        byte[] bArr = new byte[i];
        System.arraycopy(this.f1086, i2, bArr, 0, length);
        int size = arrayListM865.size();
        int i4 = 0;
        while (i4 < size) {
            Object obj = arrayListM865.get(i4);
            i4++;
            byte[] bArr2 = (byte[]) obj;
            System.arraycopy(bArr2, 0, bArr, length, bArr2.length);
            length += bArr2.length;
        }
        return bArr;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˈᵲᵢ */
    public final String mo103() throws IOException {
        int iM870 = m870();
        int i = this.f1085;
        int i2 = this.f1083;
        int i3 = i2 - i;
        byte[] bArrM861 = this.f1086;
        if (iM870 <= i3 && iM870 > 0) {
            this.f1085 = i + iM870;
        } else {
            if (iM870 == 0) {
                return "";
            }
            if (iM870 < 0) {
                throw InvalidProtocolBufferException.m837();
            }
            i = 0;
            if (iM870 <= i2) {
                m869(iM870);
                this.f1085 = iM870;
            } else {
                bArrM861 = m861(iM870);
            }
        }
        return AbstractC4937.f18752.ᵱʡˏ(bArrM861, i, iM870);
    }

    /* JADX INFO: renamed from: ˈⁱᵡ, reason: contains not printable characters */
    public final void m862() {
        int i = this.f1083 + this.f1088;
        this.f1083 = i;
        int i2 = this.f1087 + i;
        int i3 = this.f1084;
        if (i2 <= i3) {
            this.f1088 = 0;
            return;
        }
        int i4 = i2 - i3;
        this.f1088 = i4;
        this.f1083 = i - i4;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˉᵲ */
    public final long mo104() {
        return m867();
    }

    /* JADX INFO: renamed from: ˊˌˊ, reason: contains not printable characters */
    public final boolean m863(int i) throws IOException {
        ByteArrayInputStream byteArrayInputStream = this.f1082;
        int i2 = this.f1085;
        int i3 = i2 + i;
        int i4 = this.f1083;
        if (i3 <= i4) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ(AbstractC0793.m2876(i, "refillBuffer() called when ", " bytes were already available in buffer"));
            return false;
        }
        int i5 = this.f1087;
        if (i <= (Integer.MAX_VALUE - i5) - i2 && i5 + i2 + i <= this.f1084) {
            byte[] bArr = this.f1086;
            if (i2 > 0) {
                if (i4 > i2) {
                    System.arraycopy(bArr, i2, bArr, 0, i4 - i2);
                }
                this.f1087 += i2;
                this.f1083 -= i2;
                this.f1085 = 0;
            }
            int i6 = this.f1083;
            try {
                int i7 = byteArrayInputStream.read(bArr, i6, Math.min(bArr.length - i6, (Integer.MAX_VALUE - this.f1087) - i6));
                if (i7 == 0 || i7 < -1 || i7 > bArr.length) {
                    throw new IllegalStateException(byteArrayInputStream.getClass() + "#read(byte[]) returned invalid result: " + i7 + "\nThe InputStream implementation is buggy.");
                }
                if (i7 > 0) {
                    this.f1083 += i7;
                    m862();
                    if (this.f1083 >= i || m863(i)) {
                        return true;
                    }
                }
            } catch (InvalidProtocolBufferException e) {
                e.f1070 = true;
                throw e;
            }
        }
        return false;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˊᵙᵾᵲ */
    public final int mo105() {
        return m864();
    }

    /* JADX INFO: renamed from: ˊᵡᵗʨ, reason: contains not printable characters */
    public final int m864() throws InvalidProtocolBufferException {
        int i = this.f1085;
        if (this.f1083 - i < 4) {
            m869(4);
            i = this.f1085;
        }
        this.f1085 = i + 4;
        byte[] bArr = this.f1086;
        return ((bArr[i + 3] & 255) << 24) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˊᵨᵧ */
    public final int mo107() {
        return m870();
    }

    /* JADX INFO: renamed from: ˊᵾʽʼ, reason: contains not printable characters */
    public final ArrayList m865(int i) throws IOException {
        ArrayList arrayList = new ArrayList();
        while (i > 0) {
            int iMin = Math.min(i, 4096);
            byte[] bArr = new byte[iMin];
            int i2 = 0;
            while (i2 < iMin) {
                int i3 = this.f1082.read(bArr, i2, iMin - i2);
                if (i3 == -1) {
                    throw InvalidProtocolBufferException.m839();
                }
                this.f1087 += i3;
                i2 += i3;
            }
            i -= iMin;
            arrayList.add(bArr);
        }
        return arrayList;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˋˈ */
    public final C1236 mo846() throws IOException {
        int iM870 = m870();
        int i = this.f1083;
        int i2 = this.f1085;
        int i3 = i - i2;
        byte[] bArr = this.f1086;
        if (iM870 <= i3 && iM870 > 0) {
            C1236 c1236M9729 = AbstractC4613.m9729(bArr, i2, iM870);
            this.f1085 += iM870;
            return c1236M9729;
        }
        if (iM870 == 0) {
            return AbstractC4613.f17546;
        }
        if (iM870 < 0) {
            throw InvalidProtocolBufferException.m837();
        }
        byte[] bArrM860 = m860(iM870);
        if (bArrM860 != null) {
            return AbstractC4613.m9729(bArrM860, 0, bArrM860.length);
        }
        int i4 = this.f1085;
        int i5 = this.f1083;
        int length = i5 - i4;
        this.f1087 += i5;
        this.f1085 = 0;
        this.f1083 = 0;
        ArrayList arrayListM865 = m865(iM870 - length);
        byte[] bArr2 = new byte[iM870];
        System.arraycopy(bArr, i4, bArr2, 0, length);
        int size = arrayListM865.size();
        int i6 = 0;
        while (i6 < size) {
            Object obj = arrayListM865.get(i6);
            i6++;
            byte[] bArr3 = (byte[]) obj;
            System.arraycopy(bArr3, 0, bArr2, length, bArr3.length);
            length += bArr3.length;
        }
        C1236 c1236 = AbstractC4613.f17546;
        return new C1236(bArr2);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˌᴵ */
    public final long mo109() {
        return m866();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˌᵨʠᵫ */
    public final int mo110() throws InvalidProtocolBufferException {
        if (mo126()) {
            this.f1081 = 0;
            return 0;
        }
        int iM870 = m870();
        this.f1081 = iM870;
        if ((iM870 >>> 3) != 0) {
            return iM870;
        }
        throw InvalidProtocolBufferException.m838();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˏːˆ */
    public final float mo111() {
        return Float.intBitsToFloat(m864());
    }

    /* JADX INFO: renamed from: ˑʢ, reason: contains not printable characters */
    public final long m866() {
        long j;
        long j2;
        long j3;
        long j4;
        int i = this.f1085;
        int i2 = this.f1083;
        if (i2 != i) {
            int i3 = i + 1;
            byte[] bArr = this.f1086;
            byte b = bArr[i];
            if (b >= 0) {
                this.f1085 = i3;
                return b;
            }
            if (i2 - i3 >= 9) {
                int i4 = i + 2;
                int i5 = (bArr[i3] << 7) ^ b;
                if (i5 < 0) {
                    j = i5 ^ (-128);
                } else {
                    int i6 = i + 3;
                    int i7 = (bArr[i4] << 14) ^ i5;
                    if (i7 >= 0) {
                        j = i7 ^ 16256;
                        i4 = i6;
                    } else {
                        int i8 = i + 4;
                        int i9 = i7 ^ (bArr[i6] << 21);
                        if (i9 < 0) {
                            j4 = (-2080896) ^ i9;
                        } else {
                            long j5 = i9;
                            i4 = i + 5;
                            long j6 = j5 ^ (((long) bArr[i8]) << 28);
                            if (j6 >= 0) {
                                j3 = 266354560;
                            } else {
                                i8 = i + 6;
                                long j7 = j6 ^ (((long) bArr[i4]) << 35);
                                if (j7 < 0) {
                                    j2 = -34093383808L;
                                } else {
                                    i4 = i + 7;
                                    j6 = j7 ^ (((long) bArr[i8]) << 42);
                                    if (j6 >= 0) {
                                        j3 = 4363953127296L;
                                    } else {
                                        i8 = i + 8;
                                        j7 = j6 ^ (((long) bArr[i4]) << 49);
                                        if (j7 < 0) {
                                            j2 = -558586000294016L;
                                        } else {
                                            i4 = i + 9;
                                            long j8 = (j7 ^ (((long) bArr[i8]) << 56)) ^ 71499008037633920L;
                                            if (j8 < 0) {
                                                int i10 = i + 10;
                                                if (bArr[i4] >= 0) {
                                                    i4 = i10;
                                                }
                                            }
                                            j = j8;
                                        }
                                    }
                                }
                                j4 = j2 ^ j7;
                            }
                            j = j3 ^ j6;
                        }
                        i4 = i8;
                        j = j4;
                    }
                }
                this.f1085 = i4;
                return j;
            }
        }
        return m859();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ˑˊᵲ */
    public final long mo113() {
        return m866();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵔᵖᵹᵫ */
    public final long mo114() {
        return m867();
    }

    /* JADX INFO: renamed from: ᵛˑﹳ, reason: contains not printable characters */
    public final long m867() throws InvalidProtocolBufferException {
        int i = this.f1085;
        if (this.f1083 - i < 8) {
            m869(8);
            i = this.f1085;
        }
        this.f1085 = i + 8;
        byte[] bArr = this.f1086;
        return ((((long) bArr[i + 1]) & 255) << 8) | (((long) bArr[i]) & 255) | ((((long) bArr[i + 2]) & 255) << 16) | ((((long) bArr[i + 3]) & 255) << 24) | ((((long) bArr[i + 4]) & 255) << 32) | ((((long) bArr[i + 5]) & 255) << 40) | ((((long) bArr[i + 6]) & 255) << 48) | ((((long) bArr[i + 7]) & 255) << 56);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵜᵪʾ */
    public final int mo116() {
        return m864();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵝᵶ */
    public final boolean mo117() {
        return m866() != 0;
    }

    /* JADX INFO: renamed from: ᵞᵛᵘ, reason: contains not printable characters */
    public final void m868(int i) throws InvalidProtocolBufferException {
        int i2 = this.f1083;
        int i3 = this.f1085;
        int i4 = i2 - i3;
        if (i <= i4 && i >= 0) {
            this.f1085 = i3 + i;
            return;
        }
        ByteArrayInputStream byteArrayInputStream = this.f1082;
        if (i < 0) {
            throw InvalidProtocolBufferException.m837();
        }
        int i5 = this.f1087;
        int i6 = i5 + i3;
        int i7 = i6 + i;
        int i8 = this.f1084;
        if (i7 > i8) {
            m868((i8 - i5) - i3);
            throw InvalidProtocolBufferException.m839();
        }
        this.f1087 = i6;
        this.f1083 = 0;
        this.f1085 = 0;
        while (i4 < i) {
            long j = i - i4;
            try {
                try {
                    long jSkip = byteArrayInputStream.skip(j);
                    if (jSkip < 0 || jSkip > j) {
                        throw new IllegalStateException(byteArrayInputStream.getClass() + "#skip returned invalid result: " + jSkip + "\nThe InputStream implementation is buggy.");
                    }
                    if (jSkip == 0) {
                        break;
                    } else {
                        i4 += (int) jSkip;
                    }
                } catch (InvalidProtocolBufferException e) {
                    e.f1070 = true;
                    throw e;
                }
            } catch (Throwable th) {
                this.f1087 += i4;
                m862();
                throw th;
            }
        }
        this.f1087 += i4;
        m862();
        if (i4 >= i) {
            return;
        }
        int i9 = this.f1083;
        int i10 = i9 - this.f1085;
        this.f1085 = i9;
        m869(1);
        while (true) {
            int i11 = i - i10;
            int i12 = this.f1083;
            if (i11 <= i12) {
                this.f1085 = i11;
                return;
            } else {
                i10 += i12;
                this.f1085 = i12;
                m869(1);
            }
        }
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵟᵹᵙ */
    public final double mo118() {
        return Double.longBitsToDouble(m867());
    }

    /* JADX INFO: renamed from: ᵨˈʼﹶ, reason: contains not printable characters */
    public final void m869(int i) throws InvalidProtocolBufferException {
        if (m863(i)) {
            return;
        }
        if (i <= (Integer.MAX_VALUE - this.f1087) - this.f1085) {
            throw InvalidProtocolBufferException.m839();
        }
        throw new InvalidProtocolBufferException("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit. If reading multiple messages, consider resetting the counter between each message using CodedInputStream.resetSizeCounter().");
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵨᵼⁱ */
    public final int mo119() {
        return AbstractC2638.m6409(m870());
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵮᵣᵗˈ */
    public final int mo121(int i) throws InvalidProtocolBufferException {
        if (i < 0) {
            throw InvalidProtocolBufferException.m837();
        }
        int i2 = this.f1087 + this.f1085 + i;
        if (i2 < 0) {
            throw new InvalidProtocolBufferException("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit. If reading multiple messages, consider resetting the counter between each message using CodedInputStream.resetSizeCounter().");
        }
        int i3 = this.f1084;
        if (i2 > i3) {
            throw InvalidProtocolBufferException.m839();
        }
        this.f1084 = i2;
        m862();
        return i3;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵯᵷʽ */
    public final long mo122() {
        return AbstractC2638.m6408(m866());
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵱʡˏ */
    public final int mo123() {
        return m870();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵱᵽʡᵚ */
    public final void mo124(int i) {
        this.f1084 = i;
        m862();
    }

    /* JADX INFO: renamed from: ᵵᵬᵽ, reason: contains not printable characters */
    public final int m870() {
        int i;
        int i2 = this.f1085;
        int i3 = this.f1083;
        if (i3 != i2) {
            int i4 = i2 + 1;
            byte[] bArr = this.f1086;
            byte b = bArr[i2];
            if (b >= 0) {
                this.f1085 = i4;
                return b;
            }
            if (i3 - i4 >= 9) {
                int i5 = i2 + 2;
                int i6 = (bArr[i4] << 7) ^ b;
                if (i6 < 0) {
                    i = i6 ^ (-128);
                } else {
                    int i7 = i2 + 3;
                    int i8 = (bArr[i5] << 14) ^ i6;
                    if (i8 >= 0) {
                        i = i8 ^ 16256;
                    } else {
                        int i9 = i2 + 4;
                        int i10 = i8 ^ (bArr[i7] << 21);
                        if (i10 < 0) {
                            i = (-2080896) ^ i10;
                        } else {
                            i7 = i2 + 5;
                            byte b2 = bArr[i9];
                            int i11 = (i10 ^ (b2 << 28)) ^ 266354560;
                            if (b2 < 0) {
                                i9 = i2 + 6;
                                if (bArr[i7] < 0) {
                                    i7 = i2 + 7;
                                    if (bArr[i9] < 0) {
                                        i9 = i2 + 8;
                                        if (bArr[i7] < 0) {
                                            i7 = i2 + 9;
                                            if (bArr[i9] < 0) {
                                                int i12 = i2 + 10;
                                                if (bArr[i7] >= 0) {
                                                    i5 = i12;
                                                    i = i11;
                                                }
                                            }
                                        }
                                    }
                                }
                                i = i11;
                            }
                            i = i11;
                        }
                        i5 = i9;
                    }
                    i5 = i7;
                }
                this.f1085 = i5;
                return i;
            }
        }
        return (int) m859();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵵᵽ */
    public final boolean mo126() {
        return this.f1085 == this.f1083 && !m863(1);
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵶˇᵱ */
    public final String mo127() throws InvalidProtocolBufferException {
        int iM870 = m870();
        byte[] bArr = this.f1086;
        if (iM870 > 0) {
            int i = this.f1083;
            int i2 = this.f1085;
            if (iM870 <= i - i2) {
                String str = new String(bArr, i2, iM870, AbstractC1130.f4831);
                this.f1085 += iM870;
                return str;
            }
        }
        if (iM870 == 0) {
            return "";
        }
        if (iM870 < 0) {
            throw InvalidProtocolBufferException.m837();
        }
        if (iM870 > this.f1083) {
            return new String(m861(iM870), AbstractC1130.f4831);
        }
        m869(iM870);
        String str2 = new String(bArr, this.f1085, iM870, AbstractC1130.f4831);
        this.f1085 += iM870;
        return str2;
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵸˆˁ */
    public final int mo128() {
        return m870();
    }

    @Override // defpackage.AbstractC2638
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final int mo129() {
        return this.f1087 + this.f1085;
    }
}
