sanitization

decompiled_code:
int sanitization()
{
_QWORD *v0; // r14
unsigned int v1; // eax
__int64 v3; // rbp
__int64 i; // rsi
int v5; // er12
int v6; // ebx
__int64 v7; // rax
__int64 v8; // r15
int v9; // eax
__int64 k; // r13
__int64 v11; // r13
__int64 v12; // rax
int v13; // eax
__int64 v14; // rax
unsigned int *v15; // r13
__int64 v16; // r15
__int64 v17; // rsi
_DWORD *v18; // r15
__int64 v19; // rdx
int *m; // rcx
int *v21; // rax
int *v22; // r8
__int64 l; // rax
double v24; // [rsp+8h] [rbp-120h]
__int64 v25; // [rsp+8h] [rbp-120h]
__int64 v26; // [rsp+8h] [rbp-120h]
int v27; // [rsp+8h] [rbp-120h]
int *v28; // [rsp+8h] [rbp-120h]
int *v29; // [rsp+8h] [rbp-120h]
__int64 v30; // [rsp+10h] [rbp-118h]
int j; // [rsp+10h] [rbp-118h]
unsigned int v32; // [rsp+1Ch] [rbp-10Ch]
double v33; // [rsp+20h] [rbp-108h]
double v34; // [rsp+28h] [rbp-100h]
double v35; // [rsp+30h] [rbp-F8h]
double v36; // [rsp+30h] [rbp-F8h]
double v37; // [rsp+40h] [rbp-E8h]
double v38; // [rsp+48h] [rbp-E0h]
struct timeval tv; // [rsp+50h] [rbp-D8h] BYREF
struct timeval v40; // [rsp+60h] [rbp-C8h] BYREF
struct timeval v41; // [rsp+70h] [rbp-B8h] BYREF
struct timeval v42; // [rsp+80h] [rbp-A8h] BYREF
struct timeval v43; // [rsp+90h] [rbp-98h] BYREF
struct timeval v44; // [rsp+A0h] [rbp-88h] BYREF
struct timeval v45; // [rsp+B0h] [rbp-78h] BYREF
struct timeval v46; // [rsp+C0h] [rbp-68h] BYREF
struct timeval v47; // [rsp+D0h] [rbp-58h] BYREF
struct timeval v48; // [rsp+E0h] [rbp-48h] BYREF

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

canonical_decompiled_code:
int func0()
{
_QWORD *v0; // r14
unsigned int v1; // eax
__int64 v3; // rbp
__int64 i; // rsi
int v5; // er12
int v6; // ebx
__int64 v7; // rax
__int64 v8; // r15
int v9; // eax
__int64 k; // r13
__int64 v11; // r13
__int64 v12; // rax
int v13; // eax
__int64 v14; // rax
unsigned int *v15; // r13
__int64 v16; // r15
__int64 v17; // rsi
_DWORD *v18; // r15
__int64 v19; // rdx
int *m; // rcx
int *v21; // rax
int *v22; // r8
__int64 l; // rax
double v24; // [rsp+8h] [rbp-120h]
__int64 v25; // [rsp+8h] [rbp-120h]
__int64 v26; // [rsp+8h] [rbp-120h]
int v27; // [rsp+8h] [rbp-120h]
int *v28; // [rsp+8h] [rbp-120h]
int *v29; // [rsp+8h] [rbp-120h]
__int64 v30; // [rsp+10h] [rbp-118h]
int j; // [rsp+10h] [rbp-118h]
unsigned int v32; // [rsp+1Ch] [rbp-10Ch]
double v33; // [rsp+20h] [rbp-108h]
double v34; // [rsp+28h] [rbp-100h]
double v35; // [rsp+30h] [rbp-F8h]
double v36; // [rsp+30h] [rbp-F8h]
double v37; // [rsp+40h] [rbp-E8h]
double v38; // [rsp+48h] [rbp-E0h]
struct timeval tv; // [rsp+50h] [rbp-D8h] BYREF
struct timeval v40; // [rsp+60h] [rbp-C8h] BYREF
struct timeval v41; // [rsp+70h] [rbp-B8h] BYREF
struct timeval v42; // [rsp+80h] [rbp-A8h] BYREF
struct timeval v43; // [rsp+90h] [rbp-98h] BYREF
struct timeval v44; // [rsp+A0h] [rbp-88h] BYREF
struct timeval v45; // [rsp+B0h] [rbp-78h] BYREF
struct timeval v46; // [rsp+C0h] [rbp-68h] BYREF
struct timeval v47; // [rsp+D0h] [rbp-58h] BYREF
struct timeval v48; // [rsp+E0h] [rbp-48h] BYREF

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

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; // rbp
__int64 v4; // rax
size_t v5; // rax
__m128i v6; // [rsp+0h] [rbp-58h] BYREF
__m128i v7; // [rsp+10h] [rbp-48h]
__int128 v8; // [rsp+20h] [rbp-38h]
__int16 v9; // [rsp+30h] [rbp-28h]

v9 = 0;
v2 = (unsigned int *)jcr_new();
v6 = 0LL;
v7 = 0LL;
v6.m128i_i16[0] = 19279;
v8 = 0LL;
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) )
{
LOBYTE(v8) = 0;
v6 = _mm_load_si128((const __m128i *)&LC15);
v7 = _mm_load_si128((const __m128i *)&LC16);
}
else
{
*(_DWORD *)(v4 + 4) = 1;
}
}
jobv_destroy(v4);
v5 = strlen(v6.m128i_i8);
bnet_send(a1, &v6, v5);
return jcr_free(v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
unsigned int *v2; // rbp
__int64 v4; // rax
size_t v5; // rax
__m128i v6; // [rsp+0h] [rbp-58h] BYREF
__m128i v7; // [rsp+10h] [rbp-48h]
__int128 v8; // [rsp+20h] [rbp-38h]
__int16 v9; // [rsp+30h] [rbp-28h]

v9 = 0;
v2 = (unsigned int *)jcr_new();
v6 = 0LL;
v7 = 0LL;
v6.m128i_i16[0] = 19279;
v8 = 0LL;
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) )
{
LOBYTE(v8) = 0;
v6 = _mm_load_si128((const __m128i *)&LC15);
v7 = _mm_load_si128((const __m128i *)&LC16);
}
else
{
*(_DWORD *)(v4 + 4) = 1;
}
}
jobv_destroy(v4);
v5 = strlen(v6.m128i_i8);
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; }


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 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 31 * v2;
v1 = *a1;
}
while ( *a1 );
return v2 & 0x7FFFFFFF;
}

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

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 31 * v2;
v1 = *a1;
}
while ( *a1 );
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


decompiled_code:
__int64 __fastcall RS_hash(_BYTE *a1)
{
int v1; // eax
int v2; // edx
int v3; // ecx
int v4; // edx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
v3 = 63689;
do
{
v4 = v3 * v2;
++a1;
v3 *= 378551;
v2 = v1 + v4;
v1 = (char)*a1;
}
while ( *a1 );
return v2 & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
int v1; // eax
int v2; // edx
int v3; // ecx
int v4; // edx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
v3 = 63689;
do
{
v4 = v3 * v2;
++a1;
v3 *= 378551;
v2 = v1 + v4;
v1 = (char)*a1;
}
while ( *a1 );
return v2 & 0x7FFFFFFF;
}

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);
}


decompiled_code:
__int64 __fastcall PJW_hash(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (char)*a1;
for ( result = 0LL; *a1; v1 = (char)*a1 )
{
++a1;
result = (unsigned int)(v1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((((unsigned int)result & 0xF0000000) >> 24) ^ (unsigned int)result) & 0xFFFFFFF;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (char)*a1;
for ( result = 0LL; *a1; v1 = (char)*a1 )
{
++a1;
result = (unsigned int)(v1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((((unsigned int)result & 0xF0000000) >> 24) ^ (unsigned int)result) & 0xFFFFFFF;
}
return result;
}

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


decompiled_code:
__int64 __fastcall ELF_hash(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (char)*a1;
result = 0LL;
if ( *a1 )
{
do
{
++a1;
LODWORD(result) = v1 + 16 * result;
if ( (result & 0xF0000000) != 0 )
LODWORD(result) = ~(result & 0xF0000000) & ((((unsigned int)result & 0xF0000000) >> 24) ^ result);
v1 = (char)*a1;
}
while ( *a1 );
result &= 0x7FFFFFFFu;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (char)*a1;
result = 0LL;
if ( *a1 )
{
do
{
++a1;
LODWORD(result) = v1 + 16 * result;
if ( (result & 0xF0000000) != 0 )
LODWORD(result) = ~(result & 0xF0000000) & ((((unsigned int)result & 0xF0000000) >> 24) ^ result);
v1 = (char)*a1;
}
while ( *a1 );
result &= 0x7FFFFFFFu;
}
return result;
}

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(_BYTE *a1)
{
int v1; // eax
int v2; // edx

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

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

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = (char)*a1;
}
while ( *a1 );
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(_BYTE *a1)
{
int v1; // eax
int v2; // edx

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

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
int v1; // eax
int v2; // edx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 65599 * v2;
v1 = (char)*a1;
}
while ( *a1 );
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);
}


decompiled_code:
__int64 __fastcall DJB_hash(_BYTE *a1)
{
int v1; // eax
int v2; // ecx

v1 = (char)*a1;
if ( !*a1 )
return 5381LL;
v2 = 5381;
do
{
++a1;
v2 += 32 * v2 + v1;
v1 = (char)*a1;
}
while ( *a1 );
return v2 & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
int v1; // eax
int v2; // ecx

v1 = (char)*a1;
if ( !*a1 )
return 5381LL;
v2 = 5381;
do
{
++a1;
v2 += 32 * v2 + v1;
v1 = (char)*a1;
}
while ( *a1 );
return v2 & 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
__int64 v7; // rdx
unsigned int v8; // edx
unsigned __int16 v10; // [rsp+Eh] [rbp-Ah]

v1 = a1;
v2 = strlen(a1);
HIBYTE(v10) = 0;
if ( v2 <= 1 )
{
v8 = v2;
v5 = a1;
v6 = 0LL;
}
else
{
v3 = v2 - 2;
v4 = (v2 - 2) >> 1;
v5 = &v1[2 * v4 + 2];
v6 = 0LL;
do
{
v7 = *(unsigned __int16 *)v1;
v1 += 2;
v6 += v7;
}
while ( v1 != v5 );
v8 = v3 - 2 * v4;
}
if ( v8 == 1 )
{
LOBYTE(v10) = *v5;
v6 += v10;
}
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
__int64 v7; // rdx
unsigned int v8; // edx
unsigned __int16 v10; // [rsp+Eh] [rbp-Ah]

v1 = a1;
v2 = strlen(a1);
HIBYTE(v10) = 0;
if ( v2 <= 1 )
{
v8 = v2;
v5 = a1;
v6 = 0LL;
}
else
{
v3 = v2 - 2;
v4 = (v2 - 2) >> 1;
v5 = &v1[2 * v4 + 2];
v6 = 0LL;
do
{
v7 = *(unsigned __int16 *)v1;
v1 += 2;
v6 += v7;
}
while ( v1 != v5 );
v8 = v3 - 2 * v4;
}
if ( v8 == 1 )
{
LOBYTE(v10) = *v5;
v6 += v10;
}
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:
// attributes: thunk
void jcr_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

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 func2(__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; // edx
int v2; // ebp
__int64 v3; // rcx
_QWORD *v4; // rax
__int64 v5; // rsi
int v6; // edx
_QWORD *v7; // rax
unsigned int v8; // er12
__int64 v9; // rdx
__int64 i; // rbx
__int64 v11; // rsi
__int64 v13[2]; // [rsp+0h] [rbp-38h]
__int64 v14; // [rsp+10h] [rbp-28h]

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");
v1 = *(_DWORD *)(a1 + 32);
v13[0] = 0LL;
v13[1] = 0LL;
v14 = 0LL;
if ( v1 <= 0 )
{
v9 = 0LL;
v8 = 0;
v2 = 0;
}
else
{
v2 = 0;
v3 = *(_QWORD *)a1 + 8LL;
v4 = **(_QWORD ***)a1;
v5 = v3 + 8LL * (unsigned int)(v1 - 1);
v6 = 0;
if ( v4 )
goto LABEL_3;
LABEL_9:
while ( 1 )
{
v7 = (_QWORD *)v3;
++*((_DWORD *)v13 + v6);
if ( v3 == v5 )
break;
while ( 1 )
{
v4 = (_QWORD *)*v7;
v3 += 8LL;
v6 = 0;
if ( !v4 )
break;
do
{
LABEL_3:
v4 = (_QWORD *)*v4;
++v6;
}
while ( v4 );
if ( v2 < v6 )
v2 = v6;
if ( v6 <= 4 )
goto LABEL_9;
++HIDWORD(v14);
v7 = (_QWORD *)v3;
if ( v3 == v5 )
goto LABEL_10;
}
}
LABEL_10:
v8 = HIDWORD(v14);
v9 = LODWORD(v13[0]);
}
for ( i = 0LL; ; v9 = *((unsigned int *)v13 + i) )
{
v11 = (unsigned int)i++;
printf("%2d: %d\n", v11, v9);
if ( i == 5 )
break;
}
printf("more: %d\n", v8);
printf("max itme counts in a bucket : %d\n", (unsigned int)v2);
return puts("\n=====================htable stat======================");
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int v1; // edx
int v2; // ebp
__int64 v3; // rcx
_QWORD *v4; // rax
__int64 v5; // rsi
int v6; // edx
_QWORD *v7; // rax
unsigned int v8; // er12
__int64 v9; // rdx
__int64 i; // rbx
__int64 v11; // rsi
__int64 v13[2]; // [rsp+0h] [rbp-38h]
__int64 v14; // [rsp+10h] [rbp-28h]

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");
v1 = *(_DWORD *)(a1 + 32);
v13[0] = 0LL;
v13[1] = 0LL;
v14 = 0LL;
if ( v1 <= 0 )
{
v9 = 0LL;
v8 = 0;
v2 = 0;
}
else
{
v2 = 0;
v3 = *(_QWORD *)a1 + 8LL;
v4 = **(_QWORD ***)a1;
v5 = v3 + 8LL * (unsigned int)(v1 - 1);
v6 = 0;
if ( v4 )
goto LABEL_3;
LABEL_9:
while ( 1 )
{
v7 = (_QWORD *)v3;
++*((_DWORD *)v13 + v6);
if ( v3 == v5 )
break;
while ( 1 )
{
v4 = (_QWORD *)*v7;
v3 += 8LL;
v6 = 0;
if ( !v4 )
break;
do
{
LABEL_3:
v4 = (_QWORD *)*v4;
++v6;
}
while ( v4 );
if ( v2 < v6 )
v2 = v6;
if ( v6 <= 4 )
goto LABEL_9;
++HIDWORD(v14);
v7 = (_QWORD *)v3;
if ( v3 == v5 )
goto LABEL_10;
}
}
LABEL_10:
v8 = HIDWORD(v14);
v9 = LODWORD(v13[0]);
}
for ( i = 0LL; ; v9 = *((unsigned int *)v13 + i) )
{
v11 = (unsigned int)i++;
printf("%2d: %d\n", v11, v9);
if ( i == 5 )
break;
}
printf("more: %d\n", v8);
printf("max itme counts in a bucket : %d\n", (unsigned int)v2);
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)
{
__int64 v2; // r13
int v3; // ebp
__int64 v5; // rbx
_QWORD *v6; // r15
__int64 result; // rax
void *v8; // rdi
__int64 v9; // rax
__int64 *v10; // [rsp+8h] [rbp-40h]

hash_index(a1, a2);
v2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a1[10]);
v10 = (__int64 *)(*(_QWORD *)a1 + 8LL * (unsigned int)a1[10]);
if ( !v2 )
return 0LL;
v3 = a1[9];
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a1[10]);
v6 = 0LL;
while ( v3 != *(_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;
}
v8 = (void *)(v5 - (int)a1[2]);
v9 = *(_QWORD *)v5;
if ( v2 == v5 )
*v10 = v9;
else
*v6 = v9;
free(v8);
--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


decompiled_code:
__int64 __fastcall htable_add(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx
_QWORD *v4; // rax
int v5; // ecx
__int64 result; // rax

if ( a2 )
{
v3 = *(int *)(a1 + 8) + a3;
v4 = (_QWORD *)(*(_QWORD *)a1 + 8LL * *(unsigned int *)(a1 + 40));
*(_QWORD *)v3 = *v4;
v5 = *(_DWORD *)(a1 + 36);
*(_QWORD *)(v3 + 16) = a2;
*(_DWORD *)(v3 + 8) = v5;
*v4 = v3;
LODWORD(v4) = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = (_DWORD)v4;
if ( (unsigned int)v4 >= *(_DWORD *)(a1 + 20) )
grow_table(a1);
result = 1LL;
}
else
{
printf("%s,%d,key==NULL\n", "libs/htable.c", 293LL);
result = 0LL;
}
return result;
}

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 = 0LL;
v6 = 0;
SHA1_Init(v7);
SHA1_Update(v7, a1, a2);
SHA1_Final(&v5, v7);
result = v6;
*a3 = _mm_loadu_si128(&v5);
a3[1].m128i_i32[0] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__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 = 0LL;
v6 = 0;
SHA1_Init(v7);
SHA1_Update(v7, a1, a2);
SHA1_Final(&v5, v7);
result = v6;
*a3 = _mm_loadu_si128(&v5);
a3[1].m128i_i32[0] = result;
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; // xmm5_8
double v4; // xmm0_8
double v5; // xmm3_8
double v6; // xmm0_8
int v7; // edx
unsigned int v8; // er12
bool v9; // zf
double v10; // xmm0_8
__int64 v11; // rax
double v12; // xmm1_8
bool v13; // dl
int v15[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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

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

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, char *a4)
{
__int64 v5; // rbx
int v6; // er12
__int64 v7; // r8
__int64 v8; // rax
char *v9; // rax

v5 = *(_QWORD *)(a3 + 264);
memset(a4, 0, 0x10000uLL);
if ( v5 )
{
v6 = 0;
do
{
while ( 1 )
{
v7 = index_lookup(a2, v5);
v8 = v6++;
v9 = &a4[v8];
if ( v7 )
{
*(_BYTE *)(v5 + 36) = 1;
*v9 = 49;
}
else
{
*v9 = 48;
}
if ( v6 > 0xFFFF )
break;
v5 = *(_QWORD *)(v5 + 40);
if ( !v5 )
goto LABEL_8;
}
printf("%s %d bigBuf is not enough\n", "backup_dedup.c", 22LL);
bnet_send(a1, a4, (unsigned int)v6);
memset(a4, 0, 0x10000uLL);
v5 = *(_QWORD *)(v5 + 40);
v6 = 0;
}
while ( v5 );
LABEL_8:
if ( v6 )
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, char *a4)
{
__int64 v5; // rbx
int v6; // er12
__int64 v7; // r8
__int64 v8; // rax
char *v9; // rax

v5 = *(_QWORD *)(a3 + 264);
memset(a4, 0, 0x10000uLL);
if ( v5 )
{
v6 = 0;
do
{
while ( 1 )
{
v7 = index_lookup(a2, v5);
v8 = v6++;
v9 = &a4[v8];
if ( v7 )
{
*(_BYTE *)(v5 + 36) = 1;
*v9 = 49;
}
else
{
*v9 = 48;
}
if ( v6 > 0xFFFF )
break;
v5 = *(_QWORD *)(v5 + 40);
if ( !v5 )
goto LABEL_8;
}
printf("%s %d bigBuf is not enough\n", "backup_dedup.c", 22LL);
bnet_send(a1, a4, (unsigned int)v6);
memset(a4, 0, 0x10000uLL);
v5 = *(_QWORD *)(v5 + 40);
v6 = 0;
}
while ( v5 );
LABEL_8:
if ( v6 )
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; }


decompiled_code:
__int64 __fastcall backup_dedup(unsigned int a1, __int64 a2)
{
char *v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // rdi
_DWORD *v8; // rax
double v9; // xmm0_8
double v10; // xmm1_8
int v11; // eax
int *v12; // r13
__int64 i; // rdi
__int64 v14; // rax
__int64 v15; // rax
char *v16; // r13
char *v17; // rdi
__int64 v18; // rax
int v19; // ecx
__int64 v20; // rdx
double v21; // [rsp+0h] [rbp-1C0h]
int v23; // [rsp+1Ch] [rbp-1A4h] BYREF
int v24; // [rsp+20h] [rbp-1A0h]
int v25; // [rsp+24h] [rbp-19Ch] BYREF
struct timeval v26; // [rsp+28h] [rbp-198h] BYREF
struct timeval tv; // [rsp+38h] [rbp-188h] BYREF
struct timeval v28; // [rsp+48h] [rbp-178h] BYREF
struct timeval v29; // [rsp+58h] [rbp-168h] BYREF
struct timeval v30; // [rsp+68h] [rbp-158h] BYREF
struct timeval v31; // [rsp+78h] [rbp-148h] BYREF
__int128 v32[19]; // [rsp+88h] [rbp-138h] BYREF

v32[0] = 0LL;
v32[1] = 0LL;
v32[2] = 0LL;
v32[3] = 0LL;
v32[4] = 0LL;
v32[5] = 0LL;
v32[6] = 0LL;
v32[7] = 0LL;
v32[8] = 0LL;
v32[9] = 0LL;
v32[10] = 0LL;
v32[11] = 0LL;
v32[12] = 0LL;
v32[13] = 0LL;
v32[14] = 0LL;
v32[15] = 0LL;
v2 = (char *)calloc(1uLL, 0x10015uLL);
container_vol_init();
jobcount_init();
v3 = jcr_new();
*(_DWORD *)(v3 + 4) = a1;
v4 = v3;
*(_QWORD *)(v3 + 568) = index_init();
*(_QWORD *)(v4 + 576) = container_new();
if ( (unsigned int)_isoc99_sscanf(a2, &backup_cmd, v32) == 1 )
{
v5 = 0LL;
v8 = (_DWORD *)jobv_new(v32);
*(_QWORD *)(v4 + 560) = v8;
*(_DWORD *)v4 = *v8;
puts("===========backup start==============");
printf("%s,%d pathname:%s \n", "backup_dedup.c", 63LL, (const char *)v32);
gettimeofday(&v26, 0LL);
v21 = *(double *)&LC6;
while ( (unsigned int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v23) != -100 )
{
if ( v23 == -6 )
{
printf("%s %d backup is over\n", "backup_dedup.c", 72LL);
break;
}
*(_QWORD *)(v4 + 544) += v23;
if ( (unsigned int)_isoc99_sscanf(v2, "%d %d", &v25) != 2 )
break;
switch ( v24 )
{
case 2:
while ( (int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v23) > 0 )
{
v15 = v23;
v16 = v2;
*(_QWORD *)(v4 + 544) += v23;
if ( v15 > 0 )
{
do
{
v17 = v16;
v16 += 20;
v18 = fingerchunk_new(v17, 0LL);
recipe_append_fingerchunk(v5, v18);
}
while ( v16 - v2 < v23 );
}
}
gettimeofday(&v28, 0LL);
dedup_mark_send(a1, *(_QWORD *)(v4 + 568), v5, v2);
gettimeofday(&v29, 0LL);
*(double *)(v4 + 584) = (double)(LODWORD(v29.tv_usec) - LODWORD(v28.tv_usec)) / 1000000.0
+ (double)(LODWORD(v29.tv_sec) - LODWORD(v28.tv_sec))
+ *(double *)(v4 + 584);
break;
case 3:
while ( (int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v23) > 0 )
{
v11 = v23;
*(_QWORD *)(v4 + 544) += v23;
v12 = (int *)chunk_new(v2, v2 + 20, (unsigned int)(v11 - 20));
gettimeofday(&v30, 0LL);
for ( i = *(_QWORD *)(v4 + 576); !(unsigned int)write_chunk(i, v12); i = v14 )
{
write_container(*(_QWORD *)(v4 + 576));
index_insert(*(_QWORD *)(v4 + 568), *(_QWORD *)(v4 + 576));
container_destroy(*(_QWORD *)(v4 + 576));
v14 = container_new();
*(_QWORD *)(v4 + 576) = v14;
}
gettimeofday(&v31, 0LL);
v9 = (double)(LODWORD(v31.tv_usec) - LODWORD(v30.tv_usec)) / 1000000.0;
v10 = (double)(LODWORD(v31.tv_sec) - LODWORD(v30.tv_sec));
++*(_DWORD *)(v4 + 556);
*(_QWORD *)(v4 + 536) += *v12;
*(double *)(v4 + 592) = v9 + v10 + *(double *)(v4 + 592);
chunk_free(v12);
}
*(_DWORD *)(v4 + 552) += *(_DWORD *)(v5 + 4);
v19 = G_VERBOSE;
v20 = (unsigned int)(*(_DWORD *)(v4 + 524) + 1);
*(_DWORD *)(v4 + 524) = v20;
if ( v19 )
printf("receive file %s OK, total: %d\n", (const char *)(v5 + 8), v20);
jobv_insert_recipe(*(_QWORD *)(v4 + 560), v5);
recipe_free(v5);
v5 = recipe_new();
break;
case 1:
while ( (int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v23) > 0 )
{
*(_QWORD *)(v4 + 544) += v23;
v5 = recipe_new();
memcpy((void *)(v5 + 8), v2, v23);
*(_DWORD *)v5 = v25;
}
break;
default:
printf("%s %d wrong\n", "backup_dedup.c", 137LL);
break;
}
}
}
else
{
v5 = 0LL;
v21 = *(double *)&LC6;
}
gettimeofday(&tv, 0LL);
*(double *)(v4 + 608) = (double)(LODWORD(tv.tv_usec) - LODWORD(v26.tv_usec)) / v21
+ (double)(LODWORD(tv.tv_sec) - LODWORD(v26.tv_sec))
+ *(double *)(v4 + 608);
gettimeofday(&v30, 0LL);
v6 = *(_QWORD *)(v4 + 576);
if ( v6 )
{
if ( *(int *)(v6 + 4) > 0 )
{
write_container(v6);
index_insert(*(_QWORD *)(v4 + 568), *(_QWORD *)(v4 + 576));
v6 = *(_QWORD *)(v4 + 576);
}
container_destroy(v6);
}
bnet_send(a1, "OK", 2LL);
gettimeofday(&v31, 0LL);
*(double *)(v4 + 592) = (double)(LODWORD(v31.tv_usec) - LODWORD(v30.tv_usec)) / v21
+ (double)(LODWORD(v31.tv_sec) - LODWORD(v30.tv_sec))
+ *(double *)(v4 + 592);
puts("============back over===============");
printf(
"total time:%.4f throughput:%.4f MB/s\n",
*(double *)(v4 + 608),
(double)(int)*(_QWORD *)(v4 + 544) / *(double *)(v4 + 608) / 1036288.0);
printf("search time:%.4f \n ", *(double *)(v4 + 584));
printf(
"writedata time:%.4f throughput:%.4f MB/s\n",
*(double *)(v4 + 592),
(double)(int)*(_QWORD *)(v4 + 536) / *(double *)(v4 + 592) / 1036288.0);
printf("old chunk count:%d, deduped chunk count:%d\n", *(unsigned int *)(v4 + 552), *(unsigned int *)(v4 + 556));
if ( v5 )
recipe_free(v5);
jobv_destroy(*(_QWORD *)(v4 + 560));
jcr_free(v4);
container_vol_destroy();
jobcount_close();
return index_destroy(*(_QWORD *)(v4 + 568));
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
char *v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // rdi
_DWORD *v8; // rax
double v9; // xmm0_8
double v10; // xmm1_8
int v11; // eax
int *v12; // r13
__int64 i; // rdi
__int64 v14; // rax
__int64 v15; // rax
char *v16; // r13
char *v17; // rdi
__int64 v18; // rax
int v19; // ecx
__int64 v20; // rdx
double v21; // [rsp+0h] [rbp-1C0h]
int v23; // [rsp+1Ch] [rbp-1A4h] BYREF
int v24; // [rsp+20h] [rbp-1A0h]
int v25; // [rsp+24h] [rbp-19Ch] BYREF
struct timeval v26; // [rsp+28h] [rbp-198h] BYREF
struct timeval tv; // [rsp+38h] [rbp-188h] BYREF
struct timeval v28; // [rsp+48h] [rbp-178h] BYREF
struct timeval v29; // [rsp+58h] [rbp-168h] BYREF
struct timeval v30; // [rsp+68h] [rbp-158h] BYREF
struct timeval v31; // [rsp+78h] [rbp-148h] BYREF
__int128 v32[19]; // [rsp+88h] [rbp-138h] BYREF

v32[0] = 0LL;
v32[1] = 0LL;
v32[2] = 0LL;
v32[3] = 0LL;
v32[4] = 0LL;
v32[5] = 0LL;
v32[6] = 0LL;
v32[7] = 0LL;
v32[8] = 0LL;
v32[9] = 0LL;
v32[10] = 0LL;
v32[11] = 0LL;
v32[12] = 0LL;
v32[13] = 0LL;
v32[14] = 0LL;
v32[15] = 0LL;
v2 = (char *)calloc(1uLL, 0x10015uLL);
container_vol_init();
jobcount_init();
v3 = jcr_new();
*(_DWORD *)(v3 + 4) = a1;
v4 = v3;
*(_QWORD *)(v3 + 568) = index_init();
*(_QWORD *)(v4 + 576) = container_new();
if ( (unsigned int)_isoc99_sscanf(a2, &backup_cmd, v32) == 1 )
{
v5 = 0LL;
v8 = (_DWORD *)jobv_new(v32);
*(_QWORD *)(v4 + 560) = v8;
*(_DWORD *)v4 = *v8;
puts("===========backup start==============");
printf("%s,%d pathname:%s \n", "backup_dedup.c", 63LL, (const char *)v32);
gettimeofday(&v26, 0LL);
v21 = *(double *)&LC6;
while ( (unsigned int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v23) != -100 )
{
if ( v23 == -6 )
{
printf("%s %d backup is over\n", "backup_dedup.c", 72LL);
break;
}
*(_QWORD *)(v4 + 544) += v23;
if ( (unsigned int)_isoc99_sscanf(v2, "%d %d", &v25) != 2 )
break;
switch ( v24 )
{
case 2:
while ( (int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v23) > 0 )
{
v15 = v23;
v16 = v2;
*(_QWORD *)(v4 + 544) += v23;
if ( v15 > 0 )
{
do
{
v17 = v16;
v16 += 20;
v18 = fingerchunk_new(v17, 0LL);
recipe_append_fingerchunk(v5, v18);
}
while ( v16 - v2 < v23 );
}
}
gettimeofday(&v28, 0LL);
func0(a1, *(_QWORD *)(v4 + 568), v5, v2);
gettimeofday(&v29, 0LL);
*(double *)(v4 + 584) = (double)(LODWORD(v29.tv_usec) - LODWORD(v28.tv_usec)) / 1000000.0
+ (double)(LODWORD(v29.tv_sec) - LODWORD(v28.tv_sec))
+ *(double *)(v4 + 584);
break;
case 3:
while ( (int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v23) > 0 )
{
v11 = v23;
*(_QWORD *)(v4 + 544) += v23;
v12 = (int *)chunk_new(v2, v2 + 20, (unsigned int)(v11 - 20));
gettimeofday(&v30, 0LL);
for ( i = *(_QWORD *)(v4 + 576); !(unsigned int)write_chunk(i, v12); i = v14 )
{
write_container(*(_QWORD *)(v4 + 576));
index_insert(*(_QWORD *)(v4 + 568), *(_QWORD *)(v4 + 576));
container_destroy(*(_QWORD *)(v4 + 576));
v14 = container_new();
*(_QWORD *)(v4 + 576) = v14;
}
gettimeofday(&v31, 0LL);
v9 = (double)(LODWORD(v31.tv_usec) - LODWORD(v30.tv_usec)) / 1000000.0;
v10 = (double)(LODWORD(v31.tv_sec) - LODWORD(v30.tv_sec));
++*(_DWORD *)(v4 + 556);
*(_QWORD *)(v4 + 536) += *v12;
*(double *)(v4 + 592) = v9 + v10 + *(double *)(v4 + 592);
chunk_free(v12);
}
*(_DWORD *)(v4 + 552) += *(_DWORD *)(v5 + 4);
v19 = G_VERBOSE;
v20 = (unsigned int)(*(_DWORD *)(v4 + 524) + 1);
*(_DWORD *)(v4 + 524) = v20;
if ( v19 )
printf("receive file %s OK, total: %d\n", (const char *)(v5 + 8), v20);
jobv_insert_recipe(*(_QWORD *)(v4 + 560), v5);
recipe_free(v5);
v5 = recipe_new();
break;
case 1:
while ( (int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v23) > 0 )
{
*(_QWORD *)(v4 + 544) += v23;
v5 = recipe_new();
memcpy((void *)(v5 + 8), v2, v23);
*(_DWORD *)v5 = v25;
}
break;
default:
printf("%s %d wrong\n", "backup_dedup.c", 137LL);
break;
}
}
}
else
{
v5 = 0LL;
v21 = *(double *)&LC6;
}
gettimeofday(&tv, 0LL);
*(double *)(v4 + 608) = (double)(LODWORD(tv.tv_usec) - LODWORD(v26.tv_usec)) / v21
+ (double)(LODWORD(tv.tv_sec) - LODWORD(v26.tv_sec))
+ *(double *)(v4 + 608);
gettimeofday(&v30, 0LL);
v6 = *(_QWORD *)(v4 + 576);
if ( v6 )
{
if ( *(int *)(v6 + 4) > 0 )
{
write_container(v6);
index_insert(*(_QWORD *)(v4 + 568), *(_QWORD *)(v4 + 576));
v6 = *(_QWORD *)(v4 + 576);
}
container_destroy(v6);
}
bnet_send(a1, "OK", 2LL);
gettimeofday(&v31, 0LL);
*(double *)(v4 + 592) = (double)(LODWORD(v31.tv_usec) - LODWORD(v30.tv_usec)) / v21
+ (double)(LODWORD(v31.tv_sec) - LODWORD(v30.tv_sec))
+ *(double *)(v4 + 592);
puts("============back over===============");
printf(
"total time:%.4f throughput:%.4f MB/s\n",
*(double *)(v4 + 608),
(double)(int)*(_QWORD *)(v4 + 544) / *(double *)(v4 + 608) / 1036288.0);
printf("search time:%.4f \n ", *(double *)(v4 + 584));
printf(
"writedata time:%.4f throughput:%.4f MB/s\n",
*(double *)(v4 + 592),
(double)(int)*(_QWORD *)(v4 + 536) / *(double *)(v4 + 592) / 1036288.0);
printf("old chunk count:%d, deduped chunk count:%d\n", *(unsigned int *)(v4 + 552), *(unsigned int *)(v4 + 556));
if ( v5 )
recipe_free(v5);
jobv_destroy(*(_QWORD *)(v4 + 560));
jcr_free(v4);
container_vol_destroy();
jobcount_close();
return index_destroy(*(_QWORD *)(v4 + 568));
}

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; // r12
__int64 v2; // rax

v1 = (char *)malloc(0x98uLL);
v2 = queue_new();
*((_DWORD *)v1 + 2) = a1;
*(_QWORD *)v1 = v2;
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) )
{
return v1;
}
puts("Failed to init mutex or work in PipelineQueue!");
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
char *v1; // r12
__int64 v2; // rax

v1 = (char *)malloc(0x98uLL);
v2 = queue_new();
*((_DWORD *)v1 + 2) = a1;
*(_QWORD *)v1 = v2;
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) )
{
return v1;
}
puts("Failed to init mutex or work in PipelineQueue!");
return 0LL;
}

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 v3; // r12

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

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

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

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 *