package kotlinx.coroutines.internal;

import F1.F0;
import q1.g;

/* JADX INFO: loaded from: classes.dex */
public abstract class v {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final r f5176a = new r("NO_THREAD_ELEMENTS");

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final y1.p f5177b = a.f5180b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final y1.p f5178c = b.f5181b;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final y1.p f5179d = c.f5182b;

    static final class a extends kotlin.jvm.internal.m implements y1.p {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static final a f5180b = new a();

        a() {
            super(2);
        }

        @Override // y1.p
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Object invoke(Object obj, g.b bVar) {
            if (!(bVar instanceof F0)) {
                return obj;
            }
            Integer num = obj instanceof Integer ? (Integer) obj : null;
            int iIntValue = num == null ? 1 : num.intValue();
            return iIntValue == 0 ? bVar : Integer.valueOf(iIntValue + 1);
        }
    }

    static final class b extends kotlin.jvm.internal.m implements y1.p {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static final b f5181b = new b();

        b() {
            super(2);
        }

        @Override // y1.p
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public final F0 invoke(F0 f02, g.b bVar) {
            if (f02 != null) {
                return f02;
            }
            if (bVar instanceof F0) {
                return (F0) bVar;
            }
            return null;
        }
    }

    static final class c extends kotlin.jvm.internal.m implements y1.p {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static final c f5182b = new c();

        c() {
            super(2);
        }

        @Override // y1.p
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public final y invoke(y yVar, g.b bVar) {
            if (bVar instanceof F0) {
                F0 f02 = (F0) bVar;
                yVar.a(f02, f02.a(yVar.f5184a));
            }
            return yVar;
        }
    }

    public static final void a(q1.g gVar, Object obj) {
        if (obj == f5176a) {
            return;
        }
        if (obj instanceof y) {
            ((y) obj).b(gVar);
            return;
        }
        Object objFold = gVar.fold(null, f5178c);
        if (objFold == null) {
            throw new NullPointerException("null cannot be cast to non-null type kotlinx.coroutines.ThreadContextElement<kotlin.Any?>");
        }
        ((F0) objFold).f(gVar, obj);
    }

    public static final Object b(q1.g gVar) {
        Object objFold = gVar.fold(0, f5177b);
        kotlin.jvm.internal.l.b(objFold);
        return objFold;
    }

    public static final Object c(q1.g gVar, Object obj) {
        if (obj == null) {
            obj = b(gVar);
        }
        return obj == 0 ? f5176a : obj instanceof Integer ? gVar.fold(new y(gVar, ((Number) obj).intValue()), f5179d) : ((F0) obj).a(gVar);
    }
}
