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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int write(int, struct input_event *, int);
void send_event(int fd, int type, int code, int value) {
  struct input_event ev = {.type = type, .code = code, .value = value};
  if (write(fd, &ev, sizeof(ev)) != sizeof(ev)) {
    perror("writing input_event");
  }
}


x86 assembly (clang, -O0):
<send_event>:
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)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
cltq
cmp    $0xc,%rax
je     116f <send_event+0x4f>
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_event>:
sub    $0x18,%rsp
mov    %esi,0x8(%rsp)
mov    %edx,0xc(%rsp)
mov    %ecx,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
cmp    $0xc,%eax
jne    1149 <send_event+0x29>
add    $0x18,%rsp
ret
lea    0xeb0(%rip),%rdi
add    $0x18,%rsp
jmp    1040 <perror@plt>

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32 }
@.str = [20 x i8] c"writing input_event\00"
define void @send_event(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 = load i32, i32* %5
%17 = call i32 @write(i32 %16, %struct.input_event* %9, i32 12)
%18 = sext i32 %17 to i64
%19 = icmp ne i64 %18, 12
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %4
ret void
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32 }
@.str = [20 x i8] c"writing input_event\00"
define void @send_event(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 = call i32 @write(i32 %0, %struct.input_event* %5, i32 12)
%11 = icmp eq i32 %10, 12
br i1 %11, label %14, label %12
12: ; preds = %4
%13 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %4
ret void
}