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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1,-0x18(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1172 <main+0x52>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <main+0x92>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11a0 <main+0x80>
movslq -0xc(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <main+0x59>
mov    -0x18(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%r8d
test   %r8d,%r8d
js     1177 <main+0x57>
test   %r8,%r8
je     118a <main+0x6a>
lea    -0x1(%r8),%rcx
mov    %r8d,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
jae    1194 <main+0x74>
mov    $0x1,%ecx
mov    $0x1,%esi
test   %rax,%rax
jne    1210 <main+0xf0>
jmp    121e <main+0xfe>
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    122c <main+0x10c>
mov    $0x1,%esi
jmp    121e <main+0xfe>
and    $0xfffffff8,%r8d
neg    %r8
mov    $0x1,%esi
mov    $0x8,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x7(%rcx),%rdi
imul   %rsi,%rdi
lea    -0x6(%rcx),%rsi
lea    -0x5(%rcx),%rdx
imul   %rdx,%rsi
imul   %rdi,%rsi
lea    -0x4(%rcx),%rdx
lea    -0x3(%rcx),%rdi
imul   %rdi,%rdx
lea    -0x2(%rcx),%rdi
imul   %rdx,%rdi
imul   %rsi,%rdi
lea    -0x1(%rcx),%rsi
imul   %rcx,%rsi
imul   %rdi,%rsi
lea    (%r8,%rcx,1),%rdx
add    $0x8,%rdx
add    $0x8,%rcx
cmp    $0x8,%rdx
jne    11b0 <main+0x90>
add    $0xfffffffffffffff9,%rcx
test   %rax,%rax
je     121e <main+0xfe>
nopw   0x0(%rax,%rax,1)
imul   %rcx,%rsi
add    $0x1,%rcx
add    $0xffffffffffffffff,%rax
jne    1210 <main+0xf0>
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"Enter an integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [53 x i8] c"Error!!! Factorial of negative number doesn't exist.\00"
@.str.3 = [16 x i8] c"Factorial = %lu\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 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 %18, label %7
7: ; preds = %0
%8 = icmp eq i32 %5, 0
br i1 %8, label %55, label %9
9: ; preds = %7
%10 = add nuw i32 %5, 1
%11 = zext i32 %10 to i64
%12 = add nsw i64 %11, -1
%13 = add nsw i64 %11, -2
%14 = and i64 %12, 7
%15 = icmp ult i64 %13, 7
br i1 %15, label %42, label %16
16: ; preds = %9
%17 = and i64 %12, -8
br label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %58
20: ; preds = %20, %16
%21 = phi i64 [ 1, %16 ], [ %39, %20 ]
%22 = phi i64 [ 1, %16 ], [ %38, %20 ]
%23 = phi i64 [ 0, %16 ], [ %40, %20 ]
%24 = mul i64 %22, %21
%25 = add nuw nsw i64 %21, 1
%26 = mul i64 %24, %25
%27 = add nuw nsw i64 %21, 2
%28 = mul i64 %26, %27
%29 = add nuw nsw i64 %21, 3
%30 = mul i64 %28, %29
%31 = add nuw nsw i64 %21, 4
%32 = mul i64 %30, %31
%33 = add nuw nsw i64 %21, 5
%34 = mul i64 %32, %33
%35 = add nuw nsw i64 %21, 6
%36 = mul i64 %34, %35
%37 = add nuw nsw i64 %21, 7
%38 = mul i64 %36, %37
%39 = add nuw nsw i64 %21, 8
%40 = add i64 %23, 8
%41 = icmp eq i64 %40, %17
br i1 %41, label %42, label %20
42: ; preds = %20, %9
%43 = phi i64 [ undef, %9 ], [ %38, %20 ]
%44 = phi i64 [ 1, %9 ], [ %39, %20 ]
%45 = phi i64 [ 1, %9 ], [ %38, %20 ]
%46 = icmp eq i64 %14, 0
br i1 %46, label %55, label %47
47: ; preds = %42, %47
%48 = phi i64 [ %52, %47 ], [ %44, %42 ]
%49 = phi i64 [ %51, %47 ], [ %45, %42 ]
%50 = phi i64 [ %53, %47 ], [ 0, %42 ]
%51 = mul i64 %49, %48
%52 = add nuw nsw i64 %48, 1
%53 = add i64 %50, 1
%54 = icmp eq i64 %53, %14
br i1 %54, label %55, label %47
55: ; preds = %42, %47, %7
%56 = phi i64 [ 1, %7 ], [ %43, %42 ], [ %51, %47 ]
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %56)
br label %58
58: ; preds = %55, %18
ret i32 0
}