package com.google.protobuf;

import java.nio.ByteBuffer;

/* JADX INFO: loaded from: classes3.dex */
public abstract class f1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final O0 f14272a;

    static {
        f14272a = (c1.f14253e && c1.f14252d && !AbstractC1302e.a()) ? new d1(1) : new d1(0);
    }

    public static int a(byte[] bArr, int i6, int i7) {
        byte b5 = bArr[i6 - 1];
        int i8 = i7 - i6;
        if (i8 == 0) {
            if (b5 > -12) {
                return -1;
            }
            return b5;
        }
        if (i8 == 1) {
            return d(b5, bArr[i6]);
        }
        if (i8 == 2) {
            return e(b5, bArr[i6], bArr[i6 + 1]);
        }
        throw new AssertionError();
    }

    public static String b(ByteBuffer byteBuffer, int i6, int i7) {
        O0 o02 = f14272a;
        o02.getClass();
        if (byteBuffer.hasArray()) {
            return o02.j(byteBuffer.array(), byteBuffer.arrayOffset() + i6, i7);
        }
        return byteBuffer.isDirect() ? o02.l(byteBuffer, i6, i7) : O0.k(byteBuffer, i6, i7);
    }

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

    public static int d(int i6, int i7) {
        if (i6 > -12 || i7 > -65) {
            return -1;
        }
        return i6 ^ (i7 << 8);
    }

    public static int e(int i6, int i7, int i8) {
        if (i6 > -12 || i7 > -65 || i8 > -65) {
            return -1;
        }
        return (i6 ^ (i7 << 8)) ^ (i8 << 16);
    }
}
