// File: /workspace/github_c_makefile_star2_O0/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/SensorBase.cpp
// Function: SensorBase::writeEnable(int, int)
int SensorBase::writeEnable(int32_t handle, int enable)
{
	int fd;
	int err;
	char buf[6];
	const char *className;

	switch(handle) {
#if (SENSORS_ACCELEROMETER_ENABLE == 1)
	case SENSORS_ACCELEROMETER_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       ACCEL_ENABLE_FILE_NAME);
		className = "AccelSensor::Enable(Accel)";
		break;
#endif
#if (SENSORS_SIGNIFICANT_MOTION_ENABLE == 1)
	case SENSORS_SIGNIFICANT_MOTION_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       SIGN_MOTION_ENABLE_FILE_NAME);
		className = "AccelSensor::Enable(SigMotion)";
		break;
#endif
#if (SENSORS_MAGNETIC_FIELD_ENABLE == 1)
	case SENSORS_MAGNETIC_FIELD_HANDLE:
	case SENSORS_UNCALIB_MAGNETIC_FIELD_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       MAGN_ENABLE_FILE_NAME);
		className = "MagnSensor::Enable()";
		break;
#endif
#if (SENSORS_GYROSCOPE_ENABLE == 1)
	case SENSORS_GYROSCOPE_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       GYRO_ENABLE_FILE_NAME);
		className = "GyroSensor::Enable()";
		break;
#endif
#if ((SENSORS_PRESSURE_ENABLE == 1) || (SENSORS_TEMP_PRESS_ENABLE == 1))
	case SENSORS_PRESSURE_HANDLE:
	case SENSORS_TEMPERATURE_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       PRESS_ENABLE_FILE_NAME);
		className = "PressTempSensor::Enable()";
		break;
#endif
#if (SENSORS_TEMP_ENABLE == 1)
	case SENSORS_TEMPERATURE_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       TEMP_ENABLE_FILE_NAME);
		className = "TempSensor::Enable()";
		break;
#endif
#if (SENSORS_TILT_ENABLE == 1)
	case SENSORS_TILT_DETECTOR_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       TILT_ENABLE_FILE_NAME);
		className = "TiltSensor::Enable()";
		break;
#endif
#if (SENSORS_STEP_COUNTER_ENABLE == 1)
	case SENSORS_STEP_COUNTER_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       STEP_C_ENABLE_FILE_NAME);
		className = "StepCounterSensor::Enable()";
		break;
#endif
#if (SENSORS_STEP_DETECTOR_ENABLE == 1)
	case SENSORS_STEP_DETECTOR_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       STEP_D_ENABLE_FILE_NAME);
		className = "StepDetectorSensor::Enable()";
		break;
#endif
#if (SENSORS_SIGN_MOTION_ENABLE == 1)
	case SENSORS_SIGN_MOTION_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       SIGN_M_ENABLE_FILE_NAME);
		className = "SignMotionSensor::Enable()";
		break;
#endif
#if (SENSORS_TAP_ENABLE == 1)
	case SENSORS_TAP_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       TAP_ENABLE_FILE_NAME);
		className = "TapSensor::Enable()";
		break;
#endif
#if ((SENSORS_HUMIDITY_ENABLE == 1) || (SENSORS_TEMP_RH_ENABLE == 1))
	case SENSORS_TEMPERATURE_HANDLE:
	case SENSORS_HUMIDITY_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       HUMIDITY_ENABLE_FILE_NAME);
		className = "HimiditySensor::Enable()";
		break;
#endif
	default:
		return -1;
	}

	fd = open(sysfs_device_path, O_RDWR);
	sprintf(buf,"%d", enable);
	err = write(fd, buf, sizeof(buf));
	close(fd);

	if(err > 0) {
		STLOGI("%s Set enable to %d", className, enable);
	} else {
		STLOGE("%s Failed to set enable: %d - %s",
		       className, enable, sysfs_device_path);
	}

	return err > 0 ? 0 : -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x15, %eax
ja 0x5baf
movq -0x38(%rbp), %rax
leaq 0x4577(%rip), %rcx      # 0xa000
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x4744(%rip), %rsi      # 0xa1f2
callq 0x51f0
leaq 0x4745(%rip), %rax      # 0xa1ff
movq %rax, -0x30(%rbp)
jmp 0x5bb8
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x473b(%rip), %rsi      # 0xa21a
callq 0x51f0
leaq 0x473b(%rip), %rax      # 0xa226
movq %rax, -0x30(%rbp)
jmp 0x5bb8
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x472b(%rip), %rsi      # 0xa23b
callq 0x51f0
leaq 0x472b(%rip), %rax      # 0xa247
movq %rax, -0x30(%rbp)
jmp 0x5bb8
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x471b(%rip), %rsi      # 0xa25c
callq 0x51f0
leaq 0x471d(%rip), %rax      # 0xa26a
movq %rax, -0x30(%rbp)
jmp 0x5bb8
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x4717(%rip), %rsi      # 0xa286
callq 0x51f0
leaq 0x4719(%rip), %rax      # 0xa294
movq %rax, -0x30(%rbp)
jmp 0x5bb8
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x4714(%rip), %rsi      # 0xa2b1
callq 0x51f0
leaq 0x4716(%rip), %rax      # 0xa2bf
movq %rax, -0x30(%rbp)
jmp 0x5bb8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5c1d
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x5180
movl %eax, -0x1c(%rbp)
leaq -0x26(%rbp), %rdi
movl -0x18(%rbp), %edx
leaq 0x4612(%rip), %rsi      # 0xa1ef
movb $0x0, %al
callq 0x5090
movl -0x1c(%rbp), %edi
leaq -0x26(%rbp), %rsi
movl $0x6, %edx
callq 0x50f0
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %edi
callq 0x5410
cmpl $0x0, -0x20(%rbp)
jle 0x5c08
jmp 0x5c0a
jmp 0x5c0a
movl -0x20(%rbp), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovgl %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)