// File: /workspace/github_c_makefile_star2_O3/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 0x52d1(%rip), %rax      # 0xbfd0
movl (%rax), %eax
xorl %ecx, %ecx
movq 0x5216(%rip), %r15      # 0xbf20
movq 0x5277(%rip), %rdx      # 0xbf88
btl %ecx, %eax
jae 0x6d1c
movq (%rdx,%rcx,8), %rsi
jmp 0x6d1e
xorl %esi, %esi
movq %rsi, (%r15,%rcx,8)
incq %rcx
cmpq $0x3, %rcx
jne 0x6d11
xorl %eax, %eax
xorl %ebx, %ebx
movq (%r15,%rax,8), %rcx
testq %rbx, %rbx
je 0x6d4b
cmpq %rbx, %rcx
movq %rbx, %rdx
cmovlq %rcx, %rdx
testq %rcx, %rcx
cmovneq %rdx, %rbx
jmp 0x6d4e
movq %rcx, %rbx
incq %rax
cmpq $0x3, %rax
jne 0x6d2f
testq %rbx, %rbx
setle %cl
movq 0x51fc(%rip), %r12      # 0xbf60
movq (%r12), %rax
cmpq %rax, %rbx
sete %dl
xorl %r14d, %r14d
orb %cl, %dl
movl $0x0, %ecx
jne 0x6dc6
movq 0x515f(%rip), %rax      # 0xbee0
movl $0x1, %ecx
movl %ecx, (%rax)
movq 0x5159(%rip), %rax      # 0xbee8
movl %ecx, (%rax)
movq (%rdi), %rax
movl $0x4, %esi
movq %rbx, %rdx
callq *0x48(%rax)
testl %eax, %eax
js 0x6dc0
movq %rbx, (%r12)
movq 0x519a(%rip), %rax      # 0xbf48
movq $0x0, (%rax)
movl $0x0, 0x8(%rax)
xorl %ecx, %ecx
jmp 0x6dce
movl %eax, %ecx
movq (%r12), %rax
movq %rax, %rbx
testq %rax, %rax
je 0x6dda
movq 0x10(%r15), %rax
cqto
idivq %rbx
movq %rax, %r14
movq 0x5197(%rip), %rax      # 0xbf78
movl %r14d, 0x8(%rax)
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop