// File: /workspace/github_c_makefile_star2_O3/yhg926[P]public_kssd/command_dist.c
// Function: dist_dispatch
int dist_dispatch(dist_opt_val_t *opt_val)
{
 if( opt_val->mmry == 0 )
  opt_val->mmry = get_sys_mmry();
 llint base_mem = (llint)( (opt_val->mmry - get_sys_mmry()) * BBILLION ) - mem_usage_stat.others ;
 real_time_mem = base_mem + (llint)(get_sys_mmry()*BBILLION) ;
 int p_fit_mem = 1;
 if( ( opt_val->refpath[0] != '\0' ) )
  {
  const char *refco_dstat_fpath = test_get_fullpath(opt_val->refpath,co_dstat);
  const char *refmco_dstat_fpath = test_get_fullpath(opt_val->refpath,mco_dstat);
  if( (refco_dstat_fpath == NULL ) && ( refmco_dstat_fpath == NULL) ){
   infile_tab_t *ref_stat = dist_organize_refpath(opt_val);
   if(ref_stat->infile_num == 0)
    err(errno,"no valid input .fas/.fq file or absent %s | %s in %s \n", co_dstat, mco_dstat, opt_val->refpath ) ;
   infile_fmt_count_t* ref_fmt_count;
      ref_fmt_count = infile_fmt_count(ref_stat);
   if( (ref_stat->infile_num == 0) || (ref_fmt_count->fasta + ref_fmt_count->fastq != ref_stat->infile_num ))
    err(errno,"not a valid input files: make sure input files are .fas/.fq format"
     "or .co.num |.mco.num files with %s | %s in %s \n", co_dstat, mco_dstat, opt_val->refpath );
   const char *dist_refco_dir = opt_val->outdir;
   mkdir(dist_refco_dir,0777);
   int *shuffled_refname_ind = shuffleN( ref_stat->infile_num, 0 );
   mem_usage_stat.input_file_name_sz = ref_stat->infile_num * ( sizeof(llong) + PATHLEN*sizeof(char) );
real_time_mem -= mem_usage_stat.input_file_name_sz;
   dim_shuffle = get_dim_shuffle(opt_val);
    hashsize = get_hashsz(dim_shuffle);
    seq2co_global_var_initial();
    mem_usage_stat.shuffled_subctx_arr_sz = (1LLU << 4*( dim_shuffle->dim_shuffle_stat.subk) )*sizeof(int);
real_time_mem -= mem_usage_stat.shuffled_subctx_arr_sz;
   p_fit_mem = real_time_mem / ( (hashsize + 1) * sizeof(llong));
   if( opt_val->p < p_fit_mem )
    p_fit_mem = opt_val->p;
   else if(p_fit_mem < 1)
    err(errno,"dist_dispatch():\n"
    " Kmer hashing need mem.(%lf G) exceed the mem. system or user provide (%lf G)\n"
    " user can either consider specify more mem.(-m ) or use smaller k value ( -k)\n"
    " or increase dimension reduction level ( -L)\n",
    (double)hashsize * sizeof(llong)/1e9, opt_val->mmry);
   size_t phash_mem = (llong)p_fit_mem * (hashsize + 1) * sizeof(llong);
real_time_mem -= phash_mem;
   opt_val->abundance = false;
   const char *refcostat = run_stageI(opt_val, ref_stat, shuffled_refname_ind, dist_refco_dir, p_fit_mem);
   run_stageII(refcostat, opt_val->outdir , opt_val->p);
   free(dim_shuffle->shuffled_dim);
real_time_mem += mem_usage_stat.shuffled_subctx_arr_sz;
  }
  else if ( refco_dstat_fpath != NULL) {
   if (refmco_dstat_fpath == NULL)
    run_stageII(refco_dstat_fpath, opt_val->refpath ,opt_val->p);
  }
  else if(refmco_dstat_fpath != NULL) {;}
  free((char*)refco_dstat_fpath);
  free((char*)refmco_dstat_fpath);
 }
 if ( (opt_val->num_remaining_args >0) || (opt_val->fpath[0] != '\0' ) )
 {
  const char *qryco_dstat_fpath = NULL;
  const char *qrymco_dstat_fpath = NULL;
  if((opt_val->pipecmd[0]=='\0') && (opt_val->num_remaining_args >0)){
   qryco_dstat_fpath = test_get_fullpath(opt_val->remaining_args[0],co_dstat);
   qrymco_dstat_fpath = test_get_fullpath(opt_val->remaining_args[0],mco_dstat);
  }
  if(opt_val->refpath[0] != '\0'){
   const char *ref_db = test_get_fullpath(opt_val->refpath, mco_dstat);
   if(ref_db==NULL) err(errno,"need speficy the ref-sketch path for -r to run the query-ref search model");
   FILE * ref_mco_stat_fp;
    if ((ref_mco_stat_fp = fopen(ref_db,"rb")) == NULL) err(errno,"mco stat file:%s",ref_db );
   mco_dstat_t mco_ref_dstat;
   fread( &mco_ref_dstat, sizeof(mco_dstat_t),1,ref_mco_stat_fp );
   fclose(ref_mco_stat_fp);
   if( qryco_dstat_fpath != NULL ){
    FILE *qry_co_stat_fp;
    if (( qry_co_stat_fp = fopen(qryco_dstat_fpath,"rb")) == NULL) err(errno,"qry co stat file:%s",qryco_dstat_fpath);
    co_dstat_t co_qry_dstat;
    fread( &co_qry_dstat, sizeof(co_dstat_t), 1, qry_co_stat_fp);
    if(co_qry_dstat.shuf_id != mco_ref_dstat.shuf_id )
     err(errno, "qry shuf_id: %d not match ref shuf_id: %d\ntry regenerate .co dir and feed -s the .shuf"
           "file used to generated ref database",co_qry_dstat.shuf_id,mco_ref_dstat.shuf_id);
    else if(co_qry_dstat.comp_num != mco_ref_dstat.comp_num)
     err(errno, "qry comp_num: %d not match ref comp_num: %d",co_qry_dstat.comp_num, mco_ref_dstat.comp_num);
    mco_cbdco_nobin_dist(opt_val);
    }
   else if (qrymco_dstat_fpath != NULL)
    err(errno,"when -r specified, the query sould not be .mco format, the valid query format shoulde be .fas/.fq file or .co");
   else{
    infile_tab_t *infile_stat = dist_organize_infiles(opt_val);
    infile_fmt_count_t* qry_fmt_count;
      qry_fmt_count = infile_fmt_count(infile_stat);
    bool is_valid_fas_fq_in = (infile_stat->infile_num != 0) &&
       (qry_fmt_count->fasta + qry_fmt_count->fastq == infile_stat->infile_num );
    if(is_valid_fas_fq_in){
    }
    else err(errno,"please specify valid query genomes seq or .co file for database search");
   }
  }
  else if( qryco_dstat_fpath != NULL) {
   if( opt_val->num_remaining_args == 1 ){
       run_stageII(qryco_dstat_fpath,opt_val->outdir, opt_val->p);
   }
   else if (opt_val->num_remaining_args > 1){
    combine_queries(opt_val);
   }
    }
  else if ( (qrymco_dstat_fpath != NULL) && (opt_val->num_remaining_args > 1 )){
  }
  else {
    infile_tab_t *infile_stat = dist_organize_infiles(opt_val);
        infile_fmt_count_t* qry_fmt_count;
        qry_fmt_count = infile_fmt_count(infile_stat);
        bool is_valid_fas_fq_in = (infile_stat->infile_num != 0) &&
          (qry_fmt_count->fasta + qry_fmt_count->fastq == infile_stat->infile_num );
        if(is_valid_fas_fq_in || (opt_val->pipecmd[0] != '\0') ){
          const char *dist_co_dir = opt_val->outdir;
     mkdir(dist_co_dir,0777);
     int *shuffled_refname_ind = shuffleN( infile_stat->infile_num, 0 );
     mem_usage_stat.input_file_name_sz = infile_stat->infile_num * ( sizeof(llong) + PATHLEN*sizeof(char) );
real_time_mem -= mem_usage_stat.input_file_name_sz;
     dim_shuffle = get_dim_shuffle(opt_val);
        hashsize = get_hashsz(dim_shuffle);
        seq2co_global_var_initial();
        mem_usage_stat.shuffled_subctx_arr_sz = (1LLU << 4*( dim_shuffle->dim_shuffle_stat.subk) )*sizeof(int);
real_time_mem -= mem_usage_stat.shuffled_subctx_arr_sz;
     p_fit_mem = real_time_mem / ( (hashsize + 1) * sizeof(llong));
     if( opt_val->p < p_fit_mem ) p_fit_mem = opt_val->p;
        else if(p_fit_mem < 1)
          err(errno,"dist_dispatch():\n"
          " Kmer hashing need mem.(%lf G) exceed the mem. system or user provide (%lf G)\n"
          " user can either consider specify more mem.(-m ) or use smaller k value ( -k)\n"
          " or increase dimension reduction level ( -L)\n",
          (double)hashsize * sizeof(llong)/1e9, opt_val->mmry);
     size_t phash_mem = (llong)p_fit_mem * (hashsize + 1) * sizeof(llong);
real_time_mem -= phash_mem ;
        run_stageI(opt_val,infile_stat,shuffled_refname_ind,dist_co_dir,p_fit_mem);
        }
    else err(errno,"not valid raw seq format");
  }
 }
 return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movsd 0x110(%rdi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x6796
jp 0x6796
callq 0x114a8
movsd %xmm0, 0x110(%rbx)
movsd %xmm0, (%rsp)
callq 0x114a8
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0xef8f(%rip), %xmm1     # 0x15740
cvttsd2si %xmm1, %r14
subq 0x16033(%rip), %r14     # 0x1c7f0
callq 0x114a8
mulsd 0xef76(%rip), %xmm0     # 0x15740
cvttsd2si %xmm0, %rax
addq %r14, %rax
movq %rax, 0x17d07(%rip)     # 0x1e4e0
leaq 0x122(%rbx), %r14
cmpb $0x0, 0x122(%rbx)
je 0x699e
leaq 0xefbc(%rip), %rsi      # 0x157b0
movq %r14, %rdi
callq 0x6d79
movq %rax, %r15
leaq 0xefb7(%rip), %rsi      # 0x157bd
movq %r14, %rdi
callq 0x6d79
movq %rax, %r12
movq %r15, %rax
orq %r12, %rax
jne 0x6970
movq %rbx, %rdi
callq 0x6e1c
cmpl $0x0, (%rax)
je 0x6cf0
movq %rax, %r13
movq %rax, %rdi
callq 0x1205e
movl (%r13), %ecx
testl %ecx, %ecx
je 0x6c78
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
jne 0x6c78
leaq 0x322(%rbx), %rdi
movq %rdi, (%rsp)
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movl (%r13), %edi
xorl %esi, %esi
callq 0x111b7
movq %rax, 0x8(%rsp)
movslq (%r13), %rax
movq %rax, %rcx
shlq $0x8, %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x15f5b(%rip)     # 0x1c7e8
subq %rax, 0x17c4c(%rip)     # 0x1e4e0
movq %rbx, %rdi
callq 0x6fd4
leaq 0x57d6d(%rip), %rbp     # 0x5e610
movq %rax, (%rbp)
movq %rax, %rdi
callq 0x70bf
leaq 0x57d72(%rip), %rcx     # 0x5e628
movl %eax, (%rcx)
callq 0x12d6c
movq (%rbp), %rax
movb 0x8(%rax), %cl
shlb $0x2, %cl
movl $0x4, %eax
shlq %cl, %rax
movq %rax, 0x15f0a(%rip)     # 0x1c7e0
movq 0x17c03(%rip), %rcx     # 0x1e4e0
subq %rax, %rcx
movq %rcx, 0x17bf9(%rip)     # 0x1e4e0
leaq 0x57d3a(%rip), %rax     # 0x5e628
movl (%rax), %ebp
leal 0x1(%rbp), %esi
shlq $0x3, %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movl 0x4(%rbx), %edx
cmpl %eax, %edx
jl 0x6910
movl %eax, %edx
testl %eax, %eax
jle 0x6d26
movslq %edx, %r8
imulq %r8, %rsi
subq %rsi, %rcx
movq %rcx, 0x17bbf(%rip)     # 0x1e4e0
movb $0x0, 0x449(%rbx)
movq %rbx, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq (%rsp), %r13
movq %r13, %rcx
callq 0x7176
movl 0x4(%rbx), %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7982
leaq 0x57cbc(%rip), %rax     # 0x5e610
movq (%rax), %rax
movq 0x10(%rax), %rdi
callq 0x3040
movq 0x15e79(%rip), %rax     # 0x1c7e0
addq %rax, 0x17b72(%rip)     # 0x1e4e0
jmp 0x698e
testq %r12, %r12
setne %al
testq %r15, %r15
sete %cl
orb %al, %cl
jne 0x698e
movl 0x4(%rbx), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x7982
movq %r15, %rdi
callq 0x3040
movq %r12, %rdi
callq 0x3040
cmpl $0x0, 0x650(%rbx)
jle 0x69ef
leaq 0x44b(%rbx), %r12
cmpb $0x0, 0x44b(%rbx)
jne 0x6a03
movq 0x658(%rbx), %rax
movq (%rax), %rdi
leaq 0xede8(%rip), %rsi      # 0x157b0
callq 0x6d79
movq %rax, %r15
movq 0x658(%rbx), %rax
movq (%rax), %rdi
leaq 0xeddc(%rip), %rsi      # 0x157bd
callq 0x6d79
testq %rax, %rax
sete %bpl
jmp 0x6a09
cmpb $0x0, 0x222(%rbx)
je 0x6c67
leaq 0x44b(%rbx), %r12
movb $0x1, %bpl
xorl %r15d, %r15d
cmpb $0x0, (%r14)
je 0x6ad3
leaq 0xeda3(%rip), %rsi      # 0x157bd
movq %r14, %rdi
callq 0x6d79
testq %rax, %rax
je 0x6c88
movq %rax, %r14
leaq 0xe632(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x6c9b
movq %rax, %r12
leaq 0x14(%rsp), %rdi
movl $0x14, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x30c0
movq %r12, %rdi
callq 0x3100
testq %r15, %r15
je 0x6b01
leaq 0xe5ef(%rip), %rsi      # 0x15067
movq %r15, %rdi
callq 0x33a0
testq %rax, %rax
je 0x6cae
leaq 0x28(%rsp), %r14
movl $0x20, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rax, %rcx
callq 0x30c0
movl (%r14), %ebp
movl 0x14(%rsp), %r14d
cmpl %r14d, %ebp
jne 0x6cc6
movl 0x38(%rsp), %ebp
movl 0x20(%rsp), %r14d
cmpl %r14d, %ebp
jne 0x6cd6
movq %rbx, %rdi
callq 0x7b93
jmp 0x6c67
testq %r15, %r15
je 0x6b43
movl 0x650(%rbx), %eax
cmpl $0x1, %eax
jne 0x6c5d
movl 0x4(%rbx), %edx
addq $0x322, %rbx            # imm = 0x322
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7982
jmp 0x6c67
testb %bpl, %bpl
je 0x6d16
movq %rbx, %rdi
callq 0x87e7
movq %rax, %rbx
movq %rax, %rdi
callq 0x1205e
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x6b30
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
je 0x6c67
callq 0x3060
movl (%rax), %edi
leaq 0xf04d(%rip), %rsi      # 0x15b8b
jmp 0x6d3d
testb %bpl, %bpl
jne 0x6b55
cmpl $0x1, 0x650(%rbx)
jg 0x6c67
movq %rbx, %rdi
callq 0x87e7
movq %rax, %r14
movq %rax, %rdi
callq 0x1205e
movl (%r14), %ecx
testl %ecx, %ecx
je 0x6b78
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
je 0x6b83
cmpb $0x0, (%r12)
je 0x6d2f
leaq 0x322(%rbx), %r15
movq %r15, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movl (%r14), %edi
xorl %esi, %esi
callq 0x111b7
movq %rax, %r12
movslq (%r14), %rax
movq %rax, %rcx
shlq $0x8, %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x15c2f(%rip)     # 0x1c7e8
subq %rax, 0x17920(%rip)     # 0x1e4e0
movq %rbx, %rdi
callq 0x6fd4
leaq 0x57a41(%rip), %r13     # 0x5e610
movq %rax, (%r13)
movq %rax, %rdi
callq 0x70bf
leaq 0x57a46(%rip), %rbp     # 0x5e628
movl %eax, (%rbp)
callq 0x12d6c
movq (%r13), %rax
movb 0x8(%rax), %cl
shlb $0x2, %cl
movl $0x4, %eax
shlq %cl, %rax
movq %rax, 0x15bdd(%rip)     # 0x1c7e0
movq 0x178d6(%rip), %rcx     # 0x1e4e0
subq %rax, %rcx
movq %rcx, 0x178cc(%rip)     # 0x1e4e0
movl (%rbp), %r13d
leal 0x1(%r13), %esi
shlq $0x3, %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movl 0x4(%rbx), %edx
cmpl %eax, %edx
jl 0x6c39
movl %eax, %edx
testl %eax, %eax
jle 0x6d44
movslq %edx, %r8
imulq %r8, %rsi
subq %rsi, %rcx
movq %rcx, 0x17896(%rip)     # 0x1e4e0
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x7176
jmp 0x6c67
jle 0x6c67
movq %rbx, %rdi
callq 0x8833
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0xec35(%rip), %rsi      # 0x158bb
jmp 0x6cfe
callq 0x3060
movl (%rax), %edi
leaq 0xed72(%rip), %rsi      # 0x15a08
jmp 0x6d3d
callq 0x3060
movl (%rax), %edi
leaq 0xeda9(%rip), %rsi      # 0x15a52
movq %r14, %rdx
jmp 0x6cbf
callq 0x3060
movl (%rax), %edi
leaq 0xeda7(%rip), %rsi      # 0x15a63
movq %r15, %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xeda3(%rip), %rsi      # 0x15a77
jmp 0x6ce4
callq 0x3060
movl (%rax), %edi
leaq 0xee0d(%rip), %rsi      # 0x15af1
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xeb86(%rip), %rsi      # 0x15884
leaq 0xeaab(%rip), %rdx      # 0x157b0
leaq 0xeab1(%rip), %rcx      # 0x157bd
movq %r14, %r8
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xedf9(%rip), %rsi      # 0x15b1d
jmp 0x6d3d
callq 0x3060
movl %ebp, %ecx
jmp 0x6d4c
callq 0x3060
movl (%rax), %edi
leaq 0xee95(%rip), %rsi      # 0x15bd2
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl %r13d, %ecx
cvtsi2sd %rcx, %xmm0
mulsd 0xe9ef(%rip), %xmm0     # 0x15748
movl (%rax), %edi
divsd 0xe9ed(%rip), %xmm0     # 0x15750
movsd 0x110(%rbx), %xmm1
leaq 0xebbb(%rip), %rsi      # 0x1592d
movb $0x2, %al
callq 0x3330