// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movzwl 0x42(%rdi), %eax
movq 0x48(%rdi,%rax,8), %r14
movq 0x18(%rdi), %r15
movzwl 0xa(%r14), %ecx
testb $0x10, %cl
jne 0x99d8
testb $0x8, 0x7c(%r15)
jne 0x9a3c
leaq 0x28(%r15), %rbp
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0xb1eb
testl %eax, %eax
jne 0x9a54
pushq $0x1
popq %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x6ac1
testl %eax, %eax
jne 0x9a54
movq 0x8(%rsp), %r12
movq (%r12), %r13
cmpq %r13, (%r14)
je 0x9bda
movq (%rbp), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
movq (%r14), %rdx
movq %rdx, 0x8(%rax,%rcx,8)
movzwl 0x42(%rbx), %eax
testq %rax, %rax
je 0x9b8d
decl %eax
movq 0x48(%rbx,%rax,8), %rcx
movzwl 0x148(%rbx,%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 0x9a9e
xorl %eax, %eax
testb $0x40, %cl
jne 0x9b7e
cmpq $0x0, (%r15)
je 0x9b7e
movq 0x48(%r15), %rbp
movq (%r14), %r13
cmpq $0x0, (%rbp)
je 0x9a6b
movq %rbp, %rdi
movq %r13, %rsi
callq 0xb54e
movl %eax, %eax
movq (%rbp), %rcx
cmpq %rax, %rcx
jb 0x9a5e
shlq $0x4, %rax
cmpq %r13, (%rbp,%rax)
jne 0x9a5e
addq %rax, %rbp
cmpq 0x8(%rbp), %r14
je 0x9b77
andb $-0x4, 0x44(%rbx)
orb $0x2, 0x7c(%r15)
movl $0xffff87b4, %eax       # imm = 0xFFFF87B4
jmp 0x9b7e
leaq 0x8(%rsp), %rdx
andq $0x0, (%rdx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x70ae
testl %eax, %eax
je 0x9abc
orb $0x2, 0x7c(%r15)
jmp 0x9b7e
cmpq $0x1ffff, %rcx          # imm = 0x1FFFF
jae 0x9bba
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x71ca
testq %rax, %rax
je 0x9b7b
movq %rax, %r12
leaq 0x8(%rsp), %rsi
movq %r13, (%rsi)
movq %rax, 0x8(%rsi)
movq %rbp, %rdi
callq 0xb5a7
testl %eax, %eax
jne 0x9b9a
movq 0x20(%r15), %rax
movl 0x10(%rax), %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x9dfd
movq %r13, (%r12)
orb $0x10, 0xa(%r12)
jmp 0x9aca
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x993f
movzwl 0x42(%rbx), %eax
movq %r12, 0x48(%rbx,%rax,8)
movq 0x68(%r15), %rcx
movl 0x20(%rbx), %edx
movq (%rcx,%rdx,8), %rcx
testb $0x4, 0x44(%rbx)
jne 0x9b53
testq %rcx, %rcx
je 0x9b77
movzwl 0x40(%rcx), %edx
cmpw 0x40(%rbx), %dx
jb 0x9b4e
cmpq %r14, 0x48(%rcx,%rax,8)
jne 0x9b4e
movq %r12, 0x48(%rcx,%rax,8)
movq 0x28(%rbx), %rdx
testb $0x4, 0x4(%rdx)
je 0x9b4e
testb $0x2, 0xa(%r12)
je 0x9b4e
leal (%rax,%rax), %esi
movzwl 0x148(%rcx,%rsi), %edx
cmpw 0x148(%rbx,%rsi), %dx
jne 0x9b4e
movzwl 0x10(%r12,%rdx,2), %edx
testb $0x2, 0x4(%r12,%rdx)
jne 0x9b4e
addq %r12, %rdx
movzwl 0x6(%rdx), %esi
addq %rsi, %rdx
addq $0x8, %rdx
movq 0x10(%rcx), %rsi
movq %rdx, 0x48(%rsi)
movq (%rcx), %rcx
jmp 0x9ae4
testq %rcx, %rcx
je 0x9b77
movq 0x10(%rcx), %rdx
movzwl 0x40(%rdx), %esi
cmpw 0x40(%rbx), %si
jb 0x9b72
cmpq %r14, 0x48(%rdx,%rax,8)
jne 0x9b72
movq %r12, 0x48(%rdx,%rax,8)
movq (%rcx), %rcx
jmp 0x9b53
xorl %eax, %eax
jmp 0x9b7e
pushq $0xc
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rbx), %rax
movq %r13, 0x28(%rax)
jmp 0x9a9e
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x4e61(%rip), %rsi      # 0xea0a
leaq 0x4e30(%rip), %rdx      # 0xe9e0
movl $0x97d, %ecx            # imm = 0x97D
callq 0xb672
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x4e26(%rip), %rsi      # 0xe9ef
leaq 0x4e10(%rip), %rdx      # 0xe9e0
movl $0x975, %ecx            # imm = 0x975
callq 0xb672
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x4de3(%rip), %rsi      # 0xe9cc
leaq 0x4df0(%rip), %rdx      # 0xe9e0
movl $0x95a, %ecx            # imm = 0x95A
callq 0xb672