#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 uinput_user_dev {
  int dummy;
};
struct input_event {
  int code;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ read(int, struct input_event *, int);
int main(void) {
  int fd;
  struct uinput_user_dev uidev;
  struct input_event ev;
  int dx, dy;
  int i;
  fd = open("/dev/input/mouse0", O_RDONLY);
  if (fd < 0)
    do {
      perror("error: open");
      exit(EXIT_FAILURE);
    } while (0);
  while (1) {
    if (read(fd, &ev, sizeof(struct input_event)) < 0)
      do {
        perror("error: write");
        exit(EXIT_FAILURE);
      } while (0);
    printf(" %d\n", ev.code);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a0 <main+0x50>
jmp    1186 <main+0x36>
lea    0xe85(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11a5 <main+0x55>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jge    11df <main+0x8f>
jmp    11c5 <main+0x75>
lea    0xe52(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
jmp    11a5 <main+0x55>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
jns    117b <main+0x2b>
lea    0xe99(%rip),%rdi
jmp    11c7 <main+0x77>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <read@plt>
test   %rax,%rax
js     11c0 <main+0x70>
lea    0xe91(%rip),%r14
lea    0x8(%rsp),%r15
nop
mov    0x8(%rsp),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
test   %rax,%rax
jns    11a0 <main+0x50>
lea    0xe57(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.uinput_user_dev = type { i32 }
%struct.input_event = type { i32 }
@.str = [18 x i8] c"/dev/input/mouse0\00"
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"error: open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [13 x i8] c"error: write\00"
@.str.3 = [5 x i8] c" %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.uinput_user_dev
%4 = alloca %struct.input_event
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %0
br label %13
13: ; preds = %12
%14 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; No predecessors!
br label %18
18: ; preds = %17, %0
br label %19
19: ; preds = %18, %29
%20 = load i32, i32* %2
%21 = call i64 @read(i32 %20, %struct.input_event* %4, i32 4)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %19
br label %24
24: ; preds = %23
%25 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; No predecessors!
br label %29
29: ; preds = %28, %19
%30 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %19
}

LLVM IR (-O2):
%struct.input_event = type { i32 }
@.str = [18 x i8] c"/dev/input/mouse0\00"
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"error: open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [13 x i8] c"error: write\00"
@.str.3 = [5 x i8] c" %d\0A\00"
define i32 @main() {
%1 = alloca %struct.input_event
%2 = bitcast %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, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = call i64 @read(i32 %4, %struct.input_event* %1, i32 4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.input_event, %struct.input_event* %1, i64 0, i32 0
br label %19
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %19, %6
%16 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %9, %19
%20 = load i32, i32* %10
%21 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = call i64 @read(i32 %4, %struct.input_event* %1, i32 4)
%23 = icmp slt i64 %22, 0
br i1 %23, label %15, label %19
}