// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/huge.c
// Function: huge_ralloc
void *
huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra,
    size_t alignment, bool zero, bool try_tcache_dalloc)
{
	void *ret;
	size_t copysize;

	/* Try to avoid moving the allocation. */
	ret = huge_ralloc_no_move(ptr, oldsize, size, extra);
	if (ret != NULL)
		return (ret);

	/*
	 * size and oldsize are different enough that we need to use a
	 * different size class.  In that case, fall back to allocating new
	 * space and copying.
	 */
	if (alignment > chunksize)
		ret = huge_palloc(size + extra, alignment, zero);
	else
		ret = huge_malloc(size + extra, zero);

	if (ret == NULL) {
		if (extra == 0)
			return (NULL);
		/* Try again, this time without extra. */
		if (alignment > chunksize)
			ret = huge_palloc(size, alignment, zero);
		else
			ret = huge_malloc(size, zero);

		if (ret == NULL)
			return (NULL);
	}

	/*
	 * Copy at most size bytes (not size+extra), since the caller has no
	 * expectation that the extra bytes will be reliably preserved.
	 */
	copysize = (size < oldsize) ? size : oldsize;

#ifdef JEMALLOC_MREMAP
	/*
	 * Use mremap(2) if this is a huge-->huge reallocation, and neither the
	 * source nor the destination are in dss.
	 */
	if (oldsize >= chunksize && (config_dss == false || (chunk_in_dss(ptr)
	    == false && chunk_in_dss(ret) == false))) {
		size_t newsize = huge_salloc(ret);

		/*
		 * Remove ptr from the tree of huge allocations before
		 * performing the remap operation, in order to avoid the
		 * possibility of another thread acquiring that mapping before
		 * this one removes it from the tree.
		 */
		huge_dalloc(ptr, false);
		if (mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE|MREMAP_FIXED,
		    ret) == MAP_FAILED) {
			/*
			 * Assuming no chunk management bugs in the allocator,
			 * the only documented way an error can occur here is
			 * if the application changed the map type for a
			 * portion of the old allocation.  This is firmly in
			 * undefined behavior territory, so write a diagnostic
			 * message, and optionally abort.
			 */
			char buf[BUFERROR_BUF];

			buferror(buf, sizeof(buf));
			malloc_printf("<jemalloc>: Error in mremap(): %s\n",
			    buf);
			if (opt_abort)
				abort();
			memcpy(ret, ptr, copysize);
			chunk_dealloc_mmap(ptr, oldsize);
		}
	} else
#endif
	{
		memcpy(ret, ptr, copysize);
		iqallocx(ptr, try_tcache_dalloc);
	}
	return (ret);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %r9d, %eax
movq %rcx, -0x60(%rbp)
movq %rdx, %rcx
movq -0x60(%rbp), %rdx
movq %rcx, -0x58(%rbp)
movq %rsi, %rcx
movq -0x58(%rbp), %rsi
movq %rcx, -0x50(%rbp)
movq %rdi, %r9
movq -0x50(%rbp), %rdi
movb %al, %cl
movb 0x10(%rbp), %al
movq %r9, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
andb $0x1, %cl
movb %cl, -0x31(%rbp)
andb $0x1, %al
movb %al, -0x32(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0xcd000
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xcd18d
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xcd291
movq -0x30(%rbp), %rax
leaq 0x5c018(%rip), %rcx     # 0x1291b0
cmpq (%rcx), %rax
jbe 0xcd1bc
movq -0x20(%rbp), %rdi
addq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0xccdf0
movq %rax, -0x40(%rbp)
jmp 0xcd1d5
movq -0x20(%rbp), %rdi
addq -0x28(%rbp), %rdi
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xccdb0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xcd243
cmpq $0x0, -0x28(%rbp)
jne 0xcd1f0
movq $0x0, -0x8(%rbp)
jmp 0xcd291
movq -0x30(%rbp), %rax
leaq 0x5bfb5(%rip), %rcx     # 0x1291b0
cmpq (%rcx), %rax
jbe 0xcd21b
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0xccdf0
movq %rax, -0x40(%rbp)
jmp 0xcd230
movq -0x20(%rbp), %rdi
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xccdb0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xcd241
movq $0x0, -0x8(%rbp)
jmp 0xcd291
jmp 0xcd243
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0xcd257
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0xcd25f
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x1fbf0
movq -0x10(%rbp), %rdi
movb -0x32(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xcd2a0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)