#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 */
int /*<<< orphan*/ chebyshev_coef(int, double (*)(double), double, double,
                                  double *);
double chebyshev_eval(int, double *, double, double, double);
double chebyshev_eval_(int, double *, double, double, double);
scalar_t__ compare_max(double, double, char *, int, double, double *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, double, int);
int /*<<< orphan*/ stderr;
int check_chebyshev_sub(int ncheb, double x0, double x1, double (*func)(double),
                        char *label, int verbose, double tiny, double *max) {
  int check = 0;
  double *a_cheb = (double *)malloc(sizeof(double) * ncheb);
  if (a_cheb == NULL) {
    fprintf(stderr, "check_chebyshev"
                    " : malloc error for "
                    "a_cheb"
                    "\n");
    exit(1);
  };
  chebyshev_coef(ncheb, func, x0, x1, a_cheb);
  char label_i[80];
  int i;
  for (i = 0; i < 100; i++) {
    double x = x0 + (double)i / 100.0 * (x1 - x0);
    double y0 = func(x);
    double y1 = chebyshev_eval(ncheb, a_cheb, x0, x1, x);
    double y2 = chebyshev_eval_(ncheb, a_cheb, x0, x1, x);
    sprintf(label_i, "%s(%f) y0-y1 [%d]", label, x, i);
    check += compare_max(y0, y1, label_i, verbose, tiny, max);
    sprintf(label_i, "%s(%f) y1-y2 [%d]", label, x, i);
    check += compare_max(y1, y2, label_i, verbose, tiny, max);
  }
  free(a_cheb);
  return (check);
}


x86 assembly (clang, -O0):
<check_chebyshev_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
movsd  %xmm2,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1200 <check_chebyshev_sub+0x70>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x50(%rbp),%rdx
call   1040 <chebyshev_coef@plt>
movl   $0x0,-0xa4(%rbp)
cmpl   $0x64,-0xa4(%rbp)
jge    138e <check_chebyshev_sub+0x1fe>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0xa4(%rbp),%xmm0
ff
movsd  0xdba(%rip),%xmm2
divsd  %xmm2,%xmm0
movsd  -0x18(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
mov    -0x20(%rbp),%rax
movsd  -0xb0(%rbp),%xmm0
ff
call   *%rax
movsd  %xmm0,-0xb8(%rbp)
ff
mov    -0x4(%rbp),%edi
mov    -0x50(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0xb0(%rbp),%xmm2
ff
call   1060 <chebyshev_eval@plt>
movsd  %xmm0,-0xc0(%rbp)
ff
mov    -0x4(%rbp),%edi
mov    -0x50(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0xb0(%rbp),%xmm2
ff
call   1050 <chebyshev_eval_@plt>
movsd  %xmm0,-0xc8(%rbp)
ff
lea    -0xa0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
movsd  -0xb0(%rbp),%xmm0
ff
mov    -0xa4(%rbp),%ecx
lea    0xd4d(%rip),%rsi
call   10a0 <sprintf@plt>
movsd  -0xb8(%rbp),%xmm0
ff
movsd  -0xc0(%rbp),%xmm1
ff
lea    -0xa0(%rbp),%rdi
mov    -0x2c(%rbp),%esi
movsd  -0x38(%rbp),%xmm2
mov    -0x40(%rbp),%rdx
call   1080 <compare_max@plt>
mov    %rax,%rcx
movslq -0x44(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x44(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
movsd  -0xb0(%rbp),%xmm0
ff
mov    -0xa4(%rbp),%ecx
lea    0xd05(%rip),%rsi
call   10a0 <sprintf@plt>
movsd  -0xc0(%rbp),%xmm0
ff
movsd  -0xc8(%rbp),%xmm1
ff
lea    -0xa0(%rbp),%rdi
mov    -0x2c(%rbp),%esi
movsd  -0x38(%rbp),%xmm2
mov    -0x40(%rbp),%rdx
call   1080 <compare_max@plt>
mov    %rax,%rcx
movslq -0x44(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x44(%rbp)
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    1224 <check_chebyshev_sub+0x94>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_chebyshev_sub>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %r8,0x50(%rsp)
movsd  %xmm2,0x38(%rsp)
mov    %ecx,%ebx
mov    %rdx,%r13
mov    %rsi,0x30(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdi,0x28(%rsp)
lea    0x0(,%rdi,8),%edi
call   1090 <malloc@plt>
mov    %rax,0x20(%rsp)
test   %rax,%rax
je     1368 <check_chebyshev_sub+0x1d8>
mov    0x28(%rsp),%rdi
mov    0x30(%rsp),%rsi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    0x20(%rsp),%rdx
call   1040 <chebyshev_coef@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x48(%rsp)
xorpd  %xmm0,%xmm0
xor    %r12d,%r12d
xor    %r14d,%r14d
nopl   (%rax)
movsd  %xmm0,0x68(%rsp)
divsd  0xdd2(%rip),%xmm0
mulsd  0x48(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
call   *0x30(%rsp)
movsd  %xmm0,0x58(%rsp)
mov    0x28(%rsp),%rbp
mov    %ebp,%edi
mov    0x20(%rsp),%r15
mov    %r15,%rsi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
call   1060 <chebyshev_eval@plt>
movsd  %xmm0,0x40(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
call   1050 <chebyshev_eval_@plt>
movsd  %xmm0,0x60(%rsp)
lea    0x70(%rsp),%rbp
mov    %rbp,%rdi
lea    0xd94(%rip),%rsi
mov    %r13,%rdx
movsd  0x18(%rsp),%xmm0
mov    %r14d,%ecx
call   10a0 <sprintf@plt>
movsd  0x58(%rsp),%xmm0
movsd  0x40(%rsp),%xmm1
mov    %rbp,%rdi
mov    %ebx,%esi
movsd  0x38(%rsp),%xmm2
mov    0x50(%rsp),%rbp
mov    %rbp,%rdx
call   1080 <compare_max@plt>
mov    %r13,%r15
mov    %rax,%r13
add    %r12d,%r13d
lea    0x70(%rsp),%r12
mov    %r12,%rdi
lea    0xd59(%rip),%rsi
mov    %r15,%rdx
movsd  0x18(%rsp),%xmm0
mov    %r14d,%ecx
call   10a0 <sprintf@plt>
movsd  0x40(%rsp),%xmm0
movsd  0x60(%rsp),%xmm1
mov    %r12,%rdi
mov    %ebx,%esi
movsd  0x38(%rsp),%xmm2
mov    %rbp,%rdx
call   1080 <compare_max@plt>
movsd  0x68(%rsp),%xmm0
mov    %rax,%r12
add    %r13d,%r12d
mov    %r15,%r13
addsd  0xccd(%rip),%xmm0
add    $0x1,%r14d
cmp    $0x64,%r14d
jne    1220 <check_chebyshev_sub+0x90>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
lea    0xc98(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"check_chebyshev : malloc error for a_cheb\0A\00"
@.str.1 = [18 x i8] c"%s(%f) y0-y1 [%d]\00"
@.str.2 = [18 x i8] c"%s(%f) y1-y2 [%d]\00"
define i32 @check_chebyshev_sub(i32 %0, double %1, double %2, double (double)* %3, i8* %4, i32 %5, double %6, double* %7) {
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double (double)*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca double
%16 = alloca double*
%17 = alloca i32
%18 = alloca double*
%19 = alloca [80 x i8]
%20 = alloca i32
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
store i32 %0, i32* %9
store double %1, double* %10
store double %2, double* %11
store double (double)* %3, double (double)** %12
store i8* %4, i8** %13
store i32 %5, i32* %14
store double %6, double* %15
store double* %7, double** %16
store i32 0, i32* %17
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = mul i64 8, %26
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to double*
store double* %30, double** %18
%31 = load double*, double** %18
%32 = icmp eq double* %31, null
br i1 %32, label %33, label %37
33: ; preds = %8
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %8
%38 = load i32, i32* %9
%39 = load double (double)*, double (double)** %12
%40 = load double, double* %10
%41 = load double, double* %11
%42 = load double*, double** %18
%43 = call i32 @chebyshev_coef(i32 %38, double (double)* %39, double %40, double %41, double* %42)
store i32 0, i32* %20
br label %44
44: ; preds = %103, %37
%45 = load i32, i32* %20
%46 = icmp slt i32 %45, 100
br i1 %46, label %47, label %106
47: ; preds = %44
%48 = load double, double* %10
%49 = load i32, i32* %20
%50 = sitofp i32 %49 to double
%51 = fdiv double %50, 1.000000e+02
%52 = load double, double* %11
%53 = load double, double* %10
%54 = fsub double %52, %53
%55 = call double @llvm.fmuladd.f64(double %51, double %54, double %48)
store double %55, double* %21
%56 = load double (double)*, double (double)** %12
%57 = load double, double* %21
%58 = call double %56(double %57)
store double %58, double* %22
%59 = load i32, i32* %9
%60 = load double*, double** %18
%61 = load double, double* %10
%62 = load double, double* %11
%63 = load double, double* %21
%64 = call double @chebyshev_eval(i32 %59, double* %60, double %61, double %62, double %63)
store double %64, double* %23
%65 = load i32, i32* %9
%66 = load double*, double** %18
%67 = load double, double* %10
%68 = load double, double* %11
%69 = load double, double* %21
%70 = call double @chebyshev_eval_(i32 %65, double* %66, double %67, double %68, double %69)
store double %70, double* %24
%71 = getelementptr inbounds [80 x i8], [80 x i8]* %19, i64 0, i64 0
%72 = load i8*, i8** %13
%73 = load double, double* %21
%74 = load i32, i32* %20
%75 = call i32 @sprintf(i8* %71, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %72, double %73, i32 %74)
%76 = load double, double* %22
%77 = load double, double* %23
%78 = getelementptr inbounds [80 x i8], [80 x i8]* %19, i64 0, i64 0
%79 = load i32, i32* %14
%80 = load double, double* %15
%81 = load double*, double** %16
%82 = call i64 @compare_max(double %76, double %77, i8* %78, i32 %79, double %80, double* %81)
%83 = load i32, i32* %17
%84 = sext i32 %83 to i64
%85 = add nsw i64 %84, %82
%86 = trunc i64 %85 to i32
store i32 %86, i32* %17
%87 = getelementptr inbounds [80 x i8], [80 x i8]* %19, i64 0, i64 0
%88 = load i8*, i8** %13
%89 = load double, double* %21
%90 = load i32, i32* %20
%91 = call i32 @sprintf(i8* %87, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %88, double %89, i32 %90)
%92 = load double, double* %23
%93 = load double, double* %24
%94 = getelementptr inbounds [80 x i8], [80 x i8]* %19, i64 0, i64 0
%95 = load i32, i32* %14
%96 = load double, double* %15
%97 = load double*, double** %16
%98 = call i64 @compare_max(double %92, double %93, i8* %94, i32 %95, double %96, double* %97)
%99 = load i32, i32* %17
%100 = sext i32 %99 to i64
%101 = add nsw i64 %100, %98
%102 = trunc i64 %101 to i32
store i32 %102, i32* %17
br label %103
103: ; preds = %47
%104 = load i32, i32* %20
%105 = add nsw i32 %104, 1
store i32 %105, i32* %20
br label %44
106: ; preds = %44
%107 = load double*, double** %18
%108 = call i32 @free(double* %107)
%109 = load i32, i32* %17
ret i32 %109
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"check_chebyshev : malloc error for a_cheb\0A\00"
@.str.1 = [18 x i8] c"%s(%f) y0-y1 [%d]\00"
@.str.2 = [18 x i8] c"%s(%f) y1-y2 [%d]\00"
define i32 @check_chebyshev_sub(i32 %0, double %1, double %2, double (double)* %3, i8* %4, i32 %5, double %6, double* %7) {
%9 = alloca [80 x i8]
%10 = shl i32 %0, 3
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to double*
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %8
%19 = tail call i32 @chebyshev_coef(i32 %0, double (double)* %3, double %1, double %2, double* %12)
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%21 = fsub double %2, %1
br label %22
22: ; preds = %18, %22
%23 = phi i32 [ 0, %18 ], [ %38, %22 ]
%24 = phi i32 [ 0, %18 ], [ %39, %22 ]
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, 1.000000e+02
%27 = call double @llvm.fmuladd.f64(double %26, double %21, double %1)
%28 = call double %3(double %27)
%29 = call double @chebyshev_eval(i32 %0, double* %12, double %1, double %2, double %27)
%30 = call double @chebyshev_eval_(i32 %0, double* %12, double %1, double %2, double %27)
%31 = call i32 @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %4, double %27, i32 %24)
%32 = call i64 @compare_max(double %28, double %29, i8* %20, i32 %5, double %6, double* %7)
%33 = trunc i64 %32 to i32
%34 = add i32 %23, %33
%35 = call i32 @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %4, double %27, i32 %24)
%36 = call i64 @compare_max(double %29, double %30, i8* %20, i32 %5, double %6, double* %7)
%37 = trunc i64 %36 to i32
%38 = add i32 %34, %37
%39 = add nuw nsw i32 %24, 1
%40 = icmp eq i32 %39, 100
br i1 %40, label %41, label %22
41: ; preds = %22
%42 = call i32 @free(double* %12)
ret i32 %38
}