#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 *calloc(int, int);
double chebyshev_node(int, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ polynomial_fit_on_points_by_dct(double *, int, double,
                                                   double, double *, int);
void polynomial_fit_on_function_by_dct(double (*f)(double), double start,
                                       double end, double *c, int degree) {
  int i, p_count = 1000;
  double *y = calloc(p_count, sizeof(double));
  for (i = 0; i < p_count; i++)
    y[i] = f((end - start) * (0.5 + 0.5 * chebyshev_node(p_count, i)) + start);
  polynomial_fit_on_points_by_dct(y, p_count, start, end, c, degree);
  free(y);
}


x86 assembly (clang, -O0):
<polynomial_fit_on_function_by_dct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
movl   $0x3e8,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11f0 <polynomial_fit_on_function_by_dct+0xb0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <chebyshev_node@plt>
mov    -0x48(%rbp),%rax
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  0xe42(%rip),%xmm1
mulsd  %xmm1,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
mov    -0x38(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117c <polynomial_fit_on_function_by_dct+0x3c>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1050 <polynomial_fit_on_points_by_dct@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polynomial_fit_on_function_by_dct>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%r12
mov    $0x3e8,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x3e8,%edi
mov    %ebx,%esi
call   1040 <chebyshev_node@plt>
movsd  0xe5c(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0x18(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
call   *%r12
movsd  %xmm0,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1190 <polynomial_fit_on_function_by_dct+0x50>
mov    %rbp,%rdi
mov    $0x3e8,%esi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %r15,%rdx
mov    %r14d,%ecx
call   1050 <polynomial_fit_on_points_by_dct@plt>
mov    %rbp,%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @polynomial_fit_on_function_by_dct(double (double)* %0, double %1, double %2, double* %3, i32 %4) {
%6 = alloca double (double)*
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
store double (double)* %0, double (double)** %6
store double %1, double* %7
store double %2, double* %8
store double* %3, double** %9
store i32 %4, i32* %10
store i32 1000, i32* %12
%14 = load i32, i32* %12
%15 = call double* @calloc(i32 %14, i32 8)
store double* %15, double** %13
store i32 0, i32* %11
br label %16
16: ; preds = %36, %5
%17 = load i32, i32* %11
%18 = load i32, i32* %12
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %39
20: ; preds = %16
%21 = load double (double)*, double (double)** %6
%22 = load double, double* %8
%23 = load double, double* %7
%24 = fsub double %22, %23
%25 = load i32, i32* %12
%26 = load i32, i32* %11
%27 = call double @chebyshev_node(i32 %25, i32 %26)
%28 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %27, double 5.000000e-01)
%29 = load double, double* %7
%30 = call double @llvm.fmuladd.f64(double %24, double %28, double %29)
%31 = call double %21(double %30)
%32 = load double*, double** %13
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
store double %31, double* %35
br label %36
36: ; preds = %20
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %16
39: ; preds = %16
%40 = load double*, double** %13
%41 = load i32, i32* %12
%42 = load double, double* %7
%43 = load double, double* %8
%44 = load double*, double** %9
%45 = load i32, i32* %10
%46 = call i32 @polynomial_fit_on_points_by_dct(double* %40, i32 %41, double %42, double %43, double* %44, i32 %45)
%47 = load double*, double** %13
%48 = call i32 @free(double* %47)
ret void
}

LLVM IR (-O2):
define void @polynomial_fit_on_function_by_dct(double (double)* nocapture %0, double %1, double %2, double* %3, i32 %4) {
%6 = tail call double* @calloc(i32 1000, i32 8)
%7 = fsub double %2, %1
br label %8
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %16, %8 ]
%10 = trunc i64 %9 to i32
%11 = tail call double @chebyshev_node(i32 1000, i32 %10)
%12 = tail call double @llvm.fmuladd.f64(double %11, double 5.000000e-01, double 5.000000e-01)
%13 = tail call double @llvm.fmuladd.f64(double %7, double %12, double %1)
%14 = tail call double %0(double %13)
%15 = getelementptr inbounds double, double* %6, i64 %9
store double %14, double* %15
%16 = add nuw nsw i64 %9, 1
%17 = icmp eq i64 %16, 1000
br i1 %17, label %18, label %8
18: ; preds = %8
%19 = tail call i32 @polynomial_fit_on_points_by_dct(double* %6, i32 1000, double %1, double %2, double* %3, i32 %4)
%20 = tail call i32 @free(double* %6)
ret void
}