package f.a.w.e.d;

import f.a.o;

/* JADX INFO: compiled from: ObservableObserveOn.java */
/* JADX INFO: loaded from: classes.dex */
public final class t<T> extends f.a.w.e.d.a<T, T> {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final f.a.o f3870e;

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

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

    /* JADX INFO: compiled from: ObservableObserveOn.java */
    public static final class a<T> extends f.a.w.d.b<T> implements f.a.n<T>, Runnable {

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

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public final o.c f3874e;

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

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

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

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        public f.a.t.b f3878i;

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

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

        /* JADX INFO: renamed from: l, reason: collision with root package name */
        public volatile boolean f3881l;
        public int m;
        public boolean n;

        public a(f.a.n<? super T> nVar, o.c cVar, boolean z, int i2) {
            this.f3873b = nVar;
            this.f3874e = cVar;
            this.f3875f = z;
            this.f3876g = i2;
        }

        @Override // f.a.n
        public void a(Throwable th) {
            if (this.f3880k) {
                f.a.y.a.C0(th);
                return;
            }
            this.f3879j = th;
            this.f3880k = true;
            e();
        }

        @Override // f.a.n
        public void b(f.a.t.b bVar) {
            if (f.a.w.a.b.validate(this.f3878i, bVar)) {
                this.f3878i = bVar;
                if (bVar instanceof f.a.w.c.a) {
                    f.a.w.c.a aVar = (f.a.w.c.a) bVar;
                    int iRequestFusion = aVar.requestFusion(7);
                    if (iRequestFusion == 1) {
                        this.m = iRequestFusion;
                        this.f3877h = aVar;
                        this.f3880k = true;
                        this.f3873b.b(this);
                        e();
                        return;
                    }
                    if (iRequestFusion == 2) {
                        this.m = iRequestFusion;
                        this.f3877h = aVar;
                        this.f3873b.b(this);
                        return;
                    }
                }
                this.f3877h = new f.a.w.f.c(this.f3876g);
                this.f3873b.b(this);
            }
        }

        @Override // f.a.n
        public void c(T t) {
            if (this.f3880k) {
                return;
            }
            if (this.m != 2) {
                this.f3877h.offer(t);
            }
            e();
        }

        @Override // f.a.w.c.d
        public void clear() {
            this.f3877h.clear();
        }

        public boolean d(boolean z, boolean z2, f.a.n<? super T> nVar) {
            if (this.f3881l) {
                this.f3877h.clear();
                return true;
            }
            if (!z) {
                return false;
            }
            Throwable th = this.f3879j;
            if (this.f3875f) {
                if (!z2) {
                    return false;
                }
                this.f3881l = true;
                if (th != null) {
                    nVar.a(th);
                } else {
                    nVar.onComplete();
                }
                this.f3874e.dispose();
                return true;
            }
            if (th != null) {
                this.f3881l = true;
                this.f3877h.clear();
                nVar.a(th);
                this.f3874e.dispose();
                return true;
            }
            if (!z2) {
                return false;
            }
            this.f3881l = true;
            nVar.onComplete();
            this.f3874e.dispose();
            return true;
        }

        @Override // f.a.t.b
        public void dispose() {
            if (this.f3881l) {
                return;
            }
            this.f3881l = true;
            this.f3878i.dispose();
            this.f3874e.dispose();
            if (getAndIncrement() == 0) {
                this.f3877h.clear();
            }
        }

        public void e() {
            if (getAndIncrement() == 0) {
                this.f3874e.b(this);
            }
        }

        @Override // f.a.w.c.d
        public boolean isEmpty() {
            return this.f3877h.isEmpty();
        }

        @Override // f.a.n
        public void onComplete() {
            if (this.f3880k) {
                return;
            }
            this.f3880k = true;
            e();
        }

        @Override // f.a.w.c.d
        public T poll() throws Exception {
            return this.f3877h.poll();
        }

        @Override // f.a.w.c.a
        public int requestFusion(int i2) {
            if ((i2 & 2) == 0) {
                return 0;
            }
            this.n = true;
            return 2;
        }

        /* JADX WARN: Code restructure failed: missing block: B:36:0x0075, code lost:
        
            r3 = addAndGet(-r3);
         */
        /* JADX WARN: Code restructure failed: missing block: B:37:0x007a, code lost:
        
            if (r3 != 0) goto L53;
         */
        /* JADX WARN: Code restructure failed: missing block: B:60:?, 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.n
                r1 = 1
                if (r0 == 0) goto L4f
                r0 = r1
            L6:
                boolean r2 = r7.f3881l
                if (r2 == 0) goto Lc
                goto L97
            Lc:
                boolean r2 = r7.f3880k
                java.lang.Throwable r3 = r7.f3879j
                boolean r4 = r7.f3875f
                if (r4 != 0) goto L28
                if (r2 == 0) goto L28
                if (r3 == 0) goto L28
                r7.f3881l = r1
                f.a.n<? super T> r0 = r7.f3873b
                java.lang.Throwable r1 = r7.f3879j
                r0.a(r1)
                f.a.o$c r0 = r7.f3874e
                r0.dispose()
                goto L97
            L28:
                f.a.n<? super T> r3 = r7.f3873b
                r4 = 0
                r3.c(r4)
                if (r2 == 0) goto L47
                r7.f3881l = r1
                java.lang.Throwable r0 = r7.f3879j
                if (r0 == 0) goto L3c
                f.a.n<? super T> r1 = r7.f3873b
                r1.a(r0)
                goto L41
            L3c:
                f.a.n<? super T> r0 = r7.f3873b
                r0.onComplete()
            L41:
                f.a.o$c r0 = r7.f3874e
                r0.dispose()
                goto L97
            L47:
                int r0 = -r0
                int r0 = r7.addAndGet(r0)
                if (r0 != 0) goto L6
                goto L97
            L4f:
                f.a.w.c.d<T> r0 = r7.f3877h
                f.a.n<? super T> r2 = r7.f3873b
                r3 = r1
            L54:
                boolean r4 = r7.f3880k
                boolean r5 = r0.isEmpty()
                boolean r4 = r7.d(r4, r5, r2)
                if (r4 == 0) goto L61
                goto L97
            L61:
                boolean r4 = r7.f3880k
                java.lang.Object r5 = r0.poll()     // Catch: java.lang.Throwable -> L81
                if (r5 != 0) goto L6b
                r6 = r1
                goto L6c
            L6b:
                r6 = 0
            L6c:
                boolean r4 = r7.d(r4, r6, r2)
                if (r4 == 0) goto L73
                goto L97
            L73:
                if (r6 == 0) goto L7d
                int r3 = -r3
                int r3 = r7.addAndGet(r3)
                if (r3 != 0) goto L54
                goto L97
            L7d:
                r2.c(r5)
                goto L61
            L81:
                r3 = move-exception
                d.i.c.a.L(r3)
                r7.f3881l = r1
                f.a.t.b r1 = r7.f3878i
                r1.dispose()
                r0.clear()
                r2.a(r3)
                f.a.o$c r0 = r7.f3874e
                r0.dispose()
            L97:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: f.a.w.e.d.t.a.run():void");
        }
    }

    public t(f.a.l<T> lVar, f.a.o oVar, boolean z, int i2) {
        super(lVar);
        this.f3870e = oVar;
        this.f3871f = z;
        this.f3872g = i2;
    }

    @Override // f.a.i
    public void v(f.a.n<? super T> nVar) {
        f.a.o oVar = this.f3870e;
        if (oVar instanceof f.a.w.g.o) {
            this.f3744b.d(nVar);
        } else {
            this.f3744b.d(new a(nVar, oVar.a(), this.f3871f, this.f3872g));
        }
    }
}
