// File: /workspace/github_c_makefile_star2_O3/yhg926[P]public_kssd/command_set.c
// Function: sketch_union
int sketch_union()
{
 const char* co_dstat_fpath = NULL;
 char combco[20];
 char unionco[20];
 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 *co_stat_fp;
 if( ( co_stat_fp = fopen(co_dstat_fpath,"rb")) == NULL ) err(errno,"sketch_union():%s",co_dstat_fpath);
 co_dstat_t co_dstat_readin;
 fread( &co_dstat_readin, sizeof(co_dstat_t),1,co_stat_fp );
 if(co_dstat_readin.infile_num == 1){
  char inpbuff;
  printf("only 1 sketch, use %s as pan-sketch?(Y/N)\n",set_opt.insketchpath);
  scanf(" %c", &inpbuff);
  if ( (inpbuff == 'Y') || (inpbuff == 'y') ) {
   chdir(set_opt.insketchpath);
   for(int i=0 ; i < co_dstat_readin.comp_num;i++){
    sprintf(combco,"%s.%d",skch_prefix,i);
    sprintf(unionco,"%s.%d",pan_prefix,i);
    if(rename(combco,unionco) !=0) err(errno,"sketch_union()");
   }
   printf("the union directory: %s created successfully\n", set_opt.insketchpath) ;
   return 1;
  }
 }
 mkdir(set_opt.outdir,0777);
 char outpath[PATHLEN];
 sprintf(outpath,"%s/%s",set_opt.outdir,co_dstat);
 FILE *co_stat_fp2;
 if( ( co_stat_fp2 = fopen(outpath,"wb")) == NULL ) err(errno,"sketch_union():%s",outpath);
 fwrite( &co_dstat_readin,sizeof(co_dstat_t),1, co_stat_fp2 );
  fclose(co_stat_fp);
  fclose(co_stat_fp2);
 size_t comp_sz = (1LLU << 4*COMPONENT_SZ);
 llong* dict = (llong*)malloc(comp_sz/8);
 unsigned int tmpcbdco;
 for(int i=0; i < co_dstat_readin.comp_num; i++){
  memset(dict,0,comp_sz/8);
  sprintf(outpath,"%s/%s.%d",set_opt.insketchpath,skch_prefix,i);
  struct stat s;
   if(stat(outpath, &s) != 0) err(errno,"sketch_union():%s",outpath);
  size_t size = s.st_size / sizeof(unsigned int);
  if( ( co_stat_fp = fopen(outpath,"rb")) == NULL ) err(errno,"sketch_union():%s",outpath);
  for(size_t n=0; n< size ; n++){
   fread(&tmpcbdco,sizeof(unsigned int),1,co_stat_fp);
   dict[tmpcbdco/64] |= ( 0x8000000000000000LLU >> (tmpcbdco % 64) ) ;
  }
  fclose(co_stat_fp);
  sprintf(outpath,"%s/%s.%d",set_opt.outdir,pan_prefix,i);
  if( ( co_stat_fp = fopen(outpath,"wb")) == NULL ) err(errno,"sketch_union():%s",outpath);
  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,co_stat_fp);
     }
    }
   }
  }
  fclose(co_stat_fp);
 }
 free(dict);
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
leaq 0xe855(%rip), %rdi      # 0x1d688
leaq 0x6976(%rip), %rsi      # 0x157b0
callq 0x6d79
testq %rax, %rax
je 0xf1c0
movq %rax, %r14
leaq 0x6215(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0xf1e3
movq %rax, %rbx
leaq 0x20(%rsp), %r14
movl $0x20, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rax, %rcx
callq 0x30c0
cmpl $0x1, 0x14(%r14)
jne 0xef52
leaq 0x8162(%rip), %rdi      # 0x16ff4
leaq 0xe7ef(%rip), %rsi      # 0x1d688
xorl %eax, %eax
callq 0x3170
leaq 0x8178(%rip), %rdi      # 0x1701f
leaq 0xc(%rsp), %r14
movq %r14, %rsi
xorl %eax, %eax
callq 0x3400
movb (%r14), %al
andb $-0x21, %al
cmpb $0x59, %al
jne 0xef52
leaq 0xe7be(%rip), %rdi      # 0x1d688
callq 0x3140
movl 0x30(%rsp), %r14d
testl %r14d, %r14d
jle 0xef38
leaq 0x6181(%rip), %rbx      # 0x15061
leaq 0x40(%rsp), %r15
leaq 0x80f4(%rip), %r12      # 0x16fe0
leaq 0x140(%rsp), %r13
xorl %ebp, %ebp
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x80c9(%rip), %rdx      # 0x16fcc
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3430
movq %r15, %rdi
movq %r13, %rsi
callq 0x33e0
testl %eax, %eax
jne 0xf1ab
incl %ebp
cmpl %ebp, %r14d
jne 0xeef6
leaq 0x80e4(%rip), %rdi      # 0x17023
leaq 0xe742(%rip), %rsi      # 0x1d688
xorl %eax, %eax
callq 0x3170
jmp 0xf17a
leaq 0xea2f(%rip), %r14      # 0x1d988
movq %r14, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
leaq 0x6476(%rip), %rsi      # 0x153e3
leaq 0x683c(%rip), %rcx      # 0x157b0
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0x60dd(%rip), %rsi      # 0x1506a
movq %r15, %rdi
callq 0x33a0
testq %rax, %rax
je 0xf191
movq %rax, %r14
leaq 0x20(%rsp), %r15
movl $0x20, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rax, %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq %r14, %rdi
callq 0x3100
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x3340
movq %rax, %r12
movl 0x10(%r15), %eax
movl %eax, 0x10(%rsp)
testl %eax, %eax
jle 0xf172
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
leaq 0x6065(%rip), %r15      # 0x1505e
leaq 0x40(%rsp), %r13
xorl %ebx, %ebx
movq %r12, 0x18(%rsp)
movl $0x2000000, %edx        # imm = 0x2000000
movq %r12, %rdi
xorl %esi, %esi
callq 0x3210
movq %r13, %rdi
movq %r15, %rsi
leaq 0xe667(%rip), %rdx      # 0x1d688
leaq 0x7fa4(%rip), %rcx      # 0x16fcc
movl %ebx, 0x8(%rsp)
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
leaq 0x140(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
jne 0xf191
movq 0x170(%rsp), %rbx
movq %r13, %rdi
leaq 0x6007(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0xf191
movq %rax, %r14
cmpq $0x4, %rbx
leaq 0xc(%rsp), %r15
jb 0xf0ab
shrq $0x2, %rbx
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x30c0
movl 0xc(%rsp), %ecx
movq %rbp, %rax
shrq %cl, %rax
shrl $0x6, %ecx
orq %rax, (%r12,%rcx,8)
decq %rbx
jne 0xf080
movq %r14, %rdi
callq 0x3100
movq %r13, %rdi
leaq 0x5fa1(%rip), %rsi      # 0x1505e
leaq 0xe8c4(%rip), %rdx      # 0x1d988
leaq 0x7f15(%rip), %rcx      # 0x16fe0
movl 0x8(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
leaq 0x5f89(%rip), %rsi      # 0x1506a
callq 0x33a0
testq %rax, %rax
je 0xf191
movq %rax, %r14
xorl %r15d, %r15d
xorl %ebx, %ebx
movq (%r12,%rbx,8), %r12
testq %r12, %r12
je 0xf139
xorl %r13d, %r13d
movq %rbp, %rax
movl %r13d, %ecx
shrq %cl, %rax
testq %r12, %rax
je 0xf130
leal (%r15,%r13), %eax
movl %eax, 0x14(%rsp)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x14(%rsp), %rdi
movq %r14, %rcx
callq 0x3450
incq %r13
cmpq $0x40, %r13
jne 0xf103
incq %rbx
addq $0x40, %r15
cmpq $0x400000, %rbx         # imm = 0x400000
movq 0x18(%rsp), %r12
jne 0xf0f7
movq %r14, %rdi
callq 0x3100
movl 0x8(%rsp), %ebx
incl %ebx
cmpl 0x10(%rsp), %ebx
leaq 0x5ef7(%rip), %r15      # 0x1505e
leaq 0x40(%rsp), %r13
jne 0xf005
movq %r12, %rdi
callq 0x3040
movl $0x1, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x7efb(%rip), %rsi      # 0x1709a
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x7ef8(%rip), %rsi      # 0x170b1
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x624f(%rip), %rsi      # 0x1541d
leaq 0x65db(%rip), %rdx      # 0x157b0
leaq 0xe4ac(%rip), %rcx      # 0x1d688
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x7ea9(%rip), %rsi      # 0x1709a
movq %r14, %rdx
jmp 0xf1a4