#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;
  scalar_t__ code;
  void *type;
};

/* Variables and functions */
void *EV_REL;
void *EV_SYN;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ REL_X;
scalar_t__ REL_Y;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct input_event *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ usleep(int);
scalar_t__ write(int, struct input_event *, int);
int move_mouse(int fd, int dx, int dy) {
  struct input_event ev;
  memset(&ev, 0, sizeof(struct input_event));
  ev.type = EV_REL;
  ev.code = REL_X;
  ev.value = dx;
  if (write(fd, &ev, sizeof(struct input_event)) < 0)
    do {
      perror("error: write");
      exit(EXIT_FAILURE);
    } while (0);
  memset(&ev, 0, sizeof(struct input_event));
  ev.type = EV_REL;
  ev.code = REL_Y;
  ev.value = dy;
  if (write(fd, &ev, sizeof(struct input_event)) < 0)
    do {
      perror("error: write");
      exit(EXIT_FAILURE);
    } while (0);
  memset(&ev, 0, sizeof(struct input_event));
  ev.type = EV_SYN;
  ev.code = 0;
  ev.value = 0;
  if (write(fd, &ev, sizeof(struct input_event)) < 0)
    do {
      perror("error: write");
      exit(EXIT_FAILURE);
    } while (0);
  usleep(15000);
  return 0;
}


x86 assembly (clang, -O0):
<move_mouse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11cd <move_mouse+0x7d>
jmp    11b3 <move_mouse+0x63>
lea    0xe46(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1239 <move_mouse+0xe9>
jmp    121f <move_mouse+0xcf>
lea    0xdda(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12a0 <move_mouse+0x150>
jmp    1286 <move_mouse+0x136>
lea    0xd73(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0x3a98,%edi
call   1070 <usleep@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<move_mouse>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e5a(%rip),%r12
mov    (%r12),%rax
mov    %rax,0x18(%rsp)
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
mov    %ebp,0x8(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x18,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1258 <move_mouse+0x108>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x18(%rsp)
mov    0x2e22(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
mov    %r14d,0x8(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1258 <move_mouse+0x108>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1258 <move_mouse+0x108>
mov    $0x3a98,%edi
call   1070 <usleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda1(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i32, i64, i8* }
@EV_REL = global i8* null
@REL_X = global i64 0
@.str = [13 x i8] c"error: write\00"
@EXIT_FAILURE = global i32 0
@REL_Y = global i64 0
@EV_SYN = global i8* null
define i32 @move_mouse(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.input_event
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = call i32 @memset(%struct.input_event* %7, i32 0, i32 24)
%9 = load i8*, i8** @EV_REL
%10 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
store i8* %9, i8** %10
%11 = load i64, i64* @REL_X
%12 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
store i64 %11, i64* %12
%13 = load i32, i32* %5
%14 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* %4
%16 = call i64 @write(i32 %15, %struct.input_event* %7, i32 24)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %3
br label %19
19: ; preds = %18
%20 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %3
%25 = call i32 @memset(%struct.input_event* %7, i32 0, i32 24)
%26 = load i8*, i8** @EV_REL
%27 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
store i8* %26, i8** %27
%28 = load i64, i64* @REL_Y
%29 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
store i64 %28, i64* %29
%30 = load i32, i32* %6
%31 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* %4
%33 = call i64 @write(i32 %32, %struct.input_event* %7, i32 24)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %24
br label %36
36: ; preds = %35
%37 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; No predecessors!
br label %41
41: ; preds = %40, %24
%42 = call i32 @memset(%struct.input_event* %7, i32 0, i32 24)
%43 = load i8*, i8** @EV_SYN
%44 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
store i8* %43, i8** %44
%45 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
store i64 0, i64* %45
%46 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
store i32 0, i32* %46
%47 = load i32, i32* %4
%48 = call i64 @write(i32 %47, %struct.input_event* %7, i32 24)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %41
br label %51
51: ; preds = %50
%52 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; No predecessors!
br label %56
56: ; preds = %55, %41
%57 = call i32 @usleep(i32 15000)
ret i32 0
}

LLVM IR (-O2):
%struct.input_event = type { i32, i64, i8* }
@EV_REL = global i8* null
@REL_X = global i64 0
@.str = [13 x i8] c"error: write\00"
@EXIT_FAILURE = global i32 0
@REL_Y = global i64 0
@EV_SYN = global i8* null
define i32 @move_mouse(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.input_event
%5 = bitcast %struct.input_event* %4 to i8*
%6 = call i32 @memset(%struct.input_event* %4, i32 0, i32 24)
%7 = load i8*, i8** @EV_REL
%8 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 2
store i8* %7, i8** %8
%9 = load i64, i64* @REL_X
%10 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 1
store i64 %9, i64* %10
%11 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 0
store i32 %1, i32* %11
%12 = call i64 @write(i32 %0, %struct.input_event* %4, i32 24)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %3
%19 = call i32 @memset(%struct.input_event* %4, i32 0, i32 24)
%20 = load i8*, i8** @EV_REL
store i8* %20, i8** %8
%21 = load i64, i64* @REL_Y
store i64 %21, i64* %10
store i32 %2, i32* %11
%22 = call i64 @write(i32 %0, %struct.input_event* %4, i32 24)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %18
%29 = call i32 @memset(%struct.input_event* %4, i32 0, i32 24)
%30 = load i8*, i8** @EV_SYN
store i8* %30, i8** %8
store i64 0, i64* %10
store i32 0, i32* %11
%31 = call i64 @write(i32 %0, %struct.input_event* %4, i32 24)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28
%38 = call i32 @usleep(i32 15000)
ret i32 0
}