// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0xa880
callq 0x21500
movq %rax, -0x78(%rbp)
movl $0x38, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
callq 0x248c0
jmp 0xa972
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x21570
movl %eax, -0x14(%rbp)
callq 0x21500
movq %rax, -0x88(%rbp)
movl $0x38, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
callq 0x2a500
jmp 0xa9a9
movq -0x80(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x21570
movl %eax, -0x28(%rbp)
callq 0x21500
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x215b0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
movq 0x50(%rax), %rax
callq *%rax
movq %rax, -0x90(%rbp)
jmp 0xa9e6
movq -0x90(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movl (%rax), %esi
movq (%rdi), %rax
movq 0x28(%rax), %rax
callq *%rax
jmp 0xaa06
jmp 0xab30
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x62f0
jmp 0xad8c
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x62f0
jmp 0xad8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x94(%rbp)
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0xaaac
movq -0x20(%rbp), %rdi
callq 0x6110
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
movq 0x3f551(%rip), %rdi     # 0x49fd0
callq 0x62c0
movq %rax, -0xa0(%rbp)
jmp 0xaa8d
movq -0xa0(%rbp), %rdi
movq 0x3f515(%rip), %rsi     # 0x49fb0
callq 0x6320
jmp 0xaaa2
movl $0x1, %edi
callq 0x63d0
movl -0x94(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xad8c
movq -0x20(%rbp), %rdi
callq 0x6110
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %esi
movq 0x3f4f9(%rip), %rdi     # 0x49fd0
callq 0x64e0
movq %rax, -0xa8(%rbp)
jmp 0xaae5
movq -0xa8(%rbp), %rdi
movq 0x3f4bd(%rip), %rsi     # 0x49fb0
callq 0x6320
jmp 0xaafa
movl $0x1, %edi
callq 0x63d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x64c0
jmp 0xad8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x64c0
jmp 0xad8c
cmpl $0x2, -0x8(%rbp)
jne 0xad60
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xf280
movq %rax, -0x50(%rbp)
movl $0xa0, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
movq -0x50(%rbp), %rsi
callq 0x10580
jmp 0xab6d
movq -0xb0(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x58, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq -0x58(%rbp), %rsi
callq 0x16f20
jmp 0xab9a
movq -0xb8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x1, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
callq 0x20250
jmp 0xabc3
movq -0xc0(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x10, %edi
callq 0x62e0
movq %rax, -0x68(%rbp)
movl $0x8, %edi
callq 0x62e0
movq %rax, -0xd0(%rbp)
movl $0x38, %edi
callq 0x62e0
movq %rax, -0xc8(%rbp)
jmp 0xac04
movq -0xc8(%rbp), %rdi
callq 0x1c2d0
jmp 0xac12
movq -0xc8(%rbp), %rsi
movq -0xd0(%rbp), %rdi
callq 0xafe0
jmp 0xac27
movq -0xd0(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xb010
movq %rax, %rdi
xorl %esi, %esi
callq 0x1c3c0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x48(%rax)
movl $0x40, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xd8(%rbp)
movq -0x68(%rbp), %rsi
callq 0x2df10
jmp 0xac7a
movq -0xd8(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x60(%rbp), %rdi
callq 0x16e70
xorl %eax, %eax
addq $0xe0, %rsp
popq %rbp
retq
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0xa0, %esi
callq 0x62f0
jmp 0xad8c
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x58, %esi
callq 0x62f0
jmp 0xad8c
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x1, %esi
callq 0x62f0
jmp 0xad8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xad2e
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x62f0
movq -0xd0(%rbp), %rdi
movl $0x8, %esi
callq 0x62f0
jmp 0xad8c
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x40, %esi
callq 0x62f0
jmp 0xad8c
movq 0x3f269(%rip), %rdi     # 0x49fd0
leaq 0x293f0(%rip), %rsi     # 0x3415e
callq 0x62c0
movq %rax, %rdi
movq 0x3f233(%rip), %rsi     # 0x49fb0
callq 0x6320
movl $0x1, %edi
callq 0x63d0
movq -0x20(%rbp), %rdi
callq 0x64f0
nopw %cs:(%rax,%rax)
nop