// File: /workspace/github_c_makefile_star2_O0/kyz[P]amostools/dumpamos.c
// Function: bank_length
uint32_t bank_length(uint8_t *src, size_t len) {
    if (len >= 6 && (amos_leek(src) == ID_AmSp || amos_leek(src) == ID_AmIc)) {
        int num_sprites = amos_deek(&src[4]);
        uint32_t pos = 6, w, h, d;
        while (num_sprites--) {
            if (pos + 10 > len) return 0;
             w = amos_deek(&src[pos+0]) * 2;
             h = amos_deek(&src[pos+2]);
             d = amos_deek(&src[pos+4]);
            pos += 10 +  w * h * d;
        }
        pos += 64; /* include palette */
        return pos > len ? 0 : pos;
    }
    else if (len >= 20 && amos_leek(src) == ID_AmBk) {
        uint32_t bank_len = (amos_leek(&src[8]) & 0x0FFFFFFF) + 20 - 8;
        return bank_len > len ? 0 : bank_len;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x6, -0x18(%rbp)
jb 0x1792
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
shll $0x18, %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
orl %ecx, %eax
cmpl $0x416d5370, %eax       # imm = 0x416D5370
je 0x1685
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
shll $0x18, %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
orl %ecx, %eax
cmpl $0x416d4963, %eax       # imm = 0x416D4963
jne 0x1792
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
shll $0x8, %eax
movq -0x10(%rbp), %rcx
movzbl 0x5(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl $0x6, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x1768
movl -0x20(%rbp), %eax
addl $0xa, %eax
movl %eax, %eax
cmpq -0x18(%rbp), %rax
jbe 0x16d2
movl $0x0, -0x4(%rbp)
jmp 0x1836
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x10(%rbp), %rcx
movl -0x20(%rbp), %edx
addl $0x0, %edx
movl %edx, %edx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
shll %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x10(%rbp), %rcx
movl -0x20(%rbp), %edx
addl $0x2, %edx
movl %edx, %edx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x4, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x10(%rbp), %rcx
movl -0x20(%rbp), %edx
addl $0x4, %edx
movl %edx, %edx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
imull -0x28(%rbp), %eax
imull -0x2c(%rbp), %eax
addl $0xa, %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x16a4
movl -0x20(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpq -0x18(%rbp), %rax
jbe 0x1781
xorl %eax, %eax
movl %eax, -0x34(%rbp)
jmp 0x1787
movl -0x20(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1836
cmpq $0x14, -0x18(%rbp)
jb 0x182d
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
shll $0x18, %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
orl %ecx, %eax
cmpl $0x416d426b, %eax       # imm = 0x416D426B
jne 0x182d
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
shll $0x18, %eax
movq -0x10(%rbp), %rcx
movzbl 0x9(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0xa(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0xb(%rcx), %ecx
orl %ecx, %eax
andl $0xfffffff, %eax        # imm = 0xFFFFFFF
addl $0x14, %eax
subl $0x8, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpq -0x18(%rbp), %rax
jbe 0x181f
xorl %eax, %eax
movl %eax, -0x38(%rbp)
jmp 0x1825
movl -0x30(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1836
jmp 0x182f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)