// File: /workspace/github_cpp_makefile_star2_O2/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_txn_end
static void
mdb_txn_end(MDB_txn *txn, unsigned mode)
{
	MDB_env	*env = txn->mt_env;
#if MDB_DEBUG
	static const char *const names[] = MDB_END_NAMES;
#endif

	/* Export or close DBI handles opened in this txn */
	mdb_dbis_update(txn, mode & MDB_END_UPDATE);

	DPRINTF(("%s txn %"Z"u%c %p on mdbenv %p, root page %"Z"u",
		names[mode & MDB_END_OPMASK],
		txn->mt_txnid, (txn->mt_flags & MDB_TXN_RDONLY) ? 'r' : 'w',
		(void *) txn, (void *)env, txn->mt_dbs[MAIN_DBI].md_root));

	if (F_ISSET(txn->mt_flags, MDB_TXN_RDONLY)) {
		if (txn->mt_u.reader) {
			txn->mt_u.reader->mr_txnid = (txnid_t)-1;
			if (!(env->me_flags & MDB_NOTLS)) {
				txn->mt_u.reader = NULL; /* txn does not own reader */
			} else if (mode & MDB_END_SLOT) {
				txn->mt_u.reader->mr_pid = 0;
				txn->mt_u.reader = NULL;
			} /* else txn owns the slot until it does MDB_END_SLOT */
		}
		txn->mt_numdbs = 0;		/* prevent further DBI activity */
		txn->mt_flags |= MDB_TXN_FINISHED;

	} else if (!F_ISSET(txn->mt_flags, MDB_TXN_FINISHED)) {
		pgno_t *pghead = env->me_pghead;

		if (!(mode & MDB_END_UPDATE)) /* !(already closed cursors) */
			mdb_cursors_close(txn, 0);
		if (!(env->me_flags & MDB_WRITEMAP)) {
			mdb_dlist_free(txn);
		}

		txn->mt_numdbs = 0;
		txn->mt_flags = MDB_TXN_FINISHED;

		if (!txn->mt_parent) {
			mdb_midl_shrink(&txn->mt_free_pgs);
			env->me_free_pgs = txn->mt_free_pgs;
			/* me_pgstate: */
			env->me_pghead = NULL;
			env->me_pglast = 0;

			env->me_txn = NULL;
			mode = 0;	/* txn == env->me_txn0, do not free() it */

			/* The writer mutex was locked in mdb_txn_begin. */
			if (env->me_txns)
				UNLOCK_MUTEX(env->me_wmutex);
		} else {
			txn->mt_parent->mt_child = NULL;
			txn->mt_parent->mt_flags &= ~MDB_TXN_HAS_CHILD;
			env->me_pgstate = ((MDB_ntxn *)txn)->mnt_pgstate;
			mdb_midl_free(txn->mt_free_pgs);
			mdb_midl_free(txn->mt_spill_pgs);
			free(txn->mt_u.dirty_list);
		}

		mdb_midl_free(pghead);
	}

	if (mode & MDB_END_FREE)
		free(txn);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x20(%rdi), %r12
movq 0x70(%rdi), %rax
movq %rdi, 0x8(%rsp)
movl 0x78(%rdi), %r14d
leaq -0x4(,%r14,4), %rcx
movq %rcx, 0x10(%rsp)
leaq -0x2(,%r14,2), %r13
imulq $0x30, %r14, %r15
leaq (%r14,%rax), %rbx
decq %rbx
xorl %ebp, %ebp
movl %esi, 0x4(%rsp)
leal (%r14,%rbp), %eax
cmpl $0x3, %eax
jl 0x35f0
testb $0x4, (%rbx,%rbp)
je 0x35e4
testb $0x10, %sil
jne 0x35c0
movq 0x88(%r12), %rax
movq -0x28(%rax,%r15), %rdi
testq %rdi, %rdi
je 0x35e4
xorps %xmm0, %xmm0
movups %xmm0, -0x30(%rax,%r15)
movq 0x90(%r12), %rax
addq %r13, %rax
andw $0x0, (%rax,%rbp,2)
movq 0x98(%r12), %rax
addq 0x10(%rsp), %rax
incl (%rax,%rbp,4)
callq 0x2030
movl 0x4(%rsp), %esi
jmp 0x35e4
movq 0x8(%rsp), %rax
movq 0x58(%rax), %rax
movl -0x2c(%rax,%r15), %eax
movl $0x8000, %ecx           # imm = 0x8000
orl %ecx, %eax
movq 0x90(%r12), %rcx
addq %r13, %rcx
movw %ax, (%rcx,%rbp,2)
decq %rbp
addq $-0x30, %r15
jmp 0x3561
testb $0x10, %sil
je 0x3602
cmpl %r14d, 0x20(%r12)
jae 0x3602
movl %r14d, 0x20(%r12)
movq 0x8(%rsp), %r13
movl 0x7c(%r13), %eax
btl $0x11, %eax
jb 0x3665
testb $0x1, %al
jne 0x3743
movq 0xb0(%r12), %r14
testb $0x10, %sil
jne 0x3631
movq %r13, %rdi
xorl %esi, %esi
callq 0x438f
testb $0x8, 0xe(%r12)
jne 0x36ab
movq 0x20(%r13), %r15
movq 0x48(%r13), %rbx
movl (%rbx), %ebp
pushq $0x1
popq %r13
cmpl %ebp, %r13d
ja 0x36a2
movl %r13d, %eax
shlq $0x4, %rax
movq 0x8(%rbx,%rax), %rsi
movq %r15, %rdi
callq 0x9564
incl %r13d
jmp 0x3647
movq 0x48(%r13), %rax
testq %rax, %rax
je 0x3693
movq $-0x1, (%rax)
testb $0x20, 0xe(%r12)
je 0x368e
btl $0x15, %esi
jae 0x3693
movq 0x48(%r13), %rax
movl $0x0, 0x8(%rax)
andq $0x0, 0x48(%r13)
andl $0x0, 0x78(%r13)
orb $0x1, 0x7c(%r13)
jmp 0x3743
andq $0x0, (%rbx)
movq 0x8(%rsp), %r13
leaq 0xb0(%r12), %rbx
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x78(%r13)
movq (%r13), %rax
testq %rax, %rax
je 0x36fb
andq $0x0, 0x8(%rax)
andb $-0x11, 0x7c(%rax)
movups 0x88(%r13), %xmm0
movups %xmm0, (%rbx)
movq 0x28(%r13), %rdi
callq 0xb1a5
movq 0x40(%r13), %rdi
callq 0xb1a5
movq 0x48(%r13), %rdi
callq 0x2030
jmp 0x3737
leaq 0x28(%r13), %rdi
callq 0xb1b4
movq 0x28(%r13), %rax
movq %rax, 0xc8(%r12)
andq $0x0, 0x60(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq 0x40(%r12), %rdi
movl $0x0, 0x4(%rsp)
testq %rdi, %rdi
je 0x3737
addq $0x40, %rdi
callq 0x2260
movq %r14, %rdi
callq 0xb1a5
movl 0x4(%rsp), %esi
testb $0x20, %sil
jne 0x3758
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2030