// File: /workspace/github_c_makefile_star2_O2/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, %r8d
leaq 0x63968(%rip), %rax     # 0xdc880
movq (%rax), %r10
movq %r10, %r9
notq %r9
movq %r9, %r11
andq %rsi, %r11
movq %rsi, %r15
subq %r11, %r15
shrq $0xc, %r15
leaq 0x639f0(%rip), %r13     # 0xdc928
movq %r15, %rax
subq (%r13), %rax
movq %rdi, %rbp
imulq $0x18, %rax, %rax
movq 0x40(%r11,%rax), %rbx
testb $0x2, %bl
jne 0x78f78
movq (%rsi), %rax
subq %rbp, %rax
addq $-0x120, %rax           # imm = 0xFEE0
movl $0x98, %esi
cqto
idivq %rsi
imulq $0x68, %rax, %rax
leaq 0x62c8f(%rip), %rdx     # 0xdbc00
movq 0x18(%rax,%rdx), %rbx
jmp 0x78f7f
andq $-0x1000, %rbx          # imm = 0xF000
movq %rbx, %r12
shrq $0xc, %r12
movq 0xe8(%rbp), %rax
movq %rax, %rsi
shlq $0xc, %rsi
addq %r10, %rsi
andq %r9, %rsi
subq %r12, %rax
movq %rax, %rdx
shlq $0xc, %rdx
addq %r10, %rdx
andq %r9, %rdx
subq %rsi, %rdx
je 0x78fc4
leaq 0x74bca(%rip), %rax     # 0xedb80
lock
addq %rdx, (%rax)
movq 0xe8(%rbp), %rax
subq %r12, %rax
leaq 0x30(%r11), %r14
movq %rax, 0xe8(%rbp)
movq %r15, %rax
subq (%r13), %rax
testb %cl, %cl
je 0x78fea
testb %r8b, %r8b
jne 0x79000
imulq $0x18, %rax, %rcx
movq 0x10(%r14,%rcx), %rcx
jmp 0x79036
imulq $0x18, %rax, %rcx
movq 0x10(%r14,%rcx), %rcx
movl %ecx, %edx
andl $0x8, %edx
shrl $0x3, %edx
orb %r8b, %dl
je 0x79036
imulq $0x18, %rax, %rax
movq %rbx, %rcx
orq $0xff8, %rcx            # imm = 0xFF8
movq %rcx, 0x10(%r14,%rax)
leaq (%r12,%r15), %rdx
movq (%r13), %rax
notq %rax
addq %rdx, %rax
imulq $0x18, %rax, %rax
movq %rcx, 0x10(%r14,%rax)
movb $0x1, %al
movq %rax, 0x20(%rsp)
pushq $0x8
popq %rsi
jmp 0x7907d
imulq $0x18, %rax, %rax
andl $0x4, %ecx
orq %rbx, %rcx
movl $0xff0, %esi            # imm = 0xFF0
orq %rsi, %rcx
movq %rcx, 0x10(%r14,%rax)
leaq (%r12,%r15), %rdx
movq (%r13), %rax
notq %rax
addq %rdx, %rax
imulq $0x18, %rax, %rax
movq 0x10(%r14,%rax), %rcx
andl $0x4, %ecx
orq %rbx, %rsi
orq %rcx, %rsi
movq %rsi, 0x10(%r14,%rax)
xorl %esi, %esi
movq $0x0, 0x20(%rsp)
leaq 0x63804(%rip), %rcx     # 0xdc888
movq (%r13), %rax
cmpq (%rcx), %rdx
jae 0x79146
movq %rdx, %rcx
subq %rax, %rcx
imulq $0x18, %rcx, %rcx
movq 0x10(%r14,%rcx), %r13
movl %r13d, %ecx
andl $0x8, %ecx
cmpl %esi, %ecx
setne %cl
orb %r13b, %cl
testb $0x1, %cl
jne 0x79146
movq %rbp, 0x8(%rsp)
movq %r13, %rbp
andq $-0x1000, %rbp          # imm = 0xF000
shrq $0xc, %r13
pushq $0x1
popq %r9
movq 0x8(%rsp), %rdi
movq %rsi, 0x10(%rsp)
movq %r11, %rsi
movq %r13, %rcx
xorl %r8d, %r8d
movq %r11, 0x18(%rsp)
callq 0x7b638
movq 0x18(%rsp), %r11
addq %rbp, %rbx
movq 0x8(%rsp), %rbp
addq %r13, %r12
movq %r15, %rax
leaq 0x63823(%rip), %rsi     # 0xdc928
subq (%rsi), %rax
imulq $0x18, %rax, %rax
movl $0xfff, %ecx            # imm = 0xFFF
movq 0x10(%r14,%rax), %rdx
andq %rcx, %rdx
orq %rbx, %rdx
movq %rdx, 0x10(%r14,%rax)
movq (%rsi), %rax
notq %rax
addq %r15, %rax
addq %r12, %rax
imulq $0x18, %rax, %rax
andq 0x10(%r14,%rax), %rcx
orq %rbx, %rcx
movq %rcx, 0x10(%r14,%rax)
movq (%rsi), %rax
movq 0x10(%rsp), %rsi
cmpq %rax, %r15
jbe 0x7920c
notq %rax
addq %r15, %rax
imulq $0x18, %rax, %rax
movq 0x10(%r14,%rax), %r13
movl %r13d, %eax
andl $0x8, %eax
cmpl %esi, %eax
setne %al
orb %r13b, %al
testb $0x1, %al
jne 0x7920c
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)
pushq $0x1
popq %r8
movq 0x8(%rsp), %rdi
movq %r11, %rsi
movq %r13, %rcx
xorl %r9d, %r9d
movq %r11, 0x18(%rsp)
callq 0x7b638
movq 0x18(%rsp), %r11
addq %rbp, %rbx
movq 0x8(%rsp), %rbp
addq %r12, %r13
movq 0x10(%rsp), %rdi
movq %rdi, %rax
leaq 0x6375b(%rip), %rsi     # 0xdc928
subq (%rsi), %rax
imulq $0x18, %rax, %rax
movl $0xfff, %ecx            # imm = 0xFFF
movq 0x10(%r14,%rax), %rdx
andq %rcx, %rdx
orq %rbx, %rdx
movq %rdx, 0x10(%r14,%rax)
addq %r15, %r12
movq (%rsi), %rax
notq %rax
addq %r12, %rax
imulq $0x18, %rax, %rax
andq 0x10(%r14,%rax), %rcx
orq %rbx, %rcx
movq %rcx, 0x10(%r14,%rax)
movq %r13, %r12
movq %rdi, %r15
pushq $0x1
popq %r8
movq %rbp, %rdi
movq %r11, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl %r8d, %r9d
movq %r11, %r14
callq 0x7ad71
leaq 0x63702(%rip), %rax     # 0xdc930
cmpq (%rax), %rbx
jne 0x7929e
leaq 0x636ee(%rip), %rax     # 0xdc928
movq (%rax), %rdx
leaq 0x63644(%rip), %rax     # 0xdc888
movq (%rax), %rcx
subq %rdx, %rcx
movq %rbp, %rdi
movq %r14, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x7b638
movq 0xe0(%rbp), %r15
movq %r14, 0xe0(%rbp)
testq %r15, %r15
je 0x7929e
leaq 0x8(%rbp), %r14
movq %r14, %rdi
callq 0x1fbb0
leaq 0x635df(%rip), %rbx     # 0xdc860
movq (%rbx), %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x7cd8d
movq %r14, %rdi
callq 0x1faa0
movq (%rbx), %rax
subq %rax, 0x30(%rbp)
cmpb $0x0, 0x20(%rsp)
je 0x792e8
movq 0x4dc8c(%rip), %rcx     # 0xc6f38
testq %rcx, %rcx
js 0x792e8
movq 0xf0(%rbp), %rax
subq 0xf8(%rbp), %rax
jbe 0x792e8
movq 0xe8(%rbp), %rdx
shrq %cl, %rdx
cmpq %rdx, %rax
jbe 0x792e8
movq %rbp, %rdi
xorl %esi, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x77ae1
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq