// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/deps/jemalloc/src/tcache.c
// Function: je_tcache_bin_flush_large
void
tcache_bin_flush_large(tsd_t *tsd, tcache_bin_t *tbin, szind_t binind,
    unsigned rem, tcache_t *tcache)
{
	arena_t *arena;
	void *ptr;
	unsigned i, nflush, ndeferred;
	bool merged_stats = false;

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

	arena = arena_choose(tsd, NULL);
	assert(arena != NULL);
	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 *locked_arena = extent_node_arena_get(&chunk->node);
		UNUSED bool idump;

		if (config_prof)
			idump = false;
		malloc_mutex_lock(&locked_arena->lock);
		if ((config_prof || config_stats) && locked_arena == arena) {
			if (config_prof) {
				idump = arena_prof_accum_locked(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 (extent_node_arena_get(&chunk->node) ==
			    locked_arena) {
				arena_dalloc_large_junked_locked(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(&locked_arena->lock);
		if (config_prof && idump)
			prof_idump();
	}
	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.
		 */
		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
movl %ecx, %ebp
movl %edx, %r12d
movq %rsi, %r14
callq 0x37351
movq %rax, 0x8(%rsp)
movl 0x10(%r14), %ebx
movl %ebp, 0x14(%rsp)
subl %ebp, %ebx
addl $-0x27, %r12d
movl $0x0, 0x4(%rsp)
leaq 0x204bc(%rip), %r15     # 0x576b0
shlq $0x5, %r12
movq %r12, 0x18(%rsp)
testl %ebx, %ebx
je 0x3729a
movq 0x18(%r14), %rax
movq (%r15), %rcx
notq %rcx
andq (%rax), %rcx
movq (%rcx), %rbp
leaq 0x8(%rbp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x106d0
cmpq 0x8(%rsp), %rbp
jne 0x37251
movq (%r14), %rax
movq 0x8(%rsp), %rcx
addq %rax, 0x78(%rcx)
movq 0x98(%rcx), %rcx
movq 0x18(%rsp), %rdx
addq %rax, 0x10(%rcx,%rdx)
andq $0x0, (%r14)
movb $0x1, %al
movl %eax, 0x4(%rsp)
movl %ebx, %r12d
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpq %r13, %r12
je 0x3728b
movq 0x18(%r14), %rax
movq (%rax,%r13,8), %rdx
movq (%r15), %rsi
notq %rsi
andq %rdx, %rsi
cmpq %rbp, (%rsi)
je 0x3727e
movl %ebx, %ecx
movq %rdx, (%rax,%rcx,8)
incl %ebx
jmp 0x37286
movq %rbp, %rdi
callq 0x2450d
incq %r13
jmp 0x37259
movq 0x20(%rsp), %rdi
callq 0x10440
jmp 0x371fd
testb $0x1, 0x4(%rsp)
jne 0x372d9
movq 0x8(%rsp), %rbx
movq %rbx, %r13
addq $0x8, %r13
movq %r13, %rdi
callq 0x106d0
movq (%r14), %rax
addq %rax, 0x78(%rbx)
movq 0x98(%rbx), %rcx
movq 0x18(%rsp), %rdx
addq %rax, 0x10(%rcx,%rdx)
andq $0x0, (%r14)
movq %r13, %rdi
callq 0x10440
movq 0x18(%r14), %rdi
movl 0x10(%r14), %eax
movl 0x14(%rsp), %ebx
subl %ebx, %eax
leaq (%rdi,%rax,8), %rsi
movl %ebx, %edx
shlq $0x3, %rdx
callq 0x10540
movl %ebx, 0x10(%r14)
cmpl %ebx, 0x8(%r14)
jle 0x37304
movl %ebx, 0x8(%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq