// File: /workspace/github_cpp_makefile_star2_O1/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
movl %esi, %ebp
movq %rdi, %rbx
movq 0x20(%rdi), %r15
movslq 0x78(%rdi), %rcx
movq %rcx, 0x8(%rsp)
cmpq $0x3, %rcx
jl 0x3937
movq 0x70(%rbx), %r12
movq 0x8(%rsp), %rax
leaq 0x1(%rax), %r13
shlq $0x4, %rax
leaq (%rax,%rax,2), %r14
testb $0x4, -0x2(%r12,%r13)
je 0x392a
testb $0x10, %bpl
jne 0x390d
movq 0x88(%r15), %rax
movq -0x28(%rax,%r14), %rdi
testq %rdi, %rdi
je 0x392a
xorps %xmm0, %xmm0
movups %xmm0, -0x30(%rax,%r14)
movq 0x90(%r15), %rax
movw $0x0, -0x4(%rax,%r13,2)
movq 0x98(%r15), %rax
incl -0x8(%rax,%r13,4)
callq 0x2030
jmp 0x392a
movq 0x58(%rbx), %rax
movl -0x2c(%rax,%r14), %eax
movl $0x8000, %ecx           # imm = 0x8000
orl %ecx, %eax
movq 0x90(%r15), %rcx
movw %ax, -0x4(%rcx,%r13,2)
decq %r13
addq $-0x30, %r14
cmpq $0x3, %r13
jg 0x38c3
testb $0x10, %bpl
je 0x3951
movq 0x8(%rsp), %rax
cmpl %eax, 0x20(%r15)
jae 0x3951
movq 0x8(%rsp), %rax
movl %eax, 0x20(%r15)
movl 0x7c(%rbx), %eax
btl $0x11, %eax
jb 0x3a42
testb $0x1, %al
jne 0x3abe
movq 0xb0(%r15), %r12
testb $0x10, %bpl
jne 0x397d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4098
testb $0x8, 0xe(%r15)
jne 0x39f1
movq %r12, 0x8(%rsp)
movq 0x48(%rbx), %rdx
movl (%rdx), %r12d
testl %r12d, %r12d
je 0x39e5
movq 0x20(%rbx), %r14
movl $0x1, %r13d
movl %ebp, 0x14(%rsp)
movl %r13d, %eax
shlq $0x4, %rax
movq 0x8(%rdx,%rax), %rdi
testb $0x4, 0xa(%rdi)
je 0x39bb
cmpl $0x1, 0xc(%rdi)
jne 0x39ce
movq 0xc0(%r14), %rax
movq %rax, (%rdi)
movq %rdi, 0xc0(%r14)
jmp 0x39dd
movq %rdx, %rbp
callq 0x2030
movq %rbp, %rdx
movl 0x14(%rsp), %ebp
incl %r13d
cmpl %r12d, %r13d
jbe 0x39a3
movq $0x0, (%rdx)
movq 0x8(%rsp), %r12
leaq 0xb0(%r15), %r14
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x78(%rbx)
movq (%rbx), %rax
testq %rax, %rax
je 0x3a7f
movq $0x0, 0x8(%rax)
andb $-0x11, 0x7c(%rax)
movups 0x88(%rbx), %xmm0
movups %xmm0, (%r14)
movq 0x28(%rbx), %rdi
callq 0xbf2d
movq 0x40(%rbx), %rdi
callq 0xbf2d
movq 0x48(%rbx), %rdi
callq 0x2030
jmp 0x3ab6
movq 0x48(%rbx), %rax
testq %rax, %rax
je 0x3a72
movq $-0x1, (%rax)
testb $0x20, 0xe(%r15)
je 0x3a6a
btl $0x15, %ebp
jae 0x3a72
movq 0x48(%rbx), %rax
movl $0x0, 0x8(%rax)
movq $0x0, 0x48(%rbx)
movl $0x0, 0x78(%rbx)
orb $0x1, 0x7c(%rbx)
jmp 0x3abe
leaq 0x28(%rbx), %rdi
callq 0xbf3c
movq 0x28(%rbx), %rax
movq %rax, 0xc8(%r15)
movq $0x0, 0x60(%r15)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq 0x40(%r15), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
je 0x3ab6
addq $0x40, %rdi
callq 0x2260
movq %r12, %rdi
callq 0xbf2d
testb $0x20, %bpl
jne 0x3ad3
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2030