// File: /workspace/github_c_makefile_star2_O0/aerospike[P]aerospike-common/src/main/citrusleaf/cf_queue.c
// Function: cf_queue_resize
static int
cf_queue_resize(cf_queue *q, uint32_t new_sz)
{
	// The rare case where the queue is not fragmented, and realloc makes sense
	// and none of the offsets need to move.
	if (0 == q->read_offset % q->alloc_sz) {
		q->elements = (uint8_t*)cf_realloc(q->elements, new_sz * q->element_sz);

		if (! q->elements) {
			return CF_QUEUE_ERR;
		}

		q->read_offset = 0;
		q->write_offset = q->alloc_sz;
	}
	else {
		uint8_t *newq = (uint8_t*)cf_malloc(new_sz * q->element_sz);

		if (! newq) {
			return CF_QUEUE_ERR;
		}

		// end_sz is used bytes in old queue from insert point to end.
		size_t end_sz =
				(q->alloc_sz - (q->read_offset % q->alloc_sz)) * q->element_sz;

		memcpy(&newq[0], CF_Q_ELEM_PTR(q, q->read_offset), end_sz);
		memcpy(&newq[end_sz], &q->elements[0],
				(q->alloc_sz * q->element_sz) - end_sz);

		cf_free(q->elements);
		q->elements = newq;

		q->write_offset = q->alloc_sz;
		q->read_offset = 0;
	}

	q->alloc_sz = new_sz;

	return CF_QUEUE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divl 0x4(%rcx)
xorl %eax, %eax
cmpl %edx, %eax
jne 0x25310
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdi
movl -0x14(%rbp), %eax
movl %eax, %esi
movq -0x10(%rbp), %rax
imulq 0x18(%rax), %rsi
callq 0x85b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x78(%rax)
jne 0x252f2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25409
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x253f8
movl -0x14(%rbp), %eax
movl %eax, %edi
movq -0x10(%rbp), %rax
imulq 0x18(%rax), %rdi
callq 0x8090
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2533a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x25409
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divl 0x4(%rcx)
movl -0x2c(%rbp), %eax
subl %edx, %eax
movl %eax, %eax
movq -0x10(%rbp), %rcx
imulq 0x18(%rcx), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%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 -0x28(%rbp), %rdx
callq 0x86b0
movq -0x20(%rbp), %rdi
addq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
movq -0x10(%rbp), %rax
imulq 0x18(%rax), %rdx
subq -0x28(%rbp), %rdx
callq 0x86b0
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x8aa0
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)