// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0xc(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x10(%rbp)
cmpl $0xc, -0x10(%rbp)
jge 0x708c
movq 0x6f99(%rip), %rax      # 0xdfd0
movl (%rax), %eax
movl -0x10(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x706c
movslq -0x10(%rbp), %rcx
movq 0x6f41(%rip), %rax      # 0xdf98
movq (%rax,%rcx,8), %rdx
movslq -0x10(%rbp), %rcx
movq 0x6ef2(%rip), %rax      # 0xdf58
movq %rdx, (%rax,%rcx,8)
jmp 0x707f
movslq -0x10(%rbp), %rcx
movq 0x6ee1(%rip), %rax      # 0xdf58
movq $0x0, (%rax,%rcx,8)
jmp 0x7081
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x702a
movl $0x0, -0x10(%rbp)
cmpl $0xc, -0x10(%rbp)
jge 0x70fc
cmpq $0x0, -0x18(%rbp)
je 0x70dc
movslq -0x10(%rbp), %rcx
movq 0x6ead(%rip), %rax      # 0xdf58
cmpq $0x0, (%rax,%rcx,8)
je 0x70da
movslq -0x10(%rbp), %rcx
movq 0x6e9b(%rip), %rax      # 0xdf58
movq (%rax,%rcx,8), %rax
cmpq -0x18(%rbp), %rax
jg 0x70da
movslq -0x10(%rbp), %rcx
movq 0x6e86(%rip), %rax      # 0xdf58
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
jmp 0x70ef
movslq -0x10(%rbp), %rcx
movq 0x6e71(%rip), %rax      # 0xdf58
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
jmp 0x70f1
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x7093
cmpq $0x0, -0x18(%rbp)
jle 0x7153
movq -0x18(%rbp), %rax
movq 0x6e22(%rip), %rcx      # 0xdf30
cmpq (%rcx), %rax
je 0x7153
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq (%rdi), %rax
movl $0x1, %esi
callq *0x48(%rax)
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x7151
movl $0x0, -0xc(%rbp)
movq -0x18(%rbp), %rcx
movq 0x6def(%rip), %rax      # 0xdf30
movq %rcx, (%rax)
movq 0x6e65(%rip), %rax      # 0xdfb0
movl $0x0, (%rax)
jmp 0x7153
movl $0x0, -0x10(%rbp)
cmpl $0xc, -0x10(%rbp)
jge 0x71c7
cmpl $0x0, -0x10(%rbp)
je 0x716c
cmpl $0xa, -0x10(%rbp)
jne 0x716e
jmp 0x71bc
movq 0x6dbb(%rip), %rax      # 0xdf30
cmpq $0x0, (%rax)
je 0x71a8
movslq -0x10(%rbp), %rcx
movq 0x6dd2(%rip), %rax      # 0xdf58
movq (%rax,%rcx,8), %rax
movq 0x6d9f(%rip), %rcx      # 0xdf30
cqto
idivq (%rcx)
movl %eax, %edx
movslq -0x10(%rbp), %rcx
movq 0x6da5(%rip), %rax      # 0xdf48
movl %edx, (%rax,%rcx,4)
jmp 0x71ba
movslq -0x10(%rbp), %rcx
movq 0x6d95(%rip), %rax      # 0xdf48
movl $0x0, (%rax,%rcx,4)
jmp 0x71bc
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x715a
movl -0xc(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq