// File: /workspace/github_c_makefile_star2_O1/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 0x8b7b8
testq %rax, %rax
jne 0x8b8d8
movq %rbx, (%rsp)
leaq 0x54001(%rip), %rbx     # 0xdf860
movq (%rbx), %rsi
leaq (%r12,%rbp), %rdi
cmpq %r13, %rsi
cmovbeq %r13, %rsi
movzbl %r14b, %r14d
movl %r14d, %edx
callq 0x8b6b5
testq %rax, %rax
je 0x8b8b4
cmpq %r15, %r12
cmovbq %r12, %r15
movq %rax, %rbx
movq %rax, %rdi
movq (%rsp), %rbp
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1fbd0
leaq 0x532bf(%rip), %rax     # 0xdeb60
cmpq $0x0, (%rax)
je 0x8b8e7
movq %rbp, %rdi
callq 0x8d814
movq %rbx, %rax
jmp 0x8b8d8
testq %rbp, %rbp
je 0x8b8d6
movq (%rbx), %rax
cmpq %r13, %rax
cmovaq %rax, %r13
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x8b6b5
testq %rax, %rax
jne 0x8b87e
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x53f92(%rip), %rax     # 0xdf880
movq (%rax), %r15
notq %r15
andq %rbp, %r15
cmpq %rbp, %r15
je 0x8b94d
movb 0x40(%rsp), %al
subq %r15, %rbp
shrq $0xc, %rbp
leaq 0x5401a(%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 0x8b95f
testb %al, %al
je 0x8ba6b
movq 0x3a623(%rip), %rax     # 0xc5f58
movq %fs:(%rax), %r13
cmpq $0x3, %r13
ja 0x8b9f1
jae 0x8b9a4
xorl %r13d, %r13d
jmp 0x8b9f1
movq %rbp, %rdi
movl $0x1, %esi
callq 0x8bb7e
jmp 0x8b8af
testb %al, %al
je 0x8bb6a
movq %r14, %rbp
andq $-0x1000, %rbp          # imm = 0xF000
leaq 0x65230(%rip), %rax     # 0xf0ba8
cmpq (%rax), %rbp
ja 0x8bb6a
movq 0x3a5d0(%rip), %rax     # 0xc5f58
movq %fs:(%rax), %r13
cmpq $0x3, %r13
ja 0x8bacf
jae 0x8ba82
xorl %r13d, %r13d
jmp 0x8bacf
jne 0x8b9f1
movq %fs:0x0, %rsi
addq %rax, %rsi
movq $0x2, %fs:(%rax)
leaq 0x651ef(%rip), %rax     # 0xf0bb0
movl (%rax), %edi
callq 0x1f1c0
testl %eax, %eax
je 0x8b945
leaq 0x176bf(%rip), %rdi     # 0xa3096
callq 0x9124c
leaq 0x53177(%rip), %rax     # 0xdeb5a
cmpb $0x1, (%rax)
jne 0x8b945
jmp 0x8baca
testq %r13, %r13
je 0x8ba6b
shrl $0x4, %r14d
movzbl %r14b, %r15d
leaq 0x53156(%rip), %rax     # 0xdeb5b
cmpb $0x1, (%rax)
movq (%rsp), %r12
jne 0x8ba21
imulq $0x68, %r15, %rsi
addq 0x3a5b7(%rip), %rsi     # 0xc5fd0
movq %r12, %rdi
callq 0x8085a
movl %r15d, %eax
shll $0x5, %eax
leaq (%rax,%r13), %r14
addq $0x28, %r14
leaq 0x6515a(%rip), %rax     # 0xf0b90
movq (%rax), %rax
movl (%rax,%r15,4), %edx
cmpl %edx, 0x10(%r14)
jne 0x8ba53
shrl %edx
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0x908bd
movq 0x18(%r14), %rax
movl 0x10(%r14), %ecx
movq %r12, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movl %eax, 0x10(%r14)
jmp 0x8bb48
movq %r12, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
movq %rbp, %rcx
callq 0x8147f
jmp 0x8b8af
jne 0x8bacf
movq %fs:0x0, %rsi
addq %rax, %rsi
movq $0x2, %fs:(%rax)
leaq 0x65111(%rip), %rax     # 0xf0bb0
movl (%rax), %edi
callq 0x1f1c0
testl %eax, %eax
je 0x8b99c
leaq 0x175e1(%rip), %rdi     # 0xa3096
callq 0x9124c
leaq 0x53099(%rip), %rax     # 0xdeb5a
cmpb $0x1, (%rax)
jne 0x8b99c
callq 0x1f1b0
testq %r13, %r13
je 0x8bb6a
shrq $0xc, %r14
leaq 0x1b(%r14), %r12
leaq 0x53074(%rip), %rax     # 0xdeb5b
cmpb $0x1, (%rax)
jne 0x8bafd
movq (%rsp), %rdi
movl $0x5a, %esi
movq %rbp, %rdx
callq 0x1f110
movq %r12, %rax
shlq $0x5, %rax
leaq (%rax,%r13), %r15
addq $0x28, %r15
leaq 0x6507d(%rip), %rax     # 0xf0b90
movq (%rax), %rax
movl 0x6c(%rax,%r14,4), %edx
cmpl %edx, 0x10(%r15)
jne 0x8bb31
shrl %edx
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rcx
callq 0x90ac1
movq 0x18(%r15), %rax
movl 0x10(%r15), %ecx
movq (%rsp), %rdx
movq %rdx, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movl %eax, 0x10(%r15)
movl 0x20(%r13), %eax
incl %eax
movl %eax, 0x20(%r13)
cmpl $0x125, %eax            # imm = 0x125
jne 0x8b8af
movq %r13, %rdi
callq 0x90815
jmp 0x8b8af
movq %r12, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
callq 0x81920
jmp 0x8b8af