package p5;

/* JADX INFO: loaded from: classes3.dex */
public final class H implements P {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final InterfaceC2742l f23049a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final C2740j f23050b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public K f23051c;

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public long f23054f;

    public H(InterfaceC2742l interfaceC2742l) {
        this.f23049a = interfaceC2742l;
        C2740j c2740jE = interfaceC2742l.e();
        this.f23050b = c2740jE;
        K k6 = c2740jE.f23099a;
        this.f23051c = k6;
        this.f23052d = k6 != null ? k6.f23062b : -1;
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:11:0x0020, code lost:
    
        if (r3 == r5.f23062b) goto L15;
     */
    @Override // p5.P
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long read(C2740j sink, long j4) {
        K k6;
        kotlin.jvm.internal.o.h(sink, "sink");
        if (j4 < 0) {
            throw new IllegalArgumentException(A0.a.m("byteCount < 0: ", j4).toString());
        }
        if (this.f23053e) {
            throw new IllegalStateException("closed");
        }
        K k7 = this.f23051c;
        C2740j c2740j = this.f23050b;
        if (k7 != null) {
            K k8 = c2740j.f23099a;
            if (k7 == k8) {
                int i6 = this.f23052d;
                kotlin.jvm.internal.o.e(k8);
            }
            throw new IllegalStateException("Peek source is invalid because upstream source was used");
        }
        if (j4 == 0) {
            return 0L;
        }
        if (!this.f23049a.p(this.f23054f + 1)) {
            return -1L;
        }
        if (this.f23051c == null && (k6 = c2740j.f23099a) != null) {
            this.f23051c = k6;
            this.f23052d = k6.f23062b;
        }
        long jMin = Math.min(j4, c2740j.f23100b - this.f23054f);
        this.f23050b.c(sink, this.f23054f, jMin);
        this.f23054f += jMin;
        return jMin;
    }

    @Override // p5.P
    public final S timeout() {
        return this.f23049a.timeout();
    }
}
