// File: sus304[P]ForRocket/src/interpolate.cpp
// Function: forrocket::interpolate::CubicSpline1D::SolveSplineCoefficient(std::vector<double, std::allocator<double>> const&, std::vector<double, std::allocator<double>> const&)
void forrocket::interpolate::CubicSpline1D::SolveSplineCoefficient(const std::vector<double>& x, const std::vector<double>& y) {
    // Tri-Diagonal Matrix Algorithm
    array_size = x.size();
    double* h_spline = new double[array_size];
    double* P_tdma = new double[array_size];
    double* Q_tdma = new double[array_size];

    a_spline = new double[array_size];
    b_spline = new double[array_size];
    c_spline = new double[array_size];
    d_spline = new double[array_size];

    for (int i=1; i < x.size(); ++i) {
        h_spline[i] = x[i+1] - x[i];
        a_spline[i] = y[i];
    }
    a_spline[array_size-1] = y[array_size-1];
    c_spline[0] = 0.0;
    c_spline[array_size-1] = 0.0;

    P_tdma[0] = 0.0;
    Q_tdma[0] = 0.0;
    for (int i=1; i < array_size; ++i) { 
        P_tdma[i] = h_spline[i] / (2.0 * (h_spline[i] + h_spline[i-1]) + h_spline[i] * P_tdma[i-1]);
        double d_tdma = (3.0 / h_spline[i]) * (a_spline[i+1] - a_spline[i]) - (3.0 / h_spline[i-1]) * (a_spline[i] - a_spline[i-1]);
        Q_tdma[i] = (d_tdma + h_spline[i] * Q_tdma[i-1]) / (2.0 * (h_spline[i] + h_spline[i-1]) + h_spline[i] * Q_tdma[i-1]);
    }
    for (int i=array_size-2; i > 0; --i) {
        c_spline[i] = P_tdma[i] * c_spline[i+1] + Q_tdma[i];
    }
    for (int i=0; i < array_size; ++i) {
        b_spline[i] = (a_spline[i+1] - a_spline[i]) / h_spline[i] - h_spline[i] / 3.0 * (c_spline[i+1] + 2.0 * c_spline[i]);
        d_spline[i] = (c_spline[i+1] - c_spline[i] / (3.0 * h_spline[i]));
    }

    delete[] h_spline;
    delete[] P_tdma;
    delete[] Q_tdma;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x86e0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl %ecx, 0x8(%rax)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x6040
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x20(%rbp)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x6040
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x28(%rbp)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x6040
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x30(%rbp)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x6040
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x10(%rax)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x6040
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x18(%rax)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x6040
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x20(%rax)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x6040
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x28(%rax)
movl $0x1, -0x34(%rbp)
movslq -0x34(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x86e0
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jae 0x27117
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x27ce0
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x27ce0
movsd -0x60(%rbp), %xmm0
subsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x27ce0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movsd (%rcx), %xmm0
movq 0x10(%rax), %rax
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x27089
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rdi
movl 0x8(%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x27ce0
movq -0x50(%rbp), %rcx
movsd (%rax), %xmm0
movq 0x10(%rcx), %rax
movl 0x8(%rcx), %edx
subl $0x1, %edx
movslq %edx, %rdx
movsd %xmm0, (%rax,%rdx,8)
movq 0x20(%rcx), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq 0x20(%rcx), %rax
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x1, -0x38(%rbp)
movq -0x50(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x27322
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq -0x20(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm1
movq -0x20(%rbp), %rcx
movl -0x38(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
addsd (%rcx,%rdx,8), %xmm1
movq -0x20(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm2
movq -0x28(%rbp), %rcx
movl -0x38(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
mulsd (%rcx,%rdx,8), %xmm2
addsd %xmm1, %xmm1
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movsd %xmm0, (%rcx,%rdx,8)
movq -0x20(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movsd 0x6de54(%rip), %xmm0    # 0x95060
divsd (%rcx,%rdx,8), %xmm0
movq 0x10(%rax), %rcx
movl -0x38(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsd (%rcx,%rdx,8), %xmm2
movq 0x10(%rax), %rcx
movslq -0x38(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm2
movq -0x20(%rbp), %rcx
movl -0x38(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movsd 0x6de1b(%rip), %xmm1    # 0x95060
divsd (%rcx,%rdx,8), %xmm1
movq 0x10(%rax), %rcx
movslq -0x38(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm3
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
subsd (%rax,%rcx,8), %xmm3
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm1
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x20(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addsd (%rax,%rcx,8), %xmm1
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
mulsd (%rax,%rcx,8), %xmm2
addsd %xmm1, %xmm1
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x27184
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x2, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0x27385
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x44(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x20(%rax), %rcx
movl -0x44(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsd (%rcx,%rdx,8), %xmm2
movq -0x30(%rbp), %rcx
movslq -0x44(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2732f
movl $0x0, -0x48(%rbp)
movq -0x50(%rbp), %rcx
movl -0x48(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x2748f
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rcx
movl -0x48(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsd (%rcx,%rdx,8), %xmm1
movq 0x10(%rax), %rcx
movslq -0x48(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm1
movq -0x20(%rbp), %rcx
movslq -0x48(%rbp), %rdx
divsd (%rcx,%rdx,8), %xmm1
movq -0x20(%rbp), %rcx
movslq -0x48(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movsd 0x6dc7f(%rip), %xmm2    # 0x95060
divsd %xmm2, %xmm0
movq 0x20(%rax), %rcx
movl -0x48(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsd (%rcx,%rdx,8), %xmm3
movq 0x20(%rax), %rcx
movslq -0x48(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm2
addsd %xmm2, %xmm2
addsd %xmm3, %xmm2
movq %xmm0, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x18(%rax), %rcx
movslq -0x48(%rbp), %rdx
movsd %xmm0, (%rcx,%rdx,8)
movq 0x20(%rax), %rcx
movl -0x48(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x20(%rax), %rcx
movslq -0x48(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm1
movq -0x20(%rbp), %rcx
movslq -0x48(%rbp), %rdx
movsd 0x6dbf9(%rip), %xmm2    # 0x95060
mulsd (%rcx,%rdx,8), %xmm2
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movq 0x28(%rax), %rax
movslq -0x48(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2738c
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x274a6
movq -0x68(%rbp), %rdi
callq 0x6560
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
je 0x274bd
movq -0x70(%rbp), %rdi
callq 0x6560
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x274d4
movq -0x78(%rbp), %rdi
callq 0x6560
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)