package o;

import java.io.IOException;
import java.util.ArrayDeque;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class RF {
    public final int a;
    public final KF b;
    public long c;
    public long d;
    public long e;
    public long f;
    public final ArrayDeque g;
    public boolean h;
    public final PF i;
    public final OF j;
    public final QF k;
    public final QF l;
    public int m;
    public IOException n;

    public RF(int i, KF kf, boolean z, boolean z2, LE le) {
        this.a = i;
        this.b = kf;
        this.f = kf.B.a();
        ArrayDeque arrayDeque = new ArrayDeque();
        this.g = arrayDeque;
        this.i = new PF(this, kf.A.a(), z2);
        this.j = new OF(this, z);
        this.k = new QF(this);
        this.l = new QF(this);
        if (le == null) {
            if (!g()) {
                throw new IllegalStateException("remotely-initiated streams should have headers");
            }
        } else {
            if (g()) {
                throw new IllegalStateException("locally-initiated streams shouldn't have headers yet");
            }
            arrayDeque.add(le);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x001c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void a() {
        /*
            r2 = this;
            byte[] r0 = o.AbstractC2264qi0.a
            monitor-enter(r2)
            o.PF r0 = r2.i     // Catch: java.lang.Throwable -> L18
            boolean r1 = r0.m     // Catch: java.lang.Throwable -> L18
            if (r1 != 0) goto L1c
            boolean r0 = r0.p     // Catch: java.lang.Throwable -> L18
            if (r0 == 0) goto L1c
            o.OF r0 = r2.j     // Catch: java.lang.Throwable -> L18
            boolean r1 = r0.l     // Catch: java.lang.Throwable -> L18
            if (r1 != 0) goto L1a
            boolean r0 = r0.n     // Catch: java.lang.Throwable -> L18
            if (r0 == 0) goto L1c
            goto L1a
        L18:
            r0 = move-exception
            goto L35
        L1a:
            r0 = 1
            goto L1d
        L1c:
            r0 = 0
        L1d:
            boolean r1 = r2.h()     // Catch: java.lang.Throwable -> L18
            monitor-exit(r2)
            if (r0 == 0) goto L2b
            r0 = 9
            r1 = 0
            r2.c(r0, r1)
            return
        L2b:
            if (r1 != 0) goto L34
            o.KF r0 = r2.b
            int r1 = r2.a
            r0.d(r1)
        L34:
            return
        L35:
            monitor-exit(r2)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: o.RF.a():void");
    }

    public final void b() throws IOException {
        OF of = this.j;
        if (of.n) {
            throw new IOException("stream closed");
        }
        if (of.l) {
            throw new IOException("stream finished");
        }
        if (this.m != 0) {
            IOException iOException = this.n;
            if (iOException == null) {
                throw new Ta0(this.m);
            }
        }
    }

    public final void c(int i, IOException iOException) {
        if (d(i, iOException)) {
            this.b.H.l(this.a, i);
        }
    }

    public final boolean d(int i, IOException iOException) {
        byte[] bArr = AbstractC2264qi0.a;
        synchronized (this) {
            if (this.m != 0) {
                return false;
            }
            this.m = i;
            this.n = iOException;
            notifyAll();
            if (this.i.m) {
                if (this.j.l) {
                    return false;
                }
            }
            this.b.d(this.a);
            return true;
        }
    }

    public final void e(int i) {
        if (d(i, null)) {
            this.b.l(this.a, i);
        }
    }

    public final OF f() {
        synchronized (this) {
            if (!this.h && !g()) {
                throw new IllegalStateException("reply before requesting the sink");
            }
        }
        return this.j;
    }

    public final boolean g() {
        boolean z = (this.a & 1) == 1;
        this.b.getClass();
        return true == z;
    }

    public final synchronized boolean h() {
        try {
            if (this.m != 0) {
                return false;
            }
            PF pf = this.i;
            if (pf.m || pf.p) {
                OF of = this.j;
                if (of.l || of.n) {
                    if (this.h) {
                        return false;
                    }
                }
            }
            return true;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final void i(LE le, boolean z) {
        boolean zH;
        byte[] bArr = AbstractC2264qi0.a;
        synchronized (this) {
            try {
                if (this.h && z) {
                    this.i.getClass();
                } else {
                    this.h = true;
                    this.g.add(le);
                }
                if (z) {
                    this.i.m = true;
                }
                zH = h();
                notifyAll();
            } catch (Throwable th) {
                throw th;
            }
        }
        if (zH) {
            return;
        }
        this.b.d(this.a);
    }
}
