// File: /workspace/github_c_makefile_star2_O2/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/chunk.c
// Function: chunk_record
static void
chunk_record(tsdn_t *tsdn, arena_t *arena, chunk_hooks_t *chunk_hooks,
    extent_tree_t *chunks_szsnad, extent_tree_t *chunks_ad, bool cache,
    void *chunk, size_t size, size_t sn, 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(tsdn, &arena->chunks_mtx);
	chunk_hooks_assure_initialized_locked(tsdn, arena, chunk_hooks);
	extent_node_init(&key, arena, (void *)((uintptr_t)chunk + size), 0, 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_szsnad.
		 */
		extent_tree_szsnad_remove(chunks_szsnad, 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));
		if (sn < extent_node_sn_get(node))
			extent_node_sn_set(node, sn);
		extent_node_zeroed_set(node, extent_node_zeroed_get(node) &&
		    !unzeroed);
		extent_tree_szsnad_insert(chunks_szsnad, node);
		arena_chunk_cache_maybe_insert(arena, node, cache);
	} else {
		/* Coalescing forward failed, so insert a new node. */
		node = arena_node_alloc(tsdn, 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(tsdn, arena, chunk_hooks,
				    chunk, size, 0, size);
			}
			goto label_return;
		}
		extent_node_init(node, arena, chunk, size, sn, !unzeroed,
		    committed);
		extent_tree_ad_insert(chunks_ad, node);
		extent_tree_szsnad_insert(chunks_szsnad, 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_szsnad.
		 */
		extent_tree_szsnad_remove(chunks_szsnad, prev);
		extent_tree_ad_remove(chunks_ad, prev);
		arena_chunk_cache_maybe_remove(arena, prev, cache);
		extent_tree_szsnad_remove(chunks_szsnad, 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));
		if (extent_node_sn_get(prev) < extent_node_sn_get(node))
			extent_node_sn_set(node, extent_node_sn_get(prev));
		extent_node_zeroed_set(node, extent_node_zeroed_get(prev) &&
		    extent_node_zeroed_get(node));
		extent_tree_szsnad_insert(chunks_szsnad, node);
		arena_chunk_cache_maybe_insert(arena, node, cache);

		arena_node_dalloc(tsdn, arena, prev);
	}

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r9d, %r15d
movq %r8, %r13
movq %rcx, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %rbp
movb 0xe8(%rsp), %r12b
xorb $0x1, %r12b
leaq 0x269db(%rip), %rax     # 0x4859c
cmpb $0x1, (%rax)
je 0x21e99
orb %r15b, %r12b
leaq 0x8a0(%rbx), %rdi
movq %rdi, 0x20(%rsp)
callq 0xb5a0
movq %rbp, 0x18(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, 0x10(%rsp)
movq %r14, %rdx
callq 0x22086
movq 0xd8(%rsp), %rax
movq 0xd0(%rsp), %rcx
addq %rcx, %rax
leaq 0x28(%rsp), %rsi
movq %rbx, (%rsi)
movq %rax, 0x8(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsi)
andl $0x0, 0x1f(%rsi)
movq %r13, %rdi
callq 0x27754
movzbl %r15b, %r14d
testq %rax, %rax
je 0x21c75
movq %rax, %rbp
movq 0x8(%rax), %rdx
cmpq 0x30(%rsp), %rdx
jne 0x21c75
movb 0xf0(%rsp), %al
cmpb %al, 0x21(%rbp)
jne 0x21c75
movq 0x10(%rbp), %rcx
movl (%rbx), %r9d
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
xorl %r8d, %r8d
movq 0x10(%rsp), %rax
callq *0x30(%rax)
testb %al, %al
je 0x21e14
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x19e27
testq %rax, %rax
je 0x21dca
movq %rax, %rbp
xorb $0x1, %r12b
movq %rbx, (%rax)
movq 0xd0(%rsp), %rax
movq %rax, 0x8(%rbp)
movq 0xd8(%rsp), %rax
movq %rax, 0x10(%rbp)
movq 0xe0(%rsp), %rax
movq %rax, 0x18(%rbp)
movb %r12b, 0x20(%rbp)
movb 0xf0(%rsp), %al
movb %al, 0x21(%rbp)
movb $0x0, 0x22(%rbp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x277c3
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x26d07
movq %rbx, %rdi
movq %rbp, %rsi
movl %r14d, %r12d
movl %r14d, %edx
callq 0x19d44
movq %r13, %rdi
movq %rbp, %rsi
callq 0x276de
testq %rax, %rax
movq 0xd0(%rsp), %rdx
je 0x21df8
movq %rax, %r15
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
leaq (%rsi,%rdi), %rax
cmpq %rdx, %rax
jne 0x21df8
movb 0xf0(%rsp), %al
cmpb %al, 0x21(%r15)
jne 0x21df8
movl (%rbx), %r9d
movq 0xd8(%rsp), %rcx
xorl %r8d, %r8d
movq 0x10(%rsp), %rax
callq *0x30(%rax)
testb %al, %al
jne 0x21df8
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x26e79
movq %r13, %rdi
movq %r15, %rsi
callq 0x27923
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x19dc6
movq %r14, %rdi
movq %rbp, %rsi
callq 0x26e79
movq %rbx, %rdi
movq %rbp, %rsi
movl %r12d, %edx
callq 0x19dc6
movq 0x8(%r15), %rax
movq %rax, 0x8(%rbp)
movq 0x10(%r15), %rax
addq %rax, 0x10(%rbp)
movq 0x18(%r15), %rax
cmpq 0x18(%rbp), %rax
jae 0x21db7
movq %rax, 0x18(%rbp)
cmpb $0x1, 0x20(%r15)
jne 0x21e66
movb 0x20(%rbp), %al
jmp 0x21e68
testb %r15b, %r15b
movq 0xd0(%rsp), %rcx
je 0x21df8
movq 0xd8(%rsp), %r8
movq %r8, (%rsp)
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
xorl %r9d, %r9d
callq 0x21fcc
movq 0x20(%rsp), %rdi
callq 0xb380
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x26e79
movq %rbx, %rdi
movq %rbp, %rsi
movl %r14d, %edx
callq 0x19dc6
movq 0xd0(%rsp), %rax
movq %rax, 0x8(%rbp)
movq 0xd8(%rsp), %rax
addq %rax, 0x10(%rbp)
movq 0xe0(%rsp), %rax
cmpq %rax, 0x18(%rbp)
jbe 0x21e59
movq %rax, 0x18(%rbp)
xorb $0x1, %r12b
andb %r12b, 0x20(%rbp)
jmp 0x21cd6
xorl %eax, %eax
movb %al, 0x20(%rbp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x26d07
movq %rbx, %rdi
movq %rbp, %rsi
movl %r12d, %edx
callq 0x19d44
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x19ec9
jmp 0x21df8
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x32454
jmp 0x21bca