// File: sus304[P]ForRocket/src/interpolate.cpp
// Function: forrocket::interpolate::CubicSpline1D::polate(double const&, std::vector<double, std::allocator<double>> const&, std::vector<double, std::allocator<double>> const&, int const&)
double forrocket::interpolate::CubicSpline1D::polate(const double& x, const std::vector<double>& x_src, const std::vector<double>& y_src, const int& fill_value) {
    int index_target;
    if (x < x_src[0]) {  // 左外挿
        switch (fill_value) {
        case 0:  // zero
            return 0;
            break;
        
        case 1:  // same
            return y_src[0];
            break;

        case 2:  // extrapolate
            index_target = 0;
            break;
        }
    }
    else if (x >= x_src[0] && x <= x_src[x_src.size()-1]) {  // 内挿
        for (int i=0; i < x_src.size(); ++i) {
            if (x <= x_src[i]) {
                index_target = i - 1;
                break;
            }
        }
    }
    else if (x > x_src[x_src.size()-1]) {  // 右外挿
        switch (fill_value) {
        case 0:  // zero
            return 0;
            break;
        
        case 1:  // same
            return y_src[y_src.size()-1];
            break;

        case 2:  // extrapolate
            index_target = x_src.size() - 1;
            break;
        }
    }

    double h = x - x_src[index_target];
    return a_spline[index_target] + b_spline[index_target] * h + c_spline[index_target] * std::pow(h, 2) + d_spline[index_target] * std::pow(h, 3);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x27ce0
movsd -0x48(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x27a37
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
testl %eax, %eax
je 0x27a03
jmp 0x279ef
movl -0x54(%rbp), %eax
subl $0x1, %eax
je 0x27a10
jmp 0x279f9
movl -0x54(%rbp), %eax
subl $0x2, %eax
je 0x27a2b
jmp 0x27a32
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x27cc7
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x27ce0
movsd (%rax), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x27cc7
movl $0x0, -0x34(%rbp)
jmp 0x27bd4
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x27ce0
movsd -0x60(%rbp), %xmm0
ucomisd (%rax), %xmm0
jb 0x27b07
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
callq 0x86e0
movq -0x70(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x27ce0
movsd -0x68(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x27b07
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rdi
callq 0x86e0
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x27b02
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x27ce0
movsd -0x80(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x27af5
movl -0x38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x27b02
jmp 0x27af7
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x27aa4
jmp 0x27bd2
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rdi
callq 0x86e0
movq -0x90(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x27ce0
movsd -0x88(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x27bd0
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x94(%rbp)
testl %eax, %eax
je 0x27b7c
jmp 0x27b62
movl -0x94(%rbp), %eax
subl $0x1, %eax
je 0x27b89
jmp 0x27b6f
movl -0x94(%rbp), %eax
subl $0x2, %eax
je 0x27bbe
jmp 0x27bce
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x27cc7
movq -0x28(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x86e0
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x27ce0
movsd (%rax), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x27cc7
movq -0x20(%rbp), %rdi
callq 0x86e0
subq $0x1, %rax
movl %eax, -0x34(%rbp)
jmp 0x27bd0
jmp 0x27bd2
jmp 0x27bd4
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0xc8(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x27ce0
movsd -0xc8(%rbp), %xmm0
movq %rax, %rcx
movq -0x50(%rbp), %rax
subsd (%rcx), %xmm0
movsd %xmm0, -0x40(%rbp)
movq 0x10(%rax), %rcx
movslq -0x34(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm1
movq 0x18(%rax), %rcx
movslq -0x34(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movsd -0x40(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x40(%rbp), %xmm0
movl $0x2, %edi
callq 0x283f0
movsd -0xc0(%rbp), %xmm1
movq -0x50(%rbp), %rax
movaps %xmm0, %xmm2
movsd -0xb8(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movq 0x28(%rax), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x40(%rbp), %xmm0
movl $0x3, %edi
callq 0x283f0
movsd -0xb0(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0xa8(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop