// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/deps/jemalloc/src/prof.c
// Function: prof_lookup
prof_thr_cnt_t *
prof_lookup(prof_bt_t *bt)
{
	union {
		prof_thr_cnt_t	*p;
		void		*v;
	} ret;
	prof_tdata_t *prof_tdata;

	cassert(config_prof);

	prof_tdata = prof_tdata_get();
	if ((uintptr_t)prof_tdata <= (uintptr_t)PROF_TDATA_STATE_MAX)
		return (NULL);

	if (ckh_search(&prof_tdata->bt2cnt, bt, NULL, &ret.v)) {
		union {
			prof_bt_t	*p;
			void		*v;
		} btkey;
		union {
			prof_ctx_t	*p;
			void		*v;
		} ctx;
		bool new_ctx;

		/*
		 * This thread's cache lacks bt.  Look for it in the global
		 * cache.
		 */
		prof_enter(prof_tdata);
		if (ckh_search(&bt2ctx, bt, &btkey.v, &ctx.v)) {
			/* bt has never been seen before.  Insert it. */
			ctx.v = imalloc(sizeof(prof_ctx_t));
			if (ctx.v == NULL) {
				prof_leave(prof_tdata);
				return (NULL);
			}
			btkey.p = bt_dup(bt);
			if (btkey.v == NULL) {
				prof_leave(prof_tdata);
				idalloc(ctx.v);
				return (NULL);
			}
			ctx.p->bt = btkey.p;
			ctx.p->lock = prof_ctx_mutex_choose();
			/*
			 * Set nlimbo to 1, in order to avoid a race condition
			 * with prof_ctx_merge()/prof_ctx_destroy().
			 */
			ctx.p->nlimbo = 1;
			memset(&ctx.p->cnt_merged, 0, sizeof(prof_cnt_t));
			ql_new(&ctx.p->cnts_ql);
			if (ckh_insert(&bt2ctx, btkey.v, ctx.v)) {
				/* OOM. */
				prof_leave(prof_tdata);
				idalloc(btkey.v);
				idalloc(ctx.v);
				return (NULL);
			}
			new_ctx = true;
		} else {
			/*
			 * Increment nlimbo, in order to avoid a race condition
			 * with prof_ctx_merge()/prof_ctx_destroy().
			 */
			malloc_mutex_lock(ctx.p->lock);
			ctx.p->nlimbo++;
			malloc_mutex_unlock(ctx.p->lock);
			new_ctx = false;
		}
		prof_leave(prof_tdata);

		/* Link a prof_thd_cnt_t into ctx for this thread. */
		if (ckh_count(&prof_tdata->bt2cnt) == PROF_TCMAX) {
			assert(ckh_count(&prof_tdata->bt2cnt) > 0);
			/*
			 * Flush the least recently used cnt in order to keep
			 * bt2cnt from becoming too large.
			 */
			ret.p = ql_last(&prof_tdata->lru_ql, lru_link);
			assert(ret.v != NULL);
			if (ckh_remove(&prof_tdata->bt2cnt, ret.p->ctx->bt,
			    NULL, NULL))
				assert(false);
			ql_remove(&prof_tdata->lru_ql, ret.p, lru_link);
			prof_ctx_merge(ret.p->ctx, ret.p);
			/* ret can now be re-used. */
		} else {
			assert(ckh_count(&prof_tdata->bt2cnt) < PROF_TCMAX);
			/* Allocate and partially initialize a new cnt. */
			ret.v = imalloc(sizeof(prof_thr_cnt_t));
			if (ret.p == NULL) {
				if (new_ctx)
					prof_ctx_destroy(ctx.p);
				return (NULL);
			}
			ql_elm_new(ret.p, cnts_link);
			ql_elm_new(ret.p, lru_link);
		}
		/* Finish initializing ret. */
		ret.p->ctx = ctx.p;
		ret.p->epoch = 0;
		memset(&ret.p->cnts, 0, sizeof(prof_cnt_t));
		if (ckh_insert(&prof_tdata->bt2cnt, btkey.v, ret.v)) {
			if (new_ctx)
				prof_ctx_destroy(ctx.p);
			idalloc(ret.v);
			return (NULL);
		}
		ql_head_insert(&prof_tdata->lru_ql, ret.p, lru_link);
		malloc_mutex_lock(ctx.p->lock);
		ql_tail_insert(&ctx.p->cnts_ql, ret.p, cnts_link);
		ctx.p->nlimbo--;
		malloc_mutex_unlock(ctx.p->lock);
	} else {
		/* Move ret to the front of the LRU. */
		ql_remove(&prof_tdata->lru_ql, ret.p, lru_link);
		ql_head_insert(&prof_tdata->lru_ql, ret.p, lru_link);
	}

	return (ret.p);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq %fs:-0x18, %rbx
testq %rbx, %rbx
jne 0x8c07b
callq 0x8d204
movq %rax, %rbx
cmpq $0x3, %rbx
jae 0x8c088
xorl %eax, %eax
jmp 0x8c21b
leaq 0x8(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x93940
testb %al, %al
je 0x8c1cf
movb $0x1, 0x58(%rbx)
leaq 0x54a7b(%rip), %rdi     # 0xe0b28
callq 0x1faa0
leaq 0x539df(%rip), %rdi     # 0xdfa98
leaq 0x10(%rsp), %rdx
movq %rsp, %rcx
movq %r14, %rsi
callq 0x93940
movl %eax, %ebp
testb %al, %al
je 0x8c226
movl $0x60, %edi
callq 0x8c482
movq %rax, (%rsp)
testq %rax, %rax
je 0x8c310
movl 0x8(%r14), %eax
leaq 0x10(,%rax,8), %rdi
callq 0x8c482
testq %rax, %rax
je 0x8c349
movq %rax, %r15
movq %rax, %rdi
addq $0x10, %rdi
movq %rdi, (%rax)
movq (%r14), %rsi
movl 0x8(%r14), %edx
shlq $0x3, %rdx
callq 0x1fbd0
movl 0x8(%r14), %eax
movl %eax, 0x8(%r15)
movq %r15, 0x10(%rsp)
movq (%rsp), %rax
movq %r15, (%rax)
movl $0x1, %eax
lock
xaddl %eax, 0x64a2e(%rip)     # 0xf0b70
andl $0x3ff, %eax            # imm = 0x3FF
leaq (%rax,%rax,4), %rax
shll $0x3, %eax
addq 0x549fb(%rip), %rax     # 0xe0b50
movq (%rsp), %rdx
movq %rax, 0x8(%rdx)
movl $0x1, 0x10(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rdx)
movups %xmm0, 0x48(%rdx)
movq $0x0, 0x58(%rdx)
movq 0x10(%rsp), %rsi
leaq 0x53915(%rip), %rdi     # 0xdfa98
callq 0x93246
testb %al, %al
je 0x8c243
leaq 0x54991(%rip), %rdi     # 0xe0b28
callq 0x1fbb0
movb $0x0, 0x58(%rbx)
movb 0x59(%rbx), %al
movb 0x5a(%rbx), %bpl
movw $0x0, 0x59(%rbx)
cmpb $0x1, %al
jne 0x8c1b6
callq 0x8cb7b
testb %bpl, %bpl
je 0x8c1c0
callq 0x8d182
movq 0x10(%rsp), %rdi
callq 0x8c711
jmp 0x8c382
movq 0x30(%rbx), %rcx
movq 0x8(%rsp), %rax
cmpq %rax, %rcx
jne 0x8c1e1
movq 0x10(%rcx), %rcx
cmpq %rax, %rcx
je 0x8c217
movq 0x10(%rax), %rdx
movq 0x18(%rax), %rsi
movq %rdx, 0x10(%rsi)
movq %rsi, 0x18(%rdx)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
testq %rcx, %rcx
je 0x8c217
movq 0x18(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq %rcx, 0x10(%rax)
movq %rax, 0x10(%rdx)
movq %rax, 0x18(%rcx)
movq %rax, 0x30(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1faa0
movq (%rsp), %rax
incl 0x10(%rax)
movq 0x8(%rax), %rdi
callq 0x1fbb0
leaq 0x548de(%rip), %rdi     # 0xe0b28
callq 0x1fbb0
movb $0x0, 0x58(%rbx)
movb 0x59(%rbx), %al
movb 0x5a(%rbx), %r14b
movw $0x0, 0x59(%rbx)
cmpb $0x1, %al
jne 0x8c269
callq 0x8cb7b
testb %r14b, %r14b
je 0x8c273
callq 0x8d182
movq %rbx, %rdi
callq 0x931db
cmpq $0x400, %rax            # imm = 0x400
jne 0x8c2df
movq 0x30(%rbx), %rax
movq 0x18(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rax), %rax
movq (%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x936a4
movq 0x30(%rbx), %rax
movq 0x8(%rsp), %rsi
cmpq %rsi, %rax
jne 0x8c2b9
movq 0x10(%rax), %rax
movq %rax, 0x30(%rbx)
cmpq %rsi, %rax
je 0x8c388
movq 0x10(%rsi), %rax
movq 0x18(%rsi), %rcx
movq %rax, 0x10(%rcx)
movq %rcx, 0x18(%rax)
movq %rsi, 0x10(%rsi)
movq %rsi, 0x18(%rsi)
jmp 0x8c390
movl $0x50, %edi
callq 0x8c482
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x8c46b
movq %rax, (%rax)
movq 0x8(%rsp), %rdx
movq %rdx, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
jmp 0x8c39e
leaq 0x54811(%rip), %rdi     # 0xe0b28
callq 0x1fbb0
movb $0x0, 0x58(%rbx)
movb 0x59(%rbx), %al
movb 0x5a(%rbx), %bpl
movw $0x0, 0x59(%rbx)
cmpb $0x1, %al
jne 0x8c336
callq 0x8cb7b
testb %bpl, %bpl
je 0x8c081
callq 0x8d182
jmp 0x8c081
movq $0x0, 0x10(%rsp)
leaq 0x547cf(%rip), %rdi     # 0xe0b28
callq 0x1fbb0
movb $0x0, 0x58(%rbx)
movb 0x59(%rbx), %al
movb 0x5a(%rbx), %bpl
movw $0x0, 0x59(%rbx)
cmpb $0x1, %al
jne 0x8c378
callq 0x8cb7b
testb %bpl, %bpl
je 0x8c382
callq 0x8d182
movq (%rsp), %rdi
jmp 0x8c3dc
movq $0x0, 0x30(%rbx)
movq 0x20(%rsi), %rdi
callq 0x8c9cc
movq 0x8(%rsp), %rdx
movq (%rsp), %rax
movq %rax, 0x20(%rdx)
movl $0x0, 0x28(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rdx)
movups %xmm0, 0x40(%rdx)
movq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x93246
testb %al, %al
je 0x8c3e6
testb %bpl, %bpl
je 0x8c3d7
movq (%rsp), %rdi
callq 0x8ca93
movq 0x8(%rsp), %rdi
callq 0x8c711
jmp 0x8c081
movq 0x30(%rbx), %rax
movq 0x8(%rsp), %rcx
testq %rax, %rax
je 0x8c408
movq 0x18(%rax), %rdx
movq %rdx, 0x18(%rcx)
movq %rax, 0x10(%rcx)
movq %rcx, 0x10(%rdx)
movq %rcx, 0x18(%rax)
movq %rcx, 0x30(%rbx)
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1faa0
movq (%rsp), %rcx
movq 0x58(%rcx), %rdx
movq 0x8(%rsp), %rax
testq %rdx, %rdx
je 0x8c44e
movq 0x8(%rdx), %rcx
movq %rcx, 0x8(%rax)
movq %rdx, (%rax)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rax, (%rcx)
movq (%rsp), %rcx
movq 0x58(%rcx), %rdx
movq %rax, 0x8(%rdx)
movq (%rax), %rax
movq %rax, 0x58(%rcx)
decl 0x10(%rcx)
movq 0x8(%rcx), %rdi
callq 0x1fbb0
movq 0x8(%rsp), %rax
jmp 0x8c21b
testb %bpl, %bpl
je 0x8c081
movq (%rsp), %rdi
callq 0x8ca93
jmp 0x8c081