#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*/ error(char *);
scalar_t__ write(int, struct input_event *, int);
void send_event(int device, int type, int code, int value) {
  struct input_event ev;
  ev.type = type;
  ev.code = code;
  ev.value = value;
  if (write(device, &ev, sizeof(ev)) < 0)
    error("error: write()");
}


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>
cmp    $0x0,%rax
jge    116d <send_event+0x4d>
lea    0xe98(%rip),%rdi
call   1040 <error@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>
test   %rax,%rax
js     1149 <send_event+0x29>
add    $0x18,%rsp
ret
lea    0xeb0(%rip),%rdi
add    $0x18,%rsp
jmp    1040 <error@plt>

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32 }
@.str = [15 x i8] c"error: write()\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 = load i32, i32* %6
%11 = getelementptr inbounds %struct.input_event, %struct.input_event* %9, i32 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* %7
%13 = getelementptr inbounds %struct.input_event, %struct.input_event* %9, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* %8
%15 = getelementptr inbounds %struct.input_event, %struct.input_event* %9, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* %5
%17 = call i64 @write(i32 %16, %struct.input_event* %9, i32 12)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %4
ret void
}

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