// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/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, %rbp
movq %rcx, %r12
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movq 0xd8(%rsp), %r15
movq 0xd0(%rsp), %rdx
leaq (%r15,%rdx), %rdi
subq 0x43f3c(%rip), %rdi     # 0x84698
cmpq $0x1000, %rdi           # imm = 0x1000
ja 0x40b52
decq %rdi
shrq $0x3, %rdi
leaq 0x19089(%rip), %rax     # 0x59800
movzbl (%rax,%rdi), %eax
leaq 0x188fe(%rip), %rcx     # 0x59080
movq (%rcx,%rax,8), %rax
movq 0x43f13(%rip), %r14     # 0x846a0
addq %r14, %rax
notq %r14
andq %rax, %r14
cmpq %rdx, %r14
jb 0x4090b
movl %r8d, 0xc(%rsp)
leaq 0x3c0(%rbx), %rdi
movq %rdi, 0x20(%rsp)
callq 0x12960
leaq 0x194f4(%rip), %rsi     # 0x59cb0
movl $0x38, %edx
movq %r13, %rdi
callq 0x12620
testl %eax, %eax
jne 0x407fc
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)
leaq 0x30(%rsp), %rsi
testq %rbp, %rbp
je 0x40825
movq %rbx, (%rsi)
movq %rbp, 0x8(%rsi)
movq %r14, 0x10(%rsi)
movw $0x0, 0x18(%rsi)
movb $0x0, 0x1a(%rsi)
movq %r12, %rdi
callq 0x47697
jmp 0x40848
movq %rbx, (%rsi)
movq $0x0, 0x8(%rsi)
movq %r14, 0x10(%rsi)
movw $0x0, 0x18(%rsi)
movb $0x0, 0x1a(%rsi)
movq 0x10(%rsp), %rdi
callq 0x466ed
movq %rax, %r14
testq %rax, %rax
movq 0xd0(%rsp), %rcx
je 0x40901
testq %rbp, %rbp
je 0x4086b
cmpq %rcx, 0x10(%r14)
jb 0x40901
movq %r12, 0x18(%rsp)
movq 0xe0(%rsp), %rdx
movq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
leaq (%r15,%rdi), %r12
decq %r12
negq %r15
movb 0x18(%r14), %al
cmpb $0x1, %al
jne 0x40895
movb $0x1, (%rdx)
movb %al, 0xa(%rsp)
andq %r15, %r12
movb 0x19(%r14), %al
movb %al, 0xb(%rsp)
cmpb $0x1, %al
jne 0x408b3
movq 0xe8(%rsp), %rax
movb $0x1, (%rax)
movq %r12, %rbp
subq %rdi, %rbp
jne 0x408ed
movq %rsi, %r15
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x46b1f
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x478e9
movzbl 0xc(%rsp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x39b15
jmp 0x40981
movl (%rbx), %r9d
movq %rsi, %r15
movq %rbp, %rdx
xorl %r8d, %r8d
callq *0x28(%r13)
testb %al, %al
je 0x40923
movq 0x20(%rsp), %rdi
callq 0x125c0
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 0x46b1f
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x478e9
movzbl 0xc(%rsp), %edx
movl %edx, 0x28(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x39b15
movq %rbp, 0x10(%r14)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x468cb
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x4777e
movq %rbx, %rdi
movq %r14, %rsi
movl 0x28(%rsp), %edx
callq 0x39aac
xorl %r14d, %r14d
movq %r15, %rsi
subq %rbp, %rsi
movb 0xf0(%rsp), %r15b
movq 0xd0(%rsp), %rdx
cmpq %rdx, %rsi
jne 0x409a6
movb 0xa(%rsp), %bpl
jmp 0x40a5a
movq %rsi, %rbp
subq %rdx, %rbp
movl (%rbx), %r9d
movq %r12, %rdi
movq %rsi, 0x28(%rsp)
movq %rbp, %rcx
xorl %r8d, %r8d
callq *0x28(%r13)
testb %al, %al
je 0x409e8
testq %r14, %r14
sete %al
xorb $0x1, %r15b
orb %al, %r15b
jne 0x40b0b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x39c10
jmp 0x40b0b
testq %r14, %r14
jne 0x40a01
movq %rbx, %rdi
callq 0x39b64
movq %rax, %r14
testq %rax, %rax
je 0x40b0b
movq 0xd0(%rsp), %rax
addq %r12, %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 0x468cb
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x4777e
movzbl 0xc(%rsp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x39aac
xorl %r14d, %r14d
cmpb $0x0, 0xb(%rsp)
jne 0x40ab6
movl (%rbx), %r8d
movq %r12, %rdi
movq 0xd0(%rsp), %rcx
movq %rcx, %rsi
xorl %edx, %edx
callq *0x10(%r13)
testb %al, %al
je 0x40ab6
movq 0x20(%rsp), %rdi
callq 0x125c0
subq $0x8, %rsp
movzbl %bpl, %eax
movzbl 0x14(%rsp), %r8d
movq %rbx, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %r12, %r9
pushq $0x0
pushq %rax
pushq 0xe8(%rsp)
jmp 0x40b44
movq 0x20(%rsp), %rdi
callq 0x125c0
testq %r14, %r14
sete %al
xorb $0x1, %r15b
orb %al, %r15b
jne 0x40ada
movq %rbx, %rdi
movq %r14, %rsi
callq 0x39c10
testb %bpl, %bpl
jne 0x4090e
movq 0xe0(%rsp), %rax
cmpb $0x0, (%rax)
je 0x4090e
movq %r12, %rdi
xorl %esi, %esi
movq 0xd0(%rsp), %rdx
callq 0x12380
jmp 0x4090e
movq 0x20(%rsp), %rdi
callq 0x125c0
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 %r12, %r9
pushq %rax
pushq %r10
pushq 0x40(%rsp)
callq 0x40cce
addq $0x20, %rsp
jmp 0x4090b
leaq 0x30(%rsp), %rsi
movl %r8d, %r14d
callq 0x14b9b
movl %r14d, %r8d
movq 0xd0(%rsp), %rdx
leaq 0x30(%rsp), %rax
movq (%rax), %rax
jmp 0x40786