// File: /workspace/github_cpp_makefile_star2_O3/Davidc2525[P]Leaf/main.cpp
// Function: main
int main(int argc, char **argv)
{

    //prepare default global configuration
    prepare_default_conf();

    /*if(argc<2){ 
        log("falta el archivo de programa",1)
    }
    string filename(args[1]);
    Scanner * s = new Scanner((const unsigned char *)filename.c_str(),filename.length());
    Parser * p = new Parser(s);
    p->Parse();*/

    int x86_64_registers = RegisterManager::getInstance()->addProvider(
        new X86_64RegisterProvider());
    int x86_32_registers = RegisterManager::getInstance()->addProvider(
        new X86_32RegisterProvider());

    RegisterProvider *rp = RegisterManager::getInstance()->getProvider(x86_64_registers);
    try
    {
        Register *r = rp->reserve();
        rp->free(r->id);
    }
    catch (const char *ex)
    {
        cout << ex << endl;
        exit(1);
    }
    catch (int ex)
    {
        cout << ex << endl;
        exit(1);
    }
    if (argc == 2)
    {
        wchar_t *fileName = coco_string_create(argv[1]);
        Scanner *scanner = new Scanner(fileName);
        Parser *parser = new Parser(scanner);
        parser->tab = new symbol_table();
        //parser->ss = new ExternSymbols();
        //parser->sl = new StringLiterals();
        ast_visitor_args *args = new ast_visitor_args;
        args->ass = new Assembly(new Program());
        //args->outfile = new string("tmp_pro_leaf_asm.asm");

        parser->data_section = args->ass->get_program()->section(Sections::data);
        parser->visitor_generator =
            new x86_64_linux_generator_visitor(args);

        try
        {
            //parser->ast_h = ThreeFactory::getInstance()->getAstHandler(handler);
        }
        catch (char const *ex)
        {
            cout << "Exception: " << ex << endl;
            exit(1);
        }

        parser->Parse();
        //test
        //cout<<*label_of_function(symbol_table::find(new string("david")))<<endl;
        //cout<<*label_of_function(symbol_table::find(new string("main")))<<endl;
        //test
        return 0;
        if (parser->errors->count == 0)
        {
        }
        else
        {
            dlog(" errores: " + to_string(parser->errors->count), 1)
        }

        coco_string_delete(fileName);

        delete parser;
        delete scanner;
    }
    else
        clog("-- No source file specified", 1) return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movl %edi, %ebp
callq 0x7a33
callq 0x11a82
movq %rax, %r15
movl $0x38, %edi
callq 0x5290
movq %rax, %r14
movq %rax, %rdi
callq 0x1276a
movq %r15, %rdi
movq %r14, %rsi
callq 0x11aa0
movl %eax, %r14d
callq 0x11a82
movq %rax, %r12
movl $0x38, %edi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
callq 0x14576
movq %r12, %rdi
movq %r15, %rsi
callq 0x11aa0
callq 0x11a82
movq %rax, %rdi
movl %r14d, %esi
callq 0x11ab2
movq %rax, %r14
movq (%rax), %rax
movq %r14, %rdi
callq *0x50(%rax)
movl (%rax), %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
cmpl $0x2, %ebp
jne 0x7c79
movq 0x8(%rbx), %rdi
callq 0x9511
movq %rax, %rbx
movl $0xa0, %edi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0xa50e
movl $0x58, %edi
callq 0x5290
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0xe8c8
movl $0x1, %edi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
callq 0x11266
movq %r15, 0x38(%r14)
movl $0x10, %edi
callq 0x5290
movq %rax, %rbx
movl $0x8, %edi
callq 0x5290
movq %rax, %r15
movl $0x38, %edi
callq 0x5290
movq %rax, %r12
movq %rax, %rdi
callq 0x102be
movq %r12, (%r15)
movq %r15, 0x8(%rbx)
movq %r12, %rdi
xorl %esi, %esi
callq 0x10346
movq %rax, 0x48(%r14)
movl $0x40, %edi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x15d38
movq %r15, 0x50(%r14)
movq %r14, %rdi
callq 0xe84e
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x1e358(%rip), %rdi     # 0x25fd8
leaq 0x114c3(%rip), %rsi     # 0x1914a
callq 0x5270
movq %rax, %rdi
callq 0x5130
jmp 0x7d4e
movq %rax, %rbx
movl $0x40, %esi
jmp 0x7ce5
movq %rax, %rbx
movl $0x38, %esi
movq %r12, %rdi
callq 0x52a0
jmp 0x7cb8
movq %rax, %rbx
movl $0x8, %esi
jmp 0x7ce5
movq %rax, %rbx
movl $0x1, %esi
jmp 0x7ce5
movq %rax, %rbx
movl $0x58, %esi
jmp 0x7cf2
movq %rax, %rbx
movl $0xa0, %esi
jmp 0x7ce5
movq %rax, %rbx
movl $0x38, %esi
movq %r15, %rdi
jmp 0x7cf5
movq %rax, %rbx
movl $0x38, %esi
movq %r14, %rdi
callq 0x52a0
movq %rbx, %rdi
callq 0x5470
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x7d2b
movq %rbx, %rdi
callq 0x5110
movq 0x1e2bf(%rip), %rdi     # 0x25fd8
movq %rax, %rsi
callq 0x5270
movq %rax, %rdi
callq 0x5130
jmp 0x7d4e
cmpl $0x1, %edx
jne 0x7cfa
movq %rbx, %rdi
callq 0x5110
movl (%rax), %esi
movq 0x1e297(%rip), %rdi     # 0x25fd8
callq 0x5460
movq %rax, %rdi
callq 0x5130
movl $0x1, %edi
callq 0x5340
jmp 0x7d5a
movq %rax, %rbx
callq 0x5430
jmp 0x7cfa