// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4e0, %rsp            # imm = 0x4E0
movq 0x397d(%rip), %rbx      # 0x8fd8
leaq 0xbba(%rip), %rsi       # 0x621c
movl $0x21, %edx
movq %rbx, %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
movups 0xc2b(%rip), %xmm0      # 0x62c8
leaq 0x2e0(%rsp), %rbx
movaps %xmm0, 0x20(%rbx)
movups 0xc08(%rip), %xmm0      # 0x62b8
movaps %xmm0, 0x10(%rbx)
movups 0xbed(%rip), %xmm0      # 0x62a8
movaps %xmm0, (%rbx)
leaq 0xb8(%rsp), %rdi
leaq 0xe0(%rsp), %rcx
movl $0x6, %edx
movq %rbx, %rsi
callq 0x5bb6
movups 0xc16(%rip), %xmm0      # 0x62f8
movaps %xmm0, 0x20(%rbx)
movups 0xbfb(%rip), %xmm0      # 0x62e8
movaps %xmm0, 0x10(%rbx)
movups 0xbe0(%rip), %xmm0      # 0x62d8
movaps %xmm0, (%rbx)
leaq 0xa0(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
leaq 0xe0(%rsp), %rcx
movl $0x6, %edx
callq 0x5bb6
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2180
movq %rax, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rbx
addq $0xfa0, %rbx            # imm = 0xFA0
movq %rbx, 0x30(%rsp)
movl $0xfa0, %edx            # imm = 0xFA0
movq %rax, %rdi
xorl %esi, %esi
callq 0x20c0
movq %rbx, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2180
movq %rax, (%rsp)
movq %rax, 0x8(%rsp)
movq %rax, %rbx
addq $0xfa0, %rbx            # imm = 0xFA0
movq %rbx, 0x10(%rsp)
movl $0xfa0, %edx            # imm = 0xFA0
movq %rax, %rdi
xorl %esi, %esi
callq 0x20c0
movq %rbx, 0x8(%rsp)
movq 0x3826(%rip), %rbx      # 0x8fd8
leaq 0xa85(%rip), %rsi       # 0x623e
movl $0x15, %edx
movq %rbx, %rdi
callq 0x21c0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x37f4(%rip), %rdi      # 0x8fd8
callq 0x2030
movq %rax, %rdi
callq 0x20e0
leaq 0x88(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x3dea
leaq 0x70(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x3dea
leaq 0x88(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
callq 0x4870
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x584c
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x5869
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x9e4(%rip), %rsi       # 0x6254
leaq 0x2e0(%rsp), %r14
movq %r14, %rdi
movl $0x10, %edx
callq 0x21a0
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r15
movq %r14, 0xe0(%rsp)
leaq 0x9dc(%rip), %r12       # 0x627a
movq %r12, 0xe8(%rsp)
subq %rbx, %r15
sarq $0x3, %r15
testq %r15, %r15
jle 0x58d5
incq %r15
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5c86
addq $0x8, %rbx
decq %r15
cmpq $0x1, %r15
jg 0x58bd
leaq 0x2e0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2210
leaq 0x990(%rip), %rsi       # 0x627c
leaq 0xe0(%rsp), %r15
movq %r15, %rdi
movl $0x10, %edx
callq 0x21a0
movq (%rsp), %r14
movq 0x8(%rsp), %r13
movq %r15, 0xd0(%rsp)
movq %r12, 0xd8(%rsp)
subq %r14, %r13
sarq $0x3, %r13
testq %r13, %r13
jle 0x5949
incq %r13
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x5c86
addq $0x8, %r14
decq %r13
cmpq $0x1, %r13
jg 0x5931
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
callq 0x2210
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3dea
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x3dea
leaq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x5304
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x599b
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x59b2
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x3617(%rip), %rax      # 0x8fd0
movq (%rax), %r15
movq 0x18(%rax), %r12
leaq 0xe8(%rsp), %rdi
movq %r15, -0x8(%rdi)
movq -0x18(%r15), %rax
movq %r12, 0xe0(%rsp,%rax)
callq 0x2140
movl $0xf8, %r13d
addq %r13, %r14
movq %r14, %rdi
callq 0x2070
leaq 0x2e8(%rsp), %rdi
movq %r15, -0x8(%rdi)
movq -0x18(%r15), %rax
movq %r12, 0x2e0(%rsp,%rax)
callq 0x2140
addq %r13, %rbx
movq %rbx, %rdi
callq 0x2070
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5a2c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5a43
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5a60
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x5a7d
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %eax, %eax
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x5aaf
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x5aaf
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5b28
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x5b28
jmp 0x5b37
jmp 0x5b37
jmp 0x5b20
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x5af0
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x5af0
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x5b47
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x5b47
movq %rax, %rbx
jmp 0x5b5d
movq %rax, %rbx
jmp 0x5b74
movq %rax, %rbx
jmp 0x5b91
jmp 0x5b25
movq %rax, %rbx
jmp 0x5b47
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2230
jmp 0x5b3a
movq %rax, %rbx
leaq 0x2e0(%rsp), %rdi
callq 0x2230
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5b5d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5b74
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5b91
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x5bae
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x2270