// File: /workspace/github_cpp_makefile_star2_O1/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), %eax
testb $0x10, %al
jne 0xa5c1
testb $0x8, 0x7c(%r15)
jne 0xa5fa
leaq 0x28(%r15), %r13
movq %r13, %rdi
movl $0x1, %esi
callq 0xbf73
testl %eax, %eax
jne 0xa613
movq %rsp, %rdx
movq %r14, %rdi
movl $0x1, %esi
callq 0x730f
testl %eax, %eax
jne 0xa613
movq (%rsp), %rax
movq (%rax), %r12
cmpq %r12, (%rbx)
je 0xa7e9
movq (%r13), %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 0xa658
decl %eax
movq 0x48(%r14,%rax,8), %rcx
movzwl 0x148(%r14,%rax,2), %eax
movzwl 0x10(%rcx,%rax,2), %eax
movw %r12w, (%rcx,%rax)
movl %r12d, %edx
shrl $0x10, %edx
movw %dx, 0x2(%rcx,%rax)
movq %r12, %rdx
shrq $0x20, %rdx
movw %dx, 0x4(%rcx,%rax)
jmp 0xa6d7
xorl %ebp, %ebp
testb $0x40, %al
jne 0xa7b8
cmpq $0x0, (%r15)
je 0xa7b8
movq 0x48(%r15), %r13
movq (%rbx), %r12
cmpq $0x0, (%r13)
je 0xa62f
movq %r13, %rdi
movq %r12, %rsi
callq 0xc310
movl %eax, %ecx
movb $0x1, %al
cmpq %rcx, (%r13)
jae 0xa631
jmp 0xa666
movq %rsp, %rdx
movq $0x0, (%rdx)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x79d8
testl %eax, %eax
je 0xa61f
movl %eax, %ebp
orb $0x2, 0x7c(%r15)
jmp 0xa7b8
cmpq $0x0, (%rsp)
jne 0xa6f6
jmp 0xa526
jmp 0xa66a
shlq $0x4, %rcx
cmpq %r12, (%r13,%rcx)
jne 0xa666
addq %r13, %rcx
cmpq 0x8(%rcx), %rbx
je 0xa662
andb $-0x4, 0x44(%r14)
orb $0x2, 0x7c(%r15)
movl $0xffff87b4, %ebp       # imm = 0xFFFF87B4
xorl %eax, %eax
jmp 0xa666
movq 0x28(%r14), %rax
movq %r12, 0x28(%rax)
jmp 0xa6d7
xorl %eax, %eax
xorl %ebp, %ebp
testb %al, %al
je 0xa6cd
cmpq $0x1ffff, (%r13)        # imm = 0x1FFFF
jae 0xa7c9
movq %r15, %rdi
movl $0x1, %esi
callq 0x7afe
movq %rax, (%rsp)
testq %rax, %rax
je 0xa6c8
leaq 0x8(%rsp), %rsi
movq %r12, (%rsi)
movq %rax, 0x8(%rsi)
movq %r13, %rdi
callq 0xc36a
movb $0x1, %cl
testl %eax, %eax
je 0xa6cf
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x5333(%rip), %rsi      # 0xf9ea
leaq 0x5302(%rip), %rdx      # 0xf9c0
movl $0x97d, %ecx            # imm = 0x97D
callq 0xc43e
movl $0xc, %ebp
xorl %ecx, %ecx
testb %cl, %cl
je 0xa7b8
movq (%rsp), %r13
movq 0x20(%r15), %rax
movl 0x10(%rax), %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0xaa49
movq %r12, (%r13)
orb $0x10, 0xa(%r13)
movq (%rsp), %rax
movzwl 0x42(%r14), %ecx
movq %rax, 0x48(%r14,%rcx,8)
movq 0x68(%r15), %rdx
movl 0x20(%r14), %esi
movq (%rdx,%rsi,8), %rdx
testb $0x4, 0x44(%r14)
jne 0xa78e
xorl %ebp, %ebp
testq %rdx, %rdx
je 0xa7b8
movzwl 0x40(%r14), %esi
cmpw %si, 0x40(%rdx)
jb 0xa784
cmpq %rbx, 0x48(%rdx,%rcx,8)
jne 0xa784
movq %rax, 0x48(%rdx,%rcx,8)
movq 0x28(%r14), %rdi
testb $0x4, 0x4(%rdi)
je 0xa784
testb $0x2, 0xa(%rax)
je 0xa784
leal (%rcx,%rcx), %r8d
movzwl 0x148(%r14,%r8), %edi
cmpw %di, 0x148(%rdx,%r8)
jne 0xa784
movzwl 0x10(%rax,%rdi,2), %edi
testb $0x2, 0x4(%rax,%rdi)
jne 0xa784
addq %rax, %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 0xa727
jmp 0xa7b8
xorl %ebp, %ebp
testq %rdx, %rdx
je 0xa7b8
movzwl 0x40(%r14), %esi
movq 0x10(%rdx), %rdi
cmpw %si, 0x40(%rdi)
jb 0xa7b0
cmpq %rbx, 0x48(%rdi,%rcx,8)
jne 0xa7b0
movq %rax, 0x48(%rdi,%rcx,8)
movq (%rdx), %rdx
testq %rdx, %rdx
jne 0xa79a
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x51f7(%rip), %rsi      # 0xf9cf
leaq 0x51e1(%rip), %rdx      # 0xf9c0
movl $0x975, %ecx            # imm = 0x975
callq 0xc43e
movq 0x18(%r14), %rax
movq 0x20(%rax), %rdi
leaq 0x51b4(%rip), %rsi      # 0xf9ac
leaq 0x51c1(%rip), %rdx      # 0xf9c0
movl $0x95a, %ecx            # imm = 0x95A
callq 0xc43e