// File: /workspace/github_c_makefile_star2_O2/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 0x3585f(%rip), %ebp     # 0x48598
cmpl $0x2, %ebp
jb 0x12e04
movl %esi, %r14d
andq $0x0, (%rsp)
leaq 0x357f7(%rip), %rdi     # 0x48548
callq 0xb5a0
pushq $0x1
popq %r12
movl 0x35838(%rip), %eax     # 0x48598
cmpq %rax, %r12
jae 0x12e35
movq 0x35840(%rip), %rax     # 0x485b0
cmpq $0x0, (%rax,%r12,8)
je 0x12de5
xorl %r13d, %r13d
cmpq $0x2, %r13
je 0x12dfc
movq 0x35829(%rip), %rax     # 0x485b0
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x12dd1
xorl %esi, %esi
testq %r13, %r13
setne %sil
callq 0x1e112
movl %eax, %r15d
movl (%rsp,%r13,4), %eax
movq 0x35804(%rip), %rcx     # 0x485b0
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x12ddb
xorl %esi, %esi
testq %r13, %r13
setne %sil
callq 0x1e112
cmpl %eax, %r15d
jae 0x12dcc
movl %r12d, (%rsp,%r13,4)
incq %r13
jmp 0x12d7a
xorl %edi, %edi
lock
xaddq %rdi, (%rax,%r12,8)
jmp 0x12d90
xorl %edi, %edi
lock
xaddq %rdi, (%rcx,%rax,8)
jmp 0x12db5
xorl %ecx, %ecx
lock
xaddq %rcx, (%rax,%r12,8)
testq %rcx, %rcx
jne 0x12d77
cmpl 0x357a0(%rip), %ebp     # 0x48598
cmovel %r12d, %ebp
incq %r12
jmp 0x12d5a
movq 0x357a5(%rip), %rax     # 0x485b0
movq (%rax), %r14
testq %r14, %r14
je 0x12efc
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x12f09
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x12f09
jmp 0x12eea
movzbl %r14b, %r12d
xorl %r13d, %r13d
xorl %r14d, %r14d
cmpq $0x2, %r13
je 0x12ede
movl (%rsp,%r13,4), %r15d
movq 0x3575c(%rip), %rax     # 0x485b0
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x12ec6
xorl %esi, %esi
testq %r13, %r13
setne %sil
callq 0x1e112
testl %eax, %eax
je 0x12e96
cmpl 0x35723(%rip), %ebp     # 0x48598
je 0x12e96
movl %ebp, (%rsp,%r13,4)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x12b2c
testq %rax, %rax
je 0x12edb
cmpq %r13, %r12
cmoveq %rax, %r14
movl %ebp, %r15d
jmp 0x12eab
cmpq %r13, %r12
jne 0x12eab
movq 0x3570e(%rip), %rax     # 0x485b0
movq (%rax,%r15,8), %r14
testq %r14, %r14
je 0x12ed0
xorl %edx, %edx
testq %r13, %r13
setne %dl
movq %rbx, %rdi
movl %r15d, %esi
callq 0x12f09
incq %r13
jmp 0x12e3f
xorl %edi, %edi
lock
xaddq %rdi, (%rax,%r15,8)
jmp 0x12e5d
xorl %r14d, %r14d
lock
xaddq %r14, (%rax,%r15,8)
jmp 0x12eab
xorl %r14d, %r14d
leaq 0x35663(%rip), %rdi     # 0x48548
callq 0xb380
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 0x12e17