#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, count;
  double fact = 1.;
  printf("\nn = ");
  scanf("%d", &n);
  if (n < 0) {
    printf("\nError: factorial of negative integer not defined\n");
    exit(1);
  }
  for (count = n; count > 0; --count)
    fact *= (double)count;
  printf("\nn = %5d   Factorial(n) = %12.3e\n", n, fact);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    118c <main+0x5c>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11b9 <main+0x89>
cvtsi2sdl -0xc(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1192 <main+0x62>
mov    -0x8(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
lea    0xe7c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
js     1241 <main+0x101>
je     1227 <main+0xe7>
lea    -0x1(%rsi),%ecx
mov    %esi,%edx
movsd  0xe81(%rip),%xmm0
mov    %esi,%eax
and    $0x7,%edx
je     11a3 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
add    $0xffffffff,%eax
add    $0xffffffff,%edx
jne    1190 <main+0x50>
cmp    $0x7,%ecx
jb     122f <main+0xef>
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
lea    -0x1(%rax),%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
mulsd  %xmm0,%xmm1
lea    -0x2(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  %xmm1,%xmm2
lea    -0x3(%rax),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mulsd  %xmm2,%xmm0
lea    -0x4(%rax),%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
mulsd  %xmm0,%xmm1
lea    -0x5(%rax),%ecx
xorps  %xmm3,%xmm3
cvtsi2sd %ecx,%xmm3
mulsd  %xmm1,%xmm2
lea    -0x6(%rax),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mulsd  %xmm2,%xmm3
lea    -0x7(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm0
add    $0xfffffff8,%eax
cmp    $0x1,%ecx
ja     11b0 <main+0x70>
jmp    122f <main+0xef>
movsd  0xdd1(%rip),%xmm0
lea    0xddb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xdeb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"\0An = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [51 x i8] c"\0AError: factorial of negative integer not defined\0A\00"
@.str.3 = [34 x i8] c"\0An = %5d Factorial(n) = %12.3e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
store i32 0, i32* %1
store double 1.000000e+00, double* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 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 %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* %2
store i32 %13, i32* %3
br label %14
14: ; preds = %22, %12
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i32, i32* %3
%19 = sitofp i32 %18 to double
%20 = load double, double* %4
%21 = fmul double %20, %19
store double %21, double* %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 %14
25: ; preds = %14
%26 = load i32, i32* %2
%27 = load double, double* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %26, double %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"\0An = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [34 x i8] c"\0An = %5d Factorial(n) = %12.3e\0A\00"
@str = [50 x i8] c"\0AError: factorial of negative integer not defined\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 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 %27, label %7
7: ; preds = %0
%8 = icmp eq i32 %5, 0
br i1 %8, label %58, label %9
9: ; preds = %7
%10 = add i32 %5, -1
%11 = and i32 %5, 7
%12 = icmp eq i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %9, %13
%14 = phi double [ %18, %13 ], [ 1.000000e+00, %9 ]
%15 = phi i32 [ %19, %13 ], [ %5, %9 ]
%16 = phi i32 [ %20, %13 ], [ 0, %9 ]
%17 = sitofp i32 %15 to double
%18 = fmul double %14, %17
%19 = add nsw i32 %15, -1
%20 = add i32 %16, 1
%21 = icmp eq i32 %20, %11
br i1 %21, label %22, label %13
22: ; preds = %13, %9
%23 = phi double [ 1.000000e+00, %9 ], [ %18, %13 ]
%24 = phi i32 [ %5, %9 ], [ %19, %13 ]
%25 = phi double [ undef, %9 ], [ %18, %13 ]
%26 = icmp ult i32 %10, 7
br i1 %26, label %58, label %30
27: ; preds = %0
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22, %30
%31 = phi double [ %55, %30 ], [ %23, %22 ]
%32 = phi i32 [ %56, %30 ], [ %24, %22 ]
%33 = sitofp i32 %32 to double
%34 = fmul double %31, %33
%35 = add nsw i32 %32, -1
%36 = sitofp i32 %35 to double
%37 = fmul double %34, %36
%38 = add nsw i32 %32, -2
%39 = sitofp i32 %38 to double
%40 = fmul double %37, %39
%41 = add nsw i32 %32, -3
%42 = sitofp i32 %41 to double
%43 = fmul double %40, %42
%44 = add nsw i32 %32, -4
%45 = sitofp i32 %44 to double
%46 = fmul double %43, %45
%47 = add nsw i32 %32, -5
%48 = sitofp i32 %47 to double
%49 = fmul double %46, %48
%50 = add nsw i32 %32, -6
%51 = sitofp i32 %50 to double
%52 = fmul double %49, %51
%53 = add nsw i32 %32, -7
%54 = sitofp i32 %53 to double
%55 = fmul double %52, %54
%56 = add nsw i32 %32, -8
%57 = icmp ugt i32 %53, 1
br i1 %57, label %30, label %58
58: ; preds = %22, %30, %7
%59 = phi double [ 1.000000e+00, %7 ], [ %25, %22 ], [ %55, %30 ]
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %5, double %59)
ret i32 0
}