// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_spline_growing_hunt
int array_interpolate_spline_growing_hunt(
					     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,mid,i,inc;
  double h,a,b;

  inc=1;

  if (x >= x_array[*last_index]) {
    if (x > x_array[n_lines-1]) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,
	      x,x_array[n_lines-1]);
      return _FAILURE_;
    }
    /* try closest neighboor upward */
    inf = *last_index;
    sup = inf + inc;
    if (x > x_array[sup]) {
      /* hunt upward */
      while (x > x_array[sup]) {
	inf = sup;
	inc += 1;
	sup += inc;
	if (sup > n_lines-1) {
	  sup = n_lines-1;
	}
      }
      /* bisect */
      while (sup-inf > 1) {
	mid=(int)(0.5*(inf+sup));
	if (x < x_array[mid]) {sup=mid;}
	else {inf=mid;}
      }
    }
   }
  else {
    if (x < x_array[0]) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,
	      x,x_array[0]);
      return _FAILURE_;
    }
    /* try closest neighboor downward */
    sup = *last_index;
    inf = sup - inc;
    if (x < x_array[inf]) {
      /* hunt downward */
      while (x < x_array[inf]) {
	sup = inf;
	inc += 1;
	inf -= inc;
	if (inf < 0) {
	  inf = 0;
	}
      }
      /* bisect */
      while (sup-inf > 1) {
	mid=(int)(0.5*(inf+sup));
	if (x < x_array[mid]) {sup=mid;}
	else {inf=mid;}
      }
    }
  }

  *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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0x50(%rsp), %r14
movl (%r9), %eax
movslq %eax, %r10
ucomisd (%rdi,%r10,8), %xmm0
jae 0x17acd
movsd (%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x17b47
leaq 0xcf650(%rip), %r15     # 0xe70df
leaq 0xcf88b(%rip), %r12     # 0xe7321
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0xa43, %r8d            # imm = 0xA43
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0xa43, %r8d            # imm = 0xA43
jmp 0x17b29
movslq %esi, %r13
movsd -0x8(%rbx,%r13,8), %xmm1
decq %r13
ucomisd %xmm1, %xmm0
jbe 0x17b84
leaq 0xcf621(%rip), %r15     # 0xe710c
leaq 0xcf82f(%rip), %r12     # 0xe7321
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0xa28, %r8d            # imm = 0xA28
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0xa28, %r8d            # imm = 0xA28
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8580
pushq $0x1
popq %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r10, %rsi
decq %rsi
movsd -0x8(%rbx,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x17bf5
pushq $-0x2
popq %rdi
xorl %r10d, %r10d
ucomisd %xmm0, %xmm1
jbe 0x17bbf
leal (%rsi,%rdi), %r11d
testl %r11d, %r11d
cmovlel %r10d, %r11d
movl %esi, %eax
movsd (%rbx,%r11,8), %xmm1
decl %edi
movl %r11d, %esi
jmp 0x17b64
movsd 0x8(%rbx,%r10,8), %xmm1
incq %r10
ucomisd %xmm1, %xmm0
jbe 0x17c35
pushq $0x2
popq %r11
movl %r10d, %edi
ucomisd %xmm1, %xmm0
jbe 0x17bfc
leal (%rdi,%r11), %r10d
cmpl %esi, %r10d
cmovgel %r13d, %r10d
movslq %r10d, %rax
movsd (%rbx,%rax,8), %xmm1
incl %r11d
movl %edi, %eax
jmp 0x17b9c
movsd 0xce0e9(%rip), %xmm2    # 0xe5cb0
movl %eax, %edi
subl %esi, %edi
cmpl $0x2, %edi
jl 0x17bf5
leal (%rsi,%rax), %edi
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movslq %edi, %rdi
movsd (%rbx,%rdi,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %edi, %eax
cmoval %esi, %edi
movl %edi, %esi
jmp 0x17bc7
movl %eax, %r10d
movl %esi, %eax
jmp 0x17c35
movsd 0xce0ac(%rip), %xmm2    # 0xe5cb0
movl %edi, %esi
subl %eax, %esi
cmpl $0x2, %esi
jl 0x17c32
leal (%rax,%rdi), %esi
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movslq %esi, %rsi
movsd (%rbx,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %esi, %edi
cmoval %eax, %esi
movl %esi, %eax
jmp 0x17c04
movl %edi, %r10d
movl 0x48(%rsp), %esi
movq 0x40(%rsp), %rdi
movl %eax, (%r9)
movslq %r10d, %r10
movsd (%rbx,%r10,8), %xmm8
cltq
movsd (%rbx,%rax,8), %xmm1
subsd %xmm1, %xmm8
subsd %xmm1, %xmm0
divsd %xmm8, %xmm0
movsd 0xcd5f9(%rip), %xmm1    # 0xe5260
subsd %xmm0, %xmm1
imull %r8d, %eax
cltq
leaq (%rdx,%rax,8), %r9
imull %r8d, %r10d
movslq %r10d, %r10
leaq (%rdx,%r10,8), %rdx
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
subsd %xmm1, %xmm2
leaq (%rcx,%rax,8), %r8
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
mulsd %xmm0, %xmm3
subsd %xmm0, %xmm3
leaq (%rcx,%r10,8), %rcx
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movsd 0xce999(%rip), %xmm4    # 0xe6650
xorl %r10d, %r10d
cmpq %r10, %rsi
je 0x17b39
movsd (%rdx,%r10,8), %xmm5
mulsd %xmm0, %xmm5
movsd (%r9,%r10,8), %xmm6
mulsd %xmm1, %xmm6
addsd %xmm5, %xmm6
movsd (%rcx,%r10,8), %xmm5
mulsd %xmm3, %xmm5
movsd (%r8,%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 0x17cba