#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 fabs(double);
int factorial(int);
double pow(double, int);
double taylorint(int n, double x) {
  static double sum = 0;
  double accuracy = 1.0E-10;
  static int iteration = 0;
  double term;
  int sign = 1;
  double top = pow(x, n + 1);
  double bottom = n + 1;
  term = sign * top / bottom;
  if (fabs(term) > accuracy) {
    iteration += 1;
    top *= x;
    bottom = factorial(iteration) * (iteration + n + 1);
    return sum + term + taylorint(n, x);
  } else {
    iteration = 0;
    return sum;
  }
}


x86 assembly (clang, -O0):
<taylorint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  0xec8(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1040 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movaps 0xe68(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    121d <taylorint+0xed>
mov    0x2e9b(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e92(%rip)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    0x2e7d(%rip),%edi
call   1030 <factorial@plt>
mov    0x2e72(%rip),%ecx
add    -0xc(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0x2e50(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0xc(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   1050 <taylorint@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1234 <taylorint+0x104>
movl   $0x0,0x2e21(%rip)
movsd  0x2e11(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<taylorint>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x1(%rbx),%ebp
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%edi
call   1040 <pow@plt>
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
movapd 0xea8(%rip),%xmm1
andpd  %xmm0,%xmm1
ucomisd 0xeac(%rip),%xmm1
jbe    11a5 <taylorint+0x75>
mov    0x2ed0(%rip),%edi
add    $0x1,%edi
mov    %edi,0x2ec7(%rip)
movapd %xmm0,(%rsp)
call   1030 <factorial@plt>
xorpd  %xmm0,%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
mov    %ebx,%edi
movsd  0x10(%rsp),%xmm0
call   1050 <taylorint@plt>
addsd  (%rsp),%xmm0
jmp    11b3 <taylorint+0x83>
movl   $0x0,0x2e8d(%rip)
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@taylorint.sum = internal global double 0.000000e+00
@taylorint.iteration = internal global i32 0
define double @taylorint(i32 %0, double %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store double 1.000000e-10, double* %6
store i32 1, i32* %8
%11 = load double, double* %5
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
%14 = call double @pow(double %11, i32 %13)
store double %14, double* %9
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
%17 = sitofp i32 %16 to double
store double %17, double* %10
%18 = load i32, i32* %8
%19 = sitofp i32 %18 to double
%20 = load double, double* %9
%21 = fmul double %19, %20
%22 = load double, double* %10
%23 = fdiv double %21, %22
store double %23, double* %7
%24 = load double, double* %7
%25 = call double @llvm.fabs.f64(double %24)
%26 = load double, double* %6
%27 = fcmp ogt double %25, %26
br i1 %27, label %28, label %49
28: ; preds = %2
%29 = load i32, i32* @taylorint.iteration
%30 = add nsw i32 %29, 1
store i32 %30, i32* @taylorint.iteration
%31 = load double, double* %5
%32 = load double, double* %9
%33 = fmul double %32, %31
store double %33, double* %9
%34 = load i32, i32* @taylorint.iteration
%35 = call i32 @factorial(i32 %34)
%36 = load i32, i32* @taylorint.iteration
%37 = load i32, i32* %4
%38 = add nsw i32 %36, %37
%39 = add nsw i32 %38, 1
%40 = mul nsw i32 %35, %39
%41 = sitofp i32 %40 to double
store double %41, double* %10
%42 = load double, double* @taylorint.sum
%43 = load double, double* %7
%44 = fadd double %42, %43
%45 = load i32, i32* %4
%46 = load double, double* %5
%47 = call double @taylorint(i32 %45, double %46)
%48 = fadd double %44, %47
store double %48, double* %3
br label %51
49: ; preds = %2
store i32 0, i32* @taylorint.iteration
%50 = load double, double* @taylorint.sum
store double %50, double* %3
br label %51
51: ; preds = %49, %28
%52 = load double, double* %3
ret double %52
}

LLVM IR (-O2):
@taylorint.iteration = internal unnamed_addr global i32 0
define double @taylorint(i32 %0, double %1) {
%3 = add nsw i32 %0, 1
%4 = tail call double @pow(double %1, i32 %3)
%5 = sitofp i32 %3 to double
%6 = fdiv double %4, %5
%7 = tail call double @llvm.fabs.f64(double %6)
%8 = fcmp ogt double %7, 1.000000e-10
br i1 %8, label %11, label %18
9: ; preds = %18, %11
%10 = phi double [ %17, %11 ], [ 0.000000e+00, %18 ]
ret double %10
11: ; preds = %2
%12 = load i32, i32* @taylorint.iteration
%13 = add nsw i32 %12, 1
store i32 %13, i32* @taylorint.iteration
%14 = tail call i32 @factorial(i32 %13)
%15 = fadd double %6, 0.000000e+00
%16 = tail call double @taylorint(i32 %0, double %1)
%17 = fadd double %15, %16
br label %9
18: ; preds = %2
store i32 0, i32* @taylorint.iteration
br label %9
}