// File: /workspace/github_cpp_makefile_star2_O3/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
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq %rdx, %rdi
subq %rcx, %rdi
sarq $0x3, %rdi
addq $-0x3, %rdi
xorl %eax, %eax
movl $0x0, %esi
cmpq $-0x3, %rdi
ja 0x549d
movl $0x1, %r13d
movq %rsp, %r15
leaq 0x20(%rsp), %r12
movq (%rbx), %rax
movsd (%rax,%r13,8), %xmm1
movsd 0x8(%rax,%r13,8), %xmm0
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
addsd -0x8(%rax,%r13,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x546d
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x547f
movq %r15, %rdi
movq %r12, %rdx
callq 0x4032
movq (%r14), %rcx
movq 0x8(%r14), %rdx
incq %r13
movq %rdx, %rax
subq %rcx, %rax
sarq $0x3, %rax
decq %rax
cmpq %r13, %rax
ja 0x542d
movq (%rsp), %rax
movq 0x8(%rsp), %rsi
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
subq %rax, %rsi
sarq $0x3, %rsi
addq $-0x3, %rsi
cmpq $-0x3, %rsi
ja 0x5548
movl $0x1, %r15d
leaq 0x20(%rsp), %rbx
leaq 0x58(%rsp), %r14
movsd (%rax,%r15,8), %xmm0
movapd %xmm0, %xmm1
subsd -0x8(%rax,%r15,8), %xmm1
movapd 0xc62(%rip), %xmm2      # 0x6150
andpd %xmm2, %xmm1
subsd 0x8(%rax,%r15,8), %xmm0
andpd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x5522
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x5531
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4032
movq (%rsp), %rax
incq %r15
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
decq %rcx
cmpq %r15, %rcx
ja 0x54d5
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3e1e
leaq 0x40(%rsp), %rdi
callq 0x3007
movsd %xmm0, 0x38(%rsp)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x557e
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movsd 0xb5a(%rip), %xmm0      # 0x60e0
ucomisd 0x38(%rsp), %xmm0
jbe 0x55d4
movq 0x3a43(%rip), %rdi      # 0x8fd8
leaq 0xbe2(%rip), %rsi       # 0x617e
movl $0x33, %edx
callq 0x21c0
movq 0x3a2b(%rip), %rdi      # 0x8fd8
movsd 0x38(%rsp), %xmm0
callq 0x2250
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
jmp 0x567f
movq 0x39fd(%rip), %rdi      # 0x8fd8
leaq 0xbd0(%rip), %rsi       # 0x61b2
movl $0x3b, %edx
callq 0x21c0
movq 0x39e5(%rip), %rdi      # 0x8fd8
movsd 0x38(%rsp), %xmm0
callq 0x2250
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq 0x39a9(%rip), %rdi      # 0x8fd8
leaq 0xbb8(%rip), %rsi       # 0x61ee
movl $0x1c, %edx
callq 0x21c0
movq 0x3991(%rip), %rdi      # 0x8fd8
movsd 0xa91(%rip), %xmm0      # 0x60e0
callq 0x2250
movq %rax, %rbx
leaq 0xbad(%rip), %rsi       # 0x620b
movl $0x50, %edx
movq %rax, %rdi
callq 0x21c0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x56a9
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x56bf
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x56f5
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x56f5
jmp 0x56f2
jmp 0x56f2
movq %rax, %rbx
jmp 0x570c
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x570c
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5722
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x2270
nop