// File: /workspace/github_cpp_makefile_star2_O2/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 0x661e
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 0x653d
movzwl 0x148(%r14,%rcx,2), %eax
testw %ax, %ax
je 0x658b
decl %eax
movw %ax, 0x148(%r14,%rcx,2)
andb $-0x3, 0x44(%r14)
movzwl 0xa(%r13), %ecx
testb $0x20, %cl
jne 0x656c
testb $0x2, %cl
je 0x663e
movzwl %ax, %eax
movzwl 0x10(%r13,%rax,2), %eax
leaq (%rax,%r13), %r12
testb $0x4, 0x4(%r13,%rax)
je 0x64ed
movq %r14, %rdi
movq %r12, %rsi
callq 0x5e86
testq %r15, %r15
je 0x6523
movq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x5f9f
testl %eax, %eax
jne 0x6599
testb $0x4, 0x4(%r12)
je 0x6523
movq 0x10(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x6325
testl %eax, %eax
jne 0x6599
xorl %eax, %eax
testq %rbx, %rbx
je 0x6599
movzwl 0x6(%r12), %ecx
movq %rcx, (%rbx)
addq $0x8, %r12
movq %r12, 0x8(%rbx)
jmp 0x6599
movzwl 0x148(%r14,%rcx,2), %eax
movzwl 0x10(%r13,%rax,2), %r12d
testb $0x4, 0x4(%r13,%r12)
jne 0x65a8
movq 0x10(%r14), %rax
andl $-0x4, 0x44(%rax)
movl $0xffff87b2, %eax       # imm = 0xFFFF87B2
cmpl $0xd, %ebp
jne 0x6494
jmp 0x6599
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 0x6599
movq %r14, %rdi
xorl %esi, %esi
callq 0x9e6c
testl %eax, %eax
je 0x65f9
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 0x6494
movq 0x10(%r14), %rdi
pushq $0xc
popq %rcx
movq %r15, %rsi
xorl %edx, %edx
callq 0x645c
xorl $0xc, %ebp
movl %eax, %ecx
xorl $0xffff87b2, %ecx       # imm = 0xFFFF87B2
orl %ebp, %ecx
je 0x6614
testl %eax, %eax
jne 0x6599
testq %rbx, %rbx
je 0x65f2
addq %r12, %r13
movzwl 0x6(%r13), %eax
movq %rax, (%rbx)
addq $0x8, %r13
movq %r13, 0x8(%rbx)
andb $-0x3, 0x44(%r14)
jmp 0x6587
movzwl 0x42(%r14), %ecx
movq 0x48(%r14,%rcx,8), %r13
movzwl 0xc(%r13), %eax
addl $0x1fff0, %eax          # imm = 0x1FFF0
shrl %eax
jmp 0x64a6
movzwl 0x42(%r14), %ecx
jmp 0x6494
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x84af(%rip), %rsi      # 0xeadc
leaq 0x84e5(%rip), %rdx      # 0xeb19
movl $0x1679, %ecx           # imm = 0x1679
callq 0xb672
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x8410(%rip), %rsi      # 0xea5d
leaq 0x84c5(%rip), %rdx      # 0xeb19
movl $0x16aa, %ecx           # imm = 0x16AA
callq 0xb672