int escape_to_hex(int c) {
  switch (c) {
  case '0':
    return 0x00;
  case 'a':
    return 0x07;
  case 'b':
    return 0x08;
  case 'f':
    return 0x0C;
  case 'n':
    return 0x0A;
  case 'r':
    return 0x0D;
  case 't':
    return 0x09;
  case 'v':
    return 0x0B;
  case '\\':
    return 0x5C;
  case '\'':
    return 0x27;
  case '"':
    return 0x22;
  case '?':
    return 0x3F;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<escape_to_hex>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x54,%eax
ja     11c0 <escape_to_hex+0xc0>
mov    -0x10(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0x7,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0x8,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0xc,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0xa,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0xd,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0x9,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0xb,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0x5c,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0x27,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0x22,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0x3f,-0x4(%rbp)
jmp    11c7 <escape_to_hex+0xc7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_to_hex>:
lea    -0x22(%rdi),%ecx
cmp    $0x54,%ecx
ja     111d <escape_to_hex+0x1d>
xor    %eax,%eax
lea    0xeef(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    %edi,%eax
ret
mov    $0xffffffff,%eax
ret
mov    $0x7,%eax
ret
mov    $0x8,%eax
ret
mov    $0xc,%eax
ret
mov    $0xa,%eax
ret
mov    $0xd,%eax
ret
mov    $0x9,%eax
ret
mov    $0xb,%eax
ret

LLVM IR (-O0):
define i32 @escape_to_hex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %17 [
i32 48, label %5
i32 97, label %6
i32 98, label %7
i32 102, label %8
i32 110, label %9
i32 114, label %10
i32 116, label %11
i32 118, label %12
i32 92, label %13
i32 39, label %14
i32 34, label %15
i32 63, label %16
]
5: ; preds = %1
store i32 0, i32* %2
br label %18
6: ; preds = %1
store i32 7, i32* %2
br label %18
7: ; preds = %1
store i32 8, i32* %2
br label %18
8: ; preds = %1
store i32 12, i32* %2
br label %18
9: ; preds = %1
store i32 10, i32* %2
br label %18
10: ; preds = %1
store i32 13, i32* %2
br label %18
11: ; preds = %1
store i32 9, i32* %2
br label %18
12: ; preds = %1
store i32 11, i32* %2
br label %18
13: ; preds = %1
store i32 92, i32* %2
br label %18
14: ; preds = %1
store i32 39, i32* %2
br label %18
15: ; preds = %1
store i32 34, i32* %2
br label %18
16: ; preds = %1
store i32 63, i32* %2
br label %18
17: ; preds = %1
store i32 -1, i32* %2
br label %18
18: ; preds = %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
define i32 @escape_to_hex(i32 %0) {
switch i32 %0, label %13 [
i32 48, label %14
i32 97, label %2
i32 98, label %3
i32 102, label %4
i32 110, label %5
i32 114, label %6
i32 116, label %7
i32 118, label %8
i32 92, label %9
i32 39, label %10
i32 34, label %11
i32 63, label %12
]
2: ; preds = %1
br label %14
3: ; preds = %1
br label %14
4: ; preds = %1
br label %14
5: ; preds = %1
br label %14
6: ; preds = %1
br label %14
7: ; preds = %1
br label %14
8: ; preds = %1
br label %14
9: ; preds = %1
br label %14
10: ; preds = %1
br label %14
11: ; preds = %1
br label %14
12: ; preds = %1
br label %14
13: ; preds = %1
br label %14
14: ; preds = %1, %13, %12, %11, %10, %9, %8, %7, %6, %5, %4, %3, %2
%15 = phi i32 [ -1, %13 ], [ %0, %12 ], [ %0, %11 ], [ %0, %10 ], [ %0, %9 ], [ 11, %8 ], [ 9, %7 ], [ 13, %6 ], [ 10, %5 ], [ 12, %4 ], [ 8, %3 ], [ 7, %2 ], [ 0, %1 ]
ret i32 %15
}