// File: /workspace/github_c_makefile_star2_O0/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/StepCounterSensor.cpp
// Function: StepCounterSensor::readEvents(sensors_event_t*, int)
int StepCounterSensor::readEvents(sensors_event_t* data, int count)
{
	if (count < 1)
		return -EINVAL;

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

	int numEventReceived = 0;
	input_event const* event;

	while (count && mInputReader.readEvent(&event)) {

		if (event->type == EVENT_TYPE_STEP_C) {

#if (DEBUG_STEP_C == 1)
	STLOGD("StepCounterSensor::readEvents (event_code=%d)", event->code);
#endif
			switch(event->code) {
			case EVENT_TYPE_STEP_C_DATA:
				steps = (uint32_t)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("StepCounterSensor: 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.u64.step_counter = (uint64_t)steps;
			mPendingEvent.timestamp = timestamp;
			memcpy(data, &mPendingEvent, sizeof(mPendingEvent));
			data++;
			count--;
			numEventReceived++;
#if (DEBUG_STEP_C == 1)
			STLOGD("StepCounterSensor::readEvents (time = %lld), count(%d), received(%d), steps(%d)",
						mPendingEvent.timestamp,
						count, numEventReceived, steps);
#endif

		} else {
			STLOGE("StepCounterSensor: unknown event (type=%d, code=%d)",
						event->type, event->code);
		}
		mInputReader.next();
	}

	return numEventReceived;
}

// 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)
cmpl $0x1, -0x1c(%rbp)
jge 0x8ebd
movl $0xffffffea, -0x4(%rbp) # imm = 0xFFFFFFEA
jmp 0x9026
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x1028, %rdi           # imm = 0x1028
movl 0x1020(%rax), %esi
callq 0x50a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jge 0x8eed
movq -0x28(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x9026
movl $0x0, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x41(%rbp)
je 0x8f1d
movq -0x40(%rbp), %rdi
addq $0x1028, %rdi           # imm = 0x1028
leaq -0x38(%rbp), %rsi
callq 0x52a0
cmpq $0x0, %rax
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x8f29
jmp 0x9020
movq -0x38(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x4, %eax
jne 0x8fa6
movq -0x38(%rbp), %rax
movzwl 0x12(%rax), %eax
movl %eax, -0x48(%rbp)
testl %eax, %eax
je 0x8f5b
jmp 0x8f47
movl -0x48(%rbp), %eax
subl $0x4, %eax
je 0x8f6e
jmp 0x8f51
movl -0x48(%rbp), %eax
subl $0x7, %eax
je 0x8f87
jmp 0x8fa2
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x10c0(%rax)
jmp 0x8fa4
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq 0x14(%rcx), %rcx
shlq $0x20, %rcx
movq %rcx, 0x10b8(%rax)
jmp 0x8fa4
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movl 0x14(%rcx), %ecx
orq 0x10b8(%rax), %rcx
movq %rcx, 0x10b8(%rax)
jmp 0x8fa4
jmp 0x8fa4
jmp 0x900b
movq -0x38(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x9007
movq -0x40(%rbp), %rsi
movl 0x10c0(%rsi), %eax
movq %rax, 0x1068(%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 -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x9009
jmp 0x9009
jmp 0x900b
movq -0x40(%rbp), %rdi
addq $0x1028, %rdi           # imm = 0x1028
callq 0x5220
jmp 0x8ef4
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop