// File: Sleepwalking[P]world-octave/matlabfunctions.cpp
// Function: interp1Q(double, double, double*, int, double*, int, double*)
void interp1Q(double x, double shift, double *y, int x_length, double *xi,
    int xi_length, double *yi) {
  double *xi_fraction = new double[xi_length];
  double *delta_y = new double[x_length];
  int *xi_base = new int[xi_length];

  double delta_x = shift;
  for (int i = 0; i < xi_length; ++i) {
    xi_base[i] = static_cast<int>((xi[i] - x) / delta_x);
    xi_fraction[i] = (xi[i] - x) / delta_x - xi_base[i];
  }
  diff(y, x_length, delta_y);
  delta_y[x_length - 1] = 0.0;

  for (int i = 0; i < xi_length; ++i)
    yi[i] = y[xi_base[i]] + delta_y[xi_base[i]] * xi_fraction[i];

  // Bug was fixed at 2013/07/14 by M. Morise
  delete[] xi_fraction;
  delete[] xi_base;
  delete[] delta_y;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movq %rdx, -0x28(%rbp)
movl %ecx, -0x2c(%rbp)
movq %r8, -0x38(%rbp)
movslq -0x2c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x40(%rbp)
movslq -0x1c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x48(%rbp)
movslq -0x2c(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x50(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x74b1
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x8(%rbp), %xmm0
divsd -0x58(%rbp), %xmm0
cvttsd2si %xmm0, %edx
movq -0x50(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x8(%rbp), %xmm0
divsd -0x58(%rbp), %xmm0
movq -0x50(%rbp), %rax
movslq -0x5c(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
subsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x7443
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x48(%rbp), %rdx
callq 0x7330
movq -0x48(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x753c
movq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x40(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x74dd
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x7553
movq -0x68(%rbp), %rdi
callq 0x1110
movq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
je 0x756a
movq -0x70(%rbp), %rdi
callq 0x1110
movq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x7581
movq -0x78(%rbp), %rdi
callq 0x1110
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)