#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 time_t;
struct input_event {
  scalar_t__ type;
  scalar_t__ code;
  int value;
};
typedef int /*<<< orphan*/ name;

/* Variables and functions */
scalar_t__ BTN_1;
int /*<<< orphan*/ EVIOCGID;
int /*<<< orphan*/ EVIOCGNAME(int);
int /*<<< orphan*/ EVIOCGVERSION;
scalar_t__ EV_KEY;
size_t ID_BUS;
size_t ID_PRODUCT;
size_t ID_VENDOR;
size_t ID_VERSION;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, struct input_event *, int);
int /*<<< orphan*/ system(char *);
int time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int fd, rd, i;
  struct input_event ev[64];
  int version;
  unsigned short id[4];
  char name[256] = "Unknown";
  time_t start_time;
  time_t duration;
  if (argc < 2) {
    printf("Usage: %s /dev/input/event<X> [cmd1] [cmd2]\n", argv[0]);
    printf("  X    = input device number\n");
    printf("  cmd1 = shell command to execute in case of short button press "
           "(less than %ds)\n",
           3);
    printf("  cmd2 = shell command to execute in case of long button press "
           "(more than %ds)\n",
           3);
    return 1;
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    perror("failed to open input device");
    return 1;
  }
  if (ioctl(fd, EVIOCGVERSION, &version)) {
    perror("can't get version");
    return 1;
  }
  printf("Input driver version is %d.%d.%d\n", version >> 16,
         (version >> 8) & 0xff, version & 0xff);
  ioctl(fd, EVIOCGID, id);
  printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
         id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]);
  ioctl(fd, EVIOCGNAME(sizeof(name)), name);
  printf("Input device name: \"%s\"\n", name);
  printf("Waiting for event from BTN_1 ... (interrupt to exit)\n");
  while (1) {
    rd = read(fd, ev, sizeof(struct input_event) * 64);
    if (rd < (int)sizeof(struct input_event)) {
      printf("yyy\n");
      perror("\nerror reading from device");
      return 1;
    }
    for (i = 0; i < rd / sizeof(struct input_event); i++)
      if ((ev[i].type == EV_KEY) && (ev[i].code == BTN_1)) {
        if (ev[i].value == 1) {
          start_time = time(NULL);
        }
        if (ev[i].value == 0) {
          duration = time(NULL) - start_time;
          if (duration < 3) {
            if (argc > 2) {
              printf("Executing shell command \"%s\" \n", argv[2]);
              system(argv[2]);
            } else
              printf(
                  "FoxBoard push button pressed for %d s (no cmd1 specified)\n",
                  duration);
          } else {
            if (argc > 3) {
              printf("Executing shell command \"%s\" \n", argv[3]);
              system(argv[3]);
            } else
              printf(
                  "FoxBoard push button pressed for %d s (no cmd2 specified)\n",
                  duration);
          }
        }
      }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x750,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x730(%rbp),%rdi
lea    0xe49(%rip),%rsi
mov    $0x100,%edx
call   1070 <memcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1220 <main+0x90>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xf27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf56(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf94(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    156b <main+0x3db>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    125a <main+0xca>
lea    0xfa3(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156b <main+0x3db>
mov    -0x14(%rbp),%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
lea    -0x624(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     1296 <main+0x106>
lea    0xf83(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156b <main+0x3db>
mov    -0x624(%rbp),%esi
sar    $0x10,%esi
mov    -0x624(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x624(%rbp),%ecx
and    $0xff,%ecx
lea    0xf59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2d06(%rip),%rax
mov    (%rax),%esi
lea    -0x62c(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%rax
movzwl -0x62c(%rbp,%rax,2),%esi
ff
mov    0x2ced(%rip),%rax
mov    (%rax),%rax
movzwl -0x62c(%rbp,%rax,2),%edx
ff
mov    0x2cab(%rip),%rax
mov    (%rax),%rax
movzwl -0x62c(%rbp,%rax,2),%ecx
ff
mov    0x2ca9(%rip),%rax
mov    (%rax),%rax
movzwl -0x62c(%rbp,%rax,2),%r8d
ff ff
lea    0xf0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x73c(%rbp)
mov    $0x100,%edi
call   10b0 <EVIOCGNAME@plt>
mov    -0x73c(%rbp),%edi
mov    %eax,%esi
lea    -0x730(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
lea    -0x730(%rbp),%rsi
lea    0xf0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x620(%rbp),%rsi
mov    $0x600,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x18,-0x18(%rbp)
jge    13cc <main+0x23c>
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf16(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    156b <main+0x3db>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x748(%rbp)
movslq -0x18(%rbp),%rax
mov    $0x18,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x748(%rbp),%rax
cmp    %rcx,%rax
jae    1566 <main+0x3d6>
movslq -0x1c(%rbp),%rcx
lea    -0x620(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    0x2bb5(%rip),%rcx
cmp    (%rcx),%rax
jne    1553 <main+0x3c3>
movslq -0x1c(%rbp),%rcx
lea    -0x620(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    0x2b67(%rip),%rcx
cmp    (%rcx),%rax
jne    1553 <main+0x3c3>
movslq -0x1c(%rbp),%rcx
lea    -0x620(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x1,0x10(%rax)
jne    1475 <main+0x2e5>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x734(%rbp)
movslq -0x1c(%rbp),%rcx
lea    -0x620(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,0x10(%rax)
jne    154e <main+0x3be>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
sub    -0x734(%rbp),%eax
mov    %eax,-0x738(%rbp)
cmpl   $0x3,-0x738(%rbp)
jge    14fe <main+0x36e>
cmpl   $0x2,-0x8(%rbp)
jle    14e5 <main+0x355>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <system@plt>
jmp    14f9 <main+0x369>
mov    -0x738(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1549 <main+0x3b9>
cmpl   $0x3,-0x8(%rbp)
jle    1530 <main+0x3a0>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <system@plt>
jmp    1544 <main+0x3b4>
mov    -0x738(%rbp),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1549 <main+0x3b9>
jmp    154e <main+0x3be>
jmp    1553 <main+0x3c3>
jmp    1558 <main+0x3c8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13d3 <main+0x243>
jmp    1385 <main+0x1f5>
mov    -0x4(%rbp),%eax
add    $0x750,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x728,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe43(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    $0x100,%edx
call   1080 <memcpy@plt>
cmp    $0x1,%ebp
jg     122b <main+0x8b>
mov    (%rbx),%rsi
lea    0xf25(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1178(%rip),%rdi
call   1030 <puts@plt>
lea    0xf38(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf76(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x728,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
jns    124d <main+0xad>
lea    0xf86(%rip),%rdi
jmp    136c <main+0x1cc>
mov    %eax,%r14d
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
lea    0x14(%rsp),%rdx
mov    %r14d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
test   %rax,%rax
jne    1365 <main+0x1c5>
mov    %rbx,0x18(%rsp)
mov    0x14(%rsp),%eax
movzbl %ah,%edx
movzbl %al,%ecx
sar    $0x10,%eax
lea    0xf72(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%rax
movzwl 0x8(%rsp,%rax,2),%esi
mov    0x2d27(%rip),%rax
mov    (%rax),%rax
movzwl 0x8(%rsp,%rax,2),%edx
mov    0x2ce8(%rip),%rax
mov    (%rax),%rax
movzwl 0x8(%rsp,%rax,2),%ecx
mov    0x2ce9(%rip),%rax
mov    (%rax),%rax
movzwl 0x8(%rsp,%rax,2),%r8d
lea    0xf2f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x100,%edi
call   10c0 <EVIOCGNAME@plt>
lea    0x20(%rsp),%r15
mov    %r14d,%edi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <ioctl@plt>
lea    0xf44(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xffc(%rip),%rdi
call   1030 <puts@plt>
lea    0x120(%rsp),%rsi
mov    %r14d,0x10(%rsp)
mov    %r14d,%edi
mov    $0x600,%edx
call   1070 <read@plt>
cmp    $0x18,%eax
jge    1376 <main+0x1d6>
lea    0x1006(%rip),%rdi
call   1030 <puts@plt>
lea    0xf15(%rip),%rdi
jmp    136c <main+0x1cc>
lea    0xe7e(%rip),%rdi
call   10b0 <perror@plt>
jmp    1214 <main+0x74>
mov    0x2c53(%rip),%r12
mov    0x2c24(%rip),%r14
mov    %ebp,0x4(%rsp)
jmp    13ab <main+0x20b>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%edi
lea    0x120(%rsp),%rsi
mov    $0x600,%edx
call   1070 <read@plt>
cmp    $0x18,%eax
jl     1350 <main+0x1b0>
mov    %eax,%r15d
mov    $0xaaaaaaab,%eax
imul   %rax,%r15
shr    $0x24,%r15
lea    0x130(%rsp),%rbx
jmp    13ea <main+0x24a>
lea    0xf21(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x18,%rbx
add    $0xffffffffffffffff,%r15
je     1390 <main+0x1f0>
mov    -0x10(%rbx),%rax
cmp    (%r12),%rax
jne    13e0 <main+0x240>
mov    -0x8(%rbx),%rax
cmp    (%r14),%rax
jne    13e0 <main+0x240>
mov    (%rbx),%eax
test   %eax,%eax
je     1414 <main+0x274>
cmp    $0x1,%eax
jne    13e0 <main+0x240>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%r13d
jmp    13e0 <main+0x240>
xor    %edi,%edi
call   1090 <time@plt>
sub    %r13d,%eax
cmp    $0x2,%eax
jg     1445 <main+0x2a5>
cmp    $0x3,%ebp
jb     1477 <main+0x2d7>
mov    0x18(%rsp),%rbp
mov    0x10(%rbp),%rsi
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbp),%rdi
jmp    1469 <main+0x2c9>
cmp    $0x4,%ebp
jb     13c5 <main+0x225>
mov    0x18(%rsp),%rbp
mov    0x18(%rbp),%rsi
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbp),%rdi
mov    0x4(%rsp),%ebp
call   1040 <system@plt>
jmp    13e0 <main+0x240>
lea    0xe34(%rip),%rdi
jmp    13cc <main+0x22c>

LLVM IR (-O0):
%struct.input_event = type { i64, i64, i32 }
@__const.main.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"
@.str = [45 x i8] c"Usage: %s /dev/input/event<X> [cmd1] [cmd2]\0A\00"
@.str.1 = [30 x i8] c" X = input device number\0A\00"
@.str.2 = [81 x i8] c" cmd1 = shell command to execute in case of short button press (less than %ds)\0A\00"
@.str.3 = [80 x i8] c" cmd2 = shell command to execute in case of long button press (more than %ds)\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [28 x i8] c"failed to open input device\00"
@EVIOCGVERSION = global i32 0
@.str.5 = [18 x i8] c"can't get version\00"
@.str.6 = [34 x i8] c"Input driver version is %d.%d.%d\0A\00"
@EVIOCGID = global i32 0
@.str.7 = [65 x i8] c"Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\0A\00"
@ID_BUS = global i64 0
@ID_VENDOR = global i64 0
@ID_PRODUCT = global i64 0
@ID_VERSION = global i64 0
@.str.8 = [25 x i8] c"Input device name: \22%s\22\0A\00"
@.str.9 = [54 x i8] c"Waiting for event from BTN_1 ... (interrupt to exit)\0A\00"
@.str.10 = [5 x i8] c"yyy\0A\00"
@.str.11 = [27 x i8] c"\0Aerror reading from device\00"
@EV_KEY = global i64 0
@BTN_1 = global i64 0
@.str.12 = [31 x i8] c"Executing shell command \22%s\22 \0A\00"
@.str.13 = [59 x i8] c"FoxBoard push button pressed for %d s (no cmd1 specified)\0A\00"
@.str.14 = [59 x i8] c"FoxBoard push button pressed for %d s (no cmd2 specified)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [64 x %struct.input_event]
%10 = alloca i32
%11 = alloca [4 x i16]
%12 = alloca [256 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [256 x i8]* %12 to i8*
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %26
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.2, i64 0, i64 0), i32 3)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.3, i64 0, i64 0), i32 3)
store i32 1, i32* %3
br label %173
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %173
35: ; preds = %26
%36 = load i32, i32* %6
%37 = load i32, i32* @EVIOCGVERSION
%38 = call i64 (i32, i32, ...) @ioctl(i32 %36, i32 %37, i32* %10)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %173
42: ; preds = %35
%43 = load i32, i32* %10
%44 = ashr i32 %43, 16
%45 = load i32, i32* %10
%46 = ashr i32 %45, 8
%47 = and i32 %46, 255
%48 = load i32, i32* %10
%49 = and i32 %48, 255
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %44, i32 %47, i32 %49)
%51 = load i32, i32* %6
%52 = load i32, i32* @EVIOCGID
%53 = getelementptr inbounds [4 x i16], [4 x i16]* %11, i64 0, i64 0
%54 = call i64 (i32, i32, ...) @ioctl(i32 %51, i32 %52, i16* %53)
%55 = load i64, i64* @ID_BUS
%56 = getelementptr inbounds [4 x i16], [4 x i16]* %11, i64 0, i64 %55
%57 = load i16, i16* %56
%58 = zext i16 %57 to i32
%59 = load i64, i64* @ID_VENDOR
%60 = getelementptr inbounds [4 x i16], [4 x i16]* %11, i64 0, i64 %59
%61 = load i16, i16* %60
%62 = zext i16 %61 to i32
%63 = load i64, i64* @ID_PRODUCT
%64 = getelementptr inbounds [4 x i16], [4 x i16]* %11, i64 0, i64 %63
%65 = load i16, i16* %64
%66 = zext i16 %65 to i32
%67 = load i64, i64* @ID_VERSION
%68 = getelementptr inbounds [4 x i16], [4 x i16]* %11, i64 0, i64 %67
%69 = load i16, i16* %68
%70 = zext i16 %69 to i32
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.7, i64 0, i64 0), i32 %58, i32 %62, i32 %66, i32 %70)
%72 = load i32, i32* %6
%73 = call i32 @EVIOCGNAME(i32 256)
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%75 = call i64 (i32, i32, ...) @ioctl(i32 %72, i32 %73, i8* %74)
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0))
br label %79
79: ; preds = %42, %172
%80 = load i32, i32* %6
%81 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 0
%82 = call i32 @read(i32 %80, %struct.input_event* %81, i32 1536)
store i32 %82, i32* %7
%83 = load i32, i32* %7
%84 = icmp slt i32 %83, 24
br i1 %84, label %85, label %88
85: ; preds = %79
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%87 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %173
88: ; preds = %79
store i32 0, i32* %8
br label %89
89: ; preds = %169, %88
%90 = load i32, i32* %8
%91 = sext i32 %90 to i64
%92 = load i32, i32* %7
%93 = sext i32 %92 to i64
%94 = udiv i64 %93, 24
%95 = icmp ult i64 %91, %94
br i1 %95, label %96, label %172
96: ; preds = %89
%97 = load i32, i32* %8
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %98
%100 = getelementptr inbounds %struct.input_event, %struct.input_event* %99, i32 0, i32 0
%101 = load i64, i64* %100
%102 = load i64, i64* @EV_KEY
%103 = icmp eq i64 %101, %102
br i1 %103, label %104, label %168
104: ; preds = %96
%105 = load i32, i32* %8
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %106
%108 = getelementptr inbounds %struct.input_event, %struct.input_event* %107, i32 0, i32 1
%109 = load i64, i64* %108
%110 = load i64, i64* @BTN_1
%111 = icmp eq i64 %109, %110
br i1 %111, label %112, label %168
112: ; preds = %104
%113 = load i32, i32* %8
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %114
%116 = getelementptr inbounds %struct.input_event, %struct.input_event* %115, i32 0, i32 2
%117 = load i32, i32* %116
%118 = icmp eq i32 %117, 1
br i1 %118, label %119, label %121
119: ; preds = %112
%120 = call i32 @time(i32* null)
store i32 %120, i32* %13
br label %121
121: ; preds = %119, %112
%122 = load i32, i32* %8
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %123
%125 = getelementptr inbounds %struct.input_event, %struct.input_event* %124, i32 0, i32 2
%126 = load i32, i32* %125
%127 = icmp eq i32 %126, 0
br i1 %127, label %128, label %167
128: ; preds = %121
%129 = call i32 @time(i32* null)
%130 = load i32, i32* %13
%131 = sub nsw i32 %129, %130
store i32 %131, i32* %14
%132 = load i32, i32* %14
%133 = icmp slt i32 %132, 3
br i1 %133, label %134, label %150
134: ; preds = %128
%135 = load i32, i32* %4
%136 = icmp sgt i32 %135, 2
br i1 %136, label %137, label %146
137: ; preds = %134
%138 = load i8**, i8*** %5
%139 = getelementptr inbounds i8*, i8** %138, i64 2
%140 = load i8*, i8** %139
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %140)
%142 = load i8**, i8*** %5
%143 = getelementptr inbounds i8*, i8** %142, i64 2
%144 = load i8*, i8** %143
%145 = call i32 @system(i8* %144)
br label %149
146: ; preds = %134
%147 = load i32, i32* %14
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.13, i64 0, i64 0), i32 %147)
br label %149
149: ; preds = %146, %137
br label %166
150: ; preds = %128
%151 = load i32, i32* %4
%152 = icmp sgt i32 %151, 3
br i1 %152, label %153, label %162
153: ; preds = %150
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 3
%156 = load i8*, i8** %155
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %156)
%158 = load i8**, i8*** %5
%159 = getelementptr inbounds i8*, i8** %158, i64 3
%160 = load i8*, i8** %159
%161 = call i32 @system(i8* %160)
br label %165
162: ; preds = %150
%163 = load i32, i32* %14
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.14, i64 0, i64 0), i32 %163)
br label %165
165: ; preds = %162, %153
br label %166
166: ; preds = %165, %149
br label %167
167: ; preds = %166, %121
br label %168
168: ; preds = %167, %104, %96
br label %169
169: ; preds = %168
%170 = load i32, i32* %8
%171 = add nsw i32 %170, 1
store i32 %171, i32* %8
br label %89
172: ; preds = %89
br label %79
173: ; preds = %85, %40, %33, %18
%174 = load i32, i32* %3
ret i32 %174
}

LLVM IR (-O2):
%struct.input_event = type { i64, i64, i32 }
@__const.main.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"
@.str = [45 x i8] c"Usage: %s /dev/input/event<X> [cmd1] [cmd2]\0A\00"
@.str.2 = [81 x i8] c" cmd1 = shell command to execute in case of short button press (less than %ds)\0A\00"
@.str.3 = [80 x i8] c" cmd2 = shell command to execute in case of long button press (more than %ds)\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [28 x i8] c"failed to open input device\00"
@EVIOCGVERSION = global i32 0
@.str.5 = [18 x i8] c"can't get version\00"
@.str.6 = [34 x i8] c"Input driver version is %d.%d.%d\0A\00"
@EVIOCGID = global i32 0
@.str.7 = [65 x i8] c"Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\0A\00"
@ID_BUS = global i64 0
@ID_VENDOR = global i64 0
@ID_PRODUCT = global i64 0
@ID_VERSION = global i64 0
@.str.8 = [25 x i8] c"Input device name: \22%s\22\0A\00"
@.str.11 = [27 x i8] c"\0Aerror reading from device\00"
@EV_KEY = global i64 0
@BTN_1 = global i64 0
@.str.12 = [31 x i8] c"Executing shell command \22%s\22 \0A\00"
@.str.13 = [59 x i8] c"FoxBoard push button pressed for %d s (no cmd1 specified)\0A\00"
@.str.14 = [59 x i8] c"FoxBoard push button pressed for %d s (no cmd2 specified)\0A\00"
@str = [53 x i8] c"Waiting for event from BTN_1 ... (interrupt to exit)\00"
@str.15 = [4 x i8] c"yyy\00"
@str.16 = [29 x i8] c" X = input device number\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x %struct.input_event]
%4 = alloca i32
%5 = alloca [4 x i16]
%6 = alloca [256 x i8]
%7 = bitcast [64 x %struct.input_event]* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast [4 x i16]* %5 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.16, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.2, i64 0, i64 0), i32 3)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @.str.3, i64 0, i64 0), i32 3)
br label %123
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = tail call i32 @open(i8* %20, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %123
26: ; preds = %18
%27 = load i32, i32* @EVIOCGVERSION
%28 = call i64 (i32, i32, ...) @ioctl(i32 %22, i32 %27, i32* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %123
32: ; preds = %26
%33 = load i32, i32* %4
%34 = ashr i32 %33, 16
%35 = lshr i32 %33, 8
%36 = and i32 %35, 255
%37 = and i32 %33, 255
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %34, i32 %36, i32 %37)
%39 = load i32, i32* @EVIOCGID
%40 = getelementptr inbounds [4 x i16], [4 x i16]* %5, i64 0, i64 0
%41 = call i64 (i32, i32, ...) @ioctl(i32 %22, i32 %39, i16* %40)
%42 = load i64, i64* @ID_BUS
%43 = getelementptr inbounds [4 x i16], [4 x i16]* %5, i64 0, i64 %42
%44 = load i16, i16* %43
%45 = zext i16 %44 to i32
%46 = load i64, i64* @ID_VENDOR
%47 = getelementptr inbounds [4 x i16], [4 x i16]* %5, i64 0, i64 %46
%48 = load i16, i16* %47
%49 = zext i16 %48 to i32
%50 = load i64, i64* @ID_PRODUCT
%51 = getelementptr inbounds [4 x i16], [4 x i16]* %5, i64 0, i64 %50
%52 = load i16, i16* %51
%53 = zext i16 %52 to i32
%54 = load i64, i64* @ID_VERSION
%55 = getelementptr inbounds [4 x i16], [4 x i16]* %5, i64 0, i64 %54
%56 = load i16, i16* %55
%57 = zext i16 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.7, i64 0, i64 0), i32 %45, i32 %49, i32 %53, i32 %57)
%59 = call i32 @EVIOCGNAME(i32 256)
%60 = call i64 (i32, i32, ...) @ioctl(i32 %22, i32 %59, i8* %10)
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %10)
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%63 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 0
%64 = call i32 @read(i32 %22, %struct.input_event* %63, i32 1536)
%65 = icmp slt i32 %64, 24
br i1 %65, label %79, label %66
66: ; preds = %32
%67 = icmp ugt i32 %0, 3
%68 = getelementptr inbounds i8*, i8** %1, i64 3
%69 = icmp ugt i32 %0, 2
%70 = getelementptr inbounds i8*, i8** %1, i64 2
br label %74
71: ; preds = %119
%72 = call i32 @read(i32 %22, %struct.input_event* %63, i32 1536)
%73 = icmp slt i32 %72, 24
br i1 %73, label %79, label %74
74: ; preds = %71, %66
%75 = phi i32 [ %64, %66 ], [ %72, %71 ]
%76 = phi i32 [ undef, %66 ], [ %120, %71 ]
%77 = udiv i32 %75, 24
%78 = zext i32 %77 to i64
br label %82
79: ; preds = %71, %32
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.15, i64 0, i64 0))
%81 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %123
82: ; preds = %74, %119
%83 = phi i64 [ 0, %74 ], [ %121, %119 ]
%84 = phi i32 [ %76, %74 ], [ %120, %119 ]
%85 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 %83, i32 0
%86 = load i64, i64* %85
%87 = load i64, i64* @EV_KEY
%88 = icmp eq i64 %86, %87
br i1 %88, label %89, label %119
89: ; preds = %82
%90 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 %83, i32 1
%91 = load i64, i64* %90
%92 = load i64, i64* @BTN_1
%93 = icmp eq i64 %91, %92
br i1 %93, label %94, label %119
94: ; preds = %89
%95 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 %83, i32 2
%96 = load i32, i32* %95
switch i32 %96, label %119 [
i32 1, label %97
i32 0, label %99
]
97: ; preds = %94
%98 = call i32 @time(i32* null)
br label %119
99: ; preds = %94
%100 = call i32 @time(i32* null)
%101 = sub nsw i32 %100, %84
%102 = icmp slt i32 %101, 3
br i1 %102, label %103, label %111
103: ; preds = %99
br i1 %69, label %104, label %109
104: ; preds = %103
%105 = load i8*, i8** %70
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %105)
%107 = load i8*, i8** %70
%108 = call i32 @system(i8* %107)
br label %119
109: ; preds = %103
%110 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.13, i64 0, i64 0), i32 %101)
br label %119
111: ; preds = %99
br i1 %67, label %112, label %117
112: ; preds = %111
%113 = load i8*, i8** %68
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %113)
%115 = load i8*, i8** %68
%116 = call i32 @system(i8* %115)
br label %119
117: ; preds = %111
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.14, i64 0, i64 0), i32 %101)
br label %119
119: ; preds = %94, %97, %82, %89, %109, %104, %117, %112
%120 = phi i32 [ %84, %104 ], [ %84, %109 ], [ %84, %112 ], [ %84, %117 ], [ %84, %89 ], [ %84, %82 ], [ %98, %97 ], [ %84, %94 ]
%121 = add nuw nsw i64 %83, 1
%122 = icmp eq i64 %121, %78
br i1 %122, label %71, label %82
123: ; preds = %79, %30, %24, %12
ret i32 1
}