sanitization

decompiled_code:
int sanitization()
{
_QWORD *v0; // rbx
unsigned int v1; // eax
unsigned int v2; // er15
double v3; // rbx
__int64 v5; // r12
__int64 i; // rsi
int v7; // er13
int v8; // ebp
__int64 k; // rbx
__int64 v10; // rax
__int64 v11; // r14
__int64 j; // rbx
__int64 v13; // rax
int v14; // eax
__int64 v15; // rax
__int64 v16; // r14
__int64 v17; // rax
int v18; // eax
unsigned int v19; // er14
__int64 v20; // rbx
int v21; // er15
__int64 v22; // rbp
__int64 v23; // rax
unsigned int *v24; // r13
int *l; // rbx
int *v26; // r15
__int64 m; // rax
double v28; // [rsp+0h] [rbp-118h]
__int64 v29; // [rsp+0h] [rbp-118h]
double v30; // [rsp+8h] [rbp-110h]
int v31; // [rsp+8h] [rbp-110h]
double v32; // [rsp+8h] [rbp-110h]
__int64 v33; // [rsp+10h] [rbp-108h]
int v34; // [rsp+18h] [rbp-100h]
_DWORD *v35; // [rsp+18h] [rbp-100h]
_QWORD *v36; // [rsp+20h] [rbp-F8h]
double v37; // [rsp+28h] [rbp-F0h]
double v38; // [rsp+30h] [rbp-E8h]
int v39; // [rsp+38h] [rbp-E0h]
struct timeval v40; // [rsp+40h] [rbp-D8h] BYREF
struct timeval v41; // [rsp+50h] [rbp-C8h] BYREF
struct timeval v42; // [rsp+60h] [rbp-B8h] BYREF
struct timeval v43; // [rsp+70h] [rbp-A8h] BYREF
struct timeval v44; // [rsp+80h] [rbp-98h] BYREF
struct timeval v45; // [rsp+90h] [rbp-88h] BYREF
struct timeval v46; // [rsp+A0h] [rbp-78h] BYREF
struct timeval v47; // [rsp+B0h] [rbp-68h] BYREF
struct timeval v48; // [rsp+C0h] [rbp-58h] BYREF
struct timeval tv; // [rsp+D0h] [rbp-48h] BYREF

container_vol_init();
jobcount_init();
gettimeofday(&tv, 0LL);
v0 = (_QWORD *)index_init();
v36 = v0;
v1 = *(_DWORD *)(*v0 + 16LL);
if ( !v1 )
{
v33 = 0LL;
v2 = 0;
v28 = 0.0;
v30 = 0.0;
v38 = 0.0;
v37 = 0.0;
goto LABEL_3;
}
v5 = phf_init(v1);
gettimeofday(&v47, 0LL);
for ( i = htable_get_first(*v0); i; i = htable_get_next(*v0) )
phf_input(v5, i);
phf_walk(v5, i);
phf_build(v5);
gettimeofday(&v46, 0LL);
v37 = (double)(LODWORD(v46.tv_usec) - LODWORD(v47.tv_usec)) / 1000000.0
+ (double)(LODWORD(v46.tv_sec) - LODWORD(v47.tv_sec))
+ 0.0;
gettimeofday(&v45, 0LL);
v31 = 1;
v7 = 0;
v8 = 0x7FFFFFFF;
while ( (int)jobcount_max() >= v31 )
{
v17 = jobv_open((unsigned int)v31);
v29 = v17;
if ( v17 )
{
v18 = *(_DWORD *)(v17 + 4);
if ( v18 )
{
if ( v18 == 1 )
{
while ( 1 )
{
v15 = jobv_search_next_recipe(v29);
v16 = v15;
if ( !v15 )
break;
if ( G_VERBOSE )
printf("track deleted file %s \n", (const char *)(v15 + 8));
for ( j = *(_QWORD *)(v16 + 264); j; j = *(_QWORD *)(j + 40) )
{
v13 = htable_lookup(*v36, j);
if ( v13 )
{
v14 = *(_DWORD *)(v13 + 20);
if ( v8 > v14 )
v8 = v14;
if ( v7 < v14 )
v7 = v14;
}
else
{
err_msg("delete.c", 81LL, "maybe wrong");
}
}
recipe_free(v16);
}
*(_DWORD *)(v29 + 4) = 2;
}
}
else
{
while ( 1 )
{
v10 = jobv_search_next_recipe(v29);
v11 = v10;
if ( !v10 )
break;
if ( G_VERBOSE )
printf("track file %s \n", (const char *)(v10 + 8));
for ( k = *(_QWORD *)(v11 + 264); k; k = *(_QWORD *)(k + 40) )
phf_mark(v5, k);
recipe_free(v11);
}
}
jobv_destroy(v29);
}
++v31;
}
gettimeofday(&v44, 0LL);
v38 = (double)(LODWORD(v44.tv_usec) - LODWORD(v45.tv_usec)) / 1000000.0
+ (double)(LODWORD(v44.tv_sec) - LODWORD(v45.tv_sec))
+ 0.0;
container_vol_max_num();
if ( v8 >= v7 )
{
puts("******no job is deleted ");
if ( v8 != v7 )
{
v33 = 0LL;
v2 = 0;
v28 = 0.0;
v30 = 0.0;
goto LABEL_59;
}
}
else
{
printf("****** scan container id from %d to %d \n", (unsigned int)v8, (unsigned int)v7);
}
v33 = 0LL;
v19 = 0;
v28 = 0.0;
v30 = 0.0;
v39 = v7;
do
{
gettimeofday(&v43, 0LL);
v23 = read_container((unsigned int)v8);
v24 = (unsigned int *)v23;
if ( v23 )
{
v20 = htable_get_first(*(_QWORD *)(v23 + 16));
if ( v20 )
{
v21 = 0;
v34 = v8;
v22 = v33;
do
{
if ( !(unsigned int)phf_search(v5, v20 + 12) )
{
*(_DWORD *)(v20 + 8) = -1;
++v21;
++v19;
v22 += *(int *)(v20 + 4);
}
v20 = htable_get_next(*((_QWORD *)v24 + 2));
}
while ( v20 );
v33 = v22;
v8 = v34;
gettimeofday(&v42, 0LL);
v32 = (double)(LODWORD(v42.tv_usec) - LODWORD(v43.tv_usec)) / 1000000.0
+ (double)(LODWORD(v42.tv_sec) - LODWORD(v43.tv_sec))
+ v30;
gettimeofday(&v41, 0LL);
if ( v24[2] != v21 )
{
if ( v21 > 0 )
{
v35 = (_DWORD *)container_init();
for ( l = (int *)htable_get_first(*((_QWORD *)v24 + 2)); l; l = (int *)htable_get_next(*((_QWORD *)v24 + 2)) )
{
if ( l[2] <= 0 )
{
htable_remove(*v36, l + 3);
}
else
{
v26 = (int *)chunk_new(l + 3, *((_QWORD *)v24 + 3) + *l, (unsigned int)l[1]);
if ( *(_BYTE *)(*((_QWORD *)v24 + 3) + *l + *v26) != 9 )
err_msg("delete.c", 138LL, "container has been corrupted.");
if ( !(unsigned int)write_chunk(v35, v26) )
err_msg("delete.c", 140LL, " write chunk into new container wrong");
}
}
*v35 = *v24;
write_container(v35);
container_usage(v35);
container_destroy(v35);
}
goto LABEL_43;
}
}
else
{
gettimeofday(&v42, 0LL);
v32 = (double)(LODWORD(v42.tv_usec) - LODWORD(v43.tv_usec)) / 1000000.0
+ (double)(LODWORD(v42.tv_sec) - LODWORD(v43.tv_sec))
+ v30;
gettimeofday(&v41, 0LL);
if ( v24[2] )
{
LABEL_43:
gettimeofday(&v40, 0LL);
v28 = (double)(LODWORD(v40.tv_usec) - LODWORD(v41.tv_usec)) / 1000000.0
+ (double)(LODWORD(v40.tv_sec) - LODWORD(v41.tv_sec))
+ v28;
gettimeofday(&v43, 0LL);
container_destroy(v24);
gettimeofday(&v42, 0LL);
v30 = (double)(LODWORD(v42.tv_usec) - LODWORD(v43.tv_usec)) / 1000000.0
+ (double)(LODWORD(v42.tv_sec) - LODWORD(v43.tv_sec))
+ v32;
goto LABEL_44;
}
}
container_free(*v24);
for ( m = htable_get_first(*((_QWORD *)v24 + 2)); m; m = htable_get_next(*((_QWORD *)v24 + 2)) )
htable_remove(*v36, m + 12);
goto LABEL_43;
}
LABEL_44:
++v8;
}
while ( v39 >= v8 );
v2 = v19;
LABEL_59:
phf_destory(v5);
LABEL_3:
index_destroy(v36);
gettimeofday(&v48, 0LL);
v3 = (double)(LODWORD(v48.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v48.tv_sec) - LODWORD(tv.tv_sec))
+ 0.0;
jobcount_close();
container_vol_destroy();
printf("delete nume:%d \n", v2);
printf("delete size:%d \n", v33);
return printf("%10.3f \n%10.3f \n%10.3f \n%10.3f \n%10.3f \n", v3, v37, v38, v30, v28);
}

canonical_decompiled_code:
int func0()
{
_QWORD *v0; // rbx
unsigned int v1; // eax
unsigned int v2; // er15
double v3; // rbx
__int64 v5; // r12
__int64 i; // rsi
int v7; // er13
int v8; // ebp
__int64 k; // rbx
__int64 v10; // rax
__int64 v11; // r14
__int64 j; // rbx
__int64 v13; // rax
int v14; // eax
__int64 v15; // rax
__int64 v16; // r14
__int64 v17; // rax
int v18; // eax
unsigned int v19; // er14
__int64 v20; // rbx
int v21; // er15
__int64 v22; // rbp
__int64 v23; // rax
unsigned int *v24; // r13
int *l; // rbx
int *v26; // r15
__int64 m; // rax
double v28; // [rsp+0h] [rbp-118h]
__int64 v29; // [rsp+0h] [rbp-118h]
double v30; // [rsp+8h] [rbp-110h]
int v31; // [rsp+8h] [rbp-110h]
double v32; // [rsp+8h] [rbp-110h]
__int64 v33; // [rsp+10h] [rbp-108h]
int v34; // [rsp+18h] [rbp-100h]
_DWORD *v35; // [rsp+18h] [rbp-100h]
_QWORD *v36; // [rsp+20h] [rbp-F8h]
double v37; // [rsp+28h] [rbp-F0h]
double v38; // [rsp+30h] [rbp-E8h]
int v39; // [rsp+38h] [rbp-E0h]
struct timeval v40; // [rsp+40h] [rbp-D8h] BYREF
struct timeval v41; // [rsp+50h] [rbp-C8h] BYREF
struct timeval v42; // [rsp+60h] [rbp-B8h] BYREF
struct timeval v43; // [rsp+70h] [rbp-A8h] BYREF
struct timeval v44; // [rsp+80h] [rbp-98h] BYREF
struct timeval v45; // [rsp+90h] [rbp-88h] BYREF
struct timeval v46; // [rsp+A0h] [rbp-78h] BYREF
struct timeval v47; // [rsp+B0h] [rbp-68h] BYREF
struct timeval v48; // [rsp+C0h] [rbp-58h] BYREF
struct timeval tv; // [rsp+D0h] [rbp-48h] BYREF

container_vol_init();
jobcount_init();
gettimeofday(&tv, 0LL);
v0 = (_QWORD *)index_init();
v36 = v0;
v1 = *(_DWORD *)(*v0 + 16LL);
if ( !v1 )
{
v33 = 0LL;
v2 = 0;
v28 = 0.0;
v30 = 0.0;
v38 = 0.0;
v37 = 0.0;
goto LABEL_3;
}
v5 = phf_init(v1);
gettimeofday(&v47, 0LL);
for ( i = htable_get_first(*v0); i; i = htable_get_next(*v0) )
phf_input(v5, i);
phf_walk(v5, i);
phf_build(v5);
gettimeofday(&v46, 0LL);
v37 = (double)(LODWORD(v46.tv_usec) - LODWORD(v47.tv_usec)) / 1000000.0
+ (double)(LODWORD(v46.tv_sec) - LODWORD(v47.tv_sec))
+ 0.0;
gettimeofday(&v45, 0LL);
v31 = 1;
v7 = 0;
v8 = 0x7FFFFFFF;
while ( (int)jobcount_max() >= v31 )
{
v17 = jobv_open((unsigned int)v31);
v29 = v17;
if ( v17 )
{
v18 = *(_DWORD *)(v17 + 4);
if ( v18 )
{
if ( v18 == 1 )
{
while ( 1 )
{
v15 = jobv_search_next_recipe(v29);
v16 = v15;
if ( !v15 )
break;
if ( G_VERBOSE )
printf("track deleted file %s \n", (const char *)(v15 + 8));
for ( j = *(_QWORD *)(v16 + 264); j; j = *(_QWORD *)(j + 40) )
{
v13 = htable_lookup(*v36, j);
if ( v13 )
{
v14 = *(_DWORD *)(v13 + 20);
if ( v8 > v14 )
v8 = v14;
if ( v7 < v14 )
v7 = v14;
}
else
{
err_msg("delete.c", 81LL, "maybe wrong");
}
}
recipe_free(v16);
}
*(_DWORD *)(v29 + 4) = 2;
}
}
else
{
while ( 1 )
{
v10 = jobv_search_next_recipe(v29);
v11 = v10;
if ( !v10 )
break;
if ( G_VERBOSE )
printf("track file %s \n", (const char *)(v10 + 8));
for ( k = *(_QWORD *)(v11 + 264); k; k = *(_QWORD *)(k + 40) )
phf_mark(v5, k);
recipe_free(v11);
}
}
jobv_destroy(v29);
}
++v31;
}
gettimeofday(&v44, 0LL);
v38 = (double)(LODWORD(v44.tv_usec) - LODWORD(v45.tv_usec)) / 1000000.0
+ (double)(LODWORD(v44.tv_sec) - LODWORD(v45.tv_sec))
+ 0.0;
container_vol_max_num();
if ( v8 >= v7 )
{
puts("******no job is deleted ");
if ( v8 != v7 )
{
v33 = 0LL;
v2 = 0;
v28 = 0.0;
v30 = 0.0;
goto LABEL_59;
}
}
else
{
printf("****** scan container id from %d to %d \n", (unsigned int)v8, (unsigned int)v7);
}
v33 = 0LL;
v19 = 0;
v28 = 0.0;
v30 = 0.0;
v39 = v7;
do
{
gettimeofday(&v43, 0LL);
v23 = read_container((unsigned int)v8);
v24 = (unsigned int *)v23;
if ( v23 )
{
v20 = htable_get_first(*(_QWORD *)(v23 + 16));
if ( v20 )
{
v21 = 0;
v34 = v8;
v22 = v33;
do
{
if ( !(unsigned int)phf_search(v5, v20 + 12) )
{
*(_DWORD *)(v20 + 8) = -1;
++v21;
++v19;
v22 += *(int *)(v20 + 4);
}
v20 = htable_get_next(*((_QWORD *)v24 + 2));
}
while ( v20 );
v33 = v22;
v8 = v34;
gettimeofday(&v42, 0LL);
v32 = (double)(LODWORD(v42.tv_usec) - LODWORD(v43.tv_usec)) / 1000000.0
+ (double)(LODWORD(v42.tv_sec) - LODWORD(v43.tv_sec))
+ v30;
gettimeofday(&v41, 0LL);
if ( v24[2] != v21 )
{
if ( v21 > 0 )
{
v35 = (_DWORD *)container_init();
for ( l = (int *)htable_get_first(*((_QWORD *)v24 + 2)); l; l = (int *)htable_get_next(*((_QWORD *)v24 + 2)) )
{
if ( l[2] <= 0 )
{
htable_remove(*v36, l + 3);
}
else
{
v26 = (int *)chunk_new(l + 3, *((_QWORD *)v24 + 3) + *l, (unsigned int)l[1]);
if ( *(_BYTE *)(*((_QWORD *)v24 + 3) + *l + *v26) != 9 )
err_msg("delete.c", 138LL, "container has been corrupted.");
if ( !(unsigned int)write_chunk(v35, v26) )
err_msg("delete.c", 140LL, " write chunk into new container wrong");
}
}
*v35 = *v24;
write_container(v35);
container_usage(v35);
container_destroy(v35);
}
goto LABEL_43;
}
}
else
{
gettimeofday(&v42, 0LL);
v32 = (double)(LODWORD(v42.tv_usec) - LODWORD(v43.tv_usec)) / 1000000.0
+ (double)(LODWORD(v42.tv_sec) - LODWORD(v43.tv_sec))
+ v30;
gettimeofday(&v41, 0LL);
if ( v24[2] )
{
LABEL_43:
gettimeofday(&v40, 0LL);
v28 = (double)(LODWORD(v40.tv_usec) - LODWORD(v41.tv_usec)) / 1000000.0
+ (double)(LODWORD(v40.tv_sec) - LODWORD(v41.tv_sec))
+ v28;
gettimeofday(&v43, 0LL);
container_destroy(v24);
gettimeofday(&v42, 0LL);
v30 = (double)(LODWORD(v42.tv_usec) - LODWORD(v43.tv_usec)) / 1000000.0
+ (double)(LODWORD(v42.tv_sec) - LODWORD(v43.tv_sec))
+ v32;
goto LABEL_44;
}
}
container_free(*v24);
for ( m = htable_get_first(*((_QWORD *)v24 + 2)); m; m = htable_get_next(*((_QWORD *)v24 + 2)) )
htable_remove(*v36, m + 12);
goto LABEL_43;
}
LABEL_44:
++v8;
}
while ( v39 >= v8 );
v2 = v19;
LABEL_59:
phf_destory(v5);
LABEL_3:
index_destroy(v36);
gettimeofday(&v48, 0LL);
v3 = (double)(LODWORD(v48.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v48.tv_sec) - LODWORD(tv.tv_sec))
+ 0.0;
jobcount_close();
container_vol_destroy();
printf("delete nume:%d \n", v2);
printf("delete size:%d \n", v33);
return printf("%10.3f \n%10.3f \n%10.3f \n%10.3f \n%10.3f \n", v3, v37, v38, v30, v28);
}

original_code:
void sanitization(){
  Recipe *rp=((void *)0);
  FingerChunk *fc=((void *)0);
  Container *ca=((void *)0);
  ChunkAddr *cdr=((void *)0);
  Chunk *chunk=((void *)0);
  struct timeval start,end;
  struct timeval b_start,b_end;
  struct timeval m_start,m_end;
  struct timeval s_start,s_end;
  struct timeval c_start,c_end;
  double g_time=0;
  double b_time=0;
  double m_time=0;
  double s_time=0;
  double c_time=0;
  int container_min=2147483647;
  int container_max=0;
  int delete_num=0;
  int64_t delete_size=0;
  int i;
  ContainerAddr *caddr;
  MemIndex * Gindex=((void *)0);
  JOB_V *jobv;
  container_vol_init();
  jobcount_init();
  PHF *phf;
       gettimeofday(&start, ((void *)0));
  Gindex=index_init();
  if(Gindex->index_table->num_items<=0)
   goto FAIL;
  phf=phf_init(Gindex->index_table->num_items);
  gettimeofday(&b_start, ((void *)0));
  for((*((void **)&(caddr))=(void *)(htable_get_first((Gindex->index_table)))); (caddr); (*((void **)&(caddr))=(void *)(htable_get_next(Gindex->index_table)))){
   phf_input(phf,caddr->hash);
  }
  phf_walk(phf);
  phf_build(phf);
  gettimeofday(&b_end, ((void *)0));
  (b_time)+=(b_end.tv_usec-b_start.tv_usec)*1.0/1000000+(b_end.tv_sec-b_start.tv_sec);
  gettimeofday(&m_start, ((void *)0));
  for(i=1;i<=jobcount_max();i++){
   jobv=jobv_open(i);
   if(jobv){
    if(!jobv->isDel){
     while((rp=jobv_search_next_recipe(jobv))){
      if(G_VERBOSE)
         printf("track file %s \n",rp->filename);
      for(fc=rp->first;fc;fc=fc->next){
       phf_mark(phf,fc->fingerprint);
      }
      recipe_free(rp);
     }
    }
    else if(jobv->isDel==1){
     while((rp=jobv_search_next_recipe(jobv))){
      if(G_VERBOSE)
         printf("track deleted file %s \n",rp->filename);
      for(fc=rp->first;fc;fc=fc->next){
       caddr=(ContainerAddr *)htable_lookup(Gindex->index_table,fc->fingerprint);
       if(!caddr){
        err_msg("delete.c",81,"maybe wrong");
        continue;
       }
       if(container_min>caddr->container_id)
        container_min=caddr->container_id;
       if(container_max<caddr->container_id)
        container_max=caddr->container_id;
      }
      recipe_free(rp);
     }
     jobv->isDel=2;
    }
    jobv_destroy(jobv);
   }
  }
  gettimeofday(&m_end, ((void *)0));
  (m_time)+=(m_end.tv_usec-m_start.tv_usec)*1.0/1000000+(m_end.tv_sec-m_start.tv_sec);
  int dead=0;
  int max_container_num=container_vol_max_num();
  if(container_min<container_max)
   printf("****** scan container id from %d to %d \n",container_min,container_max);
  else
   printf("******no job is  deleted \n");
  for(i=container_min;i<=container_max;i++){
   gettimeofday(&s_start, ((void *)0));
   ca=read_container(i);
   if(!ca)
    continue;
   dead=0;
   for((*((void **)&(cdr))=(void *)(htable_get_first((ca->meta_table)))); (cdr); (*((void **)&(cdr))=(void *)(htable_get_next(ca->meta_table)))){
    if(!phf_search(phf,cdr->hash)){
     cdr->container_id=-1;
     dead++;
     delete_num++;
     delete_size+=cdr->length;
    }
   }
   gettimeofday(&s_end, ((void *)0));
   (s_time)+=(s_end.tv_usec-s_start.tv_usec)*1.0/1000000+(s_end.tv_sec-s_start.tv_sec);
   gettimeofday(&c_start, ((void *)0));
   if(dead==ca->chunk_num){
    container_free(ca->container_id);
    for((*((void **)&(cdr))=(void *)(htable_get_first((ca->meta_table)))); (cdr); (*((void **)&(cdr))=(void *)(htable_get_next(ca->meta_table)))){
     htable_remove(Gindex->index_table,cdr->hash);
    }
   }
   else if(dead>0){
    Container * newca=container_init();
    for((*((void **)&(cdr))=(void *)(htable_get_first((ca->meta_table)))); (cdr); (*((void **)&(cdr))=(void *)(htable_get_next(ca->meta_table)))){
     if(cdr->container_id>0){
        chunk =chunk_new( cdr->hash,ca->data_buffer+cdr->offset,cdr->length);
           if(*(ca->data_buffer+cdr->offset+chunk->length) != '\t')
             err_msg("delete.c",138,"container has been corrupted.");
       if( write_chunk(newca,chunk)==0)
        err_msg("delete.c",140," write chunk into new container  wrong");
     }
     else{
      htable_remove(Gindex->index_table,cdr->hash);
     }
    }
     newca->container_id=ca->container_id;
    write_container(newca);
    container_usage(newca);
    container_destroy(newca);
   }
   else {
   }
   gettimeofday(&c_end, ((void *)0));
   (c_time)+=(c_end.tv_usec-c_start.tv_usec)*1.0/1000000+(c_end.tv_sec-c_start.tv_sec);
   gettimeofday(&s_start, ((void *)0));
    container_destroy(ca);
   gettimeofday(&s_end, ((void *)0));
   (s_time)+=(s_end.tv_usec-s_start.tv_usec)*1.0/1000000+(s_end.tv_sec-s_start.tv_sec);
  }
  phf_destory( phf);
 FAIL:
  index_destroy(Gindex);
  gettimeofday(&end, ((void *)0));
  (g_time)+=(end.tv_usec-start.tv_usec)*1.0/1000000+(end.tv_sec-start.tv_sec);
  jobcount_close();
  container_vol_destroy();
  printf("delete nume:%d \n",delete_num);
  printf("delete size:%d \n",delete_size);
  printf("%10.3f \n%10.3f \n%10.3f \n%10.3f \n%10.3f \n",g_time,b_time,m_time,s_time,c_time);
}

canonical_original_code:
void sanitization(){
  struct recipe_tag *rp = ((void *)0);
  struct finger_chunk_tag *fc = ((void *)0);
  struct container_tag *ca = ((void *)0);
  struct chunk_address *cdr = ((void *)0);
  struct chunk_tag *chunk = ((void *)0);
  struct timeval start; struct timeval end;
  struct timeval b_start; struct timeval b_end;
  struct timeval m_start; struct timeval m_end;
  struct timeval s_start; struct timeval s_end;
  struct timeval c_start; struct timeval c_end;
  double g_time = 0;
  double b_time = 0;
  double m_time = 0;
  double s_time = 0;
  double c_time = 0;
  int container_min = 2147483647;
  int container_max = 0;
  int delete_num = 0;
  long delete_size = 0;
  int i;
  struct container_index *caddr;
  struct mem_index *Gindex = ((void *)0);
  struct job_des *jobv;
  container_vol_init();
  jobcount_init();
  struct PHF *phf;
       gettimeofday(&start, ((void *)0));
  Gindex=index_init();
  if(Gindex->index_table->num_items<=0)
   goto FAIL;
  phf=phf_init(Gindex->index_table->num_items);
  gettimeofday(&b_start, ((void *)0));
  for((*((void **)&(caddr))=(void *)(htable_get_first((Gindex->index_table)))); (caddr); (*((void **)&(caddr))=(void *)(htable_get_next(Gindex->index_table)))){
   phf_input(phf,caddr->hash);
  }
  phf_walk(phf);
  phf_build(phf);
  gettimeofday(&b_end, ((void *)0));
  (b_time)+=(b_end.tv_usec-b_start.tv_usec)*1.0/1000000+(b_end.tv_sec-b_start.tv_sec);
  gettimeofday(&m_start, ((void *)0));
  for(i=1;i<=jobcount_max();i++){
   jobv=jobv_open(i);
   if(jobv){
    if(!jobv->isDel){
     while((rp=jobv_search_next_recipe(jobv))){
      if(G_VERBOSE)
         printf("track file %s \n",rp->filename);
      for(fc=rp->first;fc;fc=fc->next){
       phf_mark(phf,fc->fingerprint);
      }
      recipe_free(rp);
     }
    }
    else if(jobv->isDel==1){
     while((rp=jobv_search_next_recipe(jobv))){
      if(G_VERBOSE)
         printf("track deleted file %s \n",rp->filename);
      for(fc=rp->first;fc;fc=fc->next){
       caddr=(struct container_index *)htable_lookup(Gindex->index_table,fc->fingerprint);
       if(!caddr){
        err_msg("delete.c",81,"maybe wrong");
        continue;
       }
       if(container_min>caddr->container_id)
        container_min=caddr->container_id;
       if(container_max<caddr->container_id)
        container_max=caddr->container_id;
      }
      recipe_free(rp);
     }
     jobv->isDel=2;
    }
    jobv_destroy(jobv);
   }
  }
  gettimeofday(&m_end, ((void *)0));
  (m_time)+=(m_end.tv_usec-m_start.tv_usec)*1.0/1000000+(m_end.tv_sec-m_start.tv_sec);
  int dead = 0;
  int max_container_num = container_vol_max_num();
  if(container_min<container_max)
   printf("****** scan container id from %d to %d \n",container_min,container_max);
  else
   printf("******no job is  deleted \n");
  for(i=container_min;i<=container_max;i++){
   gettimeofday(&s_start, ((void *)0));
   ca=read_container(i);
   if(!ca)
    continue;
   dead=0;
   for((*((void **)&(cdr))=(void *)(htable_get_first((ca->meta_table)))); (cdr); (*((void **)&(cdr))=(void *)(htable_get_next(ca->meta_table)))){
    if(!phf_search(phf,cdr->hash)){
     cdr->container_id=-1;
     dead++;
     delete_num++;
     delete_size+=cdr->length;
    }
   }
   gettimeofday(&s_end, ((void *)0));
   (s_time)+=(s_end.tv_usec-s_start.tv_usec)*1.0/1000000+(s_end.tv_sec-s_start.tv_sec);
   gettimeofday(&c_start, ((void *)0));
   if(dead==ca->chunk_num){
    container_free(ca->container_id);
    for((*((void **)&(cdr))=(void *)(htable_get_first((ca->meta_table)))); (cdr); (*((void **)&(cdr))=(void *)(htable_get_next(ca->meta_table)))){
     htable_remove(Gindex->index_table,cdr->hash);
    }
   }
   else if(dead>0){
    struct container_tag *newca = container_init();
    for((*((void **)&(cdr))=(void *)(htable_get_first((ca->meta_table)))); (cdr); (*((void **)&(cdr))=(void *)(htable_get_next(ca->meta_table)))){
     if(cdr->container_id>0){
        chunk =chunk_new( cdr->hash,ca->data_buffer+cdr->offset,cdr->length);
           if(*(ca->data_buffer+cdr->offset+chunk->length) != '\t')
             err_msg("delete.c",138,"container has been corrupted.");
       if( write_chunk(newca,chunk)==0)
        err_msg("delete.c",140," write chunk into new container  wrong");
     }
     else{
      htable_remove(Gindex->index_table,cdr->hash);
     }
    }
     newca->container_id=ca->container_id;
    write_container(newca);
    container_usage(newca);
    container_destroy(newca);
   }
   else {
   }
   gettimeofday(&c_end, ((void *)0));
   (c_time)+=(c_end.tv_usec-c_start.tv_usec)*1.0/1000000+(c_end.tv_sec-c_start.tv_sec);
   gettimeofday(&s_start, ((void *)0));
    container_destroy(ca);
   gettimeofday(&s_end, ((void *)0));
   (s_time)+=(s_end.tv_usec-s_start.tv_usec)*1.0/1000000+(s_end.tv_sec-s_start.tv_sec);
  }
  phf_destory( phf);
 FAIL:
  index_destroy(Gindex);
  gettimeofday(&end, ((void *)0));
  (g_time)+=(end.tv_usec-start.tv_usec)*1.0/1000000+(end.tv_sec-start.tv_sec);
  jobcount_close();
  container_vol_destroy();
  printf("delete nume:%d \n",delete_num);
  printf("delete size:%d \n",delete_size);
  printf("%10.3f \n%10.3f \n%10.3f \n%10.3f \n%10.3f \n",g_time,b_time,m_time,s_time,c_time);
}

variable_types: struct finger_chunk_tag { unsigned char fingerprint[20]; long offset; int length; char existed; struct finger_chunk_tag *next; } *

variable_types: struct container_tag { int container_id; int data_size; int chunk_num; struct htable_t { struct hlink_t { void *next; unsigned int hash; unsigned char *key; } **table; int loffset; int keylen; unsigned int num_items; unsigned int max_items; unsigned int grow_count; unsigned int replace_count; unsigned int buckets; unsigned int hash; unsigned int index; unsigned int mask; unsigned int rshift; struct hlink_t *walkptr; unsigned int walk_index; } *meta_table; unsigned char *data_buffer; struct hlink_t next; } *

variable_types: struct chunk_address { int offset; int length; int container_id; unsigned char hash[20]; struct hlink_t { void *next; unsigned int hash; unsigned char *key; } next; } *

variable_types: struct chunk_tag { int length; unsigned char hash[20]; unsigned char *data; } *

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: i int

variable_types: struct container_index { unsigned char hash[20]; int container_id; struct hlink_t { void *next; unsigned int hash; unsigned char *key; } next; } *

variable_types: struct mem_index { struct htable_t { struct hlink_t { void *next; unsigned int hash; unsigned char *key; } **table; int loffset; int keylen; unsigned int num_items; unsigned int max_items; unsigned int grow_count; unsigned int replace_count; unsigned int buckets; unsigned int hash; unsigned int index; unsigned int mask; unsigned int rshift; struct hlink_t *walkptr; unsigned int walk_index; } *index_table; struct htable_t *index_new; struct lru_cache { int item_count; int hit; int miss; struct htable_t *htable; struct DList { struct node_t { void *data; struct node_t *prev; struct node_t *next; } *head; struct node_t *tail; int size; } *plist; } *index_cache; struct htable_t *container_cache; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *

variable_types: struct job_des { int nJobId; int isDel; char szBackupPath[256]; int nFileNum; int fd; } *

variable_types: struct PHF { long finger_num; long bucket_num; long vector_num; struct Bucket { int index; int size; struct FP { unsigned char hash[21]; struct FP *next; } *data; } *B; unsigned short *D; unsigned char *T; unsigned int (*g_hash)(char *str); unsigned int (*f1_hash)(char *str); unsigned int (*f2_hash)(char *str); } *

variable_types: dead int

user_defined_types: struct recipe_tag { int fileindex; int chunknum; char filename[256]; struct finger_chunk_tag *first; struct finger_chunk_tag *last; }

user_defined_types: struct chunk_address { int offset; int length; int container_id; unsigned char hash[20]; struct hlink_t next; }

user_defined_types: struct container_index { unsigned char hash[20]; int container_id; struct hlink_t next; }

user_defined_types: struct PHF { long finger_num; long bucket_num; long vector_num; struct Bucket *B; unsigned short *D; unsigned char *T; unsigned int (*g_hash)(char *str); unsigned int (*f1_hash)(char *str); unsigned int (*f2_hash)(char *str); }

user_defined_types: struct Bucket { int index; int size; struct FP *data; }


repo: zhoupj/Deduper

decompiled_code:
__int64 __fastcall delete_job(unsigned int a1, __int64 a2)
{
unsigned int *v2; // rbx
__int64 v4; // rax
size_t v5; // rax
_QWORD v6[6]; // [rsp+0h] [rbp-58h] BYREF
__int16 v7; // [rsp+30h] [rbp-28h]

v2 = (unsigned int *)jcr_new();
v6[0] = 19279LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v7 = 0;
if ( (unsigned int)_isoc99_sscanf(a2, &delete_cmd, v2) != 1 )
return err_msg("delete.c", 189LL, "delete cmd wrong");
printf("delete job %d \n", *v2);
v4 = jobv_open(*v2);
*((_QWORD *)v2 + 70) = v4;
if ( v4 )
{
if ( *(_DWORD *)(v4 + 4) )
strcpy((char *)v6, "This job has been deleted before");
else
*(_DWORD *)(v4 + 4) = 1;
}
jobv_destroy(*((_QWORD *)v2 + 70));
v5 = strlen((const char *)v6);
bnet_send(a1, v6, v5);
return jcr_free(v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
unsigned int *v2; // rbx
__int64 v4; // rax
size_t v5; // rax
_QWORD v6[6]; // [rsp+0h] [rbp-58h] BYREF
__int16 v7; // [rsp+30h] [rbp-28h]

v2 = (unsigned int *)jcr_new();
v6[0] = 19279LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v7 = 0;
if ( (unsigned int)_isoc99_sscanf(a2, &delete_cmd, v2) != 1 )
return err_msg("delete.c", 189LL, "delete cmd wrong");
printf("delete job %d \n", *v2);
v4 = jobv_open(*v2);
*((_QWORD *)v2 + 70) = v4;
if ( v4 )
{
if ( *(_DWORD *)(v4 + 4) )
strcpy((char *)v6, "This job has been deleted before");
else
*(_DWORD *)(v4 + 4) = 1;
}
jobv_destroy(*((_QWORD *)v2 + 70));
v5 = strlen((const char *)v6);
bnet_send(a1, v6, v5);
return jcr_free(v2);
}

original_code:
void delete_job(int fd,char *msg){
   int deleted=0;
   JCR *jcr=((void *)0);
   jcr=jcr_new();
   char buf[50]={0};
   strcpy(buf,"OK");
   if(sscanf(msg,delete_cmd,&jcr->nJobId)!=1){
    err_msg("delete.c",189,"delete cmd wrong");
    return;
   }
   printf("delete job %d \n",jcr->nJobId);
   jcr->jobv=jobv_open(jcr->nJobId);
   if(jcr->jobv){
    if(jcr->jobv->isDel)
     strcpy(buf,"This job has been deleted before");
    else
     jcr->jobv->isDel=1;
   }
   jobv_destroy(jcr->jobv);
   bnet_send(fd,buf,strlen(buf));
   jcr_free(jcr);
}

canonical_original_code:
void delete_job(int fd, char *msg){
   int deleted = 0;
   struct jcr *jcr = ((void *)0);
   jcr=jcr_new();
   char buf[50] = {0};
   strcpy(buf,"OK");
   if(sscanf(msg,delete_cmd,&jcr->nJobId)!=1){
    err_msg("delete.c",189,"delete cmd wrong");
    return;
   }
   printf("delete job %d \n",jcr->nJobId);
   jcr->jobv=jobv_open(jcr->nJobId);
   if(jcr->jobv){
    if(jcr->jobv->isDel)
     strcpy(buf,"This job has been deleted before");
    else
     jcr->jobv->isDel=1;
   }
   jobv_destroy(jcr->jobv);
   bnet_send(fd,buf,strlen(buf));
   jcr_free(jcr);
}

variable_types: fd int

variable_types:
msg
char *

variable_types: deleted int

variable_types: struct jcr { int nJobId; int dataSocket; int fingerSocket; char szBackupPath[256]; char szRestorePath[256]; int nFileCount; long nSize; long nDedupSize; long nRecvSize; int nChunkCount; int nDedupChunkCount; struct job_des { int nJobId; int isDel; char szBackupPath[256]; int nFileNum; int fd; } *jobv; struct mem_index { struct htable_t { struct hlink_t { void *next; unsigned int hash; unsigned char *key; } **table; int loffset; int keylen; unsigned int num_items; unsigned int max_items; unsigned int grow_count; unsigned int replace_count; unsigned int buckets; unsigned int hash; unsigned int index; unsigned int mask; unsigned int rshift; struct hlink_t *walkptr; unsigned int walk_index; } *index_table; struct htable_t *index_new; struct lru_cache { int item_count; int hit; int miss; struct htable_t *htable; struct DList { struct node_t { void *data; struct node_t *prev; struct node_t *next; } *head; struct node_t *tail; int size; } *plist; } *index_cache; struct htable_t *container_cache; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *memIndex; struct container_tag { int container_id; int data_size; int chunk_num; struct htable_t *meta_table; unsigned char *data_buffer; struct hlink_t next; } *container; double searchTime; double writeDataTime; double writeRecipeTime; double recvTime; double totalTime; } *

variable_types:
buf
char [50]

return_type: void

user_defined_types: struct jcr { int nJobId; int dataSocket; int fingerSocket; char szBackupPath[256]; char szRestorePath[256]; int nFileCount; long nSize; long nDedupSize; long nRecvSize; int nChunkCount; int nDedupChunkCount; struct job_des *jobv; struct mem_index *memIndex; struct container_tag *container; double searchTime; double writeDataTime; double writeRecipeTime; double recvTime; double totalTime; }

user_defined_types: struct mem_index { struct htable_t *index_table; struct htable_t *index_new; struct lru_cache *index_cache; struct htable_t *container_cache; union pthread_mutex_t mutex; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct htable_t { struct hlink_t **table; int loffset; int keylen; unsigned int num_items; unsigned int max_items; unsigned int grow_count; unsigned int replace_count; unsigned int buckets; unsigned int hash; unsigned int index; unsigned int mask; unsigned int rshift; struct hlink_t *walkptr; unsigned int walk_index; }

user_defined_types: struct lru_cache { int item_count; int hit; int miss; struct htable_t *htable; struct DList *plist; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct DList { struct node_t *head; struct node_t *tail; int size; }


decompiled_code:
int __fastcall local_delete_job(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
__int64 v7; // rbp
__int64 v8; // rax
_QWORD v10[6]; // [rsp+0h] [rbp-58h] BYREF
__int16 v11; // [rsp+30h] [rbp-28h]

v10[1] = 6778479LL;
v10[2] = 0LL;
v10[3] = 0LL;
v10[4] = 0LL;
v10[5] = 0LL;
v11 = 0;
v6 = jcr_new(a1, a2, a3, a4, a5, a6, 0x7277207972726F73LL);
if ( (int)a1 <= 0 )
return err_msg("delete.c", 215LL, "delete cmd wrong");
v7 = v6;
printf("delete job %d \n", (unsigned int)a1);
v8 = jobv_open((unsigned int)a1);
*(_QWORD *)(v7 + 560) = v8;
if ( v8 )
{
if ( *(_DWORD *)(v8 + 4) )
{
strcpy((char *)v10, "This job has been deleted before");
}
else
{
*(_DWORD *)(v8 + 4) = 1;
strcpy((char *)v10, "OK deleted it");
}
}
jobv_destroy(*(_QWORD *)(v7 + 560));
jcr_free(v7);
return printf("========%s \n", (const char *)v10);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
__int64 v7; // rbp
__int64 v8; // rax
_QWORD v10[6]; // [rsp+0h] [rbp-58h] BYREF
__int16 v11; // [rsp+30h] [rbp-28h]

v10[1] = 6778479LL;
v10[2] = 0LL;
v10[3] = 0LL;
v10[4] = 0LL;
v10[5] = 0LL;
v11 = 0;
v6 = jcr_new(a1, a2, a3, a4, a5, a6, 0x7277207972726F73LL);
if ( (int)a1 <= 0 )
return err_msg("delete.c", 215LL, "delete cmd wrong");
v7 = v6;
printf("delete job %d \n", (unsigned int)a1);
v8 = jobv_open((unsigned int)a1);
*(_QWORD *)(v7 + 560) = v8;
if ( v8 )
{
if ( *(_DWORD *)(v8 + 4) )
{
strcpy((char *)v10, "This job has been deleted before");
}
else
{
*(_DWORD *)(v8 + 4) = 1;
strcpy((char *)v10, "OK deleted it");
}
}
jobv_destroy(*(_QWORD *)(v7 + 560));
jcr_free(v7);
return printf("========%s \n", (const char *)v10);
}

original_code:
void local_delete_job(int jobid){
   int deleted=0;
   JCR *jcr=((void *)0);
   char buf[50]={0};
   strcpy(buf,"sorry wrong");
   jcr=jcr_new();
   if(jobid<=0){
    err_msg("delete.c",215,"delete cmd wrong");
    return;
   }
   printf("delete job %d \n",jobid);
   jcr->jobv=jobv_open(jobid);
   if(jcr->jobv){
    if(jcr->jobv->isDel)
     strcpy(buf,"This job has been deleted before");
    else {
     jcr->jobv->isDel=1;
     strcpy(buf,"OK deleted it");
    }
   }
   jobv_destroy(jcr->jobv);
   jcr_free(jcr);
   printf("========%s \n",buf);
}

canonical_original_code:
void local_delete_job(int jobid){
   int deleted = 0;
   struct jcr *jcr = ((void *)0);
   char buf[50] = {0};
   strcpy(buf,"sorry wrong");
   jcr=jcr_new();
   if(jobid<=0){
    err_msg("delete.c",215,"delete cmd wrong");
    return;
   }
   printf("delete job %d \n",jobid);
   jcr->jobv=jobv_open(jobid);
   if(jcr->jobv){
    if(jcr->jobv->isDel)
     strcpy(buf,"This job has been deleted before");
    else {
     jcr->jobv->isDel=1;
     strcpy(buf,"OK deleted it");
    }
   }
   jobv_destroy(jcr->jobv);
   jcr_free(jcr);
   printf("========%s \n",buf);
}

variable_types: jobid int

user_defined_types: struct job_des { int nJobId; int isDel; char szBackupPath[256]; int nFileNum; int fd; }

user_defined_types: struct container_tag { int container_id; int data_size; int chunk_num; struct htable_t *meta_table; unsigned char *data_buffer; struct hlink_t next; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct hlink_t { void *next; unsigned int hash; unsigned char *key; }

user_defined_types: struct node_t { void *data; struct node_t *prev; struct node_t *next; }


decompiled_code:
__int64 __fastcall simple_hash(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
int v2; // ecx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v2 = v1 + 31 * v2;
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
int v2; // ecx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v2 = v1 + 31 * v2;
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 & 0x7FFFFFFF;
}

original_code:
unsigned int simple_hash(char *str)
{
 register unsigned int hash;
 register unsigned char *p;
 for(hash = 0, p = (unsigned char *)str; *p ; p++)
  hash = 31 * hash + *p;
 return (hash & 0x7FFFFFFF);
}

variable_types:
str
char *

variable_types:
hash
unsigned int

variable_types:
p
unsigned char *

return_type: unsigned int


original_code:
unsigned int RS_hash(char *str)
{
         unsigned int b = 378551;
         unsigned int a = 63689;
         unsigned int hash = 0;
         while (*str)
         {
                 hash = hash * a + (*str++);
                 a *= b;
         }
         return (hash & 0x7FFFFFFF);
}

variable_types:
b
unsigned int

variable_types:
a
unsigned int


original_code:
unsigned int JS_hash(char *str)
{
         unsigned int hash = 1315423911;
         while (*str)
         {
                 hash ^= ((hash << 5) + (*str++) + (hash >> 2));
         }
         return (hash & 0x7FFFFFFF);
}


original_code:
unsigned int PJW_hash(char *str)
{
         unsigned int BitsInUnignedInt = (unsigned int)(sizeof(unsigned int) * 8);
         unsigned int ThreeQuarters = (unsigned int)((BitsInUnignedInt * 3) / 4);
         unsigned int OneEighth = (unsigned int)(BitsInUnignedInt / 8);
         unsigned int HighBits = (unsigned int)(0xFFFFFFFF) << (BitsInUnignedInt - OneEighth);
         unsigned int hash = 0;
         unsigned int test = 0;
         while (*str)
         {
                 hash = (hash << OneEighth) + (*str++);
                 if ((test = hash & HighBits) != 0)
                 {
                         hash = ((hash ^ (test >> ThreeQuarters)) & (~HighBits));
                 }
         }
         return (hash & 0x7FFFFFFF);
}

variable_types:
BitsInUnignedInt
unsigned int

variable_types:
ThreeQuarters
unsigned int

variable_types:
OneEighth
unsigned int

variable_types:
HighBits
unsigned int

variable_types:
test
unsigned int


original_code:
unsigned int ELF_hash(char *str)
{
         unsigned int hash = 0;
         unsigned int x = 0;
         while (*str)
         {
                 hash = (hash << 4) + (*str++);
                 if ((x = hash & 0xF0000000L) != 0)
                 {
                         hash ^= (x >> 24);
                         hash &= ~x;
                 }
         }
         return (hash & 0x7FFFFFFF);
}

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall BKDR_hash(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 & 0x7FFFFFFF;
}

original_code:
unsigned int BKDR_hash(char *str)
{
         unsigned int seed = 131;
         unsigned int hash = 0;
         while (*str)
         {
                 hash = hash * seed + (*str++);
         }
         return (hash & 0x7FFFFFFF);
}

variable_types:
seed
unsigned int


decompiled_code:
__int64 __fastcall SDBM_hash(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 65599 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 & 0x7FFFFFFF;
}

original_code:
unsigned int SDBM_hash(char *str)
{
         unsigned int hash = 0;
         while (*str)
         {
                 hash = (*str++) + (hash << 6) + (hash << 16) - hash;
         }
         return (hash & 0x7FFFFFFF);
}


original_code:
unsigned int DJB_hash(char *str)
{
         unsigned int hash = 5381;
         while (*str)
         {
                 hash += (hash << 5) + (*str++);
         }
         return (hash & 0x7FFFFFFF);
}


original_code:
unsigned int AP_hash(char *str)
{
         unsigned int hash = 0;
         int i;
         for (i=0; *str; i++)
         {
                 if ((i & 1) == 0)
                 {
                         hash ^= ((hash << 7) ^ (*str++) ^ (hash >> 3));
                 }
                 else
                 {
                         hash ^= (~((hash << 11) ^ (*str++) ^ (hash >> 5)));
                 }
         }
         return (hash & 0x7FFFFFFF);
}

variable_types: i int


decompiled_code:
__int64 __fastcall CRC_hash(const char *a1)
{
const char *v1; // rbx
unsigned int v2; // eax
unsigned int v3; // esi
unsigned int v4; // edi
const char *v5; // rcx
unsigned __int64 v6; // rax
unsigned int v7; // edx
unsigned __int16 v9; // [rsp+Eh] [rbp-Ah]

v1 = a1;
v2 = strlen(a1);
HIBYTE(v9) = 0;
if ( v2 <= 1 )
{
v7 = v2;
v5 = a1;
v6 = 0LL;
}
else
{
v3 = v2 - 2;
v4 = (v2 - 2) >> 1;
v5 = &v1[2 * v4 + 2];
v6 = 0LL;
do
{
v1 += 2;
v6 += *((unsigned __int16 *)v1 - 1);
}
while ( v1 != v5 );
v7 = v3 - 2 * v4;
}
if ( v7 == 1 )
{
LOBYTE(v9) = *v5;
v6 += v9;
}
return (unsigned __int16)~(v6 + WORD1(v6) + (((unsigned __int16)v6 + (unsigned int)(v6 >> 16)) >> 16));
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
const char *v1; // rbx
unsigned int v2; // eax
unsigned int v3; // esi
unsigned int v4; // edi
const char *v5; // rcx
unsigned __int64 v6; // rax
unsigned int v7; // edx
unsigned __int16 v9; // [rsp+Eh] [rbp-Ah]

v1 = a1;
v2 = strlen(a1);
HIBYTE(v9) = 0;
if ( v2 <= 1 )
{
v7 = v2;
v5 = a1;
v6 = 0LL;
}
else
{
v3 = v2 - 2;
v4 = (v2 - 2) >> 1;
v5 = &v1[2 * v4 + 2];
v6 = 0LL;
do
{
v1 += 2;
v6 += *((unsigned __int16 *)v1 - 1);
}
while ( v1 != v5 );
v7 = v3 - 2 * v4;
}
if ( v7 == 1 )
{
LOBYTE(v9) = *v5;
v6 += v9;
}
return (unsigned __int16)~(v6 + WORD1(v6) + (((unsigned __int16)v6 + (unsigned int)(v6 >> 16)) >> 16));
}

original_code:
unsigned int CRC_hash(char *str)
{
    unsigned int nleft = strlen(str);
    unsigned long long sum = 0;
    unsigned short int *w = (unsigned short int *)str;
    unsigned short int answer = 0;
    while ( nleft > 1 ) {
        sum += *w++;
        nleft -= 2;
    }
    if ( 1 == nleft ) {
        *( unsigned char * )( &answer ) = *( unsigned char * )w ;
        sum += answer;
    }
    sum = ( sum >> 16 ) + ( sum & 0xFFFF );
    sum += ( sum >> 16 );
    answer = ~sum;
    return (answer & 0xFFFFFFFF);
}

canonical_original_code:
unsigned int CRC_hash(char *str)
{
    unsigned int nleft = strlen(str);
    unsigned long long sum = 0;
    unsigned short *w = (unsigned short int *)str;
    unsigned short answer = 0;
    while ( nleft > 1 ) {
        sum += *w++;
        nleft -= 2;
    }
    if ( 1 == nleft ) {
        *( unsigned char * )( &answer ) = *( unsigned char * )w ;
        sum += answer;
    }
    sum = ( sum >> 16 ) + ( sum & 0xFFFF );
    sum += ( sum >> 16 );
    answer = ~sum;
    return (answer & 0xFFFFFFFF);
}

variable_types:
nleft
unsigned int

variable_types:
sum
unsigned long long

variable_types:
w
unsigned short *

variable_types:
answer
unsigned short


decompiled_code:
void __fastcall jcr_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void jcr_free(JCR* jcr) {
 free(jcr);
}

canonical_original_code:
void jcr_free(struct jcr *jcr) {
 free(jcr);
}

variable_types: struct jcr { int nJobId; int dataSocket; int fingerSocket; char szBackupPath[256]; char szRestorePath[256]; int nFileCount; long nSize; long nDedupSize; long nRecvSize; int nChunkCount; int nDedupChunkCount; struct job_des { int nJobId; int isDel; char szBackupPath[256]; int nFileNum; int fd; } *jobv; struct mem_index { struct htable_t { struct hlink_t { void *next; unsigned int hash; unsigned char *key; } **table; int loffset; int keylen; unsigned int num_items; unsigned int max_items; unsigned int grow_count; unsigned int replace_count; unsigned int buckets; unsigned int hash; unsigned int index; unsigned int mask; unsigned int rshift; struct hlink_t *walkptr; unsigned int walk_index; } *index_table; struct htable_t *index_new; struct lru_cache { int item_count; int hit; int miss; struct htable_t *htable; struct DList { struct node_t { void *data; struct node_t *prev; struct node_t *next; } *head; struct node_t *tail; int size; } *plist; } *index_cache; struct htable_t *container_cache; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *memIndex; struct container_tag { int container_id; int data_size; int chunk_num; struct htable_t *meta_table; unsigned char *data_buffer; struct hlink_t next; } *container; double searchTime; double writeDataTime; double writeRecipeTime; double recvTime; double totalTime; } *


decompiled_code:
__int64 __fastcall htable_get_size(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
uint32_t htable_get_size(htable *tbl)
{
   return tbl->num_items;
}

canonical_original_code:
unsigned int htable_get_size(struct htable_t *tbl)
{
   return tbl->num_items;
}

variable_types: struct htable_t { struct hlink_t { void *next; unsigned int hash; unsigned char *key; } **table; int loffset; int keylen; unsigned int num_items; unsigned int max_items; unsigned int grow_count; unsigned int replace_count; unsigned int buckets; unsigned int hash; unsigned int index; unsigned int mask; unsigned int rshift; struct hlink_t *walkptr; unsigned int walk_index; } *


decompiled_code:
int __fastcall htable_get_stats(__int64 a1)
{
int v1; // eax
_QWORD **v2; // rcx
__int64 v3; // rsi
int v4; // ebx
__int64 i; // rbp
int v7; // edx
_QWORD *v8; // rax
int v9[5]; // [rsp+0h] [rbp-38h]
unsigned int v10; // [rsp+14h] [rbp-24h]

puts("\n=====================htable stat======================");
printf("current counts: %u\n total counts: %u\n", *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
printf("total buckets: %u \n ", *(unsigned int *)(a1 + 32));
printf("grow table counts: %u\n", *(unsigned int *)(a1 + 24));
printf("replaced items counts: %u \n", *(unsigned int *)(a1 + 28));
puts("item_counts/bucket: buckets");
v9[0] = 0;
v9[1] = 0;
v9[2] = 0;
v9[3] = 0;
v9[4] = 0;
v10 = 0;
v1 = *(_DWORD *)(a1 + 32);
if ( v1 > 0 )
{
v2 = *(_QWORD ***)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
v4 = 0;
while ( 1 )
{
v8 = *v2;
if ( *v2 )
{
v7 = 0;
do
{
v8 = (_QWORD *)*v8;
++v7;
}
while ( v8 );
if ( v4 < v7 )
v4 = v7;
if ( v7 > 4 )
{
++v10;
goto LABEL_11;
}
}
else
{
if ( v4 < 0 )
v4 = 0;
v7 = 0;
}
++v9[v7];
LABEL_11:
if ( (_QWORD **)v3 == ++v2 )
goto LABEL_4;
}
}
v4 = 0;
LABEL_4:
for ( i = 0LL; i != 5; ++i )
printf("%2d: %d\n", (unsigned int)i, (unsigned int)v9[i]);
printf("more: %d\n", v10);
printf("max itme counts in a bucket : %d\n", (unsigned int)v4);
return puts("\n=====================htable stat======================");
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int v1; // eax
_QWORD **v2; // rcx
__int64 v3; // rsi
int v4; // ebx
__int64 i; // rbp
int v7; // edx
_QWORD *v8; // rax
int v9[5]; // [rsp+0h] [rbp-38h]
unsigned int v10; // [rsp+14h] [rbp-24h]

puts("\n=====================htable stat======================");
printf("current counts: %u\n total counts: %u\n", *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
printf("total buckets: %u \n ", *(unsigned int *)(a1 + 32));
printf("grow table counts: %u\n", *(unsigned int *)(a1 + 24));
printf("replaced items counts: %u \n", *(unsigned int *)(a1 + 28));
puts("item_counts/bucket: buckets");
v9[0] = 0;
v9[1] = 0;
v9[2] = 0;
v9[3] = 0;
v9[4] = 0;
v10 = 0;
v1 = *(_DWORD *)(a1 + 32);
if ( v1 > 0 )
{
v2 = *(_QWORD ***)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
v4 = 0;
while ( 1 )
{
v8 = *v2;
if ( *v2 )
{
v7 = 0;
do
{
v8 = (_QWORD *)*v8;
++v7;
}
while ( v8 );
if ( v4 < v7 )
v4 = v7;
if ( v7 > 4 )
{
++v10;
goto LABEL_11;
}
}
else
{
if ( v4 < 0 )
v4 = 0;
v7 = 0;
}
++v9[v7];
LABEL_11:
if ( (_QWORD **)v3 == ++v2 )
goto LABEL_4;
}
}
v4 = 0;
LABEL_4:
for ( i = 0LL; i != 5; ++i )
printf("%2d: %d\n", (unsigned int)i, (unsigned int)v9[i]);
printf("more: %d\n", v10);
printf("max itme counts in a bucket : %d\n", (unsigned int)v4);
return puts("\n=====================htable stat======================");
}

original_code:
void htable_get_stats(htable *tbl)
{
   int hits[4 +1+1];
   int max = 0;
   int i, j;
   hlink *p;
   printf("\n=====================htable stat======================\n");
   printf("current counts: %u\n total counts: %u\n", tbl->num_items, tbl->max_items);
   printf("total buckets: %u \n ",tbl->buckets);
   printf("grow table counts: %u\n",tbl->grow_count);
   printf("replaced items counts: %u \n",tbl->replace_count);
   printf("item_counts/bucket: buckets\n");
   for (i=0; i <= 4 +1; i++) {
      hits[i] = 0;
   }
   for (i=0; i<(int)tbl->buckets; i++) {
      p = tbl->table[i];
      j = 0;
      while (p) {
         p = (hlink *)(p->next);
         j++;
      }
      if (j > max) {
         max = j;
      }
      if (j <= 4) {
         hits[j]++;
      }
     else
   hits[4 +1]++;
   }
   for (i=0; i <=4; i++) {
      printf("%2d:           %d\n",i, hits[i]);
   }
      printf("more:           %d\n", hits[4 +1]);
   printf("max itme counts in a bucket : %d\n", max);
   printf("\n=====================htable stat======================\n");
}

canonical_original_code:
void htable_get_stats(struct htable_t *tbl)
{
   int hits[-1];
   int max = 0;
   int i; int j;
   struct hlink_t *p;
   printf("\n=====================htable stat======================\n");
   printf("current counts: %u\n total counts: %u\n", tbl->num_items, tbl->max_items);
   printf("total buckets: %u \n ",tbl->buckets);
   printf("grow table counts: %u\n",tbl->grow_count);
   printf("replaced items counts: %u \n",tbl->replace_count);
   printf("item_counts/bucket: buckets\n");
   for (i=0; i <= 4 +1; i++) {
      hits[i] = 0;
   }
   for (i=0; i<(int)tbl->buckets; i++) {
      p = tbl->table[i];
      j = 0;
      while (p) {
         p = (struct hlink_t *)(p->next);
         j++;
      }
      if (j > max) {
         max = j;
      }
      if (j <= 4) {
         hits[j]++;
      }
     else
   hits[4 +1]++;
   }
   for (i=0; i <=4; i++) {
      printf("%2d:           %d\n",i, hits[i]);
   }
      printf("more:           %d\n", hits[4 +1]);
   printf("max itme counts in a bucket : %d\n", max);
   printf("\n=====================htable stat======================\n");
}

variable_types:
hits
int [-1]

variable_types: max int

variable_types: j int

variable_types: struct hlink_t { void *next; unsigned int hash; unsigned char *key; } *


decompiled_code:
__int64 __fastcall htable_remove(_DWORD *a1, unsigned int *a2)
{
_QWORD *v2; // rax
__int64 v3; // r15
int v4; // ebp
__int64 v5; // rbx
_QWORD *v6; // r12
__int64 result; // rax
_QWORD *v8; // [rsp+8h] [rbp-40h]

hash_index(a1, a2);
v2 = (_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a1[10]);
v8 = v2;
v3 = *v2;
if ( !*v2 )
return 0LL;
v4 = a1[9];
v5 = *v2;
v6 = 0LL;
while ( v4 != *(_DWORD *)(v5 + 8) || memcmp(a2, *(const void **)(v5 + 16), (int)a1[3]) )
{
result = *(_QWORD *)v5;
v6 = (_QWORD *)v5;
if ( !*(_QWORD *)v5 )
return result;
v5 = *(_QWORD *)v5;
}
if ( v3 == v5 )
*v8 = *(_QWORD *)v5;
else
*v6 = *(_QWORD *)v5;
free((void *)(v5 - (int)a1[2]));
--a1[4];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, unsigned int *a2)
{
_QWORD *v2; // rax
__int64 v3; // r15
int v4; // ebp
__int64 v5; // rbx
_QWORD *v6; // r12
__int64 result; // rax
_QWORD *v8; // [rsp+8h] [rbp-40h]

func0(a1, a2);
v2 = (_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a1[10]);
v8 = v2;
v3 = *v2;
if ( !*v2 )
return 0LL;
v4 = a1[9];
v5 = *v2;
v6 = 0LL;
while ( v4 != *(_DWORD *)(v5 + 8) || memcmp(a2, *(const void **)(v5 + 16), (int)a1[3]) )
{
result = *(_QWORD *)v5;
v6 = (_QWORD *)v5;
if ( !*(_QWORD *)v5 )
return result;
v5 = *(_QWORD *)v5;
}
if ( v3 == v5 )
*v8 = *(_QWORD *)v5;
else
*v6 = *(_QWORD *)v5;
free((void *)(v5 - (int)a1[2]));
--a1[4];
return 1LL;
}

original_code:
int htable_remove(htable * tbl,unsigned char *key){
  hlink *hp,*head,*last = ((void *)0);
    hash_index(tbl,key);
    head = tbl->table[tbl->index];
    for (hp=tbl->table[tbl->index]; hp; last = hp,hp=(hlink *)hp->next)
    {
        if (tbl->hash == hp->hash && memcmp(key, hp->key,tbl->keylen) == 0)
        {
    if(hp != head){
     last->next = hp->next;
     free( ((char *)hp)-tbl->loffset);
    }
    else{
     tbl->table[tbl->index] = hp->next;
     free( ((char *)hp)-tbl->loffset);
    }
    tbl->num_items--;
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int htable_remove(struct htable_t *tbl, unsigned char *key){
  struct hlink_t *hp; struct hlink_t *head; struct hlink_t *last = ((void *)0);
    hash_index(tbl,key);
    head = tbl->table[tbl->index];
    for (hp=tbl->table[tbl->index]; hp; last = hp,hp=(struct hlink_t *)hp->next)
    {
        if (tbl->hash == hp->hash && memcmp(key, hp->key,tbl->keylen) == 0)
        {
    if(hp != head){
     last->next = hp->next;
     free( ((char *)hp)-tbl->loffset);
    }
    else{
     tbl->table[tbl->index] = hp->next;
     free( ((char *)hp)-tbl->loffset);
    }
    tbl->num_items--;
            return 1;
        }
    }
    return 0;
}

variable_types:
key
unsigned char *

return_type: int


original_code:
int htable_add(htable *tbl,unsigned char *key, void *item)
{
   hlink *hp;
   int rc = 1;
   int count;
 do{
     if(key == ((void *)0))
     {
           rc = 0;
   printf("%s,%d,key==NULL\n","libs/htable.c",293);
   break;
     }
  hp = (hlink *)(((char *)item)+tbl->loffset);
  hp->next = tbl->table[tbl->index];
    hp->hash = tbl->hash;
  hp->key=key;
     tbl->table[tbl->index] = hp;
     if (++tbl->num_items >= tbl->max_items) {
   grow_table(tbl);
    }
 }while(0);
    return rc;
}

canonical_original_code:
int htable_add(struct htable_t *tbl, unsigned char *key, void *item)
{
   struct hlink_t *hp;
   int rc = 1;
   int count;
 do{
     if(key == ((void *)0))
     {
           rc = 0;
   printf("%s,%d,key==NULL\n","libs/htable.c",293);
   break;
     }
  hp = (struct hlink_t *)(((char *)item)+tbl->loffset);
  hp->next = tbl->table[tbl->index];
    hp->hash = tbl->hash;
  hp->key=key;
     tbl->table[tbl->index] = hp;
     if (++tbl->num_items >= tbl->max_items) {
   grow_table(tbl);
    }
 }while(0);
    return rc;
}

variable_types:
item
void *

variable_types: rc int

variable_types: count int


decompiled_code:
__int64 __fastcall finger_chunk(__int64 a1, int a2, __m128i *a3)
{
__int64 result; // rax
__m128i v5; // [rsp+0h] [rbp-98h] BYREF
unsigned int v6; // [rsp+10h] [rbp-88h]
char v7[120]; // [rsp+20h] [rbp-78h] BYREF

v5 = 0uLL;
v6 = 0;
SHA1_Init(v7);
SHA1_Update(v7, a1, a2);
SHA1_Final(&v5, v7);
*a3 = _mm_loadu_si128(&v5);
result = v6;
a3[1].m128i_i32[0] = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, __m128i *a3)
{
__int64 result; // rax
__m128i v5; // [rsp+0h] [rbp-98h] BYREF
unsigned int v6; // [rsp+10h] [rbp-88h]
char v7[120]; // [rsp+20h] [rbp-78h] BYREF

v5 = 0uLL;
v6 = 0;
SHA1_Init(v7);
SHA1_Update(v7, a1, a2);
SHA1_Final(&v5, v7);
*a3 = _mm_loadu_si128(&v5);
result = v6;
a3[1].m128i_i32[0] = v6;
return result;
}

original_code:
void finger_chunk(unsigned char *buf, uint32_t len,unsigned char hash[])
{
   SHA_CTX context;
   unsigned char digest[20]={0};
   SHA1_Init(&context);
   SHA1_Update(&context, buf, (int)len);
   SHA1_Final(digest,&context);
   memcpy(hash,digest,20);
}

canonical_original_code:
void finger_chunk(unsigned char *buf, unsigned int len, unsigned char hash[])
{
   struct SHAstate_st context;
   unsigned char digest[20] = {0};
   SHA1_Init(&context);
   SHA1_Update(&context, buf, (int)len);
   SHA1_Final(digest,&context);
   memcpy(hash,digest,20);
}

variable_types:
buf
unsigned char *

variable_types:
len
unsigned int

variable_types:
hash
unsigned char []

variable_types: struct SHAstate_st { unsigned int h0; unsigned int Nl; unsigned int data[16]; unsigned int num; }

variable_types:
digest
unsigned char [20]


decompiled_code:
__int64 Cbr_init()
{
__int64 result; // rax

left_number = 0LL;
total_numbel = 0LL;
rewirte_ratio = LC1;
max_utility = LC2;
current_uitilty = LC2;
cbr_htable = htable_init(16LL, 4LL, 32LL);
result = 0LL;
memset(utility_buckets, 0, 0xFA0uLL);
utility_buckets[1000] = 0;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

left_number = 0LL;
total_numbel = 0LL;
rewirte_ratio = LC1;
max_utility = LC2;
current_uitilty = LC2;
cbr_htable = htable_init(16LL, 4LL, 32LL);
result = 0LL;
memset(utility_buckets, 0, 0xFA0uLL);
utility_buckets[1000] = 0;
return result;
}

original_code:
void Cbr_init(){
 left_number=0;
 total_numbel=0;
 rewirte_ratio=0.05;
 max_utility=0.3;
         current_uitilty=0.3;
 CBRItem r;
 cbr_htable=htable_init((char*)&r.next-(char*)&r,4,32);
 memset(utility_buckets,0,sizeof(utility_buckets));
}

canonical_original_code:
void Cbr_init(){
 left_number=0;
 total_numbel=0;
 rewirte_ratio=0.05;
 max_utility=0.3;
         current_uitilty=0.3;
 struct CBR_item r;
 cbr_htable=htable_init((char *)&r.next-(char *)&r,4,32);
 memset(utility_buckets,0,sizeof(utility_buckets));
}

variable_types: struct CBR_item { int container_id; int size; int rewrite_flag; struct hlink_t { void *next; unsigned int hash; unsigned char *key; } next; }

user_defined_types: struct CBR_item { int container_id; int size; int rewrite_flag; struct hlink_t next; }


decompiled_code:
__int64 Cbr_destroy()
{
return htable_destroy(cbr_htable);
}

canonical_decompiled_code:
__int64 func1()
{
return htable_destroy(cbr_htable);
}

original_code:
void Cbr_destroy(){
 htable_destroy(cbr_htable);
}


decompiled_code:
__int64 __fastcall cbr_decision(int a1, int a2)
{
__int64 v2; // rax
double v3; // xmm0_8
int v4; // edx
unsigned int v5; // ebx
int v6; // edx
__int64 v7; // rax
double v8; // xmm1_8
double v9; // xmm0_8
bool v10; // dl
__m128d v11; // xmm0
int v13[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v13[0] = a1;
v2 = htable_lookup(cbr_htable, v13);
if ( v2 )
{
*(double *)&total_numbel = *(double *)&total_numbel + 1.0;
v3 = (double)*(int *)(v2 + 4) / (double)DEFAULT_CONTAINER_SIZE;
v4 = (int)(v3 / 0.001);
if ( v4 > 1000 )
v4 = 1000;
++utility_buckets[v4];
v5 = *(_DWORD *)(v2 + 8);
if ( v5 )
{
v5 = 1;
if ( fmin(*(double *)&max_utility, *(double *)&current_uitilty) < v3 )
{
*(_DWORD *)(v2 + 8) = 0;
v5 = 0;
}
}
v6 = *(_DWORD *)(v2 + 4) - a2;
*(_DWORD *)(v2 + 4) = v6;
if ( !v6 )
htable_remove(cbr_htable, v13);
left_number = 0LL;
current_uitilty = LC1;
v7 = 1LL;
v8 = *(double *)&LC1;
v9 = 0.0;
if ( *(double *)&rewirte_ratio > 0.0 / *(double *)&total_numbel )
{
do
{
v9 = v9 + (double)utility_buckets[v7 - 1];
v8 = v8 + 0.001;
v10 = (int)v7++ <= 1000;
}
while ( v10 && *(double *)&rewirte_ratio > v9 / *(double *)&total_numbel );
left_number = *(_QWORD *)&v9;
v11.m128d_f64[0] = v8;
v11.m128d_f64[0] = _mm_cmpge_sd(v11, (__m128d)(unsigned __int64)LC1).m128d_f64[0];
current_uitilty = *(_QWORD *)&v8 & *(_QWORD *)&v11.m128d_f64[0] | ~*(_QWORD *)&v11.m128d_f64[0] & LC1;
}
}
else
{
err_msg("cbr.c", 81LL, "error ==========");
v5 = 1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
__int64 v2; // rax
double v3; // xmm0_8
int v4; // edx
unsigned int v5; // ebx
int v6; // edx
__int64 v7; // rax
double v8; // xmm1_8
double v9; // xmm0_8
bool v10; // dl
__m128d v11; // xmm0
int v13[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v13[0] = a1;
v2 = htable_lookup(cbr_htable, v13);
if ( v2 )
{
*(double *)&total_numbel = *(double *)&total_numbel + 1.0;
v3 = (double)*(int *)(v2 + 4) / (double)DEFAULT_CONTAINER_SIZE;
v4 = (int)(v3 / 0.001);
if ( v4 > 1000 )
v4 = 1000;
++utility_buckets[v4];
v5 = *(_DWORD *)(v2 + 8);
if ( v5 )
{
v5 = 1;
if ( fmin(*(double *)&max_utility, *(double *)&current_uitilty) < v3 )
{
*(_DWORD *)(v2 + 8) = 0;
v5 = 0;
}
}
v6 = *(_DWORD *)(v2 + 4) - a2;
*(_DWORD *)(v2 + 4) = v6;
if ( !v6 )
htable_remove(cbr_htable, v13);
left_number = 0LL;
current_uitilty = LC1;
v7 = 1LL;
v8 = *(double *)&LC1;
v9 = 0.0;
if ( *(double *)&rewirte_ratio > 0.0 / *(double *)&total_numbel )
{
do
{
v9 = v9 + (double)utility_buckets[v7 - 1];
v8 = v8 + 0.001;
v10 = (int)v7++ <= 1000;
}
while ( v10 && *(double *)&rewirte_ratio > v9 / *(double *)&total_numbel );
left_number = *(_QWORD *)&v9;
v11.m128d_f64[0] = v8;
v11.m128d_f64[0] = _mm_cmpge_sd(v11, (__m128d)(unsigned __int64)LC1).m128d_f64[0];
current_uitilty = *(_QWORD *)&v8 & *(_QWORD *)&v11.m128d_f64[0] | ~*(_QWORD *)&v11.m128d_f64[0] & LC1;
}
}
else
{
err_msg("cbr.c", 81LL, "error ==========");
v5 = 1;
}
return v5;
}

original_code:
int cbr_decision(int old_container_id,int chunk_size){
 CBRItem * rf=htable_lookup(cbr_htable,&old_container_id);
 int rewrite=0;
 double thr=0;
 int value=0;
 int i;
 if(rf){
  total_numbel++;
  thr=rf->size*1.0/ DEFAULT_CONTAINER_SIZE;
  value=thr/0.001;
  if(value>1000)
   value=1000;
  utility_buckets[value]++;
  if(!rf->rewrite_flag)
   rewrite=0;
  else if(thr<=((max_utility)<(current_uitilty)?(max_utility):(current_uitilty))){
   rewrite=1;
  }
  else{
   rf->rewrite_flag=0;
   rewrite=0;
  }
  rf->size-=chunk_size;
  if(rf->size==0)
   htable_remove(cbr_htable,&old_container_id);
  left_number=0;
  i=0;
  current_uitilty=0.05;
  while(left_number/total_numbel< rewirte_ratio && i<=1000){
   left_number+=utility_buckets[i++];
   current_uitilty+=0.001;
  }
  if(current_uitilty<0.05)
   current_uitilty=0.05;
 }
 else{
  err_msg("cbr.c",81,"error ==========");
  return 1;
 }
 return rewrite;
}

canonical_original_code:
int cbr_decision(int old_container_id, int chunk_size){
 struct CBR_item *rf = htable_lookup(cbr_htable,&old_container_id);
 int rewrite = 0;
 double thr = 0;
 int value = 0;
 int i;
 if(rf){
  total_numbel++;
  thr=rf->size*1.0/ DEFAULT_CONTAINER_SIZE;
  value=thr/0.001;
  if(value>1000)
   value=1000;
  utility_buckets[value]++;
  if(!rf->rewrite_flag)
   rewrite=0;
  else if(thr<=((max_utility)<(current_uitilty)?(max_utility):(current_uitilty))){
   rewrite=1;
  }
  else{
   rf->rewrite_flag=0;
   rewrite=0;
  }
  rf->size-=chunk_size;
  if(rf->size==0)
   htable_remove(cbr_htable,&old_container_id);
  left_number=0;
  i=0;
  current_uitilty=0.05;
  while(left_number/total_numbel< rewirte_ratio && i<=1000){
   left_number+=utility_buckets[i++];
   current_uitilty+=0.001;
  }
  if(current_uitilty<0.05)
   current_uitilty=0.05;
 }
 else{
  err_msg("cbr.c",81,"error ==========");
  return 1;
 }
 return rewrite;
}

variable_types: struct CBR_item { int container_id; int size; int rewrite_flag; struct hlink_t { void *next; unsigned int hash; unsigned char *key; } next; } *

variable_types: rewrite int

variable_types: thr double

variable_types: value int

variable_types: i int


decompiled_code:
__int64 __fastcall dedup_mark_send(unsigned int a1, __int64 a2, __int64 a3, void *a4)
{
__int64 v5; // rbx
int v6; // ebp

v5 = *(_QWORD *)(a3 + 264);
memset(a4, 0, 0x10000uLL);
if ( v5 )
{
v6 = 0;
do
{
if ( index_lookup(a2, v5) )
{
*(_BYTE *)(v5 + 36) = 1;
*((_BYTE *)a4 + v6) = 49;
}
else
{
*((_BYTE *)a4 + v6) = 48;
}
if ( ++v6 > 0xFFFF )
{
printf("%s %d bigBuf is not enough\n", "backup_dedup.c", 22LL);
bnet_send(a1, a4, (unsigned int)v6);
memset(a4, 0, 0x10000uLL);
v6 = 0;
}
v5 = *(_QWORD *)(v5 + 40);
}
while ( v5 );
if ( v6 > 0 )
bnet_send(a1, a4, (unsigned int)v6);
}
return bnet_signal(a1, 4294967292LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, __int64 a3, void *a4)
{
__int64 v5; // rbx
int v6; // ebp

v5 = *(_QWORD *)(a3 + 264);
memset(a4, 0, 0x10000uLL);
if ( v5 )
{
v6 = 0;
do
{
if ( index_lookup(a2, v5) )
{
*(_BYTE *)(v5 + 36) = 1;
*((_BYTE *)a4 + v6) = 49;
}
else
{
*((_BYTE *)a4 + v6) = 48;
}
if ( ++v6 > 0xFFFF )
{
printf("%s %d bigBuf is not enough\n", "backup_dedup.c", 22LL);
bnet_send(a1, a4, (unsigned int)v6);
memset(a4, 0, 0x10000uLL);
v6 = 0;
}
v5 = *(_QWORD *)(v5 + 40);
}
while ( v5 );
if ( v6 > 0 )
bnet_send(a1, a4, (unsigned int)v6);
}
return bnet_signal(a1, 4294967292LL);
}

original_code:
void dedup_mark_send(int fd,MemIndex* memdex,Recipe *rp,char * buf){
 FingerChunk *fc=((void *)0);
 fc=rp->first;
 int i=0;
 memset(buf,0,64*1024);
 while(fc){
  if(index_lookup(memdex,fc->fingerprint)){
   fc->existed=1;
   buf[i++]='1';
  }
  else
   buf[i++]='0';
  if(i>=64*1024){
   printf("%s %d bigBuf is not enough\n","backup_dedup.c",22);
   bnet_send(fd,buf,i);
   memset(buf,0,64*1024);
   i=0;
  }
  fc=fc->next;
 }
 if(i>0){
  bnet_send(fd,buf,i);
 }
 bnet_signal(fd,-4);
}

canonical_original_code:
void dedup_mark_send(int fd, struct mem_index *memdex, struct recipe_tag *rp, char *buf){
 struct finger_chunk_tag *fc = ((void *)0);
 fc=rp->first;
 int i = 0;
 memset(buf,0,64*1024);
 while(fc){
  if(index_lookup(memdex,fc->fingerprint)){
   fc->existed=1;
   buf[i++]='1';
  }
  else
   buf[i++]='0';
  if(i>=64*1024){
   printf("%s %d bigBuf is not enough\n","backup_dedup.c",22);
   bnet_send(fd,buf,i);
   memset(buf,0,64*1024);
   i=0;
  }
  fc=fc->next;
 }
 if(i>0){
  bnet_send(fd,buf,i);
 }
 bnet_signal(fd,-4);
}

variable_types: fd int

variable_types: struct mem_index { struct htable_t { struct hlink_t { void *next; unsigned int hash; unsigned char *key; } **table; int loffset; int keylen; unsigned int num_items; unsigned int max_items; unsigned int grow_count; unsigned int replace_count; unsigned int buckets; unsigned int hash; unsigned int index; unsigned int mask; unsigned int rshift; struct hlink_t *walkptr; unsigned int walk_index; } *index_table; struct htable_t *index_new; struct lru_cache { int item_count; int hit; int miss; struct htable_t *htable; struct DList { struct node_t { void *data; struct node_t *prev; struct node_t *next; } *head; struct node_t *tail; int size; } *plist; } *index_cache; struct htable_t *container_cache; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *

variable_types: struct recipe_tag { int fileindex; int chunknum; char filename[256]; struct finger_chunk_tag { unsigned char fingerprint[20]; long offset; int length; char existed; struct finger_chunk_tag *next; } *first; struct finger_chunk_tag *last; } *

variable_types:
buf
char *

user_defined_types: struct recipe_tag { int fileindex; int chunknum; char filename[256]; struct finger_chunk_tag *first; struct finger_chunk_tag *last; }


original_code:
void backup_dedup(int fd,char *msg){
 JCR *jcr=((void *)0);
 char fileset[256]={0};
 char *buf=(char *)calloc(1,64*1024 +21);
 int len;
 int type;
 int index;
 Recipe *rp=((void *)0);
 FingerChunk *fc=((void *)0);
 char *p=((void *)0);
 Chunk *chunk=((void *)0);
 container_vol_init();
 jobcount_init();
 jcr=jcr_new();
 jcr->dataSocket=fd;
 jcr->memIndex=index_init();
 jcr->container=container_new();
 if(sscanf(msg,backup_cmd,fileset)!=1){
  goto FAIL;
 }
 jcr->jobv=jobv_new(fileset);
 jcr->nJobId=jcr->jobv->nJobId;
 printf("===========backup start==============\n");
 printf("%s,%d pathname:%s \n", "backup_dedup.c",63,fileset);
 struct timeval gstart,gend;
 struct timeval sstart,ssend;
 struct timeval wstart,wend;
 gettimeofday(&gstart, ((void *)0));
 while(bnet_recv(jcr->dataSocket,buf,&len)!=-100){
  if(len==-6){
   printf("%s %d backup is over\n","backup_dedup.c",72);
   break;
  }
  jcr->nRecvSize+=len;
  if(sscanf(buf,"%d %d",&index,&type)!=2)
   goto FAIL;
  switch(type){
   case 1:
    while(bnet_recv(jcr->dataSocket,buf,&len)>0){
     jcr->nRecvSize+=len;
     rp=recipe_new();
     memcpy(rp->filename,buf,len);
     rp->fileindex=index;
    }
    break;
   case 2:
    while(bnet_recv(jcr->dataSocket,buf,&len)>0){
     jcr->nRecvSize+=len;
     p=buf;
     while(p-buf<len){
      fc=fingerchunk_new(p,0);
      recipe_append_fingerchunk(rp,fc);
      p+=sizeof(Fingerprint);
     }
    }
    gettimeofday(&sstart, ((void *)0));
    dedup_mark_send(fd,jcr->memIndex,rp,buf);
    gettimeofday(&ssend, ((void *)0));
    (jcr->searchTime)+=(ssend.tv_usec-sstart.tv_usec)*1.0/1000000+(ssend.tv_sec-sstart.tv_sec);
    break;
   case 3:
    while(bnet_recv(jcr->dataSocket,buf,&len)>0){
     jcr->nRecvSize+=len;
     chunk=chunk_new(buf,buf+sizeof(Fingerprint),len-sizeof(Fingerprint));
     gettimeofday(&wstart, ((void *)0));
     while(write_chunk(jcr->container, chunk)==0){
      write_container(jcr->container);
      index_insert(jcr->memIndex,jcr->container);
      container_destroy(jcr->container);
      jcr->container=container_new();
     }
     gettimeofday(&wend, ((void *)0));
     (jcr->writeDataTime)+=(wend.tv_usec-wstart.tv_usec)*1.0/1000000+(wend.tv_sec-wstart.tv_sec);
     jcr->nDedupChunkCount++;
     jcr->nDedupSize+=chunk->length;
     chunk_free(chunk);
    }
    jcr->nChunkCount+=rp->chunknum;
    jcr->nFileCount++;
    if(G_VERBOSE)
     printf("receive file %s OK, total: %d\n",rp->filename,jcr->nFileCount);
    jobv_insert_recipe(jcr->jobv, rp);
    recipe_free(rp);
    rp=recipe_new();
    break;
   default:
    printf("%s %d wrong\n","backup_dedup.c",137);
    break;
  }
 }
FAIL:
 gettimeofday(&gend, ((void *)0));
 (jcr->recvTime)+=(gend.tv_usec-gstart.tv_usec)*1.0/1000000+(gend.tv_sec-gstart.tv_sec);
 gettimeofday(&wstart, ((void *)0));
 if(jcr->container){
  if(jcr->container->data_size>0){
   write_container(jcr->container);
   index_insert(jcr->memIndex,jcr->container);
  }
  container_destroy(jcr->container);
 }
 bnet_send(fd,"OK",2);
 gettimeofday(&wend, ((void *)0));
 (jcr->writeDataTime)+=(wend.tv_usec-wstart.tv_usec)*1.0/1000000+(wend.tv_sec-wstart.tv_sec);
 printf("============back over===============\n");
 printf("total time:%.4f   throughput:%.4f MB/s\n",jcr->recvTime,jcr->nRecvSize*1.0/jcr->recvTime/1036288.0);
 printf("search  time:%.4f \n ",jcr->searchTime);
 printf("writedata time:%.4f throughput:%.4f MB/s\n",jcr->writeDataTime,jcr->nDedupSize*1.0/jcr->writeDataTime/1036288.0);
 printf("old chunk count:%d, deduped chunk count:%d\n",jcr->nChunkCount,jcr->nDedupChunkCount);
 if(rp){
  recipe_free(rp);
 }
 jobv_destroy(jcr->jobv);
 jcr_free(jcr);
 container_vol_destroy();
 jobcount_close();
 index_destroy(jcr->memIndex);
}

canonical_original_code:
void backup_dedup(int fd, char *msg){
 struct jcr *jcr = ((void *)0);
 char fileset[256] = {0};
 char *buf = (char *)calloc(1,64*1024 +21);
 int len;
 int type;
 int index;
 struct recipe_tag *rp = ((void *)0);
 struct finger_chunk_tag *fc = ((void *)0);
 char *p = ((void *)0);
 struct chunk_tag *chunk = ((void *)0);
 container_vol_init();
 jobcount_init();
 jcr=jcr_new();
 jcr->dataSocket=fd;
 jcr->memIndex=index_init();
 jcr->container=container_new();
 if(sscanf(msg,backup_cmd,fileset)!=1){
  goto FAIL;
 }
 jcr->jobv=jobv_new(fileset);
 jcr->nJobId=jcr->jobv->nJobId;
 printf("===========backup start==============\n");
 printf("%s,%d pathname:%s \n", "backup_dedup.c",63,fileset);
 struct timeval gstart; struct timeval gend;
 struct timeval sstart; struct timeval ssend;
 struct timeval wstart; struct timeval wend;
 gettimeofday(&gstart, ((void *)0));
 while(bnet_recv(jcr->dataSocket,buf,&len)!=-100){
  if(len==-6){
   printf("%s %d backup is over\n","backup_dedup.c",72);
   break;
  }
  jcr->nRecvSize+=len;
  if(sscanf(buf,"%d %d",&index,&type)!=2)
   goto FAIL;
  switch(type){
   case 1:
    while(bnet_recv(jcr->dataSocket,buf,&len)>0){
     jcr->nRecvSize+=len;
     rp=recipe_new();
     memcpy(rp->filename,buf,len);
     rp->fileindex=index;
    }
    break;
   case 2:
    while(bnet_recv(jcr->dataSocket,buf,&len)>0){
     jcr->nRecvSize+=len;
     p=buf;
     while(p-buf<len){
      fc=fingerchunk_new(p,0);
      recipe_append_fingerchunk(rp,fc);
      p+=sizeof(Fingerprint);
     }
    }
    gettimeofday(&sstart, ((void *)0));
    dedup_mark_send(fd,jcr->memIndex,rp,buf);
    gettimeofday(&ssend, ((void *)0));
    (jcr->searchTime)+=(ssend.tv_usec-sstart.tv_usec)*1.0/1000000+(ssend.tv_sec-sstart.tv_sec);
    break;
   case 3:
    while(bnet_recv(jcr->dataSocket,buf,&len)>0){
     jcr->nRecvSize+=len;
     chunk=chunk_new(buf,buf+sizeof(Fingerprint),len-sizeof(Fingerprint));
     gettimeofday(&wstart, ((void *)0));
     while(write_chunk(jcr->container, chunk)==0){
      write_container(jcr->container);
      index_insert(jcr->memIndex,jcr->container);
      container_destroy(jcr->container);
      jcr->container=container_new();
     }
     gettimeofday(&wend, ((void *)0));
     (jcr->writeDataTime)+=(wend.tv_usec-wstart.tv_usec)*1.0/1000000+(wend.tv_sec-wstart.tv_sec);
     jcr->nDedupChunkCount++;
     jcr->nDedupSize+=chunk->length;
     chunk_free(chunk);
    }
    jcr->nChunkCount+=rp->chunknum;
    jcr->nFileCount++;
    if(G_VERBOSE)
     printf("receive file %s OK, total: %d\n",rp->filename,jcr->nFileCount);
    jobv_insert_recipe(jcr->jobv, rp);
    recipe_free(rp);
    rp=recipe_new();
    break;
   default:
    printf("%s %d wrong\n","backup_dedup.c",137);
    break;
  }
 }
FAIL:
 gettimeofday(&gend, ((void *)0));
 (jcr->recvTime)+=(gend.tv_usec-gstart.tv_usec)*1.0/1000000+(gend.tv_sec-gstart.tv_sec);
 gettimeofday(&wstart, ((void *)0));
 if(jcr->container){
  if(jcr->container->data_size>0){
   write_container(jcr->container);
   index_insert(jcr->memIndex,jcr->container);
  }
  container_destroy(jcr->container);
 }
 bnet_send(fd,"OK",2);
 gettimeofday(&wend, ((void *)0));
 (jcr->writeDataTime)+=(wend.tv_usec-wstart.tv_usec)*1.0/1000000+(wend.tv_sec-wstart.tv_sec);
 printf("============back over===============\n");
 printf("total time:%.4f   throughput:%.4f MB/s\n",jcr->recvTime,jcr->nRecvSize*1.0/jcr->recvTime/1036288.0);
 printf("search  time:%.4f \n ",jcr->searchTime);
 printf("writedata time:%.4f throughput:%.4f MB/s\n",jcr->writeDataTime,jcr->nDedupSize*1.0/jcr->writeDataTime/1036288.0);
 printf("old chunk count:%d, deduped chunk count:%d\n",jcr->nChunkCount,jcr->nDedupChunkCount);
 if(rp){
  recipe_free(rp);
 }
 jobv_destroy(jcr->jobv);
 jcr_free(jcr);
 container_vol_destroy();
 jobcount_close();
 index_destroy(jcr->memIndex);
}

variable_types:
msg
char *

variable_types: struct jcr { int nJobId; int dataSocket; int fingerSocket; char szBackupPath[256]; char szRestorePath[256]; int nFileCount; long nSize; long nDedupSize; long nRecvSize; int nChunkCount; int nDedupChunkCount; struct job_des { int nJobId; int isDel; char szBackupPath[256]; int nFileNum; int fd; } *jobv; struct mem_index { struct htable_t { struct hlink_t { void *next; unsigned int hash; unsigned char *key; } **table; int loffset; int keylen; unsigned int num_items; unsigned int max_items; unsigned int grow_count; unsigned int replace_count; unsigned int buckets; unsigned int hash; unsigned int index; unsigned int mask; unsigned int rshift; struct hlink_t *walkptr; unsigned int walk_index; } *index_table; struct htable_t *index_new; struct lru_cache { int item_count; int hit; int miss; struct htable_t *htable; struct DList { struct node_t { void *data; struct node_t *prev; struct node_t *next; } *head; struct node_t *tail; int size; } *plist; } *index_cache; struct htable_t *container_cache; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *memIndex; struct container_tag { int container_id; int data_size; int chunk_num; struct htable_t *meta_table; unsigned char *data_buffer; struct hlink_t next; } *container; double searchTime; double writeDataTime; double writeRecipeTime; double recvTime; double totalTime; } *

variable_types:
fileset
char [256]

variable_types: len int

variable_types: type int

variable_types: index int

variable_types: struct finger_chunk_tag { unsigned char fingerprint[20]; long offset; int length; char existed; struct finger_chunk_tag *next; } *

variable_types:
p
char *

variable_types: struct chunk_tag { int length; unsigned char hash[20]; unsigned char *data; } *

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
char *__fastcall pipeline_queue_init(int a1)
{
char *v1; // rbx

v1 = (char *)malloc(0x98uLL);
*(_QWORD *)v1 = queue_new();
*((_DWORD *)v1 + 2) = a1;
if ( pthread_mutex_init((pthread_mutex_t *)(v1 + 16), 0LL)
|| pthread_cond_init((pthread_cond_t *)(v1 + 56), 0LL)
|| pthread_cond_init((pthread_cond_t *)(v1 + 104), 0LL) )
{
puts("Failed to init mutex or work in PipelineQueue!");
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
char *v1; // rbx

v1 = (char *)malloc(0x98uLL);
*(_QWORD *)v1 = queue_new();
*((_DWORD *)v1 + 2) = a1;
if ( pthread_mutex_init((pthread_mutex_t *)(v1 + 16), 0LL)
|| pthread_cond_init((pthread_cond_t *)(v1 + 56), 0LL)
|| pthread_cond_init((pthread_cond_t *)(v1 + 104), 0LL) )
{
puts("Failed to init mutex or work in PipelineQueue!");
v1 = 0LL;
}
return v1;
}

original_code:
PipelineQueue* pipeline_queue_init(int size){
    PipelineQueue *p_queue = (PipelineQueue*)malloc(sizeof(PipelineQueue));
    p_queue->queue = queue_new();
    p_queue->max_size = size;
    if(pthread_mutex_init(&p_queue->mutex, 0)
            || pthread_cond_init(&p_queue->max_work, 0) || pthread_cond_init(&p_queue->min_work, 0)){
        puts("Failed to init mutex or work in PipelineQueue!");
        return ((void *)0);
    }
    return p_queue;
}

canonical_original_code:
struct PipelineQueue *pipeline_queue_init(int size){
    struct PipelineQueue *p_queue = (PipelineQueue*)malloc(sizeof(PipelineQueue));
    p_queue->queue = queue_new();
    p_queue->max_size = size;
    if(pthread_mutex_init(&p_queue->mutex, 0)
            || pthread_cond_init(&p_queue->max_work, 0) || pthread_cond_init(&p_queue->min_work, 0)){
        puts("Failed to init mutex or work in PipelineQueue!");
        return ((void *)0);
    }
    return p_queue;
}

variable_types: size int

variable_types: struct PipelineQueue { struct queue_tag { struct queue_ele_tag { struct queue_ele_tag *next; void *data; } *first; int elem_num; } *queue; int max_size; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } max_work; union pthread_cond_t min_work; } *

user_defined_types: struct PipelineQueue { struct queue_tag *queue; int max_size; union pthread_mutex_t mutex; union pthread_cond_t max_work; union pthread_cond_t min_work; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct queue_tag { struct queue_ele_tag *first; int elem_num; }


decompiled_code:
void __fastcall pipeline_queue_destroy(void *ptr)
{
queue_free(*(_QWORD *)ptr);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 16));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 56));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 104));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
queue_free(*(_QWORD *)ptr);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 16));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 56));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 104));
free(ptr);
}

original_code:
void pipeline_queue_destroy(PipelineQueue* p_queue){
    queue_free(p_queue->queue);
    pthread_mutex_destroy(&p_queue->mutex);
    pthread_cond_destroy(&p_queue->max_work);
    pthread_cond_destroy(&p_queue->min_work);
    free(p_queue);
}

canonical_original_code:
void pipeline_queue_destroy(struct PipelineQueue *p_queue){
    queue_free(p_queue->queue);
    pthread_mutex_destroy(&p_queue->mutex);
    pthread_cond_destroy(&p_queue->max_work);
    pthread_cond_destroy(&p_queue->min_work);
    free(p_queue);
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct queue_ele_tag { struct queue_ele_tag *next; void *data; }


decompiled_code:
int __fastcall pipeline_queue_push(_QWORD *a1, __int64 a2)
{
pthread_mutex_t *v2; // rbp
int result; // eax

v2 = (pthread_mutex_t *)(a1 + 2);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 2)) )
return puts("failed to lock!");
while ( *((int *)a1 + 2) > 0 )
{
if ( (int)queue_size(*a1) < *((_DWORD *)a1 + 2) )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 7), v2);
}
queue_push(*a1, a2);
pthread_cond_broadcast((pthread_cond_t *)(a1 + 13));
result = pthread_mutex_unlock(v2);
if ( result )
return puts("failed to lock!");
return result;
}

canonical_decompiled_code:
int __fastcall func2(_QWORD *a1, __int64 a2)
{
pthread_mutex_t *v2; // rbp
int result; // eax

v2 = (pthread_mutex_t *)(a1 + 2);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 2)) )
return puts("failed to lock!");
while ( *((int *)a1 + 2) > 0 )
{
if ( (int)queue_size(*a1) < *((_DWORD *)a1 + 2) )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 7), v2);
}
queue_push(*a1, a2);
pthread_cond_broadcast((pthread_cond_t *)(a1 + 13));
result = pthread_mutex_unlock(v2);
if ( result )
return puts("failed to lock!");
return result;
}

original_code:
void pipeline_queue_push(PipelineQueue* p_queue, void* item){
    if(pthread_mutex_lock(&p_queue->mutex) != 0){
        puts("failed to lock!");
        return;
    }
    while(p_queue->max_size>0&&queue_size(p_queue->queue) >= p_queue->max_size){
        pthread_cond_wait(&p_queue->max_work, &p_queue->mutex);
    }
    queue_push(p_queue->queue, item);
    pthread_cond_broadcast(&p_queue->min_work);
    if(pthread_mutex_unlock(&p_queue->mutex)){
        puts("failed to lock!");
        return;
    }
}

canonical_original_code:
void pipeline_queue_push(struct PipelineQueue *p_queue, void *item){
    if(pthread_mutex_lock(&p_queue->mutex) != 0){
        puts("failed to lock!");
        return;
    }
    while(p_queue->max_size>0&&queue_size(p_queue->queue) >= p_queue->max_size){
        pthread_cond_wait(&p_queue->max_work, &p_queue->mutex);
    }
    queue_push(p_queue->queue, item);
    pthread_cond_broadcast(&p_queue->min_work);
    if(pthread_mutex_unlock(&p_queue->mutex)){
        puts("failed to lock!");
        return;
    }
}

variable_types:
item
void *

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }


decompiled_code:
__int64 __fastcall pipeline_queue_pop(__int64 a1)
{
pthread_mutex_t *v1; // rbp
__int64 v2; // r12

v1 = (pthread_mutex_t *)(a1 + 16);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 16)) )
{
puts("failed to lock!");
v2 = 0LL;
}
else
{
while ( (int)queue_size(*(_QWORD *)a1) <= 0 )
pthread_cond_wait((pthread_cond_t *)(a1 + 104), v1);
v2 = queue_pop(*(_QWORD *)a1);
pthread_cond_broadcast((pthread_cond_t *)(a1 + 56));
pthread_mutex_unlock(v1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
pthread_mutex_t *v1; // rbp
__int64 v2; // r12

v1 = (pthread_mutex_t *)(a1 + 16);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 16)) )
{
puts("failed to lock!");
v2 = 0LL;
}
else
{
while ( (int)queue_size(*(_QWORD *)a1) <= 0 )
pthread_cond_wait((pthread_cond_t *)(a1 + 104), v1);
v2 = queue_pop(*(_QWORD *)a1);
pthread_cond_broadcast((pthread_cond_t *)(a1 + 56));
pthread_mutex_unlock(v1);
}
return v2;
}

original_code:
void* pipeline_queue_pop(PipelineQueue* p_queue){
    if(pthread_mutex_lock(&p_queue->mutex) != 0){
        puts("failed to lock!");
        return ((void *)0);
    }
    while(queue_size(p_queue->queue) <= 0){
        pthread_cond_wait(&p_queue->min_work, &p_queue->mutex);
    }
    void * item = queue_pop(p_queue->queue);
    pthread_cond_broadcast(&p_queue->max_work);
    pthread_mutex_unlock(&p_queue->mutex);
    return item;
}

canonical_original_code:
void *pipeline_queue_pop(struct PipelineQueue *p_queue){
    if(pthread_mutex_lock(&p_queue->mutex) != 0){
        puts("failed to lock!");
        return ((void *)0);
    }
    while(queue_size(p_queue->queue) <= 0){
        pthread_cond_wait(&p_queue->min_work, &p_queue->mutex);
    }
    void *item = queue_pop(p_queue->queue);
    pthread_cond_broadcast(&p_queue->max_work);
    pthread_mutex_unlock(&p_queue->mutex);
    return item;
}

return_type: void *


decompiled_code:
int __fastcall handle_client_request(unsigned int *a1)
{
unsigned int v1; // ebp
int result; // eax
__int64 i; // rsi
int v4; // [rsp+Ch] [rbp-14Ch] BYREF
char v5[296]; // [rsp+10h] [rbp-148h] BYREF
int v6; // [rsp+138h] [rbp-20h]

v1 = *a1;
v4 = 0;
while ( 1 )
{
while ( 1 )
{
memset(v5, 0, sizeof(v5));
v6 = 0;
if ( (unsigned int)bnet_recv(v1, v5, &v4) == -100 )
{
printf("%s,%d network error\n", "server.c", 183LL);
goto LABEL_3;
}
if ( v4 <= 0 )
goto LABEL_3;
if ( memcmp(v5, "BACK", 4uLL) )
break;
if ( G_NOT_DEDUP )
{
backup_formal(v1, v5);
}
else if ( G_PIPELINE )
{
for ( i = (unsigned int)data_fd; data_fd < 0; i = (unsigned int)data_fd )
sleep(1u);
pipeline_backup(v1, i, v5);
}
else
{
backup_dedup(v1, v5);
}
}
if ( !memcmp(v5, "REST", 4uLL) )
break;
if ( !memcmp(v5, "DELE", 4uLL) )
delete_job(v1, v5);
else
printf("%s,%d invalid command \n", "server.c", 213LL);
}
if ( G_NOT_DEDUP )
restore_formal(v1, v5);
else
restore(v1, v5);
LABEL_3:
printf("%s %d client quit\n", "server.c", 217LL);
close(v1);
result = close(data_fd);
data_fd = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int *a1)
{
unsigned int v1; // ebp
int result; // eax
__int64 i; // rsi
int v4; // [rsp+Ch] [rbp-14Ch] BYREF
char v5[296]; // [rsp+10h] [rbp-148h] BYREF
int v6; // [rsp+138h] [rbp-20h]

v1 = *a1;
v4 = 0;
while ( 1 )
{
while ( 1 )
{
memset(v5, 0, sizeof(v5));
v6 = 0;
if ( (unsigned int)bnet_recv(v1, v5, &v4) == -100 )
{
printf("%s,%d network error\n", "server.c", 183LL);
goto LABEL_3;
}
if ( v4 <= 0 )
goto LABEL_3;
if ( memcmp(v5, "BACK", 4uLL) )
break;
if ( G_NOT_DEDUP )
{
backup_formal(v1, v5);
}
else if ( G_PIPELINE )
{
for ( i = (unsigned int)data_fd; data_fd < 0; i = (unsigned int)data_fd )
sleep(1u);
pipeline_backup(v1, i, v5);
}
else
{
backup_dedup(v1, v5);
}
}
if ( !memcmp(v5, "REST", 4uLL) )
break;
if ( !memcmp(v5, "DELE", 4uLL) )
delete_job(v1, v5);
else
printf("%s,%d invalid command \n", "server.c", 213LL);
}
if ( G_NOT_DEDUP )
restore_formal(v1, v5);
else
restore(v1, v5);
LABEL_3:
printf("%s %d client quit\n", "server.c", 217LL);
close(v1);
result = close(data_fd);
data_fd = -1;
return result;
}

original_code:
void *handle_client_request(void * data){
 int fd=*(int *)data;
 char msg[300];
 int len=0;
 int result=0;
 while(1){
  memset(msg,0,300);
  if(bnet_recv(fd,msg,&len)==-100 ){
   printf("%s,%d network error\n","server.c",183);
   break;
  }
  if(len<=0)
   break;
  if(strncmp(msg,"BACK",4)==0){
   if(G_NOT_DEDUP){
    backup_formal(fd,msg);
   }
   else if(G_PIPELINE){
    while(data_fd<0)
     sleep(1);
    pipeline_backup( fd,data_fd,msg);
   }
   else
    backup_dedup(fd,msg);
  }
  else if(strncmp(msg,"REST",4)==0){
   if(G_NOT_DEDUP){
    restore_formal( fd, msg);
   }
   else
    restore( fd, msg);
   break;
  }
  else if(strncmp(msg,"DELE",4)==0){
   delete_job(fd,msg);
  }
  else {
   printf("%s,%d invalid command \n","server.c",213);
  }
 }
 printf("%s %d client quit\n","server.c",217);
 close(fd);
 close(data_fd);
 data_fd=-1;
}

canonical_original_code:
void *handle_client_request(void *data){
 int fd = *(int *)data;
 char msg[300];
 int len = 0;
 int result = 0;
 while(1){
  memset(msg,0,300);
  if(bnet_recv(fd,msg,&len)==-100 ){
   printf("%s,%d network error\n","server.c",183);
   break;
  }
  if(len<=0)
   break;
  if(strncmp(msg,"BACK",4)==0){
   if(G_NOT_DEDUP){
    backup_formal(fd,msg);
   }
   else if(G_PIPELINE){
    while(data_fd<0)
     sleep(1);
    pipeline_backup( fd,data_fd,msg);
   }
   else
    backup_dedup(fd,msg);
  }
  else if(strncmp(msg,"REST",4)==0){
   if(G_NOT_DEDUP){
    restore_formal( fd, msg);
   }
   else
    restore( fd, msg);
   break;
  }
  else if(strncmp(msg,"DELE",4)==0){
   delete_job(fd,msg);
  }
  else {
   printf("%s,%d invalid command \n","server.c",213);
  }
 }
 printf("%s %d client quit\n","server.c",217);
 close(fd);
 close(data_fd);
 data_fd=-1;
}

variable_types:
data
void *

variable_types: fd int

variable_types:
msg
char [300]

variable_types: result int


decompiled_code:
__int64 __fastcall wait_conncet(void *a1)
{
pthread_t v1; // rax
int v2; // ebx
int *v3; // rbp
int v4; // eax
__int64 result; // rax
fd_set readfds; // [rsp+10h] [rbp-E8h] BYREF
struct sockaddr v7; // [rsp+90h] [rbp-68h] BYREF
socklen_t addr_len; // [rsp+ACh] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+B0h] [rbp-48h] BYREF

v1 = pthread_self();
pthread_detach(v1);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = _bswap_16(8889);
v2 = socket(2, 1, 0);
if ( bind(v2, &addr, 0x10u) )
{
puts("Can not bind address!");
result = -1LL;
}
else if ( listen(v2, 5) )
{
puts("Can not listen the port!");
result = -1LL;
}
else
{
v3 = _errno_location();
do
{
LABEL_4:
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[(unsigned int)v2 >> 6] |= 1LL << v2;
*v3 = 0;
if ( select(v2 + 1, &readfds, 0LL, 0LL, 0LL) < 0 )
break;
if ( (readfds.fds_bits[v2 / 64] & (1LL << (v2 % 64))) != 0 )
{
while ( 1 )
{
addr_len = 16;
v4 = accept(v2, &v7, &addr_len);
if ( v4 >= 0 )
break;
if ( *v3 != 4 )
goto LABEL_4;
}
data_fd = v4;
printf("%s %d connectd fd:%d\n", "server.c", 272LL, (unsigned int)v4);
}
}
}
while ( *v3 == 4 );
close(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1)
{
pthread_t v1; // rax
int v2; // ebx
int *v3; // rbp
int v4; // eax
__int64 result; // rax
fd_set readfds; // [rsp+10h] [rbp-E8h] BYREF
struct sockaddr v7; // [rsp+90h] [rbp-68h] BYREF
socklen_t addr_len; // [rsp+ACh] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+B0h] [rbp-48h] BYREF

v1 = pthread_self();
pthread_detach(v1);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = func2(8889);
v2 = socket(2, 1, 0);
if ( bind(v2, &addr, 0x10u) )
{
puts("Can not bind address!");
result = -1LL;
}
else if ( listen(v2, 5) )
{
puts("Can not listen the port!");
result = -1LL;
}
else
{
v3 = _errno_location();
do
{
LABEL_4:
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[(unsigned int)v2 >> 6] |= 1LL << v2;
*v3 = 0;
if ( select(v2 + 1, &readfds, 0LL, 0LL, 0LL) < 0 )
break;
if ( (readfds.fds_bits[v2 / 64] & (1LL << (v2 % 64))) != 0 )
{
while ( 1 )
{
addr_len = 16;
v4 = accept(v2, &v7, &addr_len);
if ( v4 >= 0 )
break;
if ( *v3 != 4 )
goto LABEL_4;
}
data_fd = v4;
printf("%s %d connectd fd:%d\n", "server.c", 272LL, (unsigned int)v4);
}
}
}
while ( *v3 == 4 );
close(v2);
result = 0LL;
}
return result;
}

original_code:
void *wait_conncet(void * arg){
 pthread_detach(pthread_self());
 struct sockaddr_in s_addr;
 s_addr.sin_family = 2;
 s_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 s_addr.sin_port = htons(8889 );
 int newsockfd=-1, fd=-1;
 socklen_t clilen;
 struct sockaddr cli_addr;
 int reuse = 1;
 fd = socket(2, SOCK_STREAM, 0);
 if (bind(fd, (struct sockaddr*) &s_addr, sizeof(struct sockaddr))!= 0) {
   printf("Can not bind address!\n");
   return -1;
 }
 if (listen(fd, 5) != 0) {
  printf("Can not listen the port!\n");
  return -1;
 }
 for (;;) {
  unsigned int maxfd = 0;
  fd_set sockset;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&sockset)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&sockset)->__fds_bits)[(((unsigned) fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << (((unsigned) fd) % (8 * (int) sizeof (__fd_mask)))))));
  maxfd = maxfd > (unsigned) fd ? maxfd : fd;
  (*__errno_location ()) = 0;
  if (select(maxfd + 1, &sockset, ((void *)0), ((void *)0), ((void *)0)) < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   close(fd);
   break;
  }
  if (((((&sockset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   do {
    clilen = sizeof(cli_addr);
    newsockfd = accept(fd, &cli_addr, &clilen);
   } while (newsockfd < 0 && (*__errno_location ()) == 4);
   if (newsockfd < 0) {
    continue;
   }
   data_fd= newsockfd;
   printf("%s %d connectd fd:%d\n","server.c",272,data_fd);
  }
 }
 return ((void *)0);
}

canonical_original_code:
void *wait_conncet(void *arg){
 pthread_detach(pthread_self());
 struct sockaddr_in s_addr;
 s_addr.sin_family = 2;
 s_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 s_addr.sin_port = htons(8889 );
 int newsockfd = -1; int fd = -1;
 unsigned int clilen;
 struct sockaddr cli_addr;
 int reuse = 1;
 fd = socket(2, SOCK_STREAM, 0);
 if (bind(fd, (struct sockaddr *) &s_addr, sizeof(struct sockaddr))!= 0) {
   printf("Can not bind address!\n");
   return -1;
 }
 if (listen(fd, 5) != 0) {
  printf("Can not listen the port!\n");
  return -1;
 }
 for (;;) {
  unsigned int maxfd = 0;
  struct fd_set sockset;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&sockset)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&sockset)->__fds_bits)[(((unsigned int) fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << (((unsigned int) fd) % (8 * (int) sizeof (__fd_mask)))))));
  maxfd = maxfd > (unsigned int) fd ? maxfd : fd;
  (*__errno_location ()) = 0;
  if (select(maxfd + 1, &sockset, ((void *)0), ((void *)0), ((void *)0)) < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   close(fd);
   break;
  }
  if (((((&sockset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   do {
    clilen = sizeof(cli_addr);
    newsockfd = accept(fd, &cli_addr, &clilen);
   } while (newsockfd < 0 && (*__errno_location ()) == 4);
   if (newsockfd < 0) {
    continue;
   }
   data_fd= newsockfd;
   printf("%s %d connectd fd:%d\n","server.c",272,data_fd);
  }
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: newsockfd int

variable_types:
clilen
unsigned int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

variable_types: reuse int

variable_types:
maxfd
unsigned int

variable_types:
sockset
struct fd_set { long __fds_bits[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
char *make_dir()
{
const char *v0; // rbp
char *result; // rax
char *v2; // rbx

v0 = (const char *)(unsigned int)((_DWORD)&BackupVolPath + 1);
while ( 1 )
{
result = strchr(v0, 47);
v2 = result;
if ( !result )
break;
++v0;
if ( *result != *(result - 1) )
{
*result = 0;
if ( access(&BackupVolPath, 0) )
mkdir(&BackupVolPath, 0x1FFu);
*v2 = 47;
v0 = v2 + 1;
}
}
return result;
}

canonical_decompiled_code:
char *func5()
{
const char *v0; // rbp
char *result; // rax
char *v2; // rbx

v0 = (const char *)(unsigned int)((_DWORD)&BackupVolPath + 1);
while ( 1 )
{
result = strchr(v0, 47);
v2 = result;
if ( !result )
break;
++v0;
if ( *result != *(result - 1) )
{
*result = 0;
if ( access(&BackupVolPath, 0) )
mkdir(&BackupVolPath, 0x1FFu);
*v2 = 47;
v0 = v2 + 1;
}
}
return result;
}

variable_types:
p
char *

variable_types:
q
char *