#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*/ ie;

/* Variables and functions */
int get_kbdevie_output();
int /*<<< orphan*/ gettimeofday(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct input_event *, int /*<<< orphan*/, int);
scalar_t__ write(int, struct input_event *, int);
int send_event(int type, int code, int value) {
  struct input_event ie;
  memset(&ie, 0, sizeof(ie));
  gettimeofday(&ie.time, NULL);
  ie.type = type;
  ie.code = code;
  ie.value = value;
  int fdo = get_kbdevie_output();
  if (write(fdo, &ie, sizeof(ie)) < 0) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<send_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x20(%rbp),%rdi
add    $0xc,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <get_kbdevie_output@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b5 <send_event+0x75>
movl   $0x0,-0x4(%rbp)
jmp    11bc <send_event+0x7c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_event>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    0x14(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %ebx,0x8(%rsp)
mov    %ebp,0xc(%rsp)
mov    %r14d,0x10(%rsp)
xor    %eax,%eax
call   1060 <get_kbdevie_output@plt>
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1030 <write@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32, i32 }
define i32 @send_event(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.input_event
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = call i32 @memset(%struct.input_event* %8, i32 0, i32 16)
%11 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 3
%12 = call i32 @gettimeofday(i32* %11, i32* null)
%13 = load i32, i32* %5
%14 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* %6
%16 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* %7
%18 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 (...) @get_kbdevie_output()
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = call i64 @write(i32 %20, %struct.input_event* %8, i32 16)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %3
store i32 0, i32* %4
br label %25
24: ; preds = %3
store i32 1, i32* %4
br label %25
25: ; preds = %24, %23
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32, i32 }
define i32 @send_event(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 16)
%7 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 3
%8 = call i32 @gettimeofday(i32* %7, i32* null)
%9 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 0
store i32 %0, i32* %9
%10 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 1
store i32 %1, i32* %10
%11 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 2
store i32 %2, i32* %11
%12 = call i32 (...) @get_kbdevie_output()
%13 = call i64 @write(i32 %12, %struct.input_event* %4, i32 16)
%14 = lshr i64 %13, 63
%15 = trunc i64 %14 to i32
%16 = xor i32 %15, 1
ret i32 %16
}