// File: /workspace/github_c_makefile_star2_O3/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
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl 0x3166a(%rip), %eax     # 0x4c598
cmpl $0x2, %eax
jb 0x1b033
movl %esi, %ebx
movl %eax, 0xc(%rsp)
xorl %eax, %eax
movl %eax, 0x10(%rsp)
movl %eax, 0x14(%rsp)
leaq 0x315fa(%rip), %rdi     # 0x4c548
callq 0xb5a0
cmpl $0x2, 0x3163e(%rip)     # 0x4c598
movl %ebx, 0x18(%rsp)
jb 0x1b06b
movl $0x1, %r13d
leaq 0x14(%rsp), %r14
movq 0x3163a(%rip), %rax     # 0x4c5b0
cmpq $0x0, (%rax,%r13,8)
je 0x1b00c
movb $0x1, %bl
xorl %eax, %eax
leaq 0x10(%rsp), %rbp
movq 0x3161f(%rip), %rcx     # 0x4c5b0
movq (%rcx,%r13,8), %rdi
testq %rdi, %rdi
je 0x1afe2
movzbl %al, %r15d
andl $0x1, %r15d
movl %r15d, %esi
callq 0x23d7b
movl %eax, %r12d
movl (%rbp), %eax
movq 0x315f9(%rip), %rcx     # 0x4c5b0
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x1afec
movl %r15d, %esi
callq 0x23d7b
cmpl %eax, %r12d
jae 0x1afd1
movl %r13d, (%rbp)
movb $0x1, %al
movq %r14, %rbp
testb $0x1, %bl
movl $0x0, %ebx
jne 0x1af8a
jmp 0x1aff6
xorl %edi, %edi
lock
xaddq %rdi, (%rcx,%r13,8)
jmp 0x1af9a
xorl %edi, %edi
lock
xaddq %rdi, (%rcx,%rax,8)
jmp 0x1afc0
movl 0x3159c(%rip), %eax     # 0x4c598
incq %r13
movl %eax, %eax
cmpq %rax, %r13
jb 0x1af6f
jmp 0x1b06b
xorl %ecx, %ecx
lock
xaddq %rcx, (%rax,%r13,8)
testq %rcx, %rcx
jne 0x1af81
movl 0x31575(%rip), %eax     # 0x4c598
movl 0xc(%rsp), %ecx
cmpl %eax, %ecx
cmovel %r13d, %ecx
movl %ecx, 0xc(%rsp)
jmp 0x1affc
movq 0x31576(%rip), %rax     # 0x4c5b0
movq (%rax), %r14
testq %r14, %r14
je 0x1b15b
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1b168
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x1b168
jmp 0x1b149
leaq 0x10(%rsp), %rbp
movzbl 0x18(%rsp), %eax
movq %rax, 0x18(%rsp)
movb $0x1, %bl
xorl %eax, %eax
xorl %r13d, %r13d
xorl %r14d, %r14d
movl (%rbp), %r15d
movq 0x31521(%rip), %rcx     # 0x4c5b0
movq (%rcx,%r15,8), %rdi
testq %rdi, %rdi
je 0x1b122
movzbl %al, %r12d
andl $0x1, %r12d
movl %r12d, %esi
callq 0x23d7b
testl %eax, %eax
movl 0xc(%rsp), %esi
je 0x1b0de
cmpl 0x314de(%rip), %esi     # 0x4c598
je 0x1b0de
movl %esi, (%rbp)
movq 0x20(%rsp), %rdi
movl %esi, %ebp
callq 0x1ad00
testq %rax, %rax
je 0x1b13a
cmpq 0x18(%rsp), %r13
cmoveq %rax, %r14
movl %ebp, %r15d
jmp 0x1b0f5
cmpq 0x18(%rsp), %r13
jne 0x1b0f5
movq 0x314c4(%rip), %rax     # 0x4c5b0
movq (%rax,%r15,8), %r14
testq %r14, %r14
je 0x1b12f
movq 0x20(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1b168
movl $0x1, %r13d
movb $0x1, %al
leaq 0x14(%rsp), %rbp
testb $0x1, %bl
movl $0x0, %ebx
jne 0x1b084
jmp 0x1b13d
xorl %edi, %edi
lock
xaddq %rdi, (%rcx,%r15,8)
jmp 0x1b09c
xorl %r14d, %r14d
lock
xaddq %r14, (%rax,%r15,8)
jmp 0x1b0f5
xorl %r14d, %r14d
leaq 0x31404(%rip), %rdi     # 0x4c548
callq 0xb380
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
lock
xaddq %r14, (%rax)
jmp 0x1b046