package i7;

import A6.n;
import Z6.AbstractC0385z;
import Z6.C0369i;
import Z6.F;
import com.google.android.gms.internal.measurement.C1;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: loaded from: classes.dex */
public final class d extends i implements a {

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f13582x = AtomicReferenceFieldUpdater.newUpdater(d.class, Object.class, "owner$volatile");
    private volatile /* synthetic */ Object owner$volatile;

    public d(boolean z8) {
        super(1, z8 ? 1 : 0);
        this.owner$volatile = z8 ? null : e.f13583a;
    }

    @Override // i7.a
    public final void a(Object obj) {
        while (f()) {
            AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = f13582x;
            Object obj2 = atomicReferenceFieldUpdater.get(this);
            B3.f fVar = e.f13583a;
            if (obj2 != fVar) {
                if (obj2 == obj || obj == null) {
                    while (!atomicReferenceFieldUpdater.compareAndSet(this, obj2, fVar)) {
                        if (atomicReferenceFieldUpdater.get(this) != obj2) {
                            break;
                        }
                    }
                    e();
                    return;
                }
                throw new IllegalStateException(("This mutex is locked by " + obj2 + ", but " + obj + " is expected").toString());
            }
        }
        throw new IllegalStateException("This mutex is not locked");
    }

    /* JADX WARN: Code restructure failed: missing block: B:10:0x0022, code lost:
    
        r2 = i7.d.f13582x;
        r3 = r0.f13581r;
        r2.set(r3, null);
        r2 = new a7.c(r3, 5, r0);
        r0 = r0.f13580q;
        r0.D(r1, r0.f7472s, new Z6.C0368h(0, r2));
     */
    @Override // i7.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object b(G6.c cVar) throws IllegalAccessException, F, InvocationTargetException {
        boolean zG = g();
        n nVar = n.f457a;
        if (!zG) {
            C0369i c0369iO = AbstractC0385z.o(C1.A(cVar));
            try {
                c cVar2 = new c(this, c0369iO);
                while (true) {
                    int andDecrement = i.f13590w.getAndDecrement(this);
                    if (andDecrement <= this.f13591q) {
                        if (andDecrement > 0) {
                            break;
                        }
                        if (d(cVar2)) {
                            break;
                        }
                    }
                }
                Object objU = c0369iO.u();
                F6.a aVar = F6.a.f2580q;
                if (objU != aVar) {
                    objU = nVar;
                }
                if (objU == aVar) {
                    return objU;
                }
            } catch (Throwable th) {
                c0369iO.C();
                throw th;
            }
        }
        return nVar;
    }

    public final boolean f() {
        return Math.max(i.f13590w.get(this), 0) == 0;
    }

    public final boolean g() {
        int i;
        char c3;
        while (true) {
            AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = i.f13590w;
            int i5 = atomicIntegerFieldUpdater.get(this);
            int i8 = this.f13591q;
            if (i5 > i8) {
                do {
                    i = atomicIntegerFieldUpdater.get(this);
                    if (i > i8) {
                    }
                } while (!atomicIntegerFieldUpdater.compareAndSet(this, i, i8));
            } else {
                if (i5 <= 0) {
                    c3 = 1;
                    break;
                }
                if (atomicIntegerFieldUpdater.compareAndSet(this, i5, i5 - 1)) {
                    f13582x.set(this, null);
                    c3 = 0;
                    break;
                }
            }
        }
        if (c3 == 0) {
            return true;
        }
        if (c3 == 1) {
            return false;
        }
        if (c3 != 2) {
            throw new IllegalStateException("unexpected");
        }
        throw new IllegalStateException("This mutex is already locked by the specified owner: null".toString());
    }

    public final String toString() {
        return "Mutex@" + AbstractC0385z.m(this) + "[isLocked=" + f() + ",owner=" + f13582x.get(this) + ']';
    }
}
