float cheb(float x, int st) {
  int chebdat[12][7] = {{1, 0, 0, 0, 0, 0, 0},
                        {2, -1, 0, 0, 0, 0, 0},
                        {4, -3, 0, 0, 0, 0, 0},
                        {8, -8, 1, 0, 0, 0, 0},
                        {16, -20, 5, 0, 0, 0, 0},
                        {32, -48, 18, -1, 0, 0, 0},
                        {64, -112, 56, -7, 0, 0, 0},
                        {128, -256, 160, -32, 1, 0, 0},
                        {256, -576, 432, -120, 9, 0, 0},
                        {512, -1280, 1120, -400, 50, -1, 0},
                        {1024, -2816, 2816, -1232, 220, -11, 0},
                        {2048, -6144, 6912, -3584, 840, -72, 1}};
  float xst, sum;
  int nst, n;
  x = (2 * x - 3.14) / 3.14;
  if (st == 0)
    return 1;
  sum = 0;
  nst = st % 2;
  if (nst == 0)
    xst = 1;
  else
    xst = x;
  n = (st + 2) / 2;
  while (nst <= st) {
    sum = sum + chebdat[st - 1][n - 1] * xst;
    nst += 2;
    xst = xst * x * x;
    n--;
  }
  return sum;
}


x86 assembly (clang, -O0):
<cheb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
lea    -0x160(%rbp),%rdi
lea    0xedf(%rip),%rsi
mov    $0x150,%edx
call   1030 <memcpy@plt>
movss  0xec5(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeac(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xea0(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1189 <cheb+0x79>
movss  0xe8d(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1289 <cheb+0x179>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x168(%rbp)
ff
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x16c(%rbp)
cmpl   $0x0,-0x16c(%rbp)
jne    11c7 <cheb+0xb7>
movss  0xe52(%rip),%xmm0
movss  %xmm0,-0x164(%rbp)
ff
jmp    11d4 <cheb+0xc4>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x164(%rbp)
ff
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x170(%rbp)
mov    -0x16c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     127c <cheb+0x16c>
movss  -0x168(%rbp),%xmm1
ff
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    -0x160(%rbp),%rax
imul   $0x1c,%rcx,%rcx
add    %rcx,%rax
mov    -0x170(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
movss  -0x164(%rbp),%xmm2
ff
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x168(%rbp)
ff
mov    -0x16c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x16c(%rbp)
movss  -0x164(%rbp),%xmm0
ff
mulss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x164(%rbp)
ff
mov    -0x170(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x170(%rbp)
jmp    11e8 <cheb+0xd8>
movss  -0x168(%rbp),%xmm0
ff
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cheb>:
test   %edi,%edi
je     1158 <cheb+0x58>
movaps %xmm0,%xmm1
mov    %edi,%ecx
shr    $0x1f,%ecx
add    %edi,%ecx
and    $0xfffffffe,%ecx
mov    %edi,%eax
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cmp    %edi,%eax
jg     11c2 <cheb+0xc2>
addss  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
addsd  0xecd(%rip),%xmm0
divsd  0xecd(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
lea    0x2(%rdi),%ecx
shr    $0x1f,%ecx
add    %edi,%ecx
add    $0x2,%ecx
sar    %ecx
test   %eax,%eax
je     1161 <cheb+0x61>
movaps %xmm1,%xmm2
jmp    1169 <cheb+0x69>
movss  0xeb0(%rip),%xmm0
ret
movss  0xea7(%rip),%xmm2
movslq %edi,%rdx
movslq %ecx,%rcx
lea    (%rdx,%rdx,8),%rsi
add    $0xfffffffffffffff7,%rsi
lea    (%rsi,%rsi,2),%rsi
add    %rsi,%rdx
add    $0xffffffffffffffff,%rdx
lea    0xe97(%rip),%rsi
add    %rdx,%rsi
lea    (%rsi,%rcx,4),%rcx
add    $0xfffffffffffffffc,%rcx
xorps  %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
xorps  %xmm3,%xmm3
cvtsi2ssl (%rcx),%xmm3
mulss  %xmm2,%xmm3
addss  %xmm3,%xmm0
add    $0x2,%eax
mulss  %xmm1,%xmm2
mulss  %xmm1,%xmm2
add    $0xfffffffffffffffc,%rcx
cmp    %edi,%eax
jle    11a0 <cheb+0xa0>
ret

LLVM IR (-O0):
@__const.cheb.chebdat = [12 x [7 x i32]] [[7 x i32] [i32 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 2, i32 -1, i32 0, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 4, i32 -3, i32 0, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 8, i32 -8, i32 1, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 16, i32 -20, i32 5, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 32, i32 -48, i32 18, i32 -1, i32 0, i32 0, i32 0], [7 x i32] [i32 64, i32 -112, i32 56, i32 -7, i32 0, i32 0, i32 0], [7 x i32] [i32 128, i32 -256, i32 160, i32 -32, i32 1, i32 0, i32 0], [7 x i32] [i32 256, i32 -576, i32 432, i32 -120, i32 9, i32 0, i32 0], [7 x i32] [i32 512, i32 -1280, i32 1120, i32 -400, i32 50, i32 -1, i32 0], [7 x i32] [i32 1024, i32 -2816, i32 2816, i32 -1232, i32 220, i32 -11, i32 0], [7 x i32] [i32 2048, i32 -6144, i32 6912, i32 -3584, i32 840, i32 -72, i32 1]]
define float @cheb(float %0, i32 %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca [12 x [7 x i32]]
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
store float %0, float* %4
store i32 %1, i32* %5
%11 = bitcast [12 x [7 x i32]]* %6 to i8*
%12 = load float, float* %4
%13 = fmul float 2.000000e+00, %12
%14 = fpext float %13 to double
%15 = fsub double %14, 3.140000e+00
%16 = fdiv double %15, 3.140000e+00
%17 = fptrunc double %16 to float
store float %17, float* %4
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %2
store float 1.000000e+00, float* %3
br label %62
21: ; preds = %2
store float 0.000000e+00, float* %8
%22 = load i32, i32* %5
%23 = srem i32 %22, 2
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store float 1.000000e+00, float* %7
br label %29
27: ; preds = %21
%28 = load float, float* %4
store float %28, float* %7
br label %29
29: ; preds = %27, %26
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 2
%32 = sdiv i32 %31, 2
store i32 %32, i32* %10
br label %33
33: ; preds = %37, %29
%34 = load i32, i32* %9
%35 = load i32, i32* %5
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %60
37: ; preds = %33
%38 = load float, float* %8
%39 = load i32, i32* %5
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [12 x [7 x i32]], [12 x [7 x i32]]* %6, i64 0, i64 %41
%43 = load i32, i32* %10
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [7 x i32], [7 x i32]* %42, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = sitofp i32 %47 to float
%49 = load float, float* %7
%50 = call float @llvm.fmuladd.f32(float %48, float %49, float %38)
store float %50, float* %8
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 2
store i32 %52, i32* %9
%53 = load float, float* %7
%54 = load float, float* %4
%55 = fmul float %53, %54
%56 = load float, float* %4
%57 = fmul float %55, %56
store float %57, float* %7
%58 = load i32, i32* %10
%59 = add nsw i32 %58, -1
store i32 %59, i32* %10
br label %33
60: ; preds = %33
%61 = load float, float* %8
store float %61, float* %3
br label %62
62: ; preds = %60, %20
%63 = load float, float* %3
ret float %63
}

LLVM IR (-O2):
@__const.cheb.chebdat = [12 x [7 x i32]] [[7 x i32] [i32 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 2, i32 -1, i32 0, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 4, i32 -3, i32 0, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 8, i32 -8, i32 1, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 16, i32 -20, i32 5, i32 0, i32 0, i32 0, i32 0], [7 x i32] [i32 32, i32 -48, i32 18, i32 -1, i32 0, i32 0, i32 0], [7 x i32] [i32 64, i32 -112, i32 56, i32 -7, i32 0, i32 0, i32 0], [7 x i32] [i32 128, i32 -256, i32 160, i32 -32, i32 1, i32 0, i32 0], [7 x i32] [i32 256, i32 -576, i32 432, i32 -120, i32 9, i32 0, i32 0], [7 x i32] [i32 512, i32 -1280, i32 1120, i32 -400, i32 50, i32 -1, i32 0], [7 x i32] [i32 1024, i32 -2816, i32 2816, i32 -1232, i32 220, i32 -11, i32 0], [7 x i32] [i32 2048, i32 -6144, i32 6912, i32 -3584, i32 840, i32 -72, i32 1]]
define float @cheb(float %0, i32 %1) {
%3 = fmul float %0, 2.000000e+00
%4 = fpext float %3 to double
%5 = fadd double %4, -3.140000e+00
%6 = fdiv double %5, 3.140000e+00
%7 = fptrunc double %6 to float
%8 = icmp eq i32 %1, 0
br i1 %8, label %34, label %9
9: ; preds = %2
%10 = srem i32 %1, 2
%11 = icmp sgt i32 %10, %1
br i1 %11, label %34, label %12
12: ; preds = %9
%13 = add nsw i32 %1, 2
%14 = sdiv i32 %13, 2
%15 = icmp eq i32 %10, 0
%16 = select i1 %15, float 1.000000e+00, float %7
%17 = add nsw i32 %1, -1
%18 = sext i32 %17 to i64
%19 = sext i32 %14 to i64
br label %20
20: ; preds = %12, %20
%21 = phi i64 [ %19, %12 ], [ %25, %20 ]
%22 = phi i32 [ %10, %12 ], [ %30, %20 ]
%23 = phi float [ 0.000000e+00, %12 ], [ %29, %20 ]
%24 = phi float [ %16, %12 ], [ %32, %20 ]
%25 = add nsw i64 %21, -1
%26 = getelementptr inbounds [12 x [7 x i32]], [12 x [7 x i32]]* @__const.cheb.chebdat, i64 0, i64 %18, i64 %25
%27 = load i32, i32* %26
%28 = sitofp i32 %27 to float
%29 = tail call float @llvm.fmuladd.f32(float %28, float %24, float %23)
%30 = add nsw i32 %22, 2
%31 = fmul float %24, %7
%32 = fmul float %31, %7
%33 = icmp sgt i32 %30, %1
br i1 %33, label %34, label %20
34: ; preds = %20, %9, %2
%35 = phi float [ 1.000000e+00, %2 ], [ 0.000000e+00, %9 ], [ %29, %20 ]
ret float %35
}