#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 main() {
  int i, num, fact = 1;
  printf("Enter a number to calculate its factorial: ");
  scanf("%d", &num);
  for (i = 1; i <= num; i++) {
    fact = fact * i;
  }
  printf("Factorial of %d is \"%d\".", num, fact);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     117f <main+0x5f>
mov    -0x10(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <main+0x3b>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf78(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf96(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%esi
mov    $0x1,%edx
test   %esi,%esi
jle    138a <main+0x26a>
mov    $0x1,%eax
cmp    $0x8,%esi
jb     1374 <main+0x254>
mov    %esi,%eax
and    $0xfffffff8,%eax
lea    -0x8(%rax),%edi
mov    %edi,%edx
shr    $0x3,%edx
add    $0x1,%edx
mov    %edx,%ecx
and    $0x3,%ecx
cmp    $0x18,%edi
jae    1192 <main+0x72>
movdqa 0xe7f(%rip),%xmm0
movdqa 0xe87(%rip),%xmm1
movdqa %xmm1,%xmm2
jmp    12d1 <main+0x1b1>
and    $0xfffffffc,%edx
movdqa 0xe63(%rip),%xmm0
movdqa 0xe6b(%rip),%xmm1
movdqa 0xe82(%rip),%xmm9
movdqa 0xe89(%rip),%xmm10
movdqa 0xe90(%rip),%xmm11
movdqa 0xe97(%rip),%xmm12
movdqa 0xe9e(%rip),%xmm13
movdqa 0xea5(%rip),%xmm14
movdqa 0xeac(%rip),%xmm15
movdqa %xmm1,%xmm2
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm6
paddd  0xe24(%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,%edx
jne    11f0 <main+0xd0>
test   %ecx,%ecx
je     1341 <main+0x221>
movdqa 0xd43(%rip),%xmm3
movdqa 0xd4b(%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,%ecx
jne    12f0 <main+0x1d0>
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,%edx
cmp    %eax,%esi
je     138a <main+0x26a>
or     $0x1,%eax
lea    0x1(%rsi),%ecx
nopw   0x0(%rax,%rax,1)
imul   %eax,%edx
add    $0x1,%eax
cmp    %eax,%ecx
jne    1380 <main+0x260>
lea    0xd3e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Enter a number to calculate its factorial: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"Factorial of %d is \22%d\22.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 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* %3)
store i32 1, i32* %2
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = mul nsw i32 %12, %13
store i32 %14, i32* %4
br label %15
15: ; preds = %11
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %7
18: ; preds = %7
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"Enter a number to calculate its factorial: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"Factorial of %d is \22%d\22.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 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, 1
br i1 %6, label %75, label %7
7: ; preds = %0
%8 = icmp ult i32 %5, 8
br i1 %8, label %66, label %9
9: ; preds = %7
%10 = and i32 %5, -8
%11 = or i32 %10, 1
%12 = add i32 %10, -8
%13 = lshr exact i32 %12, 3
%14 = add nuw nsw i32 %13, 1
%15 = and i32 %14, 3
%16 = icmp ult i32 %12, 24
br i1 %16, label %42, label %17
17: ; preds = %9
%18 = and i32 %14, 1073741820
br label %19
19: ; preds = %19, %17
%20 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %17 ], [ %37, %19 ]
%21 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %17 ], [ %38, %19 ]
%22 = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %17 ], [ %39, %19 ]
%23 = phi i32 [ 0, %17 ], [ %40, %19 ]
%24 = add <4 x i32> %22, <i32 4, i32 4, i32 4, i32 4>
%25 = mul <4 x i32> %20, %22
%26 = mul <4 x i32> %21, %24
%27 = add <4 x i32> %22, <i32 8, i32 8, i32 8, i32 8>
%28 = add <4 x i32> %22, <i32 12, i32 12, i32 12, i32 12>
%29 = mul <4 x i32> %25, %27
%30 = mul <4 x i32> %26, %28
%31 = add <4 x i32> %22, <i32 16, i32 16, i32 16, i32 16>
%32 = add <4 x i32> %22, <i32 20, i32 20, i32 20, i32 20>
%33 = mul <4 x i32> %29, %31
%34 = mul <4 x i32> %30, %32
%35 = add <4 x i32> %22, <i32 24, i32 24, i32 24, i32 24>
%36 = add <4 x i32> %22, <i32 28, i32 28, i32 28, i32 28>
%37 = mul <4 x i32> %33, %35
%38 = mul <4 x i32> %34, %36
%39 = add <4 x i32> %22, <i32 32, i32 32, i32 32, i32 32>
%40 = add i32 %23, 4
%41 = icmp eq i32 %40, %18
br i1 %41, label %42, label %19
42: ; preds = %19, %9
%43 = phi <4 x i32> [ undef, %9 ], [ %37, %19 ]
%44 = phi <4 x i32> [ undef, %9 ], [ %38, %19 ]
%45 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %9 ], [ %37, %19 ]
%46 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %9 ], [ %38, %19 ]
%47 = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %9 ], [ %39, %19 ]
%48 = icmp eq i32 %15, 0
br i1 %48, label %60, label %49
49: ; preds = %42, %49
%50 = phi <4 x i32> [ %55, %49 ], [ %45, %42 ]
%51 = phi <4 x i32> [ %56, %49 ], [ %46, %42 ]
%52 = phi <4 x i32> [ %57, %49 ], [ %47, %42 ]
%53 = phi i32 [ %58, %49 ], [ 0, %42 ]
%54 = add <4 x i32> %52, <i32 4, i32 4, i32 4, i32 4>
%55 = mul <4 x i32> %50, %52
%56 = mul <4 x i32> %51, %54
%57 = add <4 x i32> %52, <i32 8, i32 8, i32 8, i32 8>
%58 = add i32 %53, 1
%59 = icmp eq i32 %58, %15
br i1 %59, label %60, label %49
60: ; preds = %49, %42
%61 = phi <4 x i32> [ %43, %42 ], [ %55, %49 ]
%62 = phi <4 x i32> [ %44, %42 ], [ %56, %49 ]
%63 = mul <4 x i32> %62, %61
%64 = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %63)
%65 = icmp eq i32 %5, %10
br i1 %65, label %75, label %66
66: ; preds = %7, %60
%67 = phi i32 [ 1, %7 ], [ %64, %60 ]
%68 = phi i32 [ 1, %7 ], [ %11, %60 ]
br label %69
69: ; preds = %66, %69
%70 = phi i32 [ %72, %69 ], [ %67, %66 ]
%71 = phi i32 [ %73, %69 ], [ %68, %66 ]
%72 = mul nsw i32 %70, %71
%73 = add nuw i32 %71, 1
%74 = icmp eq i32 %71, %5
br i1 %74, label %75, label %69
75: ; preds = %69, %60, %0
%76 = phi i32 [ 1, %0 ], [ %64, %60 ], [ %72, %69 ]
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %76)
ret i32 0
}