// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/jemalloc.c
// Function: je_arena_choose_hard
arena_t *
arena_choose_hard(tsd_t *tsd, bool internal)
{
	arena_t *ret JEMALLOC_CC_SILENCE_INIT(NULL);

	if (narenas_auto > 1) {
		unsigned i, j, choose[2], first_null;

		/*
		 * Determine binding for both non-internal and internal
		 * allocation.
		 *
		 *   choose[0]: For application allocation.
		 *   choose[1]: For internal metadata allocation.
		 */

		for (j = 0; j < 2; j++)
			choose[j] = 0;

		first_null = narenas_auto;
		malloc_mutex_lock(tsd_tsdn(tsd), &arenas_lock);
		assert(arena_get(tsd_tsdn(tsd), 0, false) != NULL);
		for (i = 1; i < narenas_auto; i++) {
			if (arena_get(tsd_tsdn(tsd), i, false) != NULL) {
				/*
				 * Choose the first arena that has the lowest
				 * number of threads assigned to it.
				 */
				for (j = 0; j < 2; j++) {
					if (arena_nthreads_get(arena_get(
					    tsd_tsdn(tsd), i, false), !!j) <
					    arena_nthreads_get(arena_get(
					    tsd_tsdn(tsd), choose[j], false),
					    !!j))
						choose[j] = i;
				}
			} else if (first_null == narenas_auto) {
				/*
				 * Record the index of the first uninitialized
				 * arena, in case all extant arenas are in use.
				 *
				 * NB: It is possible for there to be
				 * discontinuities in terms of initialized
				 * versus uninitialized arenas, due to the
				 * "thread.arena" mallctl.
				 */
				first_null = i;
			}
		}

		for (j = 0; j < 2; j++) {
			if (arena_nthreads_get(arena_get(tsd_tsdn(tsd),
			    choose[j], false), !!j) == 0 || first_null ==
			    narenas_auto) {
				/*
				 * Use an unloaded arena, or the least loaded
				 * arena if all arenas are already initialized.
				 */
				if (!!j == internal) {
					ret = arena_get(tsd_tsdn(tsd),
					    choose[j], false);
				}
			} else {
				arena_t *arena;

				/* Initialize a new arena. */
				choose[j] = first_null;
				arena = arena_init_locked(tsd_tsdn(tsd),
				    choose[j]);
				if (arena == NULL) {
					malloc_mutex_unlock(tsd_tsdn(tsd),
					    &arenas_lock);
					return (NULL);
				}
				if (!!j == internal)
					ret = arena;
			}
			arena_bind(tsd, choose[j], !!j);
		}
		malloc_mutex_unlock(tsd_tsdn(tsd), &arenas_lock);
	} else {
		ret = arena_get(tsd_tsdn(tsd), 0, false);
		arena_bind(tsd, 0, false);
		arena_bind(tsd, 0, true);
	}

	return (ret);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x314b3(%rip), %ebp     # 0x4c598
cmpl $0x2, %ebp
jb 0x1b279
movl %esi, %r14d
movq $0x0, (%rsp)
leaq 0x31448(%rip), %rdi     # 0x4c548
callq 0xb5a0
cmpl $0x2, 0x3148c(%rip)     # 0x4c598
jb 0x1b1bd
movl $0x1, %r12d
movq 0x31491(%rip), %rax     # 0x4c5b0
cmpq $0x0, (%rax,%r12,8)
je 0x1b194
xorl %r13d, %r13d
movq 0x31480(%rip), %rax     # 0x4c5b0
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x1b180
xorl %esi, %esi
testq %r13, %r13
setne %sil
callq 0x23e62
movl %eax, %r15d
movl (%rsp,%r13,4), %eax
movq 0x3145b(%rip), %rcx     # 0x4c5b0
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x1b18a
xorl %esi, %esi
testq %r13, %r13
setne %sil
callq 0x23e62
cmpl %eax, %r15d
jae 0x1b175
movl %r12d, (%rsp,%r13,4)
incq %r13
cmpq $0x1, %r13
je 0x1b129
jmp 0x1b1ab
xorl %edi, %edi
lock
xaddq %rdi, (%rax,%r12,8)
jmp 0x1b139
xorl %edi, %edi
lock
xaddq %rdi, (%rcx,%rax,8)
jmp 0x1b15e
xorl %ecx, %ecx
lock
xaddq %rcx, (%rax,%r12,8)
testq %rcx, %rcx
jne 0x1b126
cmpl 0x313f1(%rip), %ebp     # 0x4c598
cmovel %r12d, %ebp
incq %r12
movl 0x313e4(%rip), %eax     # 0x4c598
cmpq %rax, %r12
jb 0x1b118
movzbl %r14b, %r13d
xorl %r15d, %r15d
xorl %r14d, %r14d
movl (%rsp,%r15,4), %r12d
movq 0x313de(%rip), %rax     # 0x4c5b0
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x1b26c
xorl %esi, %esi
testq %r15, %r15
setne %sil
callq 0x23e62
testl %eax, %eax
je 0x1b218
cmpl 0x313a1(%rip), %ebp     # 0x4c598
je 0x1b218
movl %ebp, (%rsp,%r15,4)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1aebb
movq %rax, %r12
testq %rax, %rax
je 0x1b238
cmpq %r15, %r13
cmoveq %r12, %r14
jmp 0x1b244
cmpq %r15, %r13
jne 0x1b249
movq 0x3138c(%rip), %rax     # 0x4c5b0
movq (%rax,%r12,8), %r14
testq %r14, %r14
jne 0x1b249
xorl %r14d, %r14d
lock
xaddq %r14, (%rax,%r12,8)
jmp 0x1b249
leaq 0x31309(%rip), %rdi     # 0x4c548
callq 0xb380
testq %r12, %r12
je 0x1b2b3
xorl %edx, %edx
testq %r15, %r15
setne %dl
movl (%rsp,%r15,4), %esi
movq %rbx, %rdi
callq 0x1b2d2
incq %r15
cmpq $0x1, %r15
je 0x1b1c7
jmp 0x1b2a5
xorl %edi, %edi
lock
xaddq %rdi, (%rax,%r12,8)
jmp 0x1b1df
movq 0x31330(%rip), %rax     # 0x4c5b0
movq (%rax), %r14
testq %r14, %r14
je 0x1b2c8
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1b2d2
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x1b2d2
jmp 0x1b2b6
leaq 0x3129c(%rip), %rdi     # 0x4c548
callq 0xb380
jmp 0x1b2b6
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
lock
xaddq %r14, (%rax)
jmp 0x1b288