// File: /workspace/github_c_makefile_star2_O3/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/arena.c
// Function: je_arena_reset
void
arena_reset(tsd_t *tsd, arena_t *arena)
{
	unsigned i;
	extent_node_t *node;

	/*
	 * Locking in this function is unintuitive.  The caller guarantees that
	 * no concurrent operations are happening in this arena, but there are
	 * still reasons that some locking is necessary:
	 *
	 * - Some of the functions in the transitive closure of calls assume
	 *   appropriate locks are held, and in some cases these locks are
	 *   temporarily dropped to avoid lock order reversal or deadlock due to
	 *   reentry.
	 * - mallctl("epoch", ...) may concurrently refresh stats.  While
	 *   strictly speaking this is a "concurrent operation", disallowing
	 *   stats refreshes would impose an inconvenient burden.
	 */

	/* Remove large allocations from prof sample set. */
	if (config_prof && opt_prof) {
		ql_foreach(node, &arena->achunks, ql_link) {
			arena_achunk_prof_reset(tsd, arena,
			    extent_node_addr_get(node));
		}
	}

	/* Reset curruns for large size classes. */
	if (config_stats) {
		for (i = 0; i < nlclasses; i++)
			arena->stats.lstats[i].curruns = 0;
	}

	/* Huge allocations. */
	malloc_mutex_lock(tsd_tsdn(tsd), &arena->huge_mtx);
	for (node = ql_last(&arena->huge, ql_link); node != NULL; node =
	    ql_last(&arena->huge, ql_link)) {
		void *ptr = extent_node_addr_get(node);
		size_t usize;

		malloc_mutex_unlock(tsd_tsdn(tsd), &arena->huge_mtx);
		if (config_stats || (config_prof && opt_prof))
			usize = isalloc(tsd_tsdn(tsd), ptr, config_prof);
		/* Remove huge allocation from prof sample set. */
		if (config_prof && opt_prof)
			prof_free(tsd, ptr, usize);
		huge_dalloc(tsd_tsdn(tsd), ptr);
		malloc_mutex_lock(tsd_tsdn(tsd), &arena->huge_mtx);
		/* Cancel out unwanted effects on stats. */
		if (config_stats)
			arena_huge_reset_stats_cancel(arena, usize);
	}
	malloc_mutex_unlock(tsd_tsdn(tsd), &arena->huge_mtx);

	malloc_mutex_lock(tsd_tsdn(tsd), &arena->lock);

	/* Bins. */
	for (i = 0; i < NBINS; i++) {
		arena_bin_t *bin = &arena->bins[i];
		malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
		bin->runcur = NULL;
		arena_run_heap_new(&bin->runs);
		if (config_stats) {
			bin->stats.curregs = 0;
			bin->stats.curruns = 0;
		}
		malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
	}

	/*
	 * Re-initialize runs_dirty such that the chunks_cache and runs_dirty
	 * chains directly correspond.
	 */
	qr_new(&arena->runs_dirty, rd_link);
	for (node = qr_next(&arena->chunks_cache, cc_link);
	    node != &arena->chunks_cache; node = qr_next(node, cc_link)) {
		qr_new(&node->rd, rd_link);
		qr_meld(&arena->runs_dirty, &node->rd, rd_link);
	}

	/* Arena chunks. */
	for (node = ql_last(&arena->achunks, ql_link); node != NULL; node =
	    ql_last(&arena->achunks, ql_link)) {
		ql_remove(&arena->achunks, node, ql_link);
		arena_chunk_discard(tsd_tsdn(tsd), arena,
		    extent_node_addr_get(node));
	}

	/* Spare. */
	if (arena->spare != NULL) {
		arena_chunk_discard(tsd_tsdn(tsd), arena, arena->spare);
		arena->spare = NULL;
	}

	assert(!arena->purging);
	arena->nactive = 0;

	for (i = 0; i < NPSIZES; i++)
		arena_run_heap_new(&arena->runs_avail[i]);

	malloc_mutex_unlock(tsd_tsdn(tsd), &arena->lock);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x299fb(%rip), %edx     # 0x4c5d4
testq %rdx, %rdx
je 0x22c87
movq 0xd0(%rbx), %rax
movq %rdx, %rcx
shlq $0x5, %rcx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
addq $0x20, %rcx
andq $-0x40, %rcx
movdqa 0x16413(%rip), %xmm1    # 0x39020
xorl %edx, %edx
movdqa 0x16419(%rip), %xmm2    # 0x39030
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x19689(%rip), %xmm4    # 0x3c2b0
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %esi
notl %esi
testb $0x1, %sil
je 0x22c62
movq $0x0, 0x18(%rax,%rdx)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x22c7a
movq $0x0, 0x38(%rax,%rdx)
paddq %xmm4, %xmm1
addq $0x40, %rdx
cmpq %rdx, %rcx
jne 0x22c27
leaq 0x830(%rbx), %r15
movq %r15, %rdi
callq 0xb5a0
movq 0x828(%rbx), %rax
testq %rax, %rax
je 0x22da7
movq 0x58(%rax), %rax
testq %rax, %rax
je 0x22da7
movl $0xff, %ebp
movq 0x8(%rax), %r12
movq %r15, %rdi
callq 0xb380
leaq 0x2a405(%rip), %rax     # 0x4d0d0
movq (%rax), %rax
notq %rax
andq %r12, %rax
movq %r12, %rcx
subq %rax, %rcx
je 0x22d77
shrq $0xc, %rcx
subq 0x2a2d5(%rip), %rcx     # 0x4cfc0
movq 0x78(%rax,%rcx,8), %r13
movl %r13d, %eax
shrl $0x5, %eax
andl %ebp, %eax
cmpl %ebp, %eax
je 0x22d91
movl %eax, %eax
leaq 0x189b7(%rip), %rcx     # 0x3b6c0
movq (%rcx,%rax,8), %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0x10a30
movq %r15, %rdi
callq 0xb5a0
cmpq $0x1000, %r13           # imm = 0x1000
ja 0x22d87
decq %r13
shrq $0x3, %r13
leaq 0x19109(%rip), %rax     # 0x3be40
movzbl (%rax,%r13), %eax
subl 0x29892(%rip), %eax     # 0x4c5d4
addl $-0x27, %eax
incq 0xc8(%rbx)
movq 0xd8(%rbx), %rcx
leaq (%rax,%rax,2), %rax
decq 0x8(%rcx,%rax,8)
movq 0x828(%rbx), %rax
testq %rax, %rax
je 0x22da7
movq 0x58(%rax), %rax
testq %rax, %rax
jne 0x22cb8
jmp 0x22da7
movq %r14, %rdi
movq %r12, %rsi
callq 0x2e344
movq %rax, %r13
jmp 0x22d0d
movq %r13, %rdi
callq 0xf6d1
jmp 0x22d3c
shrq %r13
andq $-0x1000, %r13          # imm = 0xF000
addq $-0x1000, %r13          # imm = 0xF000
jmp 0x22d0d
movq %r15, %rdi
callq 0xb380
leaq 0x10(%rbx), %rdi
movq %rdi, (%rsp)
callq 0xb5a0
leaq 0x980(%rbx), %r13
xorl %ebp, %ebp
xorl %r15d, %r15d
leaq (%r15,%r13), %r12
movq %r12, %rdi
callq 0xb5a0
movq %rbp, 0x9f8(%rbx,%r15)
movq %rbp, 0xa20(%rbx,%r15)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x9d0(%rbx,%r15)
movq %r12, %rdi
callq 0xb380
addq $0xa8, %r15
cmpq $0x1998, %r15           # imm = 0x1998
jne 0x22dc8
leaq 0x138(%rbx), %rax
movq %rax, 0x138(%rbx)
movq %rax, 0x140(%rbx)
leaq 0x148(%rbx), %rcx
movq 0x188(%rbx), %rdx
cmpq %rcx, %rdx
je 0x22e57
movq %rax, %rsi
movq %rsi, %rdi
leaq 0x30(%rdx), %rsi
movq %rsi, (%rdi)
movq %rax, 0x30(%rdx)
movq %rdi, 0x38(%rdx)
movq 0x40(%rdx), %rdx
cmpq %rcx, %rdx
jne 0x22e35
movq %rsi, 0x140(%rbx)
movq 0x100(%rbx), %rcx
testq %rcx, %rcx
je 0x22ebb
movq 0x58(%rcx), %rax
testq %rax, %rax
je 0x22ebb
cmpq %rax, %rcx
jne 0x22e7c
movq 0x50(%rcx), %rcx
movq %rcx, 0x100(%rbx)
cmpq %rax, %rcx
je 0x22e9f
movq 0x50(%rax), %rcx
movq 0x58(%rax), %rdx
movq %rcx, 0x50(%rdx)
movq 0x58(%rax), %rdx
movq %rdx, 0x58(%rcx)
movq %rax, 0x50(%rax)
movq %rax, 0x58(%rax)
jmp 0x22eaa
movq $0x0, 0x100(%rbx)
movq 0x8(%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22f15
jmp 0x22e57
movq 0x110(%rbx), %rdx
testq %rdx, %rdx
je 0x22edd
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22f15
movq $0x0, 0x110(%rbx)
movq $0x0, 0x128(%rbx)
addq $0x2318, %rbx           # imm = 0x2318
movl $0x638, %edx            # imm = 0x638
movq %rbx, %rdi
xorl %esi, %esi
callq 0xb230
movq (%rsp), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb380