// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_hunt_ascending
int array_hunt_ascending(
                          double * array,
                          int size,
                          double value,
                          int * index,
                          ErrorMsg errmsg
                          ) {
  int i_inf,i_sup,i_mid;

  i_inf=0;
  i_sup=size-1;

  /* checks */
  if (array[i_inf] > array[i_sup]) {
    class_sprintf(errmsg,"%s(L:%d) array is not in ascending order (checked only the boundaries)",__func__,__LINE__);
    return _FAILURE_;
  }
  if ((value < array[i_inf]) || (value > array[i_sup])) {
    class_sprintf(errmsg,"%s(L:%d) %e is outside the range [%e, %e]",__func__,__LINE__,value,array[0],array[size-1]);
    return _FAILURE_;
  }

  /* bisection */
  while (i_sup-i_inf>1) {
    i_mid = (i_sup+i_inf)/2;
    if (value > array[i_mid])
      i_inf=i_mid;
    else
      i_sup=i_mid;
  }

  /* result */
  *index = i_inf;

  /* check for debug */
  /*
  fprintf(stderr,
          "Check that array[%d]=%e<%e<array[%d]=%e\n",
          *index,
          array[*index],
          value,
          *index+1,
          array[*index+1]);
  return _FAILURE_;
  */

  return _SUCCESS_;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movl %esi, 0x34(%rsp)
movsd %xmm0, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl 0x34(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x10(%rsp)
movq 0x38(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rax
movslq 0x10(%rsp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x2b7df
jmp 0x2b782
xorl %eax, %eax
movl %eax, %esi
leaq 0x1a8f44(%rip), %rdx    # 0x1d46d1
leaq 0x1a8f84(%rip), %rcx    # 0x1d4718
movl $0xddd, %r8d            # imm = 0xDDD
movq %rsi, %rdi
movb $0x0, %al
callq 0x8540
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movl 0x8(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq 0x1a8f13(%rip), %rdx    # 0x1d46d1
leaq 0x1a8f53(%rip), %rcx    # 0x1d4718
movl $0xddd, %r8d            # imm = 0xDDD
movb $0x0, %al
callq 0x8540
movl $0x1, 0x44(%rsp)
jmp 0x2b918
movsd 0x28(%rsp), %xmm1
movq 0x38(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2b815
movsd 0x28(%rsp), %xmm0
movq 0x38(%rsp), %rax
movslq 0x10(%rsp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x2b8b7
jmp 0x2b817
movsd 0x28(%rsp), %xmm0
movq 0x38(%rsp), %rax
movsd (%rax), %xmm1
movq 0x38(%rsp), %rax
movl 0x34(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
xorl %eax, %eax
movl %eax, %esi
leaq 0x1a8e39(%rip), %rdx    # 0x1d467e
leaq 0x1a8ecc(%rip), %rcx    # 0x1d4718
movl $0xde1, %r8d            # imm = 0xDE1
movq %rsi, %rdi
movb $0x3, %al
callq 0x8540
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rdi
movl 0x4(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
movsd 0x28(%rsp), %xmm0
movq 0x38(%rsp), %rax
movsd (%rax), %xmm1
movq 0x38(%rsp), %rax
movl 0x34(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
leaq 0x1a8de5(%rip), %rdx    # 0x1d467e
leaq 0x1a8e78(%rip), %rcx    # 0x1d4718
movl $0xde1, %r8d            # imm = 0xDE1
movb $0x3, %al
callq 0x8540
movl $0x1, 0x44(%rsp)
jmp 0x2b918
jmp 0x2b8b9
movl 0x10(%rsp), %eax
subl 0x14(%rsp), %eax
cmpl $0x1, %eax
jle 0x2b905
movl 0x10(%rsp), %eax
addl 0x14(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0xc(%rsp)
movsd 0x28(%rsp), %xmm0
movq 0x38(%rsp), %rax
movslq 0xc(%rsp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x2b8fb
movl 0xc(%rsp), %eax
movl %eax, 0x14(%rsp)
jmp 0x2b903
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x2b8b9
movl 0x14(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)