// File: /workspace/github_cpp_makefile_star2_O1/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), %ebx
movl 0x30(%rdi), %eax
cmpl %eax, %ebx
jne 0xc1e6
cmpl $0x0, 0x34(%r15)
je 0xc360
cmpl %eax, %ebx
jae 0xc26e
cmpl 0x30(%r15), %ebx
setb %bpl
jae 0xc360
imulq $0x380, %rbx, %r13      # imm = 0x380
leaq 0x8943(%rip), %r12      # 0x14b4d
movq %r15, %rdi
movq %r12, %rsi
callq 0x30c0
testl %eax, %eax
je 0xc236
movq 0x98(%r15), %rax
movq 0x340(%rax,%r13), %rax
cmpq 0x340(%r14), %rax
jne 0xc252
jmp 0xc35a
movq 0x98(%r15), %rax
movq 0x348(%rax,%r13), %rax
cmpq 0x348(%r14), %rax
je 0xc35a
incq %rbx
movl 0x30(%r15), %eax
addq $0x380, %r13            # imm = 0x380
cmpq %rax, %rbx
setb %bpl
jb 0xc20a
jmp 0xc360
cmpl 0x20(%r15), %ebx
setb %r12b
jae 0xc2e8
imulq $0x380, %rbx, %r13      # imm = 0x380
movq %rbx, %rbp
movq %r15, %rdi
leaq 0x88c1(%rip), %rsi      # 0x14b4d
callq 0x30c0
testl %eax, %eax
je 0xc2af
movq 0x98(%r15), %rax
movq 0x340(%rax,%r13), %rax
cmpq 0x340(%r14), %rax
jne 0xc2c7
jmp 0xc2e2
movq 0x98(%r15), %rax
movq 0x348(%rax,%r13), %rax
cmpq 0x348(%r14), %rax
je 0xc2e2
incq %rbp
movl 0x20(%r15), %eax
incl %ebx
addq $0x380, %r13            # imm = 0x380
cmpq %rax, %rbp
setb %r12b
jb 0xc282
jmp 0xc2e8
testb $0x1, %r12b
jne 0xc365
cmpl $0x0, 0x30(%r15)
setne %bpl
je 0xc35a
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r15, %rdi
leaq 0x884a(%rip), %rsi      # 0x14b4d
callq 0x30c0
testl %eax, %eax
je 0xc326
movq 0x98(%r15), %rax
movq 0x340(%rax,%r12), %rax
cmpq 0x340(%r14), %rax
jne 0xc33e
jmp 0xc357
movq 0x98(%r15), %rax
movq 0x348(%rax,%r12), %rax
cmpq 0x348(%r14), %rax
je 0xc357
incq %r13
movl 0x30(%r15), %eax
addq $0x380, %r12            # imm = 0x380
cmpq %rax, %r13
setb %bpl
jb 0xc2f9
jmp 0xc35a
movl %r13d, %ebx
testb $0x1, %bpl
jne 0xc365
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq