// File: /workspace/github_c_makefile_star2_O3/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
movl $0x1, %eax
cmpl $0x73, %edi
jle 0x428b
cmpl $0x74, %edi
je 0x42ca
cmpl $0x78, %edi
jne 0x433d
leaq 0x42d0(%rip), %rsi      # 0x8527
movq %rbx, %rdi
callq 0x2050
testl %eax, %eax
je 0x4333
leaq 0x42be(%rip), %rsi      # 0x852c
movq %rbx, %rdi
callq 0x2050
testl %eax, %eax
jne 0x435a
movl $0x0, 0x6c(%r14)
jmp 0x433b
cmpl $0x64, %edi
jne 0x4322
cmpq $0x0, (%r14)
jne 0x4347
movq 0x8d2b(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
callq 0x2290
movq %rax, (%r14)
testq %rax, %rax
jne 0x433b
leaq 0x3dba(%rip), %rdi      # 0x807a
callq 0x2240
jmp 0x4375
cmpb $0x0, 0x69(%r14)
jne 0x430f
xorl %r15d, %r15d
leaq 0x90d5(%rip), %r12      # 0xd3b0
xorl %r13d, %r13d
leaq (%r12,%r15), %rsi
movq %rbx, %rdi
callq 0x2170
testl %eax, %eax
jne 0x4300
movb 0x8(%r15,%r12), %r13b
movb %r13b, 0x69(%r14)
movb 0x9(%r15,%r12), %al
movb %al, 0x6a(%r14)
addq $0xa, %r15
cmpq $0x50, %r15
jne 0x42de
testb %r13b, %r13b
jne 0x433b
movq 0x8ce2(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x422e(%rip), %rsi      # 0x854e
jmp 0x436b
cmpl $0x3f, %edi
je 0x432c
cmpl $0x68, %edi
jne 0x433d
callq 0x2644
jmp 0x4375
movl $0x1, 0x6c(%r14)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x8caa(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x3d0c(%rip), %rsi      # 0x8064
jmp 0x436b
movq 0x8c97(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x41c5(%rip), %rsi      # 0x8530
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2180
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x433d