// File: /workspace/github_c_makefile_star2_O1/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, 0xc(%rsp)
movq 0x623f(%rip), %r13      # 0xd5e0
leaq 0x6238(%rip), %r14      # 0xd5e0
cmpq %r14, %r13
je 0x7404
xorl %edx, %edx
movq %r13, %rsi
xorl %ecx, %ecx
xorl %eax, %eax
movslq 0x18(%rsi), %rdi
testq %rdi, %rdi
jle 0x73e8
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 0x73cd
addl %edi, %ecx
movq (%rsi), %rsi
cmpq %r14, %rsi
jne 0x73b6
incl %eax
movslq %ecx, %rdi
shlq $0x5, %rdi
addq $0x20, %rdi
movslq %eax, %rbx
jmp 0x740e
movl $0x20, %edi
movl $0x1, %ebx
callq 0x21c0
testq %rax, %rax
je 0x7595
movq %rax, %rbp
movq %rbx, %rdi
callq 0x21c0
testq %rax, %rax
je 0x759d
movq %rax, %r15
movq %rax, %rbx
movq %rbp, %r12
cmpq %r14, %r13
je 0x74d4
movq %rbp, %r12
movq %r15, %rbx
movq 0x10(%r13), %rsi
movslq 0x18(%r13), %rdx
shlq $0x5, %rdx
movq %r12, %rdi
callq 0x21a0
movslq 0x18(%r13), %rax
testq %rax, %rax
jle 0x74c0
movl $0x18, %ecx
xorl %edx, %edx
movq 0x10(%r13), %rsi
movl -0x10(%rsi,%rcx), %edi
cmpl $0x2, %edi
je 0x749f
cmpl $0x1, %edi
je 0x748e
testl %edi, %edi
jne 0x74b0
movb (%rsi,%rcx), %sil
movb %sil, (%rbx)
incq %rbx
jmp 0x74b0
movb (%rsi,%rcx), %sil
movb %sil, (%rbx)
movb $0x3a, 0x1(%rbx)
addq $0x2, %rbx
jmp 0x74b0
movb (%rsi,%rcx), %sil
movb %sil, (%rbx)
movw $0x3a3a, 0x1(%rbx)      # imm = 0x3A3A
addq $0x3, %rbx
incq %rdx
movslq 0x18(%r13), %rsi
addq $0x20, %rcx
cmpq %rsi, %rdx
jl 0x746c
shlq $0x5, %rax
addq %rax, %r12
movq (%r13), %r13
cmpq %r14, %r13
jne 0x7448
movq %r15, 0x18(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
movb $0x0, (%rbx)
movq 0x5adf(%rip), %r15      # 0xcfd0
movq %rbp, 0x10(%rsp)
movq 0x5af3(%rip), %rax      # 0xcff0
movl $0x1, (%rax)
xorl %r13d, %r13d
movl 0xc(%rsp), %edi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x20d0
movl $0x0, %r12d
testl %eax, %eax
je 0x757a
movl %eax, %ebx
movl %eax, %r13d
xorl %r12d, %r12d
movq %r14, %rbp
movq (%rbp), %rbp
cmpq %r14, %rbp
je 0x7552
movq (%r15), %rsi
movq 0x28(%rbp), %rdx
movl %r13d, %edi
callq *0x20(%rbp)
testl %eax, %eax
cmovsl %eax, %r12d
jg 0x7534
cmpl $-0x1, %ebx
je 0x756b
cmpl $0x3f, %ebx
movq 0x10(%rsp), %rbp
jne 0x7574
movl $0x1, %r12d
xorl %eax, %eax
jmp 0x7576
xorl %eax, %eax
movq 0x10(%rsp), %rbp
jmp 0x7576
movb $0x1, %al
testb %al, %al
je 0x7589
cmpl $-0x1, %r13d
je 0x7589
testl %r12d, %r12d
je 0x74f6
movq 0x18(%rsp), %rdi
callq 0x2030
jmp 0x75a3
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x75ab
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbp, %rdi
callq 0x2030
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)