// File: /workspace/github_c_makefile_star2_O1/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 0x267a3(%rip), %rax     # 0x4d0d0
leaq (%rax,%rbx), %rdx
notq %rax
andq %rdx, %rax
movq %r15, %r12
subq 0x26787(%rip), %r12     # 0x4d0c8
addq %rax, %r12
cmpq %r15, %r12
jb 0x26ae6
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 0x16059(%rip), %rsi     # 0x3c9d8
movl $0x38, %edx
movq %r13, %rdi
callq 0xb3c0
testl %eax, %eax
jne 0x269c2
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 0x269f2
movq %r14, (%rsi)
movq %rbp, 0x8(%rsi)
movq %r12, 0x10(%rsi)
movq $0x0, 0x18(%rsi)
movl $0x0, 0x1f(%rsi)
movq 0x10(%rsp), %rdi
callq 0x2d873
jmp 0x26a14
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 0x2c7b8
movq %rax, %r12
testq %rax, %rax
je 0x26adc
testq %rbp, %rbp
je 0x26a30
cmpq %r15, 0x10(%r12)
jb 0x26adc
movq 0x100(%rsp), %rdx
movq 0xf8(%rsp), %rcx
movq 0x8(%r12), %rdi
movq 0x10(%r12), %rsi
leaq (%rbx,%rdi), %rbp
decq %rbp
negq %rbx
movq 0x18(%r12), %rax
movq %rax, (%rcx)
movb 0x20(%r12), %al
movb %al, 0x2(%rsp)
cmpb $0x1, %al
jne 0x26a6c
movb $0x1, (%rdx)
andq %rbx, %rbp
movb 0x21(%r12), %al
movb %al, 0x3(%rsp)
cmpb $0x1, %al
jne 0x26a87
movq 0x108(%rsp), %rax
movb $0x1, (%rax)
movq %rsi, 0x28(%rsp)
movq %rbp, %rbx
subq %rdi, %rbx
jne 0x26ac3
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2cc3a
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2daa4
movzbl 0x4(%rsp), %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x219f5
jmp 0x26b5c
movq 0x10(%r12), %rsi
movl (%r14), %r9d
movq %rbx, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq *0x28(%r13)
testb %al, %al
je 0x26afd
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 0x2cc3a
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2daa4
movzbl 0x4(%rsp), %edx
movl %edx, 0x34(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x219f5
movq %rbx, 0x10(%r12)
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2c9c1
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2d932
movq %r14, %rdi
movq %r12, %rsi
movl 0x34(%rsp), %edx
callq 0x2198c
xorl %r12d, %r12d
movq 0x28(%rsp), %rsi
subq %rbx, %rsi
cmpq %r15, %rsi
jne 0x26b72
movb 0x3(%rsp), %bl
jmp 0x26c46
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 0x26bc1
testq %r12, %r12
sete %al
movb 0x110(%rsp), %cl
xorb $0x1, %cl
orb %al, %cl
jne 0x26d15
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x21b05
jmp 0x26d15
testq %r12, %r12
jne 0x26bdf
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x21a44
movq %rax, %r12
testq %rax, %rax
je 0x26d15
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 0x2c9c1
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2d932
movzbl 0x4(%rsp), %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2198c
xorl %r12d, %r12d
testb %bl, %bl
jne 0x26ca2
movl (%r14), %r8d
movq %rbp, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq *0x10(%r13)
testb %al, %al
je 0x26ca2
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 0x26d5a
movq 0x20(%rsp), %rdi
callq 0xb380
testq %r12, %r12
sete %al
movb 0x110(%rsp), %cl
xorb $0x1, %cl
orb %al, %cl
jne 0x26cd0
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x21b05
movq 0x100(%rsp), %rax
cmpb $0x1, (%rax)
jne 0x26ae8
cmpb $0x0, 0x2(%rsp)
jne 0x26cf5
movq %rbp, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0xb230
leaq 0x258a0(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
jne 0x26ae8
movq %rbp, %rdi
movq %r15, %rsi
callq 0x37158
jmp 0x26ae8
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 0x2707a
addq $0x30, %rsp
jmp 0x26ae6