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

	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_PREV || op == MDB_PREV_DUP) {
				rc = mdb_cursor_prev(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_PREV);
				if (op != MDB_PREV || rc != MDB_NOTFOUND) {
					if (rc == MDB_SUCCESS) {
						MDB_GET_KEY(leaf, key);
						mc->mc_flags &= ~C_EOF;
					}
					return rc;
				}
			}
		} else {
			mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF);
			if (op == MDB_PREV_DUP)
				return MDB_NOTFOUND;
		}
	}

	DPRINTF(("cursor_prev: top page is %"Z"u in cursor %p",
		mdb_dbg_pgno(mp), (void *) mc));

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

	mc->mc_flags &= ~C_EOF;

	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_last(&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
movq %rdi, %r14
testb $0x1, 0x44(%rdi)
je 0x6ae5
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %rbx
movzwl 0x42(%r14), %ecx
movq 0x48(%r14,%rcx,8), %r13
movq 0x28(%r14), %rax
testb $0x4, 0x4(%rax)
jne 0x6a02
movzwl 0x148(%r14,%rcx,2), %eax
testw %ax, %ax
je 0x6a50
decl %eax
movw %ax, 0x148(%r14,%rcx,2)
andb $-0x3, 0x44(%r14)
movzwl 0xa(%r13), %ecx
testb $0x20, %cl
jne 0x6a31
testb $0x2, %cl
je 0x6b05
movzwl %ax, %eax
movzwl 0x10(%r13,%rax,2), %eax
leaq (%rax,%r13), %r12
testb $0x4, 0x4(%r13,%rax)
je 0x69b2
movq %r14, %rdi
movq %r12, %rsi
callq 0x633e
testq %r15, %r15
je 0x69e8
movq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x645b
testl %eax, %eax
jne 0x6a5e
testb $0x4, 0x4(%r12)
je 0x69e8
movq 0x10(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x67e8
testl %eax, %eax
jne 0x6a5e
xorl %eax, %eax
testq %rbx, %rbx
je 0x6a5e
movzwl 0x6(%r12), %ecx
movq %rcx, (%rbx)
addq $0x8, %r12
movq %r12, 0x8(%rbx)
jmp 0x6a5e
movzwl 0x148(%r14,%rcx,2), %eax
movzwl 0x10(%r13,%rax,2), %r12d
testb $0x4, 0x4(%r13,%r12)
jne 0x6a6d
movq 0x10(%r14), %rax
andl $-0x4, 0x44(%rax)
movl $0xffff87b2, %eax       # imm = 0xFFFF87B2
cmpl $0xd, %ebp
jne 0x6959
jmp 0x6a5e
movq 0x28(%r14), %rcx
movl (%rcx), %ecx
movq %rcx, (%rbx)
movzwl %ax, %eax
imulq %rcx, %rax
addq %r13, %rax
addq $0x10, %rax
movq %rax, 0x8(%rbx)
xorl %eax, %eax
jmp 0x6a5e
movq %r14, %rdi
xorl %esi, %esi
callq 0xa6a4
testl %eax, %eax
je 0x6ac0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %eax
andl $-0x2, %eax
cmpl $0xc, %eax
jne 0x6959
movq 0x10(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0xc, %ecx
callq 0x6921
xorl $0xc, %ebp
movl %eax, %ecx
xorl $0xffff87b2, %ecx       # imm = 0xFFFF87B2
orl %ebp, %ecx
je 0x6adb
testl %eax, %eax
jne 0x6a5e
testq %rbx, %rbx
je 0x6ab9
addq %r12, %r13
movzwl 0x6(%r13), %eax
movq %rax, (%rbx)
addq $0x8, %r13
movq %r13, 0x8(%rbx)
andb $-0x3, 0x44(%r14)
jmp 0x6a4c
movzwl 0x42(%r14), %ecx
movq 0x48(%r14,%rcx,8), %r13
movzwl 0xc(%r13), %eax
addl $0x1fff0, %eax          # imm = 0x1FFF0
shrl %eax
jmp 0x696b
movzwl 0x42(%r14), %ecx
jmp 0x6959
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x9008(%rip), %rsi      # 0xfafc
leaq 0x903e(%rip), %rdx      # 0xfb39
movl $0x1679, %ecx           # imm = 0x1679
callq 0xbfbd
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x8f69(%rip), %rsi      # 0xfa7d
leaq 0x901e(%rip), %rdx      # 0xfb39
movl $0x16aa, %ecx           # imm = 0x16AA
callq 0xbfbd