// File: /workspace/github_cpp_makefile_star2_O3/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)
movl 0x78(%r14), %ecx
cmovneq %rax, %rdi
movq %rcx, %rax
testq %rdi, %rdi
je 0xa8b6
testb $0x1, 0x44(%rdi)
jne 0xa81f
movq (%rdi), %rdi
jmp 0xa80b
movq %rdi, %rsi
movzwl 0x40(%rsi), %r10d
testq %r10, %r10
je 0xa86b
negq %r10
movq $-0x1, %r8
movq 0x50(%rsi,%r8,8), %r9
movzwl 0xa(%r9), %r11d
movl %r11d, %ebp
andl $0xc050, %ebp           # imm = 0xC050
cmpl %ebx, %ebp
jne 0xa859
xorl $0x8000, %r11d          # imm = 0x8000
movw %r11w, 0xa(%r9)
leaq (%r10,%r8), %r11
incq %r11
incq %r8
cmpq $-0x1, %r11
jne 0xa836
jmp 0xa874
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movq 0x10(%rsi), %r10
testq %r10, %r10
je 0xa81a
testq %r9, %r9
je 0xa81a
movl 0x44(%r10), %r11d
andl $0x1, %r11d
je 0xa81a
testb $0x2, 0xa(%r9)
je 0xa81a
movzwl 0x148(%rsi,%r8,2), %esi
movzwl 0x10(%r9,%rsi,2), %esi
testb $0x2, 0x4(%r9,%rsi)
movq %r10, %rsi
jne 0xa822
jmp 0xa81a
subq $0x1, %rax
jb 0xa8c9
movq 0x68(%r14), %rsi
movq (%rsi,%rax,8), %rdi
jmp 0xa80b
xorl %eax, %eax
testl %edx, %edx
je 0xa947
testl %ecx, %ecx
je 0xa947
movl $0x28, %r13d
xorl %ebp, %ebp
leaq 0x10(%rsp), %r15
leaq 0xc(%rsp), %r12
movq 0x70(%r14), %rax
testb $0x1, (%rax,%rbp)
je 0xa935
movq 0x58(%r14), %rax
movq (%rax,%r13), %rsi
cmpq $-0x1, %rsi
je 0xa935
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x74c4
testl %eax, %eax
jne 0xa947
movq 0x10(%rsp), %rax
movzwl 0xa(%rax), %ecx
movl %ecx, %edx
andl $0xc050, %edx           # imm = 0xC050
cmpl %ebx, %edx
jne 0xa935
cmpl $0x1, 0xc(%rsp)
jg 0xa935
xorl $0x8000, %ecx           # imm = 0x8000
movw %cx, 0xa(%rax)
incq %rbp
movl 0x78(%r14), %eax
addq $0x30, %r13
cmpq %rax, %rbp
jb 0xa8e5
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq