package jq;

/* loaded from: classes3.dex */
public final class t {

    /* renamed from: e, reason: collision with root package name */
    private static final a f25272e = new a(null);

    /* renamed from: f, reason: collision with root package name */
    private static final long[] f25273f = new long[0];

    /* renamed from: a, reason: collision with root package name */
    private final hq.e f25274a;

    /* renamed from: b, reason: collision with root package name */
    private final dn.p f25275b;

    /* renamed from: c, reason: collision with root package name */
    private long f25276c;

    /* renamed from: d, reason: collision with root package name */
    private final long[] f25277d;

    /* loaded from: classes3.dex */
    private static final class a {
        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }
    }

    public t(hq.e descriptor, dn.p readIfAbsent) {
        kotlin.jvm.internal.t.g(descriptor, "descriptor");
        kotlin.jvm.internal.t.g(readIfAbsent, "readIfAbsent");
        this.f25274a = descriptor;
        this.f25275b = readIfAbsent;
        int k10 = descriptor.k();
        if (k10 <= 64) {
            this.f25276c = k10 != 64 ? (-1) << k10 : 0L;
            this.f25277d = f25273f;
        } else {
            this.f25276c = 0L;
            this.f25277d = e(k10);
        }
    }

    private final void b(int i10) {
        int i11 = (i10 >>> 6) - 1;
        long[] jArr = this.f25277d;
        jArr[i11] = jArr[i11] | (1 << (i10 & 63));
    }

    private final int c() {
        int length = this.f25277d.length;
        int i10 = 0;
        while (i10 < length) {
            int i11 = i10 + 1;
            int i12 = i11 * 64;
            long j10 = this.f25277d[i10];
            while (j10 != -1) {
                int numberOfTrailingZeros = Long.numberOfTrailingZeros(~j10);
                j10 |= 1 << numberOfTrailingZeros;
                int i13 = numberOfTrailingZeros + i12;
                if (((Boolean) this.f25275b.invoke(this.f25274a, Integer.valueOf(i13))).booleanValue()) {
                    this.f25277d[i10] = j10;
                    return i13;
                }
            }
            this.f25277d[i10] = j10;
            i10 = i11;
        }
        return -1;
    }

    private final long[] e(int i10) {
        int Y;
        long[] jArr = new long[(i10 - 1) >>> 6];
        if ((i10 & 63) != 0) {
            Y = sm.p.Y(jArr);
            jArr[Y] = (-1) << i10;
        }
        return jArr;
    }

    public final void a(int i10) {
        if (i10 < 64) {
            this.f25276c |= 1 << i10;
        } else {
            b(i10);
        }
    }

    public final int d() {
        int numberOfTrailingZeros;
        int k10 = this.f25274a.k();
        do {
            long j10 = this.f25276c;
            if (j10 == -1) {
                if (k10 > 64) {
                    return c();
                }
                return -1;
            }
            numberOfTrailingZeros = Long.numberOfTrailingZeros(~j10);
            this.f25276c |= 1 << numberOfTrailingZeros;
        } while (!((Boolean) this.f25275b.invoke(this.f25274a, Integer.valueOf(numberOfTrailingZeros))).booleanValue());
        return numberOfTrailingZeros;
    }
}
