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

/* Variables and functions */
int /*<<< orphan*/ EV_KEY;
int /*<<< orphan*/ EV_SYN;
int /*<<< orphan*/ memset(struct input_event *, int /*<<< orphan*/, int);
scalar_t__ write(int, struct input_event *, int);
void send_key_down_event(int uinput_fd, int code) {
  struct input_event ev;
  memset(&ev, 0, sizeof(struct input_event));
  ev.type = EV_KEY;
  ev.code = code;
  ev.value = 1;
  if (write(uinput_fd, &ev, sizeof(struct input_event)) < 0)
    return;
  memset(&ev, 0, sizeof(struct input_event));
  ev.type = EV_SYN;
  if (write(uinput_fd, &ev, sizeof(struct input_event)) < 0)
    return;
}


x86 assembly (clang, -O0):
<send_key_down_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1177 <send_key_down_event+0x57>
jmp    11b3 <send_key_down_event+0x93>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b3 <send_key_down_event+0x93>
jmp    11b3 <send_key_down_event+0x93>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_key_down_event>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,(%rsp)
movl   $0x1,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1198 <send_key_down_event+0x78>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32 }
@EV_KEY = global i32 0
@EV_SYN = global i32 0
define void @send_key_down_event(i32 %0, i32 %1) {
%3 = alloca %struct.input_event
%4 = bitcast %struct.input_event* %3 to i8*
%5 = call i32 @memset(%struct.input_event* %3, i32 0, i32 12)
%6 = load i32, i32* @EV_KEY
%7 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 2
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 0
store i32 %1, i32* %8
%9 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 1
store i32 1, i32* %9
%10 = call i64 @write(i32 %0, %struct.input_event* %3, i32 12)
%11 = icmp slt i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = call i32 @memset(%struct.input_event* %3, i32 0, i32 12)
%14 = load i32, i32* @EV_SYN
store i32 %14, i32* %7
%15 = call i64 @write(i32 %0, %struct.input_event* %3, i32 12)
br label %16
16: ; preds = %12, %2
ret void
}