// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdi, %rbx
movzwl 0x42(%rdi), %eax
movq 0x48(%rdi,%rax,8), %r13
movq %r13, 0x8(%rsp)
movzwl 0xa(%r13), %eax
testb $0x1, %al
je 0xa562
movl %edx, %ebp
movq %rsi, %r14
leaq 0x8(%rsp), %r12
movzwl 0xc(%r13), %eax
movl %eax, %ecx
andl $-0x4, %ecx
cmpw $0x10, %cx
je 0xa5a0
testb $0xc, %bpl
je 0xa45f
testb $0x8, %bpl
jne 0xa493
xorl %r15d, %r15d
jmp 0xa4bd
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x14(%rsp), %rdx
callq 0x9ee4
testq %rax, %rax
je 0xa4a6
movzwl 0x42(%rbx), %eax
movzwl 0x148(%rbx,%rax,2), %r15d
cmpl $0x0, 0x14(%rsp)
jne 0xa4b8
testw %r15w, %r15w
jne 0xa4b5
jmp 0xa5e0
movzwl %ax, %r15d
addl $0x1fff0, %r15d         # imm = 0x1FFF0
shrl %r15d
decl %r15d
jmp 0xa4bd
movzwl 0xc(%r13), %r15d
addl $0x1fff0, %r15d         # imm = 0x1FFF0
shrl %r15d
decl %r15d
movzwl 0xc(%r13), %eax
movzwl %r15w, %ecx
movzwl %ax, %eax
addl $-0x10, %eax
shrl %eax
cmpl %ecx, %eax
jbe 0xa5c0
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 %r12, %rdx
xorl %ecx, %ecx
callq 0x74c4
testl %eax, %eax
jne 0xa591
movzwl 0x42(%rbx), %eax
movw %r15w, 0x148(%rbx,%rax,2)
movzwl 0x40(%rbx), %eax
cmpq $0x20, %rax
jae 0xa584
leal 0x1(%rax), %ecx
movq 0x8(%rsp), %r13
movw %cx, 0x40(%rbx)
movw %ax, 0x42(%rbx)
movq %r13, 0x48(%rbx,%rax,8)
movw $0x0, 0x148(%rbx,%rax,2)
testb $0x1, %bpl
je 0xa555
movq %rbx, %rdi
callq 0xa0ec
testl %eax, %eax
jne 0xa591
movzwl 0x42(%rbx), %eax
movq 0x48(%rbx,%rax,8), %r13
movq %r13, 0x8(%rsp)
movzwl 0xa(%r13), %eax
testb $0x1, %al
jne 0xa43a
testb $0x2, %al
jne 0xa575
movq 0x18(%rbx), %rax
orl $0x2, 0x7c(%rax)
movl $0xffff87b4, %eax       # imm = 0xFFFF87B4
jmp 0xa591
movl 0x44(%rbx), %eax
andl $-0x4, %eax
incl %eax
movl %eax, 0x44(%rbx)
xorl %eax, %eax
jmp 0xa591
movq 0x18(%rbx), %rax
orl $0x2, 0x7c(%rax)
movl $0xffff87bd, %eax       # imm = 0xFFFF87BD
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 0x5483(%rip), %rsi      # 0xfa32
leaq 0x548c(%rip), %rdx      # 0xfa42
movl $0x14c4, %ecx           # imm = 0x14C4
callq 0xbfbd
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x548e(%rip), %rsi      # 0xfa5d
leaq 0x546c(%rip), %rdx      # 0xfa42
movl $0x14da, %ecx           # imm = 0x14DA
callq 0xbfbd
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x5468(%rip), %rsi      # 0xfa57
leaq 0x544c(%rip), %rdx      # 0xfa42
movl $0x14d3, %ecx           # imm = 0x14D3
callq 0xbfbd