#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 *);
long double factorial_long(int n) {
  if (n < 0) {
    printf("Error!  Negative factorial not defined.\n");
    exit(65);
  }
  static const long double Fact[] = {
      1.00000000000000000000E0,          1.00000000000000000000E0,
      2.00000000000000000000E0,          6.00000000000000000000E0,
      2.40000000000000000000E1,          1.20000000000000000000E2,
      7.20000000000000000000E2,          5.04000000000000000000E3,
      4.03200000000000000000E4,          3.62880000000000000000E5,
      3.62880000000000000000E6,          3.99168000000000000000E7,
      4.79001600000000000000E8,          6.22702080000000000000E9,
      8.71782912000000000000E10,         1.30767436800000000000E12,
      2.09227898880000000000E13,         3.55687428096000000000E14,
      6.40237370572800000000E15,         1.21645100408832000000E17,
      2.43290200817664000000E18,         5.10909421717094400000E19,
      1.12400072777760768000E21,         2.58520167388849766400E22,
      6.20448401733239439360E23,         1.55112100433309859840E25,
      4.03291461126605635584E26,         1.0888869450418352160768E28,
      3.04888344611713860501504E29,      8.841761993739701954543616E30,
      2.6525285981219105863630848E32,    8.22283865417792281772556288E33,
      2.6313083693369353016721801216E35, 8.68331761881188649551819440128E36};
  long double nFact = 1.0;
  int c;
  if (n <= 33) {
    return Fact[n];
  } else {
    nFact = Fact[33];
    for (c = 34; c < n; c++) {
      nFact *= c;
    }
    return nFact;
  }
}


x86 assembly (clang, -O0):
<factorial_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    114b <factorial_long+0x2b>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
mov    $0x41,%edi
call   1040 <exit@plt>
fld1
fstpt  -0x30(%rbp)
cmpl   $0x21,-0x14(%rbp)
jg     1174 <factorial_long+0x54>
movslq -0x14(%rbp),%rax
shl    $0x4,%rax
lea    0xec7(%rip),%rcx
fldt   (%rax,%rcx,1)
fstpt  -0x10(%rbp)
jmp    11b5 <factorial_long+0x95>
fldt   0x10c6(%rip)
fstpt  -0x30(%rbp)
movl   $0x22,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11af <factorial_long+0x8f>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
fildl  -0x38(%rbp)
fldt   -0x30(%rbp)
fmulp  %st,%st(1)
fstpt  -0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1184 <factorial_long+0x64>
fldt   -0x30(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial_long>:
sub    $0x28,%rsp
test   %edi,%edi
js     123b <factorial_long+0x11b>
cmp    $0x22,%edi
jae    1148 <factorial_long+0x28>
mov    %edi,%eax
shl    $0x4,%rax
lea    0xed2(%rip),%rcx
fldt   (%rax,%rcx,1)
fldz
jmp    1234 <factorial_long+0x114>
fldl   0xeb2(%rip)
fldz
je     1234 <factorial_long+0x114>
fstp   %st(1)
fstp   %st(0)
lea    -0x22(%rdi),%ecx
add    $0xffffffdd,%edi
mov    %ecx,%eax
and    $0x7,%eax
fldl   0xe95(%rip)
mov    $0x22,%esi
fldz
cmp    $0x7,%edi
fldz
jb     1211 <factorial_long+0xf1>
fstp   %st(1)
fstp   %st(0)
fstp   %st(0)
and    $0xfffffff8,%ecx
neg    %ecx
fldl   0xe72(%rip)
mov    $0x22,%edx
flds   0xe6f(%rip)
fldz
fxch   %st(2)
fxch   %st(1)
nop
fstp   %st(2)
fmul   %st(1),%st
lea    0x1(%rdx),%esi
mov    %esi,0x24(%rsp)
fimull 0x24(%rsp)
lea    0x2(%rdx),%esi
mov    %esi,0x20(%rsp)
fimull 0x20(%rsp)
lea    0x3(%rdx),%esi
mov    %esi,0x1c(%rsp)
fimull 0x1c(%rsp)
lea    0x4(%rdx),%esi
mov    %esi,0x18(%rsp)
fimull 0x18(%rsp)
lea    0x5(%rdx),%esi
mov    %esi,0x14(%rsp)
fimull 0x14(%rsp)
lea    0x6(%rdx),%esi
mov    %esi,0x10(%rsp)
fimull 0x10(%rsp)
lea    0x7(%rdx),%esi
mov    %esi,0xc(%rsp)
fimull 0xc(%rsp)
fxch   %st(1)
fadds  0xe13(%rip)
mov    %edx,%esi
add    $0x8,%esi
lea    (%rcx,%rdx,1),%edi
add    $0x8,%edi
mov    %esi,%edx
fld    %st(1)
cmp    $0x22,%edi
fxch   %st(2)
fxch   %st(1)
jne    11a0 <factorial_long+0x80>
fstp   %st(0)
test   %eax,%eax
fxch   %st(1)
je     1234 <factorial_long+0x114>
fstp   %st(1)
fldz
nopl   (%rax)
fstp   %st(0)
mov    %esi,0x8(%rsp)
fimull 0x8(%rsp)
add    $0x1,%esi
add    $0xffffffff,%eax
fldz
jne    1220 <factorial_long+0x100>
fstp   %st(0)
add    $0x28,%rsp
ret
lea    0xfee(%rip),%rdi
call   1030 <puts@plt>
mov    $0x41,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Error! Negative factorial not defined.\0A\00"
@factorial_long.Fact = internal constant [34 x x86_fp80] [x86_fp80 0xK3FFF8000000000000000, x86_fp80 0xK3FFF8000000000000000, x86_fp80 0xK40008000000000000000, x86_fp80 0xK4001C000000000000000, x86_fp80 0xK4003C000000000000000, x86_fp80 0xK4005F000000000000000, x86_fp80 0xK4008B400000000000000, x86_fp80 0xK400B9D80000000000000, x86_fp80 0xK400E9D80000000000000, x86_fp80 0xK4011B130000000000000, x86_fp80 0xK4014DD7C000000000000, x86_fp80 0xK40189845400000000000, x86_fp80 0xK401BE467E00000000000, x86_fp80 0xK401FB994660000000000, x86_fp80 0xK4023A261D94000000000, x86_fp80 0xK4027983BBBAC00000000, x86_fp80 0xK402B983BBBAC00000000, x86_fp80 0xK402FA1BF7766C0000000, x86_fp80 0xK4033B5F7665398000000, x86_fp80 0xK4037D815C98344800000, x86_fp80 0xK403C870D9DF20AD00000, x86_fp80 0xK4040B141DF4DAE310000, x86_fp80 0xK4044F3BA930ACF836000, x86_fp80 0xK4049AF2E19AFC5267000, x86_fp80 0xK404E83629343D3DCD000, x86_fp80 0xK4052CD4A0619FB090800, x86_fp80 0xK4057A6CC24F51BF75800, x86_fp80 0xK405C8CBC3F2ECF98B000, x86_fp80 0xK4060F6496E91EB4B3800, x86_fp80 0xK4065DF328C343D3C2800, x86_fp80 0xK406AD13F6370F9686800, x86_fp80 0xK406FCAB56855719D2000, x86_fp80 0xK4074CAB56855719D2000, x86_fp80 0xK4079D10B13981D2A0800]
define x86_fp80 @factorial_long(i32 %0) {
%2 = alloca x86_fp80
%3 = alloca i32
%4 = alloca x86_fp80
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 65)
unreachable
11: ; preds = %1
store x86_fp80 0xK3FFF8000000000000000, x86_fp80* %4
%12 = load i32, i32* %3
%13 = icmp sle i32 %12, 33
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [34 x x86_fp80], [34 x x86_fp80]* @factorial_long.Fact, i64 0, i64 %16
%18 = load x86_fp80, x86_fp80* %17
store x86_fp80 %18, x86_fp80* %2
br label %35
19: ; preds = %11
%20 = load x86_fp80, x86_fp80* getelementptr inbounds ([34 x x86_fp80], [34 x x86_fp80]* @factorial_long.Fact, i64 0, i64 33)
store x86_fp80 %20, x86_fp80* %4
store i32 34, i32* %5
br label %21
21: ; preds = %30, %19
%22 = load i32, i32* %5
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i32, i32* %5
%27 = sitofp i32 %26 to x86_fp80
%28 = load x86_fp80, x86_fp80* %4
%29 = fmul x86_fp80 %28, %27
store x86_fp80 %29, x86_fp80* %4
br label %30
30: ; preds = %25
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %21
33: ; preds = %21
%34 = load x86_fp80, x86_fp80* %4
store x86_fp80 %34, x86_fp80* %2
br label %35
35: ; preds = %33, %14
%36 = load x86_fp80, x86_fp80* %2
ret x86_fp80 %36
}

LLVM IR (-O2):
@factorial_long.Fact = internal unnamed_addr constant [34 x x86_fp80] [x86_fp80 0xK3FFF8000000000000000, x86_fp80 0xK3FFF8000000000000000, x86_fp80 0xK40008000000000000000, x86_fp80 0xK4001C000000000000000, x86_fp80 0xK4003C000000000000000, x86_fp80 0xK4005F000000000000000, x86_fp80 0xK4008B400000000000000, x86_fp80 0xK400B9D80000000000000, x86_fp80 0xK400E9D80000000000000, x86_fp80 0xK4011B130000000000000, x86_fp80 0xK4014DD7C000000000000, x86_fp80 0xK40189845400000000000, x86_fp80 0xK401BE467E00000000000, x86_fp80 0xK401FB994660000000000, x86_fp80 0xK4023A261D94000000000, x86_fp80 0xK4027983BBBAC00000000, x86_fp80 0xK402B983BBBAC00000000, x86_fp80 0xK402FA1BF7766C0000000, x86_fp80 0xK4033B5F7665398000000, x86_fp80 0xK4037D815C98344800000, x86_fp80 0xK403C870D9DF20AD00000, x86_fp80 0xK4040B141DF4DAE310000, x86_fp80 0xK4044F3BA930ACF836000, x86_fp80 0xK4049AF2E19AFC5267000, x86_fp80 0xK404E83629343D3DCD000, x86_fp80 0xK4052CD4A0619FB090800, x86_fp80 0xK4057A6CC24F51BF75800, x86_fp80 0xK405C8CBC3F2ECF98B000, x86_fp80 0xK4060F6496E91EB4B3800, x86_fp80 0xK4065DF328C343D3C2800, x86_fp80 0xK406AD13F6370F9686800, x86_fp80 0xK406FCAB56855719D2000, x86_fp80 0xK4074CAB56855719D2000, x86_fp80 0xK4079D10B13981D2A0800]
@str = [40 x i8] c"Error! Negative factorial not defined.\00"
define x86_fp80 @factorial_long(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 65)
unreachable
6: ; preds = %1
%7 = icmp ult i32 %0, 34
br i1 %7, label %17, label %8
8: ; preds = %6
%9 = icmp eq i32 %0, 34
br i1 %9, label %65, label %10
10: ; preds = %8
%11 = add i32 %0, -34
%12 = add i32 %0, -35
%13 = and i32 %11, 7
%14 = icmp ult i32 %12, 7
br i1 %14, label %51, label %15
15: ; preds = %10
%16 = and i32 %11, -8
br label %21
17: ; preds = %6
%18 = zext i32 %0 to i64
%19 = getelementptr inbounds [34 x x86_fp80], [34 x x86_fp80]* @factorial_long.Fact, i64 0, i64 %18
%20 = load x86_fp80, x86_fp80* %19
br label %65
21: ; preds = %21, %15
%22 = phi i32 [ 34, %15 ], [ %48, %21 ]
%23 = phi x86_fp80 [ 0xK4079D10B13981D2A0800, %15 ], [ %47, %21 ]
%24 = phi i32 [ 0, %15 ], [ %49, %21 ]
%25 = sitofp i32 %22 to x86_fp80
%26 = fmul x86_fp80 %23, %25
%27 = or i32 %22, 1
%28 = sitofp i32 %27 to x86_fp80
%29 = fmul x86_fp80 %26, %28
%30 = add nuw nsw i32 %22, 2
%31 = sitofp i32 %30 to x86_fp80
%32 = fmul x86_fp80 %29, %31
%33 = add nuw nsw i32 %22, 3
%34 = sitofp i32 %33 to x86_fp80
%35 = fmul x86_fp80 %32, %34
%36 = add nuw nsw i32 %22, 4
%37 = sitofp i32 %36 to x86_fp80
%38 = fmul x86_fp80 %35, %37
%39 = add nuw nsw i32 %22, 5
%40 = sitofp i32 %39 to x86_fp80
%41 = fmul x86_fp80 %38, %40
%42 = add nuw nsw i32 %22, 6
%43 = sitofp i32 %42 to x86_fp80
%44 = fmul x86_fp80 %41, %43
%45 = add nuw nsw i32 %22, 7
%46 = sitofp i32 %45 to x86_fp80
%47 = fmul x86_fp80 %44, %46
%48 = add nuw nsw i32 %22, 8
%49 = add i32 %24, 8
%50 = icmp eq i32 %49, %16
br i1 %50, label %51, label %21
51: ; preds = %21, %10
%52 = phi x86_fp80 [ undef, %10 ], [ %47, %21 ]
%53 = phi i32 [ 34, %10 ], [ %48, %21 ]
%54 = phi x86_fp80 [ 0xK4079D10B13981D2A0800, %10 ], [ %47, %21 ]
%55 = icmp eq i32 %13, 0
br i1 %55, label %65, label %56
56: ; preds = %51, %56
%57 = phi i32 [ %62, %56 ], [ %53, %51 ]
%58 = phi x86_fp80 [ %61, %56 ], [ %54, %51 ]
%59 = phi i32 [ %63, %56 ], [ 0, %51 ]
%60 = sitofp i32 %57 to x86_fp80
%61 = fmul x86_fp80 %58, %60
%62 = add nuw nsw i32 %57, 1
%63 = add i32 %59, 1
%64 = icmp eq i32 %63, %13
br i1 %64, label %65, label %56
65: ; preds = %51, %56, %8, %17
%66 = phi x86_fp80 [ %20, %17 ], [ 0xK4079D10B13981D2A0800, %8 ], [ %52, %51 ], [ %61, %56 ]
ret x86_fp80 %66
}