// File: /workspace/github_c_makefile_star2_O0/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/chunk_dss.c
// Function: je_chunk_alloc_dss
void *
chunk_alloc_dss(tsdn_t *tsdn, 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);

	if (!atomic_read_u(&dss_exhausted)) {
		/*
		 * The loop is necessary to recover from races with other
		 * threads that are using the DSS for something other than
		 * malloc.
		 */
		while (true) {
			void *ret, *cpad, *max_cur, *dss_next, *dss_prev;
			size_t gap_size, cpad_size;
			intptr_t incr;

			max_cur = chunk_dss_max_update(new_addr);
			if (max_cur == NULL)
				goto label_oom;

			/*
			 * 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)
				goto label_oom; /* Wrap-around. */
			incr = gap_size + cpad_size + size;

			/*
			 * Optimistically update dss_max, and roll back below if
			 * sbrk() fails.  No other thread will try to extend the
			 * DSS while dss_max is greater than the current DSS
			 * max reported by sbrk(0).
			 */
			if (atomic_cas_p(&dss_max, max_cur, dss_next))
				continue;

			/* Try to allocate. */
			dss_prev = chunk_dss_sbrk(incr);
			if (dss_prev == max_cur) {
				/* Success. */
				if (cpad_size != 0) {
					chunk_hooks_t chunk_hooks =
					    CHUNK_HOOKS_INITIALIZER;
					chunk_dalloc_wrapper(tsdn, arena,
					    &chunk_hooks, cpad, cpad_size,
					    arena_extent_sn_next(arena), false,
					    true);
				}
				if (*zero) {
					JEMALLOC_VALGRIND_MAKE_MEM_UNDEFINED(
					    ret, size);
					memset(ret, 0, size);
				}
				if (!*commit)
					*commit = pages_decommit(ret, size);
				return (ret);
			}

			/*
			 * Failure, whether due to OOM or a race with a raw
			 * sbrk() call from outside the allocator.  Try to roll
			 * back optimistic dss_max update; if rollback fails,
			 * it's due to another caller of this function having
			 * succeeded since this invocation started, in which
			 * case rollback is not necessary.
			 */
			atomic_cas_p(&dss_max, dss_next, max_cur);
			if (dss_prev == (void *)-1) {
				/* OOM. */
				atomic_write_u(&dss_exhausted, (unsigned)true);
				goto label_oom;
			}
		}
	}
label_oom:
	return (NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
jmp 0x53519
jmp 0x5351b
jmp 0x5351d
jmp 0x5351f
jmp 0x53521
cmpq $0x0, -0x28(%rbp)
jge 0x53535
movq $0x0, -0x8(%rbp)
jmp 0x53791
leaq 0x50b84(%rip), %rdi     # 0xa40c0
xorl %esi, %esi
callq 0x53460
cmpl $0x0, %eax
jne 0x53787
jmp 0x5354e
movq -0x20(%rbp), %rdi
callq 0x537a0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x53567
jmp 0x53789
leaq 0x50b3a(%rip), %rax     # 0xa40a8
movq (%rax), %rax
movq 0x50b50(%rip), %rcx     # 0xa40c8
leaq 0x50b31(%rip), %rdx     # 0xa40b0
andq (%rdx), %rcx
subq %rcx, %rax
leaq 0x50b24(%rip), %rcx     # 0xa40b0
andq (%rcx), %rax
movq %rax, -0x68(%rbp)
movq 0x50b2e(%rip), %rax     # 0xa40c8
addq -0x68(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x50b1f(%rip), %rax     # 0xa40c8
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
xorq $-0x1, %rcx
addq $0x1, %rcx
andq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq 0x50adb(%rip), %rcx     # 0xa40c8
cmpq %rcx, %rax
jb 0x53602
movq -0x58(%rbp), %rax
movq 0x50acb(%rip), %rcx     # 0xa40c8
cmpq %rcx, %rax
jae 0x53607
jmp 0x53789
movq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq 0x50aa2(%rip), %rdi     # 0xa40c8
callq 0x53840
testb $0x1, %al
jne 0x53631
jmp 0x53636
jmp 0x5354e
movq -0x78(%rbp), %rdi
callq 0x53870
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x5374e
cmpq $0x0, -0x70(%rbp)
je 0x536e0
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0xb210
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x43560
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rcx
movq -0xb8(%rbp), %r8
movq %rax, %r9
leaq -0xb0(%rbp), %rdx
xorl %eax, %eax
movl $0x0, (%rsp)
movl $0x1, 0x8(%rsp)
callq 0x52a50
movq -0x38(%rbp), %rax
testb $0x1, (%rax)
je 0x53723
jmp 0x536eb
leaq 0x4fe8a(%rip), %rax     # 0xa357c
movb (%rax), %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x53712
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x86000
jmp 0x53714
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rdx
xorl %esi, %esi
callq 0xb210
movq 0x10(%rbp), %rax
testb $0x1, (%rax)
jne 0x53744
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x671d0
movb %al, %cl
movq 0x10(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x53791
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
leaq 0x5096b(%rip), %rdi     # 0xa40c8
callq 0x53840
movq $-0x1, %rax
cmpq %rax, -0x60(%rbp)
jne 0x53782
leaq 0x5094a(%rip), %rdi     # 0xa40c0
movl $0x1, %esi
callq 0x534c0
jmp 0x53789
jmp 0x5354e
jmp 0x53789
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nop