// File: /workspace/github_c_makefile_star2_O2/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 $0x1
popq %rax
cmpq $0x65, %rsi
jb 0x1ce9
movl (%rdi), %r8d
bswapl %r8d
cmpl $0x50496474, %r8d       # imm = 0x50496474
je 0x1c7e
cmpl $0x50496431, %r8d       # imm = 0x50496431
jne 0x1cea
movl 0x4(%rdi), %ecx
bswapl %ecx
leaq -0x5c(%rsi), %r9
cmpq %rcx, %r9
jbe 0x1cea
leal 0x8(%rcx), %r9d
movl (%rdi,%r9), %r9d
bswapl %r9d
cmpl $0x50497478, %r9d       # imm = 0x50497478
je 0x1ca9
cmpl $0x50497431, %r9d       # imm = 0x50497431
jne 0x1cea
addl $0x10, %ecx
addq %rdi, %rcx
movslq %esi, %rsi
pushq $0x1
popq %r8
cmpq $0x29, %r8
je 0x1d73
cmpq $0x10, %r8
jb 0x1ccf
leaq 0x2(%rcx), %r9
movq %r9, -0x80(%rdx,%r8,8)
movzbl 0x1(%rcx), %r9d
addq %r9, %rcx
addq $0x2, %rcx
movq %rcx, %r9
subq %rdi, %r9
incq %r8
cmpq %rsi, %r9
jle 0x1cb6
retq
cmpq $0x12d, %rsi            # imm = 0x12D
jb 0x1ce9
cmpl $0x3f3, %r8d            # imm = 0x3F3
jne 0x1ce9
movl 0x18(%rdi), %ecx
bswapl %ecx
cmpl $0x3e9, %ecx            # imm = 0x3E9
jne 0x1ce9
cmpb $0x0, 0x12a(%rdi)
jns 0x1ce9
movzwl 0x128(%rdi), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movl 0x20(%rdi), %r8d
bswapl %r8d
subl %r8d, %ecx
addl $0x24, %ecx
cmpq %rsi, %rcx
jae 0x1ce9
addq %rdi, %rcx
addq %rdi, %rsi
xorl %edi, %edi
cmpq $0x19, %rdi
je 0x1d61
cmpq %rsi, %rcx
jae 0x1ce9
cmpb $-0x1, (%rcx)
je 0x1d61
movq %rcx, (%rdx,%rdi,8)
cmpb $0x0, (%rcx)
leaq 0x1(%rcx), %rcx
je 0x1d5c
cmpq %rsi, %rcx
jb 0x1d4e
incq %rdi
jmp 0x1d3a
movl %edi, %eax
cmpq $0x19, %rax
je 0x1d73
andq $0x0, (%rdx,%rax,8)
incq %rax
jmp 0x1d63
xorl %eax, %eax
retq