// File: /workspace/github_c_makefile_star2_O1/kyz[P]amostools/./amoslib.c
// Function: AMOS_parse_config
int AMOS_parse_config(uint8_t *src, size_t len,
                      char *slots[AMOS_EXTENSION_SLOTS])
{
    /* AMOSPro_Interpreter_Config format: PId1 / PIdt */
    if (len > 100 && (amos_leek(src) == 0x50496431 ||
                      amos_leek(src) == 0x50496474))
    {
        /* items section: PIt1 / PItx */
        uint32_t idlen = amos_leek(&src[4]);
        if (idlen < (len - 92) && (amos_leek(&src[idlen + 8]) == 0x50497431 ||
                                   amos_leek(&src[idlen + 8]) == 0x50497478))
        {
            uint8_t *p = &src[idlen + 16];
            int i;
            /* config strings 16-41 are extensions 1-25 */
            for (i = 1; i < (16+AMOS_EXTENSION_SLOTS); i++) {
                if (i >= 16) slots[i - 16] = (char *) &p[2];
                p += p[1] + 2;
                if ((p - src) > (int) len) return 1;
            }
            return 0; /* success */
        }
    }

    /* AMOS1_3_Pal.env, etc. format: Amiga code hunk */
    if (len > 300 && amos_leek(src) == 0x3f3 && amos_leek(&src[24]) == 0x3e9) {
        uint32_t dta = amos_leek(&src[32]);
        /* look up config entry 66 */
        uint32_t offset = amos_deek(&src[36 + 65 * 4]) + 36 - dta;
        uint32_t flags  = amos_deek(&src[36 + 65 * 4 + 2]);
        /* entry must be list of strings */
        if (flags & 0x8000 && offset < len) {
            uint8_t *s = &src[offset], *end = &src[len];
            int i;
            for (i = 0; i < AMOS_EXTENSION_SLOTS; i++) {
                if (s >= end) return 1;
                if (*s == 0xFF) break; /* end of list */
                slots[i] = (char *) s;
                while (*s++ && s < end); /* skip string */
            }
            for (; i < AMOS_EXTENSION_SLOTS; i++) {
                slots[i] = NULL;
            }
            return 0; /* success */
        }
    }
    return 1; /* failure */
}

// Assembly:
pushq %rbx
cmpq $0x65, %rsi
jb 0x1e28
movl (%rdi), %ecx
bswapl %ecx
cmpl $0x50496474, %ecx       # imm = 0x50496474
je 0x1da7
cmpl $0x50496431, %ecx       # imm = 0x50496431
jne 0x1e28
movl 0x4(%rdi), %ecx
bswapl %ecx
leaq -0x5c(%rsi), %rax
movb $0x1, %r8b
cmpq %rcx, %rax
jbe 0x1e15
leal 0x8(%rcx), %eax
movl (%rdi,%rax), %r9d
bswapl %r9d
cmpl $0x50497478, %r9d       # imm = 0x50497478
je 0x1dd4
cmpl $0x50497431, %r9d       # imm = 0x50497431
jne 0x1e1f
addl $0x10, %ecx
addq %rdi, %rcx
movslq %esi, %r8
movl $0x1, %r9d
cmpq $0x10, %r9
jb 0x1df2
leaq 0x2(%rcx), %rax
movq %rax, -0x80(%rdx,%r9,8)
movzbl 0x1(%rcx), %eax
addq %rax, %rcx
addq $0x2, %rcx
movq %rcx, %r10
subq %rdi, %r10
xorl %eax, %eax
cmpq %r8, %r10
jg 0x1e17
incq %r9
cmpq $0x29, %r9
jne 0x1de3
jmp 0x1e1c
jmp 0x1e1f
movl $0x1, %eax
xorl %r8d, %r8d
testb %r8b, %r8b
je 0x1ef7
cmpq $0x12d, %rsi            # imm = 0x12D
jb 0x1ef2
movl (%rdi), %ecx
bswapl %ecx
cmpl $0x3f3, %ecx            # imm = 0x3F3
jne 0x1ef2
movl 0x18(%rdi), %ecx
bswapl %ecx
cmpl $0x3e9, %ecx            # imm = 0x3E9
jne 0x1ef2
movb $0x1, %bl
cmpb $0x0, 0x12a(%rdi)
jns 0x1eee
movzwl 0x128(%rdi), %ecx
rolw $0x8, %cx
movzwl %cx, %r8d
movl 0x20(%rdi), %ecx
bswapl %ecx
subl %ecx, %r8d
addl $0x24, %r8d
cmpq %rsi, %r8
jae 0x1eee
addq %rdi, %r8
addq %rdi, %rsi
xorl %ecx, %ecx
cmpq %rsi, %r8
jae 0x1ee7
cmpb $-0x1, (%r8)
je 0x1eb9
movq %r8, (%rdx,%rcx,8)
cmpb $0x0, (%r8)
leaq 0x1(%r8), %r8
je 0x1eab
cmpq %rsi, %r8
jb 0x1e9c
incq %rcx
cmpq $0x19, %rcx
jne 0x1e8d
movl $0x19, %ecx
xorl %ebx, %ebx
movl $0x0, %eax
cmpl $0x18, %ecx
ja 0x1eee
movl %ecx, %eax
leaq (%rdx,%rax,8), %rdi
movl $0x18, %eax
subl %ecx, %eax
leaq 0x8(,%rax,8), %rdx
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x1130
xorl %eax, %eax
jmp 0x1eee
movl $0x1, %eax
xorl %ebx, %ebx
testb %bl, %bl
je 0x1ef7
movl $0x1, %eax
popq %rbx
retq