// File: /workspace/github_c_makefile_star2_O0/kyz[P]amostools/listamos.c
// Function: read_config_extensions
void read_config_extensions(int argc, char *argv[]) {
    char *dir = ".", *config = NULL, *fullname = NULL, *fp;
    char *slots[AMOS_EXTENSION_SLOTS];
    uint8_t *buf = NULL;
    size_t len;
    int i, j;

    DIR *d = NULL;
    struct dirent *de;

    /* look for -c and -d options */
    for (i = 1; i < argc; i++) {
        if (argv[i][0] != '-') break; /* end of arg processing */
        if (argv[i][1] == 'c') config = argv[++i];
        else if (argv[i][1] == 'd') dir = argv[++i];
        else if (argv[i][1] == 'e' && !argv[i][2]) i++;
    }

    /* if no '-c' flag, do nothing */
    if (!config) goto error_handler;

    /* open '-d' directory */
    if (!(d = opendir(dir))) {
        perror(dir);
        goto error_handler;
    }

    /* read '-c' config file */
    if (!(buf = read_file(config, &len))) {
        goto error_handler;
    }
    if (AMOS_parse_config(buf, len, slots)) {
        fprintf(stderr, "%s: not an AMOS config file\n", config);
        goto error_handler;
    }

    /* reduce the extension names to just NULL or a filename,
     * and remove default extensions */
    for (i = 0; i < AMOS_EXTENSION_SLOTS; i++) {
        if (slots[i] && *slots[i]) {
            char *fname = strrchr(slots[i], '/');
            if (fname) slots[i] = fname + 1;
            /* ignore extensions loaded by default */
            for (j = 0; j < NUM_DEFAULT_EXTENSIONS; j++) {
                if (!strcasecmp(slots[i], default_extensions[j])) {
                    slots[i] = NULL;
                    break;
                }
            }
        }
        else {
            slots[i] = NULL;
        }
    }

    /* allocate space for dir + "/" + fname, pre-fill dir + "/" */
    fullname = malloc(strlen(dir) + 257);
    if (!fullname) goto error_handler;
    strcpy(fullname, dir);
    fp = &fullname[strlen(dir)];
    *fp++ = '/';

    /* find files in the directory that are listed as extensions */
    while ((de = readdir(d))) {
        /* compare each extension's filename to the current dir entry */
        for (i = 0; i < AMOS_EXTENSION_SLOTS; i++) {
            if (!slots[i] || strcasecmp(de->d_name, slots[i])) continue;
            /* build the full path and load extension */
            strncpy(fp, de->d_name, 256);
            read_extension_file(fullname, i + 1);
            slots[i] = NULL;
        }
    }

    /* complain about any listed extensions not loaded */
    for (i = 0; i < AMOS_EXTENSION_SLOTS; i++) {
        if (slots[i]) fprintf(stderr, "%s/%s: no such file\n", dir, slots[i]);
    }

 error_handler:
    if (d) closedir(d);
    free(buf);
    free(fullname);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x103d(%rip), %rax      # 0x41a6
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x108(%rbp)
movq $0x0, -0x120(%rbp)
movl $0x1, -0x114(%rbp)
movl -0x114(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x328e
movq -0x10(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x31c8
jmp 0x328e
movq -0x10(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x63, %eax
jne 0x3200
movq -0x10(%rbp), %rax
movl -0x114(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x114(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
jmp 0x3278
movq -0x10(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x64, %eax
jne 0x3238
movq -0x10(%rbp), %rax
movl -0x114(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x114(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
jmp 0x3276
movq -0x10(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x65, %eax
jne 0x3274
movq -0x10(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpb $0x0, 0x2(%rax)
jne 0x3274
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x3276
jmp 0x3278
jmp 0x327a
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x319d
cmpq $0x0, -0x20(%rbp)
jne 0x329a
jmp 0x35d1
movq -0x18(%rbp), %rdi
callq 0x10b0
movq %rax, -0x120(%rbp)
cmpq $0x0, %rax
jne 0x32be
movq -0x18(%rbp), %rdi
callq 0x11b0
jmp 0x35d1
movq -0x20(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x12d0
movq %rax, -0x108(%rbp)
cmpq $0x0, %rax
jne 0x32e0
jmp 0x35d1
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rsi
leaq -0x100(%rbp), %rdx
callq 0x2310
cmpl $0x0, %eax
je 0x3320
movq 0x2cf2(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xe94(%rip), %rsi       # 0x41a8
movb $0x0, %al
callq 0x1150
jmp 0x35d1
movl $0x0, -0x114(%rbp)
cmpl $0x19, -0x114(%rbp)
jge 0x343d
movslq -0x114(%rbp), %rax
cmpq $0x0, -0x100(%rbp,%rax,8)
je 0x3414
movslq -0x114(%rbp), %rax
movq -0x100(%rbp,%rax,8), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x3414
movslq -0x114(%rbp), %rax
movq -0x100(%rbp,%rax,8), %rdi
movl $0x2f, %esi
callq 0x1110
movq %rax, -0x130(%rbp)
cmpq $0x0, -0x130(%rbp)
je 0x33ac
movq -0x130(%rbp), %rcx
addq $0x1, %rcx
movslq -0x114(%rbp), %rax
movq %rcx, -0x100(%rbp,%rax,8)
movl $0x0, -0x118(%rbp)
cmpl $0x9, -0x118(%rbp)
jge 0x3412
movslq -0x114(%rbp), %rax
movq -0x100(%rbp,%rax,8), %rdi
movslq -0x118(%rbp), %rcx
leaq 0x2d24(%rip), %rax      # 0x6100
movq (%rax,%rcx,8), %rsi
callq 0x1050
cmpl $0x0, %eax
jne 0x33ff
movslq -0x114(%rbp), %rax
movq $0x0, -0x100(%rbp,%rax,8)
jmp 0x3412
jmp 0x3401
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x33b6
jmp 0x3427
movslq -0x114(%rbp), %rax
movq $0x0, -0x100(%rbp,%rax,8)
jmp 0x3429
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x332a
movq -0x18(%rbp), %rdi
callq 0x10d0
movq %rax, %rdi
addq $0x101, %rdi            # imm = 0x101
callq 0x1180
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3465
jmp 0x35d1
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1080
movq -0x28(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10d0
movq %rax, %rcx
movq -0x138(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb $0x2f, (%rax)
movq -0x120(%rbp), %rdi
callq 0x1170
movq %rax, -0x128(%rbp)
cmpq $0x0, %rax
je 0x356c
movl $0x0, -0x114(%rbp)
cmpl $0x19, -0x114(%rbp)
jge 0x3567
movslq -0x114(%rbp), %rax
cmpq $0x0, -0x100(%rbp,%rax,8)
je 0x3513
movq -0x128(%rbp), %rdi
addq $0x13, %rdi
movslq -0x114(%rbp), %rax
movq -0x100(%rbp,%rax,8), %rsi
callq 0x1050
cmpl $0x0, %eax
je 0x3515
jmp 0x3553
movq -0x30(%rbp), %rdi
movq -0x128(%rbp), %rsi
addq $0x13, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x1070
movq -0x28(%rbp), %rdi
movl -0x114(%rbp), %esi
addl $0x1, %esi
callq 0x2ef0
movslq -0x114(%rbp), %rax
movq $0x0, -0x100(%rbp,%rax,8)
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x34d0
jmp 0x34a9
movl $0x0, -0x114(%rbp)
cmpl $0x19, -0x114(%rbp)
jge 0x35cf
movslq -0x114(%rbp), %rax
cmpq $0x0, -0x100(%rbp,%rax,8)
je 0x35bc
movq 0x2a60(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movslq -0x114(%rbp), %rax
movq -0x100(%rbp,%rax,8), %rcx
leaq 0xc10(%rip), %rsi       # 0x41c5
movb $0x0, %al
callq 0x1150
jmp 0x35be
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x3576
jmp 0x35d1
cmpq $0x0, -0x120(%rbp)
je 0x35e7
movq -0x120(%rbp), %rdi
callq 0x1120
movq -0x108(%rbp), %rdi
callq 0x1040
movq -0x28(%rbp), %rdi
callq 0x1040
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)