#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 */
struct pumas_physics {
  int dummy;
};
struct pumas_context {
  int dummy;
};

/* Variables and functions */
double math_pchip_interpolate(double const, double const, double const,
                              double const, double const);
int table_index(struct pumas_physics const *, struct pumas_context *,
                double const *, double);
double table_interpolate_pchip(const struct pumas_physics *physics,
                               struct pumas_context *context,
                               const double *table_X, const double *table_Y,
                               const double *table_M, double x) {
  const int i1 = table_index(physics, context, table_X, x);
  const int i2 = i1 + 1;
  const double dX = table_X[i2] - table_X[i1];
  const double t = (x - table_X[i1]) / dX;
  const double m1 = table_M[i1] * dX;
  const double m2 = (i2 > 1) ? table_M[i2] * dX : m1;
  return math_pchip_interpolate(t, table_Y[i1], table_Y[i2], m1, m2);
}


x86 assembly (clang, -O0):
<table_interpolate_pchip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movsd  -0x30(%rbp),%xmm0
call   1040 <table_index@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
cmpl   $0x1,-0x38(%rbp)
jle    11db <table_interpolate_pchip+0xbb>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    11e5 <table_interpolate_pchip+0xc5>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x50(%rbp),%xmm3
movsd  -0x58(%rbp),%xmm4
call   1030 <math_pchip_interpolate@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<table_interpolate_pchip>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%rbx
movsd  %xmm0,0x8(%rsp)
call   1040 <table_index@plt>
movslq %eax,%rcx
lea    0x1(%rcx),%rax
movsd  (%rbx,%rcx,8),%xmm1
movsd  0x8(%rbx,%rcx,8),%xmm2
subsd  %xmm1,%xmm2
movsd  (%r15,%rcx,8),%xmm3
mulsd  %xmm2,%xmm3
movapd %xmm3,%xmm4
test   %ecx,%ecx
jle    116f <table_interpolate_pchip+0x4f>
movsd  (%r15,%rax,8),%xmm4
mulsd  %xmm2,%xmm4
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
movsd  (%r14,%rcx,8),%xmm1
movsd  (%r14,%rax,8),%xmm2
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <math_pchip_interpolate@plt>

LLVM IR (-O0):
%struct.pumas_physics = type { i32 }
%struct.pumas_context = type { i32 }
define double @table_interpolate_pchip(%struct.pumas_physics* %0, %struct.pumas_context* %1, double* %2, double* %3, double* %4, double %5) {
%7 = alloca %struct.pumas_physics*
%8 = alloca %struct.pumas_context*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store %struct.pumas_physics* %0, %struct.pumas_physics** %7
store %struct.pumas_context* %1, %struct.pumas_context** %8
store double* %2, double** %9
store double* %3, double** %10
store double* %4, double** %11
store double %5, double* %12
%19 = load %struct.pumas_physics*, %struct.pumas_physics** %7
%20 = load %struct.pumas_context*, %struct.pumas_context** %8
%21 = load double*, double** %9
%22 = load double, double* %12
%23 = call i32 @table_index(%struct.pumas_physics* %19, %struct.pumas_context* %20, double* %21, double %22)
store i32 %23, i32* %13
%24 = load i32, i32* %13
%25 = add nsw i32 %24, 1
store i32 %25, i32* %14
%26 = load double*, double** %9
%27 = load i32, i32* %14
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %9
%32 = load i32, i32* %13
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = fsub double %30, %35
store double %36, double* %15
%37 = load double, double* %12
%38 = load double*, double** %9
%39 = load i32, i32* %13
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = fsub double %37, %42
%44 = load double, double* %15
%45 = fdiv double %43, %44
store double %45, double* %16
%46 = load double*, double** %11
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double, double* %15
%52 = fmul double %50, %51
store double %52, double* %17
%53 = load i32, i32* %14
%54 = icmp sgt i32 %53, 1
br i1 %54, label %55, label %63
55: ; preds = %6
%56 = load double*, double** %11
%57 = load i32, i32* %14
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = load double, double* %15
%62 = fmul double %60, %61
br label %65
63: ; preds = %6
%64 = load double, double* %17
br label %65
65: ; preds = %63, %55
%66 = phi double [ %62, %55 ], [ %64, %63 ]
store double %66, double* %18
%67 = load double, double* %16
%68 = load double*, double** %10
%69 = load i32, i32* %13
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
%72 = load double, double* %71
%73 = load double*, double** %10
%74 = load i32, i32* %14
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
%77 = load double, double* %76
%78 = load double, double* %17
%79 = load double, double* %18
%80 = call double @math_pchip_interpolate(double %67, double %72, double %77, double %78, double %79)
ret double %80
}

LLVM IR (-O2):
%struct.pumas_physics = type { i32 }
%struct.pumas_context = type { i32 }
define double @table_interpolate_pchip(%struct.pumas_physics* %0, %struct.pumas_context* %1, double* %2, double* nocapture %3, double* nocapture %4, double %5) {
%7 = tail call i32 @table_index(%struct.pumas_physics* %0, %struct.pumas_context* %1, double* %2, double %5)
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds double, double* %2, i64 %9
%11 = load double, double* %10
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds double, double* %2, i64 %12
%14 = load double, double* %13
%15 = fsub double %11, %14
%16 = getelementptr inbounds double, double* %4, i64 %12
%17 = load double, double* %16
%18 = fmul double %17, %15
%19 = icmp sgt i32 %7, 0
br i1 %19, label %20, label %24
20: ; preds = %6
%21 = getelementptr inbounds double, double* %4, i64 %9
%22 = load double, double* %21
%23 = fmul double %15, %22
br label %24
24: ; preds = %6, %20
%25 = phi double [ %23, %20 ], [ %18, %6 ]
%26 = fsub double %5, %14
%27 = fdiv double %26, %15
%28 = getelementptr inbounds double, double* %3, i64 %12
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %3, i64 %9
%31 = load double, double* %30
%32 = tail call double @math_pchip_interpolate(double %27, double %29, double %31, double %18, double %25)
ret double %32
}