// File: /workspace/github_c_makefile_star2_O2/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 0x178a4
movl 0x1058(%rsp), %esi
movq 0x1050(%rsp), %rdi
leal 0x1(%r10), %r11d
imull %r8d, %r11d
movl %r10d, %ebp
imull %r8d, %ebp
movsd (%r14,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x17904
leaq -0x1(%r10), %r15
subl %r8d, %r11d
subl %r8d, %ebp
testq %r10, %r10
movq %r15, %r10
jg 0x17834
movsd (%r14), %xmm1
leaq 0xcf87d(%rip), %r15     # 0xe70df
leaq 0xcfa8f(%rip), %r12     # 0xe72f8
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 0x8580
incl %eax
movslq %eax, %rsi
movsd (%r14), %xmm1
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x9f0, %r8d            # imm = 0x9F0
jmp 0x17971
leaq 0xcfa11(%rip), %rsi     # 0xe72bc
leaq 0x810(%rsp), %r14
movq %r14, %rdi
movl %r10d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x2e014
leaq 0xcd7b9(%rip), %rsi     # 0xe5082
leaq 0xcfa0f(%rip), %rdx     # 0xe72df
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xcd74b(%rip), %rsi     # 0xe5034
leaq 0xcfa08(%rip), %rdx     # 0xe72f8
movq %rbx, %rdi
movl $0x9ec, %ecx            # imm = 0x9EC
movq %r15, %r8
xorl %eax, %eax
callq 0x2e014
jmp 0x1797e
movl %r10d, %r10d
movsd 0x8(%r14,%r10,8), %xmm8
ucomisd %xmm8, %xmm0
jbe 0x17993
addl %r8d, %r11d
addl %r8d, %ebp
incq %r10
cmpl %r10d, %eax
jg 0x17907
movslq %eax, %r13
movsd (%r14,%r13,8), %xmm1
leaq 0xcf7d9(%rip), %r15     # 0xe710c
leaq 0xcf9be(%rip), %r12     # 0xe72f8
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 0x8580
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 0x8580
pushq $0x1
popq %rax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r10d, (%r9)
movl %r10d, %eax
movsd (%r14,%rax,8), %xmm1
subsd %xmm1, %xmm8
subsd %xmm1, %xmm0
divsd %xmm8, %xmm0
movsd 0xcd8ab(%rip), %xmm1    # 0xe5260
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
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movslq %r11d, %r9
leaq (%rcx,%r9,8), %r8
movslq %ebp, %r10
leaq (%rcx,%r10,8), %rcx
leaq (%rdx,%r9,8), %r9
leaq (%rdx,%r10,8), %rdx
movsd 0xcec52(%rip), %xmm4    # 0xe6650
xorl %r10d, %r10d
cmpq %r10, %rsi
je 0x17981
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, (%rdi,%r10,8)
incq %r10
jmp 0x17a01