// File: /workspace/github_c_makefile_star2_O1/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 $0x208, %rsp            # imm = 0x208
leaq 0xe86d(%rip), %rdi      # 0x1d788
leaq 0x683e(%rip), %rsi      # 0x15760
callq 0x6bcc
testq %rax, %rax
je 0xf482
movq %rax, %rbx
leaq 0x612d(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0xf46f
movq %rax, %r14
leaq 0x50(%rsp), %rdi
movl $0x20, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x30c0
movq %r14, %rdi
callq 0x3100
leaq 0xe714(%rip), %rdi      # 0x1d688
leaq 0x67e5(%rip), %rsi      # 0x15760
callq 0x6bcc
testq %rax, %rax
je 0xf4a0
movq %rax, %rbx
leaq 0x178(%rsp), %rsi
movq %rax, %rdi
callq 0x32e0
testl %eax, %eax
jne 0xf46f
movq 0x1a8(%rsp), %r15
movq %r15, %rdi
callq 0x3340
movq %rax, %r12
leaq 0x60a9(%rip), %rsi      # 0x15067
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0xf46f
movq %rax, %r14
movl $0x1, %edx
movq %r12, %rdi
movq %r15, 0x30(%rsp)
movq %r15, %rsi
movq %rax, %rcx
callq 0x30c0
movl (%r12), %ebx
movl 0x50(%rsp), %ebp
cmpl %ebx, %ebp
jne 0xf4c3
movslq 0x14(%r12), %r15
movq %r14, %rdi
callq 0x3100
movq %r12, 0x28(%rsp)
addq $0x20, %r12
leaq (,%r15,4), %rdx
movq %r12, 0x48(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x3210
leaq 0xe95a(%rip), %rdi      # 0x1d988
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
leaq 0x8(,%r15,8), %rbx
movq %rbx, %rdi
callq 0x3340
movq %rax, %r13
movq %rbx, %rdi
callq 0x3340
movq %rax, 0x8(%rsp)
movq $0x0, (%rax)
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x3340
movq %rax, %rbp
movl 0x60(%rsp), %eax
movl %eax, 0x10(%rsp)
testl %eax, %eax
jle 0xf3dc
leaq 0x1(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0xe6fc(%rip), %r14      # 0x1d788
leaq 0x70(%rsp), %r12
xorl %ebx, %ebx
movq %r15, 0x20(%rsp)
movq %r13, 0x40(%rsp)
movl $0x2000000, %edx        # imm = 0x2000000
movq %rbp, %rdi
xorl %esi, %esi
callq 0x3210
movq %r12, %rdi
leaq 0x5fa8(%rip), %rsi      # 0x1505e
movq %r14, %rdx
leaq 0x7ed0(%rip), %rcx      # 0x16f90
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
leaq 0x178(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
je 0xf114
movq %r12, %rdi
leaq 0x5f76(%rip), %rsi      # 0x1505e
movq %r14, %rdx
leaq 0x7ea2(%rip), %rcx      # 0x16f94
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
leaq 0x178(%rsp), %rsi
callq 0x32e0
testl %eax, %eax
jne 0xf455
movl %ebx, 0x4(%rsp)
movq 0x1a8(%rsp), %r14
movq %r12, %rdi
leaq 0x5f3d(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0xf455
movq %rax, %rbx
cmpq $0x4, %r14
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
leaq 0x14(%rsp), %r15
jb 0xf186
shrq $0x2, %r14
movl $0x4, %esi
movq %rdx, %r12
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x30c0
movq %r12, %rdx
movl 0x14(%rsp), %ecx
movq %r12, %rax
shrq %cl, %rax
shrl $0x6, %ecx
orq %rax, (%rbp,%rcx,8)
decq %r14
jne 0xf154
movq %rbx, %rdi
callq 0x3100
leaq 0x70(%rsp), %r14
movq %r14, %rdi
leaq 0x7e99(%rip), %rsi      # 0x17036
leaq 0xe4e4(%rip), %rdx      # 0x1d688
leaq 0x7dd1(%rip), %rcx      # 0x16f7c
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x5ea6(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0xf455
movq %rax, %rbx
movl $0x8, %esi
movq %r13, %rdi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x30c0
movq %rbx, %rdi
callq 0x3100
movq %r14, %rdi
leaq 0x5e65(%rip), %r12      # 0x1505e
movq %r12, %rsi
leaq 0xe485(%rip), %rdx      # 0x1d688
leaq 0x7d72(%rip), %rcx      # 0x16f7c
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x5e47(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
movq 0x20(%rsp), %r15
je 0xf455
movq %rax, %rbx
movq (%r13,%r15,8), %r14
leaq (,%r14,4), %rdi
callq 0x3340
movl $0x4, %esi
movq %rax, 0x38(%rsp)
movq %rax, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x30c0
movq %rbx, %rdi
callq 0x3100
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0xe70e(%rip), %rdx      # 0x1d988
leaq 0x7cfb(%rip), %rcx      # 0x16f7c
movl 0x4(%rsp), %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0x5dd3(%rip), %rsi      # 0x1506a
callq 0x33a0
testq %rax, %rax
je 0xf455
movq %rax, %r14
testl %r15d, %r15d
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
jle 0xf356
xorl %r12d, %r12d
movq %r12, %r15
movq 0x8(%rsp), %rcx
movq (%rcx,%r12,8), %rax
incq %r12
movq %rax, 0x8(%rcx,%r15,8)
movq (%r13,%r15,8), %rax
movq 0x8(%r13,%r15,8), %r13
subq %rax, %r13
je 0xf343
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,4), %rbx
movl (%rbx), %ecx
movl %ecx, %eax
movq %rsi, %rdx
shrq %cl, %rdx
shrl $0x6, %eax
xorl %ecx, %ecx
testq %rdx, (%rbp,%rax,8)
setne %cl
cmpl %ecx, 0xe369(%rip)      # 0x1d670
jne 0xf33a
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x3450
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
movq 0x8(%rsp), %rax
incq (%rax,%r12,8)
movq 0x48(%rsp), %rax
incl (%rax,%r15,4)
addq $0x4, %rbx
decq %r13
jne 0xf2ea
movq 0x20(%rsp), %r15
cmpq %r15, %r12
movq 0x40(%rsp), %r13
jne 0xf2be
movq %r14, %rdi
callq 0x3100
leaq 0x70(%rsp), %r12
movq %r12, %rdi
leaq 0x7cc9(%rip), %rsi      # 0x17036
leaq 0xe614(%rip), %rdx      # 0x1d988
leaq 0x7c01(%rip), %rcx      # 0x16f7c
movl 0x4(%rsp), %r14d
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
leaq 0x5cd6(%rip), %rsi      # 0x1506a
callq 0x33a0
testq %rax, %rax
je 0xf455
movq %rax, %rbx
movl $0x8, %esi
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
incl %r14d
cmpl 0x10(%rsp), %r14d
movl %r14d, %ebx
leaq 0xe3b2(%rip), %r14      # 0x1d788
jne 0xf09d
leaq 0x5fb0(%rip), %rsi      # 0x15393
leaq 0xe59e(%rip), %rdx      # 0x1d988
leaq 0x636f(%rip), %rcx      # 0x15760
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3430
leaq 0x5c63(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0xf455
movq %rax, %rbx
movl $0x1, %edx
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq 0x30(%rsp), %rsi
movq %rax, %rcx
callq 0x3450
movq %r14, %rdi
callq 0x3040
movq %rbx, %rdi
callq 0x3100
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x7b9e(%rip), %rsi      # 0x17001
leaq 0x70(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x7b84(%rip), %rsi      # 0x17001
movq %rbx, %rdx
jmp 0xf468
callq 0x3060
movl (%rax), %edi
leaq 0x5f3d(%rip), %rsi      # 0x153cd
leaq 0x62c9(%rip), %rdx      # 0x15760
leaq 0xe2ea(%rip), %rcx      # 0x1d788
jmp 0xf4bc
callq 0x3060
movl (%rax), %edi
leaq 0x5f1f(%rip), %rsi      # 0x153cd
leaq 0x62ab(%rip), %rdx      # 0x15760
leaq 0xe1cc(%rip), %rcx      # 0x1d688
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x7b44(%rip), %rsi      # 0x17015
movl %ebx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3330