char getEscape(char ch) {
  static struct {
    char ch;
    char code;
  } const pair[] = {
      {'\"', '\"'}, {'\\', '\\'}, {'/', '/'},  {'b', '\b'},
      {'f', '\f'},  {'n', '\n'},  {'r', '\r'}, {'t', '\t'},
  };
  unsigned int i;
  for (i = 0; i < sizeof pair / sizeof *pair; ++i)
    if (pair[i].ch == ch)
      return pair[i].code;
  return '\0';
}


x86 assembly (clang, -O0):
<getEscape>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    $0x8,%rax
jae    1165 <getEscape+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0xed6(%rip),%rax
movsbl (%rax,%rcx,2),%eax
movsbl -0x2(%rbp),%ecx
cmp    %ecx,%eax
jne    1152 <getEscape+0x52>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0xeba(%rip),%rax
mov    0x1(%rax,%rcx,2),%al
mov    %al,-0x1(%rbp)
jmp    1169 <getEscape+0x69>
jmp    1157 <getEscape+0x57>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1111 <getEscape+0x11>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getEscape>:
xor    %eax,%eax
lea    -0x2f(%rdi),%ecx
cmp    $0x45,%cl
ja     1124 <getEscape+0x24>
movzbl %cl,%ecx
lea    0xeec(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x2,%eax
jmp    1153 <getEscape+0x53>
cmp    $0x22,%dil
je     1153 <getEscape+0x53>
ret
mov    $0x1,%eax
jmp    1153 <getEscape+0x53>
mov    $0x3,%eax
jmp    1153 <getEscape+0x53>
mov    $0x4,%eax
jmp    1153 <getEscape+0x53>
mov    $0x5,%eax
jmp    1153 <getEscape+0x53>
mov    $0x7,%eax
jmp    1153 <getEscape+0x53>
mov    $0x6,%eax
lea    0xfc6(%rip),%rcx
mov    0x1(%rcx,%rax,2),%al
ret

LLVM IR (-O0):
%struct.anon = type { i8, i8 }
@getEscape.pair = internal constant [8 x %struct.anon] [%struct.anon { i8 34, i8 34 }, %struct.anon { i8 92, i8 92 }, %struct.anon { i8 47, i8 47 }, %struct.anon { i8 98, i8 8 }, %struct.anon { i8 102, i8 12 }, %struct.anon { i8 110, i8 10 }, %struct.anon { i8 114, i8 13 }, %struct.anon { i8 116, i8 9 }]
define signext i8 @getEscape(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
store i8 %0, i8* %3
store i32 0, i32* %4
br label %5
5: ; preds = %26, %1
%6 = load i32, i32* %4
%7 = zext i32 %6 to i64
%8 = icmp ult i64 %7, 8
br i1 %8, label %9, label %29
9: ; preds = %5
%10 = load i32, i32* %4
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* @getEscape.pair, i64 0, i64 %11
%13 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %15, %17
br i1 %18, label %19, label %25
19: ; preds = %9
%20 = load i32, i32* %4
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* @getEscape.pair, i64 0, i64 %21
%23 = getelementptr inbounds %struct.anon, %struct.anon* %22, i32 0, i32 1
%24 = load i8, i8* %23
store i8 %24, i8* %2
br label %30
25: ; preds = %9
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add i32 %27, 1
store i32 %28, i32* %4
br label %5
29: ; preds = %5
store i8 0, i8* %2
br label %30
30: ; preds = %29, %19
%31 = load i8, i8* %2
ret i8 %31
}

LLVM IR (-O2):
%struct.anon = type { i8, i8 }
@getEscape.pair = internal unnamed_addr constant [8 x %struct.anon] [%struct.anon { i8 34, i8 34 }, %struct.anon { i8 92, i8 92 }, %struct.anon { i8 47, i8 47 }, %struct.anon { i8 98, i8 8 }, %struct.anon { i8 102, i8 12 }, %struct.anon { i8 110, i8 10 }, %struct.anon { i8 114, i8 13 }, %struct.anon { i8 116, i8 9 }]
define signext i8 @getEscape(i8 signext %0) {
switch i8 %0, label %13 [
i8 34, label %9
i8 92, label %2
i8 47, label %3
i8 98, label %4
i8 102, label %5
i8 110, label %6
i8 114, label %7
i8 116, label %8
]
2: ; preds = %1
br label %9
3: ; preds = %1
br label %9
4: ; preds = %1
br label %9
5: ; preds = %1
br label %9
6: ; preds = %1
br label %9
7: ; preds = %1
br label %9
8: ; preds = %1
br label %9
9: ; preds = %1, %8, %7, %6, %5, %4, %3, %2
%10 = phi i64 [ 0, %1 ], [ 1, %2 ], [ 2, %3 ], [ 3, %4 ], [ 4, %5 ], [ 5, %6 ], [ 6, %7 ], [ 7, %8 ]
%11 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* @getEscape.pair, i64 0, i64 %10, i32 1
%12 = load i8, i8* %11
br label %13
13: ; preds = %1, %9
%14 = phi i8 [ %12, %9 ], [ 0, %1 ]
ret i8 %14
}