// File: /workspace/github_c_makefile_star2_O1/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 0xff54
movq %rax, %r13
leaq 0xd387(%rip), %rdi      # 0x1d688
leaq 0x5458(%rip), %rsi      # 0x15760
callq 0x6bcc
testq %rax, %rax
je 0x10903
movq %rax, %r14
leaq 0x4d47(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x10926
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 0x10939
movq %r14, %rdi
callq 0x3040
leaq 0xd611(%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 0x10754
leaq 0xd2ae(%rip), %rax      # 0x1d688
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movq %r12, 0x60(%rsp)
leaq 0x90(%rsp), %r14
movq %r14, %rdi
leaq 0x4c62(%rip), %rsi      # 0x1505e
movq %rax, %rdx
leaq 0x6b76(%rip), %rcx      # 0x16f7c
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 0x108e6
movq 0x1c8(%rsp), %r13
movq %r13, %rdi
callq 0x3340
movq %rax, %rbx
movq %r14, %rdi
leaq 0x4c1e(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x108e6
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 0x4bda(%rip), %rsi      # 0x1505e
leaq 0xd1fd(%rip), %rdx      # 0x1d688
leaq 0x6af1(%rip), %rcx      # 0x16f83
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x198(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
jne 0x108e6
movq 0x1c8(%rsp), %r13
movq %r13, %rdi
callq 0x3340
movq %rax, %rbx
movq %r14, %rdi
leaq 0x4b94(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x108e6
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 0x4b50(%rip), %rsi      # 0x1505e
leaq 0xd473(%rip), %rdx      # 0x1d988
leaq 0x6a60(%rip), %rcx      # 0x16f7c
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x4b38(%rip), %rsi      # 0x1506a
callq 0x33a0
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x108e6
movq 0x18(%rsp), %rax
movq $0x0, (%rax)
testl %r12d, %r12d
movq 0x28(%rsp), %rax
jle 0x106ac
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 0x10699
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 0x105ed
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 0x105e5
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 0x105cc
incq %rsi
cmpq %rdx, %rsi
jne 0x105ba
movslq %ebp, %r12
xorl %ebx, %ebx
xorl %r13d, %r13d
movq (%r15,%r13,8), %r15
testq %r15, %r15
je 0x10651
xorl %ebp, %ebp
movq %r10, %rax
movl %ebp, %ecx
shrq %cl, %rax
testq %r15, %rax
je 0x10648
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 0x10600
incq %r13
addq $0x40, %rbx
cmpq $0x400000, %r13         # imm = 0x400000
movq 0x58(%rsp), %r15
jne 0x105f5
leal 0x1(%r12), %ebp
movq 0x18(%rsp), %rax
movq %r14, 0x8(%rax,%r12,8)
leaq 0x6b74(%rip), %rdi      # 0x171f0
movq 0x50(%rsp), %rbx
movl %ebx, %esi
movq 0x60(%rsp), %r12
movl %r12d, %edx
xorl %eax, %eax
callq 0x3170
movq 0x68(%rsp), %r13
jmp 0x1069e
movq 0x50(%rsp), %rbx
incq %rbx
cmpq %r12, %rbx
jne 0x1056f
jmp 0x106ae
xorl %ebp, %ebp
movl $0xa, %edi
callq 0x3050
movq 0x20(%rsp), %rdi
callq 0x3100
leaq 0x90(%rsp), %r14
movq %r14, %rdi
leaq 0x498a(%rip), %rsi      # 0x1505e
leaq 0xd2ad(%rip), %rdx      # 0x1d988
leaq 0x68a1(%rip), %rcx      # 0x16f83
movl 0xc(%rsp), %ebx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x4970(%rip), %rsi      # 0x1506a
callq 0x33a0
testq %rax, %rax
je 0x108e6
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 0xcf3c(%rip), %rax      # 0x1d688
jne 0x103ea
jmp 0x1075f
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movl %ebp, 0x84(%rsp)
movb $0x0, 0x74(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x4c14(%rip), %rsi      # 0x15393
leaq 0xd202(%rip), %rdx      # 0x1d988
leaq 0x4fd3(%rip), %rcx      # 0x15760
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3430
leaq 0x48c4(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x108e6
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
testl %r12d, %r12d
jle 0x10874
movq 0x28(%rsp), %rax
movq 0x8(%rax), %r14
shlq $0x3, %r12
leaq (%r12,%r12,2), %r15
leaq 0x69f6(%rip), %r12      # 0x17211
xorl %ebp, %ebp
xorl %ebx, %ebx
movl (%r14,%rbp), %edx
testl %edx, %edx
je 0x10857
movq 0x8(%r14,%rbp), %rcx
movslq %ebx, %rdi
shlq $0x8, %rdi
addq %r13, %rdi
testq %rcx, %rcx
je 0x10847
movq %r12, %rsi
xorl %eax, %eax
callq 0x3430
jmp 0x10855
leaq 0x7965(%rip), %rsi      # 0x181b3
xorl %eax, %eax
callq 0x3430
incl %ebx
movq 0x10(%r14,%rbp), %rdi
callq 0x3040
movq 0x8(%r14,%rbp), %rdi
callq 0x3040
addq $0x18, %rbp
cmpq %rbp, %r15
jne 0x1081f
movq 0x28(%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0x3040
movq %rbx, %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 0x6897(%rip), %rsi      # 0x1718b
leaq 0x90(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x4abc(%rip), %rsi      # 0x153cd
leaq 0x4e48(%rip), %rdx      # 0x15760
leaq 0xcd69(%rip), %rcx      # 0x1d688
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x6857(%rip), %rsi      # 0x1718b
movq %r14, %rdx
jmp 0x108fc
callq 0x3060
movl (%rax), %edi
leaq 0x685c(%rip), %rsi      # 0x171a3
movq %r14, %rdx
movl %r15d, %ecx
movq %rbx, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x3330