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

/* Variables and functions */
int /*<<< orphan*/ ABS_PRESSURE;
int /*<<< orphan*/ BTN_TOUCH;
int /*<<< orphan*/ EV_ABS;
int /*<<< orphan*/ EV_KEY;
int /*<<< orphan*/ gettimeofday(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ syncInput(int);
scalar_t__ write(int, struct input_event *, int);
void setTapEvent(int fd, bool tap) {
  struct input_event ev;
  memset((void *)&ev, 0, sizeof(struct input_event));
  gettimeofday(&ev.time, NULL);
  ev.type = EV_KEY;
  ev.code = BTN_TOUCH;
  ev.value = tap == true ? 1 : 0;
  if (write(fd, &ev, sizeof(ev)) < 0) {
    printf("write err\n");
  }
  ev.type = EV_ABS;
  ev.code = ABS_PRESSURE;
  ev.value = tap == true ? 1024 : 0;
  if (write(fd, &ev, sizeof(ev)) < 0) {
    printf("write err\n");
  }
  syncInput(fd);
}


x86 assembly (clang, -O0):
<setTapEvent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x18(%rbp),%rdi
add    $0xc,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11d1 <setTapEvent+0x81>
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edx
xor    %eax,%eax
mov    $0x400,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1223 <setTapEvent+0xd3>
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1070 <syncInput@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setTapEvent>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
xor    %eax,%eax
cmp    $0x1,%ebp
sete   %al
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    11bf <setTapEvent+0x6f>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
cmp    $0x1,%ebp
sete   %al
mov    0x2df2(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2df5(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rsp)
shl    $0xa,%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    1207 <setTapEvent+0xb7>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <syncInput@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32, i32 }
@EV_KEY = global i32 0
@BTN_TOUCH = global i32 0
@.str = [11 x i8] c"write err\0A\00"
@EV_ABS = global i32 0
@ABS_PRESSURE = global i32 0
define void @setTapEvent(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.input_event
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = bitcast %struct.input_event* %5 to i8*
%7 = call i32 @memset(i8* %6, i32 0, i32 16)
%8 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 3
%9 = call i32 @gettimeofday(i32* %8, i32* null)
%10 = load i32, i32* @EV_KEY
%11 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @BTN_TOUCH
%13 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 1, i32 0
%18 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* %3
%20 = call i64 @write(i32 %19, %struct.input_event* %5, i32 16)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i32, i32* @EV_ABS
%26 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 2
store i32 %25, i32* %26
%27 = load i32, i32* @ABS_PRESSURE
%28 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 1
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 1024, i32 0
%33 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* %3
%35 = call i64 @write(i32 %34, %struct.input_event* %5, i32 16)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %24
%38 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %37, %24
%40 = load i32, i32* %3
%41 = call i32 @syncInput(i32 %40)
ret void
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32, i32 }
@EV_KEY = global i32 0
@BTN_TOUCH = global i32 0
@EV_ABS = global i32 0
@ABS_PRESSURE = global i32 0
@str.1 = [10 x i8] c"write err\00"
define void @setTapEvent(i32 %0, i32 %1) {
%3 = alloca %struct.input_event
%4 = bitcast %struct.input_event* %3 to i8*
%5 = call i32 @memset(i8* %4, i32 0, i32 16)
%6 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 3
%7 = call i32 @gettimeofday(i32* %6, i32* null)
%8 = load i32, i32* @EV_KEY
%9 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @BTN_TOUCH
%11 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = icmp eq i32 %1, 1
%13 = zext i1 %12 to i32
%14 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 0
store i32 %13, i32* %14
%15 = call i64 @write(i32 %0, %struct.input_event* %3, i32 16)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = load i32, i32* @EV_ABS
store i32 %20, i32* %9
%21 = load i32, i32* @ABS_PRESSURE
store i32 %21, i32* %11
%22 = select i1 %12, i32 1024, i32 0
store i32 %22, i32* %14
%23 = call i64 @write(i32 %0, %struct.input_event* %3, i32 16)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = call i32 @syncInput(i32 %0)
ret void
}