// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_spline_growing_closeby
int array_interpolate_spline_growing_closeby(
					     double * x_array,
					     int n_lines,
					     double * array,
					     double * array_splined,
					     int n_columns,
					     double x,
					     int * last_index,
					     double * result,
					     int result_size, /** from 1 to n_columns */
					     ErrorMsg errmsg) {

  int inf,sup,i;
  double h,a,b;

  /*
  if (*last_index < 0) {
    class_sprintf(errmsg,"%s(L:%d) problem with last_index =%d < 0",__func__,__LINE__,*last_index);
    return _FAILURE_;
  }
  if (*last_index > (n_lines-1)) {
    class_sprintf(errmsg,"%s(L:%d) problem with last_index =%d > %d",__func__,__LINE__,*last_index,n_lines-1);
    return _FAILURE_;
  }
  */

  inf = *last_index;
  class_test(inf<0 || inf>(n_lines-1),
	     errmsg,
	     "*lastindex=%d out of range [0:%d]\n",inf,n_lines-1);
  while (x < x_array[inf]) {
    inf--;
    if (inf < 0) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,
	      x,x_array[0]);
      return _FAILURE_;
    }
  }
  sup = inf+1;
  while (x > x_array[sup]) {
    sup++;
    if (sup > (n_lines-1)) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,
	      x,x_array[n_lines-1]);
      return _FAILURE_;
    }
  }
  inf = sup-1;

  *last_index = inf;

  h = x_array[sup] - x_array[inf];
  b = (x-x_array[inf])/h;
  a = 1-b;

  for (i=0; i<result_size; i++)
    *(result+i) =
      a * *(array+inf*n_columns+i) +
      b * *(array+sup*n_columns+i) +
      ((a*a*a-a)* *(array_splined+inf*n_columns+i) +
       (b*b*b-b)* *(array_splined+sup*n_columns+i))*h*h/6.;

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movq %rdi, %r14
movq 0x1060(%rsp), %rbx
movl (%r9), %r10d
testl %r10d, %r10d
sets %dil
leal -0x1(%rsi), %eax
cmpl %esi, %r10d
setge %sil
orb %dil, %sil
jne 0x199c2
movl 0x1058(%rsp), %edi
movq 0x1050(%rsp), %rsi
leal 0x1(%r10), %r11d
imull %r8d, %r11d
movl %r10d, %ebp
imull %r8d, %ebp
movsd (%r14,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x19a22
leaq -0x1(%r10), %r15
subl %r8d, %r11d
subl %r8d, %ebp
testq %r10, %r10
movq %r15, %r10
jg 0x19952
movsd (%r14), %xmm1
leaq 0xd679f(%rip), %r15     # 0xf011f
leaq 0xd69b1(%rip), %r12     # 0xf0338
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x9f0, %r8d            # imm = 0x9F0
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%r14), %xmm1
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x9f0, %r8d            # imm = 0x9F0
jmp 0x19a93
leaq 0xd6933(%rip), %rsi     # 0xf02fc
leaq 0x810(%rsp), %r14
movq %r14, %rdi
movl %r10d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x30af0
leaq 0xd469b(%rip), %rsi     # 0xee082
leaq 0xd6931(%rip), %rdx     # 0xf031f
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xd462d(%rip), %rsi     # 0xee034
leaq 0xd692a(%rip), %rdx     # 0xf0338
movq %rbx, %rdi
movl $0x9ec, %ecx            # imm = 0x9EC
movq %r15, %r8
xorl %eax, %eax
callq 0x30af0
jmp 0x19aa0
movl %r10d, %r10d
movsd 0x8(%r14,%r10,8), %xmm8
ucomisd %xmm8, %xmm0
jbe 0x19ab7
addl %r8d, %r11d
addl %r8d, %ebp
incq %r10
cmpl %r10d, %eax
jg 0x19a25
movslq %eax, %r13
movsd (%r14,%r13,8), %xmm1
leaq 0xd66f7(%rip), %r15     # 0xf014c
leaq 0xd68dc(%rip), %r12     # 0xf0338
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x9f9, %r8d            # imm = 0x9F9
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%r14,%r13,8), %xmm1
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x9f9, %r8d            # imm = 0x9F9
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8550
movl $0x1, %eax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r10d, (%r9)
testl %edi, %edi
jle 0x19b7f
movl %r10d, %eax
movsd (%r14,%rax,8), %xmm1
subsd %xmm1, %xmm8
subsd %xmm1, %xmm0
divsd %xmm8, %xmm0
movsd 0xd477f(%rip), %xmm1    # 0xee260
subsd %xmm0, %xmm1
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
subsd %xmm1, %xmm2
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
mulsd %xmm0, %xmm3
subsd %xmm0, %xmm3
movl %edi, %edi
movslq %r11d, %rax
leaq (%rcx,%rax,8), %r8
movslq %ebp, %r10
leaq (%rcx,%r10,8), %rcx
leaq (%rdx,%rax,8), %r9
leaq (%rdx,%r10,8), %rdx
xorl %eax, %eax
movsd 0xd5b49(%rip), %xmm4    # 0xef670
xorl %r10d, %r10d
movsd (%r9,%r10,8), %xmm5
mulsd %xmm0, %xmm5
movsd (%rdx,%r10,8), %xmm6
mulsd %xmm1, %xmm6
addsd %xmm5, %xmm6
movsd (%r8,%r10,8), %xmm5
mulsd %xmm3, %xmm5
movsd (%rcx,%r10,8), %xmm7
mulsd %xmm2, %xmm7
addsd %xmm5, %xmm7
mulsd %xmm8, %xmm7
mulsd %xmm8, %xmm7
divsd %xmm4, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, (%rsi,%r10,8)
incq %r10
cmpq %r10, %rdi
jne 0x19b2a
jmp 0x19aa5
xorl %eax, %eax
jmp 0x19aa5