// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/deps/jemalloc/src/chunk.c
// Function: chunk_recycle
static void *
chunk_recycle(arena_t *arena, chunk_hooks_t *chunk_hooks,
    extent_tree_t *chunks_szad, extent_tree_t *chunks_ad, bool cache,
    void *new_addr, size_t size, size_t alignment, bool *zero, bool *commit,
    bool dalloc_node)
{
	void *ret;
	extent_node_t *node;
	size_t alloc_size, leadsize, trailsize;
	bool zeroed, committed;

	assert(new_addr == NULL || alignment == chunksize);
	/*
	 * 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 = CHUNK_CEILING(s2u(size + alignment - chunksize));
	/* Beware size_t wrap-around. */
	if (alloc_size < size)
		return (NULL);
	malloc_mutex_lock(&arena->chunks_mtx);
	chunk_hooks_assure_initialized_locked(arena, chunk_hooks);
	if (new_addr != NULL) {
		extent_node_t key;
		extent_node_init(&key, arena, new_addr, alloc_size, false,
		    false);
		node = extent_tree_ad_search(chunks_ad, &key);
	} else {
		node = chunk_first_best_fit(arena, chunks_szad, chunks_ad,
		    alloc_size);
	}
	if (node == NULL || (new_addr != NULL && extent_node_size_get(node) <
	    size)) {
		malloc_mutex_unlock(&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);
	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(&arena->chunks_mtx);
		return (NULL);
	}
	/* Remove node from the tree. */
	extent_tree_szad_remove(chunks_szad, 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_szad_insert(chunks_szad, 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(arena, node);
			malloc_mutex_unlock(&arena->chunks_mtx);
			chunk_record(arena, chunk_hooks, chunks_szad, chunks_ad,
			    cache, ret, size + trailsize, zeroed, committed);
			return (NULL);
		}
		/* Insert the trailing space as a smaller chunk. */
		if (node == NULL) {
			node = arena_node_alloc(arena);
			if (node == NULL) {
				malloc_mutex_unlock(&arena->chunks_mtx);
				chunk_record(arena, chunk_hooks, chunks_szad,
				    chunks_ad, cache, ret, size + trailsize,
				    zeroed, committed);
				return (NULL);
			}
		}
		extent_node_init(node, arena, (void *)((uintptr_t)(ret) + size),
		    trailsize, zeroed, committed);
		extent_tree_szad_insert(chunks_szad, 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(&arena->chunks_mtx);
		chunk_record(arena, chunk_hooks, chunks_szad, chunks_ad, cache,
		    ret, size, zeroed, committed);
		return (NULL);
	}
	malloc_mutex_unlock(&arena->chunks_mtx);

	assert(dalloc_node || node != NULL);
	if (dalloc_node && node != NULL)
		arena_node_dalloc(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;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, %r14
movq %rcx, %r12
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movq 0xd8(%rsp), %rbp
movq 0xd0(%rsp), %rdx
leaq (%rdx,%rbp), %rdi
subq 0x2d000(%rip), %rdi     # 0x5b6a8
cmpq $0x1000, %rdi           # imm = 0x1000
ja 0x2eaad
decq %rdi
shrq $0x3, %rdi
leaq 0x198fd(%rip), %rax     # 0x47fc0
movzbl (%rax,%rdi), %eax
leaq 0x19172(%rip), %rcx     # 0x47840
movq (%rcx,%rax,8), %rax
movq 0x2cfd7(%rip), %r15     # 0x5b6b0
addq %r15, %rax
notq %r15
andq %rax, %r15
cmpq %rdx, %r15
jb 0x2e865
movl %r8d, 0xc(%rsp)
leaq 0x3c0(%rbx), %rdi
movq %rdi, 0x20(%rsp)
callq 0x106d0
leaq 0x19d98(%rip), %rsi     # 0x484a0
movl $0x38, %edx
movq %r13, %rdi
callq 0x104a0
testl %eax, %eax
jne 0x2e748
movups 0x418(%rbx), %xmm0
movups 0x428(%rbx), %xmm1
movups 0x438(%rbx), %xmm2
movq 0x448(%rbx), %rax
movq %rax, 0x30(%r13)
movups %xmm2, 0x20(%r13)
movups %xmm1, 0x10(%r13)
movups %xmm0, (%r13)
testq %r14, %r14
movq %r12, 0x18(%rsp)
leaq 0x30(%rsp), %rsi
je 0x2e796
movq %rbx, (%rsi)
movq %r14, 0x8(%rsi)
movq %r15, 0x10(%rsi)
movw $0x0, 0x18(%rsi)
movb $0x0, 0x1a(%rsi)
movq %r12, %rdi
callq 0x35709
testq %rax, %rax
movq 0xd0(%rsp), %rcx
je 0x2e85b
movq %rax, %r14
movq 0x10(%rax), %r12
cmpq %rcx, %r12
jae 0x2e7d1
jmp 0x2e85b
movq %rbx, (%rsi)
movq $0x0, 0x8(%rsi)
movq %r15, 0x10(%rsi)
movw $0x0, 0x18(%rsi)
movb $0x0, 0x1a(%rsi)
movq 0x10(%rsp), %rdi
callq 0x346f0
testq %rax, %rax
movq 0xd0(%rsp), %rcx
je 0x2e85b
movq %rax, %r14
movq 0x10(%rax), %r12
movq 0xe0(%rsp), %rdx
movq 0x8(%r14), %rdi
leaq (%rdi,%rbp), %r15
decq %r15
negq %rbp
movb 0x18(%r14), %al
movb %al, 0xa(%rsp)
cmpb $0x1, %al
jne 0x2e7f6
movb $0x1, (%rdx)
andq %rbp, %r15
movb 0x19(%r14), %al
movb %al, 0xb(%rsp)
cmpb $0x1, %al
jne 0x2e810
movq 0xe8(%rsp), %rax
movb $0x1, (%rax)
movq %r15, %rbp
subq %rdi, %rbp
jne 0x2e847
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x34b6e
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x35949
movzbl 0xc(%rsp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x27085
jmp 0x2e8db
movl (%rbx), %r9d
movq %r12, %rsi
movq %rbp, %rdx
xorl %r8d, %r8d
callq *0x28(%r13)
testb %al, %al
je 0x2e87d
movq 0x20(%rsp), %rdi
callq 0x10440
xorl %r15d, %r15d
movq %r15, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x34b6e
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x35949
movzbl 0xc(%rsp), %edx
movl %edx, 0x2c(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x27085
movq %rbp, 0x10(%r14)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x3491e
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x357dd
movq %rbx, %rdi
movq %r14, %rsi
movl 0x2c(%rsp), %edx
callq 0x27024
xorl %r14d, %r14d
subq %rbp, %r12
movq 0xd0(%rsp), %rdx
cmpq %rdx, %r12
jne 0x2e8fa
movq 0x18(%rsp), %r12
movb 0xa(%rsp), %bpl
jmp 0x2e9b4
movq %r12, %rbp
subq %rdx, %rbp
movl (%rbx), %r9d
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rcx
xorl %r8d, %r8d
callq *0x28(%r13)
testb %al, %al
je 0x2e93f
testq %r14, %r14
sete %al
movb 0xf0(%rsp), %cl
xorb $0x1, %cl
orb %al, %cl
jne 0x2ea68
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2715e
jmp 0x2ea68
testq %r14, %r14
jne 0x2e958
movq %rbx, %rdi
callq 0x270cc
movq %rax, %r14
testq %rax, %rax
je 0x2ea68
movq 0xd0(%rsp), %rax
addq %r15, %rax
movq %rbx, (%r14)
movq %rax, 0x8(%r14)
movq %rbp, 0x10(%r14)
movb 0xa(%rsp), %bpl
movb %bpl, 0x18(%r14)
movb 0xb(%rsp), %al
movb %al, 0x19(%r14)
movb $0x0, 0x1a(%r14)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x3491e
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x357dd
movzbl 0xc(%rsp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x27024
xorl %r14d, %r14d
cmpb $0x0, 0xb(%rsp)
jne 0x2ea0e
movl (%rbx), %r8d
movq %r15, %rdi
movq 0xd0(%rsp), %rcx
movq %rcx, %rsi
xorl %edx, %edx
callq *0x10(%r13)
testb %al, %al
je 0x2ea0e
movq 0x20(%rsp), %rdi
callq 0x10440
subq $0x8, %rsp
movzbl %bpl, %eax
movzbl 0x14(%rsp), %r8d
movq %rbx, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rcx
movq %r15, %r9
pushq $0x0
pushq %rax
pushq 0xe8(%rsp)
jmp 0x2ea9f
movq 0x20(%rsp), %rdi
callq 0x10440
testq %r14, %r14
sete %al
movb 0xf0(%rsp), %cl
xorb $0x1, %cl
orb %al, %cl
jne 0x2ea37
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2715e
testb %bpl, %bpl
jne 0x2e868
movq 0xe0(%rsp), %rax
cmpb $0x0, (%rax)
je 0x2e868
movq %r15, %rdi
xorl %esi, %esi
movq 0xd0(%rsp), %rdx
callq 0x10270
jmp 0x2e868
movq 0x20(%rsp), %rdi
callq 0x10440
subq $0x8, %rsp
movzbl 0x13(%rsp), %eax
movzbl 0x12(%rsp), %r10d
movzbl 0x14(%rsp), %r8d
movq %rbx, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %r15, %r9
pushq %rax
pushq %r10
pushq %r12
callq 0x2ec26
addq $0x20, %rsp
jmp 0x2e865
leaq 0x30(%rsp), %rsi
movl %r8d, %r15d
callq 0x12338
movl %r15d, %r8d
movq 0xd0(%rsp), %rdx
leaq 0x30(%rsp), %rax
movq (%rax), %rax
jmp 0x2e6d2