#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 /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int main(int argc, char **argv) {
  int fd, bytes;
  unsigned char data[3];
  const char *pDevice = "/dev/input/mice";
  fd = open(pDevice, O_RDWR);
  if (fd == -1) {
    printf("ERROR Opening %s\n", pDevice);
    return -1;
  }
  int left, middle, right;
  signed char x, y;
  while (1) {
    bytes = read(fd, data, sizeof(data));
    if (bytes > 0) {
      left = data[0] & 0x1;
      right = data[0] & 0x2;
      middle = data[0] & 0x4;
      x = data[1];
      y = data[2];
      printf("x=%d, y=%d, left=%d, middle=%d, right=%d\n", x, y, left, middle,
             right);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118d <main+0x5d>
mov    -0x28(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbp
ret
jmp    1192 <main+0x62>
mov    -0x14(%rbp),%edi
lea    -0x1b(%rbp),%rsi
mov    $0x3,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11fb <main+0xcb>
movzbl -0x1b(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movzbl -0x1b(%rbp),%eax
and    $0x2,%eax
mov    %eax,-0x34(%rbp)
movzbl -0x1b(%rbp),%eax
and    $0x4,%eax
mov    %eax,-0x30(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x35(%rbp)
mov    -0x19(%rbp),%al
mov    %al,-0x36(%rbp)
movsbl -0x35(%rbp),%esi
movsbl -0x36(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x34(%rbp),%r9d
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <main+0x62>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11b0 <main+0x80>
mov    %eax,%ebx
lea    0xd(%rsp),%r14
lea    0xec1(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1170 <main+0x40>
movzbl 0xd(%rsp),%r8d
mov    %r8d,%ecx
and    $0x1,%ecx
mov    %r8d,%r9d
and    $0x2,%r9d
and    $0x4,%r8d
movsbl 0xe(%rsp),%esi
movsbl 0xf(%rsp),%edx
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1170 <main+0x40>
lea    0xe59(%rip),%rdi
lea    0xe42(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDWR = global i32 0
@.str.1 = [18 x i8] c"ERROR Opening %s\0A\00"
@.str.2 = [42 x i8] c"x=%d, y=%d, left=%d, middle=%d, right=%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 [3 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
%14 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %9
%15 = load i8*, i8** %9
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i8*, i8** %9
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %21)
ret i32 -1
23: ; preds = %2
br label %24
24: ; preds = %23, %55
%25 = load i32, i32* %6
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 3)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %55
30: ; preds = %24
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = and i32 %33, 1
store i32 %34, i32* %10
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = and i32 %37, 2
store i32 %38, i32* %12
%39 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = and i32 %41, 4
store i32 %42, i32* %11
%43 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
%44 = load i8, i8* %43
store i8 %44, i8* %13
%45 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
%46 = load i8, i8* %45
store i8 %46, i8* %14
%47 = load i8, i8* %13
%48 = sext i8 %47 to i32
%49 = load i8, i8* %14
%50 = sext i8 %49 to i32
%51 = load i32, i32* %10
%52 = load i32, i32* %11
%53 = load i32, i32* %12
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %50, i32 %51, i32 %52, i32 %53)
br label %55
55: ; preds = %30, %24
br label %24
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDWR = global i32 0
@.str.1 = [18 x i8] c"ERROR Opening %s\0A\00"
@.str.2 = [42 x i8] c"x=%d, y=%d, left=%d, middle=%d, right=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %13
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
ret i32 -1
13: ; preds = %27, %8
%14 = call i32 @read(i32 %6, i8* %4, i32 3)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i8, i8* %4
%18 = zext i8 %17 to i32
%19 = and i32 %18, 1
%20 = and i32 %18, 2
%21 = and i32 %18, 4
%22 = load i8, i8* %9
%23 = load i8, i8* %10
%24 = sext i8 %22 to i32
%25 = sext i8 %23 to i32
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %25, i32 %19, i32 %21, i32 %20)
br label %27
27: ; preds = %16, %13
br label %13
}