// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %rdx, 0x8(%rsp)
movq %rdi, %rbp
movq (%rsi), %r13
movq 0x8(%rsi), %r12
subq %r13, %r12
movq %r12, %r15
sarq $0x3, %r15
movl %r15d, 0x8(%rdi)
movq %rdi, (%rsp)
movq %r12, %rax
shlq $0x1d, %rax
movq %rax, %r14
sarq $0x1d, %r14
movq %rax, 0x18(%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, 0x30(%rsp)
shrq $0x3, %r12
movslq %r12d, %rax
movq %rax, 0x10(%rsp)
leaq (,%rax,8), %r14
testl %r15d, %r15d
movq $-0x1, %rax
cmovsq %rax, %r14
movq %r14, %rdi
callq 0x5030
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0x5030
movq %rax, %r12
movq %rax, 0x10(%rbp)
movq %r14, %rdi
callq 0x5030
movq %rax, 0x20(%rsp)
movq %rax, 0x18(%rbp)
movq %r14, %rdi
callq 0x5030
movq %rax, %rbp
movq (%rsp), %rax
movq %rbp, 0x20(%rax)
movq %r14, %rdi
callq 0x5030
movq 0x8(%rsp), %rdi
movq (%rsp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x2, %r15
jb 0x13b9d
movq (%rdi), %rcx
movl $0x1, %edx
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)
leaq 0x1(%rdx), %rsi
movq %rsi, %rdx
cmpq %rsi, %r15
jne 0x13b73
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
movq 0x18(%rsp), %rdx
addq %rcx, %rdx
sarq $0x20, %rdx
movq (%rdi), %rcx
movsd (%rcx,%rdx,8), %xmm0
movq 0x10(%rsp), %rdx
movsd %xmm0, -0x8(%r12,%rdx,8)
xorl %ecx, %ecx
movq %rcx, (%rbp)
movq %rcx, -0x8(%rbp,%rdx,8)
movq 0x30(%rsp), %r14
movq %rcx, (%r14)
movq 0x28(%rsp), %r13
movq %rcx, (%r13)
cmpl $0x2, %r15d
jl 0x13ca5
movl %r15d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movsd (%r13), %xmm2
movsd (%r14), %xmm3
movl $0x1, %edx
movsd 0x26692(%rip), %xmm0    # 0x3a2a0
movsd 0x26692(%rip), %xmm1    # 0x3a2a8
movsd -0x8(%rbx,%rdx,8), %xmm5
movsd (%rbx,%rdx,8), %xmm6
mulsd %xmm6, %xmm3
movapd %xmm6, %xmm4
movapd %xmm0, %xmm7
divsd %xmm6, %xmm7
mulsd %xmm6, %xmm2
addsd %xmm5, %xmm6
addsd %xmm6, %xmm6
addsd %xmm6, %xmm3
divsd %xmm3, %xmm4
movsd %xmm4, (%r14,%rdx,8)
movsd (%r12,%rdx,8), %xmm3
movsd 0x8(%r12,%rdx,8), %xmm8
subsd %xmm3, %xmm8
mulsd %xmm7, %xmm8
subsd -0x8(%r12,%rdx,8), %xmm3
movapd %xmm1, %xmm7
divsd %xmm5, %xmm7
mulsd %xmm3, %xmm7
addsd %xmm8, %xmm7
addsd %xmm2, %xmm7
addsd %xmm6, %xmm2
divsd %xmm2, %xmm7
movsd %xmm7, (%r13,%rdx,8)
leaq 0x1(%rdx), %rsi
movapd %xmm4, %xmm3
movapd %xmm7, %xmm2
movq %rsi, %rdx
cmpq %rsi, %rcx
jne 0x13c16
cmpl $0x3, %r15d
jl 0x13cd5
leal -0x2(%r15), %ecx
movsd 0x8(%rbp,%rcx,8), %xmm0
incq %rcx
mulsd -0x8(%r14,%rcx,8), %xmm0
addsd -0x8(%r13,%rcx,8), %xmm0
movsd %xmm0, -0x8(%rbp,%rcx,8)
decq %rcx
cmpq $0x1, %rcx
jg 0x13cb8
testl %r15d, %r15d
movq 0x20(%rsp), %rsi
jle 0x13d50
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movsd 0x265b8(%rip), %xmm0    # 0x3a2a8
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)
leaq 0x1(%rcx), %rdx
movq %rdx, %rcx
cmpq %rdx, %r15
jne 0x13cf0
movq %rbx, %rdi
callq 0x5410
movq %r14, %rdi
callq 0x5410
movq %r13, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5410