package wp;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import rm.n0;
import tp.u1;
import tp.y1;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public final class i0 extends xp.b implements t, e, xp.m {

    /* renamed from: u, reason: collision with root package name */
    private static final AtomicReferenceFieldUpdater f49606u = AtomicReferenceFieldUpdater.newUpdater(i0.class, Object.class, "_state");
    private volatile Object _state;

    /* renamed from: t, reason: collision with root package name */
    private int f49607t;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public static final class a extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f49608p;

        /* renamed from: q, reason: collision with root package name */
        Object f49609q;

        /* renamed from: r, reason: collision with root package name */
        Object f49610r;

        /* renamed from: s, reason: collision with root package name */
        Object f49611s;

        /* renamed from: t, reason: collision with root package name */
        Object f49612t;

        /* renamed from: u, reason: collision with root package name */
        /* synthetic */ Object f49613u;

        /* renamed from: w, reason: collision with root package name */
        int f49615w;

        a(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f49613u = obj;
            this.f49615w |= Integer.MIN_VALUE;
            return i0.this.collect(null, this);
        }
    }

    public i0(Object obj) {
        this._state = obj;
    }

    private final boolean p(Object obj, Object obj2) {
        int i10;
        xp.d[] m10;
        synchronized (this) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f49606u;
            Object obj3 = atomicReferenceFieldUpdater.get(this);
            if (obj != null && !kotlin.jvm.internal.t.b(obj3, obj)) {
                return false;
            }
            if (kotlin.jvm.internal.t.b(obj3, obj2)) {
                return true;
            }
            atomicReferenceFieldUpdater.set(this, obj2);
            int i11 = this.f49607t;
            if ((i11 & 1) != 0) {
                this.f49607t = i11 + 2;
                return true;
            }
            int i12 = i11 + 1;
            this.f49607t = i12;
            xp.d[] m11 = m();
            n0 n0Var = n0.f34904a;
            while (true) {
                k0[] k0VarArr = (k0[]) m11;
                if (k0VarArr != null) {
                    for (k0 k0Var : k0VarArr) {
                        if (k0Var != null) {
                            k0Var.g();
                        }
                    }
                }
                synchronized (this) {
                    i10 = this.f49607t;
                    if (i10 == i12) {
                        this.f49607t = i12 + 1;
                        return true;
                    }
                    m10 = m();
                    n0 n0Var2 = n0.f34904a;
                }
                m11 = m10;
                i12 = i10;
            }
        }
    }

    @Override // wp.t
    public boolean a(Object obj, Object obj2) {
        if (obj == null) {
            obj = xp.p.f50997a;
        }
        if (obj2 == null) {
            obj2 = xp.p.f50997a;
        }
        return p(obj, obj2);
    }

    @Override // xp.m
    public e b(vm.g gVar, int i10, vp.a aVar) {
        return j0.d(this, gVar, i10, aVar);
    }

    @Override // wp.s
    public void c() {
        throw new UnsupportedOperationException("MutableStateFlow.resetReplayCache is not supported");
    }

    /* JADX WARN: Code restructure failed: missing block: B:20:0x00a5, code lost:
    
        if (kotlin.jvm.internal.t.b(r9, r11) == false) goto L38;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:17:0x009c A[Catch: all -> 0x0061, TryCatch #0 {all -> 0x0061, blocks: (B:14:0x003e, B:15:0x0094, B:17:0x009c, B:19:0x00a1, B:21:0x00c2, B:23:0x00c8, B:27:0x00a7, B:30:0x00ae, B:39:0x005c), top: B:7:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:19:0x00a1 A[Catch: all -> 0x0061, TryCatch #0 {all -> 0x0061, blocks: (B:14:0x003e, B:15:0x0094, B:17:0x009c, B:19:0x00a1, B:21:0x00c2, B:23:0x00c8, B:27:0x00a7, B:30:0x00ae, B:39:0x005c), top: B:7:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:23:0x00c8 A[Catch: all -> 0x0061, TRY_LEAVE, TryCatch #0 {all -> 0x0061, blocks: (B:14:0x003e, B:15:0x0094, B:17:0x009c, B:19:0x00a1, B:21:0x00c2, B:23:0x00c8, B:27:0x00a7, B:30:0x00ae, B:39:0x005c), top: B:7:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00ab  */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00c0 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:33:0x00c1  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00ad  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x007a  */
    /* JADX WARN: Removed duplicated region for block: B:9:0x0025  */
    /* JADX WARN: Type inference failed for: r2v0, types: [int] */
    /* JADX WARN: Type inference failed for: r2v1 */
    /* JADX WARN: Type inference failed for: r2v14 */
    /* JADX WARN: Type inference failed for: r2v15 */
    /* JADX WARN: Type inference failed for: r2v16 */
    /* JADX WARN: Type inference failed for: r2v17 */
    /* JADX WARN: Type inference failed for: r2v2, types: [xp.d] */
    /* JADX WARN: Type inference failed for: r2v21 */
    /* JADX WARN: Type inference failed for: r2v3 */
    /* JADX WARN: Type inference failed for: r2v4 */
    /* JADX WARN: Type inference failed for: r2v5 */
    /* JADX WARN: Type inference failed for: r2v7, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r2v9, types: [wp.k0] */
    /* JADX WARN: Type inference failed for: r7v1, types: [xp.b] */
    /* JADX WARN: Type inference failed for: r7v10 */
    /* JADX WARN: Type inference failed for: r7v11 */
    /* JADX WARN: Type inference failed for: r7v12 */
    /* JADX WARN: Type inference failed for: r7v2 */
    /* JADX WARN: Type inference failed for: r7v3 */
    /* JADX WARN: Type inference failed for: r7v5, types: [java.lang.Object] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:22:0x00c6 -> B:15:0x0094). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:24:0x00d8 -> B:15:0x0094). Please report as a decompilation issue!!! */
    @Override // wp.x, wp.e
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object collect(f fVar, vm.d dVar) {
        a aVar;
        Object f10;
        ?? r22;
        ?? r72;
        f fVar2;
        u1 u1Var;
        Object obj;
        i0 i0Var;
        k0 k0Var;
        boolean h10;
        Object obj2;
        try {
            if (dVar instanceof a) {
                aVar = (a) dVar;
                int i10 = aVar.f49615w;
                if ((i10 & Integer.MIN_VALUE) != 0) {
                    aVar.f49615w = i10 - Integer.MIN_VALUE;
                    Object obj3 = aVar.f49613u;
                    f10 = wm.d.f();
                    r22 = aVar.f49615w;
                    if (r22 != 0) {
                        rm.y.b(obj3);
                        r22 = (k0) h();
                    } else if (r22 == 1) {
                        r22 = (k0) aVar.f49610r;
                        fVar = (f) aVar.f49609q;
                        this = (i0) aVar.f49608p;
                        try {
                            rm.y.b(obj3);
                            r22 = r22;
                        } catch (Throwable th2) {
                            r72 = this;
                            th = th2;
                            r72.k(r22);
                            throw th;
                        }
                    } else if (r22 == 2) {
                        obj = aVar.f49612t;
                        u1Var = (u1) aVar.f49611s;
                        k0 k0Var2 = (k0) aVar.f49610r;
                        fVar2 = (f) aVar.f49609q;
                        i0 i0Var2 = (i0) aVar.f49608p;
                        rm.y.b(obj3);
                        k0Var = k0Var2;
                        i0Var = i0Var2;
                        h10 = k0Var.h();
                        r22 = k0Var;
                        r72 = i0Var;
                        if (!h10) {
                        }
                        Object obj4 = f49606u.get(r72);
                        if (u1Var != null) {
                        }
                        if (obj != null) {
                        }
                        if (obj4 == xp.p.f50997a) {
                        }
                        aVar.f49608p = r72;
                        aVar.f49609q = fVar2;
                        aVar.f49610r = r22;
                        aVar.f49611s = u1Var;
                        aVar.f49612t = obj4;
                        aVar.f49615w = 2;
                        if (fVar2.emit(obj2, aVar) == f10) {
                        }
                    } else {
                        if (r22 != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        obj = aVar.f49612t;
                        u1Var = (u1) aVar.f49611s;
                        k0 k0Var3 = (k0) aVar.f49610r;
                        fVar2 = (f) aVar.f49609q;
                        i0 i0Var3 = (i0) aVar.f49608p;
                        rm.y.b(obj3);
                        r22 = k0Var3;
                        r72 = i0Var3;
                        Object obj42 = f49606u.get(r72);
                        if (u1Var != null) {
                            y1.i(u1Var);
                        }
                        if (obj != null) {
                            k0Var = r22;
                            i0Var = r72;
                        }
                        obj2 = obj42 == xp.p.f50997a ? null : obj42;
                        aVar.f49608p = r72;
                        aVar.f49609q = fVar2;
                        aVar.f49610r = r22;
                        aVar.f49611s = u1Var;
                        aVar.f49612t = obj42;
                        aVar.f49615w = 2;
                        if (fVar2.emit(obj2, aVar) == f10) {
                            return f10;
                        }
                        obj = obj42;
                        k0Var = r22;
                        i0Var = r72;
                        h10 = k0Var.h();
                        r22 = k0Var;
                        r72 = i0Var;
                        if (!h10) {
                            aVar.f49608p = i0Var;
                            aVar.f49609q = fVar2;
                            aVar.f49610r = k0Var;
                            aVar.f49611s = u1Var;
                            aVar.f49612t = obj;
                            aVar.f49615w = 3;
                            Object e10 = k0Var.e(aVar);
                            r22 = k0Var;
                            r72 = i0Var;
                            if (e10 == f10) {
                                return f10;
                            }
                        }
                        Object obj422 = f49606u.get(r72);
                        if (u1Var != null) {
                        }
                        if (obj != null) {
                        }
                        if (obj422 == xp.p.f50997a) {
                        }
                        aVar.f49608p = r72;
                        aVar.f49609q = fVar2;
                        aVar.f49610r = r22;
                        aVar.f49611s = u1Var;
                        aVar.f49612t = obj422;
                        aVar.f49615w = 2;
                        if (fVar2.emit(obj2, aVar) == f10) {
                        }
                    }
                    r72 = this;
                    fVar2 = fVar;
                    u1Var = (u1) aVar.getContext().d(u1.f36592j);
                    obj = null;
                    r22 = r22;
                    Object obj4222 = f49606u.get(r72);
                    if (u1Var != null) {
                    }
                    if (obj != null) {
                    }
                    if (obj4222 == xp.p.f50997a) {
                    }
                    aVar.f49608p = r72;
                    aVar.f49609q = fVar2;
                    aVar.f49610r = r22;
                    aVar.f49611s = u1Var;
                    aVar.f49612t = obj4222;
                    aVar.f49615w = 2;
                    if (fVar2.emit(obj2, aVar) == f10) {
                    }
                }
            }
            if (r22 != 0) {
            }
            r72 = this;
            fVar2 = fVar;
            u1Var = (u1) aVar.getContext().d(u1.f36592j);
            obj = null;
            r22 = r22;
            Object obj42222 = f49606u.get(r72);
            if (u1Var != null) {
            }
            if (obj != null) {
            }
            if (obj42222 == xp.p.f50997a) {
            }
            aVar.f49608p = r72;
            aVar.f49609q = fVar2;
            aVar.f49610r = r22;
            aVar.f49611s = u1Var;
            aVar.f49612t = obj42222;
            aVar.f49615w = 2;
            if (fVar2.emit(obj2, aVar) == f10) {
            }
        } catch (Throwable th3) {
            th = th3;
        }
        aVar = new a(dVar);
        Object obj32 = aVar.f49613u;
        f10 = wm.d.f();
        r22 = aVar.f49615w;
    }

    @Override // wp.s
    public boolean d(Object obj) {
        setValue(obj);
        return true;
    }

    @Override // wp.s, wp.f
    public Object emit(Object obj, vm.d dVar) {
        setValue(obj);
        return n0.f34904a;
    }

    @Override // wp.t, wp.h0
    public Object getValue() {
        zp.h0 h0Var = xp.p.f50997a;
        Object obj = f49606u.get(this);
        if (obj == h0Var) {
            return null;
        }
        return obj;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // xp.b
    /* renamed from: n, reason: merged with bridge method [inline-methods] */
    public k0 i() {
        return new k0();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // xp.b
    /* renamed from: o, reason: merged with bridge method [inline-methods] */
    public k0[] j(int i10) {
        return new k0[i10];
    }

    @Override // wp.t
    public void setValue(Object obj) {
        if (obj == null) {
            obj = xp.p.f50997a;
        }
        p(null, obj);
    }
}
