// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %ebx
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
callq 0x82634
testq %rax, %rax
jne 0x82843
movq %r14, (%rsp)
leaq 0x5a187(%rip), %r14     # 0xdc860
leaq (%r12,%rbp), %rdi
movzbl %bl, %ebx
cmpq %r13, (%r14)
jae 0x826f1
movq %r13, %rsi
movl %ebx, %edx
callq 0x82531
jmp 0x826f8
movl %ebx, %esi
callq 0x82520
testq %rax, %rax
je 0x82736
cmpq %r15, %r12
cmovbq %r12, %r15
movq %rax, %r14
movq %rax, %rdi
movq (%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
callq 0x1fbd0
leaq 0x59440(%rip), %rax     # 0xdbb60
cmpq $0x0, (%rax)
je 0x8275a
movq %r13, %rdi
callq 0x842d8
movq %r14, %rax
jmp 0x82843
testq %rbp, %rbp
je 0x82841
cmpq %r13, (%r14)
jae 0x8282e
movq %r12, %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x82531
jmp 0x82838
leaq 0x5a11f(%rip), %rax     # 0xdc880
movq (%rax), %r15
notq %r15
andq %r13, %r15
cmpq %r13, %r15
je 0x82852
movb 0x40(%rsp), %al
subq %r15, %r13
shrq $0xc, %r13
leaq 0x5a1a3(%rip), %rcx     # 0xdc928
movq %r13, %rdx
subq (%rcx), %rdx
movq (%r15), %rbx
imulq $0x18, %rdx, %rcx
movq 0x40(%r15,%rcx), %rbp
testb $0x2, %bpl
jne 0x82862
testb %al, %al
je 0x8291f
callq 0x82afd
testq %rax, %rax
je 0x8291f
movq %rax, %r12
shrl $0x4, %ebp
movzbl %bpl, %ebx
leaq 0x59393(%rip), %rax     # 0xdbb5b
cmpb $0x1, (%rax)
movq (%rsp), %r13
jne 0x827e4
imulq $0x68, %rbx, %rsi
addq 0x407f4(%rip), %rsi     # 0xc2fd0
movq %r13, %rdi
callq 0x7833d
movl %ebx, %eax
shll $0x5, %eax
leaq (%r12,%rax), %r15
addq $0x28, %r15
leaq 0x6b398(%rip), %rcx     # 0xedb90
movq (%rcx), %rcx
movl 0x38(%r12,%rax), %edx
cmpl (%rcx,%rbx,4), %edx
jne 0x82819
shrl %edx
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rcx
callq 0x870f5
movl 0x10(%r15), %edx
movq 0x18(%r15), %rax
movl %edx, %ecx
movq %r13, (%rax,%rcx,8)
incl %edx
movl %edx, 0x10(%r15)
jmp 0x828fe
movq %r12, %rdi
movl %ebx, %esi
callq 0x82520
testq %rax, %rax
jne 0x826fd
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0x82936
jmp 0x8272e
testb %al, %al
je 0x8290b
movq %rbp, %r13
andq $-0x1000, %r13          # imm = 0xF000
leaq 0x6b32d(%rip), %rax     # 0xedba8
cmpq (%rax), %r13
ja 0x8290b
callq 0x82afd
testq %rax, %rax
je 0x8290b
movq %rax, %r12
shrq $0xc, %rbp
leaq 0x1b(%rbp), %r15
leaq 0x592bb(%rip), %rax     # 0xdbb5b
cmpb $0x1, (%rax)
jne 0x828b4
pushq $0x5a
popq %rsi
movq (%rsp), %rdi
movq %r13, %rdx
callq 0x1f110
movq %r15, %rax
shlq $0x5, %rax
leaq (%r12,%rax), %rbx
addq $0x28, %rbx
leaq 0x6b2c6(%rip), %rcx     # 0xedb90
movq (%rcx), %rcx
movl 0x38(%r12,%rax), %edx
cmpl 0x6c(%rcx,%rbp,4), %edx
jne 0x828eb
shrl %edx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x872d5
movl 0x10(%rbx), %edx
movq (%rsp), %rsi
movq 0x18(%rbx), %rax
movl %edx, %ecx
movq %rsi, (%rax,%rcx,8)
incl %edx
movl %edx, 0x10(%rbx)
movq %r12, %rdi
callq 0x82b60
jmp 0x8272e
movq %rbx, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
callq 0x792f7
jmp 0x8272e
movq %rbx, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
movq %r13, %rcx
callq 0x78e5d
jmp 0x8272e