#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 /*<<< orphan*/ value;
  void *code;
  void *type;
};
typedef int /*<<< orphan*/ event;
typedef void *__u16;
typedef int /*<<< orphan*/ __s32;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(struct input_event *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int write(int, struct input_event *, int);
int send_event(int fd, __u16 type, __u16 code, __s32 value) {
  struct input_event event;
  memset(&event, 0, sizeof(event));
  event.type = type;
  event.code = code;
  event.value = value;
  if (write(fd, &event, sizeof(event)) != sizeof(event)) {
    fprintf(stderr, "Error on send_event\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cltq
cmp    $0x18,%rax
je     11aa <send_event+0x7a>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <send_event+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_event>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r12d
mov    %rsp,%r13
xor    %r15d,%r15d
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    %rbx,0x10(%rsp)
mov    %rbp,0x8(%rsp)
mov    %r14d,(%rsp)
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x18,%edx
call   1030 <write@plt>
cmp    $0x18,%eax
je     119d <send_event+0x6d>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.input_event = type { i32, i8*, i8* }
@stderr = global i32 0
@.str = [21 x i8] c"Error on send_event\0A\00"
define i32 @send_event(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.input_event
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = call i32 @memset(%struct.input_event* %10, i32 0, i32 24)
%12 = load i8*, i8** %7
%13 = getelementptr inbounds %struct.input_event, %struct.input_event* %10, i32 0, i32 2
store i8* %12, i8** %13
%14 = load i8*, i8** %8
%15 = getelementptr inbounds %struct.input_event, %struct.input_event* %10, i32 0, i32 1
store i8* %14, i8** %15
%16 = load i32, i32* %9
%17 = getelementptr inbounds %struct.input_event, %struct.input_event* %10, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %6
%19 = call i32 @write(i32 %18, %struct.input_event* %10, i32 24)
%20 = sext i32 %19 to i64
%21 = icmp ne i64 %20, 24
br i1 %21, label %22, label %25
22: ; preds = %4
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %26
25: ; preds = %4
store i32 0, i32* %5
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
%struct.input_event = type { i32, i8*, i8* }
@stderr = global i32 0
@.str = [21 x i8] c"Error on send_event\0A\00"
define i32 @send_event(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca %struct.input_event
%6 = bitcast %struct.input_event* %5 to i8*
%7 = call i32 @memset(%struct.input_event* %5, i32 0, i32 24)
%8 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 2
store i8* %1, i8** %8
%9 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 1
store i8* %2, i8** %9
%10 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 0
store i32 %3, i32* %10
%11 = call i32 @write(i32 %0, %struct.input_event* %5, i32 24)
%12 = icmp eq i32 %11, 24
br i1 %12, label %16, label %13
13: ; preds = %4
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %4, %13
%17 = phi i32 [ -1, %13 ], [ 0, %4 ]
ret i32 %17
}