// File: /workspace/github_cpp_makefile_star2_O1/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 0x6e1b
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %rbx
movzwl 0x42(%r14), %eax
movq 0x48(%r14,%rax,8), %r13
movq 0x28(%r14), %rcx
testb $0x4, 0x4(%rcx)
jne 0x6d31
movzwl 0x42(%r14), %eax
movzwl 0x148(%r14,%rax,2), %ecx
testw %cx, %cx
je 0x6d8b
decl %ecx
movw %cx, 0x148(%r14,%rax,2)
andb $-0x3, 0x44(%r14)
movzwl 0xa(%r13), %eax
testb $0x20, %al
jne 0x6d60
testb $0x2, %al
je 0x6e3b
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 0x6cdd
movq %r14, %rdi
movq %r12, %rsi
callq 0x6663
testq %r15, %r15
je 0x6d17
movq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x6780
testl %eax, %eax
jne 0x6d99
testb $0x4, 0x4(%r12)
je 0x6d17
movq 0x10(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x6b13
testl %eax, %eax
jne 0x6d99
xorl %eax, %eax
testq %rbx, %rbx
je 0x6d99
movzwl 0x6(%r12), %ecx
movq %rcx, (%rbx)
addq $0x8, %r12
movq %r12, 0x8(%rbx)
jmp 0x6d99
movzwl 0x148(%r14,%rax,2), %eax
movzwl 0x10(%r13,%rax,2), %r12d
testb $0x4, 0x4(%r13,%r12)
jne 0x6da8
movq 0x10(%r14), %rax
andl $-0x4, 0x44(%rax)
movl $0xffff87b2, %eax       # imm = 0xFFFF87B2
cmpl $0xd, %ebp
jne 0x6c76
jmp 0x6d99
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
jmp 0x6d99
movq %r14, %rdi
xorl %esi, %esi
callq 0xaab8
testl %eax, %eax
je 0x6dff
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 0x6c76
movq 0x10(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0xc, %ecx
callq 0x6c3e
xorl $0xc, %ebp
movl %eax, %ecx
xorl $0xffff87b2, %ecx       # imm = 0xFFFF87B2
orl %ebp, %ecx
je 0x6c76
testl %eax, %eax
jne 0x6d99
testq %rbx, %rbx
je 0x6df8
addq %r12, %r13
movzwl 0x6(%r13), %ecx
movq %rcx, (%rbx)
addq $0x8, %r13
movq %r13, 0x8(%rbx)
andb $-0x3, 0x44(%r14)
jmp 0x6d99
movzwl 0x42(%r14), %eax
movq 0x48(%r14,%rax,8), %r13
movzwl 0xc(%r13), %ecx
addl $0x1fff0, %ecx          # imm = 0x1FFF0
shrl %ecx
jmp 0x6c8d
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x8c92(%rip), %rsi      # 0xfabc
leaq 0x8cc8(%rip), %rdx      # 0xfaf9
movl $0x1679, %ecx           # imm = 0x1679
callq 0xc43e
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x8bf3(%rip), %rsi      # 0xfa3d
leaq 0x8ca8(%rip), %rdx      # 0xfaf9
movl $0x16aa, %ecx           # imm = 0x16AA
callq 0xc43e