// File: /workspace/github_c_makefile_star2_O1/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 0x65da
jp 0x65da
callq 0x110fc
movsd %xmm0, 0x110(%rbx)
movsd 0x110(%rbx), %xmm0
movsd %xmm0, (%rsp)
callq 0x110fc
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0xf0f3(%rip), %xmm1     # 0x156f0
cvttsd2si %xmm1, %r14
subq 0x161e7(%rip), %r14     # 0x1c7f0
callq 0x110fc
mulsd 0xf0da(%rip), %xmm0     # 0x156f0
cvttsd2si %xmm0, %rax
addq %r14, %rax
movq %rax, 0x17ebb(%rip)     # 0x1e4e0
leaq 0x122(%rbx), %r14
cmpb $0x0, 0x122(%rbx)
je 0x67f2
leaq 0xf120(%rip), %rsi      # 0x15760
movq %r14, %rdi
callq 0x6bcc
movq %rax, %r15
leaq 0xf11b(%rip), %rsi      # 0x1576d
movq %r14, %rdi
callq 0x6bcc
movq %rax, %r12
movq %r15, %rax
orq %r12, %rax
jne 0x67c4
movq %rbx, %rdi
callq 0x6c6f
cmpl $0x0, (%rax)
je 0x6b43
movq %rax, %r13
movq %rax, %rdi
callq 0x11b1a
movl (%r13), %ecx
testl %ecx, %ecx
je 0x6acb
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
jne 0x6acb
leaq 0x322(%rbx), %rdi
movq %rdi, (%rsp)
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movl (%r13), %edi
xorl %esi, %esi
callq 0x10e9a
movq %rax, 0x8(%rsp)
movslq (%r13), %rax
movq %rax, %rcx
shlq $0x8, %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x1610f(%rip)     # 0x1c7e8
subq %rax, 0x17e00(%rip)     # 0x1e4e0
movq %rbx, %rdi
callq 0x6d15
leaq 0x57f21(%rip), %rbp     # 0x5e610
movq %rax, (%rbp)
movq %rax, %rdi
callq 0x6e00
leaq 0x57f26(%rip), %rcx     # 0x5e628
movl %eax, (%rcx)
callq 0x12434
movq (%rbp), %rax
movb 0x8(%rax), %cl
shlb $0x2, %cl
movl $0x4, %eax
shlq %cl, %rax
movq %rax, 0x160be(%rip)     # 0x1c7e0
movq 0x17db7(%rip), %rcx     # 0x1e4e0
subq %rax, %rcx
movq %rcx, 0x17dad(%rip)     # 0x1e4e0
leaq 0x57eee(%rip), %rax     # 0x5e628
movl (%rax), %ebp
leal 0x1(%rbp), %esi
leaq (,%rsi,8), %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
movl 0x4(%rbx), %edx
cmpl %eax, %edx
jl 0x6760
movl %eax, %edx
testl %eax, %eax
jle 0x6b79
movslq %edx, %r8
imulq %r8, %rsi
shlq $0x3, %rsi
subq %rsi, %rcx
movq %rcx, 0x17d6b(%rip)     # 0x1e4e0
movb $0x0, 0x449(%rbx)
movq %rbx, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq (%rsp), %r13
movq %r13, %rcx
callq 0x6eb7
movl 0x4(%rbx), %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x75d4
leaq 0x57e68(%rip), %rax     # 0x5e610
movq (%rax), %rax
movq 0x10(%rax), %rdi
callq 0x3040
movq 0x16025(%rip), %rax     # 0x1c7e0
addq %rax, 0x17d1e(%rip)     # 0x1e4e0
jmp 0x67e2
testq %r12, %r12
setne %al
testq %r15, %r15
sete %cl
orb %al, %cl
jne 0x67e2
movl 0x4(%rbx), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x75d4
movq %r15, %rdi
callq 0x3040
movq %r12, %rdi
callq 0x3040
movl 0x650(%rbx), %eax
testl %eax, %eax
jg 0x6809
cmpb $0x0, 0x222(%rbx)
je 0x6aba
xorl %r15d, %r15d
movb $0x1, %bpl
testl %eax, %eax
jle 0x6852
cmpb $0x0, 0x44b(%rbx)
jne 0x6852
movq 0x658(%rbx), %rax
movq (%rax), %rdi
leaq 0xef33(%rip), %rsi      # 0x15760
callq 0x6bcc
movq %rax, %r15
movq 0x658(%rbx), %rax
movq (%rax), %rdi
leaq 0xef27(%rip), %rsi      # 0x1576d
callq 0x6bcc
testq %rax, %rax
sete %bpl
cmpb $0x0, (%r14)
je 0x691c
leaq 0xef0a(%rip), %rsi      # 0x1576d
movq %r14, %rdi
callq 0x6bcc
testq %rax, %rax
je 0x6adb
movq %rax, %r14
leaq 0xe7e9(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x6aee
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 0x694a
leaq 0xe7a6(%rip), %rsi      # 0x15067
movq %r15, %rdi
callq 0x33a0
testq %rax, %rax
je 0x6b01
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 0x6b19
movl 0x38(%rsp), %ebp
movl 0x20(%rsp), %r14d
cmpl %r14d, %ebp
jne 0x6b29
movq %rbx, %rdi
callq 0x77ec
jmp 0x6aba
testq %r15, %r15
je 0x698c
movl 0x650(%rbx), %eax
cmpl $0x1, %eax
jne 0x6ab0
movl 0x4(%rbx), %edx
addq $0x322, %rbx            # imm = 0x322
movq %r15, %rdi
movq %rbx, %rsi
callq 0x75d4
jmp 0x6aba
testb %bpl, %bpl
je 0x6b69
movq %rbx, %rdi
callq 0x845e
movq %rax, %rbx
movq %rax, %rdi
callq 0x11b1a
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x6979
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
je 0x6aba
callq 0x3060
movl (%rax), %edi
leaq 0xf1b4(%rip), %rsi      # 0x15b3b
jmp 0x6b90
testb %bpl, %bpl
jne 0x699e
cmpl $0x1, 0x650(%rbx)
jg 0x6aba
movq %rbx, %rdi
callq 0x845e
movq %rax, %r14
movq %rax, %rdi
callq 0x11b1a
movl (%r14), %ecx
testl %ecx, %ecx
je 0x69c1
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
je 0x69ce
cmpb $0x0, 0x44b(%rbx)
je 0x6b82
leaq 0x322(%rbx), %r15
movq %r15, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movl (%r14), %edi
xorl %esi, %esi
callq 0x10e9a
movq %rax, %r12
movslq (%r14), %rax
movq %rax, %rcx
shlq $0x8, %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x15de4(%rip)     # 0x1c7e8
subq %rax, 0x17ad5(%rip)     # 0x1e4e0
movq %rbx, %rdi
callq 0x6d15
leaq 0x57bf6(%rip), %r13     # 0x5e610
movq %rax, (%r13)
movq %rax, %rdi
callq 0x6e00
leaq 0x57bfb(%rip), %rbp     # 0x5e628
movl %eax, (%rbp)
callq 0x12434
movq (%r13), %rax
movb 0x8(%rax), %cl
shlb $0x2, %cl
movl $0x4, %eax
shlq %cl, %rax
movq %rax, 0x15d92(%rip)     # 0x1c7e0
movq 0x17a8b(%rip), %rcx     # 0x1e4e0
subq %rax, %rcx
movq %rcx, 0x17a81(%rip)     # 0x1e4e0
movl (%rbp), %r13d
leal 0x1(%r13), %esi
leaq (,%rsi,8), %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
movl 0x4(%rbx), %edx
cmpl %eax, %edx
jl 0x6a88
movl %eax, %edx
testl %eax, %eax
jle 0x6b97
movslq %edx, %r8
imulq %r8, %rsi
shlq $0x3, %rsi
subq %rsi, %rcx
movq %rcx, 0x17a43(%rip)     # 0x1e4e0
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x6eb7
jmp 0x6aba
jle 0x6aba
movq %rbx, %rdi
callq 0x84aa
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 0xed92(%rip), %rsi      # 0x1586b
jmp 0x6b51
callq 0x3060
movl (%rax), %edi
leaq 0xeecf(%rip), %rsi      # 0x159b8
jmp 0x6b90
callq 0x3060
movl (%rax), %edi
leaq 0xef06(%rip), %rsi      # 0x15a02
movq %r14, %rdx
jmp 0x6b12
callq 0x3060
movl (%rax), %edi
leaq 0xef04(%rip), %rsi      # 0x15a13
movq %r15, %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xef00(%rip), %rsi      # 0x15a27
jmp 0x6b37
callq 0x3060
movl (%rax), %edi
leaq 0xef6a(%rip), %rsi      # 0x15aa1
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xece3(%rip), %rsi      # 0x15834
leaq 0xec08(%rip), %rdx      # 0x15760
leaq 0xec0e(%rip), %rcx      # 0x1576d
movq %r14, %r8
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xef56(%rip), %rsi      # 0x15acd
jmp 0x6b90
callq 0x3060
movl %ebp, %ecx
jmp 0x6b9f
callq 0x3060
movl (%rax), %edi
leaq 0xeff2(%rip), %rsi      # 0x15b82
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl %r13d, %ecx
cvtsi2sd %rcx, %xmm0
mulsd 0xeb4c(%rip), %xmm0     # 0x156f8
movl (%rax), %edi
divsd 0xeb4a(%rip), %xmm0     # 0x15700
movsd 0x110(%rbx), %xmm1
leaq 0xed18(%rip), %rsi      # 0x158dd
movb $0x2, %al
callq 0x3330