// File: /workspace/github_c_makefile_star2_O3/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 0xc16a(%rip), %r15      # 0x153e3
leaq 0xc53d(%rip), %rcx      # 0x157bd
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, 0x68(%rsp)
movq %r13, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xc514(%rip), %rcx      # 0x157b0
movq %r14, %rdi
movq %r15, %rsi
movq %r12, 0x78(%rsp)
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xbdaf(%rip), %rsi      # 0x15067
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x990f
movq %rax, %rbx
leaq 0xbd94(%rip), %rsi      # 0x15067
movq %r14, %rdi
callq 0x33a0
testq %rax, %rax
je 0x991f
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 0x992f
movl 0xac(%rsp), %ebx
movl 0x88(%rsp), %ebp
cmpl %ebp, %ebx
jne 0x9945
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 0x97ab
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 0x9797
movq %r14, 0x30(%rsp)
cltq
movq %rax, 0x18(%rsp)
cmpl $0x0, (%rsp)
leaq 0xca9e(%rip), %r15      # 0x15f2f
leaq 0xbbd2(%rip), %r13      # 0x1506a
leaq 0x15051(%rip), %rbp     # 0x1e4f0
jle 0x951b
xorl %ebx, %ebx
cmpl $0x0, (%r12,%rbx,4)
je 0x9506
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
leaq 0xca89(%rip), %rsi      # 0x15f45
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 0x98f2
movq %rax, %r14
movl $0x4, %esi
movq %rbp, %rdi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x3450
movq %r14, %rdi
callq 0x3100
jmp 0x9512
movq %r15, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x3180
incq %rbx
cmpq %rbx, (%rsp)
jne 0x94a3
cmpl $0x0, 0xc(%rsp)
movq 0x30(%rsp), %r14
movq 0x18(%rsp), %r15
jle 0x9797
shlq $0x2, %r15
xorl %r8d, %r8d
movq %r15, 0x18(%rsp)
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
leaq 0xca17(%rip), %rsi      # 0x15f65
movq 0x68(%rsp), %rdx
movl %r14d, %ecx
movl %r8d, 0x14(%rsp)
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
callq 0x44dc
movq %rax, %r13
cmpl $0x0, (%rsp)
jle 0x977c
xorl %ebp, %ebp
cmpl $0x0, (%r12,%rbp,4)
je 0x976f
movl %ebp, %ecx
shrl $0x10, %ecx
movzwl %bp, %r8d
leaq 0x1c0(%rsp), %rdi
leaq 0xbb8f(%rip), %rsi      # 0x1512b
movq 0x78(%rsp), %rdx
movl 0x14(%rsp), %r9d
xorl %eax, %eax
callq 0x3430
leaq 0x350(%rsp), %rbx
movq %rbx, %rdi
leaq 0xc986(%rip), %rsi      # 0x15f45
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 0x98d3
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 0x98ae
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 0xbb63(%rip), %rsi      # 0x151af
leaq 0x1c0(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xbf3d
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 0xbafe(%rip), %rsi      # 0x151c2
leaq 0x1c0(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xbf3d
movl 0x44(%rsp), %edi
callq 0x3220
movq 0x80(%rsp), %rsi
movq %rsi, %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0x9731
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movq (%r13,%rdx,8), %rdx
testq %rdx, %rdx
je 0x9729
movl (%rdx), %edi
decl %edi
cmpl $-0x3, %edi
ja 0x9729
movl $0x1, %r8d
movl (%rdx,%r8,4), %edi
incl (%r12,%rdi,4)
incq %r8
movl (%rdx), %edi
incl %edi
cmpq %rdi, %r8
jb 0x9715
incq %rcx
cmpq %rax, %rcx
jne 0x96f9
movq %rbx, %rdi
callq 0x3360
movq %r12, %rdi
movq %r15, %rsi
movl $0x4, %edx
callq 0x3120
testl %eax, %eax
movq 0x30(%rsp), %r14
js 0x98be
movq %r12, %rdi
movq %r15, %rsi
callq 0x3360
movl 0x40(%rsp), %edi
callq 0x3220
movq 0x50(%rsp), %r12
incq %rbp
cmpq (%rsp), %rbp
jne 0x9579
movq %r13, %rdi
callq 0x45c9
movl 0x14(%rsp), %r8d
incl %r8d
cmpl 0xc(%rsp), %r8d
jne 0x953c
leal 0x1(%r14), %eax
movl 0x10(%rsp), %edx
cmpl %edx, %r14d
movl %eax, %r14d
jne 0x945c
movq 0x28(%rsp), %r14
movl %r14d, 0x54d39(%rip)    # 0x5e4f0
movq (%rsp), %rax
movl %eax, 0x54d33(%rip)     # 0x5e4f4
movl 0x90(%rsp), %eax
movl 0x94(%rsp), %ecx
movl %eax, 0x54d23(%rip)     # 0x5e4f8
movl %ecx, 0x54d21(%rip)     # 0x5e4fc
leaq 0xc7f4(%rip), %rsi      # 0x15fd6
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xc5b6(%rip), %rsi      # 0x15db6
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x995e
movq %rax, %rbx
cmpl $0xffff0001, %r14d      # imm = 0xFFFF0001
movq 0x60(%rsp), %r13
movq 0x58(%rsp), %rbp
jl 0x9872
xorl %r14d, %r14d
cmpl $0x0, (%rsp)
jle 0x9864
xorl %r15d, %r15d
cmpl $0x0, (%r12,%r15,4)
je 0x985b
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 0x996e
addq $0x10, %rsp
incq %r15
cmpq %r15, (%rsp)
jne 0x9833
leal 0x1(%r14), %eax
cmpl 0x10(%rsp), %r14d
movl %eax, %r14d
jne 0x982a
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 0xc6dd(%rip), %rsi      # 0x15f99
jmp 0x98cc
movq 0x70(%rsp), %rax
movl (%rax), %edi
leaq 0xc6e3(%rip), %rsi      # 0x15faf
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xc691(%rip), %rsi      # 0x15f72
leaq 0x350(%rsp), %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xc653(%rip), %rsi      # 0x15f53
leaq 0xc0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xc4fb(%rip), %rsi      # 0x15e18
jmp 0x98cc
callq 0x3060
movl (%rax), %edi
leaq 0xc531(%rip), %rsi      # 0x15e5e
jmp 0x98cc
callq 0x3060
movl (%rax), %edi
leaq 0xc566(%rip), %rsi      # 0x15ea3
movl 0xc(%rsp), %edx
movl %ebx, %ecx
jmp 0x9957
callq 0x3060
movl (%rax), %edi
leaq 0xc597(%rip), %rsi      # 0x15eea
movl %ebx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xc67a(%rip), %rsi      # 0x15fe6
jmp 0x9900