// File: istellartech[P]OpenTsiolkovsky/src/fileio.cpp
// Function: interp_matrix(double, Eigen::Matrix<double, -1, -1, 0, -1, -1>, int)
double interp_matrix(double x, MatrixXd matrix, int col_num){
    // 線形補間をする、外挿は無し。点の外は最外点そのまま
    // (x, y)の行が沢山並んでいるのを想定
    // @params x 取得したいデータのx成分
    // @params matrix 2x? データ配列(x,y)
    // @params col_num 取得したいデータの列数 default:1
    // @return y(double) 入力xのデータ
    double y = 0.0;
    double alpha = 0.0;
    for (int i = 0; i < matrix.rows()-1; i++) {
        if (x >= matrix(i,0) && x < matrix(i+1,0)) {
            alpha = (x - matrix(i,0)) / (matrix(i+1,0) - matrix(i,0));
            y = matrix(i,col_num) + alpha * (matrix(i+1,col_num) - matrix(i,col_num));
        }
    }
    if (x < matrix(0,0)) {
        y = matrix(0,col_num);
    }else if (x >= matrix(matrix.rows()-1,0)){
        y = matrix(matrix.rows()-1,col_num);
    }
    return y;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x38(%rbp)
movsd %xmm0, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rax
movq %rax, -0x40(%rbp)
callq 0x8490
movq %rax, %rcx
movq -0x40(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x3b618
movq -0x38(%rbp), %rdi
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movslq -0x2c(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x8540
movsd -0x48(%rbp), %xmm0
ucomisd (%rax), %xmm0
jb 0x3b608
movq -0x38(%rbp), %rdi
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x8540
movsd -0x50(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3b608
movq -0x38(%rbp), %rdi
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movslq -0x2c(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x8540
movsd -0x80(%rbp), %xmm0
movq -0x38(%rbp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x8540
movq -0x38(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movslq -0x2c(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x8540
movsd -0x78(%rbp), %xmm1
movsd -0x70(%rbp), %xmm0
movq -0x38(%rbp), %rdi
subsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movslq -0x2c(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x8540
movq -0x38(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
movslq -0x14(%rbp), %rdx
callq 0x8540
movq -0x38(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movslq -0x2c(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x8540
movsd -0x68(%rbp), %xmm2
movsd -0x60(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
subsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0x3b60a
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3b4a2
movq -0x38(%rbp), %rdi
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x8540
movsd -0x88(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3b663
movq -0x38(%rbp), %rdi
movslq -0x14(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x8540
movsd (%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0x3b6c3
movq -0x38(%rbp), %rdi
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
callq 0x8490
movq -0x38(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x8540
movsd -0x90(%rbp), %xmm0
ucomisd (%rax), %xmm0
jb 0x3b6c1
movq -0x38(%rbp), %rdi
callq 0x8490
movq -0x38(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
movslq -0x14(%rbp), %rdx
callq 0x8540
movsd (%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0x3b6c3
movsd -0x20(%rbp), %xmm0
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)