// File: /workspace/github_c_makefile_star2_O0/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_optarg_cb
static int eprog_optarg_cb(int val, const char *arg, void *privdata)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)privdata;

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

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

        case 'x':
            if (strcasecmp(arg, "high") == 0)
            {
                p_prog->reset_polarity = RESET_POLARITY_HIGH;
            }
            else if (strcasecmp(arg, "low") == 0)
            {
                p_prog->reset_polarity = RESET_POLARITY_LOW;
            }
            else
            {
                fprintf(stderr, "invalid reset polarity: '%s'\n", arg);
                return -1;
            }
            break;

        case 't':
            {
                unsigned int i;

                if (p_prog->eprom_type != 0)
                {
                    fprintf(stderr, "invalid EPROM type: '%s'\n", arg);
                    return -1;
                }

                for (i = 0; i < ARRAY_SIZE(eprom_types); i++)
                {
                    if (strcmp(arg, eprom_types[i].name) == 0)
                    {
                        p_prog->eprom_type  = eprom_types[i].eprom_type;
                        p_prog->pagesize    = eprom_types[i].pagesize;
                    }
                }

                if (p_prog->eprom_type == 0)
                {
                    fprintf(stderr, "invalid EPROM type: '%s'\n", arg);
                    return -1;
                }
            }
            break;

        case 'h':
        case '?': /* error */
            fprintf(stderr, "Usage: eprom_sim [options]\n"
            "  -d <device>                  - selects eprom_sim device\n"
            "  -x <reset polarity>          - select 'high' or 'low' active reset\n"
            "  -t <type>                    - selects EPROM type (2716 - 27010)\n"
            "  -r eprom:<file>              - reads EPROM to file   (.bin | .hex | -)\n"
            "  -w eprom:<file>              - write EPROM from file (.bin | .hex)\n"
            "  -p <0|1|2>                   - progress bar mode\n"
            "\n"
            "Example: eprom_sim -d /dev/ttyUSB0 -t 2764 -r high -w eprom:data.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, -0x28(%rbp)
subl $0x3f, %eax
je 0x4273
jmp 0x407c
movl -0x28(%rbp), %eax
subl $0x64, %eax
je 0x40af
jmp 0x4086
movl -0x28(%rbp), %eax
subl $0x68, %eax
je 0x4273
jmp 0x4094
movl -0x28(%rbp), %eax
subl $0x74, %eax
je 0x4194
jmp 0x40a2
movl -0x28(%rbp), %eax
subl $0x78, %eax
je 0x4121
jmp 0x4294
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x40e1
movq 0xbf38(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x704a(%rip), %rsi      # 0xb118
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x42a4
movq 0xbee8(%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 0x411c
leaq 0x7023(%rip), %rdi      # 0xb12e
callq 0x2210
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x42a4
jmp 0x429d
movq -0x10(%rbp), %rdi
leaq 0x74b0(%rip), %rsi      # 0xb5dc
callq 0x2040
cmpl $0x0, %eax
jne 0x4143
movq -0x20(%rbp), %rax
movl $0x1, 0x6c(%rax)
jmp 0x418f
movq -0x10(%rbp), %rdi
leaq 0x7493(%rip), %rsi      # 0xb5e1
callq 0x2040
cmpl $0x0, %eax
jne 0x4165
movq -0x20(%rbp), %rax
movl $0x0, 0x6c(%rax)
jmp 0x418d
movq 0xbe8c(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x746b(%rip), %rsi      # 0xb5e5
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x42a4
jmp 0x418f
jmp 0x429d
movq -0x20(%rbp), %rax
movzbl 0x69(%rax), %eax
cmpl $0x0, %eax
je 0x41c9
movq 0xbe50(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x744d(%rip), %rsi      # 0xb603
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x42a4
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpq $0x8, %rax
jae 0x423f
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %eax
leaq 0xc1a9(%rip), %rsi      # 0x10390
imulq $0xa, %rax, %rax
addq %rax, %rsi
callq 0x2150
cmpl $0x0, %eax
jne 0x4232
movl -0x24(%rbp), %eax
movl %eax, %ecx
leaq 0xc18c(%rip), %rax      # 0x10390
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movb 0x8(%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, 0x69(%rax)
movl -0x24(%rbp), %eax
movl %eax, %ecx
leaq 0xc16f(%rip), %rax      # 0x10390
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movb 0x9(%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, 0x6a(%rax)
jmp 0x4234
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x41d0
movq -0x20(%rbp), %rax
movzbl 0x69(%rax), %eax
cmpl $0x0, %eax
jne 0x4271
movq 0xbda5(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x73a2(%rip), %rsi      # 0xb603
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x42a4
jmp 0x429d
movq 0xbd7e(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x7399(%rip), %rsi      # 0xb61d
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x42a4
movl $0x1, -0x4(%rbp)
jmp 0x42a4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)