// File: 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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movl 0x2c(%rcx), %eax
cmpl 0x30(%rcx), %eax
jne 0x14dd8
movq 0x8(%rsp), %rax
cmpl $0x0, 0x34(%rax)
jne 0x14dd8
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0x15037
movq 0x8(%rsp), %rcx
movl 0x2c(%rcx), %eax
cmpl 0x30(%rcx), %eax
jae 0x14eb1
movq 0x8(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x8(%rsp), %rcx
movl 0x1c(%rsp), %eax
cmpl 0x30(%rcx), %eax
jae 0x14eac
movq 0x8(%rsp), %rdi
leaq 0xece7(%rip), %rsi      # 0x23afa
callq 0x15190
testb $0x1, %al
jne 0x14e1e
jmp 0x14e5c
movq 0x8(%rsp), %rax
movq 0x98(%rax), %rax
movl 0x1c(%rsp), %ecx
imulq $0x380, %rcx, %rcx      # imm = 0x380
addq %rcx, %rax
movq 0x348(%rax), %rax
movq 0x20(%rsp), %rcx
cmpq 0x348(%rcx), %rax
jne 0x14e5a
movl 0x1c(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x15037
jmp 0x14e9a
movq 0x8(%rsp), %rax
movq 0x98(%rax), %rax
movl 0x1c(%rsp), %ecx
imulq $0x380, %rcx, %rcx      # imm = 0x380
addq %rcx, %rax
movq 0x340(%rax), %rax
movq 0x20(%rsp), %rcx
cmpq 0x340(%rcx), %rax
jne 0x14e98
movl 0x1c(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x15037
jmp 0x14e9a
jmp 0x14e9c
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x14df5
jmp 0x1502f
movq 0x8(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x8(%rsp), %rcx
movl 0x18(%rsp), %eax
cmpl 0x20(%rcx), %eax
jae 0x14f74
movq 0x8(%rsp), %rdi
leaq 0xec1f(%rip), %rsi      # 0x23afa
callq 0x15190
testb $0x1, %al
jne 0x14ee6
jmp 0x14f24
movq 0x8(%rsp), %rax
movq 0x98(%rax), %rax
movl 0x18(%rsp), %ecx
imulq $0x380, %rcx, %rcx      # imm = 0x380
addq %rcx, %rax
movq 0x348(%rax), %rax
movq 0x20(%rsp), %rcx
cmpq 0x348(%rcx), %rax
jne 0x14f22
movl 0x18(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x15037
jmp 0x14f62
movq 0x8(%rsp), %rax
movq 0x98(%rax), %rax
movl 0x18(%rsp), %ecx
imulq $0x380, %rcx, %rcx      # imm = 0x380
addq %rcx, %rax
movq 0x340(%rax), %rax
movq 0x20(%rsp), %rcx
cmpq 0x340(%rcx), %rax
jne 0x14f60
movl 0x18(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x15037
jmp 0x14f62
jmp 0x14f64
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x14ebd
movl $0x0, 0x14(%rsp)
movq 0x8(%rsp), %rcx
movl 0x14(%rsp), %eax
cmpl 0x30(%rcx), %eax
jae 0x1502d
movq 0x8(%rsp), %rdi
leaq 0xeb60(%rip), %rsi      # 0x23afa
callq 0x15190
testb $0x1, %al
jne 0x14fa5
jmp 0x14fe0
movq 0x8(%rsp), %rax
movq 0x98(%rax), %rax
movl 0x14(%rsp), %ecx
imulq $0x380, %rcx, %rcx      # imm = 0x380
addq %rcx, %rax
movq 0x348(%rax), %rax
movq 0x20(%rsp), %rcx
cmpq 0x348(%rcx), %rax
jne 0x14fde
movl 0x14(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x15037
jmp 0x1501b
movq 0x8(%rsp), %rax
movq 0x98(%rax), %rax
movl 0x14(%rsp), %ecx
imulq $0x380, %rcx, %rcx      # imm = 0x380
addq %rcx, %rax
movq 0x340(%rax), %rax
movq 0x20(%rsp), %rcx
cmpq 0x340(%rcx), %rax
jne 0x15019
movl 0x14(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x15037
jmp 0x1501b
jmp 0x1501d
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x14f7c
jmp 0x1502f
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq