#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 /*<<< orphan*/ scanf(char *, int *);
void fac() {
  int i, n;
  unsigned long long int fact = 1;
  printf("Enter an integer upto 12: ");
  scanf("%d", &n);
  if (n < 0)
    printf("The factorial of %d doesn't exist.", n);
  else if (n > 12) {
    printf("Error!! This program can only calculate factorials of integers "
           "from 0 to 12 only.");
  } else {
    for (i = 1; i <= n; i++) {
      fact *= i;
    }
    printf("The factorial of %d = %lu", n, fact);
  }
}


x86 assembly (clang, -O0):
<fac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x1,-0x10(%rbp)
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    116e <fac+0x4e>
mov    -0x8(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d3 <fac+0xb3>
cmpl   $0xc,-0x8(%rbp)
jle    118b <fac+0x6b>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ce <fac+0xae>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b9 <fac+0x99>
movslq -0x4(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <fac+0x72>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d3 <fac+0xb3>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fac>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
js     115d <fac+0x3d>
cmp    $0xc,%esi
jbe    116d <fac+0x4d>
lea    0xeed(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
pop    %rax
ret
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
pop    %rax
ret
test   %rsi,%rsi
je     119b <fac+0x7b>
lea    -0x1(%rsi),%rcx
mov    %esi,%r9d
and    $0x7,%r9d
cmp    $0x7,%rcx
jae    11a5 <fac+0x85>
mov    $0x1,%ecx
mov    $0x1,%edx
test   %r9,%r9
jne    1220 <fac+0x100>
jmp    122e <fac+0x10e>
mov    $0x1,%edx
jmp    122e <fac+0x10e>
mov    %esi,%r8d
and    $0xfffffff8,%r8d
neg    %r8
mov    $0x1,%edx
mov    $0x8,%ecx
nopl   0x0(%rax)
lea    -0x7(%rcx),%rdi
imul   %rdx,%rdi
lea    -0x6(%rcx),%rdx
lea    -0x5(%rcx),%rax
imul   %rax,%rdx
imul   %rdi,%rdx
lea    -0x4(%rcx),%rax
lea    -0x3(%rcx),%rdi
imul   %rdi,%rax
lea    -0x2(%rcx),%rdi
imul   %rax,%rdi
imul   %rdx,%rdi
lea    -0x1(%rcx),%rdx
imul   %rcx,%rdx
imul   %rdi,%rdx
lea    (%r8,%rcx,1),%rax
add    $0x8,%rax
add    $0x8,%rcx
cmp    $0x8,%rax
jne    11c0 <fac+0xa0>
add    $0xfffffffffffffff9,%rcx
test   %r9,%r9
je     122e <fac+0x10e>
nopw   0x0(%rax,%rax,1)
imul   %rcx,%rdx
add    $0x1,%rcx
add    $0xffffffffffffffff,%r9
jne    1220 <fac+0x100>
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter an integer upto 12: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"The factorial of %d doesn't exist.\00"
@.str.3 = [82 x i8] c"Error!! This program can only calculate factorials of integers from 0 to 12 only.\00"
@.str.4 = [26 x i8] c"The factorial of %d = %lu\00"
define void @fac() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i64 1, i64* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %34
11: ; preds = %0
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 12
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.3, i64 0, i64 0))
br label %33
16: ; preds = %11
store i32 1, i32* %1
br label %17
17: ; preds = %26, %16
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = load i64, i64* %3
%25 = mul i64 %24, %23
store i64 %25, i64* %3
br label %26
26: ; preds = %21
%27 = load i32, i32* %1
%28 = add nsw i32 %27, 1
store i32 %28, i32* %1
br label %17
29: ; preds = %17
%30 = load i32, i32* %2
%31 = load i64, i64* %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %30, i64 %31)
br label %33
33: ; preds = %29, %14
br label %34
34: ; preds = %33, %8
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter an integer upto 12: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"The factorial of %d doesn't exist.\00"
@.str.3 = [82 x i8] c"Error!! This program can only calculate factorials of integers from 0 to 12 only.\00"
@.str.4 = [26 x i8] c"The factorial of %d = %lu\00"
define void @fac() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %62
9: ; preds = %0
%10 = icmp ugt i32 %5, 12
br i1 %10, label %22, label %11
11: ; preds = %9
%12 = icmp eq i32 %5, 0
br i1 %12, label %59, label %13
13: ; preds = %11
%14 = add nuw nsw i32 %5, 1
%15 = zext i32 %14 to i64
%16 = add nsw i64 %15, -1
%17 = add nsw i64 %15, -2
%18 = and i64 %16, 7
%19 = icmp ult i64 %17, 7
br i1 %19, label %46, label %20
20: ; preds = %13
%21 = and i64 %16, -8
br label %24
22: ; preds = %9
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.3, i64 0, i64 0))
br label %62
24: ; preds = %24, %20
%25 = phi i64 [ 1, %20 ], [ %43, %24 ]
%26 = phi i64 [ 1, %20 ], [ %42, %24 ]
%27 = phi i64 [ 0, %20 ], [ %44, %24 ]
%28 = mul i64 %26, %25
%29 = add nuw nsw i64 %25, 1
%30 = mul i64 %28, %29
%31 = add nuw nsw i64 %25, 2
%32 = mul i64 %30, %31
%33 = add nuw nsw i64 %25, 3
%34 = mul i64 %32, %33
%35 = add nuw nsw i64 %25, 4
%36 = mul i64 %34, %35
%37 = add nuw nsw i64 %25, 5
%38 = mul i64 %36, %37
%39 = add nuw nsw i64 %25, 6
%40 = mul i64 %38, %39
%41 = add nuw nsw i64 %25, 7
%42 = mul i64 %40, %41
%43 = add nuw nsw i64 %25, 8
%44 = add i64 %27, 8
%45 = icmp eq i64 %44, %21
br i1 %45, label %46, label %24
46: ; preds = %24, %13
%47 = phi i64 [ undef, %13 ], [ %42, %24 ]
%48 = phi i64 [ 1, %13 ], [ %43, %24 ]
%49 = phi i64 [ 1, %13 ], [ %42, %24 ]
%50 = icmp eq i64 %18, 0
br i1 %50, label %59, label %51
51: ; preds = %46, %51
%52 = phi i64 [ %56, %51 ], [ %48, %46 ]
%53 = phi i64 [ %55, %51 ], [ %49, %46 ]
%54 = phi i64 [ %57, %51 ], [ 0, %46 ]
%55 = mul i64 %53, %52
%56 = add nuw nsw i64 %52, 1
%57 = add i64 %54, 1
%58 = icmp eq i64 %57, %18
br i1 %58, label %59, label %51
59: ; preds = %46, %51, %11
%60 = phi i64 [ 1, %11 ], [ %47, %46 ], [ %55, %51 ]
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %5, i64 %60)
br label %62
62: ; preds = %22, %59, %7
ret void
}