// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/jemalloc.c
// Function: je_realloc
void *
je_realloc(void *ptr, size_t size)
{
	void *ret;
	size_t usize JEMALLOC_CC_SILENCE_INIT(0);
	size_t old_size = 0;
	size_t old_rzsize JEMALLOC_CC_SILENCE_INIT(0);
	prof_thr_cnt_t *cnt JEMALLOC_CC_SILENCE_INIT(NULL);
	prof_ctx_t *old_ctx JEMALLOC_CC_SILENCE_INIT(NULL);

	if (size == 0) {
		if (ptr != NULL) {
			/* realloc(ptr, 0) is equivalent to free(p). */
			if (config_prof) {
				old_size = isalloc(ptr, true);
				if (config_valgrind && opt_valgrind)
					old_rzsize = p2rz(ptr);
			} else if (config_stats) {
				old_size = isalloc(ptr, false);
				if (config_valgrind && opt_valgrind)
					old_rzsize = u2rz(old_size);
			} else if (config_valgrind && opt_valgrind) {
				old_size = isalloc(ptr, false);
				old_rzsize = u2rz(old_size);
			}
			if (config_prof && opt_prof) {
				old_ctx = prof_ctx_get(ptr);
				cnt = NULL;
			}
			iqalloc(ptr);
			ret = NULL;
			goto label_return;
		} else
			size = 1;
	}

	if (ptr != NULL) {
		assert(malloc_initialized || IS_INITIALIZER);

		if (config_prof) {
			old_size = isalloc(ptr, true);
			if (config_valgrind && opt_valgrind)
				old_rzsize = p2rz(ptr);
		} else if (config_stats) {
			old_size = isalloc(ptr, false);
			if (config_valgrind && opt_valgrind)
				old_rzsize = u2rz(old_size);
		} else if (config_valgrind && opt_valgrind) {
			old_size = isalloc(ptr, false);
			old_rzsize = u2rz(old_size);
		}
		if (config_prof && opt_prof) {
			usize = s2u(size);
			old_ctx = prof_ctx_get(ptr);
			PROF_ALLOC_PREP(1, usize, cnt);
			if (cnt == NULL) {
				old_ctx = NULL;
				ret = NULL;
				goto label_oom;
			}
			if (prof_promote && (uintptr_t)cnt != (uintptr_t)1U &&
			    usize <= SMALL_MAXCLASS) {
				ret = iralloc(ptr, SMALL_MAXCLASS+1, 0, 0,
				    false, false);
				if (ret != NULL)
					arena_prof_promoted(ret, usize);
				else
					old_ctx = NULL;
			} else {
				ret = iralloc(ptr, size, 0, 0, false, false);
				if (ret == NULL)
					old_ctx = NULL;
			}
		} else {
			if (config_stats || (config_valgrind && opt_valgrind))
				usize = s2u(size);
			ret = iralloc(ptr, size, 0, 0, false, false);
		}

label_oom:
		if (ret == NULL) {
			if (config_xmalloc && opt_xmalloc) {
				malloc_write("<jemalloc>: Error in realloc(): "
				    "out of memory\n");
				abort();
			}
			set_errno(ENOMEM);
		}
	} else {
		/* realloc(NULL, size) is equivalent to malloc(size). */
		if (config_prof && opt_prof)
			old_ctx = NULL;
		if (malloc_init()) {
			if (config_prof && opt_prof)
				cnt = NULL;
			ret = NULL;
		} else {
			if (config_prof && opt_prof) {
				usize = s2u(size);
				PROF_ALLOC_PREP(1, usize, cnt);
				if (cnt == NULL)
					ret = NULL;
				else {
					if (prof_promote && (uintptr_t)cnt !=
					    (uintptr_t)1U && usize <=
					    SMALL_MAXCLASS) {
						ret = imalloc(SMALL_MAXCLASS+1);
						if (ret != NULL) {
							arena_prof_promoted(ret,
							    usize);
						}
					} else
						ret = imalloc(size);
				}
			} else {
				if (config_stats || (config_valgrind &&
				    opt_valgrind))
					usize = s2u(size);
				ret = imalloc(size);
			}
		}

		if (ret == NULL) {
			if (config_xmalloc && opt_xmalloc) {
				malloc_write("<jemalloc>: Error in realloc(): "
				    "out of memory\n");
				abort();
			}
			set_errno(ENOMEM);
		}
	}

label_return:
	if (config_prof && opt_prof)
		prof_realloc(ret, usize, cnt, old_size, old_ctx);
	if (config_stats && ret != NULL) {
		thread_allocated_t *ta;
		assert(usize == isalloc(ret, config_prof));
		ta = thread_allocated_tsd_get();
		ta->allocated += usize;
		ta->deallocated += old_size;
	}
	UTRACE(ptr, size, ret);
	JEMALLOC_VALGRIND_REALLOC(ret, usize, ptr, old_size, old_rzsize, false);
	return (ret);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
testq %rsi, %rsi
je 0x7646f
movq %rsi, %r15
testq %rbx, %rbx
je 0x764ed
movq %rbx, %rdi
callq 0x76240
movq %rax, %r14
cmpb $0x1, 0x6570a(%rip)     # 0xdbb6a
jne 0x7649c
movq %r14, %rdi
callq 0x766aa
movq %rax, %r13
jmp 0x7649f
testq %rbx, %rbx
je 0x764e9
movq %rbx, %rdi
callq 0x76240
movq %rax, %r14
cmpb $0x1, 0x656e4(%rip)     # 0xdbb6a
jne 0x7654b
movq %r14, %rdi
callq 0x766aa
movq %rax, %r13
jmp 0x7654e
xorl %r13d, %r13d
movq %r15, %rdi
callq 0x760c0
movq %rax, %r12
andq $0x0, 0x8(%rsp)
movl $0x1, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x76ec2
testq %rax, %rax
je 0x764d6
movq %rax, %r15
jmp 0x7651c
callq 0x1f810
movl $0xc, (%rax)
movb $0x1, %bpl
xorl %r15d, %r15d
jmp 0x7655f
pushq $0x1
popq %r15
callq 0x75442
testb %al, %al
je 0x764fb
xorl %r12d, %r12d
jmp 0x76532
movq %r15, %rdi
callq 0x760c0
movq %rax, %r12
movq %r15, %rdi
callq 0x7611b
testq %rax, %rax
je 0x76532
movq %rax, %r15
xorl %r13d, %r13d
xorl %r14d, %r14d
addq %r12, %fs:-0x28
addq %r14, %fs:-0x20
xorl %ebp, %ebp
jmp 0x7655f
callq 0x1f810
movl $0xc, (%rax)
movb $0x1, %bpl
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r13d, %r13d
jmp 0x7655f
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x766d9
movb $0x1, %bpl
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpb $0x1, 0x65604(%rip)     # 0xdbb6a
jne 0x76698
movq %r15, %rdi
callq 0x76125
movq %rax, %rcx
cmpq %rbx, %r15
je 0x76655
testq %rbx, %rbx
je 0x765c6
leaq 0x20(%rsp), %rax
movq $0x1302, (%rax)         # imm = 0x1302
movq %rbx, 0x8(%rax)
movq %r13, 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, 0x18(%rsp)
movq 0x18(%rsp), %rax
testb %bpl, %bpl
jne 0x76698
cmpq %r12, %r14
cmovaeq %r12, %r14
leaq 0x20(%rsp), %rax
movq $0x1301, (%rax)         # imm = 0x1301
movq %r15, 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, 0x18(%rsp)
movq 0x18(%rsp), %rax
testq %r14, %r14
je 0x76698
leaq 0x20(%rsp), %rax
movq $0x4d430002, (%rax)     # imm = 0x4D430002
movq %r15, 0x8(%rax)
movq %r14, 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 0x7668e
leaq 0x20(%rsp), %rax
movq $0x130b, (%rax)         # imm = 0x130B
movq %rbx, 0x8(%rax)
movq %r14, 0x10(%rax)
movq %r12, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq $0x0, 0x28(%rax)
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %r15, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq