#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 *);
int factorial() {
  int i, fact = 1, num;
  printf("\nEnter a number to find factorial : ");
  scanf("%d", &num);
  if (num < 0) {
    printf("\nPlease enter a positive number to");
    printf(" find factorial and try again. \n");
    printf("\nFactorial can't be found for negative");
    printf(" values. It can be only positive or 0  \n");
    return 1;
  }
  for (i = 1; i <= num; i++)
    fact = fact * i;
  printf("\n");
  printf("Factorial of entered number %d is:%d\n", num, fact);
  return 0;
}


x86 assembly (clang, -O0):
<factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jge    119b <factorial+0x7b>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ef <factorial+0xcf>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11c6 <factorial+0xa6>
mov    -0xc(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a2 <factorial+0x82>
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial>:
push   %rbp
push   %rbx
push   %rax
lea    0xf56(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf6d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     11b6 <factorial+0x76>
mov    $0x1,%ebx
je     13ea <factorial+0x2aa>
mov    $0x1,%ecx
cmp    $0x8,%eax
jb     13d4 <factorial+0x294>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%edi
mov    %edi,%esi
shr    $0x3,%esi
add    $0x1,%esi
mov    %esi,%edx
and    $0x3,%edx
cmp    $0x18,%edi
jae    11f4 <factorial+0xb4>
movdqa 0xe5b(%rip),%xmm0
movdqa 0xe63(%rip),%xmm1
movdqa %xmm1,%xmm2
jmp    1331 <factorial+0x1f1>
lea    0xf0b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf6d(%rip),%rdi
call   1040 <puts@plt>
lea    0xf14(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf73(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
jmp    140a <factorial+0x2ca>
and    $0xfffffffc,%esi
movdqa 0xe01(%rip),%xmm0
movdqa 0xe09(%rip),%xmm1
movdqa 0xe20(%rip),%xmm9
movdqa 0xe27(%rip),%xmm10
movdqa 0xe2e(%rip),%xmm11
movdqa 0xe35(%rip),%xmm12
movdqa 0xe3c(%rip),%xmm13
movdqa 0xe43(%rip),%xmm14
movdqa 0xe4a(%rip),%xmm15
movdqa %xmm1,%xmm2
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm6
paddd  0xdc4(%rip),%xmm6
pshufd $0xf5,%xmm0,%xmm7
pshufd $0xf5,%xmm1,%xmm3
pmuludq %xmm7,%xmm3
pmuludq %xmm0,%xmm1
pshufd $0xf5,%xmm2,%xmm7
pshufd $0xf5,%xmm6,%xmm4
pmuludq %xmm7,%xmm4
pmuludq %xmm2,%xmm6
movdqa %xmm0,%xmm2
paddd  %xmm9,%xmm2
movdqa %xmm0,%xmm7
paddd  %xmm10,%xmm7
pmuludq %xmm2,%xmm1
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm3,%xmm2
pmuludq %xmm7,%xmm6
pshufd $0xf5,%xmm7,%xmm3
pmuludq %xmm4,%xmm3
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm7
paddd  %xmm12,%xmm7
pshufd $0xf5,%xmm4,%xmm5
pmuludq %xmm2,%xmm5
pmuludq %xmm1,%xmm4
pshufd $0xf5,%xmm7,%xmm8
pmuludq %xmm3,%xmm8
pmuludq %xmm6,%xmm7
movdqa %xmm0,%xmm2
paddd  %xmm13,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm14,%xmm3
pmuludq %xmm2,%xmm4
pshufd $0xe8,%xmm4,%xmm1
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm5,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
pmuludq %xmm3,%xmm7
pshufd $0xe8,%xmm7,%xmm2
pshufd $0xf5,%xmm3,%xmm3
pmuludq %xmm8,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm2
paddd  %xmm15,%xmm0
add    $0xfffffffc,%esi
jne    1250 <factorial+0x110>
test   %edx,%edx
je     13a1 <factorial+0x261>
movdqa 0xce3(%rip),%xmm3
movdqa 0xceb(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nop
movdqa %xmm0,%xmm5
paddd  %xmm3,%xmm5
pshufd $0xf5,%xmm1,%xmm6
pmuludq %xmm0,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pshufd $0xf5,%xmm0,%xmm7
pmuludq %xmm6,%xmm7
pshufd $0xe8,%xmm7,%xmm6
punpckldq %xmm6,%xmm1
pshufd $0xf5,%xmm2,%xmm6
pmuludq %xmm5,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pshufd $0xf5,%xmm5,%xmm5
pmuludq %xmm6,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm5,%xmm2
paddd  %xmm4,%xmm0
add    $0xffffffff,%edx
jne    1350 <factorial+0x210>
pshufd $0xf5,%xmm1,%xmm0
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm0,%xmm3
pmuludq %xmm1,%xmm2
pshufd $0xee,%xmm2,%xmm0
pmuludq %xmm2,%xmm0
pshufd $0xaa,%xmm3,%xmm1
pmuludq %xmm3,%xmm1
pmuludq %xmm0,%xmm1
movd   %xmm1,%ebx
cmp    %ecx,%eax
je     13ea <factorial+0x2aa>
or     $0x1,%ecx
add    $0x1,%eax
nopw   0x0(%rax,%rax,1)
imul   %ecx,%ebx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    13e0 <factorial+0x2a0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%esi
lea    0xd13(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"\0AEnter a number to find factorial : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"\0APlease enter a positive number to\00"
@.str.3 = [33 x i8] c" find factorial and try again. \0A\00"
@.str.4 = [39 x i8] c"\0AFactorial can't be found for negative\00"
@.str.5 = [41 x i8] c" values. It can be only positive or 0 \0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [38 x i8] c"Factorial of entered number %d is:%d\0A\00"
define i32 @factorial() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 1, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %31
14: ; preds = %0
store i32 1, i32* %2
br label %15
15: ; preds = %23, %14
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = mul nsw i32 %20, %21
store i32 %22, i32* %3
br label %23
23: ; preds = %19
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %15
26: ; preds = %15
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %28, i32 %29)
store i32 0, i32* %1
br label %31
31: ; preds = %26, %9
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [37 x i8] c"\0AEnter a number to find factorial : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"\0APlease enter a positive number to\00"
@.str.4 = [39 x i8] c"\0AFactorial can't be found for negative\00"
@.str.7 = [38 x i8] c"Factorial of entered number %d is:%d\0A\00"
@str = [32 x i8] c" find factorial and try again. \00"
@str.8 = [40 x i8] c" values. It can be only positive or 0 \00"
define i32 @factorial() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 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 %71, label %7
7: ; preds = %0
%8 = icmp eq i32 %5, 0
br i1 %8, label %82, label %9
9: ; preds = %7
%10 = icmp ult i32 %5, 8
br i1 %10, label %68, label %11
11: ; preds = %9
%12 = and i32 %5, -8
%13 = or i32 %12, 1
%14 = add i32 %12, -8
%15 = lshr exact i32 %14, 3
%16 = add nuw nsw i32 %15, 1
%17 = and i32 %16, 3
%18 = icmp ult i32 %14, 24
br i1 %18, label %44, label %19
19: ; preds = %11
%20 = and i32 %16, 1073741820
br label %21
21: ; preds = %21, %19
%22 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %19 ], [ %39, %21 ]
%23 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %19 ], [ %40, %21 ]
%24 = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %19 ], [ %41, %21 ]
%25 = phi i32 [ 0, %19 ], [ %42, %21 ]
%26 = add <4 x i32> %24, <i32 4, i32 4, i32 4, i32 4>
%27 = mul <4 x i32> %22, %24
%28 = mul <4 x i32> %23, %26
%29 = add <4 x i32> %24, <i32 8, i32 8, i32 8, i32 8>
%30 = add <4 x i32> %24, <i32 12, i32 12, i32 12, i32 12>
%31 = mul <4 x i32> %27, %29
%32 = mul <4 x i32> %28, %30
%33 = add <4 x i32> %24, <i32 16, i32 16, i32 16, i32 16>
%34 = add <4 x i32> %24, <i32 20, i32 20, i32 20, i32 20>
%35 = mul <4 x i32> %31, %33
%36 = mul <4 x i32> %32, %34
%37 = add <4 x i32> %24, <i32 24, i32 24, i32 24, i32 24>
%38 = add <4 x i32> %24, <i32 28, i32 28, i32 28, i32 28>
%39 = mul <4 x i32> %35, %37
%40 = mul <4 x i32> %36, %38
%41 = add <4 x i32> %24, <i32 32, i32 32, i32 32, i32 32>
%42 = add i32 %25, 4
%43 = icmp eq i32 %42, %20
br i1 %43, label %44, label %21
44: ; preds = %21, %11
%45 = phi <4 x i32> [ undef, %11 ], [ %39, %21 ]
%46 = phi <4 x i32> [ undef, %11 ], [ %40, %21 ]
%47 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %11 ], [ %39, %21 ]
%48 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %11 ], [ %40, %21 ]
%49 = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %11 ], [ %41, %21 ]
%50 = icmp eq i32 %17, 0
br i1 %50, label %62, label %51
51: ; preds = %44, %51
%52 = phi <4 x i32> [ %57, %51 ], [ %47, %44 ]
%53 = phi <4 x i32> [ %58, %51 ], [ %48, %44 ]
%54 = phi <4 x i32> [ %59, %51 ], [ %49, %44 ]
%55 = phi i32 [ %60, %51 ], [ 0, %44 ]
%56 = add <4 x i32> %54, <i32 4, i32 4, i32 4, i32 4>
%57 = mul <4 x i32> %52, %54
%58 = mul <4 x i32> %53, %56
%59 = add <4 x i32> %54, <i32 8, i32 8, i32 8, i32 8>
%60 = add i32 %55, 1
%61 = icmp eq i32 %60, %17
br i1 %61, label %62, label %51
62: ; preds = %51, %44
%63 = phi <4 x i32> [ %45, %44 ], [ %57, %51 ]
%64 = phi <4 x i32> [ %46, %44 ], [ %58, %51 ]
%65 = mul <4 x i32> %64, %63
%66 = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %65)
%67 = icmp eq i32 %5, %12
br i1 %67, label %82, label %68
68: ; preds = %9, %62
%69 = phi i32 [ 1, %9 ], [ %66, %62 ]
%70 = phi i32 [ 1, %9 ], [ %13, %62 ]
br label %76
71: ; preds = %0
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.8, i64 0, i64 0))
br label %87
76: ; preds = %68, %76
%77 = phi i32 [ %79, %76 ], [ %69, %68 ]
%78 = phi i32 [ %80, %76 ], [ %70, %68 ]
%79 = mul nsw i32 %77, %78
%80 = add nuw i32 %78, 1
%81 = icmp eq i32 %78, %5
br i1 %81, label %82, label %76
82: ; preds = %76, %62, %7
%83 = phi i32 [ 1, %7 ], [ %66, %62 ], [ %79, %76 ]
%84 = call i32 @putchar(i32 10)
%85 = load i32, i32* %1
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %85, i32 %83)
br label %87
87: ; preds = %82, %71
%88 = phi i32 [ 1, %71 ], [ 0, %82 ]
ret i32 %88
}