package com.google.android.play.core.assetpacks;

import java.io.FilterInputStream;
import java.io.InputStream;

/* loaded from: classes3.dex */
final class q0 extends FilterInputStream {

    /* renamed from: p, reason: collision with root package name */
    private final g2 f14043p;

    /* renamed from: q, reason: collision with root package name */
    private byte[] f14044q;

    /* renamed from: r, reason: collision with root package name */
    private long f14045r;

    /* renamed from: s, reason: collision with root package name */
    private boolean f14046s;

    /* renamed from: t, reason: collision with root package name */
    private boolean f14047t;

    /* JADX INFO: Access modifiers changed from: package-private */
    public q0(InputStream inputStream) {
        super(inputStream);
        this.f14043p = new g2();
        this.f14044q = new byte[4096];
        this.f14046s = false;
        this.f14047t = false;
    }

    private final int e(byte[] bArr, int i10, int i11) {
        return Math.max(0, super.read(bArr, i10, i11));
    }

    private final boolean f(int i10) {
        int e10 = e(this.f14044q, 0, i10);
        if (e10 != i10) {
            int i11 = i10 - e10;
            if (e(this.f14044q, e10, i11) != i11) {
                this.f14043p.b(this.f14044q, 0, e10);
                return false;
            }
        }
        this.f14043p.b(this.f14044q, 0, i10);
        return true;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final long a() {
        return this.f14045r;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: Code restructure failed: missing block: B:10:0x0019, code lost:
    
        if (r9.f14047t == false) goto L11;
     */
    /* JADX WARN: Code restructure failed: missing block: B:12:0x0023, code lost:
    
        if (f(30) != false) goto L15;
     */
    /* JADX WARN: Code restructure failed: missing block: B:13:0x0025, code lost:
    
        r9.f14046s = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:14:0x002d, code lost:
    
        return r9.f14043p.c();
     */
    /* JADX WARN: Code restructure failed: missing block: B:16:0x002e, code lost:
    
        r0 = r9.f14043p.c();
     */
    /* JADX WARN: Code restructure failed: missing block: B:17:0x0038, code lost:
    
        if (r0.d() == false) goto L19;
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x003a, code lost:
    
        r9.f14047t = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:19:0x003c, code lost:
    
        return r0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x0048, code lost:
    
        if (r0.b() == 4294967295L) goto L32;
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x004a, code lost:
    
        r0 = r9.f14043p.a() - 30;
        r2 = r9.f14044q.length;
        r5 = r0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:23:0x0059, code lost:
    
        if (r5 <= r2) goto L26;
     */
    /* JADX WARN: Code restructure failed: missing block: B:24:0x005b, code lost:
    
        r2 = r2 + r2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:25:0x005f, code lost:
    
        if (r2 < r5) goto L39;
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x0061, code lost:
    
        r9.f14044q = java.util.Arrays.copyOf(r9.f14044q, r2);
     */
    /* JADX WARN: Code restructure failed: missing block: B:2:0x0006, code lost:
    
        if (r9.f14045r > 0) goto L4;
     */
    /* JADX WARN: Code restructure failed: missing block: B:30:0x006d, code lost:
    
        if (f(r0) != false) goto L30;
     */
    /* JADX WARN: Code restructure failed: missing block: B:31:0x006f, code lost:
    
        r9.f14046s = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:32:0x0077, code lost:
    
        return r9.f14043p.c();
     */
    /* JADX WARN: Code restructure failed: missing block: B:33:0x0078, code lost:
    
        r0 = r9.f14043p.c();
        r9.f14045r = r0.b();
     */
    /* JADX WARN: Code restructure failed: missing block: B:34:0x0084, code lost:
    
        return r0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:36:0x008c, code lost:
    
        throw new com.google.android.play.core.assetpacks.d1("Files bigger than 4GiB are not supported.");
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x009a, code lost:
    
        return new com.google.android.play.core.assetpacks.m0(null, -1, -1, false, false, null);
     */
    /* JADX WARN: Code restructure failed: missing block: B:3:0x0008, code lost:
    
        r0 = r9.f14044q;
     */
    /* JADX WARN: Code restructure failed: missing block: B:4:0x0011, code lost:
    
        if (read(r0, 0, r0.length) != (-1)) goto L37;
     */
    /* JADX WARN: Code restructure failed: missing block: B:8:0x0015, code lost:
    
        if (r9.f14046s != false) goto L34;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final h3 b() {
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final boolean c() {
        return this.f14047t;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final boolean d() {
        return this.f14046s;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int read(byte[] bArr) {
        return read(bArr, 0, bArr.length);
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int read(byte[] bArr, int i10, int i11) {
        long j10 = this.f14045r;
        if (j10 <= 0 || this.f14046s) {
            return -1;
        }
        int e10 = e(bArr, i10, (int) Math.min(j10, i11));
        this.f14045r -= e10;
        if (e10 != 0) {
            return e10;
        }
        this.f14046s = true;
        return 0;
    }
}
