// File: /workspace/github_cpp_makefile_star2_O3/NishadSaraf[P]Championship-Simulator/src/cache.cc
// Function: CACHE::return_data(PACKET*)
void CACHE::return_data(PACKET *packet)
{
    // check MSHR information
    int mshr_index = check_mshr(packet);

    // sanity check
    if (mshr_index == -1) {
        cerr << "[" << NAME << "_MSHR] " << __func__ << " instr_id: " << packet->instr_id << " cannot find a matching entry!";
        cerr << " full_addr: " << hex << packet->full_addr;
        cerr << " address: " << packet->address << dec;
        cerr << " event: " << packet->event_cycle << " current: " << current_core_cycle[packet->cpu] << endl;
        assert(0);
    }

    // MSHR holds the most updated information about this request
    // no need to do memcpy
    MSHR.num_returned++;
    MSHR.entry[mshr_index].returned = COMPLETED;
    MSHR.entry[mshr_index].data = packet->data;

    // ADD LATENCY
    if (MSHR.entry[mshr_index].event_cycle < current_core_cycle[packet->cpu])
        MSHR.entry[mshr_index].event_cycle = current_core_cycle[packet->cpu] + LATENCY;
    else
        MSHR.entry[mshr_index].event_cycle += LATENCY;

    update_fill_cycle();

    DP (if (warmup_complete[packet->cpu]) {
    cout << "[" << NAME << "_MSHR] " <<  __func__ << " instr_id: " << MSHR.entry[mshr_index].instr_id;
    cout << " address: " << hex << MSHR.entry[mshr_index].address << " full_addr: " << MSHR.entry[mshr_index].full_addr;
    cout << " data: " << MSHR.entry[mshr_index].data << dec << " num_returned: " << MSHR.num_returned;
    cout << " index: " << mshr_index << " occupancy: " << MSHR.occupancy;
    cout << " event: " << MSHR.entry[mshr_index].event_cycle << " current: " << current_core_cycle[packet->cpu] << " next: " << MSHR.next_fill_cycle << endl; });
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r15
movl 0x7388(%rdi), %ecx
testq %rcx, %rcx
je 0x660e
movq 0xca20(%r15), %rax
movq 0x340(%rbx), %rsi
imulq $0x380, %rcx, %rdi      # imm = 0x380
xorl %edx, %edx
movabsq $0x100000000, %r8       # imm = 0x100000000
xorl %ecx, %ecx
cmpq %rsi, 0x340(%rax,%rdx)
je 0x6754
addq %r8, %rcx
addq $0x380, %rdx            # imm = 0x380
cmpq %rdx, %rdi
jne 0x65f1
movq 0x139db(%rip), %r14     # 0x19ff0
leaq 0xda74(%rip), %rsi      # 0x14090
movq %r14, %rdi
callq 0x3250
addq $0x7350, %r15           # imm = 0x7350
movq %rax, %rdi
movq %r15, %rsi
callq 0x31e0
leaq 0xdc62(%rip), %rsi      # 0x1429f
movq %rax, %rdi
callq 0x3250
leaq 0xdc5b(%rip), %rsi      # 0x142a7
movq %rax, %rdi
callq 0x3250
leaq 0xe8f5(%rip), %rsi      # 0x14f50
movq %rax, %rdi
callq 0x3250
movq 0x368(%rbx), %rsi
movq %rax, %rdi
callq 0x3090
leaq 0xdc3a(%rip), %rsi      # 0x142b3
movq %rax, %rdi
callq 0x3250
leaq 0xdb06(%rip), %rsi      # 0x1418e
movq %r14, %rdi
callq 0x3250
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq 0x348(%rbx), %rsi
movq %rax, %rdi
callq 0x3090
leaq 0xdac8(%rip), %rsi      # 0x14183
movq %r14, %rdi
callq 0x3250
movq 0x340(%rbx), %rsi
movq %rax, %rdi
callq 0x3090
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0xdaad(%rip), %rsi      # 0x1419b
movq %r14, %rdi
callq 0x3250
movq 0x378(%rbx), %rsi
movq %rax, %rdi
callq 0x3090
leaq 0xdbc6(%rip), %rsi      # 0x142d2
movq %rax, %rdi
callq 0x3250
movl 0x330(%rbx), %ecx
leaq 0x7a79f(%rip), %rdx     # 0x80ec0
movq (%rdx,%rcx,8), %rsi
movq %rax, %rdi
callq 0x3090
movq %rax, %rdi
callq 0x3110
leaq 0xd92b(%rip), %rdi      # 0x14067
leaq 0xd926(%rip), %rsi      # 0x14069
leaq 0xdb93(%rip), %rcx      # 0x142dd
movl $0x4f4, %edx            # imm = 0x4F4
callq 0x3160
movabsq $0x37ffffffc80, %rsi    # imm = 0x37FFFFFFC80
cmpq %rsi, %rdx
je 0x660e
incl 0xc9c0(%r15)
sarq $0x20, %rcx
imulq $0x380, %rcx, %rcx      # imm = 0x380
movb $0x2, 0x32c(%rax,%rcx)
movq 0x360(%rbx), %rdx
movq %rdx, 0x360(%rax,%rcx)
movq 0x378(%rax,%rcx), %rdx
movl 0x330(%rbx), %esi
leaq 0x7a71b(%rip), %rdi     # 0x80ec0
movq (%rdi,%rsi,8), %rsi
cmpq %rsi, %rdx
cmovaq %rdx, %rsi
movl 0x738c(%r15), %edx
addq %rdx, %rsi
movq %rsi, 0x378(%rax,%rcx)
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3fca
nop