decompiled_code:
__int64 __fastcall counter_clock_wise(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx

if ( !a2 )
return 0LL;
result = *(_QWORD *)(a2 + 40);
if ( result )
{
v3 = *(_QWORD *)(result + 32);
v4 = *(_QWORD *)(a2 + 48);
if ( v4 )
{
if ( *(_QWORD *)(v4 + 32) == a2 )
*(_QWORD *)(v4 + 32) = result;
else
*(_QWORD *)(v4 + 40) = result;
}
else if ( *a1 == a2 )
{
*a1 = result;
}
*(_QWORD *)(result + 48) = *(_QWORD *)(a2 + 48);
*(_QWORD *)(a2 + 48) = result;
*(_QWORD *)(result + 32) = a2;
*(_QWORD *)(a2 + 40) = v3;
if ( v3 )
*(_QWORD *)(v3 + 48) = a2;
}
return result;
}

original_code:
rb_node* counter_clock_wise(rb_node**root,rb_node* node){
    if(node == ((void *)0) || node->rchild == ((void *)0))
    return ((void *)0);
    rb_node *rb_1=node, *rb_2=node->rchild, *rb_3=node->rchild->lchild;
    if(rb_1->parent != ((void *)0)){
    if(rb_1->parent->lchild == rb_1)
        rb_1->parent->lchild = rb_2;
    else
        rb_1->parent->rchild = rb_2;
    }
    else if(rb_1 == *root){
    *root = rb_2;
}
    rb_2->parent = rb_1->parent;
    rb_1->parent = rb_2;
      rb_2->lchild = rb_1;
      rb_1->rchild = rb_3;
      if(rb_3 != ((void *)0))rb_3->parent = rb_1;
      return rb_2;
  }

canonical_original_code:
struct rb_node_t *counter_clock_wise(struct rb_node_t **root, struct rb_node_t *node){
    if(node == ((void *)0) || node->rchild == ((void *)0))
    return ((void *)0);
    struct rb_node_t *rb_1 = node; struct rb_node_t *rb_2 = node->rchild; struct rb_node_t *rb_3 = node->rchild->lchild;
    if(rb_1->parent != ((void *)0)){
    if(rb_1->parent->lchild == rb_1)
        rb_1->parent->lchild = rb_2;
    else
        rb_1->parent->rchild = rb_2;
    }
    else if(rb_1 == *root){
    *root = rb_2;
}
    rb_2->parent = rb_1->parent;
    rb_1->parent = rb_2;
      rb_2->lchild = rb_1;
      rb_1->rchild = rb_3;
      if(rb_3 != ((void *)0))rb_3->parent = rb_1;
      return rb_2;
  }

user_defined_types: struct rb_node_t { unsigned char key[20]; unsigned int hash; int colour; struct rb_node_t *lchild; void *data; }


repo: zhoupj/Deduper

original_code:
void rb_insert(rb_node **root,unsigned char key[],void *data){
    rb_node *p=*root, *q=((void *)0);
   int left=1;
   unsigned int hash;
   hash=sdbm_hash(key);
   if(*root == ((void *)0)){
    *root = get_node(((void *)0), key,hash,data);
    (*root)->colour = BLACK;
    return;
    }
    while(p != ((void *)0)){
     q = p;
     if(hash < p->hash)
        { p = p->lchild;left=1;}
     else if(hash > p->hash)
         {p = p->rchild;left=0;}
     else{
          if(memcmp(key,p->key,20)<0)
       { p = p->lchild;left=1;}
   else if (memcmp(key,p->key,20)>0)
         {p = p->rchild;left=0;}
   else
    {
    printf("%s:%d same key\n","libs/rbtree.c",142);
    return;
    }
   }
    }
    if(left)
     q->lchild = get_node(q, key,hash,data);
    else
      q->rchild = get_node(q, key,hash,data);
     while(q != ((void *)0) && q->colour == RED){
      p = q->parent;
      if(p->lchild == q){
          if(q->rchild != ((void *)0) && q->rchild->colour == RED)
          counter_clock_wise(root,q);
          q = clock_wise(root,p);
          q->lchild->colour = BLACK;
      }
      else{
          if(q->lchild != ((void *)0) && q->lchild->colour == RED)
          clock_wise(root,q);
          q = counter_clock_wise(root,p);
          q->rchild->colour = BLACK;
      }
      q = q->parent;
     }
     (*root)->colour = BLACK;
 }

canonical_original_code:
void rb_insert(struct rb_node_t **root, unsigned char key[], void *data){
    struct rb_node_t *p = *root; struct rb_node_t *q = ((void *)0);
   int left = 1;
   unsigned int hash;
   hash=sdbm_hash(key);
   if(*root == ((void *)0)){
    *root = get_node(((void *)0), key,hash,data);
    (*root)->colour = BLACK;
    return;
    }
    while(p != ((void *)0)){
     q = p;
     if(hash < p->hash)
        { p = p->lchild;left=1;}
     else if(hash > p->hash)
         {p = p->rchild;left=0;}
     else{
          if(memcmp(key,p->key,20)<0)
       { p = p->lchild;left=1;}
   else if (memcmp(key,p->key,20)>0)
         {p = p->rchild;left=0;}
   else
    {
    printf("%s:%d same key\n","libs/rbtree.c",142);
    return;
    }
   }
    }
    if(left)
     q->lchild = get_node(q, key,hash,data);
    else
      q->rchild = get_node(q, key,hash,data);
     while(q != ((void *)0) && q->colour == RED){
      p = q->parent;
      if(p->lchild == q){
          if(q->rchild != ((void *)0) && q->rchild->colour == RED)
          counter_clock_wise(root,q);
          q = clock_wise(root,p);
          q->lchild->colour = BLACK;
      }
      else{
          if(q->lchild != ((void *)0) && q->lchild->colour == RED)
          clock_wise(root,q);
          q = counter_clock_wise(root,p);
          q->rchild->colour = BLACK;
      }
      q = q->parent;
     }
     (*root)->colour = BLACK;
 }

variable_types: struct rb_node_t { unsigned char key[20]; unsigned int hash; int colour; struct rb_node_t *lchild; void *data; } **

variable_types:
key
unsigned char []

variable_types:
data
void *

variable_types: left int

variable_types:
hash
unsigned int

return_type: void


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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 32) )
result = show_rb_tree();
++g_count;
if ( *(_QWORD *)(a1 + 40) )
result = show_rb_tree();
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 32) )
result = func6();
++g_count;
if ( *(_QWORD *)(a1 + 40) )
result = func6();
}
return result;
}

original_code:
void show_rb_tree(rb_node* node){
     if(node == ((void *)0))
      return;
    if(node->lchild != ((void *)0)){
     show_rb_tree(node->lchild);
     }
      g_count++;
     if(node->rchild != ((void *)0)){
     show_rb_tree(node->rchild);
     }
 }

canonical_original_code:
void show_rb_tree(struct rb_node_t *node){
     if(node == ((void *)0))
      return;
    if(node->lchild != ((void *)0)){
     show_rb_tree(node->lchild);
     }
      g_count++;
     if(node->rchild != ((void *)0)){
     show_rb_tree(node->rchild);
     }
 }

variable_types: struct rb_node_t { unsigned char key[20]; unsigned int hash; int colour; struct rb_node_t *lchild; void *data; } *


zerr

decompiled_code:
unsigned int __fastcall zerr(unsigned int a1)
{
unsigned int result; // eax

result = fwrite("zpipe: ", 1uLL, 7uLL, stderr);
if ( a1 >= 0xFFFFFFFA )
{
result = a1 + 6;
switch ( a1 )
{
case 0xFFFFFFFA:
result = fwrite("zlib version mismatch!\n", 1uLL, 0x17uLL, stderr);
break;
case 0xFFFFFFFB:
return result;
case 0xFFFFFFFC:
result = fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
break;
case 0xFFFFFFFD:
result = fwrite("invalid or incomplete deflate data\n", 1uLL, 0x23uLL, stderr);
break;
case 0xFFFFFFFE:
result = fwrite("invalid compression level\n", 1uLL, 0x1AuLL, stderr);
break;
case 0xFFFFFFFF:
if ( ferror(stdin) )
fwrite("error reading stdin\n", 1uLL, 0x14uLL, stderr);
result = ferror(stdout);
if ( result )
result = fwrite("error writing stdout\n", 1uLL, 0x15uLL, stderr);
break;
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func4(unsigned int a1)
{
unsigned int result; // eax

result = fwrite("zpipe: ", 1uLL, 7uLL, stderr);
if ( a1 >= 0xFFFFFFFA )
{
result = a1 + 6;
switch ( a1 )
{
case 0xFFFFFFFA:
result = fwrite("zlib version mismatch!\n", 1uLL, 0x17uLL, stderr);
break;
case 0xFFFFFFFB:
return result;
case 0xFFFFFFFC:
result = fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
break;
case 0xFFFFFFFD:
result = fwrite("invalid or incomplete deflate data\n", 1uLL, 0x23uLL, stderr);
break;
case 0xFFFFFFFE:
result = fwrite("invalid compression level\n", 1uLL, 0x1AuLL, stderr);
break;
case 0xFFFFFFFF:
if ( ferror(stdin) )
fwrite("error reading stdin\n", 1uLL, 0x14uLL, stderr);
result = ferror(stdout);
if ( result )
result = fwrite("error writing stdout\n", 1uLL, 0x15uLL, stderr);
break;
}
}
return result;
}

original_code:
void zerr(int ret)
{
    fputs("zpipe: ", stderr);
    switch (ret) {
    case (-1):
        if (ferror(stdin))
            fputs("error reading stdin\n", stderr);
        if (ferror(stdout))
            fputs("error writing stdout\n", stderr);
        break;
    case (-2):
        fputs("invalid compression level\n", stderr);
        break;
    case (-3):
        fputs("invalid or incomplete deflate data\n", stderr);
        break;
    case (-4):
        fputs("out of memory\n", stderr);
        break;
    case (-6):
        fputs("zlib version mismatch!\n", stderr);
    }
}

variable_types: ret int


decompiled_code:
__int64 __fastcall zlib_compress_block(__int64 a1, int a2, __int64 a3, int *a4)
{
unsigned int v4; // eax
unsigned int v5; // ebx

v4 = def_block(a1, a2, a3, a4, 0xFFFFFFFF);
v5 = v4;
if ( v4 )
zerr(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, __int64 a3, int *a4)
{
unsigned int v4; // eax
unsigned int v5; // ebx

v4 = func1(a1, a2, a3, a4, 0xFFFFFFFF);
v5 = v4;
if ( v4 )
func4(v4);
return v5;
}

original_code:
int zlib_compress_block(unsigned char *buf_in, int len_in, unsigned char *buf_out, int *len_out)
{
 int ret;
 ret = def_block(buf_in, len_in, buf_out, len_out, (-1));
 if (ret != 0)
  zerr(ret);
 return ret;
}

return_type: int


decompiled_code:
__int64 __fastcall zlib_decompress_block(__int64 a1, int a2, __int64 a3, int *a4)
{
unsigned int v4; // eax
unsigned int v5; // ebx

v4 = inf_block(a1, a2, a3, a4);
v5 = v4;
if ( v4 )
zerr(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, __int64 a3, int *a4)
{
unsigned int v4; // eax
unsigned int v5; // ebx

v4 = func3(a1, a2, a3, a4);
v5 = v4;
if ( v4 )
func4(v4);
return v5;
}

original_code:
int zlib_decompress_block(unsigned char *buf_in, int len_in, unsigned char *buf_out, int *len_out)
{
 int ret;
 ret = inf_block(buf_in, len_in, buf_out, len_out);
 if (ret != 0)
  zerr(ret);
 return ret;
}


readn

decompiled_code:
__int64 __fastcall readn(int fd, void *buf, int a3)
{
int v3; // er13
int v5; // ebx
int v6; // edx
int v7; // eax

v3 = a3;
if ( a3 > 0 )
{
v5 = a3;
while ( 1 )
{
v7 = read(fd, buf, v5);
v6 = v7;
if ( v7 < 0 )
{
if ( *_errno_location() != 4 )
return 4294967196LL;
v6 = 0;
}
else if ( !v7 )
{
return (unsigned int)(v3 - v5);
}
v5 -= v6;
buf = (char *)buf + v6;
if ( v5 <= 0 )
return (unsigned int)(v3 - v5);
}
}
v5 = a3;
return (unsigned int)(v3 - v5);
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf, int a3)
{
int v3; // er13
int v5; // ebx
int v6; // edx
int v7; // eax

v3 = a3;
if ( a3 > 0 )
{
v5 = a3;
while ( 1 )
{
v7 = read(fd, buf, v5);
v6 = v7;
if ( v7 < 0 )
{
if ( *_errno_location() != 4 )
return 4294967196LL;
v6 = 0;
}
else if ( !v7 )
{
return (unsigned int)(v3 - v5);
}
v5 -= v6;
buf = (char *)buf + v6;
if ( v5 <= 0 )
return (unsigned int)(v3 - v5);
}
}
v5 = a3;
return (unsigned int)(v3 - v5);
}

original_code:
int readn(int fd, char *vptr, int n)
{
   int nleft;
    int nread;
    char *ptr;
    ptr = vptr;
    nleft = n;
    while (nleft > 0)
 {
        if ( (nread = read(fd, ptr, nleft)) < 0)
  {
            if ((*__errno_location ()) == 4)
                nread = 0;
            else
                return(-100);
        } else if (nread == 0)
            break;
        nleft -= nread;
        ptr += nread;
    }
    return(n - nleft);
}

variable_types: fd int

variable_types:
vptr
char *

variable_types: n int

variable_types: nleft int

variable_types: nread int

variable_types:
ptr
char *


writen

decompiled_code:
__int64 __fastcall writen(int fd, void *buf, int a3)
{
unsigned int v3; // er14
int v5; // ebx
int v6; // eax
int v7; // edx

v3 = a3;
if ( a3 > 0 )
{
v5 = a3;
do
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
{
if ( v6 >= 0 )
return (unsigned int)-100;
if ( *_errno_location() != 4 )
return (unsigned int)-100;
v7 = 0;
}
v5 -= v7;
buf = (char *)buf + v7;
}
while ( v5 > 0 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, int a3)
{
unsigned int v3; // er14
int v5; // ebx
int v6; // eax
int v7; // edx

v3 = a3;
if ( a3 > 0 )
{
v5 = a3;
do
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
{
if ( v6 >= 0 )
return (unsigned int)-100;
if ( *_errno_location() != 4 )
return (unsigned int)-100;
v7 = 0;
}
v5 -= v7;
buf = (char *)buf + v7;
}
while ( v5 > 0 );
}
return v3;
}

original_code:
int writen(int fd, const char *vptr, int n)
{
    int nleft;
    int nwritten;
    const char *ptr;
    ptr = vptr;
    nleft = n;
    while (nleft > 0)
 {
        if ( (nwritten = write(fd, ptr, nleft)) <= 0)
  {
            if (nwritten < 0 && (*__errno_location ()) == 4)
                nwritten = 0;
            else
                return(-100);
        }
        nleft -= nwritten;
        ptr += nwritten;
    }
    return(n);
}

canonical_original_code:
int writen(int fd, char *vptr, int n)
{
    int nleft;
    int nwritten;
    char *ptr;
    ptr = vptr;
    nleft = n;
    while (nleft > 0)
 {
        if ( (nwritten = write(fd, ptr, nleft)) <= 0)
  {
            if (nwritten < 0 && (*__errno_location ()) == 4)
                nwritten = 0;
            else
                return(-100);
        }
        nleft -= nwritten;
        ptr += nwritten;
    }
    return(n);
}

variable_types: nwritten int


decompiled_code:
__int64 __fastcall bnet_signal(int fd, unsigned int a2)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = _bswap_32(a2);
if ( (unsigned int)writen(fd, buf, 4) == 4 )
return 0LL;
puts("failed to send signal!");
return 4294967196LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, unsigned int a2)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = func0(a2);
if ( (unsigned int)func2(fd, buf, 4) == 4 )
return 0LL;
puts("failed to send signal!");
return 4294967196LL;
}

original_code:
int bnet_signal(int fd, int sig) {
 int net_order_size = htonl(sig);
    if (writen(fd, &net_order_size, sizeof(int)) != sizeof(int)) {
        printf("failed to send signal!\n");
        return -100;
    }
    return 0;
}

variable_types: sig int


decompiled_code:
__int64 __fastcall fls32(unsigned int a1)
{
__int64 result; // rax

if ( (a1 & 0xFFFF0000) != 0 )
{
if ( (a1 & 0xFF000000) != 0 )
result = (unsigned int)(unsigned __int8)bytemsb[HIBYTE(a1)] + 24;
else
result = (unsigned int)(unsigned __int8)bytemsb[HIWORD(a1)] + 16;
}
else if ( (a1 & 0xFF00) != 0 )
{
result = (unsigned int)(unsigned __int8)bytemsb[a1 >> 8] + 8;
}
else
{
result = (unsigned __int8)bytemsb[a1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 result; // rax

if ( (a1 & 0xFFFF0000) != 0 )
{
if ( (a1 & 0xFF000000) != 0 )
result = (unsigned int)(unsigned __int8)bytemsb[HIBYTE(a1)] + 24;
else
result = (unsigned int)(unsigned __int8)bytemsb[HIWORD(a1)] + 16;
}
else if ( (a1 & 0xFF00) != 0 )
{
result = (unsigned int)(unsigned __int8)bytemsb[a1 >> 8] + 8;
}
else
{
result = (unsigned __int8)bytemsb[a1];
}
return result;
}

original_code:
static uint8_t fls32 (uint32_t v)
{
  if (v & 0xffff0000) {
    if (v & 0xff000000)
      return 24 + bytemsb[v>>24];
    else
      return 16 + bytemsb[v>>16];
  }
  if (v & 0x0000ff00)
    return 8 + bytemsb[v>>8];
  else
    return bytemsb[v];
}

canonical_original_code:
static unsigned char fls32(unsigned int v)
{
  if (v & 0xffff0000) {
    if (v & 0xff000000)
      return 24 + bytemsb[v>>24];
    else
      return 16 + bytemsb[v>>16];
  }
  if (v & 0x0000ff00)
    return 8 + bytemsb[v>>8];
  else
    return bytemsb[v];
}

variable_types:
v
unsigned int

return_type: unsigned char


polymult

decompiled_code:
__int64 __fastcall polymult(_QWORD *a1, __int64 *a2, __int64 a3, unsigned __int64 a4)
{
__int64 v4; // r8
__int64 v5; // r9
__int64 result; // rax

v4 = a3 & 1;
if ( (a3 & 1) != 0 )
v4 = a4;
v5 = 0LL;
LODWORD(result) = 1;
do
{
if ( (a3 & (1LL << result)) != 0 )
{
v5 ^= a4 >> (64 - (unsigned __int8)result);
v4 ^= a4 << result;
}
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 64 );
if ( a1 )
*a1 = v5;
if ( a2 )
*a2 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 *a2, __int64 a3, unsigned __int64 a4)
{
__int64 v4; // r8
__int64 v5; // r9
__int64 result; // rax

v4 = a3 & 1;
if ( (a3 & 1) != 0 )
v4 = a4;
v5 = 0LL;
LODWORD(result) = 1;
do
{
if ( (a3 & (1LL << result)) != 0 )
{
v5 ^= a4 >> (64 - (unsigned __int8)result);
v4 ^= a4 << result;
}
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 64 );
if ( a1 )
*a1 = v5;
if ( a2 )
*a2 = v4;
return result;
}

original_code:
static void polymult (uint64_t *php, uint64_t *plp, uint64_t x, uint64_t y)
{
  int i;
  uint64_t ph = 0, pl = 0;
  if (x & 1)
    pl = y;
  for ( i = 1; i < 64; i++)
    if (x & ((int64_t)1 << i)) {
      ph ^= y >> (64 - i);
      pl ^= y << i;
    }
  if (php)
    *php = ph;
  if (plp)
    *plp = pl;
}

canonical_original_code:
static void polymult(unsigned long *php, unsigned long *plp, unsigned long x, unsigned long y)
{
  int i;
  unsigned long ph = 0; unsigned long pl = 0;
  if (x & 1)
    pl = y;
  for ( i = 1; i < 64; i++)
    if (x & ((long)1 << i)) {
      ph ^= y >> (64 - i);
      pl ^= y << i;
    }
  if (php)
    *php = ph;
  if (plp)
    *plp = pl;
}

variable_types:
php
unsigned long *

variable_types:
plp
unsigned long *

variable_types:
x
unsigned long

variable_types:
y
unsigned long

variable_types: i int

variable_types:
ph
unsigned long

variable_types:
pl
unsigned long


decompiled_code:
void windows_reset()
{
fingerprint = 0LL;
buf = 0LL;
qword_DE8 = 0LL;
qword_DF0 = 0LL;
qword_DF8 = 0LL;
qword_E00 = 0LL;
qword_E08 = 0LL;
}

canonical_decompiled_code:
void func9()
{
fingerprint = 0LL;
buf = 0LL;
qword_DE8 = 0LL;
qword_DF0 = 0LL;
qword_DF8 = 0LL;
qword_E00 = 0LL;
qword_E08 = 0LL;
}

original_code:
static void windows_reset () {
    fingerprint = 0;
    memset((char*) buf,0,sizeof (buf));
}

canonical_original_code:
static void windows_reset() {
    fingerprint = 0;
    memset((char *) buf,0,sizeof (buf));
}


decompiled_code:
void chunk_alg_init()
{
if ( !rabin_init_flag )
{
window_init(0xBFE6B8A5BF378D83LL);
rabin_init_flag = 1;
}
windows_reset();
}

canonical_decompiled_code:
void func10()
{
if ( !rabin_init_flag )
{
func8(0xBFE6B8A5BF378D83LL);
rabin_init_flag = 1;
}
func9();
}

original_code:
void chunk_alg_init(){
 if(rabin_init_flag == 0){
     window_init(0xbfe6b8a5bf378d83LL);
  rabin_init_flag = 1;
 }
    _last_pos = 0;
    _cur_pos = 0;
    windows_reset();
    _num_chunks = 0;
}


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

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

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

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

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

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

variable_types:
buf
unsigned char *

variable_types:
len
unsigned int

variable_types:
hash
unsigned char []

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

variable_types:
digest
unsigned char [20]


decompiled_code:
__int64 __fastcall chunk_data(_BYTE *a1, int a2)
{
int v3; // esi
char v4; // cl
int v6; // edi
unsigned __int8 v7; // al
unsigned __int64 v8; // rdx

windows_reset();
if ( a2 <= 0 )
{
v6 = 1;
}
else
{
v3 = bufpos;
v4 = shift;
v6 = 1;
do
{
if ( ++v3 >= 48 )
v3 = 0;
v7 = *((_BYTE *)&buf + v3);
*((_BYTE *)&buf + v3) = *a1;
v8 = fingerprint ^ U[v7];
fingerprint = v8 << 8;
fingerprint = T[v8 >> v4] ^ ((v8 << 8) | (unsigned __int8)*a1);
if ( (fingerprint & 0x1FFF) == 120 && v6 > 2047 )
{
bufpos = v3;
return (unsigned int)v6;
}
if ( v6 > 0xFFFF || a2 == v6 )
{
bufpos = v3;
return (unsigned int)v6;
}
++v6;
++a1;
}
while ( a2 >= v6 );
bufpos = v3;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1, int a2)
{
int v3; // esi
char v4; // cl
int v6; // edi
unsigned __int8 v7; // al
unsigned __int64 v8; // rdx

func9();
if ( a2 <= 0 )
{
v6 = 1;
}
else
{
v3 = bufpos;
v4 = shift;
v6 = 1;
do
{
if ( ++v3 >= 48 )
v3 = 0;
v7 = *((_BYTE *)&buf + v3);
*((_BYTE *)&buf + v3) = *a1;
v8 = fingerprint ^ U[v7];
fingerprint = v8 << 8;
fingerprint = T[v8 >> v4] ^ ((v8 << 8) | (unsigned __int8)*a1);
if ( (fingerprint & 0x1FFF) == 120 && v6 > 2047 )
{
bufpos = v3;
return (unsigned int)v6;
}
if ( v6 > 0xFFFF || a2 == v6 )
{
bufpos = v3;
return (unsigned int)v6;
}
++v6;
++a1;
}
while ( a2 >= v6 );
bufpos = v3;
}
return (unsigned int)v6;
}

original_code:
int chunk_data(unsigned char *p, int n)
{
 int i=1;
 windows_reset();
 while(i<=n){
  do{ unsigned char om; uint64_t x; if (++bufpos >= size) bufpos = 0; om = buf[bufpos]; buf[bufpos] = p[i-1]; fingerprint ^= U[om]; x = fingerprint >> shift; fingerprint <<= 8; fingerprint |= p[i-1]; fingerprint ^= T[x]; }while(0);
  if (((fingerprint & chunk_size) == 0x78 && i >= 2048)
        || i >= 65536 || i == n) {
   break;
  }
  else i++;
  }
  return i;
}

canonical_original_code:
int chunk_data(unsigned char *p, int n)
{
 int i = 1;
 windows_reset();
 while(i<=n){
  do{ unsigned char om; unsigned long x; if (++bufpos >= size) bufpos = 0; om = buf[bufpos]; buf[bufpos] = p[i-1]; fingerprint ^= U[om]; x = fingerprint >> shift; fingerprint <<= 8; fingerprint |= p[i-1]; fingerprint ^= T[x]; }while(0);
  if (((fingerprint & chunk_size) == 0x78 && i >= 2048)
        || i >= 65536 || i == n) {
   break;
  }
  else i++;
  }
  return i;
}

variable_types:
p
unsigned char *

variable_types: n int

variable_types:
om
unsigned char


decompiled_code:
void *__fastcall workq_server(void *a1)
{
pthread_t v1; // r13
int v2; // er12
int v3; // er14
__int64 v4; // rax
_QWORD *v5; // rbp
int v6; // eax
int v8; // eax
struct timezone tz; // [rsp+8h] [rbp-50h] BYREF
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF
struct timespec abstime; // [rsp+20h] [rbp-38h] BYREF

v1 = pthread_self();
printf("threadid 0x%x is created!\n", v1);
v2 = pthread_mutex_lock((pthread_mutex_t *)a1);
if ( !v2 )
{
LABEL_16:
while ( 2 )
{
gettimeofday(&tv, &tz);
abstime.tv_nsec = 0LL;
abstime.tv_sec = tv.tv_sec + 5;
while ( 1 )
{
v5 = (_QWORD *)*((_QWORD *)a1 + 18);
if ( v5 )
break;
if ( *((_DWORD *)a1 + 41) )
{
v3 = v2;
goto LABEL_4;
}
++*((_DWORD *)a1 + 44);
v6 = pthread_cond_timedwait((pthread_cond_t *)((char *)a1 + 40), (pthread_mutex_t *)a1, &abstime);
--*((_DWORD *)a1 + 44);
if ( v6 == 110 )
{
v5 = (_QWORD *)*((_QWORD *)a1 + 18);
if ( v5 )
{
v3 = 1;
goto LABEL_11;
}
v3 = 1;
LABEL_4:
v4 = *((_QWORD *)a1 + 18);
LABEL_5:
if ( *((_DWORD *)a1 + 41) )
{
v8 = *((_DWORD *)a1 + 43) - 1;
*((_DWORD *)a1 + 43) = v8;
if ( !v8 )
pthread_cond_broadcast((pthread_cond_t *)((char *)a1 + 40));
pthread_mutex_unlock((pthread_mutex_t *)a1);
printf("threadid 0x%x is exit normally!\n", v1);
return 0LL;
}
if ( v3 && !v4 )
{
printf("timedout,exit ,threadid 0x%x\n", v1);
--*((_DWORD *)a1 + 43);
pthread_mutex_unlock((pthread_mutex_t *)a1);
return 0LL;
}
goto LABEL_16;
}
if ( v6 )
{
--*((_DWORD *)a1 + 43);
pthread_mutex_unlock((pthread_mutex_t *)a1);
return 0LL;
}
}
v3 = v2;
LABEL_11:
*((_QWORD *)a1 + 18) = *v5;
if ( *((_QWORD **)a1 + 19) == v5 )
*((_QWORD *)a1 + 19) = 0LL;
if ( !pthread_mutex_unlock((pthread_mutex_t *)a1) )
{
(*((void (__fastcall **)(_QWORD))a1 + 23))(v5[1]);
free(v5);
if ( !pthread_mutex_lock((pthread_mutex_t *)a1) )
{
v4 = *((_QWORD *)a1 + 18);
if ( v4 )
continue;
goto LABEL_5;
}
}
break;
}
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
pthread_t v1; // r13
int v2; // er12
int v3; // er14
__int64 v4; // rax
_QWORD *v5; // rbp
int v6; // eax
int v8; // eax
struct timezone tz; // [rsp+8h] [rbp-50h] BYREF
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF
struct timespec abstime; // [rsp+20h] [rbp-38h] BYREF

v1 = pthread_self();
printf("threadid 0x%x is created!\n", v1);
v2 = pthread_mutex_lock((pthread_mutex_t *)a1);
if ( !v2 )
{
LABEL_16:
while ( 2 )
{
gettimeofday(&tv, &tz);
abstime.tv_nsec = 0LL;
abstime.tv_sec = tv.tv_sec + 5;
while ( 1 )
{
v5 = (_QWORD *)*((_QWORD *)a1 + 18);
if ( v5 )
break;
if ( *((_DWORD *)a1 + 41) )
{
v3 = v2;
goto LABEL_4;
}
++*((_DWORD *)a1 + 44);
v6 = pthread_cond_timedwait((pthread_cond_t *)((char *)a1 + 40), (pthread_mutex_t *)a1, &abstime);
--*((_DWORD *)a1 + 44);
if ( v6 == 110 )
{
v5 = (_QWORD *)*((_QWORD *)a1 + 18);
if ( v5 )
{
v3 = 1;
goto LABEL_11;
}
v3 = 1;
LABEL_4:
v4 = *((_QWORD *)a1 + 18);
LABEL_5:
if ( *((_DWORD *)a1 + 41) )
{
v8 = *((_DWORD *)a1 + 43) - 1;
*((_DWORD *)a1 + 43) = v8;
if ( !v8 )
pthread_cond_broadcast((pthread_cond_t *)((char *)a1 + 40));
pthread_mutex_unlock((pthread_mutex_t *)a1);
printf("threadid 0x%x is exit normally!\n", v1);
return 0LL;
}
if ( v3 && !v4 )
{
printf("timedout,exit ,threadid 0x%x\n", v1);
--*((_DWORD *)a1 + 43);
pthread_mutex_unlock((pthread_mutex_t *)a1);
return 0LL;
}
goto LABEL_16;
}
if ( v6 )
{
--*((_DWORD *)a1 + 43);
pthread_mutex_unlock((pthread_mutex_t *)a1);
return 0LL;
}
}
v3 = v2;
LABEL_11:
*((_QWORD *)a1 + 18) = *v5;
if ( *((_QWORD **)a1 + 19) == v5 )
*((_QWORD *)a1 + 19) = 0LL;
if ( !pthread_mutex_unlock((pthread_mutex_t *)a1) )
{
(*((void (__fastcall **)(_QWORD))a1 + 23))(v5[1]);
free(v5);
if ( !pthread_mutex_lock((pthread_mutex_t *)a1) )
{
v4 = *((_QWORD *)a1 + 18);
if ( v4 )
continue;
goto LABEL_5;
}
}
break;
}
}
return 0LL;
}

original_code:
void *workq_server(void *arg)
{
 struct timespec timeout;
 workq_t *wq = (workq_t *)arg;
 workq_ele_t *we;
 int stat, timedout;
 struct timeval tv;
 struct timezone tz;
  printf("threadid 0x%x is created!\n",pthread_self());
 if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
  return ((void *)0);
 }
     for (;;)
 {
  timedout = 0;
  gettimeofday(&tv, &tz);
  timeout.tv_nsec = 0;
  timeout.tv_sec = tv.tv_sec + 5;
  while (wq->first == ((void *)0) && !wq->quit)
  {
   wq->idle_workers++;
   stat = pthread_cond_timedwait(&wq->work, &wq->mutex, &timeout);
   wq->idle_workers--;
   if (stat == 110) {
    timedout = 1;
    break;
   } else if (stat != 0) {
    wq->num_workers--;
    pthread_mutex_unlock(&wq->mutex);
    return ((void *)0);
   }
  }
  we = wq->first;
  if (we != ((void *)0))
        {
   wq->first = we->next;
   if (wq->last == we) {
    wq->last = ((void *)0);
   }
   if ((stat = pthread_mutex_unlock(&wq->mutex)) != 0) {
    return ((void *)0);
   }
   wq->engine(we->data);
   free(we);
   if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
    return ((void *)0);
   }
  }
  if (wq->first == ((void *)0) && wq->quit) {
   wq->num_workers--;
   if (wq->num_workers == 0) {
    pthread_cond_broadcast(&wq->work);
   }
   pthread_mutex_unlock(&wq->mutex);
   printf("threadid 0x%x is exit normally!\n",pthread_self());
     return ((void *)0);
  }
  if (wq->first == ((void *)0) && timedout) {
   printf("timedout,exit ,threadid 0x%x\n",pthread_self());
   wq->num_workers--;
   break;
  }
 }
 pthread_mutex_unlock(&wq->mutex);
 return ((void *)0);
}

canonical_original_code:
void *workq_server(void *arg)
{
 struct timespec timeout;
 struct workq_tag *wq = (workq_t *)arg;
 struct workq_ele_tag *we;
 int stat; int timedout;
 struct timeval tv;
 struct timezone tz;
  printf("threadid 0x%x is created!\n",pthread_self());
 if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
  return ((void *)0);
 }
     for (;;)
 {
  timedout = 0;
  gettimeofday(&tv, &tz);
  timeout.tv_nsec = 0;
  timeout.tv_sec = tv.tv_sec + 5;
  while (wq->first == ((void *)0) && !wq->quit)
  {
   wq->idle_workers++;
   stat = pthread_cond_timedwait(&wq->work, &wq->mutex, &timeout);
   wq->idle_workers--;
   if (stat == 110) {
    timedout = 1;
    break;
   } else if (stat != 0) {
    wq->num_workers--;
    pthread_mutex_unlock(&wq->mutex);
    return ((void *)0);
   }
  }
  we = wq->first;
  if (we != ((void *)0))
        {
   wq->first = we->next;
   if (wq->last == we) {
    wq->last = ((void *)0);
   }
   if ((stat = pthread_mutex_unlock(&wq->mutex)) != 0) {
    return ((void *)0);
   }
   wq->engine(we->data);
   free(we);
   if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
    return ((void *)0);
   }
  }
  if (wq->first == ((void *)0) && wq->quit) {
   wq->num_workers--;
   if (wq->num_workers == 0) {
    pthread_cond_broadcast(&wq->work);
   }
   pthread_mutex_unlock(&wq->mutex);
   printf("threadid 0x%x is exit normally!\n",pthread_self());
     return ((void *)0);
  }
  if (wq->first == ((void *)0) && timedout) {
   printf("timedout,exit ,threadid 0x%x\n",pthread_self());
   wq->num_workers--;
   break;
  }
 }
 pthread_mutex_unlock(&wq->mutex);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: struct workq_tag { 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; union pthread_attr_t { char __size[56]; long __align; } attr; struct workq_ele_tag { struct workq_ele_tag *next; void *data; } *first; int valid; int quit; int max_workers; int num_workers; int idle_workers; void *(*engine)(void *arg); } *

variable_types: stat int

variable_types: timedout int

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

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }

return_type: void *

user_defined_types: struct workq_tag { union pthread_mutex_t mutex; union pthread_cond_t work; union pthread_attr_t attr; struct workq_ele_tag *first; int valid; int quit; int max_workers; int num_workers; int idle_workers; void *(*engine)(void *arg); }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long 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; }


decompiled_code:
__int64 __fastcall workq_init(pthread_mutex_t *mutex, unsigned int a2, struct __pthread_internal_list *a3)
{
pthread_attr_t *v4; // r14
unsigned int v5; // ebx

v4 = (pthread_attr_t *)(&mutex[2].__align + 1);
v5 = pthread_attr_init((pthread_attr_t *)(&mutex[2].__align + 1));
if ( !v5 )
{
v5 = pthread_attr_setdetachstate(v4, 1);
if ( v5 || (v5 = pthread_mutex_init(mutex, 0LL)) != 0 )
{
pthread_attr_destroy(v4);
}
else
{
v5 = pthread_cond_init((pthread_cond_t *)&mutex[1], 0LL);
if ( v5 )
{
pthread_mutex_destroy(mutex);
pthread_attr_destroy(v4);
}
else
{
mutex[4].__count = 0;
*(_OWORD *)(&mutex[3].__align + 3) = 0uLL;
*(&mutex[4].__align + 1) = a2;
mutex[4].__kind = 0;
mutex[4].__list.__prev = a3;
mutex[4].__lock = 233578514;
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_mutex_t *mutex, unsigned int a2, struct __pthread_internal_list *a3)
{
pthread_attr_t *v4; // r14
unsigned int v5; // ebx

v4 = (pthread_attr_t *)(&mutex[2].__align + 1);
v5 = pthread_attr_init((pthread_attr_t *)(&mutex[2].__align + 1));
if ( !v5 )
{
v5 = pthread_attr_setdetachstate(v4, 1);
if ( v5 || (v5 = pthread_mutex_init(mutex, 0LL)) != 0 )
{
pthread_attr_destroy(v4);
}
else
{
v5 = pthread_cond_init((pthread_cond_t *)&mutex[1], 0LL);
if ( v5 )
{
pthread_mutex_destroy(mutex);
pthread_attr_destroy(v4);
}
else
{
mutex[4].__count = 0;
*(_OWORD *)(&mutex[3].__align + 3) = 0uLL;
*(&mutex[4].__align + 1) = a2;
mutex[4].__kind = 0;
mutex[4].__list.__prev = a3;
mutex[4].__lock = 233578514;
}
}
}
return v5;
}

original_code:
int workq_init(workq_t *wq, int threads, void *(*engine)(void *arg))
{
 int stat;
 if ((stat = pthread_attr_init(&wq->attr)) != 0) {
  return stat;
 }
 if ((stat = pthread_attr_setdetachstate(&wq->attr, PTHREAD_CREATE_DETACHED)) != 0) {
  pthread_attr_destroy(&wq->attr);
  return stat;
 }
 if ((stat = pthread_mutex_init(&wq->mutex, ((void *)0))) != 0) {
  pthread_attr_destroy(&wq->attr);
  return stat;
 }
 if ((stat = pthread_cond_init(&wq->work, ((void *)0))) != 0) {
  pthread_mutex_destroy(&wq->mutex);
  pthread_attr_destroy(&wq->attr);
  return stat;
 }
 wq->quit = 0;
 wq->first = wq->last = ((void *)0);
 wq->max_workers = threads;
 wq->num_workers = 0;
 wq->idle_workers = 0;
 wq->engine = engine;
 wq->valid = 0xdec2012;
 return 0;
}

canonical_original_code:
int workq_init(struct workq_tag *wq, int threads, void *(*engine)(void *arg))
{
 int stat;
 if ((stat = pthread_attr_init(&wq->attr)) != 0) {
  return stat;
 }
 if ((stat = pthread_attr_setdetachstate(&wq->attr, PTHREAD_CREATE_DETACHED)) != 0) {
  pthread_attr_destroy(&wq->attr);
  return stat;
 }
 if ((stat = pthread_mutex_init(&wq->mutex, ((void *)0))) != 0) {
  pthread_attr_destroy(&wq->attr);
  return stat;
 }
 if ((stat = pthread_cond_init(&wq->work, ((void *)0))) != 0) {
  pthread_mutex_destroy(&wq->mutex);
  pthread_attr_destroy(&wq->attr);
  return stat;
 }
 wq->quit = 0;
 wq->first = wq->last = ((void *)0);
 wq->max_workers = threads;
 wq->num_workers = 0;
 wq->idle_workers = 0;
 wq->engine = engine;
 wq->valid = 0xdec2012;
 return 0;
}

variable_types: threads int

variable_types:
engine
void *(*)(void *arg)

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }

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

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

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


decompiled_code:
__int64 __fastcall workq_destroy(pthread_mutex_t *mutex)
{
unsigned int v1; // ebx
int v3; // ebp
int v4; // eax

v1 = 22;
if ( mutex[4].__lock == 233578514 )
{
v1 = pthread_mutex_lock(mutex);
if ( !v1 )
{
mutex[4].__lock = 0;
if ( (int)mutex[4].__nusers > 0 )
{
mutex[4].__count = 1;
if ( mutex[4].__kind )
{
v1 = pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
if ( v1 )
{
LABEL_8:
pthread_mutex_unlock(mutex);
return v1;
}
}
while ( (int)mutex[4].__nusers > 0 )
{
v1 = pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
if ( v1 )
goto LABEL_8;
}
}
v1 = pthread_mutex_unlock(mutex);
if ( !v1 )
{
v1 = pthread_mutex_destroy(mutex);
v3 = pthread_cond_destroy((pthread_cond_t *)&mutex[1]);
v4 = pthread_attr_destroy((pthread_attr_t *)(&mutex[2].__align + 1));
if ( !v1 )
{
if ( v3 )
v4 = v3;
v1 = v4;
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_mutex_t *mutex)
{
unsigned int v1; // ebx
int v3; // ebp
int v4; // eax

v1 = 22;
if ( mutex[4].__lock == 233578514 )
{
v1 = pthread_mutex_lock(mutex);
if ( !v1 )
{
mutex[4].__lock = 0;
if ( (int)mutex[4].__nusers > 0 )
{
mutex[4].__count = 1;
if ( mutex[4].__kind )
{
v1 = pthread_cond_broadcast((pthread_cond_t *)&mutex[1]);
if ( v1 )
{
LABEL_8:
pthread_mutex_unlock(mutex);
return v1;
}
}
while ( (int)mutex[4].__nusers > 0 )
{
v1 = pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
if ( v1 )
goto LABEL_8;
}
}
v1 = pthread_mutex_unlock(mutex);
if ( !v1 )
{
v1 = pthread_mutex_destroy(mutex);
v3 = pthread_cond_destroy((pthread_cond_t *)&mutex[1]);
v4 = pthread_attr_destroy((pthread_attr_t *)(&mutex[2].__align + 1));
if ( !v1 )
{
if ( v3 )
v4 = v3;
v1 = v4;
}
}
}
}
return v1;
}

original_code:
int workq_destroy(workq_t *wq)
{
 int stat, stat1, stat2;
 if (wq->valid != 0xdec2012) {
  return 22;
 }
 if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
  return stat;
 }
 wq->valid = 0;
 if (wq->num_workers > 0) {
  wq->quit = 1;
  if (wq->idle_workers) {
   if ((stat = pthread_cond_broadcast(&wq->work)) != 0) {
    pthread_mutex_unlock(&wq->mutex);
    return stat;
   }
  }
  while (wq->num_workers > 0) {
   if ((stat = pthread_cond_wait(&wq->work, &wq->mutex)) != 0) {
    pthread_mutex_unlock(&wq->mutex);
    return stat;
   }
  }
 }
 if ((stat = pthread_mutex_unlock(&wq->mutex)) != 0) {
  return stat;
 }
 stat = pthread_mutex_destroy(&wq->mutex);
 stat1 = pthread_cond_destroy(&wq->work);
 stat2 = pthread_attr_destroy(&wq->attr);
 return (stat != 0 ? stat : (stat1 != 0 ? stat1 : stat2));
}

canonical_original_code:
int workq_destroy(struct workq_tag *wq)
{
 int stat; int stat1; int stat2;
 if (wq->valid != 0xdec2012) {
  return 22;
 }
 if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
  return stat;
 }
 wq->valid = 0;
 if (wq->num_workers > 0) {
  wq->quit = 1;
  if (wq->idle_workers) {
   if ((stat = pthread_cond_broadcast(&wq->work)) != 0) {
    pthread_mutex_unlock(&wq->mutex);
    return stat;
   }
  }
  while (wq->num_workers > 0) {
   if ((stat = pthread_cond_wait(&wq->work, &wq->mutex)) != 0) {
    pthread_mutex_unlock(&wq->mutex);
    return stat;
   }
  }
 }
 if ((stat = pthread_mutex_unlock(&wq->mutex)) != 0) {
  return stat;
 }
 stat = pthread_mutex_destroy(&wq->mutex);
 stat1 = pthread_cond_destroy(&wq->work);
 stat2 = pthread_attr_destroy(&wq->attr);
 return (stat != 0 ? stat : (stat1 != 0 ? stat1 : stat2));
}


decompiled_code:
__int64 __fastcall workq_add(void *arg, __int64 a2, _QWORD *a3, int a4)
{
unsigned int v4; // ebp
_QWORD *v8; // rax
_QWORD *v9; // r12
__int64 v10; // rax
unsigned int v11; // er14
unsigned int v12; // er14
pthread_t newthread[8]; // [rsp+8h] [rbp-40h] BYREF

v4 = 22;
if ( *((_DWORD *)arg + 40) == 233578514 )
{
v8 = malloc(0x10uLL);
v9 = v8;
if ( !v8 )
return 12;
v8[1] = a2;
*v8 = 0LL;
v4 = pthread_mutex_lock((pthread_mutex_t *)arg);
if ( v4 )
{
free(v9);
}
else
{
if ( a4 )
{
v10 = *((_QWORD *)arg + 18);
if ( v10 )
{
*v9 = v10;
*((_QWORD *)arg + 18) = v9;
}
else
{
*((_QWORD *)arg + 18) = v9;
*((_QWORD *)arg + 19) = v9;
}
}
else
{
if ( *((_QWORD *)arg + 18) )
**((_QWORD **)arg + 19) = v9;
else
*((_QWORD *)arg + 18) = v9;
*((_QWORD *)arg + 19) = v9;
}
if ( *((int *)arg + 44) > 0 )
{
v11 = pthread_cond_broadcast((pthread_cond_t *)((char *)arg + 40));
if ( v11 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v11;
}
}
else if ( *((_DWORD *)arg + 43) < *((_DWORD *)arg + 42) )
{
v12 = pthread_create(newthread, (const pthread_attr_t *)((char *)arg + 88), workq_server, arg);
if ( v12 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v12;
}
++*((_DWORD *)arg + 43);
}
pthread_mutex_unlock((pthread_mutex_t *)arg);
if ( a3 )
*a3 = v9;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *arg, __int64 a2, _QWORD *a3, int a4)
{
unsigned int v4; // ebp
_QWORD *v8; // rax
_QWORD *v9; // r12
__int64 v10; // rax
unsigned int v11; // er14
unsigned int v12; // er14
pthread_t newthread[8]; // [rsp+8h] [rbp-40h] BYREF

v4 = 22;
if ( *((_DWORD *)arg + 40) == 233578514 )
{
v8 = malloc(0x10uLL);
v9 = v8;
if ( !v8 )
return 12;
v8[1] = a2;
*v8 = 0LL;
v4 = pthread_mutex_lock((pthread_mutex_t *)arg);
if ( v4 )
{
free(v9);
}
else
{
if ( a4 )
{
v10 = *((_QWORD *)arg + 18);
if ( v10 )
{
*v9 = v10;
*((_QWORD *)arg + 18) = v9;
}
else
{
*((_QWORD *)arg + 18) = v9;
*((_QWORD *)arg + 19) = v9;
}
}
else
{
if ( *((_QWORD *)arg + 18) )
**((_QWORD **)arg + 19) = v9;
else
*((_QWORD *)arg + 18) = v9;
*((_QWORD *)arg + 19) = v9;
}
if ( *((int *)arg + 44) > 0 )
{
v11 = pthread_cond_broadcast((pthread_cond_t *)((char *)arg + 40));
if ( v11 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v11;
}
}
else if ( *((_DWORD *)arg + 43) < *((_DWORD *)arg + 42) )
{
v12 = pthread_create(newthread, (const pthread_attr_t *)((char *)arg + 88), workq_server, arg);
if ( v12 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v12;
}
++*((_DWORD *)arg + 43);
}
pthread_mutex_unlock((pthread_mutex_t *)arg);
if ( a3 )
*a3 = v9;
}
}
return v4;
}

original_code:
int workq_add(workq_t *wq, void *element, workq_ele_t **work_item, int priority)
{
 int stat;
 workq_ele_t *item;
 pthread_t id;
 if (wq->valid != 0xdec2012) {
  return 22;
 }
 if ((item = (workq_ele_t *)malloc(sizeof(workq_ele_t))) == ((void *)0)) {
  return 12;
 }
 item->data = element;
 item->next = ((void *)0);
 if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
  free(item);
  return stat;
 }
 if (priority) {
  if (wq->first == ((void *)0)) {
   wq->first = item;
   wq->last = item;
  } else {
   item->next = wq->first;
   wq->first = item;
  }
 } else {
  if (wq->first == ((void *)0)) {
   wq->first = item;
  } else {
   wq->last->next = item;
  }
  wq->last = item;
 }
 if (wq->idle_workers > 0) {
  if ((stat = pthread_cond_broadcast(&wq->work)) != 0) {
   pthread_mutex_unlock(&wq->mutex);
   return stat;
  }
 }
 else if (wq->num_workers < wq->max_workers) {
  if ((stat = pthread_create(&id, &wq->attr, workq_server, (void *)wq)) != 0) {
   pthread_mutex_unlock(&wq->mutex);
   return stat;
  }
  wq->num_workers++;
 }
  pthread_mutex_unlock(&wq->mutex);
 if (work_item) {
  *work_item = item;
 }
 return stat;
}

canonical_original_code:
int workq_add(struct workq_tag *wq, void *element, struct workq_ele_tag **work_item, int priority)
{
 int stat;
 struct workq_ele_tag *item;
 unsigned long id;
 if (wq->valid != 0xdec2012) {
  return 22;
 }
 if ((item = (struct workq_ele_tag *)malloc(sizeof(workq_ele_t))) == ((void *)0)) {
  return 12;
 }
 item->data = element;
 item->next = ((void *)0);
 if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
  free(item);
  return stat;
 }
 if (priority) {
  if (wq->first == ((void *)0)) {
   wq->first = item;
   wq->last = item;
  } else {
   item->next = wq->first;
   wq->first = item;
  }
 } else {
  if (wq->first == ((void *)0)) {
   wq->first = item;
  } else {
   wq->last->next = item;
  }
  wq->last = item;
 }
 if (wq->idle_workers > 0) {
  if ((stat = pthread_cond_broadcast(&wq->work)) != 0) {
   pthread_mutex_unlock(&wq->mutex);
   return stat;
  }
 }
 else if (wq->num_workers < wq->max_workers) {
  if ((stat = pthread_create(&id, &wq->attr, workq_server, (void *)wq)) != 0) {
   pthread_mutex_unlock(&wq->mutex);
   return stat;
  }
  wq->num_workers++;
 }
  pthread_mutex_unlock(&wq->mutex);
 if (work_item) {
  *work_item = item;
 }
 return stat;
}

variable_types:
element
void *

variable_types: priority int

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

variable_types:
id
unsigned long


decompiled_code:
__int64 __fastcall workq_remove(void *arg, _QWORD *a2)
{
unsigned int v2; // er12
_QWORD *v4; // rcx
_QWORD *v5; // rax
_QWORD *v6; // rdx
unsigned int v7; // ebp
unsigned int v8; // ebp
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = 22;
if ( *((_DWORD *)arg + 40) == 233578514 )
{
v2 = pthread_mutex_lock((pthread_mutex_t *)arg);
if ( !v2 )
{
v4 = (_QWORD *)*((_QWORD *)arg + 18);
if ( !v4 )
return 22;
if ( v4 != a2 )
{
v5 = (_QWORD *)*((_QWORD *)arg + 18);
do
{
v6 = v5;
v5 = (_QWORD *)*v5;
if ( !v5 )
return 22;
}
while ( a2 != v5 );
if ( v4 != v5 )
{
*v6 = *v5;
if ( *((_QWORD **)arg + 19) == v5 )
*((_QWORD *)arg + 19) = v6;
*v5 = *((_QWORD *)arg + 18);
*((_QWORD *)arg + 18) = v5;
}
}
if ( *((int *)arg + 44) > 0 )
{
v7 = pthread_cond_broadcast((pthread_cond_t *)((char *)arg + 40));
if ( v7 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v7;
}
}
else if ( *((_DWORD *)arg + 43) < *((_DWORD *)arg + 42) )
{
v8 = pthread_create(newthread, (const pthread_attr_t *)((char *)arg + 88), workq_server, arg);
if ( v8 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v8;
}
++*((_DWORD *)arg + 43);
}
pthread_mutex_unlock((pthread_mutex_t *)arg);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *arg, _QWORD *a2)
{
unsigned int v2; // er12
_QWORD *v4; // rcx
_QWORD *v5; // rax
_QWORD *v6; // rdx
unsigned int v7; // ebp
unsigned int v8; // ebp
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = 22;
if ( *((_DWORD *)arg + 40) == 233578514 )
{
v2 = pthread_mutex_lock((pthread_mutex_t *)arg);
if ( !v2 )
{
v4 = (_QWORD *)*((_QWORD *)arg + 18);
if ( !v4 )
return 22;
if ( v4 != a2 )
{
v5 = (_QWORD *)*((_QWORD *)arg + 18);
do
{
v6 = v5;
v5 = (_QWORD *)*v5;
if ( !v5 )
return 22;
}
while ( a2 != v5 );
if ( v4 != v5 )
{
*v6 = *v5;
if ( *((_QWORD **)arg + 19) == v5 )
*((_QWORD *)arg + 19) = v6;
*v5 = *((_QWORD *)arg + 18);
*((_QWORD *)arg + 18) = v5;
}
}
if ( *((int *)arg + 44) > 0 )
{
v7 = pthread_cond_broadcast((pthread_cond_t *)((char *)arg + 40));
if ( v7 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v7;
}
}
else if ( *((_DWORD *)arg + 43) < *((_DWORD *)arg + 42) )
{
v8 = pthread_create(newthread, (const pthread_attr_t *)((char *)arg + 88), workq_server, arg);
if ( v8 )
{
pthread_mutex_unlock((pthread_mutex_t *)arg);
return v8;
}
++*((_DWORD *)arg + 43);
}
pthread_mutex_unlock((pthread_mutex_t *)arg);
}
}
return v2;
}

original_code:
int workq_remove(workq_t *wq, workq_ele_t *work_item)
{
 int stat, found = 0;
 pthread_t id;
 workq_ele_t *item, *prev;
 if (wq->valid != 0xdec2012) {
  return 22;
 }
 if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
  return stat;
 }
 for (prev=item=wq->first; item; item=item->next) {
  if (item == work_item) {
   found = 1;
   break;
  }
  prev = item;
 }
 if (!found) {
  return 22;
 }
 if (wq->first != work_item) {
  prev->next = work_item->next;
  if (wq->last == work_item) {
   wq->last = prev;
  }
  work_item->next = wq->first;
  wq->first = work_item;
 }
 if (wq->idle_workers > 0) {
  if ((stat = pthread_cond_broadcast(&wq->work)) != 0) {
   pthread_mutex_unlock(&wq->mutex);
   return stat;
  }
 }
 else if (wq->num_workers < wq->max_workers)
 {
  if ((stat = pthread_create(&id, &wq->attr, workq_server, (void *)wq)) != 0) {
   pthread_mutex_unlock(&wq->mutex);
   return stat;
  }
  wq->num_workers++;
 }
 pthread_mutex_unlock(&wq->mutex);
 return stat;
}

canonical_original_code:
int workq_remove(struct workq_tag *wq, struct workq_ele_tag *work_item)
{
 int stat; int found = 0;
 unsigned long id;
 struct workq_ele_tag *item; struct workq_ele_tag *prev;
 if (wq->valid != 0xdec2012) {
  return 22;
 }
 if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
  return stat;
 }
 for (prev=item=wq->first; item; item=item->next) {
  if (item == work_item) {
   found = 1;
   break;
  }
  prev = item;
 }
 if (!found) {
  return 22;
 }
 if (wq->first != work_item) {
  prev->next = work_item->next;
  if (wq->last == work_item) {
   wq->last = prev;
  }
  work_item->next = wq->first;
  wq->first = work_item;
 }
 if (wq->idle_workers > 0) {
  if ((stat = pthread_cond_broadcast(&wq->work)) != 0) {
   pthread_mutex_unlock(&wq->mutex);
   return stat;
  }
 }
 else if (wq->num_workers < wq->max_workers)
 {
  if ((stat = pthread_create(&id, &wq->attr, workq_server, (void *)wq)) != 0) {
   pthread_mutex_unlock(&wq->mutex);
   return stat;
  }
  wq->num_workers++;
 }
 pthread_mutex_unlock(&wq->mutex);
 return stat;
}

variable_types: found int


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

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

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

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

original_code:
DList * dlist_init(){
 DList *plist = (DList *)malloc(sizeof(DList));
 plist->head=((void *)0);
 plist->tail=((void *)0);
 plist->size=0;
 return plist;
}

canonical_original_code:
struct DList *dlist_init(){
 struct DList *plist = (DList *)malloc(sizeof(DList));
 plist->head=((void *)0);
 plist->tail=((void *)0);
 plist->size=0;
 return plist;
}

variable_types: struct DList { struct node_t { void *data; struct node_t *prev; struct node_t *next; } *head; struct node_t *tail; int size; } *

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


decompiled_code:
void __fastcall dlist_destory(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *(_QWORD *)ptr;
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 16);
free(*v2);
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *(_QWORD *)ptr;
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 16);
free(*v2);
free(v2);
}
free(ptr);
}

original_code:
void dlist_destory(DList * plist){
 PNode p=((void *)0);
 PNode q=plist->head;
 while(q){
  p=q->next;
  free(q->data);
  free(q);
  q=p;
 }
 free(plist);
}

canonical_original_code:
void dlist_destory(struct DList *plist){
 struct node_t *p = ((void *)0);
 struct node_t *q = plist->head;
 while(q){
  p=q->next;
  free(q->data);
  free(q);
  q=p;
 }
 free(plist);
}

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


decompiled_code:
__int64 __fastcall dlist_search(__int64 *a1, _DWORD *a2)
{
__int64 i; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
**(_DWORD **)i = *a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, _DWORD *a2)
{
__int64 i; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
**(_DWORD **)i = *a2;
return 0LL;
}

original_code:
int dlist_search(DList * plist,ItemType item){
 PNode p=plist->head;
 while(p){
  if(memcpy(p->data,item,4)==0){
   if(plist->head==p)
    return 1;
   if(p->prev)
    p->prev->next=p->next;
   else
    plist->head=p->next;
   if(p->next)
    p->next->prev=p->prev;
   else
    plist->tail=p->prev;
   break;
  }
  p=p->next;
 }
 if(p)
  return 1;
 else
  return 0;
}

canonical_original_code:
int dlist_search(struct DList *plist, void *item){
 struct node_t *p = plist->head;
 while(p){
  if(memcpy(p->data,item,4)==0){
   if(plist->head==p)
    return 1;
   if(p->prev)
    p->prev->next=p->next;
   else
    plist->head=p->next;
   if(p->next)
    p->next->prev=p->prev;
   else
    plist->tail=p->prev;
   break;
  }
  p=p->next;
 }
 if(p)
  return 1;
 else
  return 0;
}

variable_types:
item
void *

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


decompiled_code:
__int64 __fastcall dlist_move_value(__int64 *a1, const void *a2, int a3)
{
__int64 v3; // rbx
size_t v4; // rbp

v3 = *a1;
if ( *a1 )
{
v4 = a3;
do
{
memcpy(*(void **)v3, a2, v4);
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, const void *a2, int a3)
{
__int64 v3; // rbx
size_t v4; // rbp

v3 = *a1;
if ( *a1 )
{
v4 = a3;
do
{
memcpy(*(void **)v3, a2, v4);
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
}
return 0LL;
}

original_code:
int dlist_move_value(DList * plist,ItemType item,int size){
 PNode p=plist->head;
 while(p){
  if(memcpy(p->data,item,size)==0){
   if(plist->head==p)
    return 1;
   if(p->prev)
    p->prev->next=p->next;
   else
    plist->head=p->next;
   if(p->next)
    p->next->prev=p->prev;
   else
    plist->tail=p->prev;
   break;
  }
  p=p->next;
 }
 if(p){
  p->next=p->prev=((void *)0);
  if(plist->head==((void *)0)){
   plist->tail=p;
  }
  else{
   plist->head->prev=p;
   p->next=plist->head;
  }
  plist->head=p;
  return 1;
 }
 return 0;
}

canonical_original_code:
int dlist_move_value(struct DList *plist, void *item, int size){
 struct node_t *p = plist->head;
 while(p){
  if(memcpy(p->data,item,size)==0){
   if(plist->head==p)
    return 1;
   if(p->prev)
    p->prev->next=p->next;
   else
    plist->head=p->next;
   if(p->next)
    p->next->prev=p->prev;
   else
    plist->tail=p->prev;
   break;
  }
  p=p->next;
 }
 if(p){
  p->next=p->prev=((void *)0);
  if(plist->head==((void *)0)){
   plist->tail=p;
  }
  else{
   plist->head->prev=p;
   p->next=plist->head;
  }
  plist->head=p;
  return 1;
 }
 return 0;
}

variable_types: size int


original_code:
ItemType dlist_delete_tail(DList * plist){
 ItemType data;
 PNode p;
 if(plist->head==((void *)0))
  return ((void *)0);
 if(plist->tail->prev){
  plist->tail->prev->next=((void *)0);
  data=plist->tail->data;
  p=plist->tail;
  plist->tail=p->prev;
  free(p);
 }
 else{
  data=plist->tail->data;
  free(plist->tail);
  plist->head=((void *)0);
  plist->tail=((void *)0);
 }
 plist->size--;
 return data;
}

canonical_original_code:
void *dlist_delete_tail(struct DList *plist){
 void *data;
 struct node_t *p;
 if(plist->head==((void *)0))
  return ((void *)0);
 if(plist->tail->prev){
  plist->tail->prev->next=((void *)0);
  data=plist->tail->data;
  p=plist->tail;
  plist->tail=p->prev;
  free(p);
 }
 else{
  data=plist->tail->data;
  free(plist->tail);
  plist->head=((void *)0);
  plist->tail=((void *)0);
 }
 plist->size--;
 return data;
}

variable_types:
data
void *


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

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

original_code:
int dlist_size(DList *plist){
 return plist->size;
}

canonical_original_code:
int dlist_size(struct DList *plist){
 return plist->size;
}


decompiled_code:
int __fastcall dlist_traver(unsigned int ***a1)
{
unsigned int **v1; // rbx

v1 = *a1;
printf("list item :");
for ( ; v1; v1 = (unsigned int **)v1[2] )
printf("%d ", **v1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int ***a1)
{
unsigned int **v1; // rbx

v1 = *a1;
printf("list item :");
for ( ; v1; v1 = (unsigned int **)v1[2] )
printf("%d ", **v1);
return putchar(10);
}

original_code:
void dlist_traver(DList *plist){
 PNode p=plist->head;
 printf("list item :");
 while(p){
  printf("%d  ",*(int *)p->data);
  p=p->next;
 }
 printf("\n");
}

canonical_original_code:
void dlist_traver(struct DList *plist){
 struct node_t *p = plist->head;
 printf("list item :");
 while(p){
  printf("%d  ",*(int *)p->data);
  p=p->next;
 }
 printf("\n");
}


decompiled_code:
__int64 __fastcall hash_g(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return *a1;
}

original_code:
unsigned int hash_g(char *str){
 return *(uint32_t*)str;
}

canonical_original_code:
unsigned int hash_g(char *str){
 return *(unsigned int *)str;
}

variable_types:
str
char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall hash_f1(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

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

original_code:
unsigned int hash_f1(char *str){
 return *(uint32_t*)(str+8);
}

canonical_original_code:
unsigned int hash_f1(char *str){
 return *(unsigned int *)(str+8);
}


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

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

original_code:
unsigned int hash_f2(char *str){
 return *(uint32_t*)(str+16);
}

canonical_original_code:
unsigned int hash_f2(char *str){
 return *(unsigned int *)(str+16);
}


decompiled_code:
__int64 __fastcall judge_bit(__int64 a1, unsigned int a2)
{
return ((int)*(unsigned __int8 *)(a1 + (a2 >> 3)) >> (a2 & 7)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
return ((int)*(unsigned __int8 *)(a1 + (a2 >> 3)) >> (a2 & 7)) & 1;
}

original_code:
int judge_bit(uint8_t * array,uint32_t bit_number){
 if( array[bit_number/8] & (1<<(bit_number%8)))
  return 1;
 return 0;
}

canonical_original_code:
int judge_bit(unsigned char *array, unsigned int bit_number){
 if( array[bit_number/8] & (1<<(bit_number%8)))
  return 1;
 return 0;
}

variable_types:
array
unsigned char *


original_code:
int quick_adjust(Bucket * A, int64_t first,int64_t last){
 int64_t i=first,j=last;
 Bucket x;
 memcpy(&x,&A[i],sizeof(x));
 while(i<j){
  while(i<j && (A[j].size<=x.size))
   j--;
  if(i<j)
   memcpy(&A[i++],&A[j],sizeof(x));
  while(i<j && (A[i].size>=x.size))
   i++;
  if(i<j)
   memcpy(&A[j--],&A[i],sizeof(x));
 }
 memcpy(&A[i],&x,sizeof(x));
 return i;
}

canonical_original_code:
int quick_adjust(struct Bucket *A, long first, long last){
 long i = first; long j = last;
 struct Bucket x;
 memcpy(&x,&A[i],sizeof(x));
 while(i<j){
  while(i<j && (A[j].size<=x.size))
   j--;
  if(i<j)
   memcpy(&A[i++],&A[j],sizeof(x));
  while(i<j && (A[i].size>=x.size))
   i++;
  if(i<j)
   memcpy(&A[j--],&A[i],sizeof(x));
 }
 memcpy(&A[i],&x,sizeof(x));
 return i;
}

variable_types: struct Bucket { int index; int size; struct FP { unsigned char hash[21]; struct FP *next; } *data; } *

variable_types: first long

variable_types: last long

variable_types: i long

variable_types: j long

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


decompiled_code:
void __fastcall quick_sort(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp

if ( a2 < a3 )
{
v4 = (int)quick_adjust(a1, a2, a3);
quick_sort(a1, a2, v4 - 1);
quick_sort(a1, v4 + 1, a3);
}
}

original_code:
void quick_sort(Bucket *A, int64_t first, int64_t last){
 int64_t mid;
 if(first<last){
  mid=quick_adjust(A,first,last);
  quick_sort(A,first,mid-1);
  quick_sort(A,mid+1,last);
 }
}

canonical_original_code:
void quick_sort(struct Bucket *A, long first, long last){
 long mid;
 if(first<last){
  mid=quick_adjust(A,first,last);
  quick_sort(A,first,mid-1);
  quick_sort(A,mid+1,last);
 }
}

variable_types: mid long

user_defined_types: struct FP { unsigned char hash[21]; struct FP *next; }


decompiled_code:
void __fastcall phf_destory(void *ptr)
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}

original_code:
void phf_destory(PHF * phf){
 free(phf->D);
 free(phf->T);
 free(phf);
}

canonical_original_code:
void phf_destory(struct PHF *phf){
 free(phf->D);
 free(phf->T);
 free(phf);
}

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

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


original_code:
void phf_walk(PHF * phf){
 int i;
 uint32_t count=0;
 printf("phf walk========================\n");
    for(i=0;i<phf->bucket_num;i++){
  if(phf->B[i].size)
   count++;
 }
 printf("\n =====%u / %ld =====n",count,phf->bucket_num);
}

canonical_original_code:
void phf_walk(struct PHF *phf){
 int i;
 unsigned int count = 0;
 printf("phf walk========================\n");
    for(i=0;i<phf->bucket_num;i++){
  if(phf->B[i].size)
   count++;
 }
 printf("\n =====%u / %ld =====n",count,phf->bucket_num);
}

variable_types: i int

variable_types:
count
unsigned int


original_code:
int phf_input(PHF * phf, Fingerprint fp){
 BucketData * bdata=(BucketData *)malloc(sizeof(BucketData));
 bdata->next=((void *)0);
 memcpy(bdata->hash,fp,20);
 bdata->hash[20]=0;
 int64_t r;
 r=phf->g_hash(bdata->hash)% (phf->bucket_num);
 bdata->next=phf->B[r].data;
 phf->B[r].data=bdata;
 phf->B[r].size++;
}

canonical_original_code:
int phf_input(struct PHF *phf, unsigned char fp[20]){
 struct FP *bdata = (BucketData *)malloc(sizeof(BucketData));
 bdata->next=((void *)0);
 memcpy(bdata->hash,fp,20);
 bdata->hash[20]=0;
 long r;
 r=phf->g_hash(bdata->hash)% (phf->bucket_num);
 bdata->next=phf->B[r].data;
 phf->B[r].data=bdata;
 phf->B[r].size++;
}

variable_types:
fp
unsigned char [20]

variable_types: struct FP { unsigned char hash[21]; struct FP *next; } *

variable_types: r long


original_code:
void phf_build(PHF * phf){
 uint32_t r=0;
 int32_t f_index=0;
 uint32_t * K=((void *)0);
 int ki=0;
 uint32_t f_p=0;
 int i=0;
 BucketData * bd=((void *)0);
 BucketData * next=((void *)0);
 int max_match_num=0;
 printf("sort:%ld \n",(phf->bucket_num-1));
 quick_sort(phf->B,0,(phf->bucket_num-1));
 if(phf->B[0].size<=0){
  err_msg("phf.c",140,"no itmes");
  return;
 }
 K=(uint32_t *)malloc(phf->B[0].size*4);
 for(r=0;r<phf->bucket_num;r++){
  ki=0;
  f_index=0;
  if(phf->B[r].size>0){
   bd=phf->B[r].data;
   while(bd && f_index<compare_num){
    f_p=(phf->f1_hash(bd->hash)+ phf->f2_hash(bd->hash)*(f_index/base_num)+f_index %base_num) % phf->vector_num;
    if(judge_bit(phf->T,f_p)==0){
     bd=bd->next;
     K[ki++]=f_p;
    }
    else{
     ki=0;
     bd=phf->B[r].data;
     f_index++;
    }
   }
   if(f_index==compare_num|| phf->B[r].size !=ki)
    err_msg("phf.c",163,"may be wrong");
   if(max_match_num<f_index)
    max_match_num=f_index;
   phf->D[phf->B[r].index]=f_index;
   for(i=0;i<ki;i++){
    set_bit(phf->T,K[i]);
   }
   bd=phf->B[r].data;
   while(bd){
    next=bd->next;
    free(bd);
    bd=next;
   }
  }
 }
 printf("max number of itmes in buckets is:%d\n",max_match_num);
 int64_t vector_size=(phf->vector_num>>3)+1;
 memset(phf->T,0,vector_size);
 free(K);
 free(phf->B);
}

canonical_original_code:
void phf_build(struct PHF *phf){
 unsigned int r = 0;
 int f_index = 0;
 unsigned int *K = ((void *)0);
 int ki = 0;
 unsigned int f_p = 0;
 int i = 0;
 struct FP *bd = ((void *)0);
 struct FP *next = ((void *)0);
 int max_match_num = 0;
 printf("sort:%ld \n",(phf->bucket_num-1));
 quick_sort(phf->B,0,(phf->bucket_num-1));
 if(phf->B[0].size<=0){
  err_msg("phf.c",140,"no itmes");
  return;
 }
 K=(unsigned int *)malloc(phf->B[0].size*4);
 for(r=0;r<phf->bucket_num;r++){
  ki=0;
  f_index=0;
  if(phf->B[r].size>0){
   bd=phf->B[r].data;
   while(bd && f_index<compare_num){
    f_p=(phf->f1_hash(bd->hash)+ phf->f2_hash(bd->hash)*(f_index/base_num)+f_index %base_num) % phf->vector_num;
    if(judge_bit(phf->T,f_p)==0){
     bd=bd->next;
     K[ki++]=f_p;
    }
    else{
     ki=0;
     bd=phf->B[r].data;
     f_index++;
    }
   }
   if(f_index==compare_num|| phf->B[r].size !=ki)
    err_msg("phf.c",163,"may be wrong");
   if(max_match_num<f_index)
    max_match_num=f_index;
   phf->D[phf->B[r].index]=f_index;
   for(i=0;i<ki;i++){
    set_bit(phf->T,K[i]);
   }
   bd=phf->B[r].data;
   while(bd){
    next=bd->next;
    free(bd);
    bd=next;
   }
  }
 }
 printf("max number of itmes in buckets is:%d\n",max_match_num);
 long vector_size = (phf->vector_num>>3)+1;
 memset(phf->T,0,vector_size);
 free(K);
 free(phf->B);
}

variable_types:
r
unsigned int

variable_types:
K
unsigned int *

variable_types: ki int


original_code:
int phf_search(PHF *phf,Fingerprint fp){
 uint32_t g_index;
 uint32_t vec_index;
 uint8_t str[21];
 memcpy(str,fp,20);
 str[20]=0;
 g_index=phf->g_hash(str)%(phf->bucket_num);
 vec_index=(phf->f1_hash(str)+ phf->f2_hash(str)*(phf->D[g_index] /base_num)+phf->D[g_index] %base_num) % phf->vector_num;
 if(judge_bit(phf->T,vec_index))
  return 1;
 return 0;
}

canonical_original_code:
int phf_search(struct PHF *phf, unsigned char fp[20]){
 unsigned int g_index;
 unsigned int vec_index;
 unsigned char str[21];
 memcpy(str,fp,20);
 str[20]=0;
 g_index=phf->g_hash(str)%(phf->bucket_num);
 vec_index=(phf->f1_hash(str)+ phf->f2_hash(str)*(phf->D[g_index] /base_num)+phf->D[g_index] %base_num) % phf->vector_num;
 if(judge_bit(phf->T,vec_index))
  return 1;
 return 0;
}

variable_types:
str
unsigned char [21]


decompiled_code:
unsigned int *__fastcall cache_init(int a1)
{
unsigned int *v1; // rbx

v1 = (unsigned int *)malloc(0x20uLL);
if ( !v1 )
err_msg("storage/container_cache.c", 7LL, "malloc worng");
v1[1] = 0;
*v1 = a1 / 60;
v1[2] = 0;
*((_QWORD *)v1 + 3) = dlist_init();
*((_QWORD *)v1 + 2) = 0LL;
*((_QWORD *)v1 + 2) = htable_init(32LL, 20LL, *v1);
return v1;
}

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

v1 = (unsigned int *)malloc(0x20uLL);
if ( !v1 )
err_msg("storage/container_cache.c", 7LL, "malloc worng");
v1[1] = 0;
*v1 = a1 / 60;
v1[2] = 0;
*((_QWORD *)v1 + 3) = dlist_init();
*((_QWORD *)v1 + 2) = 0LL;
*((_QWORD *)v1 + 2) = htable_init(32LL, 20LL, *v1);
return v1;
}

original_code:
Cache * cache_init(int cache_size){
 Cache *cache=((void *)0);
     cache=(Cache *)malloc(sizeof(Cache));
 if(!cache)
  err_msg("storage/container_cache.c",7,"malloc worng");
 cache->hit=0;
 cache->item_count=cache_size/60;
 cache->miss=0;
 cache->plist=dlist_init();
 ChunkAddr ca;
 cache->htable=((void *)0);
 cache->htable=htable_init((char*)&ca.next-(char*)&ca,20,cache->item_count);
 return cache;
}

canonical_original_code:
struct lru_cache *cache_init(int cache_size){
 struct lru_cache *cache = ((void *)0);
     cache=(struct lru_cache *)malloc(sizeof(Cache));
 if(!cache)
  err_msg("storage/container_cache.c",7,"malloc worng");
 cache->hit=0;
 cache->item_count=cache_size/60;
 cache->miss=0;
 cache->plist=dlist_init();
 struct chunk_address ca;
 cache->htable=((void *)0);
 cache->htable=htable_init((char *)&ca.next-(char *)&ca,20,cache->item_count);
 return cache;
}

variable_types: struct lru_cache { int item_count; int hit; int miss; 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; } *htable; struct DList { struct node_t { void *data; struct node_t *prev; struct node_t *next; } *head; struct node_t *tail; int size; } *plist; } *

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

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

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

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


decompiled_code:
__int64 __fastcall cache_remove(__int64 a1, __int64 a2)
{
__int64 result; // rax

for ( result = htable_get_first(*(_QWORD *)(a2 + 16)); result; result = htable_get_next(*(_QWORD *)(a2 + 16)) )
htable_remove(*(_QWORD *)(a1 + 16), result + 12);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax

for ( result = htable_get_first(*(_QWORD *)(a2 + 16)); result; result = htable_get_next(*(_QWORD *)(a2 + 16)) )
htable_remove(*(_QWORD *)(a1 + 16), result + 12);
return result;
}

original_code:
void cache_remove(Cache * cache,Container * ca){
 ChunkAddr *cadr=((void *)0);
 for((*((void **)&(cadr))=(void *)(htable_get_first((ca->meta_table)))); (cadr); (*((void **)&(cadr))=(void *)(htable_get_next(ca->meta_table)))){
  htable_remove(cache->htable,cadr->hash);
 }
}

canonical_original_code:
void cache_remove(struct lru_cache *cache, struct container_tag *ca){
 struct chunk_address *cadr = ((void *)0);
 for((*((void **)&(cadr))=(void *)(htable_get_first((ca->meta_table)))); (cadr); (*((void **)&(cadr))=(void *)(htable_get_next(ca->meta_table)))){
  htable_remove(cache->htable,cadr->hash);
 }
}

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 cache_insert(__int64 a1, __int64 a2)
{
unsigned int *i; // rax
__int64 v3; // rax
int *v5; // r12
__int64 v6; // r13

if ( *(_DWORD *)(*(_QWORD *)(a1 + 16) + 16LL) >= *(_DWORD *)a1 )
{
dlist_traver(*(_QWORD *)(a1 + 24));
v5 = (int *)dlist_delete_tail(*(_QWORD *)(a1 + 24));
if ( *v5 > 0 )
{
v6 = read_container();
if ( !v6 )
err_msg("storage/container_cache.c", 38LL, "wrong read container in cache");
cache_remove(a1, v6);
container_destroy(v6);
}
free(v5);
}
for ( i = (unsigned int *)htable_get_first(*(_QWORD *)(a2 + 16));
i;
i = (unsigned int *)htable_get_next(*(_QWORD *)(a2 + 16)) )
{
v3 = chunkaddr_new(i + 3, *i, i[1]);
*(_DWORD *)(v3 + 8) = *(_DWORD *)a2;
htable_insert(*(_QWORD *)(a1 + 16), v3 + 12);
}
*(_DWORD *)malloc(4uLL) = *(_DWORD *)a2;
dlist_insert(*(_QWORD *)(a1 + 24));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int *i; // rax
__int64 v3; // rax
int *v5; // r12
__int64 v6; // r13

if ( *(_DWORD *)(*(_QWORD *)(a1 + 16) + 16LL) >= *(_DWORD *)a1 )
{
dlist_traver(*(_QWORD *)(a1 + 24));
v5 = (int *)dlist_delete_tail(*(_QWORD *)(a1 + 24));
if ( *v5 > 0 )
{
v6 = read_container();
if ( !v6 )
err_msg("storage/container_cache.c", 38LL, "wrong read container in cache");
func1(a1, v6);
container_destroy(v6);
}
free(v5);
}
for ( i = (unsigned int *)htable_get_first(*(_QWORD *)(a2 + 16));
i;
i = (unsigned int *)htable_get_next(*(_QWORD *)(a2 + 16)) )
{
v3 = chunkaddr_new(i + 3, *i, i[1]);
*(_DWORD *)(v3 + 8) = *(_DWORD *)a2;
htable_insert(*(_QWORD *)(a1 + 16), v3 + 12);
}
*(_DWORD *)malloc(4uLL) = *(_DWORD *)a2;
dlist_insert(*(_QWORD *)(a1 + 24));
return 1LL;
}

original_code:
int cache_insert(Cache *cache,Container * ca){
 Container * evitor_ca=((void *)0);
 ChunkAddr *cadr=((void *)0);
 ChunkAddr *newcadr=((void *)0);
 int *evitor_ca_id=0;
 if(cache->htable->num_items>=cache->item_count){
  dlist_traver(cache->plist);
  evitor_ca_id=(int*)dlist_delete_tail(cache->plist);
  if(*evitor_ca_id>0){
   evitor_ca=read_container(*evitor_ca_id);
   if(evitor_ca==((void *)0))
    err_msg("storage/container_cache.c",38,"wrong read container in cache");
   cache_remove(cache,evitor_ca);
   container_destroy(evitor_ca);
  }
  free(evitor_ca_id);
 }
 for((*((void **)&(cadr))=(void *)(htable_get_first((ca->meta_table)))); (cadr); (*((void **)&(cadr))=(void *)(htable_get_next(ca->meta_table)))){
  newcadr=chunkaddr_new(cadr->hash,cadr->offset,cadr->length);
  newcadr->container_id=ca->container_id;
  htable_insert(cache->htable,newcadr->hash,newcadr);
 }
 int *id=(int *)malloc(sizeof(int));
 *id=ca->container_id;
 dlist_insert(cache->plist,id);
  return 1;
}

canonical_original_code:
int cache_insert(struct lru_cache *cache, struct container_tag *ca){
 struct container_tag *evitor_ca = ((void *)0);
 struct chunk_address *cadr = ((void *)0);
 struct chunk_address *newcadr = ((void *)0);
 int *evitor_ca_id = 0;
 if(cache->htable->num_items>=cache->item_count){
  dlist_traver(cache->plist);
  evitor_ca_id=(int *)dlist_delete_tail(cache->plist);
  if(*evitor_ca_id>0){
   evitor_ca=read_container(*evitor_ca_id);
   if(evitor_ca==((void *)0))
    err_msg("storage/container_cache.c",38,"wrong read container in cache");
   cache_remove(cache,evitor_ca);
   container_destroy(evitor_ca);
  }
  free(evitor_ca_id);
 }
 for((*((void **)&(cadr))=(void *)(htable_get_first((ca->meta_table)))); (cadr); (*((void **)&(cadr))=(void *)(htable_get_next(ca->meta_table)))){
  newcadr=chunkaddr_new(cadr->hash,cadr->offset,cadr->length);
  newcadr->container_id=ca->container_id;
  htable_insert(cache->htable,newcadr->hash,newcadr);
 }
 int *id = (int *)malloc(sizeof(int));
 *id=ca->container_id;
 dlist_insert(cache->plist,id);
  return 1;
}

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

variable_types:
id
int *

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:
__int64 __fastcall cache_search(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

v1 = htable_lookup(*(_QWORD *)(a1 + 16));
v2 = v1;
if ( v1 )
{
++*(_DWORD *)(a1 + 4);
dlist_move_value(*(_QWORD *)(a1 + 24), v1 + 8, 4LL);
}
else
{
++*(_DWORD *)(a1 + 8);
}
return v2;
}

original_code:
void * cache_search(Cache*cache,unsigned char *key){
 void * res=htable_lookup(cache->htable, key);
 if(res){
  cache->hit++;
  dlist_move_value(cache->plist,&(((ChunkAddr*)res)->container_id), sizeof(int));
 }
 else
  cache->miss++;
 return res;
}

canonical_original_code:
void *cache_search(struct lru_cache *cache, unsigned char *key){
 void *res = htable_lookup(cache->htable, key);
 if(res){
  cache->hit++;
  dlist_move_value(cache->plist,&(((struct chunk_address *)res)->container_id), sizeof(int));
 }
 else
  cache->miss++;
 return res;
}

variable_types:
key
unsigned char *

variable_types:
res
void *

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


decompiled_code:
int __fastcall cache_statistics(unsigned int *a1)
{
puts("\n============cache statistics=============");
printf("container count included:%d \n", *(unsigned int *)(*((_QWORD *)a1 + 3) + 16LL));
printf("current items in cache:%d \n", *(unsigned int *)(*((_QWORD *)a1 + 2) + 16LL));
printf("max items in cache: %d \n", *a1);
printf("search cache counts:%d\n", a1[1] + a1[2]);
printf("hits: %d \n", a1[1]);
printf("miss: %d \n", a1[2]);
return puts("============cache statistics=============\n");
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1)
{
puts("\n============cache statistics=============");
printf("container count included:%d \n", *(unsigned int *)(*((_QWORD *)a1 + 3) + 16LL));
printf("current items in cache:%d \n", *(unsigned int *)(*((_QWORD *)a1 + 2) + 16LL));
printf("max items in cache: %d \n", *a1);
printf("search cache counts:%d\n", a1[1] + a1[2]);
printf("hits: %d \n", a1[1]);
printf("miss: %d \n", a1[2]);
return puts("============cache statistics=============\n");
}

original_code:
void cache_statistics(Cache * cache){
 printf("\n============cache statistics=============\n");
 printf("container count included:%d \n",cache->plist->size);
 printf("current items in cache:%d \n",cache->htable->num_items);
 printf("max items in cache:   %d \n",cache->item_count);
 printf("search cache counts:%d\n",(cache->hit+cache->miss));
 printf("hits: %d \n",cache->hit);
 printf("miss: %d \n",cache->miss);
 printf("============cache statistics=============\n\n");
}

canonical_original_code:
void cache_statistics(struct lru_cache *cache){
 printf("\n============cache statistics=============\n");
 printf("container count included:%d \n",cache->plist->size);
 printf("current items in cache:%d \n",cache->htable->num_items);
 printf("max items in cache:   %d \n",cache->item_count);
 printf("search cache counts:%d\n",(cache->hit+cache->miss));
 printf("hits: %d \n",cache->hit);
 printf("miss: %d \n",cache->miss);
 printf("============cache statistics=============\n\n");
}


decompiled_code:
void __fastcall cache_destroy(void *ptr)
{
cache_statistics((unsigned int *)ptr);
dlist_destory(*((_QWORD *)ptr + 3));
if ( *((_QWORD *)ptr + 2) )
htable_destroy();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
func4((unsigned int *)ptr);
dlist_destory(*((_QWORD *)ptr + 3));
if ( *((_QWORD *)ptr + 2) )
htable_destroy();
free(ptr);
}

original_code:
void cache_destroy(Cache * cache){
  cache_statistics(cache);
  dlist_destory(cache->plist);
  if(cache->htable)
   htable_destroy(cache->htable);
  free(cache);
}

canonical_original_code:
void cache_destroy(struct lru_cache *cache){
  cache_statistics(cache);
  dlist_destory(cache->plist);
  if(cache->htable)
   htable_destroy(cache->htable);
  free(cache);
}


original_code:
int cache_insert_r(Cache *cache,Container * ca){
 Container * evitor_ca=((void *)0);
 ChunkAddr *cadr=((void *)0);
 ChunkAddrRes *newcadr=((void *)0);
 if(cache->plist->size>=cache->item_count){
  evitor_ca=(Container*)dlist_delete_tail(cache->plist);
  if(evitor_ca){
   cache_remove(cache,evitor_ca);
   container_destroy(evitor_ca);
  }
 }
 for((*((void **)&(cadr))=(void *)(htable_get_first((ca->meta_table)))); (cadr); (*((void **)&(cadr))=(void *)(htable_get_next(ca->meta_table)))){
  newcadr=(ChunkAddrRes*)malloc(sizeof(ChunkAddrRes));
  newcadr->length=cadr->length;
  newcadr->offset=cadr->offset;
  newcadr->container=ca;
  memcpy(newcadr->hash,cadr->hash,sizeof(Fingerprint));
  htable_insert(cache->htable,newcadr->hash,newcadr);
 }
 dlist_insert(cache->plist,ca);
  return 1;
}

canonical_original_code:
int cache_insert_r(struct lru_cache *cache, struct container_tag *ca){
 struct container_tag *evitor_ca = ((void *)0);
 struct chunk_address *cadr = ((void *)0);
 struct chunk_address_restore *newcadr = ((void *)0);
 if(cache->plist->size>=cache->item_count){
  evitor_ca=(struct container_tag *)dlist_delete_tail(cache->plist);
  if(evitor_ca){
   cache_remove(cache,evitor_ca);
   container_destroy(evitor_ca);
  }
 }
 for((*((void **)&(cadr))=(void *)(htable_get_first((ca->meta_table)))); (cadr); (*((void **)&(cadr))=(void *)(htable_get_next(ca->meta_table)))){
  newcadr=(struct chunk_address_restore *)malloc(sizeof(ChunkAddrRes));
  newcadr->length=cadr->length;
  newcadr->offset=cadr->offset;
  newcadr->container=ca;
  memcpy(newcadr->hash,cadr->hash,sizeof(Fingerprint));
  htable_insert(cache->htable,newcadr->hash,newcadr);
 }
 dlist_insert(cache->plist,ca);
  return 1;
}

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

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


original_code:
void * cache_search_r(Cache*cache,unsigned char *key){
 ChunkAddrRes* res=(ChunkAddrRes*)htable_lookup(cache->htable, key);
 if(res){
  cache->hit++;
  dlist_move_ptr(cache->plist,res->container);
 }
 else
  cache->miss++;
 return res;
}

canonical_original_code:
void *cache_search_r(struct lru_cache *cache, unsigned char *key){
 struct chunk_address_restore *res = (ChunkAddrRes*)htable_lookup(cache->htable, key);
 if(res){
  cache->hit++;
  dlist_move_ptr(cache->plist,res->container);
 }
 else
  cache->miss++;
 return res;
}


decompiled_code:
__int64 jobcount_init()
{
size_t v0; // rax
int v1; // eax
int v2; // ebx
__int64 result; // rax

strcpy(job_count_file, &BackupVolPath);
v0 = strlen(job_count_file);
*(_QWORD *)&job_count_file[v0] = 0x6E756F635F626F6ALL;
*(__int16 *)((char *)&word_B88 + v0) = 116;
v1 = open(job_count_file, 66, 420LL);
if ( v1 <= 0 )
{
puts("Can not open job_count_file");
result = 0LL;
}
else
{
v2 = v1;
if ( read(v1, &g_job_count, 4uLL) == 4 )
{
printf("%s,%d total job counts:%d\n", "job/job.c", 29LL, (unsigned int)g_job_count);
}
else
{
g_job_count = 0;
lseek(v2, 0LL, 0);
write(v2, &g_job_count, 4uLL);
}
close(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
size_t v0; // rax
int v1; // eax
int v2; // ebx
__int64 result; // rax

strcpy(job_count_file, &BackupVolPath);
v0 = strlen(job_count_file);
*(_QWORD *)&job_count_file[v0] = 0x6E756F635F626F6ALL;
*(__int16 *)((char *)&word_B88 + v0) = 116;
v1 = open(job_count_file, 66, 420LL);
if ( v1 <= 0 )
{
puts("Can not open job_count_file");
result = 0LL;
}
else
{
v2 = v1;
if ( read(v1, &g_job_count, 4uLL) == 4 )
{
printf("%s,%d total job counts:%d\n", "job/job.c", 29LL, (unsigned int)g_job_count);
}
else
{
g_job_count = 0;
lseek(v2, 0LL, 0);
write(v2, &g_job_count, 4uLL);
}
close(v2);
result = 1LL;
}
return result;
}

original_code:
int jobcount_init() {
 strcpy(job_count_file,BackupVolPath);
 strcat(job_count_file,"job_count");
  int fd;
   if ((fd = open(job_count_file, 0100 | 02, 0644)) <= 0) {
         printf("Can not open job_count_file\n");
         return 0;
  }
    if (read(fd, &g_job_count, 4) == 4) {
       printf("%s,%d total job counts:%d\n","job/job.c",29,g_job_count);
    } else {
        g_job_count = 0;
        lseek(fd, 0, 0);
        write(fd, &g_job_count, 4);
    }
    close(fd);
    return 1;
}

variable_types: fd int


decompiled_code:
__int64 jobcount_close()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax

v0 = open(job_count_file, 2);
if ( v0 <= 0 )
{
puts("Can not write job_count_file");
result = 0LL;
}
else
{
v1 = v0;
write(v0, &g_job_count, 4uLL);
close(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax

v0 = open(job_count_file, 2);
if ( v0 <= 0 )
{
puts("Can not write job_count_file");
result = 0LL;
}
else
{
v1 = v0;
write(v0, &g_job_count, 4uLL);
close(v1);
result = 1LL;
}
return result;
}

original_code:
int jobcount_close(){
    int fd;
    if ((fd = open(job_count_file, 02)) <= 0) {
        printf("Can not write job_count_file\n");
        return 0;
    }
    write(fd, &g_job_count, 4);
    close(fd);
    return 1;
}


decompiled_code:
__int64 jobcount_max()
{
return (unsigned int)g_job_count;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)g_job_count;
}

original_code:
int jobcount_max(){
 return g_job_count;
}


original_code:
JOB_V* jobv_init(){
 JOB_V *jv=(JOB_V*)malloc(sizeof(JOB_V));
 jv->fd=-1;
 jv->isDel=0;
 jv->nFileNum=0;
 jv->nJobId=0;
 memset(jv->szBackupPath,0, 256);
 return jv;
}

canonical_original_code:
struct job_des *jobv_init(){
 struct job_des *jv = (JOB_V*)malloc(sizeof(JOB_V));
 jv->fd=-1;
 jv->isDel=0;
 jv->nFileNum=0;
 jv->nJobId=0;
 memset(jv->szBackupPath,0, 256);
 return jv;
}

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


decompiled_code:
__int64 __fastcall jobv_write_head(void *buf)
{
lseek(*((_DWORD *)buf + 67), 0LL, 0);
write(*((_DWORD *)buf + 67), buf, 4uLL);
write(*((_DWORD *)buf + 67), (char *)buf + 4, 4uLL);
write(*((_DWORD *)buf + 67), (char *)buf + 8, 0x100uLL);
write(*((_DWORD *)buf + 67), (char *)buf + 264, 4uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *buf)
{
lseek(*((_DWORD *)buf + 67), 0LL, 0);
write(*((_DWORD *)buf + 67), buf, 4uLL);
write(*((_DWORD *)buf + 67), (char *)buf + 4, 4uLL);
write(*((_DWORD *)buf + 67), (char *)buf + 8, 0x100uLL);
write(*((_DWORD *)buf + 67), (char *)buf + 264, 4uLL);
return 1LL;
}

original_code:
int jobv_write_head(JOB_V* jv) {
    lseek(jv->fd, 0, 0);
    write(jv->fd, &jv->nJobId, 4);
    write(jv->fd, &jv->isDel, 4);
    write(jv->fd, jv->szBackupPath, 256);
    write(jv->fd, &jv->nFileNum, 4);
    return 1;
}

canonical_original_code:
int jobv_write_head(struct job_des *jv) {
    lseek(jv->fd, 0, 0);
    write(jv->fd, &jv->nJobId, 4);
    write(jv->fd, &jv->isDel, 4);
    write(jv->fd, jv->szBackupPath, 256);
    write(jv->fd, &jv->nFileNum, 4);
    return 1;
}

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


decompiled_code:
__int64 __fastcall jobv_read_head(void *buf)
{
lseek(*((_DWORD *)buf + 67), 0LL, 0);
read(*((_DWORD *)buf + 67), buf, 4uLL);
read(*((_DWORD *)buf + 67), (char *)buf + 4, 4uLL);
read(*((_DWORD *)buf + 67), (char *)buf + 8, 0x100uLL);
read(*((_DWORD *)buf + 67), (char *)buf + 264, 4uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *buf)
{
lseek(*((_DWORD *)buf + 67), 0LL, 0);
read(*((_DWORD *)buf + 67), buf, 4uLL);
read(*((_DWORD *)buf + 67), (char *)buf + 4, 4uLL);
read(*((_DWORD *)buf + 67), (char *)buf + 8, 0x100uLL);
read(*((_DWORD *)buf + 67), (char *)buf + 264, 4uLL);
return 1LL;
}

original_code:
int jobv_read_head(JOB_V* psVolume) {
    lseek(psVolume->fd, 0, 0);
    read(psVolume->fd, &psVolume->nJobId, 4);
    read(psVolume->fd, &psVolume->isDel, 4);
    read(psVolume->fd, psVolume->szBackupPath, 256);
    read(psVolume->fd, &psVolume->nFileNum, 4);
    return 1;
}

canonical_original_code:
int jobv_read_head(struct job_des *psVolume) {
    lseek(psVolume->fd, 0, 0);
    read(psVolume->fd, &psVolume->nJobId, 4);
    read(psVolume->fd, &psVolume->isDel, 4);
    read(psVolume->fd, psVolume->szBackupPath, 256);
    read(psVolume->fd, &psVolume->nFileNum, 4);
    return 1;
}


original_code:
void jobv_insert_recipe(JOB_V * jv,Recipe *rp){
 char *buf=((void *)0),*p;
 buf=(char *)calloc(1,4+4+256 +rp->chunknum*32+10);
 p=buf;
 memcpy(p,&rp->fileindex,sizeof(int));p+=4;
 memcpy(p,&rp->chunknum,sizeof(int));p+=4;
 memcpy(p,rp->filename,256);p+=256;
 FingerChunk *fc;
 fc=rp->first;
 while(fc){
  memcpy(p,fc->fingerprint,sizeof(Fingerprint));p+=sizeof(Fingerprint);
  memcpy(p,&fc->offset,8);p+=8;
  memcpy(p,&fc->length,4);p+=4;
  fc=fc->next;
 }
 writen(jv->fd,buf,(p-buf));
 free(buf);
 jv->nFileNum++;
}

canonical_original_code:
void jobv_insert_recipe(struct job_des *jv, struct recipe_tag *rp){
 char *buf = ((void *)0); char *p;
 buf=(char *)calloc(1,4+4+256 +rp->chunknum*32+10);
 p=buf;
 memcpy(p,&rp->fileindex,sizeof(int));p+=4;
 memcpy(p,&rp->chunknum,sizeof(int));p+=4;
 memcpy(p,rp->filename,256);p+=256;
 struct finger_chunk_tag *fc;
 fc=rp->first;
 while(fc){
  memcpy(p,fc->fingerprint,sizeof(Fingerprint));p+=sizeof(Fingerprint);
  memcpy(p,&fc->offset,8);p+=8;
  memcpy(p,&fc->length,4);p+=4;
  fc=fc->next;
 }
 writen(jv->fd,buf,(p-buf));
 free(buf);
 jv->nFileNum++;
}

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

variable_types:
buf
char *

variable_types:
p
char *

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


original_code:
Recipe * jobv_search_next_recipe(JOB_V*jv){
 char *buf=((void *)0),*p=((void *)0);
 int i=0;
 Recipe *rp=((void *)0);
 int chunknum=0;
 rp=recipe_new();
 if(!rp)
  return ((void *)0);
 if(read(jv->fd,&rp->fileindex,4)!=4)
  return ((void *)0);
 read(jv->fd,&chunknum,4);
 buf=(char *)malloc(256 +chunknum*32);
 p=buf;
 readn(jv->fd,buf,256 +chunknum*32);
 memcpy(rp->filename,p,256);p+=256;
 for(i=0;i<chunknum;i++){
  FingerChunk *fc=(FingerChunk *)malloc(sizeof(FingerChunk));
  fc->existed=0;
  memcpy(fc->fingerprint,p,sizeof(Fingerprint));p+=sizeof(Fingerprint);
  memcpy(&fc->offset,p,8);p+=8;
  memcpy(&fc->length,p,4);p+=4;
  recipe_append_fingerchunk(rp,fc);
 }
 if(rp->chunknum!=chunknum)
  err_msg("job/job.c",166,"chunk numbers are not matched \n");
 free(buf);
 return rp;
}

canonical_original_code:
struct recipe_tag *jobv_search_next_recipe(struct job_des *jv){
 char *buf = ((void *)0); char *p = ((void *)0);
 int i = 0;
 struct recipe_tag *rp = ((void *)0);
 int chunknum = 0;
 rp=recipe_new();
 if(!rp)
  return ((void *)0);
 if(read(jv->fd,&rp->fileindex,4)!=4)
  return ((void *)0);
 read(jv->fd,&chunknum,4);
 buf=(char *)malloc(256 +chunknum*32);
 p=buf;
 readn(jv->fd,buf,256 +chunknum*32);
 memcpy(rp->filename,p,256);p+=256;
 for(i=0;i<chunknum;i++){
  struct finger_chunk_tag *fc = (FingerChunk *)malloc(sizeof(FingerChunk));
  fc->existed=0;
  memcpy(fc->fingerprint,p,sizeof(Fingerprint));p+=sizeof(Fingerprint);
  memcpy(&fc->offset,p,8);p+=8;
  memcpy(&fc->length,p,4);p+=4;
  recipe_append_fingerchunk(rp,fc);
 }
 if(rp->chunknum!=chunknum)
  err_msg("job/job.c",166,"chunk numbers are not matched \n");
 free(buf);
 return rp;
}

variable_types: i int

variable_types: chunknum int

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


decompiled_code:
void __fastcall jobv_destroy(void *ptr)
{
int v2; // edi

jobv_write_head(ptr);
v2 = *((_DWORD *)ptr + 67);
if ( v2 > 0 )
close(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
int v2; // edi

func4(ptr);
v2 = *((_DWORD *)ptr + 67);
if ( v2 > 0 )
close(v2);
free(ptr);
}

original_code:
void jobv_destroy(JOB_V *jv)
{
 jobv_write_head(jv);
 if(jv->fd>0)
  close(jv->fd);
 jv->fd=-1;
 free(jv);
}

canonical_original_code:
void jobv_destroy(struct job_des *jv)
{
 jobv_write_head(jv);
 if(jv->fd>0)
  close(jv->fd);
 jv->fd=-1;
 free(jv);
}


original_code:
JOB_V *jobv_new(char * pathname){
 JOB_V *jv=jobv_init();
 char path[256]={0};
 char str[50]={0};
 strcpy(path,BackupVolPath);
 pthread_mutex_lock(&g_mutex);
 jv->nJobId=++g_job_count;
 pthread_mutex_unlock(&g_mutex);
 sprintf(str,"job_%d",g_job_count);
 strcat(path,str);
 printf("new job_v:%s\n",path);
 if ((jv->fd = open(path, 0100 | 01000 | 02, 0644)) <= 0) {
         err_msg("job/job.c",77,"can not creat  job_%d",jv->nJobId);
                 jobv_destroy(jv);
          return ((void *)0);
        }
 memcpy(jv->szBackupPath,pathname,strlen(pathname));
 jobv_write_head( jv);
 return jv;
}

canonical_original_code:
struct job_des *jobv_new(char *pathname){
 struct job_des *jv = jobv_init();
 char path[256] = {0};
 char str[50] = {0};
 strcpy(path,BackupVolPath);
 pthread_mutex_lock(&g_mutex);
 jv->nJobId=++g_job_count;
 pthread_mutex_unlock(&g_mutex);
 sprintf(str,"job_%d",g_job_count);
 strcat(path,str);
 printf("new job_v:%s\n",path);
 if ((jv->fd = open(path, 0100 | 01000 | 02, 0644)) <= 0) {
         err_msg("job/job.c",77,"can not creat  job_%d",jv->nJobId);
                 jobv_destroy(jv);
          return ((void *)0);
        }
 memcpy(jv->szBackupPath,pathname,strlen(pathname));
 jobv_write_head( jv);
 return jv;
}

variable_types:
pathname
char *

variable_types:
path
char [256]

variable_types:
str
char [50]

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


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

result = htable_init(8LL, 4LL, 32LL);
cap_htable = result;
return result;
}

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

result = htable_init(8LL, 4LL, 32LL);
cap_htable = result;
return result;
}

original_code:
void capping_init(){
 CapItem r;
 cap_htable=htable_init((char*)&r.next-(char*)&r,4,32);
}

canonical_original_code:
void capping_init(){
 struct Cap_item r;
 cap_htable=htable_init((char *)&r.next-(char *)&r,4,32);
}

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

user_defined_types: struct Cap_item { int container_id; int chunk_count; struct hlink_t next; }


decompiled_code:
__int64 capping_destroy()
{
return htable_destroy(cap_htable);
}

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

original_code:
void capping_destroy(){
 htable_destroy(cap_htable);
}


decompiled_code:
__int64 capping_reset()
{
__int64 i; // rsi
__int64 result; // rax

for ( i = htable_get_first(cap_htable); i; i = htable_get_next(cap_htable) )
htable_remove(cap_htable, i);
result = cap_htable;
if ( *(_DWORD *)(cap_htable + 16) )
result = err_msg("capping.c", 24LL, "reset wrong");
return result;
}

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

for ( i = htable_get_first(cap_htable); i; i = htable_get_next(cap_htable) )
htable_remove(cap_htable, i);
result = cap_htable;
if ( *(_DWORD *)(cap_htable + 16) )
result = err_msg("capping.c", 24LL, "reset wrong");
return result;
}

original_code:
void capping_reset(){
 CapItem * rf;
 for((*((void **)&(rf))=(void *)(htable_get_first((cap_htable)))); (rf); (*((void **)&(rf))=(void *)(htable_get_next(cap_htable)))){
  htable_remove(cap_htable,&rf->container_id);
 }
 if(cap_htable->num_items!=0)
  err_msg("capping.c",24,"reset wrong");
}

canonical_original_code:
void capping_reset(){
 struct Cap_item *rf;
 for((*((void **)&(rf))=(void *)(htable_get_first((cap_htable)))); (rf); (*((void **)&(rf))=(void *)(htable_get_next(cap_htable)))){
  htable_remove(cap_htable,&rf->container_id);
 }
 if(cap_htable->num_items!=0)
  err_msg("capping.c",24,"reset wrong");
}

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


decompiled_code:
int capping_build()
{
__int64 v0; // r8
int v2; // ebp
int i; // ebx
int *v4; // rax
int v5; // edx
int v6; // er13
int v7[11]; // [rsp+0h] [rbp-2Ch] BYREF

v0 = *(unsigned int *)(cap_htable + 16);
if ( (unsigned int)v0 <= G_CAPPING_T )
return 0;
v2 = v0 - G_CAPPING_T;
printf("%s %d needing cappping total (%d) %d \n", "capping.c", 48LL, (unsigned int)(v0 - G_CAPPING_T), v0);
v7[0] = 0;
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
v7[0] = 0;
v4 = (int *)htable_get_first(cap_htable);
if ( v4 )
{
v6 = 0x7FFFFFFF;
do
{
v5 = v4[1];
if ( v5 < v6 )
{
v7[0] = *v4;
v6 = v5;
}
v4 = (int *)htable_get_next(cap_htable);
}
while ( v4 );
}
if ( v7[0] )
htable_remove(cap_htable, v7);
else
err_msg("capping.c", 65LL, "maybe wrong");
}
}
return printf("===============%d \n", *(unsigned int *)(cap_htable + 16));
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // r8
int v2; // ebp
int i; // ebx
int *v4; // rax
int v5; // edx
int v6; // er13
int v7[11]; // [rsp+0h] [rbp-2Ch] BYREF

v0 = *(unsigned int *)(cap_htable + 16);
if ( (unsigned int)v0 <= G_CAPPING_T )
return 0;
v2 = v0 - G_CAPPING_T;
printf("%s %d needing cappping total (%d) %d \n", "capping.c", 48LL, (unsigned int)(v0 - G_CAPPING_T), v0);
v7[0] = 0;
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
v7[0] = 0;
v4 = (int *)htable_get_first(cap_htable);
if ( v4 )
{
v6 = 0x7FFFFFFF;
do
{
v5 = v4[1];
if ( v5 < v6 )
{
v7[0] = *v4;
v6 = v5;
}
v4 = (int *)htable_get_next(cap_htable);
}
while ( v4 );
}
if ( v7[0] )
htable_remove(cap_htable, v7);
else
err_msg("capping.c", 65LL, "maybe wrong");
}
}
return printf("===============%d \n", *(unsigned int *)(cap_htable + 16));
}

original_code:
int capping_build(){
 if(cap_htable->num_items<=G_CAPPING_T){
  return 0;
 }
 int diff_num=cap_htable->num_items-G_CAPPING_T;
 printf("%s %d needing cappping total (%d)  %d \n","capping.c",48,diff_num,cap_htable->num_items);
 int i=0;
 int min_ck=2147483647;
 int min_cid=0;
 CapItem *var=((void *)0);
 for(i=0;i<diff_num;i++){
  min_cid=0;
  int min_ck=2147483647;
  for((*((void **)&(var))=(void *)(htable_get_first((cap_htable)))); (var); (*((void **)&(var))=(void *)(htable_get_next(cap_htable)))){
   if(min_ck> var->chunk_count){
    min_ck=var->chunk_count;
    min_cid=var->container_id;
   }
  }
  if(min_cid)
   htable_remove(cap_htable,&min_cid);
  else
   err_msg("capping.c",65,"maybe wrong");
 }
 printf("===============%d \n",cap_htable->num_items);
}

canonical_original_code:
int capping_build(){
 if(cap_htable->num_items<=G_CAPPING_T){
  return 0;
 }
 int diff_num = cap_htable->num_items-G_CAPPING_T;
 printf("%s %d needing cappping total (%d)  %d \n","capping.c",48,diff_num,cap_htable->num_items);
 int i = 0;
 int min_ck = 2147483647;
 int min_cid = 0;
 struct Cap_item *var = ((void *)0);
 for(i=0;i<diff_num;i++){
  min_cid=0;
  int min_ck = 2147483647;
  for((*((void **)&(var))=(void *)(htable_get_first((cap_htable)))); (var); (*((void **)&(var))=(void *)(htable_get_next(cap_htable)))){
   if(min_ck> var->chunk_count){
    min_ck=var->chunk_count;
    min_cid=var->container_id;
   }
  }
  if(min_cid)
   htable_remove(cap_htable,&min_cid);
  else
   err_msg("capping.c",65,"maybe wrong");
 }
 printf("===============%d \n",cap_htable->num_items);
}


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

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

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

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

original_code:
int capping_rewrite(int old_container_id){
 CapItem * rf=htable_lookup(cap_htable,&old_container_id);
 if(rf)
  return 0;
 else
  return 1;
}

canonical_original_code:
int capping_rewrite(int old_container_id){
 struct Cap_item *rf = htable_lookup(cap_htable,&old_container_id);
 if(rf)
  return 0;
 else
  return 1;
}