#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_test() {
  int n, i;
  int factorial = 1;
  printf("Enter an integer for factorial test: \n");
  scanf("%d", &n);
  if (n < 0)
    printf("Error! Factorial of a negative number doesn't exist.\n");
  else {
    for (i = 1; i <= n;) {
      factorial = factorial * i;
      i = i + 1;
    }
    printf("Factorial of %d is: %d\n", n, factorial);
  }
}


x86 assembly (clang, -O0):
<factorial_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
jge    116a <factorial_test+0x4a>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a9 <factorial_test+0x89>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1195 <factorial_test+0x75>
mov    -0xc(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1171 <factorial_test+0x51>
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial_test>:
push   %rax
lea    0xf83(%rip),%rdi
call   1030 <puts@plt>
lea    0xf5c(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
js     11a2 <factorial_test+0x72>
mov    $0x1,%edx
je     13aa <factorial_test+0x27a>
mov    $0x1,%eax
cmp    $0x8,%esi
jb     1394 <factorial_test+0x264>
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    11b0 <factorial_test+0x80>
movdqa 0xe6f(%rip),%xmm0
movdqa 0xe77(%rip),%xmm1
movdqa %xmm1,%xmm2
jmp    12f1 <factorial_test+0x1c1>
lea    0xf38(%rip),%rdi
call   1030 <puts@plt>
pop    %rax
ret
and    $0xfffffffc,%edx
movdqa 0xe45(%rip),%xmm0
movdqa 0xe4d(%rip),%xmm1
movdqa 0xe64(%rip),%xmm9
movdqa 0xe6b(%rip),%xmm10
movdqa 0xe72(%rip),%xmm11
movdqa 0xe79(%rip),%xmm12
movdqa 0xe80(%rip),%xmm13
movdqa 0xe87(%rip),%xmm14
movdqa 0xe8e(%rip),%xmm15
movdqa %xmm1,%xmm2
cs nopw 0x0(%rax,%rax,1)
movdqa %xmm0,%xmm6
paddd  0xe04(%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    1210 <factorial_test+0xe0>
test   %ecx,%ecx
je     1361 <factorial_test+0x231>
movdqa 0xd23(%rip),%xmm3
movdqa 0xd2b(%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    1310 <factorial_test+0x1e0>
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     13aa <factorial_test+0x27a>
or     $0x1,%eax
lea    0x1(%rsi),%ecx
nopw   0x0(%rax,%rax,1)
imul   %eax,%edx
add    $0x1,%eax
cmp    %eax,%ecx
jne    13a0 <factorial_test+0x270>
lea    0xcf2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Enter an integer for factorial test: \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"Error! Factorial of a negative number doesn't exist.\0A\00"
@.str.3 = [24 x i8] c"Factorial of %d is: %d\0A\00"
define void @factorial_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 1, i32* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 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* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %25
10: ; preds = %0
store i32 1, i32* %2
br label %11
11: ; preds = %15, %10
%12 = load i32, i32* %2
%13 = load i32, i32* %1
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = mul nsw i32 %16, %17
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %11
21: ; preds = %11
%22 = load i32, i32* %1
%23 = load i32, i32* %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %23)
br label %25
25: ; preds = %21, %8
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [24 x i8] c"Factorial of %d is: %d\0A\00"
@str = [38 x i8] c"Enter an integer for factorial test: \00"
@str.4 = [53 x i8] c"Error! Factorial of a negative number doesn't exist.\00"
define void @factorial_test() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 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 %79, 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 %79, label %68
68: ; preds = %9, %62
%69 = phi i32 [ 1, %9 ], [ %66, %62 ]
%70 = phi i32 [ 1, %9 ], [ %13, %62 ]
br label %73
71: ; preds = %0
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.4, i64 0, i64 0))
br label %82
73: ; preds = %68, %73
%74 = phi i32 [ %76, %73 ], [ %69, %68 ]
%75 = phi i32 [ %77, %73 ], [ %70, %68 ]
%76 = mul nsw i32 %74, %75
%77 = add nuw i32 %75, 1
%78 = icmp eq i32 %75, %5
br i1 %78, label %79, label %73
79: ; preds = %73, %62, %7
%80 = phi i32 [ 1, %7 ], [ %66, %62 ], [ %76, %73 ]
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %5, i32 %80)
br label %82
82: ; preds = %79, %71
ret void
}