#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 M_PI;
double cos(double);
void chebyshev_coef(int ncheb, double (*func)(double), double x0, double x1,
                    double *a) {
  double y0 = 0.5 * (x1 - x0);
  double y1 = 0.5 * (x1 + x0);
  double twon = 2.0 / (double)ncheb;
  int j;
  for (j = 0; j < ncheb; j++) {
    double x = 0.0;
    int k;
    for (k = 1; k <= ncheb; k++) {
      double pikn = M_PI * ((double)k - 0.5) / (double)ncheb;
      double y = cos(pikn);
      double yy = y * y0 + y1;
      double z = cos((double)j * pikn);
      x += func(yy) * z;
    }
    a[j] = twon * x;
  }
  a[0] *= 0.5;
}


x86 assembly (clang, -O0):
<chebyshev_coef>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xec6(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
movsd  0xeab(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xe8d(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    126c <chebyshev_coef+0x15c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1247 <chebyshev_coef+0x137>
mov    0x2e37(%rip),%rax
movsd  (%rax),%xmm0
cvtsi2sdl -0x54(%rbp),%xmm1
movsd  0xe46(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1030 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
cvtsi2sdl -0x44(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
call   1030 <cos@plt>
movsd  %xmm0,-0x78(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x70(%rbp),%xmm0
call   *%rax
movsd  -0x78(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    119e <chebyshev_coef+0x8e>
movsd  -0x40(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1183 <chebyshev_coef+0x73>
mov    -0x28(%rbp),%rax
movsd  0xd90(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chebyshev_coef>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,0x8(%rsp)
test   %edi,%edi
jle    1269 <chebyshev_coef+0x159>
mov    %rsi,%r15
mov    %edi,%ebx
movapd %xmm1,%xmm3
movapd %xmm0,%xmm2
subsd  %xmm0,%xmm3
movsd  0xebc(%rip),%xmm0
mulsd  %xmm0,%xmm3
movsd  %xmm3,0x20(%rsp)
addsd  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x28(%rsp)
movsd  0xe9d(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %edi,%r12d
neg    %ebx
xor    %r13d,%r13d
mov    0x2e64(%rip),%rbp
movsd  0xe84(%rip),%xmm3
movsd  %xmm1,0x18(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm2,%xmm2
cvtsi2sd %r13d,%xmm2
movsd  %xmm2,0x30(%rsp)
mov    $0x1,%r14d
xorpd  %xmm2,%xmm2
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,0x40(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
addsd  %xmm3,%xmm0
mulsd  0x0(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1030 <cos@plt>
mulsd  0x20(%rsp),%xmm0
addsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
movsd  (%rsp),%xmm0
mulsd  0x30(%rsp),%xmm0
call   1030 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x38(%rsp),%xmm0
call   *%r15
movsd  0x40(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
mulsd  (%rsp),%xmm0
addsd  %xmm0,%xmm2
movsd  0xdde(%rip),%xmm3
lea    (%rbx,%r14,1),%eax
add    $0x1,%eax
mov    %r14d,%ecx
add    $0x1,%ecx
mov    %ecx,%r14d
cmp    $0x1,%eax
jne    11c0 <chebyshev_coef+0xb0>
mulsd  0x10(%rsp),%xmm2
mov    0x8(%rsp),%rax
movsd  %xmm2,(%rax,%r13,8)
add    $0x1,%r13
cmp    %r12,%r13
jne    11a0 <chebyshev_coef+0x90>
mov    0x8(%rsp),%rax
movsd  (%rax),%xmm0
mulsd  0xd86(%rip),%xmm0
movsd  %xmm0,(%rax)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define void @chebyshev_coef(i32 %0, double (double)* %1, double %2, double %3, double* %4) {
%6 = alloca i32
%7 = alloca double (double)*
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca double
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
store i32 %0, i32* %6
store double (double)* %1, double (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 i32, i32* %6
%30 = sitofp i32 %29 to double
%31 = fdiv double 2.000000e+00, %30
store double %31, double* %13
store i32 0, i32* %14
br label %32
32: ; preds = %78, %5
%33 = load i32, i32* %14
%34 = load i32, i32* %6
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %81
36: ; preds = %32
store double 0.000000e+00, double* %15
store i32 1, i32* %16
br label %37
37: ; preds = %67, %36
%38 = load i32, i32* %16
%39 = load i32, i32* %6
%40 = icmp sle i32 %38, %39
br i1 %40, label %41, label %70
41: ; preds = %37
%42 = load double, double* @M_PI
%43 = load i32, i32* %16
%44 = sitofp i32 %43 to double
%45 = fsub double %44, 5.000000e-01
%46 = fmul double %42, %45
%47 = load i32, i32* %6
%48 = sitofp i32 %47 to double
%49 = fdiv double %46, %48
store double %49, double* %17
%50 = load double, double* %17
%51 = call double @cos(double %50)
store double %51, double* %18
%52 = load double, double* %18
%53 = load double, double* %11
%54 = load double, double* %12
%55 = call double @llvm.fmuladd.f64(double %52, double %53, double %54)
store double %55, double* %19
%56 = load i32, i32* %14
%57 = sitofp i32 %56 to double
%58 = load double, double* %17
%59 = fmul double %57, %58
%60 = call double @cos(double %59)
store double %60, double* %20
%61 = load double (double)*, double (double)** %7
%62 = load double, double* %19
%63 = call double %61(double %62)
%64 = load double, double* %20
%65 = load double, double* %15
%66 = call double @llvm.fmuladd.f64(double %63, double %64, double %65)
store double %66, double* %15
br label %67
67: ; preds = %41
%68 = load i32, i32* %16
%69 = add nsw i32 %68, 1
store i32 %69, i32* %16
br label %37
70: ; preds = %37
%71 = load double, double* %13
%72 = load double, double* %15
%73 = fmul double %71, %72
%74 = load double*, double** %10
%75 = load i32, i32* %14
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
store double %73, double* %77
br label %78
78: ; preds = %70
%79 = load i32, i32* %14
%80 = add nsw i32 %79, 1
store i32 %80, i32* %14
br label %32
81: ; preds = %32
%82 = load double*, double** %10
%83 = getelementptr inbounds double, double* %82, i64 0
%84 = load double, double* %83
%85 = fmul double %84, 5.000000e-01
store double %85, double* %83
ret void
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define void @chebyshev_coef(i32 %0, double (double)* nocapture %1, double %2, double %3, double* nocapture %4) {
%6 = fsub double %3, %2
%7 = fmul double %6, 5.000000e-01
%8 = fadd double %2, %3
%9 = fmul double %8, 5.000000e-01
%10 = sitofp i32 %0 to double
%11 = fdiv double 2.000000e+00, %10
%12 = icmp sgt i32 %0, 0
br i1 %12, label %13, label %40
13: ; preds = %5
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %35, %13
%16 = phi i64 [ 0, %13 ], [ %38, %35 ]
%17 = trunc i64 %16 to i32
%18 = sitofp i32 %17 to double
br label %19
19: ; preds = %15, %19
%20 = phi double [ 0.000000e+00, %15 ], [ %32, %19 ]
%21 = phi i32 [ 1, %15 ], [ %33, %19 ]
%22 = load double, double* @M_PI
%23 = sitofp i32 %21 to double
%24 = fadd double %23, -5.000000e-01
%25 = fmul double %24, %22
%26 = fdiv double %25, %10
%27 = tail call double @cos(double %26)
%28 = tail call double @llvm.fmuladd.f64(double %27, double %7, double %9)
%29 = fmul double %26, %18
%30 = tail call double @cos(double %29)
%31 = tail call double %1(double %28)
%32 = tail call double @llvm.fmuladd.f64(double %31, double %30, double %20)
%33 = add nuw i32 %21, 1
%34 = icmp eq i32 %21, %0
br i1 %34, label %35, label %19
35: ; preds = %19
%36 = fmul double %11, %32
%37 = getelementptr inbounds double, double* %4, i64 %16
store double %36, double* %37
%38 = add nuw nsw i64 %16, 1
%39 = icmp eq i64 %38, %14
br i1 %39, label %40, label %15
40: ; preds = %35, %5
%41 = load double, double* %4
%42 = fmul double %41, 5.000000e-01
store double %42, double* %4
ret void
}