// File: /workspace/github_c_makefile_star2_O2/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 0x5be6(%rip), %rax      # 0xbfc8
movl (%rax), %eax
xorl %ecx, %ecx
movq 0x5b63(%rip), %r14      # 0xbf50
movq 0x5b9c(%rip), %rdx      # 0xbf90
cmpq $0xc, %rcx
je 0x6410
btl %ecx, %eax
jae 0x6405
movq (%rdx,%rcx,8), %rsi
jmp 0x6407
xorl %esi, %esi
movq %rsi, (%r14,%rcx,8)
incq %rcx
jmp 0x63f4
xorl %eax, %eax
xorl %ebx, %ebx
cmpq $0xc, %rax
je 0x643f
movq (%r14,%rax,8), %rcx
testq %rbx, %rbx
je 0x6437
cmpq %rbx, %rcx
movq %rbx, %rdx
cmovlq %rcx, %rdx
testq %rcx, %rcx
cmoveq %rbx, %rdx
movq %rdx, %rcx
incq %rax
movq %rcx, %rbx
jmp 0x6414
testq %rbx, %rbx
setle %cl
movq 0x5adc(%rip), %r15      # 0xbf28
movq (%r15), %rax
cmpq %rax, %rbx
sete %dl
xorl %ebp, %ebp
orb %cl, %dl
je 0x6460
movq %rax, %rbx
jmp 0x6484
movq (%rdi), %rax
pushq $0x1
popq %rsi
movq %rbx, %rdx
callq *0x48(%rax)
testl %eax, %eax
js 0x647f
movq %rbx, (%r15)
movq 0x5b2e(%rip), %rax      # 0xbfa8
andl $0x0, (%rax)
jmp 0x6484
movq (%r15), %rbx
movl %eax, %ebp
xorl %ecx, %ecx
movq 0x5ab3(%rip), %rsi      # 0xbf40
cmpq $0xc, %rcx
je 0x64b6
testl %ecx, %ecx
je 0x64b1
cmpl $0xa, %ecx
je 0x64b1
testq %rbx, %rbx
je 0x64ac
movq (%r14,%rcx,8), %rax
cqto
idivq %rbx
jmp 0x64ae
xorl %eax, %eax
movl %eax, (%rsi,%rcx,4)
incq %rcx
jmp 0x648d
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop