// File: /workspace/github_c_makefile_star2_O0/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/GyroSensor.cpp
// Function: GyroSensor::enable(int, int, int)
int GyroSensor::enable(int32_t handle, int en,
		       int  __attribute__((unused))type)
{
	int err = 0;
	int flags = en ? 1 : 0;
	int what = -1;
	int mEnabledPrev;

	what = getWhatFromHandle(handle);
	if (what < 0)
		return what;

	if (flags) {
		mEnabled |= (1<<what);
		writeMinDelay();

		if (mEnabled == (1<<what)) {
#if ((GYROSCOPE_GBIAS_ESTIMATION_STANDALONE == 1) && (SENSORS_ACCELEROMETER_ENABLE == 1))
			acc->enable(SENSORS_GYROSCOPE_HANDLE, flags, 1);
			iNemoEngine_API_gbias_enable(flags);
#endif
#if !defined(NOT_SET_GYRO_INITIAL_STATE)
			setInitialState();
#endif
			err = writeEnable(SENSORS_GYROSCOPE_HANDLE, flags);
			if(err >= 0)
				err = 0;
		}

	} else {
		mEnabledPrev = mEnabled;
		mEnabled &= ~(1<<what);

		if ((!mEnabled) && (mEnabledPrev)){
			err = writeEnable(SENSORS_GYROSCOPE_HANDLE, flags);
			if(err >= 0)
				err = 0;

#if ((GYROSCOPE_GBIAS_ESTIMATION_STANDALONE == 1) && (SENSORS_ACCELEROMETER_ENABLE == 1))
			acc->enable(SENSORS_GYROSCOPE_HANDLE, flags, 1);
			STLOGD("GyroSensor::Acc OFF");
			iNemoEngine_API_gbias_enable(false);
#endif

		}
		//setDelay(handle, DELAY_OFF);
		if (mEnabled) {
			writeMinDelay();
		}
	}

	if(err >= 0 ) {
		STLOGD("%s: (%d), handle: %d, what: %d, mEnabled: %x",
			__func__, flags, handle, what, mEnabled);
	} else {
		STLOGE("%s: (%d), handle: %d, what: %d, mEnabled: %x",
			__func__, flags, handle, what, mEnabled);
	}

	return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x38(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x18(%rbp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x24(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0x58(%rax)
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0x7b6b
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7c6c
cmpl $0x0, -0x24(%rbp)
je 0x7be1
movq -0x38(%rbp), %rdi
movl -0x28(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq 0x6450(%rip), %rax      # 0xdfd8
orl (%rax), %ecx
movq 0x6447(%rip), %rax      # 0xdfd8
movl %ecx, (%rax)
movq (%rdi), %rax
callq *0x68(%rax)
movq 0x6438(%rip), %rax      # 0xdfd8
movl (%rax), %eax
movl -0x28(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jne 0x7bdf
movq -0x38(%rbp), %rdi
callq 0x5340
movq -0x38(%rbp), %rdi
movl -0x24(%rbp), %edx
movq (%rdi), %rax
movl $0x4, %esi
callq *0x40(%rax)
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jl 0x7bdd
movl $0x0, -0x20(%rbp)
jmp 0x7bdf
jmp 0x7c5c
movq 0x63f0(%rip), %rax      # 0xdfd8
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
movq 0x63d5(%rip), %rax      # 0xdfd8
andl (%rax), %ecx
movq 0x63cc(%rip), %rax      # 0xdfd8
movl %ecx, (%rax)
movq 0x63c3(%rip), %rax      # 0xdfd8
cmpl $0x0, (%rax)
jne 0x7c44
cmpl $0x0, -0x2c(%rbp)
je 0x7c44
movq -0x38(%rbp), %rdi
movl -0x24(%rbp), %edx
movq (%rdi), %rax
movl $0x4, %esi
callq *0x40(%rax)
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jl 0x7c42
movl $0x0, -0x20(%rbp)
jmp 0x7c44
movq 0x638d(%rip), %rax      # 0xdfd8
cmpl $0x0, (%rax)
je 0x7c5a
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
jmp 0x7c5c
cmpl $0x0, -0x20(%rbp)
jl 0x7c64
jmp 0x7c66
jmp 0x7c66
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)