// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rdi, %rbx
movzwl 0x42(%rdi), %eax
movq 0x48(%rdi,%rax,8), %rax
movq %rsp, %r15
movq %rax, (%r15)
movq (%rsp), %r12
movzwl 0xa(%r12), %eax
testb $0x1, %al
je 0xa985
movzwl 0xc(%r12), %eax
andl $-0x4, %eax
cmpw $0x10, %ax
je 0xa9d4
testb $0xc, %bpl
je 0xa866
testb $0x8, %bpl
jne 0xa89c
xorl %r14d, %r14d
jmp 0xa8af
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rdx
callq 0xa2ee
testq %rax, %rax
je 0xa89c
movzwl 0x42(%rbx), %eax
movzwl 0x148(%rbx,%rax,2), %r14d
cmpl $0x0, 0xc(%rsp)
jne 0xa8af
testw %r14w, %r14w
jne 0xa8ac
jmp 0xa9f4
movzwl 0xc(%r12), %r14d
addl $0x1fff0, %r14d         # imm = 0x1FFF0
shrl %r14d
decl %r14d
movzwl %r14w, %eax
movzwl 0xc(%r12), %ecx
addl $-0x10, %ecx
shrl %ecx
cmpl %eax, %ecx
jbe 0xa9b4
movzwl 0x10(%r12,%rax,2), %eax
movq 0x18(%rbx), %rdi
movl (%r12,%rax), %ecx
movzwl 0x4(%r12,%rax), %esi
shlq $0x20, %rsi
orq %rcx, %rsi
xorl %r12d, %r12d
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x789a
testl %eax, %eax
jne 0xa977
movzwl 0x42(%rbx), %eax
movw %r14w, 0x148(%rbx,%rax,2)
movzwl 0x40(%rbx), %ecx
cmpq $0x20, %rcx
jb 0xa91c
movq 0x18(%rbx), %rax
orl $0x2, 0x7c(%rax)
movl $0xffff87bd, %eax       # imm = 0xFFFF87BD
jmp 0xa93d
movq (%rsp), %rax
leal 0x1(%rcx), %edx
movw %dx, 0x40(%rbx)
movw %cx, 0x42(%rbx)
movq %rax, 0x48(%rbx,%rcx,8)
movw $0x0, 0x148(%rbx,%rcx,2)
movl %r13d, %eax
cmpw $0x20, %cx
setb %r12b
setae %cl
testb $0x1, %bpl
sete %dl
orb %cl, %dl
jne 0xa977
movq %rbx, %rdi
callq 0xa4f1
testl %eax, %eax
je 0xa964
xorl %r12d, %r12d
jmp 0xa977
movzwl 0x42(%rbx), %eax
movq 0x48(%rbx,%rax,8), %rax
movq %rax, (%rsp)
movb $0x1, %r12b
movl %r13d, %eax
movl %eax, %r13d
testb %r12b, %r12b
jne 0xa830
jmp 0xa9a5
testb $0x2, %al
jne 0xa998
movq 0x18(%rbx), %rax
orl $0x2, 0x7c(%rax)
movl $0xffff87b4, %eax       # imm = 0xFFFF87B4
jmp 0xa9a5
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 0x505a(%rip), %rsi      # 0xfa1d
leaq 0x5038(%rip), %rdx      # 0xfa02
movl $0x14da, %ecx           # imm = 0x14DA
callq 0xc43e
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x500f(%rip), %rsi      # 0xf9f2
leaq 0x5018(%rip), %rdx      # 0xfa02
movl $0x14c4, %ecx           # imm = 0x14C4
callq 0xc43e
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x5014(%rip), %rsi      # 0xfa17
leaq 0x4ff8(%rip), %rdx      # 0xfa02
movl $0x14d3, %ecx           # imm = 0x14D3
callq 0xc43e