#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uinp;
struct TYPE_2__ {
  int version;
  int /*<<< orphan*/ bustype;
};
struct uinput_user_dev {
  int value;
  int /*<<< orphan*/ code;
  void *type;
  int /*<<< orphan*/ time;
  TYPE_1__ id;
  int /*<<< orphan*/ name;
};
struct input_event {
  int value;
  int /*<<< orphan*/ code;
  void *type;
  int /*<<< orphan*/ time;
  TYPE_1__ id;
  int /*<<< orphan*/ name;
};
typedef int /*<<< orphan*/ event;

/* Variables and functions */
int /*<<< orphan*/ BTN_MOUSE;
int /*<<< orphan*/ BUS_USB;
int /*<<< orphan*/ EV_KEY;
void *EV_REL;
void *EV_SYN;
int O_NDELAY;
int O_WRONLY;
int /*<<< orphan*/ REL_X;
int /*<<< orphan*/ REL_Y;
int /*<<< orphan*/ SYN_REPORT;
int /*<<< orphan*/ UI_DEV_CREATE;
int /*<<< orphan*/ UI_DEV_DESTROY;
int /*<<< orphan*/ UI_SET_EVBIT;
int /*<<< orphan*/ UI_SET_KEYBIT;
int /*<<< orphan*/ UI_SET_RELBIT;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ gettimeofday(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int ioctl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ memset(struct uinput_user_dev *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ usleep(int);
int write(int, struct uinput_user_dev *, int);
int main(void) {
  struct uinput_user_dev uinp;
  struct input_event event;
  int ufile, retcode, i;
  ufile = open("/dev/uinput", O_WRONLY | O_NDELAY);
  if (ufile == -1) {
    printf("Could not open uinput: %s\n", strerror(errno));
    return -1;
  }
  memset(&uinp, 0, sizeof(uinp));
  strncpy(uinp.name, "simulated mouse", 20);
  uinp.id.version = 4;
  uinp.id.bustype = BUS_USB;
  ioctl(ufile, UI_SET_EVBIT, EV_KEY);
  ioctl(ufile, UI_SET_EVBIT, EV_REL);
  ioctl(ufile, UI_SET_RELBIT, REL_X);
  ioctl(ufile, UI_SET_RELBIT, REL_Y);
  for (i = 0; i < 256; i++) {
    ioctl(ufile, UI_SET_KEYBIT, i);
  }
  ioctl(ufile, UI_SET_KEYBIT, BTN_MOUSE);
  retcode = write(ufile, &uinp, sizeof(uinp));
  printf("First write returned %d.\n", retcode);
  retcode = ioctl(ufile, UI_DEV_CREATE);
  if (retcode == -1) {
    printf("Error create uinput device: %s\n", strerror(errno));
    return -1;
  }
  printf("test prepared\n");
  sleep(10);
  for (i = 0; i < 100; i++) {
    memset(&event, 0, sizeof(event));
    gettimeofday(&event.time, NULL);
    event.type = EV_REL;
    event.code = REL_X;
    event.value = -2;
    write(ufile, &event, sizeof(event));
    memset(&event, 0, sizeof(event));
    gettimeofday(&event.time, NULL);
    event.type = EV_REL;
    event.code = REL_Y;
    event.value = -2;
    write(ufile, &event, sizeof(event));
    memset(&event, 0, sizeof(event));
    gettimeofday(&event.time, NULL);
    event.type = EV_SYN;
    event.code = SYN_REPORT;
    event.value = 0;
    write(ufile, &event, sizeof(event));
    usleep(10000);
  }
  printf("test done\n");
  ioctl(ufile, UI_DEV_DESTROY);
  close(ufile);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    0x2da9(%rip),%rax
or     (%rax),%esi
lea    0xe28(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    1215 <main+0x65>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e4 <main+0x334>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    -0xc(%rbp),%edi
lea    0xdf8(%rip),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
movl   $0x4,-0x14(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4c(%rbp),%edi
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x4c(%rbp),%edi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
mov    0x2d3d(%rip),%rax
mov    (%rax),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x4c(%rbp),%edi
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
mov    0x2d00(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x4c(%rbp),%edi
mov    0x2d15(%rip),%rax
mov    (%rax),%esi
mov    0x2d44(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x100,-0x54(%rbp)
jge    12f5 <main+0x145>
mov    -0x4c(%rbp),%edi
mov    0x2cad(%rip),%rax
mov    (%rax),%esi
mov    -0x54(%rbp),%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    12c4 <main+0x114>
mov    -0x4c(%rbp),%edi
mov    0x2c89(%rip),%rax
mov    (%rax),%esi
mov    0x2c68(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x4c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x20,%edx
call   1040 <write@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%esi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4c(%rbp),%edi
mov    0x2cb0(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    1381 <main+0x1d1>
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xce3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e4 <main+0x334>
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   10c0 <sleep@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x64,-0x54(%rbp)
jge    14bb <main+0x30b>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    -0x48(%rbp),%rdi
add    $0x10,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    0x2be6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2bb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
movl   $0xfffffffe,-0x48(%rbp)
mov    -0x4c(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x20,%edx
call   1040 <write@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    -0x48(%rbp),%rdi
add    $0x10,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    0x2b93(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2bc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
movl   $0xfffffffe,-0x48(%rbp)
mov    -0x4c(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x20,%edx
call   1040 <write@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    -0x48(%rbp),%rdi
add    $0x10,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    0x2b68(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2b1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x4c(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x20,%edx
call   1040 <write@plt>
mov    $0x2710,%edi
call   10d0 <usleep@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    13a0 <main+0x1f0>
lea    0xbbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4c(%rbp),%edi
mov    0x2ad5(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x4c(%rbp),%edi
call   1090 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2d8b(%rip),%rax
mov    0x2d9c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe19(%rip),%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     143e <main+0x27e>
mov    %eax,%ebp
lea    0x28(%rsp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x44(%rsp),%edi
lea    0xe14(%rip),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
movl   $0x4,0x3c(%rsp)
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
mov    0x2d77(%rip),%rbx
mov    (%rbx),%esi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    (%rbx),%esi
mov    0x2d62(%rip),%r15
mov    (%r15),%rdx
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    0x2d57(%rip),%rbx
mov    (%rbx),%esi
mov    0x2d26(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    (%rbx),%esi
mov    0x2d72(%rip),%r13
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    0x2cee(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r14),%esi
mov    %ebp,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1090 <ioctl@plt>
add    $0x1,%ebx
cmp    $0x100,%ebx
jne    12a0 <main+0xe0>
mov    (%r14),%esi
mov    0x2cad(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
lea    0x28(%rsp),%rsi
mov    %ebp,%edi
mov    $0x20,%edx
call   1050 <write@plt>
lea    0xd51(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1455 <main+0x295>
lea    0xd60(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   10d0 <sleep@plt>
mov    $0x64,%r12d
lea    0x18(%rsp),%r14
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    0x2c40(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
movl   $0xfffffffe,0x8(%rsp)
ff
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    0x0(%r13),%eax
mov    %eax,0xc(%rsp)
movl   $0xfffffffe,0x8(%rsp)
ff
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
mov    0x2bbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <write@plt>
mov    $0x2710,%edi
call   10e0 <usleep@plt>
add    $0xffffffff,%r12d
jne    1330 <main+0x170>
lea    0xc63(%rip),%rdi
call   1040 <puts@plt>
mov    0x2b80(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
jmp    1479 <main+0x2b9>
mov    0x2b3b(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xbb9(%rip),%rdi
jmp    146a <main+0x2aa>
mov    0x2b24(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xbe7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.uinput_user_dev = type { i32, i32, i8*, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32 }
%struct.input_event = type { i32, i32, i8*, i32, %struct.TYPE_2__, i32 }
@.str = [12 x i8] c"/dev/uinput\00"
@O_WRONLY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [27 x i8] c"Could not open uinput: %s\0A\00"
@errno = global i32 0
@.str.2 = [16 x i8] c"simulated mouse\00"
@BUS_USB = global i32 0
@UI_SET_EVBIT = global i32 0
@EV_KEY = global i32 0
@EV_REL = global i8* null
@UI_SET_RELBIT = global i32 0
@REL_X = global i32 0
@REL_Y = global i32 0
@UI_SET_KEYBIT = global i32 0
@BTN_MOUSE = global i32 0
@.str.3 = [26 x i8] c"First write returned %d.\0A\00"
@UI_DEV_CREATE = global i32 0
@.str.4 = [32 x i8] c"Error create uinput device: %s\0A\00"
@.str.5 = [15 x i8] c"test prepared\0A\00"
@EV_SYN = global i8* null
@SYN_REPORT = global i32 0
@.str.6 = [11 x i8] c"test done\0A\00"
@UI_DEV_DESTROY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.uinput_user_dev
%3 = alloca %struct.input_event
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_NDELAY
%9 = or i32 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 -1, i32* %1
br label %126
17: ; preds = %0
%18 = call i32 @memset(%struct.uinput_user_dev* %2, i32 0, i32 32)
%19 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %2, i32 0, i32 5
%20 = load i32, i32* %19
%21 = call i32 @strncpy(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 20)
%22 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %2, i32 0, i32 4
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 4, i32* %23
%24 = load i32, i32* @BUS_USB
%25 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %2, i32 0, i32 4
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 1
store i32 %24, i32* %26
%27 = load i32, i32* %4
%28 = load i32, i32* @UI_SET_EVBIT
%29 = load i32, i32* @EV_KEY
%30 = call i32 (i32, i32, ...) @ioctl(i32 %27, i32 %28, i32 %29)
%31 = load i32, i32* %4
%32 = load i32, i32* @UI_SET_EVBIT
%33 = load i8*, i8** @EV_REL
%34 = call i32 (i32, i32, ...) @ioctl(i32 %31, i32 %32, i8* %33)
%35 = load i32, i32* %4
%36 = load i32, i32* @UI_SET_RELBIT
%37 = load i32, i32* @REL_X
%38 = call i32 (i32, i32, ...) @ioctl(i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* %4
%40 = load i32, i32* @UI_SET_RELBIT
%41 = load i32, i32* @REL_Y
%42 = call i32 (i32, i32, ...) @ioctl(i32 %39, i32 %40, i32 %41)
store i32 0, i32* %6
br label %43
43: ; preds = %51, %17
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 256
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i32, i32* %4
%48 = load i32, i32* @UI_SET_KEYBIT
%49 = load i32, i32* %6
%50 = call i32 (i32, i32, ...) @ioctl(i32 %47, i32 %48, i32 %49)
br label %51
51: ; preds = %46
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %43
54: ; preds = %43
%55 = load i32, i32* %4
%56 = load i32, i32* @UI_SET_KEYBIT
%57 = load i32, i32* @BTN_MOUSE
%58 = call i32 (i32, i32, ...) @ioctl(i32 %55, i32 %56, i32 %57)
%59 = load i32, i32* %4
%60 = call i32 @write(i32 %59, %struct.uinput_user_dev* %2, i32 32)
store i32 %60, i32* %5
%61 = load i32, i32* %5
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %4
%64 = load i32, i32* @UI_DEV_CREATE
%65 = call i32 (i32, i32, ...) @ioctl(i32 %63, i32 %64)
store i32 %65, i32* %5
%66 = load i32, i32* %5
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %72
68: ; preds = %54
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %70)
store i32 -1, i32* %1
br label %126
72: ; preds = %54
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%74 = call i32 @sleep(i32 10)
store i32 0, i32* %6
br label %75
75: ; preds = %116, %72
%76 = load i32, i32* %6
%77 = icmp slt i32 %76, 100
br i1 %77, label %78, label %119
78: ; preds = %75
%79 = bitcast %struct.input_event* %3 to %struct.uinput_user_dev*
%80 = call i32 @memset(%struct.uinput_user_dev* %79, i32 0, i32 32)
%81 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 3
%82 = call i32 @gettimeofday(i32* %81, i32* null)
%83 = load i8*, i8** @EV_REL
%84 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 2
store i8* %83, i8** %84
%85 = load i32, i32* @REL_X
%86 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 1
store i32 %85, i32* %86
%87 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 0
store i32 -2, i32* %87
%88 = load i32, i32* %4
%89 = bitcast %struct.input_event* %3 to %struct.uinput_user_dev*
%90 = call i32 @write(i32 %88, %struct.uinput_user_dev* %89, i32 32)
%91 = bitcast %struct.input_event* %3 to %struct.uinput_user_dev*
%92 = call i32 @memset(%struct.uinput_user_dev* %91, i32 0, i32 32)
%93 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 3
%94 = call i32 @gettimeofday(i32* %93, i32* null)
%95 = load i8*, i8** @EV_REL
%96 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 2
store i8* %95, i8** %96
%97 = load i32, i32* @REL_Y
%98 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 1
store i32 %97, i32* %98
%99 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 0
store i32 -2, i32* %99
%100 = load i32, i32* %4
%101 = bitcast %struct.input_event* %3 to %struct.uinput_user_dev*
%102 = call i32 @write(i32 %100, %struct.uinput_user_dev* %101, i32 32)
%103 = bitcast %struct.input_event* %3 to %struct.uinput_user_dev*
%104 = call i32 @memset(%struct.uinput_user_dev* %103, i32 0, i32 32)
%105 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 3
%106 = call i32 @gettimeofday(i32* %105, i32* null)
%107 = load i8*, i8** @EV_SYN
%108 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 2
store i8* %107, i8** %108
%109 = load i32, i32* @SYN_REPORT
%110 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 1
store i32 %109, i32* %110
%111 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 0
store i32 0, i32* %111
%112 = load i32, i32* %4
%113 = bitcast %struct.input_event* %3 to %struct.uinput_user_dev*
%114 = call i32 @write(i32 %112, %struct.uinput_user_dev* %113, i32 32)
%115 = call i32 @usleep(i32 10000)
br label %116
116: ; preds = %78
%117 = load i32, i32* %6
%118 = add nsw i32 %117, 1
store i32 %118, i32* %6
br label %75
119: ; preds = %75
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%121 = load i32, i32* %4
%122 = load i32, i32* @UI_DEV_DESTROY
%123 = call i32 (i32, i32, ...) @ioctl(i32 %121, i32 %122)
%124 = load i32, i32* %4
%125 = call i32 @close(i32 %124)
br label %126
126: ; preds = %119, %68, %13
%127 = load i32, i32* %1
ret i32 %127
}

LLVM IR (-O2):
%struct.uinput_user_dev = type { i32, i32, i8*, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32 }
%struct.input_event = type { i32, i32, i8*, i32, %struct.TYPE_2__, i32 }
@.str = [12 x i8] c"/dev/uinput\00"
@O_WRONLY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [27 x i8] c"Could not open uinput: %s\0A\00"
@errno = global i32 0
@.str.2 = [16 x i8] c"simulated mouse\00"
@BUS_USB = global i32 0
@UI_SET_EVBIT = global i32 0
@EV_KEY = global i32 0
@EV_REL = global i8* null
@UI_SET_RELBIT = global i32 0
@REL_X = global i32 0
@REL_Y = global i32 0
@UI_SET_KEYBIT = global i32 0
@BTN_MOUSE = global i32 0
@.str.3 = [26 x i8] c"First write returned %d.\0A\00"
@UI_DEV_CREATE = global i32 0
@.str.4 = [32 x i8] c"Error create uinput device: %s\0A\00"
@EV_SYN = global i8* null
@SYN_REPORT = global i32 0
@UI_DEV_DESTROY = global i32 0
@str = [14 x i8] c"test prepared\00"
@str.7 = [10 x i8] c"test done\00"
define i32 @main() {
%1 = alloca %struct.uinput_user_dev
%2 = alloca %struct.input_event
%3 = bitcast %struct.uinput_user_dev* %1 to i8*
%4 = bitcast %struct.input_event* %2 to i8*
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %86
14: ; preds = %0
%15 = call i32 @memset(%struct.uinput_user_dev* %1, i32 0, i32 32)
%16 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %1, i64 0, i32 5
%17 = load i32, i32* %16
%18 = call i32 @strncpy(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 20)
%19 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %1, i64 0, i32 4, i32 0
store i32 4, i32* %19
%20 = load i32, i32* @BUS_USB
%21 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %1, i64 0, i32 4, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @UI_SET_EVBIT
%23 = load i32, i32* @EV_KEY
%24 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %22, i32 %23)
%25 = load i32, i32* @UI_SET_EVBIT
%26 = load i8*, i8** @EV_REL
%27 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %25, i8* %26)
%28 = load i32, i32* @UI_SET_RELBIT
%29 = load i32, i32* @REL_X
%30 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %28, i32 %29)
%31 = load i32, i32* @UI_SET_RELBIT
%32 = load i32, i32* @REL_Y
%33 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %31, i32 %32)
br label %34
34: ; preds = %14, %34
%35 = phi i32 [ 0, %14 ], [ %38, %34 ]
%36 = load i32, i32* @UI_SET_KEYBIT
%37 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %36, i32 %35)
%38 = add nuw nsw i32 %35, 1
%39 = icmp eq i32 %38, 256
br i1 %39, label %40, label %34
40: ; preds = %34
%41 = load i32, i32* @UI_SET_KEYBIT
%42 = load i32, i32* @BTN_MOUSE
%43 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %41, i32 %42)
%44 = call i32 @write(i32 %8, %struct.uinput_user_dev* %1, i32 32)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = load i32, i32* @UI_DEV_CREATE
%47 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %40
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %86
53: ; preds = %40
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%55 = call i32 @sleep(i32 10)
%56 = bitcast %struct.input_event* %2 to %struct.uinput_user_dev*
%57 = getelementptr inbounds %struct.input_event, %struct.input_event* %2, i64 0, i32 3
%58 = getelementptr inbounds %struct.input_event, %struct.input_event* %2, i64 0, i32 2
%59 = getelementptr inbounds %struct.input_event, %struct.input_event* %2, i64 0, i32 1
%60 = getelementptr inbounds %struct.input_event, %struct.input_event* %2, i64 0, i32 0
br label %61
61: ; preds = %53, %61
%62 = phi i32 [ 0, %53 ], [ %79, %61 ]
%63 = call i32 @memset(%struct.uinput_user_dev* %56, i32 0, i32 32)
%64 = call i32 @gettimeofday(i32* %57, i32* null)
%65 = load i8*, i8** @EV_REL
store i8* %65, i8** %58
%66 = load i32, i32* @REL_X
store i32 %66, i32* %59
store i32 -2, i32* %60
%67 = call i32 @write(i32 %8, %struct.uinput_user_dev* %56, i32 32)
%68 = call i32 @memset(%struct.uinput_user_dev* %56, i32 0, i32 32)
%69 = call i32 @gettimeofday(i32* %57, i32* null)
%70 = load i8*, i8** @EV_REL
store i8* %70, i8** %58
%71 = load i32, i32* @REL_Y
store i32 %71, i32* %59
store i32 -2, i32* %60
%72 = call i32 @write(i32 %8, %struct.uinput_user_dev* %56, i32 32)
%73 = call i32 @memset(%struct.uinput_user_dev* %56, i32 0, i32 32)
%74 = call i32 @gettimeofday(i32* %57, i32* null)
%75 = load i8*, i8** @EV_SYN
store i8* %75, i8** %58
%76 = load i32, i32* @SYN_REPORT
store i32 %76, i32* %59
store i32 0, i32* %60
%77 = call i32 @write(i32 %8, %struct.uinput_user_dev* %56, i32 32)
%78 = call i32 @usleep(i32 10000)
%79 = add nuw nsw i32 %62, 1
%80 = icmp eq i32 %79, 100
br i1 %80, label %81, label %61
81: ; preds = %61
%82 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.7, i64 0, i64 0))
%83 = load i32, i32* @UI_DEV_DESTROY
%84 = call i32 (i32, i32, ...) @ioctl(i32 %8, i32 %83)
%85 = call i32 @close(i32 %8)
br label %86
86: ; preds = %81, %49, %10
%87 = phi i32 [ -1, %10 ], [ -1, %49 ], [ 0, %81 ]
ret i32 %87
}