// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/match/karlin_altschul_stat.c
// Function: gt_karlin_altschul_stat_calculate_ungapped_K
static double gt_karlin_altschul_stat_calculate_ungapped_K(
                                                     const ScoringFrequency *sf,
                                                     double lambda,
                                                     double H)
{
  GtWord  low,
          high,
          divisor;
  double  expnlambda,
          K;

  gt_assert(lambda > 0 && H > 0);
  divisor = gt_karlin_altschul_stat_gcd(sf); /* greatest common divisor */
  low = sf->low_align_score/divisor;
  high = sf->high_align_score/divisor;
  lambda *= divisor;
  expnlambda = exp(-lambda);
  if (low == -1 && high == 1)
  {
    K = (sf->sprob[0] - sf->sprob[sf->high_align_score - sf->low_align_score]) *
        (sf->sprob[0] - sf->sprob[sf->high_align_score - sf->low_align_score])/
        sf->sprob[0];
  }
  else if (low == -1 || high == 1)
  {
    const double score_avg = sf->score_avg,
                 one_minus_expnlambda = 1-expnlambda;

    gt_assert(score_avg < 0.0);
    if (high != 1)
    {
      const double score_avg_div = score_avg / divisor;
      K = lambda * one_minus_expnlambda / H *(score_avg_div * score_avg_div);
    }
    else
    {
      K = H/lambda * one_minus_expnlambda;
    }
  }
  else
  {
    const GtUword range = (GtUword) (high - low);
    const GtUword iterlimit = 100;
    const double sumlimit = 0.0001;
    const GtUword size = iterlimit * range + 1;
    GtWord count;
    GtUword sigma = 0;
    GtWord low_align_score = 0, high_align_score = 0;
    double inner_sum = 1.0,
           *alignnment_score_probs
             = gt_calloc(size, sizeof (*alignnment_score_probs));

    gt_assert(low <= high);
    /* K = lambda*exp(-2*sigma)/(H*(1-exp(-lambda)) */

    alignnment_score_probs[0] = 1.0;
    for (count = 0; count < iterlimit && inner_sum > sumlimit; count++)
    {
      GtWord idx, jdx, first, last;
      if (count > 0)
      {
        inner_sum /= count;
        sigma += inner_sum;
      }

      first = last = range;
      low_align_score += low;
      high_align_score += high;
      for (idx = high_align_score-low_align_score; idx >= 0; idx--)
      {
        GtWord firstidx = idx-first;
        GtWord lastidx = idx-last;
        GtWord secondidx = sf->sprob[low] + first;
        for (inner_sum = 0.; firstidx >= lastidx; )
        {
          inner_sum += alignnment_score_probs[firstidx] *
                      alignnment_score_probs[secondidx];
          firstidx--;
          secondidx++;
        }

        if (first > 0)
          --first;
        if (idx <= range)
          --last;

        alignnment_score_probs[idx] = inner_sum;
        if (idx == 0)
          break;
      }

      inner_sum = alignnment_score_probs[++idx];
      for (jdx = low_align_score + 1; jdx < 0; jdx++)
      {
        inner_sum = alignnment_score_probs[++idx] + inner_sum * expnlambda;
      }
      inner_sum *= expnlambda;
      for (/*Nothing*/; jdx <= high_align_score; ++jdx)
        inner_sum += alignnment_score_probs[++jdx];
    }
    gt_free(alignnment_score_probs);
    /* no terms of geometric progression, check to add these terms for
       correction in future */

    K = -exp(-2.0*sigma)/(H/lambda*expnlambda);
  }

  return K;
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movsd %xmm0, 0xd8(%rsp)
movsd %xmm1, 0xd0(%rsp)
movsd 0xd8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x25e975
movsd 0xd0(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
ja 0x25e9ad
movq 0x3dd624(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2b768d(%rip), %rsi    # 0x516013
leaq 0x31d37a(%rip), %rdx    # 0x57bd07
leaq 0x31d387(%rip), %rcx    # 0x57bd1b
leaq 0x31cef5(%rip), %r8     # 0x57b890
movl $0x155, %r9d            # imm = 0x155
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x25e9af
movq 0xe0(%rsp), %rdi
callq 0x260d40
movq %rax, 0xb8(%rsp)
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rax
cqto
idivq 0xb8(%rsp)
movq %rax, 0xc8(%rsp)
movq 0xe0(%rsp), %rax
movq 0x18(%rax), %rax
cqto
idivq 0xb8(%rsp)
movq %rax, 0xc0(%rsp)
cvtsi2sdq 0xb8(%rsp), %xmm0
mulsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0xd8(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x19d40
movsd %xmm0, 0xb0(%rsp)
cmpq $-0x1, 0xc8(%rsp)
jne 0x25eaf7
cmpq $0x1, 0xc0(%rsp)
jne 0x25eaf7
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq 0xe0(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0xe0(%rsp), %rdx
subq 0x10(%rdx), %rcx
subsd (%rax,%rcx,8), %xmm0
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm1
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq 0xe0(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0xe0(%rsp), %rdx
subq 0x10(%rdx), %rcx
subsd (%rax,%rcx,8), %xmm1
mulsd %xmm1, %xmm0
movq 0xe0(%rsp), %rax
movq (%rax), %rax
divsd (%rax), %xmm0
movsd %xmm0, 0xa8(%rsp)
jmp 0x25f0a3
cmpq $-0x1, 0xc8(%rsp)
je 0x25eb11
cmpq $0x1, 0xc0(%rsp)
jne 0x25ec19
movq 0xe0(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0x2b8711(%rip), %xmm0   # 0x517240
subsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
xorps %xmm0, %xmm0
ucomisd 0xa0(%rsp), %xmm0
ja 0x25eb87
movq 0x3dd44a(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2b74b3(%rip), %rsi    # 0x516013
leaq 0x31d1e1(%rip), %rdx    # 0x57bd48
leaq 0x31d1ad(%rip), %rcx    # 0x57bd1b
leaq 0x31cd1b(%rip), %r8     # 0x57b890
movl $0x166, %r9d            # imm = 0x166
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x25eb89
cmpq $0x1, 0xc0(%rsp)
je 0x25ebf0
movsd 0xa0(%rsp), %xmm0
cvtsi2sdq 0xb8(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0xd8(%rsp), %xmm0
mulsd 0x98(%rsp), %xmm0
divsd 0xd0(%rsp), %xmm0
movsd 0x90(%rsp), %xmm1
mulsd 0x90(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rsp)
jmp 0x25ec14
movsd 0xd0(%rsp), %xmm0
divsd 0xd8(%rsp), %xmm0
mulsd 0x98(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
jmp 0x25f0a1
movq 0xc0(%rsp), %rax
subq 0xc8(%rsp), %rax
movq %rax, 0x88(%rsp)
movq $0x64, 0x80(%rsp)
movsd 0x2cfad3(%rip), %xmm0   # 0x52e718
movsd %xmm0, 0x78(%rsp)
imulq $0x64, 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movsd 0x2b85c0(%rip), %xmm0   # 0x517240
movsd %xmm0, 0x48(%rsp)
movq 0x70(%rsp), %rdi
movl $0x8, %esi
leaq 0x31cbf9(%rip), %rdx    # 0x57b890
movl $0x17c, %ecx            # imm = 0x17C
callq 0xe83c0
movq %rax, 0x40(%rsp)
movq 0xc8(%rsp), %rax
cmpq 0xc0(%rsp), %rax
jle 0x25ecf0
movq 0x3dd2e1(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2b734a(%rip), %rsi    # 0x516013
leaq 0x31d088(%rip), %rdx    # 0x57bd58
leaq 0x31d044(%rip), %rcx    # 0x57bd1b
leaq 0x31cbb2(%rip), %r8     # 0x57b890
movl $0x17e, %r9d            # imm = 0x17E
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x25ecf2
movq 0x40(%rsp), %rax
movsd 0x2b8541(%rip), %xmm0   # 0x517240
movsd %xmm0, (%rax)
movq $0x0, 0x68(%rsp)
xorl %eax, %eax
cmpq $0x64, 0x68(%rsp)
movb %al, 0x7(%rsp)
jae 0x25ed33
movsd 0x48(%rsp), %xmm0
movsd 0x2cf9f0(%rip), %xmm1   # 0x52e718
ucomisd %xmm1, %xmm0
seta %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x25ed40
jmp 0x25f013
cmpq $0x0, 0x68(%rsp)
jle 0x25edbc
cvtsi2sdq 0x68(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm1
movaps 0x2b9bc4(%rip), %xmm2   # 0x518930
movq 0x60(%rsp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x2b9bc2(%rip), %xmm2   # 0x518940
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x2b9fc8(%rip), %xmm1   # 0x518d70
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x60(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq 0xc8(%rsp), %rax
addq 0x58(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0xc0(%rsp), %rax
addq 0x50(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
subq 0x58(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x38(%rsp)
jl 0x25ef24
movq 0x38(%rsp), %rax
subq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x38(%rsp), %rax
subq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq 0xc8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsi2sdq 0x28(%rsp), %xmm1
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
jl 0x25eebd
movq 0x40(%rsp), %rax
movq 0x18(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x40(%rsp), %rax
movq 0x8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x48(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x18(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x25ee61
cmpq $0x0, 0x28(%rsp)
jle 0x25eed3
movq 0x28(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x88(%rsp), %rax
ja 0x25eef0
movq 0x20(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x20(%rsp)
movsd 0x48(%rsp), %xmm0
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpq $0x0, 0x38(%rsp)
jne 0x25ef0f
jmp 0x25ef24
jmp 0x25ef11
movq 0x38(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x25ee01
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x38(%rsp)
movsd 0x8(%rax,%rcx,8), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jge 0x25efa5
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x38(%rsp)
movsd 0x8(%rax,%rcx,8), %xmm1
movsd 0x48(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x25ef54
movsd 0xb0(%rsp), %xmm0
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x50(%rsp), %rax
jg 0x25effe
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x30(%rsp)
movsd 0x8(%rax,%rcx,8), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x25efba
jmp 0x25f000
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x25ed0c
movq 0x40(%rsp), %rdi
leaq 0x31c871(%rip), %rsi    # 0x57b890
movl $0x1ae, %edx            # imm = 0x1AE
callq 0xe88c0
movaps 0x2b9900(%rip), %xmm0   # 0x518930
movq 0x60(%rsp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x2b98fe(%rip), %xmm0   # 0x518940
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x31c7c7(%rip), %xmm0   # 0x57b820
mulsd %xmm1, %xmm0
callq 0x19d40
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0xd0(%rsp), %xmm1
divsd 0xd8(%rsp), %xmm1
mulsd 0xb0(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rsp)
jmp 0x25f0a3
movsd 0xa8(%rsp), %xmm0
addq $0xe8, %rsp
retq
nopw %cs:(%rax,%rax)