// File: kelwinfc[P]ci4721-Fernandez-Gyomrey/src/optimizer.cpp
// Function: next_instruction_jumps(Block&)
void next_instruction_jumps(Block& code){
    if ( code.w_vector ){
        unsigned int nsize = code.instructions.vinst->size();
        
        // Guardar las instrucciones que no sean saltos a la siguiente
        // instruccion
        vector<inst*> new_insts;
        for (unsigned int i=0; i+1<nsize; i++){
            quad* current_inst = (quad*)(*(code.instructions.vinst))[i];
            quad* next_inst    = (quad*)(*(code.instructions.vinst))[i+1];
            
            if (    current_inst->op == quad::GOTO 
                 && current_inst->get_goal_label() == next_inst->label
               )
            {
                delete current_inst;
                (*(code.instructions.vinst))[i] = 0;
            } else {
                new_insts.push_back( current_inst );
            }
        }
        if ( nsize ){
            new_insts.push_back( code.instructions.vinst->back() );
        }
        unsigned int goal_size = new_insts.size();
        
        code.instructions.vinst->clear();
        for (unsigned int i=0; i<goal_size; i++){
            code.instructions.vinst->push_back( new_insts[i] );
        }
    }
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq 0x70(%rsp), %rax
testb $0x1, 0x4(%rax)
je 0x3ce41
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x34d30
movl %eax, 0x6c(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x349f0
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
cmpl 0x6c(%rsp), %eax
jae 0x3cda9
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x34d50
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x34d50
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
cmpl $0x16, 0xc(%rax)
jne 0x3cd7a
movq 0x40(%rsp), %rdi
callq 0x38d80
movl %eax, 0x14(%rsp)
jmp 0x3cd09
movl 0x14(%rsp), %eax
movq 0x38(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x3cd7a
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x3cd40
movq 0x8(%rsp), %rdi
callq 0x3d270
movq 0x8(%rsp), %rdi
movl $0x48, %esi
callq 0x63a0
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x34d50
movq $0x0, (%rax)
jmp 0x3cd97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x3d2d0
jmp 0x3ce46
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3d280
jmp 0x3cd95
jmp 0x3cd97
jmp 0x3cd99
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x3cc9c
cmpl $0x0, 0x6c(%rsp)
je 0x3cdcf
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x34ae0
movq %rax, %rsi
leaq 0x50(%rsp), %rdi
callq 0x34a70
jmp 0x3cdcd
jmp 0x3cdcf
leaq 0x50(%rsp), %rdi
callq 0x34d30
movl %eax, 0x1c(%rsp)
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3d2b0
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jae 0x3ce37
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, (%rsp)
movl 0x18(%rsp), %eax
movl %eax, %esi
leaq 0x50(%rsp), %rdi
callq 0x34d50
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x34a70
jmp 0x3ce28
jmp 0x3ce2a
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x3cdf3
leaq 0x50(%rsp), %rdi
callq 0x3d2d0
addq $0x78, %rsp
retq
movq 0x30(%rsp), %rdi
callq 0x66b0