// File: /workspace/github_c_makefile_star2_O3/sheneman[P]clearcut/dist.c
// Function: NJ_compute_dmat
DMAT *
NJ_compute_dmat(NJ_ARGS *nj_args,
		NJ_alignment *alignment) {

  DMAT *dmat;
  long int i;
  
  
  /* allocate distance matrix here */
  dmat = (DMAT *)calloc(1, sizeof(DMAT));
  if(!dmat) {
    fprintf(stderr, "Clearcut: Memory allocation error in NJ_compute_dmat()\n");
    return(NULL);
  }
  
  dmat->ntaxa = alignment->nseq;
  dmat->size  = alignment->nseq;

  /* allocate memory to hold the taxa names */
  dmat->taxaname = (char **)calloc(alignment->nseq, sizeof(char *));
  if(!dmat->taxaname) {
    fprintf(stderr, "Clearcut: Memory allocation error in NJ_compute_dmat()\n");
    return(NULL);
  }
  
  /* copy sequence titles */
  for(i=0;i<alignment->nseq;i++) {
    dmat->taxaname[i] = (char *)calloc(strlen(alignment->titles[i])+1, sizeof(char));
    if(!dmat->taxaname[i]) {
      fprintf(stderr, "Clearcut: Memory allocation error in NJ_compute_dmat()\n");
      return(NULL);
    }

    strncpy(dmat->taxaname[i], alignment->titles[i], strlen(alignment->titles[i]));
  }

  /* allocate val matrix in dmat */
  dmat->val = (float *)calloc(dmat->ntaxa*dmat->ntaxa, sizeof(float));
  if(!dmat->val) {
    fprintf(stderr, "Clearcut: Memory allocation error in NJ_compute_dmat()\n");
    return(NULL);
  }

  /* now lets allocate space for the r and r2 columns */
  dmat->r  = (float *)calloc(dmat->ntaxa, sizeof(float));
  dmat->r2 = (float *)calloc(dmat->ntaxa, sizeof(float));

  /* track some memory addresses */
  dmat->rhandle   = dmat->r;
  dmat->r2handle  = dmat->r2;
  dmat->valhandle = dmat->val;
  
  /* apply model correction to matrix */
  switch(nj_args->correction_model) {

  case NJ_MODEL_JUKES:
    
    if(nj_args->dna_flag) {
      NJ_DNA_jc_correction(dmat, alignment);
    } else if(nj_args->protein_flag) {
      NJ_PROTEIN_jc_correction(dmat, alignment);
    } else {
      fprintf(stderr, "Clearcut: Need to know sequence type for Jukes-Cantor model correction.\n");
      return(NULL);
    }

    break;

  case NJ_MODEL_KIMURA:

    if(nj_args->dna_flag) {
      NJ_DNA_k2p_correction(dmat, alignment);
    } else if(nj_args->protein_flag) {
      NJ_PROTEIN_kimura_correction(dmat, alignment);
    } else {
      fprintf(stderr, "Clearcut: Need to know sequence type for Kimura model correction.\n");
      return(NULL);
    }

    break;

  case NJ_MODEL_NONE:

    NJ_no_correction(dmat, alignment);

    break;

  default:
    fprintf(stderr, "Clearcut: Invalid distance correction model.\n");
    return(NULL);
  }
  
  return(dmat);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r15
movl $0x1, %edi
movl $0x48, %esi
callq 0x2160
testq %rax, %rax
je 0x4c4b
movq %rax, %rbx
movq (%r14), %r12
movq %r12, (%rax)
movq %r12, 0x8(%rax)
movl $0x8, %esi
movq %r12, %rdi
callq 0x2160
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x4c52
movq %r15, 0x8(%rsp)
movq %r14, (%rsp)
movq %rbx, 0x10(%rsp)
testq %r12, %r12
jle 0x4b8b
movq %rax, %r13
movq (%rsp), %rax
movq 0x10(%rax), %r14
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
callq 0x20e0
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x2160
movq %rax, (%r13,%rbx,8)
testq %rax, %rax
je 0x4c60
movq %rax, %rbp
movq (%r14,%rbx,8), %r15
movq %r15, %rdi
callq 0x20e0
movq %rbp, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2070
incq %rbx
cmpq %rbx, %r12
jne 0x4b41
movq %r12, %rdi
imulq %r12, %rdi
movl $0x4, %esi
callq 0x2160
movq 0x10(%rsp), %rbx
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x4c59
movq %rax, %r13
movl $0x4, %esi
movq %r12, %rdi
callq 0x2160
movq %rax, %r15
movq %rax, 0x28(%rbx)
movl $0x4, %esi
movq %r12, %rdi
callq 0x2160
movq %rax, 0x30(%rbx)
movq %r15, 0x38(%rbx)
movq %rax, 0x40(%rbx)
movq %r13, 0x20(%rbx)
movq 0x8(%rsp), %rcx
movl 0x4c(%rcx), %eax
cmpl $0x64, %eax
je 0x4c0d
cmpl $0x66, %eax
movq (%rsp), %rsi
je 0x4c1b
cmpl $0x65, %eax
jne 0x4c67
cmpl $0x0, 0x40(%rcx)
je 0x4c2b
movq %rbx, %rdi
callq 0x4c8e
jmp 0x4c7c
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x52bf
jmp 0x4c7c
cmpl $0x0, 0x40(%rcx)
je 0x4c3b
movq %rbx, %rdi
callq 0x4edc
jmp 0x4c7c
cmpl $0x0, 0x44(%rcx)
je 0x4c6e
movq %rbx, %rdi
callq 0x4da6
jmp 0x4c7c
cmpl $0x0, 0x44(%rcx)
je 0x4c75
movq %rbx, %rdi
callq 0x50f2
jmp 0x4c7c
callq 0x241b
jmp 0x4c7a
callq 0x23ff
jmp 0x4c7a
callq 0x23c7
jmp 0x4c7a
callq 0x23e3
jmp 0x4c7a
callq 0x23ab
jmp 0x4c7a
callq 0x238f
jmp 0x4c7a
callq 0x2373
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq