#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double chebyshev_eval(double x, const double *a, int n) {
  if (n < 1 || n > 1000) {
    fprintf(stderr, "n not on [1, 1000]\n");
    exit(EXIT_FAILURE);
  }
  if (x < -1.1 || x > 1.1) {
    fprintf(stderr, "x not on [-1.1, 1.1]\n");
    exit(EXIT_FAILURE);
  }
  double b0, b1, b2;
  b0 = b1 = b2 = 0;
  double twox = x * 2;
  for (int i = 1; i <= n; ++i) {
    b2 = b1;
    b1 = b0;
    b0 = twox * b1 - b2 + a[n - i];
  }
  return (b0 - b2) * 0.5;
}


x86 assembly (clang, -O0):
<chebyshev_eval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     114b <chebyshev_eval+0x2b>
cmpl   $0x3e8,-0x14(%rbp)
jle    116e <chebyshev_eval+0x4e>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xec5(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
movsd  0xe8a(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     1198 <chebyshev_eval+0x78>
movsd  -0x8(%rbp),%xmm0
movsd  0xe7a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11bb <chebyshev_eval+0x9b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe35(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     125f <chebyshev_eval+0x13f>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ec <chebyshev_eval+0xcc>
movsd  -0x20(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  0xda7(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chebyshev_eval>:
push   %rax
lea    -0x3e9(%rsi),%eax
cmp    $0xfffffc17,%eax
jbe    1201 <chebyshev_eval+0xe1>
movsd  0xec6(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1213 <chebyshev_eval+0xf3>
ucomisd 0xebc(%rip),%xmm0
ja     1213 <chebyshev_eval+0xf3>
addsd  %xmm0,%xmm0
mov    %esi,%r8d
cmp    $0x1,%esi
jne    1173 <chebyshev_eval+0x53>
xorpd  %xmm1,%xmm1
mov    $0x1,%ecx
xorpd  %xmm2,%xmm2
test   $0x1,%r8b
jne    11d6 <chebyshev_eval+0xb6>
jmp    11ef <chebyshev_eval+0xcf>
mov    %r8d,%edx
and    $0xfffffffe,%edx
lea    (%rdi,%r8,8),%rsi
xorpd  %xmm1,%xmm1
mov    $0xffffffffffffffff,%rcx
xorpd  %xmm2,%xmm2
nopl   0x0(%rax)
movapd %xmm1,%xmm3
movapd %xmm0,%xmm1
mulsd  %xmm3,%xmm1
subsd  %xmm2,%xmm1
movapd %xmm1,%xmm2
addsd  (%rsi,%rcx,8),%xmm2
movapd %xmm0,%xmm1
mulsd  %xmm2,%xmm1
subsd  %xmm3,%xmm1
addsd  -0x8(%rsi,%rcx,8),%xmm1
lea    (%rdx,%rcx,1),%rax
add    $0xfffffffffffffffe,%rax
add    $0xfffffffffffffffe,%rcx
cmp    $0xffffffffffffffff,%rax
jne    1190 <chebyshev_eval+0x70>
neg    %rcx
test   $0x1,%r8b
je     11ef <chebyshev_eval+0xcf>
mulsd  %xmm1,%xmm0
subsd  %xmm2,%xmm0
sub    %rcx,%r8
addsd  (%rdi,%r8,8),%xmm0
movapd %xmm2,%xmm3
movapd %xmm0,%xmm1
subsd  %xmm3,%xmm1
mulsd  0xe15(%rip),%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
jmp    1223 <chebyshev_eval+0x103>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"n not on [1, 1000]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"x not on [-1.1, 1.1]\0A\00"
define double @chebyshev_eval(double %0, double* %1, i32 %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store double %0, double* %4
store double* %1, double** %5
store i32 %2, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 1
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 1000
br i1 %16, label %17, label %22
17: ; preds = %14, %3
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
%23 = load double, double* %4
%24 = fcmp olt double %23, -1.100000e+00
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load double, double* %4
%27 = fcmp ogt double %26, 1.100000e+00
br i1 %27, label %28, label %33
28: ; preds = %25, %22
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %25
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %7
%34 = load double, double* %4
%35 = fmul double %34, 2.000000e+00
store double %35, double* %10
store i32 1, i32* %11
br label %36
36: ; preds = %56, %33
%37 = load i32, i32* %11
%38 = load i32, i32* %6
%39 = icmp sle i32 %37, %38
br i1 %39, label %40, label %59
40: ; preds = %36
%41 = load double, double* %8
store double %41, double* %9
%42 = load double, double* %7
store double %42, double* %8
%43 = load double, double* %10
%44 = load double, double* %8
%45 = load double, double* %9
%46 = fneg double %45
%47 = call double @llvm.fmuladd.f64(double %43, double %44, double %46)
%48 = load double*, double** %5
%49 = load i32, i32* %6
%50 = load i32, i32* %11
%51 = sub nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %48, i64 %52
%54 = load double, double* %53
%55 = fadd double %47, %54
store double %55, double* %7
br label %56
56: ; preds = %40
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %36
59: ; preds = %36
%60 = load double, double* %7
%61 = load double, double* %9
%62 = fsub double %60, %61
%63 = fmul double %62, 5.000000e-01
ret double %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"n not on [1, 1000]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"x not on [-1.1, 1.1]\0A\00"
define double @chebyshev_eval(double %0, double* nocapture %1, i32 %2) {
%4 = add i32 %2, -1001
%5 = icmp ult i32 %4, -1000
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3
%12 = fcmp olt double %0, -1.100000e+00
%13 = fcmp ogt double %0, 1.100000e+00
%14 = or i1 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %11
%21 = fmul double %0, 2.000000e+00
%22 = zext i32 %2 to i64
%23 = zext i32 %2 to i64
%24 = and i64 %23, 1
%25 = icmp eq i32 %2, 1
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = and i64 %23, 4294967294
br label %47
28: ; preds = %47, %20
%29 = phi double [ undef, %20 ], [ %49, %47 ]
%30 = phi double [ undef, %20 ], [ %64, %47 ]
%31 = phi i64 [ 1, %20 ], [ %65, %47 ]
%32 = phi double [ 0.000000e+00, %20 ], [ %64, %47 ]
%33 = phi double [ 0.000000e+00, %20 ], [ %57, %47 ]
%34 = icmp eq i64 %24, 0
br i1 %34, label %42, label %35
35: ; preds = %28
%36 = fneg double %33
%37 = tail call double @llvm.fmuladd.f64(double %21, double %32, double %36)
%38 = sub nsw i64 %22, %31
%39 = getelementptr inbounds double, double* %1, i64 %38
%40 = load double, double* %39
%41 = fadd double %37, %40
br label %42
42: ; preds = %28, %35
%43 = phi double [ %29, %28 ], [ %33, %35 ]
%44 = phi double [ %30, %28 ], [ %41, %35 ]
%45 = fsub double %44, %43
%46 = fmul double %45, 5.000000e-01
ret double %46
47: ; preds = %47, %26
%48 = phi i64 [ 1, %26 ], [ %65, %47 ]
%49 = phi double [ 0.000000e+00, %26 ], [ %64, %47 ]
%50 = phi double [ 0.000000e+00, %26 ], [ %57, %47 ]
%51 = phi i64 [ 0, %26 ], [ %66, %47 ]
%52 = fneg double %50
%53 = tail call double @llvm.fmuladd.f64(double %21, double %49, double %52)
%54 = sub nsw i64 %22, %48
%55 = getelementptr inbounds double, double* %1, i64 %54
%56 = load double, double* %55
%57 = fadd double %53, %56
%58 = xor i64 %48, -1
%59 = fneg double %49
%60 = tail call double @llvm.fmuladd.f64(double %21, double %57, double %59)
%61 = add nsw i64 %58, %22
%62 = getelementptr inbounds double, double* %1, i64 %61
%63 = load double, double* %62
%64 = fadd double %60, %63
%65 = add nuw nsw i64 %48, 2
%66 = add i64 %51, 2
%67 = icmp eq i64 %66, %27
br i1 %67, label %28, label %47
}