// File: /workspace/github_c_makefile_star2_O3/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 $0x288, %rsp            # imm = 0x288
movl %r8d, %r14d
movq %rcx, 0x8(%rsp)
movq %rdx, %rbp
movq %rsi, %r13
movq %rdi, 0x10(%rsp)
movslq %r8d, %rbx
leaq (,%rbx,8), %rdi
callq 0x3340
movq %rax, %r12
movl %r14d, 0x34(%rsp)
movl %r14d, %r15d
testl %ebx, %ebx
jle 0x71dd
leaq 0x57468(%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 0x71c9
movq %r15, 0x60(%rsp)
movslq (%r13), %rbx
movq %rbx, %rdi
shlq $0x2, %rdi
callq 0x3340
movq %rax, 0x48(%rsp)
movq 0x10(%rsp), %rcx
cmpb $0x0, 0x64c(%rcx)
je 0x726c
testl %ebx, %ebx
jle 0x74eb
movq %r12, 0x18(%rsp)
leaq 0x44b(%rcx), %rbx
movq $0x0, 0x20(%rsp)
xorl %r12d, %r12d
movq 0x8(%rsp), %r14
movq 0x8(%r13), %rax
movslq (%rbp,%r12,4), %rcx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %r15
leaq 0xeb23(%rip), %rdi      # 0x15d66
movq %r15, %rsi
xorl %eax, %eax
callq 0x3170
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12eaf
incq %r12
movslq (%r13), %rax
cmpq %rax, %r12
jl 0x722a
jmp 0x77ec
movq %r12, 0x18(%rsp)
testl %ebx, %ebx
movq %rbp, 0x40(%rsp)
movq %r13, 0x38(%rsp)
jle 0x74fe
leaq 0x44b(%rcx), %rax
movq %rax, (%rsp)
leaq 0x16d6b(%rip), %rbx     # 0x1e000
leaq 0x76(%rsp), %r12
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
movq 0x8(%rsp), %r14
movq 0x8(%r13), %rax
movslq (%rbp,%r15,4), %rdx
shlq $0x4, %rdx
movq 0x8(%rax,%rdx), %r13
xorl %ebp, %ebp
leaq 0x180(%rsp), %rdi
leaq 0xeab1(%rip), %rsi      # 0x15d7f
movq %r14, %rdx
movq %r15, 0x28(%rsp)
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
callq 0x3130
movq %rax, %r14
xorl %ecx, %ecx
movq (%rbx,%rcx,8), %r15
movq %r15, %rdi
callq 0x3130
movl %r14d, %ecx
subl %eax, %ecx
movslq %ecx, %rdi
addq %r13, %rdi
movq %r15, %rsi
callq 0x32b0
testb $0x1, %bpl
jne 0x731e
movl $0x1, %ecx
movb $0x1, %bpl
testl %eax, %eax
jne 0x72ed
testl %eax, %eax
movq %r13, %r14
leaq 0x80(%rsp), %rax
cmoveq %rax, %r14
leaq 0x16caa(%rip), %rax     # 0x1dfe0
movq (%rax), %rdx
movq %r12, %rdi
leaq 0xe089(%rip), %rsi      # 0x153cc
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
callq 0x3130
leaq (%rax,%r14), %r15
movq %r12, %rdi
callq 0x3130
subq %rax, %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x32b0
testl %eax, %eax
je 0x73cd
xorl %ebp, %ebp
cmpq $0x1, %rbp
je 0x73c4
leaq 0x16c61(%rip), %rax     # 0x1dfe0
movq 0x8(%rax,%rbp,8), %rdx
movq %r12, %rdi
leaq 0xe03e(%rip), %rsi      # 0x153cc
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
callq 0x3130
leaq (%rax,%r14), %r15
movq %r12, %rdi
callq 0x3130
subq %rax, %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x32b0
incq %rbp
testl %eax, %eax
jne 0x7372
cmpq $0x1, %rbp
je 0x73cd
movq (%rsp), %rax
cmpb $0x0, (%rax)
je 0x743d
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movq 0x10(%rsp), %rax
cmpb $0x1, 0x449(%rax)
movq 0x40(%rsp), %rbp
movq 0x8(%rsp), %r14
jne 0x7412
movq %r13, %rdi
movq (%rsp), %rdx
movl 0x34(%rsp), %ecx
callq 0x1452f
leaq 0x180(%rsp), %rdi
movq %rax, %rsi
callq 0x13ed2
jmp 0x74a6
movl 0x424(%rax), %r8d
movl 0x428(%rax), %ecx
movq %r13, %rdi
movq (%rsp), %rdx
callq 0x1377f
leaq 0x180(%rsp), %rdi
movq %rax, %rsi
callq 0x1424a
jmp 0x74a6
movq 0x10(%rsp), %r15
cmpb $0x1, 0x449(%r15)
movq 0x40(%rsp), %rbp
movq 0x8(%rsp), %r14
jne 0x746a
movb $0x0, 0x449(%r15)
leaq 0xf14c(%rip), %rdi      # 0x165b1
callq 0x30a0
movq 0x18(%rsp), %rax
movq (%rax), %rsi
cmpb $0x1, 0x44a(%r15)
jne 0x748a
movq %r13, %rdi
movq (%rsp), %rdx
callq 0x1496e
jmp 0x7496
movq %r13, %rdi
movq (%rsp), %rdx
callq 0x13427
leaq 0x180(%rsp), %rdi
movq %rax, %rsi
callq 0x143c2
movq 0x48(%rsp), %rcx
movq 0x28(%rsp), %r15
movl %eax, (%rcx,%r15,4)
movl %eax, %eax
addq %rax, 0x20(%rsp)
incq %r15
movq 0x38(%rsp), %rax
movl (%rax), %edx
leaq 0xe8bc(%rip), %rdi      # 0x15d88
movl %r15d, %esi
movq %r13, %rcx
movq %rax, %r13
xorl %eax, %eax
callq 0x3170
movslq (%r13), %rax
cmpq %rax, %r15
jl 0x72ab
jmp 0x750c
movq $0x0, 0x20(%rsp)
movq 0x8(%rsp), %r14
jmp 0x77f1
movq $0x0, 0x20(%rsp)
movq 0x8(%rsp), %r14
movl $0xa, %edi
callq 0x3050
leaq 0x57113(%rip), %rax     # 0x5e630
cmpl $0x0, (%rax)
jle 0x77ec
leaq 0xdb31(%rip), %rbx      # 0x1505e
leaq 0x80(%rsp), %r12
xorl %ebp, %ebp
movslq (%r13), %rax
leaq 0x8(,%rax,8), %rdi
callq 0x3340
movq %rax, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
leaq 0xfa70(%rip), %rcx      # 0x16fcc
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
leaq 0xdafa(%rip), %r15      # 0x1506a
movq %r15, %rsi
callq 0x33a0
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x7952
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
leaq 0xfa3d(%rip), %rcx      # 0x16fd3
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
movq %r15, %rsi
callq 0x33a0
testq %rax, %rax
je 0x7952
movq %rax, 0x68(%rsp)
movq 0x10(%rsp), %rax
cmpb $0x1, 0x449(%rax)
jne 0x75fe
movq %r12, %rdi
leaq 0xdf43(%rip), %rsi      # 0x15514
movq %r14, %rdx
leaq 0xf9f1(%rip), %rcx      # 0x16fcc
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
movq %r15, %rsi
callq 0x33a0
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x7952
movl %ebp, 0x28(%rsp)
movl $0x4ccccc, %edi         # imm = 0x4CCCCC
callq 0x3340
movq %rax, %r13
movq (%rsp), %rax
movq $0x0, (%rax)
movq 0x38(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x7762
xorl %ebp, %ebp
movq %r12, %rdi
leaq 0xe76a(%rip), %rsi      # 0x15d9e
movq %r14, %rdx
movl %ebp, %ecx
movl 0x28(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
leaq 0xda18(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x7952
movq %rax, %rbx
movq %r12, %rdi
leaq 0x180(%rsp), %rsi
callq 0x32e0
movq 0x1b0(%rsp), %r14
movq %r14, %rax
shrq $0x2, %rax
movslq %eax, %r15
movq (%rsp), %rcx
movq (%rcx,%rbp,8), %rax
addq %r15, %rax
movq %rax, 0x8(%rcx,%rbp,8)
movl $0x1, %edx
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x30c0
movl $0x1, %edx
movq %r13, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %r14
movq 0x58(%rsp), %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq %r12, %rdi
callq 0x3070
movq 0x10(%rsp), %rax
cmpb $0x1, 0x449(%rax)
jne 0x774e
movq %r12, %rdi
leaq 0xe6c3(%rip), %rsi      # 0x15daa
movq %r14, %rdx
movl %ebp, %ecx
movl 0x28(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
leaq 0xd965(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x7952
movq %rax, %rbx
addq %r15, %r15
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %rcx
callq 0x30c0
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rsi
movq 0x50(%rsp), %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq %r12, %rdi
callq 0x3070
incq %rbp
movq 0x38(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rbp
jl 0x762a
movq 0x58(%rsp), %rdi
callq 0x3100
movq 0x10(%rsp), %rax
cmpb $0x0, 0x449(%rax)
je 0x7784
movq 0x50(%rsp), %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3040
movq 0x38(%rsp), %r13
movslq (%r13), %rdx
incq %rdx
movl $0x8, %esi
movq (%rsp), %rbx
movq %rbx, %rdi
movq 0x68(%rsp), %r15
movq %r15, %rcx
callq 0x3450
movq %r15, %rdi
callq 0x3100
movq %rbx, %rdi
callq 0x3040
movl 0x28(%rsp), %ebp
incl %ebp
leaq 0x56e62(%rip), %rax     # 0x5e630
cmpl (%rax), %ebp
movq 0x40(%rsp), %rax
leaq 0xd882(%rip), %rbx      # 0x1505e
jl 0x7537
movq 0x18(%rsp), %r12
movq %rax, %rbp
jmp 0x77f1
movq 0x18(%rsp), %r12
cmpl $0x0, 0x34(%rsp)
movq 0x60(%rsp), %r15
jle 0x7810
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
callq 0x3040
incq %rbx
cmpq %rbx, %r15
jne 0x77ff
movq %r12, %rdi
callq 0x3040
leaq 0x56df1(%rip), %rax     # 0x5e610
movq (%rax), %rax
movl (%rax), %ecx
movl %ecx, 0x80(%rsp)
movq 0x10(%rsp), %rcx
movb 0x449(%rcx), %cl
movb %cl, 0x84(%rsp)
movl 0x4(%rax), %ecx
addl %ecx, %ecx
movl %ecx, 0x88(%rsp)
movl 0xc(%rax), %eax
addl %eax, %eax
movl %eax, 0x8c(%rsp)
leaq 0x56dd4(%rip), %rax     # 0x5e630
movl (%rax), %eax
movl %eax, 0x90(%rsp)
movl (%r13), %eax
movl %eax, 0x94(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x98(%rsp)
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %rbx
leaq 0xdb52(%rip), %rsi      # 0x153e3
leaq 0xdf18(%rip), %rcx      # 0x157b0
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xd7be(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x796f
movq %rax, %r14
leaq 0x80(%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 0x7935
xorl %r12d, %r12d
movq 0x8(%r13), %rax
movslq (%rbp,%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 0x7909
movq %r14, %rdi
callq 0x3100
movq %rbx, %rax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0xea66(%rip), %rsi      # 0x163c6
leaq 0x80(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xea49(%rip), %rsi      # 0x163c6
movq %rbx, %rdx
jmp 0x7968