#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 /*<<< orphan*/ free(char *);
scalar_t__ json_util_allocSubstring(char const *, int, int, char **);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
void test_json_util_allocSubstring() {
  puts("Test json_util_allocSubstring");
  puts("======================================================================="
       "=========");
  const char *str[100] = {"abcdefg", "12345678"};
  int i;
  for (i = 0; str[i] != NULL; i++) {
    char *substring;
    if (json_util_allocSubstring(str[i], 1, 3, &substring) != 0) {
      puts("json_util_allocSubstring failure");
      return;
    }
    printf("%s\n", substring);
    free(substring);
  }
  puts("======================================================================="
       "=========\n");
}


x86 assembly (clang, -O0):
<test_json_util_allocSubstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
lea    -0x320(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1060 <memset@plt>
lea    0xee2(%rip),%rax
mov    %rax,-0x320(%rbp)
lea    0xedc(%rip),%rax
mov    %rax,-0x318(%rbp)
movl   $0x0,-0x324(%rbp)
movslq -0x324(%rbp),%rax
cmpq   $0x0,-0x320(%rbp,%rax,8)
je     1235 <test_json_util_allocSubstring+0xe5>
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdi
ff
mov    $0x1,%esi
mov    $0x3,%edx
lea    -0x330(%rbp),%rcx
call   1070 <json_util_allocSubstring@plt>
cmp    $0x0,%rax
je     1202 <test_json_util_allocSubstring+0xb2>
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
jmp    1241 <test_json_util_allocSubstring+0xf1>
mov    -0x330(%rbp),%rsi
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
mov    -0x330(%rbp),%rdi
call   1030 <free@plt>
mov    -0x324(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x324(%rbp)
jmp    11ac <test_json_util_allocSubstring+0x5c>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_json_util_allocSubstring>:
push   %r15
push   %r14
push   %rbx
sub    $0x330,%rsp
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
lea    0xeaf(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rdi
mov    $0x310,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xee3(%rip),%rdi
mov    %rdi,0x10(%rsp)
lea    0x18(%rsp),%rbx
lea    0xeda(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0x8(%rsp),%r15
lea    0xef3(%rip),%r14
xchg   %ax,%ax
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r15,%rcx
call   1070 <json_util_allocSubstring@plt>
test   %rax,%rax
jne    11f3 <test_json_util_allocSubstring+0xa3>
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    11b0 <test_json_util_allocSubstring+0x60>
lea    0xeb4(%rip),%rdi
jmp    11fa <test_json_util_allocSubstring+0xaa>
lea    0xe86(%rip),%rdi
call   1040 <puts@plt>
add    $0x330,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Test json_util_allocSubstring\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [8 x i8] c"abcdefg\00"
@.str.3 = [9 x i8] c"12345678\00"
@.str.4 = [33 x i8] c"json_util_allocSubstring failure\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_util_allocSubstring() {
%1 = alloca [100 x i8*]
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast [100 x i8*]* %1 to i8*
%7 = bitcast i8* %6 to <{ i8*, i8*, [98 x i8*] }>*
%8 = getelementptr inbounds <{ i8*, i8*, [98 x i8*] }>, <{ i8*, i8*, [98 x i8*] }>* %7, i32 0, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds <{ i8*, i8*, [98 x i8*] }>, <{ i8*, i8*, [98 x i8*] }>* %7, i32 0, i32 1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8** %9
store i32 0, i32* %2
br label %10
10: ; preds = %30, %0
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %33
16: ; preds = %10
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = call i64 @json_util_allocSubstring(i8* %20, i32 1, i32 3, i8** %3)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %35
25: ; preds = %16
%26 = load i8*, i8** %3
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %3
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %25
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %10
33: ; preds = %10
%34 = call i32 @puts(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %33, %23
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Test json_util_allocSubstring\00"
@.str.1 = [81 x i8] c"================================================================================\00"
@.str.2 = [8 x i8] c"abcdefg\00"
@.str.3 = [9 x i8] c"12345678\00"
@.str.4 = [33 x i8] c"json_util_allocSubstring failure\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_util_allocSubstring() {
%1 = alloca [100 x i8*]
%2 = alloca i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast [100 x i8*]* %1 to i8*
%6 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 2
%7 = bitcast i8** %6 to i8*
%8 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %9
%10 = bitcast i8** %2 to i8*
br label %11
11: ; preds = %0, %18
%12 = phi i64 [ 0, %0 ], [ %23, %18 ]
%13 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %0 ], [ %25, %18 ]
%14 = call i64 @json_util_allocSubstring(i8* %13, i32 1, i32 3, i8** %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %29
18: ; preds = %11
%19 = load i8*, i8** %2
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %2
%22 = call i32 @free(i8* %21)
%23 = add nuw i64 %12, 1
%24 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %11
27: ; preds = %18
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.6, i64 0, i64 0))
br label %29
29: ; preds = %16, %27
ret void
}