// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/shu-divergence.c
// Function: gt_divergence
double gt_divergence(double E, /* relative error for divergence calculation */
                   double T, /* absolute error for exp shulen*/
                   double M, /* minimum for logarithm */
                   double threshold, /* abs error for divergence */
                   double shulen,
                   GtUword subjectLength,
                   double gc,
                   double *ln_n_fac,
                   GtUword n_s)
{
  double p, q,
         du, dl, dm, d, exp_shulen;
  double *s1;
  s1 = gt_calloc((size_t) n_s + 1, sizeof (double));

  p = gc / 2;
  q = (1.0 - gc) / 2.0;
  du = 0.0;
  dl = 1.0 - (2 * p * p + 2 * q * q);  /* dl < 0.75 */

  while (gt_double_smaller_double(threshold, (dl - du) / 2.0)) {
    dm = (du + dl) / 2.0;
    exp_shulen = expShulen(T, M, dm, p, subjectLength, ln_n_fac, s1, n_s);
    if (gt_double_smaller_double(shulen, exp_shulen))
      du = dm;
    else
      dl = dm;
    /* test the relative error between du and dl; if it is smaller than some
     * threshold, then break !! */
    if (fabs (dl - du) / dl <= E)
      break;
  }
  d = (du + dl) / 2.0;
  gt_free(s1);
  return d;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdx, %r13
movq %rsi, %r14
movsd %xmm5, 0x18(%rsp)
movq %rdi, %r15
movsd %xmm4, 0x88(%rsp)
movsd %xmm3, 0x98(%rsp)
movsd %xmm2, 0xb0(%rsp)
movsd %xmm1, 0xa8(%rsp)
movsd %xmm0, 0x80(%rsp)
leaq 0x1(%rdx), %rdi
leaq 0xb93c4(%rip), %rdx     # 0x385ec0
pushq $0x8
popq %rsi
movl $0x95, %ecx
callq 0x9334a
movq %rax, 0x40(%rsp)
movsd 0x29342(%rip), %xmm3    # 0x2f5e58
movsd 0x1970a(%rip), %xmm4    # 0x2e6228
movapd %xmm4, %xmm0
movsd 0x18(%rsp), %xmm5
subsd %xmm5, %xmm0
mulsd %xmm3, %xmm5
mulsd %xmm3, %xmm0
movapd %xmm5, %xmm1
addsd %xmm5, %xmm1
movapd %xmm0, %xmm2
addsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm5, %xmm1
addsd %xmm2, %xmm1
movapd %xmm4, %xmm2
subsd %xmm1, %xmm2
movsd %xmm5, 0x18(%rsp)
subsd %xmm5, %xmm3
movsd %xmm3, 0x68(%rsp)
movq %r15, %xmm0
punpckldq 0x1ad6b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1ad73(%rip), %xmm0    # 0x2e78f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x100(%rsp)
leaq 0x8(%r14), %rax
movq %rax, 0x90(%rsp)
xorpd %xmm3, %xmm3
movq %r13, 0xa0(%rsp)
movsd %xmm3, 0x38(%rsp)
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm1
subsd %xmm3, %xmm1
movsd 0x29292(%rip), %xmm0    # 0x2f5e58
mulsd %xmm0, %xmm1
movsd 0x98(%rsp), %xmm0
callq 0x955e2
testb %al, %al
je 0x2ccfcf
movsd 0x8(%rsp), %xmm1
addsd 0x38(%rsp), %xmm1
mulsd 0x29264(%rip), %xmm1    # 0x2f5e58
movsd 0x1962c(%rip), %xmm2    # 0x2e6228
movsd %xmm1, 0x58(%rsp)
subsd %xmm1, %xmm2
xorpd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
xorl %r12d, %r12d
movq 0x90(%rsp), %rbx
pushq $0x1
popq %rbp
movsd %xmm2, 0xb8(%rsp)
movsd %xmm2, 0x48(%rsp)
cmpq %r15, %rbp
jae 0x2ccf76
movsd %xmm0, 0xc0(%rsp)
movsd 0x195e1(%rip), %xmm0    # 0x2e6228
subsd 0x48(%rsp), %xmm0
movq %rbp, %xmm1
movdqa %xmm1, 0xe0(%rsp)
testl %r12d, %r12d
jne 0x2cceaf
cmpq %r13, %rbp
ja 0x2cd045
movq 0x40(%rsp), %rax
movsd (%rax,%rbp,8), %xmm1
xorl %r12d, %r12d
ucomisd 0x3f066(%rip), %xmm1    # 0x30bce8
jne 0x2cceab
jp 0x2cceab
movsd %xmm0, 0x10(%rsp)
movapd 0xe0(%rsp), %xmm0
unpcklps 0x1ac3c(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1ac44(%rip), %xmm0    # 0x2e78f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0xf0(%rsp)
xorpd %xmm1, %xmm1
movq %rbx, %r13
xorl %r12d, %r12d
cmpq %rbp, %r12
ja 0x2cce90
movsd %xmm1, 0xd8(%rsp)
xorpd %xmm0, %xmm0
je 0x2cccf5
movsd (%r14,%rbp,8), %xmm0
subsd (%r14,%r12,8), %xmm0
subsd (%r13), %xmm0
movsd %xmm0, 0x50(%rsp)
movaps 0xf0(%rsp), %xmm0
callq 0x176d0
movsd %xmm0, 0xd0(%rsp)
movq %r12, %xmm0
punpckldq 0x1abc2(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1abca(%rip), %xmm0    # 0x2e78f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x70(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x17d10
movsd %xmm0, 0x20(%rsp)
movapd 0xf0(%rsp), %xmm1
subsd 0x70(%rsp), %xmm1
movapd %xmm1, 0x110(%rsp)
movsd 0x68(%rsp), %xmm0
callq 0x17d10
movsd %xmm0, 0xc8(%rsp)
movsd 0x18(%rsp), %xmm0
movaps 0x70(%rsp), %xmm1
callq 0x17d10
movsd %xmm0, 0x70(%rsp)
movsd 0x68(%rsp), %xmm0
movaps 0x110(%rsp), %xmm1
callq 0x17d10
movsd 0x20(%rsp), %xmm1
mulsd 0xd0(%rsp), %xmm1
mulsd 0xc8(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
mulsd 0x70(%rsp), %xmm0
movsd 0x1945e(%rip), %xmm1    # 0x2e6228
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movapd 0x100(%rsp), %xmm1
callq 0x17d10
mulsd 0x20(%rsp), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0x2ccdf2
jnp 0x2cce60
ucomisd 0xb0(%rsp), %xmm0
jae 0x2cce32
addsd 0x19423(%rip), %xmm0    # 0x2e6228
callq 0x175e0
addsd 0x50(%rsp), %xmm0
callq 0x17da0
movsd %xmm0, 0x20(%rsp)
movsd 0x50(%rsp), %xmm0
callq 0x17da0
movsd 0x20(%rsp), %xmm2
subsd %xmm0, %xmm2
jmp 0x2cce60
callq 0x175e0
xorpd %xmm2, %xmm2
movsd 0x40ded(%rip), %xmm1    # 0x30dc30
ucomisd %xmm0, %xmm1
jae 0x2cce60
movsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x17da0
movapd %xmm0, %xmm2
movsd 0xd8(%rsp), %xmm1
addsd %xmm2, %xmm1
incq %r12
addq $-0x8, %r13
ucomisd 0x193ac(%rip), %xmm1    # 0x2e6228
jb 0x2ccccb
pushq $0x1
popq %r12
movsd 0x1939a(%rip), %xmm1    # 0x2e6228
jmp 0x2cce93
xorl %r12d, %r12d
movsd 0x10(%rsp), %xmm0
movq 0x40(%rsp), %rax
movsd %xmm1, (%rax,%rbp,8)
movq 0xa0(%rsp), %r13
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movapd %xmm0, %xmm2
subsd 0x60(%rsp), %xmm2
movapd 0xe0(%rsp), %xmm1
unpcklps 0x1aa11(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1aa19(%rip), %xmm1    # 0x2e78f0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, 0x20(%rsp)
callq 0x955a5
testb %al, %al
jne 0x2ccf11
xorpd %xmm1, %xmm1
movapd 0x20(%rsp), %xmm0
callq 0x955ed
testb %al, %al
je 0x2cd01b
movsd 0xc0(%rsp), %xmm0
movapd 0x20(%rsp), %xmm2
addsd %xmm2, %xmm0
ucomisd 0x192fc(%rip), %xmm0    # 0x2e6228
jb 0x2ccf49
divsd %xmm0, %xmm2
movapd %xmm0, %xmm1
movsd 0xa8(%rsp), %xmm0
ucomisd %xmm2, %xmm0
movapd %xmm1, %xmm0
jae 0x2ccf7a
movsd 0x48(%rsp), %xmm1
mulsd 0xb8(%rsp), %xmm1
movsd %xmm1, 0x48(%rsp)
incq %rbp
addq $0x8, %rbx
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x60(%rsp)
jmp 0x2ccc2d
movapd %xmm0, %xmm1
movsd 0x88(%rsp), %xmm0
callq 0x955e2
testb %al, %al
jne 0x2ccf9a
movsd 0x58(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
jmp 0x2ccfa6
movsd 0x58(%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
andpd 0x3ed9a(%rip), %xmm0    # 0x30bd50
divsd %xmm2, %xmm0
movsd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x2ccbaa
jmp 0x2ccfdb
movsd 0x8(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
addsd %xmm3, %xmm2
mulsd 0x28e71(%rip), %xmm2    # 0x2f5e58
movsd %xmm2, 0x8(%rsp)
leaq 0xb8ecc(%rip), %rsi     # 0x385ec0
movq 0x40(%rsp), %rdi
movl $0xa9, %edx
callq 0x936f9
movsd 0x8(%rsp), %xmm0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x16af46(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x17fe7(%rip), %rsi     # 0x2e5013
leaq 0xb8ea8(%rip), %rdx     # 0x385edb
leaq 0xb8eec(%rip), %rcx     # 0x385f26
leaq 0xb8e7f(%rip), %r8      # 0x385ec0
pushq $0x7c
jmp 0x2cd06d
movq 0x16af1c(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x17fbd(%rip), %rsi     # 0x2e5013
leaq 0xb8ed3(%rip), %rdx     # 0x385f30
leaq 0xb8f22(%rip), %rcx     # 0x385f86
leaq 0xb8e55(%rip), %r8      # 0x385ec0
pushq $0x2b
popq %r9
xorl %eax, %eax
callq 0x17a50
callq 0x17390