// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/twiboot.c
// Function: twi_optarg_cb
static int twi_optarg_cb(int val, const char *arg, void *privdata)
{
    struct twi_privdata *twi = (struct twi_privdata *)privdata;

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

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

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

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

        case 's': /* stay in bootloader */
            twi->stay_in_bootloader = 1;
            break;

        case 'h':
        case '?': /* error */
                fprintf(stderr, "Usage: twiboot [options]\n"
                    "  -a <address>                 - selects i2c address (0x01 - 0x7F)\n"
                    "  -d <device>                  - selects i2c device  (default: /dev/i2c-0)\n"
                    "  -s                           - stay in bootloader afterwards\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: twiboot -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 0xa76d
jmp 0xa64c
movl -0x2c(%rbp), %eax
subl $0x61, %eax
je 0xa683
jmp 0xa656
movl -0x2c(%rbp), %eax
subl $0x64, %eax
je 0xa6f1
jmp 0xa664
movl -0x2c(%rbp), %eax
subl $0x68, %eax
je 0xa76d
jmp 0xa672
movl -0x2c(%rbp), %eax
subl $0x73, %eax
je 0xa760
jmp 0xa78e
movq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x10, %edx
callq 0x2180
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xa6c4
movq -0x20(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x1, %eax
jl 0xa6c4
movq -0x20(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x7f, %eax
jle 0xa6ec
movq 0x592d(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xa28(%rip), %rsi       # 0xb101
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa79e
jmp 0xa797
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0xa726
movq 0x58f6(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0x58c4(%rip), %rax      # 0xffd0
movq (%rax), %rdx
leaq 0xa02(%rip), %rsi       # 0xb118
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa79e
movq 0x58a3(%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 0xa75e
leaq 0x9de(%rip), %rdi       # 0xb12e
callq 0x2210
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa79e
jmp 0xa797
movq -0x20(%rbp), %rax
movl $0x1, 0x14(%rax)
jmp 0xa797
movq 0x5884(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x1e7b(%rip), %rsi      # 0xc5f9
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa79e
movl $0x1, -0x4(%rbp)
jmp 0xa79e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)