#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct input_absinfo {
  unsigned int maximum;
  unsigned int minimum;
};

/* Variables and functions */
int /*<<< orphan*/ EVIOCGABS(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct input_absinfo *);
int get_axix_threshold(int fd, int axis, unsigned int percentage) {
  struct input_absinfo absinfo;
  if (ioctl(fd, EVIOCGABS(axis), &absinfo) < 0) {
    return -1;
  }
  return (absinfo.maximum - absinfo.minimum) * percentage / 100;
}


x86 assembly (clang, -O0):
<get_axix_threshold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <EVIOCGABS@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1163 <get_axix_threshold+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1179 <get_axix_threshold+0x59>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_axix_threshold>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %edi,%ebp
mov    %esi,%edi
call   1030 <EVIOCGABS@plt>
mov    %rsp,%rdx
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1156 <get_axix_threshold+0x36>
mov    (%rsp),%eax
sub    0x4(%rsp),%eax
imul   %ebx,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
jmp    115b <get_axix_threshold+0x3b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.input_absinfo = type { i32, i32 }
define i32 @get_axix_threshold(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.input_absinfo
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 @EVIOCGABS(i32 %10)
%12 = call i64 @ioctl(i32 %9, i32 %11, %struct.input_absinfo* %8)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %24
15: ; preds = %3
%16 = getelementptr inbounds %struct.input_absinfo, %struct.input_absinfo* %8, i32 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.input_absinfo, %struct.input_absinfo* %8, i32 0, i32 1
%19 = load i32, i32* %18
%20 = sub i32 %17, %19
%21 = load i32, i32* %7
%22 = mul i32 %20, %21
%23 = udiv i32 %22, 100
store i32 %23, i32* %4
br label %24
24: ; preds = %15, %14
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
%struct.input_absinfo = type { i32, i32 }
define i32 @get_axix_threshold(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.input_absinfo
%5 = bitcast %struct.input_absinfo* %4 to i8*
%6 = tail call i32 @EVIOCGABS(i32 %1)
%7 = call i64 @ioctl(i32 %0, i32 %6, %struct.input_absinfo* %4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %3
%10 = getelementptr inbounds %struct.input_absinfo, %struct.input_absinfo* %4, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.input_absinfo, %struct.input_absinfo* %4, i64 0, i32 1
%13 = load i32, i32* %12
%14 = sub i32 %11, %13
%15 = mul i32 %14, %2
%16 = udiv i32 %15, 100
br label %17
17: ; preds = %3, %9
%18 = phi i32 [ %16, %9 ], [ -1, %3 ]
ret i32 %18
}