// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/jemalloc.c
// Function: je_rallocm
int
je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags)
{
	void *p, *q;
	size_t usize;
	size_t old_size;
	size_t old_rzsize JEMALLOC_CC_SILENCE_INIT(0);
	size_t alignment = (ZU(1) << (flags & ALLOCM_LG_ALIGN_MASK)
	    & (SIZE_T_MAX-1));
	bool zero = flags & ALLOCM_ZERO;
	bool no_move = flags & ALLOCM_NO_MOVE;
	unsigned arena_ind = ((unsigned)(flags >> 8)) - 1;
	bool try_tcache_alloc, try_tcache_dalloc;
	arena_t *arena;

	assert(ptr != NULL);
	assert(*ptr != NULL);
	assert(size != 0);
	assert(SIZE_T_MAX - size >= extra);
	assert(malloc_initialized || IS_INITIALIZER);

	if (arena_ind != UINT_MAX) {
		arena_chunk_t *chunk;
		try_tcache_alloc = true;
		chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(*ptr);
		try_tcache_dalloc = (chunk == *ptr || chunk->arena !=
		    arenas[arena_ind]);
		arena = arenas[arena_ind];
	} else {
		try_tcache_alloc = true;
		try_tcache_dalloc = true;
		arena = NULL;
	}

	p = *ptr;
	if (config_prof && opt_prof) {
		prof_thr_cnt_t *cnt;

		/*
		 * usize isn't knowable before iralloc() returns when extra is
		 * non-zero.  Therefore, compute its maximum possible value and
		 * use that in PROF_ALLOC_PREP() to decide whether to capture a
		 * backtrace.  prof_realloc() will use the actual usize to
		 * decide whether to sample.
		 */
		size_t max_usize = (alignment == 0) ? s2u(size+extra) :
		    sa2u(size+extra, alignment);
		prof_ctx_t *old_ctx = prof_ctx_get(p);
		old_size = isalloc(p, true);
		if (config_valgrind && opt_valgrind)
			old_rzsize = p2rz(p);
		PROF_ALLOC_PREP(1, max_usize, cnt);
		if (cnt == NULL)
			goto label_oom;
		/*
		 * Use minimum usize to determine whether promotion may happen.
		 */
		if (prof_promote && (uintptr_t)cnt != (uintptr_t)1U
		    && ((alignment == 0) ? s2u(size) : sa2u(size, alignment))
		    <= SMALL_MAXCLASS) {
			q = irallocx(p, SMALL_MAXCLASS+1, (SMALL_MAXCLASS+1 >=
			    size+extra) ? 0 : size+extra - (SMALL_MAXCLASS+1),
			    alignment, zero, no_move, try_tcache_alloc,
			    try_tcache_dalloc, arena);
			if (q == NULL)
				goto label_err;
			if (max_usize < PAGE) {
				usize = max_usize;
				arena_prof_promoted(q, usize);
			} else
				usize = isalloc(q, config_prof);
		} else {
			q = irallocx(p, size, extra, alignment, zero, no_move,
			    try_tcache_alloc, try_tcache_dalloc, arena);
			if (q == NULL)
				goto label_err;
			usize = isalloc(q, config_prof);
		}
		prof_realloc(q, usize, cnt, old_size, old_ctx);
		if (rsize != NULL)
			*rsize = usize;
	} else {
		if (config_stats) {
			old_size = isalloc(p, false);
			if (config_valgrind && opt_valgrind)
				old_rzsize = u2rz(old_size);
		} else if (config_valgrind && opt_valgrind) {
			old_size = isalloc(p, false);
			old_rzsize = u2rz(old_size);
		}
		q = irallocx(p, size, extra, alignment, zero, no_move,
		    try_tcache_alloc, try_tcache_dalloc, arena);
		if (q == NULL)
			goto label_err;
		if (config_stats)
			usize = isalloc(q, config_prof);
		if (rsize != NULL) {
			if (config_stats == false)
				usize = isalloc(q, config_prof);
			*rsize = usize;
		}
	}

	*ptr = q;
	if (config_stats) {
		thread_allocated_t *ta;
		ta = thread_allocated_tsd_get();
		ta->allocated += usize;
		ta->deallocated += old_size;
	}
	UTRACE(p, size, q);
	JEMALLOC_VALGRIND_REALLOC(q, usize, p, old_size, old_rzsize, zero);
	return (ALLOCM_SUCCESS);
label_err:
	if (no_move) {
		UTRACE(p, size, q);
		return (ALLOCM_ERR_NOT_MOVED);
	}
label_oom:
	if (config_xmalloc && opt_xmalloc) {
		malloc_write("<jemalloc>: Error in rallocm(): "
		    "out of memory\n");
		abort();
	}
	UTRACE(p, size, 0);
	return (ALLOCM_ERR_OOM);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, %ebx
movq %rcx, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
pushq $0x1
popq %r14
movl %ebx, %ecx
shlq %cl, %r14
movq %rdi, 0x10(%rsp)
movq (%rdi), %r15
movb $0x1, %r12b
cmpl $0x100, %r8d            # imm = 0x100
movq %rsi, 0x18(%rsp)
jae 0x76bee
xorl %ebp, %ebp
jmp 0x76c24
movl %ebx, %eax
sarl $0x8, %eax
decl %eax
leaq 0x65c84(%rip), %rcx     # 0xdc880
movq (%rcx), %rcx
notq %rcx
andq %r15, %rcx
movq 0x64f6c(%rip), %rdx     # 0xdbb78
movl %eax, %eax
cmpq %rcx, %r15
je 0x76c20
movq (%rdx,%rax,8), %rbp
cmpq %rbp, (%rcx)
setne %r12b
jmp 0x76c24
movq (%rdx,%rax,8), %rbp
andq $-0x2, %r14
movq %r15, %rdi
callq 0x76240
cmpb $0x1, 0x64f33(%rip)     # 0xdbb6a
jne 0x76c4b
movq %rax, %r13
movq %rax, %rdi
callq 0x766aa
movq %rax, 0x8(%rsp)
jmp 0x76c57
movq %rax, %r13
movq $0x0, 0x8(%rsp)
movl %ebx, %r8d
andl $0x40, %r8d
shrl $0x6, %r8d
movzbl %r12b, %eax
movl %ebx, %ecx
shrb $0x7, %cl
movzbl %cl, %r9d
movq %r15, %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r14, %rcx
pushq %rbp
pushq %rax
callq 0x76ec2
addq $0x10, %rsp
testq %rax, %rax
je 0x76e15
movq %rax, %rbp
movq %rax, %rdi
callq 0x76240
movq %rax, %r12
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x76cae
movq %r12, (%rax)
movq 0x10(%rsp), %rax
movq %rbp, (%rax)
addq %r12, %fs:-0x28
addq %r13, %fs:-0x20
xorl %ecx, %ecx
cmpb $0x1, 0x64e99(%rip)     # 0xdbb6a
jne 0x76eb1
movq %rbp, %rdi
callq 0x76125
movq %rax, %rcx
cmpq %r15, %rbp
je 0x76e22
testq %r15, %r15
je 0x76d34
leaq 0x30(%rsp), %rax
movq $0x1302, (%rax)         # imm = 0x1302
movq %r15, 0x8(%rax)
movq 0x8(%rsp), %rdx
movq %rdx, 0x10(%rax)
xorl %edx, %edx
movq %rdx, 0x18(%rax)
movq %rdx, 0x20(%rax)
movq %rdx, 0x28(%rax)
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, (%rsp)
movq (%rsp), %rax
cmpq %r12, %r13
movq %r12, %rsi
cmovbq %r13, %rsi
leaq 0x30(%rsp), %rax
movq $0x1301, (%rax)         # imm = 0x1301
movq %rbp, 0x8(%rax)
movq %r12, 0x10(%rax)
movq %rcx, 0x18(%rax)
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movq %rcx, 0x28(%rax)
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, (%rsp)
movq (%rsp), %rax
testq %rsi, %rsi
je 0x76dc1
leaq 0x30(%rsp), %rax
movq $0x4d430002, (%rax)     # imm = 0x4D430002
movq %rbp, 0x8(%rax)
movq %rsi, 0x10(%rax)
xorl %edx, %edx
movq %rdx, 0x18(%rax)
movq %rdx, 0x20(%rax)
movq %rdx, 0x28(%rax)
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, (%rsp)
movq (%rsp), %rax
testb $0x40, %bl
je 0x76eb1
cmpq %r13, %r12
jbe 0x76eb1
subq %rsi, %r12
leaq 0x30(%rsp), %rax
movq $0x4d430002, (%rax)     # imm = 0x4D430002
addq %rsi, %rbp
movq %rbp, 0x8(%rax)
movq %r12, 0x10(%rax)
xorl %ecx, %ecx
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq %rcx, 0x28(%rax)
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
jmp 0x76ea9
shrb $0x7, %bl
movzbl %bl, %ecx
incl %ecx
jmp 0x76eb1
leaq 0x30(%rsp), %rax
movq $0x130b, (%rax)         # imm = 0x130B
movq %r15, 0x8(%rax)
movq %r13, 0x10(%rax)
movq %r12, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq $0x0, 0x28(%rax)
xorl %ecx, %ecx
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, (%rsp)
movq (%rsp), %rax
testb $0x40, %bl
je 0x76eb1
subq %r13, %r12
jbe 0x76eb1
leaq 0x30(%rsp), %rax
movq $0x4d430002, (%rax)     # imm = 0x4D430002
addq %r15, %r13
movq %r13, 0x8(%rax)
movq %r12, 0x10(%rax)
xorl %ecx, %ecx
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq %rcx, 0x28(%rax)
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, (%rsp)
movq (%rsp), %rax
movl %ecx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq