// File: /workspace/github_cpp_makefile_star2_O3/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_reader_check0
static int ESECT
mdb_reader_check0(MDB_env *env, int rlocked, int *dead)
{
	mdb_mutexref_t rmutex = rlocked ? NULL : env->me_rmutex;
	unsigned int i, j, rdrs;
	MDB_reader *mr;
	MDB_PID_T *pids, pid;
	int rc = MDB_SUCCESS, count = 0;

	rdrs = env->me_txns->mti_numreaders;
	pids = malloc((rdrs+1) * sizeof(MDB_PID_T));
	if (!pids)
		return ENOMEM;
	pids[0] = 0;
	mr = env->me_txns->mti_readers;
	for (i=0; i<rdrs; i++) {
		pid = mr[i].mr_pid;
		if (pid && pid != env->me_pid) {
			if (mdb_pid_insert(pids, pid) == 0) {
				if (!mdb_reader_pid(env, Pidcheck, pid)) {
					/* Stale reader found */
					j = i;
					if (rmutex) {
						if ((rc = LOCK_MUTEX0(rmutex)) != 0) {
							if ((rc = mdb_mutex_failed(env, rmutex, rc)))
								break;
							rdrs = 0; /* the above checked all readers */
						} else {
							/* Recheck, a new process may have reused pid */
							if (mdb_reader_pid(env, Pidcheck, pid))
								j = rdrs;
						}
					}
					for (; j<rdrs; j++)
							if (mr[j].mr_pid == pid) {
								DPRINTF(("clear stale reader pid %u txn %"Z"d",
									(unsigned) pid, mr[j].mr_txnid));
								mr[j].mr_pid = 0;
								count++;
							}
					if (rmutex)
						UNLOCK_MUTEX(rmutex);
				}
			}
		}
	}
	free(pids);
	if (dead)
		*dead = count;
	return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, (%rsp)
movq 0x40(%rdi), %rbp
leaq 0x8(%rbp), %r13
xorl %ebx, %ebx
movl %esi, 0xc(%rsp)
testl %esi, %esi
cmovneq %rbx, %r13
movq %rdx, %r14
movl 0x38(%rbp), %r15d
leal 0x1(%r15), %edi
shlq $0x2, %rdi
callq 0x2270
testq %rax, %rax
je 0xd925
movq %rax, %r12
movq %r13, 0x10(%rsp)
movl $0x0, (%rax)
movl $0x0, %r13d
testl %r15d, %r15d
je 0xd913
movq %r14, 0x18(%rsp)
movq %rbp, %rax
addq $0x80, %rbp
addq $0x88, %rax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq (%rsp), %rdi
movq %r14, %rax
shlq $0x6, %rax
movl 0x8(%rbp,%rax), %r13d
testl %r13d, %r13d
je 0xd8db
cmpl 0x28(%rdi), %r13d
je 0xd8db
movl (%r12), %eax
testl %eax, %eax
je 0xd827
xorl %edx, %edx
movl %eax, %r9d
movl %r9d, %r8d
shrl %r8d
leal (%rdx,%r8), %ecx
incl %ecx
movl %r13d, %esi
subl (%r12,%rcx,4), %esi
js 0xd814
je 0xd8db
notl %r8d
addl %r8d, %r9d
movl %ecx, %edx
movl %r9d, %r8d
movl %r8d, %r9d
testl %r8d, %r8d
jne 0xd7ee
xorl %edx, %edx
testl %esi, %esi
setg %dl
addl %edx, %ecx
jmp 0xd82c
movl $0x1, %ecx
incl %eax
movl %eax, (%r12)
cmpl %ecx, %eax
jbe 0xd84b
movl %eax, %eax
movl %ecx, %ecx
movl -0x4(%r12,%rax,4), %edx
movl %edx, (%r12,%rax,4)
decq %rax
cmpq %rcx, %rax
ja 0xd83a
movl %eax, %eax
movl %r13d, (%r12,%rax,4)
movl $0x5, %esi
movl %r13d, %edx
callq 0x9c89
testl %eax, %eax
jne 0xd8d7
cmpl $0x0, 0xc(%rsp)
je 0xd8a8
movl %r14d, %ecx
movl %r15d, %eax
subl %ecx, %eax
jbe 0xd89b
movl %ecx, %ecx
shlq $0x6, %rcx
addq 0x20(%rsp), %rcx
movq (%rsp), %rdi
movl (%rcx), %edx
cmpl %r13d, %edx
jne 0xd891
movl $0x0, (%rcx)
incl %ebx
addq $0x40, %rcx
decl %eax
jne 0xd882
jmp 0xd89f
movq (%rsp), %rdi
cmpl $0x0, 0xc(%rsp)
jne 0xd8db
jmp 0xd8cd
movq 0x10(%rsp), %rdi
callq 0x2410
testl %eax, %eax
je 0xd8ec
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %eax, %edx
callq 0xd942
xorl %r15d, %r15d
testl %eax, %eax
jne 0xd93d
movq 0x10(%rsp), %rdi
callq 0x2260
movq (%rsp), %rdi
incq %r14
movl %r15d, %eax
cmpq %rax, %r14
jb 0xd7c2
jmp 0xd90b
movq (%rsp), %rdi
movl $0x5, %esi
movl %r13d, %edx
callq 0x9c89
testl %eax, %eax
movl %r15d, %ecx
cmovel %r14d, %ecx
jmp 0xd86c
xorl %r13d, %r13d
movq 0x18(%rsp), %r14
movq %r12, %rdi
callq 0x2030
testq %r14, %r14
je 0xd92b
movl %ebx, (%r14)
jmp 0xd92b
movl $0xc, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r13d
jmp 0xd90e