#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*/ iscntrl(char const);
int /*<<< orphan*/ printf(char *, ...);
void json_print_string(const char *str, size_t bytes) {
  size_t i;
  printf("\"");
  for (i = 0; i < bytes; ++i) {
    switch (str[i]) {
    case '\"':
      printf("\\\"");
      break;
    case '\\':
      printf("\\\\");
      break;
    case '/':
      printf("\\/");
      break;
    case '\b':
      printf("\\b");
      break;
    case '\f':
      printf("\\f");
      break;
    case '\n':
      printf("\\n");
      break;
    case '\r':
      printf("\\r");
      break;
    case '\t':
      printf("\\t");
      break;
    default:
      if (iscntrl(str[i])) {
        printf("\\u%.4u", str[i]);
      } else {
        printf("%c", str[i]);
      }
    }
  }
  printf("\"");
}


x86 assembly (clang, -O0):
<json_print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12ee <json_print_string+0x1ce>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x8,%eax
je     1221 <json_print_string+0x101>
jmp    1171 <json_print_string+0x51>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
je     126d <json_print_string+0x14d>
jmp    1182 <json_print_string+0x62>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     1247 <json_print_string+0x127>
jmp    1193 <json_print_string+0x73>
mov    -0x1c(%rbp),%eax
sub    $0xc,%eax
je     1234 <json_print_string+0x114>
jmp    11a4 <json_print_string+0x84>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     125a <json_print_string+0x13a>
jmp    11b5 <json_print_string+0x95>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     11e8 <json_print_string+0xc8>
jmp    11c6 <json_print_string+0xa6>
mov    -0x1c(%rbp),%eax
sub    $0x2f,%eax
je     120e <json_print_string+0xee>
jmp    11d7 <json_print_string+0xb7>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
je     11fb <json_print_string+0xdb>
jmp    1280 <json_print_string+0x160>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%eax
je     12b9 <json_print_string+0x199>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d3 <json_print_string+0x1b3>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <json_print_string+0x1b8>
jmp    12dd <json_print_string+0x1bd>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1146 <json_print_string+0x26>
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<json_print_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x22,%edi
call   1030 <putchar@plt>
test   %r14,%r14
je     121a <json_print_string+0xea>
lea    0xea5(%rip),%r12
lea    0xf3e(%rip),%rbp
lea    0xf3d(%rip),%r15
xor    %r13d,%r13d
jmp    1194 <json_print_string+0x64>
mov    %rbp,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r13
cmp    %r13,%r14
je     121a <json_print_string+0xea>
movsbl (%rbx,%r13,1),%edi
lea    -0x8(%rdi),%eax
cmp    $0x27,%eax
ja     11b3 <json_print_string+0x83>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0xef8(%rip),%rdi
jmp    1180 <json_print_string+0x50>
cmp    $0x5c,%edi
jne    11c1 <json_print_string+0x91>
lea    0xee4(%rip),%rdi
jmp    1180 <json_print_string+0x50>
call   1040 <iscntrl@plt>
movsbl (%rbx,%r13,1),%esi
test   %eax,%eax
je     120e <json_print_string+0xde>
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1187 <json_print_string+0x57>
lea    0xecf(%rip),%rdi
jmp    1180 <json_print_string+0x50>
lea    0xec0(%rip),%rdi
jmp    1180 <json_print_string+0x50>
lea    0xeb4(%rip),%rdi
jmp    1180 <json_print_string+0x50>
lea    0xeb1(%rip),%rdi
jmp    1180 <json_print_string+0x50>
mov    %r15,%rdi
jmp    1180 <json_print_string+0x50>
mov    %esi,%edi
call   1030 <putchar@plt>
jmp    1187 <json_print_string+0x57>
mov    $0x22,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
@.str.1 = [3 x i8] c"\\\22\00"
@.str.2 = [3 x i8] c"\\\\\00"
@.str.3 = [3 x i8] c"\\/\00"
@.str.4 = [3 x i8] c"\\b\00"
@.str.5 = [3 x i8] c"\\f\00"
@.str.6 = [3 x i8] c"\\n\00"
@.str.7 = [3 x i8] c"\\r\00"
@.str.8 = [3 x i8] c"\\t\00"
@.str.9 = [7 x i8] c"\\u%.4u\00"
@.str.10 = [3 x i8] c"%c\00"
define void @json_print_string(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %5
br label %7
7: ; preds = %56, %2
%8 = load i64, i64* %5
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %59
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i64, i64* %5
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %33 [
i32 34, label %17
i32 92, label %19
i32 47, label %21
i32 8, label %23
i32 12, label %25
i32 10, label %27
i32 13, label %29
i32 9, label %31
]
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %55
19: ; preds = %11
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %55
21: ; preds = %11
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %55
23: ; preds = %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %55
25: ; preds = %11
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %55
27: ; preds = %11
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %55
29: ; preds = %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %55
31: ; preds = %11
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %55
33: ; preds = %11
%34 = load i8*, i8** %3
%35 = load i64, i64* %5
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i8, i8* %36
%38 = call i32 @iscntrl(i8 signext %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %33
%41 = load i8*, i8** %3
%42 = load i64, i64* %5
%43 = getelementptr inbounds i8, i8* %41, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %45)
br label %54
47: ; preds = %33
%48 = load i8*, i8** %3
%49 = load i64, i64* %5
%50 = getelementptr inbounds i8, i8* %48, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %47, %40
br label %55
55: ; preds = %54, %31, %29, %27, %25, %23, %21, %19, %17
br label %56
56: ; preds = %55
%57 = load i64, i64* %5
%58 = add i64 %57, 1
store i64 %58, i64* %5
br label %7
59: ; preds = %7
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"\\\22\00"
@.str.2 = [3 x i8] c"\\\\\00"
@.str.3 = [3 x i8] c"\\/\00"
@.str.4 = [3 x i8] c"\\b\00"
@.str.5 = [3 x i8] c"\\f\00"
@.str.6 = [3 x i8] c"\\n\00"
@.str.7 = [3 x i8] c"\\r\00"
@.str.8 = [3 x i8] c"\\t\00"
@.str.9 = [7 x i8] c"\\u%.4u\00"
define void @json_print_string(i8* nocapture %0, i64 %1) {
%3 = tail call i32 @putchar(i32 34)
%4 = icmp eq i64 %1, 0
br i1 %4, label %38, label %5
5: ; preds = %2, %35
%6 = phi i64 [ %36, %35 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %26 [
i32 34, label %10
i32 92, label %12
i32 47, label %14
i32 8, label %16
i32 12, label %18
i32 10, label %20
i32 13, label %22
i32 9, label %24
]
10: ; preds = %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %35
12: ; preds = %5
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %35
14: ; preds = %5
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %35
16: ; preds = %5
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %35
18: ; preds = %5
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %35
20: ; preds = %5
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %35
22: ; preds = %5
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %35
24: ; preds = %5
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %35
26: ; preds = %5
%27 = tail call i32 @iscntrl(i8 signext %8)
%28 = icmp eq i32 %27, 0
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
br i1 %28, label %33, label %31
31: ; preds = %26
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %30)
br label %35
33: ; preds = %26
%34 = tail call i32 @putchar(i32 %30)
br label %35
35: ; preds = %10, %12, %14, %16, %18, %20, %22, %24, %33, %31
%36 = add nuw i64 %6, 1
%37 = icmp eq i64 %36, %1
br i1 %37, label %38, label %5
38: ; preds = %35, %2
%39 = tail call i32 @putchar(i32 34)
ret void
}