// File: NishadSaraf[P]Championship-Simulator/src/ooo_cpu.cc
// Function: O3_CPU::check_rob(unsigned long)
uint32_t O3_CPU::check_rob(uint64_t instr_id)
{
    if ((ROB.head == ROB.tail) && ROB.occupancy == 0)
        return ROB.SIZE;

    if (ROB.head < ROB.tail) {
        for (uint32_t i=ROB.head; i<ROB.tail; i++) {
            if (ROB.entry[i].instr_id == instr_id) {
                DP ( if (warmup_complete[ROB.cpu]) {
                cout << "[ROB] " << __func__ << " same instr_id: " << ROB.entry[i].instr_id;
                cout << " rob_index: " << i << endl; });
                return i;
            }
        }
    }
    else {
        for (uint32_t i=ROB.head; i<ROB.SIZE; i++) {
            if (ROB.entry[i].instr_id == instr_id) {
                DP ( if (warmup_complete[cpu]) {
                cout << "[ROB] " << __func__ << " same instr_id: " << ROB.entry[i].instr_id;
                cout << " rob_index: " << i << endl; });
                return i;
            }
        }
        for (uint32_t i=0; i<ROB.tail; i++) {
            if (ROB.entry[i].instr_id == instr_id) {
                DP ( if (warmup_complete[cpu]) {
                cout << "[ROB] " << __func__ << " same instr_id: " << ROB.entry[i].instr_id;
                cout << " rob_index: " << i << endl; });
                return i;
            }
        }
    }

    cerr << "[ROB_ERROR] " << __func__ << " does not have any matching index! ";
    cerr << " instr_id: " << instr_id << endl;
    assert(0);

    return ROB.SIZE;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movl 0x958(%rcx), %eax
cmpl 0x95c(%rcx), %eax
jne 0x15ea8
movq 0x8(%rsp), %rax
cmpl $0x0, 0x960(%rax)
jne 0x15ea8
movq 0x8(%rsp), %rax
movl 0x950(%rax), %eax
movl %eax, 0x34(%rsp)
jmp 0x1605a
movq 0x8(%rsp), %rcx
movl 0x958(%rcx), %eax
cmpl 0x95c(%rcx), %eax
jae 0x15f20
movq 0x8(%rsp), %rax
movl 0x958(%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x8(%rsp), %rcx
movl 0x1c(%rsp), %eax
cmpl 0x95c(%rcx), %eax
jae 0x15f1b
movq 0x8(%rsp), %rax
movq 0x9b8(%rax), %rax
movl 0x1c(%rsp), %ecx
imulq $0x758, %rcx, %rcx      # imm = 0x758
addq %rcx, %rax
movq (%rax), %rax
cmpq 0x20(%rsp), %rax
jne 0x15f0c
movl 0x1c(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x1605a
jmp 0x15f0e
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x15eca
jmp 0x15fdb
movq 0x8(%rsp), %rax
movl 0x958(%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x8(%rsp), %rcx
movl 0x18(%rsp), %eax
cmpl 0x950(%rcx), %eax
jae 0x15f80
movq 0x8(%rsp), %rax
movq 0x9b8(%rax), %rax
movl 0x18(%rsp), %ecx
imulq $0x758, %rcx, %rcx      # imm = 0x758
addq %rcx, %rax
movq (%rax), %rax
cmpq 0x20(%rsp), %rax
jne 0x15f71
movl 0x18(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x1605a
jmp 0x15f73
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x15f2f
movl $0x0, 0x14(%rsp)
movq 0x8(%rsp), %rcx
movl 0x14(%rsp), %eax
cmpl 0x95c(%rcx), %eax
jae 0x15fd9
movq 0x8(%rsp), %rax
movq 0x9b8(%rax), %rax
movl 0x14(%rsp), %ecx
imulq $0x758, %rcx, %rcx      # imm = 0x758
addq %rcx, %rax
movq (%rax), %rax
cmpq 0x20(%rsp), %rax
jne 0x15fca
movl 0x14(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x1605a
jmp 0x15fcc
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x15f88
jmp 0x15fdb
movq 0x1300e(%rip), %rdi     # 0x28ff0
leaq 0xdbf8(%rip), %rsi      # 0x23be1
callq 0x3220
movq %rax, %rdi
leaq 0xdc30(%rip), %rsi      # 0x23c28
callq 0x3220
movq %rax, %rdi
leaq 0xdc2b(%rip), %rsi      # 0x23c32
callq 0x3220
movq 0x12fdd(%rip), %rdi     # 0x28ff0
leaq 0xde05(%rip), %rsi      # 0x23e1f
callq 0x3220
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x3080
movq %rax, %rdi
movq 0x12f82(%rip), %rsi     # 0x28fb8
callq 0x3250
leaq 0xcfc2(%rip), %rdi      # 0x23004
leaq 0xdb6c(%rip), %rsi      # 0x23bb5
movl $0x164, %edx            # imm = 0x164
leaq 0xdc01(%rip), %rcx      # 0x23c56
callq 0x3160
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)