package androidx.emoji2.text;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/* JADX INFO: compiled from: MetadataListReader.java */
/* JADX INFO: loaded from: classes.dex */
class l {

    /* JADX INFO: compiled from: MetadataListReader.java */
    private static class a implements c {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final ByteBuffer f2120a;

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

        @Override // androidx.emoji2.text.l.c
        public long a() throws IOException {
            return l.c(this.f2120a.getInt());
        }

        @Override // androidx.emoji2.text.l.c
        public void b(int i3) throws IOException {
            ByteBuffer byteBuffer = this.f2120a;
            byteBuffer.position(byteBuffer.position() + i3);
        }

        @Override // androidx.emoji2.text.l.c
        public int c() throws IOException {
            return l.d(this.f2120a.getShort());
        }

        @Override // androidx.emoji2.text.l.c
        public int d() throws IOException {
            return this.f2120a.getInt();
        }

        @Override // androidx.emoji2.text.l.c
        public long e() {
            return this.f2120a.position();
        }
    }

    /* JADX INFO: compiled from: MetadataListReader.java */
    private static class b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final long f2121a;

        b(long j3, long j4) {
            this.f2121a = j3;
        }

        long a() {
            return this.f2121a;
        }
    }

    /* JADX INFO: compiled from: MetadataListReader.java */
    private interface c {
        long a() throws IOException;

        void b(int i3) throws IOException;

        int c() throws IOException;

        int d() throws IOException;

        long e();
    }

    private static b a(c cVar) throws IOException {
        long jA;
        cVar.b(4);
        int iC = cVar.c();
        if (iC > 100) {
            throw new IOException("Cannot read metadata.");
        }
        cVar.b(6);
        int i3 = 0;
        while (true) {
            if (i3 >= iC) {
                jA = -1;
                break;
            }
            int iD = cVar.d();
            cVar.b(4);
            jA = cVar.a();
            cVar.b(4);
            if (1835365473 == iD) {
                break;
            }
            i3++;
        }
        if (jA != -1) {
            cVar.b((int) (jA - cVar.e()));
            cVar.b(12);
            long jA2 = cVar.a();
            for (int i4 = 0; i4 < jA2; i4++) {
                int iD2 = cVar.d();
                long jA3 = cVar.a();
                long jA4 = cVar.a();
                if (1164798569 == iD2 || 1701669481 == iD2) {
                    return new b(jA3 + jA, jA4);
                }
            }
        }
        throw new IOException("Cannot read metadata.");
    }

    static y.b b(ByteBuffer byteBuffer) throws IOException {
        ByteBuffer byteBufferDuplicate = byteBuffer.duplicate();
        byteBufferDuplicate.position((int) a(new a(byteBufferDuplicate)).a());
        return y.b.h(byteBufferDuplicate);
    }

    static long c(int i3) {
        return ((long) i3) & 4294967295L;
    }

    static int d(short s2) {
        return s2 & 65535;
    }
}
