// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_search_bisect
int array_search_bisect(
                        int n_lines,
                        double * __restrict__ array,
                        double c,
                        int * __restrict__ last_index,
                        ErrorMsg errmsg) {

  int inf,sup,mid;

  inf=0;
  sup=n_lines-1;

  if (array[inf] < array[sup]){

    if (c < array[inf]) {
      class_sprintf(errmsg,"%s(L:%d) : c=%e < y_min=%e",__func__,__LINE__,c,array[inf]);
      return _FAILURE_;
    }

    if (c > array[sup]) {
      class_sprintf(errmsg,"%s(L:%d) : c=%e > y_max=%e",__func__,__LINE__,c,array[sup]);
      return _FAILURE_;
    }

    while (sup-inf > 1) {

      mid=(int)(0.5*(inf+sup));
      if (c < array[mid]) {sup=mid;}
      else {inf=mid;}

    }

  }

  else {

    if (c < array[sup]) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,c,array[sup]);
      return _FAILURE_;
    }

    if (c > array[inf]) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,c,array[inf]);
      return _FAILURE_;
    }

    while (sup-inf > 1) {

      mid=(int)(0.5*(inf+sup));
      if (c > array[mid]) {sup=mid;}
      else {inf=mid;}

    }

  }

  *last_index = inf;

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rcx, %rbx
movsd (%rsi), %xmm2
movslq %edi, %rax
decl %edi
movsd -0x8(%rsi,%rax,8), %xmm1
ucomisd %xmm2, %xmm1
jbe 0x163af
ucomisd %xmm0, %xmm2
jbe 0x16402
leaq 0xd0dfb(%rip), %r14     # 0xe7164
leaq 0xd0e0f(%rip), %r15     # 0xe717f
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x76d, %r8d            # imm = 0x76D
movapd %xmm2, %xmm1
movsd %xmm2, (%rsp)
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x76d, %r8d            # imm = 0x76D
jmp 0x164a4
ucomisd %xmm0, %xmm1
jbe 0x16452
leaq 0xd0d1f(%rip), %r14     # 0xe70df
leaq 0xd0db8(%rip), %r15     # 0xe717f
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x783, %r8d            # imm = 0x783
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, (%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x783, %r8d            # imm = 0x783
jmp 0x164a4
ucomisd %xmm1, %xmm0
jbe 0x164bb
leaq 0xd0d80(%rip), %r14     # 0xe7193
leaq 0xd0d65(%rip), %r15     # 0xe717f
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x772, %r8d            # imm = 0x772
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, (%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x772, %r8d            # imm = 0x772
jmp 0x164a4
ucomisd %xmm2, %xmm0
jbe 0x164f3
leaq 0xd0ca9(%rip), %r14     # 0xe710c
leaq 0xd0d15(%rip), %r15     # 0xe717f
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x788, %r8d            # imm = 0x788
movapd %xmm2, %xmm1
movsd %xmm2, (%rsp)
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x788, %r8d            # imm = 0x788
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
movb $0x2, %al
callq 0x8580
pushq $0x1
popq %rax
jmp 0x1652b
xorl %eax, %eax
movsd 0xcf7eb(%rip), %xmm2    # 0xe5cb0
movl %edi, %ecx
subl %eax, %ecx
cmpl $0x2, %ecx
jl 0x16527
leal (%rax,%rdi), %ecx
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %rcx
movsd (%rsi,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %edi
cmoval %eax, %ecx
movl %ecx, %eax
jmp 0x164c5
xorl %eax, %eax
movsd 0xcf7b3(%rip), %xmm2    # 0xe5cb0
movl %edi, %ecx
subl %eax, %ecx
cmpl $0x2, %ecx
jl 0x16527
leal (%rax,%rdi), %ecx
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %rcx
ucomisd (%rsi,%rcx,8), %xmm0
cmoval %ecx, %edi
cmoval %eax, %ecx
movl %ecx, %eax
jmp 0x164fd
movl %eax, (%rdx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq