#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_util_getNextCharacter(char *, int *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ puts(char *);
void test_json_util_getNextCharacter() {
  puts("Test json_util_getNextCharacter");
  puts("======================================================================="
       "=========");
  puts("    0123456789 123456789 123456789\n");
  char *str[100] = {"        a         b", "c       d     ", "abc",
                    "a    b   bcd   "};
  int i;
  for (i = 0; str[i] != NULL; i++) {
    printf("%2d. %s\n\n", i + 1, str[i]);
    int j = 0;
    for (;;) {
      if (json_util_getNextCharacter(str[i], &j) == -1) {
        break;
      }
      printf("    str[%d] = %c\n", j, str[i][j]);
      j++;
    }
    puts("");
  }
  puts("======================================================================="
       "=========\n");
}


x86 assembly (clang, -O0):
<test_json_util_getNextCharacter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
lea    -0x320(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1050 <memset@plt>
lea    0xf0c(%rip),%rax
mov    %rax,-0x320(%rbp)
lea    0xf12(%rip),%rax
mov    %rax,-0x318(%rbp)
lea    0xf13(%rip),%rax
mov    %rax,-0x310(%rbp)
lea    0xf09(%rip),%rax
mov    %rax,-0x308(%rbp)
movl   $0x0,-0x324(%rbp)
movslq -0x324(%rbp),%rax
cmpq   $0x0,-0x320(%rbp,%rax,8)
je     1295 <test_json_util_getNextCharacter+0x155>
mov    -0x324(%rbp),%esi
add    $0x1,%esi
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdx
ff
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x328(%rbp)
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdi
ff
lea    -0x328(%rbp),%rsi
call   1060 <json_util_getNextCharacter@plt>
cmp    $0xffffffff,%eax
jne    1233 <test_json_util_getNextCharacter+0xf3>
jmp    1275 <test_json_util_getNextCharacter+0x135>
mov    -0x328(%rbp),%esi
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rax
ff
movslq -0x328(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x328(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x328(%rbp)
jmp    120a <test_json_util_getNextCharacter+0xca>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
mov    -0x324(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x324(%rbp)
jmp    11c4 <test_json_util_getNextCharacter+0x84>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_json_util_getNextCharacter>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x330,%rsp
lea    0xe99(%rip),%rdi
call   1040 <puts@plt>
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
lea    0xef2(%rip),%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%rdi
mov    $0x300,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xef9(%rip),%rbx
mov    %rbx,0x10(%rsp)
lea    0xf01(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xf04(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xefc(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xf00(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xefe(%rip),%r12
xor    %r13d,%r13d
jmp    11f4 <test_json_util_getNextCharacter+0xa4>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp,%r13,8),%rbx
test   %rbx,%rbx
je     123a <test_json_util_getNextCharacter+0xea>
add    $0x1,%r13
mov    %r14,%rdi
mov    %r13d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,0xc(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <json_util_getNextCharacter@plt>
cmp    $0xffffffff,%eax
je     11e0 <test_json_util_getNextCharacter+0x90>
movslq 0xc(%rsp),%rsi
movsbl (%rbx,%rsi,1),%edx
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
addl   $0x1,0xc(%rsp)
jmp    1210 <test_json_util_getNextCharacter+0xc0>
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
add    $0x330,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Test json_util_getNextCharacter\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" a b\00"
@.str.4 = [15 x i8] c"c d \00"
@.str.5 = [4 x i8] c"abc\00"
@.str.6 = [16 x i8] c"a b bcd \00"
@.str.7 = [10 x i8] c"%2d. %s\0A\0A\00"
@.str.8 = [18 x i8] c" str[%d] = %c\0A\00"
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_util_getNextCharacter() {
%1 = alloca [100 x i8*]
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 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 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%7 = bitcast [100 x i8*]* %1 to i8*
%8 = bitcast i8* %7 to <{ i8*, i8*, i8*, i8*, [96 x i8*] }>*
%9 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, [96 x i8*] }>, <{ i8*, i8*, i8*, i8*, [96 x i8*] }>* %8, i32 0, i32 0
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, [96 x i8*] }>, <{ i8*, i8*, i8*, i8*, [96 x i8*] }>* %8, i32 0, i32 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, [96 x i8*] }>, <{ i8*, i8*, i8*, i8*, [96 x i8*] }>* %8, i32 0, i32 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds <{ i8*, i8*, i8*, i8*, [96 x i8*] }>, <{ i8*, i8*, i8*, i8*, [96 x i8*] }>* %8, i32 0, i32 3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i32 0, i32 0), i8** %12
store i32 0, i32* %2
br label %13
13: ; preds = %51, %0
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %54
19: ; preds = %13
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 %21, i8* %25)
store i32 0, i32* %3
br label %27
27: ; preds = %35, %19
%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 @json_util_getNextCharacter(i8* %31, i32* %3)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %35
34: ; preds = %27
br label %49
35: ; preds = %27
%36 = load i32, i32* %3
%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 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i32 %36, i32 %45)
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %27
49: ; preds = %34
%50 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
br label %51
51: ; preds = %49
%52 = load i32, i32* %2
%53 = add nsw i32 %52, 1
store i32 %53, i32* %2
br label %13
54: ; preds = %13
%55 = call i32 @puts(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Test json_util_getNextCharacter\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" a b\00"
@.str.4 = [15 x i8] c"c d \00"
@.str.5 = [4 x i8] c"abc\00"
@.str.6 = [16 x i8] c"a b bcd \00"
@.str.7 = [10 x i8] c"%2d. %s\0A\0A\00"
@.str.8 = [18 x i8] c" str[%d] = %c\0A\00"
@.str.10 = [82 x i8] c"================================================================================\0A\00"
define void @test_json_util_getNextCharacter() {
%1 = alloca [100 x i8*]
%2 = alloca i32
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 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 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%6 = bitcast [100 x i8*]* %1 to i8*
%7 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 4
%8 = bitcast i8** %7 to i8*
%9 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8** %12
%13 = bitcast i32* %2 to i8*
br label %14
14: ; preds = %0, %33
%15 = phi i64 [ 0, %0 ], [ %17, %33 ]
%16 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %0 ], [ %36, %33 ]
%17 = add nuw nsw i64 %15, 1
%18 = trunc i64 %17 to i32
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 %18, i8* %16)
store i32 0, i32* %2
%20 = call i32 @json_util_getNextCharacter(i8* %16, i32* %2)
%21 = icmp eq i32 %20, -1
br i1 %21, label %33, label %22
22: ; preds = %14, %22
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %16, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i32 %23, i32 %27)
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
%31 = call i32 @json_util_getNextCharacter(i8* %16, i32* %2)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %22
33: ; preds = %22, %14
%34 = call i32 @putchar(i32 10)
%35 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %17
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %14
38: ; preds = %33
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
ret void
}