// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r14
movq %rsi, %rbx
cmpl $0x64, %edi
je 0x3696
cmpl $0x74, %edi
je 0x36c8
cmpl $0x78, %edi
je 0x365e
cmpl $0x3f, %edi
je 0x372e
cmpl $0x68, %edi
je 0x372e
pushq $0x1
jmp 0x377e
leaq 0x4ec2(%rip), %rsi      # 0x8527
movq %rbx, %rdi
callq 0x2050
testl %eax, %eax
je 0x3722
leaq 0x4eb0(%rip), %rsi      # 0x852c
movq %rbx, %rdi
callq 0x2050
testl %eax, %eax
jne 0x3761
andl $0x0, 0x6c(%r14)
jmp 0x372a
cmpq $0x0, (%r14)
jne 0x374e
movq 0x9929(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
callq 0x2290
movq %rax, (%r14)
testq %rax, %rax
jne 0x372a
leaq 0x49bc(%rip), %rdi      # 0x807a
callq 0x2240
jmp 0x377c
cmpb $0x0, 0x69(%r14)
jne 0x370f
xorl %r15d, %r15d
leaq 0x9cd7(%rip), %r12      # 0xd3b0
xorl %r13d, %r13d
cmpq $0x50, %r15
je 0x370a
leaq (%r12,%r15), %rsi
movq %rbx, %rdi
callq 0x2170
testl %eax, %eax
jne 0x3704
movb 0x8(%r15,%r12), %r13b
movb %r13b, 0x69(%r14)
movb 0x9(%r15,%r12), %al
movb %al, 0x6a(%r14)
addq $0xa, %r15
jmp 0x36dc
testb %r13b, %r13b
jne 0x372a
movq 0x98e2(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x4e2e(%rip), %rsi      # 0x854e
jmp 0x3772
movl $0x1, 0x6c(%r14)
xorl %eax, %eax
jmp 0x377f
movq 0x98c3(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x4e29(%rip), %rdi      # 0x8568
pushq $0x1
popq %rdx
movl $0x1e5, %esi            # imm = 0x1E5
callq 0x2280
jmp 0x377c
movq 0x98a3(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x4905(%rip), %rsi      # 0x8064
jmp 0x3772
movq 0x9890(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x4dbe(%rip), %rsi      # 0x8530
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2180
pushq $-0x1
popq %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq