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

import defpackage.AbstractC0715;
import defpackage.AbstractC2202;
import defpackage.AbstractC3026;
import defpackage.AbstractC3306;
import defpackage.AbstractC3915;
import defpackage.C5500;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;

/* renamed from: com.google.crypto.tink.shaded.protobuf.ˏᵙ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0022 extends AbstractC0715 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public int f1087;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public int f1088;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public int f1089;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final ByteArrayInputStream f1090;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public int f1091;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public int f1092 = Integer.MAX_VALUE;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public int f1093;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final byte[] f1094;

    public C0022(ByteArrayInputStream byteArrayInputStream) {
        Charset charset = AbstractC3306.f12387;
        this.f1090 = byteArrayInputStream;
        this.f1094 = new byte[4096];
        this.f1087 = 0;
        this.f1088 = 0;
        this.f1091 = 0;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˀᵗᵝᵭ */
    public final String mo153() throws IOException {
        int iM922 = m922();
        int i = this.f1088;
        int i2 = this.f1087;
        int i3 = i2 - i;
        byte[] bArrM919 = this.f1094;
        if (iM922 <= i3 && iM922 > 0) {
            this.f1088 = i + iM922;
        } else {
            if (iM922 == 0) {
                return "";
            }
            if (iM922 < 0) {
                throw InvalidProtocolBufferException.m834();
            }
            i = 0;
            if (iM922 <= i2) {
                m915(iM922);
                this.f1088 = iM922;
            } else {
                bArrM919 = m919(iM922);
            }
        }
        return AbstractC3026.f11662.ᵨᵳʝ(bArrM919, i, iM922);
    }

    /* renamed from: ˀᵗᵩ, reason: contains not printable characters */
    public final void m913() {
        int i = this.f1087 + this.f1089;
        this.f1087 = i;
        int i2 = this.f1091 + i;
        int i3 = this.f1092;
        if (i2 <= i3) {
            this.f1089 = 0;
            return;
        }
        int i4 = i2 - i3;
        this.f1089 = i4;
        this.f1087 = i - i4;
    }

    /* renamed from: ˁˑᵰ, reason: contains not printable characters */
    public final ArrayList m914(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.f1090.read(bArr, i2, iMin - i2);
                if (i3 == -1) {
                    throw InvalidProtocolBufferException.m835();
                }
                this.f1091 += i3;
                i2 += i3;
            }
            i -= iMin;
            arrayList.add(bArr);
        }
        return arrayList;
    }

    /* renamed from: ˆᵼᵷˊ, reason: contains not printable characters */
    public final void m915(int i) throws InvalidProtocolBufferException {
        if (m917(i)) {
            return;
        }
        if (i <= (Integer.MAX_VALUE - this.f1091) - this.f1088) {
            throw InvalidProtocolBufferException.m835();
        }
        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().");
    }

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public final long m916() throws InvalidProtocolBufferException {
        long j = 0;
        for (int i = 0; i < 64; i += 7) {
            if (this.f1088 == this.f1087) {
                m915(1);
            }
            int i2 = this.f1088;
            this.f1088 = i2 + 1;
            j |= (r3 & Byte.MAX_VALUE) << i;
            if ((this.f1094[i2] & 128) == 0) {
                return j;
            }
        }
        throw InvalidProtocolBufferException.m840();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˌʾˀ */
    public final double mo158() {
        return Double.longBitsToDouble(m920());
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˌᵜᵹᵩ */
    public final int mo159(int i) throws InvalidProtocolBufferException {
        if (i < 0) {
            throw InvalidProtocolBufferException.m834();
        }
        int i2 = this.f1091 + this.f1088 + 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.f1092;
        if (i2 > i3) {
            throw InvalidProtocolBufferException.m835();
        }
        this.f1092 = i2;
        m913();
        return i3;
    }

    /* renamed from: ˌᵪ, reason: contains not printable characters */
    public final boolean m917(int i) throws IOException {
        ByteArrayInputStream byteArrayInputStream = this.f1090;
        int i2 = this.f1088;
        int i3 = i2 + i;
        int i4 = this.f1087;
        if (i3 <= i4) {
            ᵹˉᵞ.ᵳٴᵶ(AbstractC3915.m8596(i, "refillBuffer() called when ", " bytes were already available in buffer"));
            return false;
        }
        int i5 = this.f1091;
        if (i <= (Integer.MAX_VALUE - i5) - i2 && i5 + i2 + i <= this.f1092) {
            byte[] bArr = this.f1094;
            if (i2 > 0) {
                if (i4 > i2) {
                    System.arraycopy(bArr, i2, bArr, 0, i4 - i2);
                }
                this.f1091 += i2;
                this.f1087 -= i2;
                this.f1088 = 0;
            }
            int i6 = this.f1087;
            try {
                int i7 = byteArrayInputStream.read(bArr, i6, Math.min(bArr.length - i6, (Integer.MAX_VALUE - this.f1091) - 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.f1087 += i7;
                    m913();
                    if (this.f1087 >= i || m917(i)) {
                        return true;
                    }
                }
            } catch (InvalidProtocolBufferException e) {
                e.f1070 = true;
                throw e;
            }
        }
        return false;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˎˏʜʾ */
    public final boolean mo161() {
        return this.f1088 == this.f1087 && !m917(1);
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˎˑː */
    public final long mo162() {
        return m918();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˏˋٴ */
    public final int mo163() {
        return this.f1091 + this.f1088;
    }

    /* renamed from: ˑᵝﹳᵜ, reason: contains not printable characters */
    public final long m918() {
        long j;
        long j2;
        long j3;
        long j4;
        int i = this.f1088;
        int i2 = this.f1087;
        if (i2 != i) {
            int i3 = i + 1;
            byte[] bArr = this.f1094;
            byte b = bArr[i];
            if (b >= 0) {
                this.f1088 = 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 ^ (bArr[i8] << 28);
                            if (j6 >= 0) {
                                j3 = 266354560;
                            } else {
                                i8 = i + 6;
                                long j7 = j6 ^ (bArr[i4] << 35);
                                if (j7 < 0) {
                                    j2 = -34093383808L;
                                } else {
                                    i4 = i + 7;
                                    j6 = j7 ^ (bArr[i8] << 42);
                                    if (j6 >= 0) {
                                        j3 = 4363953127296L;
                                    } else {
                                        i8 = i + 8;
                                        j7 = j6 ^ (bArr[i4] << 49);
                                        if (j7 < 0) {
                                            j2 = -558586000294016L;
                                        } else {
                                            i4 = i + 9;
                                            long j8 = (j7 ^ (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.f1088 = i4;
                return j;
            }
        }
        return m916();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˑᵥˁ */
    public final int mo165() {
        return m922();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ˑᵱ */
    public final int mo166() {
        return m922();
    }

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public final byte[] m919(int i) throws IOException {
        byte[] bArrM924 = m924(i);
        if (bArrM924 != null) {
            return bArrM924;
        }
        int i2 = this.f1088;
        int i3 = this.f1087;
        int length = i3 - i2;
        this.f1091 += i3;
        this.f1088 = 0;
        this.f1087 = 0;
        ArrayList arrayListM914 = m914(i - length);
        byte[] bArr = new byte[i];
        System.arraycopy(this.f1094, i2, bArr, 0, length);
        int size = arrayListM914.size();
        int i4 = 0;
        while (i4 < size) {
            Object obj = arrayListM914.get(i4);
            i4++;
            byte[] bArr2 = (byte[]) obj;
            System.arraycopy(bArr2, 0, bArr, length, bArr2.length);
            length += bArr2.length;
        }
        return bArr;
    }

    /* renamed from: ᵙᵢᵨᵳ, reason: contains not printable characters */
    public final long m920() throws InvalidProtocolBufferException {
        int i = this.f1088;
        if (this.f1087 - i < 8) {
            m915(8);
            i = this.f1088;
        }
        this.f1088 = i + 8;
        byte[] bArr = this.f1094;
        return ((bArr[i + 1] & 255) << 8) | (bArr[i] & 255) | ((bArr[i + 2] & 255) << 16) | ((bArr[i + 3] & 255) << 24) | ((bArr[i + 4] & 255) << 32) | ((bArr[i + 5] & 255) << 40) | ((bArr[i + 6] & 255) << 48) | ((bArr[i + 7] & 255) << 56);
    }

    /* renamed from: ᵛˈᵤ, reason: contains not printable characters */
    public final void m921(int i) throws InvalidProtocolBufferException {
        int i2 = this.f1087;
        int i3 = this.f1088;
        int i4 = i2 - i3;
        if (i <= i4 && i >= 0) {
            this.f1088 = i3 + i;
            return;
        }
        ByteArrayInputStream byteArrayInputStream = this.f1090;
        if (i < 0) {
            throw InvalidProtocolBufferException.m834();
        }
        int i5 = this.f1091;
        int i6 = i5 + i3;
        int i7 = i6 + i;
        int i8 = this.f1092;
        if (i7 > i8) {
            m921((i8 - i5) - i3);
            throw InvalidProtocolBufferException.m835();
        }
        this.f1091 = i6;
        this.f1087 = 0;
        this.f1088 = 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.f1091 += i4;
                m913();
                throw th;
            }
        }
        this.f1091 += i4;
        m913();
        if (i4 >= i) {
            return;
        }
        int i9 = this.f1087;
        int i10 = i9 - this.f1088;
        this.f1088 = i9;
        m915(1);
        while (true) {
            int i11 = i - i10;
            int i12 = this.f1087;
            if (i11 <= i12) {
                this.f1088 = i11;
                return;
            } else {
                i10 += i12;
                this.f1088 = i12;
                m915(1);
            }
        }
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵞʡ */
    public final long mo170() {
        return m920();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵡʠ */
    public final int mo171() {
        return m922();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵡˎ */
    public final int mo172() throws InvalidProtocolBufferException {
        if (mo161()) {
            this.f1093 = 0;
            return 0;
        }
        int iM922 = m922();
        this.f1093 = iM922;
        if ((iM922 >>> 3) != 0) {
            return iM922;
        }
        throw InvalidProtocolBufferException.m838();
    }

    /* renamed from: ᵡᵘˎʽ, reason: contains not printable characters */
    public final int m922() {
        int i;
        int i2 = this.f1088;
        int i3 = this.f1087;
        if (i3 != i2) {
            int i4 = i2 + 1;
            byte[] bArr = this.f1094;
            byte b = bArr[i2];
            if (b >= 0) {
                this.f1088 = 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.f1088 = i5;
                return i;
            }
        }
        return (int) m916();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵡⁱᵥ */
    public final String mo174() throws InvalidProtocolBufferException {
        int iM922 = m922();
        byte[] bArr = this.f1094;
        if (iM922 > 0) {
            int i = this.f1087;
            int i2 = this.f1088;
            if (iM922 <= i - i2) {
                String str = new String(bArr, i2, iM922, AbstractC3306.f12387);
                this.f1088 += iM922;
                return str;
            }
        }
        if (iM922 == 0) {
            return "";
        }
        if (iM922 < 0) {
            throw InvalidProtocolBufferException.m834();
        }
        if (iM922 > this.f1087) {
            return new String(m919(iM922), AbstractC3306.f12387);
        }
        m915(iM922);
        String str2 = new String(bArr, this.f1088, iM922, AbstractC3306.f12387);
        this.f1088 += iM922;
        return str2;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵢˇᵭ */
    public final int mo175() {
        return m925();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵤᵙᵷ */
    public final long mo176() {
        return AbstractC0715.m2711(m918());
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵧᵾˀˈ */
    public final long mo177() {
        return m918();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵨᵳʝ */
    public final float mo178() {
        return Float.intBitsToFloat(m925());
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public final C5500 mo923() throws IOException {
        int iM922 = m922();
        int i = this.f1087;
        int i2 = this.f1088;
        int i3 = i - i2;
        byte[] bArr = this.f1094;
        if (iM922 <= i3 && iM922 > 0) {
            C5500 c5500M5862 = AbstractC2202.m5862(bArr, i2, iM922);
            this.f1088 += iM922;
            return c5500M5862;
        }
        if (iM922 == 0) {
            return AbstractC2202.f8641;
        }
        if (iM922 < 0) {
            throw InvalidProtocolBufferException.m834();
        }
        byte[] bArrM924 = m924(iM922);
        if (bArrM924 != null) {
            return AbstractC2202.m5862(bArrM924, 0, bArrM924.length);
        }
        int i4 = this.f1088;
        int i5 = this.f1087;
        int length = i5 - i4;
        this.f1091 += i5;
        this.f1088 = 0;
        this.f1087 = 0;
        ArrayList arrayListM914 = m914(iM922 - length);
        byte[] bArr2 = new byte[iM922];
        System.arraycopy(bArr, i4, bArr2, 0, length);
        int size = arrayListM914.size();
        int i6 = 0;
        while (i6 < size) {
            Object obj = arrayListM914.get(i6);
            i6++;
            byte[] bArr3 = (byte[]) obj;
            System.arraycopy(bArr3, 0, bArr2, length, bArr3.length);
            length += bArr3.length;
        }
        C5500 c5500 = AbstractC2202.f8641;
        return new C5500(bArr2);
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵯٴᵦ */
    public final boolean mo180() {
        return m918() != 0;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵴᵳ */
    public final void mo182(int i) throws InvalidProtocolBufferException {
        if (this.f1093 != i) {
            throw new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
        }
    }

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public final byte[] m924(int i) throws IOException {
        if (i == 0) {
            return AbstractC3306.f12388;
        }
        if (i < 0) {
            throw InvalidProtocolBufferException.m834();
        }
        int i2 = this.f1091;
        int i3 = this.f1088;
        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.f1092;
        if (i4 > i5) {
            m921((i5 - i2) - i3);
            throw InvalidProtocolBufferException.m835();
        }
        int i6 = this.f1087 - i3;
        int i7 = i - i6;
        ByteArrayInputStream byteArrayInputStream = this.f1090;
        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.f1094, this.f1088, bArr, 0, i6);
        this.f1091 += this.f1087;
        this.f1088 = 0;
        this.f1087 = 0;
        while (i6 < i) {
            try {
                int i8 = byteArrayInputStream.read(bArr, i6, i - i6);
                if (i8 == -1) {
                    throw InvalidProtocolBufferException.m835();
                }
                this.f1091 += i8;
                i6 += i8;
            } catch (InvalidProtocolBufferException e2) {
                e2.f1070 = true;
                throw e2;
            }
        }
        return bArr;
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵶᵷᵕ */
    public final void mo184(int i) {
        this.f1092 = i;
        m913();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵸʓᵠ */
    public final int mo185() {
        return m925();
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵾᵬ */
    public final int mo186() {
        return AbstractC0715.m2713(m922());
    }

    @Override // defpackage.AbstractC0715
    /* renamed from: ᵿʗᵝʽ */
    public final long mo187() {
        return m920();
    }

    /* renamed from: ﾞⁱ, reason: contains not printable characters */
    public final int m925() throws InvalidProtocolBufferException {
        int i = this.f1088;
        if (this.f1087 - i < 4) {
            m915(4);
            i = this.f1088;
        }
        this.f1088 = i + 4;
        byte[] bArr = this.f1094;
        return ((bArr[i + 3] & 255) << 24) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16);
    }
}
