// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/deps/jemalloc/src/base.c
// Function: je_base_alloc
void *
base_alloc(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, false, false);
	malloc_mutex_lock(&base_mtx);
	node = extent_tree_szad_nsearch(&base_avail_szad, &key);
	if (node != NULL) {
		/* Use existing space. */
		extent_tree_szad_remove(&base_avail_szad, node);
	} else {
		/* Try to allocate more space. */
		node = base_chunk_alloc(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_szad_insert(&base_avail_szad, node);
	} else
		base_node_dalloc(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(&base_mtx);
	return (ret);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x68, %rsp
addq $0x3f, %rdi
movq %rdi, %rbx
andq $-0x40, %rbx
cmpq $0x1000, %rbx           # imm = 0x1000
ja 0x2df73
leaq -0x1(%rbx), %rax
shrq $0x3, %rax
leaq 0x1a216(%rip), %rcx     # 0x47fc0
movzbl (%rcx,%rax), %eax
leaq 0x19a8b(%rip), %rcx     # 0x47840
movq (%rcx,%rax,8), %rax
xorps %xmm0, %xmm0
movq %rsp, %r14
movaps %xmm0, (%r14)
movq %rax, 0x10(%r14)
movw $0x0, 0x18(%r14)
movb $0x0, 0x1a(%r14)
leaq 0x2d7a6(%rip), %rdi     # 0x5b580
callq 0x106d0
leaq 0x2d7c2(%rip), %rdi     # 0x5b5a8
movq %r14, %rsi
callq 0x346f0
testq %rax, %rax
je 0x2de12
movq %rax, %r14
leaq 0x2d7ab(%rip), %rdi     # 0x5b5a8
movq %rax, %rsi
callq 0x34b6e
movq 0x8(%r14), %r15
movq 0x10(%r14), %r12
jmp 0x2deb0
movq 0x2d817(%rip), %r14     # 0x5b630
testq %r14, %r14
je 0x2de3c
movq (%r14), %rax
movq %rax, 0x2d808(%rip)     # 0x5b630
leaq 0x2c855(%rip), %rax     # 0x5a684
cmpb $0x1, (%rax)
je 0x2dfa8
xorl %eax, %eax
jmp 0x2de41
movl $0x80, %eax
addq %rbx, %rax
leaq 0x2d865(%rip), %rcx     # 0x5b6b0
movq (%rcx), %r12
addq %r12, %rax
notq %r12
andq %rax, %r12
movq %r12, %rdi
callq 0x2e5ac
testq %rax, %rax
je 0x2df4c
movq %rax, %r15
addq %r12, 0x2d7b6(%rip)     # 0x5b628
testq %r14, %r14
jne 0x2de95
movq %r15, %r14
subq $-0x80, %r15
addq $-0x80, %r12
subq $-0x80, 0x2d78e(%rip)   # 0x5b618
addq $0x1000, 0x2d78b(%rip) # imm = 0x1000
movq $0x0, (%r14)
movq %r15, 0x8(%r14)
movq %r12, 0x10(%r14)
movw $0x101, 0x18(%r14)      # imm = 0x101
movb $0x0, 0x1a(%r14)
subq %rbx, %r12
jbe 0x2ded2
leaq (%rbx,%r15), %rax
movq %rax, 0x8(%r14)
movq %r12, 0x10(%r14)
leaq 0x2d6e0(%rip), %rdi     # 0x5b5a8
movq %r14, %rsi
callq 0x3491e
jmp 0x2def3
leaq 0x2c7ab(%rip), %rax     # 0x5a684
cmpb $0x1, (%rax)
je 0x2df96
movq 0x2d747(%rip), %rax     # 0x5b630
movq %rax, (%r14)
movq %r14, 0x2d73d(%rip)     # 0x5b630
movq %r15, %rax
addq %rbx, 0x2d71b(%rip)     # 0x5b618
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, 0x2d6fb(%rip)     # 0x5b620
leaq 0x2c758(%rip), %rax     # 0x5a684
cmpb $0x1, (%rax)
je 0x2df89
leaq 0x2d648(%rip), %rdi     # 0x5b580
callq 0x10440
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
testq %r14, %r14
je 0x2df6e
leaq 0x2c72c(%rip), %rax     # 0x5a684
cmpb $0x1, (%rax)
je 0x2dfba
movq 0x2d6cc(%rip), %rax     # 0x5b630
movq %rax, (%r14)
movq %r14, 0x2d6c2(%rip)     # 0x5b630
xorl %r15d, %r15d
jmp 0x2df31
movq %rsp, %r14
movq %rbx, %rsi
movq %r14, %rdx
callq 0x122e9
movq (%r14), %rax
jmp 0x2ddb9
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3e7e8
jmp 0x2df31
movl $0x68, %esi
movq %r14, %rdi
callq 0x3e7a6
jmp 0x2dee2
movl $0x68, %esi
movq %r14, %rdi
callq 0x3e7a6
jmp 0x2de38
movl $0x68, %esi
movq %r14, %rdi
callq 0x3e7a6
jmp 0x2df5d