#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, int, int, char *);
void map(int array[], int len, char *(*fn)(int)) {
  char *resarray[len];
  int i;
  for (i = 0; i < len; i++) {
    resarray[i] = fn(array[i]);
    printf("Array[%d] is %d, Result[%d] is %s\n", i, array[i], i, resarray[i]);
  }
}


x86 assembly (clang, -O0):
<map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b0 <map+0xa0>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    (%rcx,%rdx,4),%edi
call   *%rax
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%esi
mov    -0x8(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
mov    -0x2c(%rbp),%ecx
movslq -0x2c(%rbp),%rdi
mov    (%rax,%rdi,8),%r8
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1151 <map+0x41>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %esi,%esi
jle    1153 <map+0x43>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%r13d
xor    %ebx,%ebx
lea    0xed1(%rip),%r12
nop
mov    (%r15,%rbx,4),%edi
call   *%r14
mov    (%r15,%rbx,4),%edx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebx,%ecx
mov    %rax,%r8
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1130 <map+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Array[%d] is %d, Result[%d] is %s\0A\00"
define void @map(i32* %0, i32 %1, i8* (i32)* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8* (i32)*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* (i32)* %2, i8* (i32)** %6
%10 = load i32, i32* %5
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8*, i64 %11
store i64 %11, i64* %8
store i32 0, i32* %9
br label %14
14: ; preds = %41, %3
%15 = load i32, i32* %9
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %44
18: ; preds = %14
%19 = load i8* (i32)*, i8* (i32)** %6
%20 = load i32*, i32** %4
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = call i8* %19(i32 %24)
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %13, i64 %27
store i8* %25, i8** %28
%29 = load i32, i32* %9
%30 = load i32*, i32** %4
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %9
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %13, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %34, i32 %35, i8* %39)
br label %41
41: ; preds = %18
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %14
44: ; preds = %14
%45 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"Array[%d] is %d, Result[%d] is %s\0A\00"
define void @map(i32* nocapture %0, i32 %1, i8* (i32)* nocapture %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %15, %7 ]
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = tail call i8* %2(i32 %10)
%12 = load i32, i32* %9
%13 = trunc i64 %8 to i32
%14 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %12, i32 %13, i8* %11)
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %17, label %7
17: ; preds = %7, %3
ret void
}