// File: /workspace/github_c_makefile_star2_O2/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
callq 0x82f5a
cmpq $0x3, %rax
jae 0x82c24
xorl %eax, %eax
jmp 0x82d84
movq %rax, %rbx
leaq 0x8(%rsp), %rcx
movq %rax, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x89513
testb %al, %al
je 0x82d34
movq %rbx, %rdi
callq 0x82f6d
leaq 0x59e48(%rip), %rdi     # 0xdca98
leaq 0x10(%rsp), %rdx
movq %rsp, %rcx
movq %r14, %rsi
callq 0x89513
movl %eax, %ebp
testb %al, %al
je 0x82d8f
pushq $0x60
popq %rdi
callq 0x82f7d
movq %rax, (%rsp)
testq %rax, %rax
je 0x82e45
movl 0x8(%r14), %eax
leaq 0x10(,%rax,8), %rdi
callq 0x82f7d
testq %rax, %rax
je 0x82e52
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)
pushq $0x1
popq %rax
lock
xaddl %eax, 0x6ae9b(%rip)     # 0xedb70
andl $0x3ff, %eax            # imm = 0x3FF
imulq $0x28, %rax, %rax
addq 0x5ae6b(%rip), %rax     # 0xddb50
movq (%rsp), %rdx
movq %rax, 0x8(%rdx)
movl $0x1, 0x10(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rdx)
movups %xmm0, 0x48(%rdx)
andq $0x0, 0x58(%rdx)
movq 0x10(%rsp), %rsi
leaq 0x59d88(%rip), %rdi     # 0xdca98
callq 0x8918a
testb %al, %al
je 0x82dac
movq %rbx, %rdi
callq 0x83145
movq 0x10(%rsp), %rdi
callq 0x83183
jmp 0x82e60
movq 0x30(%rbx), %rcx
movq 0x8(%rsp), %rax
cmpq %rax, %rcx
jne 0x82d4a
movq 0x10(%rcx), %rcx
movq %rcx, 0x30(%rbx)
cmpq %rax, %rcx
je 0x82d80
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 0x82d80
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
movq %rbx, %rdi
callq 0x83145
movq %rbx, %rdi
callq 0x8912b
cmpq $0x400, %rax            # imm = 0x400
jne 0x82e19
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 0x893a9
movq 0x30(%rbx), %rax
movq 0x8(%rsp), %rsi
cmpq %rsi, %rax
jne 0x82dfa
movq 0x10(%rax), %rax
movq %rax, 0x30(%rbx)
cmpq %rsi, %rax
je 0x82e66
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 0x82e6b
pushq $0x50
popq %rdi
callq 0x82f7d
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x82f43
movq %rax, (%rax)
movq 0x8(%rsp), %rdx
movq %rdx, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
jmp 0x82e79
movq %rbx, %rdi
callq 0x83145
jmp 0x82c1d
andq $0x0, 0x10(%rsp)
movq %rbx, %rdi
callq 0x83145
movq (%rsp), %rdi
jmp 0x82eb4
andq $0x0, 0x30(%rbx)
movq 0x20(%rsi), %rdi
callq 0x83360
movq 0x8(%rsp), %rdx
movq (%rsp), %rax
movq %rax, 0x20(%rdx)
andl $0x0, 0x28(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rdx)
movups %xmm0, 0x40(%rdx)
movq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x8918a
testb %al, %al
je 0x82ebe
testb %bpl, %bpl
je 0x82eaf
movq (%rsp), %rdi
callq 0x83424
movq 0x8(%rsp), %rdi
callq 0x83183
jmp 0x82c1d
movq 0x30(%rbx), %rax
movq 0x8(%rsp), %rcx
testq %rax, %rax
je 0x82ee0
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 0x82f26
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 0x82d84
testb %bpl, %bpl
je 0x82c1d
movq (%rsp), %rdi
callq 0x83424
jmp 0x82c1d