// File: /workspace/github_cpp_makefile_star2_O3/fanyazhi[P]Spline-Fitting/src/cubicSpline.cpp
// Function: splineDerivative(int, std::vector<double, std::allocator<double>>, std::vector<double, std::allocator<double>>)
vector<double> splineDerivative(int d, vector<double> x, vector<double> y) {
    //solve a[][]k[] = b[] to find frst derivatives
    vector<double> k(d);
    CRSmatrix a(d, d);
    vector<double> b(d);

    //first row
    a.changeValue(2.0 / (x[1] - x[0]), 0, 0);
    a.changeValue(1.0 / (x[1] - x[0]), 0, 1);
    b[0] = 3.0 * (y[1] - y[0]) / pow((x[1] - x[0]), 2);

    //middle rows
    for (int i = 1; i < d - 1; i++) {
        a.changeValue(1.0 / (x[i] - x[i - 1]), i, i - 1);
        a.changeValue(2.0 * (1 / (x[i] - x[i - 1]) + 1 / (x[i + 1] - x[i])), i, i);
        a.changeValue(1.0 / (x[i + 1] - x[i]), i, i + 1);
        b[i] = 3.0 * (((y[i] - y[i - 1]) / pow((x[i] - x[i - 1]), 2)) + ((y[i + 1] - y[i]) / pow((x[i + 1] - x[i]), 2)));
    }

    //last row
    a.changeValue(1.0 / (x[d - 1] - x[d - 2]), d - 1, d - 1);
    a.changeValue(2.0 / (x[d - 1] - x[d - 2]), d - 1, d - 2);
    b[d - 1] = 3.0 * (y[d - 1] - y[d - 2]) / pow((x[d - 1] - x[d - 2]), 2);

    k = Jacobi(a, b);

    return k;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rcx, %r12
movq %rdx, %r15
movl %esi, %ebx
movslq %esi, %r14
leaq 0x68(%rsp), %rdx
movq %rdi, 0x8(%rsp)
movq %r14, %rsi
callq 0x3d90
leaq 0x68(%rsp), %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x2b04
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %r14, %rsi
callq 0x3d90
movq (%r15), %rax
movsd 0x8(%rax), %xmm1
subsd (%rax), %xmm1
movsd 0x1c96(%rip), %xmm0     # 0x60d0
divsd %xmm1, %xmm0
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b8c
movq (%r15), %rax
movsd 0x8(%rax), %xmm1
subsd (%rax), %xmm1
movsd 0x1ba8(%rip), %xmm0     # 0x6008
divsd %xmm1, %xmm0
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x2b8c
movq %r14, 0x48(%rsp)
movq (%r12), %rax
movsd 0x8(%rax), %xmm0
subsd (%rax), %xmm0
mulsd 0x1c49(%rip), %xmm0     # 0x60d8
movq (%r15), %rax
movsd 0x8(%rax), %xmm1
subsd (%rax), %xmm1
mulsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movq 0x18(%rsp), %rcx
movsd %xmm0, (%rcx)
leal -0x1(%rbx), %ecx
cmpl $0x3, %ebx
movl %ecx, 0x14(%rsp)
jl 0x45b6
movl %ecx, %r14d
decq %r14
xorl %ebx, %ebx
leaq 0x68(%rsp), %r13
leaq 0x1(%rbx), %rbp
movsd 0x8(%rax,%rbx,8), %xmm1
subsd (%rax,%rbx,8), %xmm1
movsd 0x1b28(%rip), %xmm0     # 0x6008
divsd %xmm1, %xmm0
movq %r13, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x2b8c
movq (%r15), %rax
movupd 0x8(%rax,%rbx,8), %xmm0
movsd (%rax,%rbx,8), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
subpd %xmm1, %xmm0
movapd 0x1be2(%rip), %xmm1     # 0x60f0
divpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
movq %r13, %rdi
movl %ebp, %esi
movl %ebp, %edx
callq 0x2b8c
leal 0x2(%rbx), %edx
movq (%r15), %rax
movsd 0x10(%rax,%rbx,8), %xmm1
subsd 0x8(%rax,%rbx,8), %xmm1
movsd 0x1ac0(%rip), %xmm0     # 0x6008
divsd %xmm1, %xmm0
movq %r13, %rdi
movl %ebp, %esi
callq 0x2b8c
movq (%r12), %rcx
movq (%r15), %rax
movupd 0x8(%rcx,%rbx,8), %xmm0
movsd (%rcx,%rbx,8), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
subpd %xmm1, %xmm0
movupd 0x8(%rax,%rbx,8), %xmm1
movsd (%rax,%rbx,8), %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
subpd %xmm2, %xmm1
mulpd %xmm1, %xmm1
divpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x1b39(%rip), %xmm1     # 0x60d8
movq 0x18(%rsp), %rcx
movsd %xmm1, 0x8(%rcx,%rbx,8)
movq %rbp, %rbx
cmpq %rbp, %r14
jne 0x44c9
movl 0x14(%rsp), %ebp
movslq %ebp, %rbx
movsd (%rax,%rbx,8), %xmm1
movq 0x48(%rsp), %r14
subsd -0x10(%rax,%r14,8), %xmm1
movsd 0x1a32(%rip), %xmm0     # 0x6008
divsd %xmm1, %xmm0
leaq 0x68(%rsp), %rdi
movl %ebp, %esi
movl %ebp, %edx
callq 0x2b8c
addq $-0x2, %r14
movq (%r15), %rax
movsd (%rax,%rbx,8), %xmm1
subsd (%rax,%r14,8), %xmm1
movsd 0x1ace(%rip), %xmm0     # 0x60d0
divsd %xmm1, %xmm0
leaq 0x68(%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2b8c
movq (%r12), %rax
movsd (%rax,%rbx,8), %xmm0
subsd (%rax,%r14,8), %xmm0
mulsd 0x1aac(%rip), %xmm0     # 0x60d8
movq (%r15), %rax
movsd (%rax,%rbx,8), %xmm1
subsd (%rax,%r14,8), %xmm1
mulsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movq 0x18(%rsp), %rax
movsd %xmm0, (%rax,%rbx,8)
leaq 0x70(%rsp), %rsi
movq -0x8(%rsi), %rax
leaq 0xc0(%rsp), %rdi
movq %rax, -0x8(%rdi)
callq 0x3e1e
leaq 0xd8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
movq 0x8(%rsp), %rbx
callq 0x3ee4
leaq 0xf0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x3ee4
leaq 0x50(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3e1e
leaq 0x30(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x3047
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rbx)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x4708
subq %rdi, %rsi
callq 0x2190
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4708
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x471f
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x473c
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x4759
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x4776
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x478d
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x47aa
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x47c7
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x47e1
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4815
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x4815
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0x3e9e
jmp 0x4879
movq %rax, %r14
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x4849
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x4849
movq %rax, %r14
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x4879
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x4879
jmp 0x4876
movq %rax, %r14
jmp 0x4890
movq %rax, %r14
jmp 0x489a
jmp 0x4876
movq %rax, %r14
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x4890
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x68(%rsp), %rdi
callq 0x3e9e
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x48b8
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2190
movq %r14, %rdi
callq 0x2270