// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movl %r9d, 0x30(%rsp)
movq %r8, %r15
movl %ecx, 0x34(%rsp)
movq %rdx, %rbx
leaq 0x61ebc(%rip), %rax     # 0xdc880
movq (%rax), %r12
notq %r12
andq %rsi, %r12
subq %r12, %rsi
shrq $0xc, %rsi
movl %esi, %edx
leaq 0x61f4b(%rip), %r13     # 0xdc928
movq %rdx, %rax
subq (%r13), %rax
movq %rdi, %rbp
imulq $0x18, %rax, %rax
movq 0x40(%r12,%rax), %r14
movl %r14d, %eax
andl $0x8, %eax
movq %rax, 0x8(%rsp)
shrq $0xc, %r14
movq %rbx, 0x38(%rsp)
shrq $0xc, %rbx
pushq $0x1
popq %r8
movq %r12, %rsi
movq %rdx, 0x10(%rsp)
movq %r14, %rcx
movl %r8d, %r9d
callq 0x7b638
movq %rbx, %r9
movq 0xe8(%rbp), %rdx
leaq (%rdx,%rbx), %rax
movq %rax, %rcx
shlq $0xc, %rcx
leaq 0x61e45(%rip), %rsi     # 0xdc880
movq (%rsi), %rsi
addq %rsi, %rcx
shlq $0xc, %rdx
addq %rsi, %rdx
notq %rsi
andq %rsi, %rcx
andq %rsi, %rdx
subq %rdx, %rcx
je 0x7aa6b
leaq 0x73123(%rip), %rax     # 0xedb80
lock
addq %rcx, (%rax)
movq 0xe8(%rbp), %rax
addq %r9, %rax
leaq 0x30(%r12), %rdi
movq %rax, 0xe8(%rbp)
cmpq %r9, %r14
movq 0x10(%rsp), %rbx
movq %rdi, 0x18(%rsp)
movq %r9, 0x20(%rsp)
je 0x7ab33
movq %r14, %rcx
subq %r9, %rcx
leaq (%rbx,%r9), %rdx
movq %rcx, %rax
movq %rdx, %rsi
subq (%r13), %rsi
shlq $0xc, %rax
imulq $0x18, %rsi, %rsi
addq %rdi, %rsi
addq $0x10, %rsi
cmpq $0x0, 0x8(%rsp)
jne 0x7aaf8
movq %rdi, %r9
movq (%rsi), %rdi
andl $0x4, %edi
movl $0xff0, %r8d            # imm = 0xFF0
orq %r8, %rdi
orq %rax, %rdi
movq %rdi, (%rsi)
addq %rbx, %r14
movq (%r13), %rsi
notq %rsi
addq %r14, %rsi
imulq $0x18, %rsi, %rsi
movq 0x10(%r9,%rsi), %rdi
andl $0x4, %edi
orq %r8, %rax
orq %rdi, %rax
movq %rax, 0x10(%r9,%rsi)
jmp 0x7ab17
orq $0xff8, %rax            # imm = 0xFF8
movq %rax, (%rsi)
addq %rbx, %r14
movq (%r13), %rsi
notq %rsi
addq %r14, %rsi
imulq $0x18, %rsi, %rsi
movq %rax, 0x10(%rdi,%rsi)
pushq $0x1
popq %r9
movq %rbp, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x7ad71
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %r9
cmpb $0x0, 0x34(%rsp)
je 0x7abf7
cmpb $0x0, 0x30(%rsp)
je 0x7ad0a
cmpq $0x0, 0x8(%rsp)
jne 0x7aca2
movq 0x10(%rsp), %r14
imulq $0x18, %r14, %rax
leaq (%rax,%r12), %rbp
addq $0x40, %rbp
shlq $0xc, %r14
addq %r12, %r14
xorl %r12d, %r12d
leaq 0x40(%rsp), %r15
movq %r9, %rbx
subq $0x1, %rbx
jb 0x7ad0a
imulq $-0x18, (%r13), %rax
testb $0x4, (%rbp,%rax)
je 0x7abea
movq $0x4d430001, 0x40(%rsp) # imm = 0x4D430001
movq %r14, 0x48(%rsp)
movq $0x1000, 0x50(%rsp)     # imm = 0x1000
movq %r12, 0x58(%rsp)
movq %r12, 0x60(%rsp)
movq %r12, 0x68(%rsp)
movq %r15, %rax
xorl %edx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, 0x28(%rsp)
movq 0x28(%rsp), %rax
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f110
movq 0x20(%rsp), %r9
addq $0x18, %rbp
addq $0x1000, %r14           # imm = 0x1000
jmp 0x7ab78
movq %rbx, %rax
subq (%r13), %rax
imulq $0x18, %rax, %rax
movq 0x10(%rdi,%rax), %rcx
andl $0x4, %ecx
shlq $0x4, %r15
orq 0x8(%rsp), %rcx
addq %r15, %rcx
incq %rcx
movq %rcx, 0x10(%rdi,%rax)
leaq -0x1(%r9), %rax
imulq $0x18, %rbx, %rcx
addq %r12, %rcx
addq $0x58, %rcx
pushq $0x1
popq %rdx
movl $0x1000, %esi           # imm = 0x1000
movq (%r13), %rdi
cmpq %rax, %rdx
jae 0x7ac68
imulq $-0x18, %rdi, %rdi
movq (%rcx,%rdi), %r8
andl $0x4, %r8d
addq %rsi, %r8
orq %r15, %r8
orq $0x1, %r8
movq %r8, (%rcx,%rdi)
incq %rdx
addq $0x1000, %rsi           # imm = 0x1000
addq $0x18, %rcx
jmp 0x7ac35
addq %r9, %rbx
notq %rdi
addq %rbx, %rdi
imulq $0x18, %rdi, %rcx
movq 0x18(%rsp), %rsi
movq 0x10(%rsi,%rcx), %rdx
andl $0x4, %edx
shlq $0xc, %rax
orq %rdx, %rax
movq 0x8(%rsp), %rdx
orq %rax, %rdx
orq %r15, %rdx
orq $0x1, %rdx
movq %rdx, 0x10(%rsi,%rcx)
jmp 0x7ad62
leaq 0x40(%rsp), %rax
movq $0x4d430001, (%rax)     # imm = 0x4D430001
movq 0x10(%rsp), %rdi
shlq $0xc, %rdi
addq %r12, %rdi
movq %rdi, 0x8(%rax)
movq 0x38(%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, 0x28(%rsp)
movq 0x28(%rsp), %rax
xorl %esi, %esi
movq %rcx, %rdx
callq 0x1f110
movq 0x20(%rsp), %r9
movq 0x10(%rsp), %rdi
addq %rdi, %r9
movq (%r13), %rax
notq %rax
addq %r9, %rax
imulq $0x18, %rax, %rax
movq 0x18(%rsp), %r8
movq 0x10(%r8,%rax), %rcx
andl $0x4, %ecx
movq 0x8(%rsp), %rsi
orq %rsi, %rcx
movl $0xff3, %edx            # imm = 0xFF3
orq %rdx, %rcx
movq %rcx, 0x10(%r8,%rax)
subq (%r13), %rdi
imulq $0x18, %rdi, %rax
movq 0x10(%r8,%rax), %rcx
andl $0x4, %ecx
orq 0x38(%rsp), %rcx
orq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x10(%r8,%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq