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

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

	arena = arena_choose(tsd, NULL);
	assert(arena != NULL);
	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 *bin_arena = extent_node_arena_get(&chunk->node);
		arena_bin_t *bin = &bin_arena->bins[binind];

		if (config_prof && bin_arena == arena) {
			if (arena_prof_accum(arena, tcache->prof_accumbytes))
				prof_idump();
			tcache->prof_accumbytes = 0;
		}

		malloc_mutex_lock(&bin->lock);
		if (config_stats && bin_arena == arena) {
			assert(!merged_stats);
			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 (extent_node_arena_get(&chunk->node) == bin_arena) {
				size_t pageind = ((uintptr_t)ptr -
				    (uintptr_t)chunk) >> LG_PAGE;
				arena_chunk_map_bits_t *bitselm =
				    arena_bitselm_get(chunk, pageind);
				arena_dalloc_bin_junked_locked(bin_arena, chunk,
				    ptr, bitselm);
			} 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) {
		/*
		 * 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 = &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 $0x38, %rsp
movl %r8d, %r12d
movl %ecx, %ebp
movq %rdx, %r14
movq 0x28(%rdi), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x3ca38
movl 0x10(%r14), %ebx
subl %r12d, %ebx
je 0x3c9bf
movl %r12d, 0x1c(%rsp)
movl %ebp, %eax
movl $0x0, 0xc(%rsp)
leaq 0x1edd6(%rip), %rbp     # 0x5b6b0
movq %rax, 0x20(%rsp)
imulq $0xe0, %rax, %rax
movq %rax, 0x28(%rsp)
movq 0x18(%r14), %rax
movq (%rbp), %rcx
notq %rcx
andq (%rax), %rcx
movq (%rcx), %r13
movq 0x28(%rsp), %rax
leaq (%rax,%r13), %r15
addq $0x450, %r15            # imm = 0x450
movq %r15, %rdi
callq 0x106d0
cmpq 0x10(%rsp), %r13
jne 0x3c939
incq 0xc0(%r15)
movq (%r14), %rax
addq %rax, 0xa8(%r15)
movq $0x0, (%r14)
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq %r15, 0x30(%rsp)
movl %ebx, %r12d
movq (%rbp), %rax
xorl %r15d, %r15d
xorl %ebx, %ebx
movq 0x18(%r14), %rcx
movq (%rcx,%r15,8), %rdx
movq %rax, %rsi
notq %rsi
andq %rdx, %rsi
cmpq %r13, (%rsi)
je 0x3c96a
movl %ebx, %esi
movq %rdx, (%rcx,%rsi,8)
incl %ebx
jmp 0x3c992
movq %rdx, %rax
subq %rsi, %rax
shrq $0xc, %rax
leaq 0x1ebdd(%rip), %rcx     # 0x5b558
subq (%rcx), %rax
leaq (%rsi,%rax,8), %rcx
addq $0x68, %rcx
movq %r13, %rdi
callq 0x29553
movq (%rbp), %rax
incq %r15
cmpq %r15, %r12
jne 0x3c94a
movq 0x30(%rsp), %rdi
callq 0x10440
testl %ebx, %ebx
jne 0x3c8eb
testb $0x1, 0xc(%rsp)
movl 0x1c(%rsp), %r12d
movq 0x20(%rsp), %rax
je 0x3c9c1
jmp 0x3ca00
movl %ebp, %eax
imulq $0xe0, %rax, %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %r15
addq $0x450, %r15            # imm = 0x450
movq %r15, %rdi
callq 0x106d0
incq 0xc0(%r15)
movq (%r14), %rax
addq %rax, 0xa8(%r15)
movq $0x0, (%r14)
movq %r15, %rdi
callq 0x10440
movq 0x18(%r14), %rdi
movl 0x10(%r14), %eax
subl %r12d, %eax
leaq (%rdi,%rax,8), %rsi
movl %r12d, %edx
shlq $0x3, %rdx
callq 0x10540
movl %r12d, 0x10(%r14)
cmpl %r12d, 0x8(%r14)
jle 0x3ca29
movl %r12d, 0x8(%r14)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x22135
movq %rax, 0x10(%rsp)
jmp 0x3c8b7