// File: /workspace/github_c_makefile_star2_O3/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, %r14d
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
callq 0x8ba30
testq %rax, %rax
jne 0x8bb50
movq %rbx, (%rsp)
leaq 0x53d89(%rip), %rbx     # 0xdf860
movq (%rbx), %rsi
leaq (%r12,%rbp), %rdi
cmpq %r13, %rsi
cmovbeq %r13, %rsi
movzbl %r14b, %r14d
movl %r14d, %edx
callq 0x8b92d
testq %rax, %rax
je 0x8bb2c
cmpq %r15, %r12
cmovbq %r12, %r15
movq %rax, %rbx
movq %rax, %rdi
movq (%rsp), %rbp
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1fbd0
leaq 0x53047(%rip), %rax     # 0xdeb60
cmpq $0x0, (%rax)
je 0x8bb5f
movq %rbp, %rdi
callq 0x8da50
movq %rbx, %rax
jmp 0x8bb50
testq %rbp, %rbp
je 0x8bb4e
movq (%rbx), %rax
cmpq %r13, %rax
cmovaq %rax, %r13
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x8b92d
testq %rax, %rax
jne 0x8baf6
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x53d1a(%rip), %rax     # 0xdf880
movq (%rax), %r15
notq %r15
andq %rbp, %r15
cmpq %rbp, %r15
je 0x8bc1a
movb 0x40(%rsp), %al
subq %r15, %rbp
shrq $0xc, %rbp
leaq 0x53d9e(%rip), %rcx     # 0xdf928
movq %rbp, %rdx
subq (%rcx), %rdx
movq (%r15), %r12
leaq (%rdx,%rdx,2), %rcx
movq 0x40(%r15,%rcx,8), %r14
testb $0x2, %r14b
jne 0x8bc2c
testb %al, %al
je 0x8bd39
movq 0x3a3a3(%rip), %rax     # 0xc5f58
movq %fs:0x0, %rsi
addq %rax, %rsi
movq %fs:(%rax), %r13
cmpq $0x3, %r13
ja 0x8bcba
jb 0x8bd39
jne 0x8bcbf
movq $0x2, %fs:(%rax)
leaq 0x64fc6(%rip), %rax     # 0xf0bb0
movl (%rax), %edi
callq 0x1f1c0
testl %eax, %eax
je 0x8bd39
leaq 0x1756e(%rip), %rdi     # 0xa316e
callq 0x915d4
leaq 0x52f4e(%rip), %rax     # 0xdeb5a
cmpb $0x1, (%rax)
jne 0x8bd39
jmp 0x8bcb5
movq %rbp, %rdi
movl $0x1, %esi
callq 0x8bdfd
jmp 0x8bb27
testb %al, %al
je 0x8bde9
movq %r14, %rdx
andq $-0x1000, %rdx          # imm = 0xF000
leaq 0x64f63(%rip), %rax     # 0xf0ba8
cmpq (%rax), %rdx
ja 0x8bde9
movq 0x3a303(%rip), %rax     # 0xc5f58
movq %fs:0x0, %rsi
addq %rax, %rsi
movq %fs:(%rax), %r13
cmpq $0x3, %r13
ja 0x8bd50
jb 0x8bde9
jne 0x8bd59
movq $0x2, %fs:(%rax)
leaq 0x64f26(%rip), %rax     # 0xf0bb0
movl (%rax), %edi
callq 0x1f1c0
testl %eax, %eax
je 0x8bde9
leaq 0x174ce(%rip), %rdi     # 0xa316e
callq 0x915d4
leaq 0x52eae(%rip), %rax     # 0xdeb5a
cmpb $0x1, (%rax)
jne 0x8bde9
callq 0x1f1b0
testq %r13, %r13
je 0x8bd39
shrl $0x4, %r14d
movzbl %r14b, %r15d
leaq 0x52e8d(%rip), %rax     # 0xdeb5b
cmpb $0x1, (%rax)
movq (%rsp), %r14
jne 0x8bcea
imulq $0x68, %r15, %rsi
addq 0x3a2ee(%rip), %rsi     # 0xc5fd0
movq %r14, %rdi
callq 0x80b41
movl %r15d, %eax
shll $0x5, %eax
leaq (%rax,%r13), %r12
addq $0x28, %r12
leaq 0x64e91(%rip), %rax     # 0xf0b90
movq (%rax), %rax
movl 0x10(%r12), %edx
cmpl (%rax,%r15,4), %edx
jne 0x8bd22
shrl %edx
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0x90bee
movl 0x10(%r12), %edx
movq 0x18(%r12), %rax
movl %edx, %ecx
movq %r14, (%rax,%rcx,8)
incl %edx
movl %edx, 0x10(%r12)
jmp 0x8bdc7
movq %r12, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
movq %rbp, %rcx
callq 0x817a1
jmp 0x8bb27
testq %r13, %r13
je 0x8bde9
shrq $0xc, %r14
leaq 0x1b(%r14), %r12
leaq 0x52df3(%rip), %rax     # 0xdeb5b
cmpb $0x1, (%rax)
jne 0x8bd7b
movq (%rsp), %rdi
movl $0x5a, %esi
callq 0x1f110
movq %r12, %rax
shlq $0x5, %rax
leaq (%rax,%r13), %r15
addq $0x28, %r15
leaq 0x64dff(%rip), %rax     # 0xf0b90
movq (%rax), %rax
movl 0x10(%r15), %edx
cmpl 0x6c(%rax,%r14,4), %edx
jne 0x8bdb3
shrl %edx
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rcx
callq 0x90dea
movl 0x10(%r15), %edx
movq (%rsp), %rsi
movq 0x18(%r15), %rax
movl %edx, %ecx
movq %rsi, (%rax,%rcx,8)
incl %edx
movl %edx, 0x10(%r15)
movl 0x20(%r13), %eax
incl %eax
movl %eax, 0x20(%r13)
cmpl $0x125, %eax            # imm = 0x125
jne 0x8bb27
movq %r13, %rdi
callq 0x90b49
jmp 0x8bb27
movq %r12, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
callq 0x81c48
jmp 0x8bb27