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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ KIOCSOUND;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int abs(char);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ read(int, struct input_event *, int);
int /*<<< orphan*/ usleep(int);
int main() {
  int fd;
  struct input_event ie;
  unsigned char button, bLeft, bMiddle, bRight;
  char x, y;
  int absolute_x, absolute_y;
  int freq_x, freq_y, sound, value;
  int freq[] = {523, 587, 659, 698, 784, 880, 988, 1046};
  if ((fd = open("/dev/input/mice", O_RDONLY)) == -1) {
    printf("Device open ERROR\n");
    exit(EXIT_FAILURE);
  } else {
    printf("Device open OK\n");
  }
  int dev = open("/dev/console", O_RDWR, 0);
  printf("right-click to set absolute x,y coordinates origin (0,0)\n");
  while (read(fd, &ie, sizeof(struct input_event))) {
    unsigned char *ptr = (unsigned char *)&ie;
    int i;
    button = ptr[0];
    bLeft = button & 0x1;
    bMiddle = (button & 0x4) > 0;
    bRight = (button & 0x2) > 0;
    x = (char)ptr[1];
    y = (char)ptr[2];
    if (bLeft)
      puts("Left button pressed");
    if (bRight)
      puts("Right button pressed");
    if (bMiddle)
      puts("Middle button pressed");
    absolute_x += x;
    absolute_y -= y;
    if (bMiddle) {
      absolute_x = 0;
      absolute_y = 0;
      printf("Absolute x,y coords origin recorded\n");
    }
    printf("X,Y: (%i, %i) dX,dY: (%d, %d)\n", absolute_x, absolute_y, x, y);
    freq_x = 700 * abs(x) % 20000;
    freq_y = 700 * abs(y) % 20000;
    sound = freq_x > freq_y ? freq_x : freq_y;
    value = ((abs(x) > abs(y) ? abs(x) : abs(y)) / 2) % 8;
    if (x || y) {
      ioctl(dev, KIOCSOUND, 1193180 / freq[value]);
      usleep(40000);
      ioctl(dev, KIOCSOUND, 0);
    } else {
      ioctl(dev, KIOCSOUND, 0);
    }
  }
  ioctl(dev, KIOCSOUND, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe6a(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe64(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe61(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11fa <main+0x7a>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    0xe3b(%rip),%rdi
xor    %edx,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x54(%rbp)
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
je     1462 <main+0x2e2>
lea    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x1,%eax
mov    %al,-0x12(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x13(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x14(%rbp)
mov    -0x60(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x60(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x16(%rbp)
cmpb   $0x0,-0x12(%rbp)
je     12bc <main+0x13c>
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
cmpb   $0x0,-0x14(%rbp)
je     12d2 <main+0x152>
lea    0xde1(%rip),%rdi
call   1030 <puts@plt>
cmpb   $0x0,-0x13(%rbp)
je     12e8 <main+0x168>
lea    0xde0(%rip),%rdi
call   1030 <puts@plt>
movsbl -0x15(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x16(%rbp),%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
cmpb   $0x0,-0x13(%rbp)
je     1324 <main+0x1a4>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
movsbl -0x15(%rbp),%ecx
movsbl -0x16(%rbp),%r8d
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x15(%rbp),%edi
call   1040 <abs@plt>
imul   $0x2bc,%eax,%eax
mov    $0x4e20,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
movsbl -0x16(%rbp),%edi
call   1040 <abs@plt>
imul   $0x2bc,%eax,%eax
mov    $0x4e20,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    138c <main+0x20c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x68(%rbp)
jmp    1392 <main+0x212>
mov    -0x28(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movsbl -0x15(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,-0x6c(%rbp)
movsbl -0x16(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jle    13cb <main+0x24b>
movsbl -0x15(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,-0x70(%rbp)
jmp    13d7 <main+0x257>
movsbl -0x16(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x30(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jne    1407 <main+0x287>
movsbl -0x16(%rbp),%eax
cmp    $0x0,%eax
je     144a <main+0x2ca>
mov    -0x54(%rbp),%edi
mov    0x2bc7(%rip),%rax
mov    (%rax),%esi
movslq -0x30(%rbp),%rcx
mov    $0x1234dc,%eax
cltd
idivl  -0x50(%rbp,%rcx,4)
mov    %eax,%edx
call   1060 <ioctl@plt>
mov    $0x9c40,%edi
call   10a0 <usleep@plt>
mov    -0x54(%rbp),%edi
mov    0x2b9c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
jmp    145d <main+0x2dd>
mov    -0x54(%rbp),%edi
mov    0x2b84(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
jmp    1232 <main+0xb2>
mov    -0x54(%rbp),%edi
mov    0x2b6c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1365 <main+0x1e5>
mov    %eax,%ebp
lea    0xee7(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,0x4(%rsp)
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1070 <read@plt>
test   %rax,%rax
je     1340 <main+0x1c0>
jmp    122c <main+0xac>
nopl   0x0(%rax)
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    0x4(%rsp),%edi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    %ebp,%edi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
test   %rax,%rax
je     1340 <main+0x1c0>
movzbl (%rsp),%ebx
movsbl 0x1(%rsp),%r14d
movsbl 0x2(%rsp),%r15d
test   $0x1,%bl
jne    1260 <main+0xe0>
test   $0x2,%bl
jne    1271 <main+0xf1>
test   $0x4,%bl
jne    1282 <main+0x102>
add    %r14d,%r13d
sub    %r15d,%r12d
jmp    12a0 <main+0x120>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
test   $0x2,%bl
je     1246 <main+0xc6>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
test   $0x4,%bl
je     124b <main+0xcb>
lea    0xddd(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
xor    %r12d,%r12d
xor    %r13d,%r13d
lea    0xdd5(%rip),%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1040 <abs@plt>
mov    %r15d,%edi
call   1040 <abs@plt>
mov    %r14d,%edi
call   1040 <abs@plt>
mov    %eax,%ebx
mov    %r15d,%edi
call   1040 <abs@plt>
cmp    %eax,%ebx
mov    %r15d,%edi
cmovg  %r14d,%edi
call   1040 <abs@plt>
or     %r15b,%r14b
je     1200 <main+0x80>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
lea    0x7(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
and    $0xfffffff8,%eax
sub    %eax,%ecx
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
movslq %ecx,%rcx
mov    $0x1234dc,%eax
xor    %edx,%edx
lea    0xcdd(%rip),%rdi
idivl  (%rdi,%rcx,4)
mov    0x4(%rsp),%edi
mov    %eax,%edx
call   1060 <ioctl@plt>
mov    $0x9c40,%edi
call   10a0 <usleep@plt>
jmp    1200 <main+0x80>
mov    0x2c91(%rip),%rax
mov    (%rax),%esi
mov    0x4(%rsp),%edi
xor    %edx,%edx
call   1060 <ioctl@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i32 }
@__const.main.freq = [8 x i32] [i32 523, i32 587, i32 659, i32 698, i32 784, i32 880, i32 988, i32 1046]
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Device open ERROR\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [16 x i8] c"Device open OK\0A\00"
@.str.3 = [13 x i8] c"/dev/console\00"
@O_RDWR = global i32 0
@.str.4 = [58 x i8] c"right-click to set absolute x,y coordinates origin (0,0)\0A\00"
@.str.5 = [20 x i8] c"Left button pressed\00"
@.str.6 = [21 x i8] c"Right button pressed\00"
@.str.7 = [22 x i8] c"Middle button pressed\00"
@.str.8 = [37 x i8] c"Absolute x,y coords origin recorded\0A\00"
@.str.9 = [31 x i8] c"X,Y: (%i, %i) dX,dY: (%d, %d)\0A\00"
@KIOCSOUND = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.input_event
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [8 x i32]
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32
store i32 0, i32* %1
%20 = bitcast [8 x i32]* %16 to i8*
%21 = load i32, i32* @O_RDONLY
%22 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %2
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28
%31 = load i32, i32* @O_RDWR
%32 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 0)
store i32 %32, i32* %17
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %156, %30
%35 = load i32, i32* %2
%36 = call i64 @read(i32 %35, %struct.input_event* %3, i32 4)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %157
38: ; preds = %34
%39 = bitcast %struct.input_event* %3 to i8*
store i8* %39, i8** %18
%40 = load i8*, i8** %18
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
store i8 %42, i8* %4
%43 = load i8, i8* %4
%44 = zext i8 %43 to i32
%45 = and i32 %44, 1
%46 = trunc i32 %45 to i8
store i8 %46, i8* %5
%47 = load i8, i8* %4
%48 = zext i8 %47 to i32
%49 = and i32 %48, 4
%50 = icmp sgt i32 %49, 0
%51 = zext i1 %50 to i32
%52 = trunc i32 %51 to i8
store i8 %52, i8* %6
%53 = load i8, i8* %4
%54 = zext i8 %53 to i32
%55 = and i32 %54, 2
%56 = icmp sgt i32 %55, 0
%57 = zext i1 %56 to i32
%58 = trunc i32 %57 to i8
store i8 %58, i8* %7
%59 = load i8*, i8** %18
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = load i8, i8* %60
store i8 %61, i8* %8
%62 = load i8*, i8** %18
%63 = getelementptr inbounds i8, i8* %62, i64 2
%64 = load i8, i8* %63
store i8 %64, i8* %9
%65 = load i8, i8* %5
%66 = icmp ne i8 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %38
%68 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %69
69: ; preds = %67, %38
%70 = load i8, i8* %7
%71 = icmp ne i8 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %74
74: ; preds = %72, %69
%75 = load i8, i8* %6
%76 = icmp ne i8 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
br label %79
79: ; preds = %77, %74
%80 = load i8, i8* %8
%81 = sext i8 %80 to i32
%82 = load i32, i32* %10
%83 = add nsw i32 %82, %81
store i32 %83, i32* %10
%84 = load i8, i8* %9
%85 = sext i8 %84 to i32
%86 = load i32, i32* %11
%87 = sub nsw i32 %86, %85
store i32 %87, i32* %11
%88 = load i8, i8* %6
%89 = icmp ne i8 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %79
store i32 0, i32* %10
store i32 0, i32* %11
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
br label %92
92: ; preds = %90, %79
%93 = load i32, i32* %10
%94 = load i32, i32* %11
%95 = load i8, i8* %8
%96 = sext i8 %95 to i32
%97 = load i8, i8* %9
%98 = sext i8 %97 to i32
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %93, i32 %94, i32 %96, i32 %98)
%100 = load i8, i8* %8
%101 = call i32 @abs(i8 signext %100)
%102 = mul nsw i32 700, %101
%103 = srem i32 %102, 20000
store i32 %103, i32* %12
%104 = load i8, i8* %9
%105 = call i32 @abs(i8 signext %104)
%106 = mul nsw i32 700, %105
%107 = srem i32 %106, 20000
store i32 %107, i32* %13
%108 = load i32, i32* %12
%109 = load i32, i32* %13
%110 = icmp sgt i32 %108, %109
br i1 %110, label %111, label %113
111: ; preds = %92
%112 = load i32, i32* %12
br label %115
113: ; preds = %92
%114 = load i32, i32* %13
br label %115
115: ; preds = %113, %111
%116 = phi i32 [ %112, %111 ], [ %114, %113 ]
store i32 %116, i32* %14
%117 = load i8, i8* %8
%118 = call i32 @abs(i8 signext %117)
%119 = load i8, i8* %9
%120 = call i32 @abs(i8 signext %119)
%121 = icmp sgt i32 %118, %120
br i1 %121, label %122, label %125
122: ; preds = %115
%123 = load i8, i8* %8
%124 = call i32 @abs(i8 signext %123)
br label %128
125: ; preds = %115
%126 = load i8, i8* %9
%127 = call i32 @abs(i8 signext %126)
br label %128
128: ; preds = %125, %122
%129 = phi i32 [ %124, %122 ], [ %127, %125 ]
%130 = sdiv i32 %129, 2
%131 = srem i32 %130, 8
store i32 %131, i32* %15
%132 = load i8, i8* %8
%133 = sext i8 %132 to i32
%134 = icmp ne i32 %133, 0
br i1 %134, label %139, label %135
135: ; preds = %128
%136 = load i8, i8* %9
%137 = sext i8 %136 to i32
%138 = icmp ne i32 %137, 0
br i1 %138, label %139, label %152
139: ; preds = %135, %128
%140 = load i32, i32* %17
%141 = load i32, i32* @KIOCSOUND
%142 = load i32, i32* %15
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds [8 x i32], [8 x i32]* %16, i64 0, i64 %143
%145 = load i32, i32* %144
%146 = sdiv i32 1193180, %145
%147 = call i32 @ioctl(i32 %140, i32 %141, i32 %146)
%148 = call i32 @usleep(i32 40000)
%149 = load i32, i32* %17
%150 = load i32, i32* @KIOCSOUND
%151 = call i32 @ioctl(i32 %149, i32 %150, i32 0)
br label %156
152: ; preds = %135
%153 = load i32, i32* %17
%154 = load i32, i32* @KIOCSOUND
%155 = call i32 @ioctl(i32 %153, i32 %154, i32 0)
br label %156
156: ; preds = %152, %139
br label %34
157: ; preds = %34
%158 = load i32, i32* %17
%159 = load i32, i32* @KIOCSOUND
%160 = call i32 @ioctl(i32 %158, i32 %159, i32 0)
ret i32 0
}

LLVM IR (-O2):
%struct.input_event = type { i32 }
@__const.main.freq = [8 x i32] [i32 523, i32 587, i32 659, i32 698, i32 784, i32 880, i32 988, i32 1046]
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"/dev/console\00"
@O_RDWR = global i32 0
@.str.5 = [20 x i8] c"Left button pressed\00"
@.str.6 = [21 x i8] c"Right button pressed\00"
@.str.7 = [22 x i8] c"Middle button pressed\00"
@.str.9 = [31 x i8] c"X,Y: (%i, %i) dX,dY: (%d, %d)\0A\00"
@KIOCSOUND = global i32 0
@str = [15 x i8] c"Device open OK\00"
@str.10 = [57 x i8] c"right-click to set absolute x,y coordinates origin (0,0)\00"
@str.11 = [36 x i8] c"Absolute x,y coords origin recorded\00"
@str.12 = [18 x i8] c"Device open ERROR\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 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @O_RDWR
%13 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 0)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.10, i64 0, i64 0))
%15 = call i64 @read(i32 %4, %struct.input_event* %1, i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %79, label %17
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %2, i64 1
%19 = getelementptr inbounds i8, i8* %2, i64 2
br label %20
20: ; preds = %17, %74
%21 = phi i32 [ undef, %17 ], [ %52, %74 ]
%22 = phi i32 [ undef, %17 ], [ %51, %74 ]
%23 = load i8, i8* %2
%24 = and i8 %23, 1
%25 = load i8, i8* %18
%26 = load i8, i8* %19
%27 = icmp eq i8 %24, 0
br i1 %27, label %30, label %28
28: ; preds = %20
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %20
%31 = and i8 %23, 2
%32 = icmp eq i8 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = and i8 %23, 4
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = sext i8 %25 to i32
%40 = add nsw i32 %21, %39
%41 = sext i8 %26 to i32
%42 = sub nsw i32 %22, %41
br label %48
43: ; preds = %35
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%45 = sext i8 %25 to i32
%46 = sext i8 %26 to i32
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.11, i64 0, i64 0))
br label %48
48: ; preds = %38, %43
%49 = phi i32 [ %46, %43 ], [ %41, %38 ]
%50 = phi i32 [ %45, %43 ], [ %39, %38 ]
%51 = phi i32 [ 0, %43 ], [ %42, %38 ]
%52 = phi i32 [ 0, %43 ], [ %40, %38 ]
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %52, i32 %51, i32 %50, i32 %49)
%54 = tail call i32 @abs(i8 signext %25)
%55 = tail call i32 @abs(i8 signext %26)
%56 = tail call i32 @abs(i8 signext %25)
%57 = tail call i32 @abs(i8 signext %26)
%58 = icmp sgt i32 %56, %57
%59 = select i1 %58, i8 %25, i8 %26
%60 = tail call i32 @abs(i8 signext %59)
%61 = icmp ne i8 %25, 0
%62 = icmp ne i8 %26, 0
%63 = select i1 %61, i1 true, i1 %62
br i1 %63, label %64, label %74
64: ; preds = %48
%65 = sdiv i32 %60, 2
%66 = srem i32 %65, 8
%67 = load i32, i32* @KIOCSOUND
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds [8 x i32], [8 x i32]* @__const.main.freq, i64 0, i64 %68
%70 = load i32, i32* %69
%71 = sdiv i32 1193180, %70
%72 = tail call i32 @ioctl(i32 %13, i32 %67, i32 %71)
%73 = tail call i32 @usleep(i32 40000)
br label %74
74: ; preds = %48, %64
%75 = load i32, i32* @KIOCSOUND
%76 = tail call i32 @ioctl(i32 %13, i32 %75, i32 0)
%77 = call i64 @read(i32 %4, %struct.input_event* %1, i32 4)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %20
79: ; preds = %74, %10
%80 = load i32, i32* @KIOCSOUND
%81 = tail call i32 @ioctl(i32 %13, i32 %80, i32 0)
ret i32 0
}