// File: /workspace/github_c_makefile_star2_O2/yhg926[P]public_kssd/command_set.c
// Function: uniq_sketch_union
int uniq_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,"uniq_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",uniq_pan_prefix,i);
        if(rename(combco,unionco) !=0) err(errno,"uniq_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,"uniq_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);
 llong* dict2 = (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);
  memset(dict2,~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,"uniq_sketch_union():%s",outpath);
    size_t size = s.st_size / sizeof(unsigned int);
    if( ( co_stat_fp = fopen(outpath,"rb")) == NULL ) err(errno,"uniq_sketch_union():%s",outpath);
    for(size_t n=0; n< size ; n++){
      fread(&tmpcbdco,sizeof(unsigned int),1,co_stat_fp);
   if ( dict[tmpcbdco/64] & ( 0x8000000000000000LLU >> (tmpcbdco % 64) ))
    dict2[tmpcbdco/64] &= ~( 0x8000000000000000LLU >> (tmpcbdco % 64) );
      dict[tmpcbdco/64] |= ( 0x8000000000000000LLU >> (tmpcbdco % 64) ) ;
    }
    fclose(co_stat_fp);
    sprintf(outpath,"%s/%s.%d",set_opt.outdir,uniq_pan_prefix,i);
    if( ( co_stat_fp = fopen(outpath,"wb")) == NULL ) err(errno,"uniq_sketch_union():%s",outpath);
    for(unsigned int n=0;n< comp_sz/64; n++){
      if(dict[n] & dict2[n]){
        for(int b=0; b< 64; b++){
          if ( (0x8000000000000000LLU >> b) & dict[n] & dict2[n] ){
            unsigned int var = 64*n + b ;
            fwrite(&var,sizeof(unsigned int),1,co_stat_fp);
          }
        }
      }
    }
    fclose(co_stat_fp);
  }
  free(dict);
 free(dict2);
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
leaq 0xdbfa(%rip), %rdi      # 0x1c688
leaq 0x5ccb(%rip), %rsi      # 0x14760
callq 0x68a5
testq %rax, %rax
je 0xee61
movq %rax, %rbx
leaq 0x55ba(%rip), %rsi      # 0x14067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0xee84
movq %rax, %r13
leaq 0x20(%rsp), %rbx
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %rax, %rcx
callq 0x30c0
cmpl $0x1, 0x14(%rbx)
jne 0xeba4
leaq 0x74bc(%rip), %rdi      # 0x15fa4
leaq 0xdb99(%rip), %rsi      # 0x1c688
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x3170
leaq 0x74d0(%rip), %rdi      # 0x15fcf
movq %rsp, %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3400
movb (%rbx), %al
andb $-0x21, %al
cmpb $0x59, %al
jne 0xeba4
leaq 0xdb69(%rip), %rdi      # 0x1c688
callq 0x3140
movl 0x30(%rsp), %r14d
testl %r14d, %r14d
cmovlel %ebp, %r14d
leaq 0x552a(%rip), %rbx      # 0x14061
leaq 0x40(%rsp), %r15
leaq 0x7451(%rip), %r12      # 0x15f94
leaq 0x140(%rsp), %r13
xorl %ebp, %ebp
cmpl %ebp, %r14d
je 0xee1d
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x7419(%rip), %rdx      # 0x15f7c
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
incl %ebp
testl %eax, %eax
je 0xeb4d
callq 0x3060
movl (%rax), %edi
leaq 0x74bf(%rip), %rsi      # 0x1605c
xorl %eax, %eax
callq 0x3330
leaq 0xdddd(%rip), %rbx      # 0x1c988
movq %rbx, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
leaq 0x57d4(%rip), %rsi      # 0x14393
leaq 0x5b9a(%rip), %rcx      # 0x14760
xorl %ebp, %ebp
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0x5489(%rip), %rsi      # 0x1406a
movq %r15, %rdi
callq 0x33a0
testq %rax, %rax
je 0xee47
movq %rax, %r15
leaq 0x20(%rsp), %r12
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %rax, %rcx
callq 0x3450
movq %r13, %rdi
callq 0x3100
movq %r15, %rdi
callq 0x3100
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x3340
movq %rax, %r14
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x3340
movq %rax, 0x8(%rsp)
movl 0x10(%r12), %eax
testl %eax, %eax
cmovlel %ebp, %eax
movl %eax, 0x10(%rsp)
leaq 0x5412(%rip), %r15      # 0x1405e
leaq 0x40(%rsp), %r12
movq %rsp, %rbp
xorl %ebx, %ebx
movq %r14, 0x18(%rsp)
cmpl 0x10(%rsp), %ebx
je 0xee09
movl $0x2000000, %edx        # imm = 0x2000000
movq %r14, %rdi
xorl %esi, %esi
callq 0x3210
movl $0x2000000, %edx        # imm = 0x2000000
movq 0x8(%rsp), %rdi
movl $0xff, %esi
callq 0x3210
movq %r12, %rdi
movq %r15, %rsi
leaq 0xd9f3(%rip), %rdx      # 0x1c688
leaq 0x72e0(%rip), %rcx      # 0x15f7c
movl %ebx, 0x4(%rsp)
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
leaq 0x140(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
jne 0xee47
movq 0x170(%rsp), %rbx
movq %r12, %rdi
leaq 0x5393(%rip), %rsi      # 0x14067
callq 0x33a0
testq %rax, %rax
je 0xee47
movq %rax, %r13
shrq $0x2, %rbx
subq $0x1, %rbx
jb 0xed36
movq %rbp, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rcx
callq 0x30c0
movl (%rsp), %ecx
movl %ecx, %eax
shrl $0x6, %eax
movq (%r14,%rax,8), %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
shrq %cl, %rsi
testq %rdx, %rsi
je 0xed2d
movq %rsi, %rcx
notq %rcx
movq 0x8(%rsp), %rdi
andq %rcx, (%rdi,%rax,8)
orq %rdx, %rsi
movq %rsi, (%r14,%rax,8)
jmp 0xece9
movq %r13, %rdi
callq 0x3100
movq %r12, %rdi
movq %r15, %rsi
leaq 0xdc3d(%rip), %rdx      # 0x1c988
leaq 0x7242(%rip), %rcx      # 0x15f94
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
leaq 0x5302(%rip), %rsi      # 0x1406a
callq 0x33a0
testq %rax, %rax
je 0xee47
movq %rax, %r13
xorl %ebx, %ebx
xorl %ebp, %ebp
cmpq $0x400000, %rbp         # imm = 0x400000
je 0xede7
movq (%r14,%rbp,8), %r12
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %r14
testq %r12, %r14
je 0xedd9
xorl %r15d, %r15d
cmpq $0x40, %r15
je 0xedd9
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
movl %r15d, %ecx
shrq %cl, %rax
andq %r12, %rax
testq %r14, %rax
je 0xedd4
leal (%rbx,%r15), %eax
movl %eax, 0x14(%rsp)
leaq 0x14(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rcx
callq 0x3450
incq %r15
jmp 0xed9b
incq %rbp
addq $0x40, %rbx
movq 0x18(%rsp), %r14
jmp 0xed7d
movq %r13, %rdi
callq 0x3100
movl 0x4(%rsp), %ebx
incl %ebx
leaq 0x5262(%rip), %r15      # 0x1405e
leaq 0x40(%rsp), %r12
movq %rsp, %rbp
jmp 0xec5b
movq %r14, %rdi
callq 0x3040
movq 0x8(%rsp), %rdi
callq 0x3040
jmp 0xee32
leaq 0x71af(%rip), %rdi      # 0x15fd3
leaq 0xd85d(%rip), %rsi      # 0x1c688
xorl %eax, %eax
callq 0x3170
pushq $0x1
popq %rax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x71f0(%rip), %rsi      # 0x16045
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x555e(%rip), %rsi      # 0x143cd
leaq 0x58ea(%rip), %rdx      # 0x14760
leaq 0xd80b(%rip), %rcx      # 0x1c688
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x71b3(%rip), %rsi      # 0x16045
movq %rbx, %rdx
jmp 0xee5a