// File: /workspace/github_c_makefile_star2_O2/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 0x29ccf
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movq %r9, 0x18(%rsp)
leaq 0x2dac8(%rip), %rdi     # 0x576c0
callq 0x106d0
cmpq $-0x1, 0x2dae3(%rip)    # 0x576e8
je 0x29cc3
leaq -0x1(%r15), %rax
movq %rax, 0x20(%rsp)
negq %r15
movq %r15, 0x28(%rsp)
movq 0x2dacd(%rip), %rcx     # 0x576f0
testq %rbx, %rbx
je 0x29c31
cmpq %rbx, %rcx
jne 0x29cc3
testq %rbx, %rbx
sete %bpl
xorl %edi, %edi
callq 0x10320
movq %rax, %r15
movq %rax, 0x2daa7(%rip)     # 0x576f0
cmpq %rbx, %rax
sete %al
orb %bpl, %al
cmpb $0x1, %al
jne 0x29cc3
movq 0x20(%rsp), %rax
leaq (%rax,%r15), %r13
andq 0x28(%rsp), %r13
cmpq %r15, %r13
jb 0x29cc3
leaq (%r14,%r13), %rbp
cmpq %r15, %rbp
jb 0x29cc3
leaq 0x2da2f(%rip), %rax     # 0x576a8
movq (%rax), %rdi
leaq 0x2da2d(%rip), %rax     # 0x576b0
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, 0x2da3b(%rip)     # 0x576e8
movq 0x2da3c(%rip), %rcx     # 0x576f0
cmpq %rcx, %rax
je 0x29ce4
cmpq $-0x1, %rax
jne 0x29c23
leaq 0x2d9f6(%rip), %rdi     # 0x576c0
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, 0x2da05(%rip)     # 0x576f0
leaq 0x2d9ce(%rip), %rdi     # 0x576c0
callq 0x10440
cmpq %r15, %r13
je 0x29d28
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rsi
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
andq $0x0, 0x30(%rsi)
pushq $0x1
popq %r8
movq 0x8(%rsp), %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x298f7
movq 0x10(%rsp), %rax
cmpb $0x1, (%rax)
movq 0x18(%rsp), %rbx
jne 0x29d50
leaq 0x2c946(%rip), %rax     # 0x56684
cmpb $0x1, (%rax)
je 0x29d6b
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x10270
cmpb $0x0, (%rbx)
jne 0x29cd2
movq %r13, %rdi
movq %r14, %rsi
callq 0x31434
movb %al, (%rbx)
jmp 0x29cd2
movq %r13, %rdi
movq %r14, %rsi
callq 0x38f6a
jmp 0x29d43