// File: /workspace/github_c_makefile_star2_O3/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 %rdx, %r13
movq 0xf0(%rsp), %rbx
movq 0xe8(%rsp), %r15
movq 0x2680f(%rip), %rax     # 0x4d0d0
leaq (%rax,%rbx), %rdx
notq %rax
andq %rdx, %rax
movq %r15, %r12
subq 0x267f3(%rip), %r12     # 0x4d0c8
addq %rax, %r12
cmpq %r15, %r12
jb 0x26a81
movq %rsi, %r14
movl %r9d, 0x4(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movq 0xe0(%rsp), %rbp
leaq 0x8a0(%rsi), %rdi
movq %rdi, 0x20(%rsp)
callq 0xb5a0
leaq 0x16185(%rip), %rsi     # 0x3ca98
movl $0x38, %edx
movq %r13, %rdi
callq 0xb3c0
testl %eax, %eax
jne 0x26956
movups 0x948(%r14), %xmm0
movups 0x958(%r14), %xmm1
movups 0x968(%r14), %xmm2
movq 0x978(%r14), %rax
movq %rax, 0x30(%r13)
movups %xmm2, 0x20(%r13)
movups %xmm1, 0x10(%r13)
movups %xmm0, (%r13)
leaq 0x38(%rsp), %rsi
testq %rbp, %rbp
je 0x2699e
movq %r14, (%rsi)
movq %rbp, 0x8(%rsi)
movq %r12, 0x10(%rsi)
movq $0x0, 0x18(%rsi)
movl $0x0, 0x1f(%rsi)
movq 0x10(%rsp), %rdi
callq 0x2d732
testq %rax, %rax
je 0x26a77
movq %rax, %r12
movq 0x10(%rax), %rsi
cmpq %r15, %rsi
jae 0x269d0
jmp 0x26a77
movq %r14, (%rsi)
xorl %eax, %eax
movq %rax, 0x8(%rsi)
movq %r12, 0x10(%rsi)
movq %rax, 0x18(%rsi)
movl $0x0, 0x1f(%rsi)
movq 0x8(%rsp), %rdi
callq 0x2c64f
testq %rax, %rax
je 0x26a77
movq %rax, %r12
movq 0x10(%rax), %rsi
movq 0x100(%rsp), %rdx
movq 0xf8(%rsp), %rcx
movq 0x8(%r12), %rdi
movq 0x18(%r12), %rax
leaq (%rbx,%rdi), %rbp
decq %rbp
negq %rbx
movq %rax, (%rcx)
movb 0x20(%r12), %al
movb %al, 0x2(%rsp)
cmpb $0x1, %al
jne 0x26a07
movb $0x1, (%rdx)
andq %rbx, %rbp
movb 0x21(%r12), %al
movb %al, 0x3(%rsp)
cmpb $0x1, %al
jne 0x26a22
movq 0x108(%rsp), %rax
movb $0x1, (%rax)
movq %rsi, 0x28(%rsp)
movq %rbp, %rbx
subq %rdi, %rbx
jne 0x26a5e
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2cb18
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2d955
movzbl 0x4(%rsp), %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x21881
jmp 0x26af7
movq 0x10(%r12), %rsi
movl (%r14), %r9d
movq %rbx, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq *0x28(%r13)
testb %al, %al
je 0x26a98
movq 0x20(%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 %r12, %rsi
callq 0x2cb18
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2d955
movzbl 0x4(%rsp), %edx
movl %edx, 0x34(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x21881
movq %rbx, 0x10(%r12)
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2c8a2
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2d7e4
movq %r14, %rdi
movq %r12, %rsi
movl 0x34(%rsp), %edx
callq 0x21820
xorl %r12d, %r12d
movq 0x28(%rsp), %rsi
subq %rbx, %rsi
cmpq %r15, %rsi
jne 0x26b0d
movb 0x3(%rsp), %bl
jmp 0x26be1
movq %rsi, %rbx
subq %r15, %rbx
movl (%r14), %r9d
movq %rbp, %rdi
movq %rsi, 0x28(%rsp)
movq %r15, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq *0x28(%r13)
testb %al, %al
je 0x26b5c
testq %r12, %r12
sete %al
movb 0x110(%rsp), %cl
xorb $0x1, %cl
orb %al, %cl
jne 0x26cb0
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2196f
jmp 0x26cb0
testq %r12, %r12
jne 0x26b7a
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x218c8
movq %rax, %r12
testq %rax, %rax
je 0x26cb0
leaq (%r15,%rbp), %rax
movq 0xf8(%rsp), %rcx
movq (%rcx), %rcx
movq %r14, (%r12)
movq %rax, 0x8(%r12)
movq %rbx, 0x10(%r12)
movq %rcx, 0x18(%r12)
movb 0x2(%rsp), %al
movb %al, 0x20(%r12)
movb 0x3(%rsp), %bl
movb %bl, 0x21(%r12)
movb $0x0, 0x22(%r12)
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2c8a2
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2d7e4
movzbl 0x4(%rsp), %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x21820
xorl %r12d, %r12d
testb %bl, %bl
jne 0x26c3d
movl (%r14), %r8d
movq %rbp, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq *0x10(%r13)
testb %al, %al
je 0x26c3d
movq 0x20(%rsp), %rdi
callq 0xb380
subq $0x8, %rsp
movzbl 0xa(%rsp), %eax
movzbl 0xc(%rsp), %r9d
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
pushq $0x0
pushq %rax
movq 0x110(%rsp), %rax
pushq (%rax)
pushq %r15
jmp 0x26cf5
movq 0x20(%rsp), %rdi
callq 0xb380
testq %r12, %r12
sete %al
movb 0x110(%rsp), %cl
xorb $0x1, %cl
orb %al, %cl
jne 0x26c6b
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2196f
movq 0x100(%rsp), %rax
cmpb $0x1, (%rax)
jne 0x26a83
cmpb $0x0, 0x2(%rsp)
jne 0x26c90
movq %rbp, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0xb230
leaq 0x25905(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
jne 0x26a83
movq %rbp, %rdi
movq %r15, %rsi
callq 0x37704
jmp 0x26a83
movq 0x20(%rsp), %rdi
callq 0xb380
subq $0x8, %rsp
movzbl 0xb(%rsp), %eax
movzbl 0xa(%rsp), %r10d
movzbl 0xc(%rsp), %r9d
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
pushq %rax
pushq %r10
movq 0x110(%rsp), %rax
pushq (%rax)
pushq 0x48(%rsp)
pushq %rbp
callq 0x27004
addq $0x30, %rsp
jmp 0x26a81