// File: /workspace/github_cpp_makefile_star2_O2/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), %r14
leaq 0x8(%r14), %r13
xorl %r15d, %r15d
movl %esi, 0xc(%rsp)
testl %esi, %esi
cmovneq %r15, %r13
movq %rdx, %rbx
movl 0x38(%r14), %ebp
leal 0x1(%rbp), %edi
shlq $0x2, %rdi
callq 0x2270
testq %rax, %rax
je 0xceae
movq %rax, %r12
movq %r13, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
andl $0x0, (%rax)
leaq 0x80(%r14), %r13
addq $0x88, %r14
movq %r14, 0x20(%rsp)
xorl %r14d, %r14d
movq (%rsp), %rdi
movl %ebp, %eax
cmpq %rax, %r14
jae 0xce95
movq %r14, %rax
shlq $0x6, %rax
movl 0x8(%r13,%rax), %ebx
testl %ebx, %ebx
je 0xce7e
cmpl 0x28(%rdi), %ebx
je 0xce7e
movl (%r12), %eax
xorl %ecx, %ecx
pushq $0x1
popq %r9
xorl %esi, %esi
movl %eax, %edx
movl %ecx, %r8d
incl %r8d
movl %r9d, %ecx
testl %edx, %edx
je 0xcdbb
movl %edx, %r10d
shrl %edx
leal (%r8,%rdx), %ecx
xorl %esi, %esi
cmpl (%r12,%rcx,4), %ebx
jl 0xcd90
je 0xce7e
notl %edx
addl %edx, %r10d
movl %ecx, %r9d
pushq $0x1
popq %rsi
movl %r10d, %edx
jmp 0xcd87
addl %esi, %ecx
incl %eax
movl %eax, (%r12)
cmpq %rcx, %rax
jbe 0xcddb
leaq -0x1(%rax), %rdx
movl %edx, %esi
movl (%r12,%rsi,4), %esi
movl %esi, (%r12,%rax,4)
movq %rdx, %rax
jmp 0xcdc3
movl %eax, %eax
movl %ebx, (%r12,%rax,4)
pushq $0x5
popq %rsi
movl %ebx, %edx
callq 0x94eb
testl %eax, %eax
je 0xcdf8
movq (%rsp), %rdi
jmp 0xce7e
cmpl $0x0, 0xc(%rsp)
je 0xce04
movl %r14d, %ecx
jmp 0xce46
movq 0x10(%rsp), %rdi
callq 0x2420
testl %eax, %eax
je 0xce30
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %eax, %edx
callq 0xcec6
xorl %ebp, %ebp
movl %r14d, %ecx
testl %eax, %eax
je 0xce46
jmp 0xcec2
movq (%rsp), %rdi
pushq $0x5
popq %rsi
movl %ebx, %edx
callq 0x94eb
testl %eax, %eax
movl %ebp, %ecx
cmovel %r14d, %ecx
movl %ecx, %eax
movl %ebp, %ecx
movq %rax, %rdx
shlq $0x6, %rdx
addq 0x20(%rsp), %rdx
movq (%rsp), %rdi
cmpq %rcx, %rax
jae 0xce77
movl (%rdx), %esi
cmpl %ebx, %esi
jne 0xce6e
movl $0x0, (%rdx)
incl %r15d
incq %rax
addq $0x40, %rdx
jmp 0xce5a
cmpl $0x0, 0xc(%rsp)
je 0xce86
incq %r14
jmp 0xcd51
movq 0x10(%rsp), %rdi
callq 0x2260
jmp 0xcdef
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x2030
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0xceb1
movl %r15d, (%rax)
jmp 0xceb1
pushq $0xc
popq %rbx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %ebx
jmp 0xce97