// File: /workspace/github_c_makefile_star2_O3/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, %rbx
callq 0x102ac
movq %rax, %r13
leaq 0xd06e(%rip), %rdi      # 0x1d688
leaq 0x518f(%rip), %rsi      # 0x157b0
callq 0x6d79
testq %rax, %rax
je 0x10c1a
movq %rax, %r14
leaq 0x4a2e(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x10c3d
movq %rax, %r15
leaq 0x70(%rsp), %r12
movl $0x20, %esi
movl $0x1, %edx
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 0x10c50
movq %r14, %rdi
callq 0x3040
leaq 0xd2f8(%rip), %rdi      # 0x1d988
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
movq %r13, 0x28(%rsp)
movslq (%r13), %r12
movl $0x4, %esi
movq %r12, %rdi
callq 0x32a0
movq %rax, 0x30(%rsp)
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x3340
movq %rax, %r15
leaq 0x8(,%r12,8), %rdi
callq 0x3340
movq %rax, 0x18(%rsp)
movl 0x80(%rsp), %eax
movl %eax, 0x38(%rsp)
testl %eax, %eax
movq %r15, 0x58(%rsp)
jle 0x10a6d
leaq 0xcf95(%rip), %rax      # 0x1d688
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movq %r12, 0x60(%rsp)
leaq 0x90(%rsp), %r14
movq %r14, %rdi
leaq 0x4949(%rip), %rsi      # 0x1505e
movq %rax, %rdx
leaq 0x68ad(%rip), %rcx      # 0x16fcc
movl %ebx, 0xc(%rsp)
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x198(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
jne 0x10bfd
movq 0x1c8(%rsp), %r13
movq %r13, %rdi
callq 0x3340
movq %rax, %rbx
movq %r14, %rdi
leaq 0x4905(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x10bfd
movq %rax, %rbp
movl $0x1, %edx
movq %rbx, 0x48(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rcx
callq 0x30c0
movq %rbp, %rdi
callq 0x3100
movq %r14, %rdi
leaq 0x48c1(%rip), %rsi      # 0x1505e
leaq 0xcee4(%rip), %rdx      # 0x1d688
leaq 0x6828(%rip), %rcx      # 0x16fd3
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x198(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
jne 0x10bfd
movq 0x1c8(%rsp), %r13
movq %r13, %rdi
callq 0x3340
movq %rax, %rbx
movq %r14, %rdi
leaq 0x487b(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x10bfd
movq %rax, %rbp
movl $0x1, %edx
movq %rbx, 0x40(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rcx
callq 0x30c0
movq %rbp, %rdi
callq 0x3100
movq %r14, %rdi
leaq 0x4837(%rip), %rsi      # 0x1505e
leaq 0xd15a(%rip), %rdx      # 0x1d988
leaq 0x6797(%rip), %rcx      # 0x16fcc
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x481f(%rip), %rsi      # 0x1506a
callq 0x33a0
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x10bfd
movq 0x18(%rsp), %rax
movq $0x0, (%rax)
testl %r12d, %r12d
movq 0x28(%rsp), %rax
jle 0x109c5
movq 0x8(%rax), %r13
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %ebp, %ebp
movq %r13, 0x68(%rsp)
movq %rbx, 0x50(%rsp)
leaq (%rbx,%rbx,2), %rbx
cmpl $0x0, (%r13,%rbx,8)
je 0x109b2
movl $0x2000000, %edx        # imm = 0x2000000
movq %r15, %rdi
xorl %esi, %esi
callq 0x3210
movq 0x10(%r13,%rbx,8), %rax
movl (%rax), %edx
testl %edx, %edx
movabsq $-0x8000000000000000, %r10 # imm = 0x8000000000000000
movq 0x48(%rsp), %r11
movq 0x40(%rsp), %rbx
jle 0x10906
incq %rdx
movl $0x1, %esi
movslq (%rax,%rsi,4), %rcx
movq (%rbx,%rcx,8), %rdi
movq 0x8(%rbx,%rcx,8), %r8
cmpq %r8, %rdi
jae 0x108fe
movl (%r11,%rdi,4), %ecx
movq %r10, %r9
shrq %cl, %r9
shrl $0x6, %ecx
orq %r9, (%r15,%rcx,8)
incq %rdi
cmpq %rdi, %r8
jne 0x108e5
incq %rsi
cmpq %rdx, %rsi
jne 0x108d3
movslq %ebp, %r12
xorl %ebx, %ebx
xorl %r13d, %r13d
movq (%r15,%r13,8), %r15
testq %r15, %r15
je 0x1096a
xorl %ebp, %ebp
movq %r10, %rax
movl %ebp, %ecx
shrq %cl, %rax
testq %r15, %rax
je 0x10961
leal (%rbx,%rbp), %eax
movl %eax, 0x3c(%rsp)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x3c(%rsp), %rdi
movq 0x20(%rsp), %rcx
callq 0x3450
movabsq $-0x8000000000000000, %r10 # imm = 0x8000000000000000
incq %r14
incq 0x10(%rsp)
movq 0x30(%rsp), %rax
incl (%rax,%r12,4)
incq %rbp
cmpq $0x40, %rbp
jne 0x10919
incq %r13
addq $0x40, %rbx
cmpq $0x400000, %r13         # imm = 0x400000
movq 0x58(%rsp), %r15
jne 0x1090e
leal 0x1(%r12), %ebp
movq 0x18(%rsp), %rax
movq %r14, 0x8(%rax,%r12,8)
leaq 0x68ab(%rip), %rdi      # 0x17240
movq 0x50(%rsp), %rbx
movl %ebx, %esi
movq 0x60(%rsp), %r12
movl %r12d, %edx
xorl %eax, %eax
callq 0x3170
movq 0x68(%rsp), %r13
jmp 0x109b7
movq 0x50(%rsp), %rbx
incq %rbx
cmpq %r12, %rbx
jne 0x10888
jmp 0x109c7
xorl %ebp, %ebp
movl $0xa, %edi
callq 0x3050
movq 0x20(%rsp), %rdi
callq 0x3100
leaq 0x90(%rsp), %r14
movq %r14, %rdi
leaq 0x4671(%rip), %rsi      # 0x1505e
leaq 0xcf94(%rip), %rdx      # 0x1d988
leaq 0x65d8(%rip), %rcx      # 0x16fd3
movl 0xc(%rsp), %ebx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x4657(%rip), %rsi      # 0x1506a
callq 0x33a0
testq %rax, %rax
je 0x10bfd
movq %rax, %r13
leal 0x1(%rbp), %eax
movslq %eax, %rdx
movl $0x8, %esi
movq 0x18(%rsp), %rdi
movq %r13, %rcx
callq 0x3450
movq %r13, %rdi
callq 0x3100
movq 0x48(%rsp), %rdi
callq 0x3040
movq 0x40(%rsp), %rdi
callq 0x3040
incl %ebx
cmpl 0x38(%rsp), %ebx
leaq 0xcc23(%rip), %rax      # 0x1d688
jne 0x10703
jmp 0x10a78
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movl %ebp, 0x84(%rsp)
movb $0x0, 0x74(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x494b(%rip), %rsi      # 0x153e3
leaq 0xcee9(%rip), %rdx      # 0x1d988
leaq 0x4d0a(%rip), %rcx      # 0x157b0
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3430
leaq 0x45ab(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x10bfd
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
movl $0x20, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x3450
movslq %ebp, %rdx
movl $0x4, %esi
movq 0x30(%rsp), %rdi
movq %rdx, 0x10(%rsp)
movq %rbx, 0x20(%rsp)
movq %rbx, %rcx
callq 0x3450
shll $0x8, %ebp
movslq %ebp, %rdi
callq 0x3340
movq %rax, %r13
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rbp
testl %r12d, %r12d
jle 0x10b8f
shlq $0x3, %r12
leaq (%r12,%r12,2), %r14
leaq 0x672d(%rip), %r12      # 0x17261
xorl %r15d, %r15d
xorl %ebx, %ebx
movl (%rbp,%r15), %edx
testl %edx, %edx
je 0x10b72
movq 0x8(%rbp,%r15), %rcx
movslq %ebx, %rdi
shlq $0x8, %rdi
addq %r13, %rdi
testq %rcx, %rcx
je 0x10b62
movq %r12, %rsi
xorl %eax, %eax
callq 0x3430
jmp 0x10b70
leaq 0x767a(%rip), %rsi      # 0x181e3
xorl %eax, %eax
callq 0x3430
incl %ebx
movq 0x10(%rbp,%r15), %rdi
callq 0x3040
movq 0x8(%rbp,%r15), %rdi
callq 0x3040
addq $0x18, %r15
cmpq %r15, %r14
jne 0x10b39
movq %rbp, %rdi
callq 0x3040
movq 0x28(%rsp), %rdi
callq 0x3040
movl $0x100, %esi            # imm = 0x100
movq %r13, %rdi
movq 0x10(%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 0x58(%rsp), %rdi
callq 0x3040
movq 0x18(%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 0x65d0(%rip), %rsi      # 0x171db
leaq 0x90(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x47f5(%rip), %rsi      # 0x1541d
leaq 0x4b81(%rip), %rdx      # 0x157b0
leaq 0xca52(%rip), %rcx      # 0x1d688
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x6590(%rip), %rsi      # 0x171db
movq %r14, %rdx
jmp 0x10c13
callq 0x3060
movl (%rax), %edi
leaq 0x6595(%rip), %rsi      # 0x171f3
movq %r14, %rdx
movl %r15d, %ecx
movq %rbx, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x3330