// File: /workspace/github_c_makefile_star2_O1/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 0x13e24(%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 0xb176(%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 0xb0f3(%rip), %r14      # 0xf004
movl %ebp, %edi
movq %rbx, %rsi
leaq 0xb133(%rip), %rdx      # 0xf050
movq %r15, %rcx
movq %r12, %r8
callq 0x1090
cmpl $0x67, %eax
jle 0x3f5b
leal -0x68(%rax), %ecx
cmpl $0x7, %ecx
ja 0x40af
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x14087(%rip), %rax     # 0x17fd0
movq (%rax), %rsi
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
callq 0x1040
jmp 0x3f11
testl %eax, %eax
jne 0x406f
movslq 0x4(%rsp), %rax
shlq $0x5, %rax
movq 0x10(%rsp,%rax), %r15
leaq 0xb0be(%rip), %rdi      # 0xf036
movq %r15, %rsi
callq 0x10f0
testl %eax, %eax
je 0x408f
leaq 0xb0b1(%rip), %rdi      # 0xf040
movq %r15, %rsi
callq 0x10f0
testl %eax, %eax
leaq 0x10(%rsp), %r15
jne 0x3f11
movq 0x14025(%rip), %rax     # 0x17fd0
movq (%rax), %rdi
callq 0x10e0
movq %rax, 0x810(%r13)
jmp 0x3f11
movq 0x1400a(%rip), %rax     # 0x17fd0
movq (%rax), %r15
movq %r15, %rdi
leaq 0xb086(%rip), %rsi      # 0xf059
callq 0x10f0
testl %eax, %eax
je 0x407a
movq %r15, %rdi
leaq 0xb073(%rip), %rsi      # 0xf05d
callq 0x10f0
testl %eax, %eax
je 0x40ba
movq %r15, %rdi
leaq 0xb062(%rip), %rsi      # 0xf063
callq 0x10f0
testl %eax, %eax
je 0x40cf
movq %r15, %rdi
leaq 0xb04e(%rip), %rsi      # 0xf066
callq 0x10f0
testl %eax, %eax
je 0x40e4
movq %r15, %rdi
leaq 0xb040(%rip), %rsi      # 0xf06f
callq 0x10f0
testl %eax, %eax
jne 0x411d
movl $0x4, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f11
movq 0x13f78(%rip), %rax     # 0x17fd0
movq (%rax), %rsi
movl $0x400, %edx            # imm = 0x400
movq 0x8(%rsp), %rdi
callq 0x1040
jmp 0x3f11
cmpl $-0x1, %eax
jne 0x3f11
jmp 0x40f9
movl $0x0, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f11
movq 0x13f3a(%rip), %rax     # 0x17fd0
movq (%rax), %rdi
callq 0x10e0
movq %rax, 0x808(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f11
cmpl $0x76, %eax
jne 0x3f11
jmp 0x4115
movl $0x1, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f11
movl $0x2, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f11
movl $0x3, 0x800(%r13)
leaq 0x10(%rsp), %r15
jmp 0x3f11
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