// File: /workspace/github_cpp_makefile_star2_O3/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 0x3895(%rip), %rbx      # 0x8fd8
leaq 0xb12(%rip), %rsi       # 0x625c
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 0xb83(%rip), %xmm0      # 0x6308
leaq 0x2e0(%rsp), %rbx
movaps %xmm0, 0x20(%rbx)
movups 0xb60(%rip), %xmm0      # 0x62f8
movaps %xmm0, 0x10(%rbx)
movups 0xb45(%rip), %xmm0      # 0x62e8
movaps %xmm0, (%rbx)
leaq 0xb8(%rsp), %rdi
leaq 0xe0(%rsp), %rcx
movl $0x6, %edx
movq %rbx, %rsi
callq 0x5c94
movups 0xb6e(%rip), %xmm0      # 0x6338
movaps %xmm0, 0x20(%rbx)
movups 0xb53(%rip), %xmm0      # 0x6328
movaps %xmm0, 0x10(%rbx)
movups 0xb38(%rip), %xmm0      # 0x6318
movaps %xmm0, (%rbx)
leaq 0xa0(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
leaq 0xe0(%rsp), %rcx
movl $0x6, %edx
callq 0x5c94
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2180
movq %rax, 0x20(%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, %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 0x3748(%rip), %rbx      # 0x8fd8
leaq 0x9e7(%rip), %rsi       # 0x627e
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 0x3716(%rip), %rdi      # 0x8fd8
callq 0x2030
movq %rax, %rdi
callq 0x20e0
leaq 0x88(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x3e1e
leaq 0x70(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x3e1e
leaq 0x88(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %rsp, %rcx
callq 0x48c0
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x592a
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x5947
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x946(%rip), %rsi       # 0x6294
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 0x93e(%rip), %r12       # 0x62ba
movq %r12, 0xe8(%rsp)
subq %rbx, %r15
sarq $0x3, %r15
testq %r15, %r15
jle 0x59b3
incq %r15
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5d58
addq $0x8, %rbx
decq %r15
cmpq $0x1, %r15
ja 0x599b
leaq 0x2e0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2210
leaq 0x8f2(%rip), %rsi       # 0x62bc
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 0x5a27
incq %r13
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x5d58
addq $0x8, %r14
decq %r13
cmpq $0x1, %r13
ja 0x5a0f
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
callq 0x2210
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3e1e
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x3e1e
leaq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x53d8
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x5a79
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5a90
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x3539(%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 0x5b0a
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5b21
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5b3e
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x5b5b
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 0x5b8d
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x5b8d
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5c06
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x5c06
jmp 0x5c15
jmp 0x5c15
jmp 0x5bfe
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x5bce
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x5bce
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x5c25
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x5c25
movq %rax, %rbx
jmp 0x5c3b
movq %rax, %rbx
jmp 0x5c52
movq %rax, %rbx
jmp 0x5c6f
jmp 0x5c03
movq %rax, %rbx
jmp 0x5c25
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2230
jmp 0x5c18
movq %rax, %rbx
leaq 0x2e0(%rsp), %rdi
callq 0x2230
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5c3b
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5c52
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5c6f
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x5c8c
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x2270