// File: dsesami[P]superscalar-processor-model/writeback.cc
// Function: writeback()
void writeback(){
    while(!WB_register.empty()) {
        // Process the age of the instruction.
        for(deque<bundle>::iterator it = WB_register.begin(); it != WB_register.end(); it++) {
            if(WB_register.size() && WB_register.front().writeback_first == -1)
                WB_register.front().writeback_first = cycles;
        }

        // Mark the instruction as ready within the ROB.
        for(u_int j=0; j < ROBSIZE; j++) {
            if(ROB.at(j).valid) {
                if (ROB.at(j).instruction.dyn == WB_register.front().dyn) {
                    ROB.at(j).ready = true;
                    for(deque<bundle>::iterator it = WB_register.begin();it!=WB_register.end();it++) {
                        if(WB_register.size() && WB_register.front().writeback_first == -1)
                            WB_register.front().writeback_first = cycles;
                    }
                    WB_register.front().writeback_time = cycles - WB_register.front().writeback_first+1;
                    ROB.at(j).instruction = WB_register.front();
                    WB_register.pop_front();
                    if(WB_register.size() == 0) break;
                }
            }
        }
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
leaq 0x7d3e(%rip), %rdi      # 0x11590
callq 0x9ae0
xorb $-0x1, %al
testb $0x1, %al
jne 0x9862
jmp 0x9ad0
leaq -0x20(%rbp), %rdi
leaq 0x7d23(%rip), %rsi      # 0x11590
callq 0x5050
leaq -0x40(%rbp), %rdi
leaq 0x7d13(%rip), %rsi      # 0x11590
callq 0x5080
leaq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x7350
testb $0x1, %al
jne 0x9895
jmp 0x98f0
leaq 0x7cf4(%rip), %rdi      # 0x11590
callq 0x3700
cmpq $0x0, %rax
je 0x98dd
leaq 0x7ce2(%rip), %rdi      # 0x11590
callq 0x73e0
cmpl $-0x1, 0x5c(%rax)
jne 0x98dd
leaq 0x7914(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xcc(%rbp)
leaq 0x7cc1(%rip), %rdi      # 0x11590
callq 0x73e0
movl -0xcc(%rbp), %ecx
movl %ecx, 0x5c(%rax)
jmp 0x98df
leaq -0x60(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x73a0
jmp 0x9872
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
leaq 0x78bb(%rip), %rcx      # 0x111bc
cmpl (%rcx), %eax
jae 0x9acb
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq 0x7ad3(%rip), %rdi      # 0x113e8
callq 0x3790
testb $0x1, (%rax)
je 0x9abb
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq 0x7ab9(%rip), %rdi      # 0x113e8
callq 0x3790
movl 0x90(%rax), %eax
movl %eax, -0xd0(%rbp)
leaq 0x7c49(%rip), %rdi      # 0x11590
callq 0x73e0
movq %rax, %rcx
movl -0xd0(%rbp), %eax
cmpl 0x70(%rcx), %eax
jne 0x9ab9
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq 0x7a7e(%rip), %rdi      # 0x113e8
callq 0x3790
movb $0x1, 0x8(%rax)
leaq -0x88(%rbp), %rdi
leaq 0x7c0f(%rip), %rsi      # 0x11590
callq 0x5050
leaq -0xa8(%rbp), %rdi
leaq 0x7bfc(%rip), %rsi      # 0x11590
callq 0x5080
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7350
testb $0x1, %al
jne 0x99b2
jmp 0x9a16
leaq 0x7bd7(%rip), %rdi      # 0x11590
callq 0x3700
cmpq $0x0, %rax
je 0x99fa
leaq 0x7bc5(%rip), %rdi      # 0x11590
callq 0x73e0
cmpl $-0x1, 0x5c(%rax)
jne 0x99fa
leaq 0x77f7(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xd4(%rbp)
leaq 0x7ba4(%rip), %rdi      # 0x11590
callq 0x73e0
movl -0xd4(%rbp), %ecx
movl %ecx, 0x5c(%rax)
jmp 0x99fc
leaq -0xc8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
xorl %edx, %edx
callq 0x73a0
jmp 0x9986
leaq 0x77b7(%rip), %rax      # 0x111d4
movl (%rax), %eax
movl %eax, -0xe8(%rbp)
leaq 0x7b64(%rip), %rdi      # 0x11590
callq 0x73e0
movq %rax, %rcx
movl -0xe8(%rbp), %eax
subl 0x5c(%rcx), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
leaq 0x7b43(%rip), %rdi      # 0x11590
callq 0x73e0
movl -0xe4(%rbp), %ecx
movl %ecx, 0x60(%rax)
leaq 0x7b2e(%rip), %rdi      # 0x11590
callq 0x73e0
movq %rax, -0xe0(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %esi
leaq 0x796e(%rip), %rdi      # 0x113e8
callq 0x3790
movq -0xe0(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rdi
movl $0x78, %edx
callq 0x2160
leaq 0x7af2(%rip), %rdi      # 0x11590
callq 0x7410
leaq 0x7ae6(%rip), %rdi      # 0x11590
callq 0x3700
cmpq $0x0, %rax
jne 0x9ab7
jmp 0x9acb
jmp 0x9ab9
jmp 0x9abb
jmp 0x9abd
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x98f7
jmp 0x984b
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)