// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, 0x10(%rsp)
movl %edi, 0xc(%rsp)
movq 0x6245(%rip), %r13      # 0xd5f0
leaq 0x623e(%rip), %rbp      # 0xd5f0
cmpq %rbp, %r13
je 0x740e
xorl %edx, %edx
movq %r13, %rsi
xorl %ecx, %ecx
xorl %eax, %eax
movslq 0x18(%rsi), %rdi
testq %rdi, %rdi
jle 0x73f2
movq 0x10(%rsi), %r8
movq %rdi, %r9
shlq $0x5, %r9
xorl %r10d, %r10d
movl 0x8(%r8,%r10), %r11d
leal 0x1(%r11), %ebx
cmpl $0x3, %r11d
cmovael %edx, %ebx
addl %ebx, %eax
addq $0x20, %r10
cmpq %r10, %r9
jne 0x73d7
addl %edi, %ecx
movq (%rsi), %rsi
cmpq %rbp, %rsi
jne 0x73c0
incl %eax
movslq %ecx, %rdi
shlq $0x5, %rdi
addq $0x20, %rdi
movslq %eax, %r15
jmp 0x7419
movl $0x20, %edi
movl $0x1, %r15d
callq 0x21d0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x758f
movq %rax, %r14
movq %r15, %rdi
callq 0x21d0
testq %rax, %rax
je 0x7587
movq %rax, %rbx
movq %rax, %r15
movq %r14, %r12
cmpq %rbp, %r13
je 0x74e7
movq %r14, %r12
movq %rbx, %r15
movq 0x10(%r13), %rsi
movslq 0x18(%r13), %rdx
shlq $0x5, %rdx
movq %r12, %rdi
callq 0x21b0
movslq 0x18(%r13), %rax
testq %rax, %rax
jle 0x74d3
movl $0x18, %ecx
xorl %edx, %edx
movq 0x10(%r13), %rsi
movl -0x10(%rsi,%rcx), %edi
cmpl $0x2, %edi
je 0x74b1
cmpl $0x1, %edi
je 0x749f
testl %edi, %edi
jne 0x74c3
movb (%rsi,%rcx), %sil
movb %sil, (%r15)
incq %r15
jmp 0x74c3
movb (%rsi,%rcx), %sil
movb %sil, (%r15)
movb $0x3a, 0x1(%r15)
addq $0x2, %r15
jmp 0x74c3
movb (%rsi,%rcx), %sil
movb %sil, (%r15)
movw $0x3a3a, 0x1(%r15)      # imm = 0x3A3A
addq $0x3, %r15
incq %rdx
movslq 0x18(%r13), %rsi
addq $0x20, %rcx
cmpq %rsi, %rdx
jl 0x747d
shlq $0x5, %rax
addq %rax, %r12
movq (%r13), %r13
cmpq %rbp, %r13
jne 0x7459
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
movb $0x0, (%r15)
movq 0x5ad0(%rip), %r15      # 0xcfd0
movq %r14, (%rsp)
movq 0x5ae5(%rip), %rax      # 0xcff0
movl $0x1, (%rax)
xorl %r12d, %r12d
movl 0xc(%rsp), %edi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x20d0
testl %eax, %eax
je 0x756b
movl %eax, %r13d
movq %rbx, %r14
xorl %r12d, %r12d
movq %rbp, %rbx
movq (%rbx), %rbx
cmpq %rbp, %rbx
je 0x7558
movq (%r15), %rsi
movq 0x28(%rbx), %rdx
movl %r13d, %edi
callq *0x20(%rbx)
testl %eax, %eax
cmovsl %eax, %r12d
jg 0x753b
cmpl $0x3f, %r13d
je 0x7572
cmpl $-0x1, %r13d
movq %r14, %rbx
je 0x757b
movq (%rsp), %r14
testl %r12d, %r12d
je 0x7504
jmp 0x757f
movl $0x1, %r12d
movq %r14, %rbx
movq (%rsp), %r14
movq %rbx, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)