#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 InverseFactorial(int);
double fabs(double);
double pow(double, double);
double sqrt(int);
double BoysSum(double x, int n, double tol) {
  if (x > 4.0)
    return sqrt(-1);
  int k = 0;
  double f = 0.0;
  double d = 0.0;
  do {
    double a = pow(x, (double)k);
    if (k % 2)
      a = -a;
    double b = InverseFactorial(k);
    double c = (2 * n + 2 * n + 1);
    d = a * b / c;
    f += d;
    ++k;
  } while (fabs(d) > tol && fabs(d) < 1.0e7);
  return f;
}


x86 assembly (clang, -O0):
<BoysSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xeae(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1170 <BoysSum+0x40>
mov    $0xffffffff,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127a <BoysSum+0x14a>
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
call   1040 <pow@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11d0 <BoysSum+0xa0>
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <InverseFactorial@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x38(%rbp),%xmm0
movaps 0xde1(%rip),%xmm1
pand   %xmm1,%xmm0
xor    %eax,%eax
ucomisd -0x20(%rbp),%xmm0
mov    %al,-0x51(%rbp)
jbe    1265 <BoysSum+0x135>
movsd  -0x38(%rbp),%xmm1
movaps 0xdc1(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xdad(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1187 <BoysSum+0x57>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BoysSum>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
ucomisd 0xeb7(%rip),%xmm0
jbe    115a <BoysSum+0x2a>
mov    $0xffffffff,%edi
add    $0x30,%rsp
pop    %rbx
jmp    1050 <sqrt@plt>
lea    0x1(,%rdi,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm1,0x18(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  0x8(%rsp),%xmm0
call   1040 <pow@plt>
test   $0x1,%bl
je     11a5 <BoysSum+0x75>
xorpd  0xe6b(%rip),%xmm0
movapd %xmm0,0x20(%rsp)
mov    %ebx,%edi
call   1030 <InverseFactorial@plt>
mulsd  0x20(%rsp),%xmm0
divsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
andpd  0xe51(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
jbe    11e8 <BoysSum+0xb8>
add    $0x1,%ebx
movsd  0xe26(%rip),%xmm2
ucomisd %xmm0,%xmm2
ja     1180 <BoysSum+0x50>
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @BoysSum(double %0, i32 %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double %0, double* %5
store i32 %1, i32* %6
store double %2, double* %7
%14 = load double, double* %5
%15 = fcmp ogt double %14, 4.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = call double @sqrt(i32 -1)
store double %17, double* %4
br label %63
18: ; preds = %3
store i32 0, i32* %8
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
br label %19
19: ; preds = %59, %18
%20 = load double, double* %5
%21 = load i32, i32* %8
%22 = sitofp i32 %21 to double
%23 = call double @pow(double %20, double %22)
store double %23, double* %11
%24 = load i32, i32* %8
%25 = srem i32 %24, 2
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load double, double* %11
%29 = fneg double %28
store double %29, double* %11
br label %30
30: ; preds = %27, %19
%31 = load i32, i32* %8
%32 = call double @InverseFactorial(i32 %31)
store double %32, double* %12
%33 = load i32, i32* %6
%34 = mul nsw i32 2, %33
%35 = load i32, i32* %6
%36 = mul nsw i32 2, %35
%37 = add nsw i32 %34, %36
%38 = add nsw i32 %37, 1
%39 = sitofp i32 %38 to double
store double %39, double* %13
%40 = load double, double* %11
%41 = load double, double* %12
%42 = fmul double %40, %41
%43 = load double, double* %13
%44 = fdiv double %42, %43
store double %44, double* %10
%45 = load double, double* %10
%46 = load double, double* %9
%47 = fadd double %46, %45
store double %47, double* %9
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %50
50: ; preds = %30
%51 = load double, double* %10
%52 = call double @llvm.fabs.f64(double %51)
%53 = load double, double* %7
%54 = fcmp ogt double %52, %53
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = load double, double* %10
%57 = call double @llvm.fabs.f64(double %56)
%58 = fcmp olt double %57, 1.000000e+07
br label %59
59: ; preds = %55, %50
%60 = phi i1 [ false, %50 ], [ %58, %55 ]
br i1 %60, label %19, label %61
61: ; preds = %59
%62 = load double, double* %9
store double %62, double* %4
br label %63
63: ; preds = %61, %16
%64 = load double, double* %4
ret double %64
}

LLVM IR (-O2):
define double @BoysSum(double %0, i32 %1, double %2) {
%4 = fcmp ogt double %0, 4.000000e+00
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = shl nsw i32 %1, 2
%7 = or i32 %6, 1
%8 = sitofp i32 %7 to double
br label %11
9: ; preds = %3
%10 = tail call double @sqrt(i32 -1)
br label %29
11: ; preds = %5, %11
%12 = phi double [ %23, %11 ], [ 0.000000e+00, %5 ]
%13 = phi i32 [ %24, %11 ], [ 0, %5 ]
%14 = sitofp i32 %13 to double
%15 = tail call double @pow(double %0, double %14)
%16 = and i32 %13, 1
%17 = icmp eq i32 %16, 0
%18 = fneg double %15
%19 = select i1 %17, double %15, double %18
%20 = tail call double @InverseFactorial(i32 %13)
%21 = fmul double %20, %19
%22 = fdiv double %21, %8
%23 = fadd double %12, %22
%24 = add nuw nsw i32 %13, 1
%25 = tail call double @llvm.fabs.f64(double %22)
%26 = fcmp ogt double %25, %2
%27 = fcmp olt double %25, 1.000000e+07
%28 = and i1 %26, %27
br i1 %28, label %11, label %29
29: ; preds = %11, %9
%30 = phi double [ %10, %9 ], [ %23, %11 ]
ret double %30
}