// File: NishadSaraf[P]Championship-Simulator/src/ooo_cpu.cc
// Function: O3_CPU::handle_merged_load(PACKET*)
void O3_CPU::handle_merged_load(PACKET *provider)
{
    for (uint32_t merged=0; merged<LQ.SIZE; merged++) {
        if (provider->lq_index_depend_on_me[merged]) {
            uint32_t merged_rob_index = LQ.entry[merged].rob_index;

            LQ.entry[merged].fetched = COMPLETED;
            LQ.entry[merged].event_cycle = current_core_cycle[cpu];
            ROB.entry[merged_rob_index].num_mem_ops--;
            ROB.entry[merged_rob_index].event_cycle = current_core_cycle[cpu];

#ifdef SANITY_CHECK
            if (ROB.entry[merged_rob_index].num_mem_ops < 0) {
                cerr << "instr_id: " << ROB.entry[merged_rob_index].instr_id << " rob_index: " << merged_rob_index << endl;
                assert(0);
            }
#endif

            if (ROB.entry[merged_rob_index].num_mem_ops == 0)
                inflight_mem_executions++;

            DP (if (warmup_complete[cpu]) {
            cout << "[ROB] " << __func__ << " load instr_id: " << LQ.entry[merged].instr_id;
            cout << " L1D_FETCH_DONE translation: " << +LQ.entry[merged].translated << hex << " address: " << (LQ.entry[merged].physical_address>>LOG2_BLOCK_SIZE);
            cout << " full_addr: " << LQ.entry[merged].physical_address << dec << " by instr_id: " << +provider->instr_id;
            cout << " remain_mem_ops: " << ROB.entry[merged_rob_index].num_mem_ops << endl; });

            release_load_queue(merged);
        }
    }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x8(%rsp), %rcx
movl 0x14(%rsp), %eax
cmpl 0x9e0(%rcx), %eax
jae 0x1aea8
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
cmpb $0x0, 0x129(%rax,%rcx)
je 0x1ae96
movq 0x8(%rsp), %rax
movq 0x9f0(%rax), %rcx
movl 0x14(%rsp), %edx
imulq $0x140, %rdx, %rdx      # imm = 0x140
addq %rdx, %rcx
movl 0x30(%rcx), %ecx
movl %ecx, 0x10(%rsp)
movq 0x9f0(%rax), %rcx
movl 0x14(%rsp), %edx
imulq $0x140, %rdx, %rdx      # imm = 0x140
addq %rdx, %rcx
movb $0x2, 0x3d(%rcx)
movl (%rax), %ecx
movl %ecx, %edx
leaq 0x7516f(%rip), %rcx     # 0x8fec0
movq (%rcx,%rdx,8), %rdx
movq 0x9f0(%rax), %rcx
movl 0x14(%rsp), %esi
imulq $0x140, %rsi, %rsi      # imm = 0x140
addq %rsi, %rcx
movq %rdx, 0x28(%rcx)
movq 0x9b8(%rax), %rcx
movl 0x10(%rsp), %edx
imulq $0x758, %rdx, %rdx      # imm = 0x758
addq %rdx, %rcx
movl 0x70(%rcx), %edx
addl $-0x1, %edx
movl %edx, 0x70(%rcx)
movl (%rax), %ecx
movl %ecx, %edx
leaq 0x75129(%rip), %rcx     # 0x8fec0
movq (%rcx,%rdx,8), %rdx
movq 0x9b8(%rax), %rcx
movl 0x10(%rsp), %esi
imulq $0x758, %rsi, %rsi      # imm = 0x758
addq %rsi, %rcx
movq %rdx, 0x40(%rcx)
movq 0x9b8(%rax), %rax
movl 0x10(%rsp), %ecx
imulq $0x758, %rcx, %rcx      # imm = 0x758
addq %rcx, %rax
cmpl $0x0, 0x70(%rax)
jge 0x1ae54
movq 0xe216(%rip), %rdi      # 0x28ff0
leaq 0x903f(%rip), %rsi      # 0x23e20
callq 0x3220
movq %rax, %rdi
movq 0x8(%rsp), %rax
movq 0x9b8(%rax), %rax
movl 0x10(%rsp), %ecx
imulq $0x758, %rcx, %rcx      # imm = 0x758
addq %rcx, %rax
movq (%rax), %rsi
callq 0x3080
movq %rax, %rdi
leaq 0x87f0(%rip), %rsi      # 0x23605
callq 0x3220
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x32c0
movq %rax, %rdi
movq 0xe188(%rip), %rsi      # 0x28fb8
callq 0x3250
leaq 0x81c8(%rip), %rdi      # 0x23004
leaq 0x8d72(%rip), %rsi      # 0x23bb5
movl $0x70c, %edx            # imm = 0x70C
leaq 0x90a9(%rip), %rcx      # 0x23ef8
callq 0x3160
movq 0x8(%rsp), %rax
movq 0x9b8(%rax), %rax
movl 0x10(%rsp), %ecx
imulq $0x758, %rcx, %rcx      # imm = 0x758
addq %rcx, %rax
cmpl $0x0, 0x70(%rax)
jne 0x1ae88
movq 0x8(%rsp), %rax
movl 0x924(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x924(%rax)
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x191c0
jmp 0x1ae98
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x1ace0
addq $0x28, %rsp
retq
nopl (%rax)