#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 *);
double factorial(int n) {
  int count;
  double fact = 1.;
  if (n < 0) {
    printf("\nError: factorial of negative integer not defined\n");
    exit(1);
  }
  for (; n > 0; --n)
    fact *= (double)count;
  return fact;
}


x86 assembly (clang, -O0):
<factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movsd  0xecd(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1158 <factorial+0x38>
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    115d <factorial+0x3d>
cmpl   $0x0,-0x4(%rbp)
jle    1184 <factorial+0x64>
cvtsi2sdl -0x8(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    115d <factorial+0x3d>
movsd  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial>:
push   %rax
test   %edi,%edi
js     11ba <factorial+0x9a>
je     1164 <factorial+0x44>
lea    -0x1(%rdi),%eax
mov    %edi,%ecx
and    $0x7,%ecx
je     116e <factorial+0x4e>
xor    %edx,%edx
movsd  0xec1(%rip),%xmm0
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mulsd  %xmm1,%xmm0
add    $0x1,%edx
cmp    %edx,%ecx
jne    1150 <factorial+0x30>
sub    %edx,%edi
cmp    $0x7,%eax
jae    117b <factorial+0x5b>
jmp    11b8 <factorial+0x98>
movsd  0xe94(%rip),%xmm0
pop    %rax
ret
movsd  0xe8a(%rip),%xmm0
cmp    $0x7,%eax
jb     11b8 <factorial+0x98>
add    $0xffffffff,%edi
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
add    $0xfffffff8,%edi
cmp    $0xfffffffe,%edi
jb     1190 <factorial+0x70>
pop    %rax
ret
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"\0AError: factorial of negative integer not defined\0A\00"
define double @factorial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
store i32 %0, i32* %2
store double 1.000000e+00, double* %4
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
br label %11
11: ; preds = %19, %10
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i32, i32* %3
%16 = sitofp i32 %15 to double
%17 = load double, double* %4
%18 = fmul double %17, %16
store double %18, double* %4
br label %19
19: ; preds = %14
%20 = load i32, i32* %2
%21 = add nsw i32 %20, -1
store i32 %21, i32* %2
br label %11
22: ; preds = %11
%23 = load double, double* %4
ret double %23
}

LLVM IR (-O2):
@str = [50 x i8] c"\0AError: factorial of negative integer not defined\00"
define double @factorial(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = icmp eq i32 %0, 0
br i1 %4, label %39, label %5
5: ; preds = %3
%6 = add i32 %0, -1
%7 = and i32 %0, 7
%8 = icmp eq i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %5, %9
%10 = phi double [ %13, %9 ], [ 1.000000e+00, %5 ]
%11 = phi i32 [ %14, %9 ], [ %0, %5 ]
%12 = phi i32 [ %15, %9 ], [ 0, %5 ]
%13 = fmul double %10, 0.000000e+00
%14 = add nsw i32 %11, -1
%15 = add i32 %12, 1
%16 = icmp eq i32 %15, %7
br i1 %16, label %17, label %9
17: ; preds = %9, %5
%18 = phi double [ 1.000000e+00, %5 ], [ %13, %9 ]
%19 = phi i32 [ %0, %5 ], [ %14, %9 ]
%20 = phi double [ undef, %5 ], [ %13, %9 ]
%21 = icmp ult i32 %6, 7
br i1 %21, label %39, label %25
22: ; preds = %1
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17, %25
%26 = phi double [ %35, %25 ], [ %18, %17 ]
%27 = phi i32 [ %36, %25 ], [ %19, %17 ]
%28 = fmul double %26, 0.000000e+00
%29 = fmul double %28, 0.000000e+00
%30 = fmul double %29, 0.000000e+00
%31 = fmul double %30, 0.000000e+00
%32 = fmul double %31, 0.000000e+00
%33 = fmul double %32, 0.000000e+00
%34 = fmul double %33, 0.000000e+00
%35 = fmul double %34, 0.000000e+00
%36 = add nsw i32 %27, -8
%37 = add i32 %27, -9
%38 = icmp ult i32 %37, -2
br i1 %38, label %25, label %39
39: ; preds = %17, %25, %3
%40 = phi double [ 1.000000e+00, %3 ], [ %20, %17 ], [ %35, %25 ]
ret double %40
}