// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %rdi, %rbx
incq 0x38(%rdi)
movq 0xf0(%rdi), %rdi
movq 0xf8(%rbx), %rax
subq %rax, %rdi
movl %esi, 0x24(%rsp)
testl %esi, %esi
jne 0x7fdfc
movq 0xe8(%rbx), %rdx
movb 0x4a142(%rip), %cl      # 0xc9f38
shrq %cl, %rdx
subq %rdx, %rdi
addq %rdi, %rax
movq %rax, 0xf8(%rbx)
leaq 0x98(%rbx), %r14
leaq 0x120(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x5faff(%rip), %r15     # 0xdf928
leaq 0x5fa58(%rip), %r8      # 0xdf888
movq %rbx, 0x38(%rsp)
movq %r14, 0x30(%rsp)
testq %rdi, %rdi
je 0x80200
movq 0x90(%rbx), %rax
cmpq %r14, %rax
je 0x7fe5d
movq %rax, %r9
movq 0x8(%rax), %rax
cmpq %r14, %rax
jne 0x7fe4f
jmp 0x7fe60
movq %rax, %r9
cmpq %r14, %r9
sete %al
testq %r9, %r9
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x7fe7f
subq %rdi, 0xf8(%rbx)
jmp 0x801f8
movq 0x18(%r9), %rdx
movq %rdx, %rax
subq %rdi, %rax
jbe 0x7fe9c
cmpq $0x0, 0x28(%r9)
jne 0x7fe9c
addq %rax, 0xf8(%rbx)
movq %rdx, %rdi
movb %cl, 0xf(%rsp)
movq %rdi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
subq %rdx, 0xf8(%rbx)
cmpq %r9, 0xe0(%rbx)
movq %r9, 0x10(%rsp)
jne 0x7fed3
movq %rbx, %rdi
callq 0x8310e
movq 0x10(%rsp), %r9
leaq 0x5f9b5(%rip), %r8      # 0xdf888
movq 0x18(%r9), %rax
addq %rax, 0x48(%rbx)
cmpq $0x0, 0x28(%r9)
sete %r13b
movq (%r15), %r12
movq (%r8), %rax
cmpq %rax, %r12
jae 0x8002d
orb 0x24(%rsp), %r13b
leaq 0x30(%r9), %r14
movq $0x0, 0x18(%rsp)
movq (%r15), %rsi
movq %r12, %rcx
subq %rsi, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%r14,%rcx,8), %rdx
testb $0x1, %dl
jne 0x7ffa4
movq %rdx, %rbp
shrq $0xc, %rbp
testb $0x8, %dl
je 0x7ffe4
testb %r13b, %r13b
je 0x7fff5
leaq (%r14,%rcx,8), %r15
andq $-0x1000, %rdx          # imm = 0xF000
movq %r12, %rsi
shlq $0xc, %rsi
addq %r9, %rsi
movl $0xff, %r8d
movq %rbx, %rdi
movl $0x1, %ecx
xorl %r9d, %r9d
callq 0x83283
movq %r15, (%r15)
movq %r15, 0x8(%r15)
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
je 0x7ff87
movq 0x8(%rcx), %rax
movq %rax, 0x8(%r15)
movq %rcx, (%r15)
movq %r15, (%rax)
movq %r15, 0x8(%rcx)
movq (%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0x5f992(%rip), %r15     # 0xdf928
leaq 0x5f8eb(%rip), %r8      # 0xdf888
movq 0x10(%rsp), %r9
jmp 0x7ffe4
testb $0x2, %dl
jne 0x7ffdd
movq %r12, %rax
shlq $0xc, %rax
movq (%rax,%r9), %rax
subq 0x50(%rsp), %rax
shrq $0x3, %rax
movabsq $-0x435e50d79435e508, %rcx # imm = 0xBCA1AF286BCA1AF8
imulq %rcx, %rax
leaq 0x5ec2e(%rip), %rcx     # 0xdec00
movq 0x18(%rax,%rcx), %rbp
shrq $0xc, %rbp
jmp 0x7ffe4
shrq $0xc, %rdx
movq %rdx, %rbp
addq %rbp, %r12
movq (%r8), %rax
cmpq %rax, %r12
jb 0x7ff05
jmp 0x80036
leaq -0x1(%r12), %rdi
subq %rsi, %rdi
jb 0x8000f
leaq (%rdi,%rdi,2), %rdi
testb $0x1, 0x10(%r14,%rdi,8)
je 0x7ff39
leaq (%r12,%rbp), %rdi
cmpq %rax, %rdi
je 0x7ffe4
subq %rsi, %rdi
leaq (%rdi,%rdi,2), %rax
testb $0x1, 0x10(%r14,%rax,8)
je 0x7ff39
jmp 0x7ffe4
movq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rdi
callq 0x1fbb0
movq 0x18(%rsp), %r13
testq %r13, %r13
je 0x8012f
movq 0x10(%rsp), %r8
leaq 0x30(%r8), %rax
movq %rax, 0x60(%rsp)
leaq 0x40(%r8), %rax
movq %rax, 0x58(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
movq %r13, %rax
movq 0x60(%rsp), %rsi
subq %rsi, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %r12
shrq $0x4, %r12
leaq (%r12,%r12,2), %rax
addq (%r15), %r12
movq 0x10(%rsi,%rax,8), %r15
movq %r15, %rsi
andq $-0x1000, %rsi          # imm = 0xF000
movq %r15, %rbx
shrq $0xc, %rbx
movq %r12, %rdi
shlq $0xc, %rdi
addq %r8, %rdi
callq 0x85b30
cmpq $0x1000, %r15           # imm = 0x1000
leaq 0x5f865(%rip), %r15     # 0xdf928
jb 0x80106
movzbl %al, %eax
shll $0x2, %eax
leaq (%r12,%r12,2), %rcx
movq 0x58(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq %rbx, %rdx
movq (%r15), %rsi
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
movq %rcx, %rdi
subq %rsi, %rdi
negq %rsi
movq (%rdi), %rdi
andq $-0x5, %rdi
orq %rax, %rdi
movq %rdi, (%rcx,%rsi)
addq $0x18, %rcx
decq %rdx
jne 0x800db
addq %rbx, %r14
incq %rbp
movq (%r13), %rax
cmpq 0x18(%rsp), %rax
movl $0x0, %r13d
cmovneq %rax, %r13
testq %r13, %r13
movq 0x10(%rsp), %r8
jne 0x8006a
jmp 0x80134
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x28(%rsp), %rdi
callq 0x1faa0
movq 0x38(%rsp), %rbx
addq %rbp, 0x40(%rbx)
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x801c7
movq 0x10(%rsp), %rax
leaq 0x30(%rax), %r15
movq %rsi, %rax
subq %r15, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq $0x4, %rdx
leaq 0x5f7b0(%rip), %rax     # 0xdf928
addq (%rax), %rdx
movq (%rsi), %r12
cmpq %rsi, %r12
je 0x8019e
movq 0x8(%rsi), %rax
movq %r12, (%rax)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
movq %rcx, 0x8(%rax)
movq %rsi, (%rsi)
movq %rsi, 0x8(%rsi)
jmp 0x801a1
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
shlq $0xc, %rdx
addq %rax, %rdx
movq %rbx, %rdi
movq %rdx, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x81526
movq %r12, %rsi
testq %r12, %r12
jne 0x8015a
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rax
subq %rax, %rdi
subq %r14, %rax
addq %rax, 0xf8(%rbx)
addq %rax, %rdi
movq 0x30(%rsp), %r14
leaq 0x5f73b(%rip), %r15     # 0xdf928
leaq 0x5f694(%rip), %r8      # 0xdf888
movb 0xf(%rsp), %cl
testb %cl, %cl
je 0x7fe3a
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq