#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 lngammafn(double);
double log(double);
double stirlerr(double n) {
  const static double sferr_halves[31] = {0.0,
                                          0.1534264097200273452913848,
                                          0.0810614667953272582196702,
                                          0.0548141210519176538961390,
                                          0.0413406959554092940938221,
                                          0.03316287351993628748511048,
                                          0.02767792568499833914878929,
                                          0.02374616365629749597132920,
                                          0.02079067210376509311152277,
                                          0.01848845053267318523077934,
                                          0.01664469118982119216319487,
                                          0.01513497322191737887351255,
                                          0.01387612882307074799874573,
                                          0.01281046524292022692424986,
                                          0.01189670994589177009505572,
                                          0.01110455975820691732662991,
                                          0.010411265261972096497478567,
                                          0.009799416126158803298389475,
                                          0.009255462182712732917728637,
                                          0.008768700134139385462952823,
                                          0.008330563433362871256469318,
                                          0.007934114564314020547248100,
                                          0.007573675487951840794972024,
                                          0.007244554301320383179543912,
                                          0.006942840107209529865664152,
                                          0.006665247032707682442354394,
                                          0.006408994188004207068439631,
                                          0.006171712263039457647532867,
                                          0.005951370112758847735624416,
                                          0.005746216513010115682023589,
                                          0.005554733551962801371038690};
  double nn;
  if (n <= 15.0) {
    nn = n + n;
    if (nn == (int)nn)
      return (sferr_halves[(int)nn]);
    return (lngammafn(n + 1.) - (n + 0.5) * log(n) + n -
            0.918938533204672741780329736406);
  }
  nn = n * n;
  if (n > 500)
    return ((0.083333333333333333333 - 0.00277777777777777777778 / nn) / n);
  if (n > 80)
    return (
        (0.083333333333333333333 -
         (0.00277777777777777777778 - 0.00079365079365079365079365 / nn) / nn) /
        n);
  if (n > 35)
    return ((0.083333333333333333333 -
             (0.00277777777777777777778 - (0.00079365079365079365079365 -
                                           0.000595238095238095238095238 / nn) /
                                              nn) /
                 nn) /
            n);
  return ((0.083333333333333333333 -
           (0.00277777777777777777778 - (0.00079365079365079365079365 -
                                         (0.000595238095238095238095238 -
                                          0.0008417508417508417508417508 / nn) /
                                             nn) /
                                            nn) /
               nn) /
          n);
}


x86 assembly (clang, -O0):
<stirlerr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xecb(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1205 <stirlerr+0xe5>
movsd  -0x10(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
cvttsd2si -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
ucomisd %xmm1,%xmm0
jne    118b <stirlerr+0x6b>
jp     118b <stirlerr+0x6b>
cvttsd2si -0x18(%rbp),%eax
movslq %eax,%rcx
lea    0xee4(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    135a <stirlerr+0x23a>
movsd  0xec5(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1030 <lngammafn@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xea6(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x28(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe51(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    135a <stirlerr+0x23a>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xde7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1253 <stirlerr+0x133>
movsd  0xdf5(%rip),%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xde0(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    135a <stirlerr+0x23a>
movsd  -0x10(%rbp),%xmm0
movsd  0xdb0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12a3 <stirlerr+0x183>
movsd  0xdbe(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xda9(%rip),%xmm1
subsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xd90(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    135a <stirlerr+0x23a>
movsd  -0x10(%rbp),%xmm0
movsd  0xd68(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1304 <stirlerr+0x1e4>
movsd  0xd76(%rip),%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xd61(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xd48(%rip),%xmm1
subsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xd2f(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    135a <stirlerr+0x23a>
movsd  0xd34(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xd1f(%rip),%xmm1
subsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xd06(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xced(%rip),%xmm1
subsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xcd4(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stirlerr>:
sub    $0x18,%rsp
movapd %xmm0,%xmm3
movsd  0xed0(%rip),%xmm0
ucomisd %xmm3,%xmm0
jae    1161 <stirlerr+0x41>
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
ucomisd 0xeda(%rip),%xmm3
jbe    1190 <stirlerr+0x70>
movsd  0xf20(%rip),%xmm4
divsd  %xmm0,%xmm4
addsd  0xefc(%rip),%xmm4
jmp    1291 <stirlerr+0x171>
movapd %xmm3,%xmm0
addsd  %xmm3,%xmm0
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b3 <stirlerr+0x93>
jp     11b3 <stirlerr+0x93>
cvttsd2si %xmm0,%eax
cltq
lea    0xefa(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm4
jmp    1295 <stirlerr+0x175>
ucomisd 0xe90(%rip),%xmm3
jbe    120d <stirlerr+0xed>
movsd  0xec6(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0xea2(%rip),%xmm1
jmp    1281 <stirlerr+0x161>
movsd  0xe4d(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm3,(%rsp)
call   1030 <lngammafn@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0xe39(%rip),%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1040 <log@plt>
movsd  0x10(%rsp),%xmm4
mulsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm4
addsd  (%rsp),%xmm4
addsd  0xe10(%rip),%xmm4
jmp    1295 <stirlerr+0x175>
ucomisd 0xe1b(%rip),%xmm3
jbe    124d <stirlerr+0x12d>
movsd  0xe41(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0xe1d(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe19(%rip),%xmm2
subsd  %xmm1,%xmm2
divsd  %xmm0,%xmm2
movsd  0xe11(%rip),%xmm4
subsd  %xmm2,%xmm4
jmp    1291 <stirlerr+0x171>
movsd  0xde3(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0xddf(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xddb(%rip),%xmm2
subsd  %xmm1,%xmm2
divsd  %xmm0,%xmm2
movsd  0xdd3(%rip),%xmm1
subsd  %xmm2,%xmm1
divsd  %xmm0,%xmm1
movsd  0xdcb(%rip),%xmm4
subsd  %xmm1,%xmm4
divsd  %xmm3,%xmm4
movapd %xmm4,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@stirlerr.sferr_halves = internal constant [31 x double] [double 0.000000e+00, double 0x3FC3A37A020B8C22, double 0x3FB4C071BCDA0A5B, double 0x3FAC1098B28DCF33, double 0x3FA52A9B923EA649, double 0x3FA0FAB9626B44FF, double 0x3F9C579A268D80B3, double 0x3F9850EA113CAF0E, double 0x3F954A2662FD78A9, double 0x3F92EEA2E990F134, double 0x3F910B4E513FCBED, double 0x3F8EFF15B81C9CC5, double 0x3F8C6B167BEBDF36, double 0x3F8A3C5F8A1E7D1D, double 0x3F885D4D612E4A86, double 0x3F86BDFCC7FBDB0A, double 0x3F8552805E7B3076, double 0x3F8411B75E41049C, double 0x3F82F4871B12AB64, double 0x3F81F553026FBCE1, double 0x3F810F9D4C0743A7, double 0x3F803FC2D49C8FB9, double 0x3F7F0593088014F8, double 0x3F7DAC773CC5B3CD, double 0x3F7C7018733AA9C6, double 0x3F7B4D04A067629F, double 0x3F7A40514700F36C, double 0x3F7947826547FE6C, double 0x3F786076C002D4A7, double 0x3F7789583FFC5E8C, double 0x3F76C08F6F194A10]
define double @stirlerr(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %3
%5 = load double, double* %3
%6 = fcmp ole double %5, 1.500000e+01
br i1 %6, label %7, label %35
7: ; preds = %1
%8 = load double, double* %3
%9 = load double, double* %3
%10 = fadd double %8, %9
store double %10, double* %4
%11 = load double, double* %4
%12 = load double, double* %4
%13 = fptosi double %12 to i32
%14 = sitofp i32 %13 to double
%15 = fcmp oeq double %11, %14
br i1 %15, label %16, label %22
16: ; preds = %7
%17 = load double, double* %4
%18 = fptosi double %17 to i32
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [31 x double], [31 x double]* @stirlerr.sferr_halves, i64 0, i64 %19
%21 = load double, double* %20
store double %21, double* %2
br label %89
22: ; preds = %7
%23 = load double, double* %3
%24 = fadd double %23, 1.000000e+00
%25 = call double @lngammafn(double %24)
%26 = load double, double* %3
%27 = fadd double %26, 5.000000e-01
%28 = load double, double* %3
%29 = call double @log(double %28)
%30 = fneg double %27
%31 = call double @llvm.fmuladd.f64(double %30, double %29, double %25)
%32 = load double, double* %3
%33 = fadd double %31, %32
%34 = fsub double %33, 0x3FED67F1C864BEB5
store double %34, double* %2
br label %89
35: ; preds = %1
%36 = load double, double* %3
%37 = load double, double* %3
%38 = fmul double %36, %37
store double %38, double* %4
%39 = load double, double* %3
%40 = fcmp ogt double %39, 5.000000e+02
br i1 %40, label %41, label %47
41: ; preds = %35
%42 = load double, double* %4
%43 = fdiv double 0x3F66C16C16C16C17, %42
%44 = fsub double 0x3FB5555555555555, %43
%45 = load double, double* %3
%46 = fdiv double %44, %45
store double %46, double* %2
br label %89
47: ; preds = %35
%48 = load double, double* %3
%49 = fcmp ogt double %48, 8.000000e+01
br i1 %49, label %50, label %59
50: ; preds = %47
%51 = load double, double* %4
%52 = fdiv double 0x3F4A01A01A01A01A, %51
%53 = fsub double 0x3F66C16C16C16C17, %52
%54 = load double, double* %4
%55 = fdiv double %53, %54
%56 = fsub double 0x3FB5555555555555, %55
%57 = load double, double* %3
%58 = fdiv double %56, %57
store double %58, double* %2
br label %89
59: ; preds = %47
%60 = load double, double* %3
%61 = fcmp ogt double %60, 3.500000e+01
br i1 %61, label %62, label %74
62: ; preds = %59
%63 = load double, double* %4
%64 = fdiv double 0x3F43813813813814, %63
%65 = fsub double 0x3F4A01A01A01A01A, %64
%66 = load double, double* %4
%67 = fdiv double %65, %66
%68 = fsub double 0x3F66C16C16C16C17, %67
%69 = load double, double* %4
%70 = fdiv double %68, %69
%71 = fsub double 0x3FB5555555555555, %70
%72 = load double, double* %3
%73 = fdiv double %71, %72
store double %73, double* %2
br label %89
74: ; preds = %59
%75 = load double, double* %4
%76 = fdiv double 0x3F4B951E2B18FF23, %75
%77 = fsub double 0x3F43813813813814, %76
%78 = load double, double* %4
%79 = fdiv double %77, %78
%80 = fsub double 0x3F4A01A01A01A01A, %79
%81 = load double, double* %4
%82 = fdiv double %80, %81
%83 = fsub double 0x3F66C16C16C16C17, %82
%84 = load double, double* %4
%85 = fdiv double %83, %84
%86 = fsub double 0x3FB5555555555555, %85
%87 = load double, double* %3
%88 = fdiv double %86, %87
store double %88, double* %2
br label %89
89: ; preds = %74, %62, %50, %41, %22, %16
%90 = load double, double* %2
ret double %90
}

LLVM IR (-O2):
@stirlerr.sferr_halves = internal unnamed_addr constant [31 x double] [double 0.000000e+00, double 0x3FC3A37A020B8C22, double 0x3FB4C071BCDA0A5B, double 0x3FAC1098B28DCF33, double 0x3FA52A9B923EA649, double 0x3FA0FAB9626B44FF, double 0x3F9C579A268D80B3, double 0x3F9850EA113CAF0E, double 0x3F954A2662FD78A9, double 0x3F92EEA2E990F134, double 0x3F910B4E513FCBED, double 0x3F8EFF15B81C9CC5, double 0x3F8C6B167BEBDF36, double 0x3F8A3C5F8A1E7D1D, double 0x3F885D4D612E4A86, double 0x3F86BDFCC7FBDB0A, double 0x3F8552805E7B3076, double 0x3F8411B75E41049C, double 0x3F82F4871B12AB64, double 0x3F81F553026FBCE1, double 0x3F810F9D4C0743A7, double 0x3F803FC2D49C8FB9, double 0x3F7F0593088014F8, double 0x3F7DAC773CC5B3CD, double 0x3F7C7018733AA9C6, double 0x3F7B4D04A067629F, double 0x3F7A40514700F36C, double 0x3F7947826547FE6C, double 0x3F786076C002D4A7, double 0x3F7789583FFC5E8C, double 0x3F76C08F6F194A10]
define double @stirlerr(double %0) {
%2 = fcmp ugt double %0, 1.500000e+01
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = fadd double %0, %0
%5 = fptosi double %4 to i32
%6 = sitofp i32 %5 to double
%7 = fcmp oeq double %4, %6
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds [31 x double], [31 x double]* @stirlerr.sferr_halves, i64 0, i64 %9
%11 = load double, double* %10
br label %56
12: ; preds = %3
%13 = fadd double %0, 1.000000e+00
%14 = tail call double @lngammafn(double %13)
%15 = fadd double %0, 5.000000e-01
%16 = tail call double @log(double %0)
%17 = fneg double %15
%18 = tail call double @llvm.fmuladd.f64(double %17, double %16, double %14)
%19 = fadd double %18, %0
%20 = fadd double %19, 0xBFED67F1C864BEB5
br label %56
21: ; preds = %1
%22 = fmul double %0, %0
%23 = fcmp ogt double %0, 5.000000e+02
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = fdiv double 0x3F66C16C16C16C17, %22
%26 = fsub double 0x3FB5555555555555, %25
%27 = fdiv double %26, %0
br label %56
28: ; preds = %21
%29 = fcmp ogt double %0, 8.000000e+01
br i1 %29, label %30, label %36
30: ; preds = %28
%31 = fdiv double 0x3F4A01A01A01A01A, %22
%32 = fsub double 0x3F66C16C16C16C17, %31
%33 = fdiv double %32, %22
%34 = fsub double 0x3FB5555555555555, %33
%35 = fdiv double %34, %0
br label %56
36: ; preds = %28
%37 = fcmp ogt double %0, 3.500000e+01
br i1 %37, label %38, label %46
38: ; preds = %36
%39 = fdiv double 0x3F43813813813814, %22
%40 = fsub double 0x3F4A01A01A01A01A, %39
%41 = fdiv double %40, %22
%42 = fsub double 0x3F66C16C16C16C17, %41
%43 = fdiv double %42, %22
%44 = fsub double 0x3FB5555555555555, %43
%45 = fdiv double %44, %0
br label %56
46: ; preds = %36
%47 = fdiv double 0x3F4B951E2B18FF23, %22
%48 = fsub double 0x3F43813813813814, %47
%49 = fdiv double %48, %22
%50 = fsub double 0x3F4A01A01A01A01A, %49
%51 = fdiv double %50, %22
%52 = fsub double 0x3F66C16C16C16C17, %51
%53 = fdiv double %52, %22
%54 = fsub double 0x3FB5555555555555, %53
%55 = fdiv double %54, %0
br label %56
56: ; preds = %46, %38, %30, %24, %12, %8
%57 = phi double [ %11, %8 ], [ %20, %12 ], [ %27, %24 ], [ %35, %30 ], [ %45, %38 ], [ %55, %46 ]
ret double %57
}