#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 NewtonPoly(double, double *, double *);
int /*<<< orphan*/ funcvals(int, double *, double *);
int /*<<< orphan*/ nodes(int, double *);
int /*<<< orphan*/ polycoeffs(int, double *, double *, double *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i, n;
  n = 15;
  double x[n + 1], y[n + 1], c[n + 1];
  double xval[29 + 1], yval[29 + 1], error;
  double polyval;
  nodes(n, x);
  funcvals(n, x, y);
  polycoeffs(n, x, y, c);
  n = 29;
  nodes(n, xval);
  funcvals(n, xval, yval);
  printf("##%2s \t %12s \t %12s \t %17s \n", "x", "f(x)", "p(x)", "f(x)-p(x)");
  for (i = 0; i <= n; i++) {
    polyval = NewtonPoly(xval[i], x, c);
    error = yval[i] - polyval;
    printf("%lf \t %lf \t %lf \t %lf \n", xval[i], yval[i], polyval, error);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x238(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x230(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x228(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <nodes@plt>
mov    -0x238(%rbp),%rsi
mov    -0x230(%rbp),%rdx
mov    -0xc(%rbp),%edi
call   1070 <funcvals@plt>
mov    -0x238(%rbp),%rsi
mov    -0x230(%rbp),%rdx
mov    -0x228(%rbp),%rcx
mov    -0xc(%rbp),%edi
call   1030 <polycoeffs@plt>
movl   $0x1d,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   1060 <nodes@plt>
mov    -0xc(%rbp),%edi
lea    -0x120(%rbp),%rsi
lea    -0x210(%rbp),%rdx
call   1070 <funcvals@plt>
lea    0xdb0(%rip),%rdi
lea    0xdc6(%rip),%rsi
lea    0xdc1(%rip),%rdx
lea    0xdc4(%rip),%rcx
lea    0xdb8(%rip),%r8
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1311 <main+0x1c1>
mov    -0x228(%rbp),%rsi
mov    -0x238(%rbp),%rdi
movslq -0x8(%rbp),%rax
movsd  -0x120(%rbp,%rax,8),%xmm0
ff ff
call   1040 <NewtonPoly@plt>
movsd  %xmm0,-0x220(%rbp)
ff
movslq -0x8(%rbp),%rax
movsd  -0x210(%rbp,%rax,8),%xmm0
ff ff
subsd  -0x220(%rbp),%xmm0
ff
movsd  %xmm0,-0x218(%rbp)
ff
movslq -0x8(%rbp),%rax
movsd  -0x120(%rbp,%rax,8),%xmm0
ff ff
movslq -0x8(%rbp),%rax
movsd  -0x210(%rbp,%rax,8),%xmm1
ff ff
movsd  -0x220(%rbp),%xmm2
ff
movsd  -0x218(%rbp),%xmm3
ff
lea    0xd32(%rip),%rdi
mov    $0x4,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    127a <main+0x12a>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x368,%rsp
lea    0x2e0(%rsp),%r14
mov    $0xf,%edi
mov    %r14,%rsi
call   1060 <nodes@plt>
lea    0x260(%rsp),%rbx
mov    $0xf,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <funcvals@plt>
lea    0x1e0(%rsp),%r15
mov    $0xf,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <polycoeffs@plt>
mov    %rsp,%rbx
mov    $0x1d,%edi
mov    %rbx,%rsi
call   1060 <nodes@plt>
lea    0xf0(%rsp),%rdx
mov    $0x1d,%edi
mov    %rbx,%rsi
call   1070 <funcvals@plt>
lea    0xe2e(%rip),%rdi
lea    0xe44(%rip),%rsi
lea    0xe3f(%rip),%rdx
lea    0xe42(%rip),%rcx
lea    0xe36(%rip),%r8
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe30(%rip),%r12
xchg   %ax,%ax
movsd  (%rsp,%rbx,8),%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <NewtonPoly@plt>
movapd %xmm0,%xmm2
movsd  0xf0(%rsp,%rbx,8),%xmm1
movapd %xmm1,%xmm3
subsd  %xmm0,%xmm3
movsd  (%rsp,%rbx,8),%xmm0
mov    %r12,%rdi
mov    $0x4,%al
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0x1e,%rbx
jne    1200 <main+0xb0>
xor    %eax,%eax
add    $0x368,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"##%2s \09 %12s \09 %12s \09 %17s \0A\00"
@.str.1 = [2 x i8] c"x\00"
@.str.2 = [5 x i8] c"f(x)\00"
@.str.3 = [5 x i8] c"p(x)\00"
@.str.4 = [10 x i8] c"f(x)-p(x)\00"
@.str.5 = [24 x i8] c"%lf \09 %lf \09 %lf \09 %lf \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca [30 x double]
%9 = alloca [30 x double]
%10 = alloca double
%11 = alloca double
store i32 0, i32* %1
store i32 15, i32* %3
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %4
%16 = alloca double, i64 %14
store i64 %14, i64* %5
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = alloca double, i64 %19
store i64 %19, i64* %6
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
%23 = zext i32 %22 to i64
%24 = alloca double, i64 %23
store i64 %23, i64* %7
%25 = load i32, i32* %3
%26 = call i32 @nodes(i32 %25, double* %16)
%27 = load i32, i32* %3
%28 = call i32 @funcvals(i32 %27, double* %16, double* %20)
%29 = load i32, i32* %3
%30 = call i32 @polycoeffs(i32 %29, double* %16, double* %20, double* %24)
store i32 29, i32* %3
%31 = load i32, i32* %3
%32 = getelementptr inbounds [30 x double], [30 x double]* %8, i64 0, i64 0
%33 = call i32 @nodes(i32 %31, double* %32)
%34 = load i32, i32* %3
%35 = getelementptr inbounds [30 x double], [30 x double]* %8, i64 0, i64 0
%36 = getelementptr inbounds [30 x double], [30 x double]* %9, i64 0, i64 0
%37 = call i32 @funcvals(i32 %34, double* %35, double* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %39
39: ; preds = %66, %0
%40 = load i32, i32* %2
%41 = load i32, i32* %3
%42 = icmp sle i32 %40, %41
br i1 %42, label %43, label %69
43: ; preds = %39
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [30 x double], [30 x double]* %8, i64 0, i64 %45
%47 = load double, double* %46
%48 = call double @NewtonPoly(double %47, double* %16, double* %24)
store double %48, double* %11
%49 = load i32, i32* %2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [30 x double], [30 x double]* %9, i64 0, i64 %50
%52 = load double, double* %51
%53 = load double, double* %11
%54 = fsub double %52, %53
store double %54, double* %10
%55 = load i32, i32* %2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [30 x double], [30 x double]* %8, i64 0, i64 %56
%58 = load double, double* %57
%59 = load i32, i32* %2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [30 x double], [30 x double]* %9, i64 0, i64 %60
%62 = load double, double* %61
%63 = load double, double* %11
%64 = load double, double* %10
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), double %58, double %62, double %63, double %64)
br label %66
66: ; preds = %43
%67 = load i32, i32* %2
%68 = add nsw i32 %67, 1
store i32 %68, i32* %2
br label %39
69: ; preds = %39
%70 = load i8*, i8** %4
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
@.str = [29 x i8] c"##%2s \09 %12s \09 %12s \09 %17s \0A\00"
@.str.1 = [2 x i8] c"x\00"
@.str.2 = [5 x i8] c"f(x)\00"
@.str.3 = [5 x i8] c"p(x)\00"
@.str.4 = [10 x i8] c"f(x)-p(x)\00"
@.str.5 = [24 x i8] c"%lf \09 %lf \09 %lf \09 %lf \0A\00"
define i32 @main() {
%1 = alloca [30 x double]
%2 = alloca [30 x double]
%3 = alloca [16 x double]
%4 = alloca [16 x double]
%5 = alloca [16 x double]
%6 = getelementptr inbounds [16 x double], [16 x double]* %5, i64 0, i64 0
%7 = getelementptr inbounds [16 x double], [16 x double]* %4, i64 0, i64 0
%8 = getelementptr inbounds [16 x double], [16 x double]* %3, i64 0, i64 0
%9 = bitcast [30 x double]* %1 to i8*
%10 = bitcast [30 x double]* %2 to i8*
%11 = call i32 @nodes(i32 15, double* %8)
%12 = call i32 @funcvals(i32 15, double* %8, double* %7)
%13 = call i32 @polycoeffs(i32 15, double* %8, double* %7, double* %6)
%14 = getelementptr inbounds [30 x double], [30 x double]* %1, i64 0, i64 0
%15 = call i32 @nodes(i32 29, double* %14)
%16 = getelementptr inbounds [30 x double], [30 x double]* %2, i64 0, i64 0
%17 = call i32 @funcvals(i32 29, double* %14, double* %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %0, %19
%20 = phi i64 [ 0, %0 ], [ %29, %19 ]
%21 = getelementptr inbounds [30 x double], [30 x double]* %1, i64 0, i64 %20
%22 = load double, double* %21
%23 = call double @NewtonPoly(double %22, double* %8, double* %6)
%24 = getelementptr inbounds [30 x double], [30 x double]* %2, i64 0, i64 %20
%25 = load double, double* %24
%26 = fsub double %25, %23
%27 = load double, double* %21
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), double %27, double %25, double %23, double %26)
%29 = add nuw nsw i64 %20, 1
%30 = icmp eq i64 %29, 30
br i1 %30, label %31, label %19
31: ; preds = %19
ret i32 0
}