#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;
typedef int KEY_F1;

/* Variables and functions */
scalar_t__ BTN_LEFT;
scalar_t__ EV_KEY;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ KEY_ENTER;
scalar_t__ KEY_ESC;
scalar_t__ KEY_F11;
scalar_t__ KEY_F12;
scalar_t__ KEY_KPENTER;
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_node(unsigned char *, int, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct timeval *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  fd_set rfds;
  struct input_event ev;
  int retval, i;
  int biggest_so_far = 0;
  int fd_array[30];
  int expected_key;
  struct timeval tv;
  if (argc > 31) {
    fprintf(stderr, "read_devices: maximum is 30 arguments\n");
    fprintf(stderr, "usage: %s key files...\n", argv[0]);
    exit(1);
  }
  if (argc <= 2) {
    fprintf(stderr, "read_devices: few arguments\n");
    fprintf(stderr, "usage: %s key files...\n", argv[0]);
    exit(1);
  }
  expected_key = atoi(argv[1]);
  if (expected_key != 14)
    tv.tv_sec = 20;
  else
    tv.tv_sec = 5;
  tv.tv_usec = 0;
  for (i = 2; i < argc; i++) {
    fd_array[i] = open(argv[i], O_RDONLY);
    if (fd_array[i] == -1) {
      perror("select (ERROR)");
      exit(1);
    }
    if (fd_array[i] > biggest_so_far)
      biggest_so_far = fd_array[i];
  }
  while (1) {
    FD_ZERO(&rfds);
    for (i = 2; i < argc; i++)
      FD_SET(fd_array[i], &rfds);
    retval = select(biggest_so_far + 1, &rfds, 0, 0, &tv);
    if (retval == -1) {
      perror("select (ERROR)");
      exit(1);
    } else if (retval) {
      for (i = 2; i < argc; i++) {
        if (FD_ISSET(fd_array[i], &rfds)) {
          read_node((unsigned char *)&ev, fd_array[i],
                    sizeof(struct input_event));
          if (ev.type == EV_KEY && ev.value == 1 &&
              ((ev.code - (KEY_F1) + 1) == expected_key)) {
            printf("detect=|%s\n", argv[i]);
            exit(1);
          }
          if (ev.type == EV_KEY && ev.value == 1 &&
              ((ev.code == KEY_F11 && expected_key == 11) ||
               (ev.code == KEY_F12 && expected_key == 12))) {
            printf("detect=|%s\n", argv[i]);
            exit(1);
          }
          if (ev.type == EV_KEY && ev.value == 1 && ev.code == BTN_LEFT &&
              expected_key == 13) {
            printf("detect=|%s\n", argv[i]);
            exit(1);
          }
          if (ev.type == EV_KEY && ev.value == 1 &&
              (ev.code == KEY_ENTER || ev.code == KEY_KPENTER) &&
              expected_key == 14) {
            printf("detect=|enter\n");
            exit(1);
          }
          if (ev.type == EV_KEY && ev.value == 1 && ev.code == KEY_ESC &&
              expected_key == 14) {
            printf("detect=|esc\n");
            exit(1);
          }
        }
      }
    } else {
      printf("detect=|timeout\n");
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x1f,-0x8(%rbp)
jle    1219 <main+0x69>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jg     1262 <main+0xb2>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0xe,-0xb4(%rbp)
je     1291 <main+0xe1>
movl   $0x14,-0xc8(%rbp)
jmp    129b <main+0xeb>
movl   $0x5,-0xc8(%rbp)
movq   $0x0,-0xc0(%rbp)
movl   $0x2,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    133d <main+0x18d>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%ecx
movslq -0x30(%rbp),%rax
mov    %ecx,-0xb0(%rbp,%rax,4)
movslq -0x30(%rbp),%rax
cmpl   $0xffffffff,-0xb0(%rbp,%rax,4)
ff
jne    1308 <main+0x158>
lea    0xd63(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movslq -0x30(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%eax
cmp    -0x34(%rbp),%eax
jle    132a <main+0x17a>
movslq -0x30(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%eax
mov    %eax,-0x34(%rbp)
jmp    132f <main+0x17f>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12ad <main+0xfd>
jmp    1342 <main+0x192>
lea    -0x14(%rbp),%rdi
call   1070 <FD_ZERO@plt>
movl   $0x2,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1380 <main+0x1d0>
movslq -0x30(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%edi
lea    -0x14(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1352 <main+0x1a2>
mov    -0x34(%rbp),%edi
add    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %ecx,%ecx
lea    -0xc8(%rbp),%r8
mov    %ecx,%edx
call   1080 <select@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    13bd <main+0x20d>
lea    0xcae(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
je     162b <main+0x47b>
movl   $0x2,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1626 <main+0x476>
movslq -0x30(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1613 <main+0x463>
lea    -0x28(%rbp),%rdi
movslq -0x30(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%esi
mov    $0x10,%edx
call   1030 <read_node@plt>
mov    -0x28(%rbp),%rax
mov    0x2ba4(%rip),%rcx
cmp    (%rcx),%rax
jne    1465 <main+0x2b5>
cmpl   $0x1,-0x20(%rbp)
jne    1465 <main+0x2b5>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cmp    -0xb4(%rbp),%eax
jne    1465 <main+0x2b5>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    0x2b50(%rip),%rcx
cmp    (%rcx),%rax
jne    14e9 <main+0x339>
cmpl   $0x1,-0x20(%rbp)
jne    14e9 <main+0x339>
movslq -0x1c(%rbp),%rax
mov    0x2b1a(%rip),%rcx
cmp    (%rcx),%rax
jne    14a4 <main+0x2f4>
cmpl   $0xb,-0xb4(%rbp)
je     14c5 <main+0x315>
movslq -0x1c(%rbp),%rax
mov    0x2b31(%rip),%rcx
cmp    (%rcx),%rax
jne    14e9 <main+0x339>
cmpl   $0xc,-0xb4(%rbp)
jne    14e9 <main+0x339>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xb93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    0x2acc(%rip),%rcx
cmp    (%rcx),%rax
jne    154c <main+0x39c>
cmpl   $0x1,-0x20(%rbp)
jne    154c <main+0x39c>
movslq -0x1c(%rbp),%rax
mov    0x2abe(%rip),%rcx
cmp    (%rcx),%rax
jne    154c <main+0x39c>
cmpl   $0xd,-0xb4(%rbp)
jne    154c <main+0x39c>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xb30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    0x2a69(%rip),%rcx
cmp    (%rcx),%rax
jne    15b7 <main+0x407>
cmpl   $0x1,-0x20(%rbp)
jne    15b7 <main+0x407>
movslq -0x1c(%rbp),%rax
mov    0x2a23(%rip),%rcx
cmp    (%rcx),%rax
je     1592 <main+0x3e2>
movslq -0x1c(%rbp),%rax
mov    0x2a3f(%rip),%rcx
cmp    (%rcx),%rax
jne    15b7 <main+0x407>
cmpl   $0xe,-0xb4(%rbp)
jne    15b7 <main+0x407>
lea    0xad1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    0x29fe(%rip),%rcx
cmp    (%rcx),%rax
jne    160e <main+0x45e>
cmpl   $0x1,-0x20(%rbp)
jne    160e <main+0x45e>
movslq -0x1c(%rbp),%rax
mov    0x2a08(%rip),%rcx
cmp    (%rcx),%rax
jne    160e <main+0x45e>
cmpl   $0xe,-0xb4(%rbp)
jne    160e <main+0x45e>
lea    0xa89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1613 <main+0x463>
jmp    1618 <main+0x468>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13ce <main+0x21e>
jmp    1643 <main+0x493>
lea    0xa61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1648 <main+0x498>
jmp    1342 <main+0x192>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%r15
cmp    $0x20,%edi
jl     11eb <main+0x2b>
mov    0x2dd0(%rip),%rbx
mov    (%rbx),%edi
lea    0xe17(%rip),%rsi
jmp    1202 <main+0x42>
mov    %edi,%ebp
cmp    $0x2,%edi
jg     1226 <main+0x66>
mov    0x2db7(%rip),%rbx
mov    (%rbx),%edi
lea    0xe3d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
mov    (%r15),%rdx
lea    0xe12(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x8(%r15),%rdi
call   10c0 <atoi@plt>
mov    %eax,0x8(%rsp)
cmp    $0xe,%eax
mov    $0x5,%eax
mov    $0x14,%ecx
cmove  %eax,%ecx
mov    %ecx,0x20(%rsp)
movq   $0x0,0x28(%rsp)
mov    %ebp,%r13d
xor    %ebp,%ebp
mov    $0x2,%ebx
mov    0x2d77(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    (%r14),%esi
call   10a0 <open@plt>
mov    %eax,0x30(%rsp,%rbx,4)
cmp    $0xffffffff,%eax
je     13e0 <main+0x220>
cmp    %ebp,%eax
cmovg  %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1270 <main+0xb0>
add    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1080 <FD_ZERO@plt>
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x30(%rsp,%rbx,4),%edi
mov    %r14,%rsi
call   10e0 <FD_SET@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    12c0 <main+0x100>
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
call   1090 <select@plt>
cmp    $0xffffffff,%eax
je     13e0 <main+0x220>
test   %eax,%eax
je     1428 <main+0x268>
mov    $0x2,%r14d
mov    0x8(%rsp),%ebx
jmp    1319 <main+0x159>
cmp    $0xe,%ebx
je     1412 <main+0x252>
xchg   %ax,%ax
add    $0x1,%r14
cmp    %r14,%r13
je     12a0 <main+0xe0>
mov    0x30(%rsp,%r14,4),%r12d
mov    %r12d,%edi
lea    0xc(%rsp),%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1310 <main+0x150>
lea    0x10(%rsp),%rdi
mov    %r12d,%esi
mov    $0x10,%edx
call   1030 <read_node@plt>
mov    0x10(%rsp),%rax
mov    0x2c72(%rip),%rcx
cmp    (%rcx),%rax
jne    1310 <main+0x150>
cmpl   $0x1,0x18(%rsp)
jne    1310 <main+0x150>
movslq 0x1c(%rsp),%rax
lea    -0x1(%rax),%ecx
cmp    %ebx,%ecx
je     13f6 <main+0x236>
mov    0x2c37(%rip),%rcx
cmp    %rax,(%rcx)
jne    137b <main+0x1bb>
cmp    $0xb,%ebx
je     13f6 <main+0x236>
mov    0x2c5e(%rip),%rcx
cmp    %rax,(%rcx)
jne    138c <main+0x1cc>
cmp    $0xc,%ebx
je     13f6 <main+0x236>
mov    0x2c3d(%rip),%rcx
cmp    %rax,(%rcx)
jne    139d <main+0x1dd>
cmp    $0xd,%ebx
je     13f6 <main+0x236>
mov    0x2bf4(%rip),%rcx
cmp    %rax,(%rcx)
je     1305 <main+0x145>
mov    0x2c14(%rip),%rcx
cmp    %rax,(%rcx)
jne    13be <main+0x1fe>
cmp    $0xe,%ebx
je     1412 <main+0x252>
mov    0x2c23(%rip),%rcx
cmp    %rax,(%rcx)
jne    1310 <main+0x150>
cmp    $0xe,%ebx
jne    1310 <main+0x150>
lea    0xca9(%rip),%rdi
jmp    1419 <main+0x259>
lea    0xc75(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    (%r15,%r14,8),%rsi
lea    0xc6a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xc7a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xc48(%rip),%rdi
jmp    1419 <main+0x259>

LLVM IR (-O0):
%struct.input_event = type { i64, i32, i32 }
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [39 x i8] c"read_devices: maximum is 30 arguments\0A\00"
@.str.1 = [24 x i8] c"usage: %s key files...\0A\00"
@.str.2 = [29 x i8] c"read_devices: few arguments\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [15 x i8] c"select (ERROR)\00"
@EV_KEY = global i64 0
@.str.4 = [12 x i8] c"detect=|%s\0A\00"
@KEY_F11 = global i64 0
@KEY_F12 = global i64 0
@BTN_LEFT = global i64 0
@KEY_ENTER = global i64 0
@KEY_KPENTER = global i64 0
@.str.5 = [15 x i8] c"detect=|enter\0A\00"
@KEY_ESC = global i64 0
@.str.6 = [13 x i8] c"detect=|esc\0A\00"
@.str.7 = [17 x i8] c"detect=|timeout\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 [30 x i32]
%12 = alloca i32
%13 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 31
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp sle i32 %26, 2
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %25
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %12
%42 = load i32, i32* %12
%43 = icmp ne i32 %42, 14
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 20, i32* %45
br label %48
46: ; preds = %37
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 5, i32* %47
br label %48
48: ; preds = %46, %44
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i64 0, i64* %49
store i32 2, i32* %9
br label %50
50: ; preds = %86, %48
%51 = load i32, i32* %9
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %89
54: ; preds = %50
%55 = load i8**, i8*** %5
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = load i32, i32* @O_RDONLY
%61 = call i32 @open(i8* %59, i32 %60)
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [30 x i32], [30 x i32]* %11, i64 0, i64 %63
store i32 %61, i32* %64
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [30 x i32], [30 x i32]* %11, i64 0, i64 %66
%68 = load i32, i32* %67
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %54
%71 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %54
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [30 x i32], [30 x i32]* %11, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = load i32, i32* %10
%79 = icmp sgt i32 %77, %78
br i1 %79, label %80, label %85
80: ; preds = %73
%81 = load i32, i32* %9
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [30 x i32], [30 x i32]* %11, i64 0, i64 %82
%84 = load i32, i32* %83
store i32 %84, i32* %10
br label %85
85: ; preds = %80, %73
br label %86
86: ; preds = %85
%87 = load i32, i32* %9
%88 = add nsw i32 %87, 1
store i32 %88, i32* %9
br label %50
89: ; preds = %50
br label %90
90: ; preds = %89, %277
%91 = call i32 @FD_ZERO(i32* %6)
store i32 2, i32* %9
br label %92
92: ; preds = %102, %90
%93 = load i32, i32* %9
%94 = load i32, i32* %4
%95 = icmp slt i32 %93, %94
br i1 %95, label %96, label %105
96: ; preds = %92
%97 = load i32, i32* %9
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [30 x i32], [30 x i32]* %11, i64 0, i64 %98
%100 = load i32, i32* %99
%101 = call i32 @FD_SET(i32 %100, i32* %6)
br label %102
102: ; preds = %96
%103 = load i32, i32* %9
%104 = add nsw i32 %103, 1
store i32 %104, i32* %9
br label %92
105: ; preds = %92
%106 = load i32, i32* %10
%107 = add nsw i32 %106, 1
%108 = call i32 @select(i32 %107, i32* %6, i32 0, i32 0, %struct.timeval* %13)
store i32 %108, i32* %8
%109 = load i32, i32* %8
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %114
111: ; preds = %105
%112 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %105
%115 = load i32, i32* %8
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %273
117: ; preds = %114
store i32 2, i32* %9
br label %118
118: ; preds = %269, %117
%119 = load i32, i32* %9
%120 = load i32, i32* %4
%121 = icmp slt i32 %119, %120
br i1 %121, label %122, label %272
122: ; preds = %118
%123 = load i32, i32* %9
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [30 x i32], [30 x i32]* %11, i64 0, i64 %124
%126 = load i32, i32* %125
%127 = call i64 @FD_ISSET(i32 %126, i32* %6)
%128 = icmp ne i64 %127, 0
br i1 %128, label %129, label %268
129: ; preds = %122
%130 = bitcast %struct.input_event* %7 to i8*
%131 = load i32, i32* %9
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [30 x i32], [30 x i32]* %11, i64 0, i64 %132
%134 = load i32, i32* %133
%135 = call i32 @read_node(i8* %130, i32 %134, i32 16)
%136 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
%137 = load i64, i64* %136
%138 = load i64, i64* @EV_KEY
%139 = icmp eq i64 %137, %138
br i1 %139, label %140, label %158
140: ; preds = %129
%141 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
%142 = load i32, i32* %141
%143 = icmp eq i32 %142, 1
br i1 %143, label %144, label %158
144: ; preds = %140
%145 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
%146 = load i32, i32* %145
%147 = sub nsw i32 %146, 1
%148 = load i32, i32* %12
%149 = icmp eq i32 %147, %148
br i1 %149, label %150, label %158
150: ; preds = %144
%151 = load i8**, i8*** %5
%152 = load i32, i32* %9
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i8*, i8** %151, i64 %153
%155 = load i8*, i8** %154
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %155)
%157 = call i32 @exit(i32 1)
unreachable
158: ; preds = %144, %140, %129
%159 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
%160 = load i64, i64* %159
%161 = load i64, i64* @EV_KEY
%162 = icmp eq i64 %160, %161
br i1 %162, label %163, label %193
163: ; preds = %158
%164 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
%165 = load i32, i32* %164
%166 = icmp eq i32 %165, 1
br i1 %166, label %167, label %193
167: ; preds = %163
%168 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
%169 = load i32, i32* %168
%170 = sext i32 %169 to i64
%171 = load i64, i64* @KEY_F11
%172 = icmp eq i64 %170, %171
br i1 %172, label %173, label %176
173: ; preds = %167
%174 = load i32, i32* %12
%175 = icmp eq i32 %174, 11
br i1 %175, label %185, label %176
176: ; preds = %173, %167
%177 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
%178 = load i32, i32* %177
%179 = sext i32 %178 to i64
%180 = load i64, i64* @KEY_F12
%181 = icmp eq i64 %179, %180
br i1 %181, label %182, label %193
182: ; preds = %176
%183 = load i32, i32* %12
%184 = icmp eq i32 %183, 12
br i1 %184, label %185, label %193
185: ; preds = %182, %173
%186 = load i8**, i8*** %5
%187 = load i32, i32* %9
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds i8*, i8** %186, i64 %188
%190 = load i8*, i8** %189
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %190)
%192 = call i32 @exit(i32 1)
unreachable
193: ; preds = %182, %176, %163, %158
%194 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
%195 = load i64, i64* %194
%196 = load i64, i64* @EV_KEY
%197 = icmp eq i64 %195, %196
br i1 %197, label %198, label %219
198: ; preds = %193
%199 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
%200 = load i32, i32* %199
%201 = icmp eq i32 %200, 1
br i1 %201, label %202, label %219
202: ; preds = %198
%203 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
%204 = load i32, i32* %203
%205 = sext i32 %204 to i64
%206 = load i64, i64* @BTN_LEFT
%207 = icmp eq i64 %205, %206
br i1 %207, label %208, label %219
208: ; preds = %202
%209 = load i32, i32* %12
%210 = icmp eq i32 %209, 13
br i1 %210, label %211, label %219
211: ; preds = %208
%212 = load i8**, i8*** %5
%213 = load i32, i32* %9
%214 = sext i32 %213 to i64
%215 = getelementptr inbounds i8*, i8** %212, i64 %214
%216 = load i8*, i8** %215
%217 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %216)
%218 = call i32 @exit(i32 1)
unreachable
219: ; preds = %208, %202, %198, %193
%220 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
%221 = load i64, i64* %220
%222 = load i64, i64* @EV_KEY
%223 = icmp eq i64 %221, %222
br i1 %223, label %224, label %246
224: ; preds = %219
%225 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
%226 = load i32, i32* %225
%227 = icmp eq i32 %226, 1
br i1 %227, label %228, label %246
228: ; preds = %224
%229 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
%230 = load i32, i32* %229
%231 = sext i32 %230 to i64
%232 = load i64, i64* @KEY_ENTER
%233 = icmp eq i64 %231, %232
br i1 %233, label %240, label %234
234: ; preds = %228
%235 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
%236 = load i32, i32* %235
%237 = sext i32 %236 to i64
%238 = load i64, i64* @KEY_KPENTER
%239 = icmp eq i64 %237, %238
br i1 %239, label %240, label %246
240: ; preds = %234, %228
%241 = load i32, i32* %12
%242 = icmp eq i32 %241, 14
br i1 %242, label %243, label %246
243: ; preds = %240
%244 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%245 = call i32 @exit(i32 1)
unreachable
246: ; preds = %240, %234, %224, %219
%247 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
%248 = load i64, i64* %247
%249 = load i64, i64* @EV_KEY
%250 = icmp eq i64 %248, %249
br i1 %250, label %251, label %267
251: ; preds = %246
%252 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
%253 = load i32, i32* %252
%254 = icmp eq i32 %253, 1
br i1 %254, label %255, label %267
255: ; preds = %251
%256 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
%257 = load i32, i32* %256
%258 = sext i32 %257 to i64
%259 = load i64, i64* @KEY_ESC
%260 = icmp eq i64 %258, %259
br i1 %260, label %261, label %267
261: ; preds = %255
%262 = load i32, i32* %12
%263 = icmp eq i32 %262, 14
br i1 %263, label %264, label %267
264: ; preds = %261
%265 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%266 = call i32 @exit(i32 1)
unreachable
267: ; preds = %261, %255, %251, %246
br label %268
268: ; preds = %267, %122
br label %269
269: ; preds = %268
%270 = load i32, i32* %9
%271 = add nsw i32 %270, 1
store i32 %271, i32* %9
br label %118
272: ; preds = %118
br label %276
273: ; preds = %114
%274 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%275 = call i32 @exit(i32 1)
unreachable
276: ; preds = %272
br label %277
277: ; preds = %276
br label %90
}

LLVM IR (-O2):
%struct.input_event = type { i64, i32, i32 }
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [39 x i8] c"read_devices: maximum is 30 arguments\0A\00"
@.str.1 = [24 x i8] c"usage: %s key files...\0A\00"
@.str.2 = [29 x i8] c"read_devices: few arguments\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [15 x i8] c"select (ERROR)\00"
@EV_KEY = global i64 0
@.str.4 = [12 x i8] c"detect=|%s\0A\00"
@KEY_F11 = global i64 0
@KEY_F12 = global i64 0
@BTN_LEFT = global i64 0
@KEY_ENTER = global i64 0
@KEY_KPENTER = global i64 0
@KEY_ESC = global i64 0
@str = [16 x i8] c"detect=|timeout\00"
@str.8 = [12 x i8] c"detect=|esc\00"
@str.9 = [14 x i8] c"detect=|enter\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.input_event
%5 = alloca [30 x i32]
%6 = alloca %struct.timeval
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.input_event* %4 to i8*
%9 = bitcast [30 x i32]* %5 to i8*
%10 = bitcast %struct.timeval* %6 to i8*
%11 = icmp sgt i32 %0, 31
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = icmp slt i32 %0, 3
br i1 %20, label %21, label %28
21: ; preds = %19
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %1
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
%32 = icmp eq i32 %31, 14
%33 = select i1 %32, i32 5, i32 20
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
store i64 0, i64* %35
%36 = zext i32 %0 to i64
br label %47
37: ; preds = %59
%38 = add i32 %61, 1
%39 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 0
%40 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 1
%41 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 2
%42 = icmp eq i32 %31, 11
%43 = icmp eq i32 %31, 12
%44 = icmp eq i32 %31, 13
%45 = zext i32 %0 to i64
%46 = zext i32 %0 to i64
br label %64
47: ; preds = %28, %59
%48 = phi i64 [ 2, %28 ], [ %62, %59 ]
%49 = phi i32 [ 0, %28 ], [ %61, %59 ]
%50 = getelementptr inbounds i8*, i8** %1, i64 %48
%51 = load i8*, i8** %50
%52 = load i32, i32* @O_RDONLY
%53 = tail call i32 @open(i8* %51, i32 %52)
%54 = getelementptr inbounds [30 x i32], [30 x i32]* %5, i64 0, i64 %48
store i32 %53, i32* %54
%55 = icmp eq i32 %53, -1
br i1 %55, label %56, label %59
56: ; preds = %47
%57 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%58 = tail call i32 @exit(i32 1)
unreachable
59: ; preds = %47
%60 = icmp sgt i32 %53, %49
%61 = select i1 %60, i32 %53, i32 %49
%62 = add nuw nsw i64 %48, 1
%63 = icmp eq i64 %62, %36
br i1 %63, label %37, label %47
64: ; preds = %145, %37
%65 = call i32 @FD_ZERO(i32* %3)
br label %66
66: ; preds = %64, %66
%67 = phi i64 [ 2, %64 ], [ %71, %66 ]
%68 = getelementptr inbounds [30 x i32], [30 x i32]* %5, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = call i32 @FD_SET(i32 %69, i32* %3)
%71 = add nuw nsw i64 %67, 1
%72 = icmp eq i64 %71, %45
br i1 %72, label %73, label %66
73: ; preds = %66
%74 = call i32 @select(i32 %38, i32* %3, i32 0, i32 0, %struct.timeval* %6)
switch i32 %74, label %78 [
i32 -1, label %75
i32 0, label %148
]
75: ; preds = %73
%76 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %73, %145
%79 = phi i64 [ %146, %145 ], [ 2, %73 ]
%80 = getelementptr inbounds [30 x i32], [30 x i32]* %5, i64 0, i64 %79
%81 = load i32, i32* %80
%82 = call i64 @FD_ISSET(i32 %81, i32* %3)
%83 = icmp eq i64 %82, 0
br i1 %83, label %145, label %84
84: ; preds = %78
%85 = call i32 @read_node(i8* %8, i32 %81, i32 16)
%86 = load i64, i64* %39
%87 = load i64, i64* @EV_KEY
%88 = icmp eq i64 %86, %87
%89 = load i32, i32* %40
%90 = icmp eq i32 %89, 1
%91 = select i1 %88, i1 %90, i1 false
br i1 %91, label %92, label %145
92: ; preds = %84
%93 = load i32, i32* %41
%94 = add nsw i32 %93, -1
%95 = icmp eq i32 %94, %31
br i1 %95, label %96, label %102
96: ; preds = %92
%97 = and i64 %79, 4294967295
%98 = getelementptr inbounds i8*, i8** %1, i64 %97
%99 = load i8*, i8** %98
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %99)
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %92
%103 = sext i32 %93 to i64
%104 = load i64, i64* @KEY_F11
%105 = icmp eq i64 %104, %103
%106 = select i1 %105, i1 %42, i1 false
br i1 %106, label %111, label %107
107: ; preds = %102
%108 = load i64, i64* @KEY_F12
%109 = icmp eq i64 %108, %103
%110 = select i1 %109, i1 %43, i1 false
br i1 %110, label %111, label %117
111: ; preds = %107, %102
%112 = and i64 %79, 4294967295
%113 = getelementptr inbounds i8*, i8** %1, i64 %112
%114 = load i8*, i8** %113
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %114)
%116 = call i32 @exit(i32 1)
unreachable
117: ; preds = %107
%118 = load i64, i64* @BTN_LEFT
%119 = icmp eq i64 %118, %103
%120 = select i1 %119, i1 %44, i1 false
br i1 %120, label %121, label %127
121: ; preds = %117
%122 = and i64 %79, 4294967295
%123 = getelementptr inbounds i8*, i8** %1, i64 %122
%124 = load i8*, i8** %123
%125 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %124)
%126 = call i32 @exit(i32 1)
unreachable
127: ; preds = %117
%128 = load i64, i64* @KEY_ENTER
%129 = icmp eq i64 %128, %103
br i1 %129, label %134, label %130
130: ; preds = %127
%131 = load i64, i64* @KEY_KPENTER
%132 = icmp eq i64 %131, %103
%133 = select i1 %132, i1 %32, i1 false
br i1 %133, label %135, label %138
134: ; preds = %127
br i1 %32, label %135, label %145
135: ; preds = %130, %134
%136 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
%137 = call i32 @exit(i32 1)
unreachable
138: ; preds = %130
%139 = load i64, i64* @KEY_ESC
%140 = icmp eq i64 %139, %103
%141 = select i1 %140, i1 %32, i1 false
br i1 %141, label %142, label %145
142: ; preds = %138
%143 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%144 = call i32 @exit(i32 1)
unreachable
145: ; preds = %134, %84, %78, %138
%146 = add nuw nsw i64 %79, 1
%147 = icmp eq i64 %146, %46
br i1 %147, label %64, label %78
148: ; preds = %73
%149 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%150 = call i32 @exit(i32 1)
unreachable
}