// File: /workspace/github_c_makefile_star2_O3/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 $0x4368, %rsp           # imm = 0x4368
movl %r9d, 0x10(%rsp)
movq %r8, 0xb8(%rsp)
movq %rcx, 0x50(%rsp)
movl %edx, %r13d
movl %esi, %r15d
movq 0x43b0(%rsp), %rax
cmpb $0x0, 0x54b(%rax)
movq %rdi, 0x28(%rsp)
je 0xac42
leaq 0x54b(%rax), %rsi
leaq 0x538c5(%rip), %rdi     # 0x5e500
callq 0x3080
jmp 0xac5d
movq %rdi, %rcx
leaq 0x538b4(%rip), %rdi     # 0x5e500
leaq 0xb3dc(%rip), %rsi      # 0x1602f
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0x5389c(%rip), %rbx     # 0x5e500
movq %rbx, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3380
movl %eax, %ebp
movl %eax, %r14d
shrl $0x1f, %r14d
callq 0x3060
movq %rax, %r12
movl (%rax), %edi
callq 0x3470
leaq 0xa520(%rip), %rsi      # 0x151af
movl %r14d, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xbf3d
leaq 0x2d0(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
callq 0x34a0
movq 0x30(%r14), %rsi
xorl %edi, %edi
movl $0x1, %edx
movl $0x2, %ecx
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x3150
xorl %r14d, %r14d
movq %rax, 0x38(%rsp)
cmpq $-0x1, %rax
sete %r14b
movq %r12, 0x20(%rsp)
movl (%r12), %edi
callq 0x3470
leaq 0xa4d1(%rip), %rsi      # 0x151c2
movl %r14d, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xbf3d
movl %ebp, %edi
callq 0x3220
movl %r15d, %ebp
movq %rbp, %rax
shlq $0xa, %rax
leaq (%rax,%rbp,4), %rdi
callq 0x3340
movq %rax, 0x18(%rsp)
leaq 0xb2af(%rip), %rsi      # 0x15fd6
leaq 0x1d0(%rsp), %rbx
movq %rbx, %rdi
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xa700(%rip), %rsi      # 0x15445
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0xb27e
movq %rax, %r14
movl %r13d, %eax
xorl %edx, %edx
divl 0x10(%rsp)
movl %eax, 0x48(%rsp)
movl %edx, 0xc(%rsp)
movq 0x43b0(%rsp), %rcx
movl 0x440(%rcx), %eax
movq %rax, 0x28(%rsp)
movl %eax, 0xd8(%rsp)
movl 0x444(%rcx), %ebx
movl %ebx, 0xdc(%rsp)
movb 0x448(%rcx), %al
movb %al, 0xe0(%rsp)
movsd 0x438(%rcx), %xmm0
movsd %xmm0, 0xe8(%rsp)
imull %r15d, %r13d
movq %r13, 0xf8(%rsp)
leaq 0xaa0e(%rip), %rsi      # 0x157d0
leaq 0x110(%rsp), %rdi
movl $0xb4, %edx
callq 0x32f0
leaq 0xb5cd(%rip), %rdi      # 0x163a8
movl $0x1c, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x3450
testl %ebx, %ebx
movq %r14, %r13
js 0xae28
incq %rbx
imulq $0x5a, 0x28(%rsp), %rax
leaq (%rsp,%rax), %r14
addq $0x110, %r14            # imm = 0x110
leaq 0xb5b6(%rip), %r12      # 0x163c5
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x32c0
addq $0x1e, %r14
decq %rbx
jne 0xae0f
movl $0xa, %edi
movq %r13, 0x40(%rsp)
movq %r13, %rsi
callq 0x3250
movq 0x43b0(%rsp), %rax
movl 0x430(%rax), %r13d
cmpl $0x400, %r13d           # imm = 0x400
jg 0xb29b
cmpl %r15d, %r13d
ja 0xb29b
movl 0x48(%rsp), %edx
testl %edx, %edx
js 0xb23b
leaq (,%rbp,4), %rax
movq %rax, 0x70(%rsp)
movslq 0x10(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %rax, %rcx
imulq %rbp, %rcx
movl %edx, %edx
movq %r13, %rbx
shlq $0x4, %rbx
leaq 0x1(%r13), %rax
movq %rax, 0x48(%rsp)
leaq 0x360(%rsp), %rax
addq %rbx, %rax
addq $-0x10, %rax
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x68(%rsp)
movq %rcx, 0x90(%rsp)
leaq (,%rcx,4), %rax
movq %rax, 0x98(%rsp)
xorl %r14d, %r14d
movslq 0xc(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rsp)
movl %r15d, 0x14(%rsp)
movq %rdx, 0x88(%rsp)
movq %rbx, 0xb0(%rsp)
movq %r13, 0xa8(%rsp)
movq 0x58(%rsp), %rcx
movl 0x10(%rsp), %eax
cmpq %rdx, %r14
jne 0xaf31
cmpl $0x0, 0xc(%rsp)
je 0xb219
movq 0x80(%rsp), %rcx
movl 0xc(%rsp), %eax
movq %rcx, 0xa0(%rsp)
movq %r14, 0x60(%rsp)
testl %eax, %eax
jle 0xb1e4
movq 0x60(%rsp), %rcx
imulq 0x58(%rsp), %rcx
movq %rcx, 0xc8(%rsp)
movl %eax, %eax
movq %rax, 0xc0(%rsp)
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
movq %rax, 0x78(%rsp)
movq 0xc8(%rsp), %rax
movq %rcx, 0xd0(%rsp)
leaq (%rcx,%rax), %r14
movq 0xb8(%rsp), %rax
movl (%rax,%r14,4), %r12d
movl %r12d, 0xf0(%rsp)
movq %r14, %rdi
shlq $0x8, %rdi
addq 0x43a8(%rsp), %rdi
movq %rdi, 0x100(%rsp)
callq 0x3130
movl %eax, 0x108(%rsp)
testq %r13, %r13
je 0xb11e
testl %r13d, %r13d
movq 0x50(%rsp), %rsi
jle 0xafef
xorl %eax, %eax
movq $0x0, 0x360(%rsp,%rax)
movl $0xffffffff, 0x368(%rsp,%rax) # imm = 0xFFFFFFFF
addq $0x10, %rax
cmpq %rax, %rbx
jne 0xafcf
imulq %rbp, %r14
movq 0x38(%rsp), %rax
leaq (%rax,%r14,4), %r14
xorl %eax, %eax
movl (%rsi,%rax,4), %ecx
movl (%r14,%rax,4), %edx
cmpl $0x1, 0x28(%rsp)
jne 0xb015
cmpl %r12d, %ecx
cmovael %r12d, %ecx
jmp 0xb01a
addl %r12d, %ecx
subl %edx, %ecx
testl %r13d, %r13d
jle 0xb06c
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
movl %ecx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
movq 0x20(%rsp), %rcx
movq 0x48(%rsp), %rdx
ucomisd (%rcx), %xmm0
jbe 0xb062
movapd (%rcx), %xmm1
movapd %xmm1, 0x10(%rcx)
movsd %xmm0, (%rcx)
movl %eax, 0x8(%rcx)
decq %rdx
addq $-0x10, %rcx
cmpq $0x1, %rdx
jg 0xb03f
incq %rax
cmpq %rbp, %rax
jne 0xaffe
jmp 0xb079
incq %rax
cmpq %rbp, %rax
jne 0xaffe
jmp 0xb1c1
testl %r13d, %r13d
jle 0xb1c1
xorl %r15d, %r15d
movq 0x18(%rsp), %r12
movslq 0x368(%rsp,%r15), %rcx
cmpq $-0x1, %rcx
je 0xb0c2
movq 0x50(%rsp), %rax
movl (%rax,%rcx,4), %edi
movl (%r14,%rcx,4), %esi
shlq $0x8, %rcx
addq 0x43a0(%rsp), %rcx
leaq 0xd8(%rsp), %rdx
movq %r12, %r8
callq 0xcb05
jmp 0xb0ca
movl $0x0, (%r12)
addq $0x404, %r12            # imm = 0x404
addq $0x10, %r15
cmpq %r15, %rbx
jne 0xb08a
movq %r13, %r14
movq 0x68(%rsp), %r12
testl %r13d, %r13d
movl 0x14(%rsp), %r15d
jle 0xb1c1
movslq -0x4(%r12), %rsi
cmpq $0x2, %rsi
jl 0xb10d
movl $0x1, %edx
movq %r12, %rdi
movq 0x40(%rsp), %rcx
callq 0x3450
addq $0x404, %r12            # imm = 0x404
decq %r14
jne 0xb0f0
jmp 0xb1c1
testl %r15d, %r15d
je 0xb1c1
movq 0x43a0(%rsp), %r12
movq 0x18(%rsp), %r14
xorl %r15d, %r15d
leaq 0xd8(%rsp), %rbx
movq 0x78(%rsp), %r13
movq 0x50(%rsp), %rax
movl (%rax,%r15,4), %edi
movl (%r13,%r15,4), %esi
movq %rbx, %rdx
movq %r12, %rcx
movq %r14, %r8
callq 0xcb05
incq %r15
addq $0x404, %r14            # imm = 0x404
addq $0x100, %r12            # imm = 0x100
cmpq %r15, %rbp
jne 0xb144
movq %rbp, %r14
movq 0x68(%rsp), %r12
movl 0x14(%rsp), %r15d
testl %r15d, %r15d
movq 0xb0(%rsp), %rbx
movq 0xa8(%rsp), %r13
je 0xb1c1
movslq -0x4(%r12), %rsi
cmpq $0x2, %rsi
jl 0xb1b5
movl $0x1, %edx
movq %r12, %rdi
movq 0x40(%rsp), %rcx
callq 0x3450
addq $0x404, %r12            # imm = 0x404
decq %r14
jne 0xb198
movq 0xd0(%rsp), %rcx
incq %rcx
movq 0x78(%rsp), %rax
addq 0x70(%rsp), %rax
cmpq 0xc0(%rsp), %rcx
jne 0xaf6a
movq 0xa0(%rsp), %rsi
imulq 0x70(%rsp), %rsi
movq 0x90(%rsp), %rax
movq 0x60(%rsp), %r14
imulq %r14, %rax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
callq 0x3360
movq 0x88(%rsp), %rdx
leaq 0x1(%r14), %rax
movq 0x30(%rsp), %rcx
addq 0x98(%rsp), %rcx
movq %rcx, 0x30(%rsp)
cmpq %rdx, %r14
movq %rax, %r14
jb 0xaf0c
movq 0x40(%rsp), %rdi
callq 0x3100
movq 0x18(%rsp), %rdi
callq 0x3040
movq 0x43b0(%rsp), %rax
cmpb $0x0, 0x64b(%rax)
jne 0xb26c
leaq 0x53299(%rip), %rdi     # 0x5e500
callq 0x3070
addq $0x4368, %rsp           # imm = 0x4368
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rax
movl (%rax), %edi
leaq 0xb09f(%rip), %rsi      # 0x1632b
leaq 0x1d0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
movq 0x20(%rsp), %rax
movl (%rax), %edi
leaq 0xb120(%rip), %rsi      # 0x163c9
movl %r13d, %edx
movl $0x400, %ecx            # imm = 0x400
movl %r15d, %r8d
xorl %eax, %eax
callq 0x3330