package p138.p176.p328;

import com.google.protobuf.InvalidProtocolBufferException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import p138.p139.p143.p144.C2803;
import p138.p176.p328.AbstractC6013;

/* JADX INFO: renamed from: ދ.ހ.ނ.ބ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C6022 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final byte[] f16894;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final boolean f16895;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public int f16896;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public int f16897;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public int f16898;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public int f16900;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public int f16902;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public int f16904;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public boolean f16901 = false;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public int f16903 = Integer.MAX_VALUE;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public int f16905 = 100;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public int f16906 = 67108864;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public InterfaceC6023 f16907 = null;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final InputStream f16899 = null;

    /* JADX INFO: renamed from: ދ.ހ.ނ.ބ$֏, reason: contains not printable characters */
    public interface InterfaceC6023 {
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        void m9380();
    }

    public C6022(byte[] bArr, int i, int i2, boolean z) {
        this.f16894 = bArr;
        this.f16896 = i2 + i;
        this.f16898 = i;
        this.f16902 = -i;
        this.f16895 = z;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public <T extends InterfaceC6049> T m9364(InterfaceC6052<T> interfaceC6052, C6025 c6025) throws InvalidProtocolBufferException {
        int iM9371 = m9371();
        if (this.f16904 >= this.f16905) {
            throw new InvalidProtocolBufferException("Protocol message had too many levels of nesting.  May be malicious.  Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
        }
        int iM9367 = m9367(iM9371);
        this.f16904++;
        T tMo9408 = interfaceC6052.mo9408(this, c6025);
        m9365(0);
        this.f16904--;
        this.f16903 = iM9367;
        m9379();
        return tMo9408;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9365(int i) throws InvalidProtocolBufferException {
        if (this.f16900 != i) {
            throw new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:42:0x00b8  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean m9366() throws InvalidProtocolBufferException {
        long jM9373;
        int i;
        long j;
        long j2;
        long j3;
        long j4;
        int i2;
        int i3 = this.f16898;
        int i4 = this.f16896;
        if (i4 == i3) {
            jM9373 = m9373();
        } else {
            byte[] bArr = this.f16894;
            int i5 = i3 + 1;
            byte b = bArr[i3];
            if (b >= 0) {
                this.f16898 = i5;
                jM9373 = b;
            } else if (i4 - i5 >= 9) {
                int i6 = i5 + 1;
                int i7 = b ^ (bArr[i5] << 7);
                if (i7 < 0) {
                    i2 = i7 ^ (-128);
                } else {
                    i = i6 + 1;
                    int i8 = i7 ^ (bArr[i6] << 14);
                    if (i8 >= 0) {
                        jM9373 = i8 ^ 16256;
                        this.f16898 = i;
                    } else {
                        i6 = i + 1;
                        int i9 = i8 ^ (bArr[i] << 21);
                        if (i9 < 0) {
                            i2 = i9 ^ (-2080896);
                        } else {
                            long j5 = i9;
                            int i10 = i6 + 1;
                            long j6 = j5 ^ (((long) bArr[i6]) << 28);
                            if (j6 >= 0) {
                                j3 = 266354560;
                            } else {
                                i6 = i10 + 1;
                                long j7 = j6 ^ (((long) bArr[i10]) << 35);
                                if (j7 < 0) {
                                    j2 = -34093383808L;
                                } else {
                                    i10 = i6 + 1;
                                    j6 = j7 ^ (((long) bArr[i6]) << 42);
                                    if (j6 >= 0) {
                                        j3 = 4363953127296L;
                                    } else {
                                        i6 = i10 + 1;
                                        j7 = j6 ^ (((long) bArr[i10]) << 49);
                                        if (j7 < 0) {
                                            j2 = -558586000294016L;
                                        } else {
                                            i10 = i6 + 1;
                                            long j8 = (j7 ^ (((long) bArr[i6]) << 56)) ^ 71499008037633920L;
                                            if (j8 < 0) {
                                                int i11 = i10 + 1;
                                                if (bArr[i10] >= 0) {
                                                    i10 = i11;
                                                }
                                                jM9373 = m9373();
                                            }
                                            j = j8;
                                            i = i10;
                                            jM9373 = j;
                                            this.f16898 = i;
                                        }
                                    }
                                }
                                j4 = j7 ^ j2;
                                j = j4;
                                i = i6;
                                jM9373 = j;
                                this.f16898 = i;
                            }
                            j = j6 ^ j3;
                            i = i10;
                            jM9373 = j;
                            this.f16898 = i;
                        }
                    }
                }
                j4 = i2;
                j = j4;
                i = i6;
                jM9373 = j;
                this.f16898 = i;
            }
        }
        return jM9373 != 0;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public int m9367(int i) {
        if (i < 0) {
            throw InvalidProtocolBufferException.m1457();
        }
        int i2 = this.f16902 + this.f16898 + i;
        int i3 = this.f16903;
        if (i2 > i3) {
            throw InvalidProtocolBufferException.m1458();
        }
        this.f16903 = i2;
        m9379();
        return i3;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public AbstractC6013 m9368() {
        int iM9371 = m9371();
        int i = this.f16896;
        int i2 = this.f16898;
        if (iM9371 > i - i2 || iM9371 <= 0) {
            return iM9371 == 0 ? AbstractC6013.f16886 : AbstractC6013.m9356(m9370(iM9371));
        }
        AbstractC6013 abstractC6013M9355 = (this.f16895 && this.f16901) ? AbstractC6013.m9355(this.f16894, i2, iM9371) : new AbstractC6013.C6020(AbstractC6013.f16887.mo9362(this.f16894, this.f16898, iM9371));
        this.f16898 += iM9371;
        return abstractC6013M9355;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public byte m9369() throws InvalidProtocolBufferException {
        if (this.f16898 == this.f16896) {
            m9372(1);
        }
        byte[] bArr = this.f16894;
        int i = this.f16898;
        this.f16898 = i + 1;
        return bArr[i];
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final byte[] m9370(int i) throws IOException {
        if (i <= 0) {
            if (i == 0) {
                return C6041.f16936;
            }
            throw InvalidProtocolBufferException.m1457();
        }
        int i2 = this.f16902;
        int i3 = this.f16898;
        int i4 = i2 + i3 + i;
        if (i4 > this.f16906) {
            throw new InvalidProtocolBufferException("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit.");
        }
        int i5 = this.f16903;
        if (i4 > i5) {
            m9376((i5 - i2) - i3);
            throw InvalidProtocolBufferException.m1458();
        }
        InputStream inputStream = this.f16899;
        if (inputStream == null) {
            throw InvalidProtocolBufferException.m1458();
        }
        int i6 = this.f16896;
        int length = i6 - i3;
        this.f16902 = i2 + i6;
        this.f16898 = 0;
        this.f16896 = 0;
        int i7 = i - length;
        if (i7 < 4096 || i7 <= inputStream.available()) {
            byte[] bArr = new byte[i];
            System.arraycopy(this.f16894, i3, bArr, 0, length);
            while (length < i) {
                int i8 = this.f16899.read(bArr, length, i - length);
                if (i8 == -1) {
                    throw InvalidProtocolBufferException.m1458();
                }
                this.f16902 += i8;
                length += i8;
            }
            return bArr;
        }
        ArrayList<byte[]> arrayList = new ArrayList();
        while (i7 > 0) {
            int iMin = Math.min(i7, 4096);
            byte[] bArr2 = new byte[iMin];
            int i9 = 0;
            while (i9 < iMin) {
                int i10 = this.f16899.read(bArr2, i9, iMin - i9);
                if (i10 == -1) {
                    throw InvalidProtocolBufferException.m1458();
                }
                this.f16902 += i10;
                i9 += i10;
            }
            i7 -= iMin;
            arrayList.add(bArr2);
        }
        byte[] bArr3 = new byte[i];
        System.arraycopy(this.f16894, i3, bArr3, 0, length);
        for (byte[] bArr4 : arrayList) {
            System.arraycopy(bArr4, 0, bArr3, length, bArr4.length);
            length += bArr4.length;
        }
        return bArr3;
    }

    /* JADX WARN: Code restructure failed: missing block: B:33:0x0068, code lost:
    
        if (r2[r3] < 0) goto L34;
     */
    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public int m9371() {
        int i;
        int i2 = this.f16898;
        int i3 = this.f16896;
        if (i3 != i2) {
            byte[] bArr = this.f16894;
            int i4 = i2 + 1;
            byte b = bArr[i2];
            if (b >= 0) {
                this.f16898 = i4;
                return b;
            }
            if (i3 - i4 >= 9) {
                int i5 = i4 + 1;
                int i6 = b ^ (bArr[i4] << 7);
                if (i6 < 0) {
                    i = i6 ^ (-128);
                } else {
                    int i7 = i5 + 1;
                    int i8 = i6 ^ (bArr[i5] << 14);
                    if (i8 >= 0) {
                        i = i8 ^ 16256;
                    } else {
                        i5 = i7 + 1;
                        int i9 = i8 ^ (bArr[i7] << 21);
                        if (i9 < 0) {
                            i = i9 ^ (-2080896);
                        } else {
                            i7 = i5 + 1;
                            byte b2 = bArr[i5];
                            i = (i9 ^ (b2 << 28)) ^ 266354560;
                            if (b2 < 0) {
                                i5 = i7 + 1;
                                if (bArr[i7] < 0) {
                                    i7 = i5 + 1;
                                    if (bArr[i5] < 0) {
                                        i5 = i7 + 1;
                                        if (bArr[i7] < 0) {
                                            i7 = i5 + 1;
                                            if (bArr[i5] < 0) {
                                                i5 = i7 + 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    i5 = i7;
                }
                this.f16898 = i5;
                return i;
            }
        }
        return (int) m9373();
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final void m9372(int i) throws InvalidProtocolBufferException {
        if (!m9378(i)) {
            throw InvalidProtocolBufferException.m1458();
        }
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public long m9373() throws InvalidProtocolBufferException {
        long j = 0;
        for (int i = 0; i < 64; i += 7) {
            byte bM9369 = m9369();
            j |= ((long) (bM9369 & 127)) << i;
            if ((bM9369 & 128) == 0) {
                return j;
            }
        }
        throw new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint.");
    }

    /* JADX WARN: Removed duplicated region for block: B:36:0x005f  */
    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean m9374(int i) throws InvalidProtocolBufferException {
        int iM9377;
        int i2 = i & 7;
        if (i2 != 0) {
            if (i2 == 1) {
                m9376(8);
                return true;
            }
            if (i2 == 2) {
                m9376(m9371());
                return true;
            }
            if (i2 != 3) {
                if (i2 == 4) {
                    return false;
                }
                if (i2 != 5) {
                    throw new InvalidProtocolBufferException("Protocol message tag had invalid wire type.");
                }
                m9376(4);
                return true;
            }
            do {
                iM9377 = m9377();
                if (iM9377 == 0) {
                    break;
                }
            } while (m9374(iM9377));
            m9365(((i >>> 3) << 3) | 4);
            return true;
        }
        int i3 = this.f16896;
        int i4 = this.f16898;
        if (i3 - i4 < 10) {
            while (i < 10) {
            }
            throw new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint.");
        }
        byte[] bArr = this.f16894;
        int i5 = 0;
        while (i5 < 10) {
            int i6 = i4 + 1;
            if (bArr[i4] >= 0) {
                this.f16898 = i6;
                break;
            }
            i5++;
            i4 = i6;
        }
        for (int i7 = 0; i7 < 10; i7++) {
            if (m9369() < 0) {
            }
        }
        throw new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint.");
        return true;
    }

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public String m9375() throws IOException {
        byte[] bArrM9370;
        int iM9371 = m9371();
        int i = this.f16898;
        if (iM9371 <= this.f16896 - i && iM9371 > 0) {
            bArrM9370 = this.f16894;
            this.f16898 = i + iM9371;
        } else {
            if (iM9371 == 0) {
                return "";
            }
            if (iM9371 <= this.f16896) {
                m9372(iM9371);
                bArrM9370 = this.f16894;
                this.f16898 = iM9371 + 0;
            } else {
                bArrM9370 = m9370(iM9371);
            }
            i = 0;
        }
        if (C6065.f16966.mo9446(0, bArrM9370, i, i + iM9371) == 0) {
            return new String(bArrM9370, i, iM9371, C6041.f16935);
        }
        throw new InvalidProtocolBufferException("Protocol message had invalid UTF-8.");
    }

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public void m9376(int i) throws InvalidProtocolBufferException {
        int i2 = this.f16896;
        int i3 = this.f16898;
        if (i <= i2 - i3 && i >= 0) {
            this.f16898 = i3 + i;
            return;
        }
        if (i < 0) {
            throw InvalidProtocolBufferException.m1457();
        }
        int i4 = this.f16902;
        int i5 = this.f16898;
        int i6 = i4 + i5 + i;
        int i7 = this.f16903;
        if (i6 > i7) {
            m9376((i7 - i4) - i5);
            throw InvalidProtocolBufferException.m1458();
        }
        int i8 = this.f16896;
        int i9 = i8 - i5;
        this.f16898 = i8;
        m9372(1);
        while (true) {
            int i10 = i - i9;
            int i11 = this.f16896;
            if (i10 <= i11) {
                this.f16898 = i10;
                return;
            } else {
                i9 += i11;
                this.f16898 = i11;
                m9372(1);
            }
        }
    }

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public int m9377() throws InvalidProtocolBufferException {
        if (this.f16898 == this.f16896 && !m9378(1)) {
            this.f16900 = 0;
            return 0;
        }
        int iM9371 = m9371();
        this.f16900 = iM9371;
        if ((iM9371 >>> 3) != 0) {
            return iM9371;
        }
        throw new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero).");
    }

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final boolean m9378(int i) throws IOException {
        int i2 = this.f16898;
        if (i2 + i <= this.f16896) {
            throw new IllegalStateException(C2803.m4872("refillBuffer() called when ", i, " bytes were already available in buffer"));
        }
        if (this.f16902 + i2 + i > this.f16903) {
            return false;
        }
        InterfaceC6023 interfaceC6023 = this.f16907;
        if (interfaceC6023 != null) {
            interfaceC6023.m9380();
        }
        if (this.f16899 != null) {
            int i3 = this.f16898;
            if (i3 > 0) {
                int i4 = this.f16896;
                if (i4 > i3) {
                    byte[] bArr = this.f16894;
                    System.arraycopy(bArr, i3, bArr, 0, i4 - i3);
                }
                this.f16902 += i3;
                this.f16896 -= i3;
                this.f16898 = 0;
            }
            InputStream inputStream = this.f16899;
            byte[] bArr2 = this.f16894;
            int i5 = this.f16896;
            int i6 = inputStream.read(bArr2, i5, bArr2.length - i5);
            if (i6 == 0 || i6 < -1 || i6 > this.f16894.length) {
                throw new IllegalStateException(C2803.m4872("InputStream#read(byte[]) returned invalid result: ", i6, "\nThe InputStream implementation is buggy."));
            }
            if (i6 > 0) {
                this.f16896 += i6;
                if ((this.f16902 + i) - this.f16906 > 0) {
                    throw new InvalidProtocolBufferException("Protocol message was too large.  May be malicious.  Use CodedInputStream.setSizeLimit() to increase the size limit.");
                }
                m9379();
                if (this.f16896 >= i) {
                    return true;
                }
                return m9378(i);
            }
        }
        return false;
    }

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final void m9379() {
        int i = this.f16896 + this.f16897;
        this.f16896 = i;
        int i2 = this.f16902 + i;
        int i3 = this.f16903;
        if (i2 <= i3) {
            this.f16897 = 0;
            return;
        }
        int i4 = i2 - i3;
        this.f16897 = i4;
        this.f16896 = i - i4;
    }
}
