// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, %r14
movq 0x18(%rdi), %rsi
movl $0xffff87c2, %ebp       # imm = 0xFFFF87C2
testb $0x13, 0x7c(%rsi)
je 0xa149
movl %ebp, %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, %ebx
movq %rdi, %r15
movq 0x38(%rdi), %rax
testb $0x2, (%rax)
je 0xa1b0
movq 0x20(%rsi), %rax
movq 0x60(%rsi), %rcx
movl 0x20(%r15), %edx
movl (%rcx,%rdx,4), %ecx
movq 0x98(%rax), %rax
cmpl (%rax,%rdx,4), %ecx
jne 0xa1a3
xorl %r13d, %r13d
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4177
movq 0x30(%r15), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0xa112
testl %eax, %eax
je 0xa22b
movl %eax, %ebp
jmp 0xa1ab
movl $0xffff87c4, %ebp       # imm = 0xFFFF87C4
xorl %r13d, %r13d
testb %r13b, %r13b
je 0xa135
movq 0x28(%r15), %rax
movq 0x28(%rax), %rsi
cmpq $-0x1, %rsi
je 0xa221
cmpq $0x1, %rsi
jbe 0xa2ce
movq 0x48(%r15), %rax
testq %rax, %rax
je 0xa1d6
cmpq %rsi, (%rax)
je 0xa1e9
leaq 0x48(%r15), %rdx
movq 0x18(%r15), %rdi
xorl %ecx, %ecx
callq 0x789a
testl %eax, %eax
jne 0xa21a
movl $0x1, 0x40(%r15)
testb $0x1, %bl
je 0xa202
movq %r15, %rdi
callq 0xa4f1
testl %eax, %eax
jne 0xa21a
xorl %ebp, %ebp
testb $0x2, %bl
jne 0xa135
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0xa809
movl %eax, %ebp
jmp 0xa135
movl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
jmp 0xa135
leaq 0xc(%rsp), %r12
movl $0x0, (%r12)
movq 0x30(%r15), %rsi
leaq 0x20(%rsp), %rdi
movq %r12, %rdx
callq 0xa2ee
cmpl $0x0, (%r12)
je 0xa27d
movzwl 0x4(%rax), %ecx
andl $0x6, %ecx
movl $0xffff87c0, %ebp       # imm = 0xFFFF87C0
cmpw $0x2, %cx
jne 0xa282
movq 0x18(%r15), %rdi
leaq 0x10(%rsp), %rdx
movq %rax, %rsi
callq 0x6780
testl %eax, %eax
je 0xa29b
xorl %ecx, %ecx
movl %eax, %ebp
jmp 0xa284
movl $0xffff87b2, %ebp       # imm = 0xFFFF87B2
xorl %ecx, %ecx
testb %cl, %cl
je 0xa1a8
movq 0x38(%r15), %rax
andb $-0x3, (%rax)
movb $0x1, %r13b
jmp 0xa1ab
movq 0x18(%rsp), %rcx
movq 0x28(%r15), %rax
movzwl 0x4(%rax), %edx
andl $0x7fff, %edx           # imm = 0x7FFF
cmpw 0x4(%rcx), %dx
jne 0xa282
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movb $0x1, %cl
jmp 0xa284
movq 0x18(%r15), %rax
movq 0x20(%rax), %rdi
leaq 0x56b6(%rip), %rsi      # 0xf993
leaq 0x56b8(%rip), %rdx      # 0xf99c
movl $0x1551, %ecx           # imm = 0x1551
callq 0xc43e