// File: /workspace/github_cpp_makefile_star2_O2/Ziang95[P]Tomasulo_simulator/memory.cpp
// Function: memory::load(LSQEntry)
bool memory::load(LSQEntry entry)
{
    ROBEntry *R = CPU_ROB->get_entry(entry.rob_i);
    int found = -1;
    bool no_blocking_SD = true;
    memCell ret;
    for (int i = Srear; is_prev_index(Sfront, i, Sfront, Srear);)
    {
        i = (--i)%Q_LEN;
        if (is_prev_index(Stor_Q[i].rob_i, entry.rob_i, CPU_ROB->get_front(), CPU_ROB->get_rear()))
        {
            if (Stor_Q[i].addr == -1)
            {
                no_blocking_SD = false;
                break;
            }
            else
            {
                if (Stor_Q[i].addr == entry.addr && found == -1)
                {
                    if (Stor_Q[i].ready)
                        found = i;
                    else
                    {
                        no_blocking_SD = false;
                        break;
                    }
                }
            }
        }
    }
    if (no_blocking_SD)
    {
        R->output.mem = sys_clk.get_prog_cyc();
        if (found >= 0)
        {
            msg_log("Forward store found, forwarding, Addr="+to_string(Stor_Q[found].addr), 3);
            ret = Stor_Q[found].val;
        }
        else
        {
            msg_log("Begin LD, ROB = " + to_string(entry.rob_i), 3);
            for (int i = 0; ; i++)
            {
                if (squash_p.flag)
                {
                    squash_p.flag = false;
                    if (is_prev_index(brcUnit.squash_ROB_i(), entry.rob_i, squash_p.R_f, squash_p.R_r))
                    {
                        at_falling_edge(mem_next_vdd);
                        return true;
                    }
                }
                if (i == CPU_cfg->ld_str->mem_time - 1)
                {
                    ret = buf[entry.addr];
                    break;
                }
                at_falling_edge(mem_next_vdd);
                at_rising_edge(mem_next_vdd);
                msg_log("Loading value from Addr="+to_string(entry.addr), 3);
            }
        }
        fCDB.enQ(&ret, entry.rob_i);
        at_falling_edge(mem_next_vdd);
        Lfront = (++Lfront)%Q_LEN;
        msg_log("Value loaded ROB = " + to_string(entry.rob_i), 2);
    }
    else
    {
        msg_log("Previous SD not ready, caller ROB = " + to_string(Load_Q[Lfront].rob_i), 3);
        at_falling_edge(mem_next_vdd);
    }
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %r13
leaq 0xa354(%rip), %rax      # 0x16370
movq (%rax), %rdi
movl 0x10(%rbp), %esi
movl %esi, -0x2c(%rbp)
callq 0x6c7e
movq %rax, -0x68(%rbp)
movl 0x18(%r13), %ecx
leaq 0x1888(%r13), %r12
movslq 0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
pushq $-0x1
popq %rax
movl %eax, -0x30(%rbp)
movl %ecx, %r15d
movq %r13, -0x38(%rbp)
movl 0x14(%r13), %edi
movl %r15d, %esi
movl %edi, %edx
callq 0xc3de
testb %al, %al
je 0xc0fb
decl %r15d
movl %r15d, %eax
cltd
movl $0x100, %ecx            # imm = 0x100
idivl %ecx
movl %edx, %r15d
movslq %edx, %rax
imulq $0x18, %rax, %r14
movl (%r12,%r14), %r13d
leaq 0xa2e9(%rip), %rax      # 0x16370
movq (%rax), %rdi
callq 0x6cf4
movq %r12, %rbx
movl %eax, %r12d
leaq 0xa2d4(%rip), %rax      # 0x16370
movq (%rax), %rdi
callq 0x6cfc
movl %r13d, %edi
movl -0x2c(%rbp), %esi
movl %r12d, %edx
movl %eax, %ecx
callq 0xc3de
testb %al, %al
je 0xc0eb
addq %rbx, %r14
movl 0x10(%r14), %eax
cmpl $-0x1, %eax
movq -0x38(%rbp), %r13
je 0xc176
movq %rbx, %r12
xorl -0x40(%rbp), %eax
movl -0x30(%rbp), %ecx
notl %ecx
orl %eax, %ecx
jne 0xc0f2
cmpb $0x1, 0x14(%r14)
movl %r15d, -0x30(%rbp)
je 0xc0f2
jmp 0xc176
movq -0x38(%rbp), %r13
movq %rbx, %r12
movl 0x18(%r13), %ecx
jmp 0xc04e
leaq 0xaba6(%rip), %rdi      # 0x16ca8
callq 0x7e24
movq -0x68(%rbp), %rcx
movl %eax, 0x58(%rcx)
movl -0x30(%rbp), %eax
testl %eax, %eax
js 0xc1dd
movl %eax, %eax
imulq $0x18, %rax, %rbx
movl 0x10(%r12,%rbx), %esi
leaq -0x60(%rbp), %r15
movq %r15, %rdi
callq 0x5ab8
leaq 0x3607(%rip), %rsi      # 0xf73e
leaq -0xf0(%rbp), %rdi
movq %r15, %rdx
callq 0x5a8a
leaq -0xf0(%rbp), %rdi
pushq $0x3
popq %rsi
callq 0x8343
addq %rbx, %r12
leaq -0xf0(%rbp), %rdi
callq 0x3140
leaq -0x60(%rbp), %rdi
callq 0x3140
addq $0xc, %r12
jmp 0xc2e9
movslq 0xc(%r13), %rax
imulq $0x18, %rax, %rax
movl 0x88(%r13,%rax), %esi
leaq -0x60(%rbp), %r14
movq %r14, %rdi
callq 0x5ab8
leaq 0x360a(%rip), %rsi      # 0xf7a3
leaq -0x90(%rbp), %rdi
movq %r14, %rdx
callq 0x5a8a
leaq -0x90(%rbp), %rdi
pushq $0x3
popq %rsi
callq 0x8343
leaq -0x90(%rbp), %rdi
callq 0x3140
leaq -0x60(%rbp), %rdi
callq 0x3140
subq $-0x80, %r13
movq %r13, %rdi
callq 0x8437
jmp 0xc36d
leaq -0x60(%rbp), %r15
movq %r15, %rdi
movl -0x2c(%rbp), %esi
callq 0x5ab8
leaq 0x3572(%rip), %rsi      # 0xf765
leaq -0xd0(%rbp), %rdi
movq %r15, %rdx
callq 0x5a8a
leaq -0xd0(%rbp), %rdi
pushq $0x3
popq %rsi
callq 0x8343
leaq -0xd0(%rbp), %rdi
callq 0x3140
leaq -0x60(%rbp), %r12
movq %r12, %rdi
callq 0x3140
addq $0x80, %r13
xorl %ebx, %ebx
leaq -0x110(%rbp), %r15
movq -0x38(%rbp), %r14
cmpb $0x1, 0x28(%r14)
jne 0xc26f
movb $0x0, 0x28(%r14)
leaq 0xa148(%rip), %rdi      # 0x16398
callq 0x7748
movl 0x1c(%r14), %edx
movl 0x20(%r14), %ecx
movl %eax, %edi
movl -0x2c(%rbp), %esi
callq 0xc3de
testb %al, %al
jne 0xc1d0
leaq 0xa0ea(%rip), %rax      # 0x16360
movq (%rax), %rax
movq 0x20(%rax), %rax
movl 0x8(%rax), %eax
decl %eax
cmpl %eax, %ebx
je 0xc2d6
movq %r13, %rdi
callq 0x8437
movq %r13, %rdi
callq 0x83e0
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x5ab8
movq %r15, %rdi
leaq 0x34ca(%rip), %rsi      # 0xf776
movq %r12, %rdx
callq 0x5a8a
movq %r15, %rdi
pushq $0x3
popq %rsi
callq 0x8343
movq %r15, %rdi
callq 0x3140
movq %r12, %rdi
callq 0x3140
incl %ebx
jmp 0xc23d
movq -0x40(%rbp), %rax
shlq $0x2, %rax
movq -0x38(%rbp), %r13
addq (%r13), %rax
movq %rax, %r12
movl (%r12), %eax
leaq -0x6c(%rbp), %rsi
movl %eax, (%rsi)
leaq 0xa126(%rip), %rdi      # 0x16420
movl -0x2c(%rbp), %r14d
movl %r14d, %edx
callq 0x3a0e
leaq 0x80(%r13), %rdi
callq 0x8437
movl 0xc(%r13), %eax
incl %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, 0xc(%r13)
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x5ab8
leaq 0x3455(%rip), %rsi      # 0xf78f
leaq -0xb0(%rbp), %rdi
movq %rbx, %rdx
callq 0x5a8a
leaq -0xb0(%rbp), %rdi
pushq $0x2
popq %rsi
callq 0x8343
leaq -0xb0(%rbp), %rdi
callq 0x3140
leaq -0x60(%rbp), %rdi
callq 0x3140
movb $0x1, %al
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
jmp 0xc3c8
jmp 0xc3b9
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
jmp 0xc3c8
jmp 0xc3b9
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0xc3c8
jmp 0xc3b9
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0xc3c8
jmp 0xc3b9
movq %rax, %rbx
jmp 0xc3cd
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x3140
leaq -0x60(%rbp), %rdi
callq 0x3140
movq %rbx, %rdi
callq 0x3440