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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char const);
int /*<<< orphan*/ fputc(unsigned char const, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char const tolower(unsigned char const);
char const toupper(unsigned char const);
void fputs_quoted_case_json(const char *data, FILE *out, int dir) {
  const char *p;
  fputc('"', out);
  for (p = data; p && *p; p++) {
    const unsigned char c = (unsigned char)*p;
    if (c == '"' || c == '\\') {
      fputc('\\', out);
      fputc(c, out);
      continue;
    }
    if (c >= 0x20) {
      fputc(dir == 1 ? toupper(c) : dir == -1 ? tolower(c) : *p, out);
      continue;
    }
    switch (c) {
    case '\b':
      fputs("\\b", out);
      break;
    case '\t':
      fputs("\\t", out);
      break;
    case '\n':
      fputs("\\n", out);
      break;
    case '\f':
      fputs("\\f", out);
      break;
    case '\r':
      fputs("\\r", out);
      break;
    default:
      fprintf(out, "\\u00%02x", c);
      break;
    }
  }
  fputc('"', out);
}


x86 assembly (clang, -O0):
<fputs_quoted_case_json>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x22,%edi
call   1050 <fputc@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x22(%rbp)
je     1199 <fputs_quoted_case_json+0x49>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11a9 <fputs_quoted_case_json+0x59>
jmp    1318 <fputs_quoted_case_json+0x1c8>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x22,%eax
je     11cc <fputs_quoted_case_json+0x7c>
movzbl -0x21(%rbp),%eax
cmp    $0x5c,%eax
jne    11ee <fputs_quoted_case_json+0x9e>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1050 <fputc@plt>
mov    -0x21(%rbp),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
jmp    1307 <fputs_quoted_case_json+0x1b7>
movzbl -0x21(%rbp),%eax
cmp    $0x20,%eax
jl     125b <fputs_quoted_case_json+0x10b>
cmpl   $0x1,-0x14(%rbp)
jne    1219 <fputs_quoted_case_json+0xc9>
movzbl -0x21(%rbp),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
mov    %eax,-0x28(%rbp)
jmp    1247 <fputs_quoted_case_json+0xf7>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1237 <fputs_quoted_case_json+0xe7>
movzbl -0x21(%rbp),%edi
call   1070 <tolower@plt>
movsbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    1241 <fputs_quoted_case_json+0xf1>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
jmp    1307 <fputs_quoted_case_json+0x1b7>
movzbl -0x21(%rbp),%eax
add    $0xfffffff8,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x5,%eax
ja     12ee <fputs_quoted_case_json+0x19e>
mov    -0x38(%rbp),%rax
lea    0xd84(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rsi
lea    0xd88(%rip),%rdi
call   1040 <fputs@plt>
jmp    1302 <fputs_quoted_case_json+0x1b2>
mov    -0x10(%rbp),%rsi
lea    0xd76(%rip),%rdi
call   1040 <fputs@plt>
jmp    1302 <fputs_quoted_case_json+0x1b2>
mov    -0x10(%rbp),%rsi
lea    0xd64(%rip),%rdi
call   1040 <fputs@plt>
jmp    1302 <fputs_quoted_case_json+0x1b2>
mov    -0x10(%rbp),%rsi
lea    0xd52(%rip),%rdi
call   1040 <fputs@plt>
jmp    1302 <fputs_quoted_case_json+0x1b2>
mov    -0x10(%rbp),%rsi
lea    0xd40(%rip),%rdi
call   1040 <fputs@plt>
jmp    1302 <fputs_quoted_case_json+0x1b2>
mov    -0x10(%rbp),%rdi
lea    0xd2e(%rip),%rsi
movzbl -0x21(%rbp),%edx
call   1060 <fprintf@plt>
jmp    1307 <fputs_quoted_case_json+0x1b7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1179 <fputs_quoted_case_json+0x29>
mov    -0x10(%rbp),%rsi
mov    $0x22,%edi
call   1050 <fputc@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputs_quoted_case_json>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    $0x22,%edi
call   1040 <fputc@plt>
test   %rbp,%rbp
je     128c <fputs_quoted_case_json+0x13c>
lea    0xe82(%rip),%r12
lea    0xe9f(%rip),%r13
jmp    11ad <fputs_quoted_case_json+0x5d>
nopw   0x0(%rax,%rax,1)
mov    $0x5c,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl %r15b,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbp
movzbl 0x0(%rbp),%r15d
cmp    $0x22,%r15b
je     1190 <fputs_quoted_case_json+0x40>
cmp    $0x5c,%r15b
je     1190 <fputs_quoted_case_json+0x40>
test   %r15b,%r15b
je     128c <fputs_quoted_case_json+0x13c>
cmp    $0x20,%r15b
jb     11e4 <fputs_quoted_case_json+0x94>
cmp    $0xffffffff,%r14d
je     120b <fputs_quoted_case_json+0xbb>
cmp    $0x1,%r14d
jne    119d <fputs_quoted_case_json+0x4d>
movzbl %r15b,%edi
call   1030 <toupper@plt>
jmp    1214 <fputs_quoted_case_json+0xc4>
lea    -0x8(%r15),%eax
cmp    $0x5,%al
ja     123f <fputs_quoted_case_json+0xef>
movzbl %al,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe0f(%rip),%rdi
jmp    127b <fputs_quoted_case_json+0x12b>
movzbl %r15b,%edi
call   1060 <tolower@plt>
mov    %eax,%r15d
jmp    119d <fputs_quoted_case_json+0x4d>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xdf1(%rip),%rdi
jmp    127b <fputs_quoted_case_json+0x12b>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xde1(%rip),%rdi
jmp    127b <fputs_quoted_case_json+0x12b>
movzbl %r15b,%edx
mov    %rbx,%rdi
lea    0xdda(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbp
jmp    11ad <fputs_quoted_case_json+0x5d>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xdb5(%rip),%rdi
jmp    127b <fputs_quoted_case_json+0x12b>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r13,%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
add    $0x1,%rbp
jmp    11ad <fputs_quoted_case_json+0x5d>
mov    $0x22,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\\b\00"
@.str.1 = [3 x i8] c"\\t\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\f\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [9 x i8] c"\\u00%02x\00"
define void @fputs_quoted_case_json(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32*, i32** %5
%10 = call i32 @fputc(i8 zeroext 34, i32* %9)
%11 = load i8*, i8** %4
store i8* %11, i8** %7
br label %12
12: ; preds = %90, %3
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %7
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br label %20
20: ; preds = %15, %12
%21 = phi i1 [ false, %12 ], [ %19, %15 ]
br i1 %21, label %22, label %93
22: ; preds = %20
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
store i8 %24, i8* %8
%25 = load i8, i8* %8
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 34
br i1 %27, label %32, label %28
28: ; preds = %22
%29 = load i8, i8* %8
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 92
br i1 %31, label %32, label %38
32: ; preds = %28, %22
%33 = load i32*, i32** %5
%34 = call i32 @fputc(i8 zeroext 92, i32* %33)
%35 = load i8, i8* %8
%36 = load i32*, i32** %5
%37 = call i32 @fputc(i8 zeroext %35, i32* %36)
br label %90
38: ; preds = %28
%39 = load i8, i8* %8
%40 = zext i8 %39 to i32
%41 = icmp sge i32 %40, 32
br i1 %41, label %42, label %67
42: ; preds = %38
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i8, i8* %8
%47 = call signext i8 @toupper(i8 zeroext %46)
%48 = sext i8 %47 to i32
br label %62
49: ; preds = %42
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i8, i8* %8
%54 = call signext i8 @tolower(i8 zeroext %53)
%55 = sext i8 %54 to i32
br label %60
56: ; preds = %49
%57 = load i8*, i8** %7
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
br label %60
60: ; preds = %56, %52
%61 = phi i32 [ %55, %52 ], [ %59, %56 ]
br label %62
62: ; preds = %60, %45
%63 = phi i32 [ %48, %45 ], [ %61, %60 ]
%64 = trunc i32 %63 to i8
%65 = load i32*, i32** %5
%66 = call i32 @fputc(i8 zeroext %64, i32* %65)
br label %90
67: ; preds = %38
%68 = load i8, i8* %8
%69 = zext i8 %68 to i32
switch i32 %69, label %85 [
i32 8, label %70
i32 9, label %73
i32 10, label %76
i32 12, label %79
i32 13, label %82
]
70: ; preds = %67
%71 = load i32*, i32** %5
%72 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %71)
br label %89
73: ; preds = %67
%74 = load i32*, i32** %5
%75 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %74)
br label %89
76: ; preds = %67
%77 = load i32*, i32** %5
%78 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %77)
br label %89
79: ; preds = %67
%80 = load i32*, i32** %5
%81 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %80)
br label %89
82: ; preds = %67
%83 = load i32*, i32** %5
%84 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %83)
br label %89
85: ; preds = %67
%86 = load i32*, i32** %5
%87 = load i8, i8* %8
%88 = call i32 @fprintf(i32* %86, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %87)
br label %89
89: ; preds = %85, %82, %79, %76, %73, %70
br label %90
90: ; preds = %89, %62, %32
%91 = load i8*, i8** %7
%92 = getelementptr inbounds i8, i8* %91, i32 1
store i8* %92, i8** %7
br label %12
93: ; preds = %20
%94 = load i32*, i32** %5
%95 = call i32 @fputc(i8 zeroext 34, i32* %94)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\b\00"
@.str.1 = [3 x i8] c"\\t\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\f\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [9 x i8] c"\\u00%02x\00"
define void @fputs_quoted_case_json(i8* %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 @fputc(i8 zeroext 34, i32* %1)
%5 = icmp eq i8* %0, null
br i1 %5, label %37, label %6
6: ; preds = %3, %35
%7 = phi i8* [ %36, %35 ], [ %0, %3 ]
%8 = load i8, i8* %7
switch i8 %8, label %12 [
i8 0, label %37
i8 92, label %9
i8 34, label %9
]
9: ; preds = %6, %6
%10 = tail call i32 @fputc(i8 zeroext 92, i32* %1)
%11 = tail call i32 @fputc(i8 zeroext %8, i32* %1)
br label %35
12: ; preds = %6
%13 = icmp ugt i8 %8, 31
br i1 %13, label %14, label %22
14: ; preds = %12
switch i32 %2, label %19 [
i32 1, label %15
i32 -1, label %17
]
15: ; preds = %14
%16 = tail call signext i8 @toupper(i8 zeroext %8)
br label %19
17: ; preds = %14
%18 = tail call signext i8 @tolower(i8 zeroext %8)
br label %19
19: ; preds = %14, %17, %15
%20 = phi i8 [ %16, %15 ], [ %18, %17 ], [ %8, %14 ]
%21 = tail call i32 @fputc(i8 zeroext %20, i32* %1)
br label %35
22: ; preds = %12
switch i8 %8, label %33 [
i8 8, label %23
i8 9, label %25
i8 10, label %27
i8 12, label %29
i8 13, label %31
]
23: ; preds = %22
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %35
25: ; preds = %22
%26 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %35
27: ; preds = %22
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %35
29: ; preds = %22
%30 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %35
31: ; preds = %22
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %35
33: ; preds = %22
%34 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %8)
br label %35
35: ; preds = %23, %25, %27, %29, %31, %33, %19, %9
%36 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
37: ; preds = %6, %3
%38 = tail call i32 @fputc(i8 zeroext 34, i32* %1)
ret void
}