// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %rbx
movl $0x1, %eax
cmpl $0x73, %edi
jle 0x42d9
cmpl $0x74, %edi
je 0x4318
cmpl $0x78, %edi
jne 0x438a
leaq 0x4282(%rip), %rsi      # 0x8527
movq %rbx, %rdi
callq 0x2050
testl %eax, %eax
je 0x4380
leaq 0x4270(%rip), %rsi      # 0x852c
movq %rbx, %rdi
callq 0x2050
testl %eax, %eax
jne 0x43a9
movl $0x0, 0x6c(%r14)
jmp 0x4388
cmpl $0x64, %edi
jne 0x436f
cmpq $0x0, (%r14)
jne 0x4396
movq 0x8cdd(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
callq 0x2280
movq %rax, (%r14)
testq %rax, %rax
jne 0x4388
leaq 0x3d6c(%rip), %rdi      # 0x807a
callq 0x2230
jmp 0x43c4
cmpb $0x0, 0x69(%r14)
jne 0x435c
xorl %r15d, %r15d
leaq 0x9077(%rip), %r12      # 0xd3a0
leaq (%r12,%r15), %rsi
movq %rbx, %rdi
callq 0x2160
testl %eax, %eax
jne 0x434b
movb 0x8(%r15,%r12), %al
movb %al, 0x69(%r14)
movb 0x9(%r15,%r12), %al
movb %al, 0x6a(%r14)
addq $0xa, %r15
cmpq $0x50, %r15
jne 0x4329
cmpb $0x0, 0x69(%r14)
jne 0x4388
movq 0x8c95(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x41e1(%rip), %rsi      # 0x854e
jmp 0x43ba
cmpl $0x3f, %edi
je 0x4379
cmpl $0x68, %edi
jne 0x438a
callq 0x26a9
jmp 0x43c4
movl $0x1, 0x6c(%r14)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x8c5b(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x3cbd(%rip), %rsi      # 0x8064
jmp 0x43ba
movq 0x8c48(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x4176(%rip), %rsi      # 0x8530
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2170
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x438a