// File: /workspace/github_c_makefile_star2_O1/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 0x90a3e
movq %rdi, %rbx
movl %r14d, 0x14(%rsp)
imulq $0x68, %rsi, %rax
addq 0x356da(%rip), %rax     # 0xc5fd0
movq %rax, 0x40(%rsp)
movl $0x0, 0x4(%rsp)
leaq 0x4ef76(%rip), %rcx     # 0xdf880
movq %rsi, 0x28(%rsp)
imulq $0x98, %rsi, %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rax
movq (%rcx), %rcx
notq %rcx
andq (%rax), %rcx
movq (%rcx), %r15
movq 0x30(%rsp), %rax
leaq (%r15,%rax), %r14
addq $0x120, %r14            # imm = 0x120
movq %r14, %rdi
callq 0x1faa0
movq %r15, %rdi
movq 0x18(%rsp), %rax
cmpq 0x18(%rax), %r15
jne 0x90969
incq 0x78(%r14)
movq (%rbx), %rax
addq %rax, 0x68(%r14)
movq $0x0, (%rbx)
movb $0x1, %al
movl %eax, 0x4(%rsp)
movq %r14, 0x38(%rsp)
cmpl $0x1, %ebp
movl %ebp, %r12d
adcl $0x0, %r12d
xorl %r14d, %r14d
xorl %ebp, %ebp
leaq 0x4eefc(%rip), %rdx     # 0xdf880
movq %rdi, 0x20(%rsp)
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %r13
movq (%rdx), %r15
notq %r15
andq %r13, %r15
cmpq %rdi, (%r15)
je 0x909a9
movl %ebp, %ecx
movq %r13, (%rax,%rcx,8)
incl %ebp
jmp 0x90a08
movq %r13, %rbx
subq %r15, %rbx
shrq $0xc, %rbx
leaq 0x4ef6e(%rip), %rax     # 0xdf928
subq (%rax), %rbx
leaq 0x4e197(%rip), %rax     # 0xdeb5b
cmpb $0x1, (%rax)
jne 0x909db
movq %r13, %rdi
movq 0x40(%rsp), %rsi
movl $0x1, %edx
callq 0x8080a
leaq (%rbx,%rbx,2), %rax
leaq (%r15,%rax,8), %rcx
addq $0x30, %rcx
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x8102e
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rbx
leaq 0x4ee78(%rip), %rdx     # 0xdf880
incq %r14
cmpq %r14, %r12
jne 0x90989
movq 0x38(%rsp), %rdi
callq 0x1fbb0
leaq 0x4ee5b(%rip), %rcx     # 0xdf880
testl %ebp, %ebp
jne 0x9091b
testb $0x1, 0x4(%rsp)
movl 0x14(%rsp), %r14d
movq 0x28(%rsp), %rsi
jne 0x90a8a
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 0x90ab2
movl %r14d, 0x8(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq