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

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

	for (nflush = tbin->ncached - rem; nflush > 0; nflush = ndeferred) {
		/* Lock the arena associated with the first object. */
		arena_chunk_t *chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(
		    tbin->avail[0]);
		arena_t *arena = chunk->arena;

		malloc_mutex_lock(&arena->lock);
		if ((config_prof || config_stats) && arena == tcache->arena) {
			if (config_prof) {
				arena_prof_accum(arena,
				    tcache->prof_accumbytes);
				tcache->prof_accumbytes = 0;
			}
			if (config_stats) {
				merged_stats = true;
				arena->stats.nrequests_large +=
				    tbin->tstats.nrequests;
				arena->stats.lstats[binind - NBINS].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)
				arena_dalloc_large_locked(arena, chunk, ptr);
			else {
				/*
				 * This object was allocated via a different
				 * arena 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(&arena->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_t *arena = tcache->arena;
		malloc_mutex_lock(&arena->lock);
		arena->stats.nrequests_large += tbin->tstats.nrequests;
		arena->stats.lstats[binind - NBINS].nrequests +=
		    tbin->tstats.nrequests;
		tbin->tstats.nrequests = 0;
		malloc_mutex_unlock(&arena->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 $0x28, %rsp
movq %rcx, 0x8(%rsp)
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, %r14
movl 0x10(%rdi), %r15d
subl %edx, %r15d
je 0x90ee2
movl %ebp, 0x4(%rsp)
movl $0x0, (%rsp)
leaq 0x4ea5c(%rip), %rbx     # 0xdf880
movq %r13, 0x10(%rsp)
shlq $0x5, %r13
movq %r13, 0x18(%rsp)
movq 0x18(%r14), %rax
movq (%rbx), %rcx
notq %rcx
andq (%rax), %rcx
movq (%rcx), %rbp
leaq 0x8(%rbp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x1faa0
movq 0x8(%rsp), %rax
cmpq 0x18(%rax), %rbp
jne 0x90e7f
movq (%r14), %rax
addq %rax, 0x68(%rbp)
movq 0x70(%rbp), %rcx
movq 0x18(%rsp), %rdx
addq %rax, -0x370(%rcx,%rdx)
movq $0x0, (%r14)
movb $0x1, %al
movl %eax, (%rsp)
movl %r15d, %r12d
movq (%rbx), %rax
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x18(%r14), %rcx
movq (%rcx,%r13,8), %rdx
movq %rax, %rsi
notq %rsi
andq %rdx, %rsi
cmpq %rbp, (%rsi)
je 0x90ead
movl %r15d, %esi
movq %rdx, (%rcx,%rsi,8)
incl %r15d
jmp 0x90eb8
movq %rbp, %rdi
callq 0x817bf
movq (%rbx), %rax
incq %r13
cmpq %r13, %r12
jne 0x90e8b
movq 0x20(%rsp), %rdi
callq 0x1fbb0
testl %r15d, %r15d
jne 0x90e32
testb $0x1, (%rsp)
movl 0x4(%rsp), %ebp
movq 0x10(%rsp), %r13
jne 0x90f1d
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rbx
leaq 0x8(%rbx), %r12
movq %r12, %rdi
callq 0x1faa0
movq (%r14), %rax
addq %rax, 0x68(%rbx)
movq 0x70(%rbx), %rcx
shlq $0x5, %r13
addq %rax, -0x370(%rcx,%r13)
movq $0x0, (%r14)
movq %r12, %rdi
callq 0x1fbb0
movq 0x18(%r14), %rdi
movl 0x10(%r14), %eax
subl %ebp, %eax
leaq (%rdi,%rax,8), %rsi
movl %ebp, %edx
shlq $0x3, %rdx
callq 0x1f780
movl %ebp, 0x10(%r14)
cmpl %ebp, 0x8(%r14)
jle 0x90f44
movl %ebp, 0x8(%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq