// File: /workspace/github_c_makefile_star2_O1/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 0x8bdfb
callq 0x8cfbd
movq %rax, %rbx
cmpq $0x3, %rbx
jae 0x8be08
xorl %eax, %eax
jmp 0x8bfdf
leaq 0x8(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x9357f
testb %al, %al
je 0x8beae
movb $0x1, 0x58(%rbx)
leaq 0x54cfb(%rip), %rdi     # 0xe0b28
callq 0x1faa0
leaq 0x53c5f(%rip), %rdi     # 0xdfa98
leaq 0x10(%rsp), %rdx
movq %rsp, %rcx
movq %r14, %rsi
callq 0x9357f
movl %eax, %ebp
testb %al, %al
je 0x8beef
movl $0x60, %edi
callq 0x8c241
movq %rax, (%rsp)
testq %rax, %rax
je 0x8c01b
movl 0x8(%r14), %eax
leaq 0x10(,%rax,8), %rdi
callq 0x8c241
testq %rax, %rax
je 0x8c054
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)
jmp 0x8c057
movq 0x30(%rbx), %rcx
movq 0x8(%rsp), %rax
cmpq %rax, %rcx
jne 0x8bec4
movq 0x10(%rcx), %rcx
movq %rcx, 0x30(%rbx)
cmpq %rax, 0x30(%rbx)
je 0x8bfb1
movq 0x10(%rax), %rcx
movq 0x18(%rax), %rdx
movq %rcx, 0x10(%rdx)
movq 0x10(%rax), %rcx
movq %rdx, 0x18(%rcx)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
jmp 0x8bfb9
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1faa0
movq (%rsp), %rax
incl 0x10(%rax)
movq 0x8(%rax), %rdi
callq 0x1fbb0
leaq 0x54c15(%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 0x8bf32
callq 0x8c8fb
testb %r14b, %r14b
je 0x8bf3c
callq 0x8cf3b
movq %rbx, %rdi
callq 0x92db8
cmpq $0x400, %rax            # imm = 0x400
jne 0x8bfea
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 0x932a3
movq 0x30(%rbx), %rax
movq 0x8(%rsp), %rsi
cmpq %rsi, %rax
jne 0x8bf86
movq 0x10(%rax), %rax
movq %rax, 0x30(%rbx)
cmpq %rsi, 0x30(%rbx)
je 0x8c139
movq 0x10(%rsi), %rax
movq 0x18(%rsi), %rcx
movq %rax, 0x10(%rcx)
movq 0x10(%rsi), %rax
movq %rcx, 0x18(%rax)
movq %rsi, 0x10(%rsi)
movq %rsi, 0x18(%rsi)
jmp 0x8c141
movq $0x0, 0x30(%rbx)
movq 0x30(%rbx), %rcx
testq %rcx, %rcx
je 0x8bfd6
movq 0x18(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq %rcx, 0x10(%rax)
movq %rax, 0x10(%rdx)
movq %rax, 0x18(%rcx)
movq %rax, 0x30(%rbx)
movq 0x8(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x50, %edi
callq 0x8c241
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x8c22a
movq %rax, (%rax)
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
jmp 0x8c14a
leaq 0x54b06(%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 0x8c041
callq 0x8c8fb
testb %bpl, %bpl
je 0x8be01
callq 0x8cf3b
jmp 0x8be01
xorl %r15d, %r15d
movq %r15, 0x10(%rsp)
testq %r15, %r15
je 0x8c103
movq (%rsp), %rax
movq %r15, (%rax)
movl $0x1, %eax
lock
xaddl %eax, 0x64af7(%rip)     # 0xf0b70
andl $0x3ff, %eax            # imm = 0x3FF
leaq (%rax,%rax,4), %rax
shll $0x3, %eax
addq 0x54ac4(%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 0x539de(%rip), %rdi     # 0xdfa98
callq 0x92e39
testb %al, %al
je 0x8bf0c
leaq 0x54a5a(%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 0x8c0ed
callq 0x8c8fb
testb %bpl, %bpl
je 0x8c0f7
callq 0x8cf3b
movq 0x10(%rsp), %rdi
callq 0x8c4ba
jmp 0x8c133
leaq 0x54a1e(%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 0x8c129
callq 0x8c8fb
testb %bpl, %bpl
je 0x8c133
callq 0x8cf3b
movq (%rsp), %rdi
jmp 0x8c18d
movq $0x0, 0x30(%rbx)
movq 0x20(%rsi), %rdi
callq 0x8c763
movq (%rsp), %rax
movq 0x8(%rsp), %rdx
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 0x92e39
testb %al, %al
je 0x8c197
testb %bpl, %bpl
je 0x8c188
movq (%rsp), %rdi
callq 0x8c813
movq 0x8(%rsp), %rdi
callq 0x8c4ba
jmp 0x8be01
movq 0x30(%rbx), %rax
testq %rax, %rax
je 0x8c1b9
movq 0x18(%rax), %rcx
movq 0x8(%rsp), %rdx
movq %rcx, 0x18(%rdx)
movq %rax, 0x10(%rdx)
movq %rdx, 0x10(%rcx)
movq %rdx, 0x18(%rax)
movq 0x8(%rsp), %rax
movq %rax, 0x30(%rbx)
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1faa0
movq (%rsp), %rax
movq 0x58(%rax), %rax
testq %rax, %rax
je 0x8c209
movq 0x8(%rax), %rcx
movq 0x8(%rsp), %rdx
movq %rcx, 0x8(%rdx)
movq %rax, (%rdx)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rax, (%rcx)
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq 0x58(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rsp), %rcx
movq %rax, 0x58(%rcx)
decl 0x10(%rcx)
movq 0x8(%rcx), %rdi
callq 0x1fbb0
jmp 0x8bfda
testb %bpl, %bpl
je 0x8be01
movq (%rsp), %rdi
callq 0x8c813
jmp 0x8be01