double taylor_tan(double x, unsigned int n) {
  static const double numer[13] = {1,
                                   1,
                                   2,
                                   17,
                                   62,
                                   1382,
                                   21844,
                                   929569,
                                   6404582,
                                   443861162,
                                   18888466084,
                                   113927491862,
                                   58870668456604};
  static const double denom[13] = {1,
                                   3,
                                   15,
                                   315,
                                   2835,
                                   155925,
                                   6081075,
                                   638512875,
                                   10854718875,
                                   1856156927625,
                                   194896477400625,
                                   49308808782358125,
                                   3698160658676859375};
  double sum, xe2;
  sum = 0;
  xe2 = x * x;
  for (unsigned int i = 0; i < n && i < 13; i++) {
    sum += ((x * numer[i]) / denom[i]);
    x *= xe2;
  }
  return sum;
}


x86 assembly (clang, -O0):
<taylor_tan>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x25(%rbp)
jae    1145 <taylor_tan+0x45>
cmpl   $0xd,-0x24(%rbp)
setb   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1155 <taylor_tan+0x55>
jmp    11a3 <taylor_tan+0xa3>
movsd  -0x8(%rbp),%xmm0
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
lea    0xe9a(%rip),%rax
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
lea    0xef9(%rip),%rax
divsd  (%rax,%rcx,8),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112a <taylor_tan+0x2a>
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<taylor_tan>:
test   %edi,%edi
je     11b4 <taylor_tan+0xb4>
add    $0xffffffff,%edi
cmp    $0xc,%edi
mov    $0xc,%ecx
cmovb  %edi,%ecx
lea    0x1(%rcx),%eax
test   %ecx,%ecx
je     11b8 <taylor_tan+0xb8>
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mov    %eax,%edx
and    $0x1e,%edx
xorpd  %xmm3,%xmm3
xor    %ecx,%ecx
lea    0xec5(%rip),%rsi
lea    0xf2e(%rip),%rdi
movapd %xmm0,%xmm4
cs nopw 0x0(%rax,%rax,1)
movapd %xmm2,%xmm1
mulsd  %xmm4,%xmm1
mulsd  (%rsi,%rcx,8),%xmm4
divsd  (%rdi,%rcx,8),%xmm4
movapd %xmm2,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0x8(%rsi,%rcx,8),%xmm1
divsd  0x8(%rdi,%rcx,8),%xmm1
addsd  %xmm3,%xmm4
addsd  %xmm4,%xmm1
add    $0x2,%rcx
movapd %xmm0,%xmm4
movapd %xmm1,%xmm3
cmp    %rcx,%rdx
jne    1150 <taylor_tan+0x50>
test   $0x1,%al
je     11af <taylor_tan+0xaf>
lea    0xe66(%rip),%rax
mulsd  (%rax,%rcx,8),%xmm0
lea    0xeca(%rip),%rax
divsd  (%rax,%rcx,8),%xmm0
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ret
xorps  %xmm0,%xmm0
ret
xorpd  %xmm1,%xmm1
xor    %ecx,%ecx
test   $0x1,%al
jne    1193 <taylor_tan+0x93>
jmp    11af <taylor_tan+0xaf>

LLVM IR (-O0):
@taylor_tan.numer = internal constant [13 x double] [double 1.000000e+00, double 1.000000e+00, double 2.000000e+00, double 1.700000e+01, double 6.200000e+01, double 1.382000e+03, double 2.184400e+04, double 9.295690e+05, double 0x41586E7980000000, double 0x41BA74C8AA000000, double 0x4211975C7A900000, double 0x423A869B91160000, double 0x42CAC572A3F94E00]
@taylor_tan.denom = internal constant [13 x double] [double 1.000000e+00, double 3.000000e+00, double 1.500000e+01, double 3.150000e+02, double 2.835000e+03, double 1.559250e+05, double 0x4157328CC0000000, double 0x41C3077775800000, double 0x420437EEECD80000, double 0x427B02B930689000, double 0x42E6283BE9B5C620, double 0x4365E5C335F8A4CE, double 0x43C9A940C33F6121]
define double @taylor_tan(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
%8 = load double, double* %3
%9 = load double, double* %3
%10 = fmul double %8, %9
store double %10, double* %6
store i32 0, i32* %7
br label %11
11: ; preds = %37, %2
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %7
%17 = icmp ult i32 %16, 13
br label %18
18: ; preds = %15, %11
%19 = phi i1 [ false, %11 ], [ %17, %15 ]
br i1 %19, label %20, label %40
20: ; preds = %18
%21 = load double, double* %3
%22 = load i32, i32* %7
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [13 x double], [13 x double]* @taylor_tan.numer, i64 0, i64 %23
%25 = load double, double* %24
%26 = fmul double %21, %25
%27 = load i32, i32* %7
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [13 x double], [13 x double]* @taylor_tan.denom, i64 0, i64 %28
%30 = load double, double* %29
%31 = fdiv double %26, %30
%32 = load double, double* %5
%33 = fadd double %32, %31
store double %33, double* %5
%34 = load double, double* %6
%35 = load double, double* %3
%36 = fmul double %35, %34
store double %36, double* %3
br label %37
37: ; preds = %20
%38 = load i32, i32* %7
%39 = add i32 %38, 1
store i32 %39, i32* %7
br label %11
40: ; preds = %18
%41 = load double, double* %5
ret double %41
}

LLVM IR (-O2):
@taylor_tan.numer = internal unnamed_addr constant [13 x double] [double 1.000000e+00, double 1.000000e+00, double 2.000000e+00, double 1.700000e+01, double 6.200000e+01, double 1.382000e+03, double 2.184400e+04, double 9.295690e+05, double 0x41586E7980000000, double 0x41BA74C8AA000000, double 0x4211975C7A900000, double 0x423A869B91160000, double 0x42CAC572A3F94E00]
@taylor_tan.denom = internal unnamed_addr constant [13 x double] [double 1.000000e+00, double 3.000000e+00, double 1.500000e+01, double 3.150000e+02, double 2.835000e+03, double 1.559250e+05, double 0x4157328CC0000000, double 0x41C3077775800000, double 0x420437EEECD80000, double 0x427B02B930689000, double 0x42E6283BE9B5C620, double 0x4365E5C335F8A4CE, double 0x43C9A940C33F6121]
define double @taylor_tan(double %0, i32 %1) {
%3 = fmul double %0, %0
%4 = icmp eq i32 %1, 0
br i1 %4, label %28, label %5
5: ; preds = %2
%6 = add i32 %1, -1
%7 = call i32 @llvm.umin.i32(i32 %6, i32 12)
%8 = add nuw nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = and i64 %9, 1
%11 = icmp eq i32 %7, 0
br i1 %11, label %14, label %12
12: ; preds = %5
%13 = and i64 %9, 30
br label %30
14: ; preds = %30, %5
%15 = phi double [ undef, %5 ], [ %50, %30 ]
%16 = phi i64 [ 0, %5 ], [ %52, %30 ]
%17 = phi double [ %0, %5 ], [ %51, %30 ]
%18 = phi double [ 0.000000e+00, %5 ], [ %50, %30 ]
%19 = icmp eq i64 %10, 0
br i1 %19, label %28, label %20
20: ; preds = %14
%21 = getelementptr inbounds [13 x double], [13 x double]* @taylor_tan.numer, i64 0, i64 %16
%22 = load double, double* %21
%23 = fmul double %17, %22
%24 = getelementptr inbounds [13 x double], [13 x double]* @taylor_tan.denom, i64 0, i64 %16
%25 = load double, double* %24
%26 = fdiv double %23, %25
%27 = fadd double %18, %26
br label %28
28: ; preds = %20, %14, %2
%29 = phi double [ 0.000000e+00, %2 ], [ %15, %14 ], [ %27, %20 ]
ret double %29
30: ; preds = %30, %12
%31 = phi i64 [ 0, %12 ], [ %52, %30 ]
%32 = phi double [ %0, %12 ], [ %51, %30 ]
%33 = phi double [ 0.000000e+00, %12 ], [ %50, %30 ]
%34 = phi i64 [ 0, %12 ], [ %53, %30 ]
%35 = getelementptr inbounds [13 x double], [13 x double]* @taylor_tan.numer, i64 0, i64 %31
%36 = load double, double* %35
%37 = fmul double %32, %36
%38 = getelementptr inbounds [13 x double], [13 x double]* @taylor_tan.denom, i64 0, i64 %31
%39 = load double, double* %38
%40 = fdiv double %37, %39
%41 = fadd double %33, %40
%42 = fmul double %3, %32
%43 = or i64 %31, 1
%44 = getelementptr inbounds [13 x double], [13 x double]* @taylor_tan.numer, i64 0, i64 %43
%45 = load double, double* %44
%46 = fmul double %42, %45
%47 = getelementptr inbounds [13 x double], [13 x double]* @taylor_tan.denom, i64 0, i64 %43
%48 = load double, double* %47
%49 = fdiv double %46, %48
%50 = fadd double %41, %49
%51 = fmul double %3, %42
%52 = add nuw nsw i64 %31, 2
%53 = add i64 %34, 2
%54 = icmp eq i64 %53, %13
br i1 %54, label %14, label %30
}