// File: /workspace/github_c_makefile_star2_O3/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
leal -0x1(%rdi), %eax
movsd (%rsi), %xmm2
movslq %edi, %rcx
movsd -0x8(%rsi,%rcx,8), %xmm1
ucomisd %xmm2, %xmm1
jbe 0x183fd
ucomisd %xmm0, %xmm2
jbe 0x18450
leaq 0xd7ded(%rip), %r14     # 0xf01a4
leaq 0xd7e01(%rip), %r15     # 0xf01bf
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 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x76d, %r8d            # imm = 0x76D
jmp 0x184f2
ucomisd %xmm0, %xmm1
jbe 0x184a0
leaq 0xd7d11(%rip), %r14     # 0xf011f
leaq 0xd7daa(%rip), %r15     # 0xf01bf
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 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x783, %r8d            # imm = 0x783
jmp 0x184f2
ucomisd %xmm1, %xmm0
jbe 0x1850e
leaq 0xd7d72(%rip), %r14     # 0xf01d3
leaq 0xd7d57(%rip), %r15     # 0xf01bf
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 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x772, %r8d            # imm = 0x772
jmp 0x184f2
ucomisd %xmm2, %xmm0
jbe 0x18551
leaq 0xd7c9b(%rip), %r14     # 0xf014c
leaq 0xd7d07(%rip), %r15     # 0xf01bf
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 0x8550
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 0x8550
movl $0x1, %eax
jmp 0x18596
cmpl $0x3, %edi
jl 0x18590
xorl %edi, %edi
movsd 0xd67b3(%rip), %xmm2    # 0xeecd0
leal (%rdi,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %rcx
movsd (%rsi,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %eax
cmoval %edi, %ecx
movl %eax, %r8d
subl %ecx, %r8d
movl %ecx, %edi
cmpl $0x1, %r8d
jg 0x1851d
jmp 0x18592
cmpl $0x3, %edi
jl 0x18590
xorl %edi, %edi
movsd 0xd6770(%rip), %xmm2    # 0xeecd0
leal (%rdi,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %rcx
ucomisd (%rsi,%rcx,8), %xmm0
cmoval %ecx, %eax
cmoval %edi, %ecx
movl %eax, %r8d
subl %ecx, %r8d
movl %ecx, %edi
cmpl $0x1, %r8d
jg 0x18560
jmp 0x18592
xorl %ecx, %ecx
movl %ecx, (%rdx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq