// File: vssense[P]Compiler/src/front-end/front-end_main.cpp
// Function: main
int main(const int argc, const char* argv[])
{
    FrontEndInfo info = {};
    info.input_file = argv[1];

    info.parser_dump_required = (strcmp(argv[parser_dump_flag_offset], "1") == 0);
    info.tree_dump_required   = (strcmp(argv[tree_dump_flag_offset],   "1") == 0);
    info.emit_tree_requiered  = (strcmp(argv[emit_tree_flag_offset],   "1") == 0);
    info.emit_code_requiered  = (strcmp(argv[emit_code_flag_offset],   "1") == 0);

    if (argc - 1 > emit_code_flag_offset)
    {
        info.output_file = argv[emit_code_flag_offset + 1];
    }


    if (info.emit_code_requiered)
    {
        const char* output = "translated_program.shl";
        if (info.output_file != nullptr)
        {
            output = info.output_file;
        }

        Translate(info.input_file, output);
        return 0;
    }

    Parser* parser = Parse(info.input_file);
    if (info.parser_dump_required)
    {
        ParserDump(parser);
    }

    Tree* tree = GetTree(parser);
    if (info.tree_dump_required)
    {
        TreeDump(tree);
    }

    if (info.emit_tree_requiered)
    {
        const char* output = "tree_in_written_form.txt";
        WriteToFile(tree, info.output_file);
    }
    else
    {
        WriteToFile(tree, tree_tmp_file);
    }

    DestructTree(tree);
    DeleteTree(tree);

    DestructParser(parser);
    DeleteParser(parser);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
movb $0x0, -0x18(%rbp)
movb $0x0, -0x17(%rbp)
movb $0x0, -0x16(%rbp)
movb $0x0, -0x15(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x4d36(%rip), %rsi      # 0x7017
callq 0x2130
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x4d17(%rip), %rsi      # 0x7017
callq 0x2130
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x17(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x4cf8(%rip), %rsi      # 0x7017
callq 0x2130
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x16(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
leaq 0x4cd9(%rip), %rsi      # 0x7017
callq 0x2130
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x15(%rbp)
movl -0x8(%rbp), %eax
subl $0x1, %eax
cmpl $0x5, %eax
jle 0x2365
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
testb $0x1, -0x15(%rbp)
je 0x239e
leaq 0x4ca7(%rip), %rax      # 0x7019
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x2385
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5fd0
movl $0x0, -0x4(%rbp)
jmp 0x2431
movq -0x28(%rbp), %rdi
callq 0x3750
movq %rax, -0x38(%rbp)
testb $0x1, -0x18(%rbp)
je 0x23ba
movq -0x38(%rbp), %rdi
callq 0x3900
movq -0x38(%rbp), %rdi
callq 0x4510
movq %rax, -0x40(%rbp)
testb $0x1, -0x17(%rbp)
je 0x23d6
movq -0x40(%rbp), %rdi
callq 0x4020
testb $0x1, -0x16(%rbp)
je 0x23f6
leaq 0x4c4d(%rip), %rax      # 0x7030
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2440
jmp 0x2406
movq -0x40(%rbp), %rdi
movq 0x8cdf(%rip), %rsi      # 0xb0e0
callq 0x2440
movq -0x40(%rbp), %rdi
callq 0x4430
movq -0x40(%rbp), %rdi
callq 0x44c0
movq -0x38(%rbp), %rdi
callq 0x3800
movq -0x38(%rbp), %rdi
callq 0x38b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)