// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/tcache.c
// Function: je_tcache_bin_flush_small
void
tcache_bin_flush_small(tsd_t *tsd, tcache_t *tcache, tcache_bin_t *tbin,
    szind_t binind, unsigned rem)
{
	arena_t *arena;
	void *ptr;
	unsigned i, nflush, ndeferred;
	bool merged_stats = false;

	assert(binind < NBINS);
	assert(rem <= tbin->ncached);

	arena = arena_choose(tsd, NULL);
	assert(arena != NULL);
	for (nflush = tbin->ncached - rem; nflush > 0; nflush = ndeferred) {
		/* Lock the arena bin associated with the first object. */
		arena_chunk_t *chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(
		    *(tbin->avail - 1));
		arena_t *bin_arena = extent_node_arena_get(&chunk->node);
		arena_bin_t *bin = &bin_arena->bins[binind];

		if (config_prof && bin_arena == arena) {
			if (arena_prof_accum(tsd_tsdn(tsd), arena,
			    tcache->prof_accumbytes))
				prof_idump(tsd_tsdn(tsd));
			tcache->prof_accumbytes = 0;
		}

		malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
		if (config_stats && bin_arena == arena) {
			assert(!merged_stats);
			merged_stats = true;
			bin->stats.nflushes++;
			bin->stats.nrequests += tbin->tstats.nrequests;
			tbin->tstats.nrequests = 0;
		}
		ndeferred = 0;
		for (i = 0; i < nflush; i++) {
			ptr = *(tbin->avail - 1 - i);
			assert(ptr != NULL);
			chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
			if (extent_node_arena_get(&chunk->node) == bin_arena) {
				size_t pageind = ((uintptr_t)ptr -
				    (uintptr_t)chunk) >> LG_PAGE;
				arena_chunk_map_bits_t *bitselm =
				    arena_bitselm_get_mutable(chunk, pageind);
				arena_dalloc_bin_junked_locked(tsd_tsdn(tsd),
				    bin_arena, chunk, ptr, bitselm);
			} else {
				/*
				 * This object was allocated via a different
				 * arena bin than the one that is currently
				 * locked.  Stash the object, so that it can be
				 * handled in a future pass.
				 */
				*(tbin->avail - 1 - ndeferred) = ptr;
				ndeferred++;
			}
		}
		malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
		arena_decay_ticks(tsd_tsdn(tsd), bin_arena, nflush - ndeferred);
	}
	if (config_stats && !merged_stats) {
		/*
		 * The flush loop didn't happen to flush to this thread's
		 * arena, so the stats didn't get merged.  Manually do so now.
		 */
		arena_bin_t *bin = &arena->bins[binind];
		malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
		bin->stats.nflushes++;
		bin->stats.nrequests += tbin->tstats.nrequests;
		tbin->tstats.nrequests = 0;
		malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
	}

	memmove(tbin->avail - rem, tbin->avail - tbin->ncached, rem *
	    sizeof(void *));
	tbin->ncached = rem;
	if ((int)tbin->ncached < tbin->low_water)
		tbin->low_water = tbin->ncached;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebx
movl %ecx, %ebp
movq %rdx, %r14
movq %rdi, %r15
movq 0x30(%rdi), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x3538e
movl 0x10(%r14), %r12d
movl %ebp, %eax
subl %ebx, %r12d
je 0x35315
movl %ebx, 0x18(%rsp)
movl $0x0, 0xc(%rsp)
leaq 0x17f21(%rip), %rcx     # 0x4d0d0
movq %rax, 0x20(%rsp)
imulq $0xa8, %rax, %rax
movq %rax, 0x28(%rsp)
movq %r15, %rbx
movq 0x18(%r14), %rax
movq (%rcx), %rcx
notq %rcx
andq -0x8(%rax), %rcx
movq (%rcx), %r13
movq 0x28(%rsp), %rax
leaq (%rax,%r13), %r15
addq $0x980, %r15            # imm = 0x980
movq %r15, %rdi
callq 0xb5a0
cmpq 0x10(%rsp), %r13
jne 0x3520e
incq 0x88(%r15)
movq (%r14), %rax
addq %rax, 0x70(%r15)
movq $0x0, (%r14)
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq %r15, 0x30(%rsp)
cmpl $0x1, %r12d
movl %r12d, 0x1c(%rsp)
movl %r12d, %ebp
adcl $0x0, %ebp
negq %rbp
xorl %r15d, %r15d
xorl %r12d, %r12d
leaq 0x17e9e(%rip), %rsi     # 0x4d0d0
movq 0x18(%r14), %rax
movq -0x8(%rax,%r15,8), %rcx
movq (%rsi), %rdx
notq %rdx
andq %rcx, %rdx
cmpq %r13, (%rdx)
je 0x3525c
movl %r12d, %edx
shlq $0x3, %rdx
subq %rdx, %rax
movq %rcx, -0x8(%rax)
incl %r12d
jmp 0x3528a
movq %rcx, %rax
subq %rdx, %rax
shrq $0xc, %rax
leaq 0x17d53(%rip), %rsi     # 0x4cfc0
subq (%rsi), %rax
leaq (%rdx,%rax,8), %r8
addq $0x78, %r8
movq %rbx, %rdi
movq %r13, %rsi
callq 0x23652
leaq 0x17e46(%rip), %rsi     # 0x4d0d0
decq %r15
cmpq %r15, %rbp
jne 0x35232
movq 0x30(%rsp), %rdi
callq 0xb380
movq %rbx, %r15
testq %rbx, %rbx
movl 0x1c(%rsp), %ebx
je 0x352d5
movl (%r13), %esi
movq 0x38(%r15), %rax
testq %rax, %rax
je 0x352e7
cmpl %esi, 0x40(%r15)
jbe 0x352e7
leaq (%rax,%rsi,8), %rax
testq %rax, %rax
je 0x352d5
subl %r12d, %ebx
movl (%rax), %ecx
movl %ecx, %edx
subl %ebx, %edx
jl 0x352f1
movl %edx, (%rax)
cmpl %ebx, %ecx
jl 0x352f6
testl %r12d, %r12d
leaq 0x17df1(%rip), %rcx     # 0x4d0d0
jne 0x351c0
jmp 0x35305
movq %r15, %rdi
callq 0x1afa2
jmp 0x352bf
movl 0x4(%rax), %edx
jmp 0x352cf
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x226c8
jmp 0x352d5
testb $0x1, 0xc(%rsp)
movl 0x18(%rsp), %ebx
movq 0x20(%rsp), %rax
jne 0x35351
imulq $0xa8, %rax, %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %r15
addq $0x980, %r15            # imm = 0x980
movq %r15, %rdi
callq 0xb5a0
incq 0x88(%r15)
movq (%r14), %rax
addq %rax, 0x70(%r15)
movq $0x0, (%r14)
movq %r15, %rdi
callq 0xb380
movq 0x18(%r14), %rsi
movl %ebx, %edx
shlq $0x3, %rdx
movq %rsi, %rdi
subq %rdx, %rdi
movl 0x10(%r14), %eax
shlq $0x3, %rax
subq %rax, %rsi
callq 0xb450
movl %ebx, 0x10(%r14)
cmpl %ebx, 0x8(%r14)
jle 0x3537f
movl %ebx, 0x8(%r14)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
xorl %esi, %esi
callq 0x1b0d1
movq %rax, 0x10(%rsp)
jmp 0x3518d