// File: /workspace/github_c_makefile_star2_O1/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, %rax
ucomisd (%rbx,%rax,8), %xmm0
jae 0x19a6e
movsd (%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x19ae1
leaq 0xd96df(%rip), %r15     # 0xf310f
leaq 0xd991a(%rip), %r12     # 0xf3351
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 0x19aca
movslq %esi, %r13
movsd -0x8(%rbx,%r13,8), %xmm1
decq %r13
ucomisd %xmm1, %xmm0
jbe 0x19b28
leaq 0xd96b0(%rip), %r15     # 0xf313c
leaq 0xd98be(%rip), %r12     # 0xf3351
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 0x19cef
movq %rax, %rsi
decq %rsi
movsd -0x8(%rbx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x19b67
movslq %esi, %rax
movsd (%rbx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x19b76
movl $0xfffffffe, %r10d      # imm = 0xFFFFFFFE
xorl %r11d, %r11d
leal (%rsi,%r10), %edi
testl %edi, %edi
cmovlel %r11d, %edi
movsd (%rbx,%rdi,8), %xmm1
decl %r10d
ucomisd %xmm0, %xmm1
movl %esi, %eax
movl %edi, %esi
ja 0x19b0a
jmp 0x19b7a
leaq 0x1(%rax), %r10
ucomisd 0x8(%rbx,%rax,8), %xmm0
jbe 0x19b6e
movslq %r10d, %rax
ucomisd (%rbx,%rax,8), %xmm0
jbe 0x19bc3
movl $0x2, %r11d
leal (%r10,%r11), %eax
cmpl %esi, %eax
cmovgel %r13d, %eax
movslq %eax, %rdi
incl %r11d
ucomisd (%rbx,%rdi,8), %xmm0
movl %r10d, %edi
movl %eax, %r10d
ja 0x19b48
jmp 0x19bc6
movl %edi, %eax
jmp 0x19c0d
movl %r10d, %eax
jmp 0x19c0b
movl %edi, %eax
movl %esi, %edi
movl %eax, %esi
subl %edi, %esi
cmpl $0x2, %esi
jl 0x19c0b
movsd 0xd8141(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movslq %esi, %rsi
movsd (%rbx,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %esi, %eax
cmoval %edi, %esi
movl %eax, %r10d
subl %esi, %r10d
movl %esi, %edi
cmpl $0x1, %r10d
jg 0x19b8f
jmp 0x19c0d
movl %r10d, %eax
movl %eax, %esi
subl %edi, %esi
cmpl $0x2, %esi
jl 0x19c0b
movsd 0xd80f9(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movslq %esi, %rsi
movsd (%rbx,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %esi, %eax
cmoval %edi, %esi
movl %eax, %r10d
subl %esi, %r10d
movl %esi, %edi
cmpl $0x1, %r10d
jg 0x19bd7
jmp 0x19c0d
movl %edi, %esi
movl 0x48(%rsp), %r10d
movl %esi, (%r9)
testl %r10d, %r10d
jle 0x19ced
movq 0x40(%rsp), %rdi
cltq
movsd (%rbx,%rax,8), %xmm8
movslq %esi, %r9
movsd (%rbx,%r9,8), %xmm1
subsd %xmm1, %xmm8
subsd %xmm1, %xmm0
divsd %xmm8, %xmm0
movsd 0xd7616(%rip), %xmm1    # 0xf1260
subsd %xmm0, %xmm1
imull %r8d, %esi
movslq %esi, %r9
leaq (%rdx,%r9,8), %rsi
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 0xd89d8(%rip), %xmm4    # 0xf2670
xorl %r10d, %r10d
movsd (%rdx,%r10,8), %xmm5
mulsd %xmm0, %xmm5
movsd (%rsi,%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
cmpq %r10, %r9
jne 0x19c9b
jmp 0x19cef
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq