#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 *);
int json_object_getValueByKey(char *, int /*<<< orphan*/, char *,
                              int /*<<< orphan*/, scalar_t__, int *, int *,
                              int *);
char *json_type_toString(int);
int /*<<< orphan*/ json_util_printSubstring(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ strlen(char *);
void test_json_object_getValueByKey() {
  puts("Test json_object_getValueByKey");
  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] = {"\"orderID\"", "\"shopperName\"", "\"shopperEmail\"",
                     "\"contents\"", "\"orderCompleted\""};
  int i;
  for (i = 0; keys[i] != NULL; i++) {
    int valueStartIndex, valueEndIndex, valueJsonType;
    if (json_object_getValueByKey(string, 0, keys[i], 0, strlen(keys[i]) - 1,
                                  &valueStartIndex, &valueEndIndex,
                                  &valueJsonType) == -1) {
      printf("%d. %s is not found\n\n", i + 1, keys[i]);
      continue;
    }
    printf("%d. %s = ", i + 1, keys[i]);
    json_util_printSubstring(string, valueStartIndex, valueEndIndex);
    printf(" (%s)\n\n", json_type_toString(valueJsonType));
  }
  free(string);
  puts("======================================================================="
       "=========\n");
}


x86 assembly (clang, -O0):
<test_json_object_getValueByKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x370,%rsp
lea    0xe5e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb6(%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_object_getValueByKey+0x5c>
mov    -0x8(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13ba <test_json_object_getValueByKey+0x22a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x348(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x348(%rbp),%rsi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1080 <memset@plt>
lea    0xe7a(%rip),%rax
mov    %rax,-0x330(%rbp)
lea    0xe76(%rip),%rax
mov    %rax,-0x328(%rbp)
lea    0xe76(%rip),%rax
mov    %rax,-0x320(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x318(%rbp)
lea    0xe74(%rip),%rax
mov    %rax,-0x310(%rbp)
movl   $0x0,-0x334(%rbp)
movslq -0x334(%rbp),%rax
cmpq   $0x0,-0x330(%rbp,%rax,8)
je     13a5 <test_json_object_getValueByKey+0x215>
mov    -0x10(%rbp),%rax
mov    %rax,-0x358(%rbp)
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rax
ff
mov    %rax,-0x350(%rbp)
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rdi
ff
call   1060 <strlen@plt>
mov    -0x358(%rbp),%rdi
mov    -0x350(%rbp),%rdx
mov    %rax,%r8
sub    $0x1,%r8
xor    %ecx,%ecx
lea    -0x338(%rbp),%r9
lea    -0x33c(%rbp),%r10
lea    -0x340(%rbp),%rax
mov    %ecx,%esi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   10a0 <json_object_getValueByKey@plt>
cmp    $0xffffffff,%eax
jne    133a <test_json_object_getValueByKey+0x1aa>
mov    -0x334(%rbp),%esi
add    $0x1,%esi
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rdx
ff
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1391 <test_json_object_getValueByKey+0x201>
mov    -0x334(%rbp),%esi
add    $0x1,%esi
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rdx
ff
lea    0xdb0(%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>
mov    -0x340(%rbp),%edi
call   1090 <json_type_toString@plt>
mov    %rax,%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    127f <test_json_object_getValueByKey+0xef>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xd66(%rip),%rdi
call   1040 <puts@plt>
add    $0x370,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_json_object_getValueByKey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x348,%rsp
lea    0xe58(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10b0 <convertFileToString@plt>
test   %rax,%rax
je     11e9 <test_json_object_getValueByKey+0x59>
lea    0xea6(%rip),%rdi
lea    0xe93(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1328 <test_json_object_getValueByKey+0x198>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xea4(%rip),%rdi
lea    0xe6c(%rip),%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x40(%rsp),%rdi
mov    $0x300,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe87(%rip),%rbp
mov    %rbp,0x20(%rsp)
lea    0xe85(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe87(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe8a(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xe89(%rip),%rax
mov    %rax,0x40(%rsp)
mov    $0x1,%ebx
lea    0x14(%rsp),%r12
lea    0x18(%rsp),%r13
lea    0x1c(%rsp),%r14
jmp    12cd <test_json_object_getValueByKey+0x13d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe82(%rip),%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%rdi
mov    0x1c(%rsp),%esi
mov    0x18(%rsp),%edx
call   1050 <json_util_printSubstring@plt>
mov    0x14(%rsp),%edi
call   1090 <json_type_toString@plt>
lea    0xe5e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x20(%rsp,%rbx,8),%rbp
add    $0x1,%rbx
test   %rbp,%rbp
je     1312 <test_json_object_getValueByKey+0x182>
mov    0x8(%rsp),%r15
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    -0x1(%rax),%r8
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
mov    %r14,%r9
push   %r12
push   %r13
call   10a0 <json_object_getValueByKey@plt>
add    $0x10,%rsp
cmp    $0xffffffff,%eax
jne    1280 <test_json_object_getValueByKey+0xf0>
lea    0xdef(%rip),%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12bf <test_json_object_getValueByKey+0x12f>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0xdf8(%rip),%rdi
call   1040 <puts@plt>
add    $0x348,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Test json_object_getValueByKey\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 = [10 x i8] c"\22orderID\22\00"
@.str.6 = [14 x i8] c"\22shopperName\22\00"
@.str.7 = [15 x i8] c"\22shopperEmail\22\00"
@.str.8 = [11 x i8] c"\22contents\22\00"
@.str.9 = [17 x i8] c"\22orderCompleted\22\00"
@.str.10 = [22 x i8] c"%d. %s is not found\0A\0A\00"
@.str.11 = [10 x i8] c"%d. %s = \00"
@.str.12 = [8 x i8] c" (%s)\0A\0A\00"
@.str.13 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_object_getValueByKey() {
%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 ([31 x i8], [31 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 %79
16: ; preds = %0
%17 = load i8*, i8** %1
%18 = load i8*, i8** %2
%19 = call i64 @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, i64 %19, i8* %20)
%22 = bitcast [100 x i8*]* %3 to i8*
%23 = bitcast i8* %22 to <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>*
%24 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>, <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>* %23, i32 0, i32 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8** %24
%25 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>, <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>* %23, i32 0, i32 1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i32 0, i32 0), i8** %25
%26 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>, <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>* %23, i32 0, i32 2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i32 0, i32 0), i8** %26
%27 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>, <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>* %23, i32 0, i32 3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i32 0, i32 0), i8** %27
%28 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>, <{ i8*, i8*, i8*, i8*, i8*, [95 x i8*] }>* %23, i32 0, i32 4
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i32 0, i32 0), i8** %28
store i32 0, i32* %4
br label %29
29: ; preds = %72, %16
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %31
%33 = load i8*, i8** %32
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %75
35: ; preds = %29
%36 = load i8*, i8** %2
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %42
%44 = load i8*, i8** %43
%45 = call i64 @strlen(i8* %44)
%46 = sub nsw i64 %45, 1
%47 = call i32 @json_object_getValueByKey(i8* %36, i32 0, i8* %40, i32 0, i64 %46, i32* %5, i32* %6, i32* %7)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %57
49: ; preds = %35
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %51, i8* %55)
br label %72
57: ; preds = %35
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
%60 = load i32, i32* %4
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i32 %59, i8* %63)
%65 = load i8*, i8** %2
%66 = load i32, i32* %5
%67 = load i32, i32* %6
%68 = call i32 @json_util_printSubstring(i8* %65, i32 %66, i32 %67)
%69 = load i32, i32* %7
%70 = call i8* @json_type_toString(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %57, %49
%73 = load i32, i32* %4
%74 = add nsw i32 %73, 1
store i32 %74, i32* %4
br label %29
75: ; preds = %29
%76 = load i8*, i8** %2
%77 = call i32 @free(i8* %76)
%78 = call i32 @puts(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.13, i64 0, i64 0))
br label %79
79: ; preds = %75, %13
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Test json_object_getValueByKey\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 = [10 x i8] c"\22orderID\22\00"
@.str.6 = [14 x i8] c"\22shopperName\22\00"
@.str.7 = [15 x i8] c"\22shopperEmail\22\00"
@.str.8 = [11 x i8] c"\22contents\22\00"
@.str.9 = [17 x i8] c"\22orderCompleted\22\00"
@.str.10 = [22 x i8] c"%d. %s is not found\0A\0A\00"
@.str.11 = [10 x i8] c"%d. %s = \00"
@.str.12 = [8 x i8] c" (%s)\0A\0A\00"
@.str.13 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_object_getValueByKey() {
%1 = alloca i8*
%2 = alloca [100 x i8*]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%8 = bitcast i8** %1 to i8*
%9 = call i64 @convertFileToString(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = 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 %57
13: ; preds = %0
%14 = load i8*, i8** %1
%15 = call i64 @strlen(i8* dereferenceable(1) %14)
%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), i64 %15, i8* %14)
%17 = bitcast [100 x i8*]* %2 to i8*
%18 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 4
%19 = bitcast i8** %18 to i8*
%20 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 4
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i8** %24
%25 = bitcast i32* %3 to i8*
%26 = bitcast i32* %4 to i8*
%27 = bitcast i32* %5 to i8*
br label %28
28: ; preds = %13, %49
%29 = phi i64 [ 0, %13 ], [ %36, %49 ]
%30 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %13 ], [ %51, %49 ]
%31 = load i8*, i8** %1
%32 = call i64 @strlen(i8* dereferenceable(1) %30)
%33 = add nsw i64 %32, -1
%34 = call i32 @json_object_getValueByKey(i8* %31, i32 0, i8* %30, i32 0, i64 %33, i32* %3, i32* %4, i32* %5)
%35 = icmp eq i32 %34, -1
%36 = add nuw i64 %29, 1
%37 = trunc i64 %36 to i32
br i1 %35, label %38, label %40
38: ; preds = %28
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %37, i8* %30)
br label %49
40: ; preds = %28
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i32 %37, i8* %30)
%42 = load i8*, i8** %1
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = call i32 @json_util_printSubstring(i8* %42, i32 %43, i32 %44)
%46 = load i32, i32* %5
%47 = call i8* @json_type_toString(i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %40, %38
%50 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 %36
%51 = load i8*, i8** %50
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %28
53: ; preds = %49
%54 = load i8*, i8** %1
%55 = call i32 @free(i8* %54)
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.13, i64 0, i64 0))
br label %57
57: ; preds = %53, %11
ret void
}