// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/mpmboot.c
// Function: mpm_optarg_cb
static int mpm_optarg_cb(int val, const char *arg, void *privdata)
{
    struct mpm_privdata *mpm = (struct mpm_privdata *)privdata;

    switch (val)
    {
        case 'a': /* address */
            {
                char *endptr;
                mpm->address = strtol(arg, &endptr, 16);

                if (*endptr != '\0' || mpm->address < 0x01 || mpm->address > 0x7F)
                {
                    fprintf(stderr, "invalid address: '%s'\n", arg);
                    return -1;
                }
            }
            break;

        case 'd': /* device */
            if (mpm->device != NULL)
            {
                fprintf(stderr, "invalid device: '%s'\n", optarg);
                return -1;
            }

            mpm->device = strdup(optarg);
            if (mpm->device == NULL)
            {
                perror("strdup()");
                return -1;
            }
            break;

        case 'h':
        case '?': /* error */
            fprintf(stderr, "Usage: mpmboot [options]\n"
                "  -a <address>                 - selects mpm address (0x01 - 0xFF)\n"
                "  -d <device>                  - selects mpm device\n"
                "  -r <flash|eeprom>:<file>     - reads flash/eeprom to file   (.bin | .hex | -)\n"
                "  -w <flash|eeprom>:<file>     - write flash/eeprom from file (.bin | .hex)\n"
                "  -n                           - disable verify after write\n"
                "  -p <0|1|2>                   - progress bar mode\n"
                "\n"
                "Example: mpmboot -d /dev/ttyUSB0 -a 0x22 -w flash:blmc.hex -w eeprom:blmc_eeprom.hex\n"
                "\n");

            return -1;

        default:
            return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x2c(%rbp)
subl $0x3f, %eax
je 0x7fe2
jmp 0x7edc
movl -0x2c(%rbp), %eax
subl $0x61, %eax
je 0x7f05
jmp 0x7ee6
movl -0x2c(%rbp), %eax
subl $0x64, %eax
je 0x7f73
jmp 0x7ef4
movl -0x2c(%rbp), %eax
subl $0x68, %eax
je 0x7fe2
jmp 0x8003
movq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x10, %edx
callq 0x2180
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x10(%rax)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x7f46
movq -0x20(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x1, %eax
jl 0x7f46
movq -0x20(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7f, %eax
jle 0x7f6e
movq 0x80ab(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x31a6(%rip), %rsi      # 0xb101
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8013
jmp 0x800c
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x7fa8
movq 0x8074(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0x8042(%rip), %rax      # 0xffd0
movq (%rax), %rdx
leaq 0x3180(%rip), %rsi      # 0xb118
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8013
movq 0x8021(%rip), %rax      # 0xffd0
movq (%rax), %rdi
callq 0x2250
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x7fe0
leaq 0x315c(%rip), %rdi      # 0xb12e
callq 0x2210
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8013
jmp 0x800c
movq 0x800f(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x419d(%rip), %rsi      # 0xc190
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8013
movl $0x1, -0x4(%rbp)
jmp 0x8013
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)