// File: /workspace/github_cpp_makefile_star2_O3/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_cursor_next
static int
mdb_cursor_next(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
{
	MDB_page	*mp;
	MDB_node	*leaf;
	int rc;

	if (mc->mc_flags & C_EOF) {
		return MDB_NOTFOUND;
	}

	mdb_cassert(mc, mc->mc_flags & C_INITIALIZED);

	mp = mc->mc_pg[mc->mc_top];

	if (mc->mc_db->md_flags & MDB_DUPSORT) {
		leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);
		if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
			if (op == MDB_NEXT || op == MDB_NEXT_DUP) {
				rc = mdb_cursor_next(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_NEXT);
				if (op != MDB_NEXT || rc != MDB_NOTFOUND) {
					if (rc == MDB_SUCCESS)
						MDB_GET_KEY(leaf, key);
					return rc;
				}
			}
		} else {
			mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF);
			if (op == MDB_NEXT_DUP)
				return MDB_NOTFOUND;
		}
	}

	DPRINTF(("cursor_next: top page is %"Z"u in cursor %p",
		mdb_dbg_pgno(mp), (void *) mc));
	if (mc->mc_flags & C_DEL)
		goto skip;

	if (mc->mc_ki[mc->mc_top] + 1u >= NUMKEYS(mp)) {
		DPUTS("=====> move to next sibling page");
		if ((rc = mdb_cursor_sibling(mc, 1)) != MDB_SUCCESS) {
			mc->mc_flags |= C_EOF;
			return rc;
		}
		mp = mc->mc_pg[mc->mc_top];
		DPRINTF(("next page is %"Z"u, key index %u", mp->mp_pgno, mc->mc_ki[mc->mc_top]));
	} else
		mc->mc_ki[mc->mc_top]++;

skip:
	DPRINTF(("==> cursor points to page %"Z"u with %u keys, key index %u",
	    mdb_dbg_pgno(mp), NUMKEYS(mp), mc->mc_ki[mc->mc_top]));

	if (IS_LEAF2(mp)) {
		key->mv_size = mc->mc_db->md_pad;
		key->mv_data = LEAF2KEY(mp, mc->mc_ki[mc->mc_top], key->mv_size);
		return MDB_SUCCESS;
	}

	mdb_cassert(mc, IS_LEAF(mp));
	leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);

	if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
		mdb_xcursor_init1(mc, leaf);
	}
	if (data) {
		if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS)
			return rc;

		if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
			rc = mdb_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
			if (rc != MDB_SUCCESS)
				return rc;
		}
	}

	MDB_GET_KEY(leaf, key);
	return MDB_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movl 0x44(%rdi), %ecx
movl $0xffff87b2, %eax       # imm = 0xFFFF87B2
testb $0x2, %cl
jne 0x6799
movq %rdi, %r14
testb $0x1, %cl
je 0x67a8
movq %rdx, %r15
movq %rsi, %rbx
movzwl 0x42(%r14), %ecx
movq 0x48(%r14,%rcx,8), %r13
movq 0x28(%r14), %rdx
testb $0x4, 0x4(%rdx)
jne 0x663f
testb $0x8, 0x44(%r14)
jne 0x66e8
movzwl 0x42(%r14), %eax
movzwl 0x148(%r14,%rax,2), %ecx
leal 0x1(%rcx), %edx
movzwl 0xc(%r13), %esi
addl $-0x10, %esi
shrl %esi
cmpl %esi, %edx
jae 0x66c3
incl %ecx
movw %cx, 0x148(%r14,%rax,2)
jmp 0x66e8
movzwl 0x148(%r14,%rcx,2), %ecx
movzwl 0x10(%r13,%rcx,2), %r12d
testb $0x4, 0x4(%r13,%r12)
jne 0x6668
movq 0x10(%r14), %rcx
andl $-0x4, 0x44(%rcx)
cmpl $0x9, %ebp
jne 0x6601
jmp 0x6799
movl %ebp, %eax
andl $-0x2, %eax
cmpl $0x8, %eax
jne 0x6601
movq 0x10(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0x8, %ecx
callq 0x65bd
xorl $0x8, %ebp
movl %eax, %ecx
xorl $0xffff87b2, %ecx       # imm = 0xFFFF87B2
orl %ebp, %ecx
je 0x6601
testl %eax, %eax
setne %cl
testq %rbx, %rbx
sete %dl
orb %cl, %dl
jne 0x6799
addq %r12, %r13
movzwl 0x6(%r13), %eax
movq %rax, (%rbx)
addq $0x8, %r13
movq %r13, 0x8(%rbx)
jmp 0x6797
movq %r14, %rdi
movl $0x1, %esi
callq 0xa6a4
testl %eax, %eax
je 0x66de
orb $0x2, 0x44(%r14)
jmp 0x6799
movzwl 0x42(%r14), %eax
movq 0x48(%r14,%rax,8), %r13
movzwl 0xa(%r13), %eax
testb $0x20, %al
jne 0x6770
testb $0x2, %al
je 0x67c8
movzwl 0x42(%r14), %eax
movzwl 0x148(%r14,%rax,2), %eax
movzwl 0x10(%r13,%rax,2), %eax
leaq (%rax,%r13), %r12
testb $0x4, 0x4(%r13,%rax)
je 0x6724
movq %r14, %rdi
movq %r12, %rsi
callq 0x633e
testq %r15, %r15
je 0x6756
movq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x645b
testl %eax, %eax
jne 0x6799
testb $0x4, 0x4(%r12)
je 0x6756
movq 0x10(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x64a4
testl %eax, %eax
jne 0x6799
xorl %eax, %eax
testq %rbx, %rbx
je 0x6799
movzwl 0x6(%r12), %ecx
movq %rcx, (%rbx)
addq $0x8, %r12
movq %r12, 0x8(%rbx)
jmp 0x6799
movq 0x28(%r14), %rax
movl (%rax), %eax
movq %rax, (%rbx)
movzwl 0x42(%r14), %ecx
movzwl 0x148(%r14,%rcx,2), %ecx
imulq %rax, %rcx
leaq (%rcx,%r13), %rax
addq $0x10, %rax
movq %rax, 0x8(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x9345(%rip), %rsi      # 0xfafc
leaq 0x935b(%rip), %rdx      # 0xfb19
movl $0x162c, %ecx           # imm = 0x162C
callq 0xbfbd
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x92a6(%rip), %rsi      # 0xfa7d
leaq 0x933b(%rip), %rdx      # 0xfb19
movl $0x165c, %ecx           # imm = 0x165C
callq 0xbfbd