// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%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 0xba80(%rip), %r15      # 0x14393
leaq 0xbe53(%rip), %rcx      # 0x1476d
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, 0x58(%rsp)
movq %r13, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xbe2a(%rip), %rcx      # 0x14760
movq %r14, %rdi
movq %r15, %rsi
movq %r12, 0x68(%rsp)
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xb715(%rip), %rsi      # 0x14067
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x8f73
movq %rax, %rbx
leaq 0xb6fa(%rip), %rsi      # 0x14067
movq %r14, %rdi
callq 0x33a0
testq %rax, %rax
je 0x8f83
movq %rax, %r14
leaq 0xac(%rsp), %rdi
pushq $0x14
popq %rsi
pushq $0x1
popq %r15
movq %rdi, %rbp
movq %r15, %rdx
movq %rbx, %rcx
callq 0x30c0
leaq 0x88(%rsp), %r12
pushq $0x20
popq %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x30c0
movl 0x14(%r12), %eax
movl %eax, 0x4(%rsp)
movslq %eax, %r13
leaq (,%r13,4), %rdi
callq 0x3340
movq %rax, %r12
movl 0x10(%rbp), %eax
movl %eax, (%rsp)
movslq %eax, %rbp
leaq (,%rbp,4), %rdi
callq 0x3340
movq %rax, %r15
pushq $0x4
popq %rsi
movq %r12, 0x50(%rsp)
movq %r12, %rdi
movq %rsi, %r12
movq %r13, %rdx
movq %r14, %rcx
callq 0x30c0
movq %r15, 0x48(%rsp)
movq %r15, %rdi
movq %r12, %rsi
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, 0x40(%rsp)
movq %r15, %rdi
movq %r13, %rdx
movq %r14, %rcx
callq 0x30c0
movl $0x100, %esi            # imm = 0x100
movq %r12, 0x38(%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, %r14d
cmpl %ebx, %eax
jne 0x8f93
movl 0xac(%rsp), %ebx
movl 0x88(%rsp), %ebp
cmpl %ebp, %ebx
jne 0x8fa8
movl $0x10000, %ecx          # imm = 0x10000
movl (%rsp), %eax
cltd
idivl %ecx
movl %edx, 0x8(%rsp)
xorl %esi, %esi
movl 0x4(%rsp), %edx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
movq %rcx, 0x20(%rsp)
testl %r14d, %r14d
cmovlel %esi, %r14d
movl %r14d, 0x2c(%rsp)
testl %eax, %eax
pushq $-0x1
popq %rcx
movl %eax, 0xc(%rsp)
cmovnsl %eax, %ecx
incl %ecx
movl %ecx, 0x10(%rsp)
xorl %r15d, %r15d
movq 0x50(%rsp), %r13
cmpl 0x10(%rsp), %r15d
je 0x8e25
movl %r15d, %eax
xorl 0xc(%rsp), %eax
orl 0x8(%rsp), %eax
je 0x8e1d
cmpl 0xc(%rsp), %r15d
movl 0x8(%rsp), %eax
movl $0x10000, %ecx          # imm = 0x10000
cmovnel %ecx, %eax
movslq %eax, %r12
xorl %ebx, %ebx
cmpq %rbx, 0x20(%rsp)
je 0x8bb1
cmpl $0x0, (%r13,%rbx,4)
je 0x8b99
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
leaq 0xc3a8(%rip), %rsi      # 0x14ef5
movq 0x18(%rsp), %rdx
movl %r15d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0xb501(%rip), %rsi      # 0x1406a
callq 0x33a0
testq %rax, %rax
je 0x8f56
movq %rax, %r14
leaq 0x1496f(%rip), %rdi     # 0x1d4f0
pushq $0x4
popq %rsi
movq %r12, %rdx
movq %rax, %rcx
callq 0x3450
movq %r14, %rdi
callq 0x3100
jmp 0x8ba9
leaq 0xc33f(%rip), %rdi      # 0x14edf
movl %ebx, %esi
xorl %eax, %eax
callq 0x3180
incq %rbx
jmp 0x8b2c
shlq $0x2, %r12
xorl %r8d, %r8d
movl %r15d, 0x30(%rsp)
movq %r12, 0x70(%rsp)
cmpl 0x2c(%rsp), %r8d
je 0x8e1d
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
leaq 0xc336(%rip), %rsi      # 0x14f15
movq 0x58(%rsp), %rdx
movl %r15d, %ecx
movl %r8d, 0x14(%rsp)
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
callq 0x4330
movq %rax, %rbp
xorl %r14d, %r14d
cmpq 0x20(%rsp), %r14
je 0x8e08
cmpl $0x0, (%r13,%r14,4)
je 0x8e00
movl %r14d, %ecx
shrl $0x10, %ecx
movzwl %r14w, %r8d
leaq 0x1c0(%rsp), %rdi
leaq 0xb4fa(%rip), %rsi      # 0x1412b
movq 0x68(%rsp), %rdx
movl 0x14(%rsp), %r9d
xorl %eax, %eax
callq 0x3430
leaq 0x350(%rsp), %rbx
movq %rbx, %rdi
leaq 0xc2a1(%rip), %rsi      # 0x14ef5
movq 0x18(%rsp), %rdx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
pushq $0x2
popq %rsi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x3380
cmpl $-0x1, %eax
je 0x8f37
movl %eax, %ebx
xorl %edi, %edi
movq %r12, %rsi
pushq $0x3
popq %rdx
pushq $0x1
popq %r13
movl %r13d, %ecx
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x3150
cmpq $-0x1, %rax
je 0x8f12
movq %rax, %r12
movq %r14, 0x80(%rsp)
movl %ebx, 0x34(%rsp)
leaq 0x1c0(%rsp), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3380
movl %eax, %r15d
movl %eax, %ebx
shrl $0x1f, %ebx
callq 0x3060
movq %rax, %r14
movl (%rax), %edi
callq 0x3470
movl %ebx, %edi
leaq 0xb4c8(%rip), %rsi      # 0x141af
leaq 0x1c0(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xb564
movl %r15d, %edi
leaq 0x2c0(%rsp), %rsi
callq 0x34a0
movq 0x2f0(%rsp), %rsi
movq %rsi, 0x78(%rsp)
xorl %edi, %edi
movl %r13d, %edx
pushq $0x2
popq %rcx
movl %r15d, %r8d
xorl %r9d, %r9d
callq 0x3150
movq %rax, %rbx
xorl %r13d, %r13d
cmpq $-0x1, %rax
sete %r13b
movq %r14, 0x60(%rsp)
movl (%r14), %edi
callq 0x3470
movl %r13d, %edi
movq 0x50(%rsp), %r13
leaq 0xb46f(%rip), %rsi      # 0x141c2
leaq 0x1c0(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xb564
movl %r15d, %edi
callq 0x3220
movq 0x78(%rsp), %rsi
movq %rsi, %rax
shrq $0x2, %rax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
pushq $0x1
popq %r8
cmpq %rax, %rcx
je 0x8db9
movl (%rbx,%rcx,4), %edx
movq (%rbp,%rdx,8), %rdx
testq %rdx, %rdx
je 0x8db4
movq %r8, %r9
movl (%rdx), %edi
incl %edi
cmpq %rdi, %r9
jae 0x8db4
movl (%rdx,%r9,4), %edi
incl (%r12,%rdi,4)
incq %r9
jmp 0x8d9e
incq %rcx
jmp 0x8d89
movq %rbx, %rdi
callq 0x3360
movq %r12, %rdi
movq 0x70(%rsp), %rbx
movq %rbx, %rsi
pushq $0x4
popq %rdx
callq 0x3120
testl %eax, %eax
movl 0x30(%rsp), %r15d
movq 0x80(%rsp), %r14
js 0x8f22
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3360
movl 0x34(%rsp), %edi
callq 0x3220
movq %rbx, %r12
incq %r14
jmp 0x8c01
movq %rbp, %rdi
callq 0x43f7
movl 0x14(%rsp), %r8d
incl %r8d
jmp 0x8bc2
incl %r15d
jmp 0x8afa
movl (%rsp), %eax
movl %eax, 0x546c2(%rip)     # 0x5d4f0
movl 0x4(%rsp), %eax
movl %eax, 0x546bc(%rip)     # 0x5d4f4
movl 0x90(%rsp), %eax
movl 0x94(%rsp), %ecx
movl %eax, 0x546ac(%rip)     # 0x5d4f8
movl %ecx, 0x546aa(%rip)     # 0x5d4fc
leaq 0xc12d(%rip), %rsi      # 0x14f86
xorl %ebx, %ebx
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xbeed(%rip), %rsi      # 0x14d66
movq %r14, %rdi
callq 0x33a0
testq %rax, %rax
je 0x8fc1
movq %rax, %r14
cmpl 0x10(%rsp), %ebx
je 0x8ed2
xorl %r15d, %r15d
cmpq %r15, 0x20(%rsp)
je 0x8ece
cmpl $0x0, (%r13,%r15,4)
je 0x8ec9
movl %ebx, %edi
movl %r15d, %esi
movq 0x18(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %r13, %r8
movq 0x38(%rsp), %r9
pushq %r14
pushq 0x48(%rsp)
callq 0x8fd1
popq %rax
popq %rcx
incq %r15
jmp 0x8e96
incl %ebx
jmp 0x8e8d
movq %r14, %rdi
callq 0x3100
movq 0x48(%rsp), %rdi
callq 0x3040
movq %r13, %rdi
callq 0x3040
movq 0x38(%rsp), %rdi
callq 0x3040
movq 0x40(%rsp), %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 0xc029(%rip), %rsi      # 0x14f49
jmp 0x8f30
movq 0x60(%rsp), %rax
movl (%rax), %edi
leaq 0xc02f(%rip), %rsi      # 0x14f5f
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xbfdd(%rip), %rsi      # 0x14f22
leaq 0x350(%rsp), %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xbf9f(%rip), %rsi      # 0x14f03
leaq 0xc0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xbe47(%rip), %rsi      # 0x14dc8
jmp 0x8f30
callq 0x3060
movl (%rax), %edi
leaq 0xbe7d(%rip), %rsi      # 0x14e0e
jmp 0x8f30
callq 0x3060
movl (%rax), %edi
leaq 0xbeb2(%rip), %rsi      # 0x14e53
movl %r14d, %edx
movl %ebx, %ecx
jmp 0x8fba
callq 0x3060
movl (%rax), %edi
leaq 0xbee4(%rip), %rsi      # 0x14e9a
movl %ebx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xbfc7(%rip), %rsi      # 0x14f96
jmp 0x8f64