// File: /workspace/github_c_makefile_star2_O1/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
movl %edx, %r13d
leaq 0x5e342(%rip), %rax     # 0xdf880
movq (%rax), %rdx
movq %rdx, %rax
notq %rax
movq %rax, %r9
andq %rsi, %r9
movq %rsi, %r15
subq %r9, %r15
shrq $0xc, %r15
leaq 0x5e3ca(%rip), %r10     # 0xdf928
movq %r15, %r8
subq (%r10), %r8
movq %rdi, %r14
leaq (%r8,%r8,2), %rdi
movq 0x40(%r9,%rdi,8), %rbx
testb $0x2, %bl
jne 0x815a2
movq (%rsi), %rsi
subq %r14, %rsi
addq $-0x120, %rsi           # imm = 0xFEE0
shrq $0x3, %rsi
movabsq $-0x435e50d79435e508, %rdi # imm = 0xBCA1AF286BCA1AF8
imulq %rsi, %rdi
leaq 0x5d665(%rip), %rsi     # 0xdec00
movq 0x18(%rdi,%rsi), %rbx
jmp 0x815a9
andq $-0x1000, %rbx          # imm = 0xF000
movq %rbx, %r12
shrq $0xc, %r12
movq 0xe8(%r14), %rsi
movq %rsi, %rdi
shlq $0xc, %rdi
addq %rdx, %rdi
andq %rax, %rdi
subq %r12, %rsi
shlq $0xc, %rsi
addq %rdx, %rsi
andq %rax, %rsi
subq %rdi, %rsi
je 0x815e1
leaq 0x6f5a3(%rip), %rax     # 0xf0b80
lock
addq %rsi, (%rax)
leaq 0x30(%r9), %rbp
subq %r12, 0xe8(%r14)
testb %cl, %cl
jne 0x81609
movq %r15, %rax
subq (%r10), %rax
leaq (%rax,%rax,2), %rax
movb 0x10(%rbp,%rax,8), %al
andb $0x8, %al
shrb $0x3, %al
orb %r13b, %al
movl %eax, %r13d
movzbl %r13b, %ecx
movq %r15, %rax
subq (%r10), %rax
leal (,%rcx,8), %esi
leaq (%rax,%rax,2), %rax
leaq 0x10(,%rax,8), %rax
addq %rbp, %rax
testb %cl, %cl
je 0x8164d
movq %rbx, %rcx
orq $0xff8, %rcx            # imm = 0xFF8
movq %rcx, (%rax)
leaq (%r12,%r15), %rax
movq (%r10), %rdx
notq %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,2), %rax
jmp 0x8167f
movq (%rax), %rcx
andl $0x4, %ecx
movq %rbx, %rdx
orq $0xff0, %rdx            # imm = 0xFF0
orq %rdx, %rcx
movq %rcx, (%rax)
leaq (%r12,%r15), %rax
movq (%r10), %rcx
notq %rcx
addq %rax, %rcx
leaq (%rcx,%rcx,2), %rax
movq 0x10(%rbp,%rax,8), %rcx
andl $0x4, %ecx
orq %rdx, %rcx
movq %rcx, 0x10(%rbp,%rax,8)
leaq (%r12,%r15), %rdx
leaq 0x5e1f9(%rip), %rax     # 0xdf888
cmpq (%rax), %rdx
movl %r13d, 0xc(%rsp)
jae 0x81757
movq %rdx, %rax
subq (%r10), %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%rbp,%rax,8), %r13
testb $0x1, %r13b
jne 0x81752
movl %r13d, %eax
andl $0x8, %eax
cmpl %esi, %eax
jne 0x81752
movq %r14, 0x10(%rsp)
movq %r13, %r14
andq $-0x1000, %r14          # imm = 0xF000
shrq $0xc, %r13
movq 0x10(%rsp), %rdi
movq %rsi, 0x18(%rsp)
movq %r9, %rsi
movq %r13, %rcx
xorl %r8d, %r8d
movq %r9, 0x20(%rsp)
movl $0x1, %r9d
callq 0x83fb9
movq 0x18(%rsp), %rsi
leaq 0x5e222(%rip), %r10     # 0xdf928
movq 0x20(%rsp), %r9
addq %r14, %rbx
movq 0x10(%rsp), %r14
movq %r15, %rax
subq (%r10), %rax
addq %r13, %r12
leaq (%rax,%rax,2), %rax
movl $0xfff, %ecx            # imm = 0xFFF
movq 0x10(%rbp,%rax,8), %rdx
andq %rcx, %rdx
orq %rbx, %rdx
movq %rdx, 0x10(%rbp,%rax,8)
movq (%r10), %rax
notq %rax
addq %r15, %rax
addq %r12, %rax
leaq (%rax,%rax,2), %rax
andq 0x10(%rbp,%rax,8), %rcx
orq %rbx, %rcx
movq %rcx, 0x10(%rbp,%rax,8)
movl 0xc(%rsp), %r13d
movq (%r10), %rax
cmpq %rax, %r15
jbe 0x81829
notq %rax
addq %r15, %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%rbp,%rax,8), %r13
testb $0x1, %r13b
jne 0x81824
movl %r13d, %eax
andl $0x8, %eax
cmpl %esi, %eax
jne 0x81824
movq %r14, 0x10(%rsp)
movq %r13, %r14
andq $-0x1000, %r14          # imm = 0xF000
shrq $0xc, %r13
movq %r15, %rdx
subq %r13, %rdx
movq %rdx, 0x18(%rsp)
movq 0x10(%rsp), %rdi
movq %r9, %rsi
movq %r13, %rcx
movl $0x1, %r8d
movq %r9, 0x20(%rsp)
xorl %r9d, %r9d
callq 0x83fb9
movq 0x20(%rsp), %r9
addq %r14, %rbx
movq 0x10(%rsp), %r14
addq %r12, %r13
movq 0x18(%rsp), %rdi
movq %rdi, %rax
leaq 0x5e143(%rip), %rsi     # 0xdf928
subq (%rsi), %rax
leaq (%rax,%rax,2), %rax
movl $0xfff, %ecx            # imm = 0xFFF
movq 0x10(%rbp,%rax,8), %rdx
andq %rcx, %rdx
orq %rbx, %rdx
movq %rdx, 0x10(%rbp,%rax,8)
addq %r15, %r12
movq (%rsi), %rax
notq %rax
addq %r12, %rax
leaq (%rax,%rax,2), %rax
andq 0x10(%rbp,%rax,8), %rcx
orq %rbx, %rcx
movq %rcx, 0x10(%rbp,%rax,8)
movq %r13, %r12
movq %rdi, %r15
movl 0xc(%rsp), %r13d
movq %r14, %rdi
movq %r9, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl $0x1, %r8d
movq %r9, %r12
movl $0x1, %r9d
callq 0x8366d
leaq 0x5e0e0(%rip), %rax     # 0xdf930
cmpq (%rax), %rbx
jne 0x818c9
leaq 0x5e0cc(%rip), %rax     # 0xdf928
movq (%rax), %rdx
leaq 0x5e022(%rip), %rax     # 0xdf888
movq (%rax), %rcx
subq %rdx, %rcx
movq %r14, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x83fb9
movq 0xe0(%r14), %r15
movq %r12, 0xe0(%r14)
testq %r15, %r15
je 0x818c9
movq %r14, %r12
addq $0x8, %r14
movq %r14, %rdi
callq 0x1fbb0
leaq 0x5dfba(%rip), %rbx     # 0xdf860
movq (%rbx), %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x85810
movq %r14, %rdi
movq %r12, %r14
callq 0x1faa0
movq (%rbx), %rax
subq %rax, 0x30(%r12)
testb %r13b, %r13b
je 0x81911
movq 0x48663(%rip), %rcx     # 0xc9f38
testq %rcx, %rcx
js 0x81911
movq 0xf0(%r14), %rax
subq 0xf8(%r14), %rax
jbe 0x81911
movq 0xe8(%r14), %rdx
shrq %cl, %rdx
cmpq %rdx, %rax
jbe 0x81911
movq %r14, %rdi
xorl %esi, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7fdbb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq