#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, int, int, int, int, int, int, int, int);
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];
    printf("hs=%d,vs=%d,lb=%d rm=%d mb=%d xo=%d yo=%d xd=%5d yd=%5d\r", hs, vs,
           lb, rb, mb, xo, yo, xd, yd);
    fflush(stdout);
  }
  close(mfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
movl   $0x0,-0xc(%rbp)
mov    %edi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%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)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11db <main+0x8b>
jmp    12de <main+0x18e>
mov    -0x1c(%rbp),%edi
lea    -0x1f(%rbp),%rsi
mov    $0x3,%edx
call   1050 <read@plt>
movsbl -0x1f(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
movsbl -0x1f(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
movsbl -0x1f(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x38(%rbp)
movsbl -0x1f(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x40(%rbp)
movsbl -0x1f(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x44(%rbp)
movsbl -0x1f(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
movsbl -0x1f(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
movsbl -0x1e(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    -0x38(%rbp),%r9d
mov    -0x2c(%rbp),%ebx
mov    -0x30(%rbp),%r11d
mov    -0x24(%rbp),%r10d
mov    -0x28(%rbp),%eax
lea    0xd5b(%rip),%rdi
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1030 <printf@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    11c5 <main+0x75>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
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,%r13d
lea    0x5(%rsp),%r14
lea    0xea1(%rip),%r15
mov    0x2e62(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <read@plt>
movzbl 0x5(%rsp),%eax
mov    %eax,%ecx
and    $0x1,%ecx
mov    %eax,%r8d
shr    %r8d
and    $0x1,%r8d
mov    %eax,%r9d
shr    $0x2,%r9d
and    $0x1,%r9d
mov    %eax,%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %eax,%edx
shr    $0x5,%edx
and    $0x1,%edx
mov    %eax,%ebx
shr    $0x6,%ebx
and    $0x1,%ebx
shr    $0x7,%eax
movsbl 0x6(%rsp),%r10d
movsbl 0x7(%rsp),%ebp
mov    %r15,%rdi
push   %rbp
push   %r10
push   %rax
push   %rbx
call   1030 <printf@plt>
add    $0x20,%rsp
mov    (%r12),%edi
call   1050 <fflush@plt>
jmp    1180 <main+0x40>

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDONLY = global i32 0
@.str.1 = [57 x i8] c"hs=%d,vs=%d,lb=%d rm=%d mb=%d xo=%d yo=%d xd=%5d yd=%5d\0D\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 = %24, %2
%21 = load i32, i32* %17
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %88
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* %15
%77 = load i32, i32* %16
%78 = load i32, i32* %12
%79 = load i32, i32* %14
%80 = load i32, i32* %13
%81 = load i32, i32* %10
%82 = load i32, i32* %11
%83 = load i32, i32* %8
%84 = load i32, i32* %9
%85 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %76, i32 %77, i32 %78, i32 %79, i32 %80, i32 %81, i32 %82, i32 %83, i32 %84)
%86 = load i32, i32* @stdout
%87 = call i32 @fflush(i32 %86)
br label %20
88: ; preds = %20
%89 = load i32, i32* %6
%90 = call i32 @close(i32 %89)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDONLY = global i32 0
@.str.1 = [57 x i8] c"hs=%d,vs=%d,lb=%d rm=%d mb=%d xo=%d yo=%d xd=%5d yd=%5d\0D\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 = %9, %2
%10 = call i32 @read(i32 %6, i8* %4, i32 3)
%11 = load i8, i8* %4
%12 = zext i8 %11 to i32
%13 = and i32 %12, 1
%14 = lshr i32 %12, 1
%15 = and i32 %14, 1
%16 = lshr i32 %12, 2
%17 = and i32 %16, 1
%18 = lshr i32 %12, 4
%19 = and i32 %18, 1
%20 = lshr i32 %12, 5
%21 = and i32 %20, 1
%22 = lshr i32 %12, 6
%23 = and i32 %22, 1
%24 = lshr i32 %12, 7
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = load i8, i8* %8
%28 = sext i8 %27 to i32
%29 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %21, i32 %13, i32 %15, i32 %17, i32 %23, i32 %24, i32 %26, i32 %28)
%30 = load i32, i32* @stdout
%31 = tail call i32 @fflush(i32 %30)
br label %9
}