// File: /workspace/github_cpp_makefile_star2_O2/dsesami[P]superscalar-processor-model/retire.cc
// Function: retire()
void retire(){

    if(isROBempty()) return; // Nothing within ROB.

   for(u_int i=0; i<ROB.size(); i++) {
        // set first cycle and duration of this instruction.
        if(ROB.at(i).ready && (ROB.at(i).instruction.retire_first == -1)) {
            ROB.at(i).instruction.retire_first = cycles;
        }
   }
for(u_int i=0; i<WIDTH; i++) {
   if(ROB.at(head).ready && ROB.at(head).valid) {
       // Print information

       ROB.at(head).instruction.retire_time = cycles - ROB.at(head).instruction.retire_first+1;
        cout << ROB.at(head).instruction.dyn << " "
             << "fu{" << ROB.at(head).instruction.op_type << "} "
             << "src{" << ROB.at(head).instruction.src_1 << ","
             << ROB.at(head).instruction.src_2 << "} "
             << "dst{" << ROB.at(head).instruction.dest << "} "
             << "FE{" << ROB.at(head).instruction.fetch_first << ","
             << ROB.at(head).instruction.fetch_time << "} "
             << "DE{" << ROB.at(head).instruction.decode_first << ","
             << ROB.at(head).instruction.decode_time << "} "
             << "RN{" << ROB.at(head).instruction.rename_first << ","
             << ROB.at(head).instruction.rename_time << "} "
             << "RR{" << ROB.at(head).instruction.regRead_first << ","
             << ROB.at(head).instruction.regRead_time << "} "
             << "DI{" << ROB.at(head).instruction.dispatch_first << ","
             << ROB.at(head).instruction.dispatch_time << "} "
             << "IS{" << ROB.at(head).instruction.issue_first << ","
             << ROB.at(head).instruction.issue_time << "} "
             << "EX{" << ROB.at(head).instruction.execute_first << ","
             << ROB.at(head).instruction.execute_time << "} "
             << "WB{" << ROB.at(head).instruction.writeback_first << ","
             << ROB.at(head).instruction.writeback_time << "} "
             << "RT{" << ROB.at(head).instruction.retire_first << ","
             << ROB.at(head).instruction.retire_time << "}  "
             << endl;

        //dyn_instr_count++;
        // invalidate RMT
        if(ROB.at(head).instruction.dest != -1) {
            if(ROB.at(head).instruction.rn_dest == RMT.at(ROB.at(head).instruction.dest).rob_tag) {
                RMT.at(ROB.at(head).instruction.dest).valid = false;
                RMT.at(ROB.at(head).instruction.dest).rob_tag = -1;
            }
        }
        // Move head down and stop.
        //ROB.at(head).ready = 0;
        ROB.at(head).valid = 0;
        ROB.at(head).instruction.address = 0;
        //ROB.at(head).address = 0;
        //ROB.at(head).dest = -1;

        head++;
        if(head == ROBSIZE) head = 0;
        //dyn_instr_count++;
   }
}
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x2a7e
testb %al, %al
je 0x4de7
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
leaq 0x45a0(%rip), %r14      # 0x9390
movl $0x98, %r15d
movl %ebx, %ebx
movq 0x8(%r14), %rax
subq (%r14), %rax
cqto
idivq %r15
cmpq %rbx, %rax
jbe 0x4e4c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2ed6
cmpb $0x1, 0x8(%rax)
jne 0x4e48
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2ed6
cmpl $-0x1, 0x84(%rax)
jne 0x4e48
leaq 0x4347(%rip), %rax      # 0x917c
movl (%rax), %ebp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2ed6
movl %ebp, 0x84(%rax)
incl %ebx
jmp 0x4df6
leaq 0x4319(%rip), %r15      # 0x916c
leaq 0x42ee(%rip), %r12      # 0x9148
leaq 0x452f(%rip), %rbx      # 0x9390
leaq 0x1559(%rip), %r13      # 0x63c1
leaq 0x155a(%rip), %r14      # 0x63c9
xorl %ebp, %ebp
cmpl (%r15), %ebp
jae 0x4dd8
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
cmpb $0x1, 0x8(%rax)
jne 0x53c0
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
cmpb $0x1, (%rax)
jne 0x53c0
leaq 0x42d0(%rip), %rax      # 0x917c
movl (%rax), %r15d
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
subl 0x84(%rax), %r15d
incl %r15d
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl %r15d, 0x88(%rax)
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x90(%rax), %esi
movq 0x40e7(%rip), %rdi      # 0x8fd8
callq 0x20f0
movq %rax, %rdi
leaq 0x14f6(%rip), %rsi      # 0x63f6
callq 0x2140
movq %rax, %rdi
leaq 0x14ae(%rip), %rsi      # 0x63bd
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x28(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x1481(%rip), %rsi      # 0x63c4
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x34(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x3c(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x142f(%rip), %rsi      # 0x63cb
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x2c(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x1400(%rip), %rsi      # 0x63d0
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x44(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x48(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x13ab(%rip), %rsi      # 0x63d4
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x4c(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x50(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x1356(%rip), %rsi      # 0x63d8
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x54(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x58(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x1301(%rip), %rsi      # 0x63dc
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x5c(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x60(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x12ac(%rip), %rsi      # 0x63e0
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x64(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x68(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x1257(%rip), %rsi      # 0x63e4
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x6c(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x70(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x1202(%rip), %rsi      # 0x63e8
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x74(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x78(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x11ad(%rip), %rsi      # 0x63ec
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x7c(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x80(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x1155(%rip), %rsi      # 0x63f0
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x84(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
movq %r14, %rsi
callq 0x2140
movq %rax, %r15
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x88(%rax), %esi
movq %r15, %rdi
callq 0x2240
movq %rax, %rdi
leaq 0x1105(%rip), %rsi      # 0x63f4
callq 0x2140
movq %rax, %rdi
callq 0x20b0
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
cmpl $-0x1, 0x2c(%rax)
je 0x537e
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movl 0x30(%rax), %r15d
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movslq 0x2c(%rax), %rsi
leaq 0x4073(%rip), %rdi      # 0x93a8
callq 0x3fe0
cmpl 0x4(%rax), %r15d
jne 0x537e
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movslq 0x2c(%rax), %rsi
leaq 0x4051(%rip), %r15      # 0x93a8
movq %r15, %rdi
callq 0x3fe0
movb $0x0, (%rax)
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movslq 0x2c(%rax), %rsi
movq %r15, %rdi
callq 0x3fe0
orl $-0x1, 0x4(%rax)
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
movb $0x0, (%rax)
movl (%r12), %esi
movq %rbx, %rdi
callq 0x2ed6
andq $0x0, 0x20(%rax)
movl (%r12), %eax
incl %eax
leaq 0x3db9(%rip), %rcx      # 0x9164
cmpl (%rcx), %eax
movl $0x0, %ecx
cmovel %ecx, %eax
movl %eax, (%r12)
leaq 0x3dac(%rip), %r15      # 0x916c
incl %ebp
jmp 0x4e71