#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 number, count;
  long unsigned int factorial;
  factorial = 1;
start:
  printf("Enter a number: ");
  scanf("%d", &number);
  if (number < 0) {
    printf("Factorial of negative number doesn't exist.\n");
    goto start;
  } else {
    for (count = 1; count <= number; count++) {
      factorial *= count;
    }
    printf("Factorial of %d = %lu\n", number, 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    0xec5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1172 <main+0x52>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1137 <main+0x17>
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    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jns    11a5 <main+0x75>
lea    0xec5(%rip),%r14
lea    0xe93(%rip),%r15
lea    0xe9d(%rip),%r12
lea    0x4(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
js     1180 <main+0x50>
test   %esi,%esi
je     11d4 <main+0xa4>
mov    %esi,%r8d
lea    -0x1(%r8),%rcx
mov    %r8d,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
jae    11de <main+0xae>
mov    $0x1,%ecx
mov    $0x1,%edx
test   %rax,%rax
jne    1250 <main+0x120>
jmp    125e <main+0x12e>
mov    $0x1,%edx
jmp    125e <main+0x12e>
and    $0xfffffff8,%r8d
neg    %r8
mov    $0x1,%edx
mov    $0x8,%ecx
nop
lea    -0x7(%rcx),%rbx
imul   %rdx,%rbx
lea    -0x6(%rcx),%rdx
lea    -0x5(%rcx),%rdi
imul   %rdi,%rdx
imul   %rbx,%rdx
lea    -0x4(%rcx),%rdi
lea    -0x3(%rcx),%rbx
imul   %rbx,%rdi
lea    -0x2(%rcx),%rbx
imul   %rdi,%rbx
imul   %rdx,%rbx
lea    -0x1(%rcx),%rdx
imul   %rcx,%rdx
imul   %rbx,%rdx
lea    (%r8,%rcx,1),%rdi
add    $0x8,%rdi
add    $0x8,%rcx
cmp    $0x8,%rdi
jne    11f0 <main+0xc0>
add    $0xfffffffffffffff9,%rcx
test   %rax,%rax
je     125e <main+0x12e>
nopw   0x0(%rax,%rax,1)
imul   %rcx,%rdx
add    $0x1,%rcx
add    $0xffffffffffffffff,%rax
jne    1250 <main+0x120>
lea    0xdaf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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