#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*/ exit(int);
char **malloc(int);
int /*<<< orphan*/ perror(char *);
char *stub1();
char **applyfuncmap(char *(*fmap[])(void)) {
  int i;
  int sz = 0;
  char **ret;
  while (fmap[sz] != NULL)
    ++sz;
  ret = malloc((sz + 1) * sizeof(char *));
  if (ret == NULL) {
    perror("malloc");
    exit(1);
  }
  for (i = 0; i < sz; i++)
    ret[i] = fmap[i]();
  ret[i] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<applyfuncmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1164 <applyfuncmap+0x34>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <applyfuncmap+0x13>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119c <applyfuncmap+0x6c>
lea    0xe73(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d7 <applyfuncmap+0xa7>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
call   *(%rax,%rcx,8)
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a3 <applyfuncmap+0x73>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<applyfuncmap>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
mov    $0x1,%r13d
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%r13
cmpq   $0x0,(%r15,%rdi,1)
lea    0x8(%rdi),%rdi
jne    1150 <applyfuncmap+0x20>
call   1030 <malloc@plt>
test   %rax,%rax
je     11ad <applyfuncmap+0x7d>
mov    %rax,%r14
test   %r13d,%r13d
je     1196 <applyfuncmap+0x66>
mov    %r13,%r12
neg    %r12
neg    %r13d
xor    %ebx,%ebx
nopl   0x0(%rax)
call   *(%r15,%rbx,8)
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <applyfuncmap+0x50>
mov    %r12d,%eax
jmp    1198 <applyfuncmap+0x68>
xor    %eax,%eax
movq   $0x0,(%r14,%rax,8)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe4c(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
define i8** @applyfuncmap(i8* ()** %0) {
%2 = alloca i8* ()**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i8* ()** %0, i8* ()*** %2
store i32 0, i32* %4
br label %6
6: ; preds = %13, %1
%7 = load i8* ()**, i8* ()*** %2
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8* ()*, i8* ()** %7, i64 %9
%11 = load i8* ()*, i8* ()** %10
%12 = icmp ne i8* ()* %11, null
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
br label %6
16: ; preds = %6
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call i8** @malloc(i32 %21)
store i8** %22, i8*** %5
%23 = load i8**, i8*** %5
%24 = icmp eq i8** %23, null
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %16
store i32 0, i32* %3
br label %29
29: ; preds = %44, %28
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %47
33: ; preds = %29
%34 = load i8* ()**, i8* ()*** %2
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8* ()*, i8* ()** %34, i64 %36
%38 = load i8* ()*, i8* ()** %37
%39 = call i8* %38()
%40 = load i8**, i8*** %5
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
store i8* %39, i8** %43
br label %44
44: ; preds = %33
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %29
47: ; preds = %29
%48 = load i8**, i8*** %5
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* null, i8** %51
%52 = load i8**, i8*** %5
ret i8** %52
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
define i8** @applyfuncmap(i8* ()** nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %7, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8* ()*, i8* ()** %0, i64 %3
%5 = load i8* ()*, i8* ()** %4
%6 = icmp eq i8* ()* %5, null
%7 = add nuw i64 %3, 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = trunc i64 %3 to i32
%10 = shl i32 %9, 3
%11 = add i32 %10, 8
%12 = tail call i8** @malloc(i32 %11)
%13 = icmp eq i8** %12, null
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = icmp eq i32 %9, 0
br i1 %15, label %31, label %16
16: ; preds = %14
%17 = and i64 %3, 4294967295
br label %21
18: ; preds = %8
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %16, %21
%22 = phi i64 [ 0, %16 ], [ %27, %21 ]
%23 = getelementptr inbounds i8* ()*, i8* ()** %0, i64 %22
%24 = load i8* ()*, i8* ()** %23
%25 = tail call i8* %24()
%26 = getelementptr inbounds i8*, i8** %12, i64 %22
store i8* %25, i8** %26
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, %17
br i1 %28, label %29, label %21
29: ; preds = %21
%30 = and i64 %3, 4294967295
br label %31
31: ; preds = %14, %29
%32 = phi i64 [ %30, %29 ], [ 0, %14 ]
%33 = getelementptr inbounds i8*, i8** %12, i64 %32
store i8* null, i8** %33
ret i8** %12
}