// File: /workspace/github_c_makefile_star2_O0/aerospike[P]aerospike-common/src/main/citrusleaf/cf_queue.c
// Function: cf_queue_pop
int
cf_queue_pop(cf_queue *q, void *buf, int ms_wait)
{
	struct timespec tp;

	if (ms_wait > 0) {
		cf_set_wait_timespec(ms_wait, &tp);
	}

	cf_queue_lock(q);

	if (q->threadsafe) {

		// Note that we have to use a while() loop. The pthread_cond_signal()
		// documentation says that AT LEAST ONE waiting thread will be awakened.
		// If more than one are awakened, the first will get the popped element,
		// others will find the queue empty and go back to waiting.

		while (CF_Q_EMPTY(q)) {
			if (CF_QUEUE_FOREVER == ms_wait) {
				pthread_cond_wait(&q->CV, &q->LOCK);
			}
			else if (CF_QUEUE_NOWAIT == ms_wait) {
				pthread_mutex_unlock(&q->LOCK);
				return CF_QUEUE_EMPTY;
			}
			else {
				pthread_cond_timedwait(&q->CV, &q->LOCK, &tp);

				if (CF_Q_EMPTY(q)) {
					pthread_mutex_unlock(&q->LOCK);
					return CF_QUEUE_EMPTY;
				}
			}
		}
	}
	else if (CF_Q_EMPTY(q)) {
		return CF_QUEUE_EMPTY;
	}

	memcpy(buf, CF_Q_ELEM_PTR(q, q->read_offset), q->element_sz);
	q->read_offset++;
	q->n_eles--;

	// This probably keeps the cache fresher because the queue is fully empty.
	if (q->read_offset == q->write_offset) {
		q->read_offset = q->write_offset = 0;
	}

	cf_queue_unlock(q);
	return CF_QUEUE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x25ce5
movl -0x1c(%rbp), %edi
leaq -0x30(%rbp), %rsi
callq 0x25e50
movq -0x10(%rbp), %rdi
callq 0x25260
movq -0x10(%rbp), %rax
testb $0x1, (%rax)
je 0x25d9f
jmp 0x25cfd
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x25d9d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x1c(%rbp), %eax
jne 0x25d32
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movq -0x10(%rbp), %rsi
addq $0x20, %rsi
callq 0x8240
jmp 0x25d98
xorl %eax, %eax
cmpl -0x1c(%rbp), %eax
jne 0x25d52
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x8740
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x25e44
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movq -0x10(%rbp), %rsi
addq $0x20, %rsi
leaq -0x30(%rbp), %rdx
callq 0x8a10
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x25d94
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x8740
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x25e44
jmp 0x25d96
jmp 0x25d98
jmp 0x25cfd
jmp 0x25dbd
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x25dbb
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x25e44
jmp 0x25dbd
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divl 0x4(%rcx)
movl %edx, %eax
movq -0x10(%rbp), %rcx
imulq 0x18(%rcx), %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
callq 0x86b0
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x25e34
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rdi
callq 0x25420
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)