// File: /workspace/github_cpp_makefile_star2_O3/NishadSaraf[P]Championship-Simulator/src/block.cc
// Function: PACKET_QUEUE::check_queue(PACKET*)
int PACKET_QUEUE::check_queue(PACKET *packet)
{
    if ((head == tail) && occupancy == 0)
        return -1;

    if (head < tail) {
        for (uint32_t i=head; i<tail; i++) {
            if (NAME == "L1D_WQ") {
                if (entry[i].full_addr == packet->full_addr) {
                    DP (if (warmup_complete[packet->cpu]) {
                    cout << "[" << NAME << "] " << __func__ << " cpu: " << packet->cpu << " instr_id: " << packet->instr_id << " same address: " << hex << packet->address;
                    cout << " full_addr: " << packet->full_addr << dec << " by instr_id: " << entry[i].instr_id << " index: " << i;
                    cout << " cycle " << packet->event_cycle << endl; });
                    return i;
                }
            }
            else {
                if (entry[i].address == packet->address) {
                    DP (if (warmup_complete[packet->cpu]) {
                    cout << "[" << NAME << "] " << __func__ << " cpu: " << packet->cpu << " instr_id: " << packet->instr_id << " same address: " << hex << packet->address;
                    cout << " full_addr: " << packet->full_addr << dec << " by instr_id: " << entry[i].instr_id << " index: " << i;
                    cout << " cycle " << packet->event_cycle << endl; });
                    return i;
                }
            }
        }
    }
    else {
        for (uint32_t i=head; i<SIZE; i++) {
            if (NAME == "L1D_WQ") {
                if (entry[i].full_addr == packet->full_addr) {
                    DP (if (warmup_complete[packet->cpu]) {
                    cout << "[" << NAME << "] " << __func__ << " cpu: " << packet->cpu << " instr_id: " << packet->instr_id << " same address: " << hex << packet->address;
                    cout << " full_addr: " << packet->full_addr << dec << " by instr_id: " << entry[i].instr_id << " index: " << i;
                    cout << " cycle " << packet->event_cycle << endl; });
                    return i;
                }
            }
            else {
                if (entry[i].address == packet->address) {
                    DP (if (warmup_complete[packet->cpu]) {
                    cout << "[" << NAME << "] " << __func__ << " cpu: " << packet->cpu << " instr_id: " << packet->instr_id << " same address: " << hex << packet->address;
                    cout << " full_addr: " << packet->full_addr << dec << " by instr_id: " << entry[i].instr_id << " index: " << i;
                    cout << " cycle " << packet->event_cycle << endl; });
                    return i;
                }
            }
        }
        for (uint32_t i=0; i<tail; i++) {
            if (NAME == "L1D_WQ") {
                if (entry[i].full_addr == packet->full_addr) {
                    DP (if (warmup_complete[packet->cpu]) {
                    cout << "[" << NAME << "] " << __func__ << " cpu: " << packet->cpu << " instr_id: " << packet->instr_id << " same address: " << hex << packet->address;
                    cout << " full_addr: " << packet->full_addr << dec << " by instr_id: " << entry[i].instr_id << " index: " << i;
                    cout << " cycle " << packet->event_cycle << endl; });
                    return i;
                }
            }
            else {
                if (entry[i].address == packet->address) {
                    DP (if (warmup_complete[packet->cpu]) {
                    cout << "[" << NAME << "] " << __func__ << " cpu: " << packet->cpu << " instr_id: " << packet->instr_id << " same address: " << hex << packet->address;
                    cout << " full_addr: " << packet->full_addr << dec << " by instr_id: " << entry[i].instr_id << " index: " << i;
                    cout << " cycle " << packet->event_cycle << endl; });
                    return i;
                }
            }
        }
    }

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %r15
movl 0x2c(%rdi), %r13d
movl 0x30(%rdi), %eax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl %eax, %r13d
jne 0xc275
cmpl $0x0, 0x34(%r15)
je 0xc3a4
cmpl %eax, %r13d
jae 0xc2e1
imulq $0x380, %r13, %rbp      # imm = 0x380
addq $0x348, %rbp            # imm = 0x348
leaq 0x88fe(%rip), %r12      # 0x14b8d
movq %r15, %rdi
movq %r12, %rsi
callq 0x30c0
movq 0x98(%r15), %rcx
testl %eax, %eax
je 0xc2b8
movq -0x8(%rcx,%rbp), %rax
cmpq 0x340(%r14), %rax
jne 0xc2c9
jmp 0xc3a1
movq (%rcx,%rbp), %rax
cmpq 0x348(%r14), %rax
je 0xc3a1
incq %r13
movl 0x30(%r15), %eax
addq $0x380, %rbp            # imm = 0x380
cmpq %rax, %r13
jb 0xc28f
jmp 0xc3a4
cmpl 0x20(%r15), %r13d
jae 0xc346
imulq $0x380, %r13, %rbp      # imm = 0x380
addq $0x348, %rbp            # imm = 0x348
leaq 0x8891(%rip), %r12      # 0x14b8d
movq %r15, %rdi
movq %r12, %rsi
callq 0x30c0
movq 0x98(%r15), %rcx
testl %eax, %eax
je 0xc322
movq -0x8(%rcx,%rbp), %rax
cmpq 0x340(%r14), %rax
jne 0xc32f
jmp 0xc3a1
movq (%rcx,%rbp), %rax
cmpq 0x348(%r14), %rax
je 0xc3a1
incq %r13
movl 0x20(%r15), %eax
addq $0x380, %rbp            # imm = 0x380
cmpq %rax, %r13
jb 0xc2fc
movl 0x30(%r15), %eax
testl %eax, %eax
je 0xc3a4
movl $0x348, %ebp            # imm = 0x348
xorl %r13d, %r13d
leaq 0x8834(%rip), %r12      # 0x14b8d
movq %r15, %rdi
movq %r12, %rsi
callq 0x30c0
movq 0x98(%r15), %rcx
testl %eax, %eax
je 0xc37f
movq -0x8(%rcx,%rbp), %rax
cmpq 0x340(%r14), %rax
jne 0xc38c
jmp 0xc3a1
movq (%rcx,%rbp), %rax
cmpq 0x348(%r14), %rax
je 0xc3a1
incq %r13
movl 0x30(%r15), %eax
addq $0x380, %rbp            # imm = 0x380
cmpq %rax, %r13
jb 0xc359
jmp 0xc3a4
movl %r13d, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop