// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/ctl.c
// Function: thread_arena_ctl
static int
thread_arena_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
    void *newp, size_t newlen)
{
	int ret;
	unsigned newind, oldind;

	malloc_mutex_lock(&ctl_mtx);
	newind = oldind = choose_arena(NULL)->ind;
	WRITE(newind, unsigned);
	READ(oldind, unsigned);
	if (newind != oldind) {
		arena_t *arena;

		if (newind >= ctl_stats.narenas) {
			/* New arena index is out of range. */
			ret = EFAULT;
			goto label_return;
		}

		/* Initialize arena if necessary. */
		malloc_mutex_lock(&arenas_lock);
		if ((arena = arenas[newind]) == NULL && (arena =
		    arenas_extend(newind)) == NULL) {
			malloc_mutex_unlock(&arenas_lock);
			ret = EAGAIN;
			goto label_return;
		}
		assert(arena == arenas[newind]);
		arenas[oldind]->nthreads--;
		arenas[newind]->nthreads++;
		malloc_mutex_unlock(&arenas_lock);

		/* Set new arena association. */
		if (config_tcache) {
			tcache_t *tcache;
			if ((uintptr_t)(tcache = *tcache_tsd_get()) >
			    (uintptr_t)TCACHE_STATE_MAX) {
				tcache_arena_dissociate(tcache);
				tcache_arena_associate(tcache, arena);
			}
		}
		arenas_tsd_set(&arena);
	}

	ret = 0;
label_return:
	malloc_mutex_unlock(&ctl_mtx);
	return (ret);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r13
movq %r8, %r12
movq %rcx, %r15
movq %rdx, %rbx
leaq 0x58eff(%rip), %rdi     # 0xdf980
callq 0x1faa0
movq 0x3f4ab(%rip), %rsi     # 0xc5f38
movq %fs:0x0, %rdx
addq %rsi, %rdx
movq %fs:(%rsi), %rax
testq %rax, %rax
jne 0x86ab9
movq %rbx, %rbp
movq %rdx, %rbx
movq %rsi, %r14
callq 0x7c4da
movq %r14, %rsi
movq %rbx, %rdx
movq %rbp, %rbx
movl (%rax), %r14d
movl %r14d, 0xc(%rsp)
movl %r14d, %ebp
testq %r12, %r12
je 0x86ae2
movq %rbx, %rax
movl $0x16, %ebx
cmpq $0x4, %r13
jne 0x86bfd
movl (%r12), %ebp
movq %rax, %rbx
testq %rbx, %rbx
sete %al
testq %r15, %r15
sete %cl
orb %al, %cl
jne 0x86b02
movq (%r15), %rax
cmpq $0x4, %rax
jne 0x86be2
movl %r14d, (%rbx)
cmpl %r14d, %ebp
jne 0x86b0e
xorl %ebx, %ebx
jmp 0x86bfd
movl $0xe, %ebx
cmpl 0x58ed7(%rip), %ebp     # 0xdf9f0
jae 0x86bfd
movq %rsi, %r13
movq %rdx, 0x10(%rsp)
leaq 0x5805a(%rip), %rdi     # 0xdeb88
callq 0x1faa0
leaq 0x5803e(%rip), %rbx     # 0xdeb78
movq (%rbx), %rax
movl %ebp, %r12d
movq (%rax,%r12,8), %rcx
movq %rcx, %r15
testq %rcx, %rcx
jne 0x86b66
movl %ebp, %edi
callq 0x7c478
testq %rax, %rax
je 0x86c1a
movq %rax, %r15
movq (%rbx), %rax
movq (%rax,%r12,8), %rcx
movq (%rax,%r14,8), %rax
decl 0x4(%rax)
incl 0x4(%rcx)
leaq 0x58011(%rip), %rdi     # 0xdeb88
callq 0x1fbb0
movq 0x3f3d5(%rip), %rax     # 0xc5f58
movq %fs:(%rax), %rbx
cmpq $0x4, %rbx
jb 0x86ba0
movq %rbx, %rdi
callq 0x90fe2
movq %rbx, %rdi
movq %r15, %rsi
callq 0x90f8d
movq %r15, %fs:(%r13)
leaq 0x58008(%rip), %rax     # 0xdebb4
movl (%rax), %edi
movq 0x10(%rsp), %rsi
callq 0x1f1c0
testl %eax, %eax
je 0x86b07
leaq 0x1c40b(%rip), %rdi     # 0xa2fd2
callq 0x915d4
leaq 0x57f87(%rip), %rax     # 0xdeb5a
cmpb $0x1, (%rax)
movl $0x0, %ebx
jne 0x86bfd
callq 0x1f1b0
movl $0x4, %edx
cmovbq %rax, %rdx
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0x1fbd0
movl $0x16, %ebx
leaq 0x58d7c(%rip), %rdi     # 0xdf980
callq 0x1fbb0
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x57f67(%rip), %rdi     # 0xdeb88
callq 0x1fbb0
movl $0xb, %ebx
jmp 0x86bfd