#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 indexAt(int);
void iterate_children(int *license_hits, int index, int height, int heap_sz) {
  int leftChild;
  int i;
  leftChild = (index - 4 + 2) * 4;
  if (leftChild >= heap_sz) {
    int arrayIndex = index - indexAt(height);
    license_hits[arrayIndex] += 1;
    return;
  }
  i = 0;
  while (i < 4) {
    iterate_children(license_hits, leftChild + i, height + 1, heap_sz);
    i++;
  }
}


x86 assembly (clang, -O0):
<iterate_children>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
add    $0x2,%eax
shl    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     117e <iterate_children+0x5e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <indexAt@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    11b5 <iterate_children+0x95>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11b5 <iterate_children+0x95>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
call   1030 <iterate_children@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1185 <iterate_children+0x65>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterate_children>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
lea    -0x8(,%rbx,4),%esi
cmp    %ecx,%esi
jge    1188 <iterate_children+0x68>
mov    %ecx,%r15d
shl    $0x2,%ebx
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%edx
call   1030 <iterate_children@plt>
lea    -0x7(%rbx),%esi
mov    %r14,%rdi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1030 <iterate_children@plt>
lea    -0x6(%rbx),%esi
mov    %r14,%rdi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1030 <iterate_children@plt>
add    $0xfffffffb,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <iterate_children@plt>
mov    %ebp,%edi
call   1040 <indexAt@plt>
sub    %eax,%ebx
movslq %ebx,%rax
addl   $0x1,(%r14,%rax,4)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @iterate_children(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 4
%14 = add nsw i32 %13, 2
%15 = mul nsw i32 %14, 4
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = load i32, i32* %8
%18 = icmp sge i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %4
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = call i32 @indexAt(i32 %21)
%23 = sub nsw i32 %20, %22
store i32 %23, i32* %11
%24 = load i32*, i32** %5
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1
store i32 %29, i32* %27
br label %44
30: ; preds = %4
store i32 0, i32* %10
br label %31
31: ; preds = %34, %30
%32 = load i32, i32* %10
%33 = icmp slt i32 %32, 4
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = load i32*, i32** %5
%36 = load i32, i32* %9
%37 = load i32, i32* %10
%38 = add nsw i32 %36, %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %8
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %31
44: ; preds = %19, %31
ret void
}

LLVM IR (-O2):
define void @iterate_children(i32* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = shl i32 %1, 2
%6 = add i32 %5, -8
%7 = icmp slt i32 %6, %3
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = add nsw i32 %2, 1
tail call void @iterate_children(i32* %0, i32 %6, i32 %9, i32 %3)
%10 = add i32 %5, -7
tail call void @iterate_children(i32* %0, i32 %10, i32 %9, i32 %3)
%11 = add i32 %5, -6
tail call void @iterate_children(i32* %0, i32 %11, i32 %9, i32 %3)
%12 = add i32 %5, -5
tail call void @iterate_children(i32* %0, i32 %12, i32 %9, i32 %3)
br label %20
13: ; preds = %4
%14 = tail call i32 @indexAt(i32 %2)
%15 = sub nsw i32 %1, %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %0, i64 %16
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
br label %20
20: ; preds = %8, %13
ret void
}