CheckVersion

decompiled_code:
__int64 __fastcall CheckVersion(const char *a1)
{
const char *v1; // rbx
unsigned int v2; // edx
const char *v3; // rbx
int v4; // ebp
struct utsname v6; // [rsp+0h] [rbp-1B8h] BYREF
unsigned int v7; // [rsp+194h] [rbp-24h] BYREF
unsigned int v8; // [rsp+198h] [rbp-20h] BYREF
unsigned int v9; // [rsp+19Ch] [rbp-1Ch] BYREF

v1 = a1;
if ( !memcmp(a1, "Version_", 8uLL) || (v2 = 0, *v1 == 95) && (++v1, !memcmp(v1, "Version_", 8uLL)) )
{
v3 = v1 + 8;
v4 = atoi(v3);
v7 = (unsigned __int8)v4;
v8 = BYTE1(v4);
v9 = BYTE2(v4);
if ( debugging )
fprintf(
stderr,
"Version string = %s, Major = %d, Minor = %d, Patch = %d.\n",
v3,
BYTE2(v4),
BYTE1(v4),
(unsigned __int8)v4);
sprintf(vstring, "%d.%d.%d", v9, v8, v7);
if ( uname(&v6) < 0 )
{
Syslog(3LL, "Cannot get kernel version information.");
v2 = 0;
}
else
{
if ( debugging )
fprintf(stderr, "Comparing kernel %s with symbol table %s.\n", v6.release, vstring);
if ( (int)_isoc99_sscanf(v6.release, "%d.%d.%d", &v9, &v8, &v7) <= 2 )
{
Syslog(3LL, "Kernel send bogus release string `%s'.", v6.release);
v2 = 0;
}
else
{
v2 = 2 * (v4 == (v7 | (v8 << 8) | (v9 << 16))) - 1;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
const char *v1; // rbx
unsigned int v2; // edx
const char *v3; // rbx
int v4; // ebp
struct utsname v6; // [rsp+0h] [rbp-1B8h] BYREF
unsigned int v7; // [rsp+194h] [rbp-24h] BYREF
unsigned int v8; // [rsp+198h] [rbp-20h] BYREF
unsigned int v9; // [rsp+19Ch] [rbp-1Ch] BYREF

v1 = a1;
if ( !memcmp(a1, "Version_", 8uLL) || (v2 = 0, *v1 == 95) && (++v1, !memcmp(v1, "Version_", 8uLL)) )
{
v3 = v1 + 8;
v4 = atoi(v3);
v7 = (unsigned __int8)v4;
v8 = BYTE1(v4);
v9 = BYTE2(v4);
if ( debugging )
fprintf(
stderr,
"Version string = %s, Major = %d, Minor = %d, Patch = %d.\n",
v3,
BYTE2(v4),
BYTE1(v4),
(unsigned __int8)v4);
sprintf(vstring, "%d.%d.%d", v9, v8, v7);
if ( uname(&v6) < 0 )
{
Syslog(3LL, "Cannot get kernel version information.");
v2 = 0;
}
else
{
if ( debugging )
fprintf(stderr, "Comparing kernel %s with symbol table %s.\n", v6.release, vstring);
if ( (int)_isoc99_sscanf(v6.release, "%d.%d.%d", &v9, &v8, &v7) <= 2 )
{
Syslog(3LL, "Kernel send bogus release string `%s'.", v6.release);
v2 = 0;
}
else
{
v2 = 2 * (v4 == (v7 | (v8 << 8) | (v9 << 16))) - 1;
}
}
}
return v2;
}

original_code:
static int CheckVersion (char * version)
{
 int vnum,
 major,
 minor,
 patch;
 int kvnum;
 struct utsname utsname;
 static char * prefix =
 {
  "Version_"
 };
 if (strncmp (version, prefix, strlen (prefix)) == 0 || (* version == '_' && strncmp (++ version, prefix, strlen (prefix)) == 0));
 else return (0);
 vnum = atoi (version + strlen (prefix));
 patch = vnum & 0x000000FF;
 minor = (vnum >> 8) & 0x000000FF;
 major = (vnum >> 16) & 0x000000FF;
 if (debugging) fprintf (stderr, "Version string = %s, Major = %d, Minor = %d, Patch = %d.\n", version + strlen (prefix), major, minor, patch);
 sprintf (vstring, "%d.%d.%d", major, minor, patch);
 if (uname (& utsname) < 0)
 {
  Syslog (3, "Cannot get kernel version information.");
  return (0);
 }
 if (debugging) fprintf (stderr, "Comparing kernel %s with symbol table %s.\n", utsname.release, vstring);
 if (sscanf (utsname.release, "%d.%d.%d", & major, & minor, & patch) < 3)
 {
  Syslog (3, "Kernel send bogus release string `%s'.", utsname.release);
  return (0);
 }
 kvnum = (major << 16) | (minor << 8) | patch;
 if (vnum != kvnum) return (- 1);
 return (1);
}

canonical_original_code:
static int CheckVersion(char *version)
{
 int vnum; int major; int minor; int patch;
 int kvnum;
 struct utsname utsname;
 static char *prefix = {
  "Version_"
 };
 if (strncmp (version, prefix, strlen (prefix)) == 0 || (* version == '_' && strncmp (++ version, prefix, strlen (prefix)) == 0));
 else return (0);
 vnum = atoi (version + strlen (prefix));
 patch = vnum & 0x000000FF;
 minor = (vnum >> 8) & 0x000000FF;
 major = (vnum >> 16) & 0x000000FF;
 if (debugging) fprintf (stderr, "Version string = %s, Major = %d, Minor = %d, Patch = %d.\n", version + strlen (prefix), major, minor, patch);
 sprintf (vstring, "%d.%d.%d", major, minor, patch);
 if (uname (& utsname) < 0)
 {
  Syslog (3, "Cannot get kernel version information.");
  return (0);
 }
 if (debugging) fprintf (stderr, "Comparing kernel %s with symbol table %s.\n", utsname.release, vstring);
 if (sscanf (utsname.release, "%d.%d.%d", & major, & minor, & patch) < 3)
 {
  Syslog (3, "Kernel send bogus release string `%s'.", utsname.release);
  return (0);
 }
 kvnum = (major << 16) | (minor << 8) | patch;
 if (vnum != kvnum) return (- 1);
 return (1);
}

variable_types:
version
char *

variable_types: vnum int

variable_types: major int

variable_types: minor int

variable_types: patch int

variable_types: kvnum int

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }

variable_types:
prefix
char *


SetParanoiaLevel

repo: razzlefratz/MotleyTools

decompiled_code:
void SetParanoiaLevel()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
extern void SetParanoiaLevel (int level)
{
 i_am_paranoid = level;
 return;
}

canonical_original_code:
extern void SetParanoiaLevel(int level)
{
 i_am_paranoid = level;
 return;
}

variable_types: level int

return_type: void


LookupSymbol

decompiled_code:
void *__fastcall LookupSymbol(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 *v2; // r11
unsigned __int64 *v4; // rax
__int64 v5; // rdx
char *v6; // r9
_QWORD *v7; // rcx
void *result; // rax
char *v9; // rsi

v2 = (unsigned __int64 *)symbols;
if ( !symbols )
return symbols;
*(_DWORD *)(a2 + 12) = 0;
*(_DWORD *)(a2 + 8) = 0;
if ( *v2 > a1 )
return 0LL;
v4 = v2;
v5 = 0LL;
if ( num_syms >= 0 )
{
while ( 1 )
{
v5 = (unsigned int)(v5 + 1);
if ( (int)v5 > num_syms )
break;
v6 = (char *)v4 + 16LL - (_QWORD)v2;
v7 = v4 + 2;
if ( v4[2] > a1 )
{
result = (void *)v4[1];
v9 = &v6[(_QWORD)v2 - 16];
*(_DWORD *)(a2 + 12) = a1 - *(_DWORD *)v9;
*(_DWORD *)(a2 + 8) = *v7 - *(_DWORD *)v9;
return result;
}
v4 += 2;
}
}
return (void *)LookupModuleSymbol(a1, a2, v5);
}

canonical_decompiled_code:
void *__fastcall func7(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 *v2; // r11
unsigned __int64 *v4; // rax
__int64 v5; // rdx
char *v6; // r9
_QWORD *v7; // rcx
void *result; // rax
char *v9; // rsi

v2 = (unsigned __int64 *)symbols;
if ( !symbols )
return symbols;
*(_DWORD *)(a2 + 12) = 0;
*(_DWORD *)(a2 + 8) = 0;
if ( *v2 > a1 )
return 0LL;
v4 = v2;
v5 = 0LL;
if ( num_syms >= 0 )
{
while ( 1 )
{
v5 = (unsigned int)(v5 + 1);
if ( (int)v5 > num_syms )
break;
v6 = (char *)v4 + 16LL - (_QWORD)v2;
v7 = v4 + 2;
if ( v4[2] > a1 )
{
result = (void *)v4[1];
v9 = &v6[(_QWORD)v2 - 16];
*(_DWORD *)(a2 + 12) = a1 - *(_DWORD *)v9;
*(_DWORD *)(a2 + 8) = *v7 - *(_DWORD *)v9;
return result;
}
v4 += 2;
}
}
return (void *)LookupModuleSymbol(a1, a2, v5);
}

original_code:
extern char const * LookupSymbol (unsigned long address, struct symbol * symbol)
{
 int lp;
 char const * last;
 if (!symbols) return ((char *) 0);
 last = symbols [0].name;
 symbol->offset = 0;
 symbol->size = 0;
 if (address < symbols [0].value) return ((char *) 0);
 for (lp = 0; lp <= num_syms; ++ lp)
 {
  if (symbols [lp].value > address)
  {
   symbol->offset = address - symbols [lp - 1].value;
   symbol->size = symbols [lp].value - symbols [lp - 1].value;
   return (last);
  }
  last = symbols [lp].name;
 }
 if ((last = LookupModuleSymbol (address, symbol)) != (char *) 0) return (last);
 return ((char *) 0);
}

canonical_original_code:
extern char *LookupSymbol(unsigned long address, struct symbol *symbol)
{
 int lp;
 char *last;
 if (!symbols) return ((char *) 0);
 last = symbols [0].name;
 symbol->offset = 0;
 symbol->size = 0;
 if (address < symbols [0].value) return ((char *) 0);
 for (lp = 0; lp <= num_syms; ++ lp)
 {
  if (symbols [lp].value > address)
  {
   symbol->offset = address - symbols [lp - 1].value;
   symbol->size = symbols [lp].value - symbols [lp - 1].value;
   return (last);
  }
  last = symbols [lp].name;
 }
 if ((last = LookupModuleSymbol (address, symbol)) != (char *) 0) return (last);
 return ((char *) 0);
}

variable_types:
address
unsigned long

variable_types: struct symbol { char *name; int size; int offset; } *

variable_types: lp int

variable_types:
last
char *

return_type: char *


decompiled_code:
int __fastcall syslogd_read_sockets(__int64 *a1)
{
int v1; // er13
int *v2; // r15
__int64 *v3; // rdx
__int64 *v4; // rbx
int v5; // edi
int v6; // eax
int v7; // ecx
int *v8; // rax
__int64 *v9; // rbp
__int64 v10; // rdi
int v11; // edi
_WORD *v12; // r12
__int64 v13; // r12
__int64 v14; // rdi
unsigned int *v16; // [rsp+8h] [rbp-10E0h]
char buf[4112]; // [rsp+10h] [rbp-10D8h] BYREF
fd_set readfds; // [rsp+1020h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+10A0h] [rbp-48h] BYREF

v3 = a1;
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
v4 = a1;
v5 = 0;
do
{
v4 = (__int64 *)*v4;
v7 = *((_DWORD *)v4 + 4);
if ( v7 >= 0 )
{
readfds.fds_bits[v7 >> 6] |= 1LL << (v7 % 64);
v6 = *((_DWORD *)v4 + 4);
if ( v6 > v5 )
v5 = v6 + 1;
}
}
while ( v3 != v4 );
LODWORD(v8) = select(v5, &readfds, 0LL, 0LL, &timeout);
if ( (int)v8 > 0 )
{
v9 = v4;
while ( 1 )
{
v9 = (__int64 *)*v9;
v11 = *((_DWORD *)v9 + 4);
if ( v11 >= 0 )
{
v12 = (_WORD *)v9[4];
if ( v12 )
{
v8 = (int *)(v11 >> 6);
if ( (readfds.fds_bits[(_QWORD)v8] & (1LL << (v11 % 64))) != 0 )
{
if ( *v12 == 2 )
{
v1 = recvfrom(v11, buf, 0x1001uLL, 0, (struct sockaddr *)v9[4], (socklen_t *)v9 + 6);
if ( v1 < 0 )
{
v8 = _errno_location();
v16 = (unsigned int *)v8;
if ( *v8 != 4 )
{
getsocketname(buf, 4097LL, v12);
LODWORD(v8) = syslogd_error(*v16, "Can't read %s with descriptor %d", buf, *((unsigned int *)v9 + 4));
}
goto LABEL_19;
}
v8 = (int *)syslogd_gethost(v12, &ourhosts, &ourdomains);
v2 = v8;
}
v13 = v9[4];
if ( *(_WORD *)v13 == 1 )
{
LODWORD(v8) = recv(*((_DWORD *)v9 + 4), buf, 0x1001uLL, 0);
v1 = (int)v8;
if ( (int)v8 < 0 )
{
v8 = _errno_location();
v10 = (unsigned int)*v8;
if ( (_DWORD)v10 != 4 )
LODWORD(v8) = syslogd_error(
v10,
"Can't read %s with descriptor %d",
(const char *)(v13 + 2),
*((unsigned int *)v9 + 4));
goto LABEL_19;
}
v2 = (int *)host_name;
}
if ( v1 > 0 )
{
if ( (unsigned int)v1 <= 0x1000 )
buf[v1++] = 0;
LODWORD(v8) = syslogd_merge(v9, v2, buf, v1);
}
}
}
else
{
LODWORD(v8) = syslogd_error(22LL, "No socket address");
}
}
LABEL_19:
if ( v4 == v9 )
return (int)v8;
}
}
if ( (int)v8 < 0 )
{
v8 = _errno_location();
v14 = (unsigned int)*v8;
if ( (_DWORD)v14 != 4 )
LODWORD(v8) = syslogd_error(v14, "select");
}
return (int)v8;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1)
{
int v1; // er13
int *v2; // r15
__int64 *v3; // rdx
__int64 *v4; // rbx
int v5; // edi
int v6; // eax
int v7; // ecx
int *v8; // rax
__int64 *v9; // rbp
__int64 v10; // rdi
int v11; // edi
_WORD *v12; // r12
__int64 v13; // r12
__int64 v14; // rdi
unsigned int *v16; // [rsp+8h] [rbp-10E0h]
char buf[4112]; // [rsp+10h] [rbp-10D8h] BYREF
fd_set readfds; // [rsp+1020h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+10A0h] [rbp-48h] BYREF

v3 = a1;
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
v4 = a1;
v5 = 0;
do
{
v4 = (__int64 *)*v4;
v7 = *((_DWORD *)v4 + 4);
if ( v7 >= 0 )
{
readfds.fds_bits[v7 >> 6] |= 1LL << (v7 % 64);
v6 = *((_DWORD *)v4 + 4);
if ( v6 > v5 )
v5 = v6 + 1;
}
}
while ( v3 != v4 );
LODWORD(v8) = select(v5, &readfds, 0LL, 0LL, &timeout);
if ( (int)v8 > 0 )
{
v9 = v4;
while ( 1 )
{
v9 = (__int64 *)*v9;
v11 = *((_DWORD *)v9 + 4);
if ( v11 >= 0 )
{
v12 = (_WORD *)v9[4];
if ( v12 )
{
v8 = (int *)(v11 >> 6);
if ( (readfds.fds_bits[(_QWORD)v8] & (1LL << (v11 % 64))) != 0 )
{
if ( *v12 == 2 )
{
v1 = recvfrom(v11, buf, 0x1001uLL, 0, (struct sockaddr *)v9[4], (socklen_t *)v9 + 6);
if ( v1 < 0 )
{
v8 = _errno_location();
v16 = (unsigned int *)v8;
if ( *v8 != 4 )
{
getsocketname(buf, 4097LL, v12);
LODWORD(v8) = syslogd_error(*v16, "Can't read %s with descriptor %d", buf, *((unsigned int *)v9 + 4));
}
goto LABEL_19;
}
v8 = (int *)syslogd_gethost(v12, &ourhosts, &ourdomains);
v2 = v8;
}
v13 = v9[4];
if ( *(_WORD *)v13 == 1 )
{
LODWORD(v8) = recv(*((_DWORD *)v9 + 4), buf, 0x1001uLL, 0);
v1 = (int)v8;
if ( (int)v8 < 0 )
{
v8 = _errno_location();
v10 = (unsigned int)*v8;
if ( (_DWORD)v10 != 4 )
LODWORD(v8) = syslogd_error(
v10,
"Can't read %s with descriptor %d",
(const char *)(v13 + 2),
*((unsigned int *)v9 + 4));
goto LABEL_19;
}
v2 = (int *)host_name;
}
if ( v1 > 0 )
{
if ( (unsigned int)v1 <= 0x1000 )
buf[v1++] = 0;
LODWORD(v8) = syslogd_merge(v9, v2, buf, v1);
}
}
}
else
{
LODWORD(v8) = syslogd_error(22LL, "No socket address");
}
}
LABEL_19:
if ( v4 == v9 )
return (int)v8;
}
}
if ( (int)v8 < 0 )
{
v8 = _errno_location();
v14 = (unsigned int)*v8;
if ( (_DWORD)v14 != 4 )
LODWORD(v8) = syslogd_error(v14, "select");
}
return (int)v8;
}

original_code:
void syslogd_read_sockets (struct socket * sockets)
{
 extern char const * host_name;
 extern char const * ourhosts [];
 extern char const * ourdomains [];
 struct socket * socket = sockets;
 struct timeval timer =
 {
  10,
  0
 };
 fd_set readfds;
 file_t fdrange = 0;
 signed count;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((& readfds)->__fds_bits)[0]) : "memory"); } while (0);
 do
 {
  socket = socket->next;
  if (socket->desc < 0)
  {
   continue;
  }
  ((void) (((& readfds)->__fds_bits)[((socket->desc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket->desc) % (8 * (int) sizeof (__fd_mask)))))));
  if (socket->desc > fdrange)
  {
   fdrange = socket->desc + 1;
  }
 }
 while (socket != sockets);
 count = select (fdrange, & readfds, (fd_set *) (0), (fd_set *) (0), & timer);
 if (count > 0)
 {
  do
  {
   socket = socket->next;
   if (socket->desc < 0)
   {
    continue;
   }
   if (socket->sockaddr == (struct sockaddr *) (0))
   {
    syslogd_error (22, "No socket address");
    continue;
   }
   if (((((& readfds)->__fds_bits)[((socket->desc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket->desc) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   {
    char const * origin;
    char buffer [0x1000 + 1];
    signed length;
    if (socket->sockaddr->sa_family == 2)
    {
     struct sockaddr_in * sockaddr_in = (struct sockaddr_in *) (socket->sockaddr);
     length = recvfrom (socket->desc, buffer, sizeof (buffer), (flag_t) (0), socket->sockaddr, & socket->socksize);
     if (length < 0)
     {
      if ((*__errno_location ()) != 4)
      {
       getsocketname (buffer, sizeof (buffer), sockaddr_in);
       syslogd_error ((*__errno_location ()), "Can't read %s with descriptor %d", buffer, socket->desc);
      }
      continue;
     }
     origin = syslogd_gethost (sockaddr_in, ourhosts, ourdomains);
    }
    if (socket->sockaddr->sa_family == 1)
    {
     struct sockaddr_un * sockaddr_un = (struct sockaddr_un *) (socket->sockaddr);
     length = recv (socket->desc, buffer, sizeof (buffer), (flag_t) (0));
     if (length < 0)
     {
      if ((*__errno_location ()) != 4)
      {
       syslogd_error ((*__errno_location ()), "Can't read %s with descriptor %d", sockaddr_un->sun_path, socket->desc);
      }
      continue;
     }
     origin = host_name;
    }
    if (length > 0)
    {
     if (length < sizeof (buffer))
     {
      buffer [length++] = (char) (0);
     }
     syslogd_merge (socket, origin, buffer, length);
     continue;
    }
   }
  }
  while (socket != sockets);
 }
 if (count < 0)
 {
  if ((*__errno_location ()) != 4)
  {
   syslogd_error ((*__errno_location ()), "select");
  }
 }
 return;
}

canonical_original_code:
void syslogd_read_sockets(struct socket *sockets)
{
 extern char *host_name;
 extern char *ourhosts[];
 extern char *ourdomains[];
 struct socket *socket = sockets;
 struct timeval timer = {
  10,
  0
 };
 struct fd_set readfds;
 int fdrange = 0;
 int count;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((& readfds)->__fds_bits)[0]) : "memory"); } while (0);
 do
 {
  socket = socket->next;
  if (socket->desc < 0)
  {
   continue;
  }
  ((void) (((& readfds)->__fds_bits)[((socket->desc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket->desc) % (8 * (int) sizeof (__fd_mask)))))));
  if (socket->desc > fdrange)
  {
   fdrange = socket->desc + 1;
  }
 }
 while (socket != sockets);
 count = select (fdrange, & readfds, (struct fd_set *) (0), (struct fd_set *) (0), & timer);
 if (count > 0)
 {
  do
  {
   socket = socket->next;
   if (socket->desc < 0)
   {
    continue;
   }
   if (socket->sockaddr == (struct sockaddr *) (0))
   {
    syslogd_error (22, "No socket address");
    continue;
   }
   if (((((& readfds)->__fds_bits)[((socket->desc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket->desc) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   {
    char *origin;
    char buffer[-1];
    int length;
    if (socket->sockaddr->sa_family == 2)
    {
     struct sockaddr_in *sockaddr_in = (struct sockaddr_in *) (socket->sockaddr);
     length = recvfrom (socket->desc, buffer, sizeof (buffer), (flag_t) (0), socket->sockaddr, & socket->socksize);
     if (length < 0)
     {
      if ((*__errno_location ()) != 4)
      {
       getsocketname (buffer, sizeof (buffer), sockaddr_in);
       syslogd_error ((*__errno_location ()), "Can't read %s with descriptor %d", buffer, socket->desc);
      }
      continue;
     }
     origin = syslogd_gethost (sockaddr_in, ourhosts, ourdomains);
    }
    if (socket->sockaddr->sa_family == 1)
    {
     struct sockaddr_un *sockaddr_un = (struct sockaddr_un *) (socket->sockaddr);
     length = recv (socket->desc, buffer, sizeof (buffer), (flag_t) (0));
     if (length < 0)
     {
      if ((*__errno_location ()) != 4)
      {
       syslogd_error ((*__errno_location ()), "Can't read %s with descriptor %d", sockaddr_un->sun_path, socket->desc);
      }
      continue;
     }
     origin = host_name;
    }
    if (length > 0)
    {
     if (length < sizeof (buffer))
     {
      buffer [length++] = (char) (0);
     }
     syslogd_merge (socket, origin, buffer, length);
     continue;
    }
   }
  }
  while (socket != sockets);
 }
 if (count < 0)
 {
  if ((*__errno_location ()) != 4)
  {
   syslogd_error ((*__errno_location ()), "select");
  }
 }
 return;
}

variable_types: struct socket { struct socket *next; struct socket *prev; int desc; unsigned long socksize; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *sockaddr; char *buffer; } *

variable_types:
ourhosts
char *[]

variable_types:
ourdomains
char *[]

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

variable_types:
readfds
struct fd_set { long __fds_bits[-1]; }

variable_types: fdrange int

variable_types: count int

variable_types:
origin
char *

variable_types:
buffer
char [-1]

variable_types: length int

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

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

user_defined_types: struct socket { struct socket *next; struct socket *prev; int desc; unsigned long socksize; struct sockaddr *sockaddr; char *buffer; }

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


decompiled_code:
__int64 syslogd_error(int errnum, char *format, ...)
{
__int64 v2; // r12
char *v4; // rax
gcc_va_list arg; // [rsp+8h] [rbp-10E0h] BYREF
char s[24]; // [rsp+20h] [rbp-10C8h] BYREF
__int64 v7; // [rsp+38h] [rbp-10B0h]
char v8[4064]; // [rsp+40h] [rbp-10A8h] BYREF

strcpy(s, "no error message");
v7 = 0LL;
memset(v8, 0, sizeof(v8));
v2 = 0LL;
if ( program_name && *program_name )
v2 = snprintf(s, 0x1000uLL, "%s: ", program_name);
if ( format && *format )
{
va_start(arg, format);
v2 += vsnprintf(&s[v2], 4096 - v2, format, arg);
}
if ( errnum )
{
v4 = strerror(errnum);
snprintf(&s[v2], 4096 - v2, ": %s", v4);
}
return syslogd_queue(43LL, host_name, s);
}

canonical_decompiled_code:
__int64 func0(int errnum, char *format, ...)
{
__int64 v2; // r12
char *v4; // rax
gcc_va_list arg; // [rsp+8h] [rbp-10E0h] BYREF
char s[24]; // [rsp+20h] [rbp-10C8h] BYREF
__int64 v7; // [rsp+38h] [rbp-10B0h]
char v8[4064]; // [rsp+40h] [rbp-10A8h] BYREF

strcpy(s, "no error message");
v7 = 0LL;
memset(v8, 0, sizeof(v8));
v2 = 0LL;
if ( program_name && *program_name )
v2 = snprintf(s, 0x1000uLL, "%s: ", program_name);
if ( format && *format )
{
va_start(arg, format);
v2 += vsnprintf(&s[v2], 4096 - v2, format, arg);
}
if ( errnum )
{
v4 = strerror(errnum);
snprintf(&s[v2], 4096 - v2, ": %s", v4);
}
return syslogd_queue(43LL, host_name, s);
}

original_code:
__attribute__ ((format (printf, 2, 3)))
void syslogd_error (errno_t number, char const * format, ...)
{
 extern char const * host_name;
 extern char const * program_name;
 char buffer [0x1000] = "no error message";
 size_t length = 0;
 if ((program_name != (char const *) (0)) && (* program_name != (char) (0)))
 {
  length += snprintf (buffer + length, sizeof (buffer) - length, "%s: ", program_name);
 }
 if ((format != (char const *) (0)) && (* format != (char) (0)))
 {
  va_list arglist;
  __builtin_va_start(arglist,format);
  length += vsnprintf (buffer + length, sizeof (buffer) - length, format, arglist);
  __builtin_va_end(arglist);
 }
 if (number != (errno_t) (0))
 {
  length += snprintf (buffer + length, sizeof (buffer) - length, ": %s", strerror (number));
 }
 syslogd_queue ((5 << 3) | 3, host_name, buffer);
 return;
}

canonical_original_code:
void syslogd_error(int number, char *format, ...)
{
 extern char *host_name;
 extern char *program_name;
 char buffer[4096] = "no error message";
 unsigned long length = 0;
 if ((program_name != (char *) (0)) && (* program_name != (char) (0)))
 {
  length += snprintf (buffer + length, sizeof (buffer) - length, "%s: ", program_name);
 }
 if ((format != (char *) (0)) && (* format != (char) (0)))
 {
  __builtin_va_list arglist;
  __builtin_va_start(arglist,format);
  length += vsnprintf (buffer + length, sizeof (buffer) - length, format, arglist);
  __builtin_va_end(arglist);
 }
 if (number != (errno_t) (0))
 {
  length += snprintf (buffer + length, sizeof (buffer) - length, ": %s", strerror (number));
 }
 syslogd_queue ((5 << 3) | 3, host_name, buffer);
 return;
}

variable_types: number int

variable_types:
format
char *

variable_types:
buffer
char [4096]

variable_types:
length
unsigned long


copyin

decompiled_code:
__int64 __fastcall copyin(__int64 a1, int a2, __int64 a3, int a4, const char *a5)
{
__int64 i; // rbx
unsigned int v7; // er12
char v8; // bp

if ( a2 > a4 )
a2 = a4;
if ( a2 <= 0 )
return 0;
for ( i = 0LL; i != a2; v7 = ++i )
{
v7 = i;
v8 = *(_BYTE *)(a3 + i);
if ( strchr(a5, v8) )
break;
*(_BYTE *)(a1 + i) = v8;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, int a4, const char *a5)
{
__int64 i; // rbx
unsigned int v7; // er12
char v8; // bp

if ( a2 > a4 )
a2 = a4;
if ( a2 <= 0 )
return 0;
for ( i = 0LL; i != a2; v7 = ++i )
{
v7 = i;
v8 = *(_BYTE *)(a3 + i);
if ( strchr(a5, v8) )
break;
*(_BYTE *)(a1 + i) = v8;
}
return v7;
}

original_code:
static int copyin (char * line, int space, char const * ptr, int len, char const * delim)
{
 int i;
 int count;
 count = len < space? len: space;
 for (i = 0; i < count && !strchr (delim, * ptr); i++)
 {
  * line++ = * ptr++;
 }
 return (i);
}

canonical_original_code:
static int copyin(char *line, int space, char *ptr, int len, char *delim)
{
 int i;
 int count;
 count = len < space? len: space;
 for (i = 0; i < count && !strchr (delim, * ptr); i++)
 {
  * line++ = * ptr++;
 }
 return (i);
}

variable_types:
line
char *

variable_types: space int

variable_types:
ptr
char *

variable_types: len int

variable_types:
delim
char *

variable_types: i int

return_type: int


decompiled_code:
void __fastcall reload_klogd(int a1)
{
change_state = 1;
reload_symbols = (a1 == 12) + 1;
signal(a1, reload_klogd);
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
change_state = 1;
reload_symbols = (a1 == 12) + 1;
signal(a1, reload_klogd);
}

original_code:
void reload_klogd (signo_t sig)
{
 change_state = 1;
 reload_symbols = 1;
 if (sig == 10)
 {
 }
 if (sig == 12)
 {
  ++ reload_symbols;
 }
 signal (sig, reload_klogd);
 return;
}

canonical_original_code:
void reload_klogd(int sig)
{
 change_state = 1;
 reload_symbols = 1;
 if (sig == 10)
 {
 }
 if (sig == 12)
 {
  ++ reload_symbols;
 }
 signal (sig, reload_klogd);
 return;
}

variable_types: sig int


decompiled_code:
void restart_klogd()
{
signal(18, restart_klogd);
change_state = 1;
caught_TSTP = 0;
}

canonical_decompiled_code:
void func2()
{
signal(18, restart_klogd);
change_state = 1;
caught_TSTP = 0;
}

original_code:
void restart_klogd (signo_t sig)
{
 signal (18, restart_klogd);
 change_state = 1;
 caught_TSTP = 0;
 return;
}

canonical_original_code:
void restart_klogd(int sig)
{
 signal (18, restart_klogd);
 change_state = 1;
 caught_TSTP = 0;
 return;
}


decompiled_code:
void stop_logging()
{
signal(20, stop_logging);
change_state = 1;
caught_TSTP = 1;
}

canonical_decompiled_code:
void func3()
{
signal(20, stop_logging);
change_state = 1;
caught_TSTP = 1;
}

original_code:
void stop_logging (signo_t sig)
{
 signal (20, stop_logging);
 change_state = 1;
 caught_TSTP = 1;
 return;
}

canonical_original_code:
void stop_logging(int sig)
{
 signal (20, stop_logging);
 change_state = 1;
 caught_TSTP = 1;
 return;
}


ReloadSymbols

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

if ( symbol_lookup )
{
if ( reload_symbols > 1 )
InitKsyms(symfile);
result = InitMsyms();
}
change_state = 0;
reload_symbols = 0;
return result;
}

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

if ( symbol_lookup )
{
if ( reload_symbols > 1 )
InitKsyms(symfile);
result = InitMsyms();
}
change_state = 0;
reload_symbols = 0;
return result;
}

original_code:
static void ReloadSymbols (void)
{
 if (symbol_lookup)
 {
  if (reload_symbols > 1)
  {
   InitKsyms (symfile);
  }
  InitMsyms ();
 }
 reload_symbols = change_state = 0;
 return;
}

canonical_original_code:
static void ReloadSymbols()
{
 if (symbol_lookup)
 {
  if (reload_symbols > 1)
  {
   InitKsyms (symfile);
  }
  InitMsyms ();
 }
 reload_symbols = change_state = 0;
 return;
}


decompiled_code:
int __fastcall signal_klogd(int sig)
{
__pid_t v1; // eax

v1 = readpf("/var/run/klogd.pid");
return kill(v1, sig);
}

canonical_decompiled_code:
int __fastcall func5(int sig)
{
__pid_t v1; // eax

v1 = readpf("/var/run/klogd.pid");
return kill(v1, sig);
}

original_code:
static void signal_klogd (signo_t sig)
{
 pid_t pid = readpf (PidFile);
 kill (pid, sig);
 return;
}

canonical_original_code:
static void signal_klogd(int sig)
{
 int pid = readpf (PidFile);
 kill (pid, sig);
 return;
}

variable_types: pid int


decompiled_code:
void __noreturn stop_klogd()
{
exit_klogd();
}

canonical_decompiled_code:
void __noreturn func9()
{
func8();
}

original_code:
void stop_klogd (signo_t sig)
{
 exit_klogd ();
 return;
}

canonical_original_code:
void stop_klogd(int sig)
{
 exit_klogd ();
 return;
}


LogKernelLine

decompiled_code:
void LogKernelLine()
{
int v0; // eax
int v1; // esi

memset(buffer, 0, sizeof(buffer));
v0 = klogctl(2, buffer, 4095);
if ( v0 > 0 )
{
LogLine(buffer, v0);
}
else
{
v1 = *_errno_location();
if ( v1 != 4 )
error(0, v1, "error return from sys_sycall");
}
}

canonical_decompiled_code:
void func13()
{
int v0; // eax
int v1; // esi

memset(buffer, 0, sizeof(buffer));
v0 = klogctl(2, buffer, 4095);
if ( v0 > 0 )
{
func12(buffer, v0);
}
else
{
v1 = *_errno_location();
if ( v1 != 4 )
error(0, v1, "error return from sys_sycall");
}
}

original_code:
static void LogKernelLine (void)
{
 int count;
 memset (buffer, '\0', sizeof (buffer));
 if ((count = klogctl (2, buffer, sizeof (buffer) - 1)) > 0)
 {
  LogLine (buffer, count);
 }
 else if ((*__errno_location ()) != 4)
 {
  error (0, (*__errno_location ()), "error return from sys_sycall");
 }
 return;
}

canonical_original_code:
static void LogKernelLine()
{
 int count;
 memset (buffer, '\0', sizeof (buffer));
 if ((count = klogctl (2, buffer, sizeof (buffer) - 1)) > 0)
 {
  LogLine (buffer, count);
 }
 else if ((*__errno_location ()) != 4)
 {
  error (0, (*__errno_location ()), "error return from sys_sycall");
 }
 return;
}

variable_types: count int


LogProcLine

decompiled_code:
void LogProcLine()
{
int v0; // eax
int *v1; // rbx
char *v2; // rax

memset(buffer, 0, sizeof(buffer));
v0 = read(kmsg, buffer, 0xFFFuLL);
if ( v0 > 0 )
{
LogLine(buffer, v0);
}
else
{
v1 = _errno_location();
if ( *v1 != 4 )
{
v2 = strerror(*v1);
Syslog(3, "can't read proc file system: %d - %s.", (unsigned int)*v1, v2);
}
}
}

canonical_decompiled_code:
void func14()
{
int v0; // eax
int *v1; // rbx
char *v2; // rax

memset(buffer, 0, sizeof(buffer));
v0 = read(kmsg, buffer, 0xFFFuLL);
if ( v0 > 0 )
{
func12(buffer, v0);
}
else
{
v1 = _errno_location();
if ( *v1 != 4 )
{
v2 = strerror(*v1);
func6(3, "can't read proc file system: %d - %s.", (unsigned int)*v1, v2);
}
}
}

original_code:
static void LogProcLine (void)
{
 int count;
 memset (buffer, '\0', sizeof (buffer));
 if ((count = read (kmsg, buffer, sizeof (buffer) - 1)) > 0)
 {
  LogLine (buffer, count);
 }
 else if ((*__errno_location ()) != 4)
 {
  Syslog (3, "can't read proc file system: %d - %s.", (*__errno_location ()), strerror ((*__errno_location ())));
 }
 return;
}

canonical_original_code:
static void LogProcLine()
{
 int count;
 memset (buffer, '\0', sizeof (buffer));
 if ((count = read (kmsg, buffer, sizeof (buffer) - 1)) > 0)
 {
  LogLine (buffer, count);
 }
 else if ((*__errno_location ()) != 4)
 {
  Syslog (3, "can't read proc file system: %d - %s.", (*__errno_location ()), strerror ((*__errno_location ())));
 }
 return;
}


variable_types:
origin
char *

variable_types:
string
char *

variable_types:
buffer
char [-1]

variable_types:
sp
char *

variable_types: priority int


decompiled_code:
__int64 __fastcall syslogd_unix_socket(struct sockaddr *addr)
{
char *v2; // r12
__int64 v3; // rdi
unsigned int v4; // ebp
int v5; // eax
int *v7; // rax
int *v8; // rax
int *v9; // rax

if ( addr->sa_data[0] )
{
v2 = addr->sa_data;
if ( unlink(addr->sa_data) && (v3 = (unsigned int)*_errno_location(), (_DWORD)v3 != 2) )
{
syslogd_error(v3, "Can't remove socket file %s", v2);
v4 = -1;
}
else
{
v4 = socket(1, 2, 0);
if ( v4 == -1 )
{
v7 = _errno_location();
syslogd_error((unsigned int)*v7, "Can't allocate socket for %s", v2);
}
else
{
v5 = strlen(v2);
if ( bind(v4, addr, v5 + 2) == -1 )
{
v8 = _errno_location();
syslogd_error((unsigned int)*v8, "Can't bind socket to %s", v2);
close(v4);
v4 = -1;
}
else if ( chmod(v2, 0x1B6u) == -1 )
{
v9 = _errno_location();
syslogd_error((unsigned int)*v9, "Can't set %s file permissions", v2);
close(v4);
v4 = -1;
}
}
}
}
else
{
*_errno_location() = 22;
syslogd_error(22LL, "Can't open socket file %s", addr->sa_data);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(struct sockaddr *addr)
{
char *v2; // r12
__int64 v3; // rdi
unsigned int v4; // ebp
int v5; // eax
int *v7; // rax
int *v8; // rax
int *v9; // rax

if ( addr->sa_data[0] )
{
v2 = addr->sa_data;
if ( unlink(addr->sa_data) && (v3 = (unsigned int)*_errno_location(), (_DWORD)v3 != 2) )
{
syslogd_error(v3, "Can't remove socket file %s", v2);
v4 = -1;
}
else
{
v4 = socket(1, 2, 0);
if ( v4 == -1 )
{
v7 = _errno_location();
syslogd_error((unsigned int)*v7, "Can't allocate socket for %s", v2);
}
else
{
v5 = strlen(v2);
if ( bind(v4, addr, v5 + 2) == -1 )
{
v8 = _errno_location();
syslogd_error((unsigned int)*v8, "Can't bind socket to %s", v2);
close(v4);
v4 = -1;
}
else if ( chmod(v2, 0x1B6u) == -1 )
{
v9 = _errno_location();
syslogd_error((unsigned int)*v9, "Can't set %s file permissions", v2);
close(v4);
v4 = -1;
}
}
}
}
else
{
*_errno_location() = 22;
syslogd_error(22LL, "Can't open socket file %s", addr->sa_data);
v4 = -1;
}
return v4;
}

original_code:
file_t syslogd_unix_socket (struct sockaddr_un * sockaddr_un)
{
 file_t fd;
 if (* sockaddr_un->sun_path == (char) (0))
 {
  (*__errno_location ()) = 22;
  syslogd_error ((*__errno_location ()), "Can't open socket file %s", sockaddr_un->sun_path);
  return (- 1);
 }
 if (unlink (sockaddr_un->sun_path))
 {
  if ((*__errno_location ()) != 2)
  {
   syslogd_error ((*__errno_location ()), "Can't remove socket file %s", sockaddr_un->sun_path);
   return (- 1);
  }
 }
 if ((fd = socket (1, SOCK_DGRAM, 0)) == - 1)
 {
  syslogd_error ((*__errno_location ()), "Can't allocate socket for %s", sockaddr_un->sun_path);
  return (- 1);
 }
 if (bind (fd, (struct sockaddr *) (sockaddr_un), sizeof (sockaddr_un->sun_family) + strlen (sockaddr_un->sun_path)) == - 1)
 {
  syslogd_error ((*__errno_location ()), "Can't bind socket to %s", sockaddr_un->sun_path);
  close (fd);
  return (- 1);
 }
 if (chmod (sockaddr_un->sun_path, 0666) == - 1)
 {
  syslogd_error ((*__errno_location ()), "Can't set %s file permissions", sockaddr_un->sun_path);
  close (fd);
  return (- 1);
 }
 return (fd);
}

canonical_original_code:
int syslogd_unix_socket(struct sockaddr_un *sockaddr_un)
{
 int fd;
 if (* sockaddr_un->sun_path == (char) (0))
 {
  (*__errno_location ()) = 22;
  syslogd_error ((*__errno_location ()), "Can't open socket file %s", sockaddr_un->sun_path);
  return (- 1);
 }
 if (unlink (sockaddr_un->sun_path))
 {
  if ((*__errno_location ()) != 2)
  {
   syslogd_error ((*__errno_location ()), "Can't remove socket file %s", sockaddr_un->sun_path);
   return (- 1);
  }
 }
 if ((fd = socket (1, SOCK_DGRAM, 0)) == - 1)
 {
  syslogd_error ((*__errno_location ()), "Can't allocate socket for %s", sockaddr_un->sun_path);
  return (- 1);
 }
 if (bind (fd, (struct sockaddr *) (sockaddr_un), sizeof (sockaddr_un->sun_family) + strlen (sockaddr_un->sun_path)) == - 1)
 {
  syslogd_error ((*__errno_location ()), "Can't bind socket to %s", sockaddr_un->sun_path);
  close (fd);
  return (- 1);
 }
 if (chmod (sockaddr_un->sun_path, 0666) == - 1)
 {
  syslogd_error ((*__errno_location ()), "Can't set %s file permissions", sockaddr_un->sun_path);
  close (fd);
  return (- 1);
 }
 return (fd);
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

variable_types: fd int

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


original_code:
void syslogd_index (struct syslogd * syslog, flag_t flags, facility_t facility, severity_t severity)
{
 if (severity == 8 + 1)
 {
  if (((syslog->f_flags) & ((1 << 2))) != (0))
  {
   syslog->f_severity [facility] |= (((1 << 8) - 1));
  }
  else
  {
   syslog->f_severity [facility] &= ~(((1 << 8) - 1));
  }
 }
 else if (severity == 8)
 {
  if (((syslog->f_flags) & ((1 << 2))) != (0))
  {
   syslog->f_severity [facility] &= ~(((1 << 8) - 1));
  }
  else
  {
   syslog->f_severity [facility] |= (((1 << 8) - 1));
  }
 }
 else if (((syslog->f_flags) & ((1 << 3))) != (0))
 {
  if (((syslog->f_flags) & ((1 << 2))) != (0))
  {
   syslog->f_severity [facility] &= ~((1 << severity));
  }
  else
  {
   syslog->f_severity [facility] |= ((1 << severity));
  }
 }
 else
 {
  if (((syslog->f_flags) & ((1 << 2))) != (0))
  {
   do
   {
    syslog->f_severity [facility] &= ~((1 << severity));
   }
   while (severity-- > 0);
  }
  else
  {
   do
   {
    syslog->f_severity [facility] |= ((1 << severity));
   }
   while (severity-- > 0);
  }
 }
 return;
}

canonical_original_code:
void syslogd_index(struct syslogd *syslog, unsigned int flags, unsigned int facility, unsigned int severity)
{
 if (severity == 8 + 1)
 {
  if (((syslog->f_flags) & ((1 << 2))) != (0))
  {
   syslog->f_severity [facility] |= (((1 << 8) - 1));
  }
  else
  {
   syslog->f_severity [facility] &= ~(((1 << 8) - 1));
  }
 }
 else if (severity == 8)
 {
  if (((syslog->f_flags) & ((1 << 2))) != (0))
  {
   syslog->f_severity [facility] &= ~(((1 << 8) - 1));
  }
  else
  {
   syslog->f_severity [facility] |= (((1 << 8) - 1));
  }
 }
 else if (((syslog->f_flags) & ((1 << 3))) != (0))
 {
  if (((syslog->f_flags) & ((1 << 2))) != (0))
  {
   syslog->f_severity [facility] &= ~((1 << severity));
  }
  else
  {
   syslog->f_severity [facility] |= ((1 << severity));
  }
 }
 else
 {
  if (((syslog->f_flags) & ((1 << 2))) != (0))
  {
   do
   {
    syslog->f_severity [facility] &= ~((1 << severity));
   }
   while (severity-- > 0);
  }
  else
  {
   do
   {
    syslog->f_severity [facility] |= ((1 << severity));
   }
   while (severity-- > 0);
  }
 }
 return;
}

variable_types: struct syslogd { struct syslogd *prev; struct syslogd *next; int f_type; char *f_name; unsigned long f_line; int f_desc; long f_time; unsigned int f_flags; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *f_sockaddr_in; unsigned int f_severity[25]; char f_posted[48]; char f_origin[64]; char f_nature[128]; char f_notice[4096]; unsigned long f_length; unsigned long f_priority; unsigned long f_repeat; unsigned long f_retry; } *

variable_types:
flags
unsigned int

variable_types:
facility
unsigned int

variable_types:
severity
unsigned int

user_defined_types: struct syslogd { struct syslogd *prev; struct syslogd *next; int f_type; char *f_name; unsigned long f_line; int f_desc; long f_time; unsigned int f_flags; struct sockaddr_in *f_sockaddr_in; unsigned int f_severity[25]; char f_posted[48]; char f_origin[64]; char f_nature[128]; char f_notice[4096]; unsigned long f_length; unsigned long f_priority; unsigned long f_repeat; unsigned long f_retry; }


decompiled_code:
unsigned int __fastcall syslogd_queue(int a1, const char *a2, const char *a3)
{
const char *v3; // r13
__int64 v5; // rbx
unsigned int result; // eax
struct tm *v7; // rax
__int64 v8; // rcx
time_t timer; // [rsp+18h] [rbp-40h] BYREF

v3 = a2;
timer = time(&timer);
if ( !a2 )
v3 = &src;
if ( !a3 )
a3 = &src;
v5 = *((_QWORD *)&syslogs + 1);
if ( (_UNKNOWN *)v5 == &syslogs )
goto LABEL_22;
result = a1;
do
{
if ( (*(_BYTE *)(v5 + 56) & 1) == 0 )
{
result = (a1 >> 3) & 0x7F;
if ( (*(_DWORD *)(v5 + 4LL * result + 72) & (1 << (a1 & 7))) != 0 )
{
result = timer;
if ( *(_QWORD *)(v5 + 48) <= timer )
{
if ( !*(_QWORD *)(v5 + 4536) )
{
v7 = localtime(&timer);
strftime((char *)(v5 + 172), 0x30uLL, "%F %T %Z", v7);
}
result = strcmp(a3, (const char *)(v5 + 412));
if ( result || (result = strcmp(v3, (const char *)(v5 + 220))) != 0 )
{
v8 = *(_QWORD *)(v5 + 4528);
if ( v8 )
{
*(_QWORD *)(v5 + 4512) = snprintf(
(char *)(v5 + 412),
0x1000uLL,
"Previous message received %d times",
v8 + 1);
*(_QWORD *)(v5 + 4528) = 0LL;
result = syslogd_write(v5, (unsigned int)state);
}
if ( *a3 )
{
*(_QWORD *)(v5 + 4520) = a1;
strncpy((char *)(v5 + 220), v3, 0x40uLL);
strfpri(v5 + 284, 128LL, (unsigned int)a1);
strncpy((char *)(v5 + 412), a3, 0x1000uLL);
*(_QWORD *)(v5 + 4528) = 0LL;
syslogd_ready(v5, (unsigned int)state);
result = syslogd_write(v5, (unsigned int)state);
}
}
else
{
++*(_QWORD *)(v5 + 4528);
}
}
}
}
v5 = *(_QWORD *)(v5 + 8);
}
while ( (_UNKNOWN *)v5 != &syslogs );
if ( *((_UNKNOWN **)&syslogs + 1) == &syslogs )
{
LABEL_22:
result = open(*((const char **)&syslogs + 3), 257);
*((_DWORD *)&syslogs + 10) = result;
if ( result != -1 )
{
syslogd_write(&syslogs, (unsigned int)state);
result = close(*((_DWORD *)&syslogs + 10));
*((_DWORD *)&syslogs + 10) = -1;
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func0(int a1, const char *a2, const char *a3)
{
const char *v3; // r13
__int64 v5; // rbx
unsigned int result; // eax
struct tm *v7; // rax
__int64 v8; // rcx
time_t timer; // [rsp+18h] [rbp-40h] BYREF

v3 = a2;
timer = time(&timer);
if ( !a2 )
v3 = &src;
if ( !a3 )
a3 = &src;
v5 = *((_QWORD *)&syslogs + 1);
if ( (_UNKNOWN *)v5 == &syslogs )
goto LABEL_22;
result = a1;
do
{
if ( (*(_BYTE *)(v5 + 56) & 1) == 0 )
{
result = (a1 >> 3) & 0x7F;
if ( (*(_DWORD *)(v5 + 4LL * result + 72) & (1 << (a1 & 7))) != 0 )
{
result = timer;
if ( *(_QWORD *)(v5 + 48) <= timer )
{
if ( !*(_QWORD *)(v5 + 4536) )
{
v7 = localtime(&timer);
strftime((char *)(v5 + 172), 0x30uLL, "%F %T %Z", v7);
}
result = strcmp(a3, (const char *)(v5 + 412));
if ( result || (result = strcmp(v3, (const char *)(v5 + 220))) != 0 )
{
v8 = *(_QWORD *)(v5 + 4528);
if ( v8 )
{
*(_QWORD *)(v5 + 4512) = snprintf(
(char *)(v5 + 412),
0x1000uLL,
"Previous message received %d times",
v8 + 1);
*(_QWORD *)(v5 + 4528) = 0LL;
result = syslogd_write(v5, (unsigned int)state);
}
if ( *a3 )
{
*(_QWORD *)(v5 + 4520) = a1;
strncpy((char *)(v5 + 220), v3, 0x40uLL);
strfpri(v5 + 284, 128LL, (unsigned int)a1);
strncpy((char *)(v5 + 412), a3, 0x1000uLL);
*(_QWORD *)(v5 + 4528) = 0LL;
syslogd_ready(v5, (unsigned int)state);
result = syslogd_write(v5, (unsigned int)state);
}
}
else
{
++*(_QWORD *)(v5 + 4528);
}
}
}
}
v5 = *(_QWORD *)(v5 + 8);
}
while ( (_UNKNOWN *)v5 != &syslogs );
if ( *((_UNKNOWN **)&syslogs + 1) == &syslogs )
{
LABEL_22:
result = open(*((const char **)&syslogs + 3), 257);
*((_DWORD *)&syslogs + 10) = result;
if ( result != -1 )
{
syslogd_write(&syslogs, (unsigned int)state);
result = close(*((_DWORD *)&syslogs + 10));
*((_DWORD *)&syslogs + 10) = -1;
}
}
return result;
}

original_code:
void syslogd_queue (int priority, char const * origin, char const * notice)
{
 extern flag_t state;
 extern struct syslogd syslogs;
 struct syslogd * syslog;
 facility_t facility = (((priority) & 0x03F8) >> 3);
 severity_t severity = (((priority) & 0x0007) >> 0);
 time_t now = time (& now);
 if (origin == (char const *) (0))
 {
  origin = "";
 }
 if (notice == (char const *) (0))
 {
  notice = "";
 }
 for (syslog = syslogs.next; syslog != & syslogs; syslog = syslog->next)
 {
  if (((syslog->f_flags) & ((1 << 0))) != (0))
  {
   continue;
  }
  if (((syslog->f_severity [facility]) & ((1 << severity))) == (0))
  {
   continue;
  }
  if (syslog->f_time > now)
  {
   continue;
  }
  if (!syslog->f_retry)
  {
   strftime (syslog->f_posted, sizeof (syslog->f_posted), "%F %T %Z", localtime (& now));
  }
  if (!strcmp (notice, syslog->f_notice) && !strcmp (origin, syslog->f_origin))
  {
   syslog->f_repeat++;
   continue;
  }
  if (syslog->f_repeat > 0)
  {
   syslog->f_length = snprintf (syslog->f_notice, sizeof (syslog->f_notice), "Previous message received %d times", syslog->f_repeat + 1);
   syslog->f_repeat = 0;
   syslogd_write (syslog, state);
  }
  if (* notice != (char) (0))
  {
   syslog->f_priority = priority;
   strncpy (syslog->f_origin, origin, sizeof (syslog->f_origin));
   strfpri (syslog->f_nature, sizeof (syslog->f_nature), priority);
   strncpy (syslog->f_notice, notice, sizeof (syslog->f_notice));
   syslog->f_repeat = 0;
   syslogd_ready (syslog, state);
   syslogd_write (syslog, state);
  }
 }
 if (syslog->next == syslog)
 {
  if ((syslog->f_desc = open (syslog->f_name, 01 | 0400)) != - 1)
  {
   syslogd_write (syslog, state);
   close (syslog->f_desc);
   syslog->f_desc = - 1;
  }
 }
 return;
}

canonical_original_code:
void syslogd_queue(int priority, char *origin, char *notice)
{
 extern unsigned int state;
 extern struct syslogd syslogs;
 struct syslogd *syslog;
 unsigned int facility = (((priority) & 0x03F8) >> 3);
 unsigned int severity = (((priority) & 0x0007) >> 0);
 long now = time (& now);
 if (origin == (char *) (0))
 {
  origin = "";
 }
 if (notice == (char *) (0))
 {
  notice = "";
 }
 for (syslog = syslogs.next; syslog != & syslogs; syslog = syslog->next)
 {
  if (((syslog->f_flags) & ((1 << 0))) != (0))
  {
   continue;
  }
  if (((syslog->f_severity [facility]) & ((1 << severity))) == (0))
  {
   continue;
  }
  if (syslog->f_time > now)
  {
   continue;
  }
  if (!syslog->f_retry)
  {
   strftime (syslog->f_posted, sizeof (syslog->f_posted), "%F %T %Z", localtime (& now));
  }
  if (!strcmp (notice, syslog->f_notice) && !strcmp (origin, syslog->f_origin))
  {
   syslog->f_repeat++;
   continue;
  }
  if (syslog->f_repeat > 0)
  {
   syslog->f_length = snprintf (syslog->f_notice, sizeof (syslog->f_notice), "Previous message received %d times", syslog->f_repeat + 1);
   syslog->f_repeat = 0;
   syslogd_write (syslog, state);
  }
  if (* notice != (char) (0))
  {
   syslog->f_priority = priority;
   strncpy (syslog->f_origin, origin, sizeof (syslog->f_origin));
   strfpri (syslog->f_nature, sizeof (syslog->f_nature), priority);
   strncpy (syslog->f_notice, notice, sizeof (syslog->f_notice));
   syslog->f_repeat = 0;
   syslogd_ready (syslog, state);
   syslogd_write (syslog, state);
  }
 }
 if (syslog->next == syslog)
 {
  if ((syslog->f_desc = open (syslog->f_name, 01 | 0400)) != - 1)
  {
   syslogd_write (syslog, state);
   close (syslog->f_desc);
   syslog->f_desc = - 1;
  }
 }
 return;
}

variable_types:
notice
char *

variable_types:
state
unsigned int

variable_types: struct syslogd { struct syslogd *prev; struct syslogd *next; int f_type; char *f_name; unsigned long f_line; int f_desc; long f_time; unsigned int f_flags; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *f_sockaddr_in; unsigned int f_severity[25]; char f_posted[48]; char f_origin[64]; char f_nature[128]; char f_notice[4096]; unsigned long f_length; unsigned long f_priority; unsigned long f_repeat; unsigned long f_retry; }

variable_types: now long


decompiled_code:
__int64 syslogd_print(unsigned int a1, const char *a2, ...)
{
__int64 v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-10E0h] BYREF
char s[24]; // [rsp+20h] [rbp-10C8h] BYREF
__int64 v6; // [rsp+38h] [rbp-10B0h]
char v7[4064]; // [rsp+40h] [rbp-10A8h] BYREF

strcpy(s, "no error message");
v6 = 0LL;
v2 = 0LL;
memset(v7, 0, sizeof(v7));
if ( program_name )
v2 = snprintf(s, 0x1000uLL, "%s: ", program_name);
if ( a2 && *a2 )
{
va_start(arg, a2);
vsnprintf(&s[v2], 4096 - v2, a2, arg);
}
return syslogd_queue(a1, host_name, s);
}

canonical_decompiled_code:
__int64 func0(unsigned int a1, const char *a2, ...)
{
__int64 v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-10E0h] BYREF
char s[24]; // [rsp+20h] [rbp-10C8h] BYREF
__int64 v6; // [rsp+38h] [rbp-10B0h]
char v7[4064]; // [rsp+40h] [rbp-10A8h] BYREF

strcpy(s, "no error message");
v6 = 0LL;
v2 = 0LL;
memset(v7, 0, sizeof(v7));
if ( program_name )
v2 = snprintf(s, 0x1000uLL, "%s: ", program_name);
if ( a2 && *a2 )
{
va_start(arg, a2);
vsnprintf(&s[v2], 4096 - v2, a2, arg);
}
return syslogd_queue(a1, host_name, s);
}

original_code:
__attribute__ ((format (printf, 2, 3)))
void syslogd_print (int priority, char const * format, ...)
{
 extern char const * host_name;
 extern char const * program_name;
 char buffer [0x1000] = "no error message";
 size_t length = 0;
 if (program_name != (char const *) (0))
 {
  length += snprintf (buffer + length, sizeof (buffer) - length, "%s: ", program_name);
 }
 if ((format != (char const *) (0)) && (* format != (char) (0)))
 {
  va_list arglist;
  __builtin_va_start(arglist,format);
  length += vsnprintf (buffer + length, sizeof (buffer) - length, format, arglist);
  __builtin_va_end(arglist);
 }
 syslogd_queue (priority, host_name, buffer);
 return;
}

canonical_original_code:
void syslogd_print(int priority, char *format, ...)
{
 extern char *host_name;
 extern char *program_name;
 char buffer[4096] = "no error message";
 unsigned long length = 0;
 if (program_name != (char *) (0))
 {
  length += snprintf (buffer + length, sizeof (buffer) - length, "%s: ", program_name);
 }
 if ((format != (char *) (0)) && (* format != (char) (0)))
 {
  __builtin_va_list arglist;
  __builtin_va_start(arglist,format);
  length += vsnprintf (buffer + length, sizeof (buffer) - length, format, arglist);
  __builtin_va_end(arglist);
 }
 syslogd_queue (priority, host_name, buffer);
 return;
}

variable_types:
format
char *

variable_types:
buffer
char [4096]

variable_types:
length
unsigned long


decompiled_code:
int __fastcall syslogd_parse(__int64 a1, unsigned int a2, const char *a3)
{
const char *i; // r15
char v5; // bp
char *v6; // r15
char *j; // r12
char v8; // bp
unsigned int v9; // eax
char *v10; // rbp
unsigned int v11; // edx
unsigned int v12; // er14
char *v13; // rax
char *k; // rbp
char v15; // r12
unsigned int v16; // eax
unsigned int v17; // ebp
const unsigned __int16 *v18; // rcx
unsigned int v19; // eax
char v20; // al
char v22; // [rsp+10h] [rbp-1038h] BYREF
char v23; // [rsp+11h] [rbp-1037h] BYREF

while ( !strchr(" \t", *a3) )
{
for ( i = a3; ; ++i )
{
v5 = *i;
if ( strchr(".; \t", *i) )
break;
}
v6 = (char *)&i[v5 == 46];
for ( j = &v22; ; *(j - 1) = v8 )
{
v8 = *v6;
if ( strchr("; \t", *v6) )
break;
++v6;
++j;
}
*j = 0;
if ( v22 == 33 )
{
v9 = *(_DWORD *)(a1 + 56) | 4;
v10 = &v23;
}
else
{
v9 = *(_DWORD *)(a1 + 56) & 0xFFFFFFFB;
v10 = &v22;
}
v11 = v9 & 0xFFFFFFF7;
if ( *v10 == 61 )
{
v11 = v9 | 8;
++v10;
}
*(_DWORD *)(a1 + 56) = v11;
v12 = syslog_lookup(v10, &syslog_severity_codes);
if ( v12 == -1 )
{
LODWORD(v13) = syslogd_error(22LL, "Don't recognize severity '%s' as per line %d", v10, *(_QWORD *)(a1 + 32));
return (int)v13;
}
while ( !strchr(".; \t", *a3) )
{
for ( k = &v22; ; *(k - 1) = v15 )
{
v15 = *a3;
if ( strchr(",.; \t", *a3) )
break;
++a3;
++k;
}
*k = 0;
v16 = syslog_lookup(&v22, &syslog_facility_codes);
if ( v16 == -1 )
{
LODWORD(v13) = syslogd_error(22LL, "Don't recognize facility '%s' as per line %d", &v22, *(_QWORD *)(a1 + 32));
return (int)v13;
}
if ( v16 == 25 )
{
v17 = 0;
do
syslogd_index(a1, a2, v17++, v12);
while ( v17 != 25 );
}
else
{
syslogd_index(a1, a2, (v16 >> 3) & 0x7F, v12);
}
a3 += *a3 == 44;
}
a3 = &v6[*v6 == 59];
}
v18 = *_ctype_b_loc();
while ( (v18[*a3] & 1) != 0 )
++a3;
if ( *a3 == 45 )
{
v19 = *(_DWORD *)(a1 + 56) & 0xFFFFFFFD;
++a3;
}
else
{
v19 = *(_DWORD *)(a1 + 56) | 2;
}
*(_DWORD *)(a1 + 56) = v19;
v20 = *a3;
if ( *a3 == 64 )
{
*(_DWORD *)(a1 + 16) = 7;
v13 = strdup(a3 + 1);
*(_QWORD *)(a1 + 24) = v13;
return (int)v13;
}
if ( v20 > 64 )
{
if ( v20 == 124 )
{
*(_DWORD *)(a1 + 16) = 2;
v13 = strdup(a3 + 1);
*(_QWORD *)(a1 + 24) = v13;
return (int)v13;
}
LABEL_45:
*(_DWORD *)(a1 + 16) = 5;
v13 = strdup(a3);
*(_QWORD *)(a1 + 24) = v13;
return (int)v13;
}
if ( v20 == 42 )
{
*(_DWORD *)(a1 + 16) = 6;
v13 = strdup("*");
*(_QWORD *)(a1 + 24) = v13;
return (int)v13;
}
if ( v20 != 47 )
goto LABEL_45;
*(_DWORD *)(a1 + 16) = 1;
*(_QWORD *)(a1 + 24) = strdup(a3);
LODWORD(v13) = isatty(*(_DWORD *)(a1 + 40));
if ( (_DWORD)v13 )
{
LODWORD(v13) = (strcmp(a3, "/dev/console") == 0) + 3;
*(_DWORD *)(a1 + 16) = (_DWORD)v13;
}
return (int)v13;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2, const char *a3)
{
const char *i; // r15
char v5; // bp
char *v6; // r15
char *j; // r12
char v8; // bp
unsigned int v9; // eax
char *v10; // rbp
unsigned int v11; // edx
unsigned int v12; // er14
char *v13; // rax
char *k; // rbp
char v15; // r12
unsigned int v16; // eax
unsigned int v17; // ebp
const unsigned __int16 *v18; // rcx
unsigned int v19; // eax
char v20; // al
char v22; // [rsp+10h] [rbp-1038h] BYREF
char v23; // [rsp+11h] [rbp-1037h] BYREF

while ( !strchr(" \t", *a3) )
{
for ( i = a3; ; ++i )
{
v5 = *i;
if ( strchr(".; \t", *i) )
break;
}
v6 = (char *)&i[v5 == 46];
for ( j = &v22; ; *(j - 1) = v8 )
{
v8 = *v6;
if ( strchr("; \t", *v6) )
break;
++v6;
++j;
}
*j = 0;
if ( v22 == 33 )
{
v9 = *(_DWORD *)(a1 + 56) | 4;
v10 = &v23;
}
else
{
v9 = *(_DWORD *)(a1 + 56) & 0xFFFFFFFB;
v10 = &v22;
}
v11 = v9 & 0xFFFFFFF7;
if ( *v10 == 61 )
{
v11 = v9 | 8;
++v10;
}
*(_DWORD *)(a1 + 56) = v11;
v12 = syslog_lookup(v10, &syslog_severity_codes);
if ( v12 == -1 )
{
LODWORD(v13) = syslogd_error(22LL, "Don't recognize severity '%s' as per line %d", v10, *(_QWORD *)(a1 + 32));
return (int)v13;
}
while ( !strchr(".; \t", *a3) )
{
for ( k = &v22; ; *(k - 1) = v15 )
{
v15 = *a3;
if ( strchr(",.; \t", *a3) )
break;
++a3;
++k;
}
*k = 0;
v16 = syslog_lookup(&v22, &syslog_facility_codes);
if ( v16 == -1 )
{
LODWORD(v13) = syslogd_error(22LL, "Don't recognize facility '%s' as per line %d", &v22, *(_QWORD *)(a1 + 32));
return (int)v13;
}
if ( v16 == 25 )
{
v17 = 0;
do
syslogd_index(a1, a2, v17++, v12);
while ( v17 != 25 );
}
else
{
syslogd_index(a1, a2, (v16 >> 3) & 0x7F, v12);
}
a3 += *a3 == 44;
}
a3 = &v6[*v6 == 59];
}
v18 = *_ctype_b_loc();
while ( (v18[*a3] & 1) != 0 )
++a3;
if ( *a3 == 45 )
{
v19 = *(_DWORD *)(a1 + 56) & 0xFFFFFFFD;
++a3;
}
else
{
v19 = *(_DWORD *)(a1 + 56) | 2;
}
*(_DWORD *)(a1 + 56) = v19;
v20 = *a3;
if ( *a3 == 64 )
{
*(_DWORD *)(a1 + 16) = 7;
v13 = strdup(a3 + 1);
*(_QWORD *)(a1 + 24) = v13;
return (int)v13;
}
if ( v20 > 64 )
{
if ( v20 == 124 )
{
*(_DWORD *)(a1 + 16) = 2;
v13 = strdup(a3 + 1);
*(_QWORD *)(a1 + 24) = v13;
return (int)v13;
}
LABEL_45:
*(_DWORD *)(a1 + 16) = 5;
v13 = strdup(a3);
*(_QWORD *)(a1 + 24) = v13;
return (int)v13;
}
if ( v20 == 42 )
{
*(_DWORD *)(a1 + 16) = 6;
v13 = strdup("*");
*(_QWORD *)(a1 + 24) = v13;
return (int)v13;
}
if ( v20 != 47 )
goto LABEL_45;
*(_DWORD *)(a1 + 16) = 1;
*(_QWORD *)(a1 + 24) = strdup(a3);
LODWORD(v13) = isatty(*(_DWORD *)(a1 + 40));
if ( (_DWORD)v13 )
{
LODWORD(v13) = (strcmp(a3, "/dev/console") == 0) + 3;
*(_DWORD *)(a1 + 16) = (_DWORD)v13;
}
return (int)v13;
}

original_code:
void syslogd_parse (struct syslogd * syslog, flag_t flags, char const * string)
{
 extern const struct _code_ syslog_facility_codes [];
 extern const struct _code_ syslog_severity_codes [];
 facility_t facility = (facility_t) (0);
 severity_t severity = (severity_t) (0);
 char symbol [0x1000];
 char const * sp;
 char * cp;
 while (!strchr (" \t", * string))
 {
  for (sp = string; !strchr (".; \t", * string); string++);
  if (* string == '.')
  {
   string++;
  }
  for (cp = symbol; !strchr ("; \t", * string); * cp++ = * string++);
  * cp = '\0';
  cp = symbol;
  if (* cp == '!')
  {
   syslog->f_flags |= ((1 << 2));
   cp++;
  }
  else
  {
   syslog->f_flags &= ~((1 << 2));
  }
  if (* cp == '=')
  {
   syslog->f_flags |= ((1 << 3));
   cp++;
  }
  else
  {
   syslog->f_flags &= ~((1 << 3));
  }
  if ((severity = syslog_lookup (cp, syslog_severity_codes)) == - 1)
  {
   syslogd_error (22, "Don't recognize severity '%s' as per line %d", cp, syslog->f_line);
   return;
  }
  while (!strchr (".; \t", * sp))
  {
   for (cp = symbol; !strchr (",.; \t", * sp); * cp++ = * sp++);
   * cp = (char) (0);
   if ((facility = syslog_lookup (symbol, syslog_facility_codes)) == - 1)
   {
    syslogd_error (22, "Don't recognize facility '%s' as per line %d", symbol, syslog->f_line);
    return;
   }
   if (facility == 25)
   {
    for (facility = 0; facility < 25; facility++)
    {
     syslogd_index (syslog, flags, facility, severity);
    }
   }
   else
   {
    facility = (((facility) & 0x03F8) >> 3);
    syslogd_index (syslog, flags, facility, severity);
   }
   if (* sp == ',')
   {
    sp++;
   }
  }
  if (* string == ';')
  {
   string++;
  }
 }
 while (((*__ctype_b_loc ())[(int) ((* string))] & (unsigned short int) _ISblank))
 {
  string++;
 }
 if (* string == '-')
 {
  syslog->f_flags &= ~((1 << 1));
  string++;
 }
 else
 {
  syslog->f_flags |= ((1 << 1));
 }
 switch (* string)
 {
 case '@':
  syslog->f_type = 7;
  syslog->f_name = strdup (++ string);
  break;
 case '|':
  syslog->f_type = 2;
  syslog->f_name = strdup (++ string);
  break;
 case '/':
  syslog->f_type = 1;
  syslog->f_name = strdup (string);
  if (isatty (syslog->f_desc))
  {
   if (!strcmp (string, "/dev/console"))
   {
    syslog->f_type = 4;
    break;
   }
   syslog->f_type = 3;
  }
  break;
 case '*':
  syslog->f_type = 6;
  syslog->f_name = strdup ("*");
  break;
 default:
  syslog->f_type = 5;
  syslog->f_name = strdup (string);
  break;
 }
 return;
}

canonical_original_code:
void syslogd_parse(struct syslogd *syslog, unsigned int flags, char *string)
{
 extern struct _code_ syslog_facility_codes[];
 extern struct _code_ syslog_severity_codes[];
 unsigned int facility = (facility_t) (0);
 unsigned int severity = (severity_t) (0);
 char symbol[4096];
 char *sp;
 char *cp;
 while (!strchr (" \t", * string))
 {
  for (sp = string; !strchr (".; \t", * string); string++);
  if (* string == '.')
  {
   string++;
  }
  for (cp = symbol; !strchr ("; \t", * string); * cp++ = * string++);
  * cp = '\0';
  cp = symbol;
  if (* cp == '!')
  {
   syslog->f_flags |= ((1 << 2));
   cp++;
  }
  else
  {
   syslog->f_flags &= ~((1 << 2));
  }
  if (* cp == '=')
  {
   syslog->f_flags |= ((1 << 3));
   cp++;
  }
  else
  {
   syslog->f_flags &= ~((1 << 3));
  }
  if ((severity = syslog_lookup (cp, syslog_severity_codes)) == - 1)
  {
   syslogd_error (22, "Don't recognize severity '%s' as per line %d", cp, syslog->f_line);
   return;
  }
  while (!strchr (".; \t", * sp))
  {
   for (cp = symbol; !strchr (",.; \t", * sp); * cp++ = * sp++);
   * cp = (char) (0);
   if ((facility = syslog_lookup (symbol, syslog_facility_codes)) == - 1)
   {
    syslogd_error (22, "Don't recognize facility '%s' as per line %d", symbol, syslog->f_line);
    return;
   }
   if (facility == 25)
   {
    for (facility = 0; facility < 25; facility++)
    {
     syslogd_index (syslog, flags, facility, severity);
    }
   }
   else
   {
    facility = (((facility) & 0x03F8) >> 3);
    syslogd_index (syslog, flags, facility, severity);
   }
   if (* sp == ',')
   {
    sp++;
   }
  }
  if (* string == ';')
  {
   string++;
  }
 }
 while (((*__ctype_b_loc ())[(int) ((* string))] & (unsigned short) _ISblank))
 {
  string++;
 }
 if (* string == '-')
 {
  syslog->f_flags &= ~((1 << 1));
  string++;
 }
 else
 {
  syslog->f_flags |= ((1 << 1));
 }
 switch (* string)
 {
 case '@':
  syslog->f_type = 7;
  syslog->f_name = strdup (++ string);
  break;
 case '|':
  syslog->f_type = 2;
  syslog->f_name = strdup (++ string);
  break;
 case '/':
  syslog->f_type = 1;
  syslog->f_name = strdup (string);
  if (isatty (syslog->f_desc))
  {
   if (!strcmp (string, "/dev/console"))
   {
    syslog->f_type = 4;
    break;
   }
   syslog->f_type = 3;
  }
  break;
 case '*':
  syslog->f_type = 6;
  syslog->f_name = strdup ("*");
  break;
 default:
  syslog->f_type = 5;
  syslog->f_name = strdup (string);
  break;
 }
 return;
}

variable_types:
string
char *

variable_types: struct _code_ { int code; char *name; } []

variable_types:
symbol
char [4096]

variable_types:
cp
char *


decompiled_code:
void __fastcall syslogd_close_sockets(__int64 *a1)
{
__int64 *v1; // rbx
const char *v2; // rbp
__int64 v3; // rdx
int *v4; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = a1;
do
{
v1 = (__int64 *)*v1;
if ( *((int *)v1 + 4) >= 0 )
{
v3 = v1[4];
if ( v3 )
{
if ( *(_WORD *)v3 == 1 )
{
v2 = (const char *)(v3 + 2);
syslogd_print(45LL, "Closing host connection on %s", (const char *)(v3 + 2));
close(*((_DWORD *)v1 + 4));
if ( unlink(v2) )
{
v4 = _errno_location();
syslogd_error((unsigned int)*v4, "Can't remove socket %s", v2);
}
*((_DWORD *)v1 + 4) = -1;
}
else if ( *(_WORD *)v3 == 2 )
{
getsocketname(v5, 32LL);
syslogd_print(45LL, "Closing inet connection on %s", v5);
close(*((_DWORD *)v1 + 4));
*((_DWORD *)v1 + 4) = -1;
}
}
else
{
syslogd_error(22LL, "Invalid socket address structure");
}
}
}
while ( a1 != v1 );
}

canonical_decompiled_code:
void __fastcall func0(__int64 *a1)
{
__int64 *v1; // rbx
const char *v2; // rbp
__int64 v3; // rdx
int *v4; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = a1;
do
{
v1 = (__int64 *)*v1;
if ( *((int *)v1 + 4) >= 0 )
{
v3 = v1[4];
if ( v3 )
{
if ( *(_WORD *)v3 == 1 )
{
v2 = (const char *)(v3 + 2);
syslogd_print(45LL, "Closing host connection on %s", (const char *)(v3 + 2));
close(*((_DWORD *)v1 + 4));
if ( unlink(v2) )
{
v4 = _errno_location();
syslogd_error((unsigned int)*v4, "Can't remove socket %s", v2);
}
*((_DWORD *)v1 + 4) = -1;
}
else if ( *(_WORD *)v3 == 2 )
{
getsocketname(v5, 32LL);
syslogd_print(45LL, "Closing inet connection on %s", v5);
close(*((_DWORD *)v1 + 4));
*((_DWORD *)v1 + 4) = -1;
}
}
else
{
syslogd_error(22LL, "Invalid socket address structure");
}
}
}
while ( a1 != v1 );
}

original_code:
void syslogd_close_sockets (struct socket * sockets)
{
 struct socket * socket = sockets;
 char buffer [0x0020];
 do
 {
  socket = socket->next;
  if (socket->desc < 0)
  {
   continue;
  }
  if (socket->sockaddr == (struct sockaddr *) (0))
  {
   syslogd_error (22, "Invalid socket address structure");
   continue;
  }
  if (socket->sockaddr->sa_family == 1)
  {
   struct sockaddr_un * sockaddr_un = (struct sockaddr_un *) (socket->sockaddr);
   syslogd_print ((5 << 3) | 5, "Closing host connection on %s", sockaddr_un->sun_path);
   close (socket->desc);
   if (unlink (sockaddr_un->sun_path))
   {
    syslogd_error ((*__errno_location ()), "Can't remove socket %s", sockaddr_un->sun_path);
   }
   socket->desc = - 1;
   continue;
  }
  if (socket->sockaddr->sa_family == 2)
  {
   struct sockaddr_in * sockaddr_in = (struct sockaddr_in *) (socket->sockaddr);
   getsocketname (buffer, sizeof (buffer), sockaddr_in);
   syslogd_print ((5 << 3) | 5, "Closing inet connection on %s", buffer);
   close (socket->desc);
   socket->desc = - 1;
   continue;
  }
 }
 while (socket != sockets);
 return;
}

canonical_original_code:
void syslogd_close_sockets(struct socket *sockets)
{
 struct socket *socket = sockets;
 char buffer[32];
 do
 {
  socket = socket->next;
  if (socket->desc < 0)
  {
   continue;
  }
  if (socket->sockaddr == (struct sockaddr *) (0))
  {
   syslogd_error (22, "Invalid socket address structure");
   continue;
  }
  if (socket->sockaddr->sa_family == 1)
  {
   struct sockaddr_un *sockaddr_un = (struct sockaddr_un *) (socket->sockaddr);
   syslogd_print ((5 << 3) | 5, "Closing host connection on %s", sockaddr_un->sun_path);
   close (socket->desc);
   if (unlink (sockaddr_un->sun_path))
   {
    syslogd_error ((*__errno_location ()), "Can't remove socket %s", sockaddr_un->sun_path);
   }
   socket->desc = - 1;
   continue;
  }
  if (socket->sockaddr->sa_family == 2)
  {
   struct sockaddr_in *sockaddr_in = (struct sockaddr_in *) (socket->sockaddr);
   getsocketname (buffer, sizeof (buffer), sockaddr_in);
   syslogd_print ((5 << 3) | 5, "Closing inet connection on %s", buffer);
   close (socket->desc);
   socket->desc = - 1;
   continue;
  }
 }
 while (socket != sockets);
 return;
}

variable_types: struct socket { struct socket *next; struct socket *prev; int desc; unsigned long socksize; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *sockaddr; char *buffer; } *

variable_types:
buffer
char [32]

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

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


symsort

decompiled_code:
__int64 __fastcall symsort(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 >= *(_QWORD *)a2 )
result = *(_QWORD *)a1 > *(_QWORD *)a2;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 >= *(_QWORD *)a2 )
result = *(_QWORD *)a1 > *(_QWORD *)a2;
return result;
}

original_code:
static int symsort (void const * p1, void const * p2)
{
 const struct module_symbol * symbol1 = p1;
 const struct module_symbol * symbol2 = p2;
 if (symbol1->value < symbol2->value)
 {
  return (- 1);
 }
 if (symbol1->value > symbol2->value)
 {
  return (1);
 }
 return (0);
}

canonical_original_code:
static int symsort(void *p1, void *p2)
{
 struct module_symbol *symbol1 = p1;
 struct module_symbol *symbol2 = p2;
 if (symbol1->value < symbol2->value)
 {
  return (- 1);
 }
 if (symbol1->value > symbol2->value)
 {
  return (1);
 }
 return (0);
}

variable_types: struct module_symbol { unsigned long value; char *name; } *


InitMsyms

decompiled_code:
__int64 InitMsyms()
{
int v0; // eax
int v1; // ebx
char *v2; // rax
char *v3; // r12
int v4; // eax
const char *v5; // rbx
__int64 v6; // r13
unsigned int v7; // ebp
__int64 v8; // rbx
unsigned int v9; // ebp
int v10; // edi
char *v11; // rax
int *v12; // rax
char *v13; // rax
char *v14; // rax
int v15; // esi
const char *v16; // r9
const char *v17; // rcx

FreeModules();
v0 = get_kernel_syms(0LL);
if ( v0 < 0 )
{
v10 = *_errno_location();
if ( v10 == 38 )
{
Syslog(6LL, "No module symbols loaded - kernel modules not enabled.\n");
}
else
{
v11 = strerror(v10);
Syslog(3LL, "Error loading kernel symbols - %s\n", v11);
}
v7 = 0;
}
else
{
v1 = v0;
if ( debugging )
fprintf(stderr, "Loading kernel module symbols - Size of table: %d\n", (unsigned int)v0);
v2 = (char *)malloc(72LL * v1);
v3 = v2;
if ( v2 )
{
v4 = get_kernel_syms(v2);
if ( v4 < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
Syslog(4LL, "Error reading kernel symbols - %s\n", v13);
v7 = 0;
}
else if ( v4 )
{
v5 = v3 + 8;
v6 = (__int64)&v3[72 * (v4 - 1) + 80];
while ( 1 )
{
v7 = AddModule(*((_QWORD *)v5 - 1), v5);
if ( !v7 )
break;
v5 += 72;
if ( v5 == (const char *)v6 )
goto LABEL_10;
}
Syslog(4LL, "Error adding kernel module table entry.\n");
free(v3);
}
else
{
if ( num_modules <= 0 )
goto LABEL_30;
LABEL_10:
v8 = 0LL;
v9 = 0;
do
{
v14 = (char *)symbols_modules + 168 * v8;
v15 = *((_DWORD *)v14 + 32);
v9 += v15;
if ( v15 > 1 )
qsort(*((void **)v14 + 15), v15, 0x10uLL, (__compar_fn_t)symsort);
++v8;
}
while ( num_modules > (int)v8 );
if ( v9 )
{
v16 = ".";
if ( num_modules != 1 )
v16 = "s.";
v17 = "symbol";
if ( v9 != 1 )
v17 = "symbols";
Syslog(6LL, "Loaded %d %s from %d module%s", v9, v17, (unsigned int)num_modules, v16);
}
else
{
LABEL_30:
Syslog(6LL, "No module symbols loaded.");
}
free(v3);
v7 = 1;
}
}
else
{
Syslog(4LL, " Failed memory allocation for kernel symbol table.\n");
v7 = 0;
}
}
return v7;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
int v1; // ebx
char *v2; // rax
char *v3; // r12
int v4; // eax
const char *v5; // rbx
__int64 v6; // r13
unsigned int v7; // ebp
__int64 v8; // rbx
unsigned int v9; // ebp
int v10; // edi
char *v11; // rax
int *v12; // rax
char *v13; // rax
char *v14; // rax
int v15; // esi
const char *v16; // r9
const char *v17; // rcx

func1();
v0 = get_kernel_syms(0LL);
if ( v0 < 0 )
{
v10 = *_errno_location();
if ( v10 == 38 )
{
Syslog(6LL, "No module symbols loaded - kernel modules not enabled.\n");
}
else
{
v11 = strerror(v10);
Syslog(3LL, "Error loading kernel symbols - %s\n", v11);
}
v7 = 0;
}
else
{
v1 = v0;
if ( debugging )
fprintf(stderr, "Loading kernel module symbols - Size of table: %d\n", (unsigned int)v0);
v2 = (char *)malloc(72LL * v1);
v3 = v2;
if ( v2 )
{
v4 = get_kernel_syms(v2);
if ( v4 < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
Syslog(4LL, "Error reading kernel symbols - %s\n", v13);
v7 = 0;
}
else if ( v4 )
{
v5 = v3 + 8;
v6 = (__int64)&v3[72 * (v4 - 1) + 80];
while ( 1 )
{
v7 = func3(*((_QWORD *)v5 - 1), v5);
if ( !v7 )
break;
v5 += 72;
if ( v5 == (const char *)v6 )
goto LABEL_10;
}
Syslog(4LL, "Error adding kernel module table entry.\n");
free(v3);
}
else
{
if ( num_modules <= 0 )
goto LABEL_30;
LABEL_10:
v8 = 0LL;
v9 = 0;
do
{
v14 = (char *)symbols_modules + 168 * v8;
v15 = *((_DWORD *)v14 + 32);
v9 += v15;
if ( v15 > 1 )
qsort(*((void **)v14 + 15), v15, 0x10uLL, (__compar_fn_t)symsort);
++v8;
}
while ( num_modules > (int)v8 );
if ( v9 )
{
v16 = ".";
if ( num_modules != 1 )
v16 = "s.";
v17 = "symbol";
if ( v9 != 1 )
v17 = "symbols";
Syslog(6LL, "Loaded %d %s from %d module%s", v9, v17, (unsigned int)num_modules, v16);
}
else
{
LABEL_30:
Syslog(6LL, "No module symbols loaded.");
}
free(v3);
v7 = 1;
}
}
else
{
Syslog(4LL, " Failed memory allocation for kernel symbol table.\n");
v7 = 0;
}
}
return v7;
}

original_code:
extern int InitMsyms ()
{
 auto int rtn,
 tmp;
 auto struct kernel_sym * kmodule_symbol,
 * p;
 FreeModules ();
 if ((rtn = get_kernel_syms ((struct kernel_sym *) 0)) < 0)
 {
  if ((*__errno_location ()) == 38) Syslog (6, "No module symbols loaded - kernel modules not enabled.\n");
  else Syslog (3, "Error loading kernel symbols - %s\n", strerror ((*__errno_location ())));
  return (0);
 }
 if (debugging) fprintf (stderr, "Loading kernel module symbols - Size of table: %d\n", rtn);
 kmodule_symbol = (struct kernel_sym *) malloc (rtn * sizeof (struct kernel_sym));
 if (kmodule_symbol == (struct kernel_sym *) 0)
 {
  Syslog (4, " Failed memory allocation for kernel symbol table.\n");
  return (0);
 }
 if ((rtn = get_kernel_syms (kmodule_symbol)) < 0)
 {
  Syslog (4, "Error reading kernel symbols - %s\n", strerror ((*__errno_location ())));
  return (0);
 }
 tmp = rtn;
 p = kmodule_symbol;
 while (tmp--)
 {
  if (!AddModule (p->value, p->name))
  {
   Syslog (4, "Error adding kernel module table " "entry.\n");
   free (kmodule_symbol);
   return (0);
  }
  ++ p;
 }
 for (rtn = tmp = 0; tmp < num_modules; ++ tmp)
 {
  rtn += symbols_modules [tmp].num_syms;
  if (symbols_modules [tmp].num_syms < 2) continue;
  qsort (symbols_modules [tmp].symbols, symbols_modules [tmp].num_syms, sizeof (struct module_symbol), symsort);
 }
 if (rtn == 0) Syslog (6, "No module symbols loaded.");
 else Syslog (6, "Loaded %d %s from %d module%s", rtn, (rtn == 1)? "symbol": "symbols", num_modules, (num_modules == 1)? ".": "s.");
 free (kmodule_symbol);
 return (1);
}

canonical_original_code:
extern int InitMsyms()
{
 auto int rtn; auto int tmp;
 auto struct kernel_sym *kmodule_symbol; auto struct kernel_sym *p;
 FreeModules ();
 if ((rtn = get_kernel_syms ((struct kernel_sym *) 0)) < 0)
 {
  if ((*__errno_location ()) == 38) Syslog (6, "No module symbols loaded - kernel modules not enabled.\n");
  else Syslog (3, "Error loading kernel symbols - %s\n", strerror ((*__errno_location ())));
  return (0);
 }
 if (debugging) fprintf (stderr, "Loading kernel module symbols - Size of table: %d\n", rtn);
 kmodule_symbol = (struct kernel_sym *) malloc (rtn * sizeof (struct kernel_sym));
 if (kmodule_symbol == (struct kernel_sym *) 0)
 {
  Syslog (4, " Failed memory allocation for kernel symbol table.\n");
  return (0);
 }
 if ((rtn = get_kernel_syms (kmodule_symbol)) < 0)
 {
  Syslog (4, "Error reading kernel symbols - %s\n", strerror ((*__errno_location ())));
  return (0);
 }
 tmp = rtn;
 p = kmodule_symbol;
 while (tmp--)
 {
  if (!AddModule (p->value, p->name))
  {
   Syslog (4, "Error adding kernel module table " "entry.\n");
   free (kmodule_symbol);
   return (0);
  }
  ++ p;
 }
 for (rtn = tmp = 0; tmp < num_modules; ++ tmp)
 {
  rtn += symbols_modules [tmp].num_syms;
  if (symbols_modules [tmp].num_syms < 2) continue;
  qsort (symbols_modules [tmp].symbols, symbols_modules [tmp].num_syms, sizeof (struct module_symbol), symsort);
 }
 if (rtn == 0) Syslog (6, "No module symbols loaded.");
 else Syslog (6, "Loaded %d %s from %d module%s", rtn, (rtn == 1)? "symbol": "symbols", num_modules, (num_modules == 1)? ".": "s.");
 free (kmodule_symbol);
 return (1);
}

variable_types: rtn int

variable_types: tmp int

variable_types: struct kernel_sym { unsigned long value; char name[60]; } *

user_defined_types: struct module_symbol { unsigned long value; char *name; }


decompiled_code:
__int64 __fastcall syslogd_inet_socket(struct sockaddr *addr)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rax
int *v5; // rax
int *v6; // rax
int optval; // [rsp+Ch] [rbp-3Ch] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

optval = 1;
v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 == -1 )
{
getsocketname(v8, 32LL, addr);
v4 = _errno_location();
syslogd_error((unsigned int)*v4, "Can't allocate socket for %s", v8);
}
else if ( setsockopt(v1, 1, 2, &optval, 4u) == -1 )
{
getsocketname(v8, 32LL, addr);
v5 = _errno_location();
syslogd_error((unsigned int)*v5, "Can't set socket options for %s", v8);
close(v2);
v2 = -1;
}
else if ( bind(v2, addr, 0x10u) == -1 )
{
getsocketname(v8, 32LL, addr);
v6 = _errno_location();
syslogd_error((unsigned int)*v6, "Can't connect to %s", v8);
close(v2);
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(struct sockaddr *addr)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rax
int *v5; // rax
int *v6; // rax
int optval; // [rsp+Ch] [rbp-3Ch] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

optval = 1;
v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 == -1 )
{
getsocketname(v8, 32LL, addr);
v4 = _errno_location();
syslogd_error((unsigned int)*v4, "Can't allocate socket for %s", v8);
}
else if ( setsockopt(v1, 1, 2, &optval, 4u) == -1 )
{
getsocketname(v8, 32LL, addr);
v5 = _errno_location();
syslogd_error((unsigned int)*v5, "Can't set socket options for %s", v8);
close(v2);
v2 = -1;
}
else if ( bind(v2, addr, 0x10u) == -1 )
{
getsocketname(v8, 32LL, addr);
v6 = _errno_location();
syslogd_error((unsigned int)*v6, "Can't connect to %s", v8);
close(v2);
v2 = -1;
}
return v2;
}

original_code:
file_t syslogd_inet_socket (struct sockaddr_in * sockaddr_in)
{
 char buffer [0x0020];
 bool_t state = true;
 file_t fd;
 if ((fd = socket (2, SOCK_DGRAM, 0)) == - 1)
 {
  getsocketname (buffer, sizeof (buffer), sockaddr_in);
  syslogd_error ((*__errno_location ()), "Can't allocate socket for %s", buffer);
  return (- 1);
 }
 if (setsockopt (fd, 1, 2, (char *) (& state), sizeof (state)) == - 1)
 {
  getsocketname (buffer, sizeof (buffer), sockaddr_in);
  syslogd_error ((*__errno_location ()), "Can't set socket options for %s", buffer);
  close (fd);
  return (- 1);
 }
 if (bind (fd, (struct sockaddr *) (sockaddr_in), sizeof (struct sockaddr_in)) == - 1)
 {
  getsocketname (buffer, sizeof (buffer), sockaddr_in);
  syslogd_error ((*__errno_location ()), "Can't connect to %s", buffer);
  close (fd);
  return (- 1);
 }
 return (fd);
}

canonical_original_code:
int syslogd_inet_socket(struct sockaddr_in *sockaddr_in)
{
 char buffer[32];
 int state = true;
 int fd;
 if ((fd = socket (2, SOCK_DGRAM, 0)) == - 1)
 {
  getsocketname (buffer, sizeof (buffer), sockaddr_in);
  syslogd_error ((*__errno_location ()), "Can't allocate socket for %s", buffer);
  return (- 1);
 }
 if (setsockopt (fd, 1, 2, (char *) (& state), sizeof (state)) == - 1)
 {
  getsocketname (buffer, sizeof (buffer), sockaddr_in);
  syslogd_error ((*__errno_location ()), "Can't set socket options for %s", buffer);
  close (fd);
  return (- 1);
 }
 if (bind (fd, (struct sockaddr *) (sockaddr_in), sizeof (struct sockaddr_in)) == - 1)
 {
  getsocketname (buffer, sizeof (buffer), sockaddr_in);
  syslogd_error ((*__errno_location ()), "Can't connect to %s", buffer);
  close (fd);
  return (- 1);
 }
 return (fd);
}

variable_types: state int

variable_types: fd int


decompiled_code:
void __fastcall syslogd_open_sockets(__int64 *a1)
{
__int64 *v1; // rbx
__int64 v2; // rbp
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = a1;
do
{
v1 = (__int64 *)*v1;
if ( *((_DWORD *)v1 + 4) == -1 )
{
v2 = v1[4];
if ( v2 )
{
if ( *(_WORD *)v2 == 1 )
{
syslogd_print(45LL, "Opening host connection on %s", (const char *)(v2 + 2));
*((_DWORD *)v1 + 4) = syslogd_unix_socket(v2);
}
else if ( *(_WORD *)v2 == 2 )
{
getsocketname(v3, 32LL, v1[4]);
syslogd_print(45LL, "Opening inet connection on %s", v3);
*((_DWORD *)v1 + 4) = syslogd_inet_socket(v2);
}
}
else
{
syslogd_error(22LL, "Missing socket address");
}
}
}
while ( a1 != v1 );
}

canonical_decompiled_code:
void __fastcall func0(__int64 *a1)
{
__int64 *v1; // rbx
__int64 v2; // rbp
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = a1;
do
{
v1 = (__int64 *)*v1;
if ( *((_DWORD *)v1 + 4) == -1 )
{
v2 = v1[4];
if ( v2 )
{
if ( *(_WORD *)v2 == 1 )
{
syslogd_print(45LL, "Opening host connection on %s", (const char *)(v2 + 2));
*((_DWORD *)v1 + 4) = syslogd_unix_socket(v2);
}
else if ( *(_WORD *)v2 == 2 )
{
getsocketname(v3, 32LL, v1[4]);
syslogd_print(45LL, "Opening inet connection on %s", v3);
*((_DWORD *)v1 + 4) = syslogd_inet_socket(v2);
}
}
else
{
syslogd_error(22LL, "Missing socket address");
}
}
}
while ( a1 != v1 );
}

original_code:
void syslogd_open_sockets (struct socket * sockets)
{
 struct socket * socket = sockets;
 do
 {
  socket = socket->next;
  if (socket->desc != - 1)
  {
   continue;
  }
  if (socket->sockaddr == (struct sockaddr *) (0))
  {
   syslogd_error (22, "Missing socket address");
   continue;
  }
  if (socket->sockaddr->sa_family == 1)
  {
   struct sockaddr_un * sockaddr_un = (struct sockaddr_un *) (socket->sockaddr);
   syslogd_print ((5 << 3) | 5, "Opening host connection on %s", sockaddr_un->sun_path);
   socket->desc = syslogd_unix_socket (sockaddr_un);
   continue;
  }
  if (socket->sockaddr->sa_family == 2)
  {
   char buffer [0x0020];
   struct sockaddr_in * sockaddr_in = (struct sockaddr_in *) (socket->sockaddr);
   getsocketname (buffer, sizeof (buffer), sockaddr_in);
   syslogd_print ((5 << 3) | 5, "Opening inet connection on %s", buffer);
   socket->desc = syslogd_inet_socket (sockaddr_in);
   continue;
  }
 }
 while (socket != sockets);
 return;
}

canonical_original_code:
void syslogd_open_sockets(struct socket *sockets)
{
 struct socket *socket = sockets;
 do
 {
  socket = socket->next;
  if (socket->desc != - 1)
  {
   continue;
  }
  if (socket->sockaddr == (struct sockaddr *) (0))
  {
   syslogd_error (22, "Missing socket address");
   continue;
  }
  if (socket->sockaddr->sa_family == 1)
  {
   struct sockaddr_un *sockaddr_un = (struct sockaddr_un *) (socket->sockaddr);
   syslogd_print ((5 << 3) | 5, "Opening host connection on %s", sockaddr_un->sun_path);
   socket->desc = syslogd_unix_socket (sockaddr_un);
   continue;
  }
  if (socket->sockaddr->sa_family == 2)
  {
   char buffer[32];
   struct sockaddr_in *sockaddr_in = (struct sockaddr_in *) (socket->sockaddr);
   getsocketname (buffer, sizeof (buffer), sockaddr_in);
   syslogd_print ((5 << 3) | 5, "Opening inet connection on %s", buffer);
   socket->desc = syslogd_inet_socket (sockaddr_in);
   continue;
  }
 }
 while (socket != sockets);
 return;
}

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


strfpri

decompiled_code:
__int64 __fastcall strfpri(char *a1, size_t a2, __int16 a3)
{
const char *v3; // rcx
char *v4; // rax
const char *v5; // r9
char *v6; // rax
int i; // edx

v3 = (const char *)syslog_facility_codes[1];
if ( v3 )
{
v4 = (char *)syslog_facility_codes;
do
{
if ( *(_DWORD *)v4 == (a3 & 0x3F8) )
break;
v4 += 16;
v3 = (const char *)*((_QWORD *)v4 + 1);
}
while ( v3 );
}
v5 = (const char *)syslog_severity_codes[1];
v6 = (char *)syslog_severity_codes;
for ( i = a3 & 7; v5; v5 = (const char *)*((_QWORD *)v6 + 1) )
{
if ( *(_DWORD *)v6 == i )
break;
v6 += 16;
}
return snprintf(a1, a2, "%s%c%s", v3, 46LL, v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, size_t a2, __int16 a3)
{
const char *v3; // rcx
char *v4; // rax
const char *v5; // r9
char *v6; // rax
int i; // edx

v3 = (const char *)syslog_facility_codes[1];
if ( v3 )
{
v4 = (char *)syslog_facility_codes;
do
{
if ( *(_DWORD *)v4 == (a3 & 0x3F8) )
break;
v4 += 16;
v3 = (const char *)*((_QWORD *)v4 + 1);
}
while ( v3 );
}
v5 = (const char *)syslog_severity_codes[1];
v6 = (char *)syslog_severity_codes;
for ( i = a3 & 7; v5; v5 = (const char *)*((_QWORD *)v6 + 1) )
{
if ( *(_DWORD *)v6 == i )
break;
v6 += 16;
}
return snprintf(a1, a2, "%s%c%s", v3, 46LL, v5);
}

original_code:
size_t strfpri (char buffer [], size_t length, flag_t option)
{
 extern const struct _code_ syslog_facility_codes [];
 extern const struct _code_ syslog_severity_codes [];
 const struct _code_ * facility;
 const struct _code_ * priority;
 for (facility = syslog_facility_codes; facility->name != (char *) (0); facility++)
 {
  if (facility->code == (option & 0x03F8))
  {
   break;
  }
 }
 for (priority = syslog_severity_codes; priority->name != (char *) (0); priority++)
 {
  if (priority->code == (option & 0x0007))
  {
   break;
  }
 }
 length = snprintf (buffer, length, "%s%c%s", facility->name, '.', priority->name);
 return (length);
}

canonical_original_code:
unsigned long strfpri(char buffer[], unsigned long length, unsigned int option)
{
 extern struct _code_ syslog_facility_codes[];
 extern struct _code_ syslog_severity_codes[];
 struct _code_ *facility;
 struct _code_ *priority;
 for (facility = syslog_facility_codes; facility->name != (char *) (0); facility++)
 {
  if (facility->code == (option & 0x03F8))
  {
   break;
  }
 }
 for (priority = syslog_severity_codes; priority->name != (char *) (0); priority++)
 {
  if (priority->code == (option & 0x0007))
  {
   break;
  }
 }
 length = snprintf (buffer, length, "%s%c%s", facility->name, '.', priority->name);
 return (length);
}

variable_types:
buffer
char []

variable_types:
option
unsigned int

variable_types: struct _code_ { int code; char *name; } *

return_type: unsigned long


decompiled_code:
char *__fastcall syslogd_gethost(__int64 a1, const char **a2, const char **a3)
{
char *v3; // rbx
struct hostent *v6; // rax
struct hostent *v7; // r15
char v8; // bp
const unsigned __int16 **v9; // r12
char v10; // al
char *v11; // r13
const char *v12; // rbp
const char *v13; // rbp
char *s2; // [rsp+8h] [rbp-40h]

v3 = "nohost";
if ( *(_WORD *)a1 == 2 )
{
v6 = gethostbyaddr((const void *)(a1 + 4), 4u, 2);
v7 = v6;
if ( v6 )
{
v3 = v6->h_name;
v8 = *v6->h_name;
if ( v8 )
{
v9 = _ctype_b_loc();
do
{
if ( ((*v9)[v8] & 0x100) != 0 )
*v3 = (*_ctype_tolower_loc())[v8];
v8 = *++v3;
}
while ( *v3 );
v3 = v7->h_name;
v10 = *v7->h_name;
if ( v10 )
{
s2 = (char *)domain_name;
v11 = v7->h_name;
do
{
if ( v10 == 46 )
{
if ( !strcmp(v11 + 1, s2) )
{
*v11 = 0;
return v7->h_name;
}
if ( a3 )
{
v13 = *a3;
while ( v13 )
{
if ( !strcmp(v11 + 1, v13) )
{
*v11 = 0;
return v7->h_name;
}
}
if ( a2 )
{
v12 = *a2;
while ( v12 )
{
if ( !strcmp(v3, v12) )
{
*v11 = 0;
return v7->h_name;
}
}
}
}
}
v10 = *++v11;
}
while ( *v11 );
}
}
}
else
{
v3 = inet_ntoa(*(struct in_addr *)(a1 + 4));
}
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, const char **a2, const char **a3)
{
char *v3; // rbx
struct hostent *v6; // rax
struct hostent *v7; // r15
char v8; // bp
const unsigned __int16 **v9; // r12
char v10; // al
char *v11; // r13
const char *v12; // rbp
const char *v13; // rbp
char *s2; // [rsp+8h] [rbp-40h]

v3 = "nohost";
if ( *(_WORD *)a1 == 2 )
{
v6 = gethostbyaddr((const void *)(a1 + 4), 4u, 2);
v7 = v6;
if ( v6 )
{
v3 = v6->h_name;
v8 = *v6->h_name;
if ( v8 )
{
v9 = _ctype_b_loc();
do
{
if ( ((*v9)[v8] & 0x100) != 0 )
*v3 = (*_ctype_tolower_loc())[v8];
v8 = *++v3;
}
while ( *v3 );
v3 = v7->h_name;
v10 = *v7->h_name;
if ( v10 )
{
s2 = (char *)domain_name;
v11 = v7->h_name;
do
{
if ( v10 == 46 )
{
if ( !strcmp(v11 + 1, s2) )
{
*v11 = 0;
return v7->h_name;
}
if ( a3 )
{
v13 = *a3;
while ( v13 )
{
if ( !strcmp(v11 + 1, v13) )
{
*v11 = 0;
return v7->h_name;
}
}
if ( a2 )
{
v12 = *a2;
while ( v12 )
{
if ( !strcmp(v3, v12) )
{
*v11 = 0;
return v7->h_name;
}
}
}
}
}
v10 = *++v11;
}
while ( *v11 );
}
}
}
else
{
v3 = inet_ntoa(*(struct in_addr *)(a1 + 4));
}
}
return v3;
}

original_code:
char const * syslogd_gethost (struct sockaddr_in * sockaddr, char const * hosts [], char const * domains [])
{
 extern char const * domain_name;
 struct hostent * hostent;
 char * sp;
 if (sockaddr->sin_family != 2)
 {
  return ("nohost");
 }
 hostent = gethostbyaddr (& sockaddr->sin_addr, sizeof (struct in_addr), sockaddr->sin_family);
 if (hostent == (struct hostent *) (0))
 {
  return ((char const *) (inet_ntoa (sockaddr->sin_addr)));
 }
 for (sp = hostent->h_name; * sp != (char) (0); sp++)
 {
  if (((*__ctype_b_loc ())[(int) ((* sp))] & (unsigned short int) _ISupper))
  {
   * sp = tolower (* sp);
  }
 }
 for (sp = hostent->h_name; * sp != (char) (0); sp++)
 {
  if (* sp != '.')
  {
   continue;
  }
  if (!strcmp (sp + 1, domain_name))
  {
   * sp = (char) (0);
   return (hostent->h_name);
  }
  if (domains == (char const **) (0))
  {
   continue;
  }
  while (* domains != (char *) (0))
  {
   if (!strcmp (sp + 1, * domains))
   {
    * sp = (char) (0);
    return (hostent->h_name);
   }
  }
  if (hosts == (char const **) (0))
  {
   continue;
  }
  while (* hosts != (char const *) (0))
  {
   if (!strcmp (hostent->h_name, * hosts))
   {
    * sp = (char) (0);
    return (hostent->h_name);
   }
  }
 }
 return (hostent->h_name);
}

canonical_original_code:
char *syslogd_gethost(struct sockaddr_in *sockaddr, char *hosts[], char *domains[])
{
 extern char *domain_name;
 struct hostent *hostent;
 char *sp;
 if (sockaddr->sin_family != 2)
 {
  return ("nohost");
 }
 hostent = gethostbyaddr (& sockaddr->sin_addr, sizeof (struct in_addr), sockaddr->sin_family);
 if (hostent == (struct hostent *) (0))
 {
  return ((char *) (inet_ntoa (sockaddr->sin_addr)));
 }
 for (sp = hostent->h_name; * sp != (char) (0); sp++)
 {
  if (((*__ctype_b_loc ())[(int) ((* sp))] & (unsigned short) _ISupper))
  {
   * sp = tolower (* sp);
  }
 }
 for (sp = hostent->h_name; * sp != (char) (0); sp++)
 {
  if (* sp != '.')
  {
   continue;
  }
  if (!strcmp (sp + 1, domain_name))
  {
   * sp = (char) (0);
   return (hostent->h_name);
  }
  if (domains == (char **) (0))
  {
   continue;
  }
  while (* domains != (char *) (0))
  {
   if (!strcmp (sp + 1, * domains))
   {
    * sp = (char) (0);
    return (hostent->h_name);
   }
  }
  if (hosts == (char **) (0))
  {
   continue;
  }
  while (* hosts != (char *) (0))
  {
   if (!strcmp (hostent->h_name, * hosts))
   {
    * sp = (char) (0);
    return (hostent->h_name);
   }
  }
 }
 return (hostent->h_name);
}

variable_types:
hosts
char *[]

variable_types:
domains
char *[]

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
sp
char *


decompiled_code:
__int64 __fastcall syslog_lookup(char *s1, _QWORD *a2)
{
const unsigned __int16 *v3; // rsi
char *v4; // rdx
int v5; // ebp
char v6; // al
const char *i; // rsi

v3 = *_ctype_b_loc();
v4 = s1;
v5 = 0;
while ( 1 )
{
v6 = *v4;
if ( (v3[*v4] & 0x800) == 0 )
break;
v5 = v6 + 10 * v5 - 48;
++v4;
}
if ( v6 )
v5 = -1;
for ( i = (const char *)a2[1]; i; i = (const char *)a2[1] )
{
if ( !strcmp(s1, i) )
break;
if ( *(_DWORD *)a2 == v5 )
break;
a2 += 2;
}
return *(unsigned int *)a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, _QWORD *a2)
{
const unsigned __int16 *v3; // rsi
char *v4; // rdx
int v5; // ebp
char v6; // al
const char *i; // rsi

v3 = *_ctype_b_loc();
v4 = s1;
v5 = 0;
while ( 1 )
{
v6 = *v4;
if ( (v3[*v4] & 0x800) == 0 )
break;
v5 = v6 + 10 * v5 - 48;
++v4;
}
if ( v6 )
v5 = -1;
for ( i = (const char *)a2[1]; i; i = (const char *)a2[1] )
{
if ( !strcmp(s1, i) )
break;
if ( *(_DWORD *)a2 == v5 )
break;
a2 += 2;
}
return *(unsigned int *)a2;
}

original_code:
int syslog_lookup (char const * string, const struct _code_ table [])
{
 code_t code = 0;
 char const * sp;
 for (sp = string; ((*__ctype_b_loc ())[(int) ((* sp))] & (unsigned short int) _ISdigit); ++ sp)
 {
  code *= 10;
  code += (int) (* sp - '0');
 }
 if (* sp != (char) (0))
 {
  code = - 1;
 }
 while (table->name != (char const *) (0))
 {
  if (strcmp (string, table->name) == 0)
  {
   break;
  }
  if (code == table->code)
  {
   break;
  }
  table++;
 }
 return (table->code);
}

canonical_original_code:
int syslog_lookup(char *string, struct _code_ table[])
{
 int code = 0;
 char *sp;
 for (sp = string; ((*__ctype_b_loc ())[(int) ((* sp))] & (unsigned short) _ISdigit); ++ sp)
 {
  code *= 10;
  code += (int) (* sp - '0');
 }
 if (* sp != (char) (0))
 {
  code = - 1;
 }
 while (table->name != (char *) (0))
 {
  if (strcmp (string, table->name) == 0)
  {
   break;
  }
  if (code == table->code)
  {
   break;
  }
  table++;
 }
 return (table->code);
}

variable_types:
string
char *

variable_types: struct _code_ { int code; char *name; } []

variable_types: code int


tightloop

repo: rbanffy/loop-anomaly-benchmark

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

for ( result = 0LL; result != 400000000; ++result )
counter += result;
return result;
}

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

for ( result = 0LL; result != 400000000; ++result )
counter += result;
return result;
}

original_code:
void tightloop() {
  unsigned j;
  for (j = 0; j < N; ++j) {
    counter += j;
  }
}

canonical_original_code:
void tightloop() {
  unsigned int j;
  for (j = 0; j < N; ++j) {
    counter += j;
  }
}

variable_types:
j
unsigned int


foo

decompiled_code:
void foo()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void foo() {
}

canonical_original_code:
void foo() {
}


decompiled_code:
__int64 loop_with_extra_call()
{
__int64 v0; // rax
__int64 result; // rax

do
{
foo();
counter += v0;
result = v0 + 1;
}
while ( result != 400000000 );
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax
__int64 result; // rax

do
{
func7();
counter += v0;
result = v0 + 1;
}
while ( result != 400000000 );
return result;
}

original_code:
void loop_with_extra_call() {
  unsigned j;
  for (j = 0; j < N; ++j) {
    __asm__("call foo");
    counter += j;
  }
}

canonical_original_code:
void loop_with_extra_call() {
  unsigned int j;
  for (j = 0; j < N; ++j) {
    __asm__("call foo");
    counter += j;
  }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4; // dl

result = 1;
if ( argc > 1 )
{
v4 = *argv[1];
if ( v4 == 116 )
{
tightloop();
result = 0;
}
else
{
result = 0;
if ( v4 == 99 )
{
loop_with_extra_call();
result = 0;
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4; // dl

result = 1;
if ( argc > 1 )
{
v4 = *argv[1];
if ( v4 == 116 )
{
func6();
result = 0;
}
else
{
result = 0;
if ( v4 == 99 )
{
func8();
result = 0;
}
}
}
return result;
}

original_code:
int main(int argc, char** argv) {
  if (argc <= 1) {
    return 1;
  }
  if (argv[1][0] == 't') {
    tightloop();
  } else if (argv[1][0] == 'c') {
    loop_with_extra_call();
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  if (argc <= 1) {
    return 1;
  }
  if (argv[1][0] == 't') {
    tightloop();
  } else if (argv[1][0] == 'c') {
    loop_with_extra_call();
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


drawImg

repo: rbryan/psychic-dangerzone

decompiled_code:
__int64 drawImg()
{
glBindTexture();
glBegin();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
return glEnd();
}

canonical_decompiled_code:
__int64 func7()
{
glBindTexture();
glBegin();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
glColor3f();
glTexCoord2f();
glVertex3f();
return glEnd();
}

original_code:
void drawImg(int X, int Y, int i){
 double delta = 2.0/5;
 double x = X*delta-1;
 double y = Y*delta-1;
 glBindTexture(0x0DE1, i);
 glBegin(0x0004);
 glColor3f(1, 1, 1);
 glTexCoord2f(0,1);
 glVertex3f(x, y, 0);
 glColor3f(1, 1, 1);
 glTexCoord2f(0,0);
 glVertex3f(x, y+delta, 0);
 glColor3f(1, 1, 1);
 glTexCoord2f(1,0);
 glVertex3f(x+delta, y+delta, 0);
 glColor3f(1, 1, 1);
 glTexCoord2f(0,.999);
 glVertex3f(x, y, 0);
 glColor3f(1, 1, 1);
 glTexCoord2f(1,.999);
 glVertex3f(x+delta, y, 0);
 glColor3f(1, 1, 1);
 glTexCoord2f(1,0);
 glVertex3f(x+delta, y+delta, 0);
 glEnd();
}

variable_types: X int

variable_types: Y int

variable_types: i int

variable_types: delta double

variable_types: x double

variable_types: y double


main

repo: rbryan/raytracer

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

v3 = 1;
if ( !(unsigned int)renderframe(argc, argv, envp) )
{
v3 = 0;
printf("This clearly did not work. Could not renderframe().");
}
return v3;
}

original_code:
int main(int argc, char *argv[]){
 if(renderframe()){
  return 1;
 }
 else{
  printf("This clearly did not work. Could not renderframe().");
  return 0;
 }
}

variable_types:
argv
char *[]


dotproduct

decompiled_code:
double __fastcall dotproduct(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

original_code:
double dotproduct(vector a, vector b){
 return (a.x*b.x+a.y*b.y+a.z*b.z);
}

canonical_original_code:
double dotproduct(struct vector a, struct vector b){
 return (a.x*b.x+a.y*b.y+a.z*b.z);
}

variable_types: struct vector { double x; double y; double z; }

variable_types:
b
struct vector

return_type: double


decompiled_code:
_BOOL8 __fastcall in_angle(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15, double a16, double a17, double a18, double a19, double a20, double a21, double a22, double a23, double a24, double a25, double a26)
{
double v32; // r12
double v33; // xmm0_8
double v34; // rbp
double v35; // xmm2_8
double v36; // xmm0_8
double v37; // rbx
double v38; // xmm7_8
double v39; // xmm3_8
double v40; // xmm0_8
double v41; // r13
double v42; // r12
double v43; // xmm4_8
double v44; // xmm5_8
double v45; // xmm1_8
double v46; // rbp
double v47; // xmm4_8
double v48; // xmm5_8
double v49; // xmm0_8
double v50; // xmm0_8
_BOOL8 result; // rax

v32 = dotproduct(a1, a2, a3, a4, a15, a16, a17, a8, a9, a10, a11, a12, a13, a14);
dot_product = *(_QWORD *)&v32;
v33 = (a18 - a15) * (a18 - a15) + (a19 - a16) * (a19 - a16) + (a20 - a17) * (a20 - a17);
if ( v33 < 0.0 )
v34 = sqrt(v33);
else
v34 = sqrt(v33);
dist1_2 = *(_QWORD *)&v34;
v35 = (a23 - a17) * (a23 - a17);
v36 = (a22 - a16) * (a22 - a16) + (a21 - a15) * (a21 - a15) + v35;
if ( v36 < 0.0 )
v37 = sqrt(v36);
else
v37 = sqrt(v36);
dist1_3 = *(_QWORD *)&v37;
v38 = a25 - a16;
v39 = a26 - a17;
v40 = (a24 - a15) * (a24 - a15) + v38 * v38 + v39 * v39;
if ( v40 < 0.0 )
v41 = sqrt(v40);
else
v41 = sqrt(v40);
dist1_inter = *(_QWORD *)&v41;
*(double *)&vec1_inter = a24 - a15;
*(double *)&qword_8A8 = a25 - a16;
*(double *)&qword_8B0 = a26 - a17;
v42 = acos(v32 / (v34 * v37));
theta = *(_QWORD *)&v42;
v45 = dotproduct(
v42,
v34 * v37,
v35,
v39,
v43,
v44,
v37,
v38,
*(double *)&vec1_inter,
*(double *)&qword_8A8,
*(double *)&qword_8B0,
a9,
a10,
a11)
/ (v34
* v41);
v46 = acos(v45);
theta_intersect = *(_QWORD *)&v46;
v49 = dotproduct(
v46,
v45,
v35,
v39,
v47,
v48,
v37,
v41,
*(double *)&vec1_inter,
*(double *)&qword_8A8,
*(double *)&qword_8B0,
a12,
a13,
a14);
v50 = acos(v49 / (v37 * v41));
result = 0LL;
if ( v42 >= v46 )
result = v42 >= v50;
return result;
}

original_code:
int in_angle(vector vec1 , vector vec2 , vector point1 , vector point2, vector point3, vector intersect){
 dot_product = dotproduct(vec1,vec2);
 dist1_2 = sqrt( pow(point2.x-point1.x,2) + pow(point2.y-point1.y,2) + pow(point2.z-point1.z,2));
 dist1_3 = sqrt( pow(point3.x-point1.x,2) + pow(point3.y-point1.y,2) + pow(point3.z-point1.z,2));
 dist1_inter = sqrt( pow(intersect.x-point1.x,2) + pow(intersect.y-point1.y,2) + pow(intersect.z-point1.z,2));
 vec1_inter.x = intersect.x - point1.x;
 vec1_inter.y = intersect.y - point1.y;
 vec1_inter.z = intersect.z - point1.z;
 theta = acos(dot_product/(dist1_2*dist1_3));
 theta_intersect = acos(dotproduct(vec1_inter,vec1)/(dist1_inter*dist1_2));
 theta_intersect2 = acos(dotproduct(vec1_inter,vec2)/(dist1_inter*dist1_3));
 if(theta >= theta_intersect && theta >= theta_intersect2){
  return 1;
 }
 return 0;
}

canonical_original_code:
int in_angle(struct vector vec1, struct vector vec2, struct vector point1, struct vector point2, struct vector point3, struct vector intersect){
 dot_product = dotproduct(vec1,vec2);
 dist1_2 = sqrt( pow(point2.x-point1.x,2) + pow(point2.y-point1.y,2) + pow(point2.z-point1.z,2));
 dist1_3 = sqrt( pow(point3.x-point1.x,2) + pow(point3.y-point1.y,2) + pow(point3.z-point1.z,2));
 dist1_inter = sqrt( pow(intersect.x-point1.x,2) + pow(intersect.y-point1.y,2) + pow(intersect.z-point1.z,2));
 vec1_inter.x = intersect.x - point1.x;
 vec1_inter.y = intersect.y - point1.y;
 vec1_inter.z = intersect.z - point1.z;
 theta = acos(dot_product/(dist1_2*dist1_3));
 theta_intersect = acos(dotproduct(vec1_inter,vec1)/(dist1_inter*dist1_2));
 theta_intersect2 = acos(dotproduct(vec1_inter,vec2)/(dist1_inter*dist1_3));
 if(theta >= theta_intersect && theta >= theta_intersect2){
  return 1;
 }
 return 0;
}

variable_types:
intersect
struct vector

user_defined_types: struct vector { double x; double y; double z; }


repo: rbu/driftnet

decompiled_code:
__int64 __fastcall audiochunk_write(char **a1, int a2)
{
__int64 result; // rax
char *v3; // rbx
size_t v4; // r14

result = 0LL;
if ( a1[1] )
{
v3 = *a1;
do
{
v4 = &a1[1][(_QWORD)*a1] - v3;
if ( &a1[1][(_QWORD)*a1] >= v3 + 1024 )
v4 = 1024LL;
if ( write(a2, v3, v4) == -1 && *_errno_location() != 4 )
return 0xFFFFFFFFLL;
v3 += v4;
}
while ( v3 < &a1[1][(_QWORD)*a1] );
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, int a2)
{
__int64 result; // rax
char *v3; // rbx
size_t v4; // r14

result = 0LL;
if ( a1[1] )
{
v3 = *a1;
do
{
v4 = &a1[1][(_QWORD)*a1] - v3;
if ( &a1[1][(_QWORD)*a1] >= v3 + 1024 )
v4 = 1024LL;
if ( write(a2, v3, v4) == -1 && *_errno_location() != 4 )
return 0xFFFFFFFFLL;
v3 += v4;
}
while ( v3 < &a1[1][(_QWORD)*a1] );
result = 0LL;
}
return result;
}

original_code:
static int audiochunk_write(const audiochunk A, int fd) {
    const unsigned char *p;
    ssize_t n;
    if (A->len == 0)
        return 0;
    p = A->data;
    do {
        size_t d = 1024;
        if (p + d > A->data + A->len)
            d = A->data + A->len - p;
        n = write(fd, p, d);
        if (n == -1 && (*__errno_location ()) != 4)
            return -1;
        else
            p += d;
    } while (p < A->data + A->len);
    return 0;
}

canonical_original_code:
static int audiochunk_write(struct _audiochunk *A, int fd) {
    unsigned char *p;
    long n;
    if (A->len == 0)
        return 0;
    p = A->data;
    do {
        unsigned long d = 1024;
        if (p + d > A->data + A->len)
            d = A->data + A->len - p;
        n = write(fd, p, d);
        if (n == -1 && (*__errno_location ()) != 4)
            return -1;
        else
            p += d;
    } while (p < A->data + A->len);
    return 0;
}

variable_types: struct _audiochunk { unsigned char *data; unsigned long len; struct _audiochunk *next; } *

variable_types: fd int

variable_types:
p
unsigned char *

variable_types: n long

variable_types:
d
unsigned long


decompiled_code:
__int64 __fastcall audiochunk_delete(_QWORD *a1)
{
xfree(*a1);
return xfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
xfree(*a1);
return xfree(a1);
}

original_code:
static void audiochunk_delete(audiochunk A) {
    xfree(A->data);
    xfree(A);
}

canonical_original_code:
static void audiochunk_delete(struct _audiochunk *A) {
    xfree(A->data);
    xfree(A);
}

user_defined_types: struct _audiochunk { unsigned char *data; unsigned long len; struct _audiochunk *next; }