// File: /workspace/github_cpp_makefile_star2_O2/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_pages_xkeep
static int
mdb_pages_xkeep(MDB_cursor *mc, unsigned pflags, int all)
{
	enum { Mask = P_SUBP|P_DIRTY|P_LOOSE|P_KEEP };
	MDB_txn *txn = mc->mc_txn;
	MDB_cursor *m3;
	MDB_xcursor *mx;
	MDB_page *dp, *mp;
	MDB_node *leaf;
	unsigned i, j;
	int rc = MDB_SUCCESS, level;

	/* Mark pages seen by cursors */
	if (mc->mc_flags & C_UNTRACK)
		mc = NULL;				/* will find mc in mt_cursors */
	for (i = txn->mt_numdbs;; mc = txn->mt_cursors[--i]) {
		for (; mc; mc=mc->mc_next) {
			if (!(mc->mc_flags & C_INITIALIZED))
				continue;
			for (m3 = mc;; m3 = &mx->mx_cursor) {
				mp = NULL;
				for (j=0; j<m3->mc_snum; j++) {
					mp = m3->mc_pg[j];
					if ((mp->mp_flags & Mask) == pflags)
						mp->mp_flags ^= P_KEEP;
				}
				mx = m3->mc_xcursor;
				/* Proceed to mx if it is at a sub-database */
				if (! (mx && (mx->mx_cursor.mc_flags & C_INITIALIZED)))
					break;
				if (! (mp && (mp->mp_flags & P_LEAF)))
					break;
				leaf = NODEPTR(mp, m3->mc_ki[j-1]);
				if (!(leaf->mn_flags & F_SUBDATA))
					break;
			}
		}
		if (i == 0)
			break;
	}

	if (all) {
		/* Mark dirty root pages */
		for (i=0; i<txn->mt_numdbs; i++) {
			if (txn->mt_dbflags[i] & DB_DIRTY) {
				pgno_t pgno = txn->mt_dbs[i].md_root;
				if (pgno == P_INVALID)
					continue;
				if ((rc = mdb_page_get(txn, pgno, &dp, &level)) != MDB_SUCCESS)
					break;
				if ((dp->mp_flags & Mask) == pflags && level <= 1)
					dp->mp_flags ^= P_KEEP;
			}
		}
	}

	return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movq 0x18(%rdi), %r14
xorl %eax, %eax
testb $0x40, 0x44(%rdi)
cmovneq %rax, %rdi
movl 0x78(%r14), %eax
movq %rax, %rcx
testq %rdi, %rdi
je 0xa04f
testb $0x1, 0x44(%rdi)
jne 0x9fd6
movq (%rdi), %rdi
jmp 0x9fc2
movq %rdi, %rsi
movzwl 0x40(%rsi), %r8d
xorl %r10d, %r10d
xorl %r9d, %r9d
cmpq %r10, %r8
je 0xa011
movq 0x48(%rsi,%r10,8), %r9
movzwl 0xa(%r9), %r11d
movl %r11d, %ebp
andl $0xc050, %ebp           # imm = 0xC050
cmpl %ebx, %ebp
jne 0xa00c
xorl $0x8000, %r11d          # imm = 0x8000
movw %r11w, 0xa(%r9)
incq %r10
jmp 0x9fe4
movq 0x10(%rsi), %r10
testq %r10, %r10
je 0x9fd1
testq %r9, %r9
je 0x9fd1
movl 0x44(%r10), %r11d
andl $0x1, %r11d
je 0x9fd1
testb $0x2, 0xa(%r9)
je 0x9fd1
decl %r8d
movzwl 0x148(%rsi,%r8,2), %esi
movzwl 0x10(%r9,%rsi,2), %esi
testb $0x2, 0x4(%r9,%rsi)
movq %r10, %rsi
jne 0x9fd9
jmp 0x9fd1
subq $0x1, %rcx
jb 0xa062
movq 0x68(%r14), %rsi
movq (%rsi,%rcx,8), %rdi
jmp 0x9fc2
testl %edx, %edx
je 0xa0db
pushq $0x28
popq %rbp
leaq 0x10(%rsp), %r12
leaq 0xc(%rsp), %r13
xorl %r15d, %r15d
movl %eax, %eax
cmpq %rax, %r15
jae 0xa0db
movq 0x70(%r14), %rax
testb $0x1, (%rax,%r15)
je 0xa0ce
movq 0x58(%r14), %rax
movq (%rax,%rbp), %rsi
cmpq $-0x1, %rsi
je 0xa0ce
movq %r14, %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x6fba
testl %eax, %eax
jne 0xa0ec
movq 0x10(%rsp), %rax
movzwl 0xa(%rax), %ecx
movl %ecx, %edx
andl $0xc050, %edx           # imm = 0xC050
cmpl %ebx, %edx
jne 0xa0ce
cmpl $0x1, 0xc(%rsp)
jg 0xa0ce
xorl $0x8000, %ecx           # imm = 0x8000
movw %cx, 0xa(%rax)
incq %r15
movl 0x78(%r14), %eax
addq $0x30, %rbp
jmp 0xa076
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa0dd