// File: /workspace/github_c_makefile_star2_O3/masyagin1998[P]GCI/src/interpreter.c
// Function: parse_args
int parse_args(int argc, char**argv, struct INTERPRETER_PARAMS*params)
{
    struct option opts[] = {
        {"version",   0, 0, 'v'},
        {"help",      0, 0, 'h'},
        {"in",        1, 0, 'i'},
        {"out",       1, 0, 'o'},
        {"mode",      1, 0, 'm'},
        {"stacksize", 1, 0,  0},
        {"heapsize",  1, 0,  0},
        {0,0,0,0}
    };

    int c;
    int idx;

    params->in[0] = '\0';
    strncpy(params->out, "stdout", sizeof(params->out));
    params->mode = INTERPRETER_INTERPRET;
    params->stacksize = 1024;
    params->heapsize = 1024 * 1024;
    
    while ((c = getopt_long(argc, argv, "i:o:m:vh", opts, &idx)) != -1) {
        switch (c) {
        case 'v':
            print_version(argv[0]);
            break;
        case 'h':
            print_help(argv[0]);
            break;
        case 'i': {
            strncpy(params->in, optarg, sizeof(params->in));
            break;   
        }
        case 'o':
            strncpy(params->out, optarg, sizeof(params->out));
            break;
        case 'm':
            if (strcmp(optarg, INTERPRETER_LEX_STR) == 0) {
                params->mode = INTERPRETER_LEX;
            } else if (strcmp(optarg, INTERPRETER_PARSE_STR) == 0) {
                params->mode = INTERPRETER_PARSE;
            } else if (strcmp(optarg, INTERPRETER_BC_STR) == 0) {
                params->mode = INTERPRETER_BC;
            } else if (strcmp(optarg, INTERPRETER_INTERPRET_STR) == 0) {
                params->mode = INTERPRETER_INTERPRET;
            } else if (strcmp(optarg, INTERPRETER_TRACE_STR) == 0) {
                params->mode = INTERPRETER_TRACE;
            } else {
                fprintf(stderr, "Invalid interpreter mode \"%s\"", optarg);
                exit(EXIT_FAILURE);
            }
            break;
        case 0: {
            if (strcmp(STACKSIZE_STR, opts[idx].name) == 0) {
                params->stacksize = atoll(optarg);
            } else if (strcmp(HEAPSIZE_STR, opts[idx].name) == 0) {
                params->heapsize = atoll(optarg);
            }
        }
        default:
            /* do nothing. */
            break;
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, %r15
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x13e04(%rip), %rsi     # 0x17cd0
leaq 0x10(%rsp), %r12
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
callq 0x1120
movb $0x0, (%r15)
movl $0x400, %r14d           # imm = 0x400
leaq (%r15,%r14), %rdi
leaq 0xb156(%rip), %rsi      # 0xf049
movl $0x400, %edx            # imm = 0x400
movq %rdi, 0x8(%rsp)
callq 0x1040
movl $0x3, 0x800(%r15)
movq %r14, 0x808(%r15)
movq %r15, %r13
movq $0x100000, 0x810(%r15) # imm = 0x100000
movq %r12, %r15
leaq 0x4(%rsp), %r12
leaq 0xb0d3(%rip), %r14      # 0xf004
movl %ebp, %edi
movq %rbx, %rsi
leaq 0xb113(%rip), %rdx      # 0xf050
movq %r15, %rcx
movq %r12, %r8
callq 0x1090
cmpl $0x67, %eax
jle 0x3f7b
leal -0x68(%rax), %ecx
cmpl $0x7, %ecx
ja 0x40d0
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x14067(%rip), %rax     # 0x17fd0
movq (%rax), %rsi
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
callq 0x1040
jmp 0x3f31
testl %eax, %eax
jne 0x4090
movslq 0x4(%rsp), %rax
shlq $0x5, %rax
movq 0x10(%rsp,%rax), %r15
leaq 0xb09e(%rip), %rdi      # 0xf036
movq %r15, %rsi
callq 0x10f0
testl %eax, %eax
je 0x40b0
leaq 0xb091(%rip), %rdi      # 0xf040
movq %r15, %rsi
callq 0x10f0
testl %eax, %eax
leaq 0x10(%rsp), %r15
jne 0x3f31
movq 0x14005(%rip), %rax     # 0x17fd0
movq (%rax), %rdi
callq 0x10e0
movq %rax, 0x810(%r13)
jmp 0x3f31
movq 0x13fea(%rip), %rax     # 0x17fd0
movq (%rax), %r15
movq %r15, %rdi
leaq 0xb066(%rip), %rsi      # 0xf059
callq 0x10f0
testl %eax, %eax
je 0x409b
movq %r15, %rdi
leaq 0xb053(%rip), %rsi      # 0xf05d
callq 0x10f0
testl %eax, %eax
je 0x40db
cmpb $0x62, (%r15)
jne 0x402f
cmpb $0x63, 0x1(%r15)
jne 0x402f
cmpb $0x0, 0x2(%r15)
je 0x4105
movq %r15, %rdi
leaq 0xb02a(%rip), %rsi      # 0xf063
callq 0x10f0
testl %eax, %eax
je 0x40f0
movq %r15, %rdi
leaq 0xb01c(%rip), %rsi      # 0xf06c
callq 0x10f0
testl %eax, %eax
jne 0x413e
movl $0x4, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f31
movq 0x13f57(%rip), %rax     # 0x17fd0
movq (%rax), %rsi
movl $0x400, %edx            # imm = 0x400
movq 0x8(%rsp), %rdi
callq 0x1040
jmp 0x3f31
cmpl $-0x1, %eax
jne 0x3f31
jmp 0x411a
movl $0x0, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f31
movq 0x13f19(%rip), %rax     # 0x17fd0
movq (%rax), %rdi
callq 0x10e0
movq %rax, 0x808(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f31
cmpl $0x76, %eax
jne 0x3f31
jmp 0x4136
movl $0x1, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f31
movl $0x3, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f31
movl $0x2, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f31
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x11d4
movq %rbx, %rdi
callq 0x133d
movq %r15, %rdi
callq 0x11b0