// File: /workspace/github_c_makefile_star2_O2/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/chunk.c
// Function: chunk_recycle
static void *
chunk_recycle(tsdn_t *tsdn, arena_t *arena, chunk_hooks_t *chunk_hooks,
    extent_tree_t *chunks_szsnad, extent_tree_t *chunks_ad, bool cache,
    void *new_addr, size_t size, size_t alignment, size_t *sn, bool *zero,
    bool *commit, bool dalloc_node)
{
	void *ret;
	extent_node_t *node;
	size_t alloc_size, leadsize, trailsize;
	bool zeroed, committed;

	assert(CHUNK_CEILING(size) == size);
	assert(alignment > 0);
	assert(new_addr == NULL || alignment == chunksize);
	assert(CHUNK_ADDR2BASE(new_addr) == new_addr);
	/*
	 * Cached chunks use the node linkage embedded in their headers, in
	 * which case dalloc_node is true, and new_addr is non-NULL because
	 * we're operating on a specific chunk.
	 */
	assert(dalloc_node || new_addr != NULL);

	alloc_size = size + CHUNK_CEILING(alignment) - chunksize;
	/* Beware size_t wrap-around. */
	if (alloc_size < size)
		return (NULL);
	malloc_mutex_lock(tsdn, &arena->chunks_mtx);
	chunk_hooks_assure_initialized_locked(tsdn, arena, chunk_hooks);
	if (new_addr != NULL) {
		extent_node_t key;
		extent_node_init(&key, arena, new_addr, alloc_size, 0, false,
		    false);
		node = extent_tree_ad_search(chunks_ad, &key);
	} else {
		node = chunk_first_best_fit(arena, chunks_szsnad, alloc_size);
	}
	if (node == NULL || (new_addr != NULL && extent_node_size_get(node) <
	    size)) {
		malloc_mutex_unlock(tsdn, &arena->chunks_mtx);
		return (NULL);
	}
	leadsize = ALIGNMENT_CEILING((uintptr_t)extent_node_addr_get(node),
	    alignment) - (uintptr_t)extent_node_addr_get(node);
	assert(new_addr == NULL || leadsize == 0);
	assert(extent_node_size_get(node) >= leadsize + size);
	trailsize = extent_node_size_get(node) - leadsize - size;
	ret = (void *)((uintptr_t)extent_node_addr_get(node) + leadsize);
	*sn = extent_node_sn_get(node);
	zeroed = extent_node_zeroed_get(node);
	if (zeroed)
		*zero = true;
	committed = extent_node_committed_get(node);
	if (committed)
		*commit = true;
	/* Split the lead. */
	if (leadsize != 0 &&
	    chunk_hooks->split(extent_node_addr_get(node),
	    extent_node_size_get(node), leadsize, size, false, arena->ind)) {
		malloc_mutex_unlock(tsdn, &arena->chunks_mtx);
		return (NULL);
	}
	/* Remove node from the tree. */
	extent_tree_szsnad_remove(chunks_szsnad, node);
	extent_tree_ad_remove(chunks_ad, node);
	arena_chunk_cache_maybe_remove(arena, node, cache);
	if (leadsize != 0) {
		/* Insert the leading space as a smaller chunk. */
		extent_node_size_set(node, leadsize);
		extent_tree_szsnad_insert(chunks_szsnad, node);
		extent_tree_ad_insert(chunks_ad, node);
		arena_chunk_cache_maybe_insert(arena, node, cache);
		node = NULL;
	}
	if (trailsize != 0) {
		/* Split the trail. */
		if (chunk_hooks->split(ret, size + trailsize, size,
		    trailsize, false, arena->ind)) {
			if (dalloc_node && node != NULL)
				arena_node_dalloc(tsdn, arena, node);
			malloc_mutex_unlock(tsdn, &arena->chunks_mtx);
			chunk_record(tsdn, arena, chunk_hooks, chunks_szsnad,
			    chunks_ad, cache, ret, size + trailsize, *sn,
			    zeroed, committed);
			return (NULL);
		}
		/* Insert the trailing space as a smaller chunk. */
		if (node == NULL) {
			node = arena_node_alloc(tsdn, arena);
			if (node == NULL) {
				malloc_mutex_unlock(tsdn, &arena->chunks_mtx);
				chunk_record(tsdn, arena, chunk_hooks,
				    chunks_szsnad, chunks_ad, cache, ret, size
				    + trailsize, *sn, zeroed, committed);
				return (NULL);
			}
		}
		extent_node_init(node, arena, (void *)((uintptr_t)(ret) + size),
		    trailsize, *sn, zeroed, committed);
		extent_tree_szsnad_insert(chunks_szsnad, node);
		extent_tree_ad_insert(chunks_ad, node);
		arena_chunk_cache_maybe_insert(arena, node, cache);
		node = NULL;
	}
	if (!committed && chunk_hooks->commit(ret, size, 0, size, arena->ind)) {
		malloc_mutex_unlock(tsdn, &arena->chunks_mtx);
		chunk_record(tsdn, arena, chunk_hooks, chunks_szsnad, chunks_ad,
		    cache, ret, size, *sn, zeroed, committed);
		return (NULL);
	}
	malloc_mutex_unlock(tsdn, &arena->chunks_mtx);

	assert(dalloc_node || node != NULL);
	if (dalloc_node && node != NULL)
		arena_node_dalloc(tsdn, arena, node);
	if (*zero) {
		if (!zeroed)
			memset(ret, 0, size);
		else if (config_debug) {
			size_t i;
			size_t *p = (size_t *)(uintptr_t)ret;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r8, 0x10(%rsp)
movq %rsi, %r12
movq 0xf0(%rsp), %rbx
movq 0xe8(%rsp), %r8
movq 0x27bb5(%rip), %rax     # 0x490d0
leaq (%rax,%rbx), %rsi
notq %rax
andq %rsi, %rax
movq %r8, %r13
subq 0x27b99(%rip), %r13     # 0x490c8
addq %rax, %r13
cmpq %r8, %r13
jb 0x216c2
movl %r9d, 0x4(%rsp)
movq %rcx, 0x8(%rsp)
movq 0xe0(%rsp), %rbp
leaq 0x8a0(%r12), %rax
movq %rdi, %r14
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %rdx, %r15
callq 0xb5a0
movq %r14, 0x18(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, 0x20(%rsp)
movq %r15, %rdx
callq 0x22086
leaq 0x38(%rsp), %rsi
testq %rbp, %rbp
je 0x215cd
movq %r12, (%rsi)
movq %rbp, 0x8(%rsi)
movq %r13, 0x10(%rsi)
andq $0x0, 0x18(%rsi)
andl $0x0, 0x1f(%rsi)
movq 0x10(%rsp), %rdi
callq 0x27727
testq %rax, %rax
movq 0xe8(%rsp), %r14
je 0x216b8
movq %rax, %r13
movq %r12, %r15
movq 0x10(%rax), %rsi
cmpq %r14, %rsi
jae 0x21607
jmp 0x216b8
movq %r12, (%rsi)
andq $0x0, 0x8(%rsi)
movq %r13, 0x10(%rsi)
andq $0x0, 0x18(%rsi)
andl $0x0, 0x1f(%rsi)
movq 0x8(%rsp), %rdi
callq 0x26c7f
testq %rax, %rax
movq 0xe8(%rsp), %r14
je 0x216b8
movq %rax, %r13
movq %r12, %r15
movq 0x10(%rax), %rsi
movq 0x100(%rsp), %rdx
movq 0xf8(%rsp), %rcx
movq 0x8(%r13), %rdi
movq 0x18(%r13), %rax
leaq (%rbx,%rdi), %rbp
decq %rbp
negq %rbx
movq %rax, (%rcx)
movb 0x20(%r13), %al
movb %al, 0x2(%rsp)
cmpb $0x1, %al
jne 0x2163b
movb $0x1, (%rdx)
andq %rbx, %rbp
movb 0x21(%r13), %al
movb %al, 0x3(%rsp)
cmpb $0x1, %al
movl 0x4(%rsp), %ecx
jne 0x21659
movq 0x108(%rsp), %rax
movb $0x1, (%rax)
movq %rsi, 0x30(%rsp)
movq %rbp, %rbx
movzbl %cl, %r12d
subq %rdi, %rbx
jne 0x2169c
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x26e79
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x27923
movq %r15, %rdi
movq %r13, %rsi
movl %r12d, 0x4(%rsp)
movl %r12d, %edx
callq 0x19dc6
jmp 0x21735
movq 0x10(%r13), %rsi
movl (%r15), %r9d
movq %rbx, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
movq 0x20(%rsp), %rax
callq *0x28(%rax)
testb %al, %al
je 0x216d9
movq 0x28(%rsp), %rdi
callq 0xb380
xorl %ebp, %ebp
movq %rbp, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x26e79
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x27923
movq %r15, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x19dc6
movq %rbx, 0x10(%r13)
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x26d07
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x277c3
movq %r15, %rdi
movq %r13, %rsi
movl %r12d, 0x4(%rsp)
movl %r12d, %edx
callq 0x19d44
xorl %r13d, %r13d
movq 0x30(%rsp), %rsi
subq %rbx, %rsi
movb 0x110(%rsp), %r12b
cmpq %r14, %rsi
jne 0x21753
movb 0x3(%rsp), %bl
jmp 0x2181f
movq %rsi, %rbx
subq %r14, %rbx
movl (%r15), %r9d
movq %rbp, %rdi
movq %rsi, 0x30(%rsp)
movq %r14, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
movq 0x20(%rsp), %rax
callq *0x28(%rax)
testb %al, %al
je 0x217a1
testq %r13, %r13
sete %al
xorb $0x1, %r12b
orb %al, %r12b
jne 0x218ee
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x19ec9
jmp 0x218ee
testq %r13, %r13
jne 0x217bf
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x19e27
movq %rax, %r13
testq %rax, %rax
je 0x218ee
leaq (%r14,%rbp), %rax
movq 0xf8(%rsp), %rcx
movq (%rcx), %rcx
movq %r15, (%r13)
movq %rax, 0x8(%r13)
movq %rbx, 0x10(%r13)
movq %rcx, 0x18(%r13)
movb 0x2(%rsp), %al
movb %al, 0x20(%r13)
movb 0x3(%rsp), %bl
movb %bl, 0x21(%r13)
movb $0x0, 0x22(%r13)
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x26d07
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x277c3
movq %r15, %rdi
movq %r13, %rsi
movl 0x4(%rsp), %edx
callq 0x19d44
xorl %r13d, %r13d
testb %bl, %bl
jne 0x21880
movl (%r15), %r8d
movq %rbp, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r14, %rcx
movq 0x20(%rsp), %rax
callq *0x10(%rax)
testb %al, %al
je 0x21880
movq 0x28(%rsp), %rdi
callq 0xb380
subq $0x8, %rsp
movzbl 0xa(%rsp), %eax
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
movl 0xc(%rsp), %r9d
pushq $0x0
pushq %rax
movq 0x110(%rsp), %rax
pushq (%rax)
pushq %r14
jmp 0x21934
movq 0x28(%rsp), %rdi
callq 0xb380
testq %r13, %r13
sete %al
xorb $0x1, %r12b
orb %al, %r12b
jne 0x218a9
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x19ec9
movq 0x100(%rsp), %rax
cmpb $0x1, (%rax)
jne 0x216c4
cmpb $0x0, 0x2(%rsp)
jne 0x218ce
movq %rbp, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0xb230
leaq 0x26cc7(%rip), %rax     # 0x4859c
cmpb $0x1, (%rax)
jne 0x216c4
movq %rbp, %rdi
movq %r14, %rsi
callq 0x324d8
jmp 0x216c4
movq 0x28(%rsp), %rdi
callq 0xb380
subq $0x8, %rsp
movzbl 0xb(%rsp), %eax
movzbl 0xa(%rsp), %r10d
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
movl 0xc(%rsp), %r9d
pushq %rax
pushq %r10
movq 0x110(%rsp), %rax
pushq (%rax)
pushq 0x50(%rsp)
pushq %rbp
callq 0x21b89
addq $0x30, %rsp
jmp 0x216c2