decompiled_code:
_BOOL8 __fastcall changelog_checkname(const char *a1)
{
bool v2; // zf
_BOOL8 result; // rax
const char *v4; // rsi
char v5; // al
char v6; // al
char v7; // al

v2 = memcmp(a1, "changelog.", 0xAuLL) == 0;
result = !v2;
if ( v2 )
{
if ( (unsigned __int8)(a1[10] - 48) <= 9u )
{
v4 = a1 + 10;
do
v5 = *++v4;
while ( (unsigned __int8)(v5 - 48) <= 9u );
return strcmp(v4, ".mfs") == 0;
}
}
else
{
v2 = memcmp(a1, "changelog_ml.", 0xDuLL) == 0;
result = !v2;
if ( v2 )
{
if ( (unsigned __int8)(a1[13] - 48) <= 9u )
{
v4 = a1 + 13;
do
v6 = *++v4;
while ( (unsigned __int8)(v6 - 48) <= 9u );
return strcmp(v4, ".mfs") == 0;
}
}
else
{
v2 = memcmp(a1, "changelog_ml_back.", 0x12uLL) == 0;
result = !v2;
if ( v2 )
{
if ( (unsigned __int8)(a1[18] - 48) <= 9u )
{
v4 = a1 + 18;
do
v7 = *++v4;
while ( (unsigned __int8)(v7 - 48) <= 9u );
return strcmp(v4, ".mfs") == 0;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1)
{
bool v2; // zf
_BOOL8 result; // rax
const char *v4; // rsi
char v5; // al
char v6; // al
char v7; // al

v2 = memcmp(a1, "changelog.", 0xAuLL) == 0;
result = !v2;
if ( v2 )
{
if ( (unsigned __int8)(a1[10] - 48) <= 9u )
{
v4 = a1 + 10;
do
v5 = *++v4;
while ( (unsigned __int8)(v5 - 48) <= 9u );
return strcmp(v4, ".mfs") == 0;
}
}
else
{
v2 = memcmp(a1, "changelog_ml.", 0xDuLL) == 0;
result = !v2;
if ( v2 )
{
if ( (unsigned __int8)(a1[13] - 48) <= 9u )
{
v4 = a1 + 13;
do
v6 = *++v4;
while ( (unsigned __int8)(v6 - 48) <= 9u );
return strcmp(v4, ".mfs") == 0;
}
}
else
{
v2 = memcmp(a1, "changelog_ml_back.", 0x12uLL) == 0;
result = !v2;
if ( v2 )
{
if ( (unsigned __int8)(a1[18] - 48) <= 9u )
{
v4 = a1 + 18;
do
v7 = *++v4;
while ( (unsigned __int8)(v7 - 48) <= 9u );
return strcmp(v4, ".mfs") == 0;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
int changelog_checkname(const char *fname) {
 const char *ptr = fname;
 if (strncmp(ptr,"changelog.",10)==0) {
  ptr+=10;
  if (*ptr>='0' && *ptr<='9') {
   while (*ptr>='0' && *ptr<='9') {
    ptr++;
   }
   if (strcmp(ptr,".mfs")==0) {
    return 1;
   }
  }
 } else if (strncmp(ptr,"changelog_ml.",13)==0) {
  ptr+=13;
  if (*ptr>='0' && *ptr<='9') {
   while (*ptr>='0' && *ptr<='9') {
    ptr++;
   }
   if (strcmp(ptr,".mfs")==0) {
    return 1;
   }
  }
 } else if (strncmp(ptr,"changelog_ml_back.",18)==0) {
  ptr+=18;
  if (*ptr>='0' && *ptr<='9') {
   while (*ptr>='0' && *ptr<='9') {
    ptr++;
   }
   if (strcmp(ptr,".mfs")==0) {
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int changelog_checkname(char *fname) {
 char *ptr = fname;
 if (strncmp(ptr,"changelog.",10)==0) {
  ptr+=10;
  if (*ptr>='0' && *ptr<='9') {
   while (*ptr>='0' && *ptr<='9') {
    ptr++;
   }
   if (strcmp(ptr,".mfs")==0) {
    return 1;
   }
  }
 } else if (strncmp(ptr,"changelog_ml.",13)==0) {
  ptr+=13;
  if (*ptr>='0' && *ptr<='9') {
   while (*ptr>='0' && *ptr<='9') {
    ptr++;
   }
   if (strcmp(ptr,".mfs")==0) {
    return 1;
   }
  }
 } else if (strncmp(ptr,"changelog_ml_back.",18)==0) {
  ptr+=18;
  if (*ptr>='0' && *ptr<='9') {
   while (*ptr>='0' && *ptr<='9') {
    ptr++;
   }
   if (strcmp(ptr,".mfs")==0) {
    return 1;
   }
  }
 }
 return 0;
}

variable_types:
ptr
char *


usage

repo: twonly/mfs

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(
stderr,
"restore metadata:\n"
"\t%s [-f] [-b] [-i] [-x [-x]] -m <meta data file> -o <restored meta data file> [ <change log file> [ <change "
"log file> [ .... ]]\n"
"dump metadata:\n"
"\t%s [-i] -m <meta data file>\n"
"autorestore:\n"
"\t%s [-f] [-b] [-i] [-x [-x]] -a [-d <data path>]\n"
"print version:\n"
"\t%s -v\n"
"\n"
"-x - produce more verbose output\n"
"-xx - even more verbose output\n"
"-b - if there is any error in change logs then save the best possible metadata file\n"
"-i - ignore some metadata structure errors (attach orphans to root, ignore names without inode, etc.)\n"
"-f - force loading all changelogs\n",
a1,
a1,
a1,
a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return fprintf(
stderr,
"restore metadata:\n"
"\t%s [-f] [-b] [-i] [-x [-x]] -m <meta data file> -o <restored meta data file> [ <change log file> [ <change "
"log file> [ .... ]]\n"
"dump metadata:\n"
"\t%s [-i] -m <meta data file>\n"
"autorestore:\n"
"\t%s [-f] [-b] [-i] [-x [-x]] -a [-d <data path>]\n"
"print version:\n"
"\t%s -v\n"
"\n"
"-x - produce more verbose output\n"
"-xx - even more verbose output\n"
"-b - if there is any error in change logs then save the best possible metadata file\n"
"-i - ignore some metadata structure errors (attach orphans to root, ignore names without inode, etc.)\n"
"-f - force loading all changelogs\n",
a1,
a1,
a1,
a1);
}

original_code:
void usage(const char* appname) {
 fprintf(stderr,"restore metadata:\n\t%s [-f] [-b] [-i] [-x [-x]] -m <meta data file> -o <restored meta data file> [ <change log file> [ <change log file> [ .... ]]\ndump metadata:\n\t%s [-i] -m <meta data file>\nautorestore:\n\t%s [-f] [-b] [-i] [-x [-x]] -a [-d <data path>]\nprint version:\n\t%s -v\n\n-x - produce more verbose output\n-xx - even more verbose output\n-b - if there is any error in change logs then save the best possible metadata file\n-i - ignore some metadata structure errors (attach orphans to root, ignore names without inode, etc.)\n-f - force loading all changelogs\n",appname,appname,appname,appname);
}

canonical_original_code:
void usage(char *appname) {
 fprintf(stderr,"restore metadata:\n\t%s [-f] [-b] [-i] [-x [-x]] -m <meta data file> -o <restored meta data file> [ <change log file> [ <change log file> [ .... ]]\ndump metadata:\n\t%s [-i] -m <meta data file>\nautorestore:\n\t%s [-f] [-b] [-i] [-x [-x]] -a [-d <data path>]\nprint version:\n\t%s -v\n\n-x - produce more verbose output\n-xx - even more verbose output\n-b - if there is any error in change logs then save the best possible metadata file\n-i - ignore some metadata structure errors (attach orphans to root, ignore names without inode, etc.)\n-f - force loading all changelogs\n",appname,appname,appname,appname);
}

variable_types:
appname
char *

return_type: void


decompiled_code:
__int64 __fastcall symlink_cache_stats_inc(unsigned __int8 a1)
{
stats_lock();
++*(_QWORD *)statsptr[a1];
return stats_unlock();
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
stats_lock();
++*(_QWORD *)statsptr[a1];
return stats_unlock();
}

original_code:
static inline void symlink_cache_stats_inc(uint8_t id) {
 if (id<STATNODES) {
  stats_lock();
  (*statsptr[id])++;
  stats_unlock();
 }
}

canonical_original_code:
static inline void symlink_cache_stats_inc(unsigned char id) {
 if (id<STATNODES) {
  stats_lock();
  (*statsptr[id])++;
  stats_unlock();
 }
}

variable_types:
id
unsigned char


decompiled_code:
__int64 symlink_cache_statsptr_init()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

v0 = stats_get_subnode(0LL, "symlink_cache", 0LL);
v1 = stats_get_subnode(v0, "inserts", 0LL);
statsptr[0] = stats_get_counterptr(v1);
v2 = stats_get_subnode(v0, "search_hits", 0LL);
qword_468 = stats_get_counterptr(v2);
v3 = stats_get_subnode(v0, "search_misses", 0LL);
qword_470 = stats_get_counterptr(v3);
v4 = stats_get_subnode(v0, "#links", 1LL);
result = stats_get_counterptr(v4);
qword_478 = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

v0 = stats_get_subnode(0LL, "symlink_cache", 0LL);
v1 = stats_get_subnode(v0, "inserts", 0LL);
statsptr[0] = stats_get_counterptr(v1);
v2 = stats_get_subnode(v0, "search_hits", 0LL);
qword_468 = stats_get_counterptr(v2);
v3 = stats_get_subnode(v0, "search_misses", 0LL);
qword_470 = stats_get_counterptr(v3);
v4 = stats_get_subnode(v0, "#links", 1LL);
result = stats_get_counterptr(v4);
qword_478 = result;
return result;
}

original_code:
static inline void symlink_cache_statsptr_init(void) {
 void *s;
 s = stats_get_subnode(((void *)0),"symlink_cache",0);
 statsptr[INSERTS] = stats_get_counterptr(stats_get_subnode(s,"inserts",0));
 statsptr[SEARCH_HITS] = stats_get_counterptr(stats_get_subnode(s,"search_hits",0));
 statsptr[SEARCH_MISSES] = stats_get_counterptr(stats_get_subnode(s,"search_misses",0));
 statsptr[LINKS] = stats_get_counterptr(stats_get_subnode(s,"#links",1));
}

canonical_original_code:
static inline void symlink_cache_statsptr_init() {
 void *s;
 s = stats_get_subnode(((void *)0),"symlink_cache",0);
 statsptr[INSERTS] = stats_get_counterptr(stats_get_subnode(s,"inserts",0));
 statsptr[SEARCH_HITS] = stats_get_counterptr(stats_get_subnode(s,"search_hits",0));
 statsptr[SEARCH_MISSES] = stats_get_counterptr(stats_get_subnode(s,"search_misses",0));
 statsptr[LINKS] = stats_get_counterptr(stats_get_subnode(s,"#links",1));
}

variable_types:
s
void *


original_code:
void symlink_cache_insert(uint32_t inode,const uint8_t *path) {
 uint32_t primes[4] = {1072573589U,3465827623U,2848548977U,748191707U};
 hashbucket *hb,*fhb;
 uint8_t h,i,fi;
 uint32_t now;
 uint32_t mints;
 now = time(((void *)0));
 mints = (4294967295U);
 fi = 0;
 fhb = ((void *)0);
 symlink_cache_stats_inc(INSERTS);
 pthread_mutex_lock(&slcachelock);
 for (h=0 ; h<4 ; h++) {
  hb = symlinkhash + ((inode*primes[h])%6257);
  for (i=0 ; i<16 ; i++) {
   if (hb->inode[i]==inode) {
    if (hb->path[i]) {
     free(hb->path[i]);
    }
    hb->path[i]=(uint8_t*)strdup((const char *)path);
    hb->time[i]=now;
    pthread_mutex_unlock(&slcachelock);
    return;
   }
   if (hb->time[i]<mints) {
    fhb = hb;
    fi = i;
    mints = hb->time[i];
   }
  }
 }
 if (fhb) {
  if (fhb->time[fi]==0) {
   symlink_cache_stats_inc(LINKS);
  }
  if (fhb->path[fi]) {
   free(fhb->path[fi]);
  }
  fhb->inode[fi]=inode;
  fhb->path[fi]=(uint8_t*)strdup((const char *)path);
  fhb->time[fi]=now;
 }
 pthread_mutex_unlock(&slcachelock);
}

canonical_original_code:
void symlink_cache_insert(unsigned int inode, unsigned char *path) {
 unsigned int primes[4] = {1072573589U,3465827623U,2848548977U,748191707U};
 struct _hashbucket *hb; struct _hashbucket *fhb;
 unsigned char h; unsigned char i; unsigned char fi;
 unsigned int now;
 unsigned int mints;
 now = time(((void *)0));
 mints = (4294967295U);
 fi = 0;
 fhb = ((void *)0);
 symlink_cache_stats_inc(INSERTS);
 pthread_mutex_lock(&slcachelock);
 for (h=0 ; h<4 ; h++) {
  hb = symlinkhash + ((inode*primes[h])%6257);
  for (i=0 ; i<16 ; i++) {
   if (hb->inode[i]==inode) {
    if (hb->path[i]) {
     free(hb->path[i]);
    }
    hb->path[i]=(unsigned char *)strdup((char *)path);
    hb->time[i]=now;
    pthread_mutex_unlock(&slcachelock);
    return;
   }
   if (hb->time[i]<mints) {
    fhb = hb;
    fi = i;
    mints = hb->time[i];
   }
  }
 }
 if (fhb) {
  if (fhb->time[fi]==0) {
   symlink_cache_stats_inc(LINKS);
  }
  if (fhb->path[fi]) {
   free(fhb->path[fi]);
  }
  fhb->inode[fi]=inode;
  fhb->path[fi]=(unsigned char *)strdup((char *)path);
  fhb->time[fi]=now;
 }
 pthread_mutex_unlock(&slcachelock);
}

variable_types:
inode
unsigned int

variable_types:
path
unsigned char *

variable_types:
primes
unsigned int [4]

variable_types: struct _hashbucket { unsigned int inode[16]; unsigned int time[16]; unsigned char *path[16]; } *

variable_types:
h
unsigned char

variable_types:
i
unsigned char

variable_types:
fi
unsigned char

variable_types:
now
unsigned int

variable_types:
mints
unsigned int


decompiled_code:
__int64 __fastcall symlink_cache_search(int a1, _QWORD *a2)
{
int v3; // ebx
unsigned int v4; // ebp
void *v5; // rsi
char *v6; // rcx
__int64 v7; // rax
char *v8; // rbx
char *v9; // r14
__int64 v10; // r13
void *v11; // rdi
__int64 result; // rax
__int64 v13[2]; // [rsp+0h] [rbp-38h] BYREF
char v14; // [rsp+10h] [rbp-28h] BYREF

v3 = 1072573589;
v13[0] = 0xCE9455273FEE2C95LL;
v13[1] = 0x2C987FDBA9C96871LL;
v4 = time(0LL);
pthread_mutex_lock(&slcachelock);
v5 = symlinkhash;
v6 = (char *)v13;
while ( 2 )
{
v7 = 0LL;
v8 = (char *)symlinkhash + 256 * (unsigned __int64)(a1 * v3 % 0x1871u);
do
{
if ( *(_DWORD *)&v8[4 * v7] == a1 )
{
v9 = &v8[4 * (int)v7];
v10 = (int)v7 + 16LL;
v11 = *(void **)&v8[8 * v10];
if ( *((_DWORD *)v9 + 16) + 86400 >= v4 )
{
*a2 = v11;
pthread_mutex_unlock(&slcachelock);
symlink_cache_stats_inc(1u);
result = 1LL;
}
else
{
if ( v11 )
{
free(v11);
*(_QWORD *)&v8[8 * v10] = 0LL;
}
*((_DWORD *)v9 + 16) = 0;
*(_DWORD *)v9 = 0;
pthread_mutex_unlock(&slcachelock);
symlink_cache_stats_dec_constprop_0(&slcachelock, v5);
symlink_cache_stats_inc(2u);
result = 0LL;
}
return result;
}
++v7;
}
while ( v7 != 16 );
v6 += 4;
if ( &v14 != v6 )
{
v3 = *(_DWORD *)v6;
continue;
}
break;
}
pthread_mutex_unlock(&slcachelock);
symlink_cache_stats_inc(2u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, _QWORD *a2)
{
int v3; // ebx
unsigned int v4; // ebp
void *v5; // rsi
char *v6; // rcx
__int64 v7; // rax
char *v8; // rbx
char *v9; // r14
__int64 v10; // r13
void *v11; // rdi
__int64 result; // rax
__int64 v13[2]; // [rsp+0h] [rbp-38h] BYREF
char v14; // [rsp+10h] [rbp-28h] BYREF

v3 = 1072573589;
v13[0] = 0xCE9455273FEE2C95LL;
v13[1] = 0x2C987FDBA9C96871LL;
v4 = time(0LL);
pthread_mutex_lock(&slcachelock);
v5 = symlinkhash;
v6 = (char *)v13;
while ( 2 )
{
v7 = 0LL;
v8 = (char *)symlinkhash + 256 * (unsigned __int64)(a1 * v3 % 0x1871u);
do
{
if ( *(_DWORD *)&v8[4 * v7] == a1 )
{
v9 = &v8[4 * (int)v7];
v10 = (int)v7 + 16LL;
v11 = *(void **)&v8[8 * v10];
if ( *((_DWORD *)v9 + 16) + 86400 >= v4 )
{
*a2 = v11;
pthread_mutex_unlock(&slcachelock);
func0(1u);
result = 1LL;
}
else
{
if ( v11 )
{
free(v11);
*(_QWORD *)&v8[8 * v10] = 0LL;
}
*((_DWORD *)v9 + 16) = 0;
*(_DWORD *)v9 = 0;
pthread_mutex_unlock(&slcachelock);
func2(&slcachelock, v5);
func0(2u);
result = 0LL;
}
return result;
}
++v7;
}
while ( v7 != 16 );
v6 += 4;
if ( &v14 != v6 )
{
v3 = *(_DWORD *)v6;
continue;
}
break;
}
pthread_mutex_unlock(&slcachelock);
func0(2u);
return 0LL;
}

original_code:
int symlink_cache_search(uint32_t inode,const uint8_t **path) {
 uint32_t primes[4] = {1072573589U,3465827623U,2848548977U,748191707U};
 hashbucket *hb;
 uint8_t h,i;
 uint32_t now;
 now = time(((void *)0));
 pthread_mutex_lock(&slcachelock);
 for (h=0 ; h<4 ; h++) {
  hb = symlinkhash + ((inode*primes[h])%6257);
  for (i=0 ; i<16 ; i++) {
   if (hb->inode[i]==inode) {
    if (hb->time[i]+86400<now) {
     if (hb->path[i]) {
      free(hb->path[i]);
      hb->path[i]=((void *)0);
     }
     hb->time[i]=0;
     hb->inode[i]=0;
     pthread_mutex_unlock(&slcachelock);
     symlink_cache_stats_dec(LINKS);
     symlink_cache_stats_inc(SEARCH_MISSES);
     return 0;
    }
    *path = hb->path[i];
    pthread_mutex_unlock(&slcachelock);
    symlink_cache_stats_inc(SEARCH_HITS);
    return 1;
   }
  }
 }
 pthread_mutex_unlock(&slcachelock);
 symlink_cache_stats_inc(SEARCH_MISSES);
 return 0;
}

canonical_original_code:
int symlink_cache_search(unsigned int inode, unsigned char **path) {
 unsigned int primes[4] = {1072573589U,3465827623U,2848548977U,748191707U};
 struct _hashbucket *hb;
 unsigned char h; unsigned char i;
 unsigned int now;
 now = time(((void *)0));
 pthread_mutex_lock(&slcachelock);
 for (h=0 ; h<4 ; h++) {
  hb = symlinkhash + ((inode*primes[h])%6257);
  for (i=0 ; i<16 ; i++) {
   if (hb->inode[i]==inode) {
    if (hb->time[i]+86400<now) {
     if (hb->path[i]) {
      free(hb->path[i]);
      hb->path[i]=((void *)0);
     }
     hb->time[i]=0;
     hb->inode[i]=0;
     pthread_mutex_unlock(&slcachelock);
     symlink_cache_stats_dec(LINKS);
     symlink_cache_stats_inc(SEARCH_MISSES);
     return 0;
    }
    *path = hb->path[i];
    pthread_mutex_unlock(&slcachelock);
    symlink_cache_stats_inc(SEARCH_HITS);
    return 1;
   }
  }
 }
 pthread_mutex_unlock(&slcachelock);
 symlink_cache_stats_inc(SEARCH_MISSES);
 return 0;
}

variable_types:
path
unsigned char **

return_type: int

user_defined_types: struct _hashbucket { unsigned int inode[16]; unsigned int time[16]; unsigned char *path[16]; }


decompiled_code:
__int64 symlink_cache_init()
{
symlinkhash = calloc(0x187100uLL, 1uLL);
return symlink_cache_statsptr_init();
}

canonical_decompiled_code:
__int64 func5()
{
symlinkhash = calloc(0x187100uLL, 1uLL);
return func1();
}

original_code:
void symlink_cache_init(void) {
 symlinkhash = malloc(sizeof(hashbucket)*6257);
 memset(symlinkhash,0,sizeof(hashbucket)*6257);
 symlink_cache_statsptr_init();
}

canonical_original_code:
void symlink_cache_init() {
 symlinkhash = malloc(sizeof(hashbucket)*6257);
 memset(symlinkhash,0,sizeof(hashbucket)*6257);
 symlink_cache_statsptr_init();
}


decompiled_code:
int symlink_cache_term()
{
void *v0; // r13
void **v1; // rbp
void **v2; // r12
void **v3; // rbx

pthread_mutex_lock(&slcachelock);
v0 = symlinkhash;
v1 = (void **)((char *)symlinkhash + 256);
v2 = (void **)((char *)symlinkhash + 1602048);
do
{
v3 = v1 - 16;
do
{
if ( *v3 )
free(*v3);
++v3;
}
while ( v1 != v3 );
v1 += 32;
}
while ( v1 != v2 );
free(v0);
return pthread_mutex_unlock(&slcachelock);
}

canonical_decompiled_code:
int func6()
{
void *v0; // r13
void **v1; // rbp
void **v2; // r12
void **v3; // rbx

pthread_mutex_lock(&slcachelock);
v0 = symlinkhash;
v1 = (void **)((char *)symlinkhash + 256);
v2 = (void **)((char *)symlinkhash + 1602048);
do
{
v3 = v1 - 16;
do
{
if ( *v3 )
free(*v3);
++v3;
}
while ( v1 != v3 );
v1 += 32;
}
while ( v1 != v2 );
free(v0);
return pthread_mutex_unlock(&slcachelock);
}

original_code:
void symlink_cache_term(void) {
 hashbucket *hb;
 uint8_t i;
 uint32_t hi;
 pthread_mutex_lock(&slcachelock);
 for (hi=0 ; hi<6257 ; hi++) {
  hb = symlinkhash + hi;
  for (i=0 ; i<16 ; i++) {
   if (hb->path[i]) {
    free(hb->path[i]);
   }
  }
 }
 free(symlinkhash);
 pthread_mutex_unlock(&slcachelock);
}

canonical_original_code:
void symlink_cache_term() {
 struct _hashbucket *hb;
 unsigned char i;
 unsigned int hi;
 pthread_mutex_lock(&slcachelock);
 for (hi=0 ; hi<6257 ; hi++) {
  hb = symlinkhash + hi;
  for (i=0 ; i<16 ; i++) {
   if (hb->path[i]) {
    free(hb->path[i]);
   }
  }
 }
 free(symlinkhash);
 pthread_mutex_unlock(&slcachelock);
}

variable_types:
hi
unsigned int


original_code:
static inline int chunkloc_compare(const uint8_t *l1,const uint8_t *l2,uint8_t s) {
 uint8_t mul1,sum1,xor1;
 uint8_t mul2,sum2,xor2;
 mul1=mul2=1;
 sum1=sum2=xor1=xor2=0;
 while (s>0) {
  s--;
  mul1*=l1[s];
  mul2*=l2[s];
  sum1+=l1[s];
  sum2+=l2[s];
  xor1^=l1[s];
  xor2^=l2[s];
 }
 return (mul1==mul2&&sum1==sum2&&xor1==xor2)?1:0;
}

canonical_original_code:
static inline int chunkloc_compare(unsigned char *l1, unsigned char *l2, unsigned char s) {
 unsigned char mul1; unsigned char sum1; unsigned char xor1;
 unsigned char mul2; unsigned char sum2; unsigned char xor2;
 mul1=mul2=1;
 sum1=sum2=xor1=xor2=0;
 while (s>0) {
  s--;
  mul1*=l1[s];
  mul2*=l2[s];
  sum1+=l1[s];
  sum2+=l2[s];
  xor1^=l1[s];
  xor2^=l2[s];
 }
 return (mul1==mul2&&sum1==sum2&&xor1==xor2)?1:0;
}

variable_types:
s
unsigned char


decompiled_code:
__int64 __fastcall chunkloc_cache_stats_inc(unsigned __int8 a1)
{
stats_lock();
++*(_QWORD *)statsptr[a1];
return stats_unlock();
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
stats_lock();
++*(_QWORD *)statsptr[a1];
return stats_unlock();
}

original_code:
static inline void chunkloc_cache_stats_inc(uint8_t id) {
 if (id<STATNODES) {
  stats_lock();
  (*statsptr[id])++;
  stats_unlock();
 }
}

canonical_original_code:
static inline void chunkloc_cache_stats_inc(unsigned char id) {
 if (id<STATNODES) {
  stats_lock();
  (*statsptr[id])++;
  stats_unlock();
 }
}


decompiled_code:
__int64 chunkloc_cache_statsptr_init()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 result; // rax

v0 = stats_get_subnode(0LL, "chunkloc_cache_test", 0LL);
v1 = stats_get_subnode(v0, "hits_correct", 0LL);
statsptr[0] = stats_get_counterptr(v1);
v2 = stats_get_subnode(v0, "hits_wrong", 0LL);
qword_6C8 = stats_get_counterptr(v2);
v3 = stats_get_subnode(v0, "misses", 0LL);
result = stats_get_counterptr(v3);
qword_6D0 = result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 result; // rax

v0 = stats_get_subnode(0LL, "chunkloc_cache_test", 0LL);
v1 = stats_get_subnode(v0, "hits_correct", 0LL);
statsptr[0] = stats_get_counterptr(v1);
v2 = stats_get_subnode(v0, "hits_wrong", 0LL);
qword_6C8 = stats_get_counterptr(v2);
v3 = stats_get_subnode(v0, "misses", 0LL);
result = stats_get_counterptr(v3);
qword_6D0 = result;
return result;
}

original_code:
static inline void chunkloc_cache_statsptr_init(void) {
 void *s;
 s = stats_get_subnode(((void *)0),"chunkloc_cache_test",0);
 statsptr[HITS_CORRECT] = stats_get_counterptr(stats_get_subnode(s,"hits_correct",0));
 statsptr[HITS_WRONG] = stats_get_counterptr(stats_get_subnode(s,"hits_wrong",0));
 statsptr[MISSES] = stats_get_counterptr(stats_get_subnode(s,"misses",0));
}

canonical_original_code:
static inline void chunkloc_cache_statsptr_init() {
 void *s;
 s = stats_get_subnode(((void *)0),"chunkloc_cache_test",0);
 statsptr[HITS_CORRECT] = stats_get_counterptr(stats_get_subnode(s,"hits_correct",0));
 statsptr[HITS_WRONG] = stats_get_counterptr(stats_get_subnode(s,"hits_wrong",0));
 statsptr[MISSES] = stats_get_counterptr(stats_get_subnode(s,"misses",0));
}


original_code:
void chunkloc_cache_insert(uint32_t inode,uint32_t pos,uint64_t chunkid,uint32_t chunkversion,uint8_t csdatasize,const uint8_t *csdata) {
 uint32_t primes[4] = {1072573589U,3465827623U,2848548977U,748191707U};
 hashbucket *hb,*fhb;
 uint8_t h,i,fi;
 uint32_t now;
 uint32_t mints;
 now = time(((void *)0));
 mints = (4294967295U);
 fi = 0;
 fhb = ((void *)0);
 pthread_mutex_lock(&clcachelock);
 for (h=0 ; h<4 ; h++) {
  hb = chunklochash + ((inode*primes[h]+pos*primes[4 -1-h])%6257);
  for (i=0 ; i<16 ; i++) {
   if (hb->inode[i]==inode && hb->pos[i]==pos) {
    if (hb->chunkid[i]!=chunkid || hb->chunkversion[i]!=chunkversion || hb->csdatasize[i]!=csdatasize || chunkloc_compare(hb->csdata[i],csdata,csdatasize)==0) {
     chunkloc_cache_stats_inc(HITS_WRONG);
    } else {
     chunkloc_cache_stats_inc(HITS_CORRECT);
    }
    if (hb->csdata[i]) {
     free(hb->csdata[i]);
    }
    hb->chunkid[i] = chunkid;
    hb->chunkversion[i] = chunkversion;
    hb->csdatasize[i] = csdatasize;
    if (csdatasize>0) {
     hb->csdata[i] = (uint8_t*)malloc(csdatasize);
     memcpy(hb->csdata[i],csdata,csdatasize);
    } else {
     hb->csdata[i] = ((void *)0);
    }
    hb->time[i]=now;
    pthread_mutex_unlock(&clcachelock);
    return;
   }
   if (hb->time[i]<mints) {
    fhb = hb;
    fi = i;
    mints = hb->time[i];
   }
  }
 }
 chunkloc_cache_stats_inc(MISSES);
 if (fhb) {
  fhb->inode[fi] = inode;
  fhb->pos[fi] = pos;
  if (fhb->csdata[fi]) {
   free(fhb->csdata[fi]);
  }
  fhb->chunkid[fi] = chunkid;
  fhb->chunkversion[fi] = chunkversion;
  fhb->csdatasize[fi] = csdatasize;
  if (csdatasize>0) {
   fhb->csdata[fi] = (uint8_t*)malloc(csdatasize);
   memcpy(fhb->csdata[fi],csdata,csdatasize);
  } else {
   fhb->csdata[fi] = ((void *)0);
  }
  fhb->time[fi]=now;
 }
 pthread_mutex_unlock(&clcachelock);
}

canonical_original_code:
void chunkloc_cache_insert(unsigned int inode, unsigned int pos, unsigned long chunkid, unsigned int chunkversion, unsigned char csdatasize, unsigned char *csdata) {
 unsigned int primes[4] = {1072573589U,3465827623U,2848548977U,748191707U};
 struct _hashbucket *hb; struct _hashbucket *fhb;
 unsigned char h; unsigned char i; unsigned char fi;
 unsigned int now;
 unsigned int mints;
 now = time(((void *)0));
 mints = (4294967295U);
 fi = 0;
 fhb = ((void *)0);
 pthread_mutex_lock(&clcachelock);
 for (h=0 ; h<4 ; h++) {
  hb = chunklochash + ((inode*primes[h]+pos*primes[4 -1-h])%6257);
  for (i=0 ; i<16 ; i++) {
   if (hb->inode[i]==inode && hb->pos[i]==pos) {
    if (hb->chunkid[i]!=chunkid || hb->chunkversion[i]!=chunkversion || hb->csdatasize[i]!=csdatasize || chunkloc_compare(hb->csdata[i],csdata,csdatasize)==0) {
     chunkloc_cache_stats_inc(HITS_WRONG);
    } else {
     chunkloc_cache_stats_inc(HITS_CORRECT);
    }
    if (hb->csdata[i]) {
     free(hb->csdata[i]);
    }
    hb->chunkid[i] = chunkid;
    hb->chunkversion[i] = chunkversion;
    hb->csdatasize[i] = csdatasize;
    if (csdatasize>0) {
     hb->csdata[i] = (unsigned char *)malloc(csdatasize);
     memcpy(hb->csdata[i],csdata,csdatasize);
    } else {
     hb->csdata[i] = ((void *)0);
    }
    hb->time[i]=now;
    pthread_mutex_unlock(&clcachelock);
    return;
   }
   if (hb->time[i]<mints) {
    fhb = hb;
    fi = i;
    mints = hb->time[i];
   }
  }
 }
 chunkloc_cache_stats_inc(MISSES);
 if (fhb) {
  fhb->inode[fi] = inode;
  fhb->pos[fi] = pos;
  if (fhb->csdata[fi]) {
   free(fhb->csdata[fi]);
  }
  fhb->chunkid[fi] = chunkid;
  fhb->chunkversion[fi] = chunkversion;
  fhb->csdatasize[fi] = csdatasize;
  if (csdatasize>0) {
   fhb->csdata[fi] = (unsigned char *)malloc(csdatasize);
   memcpy(fhb->csdata[fi],csdata,csdatasize);
  } else {
   fhb->csdata[fi] = ((void *)0);
  }
  fhb->time[fi]=now;
 }
 pthread_mutex_unlock(&clcachelock);
}

variable_types:
pos
unsigned int

variable_types:
chunkid
unsigned long

variable_types:
chunkversion
unsigned int

variable_types:
csdatasize
unsigned char

variable_types:
csdata
unsigned char *

variable_types: struct _hashbucket { unsigned int inode[16]; unsigned int pos[16]; unsigned int time[16]; unsigned long chunkid[16]; unsigned int chunkversion[16]; unsigned char csdatasize[16]; unsigned char *csdata[16]; } *


original_code:
int chunkloc_cache_search(uint32_t inode,uint32_t pos,uint64_t *chunkid,uint32_t *chunkversion,uint8_t *csdatasize,const uint8_t **csdata) {
 uint32_t primes[4] = {1072573589U,3465827623U,2848548977U,748191707U};
 hashbucket *hb;
 uint8_t h,i;
 pthread_mutex_lock(&clcachelock);
 for (h=0 ; h<4 ; h++) {
  hb = chunklochash + ((inode*primes[h]+pos*primes[4 -1-h])%6257);
  for (i=0 ; i<16 ; i++) {
   if (hb->inode[i]==inode && hb->pos[i]==pos) {
    *chunkid = hb->chunkid[i];
    *chunkversion = hb->chunkversion[i];
    *csdatasize = hb->csdatasize[i];
    *csdata = hb->csdata[i];
    pthread_mutex_unlock(&clcachelock);
    return 1;
   }
  }
 }
 pthread_mutex_unlock(&clcachelock);
 return 0;
}

canonical_original_code:
int chunkloc_cache_search(unsigned int inode, unsigned int pos, unsigned long *chunkid, unsigned int *chunkversion, unsigned char *csdatasize, unsigned char **csdata) {
 unsigned int primes[4] = {1072573589U,3465827623U,2848548977U,748191707U};
 struct _hashbucket *hb;
 unsigned char h; unsigned char i;
 pthread_mutex_lock(&clcachelock);
 for (h=0 ; h<4 ; h++) {
  hb = chunklochash + ((inode*primes[h]+pos*primes[4 -1-h])%6257);
  for (i=0 ; i<16 ; i++) {
   if (hb->inode[i]==inode && hb->pos[i]==pos) {
    *chunkid = hb->chunkid[i];
    *chunkversion = hb->chunkversion[i];
    *csdatasize = hb->csdatasize[i];
    *csdata = hb->csdata[i];
    pthread_mutex_unlock(&clcachelock);
    return 1;
   }
  }
 }
 pthread_mutex_unlock(&clcachelock);
 return 0;
}

variable_types:
inode
unsigned int

variable_types:
chunkid
unsigned long *

variable_types:
chunkversion
unsigned int *

variable_types:
csdatasize
unsigned char *

variable_types:
csdata
unsigned char **

user_defined_types: struct _hashbucket { unsigned int inode[16]; unsigned int pos[16]; unsigned int time[16]; unsigned long chunkid[16]; unsigned int chunkversion[16]; unsigned char csdatasize[16]; unsigned char *csdata[16]; }


decompiled_code:
__int64 chunkloc_cache_init()
{
chunklochash = calloc(0x326910uLL, 1uLL);
return chunkloc_cache_statsptr_init();
}

canonical_decompiled_code:
__int64 func5()
{
chunklochash = calloc(0x326910uLL, 1uLL);
return func2();
}

original_code:
void chunkloc_cache_init(void) {
 chunklochash = malloc(sizeof(hashbucket)*6257);
 memset(chunklochash,0,sizeof(hashbucket)*6257);
 chunkloc_cache_statsptr_init();
}

canonical_original_code:
void chunkloc_cache_init() {
 chunklochash = malloc(sizeof(hashbucket)*6257);
 memset(chunklochash,0,sizeof(hashbucket)*6257);
 chunkloc_cache_statsptr_init();
}


decompiled_code:
int chunkloc_cache_term()
{
void *v0; // r13
void **v1; // rbp
void **v2; // r12
void **v3; // rbx

pthread_mutex_lock(&clcachelock);
v0 = chunklochash;
v1 = (void **)((char *)chunklochash + 528);
v2 = (void **)((char *)chunklochash + 3304224);
do
{
v3 = v1 - 16;
do
{
if ( *v3 )
free(*v3);
++v3;
}
while ( v1 != v3 );
v1 += 66;
}
while ( v1 != v2 );
free(v0);
return pthread_mutex_unlock(&clcachelock);
}

canonical_decompiled_code:
int func6()
{
void *v0; // r13
void **v1; // rbp
void **v2; // r12
void **v3; // rbx

pthread_mutex_lock(&clcachelock);
v0 = chunklochash;
v1 = (void **)((char *)chunklochash + 528);
v2 = (void **)((char *)chunklochash + 3304224);
do
{
v3 = v1 - 16;
do
{
if ( *v3 )
free(*v3);
++v3;
}
while ( v1 != v3 );
v1 += 66;
}
while ( v1 != v2 );
free(v0);
return pthread_mutex_unlock(&clcachelock);
}

original_code:
void chunkloc_cache_term(void) {
 hashbucket *hb;
 uint8_t i;
 uint32_t hi;
 pthread_mutex_lock(&clcachelock);
 for (hi=0 ; hi<6257 ; hi++) {
  hb = chunklochash + hi;
  for (i=0 ; i<16 ; i++) {
   if (hb->csdata[i]) {
    free(hb->csdata[i]);
   }
  }
 }
 free(chunklochash);
 pthread_mutex_unlock(&clcachelock);
}

canonical_original_code:
void chunkloc_cache_term() {
 struct _hashbucket *hb;
 unsigned char i;
 unsigned int hi;
 pthread_mutex_lock(&clcachelock);
 for (hi=0 ; hi<6257 ; hi++) {
  hb = chunklochash + hi;
  for (i=0 ; i<16 ; i++) {
   if (hb->csdata[i]) {
    free(hb->csdata[i]);
   }
  }
 }
 free(chunklochash);
 pthread_mutex_unlock(&clcachelock);
}

variable_types:
i
unsigned char


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 func0(__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:
ptr
unsigned char **

variable_types:
val
unsigned int


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

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

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

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

original_code:
static inline void put16bit(uint8_t **ptr,uint16_t val) {
 (*ptr)[0]=((val)>>8)&0xFF;
 (*ptr)[1]=(val)&0xFF;
 (*ptr)+=2;
}

canonical_original_code:
static inline void put16bit(unsigned char **ptr, unsigned short val) {
 (*ptr)[0]=((val)>>8)&0xFF;
 (*ptr)[1]=(val)&0xFF;
 (*ptr)+=2;
}

variable_types:
val
unsigned short


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

return_type: unsigned int


decompiled_code:
void *__fastcall masterproxy_acceptor(void *a1)
{
int v1; // ebp
_DWORD *v3; // rax
void *v4; // r12
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-58h] BYREF

pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 0x100000uLL);
pthread_attr_setdetachstate(&attr, 1);
while ( !terminate )
{
v1 = tcptoaccept((unsigned int)lsock, 1000LL);
if ( v1 >= 0 )
{
v3 = malloc(4uLL);
*v3 = v1;
v4 = v3;
tcpnodelay((unsigned int)v1);
if ( pthread_create(&newthread, &attr, masterproxy_server, v4) < 0 )
{
free(v4);
tcpclose((unsigned int)v1);
}
}
}
pthread_attr_destroy(&attr);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
int v1; // ebp
_DWORD *v3; // rax
void *v4; // r12
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-58h] BYREF

pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 0x100000uLL);
pthread_attr_setdetachstate(&attr, 1);
while ( !terminate )
{
v1 = tcptoaccept((unsigned int)lsock, 1000LL);
if ( v1 >= 0 )
{
v3 = malloc(4uLL);
*v3 = v1;
v4 = v3;
tcpnodelay((unsigned int)v1);
if ( pthread_create(&newthread, &attr, masterproxy_server, v4) < 0 )
{
free(v4);
tcpclose((unsigned int)v1);
}
}
}
pthread_attr_destroy(&attr);
return 0LL;
}

original_code:
static void* masterproxy_acceptor(void *args) {
 pthread_t clientthread;
 pthread_attr_t thattr;
 int sock;
 (void)args;
 pthread_attr_init(&thattr);
 pthread_attr_setstacksize(&thattr,0x100000);
 pthread_attr_setdetachstate(&thattr,PTHREAD_CREATE_DETACHED);
 while (terminate==0) {
  sock = tcptoaccept(lsock,1000);
  if (sock>=0) {
   int *s = malloc(sizeof(int));
   *s = sock;
   tcpnodelay(sock);
   if (pthread_create(&clientthread,&thattr,masterproxy_server,s)<0) {
    free(s);
    tcpclose(sock);
   }
  }
 }
 pthread_attr_destroy(&thattr);
 return ((void *)0);
}

canonical_original_code:
static void *masterproxy_acceptor(void *args) {
 unsigned long clientthread;
 union pthread_attr_t thattr;
 int sock;
 (void)args;
 pthread_attr_init(&thattr);
 pthread_attr_setstacksize(&thattr,0x100000);
 pthread_attr_setdetachstate(&thattr,PTHREAD_CREATE_DETACHED);
 while (terminate==0) {
  sock = tcptoaccept(lsock,1000);
  if (sock>=0) {
   int *s = malloc(sizeof(int));
   *s = sock;
   tcpnodelay(sock);
   if (pthread_create(&clientthread,&thattr,masterproxy_server,s)<0) {
    free(s);
    tcpclose(sock);
   }
  }
 }
 pthread_attr_destroy(&thattr);
 return ((void *)0);
}

variable_types:
args
void *

variable_types:
clientthread
unsigned long

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

variable_types: sock int

variable_types:
s
int *

return_type: void *


original_code:
static void* masterproxy_server(void *args) {
 uint8_t header[8];
 uint8_t querybuffer[10000];
 uint8_t ansbuffer[10000];
 uint8_t *wptr;
 const uint8_t *rptr;
 int sock = *((int*)args);
 uint32_t psize,cmd,msgid,asize,acmd;
 free(args);
 for (;;) {
  if (tcptoread(sock,header,8,1000)!=8) {
   tcpclose(sock);
   return ((void *)0);
  }
  rptr = header;
  cmd = get32bit(&rptr);
  psize = get32bit(&rptr);
  if (cmd==(0 +400)) {
   if (psize!=73) {
    tcpclose(sock);
    return ((void *)0);
   }
   if (tcptoread(sock,querybuffer,psize,1000)!=(int32_t)(psize)) {
    tcpclose(sock);
    return ((void *)0);
   }
   if (memcmp(querybuffer,"DjI1GAQDULI5d2YjA26ypc3ovkhjvhciTQVx3CS4nYgtBoUcsljiVpsErJENHaw0",64)!=0) {
    tcpclose(sock);
    return ((void *)0);
   }
   if (querybuffer[64]!=4) {
    tcpclose(sock);
    return ((void *)0);
   }
   wptr = ansbuffer;
   put32bit(&wptr,(0 +401));
   put32bit(&wptr,1);
   put8bit(&wptr,0);
   if (tcptowrite(sock,ansbuffer,9,1000)!=9) {
    tcpclose(sock);
    return ((void *)0);
   }
  } else {
   if (psize<4 || psize>10000) {
    tcpclose(sock);
    return ((void *)0);
   }
   if (tcptoread(sock,querybuffer,psize,1000)!=(int32_t)(psize)) {
    tcpclose(sock);
    return ((void *)0);
   }
   rptr = querybuffer;
   msgid = get32bit(&rptr);
   asize = 10000 -12;
   if (fs_custom(cmd,querybuffer+4,psize-4,&acmd,ansbuffer+12,&asize)!=0) {
    tcpclose(sock);
    return ((void *)0);
   }
   wptr = ansbuffer;
   put32bit(&wptr,acmd);
   put32bit(&wptr,asize+4);
   put32bit(&wptr,msgid);
   if (tcptowrite(sock,ansbuffer,asize+12,1000)!=(int32_t)(asize+12)) {
    tcpclose(sock);
    return ((void *)0);
   }
  }
 }
}

canonical_original_code:
static void *masterproxy_server(void *args) {
 unsigned char header[8];
 unsigned char querybuffer[10000];
 unsigned char ansbuffer[10000];
 unsigned char *wptr;
 unsigned char *rptr;
 int sock = *((int*)args);
 unsigned int psize; unsigned int cmd; unsigned int msgid; unsigned int asize; unsigned int acmd;
 free(args);
 for (;;) {
  if (tcptoread(sock,header,8,1000)!=8) {
   tcpclose(sock);
   return ((void *)0);
  }
  rptr = header;
  cmd = get32bit(&rptr);
  psize = get32bit(&rptr);
  if (cmd==(0 +400)) {
   if (psize!=73) {
    tcpclose(sock);
    return ((void *)0);
   }
   if (tcptoread(sock,querybuffer,psize,1000)!=(int)(psize)) {
    tcpclose(sock);
    return ((void *)0);
   }
   if (memcmp(querybuffer,"DjI1GAQDULI5d2YjA26ypc3ovkhjvhciTQVx3CS4nYgtBoUcsljiVpsErJENHaw0",64)!=0) {
    tcpclose(sock);
    return ((void *)0);
   }
   if (querybuffer[64]!=4) {
    tcpclose(sock);
    return ((void *)0);
   }
   wptr = ansbuffer;
   put32bit(&wptr,(0 +401));
   put32bit(&wptr,1);
   put8bit(&wptr,0);
   if (tcptowrite(sock,ansbuffer,9,1000)!=9) {
    tcpclose(sock);
    return ((void *)0);
   }
  } else {
   if (psize<4 || psize>10000) {
    tcpclose(sock);
    return ((void *)0);
   }
   if (tcptoread(sock,querybuffer,psize,1000)!=(int)(psize)) {
    tcpclose(sock);
    return ((void *)0);
   }
   rptr = querybuffer;
   msgid = get32bit(&rptr);
   asize = 10000 -12;
   if (fs_custom(cmd,querybuffer+4,psize-4,&acmd,ansbuffer+12,&asize)!=0) {
    tcpclose(sock);
    return ((void *)0);
   }
   wptr = ansbuffer;
   put32bit(&wptr,acmd);
   put32bit(&wptr,asize+4);
   put32bit(&wptr,msgid);
   if (tcptowrite(sock,ansbuffer,asize+12,1000)!=(int)(asize+12)) {
    tcpclose(sock);
    return ((void *)0);
   }
  }
 }
}

variable_types:
header
unsigned char [8]

variable_types:
querybuffer
unsigned char [10000]

variable_types:
ansbuffer
unsigned char [10000]

variable_types:
wptr
unsigned char *

variable_types:
rptr
unsigned char *

variable_types:
psize
unsigned int

variable_types:
cmd
unsigned int

variable_types:
msgid
unsigned int

variable_types:
asize
unsigned int

variable_types:
acmd
unsigned int


decompiled_code:
__int64 __fastcall masterproxy_getlocation(__int64 a1)
{
__int64 result; // rax
__int64 v2[2]; // [rsp+0h] [rbp-18h] BYREF
unsigned __int8 *v3; // [rsp+10h] [rbp-8h] BYREF

v2[0] = a1;
v3 = (unsigned __int8 *)(a1 + 10);
result = (unsigned int)lsock;
if ( lsock >= 0 )
{
result = get32bit(&v3);
if ( (unsigned int)result > 0x10617 )
{
put32bit((__int64)v2, proxyhost);
result = put16bit((__int64)v2, (unsigned __int16)proxyport);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
__int64 v2[2]; // [rsp+0h] [rbp-18h] BYREF
unsigned __int8 *v3; // [rsp+10h] [rbp-8h] BYREF

v2[0] = a1;
v3 = (unsigned __int8 *)(a1 + 10);
result = (unsigned int)lsock;
if ( lsock >= 0 )
{
result = func2(&v3);
if ( (unsigned int)result > 0x10617 )
{
func0((__int64)v2, proxyhost);
result = func1((__int64)v2, (unsigned __int16)proxyport);
}
}
return result;
}

original_code:
void masterproxy_getlocation(uint8_t *masterinfo) {
 const uint8_t *rptr = masterinfo+10;
 if (lsock>=0 && get32bit(&rptr)>=0x00010618) {
  put32bit(&masterinfo,proxyhost);
  put16bit(&masterinfo,proxyport);
 }
}

canonical_original_code:
void masterproxy_getlocation(unsigned char *masterinfo) {
 unsigned char *rptr = masterinfo+10;
 if (lsock>=0 && get32bit(&rptr)>=0x00010618) {
  put32bit(&masterinfo,proxyhost);
  put16bit(&masterinfo,proxyport);
 }
}

variable_types:
masterinfo
unsigned char *


decompiled_code:
int masterproxy_term()
{
terminate = 1;
return pthread_join(proxythread, 0LL);
}

canonical_decompiled_code:
int func7()
{
terminate = 1;
return pthread_join(proxythread, 0LL);
}

original_code:
void masterproxy_term(void) {
 terminate=1;
 pthread_join(proxythread,((void *)0));
}

canonical_original_code:
void masterproxy_term() {
 terminate=1;
 pthread_join(proxythread,((void *)0));
}


decompiled_code:
__int64 masterproxy_init()
{
unsigned int v0; // er12
int v1; // eax
__int64 result; // rax
pthread_attr_t v3; // [rsp+0h] [rbp-48h] BYREF

v0 = -1;
v1 = tcpsocket();
lsock = v1;
if ( v1 < 0 )
return v0;
tcpnonblock((unsigned int)v1);
tcpnodelay((unsigned int)lsock);
tcpsetacceptfilter((unsigned int)lsock);
if ( (int)tcpstrlisten((unsigned int)lsock, "127.0.0.1", 0LL, 100LL) >= 0
&& (int)tcpgetmyaddr((unsigned int)lsock, &proxyhost, &proxyport) >= 0 )
{
terminate = 0;
v0 = 1;
pthread_attr_init(&v3);
pthread_attr_setstacksize(&v3, 0x100000uLL);
pthread_create(&proxythread, &v3, masterproxy_acceptor, 0LL);
pthread_attr_destroy(&v3);
return v0;
}
tcpclose((unsigned int)lsock);
result = 0xFFFFFFFFLL;
lsock = -1;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // er12
int v1; // eax
__int64 result; // rax
pthread_attr_t v3; // [rsp+0h] [rbp-48h] BYREF

v0 = -1;
v1 = tcpsocket();
lsock = v1;
if ( v1 < 0 )
return v0;
tcpnonblock((unsigned int)v1);
tcpnodelay((unsigned int)lsock);
tcpsetacceptfilter((unsigned int)lsock);
if ( (int)tcpstrlisten((unsigned int)lsock, "127.0.0.1", 0LL, 100LL) >= 0
&& (int)tcpgetmyaddr((unsigned int)lsock, &proxyhost, &proxyport) >= 0 )
{
terminate = 0;
v0 = 1;
pthread_attr_init(&v3);
pthread_attr_setstacksize(&v3, 0x100000uLL);
pthread_create(&proxythread, &v3, masterproxy_acceptor, 0LL);
pthread_attr_destroy(&v3);
return v0;
}
tcpclose((unsigned int)lsock);
result = 0xFFFFFFFFLL;
lsock = -1;
return result;
}

original_code:
int masterproxy_init(void) {
 pthread_attr_t thattr;
 lsock = tcpsocket();
 if (lsock<0) {
  return -1;
 }
 tcpnonblock(lsock);
 tcpnodelay(lsock);
 if (tcpsetacceptfilter(lsock)<0 && (*__errno_location ())!=95) {
 }
 if (tcpstrlisten(lsock,"127.0.0.1",0,100)<0) {
  tcpclose(lsock);
  lsock = -1;
  return -1;
 }
 if (tcpgetmyaddr(lsock,&proxyhost,&proxyport)<0) {
  tcpclose(lsock);
  lsock = -1;
  return -1;
 }
 terminate = 0;
 pthread_attr_init(&thattr);
 pthread_attr_setstacksize(&thattr,0x100000);
 pthread_create(&proxythread,&thattr,masterproxy_acceptor,((void *)0));
 pthread_attr_destroy(&thattr);
 return 1;
}

canonical_original_code:
int masterproxy_init() {
 union pthread_attr_t thattr;
 lsock = tcpsocket();
 if (lsock<0) {
  return -1;
 }
 tcpnonblock(lsock);
 tcpnodelay(lsock);
 if (tcpsetacceptfilter(lsock)<0 && (*__errno_location ())!=95) {
 }
 if (tcpstrlisten(lsock,"127.0.0.1",0,100)<0) {
  tcpclose(lsock);
  lsock = -1;
  return -1;
 }
 if (tcpgetmyaddr(lsock,&proxyhost,&proxyport)<0) {
  tcpclose(lsock);
  lsock = -1;
  return -1;
 }
 terminate = 0;
 pthread_attr_init(&thattr);
 pthread_attr_setstacksize(&thattr,0x100000);
 pthread_create(&proxythread,&thattr,masterproxy_acceptor,((void *)0));
 pthread_attr_destroy(&thattr);
 return 1;
}

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


decompiled_code:
void changelog_reload()
{
BackLogsNumber = cfg_getuint32("BACK_LOGS", 50LL);
if ( (unsigned int)BackLogsNumber > 0x3E8 )
{
syslog(4, "BACK_LOGS value too big !!!");
BackLogsNumber = (int)&unk_30D40;
}
}

canonical_decompiled_code:
void func0()
{
BackLogsNumber = cfg_getuint32("BACK_LOGS", 50LL);
if ( (unsigned int)BackLogsNumber > 0x3E8 )
{
syslog(4, "BACK_LOGS value too big !!!");
BackLogsNumber = (int)&unk_30D40;
}
}

original_code:
void changelog_reload(void) {
 BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
 if (BackLogsNumber>1000U) {
  syslog(4,"BACK_LOGS value too big !!!");
  BackLogsNumber = 200000U;
 }
}

canonical_original_code:
void changelog_reload() {
 BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
 if (BackLogsNumber>1000U) {
  syslog(4,"BACK_LOGS value too big !!!");
  BackLogsNumber = 200000U;
 }
}


decompiled_code:
__int64 changelog_rotate()
{
unsigned int v0; // ebx
__int64 v1; // rcx
__int64 result; // rax
char v3[112]; // [rsp+0h] [rbp-E8h] BYREF
char s[120]; // [rsp+70h] [rbp-78h] BYREF

if ( fd )
{
fclose(fd);
fd = 0LL;
}
v0 = BackLogsNumber;
if ( BackLogsNumber )
{
do
{
v1 = v0--;
snprintf(v3, 0x64uLL, "changelog.%u.mfs", v1);
snprintf(s, 0x64uLL, "changelog.%u.mfs", v0);
rename(s, v3);
}
while ( v0 );
result = matomlserv_broadcast_logrotate();
}
else
{
unlink("changelog.0.mfs");
result = matomlserv_broadcast_logrotate();
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx
__int64 v1; // rcx
__int64 result; // rax
char v3[112]; // [rsp+0h] [rbp-E8h] BYREF
char s[120]; // [rsp+70h] [rbp-78h] BYREF

if ( fd )
{
fclose(fd);
fd = 0LL;
}
v0 = BackLogsNumber;
if ( BackLogsNumber )
{
do
{
v1 = v0--;
snprintf(v3, 0x64uLL, "changelog.%u.mfs", v1);
snprintf(s, 0x64uLL, "changelog.%u.mfs", v0);
rename(s, v3);
}
while ( v0 );
result = matomlserv_broadcast_logrotate();
}
else
{
unlink("changelog.0.mfs");
result = matomlserv_broadcast_logrotate();
}
return result;
}

original_code:
void changelog_rotate() {
 char logname1[100],logname2[100];
 uint32_t i;
 if (fd) {
  fclose(fd);
  fd=((void *)0);
 }
 if (BackLogsNumber>0) {
  for (i=BackLogsNumber ; i>0 ; i--) {
   snprintf(logname1,100,"changelog.%""u"".mfs",i);
   snprintf(logname2,100,"changelog.%""u"".mfs",i-1);
   rename(logname2,logname1);
  }
 } else {
  unlink("changelog.0.mfs");
 }
 matomlserv_broadcast_logrotate();
}

canonical_original_code:
void changelog_rotate() {
 char logname1[100]; char logname2[100];
 unsigned int i;
 if (fd) {
  fclose(fd);
  fd=((void *)0);
 }
 if (BackLogsNumber>0) {
  for (i=BackLogsNumber ; i>0 ; i--) {
   snprintf(logname1,100,"changelog.%""u"".mfs",i);
   snprintf(logname2,100,"changelog.%""u"".mfs",i-1);
   rename(logname2,logname1);
  }
 } else {
  unlink("changelog.0.mfs");
 }
 matomlserv_broadcast_logrotate();
}

variable_types:
i
unsigned int


changelog

decompiled_code:
__int64 changelog(__int64 a1, const char *a2, ...)
{
unsigned int v3; // eax
void *v4; // r12
FILE *v5; // rdi
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v3 = vsnprintf(printbuff_0, (size_t)&unk_30D40, a2, arg);
LODWORD(v4) = v3 + 1;
if ( v3 > (unsigned int)&unk_30D3F )
{
byte_30FFF = 0;
v4 = &unk_30D40;
}
v5 = fd;
if ( fd
|| (fd = fopen64("changelog.0.mfs", "a"), (v5 = fd) != 0LL)
|| (syslog(5, "lost MFS change %lu: %s", a1, printbuff_0), (v5 = fd) != 0LL) )
{
fprintf(v5, "%lu: %s\n", a1, printbuff_0);
fflush(fd);
}
return matomlserv_broadcast_logstring(a1, printbuff_0, (unsigned int)v4);
}

canonical_decompiled_code:
__int64 func2(__int64 a1, const char *a2, ...)
{
unsigned int v3; // eax
void *v4; // r12
FILE *v5; // rdi
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v3 = vsnprintf(printbuff_0, (size_t)&unk_30D40, a2, arg);
LODWORD(v4) = v3 + 1;
if ( v3 > (unsigned int)&unk_30D3F )
{
byte_30FFF = 0;
v4 = &unk_30D40;
}
v5 = fd;
if ( fd
|| (fd = fopen64("changelog.0.mfs", "a"), (v5 = fd) != 0LL)
|| (syslog(5, "lost MFS change %lu: %s", a1, printbuff_0), (v5 = fd) != 0LL) )
{
fprintf(v5, "%lu: %s\n", a1, printbuff_0);
fflush(fd);
}
return matomlserv_broadcast_logstring(a1, printbuff_0, (unsigned int)v4);
}

original_code:
void changelog(uint64_t version,const char *format,...) {
 static char printbuff[200000U];
 va_list ap;
 uint32_t leng;
 __builtin_va_start(ap,format);
 leng = vsnprintf(printbuff,200000U,format,ap);
 __builtin_va_end(ap);
 if (leng>=200000U) {
  printbuff[200000U -1]='\0';
  leng=200000U;
 } else {
  leng++;
 }
 if (fd==((void *)0)) {
  fd = fopen("changelog.0.mfs","a");
  if (!fd) {
   syslog(5,"lost MFS change %""l" "u"": %s",version,printbuff);
  }
 }
 if (fd) {
  fprintf(fd,"%""l" "u"": %s\n",version,printbuff);
  fflush(fd);
 }
 matomlserv_broadcast_logstring(version,(uint8_t*)printbuff,leng);
}

canonical_original_code:
void changelog(unsigned long version, char *format, ...) {
 static char printbuff[200000];
 __builtin_va_list ap;
 unsigned int leng;
 __builtin_va_start(ap,format);
 leng = vsnprintf(printbuff,200000U,format,ap);
 __builtin_va_end(ap);
 if (leng>=200000U) {
  printbuff[200000U -1]='\0';
  leng=200000U;
 } else {
  leng++;
 }
 if (fd==((void *)0)) {
  fd = fopen("changelog.0.mfs","a");
  if (!fd) {
   syslog(5,"lost MFS change %""l" "u"": %s",version,printbuff);
  }
 }
 if (fd) {
  fprintf(fd,"%""l" "u"": %s\n",version,printbuff);
  fflush(fd);
 }
 matomlserv_broadcast_logstring(version,(unsigned char *)printbuff,leng);
}

variable_types:
version
unsigned long

variable_types:
format
char *

variable_types:
printbuff
char [200000]

variable_types:
leng
unsigned int


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

BackLogsNumber = cfg_getuint32("BACK_LOGS", 50LL);
if ( (unsigned int)BackLogsNumber > 0x3E8 )
{
fwrite("BACK_LOGS value too big !!!", 1uLL, 0x1BuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
main_reloadregister(changelog_reload);
result = 0LL;
fd = 0LL;
}
return result;
}

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

BackLogsNumber = cfg_getuint32("BACK_LOGS", 50LL);
if ( (unsigned int)BackLogsNumber > 0x3E8 )
{
fwrite("BACK_LOGS value too big !!!", 1uLL, 0x1BuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
main_reloadregister(changelog_reload);
result = 0LL;
fd = 0LL;
}
return result;
}

original_code:
int changelog_init(void) {
 BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
 if (BackLogsNumber>1000U) {
  fprintf(stderr,"BACK_LOGS value too big !!!");
  return -1;
 }
 main_reloadregister(changelog_reload);
 fd = ((void *)0);
 return 0;
}

canonical_original_code:
int changelog_init() {
 BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
 if (BackLogsNumber>1000U) {
  fprintf(stderr,"BACK_LOGS value too big !!!");
  return -1;
 }
 main_reloadregister(changelog_reload);
 fd = ((void *)0);
 return 0;
}


decompiled_code:
__int64 __fastcall cfg_load(const char *a1, int a2)
{
logundefined = a2;
paramhead = 0LL;
cfgfname = strdup(a1);
return cfg_reload();
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, int a2)
{
logundefined = a2;
paramhead = 0LL;
cfgfname = strdup(a1);
return func0();
}

original_code:
int cfg_load (const char *configfname,int _lu) {
 paramhead = ((void *)0);
 logundefined = _lu;
 cfgfname = strdup(configfname);
 return cfg_reload();
}

canonical_original_code:
int cfg_load(char *configfname, int _lu) {
 paramhead = ((void *)0);
 logundefined = _lu;
 cfgfname = strdup(configfname);
 return cfg_reload();
}

variable_types:
configfname
char *


decompiled_code:
__int64 __fastcall cfg_isdefined(char *s1)
{
const char **v1; // rbx

v1 = (const char **)paramhead;
if ( !paramhead )
return 0LL;
while ( strcmp(s1, *v1) )
{
v1 = (const char **)v1[2];
if ( !v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
const char **v1; // rbx

v1 = (const char **)paramhead;
if ( !paramhead )
return 0LL;
while ( strcmp(s1, *v1) )
{
v1 = (const char **)v1[2];
if ( !v1 )
return 0LL;
}
return 1LL;
}

original_code:
int cfg_isdefined(const char *name) {
 paramstr *_cfg_tmp;
 for (_cfg_tmp = paramhead ; _cfg_tmp ; _cfg_tmp=_cfg_tmp->next) {
  if (strcmp(name,_cfg_tmp->name)==0) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int cfg_isdefined(char *name) {
 struct paramsstr *_cfg_tmp;
 for (_cfg_tmp = paramhead ; _cfg_tmp ; _cfg_tmp=_cfg_tmp->next) {
  if (strcmp(name,_cfg_tmp->name)==0) {
   return 1;
  }
 }
 return 0;
}

variable_types:
name
char *

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


decompiled_code:
void cfg_term()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)paramhead;
if ( paramhead )
{
do
{
v1 = v0;
v0 = (void **)v0[2];
free(v1[1]);
free(*v1);
free(v1);
}
while ( v0 );
}
free(cfgfname);
}

canonical_decompiled_code:
void func3()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)paramhead;
if ( paramhead )
{
do
{
v1 = v0;
v0 = (void **)v0[2];
free(v1[1]);
free(*v1);
free(v1);
}
while ( v0 );
}
free(cfgfname);
}

original_code:
void cfg_term(void) {
 paramstr *i,*in;
 for (i = paramhead ; i ; i = in) {
  in = i->next;
  free(i->value);
  free(i->name);
  free(i);
 }
 free(cfgfname);
}

canonical_original_code:
void cfg_term() {
 struct paramsstr *i; struct paramsstr *in;
 for (i = paramhead ; i ; i = in) {
  in = i->next;
  free(i->value);
  free(i->name);
  free(i);
 }
 free(cfgfname);
}

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


decompiled_code:
char *__fastcall cfg_getstr(char *s1, char *s)
{
void *v2; // rbx
char *result; // rax

v2 = paramhead;
if ( !paramhead )
{
LABEL_7:
if ( logundefined )
{
syslog(5, "config: using default value for option '%s' - '%s'", s1, s);
fprintf(stderr, "config: using default value for option '%s' - '%s'\n", s1, s);
}
result = strdup(s);
if ( result )
return result;
LABEL_6:
fprintf(stderr, "out of memory: %s is NULL\n", "_cfg_ret_tmp");
syslog(3, "out of memory: %s is NULL", "_cfg_ret_tmp");
abort();
}
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_7;
}
result = strdup(*((const char **)v2 + 1));
if ( !result )
goto LABEL_6;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *s1, char *s)
{
void *v2; // rbx
char *result; // rax

v2 = paramhead;
if ( !paramhead )
{
LABEL_7:
if ( logundefined )
{
syslog(5, "config: using default value for option '%s' - '%s'", s1, s);
fprintf(stderr, "config: using default value for option '%s' - '%s'\n", s1, s);
}
result = strdup(s);
if ( result )
return result;
LABEL_6:
fprintf(stderr, "out of memory: %s is NULL\n", "_cfg_ret_tmp");
syslog(3, "out of memory: %s is NULL", "_cfg_ret_tmp");
abort();
}
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_7;
}
result = strdup(*((const char **)v2 + 1));
if ( !result )
goto LABEL_6;
return result;
}

original_code: char* cfg_getstr(const char *name,char* def) { paramstr *_cfg_tmp; for (_cfg_tmp = paramhead ; _cfg_tmp ; _cfg_tmp=_cfg_tmp->next) { if (strcmp(name,_cfg_tmp->name)==0) { { char* _cfg_ret_tmp = strdup(_cfg_tmp->value); ((_cfg_ret_tmp!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","_cfg_ret_tmp"),syslog(3,"out of memory: %s is NULL","_cfg_ret_tmp"),abort())); return _cfg_ret_tmp; }; } } if (logundefined) { { syslog((5),("config: using default value for option '%s' - '" "%s" "'"), name,def); fprintf(stderr,"config: using default value for option '%s' - '" "%s" "'" "\n", name,def); }; } { char* _cfg_ret_tmp = strdup(def); ((_cfg_ret_tmp!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","_cfg_ret_tmp"),syslog(3,"out of memory: %s is NULL","_cfg_ret_tmp"),abort())); return _cfg_ret_tmp; }; }

canonical_original_code: char *cfg_getstr(char *name, char *def) { struct paramsstr *_cfg_tmp; for (_cfg_tmp = paramhead ; _cfg_tmp ; _cfg_tmp=_cfg_tmp->next) { if (strcmp(name,_cfg_tmp->name)==0) { { char *_cfg_ret_tmp = strdup(_cfg_tmp->value); ((_cfg_ret_tmp!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","_cfg_ret_tmp"),syslog(3,"out of memory: %s is NULL","_cfg_ret_tmp"),abort())); return _cfg_ret_tmp; }; } } if (logundefined) { { syslog((5),("config: using default value for option '%s' - '" "%s" "'"), name,def); fprintf(stderr,"config: using default value for option '%s' - '" "%s" "'" "\n", name,def); }; } { char *_cfg_ret_tmp = strdup(def); ((_cfg_ret_tmp!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","_cfg_ret_tmp"),syslog(3,"out of memory: %s is NULL","_cfg_ret_tmp"),abort())); return _cfg_ret_tmp; }; }

variable_types:
def
char *

return_type: char *


decompiled_code:
__int64 __fastcall cfg_getnum(char *s1, unsigned int a2)
{
unsigned int v2; // er13
void *v3; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func5(char *s1, unsigned int a2)
{
unsigned int v2; // er13
void *v3; // rbx

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

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

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

variable_types: def int


decompiled_code:
__int64 __fastcall cfg_getint8(char *s1, unsigned int a2)
{
void *v2; // rbx
unsigned int v3; // er14

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

canonical_decompiled_code:
__int64 __fastcall func6(char *s1, unsigned int a2)
{
void *v2; // rbx
unsigned int v3; // er14

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

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

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

variable_types: def char

return_type: char


decompiled_code:
__int64 __fastcall cfg_getuint8(char *s1, unsigned int a2)
{
void *v2; // rbx
unsigned int v3; // er14

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_7;
}
return (unsigned int)strtoul(*((const char **)v2 + 1), 0LL, 0);
}
LABEL_7:
v3 = a2;
if ( !logundefined )
return v3;
syslog(5, "config: using default value for option '%s' - '%u'", s1, (unsigned __int8)a2);
fprintf(stderr, "config: using default value for option '%s' - '%u'\n", s1, (unsigned __int8)a2);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s1, unsigned int a2)
{
void *v2; // rbx
unsigned int v3; // er14

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_7;
}
return (unsigned int)strtoul(*((const char **)v2 + 1), 0LL, 0);
}
LABEL_7:
v3 = a2;
if ( !logundefined )
return v3;
syslog(5, "config: using default value for option '%s' - '%u'", s1, (unsigned __int8)a2);
fprintf(stderr, "config: using default value for option '%s' - '%u'\n", s1, (unsigned __int8)a2);
return a2;
}

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

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

variable_types:
def
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall cfg_getint16(char *s1, unsigned int a2)
{
void *v2; // rbx
unsigned int v3; // er14

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_7;
}
return (unsigned int)strtol(*((const char **)v2 + 1), 0LL, 0);
}
LABEL_7:
v3 = a2;
if ( !logundefined )
return v3;
syslog(5, "config: using default value for option '%s' - '%d'", s1, (unsigned int)(__int16)a2);
fprintf(stderr, "config: using default value for option '%s' - '%d'\n", s1, (unsigned int)(__int16)a2);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s1, unsigned int a2)
{
void *v2; // rbx
unsigned int v3; // er14

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_7;
}
return (unsigned int)strtol(*((const char **)v2 + 1), 0LL, 0);
}
LABEL_7:
v3 = a2;
if ( !logundefined )
return v3;
syslog(5, "config: using default value for option '%s' - '%d'", s1, (unsigned int)(__int16)a2);
fprintf(stderr, "config: using default value for option '%s' - '%d'\n", s1, (unsigned int)(__int16)a2);
return a2;
}

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

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

variable_types: def short

return_type: short


decompiled_code:
__int64 __fastcall cfg_getuint16(char *s1, unsigned int a2)
{
void *v2; // rbx
unsigned int v3; // er14

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_7;
}
return (unsigned int)strtoul(*((const char **)v2 + 1), 0LL, 0);
}
LABEL_7:
v3 = a2;
if ( !logundefined )
return v3;
syslog(5, "config: using default value for option '%s' - '%u'", s1, (unsigned __int16)a2);
fprintf(stderr, "config: using default value for option '%s' - '%u'\n", s1, (unsigned __int16)a2);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s1, unsigned int a2)
{
void *v2; // rbx
unsigned int v3; // er14

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_7;
}
return (unsigned int)strtoul(*((const char **)v2 + 1), 0LL, 0);
}
LABEL_7:
v3 = a2;
if ( !logundefined )
return v3;
syslog(5, "config: using default value for option '%s' - '%u'", s1, (unsigned __int16)a2);
fprintf(stderr, "config: using default value for option '%s' - '%u'\n", s1, (unsigned __int16)a2);
return a2;
}

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

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

variable_types:
def
unsigned short

return_type: unsigned short


decompiled_code:
// attributes: thunk
__int64 __fastcall cfg_getint32(char *s1, unsigned int a2)
{
return cfg_getnum(s1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s1, unsigned int a2)
{
return func5(s1, a2);
}

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

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


decompiled_code:
__int64 __fastcall cfg_getuint32(char *s1, unsigned int a2)
{
unsigned int v2; // er13
void *v3; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func11(char *s1, unsigned int a2)
{
unsigned int v2; // er13
void *v3; // rbx

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

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

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

variable_types:
def
unsigned int


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

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

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

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

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

canonical_original_code: long cfg_getint64(char *name, 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 strtoll(_cfg_tmp->value,((void *)0),0); } } if (logundefined) { { syslog((5),("config: using default value for option '%s' - '" "%""l" "d" "'"), name,def); fprintf(stderr,"config: using default value for option '%s' - '" "%""l" "d" "'" "\n", name,def); }; } return def; }

variable_types: def long

return_type: long


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_6;
}
result = strtoull(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_6:
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_6;
}
result = strtoull(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_6:
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

return_type: unsigned long


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

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

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

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

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: def double

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


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)
{
__int64 *v7; // rbp
unsigned int *v8; // rbx
__int64 v9; // rcx
__int64 result; // rax
__int64 v11; // rsi
__int64 v12; // rdx

v7 = a1;
v8 = (unsigned int *)*a1;
if ( !*a1 )
{
LABEL_11:
result = (__int64)malloc(0x20uLL);
*v7 = 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;
}
v9 = a2 - 1;
result = a3 + 1;
while ( 1 )
{
v11 = *v8;
if ( (unsigned int)v11 <= a3 )
break;
LABEL_9:
v7 = (__int64 *)(v8 + 4);
LABEL_10:
v8 = (unsigned int *)*v7;
if ( !*v7 )
goto LABEL_11;
}
v12 = v8[1];
if ( (unsigned int)v12 < a2 )
goto LABEL_18;
if ( (unsigned int)v11 < a2 )
{
if ( (unsigned int)v12 < a3 )
{
if ( (unsigned int)v11 <= a2 )
{
if ( (unsigned int)v12 >= a3 )
return result;
v8[1] = v9;
LABEL_18:
v7 = (__int64 *)(v8 + 6);
goto LABEL_10;
}
goto LABEL_8;
}
LABEL_7:
if ( (unsigned int)v11 <= a2 )
{
if ( (unsigned int)v11 < a2 )
{
result = itree_add(v8 + 4, v11, a2 - 1, v8[2]);
v12 = v8[1];
}
if ( a3 < (unsigned int)v12 )
result = itree_add(v8 + 6, a3 + 1, v12, v8[2]);
goto LABEL_23;
}
LABEL_8:
*v8 = result;
goto LABEL_9;
}
if ( (unsigned int)v12 > a3 )
goto LABEL_7;
if ( (unsigned int)v11 > a2 )
{
result = itree_delete(v8 + 4, a2, (unsigned int)(v11 - 1), v9);
LODWORD(v12) = v8[1];
}
if ( a3 > (unsigned int)v12 )
result = itree_delete(v8 + 6, (unsigned int)(v12 + 1), a3, v9);
LABEL_23:
*v8 = a2;
v8[1] = a3;
v8[2] = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 *v7; // rbp
unsigned int *v8; // rbx
__int64 v9; // rcx
__int64 result; // rax
__int64 v11; // rsi
__int64 v12; // rdx

v7 = a1;
v8 = (unsigned int *)*a1;
if ( !*a1 )
{
LABEL_11:
result = (__int64)malloc(0x20uLL);
*v7 = 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;
}
v9 = a2 - 1;
result = a3 + 1;
while ( 1 )
{
v11 = *v8;
if ( (unsigned int)v11 <= a3 )
break;
LABEL_9:
v7 = (__int64 *)(v8 + 4);
LABEL_10:
v8 = (unsigned int *)*v7;
if ( !*v7 )
goto LABEL_11;
}
v12 = v8[1];
if ( (unsigned int)v12 < a2 )
goto LABEL_18;
if ( (unsigned int)v11 < a2 )
{
if ( (unsigned int)v12 < a3 )
{
if ( (unsigned int)v11 <= a2 )
{
if ( (unsigned int)v12 >= a3 )
return result;
v8[1] = v9;
LABEL_18:
v7 = (__int64 *)(v8 + 6);
goto LABEL_10;
}
goto LABEL_8;
}
LABEL_7:
if ( (unsigned int)v11 <= a2 )
{
if ( (unsigned int)v11 < a2 )
{
result = func2(v8 + 4, v11, a2 - 1, v8[2]);
v12 = v8[1];
}
if ( a3 < (unsigned int)v12 )
result = func2(v8 + 6, a3 + 1, v12, v8[2]);
goto LABEL_23;
}
LABEL_8:
*v8 = result;
goto LABEL_9;
}
if ( (unsigned int)v12 > a3 )
goto LABEL_7;
if ( (unsigned int)v11 > a2 )
{
result = func3(v8 + 4, a2, (unsigned int)(v11 - 1), v9);
LODWORD(v12) = v8[1];
}
if ( a3 > (unsigned int)v12 )
result = func3(v8 + 6, (unsigned int)(v12 + 1), a3, v9);
LABEL_23:
*v8 = a2;
v8[1] = a3;
v8[2] = a4;
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; }


decompiled_code:
void __fastcall itree_delete(char **a1, unsigned int a2, unsigned int a3)
{
char *v3; // rbx
char **v4; // rbp
unsigned int v6; // edi
__int64 v8; // rcx
unsigned int v9; // edx
unsigned int v10; // esi
unsigned int v11; // er13
unsigned int v12; // ecx
unsigned int v13; // er12

v3 = *a1;
if ( !*a1 )
return;
v4 = a1;
v6 = a2 - 1;
v8 = a3 + 1;
while ( 1 )
{
while ( 1 )
{
v10 = *(_DWORD *)v3;
if ( *(_DWORD *)v3 <= a3 )
break;
v4 = (char **)(v3 + 16);
LABEL_13:
v3 = *v4;
if ( !*v4 )
return;
}
v9 = *((_DWORD *)v3 + 1);
if ( v9 < a2 )
goto LABEL_10;
if ( v9 > a3 )
break;
if ( v10 >= a2 )
{
if ( v10 > a2 )
{
itree_delete(v3 + 16, a2, v10 - 1, v8);
v9 = *((_DWORD *)v3 + 1);
}
if ( a3 > v9 )
itree_delete(v3 + 24, v9 + 1, a3, v8);
itree_remove(v4);
return;
}
if ( v9 >= a3 )
break;
if ( v10 > a2 )
goto LABEL_16;
if ( v9 >= a3 )
return;
*((_DWORD *)v3 + 1) = v6;
LABEL_10:
v4 = (char **)(v3 + 24);
v3 = (char *)*((_QWORD *)v3 + 3);
if ( !v3 )
return;
}
if ( v10 > a2 )
{
LABEL_16:
*(_DWORD *)v3 = v8;
v4 = (char **)(v3 + 16);
goto LABEL_13;
}
if ( v10 == a2 )
{
*(_DWORD *)v3 = a3 + 1;
}
else
{
v11 = a2 - 1;
if ( v9 == a3 )
{
LABEL_21:
*((_DWORD *)v3 + 1) = v11;
return;
}
v12 = *((_DWORD *)v3 + 2);
v13 = a3 + 1;
if ( (((unsigned __int8)a2 ^ (unsigned __int8)a3) & 1) != 0 )
{
itree_add((__int64 *)v3 + 3, v13, v9, v12);
goto LABEL_21;
}
itree_add((__int64 *)v3 + 2, v10, v11, v12);
*(_DWORD *)v3 = v13;
}
}

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


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)
{
_DWORD *v2; // [rsp+0h] [rbp-18h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

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

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 *


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

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

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


decompiled_code:
// attributes: thunk
void __fastcall itree_freeall(void *ptr)
{
itree_free(ptr);
}

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

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

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