package kotlin.coroutines;

import kotlin.jvm.functions.Function2;

/* JADX INFO: loaded from: classes.dex */
public abstract class e {
    public static h a(h hVar, h hVar2) {
        nb.g.i(hVar2, "context");
        return hVar2 == EmptyCoroutineContext.f29221a ? hVar : (h) hVar2.E(hVar, new Function2() { // from class: kotlin.coroutines.CoroutineContext$plus$1
            @Override // kotlin.jvm.functions.Function2
            public final Object invoke(Object obj, Object obj2) {
                CombinedContext combinedContext;
                h hVar3 = (h) obj;
                f fVar = (f) obj2;
                nb.g.i(hVar3, "acc");
                nb.g.i(fVar, "element");
                h hVarX = hVar3.x(fVar.getKey());
                EmptyCoroutineContext emptyCoroutineContext = EmptyCoroutineContext.f29221a;
                if (hVarX == emptyCoroutineContext) {
                    return fVar;
                }
                c cVar = c.f29225a;
                d dVar = (d) hVarX.m(cVar);
                if (dVar == null) {
                    combinedContext = new CombinedContext(fVar, hVarX);
                } else {
                    h hVarX2 = hVarX.x(cVar);
                    if (hVarX2 == emptyCoroutineContext) {
                        return new CombinedContext(dVar, fVar);
                    }
                    combinedContext = new CombinedContext(dVar, new CombinedContext(fVar, hVarX2));
                }
                return combinedContext;
            }
        });
    }
}
