package defpackage;

import androidx.media3.container.NalUnitUtil;
import defpackage.fx4;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugProbesKt;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000&\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\b\u0002\u0018\u0000*\u0004\b\u0000\u0010\u00012\b\u0012\u0004\u0012\u00020\u00030\u00022\b\u0012\u0004\u0012\u00028\u00000\u00042\b\u0012\u0004\u0012\u00028\u00000\u00052\b\u0012\u0004\u0012\u00028\u00000\u0006R\u0011\u0010\t\u001a\b\u0012\u0004\u0012\u00020\b0\u00078\u0002X\u0082\u0004¨\u0006\n"}, d2 = {"Lh49;", "T", "Lu1;", "Lj49;", "Lig6;", "Lws0;", "Lcs3;", "Lww;", "", "_state", "kotlinx-coroutines-core"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
final class h49<T> extends u1<j49> implements ig6<T>, ws0<T>, cs3<T> {
    public static final /* synthetic */ AtomicReferenceFieldUpdater e = AtomicReferenceFieldUpdater.newUpdater(h49.class, Object.class, "_state$volatile");
    private volatile /* synthetic */ Object _state$volatile;
    public int d;

    public h49(Object obj) {
        this._state$volatile = obj;
    }

    @Override // defpackage.gg6
    public final boolean a(Object obj) {
        setValue(obj);
        return true;
    }

    @Override // defpackage.cs3
    public final j43 b(gj1 gj1Var, int i, ug0 ug0Var) {
        return (((i < 0 || i >= 2) && i != -2) || ug0Var != ug0.b) ? xp8.d(this, gj1Var, i, ug0Var) : this;
    }

    /* JADX WARN: Code restructure failed: missing block: B:30:0x008d, code lost:
    
        if (r6 == r4) goto L71;
     */
    /* JADX WARN: Code restructure failed: missing block: B:78:0x00a5, code lost:
    
        if (r2 != r4) goto L36;
     */
    /* JADX WARN: Path cross not found for [B:44:0x00bb, B:46:0x00c1], limit reached: 76 */
    /* JADX WARN: Path cross not found for [B:46:0x00c1, B:44:0x00bb], limit reached: 76 */
    /* JADX WARN: Path cross not found for [B:46:0x00c1, B:54:0x00dc], limit reached: 76 */
    /* JADX WARN: Path cross not found for [B:70:0x0125, B:69:0x0124], limit reached: 76 */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00ad A[Catch: all -> 0x0043, TryCatch #1 {all -> 0x0043, blocks: (B:14:0x003f, B:36:0x00a5, B:38:0x00ad, B:41:0x00b4, B:42:0x00b8, B:44:0x00bb, B:54:0x00dc, B:57:0x00ec, B:58:0x0106, B:64:0x0116, B:66:0x011e, B:61:0x010d, B:63:0x0113, B:46:0x00c1, B:50:0x00c8, B:21:0x005c, B:24:0x006d, B:35:0x0096), top: B:76:0x0029 }] */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00bb A[Catch: all -> 0x0043, TryCatch #1 {all -> 0x0043, blocks: (B:14:0x003f, B:36:0x00a5, B:38:0x00ad, B:41:0x00b4, B:42:0x00b8, B:44:0x00bb, B:54:0x00dc, B:57:0x00ec, B:58:0x0106, B:64:0x0116, B:66:0x011e, B:61:0x010d, B:63:0x0113, B:46:0x00c1, B:50:0x00c8, B:21:0x005c, B:24:0x006d, B:35:0x0096), top: B:76:0x0029 }] */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00c5  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x00c7  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00da  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x00db  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x00eb  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x00ec A[Catch: all -> 0x0043, TryCatch #1 {all -> 0x0043, blocks: (B:14:0x003f, B:36:0x00a5, B:38:0x00ad, B:41:0x00b4, B:42:0x00b8, B:44:0x00bb, B:54:0x00dc, B:57:0x00ec, B:58:0x0106, B:64:0x0116, B:66:0x011e, B:61:0x010d, B:63:0x0113, B:46:0x00c1, B:50:0x00c8, B:21:0x005c, B:24:0x006d, B:35:0x0096), top: B:76:0x0029 }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0019  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:56:0x00eb -> B:36:0x00a5). Please report as a decompilation issue!!! */
    @Override // defpackage.j43
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object collect(l43 l43Var, Continuation continuation) {
        g49 g49Var;
        h49<T> h49Var;
        j49 j49Var;
        l43 l43Var2;
        fx4 fx4Var;
        Object obj;
        Object andSet;
        Object obj2;
        Object obj3;
        l43 l43Var3 = l43Var;
        if (continuation instanceof g49) {
            g49Var = (g49) continuation;
            int i = g49Var.j;
            if ((i & Integer.MIN_VALUE) != 0) {
                g49Var.j = i - Integer.MIN_VALUE;
            } else {
                g49Var = new g49(this, continuation);
            }
        }
        Object obj4 = g49Var.f;
        ck1 ck1Var = ck1.a;
        int i2 = g49Var.j;
        e6a e6aVar = e6a.a;
        try {
            if (i2 == 0) {
                s38.b(obj4);
                j49Var = (j49) c();
                try {
                    if (l43Var3 instanceof ia9) {
                        g49Var.a = this;
                        g49Var.b = l43Var3;
                        g49Var.c = j49Var;
                        g49Var.j = 1;
                        ((ia9) l43Var3).b(g49Var);
                    }
                    h49Var = this;
                } catch (Throwable th) {
                    th = th;
                    h49Var = this;
                    h49Var.f(j49Var);
                    throw th;
                }
            } else if (i2 == 1) {
                j49Var = (j49) g49Var.c;
                l43Var3 = g49Var.b;
                h49Var = (h49) g49Var.a;
                s38.b(obj4);
            } else if (i2 == 2) {
                obj = g49Var.e;
                fx4Var = g49Var.d;
                j49Var = (j49) g49Var.c;
                l43Var2 = g49Var.b;
                h49Var = (h49) g49Var.a;
                s38.b(obj4);
                AtomicReference atomicReference = j49Var.a;
                kg9 kg9Var = i49.a;
                andSet = atomicReference.getAndSet(kg9Var);
                cr4.d(andSet);
                if (andSet == i49.b) {
                }
                obj2 = e.get(h49Var);
                if (fx4Var != null) {
                }
                if (obj != null) {
                }
                if (obj2 != kq6.a) {
                }
                g49Var.a = h49Var;
                g49Var.b = l43Var2;
                g49Var.c = j49Var;
                g49Var.d = fx4Var;
                g49Var.e = obj2;
                g49Var.j = 2;
                if (l43Var2.emit(obj3, g49Var) != ck1Var) {
                }
            } else {
                if (i2 != 3) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                obj = g49Var.e;
                fx4Var = g49Var.d;
                j49Var = (j49) g49Var.c;
                l43Var2 = g49Var.b;
                h49Var = (h49) g49Var.a;
                s38.b(obj4);
                obj2 = e.get(h49Var);
                if (fx4Var != null && !fx4Var.isActive()) {
                    throw fx4Var.w();
                }
                if (obj != null || !obj.equals(obj2)) {
                    obj3 = obj2 != kq6.a ? null : obj2;
                    g49Var.a = h49Var;
                    g49Var.b = l43Var2;
                    g49Var.c = j49Var;
                    g49Var.d = fx4Var;
                    g49Var.e = obj2;
                    g49Var.j = 2;
                    if (l43Var2.emit(obj3, g49Var) != ck1Var) {
                        return ck1Var;
                    }
                    obj = obj2;
                }
                AtomicReference atomicReference2 = j49Var.a;
                kg9 kg9Var2 = i49.a;
                andSet = atomicReference2.getAndSet(kg9Var2);
                cr4.d(andSet);
                if (andSet == i49.b) {
                    g49Var.a = h49Var;
                    g49Var.b = l43Var2;
                    g49Var.c = j49Var;
                    g49Var.d = fx4Var;
                    g49Var.e = obj;
                    g49Var.j = 3;
                    ts0 ts0Var = new ts0(1, dr4.d(g49Var));
                    ts0Var.r();
                    AtomicReference atomicReference3 = j49Var.a;
                    while (true) {
                        if (atomicReference3.compareAndSet(kg9Var2, ts0Var)) {
                            break;
                        }
                        if (atomicReference3.get() != kg9Var2) {
                            ts0Var.resumeWith(e6aVar);
                            break;
                        }
                    }
                    Object objQ = ts0Var.q();
                    ck1 ck1Var2 = ck1.a;
                    if (objQ == ck1Var2) {
                        DebugProbesKt.probeCoroutineSuspended(g49Var);
                    }
                    if (objQ != ck1Var2) {
                    }
                    if (e6aVar != ck1Var) {
                    }
                    return ck1Var;
                }
                obj2 = e.get(h49Var);
                if (fx4Var != null) {
                    throw fx4Var.w();
                }
                if (obj != null) {
                }
                if (obj2 != kq6.a) {
                }
                g49Var.a = h49Var;
                g49Var.b = l43Var2;
                g49Var.c = j49Var;
                g49Var.d = fx4Var;
                g49Var.e = obj2;
                g49Var.j = 2;
                if (l43Var2.emit(obj3, g49Var) != ck1Var) {
                }
            }
            l43Var2 = l43Var3;
            fx4Var = (fx4) g49Var.getE().cb(fx4.b.a);
            obj = null;
            obj2 = e.get(h49Var);
            if (fx4Var != null) {
            }
            if (obj != null) {
            }
            if (obj2 != kq6.a) {
            }
            g49Var.a = h49Var;
            g49Var.b = l43Var2;
            g49Var.c = j49Var;
            g49Var.d = fx4Var;
            g49Var.e = obj2;
            g49Var.j = 2;
            if (l43Var2.emit(obj3, g49Var) != ck1Var) {
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }

    @Override // defpackage.u1
    public final w1 d() {
        return new j49();
    }

    @Override // defpackage.u1
    public final w1[] e() {
        return new j49[2];
    }

    @Override // defpackage.l43
    public final Object emit(Object obj, Continuation continuation) {
        setValue(obj);
        return e6a.a;
    }

    @Override // defpackage.ig6, defpackage.o29
    public final Object getValue() {
        Object obj = e.get(this);
        if (obj == kq6.a) {
            return null;
        }
        return obj;
    }

    @Override // defpackage.ig6
    public final void setValue(Object obj) {
        int i;
        w1[] w1VarArr;
        kg9 kg9Var;
        if (obj == null) {
            obj = kq6.a;
        }
        synchronized (this) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = e;
            if (cr4.b(atomicReferenceFieldUpdater.get(this), obj)) {
                return;
            }
            atomicReferenceFieldUpdater.set(this, obj);
            int i2 = this.d;
            if ((i2 & 1) != 0) {
                this.d = i2 + 2;
                return;
            }
            int i3 = i2 + 1;
            this.d = i3;
            w1[] w1VarArr2 = this.a;
            while (true) {
                j49[] j49VarArr = (j49[]) w1VarArr2;
                if (j49VarArr != null) {
                    for (j49 j49Var : j49VarArr) {
                        if (j49Var != null) {
                            AtomicReference atomicReference = j49Var.a;
                            while (true) {
                                Object obj2 = atomicReference.get();
                                if (obj2 != null && obj2 != (kg9Var = i49.b)) {
                                    kg9 kg9Var2 = i49.a;
                                    if (obj2 != kg9Var2) {
                                        while (!atomicReference.compareAndSet(obj2, kg9Var2)) {
                                            if (atomicReference.get() != obj2) {
                                                break;
                                            }
                                        }
                                        ((ts0) obj2).resumeWith(e6a.a);
                                        break;
                                    }
                                    while (!atomicReference.compareAndSet(obj2, kg9Var)) {
                                        if (atomicReference.get() != obj2) {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                synchronized (this) {
                    i = this.d;
                    if (i == i3) {
                        this.d = i3 + 1;
                        return;
                    }
                    w1VarArr = this.a;
                }
                w1VarArr2 = w1VarArr;
                i3 = i;
            }
        }
    }
}
