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

/* Variables and functions */
int /*<<< orphan*/ EV_SYN;
int /*<<< orphan*/ SYN_REPORT;
int /*<<< orphan*/ gettimeofday(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ write(int, struct input_event *, int);
void syncInput(int fd) {
  struct input_event ev;
  memset((void *)&ev, 0, sizeof(struct input_event));
  gettimeofday(&ev.time, NULL);
  ev.type = EV_SYN;
  ev.code = SYN_REPORT;
  ev.value = 0;
  if (write(fd, &ev, sizeof(ev)) < 0) {
    printf("write err\n");
  }
}


x86 assembly (clang, -O0):
<syncInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rdi
add    $0x10,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b3 <syncInput+0x73>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<syncInput>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    11a9 <syncInput+0x69>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.input_event = type { i64, i32, i32, i32 }
@EV_SYN = global i32 0
@SYN_REPORT = global i32 0
@.str = [11 x i8] c"write err\0A\00"
define void @syncInput(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.input_event
store i32 %0, i32* %2
%4 = bitcast %struct.input_event* %3 to i8*
%5 = call i32 @memset(i8* %4, i32 0, i32 24)
%6 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 3
%7 = call i32 @gettimeofday(i32* %6, i32* null)
%8 = load i32, i32* @EV_SYN
%9 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @SYN_REPORT
%11 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i32 0, i32 0
store i64 0, i64* %12
%13 = load i32, i32* %2
%14 = call i64 @write(i32 %13, %struct.input_event* %3, i32 24)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
ret void
}

LLVM IR (-O2):
%struct.input_event = type { i64, i32, i32, i32 }
@EV_SYN = global i32 0
@SYN_REPORT = global i32 0
@str = [10 x i8] c"write err\00"
define void @syncInput(i32 %0) {
%2 = alloca %struct.input_event
%3 = bitcast %struct.input_event* %2 to i8*
%4 = call i32 @memset(i8* %3, i32 0, i32 24)
%5 = getelementptr inbounds %struct.input_event, %struct.input_event* %2, i64 0, i32 3
%6 = call i32 @gettimeofday(i32* %5, i32* null)
%7 = load i32, i32* @EV_SYN
%8 = getelementptr inbounds %struct.input_event, %struct.input_event* %2, i64 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* @SYN_REPORT
%10 = getelementptr inbounds %struct.input_event, %struct.input_event* %2, i64 0, i32 1
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.input_event, %struct.input_event* %2, i64 0, i32 0
store i64 0, i64* %11
%12 = call i64 @write(i32 %0, %struct.input_event* %2, i32 24)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
ret void
}