// File: /workspace/github_c_makefile_star2_O2/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 0x62d6
jp 0x62d6
callq 0x1058c
movsd %xmm0, 0x110(%rbx)
movsd %xmm0, (%rsp)
callq 0x1058c
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0xe3ff(%rip), %xmm1     # 0x146f0
cvttsd2si %xmm1, %r14
subq 0x154f3(%rip), %r14     # 0x1b7f0
callq 0x1058c
mulsd 0xe3e6(%rip), %xmm0     # 0x146f0
cvttsd2si %xmm0, %rax
addq %r14, %rax
movq %rax, 0x171c7(%rip)     # 0x1d4e0
leaq 0x122(%rbx), %r14
cmpb $0x0, 0x122(%rbx)
je 0x64d8
leaq 0xe42c(%rip), %rsi      # 0x14760
movq %r14, %rdi
callq 0x68a5
movq %rax, %r15
leaq 0xe427(%rip), %rsi      # 0x1476d
movq %r14, %rdi
callq 0x68a5
movq %rax, %r12
movq %r15, %rax
orq %r12, %rax
jne 0x64aa
movq %rbx, %rdi
callq 0x6948
cmpl $0x0, (%rax)
je 0x681c
movq %rax, %r13
movq %rax, %rdi
callq 0x10f0f
movl (%r13), %ecx
testl %ecx, %ecx
je 0x67a4
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
jne 0x67a4
leaq 0x322(%rbx), %rdi
movq %rdi, (%rsp)
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movl (%r13), %edi
xorl %esi, %esi
callq 0x10341
movq %rax, 0x8(%rsp)
movslq (%r13), %rax
imulq $0x108, %rax, %rax      # imm = 0x108
movq %rax, 0x1541f(%rip)     # 0x1b7e8
subq %rax, 0x17110(%rip)     # 0x1d4e0
movq %rbx, %rdi
callq 0x69e5
leaq 0x57231(%rip), %rbp     # 0x5d610
movq %rax, (%rbp)
movq %rax, %rdi
callq 0x6ad0
leaq 0x57236(%rip), %rcx     # 0x5d628
movl %eax, (%rcx)
callq 0x116fc
movq (%rbp), %rax
movb 0x8(%rax), %cl
shlb $0x2, %cl
pushq $0x4
popq %rax
shlq %cl, %rax
movq %rax, 0x153d0(%rip)     # 0x1b7e0
movq 0x170c9(%rip), %rcx     # 0x1d4e0
subq %rax, %rcx
movq %rcx, 0x170bf(%rip)     # 0x1d4e0
leaq 0x57200(%rip), %rax     # 0x5d628
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 0x644a
movl %eax, %edx
testl %eax, %eax
jle 0x6852
movslq %edx, %r8
imulq %r8, %rsi
subq %rsi, %rcx
movq %rcx, 0x17085(%rip)     # 0x1d4e0
movb $0x0, 0x449(%rbx)
movq %rbx, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq (%rsp), %r13
movq %r13, %rcx
callq 0x6b75
movl 0x4(%rbx), %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7229
leaq 0x57182(%rip), %rax     # 0x5d610
movq (%rax), %rax
movq 0x10(%rax), %rdi
callq 0x3040
movq 0x1533f(%rip), %rax     # 0x1b7e0
addq %rax, 0x17038(%rip)     # 0x1d4e0
jmp 0x64c8
testq %r12, %r12
setne %al
testq %r15, %r15
sete %cl
orb %al, %cl
jne 0x64c8
movl 0x4(%rbx), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x7229
movq %r15, %rdi
callq 0x3040
movq %r12, %rdi
callq 0x3040
cmpl $0x0, 0x650(%rbx)
jle 0x6529
leaq 0x44b(%rbx), %r12
cmpb $0x0, 0x44b(%rbx)
jne 0x653d
movq 0x658(%rbx), %rax
movq (%rax), %rdi
leaq 0xe25e(%rip), %rsi      # 0x14760
callq 0x68a5
movq %rax, %r15
movq 0x658(%rbx), %rax
movq (%rax), %rdi
leaq 0xe252(%rip), %rsi      # 0x1476d
callq 0x68a5
testq %rax, %rax
sete %bpl
jmp 0x6543
cmpb $0x0, 0x222(%rbx)
je 0x6793
leaq 0x44b(%rbx), %r12
movb $0x1, %bpl
xorl %r15d, %r15d
cmpb $0x0, (%r14)
je 0x6605
leaq 0xe219(%rip), %rsi      # 0x1476d
movq %r14, %rdi
callq 0x68a5
testq %rax, %rax
je 0x67b4
movq %rax, %r14
leaq 0xdaf8(%rip), %rsi      # 0x14067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x67c7
movq %rax, %r12
leaq 0x14(%rsp), %rdi
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x30c0
movq %r12, %rdi
callq 0x3100
testq %r15, %r15
je 0x6633
leaq 0xdab9(%rip), %rsi      # 0x14067
movq %r15, %rdi
callq 0x33a0
testq %rax, %rax
je 0x67da
leaq 0x28(%rsp), %r14
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rcx
callq 0x30c0
movl (%r14), %ebp
movl 0x14(%rsp), %r14d
cmpl %r14d, %ebp
jne 0x67f2
movl 0x38(%rsp), %ebp
movl 0x20(%rsp), %r14d
cmpl %r14d, %ebp
jne 0x6802
movq %rbx, %rdi
callq 0x7432
jmp 0x6793
testq %r15, %r15
je 0x6675
movl 0x650(%rbx), %eax
cmpl $0x1, %eax
jne 0x6789
movl 0x4(%rbx), %edx
addq $0x322, %rbx            # imm = 0x322
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7229
jmp 0x6793
testb %bpl, %bpl
je 0x6842
movq %rbx, %rdi
callq 0x7dd2
movq %rax, %rbx
movq %rax, %rdi
callq 0x10f0f
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x6662
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
je 0x6793
callq 0x3060
movl (%rax), %edi
leaq 0xe4cb(%rip), %rsi      # 0x14b3b
jmp 0x6869
testb %bpl, %bpl
jne 0x6687
cmpl $0x1, 0x650(%rbx)
jg 0x6793
movq %rbx, %rdi
callq 0x7dd2
movq %rax, %r14
movq %rax, %rdi
callq 0x10f0f
movl (%r14), %ecx
testl %ecx, %ecx
je 0x66aa
movl 0x4(%rax), %edx
addl (%rax), %edx
cmpl %ecx, %edx
je 0x66b5
cmpb $0x0, (%r12)
je 0x685b
leaq 0x322(%rbx), %r15
movq %r15, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movl (%r14), %edi
xorl %esi, %esi
callq 0x10341
movq %rax, %r12
movslq (%r14), %rax
imulq $0x108, %rax, %rax      # imm = 0x108
movq %rax, 0x15101(%rip)     # 0x1b7e8
subq %rax, 0x16df2(%rip)     # 0x1d4e0
movq %rbx, %rdi
callq 0x69e5
leaq 0x56f13(%rip), %r13     # 0x5d610
movq %rax, (%r13)
movq %rax, %rdi
callq 0x6ad0
leaq 0x56f18(%rip), %rbp     # 0x5d628
movl %eax, (%rbp)
callq 0x116fc
movq (%r13), %rax
movb 0x8(%rax), %cl
shlb $0x2, %cl
pushq $0x4
popq %rax
shlq %cl, %rax
movq %rax, 0x150b1(%rip)     # 0x1b7e0
movq 0x16daa(%rip), %rcx     # 0x1d4e0
subq %rax, %rcx
movq %rcx, 0x16da0(%rip)     # 0x1d4e0
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 0x6765
movl %eax, %edx
testl %eax, %eax
jle 0x6870
movslq %edx, %r8
imulq %r8, %rsi
subq %rsi, %rcx
movq %rcx, 0x16d6a(%rip)     # 0x1d4e0
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x6b75
jmp 0x6793
jle 0x6793
movq %rbx, %rdi
callq 0x7e1e
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 0xe0b9(%rip), %rsi      # 0x1486b
jmp 0x682a
callq 0x3060
movl (%rax), %edi
leaq 0xe1f6(%rip), %rsi      # 0x149b8
jmp 0x6869
callq 0x3060
movl (%rax), %edi
leaq 0xe22d(%rip), %rsi      # 0x14a02
movq %r14, %rdx
jmp 0x67eb
callq 0x3060
movl (%rax), %edi
leaq 0xe22b(%rip), %rsi      # 0x14a13
movq %r15, %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xe227(%rip), %rsi      # 0x14a27
jmp 0x6810
callq 0x3060
movl (%rax), %edi
leaq 0xe291(%rip), %rsi      # 0x14aa1
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xe00a(%rip), %rsi      # 0x14834
leaq 0xdf2f(%rip), %rdx      # 0x14760
leaq 0xdf35(%rip), %rcx      # 0x1476d
movq %r14, %r8
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xe27d(%rip), %rsi      # 0x14acd
jmp 0x6869
callq 0x3060
movl %ebp, %ecx
jmp 0x6878
callq 0x3060
movl (%rax), %edi
leaq 0xe319(%rip), %rsi      # 0x14b82
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl %r13d, %ecx
cvtsi2sd %rcx, %xmm0
mulsd 0xde73(%rip), %xmm0     # 0x146f8
movl (%rax), %edi
divsd 0xde71(%rip), %xmm0     # 0x14700
movsd 0x110(%rbx), %xmm1
leaq 0xe03f(%rip), %rsi      # 0x148dd
movb $0x2, %al
callq 0x3330