#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 */
char *getNextFromJSONArray(char const *, char const *, int *);
int getCountFromJSONArray(const char *data) {
  int c = 0;
  const char *next = data;
  int nextSize = 0;
  while ((next = getNextFromJSONArray(data, next + nextSize, &nextSize)) !=
         NULL) {
    if (nextSize > 0) {
      c++;
    } else {
      break;
    }
  }
  return c;
}


x86 assembly (clang, -O0):
<getCountFromJSONArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <getNextFromJSONArray@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     117a <getCountFromJSONArray+0x6a>
cmpl   $0x0,-0x1c(%rbp)
jle    1170 <getCountFromJSONArray+0x60>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <getCountFromJSONArray+0x65>
jmp    117a <getCountFromJSONArray+0x6a>
jmp    1132 <getCountFromJSONArray+0x22>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCountFromJSONArray>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
xor    %ecx,%ecx
mov    $0xffffffff,%ebp
lea    0xc(%rsp),%r14
mov    %rdi,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%esi
add    %rax,%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <getNextFromJSONArray@plt>
add    $0x1,%ebp
test   %rax,%rax
je     1160 <getCountFromJSONArray+0x50>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jg     1140 <getCountFromJSONArray+0x30>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getCountFromJSONArray(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
store i8* %6, i8** %4
store i32 0, i32* %5
br label %7
7: ; preds = %22, %1
%8 = load i8*, i8** %2
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = call i8* @getNextFromJSONArray(i8* %8, i8* %12, i32* %5)
store i8* %13, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %23
15: ; preds = %7
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %22
21: ; preds = %15
br label %23
22: ; preds = %18
br label %7
23: ; preds = %21, %7
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @getCountFromJSONArray(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %4, %1
%5 = phi i32 [ 0, %1 ], [ %12, %4 ]
%6 = phi i32 [ 0, %1 ], [ %15, %4 ]
%7 = phi i8* [ %0, %1 ], [ %10, %4 ]
%8 = zext i32 %5 to i64
%9 = getelementptr inbounds i8, i8* %7, i64 %8
%10 = call i8* @getNextFromJSONArray(i8* %0, i8* %9, i32* %2)
%11 = icmp ne i8* %10, null
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
%14 = select i1 %11, i1 %13, i1 false
%15 = add nuw nsw i32 %6, 1
br i1 %14, label %4, label %16
16: ; preds = %4
ret i32 %6
}