// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/arena.c
// Function: arena_run_split
static void
arena_run_split(arena_t *arena, arena_run_t *run, size_t size, bool large,
    size_t binind, bool zero)
{
	arena_chunk_t *chunk;
	size_t run_ind, total_pages, need_pages, rem_pages, i;
	size_t flag_dirty;

	assert((large && binind == BININD_INVALID) || (large == false && binind
	    != BININD_INVALID));

	chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(run);
	run_ind = (unsigned)(((uintptr_t)run - (uintptr_t)chunk) >> LG_PAGE);
	flag_dirty = arena_mapbits_dirty_get(chunk, run_ind);
	total_pages = arena_mapbits_unallocated_size_get(chunk, run_ind) >>
	    LG_PAGE;
	assert(arena_mapbits_dirty_get(chunk, run_ind+total_pages-1) ==
	    flag_dirty);
	need_pages = (size >> LG_PAGE);
	assert(need_pages > 0);
	assert(need_pages <= total_pages);
	rem_pages = total_pages - need_pages;

	arena_avail_remove(arena, chunk, run_ind, total_pages, true, true);
	if (config_stats) {
		/*
		 * Update stats_cactive if nactive is crossing a chunk
		 * multiple.
		 */
		size_t cactive_diff = CHUNK_CEILING((arena->nactive +
		    need_pages) << LG_PAGE) - CHUNK_CEILING(arena->nactive <<
		    LG_PAGE);
		if (cactive_diff != 0)
			stats_cactive_add(cactive_diff);
	}
	arena->nactive += need_pages;

	/* Keep track of trailing unused pages for later use. */
	if (rem_pages > 0) {
		if (flag_dirty != 0) {
			arena_mapbits_unallocated_set(chunk, run_ind+need_pages,
			    (rem_pages << LG_PAGE), CHUNK_MAP_DIRTY);
			arena_mapbits_unallocated_set(chunk,
			    run_ind+total_pages-1, (rem_pages << LG_PAGE),
			    CHUNK_MAP_DIRTY);
		} else {
			arena_mapbits_unallocated_set(chunk, run_ind+need_pages,
			    (rem_pages << LG_PAGE),
			    arena_mapbits_unzeroed_get(chunk,
			    run_ind+need_pages));
			arena_mapbits_unallocated_set(chunk,
			    run_ind+total_pages-1, (rem_pages << LG_PAGE),
			    arena_mapbits_unzeroed_get(chunk,
			    run_ind+total_pages-1));
		}
		arena_avail_insert(arena, chunk, run_ind+need_pages, rem_pages,
		    false, true);
	}

	/*
	 * Update the page map separately for large vs. small runs, since it is
	 * possible to avoid iteration for large mallocs.
	 */
	if (large) {
		if (zero) {
			if (flag_dirty == 0) {
				/*
				 * The run is clean, so some pages may be
				 * zeroed (i.e. never before touched).
				 */
				for (i = 0; i < need_pages; i++) {
					if (arena_mapbits_unzeroed_get(chunk,
					    run_ind+i) != 0) {
						VALGRIND_MAKE_MEM_UNDEFINED(
						    (void *)((uintptr_t)
						    chunk + ((run_ind+i) <<
						    LG_PAGE)), PAGE);
						memset((void *)((uintptr_t)
						    chunk + ((run_ind+i) <<
						    LG_PAGE)), 0, PAGE);
					} else if (config_debug) {
						VALGRIND_MAKE_MEM_DEFINED(
						    (void *)((uintptr_t)
						    chunk + ((run_ind+i) <<
						    LG_PAGE)), PAGE);
						arena_chunk_validate_zeroed(
						    chunk, run_ind+i);
					}
				}
			} else {
				/*
				 * The run is dirty, so all pages must be
				 * zeroed.
				 */
				VALGRIND_MAKE_MEM_UNDEFINED((void
				    *)((uintptr_t)chunk + (run_ind <<
				    LG_PAGE)), (need_pages << LG_PAGE));
				memset((void *)((uintptr_t)chunk + (run_ind <<
				    LG_PAGE)), 0, (need_pages << LG_PAGE));
			}
		}

		/*
		 * Set the last element first, in case the run only contains one
		 * page (i.e. both statements set the same element).
		 */
		arena_mapbits_large_set(chunk, run_ind+need_pages-1, 0,
		    flag_dirty);
		arena_mapbits_large_set(chunk, run_ind, size, flag_dirty);
	} else {
		assert(zero == false);
		/*
		 * Propagate the dirty and unzeroed flags to the allocated
		 * small run, so that arena_dalloc_bin_run() has the ability to
		 * conditionally trim clean pages.
		 */
		arena_mapbits_small_set(chunk, run_ind, 0, binind, flag_dirty);
		/*
		 * The first page will always be dirtied during small run
		 * initialization, so a validation failure here would not
		 * actually cause an observable failure.
		 */
		if (config_debug && flag_dirty == 0 &&
		    arena_mapbits_unzeroed_get(chunk, run_ind) == 0)
			arena_chunk_validate_zeroed(chunk, run_ind);
		for (i = 1; i < need_pages - 1; i++) {
			arena_mapbits_small_set(chunk, run_ind+i, i, binind, 0);
			if (config_debug && flag_dirty == 0 &&
			    arena_mapbits_unzeroed_get(chunk, run_ind+i) == 0)
				arena_chunk_validate_zeroed(chunk, run_ind+i);
		}
		arena_mapbits_small_set(chunk, run_ind+need_pages-1,
		    need_pages-1, binind, flag_dirty);
		if (config_debug && flag_dirty == 0 &&
		    arena_mapbits_unzeroed_get(chunk, run_ind+need_pages-1) ==
		    0) {
			arena_chunk_validate_zeroed(chunk,
			    run_ind+need_pages-1);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0x28(%rsp)
movq %r8, %r15
movl %ecx, 0x2c(%rsp)
movq %rdx, %rbx
leaq 0x5c248(%rip), %r13     # 0xdf880
movq (%r13), %r12
notq %r12
andq %rsi, %r12
subq %r12, %rsi
shrq $0xc, %rsi
movl %esi, %edx
leaq 0x5c2d6(%rip), %rcx     # 0xdf928
movq %rdx, %rax
subq (%rcx), %rax
movq %rdi, %rbp
leaq (%rax,%rax,2), %rax
movq 0x40(%r12,%rax,8), %r14
movl %r14d, %eax
andl $0x8, %eax
movq %rax, (%rsp)
shrq $0xc, %r14
movq %rbx, 0x10(%rsp)
shrq $0xc, %rbx
movq %r12, %rsi
movq %rdx, 0x8(%rsp)
movq %r14, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x8435d
movq 0xe8(%rbp), %rdx
leaq (%rdx,%rbx), %rax
movq %rax, %rcx
shlq $0xc, %rcx
movq (%r13), %rsi
addq %rsi, %rcx
shlq $0xc, %rdx
addq %rsi, %rdx
notq %rsi
andq %rsi, %rcx
andq %rsi, %rdx
subq %rdx, %rcx
je 0x836da
leaq 0x6d4b4(%rip), %rax     # 0xf0b80
lock
addq %rcx, (%rax)
movq 0xe8(%rbp), %rax
addq %rbx, %rax
leaq 0x30(%r12), %r10
movq %rax, 0xe8(%rbp)
cmpq %rbx, %r14
movq 0x8(%rsp), %r13
movq %r10, 0x18(%rsp)
je 0x83796
movq %r14, %rcx
subq %rbx, %rcx
leaq (%rbx,%r13), %rdx
movq %rcx, %rax
movq %rdx, %rsi
leaq 0x5c218(%rip), %r9      # 0xdf928
subq (%r9), %rsi
shlq $0xc, %rax
leaq (%rsi,%rsi,2), %rsi
leaq (%r10,%rsi,8), %rsi
addq $0x10, %rsi
cmpq $0x0, (%rsp)
jne 0x8375f
movq (%rsi), %rdi
andl $0x4, %edi
movl $0xff0, %r8d            # imm = 0xFF0
orq %r8, %rdi
orq %rax, %rdi
movq %rdi, (%rsi)
addq %r13, %r14
movq (%r9), %rsi
notq %rsi
addq %r14, %rsi
leaq (%rsi,%rsi,2), %rsi
movq 0x10(%r10,%rsi,8), %rdi
andl $0x4, %edi
orq %r8, %rax
orq %rdi, %rax
jmp 0x83778
orq $0xff8, %rax            # imm = 0xFF8
movq %rax, (%rsi)
addq %r13, %r14
movq (%r9), %rsi
notq %rsi
addq %r14, %rsi
leaq (%rsi,%rsi,2), %rsi
movq %rax, 0x10(%r10,%rsi,8)
movq %rbp, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x83a12
movq 0x18(%rsp), %r10
cmpb $0x0, 0x2c(%rsp)
leaq 0x5c186(%rip), %r9      # 0xdf928
je 0x83889
cmpb $0x0, 0x28(%rsp)
je 0x839b3
cmpq $0x0, (%rsp)
jne 0x83944
cmpq $0x1000, 0x10(%rsp)     # imm = 0x1000
jb 0x839b3
movq (%r9), %rax
movq 0x8(%rsp), %r14
leaq (%r14,%r14,2), %rcx
leaq (%r12,%rcx,8), %rbp
addq $0x40, %rbp
shlq $0xc, %r14
addq %r12, %r14
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
movq %rbx, %r13
leaq (,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rbp, %rdx
subq %rcx, %rdx
testb $0x4, (%rdx)
je 0x83870
movq $0x4d430001, 0x30(%rsp) # imm = 0x4D430001
movq %r14, 0x38(%rsp)
movq $0x1000, 0x40(%rsp)     # imm = 0x1000
movq %r12, 0x48(%rsp)
movq %r12, 0x50(%rsp)
movq %r12, 0x58(%rsp)
movq %r15, %rax
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, 0x20(%rsp)
movq 0x20(%rsp), %rax
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f110
movq 0x18(%rsp), %r10
leaq 0x5c0bb(%rip), %r9      # 0xdf928
movq (%r9), %rax
addq $0x18, %rbp
addq $0x1000, %r14           # imm = 0x1000
decq %r13
jne 0x837f3
jmp 0x839b3
movq %r13, %rax
subq (%r9), %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%r10,%rax,8), %rcx
andl $0x4, %ecx
shlq $0x4, %r15
orq (%rsp), %rcx
addq %r15, %rcx
incq %rcx
movq %rcx, 0x10(%r10,%rax,8)
leaq -0x1(%rbx), %rax
cmpq $0x2, %rax
jb 0x8390d
leaq -0x2(%rbx), %rcx
leaq (,%r13,2), %rdx
addq %r13, %rdx
leaq (%r12,%rdx,8), %rdx
addq $0x58, %rdx
movl $0x1000, %esi           # imm = 0x1000
movq (%r9), %rdi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
movq %rdx, %r8
subq %rdi, %r8
negq %rdi
movq (%r8), %r8
andl $0x4, %r8d
addq %rsi, %r8
orq %r15, %r8
orq $0x1, %r8
movq %r8, (%rdx,%rdi)
addq $0x18, %rdx
addq $0x1000, %rsi           # imm = 0x1000
decq %rcx
jne 0x838d4
addq %rbx, %r13
movq (%r9), %rcx
notq %rcx
addq %r13, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%r10,%rcx,8), %rdx
andl $0x4, %edx
shlq $0xc, %rax
orq %rdx, %rax
movq (%rsp), %rdx
orq %rax, %rdx
orq %r15, %rdx
orq $0x1, %rdx
movq %rdx, 0x10(%r10,%rcx,8)
jmp 0x83a03
leaq 0x30(%rsp), %rax
movq $0x4d430001, (%rax)     # imm = 0x4D430001
movq 0x8(%rsp), %rdi
shlq $0xc, %rdi
addq %r12, %rdi
movq %rdi, 0x8(%rax)
movq 0x10(%rsp), %rcx
andq $-0x1000, %rcx          # imm = 0xF000
movq %rcx, 0x10(%rax)
xorl %edx, %edx
movq %rdx, 0x18(%rax)
movq %rdx, 0x20(%rax)
movq %rdx, 0x28(%rax)
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, 0x20(%rsp)
movq 0x20(%rsp), %rax
xorl %esi, %esi
movq %rcx, %rdx
callq 0x1f110
movq 0x18(%rsp), %r10
leaq 0x5bf75(%rip), %r9      # 0xdf928
movq 0x8(%rsp), %rdi
addq %rdi, %rbx
movq (%r9), %rax
notq %rax
addq %rbx, %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%r10,%rax,8), %rcx
andl $0x4, %ecx
movq (%rsp), %rsi
orq %rsi, %rcx
movl $0xff3, %edx            # imm = 0xFF3
orq %rdx, %rcx
movq %rcx, 0x10(%r10,%rax,8)
subq (%r9), %rdi
leaq (%rdi,%rdi,2), %rax
movq 0x10(%r10,%rax,8), %rcx
andl $0x4, %ecx
orq 0x10(%rsp), %rcx
orq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x10(%r10,%rax,8)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq