void escape(char *source, char *target) {
  while (*source != '\0') {
    switch (*source) {
    case '\a':
      *target++ = '\\';
      *target++ = 'a';
      break;
    case '\b':
      *target++ = '\\';
      *target++ = 'b';
      break;
    case '\f':
      *target++ = '\\';
      *target++ = 'f';
      break;
    case '\n':
      *target++ = '\\';
      *target++ = 'n';
      break;
    case '\r':
      *target++ = '\\';
      *target++ = 'r';
      break;
    case '\t':
      *target++ = '\\';
      *target++ = 't';
      break;
    case '\v':
      *target++ = '\\';
      *target++ = 'v';
      break;
    case '\\':
      *target++ = '\\';
      *target++ = '\\';
      break;
    case '\'':
      *target++ = '\\';
      *target++ = '\'';
      break;
    case '\"':
      *target++ = '\\';
      *target++ = '\"';
      break;
    case '\?':
      *target++ = '\\';
      *target++ = '?';
      break;
    default:
      *target++ = *source;
    }
    source++;
  }
  *target = '\0';
}


x86 assembly (clang, -O0):
<escape>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1334 <escape+0x234>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xfffffff9,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x55,%eax
ja     130c <escape+0x20c>
mov    -0x18(%rbp),%rax
lea    0xec0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x61,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x62,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x66,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x6e,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x72,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x74,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x76,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x27,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x22,(%rax)
jmp    1323 <escape+0x223>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x3f,(%rax)
jmp    1323 <escape+0x223>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    110c <escape+0xc>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape>:
mov    (%rdi),%cl
test   %cl,%cl
je     11c5 <escape+0xc5>
add    $0x1,%rdi
lea    0xeeb(%rip),%rax
jmp    112f <escape+0x2f>
mov    %cl,(%rsi)
add    $0x1,%rsi
nopl   (%rax)
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
je     11c5 <escape+0xc5>
movsbl %cl,%edx
add    $0xfffffff9,%edx
cmp    $0x55,%edx
ja     1117 <escape+0x17>
movslq (%rax,%rdx,4),%rdx
add    %rax,%rdx
jmp    *%rdx
movw   $0x615c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x625c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x745c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x6e5c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x765c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x665c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x725c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x225c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x275c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x3f5c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movw   $0x5c5c,(%rsi)
add    $0x2,%rsi
jmp    1120 <escape+0x20>
movb   $0x0,(%rsi)
ret

LLVM IR (-O0):
define void @escape(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %5
5: ; preds = %74, %2
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %77
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %69 [
i32 7, label %14
i32 8, label %19
i32 12, label %24
i32 10, label %29
i32 13, label %34
i32 9, label %39
i32 11, label %44
i32 92, label %49
i32 39, label %54
i32 34, label %59
i32 63, label %64
]
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %4
store i8 92, i8* %15
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
store i8 97, i8* %17
br label %74
19: ; preds = %10
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
store i8 92, i8* %20
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %4
store i8 98, i8* %22
br label %74
24: ; preds = %10
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
store i8 92, i8* %25
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
store i8 102, i8* %27
br label %74
29: ; preds = %10
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 92, i8* %30
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
store i8 110, i8* %32
br label %74
34: ; preds = %10
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
store i8 92, i8* %35
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
store i8 114, i8* %37
br label %74
39: ; preds = %10
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
store i8 92, i8* %40
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
store i8 116, i8* %42
br label %74
44: ; preds = %10
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
store i8 92, i8* %45
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %4
store i8 118, i8* %47
br label %74
49: ; preds = %10
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %4
store i8 92, i8* %50
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %4
store i8 92, i8* %52
br label %74
54: ; preds = %10
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %4
store i8 92, i8* %55
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %4
store i8 39, i8* %57
br label %74
59: ; preds = %10
%60 = load i8*, i8** %4
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %4
store i8 92, i8* %60
%62 = load i8*, i8** %4
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %4
store i8 34, i8* %62
br label %74
64: ; preds = %10
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %4
store i8 92, i8* %65
%67 = load i8*, i8** %4
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %4
store i8 63, i8* %67
br label %74
69: ; preds = %10
%70 = load i8*, i8** %3
%71 = load i8, i8* %70
%72 = load i8*, i8** %4
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %4
store i8 %71, i8* %72
br label %74
74: ; preds = %69, %64, %59, %54, %49, %44, %39, %34, %29, %24, %19, %14
%75 = load i8*, i8** %3
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %3
br label %5
77: ; preds = %5
%78 = load i8*, i8** %4
store i8 0, i8* %78
ret void
}

LLVM IR (-O2):
define void @escape(i8* nocapture %0, i8* writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %50, label %5
5: ; preds = %2, %45
%6 = phi i8 [ %48, %45 ], [ %3, %2 ]
%7 = phi i8* [ %46, %45 ], [ %1, %2 ]
%8 = phi i8* [ %47, %45 ], [ %0, %2 ]
%9 = sext i8 %6 to i32
switch i32 %9, label %43 [
i32 7, label %10
i32 8, label %13
i32 12, label %16
i32 10, label %19
i32 13, label %22
i32 9, label %25
i32 11, label %28
i32 92, label %31
i32 39, label %34
i32 34, label %37
i32 63, label %40
]
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%12 = getelementptr inbounds i8, i8* %7, i64 2
store i8 97, i8* %11
br label %45
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%15 = getelementptr inbounds i8, i8* %7, i64 2
store i8 98, i8* %14
br label %45
16: ; preds = %5
%17 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%18 = getelementptr inbounds i8, i8* %7, i64 2
store i8 102, i8* %17
br label %45
19: ; preds = %5
%20 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%21 = getelementptr inbounds i8, i8* %7, i64 2
store i8 110, i8* %20
br label %45
22: ; preds = %5
%23 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%24 = getelementptr inbounds i8, i8* %7, i64 2
store i8 114, i8* %23
br label %45
25: ; preds = %5
%26 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%27 = getelementptr inbounds i8, i8* %7, i64 2
store i8 116, i8* %26
br label %45
28: ; preds = %5
%29 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%30 = getelementptr inbounds i8, i8* %7, i64 2
store i8 118, i8* %29
br label %45
31: ; preds = %5
%32 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%33 = getelementptr inbounds i8, i8* %7, i64 2
store i8 92, i8* %32
br label %45
34: ; preds = %5
%35 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%36 = getelementptr inbounds i8, i8* %7, i64 2
store i8 39, i8* %35
br label %45
37: ; preds = %5
%38 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%39 = getelementptr inbounds i8, i8* %7, i64 2
store i8 34, i8* %38
br label %45
40: ; preds = %5
%41 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%42 = getelementptr inbounds i8, i8* %7, i64 2
store i8 63, i8* %41
br label %45
43: ; preds = %5
%44 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %6, i8* %7
br label %45
45: ; preds = %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10
%46 = phi i8* [ %44, %43 ], [ %42, %40 ], [ %39, %37 ], [ %36, %34 ], [ %33, %31 ], [ %30, %28 ], [ %27, %25 ], [ %24, %22 ], [ %21, %19 ], [ %18, %16 ], [ %15, %13 ], [ %12, %10 ]
%47 = getelementptr inbounds i8, i8* %8, i64 1
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 0
br i1 %49, label %50, label %5
50: ; preds = %45, %2
%51 = phi i8* [ %1, %2 ], [ %46, %45 ]
store i8 0, i8* %51
ret void
}