#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 input_event TYPE_1__;

/* Type definitions */
struct input_event {
  long sec;
  long usec;
  unsigned short type;
  unsigned short code;
  unsigned int value;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ button(unsigned short);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, TYPE_1__ *, int);
void main() {
  struct input_event {
    long sec;
    long usec;
    unsigned short type;
    unsigned short code;
    unsigned value;
  } ev[2];
  int rd, fd, i;
  char *state[] = {"Up", "Down"};
  if ((fd = open("/dev/input/event7", O_RDONLY)) < 0) {
    perror("evtest");
    exit(-1);
  }
  while (1) {
    printf("-----\n");
    rd = read(fd, ev, sizeof(struct input_event) * 2);
    printf("%d %d\n", rd, sizeof(struct input_event));
    if (rd < (int)sizeof(struct input_event)) {
      continue;
    }
    printf(" %ld.%ld  %s %s\n", ev[0].sec, ev[0].usec / 1000,
           button(ev[0].code), state[ev[0].value]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x2c91(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c8e(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jge    11b5 <main+0x55>
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    11ba <main+0x5a>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x30,%edx
call   1050 <read@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x18,%edx
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x18,-0x34(%rbp)
jge    1201 <main+0xa1>
jmp    11ba <main+0x5a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x58(%rbp)
movzwl -0x1e(%rbp),%edi
call   1030 <button@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
mov    -0x50(%rbp,%rax,8),%r8
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ba <main+0x5a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %rbx
sub    $0x40,%rsp
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1259 <main+0xe9>
mov    %eax,%r14d
lea    0xe96(%rip),%r15
lea    0x10(%rsp),%rbp
lea    0xe72(%rip),%rbx
mov    %eax,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x30,%edx
call   1060 <read@plt>
mov    %eax,%r13d
mov    $0x18,%edx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x18,%r13d
jl     11c0 <main+0x50>
mov    0x10(%rsp),%r13
movabs $0x20c49ba5e353f7cf,%rax
9b c4 20
imulq  0x18(%rsp)
mov    %rbx,%r14
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x7,%rbx
add    %rax,%rbx
movzwl 0x22(%rsp),%edi
call   1040 <button@plt>
mov    0x24(%rsp),%ecx
lea    0xe11(%rip),%rdx
movslq (%rdx,%rcx,4),%r8
add    %rdx,%r8
lea    0xdeb(%rip),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r14,%rbx
mov    0xc(%rsp),%r14d
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c0 <main+0x50>
lea    0xdba(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i64, i64, i16, i16, i32 }
%struct.input_event.0 = type { i64, i64, i16, i16, i32 }
@.str = [3 x i8] c"Up\00"
@.str.1 = [5 x i8] c"Down\00"
@__const.main.state = [2 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [18 x i8] c"/dev/input/event7\00"
@O_RDONLY = global i32 0
@.str.3 = [7 x i8] c"evtest\00"
@.str.4 = [7 x i8] c"-----\0A\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [17 x i8] c" %ld.%ld %s %s\0A\00"
define void @main() {
%1 = alloca [2 x %struct.input_event]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i8*]
%6 = bitcast [2 x i8*]* %5 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %7)
store i32 %8, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
br label %14
14: ; preds = %13, %24, %25
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0
%18 = bitcast %struct.input_event* %17 to %struct.input_event.0*
%19 = call i32 @read(i32 %16, %struct.input_event.0* %18, i32 48)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %20, i64 24)
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 24
br i1 %23, label %24, label %25
24: ; preds = %14
br label %14
25: ; preds = %14
%26 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0
%27 = getelementptr inbounds %struct.input_event, %struct.input_event* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0
%30 = getelementptr inbounds %struct.input_event, %struct.input_event* %29, i32 0, i32 1
%31 = load i64, i64* %30
%32 = sdiv i64 %31, 1000
%33 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0
%34 = getelementptr inbounds %struct.input_event, %struct.input_event* %33, i32 0, i32 3
%35 = load i16, i16* %34
%36 = call i32 @button(i16 zeroext %35)
%37 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0
%38 = getelementptr inbounds %struct.input_event, %struct.input_event* %37, i32 0, i32 4
%39 = load i32, i32* %38
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64 %28, i64 %32, i32 %36, i8* %42)
br label %14
}

LLVM IR (-O2):
%struct.input_event = type { i64, i64, i16, i16, i32 }
%struct.input_event.0 = type { i64, i64, i16, i16, i32 }
@.str = [3 x i8] c"Up\00"
@.str.1 = [5 x i8] c"Down\00"
@reltable.main = [2 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([2 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([2 x i32]* @reltable.main to i64)) to i32)]
@.str.2 = [18 x i8] c"/dev/input/event7\00"
@O_RDONLY = global i32 0
@.str.3 = [7 x i8] c"evtest\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [17 x i8] c" %ld.%ld %s %s\0A\00"
@str = [6 x i8] c"-----\00"
define void @main() {
%1 = alloca [2 x %struct.input_event]
%2 = bitcast [2 x %struct.input_event]* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = bitcast [2 x %struct.input_event]* %1 to %struct.input_event.0*
%8 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0, i32 0
%9 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0, i32 1
%10 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0, i32 3
%11 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %1, i64 0, i64 0, i32 4
br label %15
12: ; preds = %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %31, %6
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%17 = call i32 @read(i32 %4, %struct.input_event.0* %7, i32 48)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %17, i64 24)
%19 = icmp slt i32 %17, 24
br i1 %19, label %31, label %20
20: ; preds = %15
%21 = load i64, i64* %8
%22 = load i64, i64* %9
%23 = sdiv i64 %22, 1000
%24 = load i16, i16* %10
%25 = tail call i32 @button(i16 zeroext %24)
%26 = load i32, i32* %11
%27 = zext i32 %26 to i64
%28 = shl i64 %27, 2
%29 = call i8* @llvm.load.relative.i64(i8* bitcast ([2 x i32]* @reltable.main to i8*), i64 %28)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64 %21, i64 %23, i32 %25, i8* %29)
br label %31
31: ; preds = %20, %15
br label %15
}