#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*/ printf(char *, int);
void populateArray(int *array, size_t arraySize,
                   size_t (*getNextValue)(size_t)) {
  int value;
  size_t i = 0;
  for (; i < arraySize; i++) {
    value = getNextValue(i);
    array[i] = value;
    printf("%d\n", value);
  }
}


x86 assembly (clang, -O0):
<populateArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1175 <populateArray+0x65>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rdi
call   *%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%esi
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    112c <populateArray+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<populateArray>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     114d <populateArray+0x3d>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xed0(%rip),%r13
mov    %rbx,%rdi
call   *%r14
mov    %eax,(%r15,%rbx,4)
mov    %r13,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <populateArray+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define void @populateArray(i32* %0, i64 %1, i64 (i64)* %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64 (i64)*
%7 = alloca i32
%8 = alloca i64
store i32* %0, i32** %4
store i64 %1, i64* %5
store i64 (i64)* %2, i64 (i64)** %6
store i64 0, i64* %8
br label %9
9: ; preds = %24, %3
%10 = load i64, i64* %8
%11 = load i64, i64* %5
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i64 (i64)*, i64 (i64)** %6
%15 = load i64, i64* %8
%16 = call i64 %14(i64 %15)
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = load i32*, i32** %4
%20 = load i64, i64* %8
%21 = getelementptr inbounds i32, i32* %19, i64 %20
store i32 %18, i32* %21
%22 = load i32, i32* %7
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %13
%25 = load i64, i64* %8
%26 = add i64 %25, 1
store i64 %26, i64* %8
br label %9
27: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define void @populateArray(i32* nocapture writeonly %0, i64 %1, i64 (i64)* nocapture %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %13, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %11, %5 ], [ 0, %3 ]
%7 = tail call i64 %2(i64 %6)
%8 = trunc i64 %7 to i32
%9 = getelementptr inbounds i32, i32* %0, i64 %6
store i32 %8, i32* %9
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%11 = add nuw i64 %6, 1
%12 = icmp eq i64 %11, %1
br i1 %12, label %13, label %5
13: ; preds = %5, %3
ret void
}