// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/funkboot.c
// Function: funk_optarg_cb
static int funk_optarg_cb(int val, const char *arg, void *privdata)
{
    struct funk_privdata *funk = (struct funk_privdata *)privdata;

    switch (val)
    {
        case 'a': /* address */
            {
                char *endptr;

                funk->address = strtol(arg, &endptr, 16);
                if (*endptr != '\0' || funk->address < 0x00 || funk->address > 0xFF) {
                    fprintf(stderr, "invalid address: '%s'\n", arg);
                    return -1;
                }
            }
            break;

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

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

        case 'h':
        case '?': /* error */
            fprintf(stderr, "Usage: funkboot [options]\n"
                "  -a <address>                 - selects rfm12 address (0x00 - 0xFF)\n"
                "  -d <device>                  - selects funkbridge 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: funkboot -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 0x660b
jmp 0x650c
movl -0x2c(%rbp), %eax
subl $0x61, %eax
je 0x6531
jmp 0x6516
movl -0x2c(%rbp), %eax
subl $0x64, %eax
je 0x659c
jmp 0x6520
movl -0x2c(%rbp), %eax
subl $0x68, %eax
je 0x660b
jmp 0x662c
movq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x10, %edx
callq 0x2180
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x656f
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jl 0x656f
movq -0x20(%rbp), %rax
cmpl $0xff, 0x10(%rax)
jle 0x6597
movq 0x9a82(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x4b7d(%rip), %rsi      # 0xb101
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x663c
jmp 0x6635
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x65d1
movq 0x9a4b(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0x9a19(%rip), %rax      # 0xffd0
movq (%rax), %rdx
leaq 0x4b57(%rip), %rsi      # 0xb118
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x663c
movq 0x99f8(%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 0x6609
leaq 0x4b33(%rip), %rdi      # 0xb12e
callq 0x2210
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x663c
jmp 0x6635
movq 0x99e6(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x5573(%rip), %rsi      # 0xbb8f
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x663c
movl $0x1, -0x4(%rbp)
jmp 0x663c
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)