#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct input_event {
  scalar_t__ type;
  int value;
  int code;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ EV_KEY;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int open(char *, int /*<<< orphan*/);
char *optarg;
int read(int, struct input_event *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct timeval *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  fd_set readstruct;
  struct input_event event;
  int maxfd = -1;
  int fd = -1;
  int c = -1;
  char *inputdev = NULL;
  static char *VERSION = "0.3";
  while ((c = getopt(argc, argv, "f:")) != -1) {
    if (c == 'f') {
      inputdev = optarg;
    }
  }
  if (inputdev == NULL) {
    fprintf(
        stdout,
        "===============================================================\n");
    fprintf(stdout, "joybutt %s - 2009-2014 by Tony Bussieres.\n", VERSION);
    fprintf(stdout, "This program reads key from input event device.\n");
    fprintf(stdout,
            "GPLv3. get the license at http://www.gnu.org/copyleft/gpl.html\n");
    fprintf(
        stdout,
        "===============================================================\n");
    fprintf(stdout,
            "you need to pass the event device file -f /dev/input/eventXX\n");
    return -1;
  }
  fprintf(stdout, "Trying to open input : %s\n", inputdev);
  fd = open(inputdev, O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Failed to open input : %s\n", inputdev);
    return -1;
  }
  fprintf(stdout, "Open successful, reading key event\n");
  FD_ZERO(&readstruct);
  FD_SET(fd, &readstruct);
  maxfd = fd + 1;
  while (1) {
    struct timeval timeout;
    timeout.tv_sec = 10;
    timeout.tv_usec = 0;
    int ret = select(maxfd, &readstruct, 0, 0, &timeout);
    if (ret == 0) {
      timeout.tv_sec = 10;
      timeout.tv_usec = 0;
    } else if (ret > 0) {
      int r = read(fd, &event, sizeof(struct input_event));
      if (r == sizeof(struct input_event)) {
        if (event.type == EV_KEY) {
          fprintf(stdout, "%d\t%d\n", event.value, event.code);
          fflush(stdout);
        }
      } else {
        fprintf(stderr, "Unable to read from device!\n");
        close(fd);
        return -1;
      }
    } else {
      break;
    }
    FD_SET(fd, &readstruct);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe33(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     11ff <main+0x6f>
cmpl   $0x66,-0x34(%rbp)
jne    11fa <main+0x6a>
mov    0x2e05(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    11c3 <main+0x33>
cmpq   $0x0,-0x40(%rbp)
jne    12a7 <main+0x117>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rdx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    144b <main+0x2bb>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    0x2d13(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1308 <main+0x178>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    144b <main+0x2bb>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x14(%rbp),%rdi
call   1060 <FD_ZERO@plt>
mov    -0x30(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   10b0 <FD_SET@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movl   $0xa,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x50(%rbp),%r8
mov    %ecx,%edx
call   1070 <select@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    1381 <main+0x1f1>
movl   $0xa,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
jmp    142b <main+0x29b>
cmpl   $0x0,-0x54(%rbp)
jle    1421 <main+0x291>
mov    -0x30(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1040 <read@plt>
mov    %eax,-0x58(%rbp)
movslq -0x58(%rbp),%rax
cmp    $0x10,%rax
jne    13f1 <main+0x261>
mov    -0x28(%rbp),%rax
mov    0x2c20(%rip),%rcx
cmp    (%rcx),%rax
jne    13ec <main+0x25c>
mov    0x2bf8(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    141c <main+0x28c>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    144b <main+0x2bb>
jmp    1426 <main+0x296>
jmp    143c <main+0x2ac>
jmp    142b <main+0x29b>
mov    -0x30(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   10b0 <FD_SET@plt>
jmp    133d <main+0x1ad>
mov    -0x30(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe57(%rip),%r15
mov    0x2e44(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0xffffffff,%eax
je     11dd <main+0x4d>
cmp    $0x66,%eax
jne    11c0 <main+0x30>
mov    (%r12),%r14
jmp    11c0 <main+0x30>
mov    0x2ddc(%rip),%rbp
mov    0x0(%rbp),%edi
test   %r14,%r14
je     12fd <main+0x16d>
lea    0xf2b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1368 <main+0x1d8>
mov    %eax,%r12d
mov    0x0(%rbp),%edi
lea    0xf31(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0x24(%rsp),%r14
mov    %r14,%rdi
call   1060 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   10b0 <FD_SET@plt>
mov    %r12d,%r15d
add    $0x1,%r15d
mov    %rsp,%r13
lea    0x10(%rsp),%rbx
mov    0x2d7c(%rip),%rbp
jmp    127b <main+0xeb>
xchg   %ax,%ax
movl   $0xa,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %r12d,%edi
mov    %r14,%rsi
call   10b0 <FD_SET@plt>
movl   $0xa,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r13,%r8
call   1070 <select@plt>
test   %eax,%eax
je     1260 <main+0xd0>
jle    1384 <main+0x1f4>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1040 <read@plt>
cmp    $0x10,%eax
jne    1390 <main+0x200>
mov    0x10(%rsp),%rax
cmp    0x0(%rbp),%rax
jne    1270 <main+0xe0>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rsp),%edx
mov    0x1c(%rsp),%ecx
lea    0xe99(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    1270 <main+0xe0>
lea    0xd03(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd30(%rip),%rsi
lea    0xce1(%rip),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd43(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd63(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd85(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    13af <main+0x21f>
mov    0x2c59(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    13af <main+0x21f>
mov    %r12d,%edi
call   1030 <close@plt>
xor    %eax,%eax
jmp    13b4 <main+0x224>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12d,%edi
call   1030 <close@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.input_event = type { i64, i32, i32 }
%struct.timeval = type { i32, i64 }
@main.VERSION = internal global i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0)
@.str = [4 x i8] c"0.3\00"
@.str.1 = [3 x i8] c"f:\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.2 = [65 x i8] c"===============================================================\0A\00"
@.str.3 = [43 x i8] c"joybutt %s - 2009-2014 by Tony Bussieres.\0A\00"
@.str.4 = [49 x i8] c"This program reads key from input event device.\0A\00"
@.str.5 = [64 x i8] c"GPLv3. get the license at http://www.gnu.org/copyleft/gpl.html\0A\00"
@.str.6 = [62 x i8] c"you need to pass the event device file -f /dev/input/eventXX\0A\00"
@.str.7 = [27 x i8] c"Trying to open input : %s\0A\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.8 = [27 x i8] c"Failed to open input : %s\0A\00"
@.str.9 = [36 x i8] c"Open successful, reading key event\0A\00"
@EV_KEY = global i64 0
@.str.10 = [7 x i8] c"%d\09%d\0A\00"
@.str.11 = [29 x i8] c"Unable to read from device!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.input_event
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca %struct.timeval
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
store i32 -1, i32* %9
store i32 -1, i32* %10
store i8* null, i8** %11
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* %10
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i32, i32* %10
%22 = icmp eq i32 %21, 102
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i8*, i8** @optarg
store i8* %24, i8** %11
br label %25
25: ; preds = %23, %20
br label %15
26: ; preds = %15
%27 = load i8*, i8** %11
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %43
29: ; preds = %26
%30 = load i32, i32* @stdout
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @stdout
%33 = load i8*, i8** @main.VERSION
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @stdout
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @stdout
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0))
%39 = load i32, i32* @stdout
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @stdout
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %112
43: ; preds = %26
%44 = load i32, i32* @stdout
%45 = load i8*, i8** %11
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %11
%48 = load i32, i32* @O_RDONLY
%49 = call i32 @open(i8* %47, i32 %48)
store i32 %49, i32* %9
%50 = load i32, i32* %9
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %43
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %11
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %54)
store i32 -1, i32* %3
br label %112
56: ; preds = %43
%57 = load i32, i32* @stdout
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
%59 = call i32 @FD_ZERO(i32* %6)
%60 = load i32, i32* %9
%61 = call i32 @FD_SET(i32 %60, i32* %6)
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %64
64: ; preds = %56, %106
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 10, i32* %65
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %66
%67 = load i32, i32* %8
%68 = call i32 @select(i32 %67, i32* %6, i32 0, i32 0, %struct.timeval* %12)
store i32 %68, i32* %13
%69 = load i32, i32* %13
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 10, i32* %72
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %73
br label %106
74: ; preds = %64
%75 = load i32, i32* %13
%76 = icmp sgt i32 %75, 0
br i1 %76, label %77, label %104
77: ; preds = %74
%78 = load i32, i32* %9
%79 = call i32 @read(i32 %78, %struct.input_event* %7, i32 16)
store i32 %79, i32* %14
%80 = load i32, i32* %14
%81 = sext i32 %80 to i64
%82 = icmp eq i64 %81, 16
br i1 %82, label %83, label %98
83: ; preds = %77
%84 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
%85 = load i64, i64* %84
%86 = load i64, i64* @EV_KEY
%87 = icmp eq i64 %85, %86
br i1 %87, label %88, label %97
88: ; preds = %83
%89 = load i32, i32* @stdout
%90 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
%91 = load i32, i32* %90
%92 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
%93 = load i32, i32* %92
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %91, i32 %93)
%95 = load i32, i32* @stdout
%96 = call i32 @fflush(i32 %95)
br label %97
97: ; preds = %88, %83
br label %103
98: ; preds = %77
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
%101 = load i32, i32* %9
%102 = call i32 @close(i32 %101)
store i32 -1, i32* %3
br label %112
103: ; preds = %97
br label %105
104: ; preds = %74
br label %109
105: ; preds = %103
br label %106
106: ; preds = %105, %71
%107 = load i32, i32* %9
%108 = call i32 @FD_SET(i32 %107, i32* %6)
br label %64
109: ; preds = %104
%110 = load i32, i32* %9
%111 = call i32 @close(i32 %110)
store i32 0, i32* %3
br label %112
112: ; preds = %109, %98, %52, %29
%113 = load i32, i32* %3
ret i32 %113
}

LLVM IR (-O2):
%struct.input_event = type { i64, i32, i32 }
%struct.timeval = type { i32, i64 }
@.str = [4 x i8] c"0.3\00"
@.str.1 = [3 x i8] c"f:\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.2 = [65 x i8] c"===============================================================\0A\00"
@.str.3 = [43 x i8] c"joybutt %s - 2009-2014 by Tony Bussieres.\0A\00"
@.str.4 = [49 x i8] c"This program reads key from input event device.\0A\00"
@.str.5 = [64 x i8] c"GPLv3. get the license at http://www.gnu.org/copyleft/gpl.html\0A\00"
@.str.6 = [62 x i8] c"you need to pass the event device file -f /dev/input/eventXX\0A\00"
@.str.7 = [27 x i8] c"Trying to open input : %s\0A\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.8 = [27 x i8] c"Failed to open input : %s\0A\00"
@.str.9 = [36 x i8] c"Open successful, reading key event\0A\00"
@EV_KEY = global i64 0
@.str.10 = [7 x i8] c"%d\09%d\0A\00"
@.str.11 = [29 x i8] c"Unable to read from device!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.input_event
%5 = alloca %struct.timeval
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.input_event* %4 to i8*
br label %8
8: ; preds = %12, %2
%9 = phi i8* [ %13, %12 ], [ null, %2 ]
br label %10
10: ; preds = %8, %10
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %11, label %10 [
i32 -1, label %14
i32 102, label %12
]
12: ; preds = %10
%13 = load i8*, i8** @optarg
br label %8
14: ; preds = %10
%15 = icmp eq i8* %9, null
%16 = load i32, i32* @stdout
br i1 %15, label %17, label %29
17: ; preds = %14
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @stdout
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32, i32* @stdout
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
br label %77
29: ; preds = %14
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%31 = load i32, i32* @O_RDONLY
%32 = tail call i32 @open(i8* %9, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %9)
br label %77
37: ; preds = %29
%38 = load i32, i32* @stdout
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
%40 = call i32 @FD_ZERO(i32* %3)
%41 = call i32 @FD_SET(i32 %32, i32* %3)
%42 = add nuw nsw i32 %32, 1
%43 = bitcast %struct.timeval* %5 to i8*
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%46 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 0
%47 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 1
%48 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 2
br label %49
49: ; preds = %73, %37
store i32 10, i32* %44
store i64 0, i64* %45
%50 = call i32 @select(i32 %42, i32* %3, i32 0, i32 0, %struct.timeval* %5)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %49
store i32 10, i32* %44
store i64 0, i64* %45
br label %73
53: ; preds = %49
%54 = icmp sgt i32 %50, 0
br i1 %54, label %55, label %75
55: ; preds = %53
%56 = call i32 @read(i32 %32, %struct.input_event* %4, i32 16)
%57 = icmp eq i32 %56, 16
br i1 %57, label %58, label %69
58: ; preds = %55
%59 = load i64, i64* %46
%60 = load i64, i64* @EV_KEY
%61 = icmp eq i64 %59, %60
br i1 %61, label %62, label %73
62: ; preds = %58
%63 = load i32, i32* @stdout
%64 = load i32, i32* %47
%65 = load i32, i32* %48
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %64, i32 %65)
%67 = load i32, i32* @stdout
%68 = call i32 @fflush(i32 %67)
br label %73
69: ; preds = %55
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
%72 = call i32 @close(i32 %32)
br label %77
73: ; preds = %58, %62, %52
%74 = call i32 @FD_SET(i32 %32, i32* %3)
br label %49
75: ; preds = %53
%76 = call i32 @close(i32 %32)
br label %77
77: ; preds = %69, %75, %34, %17
%78 = phi i32 [ -1, %17 ], [ -1, %34 ], [ 0, %75 ], [ -1, %69 ]
ret i32 %78
}