// File: /workspace/github_cpp_makefile_star2_O1/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 0x62e0
movq %rax, (%rsp)
movq %rax, %rdi
callq 0x2ade0
movq 0x18(%r15), %r13
subq 0x10(%r15), %r13
shrq $0x3, %r13
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, 0x8(%rsp)
xorl %esi, %esi
callq 0x172e0
testl %r13d, %r13d
je 0x12bc8
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
movq 0x10(%r15), %r14
movq (%r14,%r12), %rax
testq %rax, %rax
je 0x12c72
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x19750(%rip), %rax     # 0x2c20d
cmpq %rax, %rdi
je 0x12acb
cmpb $0x2a, (%rdi)
jne 0x12ad0
xorl %ebp, %ebp
jmp 0x12ae2
movb $0x1, %bpl
jmp 0x12ae2
leaq 0x19736(%rip), %rsi     # 0x2c20d
callq 0x6400
testl %eax, %eax
sete %bpl
testb %bpl, %bpl
je 0x12b15
movq (%r14,%r12), %rax
movq 0x98(%rax), %rsi
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x17fb8
movq %rbx, %rdi
leaq 0x1a070(%rip), %rsi     # 0x2cb79
callq 0x60d0
testl %eax, %eax
sete %bl
jmp 0x12b17
xorl %ebx, %ebx
testb %bpl, %bpl
je 0x12b38
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x12b38
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x62f0
movq 0x10(%r15), %rbp
movq (%rbp,%r12), %r14
testb %bl, %bl
je 0x12b4c
movq %r14, 0x8(%rsp)
jmp 0x12bbb
testq %r14, %r14
je 0x12c72
movq (%r14), %rbx
movq -0x8(%rbx), %rax
movq 0x8(%rax), %rdi
leaq 0x196a6(%rip), %rax     # 0x2c20d
cmpq %rax, %rdi
je 0x12b9f
cmpb $0x2a, (%rdi)
je 0x12b81
leaq 0x19695(%rip), %rsi     # 0x2c20d
callq 0x6400
testl %eax, %eax
je 0x12b9f
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x12bab
movq %r14, (%rax)
addq $0x8, 0x40(%rsp)
jmp 0x12bbb
movq %r14, %rdi
movq (%rsp), %rsi
callq *0x10(%rbx)
jmp 0x12bbb
addq %r12, %rbp
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x17472
addq $0x8, %r12
decl %r13d
jne 0x12a9a
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x2af04
leaq 0x2b7a5(%rip), %rcx     # 0x3e380
movl %eax, (%rcx)
movq 0x20(%rsp), %rax
cmpq %rax, 0x40(%rsp)
je 0x12c45
movq (%rax), %r14
movq 0x30(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x12c00
addq $0x8, %rax
jmp 0x12c32
movq 0x28(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x62f0
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 0x12bdd
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x10(%rax)
leaq 0x10(%rsp), %rdi
callq 0x16bf2
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6340
movq %rax, %r14
movl $0x8, %esi
movq (%rsp), %rdi
callq 0x62f0
jmp 0x12c9f
jmp 0x12c92
jmp 0x12c92
jmp 0x12c92
jmp 0x12c92
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x16bf2
movq %r14, %rdi
callq 0x6550
nop