#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 */
typedef int uint64_t;

/* Variables and functions */
double taylor_tan(double x, unsigned int n) {
  if (n >= 14)
    return .0;
  static const uint64_t numerator[] = {1,
                                       1,
                                       2,
                                       17,
                                       62,
                                       1382,
                                       21844,
                                       929569,
                                       6404582,
                                       443861162,
                                       18888466084,
                                       113927491862,
                                       58870668456604};
  static const uint64_t denominator[] = {1,
                                         3,
                                         15,
                                         315,
                                         2835,
                                         155925,
                                         6081075,
                                         638512875,
                                         10854718875,
                                         1856156927625,
                                         194896477400625,
                                         49308808782358125,
                                         3698160658676859375};
  const double pow2x = x * x;
  double lastTopX = x;
  double res = 0;
  for (unsigned int i = 0; i < n; i++) {
    res += (numerator[i] * lastTopX) / denominator[i];
    lastTopX *= pow2x;
  }
  return res;
}


x86 assembly (clang, -O0):
<taylor_tan>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
cmpl   $0xe,-0x14(%rbp)
jb     1123 <taylor_tan+0x23>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <taylor_tan+0xb3>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11a9 <taylor_tan+0xa9>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
lea    0xe9d(%rip),%rax
cvtsi2sdl (%rax,%rcx,4),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
lea    0xec7(%rip),%rax
cvtsi2sdl (%rax,%rcx,4),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    114b <taylor_tan+0x4b>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<taylor_tan>:
xorpd  %xmm1,%xmm1
cmp    $0xd,%edi
ja     1159 <taylor_tan+0x59>
test   %edi,%edi
je     1159 <taylor_tan+0x59>
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mov    %edi,%eax
shl    $0x2,%rax
xorpd  %xmm1,%xmm1
xor    %ecx,%ecx
lea    0xed8(%rip),%rdx
lea    0xf11(%rip),%rsi
nop
xorps  %xmm3,%xmm3
cvtsi2sdl (%rcx,%rdx,1),%xmm3
mulsd  %xmm0,%xmm3
xorps  %xmm4,%xmm4
cvtsi2sdl (%rcx,%rsi,1),%xmm4
divsd  %xmm4,%xmm3
addsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
add    $0x4,%rcx
cmp    %rcx,%rax
jne    1130 <taylor_tan+0x30>
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
@taylor_tan.numerator = internal constant [13 x i32] [i32 1, i32 1, i32 2, i32 17, i32 62, i32 1382, i32 21844, i32 929569, i32 6404582, i32 443861162, i32 1708596900, i32 -2036625130, i32 -448269668]
@taylor_tan.denominator = internal constant [13 x i32] [i32 1, i32 3, i32 15, i32 315, i32 2835, i32 155925, i32 6081075, i32 638512875, i32 -2030183013, i32 731055753, i32 -548557263, i32 -1346034067, i32 2126660079]
define double @taylor_tan(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp uge i32 %10, 14
br i1 %11, label %12, label %13
12: ; preds = %2
store double 0.000000e+00, double* %3
br label %46
13: ; preds = %2
%14 = load double, double* %4
%15 = load double, double* %4
%16 = fmul double %14, %15
store double %16, double* %6
%17 = load double, double* %4
store double %17, double* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %9
br label %18
18: ; preds = %41, %13
%19 = load i32, i32* %9
%20 = load i32, i32* %5
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %44
22: ; preds = %18
%23 = load i32, i32* %9
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [13 x i32], [13 x i32]* @taylor_tan.numerator, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = sitofp i32 %26 to double
%28 = load double, double* %7
%29 = fmul double %27, %28
%30 = load i32, i32* %9
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [13 x i32], [13 x i32]* @taylor_tan.denominator, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = sitofp i32 %33 to double
%35 = fdiv double %29, %34
%36 = load double, double* %8
%37 = fadd double %36, %35
store double %37, double* %8
%38 = load double, double* %6
%39 = load double, double* %7
%40 = fmul double %39, %38
store double %40, double* %7
br label %41
41: ; preds = %22
%42 = load i32, i32* %9
%43 = add i32 %42, 1
store i32 %43, i32* %9
br label %18
44: ; preds = %18
%45 = load double, double* %8
store double %45, double* %3
br label %46
46: ; preds = %44, %12
%47 = load double, double* %3
ret double %47
}

LLVM IR (-O2):
@taylor_tan.numerator = internal unnamed_addr constant [13 x i32] [i32 1, i32 1, i32 2, i32 17, i32 62, i32 1382, i32 21844, i32 929569, i32 6404582, i32 443861162, i32 1708596900, i32 -2036625130, i32 -448269668]
@taylor_tan.denominator = internal unnamed_addr constant [13 x i32] [i32 1, i32 3, i32 15, i32 315, i32 2835, i32 155925, i32 6081075, i32 638512875, i32 -2030183013, i32 731055753, i32 -548557263, i32 -1346034067, i32 2126660079]
define double @taylor_tan(double %0, i32 %1) {
%3 = icmp ugt i32 %1, 13
br i1 %3, label %25, label %4
4: ; preds = %2
%5 = fmul double %0, %0
%6 = icmp eq i32 %1, 0
br i1 %6, label %25, label %7
7: ; preds = %4
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %23, %9 ]
%11 = phi double [ 0.000000e+00, %7 ], [ %21, %9 ]
%12 = phi double [ %0, %7 ], [ %22, %9 ]
%13 = getelementptr inbounds [13 x i32], [13 x i32]* @taylor_tan.numerator, i64 0, i64 %10
%14 = load i32, i32* %13
%15 = sitofp i32 %14 to double
%16 = fmul double %12, %15
%17 = getelementptr inbounds [13 x i32], [13 x i32]* @taylor_tan.denominator, i64 0, i64 %10
%18 = load i32, i32* %17
%19 = sitofp i32 %18 to double
%20 = fdiv double %16, %19
%21 = fadd double %11, %20
%22 = fmul double %5, %12
%23 = add nuw nsw i64 %10, 1
%24 = icmp eq i64 %23, %8
br i1 %24, label %25, label %9
25: ; preds = %9, %4, %2
%26 = phi double [ 0.000000e+00, %2 ], [ 0.000000e+00, %4 ], [ %21, %9 ]
ret double %26
}