#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*/ free(char *);
scalar_t__ json_string_toString(char *, int /*<<< orphan*/, char **);
int /*<<< orphan*/ printHexArray(char *, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ strlen(char *);
void test_json_string_toString() {
  puts("Test json_string_toString");
  puts("======================================================================="
       "=========");
  char *str[100] = {"\"\"ab c\"",
                    "",
                    "\"abc\"",
                    "abc",
                    "\"",
                    "\"abc\"abc",
                    "\"abc\\",
                    "\"abc",
                    "\"\"abc\"",
                    "\"\\abc\"",
                    "\"/abc\"",
                    "\"\\/abc\"",
                    "\"\\\"\\\\\\/\\b\\f\\n\\r\\t\"",
                    "\"abc\\u\"",
                    "\"abc\\u1\"",
                    "\"abc\\u12\"",
                    "\"abc\\u123\"",
                    "\"abc\\u1234\"",
                    "\"abc\\u1234",
                    "\"abc\\u1a34\"",
                    "\"abc\\u1A3456\"",
                    "\"abc\\u12s4\"",
                    "\"abc\\u1234\\u1234abc\""};
  int i;
  for (i = 0; str[i] != NULL; i++) {
    puts("---------------------------------------------------------------------"
         "-----------");
    printf("%d. ", i + 1);
    char *string;
    if (json_string_toString(str[i], 0, &string) != 0) {
      printf("%s is not JSON string\n\n", str[i]);
      continue;
    }
    printf("%s is \"%s\" (%lu)\n", str[i], string, strlen(string));
    printHexArray(string, 0, strlen(string) + 1);
    puts("");
    free(string);
  }
  puts("======================================================================="
       "=========\n");
}


x86 assembly (clang, -O0):
<test_json_string_toString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
lea    0xe7e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
lea    -0x320(%rbp),%rdi
lea    0x295f(%rip),%rsi
mov    $0x320,%edx
call   1080 <memcpy@plt>
movl   $0x0,-0x324(%rbp)
movslq -0x324(%rbp),%rax
cmpq   $0x0,-0x320(%rbp,%rax,8)
je     12e1 <test_json_string_toString+0x171>
lea    0xf58(%rip),%rdi
call   1040 <puts@plt>
mov    -0x324(%rbp),%esi
add    $0x1,%esi
lea    0xf94(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdi
ff
xor    %esi,%esi
lea    -0x330(%rbp),%rdx
call   1070 <json_string_toString@plt>
cmp    $0x0,%rax
je     1237 <test_json_string_toString+0xc7>
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rsi
ff
lea    0xf55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12cd <test_json_string_toString+0x15d>
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rax
ff
mov    %rax,-0x348(%rbp)
mov    -0x330(%rbp),%rax
mov    %rax,-0x340(%rbp)
mov    -0x330(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x348(%rbp),%rsi
mov    -0x340(%rbp),%rdx
mov    %rax,%rcx
lea    0xf19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x330(%rbp),%rax
mov    %rax,-0x338(%rbp)
mov    -0x330(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x338(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1090 <printHexArray@plt>
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
mov    -0x330(%rbp),%rdi
call   1030 <free@plt>
mov    -0x324(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x324(%rbp)
jmp    11b5 <test_json_string_toString+0x45>
lea    0xec2(%rip),%rdi
call   1040 <puts@plt>
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_json_string_toString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rdi
call   1050 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1050 <puts@plt>
lea    0xed1(%rip),%r13
mov    $0x1,%ebx
lea    0xf84(%rip),%r15
lea    0xfce(%rip),%r12
mov    %rsp,%r14
lea    0x2949(%rip),%rbp
jmp    1226 <test_json_string_toString+0xb6>
nopl   0x0(%rax)
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0xfc5(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbp,%rdi
lea    0x2903(%rip),%rbp
xor    %esi,%esi
call   1090 <printHexArray@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x0(%rbp,%rbx,8),%r13
add    $0x1,%rbx
cmp    $0x18,%rbx
je     1263 <test_json_string_toString+0xf3>
mov    %r15,%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1080 <json_string_toString@plt>
test   %rax,%rax
je     11c0 <test_json_string_toString+0x50>
lea    0xf29(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1217 <test_json_string_toString+0xa7>
lea    0xf40(%rip),%rdi
call   1050 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Test json_string_toString\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [8 x i8] c"\22\22ab c\22\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [6 x i8] c"\22abc\22\00"
@.str.5 = [4 x i8] c"abc\00"
@.str.6 = [2 x i8] c"\22\00"
@.str.7 = [9 x i8] c"\22abc\22abc\00"
@.str.8 = [6 x i8] c"\22abc\\\00"
@.str.9 = [5 x i8] c"\22abc\00"
@.str.10 = [7 x i8] c"\22\22abc\22\00"
@.str.11 = [7 x i8] c"\22\\abc\22\00"
@.str.12 = [7 x i8] c"\22/abc\22\00"
@.str.13 = [8 x i8] c"\22\\/abc\22\00"
@.str.14 = [19 x i8] c"\22\\\22\\\\\\/\\b\\f\\n\\r\\t\22\00"
@.str.15 = [8 x i8] c"\22abc\\u\22\00"
@.str.16 = [9 x i8] c"\22abc\\u1\22\00"
@.str.17 = [10 x i8] c"\22abc\\u12\22\00"
@.str.18 = [11 x i8] c"\22abc\\u123\22\00"
@.str.19 = [12 x i8] c"\22abc\\u1234\22\00"
@.str.20 = [11 x i8] c"\22abc\\u1234\00"
@.str.21 = [12 x i8] c"\22abc\\u1a34\22\00"
@.str.22 = [14 x i8] c"\22abc\\u1A3456\22\00"
@.str.23 = [12 x i8] c"\22abc\\u12s4\22\00"
@.str.24 = [21 x i8] c"\22abc\\u1234\\u1234abc\22\00"
@__const.test_json_string_toString.str = <{ [23 x i8*], [77 x i8*] }> <{ [23 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.20, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.21, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.22, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.24, i32 0, i32 0)], [77 x i8*] zeroinitializer }>
@.str.25 = [81 x i8] c"--------------------------------------------------------------------------------\00"
@.str.26 = [5 x i8] c"%d. \00"
@.str.27 = [24 x i8] c"%s is not JSON string\0A\0A\00"
@.str.28 = [18 x i8] c"%s is \22%s\22 (%lu)\0A\00"
@.str.29 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_string_toString() {
%1 = alloca [100 x i8*]
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast [100 x i8*]* %1 to i8*
store i32 0, i32* %2
br label %7
7: ; preds = %47, %0
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %9
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %50
13: ; preds = %7
%14 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.25, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.26, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %19
%21 = load i8*, i8** %20
%22 = call i64 @json_string_toString(i8* %21, i32 0, i8** %3)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %13
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.27, i64 0, i64 0), i8* %28)
br label %47
30: ; preds = %13
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = load i8*, i8** %3
%36 = load i8*, i8** %3
%37 = call i64 @strlen(i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.28, i64 0, i64 0), i8* %34, i8* %35, i64 %37)
%39 = load i8*, i8** %3
%40 = load i8*, i8** %3
%41 = call i64 @strlen(i8* %40)
%42 = add nsw i64 %41, 1
%43 = call i32 @printHexArray(i8* %39, i32 0, i64 %42)
%44 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%45 = load i8*, i8** %3
%46 = call i32 @free(i8* %45)
br label %47
47: ; preds = %30, %24
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %7
50: ; preds = %7
%51 = call i32 @puts(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.29, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"Test json_string_toString\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [8 x i8] c"\22\22ab c\22\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [6 x i8] c"\22abc\22\00"
@.str.5 = [4 x i8] c"abc\00"
@.str.6 = [2 x i8] c"\22\00"
@.str.7 = [9 x i8] c"\22abc\22abc\00"
@.str.8 = [6 x i8] c"\22abc\\\00"
@.str.9 = [5 x i8] c"\22abc\00"
@.str.10 = [7 x i8] c"\22\22abc\22\00"
@.str.11 = [7 x i8] c"\22\\abc\22\00"
@.str.12 = [7 x i8] c"\22/abc\22\00"
@.str.13 = [8 x i8] c"\22\\/abc\22\00"
@.str.14 = [19 x i8] c"\22\\\22\\\\\\/\\b\\f\\n\\r\\t\22\00"
@.str.15 = [8 x i8] c"\22abc\\u\22\00"
@.str.16 = [9 x i8] c"\22abc\\u1\22\00"
@.str.17 = [10 x i8] c"\22abc\\u12\22\00"
@.str.18 = [11 x i8] c"\22abc\\u123\22\00"
@.str.19 = [12 x i8] c"\22abc\\u1234\22\00"
@.str.20 = [11 x i8] c"\22abc\\u1234\00"
@.str.21 = [12 x i8] c"\22abc\\u1a34\22\00"
@.str.22 = [14 x i8] c"\22abc\\u1A3456\22\00"
@.str.23 = [12 x i8] c"\22abc\\u12s4\22\00"
@.str.24 = [21 x i8] c"\22abc\\u1234\\u1234abc\22\00"
@__const.test_json_string_toString.str = <{ [23 x i8*], [77 x i8*] }> <{ [23 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.20, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.21, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.22, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.24, i32 0, i32 0)], [77 x i8*] zeroinitializer }>
@.str.25 = [81 x i8] c"--------------------------------------------------------------------------------\00"
@.str.26 = [5 x i8] c"%d. \00"
@.str.27 = [24 x i8] c"%s is not JSON string\0A\0A\00"
@.str.28 = [18 x i8] c"%s is \22%s\22 (%lu)\0A\00"
@.str.29 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_string_toString() {
%1 = alloca i8*
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i8** %1 to i8*
br label %5
5: ; preds = %0, %27
%6 = phi i64 [ 0, %0 ], [ %9, %27 ]
%7 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %0 ], [ %29, %27 ]
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.25, i64 0, i64 0))
%9 = add nuw nsw i64 %6, 1
%10 = trunc i64 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.26, i64 0, i64 0), i32 %10)
%12 = call i64 @json_string_toString(i8* %7, i32 0, i8** %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %5
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.27, i64 0, i64 0), i8* %7)
br label %27
16: ; preds = %5
%17 = load i8*, i8** %1
%18 = call i64 @strlen(i8* dereferenceable(1) %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.28, i64 0, i64 0), i8* %7, i8* %17, i64 %18)
%20 = load i8*, i8** %1
%21 = call i64 @strlen(i8* dereferenceable(1) %20)
%22 = add nsw i64 %21, 1
%23 = call i32 @printHexArray(i8* %20, i32 0, i64 %22)
%24 = call i32 @putchar(i32 10)
%25 = load i8*, i8** %1
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %16, %14
%28 = getelementptr inbounds [100 x i8*], [100 x i8*]* bitcast (<{ [23 x i8*], [77 x i8*] }>* @__const.test_json_string_toString.str to [100 x i8*]*), i64 0, i64 %9
%29 = load i8*, i8** %28
%30 = icmp eq i64 %9, 23
br i1 %30, label %31, label %5
31: ; preds = %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.29, i64 0, i64 0))
ret void
}