// File: ncbi[P]amr/seq.cpp
// Function: Seq_sp::Peptide::getComplexityInt(unsigned long, unsigned long) const
double Peptide::getComplexityInt (size_t start,
                                  size_t end) const
{
  if (seq. empty ())
    return 0;

  const size_t maxAANum = 21;

  // diFreq[][], n
  size_t diFreq [maxAANum] [maxAANum];
  FOR (size_t, i, maxAANum)
    FOR (size_t, j, maxAANum)
      diFreq [i] [j] = 0;
  size_t n = 0;
  minimize (end, seq. size ());
  FOR_START (size_t, i, start + 1, end)
    {
      const size_t a = aa2num (seq [i - 1]);
      const size_t b = aa2num (seq [i]);
      if (   a < maxAANum 
          && b < maxAANum
         )
      {
        diFreq [a] [b] ++;
        n++;
      }
    }

  // Entropy
  double s = 0;
  FOR (size_t, i, maxAANum)
    FOR (size_t, j, maxAANum)
      if (diFreq [i] [j])
      {
       	const double p = (double) diFreq [i] [j] / (double) n;
       	s -= p * log (p);
      }
  ASSERT (s >= 0);

  return s;
}

// Assembly:
subq $0xf88, %rsp            # imm = 0xF88
movq %rdi, 0xf78(%rsp)
movq %rsi, 0xf70(%rsp)
movq %rdx, 0xf68(%rsp)
movq 0xf78(%rsp), %rdi
movq %rdi, 0x18(%rsp)
addq $0x28, %rdi
callq 0xdc60
testb $0x1, %al
jne 0xbd12b
jmp 0xbd13c
xorps %xmm0, %xmm0
movsd %xmm0, 0xf80(%rsp)
jmp 0xbd6db
movq $0x15, 0xf60(%rsp)
movq $0x0, 0x188(%rsp)
cmpq $0x15, 0x188(%rsp)
jae 0xbd1cb
movq $0x0, 0x180(%rsp)
cmpq $0x15, 0x180(%rsp)
jae 0xbd1b3
leaq 0x190(%rsp), %rax
imulq $0xa8, 0x188(%rsp), %rcx
addq %rcx, %rax
movq 0x180(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movq 0x180(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x180(%rsp)
jmp 0xbd16b
jmp 0xbd1b5
movq 0x188(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x188(%rsp)
jmp 0xbd154
movq 0x18(%rsp), %rdi
movq $0x0, 0x178(%rsp)
addq $0x28, %rdi
callq 0xd520
movq %rax, %rsi
leaq 0xf68(%rsp), %rdi
callq 0xd8000
movq 0xf70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rax
cmpq 0xf68(%rsp), %rax
jae 0xbd2df
movq 0x18(%rsp), %rdi
addq $0x28, %rdi
movq 0x170(%rsp), %rsi
subq $0x1, %rsi
callq 0xd7d0
movsbl (%rax), %edi
callq 0xbb2e0
movq 0x18(%rsp), %rdi
movq %rax, 0x168(%rsp)
addq $0x28, %rdi
movq 0x170(%rsp), %rsi
callq 0xd7d0
movsbl (%rax), %edi
callq 0xbb2e0
movq %rax, 0x160(%rsp)
cmpq $0x15, 0x168(%rsp)
jae 0xbd2c4
cmpq $0x15, 0x160(%rsp)
jae 0xbd2c4
leaq 0x190(%rsp), %rax
imulq $0xa8, 0x168(%rsp), %rcx
addq %rcx, %rax
movq 0x160(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x178(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x178(%rsp)
jmp 0xbd2c6
movq 0x170(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x170(%rsp)
jmp 0xbd209
xorps %xmm0, %xmm0
movsd %xmm0, 0x158(%rsp)
movq $0x0, 0x150(%rsp)
cmpq $0x15, 0x150(%rsp)
jae 0xbd447
movq $0x0, 0x148(%rsp)
cmpq $0x15, 0x148(%rsp)
jae 0xbd42c
leaq 0x190(%rsp), %rax
imulq $0xa8, 0x150(%rsp), %rcx
addq %rcx, %rax
movq 0x148(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0xbd411
movq 0x150(%rsp), %rax
imulq $0xa8, %rax, %rax
leaq 0x190(%rsp,%rax), %rax
movq 0x148(%rsp), %rcx
movq (%rax,%rcx,8), %xmm0
movaps 0x29d1a(%rip), %xmm3    # 0xe7090
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x29d1e(%rip), %xmm2    # 0xe70a0
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0x178(%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
divsd %xmm1, %xmm0
movsd %xmm0, 0x140(%rsp)
movsd 0x140(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x140(%rsp), %xmm0
callq 0xd5e0
movaps %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
movsd 0x158(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x158(%rsp)
jmp 0xbd413
movq 0x148(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x148(%rsp)
jmp 0xbd312
jmp 0xbd42e
movq 0x150(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x150(%rsp)
jmp 0xbd2f7
callq 0xd0a0
movl $0x0, (%rax)
movsd 0x158(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jae 0xbd6c9
callq 0xd8c0
cmpl $0x0, %eax
jne 0xbd6bf
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xdd50
movq 0x8(%rsp), %rdx
leaq 0x2afb2(%rip), %rsi     # 0xe8446
leaq 0xa0(%rsp), %rdi
callq 0xfae0
jmp 0xbd4a3
leaq 0x68(%rsp), %rdi
movl $0xe0b, %esi            # imm = 0xE0B
callq 0x11600
jmp 0xbd4b4
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0x11510
jmp 0xbd4d0
leaq 0x25cfa(%rip), %rdx     # 0xe31d1
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x114c0
jmp 0xbd4ee
leaq 0x27(%rsp), %rdi
movq %rdi, (%rsp)
callq 0xdd50
movq (%rsp), %rdx
leaq 0x2bbab(%rip), %rsi     # 0xe90b2
leaq 0x28(%rsp), %rdi
callq 0xfae0
jmp 0xbd513
leaq 0x2648a(%rip), %rdx     # 0xe39a4
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x114c0
jmp 0xbd52b
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x11510
jmp 0xbd547
leaq 0x2b2fd(%rip), %rdx     # 0xe884b
leaq 0x120(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x114c0
jmp 0xbd565
leaq 0x120(%rsp), %rdi
callq 0x173d0
jmp 0xbd574
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xbd6b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xbd6a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xbd699
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xbd68c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xbd675
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xbd66b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xbd661
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xbd654
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x120(%rsp), %rdi
callq 0xdf08
leaq 0x100(%rsp), %rdi
callq 0xdf08
leaq 0x48(%rsp), %rdi
callq 0xdf08
leaq 0x28(%rsp), %rdi
callq 0xdf08
leaq 0x27(%rsp), %rdi
callq 0xd7a0
leaq 0xe0(%rsp), %rdi
callq 0xdf08
leaq 0xc0(%rsp), %rdi
callq 0xdf08
leaq 0x68(%rsp), %rdi
callq 0xdf08
leaq 0xa0(%rsp), %rdi
callq 0xdf08
leaq 0x9f(%rsp), %rdi
callq 0xd7a0
jmp 0xbd6ec
movl $0x1, %edi
callq 0xd8e0
movsd 0x158(%rsp), %xmm0
movsd %xmm0, 0xf80(%rsp)
movsd 0xf80(%rsp), %xmm0
addq $0xf88, %rsp            # imm = 0xF88
retq
movq 0x90(%rsp), %rdi
callq 0xdd40
nopl (%rax)