// File: /workspace/github_c_makefile_star2_O3/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 0x1e99
movl (%rdi), %ecx
bswapl %ecx
cmpl $0x50496474, %ecx       # imm = 0x50496474
je 0x1db5
cmpl $0x50496431, %ecx       # imm = 0x50496431
jne 0x1e25
movl 0x4(%rdi), %eax
bswapl %eax
leaq -0x5c(%rsi), %r8
cmpq %rax, %r8
jbe 0x1e25
leal 0x8(%rax), %r8d
movl (%rdi,%r8), %r8d
bswapl %r8d
cmpl $0x50497478, %r8d       # imm = 0x50497478
je 0x1de0
cmpl $0x50497431, %r8d       # imm = 0x50497431
jne 0x1e25
addl $0x10, %eax
addq %rdi, %rax
movslq %esi, %rcx
movl $0x1, %esi
cmpq $0x10, %rsi
jb 0x1dfd
leaq 0x2(%rax), %r8
movq %r8, -0x80(%rdx,%rsi,8)
movzbl 0x1(%rax), %r8d
addq %r8, %rax
addq $0x2, %rax
movq %rax, %r8
subq %rdi, %r8
cmpq %rcx, %r8
jg 0x1e99
incq %rsi
cmpq $0x29, %rsi
jne 0x1dee
xorl %ebx, %ebx
jmp 0x1e9e
cmpq $0x12d, %rsi            # imm = 0x12D
jb 0x1e99
cmpl $0x3f3, %ecx            # imm = 0x3F3
jne 0x1e99
movl 0x18(%rdi), %eax
bswapl %eax
cmpl $0x3e9, %eax            # imm = 0x3E9
jne 0x1e99
cmpb $0x0, 0x12a(%rdi)
jns 0x1e99
movzwl 0x128(%rdi), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl 0x20(%rdi), %ecx
bswapl %ecx
subl %ecx, %eax
addl $0x24, %eax
cmpq %rsi, %rax
jae 0x1e99
addq %rdi, %rax
addq %rdi, %rsi
xorl %ecx, %ecx
xorl %ebx, %ebx
cmpq %rsi, %rax
jae 0x1e99
cmpb $-0x1, (%rax)
je 0x1ea2
movq %rax, (%rdx,%rcx,8)
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
je 0x1e8e
cmpq %rsi, %rax
jb 0x1e80
incq %rcx
cmpq $0x19, %rcx
jne 0x1e72
jmp 0x1e9e
movl $0x1, %ebx
movl %ebx, %eax
popq %rbx
retq
cmpq $0x18, %rcx
ja 0x1e21
leaq (%rdx,%rcx,8), %rdi
shlq $0x3, %rcx
movl $0xc0, %eax
subq %rcx, %rax
movabsq $0x7fffffff8, %rdx      # imm = 0x7FFFFFFF8
andq %rax, %rdx
addq $0x8, %rdx
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x1130
jmp 0x1e9e