// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/arena.c
// Function: arena_palloc
void *
arena_palloc(arena_t *arena, size_t size, size_t alignment, bool zero)
{
	void *ret;
	size_t alloc_size, leadsize, trailsize;
	arena_run_t *run;
	arena_chunk_t *chunk;

	assert((size & PAGE_MASK) == 0);

	alignment = PAGE_CEILING(alignment);
	alloc_size = size + alignment - PAGE;

	malloc_mutex_lock(&arena->lock);
	run = arena_run_alloc(arena, alloc_size, true, BININD_INVALID, zero);
	if (run == NULL) {
		malloc_mutex_unlock(&arena->lock);
		return (NULL);
	}
	chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(run);

	leadsize = ALIGNMENT_CEILING((uintptr_t)run, alignment) -
	    (uintptr_t)run;
	assert(alloc_size >= leadsize + size);
	trailsize = alloc_size - leadsize - size;
	ret = (void *)((uintptr_t)run + leadsize);
	if (leadsize != 0) {
		arena_run_trim_head(arena, chunk, run, alloc_size, alloc_size -
		    leadsize);
	}
	if (trailsize != 0) {
		arena_run_trim_tail(arena, chunk, ret, size + trailsize, size,
		    false);
	}

	if (config_stats) {
		arena->stats.nmalloc_large++;
		arena->stats.nrequests_large++;
		arena->stats.allocated_large += size;
		arena->stats.lstats[(size >> LG_PAGE) - 1].nmalloc++;
		arena->stats.lstats[(size >> LG_PAGE) - 1].nrequests++;
		arena->stats.lstats[(size >> LG_PAGE) - 1].curruns++;
	}
	malloc_mutex_unlock(&arena->lock);

	if (config_fill && zero == false) {
		if (opt_junk)
			memset(ret, 0xa5, size);
		else if (opt_zero)
			memset(ret, 0, size);
	}
	return (ret);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r13d
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
addq $0xfff, %rbx            # imm = 0xFFF
movq $-0x1000, %rbp          # imm = 0xF000
andq %rbp, %rbx
addq %rsi, %rbp
addq %rbx, %rbp
leaq 0x8(%rdi), %r15
movq %r15, %rdi
callq 0x1faa0
pushq $0x1
popq %rdx
movl $0xff, %ecx
movq %r12, %rdi
movq %rbp, %rsi
movl %r13d, %r8d
callq 0x786a2
testq %rax, %rax
je 0x788f1
movl %r13d, 0x4(%rsp)
leaq 0x640e5(%rip), %rcx     # 0xdc880
movq (%rcx), %r13
notq %r13
andq %rax, %r13
leaq (%rbx,%rax), %rcx
decq %rcx
negq %rbx
andq %rcx, %rbx
movq %rax, %rcx
subq %rbx, %rcx
leaq (%rcx,%rbp), %rbp
je 0x78862
movq %rax, %r8
subq %r13, %r8
shrq $0xc, %r8
negq %rcx
movq %rcx, %rsi
shrq $0xc, %rsi
leaq 0x6414c(%rip), %rdi     # 0xdc928
movq (%rdi), %r9
movq %r8, %rdx
subq %r9, %rdx
imulq $0x18, %rdx, %rdx
movq 0x40(%r13,%rdx), %rdx
andl $0x8, %edx
addq %r8, %rsi
notq %r9
addq %rsi, %r9
imulq $0x18, %r9, %r10
movq 0x40(%r13,%r10), %r11
andl $0x4, %r11d
orq %rdx, %r11
movl $0xff3, %r9d            # imm = 0xFF3
orq %r9, %r11
movq %r11, 0x40(%r13,%r10)
subq (%rdi), %r8
imulq $0x18, %r8, %r8
movq 0x40(%r13,%r8), %r10
andl $0x4, %r10d
orq %rdx, %rcx
orq %r9, %rcx
orq %r10, %rcx
movq %rcx, 0x40(%r13,%r8)
subq (%rdi), %rsi
imulq $0x18, %rsi, %rcx
movq 0x40(%r13,%rcx), %rsi
andl $0x4, %esi
orq %rdx, %rsi
orq %rbp, %r9
orq %rsi, %r9
movq %r9, 0x40(%r13,%rcx)
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x78f00
cmpq %r14, %rbp
je 0x7887e
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
movq %r14, %r8
xorl %r9d, %r9d
callq 0x78934
incq 0x68(%r12)
movdqu 0x50(%r12), %xmm0
movq %r14, %xmm1
shufpd $0x2, 0x11948(%rip), %xmm1 # xmm1 = xmm1[0],mem[1]
paddq %xmm0, %xmm1
movdqu %xmm1, 0x50(%r12)
movq 0x70(%r12), %rax
movq %r14, %rcx
shrq $0x7, %rcx
andq $-0x20, %rcx
incq -0x20(%rcx,%rax)
movdqu -0x10(%rcx,%rax), %xmm0
pcmpeqd %xmm1, %xmm1
psubq %xmm1, %xmm0
movdqu %xmm0, -0x10(%rcx,%rax)
movq %r15, %rdi
callq 0x1fbb0
cmpb $0x0, 0x4(%rsp)
jne 0x788fb
leaq 0x63279(%rip), %rax     # 0xdbb5b
cmpb $0x1, (%rax)
jne 0x7890d
movq %rbx, %rdi
movl $0xa5, %esi
jmp 0x7891e
movq %r15, %rdi
callq 0x1fbb0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x63258(%rip), %rax     # 0xdbb6c
cmpb $0x1, (%rax)
jne 0x788fb
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1f110