// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x70c8
jmp 0x727f
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x4161(%rip), %rsi      # 0xb238
callq 0x21c0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x710c
movq 0x7f0a(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x46a5(%rip), %rsi      # 0xb7a5
movb $0x0, %al
callq 0x2150
jmp 0x727f
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x46bb(%rip), %rsi      # 0xb7da
movb $0x0, %al
callq 0x2150
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdx
leaq 0x418b(%rip), %rsi      # 0xb2c7
movb $0x0, %al
callq 0x2150
movq $0x1, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x726d
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x466a(%rip), %rsi      # 0xb7e2
movb $0x0, %al
callq 0x2150
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x724a
movq -0x8(%rbp), %rax
cmpl $0x0, 0x64(%rax)
je 0x71ec
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x7010
movq -0x38(%rbp), %rdi
movq %rax, %rcx
movq -0x30(%rbp), %rax
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x4603(%rip), %rsi      # 0xb7e6
movb $0x1, %al
callq 0x2150
jmp 0x7237
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x7010
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movq -0x40(%rbp), %rax
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x45ba(%rip), %rsi      # 0xb7ea
movb $0x1, %al
callq 0x2150
jmp 0x7239
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x7187
movq -0x18(%rbp), %rdi
leaq 0x3fe1(%rip), %rsi      # 0xb236
movb $0x0, %al
callq 0x2150
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x714b
cmpq $0x0, -0x18(%rbp)
je 0x727d
movq -0x18(%rbp), %rdi
callq 0x20b0
jmp 0x727f
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)