// File: /workspace/github_cpp_makefile_star2_O1/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_ovpage_free
static int
mdb_ovpage_free(MDB_cursor *mc, MDB_page *mp)
{
	MDB_txn *txn = mc->mc_txn;
	pgno_t pg = mp->mp_pgno;
	unsigned x = 0, ovpages = mp->mp_pages;
	MDB_env *env = txn->mt_env;
	MDB_IDL sl = txn->mt_spill_pgs;
	MDB_ID pn = pg << 1;
	int rc;

	DPRINTF(("free ov page %"Z"u (%d)", pg, ovpages));
	/* If the page is dirty or on the spill list we just acquired it,
	 * so we should give it back to our current free list, if any.
	 * Otherwise put it onto the list of pages we freed in this txn.
	 *
	 * Won't create me_pghead: me_pglast must be inited along with it.
	 * Unsupported in nested txns: They would need to hide the page
	 * range in ancestor txns' dirty and spilled lists.
	 */
	if (env->me_pghead &&
		!txn->mt_parent &&
		((mp->mp_flags & P_DIRTY) ||
		 (sl && (x = mdb_midl_search(sl, pn)) <= sl[0] && sl[x] == pn)))
	{
		unsigned i, j;
		pgno_t *mop;
		MDB_ID2 *dl, ix, iy;
		rc = mdb_midl_need(&env->me_pghead, ovpages);
		if (rc)
			return rc;
		if (!(mp->mp_flags & P_DIRTY)) {
			/* This page is no longer spilled */
			if (x == sl[0])
				sl[0]--;
			else
				sl[x] |= 1;
			goto release;
		}
		/* Remove from dirty list */
		dl = txn->mt_u.dirty_list;
		x = dl[0].mid--;
		for (ix = dl[x]; ix.mptr != mp; ix = iy) {
			if (x > 1) {
				x--;
				iy = dl[x];
				dl[x] = ix;
			} else {
				mdb_cassert(mc, x > 1);
				j = ++(dl[0].mid);
				dl[j] = ix;		/* Unsorted. OK when MDB_TXN_ERROR. */
				txn->mt_flags |= MDB_TXN_ERROR;
				return MDB_CORRUPTED;
			}
		}
		if (!(env->me_flags & MDB_WRITEMAP))
			mdb_dpage_free(env, mp);
release:
		/* Insert in me_pghead */
		mop = env->me_pghead;
		j = mop[0] + ovpages;
		for (i = mop[0]; i && mop[i] < pg; i--)
			mop[j--] = mop[i];
		while (j>i)
			mop[j--] = pg++;
		mop[0] += ovpages;
	} else {
		rc = mdb_midl_append_range(&txn->mt_free_pgs, pg, ovpages);
		if (rc)
			return rc;
	}
	mc->mc_db->md_overflow_pages -= ovpages;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq 0x18(%rdi), %rbx
movq (%rsi), %r15
movl 0xc(%rsi), %r14d
movq 0x20(%rbx), %r13
cmpq $0x0, 0xb0(%r13)
je 0x7bc1
cmpq $0x0, (%rbx)
je 0x7bf9
addq $0x28, %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0xc0ba
movl %eax, %ebp
testl %eax, %eax
jne 0x7be8
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
subq %r14, 0x18(%rax)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r12
movq 0x40(%rbx), %rbp
xorl %eax, %eax
testb $0x10, 0xa(%rsi)
jne 0x7c32
testq %rbp, %rbp
je 0x7bc1
leaq (%r15,%r15), %rsi
movq %rbp, %rdi
movq %rsi, 0x8(%rsp)
callq 0xbeac
movl %eax, %ecx
cmpq %rcx, (%rbp)
jb 0x7bc1
movq 0x8(%rsp), %rdx
cmpq %rdx, (%rbp,%rcx,8)
jne 0x7bc1
movl %eax, 0x14(%rsp)
movq %rbp, 0x20(%rsp)
leaq 0xb0(%r13), %rdi
movq %rdi, 0x8(%rsp)
movl %r14d, %esi
callq 0xbf73
movl %eax, %ebp
testl %eax, %eax
jne 0x7be8
movq 0x8(%rsp), %rdi
testb $0x10, 0xa(%r12)
jne 0x7c82
movl 0x14(%rsp), %eax
movq 0x20(%rsp), %rdx
movq (%rdx), %rcx
cmpq %rax, %rcx
movq %rdi, %rbx
jne 0x7cfa
decq %rcx
movq %rcx, (%rdx)
jmp 0x7cfe
movq 0x48(%rbx), %rsi
movq (%rsi), %rcx
leaq -0x1(%rcx), %rax
movq %rax, (%rsi)
movl %ecx, %edx
shlq $0x4, %rdx
movq 0x8(%rsi,%rdx), %rax
cmpq %r12, %rax
movq %rdi, %rbx
je 0x7ce6
addq %rsi, %rdx
movq (%rdx), %rdx
movl %ecx, %ecx
movq %rcx, %rdi
shlq $0x4, %rdi
addq %rdi, %rsi
addq $-0x8, %rsi
incq %rcx
decq %rcx
cmpq $0x2, %rcx
jb 0x7d56
movq -0x8(%rsi), %rdi
movq (%rsi), %r8
movq %rdx, -0x8(%rsi)
movq %rax, (%rsi)
addq $-0x10, %rsi
movq %rdi, %rdx
movq %r8, %rax
cmpq %r12, %r8
jne 0x7cbc
testb $0x8, 0xe(%r13)
jne 0x7cfe
movq %r13, %rdi
movq %r12, %rsi
callq 0xa0ec
jmp 0x7cfe
orb $0x1, (%rdx,%rax,8)
movq (%rbx), %rax
movl (%rax), %ecx
testl %ecx, %ecx
je 0x7d27
leal (%r14,%rcx), %edx
movl %ecx, %esi
movq (%rax,%rsi,8), %rsi
cmpq %r15, %rsi
jae 0x7d2c
movl %edx, %edx
movq %rsi, (%rax,%rdx,8)
decl %ecx
jne 0x7d07
xorl %ecx, %ecx
movl %r14d, %edx
jmp 0x7d2c
movl %r14d, %edx
addl %ecx, %edx
cmpl %ecx, %edx
jbe 0x7d46
movl %edx, %esi
leaq (%rax,%rsi,8), %rsi
movq %r15, (%rsi)
incq %r15
addq $-0x8, %rsi
decl %edx
cmpl %edx, %ecx
jb 0x7d36
addq %r14, (%rax)
testl %ebp, %ebp
jne 0x7be8
jmp 0x7bd9
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x7dae(%rip), %rsi      # 0xfb18
leaq 0x7dad(%rip), %rdx      # 0xfb1e
movl $0x1597, %ecx           # imm = 0x1597
callq 0xc43e