// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbp
incq 0x38(%rdi)
movq 0xf0(%rdi), %rbx
movq 0xf8(%rdi), %rax
subq %rax, %rbx
movl %esi, 0x1c(%rsp)
testl %esi, %esi
jne 0x77b22
movq 0xe8(%rbp), %rdx
movb 0x4f41c(%rip), %cl      # 0xc6f38
shrq %cl, %rdx
subq %rdx, %rbx
addq %rbx, %rax
movq %rax, 0xf8(%rbp)
leaq 0x98(%rbp), %rdx
leaq 0x120(%rbp), %rcx
movq %rcx, 0x48(%rsp)
leaq 0x8(%rbp), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x64dd9(%rip), %r13     # 0xdc928
leaq 0x64d32(%rip), %rsi     # 0xdc888
movq %rbp, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
testq %rbx, %rbx
je 0x77ebc
movq 0x90(%rbp), %rcx
cmpq %rdx, %rcx
je 0x77b83
movq %rcx, %rdi
movq 0x8(%rcx), %rcx
cmpq %rdx, %rcx
jne 0x77b75
jmp 0x77b86
movq %rcx, %rdi
cmpq %rdx, %rdi
je 0x77eb2
testq %rdi, %rdi
je 0x77eb2
movq 0x18(%rdi), %r14
movq %r14, %rcx
subq %rbx, %rcx
jbe 0x77bb1
cmpq $0x0, 0x28(%rdi)
jne 0x77bb1
addq %rcx, %rax
movq %r14, %rbx
subq %r14, %rax
movq %rax, 0xf8(%rbp)
movq %r14, %rax
cmpq %rdi, 0xe0(%rbp)
movq %rdi, 0x8(%rsp)
jne 0x77be4
movq %rbp, %rdi
callq 0x7a83f
movq 0x8(%rsp), %rdi
leaq 0x64ca8(%rip), %rsi     # 0xdc888
movq 0x18(%rdi), %rax
addq %rax, 0x48(%rbp)
movq %r14, 0x38(%rsp)
subq %r14, %rbx
movq %rbx, 0x40(%rsp)
cmpq $0x0, 0x28(%rdi)
sete %al
orb 0x1c(%rsp), %al
movb %al, 0x10(%rsp)
movq (%r13), %r12
leaq 0x30(%rdi), %rax
movq %rax, (%rsp)
xorl %r14d, %r14d
movq (%rsi), %rax
cmpq %rax, %r12
jae 0x77d45
movq (%r13), %rcx
movq %r12, %rdx
subq %rcx, %rdx
imulq $0x18, %rdx, %r15
movq (%rsp), %rdx
movq 0x10(%rdx,%r15), %rdx
testb $0x1, %dl
jne 0x77caa
movq %rdx, %rbx
shrq $0xc, %rbx
testb $0x8, %dl
je 0x77d3d
cmpb $0x0, 0x10(%rsp)
je 0x77ce8
addq (%rsp), %r15
andq $-0x1000, %rdx          # imm = 0xF000
movq %r12, %rsi
shlq $0xc, %rsi
addq %rdi, %rsi
movl $0xff, %r8d
movq %rbp, %rdi
pushq $0x1
popq %rcx
xorl %r9d, %r9d
callq 0x7a9a0
movq %r15, (%r15)
movq %r15, 0x8(%r15)
testq %r14, %r14
je 0x77d2e
movq 0x8(%r14), %rax
movq %rax, 0x8(%r15)
movq %r14, (%r15)
movq %r15, (%rax)
movq %r15, 0x8(%r14)
movq (%r15), %r14
jmp 0x77d31
testb $0x2, %dl
jne 0x77cdf
movq %r12, %rax
shlq $0xc, %rax
movq (%rax,%rdi), %rax
subq 0x48(%rsp), %rax
cqto
movl $0x98, %ecx
idivq %rcx
imulq $0x68, %rax, %rax
leaq 0x63f2c(%rip), %rcx     # 0xdbc00
movq 0x18(%rax,%rcx), %rbx
shrq $0xc, %rbx
jmp 0x77d3d
shrq $0xc, %rdx
movq %rdx, %rbx
jmp 0x77d3d
leaq -0x1(%r12), %rsi
subq %rcx, %rsi
jb 0x77d06
imulq $0x18, %rsi, %rsi
movq (%rsp), %r8
testb $0x1, 0x10(%r8,%rsi)
je 0x77c57
leaq (%rbx,%r12), %rsi
cmpq %rax, %rsi
je 0x77d25
subq %rcx, %rsi
imulq $0x18, %rsi, %rax
movq (%rsp), %rcx
testb $0x1, 0x10(%rcx,%rax)
je 0x77c57
leaq 0x64b5c(%rip), %rsi     # 0xdc888
jmp 0x77d3d
movq %r15, %r14
leaq 0x64b50(%rip), %rsi     # 0xdc888
movq 0x8(%rsp), %rdi
addq %rbx, %r12
jmp 0x77c14
movq %rdi, %rbx
movq 0x20(%rsp), %rdi
callq 0x1fbb0
leaq 0x40(%rbx), %rax
movq %rax, 0x50(%rsp)
movq %r14, %r15
xorl %r14d, %r14d
movq %r15, 0x10(%rsp)
xorl %r12d, %r12d
testq %r15, %r15
je 0x77e08
movq %r15, %rax
movq (%rsp), %rsi
subq %rsi, %rax
xorl %edx, %edx
pushq $0x18
popq %rcx
divq %rcx
movq %r12, %rbp
movq %rax, %r12
imulq $0x18, %rax, %rax
addq (%r13), %r12
movq 0x10(%rsi,%rax), %rbx
movq %rbx, %rsi
andq $-0x1000, %rsi          # imm = 0xF000
shrq $0xc, %rbx
movq %r12, %rdi
shlq $0xc, %rdi
addq 0x8(%rsp), %rdi
callq 0x7d084
movzbl %al, %eax
shll $0x2, %eax
imulq $0x18, %r12, %rcx
movq %rbp, %r12
addq 0x50(%rsp), %rcx
movq %rbx, %rdx
subq $0x1, %rdx
jb 0x77deb
imulq $-0x18, (%r13), %rsi
movq (%rcx,%rsi), %rdi
andq $-0x5, %rdi
orq %rax, %rdi
movq %rdi, (%rcx,%rsi)
addq $0x18, %rcx
jmp 0x77dcb
addq %rbx, %r12
incq %r14
movq (%r15), %rax
cmpq 0x10(%rsp), %rax
movl $0x0, %r15d
cmovneq %rax, %r15
jmp 0x77d69
movq 0x20(%rsp), %rdi
callq 0x1faa0
movq 0x30(%rsp), %rbp
addq %r14, 0x40(%rbp)
pushq $0x1
popq %r15
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x77e83
movq %rdi, %rax
subq (%rsp), %rax
xorl %edx, %edx
pushq $0x18
popq %rcx
divq %rcx
addq (%r13), %rax
movq (%rdi), %rcx
movl $0x0, %ebx
cmpq %rdi, %rcx
je 0x77e65
movq 0x8(%rdi), %rdx
movq %rcx, (%rdx)
movq (%rdi), %rdx
movq 0x8(%rdi), %rsi
movq %rsi, 0x8(%rdx)
movq %rdi, (%rdi)
movq %rdi, 0x8(%rdi)
movq %rcx, %rbx
shlq $0xc, %rax
addq 0x8(%rsp), %rax
movq %rbp, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl %r15d, %ecx
callq 0x78f00
movq %rbx, %rdi
jmp 0x77e24
movq 0x38(%rsp), %rax
subq %r12, %rax
movq 0x40(%rsp), %rbx
addq %rax, %rbx
addq 0xf8(%rbp), %rax
movq %rax, 0xf8(%rbp)
movq 0x28(%rsp), %rdx
leaq 0x649db(%rip), %rsi     # 0xdc888
jmp 0x77b60
subq %rbx, %rax
movq %rax, 0xf8(%rbp)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq