// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movl %edx, %r14d
movl 0x10(%rdi), %ebp
subl %edx, %ebp
movq %rdi, 0x8(%rsp)
je 0x90d67
movq %rdi, %rbx
movl %r14d, 0x14(%rsp)
imulq $0x68, %rsi, %rax
addq 0x353a9(%rip), %rax     # 0xc5fd0
movq %rax, 0x40(%rsp)
movl $0x0, 0x4(%rsp)
leaq 0x4ec45(%rip), %r14     # 0xdf880
movq %rsi, 0x28(%rsp)
imulq $0x98, %rsi, %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rax
movq (%r14), %rcx
notq %rcx
andq (%rax), %rcx
movq (%rcx), %r12
movq 0x30(%rsp), %rax
leaq (%r12,%rax), %r15
addq $0x120, %r15            # imm = 0x120
movq %r15, %rdi
callq 0x1faa0
movq %r12, %rdi
movq 0x18(%rsp), %rax
cmpq 0x18(%rax), %r12
jne 0x90c9a
incq 0x78(%r15)
movq (%rbx), %rax
addq %rax, 0x68(%r15)
movq $0x0, (%rbx)
movb $0x1, %al
movl %eax, 0x4(%rsp)
movq %r15, 0x38(%rsp)
movl %ebp, %r12d
movq (%r14), %rax
xorl %r14d, %r14d
xorl %ebp, %ebp
movq %rdi, 0x20(%rsp)
movq 0x18(%rbx), %rcx
movq (%rcx,%r14,8), %r13
movq %rax, %r15
notq %r15
andq %r13, %r15
cmpq %rdi, (%r15)
je 0x90ccf
movl %ebp, %edx
movq %r13, (%rcx,%rdx,8)
incl %ebp
jmp 0x90d31
movq %r13, %rbx
subq %r15, %rbx
shrq $0xc, %rbx
leaq 0x4ec48(%rip), %rax     # 0xdf928
subq (%rax), %rbx
leaq 0x4de71(%rip), %rax     # 0xdeb5b
cmpb $0x1, (%rax)
jne 0x90d01
movq %r13, %rdi
movq 0x40(%rsp), %rsi
movl $0x1, %edx
callq 0x80af1
leaq (%rbx,%rbx,2), %rax
leaq (%r15,%rax,8), %rcx
addq $0x30, %rcx
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x8134a
movq 0x20(%rsp), %rdi
leaq 0x4eb57(%rip), %rax     # 0xdf880
movq (%rax), %rax
movq 0x8(%rsp), %rbx
incq %r14
cmpq %r14, %r12
jne 0x90caf
movq 0x38(%rsp), %rdi
callq 0x1fbb0
testl %ebp, %ebp
leaq 0x4eb30(%rip), %r14     # 0xdf880
jne 0x90c4c
testb $0x1, 0x4(%rsp)
movl 0x14(%rsp), %r14d
movq 0x28(%rsp), %rsi
jne 0x90db3
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
imulq $0x98, %rsi, %rcx
leaq (%rax,%rcx), %rbx
addq $0x120, %rbx            # imm = 0x120
movq %rbx, %rdi
callq 0x1faa0
incq 0x78(%rbx)
movq 0x8(%rsp), %rax
movq (%rax), %rax
addq %rax, 0x68(%rbx)
movq 0x8(%rsp), %rax
movq $0x0, (%rax)
movq %rbx, %rdi
movq 0x8(%rsp), %rbx
callq 0x1fbb0
movq 0x18(%rbx), %rdi
movl 0x10(%rbx), %eax
subl %r14d, %eax
leaq (%rdi,%rax,8), %rsi
movl %r14d, %edx
shlq $0x3, %rdx
callq 0x1f780
movl %r14d, 0x10(%rbx)
cmpl %r14d, 0x8(%rbx)
jle 0x90ddb
movl %r14d, 0x8(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq