// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/chunk.c
// Function: chunk_record
static void
chunk_record(extent_tree_t *chunks_szad, extent_tree_t *chunks_ad, void *chunk,
    size_t size)
{
	bool unzeroed;
	extent_node_t *xnode, *node, *prev, key;

	unzeroed = pages_purge(chunk, size);

	/*
	 * Allocate a node before acquiring chunks_mtx even though it might not
	 * be needed, because base_node_alloc() may cause a new base chunk to
	 * be allocated, which could cause deadlock if chunks_mtx were already
	 * held.
	 */
	xnode = base_node_alloc();

	malloc_mutex_lock(&chunks_mtx);
	key.addr = (void *)((uintptr_t)chunk + size);
	node = extent_tree_ad_nsearch(chunks_ad, &key);
	/* Try to coalesce forward. */
	if (node != NULL && node->addr == key.addr) {
		/*
		 * 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);
		node->addr = chunk;
		node->size += size;
		node->zeroed = (node->zeroed && (unzeroed == false));
		extent_tree_szad_insert(chunks_szad, node);
		if (xnode != NULL)
			base_node_dealloc(xnode);
	} else {
		/* Coalescing forward failed, so insert a new node. */
		if (xnode == NULL) {
			/*
			 * base_node_alloc() failed, which is an exceedingly
			 * unlikely failure.  Leak chunk; its pages have
			 * already been purged, so this is only a virtual
			 * memory leak.
			 */
			malloc_mutex_unlock(&chunks_mtx);
			return;
		}
		node = xnode;
		node->addr = chunk;
		node->size = size;
		node->zeroed = (unzeroed == false);
		extent_tree_ad_insert(chunks_ad, node);
		extent_tree_szad_insert(chunks_szad, node);
	}

	/* Try to coalesce backward. */
	prev = extent_tree_ad_prev(chunks_ad, node);
	if (prev != NULL && (void *)((uintptr_t)prev->addr + prev->size) ==
	    chunk) {
		/*
		 * 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);

		extent_tree_szad_remove(chunks_szad, node);
		node->addr = prev->addr;
		node->size += prev->size;
		node->zeroed = (node->zeroed && prev->zeroed);
		extent_tree_szad_insert(chunks_szad, node);

		base_node_dealloc(prev);
	}
	malloc_mutex_unlock(&chunks_mtx);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xc0e80
andb $0x1, %al
movb %al, -0x21(%rbp)
callq 0xbfe80
movq %rax, -0x30(%rbp)
leaq 0x68a3b(%rip), %rdi     # 0x129188
callq 0xc0670
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xcb530
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xc0806
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
cmpq -0x58(%rbp), %rax
jne 0xc0806
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xc9e30
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x38(%rcx)
movb %al, -0x81(%rbp)
je 0xc07d7
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
sete %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %cl
movq -0x38(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xc99e0
cmpq $0x0, -0x30(%rbp)
je 0xc0804
movq -0x30(%rbp), %rdi
callq 0xbfef0
jmp 0xc0870
cmpq $0x0, -0x30(%rbp)
jne 0xc081e
leaq 0x68974(%rip), %rdi     # 0x129188
callq 0xc0690
jmp 0xc0942
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
sete %cl
movq -0x38(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x38(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xcb690
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xc99e0
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xcb380
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xc0936
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rcx
addq 0x30(%rcx), %rax
cmpq -0x18(%rbp), %rax
jne 0xc0936
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xc9e30
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xcbaf0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xc9e30
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x38(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x38(%rcx)
movb %al, -0x82(%rbp)
je 0xc0910
movq -0x40(%rbp), %rax
movb 0x38(%rax), %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %cl
movq -0x38(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xc99e0
movq -0x40(%rbp), %rdi
callq 0xbfef0
leaq 0x6884b(%rip), %rdi     # 0x129188
callq 0xc0690
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)