#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct input_event {
  int /*<<< orphan*/ value;
  int /*<<< orphan*/ code;
  int /*<<< orphan*/ type;
  TYPE_1__ time;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
size_t read(int, struct input_event *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd = -1;
  int yalv;
  size_t read_bytes;
  struct input_event ev[64];
  if (argc != 2) {
    fprintf(stderr, "usage: %s event-device - probably /dev/input/evdev0\n",
            argv[0]);
    exit(1);
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    perror("evdev open");
    exit(1);
  }
  while (1) {
    read_bytes = read(fd, ev, sizeof(struct input_event) * 64);
    if (read_bytes < (int)sizeof(struct input_event)) {
      perror("evtest: short read");
      exit(1);
    }
    for (yalv = 0; yalv < (int)(read_bytes / sizeof(struct input_event));
         yalv++) {
      printf("Event: time %ld.%06ld, type %d, code %d, value %d\n",
             ev[yalv].time.tv_sec, ev[yalv].time.tv_usec, ev[yalv].type,
             ev[yalv].code, ev[yalv].value);
    }
  }
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b0 <main+0x50>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11e8 <main+0x88>
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11ed <main+0x8d>
mov    -0x14(%rbp),%edi
lea    -0x520(%rbp),%rsi
mov    $0x500,%edx
call   1040 <read@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x14,-0x20(%rbp)
jae    1226 <main+0xc6>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x524(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x14,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x524(%rbp),%eax
cmp    %ecx,%eax
jge    12d9 <main+0x179>
movslq -0x18(%rbp),%rcx
lea    -0x520(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    0x10(%rax),%esi
movslq -0x18(%rbp),%rcx
lea    -0x520(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    0xc(%rax),%edx
movslq -0x18(%rbp),%rcx
lea    -0x520(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%ecx
movslq -0x18(%rbp),%rdi
lea    -0x520(%rbp),%rax
imul   $0x14,%rdi,%rdi
add    %rdi,%rax
mov    0x4(%rax),%r8d
movslq -0x18(%rbp),%rdi
lea    -0x520(%rbp),%rax
imul   $0x14,%rdi,%rdi
add    %rdi,%rax
mov    (%rax),%r9d
lea    0xd8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    122d <main+0xcd>
jmp    11ed <main+0x8d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x508,%rsp
cmp    $0x2,%edi
jne    1195 <main+0x35>
mov    0x8(%rsi),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
jns    11b7 <main+0x57>
lea    0xea2(%rip),%rdi
jmp    11d6 <main+0x76>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%r12d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x500,%edx
call   1040 <read@plt>
cmp    $0x14,%rax
jae    11e5 <main+0x85>
lea    0xe6a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movabs $0xcccccccccccccccd,%r15
cc cc cc
lea    0xe5d(%rip),%r13
mov    %rsp,%r14
jmp    1216 <main+0xb6>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x500,%edx
call   1040 <read@plt>
cmp    $0x14,%rax
jb     11cf <main+0x6f>
mul    %r15
shr    $0x4,%rdx
test   %edx,%edx
jle    1200 <main+0xa0>
mov    %edx,%eax
shl    $0x2,%rax
lea    (%rax,%rax,4),%rbp
xor    %ebx,%ebx
nopl   (%rax)
mov    0x10(%rsp,%rbx,1),%esi
mov    0xc(%rsp,%rbx,1),%edx
mov    0x8(%rsp,%rbx,1),%ecx
mov    (%rsp,%rbx,1),%r9d
mov    0x4(%rsp,%rbx,1),%r8d
mov    %r13,%rdi
call   1030 <printf@plt>
add    $0x14,%rbx
cmp    %rbx,%rbp
jne    1230 <main+0xd0>
jmp    1200 <main+0xa0>

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32 }
@stderr = global i32 0
@.str = [53 x i8] c"usage: %s event-device - probably /dev/input/evdev0\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"evdev open\00"
@.str.2 = [19 x i8] c"evtest: short read\00"
@.str.3 = [51 x i8] c"Event: time %ld.%06ld, type %d, code %d, value %d\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 i64
%9 = alloca [64 x %struct.input_event]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %19
br label %30
30: ; preds = %29, %78
%31 = load i32, i32* %6
%32 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 0
%33 = call i64 @read(i32 %31, %struct.input_event* %32, i32 1280)
store i64 %33, i64* %8
%34 = load i64, i64* %8
%35 = icmp ult i64 %34, 20
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30
store i32 0, i32* %7
br label %40
40: ; preds = %75, %39
%41 = load i32, i32* %7
%42 = load i64, i64* %8
%43 = udiv i64 %42, 20
%44 = trunc i64 %43 to i32
%45 = icmp slt i32 %41, %44
br i1 %45, label %46, label %78
46: ; preds = %40
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %48
%50 = getelementptr inbounds %struct.input_event, %struct.input_event* %49, i32 0, i32 3
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %54
%56 = getelementptr inbounds %struct.input_event, %struct.input_event* %55, i32 0, i32 3
%57 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %60
%62 = getelementptr inbounds %struct.input_event, %struct.input_event* %61, i32 0, i32 2
%63 = load i32, i32* %62
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %65
%67 = getelementptr inbounds %struct.input_event, %struct.input_event* %66, i32 0, i32 1
%68 = load i32, i32* %67
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %9, i64 0, i64 %70
%72 = getelementptr inbounds %struct.input_event, %struct.input_event* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %52, i32 %58, i32 %63, i32 %68, i32 %73)
br label %75
75: ; preds = %46
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %40
78: ; preds = %40
br label %30
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32 }
@stderr = global i32 0
@.str = [53 x i8] c"usage: %s event-device - probably /dev/input/evdev0\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"evdev open\00"
@.str.2 = [19 x i8] c"evtest: short read\00"
@.str.3 = [51 x i8] c"Event: time %ld.%06ld, type %d, code %d, value %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x %struct.input_event]
%4 = bitcast [64 x %struct.input_event]* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 0
%19 = call i64 @read(i32 %15, %struct.input_event* %18, i32 1280)
%20 = icmp ult i64 %19, 20
br i1 %20, label %34, label %27
21: ; preds = %11
%22 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %37, %27
%25 = call i64 @read(i32 %15, %struct.input_event* %18, i32 1280)
%26 = icmp ult i64 %25, 20
br i1 %26, label %34, label %27
27: ; preds = %17, %24
%28 = phi i64 [ %25, %24 ], [ %19, %17 ]
%29 = udiv i64 %28, 20
%30 = trunc i64 %29 to i32
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %24
32: ; preds = %27
%33 = and i64 %29, 4294967295
br label %37
34: ; preds = %24, %17
%35 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %32, %37
%38 = phi i64 [ 0, %32 ], [ %50, %37 ]
%39 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 %38, i32 3, i32 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 %38, i32 3, i32 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 %38, i32 2
%44 = load i32, i32* %43
%45 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 %38, i32 1
%46 = load i32, i32* %45
%47 = getelementptr inbounds [64 x %struct.input_event], [64 x %struct.input_event]* %3, i64 0, i64 %38, i32 0
%48 = load i32, i32* %47
%49 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %42, i32 %44, i32 %46, i32 %48)
%50 = add nuw nsw i64 %38, 1
%51 = icmp eq i64 %50, %33
br i1 %51, label %24, label %37
}