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

/* Variables and functions */
int64_t factorial(int n) {
  switch (n) {
  case 0:
  case 1:
    return 1;
    break;
  case 2:
    return 2;
    break;
  case 3:
    return 6;
    break;
  case 4:
    return 24;
    break;
  case 5:
    return 120;
    break;
  default:
    return n * factorial(n - 1);
    break;
  }
}


x86 assembly (clang, -O0):
<factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0x5,%rax
ja     117c <factorial+0x6c>
mov    -0x10(%rbp),%rax
lea    0xec9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x4(%rbp)
jmp    1198 <factorial+0x88>
movl   $0x2,-0x4(%rbp)
jmp    1198 <factorial+0x88>
movl   $0x6,-0x4(%rbp)
jmp    1198 <factorial+0x88>
movl   $0x18,-0x4(%rbp)
jmp    1198 <factorial+0x88>
movl   $0x78,-0x4(%rbp)
jmp    1198 <factorial+0x88>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial>:
movslq %edi,%rax
lea    0xef6(%rip),%rcx
lea    (%rcx,%rax,4),%rcx
mov    $0x1,%eax
cmp    $0x6,%edi
jb     1131 <factorial+0x31>
nopl   0x0(%rax,%rax,1)
imul   %edi,%eax
lea    -0x1(%rdi),%edx
add    $0xfffffffffffffffc,%rcx
mov    %edx,%edi
cmp    $0x6,%edi
jae    1120 <factorial+0x20>
imul   (%rcx),%eax
ret

LLVM IR (-O0):
define i32 @factorial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %10 [
i32 0, label %5
i32 1, label %5
i32 2, label %6
i32 3, label %7
i32 4, label %8
i32 5, label %9
]
5: ; preds = %1, %1
store i32 1, i32* %2
br label %16
6: ; preds = %1
store i32 2, i32* %2
br label %16
7: ; preds = %1
store i32 6, i32* %2
br label %16
8: ; preds = %1
store i32 24, i32* %2
br label %16
9: ; preds = %1
store i32 120, i32* %2
br label %16
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 1
%14 = call i32 @factorial(i32 %13)
%15 = mul nsw i32 %11, %14
store i32 %15, i32* %2
br label %16
16: ; preds = %10, %9, %8, %7, %6, %5
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@switch.table.factorial = [6 x i32] [i32 1, i32 1, i32 2, i32 6, i32 24, i32 120]
define i32 @factorial(i32 %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i32 [ 1, %1 ], [ %8, %6 ]
%4 = phi i32 [ %0, %1 ], [ %7, %6 ]
%5 = icmp ult i32 %4, 6
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = add nsw i32 %4, -1
%8 = mul nsw i32 %4, %3
br label %2
9: ; preds = %2
%10 = sext i32 %4 to i64
%11 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.factorial, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, %3
ret i32 %13
}