// File: /workspace/github_cpp_makefile_star2_O1/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 %rdx, %r14
movq %rdi, %r13
testl %esi, %esi
je 0xdbb2
movq $0x0, (%rsp)
jmp 0xdbbe
movq 0x40(%r13), %rax
addq $0x8, %rax
movq %rax, (%rsp)
movq 0x40(%r13), %rbx
movl 0x38(%rbx), %r15d
leal 0x1(%r15), %edi
shlq $0x2, %rdi
callq 0x2270
testq %rax, %rax
je 0xdd80
movq %rax, %r12
movl $0x0, (%rax)
testl %r15d, %r15d
je 0xdd88
movq %r14, 0x10(%rsp)
leaq 0x80(%rbx), %r10
addq $0x88, %rbx
movq %rbx, 0x20(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r13, 0x18(%rsp)
movq %r10, 0x8(%rsp)
movq %r14, %rax
shlq $0x6, %rax
movl 0x8(%r10,%rax), %ebp
testl %ebp, %ebp
je 0xdd67
cmpl 0x28(%r13), %ebp
je 0xdd67
movl (%r12), %eax
testl %eax, %eax
je 0xdc85
xorl %esi, %esi
movl %eax, %edx
movl %edx, %r9d
shrl %r9d
leal (%rsi,%r9), %ecx
incl %ecx
movl (%r12,%rcx,4), %r8d
movl %ebp, %edi
subl %r8d, %edi
movb $0x1, %r8b
js 0xdc60
jne 0xdc65
xorl %r8d, %r8d
jmp 0xdc6d
movl %r9d, %edx
jmp 0xdc6d
notl %r9d
addl %r9d, %edx
movl %ecx, %esi
testb %r8b, %r8b
je 0xdd67
testl %edx, %edx
jne 0xdc3f
xorl %edx, %edx
testl %edi, %edi
setg %dl
addl %edx, %ecx
jmp 0xdc8a
movl $0x1, %ecx
incl %eax
movl %eax, (%r12)
cmpl %ecx, %eax
jbe 0xdca9
movl %eax, %eax
movl %ecx, %ecx
movl -0x4(%r12,%rax,4), %edx
movl %edx, (%r12,%rax,4)
decq %rax
cmpq %rcx, %rax
ja 0xdc98
movl %eax, %eax
movl %ebp, (%r12,%rax,4)
movq %r13, %rdi
movl $0x5, %esi
movl %ebp, %edx
callq 0xa064
testl %eax, %eax
jne 0xdd62
movq (%rsp), %rax
testq %rax, %rax
je 0xdcfd
movq %rax, %rdi
movq %rax, (%rsp)
callq 0x2410
movq %r13, %rdi
testl %eax, %eax
je 0xdd02
movq (%rsp), %rsi
movl %eax, %edx
callq 0xddaf
movl %eax, %r13d
xorl %r15d, %r15d
movl %r14d, %eax
testl %r13d, %r13d
je 0xdd17
jmp 0xdd79
movl %r14d, %eax
jmp 0xdd17
movl $0x5, %esi
movl %ebp, %edx
callq 0xa064
testl %eax, %eax
movl %r15d, %eax
cmovel %r14d, %eax
cmpl %r15d, %eax
jae 0xdd4f
movl %eax, %eax
movl %r15d, %ecx
subq %rax, %rcx
shlq $0x6, %rax
addq 0x20(%rsp), %rax
movq 0x18(%rsp), %r13
movq (%rsp), %rdi
movl (%rax), %edx
cmpl %ebp, %edx
jne 0xdd44
movl $0x0, (%rax)
incl %ebx
addq $0x40, %rax
decq %rcx
jne 0xdd36
jmp 0xdd58
movq 0x18(%rsp), %r13
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xdd62
callq 0x2260
movq 0x8(%rsp), %r10
incq %r14
movl %r15d, %eax
cmpq %rax, %r14
jb 0xdc15
xorl %r13d, %r13d
movq 0x10(%rsp), %r14
jmp 0xdd8d
movl $0xc, %r13d
jmp 0xdd9d
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x2030
testq %r14, %r14
je 0xdd9d
movl %ebx, (%r14)
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq