// File: /workspace/github_cpp_makefile_star2_O3/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
movl 0x340(%rsi), %r14d
movl 0x7370(%rdi), %edi
callq 0x9203
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
shll %cl, %ebp
notl %ebp
andl %r14d, %ebp
cmpl %ebp, 0x7370(%r15)
jb 0x49fd
movl 0x7374(%r15), %ecx
testq %rcx, %rcx
je 0x49f2
movq 0x7390(%r15), %rdx
movl %ebp, %esi
movq (%rdx,%rsi,8), %rsi
xorl %edx, %edx
cmpb $0x0, (%rsi)
je 0x49e2
movq 0x28(%rsi), %rdi
cmpq 0x340(%rbx), %rdi
je 0x49f0
incq %rdx
addq $0x50, %rsi
cmpq %rdx, %rcx
jne 0x49d0
jmp 0x49f2
movl %edx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x155ec(%rip), %r14     # 0x19ff0
leaq 0xf685(%rip), %rsi      # 0x14090
movq %r14, %rdi
callq 0x3250
leaq 0x7350(%r15), %rsi
movq %rax, %rdi
callq 0x31e0
leaq 0x102ed(%rip), %rsi     # 0x14d16
movq %rax, %rdi
callq 0x3250
leaq 0xf721(%rip), %rsi      # 0x14159
movq %rax, %rdi
callq 0x3250
leaq 0xf71c(%rip), %rsi      # 0x14163
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
movl %ebp, %esi
callq 0x32d0
leaq 0xf718(%rip), %rsi      # 0x14178
movq %rax, %rdi
callq 0x3250
movl 0x7370(%r15), %esi
movq %rax, %rdi
callq 0x32d0
leaq 0xf705(%rip), %rsi      # 0x14183
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 0x340(%rbx), %rsi
movq %rax, %rdi
callq 0x3090
leaq 0xf6dd(%rip), %rsi      # 0x1418e
movq %rax, %rdi
callq 0x3250
movq 0x348(%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 0xf6b7(%rip), %rsi      # 0x1419b
movq %r14, %rdi
callq 0x3250
movq 0x378(%rbx), %rsi
movq %rax, %rdi
callq 0x3090
movq %rax, %rdi
callq 0x3110
leaq 0xf55d(%rip), %rdi      # 0x14067
leaq 0xf558(%rip), %rsi      # 0x14069
leaq 0xf68c(%rip), %rcx      # 0x141a4
movl $0x36b, %edx            # imm = 0x36B
callq 0x3160