// File: /workspace/github_c_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movl $0x1, %edi
movl $0x48, %esi
callq 0x2160
movq %rax, %rbx
testq %rax, %rax
je 0x2f2d
movq (%r14), %r15
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movl $0x8, %esi
movq %r15, %rdi
callq 0x2160
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x2f2d
movq %rax, %r12
testq %r15, %r15
jle 0x2e3a
movq 0x10(%r14), %r13
xorl %ebp, %ebp
movq (%r13,%rbp,8), %rdi
callq 0x20e0
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x2160
movq %rax, (%r12,%rbp,8)
testq %rax, %rax
je 0x2f2d
incq %rbp
cmpq %rbp, %r15
jne 0x2e0d
leaq 0x1(%r15), %rax
imulq %r15, %rax
movq %rax, %rbp
shrq $0x3f, %rbp
addq %rax, %rbp
sarq %rbp
movl $0x4, %esi
movq %rbp, %rdi
callq 0x2160
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x2f2d
movq %rax, %r13
movl $0x4, %esi
movq %r15, %rdi
callq 0x2160
movq %rax, 0x10(%rsp)
movq %rax, 0x28(%rbx)
movl $0x4, %esi
movq %r15, %rdi
callq 0x2160
movq %rax, 0x8(%rsp)
movq %rax, 0x30(%rbx)
testq %r15, %r15
jle 0x2ed0
xorl %ebp, %ebp
movq (%r12,%rbp,8), %rdi
movq 0x10(%r14), %rax
movq (%rax,%rbp,8), %rsi
callq 0x2090
incq %rbp
movq (%r14), %r15
cmpq %r15, %rbp
jl 0x2e9f
leaq 0x1(%r15), %rax
imulq %r15, %rax
movq %rax, %rbp
shrq $0x3f, %rbp
addq %rax, %rbp
sarq %rbp
movq 0x20(%r14), %rsi
shlq $0x2, %rbp
movq %r13, %rdi
movq %rbp, %rdx
callq 0x21b0
movq 0x38(%r14), %rsi
shlq $0x2, %r15
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
callq 0x21b0
movq 0x40(%r14), %rsi
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r15, %rdx
callq 0x21b0
movq %r13, 0x20(%rbx)
movq %r12, 0x38(%rbx)
movq %r14, 0x40(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x2260
xorl %ebx, %ebx
jmp 0x2f1b