// File: /workspace/github_c_makefile_star2_O3/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, %ebp
movq %r8, %r12
movq %rcx, 0x8(%rsp)
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, 0x18(%rsp)
movq 0xd8(%rsp), %r15
movb 0xe8(%rsp), %r14b
leaq 0x2555a(%rip), %rax     # 0x4c59c
cmpb $0x1, (%rax)
je 0x27361
xorb $0x1, %r14b
leaq 0x8a0(%rbx), %rdi
movq %rdi, 0x20(%rsp)
callq 0xb5a0
leaq 0x15a31(%rip), %rsi     # 0x3ca98
movl $0x38, %edx
movq %r13, %rdi
callq 0xb3c0
testl %eax, %eax
jne 0x270a7
movups 0x948(%rbx), %xmm0
movups 0x958(%rbx), %xmm1
movups 0x968(%rbx), %xmm2
movq 0x978(%rbx), %rax
movq %rax, 0x30(%r13)
movups %xmm2, 0x20(%r13)
movups %xmm1, 0x10(%r13)
movups %xmm0, (%r13)
orb %bpl, %r14b
movq 0xd0(%rsp), %rax
addq %r15, %rax
leaq 0x28(%rsp), %rsi
movq %rbx, (%rsi)
movq %rax, 0x8(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsi)
movl $0x0, 0x1f(%rsi)
movq %r12, %rdi
callq 0x2d764
testq %rax, %rax
je 0x2711d
movq %rax, %r15
movq 0x8(%rax), %rdx
cmpq 0x30(%rsp), %rdx
jne 0x2711d
movb 0xf0(%rsp), %al
cmpb %al, 0x21(%r15)
jne 0x2711d
movq 0x10(%r15), %rcx
movl (%rbx), %r9d
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
xorl %r8d, %r8d
callq *0x30(%r13)
testb %al, %al
je 0x272be
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x218c8
testq %rax, %rax
je 0x27276
movq %rax, %r15
xorb $0x1, %r14b
movq %rbx, (%rax)
movq 0xd0(%rsp), %rax
movq %rax, 0x8(%r15)
movq 0xd8(%rsp), %rax
movq %rax, 0x10(%r15)
movq 0xe0(%rsp), %rax
movq %rax, 0x18(%r15)
movb %r14b, 0x20(%r15)
movb 0xf0(%rsp), %al
movb %al, 0x21(%r15)
movb $0x0, 0x22(%r15)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2d7e4
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x2c8a2
movzbl %bpl, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21820
movq %r12, %rdi
movq %r15, %rsi
callq 0x2d6e5
testq %rax, %rax
je 0x272a2
movq %rax, %r14
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
leaq (%rsi,%rdi), %rax
cmpq 0xd0(%rsp), %rax
jne 0x272a2
movb 0xf0(%rsp), %al
cmpb %al, 0x21(%r14)
jne 0x272a2
movl (%rbx), %r9d
movq 0xd0(%rsp), %rdx
movq 0xd8(%rsp), %rcx
xorl %r8d, %r8d
callq *0x30(%r13)
testb %al, %al
jne 0x272a2
movq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x2cb18
movq %r12, %rdi
movq %r14, %rsi
callq 0x2d955
movzbl %bpl, %ebp
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x21881
movq %r13, %rdi
movq %r15, %rsi
callq 0x2cb18
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x21881
movq 0x8(%r14), %rax
movq %rax, 0x8(%r15)
movq 0x10(%r14), %rax
addq %rax, 0x10(%r15)
movq 0x18(%r14), %rax
cmpq 0x18(%r15), %rax
jae 0x27262
movq %rax, 0x18(%r15)
cmpb $0x1, 0x20(%r14)
jne 0x2732c
movb 0x20(%r15), %al
jmp 0x2732e
testb %bpl, %bpl
je 0x272a2
movq %rbx, %rdi
movq %r13, %rsi
callq 0x26e28
movl (%rbx), %r8d
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rcx
movq %rcx, %rsi
xorl %edx, %edx
callq *0x20(%r13)
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 %r15, %rsi
callq 0x2cb18
movzbl %bpl, %edx
movq %rbx, %rdi
movq %r15, %rsi
movl %edx, 0x14(%rsp)
callq 0x21881
movq 0xd0(%rsp), %rax
movq %rax, 0x8(%r15)
movq 0xd8(%rsp), %rax
addq %rax, 0x10(%r15)
movq 0xe0(%rsp), %rax
cmpq %rax, 0x18(%r15)
jbe 0x27308
movq %rax, 0x18(%r15)
xorb $0x1, %r14b
andb %r14b, 0x20(%r15)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x2c8a2
movq %rbx, %rdi
movq %r15, %rsi
movl 0x14(%rsp), %edx
jmp 0x27197
xorl %eax, %eax
movb %al, 0x20(%r15)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x2c8a2
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x21820
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2196f
jmp 0x272a2
movq 0xd0(%rsp), %rdi
movq %r15, %rsi
callq 0x37680
jmp 0x2704b