// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/match/karlin_altschul_stat.c
// Function: gt_evalue_length_adjustment
static GtUword gt_evalue_length_adjustment(GtUword query_length,
                                           GtUword actual_db_length,
                                           GtUword num_of_db_seqs,
                                           double alpha_div_lambda,
                                           double beta,
                                           double K,
                                           double logK)
{
  unsigned int idx;
  const unsigned int kMaxIterations = 20;
  double len_min = 0, len_max, len_next, len, len_bar, space, nNm;
  GtUword length_adjustment;
  bool converged = false;

  /* l_max is the largest nonnegative solution of
     K * (m - l) * (n - N * l) > GT_MAX(m,n) */

  space = actual_db_length * query_length
          - GT_MAX(query_length, actual_db_length)/K;
  if (space < 0)
    return 0; /* length_adjustnment = 0 */

  nNm = query_length * num_of_db_seqs + actual_db_length;
  /* quadratic formula */
  len_max = 2 * space / (nNm + sqrt(nNm * nNm - 4 * num_of_db_seqs * space));

  len_next = 0;

  for (idx = 0; idx < kMaxIterations; idx++)
  {
    len = len_next;
    len_bar = beta + alpha_div_lambda *
              (logK + log((double) (query_length - len) *
                          (double) (actual_db_length - num_of_db_seqs*len)));
    if (len_bar >= len)
    {
      len_min = len;
      if (len_bar -len_min <= 1.0)
      {
        converged = true;
        break;
      }
      if (len_min == len_max)
        break;
    }
    else
    {
      len_max = len;
    }
    if (len_min <= len_bar && len_bar <= len_max)
      len_next = len_bar;
    else if (idx == 0)
      len_next = len_max;
    else
      len_next = (len_min+len_max)/2;
  }

  length_adjustment = (GtUword) len_min; /* floor(fixed point) */
  if (converged)
  {
    len = ceil(len_min);
    if (len <= len_max)
    {
      if (alpha_div_lambda * (logK +
                              log((query_length-len) *
                                  (actual_db_length-num_of_db_seqs*len))) + beta
          >= len)
      {
        length_adjustment = (GtUword) len;
      }
    }
  }

  return length_adjustment;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movq %rdx, 0xb8(%rsp)
movsd %xmm0, 0xb0(%rsp)
movsd %xmm1, 0xa8(%rsp)
movsd %xmm2, 0xa0(%rsp)
movsd %xmm3, 0x98(%rsp)
movl $0x14, 0x90(%rsp)
movq $0x0, 0x88(%rsp)
movb $0x0, 0x4f(%rsp)
movq 0xc0(%rsp), %rax
movq 0xc8(%rsp), %rcx
imulq %rcx, %rax
movq %rax, %xmm0
movaps 0x2b8ca1(%rip), %xmm1   # 0x518930
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2b8ca5(%rip), %xmm1   # 0x518940
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0xc8(%rsp), %rax
cmpq 0xc0(%rsp), %rax
jbe 0x25fcd1
movq 0xc8(%rsp), %rax
movq %rax, 0x38(%rsp)
jmp 0x25fcde
movq 0xc0(%rsp), %rax
movq %rax, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
movq 0x38(%rsp), %rax
movq %rax, %xmm1
movaps 0x2b8c3b(%rip), %xmm2   # 0x518930
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2b8c3f(%rip), %xmm2   # 0x518940
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd 0xa0(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x60(%rsp), %xmm0
jbe 0x25fd3f
movq $0x0, 0xd0(%rsp)
jmp 0x2601ca
movq 0xc8(%rsp), %rax
movq 0xb8(%rsp), %rcx
imulq %rcx, %rax
movq 0xc0(%rsp), %rcx
addq %rcx, %rax
movq %rax, %xmm0
movaps 0x2b8bc6(%rip), %xmm4   # 0x518930
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movapd 0x2b8bca(%rip), %xmm3   # 0x518940
subpd %xmm3, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x60(%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x58(%rsp), %xmm2
movaps %xmm2, %xmm0
movsd %xmm0, 0x28(%rsp)
movaps %xmm2, %xmm0
movq 0xb8(%rsp), %rax
shlq $0x2, %rax
movq %rax, %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm3, %xmm1
movaps %xmm1, %xmm3
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm3, %xmm1
mulsd 0x60(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x19590
movsd 0x28(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x30(%rsp), %xmm0
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
movl $0x0, 0x94(%rsp)
cmpl $0x14, 0x94(%rsp)
jae 0x260039
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movaps 0x2b8ab3(%rip), %xmm4   # 0x518930
movq 0xc8(%rsp), %xmm0
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movapd 0x2b8aae(%rip), %xmm3   # 0x518940
subpd %xmm3, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x70(%rsp), %xmm1
subsd %xmm1, %xmm0
movq 0xc0(%rsp), %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm1, %xmm2
movq 0xb8(%rsp), %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm3, %xmm1
movaps %xmm1, %xmm3
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm3, %xmm1
movsd 0x70(%rsp), %xmm3
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
callq 0x195c0
movsd 0x10(%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
movaps %xmm0, %xmm3
movsd 0x20(%rsp), %xmm0
addsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm0
ucomisd 0x70(%rsp), %xmm0
jb 0x25ff99
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x68(%rsp), %xmm1
subsd 0x88(%rsp), %xmm1
movsd 0x2b72d4(%rip), %xmm0   # 0x517240
ucomisd %xmm1, %xmm0
jb 0x25ff7c
movb $0x1, 0x4f(%rsp)
jmp 0x260039
movsd 0x88(%rsp), %xmm0
ucomisd 0x80(%rsp), %xmm0
jne 0x25ff97
jp 0x25ff97
jmp 0x260039
jmp 0x25ffa8
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x88(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x25ffe0
movsd 0x68(%rsp), %xmm1
movsd 0x80(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x25ffe0
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
jmp 0x260021
cmpl $0x0, 0x94(%rsp)
jne 0x25fffb
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
jmp 0x26001f
movsd 0x88(%rsp), %xmm0
addsd 0x80(%rsp), %xmm0
movsd 0x2b8d4b(%rip), %xmm1   # 0x518d60
divsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
jmp 0x260021
jmp 0x260023
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x25fe2f
movsd 0x88(%rsp), %xmm0
movsd 0x2b8d26(%rip), %xmm2   # 0x518d70
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rcx
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x50(%rsp)
testb $0x1, 0x4f(%rsp)
je 0x2601bd
movsd 0x88(%rsp), %xmm0
callq 0x190e0
movsd %xmm0, 0x70(%rsp)
movsd 0x70(%rsp), %xmm1
movsd 0x80(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x2601bb
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0xc8(%rsp), %xmm0
movaps 0x2b885e(%rip), %xmm4   # 0x518930
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movapd 0x2b8862(%rip), %xmm3   # 0x518940
subpd %xmm3, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x70(%rsp), %xmm1
subsd %xmm1, %xmm0
movq 0xc0(%rsp), %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm1, %xmm2
movq 0xb8(%rsp), %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm3, %xmm1
movaps %xmm1, %xmm3
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm3, %xmm1
movsd 0x70(%rsp), %xmm3
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
callq 0x195c0
movsd (%rsp), %xmm2
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm2
movsd 0xa8(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x70(%rsp), %xmm0
jb 0x2601b9
movsd 0x70(%rsp), %xmm0
movsd 0x2b8bda(%rip), %xmm2   # 0x518d70
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rcx
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x2601bb
jmp 0x2601bd
movq 0x50(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
addq $0xd8, %rsp
retq
nopw (%rax,%rax)