// File: /workspace/github_c_makefile_star2_O1/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/GyroSensor.cpp
// Function: GyroSensor::writeMinDelay()
int GyroSensor::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 ((Min_delay_ms > 0) && (Min_delay_ms != delayms)) {
		samples_to_discard = (int)(GYRO_STARTUP_TIME_MS / Min_delay_ms) + 1;
		startup_samples = samples_to_discard;
		err = writeDelay(SENSORS_GYROSCOPE_HANDLE, Min_delay_ms);
		if(err >= 0) {
			err = 0;
			delayms = Min_delay_ms;
			memset(DecimationCount, 0, sizeof(DecimationCount));
#if (GYROSCOPE_GBIAS_ESTIMATION_STANDALONE == 1)
			iNemoEngine_API_gbias_set_frequency(1000.0f / (float)Min_delay_ms);
  #if (SENSORS_ACCELEROMETER_ENABLE == 1)
			if (Min_delay_ms >= 10)
				acc->setDelay(SENSORS_GYROSCOPE_HANDLE, (float)Min_delay_ms*1000000);
			else
				acc->setDelay(SENSORS_GYROSCOPE_HANDLE, 10000000);
  #endif
#endif
		}
	}

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

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

#if (DEBUG_POLL_RATE == 1)
	STLOGD("%s: writeDelayBuffer[] = %lld, %lld, %lld",
		__func__, writeDelayBuffer[0],
		writeDelayBuffer[1], writeDelayBuffer[2]);
	STLOGD("%s: Min_delay_ms = %lld, delayms = %lld, mEnabled = %d",
		__func__, Min_delay_ms, delayms, mEnabled);
	STLOGD("%s: samples_to_discard = %d",
		__func__, samples_to_discard);
	STLOGD("%s: DecimationBuffer = %d, %d, %d",
		__func__, DecimationBuffer[0], DecimationBuffer[1],
		DecimationBuffer[2]);
#endif

	return err;

}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq 0x52d7(%rip), %rax      # 0xbfd0
movl (%rax), %eax
xorl %ecx, %ecx
movq 0x521c(%rip), %r15      # 0xbf20
movq 0x527d(%rip), %rdx      # 0xbf88
btl %ecx, %eax
jae 0x6d16
movq (%rdx,%rcx,8), %rsi
jmp 0x6d18
xorl %esi, %esi
movq %rsi, (%r15,%rcx,8)
incq %rcx
cmpq $0x3, %rcx
jne 0x6d0b
xorl %eax, %eax
xorl %r14d, %r14d
movq (%r15,%rax,8), %rcx
testq %r14, %r14
je 0x6d46
cmpq %r14, %rcx
movq %r14, %rdx
cmovlq %rcx, %rdx
testq %rcx, %rcx
cmovneq %rdx, %r14
jmp 0x6d49
movq %rcx, %r14
incq %rax
cmpq $0x3, %rax
jne 0x6d2a
xorl %ebx, %ebx
movq 0x5205(%rip), %r12      # 0xbf60
testq %r14, %r14
jle 0x6dac
cmpq (%r12), %r14
je 0x6dac
movq 0x5173(%rip), %rax      # 0xbee0
movl $0x1, %ecx
movl %ecx, (%rax)
movq 0x516d(%rip), %rax      # 0xbee8
movl %ecx, (%rax)
movq (%rdi), %rax
movl $0x4, %esi
movq %r14, %rdx
callq *0x48(%rax)
testl %eax, %eax
js 0x6daa
movq %r14, (%r12)
movq 0x51ae(%rip), %rax      # 0xbf48
movq $0x0, (%rax)
movl $0x0, 0x8(%rax)
jmp 0x6dac
movl %eax, %ebx
movq (%r12), %rcx
xorl %esi, %esi
movq 0x51bf(%rip), %rdi      # 0xbf78
cmpq $0x2, %rsi
jne 0x6dd4
testq %rcx, %rcx
je 0x6dcf
movq (%r15,%rsi,8), %rax
cqto
idivq %rcx
jmp 0x6dd1
xorl %eax, %eax
movl %eax, (%rdi,%rsi,4)
incq %rsi
cmpq $0x3, %rsi
jne 0x6db9
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop