// File: /workspace/github_c_makefile_star2_O3/sheneman[P]clearcut/dmat.c
// Function: NJ_output_matrix
void
NJ_output_matrix(NJ_ARGS *nj_args,
		 DMAT *dmat) {
  
  FILE *fp = NULL;
  long int i, j;


  
  /* if we haven't specieid matrixout, return immediately */
  if(!nj_args->matrixout) {
    return;
  }
  
  /* open the specified matrix file for writing */
  fp = fopen(nj_args->matrixout, "w");
  if(!fp) {
    fprintf(stderr, "Clearcut: Could not open matrix file %s for output.\n", nj_args->matrixout);
    return;
  }

  /* output the number of taxa in the matrix */
  fprintf(fp, "   %ld\n", dmat->size);

  fprintf(fp, "%s\n", dmat->taxaname[0]); // print the first taxon name outside of the main loop

  for(i=1;i<dmat->size;i++) {
    
    /* output taxaname */
    fprintf(fp, "%s\t", dmat->taxaname[i]);

    for(j=0;j<i;j++) {
      if(nj_args->expdist) {  /* exponential notation (or not) */
	fprintf(fp, "%e ", dmat->val[NJ_MAP(j,i,dmat->size)]);  
      } else {
	fprintf(fp, "%f ", dmat->val[NJ_MAP(j,i,dmat->size)]);
      }
    }
    
    fprintf(fp, "\n");
  }

#ifdef FULL_SYMMETRIC_MATRIX 

  /* output the number of taxa in the matrix */
  fprintf(fp, "   %ld\n", dmat->size);
  for(i=0;i<dmat->size;i++) {
    
    /* output taxaname */
    fprintf(fp, "%s\t", dmat->taxaname[i]);

    for(j=0;j<dmat->size;j++) {
      if(i>j) {
	if(nj_args->expdist) {  /* exponential notation (or not) */
	  fprintf(fp, "%e ", dmat->val[NJ_MAP(j,i,dmat->size)]);  
	} else {
	  fprintf(fp, "%f ", dmat->val[NJ_MAP(j,i,dmat->size)]);
	}
      } else if(i<j) {
	if(nj_args->expdist) {  /* exponential notation (or not) */
	  fprintf(fp, "%e ", dmat->val[NJ_MAP(i,j,dmat->size)]);
	} else {
	  fprintf(fp, "%f ", dmat->val[NJ_MAP(i,j,dmat->size)]);
	}
      } else {
	if(nj_args->expdist) {  /* exponential notation (or not) */
	  fprintf(fp, "%e ", 0.0);
	} else {
	  fprintf(fp, "%f ", 0.0);
	}
      }
    }
    
    fprintf(fp, "\n");
  }

#endif // FULL_SYMMETRIC_MATRIX
  
  /* close the file here */
  if(fp) {
    fclose(fp);
  }
  
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0x601f
movq %rsi, %r14
leaq 0x2347(%rip), %rsi      # 0x824d
callq 0x2200
testq %rax, %rax
je 0x6013
movq %rax, %r15
movq %rbx, (%rsp)
movq 0x8(%r14), %rdx
leaq 0x28f0(%rip), %rsi      # 0x8816
movq %rax, %rdi
xorl %eax, %eax
callq 0x2180
movq 0x10(%r14), %rax
movq (%rax), %rdx
leaq 0x239c(%rip), %rsi      # 0x82da
movq %r15, %rdi
xorl %eax, %eax
callq 0x2180
cmpq $0x2, 0x8(%r14)
jl 0x5ffd
movl $0x1, %r13d
movq 0x10(%r14), %rax
movq (%rax,%r13,8), %rdx
movq %r15, %rdi
leaq 0x28b3(%rip), %rsi      # 0x881e
xorl %eax, %eax
callq 0x2180
movq $-0x1, %rbp
xorl %r12d, %r12d
movq %r15, %rbx
movq (%rsp), %r15
movq 0x8(%r14), %rax
leaq (,%rax,2), %rax
addq %rbp, %rax
imulq %r12, %rax
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
andq $-0x2, %rcx
addq %rcx, %rcx
addq 0x18(%r14), %rcx
cmpl $0x0, 0x64(%r15)
xorps %xmm0, %xmm0
cvtss2sd (%rcx,%r13,4), %xmm0
leaq 0x2862(%rip), %rsi      # 0x8822
leaq 0x285f(%rip), %rax      # 0x8826
cmoveq %rax, %rsi
movq %rbx, %rdi
movb $0x1, %al
callq 0x2180
incq %r12
decq %rbp
cmpq %r12, %r13
jne 0x5f83
movl $0xa, %edi
movq %rbx, %rsi
callq 0x2150
incq %r13
cmpq 0x8(%r14), %r13
movq %rbx, %r15
jl 0x5f59
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20d0
addq $0x10, %rbx
movq %rbx, %rdi
callq 0x268f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop