// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/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:
testq %rdx, %rdx
js 0x414b9
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, %rbx
movq %rsi, %r13
movq %rdi, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x28(%rsp)
leaq 0x433aa(%rip), %rdi     # 0x846b0
callq 0x12960
cmpq $-0x1, 0x433c5(%rip)    # 0x846d8
je 0x414c9
leaq -0x1(%rbx), %rax
movq %rax, 0x30(%rsp)
negq %rbx
movq %rbx, 0x38(%rsp)
movl $0x8, %r12d
testq %r13, %r13
je 0x41342
cmpq %r13, 0x433a4(%rip)     # 0x846e0
jne 0x41497
testq %r13, %r13
sete %bpl
xorl %edi, %edi
callq 0x12460
movq %rax, %rbx
movq %rax, 0x43386(%rip)     # 0x846e0
cmpq %r13, %rax
sete %al
orb %bpl, %al
cmpb $0x1, %al
jne 0x41497
movq 0x30(%rsp), %rax
leaq (%rax,%rbx), %rbp
andq 0x38(%rsp), %rbp
movq 0x10(%rsp), %rdx
leaq (%rdx,%rbp), %r14
cmpq %rbx, %rbp
setae %al
cmpq %rbx, %r14
setae %cl
testb %cl, %al
jne 0x413b2
leaq 0x43317(%rip), %rdi     # 0x846b0
callq 0x125c0
movl $0x1, %r12d
movq $0x0, 0x8(%rsp)
jmp 0x41497
leaq 0x432df(%rip), %rax     # 0x84698
movq (%rax), %rdi
leaq 0x432dd(%rip), %rax     # 0x846a0
movq (%rax), %rax
movq %rax, %rcx
andq %rbx, %rcx
subq %rcx, %rdi
andq %rax, %rdi
addq %rdi, %rbx
movq %rbp, %r15
subq %rbx, %r15
addq %rdx, %rdi
addq %r15, %rdi
callq 0x12460
movq %rax, 0x432eb(%rip)     # 0x846d8
xorl %r12d, %r12d
cmpq 0x432e9(%rip), %rax     # 0x846e0
jne 0x41497
movq %r14, 0x432dc(%rip)     # 0x846e0
leaq 0x432a5(%rip), %rdi     # 0x846b0
callq 0x125c0
cmpq %rbx, %rbp
je 0x4144b
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movq %rbx, %rdx
movq %r15, %rcx
movl $0x1, %r8d
callq 0x4108f
movq 0x20(%rsp), %rax
cmpb $0x1, (%rax)
movq 0x28(%rsp), %rbx
jne 0x41478
leaq 0x42333(%rip), %rax     # 0x83794
cmpb $0x1, (%rax)
movq 0x10(%rsp), %r14
je 0x414ac
movq %rbp, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x12380
movl $0x1, %r12d
cmpb $0x0, (%rbx)
jne 0x41492
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
callq 0x48fb4
movb %al, (%rbx)
movq %rbp, 0x8(%rsp)
testl %r12d, %r12d
jne 0x414bc
cmpq $-0x1, 0x43234(%rip)    # 0x846d8
jne 0x4132a
jmp 0x414c9
movq %rbp, %rdi
movq %r14, %rsi
callq 0x507e2
jmp 0x4146b
xorl %eax, %eax
retq
cmpl $0x1, %r12d
jne 0x414c9
movq 0x8(%rsp), %rax
jmp 0x414d7
leaq 0x431e0(%rip), %rdi     # 0x846b0
callq 0x125c0
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq