// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/optarg.c
// Function: optarg_parse
int optarg_parse(int argc, char * const argv[])
{
    struct option *longopts;
    char *optstring;

    int opt_count;
    int optstring_len;
    optarg_getsize(&opt_count, &optstring_len);

    longopts = malloc(sizeof(struct option) * opt_count);
    if (longopts == NULL)
    {
        return -1;
    }

    optstring = malloc(optstring_len);
    if (optstring == NULL)
    {
        free(longopts);
        return -1;
    }

    optarg_copy(longopts, optstring);

    int retval = 0;
    int val = 0;
    while (val != -1 && retval == 0)
    {
        opterr = 1; /* print error message to stderr */
        val = getopt_long(argc, argv, optstring, longopts, NULL);

        /* variable assigned (not supported) */
        if (val == 0x00)
        {
            continue;
        }

        struct optarg_entry *entry;
        list_for_each_entry(entry, &option_list, list)
        {
            int ret = entry->parser_cb(val, optarg, entry->privdata);

            /* option recognized, with error */
            if (ret < 0)
            {
                retval = ret;
                break;
            }
            /* option recognized, no error */
            else if (ret == 0)
            {
                break;
            }
        }

        /* parsing completed */
        if (val == -1)
        {
            break;
        }

        /* parsing error */
        if (val == '?')
        {
            retval = 1;
            break;
        }
    }

    free(optstring);
    free(longopts);

    return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x24(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x99a0
movslq -0x24(%rbp), %rdi
shlq $0x5, %rdi
callq 0x21b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x9840
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x998e
movslq -0x28(%rbp), %rdi
callq 0x21b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x9869
movq -0x18(%rbp), %rdi
callq 0x2030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x998e
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x9a90
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x30(%rbp)
movb %al, -0x61(%rbp)
je 0x9899
cmpl $0x0, -0x2c(%rbp)
sete %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x98a5
jmp 0x9976
movq 0x6744(%rip), %rax      # 0xfff0
movl $0x1, (%rax)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x20b0
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x98d6
jmp 0x9884
movq 0x6d23(%rip), %rax      # 0x10600
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
leaq 0x6d04(%rip), %rcx      # 0x10600
cmpq %rcx, %rax
je 0x995a
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %edi
movq 0x66bd(%rip), %rcx      # 0xffd0
movq (%rcx), %rsi
movq -0x38(%rbp), %rcx
movq 0x28(%rcx), %rdx
callq *%rax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x9931
movl -0x4c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x995a
cmpl $0x0, -0x4c(%rbp)
jne 0x9939
jmp 0x995a
jmp 0x993b
jmp 0x993d
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x98f1
cmpl $-0x1, -0x30(%rbp)
jne 0x9962
jmp 0x9976
cmpl $0x3f, -0x30(%rbp)
jne 0x9971
movl $0x1, -0x2c(%rbp)
jmp 0x9976
jmp 0x9884
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rdi
callq 0x2030
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)