decompiled_code:
unsigned __int64 __fastcall cfg_getuint64(char *s1, unsigned __int64 a2)
{
void *v2; // rbx
unsigned __int64 result; // rax

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_4;
}
result = strtoull(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
syslog(5, "config: using default value for option '%s' - '%lu'", s1, a2);
fprintf(stderr, "config: using default value for option '%s' - '%lu'\n", s1, a2);
result = a2;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(char *s1, unsigned __int64 a2)
{
void *v2; // rbx
unsigned __int64 result; // rax

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_4;
}
result = strtoull(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
syslog(5, "config: using default value for option '%s' - '%lu'", s1, a2);
fprintf(stderr, "config: using default value for option '%s' - '%lu'\n", s1, a2);
result = a2;
}
}
return result;
}

original_code: uint64_t cfg_getuint64(const char *name,uint64_t def) { paramstr *_cfg_tmp; for (_cfg_tmp = paramhead ; _cfg_tmp ; _cfg_tmp=_cfg_tmp->next) { if (strcmp(name,_cfg_tmp->name)==0) { return strtoull(_cfg_tmp->value,((void *)0),0); } } if (logundefined) { { syslog((5),("config: using default value for option '%s' - '" "%""l" "u" "'"), name,def); fprintf(stderr,"config: using default value for option '%s' - '" "%""l" "u" "'" "\n", name,def); }; } return def; }

canonical_original_code: unsigned long cfg_getuint64(char *name, unsigned long def) { struct paramsstr *_cfg_tmp; for (_cfg_tmp = paramhead ; _cfg_tmp ; _cfg_tmp=_cfg_tmp->next) { if (strcmp(name,_cfg_tmp->name)==0) { return strtoull(_cfg_tmp->value,((void *)0),0); } } if (logundefined) { { syslog((5),("config: using default value for option '%s' - '" "%""l" "u" "'"), name,def); fprintf(stderr,"config: using default value for option '%s' - '" "%""l" "u" "'" "\n", name,def); }; } return def; }

variable_types:
def
unsigned long


repo: twonly/mfs

decompiled_code:
double __fastcall cfg_getdouble(char *s1, double result)
{
void *v2; // rbx

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_4;
}
result = strtod(*((const char **)v2 + 1), 0LL);
}
else
{
LABEL_4:
if ( logundefined )
{
syslog(5, "config: using default value for option '%s' - '%lf'", s1, result);
fprintf(stderr, "config: using default value for option '%s' - '%lf'\n", s1, result);
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func14(char *s1, double result)
{
void *v2; // rbx

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_4;
}
result = strtod(*((const char **)v2 + 1), 0LL);
}
else
{
LABEL_4:
if ( logundefined )
{
syslog(5, "config: using default value for option '%s' - '%lf'", s1, result);
fprintf(stderr, "config: using default value for option '%s' - '%lf'\n", s1, result);
}
}
return result;
}

original_code: double cfg_getdouble(const char *name,double def) { paramstr *_cfg_tmp; for (_cfg_tmp = paramhead ; _cfg_tmp ; _cfg_tmp=_cfg_tmp->next) { if (strcmp(name,_cfg_tmp->name)==0) { return strtod(_cfg_tmp->value,((void *)0)); } } if (logundefined) { { syslog((5),("config: using default value for option '%s' - '" "%lf" "'"), name,def); fprintf(stderr,"config: using default value for option '%s' - '" "%lf" "'" "\n", name,def); }; } return def; }

canonical_original_code: double cfg_getdouble(char *name, double def) { struct paramsstr *_cfg_tmp; for (_cfg_tmp = paramhead ; _cfg_tmp ; _cfg_tmp=_cfg_tmp->next) { if (strcmp(name,_cfg_tmp->name)==0) { return strtod(_cfg_tmp->value,((void *)0)); } } if (logundefined) { { syslog((5),("config: using default value for option '%s' - '" "%lf" "'"), name,def); fprintf(stderr,"config: using default value for option '%s' - '" "%lf" "'" "\n", name,def); }; } return def; }

variable_types:
name
char *

variable_types: def double

variable_types: struct paramsstr { char *name; char *value; struct paramsstr *next; } *

return_type: double


original_code:
static inline void itree_remove(itnode **p) {
 itnode *n = *p;
 itnode *nit,**nptr;
 uint32_t l,r;
 if (n->left==((void *)0)) {
  *p = n->right;
  free(n);
 } else if (n->right==((void *)0)) {
  *p = n->left;
  free(n);
 } else {
  l = r = 0;
  for (nit=n->left->right ; nit ; nit=nit->right) {
   l++;
  }
  for (nit=n->right->left ; nit ; nit=nit->left) {
   r++;
  }
  if (l==r) {
   l+=((n->from)^(n->to))&1;
  }
  if (r>l) {
   nptr = &(n->right);
   while ((nit=*nptr) && nit->left) {
    nptr = &(nit->left);
   }
   *nptr = nit->right;
  } else {
   nptr = &(n->left);
   while ((nit=*nptr) && nit->right) {
    nptr = &(nit->right);
   }
   *nptr = nit->left;
  }
  nit->left = n->left;
  nit->right = n->right;
  *p = nit;
 }
}

canonical_original_code:
static inline void itree_remove(struct _itnode **p) {
 struct _itnode *n = *p;
 struct _itnode *nit; struct _itnode **nptr;
 unsigned int l; unsigned int r;
 if (n->left==((void *)0)) {
  *p = n->right;
  free(n);
 } else if (n->right==((void *)0)) {
  *p = n->left;
  free(n);
 } else {
  l = r = 0;
  for (nit=n->left->right ; nit ; nit=nit->right) {
   l++;
  }
  for (nit=n->right->left ; nit ; nit=nit->left) {
   r++;
  }
  if (l==r) {
   l+=((n->from)^(n->to))&1;
  }
  if (r>l) {
   nptr = &(n->right);
   while ((nit=*nptr) && nit->left) {
    nptr = &(nit->left);
   }
   *nptr = nit->right;
  } else {
   nptr = &(n->left);
   while ((nit=*nptr) && nit->right) {
    nptr = &(nit->right);
   }
   *nptr = nit->left;
  }
  nit->left = n->left;
  nit->right = n->right;
  *p = nit;
 }
}

variable_types: struct _itnode { unsigned int from; unsigned int id; struct _itnode *left; } **

variable_types:
l
unsigned int

variable_types:
r
unsigned int

return_type: void


decompiled_code:
void __fastcall itree_free(void *ptr)
{
if ( ptr )
{
itree_free(*((void **)ptr + 2));
itree_free(*((void **)ptr + 3));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
func1(*((void **)ptr + 2));
func1(*((void **)ptr + 3));
free(ptr);
}
}

original_code:
static inline void itree_free(itnode *n) {
 if (n) {
  itree_free(n->left);
  itree_free(n->right);
  free(n);
 }
}

canonical_original_code:
static inline void itree_free(struct _itnode *n) {
 if (n) {
  itree_free(n->left);
  itree_free(n->right);
  free(n);
 }
}

variable_types: struct _itnode { unsigned int from; unsigned int id; struct _itnode *left; } *


decompiled_code:
__int64 __fastcall itree_add(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int *v7; // rbx
__int64 v8; // rsi
__int64 result; // rax
unsigned int v10; // esi

v7 = (unsigned int *)*a1;
if ( *a1 )
{
v8 = *v7;
if ( (unsigned int)v8 > a3 )
{
result = itree_add(v7 + 4, a2);
}
else
{
result = v7[1];
if ( (unsigned int)result < a2 )
{
result = itree_add(v7 + 6, a2);
}
else if ( (unsigned int)result <= a3 && (unsigned int)v8 >= a2 )
{
if ( (unsigned int)v8 > a2 )
result = itree_delete(v7 + 4, a2, (unsigned int)(v8 - 1));
v10 = v7[1];
if ( v10 < a3 )
result = itree_delete(v7 + 6, v10 + 1, a3);
*v7 = a2;
v7[1] = a3;
v7[2] = a4;
}
else if ( (unsigned int)result >= a3 && (unsigned int)v8 <= a2 )
{
if ( (unsigned int)v8 < a2 )
result = itree_add(v7 + 4, v8);
if ( v7[1] > a3 )
result = itree_add(v7 + 6, a3 + 1);
*v7 = a2;
v7[1] = a3;
v7[2] = a4;
}
else if ( (unsigned int)v8 > a2 )
{
*v7 = a3 + 1;
result = itree_add(v7 + 4, a2);
}
else if ( (unsigned int)result < a3 )
{
v7[1] = a2 - 1;
result = itree_add(v7 + 6, a2);
}
}
}
else
{
result = (__int64)malloc(0x20uLL);
*a1 = result;
if ( !result )
{
fprintf(stderr, "out of memory: %s is NULL\n", "n");
syslog(3, "out of memory: %s is NULL", "n");
abort();
}
*(_DWORD *)result = a2;
*(_DWORD *)(result + 4) = a3;
*(_DWORD *)(result + 8) = a4;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int *v7; // rbx
__int64 v8; // rsi
__int64 result; // rax
unsigned int v10; // esi

v7 = (unsigned int *)*a1;
if ( *a1 )
{
v8 = *v7;
if ( (unsigned int)v8 > a3 )
{
result = func2(v7 + 4, a2);
}
else
{
result = v7[1];
if ( (unsigned int)result < a2 )
{
result = func2(v7 + 6, a2);
}
else if ( (unsigned int)result <= a3 && (unsigned int)v8 >= a2 )
{
if ( (unsigned int)v8 > a2 )
result = func3(v7 + 4, a2, (unsigned int)(v8 - 1));
v10 = v7[1];
if ( v10 < a3 )
result = func3(v7 + 6, v10 + 1, a3);
*v7 = a2;
v7[1] = a3;
v7[2] = a4;
}
else if ( (unsigned int)result >= a3 && (unsigned int)v8 <= a2 )
{
if ( (unsigned int)v8 < a2 )
result = func2(v7 + 4, v8);
if ( v7[1] > a3 )
result = func2(v7 + 6, a3 + 1);
*v7 = a2;
v7[1] = a3;
v7[2] = a4;
}
else if ( (unsigned int)v8 > a2 )
{
*v7 = a3 + 1;
result = func2(v7 + 4, a2);
}
else if ( (unsigned int)result < a3 )
{
v7[1] = a2 - 1;
result = func2(v7 + 6, a2);
}
}
}
else
{
result = (__int64)malloc(0x20uLL);
*a1 = result;
if ( !result )
{
fprintf(stderr, "out of memory: %s is NULL\n", "n");
syslog(3, "out of memory: %s is NULL", "n");
abort();
}
*(_DWORD *)result = a2;
*(_DWORD *)(result + 4) = a3;
*(_DWORD *)(result + 8) = a4;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
}
return result;
}

original_code:
static inline void itree_add(itnode **p,uint32_t f,uint32_t t,uint32_t id) {
 itnode *n = *p;
 if (n) {
  if (t<n->from) {
   itree_add(&(n->left),f,t,id);
  } else if (f>n->to) {
   itree_add(&(n->right),f,t,id);
  } else if (f<=n->from && t>=n->to) {
   if (f<n->from) {
    itree_delete(&(n->left),f,n->from-1);
   }
   if (t>n->to) {
    itree_delete(&(n->right),n->to+1,t);
   }
   n->from = f;
   n->to = t;
   n->id = id;
  } else if (f>=n->from && t<=n->to) {
   if (f>n->from) {
    itree_add(&(n->left),n->from,f-1,n->id);
   }
   if (t<n->to) {
    itree_add(&(n->right),t+1,n->to,n->id);
   }
   n->from = f;
   n->to = t;
   n->id = id;
  } else if (f<n->from) {
   n->from = t+1;
   itree_add(&(n->left),f,t,id);
  } else if (t>n->to) {
   n->to = f-1;
   itree_add(&(n->right),f,t,id);
  }
 } else {
  *p = n = malloc(sizeof(itnode));
  ((n!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","n"),syslog(3,"out of memory: %s is NULL","n"),abort()));
  n->from = f;
  n->to = t;
  n->id = id;
  n->left = ((void *)0);
  n->right = ((void *)0);
 }
}

canonical_original_code:
static inline void itree_add(struct _itnode **p, unsigned int f, unsigned int t, unsigned int id) {
 struct _itnode *n = *p;
 if (n) {
  if (t<n->from) {
   itree_add(&(n->left),f,t,id);
  } else if (f>n->to) {
   itree_add(&(n->right),f,t,id);
  } else if (f<=n->from && t>=n->to) {
   if (f<n->from) {
    itree_delete(&(n->left),f,n->from-1);
   }
   if (t>n->to) {
    itree_delete(&(n->right),n->to+1,t);
   }
   n->from = f;
   n->to = t;
   n->id = id;
  } else if (f>=n->from && t<=n->to) {
   if (f>n->from) {
    itree_add(&(n->left),n->from,f-1,n->id);
   }
   if (t<n->to) {
    itree_add(&(n->right),t+1,n->to,n->id);
   }
   n->from = f;
   n->to = t;
   n->id = id;
  } else if (f<n->from) {
   n->from = t+1;
   itree_add(&(n->left),f,t,id);
  } else if (t>n->to) {
   n->to = f-1;
   itree_add(&(n->right),f,t,id);
  }
 } else {
  *p = n = malloc(sizeof(itnode));
  ((n!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","n"),syslog(3,"out of memory: %s is NULL","n"),abort()));
  n->from = f;
  n->to = t;
  n->id = id;
  n->left = ((void *)0);
  n->right = ((void *)0);
 }
}

variable_types:
f
unsigned int

variable_types:
t
unsigned int

variable_types:
id
unsigned int

user_defined_types: struct _itnode { unsigned int from; unsigned int id; struct _itnode *left; }


original_code:
static inline void itree_delete(itnode **p,uint32_t f,uint32_t t) {
 itnode *n = *p;
 if (n) {
  if (t<n->from) {
   itree_delete(&(n->left),f,t);
  } else if (f>n->to) {
   itree_delete(&(n->right),f,t);
  } else if (f<=n->from && t>=n->to) {
   if (f<n->from) {
    itree_delete(&(n->left),f,n->from-1);
   }
   if (t>n->to) {
    itree_delete(&(n->right),n->to+1,t);
   }
   itree_remove(p);
  } else if (f>=n->from && t<=n->to) {
   if (f==n->from) {
    n->from = t+1;
   } else if (t==n->to) {
    n->to = f-1;
   } else {
    if ((t^f)&1) {
     itree_add(&(n->right),t+1,n->to,n->id);
     n->to = f-1;
    } else {
     itree_add(&(n->left),n->from,f-1,n->id);
     n->from = t+1;
    }
   }
  } else if (f<n->from) {
   n->from = t+1;
   itree_delete(&(n->left),f,t);
  } else if (t>n->to) {
   n->to = f-1;
   itree_delete(&(n->right),f,t);
  }
 }
}

canonical_original_code:
static inline void itree_delete(struct _itnode **p, unsigned int f, unsigned int t) {
 struct _itnode *n = *p;
 if (n) {
  if (t<n->from) {
   itree_delete(&(n->left),f,t);
  } else if (f>n->to) {
   itree_delete(&(n->right),f,t);
  } else if (f<=n->from && t>=n->to) {
   if (f<n->from) {
    itree_delete(&(n->left),f,n->from-1);
   }
   if (t>n->to) {
    itree_delete(&(n->right),n->to+1,t);
   }
   itree_remove(p);
  } else if (f>=n->from && t<=n->to) {
   if (f==n->from) {
    n->from = t+1;
   } else if (t==n->to) {
    n->to = f-1;
   } else {
    if ((t^f)&1) {
     itree_add(&(n->right),t+1,n->to,n->id);
     n->to = f-1;
    } else {
     itree_add(&(n->left),n->from,f-1,n->id);
     n->from = t+1;
    }
   }
  } else if (f<n->from) {
   n->from = t+1;
   itree_delete(&(n->left),f,t);
  } else if (t>n->to) {
   n->to = f-1;
   itree_delete(&(n->right),f,t);
  }
 }
}


decompiled_code:
__int64 __fastcall itree_tolist(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rax

result = a2;
if ( a1 )
{
v3 = (_QWORD *)itree_tolist(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 16) = 0LL;
*v3 = a1;
result = itree_tolist(*(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 24) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rax

result = a2;
if ( a1 )
{
v3 = (_QWORD *)func4(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 16) = 0LL;
*v3 = a1;
result = func4(*(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 24) = 0LL;
}
return result;
}

original_code:
itnode** itree_tolist(itnode *n,itnode **tail) {
 if (n) {
  tail = itree_tolist(n->left,tail);
  n->left = ((void *)0);
  *tail = n;
  tail = itree_tolist(n->right,&(n->left));
  n->right = ((void *)0);
 }
 return tail;
}

canonical_original_code:
struct _itnode **itree_tolist(struct _itnode *n, struct _itnode **tail) {
 if (n) {
  tail = itree_tolist(n->left,tail);
  n->left = ((void *)0);
  *tail = n;
  tail = itree_tolist(n->right,&(n->left));
  n->right = ((void *)0);
 }
 return tail;
}

variable_types:
n
struct _itnode *

variable_types:
tail
struct _itnode **

return_type: struct _itnode { unsigned int from; unsigned int id; struct _itnode *left; } **


original_code:
void itree_simplify(itnode *n) {
 itnode *f;
 while (n && n->left) {
  if (n->id == n->left->id && n->to+1 == n->left->from) {
   n->to = n->left->to;
   f = n->left;
   n->left = n->left->left;
   free(f);
  } else {
   n = n->left;
  }
 }
}

canonical_original_code:
void itree_simplify(struct _itnode *n) {
 struct _itnode *f;
 while (n && n->left) {
  if (n->id == n->left->id && n->to+1 == n->left->from) {
   n->to = n->left->to;
   f = n->left;
   n->left = n->left->left;
   free(f);
  } else {
   n = n->left;
  }
 }
}


decompiled_code:
__int64 __fastcall itree_totree(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 *v4; // rcx
__int64 v5; // rax
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

result = a1;
v6 = a1;
v3 = a1;
v4 = &v6;
if ( a1 )
{
do
{
v5 = *(_QWORD *)(result + 16);
if ( !v5 )
break;
v4 = (__int64 *)(*v4 + 16);
result = *(_QWORD *)(v5 + 16);
v3 = *v4;
}
while ( result );
*a2 = v3;
*v4 = 0LL;
itree_totree(*(_QWORD *)(v3 + 16), v3 + 24);
result = itree_totree(v6, v3 + 16);
}
else
{
*a2 = 0LL;
}
return result;
}

original_code:
void itree_totree(itnode *l,itnode **p) {
 itnode **m,*i;
 if (l) {
  i = l;
  m = &l;
  while (i && i->left) {
   m = &((*m)->left);
   i = i->left->left;
  }
  *p = i = *m;
  (*m) = ((void *)0);
  itree_totree(i->left,&(i->right));
  itree_totree(l,&(i->left));
 } else {
  *p = ((void *)0);
 }
}

canonical_original_code:
void itree_totree(struct _itnode *l, struct _itnode **p) {
 struct _itnode **m; struct _itnode *i;
 if (l) {
  i = l;
  m = &l;
  while (i && i->left) {
   m = &((*m)->left);
   i = i->left->left;
  }
  *p = i = *m;
  (*m) = ((void *)0);
  itree_totree(i->left,&(i->right));
  itree_totree(l,&(i->left));
 } else {
  *p = ((void *)0);
 }
}

variable_types:
p
struct _itnode **


decompiled_code:
__int64 __fastcall itree_rebalance(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
_DWORD *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
itree_tolist(a1, (__int64)&v3);
itree_simplify(v3);
v2 = 0LL;
itree_totree((__int64)v3, &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
_DWORD *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
func4(a1, (__int64)&v3);
func5(v3);
v2 = 0LL;
func6((__int64)v3, &v2);
return v2;
}

original_code:
void* itree_rebalance(void *o) {
 itnode *head;
 itnode *root = (itnode*)o;
 head = ((void *)0);
 itree_tolist(root,&head);
 itree_simplify(head);
 root = ((void *)0);
 itree_totree(head,&root);
 return (void*)root;
}

canonical_original_code:
void *itree_rebalance(void *o) {
 struct _itnode *head;
 struct _itnode *root = (itnode*)o;
 head = ((void *)0);
 itree_tolist(root,&head);
 itree_simplify(head);
 root = ((void *)0);
 itree_totree(head,&root);
 return (void *)root;
}

variable_types:
o
void *

return_type: void *


decompiled_code:
__int64 __fastcall itree_find(__int64 a1, unsigned int a2)
{
if ( !a1 )
return 0LL;
do
{
if ( *(_DWORD *)a1 > a2 )
{
a1 = *(_QWORD *)(a1 + 16);
}
else
{
if ( *(_DWORD *)(a1 + 4) >= a2 )
return *(unsigned int *)(a1 + 8);
a1 = *(_QWORD *)(a1 + 24);
}
}
while ( a1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
if ( !a1 )
return 0LL;
do
{
if ( *(_DWORD *)a1 > a2 )
{
a1 = *(_QWORD *)(a1 + 16);
}
else
{
if ( *(_DWORD *)(a1 + 4) >= a2 )
return *(unsigned int *)(a1 + 8);
a1 = *(_QWORD *)(a1 + 24);
}
}
while ( a1 );
return 0LL;
}

original_code:
uint32_t itree_find(void *o,uint32_t v) {
 itnode *n;
 for (n = (itnode*)o ; n ; n = (v<n->from)?n->left:n->right) {
  if (v>=n->from && v<=n->to) {
   return n->id;
  }
 }
 return 0;
}

canonical_original_code:
unsigned int itree_find(void *o, unsigned int v) {
 struct _itnode *n;
 for (n = (struct _itnode *)o ; n ; n = (v<n->from)?n->left:n->right) {
  if (v>=n->from && v<=n->to) {
   return n->id;
  }
 }
 return 0;
}

variable_types:
v
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall itree_freeall(void *a1)
{
itree_free(a1);
}

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

original_code:
void itree_freeall(void *o) {
 itree_free((itnode*)o);
}

canonical_original_code:
void itree_freeall(void *o) {
 itree_free((struct _itnode *)o);
}


decompiled_code:
__int64 __fastcall dcm_open(int a1, int a2)
{
unsigned int v2; // ecx
unsigned int v3; // eax
unsigned int v4; // edx
unsigned int v5; // er9
unsigned int v6; // eax
int v7; // er8
__int64 v8; // r10
int v9; // eax
unsigned int v10; // er10
unsigned int v11; // er8
__int64 v12; // r9
unsigned int v13; // esi
__int64 result; // rax
unsigned int v15; // esi
unsigned int v16; // edx
int v17; // edx
__int64 v18; // rdi

v2 = 1246751953 * a1 % 0x3D090u;
v3 = dcm_inodehash[v2];
if ( v3 <= (unsigned int)&unk_7A11F )
{
while ( dcm_tab[6 * v3] != a1 || (unsigned int)dword_F4924[6 * v3] >> 1 != a2 )
{
v3 = dword_F492C[6 * v3];
if ( v3 > (unsigned int)&unk_7A11F )
goto LABEL_2;
}
if ( dcm_lru_last != v3 )
{
v15 = dword_F4930[6 * v3];
v16 = dword_F4934[6 * v3];
if ( v15 > (unsigned int)&unk_7A11F )
dcm_lru_first = dword_F4934[6 * v3];
else
dword_F4934[6 * v15] = v16;
if ( v16 > (unsigned int)&unk_7A11F )
dcm_lru_last = v15;
else
dword_F4930[6 * v16] = v15;
v17 = dcm_lru_last;
v18 = 3LL * v3;
dword_F4930[2 * v18] = dcm_lru_last;
dword_F4934[2 * v18] = -1;
dword_F4934[6 * v17] = v3;
dcm_lru_last = v3;
}
result = dword_F4924[6 * v3] & 1;
}
else
{
LABEL_2:
v4 = dcm_lru_first;
v5 = dword_F4930[6 * dcm_lru_first];
v6 = dword_F4934[6 * dcm_lru_first];
if ( v5 > (unsigned int)&unk_7A11F )
dcm_lru_first = dword_F4934[6 * dcm_lru_first];
else
dword_F4934[6 * v5] = v6;
if ( v6 > (unsigned int)&unk_7A11F )
dcm_lru_last = v5;
else
dword_F4930[6 * v6] = v5;
v7 = dcm_lru_last;
v8 = 3LL * v4;
dword_F4930[2 * v8] = dcm_lru_last;
dword_F4934[2 * v8] = -1;
dword_F4934[6 * v7] = v4;
dcm_lru_last = v4;
v9 = dcm_tab[6 * v4];
if ( v9 )
{
v10 = dword_F4928[6 * v4];
v11 = dword_F492C[6 * v4];
if ( v10 > (unsigned int)&unk_7A11F )
dcm_inodehash[1246751953 * v9 % 0x3D090u] = v11;
else
dword_F492C[6 * v10] = v11;
if ( v11 <= (unsigned int)&unk_7A11F )
dword_F4928[6 * v11] = v10;
}
v12 = 3LL * v4;
dcm_tab[2 * v12] = a1;
LOBYTE(dword_F4924[2 * v12]) &= 0xFEu;
dcm_tab[6 * v4 + 1] = dcm_tab[6 * v4 + 1] & 1 | (2 * a2);
v13 = dcm_inodehash[v2];
dword_F492C[2 * v12] = v13;
dword_F4928[2 * v12] = -1;
dcm_inodehash[v2] = v4;
result = 0LL;
if ( v13 <= (unsigned int)&unk_7A11F )
{
dword_F4928[6 * v13] = v4;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
unsigned int v2; // ecx
unsigned int v3; // eax
unsigned int v4; // edx
unsigned int v5; // er9
unsigned int v6; // eax
int v7; // er8
__int64 v8; // r10
int v9; // eax
unsigned int v10; // er10
unsigned int v11; // er8
__int64 v12; // r9
unsigned int v13; // esi
__int64 result; // rax
unsigned int v15; // esi
unsigned int v16; // edx
int v17; // edx
__int64 v18; // rdi

v2 = 1246751953 * a1 % 0x3D090u;
v3 = dcm_inodehash[v2];
if ( v3 <= (unsigned int)&unk_7A11F )
{
while ( dcm_tab[6 * v3] != a1 || (unsigned int)dword_F4924[6 * v3] >> 1 != a2 )
{
v3 = dword_F492C[6 * v3];
if ( v3 > (unsigned int)&unk_7A11F )
goto LABEL_2;
}
if ( dcm_lru_last != v3 )
{
v15 = dword_F4930[6 * v3];
v16 = dword_F4934[6 * v3];
if ( v15 > (unsigned int)&unk_7A11F )
dcm_lru_first = dword_F4934[6 * v3];
else
dword_F4934[6 * v15] = v16;
if ( v16 > (unsigned int)&unk_7A11F )
dcm_lru_last = v15;
else
dword_F4930[6 * v16] = v15;
v17 = dcm_lru_last;
v18 = 3LL * v3;
dword_F4930[2 * v18] = dcm_lru_last;
dword_F4934[2 * v18] = -1;
dword_F4934[6 * v17] = v3;
dcm_lru_last = v3;
}
result = dword_F4924[6 * v3] & 1;
}
else
{
LABEL_2:
v4 = dcm_lru_first;
v5 = dword_F4930[6 * dcm_lru_first];
v6 = dword_F4934[6 * dcm_lru_first];
if ( v5 > (unsigned int)&unk_7A11F )
dcm_lru_first = dword_F4934[6 * dcm_lru_first];
else
dword_F4934[6 * v5] = v6;
if ( v6 > (unsigned int)&unk_7A11F )
dcm_lru_last = v5;
else
dword_F4930[6 * v6] = v5;
v7 = dcm_lru_last;
v8 = 3LL * v4;
dword_F4930[2 * v8] = dcm_lru_last;
dword_F4934[2 * v8] = -1;
dword_F4934[6 * v7] = v4;
dcm_lru_last = v4;
v9 = dcm_tab[6 * v4];
if ( v9 )
{
v10 = dword_F4928[6 * v4];
v11 = dword_F492C[6 * v4];
if ( v10 > (unsigned int)&unk_7A11F )
dcm_inodehash[1246751953 * v9 % 0x3D090u] = v11;
else
dword_F492C[6 * v10] = v11;
if ( v11 <= (unsigned int)&unk_7A11F )
dword_F4928[6 * v11] = v10;
}
v12 = 3LL * v4;
dcm_tab[2 * v12] = a1;
LOBYTE(dword_F4924[2 * v12]) &= 0xFEu;
dcm_tab[6 * v4 + 1] = dcm_tab[6 * v4 + 1] & 1 | (2 * a2);
v13 = dcm_inodehash[v2];
dword_F492C[2 * v12] = v13;
dword_F4928[2 * v12] = -1;
dcm_inodehash[v2] = v4;
result = 0LL;
if ( v13 <= (unsigned int)&unk_7A11F )
{
dword_F4928[6 * v13] = v4;
result = 0LL;
}
}
return result;
}

original_code:
int dcm_open(uint32_t inode,uint32_t sessionid) {
 uint32_t ih = (((inode)*0x4A4FECD1)%((500000)/2));
 uint32_t p,pp,np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
   if (dcm_lru_last!=p) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = dcm_lru_last;
    dcm_tab[p].lrunext = 0xFFFFFFFF;
    dcm_tab[dcm_lru_last].lrunext = p;
    dcm_lru_last = p;
   }
   return dcm_tab[p].cacheok;
  }
  p = dcm_tab[p].inext;
 }
 p = dcm_lru_first;
 pp = dcm_tab[p].lruprev;
 np = dcm_tab[p].lrunext;
 if (pp<500000) {
  dcm_tab[pp].lrunext = np;
 } else {
  dcm_lru_first = np;
 }
 if (np<500000) {
  dcm_tab[np].lruprev = pp;
 } else {
  dcm_lru_last = pp;
 }
 dcm_tab[p].lruprev = dcm_lru_last;
 dcm_tab[p].lrunext = 0xFFFFFFFF;
 dcm_tab[dcm_lru_last].lrunext = p;
 dcm_lru_last = p;
 if (dcm_tab[p].inode>0) {
  ih = (((dcm_tab[p].inode)*0x4A4FECD1)%((500000)/2));
  pp = dcm_tab[p].iprev;
  np = dcm_tab[p].inext;
  if (pp<500000) {
   dcm_tab[pp].inext = np;
  } else {
   dcm_inodehash[ih] = np;
  }
  if (np<500000) {
   dcm_tab[np].iprev = pp;
  }
 }
 dcm_tab[p].inode = inode;
 dcm_tab[p].cacheok = 0;
 dcm_tab[p].sessionid = sessionid;
 ih = (((inode)*0x4A4FECD1)%((500000)/2));
 np = dcm_inodehash[ih];
 dcm_tab[p].inext = np;
 dcm_tab[p].iprev = 0xFFFFFFFF;
 dcm_inodehash[ih] = p;
 if (np<500000) {
  dcm_tab[np].iprev = p;
 }
 return 0;
}

canonical_original_code:
int dcm_open(unsigned int inode, unsigned int sessionid) {
 unsigned int ih = (((inode)*0x4A4FECD1)%((500000)/2));
 unsigned int p; unsigned int pp; unsigned int np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
   if (dcm_lru_last!=p) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = dcm_lru_last;
    dcm_tab[p].lrunext = 0xFFFFFFFF;
    dcm_tab[dcm_lru_last].lrunext = p;
    dcm_lru_last = p;
   }
   return dcm_tab[p].cacheok;
  }
  p = dcm_tab[p].inext;
 }
 p = dcm_lru_first;
 pp = dcm_tab[p].lruprev;
 np = dcm_tab[p].lrunext;
 if (pp<500000) {
  dcm_tab[pp].lrunext = np;
 } else {
  dcm_lru_first = np;
 }
 if (np<500000) {
  dcm_tab[np].lruprev = pp;
 } else {
  dcm_lru_last = pp;
 }
 dcm_tab[p].lruprev = dcm_lru_last;
 dcm_tab[p].lrunext = 0xFFFFFFFF;
 dcm_tab[dcm_lru_last].lrunext = p;
 dcm_lru_last = p;
 if (dcm_tab[p].inode>0) {
  ih = (((dcm_tab[p].inode)*0x4A4FECD1)%((500000)/2));
  pp = dcm_tab[p].iprev;
  np = dcm_tab[p].inext;
  if (pp<500000) {
   dcm_tab[pp].inext = np;
  } else {
   dcm_inodehash[ih] = np;
  }
  if (np<500000) {
   dcm_tab[np].iprev = pp;
  }
 }
 dcm_tab[p].inode = inode;
 dcm_tab[p].cacheok = 0;
 dcm_tab[p].sessionid = sessionid;
 ih = (((inode)*0x4A4FECD1)%((500000)/2));
 np = dcm_inodehash[ih];
 dcm_tab[p].inext = np;
 dcm_tab[p].iprev = 0xFFFFFFFF;
 dcm_inodehash[ih] = p;
 if (np<500000) {
  dcm_tab[np].iprev = p;
 }
 return 0;
}

variable_types:
inode
unsigned int

variable_types:
sessionid
unsigned int

variable_types:
ih
unsigned int

variable_types:
p
unsigned int

variable_types:
pp
unsigned int

variable_types:
np
unsigned int

return_type: int


decompiled_code:
__int64 __fastcall dcm_access(int a1, int a2)
{
__int64 result; // rax
unsigned int v3; // esi
unsigned int v4; // edx
int v5; // edx
__int64 v6; // rdi

result = (unsigned int)dcm_inodehash[1246751953 * a1 % 0x3D090u];
if ( (unsigned int)result <= (unsigned int)&unk_7A11F )
{
while ( dcm_tab[6 * (unsigned int)result] != a1 || (unsigned int)dword_F4924[6 * (unsigned int)result] >> 1 != a2 )
{
result = (unsigned int)dword_F492C[6 * (unsigned int)result];
if ( (unsigned int)result > (unsigned int)&unk_7A11F )
return result;
}
if ( dcm_lru_last != (_DWORD)result )
{
v3 = dword_F4930[6 * (unsigned int)result];
v4 = dword_F4934[6 * (unsigned int)result];
if ( v3 > (unsigned int)&unk_7A11F )
dcm_lru_first = dword_F4934[6 * (unsigned int)result];
else
dword_F4934[6 * v3] = v4;
if ( v4 > (unsigned int)&unk_7A11F )
dcm_lru_last = v3;
else
dword_F4930[6 * v4] = v3;
v5 = dcm_lru_last;
v6 = 3LL * (unsigned int)result;
dword_F4930[2 * v6] = dcm_lru_last;
dword_F4934[2 * v6] = -1;
dword_F4934[6 * v5] = result;
dcm_lru_last = result;
}
result = 3LL * (unsigned int)result;
LOBYTE(dword_F4924[2 * result]) |= 1u;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 result; // rax
unsigned int v3; // esi
unsigned int v4; // edx
int v5; // edx
__int64 v6; // rdi

result = (unsigned int)dcm_inodehash[1246751953 * a1 % 0x3D090u];
if ( (unsigned int)result <= (unsigned int)&unk_7A11F )
{
while ( dcm_tab[6 * (unsigned int)result] != a1 || (unsigned int)dword_F4924[6 * (unsigned int)result] >> 1 != a2 )
{
result = (unsigned int)dword_F492C[6 * (unsigned int)result];
if ( (unsigned int)result > (unsigned int)&unk_7A11F )
return result;
}
if ( dcm_lru_last != (_DWORD)result )
{
v3 = dword_F4930[6 * (unsigned int)result];
v4 = dword_F4934[6 * (unsigned int)result];
if ( v3 > (unsigned int)&unk_7A11F )
dcm_lru_first = dword_F4934[6 * (unsigned int)result];
else
dword_F4934[6 * v3] = v4;
if ( v4 > (unsigned int)&unk_7A11F )
dcm_lru_last = v3;
else
dword_F4930[6 * v4] = v3;
v5 = dcm_lru_last;
v6 = 3LL * (unsigned int)result;
dword_F4930[2 * v6] = dcm_lru_last;
dword_F4934[2 * v6] = -1;
dword_F4934[6 * v5] = result;
dcm_lru_last = result;
}
result = 3LL * (unsigned int)result;
LOBYTE(dword_F4924[2 * result]) |= 1u;
}
return result;
}

original_code:
void dcm_access(uint32_t inode,uint32_t sessionid) {
 uint32_t ih = (((inode)*0x4A4FECD1)%((500000)/2));
 uint32_t p,pp,np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
   if (dcm_lru_last!=p) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = dcm_lru_last;
    dcm_tab[p].lrunext = 0xFFFFFFFF;
    dcm_tab[dcm_lru_last].lrunext = p;
    dcm_lru_last = p;
   }
   dcm_tab[p].cacheok = 1;
   return;
  }
  p = dcm_tab[p].inext;
 }
}

canonical_original_code:
void dcm_access(unsigned int inode, unsigned int sessionid) {
 unsigned int ih = (((inode)*0x4A4FECD1)%((500000)/2));
 unsigned int p; unsigned int pp; unsigned int np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
   if (dcm_lru_last!=p) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = dcm_lru_last;
    dcm_tab[p].lrunext = 0xFFFFFFFF;
    dcm_tab[dcm_lru_last].lrunext = p;
    dcm_lru_last = p;
   }
   dcm_tab[p].cacheok = 1;
   return;
  }
  p = dcm_tab[p].inext;
 }
}


decompiled_code:
__int64 __fastcall dcm_modify(int a1, int a2)
{
unsigned int v3; // esi
__int64 result; // rax
int v5; // er8
int v6; // ecx
char v7; // bl
char v8; // r11
unsigned int v9; // er11
__int64 v10; // rbp
unsigned int v11; // er12
unsigned int v12; // ebp
__int64 v13; // r12
unsigned int v14; // edx
unsigned int v15; // ebx
__int64 v16; // rbp
unsigned int v17; // edx

v3 = 1246751953 * a1 % 0x3D090u;
result = (unsigned int)dcm_inodehash[v3];
if ( (unsigned int)result > (unsigned int)&unk_7A11F )
return result;
v5 = dcm_lru_last;
v6 = dcm_lru_first;
v7 = 0;
v8 = 0;
do
{
if ( dcm_tab[6 * (unsigned int)result] != a1 )
goto LABEL_21;
if ( (unsigned int)dword_F4924[6 * (unsigned int)result] >> 1 == a2 )
{
if ( (_DWORD)result != v5 )
{
v14 = dword_F4930[6 * (unsigned int)result];
v15 = dword_F4934[6 * (unsigned int)result];
if ( v14 > (unsigned int)&unk_7A11F )
{
v6 = dword_F4934[6 * (unsigned int)result];
v8 = 1;
}
else
{
dword_F4934[6 * v14] = v15;
}
if ( v15 <= (unsigned int)&unk_7A11F )
{
dword_F4930[6 * v15] = v14;
v14 = v5;
}
v16 = 3LL * (unsigned int)result;
dword_F4930[2 * v16] = v14;
dword_F4934[2 * v16] = -1;
dword_F4934[6 * v14] = result;
v5 = result;
v7 = 1;
}
LOBYTE(dword_F4924[6 * (unsigned int)result]) |= 1u;
LABEL_21:
result = (unsigned int)dword_F492C[6 * (unsigned int)result];
continue;
}
if ( v6 != (_DWORD)result )
{
v9 = dword_F4930[6 * (unsigned int)result];
v17 = dword_F4934[6 * (unsigned int)result];
if ( v9 > (unsigned int)&unk_7A11F )
v6 = dword_F4934[6 * (unsigned int)result];
else
dword_F4934[6 * v9] = v17;
if ( v17 > (unsigned int)&unk_7A11F )
{
v7 = 1;
}
else
{
dword_F4930[6 * v17] = v9;
v9 = v5;
}
v10 = 3LL * (unsigned int)result;
dword_F4930[2 * v10] = -1;
dword_F4934[2 * v10] = v6;
dword_F4930[6 * v6] = result;
v5 = v9;
v8 = 1;
}
v11 = dword_F4928[6 * (unsigned int)result];
v12 = dword_F492C[6 * (unsigned int)result];
if ( v11 > (unsigned int)&unk_7A11F )
dcm_inodehash[v3] = v12;
else
dword_F492C[6 * v11] = v12;
if ( v12 <= (unsigned int)&unk_7A11F )
dword_F4928[6 * v12] = v11;
v13 = 3LL * (unsigned int)result;
dcm_tab[2 * v13] = 0;
dword_F492C[2 * v13] = -1;
dword_F4928[2 * v13] = -1;
v6 = result;
result = v12;
}
while ( (unsigned int)result <= (unsigned int)&unk_7A11F );
if ( v8 )
dcm_lru_first = v6;
if ( v7 )
dcm_lru_last = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
unsigned int v3; // esi
__int64 result; // rax
int v5; // er8
int v6; // ecx
char v7; // bl
char v8; // r11
unsigned int v9; // er11
__int64 v10; // rbp
unsigned int v11; // er12
unsigned int v12; // ebp
__int64 v13; // r12
unsigned int v14; // edx
unsigned int v15; // ebx
__int64 v16; // rbp
unsigned int v17; // edx

v3 = 1246751953 * a1 % 0x3D090u;
result = (unsigned int)dcm_inodehash[v3];
if ( (unsigned int)result > (unsigned int)&unk_7A11F )
return result;
v5 = dcm_lru_last;
v6 = dcm_lru_first;
v7 = 0;
v8 = 0;
do
{
if ( dcm_tab[6 * (unsigned int)result] != a1 )
goto LABEL_21;
if ( (unsigned int)dword_F4924[6 * (unsigned int)result] >> 1 == a2 )
{
if ( (_DWORD)result != v5 )
{
v14 = dword_F4930[6 * (unsigned int)result];
v15 = dword_F4934[6 * (unsigned int)result];
if ( v14 > (unsigned int)&unk_7A11F )
{
v6 = dword_F4934[6 * (unsigned int)result];
v8 = 1;
}
else
{
dword_F4934[6 * v14] = v15;
}
if ( v15 <= (unsigned int)&unk_7A11F )
{
dword_F4930[6 * v15] = v14;
v14 = v5;
}
v16 = 3LL * (unsigned int)result;
dword_F4930[2 * v16] = v14;
dword_F4934[2 * v16] = -1;
dword_F4934[6 * v14] = result;
v5 = result;
v7 = 1;
}
LOBYTE(dword_F4924[6 * (unsigned int)result]) |= 1u;
LABEL_21:
result = (unsigned int)dword_F492C[6 * (unsigned int)result];
continue;
}
if ( v6 != (_DWORD)result )
{
v9 = dword_F4930[6 * (unsigned int)result];
v17 = dword_F4934[6 * (unsigned int)result];
if ( v9 > (unsigned int)&unk_7A11F )
v6 = dword_F4934[6 * (unsigned int)result];
else
dword_F4934[6 * v9] = v17;
if ( v17 > (unsigned int)&unk_7A11F )
{
v7 = 1;
}
else
{
dword_F4930[6 * v17] = v9;
v9 = v5;
}
v10 = 3LL * (unsigned int)result;
dword_F4930[2 * v10] = -1;
dword_F4934[2 * v10] = v6;
dword_F4930[6 * v6] = result;
v5 = v9;
v8 = 1;
}
v11 = dword_F4928[6 * (unsigned int)result];
v12 = dword_F492C[6 * (unsigned int)result];
if ( v11 > (unsigned int)&unk_7A11F )
dcm_inodehash[v3] = v12;
else
dword_F492C[6 * v11] = v12;
if ( v12 <= (unsigned int)&unk_7A11F )
dword_F4928[6 * v12] = v11;
v13 = 3LL * (unsigned int)result;
dcm_tab[2 * v13] = 0;
dword_F492C[2 * v13] = -1;
dword_F4928[2 * v13] = -1;
v6 = result;
result = v12;
}
while ( (unsigned int)result <= (unsigned int)&unk_7A11F );
if ( v8 )
dcm_lru_first = v6;
if ( v7 )
dcm_lru_last = v5;
return result;
}

original_code:
void dcm_modify(uint32_t inode,uint32_t sessionid) {
 uint32_t ih = (((inode)*0x4A4FECD1)%((500000)/2));
 uint32_t p,pp,np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid != sessionid) {
   if (p!=dcm_lru_first) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = 0xFFFFFFFF;
    dcm_tab[p].lrunext = dcm_lru_first;
    dcm_tab[dcm_lru_first].lruprev = p;
    dcm_lru_first = p;
   }
   pp = dcm_tab[p].iprev;
   np = dcm_tab[p].inext;
   if (pp<500000) {
    dcm_tab[pp].inext = np;
   } else {
    dcm_inodehash[ih] = np;
   }
   if (np<500000) {
    dcm_tab[np].iprev = pp;
   }
   dcm_tab[p].inode = 0;
   dcm_tab[p].inext = 0xFFFFFFFF;
   dcm_tab[p].iprev = 0xFFFFFFFF;
   p = np;
  } else {
   if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
    if (dcm_lru_last!=p) {
     pp = dcm_tab[p].lruprev;
     np = dcm_tab[p].lrunext;
     if (pp<500000) {
      dcm_tab[pp].lrunext = np;
     } else {
      dcm_lru_first = np;
     }
     if (np<500000) {
      dcm_tab[np].lruprev = pp;
     } else {
      dcm_lru_last = pp;
     }
     dcm_tab[p].lruprev = dcm_lru_last;
     dcm_tab[p].lrunext = 0xFFFFFFFF;
     dcm_tab[dcm_lru_last].lrunext = p;
     dcm_lru_last = p;
    }
    dcm_tab[p].cacheok = 1;
   }
   p = dcm_tab[p].inext;
  }
 }
}

canonical_original_code:
void dcm_modify(unsigned int inode, unsigned int sessionid) {
 unsigned int ih = (((inode)*0x4A4FECD1)%((500000)/2));
 unsigned int p; unsigned int pp; unsigned int np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid != sessionid) {
   if (p!=dcm_lru_first) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = 0xFFFFFFFF;
    dcm_tab[p].lrunext = dcm_lru_first;
    dcm_tab[dcm_lru_first].lruprev = p;
    dcm_lru_first = p;
   }
   pp = dcm_tab[p].iprev;
   np = dcm_tab[p].inext;
   if (pp<500000) {
    dcm_tab[pp].inext = np;
   } else {
    dcm_inodehash[ih] = np;
   }
   if (np<500000) {
    dcm_tab[np].iprev = pp;
   }
   dcm_tab[p].inode = 0;
   dcm_tab[p].inext = 0xFFFFFFFF;
   dcm_tab[p].iprev = 0xFFFFFFFF;
   p = np;
  } else {
   if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
    if (dcm_lru_last!=p) {
     pp = dcm_tab[p].lruprev;
     np = dcm_tab[p].lrunext;
     if (pp<500000) {
      dcm_tab[pp].lrunext = np;
     } else {
      dcm_lru_first = np;
     }
     if (np<500000) {
      dcm_tab[np].lruprev = pp;
     } else {
      dcm_lru_last = pp;
     }
     dcm_tab[p].lruprev = dcm_lru_last;
     dcm_tab[p].lrunext = 0xFFFFFFFF;
     dcm_tab[dcm_lru_last].lrunext = p;
     dcm_lru_last = p;
    }
    dcm_tab[p].cacheok = 1;
   }
   p = dcm_tab[p].inext;
  }
 }
}


original_code:
int dcm_init(void) {
 uint32_t i;
 for (i=0 ; i<((500000)/2) ; i++) {
  dcm_inodehash[i]=0xFFFFFFFF;
 }
 for (i=0 ; i<500000 ; i++) {
  dcm_tab[i].inode=0;
  dcm_tab[i].sessionid=0;
  dcm_tab[i].iprev = 0xFFFFFFFF;
  dcm_tab[i].inext = 0xFFFFFFFF;
  dcm_tab[i].lruprev = i-1;
  dcm_tab[i].lrunext = i+1;
 }
 dcm_tab[0].lruprev = 0xFFFFFFFF;
 dcm_lru_first = 0;
 dcm_tab[500000 -1].lrunext = 0xFFFFFFFF;
 dcm_lru_last = 500000 -1;
 return 0;
}

canonical_original_code:
int dcm_init() {
 unsigned int i;
 for (i=0 ; i<((500000)/2) ; i++) {
  dcm_inodehash[i]=0xFFFFFFFF;
 }
 for (i=0 ; i<500000 ; i++) {
  dcm_tab[i].inode=0;
  dcm_tab[i].sessionid=0;
  dcm_tab[i].iprev = 0xFFFFFFFF;
  dcm_tab[i].inext = 0xFFFFFFFF;
  dcm_tab[i].lruprev = i-1;
  dcm_tab[i].lrunext = i+1;
 }
 dcm_tab[0].lruprev = 0xFFFFFFFF;
 dcm_lru_first = 0;
 dcm_tab[500000 -1].lrunext = 0xFFFFFFFF;
 dcm_lru_last = 500000 -1;
 return 0;
}

variable_types:
i
unsigned int


decompiled_code:
char *strerr_init()
{
__int64 v0; // rax
int v1; // ecx
unsigned int v2; // eax
int v3; // edx
int v4; // er12
size_t v5; // rbp
char *v6; // rbx
const __m128i *v7; // r9
int v8; // er8
unsigned int v9; // edx
char *result; // rax

v0 = 1LL;
do
v1 = v0++;
while ( *(_QWORD *)(16 * v0 + 0x1438) );
v2 = (unsigned int)(3 * v1) >> 1;
errhsize = 1;
if ( (unsigned int)(3 * v1) > 1 )
{
v3 = 1;
do
{
v3 *= 2;
v2 >>= 1;
}
while ( v2 );
errhsize = v3;
}
v4 = errhsize;
v5 = 16LL * (unsigned int)errhsize;
v6 = (char *)malloc(v5);
errhash = v6;
memset(v6, 0, v5);
v7 = (const __m128i *)&errtab;
v8 = v4 - 1;
do
{
v9 = v8 & (1905886897 * v7->m128i_i32[0]);
result = &v6[16 * v9];
if ( *((_QWORD *)result + 1) )
{
while ( v7->m128i_i32[0] != *(_DWORD *)result )
{
v9 = v8 & ((v8 & (760092119 * v7->m128i_i32[0]) | 1) + v9);
result = &v6[16 * v9];
if ( !*((_QWORD *)result + 1) )
goto LABEL_12;
}
}
else
{
LABEL_12:
*(__m128i *)result = _mm_load_si128(v7);
}
++v7;
}
while ( v7->m128i_i64[1] );
return result;
}

canonical_decompiled_code:
char *func0()
{
__int64 v0; // rax
int v1; // ecx
unsigned int v2; // eax
int v3; // edx
int v4; // er12
size_t v5; // rbp
char *v6; // rbx
const __m128i *v7; // r9
int v8; // er8
unsigned int v9; // edx
char *result; // rax

v0 = 1LL;
do
v1 = v0++;
while ( *(_QWORD *)(16 * v0 + 0x1438) );
v2 = (unsigned int)(3 * v1) >> 1;
errhsize = 1;
if ( (unsigned int)(3 * v1) > 1 )
{
v3 = 1;
do
{
v3 *= 2;
v2 >>= 1;
}
while ( v2 );
errhsize = v3;
}
v4 = errhsize;
v5 = 16LL * (unsigned int)errhsize;
v6 = (char *)malloc(v5);
errhash = v6;
memset(v6, 0, v5);
v7 = (const __m128i *)&errtab;
v8 = v4 - 1;
do
{
v9 = v8 & (1905886897 * v7->m128i_i32[0]);
result = &v6[16 * v9];
if ( *((_QWORD *)result + 1) )
{
while ( v7->m128i_i32[0] != *(_DWORD *)result )
{
v9 = v8 & ((v8 & (760092119 * v7->m128i_i32[0]) | 1) + v9);
result = &v6[16 * v9];
if ( !*((_QWORD *)result + 1) )
goto LABEL_12;
}
}
else
{
LABEL_12:
*(__m128i *)result = _mm_load_si128(v7);
}
++v7;
}
while ( v7->m128i_i64[1] );
return result;
}

original_code:
void strerr_init(void) {
 uint32_t n;
 uint32_t hash,disp;
 for (n=0 ; errtab[n].str ; n++) {}
 n = (n*3)/2;
 errhsize = 1;
 while (n>0) {
  errhsize<<=1;
  n>>=1;
 }
 errhash = malloc(sizeof(errent)*errhsize);
 memset(errhash,0,sizeof(errent)*errhsize);
 for (n=0 ; errtab[n].str ; n++) {
  hash = errtab[n].num;
  disp = ((hash * 760092119) & (errhsize-1)) | 1;
  hash = ((hash * 1905886897) & (errhsize-1));
  while (errhash[hash].str!=((void *)0) && errhash[hash].num != errtab[n].num) {
   hash+=disp;
   hash&=(errhsize-1);
  }
  if (errhash[hash].str==((void *)0)) {
   errhash[hash] = errtab[n];
  }
 }
}

canonical_original_code:
void strerr_init() {
 unsigned int n;
 unsigned int hash; unsigned int disp;
 for (n=0 ; errtab[n].str ; n++) {}
 n = (n*3)/2;
 errhsize = 1;
 while (n>0) {
  errhsize<<=1;
  n>>=1;
 }
 errhash = malloc(sizeof(errent)*errhsize);
 memset(errhash,0,sizeof(errent)*errhsize);
 for (n=0 ; errtab[n].str ; n++) {
  hash = errtab[n].num;
  disp = ((hash * 760092119) & (errhsize-1)) | 1;
  hash = ((hash * 1905886897) & (errhsize-1));
  while (errhash[hash].str!=((void *)0) && errhash[hash].num != errtab[n].num) {
   hash+=disp;
   hash&=(errhsize-1);
  }
  if (errhash[hash].str==((void *)0)) {
   errhash[hash] = errtab[n];
  }
 }
}

variable_types:
n
unsigned int

variable_types:
hash
unsigned int

variable_types:
disp
unsigned int


strerr

decompiled_code:
const char *__fastcall strerr(int a1)
{
unsigned int v1; // edx
char *v2; // rax
__int64 v3; // rcx

v1 = (errhsize - 1) & (1905886897 * a1);
v2 = (char *)errhash + 16 * v1;
v3 = *((_QWORD *)v2 + 1);
if ( !v3 )
return "Unknown error";
while ( *(_DWORD *)v2 != a1 )
{
v1 = (errhsize - 1) & (((errhsize - 1) & (760092119 * a1) | 1) + v1);
v2 = (char *)errhash + 16 * v1;
v3 = *((_QWORD *)v2 + 1);
if ( !v3 )
return "Unknown error";
}
return (const char *)v3;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
unsigned int v1; // edx
char *v2; // rax
__int64 v3; // rcx

v1 = (errhsize - 1) & (1905886897 * a1);
v2 = (char *)errhash + 16 * v1;
v3 = *((_QWORD *)v2 + 1);
if ( !v3 )
return "Unknown error";
while ( *(_DWORD *)v2 != a1 )
{
v1 = (errhsize - 1) & (((errhsize - 1) & (760092119 * a1) | 1) + v1);
v2 = (char *)errhash + 16 * v1;
v3 = *((_QWORD *)v2 + 1);
if ( !v3 )
return "Unknown error";
}
return (const char *)v3;
}

original_code:
const char* strerr(int error) {
 uint32_t hash,disp;
 hash = error;
 disp = ((hash * 760092119) & (errhsize-1)) | 1;
 hash = ((hash * 1905886897) & (errhsize-1));
 while (errhash[hash].str!=((void *)0)) {
  if (errhash[hash].num == error) {
   return errhash[hash].str;
  }
  hash+=disp;
  hash&=(errhsize-1);
 }
 return "Unknown error";
}

canonical_original_code:
char *strerr(int error) {
 unsigned int hash; unsigned int disp;
 hash = error;
 disp = ((hash * 760092119) & (errhsize-1)) | 1;
 hash = ((hash * 1905886897) & (errhsize-1));
 while (errhash[hash].str!=((void *)0)) {
  if (errhash[hash].num == error) {
   return errhash[hash].str;
  }
  hash+=disp;
  hash&=(errhsize-1);
 }
 return "Unknown error";
}

variable_types: error int

return_type: char *


decompiled_code:
void strerr_term()
{
free(errhash);
}

canonical_decompiled_code:
void func2()
{
free(errhash);
}

original_code:
void strerr_term(void) {
 free(errhash);
}

canonical_original_code:
void strerr_term() {
 free(errhash);
}


decompiled_code:
__int64 chartsdata_store()
{
return charts_store();
}

canonical_decompiled_code:
__int64 func1()
{
return charts_store();
}

original_code:
void chartsdata_store(void) {
 charts_store();
}

canonical_original_code:
void chartsdata_store() {
 charts_store();
}


decompiled_code:
__int64 chartsdata_term()
{
chartsdata_refresh();
charts_store();
return charts_term();
}

canonical_decompiled_code:
__int64 func2()
{
func0();
charts_store();
return charts_term();
}

original_code:
void chartsdata_term(void) {
 chartsdata_refresh();
 charts_store();
 charts_term();
}

canonical_original_code:
void chartsdata_term() {
 chartsdata_refresh();
 charts_store();
 charts_term();
}


decompiled_code:
__int64 chartsdata_memusage()
{
return memusage;
}

canonical_decompiled_code:
__int64 func3()
{
return memusage;
}

original_code:
uint64_t chartsdata_memusage(void) {
 return memusage;
}

canonical_original_code:
unsigned long chartsdata_memusage() {
 return memusage;
}

return_type: unsigned long


variable_types:
ptr
unsigned char **

variable_types:
val
unsigned long


decompiled_code:
__int64 __fastcall put32bit(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
**(_BYTE **)a1 = HIBYTE(a2);
*(_BYTE *)(*(_QWORD *)a1 + 1LL) = BYTE2(a2);
*(_BYTE *)(*(_QWORD *)a1 + 2LL) = BYTE1(a2);
*(_BYTE *)(*(_QWORD *)a1 + 3LL) = a2;
*(_QWORD *)a1 += 4LL;
return result;
}

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

result = a2;
**(_BYTE **)a1 = HIBYTE(a2);
*(_BYTE *)(*(_QWORD *)a1 + 1LL) = BYTE2(a2);
*(_BYTE *)(*(_QWORD *)a1 + 2LL) = BYTE1(a2);
*(_BYTE *)(*(_QWORD *)a1 + 3LL) = a2;
*(_QWORD *)a1 += 4LL;
return result;
}

canonical_original_code:
static inline void put32bit(unsigned char **ptr, unsigned int val) {
 (*ptr)[0]=((val)>>24)&0xFF;
 (*ptr)[1]=((val)>>16)&0xFF;
 (*ptr)[2]=((val)>>8)&0xFF;
 (*ptr)[3]=(val)&0xFF;
 (*ptr)+=4;
}

variable_types:
val
unsigned int


canonical_original_code:
static inline unsigned int get32bit(unsigned char **ptr) {
 unsigned int t32;
 t32=((*ptr)[3]+256U*((*ptr)[2]+256U*((*ptr)[1]+256U*(*ptr)[0])));
 (*ptr)+=4;
 return t32;
}


decompiled_code:
char *chunk_malloc()
{
char *result; // rax
void *v1; // rbx
void *v2; // rax

result = (char *)chfreehead;
if ( chfreehead )
{
chfreehead = *(_QWORD *)(chfreehead + 32);
}
else
{
v1 = cbhead;
if ( !cbhead || *(int *)((char *)&dword_C3500 + (_QWORD)cbhead) == 20000 )
{
v2 = malloc((size_t)&unk_C3510);
if ( !v2 )
{
fprintf(stderr, "out of memory: %s is NULL\n", "cb");
syslog(3, "out of memory: %s is NULL", "cb");
abort();
}
*(__int64 *)((char *)&qword_C3508 + (_QWORD)v2) = (__int64)v1;
*(int *)((char *)&dword_C3500 + (_QWORD)v2) = 0;
cbhead = v2;
}
result = (char *)cbhead + 40 * (unsigned int)(*(int *)((char *)&dword_C3500 + (_QWORD)cbhead))++;
}
return result;
}

canonical_decompiled_code:
char *func4()
{
char *result; // rax
void *v1; // rbx
void *v2; // rax

result = (char *)chfreehead;
if ( chfreehead )
{
chfreehead = *(_QWORD *)(chfreehead + 32);
}
else
{
v1 = cbhead;
if ( !cbhead || *(int *)((char *)&dword_C3500 + (_QWORD)cbhead) == 20000 )
{
v2 = malloc((size_t)&unk_C3510);
if ( !v2 )
{
fprintf(stderr, "out of memory: %s is NULL\n", "cb");
syslog(3, "out of memory: %s is NULL", "cb");
abort();
}
*(__int64 *)((char *)&qword_C3508 + (_QWORD)v2) = (__int64)v1;
*(int *)((char *)&dword_C3500 + (_QWORD)v2) = 0;
cbhead = v2;
}
result = (char *)cbhead + 40 * (unsigned int)(*(int *)((char *)&dword_C3500 + (_QWORD)cbhead))++;
}
return result;
}

original_code:
static inline chunk* chunk_malloc() {
 chunk_bucket *cb;
 chunk *ret;
 if (chfreehead) {
  ret = chfreehead;
  chfreehead = ret->next;
  return ret;
 }
 if (cbhead==((void *)0) || cbhead->firstfree==20000) {
  cb = (chunk_bucket*)malloc(sizeof(chunk_bucket));
  ((cb!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","cb"),syslog(3,"out of memory: %s is NULL","cb"),abort()));
  cb->next = cbhead;
  cb->firstfree = 0;
  cbhead = cb;
 }
 ret = (cbhead->bucket)+(cbhead->firstfree);
 cbhead->firstfree++;
 return ret;
}

canonical_original_code:
static inline struct chunk *chunk_malloc() {
 struct _chunk_bucket *cb;
 struct chunk *ret;
 if (chfreehead) {
  ret = chfreehead;
  chfreehead = ret->next;
  return ret;
 }
 if (cbhead==((void *)0) || cbhead->firstfree==20000) {
  cb = (struct _chunk_bucket *)malloc(sizeof(chunk_bucket));
  ((cb!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","cb"),syslog(3,"out of memory: %s is NULL","cb"),abort()));
  cb->next = cbhead;
  cb->firstfree = 0;
  cbhead = cb;
 }
 ret = (cbhead->bucket)+(cbhead->firstfree);
 cbhead->firstfree++;
 return ret;
}

variable_types: struct _chunk_bucket { struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned char allvalidcopies; unsigned char regularvalidcopies; unsigned int needverincrease; unsigned int interrupted; unsigned int operation; unsigned int lockedto; unsigned int fcount; struct _slist { void *ptr; unsigned char valid; unsigned int version; struct _slist *next; } *slisthead; unsigned int *ftab; struct chunk *next; } bucket[20000]; unsigned int firstfree; struct _chunk_bucket *next; } *

variable_types: struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned char allvalidcopies; unsigned char regularvalidcopies; unsigned int needverincrease; unsigned int interrupted; unsigned int operation; unsigned int lockedto; unsigned int fcount; struct _slist { void *ptr; unsigned char valid; unsigned int version; struct _slist *next; } *slisthead; unsigned int *ftab; struct chunk *next; } *

user_defined_types: struct _chunk_bucket { struct chunk bucket[20000]; unsigned int firstfree; struct _chunk_bucket *next; }

user_defined_types: struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned char allvalidcopies; unsigned char regularvalidcopies; unsigned int needverincrease; unsigned int interrupted; unsigned int operation; unsigned int lockedto; unsigned int fcount; struct _slist *slisthead; unsigned int *ftab; struct chunk *next; }


decompiled_code:
__int64 __fastcall chunk_delete_file(__int64 a1, unsigned __int8 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = chunk_find(a1);
if ( v2 )
result = chunk_delete_file_int(v2, a2);
else
result = 13LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int8 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = chunk_find(a1);
if ( v2 )
result = func6(v2, a2);
else
result = 13LL;
return result;
}

original_code:
int chunk_delete_file(uint64_t chunkid,uint8_t goal) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 return chunk_delete_file_int(c,goal);
}

canonical_original_code:
int chunk_delete_file(unsigned long chunkid, unsigned char goal) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 return chunk_delete_file_int(c,goal);
}

variable_types:
chunkid
unsigned long

variable_types:
goal
unsigned char

user_defined_types: struct _slist { void *ptr; unsigned char valid; unsigned int version; struct _slist *next; }


decompiled_code:
__int64 __fastcall chunk_add_file(__int64 a1, unsigned __int8 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = chunk_find(a1);
if ( v2 )
result = chunk_add_file_int((__int64)v2, a2);
else
result = 13LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int8 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = chunk_find(a1);
if ( v2 )
result = func5((__int64)v2, a2);
else
result = 13LL;
return result;
}

original_code:
int chunk_add_file(uint64_t chunkid,uint8_t goal) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 return chunk_add_file_int(c,goal);
}

canonical_original_code:
int chunk_add_file(unsigned long chunkid, unsigned char goal) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 return chunk_add_file_int(c,goal);
}


decompiled_code:
__int64 __fastcall chunk_unlock(__int64 a1)
{
_QWORD *v1; // rax

v1 = chunk_find(a1);
if ( !v1 )
return 13LL;
*((_DWORD *)v1 + 4) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_QWORD *v1; // rax

v1 = chunk_find(a1);
if ( !v1 )
return 13LL;
*((_DWORD *)v1 + 4) = 0;
return 0LL;
}

original_code:
int chunk_unlock(uint64_t chunkid) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->lockedto=0;
 return 0;
}

canonical_original_code:
int chunk_unlock(unsigned long chunkid) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->lockedto=0;
 return 0;
}


decompiled_code:
__int64 __fastcall chunk_set_version(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = chunk_find(a1);
if ( !v2 )
return 13LL;
*((_DWORD *)v2 + 2) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = chunk_find(a1);
if ( !v2 )
return 13LL;
*((_DWORD *)v2 + 2) = a2;
return 0LL;
}

original_code:
int chunk_set_version(uint64_t chunkid,uint32_t version) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->version = version;
 return 0;
}

canonical_original_code:
int chunk_set_version(unsigned long chunkid, unsigned int version) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->version = version;
 return 0;
}

variable_types:
version
unsigned int

variable_types: struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned int lockedto; unsigned int fcount; unsigned int *ftab; struct chunk *next; } *


decompiled_code:
__int64 __fastcall chunk_increase_version(__int64 a1)
{
_QWORD *v1; // rax

v1 = chunk_find(a1);
if ( !v1 )
return 13LL;
++*((_DWORD *)v1 + 2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
_QWORD *v1; // rax

v1 = chunk_find(a1);
if ( !v1 )
return 13LL;
++*((_DWORD *)v1 + 2);
return 0LL;
}

original_code:
int chunk_increase_version(uint64_t chunkid) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->version++;
 return 0;
}

canonical_original_code:
int chunk_increase_version(unsigned long chunkid) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->version++;
 return 0;
}

user_defined_types: struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned int lockedto; unsigned int fcount; unsigned int *ftab; struct chunk *next; }


decompiled_code:
unsigned int chunk_dump()
{
unsigned int result; // eax
unsigned int v1; // ebp
__int64 *v2; // r13
__int64 i; // rbx
__int64 v4; // r8

result = time(0LL);
v1 = result;
v2 = chunkhash;
do
{
for ( i = *v2; i; i = *(_QWORD *)(i + 32) )
{
v4 = *(unsigned int *)(i + 16);
if ( v1 > (unsigned int)v4 )
v4 = 0LL;
result = printf(
"*|i:%016lX|v:%08X|g:%u|t:%10u\n",
*(_QWORD *)i,
*(unsigned int *)(i + 8),
*(unsigned __int8 *)(i + 12),
v4);
}
++v2;
}
while ( v2 != &chfreehead );
return result;
}

canonical_decompiled_code:
unsigned int func16()
{
unsigned int result; // eax
unsigned int v1; // ebp
__int64 *v2; // r13
__int64 i; // rbx
__int64 v4; // r8

result = time(0LL);
v1 = result;
v2 = chunkhash;
do
{
for ( i = *v2; i; i = *(_QWORD *)(i + 32) )
{
v4 = *(unsigned int *)(i + 16);
if ( v1 > (unsigned int)v4 )
v4 = 0LL;
result = printf(
"*|i:%016lX|v:%08X|g:%u|t:%10u\n",
*(_QWORD *)i,
*(unsigned int *)(i + 8),
*(unsigned __int8 *)(i + 12),
v4);
}
++v2;
}
while ( v2 != &chfreehead );
return result;
}

original_code:
void chunk_dump(void) {
 chunk *c;
 uint32_t i,lockedto,now;
 now = time(((void *)0));
 for (i=0 ; i<0x100000 ; i++) {
  for (c=chunkhash[i] ; c ; c=c->next) {
   lockedto = c->lockedto;
   if (lockedto<now) {
    lockedto = 0;
   }
   printf("*|i:%016""l" "X""|v:%08""X""|g:%""u""|t:%10""u""\n",c->chunkid,c->version,c->goal,lockedto);
  }
 }
}

canonical_original_code:
void chunk_dump() {
 struct chunk *c;
 unsigned int i; unsigned int lockedto; unsigned int now;
 now = time(((void *)0));
 for (i=0 ; i<0x100000 ; i++) {
  for (c=chunkhash[i] ; c ; c=c->next) {
   lockedto = c->lockedto;
   if (lockedto<now) {
    lockedto = 0;
   }
   printf("*|i:%016""l" "X""|v:%08""X""|g:%""u""|t:%10""u""\n",c->chunkid,c->version,c->goal,lockedto);
  }
 }
}

variable_types:
lockedto
unsigned int

variable_types:
now
unsigned int


decompiled_code:
__int64 __fastcall merger_nextentry(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 result; // rax
__int64 v4; // rdx

v1 = 40LL * a1;
if ( fgets(*(char **)(heap + v1 + 16), 200000, *(FILE **)(heap + v1)) )
{
v2 = heap + v1;
result = strtoll(*(const char **)(heap + v1 + 16), (char **)(heap + v1 + 24), 10);
v4 = *(_QWORD *)(v2 + 32);
if ( v4 >= 0 && (v4 >= result || maxidhole + v4 <= result) )
{
printf("found garbage at the end of file: %s (last correct id: %lu)\n", *(const char **)(v2 + 8), v4);
result = heap;
*(_QWORD *)(heap + v1 + 32) = -1LL;
}
else
{
*(_QWORD *)(v2 + 32) = result;
}
}
else
{
result = heap;
*(_QWORD *)(heap + v1 + 32) = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 result; // rax
__int64 v4; // rdx

v1 = 40LL * a1;
if ( fgets(*(char **)(heap + v1 + 16), 200000, *(FILE **)(heap + v1)) )
{
v2 = heap + v1;
result = strtoll(*(const char **)(heap + v1 + 16), (char **)(heap + v1 + 24), 10);
v4 = *(_QWORD *)(v2 + 32);
if ( v4 >= 0 && (v4 >= result || maxidhole + v4 <= result) )
{
printf("found garbage at the end of file: %s (last correct id: %lu)\n", *(const char **)(v2 + 8), v4);
result = heap;
*(_QWORD *)(heap + v1 + 32) = -1LL;
}
else
{
*(_QWORD *)(v2 + 32) = result;
}
}
else
{
result = heap;
*(_QWORD *)(heap + v1 + 32) = -1LL;
}
return result;
}

original_code:
void merger_nextentry(uint32_t pos) {
 if (fgets(heap[pos].buff,200000,heap[pos].fd)) {
  int64_t nextid = strtoll(heap[pos].buff,&(heap[pos].ptr),10);
  if (heap[pos].nextid<0 || (nextid>heap[pos].nextid && nextid<heap[pos].nextid+maxidhole)) {
   heap[pos].nextid = nextid;
  } else {
   printf("found garbage at the end of file: %s (last correct id: %""l" "u"")\n",heap[pos].filename,heap[pos].nextid);
   heap[pos].nextid = -1L;
  }
 } else {
  heap[pos].nextid = -1L;
 }
}

canonical_original_code:
void merger_nextentry(unsigned int pos) {
 if (fgets(heap[pos].buff,200000,heap[pos].fd)) {
  long nextid = strtoll(heap[pos].buff,&(heap[pos].ptr),10);
  if (heap[pos].nextid<0 || (nextid>heap[pos].nextid && nextid<heap[pos].nextid+maxidhole)) {
   heap[pos].nextid = nextid;
  } else {
   printf("found garbage at the end of file: %s (last correct id: %""l" "u"")\n",heap[pos].filename,heap[pos].nextid);
   heap[pos].nextid = -1L;
  }
 } else {
  heap[pos].nextid = -1L;
 }
}

variable_types:
pos
unsigned int

variable_types: nextid long


decompiled_code:
void merger_delete_entry()
{
FILE *v0; // rdi
__int64 v1; // rbx
void *v2; // rdi
void *v3; // rdi

v0 = *(FILE **)(heap + 40LL * (unsigned int)heapsize);
if ( v0 )
fclose(v0);
v1 = heap + 40LL * (unsigned int)heapsize;
v2 = *(void **)(v1 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(v1 + 16);
if ( v3 )
free(v3);
}

canonical_decompiled_code:
void func3()
{
FILE *v0; // rdi
__int64 v1; // rbx
void *v2; // rdi
void *v3; // rdi

v0 = *(FILE **)(heap + 40LL * (unsigned int)heapsize);
if ( v0 )
fclose(v0);
v1 = heap + 40LL * (unsigned int)heapsize;
v2 = *(void **)(v1 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(v1 + 16);
if ( v3 )
free(v3);
}

original_code:
void merger_delete_entry(void) {
 if (heap[heapsize].fd) {
  fclose(heap[heapsize].fd);
 }
 if (heap[heapsize].filename) {
  free(heap[heapsize].filename);
 }
 if (heap[heapsize].buff) {
  free(heap[heapsize].buff);
 }
}

canonical_original_code:
void merger_delete_entry() {
 if (heap[heapsize].fd) {
  fclose(heap[heapsize].fd);
 }
 if (heap[heapsize].filename) {
  free(heap[heapsize].filename);
 }
 if (heap[heapsize].buff) {
  free(heap[heapsize].buff);
 }
}


quit

decompiled_code:
void __fastcall __noreturn quit(int a1)
{
puts("Server is shutting down");
close(sockfd);
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int a1)
{
puts("Server is shutting down");
close(sockfd);
exit(a1);
}

original_code:
void quit(int sig) {
 printf("Server is shutting down\n");
 close(sockfd);
 exit(sig);
}

variable_types: sig int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int *v5; // rax
int *v6; // rax
int *v7; // rax
int v8; // ebp
unsigned __int16 v9; // bx
char *v10; // rax
char *v11; // rax
int v12; // er12
char *v13; // rbx
char *i; // rdi
int *v15; // rax
struct tm *v16; // rsi
struct tm *v17; // rdi
__int64 j; // rcx
size_t v19; // rax
struct tm *v20; // rsi
__int64 v21; // rcx
struct tm *v22; // rdi
__int64 v23; // rax
struct tm *v24; // rsi
struct tm *v25; // rdi
__int64 k; // rcx
int *v27; // rax
int *v28; // rax
socklen_t addr_len; // [rsp+4h] [rbp-A24h] BYREF
time_t timer; // [rsp+8h] [rbp-A20h] BYREF
struct sockaddr v31; // [rsp+10h] [rbp-A18h] BYREF
struct tm tp; // [rsp+20h] [rbp-A08h] BYREF
struct stat v33; // [rsp+60h] [rbp-9C8h] BYREF
char dest[256]; // [rsp+F0h] [rbp-938h] BYREF
__int64 buf[256]; // [rsp+1F0h] [rbp-838h] BYREF
struct sockaddr addr; // [rsp+9F0h] [rbp-38h] BYREF

signal(2, (__sighandler_t)quit);
v3 = socket(2, 1, 0);
sockfd = v3;
if ( v3 >= 0 )
{
v4 = v3;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(3456);
if ( bind(v4, &addr, 0x10u) )
{
perror("Error binding");
v5 = __errno_location();
exit(*v5);
}
if ( listen(sockfd, 10) )
{
perror("Error listening");
v7 = __errno_location();
exit(*v7);
}
puts("Server is now listening for connections");
puts("Press CTRL-c to stop the server");
while ( 1 )
{
addr_len = 16;
v8 = accept(sockfd, &v31, &addr_len);
v9 = _bswap_16(*(__int16 *)v31.sa_data);
v10 = inet_ntoa(*(struct in_addr *)&v31.sa_data[2]);
printf("%s:%d connected\n", v10, v9);
if ( !fork() )
break;
if ( close(v8) < 0 )
{
perror("Error closing client connection in parent.");
v28 = __errno_location();
exit(*v28);
}
waitpid(-1, 0LL, 1);
}
if ( close(sockfd) >= 0 )
{
memset(buf, 0, sizeof(buf));
memset(dest, 0, sizeof(dest));
recv(v8, buf, 0x800uLL, 0);
printf("Client request:\n%s\n", (const char *)buf);
v11 = strtok((char *)buf, " ");
v12 = strcmp(v11, "GET");
v13 = strtok(0LL, " ");
strtok(0LL, "\r");
strtok(0LL, "\n");
strtok(0LL, "\n");
for ( i = strtok(0LL, "\n"); strlen(i) > 1; i = strtok(0LL, "\n") )
;
dest[0] = 46;
strcat(dest, v13);
file = fopen(dest, "r");
memset(buf, 0, sizeof(buf));
memset(dest, 0, sizeof(dest));
if ( file )
{
stat(dest, &v33);
strcpy((char *)buf, "HTTP/1.1 200 OK\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Date: ");
time(&timer);
v16 = gmtime(&timer);
v17 = &tp;
for ( j = 14LL; j; --j )
{
v17->tm_sec = v16->tm_sec;
v16 = (struct tm *)((char *)v16 + 4);
v17 = (struct tm *)((char *)v17 + 4);
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
strcat((char *)buf, dest);
strcpy((char *)buf + strlen((const char *)buf), "\r\n");
v19 = strlen((const char *)buf);
*(__int64 *)((char *)buf + v19) = 0x646F4D2D7473614CLL;
*(__int64 *)((char *)&buf[1] + v19) = 0x203A6465696669LL;
v20 = gmtime(&v33.st_mtim.tv_sec);
v21 = 14LL;
v22 = &tp;
while ( v21 )
{
v22->tm_sec = v20->tm_sec;
v20 = (struct tm *)((char *)v20 + 4);
v22 = (struct tm *)((char *)v22 + 4);
--v21;
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
strcat((char *)buf, dest);
strcpy((char *)buf + strlen((const char *)buf), "\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Content-Type: text/html\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Content-Length: ");
fseek(file, 0LL, 2);
v23 = ftell(file);
sprintf(dest, "%ld", v23);
fseek(file, 0LL, 0);
strcat((char *)buf, dest);
strcpy((char *)buf + strlen((const char *)buf), "\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Connection: close\r\n\r\n");
if ( !v12 )
{
fread(dest, 1uLL, v33.st_size, file);
strcat((char *)buf, dest);
}
fclose(file);
}
else
{
strcpy((char *)buf, "HTTP/1.1 404 Not Found\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Date: ");
time(&timer);
v24 = gmtime(&timer);
v25 = &tp;
for ( k = 14LL; k; --k )
{
v25->tm_sec = v24->tm_sec;
v24 = (struct tm *)((char *)v24 + 4);
v25 = (struct tm *)((char *)v25 + 4);
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
strcat((char *)buf, dest);
strcpy((char *)buf + strlen((const char *)buf), "\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Connection: close\r\n\r\n");
}
printf("Server response:\n%s\n", (const char *)buf);
send(v8, buf, 0x800uLL, 0);
if ( close(v8) >= 0 )
exit(0);
perror("Error closing client connection.");
v27 = __errno_location();
exit(*v27);
}
perror("Error closing server socket in child process serving client.");
v15 = __errno_location();
exit(*v15);
}
perror("Error creating file descriptor for socket");
v6 = __errno_location();
exit(*v6);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int *v5; // rax
int *v6; // rax
int *v7; // rax
int v8; // ebp
unsigned __int16 v9; // bx
char *v10; // rax
char *v11; // rax
int v12; // er12
char *v13; // rbx
char *i; // rdi
int *v15; // rax
struct tm *v16; // rsi
struct tm *v17; // rdi
__int64 j; // rcx
size_t v19; // rax
struct tm *v20; // rsi
__int64 v21; // rcx
struct tm *v22; // rdi
__int64 v23; // rax
struct tm *v24; // rsi
struct tm *v25; // rdi
__int64 k; // rcx
int *v27; // rax
int *v28; // rax
socklen_t addr_len; // [rsp+4h] [rbp-A24h] BYREF
time_t timer; // [rsp+8h] [rbp-A20h] BYREF
struct sockaddr v31; // [rsp+10h] [rbp-A18h] BYREF
struct tm tp; // [rsp+20h] [rbp-A08h] BYREF
struct stat v33; // [rsp+60h] [rbp-9C8h] BYREF
char dest[256]; // [rsp+F0h] [rbp-938h] BYREF
__int64 buf[256]; // [rsp+1F0h] [rbp-838h] BYREF
struct sockaddr addr; // [rsp+9F0h] [rbp-38h] BYREF

signal(2, (__sighandler_t)quit);
v3 = socket(2, 1, 0);
sockfd = v3;
if ( v3 >= 0 )
{
v4 = v3;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func8(3456);
if ( bind(v4, &addr, 0x10u) )
{
perror("Error binding");
v5 = __errno_location();
exit(*v5);
}
if ( listen(sockfd, 10) )
{
perror("Error listening");
v7 = __errno_location();
exit(*v7);
}
puts("Server is now listening for connections");
puts("Press CTRL-c to stop the server");
while ( 1 )
{
addr_len = 16;
v8 = accept(sockfd, &v31, &addr_len);
v9 = func8(*(__int16 *)v31.sa_data);
v10 = inet_ntoa(*(struct in_addr *)&v31.sa_data[2]);
printf("%s:%d connected\n", v10, v9);
if ( !fork() )
break;
if ( close(v8) < 0 )
{
perror("Error closing client connection in parent.");
v28 = __errno_location();
exit(*v28);
}
waitpid(-1, 0LL, 1);
}
if ( close(sockfd) >= 0 )
{
memset(buf, 0, sizeof(buf));
memset(dest, 0, sizeof(dest));
recv(v8, buf, 0x800uLL, 0);
printf("Client request:\n%s\n", (const char *)buf);
v11 = strtok((char *)buf, " ");
v12 = strcmp(v11, "GET");
v13 = strtok(0LL, " ");
strtok(0LL, "\r");
strtok(0LL, "\n");
strtok(0LL, "\n");
for ( i = strtok(0LL, "\n"); strlen(i) > 1; i = strtok(0LL, "\n") )
;
dest[0] = 46;
strcat(dest, v13);
file = fopen(dest, "r");
memset(buf, 0, sizeof(buf));
memset(dest, 0, sizeof(dest));
if ( file )
{
func11(dest, &v33);
strcpy((char *)buf, "HTTP/1.1 200 OK\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Date: ");
time(&timer);
v16 = gmtime(&timer);
v17 = &tp;
for ( j = 14LL; j; --j )
{
v17->tm_sec = v16->tm_sec;
v16 = (struct tm *)((char *)v16 + 4);
v17 = (struct tm *)((char *)v17 + 4);
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
strcat((char *)buf, dest);
strcpy((char *)buf + strlen((const char *)buf), "\r\n");
v19 = strlen((const char *)buf);
*(__int64 *)((char *)buf + v19) = 0x646F4D2D7473614CLL;
*(__int64 *)((char *)&buf[1] + v19) = 0x203A6465696669LL;
v20 = gmtime(&v33.st_mtim.tv_sec);
v21 = 14LL;
v22 = &tp;
while ( v21 )
{
v22->tm_sec = v20->tm_sec;
v20 = (struct tm *)((char *)v20 + 4);
v22 = (struct tm *)((char *)v22 + 4);
--v21;
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
strcat((char *)buf, dest);
strcpy((char *)buf + strlen((const char *)buf), "\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Content-Type: text/html\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Content-Length: ");
fseek(file, 0LL, 2);
v23 = ftell(file);
sprintf(dest, "%ld", v23);
fseek(file, 0LL, 0);
strcat((char *)buf, dest);
strcpy((char *)buf + strlen((const char *)buf), "\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Connection: close\r\n\r\n");
if ( !v12 )
{
fread(dest, 1uLL, v33.st_size, file);
strcat((char *)buf, dest);
}
fclose(file);
}
else
{
strcpy((char *)buf, "HTTP/1.1 404 Not Found\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Date: ");
time(&timer);
v24 = gmtime(&timer);
v25 = &tp;
for ( k = 14LL; k; --k )
{
v25->tm_sec = v24->tm_sec;
v24 = (struct tm *)((char *)v24 + 4);
v25 = (struct tm *)((char *)v25 + 4);
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
strcat((char *)buf, dest);
strcpy((char *)buf + strlen((const char *)buf), "\r\n");
strcpy((char *)buf + strlen((const char *)buf), "Connection: close\r\n\r\n");
}
printf("Server response:\n%s\n", (const char *)buf);
send(v8, buf, 0x800uLL, 0);
if ( close(v8) >= 0 )
exit(0);
perror("Error closing client connection.");
v27 = __errno_location();
exit(*v27);
}
perror("Error closing server socket in child process serving client.");
v15 = __errno_location();
exit(*v15);
}
perror("Error creating file descriptor for socket");
v6 = __errno_location();
exit(*v6);
}

original_code:
int main()
{
 signal(2, quit);
 struct sockaddr_in server;
 char buffer[2048];
 pid_t pid;
 if ((sockfd = socket(2, SOCK_STREAM, 0)) < 0)
 {
  perror("Error creating file descriptor for socket");
  exit((*__errno_location ()));
 }
 memset(&server, 0, sizeof(server));
 server.sin_family = 2;
 server.sin_port = htons(3456);
 server.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) != 0)
 {
  perror("Error binding");
  exit((*__errno_location ()));
    }
 if (listen(sockfd,10) != 0)
 {
  perror("Error listening");
  exit((*__errno_location ()));
    }
 printf("Server is now listening for connections\n");
 printf("Press CTRL-c to stop the server\n");
 while(1)
 {
  int clientfd;
  struct sockaddr_in client;
  unsigned int clientlen = sizeof(client);
  clientfd = accept(sockfd,(struct sockaddr *)&client, &clientlen);
  printf("%s:%d connected\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));
  pid = fork();
  if (pid == 0) {
   if ( close(sockfd) < 0 ) {
    perror("Error closing server socket in child process serving client.");
    exit((*__errno_location ()));
   }
   char *type;
   int req;
   char *res;
   char *version;
   char *line;
   char buf2[256];
   memset(buffer,0,2048);
   memset(buf2,0,256);
   recv(clientfd,buffer,2048,0);
   printf("Client request:\n%s\n",buffer);
   type = strtok(buffer," ");
   if(strcmp(type,"HEAD")==0)
     req = 0;
   if(strcmp(type,"GET")==0)
     req = 1;
   res = strtok(((void *)0)," ");
   version = strtok(((void *)0),"\r");
   strtok(((void *)0),"\n");
   strtok(((void *)0),"\n");
   line = strtok(((void *)0),"\n");
   while(strlen(line)>1)
    {
      line = strtok(((void *)0),"\n");
    }
   if( req==0 || req==1 )
   {
    char *directory;
    struct tm timeinfo;
    time_t rawtime;
    buf2[0] = '.';
    directory = strcat(buf2,res);
    file = fopen(directory,"r");
    memset(buffer,0,2048);
    memset(buf2,0,256);
    if(file==((void *)0))
    {
     sprintf(buffer,"HTTP/1.1 404 Not Found\r\n");
     strcat(buffer,"Date: ");
     time(&rawtime);
     timeinfo = *gmtime(&rawtime);
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Connection: close\r\n\r\n");
    }
    else {
     struct stat fstat;
     stat(directory,&fstat);
     sprintf(buffer,"HTTP/1.1 200 OK\r\n");
     strcat(buffer,"Date: ");
     time(&rawtime);
     timeinfo = *gmtime(&rawtime);
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Last-Modified: ");
     timeinfo = *gmtime(&(fstat.st_mtim.tv_sec));
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Content-Type: text/html\r\n");
     strcat(buffer,"Content-Length: ");
     fseek(file, 0L, 2);
     sprintf(buf2,"%ld",ftell(file));
     fseek(file, 0L, 0);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Connection: close\r\n\r\n");
     if(req==1)
       {
         fread(buf2,1,fstat.st_size,file);
         strcat(buffer,buf2);
       }
     fclose(file);
    }
   }
   printf("Server response:\n%s\n",buffer);
   send(clientfd, buffer, 2048, 0);
   if ( close(clientfd) < 0 ) {
    perror("Error closing client connection.");
    exit((*__errno_location ()));
   }
   exit(0);
  }
  if ( close(clientfd) < 0 ) {
   perror("Error closing client connection in parent.");
   exit((*__errno_location ()));
  }
  waitpid(-1, ((void *)0), 1);
 }
 return 0;
}

canonical_original_code:
int main()
{
 signal(2, quit);
 struct sockaddr_in server;
 char buffer[2048];
 int pid;
 if ((sockfd = socket(2, SOCK_STREAM, 0)) < 0)
 {
  perror("Error creating file descriptor for socket");
  exit((*__errno_location ()));
 }
 memset(&server, 0, sizeof(server));
 server.sin_family = 2;
 server.sin_port = htons(3456);
 server.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) != 0)
 {
  perror("Error binding");
  exit((*__errno_location ()));
    }
 if (listen(sockfd,10) != 0)
 {
  perror("Error listening");
  exit((*__errno_location ()));
    }
 printf("Server is now listening for connections\n");
 printf("Press CTRL-c to stop the server\n");
 while(1)
 {
  int clientfd;
  struct sockaddr_in client;
  unsigned int clientlen = sizeof(client);
  clientfd = accept(sockfd,(struct sockaddr *)&client, &clientlen);
  printf("%s:%d connected\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));
  pid = fork();
  if (pid == 0) {
   if ( close(sockfd) < 0 ) {
    perror("Error closing server socket in child process serving client.");
    exit((*__errno_location ()));
   }
   char *type;
   int req;
   char *res;
   char *version;
   char *line;
   char buf2[256];
   memset(buffer,0,2048);
   memset(buf2,0,256);
   recv(clientfd,buffer,2048,0);
   printf("Client request:\n%s\n",buffer);
   type = strtok(buffer," ");
   if(strcmp(type,"HEAD")==0)
     req = 0;
   if(strcmp(type,"GET")==0)
     req = 1;
   res = strtok(((void *)0)," ");
   version = strtok(((void *)0),"\r");
   strtok(((void *)0),"\n");
   strtok(((void *)0),"\n");
   line = strtok(((void *)0),"\n");
   while(strlen(line)>1)
    {
      line = strtok(((void *)0),"\n");
    }
   if( req==0 || req==1 )
   {
    char *directory;
    struct tm timeinfo;
    long rawtime;
    buf2[0] = '.';
    directory = strcat(buf2,res);
    file = fopen(directory,"r");
    memset(buffer,0,2048);
    memset(buf2,0,256);
    if(file==((void *)0))
    {
     sprintf(buffer,"HTTP/1.1 404 Not Found\r\n");
     strcat(buffer,"Date: ");
     time(&rawtime);
     timeinfo = *gmtime(&rawtime);
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Connection: close\r\n\r\n");
    }
    else {
     struct stat fstat;
     stat(directory,&fstat);
     sprintf(buffer,"HTTP/1.1 200 OK\r\n");
     strcat(buffer,"Date: ");
     time(&rawtime);
     timeinfo = *gmtime(&rawtime);
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Last-Modified: ");
     timeinfo = *gmtime(&(fstat.st_mtim.tv_sec));
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Content-Type: text/html\r\n");
     strcat(buffer,"Content-Length: ");
     fseek(file, 0L, 2);
     sprintf(buf2,"%ld",ftell(file));
     fseek(file, 0L, 0);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Connection: close\r\n\r\n");
     if(req==1)
       {
         fread(buf2,1,fstat.st_size,file);
         strcat(buffer,buf2);
       }
     fclose(file);
    }
   }
   printf("Server response:\n%s\n",buffer);
   send(clientfd, buffer, 2048, 0);
   if ( close(clientfd) < 0 ) {
    perror("Error closing client connection.");
    exit((*__errno_location ()));
   }
   exit(0);
  }
  if ( close(clientfd) < 0 ) {
   perror("Error closing client connection in parent.");
   exit((*__errno_location ()));
  }
  waitpid(-1, ((void *)0), 1);
 }
 return 0;
}

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

variable_types:
buffer
char [2048]

variable_types: pid int

variable_types: clientfd int

variable_types:
clientlen
unsigned int

variable_types:
type
char *

variable_types: req int

variable_types:
res
char *

variable_types:
version
char *

variable_types:
line
char *

variable_types:
directory
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: rawtime long

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

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

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

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


argcmpTestOptions

repo: tychon/chaospendel

decompiled_code:
__int64 __fastcall argcmpTestOptions(char *s2, char *s)
{
char *v4; // rdi
int v5; // eax
char *save_ptr; // [rsp+8h] [rbp-10h] BYREF

save_ptr = (char *)&unk_368;
while ( 1 )
{
v4 = strtok_r(s, "|", &save_ptr);
if ( !v4 )
break;
v5 = strcmp(v4, s2);
s = 0LL;
if ( !v5 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2, char *s)
{
char *v4; // rdi
int v5; // eax
char *save_ptr; // [rsp+8h] [rbp-10h] BYREF

save_ptr = (char *)&unk_368;
while ( 1 )
{
v4 = strtok_r(s, "|", &save_ptr);
if ( !v4 )
break;
v5 = strcmp(v4, s2);
s = 0LL;
if ( !v5 )
return 1LL;
}
return 0LL;
}

original_code:
int argcmpTestOptions(const char *arg, char *options) {
  char *token = "x", *saveptr = "y";
  while ( (token = strtok_r(options, "|", &saveptr)) ) {
    options = ((void *)0);
    if (strcmp(token, arg) == 0) return 1;
  }
  return 0;
}

canonical_original_code:
int argcmpTestOptions(char *arg, char *options) {
  char *token = "x"; char *saveptr = "y";
  while ( (token = strtok_r(options, "|", &saveptr)) ) {
    options = ((void *)0);
    if (strcmp(token, arg) == 0) return 1;
  }
  return 0;
}

variable_types:
arg
char *

variable_types:
options
char *

variable_types:
token
char *

variable_types:
saveptr
char *


getMicroseconds

decompiled_code:
__suseconds_t getMicroseconds()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func1()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
long long getMicroseconds() {
  struct timeval tv;
  gettimeofday(&tv, ((void *)0));
  return (long long)tv.tv_sec * 1000000 + tv.tv_usec;
}

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

return_type: long long


argcmpass

decompiled_code:
__int64 __fastcall argcmpass(char *src, int a2, __int64 a3, int *a4, _QWORD *a5)
{
size_t v8; // rax
char *v9; // r15
__int64 result; // rax
int v11; // eax

v8 = strlen(src);
v9 = (char *)assert_malloc(v8 + 1);
strcpy(v9, src);
result = argcmpTestOptions(*(char **)(a3 + 8LL * *a4), v9);
if ( (_DWORD)result )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
exit(1);
}
v11 = *a4 + 1;
*a4 = v11;
if ( !strcmp("NULL", *(const char **)(a3 + 8LL * v11)) )
*a5 = 0LL;
else
*a5 = *(_QWORD *)(a3 + 8LL * v11);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int a2, __int64 a3, int *a4, _QWORD *a5)
{
size_t v8; // rax
char *v9; // r15
__int64 result; // rax
int v11; // eax

v8 = strlen(src);
v9 = (char *)assert_malloc(v8 + 1);
strcpy(v9, src);
result = func0(*(char **)(a3 + 8LL * *a4), v9);
if ( (_DWORD)result )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
exit(1);
}
v11 = *a4 + 1;
*a4 = v11;
if ( !strcmp("NULL", *(const char **)(a3 + 8LL * v11)) )
*a5 = 0LL;
else
*a5 = *(_QWORD *)(a3 + 8LL * v11);
result = 1LL;
}
return result;
}

original_code:
int argcmpass(char *options, const int argc, char *argv[], int *argindex, char **dest) {
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(argv[*argindex], opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    if (strcmp("NULL", argv[*argindex]) != 0)
      *dest = argv[*argindex];
    else *dest = ((void *)0);
    return 1;
  }
  else
    return 0;
}

canonical_original_code:
int argcmpass(char *options, int argc, char *argv[], int *argindex, char **dest) {
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(argv[*argindex], opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    if (strcmp("NULL", argv[*argindex]) != 0)
      *dest = argv[*argindex];
    else *dest = ((void *)0);
    return 1;
  }
  else
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
argindex
int *

variable_types:
dest
char **

variable_types:
opts
char *


argcmpassint

decompiled_code:
__int64 __fastcall argcmpassint(char *src, int a2, __int64 a3, int *a4, _DWORD *a5)
{
char *v8; // r15
size_t v9; // rax
char *v10; // r12
__int64 result; // rax
int v12; // eax
const char *v13; // rbx
__int64 v14; // rax
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v8 = *(char **)(a3 + 8LL * *a4);
v9 = strlen(src);
v10 = (char *)assert_malloc(v9 + 1);
strcpy(v10, src);
result = argcmpTestOptions(v8, v10);
if ( (_DWORD)result )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
exit(1);
}
v12 = *a4 + 1;
*a4 = v12;
v13 = *(const char **)(a3 + 8LL * v12);
v14 = strtol(v13, &endptr, 0);
if ( v14 < (__int64)0xFFFFFFFF80000000LL )
{
fprintf(stderr, "error: Value of option \"%s\" is too small.\n", v8);
exit(1);
}
if ( v14 == 0x7FFFFFFFFFFFFFFFLL )
{
fprintf(stderr, "error: Value of option \"%s\" is too big.\n", v8);
exit(1);
}
if ( endptr == v13 )
{
fprintf(stderr, "error: Invalid number in option \"%s\".\n", v8);
exit(1);
}
*a5 = v14;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, int a2, __int64 a3, int *a4, _DWORD *a5)
{
char *v8; // r15
size_t v9; // rax
char *v10; // r12
__int64 result; // rax
int v12; // eax
const char *v13; // rbx
__int64 v14; // rax
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v8 = *(char **)(a3 + 8LL * *a4);
v9 = strlen(src);
v10 = (char *)assert_malloc(v9 + 1);
strcpy(v10, src);
result = func0(v8, v10);
if ( (_DWORD)result )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
exit(1);
}
v12 = *a4 + 1;
*a4 = v12;
v13 = *(const char **)(a3 + 8LL * v12);
v14 = strtol(v13, &endptr, 0);
if ( v14 < (__int64)0xFFFFFFFF80000000LL )
{
fprintf(stderr, "error: Value of option \"%s\" is too small.\n", v8);
exit(1);
}
if ( v14 == 0x7FFFFFFFFFFFFFFFLL )
{
fprintf(stderr, "error: Value of option \"%s\" is too big.\n", v8);
exit(1);
}
if ( endptr == v13 )
{
fprintf(stderr, "error: Invalid number in option \"%s\".\n", v8);
exit(1);
}
*a5 = v14;
result = 1LL;
}
return result;
}

original_code:
int argcmpassint(char *options, const int argc, char *argv[], int *argindex, int *dest) {
  char *opt = argv[*argindex];
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(opt, opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    char *endptr, *value = argv[*argindex];
    long parsed = strtol(value, &endptr, 0);
    if (parsed < (-0x7fffffff - 1)) {
      fprintf(stderr, "error: Value of option \"%s\" is too small.\n", opt);
      exit(1);
    } else if (parsed == 0x7fffffffffffffffL) {
      fprintf(stderr, "error: Value of option \"%s\" is too big.\n", opt);
      exit(1);
    } else if (value == endptr) {
      fprintf(stderr, "error: Invalid number in option \"%s\".\n", opt);
      exit(1);
    } else
      *dest = (int)parsed;
    return 1;
  }
  else
    return 0;
}

canonical_original_code:
int argcmpassint(char *options, int argc, char *argv[], int *argindex, int *dest) {
  char *opt = argv[*argindex];
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(opt, opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    char *endptr; char *value = argv[*argindex];
    long parsed = strtol(value, &endptr, 0);
    if (parsed < (-0x7fffffff - 1)) {
      fprintf(stderr, "error: Value of option \"%s\" is too small.\n", opt);
      exit(1);
    } else if (parsed == 0x7fffffffffffffffL) {
      fprintf(stderr, "error: Value of option \"%s\" is too big.\n", opt);
      exit(1);
    } else if (value == endptr) {
      fprintf(stderr, "error: Invalid number in option \"%s\".\n", opt);
      exit(1);
    } else
      *dest = (int)parsed;
    return 1;
  }
  else
    return 0;
}

variable_types:
dest
int *

variable_types:
opt
char *

variable_types:
endptr
char *

variable_types:
value
char *

variable_types: parsed long


argcmpassdouble

decompiled_code:
double __fastcall argcmpassdouble(char *src, int a2, __int64 a3, int *a4, double *a5)
{
char *v8; // r15
size_t v9; // rax
char *v10; // r12
int v11; // eax
const char *v12; // rbx
double v13; // xmm0_8
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v8 = *(char **)(a3 + 8LL * *a4);
v9 = strlen(src);
v10 = (char *)assert_malloc(v9 + 1);
strcpy(v10, src);
if ( !(unsigned int)argcmpTestOptions(v8, v10) )
return 0.0;
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
exit(1);
}
v11 = *a4 + 1;
*a4 = v11;
v12 = *(const char **)(a3 + 8LL * v11);
v13 = strtod(v12, &endptr);
if ( endptr == v12 || *endptr )
{
fprintf(stderr, "error: Invalid number in option \"%s\".\n", v8);
exit(1);
}
*a5 = v13;
return *(double *)&LC7;
}

canonical_decompiled_code:
double __fastcall func4(char *src, int a2, __int64 a3, int *a4, double *a5)
{
char *v8; // r15
size_t v9; // rax
char *v10; // r12
int v11; // eax
const char *v12; // rbx
double v13; // xmm0_8
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v8 = *(char **)(a3 + 8LL * *a4);
v9 = strlen(src);
v10 = (char *)assert_malloc(v9 + 1);
strcpy(v10, src);
if ( !(unsigned int)func0(v8, v10) )
return 0.0;
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
exit(1);
}
v11 = *a4 + 1;
*a4 = v11;
v12 = *(const char **)(a3 + 8LL * v11);
v13 = strtod(v12, &endptr);
if ( endptr == v12 || *endptr )
{
fprintf(stderr, "error: Invalid number in option \"%s\".\n", v8);
exit(1);
}
*a5 = v13;
return *(double *)&LC7;
}

original_code:
double argcmpassdouble(char *options, const int argc, char *argv[], int *argindex, double *dest) {
  char *opt = argv[*argindex];
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(opt, opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    char *endptr, *value = argv[*argindex];
    double parsed = strtod(value, &endptr);
    if (value == endptr || *endptr != '\0') {
      fprintf(stderr, "error: Invalid number in option \"%s\".\n", opt);
      exit(1);
    } else
      *dest = parsed;
    return 1;
  }
  else
    return 0;
}

canonical_original_code:
double argcmpassdouble(char *options, int argc, char *argv[], int *argindex, double *dest) {
  char *opt = argv[*argindex];
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(opt, opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    char *endptr; char *value = argv[*argindex];
    double parsed = strtod(value, &endptr);
    if (value == endptr || *endptr != '\0') {
      fprintf(stderr, "error: Invalid number in option \"%s\".\n", opt);
      exit(1);
    } else
      *dest = parsed;
    return 1;
  }
  else
    return 0;
}

variable_types:
dest
double *

variable_types: parsed double


decompiled_code:
void *__fastcall assert_calloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( a2 != 0 && a1 != 0 && !result )
_assert_fail("result != NULL || nmemb == 0 || size == 0", "memory_wrappers.c", 9u, "assert_calloc");
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( a2 != 0 && a1 != 0 && !result )
_assert_fail("result != NULL || nmemb == 0 || size == 0", "memory_wrappers.c", 9u, "assert_calloc");
return result;
}

original_code:
void *assert_calloc(size_t nmemb, size_t size) {
  void *result = calloc(nmemb, size);
  ((void) sizeof ((result != ((void *)0) || nmemb == 0 || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || nmemb == 0 || size == 0) ; else __assert_fail ("result != NULL || nmemb == 0 || size == 0", "memory_wrappers.c", 9, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

canonical_original_code:
void *assert_calloc(unsigned long nmemb, unsigned long size) {
  void *result = calloc(nmemb, size);
  ((void) sizeof ((result != ((void *)0) || nmemb == 0 || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || nmemb == 0 || size == 0) ; else __assert_fail ("result != NULL || nmemb == 0 || size == 0", "memory_wrappers.c", 9, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

variable_types:
result
void *


decompiled_code:
void *__fastcall assert_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a1 )
_assert_fail("result != NULL || size == 0", "memory_wrappers.c", 0xFu, "assert_malloc");
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a1 )
_assert_fail("result != NULL || size == 0", "memory_wrappers.c", 0xFu, "assert_malloc");
}
return result;
}

original_code:
void *assert_malloc(size_t size) {
  void *result = malloc(size);
  ((void) sizeof ((result != ((void *)0) || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || size == 0) ; else __assert_fail ("result != NULL || size == 0", "memory_wrappers.c", 15, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

canonical_original_code:
void *assert_malloc(unsigned long size) {
  void *result = malloc(size);
  ((void) sizeof ((result != ((void *)0) || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || size == 0) ; else __assert_fail ("result != NULL || size == 0", "memory_wrappers.c", 15, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}


decompiled_code:
void *__fastcall assert_realloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
if ( a2 )
_assert_fail("result != NULL || size == 0", "memory_wrappers.c", 0x15u, "assert_realloc");
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
if ( a2 )
_assert_fail("result != NULL || size == 0", "memory_wrappers.c", 0x15u, "assert_realloc");
}
return result;
}

original_code:
void *assert_realloc(void *ptr, size_t size) {
  void *result = realloc(ptr, size);
  ((void) sizeof ((result != ((void *)0) || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || size == 0) ; else __assert_fail ("result != NULL || size == 0", "memory_wrappers.c", 21, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

canonical_original_code:
void *assert_realloc(void *ptr, unsigned long size) {
  void *result = realloc(ptr, size);
  ((void) sizeof ((result != ((void *)0) || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || size == 0) ; else __assert_fail ("result != NULL || size == 0", "memory_wrappers.c", 21, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

variable_types:
ptr
void *


repo: tyler-cromwell/Strutil

original_code:
char * strutil_lcs(char *str1, char *str2) {
    size_t m = strlen(str1);
    size_t n = strlen(str2);
    size_t l = 0;
    char *B = calloc(m * n, sizeof(char));
    char *C = calloc(m * n, sizeof(char));
    char *lcs = ((void *)0);
    for (size_t i = 1; i < m; i++) {
        for (size_t j = 1; j < n; j++) {
            if (str1[i] == str2[j]) {
                C[i*n+j] = C[(i-1)*n+(j-1)] + 1;
                B[i*n+j] = DIAGONAL;
            }
            else if (C[(i-1)*n+j] >= C[i*n+(j-1)]) {
                C[i*n+j] = C[(i-1)*n+j];
                B[i*n+j] = UP;
            }
            else {
                C[i*n+j] = C[i*n+(j-1)];
                B[i*n+j] = LEFT;
            }
        }
    }
    size_t i = m-1;
    size_t j = n-1;
    while (i != 0 && j != 0) {
        if (B[i*n+j] == DIAGONAL) {
            i--;
            j--;
            lcs = realloc(lcs, (l+1) * sizeof(char));
            lcs[l++] = str1[i+1];
        }
        else if (B[i*n+j] == UP) {
            i--;
        }
        else {
            j--;
        }
    }
    lcs = realloc(lcs, (l+1) * sizeof(char));
    lcs[l] = '\0';
    char *result = strutil_reverse(lcs);
    free(B);
    free(C);
    free(lcs);
    return result;
}

canonical_original_code:
char *strutil_lcs(char *str1, char *str2) {
    unsigned long m = strlen(str1);
    unsigned long n = strlen(str2);
    unsigned long l = 0;
    char *B = calloc(m * n, sizeof(char));
    char *C = calloc(m * n, sizeof(char));
    char *lcs = ((void *)0);
    for (unsigned long i = 1; i < m; i++) {
        for (unsigned long j = 1; j < n; j++) {
            if (str1[i] == str2[j]) {
                C[i*n+j] = C[(i-1)*n+(j-1)] + 1;
                B[i*n+j] = DIAGONAL;
            }
            else if (C[(i-1)*n+j] >= C[i*n+(j-1)]) {
                C[i*n+j] = C[(i-1)*n+j];
                B[i*n+j] = UP;
            }
            else {
                C[i*n+j] = C[i*n+(j-1)];
                B[i*n+j] = LEFT;
            }
        }
    }
    unsigned long i = m-1;
    unsigned long j = n-1;
    while (i != 0 && j != 0) {
        if (B[i*n+j] == DIAGONAL) {
            i--;
            j--;
            lcs = realloc(lcs, (l+1) * sizeof(char));
            lcs[l++] = str1[i+1];
        }
        else if (B[i*n+j] == UP) {
            i--;
        }
        else {
            j--;
        }
    }
    lcs = realloc(lcs, (l+1) * sizeof(char));
    lcs[l] = '\0';
    char *result = strutil_reverse(lcs);
    free(B);
    free(C);
    free(lcs);
    return result;
}

variable_types:
m
unsigned long

variable_types:
n
unsigned long

variable_types:
l
unsigned long

variable_types:
B
char *

variable_types:
C
char *

variable_types:
lcs
char *

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
result
char *