// File: Ziang95[P]Tomasulo_simulator/ROB.cpp
// Function: ROB::ROB_automate()
void ROB::ROB_automate()
{
    next_vdd = 0;
    while (true)
    {
        at_rising_edge(next_vdd);
        if (front != rear && buf[front].finished && buf[front].code != SD)
        {
            string rName = buf[front].regName;
            msg_log("Commit " + buf[front].name + " = " + to_string(rName[0]=='R'? buf[front].value.i : buf[front].value.f) + " ROB = " + to_string(front), 2);
            buf[front].output.commit = sys_clk.get_prog_cyc();
            if (buf[front].regName != "NO_RET")
            {
                auto got = RAT.find(rName);
                if (got != RAT.end() && got->second == front)
                    RAT.erase(got);
                reg->set(rName, buf[front].value);
            }
            instr_timeline_output(&buf[front]);
            at_falling_edge(next_vdd);
            ptr_advance();
            msg_log("ROB pointer moved to: " + to_string(front), 3);
        }
        else
        {
            if (front == rear)
                if (instr_Q->finished())
                    sys_clk.end_instr();
            else
                msg_log("ROB waiting for entry (" + to_string(front) + ") to finish", 3);
            at_falling_edge(next_vdd);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x208(%rbp)
movl $0x0, 0x20(%rax)
movq -0x208(%rbp), %rdi
addq $0x20, %rdi
callq 0x12130
movq -0x208(%rbp), %rcx
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
je 0xed92
movq -0x208(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq (%rcx), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
testb $0x1, (%rax)
je 0xed92
movq -0x208(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq (%rcx), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
cmpl $0x7, 0x4c(%rax)
je 0xed92
movq -0x208(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq (%rcx), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x5, %rcx
leaq 0x28(%rax,%rcx), %rsi
leaq -0x28(%rbp), %rdi
callq 0x4180
movq -0x208(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq (%rcx), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x5, %rcx
leaq 0x8(%rax,%rcx), %rdx
leaq 0x139dc(%rip), %rsi     # 0x22248
leaq -0xc8(%rbp), %rdi
callq 0xf080
jmp 0xe87a
leaq 0x13f09(%rip), %rdx     # 0x2278a
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x8810
jmp 0xe896
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0x4690
movq %rax, -0x210(%rbp)
jmp 0xe8ac
movq -0x210(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x52, %eax
jne 0xe8e2
movq -0x208(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq (%rcx), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
cvtsi2ssl 0x48(%rax), %xmm0
movss %xmm0, -0x214(%rbp)
jmp 0xe907
movq -0x208(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq (%rcx), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movss 0x48(%rax), %xmm0
movss %xmm0, -0x214(%rbp)
movss -0x214(%rbp), %xmm0
leaq -0xf8(%rbp), %rdi
callq 0x8860
jmp 0xe91d
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x8740
jmp 0xe939
leaq 0x13e46(%rip), %rdx     # 0x22786
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x8810
jmp 0xe952
movq -0x208(%rbp), %rax
movl (%rax), %esi
leaq -0x118(%rbp), %rdi
callq 0x8410
jmp 0xe969
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0x8740
jmp 0xe97f
leaq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x12060
jmp 0xe98f
leaq -0x48(%rbp), %rdi
callq 0x4240
leaq -0x118(%rbp), %rdi
callq 0x4240
leaq -0x68(%rbp), %rdi
callq 0x4240
leaq -0x88(%rbp), %rdi
callq 0x4240
leaq -0xf8(%rbp), %rdi
callq 0x4240
leaq -0xa8(%rbp), %rdi
callq 0x4240
leaq -0xc8(%rbp), %rdi
callq 0x4240
leaq 0x213b4(%rip), %rdi     # 0x2fd98
callq 0x116c0
movl %eax, -0x218(%rbp)
jmp 0xe9f1
movq -0x208(%rbp), %rcx
movl -0x218(%rbp), %esi
movq 0x8(%rcx), %rax
movslq (%rcx), %rdx
leaq (%rdx,%rdx,4), %rdx
shlq $0x5, %rdx
movl %esi, 0x60(%rax,%rdx)
movq 0x8(%rcx), %rax
movslq (%rcx), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x5, %rcx
leaq 0x28(%rax,%rcx), %rdi
leaq 0x13824(%rip), %rsi     # 0x22250
callq 0xf190
movb %al, -0x219(%rbp)
jmp 0xea39
movb -0x219(%rbp), %al
testb $0x1, %al
jne 0xea48
jmp 0xec9c
leaq 0x21309(%rip), %rdi     # 0x2fd58
leaq -0x28(%rbp), %rsi
callq 0xf1c0
movq %rax, -0x228(%rbp)
jmp 0xea61
movq -0x228(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq 0x212e2(%rip), %rdi     # 0x2fd58
callq 0xf220
movq %rax, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0xf1f0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x229(%rbp)
jne 0xeaa6
jmp 0xeac7
leaq -0x120(%rbp), %rdi
callq 0xf250
movq -0x208(%rbp), %rcx
movl 0x20(%rax), %eax
cmpl (%rcx), %eax
sete %al
movb %al, -0x229(%rbp)
movb -0x229(%rbp), %al
testb $0x1, %al
jne 0xead6
jmp 0xec0d
movq -0x120(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rsi
leaq 0x21266(%rip), %rdi     # 0x2fd58
callq 0xf280
movq %rax, -0x238(%rbp)
jmp 0xeb00
movq -0x238(%rbp), %rax
movq %rax, -0x138(%rbp)
jmp 0xec0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xed84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xebfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xebf0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xebe4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xebd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xebcf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xebc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4240
leaq -0x118(%rbp), %rdi
callq 0x4240
leaq -0x68(%rbp), %rdi
callq 0x4240
leaq -0x88(%rbp), %rdi
callq 0x4240
leaq -0xf8(%rbp), %rdi
callq 0x4240
leaq -0xa8(%rbp), %rdi
callq 0x4240
leaq -0xc8(%rbp), %rdi
callq 0x4240
jmp 0xed84
leaq 0x2117c(%rip), %rax     # 0x2fd90
movq (%rax), %rax
movq %rax, -0x240(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4180
jmp 0xec30
movq -0x240(%rbp), %rdi
movq -0x208(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq (%rcx), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x5, %rcx
movl 0x48(%rax,%rcx), %eax
movl %eax, -0x15c(%rbp)
movl -0x15c(%rbp), %edx
leaq -0x158(%rbp), %rsi
callq 0x208f0
jmp 0xec6b
leaq -0x158(%rbp), %rdi
callq 0x4240
jmp 0xec9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x4240
jmp 0xed84
movq -0x208(%rbp), %rax
movq 0x8(%rax), %rdi
movslq (%rax), %rax
leaq (%rax,%rax,4), %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x1cfd0
jmp 0xecbc
movq -0x208(%rbp), %rdi
addq $0x20, %rdi
callq 0x121a0
jmp 0xecce
movq -0x208(%rbp), %rdi
callq 0xe5a0
movq -0x208(%rbp), %rax
movl (%rax), %esi
leaq -0x1a0(%rbp), %rdi
callq 0x8410
jmp 0xecf1
leaq 0x1355f(%rip), %rsi     # 0x22257
leaq -0x180(%rbp), %rdi
leaq -0x1a0(%rbp), %rdx
callq 0x83c0
jmp 0xed0d
leaq -0x180(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0xed20
leaq -0x180(%rbp), %rdi
callq 0x4240
leaq -0x1a0(%rbp), %rdi
callq 0x4240
leaq -0x28(%rbp), %rdi
callq 0x4240
jmp 0xeec9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xed78
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x4240
leaq -0x1a0(%rbp), %rdi
callq 0x4240
leaq -0x28(%rbp), %rdi
callq 0x4240
jmp 0xeece
movq -0x208(%rbp), %rcx
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
jne 0xeeb9
leaq 0x206ad(%rip), %rax     # 0x2f458
movq (%rax), %rdi
callq 0x17800
testb $0x1, %al
jne 0xedb9
jmp 0xedca
leaq 0x20fd8(%rip), %rdi     # 0x2fd98
callq 0x11700
jmp 0xeeb7
movq -0x208(%rbp), %rax
movl (%rax), %esi
leaq -0x200(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x8410
movq -0x248(%rbp), %rdx
leaq 0x1347a(%rip), %rsi     # 0x2226e
leaq -0x1e0(%rbp), %rdi
callq 0x83c0
jmp 0xee02
leaq 0x1347d(%rip), %rdx     # 0x22286
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x8810
jmp 0xee1e
leaq -0x1c0(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0xee31
leaq -0x1c0(%rbp), %rdi
callq 0x4240
leaq -0x1e0(%rbp), %rdi
callq 0x4240
leaq -0x200(%rbp), %rdi
callq 0x4240
jmp 0xeeb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xeea9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xee9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x4240
leaq -0x1e0(%rbp), %rdi
callq 0x4240
leaq -0x200(%rbp), %rdi
callq 0x4240
jmp 0xeece
jmp 0xeeb9
movq -0x208(%rbp), %rdi
addq $0x20, %rdi
callq 0x121a0
jmp 0xe7c1
movq -0xd0(%rbp), %rdi
callq 0x45f0
nopw (%rax,%rax)