// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/tcache.c
// Function: tcache_bin_flush_small
void
tcache_bin_flush_small(tcache_bin_t *tbin, size_t binind, unsigned rem,
    tcache_t *tcache)
{
	void *ptr;
	unsigned i, nflush, ndeferred;
	bool merged_stats = false;

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

	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[0]);
		arena_t *arena = chunk->arena;
		arena_bin_t *bin = &arena->bins[binind];

		if (config_prof && arena == tcache->arena) {
			malloc_mutex_lock(&arena->lock);
			arena_prof_accum(arena, tcache->prof_accumbytes);
			malloc_mutex_unlock(&arena->lock);
			tcache->prof_accumbytes = 0;
		}

		malloc_mutex_lock(&bin->lock);
		if (config_stats && arena == tcache->arena) {
			assert(merged_stats == false);
			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[i];
			assert(ptr != NULL);
			chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
			if (chunk->arena == arena) {
				size_t pageind = ((uintptr_t)ptr -
				    (uintptr_t)chunk) >> LG_PAGE;
				arena_chunk_map_t *mapelm =
				    arena_mapp_get(chunk, pageind);
				if (config_fill && opt_junk) {
					arena_alloc_junk_small(ptr,
					    &arena_bin_info[binind], true);
				}
				arena_dalloc_bin_locked(arena, chunk, ptr,
				    mapelm);
			} 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[ndeferred] = ptr;
				ndeferred++;
			}
		}
		malloc_mutex_unlock(&bin->lock);
	}
	if (config_stats && merged_stats == false) {
		/*
		 * 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 = &tcache->arena->bins[binind];
		malloc_mutex_lock(&bin->lock);
		bin->stats.nflushes++;
		bin->stats.nrequests += tbin->tstats.nrequests;
		tbin->tstats.nrequests = 0;
		malloc_mutex_unlock(&bin->lock);
	}

	memmove(tbin->avail, &tbin->avail[tbin->ncached - rem],
	    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 $0x48, %rsp
movq %rcx, 0x20(%rsp)
movq %rdi, %r15
movl 0x10(%rdi), %r13d
movl %edx, 0x10(%rsp)
subl %edx, %r13d
imulq $0x68, %rsi, %rax
addq 0x3beaf(%rip), %rax     # 0xc2fd0
movq %rax, 0x38(%rsp)
movl $0x0, 0xc(%rsp)
leaq 0x5574b(%rip), %rbx     # 0xdc880
imulq $0x98, %rsi, %rax
movq %rax, 0x18(%rsp)
testl %r13d, %r13d
je 0x8725c
movq 0x18(%r15), %rax
movq (%rbx), %rcx
notq %rcx
andq (%rax), %rcx
movq (%rcx), %r12
movq 0x18(%rsp), %rax
leaq (%r12,%rax), %r14
addq $0x120, %r14            # imm = 0x120
movq %r14, %rdi
callq 0x1faa0
movq %r12, %rdx
movq 0x20(%rsp), %rax
cmpq 0x18(%rax), %r12
jne 0x87195
incq 0x78(%r14)
movq (%r15), %rax
addq %rax, 0x68(%r14)
andq $0x0, (%r15)
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq %r14, 0x30(%rsp)
movl %r13d, %esi
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %rdx, 0x28(%rsp)
movq %rsi, 0x40(%rsp)
cmpq %r14, %rsi
je 0x8724d
movq 0x18(%r15), %rax
movq (%rax,%r14,8), %r12
movq (%rbx), %rbp
notq %rbp
andq %r12, %rbp
cmpq %rdx, (%rbp)
je 0x871d9
movl %r13d, %ecx
movq %r12, (%rax,%rcx,8)
incl %r13d
jmp 0x87245
movl %r13d, 0x14(%rsp)
movq %rbx, %r13
movq %r15, %rbx
movq %r12, %r15
subq %rbp, %r15
shrq $0xc, %r15
leaq 0x55733(%rip), %rax     # 0xdc928
subq (%rax), %r15
leaq 0x5495c(%rip), %rax     # 0xdbb5b
cmpb $0x1, (%rax)
jne 0x87214
movq %r12, %rdi
movq 0x38(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x782ed
imulq $0x18, %r15, %rax
leaq (%rax,%rbp), %rcx
addq $0x30, %rcx
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x78a2f
movq 0x28(%rsp), %rdx
movq %rbx, %r15
movq %r13, %rbx
movl 0x14(%rsp), %r13d
movq 0x40(%rsp), %rsi
incq %r14
jmp 0x871ad
movq 0x30(%rsp), %rdi
callq 0x1fbb0
jmp 0x87141
testb $0x1, 0xc(%rsp)
jne 0x8729b
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rsp), %rcx
leaq (%rax,%rcx), %rbx
addq $0x120, %rbx            # imm = 0x120
movq %rbx, %rdi
callq 0x1faa0
incq 0x78(%rbx)
movq (%r15), %rax
addq %rax, 0x68(%rbx)
andq $0x0, (%r15)
movq %rbx, %rdi
callq 0x1fbb0
movq 0x18(%r15), %rdi
movl 0x10(%r15), %eax
movl 0x10(%rsp), %ebx
subl %ebx, %eax
leaq (%rdi,%rax,8), %rsi
movl %ebx, %edx
shlq $0x3, %rdx
callq 0x1f780
movl %ebx, 0x10(%r15)
cmpl %ebx, 0x8(%r15)
jle 0x872c6
movl %ebx, 0x8(%r15)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq