// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x101e5(%rip), %r15     # 0x25fd8
leaq 0x5579(%rip), %rsi      # 0x1b373
movl $0x14, %edx
movq %r15, %rdi
callq 0x5300
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x5260
movsbl %al, %esi
movq %r15, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x51a0
testq %r14, %r14
je 0x1602c
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movl $0x4, %esi
callq 0x10346
movq %rax, %r12
movl $0x28, %edi
callq 0x5290
movq %rax, %r15
leaq 0x541f(%rip), %rsi      # 0x1b27e
movq %rax, %rdi
callq 0xfc44
movq %r12, %rdi
movq %r15, %rsi
callq 0xf294
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movl $0x3, %esi
callq 0x10346
movq %rax, %r12
movl $0x28, %edi
callq 0x5290
movq %rax, %r15
leaq 0x53f0(%rip), %rsi      # 0x1b28a
movq %rax, %rdi
callq 0xfc44
movq %r12, %rdi
movq %r15, %rsi
callq 0xf294
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movl $0x3, %esi
callq 0x10346
movq %rax, %r12
movl $0x28, %edi
callq 0x5290
movq %rax, %r15
leaq 0x54b3(%rip), %rsi      # 0x1b388
movq %rax, %rdi
callq 0xfc44
movq %r12, %rdi
movq %r15, %rsi
callq 0xf294
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
movq %rax, 0x20(%rbx)
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *(%rax)
movq 0x18(%rbx), %r14
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5260
movsbl %al, %esi
movq %r14, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x51a0
movq 0x18(%rbx), %r14
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5260
movsbl %al, %esi
movq %r14, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x51a0
movq 0x18(%rbx), %r14
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5260
movsbl %al, %esi
movq %r14, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x51a0
movq 0x18(%rbx), %r14
leaq 0x5407(%rip), %rsi      # 0x1b394
movl $0x2b, %edx
movq %r14, %rdi
callq 0x5300
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5260
movsbl %al, %esi
movq %r14, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x51a0
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rsi
movq (%rax), %rdi
callq 0x102e6
movq 0x10000(%rip), %r14     # 0x25fd8
leaq 0x53e1(%rip), %rsi      # 0x1b3c0
movl $0x8, %edx
movq %r14, %rdi
callq 0x5300
movl 0x8(%rbx), %esi
movq %r14, %rdi
callq 0x5460
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x5260
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x51a0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x1603c
jmp 0x1603c
movq %rax, %rbx
movl $0x28, %esi
movq %r15, %rdi
callq 0x52a0
movq %rbx, %rdi
callq 0x5470