#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 strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void keydown(int xte_fd, char *key, int *state) {
  if (!*state) {
    write(xte_fd, "keydown ", 8);
    write(xte_fd, key, strlen(key));
    write(xte_fd, "\n", 1);
    *state = 1;
  }
}


x86 assembly (clang, -O0):
<keydown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1197 <keydown+0x77>
mov    -0x4(%rbp),%edi
lea    0xeb6(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    0xe86(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keydown>:
push   %rbp
push   %r14
push   %rbx
cmpl   $0x0,(%rdx)
jne    116f <keydown+0x4f>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xec8(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xeac(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
movl   $0x1,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"keydown \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @keydown(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%7 = load i32*, i32** %6
%8 = load i32, i32* %7
%9 = icmp ne i32 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %3
%11 = load i32, i32* %4
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%13 = load i32, i32* %4
%14 = load i8*, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @write(i32 %13, i8* %14, i32 %16)
%18 = load i32, i32* %4
%19 = call i32 @write(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%20 = load i32*, i32** %6
store i32 1, i32* %20
br label %21
21: ; preds = %10, %3
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"keydown \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @keydown(i32 %0, i8* %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i32 @write(i32 %0, i8* %1, i32 %8)
%10 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 1, i32* %2
br label %11
11: ; preds = %6, %3
ret void
}