// File: /workspace/github_c_makefile_star2_O1/yhg926[P]public_kssd/command_dist.c
// Function: run_stageI
const char * run_stageI (dist_opt_val_t *opt_val, infile_tab_t *seqfile_stat,
      int* shuffled_seqfname_ind, const char *co_dir, int p_fit_mem)
{
 llong **CO = malloc( p_fit_mem * sizeof(llong *) );
  for(int i = 0; i< p_fit_mem; i++ ){
   CO[i] = (llong *)malloc(hashsize * sizeof(llong) );
 }
 llong all_ctx_ct = 0 ;
 ctx_obj_ct_t *ctx_ct_list = malloc(sizeof(ctx_obj_ct_t) * seqfile_stat->infile_num);
 if(opt_val->byread){
  for(int i = 0; i< seqfile_stat->infile_num; i++){
   char* seqfname = seqfile_stat->organized_infile_tab[ shuffled_seqfname_ind[i] ].fpath;
   printf("decomposing %s by reads\n",seqfname) ;
   reads2mco(seqfname, co_dir, opt_val->pipecmd);
  }
 }
 else {
  int num_threads = seqfile_stat->infile_num > p_fit_mem ? p_fit_mem : 1;
  int fcount = 0;
#pragma omp parallel for num_threads(num_threads) reduction(+:all_ctx_ct) schedule(guided)
   for(int i = 0; i< seqfile_stat->infile_num; i++){
     int tid = 0;
#ifdef _OPENMP
      tid = omp_get_thread_num();
#endif
      char* seqfname = seqfile_stat->organized_infile_tab[ shuffled_seqfname_ind[i] ].fpath;
      char cofname[PATHLEN];
      sprintf(cofname,"%s/%d.co",co_dir,i);
      llong *co;
      if(isOK_fmt_infile(seqfname,fastq_fmt,FQ_FMT_SZ) || opt_val->pipecmd[0]!='\0'){
    if(opt_val->abundance){
     co = mt_shortreads2koc(seqfname,CO[tid],opt_val->pipecmd, p_fit_mem);
      ctx_ct_list[i] = write_fqkoc2files(cofname,co);
    }
    else{
     co = fastq2co(seqfname,CO[tid],opt_val->pipecmd,opt_val->kmerqlty,opt_val->kmerocrs);
         ctx_ct_list[i] = write_fqco2file(cofname,co);
    }
       }
       else{
    if(opt_val->abundance) {
     opt_val->abundance = 0;
     printf("Warning: close abundance mode (-A) since non-fastq file input.\n");
    }
    if(opt_val->u)
     co = uniq_fasta2co(seqfname,CO[tid],opt_val->pipecmd);
    else
      co = fasta2co(seqfname,CO[tid],opt_val->pipecmd);
        ctx_ct_list[i] = wrt_co2cmpn_use_inn_subctx(cofname,co);
       }
   all_ctx_ct += ctx_ct_list[i] ;
#pragma omp atomic
   fcount++;
   printf("%d/%d decomposing %s\r",fcount,seqfile_stat->infile_num,seqfname) ;
  }
  printf("\n");
#pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
    for(int c = 0; c < component_num; c++){
   size_t *cof_index_in_cbdco = malloc( (seqfile_stat->infile_num + 1) * sizeof(size_t) );
      char tmpfname[PATHLEN];
      FILE *com_cofp,*indexfp, *com_abund_fp;
     sprintf(tmpfname,"%s/%s.%d",co_dir,skch_prefix,c);
   if( (com_cofp = fopen(tmpfname,"wb")) == NULL) err(errno,"%s",tmpfname);
      sprintf(tmpfname,"%s/%s.%d",co_dir,idx_prefix,c);
      if( (indexfp = fopen(tmpfname,"wb")) == NULL) err(errno,"%s",tmpfname);
   if(opt_val->abundance) {
    sprintf(tmpfname,"%s/%s.%d.a",co_dir,skch_prefix,c);
    com_abund_fp = fopen(tmpfname,"wb");
    if( com_abund_fp == NULL) err(errno,"%s",tmpfname);
   }
      void *tmp_mem = malloc( LD_FCTR * 2 * (1LLU << (4*COMPONENT_SZ - CTX_SPC_USE_L)) *sizeof(unsigned int) );
      struct stat tmpstat;
      FILE *tmpfp;
      cof_index_in_cbdco[0] = 0;
      for(int i = 0; i< seqfile_stat->infile_num; i++){
       sprintf(tmpfname,"%s/%d.co.%d", co_dir, i, c);
        if( (tmpfp = fopen(tmpfname,"rb")) == NULL) err(errno,"%s",tmpfname);
        stat(tmpfname,&tmpstat);
        int tmpkmerct = tmpstat.st_size/sizeof(unsigned int);
        cof_index_in_cbdco[i+1] = (size_t)cof_index_in_cbdco[i] + tmpkmerct;
        fread(tmp_mem,tmpstat.st_size,1,tmpfp);
        fwrite(tmp_mem,tmpstat.st_size,1,com_cofp);
        fclose(tmpfp);
        remove(tmpfname);
    if(opt_val->abundance) {
     sprintf(tmpfname,"%s/%d.co.%d.a", co_dir, i, c);
     if( (tmpfp = fopen(tmpfname,"rb")) == NULL) err(errno,"%s",tmpfname);
     fread(tmp_mem, sizeof(unsigned short)*tmpkmerct, 1 , tmpfp);
     fwrite(tmp_mem, sizeof(unsigned short)*tmpkmerct, 1 , com_abund_fp );
     fclose(tmpfp);
     remove(tmpfname);
    }
      }
      fclose(com_cofp);
   if(opt_val->abundance) fclose(com_abund_fp) ;
   free(tmp_mem);
      fwrite(cof_index_in_cbdco,sizeof(size_t), seqfile_stat->infile_num + 1, indexfp);
      fclose(indexfp);
      free(cof_index_in_cbdco);
    }
 }
  for(int i = 0; i< p_fit_mem; i++ ) free(CO[i]);
  free(CO);
  co_dstat_t co_dstat_wrout;
 co_dstat_wrout.shuf_id = dim_shuffle->dim_shuffle_stat.id ;
 co_dstat_wrout.koc = opt_val->abundance ;
 co_dstat_wrout.kmerlen = dim_shuffle->dim_shuffle_stat.k * 2;
 co_dstat_wrout.dim_rd_len = dim_shuffle->dim_shuffle_stat.drlevel * 2 ;
  co_dstat_wrout.comp_num = component_num ;
  co_dstat_wrout.infile_num = seqfile_stat->infile_num;
 co_dstat_wrout.all_ctx_ct = all_ctx_ct;
  char *co_dstat_fullname = malloc(PATHLEN*sizeof(char) );
  sprintf(co_dstat_fullname, "%s/%s",co_dir,co_dstat);
  FILE *coutfp;
  if ( ( coutfp = fopen(co_dstat_fullname,"wb")) == NULL ) err(errno,"%s",co_dstat_fullname);
   fwrite(&co_dstat_wrout,sizeof(co_dstat_wrout),1,coutfp);
 fwrite(ctx_ct_list,sizeof(ctx_obj_ct_t),co_dstat_wrout.infile_num,coutfp);
 free(ctx_ct_list);
 for(int i = 0; i< co_dstat_wrout.infile_num; i++)
  fwrite(seqfile_stat->organized_infile_tab[ shuffled_seqfname_ind[i] ].fpath,PATHLEN,1,coutfp);
  fclose(coutfp);
 return (const char *)co_dstat_fullname;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movl %r8d, %r14d
movq %rcx, 0x20(%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, 0x10(%rsp)
movslq %r8d, %rbx
leaq (,%rbx,8), %rdi
callq 0x3340
movq %rax, %r12
movl %r14d, 0x28(%rsp)
movl %r14d, %r15d
testl %ebx, %ebx
jle 0x6f1e
leaq 0x57727(%rip), %rax     # 0x5e628
movl (%rax), %ebx
shlq $0x3, %rbx
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x3340
movq %rax, (%r12,%r14,8)
incq %r14
cmpq %r14, %r15
jne 0x6f0a
movq %r15, 0x60(%rsp)
movslq (%rbp), %rdi
shlq $0x2, %rdi
callq 0x3340
movq %rax, 0x48(%rsp)
movl (%rbp), %eax
movq 0x10(%rsp), %rcx
cmpb $0x0, 0x64c(%rcx)
je 0x6fac
testl %eax, %eax
jle 0x712b
movq %r12, 0x18(%rsp)
leaq 0x44b(%rcx), %rbx
movq $0x0, (%rsp)
xorl %r12d, %r12d
movq 0x20(%rsp), %r14
movq 0x8(%rbp), %rax
movslq (%r13,%r12,4), %rcx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %r15
leaq 0xed93(%rip), %rdi      # 0x15d16
movq %r15, %rsi
xorl %eax, %eax
callq 0x3170
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12577
incq %r12
movslq (%rbp), %rax
cmpq %rax, %r12
jl 0x6f6a
jmp 0x7452
movq %r12, 0x18(%rsp)
movq %rbp, 0x8(%rsp)
movq %r13, 0x30(%rsp)
testl %eax, %eax
jle 0x713d
leaq 0x44b(%rcx), %rbx
leaq 0x70(%rsp), %r12
leaq 0xed62(%rip), %rbp      # 0x15d38
xorl %r14d, %r14d
movq $0x0, (%rsp)
movq 0x8(%rsp), %r15
movq 0x8(%r15), %rax
movq 0x30(%rsp), %rcx
movslq (%rcx,%r14,4), %rcx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %r13
movq %r12, %rdi
leaq 0xed29(%rip), %rsi      # 0x15d2f
movq 0x20(%rsp), %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
leaq 0x16fc1(%rip), %rsi     # 0x1dfe0
movl $0x2, %edx
callq 0x8e80
testl %eax, %eax
jne 0x7036
cmpb $0x0, (%rbx)
je 0x70ca
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movq 0x10(%rsp), %rax
cmpb $0x1, 0x449(%rax)
jne 0x7068
movq %r13, %rdi
movq %rbx, %rdx
movl 0x28(%rsp), %ecx
callq 0x13bd4
movq %r12, %rdi
movq %rax, %rsi
callq 0x135a0
jmp 0x708b
movl 0x424(%rax), %r8d
movl 0x428(%rax), %ecx
movq %r13, %rdi
movq %rbx, %rdx
callq 0x12e4d
movq %r12, %rdi
movq %rax, %rsi
callq 0x138fb
movq (%rsp), %r15
movq 0x48(%rsp), %rcx
movl %eax, (%rcx,%r14,4)
movl %eax, %eax
addq %rax, %r15
movq %r15, (%rsp)
incq %r14
movq 0x8(%rsp), %r15
movl (%r15), %edx
movq %rbp, %rdi
movl %r14d, %esi
movq %r13, %rcx
xorl %eax, %eax
callq 0x3170
movslq (%r15), %rax
cmpq %rax, %r14
jl 0x6fe6
jmp 0x7145
movq 0x10(%rsp), %r15
cmpb $0x1, 0x449(%r15)
jne 0x70ed
movb $0x0, 0x449(%r15)
leaq 0xf479(%rip), %rdi      # 0x16561
callq 0x30a0
movq 0x18(%rsp), %rax
movq (%rax), %rsi
cmpb $0x1, 0x44a(%r15)
jne 0x710c
movq %r13, %rdi
movq %rbx, %rdx
callq 0x14010
jmp 0x7117
movq %r13, %rdi
movq %rbx, %rdx
callq 0x12af5
movq (%rsp), %r15
movq %r12, %rdi
movq %rax, %rsi
callq 0x13a6d
jmp 0x708f
movq $0x0, (%rsp)
movq 0x20(%rsp), %r14
jmp 0x7457
movq $0x0, (%rsp)
movl $0xa, %edi
callq 0x3050
leaq 0x574da(%rip), %rax     # 0x5e630
cmpl $0x0, (%rax)
jle 0x7443
leaq 0xdef8(%rip), %rbx      # 0x1505e
leaq 0xdefd(%rip), %r15      # 0x1506a
xorl %r12d, %r12d
movq 0x8(%rsp), %rbp
movq 0x20(%rsp), %r14
movslq (%rbp), %rax
leaq 0x8(,%rax,8), %rdi
callq 0x3340
movq %rax, 0x38(%rsp)
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
leaq 0xfdd7(%rip), %rcx      # 0x16f7c
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbp, %rdi
movq %r15, %rsi
callq 0x33a0
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x75a7
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
leaq 0xfdab(%rip), %rcx      # 0x16f83
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbp, %rdi
movq %r15, %rsi
callq 0x33a0
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x75a7
movq 0x10(%rsp), %rax
cmpb $0x1, 0x449(%rax)
jne 0x7240
movq %rbp, %rdi
leaq 0xe2b1(%rip), %rsi      # 0x154c4
movq %r14, %rdx
leaq 0xfd5f(%rip), %rcx      # 0x16f7c
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbp, %rdi
movq %r15, %rsi
callq 0x33a0
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x75a7
movl $0x4ccccc, %edi         # imm = 0x4CCCCC
callq 0x3340
movq %rax, 0x40(%rsp)
movq 0x38(%rsp), %rax
movq $0x0, (%rax)
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x73b9
xorl %r15d, %r15d
movl %r12d, 0x2c(%rsp)
movq %rbp, %rdi
leaq 0xead3(%rip), %rsi      # 0x15d4e
movq %r14, %rdx
movl %r15d, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbp, %rdi
leaq 0xddd2(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x75a7
movq %rax, %rbx
movq %rbp, %rdi
leaq 0x178(%rsp), %rsi
callq 0x32e0
movq 0x1a8(%rsp), %r14
movq %r14, %rax
shrq $0x2, %rax
movslq %eax, %r13
movq 0x38(%rsp), %rcx
movq (%rcx,%r15,8), %rax
addq %r13, %rax
movq %rax, 0x8(%rcx,%r15,8)
movl $0x1, %edx
movq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x30c0
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rsi
movq 0x20(%rsp), %r14
movq 0x58(%rsp), %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq %rbp, %rdi
callq 0x3070
movq 0x10(%rsp), %rax
cmpb $0x1, 0x449(%rax)
jne 0x73a0
movq %rbp, %rdi
leaq 0xea27(%rip), %rsi      # 0x15d5a
movq %r14, %rdx
movl %r15d, %ecx
movl 0x2c(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %rbp, %rdi
leaq 0xdd18(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x75a7
movq %rax, %rbx
addq %r13, %r13
movl $0x1, %edx
movq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rcx
callq 0x30c0
movl $0x1, %edx
movq %r12, %rdi
movq %r13, %rsi
movq 0x50(%rsp), %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq %rbp, %rdi
callq 0x3070
incq %r15
movq 0x8(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r15
movl 0x2c(%rsp), %r12d
jl 0x7271
movq 0x58(%rsp), %rdi
callq 0x3100
movq 0x10(%rsp), %rax
cmpb $0x0, 0x449(%rax)
je 0x73db
movq 0x50(%rsp), %rdi
callq 0x3100
movq 0x40(%rsp), %rdi
callq 0x3040
movq 0x8(%rsp), %rbp
movslq (%rbp), %rdx
incq %rdx
movl $0x8, %esi
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq 0x68(%rsp), %r15
movq %r15, %rcx
callq 0x3450
movq %r15, %rdi
callq 0x3100
movq %rbx, %rdi
callq 0x3040
incl %r12d
leaq 0x5720b(%rip), %rax     # 0x5e630
cmpl (%rax), %r12d
movq 0x30(%rsp), %r13
leaq 0xdc2a(%rip), %rbx      # 0x1505e
leaq 0xdc2f(%rip), %r15      # 0x1506a
jl 0x717a
jmp 0x7452
movq 0x30(%rsp), %r13
movq 0x8(%rsp), %rbp
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r12
cmpl $0x0, 0x28(%rsp)
movq 0x60(%rsp), %r15
jle 0x7476
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
callq 0x3040
incq %rbx
cmpq %rbx, %r15
jne 0x7465
movq %r12, %rdi
callq 0x3040
leaq 0x5718b(%rip), %rax     # 0x5e610
movq (%rax), %rax
movl (%rax), %ecx
movl %ecx, 0x70(%rsp)
movq 0x10(%rsp), %rcx
movb 0x449(%rcx), %cl
movb %cl, 0x74(%rsp)
movl 0x4(%rax), %ecx
addl %ecx, %ecx
movl %ecx, 0x78(%rsp)
movl 0xc(%rax), %eax
addl %eax, %eax
movl %eax, 0x7c(%rsp)
leaq 0x5717a(%rip), %rax     # 0x5e630
movl (%rax), %eax
movl %eax, 0x80(%rsp)
movl (%rbp), %eax
movl %eax, 0x84(%rsp)
movq (%rsp), %rax
movq %rax, 0x88(%rsp)
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %rbx
leaq 0xdeaa(%rip), %rsi      # 0x15393
leaq 0xe270(%rip), %rcx      # 0x15760
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xdb66(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x75c1
movq %rax, %r14
leaq 0x70(%rsp), %r15
movl $0x20, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rax, %rcx
callq 0x3450
movslq 0x14(%r15), %r15
movl $0x4, %esi
movq 0x48(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3450
movq %r12, %rdi
callq 0x3040
testq %r15, %r15
jle 0x758a
xorl %r12d, %r12d
movq 0x8(%rbp), %rax
movslq (%r13,%r12,4), %rcx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x1, %edx
movq %r14, %rcx
callq 0x3450
incq %r12
cmpq %r12, %r15
jne 0x755e
movq %r14, %rdi
callq 0x3100
movq %rbx, %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0xedc1(%rip), %rsi      # 0x16376
leaq 0x70(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xeda7(%rip), %rsi      # 0x16376
movq %rbx, %rdx
jmp 0x75ba