// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/arena.c
// Function: arena_chunk_purge
static inline size_t
arena_chunk_purge(arena_t *arena, arena_chunk_t *chunk, bool all)
{
	size_t npurged;
	ql_head(arena_chunk_map_t) mapelms;
	arena_chunk_map_t *mapelm;
	size_t pageind, npages;
	size_t nmadvise;

	ql_new(&mapelms);

	/*
	 * If chunk is the spare, temporarily re-allocate it, 1) so that its
	 * run is reinserted into runs_avail, and 2) so that it cannot be
	 * completely discarded by another thread while arena->lock is dropped
	 * by this thread.  Note that the arena_run_dalloc() call will
	 * implicitly deallocate the chunk, so no explicit action is required
	 * in this function to deallocate the chunk.
	 *
	 * Note that once a chunk contains dirty pages, it cannot again contain
	 * a single run unless 1) it is a dirty run, or 2) this function purges
	 * dirty pages and causes the transition to a single clean run.  Thus
	 * (chunk == arena->spare) is possible, but it is not possible for
	 * this function to be called on the spare unless it contains a dirty
	 * run.
	 */
	if (chunk == arena->spare) {
		assert(arena_mapbits_dirty_get(chunk, map_bias) != 0);
		assert(arena_mapbits_dirty_get(chunk, chunk_npages-1) != 0);

		arena_chunk_alloc(arena);
	}

	if (config_stats)
		arena->stats.purged += chunk->ndirty;

	/*
	 * Operate on all dirty runs if there is no clean/dirty run
	 * fragmentation.
	 */
	if (chunk->nruns_adjac == 0)
		all = true;

	/*
	 * Temporarily allocate free dirty runs within chunk.  If all is false,
	 * only operate on dirty runs that are fragments; otherwise operate on
	 * all dirty runs.
	 */
	for (pageind = map_bias; pageind < chunk_npages; pageind += npages) {
		mapelm = arena_mapp_get(chunk, pageind);
		if (arena_mapbits_allocated_get(chunk, pageind) == 0) {
			size_t run_size =
			    arena_mapbits_unallocated_size_get(chunk, pageind);

			npages = run_size >> LG_PAGE;
			assert(pageind + npages <= chunk_npages);
			assert(arena_mapbits_dirty_get(chunk, pageind) ==
			    arena_mapbits_dirty_get(chunk, pageind+npages-1));

			if (arena_mapbits_dirty_get(chunk, pageind) != 0 &&
			    (all || arena_avail_adjac(chunk, pageind,
			    npages))) {
				arena_run_t *run = (arena_run_t *)((uintptr_t)
				    chunk + (uintptr_t)(pageind << LG_PAGE));

				arena_run_split(arena, run, run_size, true,
				    BININD_INVALID, false);
				/* Append to list for later processing. */
				ql_elm_new(mapelm, u.ql_link);
				ql_tail_insert(&mapelms, mapelm, u.ql_link);
			}
		} else {
			/* Skip run. */
			if (arena_mapbits_large_get(chunk, pageind) != 0) {
				npages = arena_mapbits_large_size_get(chunk,
				    pageind) >> LG_PAGE;
			} else {
				size_t binind;
				arena_bin_info_t *bin_info;
				arena_run_t *run = (arena_run_t *)((uintptr_t)
				    chunk + (uintptr_t)(pageind << LG_PAGE));

				assert(arena_mapbits_small_runind_get(chunk,
				    pageind) == 0);
				binind = arena_bin_index(arena, run->bin);
				bin_info = &arena_bin_info[binind];
				npages = bin_info->run_size >> LG_PAGE;
			}
		}
	}
	assert(pageind == chunk_npages);
	assert(chunk->ndirty == 0 || all == false);
	assert(chunk->nruns_adjac == 0);

	malloc_mutex_unlock(&arena->lock);
	if (config_stats)
		nmadvise = 0;
	npurged = 0;
	ql_foreach(mapelm, &mapelms, u.ql_link) {
		bool unzeroed;
		size_t flag_unzeroed, i;

		pageind = (((uintptr_t)mapelm - (uintptr_t)chunk->map) /
		    sizeof(arena_chunk_map_t)) + map_bias;
		npages = arena_mapbits_large_size_get(chunk, pageind) >>
		    LG_PAGE;
		assert(pageind + npages <= chunk_npages);
		unzeroed = pages_purge((void *)((uintptr_t)chunk + (pageind <<
		    LG_PAGE)), (npages << LG_PAGE));
		flag_unzeroed = unzeroed ? CHUNK_MAP_UNZEROED : 0;
		/*
		 * Set the unzeroed flag for all pages, now that pages_purge()
		 * has returned whether the pages were zeroed as a side effect
		 * of purging.  This chunk map modification is safe even though
		 * the arena mutex isn't currently owned by this thread,
		 * because the run is marked as allocated, thus protecting it
		 * from being modified by any other thread.  As long as these
		 * writes don't perturb the first and last elements'
		 * CHUNK_MAP_ALLOCATED bits, behavior is well defined.
		 */
		for (i = 0; i < npages; i++) {
			arena_mapbits_unzeroed_set(chunk, pageind+i,
			    flag_unzeroed);
		}
		npurged += npages;
		if (config_stats)
			nmadvise++;
	}
	malloc_mutex_lock(&arena->lock);
	if (config_stats)
		arena->stats.nmadvise += nmadvise;

	/* Deallocate runs. */
	for (mapelm = ql_first(&mapelms); mapelm != NULL;
	    mapelm = ql_first(&mapelms)) {
		arena_run_t *run;

		pageind = (((uintptr_t)mapelm - (uintptr_t)chunk->map) /
		    sizeof(arena_chunk_map_t)) + map_bias;
		run = (arena_run_t *)((uintptr_t)chunk + (uintptr_t)(pageind <<
		    LG_PAGE));
		ql_remove(&mapelms, mapelm, u.ql_link);
		arena_run_dalloc(arena, run, false, true);
	}

	return (npurged);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0xe0(%rcx), %rax
jne 0xb9434
jmp 0xb9425
jmp 0xb9427
jmp 0xb9429
jmp 0xb942b
movq -0x8(%rbp), %rdi
callq 0xb9870
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
addq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0xb9457
movb $0x1, -0x11(%rbp)
leaq 0x6fe1a(%rip), %rax     # 0x129278
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
leaq 0x6fd68(%rip), %rcx     # 0x1291d8
cmpq (%rcx), %rax
jae 0xb9621
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xb73d0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xb9a60
cmpq $0x0, %rax
jne 0xb9596
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xb9a90
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
shrq $0xc, %rax
movq %rax, -0x40(%rbp)
jmp 0xb94c0
jmp 0xb94c2
jmp 0xb94c4
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xb9ad0
cmpq $0x0, %rax
je 0xb9594
testb $0x1, -0x11(%rbp)
jne 0xb94fb
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0xb9b00
testb $0x1, %al
jne 0xb94fb
jmp 0xb9594
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0xc, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movl $0x1, %ecx
movl $0xff, %r8d
xorl %r9d, %r9d
callq 0xb9b50
movq -0x30(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xb9546
cmpq $0x0, -0x28(%rbp)
je 0xb9587
jmp 0xb954f
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xb9587
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0xb9594
jmp 0xb960e
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xba040
cmpq $0x0, %rax
je 0xb95c0
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xb7500
shrq $0xc, %rax
movq %rax, -0x40(%rbp)
jmp 0xb960c
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0xc, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
jmp 0xb95d5
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rax
movq (%rax), %rsi
callq 0xba070
movq %rax, -0x60(%rbp)
leaq 0x6ef60(%rip), %rax     # 0x128550
imulq $0x68, -0x60(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0xc, %rax
movq %rax, -0x40(%rbp)
jmp 0xb960e
jmp 0xb9610
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xb9465
jmp 0xb9623
jmp 0xb9625
jmp 0xb9627
jmp 0xb9629
jmp 0xb962b
jmp 0xb962d
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0xb5ee0
movq $0x0, -0x48(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xb9765
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
addq $0x30, %rcx
subq %rcx, %rax
movl $0x18, %ecx
xorl %edx, %edx
divq %rcx
leaq 0x6fbfb(%rip), %rcx     # 0x129278
addq (%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xb7500
shrq $0xc, %rax
movq %rax, -0x40(%rbp)
jmp 0xb969b
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
shlq $0xc, %rax
addq %rax, %rdi
movq -0x40(%rbp), %rsi
shlq $0xc, %rsi
callq 0xc0e80
andb $0x1, %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %dl
xorl %eax, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0xb9715
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
callq 0xba0b0
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0xb96dc
movq -0x40(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpq -0x28(%rbp), %rax
je 0xb974a
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x98(%rbp)
jmp 0xb9755
xorl %eax, %eax
movq %rax, -0x98(%rbp)
jmp 0xb9755
movq -0x98(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xb9652
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0xb5d20
movq -0x48(%rbp), %rcx
movq -0x8(%rbp), %rax
addq 0x40(%rax), %rcx
movq %rcx, 0x40(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xb985f
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
addq $0x30, %rcx
subq %rcx, %rax
movl $0x18, %ecx
xorl %edx, %edx
divq %rcx
leaq 0x6fac3(%rip), %rcx     # 0x129278
addq (%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0xc, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0xb97e7
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0xb9831
jmp 0xb97f3
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xb9839
movq $0x0, -0x28(%rbp)
jmp 0xb983b
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0xb7540
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xb978a
movq -0x20(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)