// File: /workspace/github_c_makefile_star2_O2/yhg926[P]public_kssd/command_set.c
// Function: combin_subset_pans
int combin_subset_pans(char* taxfile){
 compan_t *subset = organize_taxf(taxfile);
  const char* co_dstat_fpath = NULL;
 co_dstat_fpath = test_get_fullpath(set_opt.insketchpath,co_dstat);
  if(co_dstat_fpath == NULL ) err(errno,"cannot find %s under %s ",co_dstat,set_opt.insketchpath);
 FILE *tmpfh;
 if( ( tmpfh = fopen(co_dstat_fpath,"rb")) == NULL ) err(errno,"combin_subset_pans():%s",co_dstat_fpath);
 co_dstat_t co_dstat_readin;
 fread( &co_dstat_readin, sizeof(co_dstat_t),1,tmpfh );
 fclose(tmpfh);
 if(co_dstat_readin.infile_num != subset->gn)
  err(errno,"combin_subset_pans():%s's genome number %d not matches %s's genome number %d",co_dstat_fpath,co_dstat_readin.infile_num,taxfile,subset->gn);
 free(co_dstat_fpath);
 mkdir(set_opt.outdir,0777);
 char tmppath[PATHLEN]; struct stat s; int outfn = 0; llong all_ctx_ct = 0;
 ctx_obj_ct_t *ctx_ct_list = calloc(subset->taxn,sizeof(ctx_obj_ct_t));
 size_t comp_sz = (1LLU << 4*COMPONENT_SZ);
  llong* dict = (llong*)malloc(comp_sz/8);
  size_t *outcombcoidx = malloc(sizeof(size_t)* (subset->taxn+1));
  for(int c=0; c < co_dstat_readin.comp_num; c++){
  sprintf(tmppath,"%s/%s.%d",set_opt.insketchpath,skch_prefix,c);
  if(stat(tmppath, &s) != 0) err(errno,"combin_subset_pans():%s",tmppath);
  unsigned int *tmpcombco = malloc(s.st_size);
  if((tmpfh = fopen(tmppath,"rb")) == NULL) err(errno,"combin_subset_pans():%s",tmppath);
  fread(tmpcombco,s.st_size, 1,tmpfh);
  fclose(tmpfh);
  sprintf(tmppath,"%s/%s.%d",set_opt.insketchpath,idx_prefix,c);
  if(stat(tmppath, &s) != 0) err(errno,"combin_subset_pans():%s",tmppath);
  size_t *tmpcombcoidx = malloc(s.st_size);
  if((tmpfh = fopen(tmppath,"rb")) == NULL) err(errno,"combin_subset_pans():%s",tmppath);
  fread(tmpcombcoidx,s.st_size, 1,tmpfh);
  fclose(tmpfh);
  sprintf(tmppath,"%s/%s.%d",set_opt.outdir,skch_prefix,c);
  if((tmpfh = fopen(tmppath,"wb")) == NULL) err(errno,"combin_subset_pans():%s",tmppath);
  outfn = 0;
  size_t offset = 0;
  outcombcoidx[0] = 0;
  for(int t = 0; t < subset->taxn; t++){
   if(subset->tax[t].taxid == 0) continue;
    memset(dict,0,comp_sz/8);
    for(int n = 1; n <= subset->tax[t].gids[0];n++){
     int gid = subset->tax[t].gids[n] ;
     for(size_t i= tmpcombcoidx[gid]; i < tmpcombcoidx[gid+1];i++){
      dict[tmpcombco[i]/64] |= ( 0x8000000000000000LLU >> (tmpcombco[i] % 64) ) ;
     }
    }
    for(unsigned int n=0;n< comp_sz/64; n++){
        if(dict[n]){
          for(int b=0; b< 64; b++){
            if ((0x8000000000000000LLU >> b) & dict[n]){
              unsigned int var = 64*n + b ;
              fwrite(&var,sizeof(unsigned int),1,tmpfh);
        offset++; all_ctx_ct++; ctx_ct_list[outfn]++;
            }
          }
        }
    }
    outfn++;
    outcombcoidx[outfn]= offset;
    printf("%d/%d species pangenome grouped\r",t,subset->taxn);
  }
  printf("\n");
  fclose(tmpfh);
  sprintf(tmppath,"%s/%s.%d",set_opt.outdir,idx_prefix,c);
  tmpfh = fopen(tmppath,"wb");
  if(tmpfh == NULL) err(errno,"combin_subset_pans():%s",tmppath);
  fwrite(outcombcoidx,sizeof(size_t),outfn+1,tmpfh);
  fclose(tmpfh);
  free(tmpcombco);
   free(tmpcombcoidx);
 }
 co_dstat_readin.infile_num = outfn;
 co_dstat_readin.koc = 0;
 co_dstat_readin.all_ctx_ct = all_ctx_ct;
 sprintf(tmppath,"%s/%s",set_opt.outdir,co_dstat);
 if((tmpfh = fopen(tmppath,"wb")) == NULL) err(errno,"combin_subset_pans():%s",tmppath);
 fwrite(&co_dstat_readin,sizeof(co_dstat_t),1,tmpfh);
 fwrite(ctx_ct_list,sizeof(ctx_obj_ct_t),outfn,tmpfh);
 char (*tmpfname)[PATHLEN] = malloc(outfn * PATHLEN);
 int idx = 0;
  for(int t=0;t<subset->taxn;t++){
  if(subset->tax[t].taxid != 0) {
   if(subset->tax[t].taxname != NULL)
    sprintf(tmpfname[idx],"%d_%s",subset->tax[t].taxid,subset->tax[t].taxname);
   else sprintf(tmpfname[idx],"%d",subset->tax[t].taxid);
   idx++;
  }
  free(subset->tax[t].gids);
    free(subset->tax[t].taxname);
  }
  free(subset->tax);
  free(subset);
 fwrite(tmpfname,PATHLEN,outfn,tmpfh);
 fclose(tmpfh);
 free(tmpfname);
 free(ctx_ct_list);
 free(dict);
 free(outcombcoidx);
 return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %r14
callq 0xf4a6
movq %rax, %r13
leaq 0xce86(%rip), %rdi      # 0x1c688
leaq 0x4f57(%rip), %rsi      # 0x14760
callq 0x68a5
testq %rax, %rax
je 0xfddc
movq %rax, %rbx
leaq 0x4846(%rip), %rsi      # 0x14067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0xfdff
movq %rax, %r15
leaq 0x70(%rsp), %r12
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %rax, %rcx
callq 0x30c0
movq %r15, %rdi
callq 0x3100
movl 0x14(%r12), %r15d
movl 0x4(%r13), %ebp
cmpl %ebp, %r15d
jne 0xfe12
movq %rbx, %rdi
callq 0x3040
leaq 0xd114(%rip), %rdi      # 0x1c988
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movl (%r13), %ebp
movslq %ebp, %rbx
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x32a0
movq %rax, 0x30(%rsp)
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x3340
movq %rax, 0x28(%rsp)
leaq 0x8(,%rbx,8), %rdi
callq 0x3340
xorl %edx, %edx
testl %ebx, %ebx
movl $0x0, %ecx
movl %ebp, 0x40(%rsp)
cmovgl %ebp, %ecx
movq %rcx, 0x58(%rsp)
movl 0x80(%rsp), %ecx
testl %ecx, %ecx
cmovlel %edx, %ecx
movl %ecx, 0x3c(%rsp)
movq %rax, 0x10(%rsp)
xorl %r8d, %r8d
movq $0x0, 0x18(%rsp)
xorl %r12d, %r12d
movq %r13, %rbp
movq %r13, 0x48(%rsp)
cmpl 0x3c(%rsp), %r8d
je 0xfc46
leaq 0x90(%rsp), %r14
movq %r14, %rdi
leaq 0x474f(%rip), %rsi      # 0x1405e
leaq 0xcd72(%rip), %rdx      # 0x1c688
leaq 0x665f(%rip), %rcx      # 0x15f7c
movl %r8d, 0xc(%rsp)
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x198(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
jne 0xfdbf
movq 0x1c8(%rsp), %r12
movq %r12, %rdi
callq 0x3340
movq %rax, %rbx
movq %r14, %rdi
leaq 0x4709(%rip), %rsi      # 0x14067
callq 0x33a0
testq %rax, %rax
je 0xfdbf
movq %rax, %r13
movq %rbx, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x30c0
movq %r13, %rdi
callq 0x3100
movq %r14, %rdi
leaq 0x46cc(%rip), %rsi      # 0x1405e
leaq 0xccef(%rip), %rdx      # 0x1c688
leaq 0x65e3(%rip), %rcx      # 0x15f83
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x198(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
jne 0xfdbf
movq 0x1c8(%rsp), %r12
movq %r12, %rdi
callq 0x3340
movq %rax, %r15
movq %r14, %rdi
leaq 0x4686(%rip), %rsi      # 0x14067
callq 0x33a0
testq %rax, %rax
je 0xfdbf
movq %rax, %r13
movq %r15, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x30c0
movq %r13, %rdi
callq 0x3100
movq %r14, %rdi
leaq 0x4649(%rip), %rsi      # 0x1405e
leaq 0xcf6c(%rip), %rdx      # 0x1c988
leaq 0x6559(%rip), %rcx      # 0x15f7c
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x4631(%rip), %rsi      # 0x1406a
callq 0x33a0
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0xfdbf
movq 0x10(%rsp), %rax
andq $0x0, (%rax)
xorl %eax, %eax
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r15, 0x50(%rsp)
cmpq 0x58(%rsp), %rax
je 0xfbad
movq 0x8(%rbp), %r14
imulq $0x18, %rax, %r15
cmpl $0x0, (%r14,%r15)
je 0xfba5
movq %rax, 0x60(%rsp)
movl $0x2000000, %edx        # imm = 0x2000000
movq 0x28(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x3210
movq 0x10(%r14,%r15), %rax
movl (%rax), %edx
testl %edx, %edx
movl $0x0, %ecx
cmovlel %ecx, %edx
incl %edx
pushq $0x1
popq %rsi
movabsq $-0x8000000000000000, %r10 # imm = 0x8000000000000000
movq 0x50(%rsp), %r11
cmpq %rdx, %rsi
je 0xfaf0
movslq (%rax,%rsi,4), %rcx
movq (%r11,%rcx,8), %rdi
movq 0x8(%r11,%rcx,8), %r8
cmpq %r8, %rdi
jae 0xfaeb
movl (%rbx,%rdi,4), %ecx
movq %r10, %r9
shrq %cl, %r9
shrl $0x6, %ecx
orq %r9, (%rbp,%rcx,8)
incq %rdi
jmp 0xfad0
incq %rsi
jmp 0xfabe
movslq %r12d, %r15
xorl %ebp, %ebp
xorl %ecx, %ecx
cmpq $0x400000, %rcx         # imm = 0x400000
je 0xfb75
movq 0x28(%rsp), %rax
movq (%rax,%rcx,8), %r14
testq %r14, %r14
je 0xfb6c
movq %rcx, 0x68(%rsp)
xorl %r12d, %r12d
cmpq $0x40, %r12
je 0xfb67
movq %r10, %rax
movl %r12d, %ecx
shrq %cl, %rax
testq %r14, %rax
je 0xfb62
leal (%r12,%rbp), %eax
movl %eax, 0x44(%rsp)
leaq 0x44(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq 0x20(%rsp), %rcx
callq 0x3450
movabsq $-0x8000000000000000, %r10 # imm = 0x8000000000000000
incq %r13
incq 0x18(%rsp)
movq 0x30(%rsp), %rax
incl (%rax,%r15,4)
incq %r12
jmp 0xfb16
movq 0x68(%rsp), %rcx
incq %rcx
addq $0x40, %rbp
jmp 0xfaf7
leal 0x1(%r15), %r12d
movq 0x10(%rsp), %rax
movq %r13, 0x8(%rax,%r15,8)
leaq 0x6666(%rip), %rdi      # 0x161f0
movq 0x60(%rsp), %r14
movl %r14d, %esi
movl 0x40(%rsp), %edx
xorl %eax, %eax
callq 0x3170
movq %r14, %rax
movq 0x48(%rsp), %rbp
incq %rax
jmp 0xfa62
pushq $0xa
popq %rdi
callq 0x3050
movq 0x20(%rsp), %rdi
callq 0x3100
leaq 0x90(%rsp), %r14
movq %r14, %rdi
leaq 0x448d(%rip), %rsi      # 0x1405e
leaq 0xcdb0(%rip), %rdx      # 0x1c988
leaq 0x63a4(%rip), %rcx      # 0x15f83
movl 0xc(%rsp), %r15d
movl %r15d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x4472(%rip), %rsi      # 0x1406a
callq 0x33a0
testq %rax, %rax
je 0xfdbf
movq %rax, %r13
leal 0x1(%r12), %eax
movslq %eax, %rdx
movq 0x10(%rsp), %rdi
pushq $0x8
popq %rsi
movq %r13, %rcx
callq 0x3450
movq %r13, %rdi
callq 0x3100
movq %rbx, %rdi
callq 0x3040
movq 0x50(%rsp), %rdi
callq 0x3040
incl %r15d
movl %r15d, %r8d
jmp 0xf8f2
movl %r12d, 0x84(%rsp)
movb $0x0, 0x74(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x472c(%rip), %rsi      # 0x14393
leaq 0xcd1a(%rip), %rdx      # 0x1c988
leaq 0x4aeb(%rip), %rcx      # 0x14760
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3430
leaq 0x43dc(%rip), %rsi      # 0x1406a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0xfdbf
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x3450
movslq %r12d, %rdx
pushq $0x4
popq %rsi
movq 0x30(%rsp), %rdi
movq %rdx, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %rbx, %rcx
callq 0x3450
shll $0x8, %r12d
movslq %r12d, %rdi
callq 0x3340
movq %rax, %r13
movq 0x8(%rbp), %rbp
imulq $0x18, 0x58(%rsp), %r14
leaq 0x651f(%rip), %rbx      # 0x16211
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq %r15, %r14
je 0xfd51
movl (%rbp,%r15), %edx
testl %edx, %edx
je 0xfd37
movq 0x8(%rbp,%r15), %rcx
movslq %r12d, %rdi
shlq $0x8, %rdi
addq %r13, %rdi
testq %rcx, %rcx
je 0xfd26
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3430
jmp 0xfd34
leaq 0x7466(%rip), %rsi      # 0x17193
xorl %eax, %eax
callq 0x3430
incl %r12d
movq 0x10(%rbp,%r15), %rdi
callq 0x3040
movq 0x8(%rbp,%r15), %rdi
callq 0x3040
addq $0x18, %r15
jmp 0xfcf8
movq %rbp, %rdi
callq 0x3040
movq 0x48(%rsp), %rdi
callq 0x3040
movl $0x100, %esi            # imm = 0x100
movq %r13, %rdi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rbx
movq %rbx, %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3040
movq 0x30(%rsp), %rdi
callq 0x3040
movq 0x28(%rsp), %rdi
callq 0x3040
movq 0x10(%rsp), %rdi
callq 0x3040
xorl %eax, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x63be(%rip), %rsi      # 0x1618b
leaq 0x90(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x45e3(%rip), %rsi      # 0x143cd
leaq 0x496f(%rip), %rdx      # 0x14760
leaq 0xc890(%rip), %rcx      # 0x1c688
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x637e(%rip), %rsi      # 0x1618b
movq %rbx, %rdx
jmp 0xfdd5
callq 0x3060
movl (%rax), %edi
leaq 0x6383(%rip), %rsi      # 0x161a3
movq %rbx, %rdx
movl %r15d, %ecx
movq %r14, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x3330