char escape_as(char chr) {
  switch (chr) {
  case '"':
    return '"';
  case '\\':
    return '\\';
  case '\b':
    return 'b';
  case '\f':
    return 'f';
  case '\n':
    return 'n';
  case '\r':
    return 'r';
  case '\t':
    return 't';
  }
  return 0;
}


x86 assembly (clang, -O0):
<escape_as>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x8,%eax
je     1197 <escape_as+0x97>
jmp    111f <escape_as+0x1f>
mov    -0x8(%rbp),%eax
sub    $0x9,%eax
je     11bb <escape_as+0xbb>
jmp    1130 <escape_as+0x30>
mov    -0x8(%rbp),%eax
sub    $0xa,%eax
je     11a9 <escape_as+0xa9>
jmp    1141 <escape_as+0x41>
mov    -0x8(%rbp),%eax
sub    $0xc,%eax
je     11a0 <escape_as+0xa0>
jmp    1152 <escape_as+0x52>
mov    -0x8(%rbp),%eax
sub    $0xd,%eax
je     11b2 <escape_as+0xb2>
jmp    1163 <escape_as+0x63>
mov    -0x8(%rbp),%eax
sub    $0x22,%eax
je     1185 <escape_as+0x85>
jmp    1174 <escape_as+0x74>
mov    -0x8(%rbp),%eax
sub    $0x5c,%eax
je     118e <escape_as+0x8e>
jmp    11c4 <escape_as+0xc4>
movb   $0x22,-0x1(%rbp)
jmp    11c8 <escape_as+0xc8>
movb   $0x5c,-0x1(%rbp)
jmp    11c8 <escape_as+0xc8>
movb   $0x62,-0x1(%rbp)
jmp    11c8 <escape_as+0xc8>
movb   $0x66,-0x1(%rbp)
jmp    11c8 <escape_as+0xc8>
movb   $0x6e,-0x1(%rbp)
jmp    11c8 <escape_as+0xc8>
movb   $0x72,-0x1(%rbp)
jmp    11c8 <escape_as+0xc8>
movb   $0x74,-0x1(%rbp)
jmp    11c8 <escape_as+0xc8>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_as>:
lea    -0x8(%rdi),%ecx
cmp    $0x1a,%ecx
ja     111d <escape_as+0x1d>
mov    $0x22,%al
lea    0xeef(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x62,%al
ret
cmp    $0x5c,%edi
jne    1125 <escape_as+0x25>
mov    $0x5c,%al
ret
xor    %eax,%eax
ret
mov    $0x74,%al
ret
mov    $0x6e,%al
ret
mov    $0x66,%al
ret
mov    $0x72,%al
ret

LLVM IR (-O0):
define signext i8 @escape_as(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
switch i32 %5, label %13 [
i32 34, label %6
i32 92, label %7
i32 8, label %8
i32 12, label %9
i32 10, label %10
i32 13, label %11
i32 9, label %12
]
6: ; preds = %1
store i8 34, i8* %2
br label %14
7: ; preds = %1
store i8 92, i8* %2
br label %14
8: ; preds = %1
store i8 98, i8* %2
br label %14
9: ; preds = %1
store i8 102, i8* %2
br label %14
10: ; preds = %1
store i8 110, i8* %2
br label %14
11: ; preds = %1
store i8 114, i8* %2
br label %14
12: ; preds = %1
store i8 116, i8* %2
br label %14
13: ; preds = %1
store i8 0, i8* %2
br label %14
14: ; preds = %13, %12, %11, %10, %9, %8, %7, %6
%15 = load i8, i8* %2
ret i8 %15
}

LLVM IR (-O2):
define signext i8 @escape_as(i8 signext %0) {
%2 = sext i8 %0 to i32
switch i32 %2, label %9 [
i32 34, label %10
i32 92, label %3
i32 8, label %4
i32 12, label %5
i32 10, label %6
i32 13, label %7
i32 9, label %8
]
3: ; preds = %1
br label %10
4: ; preds = %1
br label %10
5: ; preds = %1
br label %10
6: ; preds = %1
br label %10
7: ; preds = %1
br label %10
8: ; preds = %1
br label %10
9: ; preds = %1
br label %10
10: ; preds = %1, %9, %8, %7, %6, %5, %4, %3
%11 = phi i8 [ 0, %9 ], [ 116, %8 ], [ 114, %7 ], [ 110, %6 ], [ 102, %5 ], [ 98, %4 ], [ 92, %3 ], [ 34, %1 ]
ret i8 %11
}