// File: /workspace/github_cpp_makefile_star2_O2/NishadSaraf[P]Championship-Simulator/src/ooo_cpu.cc
// Function: O3_CPU::schedule_instruction()
void O3_CPU::schedule_instruction()
{
    if ((ROB.head == ROB.tail) && ROB.occupancy == 0)
        return;

    // execution is out-of-order but we have an in-order scheduling algorithm to detect all RAW dependencies
    uint32_t limit = ROB.next_fetch[1];
    num_searched = 0;
    if (ROB.head < limit) {
        for (uint32_t i=ROB.head; i<limit; i++) { 
            if ((ROB.entry[i].fetched != COMPLETED) || (ROB.entry[i].event_cycle > current_core_cycle[cpu]) || (num_searched >= SCHEDULER_SIZE))
                return;

            if (ROB.entry[i].scheduled == 0)
                do_scheduling(i);

            num_searched++;
        }
    }
    else {
        for (uint32_t i=ROB.head; i<ROB.SIZE; i++) {
            if ((ROB.entry[i].fetched != COMPLETED) || (ROB.entry[i].event_cycle > current_core_cycle[cpu]) || (num_searched >= SCHEDULER_SIZE))
                return;

            if (ROB.entry[i].scheduled == 0)
                do_scheduling(i);

            num_searched++;
        }
        for (uint32_t i=0; i<limit; i++) { 
            if ((ROB.entry[i].fetched != COMPLETED) || (ROB.entry[i].event_cycle > current_core_cycle[cpu]) || (num_searched >= SCHEDULER_SIZE))
                return;

            if (ROB.entry[i].scheduled == 0)
                do_scheduling(i);

            num_searched++;
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl 0x958(%rdi), %r14d
cmpl 0x95c(%rdi), %r14d
jne 0xa92d
cmpl $0x0, 0x960(%rbx)
jne 0xa92d
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl 0x97c(%rbx), %r15d
andl $0x0, 0x928(%rbx)
cmpl %r15d, %r14d
jae 0xa9a7
imulq $0x758, %r14, %r12      # imm = 0x758
addq $0x68, %r12
xorl %eax, %eax
leaq 0x7255c(%rip), %r13     # 0x7ceb0
cmpq %r15, %r14
jae 0xa923
movq 0x9b8(%rbx), %rcx
cmpl $0x2, -0x4(%rcx,%r12)
jne 0xa923
movq -0x28(%rcx,%r12), %rdx
movl (%rbx), %esi
cmpq (%r13,%rsi,8), %rdx
ja 0xa923
cmpl $0x63, %eax
ja 0xa923
cmpl $0x0, (%rcx,%r12)
jne 0xa993
movq %rbx, %rdi
movl %r14d, %esi
callq 0xaa88
movl 0x928(%rbx), %eax
incl %eax
movl %eax, 0x928(%rbx)
incq %r14
addq $0x758, %r12            # imm = 0x758
jmp 0xa954
imulq $0x758, %r14, %r13      # imm = 0x758
addq $0x68, %r13
xorl %eax, %eax
leaq 0x724f5(%rip), %r12     # 0x7ceb0
movl 0x950(%rbx), %ecx
cmpq %rcx, %r14
jae 0xaa1f
movq 0x9b8(%rbx), %rcx
cmpl $0x2, -0x4(%rcx,%r13)
jne 0xa923
movq -0x28(%rcx,%r13), %rdx
movl (%rbx), %esi
cmpq (%r12,%rsi,8), %rdx
ja 0xa923
cmpl $0x63, %eax
ja 0xa923
cmpl $0x0, (%rcx,%r13)
jne 0xaa0b
movq %rbx, %rdi
movl %r14d, %esi
callq 0xaa88
movl 0x928(%rbx), %eax
incl %eax
movl %eax, 0x928(%rbx)
incq %r14
addq $0x758, %r13            # imm = 0x758
jmp 0xa9bb
pushq $0x68
popq %r13
xorl %r14d, %r14d
cmpq %r14, %r15
je 0xa923
movq 0x9b8(%rbx), %rcx
cmpl $0x2, -0x4(%rcx,%r13)
jne 0xa923
movq -0x28(%rcx,%r13), %rdx
movl (%rbx), %esi
cmpq (%r12,%rsi,8), %rdx
ja 0xa923
cmpl $0x63, %eax
ja 0xa923
cmpl $0x0, (%rcx,%r13)
jne 0xaa74
movq %rbx, %rdi
movl %r14d, %esi
callq 0xaa88
movl 0x928(%rbx), %eax
incl %eax
movl %eax, 0x928(%rbx)
incq %r14
addq $0x758, %r13            # imm = 0x758
jmp 0xaa26