// File: /workspace/github_c_makefile_star2_O1/sheneman[P]clearcut/clearcut.c
// Function: NJ_dup_dmat
DMAT *
NJ_dup_dmat(DMAT *src) {
  
  long int i;
  DMAT *dest;
  
  /* allocate the resulting distance matrix */
  dest = (DMAT *)calloc(1, sizeof(DMAT));
  if(!dest) {
    fprintf(stderr, "Clearcut: Memory allocation error in NJ_dup_dmat()\n");
    goto XIT_BAD;
  }

  dest->ntaxa = src->ntaxa;
  dest->size  = src->size;
  
  /* allocate space for array of pointers to taxanames */
  dest->taxaname = (char **)calloc(dest->ntaxa, sizeof(char *));
  if(!dest->taxaname) {
    fprintf(stderr, "Clearcut: Memory allocation error in NJ_dup_dmat()\n");
    goto XIT_BAD;
  }

  /* allocate space for the taxanames themselves */
  for(i=0;i<src->ntaxa;i++) {
    dest->taxaname[i] = (char *)calloc(strlen(src->taxaname[i])+1, sizeof(char));
    if(!dest->taxaname[i]) {
      fprintf(stderr, "Clearcut: Memory allocation error in NJ_dup_dmat()\n");
      goto XIT_BAD;
    }
  }
  
  /* allocate space for the distance values */
  dest->val = (float *)calloc(NJ_NCELLS(src->ntaxa), sizeof(float));
  if(!dest->val) {
    fprintf(stderr, "Clearcut: Memory allocation error in NJ_dup_dmat()\n");
    goto XIT_BAD;
  }
  
  /* allocate space for the r and r2 vectors */
  dest->r  = (float *)calloc(src->ntaxa, sizeof(float));
  dest->r2 = (float *)calloc(src->ntaxa, sizeof(float));
  
  /* copy titles */
  for(i=0;i<src->ntaxa;i++) {
    strcpy(dest->taxaname[i], src->taxaname[i]);
  }
  
  /* copy values */
  memcpy(dest->val, src->valhandle, NJ_NCELLS(src->ntaxa)*sizeof(float));
  
  /* copy r and r2 */
  memcpy(dest->r,  src->rhandle,  src->ntaxa*sizeof(float));
  memcpy(dest->r2, src->r2handle, src->ntaxa*sizeof(float));
  
  /* track some memory addresses */
  dest->valhandle = dest->val;
  dest->rhandle   = dest->r;
  dest->r2handle  = dest->r2;
  
  return(dest);
  
 XIT_BAD:
  
  /* free what we may have allocated */
  NJ_free_dmat(dest);
  
  return(NULL);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movl $0x1, %edi
movl $0x48, %esi
callq 0x2160
movq %rax, %rbx
testq %rax, %rax
je 0x2f0d
movq (%r14), %r15
movq %r15, (%rbx)
movq 0x8(%r14), %rax
movq %rax, 0x8(%rbx)
movl $0x8, %esi
movq %r15, %rdi
callq 0x2160
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x2f0d
testq %r15, %r15
jle 0x2e27
xorl %r12d, %r12d
movq 0x10(%r14), %rax
movq (%rax,%r12,8), %rdi
callq 0x20e0
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x2160
movq 0x10(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x10(%rbx), %rax
cmpq $0x0, (%rax,%r12,8)
je 0x2f0d
incq %r12
cmpq %r12, %r15
jne 0x2ded
leaq 0x1(%r15), %rax
imulq %r15, %rax
movq %rax, %rdi
shrq $0x3f, %rdi
addq %rax, %rdi
sarq %rdi
movl $0x4, %esi
callq 0x2160
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x2f0d
movl $0x4, %esi
movq %r15, %rdi
callq 0x2160
movq %rax, 0x28(%rbx)
movl $0x4, %esi
movq %r15, %rdi
callq 0x2160
movq %rax, 0x30(%rbx)
movq (%r14), %rax
testq %rax, %rax
jle 0x2ea0
xorl %r15d, %r15d
movq 0x10(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq 0x10(%r14), %rax
movq (%rax,%r15,8), %rsi
callq 0x2090
incq %r15
movq (%r14), %rax
cmpq %rax, %r15
jl 0x2e80
movq 0x18(%rbx), %rdi
movq 0x20(%r14), %rsi
leaq 0x1(%rax), %rcx
imulq %rax, %rcx
movq %rcx, %rdx
shrq $0x3f, %rdx
addq %rcx, %rdx
addq %rdx, %rdx
andq $-0x4, %rdx
callq 0x21b0
movq 0x28(%rbx), %rdi
movq (%r14), %rdx
movq 0x38(%r14), %rsi
shlq $0x2, %rdx
callq 0x21b0
movq 0x30(%rbx), %rdi
movq (%r14), %rdx
movq 0x40(%r14), %rsi
shlq $0x2, %rdx
callq 0x21b0
movq 0x18(%rbx), %rax
movq %rax, 0x20(%rbx)
movups 0x28(%rbx), %xmm0
movups %xmm0, 0x38(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rbx, %rdi
callq 0x2260
xorl %ebx, %ebx
jmp 0x2efe