#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 KEY_DC;
int KEY_IC;
int /*<<< orphan*/ *keyname(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strcmp(int /*<<< orphan*/ *, char *);
scalar_t__ strncmp(int /*<<< orphan*/ *, char *, int);
char *display_keyname(int i) {
  static char buffer[4];
  if (i == '\t')
    return "TAB";
  if (i == '\n')
    return "ENTER";
  if (i == 27)
    return "ESCAPE";
  if (i == 32)
    return "SPACE";
  if (i == KEY_DC)
    return "DELETE";
  if (i == KEY_IC)
    return "INSERT";
  if (keyname(i) == NULL)
    return "UNKNOWN";
  if (strcmp(keyname(i), "NO KEY NAME") == 0) {
    if (i >= 0 && i < 32) {
      sprintf(buffer, "^%c", i + '@');
      return buffer;
    }
    if (i > 32 && i < 127) {
      sprintf(buffer, "%c", i);
      return buffer;
    }
    return "UNKNOWN";
  }
  if (strncmp(keyname(i), "KEY_", 4) == 0)
    return (char *)(keyname(i) + 4);
  return (char *)keyname(i);
}


x86 assembly (clang, -O0):
<display_keyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jne    1165 <display_keyname+0x25>
lea    0xea4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
cmpl   $0xa,-0xc(%rbp)
jne    117f <display_keyname+0x3f>
lea    0xe8e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
cmpl   $0x1b,-0xc(%rbp)
jne    1199 <display_keyname+0x59>
lea    0xe7a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
cmpl   $0x20,-0xc(%rbp)
jne    11b3 <display_keyname+0x73>
lea    0xe67(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
mov    -0xc(%rbp),%eax
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%eax
jne    11d5 <display_keyname+0x95>
lea    0xe4b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
mov    -0xc(%rbp),%eax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%eax
jne    11f7 <display_keyname+0xb7>
lea    0xe30(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
mov    -0xc(%rbp),%edi
call   1050 <keyname@plt>
cmp    $0x0,%rax
jne    1219 <display_keyname+0xd9>
lea    0xe15(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
mov    -0xc(%rbp),%edi
call   1050 <keyname@plt>
mov    %rax,%rdi
lea    0xe02(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12c1 <display_keyname+0x181>
cmpl   $0x0,-0xc(%rbp)
jl     1277 <display_keyname+0x137>
cmpl   $0x20,-0xc(%rbp)
jge    1277 <display_keyname+0x137>
mov    -0xc(%rbp),%edx
add    $0x40,%edx
lea    0x2de9(%rip),%rdi
lea    0xdd7(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2dd6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
cmpl   $0x20,-0xc(%rbp)
jle    12b1 <display_keyname+0x171>
cmpl   $0x7f,-0xc(%rbp)
jge    12b1 <display_keyname+0x171>
mov    -0xc(%rbp),%edx
lea    0x2daf(%rip),%rdi
lea    0xd9e(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2d9c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
lea    0xd6d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
mov    -0xc(%rbp),%edi
call   1050 <keyname@plt>
mov    %rax,%rdi
lea    0xd6a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12fc <display_keyname+0x1bc>
mov    -0xc(%rbp),%edi
call   1050 <keyname@plt>
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
jmp    1308 <display_keyname+0x1c8>
mov    -0xc(%rbp),%edi
call   1050 <keyname@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_keyname>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    -0x9(%r14),%eax
cmp    $0x17,%eax
ja     1171 <display_keyname+0x31>
lea    0xf08(%rip),%rbx
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xef5(%rip),%rbx
jmp    1196 <display_keyname+0x56>
mov    0x2e70(%rip),%rax
cmp    %r14d,(%rax)
jne    119f <display_keyname+0x5f>
lea    0xef3(%rip),%rbx
jmp    1196 <display_keyname+0x56>
lea    0xedd(%rip),%rbx
jmp    1196 <display_keyname+0x56>
lea    0xedb(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e3a(%rip),%rax
cmp    %r14d,(%rax)
jne    11b4 <display_keyname+0x74>
lea    0xecc(%rip),%rbx
jmp    1196 <display_keyname+0x56>
mov    %r14d,%edi
call   1050 <keyname@plt>
lea    0xec2(%rip),%rbx
test   %rax,%rax
je     1196 <display_keyname+0x56>
mov    %r14d,%edi
call   1050 <keyname@plt>
lea    0xeb6(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     121c <display_keyname+0xdc>
mov    %r14d,%edi
call   1050 <keyname@plt>
lea    0xeaa(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%r15
mov    %r14d,%edi
call   1050 <keyname@plt>
mov    %rax,%rbx
test   %r15,%r15
jne    1196 <display_keyname+0x56>
add    $0x10,%rbx
jmp    1196 <display_keyname+0x56>
cmp    $0x1f,%r14d
ja     1244 <display_keyname+0x104>
add    $0x40,%r14d
lea    0x2e17(%rip),%rbx
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1060 <sprintf@plt>
jmp    1196 <display_keyname+0x56>
lea    -0x21(%r14),%eax
cmp    $0x5d,%eax
ja     1196 <display_keyname+0x56>
mov    %r14b,0x2dec(%rip)
lea    0x2de5(%rip),%rbx
movb   $0x0,0x2ddf(%rip)
jmp    1196 <display_keyname+0x56>

LLVM IR (-O0):
@display_keyname.buffer = internal global [4 x i8] zeroinitializer
@.str = [4 x i8] c"TAB\00"
@.str.1 = [6 x i8] c"ENTER\00"
@.str.2 = [7 x i8] c"ESCAPE\00"
@.str.3 = [6 x i8] c"SPACE\00"
@KEY_DC = global i32 0
@.str.4 = [7 x i8] c"DELETE\00"
@KEY_IC = global i32 0
@.str.5 = [7 x i8] c"INSERT\00"
@.str.6 = [8 x i8] c"UNKNOWN\00"
@.str.7 = [12 x i8] c"NO KEY NAME\00"
@.str.8 = [4 x i8] c"^%c\00"
@.str.9 = [3 x i8] c"%c\00"
@.str.10 = [5 x i8] c"KEY_\00"
define i8* @display_keyname(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 9
br i1 %5, label %6, label %7
6: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2
br label %73
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 10
br i1 %9, label %10, label %11
10: ; preds = %7
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %73
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 27
br i1 %13, label %14, label %15
14: ; preds = %11
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %73
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 32
br i1 %17, label %18, label %19
18: ; preds = %15
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %73
19: ; preds = %15
%20 = load i32, i32* %3
%21 = load i32, i32* @KEY_DC
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %73
24: ; preds = %19
%25 = load i32, i32* %3
%26 = load i32, i32* @KEY_IC
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %73
29: ; preds = %24
%30 = load i32, i32* %3
%31 = call i32* @keyname(i32 %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %34
33: ; preds = %29
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %73
34: ; preds = %29
%35 = load i32, i32* %3
%36 = call i32* @keyname(i32 %35)
%37 = call i64 @strcmp(i32* %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %59
39: ; preds = %34
%40 = load i32, i32* %3
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = load i32, i32* %3
%44 = icmp slt i32 %43, 32
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 64
%48 = call i32 @sprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %47)
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 0), i8** %2
br label %73
49: ; preds = %42, %39
%50 = load i32, i32* %3
%51 = icmp sgt i32 %50, 32
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i32, i32* %3
%54 = icmp slt i32 %53, 127
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %3
%57 = call i32 @sprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %56)
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 0), i8** %2
br label %73
58: ; preds = %52, %49
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %73
59: ; preds = %34
%60 = load i32, i32* %3
%61 = call i32* @keyname(i32 %60)
%62 = call i64 @strncmp(i32* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %69
64: ; preds = %59
%65 = load i32, i32* %3
%66 = call i32* @keyname(i32 %65)
%67 = getelementptr inbounds i32, i32* %66, i64 4
%68 = bitcast i32* %67 to i8*
store i8* %68, i8** %2
br label %73
69: ; preds = %59
%70 = load i32, i32* %3
%71 = call i32* @keyname(i32 %70)
%72 = bitcast i32* %71 to i8*
store i8* %72, i8** %2
br label %73
73: ; preds = %69, %64, %58, %55, %45, %33, %28, %23, %18, %14, %10, %6
%74 = load i8*, i8** %2
ret i8* %74
}

LLVM IR (-O2):
@display_keyname.buffer = internal global [4 x i8] zeroinitializer
@.str = [4 x i8] c"TAB\00"
@.str.1 = [6 x i8] c"ENTER\00"
@.str.2 = [7 x i8] c"ESCAPE\00"
@.str.3 = [6 x i8] c"SPACE\00"
@KEY_DC = global i32 0
@.str.4 = [7 x i8] c"DELETE\00"
@KEY_IC = global i32 0
@.str.5 = [7 x i8] c"INSERT\00"
@.str.6 = [8 x i8] c"UNKNOWN\00"
@.str.7 = [12 x i8] c"NO KEY NAME\00"
@.str.8 = [4 x i8] c"^%c\00"
@.str.10 = [5 x i8] c"KEY_\00"
define i8* @display_keyname(i32 %0) {
switch i32 %0, label %5 [
i32 9, label %38
i32 10, label %2
i32 27, label %3
i32 32, label %4
]
2: ; preds = %1
br label %38
3: ; preds = %1
br label %38
4: ; preds = %1
br label %38
5: ; preds = %1
%6 = load i32, i32* @KEY_DC
%7 = icmp eq i32 %6, %0
br i1 %7, label %38, label %8
8: ; preds = %5
%9 = load i32, i32* @KEY_IC
%10 = icmp eq i32 %9, %0
br i1 %10, label %38, label %11
11: ; preds = %8
%12 = tail call i32* @keyname(i32 %0)
%13 = icmp eq i32* %12, null
br i1 %13, label %38, label %14
14: ; preds = %11
%15 = tail call i32* @keyname(i32 %0)
%16 = tail call i64 @strcmp(i32* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = icmp ult i32 %0, 32
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = add nuw nsw i32 %0, 64
%22 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %21)
br label %38
23: ; preds = %18
%24 = add i32 %0, -33
%25 = icmp ult i32 %24, 94
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = trunc i32 %0 to i8
store i8 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 1)
br label %38
28: ; preds = %14
%29 = tail call i32* @keyname(i32 %0)
%30 = tail call i64 @strncmp(i32* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4)
%31 = icmp eq i64 %30, 0
%32 = tail call i32* @keyname(i32 %0)
br i1 %31, label %33, label %36
33: ; preds = %28
%34 = getelementptr inbounds i32, i32* %32, i64 4
%35 = bitcast i32* %34 to i8*
br label %38
36: ; preds = %28
%37 = bitcast i32* %32 to i8*
br label %38
38: ; preds = %23, %11, %8, %5, %1, %36, %33, %26, %20, %4, %3, %2
%39 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 0), %20 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @display_keyname.buffer, i64 0, i64 0), %26 ], [ %35, %33 ], [ %37, %36 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %8 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %11 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %23 ]
ret i8* %39
}