decompiled_code:
__int64 __fastcall cs_readblock(unsigned int a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, __int64 a6)
{
int *v9; // rax
const char *v10; // rax
__int64 result; // rax
int *v12; // rax
const char *v13; // rax
unsigned __int64 v14; // rax
int *v15; // rax
const char *v16; // rax
char *v17; // rax
unsigned __int64 v18; // rax
unsigned int v19; // ebx
__int64 v20; // rcx
__int64 v21; // rcx
__int64 v22; // rcx
int v23; // ebx
unsigned int v24; // eax
unsigned int v25; // ebp
int *v26; // rax
const char *v27; // rax
unsigned __int16 v29; // [rsp+10h] [rbp-88h]
unsigned __int16 v30; // [rsp+12h] [rbp-86h]
int v31; // [rsp+14h] [rbp-84h]
unsigned __int8 *v32; // [rsp+28h] [rbp-70h] BYREF
char v33[40]; // [rsp+30h] [rbp-68h] BYREF
__int64 v34[8]; // [rsp+58h] [rbp-40h] BYREF

v34[0] = (__int64)v33;
put32bit((__int64)v34, 0xC8u);
put32bit((__int64)v34, 0x14u);
put64bit(v34, a2);
put32bit((__int64)v34, a3);
put32bit((__int64)v34, a4);
put32bit((__int64)v34, a5);
if ( (unsigned int)tcptowrite(a1, v33, 28LL, 5000LL) == 28 )
{
while ( 1 )
{
while ( 1 )
{
if ( (unsigned int)tcptoread(a1, v33, 8LL, 5000LL) != 8 )
{
v12 = _errno_location();
v13 = (const char *)strerr((unsigned int)*v12);
syslog(5, "readblock; tcpread error: %s", v13);
return 0xFFFFFFFFLL;
}
v32 = (unsigned __int8 *)v33;
v23 = get32bit(&v32);
v24 = get32bit(&v32);
v25 = v24;
if ( v23 == 201 )
{
if ( v24 == 9 )
{
if ( (unsigned int)tcptoread(a1, v33, 9LL, 5000LL) == 9 )
{
v32 = (unsigned __int8 *)v33;
v14 = get64bit(&v32);
if ( *v32 )
{
v17 = mfsstrerr(*v32);
syslog(5, "readblock; READ_STATUS status: %s", v17);
result = 0xFFFFFFFFLL;
}
else if ( a2 == v14 )
{
if ( a5 )
{
syslog(5, "readblock; READ_STATUS incorrect data size (left: %u)", a5);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
syslog(5, "readblock; READ_STATUS incorrect chunkid (got:%lu expected:%lu)", v14, a2);
result = 0xFFFFFFFFLL;
}
}
else
{
v15 = _errno_location();
v16 = (const char *)strerr((unsigned int)*v15);
syslog(5, "readblock; READ_STATUS tcpread error: %s", v16);
result = 0xFFFFFFFFLL;
}
}
else
{
syslog(5, "readblock; READ_STATUS incorrect message size (%u/9)", v24);
result = 0xFFFFFFFFLL;
}
return result;
}
if ( v23 != 202 )
break;
if ( v24 <= 0x13 )
{
syslog(5, "readblock; READ_DATA incorrect message size (%u/>=20)", v24);
return 0xFFFFFFFFLL;
}
if ( (unsigned int)tcptoread(a1, v33, 20LL, 5000LL) != 20 )
{
LABEL_35:
v26 = _errno_location();
v27 = (const char *)strerr((unsigned int)*v26);
syslog(5, "readblock; READ_DATA tcpread error: %s", v27);
return 0xFFFFFFFFLL;
}
v32 = (unsigned __int8 *)v33;
v18 = get64bit(&v32);
if ( a2 != v18 )
{
syslog(5, "readblock; READ_DATA incorrect chunkid (got:%lu expected:%lu)", v18, a2);
return 0xFFFFFFFFLL;
}
v29 = get16bit(&v32);
v30 = get16bit(&v32);
v19 = get32bit(&v32);
v31 = get32bit(&v32);
v20 = v19 + 20;
if ( (_DWORD)v20 != v25 )
{
syslog(5, "readblock; READ_DATA incorrect message size (%u/%u)", v25, v20);
return 0xFFFFFFFFLL;
}
if ( !v19 )
{
syslog(5, "readblock; READ_DATA empty block");
return 0xFFFFFFFFLL;
}
v21 = HIWORD(a4);
if ( v29 != (_DWORD)v21 )
{
syslog(5, "readblock; READ_DATA incorrect block number (got:%u expected:%u)", v29, v21);
return 0xFFFFFFFFLL;
}
if ( v30 != (unsigned __int16)a4 )
{
syslog(5, "readblock; READ_DATA incorrect block offset (got:%u expected:%u)", v30, (unsigned __int16)a4);
return 0xFFFFFFFFLL;
}
v22 = 0x10000 - (unsigned int)(unsigned __int16)a4;
if ( a5 <= (unsigned int)v22 )
v22 = a5;
if ( (_DWORD)v22 != v19 )
{
syslog(5, "readblock; READ_DATA incorrect block size (got:%u expected:%u)", v19, v22);
return 0xFFFFFFFFLL;
}
if ( (unsigned int)tcptoread(a1, a6, v19, 5000LL) != v19 )
goto LABEL_35;
if ( (unsigned int)mycrc32(0LL, a6, v19) != v31 )
{
syslog(5, "readblock; READ_DATA crc checksum error");
return 0xFFFFFFFFLL;
}
a4 += v19;
a5 -= v19;
a6 += v19;
}
if ( v23 )
break;
if ( v24 )
{
syslog(5, "readblock; NOP incorrect message size (%u/0)", v24);
return 0xFFFFFFFFLL;
}
}
if ( (unsigned int)(v23 - 1) <= 1 )
syslog(5, "readblock; got UNKNOWN_COMMAND/BAD_COMMAND_SIZE !!!");
else
syslog(5, "readblock; unknown message");
result = 0xFFFFFFFFLL;
}
else
{
v9 = _errno_location();
v10 = (const char *)strerr((unsigned int)*v9);
syslog(5, "readblock; tcpwrite error: %s", v10);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, __int64 a6)
{
int *v9; // rax
const char *v10; // rax
__int64 result; // rax
int *v12; // rax
const char *v13; // rax
unsigned __int64 v14; // rax
int *v15; // rax
const char *v16; // rax
char *v17; // rax
unsigned __int64 v18; // rax
unsigned int v19; // ebx
__int64 v20; // rcx
__int64 v21; // rcx
__int64 v22; // rcx
int v23; // ebx
unsigned int v24; // eax
unsigned int v25; // ebp
int *v26; // rax
const char *v27; // rax
unsigned __int16 v29; // [rsp+10h] [rbp-88h]
unsigned __int16 v30; // [rsp+12h] [rbp-86h]
int v31; // [rsp+14h] [rbp-84h]
unsigned __int8 *v32; // [rsp+28h] [rbp-70h] BYREF
char v33[40]; // [rsp+30h] [rbp-68h] BYREF
__int64 v34[8]; // [rsp+58h] [rbp-40h] BYREF

v34[0] = (__int64)v33;
func1((__int64)v34, 0xC8u);
func1((__int64)v34, 0x14u);
func0(v34, a2);
func1((__int64)v34, a3);
func1((__int64)v34, a4);
func1((__int64)v34, a5);
if ( (unsigned int)tcptowrite(a1, v33, 28LL, 5000LL) == 28 )
{
while ( 1 )
{
while ( 1 )
{
if ( (unsigned int)tcptoread(a1, v33, 8LL, 5000LL) != 8 )
{
v12 = _errno_location();
v13 = (const char *)strerr((unsigned int)*v12);
syslog(5, "readblock; tcpread error: %s", v13);
return 0xFFFFFFFFLL;
}
v32 = (unsigned __int8 *)v33;
v23 = func3(&v32);
v24 = func3(&v32);
v25 = v24;
if ( v23 == 201 )
{
if ( v24 == 9 )
{
if ( (unsigned int)tcptoread(a1, v33, 9LL, 5000LL) == 9 )
{
v32 = (unsigned __int8 *)v33;
v14 = func2(&v32);
if ( *v32 )
{
v17 = func5(*v32);
syslog(5, "readblock; READ_STATUS status: %s", v17);
result = 0xFFFFFFFFLL;
}
else if ( a2 == v14 )
{
if ( a5 )
{
syslog(5, "readblock; READ_STATUS incorrect data size (left: %u)", a5);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
syslog(5, "readblock; READ_STATUS incorrect chunkid (got:%lu expected:%lu)", v14, a2);
result = 0xFFFFFFFFLL;
}
}
else
{
v15 = _errno_location();
v16 = (const char *)strerr((unsigned int)*v15);
syslog(5, "readblock; READ_STATUS tcpread error: %s", v16);
result = 0xFFFFFFFFLL;
}
}
else
{
syslog(5, "readblock; READ_STATUS incorrect message size (%u/9)", v24);
result = 0xFFFFFFFFLL;
}
return result;
}
if ( v23 != 202 )
break;
if ( v24 <= 0x13 )
{
syslog(5, "readblock; READ_DATA incorrect message size (%u/>=20)", v24);
return 0xFFFFFFFFLL;
}
if ( (unsigned int)tcptoread(a1, v33, 20LL, 5000LL) != 20 )
{
LABEL_35:
v26 = _errno_location();
v27 = (const char *)strerr((unsigned int)*v26);
syslog(5, "readblock; READ_DATA tcpread error: %s", v27);
return 0xFFFFFFFFLL;
}
v32 = (unsigned __int8 *)v33;
v18 = func2(&v32);
if ( a2 != v18 )
{
syslog(5, "readblock; READ_DATA incorrect chunkid (got:%lu expected:%lu)", v18, a2);
return 0xFFFFFFFFLL;
}
v29 = func4(&v32);
v30 = func4(&v32);
v19 = func3(&v32);
v31 = func3(&v32);
v20 = v19 + 20;
if ( (_DWORD)v20 != v25 )
{
syslog(5, "readblock; READ_DATA incorrect message size (%u/%u)", v25, v20);
return 0xFFFFFFFFLL;
}
if ( !v19 )
{
syslog(5, "readblock; READ_DATA empty block");
return 0xFFFFFFFFLL;
}
v21 = HIWORD(a4);
if ( v29 != (_DWORD)v21 )
{
syslog(5, "readblock; READ_DATA incorrect block number (got:%u expected:%u)", v29, v21);
return 0xFFFFFFFFLL;
}
if ( v30 != (unsigned __int16)a4 )
{
syslog(5, "readblock; READ_DATA incorrect block offset (got:%u expected:%u)", v30, (unsigned __int16)a4);
return 0xFFFFFFFFLL;
}
v22 = 0x10000 - (unsigned int)(unsigned __int16)a4;
if ( a5 <= (unsigned int)v22 )
v22 = a5;
if ( (_DWORD)v22 != v19 )
{
syslog(5, "readblock; READ_DATA incorrect block size (got:%u expected:%u)", v19, v22);
return 0xFFFFFFFFLL;
}
if ( (unsigned int)tcptoread(a1, a6, v19, 5000LL) != v19 )
goto LABEL_35;
if ( (unsigned int)mycrc32(0LL, a6, v19) != v31 )
{
syslog(5, "readblock; READ_DATA crc checksum error");
return 0xFFFFFFFFLL;
}
a4 += v19;
a5 -= v19;
a6 += v19;
}
if ( v23 )
break;
if ( v24 )
{
syslog(5, "readblock; NOP incorrect message size (%u/0)", v24);
return 0xFFFFFFFFLL;
}
}
if ( (unsigned int)(v23 - 1) <= 1 )
syslog(5, "readblock; got UNKNOWN_COMMAND/BAD_COMMAND_SIZE !!!");
else
syslog(5, "readblock; unknown message");
result = 0xFFFFFFFFLL;
}
else
{
v9 = _errno_location();
v10 = (const char *)strerr((unsigned int)*v9);
syslog(5, "readblock; tcpwrite error: %s", v10);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cs_readblock(int fd,uint64_t chunkid,uint32_t version,uint32_t offset,uint32_t size,uint8_t *buff) {
 uint8_t *wptr,ibuff[28];
 const uint8_t *rptr;
 wptr = ibuff;
 put32bit(&wptr,(0 +200));
 put32bit(&wptr,20);
 put64bit(&wptr,chunkid);
 put32bit(&wptr,version);
 put32bit(&wptr,offset);
 put32bit(&wptr,size);
 if (tcptowrite(fd,ibuff,28,5000)!=28) {
  syslog(5,"readblock; tcpwrite error: %s",strerr((*__errno_location ())));
  return -1;
 }
 for (;;) {
  uint32_t cmd,l;
  uint64_t t64;
  uint16_t blockno,blockoffset;
  uint32_t breq,blocksize,blockcrc;
  if (tcptoread(fd,ibuff,8,5000)!=8) {
   syslog(5,"readblock; tcpread error: %s",strerr((*__errno_location ())));
   return -1;
  }
  rptr = ibuff;
  cmd = get32bit(&rptr);
  l = get32bit(&rptr);
  if (cmd==(0 +201)) {
   if (l!=9) {
    syslog(5,"readblock; READ_STATUS incorrect message size (%""u""/9)",l);
    return -1;
   }
   if (tcptoread(fd,ibuff,9,5000)!=9) {
    syslog(5,"readblock; READ_STATUS tcpread error: %s",strerr((*__errno_location ())));
    return -1;
   }
   rptr = ibuff;
   t64 = get64bit(&rptr);
   if (*rptr!=0) {
    syslog(5,"readblock; READ_STATUS status: %s",mfsstrerr(*rptr));
    return -1;
   }
   if (t64!=chunkid) {
    syslog(5,"readblock; READ_STATUS incorrect chunkid (got:%""l" "u"" expected:%""l" "u"")",t64,chunkid);
    return -1;
   }
   if (size!=0) {
    syslog(5,"readblock; READ_STATUS incorrect data size (left: %""u"")",size);
    return -1;
   }
   return 0;
  } else if (cmd==(0 +202)) {
   if (l<20) {
    syslog(5,"readblock; READ_DATA incorrect message size (%""u""/>=20)",l);
    return -1;
   }
   if (tcptoread(fd,ibuff,20,5000)!=20) {
    syslog(5,"readblock; READ_DATA tcpread error: %s",strerr((*__errno_location ())));
    return -1;
   }
   rptr = ibuff;
   t64 = get64bit(&rptr);
   if (t64!=chunkid) {
    syslog(5,"readblock; READ_DATA incorrect chunkid (got:%""l" "u"" expected:%""l" "u"")",t64,chunkid);
    return -1;
   }
   blockno = get16bit(&rptr);
   blockoffset = get16bit(&rptr);
   blocksize = get32bit(&rptr);
   blockcrc = get32bit(&rptr);
   if (l!=20+blocksize) {
    syslog(5,"readblock; READ_DATA incorrect message size (%""u""/%""u"")",l,20+blocksize);
    return -1;
   }
   if (blocksize==0) {
    syslog(5,"readblock; READ_DATA empty block");
    return -1;
   }
   if (blockno!=(offset>>16)) {
    syslog(5,"readblock; READ_DATA incorrect block number (got:%""u"" expected:%""u"")",blockno,(offset>>16));
    return -1;
   }
   if (blockoffset!=(offset&0x0FFFF)) {
    syslog(5,"readblock; READ_DATA incorrect block offset (got:%""u"" expected:%""u"")",blockoffset,(offset&0x0FFFF));
    return -1;
   }
   breq = 0x10000 - (uint32_t)blockoffset;
   if (size<breq) {
    breq=size;
   }
   if (blocksize!=breq) {
    syslog(5,"readblock; READ_DATA incorrect block size (got:%""u"" expected:%""u"")",blocksize,breq);
    return -1;
   }
   if (tcptoread(fd,buff,blocksize,5000)!=(int32_t)blocksize) {
    syslog(5,"readblock; READ_DATA tcpread error: %s",strerr((*__errno_location ())));
    return -1;
   }
   if (blockcrc!=mycrc32(0,buff,blocksize)) {
    syslog(5,"readblock; READ_DATA crc checksum error");
    return -1;
   }
   offset+=blocksize;
   size-=blocksize;
   buff+=blocksize;
  } else if (cmd==0) {
   if (l!=0) {
    syslog(5,"readblock; NOP incorrect message size (%""u""/0)",l);
    return -1;
   }
  } else if (cmd==1 || cmd==2) {
   syslog(5,"readblock; got UNKNOWN_COMMAND/BAD_COMMAND_SIZE !!!");
   return -1;
  } else {
   syslog(5,"readblock; unknown message");
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int cs_readblock(int fd, unsigned long chunkid, unsigned int version, unsigned int offset, unsigned int size, unsigned char *buff) {
 unsigned char *wptr; unsigned char ibuff[28];
 unsigned char *rptr;
 wptr = ibuff;
 put32bit(&wptr,(0 +200));
 put32bit(&wptr,20);
 put64bit(&wptr,chunkid);
 put32bit(&wptr,version);
 put32bit(&wptr,offset);
 put32bit(&wptr,size);
 if (tcptowrite(fd,ibuff,28,5000)!=28) {
  syslog(5,"readblock; tcpwrite error: %s",strerr((*__errno_location ())));
  return -1;
 }
 for (;;) {
  unsigned int cmd; unsigned int l;
  unsigned long t64;
  unsigned short blockno; unsigned short blockoffset;
  unsigned int breq; unsigned int blocksize; unsigned int blockcrc;
  if (tcptoread(fd,ibuff,8,5000)!=8) {
   syslog(5,"readblock; tcpread error: %s",strerr((*__errno_location ())));
   return -1;
  }
  rptr = ibuff;
  cmd = get32bit(&rptr);
  l = get32bit(&rptr);
  if (cmd==(0 +201)) {
   if (l!=9) {
    syslog(5,"readblock; READ_STATUS incorrect message size (%""u""/9)",l);
    return -1;
   }
   if (tcptoread(fd,ibuff,9,5000)!=9) {
    syslog(5,"readblock; READ_STATUS tcpread error: %s",strerr((*__errno_location ())));
    return -1;
   }
   rptr = ibuff;
   t64 = get64bit(&rptr);
   if (*rptr!=0) {
    syslog(5,"readblock; READ_STATUS status: %s",mfsstrerr(*rptr));
    return -1;
   }
   if (t64!=chunkid) {
    syslog(5,"readblock; READ_STATUS incorrect chunkid (got:%""l" "u"" expected:%""l" "u"")",t64,chunkid);
    return -1;
   }
   if (size!=0) {
    syslog(5,"readblock; READ_STATUS incorrect data size (left: %""u"")",size);
    return -1;
   }
   return 0;
  } else if (cmd==(0 +202)) {
   if (l<20) {
    syslog(5,"readblock; READ_DATA incorrect message size (%""u""/>=20)",l);
    return -1;
   }
   if (tcptoread(fd,ibuff,20,5000)!=20) {
    syslog(5,"readblock; READ_DATA tcpread error: %s",strerr((*__errno_location ())));
    return -1;
   }
   rptr = ibuff;
   t64 = get64bit(&rptr);
   if (t64!=chunkid) {
    syslog(5,"readblock; READ_DATA incorrect chunkid (got:%""l" "u"" expected:%""l" "u"")",t64,chunkid);
    return -1;
   }
   blockno = get16bit(&rptr);
   blockoffset = get16bit(&rptr);
   blocksize = get32bit(&rptr);
   blockcrc = get32bit(&rptr);
   if (l!=20+blocksize) {
    syslog(5,"readblock; READ_DATA incorrect message size (%""u""/%""u"")",l,20+blocksize);
    return -1;
   }
   if (blocksize==0) {
    syslog(5,"readblock; READ_DATA empty block");
    return -1;
   }
   if (blockno!=(offset>>16)) {
    syslog(5,"readblock; READ_DATA incorrect block number (got:%""u"" expected:%""u"")",blockno,(offset>>16));
    return -1;
   }
   if (blockoffset!=(offset&0x0FFFF)) {
    syslog(5,"readblock; READ_DATA incorrect block offset (got:%""u"" expected:%""u"")",blockoffset,(offset&0x0FFFF));
    return -1;
   }
   breq = 0x10000 - (unsigned int)blockoffset;
   if (size<breq) {
    breq=size;
   }
   if (blocksize!=breq) {
    syslog(5,"readblock; READ_DATA incorrect block size (got:%""u"" expected:%""u"")",blocksize,breq);
    return -1;
   }
   if (tcptoread(fd,buff,blocksize,5000)!=(int)blocksize) {
    syslog(5,"readblock; READ_DATA tcpread error: %s",strerr((*__errno_location ())));
    return -1;
   }
   if (blockcrc!=mycrc32(0,buff,blocksize)) {
    syslog(5,"readblock; READ_DATA crc checksum error");
    return -1;
   }
   offset+=blocksize;
   size-=blocksize;
   buff+=blocksize;
  } else if (cmd==0) {
   if (l!=0) {
    syslog(5,"readblock; NOP incorrect message size (%""u""/0)",l);
    return -1;
   }
  } else if (cmd==1 || cmd==2) {
   syslog(5,"readblock; got UNKNOWN_COMMAND/BAD_COMMAND_SIZE !!!");
   return -1;
  } else {
   syslog(5,"readblock; unknown message");
   return -1;
  }
 }
 return 0;
}

variable_types: fd int

variable_types:
chunkid
unsigned long

variable_types:
version
unsigned int

variable_types:
offset
unsigned int

variable_types:
size
unsigned int

variable_types:
buff
unsigned char *

variable_types:
wptr
unsigned char *

variable_types:
ibuff
unsigned char [28]

variable_types:
rptr
unsigned char *

variable_types:
cmd
unsigned int

variable_types:
l
unsigned int

variable_types:
blockno
unsigned short

variable_types:
blockoffset
unsigned short

variable_types:
breq
unsigned int

variable_types:
blocksize
unsigned int

variable_types:
blockcrc
unsigned int


findfirstlogversion

repo: twonly/mfs

decompiled_code:
__int64 __fastcall findfirstlogversion(const char *a1)
{
int v1; // eax
__int64 v2; // rcx
int v3; // ebp
int v4; // ebx
__int64 i; // rdx
unsigned __int8 v6; // al
char v8[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = open64(a1, 0);
v2 = 0LL;
if ( v1 >= 0 )
{
v3 = v1;
v4 = read(v1, v8, 0x32uLL);
close(v3);
v2 = 0LL;
if ( v4 > 0 )
{
for ( i = 0LL; ; ++i )
{
v6 = v8[i];
if ( (unsigned __int8)(v6 - 48) > 9u )
break;
v2 = v6 - 48 + 10 * v2;
if ( i == v4 - 1 )
return 0LL;
}
if ( v4 <= (int)i )
{
v2 = 0LL;
}
else if ( v8[(int)i] != 58 )
{
v2 = 0LL;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // eax
__int64 v2; // rcx
int v3; // ebp
int v4; // ebx
__int64 i; // rdx
unsigned __int8 v6; // al
char v8[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = open64(a1, 0);
v2 = 0LL;
if ( v1 >= 0 )
{
v3 = v1;
v4 = read(v1, v8, 0x32uLL);
close(v3);
v2 = 0LL;
if ( v4 > 0 )
{
for ( i = 0LL; ; ++i )
{
v6 = v8[i];
if ( (unsigned __int8)(v6 - 48) > 9u )
break;
v2 = v6 - 48 + 10 * v2;
if ( i == v4 - 1 )
return 0LL;
}
if ( v4 <= (int)i )
{
v2 = 0LL;
}
else if ( v8[(int)i] != 58 )
{
v2 = 0LL;
}
}
}
return v2;
}

original_code:
uint64_t findfirstlogversion(const char *fname) {
 uint8_t buff[50];
 int32_t s,p;
 uint64_t fv;
 int fd;
 fd = open(fname,00);
 if (fd<0) {
  return 0;
 }
 s = read(fd,buff,50);
 close(fd);
 if (s<=0) {
  return 0;
 }
 fv = 0;
 p = 0;
 while (p<s && buff[p]>='0' && buff[p]<='9') {
  fv *= 10;
  fv += buff[p]-'0';
  p++;
 }
 if (p>=s || buff[p]!=':') {
  return 0;
 }
 return fv;
}

canonical_original_code:
unsigned long findfirstlogversion(char *fname) {
 unsigned char buff[50];
 int s; int p;
 unsigned long fv;
 int fd;
 fd = open(fname,00);
 if (fd<0) {
  return 0;
 }
 s = read(fd,buff,50);
 close(fd);
 if (s<=0) {
  return 0;
 }
 fv = 0;
 p = 0;
 while (p<s && buff[p]>='0' && buff[p]<='9') {
  fv *= 10;
  fv += buff[p]-'0';
  p++;
 }
 if (p>=s || buff[p]!=':') {
  return 0;
 }
 return fv;
}

variable_types:
fname
char *

variable_types:
buff
unsigned char [50]

variable_types: s int

variable_types: p int

variable_types:
fv
unsigned long

return_type: unsigned long


findlastlogversion

original_code:
uint64_t findlastlogversion(const char *fname) {
 struct stat st;
 uint8_t buff[32800];
 uint64_t size;
 uint32_t buffpos;
 uint64_t lastnewline,lv;
 int fd;
 fd = open(fname,00);
 if (fd<0) {
  return 0;
 }
 fstat(fd,&st);
 size = st.st_size;
 memset(buff,0,32);
 lastnewline = 0;
 while (size>0 && size+200000>(uint64_t)(st.st_size)) {
  if (size>32768) {
   memcpy(buff+32768,buff,32);
   size-=32768;
   lseek(fd,size,0);
   if (read(fd,buff,32768)!=32768) {
    close(fd);
    return 0;
   }
   buffpos = 32768;
  } else {
   memmove(buff+size,buff,32);
   lseek(fd,0,0);
   if (read(fd,buff,size)!=(ssize_t)size) {
    close(fd);
    return 0;
   }
   buffpos = size;
   size = 0;
  }
  while (buffpos>0) {
   buffpos--;
   if (buff[buffpos]=='\n') {
    if (lastnewline==0) {
     lastnewline = size + buffpos;
    } else {
     if (lastnewline+1 != (uint64_t)(st.st_size)) {
      close(fd);
      return 0;
     }
     buffpos++;
     lv = 0;
     while (buffpos<32800 && buff[buffpos]>='0' && buff[buffpos]<='9') {
      lv *= 10;
      lv += buff[buffpos]-'0';
      buffpos++;
     }
     if (buffpos==32800 || buff[buffpos]!=':') {
      lv = 0;
     }
     close(fd);
     return lv;
    }
   }
  }
 }
 close(fd);
 return 0;
}

canonical_original_code:
unsigned long findlastlogversion(char *fname) {
 struct stat st;
 unsigned char buff[32800];
 unsigned long size;
 unsigned int buffpos;
 unsigned long lastnewline; unsigned long lv;
 int fd;
 fd = open(fname,00);
 if (fd<0) {
  return 0;
 }
 fstat(fd,&st);
 size = st.st_size;
 memset(buff,0,32);
 lastnewline = 0;
 while (size>0 && size+200000>(unsigned long)(st.st_size)) {
  if (size>32768) {
   memcpy(buff+32768,buff,32);
   size-=32768;
   lseek(fd,size,0);
   if (read(fd,buff,32768)!=32768) {
    close(fd);
    return 0;
   }
   buffpos = 32768;
  } else {
   memmove(buff+size,buff,32);
   lseek(fd,0,0);
   if (read(fd,buff,size)!=(long)size) {
    close(fd);
    return 0;
   }
   buffpos = size;
   size = 0;
  }
  while (buffpos>0) {
   buffpos--;
   if (buff[buffpos]=='\n') {
    if (lastnewline==0) {
     lastnewline = size + buffpos;
    } else {
     if (lastnewline+1 != (unsigned long)(st.st_size)) {
      close(fd);
      return 0;
     }
     buffpos++;
     lv = 0;
     while (buffpos<32800 && buff[buffpos]>='0' && buff[buffpos]<='9') {
      lv *= 10;
      lv += buff[buffpos]-'0';
      buffpos++;
     }
     if (buffpos==32800 || buff[buffpos]!=':') {
      lv = 0;
     }
     close(fd);
     return lv;
    }
   }
  }
 }
 close(fd);
 return 0;
}

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

variable_types:
buff
unsigned char [32800]

variable_types:
size
unsigned long

variable_types:
buffpos
unsigned int

variable_types:
lastnewline
unsigned long

variable_types:
lv
unsigned long

variable_types: fd int

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


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

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

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

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

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 *

return_type: int


usage

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)
{
__int64 result; // rax

if ( a1 <= 3u )
{
stats_lock();
++*(_QWORD *)statsptr[a1];
result = stats_unlock();
}
return result;
}

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

if ( a1 <= 3u )
{
stats_lock();
++*(_QWORD *)statsptr[a1];
result = stats_unlock();
}
return result;
}

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; // rbx
__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_488 = stats_get_counterptr(v2);
v3 = stats_get_subnode(v0, "search_misses", 0LL);
qword_490 = stats_get_counterptr(v3);
v4 = stats_get_subnode(v0, "#links", 1LL);
result = stats_get_counterptr(v4);
qword_498 = result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__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_488 = stats_get_counterptr(v2);
v3 = stats_get_subnode(v0, "search_misses", 0LL);
qword_490 = stats_get_counterptr(v3);
v4 = stats_get_subnode(v0, "#links", 1LL);
result = stats_get_counterptr(v4);
qword_498 = 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)
{
unsigned int v3; // er13
char *v4; // rdx
unsigned __int64 v5; // rdi
unsigned __int64 v6; // rbx
__int64 i; // rax
int v8; // er12
__int64 result; // rax
_DWORD *v10; // rbp
void *v11; // rdi
int v12[4]; // [rsp+0h] [rbp-38h] BYREF
char v13; // [rsp+10h] [rbp-28h] BYREF

v12[0] = 1072573589;
v12[1] = -829139673;
v12[2] = -1446418319;
v12[3] = 748191707;
v3 = time(0LL);
pthread_mutex_lock(&slcachelock);
v4 = (char *)v12;
while ( 2 )
{
v5 = (1328234253 * (unsigned __int64)(unsigned int)(*(_DWORD *)v4 * a1)) >> 32;
v6 = symlinkhash
+ ((unsigned __int64)(*(_DWORD *)v4 * a1
- 6257 * (((unsigned int)v5 + ((unsigned int)(*(_DWORD *)v4 * a1 - v5) >> 1)) >> 12)) << 8);
for ( i = 0LL; i != 16; ++i )
{
v8 = i;
if ( *(_DWORD *)(v6 + 4 * i) == a1 )
{
v10 = (_DWORD *)(v6 + 4LL * (int)i);
if ( v10[16] + 86400 >= v3 )
{
*a2 = *(_QWORD *)(v6 + 8LL * (int)i + 128);
pthread_mutex_unlock(&slcachelock);
symlink_cache_stats_inc(1u);
result = 1LL;
}
else
{
v11 = *(void **)(v6 + 8LL * (int)i + 128);
if ( v11 )
{
free(v11);
*(_QWORD *)(v6 + 8LL * v8 + 128) = 0LL;
}
v10[16] = 0;
*v10 = 0;
pthread_mutex_unlock(&slcachelock);
symlink_cache_stats_dec(3u);
symlink_cache_stats_inc(2u);
result = 0LL;
}
return result;
}
}
v4 += 4;
if ( v4 != &v13 )
continue;
break;
}
pthread_mutex_unlock(&slcachelock);
symlink_cache_stats_inc(2u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, _QWORD *a2)
{
unsigned int v3; // er13
char *v4; // rdx
unsigned __int64 v5; // rdi
unsigned __int64 v6; // rbx
__int64 i; // rax
int v8; // er12
__int64 result; // rax
_DWORD *v10; // rbp
void *v11; // rdi
int v12[4]; // [rsp+0h] [rbp-38h] BYREF
char v13; // [rsp+10h] [rbp-28h] BYREF

v12[0] = 1072573589;
v12[1] = -829139673;
v12[2] = -1446418319;
v12[3] = 748191707;
v3 = time(0LL);
pthread_mutex_lock(&slcachelock);
v4 = (char *)v12;
while ( 2 )
{
v5 = (1328234253 * (unsigned __int64)(unsigned int)(*(_DWORD *)v4 * a1)) >> 32;
v6 = symlinkhash
+ ((unsigned __int64)(*(_DWORD *)v4 * a1
- 6257 * (((unsigned int)v5 + ((unsigned int)(*(_DWORD *)v4 * a1 - v5) >> 1)) >> 12)) << 8);
for ( i = 0LL; i != 16; ++i )
{
v8 = i;
if ( *(_DWORD *)(v6 + 4 * i) == a1 )
{
v10 = (_DWORD *)(v6 + 4LL * (int)i);
if ( v10[16] + 86400 >= v3 )
{
*a2 = *(_QWORD *)(v6 + 8LL * (int)i + 128);
pthread_mutex_unlock(&slcachelock);
func0(1u);
result = 1LL;
}
else
{
v11 = *(void **)(v6 + 8LL * (int)i + 128);
if ( v11 )
{
free(v11);
*(_QWORD *)(v6 + 8LL * v8 + 128) = 0LL;
}
v10[16] = 0;
*v10 = 0;
pthread_mutex_unlock(&slcachelock);
func1(3u);
func0(2u);
result = 0LL;
}
return result;
}
}
v4 += 4;
if ( v4 != &v13 )
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 **

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


decompiled_code:
__int64 symlink_cache_init()
{
symlinkhash = (__int64)malloc(0x187100uLL);
memset((void *)symlinkhash, 0, 0x187100uLL);
return symlink_cache_statsptr_init();
}

canonical_decompiled_code:
__int64 func5()
{
symlinkhash = (__int64)malloc(0x187100uLL);
memset((void *)symlinkhash, 0, 0x187100uLL);
return func2();
}

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()
{
__int64 i; // r12
void **v1; // rbx
void *v2; // r13
__int64 v3; // rbp

pthread_mutex_lock(&slcachelock);
for ( i = 0LL; i != 1601792; i += 256LL )
{
v2 = (void *)symlinkhash;
v1 = (void **)(symlinkhash + i + 128);
v3 = symlinkhash + i + 256;
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)v3 );
}
free(v2);
return pthread_mutex_unlock(&slcachelock);
}

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

pthread_mutex_lock(&slcachelock);
for ( i = 0LL; i != 1601792; i += 256LL )
{
v2 = (void *)symlinkhash;
v1 = (void **)(symlinkhash + i + 128);
v3 = symlinkhash + i + 256;
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)v3 );
}
free(v2);
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)
{
__int64 result; // rax

if ( a1 <= 2u )
{
stats_lock();
++*(_QWORD *)statsptr[a1];
result = stats_unlock();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 <= 2u )
{
stats_lock();
++*(_QWORD *)statsptr[a1];
result = stats_unlock();
}
return result;
}

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; // rbx
__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_6A8 = stats_get_counterptr(v2);
v3 = stats_get_subnode(v0, "misses", 0LL);
result = stats_get_counterptr(v3);
qword_6B0 = result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__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_6A8 = stats_get_counterptr(v2);
v3 = stats_get_subnode(v0, "misses", 0LL);
result = stats_get_counterptr(v3);
qword_6B0 = 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 = (__int64)malloc(0x326910uLL);
memset((void *)chunklochash, 0, 0x326910uLL);
return chunkloc_cache_statsptr_init();
}

canonical_decompiled_code:
__int64 func5()
{
chunklochash = (__int64)malloc(0x326910uLL);
memset((void *)chunklochash, 0, 0x326910uLL);
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()
{
__int64 i; // r12
void **v1; // rbx
void *v2; // r13
__int64 v3; // rbp

pthread_mutex_lock(&clcachelock);
for ( i = 0LL; i != 3303696; i += 528LL )
{
v2 = (void *)chunklochash;
v1 = (void **)(chunklochash + i + 400);
v3 = chunklochash + i + 528;
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)v3 );
}
free(v2);
return pthread_mutex_unlock(&clcachelock);
}

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

pthread_mutex_lock(&clcachelock);
for ( i = 0LL; i != 3303696; i += 528LL )
{
v2 = (void *)chunklochash;
v1 = (void **)(chunklochash + i + 400);
v3 = chunklochash + i + 528;
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)v3 );
}
free(v2);
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; // ebx
_DWORD *v2; // rbp
pthread_attr_t v4; // [rsp+0h] [rbp-58h] BYREF
pthread_t newthread[4]; // [rsp+38h] [rbp-20h] BYREF

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

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
int v1; // ebx
_DWORD *v2; // rbp
pthread_attr_t v4; // [rsp+0h] [rbp-58h] BYREF
pthread_t newthread[4]; // [rsp+38h] [rbp-20h] BYREF

pthread_attr_init(&v4);
pthread_attr_setstacksize(&v4, 0x100000uLL);
pthread_attr_setdetachstate(&v4, 1);
while ( !terminate )
{
v1 = tcptoaccept((unsigned int)lsock, 1000LL);
if ( v1 >= 0 )
{
v2 = malloc(4uLL);
*v2 = v1;
tcpnodelay((unsigned int)v1);
if ( pthread_create(newthread, &v4, masterproxy_server, v2) < 0 )
{
free(v2);
tcpclose((unsigned int)v1);
}
}
}
pthread_attr_destroy(&v4);
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 *


decompiled_code:
void *__fastcall masterproxy_server(void *a1)
{
unsigned int v1; // er12
unsigned int v3; // ebp
unsigned int v4; // eax
unsigned int v5; // er14
unsigned int v6; // ebx
int v7; // eax
unsigned int v8; // [rsp+8h] [rbp-4E70h] BYREF
int v9; // [rsp+Ch] [rbp-4E6Ch] BYREF
char *v10; // [rsp+10h] [rbp-4E68h] BYREF
char *v11; // [rsp+18h] [rbp-4E60h] BYREF
char v12[12]; // [rsp+20h] [rbp-4E58h] BYREF
char v13[9988]; // [rsp+2Ch] [rbp-4E4Ch] BYREF
char s1[4]; // [rsp+2730h] [rbp-2748h] BYREF
char v15[10004]; // [rsp+2734h] [rbp-2744h] BYREF
char v16[48]; // [rsp+4E48h] [rbp-30h] BYREF

v1 = *(_DWORD *)a1;
free(a1);
while ( (unsigned int)tcptoread(v1, v16, 8LL, 1000LL) == 8 )
{
v10 = v16;
v3 = get32bit((unsigned __int8 **)&v10);
v4 = get32bit((unsigned __int8 **)&v10);
if ( v3 == 400 )
{
if ( v4 != 73 )
break;
if ( (unsigned int)tcptoread(v1, s1, 73LL, 1000LL) != 73 )
break;
if ( memcmp(s1, "DjI1GAQDULI5d2YjA26ypc3ovkhjvhciTQVx3CS4nYgtBoUcsljiVpsErJENHaw0", 0x40uLL) )
break;
if ( v15[60] != 4 )
break;
v11 = v12;
put32bit((__int64)&v11, 0x191u);
put32bit((__int64)&v11, 1u);
put8bit((__int64 *)&v11, 0);
if ( (unsigned int)tcptowrite(v1, v12, 9LL, 1000LL) != 9 )
break;
}
else
{
v5 = v4 - 4;
if ( v4 - 4 > 0x270C )
break;
if ( (unsigned int)tcptoread(v1, s1, v4, 1000LL) != v4 )
break;
v10 = s1;
v6 = get32bit((unsigned __int8 **)&v10);
v9 = 9988;
if ( (unsigned __int8)fs_custom(v3, v15, v5, &v8, v13, &v9) )
break;
v11 = v12;
put32bit((__int64)&v11, v8);
put32bit((__int64)&v11, v9 + 4);
put32bit((__int64)&v11, v6);
v7 = tcptowrite(v1, v12, (unsigned int)(v9 + 12), 1000LL);
if ( v7 != v9 + 12 )
break;
}
}
tcpclose(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func5(void *a1)
{
unsigned int v1; // er12
unsigned int v3; // ebp
unsigned int v4; // eax
unsigned int v5; // er14
unsigned int v6; // ebx
int v7; // eax
unsigned int v8; // [rsp+8h] [rbp-4E70h] BYREF
int v9; // [rsp+Ch] [rbp-4E6Ch] BYREF
char *v10; // [rsp+10h] [rbp-4E68h] BYREF
char *v11; // [rsp+18h] [rbp-4E60h] BYREF
char v12[12]; // [rsp+20h] [rbp-4E58h] BYREF
char v13[9988]; // [rsp+2Ch] [rbp-4E4Ch] BYREF
char s1[4]; // [rsp+2730h] [rbp-2748h] BYREF
char v15[10004]; // [rsp+2734h] [rbp-2744h] BYREF
char v16[48]; // [rsp+4E48h] [rbp-30h] BYREF

v1 = *(_DWORD *)a1;
free(a1);
while ( (unsigned int)tcptoread(v1, v16, 8LL, 1000LL) == 8 )
{
v10 = v16;
v3 = func3((unsigned __int8 **)&v10);
v4 = func3((unsigned __int8 **)&v10);
if ( v3 == 400 )
{
if ( v4 != 73 )
break;
if ( (unsigned int)tcptoread(v1, s1, 73LL, 1000LL) != 73 )
break;
if ( memcmp(s1, "DjI1GAQDULI5d2YjA26ypc3ovkhjvhciTQVx3CS4nYgtBoUcsljiVpsErJENHaw0", 0x40uLL) )
break;
if ( v15[60] != 4 )
break;
v11 = v12;
func0((__int64)&v11, 0x191u);
func0((__int64)&v11, 1u);
func2((__int64 *)&v11, 0);
if ( (unsigned int)tcptowrite(v1, v12, 9LL, 1000LL) != 9 )
break;
}
else
{
v5 = v4 - 4;
if ( v4 - 4 > 0x270C )
break;
if ( (unsigned int)tcptoread(v1, s1, v4, 1000LL) != v4 )
break;
v10 = s1;
v6 = func3((unsigned __int8 **)&v10);
v9 = 9988;
if ( (unsigned __int8)fs_custom(v3, v15, v5, &v8, v13, &v9) )
break;
v11 = v12;
func0((__int64)&v11, v8);
func0((__int64)&v11, v9 + 4);
func0((__int64)&v11, v6);
v7 = tcptowrite(v1, v12, (unsigned int)(v9 + 12), 1000LL);
if ( v7 != v9 + 12 )
break;
}
}
tcpclose(v1);
return 0LL;
}

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;
result = a1 + 10;
v3 = (unsigned __int8 *)(a1 + 10);
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;
result = a1 + 10;
v3 = (unsigned __int8 *)(a1 + 10);
if ( lsock >= 0 )
{
result = func3(&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()
{
__int64 result; // rax
pthread_attr_t v1; // [rsp+0h] [rbp-48h] BYREF

lsock = tcpsocket();
result = 0xFFFFFFFFLL;
if ( lsock >= 0 )
{
tcpnonblock();
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 )
{
tcpclose((unsigned int)lsock);
lsock = -1;
result = 0xFFFFFFFFLL;
}
else
{
terminate = 0;
pthread_attr_init(&v1);
pthread_attr_setstacksize(&v1, 0x100000uLL);
pthread_create(&proxythread, &v1, masterproxy_acceptor, 0LL);
pthread_attr_destroy(&v1);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
pthread_attr_t v1; // [rsp+0h] [rbp-48h] BYREF

lsock = tcpsocket();
result = 0xFFFFFFFFLL;
if ( lsock >= 0 )
{
tcpnonblock();
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 )
{
tcpclose((unsigned int)lsock);
lsock = -1;
result = 0xFFFFFFFFLL;
}
else
{
terminate = 0;
pthread_attr_init(&v1);
pthread_attr_setstacksize(&v1, 0x100000uLL);
pthread_create(&proxythread, &v1, masterproxy_acceptor, 0LL);
pthread_attr_destroy(&v1);
result = 1LL;
}
}
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
char v2[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
{
snprintf(s, 0x64uLL, "changelog.%u.mfs", v0--);
snprintf(v2, 0x64uLL, "changelog.%u.mfs", v0);
rename(v2, s);
}
while ( v0 );
}
else
{
unlink("changelog.0.mfs");
}
return matomlserv_broadcast_logrotate();
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx
char v2[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
{
snprintf(s, 0x64uLL, "changelog.%u.mfs", v0--);
snprintf(v2, 0x64uLL, "changelog.%u.mfs", v0);
rename(v2, s);
}
while ( v0 );
}
else
{
unlink("changelog.0.mfs");
}
return matomlserv_broadcast_logrotate();
}

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; // rbp
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_30FBF = 0;
v4 = &unk_30D40;
}
if ( fd || (fd = fopen64("changelog.0.mfs", "a")) != 0LL )
{
v5 = fd;
}
else
{
syslog(5, "lost MFS change %lu: %s", a1, printbuff_0);
v5 = fd;
if ( !fd )
return matomlserv_broadcast_logstring(a1, printbuff_0, (unsigned int)v4);
}
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; // rbp
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_30FBF = 0;
v4 = &unk_30D40;
}
if ( fd || (fd = fopen64("changelog.0.mfs", "a")) != 0LL )
{
v5 = fd;
}
else
{
syslog(5, "lost MFS change %lu: %s", a1, printbuff_0);
v5 = fd;
if ( !fd )
return matomlserv_broadcast_logstring(a1, printbuff_0, (unsigned int)v4);
}
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);
fd = 0LL;
result = 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);
fd = 0LL;
result = 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)
{
paramhead = 0LL;
logundefined = a2;
cfgfname = strdup(a1);
return cfg_reload();
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, int a2)
{
paramhead = 0LL;
logundefined = a2;
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 )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_4;
}
result = strdup(*((const char **)v2 + 1));
if ( !result )
{
fprintf(stderr, "out of memory: %s is NULL\n", "_cfg_ret_tmp");
syslog(3, "out of memory: %s is NULL", "_cfg_ret_tmp");
abort();
}
}
else
{
LABEL_4:
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 )
{
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 result;
}

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

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_4;
}
result = strdup(*((const char **)v2 + 1));
if ( !result )
{
fprintf(stderr, "out of memory: %s is NULL\n", "_cfg_ret_tmp");
syslog(3, "out of memory: %s is NULL", "_cfg_ret_tmp");
abort();
}
}
else
{
LABEL_4:
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 )
{
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 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)
{
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_4;
}
result = strtol(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s1, unsigned int 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_4;
}
result = strtol(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

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

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_4;
}
result = strtol(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1, unsigned int 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_4;
}
result = strtol(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

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:
unsigned __int64 __fastcall cfg_getuint8(char *s1, unsigned int 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 = strtoul(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(char *s1, unsigned int 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 = strtoul(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

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

v2 = paramhead;
if ( paramhead )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = (void *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_4;
}
result = strtol(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s1, unsigned int 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_4;
}
result = strtol(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

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:
unsigned __int64 __fastcall cfg_getuint16(char *s1, unsigned int 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 = strtoul(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(char *s1, unsigned int 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 = strtoul(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

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:
__int64 __fastcall cfg_getint32(char *s1, unsigned int 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_4;
}
result = strtol(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s1, unsigned int 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_4;
}
result = strtol(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

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:
unsigned __int64 __fastcall cfg_getuint32(char *s1, unsigned int 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 = strtoul(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(char *s1, unsigned int 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 = strtoul(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
if ( logundefined )
{
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);
result = a2;
}
}
return result;
}

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_4;
}
result = strtoll(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
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_4;
}
result = strtoll(*((const char **)v2 + 1), 0LL, 0);
}
else
{
LABEL_4:
result = a2;
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