// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x1, %edi
movl $0x48, %esi
callq 0x2130
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x539f
movq 0x9c77(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x60b8(%rip), %rsi      # 0xb443
movb $0x0, %al
callq 0x2150
movq $0x0, -0x8(%rbp)
jmp 0x56be
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x2130
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x5408
movq 0x9c0e(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x604f(%rip), %rsi      # 0xb443
movb $0x0, %al
callq 0x2150
movq $0x0, -0x8(%rbp)
jmp 0x56be
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x54f0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x20c0
movq %rax, %rdi
addq $0x1, %rdi
movl $0x1, %esi
callq 0x2130
movq %rax, %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x5492
movq 0x9b84(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x5fc5(%rip), %rsi      # 0xb443
movb $0x0, %al
callq 0x2150
movq $0x0, -0x8(%rbp)
jmp 0x56be
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x20c0
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %rax, %rdx
callq 0x2050
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x5410
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
imulq (%rax), %rdi
movl $0x4, %esi
callq 0x2130
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x5544
movq 0x9ad2(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x5f13(%rip), %rsi      # 0xb443
movb $0x0, %al
callq 0x2150
movq $0x0, -0x8(%rbp)
jmp 0x56be
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl $0x4, %esi
movq %rsi, -0x48(%rbp)
callq 0x2130
movq -0x48(%rbp), %rsi
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x2130
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x40(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %eax
movl %eax, -0x3c(%rbp)
subl $0x64, %eax
je 0x5685
jmp 0x55b8
movl -0x3c(%rbp), %eax
subl $0x65, %eax
je 0x55cf
jmp 0x55c2
movl -0x3c(%rbp), %eax
subl $0x66, %eax
je 0x562d
jmp 0x5694
movq -0x10(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x55e8
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x56d0
jmp 0x5628
movq -0x10(%rbp), %rax
cmpl $0x0, 0x44(%rax)
je 0x5601
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5880
jmp 0x5626
movq 0x99f0(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x5e69(%rip), %rsi      # 0xb47b
movb $0x0, %al
callq 0x2150
movq $0x0, -0x8(%rbp)
jmp 0x56be
jmp 0x5628
jmp 0x56b6
movq -0x10(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x5646
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x59f0
jmp 0x5683
movq -0x10(%rbp), %rax
cmpl $0x0, 0x44(%rax)
je 0x565f
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5d10
jmp 0x5681
movq 0x9992(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x5e54(%rip), %rsi      # 0xb4c4
movb $0x0, %al
callq 0x2150
movq $0x0, -0x8(%rbp)
jmp 0x56be
jmp 0x5683
jmp 0x56b6
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5f10
jmp 0x56b6
movq 0x995d(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x5e62(%rip), %rsi      # 0xb507
movb $0x0, %al
callq 0x2150
movq $0x0, -0x8(%rbp)
jmp 0x56be
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)