// File: /workspace/github_cpp_makefile_star2_O3/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), %esi
movl 0x3804(%r15), %eax
leal 0x1(%rax), %ecx
leal 0x100(%rax), %edx
testl %ecx, %ecx
cmovsl %edx, %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
negl %ecx
addl %eax, %ecx
incl %ecx
cmpl %esi, %ecx
je 0x4260
movl %ecx, 0x3804(%r15)
leal 0xff(%rsi), %ecx
testl %esi, %esi
cmovnsl %esi, %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
movl %esi, %edi
subl %ecx, %edi
movl %eax, %ecx
cmpl %eax, %edi
je 0x4175
incl %esi
movl %edi, %ecx
movslq %ecx, %rdi
imulq $0x38, %rdi, %rdi
cmpl %r14d, 0x4(%r15,%rdi)
jge 0x4175
leal 0xff(%rsi), %edi
testl %esi, %esi
cmovnsl %esi, %edi
andl $0xffffff00, %edi       # imm = 0xFFFFFF00
movl %esi, %ecx
subl %edi, %ecx
incl %esi
cmpl %eax, %ecx
jne 0x414a
movl %eax, %ecx
movq %r13, %rsi
movl 0x18(%rbp), %r8d
movq 0x10(%rbp), %rdi
leal 0x1ff(%rax), %r9d
testl %edx, %edx
cmovnsl %edx, %r9d
andl $0xffffff00, %r9d       # imm = 0xFFFFFF00
negl %r9d
leal (%rax,%r9), %edx
addl $0x100, %edx            # imm = 0x100
cmpl %ecx, %edx
je 0x4208
addl $0xff, %eax
leal 0xff(%rax), %r9d
testl %eax, %eax
cmovnsl %eax, %r9d
andl $0xffffff00, %r9d       # imm = 0xFFFFFF00
movslq %edx, %rdx
movl %eax, %r10d
subl %r9d, %r10d
movslq %r10d, %r9
imulq $0x38, %r9, %r11
imulq $0x38, %rdx, %rdx
movq 0x30(%r15,%r11), %r13
movq %r13, 0x30(%r15,%rdx)
movups (%r15,%r11), %xmm0
movups 0x10(%r15,%r11), %xmm1
movups 0x20(%r15,%r11), %xmm2
movups %xmm2, 0x20(%r15,%rdx)
movups %xmm1, 0x10(%r15,%rdx)
movups %xmm0, (%r15,%rdx)
decl %eax
movl %r10d, %edx
cmpl %ecx, %r9d
jne 0x41aa
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 %rsi, 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 0x16d11(%rip), %rsi     # 0x1af90
movq %rax, %rdi
xorl %edx, %edx
callq 0x3420
nop