// File: /workspace/github_cpp_makefile_star2_O1/Ziang95[P]Tomasulo_simulator/FU.cpp
// Function: FU_Q::enQ(opCode, int, memCell*, memCell*, memCell*, LSQEntry*, int, bool*)
const FU_QEntry* FU_Q::enQ(opCode c, int d, memCell *r, memCell *op1, memCell *op2, LSQEntry *_lsqe, int offst, bool* busy)
{
    pthread_mutex_lock(&Q_lock);
    if ((rear+1)%Q_LEN == front)
    {
        pthread_mutex_unlock(&Q_lock);
        throw -1;
    }
    int index = rear;
    rear = (++rear)%Q_LEN;
    int pos = 0;
    for (; (front + pos)%Q_LEN != index && queue[(front + pos)%Q_LEN].dest < d; pos++);
    for (int i = index; (Q_LEN + i)%Q_LEN != (front + pos)%Q_LEN; i--)
        queue[(Q_LEN+i)%Q_LEN] = queue[(Q_LEN+i-1)%Q_LEN];
    index = (front+pos)%Q_LEN;
    queue[index].code = c;
    queue[index].dest = d;
    queue[index].res = r;
    queue[index].oprnd1 = op1;
    queue[index].oprnd2 = op2;
    queue[index].offset = offst;
    queue[index].lsqe = _lsqe;
    queue[index].busy = busy;
    pthread_mutex_unlock(&Q_lock);
    return &queue[index];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r13
movq %r8, -0x38(%rbp)
movq %rcx, -0x30(%rbp)
movl %edx, %r14d
movl %esi, %r12d
movq %rdi, %r15
leaq 0x3808(%rdi), %rbx
movq %rbx, %rdi
callq 0x3380
movl 0x3800(%r15), %edx
movl 0x3804(%r15), %eax
leal 0x1(%rax), %ecx
leal 0x100(%rax), %esi
testl %ecx, %ecx
cmovsl %esi, %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
negl %ecx
addl %eax, %ecx
incl %ecx
cmpl %edx, %ecx
je 0x423c
movl %ecx, 0x3804(%r15)
leal 0xff(%rdx), %edi
testl %edx, %edx
cmovnsl %edx, %edi
andl $0xffffff00, %edi       # imm = 0xFFFFFF00
movl %edx, %ecx
subl %edi, %ecx
cmpl %eax, %ecx
je 0x4151
incl %edx
movslq %ecx, %rdi
imulq $0x38, %rdi, %rdi
cmpl %r14d, 0x4(%r15,%rdi)
jge 0x4151
leal 0xff(%rdx), %edi
testl %edx, %edx
cmovnsl %edx, %edi
andl $0xffffff00, %edi       # imm = 0xFFFFFF00
movl %edx, %ecx
subl %edi, %ecx
incl %edx
cmpl %eax, %ecx
jne 0x4128
movq %r13, %rdx
movl 0x18(%rbp), %r8d
movq 0x10(%rbp), %rdi
leal 0x1ff(%rax), %r9d
testl %esi, %esi
cmovnsl %esi, %r9d
andl $0xffffff00, %r9d       # imm = 0xFFFFFF00
negl %r9d
leal (%rax,%r9), %esi
addl $0x100, %esi            # imm = 0x100
cmpl %ecx, %esi
je 0x41e4
addl $0xff, %eax
leal 0xff(%rax), %r9d
testl %eax, %eax
cmovnsl %eax, %r9d
andl $0xffffff00, %r9d       # imm = 0xFFFFFF00
movslq %esi, %rsi
movl %eax, %r10d
subl %r9d, %r10d
movslq %r10d, %r9
imulq $0x38, %r9, %r11
imulq $0x38, %rsi, %rsi
movq 0x30(%r15,%r11), %r13
movq %r13, 0x30(%r15,%rsi)
movups (%r15,%r11), %xmm0
movups 0x10(%r15,%r11), %xmm1
movups 0x20(%r15,%r11), %xmm2
movups %xmm2, 0x20(%r15,%rsi)
movups %xmm1, 0x10(%r15,%rsi)
movups %xmm0, (%r15,%rsi)
decl %eax
movl %r10d, %esi
cmpl %ecx, %r9d
jne 0x4186
movslq %ecx, %rax
imulq $0x38, %rax, %rax
leaq (%r15,%rax), %r13
movl %r12d, (%r15,%rax)
movl %r14d, 0x4(%r15,%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x8(%r15,%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x10(%r15,%rax)
movq %rdx, 0x18(%r15,%rax)
movl %r8d, 0x28(%r15,%rax)
movq %rdi, 0x20(%r15,%rax)
movq 0x20(%rbp), %rcx
movq %rcx, 0x30(%r15,%rax)
movq %rbx, %rdi
callq 0x31e0
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x31e0
movl $0x4, %edi
callq 0x3140
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x16d35(%rip), %rsi     # 0x1af90
movq %rax, %rdi
xorl %edx, %edx
callq 0x3420
nop