#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 factorial(void) {
  int count = 0, fact = 0;
  printf("\n\n");
  printf("Enter a positive decimal number: ");
  scanf("%d", &fact);
  printf("\n\n");
  if ((fact == 0) || (fact == 1)) {
    printf("Result: 1\n\n");
  } else {
    count = fact;
    while (count != 1) {
      count--;
      fact = fact * count;
    }
    printf("Result: %d\n\n", fact);
  }
}


x86 assembly (clang, -O0):
<factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1184 <factorial+0x64>
cmpl   $0x1,-0x8(%rbp)
jne    1197 <factorial+0x77>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d0 <factorial+0xb0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
je     11bf <factorial+0x9f>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
imul   -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    119d <factorial+0x7d>
mov    -0x8(%rbp),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xfbc(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xf7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf91(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
jae    118d <factorial+0x5d>
lea    0xf7f(%rip),%rdi
call   1030 <puts@plt>
jmp    140a <factorial+0x2da>
lea    -0x1(%rax),%ecx
cmp    $0x8,%ecx
jae    119c <factorial+0x6c>
mov    %eax,%esi
jmp    13de <factorial+0x2ae>
mov    %ecx,%edx
and    $0xfffffff8,%edx
movd   %eax,%xmm0
pshufd $0x0,%xmm0,%xmm8
paddd  0xe4c(%rip),%xmm8
movd   %eax,%xmm0
movaps 0xe51(%rip),%xmm1
movss  %xmm0,%xmm1
lea    -0x8(%rdx),%ebx
mov    %ebx,%edi
shr    $0x3,%edi
add    $0x1,%edi
mov    %edi,%esi
and    $0x3,%esi
cmp    $0x18,%ebx
jae    11e5 <factorial+0xb5>
movdqa 0xe40(%rip),%xmm2
jmp    132f <factorial+0x1ff>
and    $0xfffffffc,%edi
movdqa 0xe30(%rip),%xmm2
movdqa 0xe37(%rip),%xmm9
movdqa 0xe3e(%rip),%xmm10
movdqa 0xe45(%rip),%xmm11
movdqa 0xe4c(%rip),%xmm12
movdqa 0xe53(%rip),%xmm13
movdqa 0xe5a(%rip),%xmm14
movdqa 0xe61(%rip),%xmm15
movdqa 0xe69(%rip),%xmm3
nopw   0x0(%rax,%rax,1)
movdqa %xmm8,%xmm7
paddd  0xe73(%rip),%xmm7
movdqa %xmm8,%xmm0
paddd  %xmm9,%xmm0
pshufd $0xf5,%xmm7,%xmm4
pshufd $0xf5,%xmm1,%xmm5
pmuludq %xmm4,%xmm5
pmuludq %xmm1,%xmm7
pshufd $0xf5,%xmm2,%xmm1
pshufd $0xf5,%xmm0,%xmm4
pmuludq %xmm1,%xmm4
pmuludq %xmm2,%xmm0
movdqa %xmm8,%xmm1
paddd  %xmm10,%xmm1
movdqa %xmm8,%xmm2
paddd  %xmm11,%xmm2
pmuludq %xmm1,%xmm7
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm5,%xmm1
pmuludq %xmm2,%xmm0
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm4,%xmm2
movdqa %xmm8,%xmm4
paddd  %xmm12,%xmm4
pshufd $0xf5,%xmm4,%xmm5
pmuludq %xmm1,%xmm5
movdqa %xmm8,%xmm6
paddd  %xmm13,%xmm6
pmuludq %xmm7,%xmm4
pshufd $0xf5,%xmm6,%xmm7
pmuludq %xmm2,%xmm7
pmuludq %xmm0,%xmm6
movdqa %xmm8,%xmm0
paddd  %xmm14,%xmm0
pmuludq %xmm0,%xmm4
pshufd $0xf5,%xmm0,%xmm0
pmuludq %xmm5,%xmm0
pshufd $0xe8,%xmm4,%xmm1
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm1
movdqa %xmm8,%xmm0
paddd  %xmm15,%xmm0
pmuludq %xmm0,%xmm6
pshufd $0xf5,%xmm0,%xmm0
pmuludq %xmm7,%xmm0
pshufd $0xe8,%xmm6,%xmm2
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm2
paddd  %xmm3,%xmm8
add    $0xfffffffc,%edi
jne    1240 <factorial+0x110>
test   %esi,%esi
je     13ac <factorial+0x27c>
pcmpeqd %xmm3,%xmm3
movdqa 0xcf1(%rip),%xmm4
movdqa 0xd69(%rip),%xmm5
nopw   0x0(%rax,%rax,1)
movdqa %xmm8,%xmm0
paddd  %xmm3,%xmm0
movdqa %xmm8,%xmm6
paddd  %xmm4,%xmm6
pshufd $0xf5,%xmm1,%xmm7
pmuludq %xmm0,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pshufd $0xf5,%xmm0,%xmm0
pmuludq %xmm7,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm1
pshufd $0xf5,%xmm2,%xmm0
pmuludq %xmm6,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pshufd $0xf5,%xmm6,%xmm6
pmuludq %xmm0,%xmm6
pshufd $0xe8,%xmm6,%xmm0
punpckldq %xmm0,%xmm2
paddd  %xmm5,%xmm8
add    $0xffffffff,%esi
jne    1350 <factorial+0x220>
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,%esi
cmp    %edx,%ecx
je     13f8 <factorial+0x2c8>
sub    %edx,%eax
add    $0xffffffff,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
imul   %eax,%esi
add    $0xffffffff,%eax
jne    13f0 <factorial+0x2c0>
mov    %esi,0xc(%rsp)
lea    0xcf2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str.1 = [34 x i8] c"Enter a positive decimal number: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [13 x i8] c"Result: %d\0A\0A\00"
@str.5 = [2 x i8] c"\0A\00"
@str.6 = [11 x i8] c"Result: 1\0A\00"
define void @factorial() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%7 = load i32, i32* %1
%8 = icmp ult i32 %7, 2
br i1 %8, label %78, label %9
9: ; preds = %0
%10 = add i32 %7, -1
%11 = icmp ult i32 %10, 8
br i1 %11, label %75, label %12
12: ; preds = %9
%13 = and i32 %10, -8
%14 = sub i32 %7, %13
%15 = insertelement <4 x i32> poison, i32 %7, i64 0
%16 = shufflevector <4 x i32> %15, <4 x i32> poison, <4 x i32> zeroinitializer
%17 = add <4 x i32> %16, <i32 0, i32 -1, i32 -2, i32 -3>
%18 = insertelement <4 x i32> <i32 poison, i32 1, i32 1, i32 1>, i32 %7, i64 0
%19 = add i32 %13, -8
%20 = lshr exact i32 %19, 3
%21 = add nuw nsw i32 %20, 1
%22 = and i32 %21, 3
%23 = icmp ult i32 %19, 24
br i1 %23, label %50, label %24
24: ; preds = %12
%25 = and i32 %21, 1073741820
br label %26
26: ; preds = %26, %24
%27 = phi <4 x i32> [ %17, %24 ], [ %47, %26 ]
%28 = phi <4 x i32> [ %18, %24 ], [ %45, %26 ]
%29 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %24 ], [ %46, %26 ]
%30 = phi i32 [ 0, %24 ], [ %48, %26 ]
%31 = add nsw <4 x i32> %27, <i32 -1, i32 -1, i32 -1, i32 -1>
%32 = add <4 x i32> %27, <i32 -5, i32 -5, i32 -5, i32 -5>
%33 = mul <4 x i32> %28, %31
%34 = mul <4 x i32> %29, %32
%35 = add <4 x i32> %27, <i32 -9, i32 -9, i32 -9, i32 -9>
%36 = add <4 x i32> %27, <i32 -13, i32 -13, i32 -13, i32 -13>
%37 = mul <4 x i32> %33, %35
%38 = mul <4 x i32> %34, %36
%39 = add <4 x i32> %27, <i32 -17, i32 -17, i32 -17, i32 -17>
%40 = add <4 x i32> %27, <i32 -21, i32 -21, i32 -21, i32 -21>
%41 = mul <4 x i32> %37, %39
%42 = mul <4 x i32> %38, %40
%43 = add <4 x i32> %27, <i32 -25, i32 -25, i32 -25, i32 -25>
%44 = add <4 x i32> %27, <i32 -29, i32 -29, i32 -29, i32 -29>
%45 = mul <4 x i32> %41, %43
%46 = mul <4 x i32> %42, %44
%47 = add <4 x i32> %27, <i32 -32, i32 -32, i32 -32, i32 -32>
%48 = add i32 %30, 4
%49 = icmp eq i32 %48, %25
br i1 %49, label %50, label %26
50: ; preds = %26, %12
%51 = phi <4 x i32> [ undef, %12 ], [ %45, %26 ]
%52 = phi <4 x i32> [ undef, %12 ], [ %46, %26 ]
%53 = phi <4 x i32> [ %17, %12 ], [ %47, %26 ]
%54 = phi <4 x i32> [ %18, %12 ], [ %45, %26 ]
%55 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %12 ], [ %46, %26 ]
%56 = icmp eq i32 %22, 0
br i1 %56, label %69, label %57
57: ; preds = %50, %57
%58 = phi <4 x i32> [ %66, %57 ], [ %53, %50 ]
%59 = phi <4 x i32> [ %64, %57 ], [ %54, %50 ]
%60 = phi <4 x i32> [ %65, %57 ], [ %55, %50 ]
%61 = phi i32 [ %67, %57 ], [ 0, %50 ]
%62 = add nsw <4 x i32> %58, <i32 -1, i32 -1, i32 -1, i32 -1>
%63 = add <4 x i32> %58, <i32 -5, i32 -5, i32 -5, i32 -5>
%64 = mul <4 x i32> %59, %62
%65 = mul <4 x i32> %60, %63
%66 = add <4 x i32> %58, <i32 -8, i32 -8, i32 -8, i32 -8>
%67 = add i32 %61, 1
%68 = icmp eq i32 %67, %22
br i1 %68, label %69, label %57
69: ; preds = %57, %50
%70 = phi <4 x i32> [ %51, %50 ], [ %64, %57 ]
%71 = phi <4 x i32> [ %52, %50 ], [ %65, %57 ]
%72 = mul <4 x i32> %71, %70
%73 = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %72)
%74 = icmp eq i32 %10, %13
br i1 %74, label %86, label %75
75: ; preds = %9, %69
%76 = phi i32 [ %7, %9 ], [ %14, %69 ]
%77 = phi i32 [ %7, %9 ], [ %73, %69 ]
br label %80
78: ; preds = %0
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %89
80: ; preds = %75, %80
%81 = phi i32 [ %83, %80 ], [ %76, %75 ]
%82 = phi i32 [ %84, %80 ], [ %77, %75 ]
%83 = add nsw i32 %81, -1
%84 = mul nsw i32 %82, %83
%85 = icmp eq i32 %83, 1
br i1 %85, label %86, label %80
86: ; preds = %80, %69
%87 = phi i32 [ %73, %69 ], [ %84, %80 ]
store i32 %87, i32* %1
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %86, %78
ret void
}