#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 */
typedef int uint32_t;
typedef int /*<<< orphan*/ iconv_t;

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ iconv_close(int /*<<< orphan*/);
int /*<<< orphan*/ iscntrl(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ string_do_convert(char const *, int /*<<< orphan*/);
size_t strlen(char const *);
int /*<<< orphan*/ xiconv_open(char *, char *);
char *xmalloc(int);
char *xrealloc(char *, size_t);
char *string_escape(const char *in) {
  uint32_t *expanded_buf;
  size_t chars = strlen(in);
  iconv_t ic = xiconv_open("UTF-32", "UTF-8");
  char *ret;
  char *pos;
  size_t i;
  expanded_buf = (uint32_t *)string_do_convert(in, ic);
  iconv_close(ic);
  ret = xmalloc(6 * chars + 1);
  pos = ret;
  for (i = 1; i < chars + 1; i++) {
    if (expanded_buf[i] & 0xffffff80) {
      pos += sprintf(pos, "\\u%04x", expanded_buf[i]);
      continue;
    }
    if (!expanded_buf[i]) {
      chars = i;
      break;
    }
    switch (expanded_buf[i]) {
    case '\"':
      pos += sprintf(pos, "\\\"");
      break;
    case '\\':
      pos += sprintf(pos, "\\\\");
      break;
    case '/':
      pos += sprintf(pos, "\\/");
      break;
    case '\b':
      pos += sprintf(pos, "\\b");
      break;
    case '\f':
      pos += sprintf(pos, "\\f");
      break;
    case '\n':
      pos += sprintf(pos, "\\n");
      break;
    case '\r':
      pos += sprintf(pos, "\\r");
      break;
    case '\t':
      pos += sprintf(pos, "\\t");
      break;
    case '\v':
      pos += sprintf(pos, "\\v");
      break;
    default:
      if (iscntrl(expanded_buf[i]))
        pos += sprintf(pos, "\\u%04x", expanded_buf[i]);
      else
        pos += sprintf(pos, "%c", (char)expanded_buf[i]);
    };
  }
  *pos = '\0';
  free(expanded_buf);
  return xrealloc(ret, strlen(ret) + 1);
}


x86 assembly (clang, -O0):
<string_escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    0xfa4(%rip),%rdi
lea    0xfa4(%rip),%rsi
call   1090 <xiconv_open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10b0 <string_do_convert@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <iconv_close@plt>
imul   $0x6,-0x18(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jae    149e <string_escape+0x30e>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xffffff80,%eax
cmp    $0x0,%eax
je     1259 <string_escape+0xc9>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xf24(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    148d <string_escape+0x2fd>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1278 <string_escape+0xe8>
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    149e <string_escape+0x30e>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    $0xfffffff8,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x54,%eax
ja     1408 <string_escape+0x278>
mov    -0x40(%rbp),%rax
lea    0xd60(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x30(%rbp),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x30(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x30(%rbp),%rdi
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x30(%rbp),%rdi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x30(%rbp),%rdi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x30(%rbp),%rdi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x30(%rbp),%rdi
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x30(%rbp),%rdi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x30(%rbp),%rdi
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <iscntrl@plt>
cmp    $0x0,%eax
je     1453 <string_escape+0x2c3>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1483 <string_escape+0x2f3>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
movsbl %al,%edx
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1488 <string_escape+0x2f8>
jmp    148d <string_escape+0x2fd>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11fb <string_escape+0x6b>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1060 <xrealloc@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_escape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %rax,%r12
lea    0xfc7(%rip),%rdi
lea    0xfc7(%rip),%rsi
call   1090 <xiconv_open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <string_do_convert@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1080 <iconv_close@plt>
lea    (%r12,%r12,1),%eax
lea    (%rax,%rax,2),%edi
or     $0x1,%edi
call   1070 <xmalloc@plt>
mov    %rax,%rbx
lea    -0x1(%r12),%rax
mov    %rbx,(%rsp)
cmp    $0xfffffffffffffffd,%rax
ja     1305 <string_escape+0x175>
lea    0xe05(%rip),%r15
xor    %r13d,%r13d
mov    (%rsp),%rbx
jmp    1245 <string_escape+0xb5>
mov    %ebp,%edi
call   1040 <iscntrl@plt>
test   %eax,%eax
je     12f5 <string_escape+0x165>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
lea    0xf57(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <sprintf@plt>
cltq
add    %rax,%rbx
add    $0x1,%r13
cmp    %r13,%r12
je     1305 <string_escape+0x175>
mov    0x4(%r14,%r13,4),%ebp
cmp    $0x80,%ebp
jae    1220 <string_escape+0x90>
cmp    $0x5c,%ebp
ja     1204 <string_escape+0x74>
mov    %ebp,%eax
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
movb   $0x0,0x2(%rbx)
movw   $0x625c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,0x2(%rbx)
movw   $0x745c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,0x2(%rbx)
movw   $0x6e5c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,0x2(%rbx)
movw   $0x765c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,0x2(%rbx)
movw   $0x665c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,0x2(%rbx)
movw   $0x725c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,0x2(%rbx)
movw   $0x225c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,0x2(%rbx)
movw   $0x2f5c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,0x2(%rbx)
movw   $0x5c5c,(%rbx)
add    $0x2,%rbx
jmp    1238 <string_escape+0xa8>
mov    %bpl,(%rbx)
movb   $0x0,0x1(%rbx)
add    $0x1,%rbx
jmp    1238 <string_escape+0xa8>
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <xrealloc@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"UTF-32\00"
@.str.1 = [6 x i8] c"UTF-8\00"
@.str.2 = [7 x i8] c"\\u%04x\00"
@.str.3 = [3 x i8] c"\\\22\00"
@.str.4 = [3 x i8] c"\\\\\00"
@.str.5 = [3 x i8] c"\\/\00"
@.str.6 = [3 x i8] c"\\b\00"
@.str.7 = [3 x i8] c"\\f\00"
@.str.8 = [3 x i8] c"\\n\00"
@.str.9 = [3 x i8] c"\\r\00"
@.str.10 = [3 x i8] c"\\t\00"
@.str.11 = [3 x i8] c"\\v\00"
@.str.12 = [3 x i8] c"%c\00"
define i8* @string_escape(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %4
%11 = call i32 @xiconv_open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %5
%12 = load i8*, i8** %2
%13 = load i32, i32* %5
%14 = call i64 @string_do_convert(i8* %12, i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %3
%16 = load i32, i32* %5
%17 = call i32 @iconv_close(i32 %16)
%18 = load i64, i64* %4
%19 = mul i64 6, %18
%20 = add i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i8* @xmalloc(i32 %21)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
store i8* %23, i8** %7
store i64 1, i64* %8
br label %24
24: ; preds = %144, %1
%25 = load i64, i64* %8
%26 = load i64, i64* %4
%27 = add i64 %26, 1
%28 = icmp ult i64 %25, %27
br i1 %28, label %29, label %147
29: ; preds = %24
%30 = load i32*, i32** %3
%31 = load i64, i64* %8
%32 = getelementptr inbounds i32, i32* %30, i64 %31
%33 = load i32, i32* %32
%34 = and i32 %33, -128
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %29
%37 = load i8*, i8** %7
%38 = load i32*, i32** %3
%39 = load i64, i64* %8
%40 = getelementptr inbounds i32, i32* %38, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i8*, i8** %7
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8* %45, i8** %7
br label %144
46: ; preds = %29
%47 = load i32*, i32** %3
%48 = load i64, i64* %8
%49 = getelementptr inbounds i32, i32* %47, i64 %48
%50 = load i32, i32* %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %46
%53 = load i64, i64* %8
store i64 %53, i64* %4
br label %147
54: ; preds = %46
%55 = load i32*, i32** %3
%56 = load i64, i64* %8
%57 = getelementptr inbounds i32, i32* %55, i64 %56
%58 = load i32, i32* %57
switch i32 %58, label %113 [
i32 34, label %59
i32 92, label %65
i32 47, label %71
i32 8, label %77
i32 12, label %83
i32 10, label %89
i32 13, label %95
i32 9, label %101
i32 11, label %107
]
59: ; preds = %54
%60 = load i8*, i8** %7
%61 = call i32 (i8*, i8*, ...) @sprintf(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%62 = load i8*, i8** %7
%63 = sext i32 %61 to i64
%64 = getelementptr inbounds i8, i8* %62, i64 %63
store i8* %64, i8** %7
br label %143
65: ; preds = %54
%66 = load i8*, i8** %7
%67 = call i32 (i8*, i8*, ...) @sprintf(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%68 = load i8*, i8** %7
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds i8, i8* %68, i64 %69
store i8* %70, i8** %7
br label %143
71: ; preds = %54
%72 = load i8*, i8** %7
%73 = call i32 (i8*, i8*, ...) @sprintf(i8* %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%74 = load i8*, i8** %7
%75 = sext i32 %73 to i64
%76 = getelementptr inbounds i8, i8* %74, i64 %75
store i8* %76, i8** %7
br label %143
77: ; preds = %54
%78 = load i8*, i8** %7
%79 = call i32 (i8*, i8*, ...) @sprintf(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%80 = load i8*, i8** %7
%81 = sext i32 %79 to i64
%82 = getelementptr inbounds i8, i8* %80, i64 %81
store i8* %82, i8** %7
br label %143
83: ; preds = %54
%84 = load i8*, i8** %7
%85 = call i32 (i8*, i8*, ...) @sprintf(i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%86 = load i8*, i8** %7
%87 = sext i32 %85 to i64
%88 = getelementptr inbounds i8, i8* %86, i64 %87
store i8* %88, i8** %7
br label %143
89: ; preds = %54
%90 = load i8*, i8** %7
%91 = call i32 (i8*, i8*, ...) @sprintf(i8* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%92 = load i8*, i8** %7
%93 = sext i32 %91 to i64
%94 = getelementptr inbounds i8, i8* %92, i64 %93
store i8* %94, i8** %7
br label %143
95: ; preds = %54
%96 = load i8*, i8** %7
%97 = call i32 (i8*, i8*, ...) @sprintf(i8* %96, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%98 = load i8*, i8** %7
%99 = sext i32 %97 to i64
%100 = getelementptr inbounds i8, i8* %98, i64 %99
store i8* %100, i8** %7
br label %143
101: ; preds = %54
%102 = load i8*, i8** %7
%103 = call i32 (i8*, i8*, ...) @sprintf(i8* %102, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%104 = load i8*, i8** %7
%105 = sext i32 %103 to i64
%106 = getelementptr inbounds i8, i8* %104, i64 %105
store i8* %106, i8** %7
br label %143
107: ; preds = %54
%108 = load i8*, i8** %7
%109 = call i32 (i8*, i8*, ...) @sprintf(i8* %108, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%110 = load i8*, i8** %7
%111 = sext i32 %109 to i64
%112 = getelementptr inbounds i8, i8* %110, i64 %111
store i8* %112, i8** %7
br label %143
113: ; preds = %54
%114 = load i32*, i32** %3
%115 = load i64, i64* %8
%116 = getelementptr inbounds i32, i32* %114, i64 %115
%117 = load i32, i32* %116
%118 = call i32 @iscntrl(i32 %117)
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %130
120: ; preds = %113
%121 = load i8*, i8** %7
%122 = load i32*, i32** %3
%123 = load i64, i64* %8
%124 = getelementptr inbounds i32, i32* %122, i64 %123
%125 = load i32, i32* %124
%126 = call i32 (i8*, i8*, ...) @sprintf(i8* %121, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %125)
%127 = load i8*, i8** %7
%128 = sext i32 %126 to i64
%129 = getelementptr inbounds i8, i8* %127, i64 %128
store i8* %129, i8** %7
br label %142
130: ; preds = %113
%131 = load i8*, i8** %7
%132 = load i32*, i32** %3
%133 = load i64, i64* %8
%134 = getelementptr inbounds i32, i32* %132, i64 %133
%135 = load i32, i32* %134
%136 = trunc i32 %135 to i8
%137 = sext i8 %136 to i32
%138 = call i32 (i8*, i8*, ...) @sprintf(i8* %131, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 %137)
%139 = load i8*, i8** %7
%140 = sext i32 %138 to i64
%141 = getelementptr inbounds i8, i8* %139, i64 %140
store i8* %141, i8** %7
br label %142
142: ; preds = %130, %120
br label %143
143: ; preds = %142, %107, %101, %95, %89, %83, %77, %71, %65, %59
br label %144
144: ; preds = %143, %36
%145 = load i64, i64* %8
%146 = add i64 %145, 1
store i64 %146, i64* %8
br label %24
147: ; preds = %52, %24
%148 = load i8*, i8** %7
store i8 0, i8* %148
%149 = load i32*, i32** %3
%150 = call i32 @free(i32* %149)
%151 = load i8*, i8** %6
%152 = load i8*, i8** %6
%153 = call i64 @strlen(i8* %152)
%154 = add i64 %153, 1
%155 = call i8* @xrealloc(i8* %151, i64 %154)
ret i8* %155
}

LLVM IR (-O2):
@.str = [7 x i8] c"UTF-32\00"
@.str.1 = [6 x i8] c"UTF-8\00"
@.str.2 = [7 x i8] c"\\u%04x\00"
@.str.3 = [3 x i8] c"\\\22\00"
@.str.4 = [3 x i8] c"\\\\\00"
@.str.5 = [3 x i8] c"\\/\00"
@.str.6 = [3 x i8] c"\\b\00"
@.str.7 = [3 x i8] c"\\f\00"
@.str.8 = [3 x i8] c"\\n\00"
@.str.9 = [3 x i8] c"\\r\00"
@.str.10 = [3 x i8] c"\\t\00"
@.str.11 = [3 x i8] c"\\v\00"
define i8* @string_escape(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i32 @xiconv_open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i64 @string_do_convert(i8* %0, i32 %3)
%5 = inttoptr i64 %4 to i32*
%6 = tail call i32 @iconv_close(i32 %3)
%7 = trunc i64 %2 to i32
%8 = mul i32 %7, 6
%9 = or i32 %8, 1
%10 = tail call i8* @xmalloc(i32 %9)
%11 = add i64 %2, -1
%12 = icmp ult i64 %11, -2
br i1 %12, label %13, label %56
13: ; preds = %1, %52
%14 = phi i64 [ %54, %52 ], [ 1, %1 ]
%15 = phi i8* [ %53, %52 ], [ %10, %1 ]
%16 = getelementptr inbounds i32, i32* %5, i64 %14
%17 = load i32, i32* %16
%18 = icmp ult i32 %17, 128
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %15, i64 %21
br label %52
23: ; preds = %13
switch i32 %17, label %42 [
i32 0, label %56
i32 34, label %24
i32 92, label %26
i32 47, label %28
i32 8, label %30
i32 12, label %32
i32 10, label %34
i32 13, label %36
i32 9, label %38
i32 11, label %40
]
24: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3, i1 false)
%25 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
26: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 3, i1 false)
%27 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
28: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 3, i1 false)
%29 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
30: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 3, i1 false)
%31 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
32: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 3, i1 false)
%33 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
34: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i64 3, i1 false)
%35 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
36: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i64 3, i1 false)
%37 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
38: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64 3, i1 false)
%39 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
40: ; preds = %23
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %15, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i64 3, i1 false)
%41 = getelementptr inbounds i8, i8* %15, i64 2
br label %52
42: ; preds = %23
%43 = tail call i32 @iscntrl(i32 %17)
%44 = icmp eq i32 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %42
%46 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %15, i64 %47
br label %52
49: ; preds = %42
%50 = trunc i32 %17 to i8
store i8 %50, i8* %15
%51 = getelementptr i8, i8* %15, i64 1
store i8 0, i8* %51
br label %52
52: ; preds = %24, %26, %28, %30, %32, %34, %36, %38, %40, %49, %45, %19
%53 = phi i8* [ %22, %19 ], [ %48, %45 ], [ %51, %49 ], [ %41, %40 ], [ %39, %38 ], [ %37, %36 ], [ %35, %34 ], [ %33, %32 ], [ %31, %30 ], [ %29, %28 ], [ %27, %26 ], [ %25, %24 ]
%54 = add nuw i64 %14, 1
%55 = icmp eq i64 %14, %2
br i1 %55, label %56, label %13
56: ; preds = %52, %23, %1
%57 = phi i8* [ %10, %1 ], [ %15, %23 ], [ %53, %52 ]
store i8 0, i8* %57
%58 = tail call i32 @free(i32* %5)
%59 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%60 = add i64 %59, 1
%61 = tail call i8* @xrealloc(i8* %10, i64 %60)
ret i8* %61
}