// File: /workspace/github_c_makefile_star2_O0/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/sensors.cpp
// Function: sensors_poll_context_t::pollEvents(sensors_event_t*, int)
int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count)
{
	int nbEvents = 0;
	int n = 0;

	do {
		if (count) {
			n = poll(mPollFds, numFds, nbEvents ? 0 : -1);
			if (n < 0) {
				STLOGE("poll() failed (%s)", strerror(errno));
				return -errno;
			}
		}
		for (int i=0 ; count && i<numSensorDrivers ; i++) {
			SensorBase* const sensor(mSensors[i]);
			if((mPollFds[i].revents & POLLIN) || (sensor->hasPendingEvents()))
			{
				int nb = sensor->readEvents(data, count);
				if (nb < count) {
					mPollFds[i].revents = 0;
				}
				count -= nb;
				nbEvents += nb;
				data += nb;
			}
		}
#if (ANDROID_VERSION >= ANDROID_JBMR2)
		if(mPollFds[flushFD].revents & POLLIN && count) {
			if (read(mPollFds[flushFD].fd, data, sizeof(struct sensors_event_t)) > 0) {
				count--;
				nbEvents++;
				data++;
			}
			mPollFds[flushFD].revents = 0;
		}
#endif
	} while (n && count);

	return nbEvents;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x6513
movq -0x40(%rbp), %rdi
addq $0xe0, %rdi
movl -0x20(%rbp), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %eax, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
movl $0x7, %esi
callq 0x5380
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x6511
callq 0x5070
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x4(%rbp)
jmp 0x6664
jmp 0x6513
movl $0x0, -0x28(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x41(%rbp)
je 0x652f
cmpl $0x6, -0x28(%rbp)
setl %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x653b
jmp 0x65da
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0x120(%rax,%rcx,8), %rcx
movq %rcx, -0x30(%rbp)
movslq -0x28(%rbp), %rcx
movswl 0xe6(%rax,%rcx,8), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x6573
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb $0x1, %al
jne 0x6573
jmp 0x65ca
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq (%rdi), %rax
callq *0x10(%rax)
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x65a1
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
movw $0x0, 0xe6(%rax,%rcx,8)
movl -0x34(%rbp), %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x34(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
jmp 0x65cc
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x651a
movq -0x40(%rbp), %rax
movswl 0x116(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x663c
cmpl $0x0, -0x1c(%rbp)
je 0x663c
movq -0x40(%rbp), %rax
movl 0x110(%rax), %edi
movq -0x18(%rbp), %rsi
movl $0x68, %edx
callq 0x5330
cmpq $0x0, %rax
jle 0x662f
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rax
movw $0x0, 0x116(%rax)
jmp 0x663e
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x42(%rbp)
je 0x6653
cmpl $0x0, -0x1c(%rbp)
setne %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
testb $0x1, %al
jne 0x64c9
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)