// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq $0x0, -0x10(%rbp)
leaq 0x10866(%rip), %rdi     # 0x23660
addq $0x18, %rdi
leaq 0x98eb(%rip), %rsi      # 0x1c6f0
callq 0x8250
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x12e3c
callq 0x3050
movl (%rax), %edi
leaq 0x955c(%rip), %rsi      # 0x1c37f
leaq 0x98c6(%rip), %rdx      # 0x1c6f0
leaq 0x1082f(%rip), %rcx     # 0x23660
addq $0x18, %rcx
movb $0x0, %al
callq 0x3300
movq -0x10(%rbp), %rdi
leaq 0x9210(%rip), %rsi      # 0x1c057
callq 0x3370
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0x12e6f
callq 0x3050
movl (%rax), %edi
movq -0x10(%rbp), %rdx
leaq 0xb0b3(%rip), %rsi      # 0x1df1b
movb $0x0, %al
callq 0x3300
movq -0x58(%rbp), %rcx
leaq -0x78(%rbp), %rdi
movl $0x20, %esi
movl $0x1, %edx
callq 0x30a0
cmpl $0x1, -0x64(%rbp)
jne 0x12f83
leaq 0xafde(%rip), %rdi      # 0x1de75
leaq 0x107c2(%rip), %rsi     # 0x23660
addq $0x18, %rsi
movb $0x0, %al
callq 0x3150
leaq 0xaff0(%rip), %rdi      # 0x1dea0
leaq -0x79(%rbp), %rsi
movb $0x0, %al
callq 0x33d0
movsbl -0x79(%rbp), %eax
cmpl $0x59, %eax
je 0x12ed1
movsbl -0x79(%rbp), %eax
cmpl $0x79, %eax
jne 0x12f81
leaq 0x10788(%rip), %rdi     # 0x23660
addq $0x18, %rdi
callq 0x3120
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x12f5c
leaq -0x30(%rbp), %rdi
movl -0x80(%rbp), %ecx
leaq 0x9153(%rip), %rsi      # 0x1c051
leaq 0xb554(%rip), %rdx      # 0x1e459
movb $0x0, %al
callq 0x3400
leaq -0x50(%rbp), %rdi
movl -0x80(%rbp), %ecx
leaq 0x9137(%rip), %rsi      # 0x1c051
leaq 0xb54c(%rip), %rdx      # 0x1e46d
movb $0x0, %al
callq 0x3400
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x33b0
cmpl $0x0, %eax
je 0x12f4f
callq 0x3050
movl (%rax), %edi
leaq 0xafea(%rip), %rsi      # 0x1df32
movb $0x0, %al
callq 0x3300
jmp 0x12f51
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x12ee8
leaq 0xaf41(%rip), %rdi      # 0x1dea4
leaq 0x106f6(%rip), %rsi     # 0x23660
addq $0x18, %rsi
movb $0x0, %al
callq 0x3150
movl $0x1, -0x4(%rbp)
jmp 0x13326
jmp 0x12f83
leaq 0x106d6(%rip), %rdi     # 0x23660
addq $0x318, %rdi            # imm = 0x318
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3080
leaq -0x180(%rbp), %rdi
leaq 0x9382(%rip), %rsi      # 0x1c32b
leaq 0x106b0(%rip), %rdx     # 0x23660
addq $0x318, %rdx            # imm = 0x318
leaq 0x9732(%rip), %rcx      # 0x1c6f0
movb $0x0, %al
callq 0x3400
leaq -0x180(%rbp), %rdi
leaq 0x9087(%rip), %rsi      # 0x1c05a
callq 0x3370
movq %rax, -0x188(%rbp)
cmpq $0x0, %rax
jne 0x13001
callq 0x3050
movl (%rax), %edi
leaq -0x180(%rbp), %rdx
leaq 0xaf21(%rip), %rsi      # 0x1df1b
movb $0x0, %al
callq 0x3300
movq -0x188(%rbp), %rcx
leaq -0x78(%rbp), %rdi
movl $0x20, %esi
movl $0x1, %edx
callq 0x3420
movq -0x58(%rbp), %rdi
callq 0x30e0
movq -0x188(%rbp), %rdi
callq 0x30e0
movq $0x10000000, -0x190(%rbp) # imm = 0x10000000
movq -0x190(%rbp), %rdi
shrq $0x3, %rdi
callq 0x3310
movq %rax, -0x198(%rbp)
movl $0x0, -0x1a0(%rbp)
movl -0x1a0(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x13313
movq -0x198(%rbp), %rdi
movq -0x190(%rbp), %rdx
shrq $0x3, %rdx
xorl %esi, %esi
callq 0x31f0
leaq -0x180(%rbp), %rdi
movl -0x1a0(%rbp), %r8d
leaq 0x8fb5(%rip), %rsi      # 0x1c04e
leaq 0x105c0(%rip), %rdx     # 0x23660
addq $0x18, %rdx
leaq 0xb3ae(%rip), %rcx      # 0x1e459
movb $0x0, %al
callq 0x3400
leaq -0x180(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x32b0
cmpl $0x0, %eax
je 0x130e6
callq 0x3050
movl (%rax), %edi
leaq -0x180(%rbp), %rdx
leaq 0xae3c(%rip), %rsi      # 0x1df1b
movb $0x0, %al
callq 0x3300
movq -0x200(%rbp), %rax
shrq $0x2, %rax
movq %rax, -0x238(%rbp)
leaq -0x180(%rbp), %rdi
leaq 0x8f51(%rip), %rsi      # 0x1c057
callq 0x3370
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0x13131
callq 0x3050
movl (%rax), %edi
leaq -0x180(%rbp), %rdx
leaq 0xadf1(%rip), %rsi      # 0x1df1b
movb $0x0, %al
callq 0x3300
movq $0x0, -0x240(%rbp)
movq -0x240(%rbp), %rax
cmpq -0x238(%rbp), %rax
jae 0x131ae
movq -0x58(%rbp), %rcx
leaq -0x19c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x30a0
movl -0x19c(%rbp), %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
shrq %cl, %rdx
movq -0x198(%rbp), %rax
movl -0x19c(%rbp), %ecx
shrl $0x6, %ecx
movl %ecx, %ecx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x240(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x240(%rbp)
jmp 0x1313c
movq -0x58(%rbp), %rdi
callq 0x30e0
leaq -0x180(%rbp), %rdi
movl -0x1a0(%rbp), %r8d
leaq 0x8e82(%rip), %rsi      # 0x1c04e
leaq 0x1048d(%rip), %rdx     # 0x23660
addq $0x318, %rdx            # imm = 0x318
leaq 0xb28c(%rip), %rcx      # 0x1e46d
movb $0x0, %al
callq 0x3400
leaq -0x180(%rbp), %rdi
leaq 0x8e64(%rip), %rsi      # 0x1c05a
callq 0x3370
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0x13221
callq 0x3050
movl (%rax), %edi
leaq -0x180(%rbp), %rdx
leaq 0xad01(%rip), %rsi      # 0x1df1b
movb $0x0, %al
callq 0x3300
movl $0x0, -0x244(%rbp)
movl -0x244(%rbp), %eax
movq -0x190(%rbp), %rcx
shrq $0x6, %rcx
cmpq %rcx, %rax
jae 0x132f6
movq -0x198(%rbp), %rax
movl -0x244(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x132e0
movl $0x0, -0x248(%rbp)
cmpl $0x40, -0x248(%rbp)
jge 0x132de
movl -0x248(%rbp), %eax
movl %eax, %ecx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
shrq %cl, %rax
movq -0x198(%rbp), %rcx
movl -0x244(%rbp), %edx
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
je 0x132cb
movl -0x244(%rbp), %eax
shll $0x6, %eax
addl -0x248(%rbp), %eax
movl %eax, -0x24c(%rbp)
movq -0x58(%rbp), %rcx
leaq -0x24c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x3420
jmp 0x132cd
movl -0x248(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x248(%rbp)
jmp 0x13267
jmp 0x132e0
jmp 0x132e2
movl -0x244(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x244(%rbp)
jmp 0x1322b
movq -0x58(%rbp), %rdi
callq 0x30e0
movl -0x1a0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a0(%rbp)
jmp 0x1305c
movq -0x198(%rbp), %rdi
callq 0x3040
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
nopw %cs:(%rax,%rax)