#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 */
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ EVIOCGNAME(int);
int /*<<< orphan*/ EVIOCGVERSION;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int);
int open_input_fd(char *dev) {
  int e, fd = open(dev, O_RDONLY);
  int version;
  char name[256] = "Unknown";
  if (fd < 0) {
    e = errno;
    {
      fprintf(stderr, "evf-getkey: ");
      fprintf(stderr, "Can't open %s: %s.", dev, strerror(e));
      fprintf(stderr, "\n");
    }
    return -1;
  }
  if (ioctl(fd, EVIOCGVERSION, &version)) {
    {
      fprintf(stderr, "evf-getkey: ");
      fprintf(stderr, "`%s' is not an input device.", dev);
      fprintf(stderr, "\n");
    }
    close(fd);
    return -1;
  }
  {
    printf("evf-getkey: ");
    printf("Input driver version %d.%d.%d", version >> 16, version >> 8 & 0xff,
           version & 0xff);
    printf("\n");
  };
  ioctl(fd, EVIOCGNAME(sizeof(name)), name);
  {
    printf("evf-getkey: ");
    printf("Device name `%s'", name);
    printf("\n");
  };
  return fd;
}


x86 assembly (clang, -O0):
<open_input_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x100,%edx
call   1070 <memcpy@plt>
cmpl   $0x0,-0x18(%rbp)
jge    124c <open_input_fd+0xcc>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xf1e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x14(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rdx
mov    %rax,%rcx
lea    0xeeb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xee7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136f <open_input_fd+0x1ef>
mov    -0x18(%rbp),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     12ca <open_input_fd+0x14a>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136f <open_input_fd+0x1ef>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
sar    $0x10,%esi
mov    -0x1c(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    $0x100,%edi
call   1090 <EVIOCGNAME@plt>
mov    -0x130(%rbp),%edi
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_input_fd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%ebx
lea    0xe49(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x100,%edx
call   1080 <memcpy@plt>
test   %ebx,%ebx
js     1238 <open_input_fd+0xa8>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
test   %rax,%rax
je     1291 <open_input_fd+0x101>
mov    0x2de7(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xf05(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xf16(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xf00(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffffff,%ebx
jmp    130b <open_input_fd+0x17b>
mov    0x2d91(%rip),%rax
mov    (%rax),%ebx
mov    0x2d90(%rip),%r15
mov    (%r15),%edi
lea    0xeae(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r15),%ebp
mov    %ebx,%edi
call   10b0 <strerror@plt>
lea    0xea3(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r15),%edi
lea    0xe9d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    130b <open_input_fd+0x17b>
lea    0xe68(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
movzbl %ah,%edx
movzbl %al,%ecx
sar    $0x10,%eax
lea    0xe89(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x100,%edi
call   10a0 <EVIOCGNAME@plt>
lea    0x10(%rsp),%rbp
mov    %ebx,%edi
mov    %eax,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe66(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@__const.open_input_fd.name = [256 x i8] c"Unknown\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@errno = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"evf-getkey: \00"
@.str.1 = [19 x i8] c"Can't open %s: %s.\00"
@.str.2 = [2 x i8] c"\0A\00"
@EVIOCGVERSION = global i32 0
@.str.3 = [29 x i8] c"`%s' is not an input device.\00"
@.str.4 = [30 x i8] c"Input driver version %d.%d.%d\00"
@.str.5 = [17 x i8] c"Device name `%s'\00"
define i32 @open_input_fd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %5
%11 = bitcast [256 x i8]* %7 to i8*
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %1
%15 = load i32, i32* @errno
store i32 %15, i32* %4
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %21)
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %60
25: ; preds = %1
%26 = load i32, i32* %5
%27 = load i32, i32* @EVIOCGVERSION
%28 = call i64 (i32, i32, ...) @ioctl(i32 %26, i32 %27, i32* %6)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %3
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %5
%39 = call i32 @close(i32 %38)
store i32 -1, i32* %2
br label %60
40: ; preds = %25
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%42 = load i32, i32* %6
%43 = ashr i32 %42, 16
%44 = load i32, i32* %6
%45 = ashr i32 %44, 8
%46 = and i32 %45, 255
%47 = load i32, i32* %6
%48 = and i32 %47, 255
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 %46, i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%51 = load i32, i32* %5
%52 = call i32 @EVIOCGNAME(i32 256)
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%54 = call i64 (i32, i32, ...) @ioctl(i32 %51, i32 %52, i8* %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%59 = load i32, i32* %5
store i32 %59, i32* %2
br label %60
60: ; preds = %40, %30, %14
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@__const.open_input_fd.name = [256 x i8] c"Unknown\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@errno = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"evf-getkey: \00"
@.str.1 = [19 x i8] c"Can't open %s: %s.\00"
@.str.2 = [2 x i8] c"\0A\00"
@EVIOCGVERSION = global i32 0
@.str.3 = [29 x i8] c"`%s' is not an input device.\00"
@.str.4 = [30 x i8] c"Input driver version %d.%d.%d\00"
@.str.5 = [17 x i8] c"Device name `%s'\00"
define i32 @open_input_fd(i8* %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = icmp slt i32 %5, 0
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = tail call i8* @strerror(i32 %10)
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %14)
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %44
18: ; preds = %1
%19 = load i32, i32* @EVIOCGVERSION
%20 = call i64 (i32, i32, ...) @ioctl(i32 %5, i32 %19, i32* %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %30, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @close(i32 %5)
br label %44
30: ; preds = %18
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* %2
%33 = ashr i32 %32, 16
%34 = lshr i32 %32, 8
%35 = and i32 %34, 255
%36 = and i32 %32, 255
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %33, i32 %35, i32 %36)
%38 = call i32 @putchar(i32 10)
%39 = call i32 @EVIOCGNAME(i32 256)
%40 = call i64 (i32, i32, ...) @ioctl(i32 %5, i32 %39, i8* %7)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%43 = call i32 @putchar(i32 10)
br label %44
44: ; preds = %30, %22, %9
%45 = phi i32 [ -1, %9 ], [ -1, %22 ], [ %5, %30 ]
ret i32 %45
}