// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x120(%rbp), %rdi
leaq 0x1da2c(%rip), %rsi     # 0x1ecd0
movl $0x100, %edx            # imm = 0x100
callq 0x1120
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rdi
addq $0x400, %rdi            # imm = 0x400
leaq 0x16d62(%rip), %rsi     # 0x18029
movl $0x400, %edx            # imm = 0x400
callq 0x1040
movq -0x18(%rbp), %rax
movl $0x3, 0x800(%rax)
movq -0x18(%rbp), %rax
movq $0x400, 0x808(%rax) # imm = 0x400
movq -0x18(%rbp), %rax
movq $0x100000, 0x810(%rax) # imm = 0x100000
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x120(%rbp), %rcx
leaq 0x16d1e(%rip), %rdx     # 0x18030
leaq -0x128(%rbp), %r8
callq 0x1080
movl %eax, -0x124(%rbp)
cmpl $-0x1, %eax
je 0x15a1
movl -0x124(%rbp), %eax
movl %eax, -0x12c(%rbp)
testl %eax, %eax
je 0x1508
jmp 0x1343
movl -0x12c(%rbp), %eax
subl $0x68, %eax
je 0x139d
jmp 0x1350
movl -0x12c(%rbp), %eax
subl $0x69, %eax
je 0x13ae
jmp 0x135d
movl -0x12c(%rbp), %eax
subl $0x6d, %eax
je 0x13ef
jmp 0x136e
movl -0x12c(%rbp), %eax
subl $0x6f, %eax
je 0x13cb
jmp 0x137b
movl -0x12c(%rbp), %eax
subl $0x76, %eax
jne 0x159a
jmp 0x138c
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x15b0
jmp 0x159c
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x16a0
jmp 0x159c
movq -0x18(%rbp), %rdi
movq 0x1dc17(%rip), %rax     # 0x1efd0
movq (%rax), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x1040
jmp 0x159c
movq -0x18(%rbp), %rdi
addq $0x400, %rdi            # imm = 0x400
movq 0x1dbf3(%rip), %rax     # 0x1efd0
movq (%rax), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x1040
jmp 0x159c
movq 0x1dbda(%rip), %rax     # 0x1efd0
movq (%rax), %rdi
leaq 0x16c39(%rip), %rsi     # 0x18039
callq 0x10f0
cmpl $0x0, %eax
jne 0x141d
movq -0x18(%rbp), %rax
movl $0x0, 0x800(%rax)
jmp 0x1503
movq 0x1dbac(%rip), %rax     # 0x1efd0
movq (%rax), %rdi
leaq 0x16c0f(%rip), %rsi     # 0x1803d
callq 0x10f0
cmpl $0x0, %eax
jne 0x144b
movq -0x18(%rbp), %rax
movl $0x1, 0x800(%rax)
jmp 0x1501
movq 0x1db7e(%rip), %rax     # 0x1efd0
movq (%rax), %rdi
leaq 0x16be7(%rip), %rsi     # 0x18043
callq 0x10f0
cmpl $0x0, %eax
jne 0x1479
movq -0x18(%rbp), %rax
movl $0x2, 0x800(%rax)
jmp 0x14ff
movq 0x1db50(%rip), %rax     # 0x1efd0
movq (%rax), %rdi
leaq 0x16bbc(%rip), %rsi     # 0x18046
callq 0x10f0
cmpl $0x0, %eax
jne 0x14a4
movq -0x18(%rbp), %rax
movl $0x3, 0x800(%rax)
jmp 0x14fd
movq 0x1db25(%rip), %rax     # 0x1efd0
movq (%rax), %rdi
leaq 0x16b9a(%rip), %rsi     # 0x1804f
callq 0x10f0
cmpl $0x0, %eax
jne 0x14cf
movq -0x18(%rbp), %rax
movl $0x4, 0x800(%rax)
jmp 0x14fb
movq 0x1db1a(%rip), %rax     # 0x1eff0
movq (%rax), %rdi
movq 0x1daf0(%rip), %rax     # 0x1efd0
movq (%rax), %rdx
leaq 0x16b6b(%rip), %rsi     # 0x18055
movb $0x0, %al
callq 0x1100
movl $0x1, %edi
callq 0x1170
jmp 0x14fd
jmp 0x14ff
jmp 0x1501
jmp 0x1503
jmp 0x159c
movslq -0x128(%rbp), %rcx
leaq -0x120(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
leaq 0x16aef(%rip), %rdi     # 0x18016
callq 0x10f0
cmpl $0x0, %eax
jne 0x1550
movq 0x1da98(%rip), %rax     # 0x1efd0
movq (%rax), %rdi
callq 0x10e0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x808(%rax)
jmp 0x1598
movslq -0x128(%rbp), %rcx
leaq -0x120(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
leaq 0x16ab1(%rip), %rdi     # 0x18020
callq 0x10f0
cmpl $0x0, %eax
jne 0x1596
movq 0x1da50(%rip), %rax     # 0x1efd0
movq (%rax), %rdi
callq 0x10e0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x810(%rax)
jmp 0x1598
jmp 0x159a
jmp 0x159c
jmp 0x12fd
xorl %eax, %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax)