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

/* Variables and functions */
int const KEY_ENTER;
scalar_t__ ev_key_click(int, int const);
int printable_to_key(char const);
int /*<<< orphan*/ usleep(int);
int ev_inject_keypress(int fd, const char c) {
  const int key = printable_to_key(c);
  if (ev_key_click(fd, key) < 0)
    return -1;
  if (key == KEY_ENTER)
    usleep(500000);
  return 0;
}


x86 assembly (clang, -O0):
<ev_inject_keypress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1040 <printable_to_key@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <ev_key_click@plt>
cmp    $0x0,%rax
jge    116e <ev_inject_keypress+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <ev_inject_keypress+0x61>
mov    -0x10(%rbp),%eax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
jne    118a <ev_inject_keypress+0x5a>
mov    $0x7a120,%edi
call   1050 <usleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ev_inject_keypress>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %esi,%edi
call   1040 <printable_to_key@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <ev_key_click@plt>
test   %rax,%rax
js     115e <ev_inject_keypress+0x2e>
xor    %ebx,%ebx
test   %ebp,%ebp
jne    1163 <ev_inject_keypress+0x33>
mov    $0x7a120,%edi
call   1050 <usleep@plt>
jmp    1163 <ev_inject_keypress+0x33>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@KEY_ENTER = constant i32 0
define i32 @ev_inject_keypress(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %4
store i8 %1, i8* %5
%7 = load i8, i8* %5
%8 = call i32 @printable_to_key(i8 signext %7)
store i32 %8, i32* %6
%9 = load i32, i32* %4
%10 = load i32, i32* %6
%11 = call i64 @ev_key_click(i32 %9, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %21
14: ; preds = %2
%15 = load i32, i32* %6
%16 = load i32, i32* @KEY_ENTER
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @usleep(i32 500000)
br label %20
20: ; preds = %18, %14
store i32 0, i32* %3
br label %21
21: ; preds = %20, %13
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@KEY_ENTER = constant i32 0
define i32 @ev_inject_keypress(i32 %0, i8 signext %1) {
%3 = tail call i32 @printable_to_key(i8 signext %1)
%4 = tail call i64 @ev_key_click(i32 %0, i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp eq i32 %3, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @usleep(i32 500000)
br label %10
10: ; preds = %6, %8, %2
%11 = phi i32 [ -1, %2 ], [ 0, %8 ], [ 0, %6 ]
ret i32 %11
}