#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*/ igraph_i_fdiv(double, double);
double igraph_chebyshev_eval(double x, const double *a, const int n) {
  double b0, b1, b2, twox;
  int i;
  if (n < 1 || n > 1000)
    (igraph_i_fdiv(0.0, 0.0));
  if (x < -1.1 || x > 1.1)
    (igraph_i_fdiv(0.0, 0.0));
  twox = x * 2;
  b2 = b1 = 0;
  b0 = 0;
  for (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):
<igraph_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     113b <igraph_chebyshev_eval+0x2b>
cmpl   $0x3e8,-0x14(%rbp)
jle    1146 <igraph_chebyshev_eval+0x36>
xorps  %xmm1,%xmm1
movaps %xmm1,%xmm0
call   1030 <igraph_i_fdiv@plt>
movsd  0xeb2(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     1170 <igraph_chebyshev_eval+0x60>
movsd  -0x8(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    117b <igraph_chebyshev_eval+0x6b>
xorps  %xmm1,%xmm1
movaps %xmm1,%xmm0
call   1030 <igraph_i_fdiv@plt>
movsd  0xe8d(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     121f <igraph_chebyshev_eval+0x10f>
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    11ac <igraph_chebyshev_eval+0x9c>
movsd  -0x20(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  0xde7(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<igraph_chebyshev_eval>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
movapd %xmm0,%xmm3
lea    -0x3e9(%rbx),%eax
cmp    $0xfffffc17,%eax
movsd  %xmm0,(%rsp)
ja     1141 <igraph_chebyshev_eval+0x31>
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
call   1030 <igraph_i_fdiv@plt>
movsd  (%rsp),%xmm3
movsd  0xeb7(%rip),%xmm0
ucomisd %xmm3,%xmm0
ja     1182 <igraph_chebyshev_eval+0x72>
ucomisd 0xeb1(%rip),%xmm3
ja     1182 <igraph_chebyshev_eval+0x72>
test   %ebx,%ebx
jle    1198 <igraph_chebyshev_eval+0x88>
addsd  %xmm3,%xmm3
mov    %ebx,%eax
cmp    $0x1,%ebx
jne    11a1 <igraph_chebyshev_eval+0x91>
xorpd  %xmm0,%xmm0
mov    $0x1,%ecx
xorpd  %xmm1,%xmm1
test   $0x1,%al
jne    1204 <igraph_chebyshev_eval+0xf4>
jmp    121d <igraph_chebyshev_eval+0x10d>
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
call   1030 <igraph_i_fdiv@plt>
movsd  (%rsp),%xmm3
test   %ebx,%ebx
jg     115d <igraph_chebyshev_eval+0x4d>
xorpd  %xmm0,%xmm0
jmp    1229 <igraph_chebyshev_eval+0x119>
mov    %eax,%edx
and    $0xfffffffe,%edx
lea    (%r14,%rax,8),%rsi
xorpd  %xmm0,%xmm0
mov    $0xffffffffffffffff,%rcx
xorpd  %xmm1,%xmm1
nopl   0x0(%rax)
movapd %xmm0,%xmm2
movapd %xmm3,%xmm0
mulsd  %xmm2,%xmm0
subsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
addsd  (%rsi,%rcx,8),%xmm1
movapd %xmm3,%xmm0
mulsd  %xmm1,%xmm0
subsd  %xmm2,%xmm0
addsd  -0x8(%rsi,%rcx,8),%xmm0
lea    (%rdx,%rcx,1),%rdi
add    $0xfffffffffffffffe,%rdi
add    $0xfffffffffffffffe,%rcx
cmp    $0xffffffffffffffff,%rdi
jne    11c0 <igraph_chebyshev_eval+0xb0>
neg    %rcx
test   $0x1,%al
je     121d <igraph_chebyshev_eval+0x10d>
mulsd  %xmm0,%xmm3
subsd  %xmm1,%xmm3
sub    %rcx,%rax
addsd  (%r14,%rax,8),%xmm3
movapd %xmm1,%xmm2
movapd %xmm3,%xmm0
subsd  %xmm2,%xmm0
mulsd  0xde7(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @igraph_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 %19
17: ; preds = %14, %3
%18 = call i32 @igraph_i_fdiv(double 0.000000e+00, double 0.000000e+00)
br label %19
19: ; preds = %17, %14
%20 = load double, double* %4
%21 = fcmp olt double %20, -1.100000e+00
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load double, double* %4
%24 = fcmp ogt double %23, 1.100000e+00
br i1 %24, label %25, label %27
25: ; preds = %22, %19
%26 = call i32 @igraph_i_fdiv(double 0.000000e+00, double 0.000000e+00)
br label %27
27: ; preds = %25, %22
%28 = load double, double* %4
%29 = fmul double %28, 2.000000e+00
store double %29, double* %10
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %7
store i32 1, i32* %11
br label %30
30: ; preds = %50, %27
%31 = load i32, i32* %11
%32 = load i32, i32* %6
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %53
34: ; preds = %30
%35 = load double, double* %8
store double %35, double* %9
%36 = load double, double* %7
store double %36, double* %8
%37 = load double, double* %10
%38 = load double, double* %8
%39 = load double, double* %9
%40 = fneg double %39
%41 = call double @llvm.fmuladd.f64(double %37, double %38, double %40)
%42 = load double*, double** %5
%43 = load i32, i32* %6
%44 = load i32, i32* %11
%45 = sub nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %42, i64 %46
%48 = load double, double* %47
%49 = fadd double %41, %48
store double %49, double* %7
br label %50
50: ; preds = %34
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %30
53: ; preds = %30
%54 = load double, double* %7
%55 = load double, double* %9
%56 = fsub double %54, %55
%57 = fmul double %56, 5.000000e-01
ret double %57
}

LLVM IR (-O2):
define double @igraph_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 %8
6: ; preds = %3
%7 = tail call i32 @igraph_i_fdiv(double 0.000000e+00, double 0.000000e+00)
br label %8
8: ; preds = %3, %6
%9 = fcmp olt double %0, -1.100000e+00
%10 = fcmp ogt double %0, 1.100000e+00
%11 = or i1 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @igraph_i_fdiv(double 0.000000e+00, double 0.000000e+00)
br label %14
14: ; preds = %8, %12
%15 = fmul double %0, 2.000000e+00
%16 = icmp slt i32 %2, 1
br i1 %16, label %64, label %17
17: ; preds = %14
%18 = zext i32 %2 to i64
%19 = zext i32 %2 to i64
%20 = and i64 %19, 1
%21 = icmp eq i32 %2, 1
br i1 %21, label %45, label %22
22: ; preds = %17
%23 = and i64 %19, 4294967294
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 1, %22 ], [ %42, %24 ]
%26 = phi double [ 0.000000e+00, %22 ], [ %41, %24 ]
%27 = phi double [ 0.000000e+00, %22 ], [ %34, %24 ]
%28 = phi i64 [ 0, %22 ], [ %43, %24 ]
%29 = fneg double %27
%30 = tail call double @llvm.fmuladd.f64(double %15, double %26, double %29)
%31 = sub nsw i64 %18, %25
%32 = getelementptr inbounds double, double* %1, i64 %31
%33 = load double, double* %32
%34 = fadd double %30, %33
%35 = xor i64 %25, -1
%36 = fneg double %26
%37 = tail call double @llvm.fmuladd.f64(double %15, double %34, double %36)
%38 = add nsw i64 %35, %18
%39 = getelementptr inbounds double, double* %1, i64 %38
%40 = load double, double* %39
%41 = fadd double %37, %40
%42 = add nuw nsw i64 %25, 2
%43 = add i64 %28, 2
%44 = icmp eq i64 %43, %23
br i1 %44, label %45, label %24
45: ; preds = %24, %17
%46 = phi double [ undef, %17 ], [ %26, %24 ]
%47 = phi double [ undef, %17 ], [ %41, %24 ]
%48 = phi i64 [ 1, %17 ], [ %42, %24 ]
%49 = phi double [ 0.000000e+00, %17 ], [ %41, %24 ]
%50 = phi double [ 0.000000e+00, %17 ], [ %34, %24 ]
%51 = icmp eq i64 %20, 0
br i1 %51, label %59, label %52
52: ; preds = %45
%53 = fneg double %50
%54 = tail call double @llvm.fmuladd.f64(double %15, double %49, double %53)
%55 = sub nsw i64 %18, %48
%56 = getelementptr inbounds double, double* %1, i64 %55
%57 = load double, double* %56
%58 = fadd double %54, %57
br label %59
59: ; preds = %45, %52
%60 = phi double [ %46, %45 ], [ %50, %52 ]
%61 = phi double [ %47, %45 ], [ %58, %52 ]
%62 = fsub double %61, %60
%63 = fmul double %62, 5.000000e-01
br label %64
64: ; preds = %59, %14
%65 = phi double [ %63, %59 ], [ 0.000000e+00, %14 ]
ret double %65
}