#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 */
#define KEY_BACKSPACE 140
#define KEY_DC 139
#define KEY_DOWN 138
#define KEY_END 137
#define KEY_ENTER 136
#define KEY_HELP 135
#define KEY_HOME 134
#define KEY_IC 133
#define KEY_LEFT 132
#define KEY_NPAGE 131
#define KEY_PPAGE 130
#define KEY_RIGHT 129
#define KEY_UP 128
int /*<<< orphan*/ sprintf(char *, char *, char);
char *key_to_name(int key) {
  static char kbuf[32];
  if (key >= 32 && key < 256) {
    if (key == 127) {
      return "delete";
    }
    kbuf[0] = key;
    kbuf[1] = '\0';
    return kbuf;
  }
  switch (key) {
  case '\t':
    return "tab";
  case '\033':
    return "escape";
  case KEY_DOWN:
    return "down-arrow";
  case KEY_UP:
    return "up-arrow";
  case KEY_LEFT:
    return "left-arrow";
  case KEY_RIGHT:
    return "right-arrow";
  case KEY_HOME:
    return "home";
  case KEY_BACKSPACE:
    return "backspace";
  case KEY_DC:
    return "delete-char";
  case KEY_IC:
    return "insert-char";
  case KEY_NPAGE:
    return "page-down";
  case KEY_PPAGE:
    return "page-up";
  case KEY_ENTER:
    return "enter";
  case KEY_END:
    return "end";
  case KEY_HELP:
    return "help";
  }
  if (key >= 0 && key < 32) {
    sprintf(kbuf, "ctrl-%c", '@' + key);
    return kbuf;
  }
  return "unknown-key";
}


x86 assembly (clang, -O0):
<key_to_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jl     116c <key_to_name+0x5c>
cmpl   $0x100,-0xc(%rbp)
jge    116c <key_to_name+0x5c>
cmpl   $0x7f,-0xc(%rbp)
jne    114c <key_to_name+0x3c>
lea    0x10cd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
mov    -0xc(%rbp),%eax
mov    %al,0x2eeb(%rip)
movb   $0x0,0x2ee5(%rip)
lea    0x2edd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
mov    -0xc(%rbp),%eax
add    $0xfffffff7,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x83,%eax
ja     1287 <key_to_name+0x177>
mov    -0x18(%rbp),%rax
lea    0xe72(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0x1079(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x106d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x1064(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x105f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x1058(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x1053(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x104f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x1044(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x103e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x103a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x1036(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x1030(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x1028(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x101e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0x1012(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
cmpl   $0x0,-0xc(%rbp)
jl     12c7 <key_to_name+0x1b7>
cmpl   $0x20,-0xc(%rbp)
jge    12c7 <key_to_name+0x1b7>
mov    -0xc(%rbp),%eax
add    $0x40,%eax
lea    0x2d98(%rip),%rdi
lea    0xfe6(%rip),%rsi
movsbl %al,%edx
call   1030 <sprintf@plt>
lea    0x2d82(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <key_to_name+0x1c2>
lea    0xfcf(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<key_to_name>:
push   %rbx
lea    -0x20(%rdi),%eax
cmp    $0xdf,%eax
ja     1129 <key_to_name+0x19>
cmp    $0x7f,%edi
jne    113c <key_to_name+0x2c>
lea    0xed9(%rip),%rbx
jmp    1188 <key_to_name+0x78>
cmp    $0x9,%edi
je     1153 <key_to_name+0x43>
cmp    $0x1b,%edi
jne    115c <key_to_name+0x4c>
lea    0xed1(%rip),%rbx
jmp    1188 <key_to_name+0x78>
mov    %dil,0x2efd(%rip)
lea    0x2ef6(%rip),%rbx
movb   $0x0,0x2ef0(%rip)
jmp    1188 <key_to_name+0x78>
lea    0xead(%rip),%rbx
jmp    1188 <key_to_name+0x78>
cmp    $0x1f,%edi
ja     1181 <key_to_name+0x71>
add    $0x40,%dil
movsbl %dil,%edx
lea    0x2ed0(%rip),%rbx
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
jmp    1188 <key_to_name+0x78>
lea    0xe92(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@key_to_name.kbuf = internal global [32 x i8] zeroinitializer
@.str = [7 x i8] c"delete\00"
@.str.1 = [4 x i8] c"tab\00"
@.str.2 = [7 x i8] c"escape\00"
@.str.3 = [11 x i8] c"down-arrow\00"
@.str.4 = [9 x i8] c"up-arrow\00"
@.str.5 = [11 x i8] c"left-arrow\00"
@.str.6 = [12 x i8] c"right-arrow\00"
@.str.7 = [5 x i8] c"home\00"
@.str.8 = [10 x i8] c"backspace\00"
@.str.9 = [12 x i8] c"delete-char\00"
@.str.10 = [12 x i8] c"insert-char\00"
@.str.11 = [10 x i8] c"page-down\00"
@.str.12 = [8 x i8] c"page-up\00"
@.str.13 = [6 x i8] c"enter\00"
@.str.14 = [4 x i8] c"end\00"
@.str.15 = [5 x i8] c"help\00"
@.str.16 = [8 x i8] c"ctrl-%c\00"
@.str.17 = [12 x i8] c"unknown-key\00"
define i8* @key_to_name(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 32
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 256
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 127
br i1 %11, label %12, label %13
12: ; preds = %9
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
br label %45
13: ; preds = %9
%14 = load i32, i32* %3
%15 = trunc i32 %14 to i8
store i8 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 1)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 0), i8** %2
br label %45
16: ; preds = %6, %1
%17 = load i32, i32* %3
switch i32 %17, label %33 [
i32 9, label %18
i32 27, label %19
i32 138, label %20
i32 128, label %21
i32 132, label %22
i32 129, label %23
i32 134, label %24
i32 140, label %25
i32 139, label %26
i32 133, label %27
i32 131, label %28
i32 130, label %29
i32 136, label %30
i32 137, label %31
i32 135, label %32
]
18: ; preds = %16
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %45
19: ; preds = %16
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %45
20: ; preds = %16
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %45
21: ; preds = %16
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %45
22: ; preds = %16
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %45
23: ; preds = %16
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %45
24: ; preds = %16
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %45
25: ; preds = %16
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %45
26: ; preds = %16
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %45
27: ; preds = %16
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %45
28: ; preds = %16
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8** %2
br label %45
29: ; preds = %16
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i8** %2
br label %45
30: ; preds = %16
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0), i8** %2
br label %45
31: ; preds = %16
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i8** %2
br label %45
32: ; preds = %16
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0), i8** %2
br label %45
33: ; preds = %16
%34 = load i32, i32* %3
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %33
%37 = load i32, i32* %3
%38 = icmp slt i32 %37, 32
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i32, i32* %3
%41 = add nsw i32 64, %40
%42 = trunc i32 %41 to i8
%43 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.16, i64 0, i64 0), i8 signext %42)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 0), i8** %2
br label %45
44: ; preds = %36, %33
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0), i8** %2
br label %45
45: ; preds = %44, %39, %32, %31, %30, %29, %28, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18, %13, %12
%46 = load i8*, i8** %2
ret i8* %46
}

LLVM IR (-O2):
@key_to_name.kbuf = internal global [32 x i8] zeroinitializer
@.str = [7 x i8] c"delete\00"
@.str.1 = [4 x i8] c"tab\00"
@.str.2 = [7 x i8] c"escape\00"
@.str.16 = [8 x i8] c"ctrl-%c\00"
@.str.17 = [12 x i8] c"unknown-key\00"
define i8* @key_to_name(i32 %0) {
%2 = add i32 %0, -32
%3 = icmp ult i32 %2, 224
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = icmp eq i32 %0, 127
br i1 %5, label %16, label %6
6: ; preds = %4
%7 = trunc i32 %0 to i8
store i8 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 1)
br label %16
8: ; preds = %1
switch i32 %0, label %10 [
i32 9, label %16
i32 27, label %9
]
9: ; preds = %8
br label %16
10: ; preds = %8
%11 = icmp ult i32 %0, 32
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = trunc i32 %0 to i8
%14 = add nuw nsw i8 %13, 64
%15 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.16, i64 0, i64 0), i8 signext %14)
br label %16
16: ; preds = %10, %8, %4, %12, %9, %6
%17 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 0), %6 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @key_to_name.kbuf, i64 0, i64 0), %12 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0), %10 ]
ret i8* %17
}