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

    //execute_status();
    // If there are no instructions, do nothing.
    if(!execute_list.size()) return;

    // Decrease the age of all the instructions in the execute list.
    for(u_int i=0;i < execute_list.size(); i++) {

        // AGE PROCESSING INFORMATION...
        if(execute_list.at(i).instruction.execute_first == -1) {
            execute_list.at(i).instruction.execute_first = cycles;
        }

        // decrease execution counter.
        execute_list.at(i).age--;
    }
    while(execute_needed()){
        for(u_int i=0;i < execute_list.size(); i++) {
            // If it is finishing execution this cycle...
            if(!execute_list.at(i).age) {
                // Wake up IQ by matching ROB values and setting it to ready.
                for(u_int j=0; j<IQ_SIZE; j++) {
                    if((IQ.at(j).instruction.rn_src_1 ==
                                execute_list.at(i).instruction.rn_dest) && (IQ.at(j).instruction.rn_src_1 != -1)) {
                        IQ.at(j).instruction.rn_src_1 = -1;
                    }
                    if((IQ.at(j).instruction.rn_src_2 ==
                                execute_list.at(i).instruction.rn_dest) && (IQ.at(j).instruction.rn_src_2 != -1)) {
                        IQ.at(j).instruction.rn_src_2 = -1;
                    }
                }
                // Wake up DI
                for(deque<bundle>::iterator j=DI_register.begin(); j!=DI_register.end(); j++) {
                    if(!DI_register.size()) break;
                    if(j->rn_src_1 == execute_list.at(i).instruction.rn_dest) {
                        j->rn_src_1 = -1;
                    }
                    if(j->rn_src_2 == execute_list.at(i).instruction.rn_dest) {
                        j->rn_src_2 = -1;
                    }
                }

                // Wake up RR
                for(deque<bundle>::iterator j=DI_register.begin(); j!=DI_register.end(); j++) {
                    if(!RR_register.size()) break;
                    if(j->rn_src_1 == execute_list.at(i).instruction.rn_dest) {
                        j->rn_src_1 = -1;
                    }
                    if(j->rn_src_2 == execute_list.at(i).instruction.rn_dest) {
                        j->rn_src_2 = -1;
                    }
                }

                if(WB_register.size() == WIDTH*5) {
                    return;
                }
                // Add to WB pipeline register.
                execute_list.at(i).instruction.execute_time = cycles - execute_list.at(i).instruction.execute_first+1;
                execute_list.at(i).instruction.valid = true;
                bundle instruction = execute_list.at(i).instruction;
                WB_register.push_back(instruction);

                // Remove from execution list.
                execute_list.erase(execute_list.begin()+i);
            }
        }
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
leaq 0x884e(%rip), %rdi      # 0x11430
callq 0x3730
cmpq $0x0, %rax
jne 0x8bf2
jmp 0x90ef
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
movq %rax, -0x170(%rbp)
leaq 0x8826(%rip), %rdi      # 0x11430
callq 0x3730
movq %rax, %rcx
movq -0x170(%rbp), %rax
cmpq %rcx, %rax
jae 0x8c86
movl -0x4(%rbp), %eax
movl %eax, %esi
leaq 0x8806(%rip), %rdi      # 0x11430
callq 0x9260
cmpl $-0x1, 0x54(%rax)
jne 0x8c5e
leaq 0x8598(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0x174(%rbp)
movl -0x4(%rbp), %eax
movl %eax, %esi
leaq 0x87e0(%rip), %rdi      # 0x11430
callq 0x9260
movl -0x174(%rbp), %ecx
movl %ecx, 0x54(%rax)
movl -0x4(%rbp), %eax
movl %eax, %esi
leaq 0x87c6(%rip), %rdi      # 0x11430
callq 0x9260
movl 0x78(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x78(%rax)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x8bf9
jmp 0x8c88
callq 0x9100
testb $0x1, %al
jne 0x8c96
jmp 0x90ed
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
movq %rax, -0x180(%rbp)
leaq 0x8782(%rip), %rdi      # 0x11430
callq 0x3730
movq %rax, %rcx
movq -0x180(%rbp), %rax
cmpq %rcx, %rax
jae 0x90e8
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x875e(%rip), %rdi      # 0x11430
callq 0x9260
cmpl $0x0, 0x78(%rax)
jne 0x90d8
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
leaq 0x84ce(%rip), %rcx      # 0x111c0
cmpl (%rcx), %eax
jae 0x8dda
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x8712(%rip), %rdi      # 0x11418
callq 0x3750
movl 0x20(%rax), %eax
movl %eax, -0x184(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x8710(%rip), %rdi      # 0x11430
callq 0x9260
movq %rax, %rcx
movl -0x184(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x8d62
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x86d9(%rip), %rdi      # 0x11418
callq 0x3750
cmpl $-0x1, 0x20(%rax)
je 0x8d62
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x86c2(%rip), %rdi      # 0x11418
callq 0x3750
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x86aa(%rip), %rdi      # 0x11418
callq 0x3750
movl 0x28(%rax), %eax
movl %eax, -0x188(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x86a8(%rip), %rdi      # 0x11430
callq 0x9260
movq %rax, %rcx
movl -0x188(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x8dca
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x8671(%rip), %rdi      # 0x11418
callq 0x3750
cmpl $-0x1, 0x28(%rax)
je 0x8dca
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x865a(%rip), %rdi      # 0x11418
callq 0x3750
movl $0xffffffff, 0x28(%rax) # imm = 0xFFFFFFFF
jmp 0x8dcc
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8ce8
leaq -0x30(%rbp), %rdi
leaq 0x875b(%rip), %rsi      # 0x11540
callq 0x5050
leaq -0x50(%rbp), %rdi
leaq 0x874b(%rip), %rsi      # 0x11540
callq 0x5080
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x7350
testb $0x1, %al
jne 0x8e10
jmp 0x8ebf
leaq 0x8729(%rip), %rdi      # 0x11540
callq 0x3700
cmpq $0x0, %rax
jne 0x8e27
jmp 0x8ebf
leaq -0x30(%rbp), %rdi
callq 0x7380
movl 0x18(%rax), %eax
movl %eax, -0x18c(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x85eb(%rip), %rdi      # 0x11430
callq 0x9260
movq %rax, %rcx
movl -0x18c(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x8e68
leaq -0x30(%rbp), %rdi
callq 0x7380
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
leaq -0x30(%rbp), %rdi
callq 0x7380
movl 0x20(%rax), %eax
movl %eax, -0x190(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x85aa(%rip), %rdi      # 0x11430
callq 0x9260
movq %rax, %rcx
movl -0x190(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x8ea9
leaq -0x30(%rbp), %rdi
callq 0x7380
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
jmp 0x8eab
leaq -0x70(%rbp), %rdi
leaq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x73a0
jmp 0x8dea
leaq -0x90(%rbp), %rdi
leaq 0x8673(%rip), %rsi      # 0x11540
callq 0x5050
leaq -0xb0(%rbp), %rdi
leaq 0x8660(%rip), %rsi      # 0x11540
callq 0x5080
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x7350
testb $0x1, %al
jne 0x8f01
jmp 0x8fc2
leaq 0x85e8(%rip), %rdi      # 0x114f0
callq 0x3700
cmpq $0x0, %rax
jne 0x8f18
jmp 0x8fc2
leaq -0x90(%rbp), %rdi
callq 0x7380
movl 0x18(%rax), %eax
movl %eax, -0x194(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x84f7(%rip), %rdi      # 0x11430
callq 0x9260
movq %rax, %rcx
movl -0x194(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x8f5f
leaq -0x90(%rbp), %rdi
callq 0x7380
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
leaq -0x90(%rbp), %rdi
callq 0x7380
movl 0x20(%rax), %eax
movl %eax, -0x198(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x84b0(%rip), %rdi      # 0x11430
callq 0x9260
movq %rax, %rcx
movl -0x198(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x8fa6
leaq -0x90(%rbp), %rdi
callq 0x7380
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
jmp 0x8fa8
leaq -0xd0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
xorl %edx, %edx
callq 0x73a0
jmp 0x8ed2
leaq 0x85c7(%rip), %rdi      # 0x11590
callq 0x3700
leaq 0x81ef(%rip), %rcx      # 0x111c4
imull $0x5, (%rcx), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x8fe4
jmp 0x90ef
leaq 0x81e9(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0x1a0(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x8431(%rip), %rdi      # 0x11430
callq 0x9260
movq %rax, %rcx
movl -0x1a0(%rbp), %eax
subl 0x54(%rcx), %eax
addl $0x1, %eax
movl %eax, -0x19c(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x840b(%rip), %rdi      # 0x11430
callq 0x9260
movl -0x19c(%rbp), %ecx
movl %ecx, 0x58(%rax)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x83f1(%rip), %rdi      # 0x11430
callq 0x9260
movb $0x1, 0x6c(%rax)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq 0x83dc(%rip), %rdi      # 0x11430
callq 0x9260
movq %rax, %rsi
leaq -0x148(%rbp), %rdi
movl $0x78, %edx
callq 0x2160
leaq 0x851c(%rip), %rdi      # 0x11590
leaq -0x148(%rbp), %rsi
callq 0x6960
leaq 0x83a9(%rip), %rdi      # 0x11430
callq 0x8850
movq %rax, -0x160(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %esi
leaq -0x160(%rbp), %rdi
callq 0x9310
movq %rax, -0x158(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x9350
movq -0x150(%rbp), %rsi
leaq 0x8364(%rip), %rdi      # 0x11430
callq 0x92a0
movq %rax, -0x168(%rbp)
jmp 0x90da
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x8c9d
jmp 0x8c88
jmp 0x90ef
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopl (%rax,%rax)