package o; import java.util.ArrayDeque; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; /* renamed from: o.fVq, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public final class C13273fVq extends fUX { private EnumC13357fYN a; private int b; private fSS> d; private int e; public C13273fVq(InterfaceC13169fSq interfaceC13169fSq, fSS> fss, EnumC13357fYN enumC13357fYN, int i, int i2) { super(interfaceC13169fSq); this.d = fss; this.a = enumC13357fYN; this.e = i; this.b = i2; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { this.c.subscribe(new HBt(interfaceC13174fSv, this.d, this.e, this.b, this.a)); } /* renamed from: o.fVq$HBt */ /* loaded from: classes6.dex */ static final class HBt extends AtomicInteger implements InterfaceC13174fSv, fSJ, fTW { private int a; private volatile boolean b; private volatile boolean c; private InterfaceC13174fSv d; private C13186fTX e; private fSS> f; private EnumC13357fYN h; private int i; private int k; private int l; private InterfaceC13414fZq m; private fSJ n; private C13355fYI j = new C13355fYI(); private ArrayDeque> g = new ArrayDeque<>(); HBt(InterfaceC13174fSv interfaceC13174fSv, fSS> fss, int i, int i2, EnumC13357fYN enumC13357fYN) { this.d = interfaceC13174fSv; this.f = fss; this.i = i; this.l = i2; this.h = enumC13357fYN; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.d(this.n, fsj)) { this.n = fsj; if (fsj instanceof InterfaceC13412fZo) { InterfaceC13412fZo interfaceC13412fZo = (InterfaceC13412fZo) fsj; int b = interfaceC13412fZo.b(3); if (b == 1) { this.k = b; this.m = interfaceC13412fZo; this.b = true; this.d.onSubscribe(this); d(); return; } if (b == 2) { this.k = b; this.m = interfaceC13412fZo; this.d.onSubscribe(this); return; } } this.m = new C13416fZs(this.l); this.d.onSubscribe(this); } } @Override // o.InterfaceC13174fSv public final void onNext(T t) { if (this.k == 0) { this.m.b(t); } d(); } @Override // o.InterfaceC13174fSv public final void onComplete() { this.b = true; d(); } @Override // o.fSJ public final void dispose() { if (this.c) { return; } this.c = true; this.n.dispose(); Throwable b = fYR.b(this.j); if (b != null && b != fYR.b) { C13418fZu.c(b); } if (getAndIncrement() != 0) { return; } do { this.m.e(); c(); } while (decrementAndGet() != 0); } private void c() { C13186fTX c13186fTX = this.e; if (c13186fTX != null) { c13186fTX.dispose(); } while (true) { C13186fTX poll = this.g.poll(); if (poll == null) { return; } else { poll.dispose(); } } } @Override // o.fTW public final void d() { R b; boolean z; if (getAndIncrement() != 0) { return; } InterfaceC13414fZq interfaceC13414fZq = this.m; ArrayDeque> arrayDeque = this.g; InterfaceC13174fSv interfaceC13174fSv = this.d; EnumC13357fYN enumC13357fYN = this.h; int i = 1; while (true) { int i2 = this.a; while (i2 != this.i) { if (this.c) { interfaceC13414fZq.e(); c(); return; } if (enumC13357fYN == EnumC13357fYN.IMMEDIATE && this.j.get() != null) { interfaceC13414fZq.e(); c(); C13355fYI c13355fYI = this.j; InterfaceC13174fSv interfaceC13174fSv2 = this.d; Throwable b2 = fYR.b(c13355fYI); if (b2 == null) { interfaceC13174fSv2.onComplete(); return; } else { if (b2 != fYR.b) { interfaceC13174fSv2.onError(b2); return; } return; } } try { T b3 = interfaceC13414fZq.b(); if (b3 == null) { break; } InterfaceC13169fSq interfaceC13169fSq = (InterfaceC13169fSq) Objects.requireNonNull(this.f.a(b3), "The mapper returned a null ObservableSource"); C13186fTX c13186fTX = new C13186fTX<>(this, this.l); arrayDeque.offer(c13186fTX); interfaceC13169fSq.subscribe(c13186fTX); i2++; } catch (Throwable th) { C13147fSI.c(th); this.n.dispose(); interfaceC13414fZq.e(); c(); if (!fYR.c(this.j, th)) { C13418fZu.c(th); } C13355fYI c13355fYI2 = this.j; InterfaceC13174fSv interfaceC13174fSv3 = this.d; Throwable b4 = fYR.b(c13355fYI2); if (b4 == null) { interfaceC13174fSv3.onComplete(); return; } else { if (b4 != fYR.b) { interfaceC13174fSv3.onError(b4); return; } return; } } } this.a = i2; if (this.c) { interfaceC13414fZq.e(); c(); return; } if (enumC13357fYN == EnumC13357fYN.IMMEDIATE && this.j.get() != null) { interfaceC13414fZq.e(); c(); C13355fYI c13355fYI3 = this.j; InterfaceC13174fSv interfaceC13174fSv4 = this.d; Throwable b5 = fYR.b(c13355fYI3); if (b5 == null) { interfaceC13174fSv4.onComplete(); return; } else { if (b5 != fYR.b) { interfaceC13174fSv4.onError(b5); return; } return; } } C13186fTX c13186fTX2 = this.e; if (c13186fTX2 == null) { if (enumC13357fYN == EnumC13357fYN.BOUNDARY && this.j.get() != null) { interfaceC13414fZq.e(); c(); Throwable b6 = fYR.b(this.j); if (b6 == null) { interfaceC13174fSv.onComplete(); return; } else { if (b6 != fYR.b) { interfaceC13174fSv.onError(b6); return; } return; } } boolean z2 = this.b; C13186fTX poll = arrayDeque.poll(); boolean z3 = poll == null; if (z2 && z3) { if (this.j.get() != null) { interfaceC13414fZq.e(); c(); Throwable b7 = fYR.b(this.j); if (b7 == null) { interfaceC13174fSv.onComplete(); return; } else { if (b7 != fYR.b) { interfaceC13174fSv.onError(b7); return; } return; } } interfaceC13174fSv.onComplete(); return; } if (!z3) { this.e = poll; } c13186fTX2 = poll; } if (c13186fTX2 != null) { InterfaceC13414fZq interfaceC13414fZq2 = c13186fTX2.b; while (!this.c) { boolean z4 = c13186fTX2.a; if (enumC13357fYN == EnumC13357fYN.IMMEDIATE && this.j.get() != null) { interfaceC13414fZq.e(); c(); Throwable b8 = fYR.b(this.j); if (b8 == null) { interfaceC13174fSv.onComplete(); return; } else { if (b8 != fYR.b) { interfaceC13174fSv.onError(b8); return; } return; } } try { b = interfaceC13414fZq2.b(); z = b == null; } catch (Throwable th2) { C13147fSI.c(th2); if (!fYR.c(this.j, th2)) { C13418fZu.c(th2); } this.e = null; this.a--; } if (z4 && z) { this.e = null; this.a--; } else if (!z) { interfaceC13174fSv.onNext(b); } } interfaceC13414fZq.e(); c(); return; } i = addAndGet(-i); if (i == 0) { return; } } } @Override // o.fTW public final void d(C13186fTX c13186fTX) { c13186fTX.a = true; d(); } @Override // o.fTW public final void c(C13186fTX c13186fTX, Throwable th) { if (fYR.c(this.j, th)) { if (this.h == EnumC13357fYN.IMMEDIATE) { this.n.dispose(); } c13186fTX.a = true; d(); return; } C13418fZu.c(th); } @Override // o.fTW public final void d(C13186fTX c13186fTX, R r) { c13186fTX.b.b(r); d(); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { if (fYR.c(this.j, th)) { this.b = true; d(); } else { C13418fZu.c(th); } } @Override // o.fSJ public final boolean isDisposed() { return this.c; } } }