// File: /workspace/github_cpp_makefile_star2_O3/dsesami[P]superscalar-processor-model/issue.cc
// Function: issue()
void issue(){

    for(u_int i=0; i<WIDTH; i++) {
        int min=50000;
        int min_index=-1;
        // stall if there isn't enough room to issue something.
        if(execute_list.size() == WIDTH*5) return;

        // Move through the IQ and locate the oldest instruction.
        for(u_int j=0; j<IQ_SIZE; j++) {
            if(!IQ.at(j).valid) continue;
            // skip this if its sources aren't ready.
            if(IQ.at(j).instruction.rn_src_1 != -1) continue;
            if(IQ.at(j).instruction.rn_src_2 != -1) continue;
            if(IQ.at(j).valid && (IQ.at(j).instruction.fetch_first < min) && ready(j)) {
                min = IQ.at(j).instruction.fetch_first;
                min_index = j;
            }
        }

        // oh, but first, age up all of the instructions in the IQ.
        for(u_int j=0; j<IQ_SIZE; j++) {
            if(!IQ.at(j).valid) continue;
            if(IQ.at(j).valid) {
                if(IQ.at(j).instruction.issue_first == -1) {
                    IQ.at(j).instruction.issue_first = cycles;
                }
            }
        }

        // If there wasn't an oldest valid instruction, leave.
        if(min_index == -1) return;

        // add the instruction to the execute list.
        int latency;
        if(IQ.at(min_index).instruction.op_type == 0) latency = 1;
        if(IQ.at(min_index).instruction.op_type == 1) latency = 2;
        if(IQ.at(min_index).instruction.op_type == 2) latency = 5;
        IQ.at(min_index).instruction.issue_time = cycles - IQ.at(min_index).instruction.issue_first+1;
        ex_entry ex_instruction = {IQ.at(min_index).instruction, latency};
        execute_list.push_back(ex_instruction);
        // invalidate that instruction in the IQ.
        IQ.at(min_index).valid=0;
    }
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq 0x55ac(%rip), %rax      # 0xb184
movl (%rax), %ecx
testl %ecx, %ecx
je 0x5e08
leaq 0x5807(%rip), %r12      # 0xb3f0
movq 0x8(%r12), %rax
xorl %edx, %edx
leaq 0x5589(%rip), %rbp      # 0xb180
leaq 0x57da(%rip), %r8       # 0xb3d8
leaq 0x558f(%rip), %r9       # 0xb194
subq (%r12), %rax
sarq $0x7, %rax
leal (%rcx,%rcx,4), %ecx
cmpq %rcx, %rax
je 0x5e08
cmpl $0x0, (%rbp)
je 0x5e08
movq %rdx, (%rsp)
movq (%r8), %rcx
movq 0x8(%r8), %rsi
movl $0xc350, %ebx           # imm = 0xC350
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0x2c, %r12d
xorl %r15d, %r15d
movq %rsi, %rdx
subq %rcx, %rdx
sarq $0x7, %rdx
cmpq %r15, %rdx
jbe 0x5e1a
cmpb $0x1, -0x2c(%rcx,%r12)
jne 0x5cb7
cmpl $-0x1, -0xc(%rcx,%r12)
jne 0x5cb7
cmpl $-0x1, -0x4(%rcx,%r12)
jne 0x5cb7
cmpl %ebx, (%rcx,%r12)
jge 0x5cb7
movl %r15d, %edi
callq 0x5e37
leaq 0x5756(%rip), %r8       # 0xb3d8
movq (%r8), %rcx
movq 0x8(%r8), %rsi
testb %al, %al
je 0x5cb0
movq %rsi, %rdx
subq %rcx, %rdx
sarq $0x7, %rdx
cmpq %r15, %rdx
leaq 0x54f3(%rip), %r9       # 0xb194
jbe 0x5e1a
movl (%rcx,%r12), %ebx
movl %r15d, %r13d
jmp 0x5cb7
leaq 0x54dd(%rip), %r9       # 0xb194
incq %r15
movl (%rbp), %eax
subq $-0x80, %r12
cmpq %rax, %r15
jb 0x5c42
testl %eax, %eax
leaq 0x571d(%rip), %r12      # 0xb3f0
je 0x5d13
movq (%r8), %rcx
movq 0x8(%r8), %rdx
subq %rcx, %rdx
sarq $0x7, %rdx
addq $0x54, %rcx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x5e26
cmpb $0x1, -0x54(%rcx)
jne 0x5d05
cmpl $-0x1, (%rcx)
jne 0x5d05
movl (%r9), %eax
movl %eax, (%rcx)
movl (%rbp), %eax
incq %rsi
movl %eax, %edi
subq $-0x80, %rcx
cmpq %rdi, %rsi
jb 0x5ce9
cmpl $-0x1, %r13d
je 0x5e08
movslq %r13d, %r15
movq (%r8), %rax
movq 0x8(%r8), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
cmpq %r15, %rdx
jbe 0x5e1a
movq %r15, %rbx
shlq $0x7, %rbx
leaq (%rax,%rbx), %rsi
addq $0x8, %rsi
movl 0x8(%rsi), %eax
testl %eax, %eax
movl $0x1, %ecx
cmovel %ecx, %r14d
cmpl $0x1, %eax
movl $0x2, %ecx
cmovel %ecx, %r14d
cmpl $0x2, %eax
movl $0x5, %eax
cmovel %eax, %r14d
movl (%r9), %eax
subl 0x4c(%rsi), %eax
incl %eax
movl %eax, 0x50(%rsi)
movl $0xf, %ecx
leaq 0x8(%rsp), %rax
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %r14d, 0x80(%rsp)
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x5db9
movl $0x10, %ecx
movq %rsi, %rdi
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x8(%r12), %rax
subq $-0x80, %rax
movq %rax, 0x8(%r12)
jmp 0x5dd7
movq %r12, %rdi
movq %rax, %rdx
callq 0x5e76
leaq 0x53c9(%rip), %r9       # 0xb194
leaq 0x5606(%rip), %r8       # 0xb3d8
movq 0x8(%r12), %rax
movq (%r8), %rcx
movq 0x8(%r8), %rdx
subq %rcx, %rdx
sarq $0x7, %rdx
cmpq %r15, %rdx
movq (%rsp), %rsi
jbe 0x5e1a
movb $0x0, (%rcx,%rbx)
incl %esi
leaq 0x5389(%rip), %rcx      # 0xb184
movl (%rcx), %ecx
cmpl %ecx, %esi
movq %rsi, %rdx
jb 0x5c05
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2534(%rip), %rdi      # 0x8355
movq %r15, %rsi
jmp 0x5e30
leaq 0x2528(%rip), %rdi      # 0x8355
movq %rdx, %rsi
xorl %eax, %eax
callq 0x21d0