// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/match/shu-divergence.c
// Function: expShulen
static double expShulen(double T, /* absolute error */
                 double M, /* min logarithm */
                 double d,
                 double p,
                 GtUword subjectLength,
                 double *ln_n_fac,
                 double *s1,
                 GtUword n_s)
{
  GtUword i;
  int thresholdReached = 0;

  double prob_i, probOld, delta, factor;

  double e = 0.0;    /* expectation */
  double t = 1.0 - d;
  double p_t = t;

  probOld  = 0.0;

  /*since for i = 0, the whole expression is 0*/
  for (i = 1LU; i < subjectLength; i++) {
    factor = 1.0 - p_t;
    if (!thresholdReached) {
      prob_i = factor * pmax(M, i, p,
                             subjectLength,
                             &thresholdReached,
                             ln_n_fac,
                             s1,
                             n_s);
    }
    else
      prob_i = factor;  /* prob_i = factor * s, where s = 1 */
    delta = (prob_i - probOld) * i;  /* delta should always be positive */
    gt_assert(gt_double_equals_double(delta, 0.0) ||
              gt_double_larger_double(delta, 0.0));
    e += delta;    /* expectation of avg shulen length(Q, S) */
    /* check error */
    if (1.0 <= e && delta / e <= T)
      break;
    p_t *= t;
    probOld = prob_i;
  }
  return e;
}

// Assembly:
subq $0x98, %rsp
movsd %xmm0, 0x90(%rsp)
movsd %xmm1, 0x88(%rsp)
movsd %xmm2, 0x80(%rsp)
movsd %xmm3, 0x78(%rsp)
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movl $0x0, 0x4c(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x3003b(%rip), %xmm0    # 0x517240
subsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movq $0x1, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x70(%rsp), %rax
jae 0x4e73d0
movsd 0x2fff6(%rip), %xmm0    # 0x517240
subsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
cmpl $0x0, 0x4c(%rsp)
jne 0x4e72b0
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x88(%rsp), %xmm0
movq 0x50(%rsp), %rdi
movsd 0x78(%rsp), %xmm1
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rcx
movq 0x60(%rsp), %r8
movq 0x58(%rsp), %r9
leaq 0x4c(%rsp), %rdx
callq 0x4e74f0
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x4e72bc
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
subsd %xmm1, %xmm0
movaps 0x3165d(%rip), %xmm2    # 0x518930
movq 0x50(%rsp), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3165b(%rip), %xmm2    # 0x518940
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
xorps %xmm1, %xmm1
callq 0xec260
testb $0x1, %al
jne 0x4e735a
movsd 0x30(%rsp), %xmm0
xorps %xmm1, %xmm1
callq 0xec320
testb $0x1, %al
jne 0x4e735a
movq 0x154c77(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2ece0(%rip), %rsi     # 0x516013
leaq 0xd4189(%rip), %rdx     # 0x5bb4c3
leaq 0xd41cd(%rip), %rcx     # 0x5bb50e
leaq 0xd4160(%rip), %r8      # 0x5bb4a8
movl $0x7c, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x4e735c
movsd 0x30(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x2fec4(%rip), %xmm1    # 0x517240
ucomisd %xmm1, %xmm0
jb 0x4e739f
movsd 0x30(%rsp), %xmm1
divsd 0x20(%rsp), %xmm1
movsd 0x90(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x4e739f
jmp 0x4e73d0
movsd 0x18(%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x4e7232
movsd 0x20(%rsp), %xmm0
addq $0x98, %rsp
retq
nop