// File: /workspace/github_c_makefile_star2_O2/yhg926[P]public_kssd/command_dist.c
// Function: dist_print_nobin
void dist_print_nobin (const char *distout_dir,unsigned int ref_num, unsigned int qry_num, unsigned int*ref_ctx_ct_list,
      unsigned int*qry_ctx_ct_list, int num_cof_batch, char (*refname)[PATHLEN], char (*qryfname)[PATHLEN],dist_opt_val_t *opt_val)
{
 if( opt_val->shared_kmerpath[0] != '\0') strcpy(full_distfcode, opt_val->shared_kmerpath );
  else sprintf(full_distfcode,"%s/sharedk_ct.dat",distout_dir);
  int fd;
  struct stat s;
  fd = open (full_distfcode, O_RDONLY);
  check (fd < 0, "open %s failed: %s", full_distfcode, strerror (errno));
  fstat (fd, & s);
  ctx_obj_ct_t * ctx_obj_ct = mmap(0, s.st_size , PROT_READ, MAP_PRIVATE, fd, 0);
  check ( ctx_obj_ct == MAP_FAILED, "mmap %s failed: %s", full_distfcode, strerror (errno));
  close(fd);
 int p_fit_mem= opt_val->p;
 prt_line_t * prt_buf = malloc(ref_num * sizeof(prt_line_t));
 char distf[PATHLEN];
  sprintf(distf, "%s/distance.out", distout_dir);
 FILE *distfp = fopen(distf,"w") ;
  if( distfp == NULL ) err(errno,"dist_print_nobin():%s",distf);
 int num_mapping_distf = qry_num / num_cof_batch; int bnum_infile;
 print_ctrl_t outfield;
 outfield.metric = opt_val->metric ;
 outfield.pfield = opt_val->outfields;
 outfield.correction = opt_val->correction;
 outfield.dthreshold = opt_val->mut_dist_max;
 outfield.cmprsn_num = ref_num*qry_num;
#define MAX_CNAME_SIZE 30
 char header[2][3][MAX_CNAME_SIZE] = {
  {"Jaccard\tMashD","P-value(J)\tFDR(J)","Jaccard_CI\tMashD_CI" },
  {"ContainmentM\tAafD","P-value(C)\tFDR(C)","ContainmentM_CI\tAafD_CI" }
 };
 fprintf(distfp,"Qry\tRef\tShared_k|Ref_s|Qry_s");
 for( int i = 0 ; i<= (int)outfield.pfield ; i++)
  fprintf(distfp,"\t%s", header[outfield.metric][i]);
 fprintf(distfp,"\n");
#define NREF 1024
 int N_max = opt_val->num_neigb;
 if( (N_max > NREF) || (N_max > ref_num) ) { err(errno,"neighborN_max %d should smaller than NREF %d and ref_num %d",N_max,NREF,ref_num); } ;
 typedef struct { double metric; int rid; } Nref_stuct;
 Nref_stuct bestNref[NREF];
 for(int b=0;b<=num_mapping_distf;b++){
    if(b==num_mapping_distf){
      bnum_infile = qry_num % num_cof_batch ;
      if( bnum_infile == 0 ) continue;
    }else bnum_infile = num_cof_batch;
    size_t maplength = (size_t)bnum_infile * ref_num * sizeof(ctx_obj_ct_t);
  for(int qid = 0; qid < bnum_infile; qid++) {
   outfield.Y_size = qry_ctx_ct_list[b*num_cof_batch + qid];
   outfield.qname = qryfname[b*num_cof_batch + qid];
   outfield.qry_len = strlen(outfield.qname);
   llong offset = ((llong)b*num_cof_batch + qid)*ref_num;
   if( N_max ) {
    for (int i=0; i< N_max ;i++ ) bestNref[i] = (Nref_stuct){0, -1};
    for(int rid = 0; rid < ref_num; rid++) {
     unsigned int X_size = ref_ctx_ct_list[rid];
         unsigned int XnY_size = ctx_obj_ct[offset + rid];
         double metric = outfield.metric == Ctm ?
        (double) XnY_size / (X_size < outfield.Y_size ? X_size : outfield.Y_size) :
        (double) XnY_size / (X_size + outfield.Y_size - XnY_size) ;
     for(int i = N_max - 1 ; i>=0; i-- ){
      if(metric > bestNref[i].metric){
        bestNref[i+1] = bestNref[i];
        bestNref[i] = (Nref_stuct){ metric, rid };
      }
      else break;
     }
    }
#pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
    for( int i = 0 ; i< N_max;i++ ){
     if (bestNref[i].rid != -1)
       output_ctrl( ref_ctx_ct_list[ bestNref[i].rid ], ctx_obj_ct[offset + bestNref[i].rid], &outfield, refname[bestNref[i].rid], &prt_buf[i]);
     else prt_buf[i].len = 0 ;
    }
    for( int i = 0 ; i< N_max;i++ )
          if(prt_buf[i].len >1) fwrite(prt_buf[i].line, prt_buf[i].len, 1, distfp);;
   }
   else {
#pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
    for(int rid = 0; rid < ref_num; rid++)
     output_ctrl( ref_ctx_ct_list[ rid ], ctx_obj_ct[ offset + rid ], &outfield, refname[rid], &prt_buf[rid]);
    for(int rid = 0; rid < ref_num; rid++)
     if(prt_buf[rid].len >1) fwrite(prt_buf[rid].line, prt_buf[rid].len, 1, distfp);;
   }
  }
  munmap(ctx_obj_ct + (size_t)b*num_cof_batch*ref_num, maplength);
 }
 fclose(distfp);
  free(prt_buf);
 if(!opt_val->keep_shared_kmer) remove(full_distfcode);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4358, %rsp           # imm = 0x4358
movl %r9d, 0x1c(%rsp)
movq %r8, 0xa8(%rsp)
movq %rcx, %r15
movl %edx, 0x38(%rsp)
movq %rdi, %rbx
movq 0x43a0(%rsp), %rax
cmpb $0x0, 0x54b(%rax)
movl %esi, 0x10(%rsp)
je 0xa247
leaq 0x54b(%rax), %rsi
leaq 0x532c0(%rip), %rdi     # 0x5d500
callq 0x3080
jmp 0xa25f
leaq 0x532b2(%rip), %rdi     # 0x5d500
leaq 0xad8a(%rip), %rsi      # 0x14fdf
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0x5329a(%rip), %r13     # 0x5d500
movq %r13, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3380
movl %eax, %r12d
movl %eax, %ebp
shrl $0x1f, %ebp
callq 0x3060
movq %rax, %r14
movl (%rax), %edi
callq 0x3470
leaq 0x9f1f(%rip), %rsi      # 0x141af
movl %ebp, %edi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xb564
leaq 0x2c0(%rsp), %rbp
movl %r12d, %edi
movq %rbp, %rsi
callq 0x34a0
movq 0x30(%rbp), %rsi
pushq $0x1
popq %rdx
pushq $0x2
popq %rcx
xorl %edi, %edi
movl %r12d, %r8d
xorl %r9d, %r9d
callq 0x3150
xorl %ebp, %ebp
movq %rax, 0x48(%rsp)
cmpq $-0x1, %rax
sete %bpl
movq %r14, 0x8(%rsp)
movl (%r14), %edi
callq 0x3470
leaq 0x9ed6(%rip), %rsi      # 0x141c2
movl %ebp, %edi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xb564
movl %r12d, %edi
callq 0x3220
movl 0x10(%rsp), %r13d
movl %r13d, %ebp
imulq $0x404, %rbp, %rdi      # imm = 0x404
callq 0x3340
movq %rax, 0x28(%rsp)
leaq 0xac63(%rip), %rsi      # 0x14f86
leaq 0x1c0(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xa0b6(%rip), %rsi      # 0x143f5
movq %r12, %rdi
callq 0x33a0
testq %rax, %rax
je 0xa830
movq %rax, %rbx
movq 0x43a0(%rsp), %rcx
movl 0x440(%rcx), %r12d
movl %r12d, 0xc8(%rsp)
movslq 0x444(%rcx), %r14
movl %r14d, 0xcc(%rsp)
movb 0x448(%rcx), %al
movb %al, 0xd0(%rsp)
movsd 0x438(%rcx), %xmm0
movsd %xmm0, 0xd8(%rsp)
movl 0x38(%rsp), %eax
imull %r13d, %eax
movq %rax, 0xe8(%rsp)
leaq 0xa3d2(%rip), %rsi      # 0x14780
leaq 0x100(%rsp), %rdi
movl $0xb4, %edx
callq 0x32f0
leaq 0xaf91(%rip), %rdi      # 0x15358
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, 0x30(%rsp)
movq %rbx, %rcx
callq 0x3450
movq %r12, 0x60(%rsp)
imulq $0x5a, %r12, %rax
leaq (%rsp,%rax), %rbx
addq $0x100, %rbx            # imm = 0x100
leaq 0xaf80(%rip), %r13      # 0x15375
xorl %r12d, %r12d
cmpq %r14, %r12
jg 0xa418
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x32c0
incq %r12
addq $0x1e, %rbx
jmp 0xa3f8
pushq $0xa
popq %rdi
movq 0x30(%rsp), %r13
movq %r13, %rsi
callq 0x3250
movq 0x43a0(%rsp), %rax
movl 0x430(%rax), %r8d
cmpl $0x400, %r8d            # imm = 0x400
jg 0xa84d
cmpl 0x10(%rsp), %r8d
ja 0xa84d
movl 0x38(%rsp), %eax
xorl %edx, %edx
movl 0x1c(%rsp), %ecx
divl %ecx
leaq (,%rbp,4), %rsi
movq %rsi, 0x68(%rsp)
movslq %ecx, %r12
movq %r12, %rsi
imulq %rbp, %rsi
testl %r8d, %r8d
movl $0x0, %r14d
cmovgl %r8d, %r14d
movq %rax, 0x88(%rsp)
cltq
movq %rax, 0x90(%rsp)
movq %r14, 0x98(%rsp)
shlq $0x4, %r14
movq %r8, 0x10(%rsp)
shlq $0x4, %r8
leaq 0x350(%rsp), %rcx
leaq (%r8,%rcx), %rax
addq $-0x10, %rax
movq %rax, 0x38(%rsp)
movq 0x28(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x58(%rsp)
movq %rsi, 0x78(%rsp)
leaq (,%rsi,4), %rax
movq %rax, 0x80(%rsp)
movl %edx, 0x18(%rsp)
movslq %edx, %rax
movq %rax, 0x70(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
xorl %eax, %eax
movq 0x60(%rsp), %rbx
movq %r12, 0xa0(%rsp)
cmpq 0x90(%rsp), %rax
jg 0xa7ef
movq %r12, 0x50(%rsp)
movq %rax, 0x20(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, %ecx
movq 0x20(%rsp), %rax
cmpq 0x88(%rsp), %rax
jne 0xa550
cmpl $0x0, 0x18(%rsp)
je 0xa7cf
movq 0x70(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x18(%rsp), %eax
movl %eax, %ecx
movq 0x20(%rsp), %rax
imulq %r12, %rax
movq %rax, 0xb0(%rsp)
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
movq %rcx, 0xb8(%rsp)
cmpq %rcx, %rdx
je 0xa7a6
movq 0xb0(%rsp), %rax
movq %rdx, 0xc0(%rsp)
leaq (%rdx,%rax), %r12
movq 0xa8(%rsp), %rax
movl (%rax,%r12,4), %r13d
movl %r13d, 0xe0(%rsp)
movq %r12, %rdi
shlq $0x8, %rdi
addq 0x4398(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
callq 0x3130
movl %eax, 0xf8(%rsp)
cmpl $0x0, 0x10(%rsp)
je 0xa6f7
imulq %rbp, %r12
xorl %eax, %eax
cmpq %rax, %r14
je 0xa5fb
andq $0x0, 0x350(%rsp,%rax)
orl $-0x1, 0x358(%rsp,%rax)
addq $0x10, %rax
jmp 0xa5df
movq 0x48(%rsp), %rax
leaq (%rax,%r12,4), %r12
xorl %eax, %eax
cmpq %rbp, %rax
je 0xa667
movl (%r15,%rax,4), %ecx
movl (%r12,%rax,4), %edx
cmpl $0x1, %ebx
jne 0xa621
cmpl %r13d, %ecx
cmovael %r13d, %ecx
jmp 0xa626
addl %r13d, %ecx
subl %edx, %ecx
cvtsi2sd %rdx, %xmm0
movl %ecx, %ecx
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
movq 0x10(%rsp), %rcx
movq 0x38(%rsp), %rdx
testl %ecx, %ecx
jle 0xa662
ucomisd (%rdx), %xmm0
jbe 0xa662
movapd (%rdx), %xmm1
movapd %xmm1, 0x10(%rdx)
movsd %xmm0, (%rdx)
movl %eax, 0x8(%rdx)
addq $-0x10, %rdx
decl %ecx
jmp 0xa640
incq %rax
jmp 0xa606
movq 0x28(%rsp), %r13
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0xa6b9
movslq 0x358(%rsp,%rbx), %rcx
cmpq $-0x1, %rcx
je 0xa6a7
movl (%r15,%rcx,4), %edi
movl (%r12,%rcx,4), %esi
shlq $0x8, %rcx
addq 0x4390(%rsp), %rcx
leaq 0xc8(%rsp), %rdx
movq %r13, %r8
callq 0xc0f3
jmp 0xa6ac
andl $0x0, (%r13)
addq $0x10, %rbx
addq $0x404, %r13            # imm = 0x404
jmp 0xa66e
movq 0x58(%rsp), %r12
movq 0x98(%rsp), %rbx
movq 0x30(%rsp), %r13
subq $0x1, %rbx
jb 0xa772
movslq -0x4(%r12), %rsi
cmpq $0x2, %rsi
jl 0xa6ee
movq %r12, %rdi
pushq $0x1
popq %rdx
movq %r13, %rcx
callq 0x3450
addq $0x404, %r12            # imm = 0x404
jmp 0xa6cb
movq 0x4390(%rsp), %r13
movq 0x28(%rsp), %r12
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0xa73d
movl (%r15,%rbx,4), %edi
movq 0x8(%rsp), %rax
movl (%rax,%rbx,4), %esi
leaq 0xc8(%rsp), %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0xc0f3
incq %rbx
addq $0x404, %r12            # imm = 0x404
addq $0x100, %r13            # imm = 0x100
jmp 0xa706
movq 0x58(%rsp), %r12
movq %rbp, %rbx
movq 0x30(%rsp), %r13
subq $0x1, %rbx
jb 0xa772
movslq -0x4(%r12), %rsi
cmpq $0x2, %rsi
jl 0xa769
movq %r12, %rdi
pushq $0x1
popq %rdx
movq %r13, %rcx
callq 0x3450
addq $0x404, %r12            # imm = 0x404
jmp 0xa74a
movq 0xc0(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rbx
movq 0xa0(%rsp), %r12
movq 0xb8(%rsp), %rcx
jmp 0xa57a
movq 0x50(%rsp), %rsi
imulq 0x68(%rsp), %rsi
movq 0x78(%rsp), %rax
imulq 0x20(%rsp), %rax
movq 0x48(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
callq 0x3360
movq 0x20(%rsp), %rax
incq %rax
movq %rax, %rcx
movq 0x40(%rsp), %rax
addq 0x80(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %rcx, %rax
jmp 0xa503
movq %r13, %rdi
callq 0x3100
movq 0x28(%rsp), %rdi
callq 0x3040
movq 0x43a0(%rsp), %rax
cmpb $0x0, 0x64b(%rax)
jne 0xa81e
leaq 0x52ce7(%rip), %rdi     # 0x5d500
callq 0x3070
addq $0x4358, %rsp           # imm = 0x4358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movl (%rax), %edi
leaq 0xaa9d(%rip), %rsi      # 0x152db
leaq 0x1c0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
movq 0x8(%rsp), %rax
movl (%rax), %edi
leaq 0xab1e(%rip), %rsi      # 0x15379
movl %r8d, %edx
movl $0x400, %ecx            # imm = 0x400
movl 0x10(%rsp), %r8d
xorl %eax, %eax
callq 0x3330