package d.a.s.e.c;

import d.a.m;

/* JADX INFO: loaded from: classes.dex */
public final class i<T> extends d.a.s.e.c.a<T, T> {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final d.a.m f5750c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final boolean f5751d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f5752e;

    public static final class a<T> extends d.a.s.d.a<T> implements d.a.l<T>, Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final d.a.l<? super T> f5753b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public final m.c f5754c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public final boolean f5755d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public final int f5756e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public d.a.s.c.d<T> f5757f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public d.a.p.b f5758g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public Throwable f5759h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        public volatile boolean f5760i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        public volatile boolean f5761j;
        public int k;
        public boolean l;

        public a(d.a.l<? super T> lVar, m.c cVar, boolean z, int i2) {
            this.f5753b = lVar;
            this.f5754c = cVar;
            this.f5755d = z;
            this.f5756e = i2;
        }

        @Override // d.a.l
        public void a(Throwable th) {
            if (this.f5760i) {
                d.a.u.a.w(th);
                return;
            }
            this.f5759h = th;
            this.f5760i = true;
            f();
        }

        @Override // d.a.l
        public void b() {
            if (this.f5760i) {
                return;
            }
            this.f5760i = true;
            f();
        }

        @Override // d.a.l
        public void c(d.a.p.b bVar) {
            if (d.a.s.a.b.validate(this.f5758g, bVar)) {
                this.f5758g = bVar;
                if (bVar instanceof d.a.s.c.a) {
                    d.a.s.c.a aVar = (d.a.s.c.a) bVar;
                    int iRequestFusion = aVar.requestFusion(7);
                    if (iRequestFusion == 1) {
                        this.k = iRequestFusion;
                        this.f5757f = aVar;
                        this.f5760i = true;
                        this.f5753b.c(this);
                        f();
                        return;
                    }
                    if (iRequestFusion == 2) {
                        this.k = iRequestFusion;
                        this.f5757f = aVar;
                        this.f5753b.c(this);
                        return;
                    }
                }
                this.f5757f = new d.a.s.f.b(this.f5756e);
                this.f5753b.c(this);
            }
        }

        @Override // d.a.s.c.d
        public void clear() {
            this.f5757f.clear();
        }

        @Override // d.a.l
        public void d(T t) {
            if (this.f5760i) {
                return;
            }
            if (this.k != 2) {
                this.f5757f.offer(t);
            }
            f();
        }

        @Override // d.a.p.b
        public void dispose() {
            if (this.f5761j) {
                return;
            }
            this.f5761j = true;
            this.f5758g.dispose();
            this.f5754c.dispose();
            if (getAndIncrement() == 0) {
                this.f5757f.clear();
            }
        }

        public boolean e(boolean z, boolean z2, d.a.l<? super T> lVar) {
            if (this.f5761j) {
                this.f5757f.clear();
                return true;
            }
            if (!z) {
                return false;
            }
            Throwable th = this.f5759h;
            if (this.f5755d) {
                if (!z2) {
                    return false;
                }
                this.f5761j = true;
                if (th != null) {
                    lVar.a(th);
                } else {
                    lVar.b();
                }
                this.f5754c.dispose();
                return true;
            }
            if (th != null) {
                this.f5761j = true;
                this.f5757f.clear();
                lVar.a(th);
                this.f5754c.dispose();
                return true;
            }
            if (!z2) {
                return false;
            }
            this.f5761j = true;
            lVar.b();
            this.f5754c.dispose();
            return true;
        }

        public void f() {
            if (getAndIncrement() == 0) {
                this.f5754c.b(this);
            }
        }

        @Override // d.a.p.b
        public boolean isDisposed() {
            return this.f5761j;
        }

        @Override // d.a.s.c.d
        public boolean isEmpty() {
            return this.f5757f.isEmpty();
        }

        @Override // d.a.s.c.d
        public T poll() {
            return this.f5757f.poll();
        }

        @Override // d.a.s.c.a
        public int requestFusion(int i2) {
            if ((i2 & 2) == 0) {
                return 0;
            }
            this.l = true;
            return 2;
        }

        /* JADX WARN: Code restructure failed: missing block: B:36:0x006f, code lost:
        
            r3 = addAndGet(-r3);
         */
        /* JADX WARN: Code restructure failed: missing block: B:37:0x0074, code lost:
        
            if (r3 != 0) goto L53;
         */
        /* JADX WARN: Code restructure failed: missing block: B:59:?, code lost:
        
            return;
         */
        @Override // java.lang.Runnable
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void run() {
            /*
                r7 = this;
                boolean r0 = r7.l
                r1 = 1
                if (r0 == 0) goto L49
                r0 = r1
            L6:
                boolean r2 = r7.f5761j
                if (r2 == 0) goto Lc
                goto L91
            Lc:
                boolean r2 = r7.f5760i
                java.lang.Throwable r3 = r7.f5759h
                boolean r4 = r7.f5755d
                if (r4 != 0) goto L22
                if (r2 == 0) goto L22
                if (r3 == 0) goto L22
                r7.f5761j = r1
                d.a.l<? super T> r0 = r7.f5753b
                java.lang.Throwable r1 = r7.f5759h
                r0.a(r1)
                goto L3b
            L22:
                d.a.l<? super T> r3 = r7.f5753b
                r4 = 0
                r3.d(r4)
                if (r2 == 0) goto L41
                r7.f5761j = r1
                java.lang.Throwable r0 = r7.f5759h
                if (r0 == 0) goto L36
                d.a.l<? super T> r1 = r7.f5753b
                r1.a(r0)
                goto L3b
            L36:
                d.a.l<? super T> r0 = r7.f5753b
                r0.b()
            L3b:
                d.a.m$c r0 = r7.f5754c
                r0.dispose()
                goto L91
            L41:
                int r0 = -r0
                int r0 = r7.addAndGet(r0)
                if (r0 != 0) goto L6
                goto L91
            L49:
                d.a.s.c.d<T> r0 = r7.f5757f
                d.a.l<? super T> r2 = r7.f5753b
                r3 = r1
            L4e:
                boolean r4 = r7.f5760i
                boolean r5 = r0.isEmpty()
                boolean r4 = r7.e(r4, r5, r2)
                if (r4 == 0) goto L5b
                goto L91
            L5b:
                boolean r4 = r7.f5760i
                java.lang.Object r5 = r0.poll()     // Catch: java.lang.Throwable -> L7b
                if (r5 != 0) goto L65
                r6 = r1
                goto L66
            L65:
                r6 = 0
            L66:
                boolean r4 = r7.e(r4, r6, r2)
                if (r4 == 0) goto L6d
                goto L91
            L6d:
                if (r6 == 0) goto L77
                int r3 = -r3
                int r3 = r7.addAndGet(r3)
                if (r3 != 0) goto L4e
                goto L91
            L77:
                r2.d(r5)
                goto L5b
            L7b:
                r3 = move-exception
                a.a.a.a.c.n0.y(r3)
                r7.f5761j = r1
                d.a.p.b r1 = r7.f5758g
                r1.dispose()
                r0.clear()
                r2.a(r3)
                d.a.m$c r0 = r7.f5754c
                r0.dispose()
            L91:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: d.a.s.e.c.i.a.run():void");
        }
    }

    public i(d.a.k<T> kVar, d.a.m mVar, boolean z, int i2) {
        super(kVar);
        this.f5750c = mVar;
        this.f5751d = z;
        this.f5752e = i2;
    }

    @Override // d.a.h
    public void o(d.a.l<? super T> lVar) {
        d.a.m mVar = this.f5750c;
        if (mVar instanceof d.a.s.g.m) {
            this.f5703b.e(lVar);
        } else {
            this.f5703b.e(new a(lVar, mVar.a(), this.f5751d, this.f5752e));
        }
    }
}
