// File: /workspace/github_cpp_makefile_star2_O2/fanyazhi[P]Spline-Fitting/main.cpp
// Function: main
int main() {
    //--------------------------------------------------------------------------------------
    // Step 1: construct the anchor points or read from file
    //--------------------------------------------------------------------------------------
    std::cout << "constructing the anchor points..." << std::endl;
    std::vector<double> x { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
    std::vector<double> y { 0.0, 1.0, 0.0, -1.0, 0.0, 1.0 };
    // std::vector<double> x = constructVariables("../examples/example_input_sine_x.csv");
    // std::vector<double> y = constructVariables("../examples/example_input_sine_y.csv");

    //--------------------------------------------------------------------------------------
    // Step 2: initialize amount of interpolated points you want to be returned
    //         higher number means smoother line
    //         initialize qx, qy for extraction
    //--------------------------------------------------------------------------------------
    int points = 500;
    std::vector<double> qx(points);
    std::vector<double> qy(points);

    //--------------------------------------------------------------------------------------
    // Step 3: perform cubic spline calculation
    //--------------------------------------------------------------------------------------
    std::cout << "calculating spline..." << std::endl;
    cubicSpline(x, y, qx, qy);

    //--------------------------------------------------------------------------------------
    // Optional: save result to output file
    //--------------------------------------------------------------------------------------
    std::ofstream outputFile_x("../examples/example_output_sine_x.csv");
    std::ostream_iterator<double> output_iterator_x(outputFile_x, "\n");
    std::copy(qx.begin(), qx.end(), output_iterator_x);
    outputFile_x.close();
    std::ofstream outputFile_y("../examples/example_output_sine_y.csv");
    std::ostream_iterator<double> output_iterator_y(outputFile_y, "\n");
    std::copy(qy.begin(), qy.end(), output_iterator_y);
    outputFile_y.close();

    //--------------------------------------------------------------------------------------
    // Optional: perform a continuous second derivative test to verify the result
    //--------------------------------------------------------------------------------------
    secondDerivativeTest(qx, qy);

    return 0;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
movq 0x369b(%rip), %rdi      # 0x7fd0
leaq 0x8e0(%rip), %rsi       # 0x521c
callq 0x2140
movq %rax, %rdi
callq 0x20b0
movups 0x978(%rip), %xmm0      # 0x52c8
leaq 0xf0(%rsp), %rbx
movaps %xmm0, 0x20(%rbx)
movups 0x955(%rip), %xmm0      # 0x52b8
movaps %xmm0, 0x10(%rbx)
movups 0x93a(%rip), %xmm0      # 0x52a8
movaps %xmm0, (%rbx)
leaq 0xa8(%rsp), %rdi
pushq $0x6
popq %r14
leaq 0x2f8(%rsp), %rcx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4c46
movups 0x961(%rip), %xmm0      # 0x52f8
movaps %xmm0, 0x20(%rbx)
movups 0x946(%rip), %xmm0      # 0x52e8
movaps %xmm0, 0x10(%rbx)
movups 0x92b(%rip), %xmm0      # 0x52d8
movaps %xmm0, (%rbx)
leaq 0x90(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0x2f8(%rsp), %rcx
movq %r14, %rdx
callq 0x4c46
leaq 0x18(%rsp), %rdi
leaq 0xf0(%rsp), %rdx
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x3336
movq %rsp, %rdi
leaq 0xf0(%rsp), %rdx
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x3336
movq 0x35cd(%rip), %rdi      # 0x7fd0
leaq 0x834(%rip), %rsi       # 0x523e
callq 0x2140
movq %rax, %rdi
callq 0x20b0
leaq 0x78(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x3470
leaq 0x60(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x3470
leaq 0x78(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %rsp, %rcx
callq 0x3fc0
leaq 0x60(%rsp), %rdi
callq 0x3692
leaq 0x78(%rsp), %rdi
callq 0x3692
leaq 0x7e7(%rip), %rsi       # 0x5254
leaq 0xf0(%rsp), %rbx
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x2170
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0xe0(%rsp), %rcx
movq %rbx, (%rcx)
leaq 0x7de(%rip), %r14       # 0x527a
movq %r14, 0x8(%rcx)
leaq 0x2f8(%rsp), %rdi
callq 0x4c7c
leaq 0xf0(%rsp), %rdi
callq 0x21c0
leaq 0x7bb(%rip), %rsi       # 0x527c
leaq 0x2f8(%rsp), %rbx
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x2170
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0xd0(%rsp), %rcx
movq %rbx, (%rcx)
movq %r14, 0x8(%rcx)
leaq 0xc0(%rsp), %rdi
callq 0x4c7c
leaq 0x2f8(%rsp), %rdi
callq 0x21c0
leaq 0x48(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3470
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x3470
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4728
leaq 0x30(%rsp), %rdi
callq 0x3692
leaq 0x48(%rsp), %rdi
callq 0x3692
leaq 0x2f8(%rsp), %rdi
callq 0x21e0
leaq 0xf0(%rsp), %rdi
callq 0x21e0
movq %rsp, %rdi
callq 0x3692
leaq 0x18(%rsp), %rdi
callq 0x3692
leaq 0x90(%rsp), %rdi
callq 0x3692
leaq 0xa8(%rsp), %rdi
callq 0x3692
xorl %eax, %eax
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r14
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3692
jmp 0x4baa
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3692
jmp 0x4bf3
jmp 0x4bf0
jmp 0x4bbc
jmp 0x4bbc
movq %rax, %rbx
jmp 0x4c00
jmp 0x4c0f
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3692
jmp 0x4bd5
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x3692
jmp 0x4c12
movq %rax, %rbx
jmp 0x4c1a
movq %rax, %rbx
jmp 0x4c24
movq %rax, %rbx
jmp 0x4c31
movq %rax, %rbx
leaq 0x2f8(%rsp), %rdi
callq 0x21e0
leaq 0xf0(%rsp), %rdi
callq 0x21e0
jmp 0x4c12
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3692
leaq 0x18(%rsp), %rdi
callq 0x3692
leaq 0x90(%rsp), %rdi
callq 0x3692
leaq 0xa8(%rsp), %rdi
callq 0x3692
movq %rbx, %rdi
callq 0x2220