#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*/ math_pchip_initialise(int /*<<< orphan*/, int,
                                         double const *, double *, double *);
void math_pchip_integrate(int n, const double *x, double *y, double *d) {
  math_pchip_initialise(0, n, x, y, d);
  double I = 0.5 * (x[1] - x[0]) * (y[1] + y[0]);
  y[0] = 0.;
  int i;
  for (i = 1; i < n - 1; i++) {
    const double x0 = x[i];
    const double x1 = x[i + 1];
    const double dx = x1 - x0;
    const double p0 = y[i];
    const double p1 = y[i + 1];
    const double m0 = d[i] * dx;
    const double m1 = d[i + 1] * dx;
    const double a0 = p0;
    const double a1 = 0.5 * m0;
    const double a2 = -(3 * (p0 - p1) + 2 * m0 + m1) / 3.;
    const double a3 = 0.25 * (2 * (p0 - p1) + m0 + m1);
    y[i] = I;
    I += dx * (a0 + a1 + a2 + a3);
  }
  y[n - 1] = I;
}


x86 assembly (clang, -O0):
<math_pchip_integrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
xor    %edi,%edi
call   1030 <math_pchip_initialise@plt>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm1
movsd  0xea7(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
addsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    131c <math_pchip_integrate+0x20c>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xdc0(%rip),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x58(%rbp),%xmm0
movsd  0xdbc(%rip),%xmm1
mulsd  -0x60(%rbp),%xmm1
movsd  0xda7(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xd7b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x50(%rbp),%xmm1
subsd  -0x58(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
addsd  -0x68(%rbp),%xmm1
movsd  0xd46(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
addsd  -0x78(%rbp),%xmm2
addsd  -0x80(%rbp),%xmm2
addsd  -0x88(%rbp),%xmm2
ff
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1189 <math_pchip_integrate+0x79>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<math_pchip_integrate>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r12d
xor    %edi,%edi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <math_pchip_initialise@plt>
movsd  0x8(%rbx),%xmm2
subsd  (%rbx),%xmm2
mulsd  0xeb8(%rip),%xmm2
movsd  0x8(%r15),%xmm6
movsd  (%r15),%xmm0
addsd  %xmm6,%xmm0
mulsd  %xmm2,%xmm0
movq   $0x0,(%r15)
lea    -0x1(%r12),%eax
cmp    $0x3,%r12d
jl     1233 <math_pchip_integrate+0x123>
mov    %eax,%ecx
mov    $0x1,%edx
movsd  0xe7f(%rip),%xmm8
movsd  0xe7e(%rip),%xmm10
movsd  0xe7d(%rip),%xmm9
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x8(%rbx,%rdx,8),%xmm5
subsd  (%rbx,%rdx,8),%xmm5
movsd  0x8(%r15,%rdx,8),%xmm11
movsd  (%r14,%rdx,8),%xmm3
movsd  0x8(%r14,%rdx,8),%xmm7
movsd  %xmm0,(%r15,%rdx,8)
lea    0x1(%rdx),%rsi
mulsd  %xmm5,%xmm3
mulsd  %xmm5,%xmm7
movapd %xmm6,%xmm1
subsd  %xmm11,%xmm1
movapd %xmm3,%xmm2
movapd %xmm1,%xmm4
addsd  %xmm1,%xmm1
addsd  %xmm3,%xmm1
mulsd  %xmm8,%xmm3
addsd  %xmm2,%xmm2
mulsd  %xmm10,%xmm4
addsd  %xmm2,%xmm4
addsd  %xmm7,%xmm4
divsd  %xmm10,%xmm4
addsd  %xmm7,%xmm1
mulsd  %xmm9,%xmm1
addsd  %xmm6,%xmm3
subsd  %xmm4,%xmm3
addsd  %xmm1,%xmm3
mulsd  %xmm5,%xmm3
addsd  %xmm3,%xmm0
movapd %xmm11,%xmm6
mov    %rsi,%rdx
cmp    %rsi,%rcx
jne    11a0 <math_pchip_integrate+0x90>
cltq
movsd  %xmm0,(%r15,%rax,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @math_pchip_integrate(i32 %0, double* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%22 = load i32, i32* %5
%23 = load double*, double** %6
%24 = load double*, double** %7
%25 = load double*, double** %8
%26 = call i32 @math_pchip_initialise(i32 0, i32 %22, double* %23, double* %24, double* %25)
%27 = load double*, double** %6
%28 = getelementptr inbounds double, double* %27, i64 1
%29 = load double, double* %28
%30 = load double*, double** %6
%31 = getelementptr inbounds double, double* %30, i64 0
%32 = load double, double* %31
%33 = fsub double %29, %32
%34 = fmul double 5.000000e-01, %33
%35 = load double*, double** %7
%36 = getelementptr inbounds double, double* %35, i64 1
%37 = load double, double* %36
%38 = load double*, double** %7
%39 = getelementptr inbounds double, double* %38, i64 0
%40 = load double, double* %39
%41 = fadd double %37, %40
%42 = fmul double %34, %41
store double %42, double* %9
%43 = load double*, double** %7
%44 = getelementptr inbounds double, double* %43, i64 0
store double 0.000000e+00, double* %44
store i32 1, i32* %10
br label %45
45: ; preds = %127, %4
%46 = load i32, i32* %10
%47 = load i32, i32* %5
%48 = sub nsw i32 %47, 1
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %130
50: ; preds = %45
%51 = load double*, double** %6
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
%55 = load double, double* %54
store double %55, double* %11
%56 = load double*, double** %6
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %56, i64 %59
%61 = load double, double* %60
store double %61, double* %12
%62 = load double, double* %12
%63 = load double, double* %11
%64 = fsub double %62, %63
store double %64, double* %13
%65 = load double*, double** %7
%66 = load i32, i32* %10
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
%69 = load double, double* %68
store double %69, double* %14
%70 = load double*, double** %7
%71 = load i32, i32* %10
%72 = add nsw i32 %71, 1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %70, i64 %73
%75 = load double, double* %74
store double %75, double* %15
%76 = load double*, double** %8
%77 = load i32, i32* %10
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %76, i64 %78
%80 = load double, double* %79
%81 = load double, double* %13
%82 = fmul double %80, %81
store double %82, double* %16
%83 = load double*, double** %8
%84 = load i32, i32* %10
%85 = add nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %83, i64 %86
%88 = load double, double* %87
%89 = load double, double* %13
%90 = fmul double %88, %89
store double %90, double* %17
%91 = load double, double* %14
store double %91, double* %18
%92 = load double, double* %16
%93 = fmul double 5.000000e-01, %92
store double %93, double* %19
%94 = load double, double* %14
%95 = load double, double* %15
%96 = fsub double %94, %95
%97 = load double, double* %16
%98 = fmul double 2.000000e+00, %97
%99 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %96, double %98)
%100 = load double, double* %17
%101 = fadd double %99, %100
%102 = fneg double %101
%103 = fdiv double %102, 3.000000e+00
store double %103, double* %20
%104 = load double, double* %14
%105 = load double, double* %15
%106 = fsub double %104, %105
%107 = load double, double* %16
%108 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %106, double %107)
%109 = load double, double* %17
%110 = fadd double %108, %109
%111 = fmul double 2.500000e-01, %110
store double %111, double* %21
%112 = load double, double* %9
%113 = load double*, double** %7
%114 = load i32, i32* %10
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds double, double* %113, i64 %115
store double %112, double* %116
%117 = load double, double* %13
%118 = load double, double* %18
%119 = load double, double* %19
%120 = fadd double %118, %119
%121 = load double, double* %20
%122 = fadd double %120, %121
%123 = load double, double* %21
%124 = fadd double %122, %123
%125 = load double, double* %9
%126 = call double @llvm.fmuladd.f64(double %117, double %124, double %125)
store double %126, double* %9
br label %127
127: ; preds = %50
%128 = load i32, i32* %10
%129 = add nsw i32 %128, 1
store i32 %129, i32* %10
br label %45
130: ; preds = %45
%131 = load double, double* %9
%132 = load double*, double** %7
%133 = load i32, i32* %5
%134 = sub nsw i32 %133, 1
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds double, double* %132, i64 %135
store double %131, double* %136
ret void
}

LLVM IR (-O2):
define void @math_pchip_integrate(i32 %0, double* %1, double* %2, double* %3) {
%5 = tail call i32 @math_pchip_initialise(i32 0, i32 %0, double* %1, double* %2, double* %3)
%6 = getelementptr inbounds double, double* %1, i64 1
%7 = load double, double* %6
%8 = load double, double* %1
%9 = fsub double %7, %8
%10 = fmul double %9, 5.000000e-01
%11 = getelementptr inbounds double, double* %2, i64 1
%12 = load double, double* %11
%13 = load double, double* %2
%14 = fadd double %12, %13
%15 = fmul double %10, %14
store double 0.000000e+00, double* %2
%16 = add i32 %0, -1
%17 = icmp sgt i32 %0, 2
br i1 %17, label %18, label %53
18: ; preds = %4
%19 = zext i32 %16 to i64
br label %20
20: ; preds = %18, %20
%21 = phi double [ %12, %18 ], [ %32, %20 ]
%22 = phi i64 [ 1, %18 ], [ %26, %20 ]
%23 = phi double [ %15, %18 ], [ %51, %20 ]
%24 = getelementptr inbounds double, double* %1, i64 %22
%25 = load double, double* %24
%26 = add nuw nsw i64 %22, 1
%27 = getelementptr inbounds double, double* %1, i64 %26
%28 = load double, double* %27
%29 = fsub double %28, %25
%30 = getelementptr inbounds double, double* %2, i64 %22
%31 = getelementptr inbounds double, double* %2, i64 %26
%32 = load double, double* %31
%33 = getelementptr inbounds double, double* %3, i64 %22
%34 = load double, double* %33
%35 = fmul double %29, %34
%36 = getelementptr inbounds double, double* %3, i64 %26
%37 = load double, double* %36
%38 = fmul double %29, %37
%39 = fmul double %35, 5.000000e-01
%40 = fsub double %21, %32
%41 = fmul double %35, 2.000000e+00
%42 = tail call double @llvm.fmuladd.f64(double %40, double 3.000000e+00, double %41)
%43 = fadd double %38, %42
%44 = fdiv double %43, 3.000000e+00
%45 = tail call double @llvm.fmuladd.f64(double %40, double 2.000000e+00, double %35)
%46 = fadd double %45, %38
%47 = fmul double %46, 2.500000e-01
store double %23, double* %30
%48 = fadd double %21, %39
%49 = fsub double %48, %44
%50 = fadd double %47, %49
%51 = tail call double @llvm.fmuladd.f64(double %29, double %50, double %23)
%52 = icmp eq i64 %26, %19
br i1 %52, label %53, label %20
53: ; preds = %20, %4
%54 = phi double [ %15, %4 ], [ %51, %20 ]
%55 = sext i32 %16 to i64
%56 = getelementptr inbounds double, double* %2, i64 %55
store double %54, double* %56
ret void
}