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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(int /*<<< orphan*/ *, int /*<<< orphan*/);
int write(int, struct input_event *, int);
int ev_emit(int fd, int type, int code, int value) {
  struct input_event ev = {.type = type, .code = code, .value = value};
  gettimeofday(&ev.time, 0);
  return write(fd, &ev, sizeof(ev));
}


x86 assembly (clang, -O0):
<ev_emit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
add    $0xc,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ev_emit>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,(%rsp)
mov    %edx,0x4(%rsp)
mov    %ecx,0x8(%rsp)
lea    0xc(%rsp),%rdi
movl   $0x0,0xc(%rsp)
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32, i32 }
define i32 @ev_emit(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.input_event
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = getelementptr inbounds %struct.input_event, %struct.input_event* %9, i32 0, i32 0
%11 = load i32, i32* %6
store i32 %11, i32* %10
%12 = getelementptr inbounds %struct.input_event, %struct.input_event* %9, i32 0, i32 1
%13 = load i32, i32* %7
store i32 %13, i32* %12
%14 = getelementptr inbounds %struct.input_event, %struct.input_event* %9, i32 0, i32 2
%15 = load i32, i32* %8
store i32 %15, i32* %14
%16 = getelementptr inbounds %struct.input_event, %struct.input_event* %9, i32 0, i32 3
store i32 0, i32* %16
%17 = getelementptr inbounds %struct.input_event, %struct.input_event* %9, i32 0, i32 3
%18 = call i32 @gettimeofday(i32* %17, i32 0)
%19 = load i32, i32* %5
%20 = call i32 @write(i32 %19, %struct.input_event* %9, i32 16)
ret i32 %20
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32, i32 }
define i32 @ev_emit(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.input_event
%6 = bitcast %struct.input_event* %5 to i8*
%7 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 0
store i32 %1, i32* %7
%8 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 1
store i32 %2, i32* %8
%9 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 2
store i32 %3, i32* %9
%10 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 3
store i32 0, i32* %10
%11 = call i32 @gettimeofday(i32* %10, i32 0)
%12 = call i32 @write(i32 %0, %struct.input_event* %5, i32 16)
ret i32 %12
}