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

/* Variables and functions */
void *BTN_LEFT;
void *EV_KEY;
void *EV_SYN;
int /*<<< orphan*/ EXIT_FAILURE;
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 click(int fd) {
  struct input_event ev;
  memset(&ev, 0, sizeof(struct input_event));
  ev.type = EV_KEY;
  ev.code = BTN_LEFT;
  ev.value = 1;
  if (write(fd, &ev, sizeof(struct input_event)) < 0)
    do {
      perror("error: write");
      exit(EXIT_FAILURE);
    } while (0);
  usleep(500000);
  memset(&ev, 0, sizeof(struct input_event));
  ev.type = EV_KEY;
  ev.code = BTN_LEFT;
  ev.value = 0;
  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):
<click>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11c8 <click+0x78>
jmp    11ae <click+0x5e>
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0x7a120,%edi
call   1070 <usleep@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    123f <click+0xef>
jmp    1225 <click+0xd5>
lea    0xdd4(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12a6 <click+0x156>
jmp    128c <click+0x13c>
lea    0xd6d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0x3a98,%edi
call   1070 <usleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<click>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e62(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    0x2e5b(%rip),%r12
mov    (%r12),%rax
mov    %rax,0x8(%rsp)
movl   $0x1,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1252 <click+0x102>
mov    $0x7a120,%edi
call   1070 <usleep@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    (%r12),%rax
mov    %rax,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1252 <click+0x102>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1252 <click+0x102>
mov    $0x3a98,%edi
call   1070 <usleep@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xda7(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

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