#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 input_event {
  scalar_t__ type;
  int code;
  int value;
};

/* Variables and functions */
scalar_t__ EV_KEY;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ err(int, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, struct input_event *, int);
int main(int argc, char **argv) {
  struct input_event ev;
  int fd;
  if (argc != 2) {
    printf("Usage: %s <evdev>\ne.g. /dev/input/event5\n", argv[0]);
    return 1;
  }
  if ((fd = open(argv[1], O_RDONLY)) == -1)
    err(2, "open %s", argv[1]);
  while (1) {
    read(fd, &ev, sizeof ev);
    if (ev.type == EV_KEY)
      printf("code: 0x%x, value: 0x%x\n", ev.code, ev.value);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1180 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11bb <main+0x7b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x2,%edi
lea    0xe74(%rip),%rsi
call   1050 <err@plt>
jmp    11c0 <main+0x80>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <read@plt>
mov    -0x20(%rbp),%rax
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%rax
jne    11f9 <main+0xb9>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c0 <main+0x80>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11ce <main+0x8e>
mov    0x8(%r14),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1181 <main+0x41>
mov    0x8(%r14),%rdx
lea    0xeb3(%rip),%rsi
mov    $0x2,%edi
call   1050 <err@plt>
lea    0x8(%rsp),%r14
mov    0x2e53(%rip),%r12
lea    0xe9e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <read@plt>
mov    0x8(%rsp),%rax
cmp    (%r12),%rax
jne    11a0 <main+0x60>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a0 <main+0x60>
mov    (%r14),%rsi
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.input_event = type { i64, i32, i32 }
@.str = [42 x i8] c"Usage: %s <evdev>\0Ae.g. /dev/input/event5\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"open %s\00"
@EV_KEY = global i64 0
@.str.2 = [25 x i8] c"code: 0x%x, value: 0x%x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.input_event
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %13)
ret i32 1
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %7
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @err(i32 2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %22, %15
br label %28
28: ; preds = %27, %41
%29 = load i32, i32* %7
%30 = call i32 @read(i32 %29, %struct.input_event* %6, i32 16)
%31 = getelementptr inbounds %struct.input_event, %struct.input_event* %6, i32 0, i32 0
%32 = load i64, i64* %31
%33 = load i64, i64* @EV_KEY
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %41
35: ; preds = %28
%36 = getelementptr inbounds %struct.input_event, %struct.input_event* %6, i32 0, i32 1
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.input_event, %struct.input_event* %6, i32 0, i32 2
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %37, i32 %39)
br label %41
41: ; preds = %35, %28
br label %28
}

LLVM IR (-O2):
%struct.input_event = type { i64, i32, i32 }
@.str = [42 x i8] c"Usage: %s <evdev>\0Ae.g. /dev/input/event5\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"open %s\00"
@EV_KEY = global i64 0
@.str.2 = [25 x i8] c"code: 0x%x, value: 0x%x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.input_event
%4 = bitcast %struct.input_event* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %7)
ret i32 1
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i8*, i8** %10
%17 = tail call i32 @err(i32 2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %9
%19 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 0
%20 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 1
%21 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 2
br label %22
22: ; preds = %31, %18
%23 = call i32 @read(i32 %13, %struct.input_event* %3, i32 16)
%24 = load i64, i64* %19
%25 = load i64, i64* @EV_KEY
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* %20
%29 = load i32, i32* %21
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29)
br label %31
31: ; preds = %27, %22
br label %22
}