// File: /workspace/github_cpp_makefile_star2_O3/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 0xd43d
cmpl $0x0, 0x960(%rbx)
jne 0xd43d
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl 0x97c(%rbx), %r15d
movl $0x0, 0x928(%rbx)
cmpl %r15d, %r14d
jae 0xd4bd
imulq $0x758, %r14, %r12      # imm = 0x758
addq $0x68, %r12
xorl %eax, %eax
leaq 0x73a59(%rip), %r13     # 0x80ec0
movq 0x9b8(%rbx), %rcx
cmpl $0x2, -0x4(%rcx,%r12)
jne 0xd433
movq -0x28(%rcx,%r12), %rdx
movl (%rbx), %esi
cmpq (%r13,%rsi,8), %rdx
ja 0xd433
cmpl $0x63, %eax
ja 0xd433
cmpl $0x0, (%rcx,%r12)
jne 0xd4a1
movq %rbx, %rdi
movl %r14d, %esi
callq 0xd5be
movl 0x928(%rbx), %eax
incl %eax
movl %eax, 0x928(%rbx)
incq %r14
addq $0x758, %r12            # imm = 0x758
cmpq %r14, %r15
jne 0xd467
jmp 0xd433
movl 0x950(%rbx), %ecx
xorl %eax, %eax
cmpl %ecx, %r14d
jae 0xd543
imulq $0x758, %r14, %r12      # imm = 0x758
addq $0x68, %r12
xorl %eax, %eax
leaq 0x739e2(%rip), %r13     # 0x80ec0
movq 0x9b8(%rbx), %rdx
cmpl $0x2, -0x4(%rdx,%r12)
jne 0xd433
movq -0x28(%rdx,%r12), %rsi
movl (%rbx), %edi
cmpq (%r13,%rdi,8), %rsi
ja 0xd433
cmpl $0x63, %eax
ja 0xd433
cmpl $0x0, (%rdx,%r12)
jne 0xd52a
movq %rbx, %rdi
movl %r14d, %esi
callq 0xd5be
movl 0x928(%rbx), %eax
movl 0x950(%rbx), %ecx
incl %eax
movl %eax, 0x928(%rbx)
incq %r14
movl %ecx, %edx
addq $0x758, %r12            # imm = 0x758
cmpq %rdx, %r14
jb 0xd4de
testq %r15, %r15
je 0xd433
movl $0x68, %r12d
xorl %r14d, %r14d
leaq 0x73964(%rip), %r13     # 0x80ec0
movq 0x9b8(%rbx), %rcx
cmpl $0x2, -0x4(%rcx,%r12)
jne 0xd433
movq -0x28(%rcx,%r12), %rdx
movl (%rbx), %esi
cmpq (%r13,%rsi,8), %rdx
ja 0xd433
cmpl $0x63, %eax
ja 0xd433
cmpl $0x0, (%rcx,%r12)
jne 0xd5a2
movq %rbx, %rdi
movl %r14d, %esi
callq 0xd5be
movl 0x928(%rbx), %eax
incl %eax
movl %eax, 0x928(%rbx)
incq %r14
addq $0x758, %r12            # imm = 0x758
cmpq %r14, %r15
jne 0xd55c
jmp 0xd433