// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $-0x1
popq %rbx
cmpl %eax, %r13d
jne 0x9b3b
cmpl $0x0, 0x34(%r15)
je 0x9c4c
imulq $0x380, %r13, %rbp      # imm = 0x380
addq $0x348, %rbp            # imm = 0x348
leaq 0x6fe3(%rip), %r12      # 0x10b33
cmpl %eax, %r13d
jae 0x9baa
movl %eax, %eax
cmpq %rax, %r13
jae 0x9c4c
movq %r15, %rdi
movq %r12, %rsi
callq 0x9d38
movq 0x98(%r15), %rcx
testb %al, %al
je 0x9b88
movq (%rcx,%rbp), %rax
cmpq 0x348(%r14), %rax
jne 0x9b9a
jmp 0x9c49
movq -0x8(%rcx,%rbp), %rax
cmpq 0x340(%r14), %rax
je 0x9c49
incq %r13
movl 0x30(%r15), %eax
addq $0x380, %rbp            # imm = 0x380
jmp 0x9b55
movl 0x20(%r15), %eax
cmpq %rax, %r13
jae 0x9bf2
movq %r15, %rdi
movq %r12, %rsi
callq 0x9d38
movq 0x98(%r15), %rcx
testb %al, %al
je 0x9bd8
movq (%rcx,%rbp), %rax
cmpq 0x348(%r14), %rax
jne 0x9be6
jmp 0x9c49
movq -0x8(%rcx,%rbp), %rax
cmpq 0x340(%r14), %rax
je 0x9c49
incq %r13
addq $0x380, %rbp            # imm = 0x380
jmp 0x9baa
movl $0x348, %ebp            # imm = 0x348
xorl %r13d, %r13d
leaq 0x6f32(%rip), %r12      # 0x10b33
movl 0x30(%r15), %eax
cmpq %rax, %r13
jae 0x9c4c
movq %r15, %rdi
movq %r12, %rsi
callq 0x9d38
movq 0x98(%r15), %rcx
testb %al, %al
je 0x9c2f
movq (%rcx,%rbp), %rax
cmpq 0x348(%r14), %rax
jne 0x9c3d
jmp 0x9c49
movq -0x8(%rcx,%rbp), %rax
cmpq 0x340(%r14), %rax
je 0x9c49
incq %r13
addq $0x380, %rbp            # imm = 0x380
jmp 0x9c01
movl %r13d, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop