// File: /workspace/github_cpp_makefile_star2_O2/kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST/to_tac.cpp
// Function: AST::to_tac()
Tac* AST::to_tac(){

    Tac *t = new Tac();

    AST_declaration* m = 0;
    uint nsize = declarations.size();
    
    queue<AST_declaration*> global_variables;
    
    for ( uint i = 0; i != nsize; i++){
        
        // El main se genera de ultimo
        if (   typeid(*declarations[i]) == typeid(AST_function)
            && ((AST_function*)declarations[i])->func->getName().compare("main") 
                    == 0)
        {
            m = declarations[i];
        }
        // La inicialización de variables se deja para antes del main
        else if ( typeid(*declarations[i]) != typeid(AST_function) ){
            global_variables.push(declarations[i]);
        }
        // Las demas funciones se generan de una vez
        else {
            declarations[i]->to_tac(t);
        }
    }
    
    first_instruction = t->next_instruction();
    
    while( !global_variables.empty() ){
        AST_declaration* d = global_variables.front();
        global_variables.pop();
        
        d->to_tac(t);
    }
    m->to_tac(t);

    return t;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
pushq $0x8
popq %rdi
callq 0x62d0
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x212a0
movq 0x18(%rbx), %rbp
subq 0x10(%rbx), %rbp
shrq $0x3, %rbp
leaq 0x18(%rsp), %rdi
callq 0x1258e
movq $0x0, 0x10(%rsp)
leaq 0x277d7(%rip), %r14     # 0x36f38
xorl %r13d, %r13d
cmpl %r13d, %ebp
je 0xf836
movl %r13d, %r12d
movq 0x10(%rbx), %rax
movq (%rax,%r12,8), %rax
testq %rax, %rax
je 0xf8a3
movq (%rax), %rax
movq -0x8(%rax), %rdi
movq %r14, %rsi
callq 0x1227e
testb %al, %al
je 0xf7d5
movq %rbx, %r15
movq 0x10(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x98(%rax), %rsi
leaq 0x68(%rsp), %rdi
callq 0x13efa
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
leaq 0x143ba(%rip), %rsi     # 0x23b79
callq 0x60d0
movq %rbx, %rdi
movl %eax, %ebx
callq 0x65c8
testl %ebx, %ebx
movq %r15, %rbx
je 0xf821
movq 0x10(%rbx), %rax
movq (%rax,%r12,8), %rax
testq %rax, %rax
je 0xf8a3
movq (%rax), %rax
movq -0x8(%rax), %rdi
movq %r14, %rsi
callq 0x12274
shlq $0x3, %r12
addq 0x10(%rbx), %r12
testb %al, %al
je 0xf810
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x1328e
jmp 0xf82e
movq (%r12), %rdi
movq (%rdi), %rax
movq 0x8(%rsp), %rsi
callq *0x10(%rax)
jmp 0xf82e
movq 0x10(%rbx), %rax
movq (%rax,%r12,8), %rax
movq %rax, 0x10(%rsp)
incl %r13d
jmp 0xf764
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2138a
leaq 0x28b36(%rip), %rcx     # 0x38380
movl %eax, (%rcx)
leaq 0x18(%rsp), %r14
movq 0x28(%rsp), %rax
cmpq %rax, 0x48(%rsp)
je 0xf876
movq (%rax), %r15
movq %r14, %rdi
callq 0x134c2
movq (%r15), %rax
movq %r15, %rdi
movq %rbx, %rsi
callq *0x10(%rax)
jmp 0xf851
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x10(%rax)
leaq 0x18(%rsp), %rdi
callq 0x12852
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6320
movq %rax, %r14
pushq $0x8
popq %rsi
movq 0x8(%rsp), %rdi
callq 0x62e0
jmp 0xf8cf
jmp 0xf8c2
jmp 0xf8c2
jmp 0xf8c2
jmp 0xf8c2
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x12852
movq %r14, %rdi
callq 0x6530
nop