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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

original_code:
LIST *create_list(){
    LIST *l = malloc(sizeof(LIST));
    if(l == ((void *)0))
        return l;
    l->first = ((void *)0);
    l->last = ((void *)0);
    l->size = 0;
    return l;
}

canonical_original_code:
struct list *create_list(){
    struct list *l = malloc(sizeof(LIST));
    if(l == ((void *)0))
        return l;
    l->first = ((void *)0);
    l->last = ((void *)0);
    l->size = 0;
    return l;
}

return_type: struct list { struct node { struct node *next; struct node *prev; int data; } *first; struct node *last; unsigned long long size; } *


append

repo: razpeitia/data-structures

original_code:
int append(LIST *l, int data){
    if(l == ((void *)0))
        return 1;
    NODE *p = malloc(sizeof(NODE));
    if(p == ((void *)0))
        return 2;
    p->data = data;
    if(l->first == ((void *)0)){
        l->first = p;
        l->last = p;
        p->next = p;
        p->prev = p;
    }
    else{
        p->next = l->first;
        p->prev = l->last;
        l->first->prev = p;
        l->last->next = p;
        l->first = p;
    }
    return 0;
}

canonical_original_code:
int append(struct list *l, int data){
    if(l == ((void *)0))
        return 1;
    struct node *p = malloc(sizeof(NODE));
    if(p == ((void *)0))
        return 2;
    p->data = data;
    if(l->first == ((void *)0)){
        l->first = p;
        l->last = p;
        p->next = p;
        p->prev = p;
    }
    else{
        p->next = l->first;
        p->prev = l->last;
        l->first->prev = p;
        l->last->next = p;
        l->first = p;
    }
    return 0;
}

variable_types: struct list { struct node { struct node *next; struct node *prev; int data; } *first; struct node *last; unsigned long long size; } *

variable_types: data int

return_type: int

user_defined_types: struct list { struct node *first; struct node *last; unsigned long long size; }


pop

original_code:
int pop(LIST *l){
    if(l == ((void *)0) )
        return 1;
    if(l->first == ((void *)0))
        return 2;
    NODE *p;
    if( l->first == l->last ){
        free(l->first);
        l->first = ((void *)0);
        l->last = ((void *)0);
        l->size = 0;
    }
    else{
        p = l->first->next;
        l->last->next = l->first->next;
        l->first->next->prev = l->last;
        free(l->first);
        l->size--;
        l->first = p;
    }
    return 0;
}

canonical_original_code:
int pop(struct list *l){
    if(l == ((void *)0) )
        return 1;
    if(l->first == ((void *)0))
        return 2;
    struct node *p;
    if( l->first == l->last ){
        free(l->first);
        l->first = ((void *)0);
        l->last = ((void *)0);
        l->size = 0;
    }
    else{
        p = l->first->next;
        l->last->next = l->first->next;
        l->first->next->prev = l->last;
        free(l->first);
        l->size--;
        l->first = p;
    }
    return 0;
}

variable_types: struct node { struct node *next; struct node *prev; int data; } *


decompiled_code:
void __fastcall destroy_list(void *ptr)
{
if ( ptr )
{
while ( (unsigned int)pop((__int64)ptr) )
;
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
while ( (unsigned int)func9((__int64)ptr) )
;
free(ptr);
}
}

original_code:
void destroy_list(LIST *l){
    if(l == ((void *)0))
        return;
    while(pop(l) != 0);
    free(l);
}

canonical_original_code:
void destroy_list(struct list *l){
    if(l == ((void *)0))
        return;
    while(pop(l) != 0);
    free(l);
}

return_type: void

user_defined_types: struct node { struct node *next; struct node *prev; int data; }


FreeSymbols

repo: razzlefratz/MotleyTools

decompiled_code:
void FreeSymbols()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi

v0 = symbols;
if ( num_syms > 0 )
{
v1 = (void **)((char *)symbols + 8);
v2 = (void **)((char *)symbols + 16 * (unsigned int)(num_syms - 1) + 24);
do
{
v3 = *v1;
v1 += 2;
free(v3);
}
while ( v2 != v1 );
}
free(v0);
symbols = 0LL;
num_syms = 0;
}

canonical_decompiled_code:
void func0()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi

v0 = symbols;
if ( num_syms > 0 )
{
v1 = (void **)((char *)symbols + 8);
v2 = (void **)((char *)symbols + 16 * (unsigned int)(num_syms - 1) + 24);
do
{
v3 = *v1;
v1 += 2;
free(v3);
}
while ( v2 != v1 );
}
free(v0);
symbols = 0LL;
num_syms = 0;
}

original_code:
static void FreeSymbols ()
{
 int index;
 for (index = 0; index < num_syms; ++ index)
 {
  free (symbols [index].name);
 }
 free (symbols);
 symbols = (struct module_symbol *) (0);
 num_syms = 0;
 return;
}

canonical_original_code:
static void FreeSymbols()
{
 int index;
 for (index = 0; index < num_syms; ++ index)
 {
  free (symbols [index].name);
 }
 free (symbols);
 symbols = (struct module_symbol *) (0);
 num_syms = 0;
 return;
}

variable_types: index int

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


AddSymbol

decompiled_code:
__int64 __fastcall AddSymbol(__int64 a1, const char *a2)
{
int v2; // ebp
size_t v3; // r13
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
char *v7; // rbx
char *v8; // rax

v2 = num_syms + 1;
v3 = 16LL * (num_syms + 1);
v4 = (char *)realloc(symbols, v3);
symbols = v4;
if ( !v4 )
return 0LL;
v5 = v4;
v6 = strlen(a2);
v7 = &v5[v3 - 16];
v8 = (char *)malloc(v6 + 1);
*((_QWORD *)v7 + 1) = v8;
if ( !v8 )
return 0LL;
*(_QWORD *)v7 = a1;
strcpy(v8, a2);
num_syms = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
int v2; // ebp
size_t v3; // r13
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
char *v7; // rbx
char *v8; // rax

v2 = num_syms + 1;
v3 = 16LL * (num_syms + 1);
v4 = (char *)realloc(symbols, v3);
symbols = v4;
if ( !v4 )
return 0LL;
v5 = v4;
v6 = strlen(a2);
v7 = &v5[v3 - 16];
v8 = (char *)malloc(v6 + 1);
*((_QWORD *)v7 + 1) = v8;
if ( !v8 )
return 0LL;
*(_QWORD *)v7 = a1;
strcpy(v8, a2);
num_syms = v2;
return 1LL;
}

original_code:
static int AddSymbol (unsigned long address, char * symbol)
{
 symbols = (struct module_symbol *) realloc (symbols, (num_syms + 1) * sizeof (struct module_symbol));
 if (symbols == (struct module_symbol *) 0) return (0);
 symbols [num_syms].name = (char *) malloc (strlen (symbol) * sizeof (char) + 1);
 if (symbols [num_syms].name == (char *) 0) return (0);
 symbols [num_syms].value = address;
 strcpy (symbols [num_syms].name, symbol);
 ++ num_syms;
 return (1);
}

canonical_original_code:
static int AddSymbol(unsigned long address, char *symbol)
{
 symbols = (struct module_symbol *) realloc (symbols, (num_syms + 1) * sizeof (struct module_symbol));
 if (symbols == (struct module_symbol *) 0) return (0);
 symbols [num_syms].name = (char *) malloc (strlen (symbol) * sizeof (char) + 1);
 if (symbols [num_syms].name == (char *) 0) return (0);
 symbols [num_syms].value = address;
 strcpy (symbols [num_syms].name, symbol);
 ++ num_syms;
 return (1);
}

variable_types:
address
unsigned long

variable_types:
symbol
char *


CheckVersion

decompiled_code:
__int64 __fastcall CheckVersion(const char *a1)
{
const char *v1; // r12
__int64 result; // rax
const char *v3; // r12
int v4; // eax
__int64 v5; // r8
__int64 v6; // rcx
int v7; // ebx
__int64 v8; // rdx
unsigned int v9; // [rsp+4h] [rbp-1B4h] BYREF
unsigned int v10; // [rsp+8h] [rbp-1B0h] BYREF
unsigned int v11; // [rsp+Ch] [rbp-1ACh] BYREF
struct utsname name; // [rsp+10h] [rbp-1A8h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
const char *v1; // r12
__int64 result; // rax
const char *v3; // r12
int v4; // eax
__int64 v5; // r8
__int64 v6; // rcx
int v7; // ebx
__int64 v8; // rdx
unsigned int v9; // [rsp+4h] [rbp-1B4h] BYREF
unsigned int v10; // [rsp+8h] [rbp-1B0h] BYREF
unsigned int v11; // [rsp+Ch] [rbp-1ACh] BYREF
struct utsname name; // [rsp+10h] [rbp-1A8h] BYREF

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

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

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


LookupSymbol

decompiled_code:
__int64 __fastcall LookupSymbol(unsigned __int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 *v4; // rbx
__int64 *v5; // rax
__int64 v6; // rdx
__int64 v7; // rdx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 *v4; // rbx
__int64 *v5; // rax
__int64 v6; // rdx
__int64 v7; // rdx
__int64 result; // rax

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

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: 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; // ebp
unsigned int *v2; // r12
int v4; // edi
__int64 *v5; // rbx
int v6; // ecx
unsigned int *v7; // rax
__int64 *v8; // r13
int v9; // edi
const char *v10; // r15
__int64 v11; // rax
__int64 v12; // rdi
__int64 v13; // rdi
unsigned int *v15; // [rsp+8h] [rbp-10E0h]
struct timeval timeout; // [rsp+10h] [rbp-10D8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-10C8h] BYREF
char buf[4168]; // [rsp+A0h] [rbp-1048h] BYREF

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

canonical_decompiled_code:
int __fastcall func0(__int64 *a1)
{
int v1; // ebp
unsigned int *v2; // r12
int v4; // edi
__int64 *v5; // rbx
int v6; // ecx
unsigned int *v7; // rax
__int64 *v8; // r13
int v9; // edi
const char *v10; // r15
__int64 v11; // rax
__int64 v12; // rdi
__int64 v13; // rdi
unsigned int *v15; // [rsp+8h] [rbp-10E0h]
struct timeval timeout; // [rsp+10h] [rbp-10D8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-10C8h] BYREF
char buf[4168]; // [rsp+A0h] [rbp-1048h] BYREF

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

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; // rbx
char *v4; // rax
gcc_va_list arg; // [rsp+8h] [rbp-10F0h] BYREF
char s[16]; // [rsp+20h] [rbp-10D8h] BYREF
__int128 v7; // [rsp+30h] [rbp-10C8h]
char v8[4064]; // [rsp+40h] [rbp-10B8h] BYREF

v2 = 0LL;
memset(v8, 0, sizeof(v8));
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC2);
v7 = 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 )
return syslogd_queue(43LL, host_name, s);
LABEL_9:
v4 = strerror(errnum);
snprintf(&s[v2], 4096 - v2, ": %s", v4);
return syslogd_queue(43LL, host_name, s);
}
if ( errnum )
goto LABEL_9;
return syslogd_queue(43LL, host_name, s);
}

canonical_decompiled_code:
__int64 func0(int errnum, char *format, ...)
{
__int64 v2; // rbx
char *v4; // rax
gcc_va_list arg; // [rsp+8h] [rbp-10F0h] BYREF
char s[16]; // [rsp+20h] [rbp-10D8h] BYREF
__int128 v7; // [rsp+30h] [rbp-10C8h]
char v8[4064]; // [rsp+40h] [rbp-10B8h] BYREF

v2 = 0LL;
memset(v8, 0, sizeof(v8));
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC2);
v7 = 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 )
return syslogd_queue(43LL, host_name, s);
LABEL_9:
v4 = strerror(errnum);
snprintf(&s[v2], 4096 - v2, ": %s", v4);
return syslogd_queue(43LL, host_name, s);
}
if ( errnum )
goto LABEL_9;
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 v8; // er12
char v9; // bp

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

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

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

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


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

result = (unsigned int)symbol_lookup;
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

result = (unsigned int)symbol_lookup;
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;
}


LogProcLine

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

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

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

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

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: count int


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_constprop_0(v0);
}
else
{
v1 = *_errno_location();
if ( v1 != 4 )
error(0, v1, "error return from sys_sycall");
}
}

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

memset(buffer, 0, sizeof(buffer));
v0 = klogctl(2, buffer, 4095);
if ( v0 > 0 )
{
func12(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:
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 *v1; // r13
__int64 v3; // rdi
unsigned int v4; // er12
int v5; // eax
int *v7; // rax
int *v8; // rax
int v9; // edi
int *v10; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(struct sockaddr *addr)
{
char *v1; // r13
__int64 v3; // rdi
unsigned int v4; // er12
int v5; // eax
int *v7; // rax
int *v8; // rax
int v9; // edi
int *v10; // rax

v1 = addr->sa_data;
if ( !addr->sa_data[0] )
{
*_errno_location() = 22;
v4 = -1;
syslogd_error(22LL, "Can't open socket file %s", addr->sa_data);
return v4;
}
if ( unlink(addr->sa_data) )
{
v3 = (unsigned int)*_errno_location();
if ( (_DWORD)v3 != 2 )
{
v4 = -1;
syslogd_error(v3, "Can't remove socket file %s", v1);
return v4;
}
}
v4 = socket(1, 2, 0);
if ( v4 == -1 )
{
v7 = _errno_location();
syslogd_error((unsigned int)*v7, "Can't allocate socket for %s", v1);
return v4;
}
v5 = strlen(v1);
if ( bind(v4, addr, v5 + 2) == -1 )
{
v8 = _errno_location();
syslogd_error((unsigned int)*v8, "Can't bind socket to %s", v1);
LABEL_12:
v9 = v4;
v4 = -1;
close(v9);
return v4;
}
if ( chmod(v1, 0x1B6u) == -1 )
{
v10 = _errno_location();
syslogd_error((unsigned int)*v10, "Can't set %s file permissions", v1);
goto LABEL_12;
}
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
time_t v5; // rax
__int64 v6; // r14
unsigned int result; // eax
__int64 v8; // rcx
struct tm *v9; // rax
__int64 v10; // rsi
int v11; // eax
__int64 v12; // rsi
__int64 v13; // [rsp+10h] [rbp-58h]
time_t timer; // [rsp+28h] [rbp-40h] BYREF

v3 = a2;
v5 = time(&timer);
v6 = *((_QWORD *)&syslogs + 1);
timer = v5;
if ( !a2 )
v3 = &src;
if ( !a3 )
a3 = &src;
result = a1;
if ( (_UNKNOWN *)v6 == &syslogs )
goto LABEL_21;
do
{
if ( (*(_BYTE *)(v6 + 56) & 1) == 0 )
{
result = (a1 >> 3) & 0x7F;
if ( (*(_DWORD *)(v6 + 4LL * result + 72) & (1 << (a1 & 7))) != 0 )
{
result = timer;
if ( *(_QWORD *)(v6 + 48) <= timer )
{
if ( !*(_QWORD *)(v6 + 4536) )
{
v9 = localtime(&timer);
strftime((char *)(v6 + 172), 0x30uLL, "%F %T %Z", v9);
}
result = strcmp(a3, (const char *)(v6 + 412));
v8 = *(_QWORD *)(v6 + 4528);
if ( result || (v13 = *(_QWORD *)(v6 + 4528), result = strcmp(v3, (const char *)(v6 + 220)), v8 = v13, result) )
{
if ( v8 )
{
v11 = snprintf((char *)(v6 + 412), 0x1000uLL, "Previous message received %d times", v8 + 1);
v12 = state;
*(_QWORD *)(v6 + 4528) = 0LL;
*(_QWORD *)(v6 + 4512) = v11;
result = syslogd_write(v6, v12);
}
if ( *a3 )
{
*(_QWORD *)(v6 + 4520) = a1;
strncpy((char *)(v6 + 220), v3, 0x40uLL);
((void (__fastcall *)(__int64, __int64, _QWORD))strfpri)(v6 + 284, 128LL, (unsigned int)a1);
strncpy((char *)(v6 + 412), a3, 0x1000uLL);
v10 = state;
*(_QWORD *)(v6 + 4528) = 0LL;
syslogd_ready(v6, v10);
result = syslogd_write(v6, state);
}
}
else
{
*(_QWORD *)(v6 + 4528) = v13 + 1;
}
}
}
}
v6 = *(_QWORD *)(v6 + 8);
}
while ( (_UNKNOWN *)v6 != &syslogs );
if ( *((_UNKNOWN **)&syslogs + 1) == &syslogs )
{
LABEL_21:
result = open(*((const char **)&syslogs + 3), 257);
*((_DWORD *)&syslogs + 10) = result;
if ( result != -1 )
{
syslogd_write(&syslogs, 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
time_t v5; // rax
__int64 v6; // r14
unsigned int result; // eax
__int64 v8; // rcx
struct tm *v9; // rax
__int64 v10; // rsi
int v11; // eax
__int64 v12; // rsi
__int64 v13; // [rsp+10h] [rbp-58h]
time_t timer; // [rsp+28h] [rbp-40h] BYREF

v3 = a2;
v5 = time(&timer);
v6 = *((_QWORD *)&syslogs + 1);
timer = v5;
if ( !a2 )
v3 = &src;
if ( !a3 )
a3 = &src;
result = a1;
if ( (_UNKNOWN *)v6 == &syslogs )
goto LABEL_21;
do
{
if ( (*(_BYTE *)(v6 + 56) & 1) == 0 )
{
result = (a1 >> 3) & 0x7F;
if ( (*(_DWORD *)(v6 + 4LL * result + 72) & (1 << (a1 & 7))) != 0 )
{
result = timer;
if ( *(_QWORD *)(v6 + 48) <= timer )
{
if ( !*(_QWORD *)(v6 + 4536) )
{
v9 = localtime(&timer);
strftime((char *)(v6 + 172), 0x30uLL, "%F %T %Z", v9);
}
result = strcmp(a3, (const char *)(v6 + 412));
v8 = *(_QWORD *)(v6 + 4528);
if ( result || (v13 = *(_QWORD *)(v6 + 4528), result = strcmp(v3, (const char *)(v6 + 220)), v8 = v13, result) )
{
if ( v8 )
{
v11 = snprintf((char *)(v6 + 412), 0x1000uLL, "Previous message received %d times", v8 + 1);
v12 = state;
*(_QWORD *)(v6 + 4528) = 0LL;
*(_QWORD *)(v6 + 4512) = v11;
result = syslogd_write(v6, v12);
}
if ( *a3 )
{
*(_QWORD *)(v6 + 4520) = a1;
strncpy((char *)(v6 + 220), v3, 0x40uLL);
((void (__fastcall *)(__int64, __int64, _QWORD))strfpri)(v6 + 284, 128LL, (unsigned int)a1);
strncpy((char *)(v6 + 412), a3, 0x1000uLL);
v10 = state;
*(_QWORD *)(v6 + 4528) = 0LL;
syslogd_ready(v6, v10);
result = syslogd_write(v6, state);
}
}
else
{
*(_QWORD *)(v6 + 4528) = v13 + 1;
}
}
}
}
v6 = *(_QWORD *)(v6 + 8);
}
while ( (_UNKNOWN *)v6 != &syslogs );
if ( *((_UNKNOWN **)&syslogs + 1) == &syslogs )
{
LABEL_21:
result = open(*((const char **)&syslogs + 3), 257);
*((_DWORD *)&syslogs + 10) = result;
if ( result != -1 )
{
syslogd_write(&syslogs, 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[16]; // [rsp+20h] [rbp-10C8h] BYREF
__int128 v6; // [rsp+30h] [rbp-10B8h]
char v7[4064]; // [rsp+40h] [rbp-10A8h] BYREF

memset(v7, 0, sizeof(v7));
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC1);
v6 = 0LL;
if ( program_name )
v2 = snprintf(s, 0x1000uLL, "%s: ", program_name);
else
v2 = 0LL;
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[16]; // [rsp+20h] [rbp-10C8h] BYREF
__int128 v6; // [rsp+30h] [rbp-10B8h]
char v7[4064]; // [rsp+40h] [rbp-10A8h] BYREF

memset(v7, 0, sizeof(v7));
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC1);
v6 = 0LL;
if ( program_name )
v2 = snprintf(s, 0x1000uLL, "%s: ", program_name);
else
v2 = 0LL;
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 *v5; // rbp
char v6; // bl
int v7; // er13
char *v8; // rdx
int v9; // ecx
const char *v10; // rbx
char v11; // al
unsigned int v12; // edx
unsigned int v13; // ecx
unsigned int v14; // er13
char v15; // bl
int v16; // esi
char *v17; // r15
unsigned int v18; // eax
unsigned int i; // ebx
char *v20; // rax
const unsigned __int16 *v21; // rdx
unsigned int v22; // eax
char v23; // al
char *v24; // rax
int v25; // edi
const char *v27; // [rsp+0h] [rbp-1048h]
char *v28; // [rsp+8h] [rbp-1040h]
char v29; // [rsp+10h] [rbp-1038h] BYREF
char v30; // [rsp+11h] [rbp-1037h] BYREF

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

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2, const char *a3)
{
const char *v5; // rbp
char v6; // bl
int v7; // er13
char *v8; // rdx
int v9; // ecx
const char *v10; // rbx
char v11; // al
unsigned int v12; // edx
unsigned int v13; // ecx
unsigned int v14; // er13
char v15; // bl
int v16; // esi
char *v17; // r15
unsigned int v18; // eax
unsigned int i; // ebx
char *v20; // rax
const unsigned __int16 *v21; // rdx
unsigned int v22; // eax
char v23; // al
char *v24; // rax
int v25; // edi
const char *v27; // [rsp+0h] [rbp-1048h]
char *v28; // [rsp+8h] [rbp-1040h]
char v29; // [rsp+10h] [rbp-1038h] BYREF
char v30; // [rsp+11h] [rbp-1037h] BYREF

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

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:
int __fastcall syslogd_close_sockets(__int64 *a1)
{
__int64 *v1; // rbx
int result; // eax
const char *v3; // rdx
const char *v4; // r12
int *v5; // rax
char v6[56]; // [rsp+0h] [rbp-38h] BYREF

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

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

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

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 = *(_QWORD *)a1 > *(_QWORD *)a2;
if ( *(_QWORD *)a1 < *(_QWORD *)a2 )
result = 0xFFFFFFFFLL;
return result;
}

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

result = *(_QWORD *)a1 > *(_QWORD *)a2;
if ( *(_QWORD *)a1 < *(_QWORD *)a2 )
result = 0xFFFFFFFFLL;
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
__int64 v1; // rbx
char *v2; // rax
char *v3; // rbp
int v4; // eax
const char *v5; // rbx
__int64 v6; // r13
unsigned int v7; // er12
__int64 result; // rax
__int64 v9; // rbx
unsigned int v10; // er12
void **v11; // rax
size_t v12; // rsi
const char *v13; // rcx
const char *v14; // r9
int v15; // edi
char *v16; // rax
int *v17; // rax
char *v18; // rax

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

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
__int64 v1; // rbx
char *v2; // rax
char *v3; // rbp
int v4; // eax
const char *v5; // rbx
__int64 v6; // r13
unsigned int v7; // er12
__int64 result; // rax
__int64 v9; // rbx
unsigned int v10; // er12
void **v11; // rax
size_t v12; // rsi
const char *v13; // rcx
const char *v14; // r9
int v15; // edi
char *v16; // rax
int *v17; // rax
char *v18; // rax

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

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


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

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

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

optval = 1;
v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 == -1 )
{
getsocketname(v9, 32LL, addr);
v4 = _errno_location();
syslogd_error((unsigned int)*v4, "Can't allocate socket for %s", v9);
return v2;
}
if ( setsockopt(v1, 1, 2, &optval, 4u) == -1 )
{
getsocketname(v9, 32LL, addr);
v5 = _errno_location();
syslogd_error((unsigned int)*v5, "Can't set socket options for %s", v9);
LABEL_7:
v6 = v2;
v2 = -1;
close(v6);
return v2;
}
if ( bind(v2, addr, 0x10u) == -1 )
{
getsocketname(v9, 32LL, addr);
v7 = _errno_location();
syslogd_error((unsigned int)*v7, "Can't connect to %s", v9);
goto LABEL_7;
}
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
int v6; // edx
char *v7; // rax

v3 = (const char *)syslog_facility_codes[1];
if ( v3 )
{
v4 = (char *)syslog_facility_codes;
do
{
if ( *(_DWORD *)v4 == (a3 & 0x3F8) )
break;
v3 = (const char *)*((_QWORD *)v4 + 3);
v4 += 16;
}
while ( v3 );
}
v5 = (const char *)syslog_severity_codes[1];
if ( v5 )
{
v6 = a3 & 7;
v7 = (char *)syslog_severity_codes;
do
{
if ( *(_DWORD *)v7 == v6 )
break;
v5 = (const char *)*((_QWORD *)v7 + 3);
v7 += 16;
}
while ( v5 );
}
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
int v6; // edx
char *v7; // rax

v3 = (const char *)syslog_facility_codes[1];
if ( v3 )
{
v4 = (char *)syslog_facility_codes;
do
{
if ( *(_DWORD *)v4 == (a3 & 0x3F8) )
break;
v3 = (const char *)*((_QWORD *)v4 + 3);
v4 += 16;
}
while ( v3 );
}
v5 = (const char *)syslog_severity_codes[1];
if ( v5 )
{
v6 = a3 & 7;
v7 = (char *)syslog_severity_codes;
do
{
if ( *(_DWORD *)v7 == v6 )
break;
v5 = (const char *)*((_QWORD *)v7 + 3);
v7 += 16;
}
while ( v5 );
}
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; // r12
struct hostent *v6; // rax
struct hostent *v7; // r14
__int64 v8; // rbx
const unsigned __int16 **v9; // r15
char v10; // al
const char *v11; // r15
const char *v12; // rbx
const char *v13; // r13
const char *v14; // r13
char *s2; // [rsp+8h] [rbp-40h]

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

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

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

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, unsigned int *a2)
{
int v3; // ebx
const unsigned __int16 **v4; // rax
char *v5; // rdx
const unsigned __int16 *v6; // rsi
int v7; // eax
const char *v8; // rsi
__int64 result; // rax
int v10; // er8

v3 = 0;
v4 = _ctype_b_loc();
v5 = s1;
v6 = *v4;
while ( 1 )
{
v7 = *v5;
if ( (v6[*v5] & 0x800) == 0 )
break;
++v5;
v3 = v7 + 10 * v3 - 48;
}
v8 = (const char *)*((_QWORD *)a2 + 1);
if ( (_BYTE)v7 )
v3 = -1;
result = *a2;
if ( v8 )
{
while ( 1 )
{
v10 = strcmp(s1, v8);
result = *a2;
if ( !v10 || v3 == (_DWORD)result )
break;
v8 = (const char *)*((_QWORD *)a2 + 3);
if ( !v8 )
return a2[4];
a2 += 4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, unsigned int *a2)
{
int v3; // ebx
const unsigned __int16 **v4; // rax
char *v5; // rdx
const unsigned __int16 *v6; // rsi
int v7; // eax
const char *v8; // rsi
__int64 result; // rax
int v10; // er8

v3 = 0;
v4 = _ctype_b_loc();
v5 = s1;
v6 = *v4;
while ( 1 )
{
v7 = *v5;
if ( (v6[*v5] & 0x800) == 0 )
break;
++v5;
v3 = v7 + 10 * v3 - 48;
}
v8 = (const char *)*((_QWORD *)a2 + 1);
if ( (_BYTE)v7 )
v3 = -1;
result = *a2;
if ( v8 )
{
while ( 1 )
{
v10 = strcmp(s1, v8);
result = *a2;
if ( !v10 || v3 == (_DWORD)result )
break;
v8 = (const char *)*((_QWORD *)a2 + 3);
if ( !v8 )
return a2[4];
a2 += 4;
}
}
return result;
}

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


main

canonical_name: main

repo: rbanffy/loop-anomaly-benchmark

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
int v4; // er8
char v5; // al

v4 = 1;
if ( argc > 1 )
{
v5 = *argv[1];
if ( v5 == 116 )
{
tightloop(argc, argv, envp, v3, 0LL);
}
else
{
v4 = 0;
if ( v5 == 99 )
loop_with_extra_call(argc, argv, envp, v3, 0LL);
}
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
int v4; // er8
char v5; // al

v4 = 1;
if ( argc > 1 )
{
v5 = *argv[1];
if ( v5 == 116 )
{
func6(argc, argv, envp, v3, 0LL);
}
else
{
v4 = 0;
if ( v5 == 99 )
func8(argc, argv, envp, v3, 0LL);
}
}
return v4;
}

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