// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/chunk.c
// Function: chunk_alloc
void *
chunk_alloc(size_t size, size_t alignment, bool base, bool *zero,
    dss_prec_t dss_prec)
{
	void *ret;

	assert(size != 0);
	assert((size & chunksize_mask) == 0);
	assert(alignment != 0);
	assert((alignment & chunksize_mask) == 0);

	/* "primary" dss. */
	if (config_dss && dss_prec == dss_prec_primary) {
		if ((ret = chunk_recycle(&chunks_szad_dss, &chunks_ad_dss, size,
		    alignment, base, zero)) != NULL)
			goto label_return;
		if ((ret = chunk_alloc_dss(size, alignment, zero)) != NULL)
			goto label_return;
	}
	/* mmap. */
	if ((ret = chunk_recycle(&chunks_szad_mmap, &chunks_ad_mmap, size,
	    alignment, base, zero)) != NULL)
		goto label_return;
	if ((ret = chunk_alloc_mmap(size, alignment, zero)) != NULL)
		goto label_return;
	/* "secondary" dss. */
	if (config_dss && dss_prec == dss_prec_secondary) {
		if ((ret = chunk_recycle(&chunks_szad_dss, &chunks_ad_dss, size,
		    alignment, base, zero)) != NULL)
			goto label_return;
		if ((ret = chunk_alloc_dss(size, alignment, zero)) != NULL)
			goto label_return;
	}

	/* All strategies for allocation failed. */
	ret = NULL;
label_return:
	if (config_ivsalloc && base == false && ret != NULL) {
		if (rtree_set(chunks_rtree, (uintptr_t)ret, ret)) {
			chunk_dealloc(ret, size, true);
			return (NULL);
		}
	}
	if ((config_stats || config_prof) && ret != NULL) {
		bool gdump;
		malloc_mutex_lock(&chunks_mtx);
		if (config_stats)
			stats_chunks.nchunks += (size / chunksize);
		stats_chunks.curchunks += (size / chunksize);
		if (stats_chunks.curchunks > stats_chunks.highchunks) {
			stats_chunks.highchunks = stats_chunks.curchunks;
			if (config_prof)
				gdump = true;
		} else if (config_prof)
			gdump = false;
		malloc_mutex_unlock(&chunks_mtx);
		if (config_prof && opt_prof && opt_prof_gdump && gdump)
			prof_gdump();
	}
	if (config_debug && *zero && ret != NULL) {
		size_t i;
		size_t *p = (size_t *)(uintptr_t)ret;

		VALGRIND_MAKE_MEM_DEFINED(ret, size);
		for (i = 0; i < size / sizeof(size_t); i++)
			assert(p[i] == 0);
	}
	assert(CHUNK_ADDR2BASE(ret) == ret);
	return (ret);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r14
movq %rsi, %r15
movq %rdi, %rbx
testl %edx, %edx
jne 0x85948
leaq (%r15,%rbx), %rax
subq 0x5a103(%rip), %rax     # 0xdf860
cmpq %rbx, %rax
jb 0x85948
leaq 0x58(%rsp), %r12
movq $0x0, 0x28(%r12)
movq %rax, 0x30(%r12)
leaq 0x5a0b8(%rip), %rdi     # 0xdf838
callq 0x1faa0
leaq 0x5a01c(%rip), %rdi     # 0xdf7a8
movq %r12, %rsi
callq 0x8a55c
testq %rax, %rax
je 0x85834
movq %rax, %r13
movq 0x28(%rax), %rbp
movq 0x30(%rax), %rax
movq %rax, 0x10(%rsp)
leaq (%r15,%rbp), %rax
decq %rax
movq %r15, %r12
negq %r12
andq %rax, %r12
movq %r12, %rax
subq %rbp, %rax
addq %rbx, %rax
movq %rax, 0x8(%rsp)
leaq 0x59fd6(%rip), %rdi     # 0xdf7a8
movq %r13, %rsi
callq 0x8a7a8
leaq 0x5a00f(%rip), %rdi     # 0xdf7f0
movq %r13, %rsi
callq 0x8b21b
movq %r12, %rax
subq %rbp, %rax
jne 0x85845
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %rax
cmpq %rax, %rbp
jne 0x858a4
leaq 0x5a02d(%rip), %rdi     # 0xdf838
callq 0x1fbb0
movb 0x38(%r13), %bpl
cmpb $0x1, %bpl
jne 0x8581e
movb $0x1, (%r14)
movq %r13, %rdi
callq 0x855bf
testb %bpl, %bpl
jne 0x85931
jmp 0x858dd
leaq 0x59ffd(%rip), %rdi     # 0xdf838
callq 0x1fbb0
jmp 0x85948
movq %rax, 0x30(%r13)
leaq 0x59f58(%rip), %rdi     # 0xdf7a8
movq %r13, %rsi
callq 0x8a62c
leaq 0x59f91(%rip), %rdi     # 0xdf7f0
movq %r13, %rsi
callq 0x8b0af
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %rax
cmpq %rax, %rbp
je 0x858d1
leaq 0x59fbb(%rip), %rdi     # 0xdf838
callq 0x1fbb0
callq 0x85574
testq %rax, %rax
je 0x85938
movq %rax, %r13
leaq 0x59f9e(%rip), %rdi     # 0xdf838
callq 0x1faa0
movq 0x8(%rsp), %rax
subq %rax, %rbp
leaq (%r12,%rbx), %rax
movq %rax, 0x28(%r13)
movq %rbp, 0x30(%r13)
leaq 0x59eee(%rip), %rdi     # 0xdf7a8
movq %r13, %rsi
callq 0x8a62c
leaq 0x59f27(%rip), %rdi     # 0xdf7f0
movq %r13, %rsi
callq 0x8b0af
leaq 0x59f60(%rip), %rdi     # 0xdf838
callq 0x1fbb0
cmpb $0x1, (%r14)
jne 0x85931
leaq 0x20(%rsp), %rax
movq $0x4d430001, (%rax)     # imm = 0x4D430001
movq %r12, 0x8(%rax)
movq %rbx, 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, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %r12, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1f110
testq %r12, %r12
jne 0x8595e
jmp 0x85948
movq %r12, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x85b4a
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x85e56
movq %rax, %r12
testq %rax, %rax
je 0x859a9
leaq 0x59ed3(%rip), %rdi     # 0xdf838
callq 0x1faa0
movq %rbx, %rax
xorl %edx, %edx
divq 0x59eea(%rip)           # 0xdf860
addq %rax, 0x59eeb(%rip)     # 0xdf868
addq 0x59ef4(%rip), %rax     # 0xdf878
movq %rax, 0x59eed(%rip)     # 0xdf878
cmpq 0x59ede(%rip), %rax     # 0xdf870
jbe 0x8599b
movq %rax, 0x59ed5(%rip)     # 0xdf870
leaq 0x59e96(%rip), %rdi     # 0xdf838
callq 0x1fbb0
jmp 0x859ac
xorl %r12d, %r12d
movq %r12, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq