// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq %r8, 0xb8(%rsp)
movq %rcx, %r15
movl %edx, %r13d
movl %esi, 0xc(%rsp)
movq 0x43b0(%rsp), %rax
cmpb $0x0, 0x54b(%rax)
movq %rdi, 0x10(%rsp)
je 0xa9b8
leaq 0x54b(%rax), %rsi
leaq 0x53b4f(%rip), %rdi     # 0x5e500
callq 0x3080
jmp 0xa9d3
movq %rdi, %rcx
leaq 0x53b3e(%rip), %rdi     # 0x5e500
leaq 0xb616(%rip), %rsi      # 0x15fdf
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0x53b26(%rip), %r12     # 0x5e500
movq %r12, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3380
movl %eax, %ebp
movl %eax, %ebx
shrl $0x1f, %ebx
callq 0x3060
movq %rax, %r14
movl (%rax), %edi
callq 0x3470
leaq 0xa7ac(%rip), %rsi      # 0x151af
movl %ebx, %edi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xbca1
leaq 0x2d0(%rsp), %rbx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x34a0
movq 0x30(%rbx), %rsi
xorl %edi, %edi
movl $0x1, %edx
movl $0x2, %ecx
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x3150
xorl %ebx, %ebx
movq %rax, 0x20(%rsp)
cmpq $-0x1, %rax
sete %bl
movq %r14, (%rsp)
movl (%r14), %edi
callq 0x3470
leaq 0xa762(%rip), %rsi      # 0x151c2
movl %ebx, %edi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xbca1
movl %ebp, %edi
callq 0x3220
movl 0xc(%rsp), %ebp
movl %ebp, %ecx
movq %rcx, %rax
shlq $0xa, %rax
movq %rcx, 0x38(%rsp)
leaq (%rax,%rcx,4), %rdi
callq 0x3340
movq %rax, 0x50(%rsp)
leaq 0xb4e9(%rip), %rsi      # 0x15f86
leaq 0x1d0(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xa93a(%rip), %rsi      # 0x153f5
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0xaff9
movq %rax, %rbx
movl %r13d, %eax
xorl %edx, %edx
divl 0x8(%rsp)
movl %eax, 0x28(%rsp)
movl %edx, 0x44(%rsp)
movq 0x43b0(%rsp), %rcx
movl 0x440(%rcx), %eax
movq %rax, 0x58(%rsp)
movl %eax, 0xd8(%rsp)
movl 0x444(%rcx), %r12d
movl %r12d, 0xdc(%rsp)
movb 0x448(%rcx), %al
movb %al, 0xe0(%rsp)
movsd 0x438(%rcx), %xmm0
movsd %xmm0, 0xe8(%rsp)
imull %ebp, %r13d
movq %r13, 0xf8(%rsp)
leaq 0xac46(%rip), %rsi      # 0x15780
leaq 0x110(%rsp), %rdi
movl $0xb4, %edx
callq 0x32f0
leaq 0xb805(%rip), %rdi      # 0x16358
movl $0x1c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3450
testl %r12d, %r12d
movq %rbx, %r13
js 0xaba1
incq %r12
imulq $0x5a, 0x58(%rsp), %rax
leaq (%rsp,%rax), %rbx
addq $0x110, %rbx            # imm = 0x110
leaq 0xb7ed(%rip), %r14      # 0x16375
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x32c0
addq $0x1e, %rbx
decq %r12
jne 0xab88
movl $0xa, %edi
movq %r13, 0x10(%rsp)
movq %r13, %rsi
callq 0x3250
movq 0x43b0(%rsp), %rax
movl 0x430(%rax), %edx
cmpl $0x400, %edx            # imm = 0x400
jg 0xb015
cmpl %ebp, %edx
ja 0xb015
movq %rdx, (%rsp)
movl 0x28(%rsp), %esi
testl %esi, %esi
movq 0x50(%rsp), %r12
js 0xafb8
movq 0x38(%rsp), %rcx
leaq (,%rcx,4), %rax
movq %rax, 0x88(%rsp)
movslq 0x8(%rsp), %rdx
movq %rdx, %rax
imulq %rcx, %rax
movq %rax, 0x80(%rsp)
movl %esi, %esi
movq (%rsp), %rax
movq %rax, %r13
shlq $0x4, %r13
incq %rax
movq %rax, 0xa8(%rsp)
leaq 0x360(%rsp), %rax
addq %r13, %rax
addq $-0x10, %rax
movq %rax, 0xa0(%rsp)
movq %r12, %rax
addq $0x4, %rax
movq %rax, 0x60(%rsp)
movq %rdx, 0x70(%rsp)
imulq %rcx, %rdx
shlq $0x2, %rdx
movq %rdx, 0x90(%rsp)
leaq (,%rcx,4), %rax
movq %rax, 0xb0(%rsp)
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rsi, 0x78(%rsp)
movq %r13, 0x98(%rsp)
movq %r15, 0x68(%rsp)
movl 0x8(%rsp), %ecx
cmpq %rsi, %rbx
jne 0xaca8
movl 0x44(%rsp), %eax
movl %eax, %ecx
testl %eax, %eax
je 0xaf96
movq %rbx, 0x48(%rsp)
movl %ecx, 0x1c(%rsp)
testl %ecx, %ecx
jle 0xaf64
movq 0x48(%rsp), %rax
imulq 0x70(%rsp), %rax
movq %rax, 0xc8(%rsp)
movl 0x1c(%rsp), %eax
movq %rax, 0xc0(%rsp)
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
movq %rax, 0x28(%rsp)
movq 0xc8(%rsp), %rax
movq %rcx, 0xd0(%rsp)
leaq (%rcx,%rax), %rbx
movq 0xb8(%rsp), %rax
movl (%rax,%rbx,4), %r14d
movl %r14d, 0xf0(%rsp)
movq %rbx, %rdi
shlq $0x8, %rdi
addq 0x43a8(%rsp), %rdi
movq %rdi, 0x100(%rsp)
callq 0x3130
movl %eax, 0x108(%rsp)
movq (%rsp), %rax
testq %rax, %rax
je 0xae9c
testl %eax, %eax
jle 0xad62
xorl %eax, %eax
movq $0x0, 0x360(%rsp,%rax)
movl $0xffffffff, 0x368(%rsp,%rax) # imm = 0xFFFFFFFF
addq $0x10, %rax
cmpq %rax, %r13
jne 0xad42
movq 0x38(%rsp), %rdi
imulq %rdi, %rbx
testl %ebp, %ebp
movq 0x58(%rsp), %r8
movq (%rsp), %r9
movq 0xa8(%rsp), %r10
movq 0xa0(%rsp), %r11
je 0xadfa
movq 0x20(%rsp), %rax
leaq (%rax,%rbx,4), %rax
xorl %ecx, %ecx
movl (%r15,%rcx,4), %edx
movl (%rax,%rcx,4), %esi
cmpl $0x1, %r8d
jne 0xada9
cmpl %r14d, %edx
cmovael %r14d, %edx
jmp 0xadae
addl %r14d, %edx
subl %esi, %edx
testl %r9d, %r9d
jle 0xadf2
xorps %xmm0, %xmm0
cvtsi2sd %rsi, %xmm0
movl %edx, %edx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
divsd %xmm1, %xmm0
movq %r11, %rdx
movq %r10, %rsi
ucomisd (%rdx), %xmm0
jbe 0xadf2
movapd (%rdx), %xmm1
movapd %xmm1, 0x10(%rdx)
movsd %xmm0, (%rdx)
movl %ecx, 0x8(%rdx)
decq %rsi
addq $-0x10, %rdx
cmpq $0x1, %rsi
jg 0xadcf
incq %rcx
cmpq %rdi, %rcx
jne 0xad93
testl %r9d, %r9d
jle 0xae57
movq 0x20(%rsp), %rax
leaq (%rax,%rbx,4), %rbx
xorl %ebp, %ebp
movq %r12, %r14
movslq 0x368(%rsp,%rbp), %rcx
cmpq $-0x1, %rcx
je 0xae40
movl (%r15,%rcx,4), %edi
movl (%rbx,%rcx,4), %esi
shlq $0x8, %rcx
addq 0x43a0(%rsp), %rcx
leaq 0xd8(%rsp), %rdx
movq %r14, %r8
callq 0xc850
jmp 0xae47
movl $0x0, (%r14)
addq $0x404, %r14            # imm = 0x404
addq $0x10, %rbp
cmpq %rbp, %r13
jne 0xae0d
movq (%rsp), %rax
movq %rax, %rbx
movq 0x60(%rsp), %r14
testl %eax, %eax
movl 0xc(%rsp), %ebp
jle 0xaf3e
movslq -0x4(%r14), %rsi
cmpq $0x2, %rsi
jl 0xae8b
movl $0x1, %edx
movq %r14, %rdi
movq 0x10(%rsp), %rcx
callq 0x3450
addq $0x404, %r14            # imm = 0x404
decq %rbx
jne 0xae6f
jmp 0xaf3e
testl %ebp, %ebp
je 0xaf3e
movq 0x43a0(%rsp), %r14
movq %r12, %rbx
xorl %ebp, %ebp
movq 0x38(%rsp), %r12
leaq 0xd8(%rsp), %r15
movq 0x28(%rsp), %r13
movq 0x68(%rsp), %rax
movl (%rax,%rbp,4), %edi
movl (%r13,%rbp,4), %esi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0xc850
incq %rbp
addq $0x404, %rbx            # imm = 0x404
addq $0x100, %r14            # imm = 0x100
cmpq %rbp, %r12
jne 0xaec3
movq %r12, %rbx
movq 0x60(%rsp), %r14
movl 0xc(%rsp), %ebp
testl %ebp, %ebp
movq 0x50(%rsp), %r12
movq 0x68(%rsp), %r15
movq 0x98(%rsp), %r13
je 0xaf3e
movslq -0x4(%r14), %rsi
cmpq $0x2, %rsi
jl 0xaf32
movl $0x1, %edx
movq %r14, %rdi
movq 0x10(%rsp), %rcx
callq 0x3450
addq $0x404, %r14            # imm = 0x404
decq %rbx
jne 0xaf16
movq 0xd0(%rsp), %rcx
incq %rcx
movq 0x28(%rsp), %rax
addq 0xb0(%rsp), %rax
cmpq 0xc0(%rsp), %rcx
jne 0xacdf
movslq 0x1c(%rsp), %rsi
imulq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rbx
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
callq 0x3360
movq 0x78(%rsp), %rsi
leaq 0x1(%rbx), %rax
movq 0x30(%rsp), %rcx
addq 0x90(%rsp), %rcx
movq %rcx, 0x30(%rsp)
cmpq %rsi, %rbx
movq %rax, %rbx
jb 0xac91
movq 0x10(%rsp), %rdi
callq 0x3100
movq %r12, %rdi
callq 0x3040
movq 0x43b0(%rsp), %rax
cmpb $0x0, 0x64b(%rax)
jne 0xafe7
leaq 0x5351e(%rip), %rdi     # 0x5e500
callq 0x3070
addq $0x4368, %rsp           # imm = 0x4368
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movl (%rax), %edi
leaq 0xb2d5(%rip), %rsi      # 0x162db
leaq 0x1d0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
movq (%rsp), %rax
movl (%rax), %edi
leaq 0xb357(%rip), %rsi      # 0x16379
movl $0x400, %ecx            # imm = 0x400
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3330