#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 */
char *strncpy(char *, char *, size_t);
char *key_char2str(char ch, char *buf, size_t sz) {
  buf[sz - 1] = '\0';
  switch (ch) {
  case '\t':
    return strncpy(buf, "tab", sz - 1);
  case '\n':
    return strncpy(buf, "enter", sz - 1);
  case ' ':
    return strncpy(buf, "space", sz - 1);
  case '\b':
    return strncpy(buf, "backspace", sz - 1);
  case 27:
    return strncpy(buf, "esc", sz - 1);
  case 127:
    return strncpy(buf, "delete", sz - 1);
  case '#':
  case '=':
  case '\\':
    buf[0] = '\\';
    buf[1] = ch;
    buf[2] = '\0';
    return buf;
  }
  buf[0] = ch;
  buf[1] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<key_char2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
movb   $0x0,-0x1(%rax,%rcx,1)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x8,%eax
je     1233 <key_char2str+0x123>
jmp    1148 <key_char2str+0x38>
mov    -0x24(%rbp),%eax
sub    $0x9,%eax
je     11d0 <key_char2str+0xc0>
jmp    1159 <key_char2str+0x49>
mov    -0x24(%rbp),%eax
sub    $0xa,%eax
je     11f1 <key_char2str+0xe1>
jmp    116a <key_char2str+0x5a>
mov    -0x24(%rbp),%eax
sub    $0x1b,%eax
je     1254 <key_char2str+0x144>
jmp    117b <key_char2str+0x6b>
mov    -0x24(%rbp),%eax
sub    $0x20,%eax
je     1212 <key_char2str+0x102>
jmp    118c <key_char2str+0x7c>
mov    -0x24(%rbp),%eax
sub    $0x23,%eax
je     1296 <key_char2str+0x186>
jmp    119d <key_char2str+0x8d>
mov    -0x24(%rbp),%eax
sub    $0x3d,%eax
je     1296 <key_char2str+0x186>
jmp    11ae <key_char2str+0x9e>
mov    -0x24(%rbp),%eax
sub    $0x5c,%eax
je     1296 <key_char2str+0x186>
jmp    11bf <key_char2str+0xaf>
mov    -0x24(%rbp),%eax
sub    $0x7f,%eax
je     1275 <key_char2str+0x165>
jmp    12bc <key_char2str+0x1ac>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
lea    0xe1d(%rip),%rsi
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
jmp    12d5 <key_char2str+0x1c5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
lea    0xe00(%rip),%rsi
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
jmp    12d5 <key_char2str+0x1c5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
lea    0xde9(%rip),%rsi
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
jmp    12d5 <key_char2str+0x1c5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
lea    0xdc4(%rip),%rsi
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
jmp    12d5 <key_char2str+0x1c5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
lea    0xdad(%rip),%rsi
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
jmp    12d5 <key_char2str+0x1c5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
lea    0xd90(%rip),%rsi
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
jmp    12d5 <key_char2str+0x1c5>
mov    -0x18(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d5 <key_char2str+0x1c5>
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<key_char2str>:
push   %rbx
mov    %rsi,%rbx
movb   $0x0,-0x1(%rsi,%rdx,1)
add    $0xffffffffffffffff,%rdx
lea    -0x8(%rdi),%eax
cmp    $0x35,%eax
ja     113e <key_char2str+0x2e>
lea    0xed4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xfa6(%rip),%rsi
jmp    1189 <key_char2str+0x79>
cmp    $0x5c,%edi
je     1151 <key_char2str+0x41>
cmp    $0x7f,%edi
jne    115e <key_char2str+0x4e>
lea    0xfa1(%rip),%rsi
jmp    1189 <key_char2str+0x79>
movb   $0x5c,(%rbx)
mov    %dil,0x1(%rbx)
movb   $0x0,0x2(%rbx)
jmp    1191 <key_char2str+0x81>
mov    %dil,(%rbx)
movb   $0x0,0x1(%rbx)
jmp    1191 <key_char2str+0x81>
lea    0xf6a(%rip),%rsi
jmp    1189 <key_char2str+0x79>
lea    0xf65(%rip),%rsi
jmp    1189 <key_char2str+0x79>
lea    0xf6c(%rip),%rsi
jmp    1189 <key_char2str+0x79>
lea    0xf5d(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"tab\00"
@.str.1 = [6 x i8] c"enter\00"
@.str.2 = [6 x i8] c"space\00"
@.str.3 = [10 x i8] c"backspace\00"
@.str.4 = [4 x i8] c"esc\00"
@.str.5 = [7 x i8] c"delete\00"
define i8* @key_char2str(i8 signext %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i64
store i8 %0, i8* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load i8*, i8** %6
%9 = load i64, i64* %7
%10 = sub i64 %9, 1
%11 = getelementptr inbounds i8, i8* %8, i64 %10
store i8 0, i8* %11
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
switch i32 %13, label %53 [
i32 9, label %14
i32 10, label %19
i32 32, label %24
i32 8, label %29
i32 27, label %34
i32 127, label %39
i32 35, label %44
i32 61, label %44
i32 92, label %44
]
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = load i64, i64* %7
%17 = sub i64 %16, 1
%18 = call i8* @strncpy(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %17)
store i8* %18, i8** %4
br label %60
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = load i64, i64* %7
%22 = sub i64 %21, 1
%23 = call i8* @strncpy(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %22)
store i8* %23, i8** %4
br label %60
24: ; preds = %3
%25 = load i8*, i8** %6
%26 = load i64, i64* %7
%27 = sub i64 %26, 1
%28 = call i8* @strncpy(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %27)
store i8* %28, i8** %4
br label %60
29: ; preds = %3
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = sub i64 %31, 1
%33 = call i8* @strncpy(i8* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 %32)
store i8* %33, i8** %4
br label %60
34: ; preds = %3
%35 = load i8*, i8** %6
%36 = load i64, i64* %7
%37 = sub i64 %36, 1
%38 = call i8* @strncpy(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %37)
store i8* %38, i8** %4
br label %60
39: ; preds = %3
%40 = load i8*, i8** %6
%41 = load i64, i64* %7
%42 = sub i64 %41, 1
%43 = call i8* @strncpy(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %42)
store i8* %43, i8** %4
br label %60
44: ; preds = %3, %3, %3
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i64 0
store i8 92, i8* %46
%47 = load i8, i8* %5
%48 = load i8*, i8** %6
%49 = getelementptr inbounds i8, i8* %48, i64 1
store i8 %47, i8* %49
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i64 2
store i8 0, i8* %51
%52 = load i8*, i8** %6
store i8* %52, i8** %4
br label %60
53: ; preds = %3
%54 = load i8, i8* %5
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i64 0
store i8 %54, i8* %56
%57 = load i8*, i8** %6
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8 0, i8* %58
%59 = load i8*, i8** %6
store i8* %59, i8** %4
br label %60
60: ; preds = %53, %44, %39, %34, %29, %24, %19, %14
%61 = load i8*, i8** %4
ret i8* %61
}

LLVM IR (-O2):
@.str = [4 x i8] c"tab\00"
@.str.1 = [6 x i8] c"enter\00"
@.str.2 = [6 x i8] c"space\00"
@.str.3 = [10 x i8] c"backspace\00"
@.str.4 = [4 x i8] c"esc\00"
@.str.5 = [7 x i8] c"delete\00"
define i8* @key_char2str(i8 signext %0, i8* returned %1, i64 %2) {
%4 = add i64 %2, -1
%5 = getelementptr inbounds i8, i8* %1, i64 %4
store i8 0, i8* %5
%6 = sext i8 %0 to i32
switch i32 %6, label %22 [
i32 9, label %7
i32 10, label %9
i32 32, label %11
i32 8, label %13
i32 27, label %15
i32 127, label %17
i32 35, label %19
i32 61, label %19
i32 92, label %19
]
7: ; preds = %3
%8 = tail call i8* @strncpy(i8* dereferenceable(1) %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %4)
br label %24
9: ; preds = %3
%10 = tail call i8* @strncpy(i8* dereferenceable(1) %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %4)
br label %24
11: ; preds = %3
%12 = tail call i8* @strncpy(i8* dereferenceable(1) %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %4)
br label %24
13: ; preds = %3
%14 = tail call i8* @strncpy(i8* dereferenceable(1) %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 %4)
br label %24
15: ; preds = %3
%16 = tail call i8* @strncpy(i8* dereferenceable(1) %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %4)
br label %24
17: ; preds = %3
%18 = tail call i8* @strncpy(i8* dereferenceable(1) %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %4)
br label %24
19: ; preds = %3, %3, %3
store i8 92, i8* %1
%20 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %0, i8* %20
%21 = getelementptr inbounds i8, i8* %1, i64 2
store i8 0, i8* %21
br label %24
22: ; preds = %3
store i8 %0, i8* %1
%23 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %23
br label %24
24: ; preds = %22, %19, %17, %15, %13, %11, %9, %7
ret i8* %1
}