// File: /workspace/github_c_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movq %rdx, %r15
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x14a14(%rip), %rsi     # 0x15cd0
leaq 0x20(%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 0xcd66(%rip), %rsi      # 0xe049
movl $0x400, %edx            # imm = 0x400
movq %rdi, 0x18(%rsp)
callq 0x1040
movl $0x3, 0x800(%r15)
movq %r14, 0x808(%r15)
movq %r15, 0x8(%rsp)
movq $0x100000, 0x810(%r15) # imm = 0x100000
movq %r12, %r15
leaq 0xcd32(%rip), %r13      # 0xe050
leaq 0x14(%rsp), %r12
leaq 0xccda(%rip), %r14      # 0xe004
movl %ebp, %edi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1090
leal -0x68(%rax), %ecx
cmpl $0x7, %ecx
ja 0x1369
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x14c7b(%rip), %rax     # 0x15fd0
movq (%rax), %rsi
movl $0x400, %edx            # imm = 0x400
movq 0x8(%rsp), %rdi
callq 0x1040
jmp 0x132a
testl %eax, %eax
je 0x1439
cmpl $-0x1, %eax
je 0x151c
cmpl $0x76, %eax
jne 0x132a
jmp 0x1689
movq 0x14c45(%rip), %rax     # 0x15fd0
movq (%rax), %r15
movq %r15, %rdi
leaq 0xccc1(%rip), %rsi      # 0xe059
callq 0x10f0
testl %eax, %eax
je 0x1496
movq %r15, %rdi
leaq 0xccae(%rip), %rsi      # 0xe05d
callq 0x10f0
testl %eax, %eax
je 0x14d1
cmpb $0x62, (%r15)
jne 0x13d4
cmpb $0x63, 0x1(%r15)
jne 0x13d4
cmpb $0x0, 0x2(%r15)
je 0x1503
movq %r15, %rdi
leaq 0xcc85(%rip), %rsi      # 0xe063
callq 0x10f0
testl %eax, %eax
je 0x14ea
movq %r15, %rdi
leaq 0xcc77(%rip), %rsi      # 0xe06c
callq 0x10f0
testl %eax, %eax
jne 0x1756
movq 0x8(%rsp), %rax
movl $0x4, 0x800(%rax)
leaq 0x20(%rsp), %r15
jmp 0x132a
movq 0x14bae(%rip), %rax     # 0x15fd0
movq (%rax), %rsi
movl $0x400, %edx            # imm = 0x400
movq 0x18(%rsp), %rdi
callq 0x1040
jmp 0x132a
movslq 0x14(%rsp), %rax
shlq $0x5, %rax
movq 0x20(%rsp,%rax), %r15
leaq 0xcbe8(%rip), %rdi      # 0xe036
movq %r15, %rsi
callq 0x10f0
testl %eax, %eax
je 0x14ac
leaq 0xcbdf(%rip), %rdi      # 0xe040
movq %r15, %rsi
callq 0x10f0
testl %eax, %eax
leaq 0x20(%rsp), %r15
jne 0x132a
movq 0x14b53(%rip), %rax     # 0x15fd0
movq (%rax), %rdi
callq 0x10e0
movq 0x8(%rsp), %rcx
movq %rax, 0x810(%rcx)
jmp 0x132a
movq 0x8(%rsp), %rax
andl $0x0, 0x800(%rax)
leaq 0x20(%rsp), %r15
jmp 0x132a
movq 0x14b1d(%rip), %rax     # 0x15fd0
movq (%rax), %rdi
callq 0x10e0
movq 0x8(%rsp), %rcx
movq %rax, 0x808(%rcx)
leaq 0x20(%rsp), %r15
jmp 0x132a
movq 0x8(%rsp), %rax
movl $0x1, 0x800(%rax)
leaq 0x20(%rsp), %r15
jmp 0x132a
movq 0x8(%rsp), %rax
movl $0x3, 0x800(%rax)
leaq 0x20(%rsp), %r15
jmp 0x132a
movq 0x8(%rsp), %rax
movl $0x2, 0x800(%rax)
leaq 0x20(%rsp), %r15
jmp 0x132a
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdx
movq 0x14ab6(%rip), %r15     # 0x15ff0
movq (%r15), %rdi
leaq 0xcc56(%rip), %rsi      # 0xe19a
xorl %eax, %eax
callq 0x1100
movq (%r15), %rcx
leaq 0xcc63(%rip), %rdi      # 0xe1b8
pushq $0x9
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc55(%rip), %rdi      # 0xe1c2
pushq $0x11
popq %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc4e(%rip), %rdi      # 0xe1d4
pushq $0x20
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc5a(%rip), %rdi      # 0xe1f5
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc57(%rip), %rdi      # 0xe207
pushq $0x22
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc65(%rip), %rdi      # 0xe22a
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc62(%rip), %rdi      # 0xe23c
pushq $0x28
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc76(%rip), %rdi      # 0xe265
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc73(%rip), %rdi      # 0xe277
pushq $0x43
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcca2(%rip), %rdi      # 0xe2bb
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcc9f(%rip), %rdi      # 0xe2cd
pushq $0x46
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xccd1(%rip), %rdi      # 0xe314
pushq $0xe
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcccb(%rip), %rdi      # 0xe323
pushq $0x32
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcce9(%rip), %rdi      # 0xe356
pushq $0xd
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r15), %rcx
leaq 0xcce2(%rip), %rdi      # 0xe364
pushq $0x33
jmp 0x1746
movq (%rbx), %rdx
movq 0x1495d(%rip), %r14     # 0x15ff0
movq (%r14), %rdi
leaq 0xcfc2(%rip), %rsi      # 0xe65f
xorl %eax, %eax
callq 0x1100
movq (%r14), %rcx
leaq 0xc9f0(%rip), %rdi      # 0xe09e
pushq $0x9
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x1190
movq (%r14), %rcx
leaq 0xc9e2(%rip), %rdi      # 0xe0a8
pushq $0x58
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r14), %rcx
leaq 0xca26(%rip), %rdi      # 0xe101
pushq $0x4d
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r14), %rcx
leaq 0xca5f(%rip), %rdi      # 0xe14f
pushq $0xf
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r14), %rcx
leaq 0xca5a(%rip), %rdi      # 0xe15f
pushq $0xb
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r14), %rcx
leaq 0xca51(%rip), %rdi      # 0xe16b
pushq $0xc
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r14), %rcx
leaq 0xca49(%rip), %rdi      # 0xe178
pushq $0x18
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq (%r14), %rcx
leaq 0xca4d(%rip), %rdi      # 0xe191
pushq $0x8
popq %rsi
movq %rbx, %rdx
callq 0x1190
xorl %edi, %edi
callq 0x1180
movq 0x14893(%rip), %rax     # 0x15ff0
movq (%rax), %rdi
leaq 0xc90b(%rip), %rsi      # 0xe072
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
pushq $0x1
popq %rdi
callq 0x1180