char *DecompileString(char *string) {
  static char buf[255];
  char *s;
  int c = 1;
  s = buf;
  *s++ = '"';
  while (string && *string) {
    if (c == sizeof(buf) - 2)
      break;
    if (*string == '\n') {
      *s++ = '\\';
      *s++ = 'n';
      c++;
    } else if (*string == '"') {
      *s++ = '\\';
      *s++ = '"';
      c++;
    } else {
      *s++ = *string;
      c++;
    }
    string++;
    if (c > (int)(sizeof(buf) - 10)) {
      *s++ = '.';
      *s++ = '.';
      *s++ = '.';
      c += 3;
      break;
    }
  }
  *s++ = '"';
  *s++ = 0;
  return buf;
}


x86 assembly (clang, -O0):
<DecompileString>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0x2f1a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x22,(%rax)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x15(%rbp)
je     114c <DecompileString+0x4c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    115c <DecompileString+0x5c>
jmp    127c <DecompileString+0x17c>
movslq -0x14(%rbp),%rax
cmp    $0xfd,%rax
jne    1171 <DecompileString+0x71>
jmp    127c <DecompileString+0x17c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11b3 <DecompileString+0xb3>
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)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121a <DecompileString+0x11a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11f5 <DecompileString+0xf5>
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)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1215 <DecompileString+0x115>
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    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121a <DecompileString+0x11a>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0xf5,-0x14(%rbp)
jle    1277 <DecompileString+0x177>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2e,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2e,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2e,(%rax)
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    127c <DecompileString+0x17c>
jmp    112c <DecompileString+0x2c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x22,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
lea    0x2d89(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<DecompileString>:
movb   $0x22,0x2f29(%rip)
lea    0x2f23(%rip),%rax
xor    %esi,%esi
jmp    112d <DecompileString+0x2d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movw   $0x225c,(%rax)
add    $0x2,%rax
add    $0x2,%rsi
mov    %rdi,%rdx
add    %rsi,%rdx
je     11b7 <DecompileString+0xb7>
movzbl (%rdx),%ecx
cmp    $0xa,%cl
je     1160 <DecompileString+0x60>
cmp    $0x22,%cl
je     1170 <DecompileString+0x70>
test   %cl,%cl
je     11b7 <DecompileString+0xb7>
mov    %cl,(%rax)
add    $0x1,%rax
cmp    $0xf4,%esi
jne    1181 <DecompileString+0x81>
jmp    11aa <DecompileString+0xaa>
nopw   0x0(%rax,%rax,1)
movw   $0x6e5c,(%rax)
jmp    1175 <DecompileString+0x75>
nopw   0x0(%rax,%rax,1)
movw   $0x225c,(%rax)
add    $0x2,%rax
cmp    $0xf4,%esi
je     11aa <DecompileString+0xaa>
movzbl 0x1(%rdx),%ecx
cmp    $0xa,%cl
je     11a0 <DecompileString+0xa0>
cmp    $0x22,%cl
je     1120 <DecompileString+0x20>
test   %cl,%cl
je     11b7 <DecompileString+0xb7>
mov    %cl,(%rax)
add    $0x1,%rax
add    $0x2,%rsi
jmp    112d <DecompileString+0x2d>
nop
movw   $0x6e5c,(%rax)
jmp    1125 <DecompileString+0x25>
movw   $0x2e2e,(%rax)
movb   $0x2e,0x2(%rax)
add    $0x3,%rax
movw   $0x22,(%rax)
lea    0x2e6d(%rip),%rax
ret

LLVM IR (-O0):
@DecompileString.buf = internal global [255 x i8] zeroinitializer
define i8* @DecompileString(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %4
store i8* getelementptr inbounds ([255 x i8], [255 x i8]* @DecompileString.buf, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i32 1
store i8* %6, i8** %3
store i8 34, i8* %5
br label %7
7: ; preds = %68, %1
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %10, %7
%16 = phi i1 [ false, %7 ], [ %14, %10 ]
br i1 %16, label %17, label %69
17: ; preds = %15
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = icmp eq i64 %19, 253
br i1 %20, label %21, label %22
21: ; preds = %17
br label %69
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
store i8 92, i8* %28
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %3
store i8 110, i8* %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %54
34: ; preds = %22
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 34
br i1 %38, label %39, label %46
39: ; preds = %34
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %3
store i8 92, i8* %40
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %3
store i8 34, i8* %42
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %53
46: ; preds = %34
%47 = load i8*, i8** %2
%48 = load i8, i8* %47
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %3
store i8 %48, i8* %49
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %53
53: ; preds = %46, %39
br label %54
54: ; preds = %53, %27
%55 = load i8*, i8** %2
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %2
%57 = load i32, i32* %4
%58 = icmp sgt i32 %57, 245
br i1 %58, label %59, label %68
59: ; preds = %54
%60 = load i8*, i8** %3
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %3
store i8 46, i8* %60
%62 = load i8*, i8** %3
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %3
store i8 46, i8* %62
%64 = load i8*, i8** %3
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %3
store i8 46, i8* %64
%66 = load i32, i32* %4
%67 = add nsw i32 %66, 3
store i32 %67, i32* %4
br label %69
68: ; preds = %54
br label %7
69: ; preds = %59, %21, %15
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %3
store i8 34, i8* %70
%72 = load i8*, i8** %3
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %3
store i8 0, i8* %72
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @DecompileString.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@DecompileString.buf = internal global [255 x i8] zeroinitializer
define i8* @DecompileString(i8* %0) {
store i8 34, i8* getelementptr inbounds ([255 x i8], [255 x i8]* @DecompileString.buf, i64 0, i64 0)
br label %2
2: ; preds = %31, %1
%3 = phi i8* [ %0, %1 ], [ %34, %31 ]
%4 = phi i8* [ getelementptr inbounds ([255 x i8], [255 x i8]* @DecompileString.buf, i64 0, i64 1), %1 ], [ %32, %31 ]
%5 = phi i32 [ 1, %1 ], [ %33, %31 ]
%6 = icmp eq i8* %3, null
br i1 %6, label %39, label %7
7: ; preds = %2
%8 = load i8, i8* %3
switch i8 %8, label %15 [
i8 0, label %39
i8 10, label %9
i8 34, label %12
]
9: ; preds = %7
%10 = getelementptr inbounds i8, i8* %4, i64 1
store i8 92, i8* %4
%11 = getelementptr inbounds i8, i8* %4, i64 2
store i8 110, i8* %10
br label %17
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %4, i64 1
store i8 92, i8* %4
%14 = getelementptr inbounds i8, i8* %4, i64 2
store i8 34, i8* %13
br label %17
15: ; preds = %7
%16 = getelementptr inbounds i8, i8* %4, i64 1
store i8 %8, i8* %4
br label %17
17: ; preds = %12, %15, %9
%18 = phi i8* [ %11, %9 ], [ %14, %12 ], [ %16, %15 ]
%19 = getelementptr inbounds i8, i8* %3, i64 1
%20 = icmp eq i32 %5, 245
br i1 %20, label %35, label %21
21: ; preds = %17
%22 = load i8, i8* %19
switch i8 %22, label %29 [
i8 0, label %39
i8 10, label %26
i8 34, label %23
]
23: ; preds = %21
%24 = getelementptr inbounds i8, i8* %18, i64 1
store i8 92, i8* %18
%25 = getelementptr inbounds i8, i8* %18, i64 2
store i8 34, i8* %24
br label %31
26: ; preds = %21
%27 = getelementptr inbounds i8, i8* %18, i64 1
store i8 92, i8* %18
%28 = getelementptr inbounds i8, i8* %18, i64 2
store i8 110, i8* %27
br label %31
29: ; preds = %21
%30 = getelementptr inbounds i8, i8* %18, i64 1
store i8 %22, i8* %18
br label %31
31: ; preds = %29, %26, %23
%32 = phi i8* [ %28, %26 ], [ %25, %23 ], [ %30, %29 ]
%33 = add nuw nsw i32 %5, 2
%34 = getelementptr inbounds i8, i8* %3, i64 2
br label %2
35: ; preds = %17
%36 = getelementptr inbounds i8, i8* %18, i64 1
store i8 46, i8* %18
%37 = getelementptr inbounds i8, i8* %18, i64 2
store i8 46, i8* %36
%38 = getelementptr inbounds i8, i8* %18, i64 3
store i8 46, i8* %37
br label %39
39: ; preds = %7, %2, %21, %35
%40 = phi i8* [ %38, %35 ], [ %4, %2 ], [ %4, %7 ], [ %18, %21 ]
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8 34, i8* %40
store i8 0, i8* %41
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @DecompileString.buf, i64 0, i64 0)
}