// File: Davidc2525[P]Leaf/compiler/backend/x86_64_linux/generator.cpp
// Function: x86_64_linux_generator_visitor::init(LEAF::AST::NODEU*)
void x86_64_linux_generator_visitor::init(ASTU start)
{
    cout << "x86_64 linux visitor" << endl;
    if (start == nullptr)
        return;
    assembly->get_program()->section(Sections::global)->add(new DInstruccion("global main"));
    assembly->get_program()->section(Sections::_extern)->add(new DInstruccion("extern printf"));
    assembly->get_program()->section(Sections::_extern)->add(new DInstruccion("extern puts"));

    reg = rp->reserve();
    start->accept(this);

    //3 espacio para firmar el archivo
    *out_file << endl;
    *out_file << endl;
    *out_file << endl;

    *out_file << "%include \"feactures/exceptions/linux64.asm\"" << endl;
    assembly->get_program()->write(*out_file);
    cout << "visits: " << visits_ins << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq 0x1bf91(%rip), %rdi     # 0x49fd0
leaq 0x80d2(%rip), %rsi      # 0x36118
callq 0x62c0
movq %rax, %rdi
movq 0x1bf5b(%rip), %rsi     # 0x49fb0
callq 0x6320
cmpq $0x0, -0x10(%rbp)
jne 0x2e066
jmp 0x2e219
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xb010
movq %rax, %rdi
movl $0x4, %esi
callq 0x1c3c0
movq %rax, -0x38(%rbp)
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x30(%rbp)
leaq 0x7f84(%rip), %rsi      # 0x36023
callq 0x1a4e0
jmp 0x2e0a6
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x18670
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xb010
movq %rax, %rdi
movl $0x3, %esi
callq 0x1c3c0
movq %rax, -0x48(%rbp)
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x40(%rbp)
leaq 0x7f43(%rip), %rsi      # 0x3602f
callq 0x1a4e0
jmp 0x2e0f3
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x18670
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xb010
movq %rax, %rdi
movl $0x3, %esi
callq 0x1c3c0
movq %rax, -0x58(%rbp)
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x50(%rbp)
leaq 0x7ff4(%rip), %rsi      # 0x3612d
callq 0x1a4e0
jmp 0x2e140
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x18670
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
movq -0x28(%rbp), %rsi
movq %rax, 0x20(%rsi)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movq 0x1be35(%rip), %rsi     # 0x49fb0
callq 0x6320
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movq 0x1be21(%rip), %rsi     # 0x49fb0
callq 0x6320
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movq 0x1be0d(%rip), %rsi     # 0x49fb0
callq 0x6320
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x7f82(%rip), %rsi      # 0x36139
callq 0x62c0
movq %rax, %rdi
movq 0x1bdea(%rip), %rsi     # 0x49fb0
callq 0x6320
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xb010
movq %rax, %rdi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x1c340
movq 0x1bde1(%rip), %rdi     # 0x49fd0
leaq 0x7f6f(%rip), %rsi      # 0x36165
callq 0x62c0
movq %rax, %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x64e0
movq %rax, %rdi
movq 0x1bd9c(%rip), %rsi     # 0x49fb0
callq 0x6320
addq $0x60, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x62f0
jmp 0x2e271
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x62f0
jmp 0x2e271
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x62f0
movq -0x18(%rbp), %rdi
callq 0x64f0
nopw (%rax,%rax)