#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__ json_getString(char *, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
void test_json_getString() {
  puts("Test json_getString");
  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, startIndex, endIndex;
  for (i = 0; str[i] != NULL; i++) {
    startIndex = 0;
    if (json_getString(str[i], startIndex, &endIndex) == 0) {
      printf("%d. %s [%d..%d] is string\n\n", i + 1, str[i], startIndex,
             endIndex);
    } else {
      printf("%d. %s is not string\n\n", i + 1, str[i]);
    }
  }
  puts("");
  char *s = str[0];
  startIndex = 1;
  if (json_getString(s, startIndex, &endIndex) == 0) {
    printf("%s [%d..%d] is string\n\n", s, startIndex, endIndex);
  } else {
    printf("%s [%d..] is not string\n\n", s, startIndex);
  }
  puts("======================================================================="
       "=========\n");
}


x86 assembly (clang, -O0):
<test_json_getString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
lea    -0x320(%rbp),%rdi
lea    0x298f(%rip),%rsi
mov    $0x320,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x324(%rbp)
movslq -0x324(%rbp),%rax
cmpq   $0x0,-0x320(%rbp,%rax,8)
je     1247 <test_json_getString+0x107>
movl   $0x0,-0x328(%rbp)
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdi
ff
mov    -0x328(%rbp),%esi
lea    -0x32c(%rbp),%rdx
call   1050 <json_getString@plt>
cmp    $0x0,%rax
jne    1208 <test_json_getString+0xc8>
mov    -0x324(%rbp),%esi
add    $0x1,%esi
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdx
ff
mov    -0x328(%rbp),%ecx
mov    -0x32c(%rbp),%r8d
lea    0xf28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122e <test_json_getString+0xee>
mov    -0x324(%rbp),%esi
add    $0x1,%esi
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdx
ff
lea    0xf19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1233 <test_json_getString+0xf3>
mov    -0x324(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x324(%rbp)
jmp    1185 <test_json_getString+0x45>
lea    0xef1(%rip),%rdi
call   1030 <puts@plt>
mov    -0x320(%rbp),%rax
mov    %rax,-0x338(%rbp)
movl   $0x1,-0x328(%rbp)
mov    -0x338(%rbp),%rdi
mov    -0x328(%rbp),%esi
lea    -0x32c(%rbp),%rdx
call   1050 <json_getString@plt>
cmp    $0x0,%rax
jne    12b4 <test_json_getString+0x174>
mov    -0x338(%rbp),%rsi
mov    -0x328(%rbp),%edx
mov    -0x32c(%rbp),%ecx
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12cf <test_json_getString+0x18f>
mov    -0x338(%rbp),%rsi
mov    -0x328(%rbp),%edx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_json_getString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xefb(%rip),%r13
mov    $0x1,%ebx
lea    0x4(%rsp),%r14
lea    0xfa9(%rip),%r15
lea    0x297e(%rip),%rbp
lea    0xfb7(%rip),%r12
jmp    11ae <test_json_getString+0x6e>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp,%rbx,8),%r13
add    $0x1,%rbx
cmp    $0x18,%rbx
je     11d8 <test_json_getString+0x98>
mov    %r13,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1060 <json_getString@plt>
test   %rax,%rax
jne    1190 <test_json_getString+0x50>
mov    0x4(%rsp),%r8d
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r13,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    119f <test_json_getString+0x5f>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe7c(%rip),%rdi
lea    0x4(%rsp),%rdx
mov    $0x1,%esi
call   1060 <json_getString@plt>
test   %rax,%rax
je     1219 <test_json_getString+0xd9>
lea    0xf53(%rip),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1237 <test_json_getString+0xf7>
mov    0x4(%rsp),%ecx
lea    0xf04(%rip),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf33(%rip),%rdi
call   1040 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Test json_getString\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_getString.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 = [28 x i8] c"%d. %s [%d..%d] is string\0A\0A\00"
@.str.26 = [23 x i8] c"%d. %s is not string\0A\0A\00"
@.str.27 = [24 x i8] c"%s [%d..%d] is string\0A\0A\00"
@.str.28 = [26 x i8] c"%s [%d..] is not string\0A\0A\00"
@.str.29 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_getString() {
%1 = alloca [100 x i8*]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%8 = bitcast [100 x i8*]* %1 to i8*
store i32 0, i32* %2
br label %9
9: ; preds = %42, %0
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %11
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %45
15: ; preds = %9
store i32 0, i32* %3
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = load i32, i32* %3
%21 = call i64 @json_getString(i8* %19, i32 %20, i32* %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %15
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.25, i64 0, i64 0), i32 %25, i8* %29, i32 %30, i32 %31)
br label %41
33: ; preds = %15
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.26, i64 0, i64 0), i32 %35, i8* %39)
br label %41
41: ; preds = %33, %23
br label %42
42: ; preds = %41
%43 = load i32, i32* %2
%44 = add nsw i32 %43, 1
store i32 %44, i32* %2
br label %9
45: ; preds = %9
%46 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%47 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 0
%48 = load i8*, i8** %47
store i8* %48, i8** %5
store i32 1, i32* %3
%49 = load i8*, i8** %5
%50 = load i32, i32* %3
%51 = call i64 @json_getString(i8* %49, i32 %50, i32* %4)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %45
%54 = load i8*, i8** %5
%55 = load i32, i32* %3
%56 = load i32, i32* %4
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.27, i64 0, i64 0), i8* %54, i32 %55, i32 %56)
br label %62
58: ; preds = %45
%59 = load i8*, i8** %5
%60 = load i32, i32* %3
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.28, i64 0, i64 0), i8* %59, i32 %60)
br label %62
62: ; preds = %58, %53
%63 = call i32 @puts(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.29, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Test json_getString\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_getString.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 = [28 x i8] c"%d. %s [%d..%d] is string\0A\0A\00"
@.str.26 = [23 x i8] c"%d. %s is not string\0A\0A\00"
@.str.27 = [24 x i8] c"%s [%d..%d] is string\0A\0A\00"
@.str.28 = [26 x i8] c"%s [%d..] is not string\0A\0A\00"
@.str.29 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_getString() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 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 i32* %1 to i8*
br label %5
5: ; preds = %0, %18
%6 = phi i64 [ 0, %0 ], [ %10, %18 ]
%7 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %0 ], [ %20, %18 ]
%8 = call i64 @json_getString(i8* %7, i32 0, i32* %1)
%9 = icmp eq i64 %8, 0
%10 = add nuw nsw i64 %6, 1
br i1 %9, label %11, label %15
11: ; preds = %5
%12 = load i32, i32* %1
%13 = trunc i64 %10 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.25, i64 0, i64 0), i32 %13, i8* %7, i32 0, i32 %12)
br label %18
15: ; preds = %5
%16 = trunc i64 %10 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.26, i64 0, i64 0), i32 %16, i8* %7)
br label %18
18: ; preds = %11, %15
%19 = getelementptr inbounds [100 x i8*], [100 x i8*]* bitcast (<{ [23 x i8*], [77 x i8*] }>* @__const.test_json_getString.str to [100 x i8*]*), i64 0, i64 %10
%20 = load i8*, i8** %19
%21 = icmp eq i64 %10, 23
br i1 %21, label %22, label %5
22: ; preds = %18
%23 = call i32 @putchar(i32 10)
%24 = call i64 @json_getString(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 1, i32* %1)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %1
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.27, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %27)
br label %31
29: ; preds = %22
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.28, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %31
31: ; preds = %29, %26
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.29, i64 0, i64 0))
ret void
}