// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %rbp
movq (%rsi), %r15
movl 0xc(%rsi), %r14d
movq 0x20(%rbp), %r13
cmpq $0x0, 0xb0(%r13)
je 0x728c
cmpq $0x0, (%rbp)
je 0x72bb
addq $0x28, %rbp
movq %rbp, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0xb32d
testl %eax, %eax
jne 0x72ac
movq 0x28(%rbx), %rax
subq %r14, 0x18(%rax)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r12
movq 0x40(%rbp), %rdi
xorl %eax, %eax
testb $0x10, 0xa(%rsi)
jne 0x72f7
testq %rdi, %rdi
je 0x728c
leaq (%r15,%r15), %rsi
movq %rsi, (%rsp)
movq %rdi, 0x8(%rsp)
callq 0xb128
movq 0x8(%rsp), %rdi
movl %eax, %ecx
cmpq %rcx, (%rdi)
jb 0x728c
movq (%rsp), %rdx
cmpq %rdx, (%rdi,%rcx,8)
jne 0x728c
movl %eax, 0x14(%rsp)
movq %rdi, 0x8(%rsp)
leaq 0xb0(%r13), %rdi
movq %rdi, (%rsp)
movl %r14d, %esi
callq 0xb1eb
testl %eax, %eax
jne 0x72ac
movq (%rsp), %rdi
testb $0x10, 0xa(%r12)
jne 0x7339
movl 0x14(%rsp), %eax
movq 0x8(%rsp), %rcx
cmpq %rax, (%rcx)
jne 0x739e
decq %rax
movq %rax, (%rcx)
jmp 0x73a2
movq 0x48(%rbp), %rcx
movq (%rcx), %rax
leaq -0x1(%rax), %rdx
movq %rdx, (%rcx)
movl %eax, %eax
movq %rax, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
addq $-0x8, %rcx
movq 0x8(%rcx), %rsi
movq 0x10(%rcx), %rdx
movq %rdi, %rbp
cmpq %r12, %rdx
je 0x738a
cmpq $0x2, %rax
jb 0x73e6
decq %rax
movq -0x8(%rcx), %rdi
movq (%rcx), %r8
movq %rsi, -0x8(%rcx)
movq %rdx, (%rcx)
addq $-0x10, %rcx
movq %r8, %rdx
movq %rdi, %rsi
jmp 0x7362
testb $0x8, 0xe(%r13)
jne 0x73a5
movq %r13, %rdi
movq %r12, %rsi
callq 0x9564
jmp 0x73a5
orb $0x1, (%rcx,%rax,8)
movq %rdi, %rbp
movq (%rbp), %rax
movl (%rax), %ecx
movl %ecx, %edx
subl $0x1, %edx
jb 0x73ca
movl %ecx, %esi
movq (%rax,%rsi,8), %rsi
cmpq %r15, %rsi
jae 0x73ca
addl %r14d, %ecx
movl %ecx, %ecx
movq %rsi, (%rax,%rcx,8)
movl %edx, %ecx
jmp 0x73ad
leal (%r14,%rcx), %edx
cmpl %ecx, %edx
jbe 0x73de
movq %r15, (%rax,%rdx,8)
incq %r15
decq %rdx
jmp 0x73ce
addq %r14, (%rax)
jmp 0x72a2
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdi
leaq 0x7743(%rip), %rsi      # 0xeb38
leaq 0x7742(%rip), %rdx      # 0xeb3e
movl $0x1597, %ecx           # imm = 0x1597
callq 0xb672