char *keyName(key)
char key;
{
  static char result[10];
  int i;
  static struct {
    char key;
    char *name;
  } keyList[] = {' ',   "SPACE", '\b',        "BACKSPACE", '\t',
                 "TAB", '\n',    "LINE FEED", '\r',        "RETURN",
                 '\33', "ESC",   '\177',      "DEL"};
  if ('!' <= key && key <= '~') {
    sprintf(result, "%c", key);
    return (result);
  }
  for (i = 0; keyList[i].key != '\0'; ++i)
    if (keyList[i].key == key)
      return (keyList[i].name);
  if (key < ' ') {
    sprintf(result, "^%c", key + 0x40);
    return (result);
  }
  sprintf(result, "\\%o", key);
  return (result);
}


x86 assembly (clang, -O0):
<keyName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
mov    $0x21,%eax
cmp    %ecx,%eax
jg     1165 <keyName+0x55>
movsbl -0x9(%rbp),%eax
cmp    $0x7e,%eax
jg     1165 <keyName+0x55>
movsbl -0x9(%rbp),%edx
lea    0x2f5a(%rip),%rdi
lea    0xeda(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
lea    0x2f45(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123a <keyName+0x12a>
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rcx
lea    0x2eb9(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11dd <keyName+0xcd>
movslq -0x10(%rbp),%rcx
lea    0x2e9b(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    11ca <keyName+0xba>
movslq -0x10(%rbp),%rcx
lea    0x2e7a(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    123a <keyName+0x12a>
jmp    11cf <keyName+0xbf>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116c <keyName+0x5c>
movsbl -0x9(%rbp),%eax
cmp    $0x20,%eax
jge    1216 <keyName+0x106>
movsbl -0x9(%rbp),%edx
add    $0x40,%edx
lea    0x2ea9(%rip),%rdi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
lea    0x2e94(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123a <keyName+0x12a>
movsbl -0x9(%rbp),%edx
lea    0x2e80(%rip),%rdi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
lea    0x2e6b(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keyName>:
mov    %edi,%eax
shl    $0x18,%eax
cmp    $0x20000001,%eax
jl     1129 <keyName+0x29>
cmp    $0x7f000000,%eax
je     1129 <keyName+0x29>
mov    %dil,0x2f07(%rip)
lea    0x2f00(%rip),%rax
movb   $0x0,0x2efa(%rip)
ret
movsbl %dil,%ecx
mov    $0xffffffffffffffff,%rax
lea    0x2ca5(%rip),%rdx
nopl   0x0(%rax,%rax,1)
movsbl (%rdx),%esi
add    $0x1,%rax
add    $0x10,%rdx
cmp    %esi,%ecx
jne    1140 <keyName+0x40>
mov    %eax,%eax
shl    $0x4,%rax
lea    0x2c84(%rip),%rcx
mov    0x8(%rax,%rcx,1),%rax
ret

LLVM IR (-O0):
%struct.anon = type { i8, i8* }
@keyName.result = internal global [10 x i8] zeroinitializer
@keyName.keyList = internal global [7 x %struct.anon] [%struct.anon { i8 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0) }, %struct.anon { i8 8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0) }, %struct.anon { i8 9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0) }, %struct.anon { i8 10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0) }, %struct.anon { i8 13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0) }, %struct.anon { i8 27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0) }, %struct.anon { i8 127, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0) }]
@.str = [6 x i8] c"SPACE\00"
@.str.1 = [10 x i8] c"BACKSPACE\00"
@.str.2 = [4 x i8] c"TAB\00"
@.str.3 = [10 x i8] c"LINE FEED\00"
@.str.4 = [7 x i8] c"RETURN\00"
@.str.5 = [4 x i8] c"ESC\00"
@.str.6 = [4 x i8] c"DEL\00"
@.str.7 = [3 x i8] c"%c\00"
@.str.8 = [4 x i8] c"^%c\00"
@.str.9 = [4 x i8] c"\\%o\00"
define i8* @keyName(i32 %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = trunc i32 %0 to i8
store i8 %5, i8* %3
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = icmp sle i32 33, %7
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = icmp sle i32 %11, 126
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %15)
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 0), i8** %2
br label %59
17: ; preds = %9, %1
store i32 0, i32* %4
br label %18
18: ; preds = %43, %17
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* @keyName.keyList, i64 0, i64 %20
%22 = getelementptr inbounds %struct.anon, %struct.anon* %21, i32 0, i32 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %46
26: ; preds = %18
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* @keyName.keyList, i64 0, i64 %28
%30 = getelementptr inbounds %struct.anon, %struct.anon* %29, i32 0, i32 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %32, %34
br i1 %35, label %36, label %42
36: ; preds = %26
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* @keyName.keyList, i64 0, i64 %38
%40 = getelementptr inbounds %struct.anon, %struct.anon* %39, i32 0, i32 1
%41 = load i8*, i8** %40
store i8* %41, i8** %2
br label %59
42: ; preds = %26
br label %43
43: ; preds = %42
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %18
46: ; preds = %18
%47 = load i8, i8* %3
%48 = sext i8 %47 to i32
%49 = icmp slt i32 %48, 32
br i1 %49, label %50, label %55
50: ; preds = %46
%51 = load i8, i8* %3
%52 = sext i8 %51 to i32
%53 = add nsw i32 %52, 64
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %53)
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 0), i8** %2
br label %59
55: ; preds = %46
%56 = load i8, i8* %3
%57 = sext i8 %56 to i32
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %57)
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 0), i8** %2
br label %59
59: ; preds = %55, %50, %36, %13
%60 = load i8*, i8** %2
ret i8* %60
}

LLVM IR (-O2):
%struct.anon = type { i8, i8* }
@keyName.result = internal global [10 x i8] zeroinitializer
@keyName.keyList = internal unnamed_addr constant [7 x %struct.anon] [%struct.anon { i8 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0) }, %struct.anon { i8 8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0) }, %struct.anon { i8 9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0) }, %struct.anon { i8 10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0) }, %struct.anon { i8 13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0) }, %struct.anon { i8 27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0) }, %struct.anon { i8 127, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0) }]
@.str = [6 x i8] c"SPACE\00"
@.str.1 = [10 x i8] c"BACKSPACE\00"
@.str.2 = [4 x i8] c"TAB\00"
@.str.3 = [10 x i8] c"LINE FEED\00"
@.str.4 = [7 x i8] c"RETURN\00"
@.str.5 = [4 x i8] c"ESC\00"
@.str.6 = [4 x i8] c"DEL\00"
define i8* @keyName(i32 %0) {
%2 = shl i32 %0, 24
%3 = ashr exact i32 %2, 24
%4 = icmp sgt i32 %2, 536870912
%5 = icmp ne i32 %2, 2130706432
%6 = and i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = trunc i32 %0 to i8
store i8 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 1)
br label %20
9: ; preds = %1, %9
%10 = phi i64 [ %15, %9 ], [ 0, %1 ]
%11 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* @keyName.keyList, i64 0, i64 %10, i32 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %3, %13
%15 = add nuw i64 %10, 1
br i1 %14, label %16, label %9
16: ; preds = %9
%17 = and i64 %10, 4294967295
%18 = getelementptr inbounds [7 x %struct.anon], [7 x %struct.anon]* @keyName.keyList, i64 0, i64 %17, i32 1
%19 = load i8*, i8** %18
br label %20
20: ; preds = %16, %7
%21 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @keyName.result, i64 0, i64 0), %7 ], [ %19, %16 ]
ret i8* %21
}