// File: Ziang95[P]Tomasulo_simulator/memory.cpp
// Function: memory::SD_Q_automat()
void memory::SD_Q_automat()
{
    SDQ_next_vdd = 0;
    while (true)
    {
        at_rising_edge(SDQ_next_vdd);
        pthread_mutex_lock(&SDQ_lock);
        int CDB_i = fCDB.get_source();
        for (int i = Sfront; i != Srear;)
        {
            if (Stor_Q[i].SD_source == CDB_i)
            {
                msg_log("SD queue entry " + to_string(i) + " got the value, source ROB = " + to_string(CDB_i), 3);
                fCDB.get_val(&Stor_Q[i].val);
                Stor_Q[i].SD_source = -1;
            }
            i = (++i)%Q_LEN;
        }
        pthread_mutex_unlock(&SDQ_lock);
        at_falling_edge(SDQ_next_vdd);
        for (int i = Sfront; i != Srear;)
        {
            if (Stor_Q[i].addr != -1)
            {
                Stor_Q[i].ready = true;
                msg_log("Stor_Q entry i = " + to_string(i) + " ready, ROB = " + to_string(Stor_Q[Sfront].rob_i), 3);
            }
            i = (++i)%Q_LEN;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x170(%rbp)
movl $0x0, 0x84(%rax)
movq -0x170(%rbp), %rdi
addq $0x84, %rdi
callq 0x12130
movq -0x170(%rbp), %rdi
addq $0x58, %rdi
callq 0x4510
leaq 0x13e62(%rip), %rdi     # 0x2f510
callq 0x5030
movl %eax, %ecx
movq -0x170(%rbp), %rax
movl %ecx, -0xc(%rbp)
movl 0x14(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x170(%rbp), %rcx
movl -0x10(%rbp), %eax
cmpl 0x18(%rcx), %eax
je 0x1b8ab
movq -0x170(%rbp), %rax
addq $0x1888, %rax           # imm = 0x1888
movslq -0x10(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x1b892
movl -0x10(%rbp), %esi
leaq -0x90(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x8410
movq -0x178(%rbp), %rdx
leaq 0x70fb(%rip), %rsi      # 0x2281b
leaq -0x70(%rbp), %rdi
callq 0x83c0
jmp 0x1b72b
leaq 0x70f9(%rip), %rdx      # 0x2282b
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x8810
jmp 0x1b741
movl -0xc(%rbp), %esi
leaq -0xc0(%rbp), %rdi
callq 0x8410
jmp 0x1b752
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x8740
jmp 0x1b768
leaq -0x30(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0x1b778
leaq -0x30(%rbp), %rdi
callq 0x4240
leaq -0xc0(%rbp), %rdi
callq 0x4240
leaq -0x50(%rbp), %rdi
callq 0x4240
leaq -0x70(%rbp), %rdi
callq 0x4240
leaq -0x90(%rbp), %rdi
callq 0x4240
movq -0x170(%rbp), %rsi
addq $0x1888, %rsi           # imm = 0x1888
movslq -0x10(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
addq $0xc, %rsi
leaq 0x13d41(%rip), %rdi     # 0x2f510
callq 0x5050
movq -0x170(%rbp), %rax
addq $0x1888, %rax           # imm = 0x1888
movslq -0x10(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
jmp 0x1b892
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1b881
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1b878
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1b86f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1b863
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4240
leaq -0xc0(%rbp), %rdi
callq 0x4240
leaq -0x50(%rbp), %rdi
callq 0x4240
leaq -0x70(%rbp), %rdi
callq 0x4240
leaq -0x90(%rbp), %rdi
callq 0x4240
jmp 0x1badf
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, -0x10(%rbp)
jmp 0x1b6c5
movq -0x170(%rbp), %rdi
addq $0x58, %rdi
callq 0x42c0
movq -0x170(%rbp), %rdi
addq $0x84, %rdi
callq 0x121a0
movq -0x170(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0x170(%rbp), %rcx
movl -0xc4(%rbp), %eax
cmpl 0x18(%rcx), %eax
je 0x1bada
movq -0x170(%rbp), %rax
addq $0x1888, %rax           # imm = 0x1888
movslq -0xc4(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x10(%rax)
je 0x1bab8
movq -0x170(%rbp), %rax
movslq -0xc4(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x1, 0x189c(%rax,%rcx,8)
movl -0xc4(%rbp), %esi
leaq -0x148(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x8410
movq -0x180(%rbp), %rdx
leaq 0x6eef(%rip), %rsi      # 0x22849
leaq -0x128(%rbp), %rdi
callq 0x83c0
jmp 0x1b968
leaq 0x6eec(%rip), %rdx      # 0x2285b
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x8810
jmp 0x1b984
movq -0x170(%rbp), %rax
movslq 0x14(%rax), %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x1888(%rax,%rcx,8), %esi
leaq -0x168(%rbp), %rdi
callq 0x8410
jmp 0x1b9a8
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x8740
jmp 0x1b9c4
leaq -0xe8(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0x1b9d7
leaq -0xe8(%rbp), %rdi
callq 0x4240
leaq -0x168(%rbp), %rdi
callq 0x4240
leaq -0x108(%rbp), %rdi
callq 0x4240
leaq -0x128(%rbp), %rdi
callq 0x4240
leaq -0x148(%rbp), %rdi
callq 0x4240
jmp 0x1bab8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1baaa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1ba9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1ba92
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x1ba86
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4240
leaq -0x168(%rbp), %rdi
callq 0x4240
leaq -0x108(%rbp), %rdi
callq 0x4240
leaq -0x128(%rbp), %rdi
callq 0x4240
leaq -0x148(%rbp), %rdi
callq 0x4240
jmp 0x1badf
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, -0xc4(%rbp)
jmp 0x1b8de
jmp 0x1b684
movq -0x98(%rbp), %rdi
callq 0x45f0
nopl (%rax,%rax)