// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/arena.c
// Function: arena_purge
static void
arena_purge(arena_t *arena, bool all)
{
	arena_chunk_t *chunk;
	size_t npurgatory;
	if (config_debug) {
		size_t ndirty = 0;

		arena_chunk_dirty_iter(&arena->chunks_dirty, NULL,
		    chunks_dirty_iter_cb, (void *)&ndirty);
		assert(ndirty == arena->ndirty);
	}
	assert(arena->ndirty > arena->npurgatory || all);
	assert((arena->nactive >> opt_lg_dirty_mult) < (arena->ndirty -
	    arena->npurgatory) || all);

	if (config_stats)
		arena->stats.npurge++;

	/*
	 * Compute the minimum number of pages that this thread should try to
	 * purge, and add the result to arena->npurgatory.  This will keep
	 * multiple threads from racing to reduce ndirty below the threshold.
	 */
	{
		size_t npurgeable = arena->ndirty - arena->npurgatory;

		if (all == false) {
			size_t threshold = (arena->nactive >>
			    opt_lg_dirty_mult);

			npurgatory = npurgeable - threshold;
		} else
			npurgatory = npurgeable;
	}
	arena->npurgatory += npurgatory;

	while (npurgatory > 0) {
		size_t npurgeable, npurged, nunpurged;

		/* Get next chunk with dirty pages. */
		chunk = arena_chunk_dirty_first(&arena->chunks_dirty);
		if (chunk == NULL) {
			/*
			 * This thread was unable to purge as many pages as
			 * originally intended, due to races with other threads
			 * that either did some of the purging work, or re-used
			 * dirty pages.
			 */
			arena->npurgatory -= npurgatory;
			return;
		}
		npurgeable = chunk->ndirty;
		assert(npurgeable != 0);

		if (npurgeable > npurgatory && chunk->nruns_adjac == 0) {
			/*
			 * This thread will purge all the dirty pages in chunk,
			 * so set npurgatory to reflect this thread's intent to
			 * purge the pages.  This tends to reduce the chances
			 * of the following scenario:
			 *
			 * 1) This thread sets arena->npurgatory such that
			 *    (arena->ndirty - arena->npurgatory) is at the
			 *    threshold.
			 * 2) This thread drops arena->lock.
			 * 3) Another thread causes one or more pages to be
			 *    dirtied, and immediately determines that it must
			 *    purge dirty pages.
			 *
			 * If this scenario *does* play out, that's okay,
			 * because all of the purging work being done really
			 * needs to happen.
			 */
			arena->npurgatory += npurgeable - npurgatory;
			npurgatory = npurgeable;
		}

		/*
		 * Keep track of how many pages are purgeable, versus how many
		 * actually get purged, and adjust counters accordingly.
		 */
		arena->npurgatory -= npurgeable;
		npurgatory -= npurgeable;
		npurged = arena_chunk_purge(arena, chunk, all);
		nunpurged = npurgeable - npurged;
		arena->npurgatory += nunpurged;
		npurgatory += nunpurged;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
jmp 0xb5d56
jmp 0xb5d58
jmp 0xb5d5a
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x8(%rbp), %rcx
subq 0xf8(%rcx), %rax
movq %rax, -0x28(%rbp)
movb -0x9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xb5db8
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movq 0x5dae5(%rip), %rcx     # 0x113888
shrq %cl, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0xb5dc0
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
addq 0xf8(%rax), %rcx
movq %rcx, 0xf8(%rax)
cmpq $0x0, -0x20(%rbp)
jbe 0xb5ed3
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
callq 0xb9380
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xb5e1a
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0xf8(%rax)
jmp 0xb5ed3
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0xb5e28
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0xb5e5f
movq -0x18(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0xb5e5f
movq -0x38(%rbp), %rcx
subq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
addq 0xf8(%rax), %rcx
movq %rcx, 0xf8(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0xf8(%rax)
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movb -0x9(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0xb93f0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq -0x8(%rbp), %rax
addq 0xf8(%rax), %rcx
movq %rcx, 0xf8(%rax)
movq -0x48(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0xb5dd6
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)