// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rdi
pushq $0x48
popq %rsi
callq 0x2160
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x26f6
movq (%r14), %r15
movups (%r14), %xmm0
movq 0x8(%rsp), %rbx
movups %xmm0, (%rbx)
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x2160
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x26f6
movq %rax, %r12
xorl %ebp, %ebp
testq %r15, %r15
movl $0x0, %ebx
cmovgq %r15, %rbx
pushq $0x1
popq %r13
cmpq %rbp, %rbx
je 0x261a
movq 0x10(%r14), %rax
movq (%rax,%rbp,8), %rdi
callq 0x20e0
leaq 0x1(%rax), %rdi
movq %r13, %rsi
callq 0x2160
movq %rax, (%r12,%rbp,8)
incq %rbp
testq %rax, %rax
jne 0x25eb
jmp 0x26f6
leaq 0x1(%r15), %rax
imulq %r15, %rax
pushq $0x2
popq %rcx
cqto
idivq %rcx
pushq $0x4
popq %rsi
movq %rax, %rdi
callq 0x2160
movq %rax, %r13
movq 0x8(%rsp), %rax
movq %r13, 0x18(%rax)
testq %r13, %r13
je 0x26f6
pushq $0x4
popq %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2160
movq 0x8(%rsp), %rbx
movq %rax, 0x10(%rsp)
movq %rax, 0x28(%rbx)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2160
movq %rax, %rbp
movq %rax, 0x30(%rbx)
xorl %ebx, %ebx
cmpq %r15, %rbx
jge 0x2698
movq (%r12,%rbx,8), %rdi
movq 0x10(%r14), %rax
movq (%rax,%rbx,8), %rsi
callq 0x2090
incq %rbx
movq (%r14), %r15
jmp 0x267a
movq 0x20(%r14), %rsi
leaq 0x1(%r15), %rax
imulq %r15, %rax
cqto
pushq $0x2
popq %rcx
idivq %rcx
leaq (,%rax,4), %rdx
movq %r13, %rdi
callq 0x21b0
movq 0x38(%r14), %rsi
shlq $0x2, %r15
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rdx
callq 0x21b0
movq 0x40(%r14), %rsi
movq %rbp, %rdi
movq %r15, %rdx
callq 0x21b0
movq 0x8(%rsp), %rax
movq %r13, 0x20(%rax)
movq %rbx, 0x38(%rax)
movq %rbp, 0x40(%rax)
jmp 0x271e
movq 0x98fb(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x4bdf(%rip), %rdi      # 0x72e6
pushq $0x33
popq %rsi
pushq $0x1
popq %rdx
callq 0x2230
movq 0x8(%rsp), %rdi
callq 0x2ebf
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq