// File: /workspace/github_c_makefile_star2_O1/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 0x5e0c
movq %rsi, %r14
leaq 0x251a(%rip), %rsi      # 0x820d
callq 0x2200
testq %rax, %rax
je 0x5e00
movq %rax, %r15
movq %rbx, (%rsp)
movq 0x8(%r14), %rdx
leaq 0x2adb(%rip), %rsi      # 0x87ee
movq %rax, %rdi
xorl %eax, %eax
callq 0x2180
movq 0x10(%r14), %rax
movq (%rax), %rdx
leaq 0x256f(%rip), %rsi      # 0x829a
movq %r15, %rdi
xorl %eax, %eax
callq 0x2180
cmpq $0x2, 0x8(%r14)
jl 0x5dea
movl $0x1, %r13d
movq 0x10(%r14), %rax
movq (%rax,%r13,8), %rdx
movq %r15, %rdi
leaq 0x2a9e(%rip), %rsi      # 0x87f6
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
cmpl $0x0, 0x64(%r15)
leaq 0x2a61(%rip), %rsi      # 0x87fa
leaq 0x2a5e(%rip), %rax      # 0x87fe
cmoveq %rax, %rsi
andq $-0x2, %rcx
addq %rcx, %rcx
addq 0x18(%r14), %rcx
xorps %xmm0, %xmm0
cvtss2sd (%rcx,%r13,4), %xmm0
movq %rbx, %rdi
movb $0x1, %al
callq 0x2180
incq %r12
decq %rbp
cmpq %r12, %r13
jne 0x5d70
movl $0xa, %edi
movq %rbx, %rsi
callq 0x2150
incq %r13
cmpq 0x8(%r14), %r13
movq %rbx, %r15
jl 0x5d46
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 0x2651
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop