// File: /workspace/github_cpp_makefile_star2_O3/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_page_search
static int
mdb_page_search(MDB_cursor *mc, MDB_val *key, int flags)
{
	int		 rc;
	pgno_t		 root;

	/* Make sure the txn is still viable, then find the root from
	 * the txn's db table and set it as the root of the cursor's stack.
	 */
	if (mc->mc_txn->mt_flags & MDB_TXN_BLOCKED) {
		DPUTS("transaction may not be used now");
		return MDB_BAD_TXN;
	} else {
		/* Make sure we're using an up-to-date root */
		if (*mc->mc_dbflag & DB_STALE) {
				MDB_cursor mc2;
				if (TXN_DBI_CHANGED(mc->mc_txn, mc->mc_dbi))
					return MDB_BAD_DBI;
				mdb_cursor_init(&mc2, mc->mc_txn, MAIN_DBI, NULL);
				rc = mdb_page_search(&mc2, &mc->mc_dbx->md_name, 0);
				if (rc)
					return rc;
				{
					MDB_val data;
					int exact = 0;
					uint16_t flags;
					MDB_node *leaf = mdb_node_search(&mc2,
						&mc->mc_dbx->md_name, &exact);
					if (!exact)
						return MDB_NOTFOUND;
					if ((leaf->mn_flags & (F_DUPDATA|F_SUBDATA)) != F_SUBDATA)
						return MDB_INCOMPATIBLE; /* not a named DB */
					rc = mdb_node_read(mc->mc_txn, leaf, &data);
					if (rc)
						return rc;
					memcpy(&flags, ((char *) data.mv_data + offsetof(MDB_db, md_flags)),
						sizeof(uint16_t));
					/* The txn may not know this DBI, or another process may
					 * have dropped and recreated the DB with other flags.
					 */
					if ((mc->mc_db->md_flags & PERSISTENT_FLAGS) != flags)
						return MDB_INCOMPATIBLE;
					memcpy(mc->mc_db, data.mv_data, sizeof(MDB_db));
				}
				*mc->mc_dbflag &= ~DB_STALE;
		}
		root = mc->mc_db->md_root;

		if (root == P_INVALID) {		/* Tree is empty. */
			DPUTS("tree is empty");
			return MDB_NOTFOUND;
		}
	}

	mdb_cassert(mc, root > 1);
	if (!mc->mc_pg[0] || mc->mc_pg[0]->mp_pgno != root)
		if ((rc = mdb_page_get(mc->mc_txn, root, &mc->mc_pg[0], NULL)) != 0)
			return rc;

	mc->mc_snum = 1;
	mc->mc_top = 0;

	DPRINTF(("db %d root page %"Z"u has flags 0x%X",
		DDBI(mc), root, mc->mc_pg[0]->mp_flags));

	if (flags & MDB_PS_MODIFY) {
		if ((rc = mdb_page_touch(mc)))
			return rc;
	}

	if (flags & MDB_PS_ROOTONLY)
		return MDB_SUCCESS;

	return mdb_page_search_root(mc, key, flags);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, %r14
movq 0x18(%rdi), %rsi
movl $0xffff87c2, %eax       # imm = 0xFFFF87C2
testb $0x13, 0x7c(%rsi)
je 0x9d57
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl %edx, %ebx
movq %rdi, %r15
movq 0x38(%rdi), %rax
testb $0x2, (%rax)
jne 0x9dd4
movq 0x28(%r15), %rax
movq 0x28(%rax), %rsi
cmpq $-0x1, %rsi
je 0x9eba
cmpq $0x1, %rsi
jbe 0x9ec4
movq 0x48(%r15), %rax
testq %rax, %rax
je 0x9d8f
cmpq %rsi, (%rax)
je 0x9da2
leaq 0x48(%r15), %rdx
movq 0x18(%r15), %rdi
xorl %ecx, %ecx
callq 0x74c4
testl %eax, %eax
jne 0x9d48
movl $0x1, 0x40(%r15)
testb $0x1, %bl
je 0x9dbb
movq %r15, %rdi
callq 0xa0ec
testl %eax, %eax
jne 0x9d48
xorl %eax, %eax
testb $0x2, %bl
jne 0x9d48
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0xa404
jmp 0x9d48
movq 0x20(%rsi), %rax
movq 0x60(%rsi), %rcx
movl 0x20(%r15), %edx
movl (%rcx,%rdx,4), %ecx
movq 0x98(%rax), %rdi
movl $0xffff87c4, %eax       # imm = 0xFFFF87C4
cmpl (%rdi,%rdx,4), %ecx
jne 0x9d48
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x40be
movq 0x30(%r15), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x9d28
testl %eax, %eax
jne 0x9d48
leaq 0xc(%rsp), %r12
movl $0x0, (%r12)
movq 0x30(%r15), %rsi
leaq 0x20(%rsp), %rdi
movq %r12, %rdx
callq 0x9ee4
cmpl $0x0, (%r12)
je 0x9eba
movq %rax, %rsi
movzwl 0x4(%rax), %ecx
andl $0x6, %ecx
movl $0xffff87c0, %eax       # imm = 0xFFFF87C0
cmpw $0x2, %cx
jne 0x9d48
movq 0x18(%r15), %rdi
leaq 0x10(%rsp), %rdx
callq 0x645b
testl %eax, %eax
jne 0x9d48
movq 0x18(%rsp), %rdx
movq 0x28(%r15), %rcx
movzwl 0x4(%rcx), %esi
andl $0x7fff, %esi           # imm = 0x7FFF
movl $0xffff87c0, %eax       # imm = 0xFFFF87C0
cmpw 0x4(%rdx), %si
jne 0x9d48
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movups %xmm2, 0x20(%rcx)
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0x38(%r15), %rax
andb $-0x3, (%rax)
jmp 0x9d65
movl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jmp 0x9d48
movq 0x18(%r15), %rax
movq 0x20(%rax), %rdi
leaq 0x5b00(%rip), %rsi      # 0xf9d3
leaq 0x5b02(%rip), %rdx      # 0xf9dc
movl $0x1551, %ecx           # imm = 0x1551
callq 0xbfbd