// File: Ziang95[P]Tomasulo_simulator/FU.cpp
// Function: FU_CDB::enQ(memCell*, int)
bool FU_CDB::enQ(memCell *v, int s)
{
    pthread_mutex_lock(&Q_lock);
    if ((rear+1)%Q_LEN == front)
    {
        err_log("The reserv_CDB queue is full");
        pthread_mutex_unlock(&Q_lock);
        return false;
    }
    int index = rear;
    rear = (++rear)%Q_LEN;
    int pos = 0;
    for (; (front + pos)%Q_LEN != index && queue[(front + pos)%Q_LEN].source < s; 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].value = *v;
    queue[index].source = s;
    pthread_mutex_unlock(&Q_lock);
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x68(%rbp)
addq $0x810, %rdi            # imm = 0x810
callq 0x4510
movq -0x68(%rbp), %rax
movl 0x80c(%rax), %eax
addl $0x1, %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movq -0x68(%rbp), %rax
cmpl 0x808(%rax), %edx
jne 0x4eb9
leaq -0x41(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x4600
movq -0x70(%rbp), %rdx
leaq 0x1d1bd(%rip), %rsi     # 0x22004
leaq -0x40(%rbp), %rdi
callq 0x44c0
jmp 0x4e52
leaq -0x40(%rbp), %rdi
callq 0x11880
jmp 0x4e5d
leaq -0x40(%rbp), %rdi
callq 0x4240
leaq -0x41(%rbp), %rdi
callq 0x43d0
movq -0x68(%rbp), %rdi
addq $0x810, %rdi            # imm = 0x810
callq 0x42c0
movb $0x0, -0x1(%rbp)
jmp 0x500d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4eab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4240
leaq -0x41(%rbp), %rdi
callq 0x43d0
jmp 0x501b
movq -0x68(%rbp), %rcx
movl 0x80c(%rcx), %eax
movl %eax, -0x58(%rbp)
movl 0x80c(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x80c(%rcx)
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movq -0x68(%rbp), %rax
movl %edx, 0x80c(%rax)
movl $0x0, -0x5c(%rbp)
movq -0x68(%rbp), %rax
movl 0x808(%rax), %eax
addl -0x5c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
xorl %eax, %eax
cmpl -0x58(%rbp), %edx
movb %al, -0x71(%rbp)
je 0x4f36
movq -0x68(%rbp), %rax
movl 0x808(%rax), %eax
addl -0x5c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movq -0x68(%rbp), %rax
movslq %edx, %rcx
movl 0x4(%rax,%rcx,8), %eax
cmpl -0x1c(%rbp), %eax
setl %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x4f3f
jmp 0x4f4c
jmp 0x4f41
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x4eee
movl -0x58(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movq -0x68(%rbp), %rax
movl %edx, -0x78(%rbp)
movl 0x808(%rax), %eax
addl -0x5c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, %eax
movl -0x78(%rbp), %edx
cmpl %eax, %edx
je 0x4fcd
movl -0x60(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
subl $0x1, %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movslq %edx, %rax
movq %rax, -0x80(%rbp)
movl -0x60(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movq -0x68(%rbp), %rax
movl %edx, %ecx
movq -0x80(%rbp), %rdx
movslq %ecx, %rcx
movq (%rax,%rdx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x4f52
movq -0x68(%rbp), %rdi
movl 0x808(%rdi), %eax
addl -0x5c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, -0x58(%rbp)
movq -0x18(%rbp), %rcx
movslq -0x58(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, (%rdi,%rax,8)
movl -0x1c(%rbp), %ecx
movslq -0x58(%rbp), %rax
movl %ecx, 0x4(%rdi,%rax,8)
addq $0x810, %rdi            # imm = 0x810
callq 0x42c0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)