#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 */
double UINT_MAX;
unsigned long ULONG_MAX;
double fac(double a) {
  if (a < 0.0)
    return (0.0 / 0.0);
  if (a > UINT_MAX)
    return (1.0 / 0.0);
  unsigned int ua = (unsigned int)(a);
  unsigned long int result = 1, i;
  for (i = 1; i <= ua; i++) {
    if (i > ULONG_MAX / result)
      return (1.0 / 0.0);
    result *= i;
  }
  return (double)result;
}


x86 assembly (clang, -O0):
<fac>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1129 <fac+0x29>
movsd  0xf09(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1200 <fac+0x100>
movsd  -0x10(%rbp),%xmm0
mov    0x2eb3(%rip),%rax
ucomisd (%rax),%xmm0
jbe    1151 <fac+0x51>
movsd  0xed9(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1200 <fac+0x100>
cvttsd2si -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
movq   $0x1,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
ja     11d4 <fac+0xd4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jbe    11b6 <fac+0xb6>
movsd  0xe74(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1200 <fac+0x100>
mov    -0x28(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116a <fac+0x6a>
movaps 0xe25(%rip),%xmm1
movq   -0x20(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe24(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<fac>:
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1117 <fac+0x17>
movsd  0xeea(%rip),%xmm0
ret
mov    0x2eca(%rip),%rax
movsd  0xee2(%rip),%xmm0
ucomisd (%rax),%xmm1
ja     11c2 <fac+0xc2>
cvttsd2si %xmm1,%rax
test   %eax,%eax
je     11c3 <fac+0xc3>
mov    %eax,%r8d
mov    0x2e89(%rip),%rax
mov    (%rax),%rcx
neg    %r8
mov    $0x1,%edi
mov    $0x1,%esi
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1180 <fac+0x80>
mov    %rcx,%rax
xor    %edx,%edx
div    %rsi
cmp    %rax,%rdi
jbe    118b <fac+0x8b>
jmp    11c2 <fac+0xc2>
nopl   0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
cmp    %rax,%rdi
ja     11c2 <fac+0xc2>
imul   %rdi,%rsi
lea    (%r8,%rdi,1),%rax
add    $0x1,%rax
add    $0x1,%rdi
cmp    $0x1,%rax
jne    1160 <fac+0x60>
movq   %rsi,%xmm1
punpckldq 0xe72(%rip),%xmm1
subpd  0xe7a(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
ret
movsd  0xe45(%rip),%xmm0
ret

LLVM IR (-O0):
@UINT_MAX = global double 0.000000e+00
@ULONG_MAX = global i64 0
define double @fac(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store double %0, double* %3
%7 = load double, double* %3
%8 = fcmp olt double %7, 0.000000e+00
br i1 %8, label %9, label %10
9: ; preds = %1
store double 0x7FF8000000000000, double* %2
br label %40
10: ; preds = %1
%11 = load double, double* %3
%12 = load double, double* @UINT_MAX
%13 = fcmp ogt double %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store double 0x7FF0000000000000, double* %2
br label %40
15: ; preds = %10
%16 = load double, double* %3
%17 = fptoui double %16 to i32
store i32 %17, i32* %4
store i64 1, i64* %5
store i64 1, i64* %6
br label %18
18: ; preds = %34, %15
%19 = load i64, i64* %6
%20 = load i32, i32* %4
%21 = zext i32 %20 to i64
%22 = icmp ule i64 %19, %21
br i1 %22, label %23, label %37
23: ; preds = %18
%24 = load i64, i64* %6
%25 = load i64, i64* @ULONG_MAX
%26 = load i64, i64* %5
%27 = udiv i64 %25, %26
%28 = icmp ugt i64 %24, %27
br i1 %28, label %29, label %30
29: ; preds = %23
store double 0x7FF0000000000000, double* %2
br label %40
30: ; preds = %23
%31 = load i64, i64* %6
%32 = load i64, i64* %5
%33 = mul i64 %32, %31
store i64 %33, i64* %5
br label %34
34: ; preds = %30
%35 = load i64, i64* %6
%36 = add i64 %35, 1
store i64 %36, i64* %6
br label %18
37: ; preds = %18
%38 = load i64, i64* %5
%39 = uitofp i64 %38 to double
store double %39, double* %2
br label %40
40: ; preds = %37, %29, %14, %9
%41 = load double, double* %2
ret double %41
}

LLVM IR (-O2):
@UINT_MAX = global double 0.000000e+00
@ULONG_MAX = global i64 0
define double @fac(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = load double, double* @UINT_MAX
%5 = fcmp olt double %4, %0
br i1 %5, label %23, label %6
6: ; preds = %3
%7 = fptoui double %0 to i32
%8 = icmp eq i32 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = zext i32 %7 to i64
%11 = load i64, i64* @ULONG_MAX
br label %12
12: ; preds = %9, %17
%13 = phi i64 [ 1, %9 ], [ %19, %17 ]
%14 = phi i64 [ 1, %9 ], [ %18, %17 ]
%15 = udiv i64 %11, %14
%16 = icmp ugt i64 %13, %15
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = mul i64 %13, %14
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %13, %10
br i1 %20, label %21, label %12
21: ; preds = %17
%22 = uitofp i64 %18 to double
br label %23
23: ; preds = %12, %6, %21, %3, %1
%24 = phi double [ 0x7FF8000000000000, %1 ], [ 0x7FF0000000000000, %3 ], [ 1.000000e+00, %6 ], [ %22, %21 ], [ 0x7FF0000000000000, %12 ]
ret double %24
}