#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*/ BS2PP_EmitChar(char **, int);
int BS2PP_ParseChar(char **);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *BS2PP_EmitCharString(char *t, char *s) {
  int i;
  if ((*(t - 1) == '\"') || (*(t - 1) == '\''))
    *t++ = ' ';
  *t++ = '\'';
  while (*s) {
    i = BS2PP_ParseChar(&s);
    if ((i < ' ') || (i >= '~')) {
      if (i > 0xFF) {
        sprintf(t, "\\u%04X", i);
        t += 6;
        continue;
      }
      switch (i) {
      case '\r':
        *t++ = '\\';
        *t++ = 'r';
        break;
      case '\n':
        *t++ = '\\';
        *t++ = 'n';
        break;
      case '\t':
        *t++ = '\\';
        *t++ = 't';
        break;
      case '\x1B':
        *t++ = '\\';
        *t++ = 'e';
        break;
      default:
        sprintf(t, "\\x%02X", i);
        t += 4;
        break;
      }
      continue;
    }
    if (i == '\"')
      *t++ = '\\';
    if (i == '\'')
      *t++ = '\\';
    if (i == '\\')
      *t++ = '\\';
    BS2PP_EmitChar(&t, i);
  }
  *t++ = '\'';
  *t = 0;
  return (t);
}


x86 assembly (clang, -O0):
<BS2PP_EmitCharString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x22,%eax
je     1162 <BS2PP_EmitCharString+0x32>
mov    -0x8(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x27,%eax
jne    1174 <BS2PP_EmitCharString+0x44>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x20,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x27,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     133a <BS2PP_EmitCharString+0x20a>
lea    -0x10(%rbp),%rdi
call   1030 <BS2PP_ParseChar@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jl     11b3 <BS2PP_EmitCharString+0x83>
cmpl   $0x7e,-0x14(%rbp)
jl     12d5 <BS2PP_EmitCharString+0x1a5>
cmpl   $0xff,-0x14(%rbp)
jle    11e4 <BS2PP_EmitCharString+0xb4>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe7e(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
jmp    1186 <BS2PP_EmitCharString+0x56>
mov    -0x14(%rbp),%eax
add    $0xfffffff7,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x12,%eax
ja     12b1 <BS2PP_EmitCharString+0x181>
mov    -0x20(%rbp),%rax
lea    0xdfc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x72,(%rax)
jmp    12d0 <BS2PP_EmitCharString+0x1a0>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x6e,(%rax)
jmp    12d0 <BS2PP_EmitCharString+0x1a0>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x74,(%rax)
jmp    12d0 <BS2PP_EmitCharString+0x1a0>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x65,(%rax)
jmp    12d0 <BS2PP_EmitCharString+0x1a0>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd94(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    1186 <BS2PP_EmitCharString+0x56>
cmpl   $0x22,-0x14(%rbp)
jne    12f1 <BS2PP_EmitCharString+0x1c1>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
cmpl   $0x27,-0x14(%rbp)
jne    130d <BS2PP_EmitCharString+0x1dd>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
cmpl   $0x5c,-0x14(%rbp)
jne    1329 <BS2PP_EmitCharString+0x1f9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x14(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1040 <BS2PP_EmitChar@plt>
jmp    1186 <BS2PP_EmitCharString+0x56>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x27,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BS2PP_EmitCharString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,0x8(%rsp)
mov    -0x1(%rdi),%al
cmp    $0x27,%al
je     114d <BS2PP_EmitCharString+0x1d>
cmp    $0x22,%al
jne    1154 <BS2PP_EmitCharString+0x24>
movb   $0x20,(%rdi)
add    $0x1,%rdi
lea    0x1(%rdi),%rax
mov    %rax,(%rsp)
movb   $0x27,(%rdi)
cmpb   $0x0,(%rsi)
je     12b2 <BS2PP_EmitCharString+0x182>
lea    0x8(%rsp),%rbx
lea    0xed8(%rip),%r14
lea    0xed8(%rip),%r15
lea    0xe7e(%rip),%r13
mov    %rsp,%r12
jmp    11b1 <BS2PP_EmitCharString+0x81>
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <sprintf@plt>
addq   $0x6,(%rsp)
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     12ae <BS2PP_EmitCharString+0x17e>
mov    %rbx,%rdi
call   1030 <BS2PP_ParseChar@plt>
lea    -0x7e(%rax),%ecx
cmp    $0xffffffa1,%ecx
ja     1200 <BS2PP_EmitCharString+0xd0>
cmp    $0x100,%eax
jge    1190 <BS2PP_EmitCharString+0x60>
mov    %eax,%ecx
add    $0xfffffff7,%ecx
cmp    $0x12,%ecx
ja     1250 <BS2PP_EmitCharString+0x120>
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x5c,(%rax)
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x74,(%rax)
jmp    11a3 <BS2PP_EmitCharString+0x73>
nopl   0x0(%rax)
cmp    $0x5c,%eax
je     120f <BS2PP_EmitCharString+0xdf>
cmp    $0x27,%eax
je     120f <BS2PP_EmitCharString+0xdf>
cmp    $0x22,%eax
jne    121e <BS2PP_EmitCharString+0xee>
mov    (%rsp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rsp)
movb   $0x5c,(%rcx)
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <BS2PP_EmitChar@plt>
jmp    11a3 <BS2PP_EmitCharString+0x73>
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x5c,(%rax)
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x6e,(%rax)
jmp    11a3 <BS2PP_EmitCharString+0x73>
mov    (%rsp),%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <sprintf@plt>
addq   $0x4,(%rsp)
jmp    11a3 <BS2PP_EmitCharString+0x73>
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x5c,(%rax)
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x72,(%rax)
jmp    11a3 <BS2PP_EmitCharString+0x73>
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x5c,(%rax)
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x65,(%rax)
jmp    11a3 <BS2PP_EmitCharString+0x73>
mov    (%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsp)
movb   $0x27,(%rax)
mov    (%rsp),%rax
movb   $0x0,(%rax)
mov    (%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\\u%04X\00"
@.str.1 = [7 x i8] c"\\x%02X\00"
define i8* @BS2PP_EmitCharString(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 34
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 39
br i1 %16, label %17, label %20
17: ; preds = %11, %2
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
store i8 32, i8* %18
br label %20
20: ; preds = %17, %11
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
store i8 39, i8* %21
br label %23
23: ; preds = %90, %71, %37, %20
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %93
27: ; preds = %23
%28 = call i32 @BS2PP_ParseChar(i8** %4)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = icmp slt i32 %29, 32
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i32, i32* %5
%33 = icmp sge i32 %32, 126
br i1 %33, label %34, label %72
34: ; preds = %31, %27
%35 = load i32, i32* %5
%36 = icmp sgt i32 %35, 255
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i8*, i8** %3
%39 = load i32, i32* %5
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 6
store i8* %42, i8** %3
br label %23
43: ; preds = %34
%44 = load i32, i32* %5
switch i32 %44, label %65 [
i32 13, label %45
i32 10, label %50
i32 9, label %55
i32 27, label %60
]
45: ; preds = %43
%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 114, i8* %48
br label %71
50: ; preds = %43
%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 110, i8* %53
br label %71
55: ; preds = %43
%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** %3
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %3
store i8 116, i8* %58
br label %71
60: ; preds = %43
%61 = load i8*, i8** %3
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %3
store i8 92, i8* %61
%63 = load i8*, i8** %3
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %3
store i8 101, i8* %63
br label %71
65: ; preds = %43
%66 = load i8*, i8** %3
%67 = load i32, i32* %5
%68 = call i32 @sprintf(i8* %66, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %67)
%69 = load i8*, i8** %3
%70 = getelementptr inbounds i8, i8* %69, i64 4
store i8* %70, i8** %3
br label %71
71: ; preds = %65, %60, %55, %50, %45
br label %23
72: ; preds = %31
%73 = load i32, i32* %5
%74 = icmp eq i32 %73, 34
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i8*, i8** %3
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %3
store i8 92, i8* %76
br label %78
78: ; preds = %75, %72
%79 = load i32, i32* %5
%80 = icmp eq i32 %79, 39
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = load i8*, i8** %3
%83 = getelementptr inbounds i8, i8* %82, i32 1
store i8* %83, i8** %3
store i8 92, i8* %82
br label %84
84: ; preds = %81, %78
%85 = load i32, i32* %5
%86 = icmp eq i32 %85, 92
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i8*, i8** %3
%89 = getelementptr inbounds i8, i8* %88, i32 1
store i8* %89, i8** %3
store i8 92, i8* %88
br label %90
90: ; preds = %87, %84
%91 = load i32, i32* %5
%92 = call i32 @BS2PP_EmitChar(i8** %3, i32 %91)
br label %23
93: ; preds = %23
%94 = load i8*, i8** %3
%95 = getelementptr inbounds i8, i8* %94, i32 1
store i8* %95, i8** %3
store i8 39, i8* %94
%96 = load i8*, i8** %3
store i8 0, i8* %96
%97 = load i8*, i8** %3
ret i8* %97
}

LLVM IR (-O2):
@.str = [7 x i8] c"\\u%04X\00"
@.str.1 = [7 x i8] c"\\x%02X\00"
define i8* @BS2PP_EmitCharString(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %1, i8** %4
%5 = getelementptr inbounds i8, i8* %0, i64 -1
%6 = load i8, i8* %5
switch i8 %6, label %9 [
i8 34, label %7
i8 39, label %7
]
7: ; preds = %2, %2
%8 = getelementptr inbounds i8, i8* %0, i64 1
store i8 32, i8* %0
br label %9
9: ; preds = %2, %7
%10 = phi i8* [ %0, %2 ], [ %8, %7 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %11, i8** %3
store i8 39, i8* %10
%12 = load i8, i8* %1
%13 = icmp eq i8 %12, 0
br i1 %13, label %71, label %14
14: ; preds = %9, %25
%15 = call i32 @BS2PP_ParseChar(i8** %4)
%16 = add i32 %15, -126
%17 = icmp ult i32 %16, -94
br i1 %17, label %18, label %55
18: ; preds = %14
%19 = icmp sgt i32 %15, 255
br i1 %19, label %20, label %29
20: ; preds = %18
%21 = load i8*, i8** %3
%22 = call i32 @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %15)
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 6
store i8* %24, i8** %3
br label %25
25: ; preds = %30, %35, %40, %45, %50, %20, %67
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %69, label %14
29: ; preds = %18
switch i32 %15, label %50 [
i32 13, label %30
i32 10, label %35
i32 9, label %40
i32 27, label %45
]
30: ; preds = %29
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %3
store i8 92, i8* %31
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %3
store i8 114, i8* %33
br label %25
35: ; preds = %29
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8* %37, i8** %3
store i8 92, i8* %36
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8* %39, i8** %3
store i8 110, i8* %38
br label %25
40: ; preds = %29
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8* %42, i8** %3
store i8 92, i8* %41
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 1
store i8* %44, i8** %3
store i8 116, i8* %43
br label %25
45: ; preds = %29
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 1
store i8* %47, i8** %3
store i8 92, i8* %46
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 1
store i8* %49, i8** %3
store i8 101, i8* %48
br label %25
50: ; preds = %29
%51 = load i8*, i8** %3
%52 = call i32 @sprintf(i8* dereferenceable(1) %51, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i64 4
store i8* %54, i8** %3
br label %25
55: ; preds = %14
switch i32 %15, label %67 [
i32 34, label %56
i32 39, label %59
i32 92, label %62
]
56: ; preds = %55
%57 = load i8*, i8** %3
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8* %58, i8** %3
br label %65
59: ; preds = %55
%60 = load i8*, i8** %3
%61 = getelementptr inbounds i8, i8* %60, i64 1
store i8* %61, i8** %3
br label %65
62: ; preds = %55
%63 = load i8*, i8** %3
%64 = getelementptr inbounds i8, i8* %63, i64 1
store i8* %64, i8** %3
br label %65
65: ; preds = %62, %56, %59
%66 = phi i8* [ %60, %59 ], [ %57, %56 ], [ %63, %62 ]
store i8 92, i8* %66
br label %67
67: ; preds = %65, %55
%68 = call i32 @BS2PP_EmitChar(i8** %3, i32 %15)
br label %25
69: ; preds = %25
%70 = load i8*, i8** %3
br label %71
71: ; preds = %69, %9
%72 = phi i8* [ %70, %69 ], [ %11, %9 ]
%73 = getelementptr inbounds i8, i8* %72, i64 1
store i8* %73, i8** %3
store i8 39, i8* %72
%74 = load i8*, i8** %3
store i8 0, i8* %74
%75 = load i8*, i8** %3
ret i8* %75
}