#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 */
typedef int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ *all_factorials(int);
int /*<<< orphan*/ factorial(int);
int /*<<< orphan*/ factorial_iterative(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/);
int main() {
  int set[10] = {1, 2, 3, 5, 8, 10, 12, 15, 18, 20};
  for (int c = 0; c < 10; c++) {
    if (c % 2 == 0)
      printf("factorial of %d: %ld\n", set[c], factorial(set[c]));
    else
      printf("factorial of %d: %ld\n", set[c], factorial_iterative(set[c]));
  }
  int n = 20;
  int lvl;
  uint64_t *results = (uint64_t *)malloc(n * sizeof(uint64_t));
  results = all_factorials(n);
  for (int c = 0; c < 20; c++) {
    lvl = (n - c) % n;
    if (!lvl)
      lvl = 20;
    printf("%d: %ld\n", lvl, results[c]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x28,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    1213 <main+0xb3>
mov    -0x34(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d7 <main+0x77>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x50(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1030 <factorial@plt>
mov    -0x50(%rbp),%esi
mov    %eax,%edx
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
jmp    1200 <main+0xa0>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x54(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1080 <factorial_iterative@plt>
mov    -0x54(%rbp),%esi
mov    %eax,%edx
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
jmp    1205 <main+0xa5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118b <main+0x2b>
movl   $0x14,-0x38(%rbp)
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%edi
call   1050 <all_factorials@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x14,-0x4c(%rbp)
jge    1290 <main+0x130>
mov    -0x38(%rbp),%eax
sub    -0x4c(%rbp),%eax
cltd
idivl  -0x38(%rbp)
mov    %edx,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    1268 <main+0x108>
movl   $0x14,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdb8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1240 <main+0xe0>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xea1(%rip),%rbx
xor    %ebp,%ebp
lea    0xec0(%rip),%r14
jmp    1190 <main+0x40>
nopw   0x0(%rax,%rax,1)
call   1070 <factorial_iterative@plt>
mov    %eax,%edx
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
add    $0x1,%rbp
add    $0x4,%rbx
cmp    $0xa,%rbp
je     11a3 <main+0x53>
mov    (%rbx),%r15d
mov    %r15d,%edi
test   $0x1,%bpl
jne    1170 <main+0x20>
call   1030 <factorial@plt>
jmp    1175 <main+0x25>
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    $0x14,%r15d
mov    $0x14,%edi
call   1050 <all_factorials@plt>
mov    %rax,%r12
mov    $0x14,%bpl
xor    %ebx,%ebx
lea    0xe69(%rip),%r14
nopl   0x0(%rax)
movzbl %bpl,%ebp
imul   $0xcd,%ebp,%eax
shr    $0xa,%eax
and    $0xfffffffc,%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%ecx
sub    %al,%cl
movzbl %cl,%eax
cmove  %r15d,%eax
movzbl %al,%esi
mov    (%r12,%rbx,4),%edx
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
add    $0xff,%bpl
cmp    $0x14,%rbx
jne    11d0 <main+0x80>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.set = [10 x i32] [i32 1, i32 2, i32 3, i32 5, i32 8, i32 10, i32 12, i32 15, i32 18, i32 20]
@.str = [22 x i8] c"factorial of %d: %ld\0A\00"
@.str.1 = [9 x i8] c"%d: %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [10 x i32]* %2 to i8*
store i32 0, i32* %3
br label %9
9: ; preds = %39, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %42
12: ; preds = %9
%13 = load i32, i32* %3
%14 = srem i32 %13, 2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 @factorial(i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %25)
br label %38
27: ; preds = %12
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @factorial_iterative(i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %36)
br label %38
38: ; preds = %27, %16
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %9
42: ; preds = %9
store i32 20, i32* %4
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = mul i64 %44, 4
%46 = trunc i64 %45 to i32
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i32*
store i32* %48, i32** %6
%49 = load i32, i32* %4
%50 = call i32* @all_factorials(i32 %49)
store i32* %50, i32** %6
store i32 0, i32* %7
br label %51
51: ; preds = %71, %42
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 20
br i1 %53, label %54, label %74
54: ; preds = %51
%55 = load i32, i32* %4
%56 = load i32, i32* %7
%57 = sub nsw i32 %55, %56
%58 = load i32, i32* %4
%59 = srem i32 %57, %58
store i32 %59, i32* %5
%60 = load i32, i32* %5
%61 = icmp ne i32 %60, 0
br i1 %61, label %63, label %62
62: ; preds = %54
store i32 20, i32* %5
br label %63
63: ; preds = %62, %54
%64 = load i32, i32* %5
%65 = load i32*, i32** %6
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
%69 = load i32, i32* %68
%70 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %64, i32 %69)
br label %71
71: ; preds = %63
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %51
74: ; preds = %51
%75 = load i32, i32* %1
ret i32 %75
}

LLVM IR (-O2):
@__const.main.set = [10 x i32] [i32 1, i32 2, i32 3, i32 5, i32 8, i32 10, i32 12, i32 15, i32 18, i32 20]
@.str = [22 x i8] c"factorial of %d: %ld\0A\00"
@.str.1 = [9 x i8] c"%d: %ld\0A\00"
define i32 @main() {
br label %4
1: ; preds = %14
%2 = tail call i64 @malloc(i32 80)
%3 = tail call i32* @all_factorials(i32 20)
br label %20
4: ; preds = %0, %14
%5 = phi i64 [ 0, %0 ], [ %17, %14 ]
%6 = and i64 %5, 1
%7 = icmp eq i64 %6, 0
%8 = getelementptr inbounds [10 x i32], [10 x i32]* @__const.main.set, i64 0, i64 %5
%9 = load i32, i32* %8
br i1 %7, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @factorial(i32 %9)
br label %14
12: ; preds = %4
%13 = tail call i32 @factorial_iterative(i32 %9)
br label %14
14: ; preds = %10, %12
%15 = phi i32 [ %11, %10 ], [ %13, %12 ]
%16 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %15)
%17 = add nuw nsw i64 %5, 1
%18 = icmp eq i64 %17, 10
br i1 %18, label %1, label %4
19: ; preds = %20
ret i32 0
20: ; preds = %1, %20
%21 = phi i64 [ 0, %1 ], [ %31, %20 ]
%22 = trunc i64 %21 to i8
%23 = sub i8 20, %22
%24 = urem i8 %23, 20
%25 = icmp eq i8 %24, 0
%26 = select i1 %25, i8 20, i8 %24
%27 = zext i8 %26 to i32
%28 = getelementptr inbounds i32, i32* %3, i64 %21
%29 = load i32, i32* %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %29)
%31 = add nuw nsw i64 %21, 1
%32 = icmp eq i64 %31, 20
br i1 %32, label %19, label %20
}