#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 main(void) {
  printf("\nrecursivefunctions started\n\n");
  unsigned int j;
  unsigned long int factorial(unsigned int n);
  for (j = 0; j < 11; ++j)
    printf("%2u! = %lu\n", j, factorial(j));
  printf("\nrecursivefunctions ended\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xb,-0x8(%rbp)
jae    117e <main+0x5e>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    -0xc(%rbp),%esi
mov    %rax,%rdx
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1144 <main+0x24>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <factorial@plt>
lea    0xeb5(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x3,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x4,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x6,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x8,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x9,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdb0(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"\0Arecursivefunctions started\0A\0A\00"
@.str.1 = [12 x i8] c"%2u! = %lu\0A\00"
@.str.2 = [28 x i8] c"\0Arecursivefunctions ended\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %4
4: ; preds = %12, %0
%5 = load i32, i32* %2
%6 = icmp ult i32 %5, 11
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i32, i32* %2
%9 = load i32, i32* %2
%10 = call i64 @factorial(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %8, i64 %10)
br label %12
12: ; preds = %7
%13 = load i32, i32* %2
%14 = add i32 %13, 1
store i32 %14, i32* %2
br label %4
15: ; preds = %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"%2u! = %lu\0A\00"
@str = [29 x i8] c"\0Arecursivefunctions started\0A\00"
@str.3 = [27 x i8] c"\0Arecursivefunctions ended\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 @factorial(i32 0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 0, i64 %2)
%4 = tail call i64 @factorial(i32 1)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 1, i64 %4)
%6 = tail call i64 @factorial(i32 2)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 2, i64 %6)
%8 = tail call i64 @factorial(i32 3)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 3, i64 %8)
%10 = tail call i64 @factorial(i32 4)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 4, i64 %10)
%12 = tail call i64 @factorial(i32 5)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 5, i64 %12)
%14 = tail call i64 @factorial(i32 6)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 6, i64 %14)
%16 = tail call i64 @factorial(i32 7)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 7, i64 %16)
%18 = tail call i64 @factorial(i32 8)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 8, i64 %18)
%20 = tail call i64 @factorial(i32 9)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 9, i64 %20)
%22 = tail call i64 @factorial(i32 10)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 10, i64 %22)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}