// File: /workspace/github_cpp_makefile_star2_O2/fanyazhi[P]Spline-Fitting/src/secondDerivativeTest.cpp
// Function: secondDerivativeTest(std::vector<double, std::allocator<double>>, std::vector<double, std::allocator<double>>)
void secondDerivativeTest(std::vector<double> qx, std::vector<double> qy) {
    //first find the second derivative at each point
    std::vector<double> dydx2;
    for (int i = 1; i < qx.size() - 1; i++) {
        double Uxxi = qy[i + 1] - 2 * qy[i] + qy[i - 1];
        dydx2.push_back(Uxxi);
    }

    //compare each second derivative with its neighbors
    std::vector<double> diffDev;
    for (int i = 1; i < dydx2.size() - 1; i++) {
        double diff = abs(dydx2[i] - dydx2[i - 1]) + abs(dydx2[i] - dydx2[i + 1]);
        diffDev.push_back(diff);
    }

    //calculate vector norm of the difference
    double norm = vectorNorm(diffDev);
    double threshold = 1E-7;
    if (norm < threshold) {
        std::cout << "Resulting curve has continuous second drivative, : " << norm << std::endl;
    } else {
        std::cout << "Resulting curve does not have continuous second drivative: " << norm << std::endl;
        std::cout << "Current threshold is set at " << threshold << ", decrease threshold or add more points (>10000) to produce a continuous result." << std::endl;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x30(%rsp), %r15
andq $0x0, 0x10(%r15)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
pushq $0x1
popq %r13
leaq 0x10(%rsp), %r12
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
decq %rax
cmpq %r13, %rax
jbe 0x479f
movq (%rbx), %rax
movsd (%rax,%r13,8), %xmm0
movsd 0x8(%rax,%r13,8), %xmm1
addsd %xmm0, %xmm0
subsd %xmm0, %xmm1
addsd -0x8(%rax,%r13,8), %xmm1
movsd %xmm1, 0x10(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x32da
incq %r13
jmp 0x4757
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rbx
andq $0x0, 0x10(%rbx)
movapd %xmm0, (%rbx)
pushq $0x1
popq %r15
leaq 0x28(%rsp), %r14
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
decq %rcx
cmpq %r15, %rcx
jbe 0x480b
movupd -0x8(%rax,%r15,8), %xmm0
movupd (%rax,%r15,8), %xmm1
subpd %xmm1, %xmm0
andpd 0x924(%rip), %xmm0      # 0x5110
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
addsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32da
incq %r15
jmp 0x47ba
leaq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3470
leaq 0x48(%rsp), %rdi
callq 0x2ade
movsd %xmm0, 0x8(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x3692
movsd 0x894(%rip), %xmm0      # 0x50d0
ucomisd 0x8(%rsp), %xmm0
jbe 0x4867
movq 0x3785(%rip), %rdi      # 0x7fd0
leaq 0x8ec(%rip), %rsi       # 0x513e
callq 0x2140
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x2200
jmp 0x48c2
movq 0x3762(%rip), %rdi      # 0x7fd0
leaq 0x8fd(%rip), %rsi       # 0x5172
callq 0x2140
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x2200
movq %rax, %rdi
callq 0x20b0
movq 0x3739(%rip), %rdi      # 0x7fd0
leaq 0x910(%rip), %rsi       # 0x51ae
callq 0x2140
movsd 0x825(%rip), %xmm0      # 0x50d0
movq %rax, %rdi
callq 0x2200
leaq 0x911(%rip), %rsi       # 0x51cb
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20b0
leaq 0x10(%rsp), %rdi
callq 0x3692
leaq 0x30(%rsp), %rdi
callq 0x3692
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3692
jmp 0x4902
jmp 0x48ff
jmp 0x48ff
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3692
jmp 0x4911
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3692
movq %rbx, %rdi
callq 0x2220
nop