main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
pthread_t *v4; // rbp
unsigned int v5; // eax
__int64 v6; // rbx
unsigned int v7; // eax
__int64 v8; // rsi
void *thread_return[4]; // [rsp+Ch] [rbp-7Ch] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-58h] BYREF

v3 = 0;
printf("\n\t\t---------------------------------------------------------------------------");
v4 = (pthread_t *)((char *)thread_return + 4);
printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
printf("\n\t\t Email : RarchK");
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Objective : To illustrate thread join operation\n ");
puts("\n\t\t..........................................................................");
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 0);
while ( 1 )
{
printf("Creating thread %d\n", v3);
v5 = pthread_create(v4, &attr, BusyWork, 0LL);
if ( v5 )
break;
++v3;
++v4;
if ( v3 == 4 )
{
v6 = 0LL;
v7 = pthread_attr_destroy(&attr);
if ( !v7 )
{
do
{
pthread_join(*(pthread_t *)((char *)&thread_return[v6] + 4), thread_return);
v8 = (unsigned int)v6++;
printf("Completed join with thread %d status= %d\n", v8, LODWORD(thread_return[0]));
}
while ( v6 != 4 );
pthread_exit(0LL);
}
printf("ERROR; return code from pthread_attr_destroy() is %d\n", v7);
exit(-1);
}
}
printf("ERROR; return code from pthread_create() is %d\n", v5);
exit(-1);
}

original_code:
int main (int argc, char *argv[])
{
   pthread_t thread[4];
   pthread_attr_t attr;
   int ret_count, t, status;
  printf("\n\t\t---------------------------------------------------------------------------");
  printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
  printf("\n\t\t Email : RarchK");
  printf("\n\t\t---------------------------------------------------------------------------");
  printf("\n\t\t Objective : To illustrate thread join operation\n ");
  printf("\n\t\t..........................................................................\n");
   pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
   for(t=0; t<4; t++)
   {
      printf("Creating thread %d\n", t);
      ret_count = pthread_create(&thread[t], &attr, BusyWork, ((void *)0));
      if (ret_count)
      {
         printf("ERROR; return code from pthread_create() is %d\n", ret_count);
         exit(-1);
      }
   }
   ret_count=pthread_attr_destroy(&attr);
   if (ret_count)
   {
    printf("ERROR; return code from pthread_attr_destroy() is %d\n", ret_count);
        exit(-1);
   }
   for(t=0; t<4; t++)
   {
      pthread_join(thread[t], (void **)&status);
      printf("Completed join with thread %d status= %d\n",t, status);
   }
   pthread_exit(((void *)0));
}

canonical_original_code:
int main(int argc, char *argv[])
{
   unsigned long thread[4];
   union pthread_attr_t attr;
   int ret_count; int t; int status;
  printf("\n\t\t---------------------------------------------------------------------------");
  printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
  printf("\n\t\t Email : RarchK");
  printf("\n\t\t---------------------------------------------------------------------------");
  printf("\n\t\t Objective : To illustrate thread join operation\n ");
  printf("\n\t\t..........................................................................\n");
   pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
   for(t=0; t<4; t++)
   {
      printf("Creating thread %d\n", t);
      ret_count = pthread_create(&thread[t], &attr, BusyWork, ((void *)0));
      if (ret_count)
      {
         printf("ERROR; return code from pthread_create() is %d\n", ret_count);
         exit(-1);
      }
   }
   ret_count=pthread_attr_destroy(&attr);
   if (ret_count)
   {
    printf("ERROR; return code from pthread_attr_destroy() is %d\n", ret_count);
        exit(-1);
   }
   for(t=0; t<4; t++)
   {
      pthread_join(thread[t], (void **)&status);
      printf("Completed join with thread %d status= %d\n",t, status);
   }
   pthread_exit(((void *)0));
}

variable_types:
thread
unsigned long [4]

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: t int

variable_types: status int


dotprod

repo: HPC-Sect/ZeroSample

decompiled_code:
void __fastcall __noreturn dotprod(void *a1)
{
int v1; // eax
double v2; // xmm1_8
double v3; // xmm0_8

LODWORD(a1) = dword_404138 * (_DWORD)a1;
v1 = (_DWORD)a1 + dword_404138;
if ( (int)a1 >= (int)a1 + dword_404138 )
{
v2 = 0.0;
}
else
{
a1 = (void *)(int)a1;
v2 = 0.0;
do
{
v3 = *(double *)(dotstr + 8LL * (_QWORD)a1) * *(double *)(qword_404128 + 8LL * (_QWORD)a1);
a1 = (char *)a1 + 1;
v2 = v2 + v3;
}
while ( v1 > (int)a1 );
}
pthread_mutex_lock(&mutexsum);
*(double *)&qword_404130 = v2 + *(double *)&qword_404130;
pthread_mutex_unlock(&mutexsum);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // eax
double v2; // xmm1_8
double v3; // xmm0_8

LODWORD(a1) = dword_404138 * (_DWORD)a1;
v1 = (_DWORD)a1 + dword_404138;
if ( (int)a1 >= (int)a1 + dword_404138 )
{
v2 = 0.0;
}
else
{
a1 = (void *)(int)a1;
v2 = 0.0;
do
{
v3 = *(double *)(dotstr + 8LL * (_QWORD)a1) * *(double *)(qword_404128 + 8LL * (_QWORD)a1);
a1 = (char *)a1 + 1;
v2 = v2 + v3;
}
while ( v1 > (int)a1 );
}
pthread_mutex_lock(&mutexsum);
*(double *)&qword_404130 = v2 + *(double *)&qword_404130;
pthread_mutex_unlock(&mutexsum);
pthread_exit(0LL);
}

original_code:
void *dotprod(void *arg)
{
   int i, start, end, offset, len ;
   double mysum, *x, *y;
   offset = (int)arg;
   len = dotstr.veclen;
   start = offset*len;
   end = start + len;
   x = dotstr.a;
   y = dotstr.b;
   mysum = 0;
   for (i=start; i<end ; i++)
    {
      mysum += (x[i] * y[i]);
    }
   pthread_mutex_lock (&mutexsum);
   dotstr.sum += mysum;
   pthread_mutex_unlock (&mutexsum);
   pthread_exit((void*) 0);
}

canonical_original_code:
void *dotprod(void *arg)
{
   int i; int start; int end; int offset; int len;
   double mysum; double *x; double *y;
   offset = (int)arg;
   len = dotstr.veclen;
   start = offset*len;
   end = start + len;
   x = dotstr.a;
   y = dotstr.b;
   mysum = 0;
   for (i=start; i<end ; i++)
    {
      mysum += (x[i] * y[i]);
    }
   pthread_mutex_lock (&mutexsum);
   dotstr.sum += mysum;
   pthread_mutex_unlock (&mutexsum);
   pthread_exit((void *) 0);
}

variable_types:
arg
void *

variable_types: i int

variable_types: start int

variable_types: end int

variable_types: offset int

variable_types: len int

variable_types: mysum double

variable_types:
x
double *

variable_types:
y
double *

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rbp
__int64 i; // rax
unsigned int v6; // eax
unsigned int v7; // eax
pthread_t *v8; // r13
char *v9; // rbx
unsigned int v10; // eax
__int64 v11; // rbx
unsigned int v12; // eax
pthread_t v13; // rdi
unsigned int v14; // eax
void *thread_return[13]; // [rsp+Ch] [rbp-6Ch] BYREF

printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
printf("\n\t\t Email : RarchK");
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Objective : To perform dot product of vector using Mutex.\n ");
puts("\n\t\t..........................................................................");
v3 = (char *)malloc(0xC80uLL);
v4 = (char *)malloc(0xC80uLL);
for ( i = 0LL; i != 3200; i += 8LL )
{
*(_QWORD *)&v3[i] = 0x3FF0000000000000LL;
*(_QWORD *)&v4[i] = 0x3FF0000000000000LL;
}
dword_404138 = 100;
dotstr = (__int64)v3;
qword_404128 = (__int64)v4;
qword_404130 = 0LL;
v6 = pthread_mutex_init(&mutexsum, 0LL);
if ( v6 )
{
printf("ERROR; return code from pthread_mutex_init() is %d\n", v6);
exit(-1);
}
v7 = pthread_attr_init((pthread_attr_t *)((char *)thread_return + 4));
if ( !v7 )
{
v8 = &callThd;
v9 = 0LL;
pthread_attr_setdetachstate((pthread_attr_t *)((char *)thread_return + 4), 0);
while ( 1 )
{
v10 = pthread_create(v8, (const pthread_attr_t *)((char *)thread_return + 4), dotprod, v9);
if ( v10 )
break;
++v9;
++v8;
if ( v9 == (char *)4 )
{
v11 = 0LL;
v12 = pthread_attr_destroy((pthread_attr_t *)((char *)thread_return + 4));
if ( !v12 )
{
do
{
v13 = *(&callThd + v11++);
pthread_join(v13, thread_return);
}
while ( v11 != 4 );
printf("Sum = %f \n", *(double *)&qword_404130);
free(v3);
free(v4);
v14 = pthread_mutex_destroy(&mutexsum);
if ( v14 )
{
printf("ERROR; return code from pthread_mutex_destroy() is %d\n", v14);
exit(-1);
}
pthread_exit(0LL);
}
printf("\n ERROR : return code from pthread_attr_destroy() is %d\n", v12);
exit(-1);
}
}
printf("ERROR; return code from pthread_create() is %d\n", v10);
exit(-1);
}
printf("ERROR; return code from pthread_attr_init() is %d\n", v7);
exit(-1);
}

original_code:
int main (int argc, char *argv[])
{
   int i;
   double *a, *b;
   int status;
   pthread_attr_t attr;
   int ret_count;
  printf("\n\t\t---------------------------------------------------------------------------");
  printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
  printf("\n\t\t Email : RarchK");
  printf("\n\t\t---------------------------------------------------------------------------");
  printf("\n\t\t Objective : To perform dot product of vector using Mutex.\n ");
  printf("\n\t\t..........................................................................\n");
   a = (double*) malloc (4*100*sizeof(double));
   b = (double*) malloc (4*100*sizeof(double));
   for (i=0; i<100*4; i++)
    {
     a[i]=1.0;
     b[i]=a[i];
    }
   dotstr.veclen = 100;
   dotstr.a = a;
   dotstr.b = b;
   dotstr.sum=0;
   ret_count=pthread_mutex_init(&mutexsum, ((void *)0));
   if (ret_count)
   {
         printf("ERROR; return code from pthread_mutex_init() is %d\n", ret_count);
         exit(-1);
   }
   ret_count=pthread_attr_init(&attr);
   if (ret_count)
   {
       printf("ERROR; return code from pthread_attr_init() is %d\n", ret_count);
       exit(-1);
   }
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 for(i=0; i<4; i++)
        {
     ret_count=pthread_create( &callThd[i], &attr, dotprod, (void *)i);
           if (ret_count)
           {
          printf("ERROR; return code from pthread_create() is %d\n", ret_count);
          exit(-1);
           }
 }
  ret_count=pthread_attr_destroy(&attr);
        if(ret_count)
 {
  printf("\n ERROR : return code from pthread_attr_destroy() is %d\n",ret_count);
  exit(-1);
 }
 for(i=0; i<4; i++)
  pthread_join( callThd[i], (void **)&status);
   printf ("Sum =  %f \n", dotstr.sum);
   free (a);
   free (b);
   ret_count=pthread_mutex_destroy(&mutexsum);
   if (ret_count)
   {
         printf("ERROR; return code from pthread_mutex_destroy() is %d\n", ret_count);
         exit(-1);
   }
   pthread_exit(((void *)0));
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int i;
   double *a; double *b;
   int status;
   union pthread_attr_t attr;
   int ret_count;
  printf("\n\t\t---------------------------------------------------------------------------");
  printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
  printf("\n\t\t Email : RarchK");
  printf("\n\t\t---------------------------------------------------------------------------");
  printf("\n\t\t Objective : To perform dot product of vector using Mutex.\n ");
  printf("\n\t\t..........................................................................\n");
   a = (double *) malloc (4*100*sizeof(double));
   b = (double *) malloc (4*100*sizeof(double));
   for (i=0; i<100*4; i++)
    {
     a[i]=1.0;
     b[i]=a[i];
    }
   dotstr.veclen = 100;
   dotstr.a = a;
   dotstr.b = b;
   dotstr.sum=0;
   ret_count=pthread_mutex_init(&mutexsum, ((void *)0));
   if (ret_count)
   {
         printf("ERROR; return code from pthread_mutex_init() is %d\n", ret_count);
         exit(-1);
   }
   ret_count=pthread_attr_init(&attr);
   if (ret_count)
   {
       printf("ERROR; return code from pthread_attr_init() is %d\n", ret_count);
       exit(-1);
   }
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 for(i=0; i<4; i++)
        {
     ret_count=pthread_create( &callThd[i], &attr, dotprod, (void *)i);
           if (ret_count)
           {
          printf("ERROR; return code from pthread_create() is %d\n", ret_count);
          exit(-1);
           }
 }
  ret_count=pthread_attr_destroy(&attr);
        if(ret_count)
 {
  printf("\n ERROR : return code from pthread_attr_destroy() is %d\n",ret_count);
  exit(-1);
 }
 for(i=0; i<4; i++)
  pthread_join( callThd[i], (void **)&status);
   printf ("Sum =  %f \n", dotstr.sum);
   free (a);
   free (b);
   ret_count=pthread_mutex_destroy(&mutexsum);
   if (ret_count)
   {
         printf("ERROR; return code from pthread_mutex_destroy() is %d\n", ret_count);
         exit(-1);
   }
   pthread_exit(((void *)0));
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
a
double *

variable_types:
b
double *

return_type: int

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
void __fastcall __noreturn inc_count(void *a1)
{
int v1; // ebp
__int64 v2; // rdx
int v3; // ebx

v1 = 10;
while ( 1 )
{
pthread_mutex_lock(&count_mutex);
v2 = (unsigned int)(count + 1);
count = v2;
if ( (_DWORD)v2 == 12 )
{
pthread_cond_signal(&count_threshold_cv);
printf("inc_count(): thread %d, count = %d Threshold reached.\n", *(unsigned int *)a1, (unsigned int)count);
v2 = (unsigned int)count;
}
v3 = 1000;
printf("inc_count(): thread %d, count = %d, unlocking mutex\n", *(unsigned int *)a1, v2);
pthread_mutex_unlock(&count_mutex);
do
{
random();
--v3;
}
while ( v3 );
if ( !--v1 )
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebp
__int64 v2; // rdx
int v3; // ebx

v1 = 10;
while ( 1 )
{
pthread_mutex_lock(&count_mutex);
v2 = (unsigned int)(count + 1);
count = v2;
if ( (_DWORD)v2 == 12 )
{
pthread_cond_signal(&count_threshold_cv);
printf("inc_count(): thread %d, count = %d Threshold reached.\n", *(unsigned int *)a1, (unsigned int)count);
v2 = (unsigned int)count;
}
v3 = 1000;
printf("inc_count(): thread %d, count = %d, unlocking mutex\n", *(unsigned int *)a1, v2);
pthread_mutex_unlock(&count_mutex);
do
{
random();
--v3;
}
while ( v3 );
if ( !--v1 )
pthread_exit(0LL);
}
}

original_code:
void *inc_count(void *idp)
{
  int j,i;
  double result=0.0;
  int *my_id = idp;
  for (i=0; i<10; i++) {
    pthread_mutex_lock(&count_mutex);
    count++;
    if (count == 12) {
      pthread_cond_signal(&count_threshold_cv);
      printf("inc_count(): thread %d, count = %d  Threshold reached.\n",
             *my_id, count);
      }
    printf("inc_count(): thread %d, count = %d, unlocking mutex\n",
    *my_id, count);
    pthread_mutex_unlock(&count_mutex);
    for (j=0; j<1000; j++)
      result = result + (double)random();
    }
  pthread_exit(((void *)0));
}

canonical_original_code:
void *inc_count(void *idp)
{
  int j; int i;
  double result = 0.0;
  int *my_id = idp;
  for (i=0; i<10; i++) {
    pthread_mutex_lock(&count_mutex);
    count++;
    if (count == 12) {
      pthread_cond_signal(&count_threshold_cv);
      printf("inc_count(): thread %d, count = %d  Threshold reached.\n",
             *my_id, count);
      }
    printf("inc_count(): thread %d, count = %d, unlocking mutex\n",
    *my_id, count);
    pthread_mutex_unlock(&count_mutex);
    for (j=0; j<1000; j++)
      result = result + (double)random();
    }
  pthread_exit(((void *)0));
}

variable_types:
idp
void *

variable_types: j int

variable_types: result double


decompiled_code:
void __fastcall __noreturn watch_count(void *a1)
{
printf("Starting watch_count(): thread %d\n", *(unsigned int *)a1);
pthread_mutex_lock(&count_mutex);
if ( count <= 11 )
{
pthread_cond_wait(&count_threshold_cv, &count_mutex);
printf("watch_count(): thread %d Condition signal received.\n", *(unsigned int *)a1);
}
pthread_mutex_unlock(&count_mutex);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
printf("Starting watch_count(): thread %d\n", *(unsigned int *)a1);
pthread_mutex_lock(&count_mutex);
if ( count <= 11 )
{
pthread_cond_wait(&count_threshold_cv, &count_mutex);
printf("watch_count(): thread %d Condition signal received.\n", *(unsigned int *)a1);
}
pthread_mutex_unlock(&count_mutex);
pthread_exit(0LL);
}

original_code:
void *watch_count(void *idp)
{
  int *my_id = idp;
  printf("Starting watch_count(): thread %d\n", *my_id);
  pthread_mutex_lock(&count_mutex);
  if (count<12) {
    pthread_cond_wait(&count_threshold_cv, &count_mutex);
    printf("watch_count(): thread %d Condition signal received.\n", *my_id);
    }
  pthread_mutex_unlock(&count_mutex);
  pthread_exit(((void *)0));
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // eax
pthread_t *v9; // rbx
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
pthread_t v13; // [rsp+0h] [rbp-78h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
pthread_t v15; // [rsp+10h] [rbp-68h] BYREF
char v16; // [rsp+18h] [rbp-60h] BYREF
pthread_attr_t attr; // [rsp+20h] [rbp-58h] BYREF

v3 = pthread_mutex_init(&count_mutex, 0LL);
if ( v3 )
{
printf("ERROR; return code from pthread_mutex_init() is %d\n", v3);
exit(-1);
}
pthread_cond_init(&count_threshold_cv, 0LL);
v4 = pthread_attr_init(&attr);
if ( v4 )
{
printf("ERROR; return code from pthread_attr_init() is %d\n", v4);
exit(-1);
}
pthread_attr_setdetachstate(&attr, 0);
v5 = pthread_create(&v13, &attr, inc_count, &thread_ids);
v6 = v5;
if ( !v5 )
{
v7 = pthread_create(&newthread, &attr, inc_count, &unk_4040B4);
v6 = v7;
if ( !v7 )
{
v8 = pthread_create(&v15, &attr, watch_count, &unk_4040B8);
if ( !v8 )
{
v9 = &v13;
while ( 1 )
{
v10 = pthread_join(*v9, 0LL);
if ( v10 )
break;
if ( ++v9 == (pthread_t *)&v16 )
{
printf("Main(): Waited on %d threads. Done.\n", 3LL);
v11 = pthread_attr_destroy(&attr);
if ( v11 )
{
printf("ERROR; return code from pthread_attr_destroy() is %d\n", v11);
exit(-1);
}
v12 = pthread_mutex_destroy(&count_mutex);
if ( v12 )
{
printf("ERROR; return code from pthread_mutex_destroy() is %d\n", v12);
exit(-1);
}
pthread_cond_destroy(&count_threshold_cv);
pthread_exit(0LL);
}
}
printf("ERROR; return code from pthread_join() is %d\n", v10);
exit(-1);
}
v6 = v8;
}
}
printf("ERROR; return code from pthread_create() is %d\n", v6);
exit(-1);
}

original_code:
int main (int argc, char *argv[])
{
  int i, ret_count;
  pthread_t threads[3];
  pthread_attr_t attr;
  ret_count=pthread_mutex_init(&count_mutex, ((void *)0));
  if (ret_count)
  {
         printf("ERROR; return code from pthread_mutex_init() is %d\n", ret_count);
         exit(-1);
  }
  pthread_cond_init (&count_threshold_cv, ((void *)0));
  ret_count=pthread_attr_init(&attr);
  if (ret_count)
  {
       printf("ERROR; return code from pthread_attr_init() is %d\n", ret_count);
       exit(-1);
  }
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  ret_count=pthread_create(&threads[0], &attr, inc_count, (void *)&thread_ids[0]);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_create() is %d\n", ret_count);
         exit(-1);
  }
  ret_count=pthread_create(&threads[1], &attr, inc_count, (void *)&thread_ids[1]);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_create() is %d\n", ret_count);
         exit(-1);
  }
  ret_count=pthread_create(&threads[2], &attr, watch_count, (void *)&thread_ids[2]);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_create() is %d\n", ret_count);
         exit(-1);
  }
  for (i=0; i<3; i++)
  {
        ret_count=pthread_join(threads[i], ((void *)0));
        if (ret_count)
        {
            printf("ERROR; return code from pthread_join() is %d\n", ret_count);
            exit(-1);
        }
  }
  printf ("Main(): Waited on %d  threads. Done.\n", 3);
  ret_count=pthread_attr_destroy(&attr);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_attr_destroy() is %d\n", ret_count);
         exit(-1);
  }
  ret_count=pthread_mutex_destroy(&count_mutex);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_mutex_destroy() is %d\n", ret_count);
         exit(-1);
  }
  pthread_cond_destroy(&count_threshold_cv);
  pthread_exit(((void *)0));
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int i; int ret_count;
  unsigned long threads[3];
  union pthread_attr_t attr;
  ret_count=pthread_mutex_init(&count_mutex, ((void *)0));
  if (ret_count)
  {
         printf("ERROR; return code from pthread_mutex_init() is %d\n", ret_count);
         exit(-1);
  }
  pthread_cond_init (&count_threshold_cv, ((void *)0));
  ret_count=pthread_attr_init(&attr);
  if (ret_count)
  {
       printf("ERROR; return code from pthread_attr_init() is %d\n", ret_count);
       exit(-1);
  }
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  ret_count=pthread_create(&threads[0], &attr, inc_count, (void *)&thread_ids[0]);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_create() is %d\n", ret_count);
         exit(-1);
  }
  ret_count=pthread_create(&threads[1], &attr, inc_count, (void *)&thread_ids[1]);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_create() is %d\n", ret_count);
         exit(-1);
  }
  ret_count=pthread_create(&threads[2], &attr, watch_count, (void *)&thread_ids[2]);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_create() is %d\n", ret_count);
         exit(-1);
  }
  for (i=0; i<3; i++)
  {
        ret_count=pthread_join(threads[i], ((void *)0));
        if (ret_count)
        {
            printf("ERROR; return code from pthread_join() is %d\n", ret_count);
            exit(-1);
        }
  }
  printf ("Main(): Waited on %d  threads. Done.\n", 3);
  ret_count=pthread_attr_destroy(&attr);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_attr_destroy() is %d\n", ret_count);
         exit(-1);
  }
  ret_count=pthread_mutex_destroy(&count_mutex);
  if (ret_count)
  {
         printf("ERROR; return code from pthread_mutex_destroy() is %d\n", ret_count);
         exit(-1);
  }
  pthread_cond_destroy(&count_threshold_cv);
  pthread_exit(((void *)0));
}

variable_types:
threads
unsigned long [3]

variable_types: union pthread_attr_t { char __size[56]; long __align; }


doRowWise

decompiled_code:
void __fastcall __noreturn doRowWise(void *a1)
{
int v1; // ebx
int v2; // edx
__int64 *v3; // rsi
char *v4; // r8
int v5; // edx
__int64 v6; // rax

v2 = dist_row * ((_DWORD)a1 - 1);
if ( v2 < v2 + dist_row )
{
v3 = (__int64 *)((char *)InMat + 8 * v2);
v4 = (char *)InMat + 8 * v2 + 8 * (unsigned __int64)(unsigned int)(dist_row - 1) + 8;
do
{
v5 = 0;
if ( col > 0 )
{
v6 = *v3;
v5 = 0;
do
{
v6 += 8LL;
v5 = (int)((double)v5 + *(double *)(v6 - 8));
}
while ( v6 != 8LL * (unsigned int)(col - 1) + 8 + *v3 );
}
if ( v1 < v5 )
v1 = v5;
++v3;
}
while ( v3 != (__int64 *)v4 );
}
pthread_mutex_lock(&mutex_norm);
if ( (double)v1 > *(double *)&NormRow )
*(double *)&NormRow = (double)v1;
pthread_mutex_unlock(&mutex_norm);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebx
int v2; // edx
__int64 *v3; // rsi
char *v4; // r8
int v5; // edx
__int64 v6; // rax

v2 = dist_row * ((_DWORD)a1 - 1);
if ( v2 < v2 + dist_row )
{
v3 = (__int64 *)((char *)InMat + 8 * v2);
v4 = (char *)InMat + 8 * v2 + 8 * (unsigned __int64)(unsigned int)(dist_row - 1) + 8;
do
{
v5 = 0;
if ( col > 0 )
{
v6 = *v3;
v5 = 0;
do
{
v6 += 8LL;
v5 = (int)((double)v5 + *(double *)(v6 - 8));
}
while ( v6 != 8LL * (unsigned int)(col - 1) + 8 + *v3 );
}
if ( v1 < v5 )
v1 = v5;
++v3;
}
while ( v3 != (__int64 *)v4 );
}
pthread_mutex_lock(&mutex_norm);
if ( (double)v1 > *(double *)&NormRow )
*(double *)&NormRow = (double)v1;
pthread_mutex_unlock(&mutex_norm);
pthread_exit(0LL);
}

original_code:
void * doRowWise(int myId)
{
       int CurRow = 0;
       int iCol,myRowSum;
       int mynorm;
       for (CurRow = ((myId - 1) * dist_row); CurRow <= ((myId * dist_row) - 1); CurRow++)
       {
            myRowSum = 0;
            for(iCol = 0 ;iCol < col; iCol++)
            myRowSum += InMat[CurRow][iCol];
            if(mynorm < myRowSum )
            mynorm = myRowSum;
       }
       pthread_mutex_lock(&mutex_norm);
       {
             if (NormRow < mynorm)
              NormRow = mynorm;
       }
       pthread_mutex_unlock(&mutex_norm);
       pthread_exit(((void *)0));
}

canonical_original_code:
void *doRowWise(int myId)
{
       int CurRow = 0;
       int iCol; int myRowSum;
       int mynorm;
       for (CurRow = ((myId - 1) * dist_row); CurRow <= ((myId * dist_row) - 1); CurRow++)
       {
            myRowSum = 0;
            for(iCol = 0 ;iCol < col; iCol++)
            myRowSum += InMat[CurRow][iCol];
            if(mynorm < myRowSum )
            mynorm = myRowSum;
       }
       pthread_mutex_lock(&mutex_norm);
       {
             if (NormRow < mynorm)
              NormRow = mynorm;
       }
       pthread_mutex_unlock(&mutex_norm);
       pthread_exit(((void *)0));
}

variable_types: myId int

variable_types: CurRow int

variable_types: iCol int

variable_types: myRowSum int

variable_types: mynorm int


Addup

decompiled_code:
int __fastcall Addup(void *a1)
{
pthread_mutex_lock(&mutex_sum);
sum += (int)a1;
return pthread_mutex_unlock(&mutex_sum);
}

canonical_decompiled_code:
int __fastcall func7(void *a1)
{
pthread_mutex_lock(&mutex_sum);
sum += (int)a1;
return pthread_mutex_unlock(&mutex_sum);
}

original_code:
void * Addup(int Id)
{
 pthread_mutex_lock(&mutex_sum);
 {
   sum += Id;
 }
  pthread_mutex_unlock(&mutex_sum);
  return;
}

canonical_original_code:
void *Addup(int Id)
{
 pthread_mutex_lock(&mutex_sum);
 {
   sum += Id;
 }
  pthread_mutex_unlock(&mutex_sum);
  return;
}

variable_types: Id int


jacobi

original_code:
void jacobi(int Number)
{
   int i,j;
   for(i = 0; i < Number; i++)
   {
      Bloc_X[i] = RHS_Vector[i];
      for (j = 0;j<i;j++)
      {
        Bloc_X[i] -= X_Old[j] * Matrix_A[i][j];
      }
      for (j = i+1;j<Number;j++)
      {
       Bloc_X[i] -= X_Old[j] * Matrix_A[i][j];
      }
      Bloc_X[i] = Bloc_X[i] / Matrix_A[i][i];
  }
  for(i = 0; i < Number; i++)
  {
   X_New[i] = Bloc_X[i];
  }
}

canonical_original_code:
void jacobi(int Number)
{
   int i; int j;
   for(i = 0; i < Number; i++)
   {
      Bloc_X[i] = RHS_Vector[i];
      for (j = 0;j<i;j++)
      {
        Bloc_X[i] -= X_Old[j] * Matrix_A[i][j];
      }
      for (j = i+1;j<Number;j++)
      {
       Bloc_X[i] -= X_Old[j] * Matrix_A[i][j];
      }
      Bloc_X[i] = Bloc_X[i] / Matrix_A[i][i];
  }
  for(i = 0; i < Number; i++)
  {
   X_New[i] = Bloc_X[i];
  }
}

variable_types: Number int

variable_types: i int

return_type: void


printmsg

decompiled_code:
int __fastcall printmsg(void *a1)
{
return printf(" %s", (const char *)a1);
}

canonical_decompiled_code:
int __fastcall func7(void *a1)
{
return printf(" %s", (const char *)a1);
}

original_code:
void * printmsg(char *s)
{
 printf(" %s", s);
 return;
}

canonical_original_code:
void *printmsg(char *s)
{
 printf(" %s", s);
 return;
}

variable_types:
s
char *


repo: HackGyver/packthatshit

decompiled_code:
__int64 __fastcall get_alignment(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er8

v2 = a1;
if ( a1 % a2 )
v2 = a2 * (a1 / a2 + 1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er8

v2 = a1;
if ( a1 % a2 )
v2 = a2 * (a1 / a2 + 1);
return v2;
}

original_code:
uint32_t get_alignment(uint32_t value, uint32_t alignment)
{
    if (!(value % alignment))
        return value;
    else
        return ((value / alignment) + 1) * alignment;
}

canonical_original_code:
unsigned int get_alignment(unsigned int value, unsigned int alignment)
{
    if (!(value % alignment))
        return value;
    else
        return ((value / alignment) + 1) * alignment;
}

variable_types:
value
unsigned int

variable_types:
alignment
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall add_section(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( (unsigned int)get_arch_pe() == 1 )
{
add_section32(a1, a2);
result = 1LL;
}
else
{
puts("Error: unknow architecture");
result = 0LL;
}
return result;
}

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

if ( (unsigned int)get_arch_pe() == 1 )
{
add_section32(a1, a2);
result = 1LL;
}
else
{
puts("Error: unknow architecture");
result = 0LL;
}
return result;
}

original_code:
int add_section(const char *filename, Loader loader) {
    switch (get_arch_pe(filename)) {
        case 1:
            add_section32(filename, loader);
            break;
        default:
            printf("Error: unknow architecture\n");
            return 0;
    }
    return 1;
}

canonical_original_code:
int add_section(char *filename, struct Struct_Loader *loader) {
    switch (get_arch_pe(filename)) {
        case 1:
            add_section32(filename, loader);
            break;
        default:
            printf("Error: unknow architecture\n");
            return 0;
    }
    return 1;
}

variable_types:
filename
char *

variable_types: struct Struct_Loader { unsigned int size; unsigned int oep; char *payload; } *


repo: HadynRichard/openrs

decompiled_code:
__int64 reactor_init()
{
int v0; // eax
__int64 v1; // rdi
__int16 v2; // ax
socklen_t v3; // edx
int v4; // eax
int v5; // er8
__int64 result; // rax
int optval; // [rsp+10h] [rbp-28h] BYREF
struct epoll_event event; // [rsp+14h] [rbp-24h] BYREF
struct sockaddr v9; // [rsp+20h] [rbp-18h] BYREF

optval = 1;
v0 = socket(2, 1, 0);
serversockfd = v0;
if ( v0 == -1 )
{
perror("socket()");
result = 0LL;
}
else if ( fcntl(v0, 4, 2048LL) == -1 )
{
perror("fcntl()");
result = 0LL;
}
else
{
v1 = serversockfd;
if ( setsockopt(serversockfd, 1, 2, &optval, 4u) == -1 )
{
perror("setsockopt()");
result = 0LL;
}
else
{
*(_DWORD *)&v9.sa_data[2] = 0;
v9.sa_family = 2;
v2 = _bswap_16_constprop_0(v1, &v9, 16LL);
*(_QWORD *)&v9.sa_data[6] = 0LL;
*(_WORD *)v9.sa_data = v2;
if ( bind(serversockfd, &v9, v3) == -1 )
{
perror("bind()");
result = 0LL;
}
else if ( listen(serversockfd, 2000) == -1 )
{
perror("listen()");
result = 0LL;
}
else
{
events = malloc(0x5DC0uLL);
v4 = epoll_create(2000);
epfd = v4;
if ( v4 )
{
event.events = 1;
event.data.fd = serversockfd;
v5 = epoll_ctl(v4, 1, serversockfd, &event);
result = 1LL;
if ( v5 < 0 )
{
perror("epoll_ctl()");
result = 0LL;
}
}
else
{
perror("epoll_create()");
result = 0LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
__int64 v1; // rdi
__int16 v2; // ax
socklen_t v3; // edx
int v4; // eax
int v5; // er8
__int64 result; // rax
int optval; // [rsp+10h] [rbp-28h] BYREF
struct epoll_event event; // [rsp+14h] [rbp-24h] BYREF
struct sockaddr v9; // [rsp+20h] [rbp-18h] BYREF

optval = 1;
v0 = socket(2, 1, 0);
serversockfd = v0;
if ( v0 == -1 )
{
perror("socket()");
result = 0LL;
}
else if ( fcntl(v0, 4, 2048LL) == -1 )
{
perror("fcntl()");
result = 0LL;
}
else
{
v1 = serversockfd;
if ( setsockopt(serversockfd, 1, 2, &optval, 4u) == -1 )
{
perror("setsockopt()");
result = 0LL;
}
else
{
*(_DWORD *)&v9.sa_data[2] = 0;
v9.sa_family = 2;
v2 = func0(v1, &v9, 16LL);
*(_QWORD *)&v9.sa_data[6] = 0LL;
*(_WORD *)v9.sa_data = v2;
if ( bind(serversockfd, &v9, v3) == -1 )
{
perror("bind()");
result = 0LL;
}
else if ( listen(serversockfd, 2000) == -1 )
{
perror("listen()");
result = 0LL;
}
else
{
events = malloc(0x5DC0uLL);
v4 = epoll_create(2000);
epfd = v4;
if ( v4 )
{
event.events = 1;
event.data.fd = serversockfd;
v5 = epoll_ctl(v4, 1, serversockfd, &event);
result = 1LL;
if ( v5 < 0 )
{
perror("epoll_ctl()");
result = 0LL;
}
}
else
{
perror("epoll_create()");
result = 0LL;
}
}
}
}
return result;
}

original_code:
int reactor_init() {
 int ON = 1, OFF = 0;
 if ((serversockfd = socket(2, SOCK_STREAM, 0)) == -1) {
  perror("socket()");
  return 0;
 }
 if (fcntl(serversockfd, 4, 04000) == -1) {
  perror("fcntl()");
  return 0;
 }
 if (setsockopt(serversockfd, 1, 2, &ON, sizeof(int)) == -1) {
  perror("setsockopt()");
  return 0;
 }
 struct sockaddr_in addr;
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 addr.sin_port = htons(43594);
 memset(&(addr.sin_zero), '\0', 8);
 if (bind(serversockfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
  perror("bind()");
  return 0;
 }
 if (listen(serversockfd, 2000) == -1) {
  perror("listen()");
  return 0;
 }
 events = malloc(2000 * sizeof(struct epoll_event));
 epfd = epoll_create(2000);
 if (!epfd) {
  perror("epoll_create()");
  return 0;
 }
 struct epoll_event ev;
 ev.events = EPOLLIN;
 ev.data.fd = serversockfd;
 if (epoll_ctl(epfd, 1, serversockfd, &ev) < 0) {
  perror("epoll_ctl()");
  return 0;
 }
 return 1;
}

canonical_original_code:
int reactor_init() {
 int ON = 1; int OFF = 0;
 if ((serversockfd = socket(2, SOCK_STREAM, 0)) == -1) {
  perror("socket()");
  return 0;
 }
 if (fcntl(serversockfd, 4, 04000) == -1) {
  perror("fcntl()");
  return 0;
 }
 if (setsockopt(serversockfd, 1, 2, &ON, sizeof(int)) == -1) {
  perror("setsockopt()");
  return 0;
 }
 struct sockaddr_in addr;
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 addr.sin_port = htons(43594);
 memset(&(addr.sin_zero), '\0', 8);
 if (bind(serversockfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
  perror("bind()");
  return 0;
 }
 if (listen(serversockfd, 2000) == -1) {
  perror("listen()");
  return 0;
 }
 events = malloc(2000 * sizeof(struct epoll_event));
 epfd = epoll_create(2000);
 if (!epfd) {
  perror("epoll_create()");
  return 0;
 }
 struct epoll_event ev;
 ev.events = EPOLLIN;
 ev.data.fd = serversockfd;
 if (epoll_ctl(epfd, 1, serversockfd, &ev) < 0) {
  perror("epoll_ctl()");
  return 0;
 }
 return 1;
}

variable_types: ON int

variable_types: OFF int

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

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }

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

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

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


decompiled_code:
void do_accept()
{
char *v0; // rbp
int v1; // eax
int v2; // ebx
char *v3; // rax
struct epoll_event *v4; // r13
_DWORD *v5; // rax
_DWORD *v6; // r12
socklen_t addr_len[11]; // [rsp+Ch] [rbp-2Ch] BYREF

addr_len[0] = 8;
v0 = (char *)malloc(0x10uLL);
v1 = accept(serversockfd, (struct sockaddr *)v0, addr_len);
if ( v1 == -1 )
{
perror("accept()");
}
else
{
v2 = v1;
if ( fcntl(v1, 4, 2048LL) == -1 )
{
perror("fcntl()");
}
else
{
v3 = inet_ntoa(*(struct in_addr *)(v0 + 4));
printf("Accepted client from %s\n", v3);
v4 = (struct epoll_event *)malloc(0xCuLL);
v5 = malloc(0x48uLL);
v4->data.u64 = (uint64_t)v5;
v6 = v5;
v4->events = 1;
if ( epoll_ctl(epfd, 1, v2, v4) < 0 )
{
perror("epoll_ctl()");
}
else
{
v6[1] = v2;
*((_QWORD *)v6 + 1) = v0;
*((_QWORD *)v6 + 2) = v4;
init_client(v6);
}
}
}
}

canonical_decompiled_code:
void func2()
{
char *v0; // rbp
int v1; // eax
int v2; // ebx
char *v3; // rax
struct epoll_event *v4; // r13
_DWORD *v5; // rax
_DWORD *v6; // r12
socklen_t addr_len[11]; // [rsp+Ch] [rbp-2Ch] BYREF

addr_len[0] = 8;
v0 = (char *)malloc(0x10uLL);
v1 = accept(serversockfd, (struct sockaddr *)v0, addr_len);
if ( v1 == -1 )
{
perror("accept()");
}
else
{
v2 = v1;
if ( fcntl(v1, 4, 2048LL) == -1 )
{
perror("fcntl()");
}
else
{
v3 = inet_ntoa(*(struct in_addr *)(v0 + 4));
printf("Accepted client from %s\n", v3);
v4 = (struct epoll_event *)malloc(0xCuLL);
v5 = malloc(0x48uLL);
v4->data.u64 = (uint64_t)v5;
v6 = v5;
v4->events = 1;
if ( epoll_ctl(epfd, 1, v2, v4) < 0 )
{
perror("epoll_ctl()");
}
else
{
v6[1] = v2;
*((_QWORD *)v6 + 1) = v0;
*((_QWORD *)v6 + 2) = v4;
init_client(v6);
}
}
}
}

original_code:
void do_accept() {
 struct sockaddr_in *addr = malloc(sizeof(struct sockaddr_in));
 int addrlen = sizeof(addr);
 int sockfd;
 if ((sockfd = accept(serversockfd, (struct sockaddr *) addr, &addrlen)) == -1) {
  perror("accept()");
  return;
 }
 if (fcntl(sockfd, 4, 04000) == -1) {
  perror("fcntl()");
  return;
 }
 printf("Accepted client from %s\n", inet_ntoa(addr->sin_addr));
 struct epoll_event *ev = malloc(sizeof(struct epoll_event));
 struct client *c = malloc(sizeof(struct client));
 ev->data.fd = sockfd;
 ev->events = EPOLLIN;
 ev->data.ptr = c;
 if (epoll_ctl(epfd, 1, sockfd, ev) < 0) {
  perror("epoll_ctl()");
  return;
 }
 c->sockfd = sockfd;
 c->addr = addr;
 c->epollev = ev;
 init_client(c);
}

variable_types: addrlen int

variable_types: sockfd int

variable_types: struct client { int state; int sockfd; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *addr; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *epollev; struct buffer { int size; char *data; int capacity; int position; int bit_position; } *in_buffer; struct buffer *out_buffer; struct isaac_context { struct isaac_results { unsigned int *results; unsigned int position; } *results; unsigned int *memory; unsigned int aa; unsigned int bb; unsigned int cc; } *in_cipher; struct isaac_context *out_cipher; struct packet { int opcode; int length; int length_type; struct buffer *payload; } *packet; struct player { int id; struct client *client; char *username; char *password; } *player; } *

user_defined_types: struct client { int state; int sockfd; struct sockaddr_in *addr; struct epoll_event *epollev; struct buffer *in_buffer; struct buffer *out_buffer; struct isaac_context *in_cipher; struct isaac_context *out_cipher; struct packet *packet; struct player *player; }

user_defined_types: struct isaac_context { struct isaac_results *results; unsigned int *memory; unsigned int aa; unsigned int bb; unsigned int cc; }


decompiled_code:
void reactor_poll()
{
int v0; // eax
unsigned __int64 v1; // rbx
__int64 v2; // r12
struct epoll_event *v3; // rax

v0 = epoll_wait(epfd, events, 2000, 0);
if ( v0 > 0 )
{
v1 = 0LL;
v2 = 12LL * v0;
while ( 1 )
{
v3 = &events[v1 / 0xC];
if ( events[v1 / 0xC].data.fd == serversockfd )
{
do_accept();
goto LABEL_4;
}
if ( (v3->events & 1) != 0 )
{
((void (__fastcall *)(_QWORD))do_read)((epoll_data_t)v3->data.u64);
v3 = &events[v1 / 0xC];
if ( (events[v1 / 0xC].events & 4) != 0 )
goto LABEL_8;
LABEL_4:
v1 += 12LL;
if ( v2 == v1 )
return;
}
else
{
if ( (v3->events & 4) == 0 )
goto LABEL_4;
LABEL_8:
v1 += 12LL;
((void (__fastcall *)(_QWORD))do_write)((epoll_data_t)v3->data.u64);
if ( v2 == v1 )
return;
}
}
}
}

canonical_decompiled_code:
void func3()
{
int v0; // eax
unsigned __int64 v1; // rbx
__int64 v2; // r12
struct epoll_event *v3; // rax

v0 = epoll_wait(epfd, events, 2000, 0);
if ( v0 > 0 )
{
v1 = 0LL;
v2 = 12LL * v0;
while ( 1 )
{
v3 = &events[v1 / 0xC];
if ( events[v1 / 0xC].data.fd == serversockfd )
{
func2();
goto LABEL_4;
}
if ( (v3->events & 1) != 0 )
{
((void (__fastcall *)(_QWORD))do_read)((epoll_data_t)v3->data.u64);
v3 = &events[v1 / 0xC];
if ( (events[v1 / 0xC].events & 4) != 0 )
goto LABEL_8;
LABEL_4:
v1 += 12LL;
if ( v2 == v1 )
return;
}
else
{
if ( (v3->events & 4) == 0 )
goto LABEL_4;
LABEL_8:
v1 += 12LL;
((void (__fastcall *)(_QWORD))do_write)((epoll_data_t)v3->data.u64);
if ( v2 == v1 )
return;
}
}
}
}

original_code:
void reactor_poll() {
 int i;
 int nfds = epoll_wait(epfd, events, 2000, 0);
 for (i = 0; i < nfds; i++) {
  if (events[i].data.fd == serversockfd) {
   do_accept();
  } else {
   if (events[i].events & EPOLLIN)
    do_read((struct client *) events[i].data.ptr);
   if (events[i].events & EPOLLOUT)
    do_write((struct client *) events[i].data.ptr);
  }
 }
}

variable_types: nfds int

user_defined_types: struct buffer { int size; char *data; int capacity; int position; int bit_position; }

user_defined_types: struct packet { int opcode; int length; int length_type; struct buffer *payload; }

user_defined_types: struct player { int id; struct client *client; char *username; char *password; }

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }

user_defined_types: struct isaac_results { unsigned int *results; unsigned int position; }


decompiled_code:
void *__fastcall init_buffer(__int64 a1)
{
void *result; // rax

result = malloc(0x1000uLL);
*(_QWORD *)(a1 + 16) = 4096LL;
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)a1 = 0;
return result;
}

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

result = malloc(0x1000uLL);
*(_QWORD *)(a1 + 16) = 4096LL;
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)a1 = 0;
return result;
}

original_code:
void init_buffer(struct buffer *b) {
 b->capacity = 4096;
 b->data = malloc(4096);
 b->position = 0;
 b->size = 0;
}

variable_types: struct buffer { int size; char *data; int capacity; int position; int bit_position; } *


decompiled_code:
void __fastcall free_buffer(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void free_buffer(struct buffer *b) {
 free(b->data);
 free(b);
}


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

result = (unsigned int)(8 * *(_DWORD *)(a1 + 20));
*(_DWORD *)(a1 + 24) = result;
return result;
}

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

result = (unsigned int)(8 * *(_DWORD *)(a1 + 20));
*(_DWORD *)(a1 + 24) = result;
return result;
}

original_code:
void bit_access_open(struct buffer *b) {
 b->bit_position = b->position * 8;
}


decompiled_code:
__int64 __fastcall bit_access_close(__int64 a1)
{
int v1; // eax
int v2; // edx
int v3; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 24);
v2 = v1 + 14;
v3 = v1 + 7;
if ( v3 < 0 )
v3 = v2;
result = (unsigned int)(v3 >> 3);
*(_DWORD *)(a1 + 20) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
int v2; // edx
int v3; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 24);
v2 = v1 + 14;
v3 = v1 + 7;
if ( v3 < 0 )
v3 = v2;
result = (unsigned int)(v3 >> 3);
*(_DWORD *)(a1 + 20) = result;
return result;
}

original_code:
void bit_access_close(struct buffer *b) {
  b->position = (b->bit_position + 7) / 8;
}


original_code:
void put_bits(struct buffer *b, int amt, int value) {
 int byte_pos = b->bit_position >> 3;
 int bit_offset = 8 - (b->bit_position & 7);
 b->bit_position += amt;
 if ((b->capacity - b->position) < (amt / 8)) {
  perror("WARNING: Buffer overflow in put_bits");
  return;
 }
 for (; amt > bit_offset; bit_offset = 8) {
  b->data[byte_pos] &= ~BIT_MASK_OUT[bit_offset];
  b->data[byte_pos++] |= (value >> (amt - bit_offset)) & BIT_MASK_OUT[bit_offset];
  amt -= bit_offset;
 }
 if (amt == bit_offset) {
  b->data[byte_pos] &= ~BIT_MASK_OUT[bit_offset];
  b->data[byte_pos] |= value & BIT_MASK_OUT[bit_offset];
 } else {
  b->data[byte_pos] &= ~(BIT_MASK_OUT[amt] << (bit_offset - amt));
  b->data[byte_pos] |= (value & BIT_MASK_OUT[amt]) << (bit_offset - amt);
 }
}

variable_types: amt int

variable_types: value int


decompiled_code:
__int64 __fastcall get_byte(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 result; // rax

v2 = *(int *)(a1 + 20);
if ( (int)v2 + 1 >= *(_DWORD *)(a1 + 16) )
{
perror("WARNING: Buffer underflow in get_byte");
result = 0LL;
}
else
{
v3 = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 20) = v2 + 1;
result = (unsigned int)*(char *)(v3 + v2);
switch ( a2 )
{
case 2:
result = (unsigned int)(128 - result);
break;
case 3:
result = (unsigned int)-(int)result;
break;
case 1:
result = (unsigned int)(result - 128);
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 result; // rax

v2 = *(int *)(a1 + 20);
if ( (int)v2 + 1 >= *(_DWORD *)(a1 + 16) )
{
perror("WARNING: Buffer underflow in get_byte");
result = 0LL;
}
else
{
v3 = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 20) = v2 + 1;
result = (unsigned int)*(char *)(v3 + v2);
switch ( a2 )
{
case 2:
result = (unsigned int)(128 - result);
break;
case 3:
result = (unsigned int)-(int)result;
break;
case 1:
result = (unsigned int)(result - 128);
break;
}
}
return result;
}

original_code:
int32_t get_byte(struct buffer *b, int xform) {
 if (b->position + 1 >= b->capacity) {
  perror("WARNING: Buffer underflow in get_byte");
  return 0;
 }
 int32_t value = 0;
 value = b->data[b->position++];
 switch (xform) {
 case 1:
  value -= 128;
  break;
 case 2:
  value = 128 - value;
  break;
 case 3:
  value = -value;
  break;
 }
 return value;
}

canonical_original_code:
int get_byte(struct buffer *b, int xform) {
 if (b->position + 1 >= b->capacity) {
  perror("WARNING: Buffer underflow in get_byte");
  return 0;
 }
 int value = 0;
 value = b->data[b->position++];
 switch (xform) {
 case 1:
  value -= 128;
  break;
 case 2:
  value = 128 - value;
  break;
 case 3:
  value = -value;
  break;
 }
 return value;
}

variable_types: xform int


original_code:
void put_byte(struct buffer *b, int32_t value, int xform) {
 if (b->position >= b->capacity) {
  perror("WARNING: Buffer overflow in put_byte");
  return;
 }
 switch (xform) {
 case 1:
  value += 128;
  break;
 case 2:
  value = 128 - value;
  break;
 case 3:
  value = -value;
  break;
 }
 b->data[b->position++] = value;
}

canonical_original_code:
void put_byte(struct buffer *b, int value, int xform) {
 if (b->position >= b->capacity) {
  perror("WARNING: Buffer overflow in put_byte");
  return;
 }
 switch (xform) {
 case 1:
  value += 128;
  break;
 case 2:
  value = 128 - value;
  break;
 case 3:
  value = -value;
  break;
 }
 b->data[b->position++] = value;
}


decompiled_code:
void __fastcall put_string(__int64 a1, char *a2)
{
char v3; // si
char *v4; // rbx

v3 = *a2;
if ( v3 )
{
v4 = a2 + 1;
do
{
++v4;
put_byte(a1, v3, 0);
v3 = *(v4 - 1);
}
while ( v3 );
}
put_byte(a1, 10, 0);
}

original_code:
void put_string(struct buffer *b, char *str) {
 char c;
 int idx = 0;
 while ((c = str[idx]) != '\0') {
  put_byte(b, c, 0);
  idx++;
 }
 put_byte(b, '\n', 0);
}

variable_types:
str
char *

variable_types: c char

variable_types: idx int


decompiled_code:
__int64 __fastcall get_short(__int64 a1, int a2, int a3)
{
__int64 result; // rax
unsigned __int8 v5; // bl
__int16 v6; // bx

if ( a2 )
{
result = 0LL;
if ( a2 == 1 )
{
v5 = get_byte(a1, a3);
result = v5 | (unsigned int)(unsigned __int16)((unsigned __int16)get_byte(a1, 0) << 8);
}
}
else
{
v6 = get_byte(a1, 0);
result = (unsigned __int8)get_byte(a1, a3) | (unsigned int)(unsigned __int16)(v6 << 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
__int64 result; // rax
unsigned __int8 v5; // bl
__int16 v6; // bx

if ( a2 )
{
result = 0LL;
if ( a2 == 1 )
{
v5 = func5(a1, a3);
result = v5 | (unsigned int)(unsigned __int16)((unsigned __int16)func5(a1, 0) << 8);
}
}
else
{
v6 = func5(a1, 0);
result = (unsigned __int8)func5(a1, a3) | (unsigned int)(unsigned __int16)(v6 << 8);
}
return result;
}

original_code:
int32_t get_short(struct buffer *b, int endian, int xform) {
 int32_t value = 0;
 switch (endian) {
 case 0:
  value |= (get_byte(b, 0) & 0xff) << 8;
  value |= (get_byte(b, xform) & 0xff);
  break;
 case 1:
  value |= (get_byte(b, xform) & 0xff);
  value |= (get_byte(b, 0) & 0xff) << 8;
  break;
 }
 return value;
}

canonical_original_code:
int get_short(struct buffer *b, int endian, int xform) {
 int value = 0;
 switch (endian) {
 case 0:
  value |= (get_byte(b, 0) & 0xff) << 8;
  value |= (get_byte(b, xform) & 0xff);
  break;
 case 1:
  value |= (get_byte(b, xform) & 0xff);
  value |= (get_byte(b, 0) & 0xff) << 8;
  break;
 }
 return value;
}

variable_types: endian int


decompiled_code:
void __fastcall put_short(__int64 a1, __int16 a2, int a3, int a4)
{
if ( a3 )
{
if ( a3 == 1 )
{
put_byte(a1, a2, a4);
put_byte(a1, SHIBYTE(a2), 0);
}
}
else
{
put_byte(a1, SHIBYTE(a2), 0);
put_byte(a1, a2, a4);
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int16 a2, int a3, int a4)
{
if ( a3 )
{
if ( a3 == 1 )
{
func6(a1, a2, a4);
func6(a1, SHIBYTE(a2), 0);
}
}
else
{
func6(a1, SHIBYTE(a2), 0);
func6(a1, a2, a4);
}
}

original_code:
void put_short(struct buffer *b, int32_t value, int endian, int xform) {
 switch (endian) {
 case 0:
  put_byte(b, value >> 8, 0);
  put_byte(b, value, xform);
  break;
 case 1:
  put_byte(b, value, xform);
  put_byte(b, value >> 8, 0);
  break;
 }
}

canonical_original_code:
void put_short(struct buffer *b, int value, int endian, int xform) {
 switch (endian) {
 case 0:
  put_byte(b, value >> 8, 0);
  put_byte(b, value, xform);
  break;
 case 1:
  put_byte(b, value, xform);
  put_byte(b, value >> 8, 0);
  break;
 }
}


decompiled_code:
__int64 __fastcall get_int(__int64 a1, int a2, int a3)
{
__int64 result; // rax
unsigned __int8 v5; // bl
__int16 v6; // r13
int v7; // er12
int v8; // ebx
int v9; // er13
__int16 v10; // r12

if ( a2 )
{
result = 0LL;
if ( a2 == 1 )
{
v5 = get_byte(a1, a3);
v6 = get_byte(a1, 0);
v7 = get_byte(a1, 0);
result = (unsigned __int16)(v6 << 8) | ((unsigned int)get_byte(a1, 0) << 24) | v5 | (v7 << 16) & 0xFF0000;
}
}
else
{
v8 = get_byte(a1, 0);
v9 = get_byte(a1, 0);
v10 = get_byte(a1, 0);
result = (unsigned __int16)(v10 << 8) | (unsigned __int8)get_byte(a1, a3) | (v8 << 24) | (v9 << 16) & 0xFF0000u;
}
return result;
}

original_code:
int32_t get_int(struct buffer *b, int endian, int xform) {
 int32_t value = 0;
 switch (endian) {
 case 0:
  value |= (get_byte(b, 0) & 0xff) << 24;
  value |= (get_byte(b, 0) & 0xff) << 16;
  value |= (get_byte(b, 0) & 0xff) << 8;
  value |= (get_byte(b, xform) & 0xff);
  break;
 case 1:
  value |= (get_byte(b, xform) & 0xff);
  value |= (get_byte(b, 0) & 0xff) << 8;
  value |= (get_byte(b, 0) & 0xff) << 16;
  value |= (get_byte(b, 0) & 0xff) << 24;
  break;
 }
 return value;
}

canonical_original_code:
int get_int(struct buffer *b, int endian, int xform) {
 int value = 0;
 switch (endian) {
 case 0:
  value |= (get_byte(b, 0) & 0xff) << 24;
  value |= (get_byte(b, 0) & 0xff) << 16;
  value |= (get_byte(b, 0) & 0xff) << 8;
  value |= (get_byte(b, xform) & 0xff);
  break;
 case 1:
  value |= (get_byte(b, xform) & 0xff);
  value |= (get_byte(b, 0) & 0xff) << 8;
  value |= (get_byte(b, 0) & 0xff) << 16;
  value |= (get_byte(b, 0) & 0xff) << 24;
  break;
 }
 return value;
}


decompiled_code:
void __fastcall put_int(__int64 a1, int a2, int a3, int a4)
{
if ( a3 )
{
if ( a3 == 1 )
{
put_byte(a1, a2, a4);
put_byte(a1, SBYTE1(a2), 0);
put_byte(a1, SBYTE2(a2), 0);
put_byte(a1, SHIBYTE(a2), 0);
}
}
else
{
put_byte(a1, SHIBYTE(a2), 0);
put_byte(a1, SBYTE2(a2), 0);
put_byte(a1, SBYTE1(a2), 0);
put_byte(a1, a2, a4);
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, int a2, int a3, int a4)
{
if ( a3 )
{
if ( a3 == 1 )
{
func6(a1, a2, a4);
func6(a1, SBYTE1(a2), 0);
func6(a1, SBYTE2(a2), 0);
func6(a1, SHIBYTE(a2), 0);
}
}
else
{
func6(a1, SHIBYTE(a2), 0);
func6(a1, SBYTE2(a2), 0);
func6(a1, SBYTE1(a2), 0);
func6(a1, a2, a4);
}
}

original_code:
void put_int(struct buffer *b, int32_t value, int endian, int xform) {
 switch (endian) {
 case 0:
  put_byte(b, value >> 24, 0);
  put_byte(b, value >> 16, 0);
  put_byte(b, value >> 8, 0);
  put_byte(b, value, xform);
  break;
 case 1:
  put_byte(b, value, xform);
  put_byte(b, value >> 8, 0);
  put_byte(b, value >> 16, 0);
  put_byte(b, value >> 24, 0);
  break;
 }
}

canonical_original_code:
void put_int(struct buffer *b, int value, int endian, int xform) {
 switch (endian) {
 case 0:
  put_byte(b, value >> 24, 0);
  put_byte(b, value >> 16, 0);
  put_byte(b, value >> 8, 0);
  put_byte(b, value, xform);
  break;
 case 1:
  put_byte(b, value, xform);
  put_byte(b, value >> 8, 0);
  put_byte(b, value >> 16, 0);
  put_byte(b, value >> 24, 0);
  break;
 }
}


original_code:
int64_t get_long(struct buffer *b, int endian, int xform) {
 int64_t value = 0;
 switch (endian) {
 case 0:
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 56L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 48L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 40L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 32L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 24L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 16L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 8L;
  value |= (int64_t) (get_byte(b, xform) & 0xff);
  break;
 case 1:
  value |= (int64_t) (get_byte(b, xform) & 0xff);
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 8L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 16L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 24L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 32L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 40L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 48L;
  value |= (int64_t) (get_byte(b, 0) & 0xff) << 56L;
  break;
 }
 return value;
}

canonical_original_code:
long get_long(struct buffer *b, int endian, int xform) {
 long value = 0;
 switch (endian) {
 case 0:
  value |= (long) (get_byte(b, 0) & 0xff) << 56L;
  value |= (long) (get_byte(b, 0) & 0xff) << 48L;
  value |= (long) (get_byte(b, 0) & 0xff) << 40L;
  value |= (long) (get_byte(b, 0) & 0xff) << 32L;
  value |= (long) (get_byte(b, 0) & 0xff) << 24L;
  value |= (long) (get_byte(b, 0) & 0xff) << 16L;
  value |= (long) (get_byte(b, 0) & 0xff) << 8L;
  value |= (long) (get_byte(b, xform) & 0xff);
  break;
 case 1:
  value |= (long) (get_byte(b, xform) & 0xff);
  value |= (long) (get_byte(b, 0) & 0xff) << 8L;
  value |= (long) (get_byte(b, 0) & 0xff) << 16L;
  value |= (long) (get_byte(b, 0) & 0xff) << 24L;
  value |= (long) (get_byte(b, 0) & 0xff) << 32L;
  value |= (long) (get_byte(b, 0) & 0xff) << 40L;
  value |= (long) (get_byte(b, 0) & 0xff) << 48L;
  value |= (long) (get_byte(b, 0) & 0xff) << 56L;
  break;
 }
 return value;
}

variable_types: value long

return_type: long


decompiled_code:
void __fastcall put_long(__int64 a1, __int64 a2, int a3, int a4)
{
if ( a3 )
{
if ( a3 == 1 )
{
put_byte(a1, a2, a4);
put_byte(a1, SBYTE1(a2), 0);
put_byte(a1, SBYTE2(a2), 0);
put_byte(a1, SBYTE3(a2), 0);
put_byte(a1, SBYTE4(a2), 0);
put_byte(a1, SBYTE5(a2), 0);
put_byte(a1, SBYTE6(a2), 0);
put_byte(a1, SHIBYTE(a2), 0);
}
}
else
{
put_byte(a1, SHIBYTE(a2), 0);
put_byte(a1, SBYTE6(a2), 0);
put_byte(a1, SBYTE5(a2), 0);
put_byte(a1, SBYTE4(a2), 0);
put_byte(a1, SBYTE3(a2), 0);
put_byte(a1, SBYTE2(a2), 0);
put_byte(a1, SBYTE1(a2), 0);
put_byte(a1, a2, a4);
}
}

original_code:
void put_long(struct buffer *b, int64_t value, int endian, int xform) {
 switch (endian) {
 case 0:
  put_byte(b, value >> 56L, 0);
  put_byte(b, value >> 48L, 0);
  put_byte(b, value >> 40L, 0);
  put_byte(b, value >> 32L, 0);
  put_byte(b, value >> 24L, 0);
  put_byte(b, value >> 16L, 0);
  put_byte(b, value >> 8L, 0);
  put_byte(b, value, xform);
  break;
 case 1:
  put_byte(b, value, xform);
  put_byte(b, value >> 8, 0);
  put_byte(b, value >> 16, 0);
  put_byte(b, value >> 24, 0);
  put_byte(b, value >> 32, 0);
  put_byte(b, value >> 40, 0);
  put_byte(b, value >> 48, 0);
  put_byte(b, value >> 56, 0);
  break;
 }
}

canonical_original_code:
void put_long(struct buffer *b, long value, int endian, int xform) {
 switch (endian) {
 case 0:
  put_byte(b, value >> 56L, 0);
  put_byte(b, value >> 48L, 0);
  put_byte(b, value >> 40L, 0);
  put_byte(b, value >> 32L, 0);
  put_byte(b, value >> 24L, 0);
  put_byte(b, value >> 16L, 0);
  put_byte(b, value >> 8L, 0);
  put_byte(b, value, xform);
  break;
 case 1:
  put_byte(b, value, xform);
  put_byte(b, value >> 8, 0);
  put_byte(b, value >> 16, 0);
  put_byte(b, value >> 24, 0);
  put_byte(b, value >> 32, 0);
  put_byte(b, value >> 40, 0);
  put_byte(b, value >> 48, 0);
  put_byte(b, value >> 56, 0);
  break;
 }
}


main

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

puts("Starting OpenRS emulator...");
printf("\tInitializing the game world\t");
world_init("\tInitializing the game world\t", argv);
puts("\t\t[OK]");
printf("\tLoading Python scripting system\t");
if ( (unsigned int)load_scripts()
&& (puts("\t\t[OK]"), printf("\tInitializing reactor networking system"), (unsigned int)reactor_init()) )
{
puts("\t\t[OK]");
puts("Startup complete.");
core_run();
result = 0;
}
else
{
puts("\nUnable to start.");
result = -1;
}
return result;
}

original_code:
int main(void) {
 printf("Starting OpenRS emulator...\n");
 printf("\tInitializing the game world\t");
 world_init();
 printf("\t\t[OK]\n");
 printf("\tLoading Python scripting system\t");
 if (!load_scripts()) {
  printf("\nUnable to start.\n");
  return -1;
 }
 printf("\t\t[OK]\n");
 printf("\tInitializing reactor networking system");
 if (!reactor_init()) {
  printf("\nUnable to start.\n");
  return -1;
 }
 printf("\t\t[OK]\n");
 printf("Startup complete.\n");
 core_run();
 return 0;
}

canonical_original_code:
int main() {
 printf("Starting OpenRS emulator...\n");
 printf("\tInitializing the game world\t");
 world_init();
 printf("\t\t[OK]\n");
 printf("\tLoading Python scripting system\t");
 if (!load_scripts()) {
  printf("\nUnable to start.\n");
  return -1;
 }
 printf("\t\t[OK]\n");
 printf("\tInitializing reactor networking system");
 if (!reactor_init()) {
  printf("\nUnable to start.\n");
  return -1;
 }
 printf("\t\t[OK]\n");
 printf("Startup complete.\n");
 core_run();
 return 0;
}


decompiled_code:
void world_free()
{
free(players);
}

canonical_decompiled_code:
void func3()
{
free(players);
}

original_code:
void world_free() {
 free(players);
}

canonical_original_code:
void world_free() {
 free(players);
}


decompiled_code:
__int64 world_sync()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 8LL; i != 16008; i += 8LL )
{
result = players;
if ( *(_QWORD *)(players + i) )
result = update_players();
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 8LL; i != 16008; i += 8LL )
{
result = players;
if ( *(_QWORD *)(players + i) )
result = update_players();
}
return result;
}

original_code:
void world_sync() {
 int i;
 for (i = 1; i <= 2000; i++)
  if (players[i]) {
   update_players(players[i]);
  }
}

variable_types: i int


decompiled_code:
void world_reset()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void world_reset() {
}

canonical_original_code:
void world_reset() {
}


decompiled_code:
__int64 __fastcall init_client(__int64 a1)
{
void *v1; // rax
void *v2; // rax
void *v3; // rax
__int64 result; // rax

*(_DWORD *)a1 = 1;
v1 = malloc(0x20uLL);
*(_QWORD *)(a1 + 24) = v1;
init_buffer(v1);
v2 = malloc(0x20uLL);
*(_QWORD *)(a1 + 32) = v2;
init_buffer(v2);
v3 = malloc(0x18uLL);
*(_QWORD *)(a1 + 56) = v3;
result = init_packet(v3);
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
void *v1; // rax
void *v2; // rax
void *v3; // rax
__int64 result; // rax

*(_DWORD *)a1 = 1;
v1 = malloc(0x20uLL);
*(_QWORD *)(a1 + 24) = v1;
init_buffer(v1);
v2 = malloc(0x20uLL);
*(_QWORD *)(a1 + 32) = v2;
init_buffer(v2);
v3 = malloc(0x18uLL);
*(_QWORD *)(a1 + 56) = v3;
result = init_packet(v3);
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
return result;
}

original_code:
void init_client(struct client *c) {
 c->state = 1;
 c->in_buffer = malloc(sizeof(struct buffer));
 init_buffer(c->in_buffer);
 c->out_buffer = malloc(sizeof(struct buffer));
 init_buffer(c->out_buffer);
 c->packet = malloc(sizeof(struct packet));
 init_packet(c->packet);
 c->in_cipher = 0;
 c->out_cipher = 0;
}


decompiled_code:
void __fastcall free_client(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

*(_DWORD *)ptr = 0;
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free_buffer(*((_QWORD *)ptr + 3));
free_buffer(*((_QWORD *)ptr + 4));
free_packet(*((_QWORD *)ptr + 7));
v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 6);
if ( v3 )
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

*(_DWORD *)ptr = 0;
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free_buffer(*((_QWORD *)ptr + 3));
free_buffer(*((_QWORD *)ptr + 4));
free_packet(*((_QWORD *)ptr + 7));
v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 6);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void free_client(struct client *c) {
 c->state = 0;
 free(c->addr);
 free(c->epollev);
 free_buffer(c->in_buffer);
 free_buffer(c->out_buffer);
 free_packet(c->packet);
 if (c->in_cipher)
  free(c->in_cipher);
 if (c->out_cipher)
  free(c->out_cipher);
 free(c);
}


decompiled_code:
int __fastcall client_send(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rsi
struct epoll_event *v5; // rcx
int v6; // edx

if ( *(int *)(a2 + 20) > 0 )
{
v3 = 0LL;
do
{
v4 = (unsigned int)*(char *)(*(_QWORD *)(a2 + 8) + v3++);
put_byte(*(_QWORD *)(a1 + 32), v4, 0LL);
}
while ( *(_DWORD *)(a2 + 20) > (int)v3 );
}
v5 = *(struct epoll_event **)(a1 + 16);
v6 = *(_DWORD *)(a1 + 4);
v5->events |= 4u;
return epoll_ctl(epfd, 3, v6, v5);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rsi
struct epoll_event *v5; // rcx
int v6; // edx

if ( *(int *)(a2 + 20) > 0 )
{
v3 = 0LL;
do
{
v4 = (unsigned int)*(char *)(*(_QWORD *)(a2 + 8) + v3++);
put_byte(*(_QWORD *)(a1 + 32), v4, 0LL);
}
while ( *(_DWORD *)(a2 + 20) > (int)v3 );
}
v5 = *(struct epoll_event **)(a1 + 16);
v6 = *(_DWORD *)(a1 + 4);
v5->events |= 4u;
return epoll_ctl(epfd, 3, v6, v5);
}

original_code:
void client_send(struct client *c, struct buffer *b) {
 int i;
 for (i = 0; i < b->position; i++)
  put_byte(c->out_buffer, b->data[i], 0);
 c->epollev->events |= EPOLLOUT;
 epoll_ctl(epfd, 3, c->sockfd, c->epollev);
}

variable_types:
b
struct buffer *


decompiled_code:
int __fastcall do_write(__int64 a1)
{
struct epoll_event *v1; // rcx
int v2; // edx

send(*(_DWORD *)(a1 + 4), *(const void **)(*(_QWORD *)(a1 + 32) + 8LL), *(int *)(*(_QWORD *)(a1 + 32) + 20LL), 0);
v1 = *(struct epoll_event **)(a1 + 16);
v2 = *(_DWORD *)(a1 + 4);
*(_DWORD *)(*(_QWORD *)(a1 + 32) + 20LL) = 0;
v1->events &= 0xFFFFFFFB;
return epoll_ctl(epfd, 3, v2, v1);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
struct epoll_event *v1; // rcx
int v2; // edx

send(*(_DWORD *)(a1 + 4), *(const void **)(*(_QWORD *)(a1 + 32) + 8LL), *(int *)(*(_QWORD *)(a1 + 32) + 20LL), 0);
v1 = *(struct epoll_event **)(a1 + 16);
v2 = *(_DWORD *)(a1 + 4);
*(_DWORD *)(*(_QWORD *)(a1 + 32) + 20LL) = 0;
v1->events &= 0xFFFFFFFB;
return epoll_ctl(epfd, 3, v2, v1);
}

original_code:
void do_write(struct client *c) {
 int amtsent = send(c->sockfd, c->out_buffer->data, c->out_buffer->position, 0);
 c->out_buffer->position = 0;
 if (0 == 0) {
  c->epollev->events &= ~EPOLLOUT;
  epoll_ctl(epfd, 3, c->sockfd, c->epollev);
 }
}

variable_types: amtsent int


original_code:
void do_isaac(struct isaac_context *isaac) {
 register uint32_t i, x, y;
 isaac->cc += 1;
 isaac->bb += isaac->cc;
 for (i = 0; i < 256; i++) {
  x = isaac->memory[i];
  switch (i % 4) {
  case 0:
   isaac->aa = isaac->aa ^ (isaac->aa << 13);
   break;
  case 1:
   isaac->aa = isaac->aa ^ (isaac->aa >> 6);
   break;
  case 2:
   isaac->aa = isaac->aa ^ (isaac->aa << 2);
   break;
  case 3:
   isaac->aa = isaac->aa ^ (isaac->aa >> 16);
   break;
  }
  isaac->aa = isaac->memory[(i + 128) % 256] + isaac->aa;
      isaac->memory[i] = y = isaac->memory[(x >> 2) % 256] + isaac->aa + isaac->bb;
      isaac->results->results[i] = isaac->bb = isaac->memory[(y >> 10) % 256] + x;
 }
}

canonical_original_code:
void do_isaac(struct isaac_context *isaac) {
 register unsigned int i; register unsigned int x; register unsigned int y;
 isaac->cc += 1;
 isaac->bb += isaac->cc;
 for (i = 0; i < 256; i++) {
  x = isaac->memory[i];
  switch (i % 4) {
  case 0:
   isaac->aa = isaac->aa ^ (isaac->aa << 13);
   break;
  case 1:
   isaac->aa = isaac->aa ^ (isaac->aa >> 6);
   break;
  case 2:
   isaac->aa = isaac->aa ^ (isaac->aa << 2);
   break;
  case 3:
   isaac->aa = isaac->aa ^ (isaac->aa >> 16);
   break;
  }
  isaac->aa = isaac->memory[(i + 128) % 256] + isaac->aa;
      isaac->memory[i] = y = isaac->memory[(x >> 2) % 256] + isaac->aa + isaac->bb;
      isaac->results->results[i] = isaac->bb = isaac->memory[(y >> 10) % 256] + x;
 }
}

variable_types: struct isaac_context { struct isaac_results { unsigned int *results; unsigned int position; } *results; unsigned int *memory; unsigned int aa; unsigned int bb; unsigned int cc; } *

variable_types:
i
unsigned int

variable_types:
x
unsigned int

variable_types:
y
unsigned int


decompiled_code:
void __fastcall free_isaac(void *ptr)
{
free(*((void **)ptr + 1));
free(**(void ***)ptr);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 1));
free(**(void ***)ptr);
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_isaac(struct isaac_context *isaac) {
 free(isaac->memory);
 free(isaac->results->results);
 free(isaac->results);
 free(isaac);
}


original_code:
int32_t isaac_next_int(struct isaac_context *isaac) {
 if (isaac->results->position-- == 0) {
  do_isaac(isaac);
  isaac->results->position = 255;
 }
 return isaac->results->results[isaac->results->position];
}

canonical_original_code:
int isaac_next_int(struct isaac_context *isaac) {
 if (isaac->results->position-- == 0) {
  do_isaac(isaac);
  isaac->results->position = 255;
 }
 return isaac->results->results[isaac->results->position];
}


decompiled_code:
void __noreturn core_run()
{
struct timeval v0; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

while ( 1 )
{
gettimeofday(&v0, 0LL);
reactor_poll();
world_tick();
world_sync();
world_reset();
gettimeofday(&tv, 0LL);
usleep(
1000
* (600
- (int)((double)(1000 * (LODWORD(tv.tv_sec) - LODWORD(v0.tv_sec)))
+ (double)(LODWORD(tv.tv_usec) - LODWORD(v0.tv_usec)) / 1000.0
+ 0.5)));
}
}

canonical_decompiled_code:
void __noreturn func0()
{
struct timeval v0; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

while ( 1 )
{
gettimeofday(&v0, 0LL);
reactor_poll();
world_tick();
world_sync();
world_reset();
gettimeofday(&tv, 0LL);
usleep(
1000
* (600
- (int)((double)(1000 * (LODWORD(tv.tv_sec) - LODWORD(v0.tv_sec)))
+ (double)(LODWORD(tv.tv_usec) - LODWORD(v0.tv_usec)) / 1000.0
+ 0.5)));
}
}

original_code:
void core_run() {
 struct timeval start, end;
 long mtime, seconds, useconds;
 for (;;) {
  gettimeofday(&start, ((void *)0));
  reactor_poll();
  world_tick();
  world_sync();
  world_reset();
  gettimeofday(&end, ((void *)0));
  seconds = end.tv_sec - start.tv_sec;
  useconds = end.tv_usec - start.tv_usec;
  mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5;
  usleep((600 - mtime) * 1000);
 }
}

canonical_original_code:
void core_run() {
 struct timeval start; struct timeval end;
 long mtime; long seconds; long useconds;
 for (;;) {
  gettimeofday(&start, ((void *)0));
  reactor_poll();
  world_tick();
  world_sync();
  world_reset();
  gettimeofday(&end, ((void *)0));
  seconds = end.tv_sec - start.tv_sec;
  useconds = end.tv_usec - start.tv_usec;
  mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5;
  usleep((600 - mtime) * 1000);
 }
}

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

variable_types: mtime long

variable_types: seconds long

variable_types: useconds long


xgetcwd

repo: HaikuArchives/TraX

decompiled_code:
char *xgetcwd()
{
unsigned int v0; // ebx
int *v1; // rax
int *v2; // r12
__int64 v3; // rax
char *i; // rbp
int v5; // er13
__int64 v6; // rax

v0 = 4098;
v1 = _errno_location();
*v1 = 0;
v2 = v1;
v3 = xmalloc(4098LL);
*v2 = 0;
for ( i = (char *)v3; ; i = (char *)v6 )
{
if ( getcwd(i, v0) )
return i;
v5 = *v2;
if ( *v2 != 34 )
break;
v0 += 32;
v6 = xrealloc(i, v0);
*v2 = 0;
}
free(i);
*v2 = v5;
return 0LL;
}

canonical_decompiled_code:
char *func0()
{
unsigned int v0; // ebx
int *v1; // rax
int *v2; // r12
__int64 v3; // rax
char *i; // rbp
int v5; // er13
__int64 v6; // rax

v0 = 4098;
v1 = _errno_location();
*v1 = 0;
v2 = v1;
v3 = xmalloc(4098LL);
*v2 = 0;
for ( i = (char *)v3; ; i = (char *)v6 )
{
if ( getcwd(i, v0) )
return i;
v5 = *v2;
if ( *v2 != 34 )
break;
v0 += 32;
v6 = xrealloc(i, v0);
*v2 = 0;
}
free(i);
*v2 = v5;
return 0LL;
}

original_code:
char *
xgetcwd ()
{
  char *cwd;
  char *ret;
  unsigned path_max;
  (*__errno_location ()) = 0;
  path_max = (unsigned) 4096;
  path_max += 2;
  cwd = xmalloc (path_max);
  (*__errno_location ()) = 0;
  while ((ret = getcwd (cwd, path_max)) == ((void *)0) && (*__errno_location ()) == 34)
    {
      path_max += 32;
      cwd = xrealloc (cwd, path_max);
      (*__errno_location ()) = 0;
    }
  if (ret == ((void *)0))
    {
      int save_errno = (*__errno_location ());
      free (cwd);
      (*__errno_location ()) = save_errno;
      return ((void *)0);
    }
  return cwd;
}

canonical_original_code:
char *xgetcwd()
{
  char *cwd;
  char *ret;
  unsigned int path_max;
  (*__errno_location ()) = 0;
  path_max = (unsigned int) 4096;
  path_max += 2;
  cwd = xmalloc (path_max);
  (*__errno_location ()) = 0;
  while ((ret = getcwd (cwd, path_max)) == ((void *)0) && (*__errno_location ()) == 34)
    {
      path_max += 32;
      cwd = xrealloc (cwd, path_max);
      (*__errno_location ()) = 0;
    }
  if (ret == ((void *)0))
    {
      int save_errno = (*__errno_location ());
      free (cwd);
      (*__errno_location ()) = save_errno;
      return ((void *)0);
    }
  return cwd;
}

variable_types:
cwd
char *

variable_types:
ret
char *

return_type: char *


error

decompiled_code:
int error(int status, int errnum, char *format, ...)
{
int result; // eax
char *v5; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( error_print_progname )
{
error_print_progname();
}
else
{
fflush(stdout);
fprintf(stderr, "%s: ", program_name);
}
va_start(arg, format);
vfprintf(stderr, format, arg);
if ( errnum )
{
v5 = strerror(errnum);
fprintf(stderr, ": %s", v5);
}
putc(10, stderr);
result = fflush(stderr);
if ( status )
exit(status);
return result;
}

canonical_decompiled_code:
int func0(int status, int errnum, char *format, ...)
{
int result; // eax
char *v5; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( error_print_progname )
{
error_print_progname();
}
else
{
fflush(stdout);
fprintf(stderr, "%s: ", program_name);
}
va_start(arg, format);
vfprintf(stderr, format, arg);
if ( errnum )
{
v5 = strerror(errnum);
fprintf(stderr, ": %s", v5);
}
putc(10, stderr);
result = fflush(stderr);
if ( status )
exit(status);
return result;
}

original_code:
void
error (int status, int errnum, const char *message, ...)
{
  va_list args;
  if (error_print_progname)
    (*error_print_progname) ();
  else
    {
      fflush (stdout);
      fprintf (stderr, "%s: ", program_name);
    }
  __builtin_va_start(args,message);
  vfprintf (stderr, message, args);
  __builtin_va_end(args);
  if (errnum)
    fprintf (stderr, ": %s", strerror (errnum));
  putc ('\n', stderr);
  fflush (stderr);
  if (status)
    exit (status);
}

canonical_original_code:
void error(int status, int errnum, char *message, ...)
{
  __builtin_va_list args;
  if (error_print_progname)
    (*error_print_progname) ();
  else
    {
      fflush (stdout);
      fprintf (stderr, "%s: ", program_name);
    }
  __builtin_va_start(args,message);
  vfprintf (stderr, message, args);
  __builtin_va_end(args);
  if (errnum)
    fprintf (stderr, ": %s", strerror (errnum));
  putc ('\n', stderr);
  fflush (stderr);
  if (status)
    exit (status);
}

variable_types: status int

variable_types: errnum int

variable_types:
message
char *


main

repo: HallowTeam/CLib

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return 0;
}

original_code:
int main(void)
{
 return 0;
}

canonical_original_code:
int main()
{
 return 0;
}


setInt

decompiled_code:
__int64 __fastcall setInt(_DWORD *a1, unsigned int a2)
{
__int64 result; // rax

*a1 = 0;
result = a2;
a1[2] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, unsigned int a2)
{
__int64 result; // rax

*a1 = 0;
result = a2;
a1[2] = a2;
return result;
}

original_code:
int setInt(s_var *var, int value)
{
 var->type = INT;
 var->value._int = value;
 return var->value._int;
}

canonical_original_code:
int setInt(struct s_var *var, int value)
{
 var->type = INT;
 var->value._int = value;
 return var->value._int;
}

variable_types: struct s_var { enum e_var { INT=0, CHAR=1, STR=2, PTR=3 } type; union u_var { int _int; char _char; char *_str; void *_ptr; } value; } *

variable_types: value int

user_defined_types: struct s_var { enum e_var type; union u_var value; }


setStr

decompiled_code:
__int64 __fastcall setStr(__int64 a1, __int64 a2)
{
__int64 result; // rax

*(_DWORD *)a1 = 2;
result = a2;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax

*(_DWORD *)a1 = 2;
result = a2;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
char *setStr(s_var *var, char *value)
{
 var->type = STR;
 var->value._str = value;
 return var->value._str;
}

canonical_original_code:
char *setStr(struct s_var *var, char *value)
{
 var->type = STR;
 var->value._str = value;
 return var->value._str;
}

variable_types:
value
char *

user_defined_types: enum e_var { INT=0, CHAR=1, STR=2, PTR=3 }

user_defined_types: union u_var { int _int; char _char; char *_str; void *_ptr; }


setPtr

decompiled_code:
__int64 __fastcall setPtr(__int64 a1, __int64 a2)
{
__int64 result; // rax

*(_DWORD *)a1 = 3;
result = a2;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax

*(_DWORD *)a1 = 3;
result = a2;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void *setPtr(s_var *var, void *value)
{
 var->type = PTR;
 var->value._ptr = value;
 return var->value._ptr;
}

canonical_original_code:
void *setPtr(struct s_var *var, void *value)
{
 var->type = PTR;
 var->value._ptr = value;
 return var->value._ptr;
}

variable_types:
value
void *


setChar

decompiled_code:
__int64 __fastcall setChar(__int64 a1, unsigned int a2)
{
__int64 result; // rax

*(_DWORD *)a1 = 1;
result = a2;
*(_BYTE *)(a1 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
__int64 result; // rax

*(_DWORD *)a1 = 1;
result = a2;
*(_BYTE *)(a1 + 8) = a2;
return result;
}

original_code:
char setChar(s_var *var, char value)
{
 var->type = CHAR;
 var->value._char = value;
 return var->value._char;
}

canonical_original_code:
char setChar(struct s_var *var, char value)
{
 var->type = CHAR;
 var->value._char = value;
 return var->value._char;
}

variable_types: value char

return_type: char


insertItemBefore

decompiled_code:
__int64 __fastcall insertItemBefore(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rdx

result = getItem(a1, a3);
v4 = *(_QWORD *)(result + 16);
if ( v4 )
*(_QWORD *)(v4 + 8) = a2;
else
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a2 + 16) = v4;
*(_QWORD *)(a2 + 8) = result;
*(_QWORD *)(result + 16) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rdx

result = getItem(a1, a3);
v4 = *(_QWORD *)(result + 16);
if ( v4 )
*(_QWORD *)(v4 + 8) = a2;
else
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a2 + 16) = v4;
*(_QWORD *)(a2 + 8) = result;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
void insertItemBefore(s_list *list, s_item *item, int index)
{
 s_item *pivot = getItem(list, index);
 if (pivot->prev == ((void *)0))
 {
  list->head = item;
 }
 else
 {
  pivot->prev->next = item;
 }
 item->prev = pivot->prev;
 item->next = pivot;
 pivot->prev = item;
}

canonical_original_code:
void insertItemBefore(struct s_list *list, struct s_item *item, int index)
{
 struct s_item *pivot = getItem(list, index);
 if (pivot->prev == ((void *)0))
 {
  list->head = item;
 }
 else
 {
  pivot->prev->next = item;
 }
 item->prev = pivot->prev;
 item->next = pivot;
 pivot->prev = item;
}

variable_types: struct s_list { int len; struct s_item { struct s_var { enum e_var { INT=0, CHAR=1, STR=2, PTR=3 } type; union u_var { int _int; char _char; char *_str; void *_ptr; } value; } *val; struct s_item *next; struct s_item *prev; } *curr; struct s_item *head; struct s_item *tail; } *

variable_types:
item
struct s_item *

variable_types: index int

user_defined_types: struct s_list { int len; struct s_item *curr; struct s_item *head; struct s_item *tail; }

user_defined_types: struct s_item { struct s_var *val; struct s_item *next; struct s_item *prev; }


insertItemAfter

decompiled_code:
__int64 __fastcall insertItemAfter(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 24);
if ( result )
{
*(_QWORD *)(a2 + 16) = result;
*(_QWORD *)(result + 8) = a2;
}
else
{
*(_QWORD *)(a1 + 16) = a2;
}
*(_QWORD *)(a1 + 24) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 24);
if ( result )
{
*(_QWORD *)(a2 + 16) = result;
*(_QWORD *)(result + 8) = a2;
}
else
{
*(_QWORD *)(a1 + 16) = a2;
}
*(_QWORD *)(a1 + 24) = a2;
return result;
}

original_code:
void insertItemAfter(s_list *list, s_item *item)
{
 if (list->tail == ((void *)0))
 {
  list->head = item;
 }
 else
 {
  item->prev = list->tail;
  list->tail->next = item;
 }
 list->tail = item;
}

canonical_original_code:
void insertItemAfter(struct s_list *list, struct s_item *item)
{
 if (list->tail == ((void *)0))
 {
  list->head = item;
 }
 else
 {
  item->prev = list->tail;
  list->tail->next = item;
 }
 list->tail = item;
}


insertItem

decompiled_code:
__int64 __fastcall insertItem(signed int *a1, signed int a2)
{
__int64 v2; // r12

v2 = newItem();
if ( v2 )
{
if ( *a1 && *a1 > a2 )
insertItemBefore((__int64)a1, v2, a2);
else
insertItemAfter((__int64)a1, v2);
++*a1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(signed int *a1, signed int a2)
{
__int64 v2; // r12

v2 = newItem();
if ( v2 )
{
if ( *a1 && *a1 > a2 )
func0((__int64)a1, v2, a2);
else
func1((__int64)a1, v2);
++*a1;
}
return v2;
}

original_code:
s_item *insertItem(s_list *list, int index)
{
 s_item *item = newItem();
 if (item == ((void *)0))
 {
  return ((void *)0);
 }
 if (list->len == 0 || list->len <= index)
 {
  insertItemAfter(list, item);
 }
 else
 {
  insertItemBefore(list, item, index);
 }
 list->len = list->len + 1;
 return item;
}

canonical_original_code:
struct s_item *insertItem(struct s_list *list, int index)
{
 struct s_item *item = newItem();
 if (item == ((void *)0))
 {
  return ((void *)0);
 }
 if (list->len == 0 || list->len <= index)
 {
  insertItemAfter(list, item);
 }
 else
 {
  insertItemBefore(list, item, index);
 }
 list->len = list->len + 1;
 return item;
}

variable_types: struct s_list { int len; struct s_item *curr; struct s_item *head; struct s_item *tail; } *

variable_types: struct s_item { struct s_var { enum e_var { INT=0, CHAR=1, STR=2, PTR=3 } type; union u_var { int _int; char _char; char *_str; void *_ptr; } value; } *val; struct s_item *next; struct s_item *prev; } *


getInt

decompiled_code:
__int64 __fastcall getInt(_DWORD *a1)
{
if ( *a1 )
puts("WARNING: var is not an INT");
return (unsigned int)a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
if ( *a1 )
puts("WARNING: var is not an INT");
return (unsigned int)a1[2];
}

original_code:
int getInt(s_var *var)
{
 if (var->type != INT)
 {
  printf("WARNING: var is not an INT\n");
 }
 return (var->value._int);
}

canonical_original_code:
int getInt(struct s_var *var)
{
 if (var->type != INT)
 {
  printf("WARNING: var is not an INT\n");
 }
 return (var->value._int);
}


getStr

decompiled_code:
__int64 __fastcall getStr(__int64 a1)
{
if ( *(_DWORD *)a1 != 2 )
puts("WARNING: var is not an STR");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( *(_DWORD *)a1 != 2 )
puts("WARNING: var is not an STR");
return *(_QWORD *)(a1 + 8);
}

original_code:
char *getStr(s_var *var)
{
 if (var->type != STR)
 {
  printf("WARNING: var is not an STR\n");
 }
 return (var->value._str);
}

canonical_original_code:
char *getStr(struct s_var *var)
{
 if (var->type != STR)
 {
  printf("WARNING: var is not an STR\n");
 }
 return (var->value._str);
}


getPtr

decompiled_code:
__int64 __fastcall getPtr(__int64 a1)
{
if ( *(_DWORD *)a1 != 3 )
puts("WARNING: var is not a PTR");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( *(_DWORD *)a1 != 3 )
puts("WARNING: var is not a PTR");
return *(_QWORD *)(a1 + 8);
}

original_code:
void *getPtr(s_var *var)
{
 if (var->type != PTR)
 {
  printf("WARNING: var is not a PTR\n");
 }
 return (var->value._ptr);
}

canonical_original_code:
void *getPtr(struct s_var *var)
{
 if (var->type != PTR)
 {
  printf("WARNING: var is not a PTR\n");
 }
 return (var->value._ptr);
}


getChar

decompiled_code:
__int64 __fastcall getChar(__int64 a1)
{
if ( *(_DWORD *)a1 != 1 )
puts("WARNING: var is not a CHAR");
return *(unsigned __int8 *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( *(_DWORD *)a1 != 1 )
puts("WARNING: var is not a CHAR");
return *(unsigned __int8 *)(a1 + 8);
}

original_code:
char getChar(s_var *var)
{
 if (var->type != CHAR)
 {
  printf("WARNING: var is not a CHAR\n");
 }
 return (var->value._char);
}

canonical_original_code:
char getChar(struct s_var *var)
{
 if (var->type != CHAR)
 {
  printf("WARNING: var is not a CHAR\n");
 }
 return (var->value._char);
}


xfree

decompiled_code:
__int64 __fastcall xfree(void *a1)
{
if ( a1 )
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
if ( a1 )
free(a1);
return 0LL;
}

original_code:
void *xfree(void *ptr)
{
 if (ptr != ((void *)0))
 {
  free(ptr);
 }
 return ptr = ((void *)0);
}

variable_types:
ptr
void *


recvTCP

decompiled_code:
__int64 __fastcall recvTCP(int *a1, __int64 *a2)
{
int v2; // er12
__int64 v3; // rbp
int v4; // ebx
__int64 v5; // rax
__int64 v6; // r14
int v7; // eax

v2 = 0;
v3 = 512LL;
v4 = 1;
while ( 1 )
{
++v4;
v5 = xrealloc(*a2, v3);
*a2 = v5;
if ( !v5 )
{
v2 = -1;
xfree(0LL);
return (unsigned int)v2;
}
v6 = v2;
v7 = recv(*a1, (void *)(v5 + v2), 0x1FFuLL, 0);
if ( v7 == -1 )
break;
v2 += v7;
if ( v7 != 511 )
{
v6 = v2;
goto LABEL_11;
}
if ( v4 == 2 )
blockFile((unsigned int)*a1, 1LL);
v3 += 511LL;
}
if ( *_errno_location() != 11 )
{
v2 = -1;
xfree(*a2);
perror("recv()");
return (unsigned int)v2;
}
LABEL_11:
if ( v4 != 2 )
blockFile((unsigned int)*a1, 0LL);
*(_BYTE *)(*a2 + v6) = 0;
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, __int64 *a2)
{
int v2; // er12
__int64 v3; // rbp
int v4; // ebx
__int64 v5; // rax
__int64 v6; // r14
int v7; // eax

v2 = 0;
v3 = 512LL;
v4 = 1;
while ( 1 )
{
++v4;
v5 = xrealloc(*a2, v3);
*a2 = v5;
if ( !v5 )
{
v2 = -1;
xfree(0LL);
return (unsigned int)v2;
}
v6 = v2;
v7 = recv(*a1, (void *)(v5 + v2), 0x1FFuLL, 0);
if ( v7 == -1 )
break;
v2 += v7;
if ( v7 != 511 )
{
v6 = v2;
goto LABEL_11;
}
if ( v4 == 2 )
blockFile((unsigned int)*a1, 1LL);
v3 += 511LL;
}
if ( *_errno_location() != 11 )
{
v2 = -1;
xfree(*a2);
perror("recv()");
return (unsigned int)v2;
}
LABEL_11:
if ( v4 != 2 )
blockFile((unsigned int)*a1, 0LL);
*(_BYTE *)(*a2 + v6) = 0;
return (unsigned int)v2;
}

original_code:
int recvTCP(s_socket *sock, char **message)
{
 int i = 1;
 int len = 0;
 int total = 0;
 do
 {
  if (i == 2)
  {
   blockFile(sock->fd, false);
  }
  if ((*message = xrealloc(*message, (512 - 1) * i++ + 1)) == ((void *)0))
  {
   xfree(*message);
   return -1;
  }
  if ((len = recv(sock->fd, *message + total, 512 - 1, 0)) == -1)
  {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)
   {
    break;
   }
   xfree(*message);
   perror("recv()");
   return -1;
  }
  total += len;
 } while (len == 512 - 1);
 if (i != 2)
 {
  blockFile(sock->fd, true);
 }
 (*message)[total] = '\0';
 return total;
}

canonical_original_code:
int recvTCP(struct s_socket *sock, char **message)
{
 int i = 1;
 int len = 0;
 int total = 0;
 do
 {
  if (i == 2)
  {
   blockFile(sock->fd, false);
  }
  if ((*message = xrealloc(*message, (512 - 1) * i++ + 1)) == ((void *)0))
  {
   xfree(*message);
   return -1;
  }
  if ((len = recv(sock->fd, *message + total, 512 - 1, 0)) == -1)
  {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)
   {
    break;
   }
   xfree(*message);
   perror("recv()");
   return -1;
  }
  total += len;
 } while (len == 512 - 1);
 if (i != 2)
 {
  blockFile(sock->fd, true);
 }
 (*message)[total] = '\0';
 return total;
}

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

variable_types:
message
char **

variable_types: i int

variable_types: len int

variable_types: total int

user_defined_types: struct s_socket { int fd; struct sockaddr_in in; }


sendTCP

decompiled_code:
__int64 __fastcall sendTCP(int *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
if ( send(*a1, a2, v2, 0) != -1 )
return 0LL;
perror("send()");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
if ( send(*a1, a2, v2, 0) != -1 )
return 0LL;
perror("send()");
return 0xFFFFFFFFLL;
}

original_code:
int sendTCP(s_socket *sock, char *message)
{
 if (send(sock->fd, message, strlen(message), 0) == -1)
 {
  perror("send()");
  return -1;
 }
 return 0;
}

canonical_original_code:
int sendTCP(struct s_socket *sock, char *message)
{
 if (send(sock->fd, message, strlen(message), 0) == -1)
 {
  perror("send()");
  return -1;
 }
 return 0;
}

variable_types:
message
char *


printVar

decompiled_code:
int __fastcall printVar(unsigned int *a1)
{
unsigned int v1; // eax
char v2; // al
int result; // eax
const void *v4; // rax
const char *v5; // rax
unsigned int v6; // eax

v1 = *a1;
if ( *a1 == 2 )
{
v5 = (const char *)getStr();
result = printf("STR : %s\n", v5);
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
{
v4 = (const void *)getPtr();
result = printf("PTR : %p\n", v4);
}
else
{
result = puts("UNDEF");
}
}
else if ( v1 )
{
v2 = getChar();
result = printf("CHAR : %c\n", (unsigned int)v2);
}
else
{
v6 = getInt();
result = printf("INT : %d\n", v6);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int *a1)
{
unsigned int v1; // eax
char v2; // al
int result; // eax
const void *v4; // rax
const char *v5; // rax
unsigned int v6; // eax

v1 = *a1;
if ( *a1 == 2 )
{
v5 = (const char *)getStr();
result = printf("STR : %s\n", v5);
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
{
v4 = (const void *)getPtr();
result = printf("PTR : %p\n", v4);
}
else
{
result = puts("UNDEF");
}
}
else if ( v1 )
{
v2 = getChar();
result = printf("CHAR : %c\n", (unsigned int)v2);
}
else
{
v6 = getInt();
result = printf("INT : %d\n", v6);
}
return result;
}

original_code:
void printVar(s_var *var)
{
 switch (var->type)
 {
  case INT : printf("INT : %d\n", getInt(var)); break;
  case STR : printf("STR : %s\n", getStr(var)); break;
  case PTR : printf("PTR : %p\n", getPtr(var)); break;
  case CHAR: printf("CHAR : %c\n", getChar(var)); break;
  default : printf("UNDEF\n") ; break;
 }
}

canonical_original_code:
void printVar(struct s_var *var)
{
 switch (var->type)
 {
  case INT : printf("INT : %d\n", getInt(var)); break;
  case STR : printf("STR : %s\n", getStr(var)); break;
  case PTR : printf("PTR : %p\n", getPtr(var)); break;
  case CHAR: printf("CHAR : %c\n", getChar(var)); break;
  default : printf("UNDEF\n") ; break;
 }
}

variable_types: struct s_var { enum e_var { INT=0, CHAR=1, STR=2, PTR=3 } type; union u_var { int _int; char _char; char *_str; void *_ptr; } value; } *


newTCPClient

decompiled_code:
__int64 __fastcall newTCPClient(char *cp, __int16 a2)
{
__int64 v3; // r12
int v4; // eax
const char *v5; // rdi
__int16 v6; // ax
int v7; // edi
socklen_t v8; // edx

v3 = xmalloc(20LL);
if ( !v3 )
return v3;
v4 = socket(2, 1, 0);
v5 = "socket()";
*(_DWORD *)v3 = v4;
if ( v4 != -1 )
{
*(_DWORD *)(v3 + 8) = inet_addr(cp);
*(_WORD *)(v3 + 4) = 2;
v6 = _bswap_16(a2);
v7 = *(_DWORD *)v3;
*(_WORD *)(v3 + 6) = v6;
if ( connect(v7, (const struct sockaddr *)(v3 + 4), v8) != -1 )
return v3;
v5 = "connect()";
}
perror(v5);
return freeSocket(v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *cp, __int16 a2)
{
__int64 v3; // r12
int v4; // eax
const char *v5; // rdi
__int16 v6; // ax
int v7; // edi
socklen_t v8; // edx

v3 = xmalloc(20LL);
if ( !v3 )
return v3;
v4 = socket(2, 1, 0);
v5 = "socket()";
*(_DWORD *)v3 = v4;
if ( v4 != -1 )
{
*(_DWORD *)(v3 + 8) = inet_addr(cp);
*(_WORD *)(v3 + 4) = 2;
v6 = func0(a2);
v7 = *(_DWORD *)v3;
*(_WORD *)(v3 + 6) = v6;
if ( connect(v7, (const struct sockaddr *)(v3 + 4), v8) != -1 )
return v3;
v5 = "connect()";
}
perror(v5);
return freeSocket(v3);
}

original_code:
s_socket *newTCPClient(char *server, int port)
{
 s_socket *sock;
 if ((sock = xmalloc(sizeof(*sock))) == ((void *)0))
 {
  return ((void *)0);
 }
 if ((sock->fd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket()");
  return freeSocket(sock);
 }
 sock->in.sin_addr.s_addr = inet_addr(server);
 sock->in.sin_family = 2;
 sock->in.sin_port = htons(port);
 if (connect(sock->fd, (SOCKADDR *)&(sock->in), sizeof(sock->in)) == -1)
 {
  perror("connect()");
  return freeSocket(sock);
 }
 return sock;
}

canonical_original_code:
struct s_socket *newTCPClient(char *server, int port)
{
 struct s_socket *sock;
 if ((sock = xmalloc(sizeof(*sock))) == ((void *)0))
 {
  return ((void *)0);
 }
 if ((sock->fd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket()");
  return freeSocket(sock);
 }
 sock->in.sin_addr.s_addr = inet_addr(server);
 sock->in.sin_family = 2;
 sock->in.sin_port = htons(port);
 if (connect(sock->fd, (struct sockaddr *)&(sock->in), sizeof(sock->in)) == -1)
 {
  perror("connect()");
  return freeSocket(sock);
 }
 return sock;
}

variable_types:
server
char *

variable_types: port int

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


newTCPServer

decompiled_code:
__int64 __fastcall newTCPServer(unsigned __int16 a1)
{
__int64 v1; // r12
int v2; // eax
__int16 v3; // ax
int v4; // edi
socklen_t v5; // edx
__int64 result; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v1 = xmalloc(20LL);
if ( !v1 )
return v1;
v2 = socket(2, 1, 0);
*(_DWORD *)v1 = v2;
if ( v2 == -1 )
{
perror("socket()");
result = freeSocket(v1);
}
else
{
setsockopt(v2, 1, 2, optval, 4u);
*(_DWORD *)(v1 + 8) = _bswap_32_constprop_0(a1, v1 + 4, 16LL);
*(_WORD *)(v1 + 4) = 2;
v3 = _bswap_16(a1);
v4 = *(_DWORD *)v1;
*(_WORD *)(v1 + 6) = v3;
if ( bind(v4, (const struct sockaddr *)(v1 + 4), v5) != -1 )
{
if ( listen(*(_DWORD *)v1, 5) == -1 )
{
perror("listen()");
v1 = freeSocket(v1);
}
return v1;
}
perror("bind()");
result = freeSocket(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1)
{
__int64 v1; // r12
int v2; // eax
__int16 v3; // ax
int v4; // edi
socklen_t v5; // edx
__int64 result; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v1 = xmalloc(20LL);
if ( !v1 )
return v1;
v2 = socket(2, 1, 0);
*(_DWORD *)v1 = v2;
if ( v2 == -1 )
{
perror("socket()");
result = freeSocket(v1);
}
else
{
setsockopt(v2, 1, 2, optval, 4u);
*(_DWORD *)(v1 + 8) = func1(a1, v1 + 4, 16LL);
*(_WORD *)(v1 + 4) = 2;
v3 = func0(a1);
v4 = *(_DWORD *)v1;
*(_WORD *)(v1 + 6) = v3;
if ( bind(v4, (const struct sockaddr *)(v1 + 4), v5) != -1 )
{
if ( listen(*(_DWORD *)v1, 5) == -1 )
{
perror("listen()");
v1 = freeSocket(v1);
}
return v1;
}
perror("bind()");
result = freeSocket(v1);
}
return result;
}

original_code:
s_socket *newTCPServer(int port)
{
 int reuse = 1;
 s_socket *sock;
 if ((sock = xmalloc(sizeof(*sock))) == ((void *)0))
 {
  return ((void *)0);
 }
 if ((sock->fd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket()");
  return freeSocket(sock);
 }
 setsockopt(sock->fd, 1, 2, &reuse, sizeof(reuse));
 sock->in.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 sock->in.sin_family = 2;
 sock->in.sin_port = htons(port);
 if (bind(sock->fd, (SOCKADDR *)&(sock->in), sizeof(sock->in)) == -1)
 {
  perror("bind()");
  return freeSocket(sock);
 }
 if (listen(sock->fd, 5) == -1)
 {
  perror("listen()");
  return freeSocket(sock);
 }
 return sock;
}

canonical_original_code:
struct s_socket *newTCPServer(int port)
{
 int reuse = 1;
 struct s_socket *sock;
 if ((sock = xmalloc(sizeof(*sock))) == ((void *)0))
 {
  return ((void *)0);
 }
 if ((sock->fd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket()");
  return freeSocket(sock);
 }
 setsockopt(sock->fd, 1, 2, &reuse, sizeof(reuse));
 sock->in.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 sock->in.sin_family = 2;
 sock->in.sin_port = htons(port);
 if (bind(sock->fd, (struct sockaddr *)&(sock->in), sizeof(sock->in)) == -1)
 {
  perror("bind()");
  return freeSocket(sock);
 }
 if (listen(sock->fd, 5) == -1)
 {
  perror("listen()");
  return freeSocket(sock);
 }
 return sock;
}

variable_types: reuse int


nextItem

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

v1 = *(_QWORD *)(a1 + 8);
if ( v1 && (result = *(_QWORD *)(v1 + 8)) != 0 )
{
*(_QWORD *)(a1 + 8) = result;
}
else
{
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

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

v1 = *(_QWORD *)(a1 + 8);
if ( v1 && (result = *(_QWORD *)(v1 + 8)) != 0 )
{
*(_QWORD *)(a1 + 8) = result;
}
else
{
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

original_code:
s_item *nextItem(s_list *list)
{
 if (list->curr == ((void *)0) || list->curr->next == ((void *)0))
 {
  return list->curr = list->head;
 }
 return list->curr = list->curr->next;
}

canonical_original_code:
struct s_item *nextItem(struct s_list *list)
{
 if (list->curr == ((void *)0) || list->curr->next == ((void *)0))
 {
  return list->curr = list->head;
 }
 return list->curr = list->curr->next;
}

return_type: struct s_item { struct s_var { enum e_var { INT=0, CHAR=1, STR=2, PTR=3 } type; union u_var { int _int; char _char; char *_str; void *_ptr; } value; } *val; struct s_item *next; struct s_item *prev; } *


prevItem

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

v1 = *(_QWORD *)(a1 + 8);
if ( v1 && (result = *(_QWORD *)(v1 + 16)) != 0 )
{
*(_QWORD *)(a1 + 8) = result;
}
else
{
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

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

v1 = *(_QWORD *)(a1 + 8);
if ( v1 && (result = *(_QWORD *)(v1 + 16)) != 0 )
{
*(_QWORD *)(a1 + 8) = result;
}
else
{
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

original_code:
s_item *prevItem(s_list *list)
{
 if (list->curr == ((void *)0) || list->curr->prev == ((void *)0))
 {
  return list->curr = list->tail;
 }
 return list->curr = list->curr->prev;
}

canonical_original_code:
struct s_item *prevItem(struct s_list *list)
{
 if (list->curr == ((void *)0) || list->curr->prev == ((void *)0))
 {
  return list->curr = list->tail;
 }
 return list->curr = list->curr->prev;
}


serverAccept

decompiled_code:
int *__fastcall serverAccept(__int64 a1)
{
int *v2; // r12
int v3; // edi
int v4; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = (int *)xmalloc(20LL);
if ( v2 )
{
v3 = *(_DWORD *)a1;
addr_len[0] = 16;
v4 = accept(v3, (struct sockaddr *)(a1 + 4), addr_len);
*v2 = v4;
if ( v4 == -1 )
{
perror("accept()");
v2 = (int *)freeSocket(v2);
}
}
return v2;
}

canonical_decompiled_code:
int *__fastcall func0(__int64 a1)
{
int *v2; // r12
int v3; // edi
int v4; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = (int *)xmalloc(20LL);
if ( v2 )
{
v3 = *(_DWORD *)a1;
addr_len[0] = 16;
v4 = accept(v3, (struct sockaddr *)(a1 + 4), addr_len);
*v2 = v4;
if ( v4 == -1 )
{
perror("accept()");
v2 = (int *)freeSocket(v2);
}
}
return v2;
}

original_code:
s_socket *serverAccept(s_socket *server)
{
 int sinsize;
 s_socket *client;
 if ((client = xmalloc(sizeof(*client))) == ((void *)0))
 {
  return ((void *)0);
 }
 sinsize = sizeof(server->in);
 if ((client->fd = accept(server->fd, (SOCKADDR *)&(server->in), (socklen_t *)&sinsize)) == -1)
 {
  perror("accept()");
  return freeSocket(client);
 }
 return client;
}

canonical_original_code:
struct s_socket *serverAccept(struct s_socket *server)
{
 int sinsize;
 struct s_socket *client;
 if ((client = xmalloc(sizeof(*client))) == ((void *)0))
 {
  return ((void *)0);
 }
 sinsize = sizeof(server->in);
 if ((client->fd = accept(server->fd, (struct sockaddr *)&(server->in), (unsigned int *)&sinsize)) == -1)
 {
  perror("accept()");
  return freeSocket(client);
 }
 return client;
}

variable_types:
server
struct s_socket *

variable_types: sinsize int