package o; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; /* renamed from: o.fWl, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public final class C13303fWl extends fUX { private fSS> a; private InterfaceC13169fSq b; private fSS> d; private fSL, ? extends R> e; /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: o.fWl$Sts */ /* loaded from: classes6.dex */ public interface Sts { void a(Throwable th); void a(HBt hBt); void d(Throwable th); void d(boolean z, LWm lWm); void e(boolean z, Object obj); } public C13303fWl(InterfaceC13169fSq interfaceC13169fSq, InterfaceC13169fSq interfaceC13169fSq2, fSS> fss, fSS> fss2, fSL, ? extends R> fsl) { super(interfaceC13169fSq); this.b = interfaceC13169fSq2; this.d = fss; this.a = fss2; this.e = fsl; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { IeS ieS = new IeS(interfaceC13174fSv, this.d, this.a, this.e); interfaceC13174fSv.onSubscribe(ieS); HBt hBt = new HBt(ieS, true); ieS.c.e(hBt); HBt hBt2 = new HBt(ieS, false); ieS.c.e(hBt2); this.c.subscribe(hBt); this.b.subscribe(hBt2); } /* renamed from: o.fWl$IeS */ /* loaded from: classes6.dex */ static final class IeS extends AtomicInteger implements fSJ, Sts { private fSS> f; private InterfaceC13174fSv g; private volatile boolean j; private fSS> m; private fSL, ? extends R> n; /* renamed from: o, reason: collision with root package name */ private int f9120o; private int q; private static Integer a = 1; private static Integer e = 2; private static Integer d = 3; private static Integer b = 4; final fSC c = new fSC(); private C13416fZs k = new C13416fZs<>(AbstractC13163fSk.bufferSize()); private Map> l = new LinkedHashMap(); private Map s = new LinkedHashMap(); private AtomicReference h = new AtomicReference<>(); private AtomicInteger i = new AtomicInteger(2); IeS(InterfaceC13174fSv interfaceC13174fSv, fSS> fss, fSS> fss2, fSL, ? extends R> fsl) { this.g = interfaceC13174fSv; this.f = fss; this.m = fss2; this.n = fsl; } @Override // o.fSJ public final void dispose() { if (this.j) { return; } this.j = true; this.c.dispose(); if (getAndIncrement() == 0) { this.k.e(); } } private void e(InterfaceC13174fSv interfaceC13174fSv) { Throwable b2 = fYR.b(this.h); Iterator> it = this.l.values().iterator(); while (it.hasNext()) { it.next().onError(b2); } this.l.clear(); this.s.clear(); interfaceC13174fSv.onError(b2); } private void b() { if (getAndIncrement() != 0) { return; } C13416fZs c13416fZs = this.k; InterfaceC13174fSv interfaceC13174fSv = this.g; int i = 1; while (!this.j) { if (this.h.get() != null) { c13416fZs.e(); this.c.dispose(); e(interfaceC13174fSv); return; } boolean z = this.i.get() == 0; Integer num = (Integer) c13416fZs.b(); boolean z2 = num == null; if (z && z2) { Iterator> it = this.l.values().iterator(); while (it.hasNext()) { it.next().onComplete(); } this.l.clear(); this.s.clear(); this.c.dispose(); interfaceC13174fSv.onComplete(); return; } if (!z2) { Object b2 = c13416fZs.b(); if (num == a) { C13423fZz c = C13423fZz.c(); int i2 = this.f9120o; this.f9120o = i2 + 1; this.l.put(Integer.valueOf(i2), c); try { InterfaceC13169fSq interfaceC13169fSq = (InterfaceC13169fSq) Objects.requireNonNull(this.f.a(b2), "The leftEnd returned a null ObservableSource"); LWm lWm = new LWm(this, true, i2); this.c.e(lWm); interfaceC13169fSq.subscribe(lWm); if (this.h.get() != null) { c13416fZs.e(); this.c.dispose(); e(interfaceC13174fSv); return; } try { interfaceC13174fSv.onNext((Object) Objects.requireNonNull(this.n.e(b2, c), "The resultSelector returned a null value")); Iterator it2 = this.s.values().iterator(); while (it2.hasNext()) { c.onNext(it2.next()); } } catch (Throwable th) { C13147fSI.c(th); fYR.c(this.h, th); c13416fZs.e(); this.c.dispose(); e(interfaceC13174fSv); return; } } catch (Throwable th2) { C13147fSI.c(th2); fYR.c(this.h, th2); c13416fZs.e(); this.c.dispose(); e(interfaceC13174fSv); return; } } else if (num == e) { int i3 = this.q; this.q = i3 + 1; this.s.put(Integer.valueOf(i3), b2); try { InterfaceC13169fSq interfaceC13169fSq2 = (InterfaceC13169fSq) Objects.requireNonNull(this.m.a(b2), "The rightEnd returned a null ObservableSource"); LWm lWm2 = new LWm(this, false, i3); this.c.e(lWm2); interfaceC13169fSq2.subscribe(lWm2); if (this.h.get() != null) { c13416fZs.e(); this.c.dispose(); e(interfaceC13174fSv); return; } else { Iterator> it3 = this.l.values().iterator(); while (it3.hasNext()) { it3.next().onNext(b2); } } } catch (Throwable th3) { C13147fSI.c(th3); fYR.c(this.h, th3); c13416fZs.e(); this.c.dispose(); e(interfaceC13174fSv); return; } } else if (num == d) { LWm lWm3 = (LWm) b2; C13423fZz remove = this.l.remove(Integer.valueOf(lWm3.b)); if (this.c.b(lWm3)) { lWm3.dispose(); } if (remove != null) { remove.onComplete(); } } else { LWm lWm4 = (LWm) b2; this.s.remove(Integer.valueOf(lWm4.b)); if (this.c.b(lWm4)) { lWm4.dispose(); } } } else { i = addAndGet(-i); if (i == 0) { return; } } } c13416fZs.e(); } @Override // o.C13303fWl.Sts public final void d(Throwable th) { if (fYR.c(this.h, th)) { this.i.decrementAndGet(); b(); } else { C13418fZu.c(th); } } @Override // o.C13303fWl.Sts public final void a(HBt hBt) { this.c.b(hBt); this.i.decrementAndGet(); b(); } @Override // o.C13303fWl.Sts public final void e(boolean z, Object obj) { synchronized (this) { this.k.e(z ? a : e, obj); } b(); } @Override // o.C13303fWl.Sts public final void d(boolean z, LWm lWm) { synchronized (this) { this.k.e(z ? d : b, lWm); } b(); } @Override // o.C13303fWl.Sts public final void a(Throwable th) { if (fYR.c(this.h, th)) { b(); } else { C13418fZu.c(th); } } @Override // o.fSJ public final boolean isDisposed() { return this.j; } } /* renamed from: o.fWl$HBt */ /* loaded from: classes6.dex */ static final class HBt extends AtomicReference implements InterfaceC13174fSv, fSJ { private Sts b; private boolean e; /* JADX INFO: Access modifiers changed from: package-private */ public HBt(Sts sts, boolean z) { this.b = sts; this.e = z; } @Override // o.fSJ public final void dispose() { EnumC13192fTf.e(this); } @Override // o.fSJ public final boolean isDisposed() { return EnumC13192fTf.c(get()); } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { EnumC13192fTf.a(this, fsj); } @Override // o.InterfaceC13174fSv public final void onNext(Object obj) { this.b.e(this.e, obj); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { this.b.d(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { this.b.a(this); } } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: o.fWl$LWm */ /* loaded from: classes6.dex */ public static final class LWm extends AtomicReference implements InterfaceC13174fSv, fSJ { private Sts a; final int b; private boolean e; /* JADX INFO: Access modifiers changed from: package-private */ public LWm(Sts sts, boolean z, int i) { this.a = sts; this.e = z; this.b = i; } @Override // o.fSJ public final void dispose() { EnumC13192fTf.e(this); } @Override // o.fSJ public final boolean isDisposed() { return EnumC13192fTf.c(get()); } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { EnumC13192fTf.a(this, fsj); } @Override // o.InterfaceC13174fSv public final void onNext(Object obj) { if (EnumC13192fTf.e(this)) { this.a.d(this.e, this); } } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { this.a.a(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { this.a.d(this.e, this); } } }