#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 cos(double);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
double func(double, double);
int /*<<< orphan*/ stdout;
void chebyshev_polynomial(double aa, double bb, double c[], int n,
                          double exponent) {
  int k, j;
  double fac, bpa, bma, *f;
  double inv_n;
  inv_n = 1. / (double)n;
  f = calloc(n, sizeof(double));
  fflush(stdout);
  bma = 0.5 * (bb - aa);
  bpa = 0.5 * (bb + aa);
  for (k = 0; k < n; k++) {
    double y = cos(3.141592653589793 * (k + 0.5) * inv_n);
    f[k] = func(y * bma + bpa, exponent);
  }
  fac = 2.0 * inv_n;
  for (j = 0; j < n; j++) {
    double sum = 0.0;
    for (k = 0; k < n; k++)
      sum += f[k] * cos(3.141592653589793 * j * (k + 0.5) * inv_n);
    c[j] = fac * sum;
  }
  free(f);
}


x86 assembly (clang, -O0):
<chebyshev_polynomial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movsd  %xmm2,-0x28(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xe8d(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
movsd  0xe4b(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm1
addsd  -0x8(%rbp),%xmm1
movsd  0xe30(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1254 <chebyshev_polynomial+0x104>
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xe07(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe13(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x58(%rbp),%xmm0
call   1070 <cos@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
call   1050 <func@plt>
mov    -0x50(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e0 <chebyshev_polynomial+0x90>
movsd  0xdb4(%rip),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1323 <chebyshev_polynomial+0x1d3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12fe <chebyshev_polynomial+0x1ae>
mov    -0x50(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
cvtsi2sdl -0x30(%rbp),%xmm1
movsd  0xd65(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xd3c(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mulsd  -0x58(%rbp),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1288 <chebyshev_polynomial+0x138>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    126d <chebyshev_polynomial+0x11d>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chebyshev_polynomial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm2,0x18(%rsp)
mov    %esi,%r15d
mov    %rdi,%r14
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,(%rsp)
mov    %esi,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
test   %r15d,%r15d
jle    13b7 <chebyshev_polynomial+0x267>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  0xe55(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x20(%rsp),%xmm3
movapd %xmm3,%xmm2
movsd  (%rsp),%xmm0
subsd  %xmm0,%xmm2
movsd  0xe38(%rip),%xmm1
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
addsd  %xmm3,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mov    %r15d,%r12d
xor    %ebp,%ebp
movsd  0xe1c(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
mulsd  0x10(%rsp),%xmm0
call   1070 <cos@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
call   1050 <func@plt>
movsd  0xdd8(%rip),%xmm2
movsd  0xdc8(%rip),%xmm1
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1200 <chebyshev_polynomial+0xb0>
test   %r15d,%r15d
movsd  0x10(%rsp),%xmm0
jle    13b7 <chebyshev_polynomial+0x267>
movapd %xmm0,%xmm3
addsd  %xmm0,%xmm3
movsd  %xmm3,0x20(%rsp)
mov    %r12d,%r13d
and    $0xfffffffe,%r13d
xor    %r15d,%r15d
jmp    1299 <chebyshev_polynomial+0x149>
nopw   0x0(%rax,%rax,1)
mulsd  0x20(%rsp),%xmm4
movsd  %xmm4,(%r14,%r15,8)
add    $0x1,%r15
cmp    %r12,%r15
je     13b7 <chebyshev_polynomial+0x267>
xorps  %xmm3,%xmm3
cvtsi2sd %r15d,%xmm3
mulsd  %xmm2,%xmm3
xorpd  %xmm4,%xmm4
xor    %ebp,%ebp
cmp    $0x1,%r12d
je     135b <chebyshev_polynomial+0x20b>
movsd  %xmm3,0x18(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm4,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  (%rbx,%rbp,8),%xmm2
movsd  %xmm2,0x8(%rsp)
addsd  %xmm1,%xmm0
mulsd  %xmm3,%xmm0
mulsd  0x10(%rsp),%xmm0
call   1070 <cos@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    0x1(%rbp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rbx,%rbp,8),%xmm1
movsd  %xmm1,0x8(%rsp)
addsd  0xcf0(%rip),%xmm0
mulsd  0x18(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1070 <cos@plt>
movsd  0x18(%rsp),%xmm3
movsd  0xcd1(%rip),%xmm1
movapd %xmm0,%xmm4
mulsd  0x8(%rsp),%xmm4
addsd  (%rsp),%xmm4
add    $0x2,%rbp
cmp    %r13,%rbp
jne    12c0 <chebyshev_polynomial+0x170>
movsd  0xcb5(%rip),%xmm2
test   $0x1,%r12b
je     1280 <chebyshev_polynomial+0x130>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  (%rbx,%rbp,8),%xmm2
movsd  %xmm2,0x8(%rsp)
addsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm3
mulsd  0x10(%rsp),%xmm3
movapd %xmm3,%xmm0
movsd  %xmm4,(%rsp)
call   1070 <cos@plt>
movsd  (%rsp),%xmm4
movsd  0xc70(%rip),%xmm2
movsd  0xc60(%rip),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm4
jmp    1280 <chebyshev_polynomial+0x130>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@stdout = global i32 0
define void @chebyshev_polynomial(double %0, double %1, double* nocapture writeonly %2, i32 %3, double %4) {
%6 = sitofp i32 %3 to double
%7 = fdiv double 1.000000e+00, %6
%8 = tail call double* @calloc(i32 %3, i32 8)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
%11 = fsub double %1, %0
%12 = fmul double %11, 5.000000e-01
%13 = fadd double %0, %1
%14 = fmul double %13, 5.000000e-01
%15 = icmp sgt i32 %3, 0
br i1 %15, label %16, label %90
16: ; preds = %5
%17 = zext i32 %3 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %29, %18 ]
%20 = trunc i64 %19 to i32
%21 = sitofp i32 %20 to double
%22 = fadd double %21, 5.000000e-01
%23 = fmul double %22, 0x400921FB54442D18
%24 = fmul double %7, %23
%25 = tail call double @cos(double %24)
%26 = tail call double @llvm.fmuladd.f64(double %25, double %12, double %14)
%27 = tail call double @func(double %26, double %4)
%28 = getelementptr inbounds double, double* %8, i64 %19
store double %27, double* %28
%29 = add nuw nsw i64 %19, 1
%30 = icmp eq i64 %29, %17
br i1 %30, label %31, label %18
31: ; preds = %18
%32 = fmul double %7, 2.000000e+00
br i1 %15, label %33, label %90
33: ; preds = %31
%34 = zext i32 %3 to i64
%35 = and i64 %17, 1
%36 = icmp eq i32 %3, 1
%37 = and i64 %17, 4294967294
%38 = icmp eq i64 %35, 0
br label %39
39: ; preds = %84, %33
%40 = phi i64 [ 0, %33 ], [ %88, %84 ]
%41 = trunc i64 %40 to i32
%42 = sitofp i32 %41 to double
%43 = fmul double %42, 0x400921FB54442D18
br i1 %36, label %70, label %44
44: ; preds = %39, %44
%45 = phi i64 [ %67, %44 ], [ 0, %39 ]
%46 = phi double [ %66, %44 ], [ 0.000000e+00, %39 ]
%47 = phi i64 [ %68, %44 ], [ 0, %39 ]
%48 = getelementptr inbounds double, double* %8, i64 %45
%49 = load double, double* %48
%50 = trunc i64 %45 to i32
%51 = sitofp i32 %50 to double
%52 = fadd double %51, 5.000000e-01
%53 = fmul double %43, %52
%54 = fmul double %7, %53
%55 = tail call double @cos(double %54)
%56 = tail call double @llvm.fmuladd.f64(double %49, double %55, double %46)
%57 = or i64 %45, 1
%58 = getelementptr inbounds double, double* %8, i64 %57
%59 = load double, double* %58
%60 = trunc i64 %57 to i32
%61 = sitofp i32 %60 to double
%62 = fadd double %61, 5.000000e-01
%63 = fmul double %43, %62
%64 = fmul double %7, %63
%65 = tail call double @cos(double %64)
%66 = tail call double @llvm.fmuladd.f64(double %59, double %65, double %56)
%67 = add nuw nsw i64 %45, 2
%68 = add i64 %47, 2
%69 = icmp eq i64 %68, %37
br i1 %69, label %70, label %44
70: ; preds = %44, %39
%71 = phi double [ undef, %39 ], [ %66, %44 ]
%72 = phi i64 [ 0, %39 ], [ %67, %44 ]
%73 = phi double [ 0.000000e+00, %39 ], [ %66, %44 ]
br i1 %38, label %84, label %74
74: ; preds = %70
%75 = getelementptr inbounds double, double* %8, i64 %72
%76 = load double, double* %75
%77 = trunc i64 %72 to i32
%78 = sitofp i32 %77 to double
%79 = fadd double %78, 5.000000e-01
%80 = fmul double %43, %79
%81 = fmul double %7, %80
%82 = tail call double @cos(double %81)
%83 = tail call double @llvm.fmuladd.f64(double %76, double %82, double %73)
br label %84
84: ; preds = %70, %74
%85 = phi double [ %71, %70 ], [ %83, %74 ]
%86 = fmul double %32, %85
%87 = getelementptr inbounds double, double* %2, i64 %40
store double %86, double* %87
%88 = add nuw nsw i64 %40, 1
%89 = icmp eq i64 %88, %34
br i1 %89, label %90, label %39
90: ; preds = %84, %5, %31
%91 = tail call i32 @free(double* %8)
ret void
}