// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/match/shu-divergence.c
// Function: pmax
static double pmax(double M, /* M value should be explored by simulation ??? */
            GtUword x,
            double p,
            GtUword subjectLength,
            int *thresholdReached,
            double *ln_n_fac,
            double *s1,
            GT_UNUSED GtUword n_s)
{

  GtUword k;
  double s = 0.0, ln_x_choose_k;
  double ln, ln1, m1, m, delta;

  gt_assert(x <= n_s && " The maximum number of elements in the array s1 "
            "should be increased!");
  if (s1[x] != 0.0)
    return s1[x];

  for (k = 0; k <= x; k++) {
    double m_a, m_b, m_c, m_d, m_e;
    if (x == k)
      ln_x_choose_k = 0.0;
    else
      ln_x_choose_k =  ln_n_fac[x] - ln_n_fac[k] - ln_n_fac[x-k];

    m_a = pow (2.0, (double) x);
    m_b = pow (p, (double) k);
    m_c = pow (0.5 - p, (double) x - k);
    m_d = pow (p, (double) k);
    m_e = pow (0.5 - p, (double) x -k);
    m = (m_a * m_b * m_c * pow (1.0 - m_d * m_e, (double) subjectLength));
    /* this is ok even with double, because of next if!*/
    if (m == 0.0)
      delta = 0.0;
    else if (M <= m) {
      ln = log(m);
      if (ln == -HUGE_VAL)
        delta = 0.0;
      else
        delta = exp (ln + ln_x_choose_k);
    }
    else {
      double delta_a, delta_b;
      m1 = 1 + m;  /* for small values of m - to avoid overflow (-INF) */
      ln1 = log(m1);
      delta_a = exp (ln1 + ln_x_choose_k);
      delta_b = exp (ln_x_choose_k);
      delta = delta_a - delta_b;
    }
    s += delta;
    if (s >= 1.0) {
      s = 1.0;
      *thresholdReached = 1;
      break;
    }
  }  /* end for */
  s1[x] = s;
  return s;
}

// Assembly:
subq $0xf8, %rsp
movsd %xmm0, 0xe8(%rsp)
movq %rdi, 0xe0(%rsp)
movsd %xmm1, 0xd8(%rsp)
movq %rsi, 0xd0(%rsp)
movq %rdx, 0xc8(%rsp)
movq %rcx, 0xc0(%rsp)
movq %r8, 0xb8(%rsp)
movq %r9, 0xb0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
movq 0xe0(%rsp), %rax
cmpq 0xb0(%rsp), %rax
ja 0x4e755f
movb $0x1, %al
testb $0x1, %al
jne 0x4e7597
jmp 0x4e755f
movq 0x154a3a(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2eaa3(%rip), %rsi     # 0x516013
leaq 0xd3fe6(%rip), %rdx     # 0x5bb55d
leaq 0xd4035(%rip), %rcx     # 0x5bb5b3
leaq 0xd3f23(%rip), %r8      # 0x5bb4a8
movl $0x2b, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x4e7599
movq 0xb8(%rsp), %rax
movq 0xe0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4e75bb
jp 0x4e75bb
jmp 0x4e75de
movq 0xb8(%rsp), %rax
movq 0xe0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xf0(%rsp)
jmp 0x4e7a12
movq $0x0, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
cmpq 0xe0(%rsp), %rax
ja 0x4e79e2
movq 0xe0(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jne 0x4e7620
xorps %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
jmp 0x4e7670
movq 0xc0(%rsp), %rax
movq 0xe0(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0xc0(%rsp), %rax
movq 0xa8(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movq 0xc0(%rsp), %rax
movq 0xe0(%rsp), %rcx
subq 0xa8(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x98(%rsp)
movq 0xe0(%rsp), %xmm1
movaps 0x312b0(%rip), %xmm0    # 0x518930
movaps %xmm0, 0x10(%rsp)
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x312af(%rip), %xmm0    # 0x518940
movaps %xmm0, 0x20(%rsp)
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x316b3(%rip), %xmm0    # 0x518d60
callq 0x19cb0
movaps 0x10(%rsp), %xmm3
movaps 0x20(%rsp), %xmm2
movsd %xmm0, 0x68(%rsp)
movsd 0xd8(%rsp), %xmm0
movq 0xa8(%rsp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
callq 0x19cb0
movaps 0x10(%rsp), %xmm4
movaps 0x20(%rsp), %xmm3
movsd %xmm0, 0x60(%rsp)
movsd 0xd8(%rsp), %xmm1
movsd 0x3f7fb(%rip), %xmm0    # 0x526f08
movsd %xmm0, 0x8(%rsp)
subsd %xmm1, %xmm0
movq 0xe0(%rsp), %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm3, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
movq 0xa8(%rsp), %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm3
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm3, %xmm2
subsd %xmm2, %xmm1
callq 0x19cb0
movaps 0x10(%rsp), %xmm3
movaps 0x20(%rsp), %xmm2
movsd %xmm0, 0x58(%rsp)
movsd 0xd8(%rsp), %xmm0
movq 0xa8(%rsp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
callq 0x19cb0
movaps 0x10(%rsp), %xmm4
movaps 0x20(%rsp), %xmm3
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
movsd %xmm1, 0x50(%rsp)
movsd 0xd8(%rsp), %xmm1
subsd %xmm1, %xmm0
movq 0xe0(%rsp), %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm3, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
movq 0xa8(%rsp), %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm3
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm3, %xmm2
subsd %xmm2, %xmm1
callq 0x19cb0
movaps 0x10(%rsp), %xmm3
movaps 0x20(%rsp), %xmm2
movsd %xmm0, 0x48(%rsp)
movsd 0x68(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x58(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
mulsd %xmm0, %xmm1
movsd 0x2f9ff(%rip), %xmm0    # 0x517240
subsd %xmm1, %xmm0
movq 0xd0(%rsp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
callq 0x19cb0
movaps %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x78(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4e7898
jp 0x4e7898
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
jmp 0x4e7977
movsd 0xe8(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x4e7904
movsd 0x78(%rsp), %xmm0
callq 0x195c0
movsd %xmm0, 0x90(%rsp)
movsd 0x90(%rsp), %xmm0
movsd 0x57d46(%rip), %xmm1    # 0x53f618
ucomisd %xmm1, %xmm0
jne 0x4e78e5
jp 0x4e78e5
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
jmp 0x4e7902
movsd 0x90(%rsp), %xmm0
addsd 0x98(%rsp), %xmm0
callq 0x19d40
movsd %xmm0, 0x70(%rsp)
jmp 0x4e7975
movsd 0x2f934(%rip), %xmm0    # 0x517240
addsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x80(%rsp), %xmm0
callq 0x195c0
movsd %xmm0, 0x88(%rsp)
movsd 0x88(%rsp), %xmm0
addsd 0x98(%rsp), %xmm0
callq 0x19d40
movsd %xmm0, 0x40(%rsp)
movsd 0x98(%rsp), %xmm0
callq 0x19d40
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
subsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
jmp 0x4e7977
movsd 0x70(%rsp), %xmm0
addsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0xa0(%rsp), %xmm0
movsd 0x2f8a0(%rip), %xmm1    # 0x517240
ucomisd %xmm1, %xmm0
jb 0x4e79c7
movsd 0x2f892(%rip), %xmm0    # 0x517240
movsd %xmm0, 0xa0(%rsp)
movq 0xc8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x4e79e2
jmp 0x4e79c9
movq 0xa8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa8(%rsp)
jmp 0x4e75ea
movsd 0xa0(%rsp), %xmm0
movq 0xb8(%rsp), %rax
movq 0xe0(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0xf0(%rsp), %xmm0
addq $0xf8, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)