void EscapeExpand(char *p, char *q) {
  while (*p++ = *q++)
    if (p[-1] == '\\')
      switch (*q++) {
      case 'n':
        p[-1] = '\n';
        break;
      case 'r':
        p[-1] = '\r';
        break;
      case 't':
        p[-1] = '\t';
        break;
      case '\\':
        p[-1] = '\\';
        break;
      case 0:
        *p = 0;
        return;
      default:
        p[-1] = q[-1];
        break;
      }
}


x86 assembly (clang, -O0):
<EscapeExpand>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     1205 <EscapeExpand+0x105>
mov    -0x8(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5c,%eax
jne    1200 <EscapeExpand+0x100>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     11e1 <EscapeExpand+0xe1>
jmp    1169 <EscapeExpand+0x69>
mov    -0x14(%rbp),%eax
sub    $0x5c,%eax
je     11d4 <EscapeExpand+0xd4>
jmp    117a <EscapeExpand+0x7a>
mov    -0x14(%rbp),%eax
sub    $0x6e,%eax
je     11ad <EscapeExpand+0xad>
jmp    118b <EscapeExpand+0x8b>
mov    -0x14(%rbp),%eax
sub    $0x72,%eax
je     11ba <EscapeExpand+0xba>
jmp    119c <EscapeExpand+0x9c>
mov    -0x14(%rbp),%eax
sub    $0x74,%eax
je     11c7 <EscapeExpand+0xc7>
jmp    11ed <EscapeExpand+0xed>
mov    -0x8(%rbp),%rax
movb   $0xa,-0x1(%rax)
jmp    11fb <EscapeExpand+0xfb>
mov    -0x8(%rbp),%rax
movb   $0xd,-0x1(%rax)
jmp    11fb <EscapeExpand+0xfb>
mov    -0x8(%rbp),%rax
movb   $0x9,-0x1(%rax)
jmp    11fb <EscapeExpand+0xfb>
mov    -0x8(%rbp),%rax
movb   $0x5c,-0x1(%rax)
jmp    11fb <EscapeExpand+0xfb>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1205 <EscapeExpand+0x105>
mov    -0x10(%rbp),%rax
mov    -0x1(%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,-0x1(%rax)
jmp    1200 <EscapeExpand+0x100>
jmp    110c <EscapeExpand+0xc>
pop    %rbp
ret

x86 assembly (clang, -O2):
<EscapeExpand>:
lea    0xef9(%rip),%r8
jmp    1118 <EscapeExpand+0x18>
nopl   0x0(%rax)
add    $0x1,%rsi
test   %al,%al
je     115f <EscapeExpand+0x5f>
mov    %rdi,%rcx
movzbl (%rsi),%eax
add    $0x1,%rdi
mov    %al,(%rcx)
cmp    $0x5c,%al
jne    1110 <EscapeExpand+0x10>
movzbl 0x1(%rsi),%r9d
movsbl %r9b,%edx
lea    -0x5c(%rdx),%eax
cmp    $0x18,%eax
ja     1150 <EscapeExpand+0x50>
mov    $0xa,%dl
movslq (%r8,%rax,4),%rax
add    %r8,%rax
jmp    *%rax
mov    $0x5c,%dl
jmp    1157 <EscapeExpand+0x57>
mov    $0xd,%dl
jmp    1157 <EscapeExpand+0x57>
mov    $0x9,%dl
jmp    1157 <EscapeExpand+0x57>
test   %edx,%edx
je     1160 <EscapeExpand+0x60>
mov    %r9d,%edx
add    $0x2,%rsi
mov    %dl,(%rcx)
jmp    1118 <EscapeExpand+0x18>
ret
movb   $0x0,0x1(%rcx)
ret

LLVM IR (-O0):
define void @EscapeExpand(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 = %44, %2
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %4
%8 = load i8, i8* %6
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %3
store i8 %8, i8* %9
%11 = icmp ne i8 %8, 0
br i1 %11, label %12, label %45
12: ; preds = %5
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 92
br i1 %17, label %18, label %44
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8, i8* %19
%22 = sext i8 %21 to i32
switch i32 %22, label %37 [
i32 110, label %23
i32 114, label %26
i32 116, label %29
i32 92, label %32
i32 0, label %35
]
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 -1
store i8 10, i8* %25
br label %43
26: ; preds = %18
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 -1
store i8 13, i8* %28
br label %43
29: ; preds = %18
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 -1
store i8 9, i8* %31
br label %43
32: ; preds = %18
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 -1
store i8 92, i8* %34
br label %43
35: ; preds = %18
%36 = load i8*, i8** %3
store i8 0, i8* %36
br label %45
37: ; preds = %18
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 -1
%40 = load i8, i8* %39
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 -1
store i8 %40, i8* %42
br label %43
43: ; preds = %37, %32, %29, %26, %23
br label %44
44: ; preds = %43, %12
br label %5
45: ; preds = %35, %5
ret void
}

LLVM IR (-O2):
define void @EscapeExpand(i8* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %20, %2
%4 = phi i8* [ %0, %2 ], [ %8, %20 ]
%5 = phi i8* [ %1, %2 ], [ %21, %20 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %5
%8 = getelementptr inbounds i8, i8* %4, i64 1
store i8 %7, i8* %4
switch i8 %7, label %20 [
i8 0, label %22
i8 92, label %9
]
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %5, i64 2
%11 = load i8, i8* %6
%12 = sext i8 %11 to i32
switch i32 %12, label %17 [
i32 110, label %18
i32 114, label %13
i32 116, label %14
i32 92, label %15
i32 0, label %16
]
13: ; preds = %9
br label %18
14: ; preds = %9
br label %18
15: ; preds = %9
br label %18
16: ; preds = %9
store i8 0, i8* %8
br label %22
17: ; preds = %9
br label %18
18: ; preds = %9, %17, %15, %14, %13
%19 = phi i8 [ 13, %13 ], [ 9, %14 ], [ 92, %15 ], [ %11, %17 ], [ 10, %9 ]
store i8 %19, i8* %4
br label %20
20: ; preds = %18, %3
%21 = phi i8* [ %10, %18 ], [ %6, %3 ]
br label %3
22: ; preds = %3, %16
ret void
}