#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*/ 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:
      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    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12a0 <json_print_string+0x190>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x8,%eax
je     1211 <json_print_string+0x101>
jmp    1161 <json_print_string+0x51>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
je     125d <json_print_string+0x14d>
jmp    1172 <json_print_string+0x62>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     1237 <json_print_string+0x127>
jmp    1183 <json_print_string+0x73>
mov    -0x1c(%rbp),%eax
sub    $0xc,%eax
je     1224 <json_print_string+0x114>
jmp    1194 <json_print_string+0x84>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     124a <json_print_string+0x13a>
jmp    11a5 <json_print_string+0x95>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     11d8 <json_print_string+0xc8>
jmp    11b6 <json_print_string+0xa6>
mov    -0x1c(%rbp),%eax
sub    $0x2f,%eax
je     11fe <json_print_string+0xee>
jmp    11c7 <json_print_string+0xb7>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
je     11eb <json_print_string+0xdb>
jmp    1270 <json_print_string+0x160>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <json_print_string+0x17a>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <json_print_string+0x17a>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <json_print_string+0x17a>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <json_print_string+0x17a>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <json_print_string+0x17a>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <json_print_string+0x17a>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <json_print_string+0x17a>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128a <json_print_string+0x17a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128f <json_print_string+0x17f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1136 <json_print_string+0x26>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1030 <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,%rbx
mov    %rdi,%r14
mov    $0x22,%edi
call   1030 <putchar@plt>
test   %rbx,%rbx
je     11dd <json_print_string+0xbd>
lea    0xeb5(%rip),%r15
lea    0xf4e(%rip),%r13
lea    0xf4d(%rip),%rbp
xor    %r12d,%r12d
jmp    1180 <json_print_string+0x60>
mov    %r13,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12
cmp    %r12,%rbx
je     11dd <json_print_string+0xbd>
movsbl (%r14,%r12,1),%edi
lea    -0x8(%rdi),%eax
cmp    $0x27,%eax
ja     119f <json_print_string+0x7f>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
lea    0xf0c(%rip),%rdi
jmp    1170 <json_print_string+0x50>
cmp    $0x5c,%edi
jne    11ad <json_print_string+0x8d>
lea    0xef8(%rip),%rdi
jmp    1170 <json_print_string+0x50>
call   1030 <putchar@plt>
jmp    1177 <json_print_string+0x57>
lea    0xefa(%rip),%rdi
jmp    1170 <json_print_string+0x50>
lea    0xeeb(%rip),%rdi
jmp    1170 <json_print_string+0x50>
lea    0xedf(%rip),%rdi
jmp    1170 <json_print_string+0x50>
lea    0xedc(%rip),%rdi
jmp    1170 <json_print_string+0x50>
mov    %rbp,%rdi
jmp    1170 <json_print_string+0x50>
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 = [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 = %41, %2
%8 = load i64, i64* %5
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %44
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 %40
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 %40
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 %40
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 %40
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 %40
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 %40
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 %40
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 %40
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 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %33, %31, %29, %27, %25, %23, %21, %19, %17
br label %41
41: ; preds = %40
%42 = load i64, i64* %5
%43 = add i64 %42, 1
store i64 %43, i64* %5
br label %7
44: ; preds = %7
%45 = 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"
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 %31, label %5
5: ; preds = %2, %28
%6 = phi i64 [ %29, %28 ], [ 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 %28
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 %28
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 %28
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 %28
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 %28
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 %28
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 %28
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 %28
26: ; preds = %5
%27 = tail call i32 @putchar(i32 %9)
br label %28
28: ; preds = %10, %12, %14, %16, %18, %20, %22, %24, %26
%29 = add nuw i64 %6, 1
%30 = icmp eq i64 %29, %1
br i1 %30, label %31, label %5
31: ; preds = %28, %2
%32 = tail call i32 @putchar(i32 34)
ret void
}