#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*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XQueryPointer(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                 int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int *, int *, int *, int *, int *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned char);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int main(void) {
  int x, y, dx, dy;
  int b, numbits;
  unsigned char octet;
  Display *dpy;
  Window root;
  if (NULL == (dpy = XOpenDisplay(NULL)))
    errx(EXIT_FAILURE, "Cannot open display");
  root = DefaultRootWindow(dpy);
  x = 0;
  y = 0;
  octet = 0;
  numbits = 0;
  for (;;) {
    int rx, ry, wx, wy, m;
    Window wr, wc;
    usleep(1000);
    XQueryPointer(dpy, root, &wr, &wc, &rx, &ry, &wx, &wy, &m);
    dx = rx - x;
    dy = ry - y;
    if (!dx && !dy)
      continue;
    x = rx;
    y = ry;
    b = (dx * dy) & 3;
    octet = (octet << 2) | b;
    ++numbits;
    if (numbits < 8)
      continue;
    fprintf(stdout, "%c", octet);
    fflush(stdout);
    numbits = 0;
    octet = 0;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11af <main+0x3f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1040 <errx@plt>
mov    -0x28(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0x1d(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x3e8,%edi
call   1090 <usleep@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x44(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x34(%rbp),%r9
lea    -0x38(%rbp),%r11
lea    -0x3c(%rbp),%r10
lea    -0x40(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1070 <XQueryPointer@plt>
mov    -0x30(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x34(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    123f <main+0xcf>
cmpl   $0x0,-0x14(%rbp)
jne    123f <main+0xcf>
jmp    11d4 <main+0x64>
mov    -0x30(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x18(%rbp)
movzbl -0x1d(%rbp),%eax
shl    $0x2,%eax
or     -0x18(%rbp),%eax
mov    %al,-0x1d(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    127d <main+0x10d>
jmp    11d4 <main+0x64>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xd87(%rip),%rsi
movzbl -0x1d(%rbp),%edx
call   1060 <fprintf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
jmp    11d4 <main+0x64>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a9 <main+0x39>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <errx@plt>
mov    %rbx,%rdi
call   1030 <DefaultRootWindow@plt>
mov    %eax,0x18(%rsp)
movl   $0x0,0xc(%rsp)
xor    %r14d,%r14d
xor    %ebp,%ebp
jmp    11df <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14d,%r13d
mov    %ebp,%r12d
mov    %r13d,%r14d
mov    %r12d,%ebp
mov    %r15,%rbx
mov    $0x3e8,%edi
call   1090 <usleep@plt>
sub    $0x8,%rsp
mov    %rbx,%r15
mov    %rbx,%rdi
mov    0x20(%rsp),%esi
lea    0x30(%rsp),%rdx
lea    0x2c(%rsp),%rcx
lea    0x28(%rsp),%r8
lea    0x24(%rsp),%r9
lea    0x34(%rsp),%rax
push   %rax
lea    0x40(%rsp),%rax
push   %rax
lea    0x4c(%rsp),%rax
push   %rax
call   1070 <XQueryPointer@plt>
add    $0x20,%rsp
mov    0x20(%rsp),%r12d
mov    %r12d,%ecx
sub    %ebp,%ecx
mov    0x1c(%rsp),%r13d
mov    %r13d,%eax
sub    %r14d,%eax
mov    %ecx,%edx
or     %eax,%edx
je     11d0 <main+0x60>
imul   %ecx,%eax
and    $0x3,%eax
movzbl 0xc(%rsp),%ecx
lea    (%rax,%rcx,4),%ecx
mov    0x10(%rsp),%rax
cmp    $0x6,%eax
jg     126a <main+0xfa>
mov    %ecx,0xc(%rsp)
add    $0x1,%eax
mov    %rax,0x10(%rsp)
jmp    11d6 <main+0x66>
mov    0x2d67(%rip),%rbx
mov    (%rbx),%edi
movzbl %cl,%edx
lea    0xd97(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%rbx),%edi
call   1080 <fflush@plt>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
movl   $0x0,0xc(%rsp)
jmp    11d6 <main+0x66>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [20 x i8] c"Cannot open display\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%c\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%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* %1
%18 = call i32* @XOpenDisplay(i32* null)
store i32* %18, i32** %9
%19 = icmp eq i32* null, %18
br i1 %19, label %20, label %23
20: ; preds = %0
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @errx(i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %20, %0
%24 = load i32*, i32** %9
%25 = call i32 @DefaultRootWindow(i32* %24)
store i32 %25, i32* %10
store i32 0, i32* %2
store i32 0, i32* %3
store i8 0, i8* %8
store i32 0, i32* %7
br label %26
26: ; preds = %61, %60, %42, %23
%27 = call i32 @usleep(i32 1000)
%28 = load i32*, i32** %9
%29 = load i32, i32* %10
%30 = call i32 @XQueryPointer(i32* %28, i32 %29, i32* %16, i32* %17, i32* %11, i32* %12, i32* %13, i32* %14, i32* %15)
%31 = load i32, i32* %11
%32 = load i32, i32* %2
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %4
%34 = load i32, i32* %12
%35 = load i32, i32* %3
%36 = sub nsw i32 %34, %35
store i32 %36, i32* %5
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %26
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %39
br label %26
43: ; preds = %39, %26
%44 = load i32, i32* %11
store i32 %44, i32* %2
%45 = load i32, i32* %12
store i32 %45, i32* %3
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = mul nsw i32 %46, %47
%49 = and i32 %48, 3
store i32 %49, i32* %6
%50 = load i8, i8* %8
%51 = zext i8 %50 to i32
%52 = shl i32 %51, 2
%53 = load i32, i32* %6
%54 = or i32 %52, %53
%55 = trunc i32 %54 to i8
store i8 %55, i8* %8
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
%58 = load i32, i32* %7
%59 = icmp slt i32 %58, 8
br i1 %59, label %60, label %61
60: ; preds = %43
br label %26
61: ; preds = %43
%62 = load i32, i32* @stdout
%63 = load i8, i8* %8
%64 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %63)
%65 = load i32, i32* @stdout
%66 = call i32 @fflush(i32 %65)
store i32 0, i32* %7
store i8 0, i8* %8
br label %26
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [20 x i8] c"Cannot open display\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%c\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = tail call i32* @XOpenDisplay(i32* null)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @errx(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %0
%14 = tail call i32 @DefaultRootWindow(i32* %8)
%15 = bitcast i32* %1 to i8*
%16 = bitcast i32* %2 to i8*
%17 = bitcast i32* %3 to i8*
%18 = bitcast i32* %4 to i8*
%19 = bitcast i32* %5 to i8*
%20 = bitcast i32* %6 to i8*
%21 = bitcast i32* %7 to i8*
br label %22
22: ; preds = %51, %13
%23 = phi i32 [ 0, %13 ], [ %52, %51 ]
%24 = phi i8 [ 0, %13 ], [ %53, %51 ]
%25 = phi i32 [ 0, %13 ], [ %54, %51 ]
%26 = phi i32 [ 0, %13 ], [ %55, %51 ]
%27 = call i32 @usleep(i32 1000)
%28 = call i32 @XQueryPointer(i32* %8, i32 %14, i32* %6, i32* %7, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5)
%29 = load i32, i32* %1
%30 = sub nsw i32 %29, %26
%31 = load i32, i32* %2
%32 = sub nsw i32 %31, %25
%33 = icmp ne i32 %30, 0
%34 = icmp ne i32 %32, 0
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %36, label %51
36: ; preds = %22
%37 = mul nsw i32 %32, %30
%38 = and i32 %37, 3
%39 = zext i8 %24 to i32
%40 = shl nuw nsw i32 %39, 2
%41 = or i32 %38, %40
%42 = trunc i32 %41 to i8
%43 = icmp slt i32 %23, 7
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = add nsw i32 %23, 1
br label %51
46: ; preds = %36
%47 = load i32, i32* @stdout
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %42)
%49 = load i32, i32* @stdout
%50 = call i32 @fflush(i32 %49)
br label %51
51: ; preds = %22, %46, %44
%52 = phi i32 [ %45, %44 ], [ 0, %46 ], [ %23, %22 ]
%53 = phi i8 [ %42, %44 ], [ 0, %46 ], [ %24, %22 ]
%54 = phi i32 [ %31, %44 ], [ %31, %46 ], [ %25, %22 ]
%55 = phi i32 [ %29, %44 ], [ %29, %46 ], [ %26, %22 ]
br label %22
}