// File: /workspace/github_cpp_makefile_star2_O2/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_page_search_root
static int
mdb_page_search_root(MDB_cursor *mc, MDB_val *key, int flags)
{
	MDB_page	*mp = mc->mc_pg[mc->mc_top];
	int rc;
	DKBUF;

	while (IS_BRANCH(mp)) {
		MDB_node	*node;
		indx_t		i;

		DPRINTF(("branch page %"Z"u has %u keys", mp->mp_pgno, NUMKEYS(mp)));
		mdb_cassert(mc, NUMKEYS(mp) > 1);
		DPRINTF(("found index 0 to page %"Z"u", NODEPGNO(NODEPTR(mp, 0))));

		if (flags & (MDB_PS_FIRST|MDB_PS_LAST)) {
			i = 0;
			if (flags & MDB_PS_LAST)
				i = NUMKEYS(mp) - 1;
		} else {
			int	 exact;
			node = mdb_node_search(mc, key, &exact);
			if (node == NULL)
				i = NUMKEYS(mp) - 1;
			else {
				i = mc->mc_ki[mc->mc_top];
				if (!exact) {
					mdb_cassert(mc, i > 0);
					i--;
				}
			}
			DPRINTF(("following index %u for key [%s]", i, DKEY(key)));
		}

		mdb_cassert(mc, i < NUMKEYS(mp));
		node = NODEPTR(mp, i);

		if ((rc = mdb_page_get(mc->mc_txn, NODEPGNO(node), &mp, NULL)) != 0)
			return rc;

		mc->mc_ki[mc->mc_top] = i;
		if ((rc = mdb_cursor_push(mc, mp)))
			return rc;

		if (flags & MDB_PS_MODIFY) {
			if ((rc = mdb_page_touch(mc)) != 0)
				return rc;
			mp = mc->mc_pg[mc->mc_top];
		}
	}

	if (!IS_LEAF(mp)) {
		DPRINTF(("internal error, index points to a %02X page!?",
		    mp->mp_flags));
		mc->mc_txn->mt_flags |= MDB_TXN_ERROR;
		return MDB_CORRUPTED;
	}

	DPRINTF(("found leaf page %"Z"u for key [%s]", mp->mp_pgno,
	    key ? DKEY(key) : "null"));
	mc->mc_flags |= C_INITIALIZED;
	mc->mc_flags &= ~C_EOF;

	return MDB_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movzwl 0x42(%rdi), %eax
movq 0x48(%rdi,%rax,8), %r13
leaq 0x10(%rsp), %r15
movq %r13, (%r15)
movzwl 0xa(%r13), %eax
testb $0x1, %al
je 0x9d39
movzwl 0xc(%r13), %eax
movl %eax, %ecx
andl $-0x4, %ecx
cmpw $0x10, %cx
je 0x9d88
testb $0xc, %bpl
je 0x9c53
testb $0x8, %bpl
jne 0x9c87
xorl %r12d, %r12d
jmp 0x9cb1
movq %rbx, %rdi
movq %r14, %rsi
leaq 0xc(%rsp), %rdx
callq 0x9741
testq %rax, %rax
je 0x9c9a
movzwl 0x42(%rbx), %eax
movzwl 0x148(%rbx,%rax,2), %r12d
cmpl $0x0, 0xc(%rsp)
jne 0x9cac
testw %r12w, %r12w
jne 0x9ca9
jmp 0x9da8
movzwl %ax, %r12d
addl $0x1fff0, %r12d         # imm = 0x1FFF0
shrl %r12d
decl %r12d
jmp 0x9cb1
movzwl 0xc(%r13), %r12d
addl $0x1fff0, %r12d         # imm = 0x1FFF0
shrl %r12d
decl %r12d
movzwl 0xc(%r13), %eax
movzwl %r12w, %ecx
movzwl %ax, %eax
addl $-0x10, %eax
shrl %eax
cmpl %ecx, %eax
jbe 0x9d68
movzwl 0x10(%r13,%rcx,2), %eax
movq 0x18(%rbx), %rdi
movl (%r13,%rax), %ecx
movzwl 0x4(%r13,%rax), %esi
shlq $0x20, %rsi
orq %rcx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6fba
testl %eax, %eax
jne 0x9d59
movzwl 0x42(%rbx), %eax
movw %r12w, 0x148(%rbx,%rax,2)
movq 0x10(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x68b2
testl %eax, %eax
jne 0x9d59
testb $0x1, %bpl
je 0x9c21
movq %rbx, %rdi
callq 0x9908
testl %eax, %eax
jne 0x9d59
movzwl 0x42(%rbx), %eax
movq 0x48(%rbx,%rax,8), %r13
movq %r13, 0x10(%rsp)
jmp 0x9c21
testb $0x2, %al
jne 0x9d4c
movq 0x18(%rbx), %rax
orl $0x2, 0x7c(%rax)
movl $0xffff87b4, %eax       # imm = 0xFFFF87B4
jmp 0x9d59
movl 0x44(%rbx), %eax
andl $-0x4, %eax
incl %eax
movl %eax, 0x44(%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x4cc6(%rip), %rsi      # 0xea3d
leaq 0x4ca4(%rip), %rdx      # 0xea22
movl $0x14da, %ecx           # imm = 0x14DA
callq 0xb672
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x4c7b(%rip), %rsi      # 0xea12
leaq 0x4c84(%rip), %rdx      # 0xea22
movl $0x14c4, %ecx           # imm = 0x14C4
callq 0xb672
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x4c80(%rip), %rsi      # 0xea37
leaq 0x4c64(%rip), %rdx      # 0xea22
movl $0x14d3, %ecx           # imm = 0x14D3
callq 0xb672