// File: /workspace/github_c_makefile_star2_O2/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 0xe2e6(%rip), %rdi      # 0x1c788
leaq 0x62b7(%rip), %rsi      # 0x14760
callq 0x68a5
testq %rax, %rax
je 0xea1c
movq %rax, %rbx
leaq 0x5ba6(%rip), %rsi      # 0x14067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0xea09
movq %rax, %r14
leaq 0x60(%rsp), %rdi
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x30c0
movq %r14, %rdi
callq 0x3100
leaq 0xe191(%rip), %rdi      # 0x1c688
leaq 0x6262(%rip), %rsi      # 0x14760
callq 0x68a5
testq %rax, %rax
je 0xea3a
movq %rax, %rbx
leaq 0x188(%rsp), %rsi
movq %rax, %rdi
callq 0x32e0
testl %eax, %eax
jne 0xea09
movq 0x1b8(%rsp), %r12
movq %r12, %rdi
callq 0x3340
movq %rax, %r15
leaq 0x5b26(%rip), %rsi      # 0x14067
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0xea09
movq %rax, %r14
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rcx
callq 0x30c0
movl (%r15), %ebx
movl 0x60(%rsp), %ebp
cmpl %ebx, %ebp
jne 0xea5d
movslq 0x14(%r15), %r13
movq %r14, %rdi
callq 0x3100
movq %r15, 0x30(%rsp)
addq $0x20, %r15
leaq (,%r13,4), %rdx
xorl %r14d, %r14d
movq %r15, 0x58(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x3210
leaq 0xe3dd(%rip), %rdi      # 0x1c988
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x3090
leaq 0x1(%r13), %rax
movq %rax, 0x20(%rsp)
leaq 0x8(,%r13,8), %rbx
movq %rbx, %rdi
callq 0x3340
movq %rbx, %rdi
movq %rax, %rbx
callq 0x3340
movq %rax, 0x8(%rsp)
andq $0x0, (%rax)
movl $0x2000000, %edi        # imm = 0x2000000
callq 0x3340
movq %rax, 0x10(%rsp)
testl %r13d, %r13d
movl $0x0, %eax
movq %r13, 0x40(%rsp)
cmovgl %r13d, %eax
movq %rax, 0x50(%rsp)
movl 0x70(%rsp), %eax
testl %eax, %eax
cmovlel %r14d, %eax
movl %eax, 0x18(%rsp)
leaq 0x5a42(%rip), %r14      # 0x1405e
leaq 0xe165(%rip), %r13      # 0x1c788
leaq 0x7a0c(%rip), %rbp      # 0x16036
xorl %r15d, %r15d
movq %r12, 0x38(%rsp)
movq %rbx, 0x28(%rsp)
cmpl 0x18(%rsp), %r15d
je 0xe974
movl $0x2000000, %edx        # imm = 0x2000000
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x3210
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
leaq 0x7925(%rip), %rcx      # 0x15f90
movl %r15d, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0x188(%rsp), %r12
movq %r12, %rsi
callq 0x32e0
testl %eax, %eax
je 0xe6b9
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
leaq 0x78f8(%rip), %rcx      # 0x15f94
movl %r15d, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
movq %r12, %rsi
callq 0x32e0
testl %eax, %eax
jne 0xe9ec
movl %r15d, 0x4(%rsp)
movq %rbx, %rdi
movq 0x1b8(%rsp), %rbx
leaq 0x5997(%rip), %r14      # 0x14067
movq %r14, %rsi
callq 0x33a0
testq %rax, %rax
je 0xe9ec
movq %rax, %r13
shrq $0x2, %rbx
leaq 0x1c(%rsp), %r12
subq $0x1, %rbx
jb 0xe723
movq %r12, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rcx
callq 0x30c0
movl 0x1c(%rsp), %ecx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
shrq %cl, %rax
shrl $0x6, %ecx
movq 0x10(%rsp), %rdx
orq %rax, (%rdx,%rcx,8)
jmp 0xe6ed
movq %r13, %rdi
callq 0x3100
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x783c(%rip), %rbp      # 0x15f7c
leaq 0xdf41(%rip), %r15      # 0x1c688
movq %r15, %rdx
movq %rbp, %rcx
movl 0x4(%rsp), %r12d
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
movq %r14, %rsi
callq 0x33a0
testq %rax, %rax
je 0xe9ec
movq %rax, %r13
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
pushq $0x8
popq %rsi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
callq 0x30c0
movq %r13, %rdi
callq 0x3100
leaq 0x80(%rsp), %r13
movq %r13, %rdi
leaq 0x58b9(%rip), %r14      # 0x1405e
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
leaq 0x58a5(%rip), %rsi      # 0x14067
callq 0x33a0
testq %rax, %rax
je 0xe9ec
movq %rax, %r13
movq %rbp, %r15
movq 0x40(%rsp), %rax
movq (%rbx,%rax,8), %rbp
leaq (,%rbp,4), %rdi
callq 0x3340
movq %rax, 0x48(%rsp)
movq %rax, %rdi
pushq $0x4
popq %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x30c0
movq %r13, %rdi
callq 0x3100
leaq 0x80(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
leaq 0xe169(%rip), %rdx      # 0x1c988
movq %r15, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
leaq 0x5834(%rip), %rsi      # 0x1406a
callq 0x33a0
testq %rax, %rax
je 0xe9ec
movq %rax, %rbp
xorl %r15d, %r15d
cmpq 0x50(%rsp), %r15
je 0xe8e7
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %r14
leaq 0x1(%r15), %r12
movq %r14, 0x8(%rax,%r15,8)
movq (%rbx,%r15,8), %rax
movq 0x8(%rbx,%r15,8), %rbx
subq %rax, %rbx
movq 0x48(%rsp), %rcx
leaq (%rcx,%rax,4), %r13
subq $0x1, %rbx
jb 0xe8da
movl (%r13), %ecx
movl %ecx, %eax
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
shrq %cl, %rdx
shrl $0x6, %eax
xorl %ecx, %ecx
movq 0x10(%rsp), %rsi
testq %rdx, (%rsi,%rax,8)
setne %cl
cmpl %ecx, 0xddc4(%rip)      # 0x1c670
jne 0xe8d4
movq %r13, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbp, %rcx
callq 0x3450
incq %r14
movq 0x8(%rsp), %rax
movq %r14, (%rax,%r12,8)
movq 0x58(%rsp), %rax
incl (%rax,%r15,4)
addq $0x4, %r13
jmp 0xe87c
movq %r12, %r15
movq 0x28(%rsp), %rbx
jmp 0xe84a
movq %rbp, %rdi
callq 0x3100
leaq 0x80(%rsp), %r14
movq %r14, %rdi
leaq 0x7735(%rip), %rbp      # 0x16036
movq %rbp, %rsi
leaq 0xe07d(%rip), %rdx      # 0x1c988
leaq 0x766a(%rip), %rcx      # 0x15f7c
movl 0x4(%rsp), %r15d
movl %r15d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x573f(%rip), %rsi      # 0x1406a
callq 0x33a0
testq %rax, %rax
je 0xe9ec
movq %rax, %r13
movq 0x8(%rsp), %rdi
pushq $0x8
popq %rsi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
callq 0x3450
movq %r13, %rdi
callq 0x3100
incl %r15d
movq 0x38(%rsp), %r12
leaq 0x56f6(%rip), %r14      # 0x1405e
leaq 0xde19(%rip), %r13      # 0x1c788
jmp 0xe637
leaq 0x5a18(%rip), %rsi      # 0x14393
leaq 0xe006(%rip), %rdx      # 0x1c988
leaq 0x5dd7(%rip), %rcx      # 0x14760
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3430
leaq 0x56c8(%rip), %rsi      # 0x1406a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0xe9ec
movq %rax, %rbx
pushq $0x1
popq %rdx
movq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
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 0x7607(%rip), %rsi      # 0x16001
leaq 0x80(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x75ea(%rip), %rsi      # 0x16001
movq %rbx, %rdx
jmp 0xea02
callq 0x3060
movl (%rax), %edi
leaq 0x59a3(%rip), %rsi      # 0x143cd
leaq 0x5d2f(%rip), %rdx      # 0x14760
leaq 0xdd50(%rip), %rcx      # 0x1c788
jmp 0xea56
callq 0x3060
movl (%rax), %edi
leaq 0x5985(%rip), %rsi      # 0x143cd
leaq 0x5d11(%rip), %rdx      # 0x14760
leaq 0xdc32(%rip), %rcx      # 0x1c688
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x75aa(%rip), %rsi      # 0x16015
movl %ebx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3330