#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 uint64_t;

/* Variables and functions */
uint64_t do_all_factorials(int n, uint64_t *results, int level) {
  if (n > 1)
    results[level] = n * do_all_factorials(n - 1, results, level + 1);
  else
    results[level] = 1;
  return results[level];
}


x86 assembly (clang, -O0):
<do_all_factorials>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    115d <do_all_factorials+0x4d>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1030 <do_all_factorials@plt>
mov    -0x18(%rbp),%edx
imul   %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    116c <do_all_factorials+0x5c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_all_factorials>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    $0x1,%eax
cmp    $0x2,%edi
jl     1139 <do_all_factorials+0x29>
mov    %edi,%ebx
lea    -0x1(%rbx),%edi
lea    0x1(%r14),%edx
mov    %r15,%rsi
call   1030 <do_all_factorials@plt>
imul   %ebx,%eax
movslq %r14d,%rcx
mov    %eax,(%r15,%rcx,4)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @do_all_factorials(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %22
9: ; preds = %3
%10 = load i32, i32* %4
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = load i32*, i32** %5
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
%16 = call i32 @do_all_factorials(i32 %12, i32* %13, i32 %15)
%17 = mul nsw i32 %10, %16
%18 = load i32*, i32** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
store i32 %17, i32* %21
br label %27
22: ; preds = %3
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 1, i32* %26
br label %27
27: ; preds = %22, %9
%28 = load i32*, i32** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
ret i32 %32
}

LLVM IR (-O2):
define i32 @do_all_factorials(i32 %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = add nsw i32 %0, -1
%7 = add nsw i32 %2, 1
%8 = tail call i32 @do_all_factorials(i32 %6, i32* %1, i32 %7)
%9 = mul nsw i32 %8, %0
br label %10
10: ; preds = %3, %5
%11 = phi i32 [ %9, %5 ], [ 1, %3 ]
%12 = sext i32 %2 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
store i32 %11, i32* %13
ret i32 %11
}