// File: NishadSaraf[P]Championship-Simulator/src/ooo_cpu.cc
// Function: O3_CPU::execute_load(unsigned int, unsigned int, unsigned int)
int O3_CPU::execute_load(uint32_t rob_index, uint32_t lq_index, uint32_t data_index)
{
    // add it to L1D
    PACKET data_packet;
    data_packet.fill_level = FILL_L1;
    data_packet.cpu = cpu;
    data_packet.data_index = LQ.entry[lq_index].data_index;
    data_packet.lq_index = lq_index;
    data_packet.address = LQ.entry[lq_index].physical_address >> LOG2_BLOCK_SIZE;
    data_packet.full_addr = LQ.entry[lq_index].physical_address;
    data_packet.instr_id = LQ.entry[lq_index].instr_id;
    data_packet.rob_index = LQ.entry[lq_index].rob_index;
    data_packet.ip = LQ.entry[lq_index].ip;
    data_packet.type = LOAD;
    data_packet.asid[0] = LQ.entry[lq_index].asid[0];
    data_packet.asid[1] = LQ.entry[lq_index].asid[1];
    data_packet.event_cycle = LQ.entry[lq_index].event_cycle;

    int rq_index = L1D.add_rq(&data_packet);

    if (rq_index == -2)
        return rq_index;
    else 
        LQ.entry[lq_index].fetched = INFLIGHT;

    return rq_index;
}

// Assembly:
subq $0x3b8, %rsp            # imm = 0x3B8
movq %rdi, 0x3a8(%rsp)
movl %esi, 0x3a4(%rsp)
movl %edx, 0x3a0(%rsp)
movl %ecx, 0x39c(%rsp)
movq 0x3a8(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x9750
movq 0x8(%rsp), %rdi
movl $0x1, 0x20(%rsp)
movl (%rdi), %eax
movl %eax, 0x348(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movl 0x34(%rax), %eax
movl %eax, 0x34c(%rsp)
movl 0x3a0(%rsp), %eax
movl %eax, 0x350(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x6, %rax
movq %rax, 0x358(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, 0x360(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movq (%rax), %rax
movq %rax, 0x380(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movl 0x30(%rax), %eax
movl %eax, 0x28(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movq 0x20(%rax), %rax
movq %rax, 0x388(%rsp)
movb $0x0, 0x347(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movb 0x3e(%rax), %al
movb %al, 0x345(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movb 0x3f(%rax), %al
movb %al, 0x346(%rsp)
movq 0x9f0(%rdi), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movq 0x28(%rax), %rax
movq %rax, 0x390(%rsp)
addq $0x44530, %rdi          # imm = 0x44530
leaq 0x18(%rsp), %rsi
callq 0x81e0
movl %eax, 0x14(%rsp)
cmpl $-0x2, 0x14(%rsp)
jne 0x19a1c
movl 0x14(%rsp), %eax
movl %eax, 0x3b4(%rsp)
jmp 0x19a48
movq 0x8(%rsp), %rax
movq 0x9f0(%rax), %rax
movl 0x3a0(%rsp), %ecx
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movb $0x1, 0x3d(%rax)
movl 0x14(%rsp), %eax
movl %eax, 0x3b4(%rsp)
movl 0x3b4(%rsp), %eax
addq $0x3b8, %rsp            # imm = 0x3B8
retq
nopw (%rax,%rax)