// File: /workspace/github_cpp_makefile_star2_O2/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, 0x28(%rsp)
movq %rdi, 0x8(%rsp)
movq (%rsi), %r13
movq 0x8(%rsi), %r12
subq %r13, %r12
movq %r12, %r15
sarq $0x3, %r15
movl %r15d, 0x8(%rdi)
movq %r15, 0x18(%rsp)
movq %r12, %rax
shlq $0x1d, %rax
movq %rax, %r14
sarq $0x1d, %r14
movq %rax, 0x30(%rsp)
testq %rax, %rax
pushq $-0x1
popq %rax
cmovsq %rax, %r14
movq %rax, %rbp
movq %r14, %rdi
callq 0x5030
movq %rax, %rbx
movq %r14, %rdi
callq 0x5030
movq %rax, %r14
shrq $0x3, %r12
movq %r12, 0x38(%rsp)
movslq %r12d, %rax
movq %rax, 0x20(%rsp)
leaq (,%rax,8), %r12
testl %r15d, %r15d
cmovsq %rbp, %r12
movq %r12, %rdi
callq 0x5030
movq %rax, %r15
movq %r12, %rdi
movq %r12, %rbp
movq %r12, 0x10(%rsp)
callq 0x5030
movq %rax, %r12
movq 0x8(%rsp), %rax
movq %r12, 0x10(%rax)
movq %rbp, %rdi
callq 0x5030
movq %rax, 0x40(%rsp)
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rcx)
movq %rbp, %rdi
callq 0x5030
movq %rax, %rbp
movq 0x8(%rsp), %rax
movq %rbp, 0x20(%rax)
movq 0x10(%rsp), %rdi
callq 0x5030
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rcx
movq %rax, 0x28(%rcx)
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
pushq $0x1
popq %rdx
cmpq %rdx, %rsi
jbe 0xf898
movsd 0x8(%r13,%rdx,8), %xmm0
subsd (%r13,%rdx,8), %xmm0
movsd %xmm0, (%rbx,%rdx,8)
movsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%r12,%rdx,8)
incq %rdx
jmp 0xf870
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
movq 0x30(%rsp), %rdi
addq %rdx, %rdi
sarq $0x20, %rdi
movsd (%rcx,%rdi,8), %xmm0
andq $0x0, (%rbp)
movq 0x20(%rsp), %rcx
andq $0x0, -0x8(%rbp,%rcx,8)
movsd %xmm0, -0x8(%r12,%rcx,8)
andq $0x0, (%r14)
andq $0x0, (%r15)
movslq 0x38(%rsp), %rcx
xorpd %xmm2, %xmm2
pushq $0x1
popq %rdx
movsd 0x21b52(%rip), %xmm1    # 0x31438
movsd 0x21b42(%rip), %xmm0    # 0x31430
cmpq %rcx, %rdx
jge 0xf987
movsd (%rbx,%rdx,8), %xmm3
movapd %xmm3, %xmm4
addsd %xmm5, %xmm4
movapd %xmm1, %xmm6
divsd %xmm3, %xmm6
movsd (%r12,%rdx,8), %xmm7
movsd 0x8(%r12,%rdx,8), %xmm8
subsd %xmm7, %xmm8
mulsd %xmm6, %xmm8
subsd -0x8(%r12,%rdx,8), %xmm7
movapd %xmm0, %xmm6
divsd %xmm5, %xmm6
mulsd %xmm7, %xmm6
addsd %xmm8, %xmm6
movapd %xmm2, %xmm5
unpckhpd %xmm2, %xmm5            # xmm5 = xmm5[1],xmm2[1]
mulsd %xmm3, %xmm5
addsd %xmm6, %xmm5
movapd %xmm3, %xmm6
unpcklpd %xmm3, %xmm6            # xmm6 = xmm6[0],xmm3[0]
mulpd %xmm2, %xmm6
addsd %xmm4, %xmm4
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
addpd %xmm6, %xmm4
movapd %xmm3, %xmm2
unpcklpd %xmm5, %xmm2            # xmm2 = xmm2[0],xmm5[0]
divpd %xmm4, %xmm2
movlpd %xmm2, (%r14,%rdx,8)
movhpd %xmm2, (%r15,%rdx,8)
incq %rdx
movapd %xmm3, %xmm5
jmp 0xf8ee
movl %esi, %ecx
addl $-0x2, %ecx
testl %ecx, %ecx
jle 0xf9ad
movsd (%r14,%rcx,8), %xmm1
mulsd 0x8(%rbp,%rcx,8), %xmm1
addsd (%r15,%rcx,8), %xmm1
movsd %xmm1, (%rbp,%rcx,8)
decq %rcx
jmp 0xf98c
xorl %ecx, %ecx
testl %esi, %esi
movl $0x0, %edx
cmovgl %esi, %edx
movq 0x40(%rsp), %rsi
cmpq %rcx, %rdx
je 0xfa1c
movsd 0x8(%r12,%rcx,8), %xmm1
subsd (%r12,%rcx,8), %xmm1
movsd (%rbx,%rcx,8), %xmm2
divsd %xmm2, %xmm1
movsd (%rbp,%rcx,8), %xmm3
movsd 0x8(%rbp,%rcx,8), %xmm4
movapd %xmm3, %xmm5
addsd %xmm3, %xmm5
addsd %xmm4, %xmm5
movapd %xmm2, %xmm6
divsd %xmm0, %xmm6
mulsd %xmm5, %xmm6
addsd %xmm1, %xmm6
movsd %xmm6, (%rsi,%rcx,8)
mulsd %xmm0, %xmm2
divsd %xmm2, %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, (%rax,%rcx,8)
incq %rcx
jmp 0xf9be
movq %rbx, %rdi
callq 0x53e0
movq %r14, %rdi
callq 0x53e0
movq %r15, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x53e0