decompiled_code:
__int64 __fastcall mempool_init(__int64 a1, unsigned __int8 a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6)
{
if ( a3 > 1 )
{
printf("unkno");
exit(1);
}
return link_mempool_init(a1, a2, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6)
{
if ( a3 > 1 )
{
printf("unkno");
exit(1);
}
return link_mempool_init(a1, a2, a4, a5, a6);
}

original_code:
mempool mempool_init(size_t size, _Bool pool_share, POOL_TYPE pool_type,
   mempool_alloc_fn chunk_alloc,
   mempool_chunk_free_fn chunk_free,
   mempool_pool_free_fn pool_destory)
{
 switch(pool_type){
 case LINK_POOL:
 case POOL_CUSTOMIZE:
     return link_mempool_init(size, pool_share, chunk_alloc, chunk_free, pool_destory);
     break;
 default:
     printf("unkno");
     exit(1);
 }
}

canonical_original_code:
struct mempool_class *mempool_init(unsigned long size, _Bool pool_share, enum POOL_TYPE pool_type, void *(*chunk_alloc)(void *m_pool, unsigned long), void (*chunk_free)(void *m_pool, void *chunk), void (*pool_destory)(void *m_pool))
{
 switch(pool_type){
 case LINK_POOL:
 case POOL_CUSTOMIZE:
     return link_mempool_init(size, pool_share, chunk_alloc, chunk_free, pool_destory);
     break;
 default:
     printf("unkno");
     exit(1);
 }
}

variable_types:
size
unsigned long

variable_types: enum POOL_TYPE { POOL_TYPE_MIN=-1, LINK_POOL=0, POOL_CUSTOMIZE=1, POOL_TYPE_MAX=2 }

return_type: struct mempool_class { void *m_pool; struct mempool_func { void *(*chunk_alloc)(void *m_pool, unsigned long); void (*chunk_free)(void *m_pool, void *chunk); void (*pool_free)(void *m_pool); } m_func; } *


main

canonical_name: main

repo: scvalex/markov

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_QWORD *v4; // rbp
size_t v5; // r13
const char *v6; // rbx
int v7; // er12
__int64 v8; // rax
const char **v9; // r13
int v10; // er14
const char *i; // rbx
__int64 *v12; // rbx
const char *v13; // rsi
const char *v14; // rsi
__int64 v15; // rbx
int v16; // er14
int v17; // er9
int v18; // er10
int v19; // er9
int v20; // er9
int v21; // er10
int v22; // er11
int v23; // er13
int v24; // eax
const char *v25; // rsi
__int64 v27; // r9
int v28; // er15
char *ptr; // [rsp+8h] [rbp-40h]

v3 = time(0LL);
srand(v3);
ptr = (char *)calloc((size_t)&dword_400000, 1uLL);
if ( !ptr )
__assert_fail("text", "markov.c", 0x29u, "main");
v4 = calloc(0x100000uLL, 8uLL);
if ( !v4 )
__assert_fail("words", "markov.c", 0x2Eu, "main");
v5 = 0LL;
*v4 = ptr;
while ( 1 )
{
v7 = v5;
if ( (unsigned int)__isoc99_scanf() == -1 )
break;
if ( v5 == 1048573 )
__assert_fail("nwords < words_count - ngram_n", "markov.c", 0x34u, "main");
v6 = (const char *)v4[v5++];
if ( v6 >= ptr + 4194284 )
__assert_fail("words[nwords] < text + text_size - 20", "markov.c", 0x35u, "main");
v4[v5] = &v6[strlen(v6) + 1];
}
qsort(v4, v5, 8uLL, sortcmp);
do
{
v8 = rand() % v7;
v9 = (const char **)&v4[v8];
v10 = v8;
for ( i = *v9; i; ++v10 )
{
if ( i[strlen(i) - 1] == 46 )
break;
i = v9[1];
++v9;
}
}
while ( v10 == -1 );
v12 = &v4[v10];
v13 = (const char *)skip_words(*v12, 1LL);
if ( v13 )
{
printf("%s ", v13);
v14 = (const char *)skip_words(*v12, 2LL);
if ( v14 )
printf("%s ", v14);
}
v15 = *v12;
v16 = 300;
do
{
v17 = 1;
do
{
v18 = v17;
v19 = 2 * v17;
}
while ( v19 < v7 && (int)wordsncmp(v4[v19], v15) < 0 );
v20 = 0;
if ( v18 > 0 )
{
do
{
while ( v20 + v18 >= v7 )
{
v18 >>= 1;
if ( !v18 )
goto LABEL_28;
}
if ( (int)wordsncmp(v4[v20 + v18], v15) < 0 )
v20 = v22;
v18 = v21 >> 1;
}
while ( v18 );
LABEL_28:
v28 = v20 + 1;
LODWORD(v27) = v20 + 2;
}
else
{
LODWORD(v27) = 2;
v28 = 1;
}
v27 = (int)v27;
do
v23 = v27;
while ( !(unsigned int)wordsncmp(v15, v4[v27]) );
v24 = rand();
v15 = skip_words(v4[v28 + v24 % (v23 - v28)], 1LL);
v25 = (const char *)skip_words(v15, 2LL);
if ( *v25 )
printf("%s ", v25);
--v16;
}
while ( v16 );
putchar(10);
free(v4);
free(ptr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_QWORD *v4; // rbp
size_t v5; // r13
const char *v6; // rbx
int v7; // er12
__int64 v8; // rax
const char **v9; // r13
int v10; // er14
const char *i; // rbx
__int64 *v12; // rbx
const char *v13; // rsi
const char *v14; // rsi
__int64 v15; // rbx
int v16; // er14
int v17; // er9
int v18; // er10
int v19; // er9
int v20; // er9
int v21; // er10
int v22; // er11
int v23; // er13
int v24; // eax
const char *v25; // rsi
__int64 v27; // r9
int v28; // er15
char *ptr; // [rsp+8h] [rbp-40h]

v3 = time(0LL);
srand(v3);
ptr = (char *)calloc((size_t)&dword_400000, 1uLL);
if ( !ptr )
__assert_fail("text", "markov.c", 0x29u, "main");
v4 = calloc(0x100000uLL, 8uLL);
if ( !v4 )
__assert_fail("words", "markov.c", 0x2Eu, "main");
v5 = 0LL;
*v4 = ptr;
while ( 1 )
{
v7 = v5;
if ( (unsigned int)__isoc99_scanf() == -1 )
break;
if ( v5 == 1048573 )
__assert_fail("nwords < words_count - ngram_n", "markov.c", 0x34u, "main");
v6 = (const char *)v4[v5++];
if ( v6 >= ptr + 4194284 )
__assert_fail("words[nwords] < text + text_size - 20", "markov.c", 0x35u, "main");
v4[v5] = &v6[strlen(v6) + 1];
}
qsort(v4, v5, 8uLL, sortcmp);
do
{
v8 = rand() % v7;
v9 = (const char **)&v4[v8];
v10 = v8;
for ( i = *v9; i; ++v10 )
{
if ( i[strlen(i) - 1] == 46 )
break;
i = v9[1];
++v9;
}
}
while ( v10 == -1 );
v12 = &v4[v10];
v13 = (const char *)skip_words(*v12, 1LL);
if ( v13 )
{
printf("%s ", v13);
v14 = (const char *)skip_words(*v12, 2LL);
if ( v14 )
printf("%s ", v14);
}
v15 = *v12;
v16 = 300;
do
{
v17 = 1;
do
{
v18 = v17;
v19 = 2 * v17;
}
while ( v19 < v7 && (int)func7(v4[v19], v15) < 0 );
v20 = 0;
if ( v18 > 0 )
{
do
{
while ( v20 + v18 >= v7 )
{
v18 >>= 1;
if ( !v18 )
goto LABEL_28;
}
if ( (int)func7(v4[v20 + v18], v15) < 0 )
v20 = v22;
v18 = v21 >> 1;
}
while ( v18 );
LABEL_28:
v28 = v20 + 1;
LODWORD(v27) = v20 + 2;
}
else
{
LODWORD(v27) = 2;
v28 = 1;
}
v27 = (int)v27;
do
v23 = v27;
while ( !(unsigned int)func7(v15, v4[v27]) );
v24 = rand();
v15 = skip_words(v4[v28 + v24 % (v23 - v28)], 1LL);
v25 = (const char *)skip_words(v15, 2LL);
if ( *v25 )
printf("%s ", v25);
--v16;
}
while ( v16 );
putchar(10);
free(v4);
free(ptr);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    srand(time(0));
    int text_size = 4 * 1024 * 1024;
    char *text = (char*)calloc(text_size, sizeof(char));
    ((void) sizeof ((text) ? 1 : 0), __extension__ ({ if (text) ; else __assert_fail ("text", "markov.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    int words_count = 1024 * 1024;
    char **words = (char**)calloc(words_count, sizeof(char*));
    ((void) sizeof ((words) ? 1 : 0), __extension__ ({ if (words) ; else __assert_fail ("words", "markov.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    int nwords = 0;
    words[0] = text;
    while (scanf("%s", words[nwords]) != (-1)) {
        ((void) sizeof ((nwords < words_count - ngram_n) ? 1 : 0), __extension__ ({ if (nwords < words_count - ngram_n) ; else __assert_fail ("nwords < words_count - ngram_n", "markov.c", 52, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((words[nwords] < text + text_size - 20) ? 1 : 0), __extension__ ({ if (words[nwords] < text + text_size - 20) ; else __assert_fail ("words[nwords] < text + text_size - 20", "markov.c", 53, __extension__ __PRETTY_FUNCTION__); }));
        words[nwords + 1] = words[nwords] + strlen(words[nwords]) + 1;
        ++nwords;
    }
    qsort(words, nwords, sizeof(words[0]), sortcmp);
    int aux = -1;
    while (aux == -1) {
        aux = rand() % nwords;
        while (words[aux] && words[aux][strlen(words[aux]) - 1] != '.') {
            ++aux;
        }
    }
    for (int i = 1; i < ngram_n && skip_words(words[aux], i) != 0; ++i)
        printf("%s ", skip_words(words[aux], i));
    char *phrase = words[aux];
    for (int wordsleft = 300; wordsleft > 0; --wordsleft) {
        int i = 1;
        for (; (i<<1) < nwords && wordsncmp(words[i<<1], phrase) < 0; i = i<<1)
            ;
        int lower = 0;
        for (; i > 0; i = i>>1) {
            if (lower + i < nwords && wordsncmp(words[lower + i], phrase) < 0)
                lower += i;
        }
        lower++;
        int start = lower;
        int end = lower + 1;
        for (; wordsncmp(phrase, words[end]) == 0; ++end)
            ;
        --end;
        char *next_phrase = words[start + rand() % (end - start + 1)];
        phrase = skip_words(next_phrase, 1);
        if (strlen(skip_words(phrase, ngram_n - 1)) == 0)
            continue;
        printf("%s ", skip_words(phrase, ngram_n - 1));
    }
    printf("\n");
    free(words);
    free(text);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
text
char *

variable_types:
words
char **

variable_types: nwords int

variable_types: aux int

variable_types: i int

variable_types:
phrase
char *

variable_types: wordsleft int

variable_types: lower int

variable_types: start int

variable_types: end int

return_type: int


wordsncmp

decompiled_code:
__int64 __fastcall wordsncmp(char *a1, _BYTE *a2)
{
char v2; // dl
int v3; // ecx
__int64 v4; // rax
unsigned int v5; // er8

v2 = *a1;
v3 = (char)*a2;
if ( *a1 != *a2 )
return (unsigned int)(v2 - v3);
v4 = 1LL;
v5 = 3;
while ( v2 || --v5 )
{
v2 = a1[v4++];
v3 = (char)a2[v4 - 1];
if ( v2 != a2[v4 - 1] )
return (unsigned int)(v2 - v3);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, _BYTE *a2)
{
char v2; // dl
int v3; // ecx
__int64 v4; // rax
unsigned int v5; // er8

v2 = *a1;
v3 = (char)*a2;
if ( *a1 != *a2 )
return (unsigned int)(v2 - v3);
v4 = 1LL;
v5 = 3;
while ( v2 || --v5 )
{
v2 = a1[v4++];
v3 = (char)a2[v4 - 1];
if ( v2 != a2[v4 - 1] )
return (unsigned int)(v2 - v3);
}
return v5;
}

original_code:
int wordsncmp(char *p, char *q) {
    int n = ngram_n;
    for (; *p == *q; ++p, ++q) {
        if (*p == 0) {
            n--;
            if (n == 0) {
                return 0;
            }
        }
    }
    return (*p - *q);
}

variable_types:
p
char *

variable_types:
q
char *

variable_types: n int


sortcmp

decompiled_code:
__int64 __fastcall sortcmp(const void *a1, const void *a2)
{
return wordsncmp(*(char **)a1, *(_BYTE **)a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(const void *a1, const void *a2)
{
return func7(*(char **)a1, *(_BYTE **)a2);
}

original_code:
int sortcmp(const void *a, const void *b) {
    return wordsncmp(*(char**)a, *(char**)b);
}

canonical_original_code:
int sortcmp(void *a, void *b) {
    return wordsncmp(*(char **)a, *(char **)b);
}

variable_types:
a
void *

variable_types:
b
void *


usage

repo: scyphus/aos

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(
stderr,
"Usage: %s output-image-file ipl loader kernel\r\n"
"\tAlign and merge `ipl', `loader', and kernel to `output-image-file'.\r\n"
"\tThe size of `ipl' must be less than or equal to 442 bytes.\r\n"
"\tThe size of `loader' must be less than or equal to 32KiB bytes.\r\n"
"\tThe overall size must be less than or equal to 14.4MiB.\r\n",
a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fprintf(
stderr,
"Usage: %s output-image-file ipl loader kernel\r\n"
"\tAlign and merge `ipl', `loader', and kernel to `output-image-file'.\r\n"
"\tThe size of `ipl' must be less than or equal to 442 bytes.\r\n"
"\tThe size of `loader' must be less than or equal to 32KiB bytes.\r\n"
"\tThe overall size must be less than or equal to 14.4MiB.\r\n",
a1);
exit(1);
}

original_code:
void
usage(const char *prog)
{
    fprintf(stderr,
            "Usage: %s output-image-file ipl loader kernel\r\n"
            "\tAlign and merge `ipl', `loader', and kernel to"
            " `output-image-file'.\r\n"
            "\tThe size of `ipl' must be less than or equal to 442 bytes.\r\n"
            "\tThe size of `loader' must be less than or equal to 32KiB"
            " bytes.\r\n"
            "\tThe overall size must be less than or equal to 14.4MiB.\r\n",
            prog);
    exit(1);
}

canonical_original_code:
void usage(char *prog)
{
    fprintf(stderr,
            "Usage: %s output-image-file ipl loader kernel\r\n"
            "\tAlign and merge `ipl', `loader', and kernel to"
            " `output-image-file'.\r\n"
            "\tThe size of `ipl' must be less than or equal to 442 bytes.\r\n"
            "\tThe size of `loader' must be less than or equal to 32KiB"
            " bytes.\r\n"
            "\tThe overall size must be less than or equal to 14.4MiB.\r\n",
            prog);
    exit(1);
}

variable_types:
prog
char *

return_type: void


repo: sdbakker/sio-platform

decompiled_code:
__int64 __fastcall sios_param_set_servicetext(char *src, __int64 a2)
{
char *v2; // rbp
size_t v3; // rbx
size_t v4; // rax
__int64 result; // rax

if ( strlen(src) + 1 > 0x100 )
{
fprintf(stdout, "Warning: [%s] servicetext to long\n", _this_object);
result = 0xFFFFFFFFLL;
}
else
{
v2 = *(char **)(a2 + 16);
v3 = 0LL;
strncpy(v2, src, 0x100uLL);
v4 = strlen(v2);
while ( v3 < v4 )
{
if ( v2[v3] == 44 )
{
v2[v3] = 1;
v4 = strlen(v2);
}
++v3;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, __int64 a2)
{
char *v2; // rbp
size_t v3; // rbx
size_t v4; // rax
__int64 result; // rax

if ( strlen(src) + 1 > 0x100 )
{
fprintf(stdout, "Warning: [%s] servicetext to long\n", _this_object);
result = 0xFFFFFFFFLL;
}
else
{
v2 = *(char **)(a2 + 16);
v3 = 0LL;
strncpy(v2, src, 0x100uLL);
v4 = strlen(v2);
while ( v3 < v4 )
{
if ( v2[v3] == 44 )
{
v2[v3] = 1;
v4 = strlen(v2);
}
++v3;
}
result = 0LL;
}
return result;
}

original_code:
static int sios_param_set_servicetext(const char * val, struct sios_param * p)
{
 int i;
 char * txt;
 if (strlen(val) + 1 > 256) {
  fprintf(stdout, "Warning: [%s] " "servicetext to long" "\n", ((&__this_object))->name);
  return -1;
 }
 txt = (char *)p->arg;
 strncpy(txt, val, 256);
 for (i=0;i<strlen(txt);i++) {
  if (txt[i] == ',')
   txt[i] = 1;
 }
 return 0;
}

canonical_original_code:
static int sios_param_set_servicetext(char *val, struct sios_param *p)
{
 int i;
 char *txt;
 if (strlen(val) + 1 > 256) {
  fprintf(stdout, "Warning: [%s] " "servicetext to long" "\n", ((&__this_object))->name);
  return -1;
 }
 txt = (char *)p->arg;
 strncpy(txt, val, 256);
 for (i=0;i<strlen(txt);i++) {
  if (txt[i] == ',')
   txt[i] = 1;
 }
 return 0;
}

variable_types:
val
char *

variable_types: struct sios_param { char *name; int (*set)(char *val, struct sios_param *); void *arg; } *

variable_types:
txt
char *


decompiled_code:
int sios_dnssd_init()
{
int result; // eax

if ( (unsigned int)mDNS_Init(&mDNSStorage, &mDNSPlatformStorage, 0LL, 0LL, 1LL, 0LL, 0LL) )
result = -1;
else
result = pthread_create(&main_dnssd_thread, 0LL, the_main_dnssd_loop, 0LL);
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

if ( (unsigned int)mDNS_Init(&mDNSStorage, &mDNSPlatformStorage, 0LL, 0LL, 1LL, 0LL, 0LL) )
result = -1;
else
result = pthread_create(&main_dnssd_thread, 0LL, the_main_dnssd_loop, 0LL);
return result;
}

original_code:
static int sios_dnssd_init()
{
 int retval;
 mStatus status;
 status = mDNS_Init(&mDNSStorage, &mDNSPlatformStorage,
      0L, 0,
      mDNStrue,
      0L, 0L);
 if (status != mStatus_NoError)
  return -1;
 retval = pthread_create(&main_dnssd_thread, ((void *)0), the_main_dnssd_loop, ((void *)0));
 if (retval)
  return retval;
 return 0;
}

canonical_original_code:
static int sios_dnssd_init()
{
 int retval;
 int status;
 status = mDNS_Init(&mDNSStorage, &mDNSPlatformStorage,
      0L, 0,
      mDNStrue,
      0L, 0L);
 if (status != mStatus_NoError)
  return -1;
 retval = pthread_create(&main_dnssd_thread, ((void *)0), the_main_dnssd_loop, ((void *)0));
 if (retval)
  return retval;
 return 0;
}

variable_types: retval int

variable_types: status int


decompiled_code:
void *__fastcall the_main_dnssd_loop(void *a1)
{
int nfds; // [rsp+Ch] [rbp-ACh] BYREF
struct timeval timeout; // [rsp+10h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-98h] BYREF

fprintf(stdout, "[%s] started\n", _this_object);
while ( 1 )
{
nfds = 0;
pthread_mutex_lock(&halt_lock);
if ( halt )
break;
pthread_mutex_unlock(&halt_lock);
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
mDNSPosixGetFDSet(&mDNSStorage, &nfds, &readfds, &timeout);
if ( select(nfds, &readfds, 0LL, 0LL, &timeout) >= 0 )
{
mDNSPosixProcessFDSet(&mDNSStorage, &readfds);
}
else if ( *_errno_location() != 4 )
{
return 0LL;
}
}
pthread_mutex_unlock(&halt_lock);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
int nfds; // [rsp+Ch] [rbp-ACh] BYREF
struct timeval timeout; // [rsp+10h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-98h] BYREF

fprintf(stdout, "[%s] started\n", _this_object);
while ( 1 )
{
nfds = 0;
pthread_mutex_lock(&halt_lock);
if ( halt )
break;
pthread_mutex_unlock(&halt_lock);
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
mDNSPosixGetFDSet(&mDNSStorage, &nfds, &readfds, &timeout);
if ( select(nfds, &readfds, 0LL, 0LL, &timeout) >= 0 )
{
mDNSPosixProcessFDSet(&mDNSStorage, &readfds);
}
else if ( *_errno_location() != 4 )
{
return 0LL;
}
}
pthread_mutex_unlock(&halt_lock);
return 0LL;
}

original_code:
static void * the_main_dnssd_loop(void * arg)
{
 fprintf(stdout, "[%s] " "started" "\n", ((&__this_object))->name);
 while (1) {
  struct timeval tv;
  int n, nfds = 0;
  fd_set readfds;
  pthread_mutex_lock(&halt_lock);
  if (halt) {
   pthread_mutex_unlock(&halt_lock);
   return ((void *)0);
  }
  pthread_mutex_unlock(&halt_lock);
  tv.tv_sec = 5;
  tv.tv_usec = 0;
  mDNSPosixGetFDSet(&mDNSStorage, &nfds, &readfds, &tv);
  n = select(nfds, &readfds, ((void *)0), ((void *)0), &tv);
  if (n < 0) {
   if ((*__errno_location ()) != 4)
    return ((void *)0);
  } else
   mDNSPosixProcessFDSet(&mDNSStorage, &readfds);
 }
}

canonical_original_code:
static void *the_main_dnssd_loop(void *arg)
{
 fprintf(stdout, "[%s] " "started" "\n", ((&__this_object))->name);
 while (1) {
  struct timeval tv;
  int n; int nfds = 0;
  struct fd_set readfds;
  pthread_mutex_lock(&halt_lock);
  if (halt) {
   pthread_mutex_unlock(&halt_lock);
   return ((void *)0);
  }
  pthread_mutex_unlock(&halt_lock);
  tv.tv_sec = 5;
  tv.tv_usec = 0;
  mDNSPosixGetFDSet(&mDNSStorage, &nfds, &readfds, &tv);
  n = select(nfds, &readfds, ((void *)0), ((void *)0), &tv);
  if (n < 0) {
   if ((*__errno_location ()) != 4)
    return ((void *)0);
  } else
   mDNSPosixProcessFDSet(&mDNSStorage, &readfds);
 }
}

variable_types:
arg
void *

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

variable_types: nfds int

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

return_type: void *


decompiled_code:
int sios_dnssd_deregister()
{
mDNS_DeregisterService(&mDNSStorage, &service_record_set);
return fprintf(stdout, "[%s] Deregistered service\n", _this_object);
}

canonical_decompiled_code:
int func4()
{
mDNS_DeregisterService(&mDNSStorage, &service_record_set);
return fprintf(stdout, "[%s] Deregistered service\n", _this_object);
}

original_code:
static void sios_dnssd_deregister()
{
 mDNS_DeregisterService(&mDNSStorage, &service_record_set);
 fprintf(stdout, "[%s] " "Deregistered service" "\n", ((&__this_object))->name);
}


decompiled_code:
__int64 dnssd_init()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 result; // rax
unsigned int v3; // er12

v0 = sios_object_register(_this_object, _this_class[0]);
if ( v0 )
{
v3 = v0;
fprintf(stderr, "Error: [%s] failed registering comm object\n", _this_object);
result = v3;
}
else
{
v1 = sios_dnssd_init();
if ( v1 )
{
fprintf(stderr, "Error: [%s] failed initializing mDNS\n", _this_object);
sios_object_deregister(_this_object);
result = v1;
}
else
{
if ( (unsigned int)sios_dnssd_register_service_constprop_0(port) )
{
fprintf(stderr, "Error: [%s] failed registering service\n", _this_object);
sios_object_deregister(_this_object);
sios_dnssd_close_isra_0();
mDNS_Close(&mDNSStorage);
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 result; // rax
unsigned int v3; // er12

v0 = sios_object_register(_this_object, _this_class[0]);
if ( v0 )
{
v3 = v0;
fprintf(stderr, "Error: [%s] failed registering comm object\n", _this_object);
result = v3;
}
else
{
v1 = func1();
if ( v1 )
{
fprintf(stderr, "Error: [%s] failed initializing mDNS\n", _this_object);
sios_object_deregister(_this_object);
result = v1;
}
else
{
if ( (unsigned int)func6(port) )
{
fprintf(stderr, "Error: [%s] failed registering service\n", _this_object);
sios_object_deregister(_this_object);
func7();
mDNS_Close(&mDNSStorage);
}
result = 0LL;
}
}
return result;
}

original_code:
int dnssd_init(void)
{
 int retval;
 retval = sios_object_register((&__this_object), __this_class);
 if (retval) {
  fprintf(stderr, "Error: [%s] " "failed registering comm object" "\n", ((&__this_object))->name);
  return retval;
 }
 retval = sios_dnssd_init();
 if (retval) {
  fprintf(stderr, "Error: [%s] " "failed initializing mDNS" "\n", ((&__this_object))->name);
  sios_object_deregister((&__this_object));
  return retval;
 }
 retval = sios_dnssd_register_service( dnstxt, name, type, domain, port);
 if (retval) {
  fprintf(stderr, "Error: [%s] " "failed registering service" "\n", ((&__this_object))->name);
  sios_object_deregister((&__this_object));
  sios_dnssd_close();
  mDNS_Close(&mDNSStorage);
 }
 return 0;
}

canonical_original_code:
int dnssd_init()
{
 int retval;
 retval = sios_object_register((&__this_object), __this_class);
 if (retval) {
  fprintf(stderr, "Error: [%s] " "failed registering comm object" "\n", ((&__this_object))->name);
  return retval;
 }
 retval = sios_dnssd_init();
 if (retval) {
  fprintf(stderr, "Error: [%s] " "failed initializing mDNS" "\n", ((&__this_object))->name);
  sios_object_deregister((&__this_object));
  return retval;
 }
 retval = sios_dnssd_register_service( dnstxt, name, type, domain, port);
 if (retval) {
  fprintf(stderr, "Error: [%s] " "failed registering service" "\n", ((&__this_object))->name);
  sios_object_deregister((&__this_object));
  sios_dnssd_close();
  mDNS_Close(&mDNSStorage);
 }
 return 0;
}


decompiled_code:
__int64 dnssd_exit()
{
sios_object_deregister(_this_object);
sios_dnssd_close_isra_0();
return mDNS_Close(&mDNSStorage);
}

canonical_decompiled_code:
__int64 func18()
{
sios_object_deregister(_this_object);
func7();
return mDNS_Close(&mDNSStorage);
}

original_code:
void dnssd_exit(void)
{
 sios_object_deregister((&__this_object));
 sios_dnssd_close();
 mDNS_Close(&mDNSStorage);
}

canonical_original_code:
void dnssd_exit()
{
 sios_object_deregister((&__this_object));
 sios_dnssd_close();
 mDNS_Close(&mDNSStorage);
}


decompiled_code:
void __fastcall handle_sigint(int a1)
{
if ( (unsigned int)(a1 - 2) > 1 )
{
if ( use_syslog )
syslog(
1,
"Assertion %s:%d in %s(): \"%s\"",
"main.c",
42LL,
"handle_sigint",
"sigraised == SIGINT || sigraised == SIGQUIT");
else
fprintf(
stderr,
"Assertion %s:%d in %s(): \"%s\"\n",
"main.c",
42LL,
"handle_sigint",
"sigraised == SIGINT || sigraised == SIGQUIT");
}
if ( use_syslog )
syslog(6, "[%s] Caught SIGINT/SIGQUIT, exiting...\n", "Core");
else
fprintf(stdout, "[%s] Caught SIGINT/SIGQUIT, exiting...\n\n", "Core");
halt = 1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( (unsigned int)(a1 - 2) > 1 )
{
if ( use_syslog )
syslog(
1,
"Assertion %s:%d in %s(): \"%s\"",
"main.c",
42LL,
"handle_sigint",
"sigraised == SIGINT || sigraised == SIGQUIT");
else
fprintf(
stderr,
"Assertion %s:%d in %s(): \"%s\"\n",
"main.c",
42LL,
"handle_sigint",
"sigraised == SIGINT || sigraised == SIGQUIT");
}
if ( use_syslog )
syslog(6, "[%s] Caught SIGINT/SIGQUIT, exiting...\n", "Core");
else
fprintf(stdout, "[%s] Caught SIGINT/SIGQUIT, exiting...\n\n", "Core");
halt = 1;
}

original_code:
static void handle_sigint(int sigraised)
{
 if (!(sigraised == 2 || sigraised == 3)) do { if (use_syslog) { syslog(1, "Assertion %s:%d in %s(): \"%s\"", "main.c", 42, __FUNCTION__, "sigraised == SIGINT || sigraised == SIGQUIT"); } else { fprintf(stderr, "Assertion %s:%d in %s(): \"%s\"" "\n", "main.c", 42, __FUNCTION__, "sigraised == SIGINT || sigraised == SIGQUIT"); } } while (0);
 do { if (use_syslog) { syslog(6, "[%s] " "Caught SIGINT/SIGQUIT, exiting...\n","Core"); } else { fprintf(stdout, "[%s] " "Caught SIGINT/SIGQUIT, exiting...\n" "\n","Core"); } } while (0);
 halt = 1;
}

variable_types: sigraised int


decompiled_code:
__int64 main_cleanup()
{
sios_core_exit();
return sios_osc_terminate();
}

canonical_decompiled_code:
__int64 func1()
{
sios_core_exit();
return sios_osc_terminate();
}

original_code:
static void main_cleanup(void)
{
 sios_core_exit();
 sios_osc_terminate();
}

canonical_original_code:
static void main_cleanup()
{
 sios_core_exit();
 sios_osc_terminate();
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
__int64 v5; // rdi
int v6; // ebp
int longind; // [rsp+Ch] [rbp-9Ch] BYREF
char dest[16]; // [rsp+10h] [rbp-98h] BYREF
__int128 v10; // [rsp+20h] [rbp-88h]
__int128 v11; // [rsp+30h] [rbp-78h]
__int128 v12; // [rsp+40h] [rbp-68h]
__int128 v13; // [rsp+50h] [rbp-58h]
__int128 v14; // [rsp+60h] [rbp-48h]
__int128 v15; // [rsp+70h] [rbp-38h]
__int128 v16; // [rsp+80h] [rbp-28h]

v3 = 0;
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC24);
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
signal(2, handle_sigint);
signal(3, handle_sigint);
while ( 1 )
{
longind = 0;
v4 = getopt_long(argc, (char *const *)argv, "p:f:Vh", &long_options_2, &longind);
if ( v4 < 0 )
break;
if ( v4 == 102 )
{
strncpy(dest, optarg, 0x80uLL);
}
else if ( v4 > 102 )
{
if ( v4 == 104 )
LABEL_26:
usage_constprop_0();
if ( v4 == 112 )
v3 = atoi(optarg);
}
else
{
if ( v4 == 63 )
goto LABEL_26;
if ( v4 == 86 )
{
puts("2.1.0");
exit(0);
}
}
}
printf("\n\tStarting SIOS version %s\n\n", "2.1.0");
if ( !sios_read_config(dest) )
{
if ( use_syslog )
syslog(0, "FATALITY: [%s] Error reading configuration", "Main");
else
fprintf(stderr, "FATALITY: [%s] Error reading configuration\n", "Main");
exit(1);
}
if ( use_syslog )
openlog("sios", 35, 8);
v5 = config;
if ( v3 > 0 )
*(_DWORD *)(config + 8LL) = v3;
v6 = sios_osc_init(v5);
if ( v6 )
{
if ( use_syslog )
syslog(0, "FATALITY: [%s] Initializing OSC failed", "Main");
else
fprintf(stderr, "FATALITY: [%s] Initializing OSC failed\n", "Main");
LABEL_32:
exit(v6);
}
v6 = sios_core_init();
if ( v6 )
{
if ( use_syslog )
syslog(0, "FATALITY: [%s] Initializing core failed", "Main");
else
fprintf(stderr, "FATALITY: [%s] Initializing core failed\n", "Main");
goto LABEL_32;
}
if ( *(_BYTE *)(config + 17LL) )
sios_dump_xml();
while ( !halt )
sleep(1u);
main_cleanup();
if ( use_syslog )
closelog();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
__int64 v5; // rdi
int v6; // ebp
int longind; // [rsp+Ch] [rbp-9Ch] BYREF
char dest[16]; // [rsp+10h] [rbp-98h] BYREF
__int128 v10; // [rsp+20h] [rbp-88h]
__int128 v11; // [rsp+30h] [rbp-78h]
__int128 v12; // [rsp+40h] [rbp-68h]
__int128 v13; // [rsp+50h] [rbp-58h]
__int128 v14; // [rsp+60h] [rbp-48h]
__int128 v15; // [rsp+70h] [rbp-38h]
__int128 v16; // [rsp+80h] [rbp-28h]

v3 = 0;
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC24);
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
signal(2, handle_sigint);
signal(3, handle_sigint);
while ( 1 )
{
longind = 0;
v4 = getopt_long(argc, (char *const *)argv, "p:f:Vh", &long_options_2, &longind);
if ( v4 < 0 )
break;
if ( v4 == 102 )
{
strncpy(dest, optarg, 0x80uLL);
}
else if ( v4 > 102 )
{
if ( v4 == 104 )
LABEL_26:
func2();
if ( v4 == 112 )
v3 = atoi(optarg);
}
else
{
if ( v4 == 63 )
goto LABEL_26;
if ( v4 == 86 )
{
puts("2.1.0");
exit(0);
}
}
}
printf("\n\tStarting SIOS version %s\n\n", "2.1.0");
if ( !sios_read_config(dest) )
{
if ( use_syslog )
syslog(0, "FATALITY: [%s] Error reading configuration", "Main");
else
fprintf(stderr, "FATALITY: [%s] Error reading configuration\n", "Main");
exit(1);
}
if ( use_syslog )
openlog("sios", 35, 8);
v5 = config;
if ( v3 > 0 )
*(_DWORD *)(config + 8LL) = v3;
v6 = sios_osc_init(v5);
if ( v6 )
{
if ( use_syslog )
syslog(0, "FATALITY: [%s] Initializing OSC failed", "Main");
else
fprintf(stderr, "FATALITY: [%s] Initializing OSC failed\n", "Main");
LABEL_32:
exit(v6);
}
v6 = sios_core_init();
if ( v6 )
{
if ( use_syslog )
syslog(0, "FATALITY: [%s] Initializing core failed", "Main");
else
fprintf(stderr, "FATALITY: [%s] Initializing core failed\n", "Main");
goto LABEL_32;
}
if ( *(_BYTE *)(config + 17LL) )
sios_dump_xml();
while ( !halt )
sleep(1u);
func1();
if ( use_syslog )
closelog();
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 char config_file[128] = "/etc/sios.config";
 int osc_port = 0;
 int retval;
 signal(2, handle_sigint);
 signal(3, handle_sigint);
 while(1) {
  static int c;
  int option_index = 0;
  static struct option long_options[] = {
   {"osc_port", 1, 0, 'p'},
   {"config", 1, 0, 'f'},
   {"version", 0, 0, 'V'},
   {0, 0, 0, 0}
  };
  c = getopt_long(argc, argv, "p:f:Vh", long_options, &option_index);
  if (c<0)
   break;
  switch(c) {
   case 'p':
    osc_port = atoi(optarg);
    break;
   case 'f':
    strncpy(config_file, optarg, 128);
    break;
   case 'V':
    printf("2.1.0" "\n");
    exit(0);
   case 'h':
   case '?':
    usage(argv[0]);
   default:
    break;
  }
 }
 printf("\n\tStarting SIOS version %s\n\n", "2.1.0");
 if (!sios_read_config(config_file))
  do { do { if (use_syslog) { syslog(0, "FATALITY: [%s] " "Error reading configuration","Main"); } else { fprintf(stderr, "FATALITY: [%s] " "Error reading configuration" "\n","Main"); } } while (0); exit((1)); } while (0);
 if (use_syslog)
  openlog("sios", 0x02|0x20|0x01, (1<<3));
 if (osc_port > 0) config->osc.port = osc_port;
 retval = sios_osc_init(&config->osc);
 if (retval)
  do { do { if (use_syslog) { syslog(0, "FATALITY: [%s] " "Initializing OSC failed","Main"); } else { fprintf(stderr, "FATALITY: [%s] " "Initializing OSC failed" "\n","Main"); } } while (0); exit((retval)); } while (0);
 retval = sios_core_init();
 if (retval)
  do { do { if (use_syslog) { syslog(0, "FATALITY: [%s] " "Initializing core failed","Main"); } else { fprintf(stderr, "FATALITY: [%s] " "Initializing core failed" "\n","Main"); } } while (0); exit((retval)); } while (0);
 if (config->dump_module_xml)
  sios_dump_xml();
 while (!halt)
  sleep(1);
 main_cleanup();
 if (use_syslog)
  closelog();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char config_file[128] = "/etc/sios.config";
 int osc_port = 0;
 int retval;
 signal(2, handle_sigint);
 signal(3, handle_sigint);
 while(1) {
  static int c;
  int option_index = 0;
  static struct option long_options[] = {
   {"osc_port", 1, 0, 'p'},
   {"config", 1, 0, 'f'},
   {"version", 0, 0, 'V'},
   {0, 0, 0, 0}
  };
  c = getopt_long(argc, argv, "p:f:Vh", long_options, &option_index);
  if (c<0)
   break;
  switch(c) {
   case 'p':
    osc_port = atoi(optarg);
    break;
   case 'f':
    strncpy(config_file, optarg, 128);
    break;
   case 'V':
    printf("2.1.0" "\n");
    exit(0);
   case 'h':
   case '?':
    usage(argv[0]);
   default:
    break;
  }
 }
 printf("\n\tStarting SIOS version %s\n\n", "2.1.0");
 if (!sios_read_config(config_file))
  do { do { if (use_syslog) { syslog(0, "FATALITY: [%s] " "Error reading configuration","Main"); } else { fprintf(stderr, "FATALITY: [%s] " "Error reading configuration" "\n","Main"); } } while (0); exit((1)); } while (0);
 if (use_syslog)
  openlog("sios", 0x02|0x20|0x01, (1<<3));
 if (osc_port > 0) config->osc.port = osc_port;
 retval = sios_osc_init(&config->osc);
 if (retval)
  do { do { if (use_syslog) { syslog(0, "FATALITY: [%s] " "Initializing OSC failed","Main"); } else { fprintf(stderr, "FATALITY: [%s] " "Initializing OSC failed" "\n","Main"); } } while (0); exit((retval)); } while (0);
 retval = sios_core_init();
 if (retval)
  do { do { if (use_syslog) { syslog(0, "FATALITY: [%s] " "Initializing core failed","Main"); } else { fprintf(stderr, "FATALITY: [%s] " "Initializing core failed" "\n","Main"); } } while (0); exit((retval)); } while (0);
 if (config->dump_module_xml)
  sios_dump_xml();
 while (!halt)
  sleep(1);
 main_cleanup();
 if (use_syslog)
  closelog();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


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

_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*v1 = 0LL;
v1[1] = 0LL;
}

original_code:
static inline void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = ((void *)0);
 entry->prev = ((void *)0);
}

variable_types: struct list_head { struct list_head *next; } *


decompiled_code:
void __fastcall sios_param_set_val(__int64 a1, const char *a2)
{
if ( a1 )
{
if ( a2 )
*(_QWORD *)(a1 + 8) = strdup(a2);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, const char *a2)
{
if ( a1 )
{
if ( a2 )
*(_QWORD *)(a1 + 8) = strdup(a2);
}
}

original_code:
void sios_param_set_val(struct sios_param_type * ptype, const char * val)
{
 if (!ptype || !val)
  return;
 ptype->val = strdup(val);
}

canonical_original_code:
void sios_param_set_val(struct sios_param_type *ptype, char *val)
{
 if (!ptype || !val)
  return;
 ptype->val = strdup(val);
}

variable_types: struct sios_param_type { char *name; char *val; struct list_head { struct list_head *next; } params; } *

user_defined_types: struct sios_param_type { char *name; char *val; struct list_head params; }


decompiled_code:
void __fastcall sios_param_destroy(void *ptr)
{
list_del((__int64)ptr + 16);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
func4((__int64)ptr + 16);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void sios_param_destroy(struct sios_param_type * ptype)
{
 list_del(&ptype->params);
 free(ptype->name);
 free(ptype->val);
 free(ptype);
}

canonical_original_code:
void sios_param_destroy(struct sios_param_type *ptype)
{
 list_del(&ptype->params);
 free(ptype->name);
 free(ptype->val);
 free(ptype);
}

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
void __fastcall sios_param_add_param(__int64 a1, __int64 a2)
{
if ( a2 )
{
if ( a1 )
list_add((_QWORD *)(a2 + 16), (__int64 *)(a1 + 16));
}
}

original_code:
struct sios_param_type * sios_param_add_param(struct sios_param_type * head,
           struct sios_param_type * ptype)
{
 if (!ptype || !head)
  return ((void *)0);
 list_add(&ptype->params, &head->params);
 return head;
}

canonical_original_code:
struct sios_param_type *sios_param_add_param(struct sios_param_type *head, struct sios_param_type *ptype)
{
 if (!ptype || !head)
  return ((void *)0);
 list_add(&ptype->params, &head->params);
 return head;
}

variable_types:
head
struct sios_param_type *

variable_types:
ptype
struct sios_param_type *

return_type: struct sios_param_type { char *name; char *val; struct list_head { struct list_head *next; } params; } *


decompiled_code:
__int64 __fastcall sios_param_set_byte(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtoul(a1, &endptr, 0);
if ( endptr == a1 || (v2 & 0xFFFFFFFFFFFFFF00LL) != 0 )
return 0xFFFFFFFFLL;
**(_BYTE **)(a2 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtoul(a1, &endptr, 0);
if ( endptr == a1 || (v2 & 0xFFFFFFFFFFFFFF00LL) != 0 )
return 0xFFFFFFFFLL;
**(_BYTE **)(a2 + 16) = v2;
return 0LL;
}

original_code: int sios_param_set_byte(const char *val, struct sios_param *p) { char *endp; unsigned long l; if (!val) return -1; l = strtoul(val, &endp, 0); if (endp == val || ((unsigned char)l != l)) return -1; *((unsigned char *)p->arg) = l; return 0; }

canonical_original_code: int sios_param_set_byte(char *val, struct sios_param *p) { char *endp; unsigned long l; if (!val) return -1; l = strtoul(val, &endp, 0); if (endp == val || ((unsigned char)l != l)) return -1; *((unsigned char *)p->arg) = l; return 0; }

variable_types:
val
char *

variable_types: struct sios_param { char *name; int (*set)(char *val, struct sios_param *); void *arg; } *

variable_types:
endp
char *

variable_types:
l
unsigned long


decompiled_code:
__int64 __fastcall sios_param_set_short(const char *a1, __int64 a2)
{
__int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtol(a1, &endptr, 0);
if ( endptr == a1 || (__int16)v2 != v2 )
return 0xFFFFFFFFLL;
**(_WORD **)(a2 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
__int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtol(a1, &endptr, 0);
if ( endptr == a1 || (__int16)v2 != v2 )
return 0xFFFFFFFFLL;
**(_WORD **)(a2 + 16) = v2;
return 0LL;
}

original_code: int sios_param_set_short(const char *val, struct sios_param *p) { char *endp; long l; if (!val) return -1; l = strtol(val, &endp, 0); if (endp == val || ((short)l != l)) return -1; *((short *)p->arg) = l; return 0; }

canonical_original_code: int sios_param_set_short(char *val, struct sios_param *p) { char *endp; long l; if (!val) return -1; l = strtol(val, &endp, 0); if (endp == val || ((short)l != l)) return -1; *((short *)p->arg) = l; return 0; }

variable_types: l long

user_defined_types: struct sios_param { char *name; int (*set)(char *val, struct sios_param *); void *arg; }


decompiled_code:
__int64 __fastcall sios_param_set_ushort(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtoul(a1, &endptr, 0);
if ( endptr == a1 || (v2 & 0xFFFFFFFFFFFF0000LL) != 0 )
return 0xFFFFFFFFLL;
**(_WORD **)(a2 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtoul(a1, &endptr, 0);
if ( endptr == a1 || (v2 & 0xFFFFFFFFFFFF0000LL) != 0 )
return 0xFFFFFFFFLL;
**(_WORD **)(a2 + 16) = v2;
return 0LL;
}

original_code: int sios_param_set_ushort(const char *val, struct sios_param *p) { char *endp; unsigned long l; if (!val) return -1; l = strtoul(val, &endp, 0); if (endp == val || ((unsigned short)l != l)) return -1; *((unsigned short *)p->arg) = l; return 0; }

canonical_original_code: int sios_param_set_ushort(char *val, struct sios_param *p) { char *endp; unsigned long l; if (!val) return -1; l = strtoul(val, &endp, 0); if (endp == val || ((unsigned short)l != l)) return -1; *((unsigned short *)p->arg) = l; return 0; }


decompiled_code:
__int64 __fastcall sios_param_set_int(const char *a1, __int64 a2)
{
__int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtol(a1, &endptr, 0);
if ( endptr == a1 || (int)v2 != v2 )
return 0xFFFFFFFFLL;
**(_DWORD **)(a2 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, __int64 a2)
{
__int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtol(a1, &endptr, 0);
if ( endptr == a1 || (int)v2 != v2 )
return 0xFFFFFFFFLL;
**(_DWORD **)(a2 + 16) = v2;
return 0LL;
}

original_code: int sios_param_set_int(const char *val, struct sios_param *p) { char *endp; long l; if (!val) return -1; l = strtol(val, &endp, 0); if (endp == val || ((int)l != l)) return -1; *((int *)p->arg) = l; return 0; }

canonical_original_code: int sios_param_set_int(char *val, struct sios_param *p) { char *endp; long l; if (!val) return -1; l = strtol(val, &endp, 0); if (endp == val || ((int)l != l)) return -1; *((int *)p->arg) = l; return 0; }


decompiled_code:
__int64 __fastcall sios_param_set_uint(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtoul(a1, &endptr, 0);
if ( endptr == a1 || v2 != (unsigned int)v2 )
return 0xFFFFFFFFLL;
**(_DWORD **)(a2 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtoul(a1, &endptr, 0);
if ( endptr == a1 || v2 != (unsigned int)v2 )
return 0xFFFFFFFFLL;
**(_DWORD **)(a2 + 16) = v2;
return 0LL;
}

original_code: int sios_param_set_uint(const char *val, struct sios_param *p) { char *endp; unsigned long l; if (!val) return -1; l = strtoul(val, &endp, 0); if (endp == val || ((unsigned int)l != l)) return -1; *((unsigned int *)p->arg) = l; return 0; }

canonical_original_code: int sios_param_set_uint(char *val, struct sios_param *p) { char *endp; unsigned long l; if (!val) return -1; l = strtoul(val, &endp, 0); if (endp == val || ((unsigned int)l != l)) return -1; *((unsigned int *)p->arg) = l; return 0; }


decompiled_code:
__int64 __fastcall sios_param_set_long(const char *a1, __int64 a2)
{
__int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtol(a1, &endptr, 0);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
**(_QWORD **)(a2 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, __int64 a2)
{
__int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtol(a1, &endptr, 0);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
**(_QWORD **)(a2 + 16) = v2;
return 0LL;
}

original_code: int sios_param_set_long(const char *val, struct sios_param *p) { char *endp; long l; if (!val) return -1; l = strtol(val, &endp, 0); if (endp == val || ((long)l != l)) return -1; *((long *)p->arg) = l; return 0; }

canonical_original_code: int sios_param_set_long(char *val, struct sios_param *p) { char *endp; long l; if (!val) return -1; l = strtol(val, &endp, 0); if (endp == val || ((long)l != l)) return -1; *((long *)p->arg) = l; return 0; }


decompiled_code:
__int64 __fastcall sios_param_set_ulong(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtoul(a1, &endptr, 0);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
**(_QWORD **)(a2 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, __int64 a2)
{
unsigned __int64 v2; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtoul(a1, &endptr, 0);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
**(_QWORD **)(a2 + 16) = v2;
return 0LL;
}

original_code: int sios_param_set_ulong(const char *val, struct sios_param *p) { char *endp; unsigned long l; if (!val) return -1; l = strtoul(val, &endp, 0); if (endp == val || ((unsigned long)l != l)) return -1; *((unsigned long *)p->arg) = l; return 0; }

canonical_original_code: int sios_param_set_ulong(char *val, struct sios_param *p) { char *endp; unsigned long l; if (!val) return -1; l = strtoul(val, &endp, 0); if (endp == val || ((unsigned long)l != l)) return -1; *((unsigned long *)p->arg) = l; return 0; }


decompiled_code:
__int64 __fastcall sios_param_set_float(const char *a1, __int64 a2)
{
double v2; // xmm0_8
float v3; // xmm2_4
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtod(a1, &endptr);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
v3 = v2;
if ( v3 != v2 )
return 0xFFFFFFFFLL;
**(float **)(a2 + 16) = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1, __int64 a2)
{
double v2; // xmm0_8
float v3; // xmm2_4
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtod(a1, &endptr);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
v3 = v2;
if ( v3 != v2 )
return 0xFFFFFFFFLL;
**(float **)(a2 + 16) = v3;
return 0LL;
}

original_code:
int sios_param_set_float(const char *val, struct sios_param *p)
{
 char *endp;
 double tmp;
 if (!val) return -1;
 tmp = strtod(val, &endp);
 if (endp == val || (float)tmp != tmp)
  return -1;
 *((float *)p->arg) = tmp;
 return 0;
}

canonical_original_code:
int sios_param_set_float(char *val, struct sios_param *p)
{
 char *endp;
 double tmp;
 if (!val) return -1;
 tmp = strtod(val, &endp);
 if (endp == val || (float)tmp != tmp)
  return -1;
 *((float *)p->arg) = tmp;
 return 0;
}

variable_types: tmp double


decompiled_code:
__int64 __fastcall sios_param_set_double(const char *a1, __int64 a2)
{
double v2; // xmm0_8
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtod(a1, &endptr);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
**(double **)(a2 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(const char *a1, __int64 a2)
{
double v2; // xmm0_8
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = strtod(a1, &endptr);
if ( endptr == a1 )
return 0xFFFFFFFFLL;
**(double **)(a2 + 16) = v2;
return 0LL;
}

original_code:
int sios_param_set_double(const char *val, struct sios_param *p)
{
 char *endp;
 double d;
 if (!val) return -1;
 d = strtod(val, &endp);
 if (endp == val)
  return -1;
 *((double *)p->arg) = d;
 return 0;
}

canonical_original_code:
int sios_param_set_double(char *val, struct sios_param *p)
{
 char *endp;
 double d;
 if (!val) return -1;
 d = strtod(val, &endp);
 if (endp == val)
  return -1;
 *((double *)p->arg) = d;
 return 0;
}

variable_types: d double


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

if ( a1 )
{
if ( strlen(a1) > 0x400 )
{
printf("%s: string parameter too long\n", *a2);
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)a2[2] = a1;
result = 0LL;
}
}
else
{
printf("%s: string parameter expected\n", *a2);
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
if ( strlen(a1) > 0x400 )
{
printf("%s: string parameter too long\n", *a2);
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)a2[2] = a1;
result = 0LL;
}
}
else
{
printf("%s: string parameter expected\n", *a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sios_param_set_charp(const char *val, struct sios_param *p)
{
 if (!val) {
  printf("%s: string parameter expected\n", p->name);
  return -1;
 }
 if (strlen(val) > 1024) {
  printf("%s: string parameter too long\n",
         p->name);
  return -1;
 }
 *(char **)p->arg = (char *)val;
 return 0;
}

canonical_original_code:
int sios_param_set_charp(char *val, struct sios_param *p)
{
 if (!val) {
  printf("%s: string parameter expected\n", p->name);
  return -1;
 }
 if (strlen(val) > 1024) {
  printf("%s: string parameter too long\n",
         p->name);
  return -1;
 }
 *(char **)p->arg = (char *)val;
 return 0;
}


decompiled_code:
__int64 __fastcall sios_param_set_bool(_BYTE *a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
{
switch ( *a1 )
{
case '0':
case 'F':
case 'N':
case 'f':
case 'n':
**(_DWORD **)(a2 + 16) = 0;
result = 0LL;
break;
case '1':
case 'T':
case 'Y':
case 't':
case 'y':
goto LABEL_4;
default:
result = 0xFFFFFFFFLL;
break;
}
}
else
{
LABEL_4:
**(_DWORD **)(a2 + 16) = 1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(_BYTE *a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
{
switch ( *a1 )
{
case '0':
case 'F':
case 'N':
case 'f':
case 'n':
**(_DWORD **)(a2 + 16) = 0;
result = 0LL;
break;
case '1':
case 'T':
case 'Y':
case 't':
case 'y':
goto LABEL_4;
default:
result = 0xFFFFFFFFLL;
break;
}
}
else
{
LABEL_4:
**(_DWORD **)(a2 + 16) = 1;
result = 0LL;
}
return result;
}

original_code:
int sios_param_set_bool(const char *val, struct sios_param *p) {
 if (!val) val = "1";
 switch (val[0]) {
 case 'y': case 'Y': case 't': case 'T': case '1':
  *(int *)p->arg = 1;
  return 0;
 case 'n': case 'N': case 'f': case 'F': case '0':
  *(int *)p->arg = 0;
  return 0;
 }
 return -1;
}

canonical_original_code:
int sios_param_set_bool(char *val, struct sios_param *p) {
 if (!val) val = "1";
 switch (val[0]) {
 case 'y': case 'Y': case 't': case 'T': case '1':
  *(int *)p->arg = 1;
  return 0;
 case 'n': case 'N': case 'f': case 'F': case '0':
  *(int *)p->arg = 0;
  return 0;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall sios_param_set_invbool(_BYTE *a1)
{
__int64 result; // rax
__int64 v2; // rdx
int v3; // [rsp+Ch] [rbp-2Ch] BYREF
__int128 v4; // [rsp+10h] [rbp-28h] BYREF
int *v5; // [rsp+20h] [rbp-18h]

v4 = 0LL;
v5 = &v3;
result = sios_param_set_bool(a1, (__int64)&v4);
if ( !(_DWORD)result )
**(_DWORD **)(v2 + 16) = v3 == 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(_BYTE *a1)
{
__int64 result; // rax
__int64 v2; // rdx
int v3; // [rsp+Ch] [rbp-2Ch] BYREF
__int128 v4; // [rsp+10h] [rbp-28h] BYREF
int *v5; // [rsp+20h] [rbp-18h]

v4 = 0LL;
v5 = &v3;
result = func18(a1, (__int64)&v4);
if ( !(_DWORD)result )
**(_DWORD **)(v2 + 16) = v3 == 0;
return result;
}

original_code:
int sios_param_set_invbool(const char *val, struct sios_param *p)
{
 int boolval, ret;
 struct sios_param dummy = { .arg = &boolval };
 ret = sios_param_set_bool(val, &dummy);
 if (ret == 0)
  *(int *)p->arg = !boolval;
 return ret;
}

canonical_original_code:
int sios_param_set_invbool(char *val, struct sios_param *p)
{
 int boolval; int ret;
 struct sios_param dummy = { .arg = &boolval };
 ret = sios_param_set_bool(val, &dummy);
 if (ret == 0)
  *(int *)p->arg = !boolval;
 return ret;
}

variable_types: boolval int

variable_types: ret int

variable_types: struct sios_param { char *name; int (*set)(char *val, struct sios_param *); void *arg; }


decompiled_code:
__int64 __fastcall sios_param_set_copystring(void *src, __int64 a2)
{
void **v2; // r12
size_t v3; // rax
__int64 result; // rax

v2 = *(void ***)(a2 + 16);
v3 = strlen((const char *)src);
if ( v3 + 1 > *(int *)v2 )
{
printf("%s: string doesn't fit in %u chars.\n", *(const char **)a2, (unsigned int)(*(_DWORD *)v2 - 1));
result = 0xFFFFFFFFLL;
}
else
{
memcpy(v2[1], src, v3 + 1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(void *src, __int64 a2)
{
void **v2; // r12
size_t v3; // rax
__int64 result; // rax

v2 = *(void ***)(a2 + 16);
v3 = strlen((const char *)src);
if ( v3 + 1 > *(int *)v2 )
{
printf("%s: string doesn't fit in %u chars.\n", *(const char **)a2, (unsigned int)(*(_DWORD *)v2 - 1));
result = 0xFFFFFFFFLL;
}
else
{
memcpy(v2[1], src, v3 + 1);
result = 0LL;
}
return result;
}

original_code:
int sios_param_set_copystring(const char *val, struct sios_param *p)
{
 struct sios_param_string *ps = p->arg;
 if (strlen(val)+1 > ps->maxlen) {
  printf("%s: string doesn't fit in %u chars.\n",
         p->name, ps->maxlen-1);
  return -1;
 }
 strcpy(ps->string, val);
 return 0;
}

canonical_original_code:
int sios_param_set_copystring(char *val, struct sios_param *p)
{
 struct sios_param_string *ps = p->arg;
 if (strlen(val)+1 > ps->maxlen) {
  printf("%s: string doesn't fit in %u chars.\n",
         p->name, ps->maxlen-1);
  return -1;
 }
 strcpy(ps->string, val);
 return 0;
}

variable_types: struct sios_param_string { int maxlen; char *string; } *


decompiled_code:
__int64 __fastcall sios_config_get_keyword(char *s1)
{
const char *v1; // rsi
char **v2; // rbx

v1 = sios_config_keywords;
if ( !sios_config_keywords )
return 0xFFFFFFFFLL;
v2 = &sios_config_keywords;
do
{
if ( !strcasecmp(s1, v1) )
return *((unsigned int *)v2 + 2);
v1 = v2[2];
v2 += 2;
}
while ( v1 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
const char *v1; // rsi
char **v2; // rbx

v1 = sios_config_keywords;
if ( !sios_config_keywords )
return 0xFFFFFFFFLL;
v2 = &sios_config_keywords;
do
{
if ( !strcasecmp(s1, v1) )
return *((unsigned int *)v2 + 2);
v1 = v2[2];
v2 += 2;
}
while ( v1 );
return 0xFFFFFFFFLL;
}

original_code:
int sios_config_get_keyword(const char * kword)
{
 struct kword *kw = sios_config_keywords;
 while (kw->name) {
  if (!strcasecmp(kword, kw->name))
   return kw->type;
  kw++;
 }
 return -1;
}

canonical_original_code:
int sios_config_get_keyword(char *kword)
{
 struct kword *kw = sios_config_keywords;
 while (kw->name) {
  if (!strcasecmp(kword, kw->name))
   return kw->type;
  kw++;
 }
 return -1;
}

variable_types:
kword
char *

variable_types: struct kword { char *name; int type; } *


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

_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*v1 = 0LL;
v1[1] = 0LL;
}

original_code:
static inline void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = ((void *)0);
 entry->prev = ((void *)0);
}

variable_types: struct list_head { struct list_head *next; } *


decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
static inline int list_empty(const struct list_head *head)
{
 return head->next == head;
}

canonical_original_code:
static inline int list_empty(struct list_head *head)
{
 return head->next == head;
}


decompiled_code:
void __fastcall sios_class_destroy(void *ptr)
{
if ( ptr )
{
free(ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
if ( ptr )
{
free(ptr);
free(ptr);
}
}

original_code:
void sios_class_destroy(struct sios_class * class)
{
 if (class) {
  free(class->name);
  free(class);
 }
}

canonical_original_code:
void sios_class_destroy(struct sios_class *class)
{
 if (class) {
  free(class->name);
  free(class);
 }
}

variable_types: struct sios_class { char name[64]; char classpath[128]; struct list_head { struct list_head *next; } object_list; struct list_head class_head; } *

user_defined_types: struct sios_class { char name[64]; char classpath[128]; struct list_head object_list; struct list_head class_head; }


decompiled_code:
void __fastcall sios_class_register(char *s2)
{
if ( s2 )
{
if ( use_syslog )
syslog(6, "[%s] registering class '%s'", "Class", s2);
else
fprintf(stdout, "[%s] registering class '%s'\n", "Class", s2);
if ( sios_find_class_by_name(s2) )
{
if ( use_syslog )
syslog(4, "Warning: [%s] '%s' already exists", "Class", s2);
else
fprintf(stdout, "Warning: [%s] '%s' already exists\n", "Class", s2);
}
else
{
snprintf(s2 + 64, 0x80uLL, "%s/%s", (const char *)*config, s2);
list_add((_QWORD *)s2 + 26, (__int64 *)&class_list);
}
}
}

canonical_decompiled_code:
void __fastcall func9(char *s2)
{
if ( s2 )
{
if ( use_syslog )
syslog(6, "[%s] registering class '%s'", "Class", s2);
else
fprintf(stdout, "[%s] registering class '%s'\n", "Class", s2);
if ( func6(s2) )
{
if ( use_syslog )
syslog(4, "Warning: [%s] '%s' already exists", "Class", s2);
else
fprintf(stdout, "Warning: [%s] '%s' already exists\n", "Class", s2);
}
else
{
snprintf(s2 + 64, 0x80uLL, "%s/%s", (const char *)*config, s2);
func2((_QWORD *)s2 + 26, (__int64 *)&class_list);
}
}
}

original_code:
int sios_class_register(struct sios_class * class)
{
 if (!class)
  return -1;
 do { if (use_syslog) { syslog(6, "[%s] " "registering class '%s'","Class", class->name); } else { fprintf(stdout, "[%s] " "registering class '%s'" "\n","Class", class->name); } } while (0);
 if (sios_find_class_by_name(class->name)) {
  do { if (use_syslog) { syslog(4, "Warning: [%s] " "'%s' already exists","Class", class->name); } else { fprintf(stdout, "Warning: [%s] " "'%s' already exists" "\n","Class", class->name); } } while (0);
  return -1;
 }
 snprintf(class->classpath, 128, "%s/%s",
   config->osc.root, class->name);
 list_add(&class->class_head, &class_list);
 return 0;
}

canonical_original_code:
int sios_class_register(struct sios_class *class)
{
 if (!class)
  return -1;
 do { if (use_syslog) { syslog(6, "[%s] " "registering class '%s'","Class", class->name); } else { fprintf(stdout, "[%s] " "registering class '%s'" "\n","Class", class->name); } } while (0);
 if (sios_find_class_by_name(class->name)) {
  do { if (use_syslog) { syslog(4, "Warning: [%s] " "'%s' already exists","Class", class->name); } else { fprintf(stdout, "Warning: [%s] " "'%s' already exists" "\n","Class", class->name); } } while (0);
  return -1;
 }
 snprintf(class->classpath, 128, "%s/%s",
   config->osc.root, class->name);
 list_add(&class->class_head, &class_list);
 return 0;
}


decompiled_code:
void __fastcall sios_class_deregister(__int64 a1)
{
__int64 v1; // rdx

if ( a1 )
{
if ( list_empty((_QWORD *)(a1 + 192)) )
list_del(v1 + 208);
}
}

original_code:
void sios_class_deregister(struct sios_class * class)
{
 if (!class || !list_empty(&class->object_list))
  return;
 list_del(&class->class_head);
}

canonical_original_code:
void sios_class_deregister(struct sios_class *class)
{
 if (!class || !list_empty(&class->object_list))
  return;
 list_del(&class->class_head);
}


original_code:
int sios_class_add_object(struct sios_object * object, struct sios_class * class)
{
 if (!object || !class)
  return -1;
 object->class = class;
 list_add(&object->class_head, &class->object_list);
 return 0;
}

canonical_original_code:
int sios_class_add_object(struct sios_object *object, struct sios_class *class)
{
 if (!object || !class)
  return -1;
 object->class = class;
 list_add(&object->class_head, &class->object_list);
 return 0;
}

variable_types: struct sios_object { char name[64]; char path[128]; char *desc; char *id; int type; struct sios_class { char name[64]; char classpath[128]; struct list_head { struct list_head *next; } object_list; struct list_head class_head; } *class; struct list_head class_head; struct list_head object_head; struct list_head osc_methods; struct list_head osc_params; struct list_head listeners; } *

variable_types:
class
struct sios_class *

user_defined_types: struct sios_object { char name[64]; char path[128]; char *desc; char *id; int type; struct sios_class *class; struct list_head class_head; struct list_head object_head; struct list_head osc_methods; struct list_head osc_params; struct list_head listeners; }


decompiled_code:
void __fastcall sios_class_del_object(__int64 a1)
{
if ( a1 )
{
*(_QWORD *)(a1 + 216) = 0LL;
list_del(a1 + 224);
}
}

original_code:
void sios_class_del_object(struct sios_object * object)
{
 if (!object)
  return;
 object->class = ((void *)0);
 list_del(&object->class_head);
}

canonical_original_code:
void sios_class_del_object(struct sios_object *object)
{
 if (!object)
  return;
 object->class = ((void *)0);
 list_del(&object->class_head);
}


decompiled_code:
__int64 sios_dump_classes()
{
return sios_classes_dump_xml(&class_list);
}

canonical_decompiled_code:
__int64 func13()
{
return sios_classes_dump_xml(&class_list);
}

original_code:
void sios_dump_classes(void)
{
 sios_classes_dump_xml(&class_list);
}

canonical_original_code:
void sios_dump_classes()
{
 sios_classes_dump_xml(&class_list);
}


canonical_original_code:
static inline void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = ((void *)0);
 entry->prev = ((void *)0);
}


decompiled_code:
__int64 __fastcall sios_object_register(__int64 a1, __int64 a2)
{
unsigned int v2; // er12

if ( !a1 )
return (unsigned int)-1;
if ( !a2 )
return (unsigned int)-1;
INIT_LIST_HEAD((_QWORD *)(a1 + 224));
INIT_LIST_HEAD((_QWORD *)(a1 + 240));
INIT_LIST_HEAD((_QWORD *)(a1 + 288));
INIT_LIST_HEAD((_QWORD *)(a1 + 256));
INIT_LIST_HEAD((_QWORD *)(a1 + 272));
if ( (v2 = sios_class_add_object(a1)) != 0 )
return (unsigned int)-1;
snprintf((char *)(a1 + 64), 0x80uLL, "%s/%s", (const char *)(a2 + 64), (const char *)a1);
list_add_constprop_0((_QWORD *)(a1 + 240));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned int v2; // er12

if ( !a1 )
return (unsigned int)-1;
if ( !a2 )
return (unsigned int)-1;
func0((_QWORD *)(a1 + 224));
func0((_QWORD *)(a1 + 240));
func0((_QWORD *)(a1 + 288));
func0((_QWORD *)(a1 + 256));
func0((_QWORD *)(a1 + 272));
if ( (v2 = sios_class_add_object(a1)) != 0 )
return (unsigned int)-1;
snprintf((char *)(a1 + 64), 0x80uLL, "%s/%s", (const char *)(a2 + 64), (const char *)a1);
func4((_QWORD *)(a1 + 240));
return v2;
}

original_code:
int sios_object_register(struct sios_object * object, struct sios_class * class)
{
 int retval = 0;
 if (!object || !class)
  return -1;
 INIT_LIST_HEAD(&object->class_head);
 INIT_LIST_HEAD(&object->object_head);
 INIT_LIST_HEAD(&object->listeners);
 INIT_LIST_HEAD(&object->osc_methods);
 INIT_LIST_HEAD(&object->osc_params);
 if (class) {
  retval = sios_class_add_object(object, class);
  if (retval)
   return -1;
  snprintf(object->path, 128, "%s/%s",
    class->classpath, object->name);
 } else {
  object->class = ((void *)0);
  snprintf(object->path, 128, "%s/%s",
    config->osc.root, object->name);
 }
 list_add(&object->object_head, &object_list);
 return 0;
}

canonical_original_code:
int sios_object_register(struct sios_object *object, struct sios_class *class)
{
 int retval = 0;
 if (!object || !class)
  return -1;
 INIT_LIST_HEAD(&object->class_head);
 INIT_LIST_HEAD(&object->object_head);
 INIT_LIST_HEAD(&object->listeners);
 INIT_LIST_HEAD(&object->osc_methods);
 INIT_LIST_HEAD(&object->osc_params);
 if (class) {
  retval = sios_class_add_object(object, class);
  if (retval)
   return -1;
  snprintf(object->path, 128, "%s/%s",
    class->classpath, object->name);
 } else {
  object->class = ((void *)0);
  snprintf(object->path, 128, "%s/%s",
    config->osc.root, object->name);
 }
 list_add(&object->object_head, &object_list);
 return 0;
}

variable_types: retval int


decompiled_code:
void __fastcall sios_object_deregister(__int64 a1)
{
if ( *(_QWORD *)(a1 + 216) )
sios_class_del_object();
list_del(a1 + 240);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
if ( *(_QWORD *)(a1 + 216) )
sios_class_del_object();
func2(a1 + 240);
}

original_code:
void sios_object_deregister(struct sios_object * object)
{
 if (object->class)
  sios_class_del_object(object);
 list_del(&object->object_head);
}

canonical_original_code:
void sios_object_deregister(struct sios_object *object)
{
 if (object->class)
  sios_class_del_object(object);
 list_del(&object->object_head);
}


decompiled_code:
__int64 __fastcall sios_object_can_have_listeners(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = sios_osc_add_listener_handlers();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = sios_osc_add_listener_handlers();
return result;
}

original_code:
void sios_object_can_have_listeners(struct sios_object * object)
{
 if (!object)
  return;
 sios_osc_add_listener_handlers(object);
}

canonical_original_code:
void sios_object_can_have_listeners(struct sios_object *object)
{
 if (!object)
  return;
 sios_osc_add_listener_handlers(object);
}


decompiled_code:
void *__fastcall the_main_writer_loop(void *a1)
{
if ( use_syslog )
syslog(6, "[%s] main writer loop started", "Core");
else
fprintf(stdout, "[%s] main writer loop started\n", "Core");
while ( 1 )
{
pthread_mutex_lock(&halt_lock);
if ( halt )
break;
pthread_mutex_unlock(&halt_lock);
sios_sources_execute_writers();
}
pthread_mutex_unlock(&halt_lock);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
if ( use_syslog )
syslog(6, "[%s] main writer loop started", "Core");
else
fprintf(stdout, "[%s] main writer loop started\n", "Core");
while ( 1 )
{
pthread_mutex_lock(&halt_lock);
if ( halt )
break;
pthread_mutex_unlock(&halt_lock);
sios_sources_execute_writers();
}
pthread_mutex_unlock(&halt_lock);
return 0LL;
}

original_code:
static void * the_main_writer_loop(void * arg)
{
 do { if (use_syslog) { syslog(6, "[%s] " "main writer loop started","Core"); } else { fprintf(stdout, "[%s] " "main writer loop started" "\n","Core"); } } while (0);
 while (1) {
  pthread_mutex_lock(&halt_lock);
  if (halt) {
   pthread_mutex_unlock(&halt_lock);
   return ((void *)0);
  }
  pthread_mutex_unlock(&halt_lock);
  sios_sources_execute_writers();
 }
}

canonical_original_code:
static void *the_main_writer_loop(void *arg)
{
 do { if (use_syslog) { syslog(6, "[%s] " "main writer loop started","Core"); } else { fprintf(stdout, "[%s] " "main writer loop started" "\n","Core"); } } while (0);
 while (1) {
  pthread_mutex_lock(&halt_lock);
  if (halt) {
   pthread_mutex_unlock(&halt_lock);
   return ((void *)0);
  }
  pthread_mutex_unlock(&halt_lock);
  sios_sources_execute_writers();
 }
}

variable_types:
arg
void *


decompiled_code:
void *__fastcall the_main_reader_loop(void *a1)
{
if ( use_syslog )
syslog(6, "[%s] main reader loop started", "Core");
else
fprintf(stdout, "[%s] main reader loop started\n", "Core");
while ( 1 )
{
pthread_mutex_lock(&halt_lock);
if ( halt )
break;
pthread_mutex_unlock(&halt_lock);
sios_sources_execute_readers();
}
pthread_mutex_unlock(&halt_lock);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
if ( use_syslog )
syslog(6, "[%s] main reader loop started", "Core");
else
fprintf(stdout, "[%s] main reader loop started\n", "Core");
while ( 1 )
{
pthread_mutex_lock(&halt_lock);
if ( halt )
break;
pthread_mutex_unlock(&halt_lock);
sios_sources_execute_readers();
}
pthread_mutex_unlock(&halt_lock);
return 0LL;
}

original_code:
static void * the_main_reader_loop(void * arg)
{
 do { if (use_syslog) { syslog(6, "[%s] " "main reader loop started","Core"); } else { fprintf(stdout, "[%s] " "main reader loop started" "\n","Core"); } } while (0);
 while (1) {
  pthread_mutex_lock(&halt_lock);
  if (halt) {
   pthread_mutex_unlock(&halt_lock);
   return ((void *)0);
  }
  pthread_mutex_unlock(&halt_lock);
  sios_sources_execute_readers();
 }
}

canonical_original_code:
static void *the_main_reader_loop(void *arg)
{
 do { if (use_syslog) { syslog(6, "[%s] " "main reader loop started","Core"); } else { fprintf(stdout, "[%s] " "main reader loop started" "\n","Core"); } } while (0);
 while (1) {
  pthread_mutex_lock(&halt_lock);
  if (halt) {
   pthread_mutex_unlock(&halt_lock);
   return ((void *)0);
  }
  pthread_mutex_unlock(&halt_lock);
  sios_sources_execute_readers();
 }
}


decompiled_code:
void sios_core_exit()
{
sios_unload_modules_all();
sios_del_source_ctx(&main_src_ctx);
pthread_mutex_lock(&halt_lock);
halt = 1;
pthread_mutex_unlock(&halt_lock);
if ( use_syslog )
syslog(7, "Debug %s:%d in %s(): joining main reader thread", "core.c", 148LL, "sios_core_exit");
else
fprintf(stdout, "Debug %s:%d in %s(): joining main reader thread\n", "core.c", 148LL, "sios_core_exit");
pthread_join(main_reader_loop_thread, 0LL);
if ( use_syslog )
syslog(7, "Debug %s:%d in %s(): joining main reader thread done", "core.c", 150LL, "sios_core_exit");
else
fprintf(stdout, "Debug %s:%d in %s(): joining main reader thread done\n", "core.c", 150LL, "sios_core_exit");
if ( use_syslog )
syslog(7, "Debug %s:%d in %s(): joining main writer thread", "core.c", 152LL, "sios_core_exit");
else
fprintf(stdout, "Debug %s:%d in %s(): joining main writer thread\n", "core.c", 152LL, "sios_core_exit");
pthread_join(main_writer_loop_thread, 0LL);
if ( use_syslog )
syslog(7, "Debug %s:%d in %s(): joining main writer thread done", "core.c", 154LL, "sios_core_exit");
else
fprintf(stdout, "Debug %s:%d in %s(): joining main writer thread done\n", "core.c", 154LL, "sios_core_exit");
}

canonical_decompiled_code:
void func3()
{
sios_unload_modules_all();
sios_del_source_ctx(&main_src_ctx);
pthread_mutex_lock(&halt_lock);
halt = 1;
pthread_mutex_unlock(&halt_lock);
if ( use_syslog )
syslog(7, "Debug %s:%d in %s(): joining main reader thread", "core.c", 148LL, "sios_core_exit");
else
fprintf(stdout, "Debug %s:%d in %s(): joining main reader thread\n", "core.c", 148LL, "sios_core_exit");
pthread_join(main_reader_loop_thread, 0LL);
if ( use_syslog )
syslog(7, "Debug %s:%d in %s(): joining main reader thread done", "core.c", 150LL, "sios_core_exit");
else
fprintf(stdout, "Debug %s:%d in %s(): joining main reader thread done\n", "core.c", 150LL, "sios_core_exit");
if ( use_syslog )
syslog(7, "Debug %s:%d in %s(): joining main writer thread", "core.c", 152LL, "sios_core_exit");
else
fprintf(stdout, "Debug %s:%d in %s(): joining main writer thread\n", "core.c", 152LL, "sios_core_exit");
pthread_join(main_writer_loop_thread, 0LL);
if ( use_syslog )
syslog(7, "Debug %s:%d in %s(): joining main writer thread done", "core.c", 154LL, "sios_core_exit");
else
fprintf(stdout, "Debug %s:%d in %s(): joining main writer thread done\n", "core.c", 154LL, "sios_core_exit");
}

original_code:
void sios_core_exit()
{
 sios_unload_modules_all();
 sios_del_source_ctx(&main_src_ctx);
 pthread_mutex_lock(&halt_lock);
 halt = 1;
 pthread_mutex_unlock(&halt_lock);
 do { if (use_syslog) { syslog(7, "Debug %s:%d in %s(): " "joining main reader thread", "core.c", 148, __FUNCTION__); } else { fprintf(stdout, "Debug %s:%d in %s(): " "joining main reader thread" "\n", "core.c", 148, __FUNCTION__); } } while (0);
 pthread_join(main_reader_loop_thread, ((void *)0));
 do { if (use_syslog) { syslog(7, "Debug %s:%d in %s(): " "joining main reader thread done", "core.c", 150, __FUNCTION__); } else { fprintf(stdout, "Debug %s:%d in %s(): " "joining main reader thread done" "\n", "core.c", 150, __FUNCTION__); } } while (0);
 do { if (use_syslog) { syslog(7, "Debug %s:%d in %s(): " "joining main writer thread", "core.c", 152, __FUNCTION__); } else { fprintf(stdout, "Debug %s:%d in %s(): " "joining main writer thread" "\n", "core.c", 152, __FUNCTION__); } } while (0);
 pthread_join(main_writer_loop_thread, ((void *)0));
 do { if (use_syslog) { syslog(7, "Debug %s:%d in %s(): " "joining main writer thread done", "core.c", 154, __FUNCTION__); } else { fprintf(stdout, "Debug %s:%d in %s(): " "joining main writer thread done" "\n", "core.c", 154, __FUNCTION__); } } while (0);
}


decompiled_code:
void sios_alloc_module()
{
_QWORD *v0; // rax
__int64 v1; // rax

v0 = malloc(0x90uLL);
if ( v0 )
{
INIT_LIST_HEAD(v0 + 5);
INIT_LIST_HEAD((_QWORD *)(v1 + 56));
}
}

canonical_decompiled_code:
void func6()
{
_QWORD *v0; // rax
__int64 v1; // rax

v0 = malloc(0x90uLL);
if ( v0 )
{
func0(v0 + 5);
func0((_QWORD *)(v1 + 56));
}
}

original_code:
struct sios_module * sios_alloc_module()
{
 struct sios_module * module;
 module = (struct sios_module*)malloc(sizeof(struct sios_module));
 if (!module)
  return ((void *)0);
 INIT_LIST_HEAD(&module->params);
 INIT_LIST_HEAD(&module->list);
 return module;
}

canonical_original_code:
struct sios_module *sios_alloc_module()
{
 struct sios_module *module;
 module = (struct sios_module *)malloc(sizeof(struct sios_module));
 if (!module)
  return ((void *)0);
 INIT_LIST_HEAD(&module->params);
 INIT_LIST_HEAD(&module->list);
 return module;
}

variable_types: struct sios_module { char *__xpg_basename; char *path; int lazy; char *lazy_id; void *dl_handle; struct list_head { struct list_head *next; } params; struct list_head list; char *module_name; char *module_descr; struct sios_class { char name[64]; char classpath[128]; struct list_head object_list; struct list_head class_head; } *class; struct sios_object { char name[64]; char path[128]; char *desc; char *id; int type; struct sios_class *class; struct list_head class_head; struct list_head object_head; struct list_head osc_methods; struct list_head osc_params; struct list_head listeners; } *obj; int (*init)(); void (*destroy)(); void (*set_name)(char *name); void (*set_descr)(char *descr); void (*set_class)(struct sios_class *class); } *

user_defined_types: struct sios_module { char *__xpg_basename; char *path; int lazy; char *lazy_id; void *dl_handle; struct list_head params; struct list_head list; char *module_name; char *module_descr; struct sios_class *class; struct sios_object *obj; int (*init)(); void (*destroy)(); void (*set_name)(char *name); void (*set_descr)(char *descr); void (*set_class)(struct sios_class *class); }


decompiled_code:
void __fastcall sios_module_add_param(__int64 a1, __int64 a2)
{
if ( a2 )
list_add((_QWORD *)(a2 + 16), (__int64 *)(a1 + 40));
}

original_code:
int sios_module_add_param(struct sios_module * module, struct sios_param_type * ptype)
{
 if (!ptype)
  return -1;
 list_add(&ptype->params, &module->params);
 return 0;
}

canonical_original_code:
int sios_module_add_param(struct sios_module *module, struct sios_param_type *ptype)
{
 if (!ptype)
  return -1;
 list_add(&ptype->params, &module->params);
 return 0;
}

variable_types: struct sios_param_type { char *name; char *val; struct list_head params; } *


decompiled_code:
__int64 __fastcall sios_load_module(__int64 a1)
{
void *v2; // rax
__int64 (*v3)(void); // rax
unsigned int v4; // eax
const char *v5; // rcx
const char **v6; // rax
const char *v7; // r8
const char *v8; // rcx
void *v9; // rax
void *v10; // rdi
void *v11; // rax
void *v12; // rdi
void *v13; // rax
void *v14; // rdi
void *v15; // rax
void *v16; // rdi
void *v17; // rax
bool v18; // zf
const char *v20; // rcx
char *v21; // rax
char *v22; // rax

v2 = dlopen(*(const char **)(a1 + 8), 2);
*(_QWORD *)(a1 + 32) = v2;
if ( v2 )
{
v3 = (__int64 (*)(void))dlsym(v2, "__compiled_against_version");
if ( v3 )
{
v4 = v3();
if ( v4 == 131328 )
{
LABEL_7:
v6 = (const char **)dlsym(*(void **)(a1 + 32), "__module_version_str");
if ( v6 )
{
v7 = *v6;
v8 = *(const char **)a1;
if ( use_syslog )
syslog(6, "[%s] loading module '%s' version %s", "Module", v8, v7);
else
fprintf(stdout, "[%s] loading module '%s' version %s\n", "Module", v8, v7);
}
else
{
v20 = *(const char **)a1;
if ( use_syslog )
syslog(6, "[%s] loading module '%s'", "Module", v20);
else
fprintf(stdout, "[%s] loading module '%s'\n", "Module", v20);
}
v9 = dlsym(*(void **)(a1 + 32), "__init_module");
v10 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 104) = v9;
v11 = dlsym(v10, "__exit_module");
v12 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 112) = v11;
v13 = dlsym(v12, "__set_module_name");
v14 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 120) = v13;
v15 = dlsym(v14, "__set_module_descr");
v16 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 128) = v15;
v17 = dlsym(v16, "__set_module_class");
v18 = *(_QWORD *)(a1 + 104) == 0LL;
*(_QWORD *)(a1 + 136) = v17;
if ( !v18 && *(_QWORD *)(a1 + 112) && *(_QWORD *)(a1 + 120) && *(_QWORD *)(a1 + 128) && v17 )
return 0LL;
goto LABEL_23;
}
v5 = *(const char **)(a1 + 72);
if ( !*(_BYTE *)(config + 16LL) )
{
if ( use_syslog )
syslog(
4,
"Warning: [%s] module version mismatch, %s has SIOS version %d, should be %d",
"Module",
v5,
v4,
131328LL);
else
fprintf(
stdout,
"Warning: [%s] module version mismatch, %s has SIOS version %d, should be %d\n",
"Module",
v5,
v4,
131328LL);
goto LABEL_7;
}
if ( use_syslog )
syslog(
3,
"Error: [%s] module version mismatch, %s has SIOS version %d, should be %d",
"Module",
v5,
v4,
131328LL);
else
fprintf(
stderr,
"Error: [%s] module version mismatch, %s has SIOS version %d, should be %d\n",
"Module",
v5,
v4,
131328LL);
}
LABEL_23:
dlclose(*(void **)(a1 + 32));
list_del(a1 + 56);
return 0xFFFFFFFFLL;
}
if ( use_syslog )
{
v21 = dlerror();
syslog(3, "Error: [%s] dlopen() failed: %s", "Module", v21);
}
else
{
v22 = dlerror();
fprintf(stderr, "Error: [%s] dlopen() failed: %s\n", "Module", v22);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
void *v2; // rax
__int64 (*v3)(void); // rax
unsigned int v4; // eax
const char *v5; // rcx
const char **v6; // rax
const char *v7; // r8
const char *v8; // rcx
void *v9; // rax
void *v10; // rdi
void *v11; // rax
void *v12; // rdi
void *v13; // rax
void *v14; // rdi
void *v15; // rax
void *v16; // rdi
void *v17; // rax
bool v18; // zf
const char *v20; // rcx
char *v21; // rax
char *v22; // rax

v2 = dlopen(*(const char **)(a1 + 8), 2);
*(_QWORD *)(a1 + 32) = v2;
if ( v2 )
{
v3 = (__int64 (*)(void))dlsym(v2, "__compiled_against_version");
if ( v3 )
{
v4 = v3();
if ( v4 == 131328 )
{
LABEL_7:
v6 = (const char **)dlsym(*(void **)(a1 + 32), "__module_version_str");
if ( v6 )
{
v7 = *v6;
v8 = *(const char **)a1;
if ( use_syslog )
syslog(6, "[%s] loading module '%s' version %s", "Module", v8, v7);
else
fprintf(stdout, "[%s] loading module '%s' version %s\n", "Module", v8, v7);
}
else
{
v20 = *(const char **)a1;
if ( use_syslog )
syslog(6, "[%s] loading module '%s'", "Module", v20);
else
fprintf(stdout, "[%s] loading module '%s'\n", "Module", v20);
}
v9 = dlsym(*(void **)(a1 + 32), "__init_module");
v10 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 104) = v9;
v11 = dlsym(v10, "__exit_module");
v12 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 112) = v11;
v13 = dlsym(v12, "__set_module_name");
v14 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 120) = v13;
v15 = dlsym(v14, "__set_module_descr");
v16 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 128) = v15;
v17 = dlsym(v16, "__set_module_class");
v18 = *(_QWORD *)(a1 + 104) == 0LL;
*(_QWORD *)(a1 + 136) = v17;
if ( !v18 && *(_QWORD *)(a1 + 112) && *(_QWORD *)(a1 + 120) && *(_QWORD *)(a1 + 128) && v17 )
return 0LL;
goto LABEL_23;
}
v5 = *(const char **)(a1 + 72);
if ( !*(_BYTE *)(config + 16LL) )
{
if ( use_syslog )
syslog(
4,
"Warning: [%s] module version mismatch, %s has SIOS version %d, should be %d",
"Module",
v5,
v4,
131328LL);
else
fprintf(
stdout,
"Warning: [%s] module version mismatch, %s has SIOS version %d, should be %d\n",
"Module",
v5,
v4,
131328LL);
goto LABEL_7;
}
if ( use_syslog )
syslog(
3,
"Error: [%s] module version mismatch, %s has SIOS version %d, should be %d",
"Module",
v5,
v4,
131328LL);
else
fprintf(
stderr,
"Error: [%s] module version mismatch, %s has SIOS version %d, should be %d\n",
"Module",
v5,
v4,
131328LL);
}
LABEL_23:
dlclose(*(void **)(a1 + 32));
func4(a1 + 56);
return 0xFFFFFFFFLL;
}
if ( use_syslog )
{
v21 = dlerror();
syslog(3, "Error: [%s] dlopen() failed: %s", "Module", v21);
}
else
{
v22 = dlerror();
fprintf(stderr, "Error: [%s] dlopen() failed: %s\n", "Module", v22);
}
return 0xFFFFFFFFLL;
}

original_code:
int sios_load_module(struct sios_module * module)
{
 int retval = -1;
 unsigned int compiled_version;
 unsigned int (*get_version)(void);
 char ** version_str;
 module->dl_handle = dlopen(module->path, 0x00002);
 if (!module->dl_handle) {
  do { if (use_syslog) { syslog(3, "Error: [%s] " "dlopen() failed: %s","Module", dlerror()); } else { fprintf(stderr, "Error: [%s] " "dlopen() failed: %s" "\n","Module", dlerror()); } } while (0);
  goto out;
 }
 get_version = dlsym(module->dl_handle, "__compiled_against_version");
 if (!get_version)
  goto out_close_handle;
 compiled_version = get_version();
 if (compiled_version != (((2) << 16) + ((1) << 8) + (0))) {
  if (config->strict_versioning) {
   do { if (use_syslog) { syslog(3, "Error: [%s] " "module version mismatch, %s has SIOS version %d, should be %d","Module", module->module_name, compiled_version, (((2) << 16) + ((1) << 8) + (0))); } else { fprintf(stderr, "Error: [%s] " "module version mismatch, %s has SIOS version %d, should be %d" "\n","Module", module->module_name, compiled_version, (((2) << 16) + ((1) << 8) + (0))); } } while (0);
   goto out_close_handle;
  } else {
   do { if (use_syslog) { syslog(4, "Warning: [%s] " "module version mismatch, %s has SIOS version %d, should be %d","Module", module->module_name, compiled_version, (((2) << 16) + ((1) << 8) + (0))); } else { fprintf(stdout, "Warning: [%s] " "module version mismatch, %s has SIOS version %d, should be %d" "\n","Module", module->module_name, compiled_version, (((2) << 16) + ((1) << 8) + (0))); } } while (0);
  }
 }
 version_str = dlsym(module->dl_handle, "__module_version_str");
 if (version_str)
  do { if (use_syslog) { syslog(6, "[%s] " "loading module '%s' version %s","Module", module->__xpg_basename, *version_str); } else { fprintf(stdout, "[%s] " "loading module '%s' version %s" "\n","Module", module->__xpg_basename, *version_str); } } while (0);
 else
  do { if (use_syslog) { syslog(6, "[%s] " "loading module '%s'","Module", module->__xpg_basename); } else { fprintf(stdout, "[%s] " "loading module '%s'" "\n","Module", module->__xpg_basename); } } while (0);
 module->init = dlsym(module->dl_handle, "__init_module");
 module->destroy = dlsym(module->dl_handle, "__exit_module");
 module->set_name = dlsym(module->dl_handle, "__set_module_name");
 module->set_descr = dlsym(module->dl_handle, "__set_module_descr");
 module->set_class = dlsym(module->dl_handle, "__set_module_class");
 if (!module->init || !module->destroy || !module->set_name
   || !module->set_descr || !module->set_class)
  goto out_close_handle;
 return 0;
out_close_handle:
 dlclose(module->dl_handle);
 list_del(&module->list);
out:
 return retval;
}

canonical_original_code:
int sios_load_module(struct sios_module *module)
{
 int retval = -1;
 unsigned int compiled_version;
 unsigned int (*get_version)();
 char **version_str;
 module->dl_handle = dlopen(module->path, 0x00002);
 if (!module->dl_handle) {
  do { if (use_syslog) { syslog(3, "Error: [%s] " "dlopen() failed: %s","Module", dlerror()); } else { fprintf(stderr, "Error: [%s] " "dlopen() failed: %s" "\n","Module", dlerror()); } } while (0);
  goto out;
 }
 get_version = dlsym(module->dl_handle, "__compiled_against_version");
 if (!get_version)
  goto out_close_handle;
 compiled_version = get_version();
 if (compiled_version != (((2) << 16) + ((1) << 8) + (0))) {
  if (config->strict_versioning) {
   do { if (use_syslog) { syslog(3, "Error: [%s] " "module version mismatch, %s has SIOS version %d, should be %d","Module", module->module_name, compiled_version, (((2) << 16) + ((1) << 8) + (0))); } else { fprintf(stderr, "Error: [%s] " "module version mismatch, %s has SIOS version %d, should be %d" "\n","Module", module->module_name, compiled_version, (((2) << 16) + ((1) << 8) + (0))); } } while (0);
   goto out_close_handle;
  } else {
   do { if (use_syslog) { syslog(4, "Warning: [%s] " "module version mismatch, %s has SIOS version %d, should be %d","Module", module->module_name, compiled_version, (((2) << 16) + ((1) << 8) + (0))); } else { fprintf(stdout, "Warning: [%s] " "module version mismatch, %s has SIOS version %d, should be %d" "\n","Module", module->module_name, compiled_version, (((2) << 16) + ((1) << 8) + (0))); } } while (0);
  }
 }
 version_str = dlsym(module->dl_handle, "__module_version_str");
 if (version_str)
  do { if (use_syslog) { syslog(6, "[%s] " "loading module '%s' version %s","Module", module->__xpg_basename, *version_str); } else { fprintf(stdout, "[%s] " "loading module '%s' version %s" "\n","Module", module->__xpg_basename, *version_str); } } while (0);
 else
  do { if (use_syslog) { syslog(6, "[%s] " "loading module '%s'","Module", module->__xpg_basename); } else { fprintf(stdout, "[%s] " "loading module '%s'" "\n","Module", module->__xpg_basename); } } while (0);
 module->init = dlsym(module->dl_handle, "__init_module");
 module->destroy = dlsym(module->dl_handle, "__exit_module");
 module->set_name = dlsym(module->dl_handle, "__set_module_name");
 module->set_descr = dlsym(module->dl_handle, "__set_module_descr");
 module->set_class = dlsym(module->dl_handle, "__set_module_class");
 if (!module->init || !module->destroy || !module->set_name
   || !module->set_descr || !module->set_class)
  goto out_close_handle;
 return 0;
out_close_handle:
 dlclose(module->dl_handle);
 list_del(&module->list);
out:
 return retval;
}


decompiled_code:
__int64 __fastcall sios_init_module(__int64 a1)
{
unsigned int v2; // er12
const char *v3; // rcx
__int64 result; // rax
void *v5; // rax
const char *v6; // rcx
const char *v7; // rcx

if ( !a1 )
return (unsigned int)-1;
(*(void (__fastcall **)(_QWORD))(a1 + 120))(*(_QWORD *)(a1 + 72));
(*(void (__fastcall **)(_QWORD))(a1 + 128))(*(_QWORD *)(a1 + 80));
(*(void (__fastcall **)(_QWORD))(a1 + 136))(*(_QWORD *)(a1 + 88));
if ( (unsigned int)module_set_params(a1) )
{
v6 = *(const char **)(a1 + 72);
v2 = -1;
if ( use_syslog )
syslog(3, "Error: [%s] Error setting parameters '%s'", "Module", v6);
else
fprintf(stderr, "Error: [%s] Error setting parameters '%s'\n", "Module", v6);
return v2;
}
v2 = (*(__int64 (**)(void))(a1 + 104))();
if ( v2 )
{
v3 = *(const char **)(a1 + 72);
if ( !use_syslog )
{
fprintf(stderr, "Error: [%s] Error initializing '%s'\n", "Module", v3);
return v2;
}
syslog(3, "Error: [%s] Error initializing '%s'", "Module", v3);
result = v2;
}
else
{
v5 = dlsym(*(void **)(a1 + 32), "__this_object");
if ( !v5 )
{
v7 = *(const char **)(a1 + 72);
v2 = -1;
if ( use_syslog )
syslog(3, "Error: [%s] Error getting object '%s'", "Module", v7);
else
fprintf(stderr, "Error: [%s] Error getting object '%s'\n", "Module", v7);
return v2;
}
*(_QWORD *)(a1 + 96) = v5;
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned int v2; // er12
const char *v3; // rcx
__int64 result; // rax
void *v5; // rax
const char *v6; // rcx
const char *v7; // rcx

if ( !a1 )
return (unsigned int)-1;
(*(void (__fastcall **)(_QWORD))(a1 + 120))(*(_QWORD *)(a1 + 72));
(*(void (__fastcall **)(_QWORD))(a1 + 128))(*(_QWORD *)(a1 + 80));
(*(void (__fastcall **)(_QWORD))(a1 + 136))(*(_QWORD *)(a1 + 88));
if ( (unsigned int)func5(a1) )
{
v6 = *(const char **)(a1 + 72);
v2 = -1;
if ( use_syslog )
syslog(3, "Error: [%s] Error setting parameters '%s'", "Module", v6);
else
fprintf(stderr, "Error: [%s] Error setting parameters '%s'\n", "Module", v6);
return v2;
}
v2 = (*(__int64 (**)(void))(a1 + 104))();
if ( v2 )
{
v3 = *(const char **)(a1 + 72);
if ( !use_syslog )
{
fprintf(stderr, "Error: [%s] Error initializing '%s'\n", "Module", v3);
return v2;
}
syslog(3, "Error: [%s] Error initializing '%s'", "Module", v3);
result = v2;
}
else
{
v5 = dlsym(*(void **)(a1 + 32), "__this_object");
if ( !v5 )
{
v7 = *(const char **)(a1 + 72);
v2 = -1;
if ( use_syslog )
syslog(3, "Error: [%s] Error getting object '%s'", "Module", v7);
else
fprintf(stderr, "Error: [%s] Error getting object '%s'\n", "Module", v7);
return v2;
}
*(_QWORD *)(a1 + 96) = v5;
result = v2;
}
return result;
}

original_code:
int sios_init_module(struct sios_module * module)
{
 int retval;
 struct sios_object * obj;
 if (!module)
  return -1;
 module->set_name(module->module_name);
 module->set_descr(module->module_descr);
 module->set_class(module->class);
 if (module_set_params(module)) {
  do { if (use_syslog) { syslog(3, "Error: [%s] " "Error setting parameters '%s'","Module", module->module_name); } else { fprintf(stderr, "Error: [%s] " "Error setting parameters '%s'" "\n","Module", module->module_name); } } while (0);
  return -1;
 }
 retval = module->init();
 if (retval) {
  do { if (use_syslog) { syslog(3, "Error: [%s] " "Error initializing '%s'","Module", module->module_name); } else { fprintf(stderr, "Error: [%s] " "Error initializing '%s'" "\n","Module", module->module_name); } } while (0);
  return retval;
 }
 obj = dlsym(module->dl_handle, "__this_object");
 if (!obj) {
  do { if (use_syslog) { syslog(3, "Error: [%s] " "Error getting object '%s'","Module", module->module_name); } else { fprintf(stderr, "Error: [%s] " "Error getting object '%s'" "\n","Module", module->module_name); } } while (0);
  return -1;
 }
 module->obj = obj;
 return 0;
}

canonical_original_code:
int sios_init_module(struct sios_module *module)
{
 int retval;
 struct sios_object *obj;
 if (!module)
  return -1;
 module->set_name(module->module_name);
 module->set_descr(module->module_descr);
 module->set_class(module->class);
 if (module_set_params(module)) {
  do { if (use_syslog) { syslog(3, "Error: [%s] " "Error setting parameters '%s'","Module", module->module_name); } else { fprintf(stderr, "Error: [%s] " "Error setting parameters '%s'" "\n","Module", module->module_name); } } while (0);
  return -1;
 }
 retval = module->init();
 if (retval) {
  do { if (use_syslog) { syslog(3, "Error: [%s] " "Error initializing '%s'","Module", module->module_name); } else { fprintf(stderr, "Error: [%s] " "Error initializing '%s'" "\n","Module", module->module_name); } } while (0);
  return retval;
 }
 obj = dlsym(module->dl_handle, "__this_object");
 if (!obj) {
  do { if (use_syslog) { syslog(3, "Error: [%s] " "Error getting object '%s'","Module", module->module_name); } else { fprintf(stderr, "Error: [%s] " "Error getting object '%s'" "\n","Module", module->module_name); } } while (0);
  return -1;
 }
 module->obj = obj;
 return 0;
}


decompiled_code:
void __fastcall sios_unload_module(__int64 a1, int a2)
{
if ( a2 )
(*(void (**)(void))(a1 + 112))();
dlclose(*(void **)(a1 + 32));
list_del(a1 + 56);
}

original_code:
void sios_unload_module(struct sios_module * module, int call_module_destroy)
{
 if (call_module_destroy)
  module->destroy();
 dlclose(module->dl_handle);
 list_del(&module->list);
}

canonical_original_code:
void sios_unload_module(struct sios_module *module, int call_module_destroy)
{
 if (call_module_destroy)
  module->destroy();
 dlclose(module->dl_handle);
 list_del(&module->list);
}


decompiled_code:
__int64 sios_dump_modules()
{
return sios_modules_dump_xml(&module_list);
}

canonical_decompiled_code:
__int64 func15()
{
return sios_modules_dump_xml(&module_list);
}

original_code:
void sios_dump_modules(void)
{
 sios_modules_dump_xml(&module_list);
}

canonical_original_code:
void sios_dump_modules()
{
 sios_modules_dump_xml(&module_list);
}


decompiled_code:
void __fastcall free_ifi_info(void *ptr)
{
_QWORD *i; // rbp
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
_QWORD *v5; // rbx

if ( ptr )
{
for ( i = ptr; ; i = v5 )
{
v2 = (void *)i[5];
if ( v2 )
free(v2);
v3 = (void *)i[6];
if ( v3 )
free(v3);
v4 = (void *)i[7];
if ( v4 )
free(v4);
v5 = (_QWORD *)i[8];
free(i);
if ( !v5 )
break;
}
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
_QWORD *i; // rbp
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
_QWORD *v5; // rbx

if ( ptr )
{
for ( i = ptr; ; i = v5 )
{
v2 = (void *)i[5];
if ( v2 )
free(v2);
v3 = (void *)i[6];
if ( v3 )
free(v3);
v4 = (void *)i[7];
if ( v4 )
free(v4);
v5 = (_QWORD *)i[8];
free(i);
if ( !v5 )
break;
}
}
}

original_code:
void
free_ifi_info(struct ifi_info *ifihead)
{
    struct ifi_info *ifi, *ifinext;
    for (ifi = ifihead; ifi != ((void *)0); ifi = ifinext) {
        if (ifi->ifi_addr != ((void *)0))
            free(ifi->ifi_addr);
        if (ifi->ifi_brdaddr != ((void *)0))
            free(ifi->ifi_brdaddr);
        if (ifi->ifi_dstaddr != ((void *)0))
            free(ifi->ifi_dstaddr);
        ifinext = ifi->ifi_next;
        free(ifi);
    }
}

canonical_original_code:
void free_ifi_info(struct ifi_info *ifihead)
{
    struct ifi_info *ifi; struct ifi_info *ifinext;
    for (ifi = ifihead; ifi != ((void *)0); ifi = ifinext) {
        if (ifi->ifi_addr != ((void *)0))
            free(ifi->ifi_addr);
        if (ifi->ifi_brdaddr != ((void *)0))
            free(ifi->ifi_brdaddr);
        if (ifi->ifi_dstaddr != ((void *)0))
            free(ifi->ifi_dstaddr);
        ifinext = ifi->ifi_next;
        free(ifi);
    }
}

variable_types: struct ifi_info { char ifi_name[16]; unsigned char ifi_haddr[8]; unsigned short ifi_hlen; short ifi_flags; short ifi_myflags; int ifi_index; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifi_addr; struct sockaddr *ifi_brdaddr; struct sockaddr *ifi_dstaddr; struct ifi_info *ifi_next; } *

user_defined_types: struct ifi_info { char ifi_name[16]; unsigned char ifi_haddr[8]; unsigned short ifi_hlen; short ifi_flags; short ifi_myflags; int ifi_index; struct sockaddr *ifi_addr; struct sockaddr *ifi_brdaddr; struct sockaddr *ifi_dstaddr; struct ifi_info *ifi_next; }