// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/deps/jemalloc/src/chunk_dss.c
// Function: je_chunk_alloc_dss
void *
chunk_alloc_dss(arena_t *arena, void *new_addr, size_t size, size_t alignment,
    bool *zero, bool *commit)
{
	cassert(have_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) {

		/*
		 * The loop is necessary to recover from races with other
		 * threads that are using the DSS for something other than
		 * malloc.
		 */
		do {
			void *ret, *cpad, *dss_next;
			size_t gap_size, cpad_size;
			intptr_t incr;
			/* Avoid an unnecessary system call. */
			if (new_addr != NULL && dss_max != new_addr)
				break;

			/* Get the current end of the DSS. */
			dss_max = chunk_dss_sbrk(0);

			/* Make sure the earlier condition still holds. */
			if (new_addr != NULL && dss_max != new_addr)
				break;

			/*
			 * 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 = chunk_dss_sbrk(incr);
			if (dss_prev == dss_max) {
				/* Success. */
				dss_max = dss_next;
				malloc_mutex_unlock(&dss_mtx);
				if (cpad_size != 0) {
					chunk_hooks_t chunk_hooks =
					    CHUNK_HOOKS_INITIALIZER;
					chunk_dalloc_wrapper(arena,
					    &chunk_hooks, cpad, cpad_size,
					    true);
				}
				if (*zero) {
					JEMALLOC_VALGRIND_MAKE_MEM_UNDEFINED(
					    ret, size);
					memset(ret, 0, size);
				}
				if (!*commit)
					*commit = pages_decommit(ret, size);
				return (ret);
			}
		} while (dss_prev != (void *)-1);
	}
	malloc_mutex_unlock(&dss_mtx);

	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
testq %rdx, %rdx
js 0x2f34f
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movq %r9, 0x18(%rsp)
leaq 0x2c448(%rip), %rdi     # 0x5b6c0
callq 0x106d0
cmpq $-0x1, 0x2c463(%rip)    # 0x5b6e8
je 0x2f343
leaq -0x1(%r15), %rax
movq %rax, 0x20(%rsp)
negq %r15
movq %r15, 0x28(%rsp)
movq 0x2c44d(%rip), %rcx     # 0x5b6f0
testq %rbx, %rbx
je 0x2f2b1
cmpq %rbx, %rcx
jne 0x2f343
testq %rbx, %rbx
sete %bpl
xorl %edi, %edi
callq 0x10320
movq %rax, %r15
movq %rax, 0x2c427(%rip)     # 0x5b6f0
cmpq %rbx, %rax
sete %al
orb %bpl, %al
cmpb $0x1, %al
jne 0x2f343
movq 0x20(%rsp), %rax
leaq (%rax,%r15), %r13
andq 0x28(%rsp), %r13
cmpq %r15, %r13
jb 0x2f343
leaq (%r14,%r13), %rbp
cmpq %r15, %rbp
jb 0x2f343
leaq 0x2c3af(%rip), %rax     # 0x5b6a8
movq (%rax), %rdi
leaq 0x2c3ad(%rip), %rax     # 0x5b6b0
movq (%rax), %rax
movq %rax, %rcx
andq %r15, %rcx
subq %rcx, %rdi
andq %rax, %rdi
addq %rdi, %r15
movq %r13, %r12
subq %r15, %r12
addq %r14, %rdi
addq %r12, %rdi
callq 0x10320
movq %rax, 0x2c3bb(%rip)     # 0x5b6e8
movq 0x2c3bc(%rip), %rcx     # 0x5b6f0
cmpq %rcx, %rax
je 0x2f364
cmpq $-0x1, %rax
jne 0x2f2a3
leaq 0x2c376(%rip), %rdi     # 0x5b6c0
callq 0x10440
xorl %r13d, %r13d
movq %r13, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, 0x2c385(%rip)     # 0x5b6f0
leaq 0x2c34e(%rip), %rdi     # 0x5b6c0
callq 0x10440
cmpq %r15, %r13
je 0x2f3ad
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rsi
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
movq $0x0, 0x30(%rsi)
movq 0x8(%rsp), %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x1, %r8d
callq 0x2f001
movq 0x10(%rsp), %rax
cmpb $0x1, (%rax)
movq 0x18(%rsp), %rbx
jne 0x2f3d5
leaq 0x2b2c1(%rip), %rax     # 0x5a684
cmpb $0x1, (%rax)
je 0x2f3f0
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x10270
cmpb $0x0, (%rbx)
jne 0x2f352
movq %r13, %rdi
movq %r14, %rsi
callq 0x36fc8
movb %al, (%rbx)
jmp 0x2f352
movq %r13, %rdi
movq %r14, %rsi
callq 0x3e7a6
jmp 0x2f3c8