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

import java.lang.reflect.Field;
import java.nio.Buffer;
import java.nio.ByteOrder;
import java.security.AccessController;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.Unsafe;

/* JADX INFO: loaded from: classes2.dex */
public abstract class l1 {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Class f23933b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final k1 f23934c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final boolean f23935d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final boolean f23936e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final long f23937f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final boolean f23938g;

    static {
        Unsafe unsafeJ = j();
        f23932a = unsafeJ;
        f23933b = d.f23888a;
        boolean zF = f(Long.TYPE);
        boolean zF2 = f(Integer.TYPE);
        char c6 = 1;
        int i10 = 0;
        k1 j1Var = null;
        if (unsafeJ != null) {
            if (!d.a()) {
                j1Var = new j1(unsafeJ);
            } else if (zF) {
                j1Var = new i1(unsafeJ, c6 == true ? 1 : 0);
            } else if (zF2) {
                j1Var = new i1(unsafeJ, i10);
            }
        }
        f23934c = j1Var;
        f23935d = j1Var == null ? false : j1Var.s();
        f23936e = j1Var == null ? false : j1Var.r();
        f23937f = c(byte[].class);
        c(boolean[].class);
        d(boolean[].class);
        c(int[].class);
        d(int[].class);
        c(long[].class);
        d(long[].class);
        c(float[].class);
        d(float[].class);
        c(double[].class);
        d(double[].class);
        c(Object[].class);
        d(Object[].class);
        Field fieldE = e();
        if (fieldE != null && j1Var != null) {
            j1Var.j(fieldE);
        }
        f23938g = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
    }

    public static void a(Throwable th) {
        Logger.getLogger(l1.class.getName()).log(Level.WARNING, "platform method missing - proto runtime falling back to safer methods: " + th);
    }

    public static Object b(Class cls) {
        try {
            return f23932a.allocateInstance(cls);
        } catch (InstantiationException e10) {
            throw new IllegalStateException(e10);
        }
    }

    public static int c(Class cls) {
        if (f23936e) {
            return f23934c.a(cls);
        }
        return -1;
    }

    public static void d(Class cls) {
        if (f23936e) {
            f23934c.b(cls);
        }
    }

    public static Field e() {
        Field declaredField;
        Field declaredField2;
        if (d.a()) {
            try {
                declaredField2 = Buffer.class.getDeclaredField("effectiveDirectAddress");
            } catch (Throwable unused) {
                declaredField2 = null;
            }
            if (declaredField2 != null) {
                return declaredField2;
            }
        }
        try {
            declaredField = Buffer.class.getDeclaredField("address");
        } catch (Throwable unused2) {
            declaredField = null;
        }
        if (declaredField == null || declaredField.getType() != Long.TYPE) {
            return null;
        }
        return declaredField;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static boolean f(Class cls) {
        if (!d.a()) {
            return false;
        }
        try {
            Class cls2 = f23933b;
            Class cls3 = Boolean.TYPE;
            cls2.getMethod("peekLong", cls, cls3);
            cls2.getMethod("pokeLong", cls, Long.TYPE, cls3);
            Class cls4 = Integer.TYPE;
            cls2.getMethod("pokeInt", cls, cls4, cls3);
            cls2.getMethod("peekInt", cls, cls3);
            cls2.getMethod("pokeByte", cls, Byte.TYPE);
            cls2.getMethod("peekByte", cls);
            cls2.getMethod("pokeByteArray", cls, byte[].class, cls4, cls4);
            cls2.getMethod("peekByteArray", cls, byte[].class, cls4, cls4);
            return true;
        } catch (Throwable unused) {
            return false;
        }
    }

    public static byte g(long j10, byte[] bArr) {
        return f23934c.d(f23937f + j10, bArr);
    }

    public static byte h(long j10, Object obj) {
        return (byte) ((f23934c.g((-4) & j10, obj) >>> ((int) (((~j10) & 3) << 3))) & 255);
    }

    public static byte i(long j10, Object obj) {
        return (byte) ((f23934c.g((-4) & j10, obj) >>> ((int) ((j10 & 3) << 3))) & 255);
    }

    public static Unsafe j() {
        try {
            return (Unsafe) AccessController.doPrivileged(new h1());
        } catch (Throwable unused) {
            return null;
        }
    }

    public static void k(Object obj, long j10, boolean z10) {
        f23934c.k(obj, j10, z10);
    }

    public static void l(byte[] bArr, long j10, byte b10) {
        f23934c.l(bArr, f23937f + j10, b10);
    }

    public static void m(Object obj, long j10, byte b10) {
        long j11 = (-4) & j10;
        int iG = f23934c.g(j11, obj);
        int i10 = ((~((int) j10)) & 3) << 3;
        q(((255 & b10) << i10) | (iG & (~(255 << i10))), j11, obj);
    }

    public static void n(Object obj, long j10, byte b10) {
        long j11 = (-4) & j10;
        int i10 = (((int) j10) & 3) << 3;
        q(((255 & b10) << i10) | (f23934c.g(j11, obj) & (~(255 << i10))), j11, obj);
    }

    public static void o(Object obj, long j10, double d10) {
        f23934c.m(obj, j10, d10);
    }

    public static void p(Object obj, long j10, float f10) {
        f23934c.n(obj, j10, f10);
    }

    public static void q(int i10, long j10, Object obj) {
        f23934c.o(i10, j10, obj);
    }

    public static void r(Object obj, long j10, long j11) {
        f23934c.p(obj, j10, j11);
    }

    public static void s(Object obj, long j10, Object obj2) {
        f23934c.q(obj, j10, obj2);
    }
}
