decompiled_code:
int __fastcall index_open(_QWORD *a1)
{
int v1; // eax
int v2; // er12
unsigned int v4; // ebx
char *v5; // rbp
unsigned int buf; // [rsp+0h] [rbp-12Ch] BYREF
char dest[16]; // [rsp+4h] [rbp-128h] BYREF
__int128 v8; // [rsp+14h] [rbp-118h]
__int128 v9; // [rsp+24h] [rbp-108h]
__int128 v10; // [rsp+34h] [rbp-F8h]
__int128 v11; // [rsp+44h] [rbp-E8h]
__int128 v12; // [rsp+54h] [rbp-D8h]
__int128 v13; // [rsp+64h] [rbp-C8h]
__int128 v14; // [rsp+74h] [rbp-B8h]
__int128 v15; // [rsp+84h] [rbp-A8h]
__int128 v16; // [rsp+94h] [rbp-98h]
__int128 v17; // [rsp+A4h] [rbp-88h]
__int128 v18; // [rsp+B4h] [rbp-78h]
__int128 v19; // [rsp+C4h] [rbp-68h]
__int128 v20; // [rsp+D4h] [rbp-58h]
__int128 v21; // [rsp+E4h] [rbp-48h]
__int128 v22; // [rsp+F4h] [rbp-38h]

buf = 0;
*(_OWORD *)dest = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
strcpy(stpcpy(dest, &BackupVolPath), "global_index");
v1 = open(dest, 66, 384LL);
if ( v1 < 0 )
return printf("%s,%d file open wrong \n", "index/index.c", 15LL);
v2 = v1;
lseek(v1, 0LL, 0);
if ( read(v2, &buf, 4uLL) == 4 )
{
if ( buf )
{
v4 = 0;
do
{
++v4;
v5 = (char *)malloc(0x30uLL);
read(v2, v5, 0x14uLL);
read(v2, v5 + 20, 4uLL);
htable_insert(*a1, v5, v5);
}
while ( buf > v4 );
}
printf("%s,%d,total index items:%u\n", "index/index.c", 26LL, *(unsigned int *)(*a1 + 16LL));
}
return close(v2);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1)
{
int v1; // eax
int v2; // er12
unsigned int v4; // ebx
char *v5; // rbp
unsigned int buf; // [rsp+0h] [rbp-12Ch] BYREF
char dest[16]; // [rsp+4h] [rbp-128h] BYREF
__int128 v8; // [rsp+14h] [rbp-118h]
__int128 v9; // [rsp+24h] [rbp-108h]
__int128 v10; // [rsp+34h] [rbp-F8h]
__int128 v11; // [rsp+44h] [rbp-E8h]
__int128 v12; // [rsp+54h] [rbp-D8h]
__int128 v13; // [rsp+64h] [rbp-C8h]
__int128 v14; // [rsp+74h] [rbp-B8h]
__int128 v15; // [rsp+84h] [rbp-A8h]
__int128 v16; // [rsp+94h] [rbp-98h]
__int128 v17; // [rsp+A4h] [rbp-88h]
__int128 v18; // [rsp+B4h] [rbp-78h]
__int128 v19; // [rsp+C4h] [rbp-68h]
__int128 v20; // [rsp+D4h] [rbp-58h]
__int128 v21; // [rsp+E4h] [rbp-48h]
__int128 v22; // [rsp+F4h] [rbp-38h]

buf = 0;
*(_OWORD *)dest = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
strcpy(stpcpy(dest, &BackupVolPath), "global_index");
v1 = open(dest, 66, 384LL);
if ( v1 < 0 )
return printf("%s,%d file open wrong \n", "index/index.c", 15LL);
v2 = v1;
lseek(v1, 0LL, 0);
if ( read(v2, &buf, 4uLL) == 4 )
{
if ( buf )
{
v4 = 0;
do
{
++v4;
v5 = (char *)malloc(0x30uLL);
read(v2, v5, 0x14uLL);
read(v2, v5 + 20, 4uLL);
htable_insert(*a1, v5, v5);
}
while ( buf > v4 );
}
printf("%s,%d,total index items:%u\n", "index/index.c", 26LL, *(unsigned int *)(*a1 + 16LL));
}
return close(v2);
}

original_code:
void index_open(MemIndex* memdex){
 char path[256]={0};
 int fd;
 unsigned int count=0;
 int i;
 ContainerAddr * cddr=((void *)0);
 strcpy(path,BackupVolPath);
 strcat(path,"global_index");
 fd=open(path, 02 | 0100 , 0400|0200);
 if(fd<0){
  printf("%s,%d file open wrong \n","index/index.c",15);
  return;
 }
 lseek(fd, 0, 0);
 if(read(fd,&count,4)==4){
  for(i=0;i<count;i++){
   cddr=(ContainerAddr*)malloc(sizeof(ContainerAddr));
   read(fd,cddr->hash,sizeof(Fingerprint));
   read(fd,&cddr->container_id,4);
   htable_insert(memdex->index_table,cddr->hash,cddr);
  }
  printf("%s,%d,total index items:%u\n","index/index.c",26,memdex->index_table->num_items);
 }
 close(fd);
}

canonical_original_code:
void index_open(struct mem_index *memdex){
 char path[256] = {0};
 int fd;
 unsigned int count = 0;
 int i;
 struct container_index *cddr = ((void *)0);
 strcpy(path,BackupVolPath);
 strcat(path,"global_index");
 fd=open(path, 02 | 0100 , 0400|0200);
 if(fd<0){
  printf("%s,%d file open wrong \n","index/index.c",15);
  return;
 }
 lseek(fd, 0, 0);
 if(read(fd,&count,4)==4){
  for(i=0;i<count;i++){
   cddr=(struct container_index *)malloc(sizeof(ContainerAddr));
   read(fd,cddr->hash,sizeof(Fingerprint));
   read(fd,&cddr->container_id,4);
   htable_insert(memdex->index_table,cddr->hash,cddr);
  }
  printf("%s,%d,total index items:%u\n","index/index.c",26,memdex->index_table->num_items);
 }
 close(fd);
}

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:
count
unsigned 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; } *

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: struct container_index { unsigned char hash[20]; int container_id; struct hlink_t next; }

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

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


repo: zhoupj/Deduper

decompiled_code:
int __fastcall index_close(_QWORD *a1)
{
int v1; // eax
int v2; // ebp
__int64 i; // rbx
__int128 v5[17]; // [rsp+0h] [rbp-118h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v5[6] = 0LL;
v5[7] = 0LL;
v5[8] = 0LL;
v5[9] = 0LL;
v5[10] = 0LL;
v5[11] = 0LL;
v5[12] = 0LL;
v5[13] = 0LL;
v5[14] = 0LL;
v5[15] = 0LL;
strcpy(stpcpy((char *)v5, &BackupVolPath), "global_index");
v1 = open((const char *)v5, 2);
if ( v1 < 0 )
return printf("%s,%d file open wrong \n", "index/index.c", 40LL);
v2 = v1;
lseek(v1, 0LL, 0);
write(v2, (const void *)(*a1 + 16LL), 4uLL);
for ( i = htable_get_first(*a1); i; i = htable_get_next(*a1) )
{
write(v2, (const void *)i, 0x14uLL);
write(v2, (const void *)(i + 20), 4uLL);
}
return close(v2);
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1)
{
int v1; // eax
int v2; // ebp
__int64 i; // rbx
__int128 v5[17]; // [rsp+0h] [rbp-118h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v5[6] = 0LL;
v5[7] = 0LL;
v5[8] = 0LL;
v5[9] = 0LL;
v5[10] = 0LL;
v5[11] = 0LL;
v5[12] = 0LL;
v5[13] = 0LL;
v5[14] = 0LL;
v5[15] = 0LL;
strcpy(stpcpy((char *)v5, &BackupVolPath), "global_index");
v1 = open((const char *)v5, 2);
if ( v1 < 0 )
return printf("%s,%d file open wrong \n", "index/index.c", 40LL);
v2 = v1;
lseek(v1, 0LL, 0);
write(v2, (const void *)(*a1 + 16LL), 4uLL);
for ( i = htable_get_first(*a1); i; i = htable_get_next(*a1) )
{
write(v2, (const void *)i, 0x14uLL);
write(v2, (const void *)(i + 20), 4uLL);
}
return close(v2);
}

original_code:
void index_close(MemIndex* memdex){
 char path[256]={0};
 int fd;
 strcpy(path,BackupVolPath);
 strcat(path,"global_index");
 fd=open(path, 02);
 if(fd<0){
  printf("%s,%d file open wrong \n","index/index.c",40);
  return;
 }
  lseek(fd, 0, 0);
 ContainerAddr * cddr=((void *)0);
 write(fd,&(memdex->index_table->num_items),sizeof(int));
  for((*((void **)&(cddr))=(void *)(htable_get_first((memdex->index_table)))); (cddr); (*((void **)&(cddr))=(void *)(htable_get_next(memdex->index_table)))){
   write(fd,cddr->hash,sizeof(Fingerprint));
  write(fd,&cddr->container_id,sizeof(int));
  }
  close(fd);
}

canonical_original_code:
void index_close(struct mem_index *memdex){
 char path[256] = {0};
 int fd;
 strcpy(path,BackupVolPath);
 strcat(path,"global_index");
 fd=open(path, 02);
 if(fd<0){
  printf("%s,%d file open wrong \n","index/index.c",40);
  return;
 }
  lseek(fd, 0, 0);
 struct container_index *cddr = ((void *)0);
 write(fd,&(memdex->index_table->num_items),sizeof(int));
  for((*((void **)&(cddr))=(void *)(htable_get_first((memdex->index_table)))); (cddr); (*((void **)&(cddr))=(void *)(htable_get_next(memdex->index_table)))){
   write(fd,cddr->hash,sizeof(Fingerprint));
  write(fd,&cddr->container_id,sizeof(int));
  }
  close(fd);
}

variable_types:
path
char [256]

variable_types: fd int

return_type: void

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

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_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

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

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


decompiled_code:
char *index_init()
{
char *v0; // r12

v0 = (char *)malloc(0x48uLL);
*(_QWORD *)v0 = htable_init(24LL, 20LL, 0xFFFFFFLL);
*((_QWORD *)v0 + 1) = htable_init(32LL, 20LL, 10240LL);
*((_QWORD *)v0 + 2) = cache_init(31457280LL);
pthread_mutex_init((pthread_mutex_t *)(v0 + 32), 0LL);
index_open(v0);
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // r12

v0 = (char *)malloc(0x48uLL);
*(_QWORD *)v0 = htable_init(24LL, 20LL, 0xFFFFFFLL);
*((_QWORD *)v0 + 1) = htable_init(32LL, 20LL, 10240LL);
*((_QWORD *)v0 + 2) = cache_init(31457280LL);
pthread_mutex_init((pthread_mutex_t *)(v0 + 32), 0LL);
func0(v0);
return v0;
}

original_code:
MemIndex* index_init(){
 MemIndex * index=(MemIndex *)malloc(sizeof(MemIndex));
 ContainerAddr caddr;
 ChunkAddr cdr;
 index->index_table=htable_init((char*)&(caddr.next)-(char*)&caddr,sizeof(Fingerprint),16777215);
 index->index_new=htable_init((char*)&(cdr.next)-(char*)&cdr,sizeof(Fingerprint),10*1024);
 index->index_cache=cache_init(30*1024*1024);
  pthread_mutex_init(&index->mutex, 0);
  index_open(index);
 return index;
}

canonical_original_code:
struct mem_index *index_init(){
 struct mem_index *index = (MemIndex *)malloc(sizeof(MemIndex));
 struct container_index caddr;
 struct chunk_address cdr;
 index->index_table=htable_init((char *)&(caddr.next)-(char *)&caddr,sizeof(Fingerprint),16777215);
 index->index_new=htable_init((char *)&(cdr.next)-(char *)&cdr,sizeof(Fingerprint),10*1024);
 index->index_cache=cache_init(30*1024*1024);
  pthread_mutex_init(&index->mutex, 0);
  index_open(index);
 return index;
}

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

return_type: 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; } *

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


decompiled_code:
int __fastcall index_insert(__int64 *a1, __int64 a2)
{
pthread_mutex_t *v2; // r13
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
__m128i *v7; // rax
__int64 v8; // rdi

v2 = (pthread_mutex_t *)(a1 + 4);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 4));
v4 = htable_get_first(*(_QWORD *)(a2 + 16));
if ( v4 )
{
v5 = v4;
do
{
v6 = htable_lookup(*a1, v5 + 12);
if ( v6 )
{
*(_DWORD *)(v6 + 20) = *(_DWORD *)a2;
}
else
{
v7 = (__m128i *)malloc(0x30uLL);
v8 = *a1;
v7[1].m128i_i32[1] = *(_DWORD *)a2;
*v7 = _mm_loadu_si128((const __m128i *)(v5 + 12));
v7[1].m128i_i32[0] = *(_DWORD *)(v5 + 28);
htable_add(v8, v7, v7);
}
htable_remove(a1[1], v5 + 12);
v5 = htable_get_next(*(_QWORD *)(a2 + 16));
}
while ( v5 );
}
return pthread_mutex_unlock(v2);
}

original_code:
void index_insert(MemIndex* memdex,Container * ct){
 pthread_mutex_lock(&memdex->mutex);
 ChunkAddr*cddr;
 ContainerAddr *ctner;
  for((*((void **)&(cddr))=(void *)(htable_get_first((ct->meta_table)))); (cddr); (*((void **)&(cddr))=(void *)(htable_get_next(ct->meta_table)))){
   ctner=htable_lookup(memdex->index_table,cddr->hash);
  if(ctner){
   ctner->container_id=ct->container_id;
  }
  else{
   ctner=(ContainerAddr *)malloc(sizeof(ContainerAddr));
   ctner->container_id=ct->container_id;
   memcpy(ctner->hash,cddr->hash,sizeof(Fingerprint));
   htable_add(memdex->index_table,ctner->hash,ctner);
  }
  htable_remove(memdex->index_new,cddr->hash);
  }
 pthread_mutex_unlock(&memdex->mutex);
}

canonical_original_code:
void index_insert(struct mem_index *memdex, struct container_tag *ct){
 pthread_mutex_lock(&memdex->mutex);
 struct chunk_address *cddr;
 struct container_index *ctner;
  for((*((void **)&(cddr))=(void *)(htable_get_first((ct->meta_table)))); (cddr); (*((void **)&(cddr))=(void *)(htable_get_next(ct->meta_table)))){
   ctner=htable_lookup(memdex->index_table,cddr->hash);
  if(ctner){
   ctner->container_id=ct->container_id;
  }
  else{
   ctner=(struct container_index *)malloc(sizeof(ContainerAddr));
   ctner->container_id=ct->container_id;
   memcpy(ctner->hash,cddr->hash,sizeof(Fingerprint));
   htable_add(memdex->index_table,ctner->hash,ctner);
  }
  htable_remove(memdex->index_new,cddr->hash);
  }
 pthread_mutex_unlock(&memdex->mutex);
}

variable_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; } *

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


decompiled_code:
__int64 __fastcall index_lookup(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // rbp
__int64 v3; // rax
__int64 v4; // r12
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdi

v2 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v3 = cache_search(*(_QWORD *)(a1 + 16), a2);
if ( v3 )
{
LABEL_2:
v4 = v3;
goto LABEL_3;
}
v6 = htable_lookup(*(_QWORD *)a1, a2);
if ( v6 )
{
v7 = read_container(*(unsigned int *)(v6 + 20));
v4 = v7;
if ( !v7 )
{
err_msg("index/index.c", 129LL, "container read error");
pthread_mutex_unlock(v2);
return v4;
}
cache_insert(*(_QWORD *)(a1 + 16), v7);
container_destroy(v4);
v3 = cache_search(*(_QWORD *)(a1 + 16), a2);
goto LABEL_2;
}
v4 = htable_lookup(*(_QWORD *)(a1 + 8), a2);
if ( !v4 )
{
v8 = chunkaddr_new(a2, 0LL, 0LL);
v9 = *(_QWORD *)(a1 + 8);
*(_DWORD *)(v8 + 8) = 0;
htable_add(v9, v8 + 12, v8);
pthread_mutex_unlock(v2);
return v4;
}
LABEL_3:
pthread_mutex_unlock(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // rbp
__int64 v3; // rax
__int64 v4; // r12
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdi

v2 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v3 = cache_search(*(_QWORD *)(a1 + 16), a2);
if ( v3 )
{
LABEL_2:
v4 = v3;
goto LABEL_3;
}
v6 = htable_lookup(*(_QWORD *)a1, a2);
if ( v6 )
{
v7 = read_container(*(unsigned int *)(v6 + 20));
v4 = v7;
if ( !v7 )
{
err_msg("index/index.c", 129LL, "container read error");
pthread_mutex_unlock(v2);
return v4;
}
cache_insert(*(_QWORD *)(a1 + 16), v7);
container_destroy(v4);
v3 = cache_search(*(_QWORD *)(a1 + 16), a2);
goto LABEL_2;
}
v4 = htable_lookup(*(_QWORD *)(a1 + 8), a2);
if ( !v4 )
{
v8 = chunkaddr_new(a2, 0LL, 0LL);
v9 = *(_QWORD *)(a1 + 8);
*(_DWORD *)(v8 + 8) = 0;
htable_add(v9, v8 + 12, v8);
pthread_mutex_unlock(v2);
return v4;
}
LABEL_3:
pthread_mutex_unlock(v2);
return v4;
}

original_code:
void * index_lookup(MemIndex* memdex,unsigned char * key){
 pthread_mutex_lock(&memdex->mutex);
 ContainerAddr * caddr=((void *)0);
 ChunkAddr *cka=((void *)0);
 Container *ca=((void *)0);
 cka=(ChunkAddr *)cache_search(memdex->index_cache, key);
 if(cka){
  pthread_mutex_unlock(&memdex->mutex);
  return cka;
 }
 caddr=htable_lookup(memdex->index_table, key);
 if(caddr==((void *)0))
 {
  cka=htable_lookup(memdex->index_new,key);
  if(!cka){
   cka=chunkaddr_new(key,0,0);
   cka->container_id=0;
   htable_add(memdex->index_new,cka->hash,cka);
   pthread_mutex_unlock(&memdex->mutex);
   return ((void *)0);
  }
  pthread_mutex_unlock(&memdex->mutex);
  return cka;
 }
 else{
  ca=read_container(caddr->container_id);
  if(ca==((void *)0)){
   err_msg("index/index.c",129,"container read error");
   pthread_mutex_unlock(&memdex->mutex);
   return ((void *)0);
  }
  cache_insert(memdex->index_cache,ca);
  container_destroy(ca);
  cka=(ChunkAddr *)cache_search(memdex->index_cache, key);
  pthread_mutex_unlock(&memdex->mutex);
  return cka;
 }
}

canonical_original_code:
void *index_lookup(struct mem_index *memdex, unsigned char *key){
 pthread_mutex_lock(&memdex->mutex);
 struct container_index *caddr = ((void *)0);
 struct chunk_address *cka = ((void *)0);
 struct container_tag *ca = ((void *)0);
 cka=(struct chunk_address *)cache_search(memdex->index_cache, key);
 if(cka){
  pthread_mutex_unlock(&memdex->mutex);
  return cka;
 }
 caddr=htable_lookup(memdex->index_table, key);
 if(caddr==((void *)0))
 {
  cka=htable_lookup(memdex->index_new,key);
  if(!cka){
   cka=chunkaddr_new(key,0,0);
   cka->container_id=0;
   htable_add(memdex->index_new,cka->hash,cka);
   pthread_mutex_unlock(&memdex->mutex);
   return ((void *)0);
  }
  pthread_mutex_unlock(&memdex->mutex);
  return cka;
 }
 else{
  ca=read_container(caddr->container_id);
  if(ca==((void *)0)){
   err_msg("index/index.c",129,"container read error");
   pthread_mutex_unlock(&memdex->mutex);
   return ((void *)0);
  }
  cache_insert(memdex->index_cache,ca);
  container_destroy(ca);
  cka=(struct chunk_address *)cache_search(memdex->index_cache, key);
  pthread_mutex_unlock(&memdex->mutex);
  return cka;
 }
}

variable_types:
key
unsigned char *

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

return_type: void *

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


decompiled_code:
void __fastcall index_destroy(void *ptr)
{
index_close(ptr);
htable_destroy(*(_QWORD *)ptr);
cache_destroy(*((_QWORD *)ptr + 2));
htable_destroy(*((_QWORD *)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
func1(ptr);
htable_destroy(*(_QWORD *)ptr);
cache_destroy(*((_QWORD *)ptr + 2));
htable_destroy(*((_QWORD *)ptr + 1));
free(ptr);
}

original_code:
void index_destroy(MemIndex* memdex){
 index_close( memdex);
 htable_destroy(memdex->index_table);
 cache_destroy(memdex->index_cache);
 htable_destroy(memdex->index_new);
 free(memdex);
}

canonical_original_code:
void index_destroy(struct mem_index *memdex){
 index_close( memdex);
 htable_destroy(memdex->index_table);
 cache_destroy(memdex->index_cache);
 htable_destroy(memdex->index_new);
 free(memdex);
}


decompiled_code:
char *index_init_r()
{
char *v0; // r12
__int64 v1; // rax
__int64 v2; // rdi

v0 = (char *)malloc(0x48uLL);
v1 = htable_init(24LL, 20LL, 0xFFFFFFLL);
v2 = G_CONTAINER_NUM;
*(_QWORD *)v0 = v1;
*((_QWORD *)v0 + 2) = cache_init_r(v2);
pthread_mutex_init((pthread_mutex_t *)(v0 + 32), 0LL);
index_open(v0);
return v0;
}

canonical_decompiled_code:
char *func6()
{
char *v0; // r12
__int64 v1; // rax
__int64 v2; // rdi

v0 = (char *)malloc(0x48uLL);
v1 = htable_init(24LL, 20LL, 0xFFFFFFLL);
v2 = G_CONTAINER_NUM;
*(_QWORD *)v0 = v1;
*((_QWORD *)v0 + 2) = cache_init_r(v2);
pthread_mutex_init((pthread_mutex_t *)(v0 + 32), 0LL);
func0(v0);
return v0;
}

original_code:
MemIndex* index_init_r(){
 MemIndex * index=(MemIndex *)malloc(sizeof(MemIndex));
 ContainerAddr caddr;
 index->index_table=htable_init((char*)&(caddr.next)-(char*)&caddr,sizeof(Fingerprint),16777215);
 index->index_cache=cache_init_r( G_CONTAINER_NUM);
  pthread_mutex_init(&index->mutex, 0);
  index_open(index);
 return index;
}

canonical_original_code:
struct mem_index *index_init_r(){
 struct mem_index *index = (MemIndex *)malloc(sizeof(MemIndex));
 struct container_index caddr;
 index->index_table=htable_init((char *)&(caddr.next)-(char *)&caddr,sizeof(Fingerprint),16777215);
 index->index_cache=cache_init_r( G_CONTAINER_NUM);
  pthread_mutex_init(&index->mutex, 0);
  index_open(index);
 return index;
}


decompiled_code:
int *__fastcall index_search_r(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // r13
unsigned int *v3; // rax
__int64 v4; // rcx
__int64 v5; // r8
int *v6; // rbx
__int64 v7; // rax
int *v8; // r12
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // r15

v2 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v3 = (unsigned int *)cache_search_r(*(_QWORD *)(a1 + 16), a2);
if ( v3 )
{
v4 = v3[1];
v5 = *v3;
v6 = (int *)v3;
if ( (int)v4 < 0 || (v7 = *((_QWORD *)v3 + 1), *(_DWORD *)(v7 + 4) < (int)v5) || (int)v5 < 0 )
{
v8 = 0LL;
err_msg("index/index.c", 179LL, "Invalid chunk length or offset, length=%d, offset=%d", v4, v5);
}
else
{
v8 = (int *)chunk_new(v6 + 4, *(_QWORD *)(v7 + 24) + (int)v5, (unsigned int)v4);
if ( *(_BYTE *)(*(_QWORD *)(*((_QWORD *)v6 + 1) + 24LL) + *v6 + *v8) != 9 )
err_msg("index/index.c", 184LL, "container has been corrupted.");
check_chunk(v8);
pthread_mutex_unlock(v2);
}
}
else
{
v10 = htable_lookup(*(_QWORD *)a1, a2);
v8 = (int *)v10;
if ( v10 )
{
v11 = read_container(*(unsigned int *)(v10 + 20));
++G_R_READNUM;
v12 = v11;
v8 = (int *)read_chunk(v11, a2);
cache_insert_r(*(_QWORD *)(a1 + 16), v12);
}
else
{
err_msg("index/index.c", 194LL, "sorry , not found , maybe wrong");
}
pthread_mutex_unlock(v2);
}
return v8;
}

canonical_decompiled_code:
int *__fastcall func7(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // r13
unsigned int *v3; // rax
__int64 v4; // rcx
__int64 v5; // r8
int *v6; // rbx
__int64 v7; // rax
int *v8; // r12
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // r15

v2 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v3 = (unsigned int *)cache_search_r(*(_QWORD *)(a1 + 16), a2);
if ( v3 )
{
v4 = v3[1];
v5 = *v3;
v6 = (int *)v3;
if ( (int)v4 < 0 || (v7 = *((_QWORD *)v3 + 1), *(_DWORD *)(v7 + 4) < (int)v5) || (int)v5 < 0 )
{
v8 = 0LL;
err_msg("index/index.c", 179LL, "Invalid chunk length or offset, length=%d, offset=%d", v4, v5);
}
else
{
v8 = (int *)chunk_new(v6 + 4, *(_QWORD *)(v7 + 24) + (int)v5, (unsigned int)v4);
if ( *(_BYTE *)(*(_QWORD *)(*((_QWORD *)v6 + 1) + 24LL) + *v6 + *v8) != 9 )
err_msg("index/index.c", 184LL, "container has been corrupted.");
check_chunk(v8);
pthread_mutex_unlock(v2);
}
}
else
{
v10 = htable_lookup(*(_QWORD *)a1, a2);
v8 = (int *)v10;
if ( v10 )
{
v11 = read_container(*(unsigned int *)(v10 + 20));
++G_R_READNUM;
v12 = v11;
v8 = (int *)read_chunk(v11, a2);
cache_insert_r(*(_QWORD *)(a1 + 16), v12);
}
else
{
err_msg("index/index.c", 194LL, "sorry , not found , maybe wrong");
}
pthread_mutex_unlock(v2);
}
return v8;
}

original_code:
Chunk* index_search_r(MemIndex* memdex,unsigned char * key){
 pthread_mutex_lock(&memdex->mutex);
 ContainerAddr * caddr=((void *)0);
 ChunkAddrRes *cka=((void *)0);
 Chunk *ck=((void *)0);
 Container *ca;
 cka=(ChunkAddrRes *)cache_search_r(memdex->index_cache, key);
 if(cka){
   if(cka->length<0||cka->offset > cka->container->data_size || cka->offset < 0){
         err_msg("index/index.c",179,"Invalid chunk length or offset, length=%d, offset=%d",cka->length,cka->offset);
          return ((void *)0);
      }
      Chunk *chunk =chunk_new( cka->hash,cka->container->data_buffer+cka->offset,cka->length);
      if(*(cka->container->data_buffer+cka->offset+chunk->length) != '\t'){
         err_msg("index/index.c",184,"container has been corrupted.");
      }
      check_chunk(chunk);
  pthread_mutex_unlock(&memdex->mutex);
  return chunk;
 }
 caddr=htable_lookup(memdex->index_table, key);
 if(caddr==((void *)0)){
  err_msg("index/index.c",194,"sorry , not found , maybe wrong");
 }
 else
 {
  ca=read_container(caddr->container_id);
  G_R_READNUM++;
  ck=read_chunk(ca,key);
  cache_insert_r(memdex->index_cache,ca);
 }
 pthread_mutex_unlock(&memdex->mutex);
 return ck;
}

canonical_original_code:
struct chunk_tag *index_search_r(struct mem_index *memdex, unsigned char *key){
 pthread_mutex_lock(&memdex->mutex);
 struct container_index *caddr = ((void *)0);
 struct chunk_address_restore *cka = ((void *)0);
 struct chunk_tag *ck = ((void *)0);
 struct container_tag *ca;
 cka=(struct chunk_address_restore *)cache_search_r(memdex->index_cache, key);
 if(cka){
   if(cka->length<0||cka->offset > cka->container->data_size || cka->offset < 0){
         err_msg("index/index.c",179,"Invalid chunk length or offset, length=%d, offset=%d",cka->length,cka->offset);
          return ((void *)0);
      }
      struct chunk_tag *chunk = chunk_new( cka->hash,cka->container->data_buffer+cka->offset,cka->length);
      if(*(cka->container->data_buffer+cka->offset+chunk->length) != '\t'){
         err_msg("index/index.c",184,"container has been corrupted.");
      }
      check_chunk(chunk);
  pthread_mutex_unlock(&memdex->mutex);
  return chunk;
 }
 caddr=htable_lookup(memdex->index_table, key);
 if(caddr==((void *)0)){
  err_msg("index/index.c",194,"sorry , not found , maybe wrong");
 }
 else
 {
  ca=read_container(caddr->container_id);
  G_R_READNUM++;
  ck=read_chunk(ca,key);
  cache_insert_r(memdex->index_cache,ca);
 }
 pthread_mutex_unlock(&memdex->mutex);
 return ck;
}

variable_types: struct chunk_address_restore { int offset; int length; 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; } *container; unsigned char hash[20]; struct hlink_t next; } *

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

user_defined_types: struct chunk_address_restore { int offset; int length; struct container_tag *container; unsigned char hash[20]; struct hlink_t next; }


decompiled_code:
void __fastcall index_destroy_r(void *ptr)
{
__int64 v1; // rax

index_close(ptr);
htable_destroy(*(_QWORD *)ptr);
cache_statistics(*((_QWORD *)ptr + 2));
while ( *(int *)(*(_QWORD *)(*((_QWORD *)ptr + 2) + 24LL) + 16LL) > 0 )
{
v1 = dlist_delete_tail();
if ( v1 )
container_destroy(v1);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
__int64 v1; // rax

func1(ptr);
htable_destroy(*(_QWORD *)ptr);
cache_statistics(*((_QWORD *)ptr + 2));
while ( *(int *)(*(_QWORD *)(*((_QWORD *)ptr + 2) + 24LL) + 16LL) > 0 )
{
v1 = dlist_delete_tail();
if ( v1 )
container_destroy(v1);
}
free(ptr);
}

original_code:
void index_destroy_r(MemIndex* memdex){
 index_close( memdex);
 htable_destroy(memdex->index_table);
  cache_statistics(memdex->index_cache);
 while(memdex->index_cache->plist->size>0){
  Container * ca=(Container *)dlist_delete_tail(memdex->index_cache->plist);
  if(ca)
   container_destroy(ca);
 }
 free(memdex);
}

canonical_original_code:
void index_destroy_r(struct mem_index *memdex){
 index_close( memdex);
 htable_destroy(memdex->index_table);
  cache_statistics(memdex->index_cache);
 while(memdex->index_cache->plist->size>0){
  struct container_tag *ca = (Container *)dlist_delete_tail(memdex->index_cache->plist);
  if(ca)
   container_destroy(ca);
 }
 free(memdex);
}


decompiled_code:
_QWORD *queue_new()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
Queue* queue_new() {
    Queue *queue = (Queue*)malloc(sizeof(Queue));
    queue->first = queue->last = 0;
    queue->elem_num = 0;
    return queue;
}

canonical_original_code:
struct queue_tag *queue_new() {
    struct queue_tag *queue = (Queue*)malloc(sizeof(Queue));
    queue->first = queue->last = 0;
    queue->elem_num = 0;
    return queue;
}

variable_types: struct queue_tag { struct queue_ele_tag { struct queue_ele_tag *next; void *data; } *first; int elem_num; } *

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


original_code:
void queue_init(Queue *queue){
    queue->first = queue->last = 0;
    queue->elem_num = 0;
}

canonical_original_code:
void queue_init(struct queue_tag *queue){
    queue->first = queue->last = 0;
    queue->elem_num = 0;
}

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


decompiled_code:
int __fastcall queue_push(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf

v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = *(_QWORD *)a1 == 0LL;
v2[1] = a2;
*v2 = 0LL;
if ( v3 )
{
++*(_DWORD *)(a1 + 16);
*(_QWORD *)a1 = v2;
}
else
{
**(_QWORD **)(a1 + 8) = v2;
++*(_DWORD *)(a1 + 16);
}
*(_QWORD *)(a1 + 8) = v2;
}
else
{
LODWORD(v2) = puts("Not enough memory!");
}
return (int)v2;
}

original_code:
void queue_push(Queue *queue, void *element) {
    queue_ele_t *item;
    if ((item = (queue_ele_t *) malloc(sizeof(queue_ele_t))) == 0) {
        puts("Not enough memory!");
        return;
    }
    item->data = element;
    item->next = 0;
    if (queue->first == 0) {
        queue->first = item;
    } else {
        queue->last->next = item;
    }
    queue->last = item;
    ++queue->elem_num;
}

canonical_original_code:
void queue_push(struct queue_tag *queue, void *element) {
    struct queue_ele_tag *item;
    if ((item = (struct queue_ele_tag *) malloc(sizeof(queue_ele_t))) == 0) {
        puts("Not enough memory!");
        return;
    }
    item->data = element;
    item->next = 0;
    if (queue->first == 0) {
        queue->first = item;
    } else {
        queue->last->next = item;
    }
    queue->last = item;
    ++queue->elem_num;
}

variable_types:
element
void *

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


original_code:
void* queue_pop(Queue *queue) {
    queue_ele_t *item = 0;
    if(queue->elem_num == 0)
        return ((void *)0);
    item = queue->first;
    queue->first = item->next;
    if (queue->last == item)
        queue->last = ((void *)0);
    --queue->elem_num;
    void *ret = item->data;
    free(item);
    return ret;
}

canonical_original_code:
void *queue_pop(struct queue_tag *queue) {
    struct queue_ele_tag *item = 0;
    if(queue->elem_num == 0)
        return ((void *)0);
    item = queue->first;
    queue->first = item->next;
    if (queue->last == item)
        queue->last = ((void *)0);
    --queue->elem_num;
    void *ret = item->data;
    free(item);
    return ret;
}

variable_types:
ret
void *


decompiled_code:
__int64 __fastcall queue_empty(__int64 a1)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 16) )
{
do
{
queue_pop(a1);
result = *(unsigned int *)(a1 + 16);
}
while ( (_DWORD)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 16) )
{
do
{
func3(a1);
result = *(unsigned int *)(a1 + 16);
}
while ( (_DWORD)result );
}
return result;
}

original_code:
void queue_empty(Queue *queue){
    while(queue->elem_num){
        queue_pop(queue);
    }
}

canonical_original_code:
void queue_empty(struct queue_tag *queue){
    while(queue->elem_num){
        queue_pop(queue);
    }
}


decompiled_code:
void __fastcall queue_free(void *ptr)
{
queue_empty((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
func4((__int64)ptr);
free(ptr);
}

original_code:
void queue_free(Queue *queue) {
    queue_empty(queue);
    free(queue);
}

canonical_original_code:
void queue_free(struct queue_tag *queue) {
    queue_empty(queue);
    free(queue);
}


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

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

original_code:
int queue_size(Queue *queue){
    return queue->elem_num;
}

canonical_original_code:
int queue_size(struct queue_tag *queue){
    return queue->elem_num;
}

return_type: int


decompiled_code:
char *sync_queue_new()
{
char *v0; // r12
__int64 v1; // rax

v0 = (char *)malloc(0x78uLL);
queue_init((__int64)v0);
*(_DWORD *)(v1 + 24) = 4660;
pthread_mutex_init((pthread_mutex_t *)(v1 + 32), 0LL);
pthread_cond_init((pthread_cond_t *)(v0 + 72), 0LL);
return v0;
}

canonical_decompiled_code:
char *func7()
{
char *v0; // r12
__int64 v1; // rax

v0 = (char *)malloc(0x78uLL);
func1((__int64)v0);
*(_DWORD *)(v1 + 24) = 4660;
pthread_mutex_init((pthread_mutex_t *)(v1 + 32), 0LL);
pthread_cond_init((pthread_cond_t *)(v0 + 72), 0LL);
return v0;
}

original_code:
SyncQueue *sync_queue_new(){
    SyncQueue* syncq = (SyncQueue*)malloc(sizeof(SyncQueue));
    queue_init(&syncq->queue);
    syncq->valid = 0x1234;
    pthread_mutex_init(&syncq->mutex, ((void *)0));
    pthread_cond_init(&syncq->work, ((void *)0));
    return syncq;
}

canonical_original_code:
struct SyncQueue *sync_queue_new(){
    struct SyncQueue *syncq = (SyncQueue*)malloc(sizeof(SyncQueue));
    queue_init(&syncq->queue);
    syncq->valid = 0x1234;
    pthread_mutex_init(&syncq->mutex, ((void *)0));
    pthread_cond_init(&syncq->work, ((void *)0));
    return syncq;
}

variable_types: struct SyncQueue { struct queue_tag { struct queue_ele_tag { struct queue_ele_tag *next; void *data; } *first; int elem_num; } queue; int valid; 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; } work; } *

user_defined_types: struct SyncQueue { struct queue_tag queue; int valid; union pthread_mutex_t mutex; union pthread_cond_t work; }

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


decompiled_code:
void __fastcall sync_queue_free(void *ptr)
{
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 32));
*((_DWORD *)ptr + 6) = 0;
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 32));
queue_empty((__int64)ptr);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 32));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 72));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 32));
*((_DWORD *)ptr + 6) = 0;
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 32));
func4((__int64)ptr);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 32));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 72));
free(ptr);
}

original_code:
void sync_queue_free(SyncQueue* sync_queue){
    pthread_mutex_lock(&sync_queue->mutex);
    sync_queue->valid = 0;
    pthread_mutex_unlock(&sync_queue->mutex);
    queue_empty(&sync_queue->queue);
    pthread_mutex_destroy(&sync_queue->mutex);
    pthread_cond_destroy(&sync_queue->work);
    free(sync_queue);
}

canonical_original_code:
void sync_queue_free(struct SyncQueue *sync_queue){
    pthread_mutex_lock(&sync_queue->mutex);
    sync_queue->valid = 0;
    pthread_mutex_unlock(&sync_queue->mutex);
    queue_empty(&sync_queue->queue);
    pthread_mutex_destroy(&sync_queue->mutex);
    pthread_cond_destroy(&sync_queue->work);
    free(sync_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]; }


decompiled_code:
// attributes: thunk
__int64 __fastcall sync_queue_size(__int64 a1)
{
return queue_size(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return func6(a1);
}

original_code:
int sync_queue_size(SyncQueue *sync_queue){
    return queue_size(&sync_queue->queue);
}

canonical_original_code:
int sync_queue_size(struct SyncQueue *sync_queue){
    return queue_size(&sync_queue->queue);
}


decompiled_code:
int __fastcall sync_queue_push(__int64 a1, __int64 a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
if ( *(_DWORD *)(a1 + 24) == 4660 )
{
queue_push(a1, a2);
pthread_cond_broadcast((pthread_cond_t *)(a1 + 72));
}
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
if ( *(_DWORD *)(a1 + 24) == 4660 )
{
func2(a1, a2);
pthread_cond_broadcast((pthread_cond_t *)(a1 + 72));
}
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
}

original_code:
void sync_queue_push(SyncQueue *sync_queue, void *elem){
    pthread_mutex_lock(&sync_queue->mutex);
    if(sync_queue->valid != 0x1234){
        pthread_mutex_unlock(&sync_queue->mutex);
        return;
    }
    queue_push(&sync_queue->queue, elem);
    pthread_cond_broadcast(&sync_queue->work);
    pthread_mutex_unlock(&sync_queue->mutex);
}

canonical_original_code:
void sync_queue_push(struct SyncQueue *sync_queue, void *elem){
    pthread_mutex_lock(&sync_queue->mutex);
    if(sync_queue->valid != 0x1234){
        pthread_mutex_unlock(&sync_queue->mutex);
        return;
    }
    queue_push(&sync_queue->queue, elem);
    pthread_cond_broadcast(&sync_queue->work);
    pthread_mutex_unlock(&sync_queue->mutex);
}

variable_types:
elem
void *


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

v1 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
if ( *(_DWORD *)(a1 + 24) == 4660 )
{
while ( 1 )
{
v2 = queue_pop(a1);
if ( v2 )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 72), v1);
}
pthread_mutex_unlock(v1);
result = v2;
}
else
{
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

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

v1 = (pthread_mutex_t *)(a1 + 32);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
if ( *(_DWORD *)(a1 + 24) == 4660 )
{
while ( 1 )
{
v2 = func3(a1);
if ( v2 )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 72), v1);
}
pthread_mutex_unlock(v1);
result = v2;
}
else
{
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

original_code:
void* sync_queue_pop(SyncQueue *sync_queue){
    pthread_mutex_lock(&sync_queue->mutex);
    if(sync_queue->valid != 0x1234){
        pthread_mutex_unlock(&sync_queue->mutex);
        return ((void *)0);
    }
    void* elem;
    while((elem = queue_pop(&sync_queue->queue)) == 0){
        pthread_cond_wait(&sync_queue->work, &sync_queue->mutex);
    }
    pthread_mutex_unlock(&sync_queue->mutex);
    return elem;
}

canonical_original_code:
void *sync_queue_pop(struct SyncQueue *sync_queue){
    pthread_mutex_lock(&sync_queue->mutex);
    if(sync_queue->valid != 0x1234){
        pthread_mutex_unlock(&sync_queue->mutex);
        return ((void *)0);
    }
    void *elem;
    while((elem = queue_pop(&sync_queue->queue)) == 0){
        pthread_cond_wait(&sync_queue->work, &sync_queue->mutex);
    }
    pthread_mutex_unlock(&sync_queue->mutex);
    return elem;
}


decompiled_code:
__int64 scan_init()
{
double v0; // xmm0_8
__int64 result; // rax

scan_htable = htable_init(16LL, 4LL, 32LL);
v0 = (double)DEFAULT_CONTAINER_SIZE * G_THRESHOLD;
result = (unsigned int)(int)v0;
fragmentation_threshold = (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
double v0; // xmm0_8
__int64 result; // rax

scan_htable = htable_init(16LL, 4LL, 32LL);
v0 = (double)DEFAULT_CONTAINER_SIZE * G_THRESHOLD;
result = (unsigned int)(int)v0;
fragmentation_threshold = (int)v0;
return result;
}

original_code:
void scan_init(){
 ReferItem r;
 scan_htable=htable_init((char*)&r.next-(char*)&r,4,32);
  fragmentation_threshold=DEFAULT_CONTAINER_SIZE*G_THRESHOLD;
}

canonical_original_code:
void scan_init(){
 struct reference_item r;
 scan_htable=htable_init((char *)&r.next-(char *)&r,4,32);
  fragmentation_threshold=DEFAULT_CONTAINER_SIZE*G_THRESHOLD;
}

variable_types: struct reference_item { int container_id; int size; int count; int rewrite; struct hlink_t { void *next; unsigned int hash; unsigned char *key; } next; }

user_defined_types: struct reference_item { int container_id; int size; int count; int rewrite; struct hlink_t next; }


decompiled_code:
__int64 scan_destroy()
{
return htable_destroy(scan_htable);
}

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

original_code:
void scan_destroy(){
 htable_destroy(scan_htable);
}


decompiled_code:
__int64 scan_reset()
{
__int64 v0; // rax
__int64 v1; // rsi
__int64 result; // rax

v0 = htable_get_first(scan_htable);
if ( v0 )
{
v1 = v0;
do
{
htable_remove(scan_htable, v1);
v1 = htable_get_next(scan_htable);
}
while ( v1 );
}
result = *(unsigned int *)(scan_htable + 16);
if ( (_DWORD)result )
result = err_msg("defragmentation.c", 26LL, "scan_reset wrong");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v1; // rsi
__int64 result; // rax

v0 = htable_get_first(scan_htable);
if ( v0 )
{
v1 = v0;
do
{
htable_remove(scan_htable, v1);
v1 = htable_get_next(scan_htable);
}
while ( v1 );
}
result = *(unsigned int *)(scan_htable + 16);
if ( (_DWORD)result )
result = err_msg("defragmentation.c", 26LL, "scan_reset wrong");
return result;
}

original_code:
void scan_reset(){
 ReferItem * rf;
 for((*((void **)&(rf))=(void *)(htable_get_first((scan_htable)))); (rf); (*((void **)&(rf))=(void *)(htable_get_next(scan_htable)))){
  htable_remove(scan_htable,&rf->container_id);
 }
 if(scan_htable->num_items!=0)
  err_msg("defragmentation.c",26,"scan_reset wrong");
}

canonical_original_code:
void scan_reset(){
 struct reference_item *rf;
 for((*((void **)&(rf))=(void *)(htable_get_first((scan_htable)))); (rf); (*((void **)&(rf))=(void *)(htable_get_next(scan_htable)))){
  htable_remove(scan_htable,&rf->container_id);
 }
 if(scan_htable->num_items!=0)
  err_msg("defragmentation.c",26,"scan_reset wrong");
}

variable_types: struct reference_item { int container_id; int size; int count; int rewrite; struct hlink_t { void *next; unsigned int hash; unsigned char *key; } next; } *


decompiled_code:
__int64 scan_numer()
{
return *(unsigned int *)(scan_htable + 16);
}

canonical_decompiled_code:
__int64 func3()
{
return *(unsigned int *)(scan_htable + 16);
}

original_code:
int scan_numer(){
 return scan_htable->num_items;
}


decompiled_code:
__int64 __fastcall scan_search(int a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
return htable_lookup(scan_htable, v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
return htable_lookup(scan_htable, v2);
}

original_code:
void * scan_search(int old_container_id){
 ReferItem * rf=htable_lookup(scan_htable,&old_container_id);
 return rf;
}

canonical_original_code:
void *scan_search(int old_container_id){
 struct reference_item *rf = htable_lookup(scan_htable,&old_container_id);
 return rf;
}


decompiled_code:
__int64 __fastcall scan_decision(int a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rax
double v4; // xmm2_8
unsigned int v5; // er12
bool v6; // zf
int v8; // eax
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v9[0] = a1;
v1 = htable_lookup(scan_htable, v9);
if ( v1 )
{
v2 = v1;
v3 = *(int *)(v1 + 4);
if ( (double)DEFAULT_CONTAINER_SIZE * G_THRESHOLD < (double)(int)v3 )
{
v8 = *(_DWORD *)(v2 + 8);
v5 = 49;
*(double *)&current_threshold = (double)(int)rewrite_size / G_total_size;
*(_DWORD *)(v2 + 8) = --v8;
if ( !v8 )
{
LABEL_6:
htable_remove(scan_htable, v9);
return v5;
}
}
else
{
if ( *(double *)&current_threshold > 0.05 )
{
v4 = G_THRESHOLD - 0.01;
v5 = 49;
}
else
{
v4 = G_THRESHOLD + 0.01;
rewrite_size += v3;
v5 = 48;
}
G_THRESHOLD = *(_QWORD *)&v4;
printf("%f %f \n", v4, *(double *)&current_threshold);
v6 = (*(_DWORD *)(v2 + 8))-- == 1;
*(double *)&current_threshold = (double)(int)rewrite_size / G_total_size;
if ( v6 )
goto LABEL_6;
}
}
else
{
v5 = 48;
puts("error ==========");
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rax
double v4; // xmm2_8
unsigned int v5; // er12
bool v6; // zf
int v8; // eax
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v9[0] = a1;
v1 = htable_lookup(scan_htable, v9);
if ( v1 )
{
v2 = v1;
v3 = *(int *)(v1 + 4);
if ( (double)DEFAULT_CONTAINER_SIZE * G_THRESHOLD < (double)(int)v3 )
{
v8 = *(_DWORD *)(v2 + 8);
v5 = 49;
*(double *)&current_threshold = (double)(int)rewrite_size / G_total_size;
*(_DWORD *)(v2 + 8) = --v8;
if ( !v8 )
{
LABEL_6:
htable_remove(scan_htable, v9);
return v5;
}
}
else
{
if ( *(double *)&current_threshold > 0.05 )
{
v4 = G_THRESHOLD - 0.01;
v5 = 49;
}
else
{
v4 = G_THRESHOLD + 0.01;
rewrite_size += v3;
v5 = 48;
}
G_THRESHOLD = *(_QWORD *)&v4;
printf("%f %f \n", v4, *(double *)&current_threshold);
v6 = (*(_DWORD *)(v2 + 8))-- == 1;
*(double *)&current_threshold = (double)(int)rewrite_size / G_total_size;
if ( v6 )
goto LABEL_6;
}
}
else
{
v5 = 48;
puts("error ==========");
}
return v5;
}

original_code:
char scan_decision(int old_container_id){
 ReferItem * rf=htable_lookup(scan_htable,&old_container_id);
 int exist=0;
 if(rf){
  if(rf->size<= DEFAULT_CONTAINER_SIZE*G_THRESHOLD ){
   if(current_threshold<=0.05){
    G_THRESHOLD+=0.01;
    exist=0;
    rewrite_size+=rf->size;
   }
   else{
    G_THRESHOLD-=0.01;
    exist=1;
   }
   printf("%f   %f \n", G_THRESHOLD,current_threshold);
  }
  else{
   exist=1;
  }
  current_threshold=rewrite_size*1.0/G_total_size;
  rf->count--;
  if(rf->count==0)
   htable_remove(scan_htable,&old_container_id);
 }
 else{
  printf("error ==========\n");
  return '0';
 }
 if(exist)
  return '1';
 else
  return '0';
}

canonical_original_code:
char scan_decision(int old_container_id){
 struct reference_item *rf = htable_lookup(scan_htable,&old_container_id);
 int exist = 0;
 if(rf){
  if(rf->size<= DEFAULT_CONTAINER_SIZE*G_THRESHOLD ){
   if(current_threshold<=0.05){
    G_THRESHOLD+=0.01;
    exist=0;
    rewrite_size+=rf->size;
   }
   else{
    G_THRESHOLD-=0.01;
    exist=1;
   }
   printf("%f   %f \n", G_THRESHOLD,current_threshold);
  }
  else{
   exist=1;
  }
  current_threshold=rewrite_size*1.0/G_total_size;
  rf->count--;
  if(rf->count==0)
   htable_remove(scan_htable,&old_container_id);
 }
 else{
  printf("error ==========\n");
  return '0';
 }
 if(exist)
  return '1';
 else
  return '0';
}

variable_types: exist int

return_type: char


decompiled_code:
__int64 __fastcall local_simulate_restore(unsigned int a1)
{
unsigned int *v1; // r12
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // r13
__int64 i; // rbx
int *v7; // rbp
__int64 v8; // rdx
__int64 v9; // rax
int v10; // ebp
double v11; // xmm0_8
size_t v13; // rax
double v14; // [rsp+8h] [rbp-70h]
double v15; // [rsp+8h] [rbp-70h]
struct timeval tv; // [rsp+10h] [rbp-68h] BYREF
struct timeval v17; // [rsp+20h] [rbp-58h] BYREF
char s[16]; // [rsp+30h] [rbp-48h] BYREF
__int64 v19; // [rsp+40h] [rbp-38h]
int v20; // [rsp+48h] [rbp-30h]
__int16 v21; // [rsp+4Ch] [rbp-2Ch]

G_R_READNUM = 0;
container_vol_init();
v1 = (unsigned int *)jcr_new();
v2 = index_init_r();
*v1 = a1;
*((_QWORD *)v1 + 71) = v2;
v3 = jobv_open(a1);
*((_QWORD *)v1 + 70) = v3;
if ( v3 )
{
printf("%s,%d restore jobid:%d \n", "restore.c", 25LL, *v1);
v14 = 0.0;
while ( 1 )
{
v4 = jobv_search_next_recipe(*((_QWORD *)v1 + 70));
v5 = v4;
if ( !v4 )
break;
if ( G_VERBOSE )
printf("send file %s \n", (const char *)(v4 + 8));
for ( i = *(_QWORD *)(v5 + 264); i; i = *(_QWORD *)(i + 40) )
{
gettimeofday(&tv, 0LL);
v7 = (int *)index_search_r(*((_QWORD *)v1 + 71), i);
*((_QWORD *)v1 + 66) += *v7;
gettimeofday(&v17, 0LL);
v14 = (double)(LODWORD(v17.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v17.tv_sec) - LODWORD(tv.tv_sec))
+ v14;
chunk_free(v7);
}
recipe_free(v5);
}
printf("read chunk speed : %20.4f MB/s \n", (double)(int)*((_QWORD *)v1 + 66) / v14 * 0.00000095367431640625);
v8 = *((_QWORD *)v1 + 66);
v19 = 0LL;
v9 = v8 + 0xFFFFF;
v20 = 0;
if ( v8 >= 0 )
v9 = v8;
v21 = 0;
*(_OWORD *)s = 0LL;
v15 = (double)G_R_READNUM / (double)(int)(v9 >> 20);
snprintf(s, 0x1EuLL, "%f\t", v15);
v10 = G_FILE_FD;
v11 = v15;
if ( G_FILE_FD )
{
v13 = strlen(s);
write(v10, s, v13);
v11 = v15;
}
printf("read containere number:%d , %20.4f /MB \n", G_R_READNUM, v11);
jobv_destroy(*((_QWORD *)v1 + 70));
}
index_destroy_r(*((_QWORD *)v1 + 71));
jcr_free(v1);
return container_vol_destroy();
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
unsigned int *v1; // r12
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // r13
__int64 i; // rbx
int *v7; // rbp
__int64 v8; // rdx
__int64 v9; // rax
int v10; // ebp
double v11; // xmm0_8
size_t v13; // rax
double v14; // [rsp+8h] [rbp-70h]
double v15; // [rsp+8h] [rbp-70h]
struct timeval tv; // [rsp+10h] [rbp-68h] BYREF
struct timeval v17; // [rsp+20h] [rbp-58h] BYREF
char s[16]; // [rsp+30h] [rbp-48h] BYREF
__int64 v19; // [rsp+40h] [rbp-38h]
int v20; // [rsp+48h] [rbp-30h]
__int16 v21; // [rsp+4Ch] [rbp-2Ch]

G_R_READNUM = 0;
container_vol_init();
v1 = (unsigned int *)jcr_new();
v2 = index_init_r();
*v1 = a1;
*((_QWORD *)v1 + 71) = v2;
v3 = jobv_open(a1);
*((_QWORD *)v1 + 70) = v3;
if ( v3 )
{
printf("%s,%d restore jobid:%d \n", "restore.c", 25LL, *v1);
v14 = 0.0;
while ( 1 )
{
v4 = jobv_search_next_recipe(*((_QWORD *)v1 + 70));
v5 = v4;
if ( !v4 )
break;
if ( G_VERBOSE )
printf("send file %s \n", (const char *)(v4 + 8));
for ( i = *(_QWORD *)(v5 + 264); i; i = *(_QWORD *)(i + 40) )
{
gettimeofday(&tv, 0LL);
v7 = (int *)index_search_r(*((_QWORD *)v1 + 71), i);
*((_QWORD *)v1 + 66) += *v7;
gettimeofday(&v17, 0LL);
v14 = (double)(LODWORD(v17.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v17.tv_sec) - LODWORD(tv.tv_sec))
+ v14;
chunk_free(v7);
}
recipe_free(v5);
}
printf("read chunk speed : %20.4f MB/s \n", (double)(int)*((_QWORD *)v1 + 66) / v14 * 0.00000095367431640625);
v8 = *((_QWORD *)v1 + 66);
v19 = 0LL;
v9 = v8 + 0xFFFFF;
v20 = 0;
if ( v8 >= 0 )
v9 = v8;
v21 = 0;
*(_OWORD *)s = 0LL;
v15 = (double)G_R_READNUM / (double)(int)(v9 >> 20);
snprintf(s, 0x1EuLL, "%f\t", v15);
v10 = G_FILE_FD;
v11 = v15;
if ( G_FILE_FD )
{
v13 = strlen(s);
write(v10, s, v13);
v11 = v15;
}
printf("read containere number:%d , %20.4f /MB \n", G_R_READNUM, v11);
jobv_destroy(*((_QWORD *)v1 + 70));
}
index_destroy_r(*((_QWORD *)v1 + 71));
jcr_free(v1);
return container_vol_destroy();
}

original_code:
void local_simulate_restore(int jobid){
  JCR *jcr=((void *)0);
  Recipe *rp=((void *)0);
  FingerChunk *fc=((void *)0);
  Chunk *chunk=((void *)0);
  struct timeval start,end;
  double restore_time=0;
  G_R_READNUM=0;
  container_vol_init();
  jcr=jcr_new();
  jcr->memIndex=index_init_r();
  jcr->nJobId=jobid;
  jcr->jobv=jobv_open(jcr->nJobId);
  if(jcr->jobv==((void *)0)){
   goto FAIL;
  }
  printf("%s,%d restore jobid:%d \n", "restore.c",25,jcr->nJobId);
  while((rp=jobv_search_next_recipe(jcr->jobv))){
   if(G_VERBOSE)
      printf("send file %s \n",rp->filename);
   for(fc=rp->first;fc;fc=fc->next){
    gettimeofday(&start, ((void *)0));
    chunk=index_search_r(jcr->memIndex,fc->fingerprint);
    jcr->nSize+=chunk->length;
    gettimeofday(&end, ((void *)0));
    (restore_time)+=(end.tv_usec-start.tv_usec)*1.0/1000000+(end.tv_sec-start.tv_sec);
    if(chunk){
     chunk_free(chunk);
    }
    else
     err_msg("restore.c",41,"not found");
   }
   recipe_free(rp);
  }
  printf("read chunk speed : %20.4f MB/s \n",jcr->nSize*1.0/restore_time/(1024*1024));
  double speed=G_R_READNUM*1.0 /(jcr->nSize/(1024*1024));
  char str[30]={0};
  snprintf(str,30,"%f\t",speed);
  if(G_FILE_FD){
   write(G_FILE_FD,str,strlen(str));
  }
  printf("read containere number:%d , %20.4f /MB \n",G_R_READNUM, speed);
 jobv_destroy(jcr->jobv);
  FAIL:
  index_destroy_r(jcr->memIndex);
  jcr_free(jcr);
  container_vol_destroy();
}

canonical_original_code:
void local_simulate_restore(int jobid){
  struct jcr *jcr = ((void *)0);
  struct recipe_tag *rp = ((void *)0);
  struct finger_chunk_tag *fc = ((void *)0);
  struct chunk_tag *chunk = ((void *)0);
  struct timeval start; struct timeval end;
  double restore_time = 0;
  G_R_READNUM=0;
  container_vol_init();
  jcr=jcr_new();
  jcr->memIndex=index_init_r();
  jcr->nJobId=jobid;
  jcr->jobv=jobv_open(jcr->nJobId);
  if(jcr->jobv==((void *)0)){
   goto FAIL;
  }
  printf("%s,%d restore jobid:%d \n", "restore.c",25,jcr->nJobId);
  while((rp=jobv_search_next_recipe(jcr->jobv))){
   if(G_VERBOSE)
      printf("send file %s \n",rp->filename);
   for(fc=rp->first;fc;fc=fc->next){
    gettimeofday(&start, ((void *)0));
    chunk=index_search_r(jcr->memIndex,fc->fingerprint);
    jcr->nSize+=chunk->length;
    gettimeofday(&end, ((void *)0));
    (restore_time)+=(end.tv_usec-start.tv_usec)*1.0/1000000+(end.tv_sec-start.tv_sec);
    if(chunk){
     chunk_free(chunk);
    }
    else
     err_msg("restore.c",41,"not found");
   }
   recipe_free(rp);
  }
  printf("read chunk speed : %20.4f MB/s \n",jcr->nSize*1.0/restore_time/(1024*1024));
  double speed = G_R_READNUM*1.0 /(jcr->nSize/(1024*1024));
  char str[30] = {0};
  snprintf(str,30,"%f\t",speed);
  if(G_FILE_FD){
   write(G_FILE_FD,str,strlen(str));
  }
  printf("read containere number:%d , %20.4f /MB \n",G_R_READNUM, speed);
 jobv_destroy(jcr->jobv);
  FAIL:
  index_destroy_r(jcr->memIndex);
  jcr_free(jcr);
  container_vol_destroy();
}

variable_types: jobid 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: 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: struct timeval { long tv_sec; long tv_usec; }

variable_types: speed double

variable_types:
str
char [30]

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 recipe_tag { int fileindex; int chunknum; char filename[256]; struct finger_chunk_tag *first; struct finger_chunk_tag *last; }

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

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


restore

decompiled_code:
__int64 __fastcall restore(unsigned int a1, __int64 a2)
{
__int64 v2; // rax
unsigned int *v3; // r12
__int64 v5; // rax
const char *v6; // rbp
size_t v7; // rax
__int64 v8; // r14
size_t v9; // rax
__int64 i; // rbx
int *v11; // rbp
double v12; // [rsp+8h] [rbp-50h]
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF
struct timeval v14; // [rsp+20h] [rbp-38h] BYREF

G_R_READNUM = 0;
container_vol_init();
v2 = jcr_new();
*(_DWORD *)(v2 + 4) = a1;
v3 = (unsigned int *)v2;
*(_QWORD *)(v2 + 568) = index_init_r();
if ( (unsigned int)_isoc99_sscanf(a2, &restore_cmd, v3) == 1 )
{
v5 = jobv_open(*v3);
*((_QWORD *)v3 + 70) = v5;
if ( v5 )
{
printf("%s,%d restore jobid:%d \n", "restore.c", 90LL, *v3);
v6 = (const char *)(*((_QWORD *)v3 + 70) + 8LL);
v7 = strlen(v6);
bnet_send(a1, v6, v7);
v12 = 0.0;
while ( 1 )
{
v8 = jobv_search_next_recipe(*((_QWORD *)v3 + 70));
if ( !v8 )
break;
if ( G_VERBOSE )
printf("send file %s \n", (const char *)(v8 + 8));
v9 = strlen((const char *)(v8 + 8));
bnet_send(a1, v8 + 8, v9);
for ( i = *(_QWORD *)(v8 + 264); i; i = *(_QWORD *)(i + 40) )
{
gettimeofday(&tv, 0LL);
v11 = (int *)index_search_r(*((_QWORD *)v3 + 71), i);
*((_QWORD *)v3 + 66) += *v11;
gettimeofday(&v14, 0LL);
v12 = (double)(LODWORD(v14.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v14.tv_sec) - LODWORD(tv.tv_sec))
+ v12;
bnet_send(a1, *((_QWORD *)v11 + 3), (unsigned int)*v11);
chunk_free(v11);
}
bnet_signal(a1, 4294967291LL);
recipe_free(v8);
}
printf("read chunk speed : %20.4f MB/s \n", (double)(int)*((_QWORD *)v3 + 66) / v12 * 0.00000095367431640625);
printf(
"read containere number:%d , %20.4f /MB \n",
G_R_READNUM,
(double)G_R_READNUM / (double)(int)(*((_QWORD *)v3 + 66) / 0x100000LL));
}
}
bnet_signal(a1, 4294967290LL);
jobv_destroy(*((_QWORD *)v3 + 70));
index_destroy_r(*((_QWORD *)v3 + 71));
jcr_free(v3);
return container_vol_destroy();
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
__int64 v2; // rax
unsigned int *v3; // r12
__int64 v5; // rax
const char *v6; // rbp
size_t v7; // rax
__int64 v8; // r14
size_t v9; // rax
__int64 i; // rbx
int *v11; // rbp
double v12; // [rsp+8h] [rbp-50h]
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF
struct timeval v14; // [rsp+20h] [rbp-38h] BYREF

G_R_READNUM = 0;
container_vol_init();
v2 = jcr_new();
*(_DWORD *)(v2 + 4) = a1;
v3 = (unsigned int *)v2;
*(_QWORD *)(v2 + 568) = index_init_r();
if ( (unsigned int)_isoc99_sscanf(a2, &restore_cmd, v3) == 1 )
{
v5 = jobv_open(*v3);
*((_QWORD *)v3 + 70) = v5;
if ( v5 )
{
printf("%s,%d restore jobid:%d \n", "restore.c", 90LL, *v3);
v6 = (const char *)(*((_QWORD *)v3 + 70) + 8LL);
v7 = strlen(v6);
bnet_send(a1, v6, v7);
v12 = 0.0;
while ( 1 )
{
v8 = jobv_search_next_recipe(*((_QWORD *)v3 + 70));
if ( !v8 )
break;
if ( G_VERBOSE )
printf("send file %s \n", (const char *)(v8 + 8));
v9 = strlen((const char *)(v8 + 8));
bnet_send(a1, v8 + 8, v9);
for ( i = *(_QWORD *)(v8 + 264); i; i = *(_QWORD *)(i + 40) )
{
gettimeofday(&tv, 0LL);
v11 = (int *)index_search_r(*((_QWORD *)v3 + 71), i);
*((_QWORD *)v3 + 66) += *v11;
gettimeofday(&v14, 0LL);
v12 = (double)(LODWORD(v14.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v14.tv_sec) - LODWORD(tv.tv_sec))
+ v12;
bnet_send(a1, *((_QWORD *)v11 + 3), (unsigned int)*v11);
chunk_free(v11);
}
bnet_signal(a1, 4294967291LL);
recipe_free(v8);
}
printf("read chunk speed : %20.4f MB/s \n", (double)(int)*((_QWORD *)v3 + 66) / v12 * 0.00000095367431640625);
printf(
"read containere number:%d , %20.4f /MB \n",
G_R_READNUM,
(double)G_R_READNUM / (double)(int)(*((_QWORD *)v3 + 66) / 0x100000LL));
}
}
bnet_signal(a1, 4294967290LL);
jobv_destroy(*((_QWORD *)v3 + 70));
index_destroy_r(*((_QWORD *)v3 + 71));
jcr_free(v3);
return container_vol_destroy();
}

original_code:
void restore(int fd,char *msg){
  JCR *jcr=((void *)0);
  Recipe *rp=((void *)0);
  FingerChunk *fc=((void *)0);
  Chunk *chunk=((void *)0);
  struct timeval start,end;
  double restore_time=0;
  G_R_READNUM=0;
  container_vol_init();
  jcr=jcr_new();
  jcr->dataSocket=fd;
  jcr->memIndex=index_init_r();
  if(sscanf(msg,restore_cmd,&jcr->nJobId)!=1){
   goto FAIL;
  }
  jcr->jobv=jobv_open(jcr->nJobId);
  if(jcr->jobv==((void *)0)){
   goto FAIL;
  }
  printf("%s,%d restore jobid:%d \n", "restore.c",90,jcr->nJobId);
  bnet_send(fd,jcr->jobv->szBackupPath,strlen(jcr->jobv->szBackupPath));
  while((rp=jobv_search_next_recipe(jcr->jobv))){
   if(G_VERBOSE)
      printf("send file %s \n",rp->filename);
   bnet_send(fd,rp->filename,strlen(rp->filename));
   for(fc=rp->first;fc;fc=fc->next){
    gettimeofday(&start, ((void *)0));
    chunk=index_search_r(jcr->memIndex,fc->fingerprint);
    jcr->nSize+=chunk->length;
    gettimeofday(&end, ((void *)0));
    (restore_time)+=(end.tv_usec-start.tv_usec)*1.0/1000000+(end.tv_sec-start.tv_sec);
    if(chunk){
     bnet_send(fd,chunk->data,chunk->length);
     chunk_free(chunk);
    }
    else
     err_msg("restore.c",124,"not found");
   }
   bnet_signal(fd,-5);
   recipe_free(rp);
  }
  printf("read chunk speed : %20.4f MB/s \n",jcr->nSize*1.0/restore_time/(1024*1024));
  double speed=G_R_READNUM*1.0 /(jcr->nSize/(1024*1024));
  printf("read containere number:%d , %20.4f /MB \n",G_R_READNUM, speed);
 FAIL:
  bnet_signal(fd,-6);
  jobv_destroy(jcr->jobv);
  index_destroy_r(jcr->memIndex);
  jcr_free(jcr);
  container_vol_destroy();
}

canonical_original_code:
void restore(int fd, char *msg){
  struct jcr *jcr = ((void *)0);
  struct recipe_tag *rp = ((void *)0);
  struct finger_chunk_tag *fc = ((void *)0);
  struct chunk_tag *chunk = ((void *)0);
  struct timeval start; struct timeval end;
  double restore_time = 0;
  G_R_READNUM=0;
  container_vol_init();
  jcr=jcr_new();
  jcr->dataSocket=fd;
  jcr->memIndex=index_init_r();
  if(sscanf(msg,restore_cmd,&jcr->nJobId)!=1){
   goto FAIL;
  }
  jcr->jobv=jobv_open(jcr->nJobId);
  if(jcr->jobv==((void *)0)){
   goto FAIL;
  }
  printf("%s,%d restore jobid:%d \n", "restore.c",90,jcr->nJobId);
  bnet_send(fd,jcr->jobv->szBackupPath,strlen(jcr->jobv->szBackupPath));
  while((rp=jobv_search_next_recipe(jcr->jobv))){
   if(G_VERBOSE)
      printf("send file %s \n",rp->filename);
   bnet_send(fd,rp->filename,strlen(rp->filename));
   for(fc=rp->first;fc;fc=fc->next){
    gettimeofday(&start, ((void *)0));
    chunk=index_search_r(jcr->memIndex,fc->fingerprint);
    jcr->nSize+=chunk->length;
    gettimeofday(&end, ((void *)0));
    (restore_time)+=(end.tv_usec-start.tv_usec)*1.0/1000000+(end.tv_sec-start.tv_sec);
    if(chunk){
     bnet_send(fd,chunk->data,chunk->length);
     chunk_free(chunk);
    }
    else
     err_msg("restore.c",124,"not found");
   }
   bnet_signal(fd,-5);
   recipe_free(rp);
  }
  printf("read chunk speed : %20.4f MB/s \n",jcr->nSize*1.0/restore_time/(1024*1024));
  double speed = G_R_READNUM*1.0 /(jcr->nSize/(1024*1024));
  printf("read containere number:%d , %20.4f /MB \n",G_R_READNUM, speed);
 FAIL:
  bnet_signal(fd,-6);
  jobv_destroy(jcr->jobv);
  index_destroy_r(jcr->memIndex);
  jcr_free(jcr);
  container_vol_destroy();
}

variable_types: fd int

variable_types:
msg
char *

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

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

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

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


decompiled_code:
// attributes: thunk
void fingerchunk_free(void *ptr)
{
free(ptr);
}

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

original_code:
void fingerchunk_free(FingerChunk * fc){
 free(fc);
}

canonical_original_code:
void fingerchunk_free(struct finger_chunk_tag *fc){
 free(fc);
}

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


decompiled_code:
int __fastcall recipe_check(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
double v3; // xmm0_8
__int128 v5[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+20h] [rbp-28h]
char v7; // [rsp+28h] [rbp-20h]

v1 = *(_QWORD *)(a1 + 24);
v6 = 0LL;
v7 = 0;
v5[0] = 0LL;
v5[1] = 0LL;
if ( v1 )
{
v2 = 0;
do
{
digestToHash(v1, v5);
printf("%s %d \n", (const char *)v5, *(unsigned int *)(v1 + 24));
v2 += *(_DWORD *)(v1 + 24);
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
v3 = (double)v2;
}
else
{
v3 = 0.0;
v2 = 0;
}
return printf(
"totalen:%d \n chunkcounts:%d \n avglen:%.2f\n",
(unsigned int)v2,
*(unsigned int *)(a1 + 8),
v3 / (double)*(int *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
double v3; // xmm0_8
__int128 v5[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+20h] [rbp-28h]
char v7; // [rsp+28h] [rbp-20h]

v1 = *(_QWORD *)(a1 + 24);
v6 = 0LL;
v7 = 0;
v5[0] = 0LL;
v5[1] = 0LL;
if ( v1 )
{
v2 = 0;
do
{
digestToHash(v1, v5);
printf("%s %d \n", (const char *)v5, *(unsigned int *)(v1 + 24));
v2 += *(_DWORD *)(v1 + 24);
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
v3 = (double)v2;
}
else
{
v3 = 0.0;
v2 = 0;
}
return printf(
"totalen:%d \n chunkcounts:%d \n avglen:%.2f\n",
(unsigned int)v2,
*(unsigned int *)(a1 + 8),
v3 / (double)*(int *)(a1 + 8));
}

original_code:
void recipe_check(Recipe *rp){
 FingerChunk *fc=rp->first;
 int totallen=0;
 char hash[41]={0};
 while(fc){
  digestToHash(fc->fingerprint,hash);
  printf("%s %d \n",hash,fc->chunklen);
  totallen+=fc->chunklen;
  fc=fc->next;
 }
 printf("totalen:%d \n  chunkcounts:%d  \n  avglen:%.2f\n",totallen,rp->chunknum,totallen*1.00/rp->chunknum);
}

canonical_original_code:
void recipe_check(struct recipe_tag *rp){
 struct finger_chunk_tag *fc = rp->first;
 int totallen = 0;
 char hash[41] = {0};
 while(fc){
  digestToHash(fc->fingerprint,hash);
  printf("%s %d \n",hash,fc->chunklen);
  totallen+=fc->chunklen;
  fc=fc->next;
 }
 printf("totalen:%d \n  chunkcounts:%d  \n  avglen:%.2f\n",totallen,rp->chunknum,totallen*1.00/rp->chunknum);
}

variable_types: struct recipe_tag { int flag; int fileindex; int chunknum; char *filename; struct finger_chunk_tag { unsigned char fingerprint[20]; char existed; int chunklen; struct finger_chunk_tag *next; } *first; struct finger_chunk_tag *last; struct recipe_tag *next; } *

variable_types: totallen int

variable_types:
hash
char [41]

user_defined_types: struct recipe_tag { int flag; int fileindex; int chunknum; char *filename; struct finger_chunk_tag *first; struct finger_chunk_tag *last; struct recipe_tag *next; }


decompiled_code:
int __fastcall backup_formal(unsigned int a1, __int64 a2)
{
char *v2; // r12
__int64 v3; // rax
__int64 v4; // rbp
__off_t v5; // rbx
int v6; // er15
_DWORD *v8; // rax
char *v9; // r14
__int64 v10; // r15
int v11; // edx
double v12; // xmm0_8
double v13; // xmm1_8
__int64 v14; // rax
__int64 v15; // rdx
int v16; // eax
int fd; // [rsp+0h] [rbp-2A4h]
double v18; // [rsp+4h] [rbp-2A0h]
int v19; // [rsp+14h] [rbp-290h]
int v20; // [rsp+28h] [rbp-27Ch] BYREF
struct timeval tv; // [rsp+2Ch] [rbp-278h] BYREF
struct timeval v22; // [rsp+3Ch] [rbp-268h] BYREF
struct timeval v23; // [rsp+4Ch] [rbp-258h] BYREF
struct timeval v24; // [rsp+5Ch] [rbp-248h] BYREF
__int128 v25[16]; // [rsp+6Ch] [rbp-238h] BYREF
char dest[312]; // [rsp+16Ch] [rbp-138h] BYREF

v25[0] = 0LL;
v25[1] = 0LL;
v25[2] = 0LL;
v25[3] = 0LL;
v25[4] = 0LL;
v25[5] = 0LL;
v25[6] = 0LL;
v25[7] = 0LL;
v25[8] = 0LL;
v25[9] = 0LL;
v25[10] = 0LL;
v25[11] = 0LL;
v25[12] = 0LL;
v25[13] = 0LL;
v25[14] = 0LL;
v25[15] = 0LL;
v2 = (char *)calloc(1uLL, 0x10015uLL);
jobcount_init();
v3 = jcr_new();
*(_DWORD *)(v3 + 4) = a1;
v4 = v3;
memset(dest, 0, 0x100uLL);
strcpy(stpcpy(dest, &BackupVolPath), "data_vol");
fd = open(dest, 66, 420LL);
if ( fd < 0 )
{
err_msg("backup_restore.c", 43LL, "can't open file");
v18 = *(double *)&LC8;
}
else
{
printf("%s %d vol_name:%s\n", "backup_restore.c", 46LL, dest);
v5 = lseek(fd, 0LL, 2);
gettimeofday(&tv, 0LL);
v6 = _isoc99_sscanf(a2, &backup_cmd, v25);
if ( v6 == 1 )
{
v8 = (_DWORD *)jobv_new(v25);
*(_QWORD *)(v4 + 560) = v8;
*(_DWORD *)v4 = *v8;
puts("===========backup start==============");
printf("%s,%d pathname:%s \n", "backup_restore.c", 61LL, (const char *)v25);
v18 = *(double *)&LC8;
while ( (unsigned int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v20) != -100 )
{
if ( v20 == -6 )
{
printf("%s %d backup is over\n", "backup_restore.c", 66LL);
break;
}
v9 = (char *)recipe_new();
memcpy(v9 + 8, v2, v20);
*(_DWORD *)v9 = v6;
v19 = v6 + 1;
while ( (int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v20) > 0 )
{
v10 = fingerchunk_new(v2, 0LL);
*(_QWORD *)(v10 + 24) = v5;
v11 = v20 - 20;
*(_DWORD *)(v10 + 32) = v20 - 20;
check_data_isra_0(v10, (__int64)(v2 + 20), v11);
gettimeofday(&v23, 0LL);
if ( (unsigned int)writen((unsigned int)fd, v2 + 20, *(unsigned int *)(v10 + 32)) != *(_DWORD *)(v10 + 32) )
err_msg("backup_restore.c", 85LL, "wrintn wrong");
gettimeofday(&v24, 0LL);
v12 = (double)(LODWORD(v24.tv_usec) - LODWORD(v23.tv_usec)) / 1000000.0;
v13 = (double)(LODWORD(v24.tv_sec) - LODWORD(v23.tv_sec));
v14 = *(int *)(v10 + 32);
++*(_DWORD *)(v4 + 552);
*(_QWORD *)(v4 + 528) += v14;
v5 += v14;
*(double *)(v4 + 592) = v12 + v13 + *(double *)(v4 + 592);
recipe_append_fingerchunk(v9, v10);
}
v15 = (unsigned int)(*(_DWORD *)(v4 + 524) + 1);
v16 = G_VERBOSE;
*(_DWORD *)(v4 + 524) = v15;
if ( v16 )
printf("receive file %s OK, total: %d\n", v9 + 8, v15);
jobv_insert_recipe(*(_QWORD *)(v4 + 560), v9);
v6 = v19;
}
}
else
{
v18 = *(double *)&LC8;
}
}
bnet_send(a1, "OK", 2LL);
gettimeofday(&v22, 0LL);
*(double *)(v4 + 608) = (double)(LODWORD(v22.tv_usec) - LODWORD(tv.tv_usec)) / v18
+ (double)(LODWORD(v22.tv_sec) - LODWORD(tv.tv_sec))
+ *(double *)(v4 + 608);
puts("============back over===============");
printf(
"total time:%.4f %.4f MB/s\n",
*(double *)(v4 + 608),
(double)(int)*(_QWORD *)(v4 + 528) / *(double *)(v4 + 608) / 1036288.0);
printf(
"write time:%.4f %.4f MB/s\n",
*(double *)(v4 + 592),
(double)(int)*(_QWORD *)(v4 + 528) / *(double *)(v4 + 592) / 1036288.0);
printf("chunk count:%d\n", *(unsigned int *)(v4 + 552));
printf("file count:%d\n", *(unsigned int *)(v4 + 524));
jobv_destroy(*(_QWORD *)(v4 + 560));
jcr_free(v4);
jobcount_close();
return close(fd);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, __int64 a2)
{
char *v2; // r12
__int64 v3; // rax
__int64 v4; // rbp
__off_t v5; // rbx
int v6; // er15
_DWORD *v8; // rax
char *v9; // r14
__int64 v10; // r15
int v11; // edx
double v12; // xmm0_8
double v13; // xmm1_8
__int64 v14; // rax
__int64 v15; // rdx
int v16; // eax
int fd; // [rsp+0h] [rbp-2A4h]
double v18; // [rsp+4h] [rbp-2A0h]
int v19; // [rsp+14h] [rbp-290h]
int v20; // [rsp+28h] [rbp-27Ch] BYREF
struct timeval tv; // [rsp+2Ch] [rbp-278h] BYREF
struct timeval v22; // [rsp+3Ch] [rbp-268h] BYREF
struct timeval v23; // [rsp+4Ch] [rbp-258h] BYREF
struct timeval v24; // [rsp+5Ch] [rbp-248h] BYREF
__int128 v25[16]; // [rsp+6Ch] [rbp-238h] BYREF
char dest[312]; // [rsp+16Ch] [rbp-138h] BYREF

v25[0] = 0LL;
v25[1] = 0LL;
v25[2] = 0LL;
v25[3] = 0LL;
v25[4] = 0LL;
v25[5] = 0LL;
v25[6] = 0LL;
v25[7] = 0LL;
v25[8] = 0LL;
v25[9] = 0LL;
v25[10] = 0LL;
v25[11] = 0LL;
v25[12] = 0LL;
v25[13] = 0LL;
v25[14] = 0LL;
v25[15] = 0LL;
v2 = (char *)calloc(1uLL, 0x10015uLL);
jobcount_init();
v3 = jcr_new();
*(_DWORD *)(v3 + 4) = a1;
v4 = v3;
memset(dest, 0, 0x100uLL);
strcpy(stpcpy(dest, &BackupVolPath), "data_vol");
fd = open(dest, 66, 420LL);
if ( fd < 0 )
{
err_msg("backup_restore.c", 43LL, "can't open file");
v18 = *(double *)&LC8;
}
else
{
printf("%s %d vol_name:%s\n", "backup_restore.c", 46LL, dest);
v5 = lseek(fd, 0LL, 2);
gettimeofday(&tv, 0LL);
v6 = _isoc99_sscanf(a2, &backup_cmd, v25);
if ( v6 == 1 )
{
v8 = (_DWORD *)jobv_new(v25);
*(_QWORD *)(v4 + 560) = v8;
*(_DWORD *)v4 = *v8;
puts("===========backup start==============");
printf("%s,%d pathname:%s \n", "backup_restore.c", 61LL, (const char *)v25);
v18 = *(double *)&LC8;
while ( (unsigned int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v20) != -100 )
{
if ( v20 == -6 )
{
printf("%s %d backup is over\n", "backup_restore.c", 66LL);
break;
}
v9 = (char *)recipe_new();
memcpy(v9 + 8, v2, v20);
*(_DWORD *)v9 = v6;
v19 = v6 + 1;
while ( (int)bnet_recv(*(unsigned int *)(v4 + 4), v2, &v20) > 0 )
{
v10 = fingerchunk_new(v2, 0LL);
*(_QWORD *)(v10 + 24) = v5;
v11 = v20 - 20;
*(_DWORD *)(v10 + 32) = v20 - 20;
func0(v10, (__int64)(v2 + 20), v11);
gettimeofday(&v23, 0LL);
if ( (unsigned int)writen((unsigned int)fd, v2 + 20, *(unsigned int *)(v10 + 32)) != *(_DWORD *)(v10 + 32) )
err_msg("backup_restore.c", 85LL, "wrintn wrong");
gettimeofday(&v24, 0LL);
v12 = (double)(LODWORD(v24.tv_usec) - LODWORD(v23.tv_usec)) / 1000000.0;
v13 = (double)(LODWORD(v24.tv_sec) - LODWORD(v23.tv_sec));
v14 = *(int *)(v10 + 32);
++*(_DWORD *)(v4 + 552);
*(_QWORD *)(v4 + 528) += v14;
v5 += v14;
*(double *)(v4 + 592) = v12 + v13 + *(double *)(v4 + 592);
recipe_append_fingerchunk(v9, v10);
}
v15 = (unsigned int)(*(_DWORD *)(v4 + 524) + 1);
v16 = G_VERBOSE;
*(_DWORD *)(v4 + 524) = v15;
if ( v16 )
printf("receive file %s OK, total: %d\n", v9 + 8, v15);
jobv_insert_recipe(*(_QWORD *)(v4 + 560), v9);
v6 = v19;
}
}
else
{
v18 = *(double *)&LC8;
}
}
bnet_send(a1, "OK", 2LL);
gettimeofday(&v22, 0LL);
*(double *)(v4 + 608) = (double)(LODWORD(v22.tv_usec) - LODWORD(tv.tv_usec)) / v18
+ (double)(LODWORD(v22.tv_sec) - LODWORD(tv.tv_sec))
+ *(double *)(v4 + 608);
puts("============back over===============");
printf(
"total time:%.4f %.4f MB/s\n",
*(double *)(v4 + 608),
(double)(int)*(_QWORD *)(v4 + 528) / *(double *)(v4 + 608) / 1036288.0);
printf(
"write time:%.4f %.4f MB/s\n",
*(double *)(v4 + 592),
(double)(int)*(_QWORD *)(v4 + 528) / *(double *)(v4 + 592) / 1036288.0);
printf("chunk count:%d\n", *(unsigned int *)(v4 + 552));
printf("file count:%d\n", *(unsigned int *)(v4 + 524));
jobv_destroy(*(_QWORD *)(v4 + 560));
jcr_free(v4);
jobcount_close();
return close(fd);
}

original_code:
void backup_formal(int fd,char *msg){
 JCR *jcr=((void *)0);
 char fileset[256]={0};
 char *buf=(char *)calloc(1,64*1024 +21);
 int len;
 int index=1;
 char vol_name[256];
 int vol_fd;
 Recipe *rp=((void *)0);
 FingerChunk *fc=((void *)0);
 char *p=((void *)0);
 int64_t rwlen=0;
 jobcount_init();
 jcr=jcr_new();
 jcr->dataSocket=fd;
 memset(vol_name,0,256);
 strcpy(vol_name,BackupVolPath);
 strcat(vol_name,"data_vol");
 vol_fd=open(vol_name,02| 0100,00644);
 if(vol_fd<0){
  err_msg("backup_restore.c",43,"can't open file");
  goto FAIL;
 }
 printf("%s %d vol_name:%s\n","backup_restore.c",46,vol_name);
        rwlen=lseek(vol_fd,0,2);
 struct timeval gstart,gend;
 struct timeval wstart,wend;
 gettimeofday(&gstart, ((void *)0));
 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_restore.c",61,fileset);
 while(bnet_recv(jcr->dataSocket,buf,&len)!=-100){
  if(len==-6){
   printf("%s %d backup is over\n","backup_restore.c",66);
   break;
  }
  rp=recipe_new();
  memcpy(rp->filename,buf,len);
  rp->fileindex=index++;
  while(bnet_recv(jcr->dataSocket,buf,&len)>0){
   fc=fingerchunk_new(buf,0);
   fc->offset=rwlen;
   fc->length=len-sizeof(Fingerprint);
   check_data(fc->fingerprint,buf+sizeof(Fingerprint),fc->length);
   gettimeofday(&wstart, ((void *)0));
    if(writen(vol_fd,buf+sizeof(Fingerprint),fc->length)!=fc->length)
     err_msg("backup_restore.c",85,"wrintn wrong");
   gettimeofday(&wend, ((void *)0));
   (jcr->writeDataTime)+=(wend.tv_usec-wstart.tv_usec)*1.0/1000000+(wend.tv_sec-wstart.tv_sec);
   rwlen+=fc->length;
   jcr->nChunkCount++;
   jcr->nSize+=fc->length;
   recipe_append_fingerchunk(rp,fc);
  }
  jcr->nFileCount++;
  if(G_VERBOSE)
   printf("receive file %s OK, total: %d\n",rp->filename,jcr->nFileCount);
  jobv_insert_recipe(jcr->jobv, rp);
  rp=((void *)0);
 }
FAIL:
 bnet_send(fd,"OK",2);
 gettimeofday(&gend, ((void *)0));
 (jcr->recvTime)+=(gend.tv_usec-gstart.tv_usec)*1.0/1000000+(gend.tv_sec-gstart.tv_sec);
 printf("============back over===============\n");
 printf("total time:%.4f   %.4f MB/s\n",jcr->recvTime,jcr->nSize*1.0/jcr->recvTime/1036288.0);
 printf("write time:%.4f  %.4f MB/s\n",jcr->writeDataTime,jcr->nSize*1.0/jcr->writeDataTime/1036288.0);
 printf("chunk count:%d\n",jcr->nChunkCount);
 printf("file count:%d\n",jcr->nFileCount);
 if(rp){
  recipe_free(rp);
 }
 jobv_destroy(jcr->jobv);
 jcr_free(jcr);
 jobcount_close();
 close(vol_fd);
}

canonical_original_code:
void backup_formal(int fd, char *msg){
 struct jcr *jcr = ((void *)0);
 char fileset[256] = {0};
 char *buf = (char *)calloc(1,64*1024 +21);
 int len;
 int index = 1;
 char vol_name[256];
 int vol_fd;
 struct recipe_tag *rp = ((void *)0);
 struct finger_chunk_tag *fc = ((void *)0);
 char *p = ((void *)0);
 long rwlen = 0;
 jobcount_init();
 jcr=jcr_new();
 jcr->dataSocket=fd;
 memset(vol_name,0,256);
 strcpy(vol_name,BackupVolPath);
 strcat(vol_name,"data_vol");
 vol_fd=open(vol_name,02| 0100,00644);
 if(vol_fd<0){
  err_msg("backup_restore.c",43,"can't open file");
  goto FAIL;
 }
 printf("%s %d vol_name:%s\n","backup_restore.c",46,vol_name);
        rwlen=lseek(vol_fd,0,2);
 struct timeval gstart; struct timeval gend;
 struct timeval wstart; struct timeval wend;
 gettimeofday(&gstart, ((void *)0));
 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_restore.c",61,fileset);
 while(bnet_recv(jcr->dataSocket,buf,&len)!=-100){
  if(len==-6){
   printf("%s %d backup is over\n","backup_restore.c",66);
   break;
  }
  rp=recipe_new();
  memcpy(rp->filename,buf,len);
  rp->fileindex=index++;
  while(bnet_recv(jcr->dataSocket,buf,&len)>0){
   fc=fingerchunk_new(buf,0);
   fc->offset=rwlen;
   fc->length=len-sizeof(Fingerprint);
   check_data(fc->fingerprint,buf+sizeof(Fingerprint),fc->length);
   gettimeofday(&wstart, ((void *)0));
    if(writen(vol_fd,buf+sizeof(Fingerprint),fc->length)!=fc->length)
     err_msg("backup_restore.c",85,"wrintn wrong");
   gettimeofday(&wend, ((void *)0));
   (jcr->writeDataTime)+=(wend.tv_usec-wstart.tv_usec)*1.0/1000000+(wend.tv_sec-wstart.tv_sec);
   rwlen+=fc->length;
   jcr->nChunkCount++;
   jcr->nSize+=fc->length;
   recipe_append_fingerchunk(rp,fc);
  }
  jcr->nFileCount++;
  if(G_VERBOSE)
   printf("receive file %s OK, total: %d\n",rp->filename,jcr->nFileCount);
  jobv_insert_recipe(jcr->jobv, rp);
  rp=((void *)0);
 }
FAIL:
 bnet_send(fd,"OK",2);
 gettimeofday(&gend, ((void *)0));
 (jcr->recvTime)+=(gend.tv_usec-gstart.tv_usec)*1.0/1000000+(gend.tv_sec-gstart.tv_sec);
 printf("============back over===============\n");
 printf("total time:%.4f   %.4f MB/s\n",jcr->recvTime,jcr->nSize*1.0/jcr->recvTime/1036288.0);
 printf("write time:%.4f  %.4f MB/s\n",jcr->writeDataTime,jcr->nSize*1.0/jcr->writeDataTime/1036288.0);
 printf("chunk count:%d\n",jcr->nChunkCount);
 printf("file count:%d\n",jcr->nFileCount);
 if(rp){
  recipe_free(rp);
 }
 jobv_destroy(jcr->jobv);
 jcr_free(jcr);
 jobcount_close();
 close(vol_fd);
}

variable_types:
fileset
char [256]

variable_types:
buf
char *

variable_types: len int

variable_types: index int

variable_types:
p
char *

variable_types: rwlen long

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

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 DList { struct node_t *head; struct node_t *tail; int size; }

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


decompiled_code:
__int64 __fastcall restore_formal(unsigned int a1, __int64 a2)
{
void *v2; // rbp
int v3; // er12
__int64 v4; // rax
unsigned int *v5; // r15
__int64 v7; // rax
const char *v8; // r14
size_t v9; // rax
__int64 v10; // r14
size_t v11; // rax
__int64 i; // rbx
int v13; // eax
int v14; // edx
char v15[312]; // [rsp+0h] [rbp-138h] BYREF

v2 = calloc(1uLL, 0x10015uLL);
memset(v15, 0, 0x100uLL);
strcpy(stpcpy(v15, &BackupVolPath), "data_vol");
v3 = open(v15, 66, 420LL);
v4 = jcr_new();
*(_DWORD *)(v4 + 4) = a1;
v5 = (unsigned int *)v4;
if ( v3 < 0 )
{
err_msg("backup_restore.c", 144LL, "can't open file");
}
else if ( (unsigned int)_isoc99_sscanf(a2, &restore_cmd, v4) == 1 )
{
v7 = jobv_open(*v5);
*((_QWORD *)v5 + 70) = v7;
if ( v7 )
{
printf("%s,%d restore jobid:%d \n", "backup_restore.c", 159LL, *v5);
v8 = (const char *)(*((_QWORD *)v5 + 70) + 8LL);
v9 = strlen(v8);
bnet_send(a1, v8, v9);
while ( 1 )
{
v10 = jobv_search_next_recipe(*((_QWORD *)v5 + 70));
if ( !v10 )
break;
if ( G_VERBOSE )
printf("send file %s \n", (const char *)(v10 + 8));
v11 = strlen((const char *)(v10 + 8));
bnet_send(a1, v10 + 8, v11);
for ( i = *(_QWORD *)(v10 + 264); i; i = *(_QWORD *)(i + 40) )
{
lseek(v3, *(_QWORD *)(i + 24), 0);
v13 = readn((unsigned int)v3, v2, *(unsigned int *)(i + 32));
v14 = *(_DWORD *)(i + 32);
if ( v13 != v14 )
{
err_msg("backup_restore.c", 178LL, "readn wrong");
v14 = *(_DWORD *)(i + 32);
}
check_data_isra_0(i, (__int64)v2, v14);
bnet_send(a1, v2, *(unsigned int *)(i + 32));
}
bnet_signal(a1, 4294967291LL);
recipe_free(v10);
}
}
}
bnet_signal(a1, 4294967290LL);
jobv_destroy(*((_QWORD *)v5 + 70));
return jcr_free(v5);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
void *v2; // rbp
int v3; // er12
__int64 v4; // rax
unsigned int *v5; // r15
__int64 v7; // rax
const char *v8; // r14
size_t v9; // rax
__int64 v10; // r14
size_t v11; // rax
__int64 i; // rbx
int v13; // eax
int v14; // edx
char v15[312]; // [rsp+0h] [rbp-138h] BYREF

v2 = calloc(1uLL, 0x10015uLL);
memset(v15, 0, 0x100uLL);
strcpy(stpcpy(v15, &BackupVolPath), "data_vol");
v3 = open(v15, 66, 420LL);
v4 = jcr_new();
*(_DWORD *)(v4 + 4) = a1;
v5 = (unsigned int *)v4;
if ( v3 < 0 )
{
err_msg("backup_restore.c", 144LL, "can't open file");
}
else if ( (unsigned int)_isoc99_sscanf(a2, &restore_cmd, v4) == 1 )
{
v7 = jobv_open(*v5);
*((_QWORD *)v5 + 70) = v7;
if ( v7 )
{
printf("%s,%d restore jobid:%d \n", "backup_restore.c", 159LL, *v5);
v8 = (const char *)(*((_QWORD *)v5 + 70) + 8LL);
v9 = strlen(v8);
bnet_send(a1, v8, v9);
while ( 1 )
{
v10 = jobv_search_next_recipe(*((_QWORD *)v5 + 70));
if ( !v10 )
break;
if ( G_VERBOSE )
printf("send file %s \n", (const char *)(v10 + 8));
v11 = strlen((const char *)(v10 + 8));
bnet_send(a1, v10 + 8, v11);
for ( i = *(_QWORD *)(v10 + 264); i; i = *(_QWORD *)(i + 40) )
{
lseek(v3, *(_QWORD *)(i + 24), 0);
v13 = readn((unsigned int)v3, v2, *(unsigned int *)(i + 32));
v14 = *(_DWORD *)(i + 32);
if ( v13 != v14 )
{
err_msg("backup_restore.c", 178LL, "readn wrong");
v14 = *(_DWORD *)(i + 32);
}
func0(i, (__int64)v2, v14);
bnet_send(a1, v2, *(unsigned int *)(i + 32));
}
bnet_signal(a1, 4294967291LL);
recipe_free(v10);
}
}
}
bnet_signal(a1, 4294967290LL);
jobv_destroy(*((_QWORD *)v5 + 70));
return jcr_free(v5);
}

original_code:
void restore_formal(int fd,char *msg){
  JCR *jcr=((void *)0);
  Recipe *rp=((void *)0);
  FingerChunk *fc=((void *)0);
  char *buf=(char *)calloc(1,64*1024 +21);
  char vol_name[256];
  int vol_fd;
  memset(vol_name,0,256);
  strcpy(vol_name,BackupVolPath);
  strcat(vol_name,"data_vol");
  vol_fd=open(vol_name,02| 0100,00644);
  jcr=jcr_new();
  jcr->dataSocket=fd;
  if(vol_fd<0){
   err_msg("backup_restore.c",144,"can't open file");
   goto FAIL;
  }
  if(sscanf(msg,restore_cmd,&jcr->nJobId)!=1){
   goto FAIL;
  }
  jcr->jobv=jobv_open(jcr->nJobId);
  if(jcr->jobv==((void *)0)){
   goto FAIL;
  }
  printf("%s,%d restore jobid:%d \n", "backup_restore.c",159,jcr->nJobId);
  bnet_send(fd,jcr->jobv->szBackupPath,strlen(jcr->jobv->szBackupPath));
  while((rp=jobv_search_next_recipe(jcr->jobv))){
   if(G_VERBOSE)
      printf("send file %s \n",rp->filename);
   bnet_send(fd,rp->filename,strlen(rp->filename));
   for(fc=rp->first;fc;fc=fc->next){
    lseek(vol_fd,fc->offset,0);
    if(readn(vol_fd,buf,fc->length)!=fc->length)
     err_msg("backup_restore.c",178,"readn wrong");
    check_data(fc->fingerprint,buf,fc->length);
    bnet_send(fd,buf,fc->length);
   }
   bnet_signal(fd,-5);
   recipe_free(rp);
  }
 FAIL:
  bnet_signal(fd,-6);
  jobv_destroy(jcr->jobv);
  jcr_free(jcr);
}

canonical_original_code:
void restore_formal(int fd, char *msg){
  struct jcr *jcr = ((void *)0);
  struct recipe_tag *rp = ((void *)0);
  struct finger_chunk_tag *fc = ((void *)0);
  char *buf = (char *)calloc(1,64*1024 +21);
  char vol_name[256];
  int vol_fd;
  memset(vol_name,0,256);
  strcpy(vol_name,BackupVolPath);
  strcat(vol_name,"data_vol");
  vol_fd=open(vol_name,02| 0100,00644);
  jcr=jcr_new();
  jcr->dataSocket=fd;
  if(vol_fd<0){
   err_msg("backup_restore.c",144,"can't open file");
   goto FAIL;
  }
  if(sscanf(msg,restore_cmd,&jcr->nJobId)!=1){
   goto FAIL;
  }
  jcr->jobv=jobv_open(jcr->nJobId);
  if(jcr->jobv==((void *)0)){
   goto FAIL;
  }
  printf("%s,%d restore jobid:%d \n", "backup_restore.c",159,jcr->nJobId);
  bnet_send(fd,jcr->jobv->szBackupPath,strlen(jcr->jobv->szBackupPath));
  while((rp=jobv_search_next_recipe(jcr->jobv))){
   if(G_VERBOSE)
      printf("send file %s \n",rp->filename);
   bnet_send(fd,rp->filename,strlen(rp->filename));
   for(fc=rp->first;fc;fc=fc->next){
    lseek(vol_fd,fc->offset,0);
    if(readn(vol_fd,buf,fc->length)!=fc->length)
     err_msg("backup_restore.c",178,"readn wrong");
    check_data(fc->fingerprint,buf,fc->length);
    bnet_send(fd,buf,fc->length);
   }
   bnet_signal(fd,-5);
   recipe_free(rp);
  }
 FAIL:
  bnet_signal(fd,-6);
  jobv_destroy(jcr->jobv);
  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; } *

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

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


original_code:
int delete_client(int sock, char* arg) {
 char buf[256]={0};
 int len=0;
 int jobid;
 if (sscanf(arg, "%d", &jobid) != 1) {
  err_msg("delete.c",10,"cmd wrong");
  return 1;
 }
 sprintf(buf, delete_cmd, jobid);
 printf("%s \n",buf);
 bnet_send(sock, buf, strlen(buf));
 if(bnet_recv(sock,buf,&len)>0){
  printf("%s \n",buf);
 }
 else
  err_msg("delete.c",21,"delete job  fail");
 return 0;
}

canonical_original_code:
int delete_client(int sock, char *arg) {
 char buf[256] = {0};
 int len = 0;
 int jobid;
 if (sscanf(arg, "%d", &jobid) != 1) {
  err_msg("delete.c",10,"cmd wrong");
  return 1;
 }
 sprintf(buf, delete_cmd, jobid);
 printf("%s \n",buf);
 bnet_send(sock, buf, strlen(buf));
 if(bnet_recv(sock,buf,&len)>0){
  printf("%s \n",buf);
 }
 else
  err_msg("delete.c",21,"delete job  fail");
 return 0;
}

variable_types: sock int

variable_types:
arg
char *

variable_types:
buf
char [256]

variable_types: jobid int