package androidx.emoji2.text;

import defpackage.l18;
import defpackage.m38;
import defpackage.mm;
import defpackage.nv5;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;

/* JADX INFO: loaded from: classes.dex */
@l18
@m38
@mm
class m {

    public static class a implements d {
        public final ByteBuffer a;

        public a(ByteBuffer byteBuffer) {
            this.a = byteBuffer;
            byteBuffer.order(ByteOrder.BIG_ENDIAN);
        }

        public final void a(int i) {
            ByteBuffer byteBuffer = this.a;
            byteBuffer.position(byteBuffer.position() + i);
        }
    }

    public static class b implements d {
    }

    public static class c {
    }

    public interface d {
    }

    public static nv5 a(MappedByteBuffer mappedByteBuffer) throws IOException {
        ByteBuffer byteBuffer;
        long j;
        ByteBuffer byteBufferDuplicate = mappedByteBuffer.duplicate();
        a aVar = new a(byteBufferDuplicate);
        aVar.a(4);
        int i = byteBufferDuplicate.getShort() & 65535;
        if (i > 100) {
            throw new IOException("Cannot read metadata.");
        }
        aVar.a(6);
        int i2 = 0;
        while (true) {
            byteBuffer = aVar.a;
            if (i2 >= i) {
                j = -1;
                break;
            }
            int i3 = byteBuffer.getInt();
            aVar.a(4);
            j = ((long) byteBuffer.getInt()) & 4294967295L;
            aVar.a(4);
            if (1835365473 == i3) {
                break;
            }
            i2++;
        }
        if (j != -1) {
            aVar.a((int) (j - ((long) byteBuffer.position())));
            aVar.a(12);
            long j2 = ((long) byteBuffer.getInt()) & 4294967295L;
            for (int i4 = 0; i4 < j2; i4++) {
                int i5 = byteBuffer.getInt();
                long j3 = ((long) byteBuffer.getInt()) & 4294967295L;
                byteBuffer.getInt();
                if (1164798569 == i5 || 1701669481 == i5) {
                    byteBufferDuplicate.position((int) (j3 + j));
                    nv5 nv5Var = new nv5();
                    byteBufferDuplicate.order(ByteOrder.LITTLE_ENDIAN);
                    int iPosition = byteBufferDuplicate.position() + byteBufferDuplicate.getInt(byteBufferDuplicate.position());
                    nv5Var.b = byteBufferDuplicate;
                    nv5Var.a = iPosition;
                    int i6 = iPosition - byteBufferDuplicate.getInt(iPosition);
                    nv5Var.c = i6;
                    nv5Var.d = nv5Var.b.getShort(i6);
                    return nv5Var;
                }
            }
        }
        throw new IOException("Cannot read metadata.");
    }
}
