package d;

/* JADX INFO: compiled from: PeekSource.kt */
/* JADX INFO: loaded from: classes.dex */
public final class s implements a0 {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final f f1594b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private v f1595c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private int f1596d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private boolean f1597e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private long f1598f;
    private final h g;

    public s(h hVar) {
        c.q.d.j.c(hVar, "upstream");
        this.g = hVar;
        f fVarA = hVar.a();
        this.f1594b = fVarA;
        v vVar = fVarA.f1563b;
        this.f1595c = vVar;
        this.f1596d = vVar != null ? vVar.f1607b : -1;
    }

    @Override // d.a0, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.f1597e = true;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0023  */
    @Override // d.a0
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long read(d.f r9, long r10) throws java.io.IOException {
        /*
            r8 = this;
            java.lang.String r0 = "sink"
            c.q.d.j.c(r9, r0)
            boolean r0 = r8.f1597e
            r1 = 1
            r0 = r0 ^ r1
            if (r0 == 0) goto L76
            d.v r0 = r8.f1595c
            r2 = 0
            if (r0 == 0) goto L24
            d.f r3 = r8.f1594b
            d.v r3 = r3.f1563b
            if (r0 != r3) goto L23
            int r0 = r8.f1596d
            if (r3 == 0) goto L1f
            int r3 = r3.f1607b
            if (r0 != r3) goto L23
            goto L24
        L1f:
            c.q.d.j.g()
            throw r2
        L23:
            r1 = 0
        L24:
            if (r1 == 0) goto L6a
            d.h r0 = r8.g
            long r3 = r8.f1598f
            long r3 = r3 + r10
            r0.p(r3)
            d.v r0 = r8.f1595c
            if (r0 != 0) goto L45
            d.f r0 = r8.f1594b
            d.v r0 = r0.f1563b
            if (r0 == 0) goto L45
            r8.f1595c = r0
            if (r0 == 0) goto L41
            int r0 = r0.f1607b
            r8.f1596d = r0
            goto L45
        L41:
            c.q.d.j.g()
            throw r2
        L45:
            d.f r0 = r8.f1594b
            long r0 = r0.b0()
            long r2 = r8.f1598f
            long r0 = r0 - r2
            long r10 = java.lang.Math.min(r10, r0)
            r0 = 0
            int r0 = (r10 > r0 ? 1 : (r10 == r0 ? 0 : -1))
            if (r0 > 0) goto L5b
            r9 = -1
            return r9
        L5b:
            d.f r2 = r8.f1594b
            long r4 = r8.f1598f
            r3 = r9
            r6 = r10
            r2.H(r3, r4, r6)
            long r0 = r8.f1598f
            long r0 = r0 + r10
            r8.f1598f = r0
            return r10
        L6a:
            java.lang.IllegalStateException r9 = new java.lang.IllegalStateException
            java.lang.String r10 = "Peek source is invalid because upstream source was used"
            java.lang.String r10 = r10.toString()
            r9.<init>(r10)
            throw r9
        L76:
            java.lang.IllegalStateException r9 = new java.lang.IllegalStateException
            java.lang.String r10 = "closed"
            java.lang.String r10 = r10.toString()
            r9.<init>(r10)
            throw r9
        */
        throw new UnsupportedOperationException("Method not decompiled: d.s.read(d.f, long):long");
    }

    @Override // d.a0
    public b0 timeout() {
        return this.g.timeout();
    }
}
