// File: /workspace/github_c_makefile_star2_O2/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
movl %r8d, %r15d
movq %rcx, %r13
movq %rdx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
movq 0xd8(%rsp), %rbp
movq 0xd0(%rsp), %rdi
leaq (%rdi,%rbp), %rax
subq 0x2e612(%rip), %rax     # 0x576a8
cmpq $0x1000, %rax           # imm = 0x1000
ja 0x29465
decq %rax
shrq $0x3, %rax
leaq 0x19a50(%rip), %rcx     # 0x42b00
movzbl (%rcx,%rax), %eax
leaq 0x192c5(%rip), %rcx     # 0x42380
movq (%rcx,%rax,8), %rcx
movq 0x2e5ea(%rip), %r12     # 0x576b0
addq %r12, %rcx
notq %r12
andq %rcx, %r12
cmpq %rdi, %r12
jb 0x29216
leaq 0x3c0(%rbx), %rdi
movq %rdi, 0x28(%rsp)
callq 0x106d0
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x29a2f
testq %r14, %r14
movq %r13, 0x20(%rsp)
leaq 0x30(%rsp), %rsi
je 0x29140
movq %rbx, (%rsi)
movq %r14, 0x8(%rsi)
movq %r12, 0x10(%rsi)
andw $0x0, 0x18(%rsi)
movb $0x0, 0x1a(%rsi)
movq %r13, %rdi
callq 0x2f43d
testq %rax, %rax
je 0x2920c
movq %rax, %r14
movq 0x10(%rax), %r13
cmpq 0xd0(%rsp), %r13
jae 0x2916f
jmp 0x2920c
movq %rbx, (%rsi)
andq $0x0, 0x8(%rsi)
movq %r12, 0x10(%rsi)
andw $0x0, 0x18(%rsi)
movb $0x0, 0x1a(%rsi)
movq 0x10(%rsp), %rdi
callq 0x2e977
testq %rax, %rax
je 0x2920c
movq %rax, %r14
movq 0x10(%rax), %r13
movq 0xe0(%rsp), %rcx
movq 0x8(%r14), %rdi
leaq (%rdi,%rbp), %r12
decq %r12
negq %rbp
movb 0x18(%r14), %al
movb %al, 0xa(%rsp)
cmpb $0x1, %al
jne 0x29194
movb $0x1, (%rcx)
andq %rbp, %r12
movb 0x19(%r14), %al
movb %al, 0xb(%rsp)
cmpb $0x1, %al
jne 0x291ae
movq 0xe8(%rsp), %rax
movb $0x1, (%rax)
movq %r12, %rbp
movzbl %r15b, %r15d
subq %rdi, %rbp
movl %r15d, 0xc(%rsp)
jne 0x291ec
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x2eb97
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x2f659
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x22142
jmp 0x2928c
movl (%rbx), %r9d
movq %r13, %rsi
movq %rbp, %rdx
movq 0xd0(%rsp), %rcx
xorl %r8d, %r8d
movq 0x18(%rsp), %rax
callq *0x28(%rax)
testb %al, %al
je 0x2922e
movq 0x28(%rsp), %rdi
callq 0x10440
xorl %r12d, %r12d
movq %r12, %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 0x2eb97
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2f659
movq %rbx, %rdi
movq %r14, %rsi
movl 0xc(%rsp), %edx
callq 0x22142
movq %rbp, 0x10(%r14)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x2ea29
movq %r15, %rdi
movl 0xc(%rsp), %r15d
movq %r14, %rsi
callq 0x2f4ff
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x220c0
xorl %r14d, %r14d
subq %rbp, %r13
movb 0xf0(%rsp), %bpl
movq 0xd0(%rsp), %rdx
cmpq %rdx, %r13
jne 0x292b3
movq 0x20(%rsp), %r15
movb 0xa(%rsp), %r13b
jmp 0x2936b
movq %r13, %r15
subq %rdx, %r15
movl (%rbx), %r9d
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rcx
xorl %r8d, %r8d
movq 0x18(%rsp), %rax
callq *0x28(%rax)
testb %al, %al
je 0x292f7
testq %r14, %r14
sete %al
xorb $0x1, %bpl
orb %al, %bpl
jne 0x2941f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22230
jmp 0x2941f
testq %r14, %r14
jne 0x29310
movq %rbx, %rdi
callq 0x221a3
movq %rax, %r14
testq %rax, %rax
je 0x2941f
movq 0xd0(%rsp), %rax
addq %r12, %rax
movq %rbx, (%r14)
movq %rax, 0x8(%r14)
movq %r15, 0x10(%r14)
movb 0xa(%rsp), %r13b
movb %r13b, 0x18(%r14)
movb 0xb(%rsp), %al
movb %al, 0x19(%r14)
movb $0x0, 0x1a(%r14)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x2ea29
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2f4ff
movq %rbx, %rdi
movq %r14, %rsi
movl 0xc(%rsp), %edx
callq 0x220c0
xorl %r14d, %r14d
cmpb $0x0, 0xb(%rsp)
jne 0x293ca
movl (%rbx), %r8d
movq %r12, %rdi
movq 0xd0(%rsp), %rcx
movq %rcx, %rsi
xorl %edx, %edx
movq 0x18(%rsp), %rax
callq *0x10(%rax)
testb %al, %al
je 0x293ca
movq 0x28(%rsp), %rdi
callq 0x10440
subq $0x8, %rsp
movzbl %r13b, %eax
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movl 0x14(%rsp), %r8d
movq %r12, %r9
pushq $0x0
pushq %rax
pushq 0xe8(%rsp)
jmp 0x29457
movq 0x28(%rsp), %rdi
callq 0x10440
testq %r14, %r14
sete %al
xorb $0x1, %bpl
orb %al, %bpl
jne 0x293ee
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22230
testb %r13b, %r13b
jne 0x29219
movq 0xe0(%rsp), %rax
cmpb $0x0, (%rax)
je 0x29219
movq %r12, %rdi
xorl %esi, %esi
movq 0xd0(%rsp), %rdx
callq 0x10270
jmp 0x29219
movq 0x28(%rsp), %rdi
callq 0x10440
subq $0x8, %rsp
movzbl 0x13(%rsp), %eax
movzbl 0x12(%rsp), %r10d
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rcx
movl 0x14(%rsp), %r8d
movq %r12, %r9
pushq %rax
pushq %r10
pushq %r13
callq 0x2956d
addq $0x20, %rsp
jmp 0x29216
testq %rax, %rax
js 0x2949b
leaq -0x1(,%rax,2), %rcx
bsrq %rcx, %rdx
leal -0x3(%rdx), %ecx
pushq $-0x1
popq %rsi
shlq %cl, %rsi
cmpq $0x6, %rdx
notq %rsi
pushq $0x7
popq %rcx
cmovaeq %rsi, %rcx
addq %rcx, %rax
notq %rcx
andq %rax, %rcx
jmp 0x290bf
movq %rax, %rcx
btrq $0x3f, %rcx
cmpq $0x1, %rcx
pushq $0x40
popq %rdx
sbbq $0x0, %rdx
jmp 0x29476