// File: 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 %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0xa8(%rbp)
movq %rsi, -0xa0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x41a0
movl $0x1, -0x2c(%rbp)
movq -0xa8(%rbp), %rdi
movslq -0x2c(%rbp), %rax
movq %rax, -0xb0(%rbp)
callq 0x49e0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0xa404
movq -0xa0(%rbp), %rdi
movl -0x2c(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x4950
movq -0xa0(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xc0(%rbp)
movslq -0x2c(%rbp), %rsi
callq 0x4950
movsd -0xc0(%rbp), %xmm0
movq -0xa0(%rbp), %rdi
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movl -0x2c(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movsd -0xb8(%rbp), %xmm0
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4830
jmp 0xa3e3
jmp 0xa3e5
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xa331
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa6da
leaq -0x60(%rbp), %rdi
callq 0x41a0
movl $0x1, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x49e0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0xa52e
movslq -0x64(%rbp), %rsi
leaq -0x28(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x4950
movq -0xe0(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xd8(%rbp)
movl -0x64(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x4950
movsd -0xd8(%rbp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
callq 0xa110
movsd %xmm0, -0xd0(%rbp)
jmp 0xa492
movslq -0x64(%rbp), %rsi
leaq -0x28(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x4950
movq -0xf8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xf0(%rbp)
movl -0x64(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x4950
movsd -0xf0(%rbp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
callq 0xa110
movsd %xmm0, -0xe8(%rbp)
jmp 0xa4e5
movsd -0xe8(%rbp), %xmm1
movsd -0xd0(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4830
jmp 0xa50d
jmp 0xa50f
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xa414
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa6d1
leaq -0x90(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4da0
jmp 0xa540
leaq -0x90(%rbp), %rdi
callq 0x3330
movsd %xmm0, -0x100(%rbp)
jmp 0xa556
leaq -0x90(%rbp), %rdi
callq 0x4720
movsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd 0x1b99(%rip), %xmm0     # 0xc110
movsd %xmm0, -0x98(%rbp)
movsd -0x78(%rbp), %xmm1
movsd -0x98(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa5ff
movq 0x6a37(%rip), %rdi      # 0x10fd0
leaq 0x1b78(%rip), %rsi      # 0xc118
callq 0x2170
movq %rax, -0x108(%rbp)
jmp 0xa5ae
movq -0x108(%rbp), %rdi
movsd -0x78(%rbp), %xmm0
callq 0x2350
movq %rax, -0x110(%rbp)
jmp 0xa5c8
movq -0x110(%rbp), %rdi
movq 0x69e2(%rip), %rsi      # 0x10fb8
callq 0x21a0
jmp 0xa5dd
jmp 0xa6b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4720
jmp 0xa6d1
movq 0x69ca(%rip), %rdi      # 0x10fd0
leaq 0x1b3f(%rip), %rsi      # 0xc14c
callq 0x2170
movq %rax, -0x118(%rbp)
jmp 0xa61b
movq -0x118(%rbp), %rdi
movsd -0x78(%rbp), %xmm0
callq 0x2350
movq %rax, -0x120(%rbp)
jmp 0xa635
movq -0x120(%rbp), %rdi
movq 0x6975(%rip), %rsi      # 0x10fb8
callq 0x21a0
jmp 0xa64a
movq 0x697f(%rip), %rdi      # 0x10fd0
leaq 0x1b30(%rip), %rsi      # 0xc188
callq 0x2170
movq %rax, -0x128(%rbp)
jmp 0xa666
movq -0x128(%rbp), %rdi
movsd -0x98(%rbp), %xmm0
callq 0x2350
movq %rax, -0x130(%rbp)
jmp 0xa683
movq -0x130(%rbp), %rdi
leaq 0x1b14(%rip), %rsi      # 0xc1a5
callq 0x2170
movq %rax, -0x138(%rbp)
jmp 0xa69f
movq -0x138(%rbp), %rdi
movq 0x690b(%rip), %rsi      # 0x10fb8
callq 0x21a0
jmp 0xa6b4
jmp 0xa6b6
leaq -0x60(%rbp), %rdi
callq 0x4720
leaq -0x28(%rbp), %rdi
callq 0x4720
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x4720
leaq -0x28(%rbp), %rdi
callq 0x4720
movq -0x40(%rbp), %rdi
callq 0x2310
nopl (%rax)