#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 */
int /*<<< orphan*/ isprint(char);
scalar_t__ malloc(int);
int strlen(char *);
char *escape_string(char *s) {
  char *ss = (char *)malloc((strlen(s) + 1) * 4), *sss = ss;
  for (; *s; s++) {
    switch (*s) {
    case '\b':
      *ss++ = '\\';
      *ss++ = 'b';
      break;
      ;
    case '\f':
      *ss++ = '\\';
      *ss++ = 'f';
      break;
      ;
    case '\n':
      *ss++ = '\\';
      *ss++ = 'n';
      break;
      ;
    case '\r':
      *ss++ = '\\';
      *ss++ = 'r';
      break;
      ;
    case '\t':
      *ss++ = '\\';
      *ss++ = 't';
      break;
      ;
    case '\v':
      *ss++ = '\\';
      *ss++ = 'v';
      break;
      ;
    case '\a':
      *ss++ = '\\';
      *ss++ = 'a';
      break;
      ;
    case '\\':
    case '\"':
      *ss++ = '\\';
      *ss++ = *s;
      break;
    default:
      if (isprint(*s)) {
        *ss++ = *s;
      } else {
        *ss++ = '\\';
        *ss++ = 'x';
        *ss++ = ((((*s) >> 4) > 9) ? (((*s) >> 4) - 10 + 'A')
                                   : (((*s) >> 4) + '0'));
        *ss++ = ((((*s) & 15) > 9) ? (((*s) & 15) - 10 + 'A')
                                   : (((*s) & 15) + '0'));
      }
      break;
    }
  }
  *ss = 0;
  return sss;
}


x86 assembly (clang, -O0):
<escape_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     13f7 <escape_string+0x2c7>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xfffffff9,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x55,%eax
ja     12e5 <escape_string+0x1b5>
mov    -0x20(%rbp),%rax
lea    0xe71(%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   $0x62,(%rax)
jmp    13e1 <escape_string+0x2b1>
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    13e1 <escape_string+0x2b1>
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    13e1 <escape_string+0x2b1>
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    13e1 <escape_string+0x2b1>
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    13e1 <escape_string+0x2b1>
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    13e1 <escape_string+0x2b1>
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    13e1 <escape_string+0x2b1>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    13e1 <escape_string+0x2b1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isprint@plt>
cmp    $0x0,%eax
je     1316 <escape_string+0x1e6>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    13dc <escape_string+0x2ac>
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   $0x78,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sar    $0x4,%eax
cmp    $0x9,%eax
jle    1365 <escape_string+0x235>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sar    $0x4,%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %eax,-0x24(%rbp)
jmp    1375 <escape_string+0x245>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sar    $0x4,%eax
add    $0x30,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0xf,%eax
cmp    $0x9,%eax
jle    13b6 <escape_string+0x286>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0xf,%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %eax,-0x28(%rbp)
jmp    13c6 <escape_string+0x296>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0xf,%eax
add    $0x30,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    13e1 <escape_string+0x2b1>
jmp    13e6 <escape_string+0x2b6>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    115e <escape_string+0x2e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x4(,%rax,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%al
test   %al,%al
je     1225 <escape_string+0xf5>
lea    0xea0(%rip),%r12
mov    %r14,%r15
jmp    118f <escape_string+0x5f>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x5c,(%r15)
movzbl (%rbx),%eax
mov    %al,0x1(%r15)
add    $0x2,%r15
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1228 <escape_string+0xf8>
movsbl %al,%edi
lea    -0x7(%rdi),%eax
cmp    $0x55,%eax
ja     11db <escape_string+0xab>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
movw   $0x615c,(%r15)
jmp    117b <escape_string+0x4b>
movw   $0x625c,(%r15)
jmp    117b <escape_string+0x4b>
movw   $0x745c,(%r15)
jmp    117b <escape_string+0x4b>
movw   $0x6e5c,(%r15)
jmp    117b <escape_string+0x4b>
movw   $0x765c,(%r15)
jmp    117b <escape_string+0x4b>
movw   $0x665c,(%r15)
jmp    117b <escape_string+0x4b>
movw   $0x725c,(%r15)
jmp    117b <escape_string+0x4b>
call   1050 <isprint@plt>
test   %eax,%eax
je     11f0 <escape_string+0xc0>
movzbl (%rbx),%eax
mov    %al,(%r15)
add    $0x1,%r15
jmp    117f <escape_string+0x4f>
movw   $0x785c,(%r15)
movzbl (%rbx),%eax
sar    $0x4,%al
add    $0x30,%al
mov    %al,0x2(%r15)
movzbl (%rbx),%eax
and    $0xf,%al
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%al
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
mov    %cl,0x3(%r15)
add    $0x4,%r15
jmp    117f <escape_string+0x4f>
mov    %r14,%r15
movb   $0x0,(%r15)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @escape_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 1
%8 = mul nsw i32 %7, 4
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %3
%11 = load i8*, i8** %3
store i8* %11, i8** %4
br label %12
12: ; preds = %125, %1
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %128
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
switch i32 %19, label %62 [
i32 8, label %20
i32 12, label %25
i32 10, label %30
i32 13, label %35
i32 9, label %40
i32 11, label %45
i32 7, label %50
i32 92, label %55
i32 34, label %55
]
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
store i8 92, i8* %21
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
store i8 98, i8* %23
br label %124
25: ; preds = %16
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
store i8 92, i8* %26
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
store i8 102, i8* %28
br label %124
30: ; preds = %16
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %3
store i8 92, i8* %31
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
store i8 110, i8* %33
br label %124
35: ; preds = %16
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
store i8 92, i8* %36
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %3
store i8 114, i8* %38
br label %124
40: ; preds = %16
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %3
store i8 92, i8* %41
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %3
store i8 116, i8* %43
br label %124
45: ; preds = %16
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %3
store i8 92, i8* %46
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %3
store i8 118, i8* %48
br label %124
50: ; preds = %16
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %3
store i8 92, i8* %51
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %3
store i8 97, i8* %53
br label %124
55: ; preds = %16, %16
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %3
store i8 92, i8* %56
%58 = load i8*, i8** %2
%59 = load i8, i8* %58
%60 = load i8*, i8** %3
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %3
store i8 %59, i8* %60
br label %124
62: ; preds = %16
%63 = load i8*, i8** %2
%64 = load i8, i8* %63
%65 = call i32 @isprint(i8 signext %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %62
%68 = load i8*, i8** %2
%69 = load i8, i8* %68
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %3
store i8 %69, i8* %70
br label %123
72: ; preds = %62
%73 = load i8*, i8** %3
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %3
store i8 92, i8* %73
%75 = load i8*, i8** %3
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %3
store i8 120, i8* %75
%77 = load i8*, i8** %2
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = ashr i32 %79, 4
%81 = icmp sgt i32 %80, 9
br i1 %81, label %82, label %89
82: ; preds = %72
%83 = load i8*, i8** %2
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = ashr i32 %85, 4
%87 = sub nsw i32 %86, 10
%88 = add nsw i32 %87, 65
br label %95
89: ; preds = %72
%90 = load i8*, i8** %2
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = ashr i32 %92, 4
%94 = add nsw i32 %93, 48
br label %95
95: ; preds = %89, %82
%96 = phi i32 [ %88, %82 ], [ %94, %89 ]
%97 = trunc i32 %96 to i8
%98 = load i8*, i8** %3
%99 = getelementptr inbounds i8, i8* %98, i32 1
store i8* %99, i8** %3
store i8 %97, i8* %98
%100 = load i8*, i8** %2
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = and i32 %102, 15
%104 = icmp sgt i32 %103, 9
br i1 %104, label %105, label %112
105: ; preds = %95
%106 = load i8*, i8** %2
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
%109 = and i32 %108, 15
%110 = sub nsw i32 %109, 10
%111 = add nsw i32 %110, 65
br label %118
112: ; preds = %95
%113 = load i8*, i8** %2
%114 = load i8, i8* %113
%115 = sext i8 %114 to i32
%116 = and i32 %115, 15
%117 = add nsw i32 %116, 48
br label %118
118: ; preds = %112, %105
%119 = phi i32 [ %111, %105 ], [ %117, %112 ]
%120 = trunc i32 %119 to i8
%121 = load i8*, i8** %3
%122 = getelementptr inbounds i8, i8* %121, i32 1
store i8* %122, i8** %3
store i8 %120, i8* %121
br label %123
123: ; preds = %118, %67
br label %124
124: ; preds = %123, %55, %50, %45, %40, %35, %30, %25, %20
br label %125
125: ; preds = %124
%126 = load i8*, i8** %2
%127 = getelementptr inbounds i8, i8* %126, i32 1
store i8* %127, i8** %2
br label %12
128: ; preds = %12
%129 = load i8*, i8** %3
store i8 0, i8* %129
%130 = load i8*, i8** %4
ret i8* %130
}

LLVM IR (-O2):
define i8* @escape_string(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl i32 %2, 2
%4 = add i32 %3, 4
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %64, label %9
9: ; preds = %1, %59
%10 = phi i8 [ %62, %59 ], [ %7, %1 ]
%11 = phi i8* [ %61, %59 ], [ %0, %1 ]
%12 = phi i8* [ %60, %59 ], [ %6, %1 ]
%13 = sext i8 %10 to i32
switch i32 %13, label %39 [
i32 8, label %14
i32 12, label %17
i32 10, label %20
i32 13, label %23
i32 9, label %26
i32 11, label %29
i32 7, label %32
i32 92, label %35
i32 34, label %35
]
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%16 = getelementptr inbounds i8, i8* %12, i64 2
store i8 98, i8* %15
br label %59
17: ; preds = %9
%18 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%19 = getelementptr inbounds i8, i8* %12, i64 2
store i8 102, i8* %18
br label %59
20: ; preds = %9
%21 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%22 = getelementptr inbounds i8, i8* %12, i64 2
store i8 110, i8* %21
br label %59
23: ; preds = %9
%24 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%25 = getelementptr inbounds i8, i8* %12, i64 2
store i8 114, i8* %24
br label %59
26: ; preds = %9
%27 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%28 = getelementptr inbounds i8, i8* %12, i64 2
store i8 116, i8* %27
br label %59
29: ; preds = %9
%30 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%31 = getelementptr inbounds i8, i8* %12, i64 2
store i8 118, i8* %30
br label %59
32: ; preds = %9
%33 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%34 = getelementptr inbounds i8, i8* %12, i64 2
store i8 97, i8* %33
br label %59
35: ; preds = %9, %9
%36 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%37 = load i8, i8* %11
%38 = getelementptr inbounds i8, i8* %12, i64 2
store i8 %37, i8* %36
br label %59
39: ; preds = %9
%40 = tail call i32 @isprint(i8 signext %10)
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i8, i8* %11
%44 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %43, i8* %12
br label %59
45: ; preds = %39
%46 = getelementptr inbounds i8, i8* %12, i64 1
store i8 92, i8* %12
%47 = getelementptr inbounds i8, i8* %12, i64 2
store i8 120, i8* %46
%48 = load i8, i8* %11
%49 = ashr i8 %48, 4
%50 = add nsw i8 %49, 48
%51 = getelementptr inbounds i8, i8* %12, i64 3
store i8 %50, i8* %47
%52 = load i8, i8* %11
%53 = and i8 %52, 15
%54 = icmp ugt i8 %53, 9
%55 = add nuw nsw i8 %53, 55
%56 = or i8 %53, 48
%57 = select i1 %54, i8 %55, i8 %56
%58 = getelementptr inbounds i8, i8* %12, i64 4
store i8 %57, i8* %51
br label %59
59: ; preds = %14, %17, %20, %23, %26, %29, %32, %35, %45, %42
%60 = phi i8* [ %44, %42 ], [ %58, %45 ], [ %38, %35 ], [ %34, %32 ], [ %31, %29 ], [ %28, %26 ], [ %25, %23 ], [ %22, %20 ], [ %19, %17 ], [ %16, %14 ]
%61 = getelementptr inbounds i8, i8* %11, i64 1
%62 = load i8, i8* %61
%63 = icmp eq i8 %62, 0
br i1 %63, label %64, label %9
64: ; preds = %59, %1
%65 = phi i8* [ %6, %1 ], [ %60, %59 ]
store i8 0, i8* %65
ret i8* %6
}