// File: /workspace/github_c_makefile_star2_O0/sheneman[P]clearcut/dist.c
// Function: NJ_DNA_k2p_correction
void
NJ_DNA_k2p_correction(DMAT *dmat,
		      NJ_alignment *alignment) {

  long int i, j;
  float P;  /* proportion of transitions   */
  float Q;  /* proportion of transversions */
  long int nucleotides;
  long int transitions, transversions;
  float dist;
  float log_x = 0.0;  /* the params for the first log  */
  float log_y = 0.0;  /* the params for the second log */

  int blowup;   /* a flag to specify if we have a log blowup */

  
  for(i=0;i<dmat->size;i++) {
    for(j=i+1;j<dmat->size;j++) {

      blowup = 0;

      /* count the number of transitions and transversions */
      NJ_DNA_count_tt(alignment, i, j, &transitions, &transversions, &nucleotides);

      if(!nucleotides) {   /* sequences have no non-ambiguous overlap in alignment */
	P = 0.0;
	Q = 0.0;
      } else {
	P = (float)transitions   / (float)nucleotides;
	Q = (float)transversions / (float)nucleotides;
      }

      /* the first log blows up if 2*P+Q = 1.0 */
      if(NJ_FLT_EQ((2.0 * P + Q), 1.0)) {
	blowup = 1;
      } else {
	if( NJ_FLT_LT(1.0 - 2.0*P - Q, 0.0) ) {
	  blowup = 1;
	} else {
	  log_x = log(1.0 - 2.0*P - Q);
	}
      }

      /* the second log blows up if 2*Q >= 1.0 */
      if( NJ_FLT_EQ((2.0 * Q), 1.0) ||
	  NJ_FLT_GT((2.0 * Q), 1.0) ) {
	blowup = 1;
      } else {
	log_y = log(1.0 - 2.0*Q);
      }
      
      /* if our logarithms blow up, we just set the distance to the max */
      if(blowup) {
	dist = NJ_BIGDIST;
      } else {
	dist = (-0.5)*log_x - 0.25*log_y;
      }
      
      if(fabs(dist) < FLT_EPSILON) {
	dmat->val[NJ_MAP(i, j, dmat->size)] = 0.0;
      } else {
	dmat->val[NJ_MAP(i, j, dmat->size)] = dist;
      }
    }
  }
  
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x5cfd
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x5cea
movl $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x30(%rbp), %r9
callq 0x6250
cmpq $0x0, -0x30(%rbp)
jne 0x5a85
xorps %xmm0, %xmm0
movss %xmm0, -0x24(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x28(%rbp)
jmp 0x5aaf
cvtsi2ssq -0x38(%rbp), %xmm0
cvtsi2ssq -0x30(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x24(%rbp)
cvtsi2ssq -0x40(%rbp), %xmm0
cvtsi2ssq -0x30(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x28(%rbp)
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x28(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss 0x5553(%rip), %xmm1     # 0xb028
callq 0x6440
cmpl $0x0, %eax
je 0x5ae8
movl $0x1, -0x50(%rbp)
jmp 0x5b5e
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
addsd %xmm1, %xmm1
movsd 0x550b(%rip), %xmm0     # 0xb008
subsd %xmm1, %xmm0
movss -0x28(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x6490
cmpl $0x0, %eax
je 0x5b28
movl $0x1, -0x50(%rbp)
jmp 0x5b5c
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
addsd %xmm1, %xmm1
movsd 0x54cb(%rip), %xmm0     # 0xb008
subsd %xmm1, %xmm0
movss -0x28(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm0
callq 0x2120
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x48(%rbp)
jmp 0x5b5e
movss -0x28(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x54a1(%rip), %xmm0     # 0xb010
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss 0x54a9(%rip), %xmm1     # 0xb028
callq 0x6440
cmpl $0x0, %eax
jne 0x5bb4
movss -0x28(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x5476(%rip), %xmm0     # 0xb010
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss 0x547e(%rip), %xmm1     # 0xb028
callq 0x61f0
cmpl $0x0, %eax
je 0x5bbd
movl $0x1, -0x50(%rbp)
jmp 0x5be4
movss -0x28(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
addsd %xmm1, %xmm1
movsd 0x5436(%rip), %xmm0     # 0xb008
subsd %xmm1, %xmm0
callq 0x2120
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x5bf9
movss 0x57ca(%rip), %xmm0     # 0xb3bc
movss %xmm0, -0x44(%rbp)
jmp 0x5c47
movss -0x48(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x4c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x57dd(%rip), %xmm1     # 0xb3f0
mulsd %xmm2, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x57b2(%rip), %xmm2     # 0xb3e8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movaps 0x53d9(%rip), %xmm0     # 0xb030
pand %xmm0, %xmm1
movsd 0x53b5(%rip), %xmm0     # 0xb018
ucomisd %xmm1, %xmm0
jbe 0x5c9b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x60d0
movq %rax, %rcx
movq -0x58(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
jmp 0x5cd7
movss -0x44(%rbp), %xmm0
movss %xmm0, -0x64(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x60d0
movss -0x64(%rbp), %xmm0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movss %xmm0, (%rax,%rcx,4)
jmp 0x5cd9
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x5a36
jmp 0x5cec
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x5a18
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)