// File: /workspace/github_cpp_makefile_star2_O1/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_txn_renew0
static int
mdb_txn_renew0(MDB_txn *txn)
{
	MDB_env *env = txn->mt_env;
	MDB_txninfo *ti = env->me_txns;
	MDB_meta *meta;
	unsigned int i, nr, flags = txn->mt_flags;
	uint16_t x;
	int rc, new_notls = 0;

	if ((flags &= MDB_TXN_RDONLY) != 0) {
		if (!ti) {
			meta = mdb_env_pick_meta(env);
			txn->mt_txnid = meta->mm_txnid;
			txn->mt_u.reader = NULL;
		} else {
			MDB_reader *r = (env->me_flags & MDB_NOTLS) ? txn->mt_u.reader :
				pthread_getspecific(env->me_txkey);
			if (r) {
				if (r->mr_pid != env->me_pid || r->mr_txnid != (txnid_t)-1)
					return MDB_BAD_RSLOT;
			} else {
				MDB_PID_T pid = env->me_pid;
				MDB_THR_T tid = pthread_self();
				mdb_mutexref_t rmutex = env->me_rmutex;

				if (!env->me_live_reader) {
					rc = mdb_reader_pid(env, Pidset, pid);
					if (rc)
						return rc;
					env->me_live_reader = 1;
				}

				if (LOCK_MUTEX(rc, env, rmutex))
					return rc;
				nr = ti->mti_numreaders;
				for (i=0; i<nr; i++)
					if (ti->mti_readers[i].mr_pid == 0)
						break;
				if (i == env->me_maxreaders) {
					UNLOCK_MUTEX(rmutex);
					return MDB_READERS_FULL;
				}
				r = &ti->mti_readers[i];
				/* Claim the reader slot, carefully since other code
				 * uses the reader table un-mutexed: First reset the
				 * slot, next publish it in mti_numreaders.  After
				 * that, it is safe for mdb_env_close() to touch it.
				 * When it will be closed, we can finally claim it.
				 */
				r->mr_pid = 0;
				r->mr_txnid = (txnid_t)-1;
				r->mr_tid = tid;
				if (i == nr)
					ti->mti_numreaders = ++nr;
				env->me_close_readers = nr;
				r->mr_pid = pid;
				UNLOCK_MUTEX(rmutex);

				new_notls = (env->me_flags & MDB_NOTLS);
				if (!new_notls && (rc=pthread_setspecific(env->me_txkey, r))) {
					r->mr_pid = 0;
					return rc;
				}
			}
			do /* LY: Retry on a race, ITS#7970. */
				r->mr_txnid = ti->mti_txnid;
			while(r->mr_txnid != ti->mti_txnid);
			txn->mt_txnid = r->mr_txnid;
			txn->mt_u.reader = r;
			meta = env->me_metas[txn->mt_txnid & 1];
		}

	} else {
		/* Not yet touching txn == env->me_txn0, it may be active */
		if (ti) {
			if (LOCK_MUTEX(rc, env, env->me_wmutex))
				return rc;
			txn->mt_txnid = ti->mti_txnid;
			meta = env->me_metas[txn->mt_txnid & 1];
		} else {
			meta = mdb_env_pick_meta(env);
			txn->mt_txnid = meta->mm_txnid;
		}
		txn->mt_txnid++;
#if MDB_DEBUG
		if (txn->mt_txnid == mdb_debug_start)
			mdb_debug = 1;
#endif
		txn->mt_child = NULL;
		txn->mt_loose_pgs = NULL;
		txn->mt_loose_count = 0;
		txn->mt_dirty_room = MDB_IDL_UM_MAX;
		txn->mt_u.dirty_list = env->me_dirty_list;
		txn->mt_u.dirty_list[0].mid = 0;
		txn->mt_free_pgs = env->me_free_pgs;
		txn->mt_free_pgs[0] = 0;
		txn->mt_spill_pgs = NULL;
		env->me_txn = txn;
		memcpy(txn->mt_dbiseqs, env->me_dbiseqs, env->me_maxdbs * sizeof(unsigned int));
	}

	/* Copy the DB info and flags */
	memcpy(txn->mt_dbs, meta->mm_dbs, CORE_DBS * sizeof(MDB_db));

	/* Moved to here to avoid a data race in read TXNs */
	txn->mt_next_pgno = meta->mm_last_pg+1;

	txn->mt_flags = flags;

	/* Setup db info */
	txn->mt_numdbs = env->me_numdbs;
	for (i=CORE_DBS; i<txn->mt_numdbs; i++) {
		x = env->me_dbflags[i];
		txn->mt_dbs[i].md_flags = x & PERSISTENT_FLAGS;
		txn->mt_dbflags[i] = (x & MDB_VALID) ? DB_VALID|DB_USRVALID|DB_STALE : 0;
	}
	txn->mt_dbflags[MAIN_DBI] = DB_VALID|DB_USRVALID;
	txn->mt_dbflags[FREE_DBI] = DB_VALID;

	if (env->me_flags & MDB_FATAL_ERROR) {
		DPUTS("environment had fatal error, must shutdown!");
		rc = MDB_PANIC;
	} else if (env->me_maxpg < txn->mt_next_pgno) {
		rc = MDB_MAP_RESIZED;
	} else {
		return MDB_SUCCESS;
	}
	mdb_txn_end(txn, new_notls /*0 or MDB_END_SLOT*/ | MDB_END_FAIL_BEGIN);
	return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x20(%rdi), %r14
movq 0x40(%r14), %rbp
movl $0x20000, %r13d         # imm = 0x20000
andl 0x7c(%rdi), %r13d
jne 0x315a
testq %rbp, %rbp
je 0x3182
leaq 0x40(%rbp), %rdi
callq 0x2410
testl %eax, %eax
je 0x3148
movq 0x40(%r14), %rsi
addq $0x40, %rsi
movq %r14, %rdi
movl %eax, %edx
callq 0xddaf
testl %eax, %eax
jne 0x3411
movq 0x30(%rbp), %rax
movq %rax, 0x18(%rbx)
andl $0x1, %eax
movq 0x48(%r14,%rax,8), %r12
jmp 0x31ae
testq %rbp, %rbp
je 0x320f
testb $0x20, 0xe(%r14)
jne 0x324b
movl 0xa0(%r14), %edi
callq 0x20b0
movq %rax, %r12
jmp 0x324f
movq 0x48(%r14), %rax
movq 0x80(%rax), %rax
movq 0x50(%r14), %rcx
xorl %edx, %edx
cmpq 0x80(%rcx), %rax
setb %dl
movq 0x48(%r14,%rdx,8), %r12
movq 0x80(%r12), %rax
movq %rax, 0x18(%rbx)
incq 0x18(%rbx)
xorl %r15d, %r15d
movq %r15, 0x8(%rbx)
movq %r15, 0x30(%rbx)
movl $0x0, 0x38(%rbx)
movl $0x1ffff, 0x80(%rbx)    # imm = 0x1FFFF
movq 0xd0(%r14), %rax
movq %rax, 0x48(%rbx)
movq %r15, (%rax)
movq 0xc8(%r14), %rax
movq %rax, 0x28(%rbx)
movq %r15, (%rax)
movq %r15, 0x40(%rbx)
movq %rbx, 0x60(%r14)
movq 0x60(%rbx), %rdi
movq 0x98(%r14), %rsi
movl 0x24(%r14), %edx
shlq $0x2, %rdx
callq 0x2240
jmp 0x3358
movq 0x48(%r14), %rax
movq 0x80(%rax), %rax
movq 0x50(%r14), %rcx
xorl %edx, %edx
cmpq 0x80(%rcx), %rax
setb %dl
movq 0x48(%r14,%rdx,8), %r12
movq 0x80(%r12), %rax
movq %rax, 0x18(%rbx)
movq $0x0, 0x48(%rbx)
xorl %r15d, %r15d
jmp 0x3358
movq 0x48(%rbx), %r12
testq %r12, %r12
je 0x327a
movl 0x8(%r12), %ecx
movl $0xffff87c1, %eax       # imm = 0xFFFF87C1
cmpl 0x28(%r14), %ecx
jne 0x32d9
movq (%r12), %rcx
xorl %r15d, %r15d
cmpq $-0x1, %rcx
jne 0x334e
jmp 0x3324
movl 0x28(%r14), %r12d
callq 0x22f0
movq %rax, (%rsp)
movq 0x40(%r14), %r15
cmpl $0x0, 0xe0(%r14)
je 0x32de
addq $0x8, %r15
movq %r15, %rdi
callq 0x2410
testl %eax, %eax
je 0x32b6
movq %r14, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0xddaf
testl %eax, %eax
jne 0x3318
movl 0x38(%rbp), %eax
testl %eax, %eax
je 0x32ff
leaq 0x88(%rbp), %rdx
xorl %ecx, %ecx
cmpl $0x0, (%rdx)
je 0x3301
incl %ecx
addq $0x40, %rdx
cmpl %ecx, %eax
jne 0x32c6
movl %eax, %ecx
jmp 0x3301
xorl %r15d, %r15d
jmp 0x334e
movq %r14, %rdi
movl $0x6, %esi
movl %r12d, %edx
callq 0xa064
testl %eax, %eax
jne 0x3318
movl $0x1, 0xe0(%r14)
jmp 0x3295
xorl %ecx, %ecx
cmpl 0x18(%r14), %ecx
jne 0x3420
movq %r15, %rdi
callq 0x2260
movl $0xffff87ba, %eax       # imm = 0xFFFF87BA
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %ecx, %ecx
testb %cl, %cl
je 0x334e
movq 0x30(%rbp), %rcx
movq %rcx, (%r12)
movq (%r12), %rcx
cmpq 0x30(%rbp), %rcx
jne 0x3324
movq (%r12), %rcx
movq %rcx, 0x18(%rbx)
movq %r12, 0x48(%rbx)
andl $0x1, %ecx
movq 0x48(%r14,%rcx,8), %r12
movb $0x1, %cl
jmp 0x3350
xorl %ecx, %ecx
testb %cl, %cl
je 0x3411
movq 0x58(%rbx), %rdi
leaq 0x18(%r12), %rsi
movl $0xc, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq 0x78(%r12), %rax
incq %rax
movq %rax, 0x10(%rbx)
movl %r13d, 0x7c(%rbx)
movl 0x20(%r14), %eax
movl %eax, 0x78(%rbx)
cmpl $0x3, %eax
jb 0x33cf
movl $0x2, %eax
movl $0x32, %ecx
xorl %edx, %edx
movq 0x90(%r14), %rsi
movzwl (%rsi,%rax,2), %esi
movl %esi, %edi
andl $0x7fff, %edi           # imm = 0x7FFF
movq 0x58(%rbx), %r8
movw %di, (%r8,%rcx,2)
testw %si, %si
movl $0x1a, %esi
cmovnsl %edx, %esi
movq 0x70(%rbx), %rdi
movb %sil, (%rdi,%rax)
incq %rax
movl 0x78(%rbx), %esi
addq $0x18, %rcx
cmpq %rsi, %rax
jb 0x3391
movq 0x70(%rbx), %rax
movb $0x18, 0x1(%rax)
movq 0x70(%rbx), %rax
movb $0x8, (%rax)
cmpl $0x0, 0xc(%r14)
js 0x33fb
movq 0x80(%r14), %rcx
xorl %eax, %eax
movl $0xffff87bf, %ebp       # imm = 0xFFFF87BF
cmpq 0x10(%rbx), %rcx
jb 0x3400
jmp 0x3411
movl $0xffff87b5, %ebp       # imm = 0xFFFF87B5
orl $0x5, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3884
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r12d, %esi
movl %ecx, %edx
shlq $0x6, %rdx
leaq (%rdx,%rbp), %r12
addq $0x80, %r12
movl $0x0, 0x8(%r12)
movq $-0x1, (%r12)
movq (%rsp), %rdx
movq %rdx, 0x10(%r12)
cmpl %eax, %ecx
jne 0x3457
incl %eax
movl %eax, 0x38(%rbp)
movl %eax, 0x1c(%r14)
movl %esi, 0x8(%r12)
movq %r15, %rdi
callq 0x2260
movl $0x200000, %r15d        # imm = 0x200000
movb $0x1, %cl
andl 0xc(%r14), %r15d
jne 0x349a
movl 0xa0(%r14), %edi
movq %r12, %rsi
callq 0x2420
testl %eax, %eax
je 0x349f
movl $0x0, 0x8(%r12)
xorl %r15d, %r15d
jmp 0x331e
jmp 0x3320
movb $0x1, %cl
jmp 0x3320