// File: dsesami[P]superscalar-processor-model/regRead.cc
// Function: regRead()
void regRead(){
    for(u_int i=0; i<WIDTH; i++) {

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

        // If the dispatch register is full, do nothing.
        if(DI_register.size() == WIDTH) {
            return;
        }
        // Otherwise check if values in the rob are ready, and if so, and move things forward.
        else if(RR_register.size()) {
            // Wake appropriate dependents! Since we do not have actual register values,
            // simply indicate that we have "ready" sources by indicating that they are not renamed.
            // Wake source 1:
            if(RR_register.front().rn_src_1 != -1) {
                if(ROB.at(RR_register.front().rn_src_1).ready) {
                    RR_register.front().rn_src_1 = -1;
                }
            }
            // Wake source 2:
            if(RR_register.front().rn_src_2 != -1) {
                if(ROB.at(RR_register.front().rn_src_2).ready) {
                    RR_register.front().rn_src_2 = -1;
                }
            }
        for(deque<bundle>::iterator it = RR_register.begin(); it != RR_register.end(); it++) {
            if(RR_register.size() && it->regRead_first == -1)
                it->regRead_first = cycles;
        }

            // Finally, move this bundle to the DI register.
            RR_register.front().regRead_time = cycles - RR_register.front().regRead_first+1;
            DI_register.push_back(RR_register.front());
            RR_register.pop_front();
        }
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
leaq 0x9668(%rip), %rcx      # 0x111c4
cmpl (%rcx), %eax
jae 0x7dd4
leaq -0x28(%rbp), %rdi
leaq 0x9981(%rip), %rsi      # 0x114f0
callq 0x5050
leaq -0x48(%rbp), %rdi
leaq 0x9971(%rip), %rsi      # 0x114f0
callq 0x5080
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x7350
testb $0x1, %al
jne 0x7b97
jmp 0x7bec
leaq 0x9952(%rip), %rdi      # 0x114f0
callq 0x3700
cmpq $0x0, %rax
je 0x7bd9
leaq -0x28(%rbp), %rdi
callq 0x7380
cmpl $-0x1, 0x3c(%rax)
jne 0x7bd9
leaq 0x9615(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xcc(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x7380
movl -0xcc(%rbp), %ecx
movl %ecx, 0x3c(%rax)
jmp 0x7bdb
leaq -0x68(%rbp), %rdi
leaq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x73a0
jmp 0x7b74
leaq 0x994d(%rip), %rdi      # 0x11540
callq 0x3700
leaq 0x95c5(%rip), %rcx      # 0x111c4
movl (%rcx), %ecx
cmpq %rcx, %rax
jne 0x7c0b
jmp 0x7dd6
leaq 0x98de(%rip), %rdi      # 0x114f0
callq 0x3700
cmpq $0x0, %rax
je 0x7dc2
leaq 0x98c8(%rip), %rdi      # 0x114f0
callq 0x73e0
cmpl $-0x1, 0x18(%rax)
je 0x7c6a
leaq 0x98b6(%rip), %rdi      # 0x114f0
callq 0x73e0
movslq 0x18(%rax), %rsi
leaq 0x979e(%rip), %rdi      # 0x113e8
callq 0x3790
testb $0x1, 0x8(%rax)
je 0x7c68
leaq 0x9894(%rip), %rdi      # 0x114f0
callq 0x73e0
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
jmp 0x7c6a
leaq 0x987f(%rip), %rdi      # 0x114f0
callq 0x73e0
cmpl $-0x1, 0x20(%rax)
je 0x7cb3
leaq 0x986d(%rip), %rdi      # 0x114f0
callq 0x73e0
movslq 0x20(%rax), %rsi
leaq 0x9755(%rip), %rdi      # 0x113e8
callq 0x3790
testb $0x1, 0x8(%rax)
je 0x7cb1
leaq 0x984b(%rip), %rdi      # 0x114f0
callq 0x73e0
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
jmp 0x7cb3
leaq -0x88(%rbp), %rdi
leaq 0x982f(%rip), %rsi      # 0x114f0
callq 0x5050
leaq -0xa8(%rbp), %rdi
leaq 0x981c(%rip), %rsi      # 0x114f0
callq 0x5080
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7350
testb $0x1, %al
jne 0x7cf2
jmp 0x7d56
leaq 0x97f7(%rip), %rdi      # 0x114f0
callq 0x3700
cmpq $0x0, %rax
je 0x7d3a
leaq -0x88(%rbp), %rdi
callq 0x7380
cmpl $-0x1, 0x3c(%rax)
jne 0x7d3a
leaq 0x94b7(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xd0(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x7380
movl -0xd0(%rbp), %ecx
movl %ecx, 0x3c(%rax)
jmp 0x7d3c
leaq -0xc8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
xorl %edx, %edx
callq 0x73a0
jmp 0x7cc6
leaq 0x9477(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xd8(%rbp)
leaq 0x9784(%rip), %rdi      # 0x114f0
callq 0x73e0
movq %rax, %rcx
movl -0xd8(%rbp), %eax
subl 0x3c(%rcx), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
leaq 0x9763(%rip), %rdi      # 0x114f0
callq 0x73e0
movl -0xd4(%rbp), %ecx
movl %ecx, 0x40(%rax)
leaq 0x974e(%rip), %rdi      # 0x114f0
callq 0x73e0
movq %rax, %rsi
leaq 0x978f(%rip), %rdi      # 0x11540
callq 0x6960
leaq 0x9733(%rip), %rdi      # 0x114f0
callq 0x7410
jmp 0x7dc4
jmp 0x7dc6
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x7b52
jmp 0x7dd6
addq $0xe0, %rsp
popq %rbp
retq
nop