// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/chunk_dss.c
// Function: chunk_alloc_dss
void *
chunk_alloc_dss(size_t size, size_t alignment, bool *zero)
{
	void *ret;

	cassert(config_dss);
	assert(size > 0 && (size & chunksize_mask) == 0);
	assert(alignment > 0 && (alignment & chunksize_mask) == 0);

	/*
	 * sbrk() uses a signed increment argument, so take care not to
	 * interpret a huge allocation request as a negative increment.
	 */
	if ((intptr_t)size < 0)
		return (NULL);

	malloc_mutex_lock(&dss_mtx);
	if (dss_prev != (void *)-1) {
		size_t gap_size, cpad_size;
		void *cpad, *dss_next;
		intptr_t incr;

		/*
		 * The loop is necessary to recover from races with other
		 * threads that are using the DSS for something other than
		 * malloc.
		 */
		do {
			/* Get the current end of the DSS. */
			dss_max = sbrk(0);
			/*
			 * Calculate how much padding is necessary to
			 * chunk-align the end of the DSS.
			 */
			gap_size = (chunksize - CHUNK_ADDR2OFFSET(dss_max)) &
			    chunksize_mask;
			/*
			 * Compute how much chunk-aligned pad space (if any) is
			 * necessary to satisfy alignment.  This space can be
			 * recycled for later use.
			 */
			cpad = (void *)((uintptr_t)dss_max + gap_size);
			ret = (void *)ALIGNMENT_CEILING((uintptr_t)dss_max,
			    alignment);
			cpad_size = (uintptr_t)ret - (uintptr_t)cpad;
			dss_next = (void *)((uintptr_t)ret + size);
			if ((uintptr_t)ret < (uintptr_t)dss_max ||
			    (uintptr_t)dss_next < (uintptr_t)dss_max) {
				/* Wrap-around. */
				malloc_mutex_unlock(&dss_mtx);
				return (NULL);
			}
			incr = gap_size + cpad_size + size;
			dss_prev = sbrk(incr);
			if (dss_prev == dss_max) {
				/* Success. */
				dss_max = dss_next;
				malloc_mutex_unlock(&dss_mtx);
				if (cpad_size != 0)
					chunk_unmap(cpad, cpad_size);
				if (*zero) {
					VALGRIND_MAKE_MEM_UNDEFINED(ret, size);
					memset(ret, 0, size);
				}
				return (ret);
			}
		} while (dss_prev != (void *)-1);
	}
	malloc_mutex_unlock(&dss_mtx);

	return (NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
jmp 0xc0b19
jmp 0xc0b1b
jmp 0xc0b1d
jmp 0xc0b1f
jmp 0xc0b21
jmp 0xc0b23
jmp 0xc0b25
cmpq $0x0, -0x10(%rbp)
jge 0xc0b39
movq $0x0, -0x8(%rbp)
jmp 0xc0d26
leaq 0x68748(%rip), %rdi     # 0x129288
callq 0xc0d40
movq $-0x1, %rax
cmpq %rax, 0x6875d(%rip)     # 0x1292b0
je 0xc0d12
jmp 0xc0b5b
xorl %eax, %eax
movl %eax, %edi
callq 0x1f3e0
movq %rax, 0x6874d(%rip)     # 0x1292b8
leaq 0x6863e(%rip), %rax     # 0x1291b0
movq (%rax), %rax
movq 0x6873c(%rip), %rcx     # 0x1292b8
leaq 0x6864d(%rip), %rdx     # 0x1291d0
andq (%rdx), %rcx
subq %rcx, %rax
leaq 0x68640(%rip), %rcx     # 0x1291d0
andq (%rcx), %rax
movq %rax, -0x30(%rbp)
movq 0x6871a(%rip), %rax     # 0x1292b8
addq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x6870b(%rip), %rax     # 0x1292b8
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
addq %rcx, %rax
xorl %ecx, %ecx
subq -0x18(%rbp), %rcx
andq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq 0x686cd(%rip), %rcx     # 0x1292b8
cmpq %rcx, %rax
jb 0xc0c00
movq -0x48(%rbp), %rax
movq 0x686bd(%rip), %rcx     # 0x1292b8
cmpq %rcx, %rax
jae 0xc0c19
leaq 0x68681(%rip), %rdi     # 0x129288
callq 0xc0d60
movq $0x0, -0x8(%rbp)
jmp 0xc0d26
movq -0x30(%rbp), %rax
addq -0x38(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1f3e0
movq %rax, 0x68677(%rip)     # 0x1292b0
movq 0x68670(%rip), %rax     # 0x1292b0
cmpq 0x68671(%rip), %rax     # 0x1292b8
jne 0xc0cfa
movq -0x48(%rbp), %rax
movq %rax, 0x68660(%rip)     # 0x1292b8
leaq 0x68629(%rip), %rdi     # 0x129288
callq 0xc0d60
cmpq $0x0, -0x38(%rbp)
je 0xc0c78
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xc06b0
movq -0x20(%rbp), %rax
testb $0x1, (%rax)
je 0xc0cf0
movq $0x4d430001, -0x80(%rbp) # imm = 0x4D430001
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x80(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
xorl %esi, %esi
callq 0x1f110
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc0d26
jmp 0xc0cfc
movq $-0x1, %rax
cmpq %rax, 0x685a6(%rip)     # 0x1292b0
jne 0xc0b5b
jmp 0xc0d12
leaq 0x6856f(%rip), %rdi     # 0x129288
callq 0xc0d60
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)