// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_hunt_descending
int array_hunt_descending(
                          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 descending 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[size-1],array[0]);
    return _FAILURE_;
  }

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

  /* result */
  *index = i_inf;

  /* check for debug */
  /* routine never used and tested before, be careful */
  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:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rcx, %r14
movslq %esi, %r13
movsd (%rdi), %xmm2
movsd -0x8(%rdi,%r13,8), %xmm1
ucomisd %xmm2, %xmm1
jbe 0x1b8be
leaq 0xd4db6(%rip), %rbx     # 0xf0639
leaq 0xd4df7(%rip), %r15     # 0xf0681
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
movl $0xda8, %r8d            # imm = 0xDA8
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
movl $0xda8, %r8d            # imm = 0xDA8
xorl %eax, %eax
callq 0x8550
jmp 0x1b92e
movapd %xmm0, %xmm4
movq %rdi, %rbx
ucomisd %xmm2, %xmm0
ja 0x1b8d1
ucomisd %xmm4, %xmm1
jbe 0x1b941
decq %r13
leaq 0xd4dbc(%rip), %r15     # 0xf0697
leaq 0xd4d9f(%rip), %r12     # 0xf0681
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0xdac, %r8d            # imm = 0xDAC
movapd %xmm4, %xmm0
movb $0x3, %al
movsd %xmm4, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movsd (%rbx), %xmm2
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0xdac, %r8d            # imm = 0xDAC
movsd 0x8(%rsp), %xmm0
movb $0x3, %al
callq 0x8550
movl $0x1, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %ecx, %ecx
cmpl $0x3, %esi
jl 0x1b979
decl %esi
xorl %ecx, %ecx
leal (%rcx,%rsi), %edi
movl %edi, %eax
shrl $0x1f, %eax
addl %edi, %eax
sarl %eax
movslq %eax, %rdi
ucomisd (%rbx,%rdi,8), %xmm4
ja 0x1b966
movl %eax, %ecx
jmp 0x1b968
movl %eax, %esi
movl %esi, %eax
subl %ecx, %eax
cmpl $0x1, %eax
jg 0x1b94c
movslq %ecx, %rax
movsd (%rbx,%rax,8), %xmm2
movl %ecx, (%rdx)
movq 0x12d636(%rip), %rax    # 0x148fb8
movq (%rax), %rdi
movslq %ecx, %rdx
incl %ecx
movsd 0x8(%rbx,%rdx,8), %xmm3
leaq 0xd4d2a(%rip), %rsi     # 0xf06c1
movapd %xmm2, %xmm0
movapd %xmm4, %xmm1
movapd %xmm3, %xmm2
movb $0x3, %al
callq 0x84e0
jmp 0x1b92e