// File: /workspace/github_c_makefile_star2_O1/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 0x4a7c
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 0x4a83
movq %r12, 0x8(%rsp)
movq %r15, (%rsp)
movq %rbx, 0x10(%rsp)
cmpq $0x0, (%r14)
jle 0x49b1
movq %rax, %r13
movq 0x10(%r14), %rbx
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rdi
callq 0x20e0
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x2160
movq %rax, (%r13,%r12,8)
testq %rax, %rax
je 0x4a91
movq %rax, %rbp
movq (%rbx,%r12,8), %r15
movq %r15, %rdi
callq 0x20e0
movq %rbp, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2070
incq %r12
cmpq (%r14), %r12
jl 0x4967
movq 0x8(%rsp), %r12
movq %r12, %rdi
imulq %r12, %rdi
movl $0x4, %esi
callq 0x2160
movq 0x10(%rsp), %rbx
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x4a8a
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 (%rsp), %rcx
movl 0x4c(%rcx), %eax
cmpl $0x64, %eax
je 0x4a36
cmpl $0x66, %eax
je 0x4a43
cmpl $0x65, %eax
jne 0x4a98
cmpl $0x0, 0x40(%rcx)
je 0x4a56
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4abf
jmp 0x4aad
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5125
jmp 0x4aad
cmpl $0x0, 0x40(%rcx)
je 0x4a69
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4d1e
jmp 0x4aad
cmpl $0x0, 0x44(%rcx)
je 0x4a9f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4bd8
jmp 0x4aad
cmpl $0x0, 0x44(%rcx)
je 0x4aa6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4f42
jmp 0x4aad
callq 0x241b
jmp 0x4aab
callq 0x23ff
jmp 0x4aab
callq 0x23c7
jmp 0x4aab
callq 0x23e3
jmp 0x4aab
callq 0x23ab
jmp 0x4aab
callq 0x238f
jmp 0x4aab
callq 0x2373
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq