// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/deps/jemalloc/src/chunk.c
// Function: chunk_record
static void
chunk_record(arena_t *arena, chunk_hooks_t *chunk_hooks,
    extent_tree_t *chunks_szad, extent_tree_t *chunks_ad, bool cache,
    void *chunk, size_t size, bool zeroed, bool committed)
{
	bool unzeroed;
	extent_node_t *node, *prev;
	extent_node_t key;

	assert(!cache || !zeroed);
	unzeroed = cache || !zeroed;
	JEMALLOC_VALGRIND_MAKE_MEM_NOACCESS(chunk, size);

	malloc_mutex_lock(&arena->chunks_mtx);
	chunk_hooks_assure_initialized_locked(arena, chunk_hooks);
	extent_node_init(&key, arena, (void *)((uintptr_t)chunk + size), 0,
	    false, false);
	node = extent_tree_ad_nsearch(chunks_ad, &key);
	/* Try to coalesce forward. */
	if (node != NULL && extent_node_addr_get(node) ==
	    extent_node_addr_get(&key) && extent_node_committed_get(node) ==
	    committed && !chunk_hooks->merge(chunk, size,
	    extent_node_addr_get(node), extent_node_size_get(node), false,
	    arena->ind)) {
		/*
		 * Coalesce chunk with the following address range.  This does
		 * not change the position within chunks_ad, so only
		 * remove/insert from/into chunks_szad.
		 */
		extent_tree_szad_remove(chunks_szad, node);
		arena_chunk_cache_maybe_remove(arena, node, cache);
		extent_node_addr_set(node, chunk);
		extent_node_size_set(node, size + extent_node_size_get(node));
		extent_node_zeroed_set(node, extent_node_zeroed_get(node) &&
		    !unzeroed);
		extent_tree_szad_insert(chunks_szad, node);
		arena_chunk_cache_maybe_insert(arena, node, cache);
	} else {
		/* Coalescing forward failed, so insert a new node. */
		node = arena_node_alloc(arena);
		if (node == NULL) {
			/*
			 * Node allocation failed, which is an exceedingly
			 * unlikely failure.  Leak chunk after making sure its
			 * pages have already been purged, so that this is only
			 * a virtual memory leak.
			 */
			if (cache) {
				chunk_purge_wrapper(arena, chunk_hooks, chunk,
				    size, 0, size);
			}
			goto label_return;
		}
		extent_node_init(node, arena, chunk, size, !unzeroed,
		    committed);
		extent_tree_ad_insert(chunks_ad, node);
		extent_tree_szad_insert(chunks_szad, node);
		arena_chunk_cache_maybe_insert(arena, node, cache);
	}

	/* Try to coalesce backward. */
	prev = extent_tree_ad_prev(chunks_ad, node);
	if (prev != NULL && (void *)((uintptr_t)extent_node_addr_get(prev) +
	    extent_node_size_get(prev)) == chunk &&
	    extent_node_committed_get(prev) == committed &&
	    !chunk_hooks->merge(extent_node_addr_get(prev),
	    extent_node_size_get(prev), chunk, size, false, arena->ind)) {
		/*
		 * Coalesce chunk with the previous address range.  This does
		 * not change the position within chunks_ad, so only
		 * remove/insert node from/into chunks_szad.
		 */
		extent_tree_szad_remove(chunks_szad, prev);
		extent_tree_ad_remove(chunks_ad, prev);
		arena_chunk_cache_maybe_remove(arena, prev, cache);
		extent_tree_szad_remove(chunks_szad, node);
		arena_chunk_cache_maybe_remove(arena, node, cache);
		extent_node_addr_set(node, extent_node_addr_get(prev));
		extent_node_size_set(node, extent_node_size_get(prev) +
		    extent_node_size_get(node));
		extent_node_zeroed_set(node, extent_node_zeroed_get(prev) &&
		    extent_node_zeroed_get(node));
		extent_tree_szad_insert(chunks_szad, node);
		arena_chunk_cache_maybe_insert(arena, node, cache);

		arena_node_dalloc(arena, prev);
	}

label_return:
	malloc_mutex_unlock(&arena->chunks_mtx);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r15
movl %r8d, %r14d
movq %rcx, %r12
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movb 0xc8(%rsp), %bpl
xorb $0x1, %bpl
leaq 0x2d0df(%rip), %rax     # 0x56684
cmpb $0x1, (%rax)
je 0x29825
orb %r14b, %bpl
leaq 0x3c0(%rbx), %rdi
movq %rdi, 0x18(%rsp)
callq 0x106d0
movq %rbx, %rdi
movq %r13, 0x8(%rsp)
movq %r13, %rsi
callq 0x29a2f
movq 0xc0(%rsp), %rax
addq %r15, %rax
leaq 0x20(%rsp), %rsi
movq %rbx, (%rsi)
movq %rax, 0x8(%rsi)
andq $0x0, 0x10(%rsi)
andl $0x0, 0x17(%rsi)
movq %r12, %rdi
callq 0x2f470
movq %rax, %r13
movzbl %r14b, %eax
movl %eax, 0x4(%rsp)
testq %r13, %r13
je 0x29647
movq 0x8(%r13), %rdx
cmpq 0x28(%rsp), %rdx
jne 0x29647
movb 0xd0(%rsp), %al
cmpb %al, 0x19(%r13)
jne 0x29647
movq 0x10(%r13), %rcx
movl (%rbx), %r9d
movq %r15, %rdi
movq 0xc0(%rsp), %rsi
xorl %r8d, %r8d
movq 0x8(%rsp), %rax
callq *0x30(%rax)
testb %al, %al
je 0x297b3
movq %rbx, %rdi
callq 0x221a3
testq %rax, %rax
je 0x29774
movq %rax, %r13
xorb $0x1, %bpl
movq %rbx, (%rax)
movq %r15, 0x8(%rax)
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%r13)
movb %bpl, 0x18(%r13)
movb 0xd0(%rsp), %al
movb %al, 0x19(%r13)
movb $0x0, 0x1a(%r13)
movq %r12, %rdi
movq %r13, %rsi
callq 0x2f4ff
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2ea29
movq %rbx, %rdi
movq %r13, %rsi
movl 0x4(%rsp), %edx
callq 0x220c0
movq %r12, %rdi
movq %r13, %rsi
callq 0x2f3e5
testq %rax, %rax
je 0x29797
movq %rax, %r14
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
leaq (%rsi,%rdi), %rax
cmpq %r15, %rax
jne 0x29797
movb 0xd0(%rsp), %al
cmpb %al, 0x19(%r14)
jne 0x29797
movl (%rbx), %r9d
movq %r15, %rdx
movq 0xc0(%rsp), %rcx
xorl %r8d, %r8d
movq 0x8(%rsp), %rax
callq *0x30(%rax)
testb %al, %al
jne 0x29797
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2eb97
movq %r12, %rdi
movq %r14, %rsi
callq 0x2f659
movq %rbx, %rdi
movq %r14, %rsi
movl 0x4(%rsp), %r15d
movl %r15d, %edx
callq 0x22142
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2eb97
movq %rbx, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x22142
movq 0x8(%r14), %rax
movq %rax, 0x8(%r13)
movq 0x10(%r14), %rax
addq %rax, 0x10(%r13)
cmpb $0x1, 0x18(%r14)
jne 0x297f5
movb 0x18(%r13), %al
jmp 0x297f7
testb %r14b, %r14b
je 0x29797
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
movq 0xc0(%rsp), %rcx
xorl %r8d, %r8d
movq %rcx, %r9
callq 0x29964
movq 0x18(%rsp), %rdi
callq 0x10440
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x2eb97
movq %rbx, %rdi
movq %r13, %rsi
movl 0x4(%rsp), %edx
callq 0x22142
movq %r15, 0x8(%r13)
movq 0xc0(%rsp), %rax
addq %rax, 0x10(%r13)
xorb $0x1, %bpl
andb %bpl, 0x18(%r13)
movq %r14, %rbp
movq %r14, %rdi
jmp 0x29699
xorl %eax, %eax
movb %al, 0x18(%r13)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2ea29
movq %rbx, %rdi
movq %r13, %rsi
movl 0x4(%rsp), %edx
callq 0x220c0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22230
jmp 0x29797
movq %r15, %rdi
movq 0xc0(%rsp), %rsi
callq 0x38f28
jmp 0x295ae