#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int mfd;
  char b[3];
  mfd = open("/dev/input/mice", O_RDONLY);
  int xd = 0, yd = 0;
  int xo = 0, yo = 0;
  int lb = 0, mb = 0, rb = 0, hs = 0, vs = 0;
  int run = 0;
  while (!run) {
    read(mfd, b, sizeof(char) * 3);
    lb = (b[0] & 1) > 0;
    rb = (b[0] & 2) > 0;
    mb = (b[0] & 4) > 0;
    hs = (b[0] & 16) > 0;
    vs = (b[0] & 32) > 0;
    xo = (b[0] & 64) > 0;
    yo = (b[0] & 128) > 0;
    xd = b[1];
    yd = b[2];
    if (xd > 0) {
      printf("X+%d", xd);
    } else {
      printf("X%d", xd);
    }
    if (yd > 0) {
      printf("Y+%d", yd);
    } else {
      printf("Y%d", yd);
    }
    if (lb > 0) {
      printf("CCC");
    }
    fflush(stdout);
  }
  close(mfd);
  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)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11da <main+0x8a>
jmp    131b <main+0x1cb>
mov    -0x14(%rbp),%edi
lea    -0x17(%rbp),%rsi
mov    $0x3,%edx
call   1050 <read@plt>
movsbl -0x17(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
movsbl -0x17(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
movsbl -0x17(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
movsbl -0x17(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x38(%rbp)
movsbl -0x17(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
movsbl -0x17(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x17(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
movsbl -0x16(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x15(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    12ae <main+0x15e>
mov    -0x1c(%rbp),%esi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bf <main+0x16f>
mov    -0x1c(%rbp),%esi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jle    12df <main+0x18f>
mov    -0x20(%rbp),%esi
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f0 <main+0x1a0>
mov    -0x20(%rbp),%esi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1308 <main+0x1b8>
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    11c4 <main+0x74>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xeb0(%rip),%r15
lea    0xeae(%rip),%r14
mov    0x2e61(%rip),%r12
jmp    1189 <main+0x49>
nopl   0x0(%rax)
mov    (%r12),%edi
call   1050 <fflush@plt>
mov    %ebx,%edi
lea    0x5(%rsp),%rsi
mov    $0x3,%edx
call   1040 <read@plt>
movzbl 0x5(%rsp),%r13d
movsbl 0x6(%rsp),%esi
test   %esi,%esi
movsbl 0x7(%rsp),%ebp
lea    0xe62(%rip),%rdi
lea    0xe56(%rip),%rax
cmovg  %rax,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebp,%ebp
mov    %r14,%rdi
cmovg  %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   $0x1,%r13b
je     1180 <main+0x40>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1180 <main+0x40>

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"X+%d\00"
@.str.2 = [4 x i8] c"X%d\00"
@.str.3 = [5 x i8] c"Y+%d\00"
@.str.4 = [4 x i8] c"Y%d\00"
@.str.5 = [4 x i8] c"CCC\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [3 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %6
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
br label %20
20: ; preds = %98, %2
%21 = load i32, i32* %17
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %101
24: ; preds = %20
%25 = load i32, i32* %6
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 3)
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = and i32 %30, 1
%32 = icmp sgt i32 %31, 0
%33 = zext i1 %32 to i32
store i32 %33, i32* %12
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = and i32 %36, 2
%38 = icmp sgt i32 %37, 0
%39 = zext i1 %38 to i32
store i32 %39, i32* %14
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = and i32 %42, 4
%44 = icmp sgt i32 %43, 0
%45 = zext i1 %44 to i32
store i32 %45, i32* %13
%46 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = and i32 %48, 16
%50 = icmp sgt i32 %49, 0
%51 = zext i1 %50 to i32
store i32 %51, i32* %15
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = and i32 %54, 32
%56 = icmp sgt i32 %55, 0
%57 = zext i1 %56 to i32
store i32 %57, i32* %16
%58 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = and i32 %60, 64
%62 = icmp sgt i32 %61, 0
%63 = zext i1 %62 to i32
store i32 %63, i32* %10
%64 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = and i32 %66, 128
%68 = icmp sgt i32 %67, 0
%69 = zext i1 %68 to i32
store i32 %69, i32* %11
%70 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
store i32 %72, i32* %8
%73 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 2
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
store i32 %75, i32* %9
%76 = load i32, i32* %8
%77 = icmp sgt i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %24
%79 = load i32, i32* %8
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %79)
br label %84
81: ; preds = %24
%82 = load i32, i32* %8
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %82)
br label %84
84: ; preds = %81, %78
%85 = load i32, i32* %9
%86 = icmp sgt i32 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i32, i32* %9
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %88)
br label %93
90: ; preds = %84
%91 = load i32, i32* %9
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %91)
br label %93
93: ; preds = %90, %87
%94 = load i32, i32* %12
%95 = icmp sgt i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %93
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %98
98: ; preds = %96, %93
%99 = load i32, i32* @stdout
%100 = call i32 @fflush(i32 %99)
br label %20
101: ; preds = %20
%102 = load i32, i32* %6
%103 = call i32 @close(i32 %102)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"X+%d\00"
@.str.2 = [4 x i8] c"X%d\00"
@.str.3 = [5 x i8] c"Y+%d\00"
@.str.4 = [4 x i8] c"Y%d\00"
@.str.5 = [4 x i8] c"CCC\00"
@stdout = global i32 0
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_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %9
9: ; preds = %26, %2
%10 = call i32 @read(i32 %6, i8* %4, i32 3)
%11 = load i8, i8* %4
%12 = and i8 %11, 1
%13 = icmp eq i8 %12, 0
%14 = load i8, i8* %7
%15 = sext i8 %14 to i32
%16 = load i8, i8* %8
%17 = sext i8 %16 to i32
%18 = icmp sgt i8 %14, 0
%19 = select i1 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %19, i32 %15)
%21 = icmp sgt i8 %16, 0
%22 = select i1 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %22, i32 %17)
br i1 %13, label %26, label %24
24: ; preds = %9
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %9
%27 = load i32, i32* @stdout
%28 = tail call i32 @fflush(i32 %27)
br label %9
}