// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
movq (%rsi), %r15
movq 0x8(%rsi), %r12
subq %r15, %r12
movq %r12, %rbp
sarq $0x3, %rbp
movl %ebp, 0x8(%rdi)
movq %rbp, 0x8(%rsp)
movq %r12, %rax
shlq $0x1d, %rax
movq %rax, %r14
sarq $0x1d, %r14
movq %rax, 0x30(%rsp)
testq %rax, %rax
movq $-0x1, %rax
cmovsq %rax, %r14
movq %r14, %rdi
callq 0x5030
movq %rax, %rbx
movq %r14, %rdi
callq 0x5030
movq %rax, 0x40(%rsp)
shrq $0x3, %r12
movslq %r12d, %rax
movq %rax, 0x28(%rsp)
leaq (,%rax,8), %r13
testl %ebp, %ebp
movq $-0x1, %rax
cmovsq %rax, %r13
movq %r13, %rdi
callq 0x5030
movq %rax, 0x18(%rsp)
movq %r13, %rdi
callq 0x5030
movq %rax, %r12
movq 0x10(%rsp), %r14
movq %rax, 0x10(%r14)
movq %r13, %rdi
callq 0x5030
movq %rax, 0x38(%rsp)
movq %rax, 0x18(%r14)
movq %r13, %rdi
callq 0x5030
movq %rax, %rbp
movq %rax, 0x20(%r14)
movq %r13, %rdi
callq 0x5030
movq 0x8(%rsp), %rdi
movq %rax, 0x28(%r14)
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
cmpq $0x2, %rdi
jb 0x1391b
movsd 0x8(%r15), %xmm0
leaq -0x1(%rdi), %rdx
xorl %esi, %esi
movsd 0x10(%r15,%rsi,8), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rbx,%rsi,8)
movsd 0x8(%rcx,%rsi,8), %xmm0
movsd %xmm0, 0x8(%r12,%rsi,8)
incq %rsi
movapd %xmm1, %xmm0
cmpq %rsi, %rdx
jne 0x138ed
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
movq 0x30(%rsp), %rsi
addq %rdx, %rsi
sarq $0x20, %rsi
movsd (%rcx,%rsi,8), %xmm0
movq 0x28(%rsp), %rdx
movsd %xmm0, -0x8(%r12,%rdx,8)
xorl %ecx, %ecx
movq %rcx, (%rbp)
movq %rcx, -0x8(%rbp,%rdx,8)
movq 0x40(%rsp), %r15
movq %rcx, (%r15)
movq 0x18(%rsp), %r14
movq %rcx, (%r14)
cmpl $0x2, %edi
movq 0x38(%rsp), %rsi
jl 0x13a60
movl %edi, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movsd 0x8(%r12), %xmm5
decq %rcx
xorpd %xmm2, %xmm2
xorl %edx, %edx
movsd 0x26915(%rip), %xmm0    # 0x3a2a0
movsd 0x26915(%rip), %xmm1    # 0x3a2a8
movsd 0x8(%rbx,%rdx,8), %xmm3
movapd %xmm3, %xmm6
addsd %xmm7, %xmm6
movapd %xmm0, %xmm8
divsd %xmm3, %xmm8
movsd 0x10(%r12,%rdx,8), %xmm4
movapd %xmm4, %xmm9
subsd %xmm5, %xmm9
subsd (%r12,%rdx,8), %xmm5
mulsd %xmm8, %xmm9
movapd %xmm1, %xmm8
divsd %xmm7, %xmm8
mulsd %xmm5, %xmm8
addsd %xmm9, %xmm8
movapd %xmm2, %xmm5
unpckhpd %xmm2, %xmm5            # xmm5 = xmm5[1],xmm2[1]
mulsd %xmm3, %xmm5
addsd %xmm8, %xmm5
movapd %xmm3, %xmm7
unpcklpd %xmm3, %xmm7            # xmm7 = xmm7[0],xmm3[0]
mulpd %xmm2, %xmm7
addsd %xmm6, %xmm6
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
addpd %xmm7, %xmm6
movapd %xmm3, %xmm2
unpcklpd %xmm5, %xmm2            # xmm2 = xmm2[0],xmm5[0]
divpd %xmm6, %xmm2
movlpd %xmm2, 0x8(%r15,%rdx,8)
movhpd %xmm2, 0x8(%r14,%rdx,8)
incq %rdx
movapd %xmm4, %xmm5
movapd %xmm3, %xmm7
cmpq %rdx, %rcx
jne 0x13993
cmpl $0x2, %edi
je 0x13a60
leal -0x2(%rdi), %ecx
movsd 0x8(%rbp,%rcx,8), %xmm0
incq %rcx
mulsd -0x8(%r15,%rcx,8), %xmm0
addsd -0x8(%r14,%rcx,8), %xmm0
movsd %xmm0, -0x8(%rbp,%rcx,8)
decq %rcx
cmpq $0x1, %rcx
ja 0x13a43
testl %edi, %edi
jle 0x13ae3
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movsd (%r12), %xmm2
movsd (%rbp), %xmm1
xorl %ecx, %ecx
movsd 0x26829(%rip), %xmm0    # 0x3a2a8
movsd 0x8(%r12,%rcx,8), %xmm3
movapd %xmm3, %xmm4
subsd %xmm2, %xmm4
movsd (%rbx,%rcx,8), %xmm2
divsd %xmm2, %xmm4
movsd 0x8(%rbp,%rcx,8), %xmm5
movapd %xmm1, %xmm6
addsd %xmm1, %xmm6
addsd %xmm5, %xmm6
movapd %xmm2, %xmm7
divsd %xmm0, %xmm7
mulsd %xmm6, %xmm7
addsd %xmm4, %xmm7
movsd %xmm7, (%rsi,%rcx,8)
mulsd %xmm0, %xmm2
divsd %xmm2, %xmm1
addsd %xmm5, %xmm1
movsd %xmm1, (%rax,%rcx,8)
leaq 0x1(%rcx), %rdx
movapd %xmm5, %xmm1
movapd %xmm3, %xmm2
movq %rdx, %rcx
cmpq %rdx, %rdi
jne 0x13a7f
movq %rbx, %rdi
callq 0x5410
movq %r15, %rdi
callq 0x5410
movq %r14, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5410
nop