// File: 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
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rcx, -0x158(%rbp)
movq %rdx, -0x150(%rbp)
movq %rdi, -0x140(%rbp)
movq %rdi, %rax
movq %rax, -0x148(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x22(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x4a00
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rsi
movq -0x130(%rbp), %rdx
callq 0x4a20
jmp 0x8b24
leaq -0x22(%rbp), %rdi
callq 0x4a90
movl -0xc(%rbp), %edx
leaq -0x88(%rbp), %rdi
movl %edx, %esi
callq 0x2c90
jmp 0x8b40
movslq -0xc(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x4a00
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x4a20
jmp 0x8b7a
leaq -0xa1(%rbp), %rdi
callq 0x4a90
movq -0x150(%rbp), %rdi
movl $0x1, %esi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x178(%rbp)
xorl %eax, %eax
movl %eax, -0x16c(%rbp)
movl %eax, %esi
callq 0x4950
movsd -0x178(%rbp), %xmm1
movl -0x16c(%rbp), %edx
movsd (%rax), %xmm0
subsd %xmm0, %xmm1
movsd 0x3431(%rip), %xmm0     # 0xc008
divsd %xmm1, %xmm0
leaq -0x88(%rbp), %rdi
movl %edx, %esi
callq 0x2e30
jmp 0x8beb
movq -0x150(%rbp), %rdi
movl $0x1, %esi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x188(%rbp)
xorl %eax, %eax
movl %eax, -0x17c(%rbp)
movl %eax, %esi
callq 0x4950
movsd -0x188(%rbp), %xmm1
movl -0x17c(%rbp), %esi
movsd (%rax), %xmm0
subsd %xmm0, %xmm1
movsd 0x33e4(%rip), %xmm0     # 0xc020
divsd %xmm1, %xmm0
leaq -0x88(%rbp), %rdi
movl $0x1, %edx
callq 0x2e30
jmp 0x8c53
movq -0x158(%rbp), %rdi
movl $0x1, %esi
movq %rsi, -0x1b0(%rbp)
callq 0x4950
movq -0x158(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1b8(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x1a0(%rbp)
callq 0x4950
movsd -0x1b8(%rbp), %xmm0
movq -0x1b0(%rbp), %rsi
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd 0x3404(%rip), %xmm1     # 0xc0b8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x1a8(%rbp)
callq 0x4950
movq -0x150(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
movsd (%rax), %xmm0
movsd %xmm0, -0x198(%rbp)
callq 0x4950
movsd -0x198(%rbp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movl $0x2, %edi
callq 0xa0e0
movsd %xmm0, -0x190(%rbp)
jmp 0x8d08
movsd -0x190(%rbp), %xmm1
movsd -0x1a8(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x1c0(%rbp)
leaq -0xa0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4950
movsd -0x1c0(%rbp), %xmm0
movsd %xmm0, (%rax)
movl $0x1, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x9138
movq -0x150(%rbp), %rdi
movslq -0xa8(%rbp), %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1c8(%rbp)
movl -0xa8(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movsd -0x1c8(%rbp), %xmm1
movsd (%rax), %xmm0
subsd %xmm0, %xmm1
movsd 0x3274(%rip), %xmm0     # 0xc020
divsd %xmm1, %xmm0
movl -0xa8(%rbp), %esi
movl %esi, %edx
decl %edx
leaq -0x88(%rbp), %rdi
callq 0x2e30
jmp 0x8dc8
movq -0x150(%rbp), %rdi
movslq -0xa8(%rbp), %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1e8(%rbp)
movl -0xa8(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movsd -0x1e8(%rbp), %xmm1
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
subsd %xmm0, %xmm1
movsd 0x3203(%rip), %xmm0     # 0xc020
movsd %xmm0, -0x1d8(%rbp)
divsd %xmm1, %xmm0
movsd %xmm0, -0x1d0(%rbp)
movl -0xa8(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1e0(%rbp)
movslq -0xa8(%rbp), %rsi
callq 0x4950
movsd -0x1e0(%rbp), %xmm2
movsd -0x1d8(%rbp), %xmm1
movsd -0x1d0(%rbp), %xmm0
movsd (%rax), %xmm3
subsd %xmm3, %xmm2
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
movl -0xa8(%rbp), %edx
leaq -0x88(%rbp), %rdi
movl %edx, %esi
callq 0x2e30
jmp 0x8ea2
movq -0x150(%rbp), %rdi
movl -0xa8(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1f0(%rbp)
movslq -0xa8(%rbp), %rsi
callq 0x4950
movsd -0x1f0(%rbp), %xmm1
movsd (%rax), %xmm0
subsd %xmm0, %xmm1
movsd 0x3130(%rip), %xmm0     # 0xc020
divsd %xmm1, %xmm0
movl -0xa8(%rbp), %esi
movl %esi, %edx
incl %edx
leaq -0x88(%rbp), %rdi
callq 0x2e30
jmp 0x8f0c
movq -0x158(%rbp), %rdi
movslq -0xa8(%rbp), %rsi
callq 0x4950
movq -0x158(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x210(%rbp)
movl -0xa8(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movsd -0x210(%rbp), %xmm0
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x208(%rbp)
movslq -0xa8(%rbp), %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x200(%rbp)
movl -0xa8(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movsd -0x200(%rbp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movl $0x2, %edi
callq 0xa0e0
movsd %xmm0, -0x1f8(%rbp)
jmp 0x8fb4
movq -0x158(%rbp), %rdi
movsd -0x1f8(%rbp), %xmm1
movsd -0x208(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x238(%rbp)
movl -0xa8(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x4950
movq -0x158(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x230(%rbp)
movslq -0xa8(%rbp), %rsi
callq 0x4950
movsd -0x230(%rbp), %xmm0
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x228(%rbp)
movl -0xa8(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x220(%rbp)
movslq -0xa8(%rbp), %rsi
callq 0x4950
movsd -0x220(%rbp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movl $0x2, %edi
callq 0xa0e0
movsd %xmm0, -0x218(%rbp)
jmp 0x9078
movsd -0x238(%rbp), %xmm1
movsd -0x218(%rbp), %xmm2
movsd -0x228(%rbp), %xmm0
divsd %xmm2, %xmm0
addsd %xmm0, %xmm1
movsd 0x3018(%rip), %xmm0     # 0xc0b8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x240(%rbp)
movslq -0xa8(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x4950
movsd -0x240(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x8d4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x22(%rbp), %rdi
callq 0x4a90
jmp 0x940a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x93fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xa1(%rbp), %rdi
callq 0x4a90
jmp 0x93d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x93c8
movq -0x150(%rbp), %rdi
movl -0xc(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x248(%rbp)
movl -0xc(%rbp), %eax
addl $-0x2, %eax
movslq %eax, %rsi
callq 0x4950
movsd -0x248(%rbp), %xmm1
movsd (%rax), %xmm0
subsd %xmm0, %xmm1
movsd 0x2e9b(%rip), %xmm0     # 0xc020
divsd %xmm1, %xmm0
movl -0xc(%rbp), %edx
decl %edx
leaq -0x88(%rbp), %rdi
movl %edx, %esi
callq 0x2e30
jmp 0x919e
movq -0x150(%rbp), %rdi
movl -0xc(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x250(%rbp)
movl -0xc(%rbp), %eax
addl $-0x2, %eax
movslq %eax, %rsi
callq 0x4950
movsd -0x250(%rbp), %xmm1
movsd (%rax), %xmm0
subsd %xmm0, %xmm1
movsd 0x2e1d(%rip), %xmm0     # 0xc008
divsd %xmm1, %xmm0
movl -0xc(%rbp), %edx
movl %edx, %esi
decl %esi
addl $-0x2, %edx
leaq -0x88(%rbp), %rdi
callq 0x2e30
jmp 0x9207
movq -0x158(%rbp), %rdi
movl -0xc(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movq -0x158(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x270(%rbp)
movl -0xc(%rbp), %eax
addl $-0x2, %eax
movslq %eax, %rsi
callq 0x4950
movsd -0x270(%rbp), %xmm0
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd 0x2e5d(%rip), %xmm1     # 0xc0b8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x268(%rbp)
movl -0xc(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x260(%rbp)
movl -0xc(%rbp), %eax
addl $-0x2, %eax
movslq %eax, %rsi
callq 0x4950
movsd -0x260(%rbp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movl $0x2, %edi
callq 0xa0e0
movsd %xmm0, -0x258(%rbp)
jmp 0x92b9
movsd -0x258(%rbp), %xmm1
movsd -0x268(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x278(%rbp)
movl -0xc(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x4950
movsd -0x278(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x110(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4cf0
jmp 0x930a
leaq -0x128(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x4da0
jmp 0x931f
leaq -0xc0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0x33b0
jmp 0x933b
movq -0x140(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x4e90
leaq -0xc0(%rbp), %rdi
callq 0x4720
leaq -0x128(%rbp), %rdi
callq 0x4720
leaq -0x110(%rbp), %rdi
callq 0x4ec0
movb $0x1, -0x21(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x4720
leaq -0x88(%rbp), %rdi
callq 0x4ec0
testb $0x1, -0x21(%rbp)
jne 0x93ee
jmp 0x93e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x93bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x4720
leaq -0x110(%rbp), %rdi
callq 0x4ec0
leaq -0xa0(%rbp), %rdi
callq 0x4720
leaq -0x88(%rbp), %rdi
callq 0x4ec0
jmp 0x93fe
movq -0x140(%rbp), %rdi
callq 0x4720
movq -0x148(%rbp), %rax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq -0x140(%rbp), %rdi
callq 0x4720
movq -0x30(%rbp), %rdi
callq 0x2310
nopw %cs:(%rax,%rax)