// File: /workspace/github_c_makefile_star2_O2/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/base.c
// Function: je_base_alloc
void *
base_alloc(tsdn_t *tsdn, size_t size)
{
	void *ret;
	size_t csize, usize;
	extent_node_t *node;
	extent_node_t key;

	/*
	 * Round size up to nearest multiple of the cacheline size, so that
	 * there is no chance of false cache line sharing.
	 */
	csize = CACHELINE_CEILING(size);

	usize = s2u(csize);
	extent_node_init(&key, NULL, NULL, usize, 0, false, false);
	malloc_mutex_lock(tsdn, &base_mtx);
	node = extent_tree_szsnad_nsearch(&base_avail_szsnad, &key);
	if (node != NULL) {
		/* Use existing space. */
		extent_tree_szsnad_remove(&base_avail_szsnad, node);
	} else {
		/* Try to allocate more space. */
		node = base_chunk_alloc(tsdn, csize);
	}
	if (node == NULL) {
		ret = NULL;
		goto label_return;
	}

	ret = extent_node_addr_get(node);
	if (extent_node_size_get(node) > csize) {
		extent_node_addr_set(node, (void *)((uintptr_t)ret + csize));
		extent_node_size_set(node, extent_node_size_get(node) - csize);
		extent_tree_szsnad_insert(&base_avail_szsnad, node);
	} else
		base_node_dalloc(tsdn, node);
	if (config_stats) {
		base_allocated += csize;
		/*
		 * Add one PAGE to base_resident for every page boundary that is
		 * crossed by the new allocation.
		 */
		base_resident += PAGE_CEILING((uintptr_t)ret + csize) -
		    PAGE_CEILING((uintptr_t)ret);
	}
	JEMALLOC_VALGRIND_MAKE_MEM_DEFINED(ret, csize);
label_return:
	malloc_mutex_unlock(tsdn, &base_mtx);
	return (ret);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
addq $0x3f, %rbx
andq $-0x40, %rbx
cmpq $0x1000, %rbx           # imm = 0x1000
ja 0x20f34
leaq -0x1(%rbx), %rax
shrq $0x3, %rax
leaq 0x15c32(%rip), %rcx     # 0x369c0
movzbl (%rcx,%rax), %eax
leaq 0x154a7(%rip), %rcx     # 0x36240
movq (%rcx,%rax,8), %rax
xorps %xmm0, %xmm0
movq %rsp, %r14
movaps %xmm0, (%r14)
movq %rax, 0x10(%r14)
andq $0x0, 0x18(%r14)
andl $0x0, 0x1f(%r14)
leaq 0x2821c(%rip), %rdi     # 0x48fd8
callq 0xb5a0
leaq 0x28260(%rip), %rdi     # 0x49028
movq %r14, %rsi
callq 0x26c7f
testq %rax, %rax
je 0x20df4
movq %rax, %r14
leaq 0x28249(%rip), %rdi     # 0x49028
movq %rax, %rsi
callq 0x26e79
movq 0x8(%r14), %r15
movq 0x10(%r14), %r12
jmp 0x20e9f
movq 0x28255(%rip), %r14     # 0x49050
testq %r14, %r14
je 0x20e1e
movq (%r14), %rax
movq %rax, 0x28246(%rip)     # 0x49050
leaq 0x2778b(%rip), %rax     # 0x4859c
cmpb $0x1, (%rax)
je 0x20f83
xorl %eax, %eax
jmp 0x20e23
movl $0x80, %eax
addq %rbx, %rax
leaq 0x282a3(%rip), %rcx     # 0x490d0
movq (%rcx), %r12
addq %r12, %rax
notq %r12
andq %rax, %r12
movq %r12, %rdi
callq 0x21419
testq %rax, %rax
je 0x20f22
movq %rax, %r15
addq %r12, 0x281ec(%rip)     # 0x49040
testq %r14, %r14
jne 0x20e77
movq %r15, %r14
subq $-0x80, %r15
addq $-0x80, %r12
subq $-0x80, 0x281c4(%rip)   # 0x49030
addq $0x1000, 0x281c1(%rip) # imm = 0x1000
pushq $0x1
popq %rax
lock
xaddq %rax, 0x281c5(%rip)     # 0x49048
andq $0x0, (%r14)
movq %r15, 0x8(%r14)
movq %r12, 0x10(%r14)
movq %rax, 0x18(%r14)
movw $0x101, 0x20(%r14)      # imm = 0x101
movb $0x0, 0x22(%r14)
subq %rbx, %r12
jbe 0x20ec1
leaq (%rbx,%r15), %rax
movq %rax, 0x8(%r14)
movq %r12, 0x10(%r14)
leaq 0x28171(%rip), %rdi     # 0x49028
movq %r14, %rsi
callq 0x26d07
jmp 0x20ec9
movq %r14, %rdi
callq 0x20f9a
movq %r15, %rax
addq %rbx, 0x2815d(%rip)     # 0x49030
leaq (%r15,%rbx), %rcx
addq $0xfff, %rcx            # imm = 0xFFF
movq $-0x1000, %rdx          # imm = 0xF000
andq %rdx, %rcx
addq $0xfff, %rax            # imm = 0xFFF
andq %rdx, %rax
subq %rax, %rcx
addq %rcx, 0x2813d(%rip)     # 0x49038
leaq 0x2769a(%rip), %rax     # 0x4859c
cmpb $0x1, (%rax)
je 0x20f76
leaq 0x280ca(%rip), %rdi     # 0x48fd8
callq 0xb380
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
testq %r14, %r14
je 0x20f2f
movq %r14, %rdi
callq 0x20f9a
xorl %r15d, %r15d
jmp 0x20f07
movabsq $0x7000000000000000, %rax # imm = 0x7000000000000000
cmpq %rax, %rbx
ja 0x20f93
leaq -0x1(,%rbx,2), %rax
bsrq %rax, %rax
movl %eax, %ecx
addb $-0x3, %cl
pushq $-0x1
popq %rdx
shlq %cl, %rdx
cmpl $0x6, %eax
notq %rdx
pushq $0x7
popq %rax
cmovaeq %rdx, %rax
leaq (%rax,%rbx), %rcx
notq %rax
andq %rcx, %rax
jmp 0x20d9d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x324d8
jmp 0x20f07
pushq $0x70
popq %rsi
movq %r14, %rdi
callq 0x32496
jmp 0x20e1a
xorl %eax, %eax
jmp 0x20d9d