// File: /workspace/github_c_makefile_star2_O1/yhg926[P]public_kssd/command_dist.c
// Function: mco_co_dist
void mco_co_dist( char *refmco_dname, char *qryco_dname, const char *distout_dir, int p_fit_mem)
{
 FILE *refmco_dstat_fp, *qryco_dstat_fp;
 char *refmco_dstat_fpath = malloc(PATHLEN*sizeof(char));
 char *qryco_dstat_fpath = malloc(PATHLEN*sizeof(char));
 sprintf(refmco_dstat_fpath,"%s/%s",refmco_dname,mco_dstat);
 sprintf(qryco_dstat_fpath,"%s/%s",qryco_dname,co_dstat);
 if( (refmco_dstat_fp = fopen(refmco_dstat_fpath,"rb")) == NULL )
  err(errno,"need provied mco dir path for mco_co_dist() arg 1. refmco_dstat_fpath");
 if( (qryco_dstat_fp = fopen(qryco_dstat_fpath,"rb")) == NULL )
  err(errno,"need provied co dir path for mco_co_dist() arg 2.  qryco_dstat_fpath");
 mco_dstat_t mco_dstat_readin ;
  co_dstat_t co_dstat_readin ;
  fread(&mco_dstat_readin,sizeof(mco_dstat_readin),1,refmco_dstat_fp);
 fread(&co_dstat_readin,sizeof(co_dstat_readin),1,qryco_dstat_fp);
 unsigned int * qry_ctx_ct_list = malloc(co_dstat_readin.infile_num * sizeof(unsigned int));
 unsigned int * ref_ctx_ct_list = malloc(mco_dstat_readin.infile_num * sizeof(unsigned int));
 fread(qry_ctx_ct_list,sizeof(unsigned int),co_dstat_readin.infile_num,qryco_dstat_fp);
 fread(ref_ctx_ct_list,sizeof(unsigned int),mco_dstat_readin.infile_num,refmco_dstat_fp);
 char (*cofname)[PATHLEN] = malloc(co_dstat_readin.infile_num * PATHLEN);
 char (*mcofname)[PATHLEN] = malloc(mco_dstat_readin.infile_num * PATHLEN);
 fread(cofname,PATHLEN,co_dstat_readin.infile_num,qryco_dstat_fp);
 fread(mcofname,PATHLEN,mco_dstat_readin.infile_num,refmco_dstat_fp);
 fclose(refmco_dstat_fp);
  fclose(qryco_dstat_fp);
 if( !(mco_dstat_readin.comp_num == co_dstat_readin.comp_num) )
  err(errno,"query args not match ref args: ref.comp_num = %d vs. %d = qry.comp_num",
    mco_dstat_readin.comp_num, co_dstat_readin.comp_num);
 if(!(mco_dstat_readin.shuf_id == co_dstat_readin.shuf_id))
  err(errno,"query args not match ref args: ref.shuf_id = %d vs. %d = qry.shuf_id",
    mco_dstat_readin.shuf_id, co_dstat_readin.shuf_id);
 int ref_bin_num = mco_dstat_readin.infile_num / BIN_SZ;
 int binsz;
 for(int i=0; i<=ref_bin_num;i++ ){
  if( i == ref_bin_num ){
     binsz = mco_dstat_readin.infile_num % BIN_SZ;
          if(binsz == 0) continue;
    }else binsz = BIN_SZ;
#pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
  for( int k=0; k< co_dstat_readin.infile_num; k++){
   if(qry_ctx_ct_list[k]==0){
    warnx("%dth co file is empty",k);
    continue;
   }
   char dist_fcode[PATHLEN];
   sprintf(dist_fcode,"%s/%d.%d.dist", distout_dir, i, k );
   FILE *distfp;
   if ( (distfp = fopen(dist_fcode,"wb")) == NULL) err(errno,"mco_co_dist()::%s",dist_fcode);
   fwrite(initial_dist, sizeof(ctx_obj_ct_t), binsz, distfp);
   fclose(distfp);
  }
  for ( int j = 0; j < mco_dstat_readin.comp_num; j++ ){
   char mco_fcode[PATHLEN];
   sprintf(mco_fcode,"%s/%d.mco.%d",refmco_dname,i,j);
   gidobj_t** unit_arrmco_readin = read_unit_arrmco_file(mco_fcode);
#pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
   for(int k=0; k< co_dstat_readin.infile_num; k++){
    if(qry_ctx_ct_list[k]==0) continue;
        int tid = 0;
#ifdef _OPENMP
        tid = omp_get_thread_num();
#endif
    char co_fcode[PATHLEN]; char dist_fcode[PATHLEN];
    sprintf(co_fcode,"%s/%d.%d.co.%d",qryco_dname,k/BIN_SZ, k % BIN_SZ, j);
    sprintf(dist_fcode,"%s/%d.%d.dist",distout_dir, i , k );
    int fd;
    if( ( (fd = open(dist_fcode,O_RDWR, 0600) ) == -1) )
         err(errno,"mco_co_dist()::distfile = %s[tid = %d]",dist_fcode,tid);
    ctx_obj_ct_t * ctx_obj_ct = mmap(NULL, binsz*(sizeof(ctx_obj_ct_t)), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if(ctx_obj_ct == MAP_FAILED) err(errno,"ctx_obj_ct mmap error");
    ctx_obj_ct = mco_co_mmpdist_core(unit_arrmco_readin,co_fcode,ctx_obj_ct);
    if ( msync( ctx_obj_ct, binsz*(sizeof(ctx_obj_ct_t)), MS_SYNC ) < 0 )
     err(errno,"mco_co_dist()::ctx_obj_ct msync failed");
    munmap(ctx_obj_ct,binsz*(sizeof(ctx_obj_ct_t)));
    close(fd);
   }
   free_unit_arrmco(unit_arrmco_readin);
  }
 }
 ref_seq_num = mco_dstat_readin.infile_num ;
  qry_seq_num = co_dstat_readin.infile_num ;
 kmerlen = co_dstat_readin.kmerlen;
  dim_reduct_len = co_dstat_readin.dim_rd_len;
 char distf[PATHLEN];
 sprintf(distf, "%s/distance.out", distout_dir);
 FILE *distfp;
 if( (distfp = fopen(distf,"a")) == NULL ) err(errno,"mco_co_dist():%s",distf);
 for(int i=0; i<=ref_bin_num;i++ ){
  for ( int k = 0; k < co_dstat_readin.infile_num; k++ ){
   if(qry_ctx_ct_list[k]>0)
    fname_dist_print(i,k,distout_dir,ref_ctx_ct_list,qry_ctx_ct_list,mcofname,cofname,distfp);
  }
 }
 fclose(distfp);
 free(ref_ctx_ct_list);
 free(qry_ctx_ct_list);
 free(mcofname);
 free(cofname);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rdx, 0x20(%rsp)
movq %rsi, %r12
movq %rdi, %r13
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %rbx
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %r14
leaq 0xc38d(%rip), %r15      # 0x15393
leaq 0xc760(%rip), %rcx      # 0x1576d
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, 0x68(%rsp)
movq %r13, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xc737(%rip), %rcx      # 0x15760
movq %r14, %rdi
movq %r15, %rsi
movq %r12, 0x78(%rsp)
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xc022(%rip), %rsi      # 0x15067
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x969c
movq %rax, %rbx
leaq 0xc007(%rip), %rsi      # 0x15067
movq %r14, %rdi
callq 0x33a0
testq %rax, %rax
je 0x96ac
movq %rax, %r14
leaq 0xac(%rsp), %rdi
movl $0x14, %esi
movl $0x1, %edx
movq %rdi, %r12
movq %rbx, %rcx
callq 0x30c0
leaq 0x88(%rsp), %r15
movl $0x20, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x30c0
movl 0x14(%r15), %eax
movq %rax, (%rsp)
movslq %eax, %r13
leaq (,%r13,4), %rdi
callq 0x3340
movq %rax, %r15
movl 0x10(%r12), %eax
movq %rax, 0x28(%rsp)
movslq %eax, %rbp
leaq (,%rbp,4), %rdi
callq 0x3340
movq %rax, %r12
movl $0x4, %esi
movq %r15, 0x50(%rsp)
movq %r15, %rdi
movq %r13, %rdx
movq %r14, %rcx
callq 0x30c0
movl $0x4, %esi
movq %r12, 0x60(%rsp)
movq %r12, %rdi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x30c0
movq %r13, %rdi
shlq $0x8, %rdi
callq 0x3340
movq %rax, %r15
movq %rbp, %rdi
shlq $0x8, %rdi
callq 0x3340
movq %rax, %r12
movl $0x100, %esi            # imm = 0x100
movq %r15, 0x58(%rsp)
movq %r15, %rdi
movq %r13, %rdx
movq %r14, %rcx
callq 0x30c0
movl $0x100, %esi            # imm = 0x100
movq %r12, 0x48(%rsp)
movq %r12, %rdi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x30c0
movq %rbx, %rdi
callq 0x3100
movq %r14, %rdi
callq 0x3100
leaq 0xac(%rsp), %rax
movl 0xc(%rax), %eax
leaq 0x88(%rsp), %rcx
movl 0x10(%rcx), %ebx
movl %eax, 0xc(%rsp)
cmpl %ebx, %eax
jne 0x96bc
movl 0xac(%rsp), %ebx
movl 0x88(%rsp), %ebp
cmpl %ebp, %ebx
jne 0x96d2
movq 0x28(%rsp), %rcx
leal 0xffff(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movl %eax, %edx
sarl $0x10, %edx
cmpl $0xffff0001, %ecx       # imm = 0xFFFF0001
movq 0x50(%rsp), %r12
movl %edx, 0x10(%rsp)
jl 0x9538
andl $0xffff0000, %eax       # imm = 0xFFFF0000
movq 0x28(%rsp), %rcx
subl %eax, %ecx
movl %ecx, 0x3c(%rsp)
xorl %r14d, %r14d
movl %r14d, %ecx
xorl %edx, %ecx
cmpl %edx, %r14d
movl 0x3c(%rsp), %edx
movl %edx, %eax
movl $0x10000, %esi          # imm = 0x10000
cmovnel %esi, %eax
orl %edx, %ecx
je 0x9524
movq %r14, 0x30(%rsp)
cltq
movq %rax, 0x18(%rsp)
cmpl $0x0, (%rsp)
leaq 0xccc1(%rip), %r15      # 0x15edf
leaq 0xbe45(%rip), %r13      # 0x1506a
leaq 0x152c4(%rip), %rbp     # 0x1e4f0
jle 0x92a8
xorl %ebx, %ebx
cmpl $0x0, (%r12,%rbx,4)
je 0x9293
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
leaq 0xccac(%rip), %rsi      # 0x15ef5
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r13, %rsi
callq 0x33a0
testq %rax, %rax
je 0x967f
movq %rax, %r14
movl $0x4, %esi
movq %rbp, %rdi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x3450
movq %r14, %rdi
callq 0x3100
jmp 0x929f
movq %r15, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x3180
incq %rbx
cmpq %rbx, (%rsp)
jne 0x9230
cmpl $0x0, 0xc(%rsp)
movq 0x30(%rsp), %r14
movq 0x18(%rsp), %r15
jle 0x9524
shlq $0x2, %r15
xorl %r8d, %r8d
movq %r15, 0x18(%rsp)
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
leaq 0xcc3a(%rip), %rsi      # 0x15f15
movq 0x68(%rsp), %rdx
movl %r14d, %ecx
movl %r8d, 0x14(%rsp)
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
callq 0x44c0
movq %rax, %r13
cmpl $0x0, (%rsp)
jle 0x9509
xorl %ebp, %ebp
cmpl $0x0, (%r12,%rbp,4)
je 0x94fc
movl %ebp, %ecx
shrl $0x10, %ecx
movzwl %bp, %r8d
leaq 0x1c0(%rsp), %rdi
leaq 0xbe02(%rip), %rsi      # 0x1512b
movq 0x78(%rsp), %rdx
movl 0x14(%rsp), %r9d
xorl %eax, %eax
callq 0x3430
leaq 0x350(%rsp), %rbx
movq %rbx, %rdi
leaq 0xcba9(%rip), %rsi      # 0x15ef5
movq 0x20(%rsp), %rdx
movl %r14d, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
movl $0x2, %esi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x3380
cmpl $-0x1, %eax
je 0x9660
movl %eax, %ebx
xorl %edi, %edi
movq %r15, %rsi
movl $0x3, %edx
movl $0x1, %ecx
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x3150
cmpq $-0x1, %rax
je 0x963b
movq %rax, %r12
movl %ebx, 0x40(%rsp)
leaq 0x1c0(%rsp), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3380
movl %eax, %ebx
movl %eax, %r15d
shrl $0x1f, %ebx
callq 0x3060
movq %rax, %r14
movl (%rax), %edi
callq 0x3470
movl %ebx, %edi
leaq 0xbdd6(%rip), %rsi      # 0x151af
leaq 0x1c0(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xbca1
movl %r15d, 0x44(%rsp)
movl %r15d, %edi
leaq 0x2c0(%rsp), %rsi
callq 0x34a0
movq 0x2f0(%rsp), %rsi
movq %rsi, 0x80(%rsp)
xorl %edi, %edi
movl $0x1, %edx
movl $0x2, %ecx
movl %r15d, %r8d
xorl %r9d, %r9d
callq 0x3150
movq %rax, %rbx
xorl %r15d, %r15d
cmpq $-0x1, %rax
sete %r15b
movq %r14, 0x70(%rsp)
movl (%r14), %edi
callq 0x3470
movl %r15d, %edi
movq 0x18(%rsp), %r15
leaq 0xbd71(%rip), %rsi      # 0x151c2
leaq 0x1c0(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xbca1
movl 0x44(%rsp), %edi
callq 0x3220
movq 0x80(%rsp), %rsi
movq %rsi, %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0x94be
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movq (%r13,%rdx,8), %rdx
testq %rdx, %rdx
je 0x94b6
movl (%rdx), %edi
decl %edi
cmpl $-0x3, %edi
ja 0x94b6
movl $0x1, %r8d
movl (%rdx,%r8,4), %edi
incl (%r12,%rdi,4)
incq %r8
movl (%rdx), %edi
incl %edi
cmpq %rdi, %r8
jb 0x94a2
incq %rcx
cmpq %rax, %rcx
jne 0x9486
movq %rbx, %rdi
callq 0x3360
movq %r12, %rdi
movq %r15, %rsi
movl $0x4, %edx
callq 0x3120
testl %eax, %eax
movq 0x30(%rsp), %r14
js 0x964b
movq %r12, %rdi
movq %r15, %rsi
callq 0x3360
movl 0x40(%rsp), %edi
callq 0x3220
movq 0x50(%rsp), %r12
incq %rbp
cmpq (%rsp), %rbp
jne 0x9306
movq %r13, %rdi
callq 0x45ad
movl 0x14(%rsp), %r8d
incl %r8d
cmpl 0xc(%rsp), %r8d
jne 0x92c9
leal 0x1(%r14), %eax
movl 0x10(%rsp), %edx
cmpl %edx, %r14d
movl %eax, %r14d
jne 0x91e9
movq 0x28(%rsp), %r14
movl %r14d, 0x54fac(%rip)    # 0x5e4f0
movq (%rsp), %rax
movl %eax, 0x54fa6(%rip)     # 0x5e4f4
movl 0x90(%rsp), %eax
movl 0x94(%rsp), %ecx
movl %eax, 0x54f96(%rip)     # 0x5e4f8
movl %ecx, 0x54f94(%rip)     # 0x5e4fc
leaq 0xca17(%rip), %rsi      # 0x15f86
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xc7d9(%rip), %rsi      # 0x15d66
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x96eb
movq %rax, %rbx
cmpl $0xffff0001, %r14d      # imm = 0xFFFF0001
movq 0x60(%rsp), %r13
movq 0x58(%rsp), %rbp
jl 0x95ff
xorl %r14d, %r14d
cmpl $0x0, (%rsp)
jle 0x95f1
xorl %r15d, %r15d
cmpl $0x0, (%r12,%r15,4)
je 0x95e8
movl %r14d, %edi
movl %r15d, %esi
movq 0x20(%rsp), %rdx
movq %r13, %rcx
movq %r12, %r8
movq 0x48(%rsp), %r9
pushq %rbx
pushq %rbp
callq 0x96fb
addq $0x10, %rsp
incq %r15
cmpq %r15, (%rsp)
jne 0x95c0
leal 0x1(%r14), %eax
cmpl 0x10(%rsp), %r14d
movl %eax, %r14d
jne 0x95b7
movq %rbx, %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3040
movq %r12, %rdi
callq 0x3040
movq 0x48(%rsp), %rdi
callq 0x3040
movq %rbp, %rdi
callq 0x3040
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0xc900(%rip), %rsi      # 0x15f49
jmp 0x9659
movq 0x70(%rsp), %rax
movl (%rax), %edi
leaq 0xc906(%rip), %rsi      # 0x15f5f
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xc8b4(%rip), %rsi      # 0x15f22
leaq 0x350(%rsp), %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xc876(%rip), %rsi      # 0x15f03
leaq 0xc0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xc71e(%rip), %rsi      # 0x15dc8
jmp 0x9659
callq 0x3060
movl (%rax), %edi
leaq 0xc754(%rip), %rsi      # 0x15e0e
jmp 0x9659
callq 0x3060
movl (%rax), %edi
leaq 0xc789(%rip), %rsi      # 0x15e53
movl 0xc(%rsp), %edx
movl %ebx, %ecx
jmp 0x96e4
callq 0x3060
movl (%rax), %edi
leaq 0xc7ba(%rip), %rsi      # 0x15e9a
movl %ebx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xc89d(%rip), %rsi      # 0x15f96
jmp 0x968d