#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 value;
  int /*<<< orphan*/ code;
  void *type;
};
typedef int /*<<< orphan*/ ev;

/* Variables and functions */
int /*<<< orphan*/ ABS_X;
int /*<<< orphan*/ ABS_Y;
int /*<<< orphan*/ BTN_LEFT;
int /*<<< orphan*/ BTN_RIGHT;
void *EV_ABS;
void *EV_KEY;
int /*<<< orphan*/ UI_DEV_DESTROY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ crash(char *);
scalar_t__ get_raw_event(int, int *, int *, int *);
int init_hidraw();
int init_uinput();
scalar_t__ ioctl(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct input_event **, int /*<<< orphan*/, int);
int now();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ write(int, ...);
int main(int argc, char *argv[]) {
  int uinput_fd;
  int hidraw_fd;
  struct input_event ev[2];
  int b, x, y;
  int touch_state, landing_x0, landing_y0, landing_t0, has_moved;
  hidraw_fd = init_hidraw();
  uinput_fd = init_uinput();
  touch_state = 0;
  while (get_raw_event(hidraw_fd, &b, &x, &y)) {
    printf("%d %4d %4d\n", b, x, y);
    if (b == 1) {
      memset(&ev, 0, sizeof(struct input_event));
      ev[0].type = ev[1].type = EV_ABS;
      ev[0].code = ABS_X;
      ev[1].code = ABS_Y;
      ev[0].value = x;
      ev[1].value = y;
      if (write(uinput_fd, &ev, sizeof(ev)) < 0)
        crash("event write");
      if (touch_state == 0) {
        touch_state = 1;
        has_moved = 0;
        landing_x0 = x;
        landing_y0 = y;
        landing_t0 = now();
      } else {
        if ((((x - landing_x0)) > 0 ? ((x - landing_x0))
                                    : -((x - landing_x0))) > 80 ||
            (((y - landing_y0)) > 0 ? ((y - landing_y0))
                                    : -((y - landing_y0))) > 80)
          has_moved = 1;
      }
    } else {
      if (touch_state == 1 && has_moved == 0) {
        if ((now() - landing_t0) < 250) {
          ev[0].type = EV_KEY;
          ev[0].code = BTN_LEFT;
          ev[0].value = 1;
          if (write(uinput_fd, &ev[0], sizeof(ev[0])) < 0)
            crash("event write: Left-click");
          ev[0].value = 0;
          if (write(uinput_fd, &ev[0], sizeof(ev[0])) < 0)
            crash("event write: Left-click");
          printf("left-click\n");
        } else {
          ev[0].type = EV_KEY;
          ev[0].code = BTN_RIGHT;
          ev[0].value = 1;
          if (write(uinput_fd, &ev[0], sizeof(ev[0])) < 0)
            crash("event write");
          ev[0].value = 0;
          if (write(uinput_fd, &ev[0], sizeof(ev[0])) < 0)
            crash("event write: Right-click");
          printf("right-click: Right-click\n");
        }
      }
      touch_state = 0;
    }
  }
  if (ioctl(uinput_fd, UI_DEV_DESTROY) < 0)
    crash("error: ioctl");
  close(uinput_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <init_hidraw@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10b0 <init_uinput@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x44(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x4c(%rbp),%rcx
call   1060 <get_raw_event@plt>
cmp    $0x0,%rax
je     147e <main+0x2de>
mov    -0x44(%rbp),%esi
mov    -0x48(%rbp),%edx
mov    -0x4c(%rbp),%ecx
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x1,-0x44(%rbp)
jne    132f <main+0x18f>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    %rax,-0x38(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0x0,%rax
jge    127f <main+0xdf>
lea    0xd92(%rip),%rdi
call   1030 <crash@plt>
cmpl   $0x0,-0x50(%rbp)
jne    12b2 <main+0x112>
movl   $0x1,-0x50(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    $0x0,%al
call   10c0 <now@plt>
mov    %eax,-0x5c(%rbp)
jmp    132a <main+0x18a>
mov    -0x48(%rbp),%eax
sub    -0x54(%rbp),%eax
cmp    $0x0,%eax
jle    12cf <main+0x12f>
mov    -0x48(%rbp),%eax
sub    -0x54(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    12dc <main+0x13c>
mov    -0x48(%rbp),%ecx
sub    -0x54(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    $0x50,%eax
jg     131e <main+0x17e>
mov    -0x4c(%rbp),%eax
sub    -0x58(%rbp),%eax
cmp    $0x0,%eax
jle    1305 <main+0x165>
mov    -0x4c(%rbp),%eax
sub    -0x58(%rbp),%eax
mov    %eax,-0x68(%rbp)
jmp    1312 <main+0x172>
mov    -0x4c(%rbp),%ecx
sub    -0x58(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    $0x50,%eax
jle    1325 <main+0x185>
movl   $0x1,-0x60(%rbp)
jmp    132a <main+0x18a>
jmp    1479 <main+0x2d9>
cmpl   $0x1,-0x50(%rbp)
jne    1472 <main+0x2d2>
cmpl   $0x0,-0x60(%rbp)
jne    1472 <main+0x2d2>
mov    $0x0,%al
call   10c0 <now@plt>
sub    -0x5c(%rbp),%eax
cmp    $0xfa,%eax
jge    13e5 <main+0x245>
mov    0x2c71(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0x0,%rax
jge    13a2 <main+0x202>
lea    0xc7b(%rip),%rdi
call   1030 <crash@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0x0,%rax
jge    13d2 <main+0x232>
lea    0xc4b(%rip),%rdi
call   1030 <crash@plt>
lea    0xc57(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    146d <main+0x2cd>
mov    0x2be4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2bf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0x0,%rax
jge    142f <main+0x28f>
lea    0xbe2(%rip),%rdi
call   1030 <crash@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0x0,%rax
jge    145f <main+0x2bf>
lea    0xbe2(%rip),%rdi
call   1030 <crash@plt>
lea    0xbef(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1472 <main+0x2d2>
movl   $0x0,-0x50(%rbp)
jmp    11d1 <main+0x31>
mov    -0x14(%rbp),%edi
mov    0x2b40(%rip),%rax
mov    (%rax),%esi
call   1090 <ioctl@plt>
cmp    $0x0,%rax
jge    14a5 <main+0x305>
lea    0xbcf(%rip),%rdi
call   1030 <crash@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@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
sub    $0x58,%rsp
xor    %eax,%eax
call   1040 <init_hidraw@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   10c0 <init_uinput@plt>
mov    %eax,%r15d
lea    0xc(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r12d,%edi
call   1070 <get_raw_event@plt>
test   %rax,%rax
je     1490 <main+0x2e0>
lea    0xe07(%rip),%rbx
lea    0xc(%rsp),%rbp
xor    %r14d,%r14d
mov    %r12d,0x1c(%rsp)
jmp    124c <main+0x9c>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r13d
movl   $0x1,0x14(%rsp)
mov    %r12d,%r15d
mov    0x1c(%rsp),%r12d
lea    0xc(%rsp),%rbp
mov    %r12d,%edi
mov    %rbp,%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1070 <get_raw_event@plt>
mov    %r13d,%r14d
test   %rax,%rax
je     1490 <main+0x2e0>
mov    0xc(%rsp),%esi
mov    0x18(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
cmpl   $0x1,0xc(%rsp)
jne    1330 <main+0x180>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x38(%rsp)
mov    %rax,0x28(%rsp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x18(%rsp),%eax
mov    %eax,0x20(%rsp)
mov    0x10(%rsp),%eax
mov    %eax,0x30(%rsp)
mov    $0x20,%edx
mov    %r15d,%r12d
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <write@plt>
test   %rax,%rax
jns    12e5 <main+0x135>
lea    0xd2c(%rip),%rdi
call   1030 <crash@plt>
mov    0x18(%rsp),%r15d
test   %r14d,%r14d
je     13e1 <main+0x231>
sub    0x54(%rsp),%r15d
mov    %r15d,%eax
neg    %eax
cmovs  %r15d,%eax
cmp    $0x50,%eax
ja     1210 <main+0x60>
mov    0x10(%rsp),%eax
sub    0x4c(%rsp),%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
mov    $0x1,%r13d
cmp    $0x51,%ecx
jae    1210 <main+0x60>
jmp    121e <main+0x6e>
nopl   (%rax)
xor    %r13d,%r13d
cmp    $0x1,%r14d
jne    122b <main+0x7b>
cmpl   $0x0,0x14(%rsp)
jne    122b <main+0x7b>
xor    %eax,%eax
call   10d0 <now@plt>
sub    0x50(%rsp),%eax
mov    0x2c76(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,0x28(%rsp)
cmp    $0xf9,%eax
jg     140c <main+0x25c>
mov    0x2c64(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
movl   $0x1,0x20(%rsp)
mov    $0x10,%edx
mov    %r15d,%edi
lea    0x20(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <write@plt>
test   %rax,%rax
jns    13aa <main+0x1fa>
lea    0xc73(%rip),%rdi
call   1030 <crash@plt>
movl   $0x0,0x20(%rsp)
mov    $0x10,%edx
mov    %r15d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <write@plt>
test   %rax,%rax
jns    13d5 <main+0x225>
lea    0xc48(%rip),%rdi
call   1030 <crash@plt>
lea    0xc93(%rip),%rdi
jmp    147b <main+0x2cb>
mov    0x10(%rsp),%eax
mov    %eax,0x4c(%rsp)
movl   $0x0,0x14(%rsp)
xor    %eax,%eax
call   10d0 <now@plt>
mov    %eax,0x50(%rsp)
mov    $0x1,%r13d
mov    %r15d,0x54(%rsp)
jmp    121e <main+0x6e>
mov    0x2bdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
movl   $0x1,0x20(%rsp)
mov    $0x10,%edx
mov    %r15d,%edi
lea    0x20(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <write@plt>
test   %rax,%rax
jns    1449 <main+0x299>
lea    0xbc8(%rip),%rdi
call   1030 <crash@plt>
movl   $0x0,0x20(%rsp)
mov    $0x10,%edx
mov    %r15d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <write@plt>
test   %rax,%rax
jns    1474 <main+0x2c4>
lea    0xbc1(%rip),%rdi
call   1030 <crash@plt>
lea    0xbdb(%rip),%rdi
call   1050 <puts@plt>
xor    %r13d,%r13d
movl   $0x0,0x14(%rsp)
jmp    122b <main+0x7b>
mov    0x2b31(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   10a0 <ioctl@plt>
test   %rax,%rax
jns    14b2 <main+0x302>
lea    0xb9c(%rip),%rdi
call   1030 <crash@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i8* }
@.str = [12 x i8] c"%d %4d %4d\0A\00"
@EV_ABS = global i8* null
@ABS_X = global i32 0
@ABS_Y = global i32 0
@.str.1 = [12 x i8] c"event write\00"
@EV_KEY = global i8* null
@BTN_LEFT = global i32 0
@.str.2 = [24 x i8] c"event write: Left-click\00"
@.str.3 = [12 x i8] c"left-click\0A\00"
@BTN_RIGHT = global i32 0
@.str.4 = [25 x i8] c"event write: Right-click\00"
@.str.5 = [26 x i8] c"right-click: Right-click\0A\00"
@UI_DEV_DESTROY = global i32 0
@.str.6 = [13 x i8] c"error: ioctl\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 [2 x %struct.input_event]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 (...) @init_hidraw()
store i32 %17, i32* %7
%18 = call i32 (...) @init_uinput()
store i32 %18, i32* %6
store i32 0, i32* %12
br label %19
19: ; preds = %164, %2
%20 = load i32, i32* %7
%21 = call i64 @get_raw_event(i32 %20, i32* %9, i32* %10, i32* %11)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %165
23: ; preds = %19
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %25, i32 %26)
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %99
30: ; preds = %23
%31 = bitcast [2 x %struct.input_event]* %8 to %struct.input_event**
%32 = call i32 @memset(%struct.input_event** %31, i32 0, i32 16)
%33 = load i8*, i8** @EV_ABS
%34 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 1
%35 = getelementptr inbounds %struct.input_event, %struct.input_event* %34, i32 0, i32 2
store i8* %33, i8** %35
%36 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%37 = getelementptr inbounds %struct.input_event, %struct.input_event* %36, i32 0, i32 2
store i8* %33, i8** %37
%38 = load i32, i32* @ABS_X
%39 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%40 = getelementptr inbounds %struct.input_event, %struct.input_event* %39, i32 0, i32 1
store i32 %38, i32* %40
%41 = load i32, i32* @ABS_Y
%42 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 1
%43 = getelementptr inbounds %struct.input_event, %struct.input_event* %42, i32 0, i32 1
store i32 %41, i32* %43
%44 = load i32, i32* %10
%45 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%46 = getelementptr inbounds %struct.input_event, %struct.input_event* %45, i32 0, i32 0
store i32 %44, i32* %46
%47 = load i32, i32* %11
%48 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 1
%49 = getelementptr inbounds %struct.input_event, %struct.input_event* %48, i32 0, i32 0
store i32 %47, i32* %49
%50 = load i32, i32* %6
%51 = call i64 (i32, ...) @write(i32 %50, [2 x %struct.input_event]* %8, i64 32)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %30
%54 = call i32 @crash(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %55
55: ; preds = %53, %30
%56 = load i32, i32* %12
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %55
store i32 1, i32* %12
store i32 0, i32* %16
%59 = load i32, i32* %10
store i32 %59, i32* %13
%60 = load i32, i32* %11
store i32 %60, i32* %14
%61 = call i32 (...) @now()
store i32 %61, i32* %15
br label %98
62: ; preds = %55
%63 = load i32, i32* %10
%64 = load i32, i32* %13
%65 = sub nsw i32 %63, %64
%66 = icmp sgt i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %62
%68 = load i32, i32* %10
%69 = load i32, i32* %13
%70 = sub nsw i32 %68, %69
br label %76
71: ; preds = %62
%72 = load i32, i32* %10
%73 = load i32, i32* %13
%74 = sub nsw i32 %72, %73
%75 = sub nsw i32 0, %74
br label %76
76: ; preds = %71, %67
%77 = phi i32 [ %70, %67 ], [ %75, %71 ]
%78 = icmp sgt i32 %77, 80
br i1 %78, label %96, label %79
79: ; preds = %76
%80 = load i32, i32* %11
%81 = load i32, i32* %14
%82 = sub nsw i32 %80, %81
%83 = icmp sgt i32 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %79
%85 = load i32, i32* %11
%86 = load i32, i32* %14
%87 = sub nsw i32 %85, %86
br label %93
88: ; preds = %79
%89 = load i32, i32* %11
%90 = load i32, i32* %14
%91 = sub nsw i32 %89, %90
%92 = sub nsw i32 0, %91
br label %93
93: ; preds = %88, %84
%94 = phi i32 [ %87, %84 ], [ %92, %88 ]
%95 = icmp sgt i32 %94, 80
br i1 %95, label %96, label %97
96: ; preds = %93, %76
store i32 1, i32* %16
br label %97
97: ; preds = %96, %93
br label %98
98: ; preds = %97, %58
br label %164
99: ; preds = %23
%100 = load i32, i32* %12
%101 = icmp eq i32 %100, 1
br i1 %101, label %102, label %163
102: ; preds = %99
%103 = load i32, i32* %16
%104 = icmp eq i32 %103, 0
br i1 %104, label %105, label %163
105: ; preds = %102
%106 = call i32 (...) @now()
%107 = load i32, i32* %15
%108 = sub nsw i32 %106, %107
%109 = icmp slt i32 %108, 250
br i1 %109, label %110, label %136
110: ; preds = %105
%111 = load i8*, i8** @EV_KEY
%112 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%113 = getelementptr inbounds %struct.input_event, %struct.input_event* %112, i32 0, i32 2
store i8* %111, i8** %113
%114 = load i32, i32* @BTN_LEFT
%115 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%116 = getelementptr inbounds %struct.input_event, %struct.input_event* %115, i32 0, i32 1
store i32 %114, i32* %116
%117 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%118 = getelementptr inbounds %struct.input_event, %struct.input_event* %117, i32 0, i32 0
store i32 1, i32* %118
%119 = load i32, i32* %6
%120 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%121 = call i64 (i32, ...) @write(i32 %119, %struct.input_event* %120, i64 16)
%122 = icmp slt i64 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %110
%124 = call i32 @crash(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %125
125: ; preds = %123, %110
%126 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%127 = getelementptr inbounds %struct.input_event, %struct.input_event* %126, i32 0, i32 0
store i32 0, i32* %127
%128 = load i32, i32* %6
%129 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%130 = call i64 (i32, ...) @write(i32 %128, %struct.input_event* %129, i64 16)
%131 = icmp slt i64 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %125
%133 = call i32 @crash(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %134
134: ; preds = %132, %125
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %162
136: ; preds = %105
%137 = load i8*, i8** @EV_KEY
%138 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%139 = getelementptr inbounds %struct.input_event, %struct.input_event* %138, i32 0, i32 2
store i8* %137, i8** %139
%140 = load i32, i32* @BTN_RIGHT
%141 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%142 = getelementptr inbounds %struct.input_event, %struct.input_event* %141, i32 0, i32 1
store i32 %140, i32* %142
%143 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%144 = getelementptr inbounds %struct.input_event, %struct.input_event* %143, i32 0, i32 0
store i32 1, i32* %144
%145 = load i32, i32* %6
%146 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%147 = call i64 (i32, ...) @write(i32 %145, %struct.input_event* %146, i64 16)
%148 = icmp slt i64 %147, 0
br i1 %148, label %149, label %151
149: ; preds = %136
%150 = call i32 @crash(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %151
151: ; preds = %149, %136
%152 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%153 = getelementptr inbounds %struct.input_event, %struct.input_event* %152, i32 0, i32 0
store i32 0, i32* %153
%154 = load i32, i32* %6
%155 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %8, i64 0, i64 0
%156 = call i64 (i32, ...) @write(i32 %154, %struct.input_event* %155, i64 16)
%157 = icmp slt i64 %156, 0
br i1 %157, label %158, label %160
158: ; preds = %151
%159 = call i32 @crash(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %160
160: ; preds = %158, %151
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %162
162: ; preds = %160, %134
br label %163
163: ; preds = %162, %102, %99
store i32 0, i32* %12
br label %164
164: ; preds = %163, %98
br label %19
165: ; preds = %19
%166 = load i32, i32* %6
%167 = load i32, i32* @UI_DEV_DESTROY
%168 = call i64 @ioctl(i32 %166, i32 %167)
%169 = icmp slt i64 %168, 0
br i1 %169, label %170, label %172
170: ; preds = %165
%171 = call i32 @crash(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %172
172: ; preds = %170, %165
%173 = load i32, i32* %6
%174 = call i32 @close(i32 %173)
ret i32 0
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i8* }
@.str = [12 x i8] c"%d %4d %4d\0A\00"
@EV_ABS = global i8* null
@ABS_X = global i32 0
@ABS_Y = global i32 0
@.str.1 = [12 x i8] c"event write\00"
@EV_KEY = global i8* null
@BTN_LEFT = global i32 0
@.str.2 = [24 x i8] c"event write: Left-click\00"
@BTN_RIGHT = global i32 0
@.str.4 = [25 x i8] c"event write: Right-click\00"
@UI_DEV_DESTROY = global i32 0
@.str.6 = [13 x i8] c"error: ioctl\00"
@str = [25 x i8] c"right-click: Right-click\00"
@str.7 = [11 x i8] c"left-click\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x %struct.input_event]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [2 x %struct.input_event]* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = tail call i32 (...) @init_hidraw()
%12 = tail call i32 (...) @init_uinput()
%13 = call i64 @get_raw_event(i32 %11, i32* %4, i32* %5, i32* %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %106, label %15
15: ; preds = %2
%16 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %3, i64 0, i64 0
%17 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %3, i64 0, i64 0, i32 2
%18 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %3, i64 0, i64 0, i32 1
%19 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %3, i64 0, i64 0, i32 0
%20 = bitcast [2 x %struct.input_event]* %3 to %struct.input_event**
%21 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %3, i64 0, i64 1, i32 2
%22 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %3, i64 0, i64 1, i32 1
%23 = getelementptr inbounds [2 x %struct.input_event], [2 x %struct.input_event]* %3, i64 0, i64 1, i32 0
br label %24
24: ; preds = %15, %98
%25 = phi i32 [ undef, %15 ], [ %103, %98 ]
%26 = phi i32 [ undef, %15 ], [ %102, %98 ]
%27 = phi i32 [ undef, %15 ], [ %101, %98 ]
%28 = phi i32 [ undef, %15 ], [ %100, %98 ]
%29 = phi i32 [ 0, %15 ], [ %99, %98 ]
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %63
36: ; preds = %24
%37 = call i32 @memset(%struct.input_event** %20, i32 0, i32 16)
%38 = load i8*, i8** @EV_ABS
store i8* %38, i8** %21
store i8* %38, i8** %17
%39 = load i32, i32* @ABS_X
store i32 %39, i32* %18
%40 = load i32, i32* @ABS_Y
store i32 %40, i32* %22
%41 = load i32, i32* %5
store i32 %41, i32* %19
%42 = load i32, i32* %6
store i32 %42, i32* %23
%43 = call i64 (i32, ...) @write(i32 %12, [2 x %struct.input_event]* %3, i64 32)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %36
%46 = call i32 @crash(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %36
%48 = icmp eq i32 %29, 0
%49 = load i32, i32* %5
br i1 %48, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* %6
%52 = call i32 (...) @now()
br label %98
53: ; preds = %47
%54 = sub nsw i32 %49, %28
%55 = call i32 @llvm.abs.i32(i32 %54, i1 true)
%56 = icmp ugt i32 %55, 80
br i1 %56, label %62, label %57
57: ; preds = %53
%58 = load i32, i32* %6
%59 = sub nsw i32 %58, %27
%60 = call i32 @llvm.abs.i32(i32 %59, i1 true)
%61 = icmp ugt i32 %60, 80
br i1 %61, label %62, label %98
62: ; preds = %57, %53
br label %98
63: ; preds = %24
%64 = icmp eq i32 %29, 1
%65 = icmp eq i32 %25, 0
%66 = select i1 %64, i1 %65, i1 false
br i1 %66, label %67, label %98
67: ; preds = %63
%68 = call i32 (...) @now()
%69 = sub nsw i32 %68, %26
%70 = icmp slt i32 %69, 250
%71 = load i8*, i8** @EV_KEY
store i8* %71, i8** %17
br i1 %70, label %72, label %85
72: ; preds = %67
%73 = load i32, i32* @BTN_LEFT
store i32 %73, i32* %18
store i32 1, i32* %19
%74 = call i64 (i32, ...) @write(i32 %12, %struct.input_event* %16, i64 16)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %72
%77 = call i32 @crash(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %78
78: ; preds = %76, %72
store i32 0, i32* %19
%79 = call i64 (i32, ...) @write(i32 %12, %struct.input_event* %16, i64 16)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %78
%82 = call i32 @crash(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %83
83: ; preds = %81, %78
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.7, i64 0, i64 0))
br label %98
85: ; preds = %67
%86 = load i32, i32* @BTN_RIGHT
store i32 %86, i32* %18
store i32 1, i32* %19
%87 = call i64 (i32, ...) @write(i32 %12, %struct.input_event* %16, i64 16)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %85
%90 = call i32 @crash(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %91
91: ; preds = %89, %85
store i32 0, i32* %19
%92 = call i64 (i32, ...) @write(i32 %12, %struct.input_event* %16, i64 16)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %91
%95 = call i32 @crash(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %96
96: ; preds = %94, %91
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %98
98: ; preds = %63, %96, %83, %50, %62, %57
%99 = phi i32 [ 1, %50 ], [ 1, %62 ], [ 1, %57 ], [ 0, %83 ], [ 0, %96 ], [ 0, %63 ]
%100 = phi i32 [ %49, %50 ], [ %28, %62 ], [ %28, %57 ], [ %28, %83 ], [ %28, %96 ], [ %28, %63 ]
%101 = phi i32 [ %51, %50 ], [ %27, %62 ], [ %27, %57 ], [ %27, %83 ], [ %27, %96 ], [ %27, %63 ]
%102 = phi i32 [ %52, %50 ], [ %26, %62 ], [ %26, %57 ], [ %26, %83 ], [ %26, %96 ], [ %26, %63 ]
%103 = phi i32 [ 0, %50 ], [ 1, %62 ], [ %25, %57 ], [ 0, %83 ], [ 0, %96 ], [ %25, %63 ]
%104 = call i64 @get_raw_event(i32 %11, i32* %4, i32* %5, i32* %6)
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %24
106: ; preds = %98, %2
%107 = load i32, i32* @UI_DEV_DESTROY
%108 = call i64 @ioctl(i32 %12, i32 %107)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %106
%111 = call i32 @crash(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %112
112: ; preds = %110, %106
%113 = call i32 @close(i32 %12)
ret i32 0
}