#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);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ memset(double *, int /*<<< orphan*/, int);
int /*<<< orphan*/ polynomial_multiplication(double *, int, double *, int,
                                             double *, int);
int /*<<< orphan*/ polynomial_subtraction(double *, int, double *, int,
                                          double *);
double *chebyshev_coefs(int degree) {
  int i;
  double *t0, *t1, *t2, *p;
  double m[2] = {0., 2.};
  t0 = calloc(degree + 1, sizeof(double));
  t0[0] = 1.;
  if (degree == 0)
    return t0;
  t1 = calloc(degree + 1, sizeof(double));
  t1[1] = 1.;
  if (degree == 1) {
    free(t0);
    return t1;
  }
  t2 = calloc(degree + 1, sizeof(double));
  for (i = 2; i <= degree; i++) {
    memset(t2, 0, (degree + 1) * sizeof(double));
    polynomial_multiplication(m, 1, t1, i - 1, t2, degree);
    polynomial_subtraction(t2, degree, t0, i - 2, t2);
    p = t0;
    t0 = t1;
    t1 = t2;
    t2 = p;
  }
  free(t0);
  free(t2);
  return t1;
}


x86 assembly (clang, -O0):
<chebyshev_coefs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeab(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsd  0xe6f(%rip),%xmm0
movsd  %xmm0,(%rax)
cmpl   $0x0,-0xc(%rbp)
jne    11ac <chebyshev_coefs+0x5c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12b3 <chebyshev_coefs+0x163>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsd  0xe34(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
cmpl   $0x1,-0xc(%rbp)
jne    11f1 <chebyshev_coefs+0xa1>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12b3 <chebyshev_coefs+0x163>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1299 <chebyshev_coefs+0x149>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x28(%rbp),%r8
mov    -0xc(%rbp),%r9d
mov    $0x1,%esi
call   1070 <polynomial_multiplication@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%ecx
sub    $0x2,%ecx
mov    -0x28(%rbp),%r8
call   1040 <polynomial_subtraction@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    120c <chebyshev_coefs+0xbc>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chebyshev_coefs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
movaps 0xe98(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x1(%r15),%r12d
mov    %r12d,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
movabs $0x3ff0000000000000,%rbp
mov    %rbp,(%rax)
test   %r15d,%r15d
je     11b4 <chebyshev_coefs+0x64>
mov    %r12d,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,0x8(%rax)
cmp    $0x1,%r15d
jne    11bc <chebyshev_coefs+0x6c>
mov    %r14,%rdi
jmp    1238 <chebyshev_coefs+0xe8>
mov    %r14,%rbx
jmp    123d <chebyshev_coefs+0xed>
mov    %r12d,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
cmp    $0x2,%r15d
jge    11d4 <chebyshev_coefs+0x84>
mov    %rax,%r13
jmp    122d <chebyshev_coefs+0xdd>
shl    $0x3,%r12d
mov    $0x1,%ebp
nopl   (%rax)
mov    %r14,%r13
mov    %rbx,%r14
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1050 <memset@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %rbx,%r8
mov    %r15d,%r9d
call   1070 <polynomial_multiplication@plt>
lea    -0x1(%rbp),%ecx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r13,%rdx
mov    %rbx,%r8
call   1040 <polynomial_subtraction@plt>
add    $0x1,%ebp
mov    %r13,%rax
cmp    %ebp,%r15d
jne    11e0 <chebyshev_coefs+0x90>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.chebyshev_coefs.m = [2 x double] [double 0.000000e+00, double 2.000000e+00]
define double* @chebyshev_coefs(i32 %0) {
%2 = alloca double*
%3 = alloca i32
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca [2 x double]
store i32 %0, i32* %3
%10 = bitcast [2 x double]* %9 to i8*
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
%13 = call double* @calloc(i32 %12, i32 8)
store double* %13, double** %5
%14 = load double*, double** %5
%15 = getelementptr inbounds double, double* %14, i64 0
store double 1.000000e+00, double* %15
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = load double*, double** %5
store double* %19, double** %2
br label %75
20: ; preds = %1
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
%23 = call double* @calloc(i32 %22, i32 8)
store double* %23, double** %6
%24 = load double*, double** %6
%25 = getelementptr inbounds double, double* %24, i64 1
store double 1.000000e+00, double* %25
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %32
28: ; preds = %20
%29 = load double*, double** %5
%30 = call i32 @free(double* %29)
%31 = load double*, double** %6
store double* %31, double** %2
br label %75
32: ; preds = %20
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
%35 = call double* @calloc(i32 %34, i32 8)
store double* %35, double** %7
store i32 2, i32* %4
br label %36
36: ; preds = %66, %32
%37 = load i32, i32* %4
%38 = load i32, i32* %3
%39 = icmp sle i32 %37, %38
br i1 %39, label %40, label %69
40: ; preds = %36
%41 = load double*, double** %7
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = mul i64 %44, 8
%46 = trunc i64 %45 to i32
%47 = call i32 @memset(double* %41, i32 0, i32 %46)
%48 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%49 = load double*, double** %6
%50 = load i32, i32* %4
%51 = sub nsw i32 %50, 1
%52 = load double*, double** %7
%53 = load i32, i32* %3
%54 = call i32 @polynomial_multiplication(double* %48, i32 1, double* %49, i32 %51, double* %52, i32 %53)
%55 = load double*, double** %7
%56 = load i32, i32* %3
%57 = load double*, double** %5
%58 = load i32, i32* %4
%59 = sub nsw i32 %58, 2
%60 = load double*, double** %7
%61 = call i32 @polynomial_subtraction(double* %55, i32 %56, double* %57, i32 %59, double* %60)
%62 = load double*, double** %5
store double* %62, double** %8
%63 = load double*, double** %6
store double* %63, double** %5
%64 = load double*, double** %7
store double* %64, double** %6
%65 = load double*, double** %8
store double* %65, double** %7
br label %66
66: ; preds = %40
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %36
69: ; preds = %36
%70 = load double*, double** %5
%71 = call i32 @free(double* %70)
%72 = load double*, double** %7
%73 = call i32 @free(double* %72)
%74 = load double*, double** %6
store double* %74, double** %2
br label %75
75: ; preds = %69, %28, %18
%76 = load double*, double** %2
ret double* %76
}

LLVM IR (-O2):
@__const.chebyshev_coefs.m = [2 x double] [double 0.000000e+00, double 2.000000e+00]
define double* @chebyshev_coefs(i32 %0) {
%2 = alloca [2 x double]
%3 = bitcast [2 x double]* %2 to i8*
%4 = add i32 %0, 1
%5 = tail call double* @calloc(i32 %4, i32 8)
store double 1.000000e+00, double* %5
%6 = icmp eq i32 %0, 0
br i1 %6, label %37, label %7
7: ; preds = %1
%8 = tail call double* @calloc(i32 %4, i32 8)
%9 = getelementptr inbounds double, double* %8, i64 1
store double 1.000000e+00, double* %9
%10 = icmp eq i32 %0, 1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @free(double* %5)
br label %37
13: ; preds = %7
%14 = tail call double* @calloc(i32 %4, i32 8)
%15 = icmp slt i32 %0, 2
br i1 %15, label %31, label %16
16: ; preds = %13
%17 = shl i32 %4, 3
%18 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
br label %19
19: ; preds = %16, %19
%20 = phi double* [ %14, %16 ], [ %22, %19 ]
%21 = phi double* [ %8, %16 ], [ %20, %19 ]
%22 = phi double* [ %5, %16 ], [ %21, %19 ]
%23 = phi i32 [ 2, %16 ], [ %29, %19 ]
%24 = call i32 @memset(double* %20, i32 0, i32 %17)
%25 = add nsw i32 %23, -1
%26 = call i32 @polynomial_multiplication(double* %18, i32 1, double* %21, i32 %25, double* %20, i32 %0)
%27 = add nsw i32 %23, -2
%28 = call i32 @polynomial_subtraction(double* %20, i32 %0, double* %22, i32 %27, double* %20)
%29 = add nuw i32 %23, 1
%30 = icmp eq i32 %23, %0
br i1 %30, label %31, label %19
31: ; preds = %19, %13
%32 = phi double* [ %5, %13 ], [ %21, %19 ]
%33 = phi double* [ %8, %13 ], [ %20, %19 ]
%34 = phi double* [ %14, %13 ], [ %22, %19 ]
%35 = call i32 @free(double* %32)
%36 = call i32 @free(double* %34)
br label %37
37: ; preds = %1, %31, %11
%38 = phi double* [ %8, %11 ], [ %33, %31 ], [ %5, %1 ]
ret double* %38
}