// File: /workspace/github_c_makefile_star2_O3/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, %r12
incq 0x38(%rdi)
movq 0xf0(%rdi), %rbx
movq 0xf8(%rdi), %rax
subq %rax, %rbx
movl %esi, 0x24(%rsp)
testl %esi, %esi
jne 0x800b5
movq 0xe8(%r12), %rdx
movb 0x49e89(%rip), %cl      # 0xc9f38
shrq %cl, %rdx
subq %rdx, %rbx
addq %rbx, %rax
movq %rax, 0xf8(%r12)
testq %rbx, %rbx
je 0x804e6
leaq 0x98(%r12), %r14
leaq 0x120(%r12), %rcx
movq %rcx, 0x50(%rsp)
leaq 0x8(%r12), %r13
leaq 0x5f83e(%rip), %rbp     # 0xdf928
movq %r12, 0x28(%rsp)
movq %r14, 0x38(%rsp)
movq %r13, 0x18(%rsp)
movq 0x90(%r12), %rcx
cmpq %r14, %rcx
je 0x80114
movq %rcx, %r8
movq 0x8(%rcx), %rcx
cmpq %r14, %rcx
jne 0x80106
jmp 0x80117
movq %rcx, %r8
cmpq %r14, %r8
je 0x804db
testq %r8, %r8
je 0x804db
movq 0x18(%r8), %rdx
movq %rdx, %rcx
subq %rbx, %rcx
jbe 0x80142
cmpq $0x0, 0x28(%r8)
jne 0x80142
addq %rcx, %rax
movq %rdx, %rbx
subq %rdx, %rax
movq %rax, 0xf8(%r12)
movq %rdx, 0x40(%rsp)
movq %rdx, %rax
cmpq %r8, 0xe0(%r12)
movq %r8, 0x10(%rsp)
jne 0x80175
movq %r12, %rdi
callq 0x8349d
movq 0x10(%rsp), %r8
movq 0x18(%r8), %rax
movq %rbx, 0x48(%rsp)
addq %rax, 0x48(%r12)
cmpq $0x0, 0x28(%r8)
sete %r15b
movq (%rbp), %r13
leaq 0x5f6f5(%rip), %rax     # 0xdf888
movq (%rax), %rax
cmpq %rax, %r13
jae 0x802e3
orb 0x24(%rsp), %r15b
leaq 0x30(%r8), %r9
movq $0x0, 0x8(%rsp)
movabsq $-0x435e50d79435e508, %r14 # imm = 0xBCA1AF286BCA1AF8
movq %r9, 0x30(%rsp)
movq (%rbp), %rsi
movq %r13, %rcx
subq %rsi, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%r9,%rcx,8), %rdx
testb $0x1, %dl
jne 0x80268
movq %rdx, %rbx
shrq $0xc, %rbx
testb $0x8, %dl
je 0x8029e
testb %r15b, %r15b
je 0x802ac
leaq (%r9,%rcx,8), %r12
andq $-0x1000, %rdx          # imm = 0xF000
movq %r13, %rsi
shlq $0xc, %rsi
addq %r8, %rsi
movl $0xff, %r8d
movq 0x28(%rsp), %rdi
movl $0x1, %ecx
xorl %r9d, %r9d
callq 0x83614
movq %r12, (%r12)
movq %r12, 0x8(%r12)
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
je 0x8024d
movq 0x8(%rcx), %rax
movq %rax, 0x8(%r12)
movq %rcx, (%r12)
movq %r12, (%rax)
movq %r12, 0x8(%rcx)
movq (%r12), %r12
leaq 0x5f634(%rip), %rax     # 0xdf888
movq (%rax), %rax
movq %r12, 0x8(%rsp)
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %r9
jmp 0x8029e
testb $0x2, %dl
jne 0x80297
movq %r13, %rcx
shlq $0xc, %rcx
movq (%rcx,%r8), %rcx
subq 0x50(%rsp), %rcx
shrq $0x3, %rcx
imulq %r14, %rcx
leaq 0x5e974(%rip), %rdx     # 0xdec00
movq 0x18(%rcx,%rdx), %rbx
shrq $0xc, %rbx
jmp 0x8029e
shrq $0xc, %rdx
movq %rdx, %rbx
addq %rbx, %r13
cmpq %rax, %r13
jb 0x801c0
jmp 0x802f5
leaq -0x1(%r13), %rdi
subq %rsi, %rdi
jb 0x802c5
leaq (%rdi,%rdi,2), %rdi
testb $0x1, 0x10(%r9,%rdi,8)
je 0x801f5
leaq (%rbx,%r13), %rdi
cmpq %rax, %rdi
je 0x8029e
subq %rsi, %rdi
leaq (%rdi,%rdi,2), %rsi
testb $0x1, 0x10(%r9,%rsi,8)
je 0x801f5
jmp 0x8029e
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0x1fbb0
jmp 0x803fc
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0x1fbb0
movq 0x8(%rsp), %r12
testq %r12, %r12
sete %al
je 0x803fc
movb %al, 0x7(%rsp)
movq 0x10(%rsp), %r8
leaq 0x40(%r8), %rax
movq %rax, 0x58(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r14, 0x60(%rsp)
movq %r12, %rax
movq 0x30(%rsp), %rsi
subq %rsi, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %r15
shrq $0x4, %r15
leaq (%r15,%r15,2), %rax
addq (%rbp), %r15
movq %rbp, %r14
movq 0x10(%rsi,%rax,8), %rbp
movq %rbp, %rsi
andq $-0x1000, %rsi          # imm = 0xF000
movq %rbp, %r13
shrq $0xc, %r13
movq %r15, %rdi
shlq $0xc, %rdi
addq %r8, %rdi
callq 0x85e44
cmpq $0x1000, %rbp           # imm = 0x1000
movq %r14, %rbp
jb 0x803cc
movzbl %al, %eax
shll $0x2, %eax
leaq (%r15,%r15,2), %rcx
movq 0x58(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq %r13, %rdx
movq (%rbp), %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 0x803a0
movq 0x60(%rsp), %r14
addq %r13, %r14
incq %rbx
movq (%r12), %r12
cmpq 0x8(%rsp), %r12
je 0x803f0
testq %r12, %r12
movq 0x10(%rsp), %r8
jne 0x8032a
movq 0x18(%rsp), %r13
movb 0x7(%rsp), %r15b
jmp 0x8040d
movb $0x1, %r15b
movq $0x0, 0x8(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x1faa0
movq 0x28(%rsp), %r12
addq %rbx, 0x40(%r12)
testb %r15b, %r15b
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
jne 0x804a8
leaq 0x30(%rsi), %rbx
movq %rdi, %rax
subq %rbx, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq $0x4, %rdx
addq (%rbp), %rdx
shlq $0xc, %rdx
addq %rsi, %rdx
movq (%rdi), %r15
cmpq %rdi, %r15
je 0x80496
movq 0x8(%rdi), %rax
movq %r15, (%rax)
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq %rcx, 0x8(%rax)
movq %rdi, (%rdi)
movq %rdi, 0x8(%rdi)
movq %r12, %rdi
movq %rdx, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x81848
movq 0x10(%rsp), %rsi
movq %r15, %rdi
testq %r15, %r15
jne 0x80432
jmp 0x804a8
movq %r12, %rdi
movq %rdx, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x81848
movq 0x48(%rsp), %rbx
movq 0x40(%rsp), %rcx
subq %rcx, %rbx
subq %r14, %rcx
movq 0xf8(%r12), %rax
addq %rcx, %rax
movq %rax, 0xf8(%r12)
addq %rcx, %rbx
movq 0x38(%rsp), %r14
jne 0x800f9
jmp 0x804e6
subq %rbx, %rax
movq %rax, 0xf8(%r12)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq