decompiled_code:
ssize_t __fastcall print_sig_desc(int a1)
{
ssize_t result; // rax

switch ( a1 )
{
case 1:
result = write(1, "\nSIGHUP: hangup\n", 0x11uLL);
break;
case 2:
result = write(1, "\nSIGINT: interrupt (from keyboard)\n", 0x24uLL);
break;
case 3:
result = write(1, "\nSIGQUIT: quit (from keyboard)\n", 0x20uLL);
break;
case 4:
result = write(1, "\nSIGILL: illegal instruction\n", 0x1EuLL);
break;
case 5:
result = write(1, "\nSIGTRAP: trace/breakpoint trap\n", 0x21uLL);
break;
case 6:
result = write(1, "\nSIGABRT: call to abort\n", 0x19uLL);
break;
case 7:
result = write(1, "\nSIGBUS: access to undefined portion of a memory object\n", 0x39uLL);
break;
case 8:
result = write(1, "\nSIGFPE: erroneous arithmetic operation\n", 0x29uLL);
break;
case 9:
result = write(1, "\nSIGKILL: kill; synthetic only\n", 0x20uLL);
break;
case 10:
result = write(1, "\nSIGUSR1: user signal 1; synthetic only\n", 0x29uLL);
break;
case 11:
result = write(1, "\nSIGSEGV: invalid memory reference\n", 0x24uLL);
break;
case 12:
result = write(1, "\nSIGUSR2: user signal 2; synthetic only\n", 0x29uLL);
break;
case 13:
result = write(1, "\nSIGPIPE: write on a pipe with no reader\n", 0x2AuLL);
break;
case 14:
result = write(1, "\nSIGALRM: alarm clock expired\n", 0x1FuLL);
break;
case 15:
result = write(1, "\nSIGTERM: termination; synthetic only\n", 0x27uLL);
break;
case 17:
result = write(1, "\nSIGCHLD: child process terminated or stopped\n", 0x2FuLL);
break;
case 18:
result = write(1, "\nSIGCONT: continue executing (from keyboard)\n", 0x2EuLL);
break;
case 19:
result = write(1, "\nSIGSTOP: stop executing (from keyboard)\n", 0x2AuLL);
break;
case 20:
result = write(1, "\nSIGTSTP: terminal stop signal (from keyboard)\n", 0x30uLL);
break;
case 21:
result = write(1, "\nSIGTTIN: background process attempting read\n", 0x2EuLL);
break;
case 22:
result = write(1, "\nSIGTTOU: background process attemping write\n", 0x2EuLL);
break;
case 23:
result = write(1, "\nSIGURG: out-of-band data available at socket\n", 0x2FuLL);
break;
case 24:
result = write(1, "\nSIGXCPU: CPU-time limit exceeded\n", 0x23uLL);
break;
case 25:
result = write(1, "\nSIGXFSZ: file-size limit exceeded\n", 0x24uLL);
break;
case 26:
result = write(1, "\nSIGVTALRM: virtual timer expired\n", 0x23uLL);
break;
case 27:
result = write(1, "\nSIGPROF: profiling timer expired\n", 0x23uLL);
break;
case 29:
result = write(1, "\nSIGPOLL: pollable event\n", 0x1AuLL);
break;
case 31:
result = write(1, "\nSIGSYS: bad system call\n", 0x1AuLL);
break;
default:
result = write(1, "\nUnknown signal\n", 0x10uLL);
break;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1)
{
ssize_t result; // rax

switch ( a1 )
{
case 1:
result = write(1, "\nSIGHUP: hangup\n", 0x11uLL);
break;
case 2:
result = write(1, "\nSIGINT: interrupt (from keyboard)\n", 0x24uLL);
break;
case 3:
result = write(1, "\nSIGQUIT: quit (from keyboard)\n", 0x20uLL);
break;
case 4:
result = write(1, "\nSIGILL: illegal instruction\n", 0x1EuLL);
break;
case 5:
result = write(1, "\nSIGTRAP: trace/breakpoint trap\n", 0x21uLL);
break;
case 6:
result = write(1, "\nSIGABRT: call to abort\n", 0x19uLL);
break;
case 7:
result = write(1, "\nSIGBUS: access to undefined portion of a memory object\n", 0x39uLL);
break;
case 8:
result = write(1, "\nSIGFPE: erroneous arithmetic operation\n", 0x29uLL);
break;
case 9:
result = write(1, "\nSIGKILL: kill; synthetic only\n", 0x20uLL);
break;
case 10:
result = write(1, "\nSIGUSR1: user signal 1; synthetic only\n", 0x29uLL);
break;
case 11:
result = write(1, "\nSIGSEGV: invalid memory reference\n", 0x24uLL);
break;
case 12:
result = write(1, "\nSIGUSR2: user signal 2; synthetic only\n", 0x29uLL);
break;
case 13:
result = write(1, "\nSIGPIPE: write on a pipe with no reader\n", 0x2AuLL);
break;
case 14:
result = write(1, "\nSIGALRM: alarm clock expired\n", 0x1FuLL);
break;
case 15:
result = write(1, "\nSIGTERM: termination; synthetic only\n", 0x27uLL);
break;
case 17:
result = write(1, "\nSIGCHLD: child process terminated or stopped\n", 0x2FuLL);
break;
case 18:
result = write(1, "\nSIGCONT: continue executing (from keyboard)\n", 0x2EuLL);
break;
case 19:
result = write(1, "\nSIGSTOP: stop executing (from keyboard)\n", 0x2AuLL);
break;
case 20:
result = write(1, "\nSIGTSTP: terminal stop signal (from keyboard)\n", 0x30uLL);
break;
case 21:
result = write(1, "\nSIGTTIN: background process attempting read\n", 0x2EuLL);
break;
case 22:
result = write(1, "\nSIGTTOU: background process attemping write\n", 0x2EuLL);
break;
case 23:
result = write(1, "\nSIGURG: out-of-band data available at socket\n", 0x2FuLL);
break;
case 24:
result = write(1, "\nSIGXCPU: CPU-time limit exceeded\n", 0x23uLL);
break;
case 25:
result = write(1, "\nSIGXFSZ: file-size limit exceeded\n", 0x24uLL);
break;
case 26:
result = write(1, "\nSIGVTALRM: virtual timer expired\n", 0x23uLL);
break;
case 27:
result = write(1, "\nSIGPROF: profiling timer expired\n", 0x23uLL);
break;
case 29:
result = write(1, "\nSIGPOLL: pollable event\n", 0x1AuLL);
break;
case 31:
result = write(1, "\nSIGSYS: bad system call\n", 0x1AuLL);
break;
default:
result = write(1, "\nUnknown signal\n", 0x10uLL);
break;
}
return result;
}

original_code:
void print_sig_desc(int sig)
{
  switch (sig) {
  case 7:
    write(1, "\nSIGBUS:  access to undefined portion of a memory object\n", 57);
    break;
  case 8:
    write(1, "\nSIGFPE:  erroneous arithmetic operation\n", 41);
    break;
  case 4:
    write(1, "\nSIGILL:  illegal instruction\n", 30);
    break;
  case 13:
    write(1, "\nSIGPIPE:  write on a pipe with no reader\n", 42);
    break;
  case 11:
    write(1, "\nSIGSEGV:  invalid memory reference\n", 36);
    break;
  case 31:
    write(1, "\nSIGSYS:  bad system call\n", 26);
    break;
  case 24:
    write(1, "\nSIGXCPU:  CPU-time limit exceeded\n", 35);
    break;
  case 25:
    write(1, "\nSIGXFSZ:  file-size limit exceeded\n", 36);
    break;
  case 6:
    write(1, "\nSIGABRT:  call to abort\n", 25);
    break;
  case 1:
    write(1, "\nSIGHUP:  hangup\n", 17);
    break;
  case 2:
    write(1, "\nSIGINT:  interrupt (from keyboard)\n", 36);
    break;
  case 9:
    write(1, "\nSIGKILL:  kill; synthetic only\n", 32);
    break;
  case 3:
    write(1, "\nSIGQUIT:  quit (from keyboard)\n", 32);
    break;
  case 15:
    write(1, "\nSIGTERM:  termination; synthetic only\n", 39);
    break;
  case 10:
    write(1, "\nSIGUSR1:  user signal 1; synthetic only\n", 41);
    break;
  case 12:
    write(1, "\nSIGUSR2:  user signal 2; synthetic only\n", 41);
    break;
  case 17:
    write(1, "\nSIGCHLD:  child process terminated or stopped\n", 47);
    break;
  case 18:
    write(1, "\nSIGCONT:  continue executing (from keyboard)\n", 46);
    break;
  case 19:
    write(1, "\nSIGSTOP:  stop executing (from keyboard)\n", 42);
    break;
  case 20:
    write(1, "\nSIGTSTP:  terminal stop signal (from keyboard)\n", 48);
    break;
  case 21:
    write(1, "\nSIGTTIN:  background process attempting read\n", 46);
    break;
  case 22:
    write(1, "\nSIGTTOU:  background process attemping write\n", 46);
    break;
  case 14:
    write(1, "\nSIGALRM:  alarm clock expired\n", 31);
    break;
  case 26:
    write(1, "\nSIGVTALRM:  virtual timer expired\n", 35);
    break;
  case 27:
    write(1, "\nSIGPROF:  profiling timer expired\n", 35);
    break;
  case 29:
    write(1, "\nSIGPOLL:  pollable event\n", 26);
    break;
  case 5:
    write(1, "\nSIGTRAP:  trace/breakpoint trap\n", 33);
    break;
  case 23:
    write(1, "\nSIGURG:  out-of-band data available at socket\n", 47);
    break;
  default:
    write(1, "\nUnknown signal\n", 16);
  }
}


repo: scubjwu/mempool

decompiled_code:
int __fastcall cal_run_time(int a1, int a2, int a3, int a4)
{
return printf("time coast: %lf\n", (double)a4 / 1000000.0 - (double)a2 / 1000000.0 + (double)(a3 - a1));
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, int a3, int a4)
{
return printf("time coast: %lf\n", (double)a4 / 1000000.0 - (double)a2 / 1000000.0 + (double)(a3 - a1));
}

original_code:
static void cal_run_time(struct timeval start, struct timeval end)
{
 double time_slot;
 time_slot = end.tv_sec - start.tv_sec + ((double)end.tv_usec/1000000 - (double)start.tv_usec/1000000);
 printf("time coast: %lf\n", time_slot);
 return;
}

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

variable_types:
end
struct timeval

return_type: void


decompiled_code:
int __fastcall thread_test(void *arg)
{
pthread_t *v1; // rbx
pthread_t *v2; // rbp
_BYTE v4[800]; // [rsp+0h] [rbp-348h] BYREF
char v5[40]; // [rsp+320h] [rbp-28h] BYREF

printf("============>%s\n", "thread_test");
v1 = (pthread_t *)v4;
v2 = (pthread_t *)v4;
do
{
if ( pthread_create(v2, 0LL, run_thread, arg) < 0 )
{
perror("pthread_create");
exit(1);
}
++v2;
}
while ( v2 != (pthread_t *)v5 );
do
pthread_join(*v1++, 0LL);
while ( v1 != (pthread_t *)v5 );
return printf("%s<============\n\n", "thread_test");
}

canonical_decompiled_code:
int __fastcall func4(void *arg)
{
pthread_t *v1; // rbx
pthread_t *v2; // rbp
_BYTE v4[800]; // [rsp+0h] [rbp-348h] BYREF
char v5[40]; // [rsp+320h] [rbp-28h] BYREF

printf("============>%s\n", "thread_test");
v1 = (pthread_t *)v4;
v2 = (pthread_t *)v4;
do
{
if ( pthread_create(v2, 0LL, run_thread, arg) < 0 )
{
perror("pthread_create");
exit(1);
}
++v2;
}
while ( v2 != (pthread_t *)v5 );
do
pthread_join(*v1++, 0LL);
while ( v1 != (pthread_t *)v5 );
return printf("%s<============\n\n", "thread_test");
}

original_code:
static void thread_test(mempool pool)
{
 printf("============>%s\n", __FUNCTION__);
 pthread_t tid[100];
 int i;
 for(i=0; i<100; i++){
  if(pthread_create(&tid[i], 0, run_thread, (void *)pool) < 0){
   perror("pthread_create");
   exit(1);
  }
 }
 for(i=0; i<100; i++)
  pthread_join(tid[i], ((void *)0));
 printf("%s<============\n\n", __FUNCTION__);
}

canonical_original_code:
static void thread_test(struct mempool_class *pool)
{
 printf("============>%s\n", __FUNCTION__);
 unsigned long tid[100];
 int i;
 for(i=0; i<100; i++){
  if(pthread_create(&tid[i], 0, run_thread, (void *)pool) < 0){
   perror("pthread_create");
   exit(1);
  }
 }
 for(i=0; i<100; i++)
  pthread_join(tid[i], ((void *)0));
 printf("%s<============\n\n", __FUNCTION__);
}

variable_types: 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; } *

variable_types:
tid
unsigned long [100]

variable_types: i int

user_defined_types: struct mempool_class { void *m_pool; struct mempool_func m_func; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // r14
__int64 v6; // r13
unsigned int v7; // er12
int v8; // eax
char v9; // al
__int64 *v10; // rbx
char v12[53]; // [rsp+3h] [rbp-35h] BYREF

v3 = argc;
if ( argc > 1 )
{
do
{
if ( *argv[1] == 45 )
break;
++argv;
--v3;
}
while ( v3 != 1 );
}
v5 = 0LL;
v6 = 0LL;
v7 = -1;
while ( 1 )
{
v8 = getopt(v3, (char *const *)argv, "n:s:b:r:");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'r':
v7 = atoi(optarg);
break;
case 's':
v5 = atoi(optarg);
break;
case 'b':
v6 = atoi(optarg);
break;
default:
puts("wrong argv!");
exit(1);
}
}
v9 = 1;
if ( v7 == -1 )
{
puts("need round num for stress test(-r)!");
v9 = 0;
}
if ( !v5 )
{
puts("need pool size(-s)!");
if ( v6 )
goto LABEL_22;
goto LABEL_21;
}
if ( !v6 )
{
LABEL_21:
puts("need base size for stress test(-b)!");
LABEL_22:
exit(1);
}
if ( !v9 )
goto LABEL_22;
printf("test pram:\n#pool size: %d\n#round num:%d\t#base size:%d\n\n", v5, v7, v6);
v10 = (__int64 *)mempool_init(v5, 1LL, 0LL, 0LL, 0LL, 0LL);
if ( !v10 )
{
puts("failed on pool create!");
exit(1);
}
puts("done pool create!");
strcpy(v12, "hello world!");
sanity_test(v10, v12);
stress_test(v10, v7, v6);
thread_test(v10);
sim_test(v10, v7, v6);
((void (__fastcall *)(__int64))v10[3])(*v10);
puts("done pool distroy!");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // r14
__int64 v6; // r13
unsigned int v7; // er12
int v8; // eax
char v9; // al
__int64 *v10; // rbx
char v12[53]; // [rsp+3h] [rbp-35h] BYREF

v3 = argc;
if ( argc > 1 )
{
do
{
if ( *argv[1] == 45 )
break;
++argv;
--v3;
}
while ( v3 != 1 );
}
v5 = 0LL;
v6 = 0LL;
v7 = -1;
while ( 1 )
{
v8 = getopt(v3, (char *const *)argv, "n:s:b:r:");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'r':
v7 = atoi(optarg);
break;
case 's':
v5 = atoi(optarg);
break;
case 'b':
v6 = atoi(optarg);
break;
default:
puts("wrong argv!");
exit(1);
}
}
v9 = 1;
if ( v7 == -1 )
{
puts("need round num for stress test(-r)!");
v9 = 0;
}
if ( !v5 )
{
puts("need pool size(-s)!");
if ( v6 )
goto LABEL_22;
goto LABEL_21;
}
if ( !v6 )
{
LABEL_21:
puts("need base size for stress test(-b)!");
LABEL_22:
exit(1);
}
if ( !v9 )
goto LABEL_22;
printf("test pram:\n#pool size: %d\n#round num:%d\t#base size:%d\n\n", v5, v7, v6);
v10 = (__int64 *)mempool_init(v5, 1LL, 0LL, 0LL, 0LL, 0LL);
if ( !v10 )
{
puts("failed on pool create!");
exit(1);
}
puts("done pool create!");
strcpy(v12, "hello world!");
func2(v10, v12);
func3(v10, v7, v6);
func4(v10);
func1(v10, v7, v6);
((void (__fastcall *)(__int64))v10[3])(*v10);
puts("done pool distroy!");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 extern char *optarg;
 int opt;
 _Bool test_p = 1;
 int roundnum = -1;
 size_t size_base = 0;
 size_t pool_size = 0;
 while(argc > 1 && (*argv[1] != '-')){
  argv++;
  argc--;
 }
 while((-1) != (opt = getopt(argc, argv, "n:s:b:r:")))
  switch(opt){
  case 's':
   pool_size = (size_t)atoi(optarg);
   break;
  case 'b':
   size_base = (size_t)atoi(optarg);
   break;
  case 'r':
   roundnum = atoi(optarg);
   break;
  default:
   printf("wrong argv!\n");
   exit(1);
  }
 if(roundnum == -1){
  printf("need round num for stress test(-r)!\n");
  test_p = 0;
 }
 if(pool_size == 0){
  printf("need pool size(-s)!\n");
  test_p = 0;
 }
 if(size_base == 0){
  printf("need base size for stress test(-b)!\n");
  test_p = 0;
 }
 if(!test_p)
  exit(1);
 printf("test pram:\n#pool size: %d\n#round num:%d\t#base size:%d\n\n",
  pool_size, roundnum, size_base);
 mempool test_pool = ((void *)0);
 test_pool = mempool_init(pool_size, 1, LINK_POOL, ((void *)0), ((void *)0), ((void *)0));
 if(!test_pool){
  printf("failed on pool create!\n");
  exit(1);
 }
 printf("done pool create!\n");
 char test_str[] = "hello world!";
 sanity_test(test_pool, test_str);
 stress_test(test_pool, roundnum, size_base);
 thread_test(test_pool);
 sim_test(test_pool, roundnum, size_base);
 test_pool->m_func.pool_free(test_pool->m_pool);
 printf("done pool distroy!\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 extern char *optarg;
 int opt;
 _Bool test_p = 1;
 int roundnum = -1;
 unsigned long size_base = 0;
 unsigned long pool_size = 0;
 while(argc > 1 && (*argv[1] != '-')){
  argv++;
  argc--;
 }
 while((-1) != (opt = getopt(argc, argv, "n:s:b:r:")))
  switch(opt){
  case 's':
   pool_size = (unsigned long)atoi(optarg);
   break;
  case 'b':
   size_base = (unsigned long)atoi(optarg);
   break;
  case 'r':
   roundnum = atoi(optarg);
   break;
  default:
   printf("wrong argv!\n");
   exit(1);
  }
 if(roundnum == -1){
  printf("need round num for stress test(-r)!\n");
  test_p = 0;
 }
 if(pool_size == 0){
  printf("need pool size(-s)!\n");
  test_p = 0;
 }
 if(size_base == 0){
  printf("need base size for stress test(-b)!\n");
  test_p = 0;
 }
 if(!test_p)
  exit(1);
 printf("test pram:\n#pool size: %d\n#round num:%d\t#base size:%d\n\n",
  pool_size, roundnum, size_base);
 struct mempool_class *test_pool = ((void *)0);
 test_pool = mempool_init(pool_size, 1, LINK_POOL, ((void *)0), ((void *)0), ((void *)0));
 if(!test_pool){
  printf("failed on pool create!\n");
  exit(1);
 }
 printf("done pool create!\n");
 char test_str[] = "hello world!";
 sanity_test(test_pool, test_str);
 stress_test(test_pool, roundnum, size_base);
 thread_test(test_pool);
 sim_test(test_pool, roundnum, size_base);
 test_pool->m_func.pool_free(test_pool->m_pool);
 printf("done pool distroy!\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
optarg
char *

variable_types: opt int

variable_types: roundnum int

return_type: int

user_defined_types: 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); }


decompiled_code:
void __fastcall chain_lock_free(void *ptr)
{
if ( pthread_spin_destroy(*(pthread_spinlock_t **)ptr) )
{
perror("pthread_spin_destroy");
exit(1);
}
munmap(*(void **)ptr, 4uLL);
shm_unlink(*((const char **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( pthread_spin_destroy(*(pthread_spinlock_t **)ptr) )
{
perror("pthread_spin_destroy");
exit(1);
}
munmap(*(void **)ptr, 4uLL);
shm_unlink(*((const char **)ptr + 1));
free(ptr);
}

original_code:
static void chain_lock_free(lock_entity lock_t)
{
 if(pthread_spin_destroy((pthread_spinlock_t *)lock_t->lock_addr)){
  perror("pthread_spin_destroy");
  exit(1);
 }
 munmap(lock_t->lock_addr, sizeof(pthread_spinlock_t));
 shm_unlink(lock_t->lock_name);
 free(lock_t);
 lock_t = ((void *)0);
}

canonical_original_code:
static void chain_lock_free(struct mem_lock_t *lock_t)
{
 if(pthread_spin_destroy((int *)lock_t->lock_addr)){
  perror("pthread_spin_destroy");
  exit(1);
 }
 munmap(lock_t->lock_addr, sizeof(pthread_spinlock_t));
 shm_unlink(lock_t->lock_name);
 free(lock_t);
 lock_t = ((void *)0);
}

variable_types: struct mem_lock_t { void *lock_addr; char *lock_name; } *


decompiled_code:
void __fastcall pool_lock_free(void *ptr)
{
if ( pthread_mutex_destroy(*(pthread_mutex_t **)ptr) )
{
perror("pthread_mutex_destroy");
exit(1);
}
munmap(*(void **)ptr, 0x28uLL);
shm_unlink(*((const char **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( pthread_mutex_destroy(*(pthread_mutex_t **)ptr) )
{
perror("pthread_mutex_destroy");
exit(1);
}
munmap(*(void **)ptr, 0x28uLL);
shm_unlink(*((const char **)ptr + 1));
free(ptr);
}

original_code:
static void pool_lock_free(lock_entity lock_t)
{
 if(pthread_mutex_destroy((pthread_mutex_t *)lock_t->lock_addr)){
  perror("pthread_mutex_destroy");
  exit(1);
 }
 munmap(lock_t->lock_addr, sizeof(pthread_mutex_t));
 shm_unlink(lock_t->lock_name);
 free(lock_t);
 lock_t = ((void *)0);
}

canonical_original_code:
static void pool_lock_free(struct mem_lock_t *lock_t)
{
 if(pthread_mutex_destroy((union pthread_mutex_t *)lock_t->lock_addr)){
  perror("pthread_mutex_destroy");
  exit(1);
 }
 munmap(lock_t->lock_addr, sizeof(pthread_mutex_t));
 shm_unlink(lock_t->lock_name);
 free(lock_t);
 lock_t = ((void *)0);
}

user_defined_types: struct mem_lock_t { void *lock_addr; char *lock_name; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
int __fastcall chain_unlock(pthread_spinlock_t **a1)
{
int result; // eax

result = pthread_spin_unlock(*a1);
if ( result )
{
perror("pthread_spin_unlock");
pthread_exit(0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(pthread_spinlock_t **a1)
{
int result; // eax

result = pthread_spin_unlock(*a1);
if ( result )
{
perror("pthread_spin_unlock");
pthread_exit(0LL);
}
return result;
}

original_code:
static void chain_unlock(lock_entity lock_t)
{
 if(pthread_spin_unlock((pthread_spinlock_t *)lock_t->lock_addr)){
  perror("pthread_spin_unlock");
  pthread_exit(((void *)0));
 }
}

canonical_original_code:
static void chain_unlock(struct mem_lock_t *lock_t)
{
 if(pthread_spin_unlock((int *)lock_t->lock_addr)){
  perror("pthread_spin_unlock");
  pthread_exit(((void *)0));
 }
}


decompiled_code:
int __fastcall pool_unlock(pthread_mutex_t **a1)
{
int result; // eax

result = pthread_mutex_unlock(*a1);
if ( result )
{
perror("pthread_mutex_unlock");
pthread_exit(0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(pthread_mutex_t **a1)
{
int result; // eax

result = pthread_mutex_unlock(*a1);
if ( result )
{
perror("pthread_mutex_unlock");
pthread_exit(0LL);
}
return result;
}

original_code:
static void pool_unlock(lock_entity lock_t)
{
 if(pthread_mutex_unlock((pthread_mutex_t *)lock_t->lock_addr)){
  perror("pthread_mutex_unlock");
  pthread_exit(((void *)0));
 }
}

canonical_original_code:
static void pool_unlock(struct mem_lock_t *lock_t)
{
 if(pthread_mutex_unlock((union pthread_mutex_t *)lock_t->lock_addr)){
  perror("pthread_mutex_unlock");
  pthread_exit(((void *)0));
 }
}


decompiled_code:
int __fastcall chain_lock(pthread_spinlock_t **a1)
{
int result; // eax

result = pthread_spin_lock(*a1);
if ( result )
{
perror("pthread_spin_lock");
pthread_exit(0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(pthread_spinlock_t **a1)
{
int result; // eax

result = pthread_spin_lock(*a1);
if ( result )
{
perror("pthread_spin_lock");
pthread_exit(0LL);
}
return result;
}

original_code:
static void chain_lock(lock_entity lock_t)
{
 if(pthread_spin_lock((pthread_spinlock_t *)lock_t->lock_addr)){
  perror("pthread_spin_lock");
  pthread_exit(((void *)0));
 }
}

canonical_original_code:
static void chain_lock(struct mem_lock_t *lock_t)
{
 if(pthread_spin_lock((int *)lock_t->lock_addr)){
  perror("pthread_spin_lock");
  pthread_exit(((void *)0));
 }
}


decompiled_code:
int __fastcall pool_lock(pthread_mutex_t **a1)
{
int result; // eax

result = pthread_mutex_lock(*a1);
if ( result )
{
perror("pthread_mutex_lock");
pthread_exit(0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(pthread_mutex_t **a1)
{
int result; // eax

result = pthread_mutex_lock(*a1);
if ( result )
{
perror("pthread_mutex_lock");
pthread_exit(0LL);
}
return result;
}

original_code:
static void pool_lock(lock_entity lock_t)
{
 if(pthread_mutex_lock((pthread_mutex_t *)lock_t->lock_addr)){
  perror("pthread_mutex_lock");
  pthread_exit(((void *)0));
 }
}

canonical_original_code:
static void pool_lock(struct mem_lock_t *lock_t)
{
 if(pthread_mutex_lock((union pthread_mutex_t *)lock_t->lock_addr)){
  perror("pthread_mutex_lock");
  pthread_exit(((void *)0));
 }
}


decompiled_code:
int __fastcall chain_lock_init(pthread_spinlock_t **a1)
{
int result; // eax

result = pthread_spin_init(*a1, 1);
if ( result )
{
perror("pthread_spin_init");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(pthread_spinlock_t **a1)
{
int result; // eax

result = pthread_spin_init(*a1, 1);
if ( result )
{
perror("pthread_spin_init");
exit(1);
}
return result;
}

original_code:
static void chain_lock_init(lock_entity lock_t)
{
 if(pthread_spin_init((pthread_spinlock_t *)lock_t->lock_addr, PTHREAD_PROCESS_SHARED)){
  perror("pthread_spin_init");
  exit(1);
 }
}

canonical_original_code:
static void chain_lock_init(struct mem_lock_t *lock_t)
{
 if(pthread_spin_init((int *)lock_t->lock_addr, PTHREAD_PROCESS_SHARED)){
  perror("pthread_spin_init");
  exit(1);
 }
}


decompiled_code:
int __fastcall pool_lock_init(pthread_mutex_t **a1)
{
int result; // eax
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-Ch] BYREF

if ( pthread_mutexattr_init(&attr) )
{
perror("pthread_mutexattr_init");
exit(1);
}
if ( pthread_mutexattr_setpshared(&attr, 1) )
{
perror("pthread_mutexattr_setpshared");
exit(1);
}
result = pthread_mutex_init(*a1, &attr);
if ( result )
{
perror("pthread_mutex_init");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(pthread_mutex_t **a1)
{
int result; // eax
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-Ch] BYREF

if ( pthread_mutexattr_init(&attr) )
{
perror("pthread_mutexattr_init");
exit(1);
}
if ( pthread_mutexattr_setpshared(&attr, 1) )
{
perror("pthread_mutexattr_setpshared");
exit(1);
}
result = pthread_mutex_init(*a1, &attr);
if ( result )
{
perror("pthread_mutex_init");
exit(1);
}
return result;
}

original_code:
static void pool_lock_init(lock_entity lock_t)
{
 pthread_mutexattr_t p_attr;
 if(pthread_mutexattr_init(&p_attr)){
  perror("pthread_mutexattr_init");
  exit(1);
 }
 if(pthread_mutexattr_setpshared(&p_attr, PTHREAD_PROCESS_SHARED)){
  perror("pthread_mutexattr_setpshared");
  exit(1);
 }
 if(pthread_mutex_init((pthread_mutex_t *)lock_t->lock_addr, &p_attr)){
  perror("pthread_mutex_init");
  exit(1);
 }
}

canonical_original_code:
static void pool_lock_init(struct mem_lock_t *lock_t)
{
 union pthread_mutexattr_t p_attr;
 if(pthread_mutexattr_init(&p_attr)){
  perror("pthread_mutexattr_init");
  exit(1);
 }
 if(pthread_mutexattr_setpshared(&p_attr, PTHREAD_PROCESS_SHARED)){
  perror("pthread_mutexattr_setpshared");
  exit(1);
 }
 if(pthread_mutex_init((union pthread_mutex_t *)lock_t->lock_addr, &p_attr)){
  perror("pthread_mutex_init");
  exit(1);
 }
}

variable_types: union pthread_mutexattr_t { char __size[4]; int __align; }


decompiled_code:
void *__fastcall lock_entity_init(__int64 a1, _QWORD *a2, unsigned int a3)
{
void *v4; // rbp
char *v5; // rax
int v6; // eax
int v7; // ebx
void *result; // rax

if ( !a1 )
{
puts("should init lock name");
exit(1);
}
if ( a3 > 2 )
{
puts("invalid parameter");
exit(1);
}
v4 = malloc(0x10uLL);
*a2 = v4;
v5 = (char *)calloc(0x80uLL, 1uLL);
*((_QWORD *)v4 + 1) = v5;
sprintf(v5, "%s.%d", (const char *)(a1 + 4), a3);
v6 = shm_open(*((const char **)v4 + 1), 194, 0x1A4u);
v7 = v6;
if ( v6 == -1 )
{
perror("shm_open");
exit(1);
}
if ( a3 )
{
if ( ftruncate(v6, 4LL) )
{
perror("ftruncate");
exit(1);
}
result = mmap(0LL, 4uLL, 3, 1, v7, 0LL);
*(_QWORD *)v4 = result;
if ( !result )
{
perror("mmap");
exit(1);
}
}
else
{
if ( ftruncate(v6, 40LL) )
{
perror("ftruncate");
exit(1);
}
result = mmap(0LL, 0x28uLL, 3, 1, v7, 0LL);
*(_QWORD *)v4 = result;
if ( !result )
{
perror("mmap");
exit(1);
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, _QWORD *a2, unsigned int a3)
{
void *v4; // rbp
char *v5; // rax
int v6; // eax
int v7; // ebx
void *result; // rax

if ( !a1 )
{
puts("should init lock name");
exit(1);
}
if ( a3 > 2 )
{
puts("invalid parameter");
exit(1);
}
v4 = malloc(0x10uLL);
*a2 = v4;
v5 = (char *)calloc(0x80uLL, 1uLL);
*((_QWORD *)v4 + 1) = v5;
sprintf(v5, "%s.%d", (const char *)(a1 + 4), a3);
v6 = shm_open(*((const char **)v4 + 1), 194, 0x1A4u);
v7 = v6;
if ( v6 == -1 )
{
perror("shm_open");
exit(1);
}
if ( a3 )
{
if ( ftruncate(v6, 4LL) )
{
perror("ftruncate");
exit(1);
}
result = mmap(0LL, 4uLL, 3, 1, v7, 0LL);
*(_QWORD *)v4 = result;
if ( !result )
{
perror("mmap");
exit(1);
}
}
else
{
if ( ftruncate(v6, 40LL) )
{
perror("ftruncate");
exit(1);
}
result = mmap(0LL, 0x28uLL, 3, 1, v7, 0LL);
*(_QWORD *)v4 = result;
if ( !result )
{
perror("mmap");
exit(1);
}
}
return result;
}

original_code:
static void lock_entity_init(char *lock_name, void **lock_t, int nnum)
{
 if(lock_name == ((void *)0)){
  printf("should init lock name\n");
  exit(1);
 }
 if(nnum < 0 || nnum >= 3){
  printf("invalid parameter\n");
  exit(1);
 }
 *lock_t = (lock_entity)malloc(sizeof(struct mem_lock_t));
 lock_entity p = *lock_t;
 p->lock_name = (char *)calloc(128, sizeof(char));
 sprintf(p->lock_name, "%s.%d", lock_name+4, nnum);
 int lock_fd;
 lock_fd = shm_open(p->lock_name, 0100|02|0200, 0644);
 if(lock_fd == -1){
  perror("shm_open");
  exit(1);
 }
 switch(nnum){
 case 0:
  if(ftruncate(lock_fd, sizeof(pthread_mutex_t))){
   perror("ftruncate");
   exit(1);
  }
  p->lock_addr = mmap(((void *)0), sizeof(pthread_mutex_t), 0x1|0x2,
        0x01, lock_fd, 0);
  if(p->lock_addr == ((void *)0)){
   perror("mmap");
   exit(1);
  }
  break;
 case 1:
 case 2:
  if(ftruncate(lock_fd, sizeof(pthread_spinlock_t))){
   perror("ftruncate");
   exit(1);
  }
  p->lock_addr = mmap(((void *)0), sizeof(pthread_spinlock_t), 0x1|0x2,
        0x01, lock_fd, 0);
  if(p->lock_addr == ((void *)0)){
   perror("mmap");
   exit(1);
  }
  break;
 default:
  break;
 }
}

canonical_original_code:
static void lock_entity_init(char *lock_name, void **lock_t, int nnum)
{
 if(lock_name == ((void *)0)){
  printf("should init lock name\n");
  exit(1);
 }
 if(nnum < 0 || nnum >= 3){
  printf("invalid parameter\n");
  exit(1);
 }
 *lock_t = (struct mem_lock_t *)malloc(sizeof(struct mem_lock_t));
 struct mem_lock_t *p = *lock_t;
 p->lock_name = (char *)calloc(128, sizeof(char));
 sprintf(p->lock_name, "%s.%d", lock_name+4, nnum);
 int lock_fd;
 lock_fd = shm_open(p->lock_name, 0100|02|0200, 0644);
 if(lock_fd == -1){
  perror("shm_open");
  exit(1);
 }
 switch(nnum){
 case 0:
  if(ftruncate(lock_fd, sizeof(pthread_mutex_t))){
   perror("ftruncate");
   exit(1);
  }
  p->lock_addr = mmap(((void *)0), sizeof(pthread_mutex_t), 0x1|0x2,
        0x01, lock_fd, 0);
  if(p->lock_addr == ((void *)0)){
   perror("mmap");
   exit(1);
  }
  break;
 case 1:
 case 2:
  if(ftruncate(lock_fd, sizeof(pthread_spinlock_t))){
   perror("ftruncate");
   exit(1);
  }
  p->lock_addr = mmap(((void *)0), sizeof(pthread_spinlock_t), 0x1|0x2,
        0x01, lock_fd, 0);
  if(p->lock_addr == ((void *)0)){
   perror("mmap");
   exit(1);
  }
  break;
 default:
  break;
 }
}

variable_types: nnum int


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


wordsncmp

repo: scvalex/markov

decompiled_code:
__int64 __fastcall wordsncmp(char *a1, char *a2)
{
char v3; // dl
char v4; // cl
__int64 v5; // rax
unsigned int v6; // esi

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

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char *a2)
{
char v3; // dl
char v4; // cl
__int64 v5; // rax
unsigned int v6; // esi

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

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, *(char **)a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(const void *a1, const void *a2)
{
return func7(*(char **)a1, *(char **)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 *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_QWORD *v4; // r13
size_t i; // rbx
int v6; // er15
const char *v7; // rbp
int v8; // er12
const char **v9; // rbp
const char *j; // rbx
char **v11; // rbx
const char *v12; // rsi
const char *v13; // rsi
char *v14; // r12
int v15; // ebp
int v16; // ebx
int v17; // er14
__int64 v18; // rbx
int v19; // ebp
int v21; // eax
const char *v22; // rax
int v23; // ebx
int v25; // [rsp+4h] [rbp-44h]
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");
*v4 = ptr;
for ( i = 0LL; ; v4[i] = &v7[strlen(v7) + 1] )
{
v6 = i;
if ( (unsigned int)__isoc99_scanf() == -1 )
break;
if ( i == 1048573 )
__assert_fail("nwords < words_count - ngram_n", "markov.c", 0x34u, "main");
v7 = (const char *)v4[i++];
if ( v7 >= ptr + 4194284 )
__assert_fail("words[nwords] < text + text_size - 20", "markov.c", 0x35u, "main");
}
qsort(v4, i, 8uLL, (__compar_fn_t)sortcmp);
do
{
v8 = rand() % v6;
v9 = (const char **)&v4[v8];
for ( j = *v9; *v9; j = *v9 )
{
if ( j[strlen(j) - 1] == 46 )
break;
++v8;
++v9;
}
}
while ( v8 == -1 );
v11 = (char **)&v4[v8];
v12 = skip_words(*v11, 1);
if ( v12 )
{
printf("%s ", v12);
v13 = skip_words(*v11, 2);
if ( v13 )
printf("%s ", v13);
}
v14 = *v11;
v25 = 300;
do
{
v23 = 1;
do
{
v15 = v23;
v23 *= 2;
}
while ( v23 < v6 && (int)wordsncmp((char *)v4[v23], v14) < 0 );
if ( v15 <= 0 )
{
v16 = 0;
}
else
{
v16 = 0;
do
{
if ( v15 + v16 < v6 && (int)wordsncmp((char *)v4[v15 + v16], v14) < 0 )
v16 += v15;
v15 >>= 1;
}
while ( v15 > 0 );
}
v17 = v16 + 1;
v18 = v16 + 2;
do
v19 = v18;
while ( !(unsigned int)wordsncmp(v14, (char *)v4[v18++]) );
v21 = rand();
v14 = skip_words((_BYTE *)v4[v17 + v21 % (v19 - v17)], 1);
v22 = skip_words(v14, 2);
if ( *v22 )
printf("%s ", v22);
--v25;
}
while ( v25 );
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; // r13
size_t i; // rbx
int v6; // er15
const char *v7; // rbp
int v8; // er12
const char **v9; // rbp
const char *j; // rbx
char **v11; // rbx
const char *v12; // rsi
const char *v13; // rsi
char *v14; // r12
int v15; // ebp
int v16; // ebx
int v17; // er14
__int64 v18; // rbx
int v19; // ebp
int v21; // eax
const char *v22; // rax
int v23; // ebx
int v25; // [rsp+4h] [rbp-44h]
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");
*v4 = ptr;
for ( i = 0LL; ; v4[i] = &v7[strlen(v7) + 1] )
{
v6 = i;
if ( (unsigned int)__isoc99_scanf() == -1 )
break;
if ( i == 1048573 )
__assert_fail("nwords < words_count - ngram_n", "markov.c", 0x34u, "main");
v7 = (const char *)v4[i++];
if ( v7 >= ptr + 4194284 )
__assert_fail("words[nwords] < text + text_size - 20", "markov.c", 0x35u, "main");
}
qsort(v4, i, 8uLL, (__compar_fn_t)sortcmp);
do
{
v8 = rand() % v6;
v9 = (const char **)&v4[v8];
for ( j = *v9; *v9; j = *v9 )
{
if ( j[strlen(j) - 1] == 46 )
break;
++v8;
++v9;
}
}
while ( v8 == -1 );
v11 = (char **)&v4[v8];
v12 = skip_words(*v11, 1);
if ( v12 )
{
printf("%s ", v12);
v13 = skip_words(*v11, 2);
if ( v13 )
printf("%s ", v13);
}
v14 = *v11;
v25 = 300;
do
{
v23 = 1;
do
{
v15 = v23;
v23 *= 2;
}
while ( v23 < v6 && (int)func7((char *)v4[v23], v14) < 0 );
if ( v15 <= 0 )
{
v16 = 0;
}
else
{
v16 = 0;
do
{
if ( v15 + v16 < v6 && (int)func7((char *)v4[v15 + v16], v14) < 0 )
v16 += v15;
v15 >>= 1;
}
while ( v15 > 0 );
}
v17 = v16 + 1;
v18 = v16 + 2;
do
v19 = v18;
while ( !(unsigned int)func7(v14, (char *)v4[v18++]) );
v21 = rand();
v14 = skip_words((_BYTE *)v4[v17 + v21 % (v19 - v17)], 1);
v22 = skip_words(v14, 2);
if ( *v22 )
printf("%s ", v22);
--v25;
}
while ( v25 );
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:
text
char *

variable_types:
words
char **

variable_types: nwords int

variable_types: aux int

variable_types:
phrase
char *

variable_types: wordsleft int

variable_types: lower int

variable_types: start int

variable_types: end int


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 *


repo: sdbakker/sio-platform

decompiled_code:
__int64 __fastcall sios_param_set_servicetext(char *src, __int64 a2)
{
char *v2; // rbp
size_t i; // rbx
__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);
strncpy(v2, src, 0x100uLL);
for ( i = 0LL; strlen(v2) > i; ++i )
{
if ( v2[i] == 44 )
v2[i] = 1;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, __int64 a2)
{
char *v2; // rbp
size_t i; // rbx
__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);
strncpy(v2, src, 0x100uLL);
for ( i = 0LL; strlen(v2) > i; ++i )
{
if ( v2[i] == 44 )
v2[i] = 1;
}
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: i int

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

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 func6()
{
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
int v1; // ebp
unsigned int v2; // ebx

v0 = sios_object_register(_this_object, _this_class[0]);
if ( v0 )
{
v2 = v0;
fprintf(stderr, "Error: [%s] failed registering comm object\n", _this_object);
}
else
{
v1 = sios_dnssd_init();
if ( v1 )
{
fprintf(stderr, "Error: [%s] failed initializing mDNS\n", _this_object);
sios_object_deregister(_this_object);
v2 = v1;
}
else
{
v2 = sios_dnssd_register_service(&dnstxt, name, type, domain, port);
if ( v2 )
{
fprintf(stderr, "Error: [%s] failed registering service\n", _this_object);
sios_object_deregister(_this_object);
sios_dnssd_close();
mDNS_Close(&mDNSStorage);
v2 = v1;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 func17()
{
unsigned int v0; // eax
int v1; // ebp
unsigned int v2; // ebx

v0 = sios_object_register(_this_object, _this_class[0]);
if ( v0 )
{
v2 = v0;
fprintf(stderr, "Error: [%s] failed registering comm object\n", _this_object);
}
else
{
v1 = func1();
if ( v1 )
{
fprintf(stderr, "Error: [%s] failed initializing mDNS\n", _this_object);
sios_object_deregister(_this_object);
v2 = v1;
}
else
{
v2 = func5(&dnstxt, name, type, domain, port);
if ( v2 )
{
fprintf(stderr, "Error: [%s] failed registering service\n", _this_object);
sios_object_deregister(_this_object);
func7();
mDNS_Close(&mDNSStorage);
v2 = v1;
}
}
}
return v2;
}

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();
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 func2()
{
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
int v5; // ebx
int v6; // ebx
int longind; // [rsp+Ch] [rbp-9Ch] BYREF
char dest[24]; // [rsp+10h] [rbp-98h] BYREF
__int64 v10; // [rsp+28h] [rbp-80h]
__int64 v11; // [rsp+30h] [rbp-78h]
__int64 v12; // [rsp+38h] [rbp-70h]
__int64 v13; // [rsp+40h] [rbp-68h]
__int64 v14; // [rsp+48h] [rbp-60h]
__int64 v15; // [rsp+50h] [rbp-58h]
__int64 v16; // [rsp+58h] [rbp-50h]
__int64 v17; // [rsp+60h] [rbp-48h]
__int64 v18; // [rsp+68h] [rbp-40h]
__int64 v19; // [rsp+70h] [rbp-38h]
__int64 v20; // [rsp+78h] [rbp-30h]
__int64 v21; // [rsp+80h] [rbp-28h]
__int64 v22; // [rsp+88h] [rbp-20h]

strcpy(dest, "/etc/sios.config");
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
signal(2, handle_sigint);
signal(3, handle_sigint);
v3 = 0;
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 == 63 )
LABEL_12:
usage(*argv);
if ( v4 == 86 )
{
puts("2.1.0");
exit(0);
}
}
else
{
if ( v4 == 104 )
goto LABEL_12;
if ( v4 == 112 )
v3 = atoi(optarg);
}
}
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);
if ( v3 > 0 )
*(_DWORD *)(config + 8LL) = v3;
v5 = sios_osc_init(config);
if ( v5 )
{
if ( use_syslog )
syslog(0, "FATALITY: [%s] Initializing OSC failed", "Main");
else
fprintf(stderr, "FATALITY: [%s] Initializing OSC failed\n", "Main");
exit(v5);
}
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");
exit(v6);
}
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
int v5; // ebx
int v6; // ebx
int longind; // [rsp+Ch] [rbp-9Ch] BYREF
char dest[24]; // [rsp+10h] [rbp-98h] BYREF
__int64 v10; // [rsp+28h] [rbp-80h]
__int64 v11; // [rsp+30h] [rbp-78h]
__int64 v12; // [rsp+38h] [rbp-70h]
__int64 v13; // [rsp+40h] [rbp-68h]
__int64 v14; // [rsp+48h] [rbp-60h]
__int64 v15; // [rsp+50h] [rbp-58h]
__int64 v16; // [rsp+58h] [rbp-50h]
__int64 v17; // [rsp+60h] [rbp-48h]
__int64 v18; // [rsp+68h] [rbp-40h]
__int64 v19; // [rsp+70h] [rbp-38h]
__int64 v20; // [rsp+78h] [rbp-30h]
__int64 v21; // [rsp+80h] [rbp-28h]
__int64 v22; // [rsp+88h] [rbp-20h]

strcpy(dest, "/etc/sios.config");
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
signal(2, handle_sigint);
signal(3, handle_sigint);
v3 = 0;
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 == 63 )
LABEL_12:
func1(*argv);
if ( v4 == 86 )
{
puts("2.1.0");
exit(0);
}
}
else
{
if ( v4 == 104 )
goto LABEL_12;
if ( v4 == 112 )
v3 = atoi(optarg);
}
}
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);
if ( v3 > 0 )
*(_DWORD *)(config + 8LL) = v3;
v5 = sios_osc_init(config);
if ( v5 )
{
if ( use_syslog )
syslog(0, "FATALITY: [%s] Initializing OSC failed", "Main");
else
fprintf(stderr, "FATALITY: [%s] Initializing OSC failed\n", "Main");
exit(v5);
}
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");
exit(v6);
}
if ( *(_BYTE *)(config + 17LL) )
sios_dump_xml();
while ( !halt )
sleep(1u);
func2();
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)
{
_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 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; } *

variable_types:
val
char *

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:
__int64 __fastcall sios_param_add_param(__int64 a1, __int64 a2)
{
if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
list_add((_QWORD *)(a2 + 16), (__int64 *)(a1 + 16));
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
func2((_QWORD *)(a2 + 16), (__int64 *)(a1 + 16));
return a1;
}

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 )
return 0xFFFFFFFFLL;
if ( v2 != (unsigned __int8)v2 )
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 )
return 0xFFFFFFFFLL;
if ( v2 != (unsigned __int8)v2 )
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: 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 )
return 0xFFFFFFFFLL;
if ( (__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 )
return 0xFFFFFFFFLL;
if ( (__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 )
return 0xFFFFFFFFLL;
if ( v2 != (unsigned __int16)v2 )
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 )
return 0xFFFFFFFFLL;
if ( v2 != (unsigned __int16)v2 )
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 )
return 0xFFFFFFFFLL;
if ( (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 )
return 0xFFFFFFFFLL;
if ( (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 )
return 0xFFFFFFFFLL;
if ( 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 )
return 0xFFFFFFFFLL;
if ( 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_3;
default:
result = 0xFFFFFFFFLL;
break;
}
}
else
{
LABEL_3:
**(_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_3;
default:
result = 0xFFFFFFFFLL;
break;
}
}
else
{
LABEL_3:
**(_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 a2)
{
__int64 result; // rax
__int64 v3[3]; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+1Ch] [rbp-Ch] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = (__int64)&v4;
result = sios_param_set_bool(a1, (__int64)v3);
if ( !(_DWORD)result )
**(_DWORD **)(a2 + 16) = v4 == 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(_BYTE *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3[3]; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+1Ch] [rbp-Ch] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = (__int64)&v4;
result = func18(a1, (__int64)v3);
if ( !(_DWORD)result )
**(_DWORD **)(a2 + 16) = v4 == 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(char *src, __int64 a2)
{
char **v2; // r12
__int64 result; // rax

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

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

v2 = *(char ***)(a2 + 16);
if ( strlen(src) + 1 > *(int *)v2 )
{
printf("%s: string doesn't fit in %u chars.\n", *(const char **)a2, (unsigned int)(*(_DWORD *)v2 - 1));
result = 0xFFFFFFFFLL;
}
else
{
strcpy(v2[1], src);
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;
while ( strcasecmp(s1, v1) )
{
v2 += 2;
v1 = *v2;
if ( !*v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v2 + 2);
}

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;
while ( strcasecmp(s1, v1) )
{
v2 += 2;
v1 = *v2;
if ( !*v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v2 + 2);
}

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)
{
_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 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:
__int64 __fastcall sios_class_register(char *s2)
{
__int64 result; // rax

if ( !s2 )
return 0xFFFFFFFFLL;
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);
result = 0xFFFFFFFFLL;
}
else
{
snprintf(s2 + 64, 0x80uLL, "%s/%s", (const char *)*config, s2);
list_add((_QWORD *)s2 + 26, (__int64 *)&class_list);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s2)
{
__int64 result; // rax

if ( !s2 )
return 0xFFFFFFFFLL;
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);
result = 0xFFFFFFFFLL;
}
else
{
snprintf(s2 + 64, 0x80uLL, "%s/%s", (const char *)*config, s2);
func2((_QWORD *)s2 + 26, (__int64 *)&class_list);
result = 0LL;
}
return result;
}

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)
{
if ( a1 )
{
if ( list_empty((_QWORD *)(a1 + 192)) )
list_del(a1 + 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);
}


decompiled_code:
__int64 __fastcall sios_class_add_object(__int64 a1, __int64 a2)
{
if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 216) = a2;
list_add((_QWORD *)(a1 + 224), (__int64 *)(a2 + 192));
return 0LL;
}

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 || !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));
v2 = sios_class_add_object(a1, a2);
if ( v2 )
return (unsigned int)-1;
snprintf((char *)(a1 + 64), 0x80uLL, "%s/%s", (const char *)(a2 + 64), (const char *)a1);
list_add((_QWORD *)(a1 + 240), (__int64 *)&object_list);
return v2;
}

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

if ( !a1 || !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));
v2 = sios_class_add_object(a1, a2);
if ( v2 )
return (unsigned int)-1;
snprintf((char *)(a1 + 64), 0x80uLL, "%s/%s", (const char *)(a2 + 64), (const char *)a1);
func2((_QWORD *)(a1 + 240), (__int64 *)&object_list);
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();
func4(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();
 }
}