double chebyshev_eval(int ncheb, const double *a, double x0, double x1,
                      double x) {
  double y0 = 0.5 * (x1 - x0);
  double y1 = 0.5 * (x1 + x0);
  double y = (x - y1) / y0;
  double b[3];
  b[0] = 0.0;
  b[1] = 0.0;
  b[2] = 0.0;
  int i, j;
  int i2, i1, i0;
  for (i = 0; i < ncheb - 1; i++) {
    i2 = (i + 2) % 3;
    i1 = (i + 1) % 3;
    i0 = (i) % 3;
    j = ncheb - 1 - i;
    b[i2] = 2 * y * b[i1] - b[i0] + a[j];
  }
  i = ncheb - 1;
  i1 = (i + 1) % 3;
  i0 = (i) % 3;
  j = 0;
  double f = y * b[i1] - b[i0] + a[j];
  return (f);
}


x86 assembly (clang, -O0):
<chebyshev_eval>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xed4(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
movsd  0xeb9(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1235 <chebyshev_eval+0x135>
mov    -0x64(%rbp),%eax
add    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x6c(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x70(%rbp)
mov    -0x64(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x74(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
sub    -0x64(%rbp),%eax
mov    %eax,-0x68(%rbp)
movsd  0xe30(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movslq -0x70(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm2
movslq -0x74(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movslq -0x6c(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1183 <chebyshev_eval+0x83>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x70(%rbp)
mov    -0x64(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x74(%rbp)
movl   $0x0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
movslq -0x70(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm2
movslq -0x74(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<chebyshev_eval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
movapd %xmm1,%xmm3
subsd  %xmm0,%xmm3
movsd  0xee6(%rip),%xmm4
mulsd  %xmm4,%xmm3
addsd  %xmm1,%xmm0
mulsd  %xmm4,%xmm0
subsd  %xmm0,%xmm2
divsd  %xmm3,%xmm2
lea    -0x1(%rdi),%r10d
xorpd  %xmm0,%xmm0
movapd %xmm0,-0x18(%rsp)
movq   $0x0,-0x8(%rsp)
cmp    $0x2,%edi
jl     11fa <chebyshev_eval+0xfa>
movapd %xmm2,%xmm0
addsd  %xmm2,%xmm0
mov    %r10d,%r11d
lea    -0x8(%rsp),%r14
lea    -0x10(%rsp),%r15
mov    $0x2,%r8d
lea    -0x18(%rsp),%r13
mov    $0x1,%r9d
xor    %ecx,%ecx
movabs $0xaaaaaaaaaaaaaaab,%r12
aa aa aa
mov    %r8,%rax
mul    %r12
shl    $0x2,%rdx
and    $0xfffffffffffffff8,%rdx
lea    (%rdx,%rdx,2),%rbx
neg    %rbx
mov    %rcx,%rax
mul    %r12
shl    $0x2,%rdx
and    $0xfffffffffffffff8,%rdx
lea    (%rdx,%rdx,2),%rbp
neg    %rbp
mov    %r9,%rax
mul    %r12
shl    $0x2,%rdx
and    $0xfffffffffffffff8,%rdx
lea    (%rdx,%rdx,2),%rax
neg    %rax
movsd  (%r15,%rax,1),%xmm1
mulsd  %xmm0,%xmm1
subsd  0x0(%r13,%rbp,1),%xmm1
addsd  (%rsi,%r11,8),%xmm1
add    $0x1,%rcx
movsd  %xmm1,(%r14,%rbx,1)
add    $0x8,%r14
add    $0x1,%r8
add    $0x8,%r13
add    $0x8,%r15
add    $0x1,%r9
add    $0xffffffffffffffff,%r11
jne    1180 <chebyshev_eval+0x80>
movslq %edi,%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%edi
movslq %r10d,%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%r10d
movslq %edi,%rax
movslq %r10d,%rcx
mulsd  -0x18(%rsp,%rax,8),%xmm2
subsd  -0x18(%rsp,%rcx,8),%xmm2
addsd  (%rsi),%xmm2
movapd %xmm2,%xmm0
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @chebyshev_eval(i32 %0, double* %1, double %2, double %3, double %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca [3 x double]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
store i32 %0, i32* %6
store double* %1, double** %7
store double %2, double* %8
store double %3, double* %9
store double %4, double* %10
%21 = load double, double* %9
%22 = load double, double* %8
%23 = fsub double %21, %22
%24 = fmul double 5.000000e-01, %23
store double %24, double* %11
%25 = load double, double* %9
%26 = load double, double* %8
%27 = fadd double %25, %26
%28 = fmul double 5.000000e-01, %27
store double %28, double* %12
%29 = load double, double* %10
%30 = load double, double* %12
%31 = fsub double %29, %30
%32 = load double, double* %11
%33 = fdiv double %31, %32
store double %33, double* %13
%34 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 0
store double 0.000000e+00, double* %34
%35 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 1
store double 0.000000e+00, double* %35
%36 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 2
store double 0.000000e+00, double* %36
store i32 0, i32* %15
br label %37
37: ; preds = %76, %5
%38 = load i32, i32* %15
%39 = load i32, i32* %6
%40 = sub nsw i32 %39, 1
%41 = icmp slt i32 %38, %40
br i1 %41, label %42, label %79
42: ; preds = %37
%43 = load i32, i32* %15
%44 = add nsw i32 %43, 2
%45 = srem i32 %44, 3
store i32 %45, i32* %17
%46 = load i32, i32* %15
%47 = add nsw i32 %46, 1
%48 = srem i32 %47, 3
store i32 %48, i32* %18
%49 = load i32, i32* %15
%50 = srem i32 %49, 3
store i32 %50, i32* %19
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 1
%53 = load i32, i32* %15
%54 = sub nsw i32 %52, %53
store i32 %54, i32* %16
%55 = load double, double* %13
%56 = fmul double 2.000000e+00, %55
%57 = load i32, i32* %18
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 %58
%60 = load double, double* %59
%61 = load i32, i32* %19
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 %62
%64 = load double, double* %63
%65 = fneg double %64
%66 = call double @llvm.fmuladd.f64(double %56, double %60, double %65)
%67 = load double*, double** %7
%68 = load i32, i32* %16
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = load double, double* %70
%72 = fadd double %66, %71
%73 = load i32, i32* %17
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 %74
store double %72, double* %75
br label %76
76: ; preds = %42
%77 = load i32, i32* %15
%78 = add nsw i32 %77, 1
store i32 %78, i32* %15
br label %37
79: ; preds = %37
%80 = load i32, i32* %6
%81 = sub nsw i32 %80, 1
store i32 %81, i32* %15
%82 = load i32, i32* %15
%83 = add nsw i32 %82, 1
%84 = srem i32 %83, 3
store i32 %84, i32* %18
%85 = load i32, i32* %15
%86 = srem i32 %85, 3
store i32 %86, i32* %19
store i32 0, i32* %16
%87 = load double, double* %13
%88 = load i32, i32* %18
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 %89
%91 = load double, double* %90
%92 = load i32, i32* %19
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 %93
%95 = load double, double* %94
%96 = fneg double %95
%97 = call double @llvm.fmuladd.f64(double %87, double %91, double %96)
%98 = load double*, double** %7
%99 = load i32, i32* %16
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds double, double* %98, i64 %100
%102 = load double, double* %101
%103 = fadd double %97, %102
store double %103, double* %20
%104 = load double, double* %20
ret double %104
}

LLVM IR (-O2):
define double @chebyshev_eval(i32 %0, double* nocapture %1, double %2, double %3, double %4) {
%6 = alloca [3 x double]
%7 = fsub double %3, %2
%8 = fmul double %7, 5.000000e-01
%9 = fadd double %2, %3
%10 = fmul double %9, 5.000000e-01
%11 = fsub double %4, %10
%12 = fdiv double %11, %8
%13 = bitcast [3 x double]* %6 to i8*
%14 = add i32 %0, -1
%15 = icmp sgt i32 %0, 1
%16 = bitcast [3 x double]* %6 to i8*
br i1 %15, label %17, label %46
17: ; preds = %5
%18 = fmul double %12, 2.000000e+00
%19 = zext i32 %14 to i64
%20 = zext i32 %14 to i64
br label %21
21: ; preds = %17, %21
%22 = phi i64 [ 0, %17 ], [ %26, %21 ]
%23 = trunc i64 %22 to i32
%24 = add i32 %23, 2
%25 = urem i32 %24, 3
%26 = add nuw nsw i64 %22, 1
%27 = trunc i64 %26 to i32
%28 = urem i32 %27, 3
%29 = trunc i64 %22 to i32
%30 = urem i32 %29, 3
%31 = sub nsw i64 %19, %22
%32 = zext i32 %28 to i64
%33 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 %32
%34 = load double, double* %33
%35 = zext i32 %30 to i64
%36 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 %35
%37 = load double, double* %36
%38 = fneg double %37
%39 = tail call double @llvm.fmuladd.f64(double %18, double %34, double %38)
%40 = getelementptr inbounds double, double* %1, i64 %31
%41 = load double, double* %40
%42 = fadd double %39, %41
%43 = zext i32 %25 to i64
%44 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 %43
store double %42, double* %44
%45 = icmp eq i64 %26, %20
br i1 %45, label %46, label %21
46: ; preds = %21, %5
%47 = srem i32 %0, 3
%48 = srem i32 %14, 3
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 %49
%51 = load double, double* %50
%52 = sext i32 %48 to i64
%53 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 %52
%54 = load double, double* %53
%55 = fneg double %54
%56 = tail call double @llvm.fmuladd.f64(double %12, double %51, double %55)
%57 = load double, double* %1
%58 = fadd double %56, %57
ret double %58
}