// File: /workspace/github_cpp_makefile_star2_O2/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 0x6df1
callq 0xfafc
movq %rax, %r15
pushq $0x38
popq %rdi
callq 0x5260
movq %rax, %r14
movq %rax, %rdi
callq 0x107ee
movq %r15, %rdi
movq %r14, %rsi
callq 0xfb3e
movl %eax, %r14d
callq 0xfafc
movq %rax, %r12
pushq $0x38
popq %rdi
callq 0x5260
movq %rax, %r15
movq %rax, %rdi
callq 0x1229e
movq %r12, %rdi
movq %r15, %rsi
callq 0xfb3e
callq 0xfafc
movq %rax, %rdi
movl %r14d, %esi
callq 0xfb50
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 0x6fd7
movq 0x8(%rbx), %rdi
callq 0x880e
movq %rax, %rbx
movl $0xa0, %edi
callq 0x5260
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x92ee
pushq $0x58
popq %rdi
callq 0x5260
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0xccee
pushq $0x1
popq %rdi
callq 0x5260
movq %rax, %r15
movq %rax, %rdi
callq 0xf496
movq %r15, 0x38(%r14)
pushq $0x10
popq %rdi
callq 0x5260
movq %rax, %rbx
pushq $0x8
popq %rdi
callq 0x5260
movq %rax, %r15
pushq $0x38
popq %rdi
callq 0x5260
movq %rax, %r12
movq %rax, %rdi
callq 0xe5ae
movq %r12, (%r15)
movq %r15, 0x8(%rbx)
movq %r12, %rdi
xorl %esi, %esi
callq 0xe61c
movq %rax, 0x48(%r14)
pushq $0x40
popq %rdi
callq 0x5260
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1359c
movq %r15, 0x50(%r14)
movq %r14, %rdi
callq 0xcc7c
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x1dff2(%rip), %rdi     # 0x24fd0
leaq 0xf179(%rip), %rsi      # 0x1615e
callq 0x5240
movq %rax, %rdi
callq 0x5120
jmp 0x709a
movq %rax, %rbx
pushq $0x40
jmp 0x7032
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r12, %rdi
callq 0x5270
jmp 0x7011
movq %rax, %rbx
pushq $0x8
jmp 0x7032
movq %rax, %rbx
pushq $0x1
jmp 0x7032
movq %rax, %rbx
pushq $0x58
jmp 0x703d
movq %rax, %rbx
movl $0xa0, %esi
jmp 0x7033
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r15, %rdi
jmp 0x7041
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x5270
movq %rbx, %rdi
callq 0x5420
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x7077
movq %rbx, %rdi
callq 0x50f0
movq 0x1df6b(%rip), %rdi     # 0x24fd0
movq %rax, %rsi
callq 0x5240
movq %rax, %rdi
callq 0x5120
jmp 0x709a
cmpl $0x1, %edx
jne 0x7046
movq %rbx, %rdi
callq 0x50f0
movl (%rax), %esi
movq 0x1df43(%rip), %rdi     # 0x24fd0
callq 0x5410
movq %rax, %rdi
callq 0x5120
pushq $0x1
popq %rdi
callq 0x5300
jmp 0x70a4
movq %rax, %rbx
callq 0x53f0
jmp 0x7046