// File: /workspace/github_c_makefile_star2_O2/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 0x5277
movq %rsi, %r14
leaq 0x2080(%rip), %rsi      # 0x720d
callq 0x21f0
testq %rax, %rax
je 0x5286
movq %rax, %r15
movq 0x8(%r14), %rdx
leaq 0x2645(%rip), %rsi      # 0x77ee
movq %rax, %rdi
xorl %eax, %eax
callq 0x2180
movq 0x10(%r14), %rax
movq (%rax), %rdx
leaq 0x20d9(%rip), %rsi      # 0x729a
movq %r15, %rdi
xorl %eax, %eax
callq 0x2180
pushq $0x1
popq %r13
cmpq 0x8(%r14), %r13
jge 0x5261
movq 0x10(%r14), %rax
movq (%rax,%r13,8), %rdx
movq %r15, %rdi
leaq 0x260b(%rip), %rsi      # 0x77f6
xorl %eax, %eax
callq 0x2180
pushq $-0x1
popq %rbp
xorl %r12d, %r12d
cmpq %r12, %r13
je 0x524e
movq 0x8(%r14), %rax
leaq (,%rax,2), %rax
addq %rbp, %rax
imulq %r12, %rax
cqto
pushq $0x2
popq %rcx
idivq %rcx
shlq $0x2, %rax
addq 0x18(%r14), %rax
cmpl $0x0, 0x64(%rbx)
cvtss2sd (%rax,%r13,4), %xmm0
leaq 0x25c9(%rip), %rsi      # 0x77fa
leaq 0x25c6(%rip), %rax      # 0x77fe
cmoveq %rax, %rsi
movq %r15, %rdi
movb $0x1, %al
callq 0x2180
incq %r12
decq %rbp
jmp 0x51f8
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0x2150
incq %r13
jmp 0x51cf
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20d0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6d6b(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq 0x10(%rbx), %rdx
leaq 0x251e(%rip), %rsi      # 0x77b9
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2180