#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 uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char);
void escape_json_output(FILE *fp, char *s) {
  while (*s) {
    switch (*s) {
    case '"':
      fprintf(fp, "\\\"");
      break;
    case '\\':
      fprintf(fp, "\\\\");
      break;
    case '\b':
      fprintf(fp, "\\\b");
      break;
    case '\f':
      fprintf(fp, "\\\f");
      break;
    case '\n':
      fprintf(fp, "\\\n");
      break;
    case '\r':
      fprintf(fp, "\\\r");
      break;
    case '\t':
      fprintf(fp, "\\\t");
      break;
    case '/':
      fprintf(fp, "\\/");
      break;
    default:
      if ((uint8_t)*s <= 0x1f) {
        char buf[8];
        snprintf(buf, sizeof buf, "\\u%04x", *s);
        fprintf(fp, "%s", buf);
      } else if ((uint8_t)*s == 0xe2 && (uint8_t) * (s + 1) == 0x80 &&
                 (uint8_t) * (s + 2) == 0xa8) {
        fprintf(fp, "\\u2028");
        s += 2;
      } else if ((uint8_t)*s == 0xe2 && (uint8_t) * (s + 1) == 0x80 &&
                 (uint8_t) * (s + 2) == 0xa9) {
        fprintf(fp, "\\u2029");
        s += 2;
      } else {
        fputc(*s, fp);
      }
      break;
    }
    s++;
  }
}


x86 assembly (clang, -O0):
<escape_json_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     13c3 <escape_json_output+0x293>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x8,%eax
je     120a <escape_json_output+0xda>
jmp    1165 <escape_json_output+0x35>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
je     1266 <escape_json_output+0x136>
jmp    1176 <escape_json_output+0x46>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     1238 <escape_json_output+0x108>
jmp    1187 <escape_json_output+0x57>
mov    -0x1c(%rbp),%eax
sub    $0xc,%eax
je     1221 <escape_json_output+0xf1>
jmp    1198 <escape_json_output+0x68>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     124f <escape_json_output+0x11f>
jmp    11a9 <escape_json_output+0x79>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     11dc <escape_json_output+0xac>
jmp    11ba <escape_json_output+0x8a>
mov    -0x1c(%rbp),%eax
sub    $0x2f,%eax
je     127d <escape_json_output+0x14d>
jmp    11cb <escape_json_output+0x9b>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
je     11f3 <escape_json_output+0xc3>
jmp    1294 <escape_json_output+0x164>
mov    -0x8(%rbp),%rdi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13b2 <escape_json_output+0x282>
mov    -0x8(%rbp),%rdi
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13b2 <escape_json_output+0x282>
mov    -0x8(%rbp),%rdi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13b2 <escape_json_output+0x282>
mov    -0x8(%rbp),%rdi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13b2 <escape_json_output+0x282>
mov    -0x8(%rbp),%rdi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13b2 <escape_json_output+0x282>
mov    -0x8(%rbp),%rdi
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13b2 <escape_json_output+0x282>
mov    -0x8(%rbp),%rdi
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13b2 <escape_json_output+0x282>
mov    -0x8(%rbp),%rdi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13b2 <escape_json_output+0x282>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x1f,%eax
jg     12db <escape_json_output+0x1ab>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x8,%esi
lea    0xd60(%rip),%rdx
movsbl (%rax),%ecx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rdx
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13ad <escape_json_output+0x27d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xe2,%eax
jne    1336 <escape_json_output+0x206>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x80,%eax
jne    1336 <escape_json_output+0x206>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0xa8,%eax
jne    1336 <escape_json_output+0x206>
mov    -0x8(%rbp),%rdi
lea    0xd04(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    13a8 <escape_json_output+0x278>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xe2,%eax
jne    1391 <escape_json_output+0x261>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x80,%eax
jne    1391 <escape_json_output+0x261>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0xa9,%eax
jne    1391 <escape_json_output+0x261>
mov    -0x8(%rbp),%rdi
lea    0xcb0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    13a3 <escape_json_output+0x273>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    13a8 <escape_json_output+0x278>
jmp    13ad <escape_json_output+0x27d>
jmp    13b2 <escape_json_output+0x282>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1140 <escape_json_output+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_json_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%al
test   %al,%al
je     1288 <escape_json_output+0x148>
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%rbx
mov    %rsp,%r13
lea    0xe97(%rip),%r12
lea    0xf30(%rip),%r15
lea    0xf3e(%rip),%rbp
jmp    11a7 <escape_json_output+0x67>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rdi
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rcx
call   1060 <fwrite@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1288 <escape_json_output+0x148>
movsbl %al,%ecx
lea    -0x8(%rcx),%edx
cmp    $0x27,%edx
ja     11ce <escape_json_output+0x8e>
movslq (%r12,%rdx,4),%rdx
add    %r12,%rdx
jmp    *%rdx
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xeda(%rip),%rdi
jmp    1190 <escape_json_output+0x50>
cmp    $0x5c,%ecx
jne    11e6 <escape_json_output+0xa6>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xebf(%rip),%rdi
jmp    1190 <escape_json_output+0x50>
cmp    $0x1f,%al
jg     1279 <escape_json_output+0x139>
mov    %r13,%rdi
mov    $0x8,%esi
lea    0xebb(%rip),%rdx
call   1030 <snprintf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
jmp    1198 <escape_json_output+0x58>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe92(%rip),%rdi
jmp    1190 <escape_json_output+0x50>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe76(%rip),%rdi
jmp    1190 <escape_json_output+0x50>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe5d(%rip),%rdi
jmp    1190 <escape_json_output+0x50>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe4d(%rip),%rdi
jmp    1190 <escape_json_output+0x50>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
jmp    1190 <escape_json_output+0x50>
mov    %ecx,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
jmp    1198 <escape_json_output+0x58>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\\22\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [3 x i8] c"\\\08\00"
@.str.3 = [3 x i8] c"\\\0C\00"
@.str.4 = [3 x i8] c"\\\0A\00"
@.str.5 = [3 x i8] c"\\\0D\00"
@.str.6 = [3 x i8] c"\\\09\00"
@.str.7 = [3 x i8] c"\\/\00"
@.str.8 = [7 x i8] c"\\u%04x\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [7 x i8] c"\\u2028\00"
@.str.11 = [7 x i8] c"\\u2029\00"
define void @escape_json_output(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [8 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
br label %6
6: ; preds = %103, %2
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %106
10: ; preds = %6
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %38 [
i32 34, label %14
i32 92, label %17
i32 8, label %20
i32 12, label %23
i32 10, label %26
i32 13, label %29
i32 9, label %32
i32 47, label %35
]
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %103
17: ; preds = %10
%18 = load i32*, i32** %3
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %103
20: ; preds = %10
%21 = load i32*, i32** %3
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %103
23: ; preds = %10
%24 = load i32*, i32** %3
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %103
26: ; preds = %10
%27 = load i32*, i32** %3
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %103
29: ; preds = %10
%30 = load i32*, i32** %3
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %103
32: ; preds = %10
%33 = load i32*, i32** %3
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %103
35: ; preds = %10
%36 = load i32*, i32** %3
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %103
38: ; preds = %10
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp sle i32 %41, 31
br i1 %42, label %43, label %51
43: ; preds = %38
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%45 = load i8*, i8** %4
%46 = load i8, i8* %45
%47 = call i32 @snprintf(i8* %44, i32 8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8 signext %46)
%48 = load i32*, i32** %3
%49 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %49)
br label %102
51: ; preds = %38
%52 = load i8*, i8** %4
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 226
br i1 %55, label %56, label %73
56: ; preds = %51
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 128
br i1 %61, label %62, label %73
62: ; preds = %56
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i64 2
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 168
br i1 %67, label %68, label %73
68: ; preds = %62
%69 = load i32*, i32** %3
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%71 = load i8*, i8** %4
%72 = getelementptr inbounds i8, i8* %71, i64 2
store i8* %72, i8** %4
br label %101
73: ; preds = %62, %56, %51
%74 = load i8*, i8** %4
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 226
br i1 %77, label %78, label %95
78: ; preds = %73
%79 = load i8*, i8** %4
%80 = getelementptr inbounds i8, i8* %79, i64 1
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 128
br i1 %83, label %84, label %95
84: ; preds = %78
%85 = load i8*, i8** %4
%86 = getelementptr inbounds i8, i8* %85, i64 2
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 169
br i1 %89, label %90, label %95
90: ; preds = %84
%91 = load i32*, i32** %3
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %91, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%93 = load i8*, i8** %4
%94 = getelementptr inbounds i8, i8* %93, i64 2
store i8* %94, i8** %4
br label %100
95: ; preds = %84, %78, %73
%96 = load i8*, i8** %4
%97 = load i8, i8* %96
%98 = load i32*, i32** %3
%99 = call i32 @fputc(i8 signext %97, i32* %98)
br label %100
100: ; preds = %95, %90
br label %101
101: ; preds = %100, %68
br label %102
102: ; preds = %101, %43
br label %103
103: ; preds = %102, %35, %32, %29, %26, %23, %20, %17, %14
%104 = load i8*, i8** %4
%105 = getelementptr inbounds i8, i8* %104, i32 1
store i8* %105, i8** %4
br label %6
106: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\\22\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [3 x i8] c"\\\08\00"
@.str.3 = [3 x i8] c"\\\0C\00"
@.str.4 = [3 x i8] c"\\\0A\00"
@.str.5 = [3 x i8] c"\\\0D\00"
@.str.6 = [3 x i8] c"\\\09\00"
@.str.7 = [3 x i8] c"\\/\00"
@.str.8 = [7 x i8] c"\\u%04x\00"
define void @escape_json_output(i32* nocapture %0, i8* nocapture %1) {
%3 = alloca [8 x i8]
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %39, label %6
6: ; preds = %2
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
br label %8
8: ; preds = %6, %35
%9 = phi i8 [ %4, %6 ], [ %37, %35 ]
%10 = phi i8* [ %1, %6 ], [ %36, %35 ]
%11 = sext i8 %9 to i32
switch i32 %11, label %28 [
i32 34, label %12
i32 92, label %14
i32 8, label %16
i32 12, label %18
i32 10, label %20
i32 13, label %22
i32 9, label %24
i32 47, label %26
]
12: ; preds = %8
%13 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %35
14: ; preds = %8
%15 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %35
16: ; preds = %8
%17 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %35
18: ; preds = %8
%19 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %35
20: ; preds = %8
%21 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %35
22: ; preds = %8
%23 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %35
24: ; preds = %8
%25 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %35
26: ; preds = %8
%27 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %35
28: ; preds = %8
%29 = icmp slt i8 %9, 32
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = call i32 @snprintf(i8* %7, i32 8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8 signext %9)
%32 = call i32 @fputs(i8* %7, i32* %0)
br label %35
33: ; preds = %28
%34 = call i32 @fputc(i8 signext %9, i32* %0)
br label %35
35: ; preds = %30, %33, %26, %24, %22, %20, %18, %16, %14, %12
%36 = getelementptr inbounds i8, i8* %10, i64 1
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %39, label %8
39: ; preds = %35, %2
ret void
}