// File: kelwinfc[P]ci4721-Fernandez-Gyomrey/src/main.cpp
// Function: main
int main (int argc,char **argv)
{
    main_args args;
    main_read_args(argc, argv, stdin, args);

    logger = new llog();
    AST *ast = main_ast_create(args);
    
    string_table* strings = main_ast_check(ast);
    
    if (args.to_separate_archives) {
        main_redirect_stdout("bla.types");
    }
    types.dump(cout);
    cout << "-------------------------------------------------------" << endl << endl;
    if (args.to_separate_archives) {
        main_redirect_stdout("bla.strings");
    }
    strings->dump(cout);
    cout << "-------------------------------------------------------" << endl << endl;
    
    if (args.ast) {
        if (args.to_separate_archives) {
            main_redirect_stdout("bla.ast");
        }
        ast->dump(cout, 0);

        if (!args.to_separate_archives) {
            cout << "-------------------------------------------------------" << endl << endl;
        }
    }
    
    if ( logger->exists_registered_error() ){
        logger->dump(cerr);
        cerr << "-------------------------------------------------------" << endl << endl;
        cerr << "Epic fail!" << endl;
        abort();
        return 1;
    }
    
    Tac* tac = main_tac_create(args, ast);

    main_tac_optimize(tac);

    main_tac_dump(args, tac);

    Spim* spim = main_spim_create(tac);

    main_spim_dump(spim);

    main_redirect_stdout();
    cout << "Like a boss!" << endl;

    return 0;
}

// Assembly:
subq $0x88, %rsp
movl $0x0, 0x84(%rsp)
movl %edi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl 0x80(%rsp), %edi
movq 0x78(%rsp), %rsi
movq 0x22b87(%rip), %rax     # 0x6dfb8
movq (%rax), %rdx
leaq 0x68(%rsp), %rcx
callq 0x4b710
movl $0x1c0, %edi            # imm = 0x1C0
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, (%rsp)
callq 0x2f030
jmp 0x4b459
movq (%rsp), %rax
movq %rax, 0x23074(%rip)     # 0x6e4d8
movq 0x68(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x4ba80
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
callq 0x4bb30
movq %rax, 0x38(%rsp)
testb $0x1, 0x69(%rsp)
je 0x4b4d1
leaq 0xc796(%rip), %rdi      # 0x57c3f
callq 0x4bc20
jmp 0x4b4d1
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x63a0
jmp 0x4b6fb
leaq 0x23008(%rip), %rdi     # 0x6e4e0
movq 0x22ae1(%rip), %rsi     # 0x6dfc0
callq 0x2dd20
movq 0x22ad5(%rip), %rdi     # 0x6dfc0
leaq 0xc757(%rip), %rsi      # 0x57c49
callq 0x6370
movq %rax, %rdi
movq 0x22a97(%rip), %rsi     # 0x6df98
callq 0x63d0
movq %rax, %rdi
movq 0x22a88(%rip), %rsi     # 0x6df98
callq 0x63d0
testb $0x1, 0x69(%rsp)
je 0x4b528
leaq 0xc75e(%rip), %rdi      # 0x57c81
callq 0x4bc20
movq 0x38(%rsp), %rdi
movq 0x22a8c(%rip), %rsi     # 0x6dfc0
callq 0x3efa0
movq 0x22a80(%rip), %rdi     # 0x6dfc0
leaq 0xc702(%rip), %rsi      # 0x57c49
callq 0x6370
movq %rax, %rdi
movq 0x22a42(%rip), %rsi     # 0x6df98
callq 0x63d0
movq %rax, %rdi
movq 0x22a33(%rip), %rsi     # 0x6df98
callq 0x63d0
testb $0x1, 0x6a(%rsp)
je 0x4b5d1
testb $0x1, 0x69(%rsp)
je 0x4b584
leaq 0xc70e(%rip), %rdi      # 0x57c8d
callq 0x4bc20
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
movq 0x22a2d(%rip), %rsi     # 0x6dfc0
xorl %edx, %edx
callq *(%rax)
testb $0x1, 0x69(%rsp)
jne 0x4b5cf
movq 0x22a1b(%rip), %rdi     # 0x6dfc0
leaq 0xc69d(%rip), %rsi      # 0x57c49
callq 0x6370
movq %rax, %rdi
movq 0x229dd(%rip), %rsi     # 0x6df98
callq 0x63d0
movq %rax, %rdi
movq 0x229ce(%rip), %rsi     # 0x6df98
callq 0x63d0
jmp 0x4b5d1
movq 0x22f00(%rip), %rdi     # 0x6e4d8
callq 0x2f750
testb $0x1, %al
jne 0x4b5e3
jmp 0x4b64e
movq 0x22eee(%rip), %rdi     # 0x6e4d8
movq 0x229ff(%rip), %rsi     # 0x6dff0
callq 0x2f760
movq 0x229f3(%rip), %rdi     # 0x6dff0
leaq 0xc645(%rip), %rsi      # 0x57c49
callq 0x6370
movq %rax, %rdi
movq 0x22985(%rip), %rsi     # 0x6df98
callq 0x63d0
movq %rax, %rdi
movq 0x22976(%rip), %rsi     # 0x6df98
callq 0x63d0
movq 0x229c2(%rip), %rdi     # 0x6dff0
leaq 0xc660(%rip), %rsi      # 0x57c95
callq 0x6370
movq %rax, %rdi
movq 0x22954(%rip), %rsi     # 0x6df98
callq 0x63d0
callq 0x61f0
movq 0x68(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rdx
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x4bdd0
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
callq 0x4be70
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4be90
movq 0x30(%rsp), %rdi
callq 0x4bfa0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
callq 0x4bfb0
xorl %eax, %eax
movl %eax, %edi
callq 0x4bc20
movq 0x228ea(%rip), %rdi     # 0x6dfc0
leaq 0xc5c3(%rip), %rsi      # 0x57ca0
callq 0x6370
movq %rax, %rdi
movq 0x228ac(%rip), %rsi     # 0x6df98
callq 0x63d0
xorl %eax, %eax
addq $0x88, %rsp
retq
movq 0x60(%rsp), %rdi
callq 0x66b0
nopw %cs:(%rax,%rax)