package com.google.crypto.tink.shaded.protobuf;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final android.support.v4.media.session.a f10539a;

    static {
        f10539a = (n0.f10528e && n0.f10527d && !AbstractC0737c.a()) ? new o0(1) : new o0(0);
    }

    public static int a(byte[] bArr, int i, int i5) {
        byte b8 = bArr[i - 1];
        int i8 = i5 - i;
        if (i8 == 0) {
            if (b8 > -12) {
                return -1;
            }
            return b8;
        }
        if (i8 == 1) {
            return c(b8, bArr[i]);
        }
        if (i8 == 2) {
            return d(b8, bArr[i], bArr[i + 1]);
        }
        throw new AssertionError();
    }

    public static int b(String str) {
        int length = str.length();
        int i = 0;
        int i5 = 0;
        while (i5 < length && str.charAt(i5) < 128) {
            i5++;
        }
        int i8 = length;
        while (true) {
            if (i5 >= length) {
                break;
            }
            char cCharAt = str.charAt(i5);
            if (cCharAt < 2048) {
                i8 += (127 - cCharAt) >>> 31;
                i5++;
            } else {
                int length2 = str.length();
                while (i5 < length2) {
                    char cCharAt2 = str.charAt(i5);
                    if (cCharAt2 < 2048) {
                        i += (127 - cCharAt2) >>> 31;
                    } else {
                        i += 2;
                        if (55296 <= cCharAt2 && cCharAt2 <= 57343) {
                            if (Character.codePointAt(str, i5) < 65536) {
                                throw new p0(i5, length2);
                            }
                            i5++;
                        }
                    }
                    i5++;
                }
                i8 += i;
            }
        }
        if (i8 >= length) {
            return i8;
        }
        throw new IllegalArgumentException("UTF-8 length does not fit in int: " + (((long) i8) + 4294967296L));
    }

    public static int c(int i, int i5) {
        if (i > -12 || i5 > -65) {
            return -1;
        }
        return i ^ (i5 << 8);
    }

    public static int d(int i, int i5, int i8) {
        if (i > -12 || i5 > -65 || i8 > -65) {
            return -1;
        }
        return (i ^ (i5 << 8)) ^ (i8 << 16);
    }
}
