#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char *malloc(size_t);
char *strescape(const char *s) {
  size_t len = 0;
  char *ret;
  char *q;
  for (const char *p = s; p[0]; p++)
    switch (p[0]) {
    case '\b':
    case '\n':
    case '\r':
    case '\x1b':
    case '\\':
      len += 2;
      break;
    default:
      len += 1;
    }
  ret = malloc(len + 1);
  q = ret;
  for (const char *p = s; p[0]; p++)
    switch (p[0]) {
    case '\b':
      q[0] = '\\';
      q[1] = 'b';
      q += 2;
      break;
    case '\n':
      q[0] = '\\';
      q[1] = 'n';
      q += 2;
      break;
    case '\r':
      q[0] = '\\';
      q[1] = 'r';
      q += 2;
      break;
    case '\x1b':
      q[0] = '\\';
      q[1] = 'e';
      q += 2;
      break;
    case '\\':
      q[0] = '\\';
      q[1] = '\\';
      q += 2;
      break;
    default:
      q[0] = p[0];
      q += 1;
      break;
    }
  q[0] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<strescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c8 <strescape+0xb8>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x34(%rbp)
sub    $0x8,%eax
je     1195 <strescape+0x85>
jmp    1151 <strescape+0x41>
mov    -0x34(%rbp),%eax
sub    $0xa,%eax
je     1195 <strescape+0x85>
jmp    1162 <strescape+0x52>
mov    -0x34(%rbp),%eax
sub    $0xd,%eax
je     1195 <strescape+0x85>
jmp    1173 <strescape+0x63>
mov    -0x34(%rbp),%eax
sub    $0x1b,%eax
je     1195 <strescape+0x85>
jmp    1184 <strescape+0x74>
mov    -0x34(%rbp),%eax
sub    $0x5c,%eax
jne    11a6 <strescape+0x96>
jmp    1195 <strescape+0x85>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    11b2 <strescape+0xa2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <strescape+0xa7>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    112c <strescape+0x1c>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     1320 <strescape+0x210>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x38(%rbp)
sub    $0x8,%eax
je     1252 <strescape+0x142>
jmp    120e <strescape+0xfe>
mov    -0x38(%rbp),%eax
sub    $0xa,%eax
je     1272 <strescape+0x162>
jmp    121f <strescape+0x10f>
mov    -0x38(%rbp),%eax
sub    $0xd,%eax
je     1292 <strescape+0x182>
jmp    1230 <strescape+0x120>
mov    -0x38(%rbp),%eax
sub    $0x1b,%eax
je     12b2 <strescape+0x1a2>
jmp    1241 <strescape+0x131>
mov    -0x38(%rbp),%eax
sub    $0x5c,%eax
je     12d2 <strescape+0x1c2>
jmp    12f2 <strescape+0x1e2>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x62,0x1(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    130a <strescape+0x1fa>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x6e,0x1(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    130a <strescape+0x1fa>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x72,0x1(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    130a <strescape+0x1fa>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x65,0x1(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    130a <strescape+0x1fa>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x5c,0x1(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    130a <strescape+0x1fa>
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    130f <strescape+0x1ff>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11e9 <strescape+0xd9>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strescape>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%bpl
test   %bpl,%bpl
je     1205 <strescape+0xf5>
mov    %rdi,%rbx
lea    0x1(%rdi),%rax
xor    %edi,%edi
mov    $0x8002500,%ecx
mov    %ebp,%edx
jmp    1153 <strescape+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
bt     %esi,%ecx
jae    1160 <strescape+0x50>
add    %rdx,%rdi
movzbl (%rax),%edx
add    $0x1,%rax
test   %dl,%dl
je     116c <strescape+0x5c>
movsbl %dl,%esi
mov    $0x2,%edx
cmp    $0x1b,%esi
jbe    1140 <strescape+0x30>
cmp    $0x5c,%esi
je     1145 <strescape+0x35>
mov    $0x1,%edx
jmp    1145 <strescape+0x35>
add    $0x1,%rdi
call   1030 <malloc@plt>
test   %bpl,%bpl
je     120f <strescape+0xff>
add    $0x1,%rbx
lea    0xe77(%rip),%rdx
mov    %rax,%rcx
jmp    11af <strescape+0x9f>
mov    %bpl,(%rcx)
mov    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
add    %rsi,%rcx
movzbl (%rbx),%ebp
add    $0x1,%rbx
test   %bpl,%bpl
je     1212 <strescape+0x102>
movsbl %bpl,%esi
lea    -0x8(%rsi),%edi
cmp    $0x13,%edi
ja     11d0 <strescape+0xc0>
movslq (%rdx,%rdi,4),%rsi
add    %rdx,%rsi
jmp    *%rsi
movw   $0x625c,(%rcx)
mov    $0x2,%esi
jmp    11a0 <strescape+0x90>
cmp    $0x5c,%esi
jne    118e <strescape+0x7e>
movw   $0x5c5c,(%rcx)
mov    $0x2,%esi
jmp    11a0 <strescape+0x90>
movw   $0x6e5c,(%rcx)
mov    $0x2,%esi
jmp    11a0 <strescape+0x90>
movw   $0x725c,(%rcx)
mov    $0x2,%esi
jmp    11a0 <strescape+0x90>
movw   $0x655c,(%rcx)
mov    $0x2,%esi
jmp    11a0 <strescape+0x90>
mov    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
movb   $0x0,(%rcx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @strescape(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = tail call dereferenceable_or_null(1) i8* @malloc(i64 1)
br label %21
6: ; preds = %15
%7 = add i64 %17, 1
%8 = tail call i8* @malloc(i64 %7)
br i1 %3, label %21, label %24
9: ; preds = %1, %15
%10 = phi i8 [ %19, %15 ], [ %2, %1 ]
%11 = phi i8* [ %18, %15 ], [ %0, %1 ]
%12 = phi i64 [ %17, %15 ], [ 0, %1 ]
%13 = sext i8 %10 to i32
switch i32 %13, label %14 [
i32 8, label %15
i32 10, label %15
i32 13, label %15
i32 27, label %15
i32 92, label %15
]
14: ; preds = %9
br label %15
15: ; preds = %9, %9, %9, %9, %9, %14
%16 = phi i64 [ 1, %14 ], [ 2, %9 ], [ 2, %9 ], [ 2, %9 ], [ 2, %9 ], [ 2, %9 ]
%17 = add i64 %12, %16
%18 = getelementptr inbounds i8, i8* %11, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %6, label %9
21: ; preds = %40, %4, %6
%22 = phi i8* [ %8, %6 ], [ %5, %4 ], [ %8, %40 ]
%23 = phi i8* [ %8, %6 ], [ %5, %4 ], [ %42, %40 ]
store i8 0, i8* %23
ret i8* %22
24: ; preds = %6, %40
%25 = phi i8 [ %44, %40 ], [ %2, %6 ]
%26 = phi i8* [ %43, %40 ], [ %0, %6 ]
%27 = phi i8* [ %42, %40 ], [ %8, %6 ]
%28 = sext i8 %25 to i32
switch i32 %28, label %39 [
i32 8, label %29
i32 10, label %31
i32 13, label %33
i32 27, label %35
i32 92, label %37
]
29: ; preds = %24
store i8 92, i8* %27
%30 = getelementptr inbounds i8, i8* %27, i64 1
store i8 98, i8* %30
br label %40
31: ; preds = %24
store i8 92, i8* %27
%32 = getelementptr inbounds i8, i8* %27, i64 1
store i8 110, i8* %32
br label %40
33: ; preds = %24
store i8 92, i8* %27
%34 = getelementptr inbounds i8, i8* %27, i64 1
store i8 114, i8* %34
br label %40
35: ; preds = %24
store i8 92, i8* %27
%36 = getelementptr inbounds i8, i8* %27, i64 1
store i8 101, i8* %36
br label %40
37: ; preds = %24
store i8 92, i8* %27
%38 = getelementptr inbounds i8, i8* %27, i64 1
store i8 92, i8* %38
br label %40
39: ; preds = %24
store i8 %25, i8* %27
br label %40
40: ; preds = %29, %31, %33, %35, %37, %39
%41 = phi i64 [ 2, %29 ], [ 2, %31 ], [ 2, %33 ], [ 2, %35 ], [ 2, %37 ], [ 1, %39 ]
%42 = getelementptr inbounds i8, i8* %27, i64 %41
%43 = getelementptr inbounds i8, i8* %26, i64 1
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 0
br i1 %45, label %21, label %24
}