// File: fanyazhi[P]Spline-Fitting/src/cubicSpline.cpp
// Function: cubicSpline(std::vector<double, std::allocator<double>>, std::vector<double, std::allocator<double>>, std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&)
void cubicSpline(vector<double> x, vector<double> y, vector<double> &qx, vector<double> &qy) {
    //initialize qx and qy for extraction
    qx[0] = x[0];
    qy[0] = y[0];

    //initialize variable t to breakdown a and y into monotonic functions
    vector<double> t(x.size());
    for (int i = 0; i < t.size(); i++) {
        t[i] = i;
    }
    vector<double> qt(qx.size());
    qt[0] = 0;
    for (int i = 1; i < qt.size(); i++) {
        qt[i] = qt[i - 1] + 1.0 * (t.size() - 1) / qx.size();
    }

    //obtain derivatives
    vector<double> ky(qt.size());
    vector<double> kx(qt.size());
    ky = splineDerivative(t.size(), t, y);
    kx = splineDerivative(t.size(), t, x);

    //if the first point and the last points are exactly the same, then the
    //curve is enclosed, and derivatives should match at the enclosure point
    double epislon = 1E-7;
    if ((abs(x[0] - x[x.size() - 1]) < epislon) && (abs(y[0] - y[y.size() - 1]) < epislon)) {
        ky[ky.size() - 1] = ky[0];
        kx[kx.size() - 1] = kx[0];
    }

    for (int j = 1; j < qt.size(); j++) {
        int i = 0;
        while (t[i] < qt[j] && i < t.size()) {
            i++;
        }
        qy[j] = cubicPoint(i, qt[j], t, y, ky);
        qx[j] = cubicPoint(i, qt[j], t, x, kx);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movq %rdi, -0x1f8(%rbp)
movq %rsi, -0x210(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x208(%rbp)
callq 0x4950
movq -0x208(%rbp), %rsi
movsd (%rax), %xmm0
movsd %xmm0, -0x218(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4950
movsd -0x218(%rbp), %xmm0
movq -0x210(%rbp), %rdi
movq -0x208(%rbp), %rsi
movsd %xmm0, (%rax)
callq 0x4950
movq -0x208(%rbp), %rsi
movsd (%rax), %xmm0
movsd %xmm0, -0x200(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4950
movsd -0x200(%rbp), %xmm0
movq -0x1f8(%rbp), %rdi
movsd %xmm0, (%rax)
callq 0x49e0
movq %rax, -0x1f0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x4a00
movq -0x1f0(%rbp), %rsi
movq -0x1e8(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x4a20
jmp 0x94f8
leaq -0x39(%rbp), %rdi
callq 0x4a90
movl $0x0, -0x50(%rbp)
movslq -0x50(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x49e0
movq %rax, %rcx
movq -0x220(%rbp), %rax
cmpq %rcx, %rax
jae 0x9576
cvtsi2sdl -0x50(%rbp), %xmm0
movsd %xmm0, -0x228(%rbp)
movslq -0x50(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x4950
movsd -0x228(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x9508
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x4a90
jmp 0x9e70
movq -0x18(%rbp), %rdi
callq 0x49e0
movq %rax, -0x238(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x4a00
movq -0x238(%rbp), %rsi
movq -0x230(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4a20
jmp 0x95af
leaq -0x69(%rbp), %rdi
callq 0x4a90
leaq -0x68(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4950
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x1, -0x70(%rbp)
movslq -0x70(%rbp), %rax
movq %rax, -0x240(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x49e0
movq %rax, %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
jae 0x96f0
movl -0x70(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x4950
movsd (%rax), %xmm0
movsd %xmm0, -0x250(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x49e0
decq %rax
movq %rax, %xmm0
movaps 0x2a91(%rip), %xmm1     # 0xc0c0
movaps %xmm1, -0x280(%rbp)
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2a8e(%rip), %xmm1     # 0xc0d0
movaps %xmm1, -0x270(%rbp)
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x258(%rbp)
movq -0x18(%rbp), %rdi
callq 0x49e0
movaps -0x280(%rbp), %xmm4
movaps -0x270(%rbp), %xmm3
movsd -0x258(%rbp), %xmm1
movsd -0x250(%rbp), %xmm0
movq %rax, %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm3
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm3, %xmm2
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x248(%rbp)
movslq -0x70(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x4950
movsd -0x248(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x95d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x69(%rbp), %rdi
callq 0x4a90
jmp 0x9e67
leaq -0x68(%rbp), %rdi
callq 0x49e0
movq %rax, -0x290(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x4a00
movq -0x290(%rbp), %rsi
movq -0x288(%rbp), %rdx
leaq -0x88(%rbp), %rdi
callq 0x4a20
jmp 0x972f
leaq -0x89(%rbp), %rdi
callq 0x4a90
leaq -0x68(%rbp), %rdi
callq 0x49e0
movq %rax, -0x2a0(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x4a00
movq -0x2a0(%rbp), %rsi
movq -0x298(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
callq 0x4a20
jmp 0x977a
leaq -0xa9(%rbp), %rdi
callq 0x4a90
leaq -0x38(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x49e0
movq -0x2b0(%rbp), %rsi
movl %eax, -0x2a4(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x4da0
jmp 0x97b1
movq -0x210(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x4da0
jmp 0x97c6
movl -0x2a4(%rbp), %esi
leaq -0xc8(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
leaq -0xf8(%rbp), %rcx
callq 0x8ab0
jmp 0x97e8
leaq -0x88(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
movq %rsi, -0x2c8(%rbp)
callq 0x4e90
movq -0x2c8(%rbp), %rdi
callq 0x4720
leaq -0xf8(%rbp), %rdi
callq 0x4720
leaq -0xe0(%rbp), %rdi
callq 0x4720
leaq -0x38(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x49e0
movq -0x2c0(%rbp), %rsi
movl %eax, -0x2b4(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x4da0
jmp 0x9851
movq -0x1f8(%rbp), %rsi
leaq -0x140(%rbp), %rdi
callq 0x4da0
jmp 0x9866
movl -0x2b4(%rbp), %esi
leaq -0x110(%rbp), %rdi
leaq -0x128(%rbp), %rdx
leaq -0x140(%rbp), %rcx
callq 0x8ab0
jmp 0x9888
leaq -0xa8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movq %rsi, -0x2e0(%rbp)
callq 0x4e90
movq -0x2e0(%rbp), %rdi
callq 0x4720
leaq -0x140(%rbp), %rdi
callq 0x4720
leaq -0x128(%rbp), %rdi
callq 0x4720
movq -0x1f8(%rbp), %rdi
movabsq $0x3e7ad7f29abcaf48, %rax # imm = 0x3E7AD7F29ABCAF48
movq %rax, -0x148(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x4950
movq -0x1f8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x2d8(%rbp)
callq 0x49e0
movq -0x1f8(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x4950
movsd -0x2d8(%rbp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
callq 0xa110
movsd %xmm0, -0x2d0(%rbp)
jmp 0x9930
movsd -0x2d0(%rbp), %xmm1
movsd -0x148(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x9b09
movq -0x210(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4950
movq -0x210(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x2f0(%rbp)
callq 0x49e0
movq -0x210(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x4950
movsd -0x2f0(%rbp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
callq 0xa110
movsd %xmm0, -0x2e8(%rbp)
jmp 0x99a3
movsd -0x2e8(%rbp), %xmm1
movsd -0x148(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x9b09
leaq -0x88(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4950
movsd (%rax), %xmm0
movsd %xmm0, -0x300(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x49e0
movq %rax, %rsi
subq $0x1, %rsi
leaq -0x88(%rbp), %rdi
callq 0x4950
movsd -0x300(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xa8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4950
movsd (%rax), %xmm0
movsd %xmm0, -0x2f8(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x49e0
movq %rax, %rsi
subq $0x1, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x4950
movsd -0x2f8(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x9b09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x89(%rbp), %rdi
callq 0x4a90
jmp 0x9e5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa9(%rbp), %rdi
callq 0x4a90
jmp 0x9e52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9e46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9ac1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x4720
leaq -0xe0(%rbp), %rdi
callq 0x4720
jmp 0x9e46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9af8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x4720
leaq -0x128(%rbp), %rdi
callq 0x4720
jmp 0x9e46
movl $0x1, -0x14c(%rbp)
movslq -0x14c(%rbp), %rax
movq %rax, -0x308(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x49e0
movq %rax, %rcx
movq -0x308(%rbp), %rax
cmpq %rcx, %rax
jae 0x9e13
movl $0x0, -0x150(%rbp)
movslq -0x150(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x4950
movsd (%rax), %xmm0
movsd %xmm0, -0x318(%rbp)
movslq -0x14c(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x4950
movsd -0x318(%rbp), %xmm1
movsd (%rax), %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
movb %al, -0x309(%rbp)
jbe 0x9bba
movslq -0x150(%rbp), %rax
movq %rax, -0x320(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x49e0
movq %rax, %rcx
movq -0x320(%rbp), %rax
cmpq %rcx, %rax
setb %al
movb %al, -0x309(%rbp)
movb -0x309(%rbp), %al
testb $0x1, %al
jne 0x9bc6
jmp 0x9bda
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x9b47
movl -0x150(%rbp), %eax
movl %eax, -0x32c(%rbp)
movslq -0x14c(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x4950
movsd (%rax), %xmm0
movsd %xmm0, -0x328(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4da0
jmp 0x9c14
movq -0x210(%rbp), %rsi
leaq -0x180(%rbp), %rdi
callq 0x4da0
jmp 0x9c29
leaq -0x198(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4da0
jmp 0x9c3e
movsd -0x328(%rbp), %xmm0
movl -0x32c(%rbp), %edi
leaq -0x168(%rbp), %rsi
movq %rsi, -0x348(%rbp)
leaq -0x180(%rbp), %rdx
movq %rdx, -0x350(%rbp)
leaq -0x198(%rbp), %rcx
movq %rcx, -0x358(%rbp)
callq 0x87d0
movsd %xmm0, -0x360(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x14c(%rbp), %rsi
callq 0x4950
movsd -0x360(%rbp), %xmm0
movq -0x358(%rbp), %rdi
movsd %xmm0, (%rax)
callq 0x4720
movq -0x350(%rbp), %rdi
callq 0x4720
movq -0x348(%rbp), %rdi
callq 0x4720
movl -0x150(%rbp), %eax
movl %eax, -0x33c(%rbp)
movslq -0x14c(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x4950
movsd (%rax), %xmm0
movsd %xmm0, -0x338(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4da0
jmp 0x9cfd
movq -0x1f8(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0x4da0
jmp 0x9d12
leaq -0x1e0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4da0
jmp 0x9d27
movsd -0x338(%rbp), %xmm0
movl -0x33c(%rbp), %edi
leaq -0x1b0(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
leaq -0x1e0(%rbp), %rcx
callq 0x87d0
movsd %xmm0, -0x368(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x14c(%rbp), %rsi
callq 0x4950
movsd -0x368(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x1e0(%rbp), %rdi
callq 0x4720
leaq -0x1c8(%rbp), %rdi
callq 0x4720
leaq -0x1b0(%rbp), %rdi
callq 0x4720
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x9b13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9dd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x4720
leaq -0x168(%rbp), %rdi
callq 0x4720
jmp 0x9e46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9e05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x4720
leaq -0x1b0(%rbp), %rdi
callq 0x4720
jmp 0x9e46
leaq -0xa8(%rbp), %rdi
callq 0x4720
leaq -0x88(%rbp), %rdi
callq 0x4720
leaq -0x68(%rbp), %rdi
callq 0x4720
leaq -0x38(%rbp), %rdi
callq 0x4720
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
leaq -0xa8(%rbp), %rdi
callq 0x4720
leaq -0x88(%rbp), %rdi
callq 0x4720
leaq -0x68(%rbp), %rdi
callq 0x4720
leaq -0x38(%rbp), %rdi
callq 0x4720
movq -0x48(%rbp), %rdi
callq 0x2310
nopl (%rax)