// File: /workspace/github_cpp_makefile_star2_O2/NishadSaraf[P]Championship-Simulator/src/cache.cc
// Function: CACHE::check_hit(PACKET*)
int CACHE::check_hit(PACKET *packet)
{
    uint32_t set = get_set(packet->address);
    int match_way = -1;

    if (NUM_SET < set) {
        cerr << "[" << NAME << "_ERROR] " << __func__ << " invalid set index: " << set << " NUM_SET: " << NUM_SET;
        cerr << " address: " << hex << packet->address << " full_addr: " << packet->full_addr << dec;
        cerr << " event: " << packet->event_cycle << endl;
        assert(0);
    }

    // hit
    for (uint32_t way=0; way<NUM_WAY; way++) {
        if (block[set][way].valid && (block[set][way].tag == packet->address)) {

            match_way = way;

            DP ( if (warmup_complete[packet->cpu]) {
            cout << "[" << NAME << "] " << __func__ << " instr_id: " << packet->instr_id << " type: " << +packet->type << hex << " addr: " << packet->address;
            cout << " full_addr: " << packet->full_addr << " tag: " << block[set][way].tag << " data: " << block[set][way].data << dec;
            cout << " set: " << set << " way: " << way << " lru: " << block[set][way].lru;
            cout << " event: " << packet->event_cycle << " cycle: " << current_core_cycle[cpu] << endl; });

            break;
        }
    }

    return match_way;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r15
movq 0x340(%rsi), %rsi
callq 0x2e58
movl %eax, %ebp
cmpl %eax, 0x7370(%r15)
jb 0x37e3
movl 0x7374(%r15), %ecx
movq 0x7390(%r15), %rdx
movl %ebp, %esi
xorl %edi, %edi
pushq $-0x1
popq %rax
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x37d8
movq (%rdx,%rsi,8), %r9
cmpb $0x0, (%r9,%rdi)
je 0x37cc
movq 0x28(%r9,%rdi), %r9
cmpq 0x340(%rbx), %r9
je 0x37d5
incq %r8
addq $0x50, %rdi
jmp 0x37ae
movl %r8d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x12806(%rip), %r14     # 0x15ff0
leaq 0xc89f(%rip), %rsi      # 0x10090
movq %r14, %rdi
callq 0x2230
leaq 0x7350(%r15), %rsi
movq %rax, %rdi
callq 0x21d0
leaq 0xd40f(%rip), %rsi      # 0x10c1e
movq %rax, %rdi
callq 0x2230
leaq 0xc93b(%rip), %rsi      # 0x10159
movq %rax, %rdi
callq 0x2230
leaq 0xc936(%rip), %rsi      # 0x10163
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
movl %ebp, %esi
callq 0x22a0
leaq 0xc932(%rip), %rsi      # 0x10178
movq %rax, %rdi
callq 0x2230
movl 0x7370(%r15), %esi
movq %rax, %rdi
callq 0x22a0
leaq 0xc91f(%rip), %rsi      # 0x10183
movq %r14, %rdi
callq 0x2230
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq 0x340(%rbx), %rsi
movq %rax, %rdi
callq 0x2080
leaq 0xc8f7(%rip), %rsi      # 0x1018e
movq %rax, %rdi
callq 0x2230
movq 0x348(%rbx), %rsi
movq %rax, %rdi
callq 0x2080
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0xc8d1(%rip), %rsi      # 0x1019b
movq %r14, %rdi
callq 0x2230
movq 0x378(%rbx), %rsi
movq %rax, %rdi
callq 0x2080
movq %rax, %rdi
callq 0x2110
leaq 0xc777(%rip), %rdi      # 0x10067
leaq 0xc772(%rip), %rsi      # 0x10069
leaq 0xc8a6(%rip), %rcx      # 0x101a4
movl $0x36b, %edx            # imm = 0x36B
callq 0x2160