// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
movl $0x8, %edi
callq 0x62f0
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x2b1f4
movq 0x18(%r15), %r12
subq 0x10(%r15), %r12
shrq $0x3, %r12
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
movq $0x0, (%rsp)
xorl %esi, %esi
callq 0x1730e
testl %r12d, %r12d
je 0x12c18
xorl %ebx, %ebx
movq $0x0, (%rsp)
movq 0x10(%r15), %rbp
movq (%rbp,%rbx), %r14
testq %r14, %r14
je 0x12cc2
movq (%r14), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x1a6e3(%rip), %rax     # 0x2d20d
cmpq %rax, %rdi
je 0x12b44
cmpb $0x2a, (%rdi)
je 0x12b9d
leaq 0x1a6d2(%rip), %rsi     # 0x2d20d
callq 0x6410
testl %eax, %eax
jne 0x12b9d
movq 0x98(%r14), %rsi
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x17ff4
movq %r14, %rdi
leaq 0x1b017(%rip), %rsi     # 0x2db79
callq 0x60d0
movl %eax, %r13d
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x12b86
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x6300
movq 0x10(%r15), %rbp
movq (%rbp,%rbx), %r14
testl %r13d, %r13d
je 0x12bf5
testq %r14, %r14
je 0x12cc2
movq (%r14), %r13
movq -0x8(%r13), %rax
movq 0x8(%rax), %rdi
leaq 0x1a65e(%rip), %rax     # 0x2d20d
cmpq %rax, %rdi
je 0x12be7
cmpb $0x2a, (%rdi)
je 0x12bc9
leaq 0x1a64d(%rip), %rsi     # 0x2d20d
callq 0x6410
testl %eax, %eax
je 0x12be7
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x12bfb
movq %r14, (%rax)
addq $0x8, 0x40(%rsp)
jmp 0x12c0b
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq *0x10(%r13)
jmp 0x12c0b
movq %r14, (%rsp)
jmp 0x12c0b
addq %rbx, %rbp
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x174a0
addq $0x8, %rbx
decl %r12d
jne 0x12b06
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2b316
leaq 0x2c75c(%rip), %rcx     # 0x3f388
movl %eax, (%rcx)
movq 0x20(%rsp), %rax
cmpq %rax, 0x40(%rsp)
je 0x12c96
movq (%rax), %r14
movq 0x30(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x12c51
addq $0x8, %rax
jmp 0x12c83
movq 0x28(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x6300
movq 0x38(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0x10(%rax)
jmp 0x12c2e
movq (%rsp), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x10(%rax)
leaq 0x10(%rsp), %rdi
callq 0x16c10
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6350
movq %rax, %r14
movl $0x8, %esi
movq 0x8(%rsp), %rdi
callq 0x6300
jmp 0x12cf0
jmp 0x12ce3
jmp 0x12ce3
jmp 0x12ce3
jmp 0x12ce3
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x16c10
movq %r14, %rdi
callq 0x6560