// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq 0x48fb(%rip), %rbx      # 0x9538
leaq 0x4520(%rip), %r15      # 0x9164
leaq 0x4745(%rip), %r14      # 0x9390
leaq 0x28(%rsp), %r12
leaq 0x8(%rsp), %r13
movq 0x10(%rbx), %rax
movq 0x30(%rbx), %rcx
cmpq %rax, %rcx
je 0x4db2
movq %rax, 0x8(%rsp)
movups 0x18(%rbx), %xmm0
movups %xmm0, 0x10(%rsp)
movq 0x28(%rbx), %rdx
movq %rdx, 0x20(%rsp)
cmpq %rcx, %rax
je 0x4cbd
movq %rbx, %rdi
callq 0x2ea4
testq %rax, %rax
je 0x4ca5
movq 0x10(%rbx), %rax
cmpl $-0x1, 0x5c(%rax)
jne 0x4ca5
leaq 0x44dc(%rip), %rcx      # 0x917c
movl (%rcx), %ecx
movl %ecx, 0x5c(%rax)
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x3c84
movq 0x30(%rbx), %rcx
movq 0x8(%rsp), %rax
jmp 0x4c7d
xorl %ebp, %ebp
movl (%r15), %eax
cmpq %rax, %rbp
jae 0x4c55
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2ed6
cmpb $0x1, (%rax)
jne 0x4daa
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2ed6
movl 0x90(%rax), %eax
movq 0x10(%rbx), %rcx
cmpl 0x70(%rcx), %eax
jne 0x4daa
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2ed6
movb $0x1, 0x8(%rax)
movq 0x10(%rbx), %rax
movq %rax, 0x8(%rsp)
movups 0x18(%rbx), %xmm0
movups %xmm0, 0x10(%rsp)
movq 0x28(%rbx), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x4452(%rip), %r15      # 0x917c
cmpq 0x30(%rbx), %rax
je 0x4d61
movq %rbx, %rdi
callq 0x2ea4
testq %rax, %rax
je 0x4d4d
movq 0x10(%rbx), %rax
cmpl $-0x1, 0x5c(%rax)
jne 0x4d4d
movl (%r15), %ecx
movl %ecx, 0x5c(%rax)
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x3c84
movq 0x8(%rsp), %rax
jmp 0x4d2a
movl (%r15), %eax
movq 0x10(%rbx), %r15
subl 0x5c(%r15), %eax
incl %eax
movl %eax, 0x60(%r15)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2ed6
leaq 0x20(%rax), %rdi
pushq $0xf
popq %rcx
movq %r15, %rsi
leaq 0x43d6(%rip), %r15      # 0x9164
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
callq 0x3ca4
movq %rbx, %rdi
callq 0x2ea4
testq %rax, %rax
je 0x4c55
incq %rbp
jmp 0x4cbf
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)