package zp;

/* loaded from: classes3.dex */
public abstract class d {

    /* renamed from: a */
    private static final h0 f53539a = new h0("CLOSED");

    public static final e b(e eVar) {
        while (true) {
            Object f10 = eVar.f();
            if (f10 == f53539a) {
                return eVar;
            }
            e eVar2 = (e) f10;
            if (eVar2 != null) {
                eVar = eVar2;
            } else if (eVar.j()) {
                return eVar;
            }
        }
    }

    public static final Object c(e0 e0Var, long j10, dn.p pVar) {
        while (true) {
            if (e0Var.f53544r >= j10 && !e0Var.h()) {
                return f0.a(e0Var);
            }
            Object f10 = e0Var.f();
            if (f10 == f53539a) {
                return f0.a(f53539a);
            }
            e0 e0Var2 = (e0) ((e) f10);
            if (e0Var2 == null) {
                e0Var2 = (e0) pVar.invoke(Long.valueOf(e0Var.f53544r + 1), e0Var);
                if (e0Var.l(e0Var2)) {
                    if (e0Var.h()) {
                        e0Var.k();
                    }
                }
            }
            e0Var = e0Var2;
        }
    }
}
