// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x20(%rsp)
movl %edi, 0x1c(%rsp)
xorl %eax, %eax
leaq 0x6ff6(%rip), %rcx      # 0xd5f0
movq %rcx, %rdx
xorl %ebx, %ebx
xorl %esi, %esi
movq (%rdx), %rdx
cmpq %rcx, %rdx
je 0x6646
movl 0x18(%rdx), %edi
testl %edi, %edi
movl $0x0, %r8d
cmovgl %edi, %r8d
shlq $0x5, %r8
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x6642
movq 0x10(%rdx), %r10
movl 0x8(%r10,%r9), %r10d
leal 0x1(%r10), %r11d
cmpl $0x3, %r10d
cmovael %eax, %r11d
addl %r11d, %ebx
addq $0x20, %r9
jmp 0x661f
addl %edi, %esi
jmp 0x6601
movslq %esi, %rdi
shlq $0x5, %rdi
addq $0x20, %rdi
callq 0x21d0
pushq $-0x1
popq %r12
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x67c9
incl %ebx
movslq %ebx, %rdi
callq 0x21d0
testq %rax, %rax
je 0x67bf
movq %rax, %r15
leaq 0x6f6b(%rip), %r14      # 0xd5f0
movq %r14, %rbp
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %r12
movq (%rbp), %rbp
cmpq %r14, %rbp
je 0x6718
movq 0x10(%rbp), %rsi
movl 0x18(%rbp), %ebx
movslq %ebx, %r13
shlq $0x5, %r13
movq %r12, %rdi
movq %r13, %rdx
callq 0x21b0
pushq $0x18
popq %rax
xorl %ecx, %ecx
movslq %ebx, %rdx
cmpq %rdx, %rcx
jge 0x6710
movq 0x10(%rbp), %rdx
movl -0x10(%rdx,%rax), %esi
cmpl $0x2, %esi
je 0x66f3
cmpl $0x1, %esi
je 0x66e2
testl %esi, %esi
jne 0x6704
movb (%rdx,%rax), %dl
movb %dl, (%r15)
incq %r15
jmp 0x6704
movb (%rdx,%rax), %dl
movb %dl, (%r15)
movb $0x3a, 0x1(%r15)
addq $0x2, %r15
jmp 0x6704
movb (%rdx,%rax), %dl
movb %dl, (%r15)
movw $0x3a3a, 0x1(%r15)      # imm = 0x3A3A
addq $0x3, %r15
incq %rcx
movl 0x18(%rbp), %ebx
addq $0x20, %rax
jmp 0x66b9
addq %r13, %r12
jmp 0x6692
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
movb $0x0, (%r15)
xorl %r12d, %r12d
movq 0x68bc(%rip), %rbx      # 0xcff0
leaq 0x6eb5(%rip), %rbp      # 0xd5f0
movq 0x688e(%rip), %r15      # 0xcfd0
movq 0x10(%rsp), %r14
testl %r12d, %r12d
jne 0x67b7
movl $0x1, (%rbx)
xorl %r12d, %r12d
movl 0x1c(%rsp), %edi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x20d0
testl %eax, %eax
je 0x6747
movl %eax, %r13d
xorl %r12d, %r12d
movq %rbp, %r14
movq (%r14), %r14
cmpq %rbp, %r14
je 0x6799
movq (%r15), %rsi
movq 0x28(%r14), %rdx
movl %r13d, %edi
callq *0x20(%r14)
testl %eax, %eax
cmovsl %eax, %r12d
jg 0x677b
cmpl $0x3f, %r13d
je 0x67ac
cmpl $-0x1, %r13d
movq 0x10(%rsp), %r14
jne 0x6747
jmp 0x67b7
pushq $0x1
popq %rax
movl %eax, %r12d
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x2030
movq 0x8(%rsp), %rdi
callq 0x2030
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop