// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/arena.c
// Function: arena_run_dalloc
static void
arena_run_dalloc(arena_t *arena, arena_run_t *run, bool dirty, bool cleaned)
{
	arena_chunk_t *chunk;
	size_t size, run_ind, run_pages, flag_dirty;

	chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(run);
	run_ind = (size_t)(((uintptr_t)run - (uintptr_t)chunk) >> LG_PAGE);
	assert(run_ind >= map_bias);
	assert(run_ind < chunk_npages);
	if (arena_mapbits_large_get(chunk, run_ind) != 0) {
		size = arena_mapbits_large_size_get(chunk, run_ind);
		assert(size == PAGE ||
		    arena_mapbits_large_size_get(chunk,
		    run_ind+(size>>LG_PAGE)-1) == 0);
	} else {
		size_t binind = arena_bin_index(arena, run->bin);
		arena_bin_info_t *bin_info = &arena_bin_info[binind];
		size = bin_info->run_size;
	}
	run_pages = (size >> LG_PAGE);
	if (config_stats) {
		/*
		 * Update stats_cactive if nactive is crossing a chunk
		 * multiple.
		 */
		size_t cactive_diff = CHUNK_CEILING(arena->nactive << LG_PAGE) -
		    CHUNK_CEILING((arena->nactive - run_pages) << LG_PAGE);
		if (cactive_diff != 0)
			stats_cactive_sub(cactive_diff);
	}
	arena->nactive -= run_pages;

	/*
	 * The run is dirty if the caller claims to have dirtied it, as well as
	 * if it was already dirty before being allocated and the caller
	 * doesn't claim to have cleaned it.
	 */
	assert(arena_mapbits_dirty_get(chunk, run_ind) ==
	    arena_mapbits_dirty_get(chunk, run_ind+run_pages-1));
	if (cleaned == false && arena_mapbits_dirty_get(chunk, run_ind) != 0)
		dirty = true;
	flag_dirty = dirty ? CHUNK_MAP_DIRTY : 0;

	/* Mark pages as unallocated in the chunk map. */
	if (dirty) {
		arena_mapbits_unallocated_set(chunk, run_ind, size,
		    CHUNK_MAP_DIRTY);
		arena_mapbits_unallocated_set(chunk, run_ind+run_pages-1, size,
		    CHUNK_MAP_DIRTY);
	} else {
		arena_mapbits_unallocated_set(chunk, run_ind, size,
		    arena_mapbits_unzeroed_get(chunk, run_ind));
		arena_mapbits_unallocated_set(chunk, run_ind+run_pages-1, size,
		    arena_mapbits_unzeroed_get(chunk, run_ind+run_pages-1));
	}

	/* Try to coalesce forward. */
	if (run_ind + run_pages < chunk_npages &&
	    arena_mapbits_allocated_get(chunk, run_ind+run_pages) == 0 &&
	    arena_mapbits_dirty_get(chunk, run_ind+run_pages) == flag_dirty) {
		size_t nrun_size = arena_mapbits_unallocated_size_get(chunk,
		    run_ind+run_pages);
		size_t nrun_pages = nrun_size >> LG_PAGE;

		/*
		 * Remove successor from runs_avail; the coalesced run is
		 * inserted later.
		 */
		assert(arena_mapbits_unallocated_size_get(chunk,
		    run_ind+run_pages+nrun_pages-1) == nrun_size);
		assert(arena_mapbits_dirty_get(chunk,
		    run_ind+run_pages+nrun_pages-1) == flag_dirty);
		arena_avail_remove(arena, chunk, run_ind+run_pages, nrun_pages,
		    false, true);

		size += nrun_size;
		run_pages += nrun_pages;

		arena_mapbits_unallocated_size_set(chunk, run_ind, size);
		arena_mapbits_unallocated_size_set(chunk, run_ind+run_pages-1,
		    size);
	}

	/* Try to coalesce backward. */
	if (run_ind > map_bias && arena_mapbits_allocated_get(chunk, run_ind-1)
	    == 0 && arena_mapbits_dirty_get(chunk, run_ind-1) == flag_dirty) {
		size_t prun_size = arena_mapbits_unallocated_size_get(chunk,
		    run_ind-1);
		size_t prun_pages = prun_size >> LG_PAGE;

		run_ind -= prun_pages;

		/*
		 * Remove predecessor from runs_avail; the coalesced run is
		 * inserted later.
		 */
		assert(arena_mapbits_unallocated_size_get(chunk, run_ind) ==
		    prun_size);
		assert(arena_mapbits_dirty_get(chunk, run_ind) == flag_dirty);
		arena_avail_remove(arena, chunk, run_ind, prun_pages, true,
		    false);

		size += prun_size;
		run_pages += prun_pages;

		arena_mapbits_unallocated_size_set(chunk, run_ind, size);
		arena_mapbits_unallocated_size_set(chunk, run_ind+run_pages-1,
		    size);
	}

	/* Insert into runs_avail, now that coalescing is complete. */
	assert(arena_mapbits_unallocated_size_get(chunk, run_ind) ==
	    arena_mapbits_unallocated_size_get(chunk, run_ind+run_pages-1));
	assert(arena_mapbits_dirty_get(chunk, run_ind) ==
	    arena_mapbits_dirty_get(chunk, run_ind+run_pages-1));
	arena_avail_insert(arena, chunk, run_ind, run_pages, true, true);

	/* Deallocate chunk if it is now completely unused. */
	if (size == arena_maxclass) {
		assert(run_ind == map_bias);
		assert(run_pages == (arena_maxclass >> LG_PAGE));
		arena_chunk_dealloc(arena, chunk);
	}

	/*
	 * It is okay to do dirty page processing here even if the chunk was
	 * deallocated above, since in that case it is the spare.  Waiting
	 * until after possible chunk deallocation to do dirty processing
	 * allows for an old spare to be fully deallocated, thus decreasing the
	 * chances of spuriously crossing the dirty page purging threshold.
	 */
	if (dirty)
		arena_maybe_purge(arena);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x5e023(%rip), %rax     # 0xdf880
movq (%rax), %r8
movq %r8, %rax
notq %rax
movq %rax, %r10
andq %rsi, %r10
movq %rsi, %r15
subq %r10, %r15
shrq $0xc, %r15
leaq 0x5e0ab(%rip), %r11     # 0xdf928
movq %r15, %r9
subq (%r11), %r9
movq %rdi, %rbp
leaq (%r9,%r9,2), %rdi
movq 0x40(%r10,%rdi,8), %rbx
testb $0x2, %bl
jne 0x818c1
movq (%rsi), %rsi
subq %rbp, %rsi
addq $-0x120, %rsi           # imm = 0xFEE0
shrq $0x3, %rsi
movabsq $-0x435e50d79435e508, %rdi # imm = 0xBCA1AF286BCA1AF8
imulq %rsi, %rdi
leaq 0x5d346(%rip), %rsi     # 0xdec00
movq 0x18(%rdi,%rsi), %rbx
jmp 0x818c8
andq $-0x1000, %rbx          # imm = 0xF000
movq %rbx, %r12
shrq $0xc, %r12
movq 0xe8(%rbp), %rsi
movq %rsi, %r9
shlq $0xc, %r9
addq %r8, %r9
andq %rax, %r9
subq %r12, %rsi
movq %rsi, %rdi
shlq $0xc, %rdi
addq %r8, %rdi
andq %rax, %rdi
subq %r9, %rdi
je 0x8190d
leaq 0x6f281(%rip), %rax     # 0xf0b80
lock
addq %rdi, (%rax)
movq 0xe8(%rbp), %rsi
subq %r12, %rsi
leaq 0x30(%r10), %r14
movq %rsi, 0xe8(%rbp)
movq %r15, %rax
subq (%r11), %rax
testb %cl, %cl
je 0x81931
testb %dl, %dl
jne 0x81947
leaq (%rax,%rax,2), %rcx
movq 0x10(%r14,%rcx,8), %rcx
jmp 0x8197e
leaq (%rax,%rax,2), %rcx
movq 0x10(%r14,%rcx,8), %rcx
movl %ecx, %esi
andl $0x8, %esi
shrl $0x3, %esi
orb %dl, %sil
je 0x8197e
leaq (%rax,%rax,2), %rax
movq %rbx, %rcx
orq $0xff8, %rcx            # imm = 0xFF8
movq %rcx, 0x10(%r14,%rax,8)
leaq (%r12,%r15), %rdx
movq (%r11), %rax
notq %rax
addq %rdx, %rax
leaq (%rax,%rax,2), %rax
movq %rcx, 0x10(%r14,%rax,8)
movb $0x1, %al
movq %rax, 0x20(%rsp)
movl $0x8, %esi
jmp 0x819c4
leaq (%rax,%rax,2), %rax
andl $0x4, %ecx
orq %rbx, %rcx
movl $0xff0, %esi            # imm = 0xFF0
orq %rsi, %rcx
movq %rcx, 0x10(%r14,%rax,8)
leaq (%r12,%r15), %rdx
movq (%r11), %rax
notq %rax
addq %rdx, %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%r14,%rax,8), %rcx
andl $0x4, %ecx
orq %rbx, %rsi
orq %rcx, %rsi
movq %rsi, 0x10(%r14,%rax,8)
xorl %esi, %esi
movq $0x0, 0x20(%rsp)
leaq 0x5debd(%rip), %rcx     # 0xdf888
movq (%r11), %rax
cmpq (%rcx), %rdx
jae 0x81a8e
movq %rdx, %rcx
subq %rax, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%r14,%rcx,8), %r13
movl %r13d, %ecx
andl $0x8, %ecx
cmpl %esi, %ecx
setne %cl
orb %r13b, %cl
testb $0x1, %cl
jne 0x81a8e
movq %rbp, 0x8(%rsp)
movq %r13, %rbp
andq $-0x1000, %rbp          # imm = 0xF000
shrq $0xc, %r13
movq 0x8(%rsp), %rdi
movq %rsi, 0x10(%rsp)
movq %r10, %rsi
movq %r13, %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
movq %r10, 0x18(%rsp)
callq 0x8435d
leaq 0x5deee(%rip), %rsi     # 0xdf928
movq 0x18(%rsp), %r10
addq %rbp, %rbx
movq 0x8(%rsp), %rbp
addq %r13, %r12
movq %r15, %rax
subq (%rsi), %rax
leaq (%rax,%rax,2), %rax
movl $0xfff, %ecx            # imm = 0xFFF
movq 0x10(%r14,%rax,8), %rdx
andq %rcx, %rdx
orq %rbx, %rdx
movq %rdx, 0x10(%r14,%rax,8)
movq (%rsi), %rax
notq %rax
addq %r15, %rax
addq %r12, %rax
leaq (%rax,%rax,2), %rax
andq 0x10(%r14,%rax,8), %rcx
orq %rbx, %rcx
movq %rcx, 0x10(%r14,%rax,8)
movq (%rsi), %rax
movq 0x10(%rsp), %rsi
cmpq %rax, %r15
jbe 0x81b56
notq %rax
addq %r15, %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%r14,%rax,8), %r13
movl %r13d, %eax
andl $0x8, %eax
cmpl %esi, %eax
setne %al
orb %r13b, %al
testb $0x1, %al
jne 0x81b56
movq %rbp, 0x8(%rsp)
movq %r13, %rbp
andq $-0x1000, %rbp          # imm = 0xF000
shrq $0xc, %r13
movq %r15, %rdx
subq %r13, %rdx
movq %rdx, 0x10(%rsp)
movq 0x8(%rsp), %rdi
movq %r10, %rsi
movq %r13, %rcx
movl $0x1, %r8d
xorl %r9d, %r9d
movq %r10, 0x18(%rsp)
callq 0x8435d
movq 0x18(%rsp), %r10
addq %rbp, %rbx
movq 0x8(%rsp), %rbp
addq %r12, %r13
movq 0x10(%rsp), %rdi
movq %rdi, %rax
leaq 0x5de11(%rip), %rsi     # 0xdf928
subq (%rsi), %rax
leaq (%rax,%rax,2), %rax
movl $0xfff, %ecx            # imm = 0xFFF
movq 0x10(%r14,%rax,8), %rdx
andq %rcx, %rdx
orq %rbx, %rdx
movq %rdx, 0x10(%r14,%rax,8)
addq %r15, %r12
movq (%rsi), %rax
notq %rax
addq %r12, %rax
leaq (%rax,%rax,2), %rax
andq 0x10(%r14,%rax,8), %rcx
orq %rbx, %rcx
movq %rcx, 0x10(%r14,%rax,8)
movq %r13, %r12
movq %rdi, %r15
movq %rbp, %rdi
movq %r10, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
movq %r10, %r14
callq 0x83a12
leaq 0x5ddb3(%rip), %rax     # 0xdf930
cmpq (%rax), %rbx
jne 0x81bef
leaq 0x5dd9f(%rip), %rax     # 0xdf928
movq (%rax), %rdx
leaq 0x5dcf5(%rip), %rax     # 0xdf888
movq (%rax), %rcx
subq %rdx, %rcx
movq %rbp, %rdi
movq %r14, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x8435d
movq 0xe0(%rbp), %r15
movq %r14, 0xe0(%rbp)
testq %r15, %r15
je 0x81bef
leaq 0x8(%rbp), %r14
movq %r14, %rdi
callq 0x1fbb0
leaq 0x5dc90(%rip), %rbx     # 0xdf860
movq (%rbx), %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x85b4a
movq %r14, %rdi
callq 0x1faa0
movq (%rbx), %rax
subq %rax, 0x30(%rbp)
cmpb $0x0, 0x20(%rsp)
je 0x81c39
movq 0x4833b(%rip), %rcx     # 0xc9f38
testq %rcx, %rcx
js 0x81c39
movq 0xf0(%rbp), %rax
subq 0xf8(%rbp), %rax
jbe 0x81c39
movq 0xe8(%rbp), %rdx
shrq %cl, %rdx
cmpq %rdx, %rax
jbe 0x81c39
movq %rbp, %rdi
xorl %esi, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x80073
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq