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


    // set first cycle and duration of this instruction.
        for(deque<bundle>::iterator it = DI_register.begin(); it != DI_register.end(); it++) {
            if(DI_register.size() && it->dispatch_first == -1)
                it->dispatch_first = cycles;
        }

    // If there isn't enough room in the IQ for the entire bundle set, do nothing.
    if(isiqfull()) {
        return;
    }
    // Otherwise move everything to the IQ.
    else if(DI_register.size()) {
        while(DI_register.size()) {
            for(u_int j=0; j<IQ_SIZE; j++) {
                if (IQ.at(j).valid) continue;

                // wake source 1:
                if(DI_register.front().rn_src_1 != -1) {
                    if(ROB.at(DI_register.front().rn_src_1).ready) {
                        DI_register.front().rn_src_1 = -1;
                    }
                }
                // Wake source 2:
                if(DI_register.front().rn_src_2 != -1) {
                    if(ROB.at(DI_register.front().rn_src_2).ready) {
                        DI_register.front().rn_src_2 = -1;
                    }
                }

        for(deque<bundle>::iterator it = DI_register.begin(); it != DI_register.end(); it++) {
            if(DI_register.size() && it->dispatch_first == -1)
                it->dispatch_first = cycles;
        }

                DI_register.front().dispatch_time = cycles - DI_register.front().dispatch_first+1;
                IQ.at(j).valid = true;
                IQ.at(j).instruction = DI_register.front();
                break;
            }
            if(!DI_register.size()) break;
            else DI_register.pop_front();
        }
    }

    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
leaq -0x20(%rbp), %rdi
leaq 0x974a(%rip), %rsi      # 0x11540
callq 0x5050
leaq -0x40(%rbp), %rdi
leaq 0x973a(%rip), %rsi      # 0x11540
callq 0x5080
leaq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x7350
testb $0x1, %al
jne 0x7e1e
jmp 0x7e73
leaq 0x971b(%rip), %rdi      # 0x11540
callq 0x3700
cmpq $0x0, %rax
je 0x7e60
leaq -0x20(%rbp), %rdi
callq 0x7380
cmpl $-0x1, 0x44(%rax)
jne 0x7e60
leaq 0x938e(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xcc(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x7380
movl -0xcc(%rbp), %ecx
movl %ecx, 0x44(%rax)
jmp 0x7e62
leaq -0x60(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x73a0
jmp 0x7dfb
callq 0x8100
testb $0x1, %al
jne 0x7e7e
jmp 0x7e83
jmp 0x80ea
leaq 0x96b6(%rip), %rdi      # 0x11540
callq 0x3700
cmpq $0x0, %rax
je 0x80e6
jmp 0x7e9b
leaq 0x969e(%rip), %rdi      # 0x11540
callq 0x3700
cmpq $0x0, %rax
je 0x80e4
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
leaq 0x92fe(%rip), %rcx      # 0x111c0
cmpl (%rcx), %eax
jae 0x80bf
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq 0x9542(%rip), %rdi      # 0x11418
callq 0x3750
testb $0x1, (%rax)
je 0x7ee5
jmp 0x80b1
leaq 0x9654(%rip), %rdi      # 0x11540
callq 0x73e0
cmpl $-0x1, 0x18(%rax)
je 0x7f2e
leaq 0x9642(%rip), %rdi      # 0x11540
callq 0x73e0
movslq 0x18(%rax), %rsi
leaq 0x94da(%rip), %rdi      # 0x113e8
callq 0x3790
testb $0x1, 0x8(%rax)
je 0x7f2c
leaq 0x9620(%rip), %rdi      # 0x11540
callq 0x73e0
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
jmp 0x7f2e
leaq 0x960b(%rip), %rdi      # 0x11540
callq 0x73e0
cmpl $-0x1, 0x20(%rax)
je 0x7f77
leaq 0x95f9(%rip), %rdi      # 0x11540
callq 0x73e0
movslq 0x20(%rax), %rsi
leaq 0x9491(%rip), %rdi      # 0x113e8
callq 0x3790
testb $0x1, 0x8(%rax)
je 0x7f75
leaq 0x95d7(%rip), %rdi      # 0x11540
callq 0x73e0
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
jmp 0x7f77
leaq -0x88(%rbp), %rdi
leaq 0x95bb(%rip), %rsi      # 0x11540
callq 0x5050
leaq -0xa8(%rbp), %rdi
leaq 0x95a8(%rip), %rsi      # 0x11540
callq 0x5080
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7350
testb $0x1, %al
jne 0x7fb6
jmp 0x801a
leaq 0x9583(%rip), %rdi      # 0x11540
callq 0x3700
cmpq $0x0, %rax
je 0x7ffe
leaq -0x88(%rbp), %rdi
callq 0x7380
cmpl $-0x1, 0x44(%rax)
jne 0x7ffe
leaq 0x91f3(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xd0(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x7380
movl -0xd0(%rbp), %ecx
movl %ecx, 0x44(%rax)
jmp 0x8000
leaq -0xc8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
xorl %edx, %edx
callq 0x73a0
jmp 0x7f8a
leaq 0x91b3(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xe0(%rbp)
leaq 0x9510(%rip), %rdi      # 0x11540
callq 0x73e0
movq %rax, %rcx
movl -0xe0(%rbp), %eax
subl 0x44(%rcx), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
leaq 0x94ef(%rip), %rdi      # 0x11540
callq 0x73e0
movl -0xdc(%rbp), %ecx
movl %ecx, 0x48(%rax)
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq 0x93ad(%rip), %rdi      # 0x11418
callq 0x3750
movb $0x1, (%rax)
leaq 0x94c6(%rip), %rdi      # 0x11540
callq 0x73e0
movq %rax, -0xd8(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq 0x9386(%rip), %rdi      # 0x11418
callq 0x3750
movq -0xd8(%rbp), %rsi
movq %rax, %rdi
addq $0x8, %rdi
movl $0x78, %edx
callq 0x2160
jmp 0x80bf
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x7eb8
leaq 0x947a(%rip), %rdi      # 0x11540
callq 0x3700
cmpq $0x0, %rax
jne 0x80d3
jmp 0x80e4
leaq 0x9466(%rip), %rdi      # 0x11540
callq 0x7410
jmp 0x7e9b
jmp 0x80e6
jmp 0x80e8
jmp 0x80ea
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)