// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../source/transfer.c
// Function: transfer_get_lmax
int transfer_get_lmax(int (*get_xmin_generic)(int sgnK,
                                              int l,
                                              double nu,
                                              double xtol,
                                              double phiminabs,
                                              double *x_nonzero,
                                              int *fevals),
                      int sgnK,
                      double nu,
                      int *lvec,
                      int lsize,
                      double phiminabs,
                      double xmax,
                      double xtol,
                      int *index_l_left,
                      int *index_l_right,
                      ErrorMsg error_message){
  double x_nonzero;
  int fevals=0, index_l_mid;
  int multiplier;
  int right_boundary_checked = _FALSE_;
  class_call(get_xmin_generic(sgnK,
                              lvec[0],
                              nu,
                              xtol,
                              phiminabs,
                              &x_nonzero,
                              &fevals),
             error_message,
             error_message);
  if (x_nonzero >= xmax){
    //printf("None relevant\n");
    //x at left boundary is already larger than xmax.
    *index_l_right = MAX(lsize-1,1);
    return _SUCCESS_;
  }
  class_call(get_xmin_generic(sgnK,
                              lvec[lsize-1],
                              nu,
                              xtol,
                              phiminabs,
                              &x_nonzero,
                              &fevals),
             error_message,
             error_message);

  if (x_nonzero < xmax){
    //All Bessels are relevant
    //printf("All relevant\n");
    *index_l_left = MAX(0,(lsize-2));
    return _SUCCESS_;
  }
  /* Hunt for left boundary: */
  for (multiplier=1; ;multiplier *= 5){
    class_call(get_xmin_generic(sgnK,
                                lvec[*index_l_left],
                                nu,
                                xtol,
                                phiminabs,
                                &x_nonzero,
                                &fevals),
               error_message,
               error_message);
    if (x_nonzero <= xmax){
      //Boundary found
      break;
    }
    else{
      //We can use current index_l_left as index_l_right:
      *index_l_right = *index_l_left;
      right_boundary_checked = _TRUE_;
    }
    //Update index_l_left:
    *index_l_left = (*index_l_left)-multiplier;
    if (*index_l_left<=0){
      *index_l_left = 0;
      break;
    }
  }
  /* If not found, hunt for right boundary: */
  if (right_boundary_checked == _FALSE_){
    for (multiplier=1; ;multiplier *= 5){
      class_call(get_xmin_generic(sgnK,
                                  lvec[*index_l_right],
                                  nu,
                                  xtol,
                                  phiminabs,
                                  &x_nonzero,
                                  &fevals),
                 error_message,
                 error_message);
      if (x_nonzero >= xmax){
        //Boundary found
        break;
      }
      else{
        //We can use current index_l_right as index_l_left:
        *index_l_left = *index_l_right;
      }
      //Update index_l_right:
      *index_l_right = (*index_l_right)+multiplier;
      if (*index_l_right>=(lsize-1)){
        *index_l_right = lsize-1;
        break;
      }
    }
  }
  //  int fevalshunt=fevals;
  fevals=0;
  //Do binary search
  //  printf("Do binary search in get_lmax. \n");
  //printf("Region: [%d, %d]\n",*index_l_left,*index_l_right);
  while (((*index_l_right) - (*index_l_left)) > 1) {
    index_l_mid= (int)(0.5*((*index_l_right)+(*index_l_left)));
    //printf("left:%d, mid=%d, right=%d\n",*index_l_left,index_l_mid,*index_l_right);
    class_call(get_xmin_generic(sgnK,
                                lvec[index_l_mid],
                                nu,
                                xtol,
                                phiminabs,
                                &x_nonzero,
                                &fevals),
               error_message,
               error_message);
    if (x_nonzero < xmax)
      *index_l_left=index_l_mid;
    else
      *index_l_right=index_l_mid;
  }
  //printf("Done\n");
  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x848, %rsp            # imm = 0x848
movq %r9, %r14
movq %r8, 0x10(%rsp)
movsd %xmm2, 0x30(%rsp)
movaps %xmm1, %xmm2
movl %ecx, %ebx
movq %rdx, %r12
movl %esi, %ebp
movq %rdi, %r13
movq 0x880(%rsp), %r15
leaq 0x4(%rsp), %rcx
movl $0x0, (%rcx)
movl (%rdx), %esi
leaq 0x8(%rsp), %rdx
movl %ebp, %edi
movsd %xmm0, 0x18(%rsp)
movsd %xmm3, 0x28(%rsp)
movapd %xmm3, %xmm1
movsd %xmm2, 0x20(%rsp)
callq *%r13
cmpl $0x1, %eax
jne 0xb1993
leaq 0x3caa0(%rip), %rsi     # 0xee3f0
leaq 0x6f317(%rip), %rdx     # 0x120c6e
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x3c6c4(%rip), %rsi     # 0xee034
leaq 0x6f341(%rip), %rdx     # 0x120cb8
movq %r15, %rdi
movl $0x1261, %ecx           # imm = 0x1261
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %ebx
jmp 0xb1a20
movsd 0x8(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jae 0xb1a0e
movslq %ebx, %rax
movl -0x4(%r12,%rax,4), %esi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movl %ebp, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq *%r13
cmpl $0x1, %eax
jne 0xb1a34
leaq 0x3ca16(%rip), %rsi     # 0xee3f0
leaq 0x6f2e9(%rip), %rdx     # 0x120cca
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x3c63a(%rip), %rsi     # 0xee034
leaq 0x6f2b7(%rip), %rdx     # 0x120cb8
movq %r15, %rdi
movl $0x1270, %ecx           # imm = 0x1270
jmp 0xb197f
cmpl $0x3, %ebx
movl $0x2, %eax
cmovgel %ebx, %eax
decl %eax
movl %eax, (%r14)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x848, %rsp            # imm = 0x848
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x30(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
jbe 0xb1a59
cmpl $0x3, %ebx
movl $0x2, %eax
cmovgel %ebx, %eax
addl $-0x2, %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
jmp 0xb1a1e
movq 0x10(%rsp), %rax
movslq (%rax), %rax
movl (%r12,%rax,4), %esi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movl %ebp, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq *%r13
cmpl $0x1, %eax
jne 0xb1ace
leaq 0x3c95e(%rip), %rsi     # 0xee3f0
leaq 0x6f281(%rip), %rdx     # 0x120d1a
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq 0x880(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x3c57a(%rip), %rsi     # 0xee034
leaq 0x6f1f7(%rip), %rdx     # 0x120cb8
movq %r14, %rdi
movl $0x1282, %ecx           # imm = 0x1282
jmp 0xb197f
movsd 0x8(%rsp), %xmm1
movsd 0x30(%rsp), %xmm0
movsd %xmm1, 0x38(%rsp)
ucomisd %xmm1, %xmm0
jb 0xb1bbc
movslq (%r14), %rax
movl (%r12,%rax,4), %esi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movl %ebp, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq *%r13
cmpl $0x1, %eax
je 0xb1b79
decl %ebx
movl $0x1, %r15d
movsd 0x8(%rsp), %xmm0
ucomisd 0x30(%rsp), %xmm0
jae 0xb1c33
movl (%r14), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
addl %r15d, %eax
movl %eax, (%r14)
cmpl %ebx, %eax
jge 0xb1c30
leal (%r15,%r15,4), %r15d
cltq
movl (%r12,%rax,4), %esi
movl %ebp, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
callq *%r13
cmpl $0x1, %eax
jne 0xb1b1f
leaq 0x3c870(%rip), %rsi     # 0xee3f0
leaq 0x6f1e9(%rip), %rdx     # 0x120d70
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq 0x880(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x3c48c(%rip), %rsi     # 0xee034
leaq 0x6f109(%rip), %rdx     # 0x120cb8
movq %r14, %rdi
movl $0x129e, %ecx           # imm = 0x129E
jmp 0xb197f
movl $0x1, %r15d
movq 0x10(%rsp), %rcx
movl (%rcx), %eax
movl %eax, (%r14)
subl %r15d, %eax
movl %eax, (%rcx)
jle 0xb1c23
movl %eax, %eax
movl (%r12,%rax,4), %esi
movl %ebp, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
callq *%r13
cmpl $0x1, %eax
je 0xb1a8b
leal (%r15,%r15,4), %r15d
movsd 0x30(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
jb 0xb1bc2
ucomisd 0x38(%rsp), %xmm0
jae 0xb1aea
jmp 0xb1c33
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
jmp 0xb1c33
movl %ebx, (%r14)
movl $0x0, 0x4(%rsp)
movl (%r14), %r15d
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %r15d, %ecx
subl %eax, %ecx
xorl %ebx, %ebx
cmpl $0x2, %ecx
jl 0xb1a20
addl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x3d069(%rip), %xmm0    # 0xeecd0
cvttsd2si %xmm0, %r15d
movslq %r15d, %rax
movl (%r12,%rax,4), %esi
movl %ebp, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
callq *%r13
cmpl $0x1, %eax
je 0xb1cd0
movsd 0x30(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
jbe 0xb1cb7
movq 0x10(%rsp), %rax
movl %r15d, (%rax)
movl %r15d, %eax
movl (%r14), %r15d
jmp 0xb1cc1
movl %r15d, (%r14)
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %r15d, %ecx
subl %eax, %ecx
cmpl $0x1, %ecx
jg 0xb1c55
jmp 0xb1a20
leaq 0x3c719(%rip), %rsi     # 0xee3f0
leaq 0x6f0e9(%rip), %rdx     # 0x120dc7
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq 0x880(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x3c335(%rip), %rsi     # 0xee034
leaq 0x6efb2(%rip), %rdx     # 0x120cb8
movq %r14, %rdi
movl $0x12bf, %ecx           # imm = 0x12BF
jmp 0xb197f