// File: Ziang95[P]Tomasulo_simulator/memory.cpp
// Function: memory::squash(int)
void memory::squash(int ROB_i)
{
    int R_f = CPU_ROB->get_front();
    int R_r = CPU_ROB->get_rear();
    pthread_mutex_lock(&LDQ_lock);
    for (int i = Lrear; ;)
    {
        int j = (i-1)%Q_LEN;
        if (j == Lfront || !is_prev_index(ROB_i, Load_Q[j].rob_i, R_f, R_r))
            break;
        Lrear = j;
        i = (--i)%Q_LEN;
    }
    pthread_mutex_unlock(&LDQ_lock);
    pthread_mutex_lock(&SDQ_lock);
    for (int i = Srear; ;)
    {
        int j = (i-1)%Q_LEN;
        if (j == Srear || !is_prev_index(ROB_i, Stor_Q[j].rob_i, R_f, R_r))
            break;
        Srear = j;
        i = (--i)%Q_LEN;
    }
    pthread_mutex_unlock(&SDQ_lock);
    msg_log("After squash, Store front = " + to_string(Sfront) + " rear = " + to_string(Srear), 3);
    squash_p.R_f = CPU_ROB->get_front();
    squash_p.R_r = CPU_ROB->get_rear();
    squash_p.ROB_i = brcUnit.squash_ROB_i();
    squash_p.flag = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq 0x1412c(%rip), %rax     # 0x2f460
movq (%rax), %rdi
callq 0xe5d0
movl %eax, -0x10(%rbp)
leaq 0x1411a(%rip), %rax     # 0x2f460
movq (%rax), %rdi
callq 0xe5e0
movq -0xe0(%rbp), %rdi
movl %eax, -0x14(%rbp)
addq $0x30, %rdi
callq 0x4510
movq -0xe0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x18(%rbp), %eax
subl $0x1, %eax
movl $0x100, %esi            # imm = 0x100
cltd
idivl %esi
movl %edx, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0xc(%rcx), %eax
je 0x1b3ba
movq -0xe0(%rbp), %rax
movl -0xc(%rbp), %edi
addq $0x88, %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
callq 0x1aec0
testb $0x1, %al
jne 0x1b3bc
jmp 0x1b3df
movq -0xe0(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, 0x10(%rax)
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, -0x18(%rbp)
jmp 0x1b36e
movq -0xe0(%rbp), %rdi
addq $0x30, %rdi
callq 0x42c0
movq -0xe0(%rbp), %rdi
addq $0x58, %rdi
callq 0x4510
movq -0xe0(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl $0x100, %esi            # imm = 0x100
cltd
idivl %esi
movl %edx, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl 0x18(%rcx), %eax
je 0x1b458
movq -0xe0(%rbp), %rax
movl -0xc(%rbp), %edi
addq $0x1888, %rax           # imm = 0x1888
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
callq 0x1aec0
testb $0x1, %al
jne 0x1b45a
jmp 0x1b47d
movq -0xe0(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, 0x18(%rax)
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, -0x20(%rbp)
jmp 0x1b40c
movq -0xe0(%rbp), %rdi
addq $0x58, %rdi
callq 0x42c0
movq -0xe0(%rbp), %rax
movl 0x14(%rax), %esi
leaq -0xa8(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x8410
movq -0xe8(%rbp), %rdx
leaq 0x733d(%rip), %rsi      # 0x227f5
leaq -0x88(%rbp), %rdi
callq 0x83c0
jmp 0x1b4c6
leaq 0x7345(%rip), %rdx      # 0x22812
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x8810
jmp 0x1b4df
movq -0xe0(%rbp), %rax
movl 0x18(%rax), %esi
leaq -0xd8(%rbp), %rdi
callq 0x8410
jmp 0x1b4f7
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x8740
jmp 0x1b50d
leaq -0x48(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0x1b51d
leaq -0x48(%rbp), %rdi
callq 0x4240
leaq -0xd8(%rbp), %rdi
callq 0x4240
leaq -0x68(%rbp), %rdi
callq 0x4240
leaq -0x88(%rbp), %rdi
callq 0x4240
leaq -0xa8(%rbp), %rdi
callq 0x4240
leaq 0x13f06(%rip), %rax     # 0x2f460
movq (%rax), %rdi
callq 0xe5d0
movl %eax, %ecx
movq -0xe0(%rbp), %rax
movl %ecx, 0x1c(%rax)
leaq 0x13eeb(%rip), %rax     # 0x2f460
movq (%rax), %rdi
callq 0xe5e0
movl %eax, %ecx
movq -0xe0(%rbp), %rax
movl %ecx, 0x20(%rax)
leaq 0x13ef8(%rip), %rdi     # 0x2f488
callq 0x105f0
movl %eax, %ecx
movq -0xe0(%rbp), %rax
movl %ecx, 0x24(%rax)
movb $0x1, 0x28(%rax)
addq $0xf0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x1b63a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x1b62e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x1b625
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x1b619
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4240
leaq -0xd8(%rbp), %rdi
callq 0x4240
leaq -0x68(%rbp), %rdi
callq 0x4240
leaq -0x88(%rbp), %rdi
callq 0x4240
leaq -0xa8(%rbp), %rdi
callq 0x4240
movq -0xb0(%rbp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)