// File: /workspace/github_c_makefile_star2_O3/yhg926[P]public_kssd/command_set.c
// Function: sketch_operate
int sketch_operate()
{
 int ret = 1;
 co_dstat_t co_dstat_pan, co_dstat_origin ;
 const char* co_dstat_fpath = NULL;
  co_dstat_fpath = test_get_fullpath(set_opt.pansketchpath,co_dstat);
 if(co_dstat_fpath == NULL ) err(errno,"cannot find %s under %s ",co_dstat,set_opt.pansketchpath);
 FILE *co_stat_fp;
  if( ( co_stat_fp = fopen(co_dstat_fpath,"rb")) == NULL ) err(errno,"sketch_operate():%s",co_dstat_fpath);
  fread( &co_dstat_pan, sizeof(co_dstat_t),1,co_stat_fp );
 fclose(co_stat_fp);
 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);
 struct stat s;
 if(stat(co_dstat_fpath, &s) != 0) err(errno,"sketch_operate():%s",co_dstat_fpath);
 size_t codstat_fz = s.st_size;
 co_dstat_t *tmpmem = malloc(codstat_fz);
 if( ( co_stat_fp = fopen(co_dstat_fpath,"rb")) == NULL ) err(errno,"sketch_operate():%s",co_dstat_fpath);
 fread(tmpmem,codstat_fz, 1, co_stat_fp);
 co_dstat_origin = *tmpmem;
 if (co_dstat_pan.shuf_id != co_dstat_origin.shuf_id) err(errno,"sketcing id not match(%d Vs. %d)",co_dstat_origin.shuf_id,co_dstat_pan.shuf_id);
 fclose(co_stat_fp);
 unsigned int *tmp_ctx_ct = (void *) tmpmem + sizeof(co_dstat_t);
 memset(tmp_ctx_ct,0,co_dstat_origin.infile_num*sizeof(unsigned int)) ;
 mkdir(set_opt.outdir,0777);
 char tmppath[PATHLEN];
 size_t *fco_pos = malloc(sizeof(size_t) * (co_dstat_origin.infile_num + 1) );
 size_t *post_fco_pos = malloc(sizeof(size_t) * (co_dstat_origin.infile_num + 1) );
 post_fco_pos[0] = 0;
 size_t comp_sz = (1LLU << 4*COMPONENT_SZ);
  llong* dict = (llong*)malloc(comp_sz/8);
  unsigned int tmppanco;
 for(int c=0; c< co_dstat_pan.comp_num; c++ ){
  memset(dict,0,comp_sz/8);
  sprintf(tmppath,"%s/%s.%d",set_opt.pansketchpath, pan_prefix, c);
    if(stat(tmppath, &s) != 0){
   sprintf(tmppath,"%s/%s.%d",set_opt.pansketchpath, uniq_pan_prefix, c);
   if(stat(tmppath, &s) != 0) err(errno,"sketch_operate():%s",tmppath);
  }
    size_t size = s.st_size / sizeof(unsigned int);
  if( ( co_stat_fp = fopen(tmppath,"rb")) == NULL ) err(errno,"sketch_operate():%s",tmppath);
  for(size_t n=0; n< size ; n++){
      fread(&tmppanco,sizeof(unsigned int),1,co_stat_fp);
      dict[tmppanco/64] |= ( 0x8000000000000000LLU >> (tmppanco % 64) ) ;
    }
  fclose(co_stat_fp);
  sprintf(tmppath,"%s/%s.index.%d",set_opt.insketchpath,skch_prefix, c);
  if( ( co_stat_fp = fopen(tmppath,"rb")) == NULL ) err(errno,"sketch_operate():%s",tmppath);
  fread(fco_pos,sizeof(size_t),co_dstat_origin.infile_num + 1 ,co_stat_fp);
  fclose(co_stat_fp);
  sprintf(tmppath,"%s/%s.%d",set_opt.insketchpath,skch_prefix, c);
    if( ( co_stat_fp = fopen(tmppath,"rb")) == NULL ) err(errno,"sketch_operate():%s",tmppath);
    unsigned int *cbd_fcode_mem = malloc(fco_pos[co_dstat_origin.infile_num] * sizeof(unsigned int));
    fread(cbd_fcode_mem,sizeof(unsigned int),fco_pos[co_dstat_origin.infile_num],co_stat_fp);
    fclose(co_stat_fp);
  sprintf(tmppath,"%s/%s.%d",set_opt.outdir,skch_prefix, c);
  if( ( co_stat_fp = fopen(tmppath,"wb")) == NULL) err(errno,"sketch_operate():%s",tmppath);
  for(int i = 0 ; i < co_dstat_origin.infile_num; i++){
   post_fco_pos[i+1] = post_fco_pos[i];
   for(int n = 0; n < fco_pos[i+1] - fco_pos[i]; n++){
    if( set_opt.operation == ( (dict[ cbd_fcode_mem[ fco_pos[i] + n ]/64 ] & (0x8000000000000000LLU >> (cbd_fcode_mem[ fco_pos[i] + n ] % 64)) ) > 0 ) ){
     fwrite(cbd_fcode_mem + fco_pos[i] + n, sizeof(unsigned int), 1, co_stat_fp);
     post_fco_pos[i+1]++;
     tmp_ctx_ct[i]++;
    }
   }
  }
  fclose(co_stat_fp);
  sprintf(tmppath,"%s/%s.index.%d",set_opt.outdir,skch_prefix, c);
    if( ( co_stat_fp = fopen(tmppath,"wb")) == NULL) err(errno,"sketch_operate():%s",tmppath);
  fwrite(post_fco_pos,sizeof(size_t),co_dstat_origin.infile_num + 1,co_stat_fp);
  fclose(co_stat_fp);
 }
 sprintf(tmppath,"%s/%s",set_opt.outdir,co_dstat);
  if( ( co_stat_fp = fopen(tmppath,"wb")) == NULL) err(errno,"sketch_operate():%s",tmppath);
  fwrite(tmpmem,codstat_fz,1,co_stat_fp);
  free(tmpmem);
  fclose(co_stat_fp);
 ret = 0;
 return ret ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
leaq 0xe57a(%rip), %rdi      # 0x1d788
leaq 0x659b(%rip), %rsi      # 0x157b0
callq 0x6d79
testq %rax, %rax
je 0xf7bb
movq %rax, %rbx
leaq 0x5e3a(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0xf7a8
movq %rax, %r14
leaq 0x60(%rsp), %rdi
movl $0x20, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x30c0
movq %r14, %rdi
callq 0x3100
leaq 0xe421(%rip), %rdi      # 0x1d688
leaq 0x6542(%rip), %rsi      # 0x157b0
callq 0x6d79
testq %rax, %rax
je 0xf7d9
movq %rax, %rbx
leaq 0x188(%rsp), %rsi
movq %rax, %rdi
callq 0x32e0
testl %eax, %eax
jne 0xf7a8
movq 0x1b8(%rsp), %r15
movq %r15, %rdi
callq 0x3340
movq %rax, %r12
leaq 0x5db6(%rip), %rsi      # 0x15067
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0xf7a8
movq %rax, %r14
movl $0x1, %edx
movq %r12, %rdi
movq %r15, 0x38(%rsp)
movq %r15, %rsi
movq %rax, %rcx
callq 0x30c0
movl (%r12), %ebx
movl 0x60(%rsp), %ebp
cmpl %ebx, %ebp
jne 0xf7fc
movslq 0x14(%r12), %r13
movq %r14, %rdi
callq 0x3100
movq %r12, 0x30(%rsp)
addq $0x20, %r12
leaq (,%r13,4), %rdx
movq %r12, 0x58(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x3210
leaq 0xe667(%rip), %rdi      # 0x1d988
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
leaq 0x8(,%r13,8), %rbx
movq %rbx, %rdi
callq 0x3340
movq %rax, %rbp
movq %rbx, %rdi
callq 0x3340
movq %rax, 0x10(%rsp)
movq $0x0, (%rax)
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x3340
movl 0x70(%rsp), %ecx
movl %ecx, 0x18(%rsp)
testl %ecx, %ecx
jle 0xf70f
leaq 0x1(%r13), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x5ce2(%rip), %rbx      # 0x1505e
leaq 0xe405(%rip), %r14      # 0x1d788
leaq 0x80(%rsp), %r15
leaq 0x188(%rsp), %r12
movl $0x0, 0x4(%rsp)
movq %r13, 0x28(%rsp)
movq %rbp, 0x48(%rsp)
movq %rax, 0x8(%rsp)
movl $0x2000000, %edx        # imm = 0x2000000
movq %rax, %rdi
xorl %esi, %esi
callq 0x3210
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
leaq 0x7c17(%rip), %rcx      # 0x16fe0
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r15, %rdi
movq %r12, %rsi
callq 0x32e0
testl %eax, %eax
je 0xf413
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
leaq 0x7bf0(%rip), %rcx      # 0x16fe4
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r15, %rdi
movq %r12, %rsi
callq 0x32e0
testl %eax, %eax
jne 0xf78b
movq 0x1b8(%rsp), %rbx
movq %r15, %rdi
leaq 0x5c42(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0xf78b
movq %rax, %r14
cmpq $0x4, %rbx
movq 0x8(%rsp), %r15
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
leaq 0x1c(%rsp), %r13
jb 0xf485
shrq $0x2, %rbx
movl $0x4, %esi
movq %rdx, %r12
movl $0x1, %edx
movq %r13, %rdi
movq %r14, %rcx
callq 0x30c0
movq %r12, %rdx
movl 0x1c(%rsp), %ecx
movq %r12, %rax
shrq %cl, %rax
shrl $0x6, %ecx
orq %rax, (%r15,%rcx,8)
decq %rbx
jne 0xf454
movq %r14, %rdi
callq 0x3100
leaq 0x80(%rsp), %r15
movq %r15, %rdi
leaq 0x7be7(%rip), %rsi      # 0x17086
leaq 0xe1e2(%rip), %rdx      # 0x1d688
leaq 0x7b1f(%rip), %rcx      # 0x16fcc
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r15, %rdi
leaq 0x5ba4(%rip), %r12      # 0x15067
movq %r12, %rsi
callq 0x33a0
testq %rax, %rax
je 0xf78b
movq %rax, %r14
movl $0x8, %esi
movq %rbp, %rdi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
callq 0x30c0
movq %r14, %rdi
callq 0x3100
movq %r15, %rdi
leaq 0x5b60(%rip), %rbx      # 0x1505e
movq %rbx, %rsi
leaq 0xe180(%rip), %rdx      # 0x1d688
leaq 0x7abd(%rip), %rcx      # 0x16fcc
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r15, %rdi
movq %r12, %rsi
callq 0x33a0
testq %rax, %rax
movq 0x28(%rsp), %r13
je 0xf78b
movq %rax, %r14
movq (%rbp,%r13,8), %r12
leaq (,%r12,4), %rdi
callq 0x3340
movl $0x4, %esi
movq %rax, 0x40(%rsp)
movq %rax, %rdi
movq %r12, %rdx
movq %r14, %rcx
callq 0x30c0
movq %r14, %rdi
callq 0x3100
movq %r15, %rdi
movq %rbx, %rsi
leaq 0xe412(%rip), %rdx      # 0x1d988
leaq 0x7a4f(%rip), %rcx      # 0x16fcc
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r15, %rdi
leaq 0x5ad7(%rip), %rsi      # 0x1506a
callq 0x33a0
testq %rax, %rax
je 0xf78b
movq %rax, %r14
testl %r13d, %r13d
movq 0x8(%rsp), %rdi
movabsq $-0x8000000000000000, %r8 # imm = 0x8000000000000000
jle 0xf674
movq 0x10(%rsp), %rax
movq (%rax), %r15
movq (%rbp), %rax
xorl %ebx, %ebx
movq %rbx, %r13
incq %rbx
movq 0x10(%rsp), %rcx
movq %r15, 0x8(%rcx,%r13,8)
movq 0x8(%rbp,%r13,8), %rbp
movq %rbp, 0x50(%rsp)
subq %rax, %rbp
je 0xf65c
movq 0x40(%rsp), %rcx
leaq (%rcx,%rax,4), %r12
movl 0xe078(%rip), %eax      # 0x1d670
movl (%r12), %ecx
movl %ecx, %edx
shrl $0x6, %edx
movq %r8, %rsi
shrq %cl, %rsi
xorl %ecx, %ecx
testq %rsi, (%rdi,%rdx,8)
setne %cl
cmpl %ecx, %eax
jne 0xf653
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x3450
movabsq $-0x8000000000000000, %r8 # imm = 0x8000000000000000
movq 0x8(%rsp), %rdi
incq %r15
movq 0x10(%rsp), %rax
movq %r15, (%rax,%rbx,8)
movq 0x58(%rsp), %rax
incl (%rax,%r13,4)
movl 0xe01d(%rip), %eax      # 0x1d670
addq $0x4, %r12
decq %rbp
jne 0xf5f8
movq 0x28(%rsp), %r13
cmpq %r13, %rbx
movq 0x48(%rsp), %rbp
movq 0x50(%rsp), %rax
jne 0xf5ca
movq %r14, %rdi
callq 0x3100
leaq 0x80(%rsp), %r15
movq %r15, %rdi
leaq 0x79f8(%rip), %rsi      # 0x17086
leaq 0xe2f3(%rip), %rdx      # 0x1d988
leaq 0x7930(%rip), %rcx      # 0x16fcc
movl 0x4(%rsp), %ebx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r15, %rdi
leaq 0x59b6(%rip), %rsi      # 0x1506a
callq 0x33a0
testq %rax, %rax
je 0xf78b
movq %rax, %r14
movl $0x8, %esi
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
callq 0x3450
movq %r14, %rdi
callq 0x3100
incl %ebx
movl %ebx, 0x4(%rsp)
cmpl 0x18(%rsp), %ebx
movq 0x8(%rsp), %rax
leaq 0x5964(%rip), %rbx      # 0x1505e
leaq 0xe087(%rip), %r14      # 0x1d788
leaq 0x188(%rsp), %r12
jne 0xf3aa
leaq 0x5ccd(%rip), %rsi      # 0x153e3
leaq 0xe26b(%rip), %rdx      # 0x1d988
leaq 0x608c(%rip), %rcx      # 0x157b0
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3430
leaq 0x592d(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
movq 0x38(%rsp), %rsi
je 0xf78b
movq %rax, %rbx
movl $0x1, %edx
movq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rax, %rcx
callq 0x3450
movq %r14, %rdi
callq 0x3040
movq %rbx, %rdi
callq 0x3100
xorl %eax, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x78b8(%rip), %rsi      # 0x17051
leaq 0x80(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x789b(%rip), %rsi      # 0x17051
movq %rbx, %rdx
jmp 0xf7a1
callq 0x3060
movl (%rax), %edi
leaq 0x5c54(%rip), %rsi      # 0x1541d
leaq 0x5fe0(%rip), %rdx      # 0x157b0
leaq 0xdfb1(%rip), %rcx      # 0x1d788
jmp 0xf7f5
callq 0x3060
movl (%rax), %edi
leaq 0x5c36(%rip), %rsi      # 0x1541d
leaq 0x5fc2(%rip), %rdx      # 0x157b0
leaq 0xde93(%rip), %rcx      # 0x1d688
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x785b(%rip), %rsi      # 0x17065
movl %ebx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3330