// File: /workspace/github_c_makefile_star2_O0/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/AccelSensor.cpp
// Function: AccelSensor::readEvents(sensors_event_t*, int)
int AccelSensor::readEvents(sensors_event_t* data, int count)
{
	float AccOffset[3] = { 0 };
	if (count < 1)
		return -EINVAL;

	if (mHasPendingEvent) {
		mHasPendingEvent = false;
	}

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

	int numEventReceived = 0;
	input_event const* event;

#if (FETCH_FULL_EVENT_BEFORE_RETURN)
	again:
#endif
	while (count && mInputReader.readEvent(&event)) {
		if (event->type == EVENT_TYPE_ACCEL) {
#if (DEBUG_ACCELEROMETER == 1)
	STLOGD("%s: (event_code=%d)", __func__, event->code);
#endif
			float value = (float) event->value;
			if (event->code == EVENT_TYPE_ACCEL_X) {
				data_raw[0] = value * CONVERT_A_X;
			}
			else if (event->code == EVENT_TYPE_ACCEL_Y) {
				data_raw[1] = value * CONVERT_A_Y;
			}
			else if (event->code == EVENT_TYPE_ACCEL_Z) {
				data_raw[2] = value * CONVERT_A_Z;
			}
#if defined(ACC_EVENT_HAS_TIMESTAMP)
			else if (event->code == EVENT_TYPE_TIME_MSB) {
				timestamp = ((int64_t)(event->value)) << 32;
			}
			else if (event->code == EVENT_TYPE_TIME_LSB) {
				timestamp |= (uint32_t)(event->value);
			}
#endif
#if (SENSORS_SIGNIFICANT_MOTION_ENABLE == 1)
			else if (event->code == EVENT_TYPE_SIGNIFICANT_MOTION) {

				if(mEnabled & (1<<SignificantMotion)) {
					mPendingEvents[SignificantMotion].data[0] = value;
					mPendingEvents[SignificantMotion].timestamp = timevalToNano(event->time);
					mPendingMask |= 1<<SignificantMotion;
  #if (DEBUG_ACCELEROMETER == 1)
					STLOGD("%s: SignificantMotion event type (type = %d, code = %d)",
						__func__, event->type, event->code);
  #endif
				}
			}
#endif
			else
				STLOGE("%s: unknown event code (type = %d, code = %d)",
					__func__, event->type, event->code);
		} else if (event->type == EV_SYN) {
			data_rot[0] = data_raw[0]*matrix_acc[0][0] +
					data_raw[1]*matrix_acc[1][0] +
					data_raw[2]*matrix_acc[2][0];
			data_rot[1] = data_raw[0]*matrix_acc[0][1] +
					data_raw[1]*matrix_acc[1][1] +
					data_raw[2]*matrix_acc[2][1];
			data_rot[2] = data_raw[0]*matrix_acc[0][2] +
					data_raw[1]*matrix_acc[1][2] +
					data_raw[2]*matrix_acc[2][2];
#if !defined(ACC_EVENT_HAS_TIMESTAMP)
			timestamp = timevalToNano(event->time);

#endif
#if (ACCEL_CALIBRATION_ENABLE == 1)
			accCalibIn.timestamp = timestamp;
			accCalibIn.acc_raw[0] = data_rot[0];
			accCalibIn.acc_raw[1] = data_rot[1];
			accCalibIn.acc_raw[2] = data_rot[2];

			ST_AccCalibration_API_Run(&accCalibOut, &accCalibIn);
#if (DEBUG_ACCELEROMETER == 1)
			STLOGD("%s: Calibration accData [uT] -> raw_x:%f raw_y:%f raw_z:%f",
				__func__,
				data_rot[0], data_rot[1], data_rot[2]);
			STLOGD("%s: Calibration accData [uT] -> uncal_x:%f uncal_y:%f uncal_z:%f",
				__func__,
				accCalibOut.acc_cal[0],
				accCalibOut.acc_cal[1],
				accCalibOut.acc_cal[2]);
#endif /* DEBUG_ACCELEROMETER */
#endif /* ACCEL_CALIBRATION_ENABLE */

			DecimationCount++;

			if ((mEnabled & ((1<<Acceleration) |
			    (1<<AccelUncalib))) &&
			    ((DecimationCount >= DecimationBuffer[Acceleration]) ||
			     (DecimationCount >= DecimationBuffer[AccelUncalib]))) {
				DecimationCount = 0;

#if (ACCEL_CALIBRATION_ENABLE == 1)
				data_calibrated.v[0] = accCalibOut.acc_cal[0];
				data_calibrated.v[1] = accCalibOut.acc_cal[1];
				data_calibrated.v[2] = accCalibOut.acc_cal[2];
				data_calibrated.status = accCalibOut.accuracy;
				AccOffset[0] = accCalibOut.offset[0];
				AccOffset[1] = accCalibOut.offset[1];
				AccOffset[2] = accCalibOut.offset[2];

#if (DEBUG_ACCELEROMETER == 1)
				STLOGD("%s: AccCalibData: %f, %f, %f (accuracy: %d) (off: %f 5f %f)",
					__func__,
					data_calibrated.v[0],
					data_calibrated.v[1],
					data_calibrated.v[2],
					data_calibrated.status,
					AccOffset[0],
					AccOffset[1],
					AccOffset[2]);
#endif /* DEBUG_ACCELEROMETER */
#else
				/**
				 * No calibration is available!
				 */
				memcpy(data_calibrated.v, data_rot,
				       sizeof(data_calibrated.v));
				data_calibrated.status = SENSOR_STATUS_UNRELIABLE;
#endif
				if (mEnabled & (1<<Acceleration)) {
					mPendingEvents[Acceleration].acceleration.status = data_calibrated.status;
					memcpy(mPendingEvents[Acceleration].data,
					       data_calibrated.v, sizeof(data_calibrated.v));
					mPendingEvents[Acceleration].timestamp = timestamp;
					mPendingMask |= 1<<Acceleration;
				}
#if (SENSORS_UNCALIB_ACCELEROMETER_ENABLE == 1)
				if (mEnabled & (1<<AccelUncalib)) {
					mPendingEvents[AccelUncalib].acceleration.status = data_calibrated.status;
					memcpy(mPendingEvents[AccelUncalib].uncalibrated_accelerometer.uncalib,
					       data_rot, sizeof(data_rot));
					memcpy(mPendingEvents[AccelUncalib].uncalibrated_accelerometer.bias,
					       AccOffset, sizeof(AccOffset));
					mPendingEvents[AccelUncalib].timestamp = timestamp;
					mPendingMask |= 1<<AccelUncalib;
				}
#endif
			}

#if (SENSORS_ACTIVITY_RECOGNIZER_ENABLE == 1)
			if (mEnabled & (1<<ActivityReco)) {
				int activity_changed = 0;

				mPendingEvents[ActivityReco].data[0] =
						(float)ActivityRecognizerFunction(
							-MS2_TO_G(data_rot[0]),
							-MS2_TO_G(data_rot[1]),
							-MS2_TO_G(data_rot[2]),
							&activity_changed);
				if (activity_changed != 0) {
#if (DEBUG_ACTIVITY_RECO == 1)
					ALOGD("ActivityRecognizerSensor::readEvents, activity = %d",
					      mPendingEvents[ActivityReco].data[0]);
#endif

					mPendingEvents[ActivityReco].timestamp = timestamp;
					mPendingMask |= 1<<ActivityReco;
				}
			}
#endif

			if (mEnabled & ((1<<iNemoAcceleration) |
					(1<<MagCalAcceleration) |
					(1<<GeoMagRotVectAcceleration) |
					(1<<Orientation) |
					(1<<Linear_Accel) |
					(1<<Gravity_Accel) |
					(1<<Gbias) |
					(1<<VirtualGyro)))
			{
				sensors_vec_t sData;
				memcpy(sData.v, data_rot, sizeof(data_rot));
				setBufferData(&sData);
			}

#if (DEBUG_ACCELEROMETER == 1)
			STLOGD("%s: Acceleration::readEvents (time = %lld), count(%d), received(%d)",
				__func__,
				mPendingEvents[Acceleration].timestamp,
				count, numEventReceived);
#endif
		} else {
			STLOGE("%s: AccelSensor: unknown event type (type = %d, code = %d)",
				__func__, event->type, event->code);
		}

		for (int j=0 ; count && mPendingMask && j<numSensors ; j++) {
			if (mPendingMask & (1<<j)) {
			    mPendingMask &= ~(1<<j);
#if (SENSORS_SIGNIFICANT_MOTION_ENABLE == 1)
				if((j == SignificantMotion) && mPendingEvents[j].data[0] == 0.0f)
					enable(SENSORS_SIGNIFICANT_MOTION_HANDLE, 0, 0);
#endif
				if (mEnabled & (1<<j)) {
					*data++ = mPendingEvents[j];
					count--;
					numEventReceived++;
				}
			}
		}

		mInputReader.next();
	}

#if (FETCH_FULL_EVENT_BEFORE_RETURN)
	/* if we didn't read a complete event, see if we can fill and
	try again instead of returning with nothing and redoing poll. */
	if (numEventReceived == 0 && (mEnabled > 0)) {
		n = mInputReader.fill(data_fd);
		if (n)
			goto again;
	}
#endif

	return numEventReceived;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x5130
cmpl $0x1, -0x1c(%rbp)
jge 0x72bd
movl $0xffffffea, -0x4(%rbp) # imm = 0xFFFFFFEA
jmp 0x77d6
movq -0x60(%rbp), %rax
testb $0x1, 0x1538(%rax)
je 0x72d5
movq -0x60(%rbp), %rax
movb $0x0, 0x1538(%rax)
movq -0x60(%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 0x7305
movq -0x30(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x77d6
movl $0x0, -0x34(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x61(%rbp)
je 0x7335
movq -0x60(%rbp), %rdi
addq $0x1028, %rdi           # imm = 0x1028
leaq -0x40(%rbp), %rsi
callq 0x52a0
cmpq $0x0, %rax
setne %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x7341
jmp 0x77d0
movq -0x40(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x4, %eax
jne 0x7438
movq -0x40(%rbp), %rax
cvtsi2ssl 0x14(%rax), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x40(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpl $0x0, %eax
jne 0x738b
movq -0x60(%rbp), %rax
movss 0x3283(%rip), %xmm0     # 0xa5fc
mulss -0x44(%rbp), %xmm0
movss %xmm0, 0x153c(%rax)
jmp 0x7433
movq -0x40(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0x73b3
movq -0x60(%rbp), %rax
movss 0x3258(%rip), %xmm0     # 0xa5fc
mulss -0x44(%rbp), %xmm0
movss %xmm0, 0x1540(%rax)
jmp 0x7431
movq -0x40(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpl $0x2, %eax
jne 0x73db
movq -0x60(%rbp), %rax
movss 0x3230(%rip), %xmm0     # 0xa5fc
mulss -0x44(%rbp), %xmm0
movss %xmm0, 0x1544(%rax)
jmp 0x742f
movq -0x40(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpl $0x4, %eax
jne 0x7401
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq 0x14(%rcx), %rcx
shlq $0x20, %rcx
movq %rcx, 0x1568(%rax)
jmp 0x742d
movq -0x40(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpl $0x7, %eax
jne 0x7429
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x14(%rcx), %ecx
orq 0x1568(%rax), %rcx
movq %rcx, 0x1568(%rax)
jmp 0x742b
jmp 0x742b
jmp 0x742d
jmp 0x742f
jmp 0x7431
jmp 0x7433
jmp 0x76d6
movq -0x40(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x76d2
movq -0x60(%rbp), %rax
movss 0x153c(%rax), %xmm1
movswl 0x6ee4(%rip), %ecx      # 0xe340
cvtsi2ss %ecx, %xmm2
movss 0x1540(%rax), %xmm0
movswl 0x6ed7(%rip), %ecx      # 0xe346
cvtsi2ss %ecx, %xmm3
mulss %xmm3, %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x1544(%rax), %xmm0
movswl 0x6ebe(%rip), %ecx      # 0xe34c
cvtsi2ss %ecx, %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x1548(%rax)
movss 0x153c(%rax), %xmm1
movswl 0x6e91(%rip), %ecx      # 0xe342
cvtsi2ss %ecx, %xmm2
movss 0x1540(%rax), %xmm0
movswl 0x6e84(%rip), %ecx      # 0xe348
cvtsi2ss %ecx, %xmm3
mulss %xmm3, %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x1544(%rax), %xmm0
movswl 0x6e6b(%rip), %ecx      # 0xe34e
cvtsi2ss %ecx, %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x154c(%rax)
movss 0x153c(%rax), %xmm1
movswl 0x6e3e(%rip), %ecx      # 0xe344
cvtsi2ss %ecx, %xmm2
movss 0x1540(%rax), %xmm0
movswl 0x6e31(%rip), %ecx      # 0xe34a
cvtsi2ss %ecx, %xmm3
mulss %xmm3, %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x1544(%rax), %xmm0
movswl 0x6e18(%rip), %ecx      # 0xe350
cvtsi2ss %ecx, %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x1550(%rax)
movq 0x6a5d(%rip), %rax      # 0xdfb0
movl (%rax), %ecx
addl $0x1, %ecx
movq 0x6a51(%rip), %rax      # 0xdfb0
movl %ecx, (%rax)
movq 0x6a68(%rip), %rax      # 0xdfd0
movl (%rax), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x769b
movq 0x6a33(%rip), %rax      # 0xdfb0
movl (%rax), %eax
movq 0x69c2(%rip), %rcx      # 0xdf48
cmpl (%rcx), %eax
jge 0x75a3
movq 0x6a1f(%rip), %rax      # 0xdfb0
movl (%rax), %eax
movq 0x69ae(%rip), %rcx      # 0xdf48
cmpl 0x4(%rcx), %eax
jl 0x769b
movq -0x60(%rbp), %rax
movq 0x6a02(%rip), %rcx      # 0xdfb0
movl $0x0, (%rcx)
movq 0x1548(%rax), %rcx
movq %rcx, 0x1554(%rax)
movl 0x1550(%rax), %ecx
movl %ecx, 0x155c(%rax)
movb $0x0, 0x1560(%rax)
movq 0x69f4(%rip), %rax      # 0xdfd0
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x762d
movq -0x60(%rbp), %rax
movb 0x1560(%rax), %cl
movb %cl, 0x107c(%rax)
movq 0x1554(%rax), %rcx
movq %rcx, 0x1070(%rax)
movl 0x155c(%rax), %ecx
movl %ecx, 0x1078(%rax)
movq 0x1568(%rax), %rcx
movq %rcx, 0x1068(%rax)
movl 0x1050(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x1050(%rax)
movq 0x699c(%rip), %rax      # 0xdfd0
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x7699
movq -0x60(%rbp), %rax
movb 0x1560(%rax), %cl
movb %cl, 0x10e4(%rax)
movq 0x1548(%rax), %rcx
movq %rcx, 0x10d8(%rax)
movl 0x1550(%rax), %ecx
movl %ecx, 0x10e0(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x10e4(%rax)
movl -0x20(%rbp), %ecx
movl %ecx, 0x10ec(%rax)
movq 0x1568(%rax), %rcx
movq %rcx, 0x10d0(%rax)
movl 0x1050(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x1050(%rax)
jmp 0x769b
movq 0x692e(%rip), %rax      # 0xdfd0
movl (%rax), %eax
andl $0x7f8, %eax            # imm = 0x7F8
cmpl $0x0, %eax
je 0x76d0
movq -0x60(%rbp), %rdi
movq 0x1548(%rdi), %rax
movq %rax, -0x54(%rbp)
movl 0x1550(%rdi), %eax
movl %eax, -0x4c(%rbp)
movq (%rdi), %rax
leaq -0x54(%rbp), %rsi
callq *0x60(%rax)
jmp 0x76d4
jmp 0x76d4
jmp 0x76d6
movl $0x0, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x62(%rbp)
je 0x7704
movq -0x60(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x1050(%rcx)
movb %al, -0x62(%rbp)
je 0x7704
cmpl $0xc, -0x58(%rbp)
setl %al
movb %al, -0x62(%rbp)
movb -0x62(%rbp), %al
testb $0x1, %al
jne 0x7710
jmp 0x77bb
movq -0x60(%rbp), %rax
movl 0x1050(%rax), %eax
movl -0x58(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x77ab
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
xorl $-0x1, %ecx
andl 0x1050(%rax), %ecx
movl %ecx, 0x1050(%rax)
movq 0x687d(%rip), %rax      # 0xdfd0
movl (%rax), %eax
movl -0x58(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x77a9
movq -0x60(%rbp), %rsi
addq $0x1058, %rsi           # imm = 0x1058
movslq -0x58(%rbp), %rax
imulq $0x68, %rax, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rdi
movq %rdi, %rax
addq $0x68, %rax
movq %rax, -0x18(%rbp)
movl $0x68, %edx
callq 0x51a0
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x77ab
jmp 0x77ad
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x76dd
movq -0x60(%rbp), %rdi
addq $0x1028, %rdi           # imm = 0x1028
callq 0x5220
jmp 0x730c
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop