#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 factorial(int n) {
  int rst;
  char db[] = "%d%c";
  printf(db, n, 10);
  if (n == 0)
    rst = 1;
  else
    rst = n;
  if (n != 1 && n != 0)
    rst = n * factorial(n - 1);
  return rst;
}


x86 assembly (clang, -O0):
<factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0xd(%rbp)
mov    0xeca(%rip),%al
mov    %al,-0x9(%rbp)
lea    -0xd(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    $0xa,%edx
call   1040 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1164 <factorial+0x44>
movl   $0x1,-0x8(%rbp)
jmp    116a <factorial+0x4a>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x4(%rbp)
je     119a <factorial+0x7a>
cmpl   $0x0,-0x4(%rbp)
je     119a <factorial+0x7a>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movb   $0x0,0xc(%rsp)
movl   $0x63256425,0x8(%rsp)
63
lea    0x8(%rsp),%rdi
mov    %ebx,%esi
mov    $0xa,%edx
call   1040 <printf@plt>
test   %ebx,%ebx
mov    $0x1,%eax
cmovne %ebx,%eax
cmp    $0x2,%ebx
jb     115f <factorial+0x3f>
lea    -0x1(%rbx),%edi
call   1030 <factorial@plt>
imul   %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.factorial.db = [5 x i8] c"%d%c\00"
define i32 @factorial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [5 x i8]
store i32 %0, i32* %2
%5 = bitcast [5 x i8]* %4 to i8*
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32 @printf(i8* %6, i32 %7, i32 10)
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %3
br label %14
12: ; preds = %1
%13 = load i32, i32* %2
store i32 %13, i32* %3
br label %14
14: ; preds = %12, %11
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i32, i32* %2
%22 = load i32, i32* %2
%23 = sub nsw i32 %22, 1
%24 = call i32 @factorial(i32 %23)
%25 = mul nsw i32 %21, %24
store i32 %25, i32* %3
br label %26
26: ; preds = %20, %17, %14
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@__const.factorial.db = [5 x i8] c"%d%c\00"
define i32 @factorial(i32 %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = call i32 @printf(i8* %3, i32 %0, i32 10)
%5 = icmp eq i32 %0, 0
%6 = select i1 %5, i32 1, i32 %0
%7 = icmp ult i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = add nsw i32 %0, -1
%10 = call i32 @factorial(i32 %9)
%11 = mul nsw i32 %10, %0
br label %12
12: ; preds = %8, %1
%13 = phi i32 [ %11, %8 ], [ %6, %1 ]
ret i32 %13
}