// File: /workspace/github_c_makefile_star2_O3/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/AccelSensor.cpp
// Function: AccelSensor::writeMinDelay()
int AccelSensor::writeMinDelay(void)
{
	int err = 0;
	int kk;
	int64_t Min_delay_ms = 0;

	for(kk = 0; kk < numSensors; kk++) {
		if ((mEnabled & 1<<kk) != 0) {
			writeDelayBuffer[kk] = setDelayBuffer[kk];
		} else {
			writeDelayBuffer[kk] = 0;
		}
	}

	// Min setDelay Definition
	for(kk = 0; kk < numSensors; kk++) {
		if (Min_delay_ms != 0) {
			if ((writeDelayBuffer[kk] != 0) &&
			    (writeDelayBuffer[kk] <= Min_delay_ms))
				Min_delay_ms = writeDelayBuffer[kk];
		} else {
			Min_delay_ms = writeDelayBuffer[kk];
		}
	}

#if (ACCEL_CALIBRATION_ENABLE == 1)
	if(Min_delay_ms > ACCEL_CALIB_PERIOD_MS)
		Min_delay_ms = ACCEL_CALIB_PERIOD_MS;
#endif
#if (SENSORS_ACTIVITY_RECOGNIZER_ENABLE == 1)
	if ((mEnabled & (1 << ActivityReco)) &&
		(Min_delay_ms > (1000 / ACTIVITY_RECOGNIZER_ODR)))
			Min_delay_ms = 1000 / ACTIVITY_RECOGNIZER_ODR;
#endif

	if ((Min_delay_ms > 0) && (Min_delay_ms != delayms)) {
		err = writeDelay(SENSORS_ACCELEROMETER_HANDLE,
				 Min_delay_ms);
		if(err >= 0) {
			err = 0;
			delayms = Min_delay_ms;
			DecimationCount = 0;
		}
	}

	// Decimation Definition
	for(kk = 0; kk < numSensors; kk++) {
		if (kk == Acceleration || kk == Gbias)
			continue;

		if (delayms)
			DecimationBuffer[kk] = writeDelayBuffer[kk]/delayms;
		else
			DecimationBuffer[kk] = 0;
	}

#if (DEBUG_POLL_RATE == 1)
	STLOGD("%s: writeDelayBuffer[] = %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld",
						__func__,
						writeDelayBuffer[0], writeDelayBuffer[1],
						writeDelayBuffer[2], writeDelayBuffer[3],
						writeDelayBuffer[4], writeDelayBuffer[5],
						writeDelayBuffer[6], writeDelayBuffer[7],
						writeDelayBuffer[8], writeDelayBuffer[9],
						writeDelayBuffer[10]);
	STLOGD("%s: Min_delay_ms = %lld, delayms = %lld, mEnabled = %d",
						__func__,
						Min_delay_ms, delayms, mEnabled);
	STLOGD("%s: DecimationBuffer = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d",
						__func__,
						DecimationBuffer[0], DecimationBuffer[1],
						DecimationBuffer[2], DecimationBuffer[3],
						DecimationBuffer[4], DecimationBuffer[5],
						DecimationBuffer[6], DecimationBuffer[7],
						DecimationBuffer[8], DecimationBuffer[9],
						DecimationBuffer[10]);
#endif

	return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq 0x5b08(%rip), %rax      # 0xbfc8
movl (%rax), %eax
xorl %ecx, %ecx
movq 0x5a85(%rip), %r14      # 0xbf50
movq 0x5abe(%rip), %rdx      # 0xbf90
btl %ecx, %eax
jae 0x64dd
movq (%rdx,%rcx,8), %rsi
jmp 0x64df
xorl %esi, %esi
movq %rsi, (%r14,%rcx,8)
incq %rcx
cmpq $0xc, %rcx
jne 0x64d2
xorl %eax, %eax
xorl %ebx, %ebx
movq (%r14,%rax,8), %rcx
testq %rbx, %rbx
je 0x650c
cmpq %rbx, %rcx
movq %rbx, %rdx
cmovlq %rcx, %rdx
testq %rcx, %rcx
cmovneq %rdx, %rbx
jmp 0x650f
movq %rcx, %rbx
incq %rax
cmpq $0xc, %rax
jne 0x64f0
testq %rbx, %rbx
setle %cl
movq 0x5a03(%rip), %r15      # 0xbf28
movq (%r15), %rax
cmpq %rax, %rbx
sete %dl
xorl %ebp, %ebp
orb %cl, %dl
je 0x6539
movq %rax, %rbx
jmp 0x6562
movq (%rdi), %rax
movl $0x1, %esi
movq %rbx, %rdx
callq *0x48(%rax)
testl %eax, %eax
js 0x655d
movq %rbx, (%r15)
movq 0x5a53(%rip), %rax      # 0xbfa8
movl $0x0, (%rax)
jmp 0x6562
movq (%r15), %rbx
movl %eax, %ebp
xorl %ecx, %ecx
movq 0x59d5(%rip), %rsi      # 0xbf40
testl %ecx, %ecx
je 0x6589
cmpl $0xa, %ecx
je 0x6589
testq %rbx, %rbx
je 0x6584
movq (%r14,%rcx,8), %rax
cqto
idivq %rbx
jmp 0x6586
xorl %eax, %eax
movl %eax, (%rsi,%rcx,4)
incq %rcx
cmpq $0xc, %rcx
jne 0x656b
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop