// File: /workspace/github_c_makefile_star2_O0/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:
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), %xmm1
movq 0x38(%rsp), %rax
movslq 0x10(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2b593
jmp 0x2b536
xorl %eax, %eax
movl %eax, %esi
leaq 0x1a90df(%rip), %rdx    # 0x1d4620
leaq 0x1a9120(%rip), %rcx    # 0x1d4668
movl $0xda8, %r8d            # imm = 0xDA8
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 0x1a90ae(%rip), %rdx    # 0x1d4620
leaq 0x1a90ef(%rip), %rcx    # 0x1d4668
movl $0xda8, %r8d            # imm = 0xDA8
movb $0x0, %al
callq 0x8540
movl $0x1, 0x44(%rsp)
jmp 0x2b727
movsd 0x28(%rsp), %xmm0
movq 0x38(%rsp), %rax
movslq 0x14(%rsp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
ja 0x2b5c9
movsd 0x28(%rsp), %xmm1
movq 0x38(%rsp), %rax
movslq 0x10(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2b66e
jmp 0x2b5cb
movsd 0x28(%rsp), %xmm0
movq 0x38(%rsp), %rax
movl 0x34(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x38(%rsp), %rax
movsd (%rax), %xmm2
xorl %eax, %eax
movl %eax, %esi
leaq 0x1a9085(%rip), %rdx    # 0x1d467e
leaq 0x1a9068(%rip), %rcx    # 0x1d4668
movl $0xdac, %r8d            # imm = 0xDAC
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
movl 0x34(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x38(%rsp), %rax
movsd (%rax), %xmm2
leaq 0x1a9031(%rip), %rdx    # 0x1d467e
leaq 0x1a9014(%rip), %rcx    # 0x1d4668
movl $0xdac, %r8d            # imm = 0xDAC
movb $0x3, %al
callq 0x8540
movl $0x1, 0x44(%rsp)
jmp 0x2b727
jmp 0x2b670
movl 0x10(%rsp), %eax
subl 0x14(%rsp), %eax
cmpl $0x1, %eax
jle 0x2b6bc
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 0x2b6b2
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x2b6ba
movl 0xc(%rsp), %eax
movl %eax, 0x14(%rsp)
jmp 0x2b670
movl 0x14(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
movq 0x218902(%rip), %rax    # 0x243fd0
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movl (%rax), %edx
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rcx
movslq (%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x28(%rsp), %xmm1
movq 0x20(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rsi
movl (%rsi), %esi
addl $0x1, %esi
movslq %esi, %rsi
movsd (%rax,%rsi,8), %xmm2
leaq 0x1a8f90(%rip), %rsi    # 0x1d46a8
movb $0x3, %al
callq 0x84e0
movl $0x1, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq