// File: /workspace/github_cpp_makefile_star2_O1/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 $0x98, %rsp
leaq 0x5050(%rip), %r8       # 0xa184
movl (%r8), %eax
testl %eax, %eax
je 0x535e
xorl %r13d, %r13d
leaq 0x52a7(%rip), %r9       # 0xa3f0
leaq 0x5030(%rip), %rbp      # 0xa180
leaq 0x5281(%rip), %r14      # 0xa3d8
leaq 0x5036(%rip), %r10      # 0xa194
movq 0x8(%r9), %rcx
subq (%r9), %rcx
sarq $0x7, %rcx
leal (%rax,%rax,4), %eax
cmpq %rax, %rcx
je 0x5311
cmpl $0x0, (%rbp)
je 0x5229
movl $0xc350, %ecx           # imm = 0xC350
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x2c, %r12d
xorl %r15d, %r15d
movq %r13, 0x10(%rsp)
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
cmpq %r15, %rdx
jbe 0x5370
cmpb $0x1, -0x2c(%rax,%r12)
jne 0x5216
cmpl $-0x1, -0xc(%rax,%r12)
jne 0x5216
cmpl $-0x1, -0x4(%rax,%r12)
jne 0x5216
cmpl %ecx, (%rax,%r12)
jge 0x5216
movl %r15d, %edi
movl %ecx, %r13d
callq 0x538a
movl %r13d, %ecx
movq 0x10(%rsp), %r13
leaq 0x4fae(%rip), %r10      # 0xa194
leaq 0x5203(%rip), %r9       # 0xa3f0
leaq 0x4f90(%rip), %r8       # 0xa184
testb %al, %al
je 0x5216
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
cmpq %r15, %rdx
jbe 0x5370
movl (%rax,%r12), %ecx
movl %r15d, %ebx
incq %r15
subq $-0x80, %r12
cmpl (%rbp), %r15d
jb 0x5197
jmp 0x522e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x0, (%rbp)
je 0x526d
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
addq $0x54, %rax
xorl %esi, %esi
cmpq %rsi, %rdx
jbe 0x537c
cmpb $0x1, -0x54(%rax)
jne 0x5261
cmpl $-0x1, (%rax)
jne 0x5261
movl (%r10), %ecx
movl %ecx, (%rax)
incq %rsi
subq $-0x80, %rax
cmpl (%rbp), %esi
jb 0x5248
cmpl $-0x1, %ebx
je 0x5311
movslq %ebx, %r15
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
cmpq %r15, %rdx
jbe 0x5370
movq %r15, %rbx
shlq $0x7, %rbx
leaq (%rax,%rbx), %rsi
addq $0x8, %rsi
movl 0x8(%rsi), %eax
testl %eax, %eax
movl $0x1, %ecx
movl 0xc(%rsp), %r11d
cmovel %ecx, %r11d
cmpl $0x1, %eax
movl $0x2, %ecx
cmovel %ecx, %r11d
cmpl $0x2, %eax
movl $0x5, %eax
cmovel %eax, %r11d
movl (%r10), %eax
subl 0x4c(%rsi), %eax
incl %eax
movl %eax, 0x50(%rsi)
movl $0xf, %ecx
leaq 0x18(%rsp), %rdx
movq %rdx, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %r11d, 0xc(%rsp)
movl %r11d, 0x90(%rsp)
movq 0x8(%r9), %rsi
cmpq 0x10(%r9), %rsi
je 0x5315
movl $0x10, %ecx
movq %rsi, %rdi
movq %rdx, %rsi
rep  movsq (%rsi), %es:(%rdi)
subq $-0x80, 0x8(%r9)
jmp 0x5332
xorl %eax, %eax
jmp 0x534b
movq %r9, %rdi
callq 0x53c8
leaq 0x4e70(%rip), %r10      # 0xa194
leaq 0x50c5(%rip), %r9       # 0xa3f0
leaq 0x4e52(%rip), %r8       # 0xa184
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
cmpq %r15, %rdx
jbe 0x5370
movb $0x0, (%rax,%rbx)
movb $0x1, %al
testb %al, %al
je 0x535e
incl %r13d
movl (%r8), %eax
cmpl %eax, %r13d
jb 0x515e
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1f7f(%rip), %rdi      # 0x72f6
movq %r15, %rsi
jmp 0x5383
leaq 0x1f73(%rip), %rdi      # 0x72f6
xorl %eax, %eax
callq 0x21d0