// File: /workspace/github_cpp_makefile_star2_O2/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 $0xf8, %rsp
movq %rcx, %r12
movq %rdx, %r15
movl %esi, %ebx
movslq %esi, %r14
leaq 0x58(%rsp), %rdx
movq %rdi, (%rsp)
movq %r14, %rsi
callq 0x3336
leaq 0x58(%rsp), %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x27f4
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r14, %rsi
callq 0x3336
movq (%r15), %rax
movsd 0x8(%rax), %xmm1
subsd (%rax), %xmm1
movsd 0x13ef(%rip), %xmm0     # 0x50c0
divsd %xmm1, %xmm0
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2866
movq (%r15), %rax
movsd 0x8(%rax), %xmm1
subsd (%rax), %xmm1
movsd 0x1319(%rip), %xmm0     # 0x5010
divsd %xmm1, %xmm0
leaq 0x58(%rsp), %rdi
pushq $0x1
popq %rdx
xorl %esi, %esi
callq 0x2866
movq %r14, 0x20(%rsp)
movq (%r12), %rax
movsd 0x8(%rax), %xmm0
subsd (%rax), %xmm0
mulsd 0x13a4(%rip), %xmm0     # 0x50c8
movq (%r15), %rax
movsd 0x8(%rax), %xmm1
subsd (%rax), %xmm1
mulsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movq 0x8(%rsp), %rcx
movsd %xmm0, (%rcx)
decl %ebx
movslq %ebx, %r13
xorl %ebp, %ebp
leaq 0x58(%rsp), %rbx
leaq 0x1(%rbp), %r14
cmpq %r13, %r14
jge 0x3e43
movsd 0x8(%rax,%rbp,8), %xmm1
subsd (%rax,%rbp,8), %xmm1
movsd 0x12a3(%rip), %xmm0     # 0x5010
divsd %xmm1, %xmm0
movq %rbx, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x2866
movq (%r15), %rax
movupd 0x8(%rax,%rbp,8), %xmm0
movsd (%rax,%rbp,8), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
subpd %xmm1, %xmm0
movapd 0x1344(%rip), %xmm1     # 0x50e0
divpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
movq %rbx, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x2866
leal 0x2(%rbp), %edx
movq (%r15), %rax
movsd 0x10(%rax,%rbp,8), %xmm1
subsd 0x8(%rax,%rbp,8), %xmm1
movsd 0x1238(%rip), %xmm0     # 0x5010
divsd %xmm1, %xmm0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2866
movq (%r12), %rcx
movq (%r15), %rax
movupd 0x8(%rcx,%rbp,8), %xmm0
movsd (%rcx,%rbp,8), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
subpd %xmm1, %xmm0
movupd 0x8(%rax,%rbp,8), %xmm1
movsd (%rax,%rbp,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 0x1298(%rip), %xmm1     # 0x50c8
movq 0x8(%rsp), %rcx
movsd %xmm1, 0x8(%rcx,%rbp,8)
movq %r14, %rbp
jmp 0x3d4d
movsd (%rax,%r13,8), %xmm1
movq 0x20(%rsp), %rbx
subsd -0x10(%rax,%rbx,8), %xmm1
movsd 0x11b4(%rip), %xmm0     # 0x5010
divsd %xmm1, %xmm0
leaq 0x58(%rsp), %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x2866
addq $-0x2, %rbx
movq (%r15), %rax
movsd (%rax,%r13,8), %xmm1
subsd (%rax,%rbx,8), %xmm1
movsd 0x1236(%rip), %xmm0     # 0x50c0
divsd %xmm1, %xmm0
leaq 0x58(%rsp), %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x2866
movq (%r12), %rax
movsd (%rax,%r13,8), %xmm0
subsd (%rax,%rbx,8), %xmm0
mulsd 0x1214(%rip), %xmm0     # 0x50c8
movq (%r15), %rax
movsd (%rax,%r13,8), %xmm1
subsd (%rax,%rbx,8), %xmm1
mulsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movq 0x8(%rsp), %rax
movsd %xmm0, (%rax,%r13,8)
leaq 0xa8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x33fc
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3470
leaq 0x40(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x2b1d
leaq 0x40(%rsp), %rbx
movq (%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3b9a
movq %rbx, %rdi
callq 0x3692
leaq 0x28(%rsp), %rdi
callq 0x3692
leaq 0xa8(%rsp), %rdi
callq 0x34be
leaq 0x8(%rsp), %rdi
callq 0x3692
leaq 0x58(%rsp), %rdi
callq 0x34be
movq %r14, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3692
jmp 0x3f7b
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x34be
jmp 0x3f9b
jmp 0x3f98
movq %rax, %rbx
jmp 0x3fa5
movq %rax, %rbx
jmp 0x3faf
jmp 0x3f98
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3692
leaq 0x58(%rsp), %rdi
callq 0x34be
movq (%rsp), %rdi
callq 0x3692
movq %rbx, %rdi
callq 0x2220