// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
callq 0x2e60
testb $0x1, %al
jne 0x9b26
jmp 0x9b2b
jmp 0xa3a4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
movq %rax, -0x10(%rbp)
leaq 0x78a8(%rip), %rdi      # 0x113e8
callq 0x37d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
cmpq %rcx, %rax
jae 0x9bb8
movl -0x4(%rbp), %eax
movl %eax, %esi
leaq 0x788b(%rip), %rdi      # 0x113e8
callq 0x3790
testb $0x1, 0x8(%rax)
je 0x9ba8
movl -0x4(%rbp), %eax
movl %eax, %esi
leaq 0x7874(%rip), %rdi      # 0x113e8
callq 0x3790
cmpl $-0x1, 0x84(%rax)
jne 0x9ba8
leaq 0x764b(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x4(%rbp), %eax
movl %eax, %esi
leaq 0x784e(%rip), %rdi      # 0x113e8
callq 0x3790
movl -0x14(%rbp), %ecx
movl %ecx, 0x84(%rax)
jmp 0x9baa
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x9b32
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x75fb(%rip), %rcx      # 0x111c4
cmpl (%rcx), %eax
jae 0xa3a2
leaq 0x75c8(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7805(%rip), %rdi      # 0x113e8
callq 0x3790
testb $0x1, 0x8(%rax)
je 0xa392
leaq 0x75a7(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x77e4(%rip), %rdi      # 0x113e8
callq 0x3790
testb $0x1, (%rax)
je 0xa392
leaq 0x75bb(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xd0(%rbp)
leaq 0x7578(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x77b5(%rip), %rdi      # 0x113e8
callq 0x3790
movq %rax, %rcx
movl -0xd0(%rbp), %eax
subl 0x84(%rcx), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
leaq 0x7549(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7786(%rip), %rdi      # 0x113e8
callq 0x3790
movl -0xcc(%rbp), %ecx
movl %ecx, 0x88(%rax)
leaq 0x7526(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7763(%rip), %rdi      # 0x113e8
callq 0x3790
movl 0x90(%rax), %esi
movq 0x7341(%rip), %rdi      # 0x10fd8
callq 0x2210
movq %rax, %rdi
leaq 0x1734(%rip), %rsi      # 0xb3da
callq 0x2190
movq %rax, %rdi
leaq 0x16ec(%rip), %rsi      # 0xb3a1
callq 0x2190
movq %rax, -0xc8(%rbp)
leaq 0x74d8(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7715(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0xc8(%rbp), %rdi
movl 0x28(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x16b4(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x16a8(%rip), %rsi      # 0xb3a8
callq 0x2190
movq %rax, -0xc0(%rbp)
leaq 0x748d(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x76ca(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0xc0(%rbp), %rdi
movl 0x34(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x1671(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0xb8(%rbp)
leaq 0x7451(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x768e(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0xb8(%rbp), %rdi
movl 0x3c(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x162d(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x1628(%rip), %rsi      # 0xb3af
callq 0x2190
movq %rax, -0xb0(%rbp)
leaq 0x7406(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7643(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0xb0(%rbp), %rdi
movl 0x2c(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x15e2(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x15e2(%rip), %rsi      # 0xb3b4
callq 0x2190
movq %rax, -0xa8(%rbp)
leaq 0x73bb(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x75f8(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0xa8(%rbp), %rdi
movl 0x44(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x159f(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0xa0(%rbp)
leaq 0x737f(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x75bc(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0xa0(%rbp), %rdi
movl 0x48(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x155b(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x155f(%rip), %rsi      # 0xb3b8
callq 0x2190
movq %rax, -0x98(%rbp)
leaq 0x7334(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7571(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x98(%rbp), %rdi
movl 0x4c(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x1518(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0x90(%rbp)
leaq 0x72f8(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7535(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x90(%rbp), %rdi
movl 0x50(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x14d4(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x14dc(%rip), %rsi      # 0xb3bc
callq 0x2190
movq %rax, -0x88(%rbp)
leaq 0x72ad(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x74ea(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x88(%rbp), %rdi
movl 0x54(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x1491(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0x80(%rbp)
leaq 0x7274(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x74b1(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x80(%rbp), %rdi
movl 0x58(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x1453(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x145f(%rip), %rsi      # 0xb3c0
callq 0x2190
movq %rax, -0x78(%rbp)
leaq 0x722f(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x746c(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x78(%rbp), %rdi
movl 0x5c(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x1416(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0x70(%rbp)
leaq 0x71f9(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7436(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x70(%rbp), %rdi
movl 0x60(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x13d8(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x13e8(%rip), %rsi      # 0xb3c4
callq 0x2190
movq %rax, -0x68(%rbp)
leaq 0x71b4(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x73f1(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x68(%rbp), %rdi
movl 0x64(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x139b(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0x60(%rbp)
leaq 0x717e(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x73bb(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x60(%rbp), %rdi
movl 0x68(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x135d(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x1371(%rip), %rsi      # 0xb3c8
callq 0x2190
movq %rax, -0x58(%rbp)
leaq 0x7139(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7376(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x58(%rbp), %rdi
movl 0x6c(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x1320(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0x50(%rbp)
leaq 0x7103(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7340(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x50(%rbp), %rdi
movl 0x70(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x12e2(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x12fa(%rip), %rsi      # 0xb3cc
callq 0x2190
movq %rax, -0x48(%rbp)
leaq 0x70be(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x72fb(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x48(%rbp), %rdi
movl 0x74(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x12a5(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0x40(%rbp)
leaq 0x7088(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x72c5(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x40(%rbp), %rdi
movl 0x78(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x1267(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x1283(%rip), %rsi      # 0xb3d0
callq 0x2190
movq %rax, -0x38(%rbp)
leaq 0x7043(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7280(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x38(%rbp), %rdi
movl 0x7c(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x122a(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0x30(%rbp)
leaq 0x700d(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x724a(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x30(%rbp), %rdi
movl 0x80(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x11e9(%rip), %rsi      # 0xb3a5
callq 0x2190
movq %rax, %rdi
leaq 0x1209(%rip), %rsi      # 0xb3d4
callq 0x2190
movq %rax, -0x28(%rbp)
leaq 0x6fc5(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7202(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x28(%rbp), %rdi
movl 0x84(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x11a9(%rip), %rsi      # 0xb3ad
callq 0x2190
movq %rax, -0x20(%rbp)
leaq 0x6f8c(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x71c9(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0x20(%rbp), %rdi
movl 0x88(%rax), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x119b(%rip), %rsi      # 0xb3d8
callq 0x2190
movq %rax, %rdi
movq 0x6d7c(%rip), %rsi      # 0x10fc8
callq 0x21c0
leaq 0x6f48(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7185(%rip), %rdi      # 0x113e8
callq 0x3790
cmpl $-0x1, 0x2c(%rax)
je 0xa321
leaq 0x6f27(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7164(%rip), %rdi      # 0x113e8
callq 0x3790
movl 0x30(%rax), %eax
movl %eax, -0xd4(%rbp)
leaq 0x6f07(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x7144(%rip), %rdi      # 0x113e8
callq 0x3790
movslq 0x2c(%rax), %rsi
leaq 0x714c(%rip), %rdi      # 0x11400
callq 0x7a60
movq %rax, %rcx
movl -0xd4(%rbp), %eax
cmpl 0x4(%rcx), %eax
jne 0xa31f
leaq 0x6ed2(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x710f(%rip), %rdi      # 0x113e8
callq 0x3790
movslq 0x2c(%rax), %rsi
leaq 0x7117(%rip), %rdi      # 0x11400
callq 0x7a60
movb $0x0, (%rax)
leaq 0x6ea8(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x70e5(%rip), %rdi      # 0x113e8
callq 0x3790
movslq 0x2c(%rax), %rsi
leaq 0x70ed(%rip), %rdi      # 0x11400
callq 0x7a60
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
jmp 0xa321
leaq 0x6e78(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x70b5(%rip), %rdi      # 0x113e8
callq 0x3790
movb $0x0, (%rax)
leaq 0x6e5e(%rip), %rax      # 0x111a0
movl (%rax), %eax
movl %eax, %esi
leaq 0x709b(%rip), %rdi      # 0x113e8
callq 0x3790
movq $0x0, 0x20(%rax)
leaq 0x6e3f(%rip), %rax      # 0x111a0
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x6e33(%rip), %rax      # 0x111a0
movl %ecx, (%rax)
leaq 0x6e2a(%rip), %rax      # 0x111a0
movl (%rax), %eax
leaq 0x6e3d(%rip), %rcx      # 0x111bc
cmpl (%rcx), %eax
jne 0xa390
leaq 0x6e16(%rip), %rax      # 0x111a0
movl $0x0, (%rax)
jmp 0xa392
jmp 0xa394
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x9bbf
jmp 0xa3a4
addq $0xe0, %rsp
popq %rbp
retq