#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_array_getValueByPosition(char *, int, int, int *, int *, int *);
char *json_type_toString(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strlen(char *);
void test_json_array_getValueByPosition() {
  puts("Test json_array_getValueByPosition");
  puts("======================================================================="
       "=========");
  char *str = "abc[\n"
              "    \"Hello\\\"\",		\n"
              "    { object }    ,\n"
              "    [ array ],\n"
              "    [12345[12345[12345]]]\n,"
              "    \"\\\"\\\\\\/\\b\\f\\n\\r\\t\",\n"
              "    10.5E+13,\n"
              "    true,\n"
              "    false, \n"
              "    null\n"
              "]]]]";
  printf("Array (%lu) = %s\n\n", strlen(str), str);
  int i, valueStartIndex, valueEndIndex, valueJsonType;
  for (i = 0; i < 10; i++) {
    if (json_array_getValueByPosition(str, 3, i, &valueStartIndex,
                                      &valueEndIndex, &valueJsonType) == -1) {
      printf("Array[%d] is not found\n\n", i);
      continue;
    }
    printf("Array[%d] = ", i);
    int j;
    for (j = valueStartIndex; j <= valueEndIndex; j++) {
      printf("%c", str[j]);
    }
    printf(" (%s)\n\n", json_type_toString(valueJsonType));
  }
  puts("======================================================================="
       "=========\n");
}


x86 assembly (clang, -O0):
<test_json_array_getValueByPosition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
lea    0xefd(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
lea    0xf81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1257 <test_json_array_getValueByPosition+0x107>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x3,%esi
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
call   1070 <json_array_getValueByPosition@plt>
cmp    $0xffffffff,%eax
jne    11e5 <test_json_array_getValueByPosition+0x95>
mov    -0xc(%rbp),%esi
lea    0xf4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1249 <test_json_array_getValueByPosition+0xf9>
mov    -0xc(%rbp),%esi
lea    0xf4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1230 <test_json_array_getValueByPosition+0xe0>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xf30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fc <test_json_array_getValueByPosition+0xac>
mov    -0x18(%rbp),%edi
call   1060 <json_type_toString@plt>
mov    %rax,%rsi
lea    0xf0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119f <test_json_array_getValueByPosition+0x4f>
lea    0xef8(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_json_array_getValueByPosition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
lea    0xea2(%rip),%rdi
call   1040 <puts@plt>
lea    0xee7(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xf76(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x14(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
xor    %ebp,%ebp
jmp    11e2 <test_json_array_getValueByPosition+0x82>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%edi
call   1070 <json_type_toString@plt>
lea    0xf7b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebp
cmp    $0xa,%ebp
je     1252 <test_json_array_getValueByPosition+0xf2>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %r15,%r8
mov    %r12,%r9
call   1080 <json_array_getValueByPosition@plt>
cmp    $0xffffffff,%eax
je     1240 <test_json_array_getValueByPosition+0xe0>
lea    0xf38(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movslq 0x14(%rsp),%r13
cmp    0xc(%rsp),%r13d
jg     11c0 <test_json_array_getValueByPosition+0x60>
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%r13,%rbx,1),%edi
call   1030 <putchar@plt>
lea    0x1(%r13),%rax
movslq 0xc(%rsp),%rcx
cmp    %rcx,%r13
mov    %rax,%r13
jl     1220 <test_json_array_getValueByPosition+0xc0>
jmp    11c0 <test_json_array_getValueByPosition+0x60>
xchg   %ax,%ax
lea    0xede(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11da <test_json_array_getValueByPosition+0x7a>
lea    0xefa(%rip),%rdi
call   1040 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Test json_array_getValueByPosition\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [158 x i8] c"abc[\0A \22Hello\\\22\22,\09\09\0A { object } ,\0A [ array ],\0A [12345[12345[12345]]]\0A, \22\\\22\\\\\\/\\b\\f\\n\\r\\t\22,\0A 10.5E+13,\0A true,\0A false, \0A null\0A]]]]\00"
@.str.3 = [19 x i8] c"Array (%lu) = %s\0A\0A\00"
@.str.4 = [25 x i8] c"Array[%d] is not found\0A\0A\00"
@.str.5 = [13 x i8] c"Array[%d] = \00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [8 x i8] c" (%s)\0A\0A\00"
@.str.8 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_array_getValueByPosition() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
store i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i8** %1
%9 = load i8*, i8** %1
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %10, i8* %11)
store i32 0, i32* %2
br label %13
13: ; preds = %47, %0
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 10
br i1 %15, label %16, label %50
16: ; preds = %13
%17 = load i8*, i8** %1
%18 = load i32, i32* %2
%19 = call i32 @json_array_getValueByPosition(i8* %17, i32 3, i32 %18, i32* %3, i32* %4, i32* %5)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %22)
br label %47
24: ; preds = %16
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %3
store i32 %27, i32* %6
br label %28
28: ; preds = %40, %24
%29 = load i32, i32* %6
%30 = load i32, i32* %4
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %43
32: ; preds = %28
%33 = load i8*, i8** %1
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, 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.6, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %32
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %28
43: ; preds = %28
%44 = load i32, i32* %5
%45 = call i8* @json_type_toString(i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %43, %21
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %13
50: ; preds = %13
%51 = call i32 @puts(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"Test json_array_getValueByPosition\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [158 x i8] c"abc[\0A \22Hello\\\22\22,\09\09\0A { object } ,\0A [ array ],\0A [12345[12345[12345]]]\0A, \22\\\22\\\\\\/\\b\\f\\n\\r\\t\22,\0A 10.5E+13,\0A true,\0A false, \0A null\0A]]]]\00"
@.str.3 = [19 x i8] c"Array (%lu) = %s\0A\0A\00"
@.str.4 = [25 x i8] c"Array[%d] is not found\0A\0A\00"
@.str.5 = [13 x i8] c"Array[%d] = \00"
@.str.7 = [8 x i8] c" (%s)\0A\0A\00"
@.str.8 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_array_getValueByPosition() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %6, i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0))
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
br label %11
11: ; preds = %0, %38
%12 = phi i32 [ 0, %0 ], [ %39, %38 ]
%13 = call i32 @json_array_getValueByPosition(i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %12, i32* %1, i32* %2, i32* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %12)
br label %38
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = icmp sgt i32 %19, %20
br i1 %21, label %34, label %22
22: ; preds = %17
%23 = sext i32 %19 to i64
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ %23, %22 ], [ %30, %24 ]
%26 = getelementptr inbounds [158 x i8], [158 x i8]* @.str.2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = call i32 @putchar(i32 %28)
%30 = add nsw i64 %25, 1
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %25, %32
br i1 %33, label %24, label %34
34: ; preds = %24, %17
%35 = load i32, i32* %3
%36 = call i8* @json_type_toString(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %34, %15
%39 = add nuw nsw i32 %12, 1
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %11
41: ; preds = %38
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.8, i64 0, i64 0))
ret void
}