#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 */
scalar_t__ convertFileToString(char const *, char **);
int /*<<< orphan*/ free(char *);
scalar_t__ json_getValueByJS(char *, int /*<<< orphan*/, char *,
                             int /*<<< orphan*/, int *, int *, int *);
char *json_type_toString(int);
int /*<<< orphan*/ json_util_printSubstring(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strlen(char *);
void test_json_getValueByJS() {
  puts("Test json_getValueByJS");
  puts("======================================================================="
       "=========");
  const char *fileName = "sample.json";
  char *string;
  if (convertFileToString(fileName, &string) != 0) {
    printf("convert file '%s' to string failure\n", fileName);
    return;
  }
  printf("%s (%lu) = %s\n", fileName, strlen(string), string);
  char *keys[100] = {"[\"contents\"]",
                     "[\"contents\"][0]",
                     "[\"contents\"][2]",
                     "[\"contents\"][0][\"productName\"]",
                     "[]",
                     "[0]",
                     "[\"orderID\"]",
                     "[\"contents\"][0][\"quantity\"]"};
  int i;
  for (i = 0; keys[i] != NULL; i++) {
    puts("---------------------------------------------------------------------"
         "-----------");
    printf("%2d. KEY (%lu) = %s\n", i + 1, strlen(keys[i]), keys[i]);
    int valueStartIndex, valueEndIndex, valueJsonType;
    if (json_getValueByJS(string, 0, keys[i], 0, &valueStartIndex,
                          &valueEndIndex, &valueJsonType) != 0) {
      printf("%s is not found\n\n", keys[i]);
      continue;
    }
    printf("    VALUE (%s) = ", json_type_toString(valueJsonType));
    json_util_printSubstring(string, valueStartIndex, valueEndIndex);
    puts("\n");
  }
  free(string);
  puts("======================================================================="
       "=========\n");
}


x86 assembly (clang, -O0):
<test_json_getValueByJS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
lea    0xe5e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <convertFileToString@plt>
cmp    $0x0,%rax
je     11ec <test_json_getValueByJS+0x5c>
mov    -0x8(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    136e <test_json_getValueByJS+0x1de>
mov    -0x8(%rbp),%rax
mov    %rax,-0x348(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x348(%rbp),%rsi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x330(%rbp),%rdi
lea    0x28d7(%rip),%rsi
mov    $0x320,%edx
call   10a0 <memcpy@plt>
movl   $0x0,-0x334(%rbp)
movslq -0x334(%rbp),%rax
cmpq   $0x0,-0x330(%rbp,%rax,8)
je     1359 <test_json_getValueByJS+0x1c9>
lea    0xec5(%rip),%rdi
call   1040 <puts@plt>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34c(%rbp)
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rdi
ff
call   1060 <strlen@plt>
mov    -0x34c(%rbp),%esi
mov    %eax,%edx
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rcx
ff
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rdx
ff
xor    %ecx,%ecx
lea    -0x338(%rbp),%r8
lea    -0x33c(%rbp),%r9
lea    -0x340(%rbp),%rax
mov    %ecx,%esi
mov    %rax,(%rsp)
call   1080 <json_getValueByJS@plt>
cmp    $0x0,%rax
je     1308 <test_json_getValueByJS+0x178>
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rsi
ff
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1345 <test_json_getValueByJS+0x1b5>
mov    -0x340(%rbp),%edi
call   1090 <json_type_toString@plt>
mov    %rax,%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x338(%rbp),%esi
mov    -0x33c(%rbp),%edx
call   1050 <json_util_printSubstring@plt>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    123d <test_json_getValueByJS+0xad>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
add    $0x360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_json_getValueByJS>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
lea    0xebb(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <convertFileToString@plt>
test   %rax,%rax
je     11d6 <test_json_getValueByJS+0x56>
lea    0xeb1(%rip),%rdi
lea    0xe9e(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12ed <test_json_getValueByJS+0x16d>
mov    0x10(%rsp),%rdi
call   1060 <strlen@plt>
mov    0x10(%rsp),%rcx
lea    0xead(%rip),%rdi
lea    0xe75(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xea5(%rip),%rbp
mov    $0x1,%ebx
lea    0xf61(%rip),%r15
lea    0x24(%rsp),%r12
lea    0x20(%rsp),%r13
lea    0x28e0(%rip),%r14
jmp    1276 <test_json_getValueByJS+0xf6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x1c(%rsp),%edi
call   1090 <json_type_toString@plt>
lea    0xf57(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%rdi
mov    0x24(%rsp),%esi
mov    0x20(%rsp),%edx
call   1050 <json_util_printSubstring@plt>
lea    0xf32(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14,%rbx,8),%rbp
add    $0x1,%rbx
cmp    $0x9,%rbx
je     12d7 <test_json_getValueByJS+0x157>
lea    0xea2(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%rdi
lea    0x1c(%rsp),%rax
mov    %rax,(%rsp)
xor    %esi,%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r13,%r9
call   1080 <json_getValueByJS@plt>
test   %rax,%rax
je     1230 <test_json_getValueByJS+0xb0>
lea    0xeba(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1268 <test_json_getValueByJS+0xe8>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Test json_getValueByJS\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [12 x i8] c"sample.json\00"
@.str.3 = [37 x i8] c"convert file '%s' to string failure\0A\00"
@.str.4 = [15 x i8] c"%s (%lu) = %s\0A\00"
@.str.5 = [13 x i8] c"[\22contents\22]\00"
@.str.6 = [16 x i8] c"[\22contents\22][0]\00"
@.str.7 = [16 x i8] c"[\22contents\22][2]\00"
@.str.8 = [31 x i8] c"[\22contents\22][0][\22productName\22]\00"
@.str.9 = [3 x i8] c"[]\00"
@.str.10 = [4 x i8] c"[0]\00"
@.str.11 = [12 x i8] c"[\22orderID\22]\00"
@.str.12 = [28 x i8] c"[\22contents\22][0][\22quantity\22]\00"
@__const.test_json_getValueByJS.keys = <{ [8 x i8*], [92 x i8*] }> <{ [8 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i32 0, i32 0)], [92 x i8*] zeroinitializer }>
@.str.13 = [81 x i8] c"--------------------------------------------------------------------------------\00"
@.str.14 = [21 x i8] c"%2d. KEY (%lu) = %s\0A\00"
@.str.15 = [18 x i8] c"%s is not found\0A\0A\00"
@.str.16 = [18 x i8] c" VALUE (%s) = \00"
@.str.17 = [2 x i8] c"\0A\00"
@.str.18 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_getValueByJS() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca [100 x i8*]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %1
%10 = load i8*, i8** %1
%11 = call i64 @convertFileToString(i8* %10, i8** %2)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i8*, i8** %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %72
16: ; preds = %0
%17 = load i8*, i8** %1
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %17, i32 %19, i8* %20)
%22 = bitcast [100 x i8*]* %3 to i8*
store i32 0, i32* %4
br label %23
23: ; preds = %65, %16
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %25
%27 = load i8*, i8** %26
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %68
29: ; preds = %23
%30 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.13, i64 0, i64 0))
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.14, i64 0, i64 0), i32 %32, i32 %37, i8* %41)
%43 = load i8*, i8** %2
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %45
%47 = load i8*, i8** %46
%48 = call i64 @json_getValueByJS(i8* %43, i32 0, i8* %47, i32 0, i32* %5, i32* %6, i32* %7)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %29
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i8* %54)
br label %65
56: ; preds = %29
%57 = load i32, i32* %7
%58 = call i8* @json_type_toString(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0), i8* %58)
%60 = load i8*, i8** %2
%61 = load i32, i32* %5
%62 = load i32, i32* %6
%63 = call i32 @json_util_printSubstring(i8* %60, i32 %61, i32 %62)
%64 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
br label %65
65: ; preds = %56, %50
%66 = load i32, i32* %4
%67 = add nsw i32 %66, 1
store i32 %67, i32* %4
br label %23
68: ; preds = %23
%69 = load i8*, i8** %2
%70 = call i32 @free(i8* %69)
%71 = call i32 @puts(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.18, i64 0, i64 0))
br label %72
72: ; preds = %68, %13
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Test json_getValueByJS\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [12 x i8] c"sample.json\00"
@.str.3 = [37 x i8] c"convert file '%s' to string failure\0A\00"
@.str.4 = [15 x i8] c"%s (%lu) = %s\0A\00"
@.str.5 = [13 x i8] c"[\22contents\22]\00"
@.str.6 = [16 x i8] c"[\22contents\22][0]\00"
@.str.7 = [16 x i8] c"[\22contents\22][2]\00"
@.str.8 = [31 x i8] c"[\22contents\22][0][\22productName\22]\00"
@.str.9 = [3 x i8] c"[]\00"
@.str.10 = [4 x i8] c"[0]\00"
@.str.11 = [12 x i8] c"[\22orderID\22]\00"
@.str.12 = [28 x i8] c"[\22contents\22][0][\22quantity\22]\00"
@__const.test_json_getValueByJS.keys = <{ [8 x i8*], [92 x i8*] }> <{ [8 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i32 0, i32 0)], [92 x i8*] zeroinitializer }>
@.str.13 = [81 x i8] c"--------------------------------------------------------------------------------\00"
@.str.14 = [21 x i8] c"%2d. KEY (%lu) = %s\0A\00"
@.str.15 = [18 x i8] c"%s is not found\0A\0A\00"
@.str.16 = [18 x i8] c" VALUE (%s) = \00"
@.str.17 = [2 x i8] c"\0A\00"
@.str.18 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_getValueByJS() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast i8** %1 to i8*
%8 = call i64 @convertFileToString(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %50
12: ; preds = %0
%13 = load i8*, i8** %1
%14 = call i32 @strlen(i8* %13)
%15 = load i8*, i8** %1
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14, i8* %15)
%17 = bitcast i32* %2 to i8*
%18 = bitcast i32* %3 to i8*
%19 = bitcast i32* %4 to i8*
br label %20
20: ; preds = %12, %42
%21 = phi i64 [ 0, %12 ], [ %24, %42 ]
%22 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), %12 ], [ %44, %42 ]
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.13, i64 0, i64 0))
%24 = add nuw nsw i64 %21, 1
%25 = call i32 @strlen(i8* %22)
%26 = trunc i64 %24 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.14, i64 0, i64 0), i32 %26, i32 %25, i8* %22)
%28 = load i8*, i8** %1
%29 = call i64 @json_getValueByJS(i8* %28, i32 0, i8* %22, i32 0, i32* %2, i32* %3, i32* %4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %20
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i8* %22)
br label %42
33: ; preds = %20
%34 = load i32, i32* %4
%35 = call i8* @json_type_toString(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %1
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = call i32 @json_util_printSubstring(i8* %37, i32 %38, i32 %39)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
br label %42
42: ; preds = %33, %31
%43 = getelementptr inbounds [100 x i8*], [100 x i8*]* bitcast (<{ [8 x i8*], [92 x i8*] }>* @__const.test_json_getValueByJS.keys to [100 x i8*]*), i64 0, i64 %24
%44 = load i8*, i8** %43
%45 = icmp eq i64 %24, 8
br i1 %45, label %46, label %20
46: ; preds = %42
%47 = load i8*, i8** %1
%48 = call i32 @free(i8* %47)
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.18, i64 0, i64 0))
br label %50
50: ; preds = %46, %10
ret void
}