#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 */

/* Variables and functions */
int /*<<< orphan*/ EVIOCGVERSION;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int IEVersion(int fd, int *version) {
  int err;
  err = ioctl(fd, EVIOCGVERSION, version);
  if (err < 0) {
    fprintf(stderr, "ioctl() failed: %s\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<IEVersion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1199 <IEVersion+0x69>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <IEVersion+0x70>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IEVersion>:
push   %rbx
mov    %rsi,%rdx
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
js     114c <IEVersion+0x1c>
pop    %rbx
ret
mov    0x2e8d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe96(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EVIOCGVERSION = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"ioctl() failed: %s\0A\00"
@errno = global i32 0
define i32 @IEVersion(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* %4
%8 = load i32, i32* @EVIOCGVERSION
%9 = load i32*, i32** %5
%10 = call i32 @ioctl(i32 %7, i32 %8, i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %3
br label %19
18: ; preds = %2
store i32 0, i32* %3
br label %19
19: ; preds = %18, %13
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@EVIOCGVERSION = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"ioctl() failed: %s\0A\00"
@errno = global i32 0
define i32 @IEVersion(i32 %0, i32* %1) {
%3 = load i32, i32* @EVIOCGVERSION
%4 = tail call i32 @ioctl(i32 %0, i32 %3, i32* %1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %2, %6
%12 = phi i32 [ -1, %6 ], [ 0, %2 ]
ret i32 %12
}