#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 json_getKeyValuePair(char *, int /*<<< orphan*/, int *, int *, int *, int *,
                         int *);
char *json_type_toString(int);
int /*<<< orphan*/ json_util_printSubstring(char *, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ puts(char *);
void test_json_getKeyValuePair() {
  puts("Test json_getKeyValuePair");
  puts("======================================================================="
       "=========");
  puts("    0123456789 123456789 123456789\n");
  char *str[100] = {"\"name\"   :   \"Leon\"",
                    "   \"age\"  :  25  ",
                    "   \"sex\"    :   \"male\" ",
                    "\"company\":\"gemtek\"",
                    "\"obj\":   {obj}",
                    "\"array\":[array]  ",
                    "array:[]",
                    "obj:{}",
                    "\"Bool\"   \n:   \ntrue",
                    "\t\"Bool\"   \t:   false",
                    "\"Null\"  :  null"};
  int i, keyStartIndex, keyEndIndex, valueStartIndex, valueEndIndex,
      valueJsonType;
  for (i = 0; str[i] != NULL; i++) {
    if (json_getKeyValuePair(str[i], 0, &keyStartIndex, &keyEndIndex,
                             &valueStartIndex, &valueEndIndex,
                             &valueJsonType) == -1) {
      printf("%2d. %s, get key value pair failure\n\n", i + 1, str[i]);
      puts("-------------------------------------------------------------------"
           "-------------");
      continue;
    }
    printf("%2d. %s\n\n      Key = ", i + 1, str[i]);
    json_util_printSubstring(str[i], keyStartIndex, keyEndIndex);
    printf(" [%d..%d]\n    Value = ", keyStartIndex, keyEndIndex);
    json_util_printSubstring(str[i], valueStartIndex, valueEndIndex);
    printf(" [%d..%d] (%s)\n\n", valueStartIndex, valueEndIndex,
           json_type_toString(valueJsonType));
    puts("---------------------------------------------------------------------"
         "-----------");
  }
  puts("======================================================================="
       "=========\n");
}


x86 assembly (clang, -O0):
<test_json_getKeyValuePair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
lea    -0x320(%rbp),%rdi
lea    0x2963(%rip),%rsi
mov    $0x320,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x324(%rbp)
movslq -0x324(%rbp),%rax
cmpq   $0x0,-0x320(%rbp,%rax,8)
je     1324 <test_json_getKeyValuePair+0x1c4>
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdi
ff
xor    %esi,%esi
lea    -0x328(%rbp),%rdx
lea    -0x32c(%rbp),%rcx
lea    -0x330(%rbp),%r8
lea    -0x334(%rbp),%r9
lea    -0x338(%rbp),%rax
mov    %rax,(%rsp)
call   1080 <json_getKeyValuePair@plt>
cmp    $0xffffffff,%eax
jne    1244 <test_json_getKeyValuePair+0xe4>
mov    -0x324(%rbp),%esi
add    $0x1,%esi
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdx
ff
lea    0xf1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf36(%rip),%rdi
call   1030 <puts@plt>
jmp    1310 <test_json_getKeyValuePair+0x1b0>
mov    -0x324(%rbp),%esi
add    $0x1,%esi
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdx
ff
lea    0xf5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdi
ff
mov    -0x328(%rbp),%esi
mov    -0x32c(%rbp),%edx
call   1040 <json_util_printSubstring@plt>
mov    -0x328(%rbp),%esi
mov    -0x32c(%rbp),%edx
lea    0xf3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdi
ff
mov    -0x330(%rbp),%esi
mov    -0x334(%rbp),%edx
call   1040 <json_util_printSubstring@plt>
mov    -0x330(%rbp),%eax
mov    %eax,-0x340(%rbp)
mov    -0x334(%rbp),%eax
mov    %eax,-0x33c(%rbp)
mov    -0x338(%rbp),%edi
call   1060 <json_type_toString@plt>
mov    -0x340(%rbp),%esi
mov    -0x33c(%rbp),%edx
mov    %rax,%rcx
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    -0x324(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x324(%rbp)
jmp    11b1 <test_json_getKeyValuePair+0x51>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_json_getKeyValuePair>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
lea    0xf06(%rip),%r14
mov    $0x1,%ebx
lea    0x14(%rsp),%r13
lea    0xfd6(%rip),%r15
lea    0x295f(%rip),%r12
jmp    1237 <test_json_getKeyValuePair+0xe7>
cs nopw 0x0(%rax,%rax,1)
lea    0x100a(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
mov    0x1c(%rsp),%edx
mov    %r14,%rdi
call   1040 <json_util_printSubstring@plt>
mov    0x20(%rsp),%esi
mov    0x1c(%rsp),%edx
lea    0xff5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    0x14(%rsp),%edx
mov    %r14,%rdi
call   1040 <json_util_printSubstring@plt>
mov    0x18(%rsp),%ebp
mov    0x14(%rsp),%r14d
mov    0x24(%rsp),%edi
call   1060 <json_type_toString@plt>
lea    0xfdc(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    (%r12,%rbx,8),%r14
add    $0x1,%rbx
cmp    $0xc,%rbx
je     127a <test_json_getKeyValuePair+0x12a>
lea    0x24(%rsp),%rax
mov    %rax,(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
lea    0x20(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    %r13,%r9
call   1070 <json_getKeyValuePair@plt>
cmp    $0xffffffff,%eax
jne    11b0 <test_json_getKeyValuePair+0x60>
lea    0xede(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1221 <test_json_getKeyValuePair+0xd1>
lea    0xf7e(%rip),%rdi
call   1030 <puts@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Test json_getKeyValuePair\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [36 x i8] c" 0123456789 123456789 123456789\0A\00"
@.str.3 = [20 x i8] c"\22name\22 : \22Leon\22\00"
@.str.4 = [18 x i8] c" \22age\22 : 25 \00"
@.str.5 = [24 x i8] c" \22sex\22 : \22male\22 \00"
@.str.6 = [19 x i8] c"\22company\22:\22gemtek\22\00"
@.str.7 = [15 x i8] c"\22obj\22: {obj}\00"
@.str.8 = [18 x i8] c"\22array\22:[array] \00"
@.str.9 = [9 x i8] c"array:[]\00"
@.str.10 = [7 x i8] c"obj:{}\00"
@.str.11 = [20 x i8] c"\22Bool\22 \0A: \0Atrue\00"
@.str.12 = [21 x i8] c"\09\22Bool\22 \09: false\00"
@.str.13 = [16 x i8] c"\22Null\22 : null\00"
@__const.test_json_getKeyValuePair.str = <{ [11 x i8*], [89 x i8*] }> <{ [11 x i8*] [i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 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 ([20 x i8], [20 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i32 0, i32 0)], [89 x i8*] zeroinitializer }>
@.str.14 = [38 x i8] c"%2d. %s, get key value pair failure\0A\0A\00"
@.str.15 = [81 x i8] c"--------------------------------------------------------------------------------\00"
@.str.16 = [22 x i8] c"%2d. %s\0A\0A Key = \00"
@.str.17 = [23 x i8] c" [%d..%d]\0A Value = \00"
@.str.18 = [17 x i8] c" [%d..%d] (%s)\0A\0A\00"
@.str.19 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_getKeyValuePair() {
%1 = alloca [100 x i8*]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 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))
%10 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%11 = bitcast [100 x i8*]* %1 to i8*
store i32 0, i32* %2
br label %12
12: ; preds = %65, %0
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %68
18: ; preds = %12
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @json_getKeyValuePair(i8* %22, i32 0, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %34
25: ; preds = %18
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.14, i64 0, i64 0), i32 %27, i8* %31)
%33 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.15, i64 0, i64 0))
br label %65
34: ; preds = %18
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.16, i64 0, i64 0), i32 %36, i8* %40)
%42 = load i32, i32* %2
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = load i32, i32* %3
%47 = load i32, i32* %4
%48 = call i32 @json_util_printSubstring(i8* %45, i32 %46, i32 %47)
%49 = load i32, i32* %3
%50 = load i32, i32* %4
%51 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.17, i64 0, i64 0), i32 %49, i32 %50)
%52 = load i32, i32* %2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %53
%55 = load i8*, i8** %54
%56 = load i32, i32* %5
%57 = load i32, i32* %6
%58 = call i32 @json_util_printSubstring(i8* %55, i32 %56, i32 %57)
%59 = load i32, i32* %5
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = call i8* @json_type_toString(i32 %61)
%63 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.18, i64 0, i64 0), i32 %59, i32 %60, i8* %62)
%64 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.15, i64 0, i64 0))
br label %65
65: ; preds = %34, %25
%66 = load i32, i32* %2
%67 = add nsw i32 %66, 1
store i32 %67, i32* %2
br label %12
68: ; preds = %12
%69 = call i32 @puts(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.19, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"Test json_getKeyValuePair\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [36 x i8] c" 0123456789 123456789 123456789\0A\00"
@.str.3 = [20 x i8] c"\22name\22 : \22Leon\22\00"
@.str.4 = [18 x i8] c" \22age\22 : 25 \00"
@.str.5 = [24 x i8] c" \22sex\22 : \22male\22 \00"
@.str.6 = [19 x i8] c"\22company\22:\22gemtek\22\00"
@.str.7 = [15 x i8] c"\22obj\22: {obj}\00"
@.str.8 = [18 x i8] c"\22array\22:[array] \00"
@.str.9 = [9 x i8] c"array:[]\00"
@.str.10 = [7 x i8] c"obj:{}\00"
@.str.11 = [20 x i8] c"\22Bool\22 \0A: \0Atrue\00"
@.str.12 = [21 x i8] c"\09\22Bool\22 \09: false\00"
@.str.13 = [16 x i8] c"\22Null\22 : null\00"
@__const.test_json_getKeyValuePair.str = <{ [11 x i8*], [89 x i8*] }> <{ [11 x i8*] [i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 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 ([20 x i8], [20 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i32 0, i32 0)], [89 x i8*] zeroinitializer }>
@.str.14 = [38 x i8] c"%2d. %s, get key value pair failure\0A\0A\00"
@.str.15 = [81 x i8] c"--------------------------------------------------------------------------------\00"
@.str.16 = [22 x i8] c"%2d. %s\0A\0A Key = \00"
@.str.17 = [23 x i8] c" [%d..%d]\0A Value = \00"
@.str.18 = [17 x i8] c" [%d..%d] (%s)\0A\0A\00"
@.str.19 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_getKeyValuePair() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 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 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%9 = bitcast i32* %1 to i8*
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
br label %14
14: ; preds = %0, %39
%15 = phi i64 [ 0, %0 ], [ %19, %39 ]
%16 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %0 ], [ %42, %39 ]
%17 = call i32 @json_getKeyValuePair(i8* %16, i32 0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5)
%18 = icmp eq i32 %17, -1
%19 = add nuw nsw i64 %15, 1
%20 = trunc i64 %19 to i32
br i1 %18, label %21, label %23
21: ; preds = %14
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.14, i64 0, i64 0), i32 %20, i8* %16)
br label %39
23: ; preds = %14
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.16, i64 0, i64 0), i32 %20, i8* %16)
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = call i32 @json_util_printSubstring(i8* %16, i32 %25, i32 %26)
%28 = load i32, i32* %1
%29 = load i32, i32* %2
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.17, i64 0, i64 0), i32 %28, i32 %29)
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = call i32 @json_util_printSubstring(i8* %16, i32 %31, i32 %32)
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i8* @json_type_toString(i32 %36)
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.18, i64 0, i64 0), i32 %34, i32 %35, i8* %37)
br label %39
39: ; preds = %23, %21
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.15, i64 0, i64 0))
%41 = getelementptr inbounds [100 x i8*], [100 x i8*]* bitcast (<{ [11 x i8*], [89 x i8*] }>* @__const.test_json_getKeyValuePair.str to [100 x i8*]*), i64 0, i64 %19
%42 = load i8*, i8** %41
%43 = icmp eq i64 %19, 11
br i1 %43, label %44, label %14
44: ; preds = %39
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.19, i64 0, i64 0))
ret void
}