// File: /workspace/github_c_makefile_star2_O0/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 %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 $0x3, -0x10(%rbp)
jge 0x7dec
movq 0x6241(%rip), %rax      # 0xdfd8
movl (%rax), %eax
movl -0x10(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x7dcc
movslq -0x10(%rbp), %rcx
movq 0x61d9(%rip), %rax      # 0xdf90
movq (%rax,%rcx,8), %rdx
movslq -0x10(%rbp), %rcx
movq 0x6162(%rip), %rax      # 0xdf28
movq %rdx, (%rax,%rcx,8)
jmp 0x7ddf
movslq -0x10(%rbp), %rcx
movq 0x6151(%rip), %rax      # 0xdf28
movq $0x0, (%rax,%rcx,8)
jmp 0x7de1
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x7d8a
movl $0x0, -0x10(%rbp)
cmpl $0x3, -0x10(%rbp)
jge 0x7e5c
cmpq $0x0, -0x18(%rbp)
je 0x7e3c
movslq -0x10(%rbp), %rcx
movq 0x611d(%rip), %rax      # 0xdf28
cmpq $0x0, (%rax,%rcx,8)
je 0x7e3a
movslq -0x10(%rbp), %rcx
movq 0x610b(%rip), %rax      # 0xdf28
movq (%rax,%rcx,8), %rax
cmpq -0x18(%rbp), %rax
jg 0x7e3a
movslq -0x10(%rbp), %rcx
movq 0x60f6(%rip), %rax      # 0xdf28
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
jmp 0x7e4f
movslq -0x10(%rbp), %rcx
movq 0x60e1(%rip), %rax      # 0xdf28
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
jmp 0x7e51
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x7df3
cmpq $0x0, -0x18(%rbp)
jle 0x7ee1
movq -0x18(%rbp), %rax
movq 0x60fa(%rip), %rcx      # 0xdf68
cmpq (%rcx), %rax
je 0x7ee1
movq -0x20(%rbp), %rdi
xorl %eax, %eax
cqto
idivq -0x18(%rbp)
movl %eax, %ecx
addl $0x1, %ecx
movq 0x605d(%rip), %rax      # 0xdee8
movl %ecx, (%rax)
movq 0x6054(%rip), %rax      # 0xdee8
movl (%rax), %ecx
movq 0x6053(%rip), %rax      # 0xdef0
movl %ecx, (%rax)
movq -0x18(%rbp), %rdx
movq (%rdi), %rax
movl $0x4, %esi
callq *0x48(%rax)
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x7edf
movl $0x0, -0xc(%rbp)
movq -0x18(%rbp), %rcx
movq 0x609f(%rip), %rax      # 0xdf68
movq %rcx, (%rax)
movq 0x607d(%rip), %rdi      # 0xdf50
xorl %esi, %esi
movl $0xc, %edx
callq 0x5130
jmp 0x7ee1
movl $0x0, -0x10(%rbp)
cmpl $0x3, -0x10(%rbp)
jge 0x7f55
cmpl $0x0, -0x10(%rbp)
je 0x7efa
cmpl $0x1, -0x10(%rbp)
jne 0x7efc
jmp 0x7f4a
movq 0x6065(%rip), %rax      # 0xdf68
cmpq $0x0, (%rax)
je 0x7f36
movslq -0x10(%rbp), %rcx
movq 0x6014(%rip), %rax      # 0xdf28
movq (%rax,%rcx,8), %rax
movq 0x6049(%rip), %rcx      # 0xdf68
cqto
idivq (%rcx)
movl %eax, %edx
movslq -0x10(%rbp), %rcx
movq 0x604f(%rip), %rax      # 0xdf80
movl %edx, (%rax,%rcx,4)
jmp 0x7f48
movslq -0x10(%rbp), %rcx
movq 0x603f(%rip), %rax      # 0xdf80
movl $0x0, (%rax,%rcx,4)
jmp 0x7f4a
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x7ee8
movl -0xc(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop