// File: /workspace/github_c_makefile_star2_O0/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/TiltSensor.cpp
// Function: TiltSensor::readEvents(sensors_event_t*, int)
int TiltSensor::readEvents(sensors_event_t* data, int count)
{
	int numEventReceived = 0;
	input_event const* event;

	if (count < 1)
		return -EINVAL;

	ssize_t n = mInputReader.fill(data_fd);
	if (n < 0)
		return n;

	while (count && mInputReader.readEvent(&event)) {
		if (event->type == EVENT_TYPE_TILT) {
#if (DEBUG_TILT == 1)
	STLOGD("TiltSensor::readEvents (event_code=%d)", event->code);
#endif
			switch(event->code) {
			case EVENT_TYPE_TILT_DATA:
				tilt_data = event->value;

				break;
#if defined(INPUT_EVENT_HAS_TIMESTAMP)
			case EVENT_TYPE_TIME_MSB:
				timestamp = ((int64_t)(event->value)) << 32;

				break;
			case EVENT_TYPE_TIME_LSB:
				timestamp |= (uint32_t)(event->value);

				break;
#endif
			default:
				STLOGE("TiltSensor: unknown event code (type = %d, code = %d)",
							event->type, event->code);
			}
		} else if (event->type == EV_SYN) {
#if !defined(INPUT_EVENT_HAS_TIMESTAMP)
			timestamp = timevalToNano(event->time);
#endif
			mPendingEvent.timestamp = timestamp;
			memcpy(data, &mPendingEvent, sizeof(mPendingEvent));
			data++;
			count--;
			numEventReceived++;
#if (DEBUG_TILT == 1)
			STLOGD("TiltSensor::readEvents (time = %lld), count(%d), received(%d)",
						mPendingEvent.timestamp,
						count, numEventReceived);
#endif
		} else {
			STLOGE("TiltSensor: unknown event (type=%d, code=%d)",
						event->type, event->code);
		}
		mInputReader.next();
	}

	return numEventReceived;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x1, -0x1c(%rbp)
jge 0x96d4
movl $0xffffffea, -0x4(%rbp) # imm = 0xFFFFFFEA
jmp 0x982b
movq -0x38(%rbp), %rax
movq %rax, %rdi
addq $0x1028, %rdi           # imm = 0x1028
movl 0x1020(%rax), %esi
callq 0x50a0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jge 0x9704
movq -0x30(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x982b
jmp 0x9706
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x39(%rbp)
je 0x972f
movq -0x38(%rbp), %rdi
addq $0x1028, %rdi           # imm = 0x1028
leaq -0x28(%rbp), %rsi
callq 0x52a0
cmpq $0x0, %rax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x973b
jmp 0x9825
movq -0x28(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x4, %eax
jne 0x97b8
movq -0x28(%rbp), %rax
movzwl 0x12(%rax), %eax
movl %eax, -0x40(%rbp)
testl %eax, %eax
je 0x976d
jmp 0x9759
movl -0x40(%rbp), %eax
subl $0x4, %eax
je 0x9780
jmp 0x9763
movl -0x40(%rbp), %eax
subl $0x7, %eax
je 0x9799
jmp 0x97b4
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x10c0(%rax)
jmp 0x97b6
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq 0x14(%rcx), %rcx
shlq $0x20, %rcx
movq %rcx, 0x10b8(%rax)
jmp 0x97b6
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x14(%rcx), %ecx
orq 0x10b8(%rax), %rcx
movq %rcx, 0x10b8(%rax)
jmp 0x97b6
jmp 0x97b6
jmp 0x9810
movq -0x28(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x980c
movq -0x38(%rbp), %rsi
movq 0x10b8(%rsi), %rax
movq %rax, 0x1060(%rsi)
movq -0x18(%rbp), %rdi
addq $0x1050, %rsi           # imm = 0x1050
movl $0x68, %edx
callq 0x51a0
movq -0x18(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x980e
jmp 0x980e
jmp 0x9810
movq -0x38(%rbp), %rdi
addq $0x1028, %rdi           # imm = 0x1028
callq 0x5220
jmp 0x9706
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq