// File: /workspace/github_c_makefile_star2_O0/STMicroelectronics[P]STMems_Android_Sensor_HAL_Input/SensorBase.cpp
// Function: SensorBase::writeDelay(int, long)
int SensorBase::writeDelay(int32_t handle, int64_t delay_ms)
{
	int fd;
	int err;
	char buf[8];
	const char *className;

	STLOGD( "SensorBase: setDelay handle = %d", handle);

	switch(handle) {
#if (SENSORS_ACCELEROMETER_ENABLE == 1)
	case SENSORS_ACCELEROMETER_HANDLE:
	case SENSORS_SIGNIFICANT_MOTION_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       ACCEL_DELAY_FILE_NAME);
		className = "AccelSensor::Delay()";
		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_DELAY_FILE_NAME);
		className = "MagnSensor::Delay()";
		break;
#endif
#if (SENSORS_GYROSCOPE_ENABLE == 1)
	case SENSORS_GYROSCOPE_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       GYRO_DELAY_FILE_NAME);
		className = "Gyro::Delay()";
		break;
#endif
#if (SENSORS_STEP_COUNTER_ENABLE == 1)
	case SENSORS_STEP_COUNTER_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       STEP_C_DELAY_FILE_NAME);
		className = "StepCounterSensor::Delay()";
		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_DELAY_FILE_NAME);
		className = "PressTempSensor::Delay()";
		break;
#endif
#if (SENSORS_TEMP_ENABLE == 1)
	case SENSORS_TEMPERATURE_HANDLE:
		strcpy(&sysfs_device_path[sysfs_device_path_len],
		       TEMP_DELAY_FILE_NAME);
		className = "TempSensor::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_DELAY_FILE_NAME);
		className = "HimiditySensor::Delay()";
		break;
#endif
	default:
		return -1;
	}

	fd = open(sysfs_device_path, O_RDWR);
	if (!fd) {
		STLOGE("%s Failed to open device: %s",
		       className, sysfs_device_path);
		return -1;
	}

	sprintf(buf,"%lld", (long long)delay_ms);
	err = write(fd, buf, sizeof(buf));
	close(fd);

	if(err > 0) {
		STLOGI("%s Set delay to %lld [ms]",
		       className, (long long)delay_ms);
	} else {
		STLOGE("%s Failed to set delay: %lld [ms] - %s",
		       className, (long long)delay_ms, sysfs_device_path);
	}

        return err > 0 ? 0 : -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x13, %eax
ja 0x5cfd
movq -0x40(%rbp), %rax
leaq 0x43ee(%rip), %rcx      # 0xa058
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x48(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x464b(%rip), %rsi      # 0xa2da
callq 0x51f0
leaq 0x4652(%rip), %rax      # 0xa2ed
movq %rax, -0x38(%rbp)
jmp 0x5d06
movq -0x48(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x4645(%rip), %rsi      # 0xa302
callq 0x51f0
leaq 0x464b(%rip), %rax      # 0xa314
movq %rax, -0x38(%rbp)
jmp 0x5d06
movq -0x48(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x1018(%rax), %rax
addq %rax, %rdi
leaq 0x4637(%rip), %rsi      # 0xa322
callq 0x51f0
leaq 0x4644(%rip), %rax      # 0xa33b
movq %rax, -0x38(%rbp)
jmp 0x5d06
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5d7b
movq -0x48(%rbp), %rdi
addq $0x18, %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x5180
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x5d2c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5d7b
leaq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x461b(%rip), %rsi      # 0xa356
movb $0x0, %al
callq 0x5090
movl -0x24(%rbp), %edi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x50f0
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %edi
callq 0x5410
cmpl $0x0, -0x28(%rbp)
jle 0x5d66
jmp 0x5d68
jmp 0x5d68
movl -0x28(%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 $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)