package kotlinx.coroutines.flow;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
import kotlinx.coroutines.channels.BufferOverflow;
import kotlinx.coroutines.g1;
import kotlinx.coroutines.y0;

/* JADX INFO: loaded from: classes.dex */
public final class v extends kotlinx.coroutines.flow.internal.a implements p, f, kotlinx.coroutines.flow.internal.h {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f29428e = AtomicReferenceFieldUpdater.newUpdater(v.class, Object.class, "_state$volatile");
    private volatile /* synthetic */ Object _state$volatile;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f29429d;

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

    /* JADX WARN: Code restructure failed: missing block: B:67:0x0098, code lost:
    
        if (r5 != r4) goto L29;
     */
    /* JADX WARN: Removed duplicated region for block: B:31:0x00a0 A[Catch: all -> 0x0046, TryCatch #0 {all -> 0x0046, blocks: (B:14:0x0041, B:29:0x0098, B:31:0x00a0, B:34:0x00a7, B:35:0x00ad, B:37:0x00b0, B:48:0x00d7, B:51:0x00ea, B:52:0x0102, B:58:0x0116, B:55:0x010d, B:57:0x0113, B:39:0x00b6, B:43:0x00bd, B:21:0x0063, B:24:0x0077, B:27:0x0088), top: B:65:0x0027 }] */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00b0 A[Catch: all -> 0x0046, TryCatch #0 {all -> 0x0046, blocks: (B:14:0x0041, B:29:0x0098, B:31:0x00a0, B:34:0x00a7, B:35:0x00ad, B:37:0x00b0, B:48:0x00d7, B:51:0x00ea, B:52:0x0102, B:58:0x0116, B:55:0x010d, B:57:0x0113, B:39:0x00b6, B:43:0x00bd, B:21:0x0063, B:24:0x0077, B:27:0x0088), top: B:65:0x0027 }] */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00ba  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00bc  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00cf A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:46:0x00d0  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00e9  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00ea A[Catch: all -> 0x0046, TryCatch #0 {all -> 0x0046, blocks: (B:14:0x0041, B:29:0x0098, B:31:0x00a0, B:34:0x00a7, B:35:0x00ad, B:37:0x00b0, B:48:0x00d7, B:51:0x00ea, B:52:0x0102, B:58:0x0116, B:55:0x010d, B:57:0x0113, B:39:0x00b6, B:43:0x00bd, B:21:0x0063, B:24:0x0077, B:27:0x0088), top: B:65:0x0027 }] */
    /* JADX WARN: Removed duplicated region for block: B:62:0x011f A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:50:0x00e9 -> B:29:0x0098). Please report as a decompilation issue!!! */
    @Override // kotlinx.coroutines.flow.f
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object a(g gVar, Continuation continuation) {
        StateFlowImpl$collect$1 stateFlowImpl$collect$1;
        v vVar;
        g gVar2;
        w wVar;
        v vVar2;
        y0 y0Var;
        g gVar3;
        Object obj;
        Object obj2;
        CoroutineSingletons coroutineSingletons;
        CoroutineSingletons coroutineSingletons2;
        Object andSet;
        Object obj3;
        Object obj4;
        if (continuation instanceof StateFlowImpl$collect$1) {
            stateFlowImpl$collect$1 = (StateFlowImpl$collect$1) continuation;
            int i10 = stateFlowImpl$collect$1.label;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                stateFlowImpl$collect$1.label = i10 - Integer.MIN_VALUE;
                vVar = this;
            } else {
                vVar = this;
                stateFlowImpl$collect$1 = new StateFlowImpl$collect$1(vVar, continuation);
            }
        }
        Object obj5 = stateFlowImpl$collect$1.result;
        CoroutineSingletons coroutineSingletons3 = CoroutineSingletons.f29226a;
        int i11 = stateFlowImpl$collect$1.label;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj5);
                gVar2 = gVar;
                wVar = (w) d();
                vVar2 = vVar;
            } else if (i11 == 1) {
                wVar = (w) stateFlowImpl$collect$1.L$2;
                gVar2 = (g) stateFlowImpl$collect$1.L$1;
                vVar2 = (v) stateFlowImpl$collect$1.L$0;
                kotlin.a.d(obj5);
            } else if (i11 == 2) {
                obj2 = stateFlowImpl$collect$1.L$4;
                y0Var = (y0) stateFlowImpl$collect$1.L$3;
                wVar = (w) stateFlowImpl$collect$1.L$2;
                gVar3 = (g) stateFlowImpl$collect$1.L$1;
                vVar2 = (v) stateFlowImpl$collect$1.L$0;
                kotlin.a.d(obj5);
                coroutineSingletons = coroutineSingletons3;
                Object obj6 = obj2;
                coroutineSingletons2 = coroutineSingletons;
                obj = obj6;
                wVar.getClass();
                la.e eVar = h.f29374d;
                andSet = w.f29430a.getAndSet(wVar, eVar);
                nb.g.f(andSet);
                if (andSet == h.f29375e) {
                }
                obj3 = f29428e.get(vVar2);
                if (y0Var != null) {
                }
                if (obj != null) {
                }
                if (obj3 != kotlinx.coroutines.flow.internal.b.f29385b) {
                }
                stateFlowImpl$collect$1.L$0 = vVar2;
                stateFlowImpl$collect$1.L$1 = gVar3;
                stateFlowImpl$collect$1.L$2 = wVar;
                stateFlowImpl$collect$1.L$3 = y0Var;
                stateFlowImpl$collect$1.L$4 = obj3;
                stateFlowImpl$collect$1.label = 2;
                if (gVar3.c(obj4, stateFlowImpl$collect$1) != coroutineSingletons2) {
                }
            } else {
                if (i11 != 3) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                Object obj7 = stateFlowImpl$collect$1.L$4;
                y0Var = (y0) stateFlowImpl$collect$1.L$3;
                wVar = (w) stateFlowImpl$collect$1.L$2;
                gVar3 = (g) stateFlowImpl$collect$1.L$1;
                vVar2 = (v) stateFlowImpl$collect$1.L$0;
                kotlin.a.d(obj5);
                obj = obj7;
                coroutineSingletons2 = coroutineSingletons3;
                obj3 = f29428e.get(vVar2);
                if (y0Var != null && !y0Var.isActive()) {
                    throw ((g1) y0Var).z();
                }
                if (obj != null || !nb.g.c(obj, obj3)) {
                    obj4 = obj3 != kotlinx.coroutines.flow.internal.b.f29385b ? null : obj3;
                    stateFlowImpl$collect$1.L$0 = vVar2;
                    stateFlowImpl$collect$1.L$1 = gVar3;
                    stateFlowImpl$collect$1.L$2 = wVar;
                    stateFlowImpl$collect$1.L$3 = y0Var;
                    stateFlowImpl$collect$1.L$4 = obj3;
                    stateFlowImpl$collect$1.label = 2;
                    if (gVar3.c(obj4, stateFlowImpl$collect$1) != coroutineSingletons2) {
                        return coroutineSingletons2;
                    }
                    coroutineSingletons = coroutineSingletons2;
                    obj2 = obj3;
                    Object obj62 = obj2;
                    coroutineSingletons2 = coroutineSingletons;
                    obj = obj62;
                }
                wVar.getClass();
                la.e eVar2 = h.f29374d;
                andSet = w.f29430a.getAndSet(wVar, eVar2);
                nb.g.f(andSet);
                if (andSet == h.f29375e) {
                    stateFlowImpl$collect$1.L$0 = vVar2;
                    stateFlowImpl$collect$1.L$1 = gVar3;
                    stateFlowImpl$collect$1.L$2 = wVar;
                    stateFlowImpl$collect$1.L$3 = y0Var;
                    stateFlowImpl$collect$1.L$4 = obj;
                    stateFlowImpl$collect$1.label = 3;
                    kotlinx.coroutines.h hVar = new kotlinx.coroutines.h(1, nb.g.F(stateFlowImpl$collect$1));
                    hVar.t();
                    while (true) {
                        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = w.f29430a;
                        boolean zCompareAndSet = atomicReferenceFieldUpdater.compareAndSet(wVar, eVar2, hVar);
                        kd.e eVar3 = kd.e.f29109a;
                        if (zCompareAndSet) {
                            break;
                        }
                        if (atomicReferenceFieldUpdater.get(wVar) != eVar2) {
                            hVar.resumeWith(eVar3);
                            break;
                        }
                    }
                    Object objS = hVar.s();
                    if (objS == coroutineSingletons3) {
                        if (objS == coroutineSingletons2) {
                            return coroutineSingletons2;
                        }
                    } else if (objS == coroutineSingletons2) {
                    }
                }
                obj3 = f29428e.get(vVar2);
                if (y0Var != null) {
                    throw ((g1) y0Var).z();
                }
                if (obj != null) {
                }
                if (obj3 != kotlinx.coroutines.flow.internal.b.f29385b) {
                }
                stateFlowImpl$collect$1.L$0 = vVar2;
                stateFlowImpl$collect$1.L$1 = gVar3;
                stateFlowImpl$collect$1.L$2 = wVar;
                stateFlowImpl$collect$1.L$3 = y0Var;
                stateFlowImpl$collect$1.L$4 = obj3;
                stateFlowImpl$collect$1.label = 2;
                if (gVar3.c(obj4, stateFlowImpl$collect$1) != coroutineSingletons2) {
                }
            }
            y0Var = (y0) stateFlowImpl$collect$1.getContext().m(kotlinx.coroutines.u.f29565b);
            gVar3 = gVar2;
            obj = null;
            coroutineSingletons2 = coroutineSingletons3;
            obj3 = f29428e.get(vVar2);
            if (y0Var != null) {
            }
            if (obj != null) {
            }
            if (obj3 != kotlinx.coroutines.flow.internal.b.f29385b) {
            }
            stateFlowImpl$collect$1.L$0 = vVar2;
            stateFlowImpl$collect$1.L$1 = gVar3;
            stateFlowImpl$collect$1.L$2 = wVar;
            stateFlowImpl$collect$1.L$3 = y0Var;
            stateFlowImpl$collect$1.L$4 = obj3;
            stateFlowImpl$collect$1.label = 2;
            if (gVar3.c(obj4, stateFlowImpl$collect$1) != coroutineSingletons2) {
            }
        } catch (Throwable th) {
            vVar2.g(wVar);
            throw th;
        }
    }

    @Override // kotlinx.coroutines.flow.internal.h
    public final f b(kotlin.coroutines.h hVar, int i10, BufferOverflow bufferOverflow) {
        return ((((i10 < 0 || i10 >= 2) && i10 != -2) || bufferOverflow != BufferOverflow.f29298b) && !((i10 == 0 || i10 == -3) && bufferOverflow == BufferOverflow.f29297a)) ? new kotlinx.coroutines.flow.internal.f(this, hVar, i10, bufferOverflow) : this;
    }

    @Override // kotlinx.coroutines.flow.g
    public final Object c(Object obj, Continuation continuation) {
        if (obj == null) {
            obj = kotlinx.coroutines.flow.internal.b.f29385b;
        }
        h(null, obj);
        return kd.e.f29109a;
    }

    @Override // kotlinx.coroutines.flow.internal.a
    public final kotlinx.coroutines.flow.internal.c e() {
        return new w();
    }

    @Override // kotlinx.coroutines.flow.internal.a
    public final kotlinx.coroutines.flow.internal.c[] f() {
        return new w[2];
    }

    public final boolean h(Object obj, Object obj2) {
        int i10;
        kotlinx.coroutines.flow.internal.c[] cVarArr;
        la.e eVar;
        synchronized (this) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f29428e;
            Object obj3 = atomicReferenceFieldUpdater.get(this);
            if (obj != null && !nb.g.c(obj3, obj)) {
                return false;
            }
            if (nb.g.c(obj3, obj2)) {
                return true;
            }
            atomicReferenceFieldUpdater.set(this, obj2);
            int i11 = this.f29429d;
            if ((i11 & 1) != 0) {
                this.f29429d = i11 + 2;
                return true;
            }
            int i12 = i11 + 1;
            this.f29429d = i12;
            kotlinx.coroutines.flow.internal.c[] cVarArr2 = this.f29381a;
            while (true) {
                w[] wVarArr = (w[]) cVarArr2;
                if (wVarArr != null) {
                    for (w wVar : wVarArr) {
                        if (wVar != null) {
                            while (true) {
                                AtomicReferenceFieldUpdater atomicReferenceFieldUpdater2 = w.f29430a;
                                Object obj4 = atomicReferenceFieldUpdater2.get(wVar);
                                if (obj4 != null && obj4 != (eVar = h.f29375e)) {
                                    la.e eVar2 = h.f29374d;
                                    if (obj4 != eVar2) {
                                        while (!atomicReferenceFieldUpdater2.compareAndSet(wVar, obj4, eVar2)) {
                                            if (atomicReferenceFieldUpdater2.get(wVar) != obj4) {
                                                break;
                                            }
                                        }
                                        ((kotlinx.coroutines.h) obj4).resumeWith(kd.e.f29109a);
                                        break;
                                    }
                                    while (!atomicReferenceFieldUpdater2.compareAndSet(wVar, obj4, eVar)) {
                                        if (atomicReferenceFieldUpdater2.get(wVar) != obj4) {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                synchronized (this) {
                    i10 = this.f29429d;
                    if (i10 == i12) {
                        this.f29429d = i12 + 1;
                        return true;
                    }
                    cVarArr = this.f29381a;
                }
                cVarArr2 = cVarArr;
                i12 = i10;
            }
        }
    }
}
