// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x610, %rsp            # imm = 0x610
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x100, %edi            # imm = 0x100
callq 0x3310
movq %rax, -0x38(%rbp)
movl $0x100, %edi            # imm = 0x100
callq 0x3310
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rdx
leaq 0x113e6(%rip), %rsi     # 0x1c32b
leaq 0x117b1(%rip), %rcx     # 0x1c6fd
movb $0x0, %al
callq 0x3400
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x113c9(%rip), %rsi     # 0x1c32b
leaq 0x11787(%rip), %rcx     # 0x1c6f0
movb $0x0, %al
callq 0x3400
movq -0x38(%rbp), %rdi
leaq 0x110dc(%rip), %rsi     # 0x1c057
callq 0x3370
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0xaf9f
callq 0x3050
movl (%rax), %edi
leaq 0x11e00(%rip), %rsi     # 0x1cd98
movb $0x0, %al
callq 0x3300
movq -0x40(%rbp), %rdi
leaq 0x110ad(%rip), %rsi     # 0x1c057
callq 0x3370
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xafce
callq 0x3050
movl (%rax), %edi
leaq 0x11e17(%rip), %rsi     # 0x1cdde
movb $0x0, %al
callq 0x3300
movq -0x28(%rbp), %rcx
leaq -0x54(%rbp), %rdi
movl $0x14, %esi
movl $0x1, %edx
callq 0x30a0
movq -0x30(%rbp), %rcx
leaq -0x78(%rbp), %rdi
movl $0x20, %esi
movl $0x1, %edx
callq 0x30a0
movslq -0x64(%rbp), %rdi
shlq $0x2, %rdi
callq 0x3310
movq %rax, -0x80(%rbp)
movslq -0x44(%rbp), %rdi
shlq $0x2, %rdi
callq 0x3310
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movslq -0x64(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x4, %esi
callq 0x30a0
movq -0x88(%rbp), %rdi
movslq -0x44(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x4, %esi
callq 0x30a0
movl -0x64(%rbp), %eax
shll $0x8, %eax
movslq %eax, %rdi
callq 0x3310
movq %rax, -0x90(%rbp)
movl -0x44(%rbp), %eax
shll $0x8, %eax
movslq %eax, %rdi
callq 0x3310
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movslq -0x64(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
callq 0x30a0
movq -0x98(%rbp), %rdi
movslq -0x44(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
callq 0x30a0
movq -0x28(%rbp), %rdi
callq 0x30e0
movq -0x30(%rbp), %rdi
callq 0x30e0
movl -0x48(%rbp), %eax
cmpl -0x68(%rbp), %eax
je 0xb0e1
callq 0x3050
movl (%rax), %edi
movl -0x48(%rbp), %edx
movl -0x68(%rbp), %ecx
leaq 0x11d49(%rip), %rsi     # 0x1ce23
movb $0x0, %al
callq 0x3300
movl -0x54(%rbp), %eax
cmpl -0x78(%rbp), %eax
je 0xb104
callq 0x3050
movl (%rax), %edi
movl -0x54(%rbp), %edx
movl -0x78(%rbp), %ecx
leaq 0x11d6d(%rip), %rsi     # 0x1ce6a
movb $0x0, %al
callq 0x3300
movl -0x44(%rbp), %eax
movl $0x10000, %ecx          # imm = 0x10000
cltd
idivl %ecx
movl %eax, -0x9c(%rbp)
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jg 0xb4ab
movl -0xa4(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jne 0xb160
movl -0x44(%rbp), %eax
movl $0x10000, %ecx          # imm = 0x10000
cltd
idivl %ecx
movl %edx, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
jne 0xb15e
jmp 0xb497
jmp 0xb16a
movl $0x10000, -0xa0(%rbp)   # imm = 0x10000
movl $0x0, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0xb24e
movq -0x80(%rbp), %rax
movslq -0xa8(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xb1ad
movl -0xa8(%rbp), %esi
leaq 0x11d0e(%rip), %rdi     # 0x1ceaf
movb $0x0, %al
callq 0x3160
jmp 0xb23a
leaq -0x1b0(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl -0xa4(%rbp), %ecx
movl -0xa8(%rbp), %r8d
leaq 0x11cf9(%rip), %rsi     # 0x1cec5
movb $0x0, %al
callq 0x3400
leaq -0x1b0(%rbp), %rdi
leaq 0x10e79(%rip), %rsi     # 0x1c05a
callq 0x3370
movq %rax, -0x1b8(%rbp)
cmpq $0x0, %rax
jne 0xb20f
callq 0x3050
movl (%rax), %edi
leaq -0x1b0(%rbp), %rdx
leaq 0x11ccb(%rip), %rsi     # 0x1ced3
movb $0x0, %al
callq 0x3300
movslq -0xa0(%rbp), %rdx
movq -0x1b8(%rbp), %rcx
leaq 0x192bc(%rip), %rdi     # 0x244e0
movl $0x4, %esi
callq 0x3420
movq -0x1b8(%rbp), %rdi
callq 0x30e0
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0xb174
movl $0x0, -0x1bc(%rbp)
movl -0x1bc(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0xb495
leaq -0x2c0(%rbp), %rdi
movq -0x8(%rbp), %rdx
movl -0xa4(%rbp), %ecx
movl -0x1bc(%rbp), %r8d
leaq 0x11c5f(%rip), %rsi     # 0x1cee5
movb $0x0, %al
callq 0x3400
leaq -0x2c0(%rbp), %rdi
callq 0x49e0
movq %rax, -0x2c8(%rbp)
movl $0x0, -0x2cc(%rbp)
movl -0x2cc(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0xb475
movq -0x80(%rbp), %rax
movslq -0x2cc(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xb2cf
jmp 0xb461
movl $0x0, -0x2d0(%rbp)
leaq -0x3d0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x5f8(%rbp)
movl -0x2cc(%rbp), %eax
movl $0x10000, %ecx          # imm = 0x10000
cltd
idivl %ecx
movl %eax, %ecx
movl -0x2cc(%rbp), %eax
movl $0x10000, %esi          # imm = 0x10000
cltd
idivl %esi
movl %edx, %r8d
movq -0x5f8(%rbp), %rdx
movl -0x1bc(%rbp), %r9d
leaq 0x10dfa(%rip), %rsi     # 0x1c11b
movb $0x0, %al
callq 0x3400
leaq -0x4d0(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl -0xa4(%rbp), %ecx
movl -0x2cc(%rbp), %r8d
leaq 0x11b7e(%rip), %rsi     # 0x1cec5
movb $0x0, %al
callq 0x3400
leaq -0x4d0(%rbp), %rdi
movl $0x2, %esi
movl $0x180, %edx            # imm = 0x180
movb $0x0, %al
callq 0x3350
movl %eax, -0x4d4(%rbp)
cmpl $-0x1, %eax
jne 0xb393
callq 0x3050
movl (%rax), %edi
leaq -0x4d0(%rbp), %rdx
movl -0x2d0(%rbp), %ecx
leaq 0x11b66(%rip), %rsi     # 0x1cef2
movb $0x0, %al
callq 0x3300
movslq -0xa0(%rbp), %rsi
shlq $0x2, %rsi
movl -0x4d4(%rbp), %r8d
xorl %eax, %eax
movl %eax, %r9d
movl $0x3, %edx
movl $0x1, %ecx
movq %r9, %rdi
callq 0x3130
movq %rax, -0x4e0(%rbp)
movq $-0x1, %rax
cmpq %rax, -0x4e0(%rbp)
jne 0xb3e8
callq 0x3050
movl (%rax), %edi
leaq 0x11b38(%rip), %rsi     # 0x1cf19
movb $0x0, %al
callq 0x3300
movq -0x2c8(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
movq -0x4e0(%rbp), %rdx
callq 0xb610
movq %rax, -0x4e0(%rbp)
movq -0x4e0(%rbp), %rdi
movslq -0xa0(%rbp), %rsi
shlq $0x2, %rsi
movl $0x4, %edx
callq 0x3100
cmpl $0x0, %eax
jge 0xb43f
callq 0x3050
movl (%rax), %edi
leaq 0x11af7(%rip), %rsi     # 0x1cf2f
movb $0x0, %al
callq 0x3300
movq -0x4e0(%rbp), %rdi
movslq -0xa0(%rbp), %rsi
shlq $0x2, %rsi
callq 0x3330
movl -0x4d4(%rbp), %edi
callq 0x3200
movl -0x2cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2cc(%rbp)
jmp 0xb2aa
movq -0x2c8(%rbp), %rdi
callq 0x4ae0
movl -0x1bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0xb258
jmp 0xb497
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0xb11f
movl -0x44(%rbp), %eax
movl %eax, 0x5902c(%rip)     # 0x644e0
movl -0x64(%rbp), %eax
movl %eax, 0x59027(%rip)     # 0x644e4
movl -0x70(%rbp), %eax
movl %eax, 0x59022(%rip)     # 0x644e8
movl -0x6c(%rbp), %eax
movl %eax, 0x5901d(%rip)     # 0x644ec
leaq -0x5e0(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x11a75(%rip), %rsi     # 0x1cf56
movb $0x0, %al
callq 0x3400
leaq -0x5e0(%rbp), %rdi
leaq 0x11840(%rip), %rsi     # 0x1cd36
callq 0x3370
movq %rax, -0x5e8(%rbp)
cmpq $0x0, %rax
jne 0xb524
callq 0x3050
movl (%rax), %edi
leaq -0x5e0(%rbp), %rdx
leaq 0x11a49(%rip), %rsi     # 0x1cf66
movb $0x0, %al
callq 0x3300
movl $0x0, -0x5ec(%rbp)
movl -0x5ec(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jg 0xb5cd
movl $0x0, -0x5f0(%rbp)
movl -0x5f0(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0xb5b7
movq -0x80(%rbp), %rax
movslq -0x5f0(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jbe 0xb5a4
movl -0x5ec(%rbp), %edi
movl -0x5f0(%rbp), %esi
movq -0x18(%rbp), %rdx
movq -0x88(%rbp), %rcx
movq -0x80(%rbp), %r8
movq -0x98(%rbp), %r9
movq -0x90(%rbp), %r10
movq -0x5e8(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xb6f0
jmp 0xb5a6
movl -0x5f0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5f0(%rbp)
jmp 0xb54a
jmp 0xb5b9
movl -0x5ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5ec(%rbp)
jmp 0xb52e
movq -0x5e8(%rbp), %rdi
callq 0x30e0
movq -0x88(%rbp), %rdi
callq 0x3040
movq -0x80(%rbp), %rdi
callq 0x3040
movq -0x98(%rbp), %rdi
callq 0x3040
movq -0x90(%rbp), %rdi
callq 0x3040
addq $0x610, %rsp            # imm = 0x610
popq %rbp
retq
nop