// File: /workspace/github_c_makefile_star2_O3/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), %edi
movslq %edi, %r10
ucomisd (%rbx,%r10,8), %xmm0
jae 0x19bfc
movsd (%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x19c6f
leaq 0xd6561(%rip), %r15     # 0xf011f
leaq 0xd679c(%rip), %r12     # 0xf0361
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 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0xa43, %r8d            # imm = 0xA43
jmp 0x19c58
movslq %esi, %r13
movsd -0x8(%rbx,%r13,8), %xmm1
decq %r13
ucomisd %xmm1, %xmm0
jbe 0x19ceb
leaq 0xd6532(%rip), %r15     # 0xf014c
leaq 0xd6740(%rip), %r12     # 0xf0361
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 0x8550
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 0x8550
movl $0x1, %eax
jmp 0x19e48
movq %r10, %rsi
decq %rsi
movsd -0x8(%rbx,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x19d5d
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
xorl %r10d, %r10d
movl %esi, %eax
leal (%rax,%rdi), %esi
testl %esi, %esi
cmovlel %r10d, %esi
movsd (%rbx,%rsi,8), %xmm1
decl %edi
ucomisd %xmm0, %xmm1
ja 0x19c8e
cmpl $0x2, %eax
jl 0x19d5f
movsd 0xd5019(%rip), %xmm2    # 0xeecd0
leal (%rsi,%rax), %edi
xorps %xmm1, %xmm1
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 %eax, %r10d
subl %edi, %r10d
movl %edi, %esi
cmpl $0x1, %r10d
jg 0x19cb7
jmp 0x19d66
leaq 0x1(%r10), %rax
ucomisd 0x8(%rbx,%r10,8), %xmm0
jbe 0x19d66
movl $0x2, %edi
movl %eax, %r10d
leal (%r10,%rdi), %eax
cmpl %esi, %eax
cmovgel %r13d, %eax
movslq %eax, %r11
incl %edi
ucomisd (%rbx,%r11,8), %xmm0
ja 0x19cfd
movl %eax, %esi
subl %r10d, %esi
cmpl $0x2, %esi
jl 0x19d63
movsd 0xd4fa7(%rip), %xmm2    # 0xeecd0
leal (%r10,%rax), %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movslq %esi, %rdi
movsd (%rbx,%rdi,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %edi, %eax
cmoval %r10d, %edi
movl %eax, %esi
subl %edi, %esi
movl %edi, %r10d
cmpl $0x1, %esi
jg 0x19d29
jmp 0x19d66
movl %edi, %eax
movl %esi, %edi
jmp 0x19d66
movl %r10d, %edi
movl 0x48(%rsp), %r10d
movl %edi, (%r9)
testl %r10d, %r10d
jle 0x19e46
movq 0x40(%rsp), %rsi
cltq
movsd (%rbx,%rax,8), %xmm8
movslq %edi, %r9
movsd (%rbx,%r9,8), %xmm1
subsd %xmm1, %xmm8
subsd %xmm1, %xmm0
divsd %xmm8, %xmm0
movsd 0xd44bd(%rip), %xmm1    # 0xee260
subsd %xmm0, %xmm1
imull %r8d, %edi
movslq %edi, %r9
leaq (%rdx,%r9,8), %rdi
imull %r8d, %eax
cltq
leaq (%rdx,%rax,8), %rdx
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
subsd %xmm1, %xmm2
leaq (%rcx,%r9,8), %r8
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
mulsd %xmm0, %xmm3
subsd %xmm0, %xmm3
leaq (%rcx,%rax,8), %rcx
movl %r10d, %r9d
xorl %eax, %eax
movsd 0xd587f(%rip), %xmm4    # 0xef670
xorl %r10d, %r10d
movsd (%rdx,%r10,8), %xmm5
mulsd %xmm0, %xmm5
movsd (%rdi,%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, (%rsi,%r10,8)
incq %r10
cmpq %r10, %r9
jne 0x19df4
jmp 0x19e48
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq