// File: kelwinfc[P]ci4721-Fernandez-Gyomrey/src/Tac.cpp
// Function: Tac::to_spim()
Spim* Tac::to_spim()
{
    Spim* spim = new Spim(this);
    
    vector<Block*>::iterator itb = list_of_blocks.begin();
    bool in = false, out = false;
    for( ; itb != list_of_blocks.end(); ++itb){
        list<inst*>::iterator iti = (*itb)->instructions.linst->begin();
        for( ; iti != (*itb)->instructions.linst->end(); ++iti){
            const inst i = **iti;
            in = !out && (in || (i.op == inst::PROLOGUE && !i.arg2->data.sym->getName().compare("main")));
            if (in) {
                switch (i.op) {
                case inst::WRITE:
                    //spim->append_inst(Spim_Inst::LI);
                    //spim->append_inst(Spim_Inst::LI);
                default:
                    break;
                }
                //spim->append_inst(*iti);
            }
            out = out || (i.op == inst::EPILOGUE && !i.arg2->data.sym->getName().compare("main"));
            if (out && in) {
                // ep�logo main
                //spim->append_inst(Spim_Inst::LI, new opd(10));
                //spim->append_inst(Spim_Inst::LI);
            }
        }
    }
    return spim;
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x28, %edi
callq 0x6390
movq 0x8(%rsp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
callq 0x4e4d0
jmp 0x4e17d
movq 0x10(%rsp), %rax
movq %rax, 0xe8(%rsp)
leaq 0x202f7(%rip), %rdi     # 0x6e488
callq 0x350a0
movq %rax, 0xd0(%rsp)
movb $0x0, 0xcf(%rsp)
movb $0x0, 0xce(%rsp)
leaq 0x202d3(%rip), %rdi     # 0x6e488
callq 0x35110
movq %rax, 0xc0(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x350d0
testb $0x1, %al
jne 0x4e1e0
jmp 0x4e428
leaq 0xd0(%rsp), %rdi
callq 0x35140
movq (%rax), %rax
movq 0x8(%rax), %rdi
callq 0x34c70
movq %rax, 0xb8(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x35140
movq (%rax), %rax
movq 0x8(%rax), %rdi
callq 0x34cc0
movq %rax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x34ca0
testb $0x1, %al
jne 0x4e240
jmp 0x4e414
leaq 0xb8(%rsp), %rdi
callq 0x34cf0
movq (%rax), %rsi
leaq 0x68(%rsp), %rdi
callq 0x4e470
movb 0xce(%rsp), %cl
movb $0x0, 0x47(%rsp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x7(%rsp)
jne 0x4e2d7
movb $0x1, %al
testb $0x1, 0xcf(%rsp)
movb %al, 0x6(%rsp)
jne 0x4e2cf
xorl %eax, %eax
cmpl $0xe, 0x74(%rsp)
movb %al, 0x5(%rsp)
jne 0x4e2c7
movq 0x88(%rsp), %rax
movq (%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0x295b0
jmp 0x4e2a5
movb $0x1, 0x47(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x48af(%rip), %rsi      # 0x52b65
callq 0x6110
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, 0x5(%rsp)
movb 0x5(%rsp), %al
movb %al, 0x6(%rsp)
movb 0x6(%rsp), %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
andb $0x1, %al
movb %al, 0xcf(%rsp)
testb $0x1, 0x47(%rsp)
jne 0x4e2ed
jmp 0x4e2f7
leaq 0x48(%rsp), %rdi
callq 0x6778
testb $0x1, 0xcf(%rsp)
je 0x4e35d
movl 0x74(%rsp), %eax
subl $0xa, %eax
je 0x4e357
jmp 0x4e359
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
movl $0x28, %esi
callq 0x63a0
jmp 0x4e438
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x3cbe0
jmp 0x4e438
jmp 0x4e359
jmp 0x4e35b
jmp 0x4e35d
movb 0xce(%rsp), %cl
movb $0x0, 0x1f(%rsp)
movb $0x1, %al
testb $0x1, %cl
movb %al, 0x4(%rsp)
jne 0x4e3c2
xorl %eax, %eax
cmpl $0xf, 0x74(%rsp)
movb %al, 0x3(%rsp)
jne 0x4e3ba
movq 0x88(%rsp), %rax
movq (%rax), %rsi
leaq 0x20(%rsp), %rdi
callq 0x295b0
jmp 0x4e398
movb $0x1, 0x1f(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x47bc(%rip), %rsi      # 0x52b65
callq 0x6110
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, 0x3(%rsp)
movb 0x3(%rsp), %al
movb %al, 0x4(%rsp)
movb 0x4(%rsp), %al
andb $0x1, %al
movb %al, 0xce(%rsp)
testb $0x1, 0x1f(%rsp)
jne 0x4e3d8
jmp 0x4e3e2
leaq 0x20(%rsp), %rdi
callq 0x6778
testb $0x1, 0xce(%rsp)
je 0x4e3f8
testb $0x1, 0xcf(%rsp)
je 0x4e3f8
jmp 0x4e3f8
leaq 0x68(%rsp), %rdi
callq 0x3cbe0
leaq 0xb8(%rsp), %rdi
callq 0x34d10
jmp 0x4e201
jmp 0x4e416
leaq 0xd0(%rsp), %rdi
callq 0x35150
jmp 0x4e1ae
movq 0xe8(%rsp), %rax
addq $0xf8, %rsp
retq
movq 0xe0(%rsp), %rdi
callq 0x66b0
nopw %cs:(%rax,%rax)
nop