// File: /workspace/github_cpp_makefile_star2_O3/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_page_touch
static int
mdb_page_touch(MDB_cursor *mc)
{
	MDB_page *mp = mc->mc_pg[mc->mc_top], *np;
	MDB_txn *txn = mc->mc_txn;
	MDB_cursor *m2, *m3;
	pgno_t	pgno;
	int rc;

	if (!F_ISSET(mp->mp_flags, P_DIRTY)) {
		if (txn->mt_flags & MDB_TXN_SPILLS) {
			np = NULL;
			rc = mdb_page_unspill(txn, mp, &np);
			if (rc)
				goto fail;
			if (np)
				goto done;
		}
		if ((rc = mdb_midl_need(&txn->mt_free_pgs, 1)) ||
			(rc = mdb_page_alloc(mc, 1, &np)))
			goto fail;
		pgno = np->mp_pgno;
		DPRINTF(("touched db %d page %"Z"u -> %"Z"u", DDBI(mc),
			mp->mp_pgno, pgno));
		mdb_cassert(mc, mp->mp_pgno != pgno);
		mdb_midl_xappend(txn->mt_free_pgs, mp->mp_pgno);
		/* Update the parent page, if any, to point to the new page */
		if (mc->mc_top) {
			MDB_page *parent = mc->mc_pg[mc->mc_top-1];
			MDB_node *node = NODEPTR(parent, mc->mc_ki[mc->mc_top-1]);
			SETPGNO(node, pgno);
		} else {
			mc->mc_db->md_root = pgno;
		}
	} else if (txn->mt_parent && !IS_SUBP(mp)) {
		MDB_ID2 mid, *dl = txn->mt_u.dirty_list;
		pgno = mp->mp_pgno;
		/* If txn has a parent, make sure the page is in our
		 * dirty list.
		 */
		if (dl[0].mid) {
			unsigned x = mdb_mid2l_search(dl, pgno);
			if (x <= dl[0].mid && dl[x].mid == pgno) {
				if (mp != dl[x].mptr) { /* bad cursor? */
					mc->mc_flags &= ~(C_INITIALIZED|C_EOF);
					txn->mt_flags |= MDB_TXN_ERROR;
					return MDB_CORRUPTED;
				}
				return 0;
			}
		}
		mdb_cassert(mc, dl[0].mid < MDB_IDL_UM_MAX);
		/* No - copy it */
		np = mdb_page_malloc(txn, 1);
		if (!np)
			return ENOMEM;
		mid.mid = pgno;
		mid.mptr = np;
		rc = mdb_mid2l_insert(dl, &mid);
		mdb_cassert(mc, rc == 0);
	} else {
		return 0;
	}

	mdb_page_copy(np, mp, txn->mt_env->me_psize);
	np->mp_pgno = pgno;
	np->mp_flags |= P_DIRTY;

done:
	/* Adjust cursors pointing to mp */
	mc->mc_pg[mc->mc_top] = np;
	m2 = txn->mt_cursors[mc->mc_dbi];
	if (mc->mc_flags & C_SUB) {
		for (; m2; m2=m2->mc_next) {
			m3 = &m2->mc_xcursor->mx_cursor;
			if (m3->mc_snum < mc->mc_snum) continue;
			if (m3->mc_pg[mc->mc_top] == mp)
				m3->mc_pg[mc->mc_top] = np;
		}
	} else {
		for (; m2; m2=m2->mc_next) {
			if (m2->mc_snum < mc->mc_snum) continue;
			if (m2->mc_pg[mc->mc_top] == mp) {
				m2->mc_pg[mc->mc_top] = np;
				if ((mc->mc_db->md_flags & MDB_DUPSORT) &&
					IS_LEAF(np) &&
					m2->mc_ki[mc->mc_top] == mc->mc_ki[mc->mc_top])
				{
					MDB_node *leaf = NODEPTR(np, mc->mc_ki[mc->mc_top]);
					if (!(leaf->mn_flags & F_SUBDATA))
						m2->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(leaf);
				}
			}
		}
	}
	return 0;

fail:
	txn->mt_flags |= MDB_TXN_ERROR;
	return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movzwl 0x42(%rdi), %eax
movq 0x48(%rdi,%rax,8), %rbx
movq 0x18(%rdi), %r15
movzwl 0xa(%rbx), %ecx
testb $0x10, %cl
jne 0xa1c1
testb $0x8, 0x7c(%r15)
jne 0xa21b
leaq 0x28(%r15), %rbp
movq %rbp, %rdi
movl $0x1, %esi
callq 0xba6f
testl %eax, %eax
jne 0xa236
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x6f78
testl %eax, %eax
jne 0xa236
movq 0x8(%rsp), %r12
movq (%r12), %r13
cmpq %r13, (%rbx)
je 0xa3e4
movq (%rbp), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
movq (%rbx), %rdx
movq %rdx, 0x8(%rax,%rcx,8)
movzwl 0x42(%r14), %eax
testq %rax, %rax
je 0xa390
decl %eax
movq 0x48(%r14,%rax,8), %rcx
movzwl 0x148(%r14,%rax,2), %eax
movzwl 0x10(%rcx,%rax,2), %eax
movw %r13w, (%rcx,%rax)
movl %r13d, %edx
shrl $0x10, %edx
movw %dx, 0x2(%rcx,%rax)
movq %r13, %rdx
shrq $0x20, %rdx
movw %dx, 0x4(%rcx,%rax)
jmp 0xa28c
xorl %eax, %eax
testb $0x40, %cl
jne 0xa23b
cmpq $0x0, (%r15)
je 0xa23b
movq 0x48(%r15), %rbp
movq (%rbx), %r13
cmpq $0x0, (%rbp)
je 0xa257
movq %rbp, %rdi
movq %r13, %rsi
callq 0xbea3
movl %eax, %eax
movq (%rbp), %rcx
cmpq %rax, %rcx
jb 0xa24a
shlq $0x4, %rax
cmpq %r13, (%rbp,%rax)
jne 0xa24a
addq %rax, %rbp
cmpq 0x8(%rbp), %rbx
je 0xa39d
andb $-0x4, 0x44(%r14)
orb $0x2, 0x7c(%r15)
movl $0xffff87b4, %eax       # imm = 0xFFFF87B4
jmp 0xa23b
leaq 0x8(%rsp), %rdx
movq $0x0, (%rdx)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x75ba
testl %eax, %eax
je 0xa2aa
orb $0x2, 0x7c(%r15)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x1ffff, %rcx          # imm = 0x1FFFF
jae 0xa3c4
movq %r15, %rdi
movl $0x1, %esi
callq 0x76c4
testq %rax, %rax
je 0xa386
movq %rax, %r12
leaq 0x8(%rsp), %rsi
movq %r13, (%rsi)
movq %rax, 0x8(%rsi)
movq %rbp, %rdi
callq 0xbee9
testl %eax, %eax
jne 0xa3a4
movq 0x20(%r15), %rax
movl 0x10(%rax), %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa635
movq %r13, (%r12)
orb $0x10, 0xa(%r12)
jmp 0xa2b8
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0xa122
movzwl 0x42(%r14), %ecx
movq %r12, 0x48(%r14,%rcx,8)
movq 0x68(%r15), %rax
movl 0x20(%r14), %edx
movq (%rax,%rdx,8), %rdx
testb $0x4, 0x44(%r14)
jne 0xa353
xorl %eax, %eax
testq %rdx, %rdx
je 0xa23b
movzwl 0x40(%r14), %esi
cmpw %si, 0x40(%rdx)
jb 0xa346
cmpq %rbx, 0x48(%rdx,%rcx,8)
jne 0xa346
movq %r12, 0x48(%rdx,%rcx,8)
movq 0x28(%r14), %rdi
testb $0x4, 0x4(%rdi)
je 0xa346
testb $0x2, 0xa(%r12)
je 0xa346
leal (%rcx,%rcx), %r8d
movzwl 0x148(%rdx,%r8), %edi
cmpw 0x148(%r14,%r8), %di
jne 0xa346
movzwl 0x10(%r12,%rdi,2), %edi
testb $0x2, 0x4(%r12,%rdi)
jne 0xa346
addq %r12, %rdi
movzwl 0x6(%rdi), %r8d
addq %r8, %rdi
addq $0x8, %rdi
movq 0x10(%rdx), %r8
movq %rdi, 0x48(%r8)
movq (%rdx), %rdx
testq %rdx, %rdx
jne 0xa2e5
jmp 0xa23b
xorl %eax, %eax
testq %rdx, %rdx
je 0xa23b
movzwl 0x40(%r14), %esi
movq 0x10(%rdx), %rdi
cmpw %si, 0x40(%rdi)
jb 0xa379
cmpq %rbx, 0x48(%rdi,%rcx,8)
jne 0xa379
movq %r12, 0x48(%rdi,%rcx,8)
movq (%rdx), %rdx
testq %rdx, %rdx
jne 0xa363
jmp 0xa23b
movl $0xc, %eax
jmp 0xa23b
movq 0x28(%r14), %rax
movq %r13, 0x28(%rax)
jmp 0xa28c
xorl %eax, %eax
jmp 0xa23b
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x5677(%rip), %rsi      # 0xfa2a
leaq 0x5646(%rip), %rdx      # 0xfa00
movl $0x97d, %ecx            # imm = 0x97D
callq 0xbfbd
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x563c(%rip), %rsi      # 0xfa0f
leaq 0x5626(%rip), %rdx      # 0xfa00
movl $0x975, %ecx            # imm = 0x975
callq 0xbfbd
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x55f9(%rip), %rsi      # 0xf9ec
leaq 0x5606(%rip), %rdx      # 0xfa00
movl $0x95a, %ecx            # imm = 0x95A
callq 0xbfbd