// File: /workspace/github_c_makefile_star2_O1/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 0x10194
leaq -0x1(%rbx), %rax
shrq $0x3, %rax
leaq 0x2be1d(%rip), %rcx     # 0x3bdc0
movzbl (%rcx,%rax), %eax
leaq 0x2b692(%rip), %rcx     # 0x3b640
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 0x3d007(%rip), %rdi     # 0x4cfd8
callq 0xb5a0
leaq 0x3d04b(%rip), %rdi     # 0x4d028
movq %r14, %rsi
callq 0x2c7b8
testq %rax, %rax
je 0x10001
movq %rax, %r14
leaq 0x3d034(%rip), %rdi     # 0x4d028
movq %rax, %rsi
callq 0x2cc3a
jmp 0x100e9
movq 0x3d048(%rip), %r14     # 0x4d050
testq %r14, %r14
je 0x10030
movq (%r14), %rax
movq %rax, 0x3d039(%rip)     # 0x4d050
leaq 0x3c57e(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
jne 0x10033
pushq $0x70
popq %rsi
movq %r14, %rdi
callq 0x37116
jmp 0x10033
xorl %r14d, %r14d
xorl %r12d, %r12d
testq %r14, %r14
sete %r12b
shll $0x7, %r12d
leaq 0x3d088(%rip), %rax     # 0x4d0d0
movq (%rax), %r15
leaq (%rbx,%r12), %rax
addq %r15, %rax
notq %r15
andq %rax, %r15
movq %r15, %rdi
callq 0x26819
testq %rax, %rax
je 0x100c0
addq %r15, 0x3cfd4(%rip)     # 0x4d040
testq %r14, %r14
jne 0x10096
movq %rax, %r14
addq %r12, 0x3cfb5(%rip)     # 0x4d030
addq %r12, %rax
subq %r12, %r15
addl $0xfff, %r12d           # imm = 0xFFF
andl $0x1000, %r12d          # imm = 0x1000
addq %r12, 0x3cfa2(%rip)     # 0x4d038
pushq $0x1
popq %rcx
lock
xaddq %rcx, 0x3cfa6(%rip)     # 0x4d048
andq $0x0, (%r14)
movq %rax, 0x8(%r14)
movq %r15, 0x10(%r14)
movq %rcx, 0x18(%r14)
movw $0x101, 0x20(%r14)      # imm = 0x101
movb $0x0, 0x22(%r14)
jmp 0x100e9
testq %r14, %r14
je 0x100e6
leaq 0x3c4d0(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
je 0x101f3
movq 0x3cf74(%rip), %rax     # 0x4d050
movq %rax, (%r14)
movq %r14, 0x3cf6a(%rip)     # 0x4d050
xorl %r14d, %r14d
testq %r14, %r14
je 0x10118
movq 0x8(%r14), %r15
movq 0x10(%r14), %rax
subq %rbx, %rax
jbe 0x1011d
leaq (%rbx,%r15), %rcx
movq %rcx, 0x8(%r14)
movq %rax, 0x10(%r14)
leaq 0x3cf1a(%rip), %rdi     # 0x4d028
movq %r14, %rsi
callq 0x2c9c1
jmp 0x1013e
xorl %r15d, %r15d
jmp 0x10179
leaq 0x3c478(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
je 0x101e3
movq 0x3cf1c(%rip), %rax     # 0x4d050
movq %rax, (%r14)
movq %r14, 0x3cf12(%rip)     # 0x4d050
addq %rbx, 0x3ceeb(%rip)     # 0x4d030
leaq (%r15,%rbx), %rax
addq $0xfff, %rax            # imm = 0xFFF
movq $-0x1000, %rcx          # imm = 0xF000
andq %rcx, %rax
leaq 0xfff(%r15), %rdx
andq %rcx, %rdx
subq %rdx, %rax
addq %rax, 0x3cecb(%rip)     # 0x4d038
leaq 0x3c428(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
je 0x101d6
leaq 0x3ce58(%rip), %rdi     # 0x4cfd8
callq 0xb380
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movabsq $0x7000000000000000, %rax # imm = 0x7000000000000000
cmpq %rax, %rbx
ja 0x10203
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 0xffb2
movq %r15, %rdi
movq %rbx, %rsi
callq 0x37158
jmp 0x10179
pushq $0x70
popq %rsi
movq %r14, %rdi
callq 0x37116
jmp 0x1012d
pushq $0x70
popq %rsi
movq %r14, %rdi
callq 0x37116
jmp 0x100d5
xorl %eax, %eax
jmp 0xffb2