// File: /workspace/github_c_makefile_star2_O2/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 0x540b(%rip), %rax      # 0xbfd0
movl (%rax), %eax
xorl %ecx, %ecx
movq 0x5350(%rip), %r15      # 0xbf20
movq 0x53b1(%rip), %rdx      # 0xbf88
cmpq $0x3, %rcx
je 0x6bf3
btl %ecx, %eax
jae 0x6be8
movq (%rdx,%rcx,8), %rsi
jmp 0x6bea
xorl %esi, %esi
movq %rsi, (%r15,%rcx,8)
incq %rcx
jmp 0x6bd7
xorl %eax, %eax
xorl %ebx, %ebx
cmpq $0x3, %rax
je 0x6c22
movq (%r15,%rax,8), %rcx
testq %rbx, %rbx
je 0x6c1a
cmpq %rbx, %rcx
movq %rbx, %rdx
cmovlq %rcx, %rdx
testq %rcx, %rcx
cmoveq %rbx, %rdx
movq %rdx, %rcx
incq %rax
movq %rcx, %rbx
jmp 0x6bf7
testq %rbx, %rbx
setle %cl
movq 0x5331(%rip), %r12      # 0xbf60
movq (%r12), %rax
cmpq %rax, %rbx
sete %dl
xorl %r14d, %r14d
orb %cl, %dl
movl $0x0, %ecx
jne 0x6c87
movq 0x5294(%rip), %rax      # 0xbee0
pushq $0x1
popq %rcx
movl %ecx, (%rax)
movq 0x5290(%rip), %rax      # 0xbee8
movl %ecx, (%rax)
movq (%rdi), %rax
pushq $0x4
popq %rsi
movq %rbx, %rdx
callq *0x48(%rax)
testl %eax, %eax
js 0x6c81
movq %rbx, (%r12)
movq 0x52d3(%rip), %rax      # 0xbf48
andq $0x0, (%rax)
andl $0x0, 0x8(%rax)
xorl %ecx, %ecx
jmp 0x6c8f
movl %eax, %ecx
movq (%r12), %rax
movq %rax, %rbx
testq %rax, %rax
je 0x6c9b
movq 0x10(%r15), %rax
cqto
idivq %rbx
movq %rax, %r14
movq 0x52d6(%rip), %rax      # 0xbf78
movl %r14d, 0x8(%rax)
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq