// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x2888, %rsp           # imm = 0x2888
movq 0x2890(%rsp), %rax
movq %rdi, 0x2878(%rsp)
movl %esi, 0x2874(%rsp)
movsd %xmm0, 0x2868(%rsp)
movq %rdx, 0x2860(%rsp)
movl %ecx, 0x285c(%rsp)
movsd %xmm1, 0x2850(%rsp)
movsd %xmm2, 0x2848(%rsp)
movsd %xmm3, 0x2840(%rsp)
movq %r8, 0x2838(%rsp)
movq %r9, 0x2830(%rsp)
movl $0x0, 0x2824(%rsp)
movl $0x0, 0x2818(%rsp)
movq 0x2878(%rsp), %rax
movl 0x2874(%rsp), %edi
movq 0x2860(%rsp), %rcx
movl (%rcx), %esi
movsd 0x2868(%rsp), %xmm0
movsd 0x2840(%rsp), %xmm1
movsd 0x2850(%rsp), %xmm2
leaq 0x2828(%rsp), %rdx
leaq 0x2824(%rsp), %rcx
callq *%rax
cmpl $0x1, %eax
jne 0x1486f1
leaq 0x2010(%rsp), %rdi
movq 0x2890(%rsp), %rcx
leaq 0x89d2f(%rip), %rsi     # 0x1d23d8
leaq 0xbcb80(%rip), %rdx     # 0x205230
movb $0x0, %al
callq 0x5b9c0
movq 0x2890(%rsp), %rdi
leaq 0x2010(%rsp), %r8
leaq 0x89966(%rip), %rsi     # 0x1d2034
leaq 0xbcba5(%rip), %rdx     # 0x20527a
movl $0x1261, %ecx           # imm = 0x1261
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2884(%rsp)
jmp 0x148c50
movsd 0x2828(%rsp), %xmm0
ucomisd 0x2848(%rsp), %xmm0
jb 0x14874b
movl 0x285c(%rsp), %eax
subl $0x1, %eax
cmpl $0x1, %eax
jge 0x14871f
movl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x14872d
movl 0x285c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %ecx
movq 0x2830(%rsp), %rax
movl %ecx, (%rax)
movl $0x0, 0x2884(%rsp)
jmp 0x148c50
movq 0x2878(%rsp), %rax
movl 0x2874(%rsp), %edi
movq 0x2860(%rsp), %rcx
movl 0x285c(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %esi
movsd 0x2868(%rsp), %xmm0
movsd 0x2840(%rsp), %xmm1
movsd 0x2850(%rsp), %xmm2
leaq 0x2828(%rsp), %rdx
leaq 0x2824(%rsp), %rcx
callq *%rax
cmpl $0x1, %eax
jne 0x148803
leaq 0x1810(%rsp), %rdi
movq 0x2890(%rsp), %rcx
leaq 0x89c1d(%rip), %rsi     # 0x1d23d8
leaq 0xbcaca(%rip), %rdx     # 0x20528c
movb $0x0, %al
callq 0x5b9c0
movq 0x2890(%rsp), %rdi
leaq 0x1810(%rsp), %r8
leaq 0x89854(%rip), %rsi     # 0x1d2034
leaq 0xbca93(%rip), %rdx     # 0x20527a
movl $0x1270, %ecx           # imm = 0x1270
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2884(%rsp)
jmp 0x148c50
movsd 0x2828(%rsp), %xmm1
movsd 0x2848(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x148861
movl 0x285c(%rsp), %ecx
subl $0x2, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jge 0x14883b
movl 0x285c(%rsp), %eax
subl $0x2, %eax
movl %eax, 0x8(%rsp)
jmp 0x148843
xorl %eax, %eax
movl %eax, 0x8(%rsp)
jmp 0x148843
movl 0x8(%rsp), %ecx
movq 0x2838(%rsp), %rax
movl %ecx, (%rax)
movl $0x0, 0x2884(%rsp)
jmp 0x148c50
movl $0x1, 0x281c(%rsp)
movq 0x2878(%rsp), %rax
movl 0x2874(%rsp), %edi
movq 0x2860(%rsp), %rcx
movq 0x2838(%rsp), %rdx
movslq (%rdx), %rdx
movl (%rcx,%rdx,4), %esi
movsd 0x2868(%rsp), %xmm0
movsd 0x2840(%rsp), %xmm1
movsd 0x2850(%rsp), %xmm2
leaq 0x2828(%rsp), %rdx
leaq 0x2824(%rsp), %rcx
callq *%rax
cmpl $0x1, %eax
jne 0x148922
leaq 0x1010(%rsp), %rdi
movq 0x2890(%rsp), %rcx
leaq 0x89afe(%rip), %rsi     # 0x1d23d8
leaq 0xbc9fb(%rip), %rdx     # 0x2052dc
movb $0x0, %al
callq 0x5b9c0
movq 0x2890(%rsp), %rdi
leaq 0x1010(%rsp), %r8
leaq 0x89735(%rip), %rsi     # 0x1d2034
leaq 0xbc974(%rip), %rdx     # 0x20527a
movl $0x1282, %ecx           # imm = 0x1282
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2884(%rsp)
jmp 0x148c50
movsd 0x2828(%rsp), %xmm1
movsd 0x2848(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x14893c
jmp 0x1489a9
movq 0x2838(%rsp), %rax
movl (%rax), %ecx
movq 0x2830(%rsp), %rax
movl %ecx, (%rax)
movl $0x1, 0x2818(%rsp)
movq 0x2838(%rsp), %rax
movl (%rax), %ecx
subl 0x281c(%rsp), %ecx
movq 0x2838(%rsp), %rax
movl %ecx, (%rax)
movq 0x2838(%rsp), %rax
cmpl $0x0, (%rax)
jg 0x148993
movq 0x2838(%rsp), %rax
movl $0x0, (%rax)
jmp 0x1489a9
jmp 0x148995
imull $0x5, 0x281c(%rsp), %eax
movl %eax, 0x281c(%rsp)
jmp 0x14886c
cmpl $0x0, 0x2818(%rsp)
jne 0x148b03
movl $0x1, 0x281c(%rsp)
movq 0x2878(%rsp), %rax
movl 0x2874(%rsp), %edi
movq 0x2860(%rsp), %rcx
movq 0x2830(%rsp), %rdx
movslq (%rdx), %rdx
movl (%rcx,%rdx,4), %esi
movsd 0x2868(%rsp), %xmm0
movsd 0x2840(%rsp), %xmm1
movsd 0x2850(%rsp), %xmm2
leaq 0x2828(%rsp), %rdx
leaq 0x2824(%rsp), %rcx
callq *%rax
cmpl $0x1, %eax
jne 0x148a78
leaq 0x810(%rsp), %rdi
movq 0x2890(%rsp), %rcx
leaq 0x899a8(%rip), %rsi     # 0x1d23d8
leaq 0xbc8fb(%rip), %rdx     # 0x205332
movb $0x0, %al
callq 0x5b9c0
movq 0x2890(%rsp), %rdi
leaq 0x810(%rsp), %r8
leaq 0x895df(%rip), %rsi     # 0x1d2034
leaq 0xbc81e(%rip), %rdx     # 0x20527a
movl $0x129e, %ecx           # imm = 0x129E
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2884(%rsp)
jmp 0x148c50
movsd 0x2828(%rsp), %xmm0
ucomisd 0x2848(%rsp), %xmm0
jb 0x148a8e
jmp 0x148b01
movq 0x2830(%rsp), %rax
movl (%rax), %ecx
movq 0x2838(%rsp), %rax
movl %ecx, (%rax)
movq 0x2830(%rsp), %rax
movl (%rax), %ecx
addl 0x281c(%rsp), %ecx
movq 0x2830(%rsp), %rax
movl %ecx, (%rax)
movq 0x2830(%rsp), %rax
movl (%rax), %eax
movl 0x285c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x148aeb
movl 0x285c(%rsp), %ecx
subl $0x1, %ecx
movq 0x2830(%rsp), %rax
movl %ecx, (%rax)
jmp 0x148b01
jmp 0x148aed
imull $0x5, 0x281c(%rsp), %eax
movl %eax, 0x281c(%rsp)
jmp 0x1489c2
jmp 0x148b03
movl $0x0, 0x2824(%rsp)
movq 0x2830(%rsp), %rax
movl (%rax), %eax
movq 0x2838(%rsp), %rcx
subl (%rcx), %eax
cmpl $0x1, %eax
jle 0x148c45
movq 0x2830(%rsp), %rax
movl (%rax), %eax
movq 0x2838(%rsp), %rcx
addl (%rcx), %eax
cvtsi2sd %eax, %xmm1
movsd 0x8a13d(%rip), %xmm0    # 0x1d2c88
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x2820(%rsp)
movq 0x2878(%rsp), %rax
movl 0x2874(%rsp), %edi
movq 0x2860(%rsp), %rcx
movslq 0x2820(%rsp), %rdx
movl (%rcx,%rdx,4), %esi
movsd 0x2868(%rsp), %xmm0
movsd 0x2840(%rsp), %xmm1
movsd 0x2850(%rsp), %xmm2
leaq 0x2828(%rsp), %rdx
leaq 0x2824(%rsp), %rcx
callq *%rax
cmpl $0x1, %eax
jne 0x148c04
leaq 0x10(%rsp), %rdi
movq 0x2890(%rsp), %rcx
leaq 0x89816(%rip), %rsi     # 0x1d23d8
leaq 0xbc7c0(%rip), %rdx     # 0x205389
movb $0x0, %al
callq 0x5b9c0
movq 0x2890(%rsp), %rdi
leaq 0x10(%rsp), %r8
leaq 0x89450(%rip), %rsi     # 0x1d2034
leaq 0xbc68f(%rip), %rdx     # 0x20527a
movl $0x12bf, %ecx           # imm = 0x12BF
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2884(%rsp)
jmp 0x148c50
movsd 0x2828(%rsp), %xmm1
movsd 0x2848(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x148c2f
movl 0x2820(%rsp), %ecx
movq 0x2838(%rsp), %rax
movl %ecx, (%rax)
jmp 0x148c40
movl 0x2820(%rsp), %ecx
movq 0x2830(%rsp), %rax
movl %ecx, (%rax)
jmp 0x148b0e
movl $0x0, 0x2884(%rsp)
movl 0x2884(%rsp), %eax
addq $0x2888, %rsp           # imm = 0x2888
retq
nop