// File: /workspace/github_c_makefile_star2_O1/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
movl %esi, %eax
movq 0x1060(%rsp), %rbx
movslq (%r9), %r10
testq %r10, %r10
js 0x19833
cmpl %eax, %r10d
jge 0x19833
movq %rdi, %r14
movl 0x1058(%rsp), %edi
movq 0x1050(%rsp), %rsi
decl %eax
leal 0x1(%r10), %r11d
imull %r8d, %r11d
movl %r10d, %ebp
imull %r8d, %ebp
movsd (%r14,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x19895
leaq -0x1(%r10), %r15
subl %r8d, %r11d
subl %r8d, %ebp
testq %r10, %r10
movq %r15, %r10
jg 0x197c3
movsd (%r14), %xmm1
leaq 0xd991e(%rip), %r15     # 0xf310f
leaq 0xd9b30(%rip), %r12     # 0xf3328
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 0x19906
decl %eax
leaq 0xd9ab0(%rip), %rsi     # 0xf32ec
leaq 0x810(%rsp), %r14
movq %r14, %rdi
movl %r10d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd7828(%rip), %rsi     # 0xf1082
leaq 0xd9aae(%rip), %rdx     # 0xf330f
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd77ba(%rip), %rsi     # 0xf1034
leaq 0xd9aa7(%rip), %rdx     # 0xf3328
movq %rbx, %rdi
movl $0x9ec, %ecx            # imm = 0x9EC
movq %r15, %r8
xorl %eax, %eax
callq 0x30c2c
jmp 0x19913
movl %r10d, %r10d
movsd 0x8(%r14,%r10,8), %xmm8
ucomisd %xmm8, %xmm0
jbe 0x1992a
addl %r8d, %r11d
addl %r8d, %ebp
incq %r10
cmpl %r10d, %eax
jg 0x19898
movslq %eax, %r13
movsd (%r14,%r13,8), %xmm1
leaq 0xd9874(%rip), %r15     # 0xf313c
leaq 0xd9a59(%rip), %r12     # 0xf3328
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 0x199f2
movl %r10d, %eax
movsd (%r14,%rax,8), %xmm1
subsd %xmm1, %xmm8
subsd %xmm1, %xmm0
divsd %xmm8, %xmm0
movsd 0xd790c(%rip), %xmm1    # 0xf1260
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 0xd8cd6(%rip), %xmm4    # 0xf2670
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 0x1999d
jmp 0x19918
xorl %eax, %eax
jmp 0x19918