// File: /workspace/github_c_makefile_star2_O3/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 0xfa8e
leaq -0x1(%rbx), %rax
shrq $0x3, %rax
leaq 0x2c58e(%rip), %rcx     # 0x3be40
movzbl (%rcx,%rax), %eax
leaq 0x2be03(%rip), %rcx     # 0x3b6c0
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 0x3d6f8(%rip), %rdi     # 0x4cfd8
callq 0xb5a0
leaq 0x3d73c(%rip), %rdi     # 0x4d028
movq %r14, %rsi
callq 0x2c64f
testq %rax, %rax
je 0xf918
movq %rax, %r14
leaq 0x3d725(%rip), %rdi     # 0x4d028
movq %rax, %rsi
callq 0x2cb18
movq 0x8(%r14), %r15
movq 0x10(%r14), %r12
jmp 0xf9c3
movq 0x3d731(%rip), %r14     # 0x4d050
testq %r14, %r14
je 0xf942
movq (%r14), %rax
movq %rax, 0x3d722(%rip)     # 0x4d050
leaq 0x3cc67(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
je 0xfaf0
xorl %eax, %eax
jmp 0xf947
movl $0x80, %eax
addq %rbx, %rax
leaq 0x3d77f(%rip), %rcx     # 0x4d0d0
movq (%rcx), %r12
addq %r12, %rax
notq %r12
andq %rax, %r12
movq %r12, %rdi
callq 0x267bd
testq %rax, %rax
je 0xfa63
movq %rax, %r15
addq %r12, 0x3d6c8(%rip)     # 0x4d040
testq %r14, %r14
jne 0xf99b
movq %r15, %r14
subq $-0x80, %r15
addq $-0x80, %r12
subq $-0x80, 0x3d6a0(%rip)   # 0x4d030
addq $0x1000, 0x3d69d(%rip) # imm = 0x1000
pushq $0x1
popq %rax
lock
xaddq %rax, 0x3d6a1(%rip)     # 0x4d048
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 0xf9e5
leaq (%rbx,%r15), %rax
movq %rax, 0x8(%r14)
movq %r12, 0x10(%r14)
leaq 0x3d64d(%rip), %rdi     # 0x4d028
movq %r14, %rsi
callq 0x2c8a2
jmp 0xfa06
leaq 0x3cbb0(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
je 0xfae0
movq 0x3d654(%rip), %rax     # 0x4d050
movq %rax, (%r14)
movq %r14, 0x3d64a(%rip)     # 0x4d050
movq %r15, %rax
addq %rbx, 0x3d620(%rip)     # 0x4d030
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, 0x3d600(%rip)     # 0x4d038
leaq 0x3cb5d(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
je 0xfad0
leaq 0x3d589(%rip), %rdi     # 0x4cfd8
callq 0xb380
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
testq %r14, %r14
je 0xfa89
leaq 0x3cb2d(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
je 0xfb00
movq 0x3d5d1(%rip), %rax     # 0x4d050
movq %rax, (%r14)
movq %r14, 0x3d5c7(%rip)     # 0x4d050
xorl %r15d, %r15d
jmp 0xfa48
movabsq $0x7000000000000000, %rax # imm = 0x7000000000000000
cmpq %rax, %rbx
ja 0xfb10
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 0xf8c1
movq %r15, %rdi
movq %rbx, %rsi
callq 0x37704
jmp 0xfa48
pushq $0x70
popq %rsi
movq %r14, %rdi
callq 0x376c2
jmp 0xf9f5
pushq $0x70
popq %rsi
movq %r14, %rdi
callq 0x376c2
jmp 0xf93e
pushq $0x70
popq %rsi
movq %r14, %rdi
callq 0x376c2
jmp 0xfa78
xorl %eax, %eax
jmp 0xf8c1