// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x958(%rdi), %r14d
cmpl 0x95c(%rdi), %r14d
jne 0xd51a
cmpl $0x0, 0x960(%rbx)
jne 0xd51a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x97c(%rbx), %r15d
movl $0x0, 0x928(%rbx)
cmpl %r15d, %r14d
jae 0xd594
imulq $0x758, %r14, %r12      # imm = 0x758
addq $0x68, %r12
leaq 0x7397e(%rip), %r13     # 0x80ec0
movq 0x9b8(%rbx), %rax
cmpl $0x2, -0x4(%rax,%r12)
jne 0xd50b
movq -0x28(%rax,%r12), %rcx
movl (%rbx), %edx
cmpq (%r13,%rdx,8), %rcx
ja 0xd50b
cmpl $0x63, 0x928(%rbx)
ja 0xd50b
cmpl $0x0, (%rax,%r12)
jne 0xd57a
movq %rbx, %rdi
movl %r14d, %esi
callq 0xd680
incl 0x928(%rbx)
incl %r14d
addq $0x758, %r12            # imm = 0x758
cmpl %r14d, %r15d
jne 0xd542
jmp 0xd50b
cmpl 0x950(%rbx), %r14d
jae 0xd60c
imulq $0x758, %r14, %r12      # imm = 0x758
addq $0x68, %r12
leaq 0x73911(%rip), %r13     # 0x80ec0
movq 0x9b8(%rbx), %rax
cmpl $0x2, -0x4(%rax,%r12)
jne 0xd50b
movq -0x28(%rax,%r12), %rcx
movl (%rbx), %edx
cmpq (%r13,%rdx,8), %rcx
ja 0xd50b
cmpl $0x63, 0x928(%rbx)
ja 0xd50b
cmpl $0x0, (%rax,%r12)
jne 0xd5f3
movq %rbx, %rdi
movl %r14d, %esi
callq 0xd680
incl 0x928(%rbx)
incl %r14d
addq $0x758, %r12            # imm = 0x758
cmpl 0x950(%rbx), %r14d
jb 0xd5af
testl %r15d, %r15d
je 0xd50b
xorl %ebp, %ebp
movl $0x68, %r14d
leaq 0x7389c(%rip), %r12     # 0x80ec0
movq 0x9b8(%rbx), %rax
cmpl $0x2, -0x4(%rax,%r14)
jne 0xd50b
movq -0x28(%rax,%r14), %rcx
movl (%rbx), %edx
cmpq (%r12,%rdx,8), %rcx
ja 0xd50b
cmpl $0x63, 0x928(%rbx)
ja 0xd50b
cmpl $0x0, (%rax,%r14)
jne 0xd666
movq %rbx, %rdi
movl %ebp, %esi
callq 0xd680
incl 0x928(%rbx)
incl %ebp
addq $0x758, %r14            # imm = 0x758
cmpl %ebp, %r15d
jne 0xd624
jmp 0xd50b
nop