// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_spline_hunt
int array_spline_hunt(double* x_array,
                       int x_size,
                       double x,
                       int* last,
                       double* h,
                       double* a,
                       double* b,
                       ErrorMsg errmsg){
  /* Define local quantities */
  int inf,sup,mid,inc;
  int last_index = *last;

  /* Error checking */
  if(last_index>=x_size-1){last_index=x_size-2;}
  if(last_index<0){last_index=0;}

  /* Hunt ! */
  inc=1;
  if (x >= x_array[last_index]) {
    if (x > x_array[x_size-1]) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,
        x,x_array[x_size-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 > x_size-1) {
          sup = x_size-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=%.20e < x_min=%.20e",__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;}
      }
    }
  }

  /* We have found the prey */
  last_index = inf;
  *last = last_index;
  *h = x_array[sup] - x_array[inf];
  *b = (x-x_array[inf])/(*h);
  *a = 1.0-(*b);

  return _SUCCESS_;
}

// Assembly:
subq $0x68, %rsp
movq 0x70(%rsp), %rax
movq %rdi, 0x58(%rsp)
movl %esi, 0x54(%rsp)
movsd %xmm0, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl 0x54(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x27e31
movl 0x54(%rsp), %eax
subl $0x2, %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
jge 0x27e40
movl $0x0, 0x14(%rsp)
movl $0x1, 0x18(%rsp)
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movslq 0x14(%rsp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jb 0x27ffe
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x27f16
jmp 0x27e85
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
xorl %eax, %eax
movl %eax, %esi
leaq 0x1ac289(%rip), %rdx    # 0x1d4133
leaq 0x1ac4bd(%rip), %rcx    # 0x1d436e
movl $0xa87, %r8d            # imm = 0xA87
movq %rsi, %rdi
movb $0x2, %al
callq 0x8540
movl %eax, 0x10(%rsp)
movq 0x70(%rsp), %rdi
movl 0x10(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
leaq 0x1ac23e(%rip), %rdx    # 0x1d4133
leaq 0x1ac472(%rip), %rcx    # 0x1d436e
movl $0xa87, %r8d            # imm = 0xA87
movb $0x2, %al
callq 0x8540
movl $0x1, 0x64(%rsp)
jmp 0x281f7
movl 0x14(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
addl 0x18(%rsp), %eax
movl %eax, 0x20(%rsp)
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movslq 0x20(%rsp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x27ff9
jmp 0x27f47
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movslq 0x20(%rsp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x27f99
movl 0x20(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
addl 0x20(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl 0x54(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x27f97
movl 0x54(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x27f47
jmp 0x27f9b
movl 0x20(%rsp), %eax
subl 0x24(%rsp), %eax
cmpl $0x1, %eax
jle 0x27ff7
movl 0x24(%rsp), %eax
addl 0x20(%rsp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x1aaccc(%rip), %xmm0   # 0x1d2c88
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1c(%rsp)
movsd 0x48(%rsp), %xmm1
movq 0x58(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x27fed
movl 0x1c(%rsp), %eax
movl %eax, 0x20(%rsp)
jmp 0x27ff5
movl 0x1c(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x27f9b
jmp 0x27ff9
jmp 0x28174
movsd 0x48(%rsp), %xmm1
movq 0x58(%rsp), %rax
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28090
jmp 0x28015
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movsd (%rax), %xmm1
xorl %eax, %eax
movl %eax, %esi
leaq 0x1ac351(%rip), %rdx    # 0x1d4380
leaq 0x1ac338(%rip), %rcx    # 0x1d436e
movl $0xaa2, %r8d            # imm = 0xAA2
movq %rsi, %rdi
movb $0x2, %al
callq 0x8540
movl %eax, 0xc(%rsp)
movq 0x70(%rsp), %rdi
movl 0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movsd (%rax), %xmm1
leaq 0x1ac311(%rip), %rdx    # 0x1d4380
leaq 0x1ac2f8(%rip), %rcx    # 0x1d436e
movl $0xaa2, %r8d            # imm = 0xAA2
movb $0x2, %al
callq 0x8540
movl $0x1, 0x64(%rsp)
jmp 0x281f7
movl 0x14(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %eax
subl 0x18(%rsp), %eax
movl %eax, 0x24(%rsp)
movsd 0x48(%rsp), %xmm1
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28172
jmp 0x280c5
movsd 0x48(%rsp), %xmm1
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28112
movl 0x24(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %ecx
movl 0x24(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jge 0x28110
movl $0x0, 0x24(%rsp)
jmp 0x280c5
jmp 0x28114
movl 0x20(%rsp), %eax
subl 0x24(%rsp), %eax
cmpl $0x1, %eax
jle 0x28170
movl 0x24(%rsp), %eax
addl 0x20(%rsp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x1aab53(%rip), %xmm0   # 0x1d2c88
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1c(%rsp)
movsd 0x48(%rsp), %xmm1
movq 0x58(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28166
movl 0x1c(%rsp), %eax
movl %eax, 0x20(%rsp)
jmp 0x2816e
movl 0x1c(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x28114
jmp 0x28172
jmp 0x28174
movl 0x24(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x58(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x48(%rsp), %xmm0
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rax
divsd (%rax), %xmm0
movq 0x28(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rax
movsd 0x1aa066(%rip), %xmm0   # 0x1d2248
subsd (%rax), %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq