main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax
__int64 v5; // rbx
double v6; // xmm0_8
unsigned int v7; // edi
__int64 v8; // rbx
pthread_t *v9; // rbp
unsigned int v10; // eax
unsigned int v11; // eax
pthread_t *v12; // r12
__int64 v13; // rbx
unsigned int v14; // eax
__int64 v15; // rbx
unsigned int v16; // eax
unsigned int v17; // eax
double v18; // rbx
double v20; // [rsp+8h] [rbp-90h]
struct timezone tz; // [rsp+18h] [rbp-80h] BYREF
struct timeval tv; // [rsp+20h] [rbp-78h] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-68h] BYREF

printf("\n\t\t--------------------------------------------------------------------------");
printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
printf("\n\t\t C-DAC Multi Core Benchmark Suite 1.0");
printf("\n\t\t Email : RarchK");
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Objective : Sorting Single Dimension Array (Integer Operations)\n ");
printf("\n\t\t Performance of Sorting a Minimum value in a large Single Dimension Array ");
puts("\n\t\t on Multi Socket Multi Core Processor using 1/2/4/8 threads ");
puts("\n\t\t..........................................................................");
if ( argc != 3 )
{
printf("\t\t Very Few Arguments\n ");
puts("\t\t Syntax : exec <Class-Size> <Threads>");
exit(-1);
}
v3 = argv[1];
v4 = atoi(argv[2]);
if ( !strcmp(v3, "A") )
CLASS_SIZE = 10000000LL;
if ( !strcmp(v3, "B") )
CLASS_SIZE = 100000000LL;
if ( !strcmp(v3, "C") )
CLASS_SIZE = 1000000000LL;
NumElements = CLASS_SIZE;
NumThreads = v4;
printf("\n\t\t Array Size : %ld", CLASS_SIZE);
printf("\n\t\t Threads : %d", (unsigned int)NumThreads);
putchar(10);
if ( NumThreads <= 0 )
{
puts("\n Number of threads must be greater than zero. Aborting ...");
}
else if ( ((NumThreads - 4) & 0xFFFFFFFB) != 0 && (unsigned int)(NumThreads - 1) > 1 )
{
puts("\n Number of Threads must be 1 or 2 or 4 or 8. Aborting ...");
}
else if ( NumElements % NumThreads )
{
puts("\n Number of threads not a factor of Integer List size. Aborting.");
}
else
{
partial_list_size = NumElements / NumThreads;
v5 = 8 * NumElements;
list = malloc(8 * NumElements);
if ( v5 < 0 )
v6 = (double)(int)((unsigned __int64)v5 >> 1) + (double)(int)((unsigned __int64)v5 >> 1);
else
v6 = (double)(int)v5;
gettimeofday(&tv, &tz);
v20 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
v7 = NumElements;
if ( NumElements > 0 )
{
v8 = 0LL;
do
{
srand48(v7);
*((_QWORD *)list + v8) = (unsigned int)(int)((double)(rand() % 1000) + 1.0);
v7 = NumElements;
++v8;
}
while ( NumElements > v8 );
}
v9 = (pthread_t *)malloc(8LL * NumThreads);
minimum_value = *(_QWORD *)list;
v10 = pthread_mutex_init(&minimum_value_lock, 0LL);
if ( v10 )
{
printf("\n ERROR : Return code from pthread_mutex_init() is %d ", v10);
exit(-1);
}
v11 = pthread_attr_init(&attr);
if ( v11 )
{
printf("\n ERROR : Return code from pthread_attr_init() is %d ", v11);
exit(-1);
}
pthread_attr_setscope(&attr, 0);
v12 = v9;
v13 = 0LL;
while ( NumThreads > (int)v13 )
{
v14 = pthread_create(v12++, &attr, (void *(*)(void *))find_min, (void *)++v13);
if ( v14 )
{
printf("\n ERROR : Return code from pthread_create() is %d ", v14);
exit(-1);
}
}
if ( NumThreads > 0 )
{
v15 = 0LL;
do
{
v16 = pthread_join(v9[v15], 0LL);
if ( v16 )
{
printf("\n ERROR : Return code from pthread_join() is %d ", v16);
exit(-1);
}
++v15;
}
while ( NumThreads > (int)v15 );
}
v17 = pthread_attr_destroy(&attr);
if ( v17 )
{
printf("\n ERROR : Return code from pthread_attr_destroy() is %d ", v17);
exit(-1);
}
gettimeofday(&tv, &tz);
v18 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
printf("\n\t\t Minimum Value found in the Integer list : %d", (unsigned int)minimum_value);
printf("\n\t\t Memory Utilised : %lf MB", (v6 + 0.0) * 0.00000095367431640625);
printf("\n\t\t Time Taken in Seconds (T) : %lf Seconds", v18 - v20);
puts("\n\t\t..........................................................................");
free(list);
free(v9);
}
return 0;
}

original_code:
int main (int argc,char * argv[])
{
        pthread_t *threads;
        pthread_attr_t pta;
        int iteration,THREADS,ret_count;
        double time_start, time_end;
        struct timeval tv;
        struct timezone tz;
        double MemoryUsed = 0.0;
 char * CLASS;
        int counter;
        printf("\n\t\t--------------------------------------------------------------------------");
        printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
        printf("\n\t\t C-DAC Multi Core Benchmark Suite 1.0");
        printf("\n\t\t Email : RarchK");
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Objective : Sorting Single Dimension Array (Integer Operations)\n ");
        printf("\n\t\t Performance of Sorting a Minimum value in a large Single Dimension Array ");
        printf("\n\t\t on Multi Socket Multi Core Processor using 1/2/4/8 threads \n");
        printf("\n\t\t..........................................................................\n");
         if( argc != 3 ){
            printf("\t\t Very Few Arguments\n ");
            printf("\t\t Syntax : exec <Class-Size> <Threads>\n");
            exit(-1);
         }
         else {
            CLASS = argv[1];
            THREADS = atoi(argv[2]);
         }
         if( strcmp(CLASS, "A" )==0){
            CLASS_SIZE = 10000000;
         }
         if( strcmp(CLASS, "B" )==0){
            CLASS_SIZE = 100000000;
         }
        if( strcmp(CLASS, "C" )==0){
            CLASS_SIZE = 1000000000;
        }
        NumElements = CLASS_SIZE;
        NumThreads = THREADS;
        printf("\n\t\t Array Size  :  %ld",NumElements);
        printf("\n\t\t Threads     :  %d",NumThreads);
        printf("\n");
        if (NumThreads < 1 )
        {
           printf("\n Number of threads must be greater than zero. Aborting ...\n");
           return 0;
        }
        if ((NumThreads != 1) && (NumThreads != 2) && (NumThreads != 4) && (NumThreads != 8))
        {
           printf("\n Number of Threads must be 1 or 2 or 4 or 8. Aborting ...\n");
           return 0;
        }
        if ( ( NumElements % NumThreads ) != 0 )
        {
           printf("\n Number of threads not a factor of Integer List size. Aborting.\n");
     return 0 ;
        }
        partial_list_size = NumElements / NumThreads;
        list = (long int *)malloc(sizeof(long int) * NumElements);
        MemoryUsed += ( NumElements * sizeof(long int));
        gettimeofday(&tv, &tz);
        time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
        for(counter = 0 ; counter < NumElements ; counter++){
            srand48((unsigned int)NumElements);
            list[counter] = (rand()%1000)+1.0;
        }
        threads = (pthread_t *)malloc(sizeof(pthread_t)*NumThreads);
        minimum_value = list[0];
        ret_count=pthread_mutex_init(&minimum_value_lock, ((void *)0));
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_mutex_init() is %d ",ret_count);
  exit(-1);
     }
        ret_count=pthread_attr_init(&pta);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_init() is %d ",ret_count);
  exit(-1);
     }
        pthread_attr_setscope(&pta,PTHREAD_SCOPE_SYSTEM);
        for(counter = 0 ; counter < NumThreads ; counter++)
 {
           ret_count=pthread_create(&threads[counter],&pta,(void *(*) (void *)) find_min,(void *) (counter+1));
        if(ret_count)
        {
  printf("\n ERROR : Return code from pthread_create() is %d ",ret_count);
  exit(-1);
        }
 }
        for(counter = 0 ; counter < NumThreads ; counter++)
 {
           ret_count=pthread_join(threads[counter],((void *)0));
        if(ret_count)
        {
  printf("\n ERROR : Return code from pthread_join() is %d ",ret_count);
  exit(-1);
        }
        }
        ret_count=pthread_attr_destroy(&pta);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_destroy() is %d ",ret_count);
  exit(-1);
     }
        gettimeofday(&tv, &tz);
        time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
        printf("\n\t\t Minimum Value found in the Integer list     :  %d",minimum_value);
        printf("\n\t\t Memory Utilised                             :  %lf MB",(MemoryUsed / (1024*1024)));
        printf("\n\t\t Time Taken in Seconds  (T)                  :  %lf Seconds",( time_end - time_start));
        printf("\n\t\t..........................................................................\n");
        free(list);
        free(threads);
        return 0;
 }

canonical_original_code:
int main(int argc, char *argv[])
{
        unsigned long *threads;
        union pthread_attr_t pta;
        int iteration; int THREADS; int ret_count;
        double time_start; double time_end;
        struct timeval tv;
        struct timezone tz;
        double MemoryUsed = 0.0;
 char *CLASS;
        int counter;
        printf("\n\t\t--------------------------------------------------------------------------");
        printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
        printf("\n\t\t C-DAC Multi Core Benchmark Suite 1.0");
        printf("\n\t\t Email : RarchK");
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Objective : Sorting Single Dimension Array (Integer Operations)\n ");
        printf("\n\t\t Performance of Sorting a Minimum value in a large Single Dimension Array ");
        printf("\n\t\t on Multi Socket Multi Core Processor using 1/2/4/8 threads \n");
        printf("\n\t\t..........................................................................\n");
         if( argc != 3 ){
            printf("\t\t Very Few Arguments\n ");
            printf("\t\t Syntax : exec <Class-Size> <Threads>\n");
            exit(-1);
         }
         else {
            CLASS = argv[1];
            THREADS = atoi(argv[2]);
         }
         if( strcmp(CLASS, "A" )==0){
            CLASS_SIZE = 10000000;
         }
         if( strcmp(CLASS, "B" )==0){
            CLASS_SIZE = 100000000;
         }
        if( strcmp(CLASS, "C" )==0){
            CLASS_SIZE = 1000000000;
        }
        NumElements = CLASS_SIZE;
        NumThreads = THREADS;
        printf("\n\t\t Array Size  :  %ld",NumElements);
        printf("\n\t\t Threads     :  %d",NumThreads);
        printf("\n");
        if (NumThreads < 1 )
        {
           printf("\n Number of threads must be greater than zero. Aborting ...\n");
           return 0;
        }
        if ((NumThreads != 1) && (NumThreads != 2) && (NumThreads != 4) && (NumThreads != 8))
        {
           printf("\n Number of Threads must be 1 or 2 or 4 or 8. Aborting ...\n");
           return 0;
        }
        if ( ( NumElements % NumThreads ) != 0 )
        {
           printf("\n Number of threads not a factor of Integer List size. Aborting.\n");
     return 0 ;
        }
        partial_list_size = NumElements / NumThreads;
        list = (long *)malloc(sizeof(long) * NumElements);
        MemoryUsed += ( NumElements * sizeof(long));
        gettimeofday(&tv, &tz);
        time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
        for(counter = 0 ; counter < NumElements ; counter++){
            srand48((unsigned int)NumElements);
            list[counter] = (rand()%1000)+1.0;
        }
        threads = (unsigned long *)malloc(sizeof(pthread_t)*NumThreads);
        minimum_value = list[0];
        ret_count=pthread_mutex_init(&minimum_value_lock, ((void *)0));
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_mutex_init() is %d ",ret_count);
  exit(-1);
     }
        ret_count=pthread_attr_init(&pta);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_init() is %d ",ret_count);
  exit(-1);
     }
        pthread_attr_setscope(&pta,PTHREAD_SCOPE_SYSTEM);
        for(counter = 0 ; counter < NumThreads ; counter++)
 {
           ret_count=pthread_create(&threads[counter],&pta,(void *(*)(void *)) find_min,(void *) (counter+1));
        if(ret_count)
        {
  printf("\n ERROR : Return code from pthread_create() is %d ",ret_count);
  exit(-1);
        }
 }
        for(counter = 0 ; counter < NumThreads ; counter++)
 {
           ret_count=pthread_join(threads[counter],((void *)0));
        if(ret_count)
        {
  printf("\n ERROR : Return code from pthread_join() is %d ",ret_count);
  exit(-1);
        }
        }
        ret_count=pthread_attr_destroy(&pta);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_destroy() is %d ",ret_count);
  exit(-1);
     }
        gettimeofday(&tv, &tz);
        time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
        printf("\n\t\t Minimum Value found in the Integer list     :  %d",minimum_value);
        printf("\n\t\t Memory Utilised                             :  %lf MB",(MemoryUsed / (1024*1024)));
        printf("\n\t\t Time Taken in Seconds  (T)                  :  %lf Seconds",( time_end - time_start));
        printf("\n\t\t..........................................................................\n");
        free(list);
        free(threads);
        return 0;
 }

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
threads
unsigned long *

variable_types: iteration int

variable_types: THREADS int

variable_types: MemoryUsed double

variable_types:
CLASS
char *

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

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

user_defined_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


repo: HPC-Sect/ZeroSample

decompiled_code:
void *queue_init()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
void *result; // rax

v0 = malloc(0x20uLL);
q = (__int64)v0;
v1 = malloc(0x10uLL);
v0[1] = v1;
v1[1] = 0LL;
v0[2] = v1;
result = malloc(0x28uLL);
v0[3] = result;
*(_DWORD *)v0 = 0;
return result;
}

canonical_decompiled_code:
void *func7()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
void *result; // rax

v0 = malloc(0x20uLL);
q = (__int64)v0;
v1 = malloc(0x10uLL);
v0[1] = v1;
v1[1] = 0LL;
v0[2] = v1;
result = malloc(0x28uLL);
v0[3] = result;
*(_DWORD *)v0 = 0;
return result;
}

original_code:
void
queue_init ()
{
  q = (queue *) malloc (sizeof (queue));
  q->front = (struct node *) malloc (sizeof (struct node));
  q->front->next = ((void *)0);
  q->rear = q->front;
  q->mutex = (pthread_mutex_t *) malloc (sizeof (pthread_mutex_t));
  q->contains = 0;
  return;
}

canonical_original_code:
void queue_init()
{
  q = (struct queue *) malloc (sizeof (queue));
  q->front = (struct node *) malloc (sizeof (struct node));
  q->front->next = ((void *)0);
  q->rear = q->front;
  q->mutex = (union pthread_mutex_t *) malloc (sizeof (pthread_mutex_t));
  q->contains = 0;
  return;
}

return_type: void

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

user_defined_types: struct queue { int contains; struct node *front; struct node *rear; union pthread_mutex_t *mutex; union pthread_cond_t *queue_full; union pthread_cond_t *queue_empty; }

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

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

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

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }


dequeue

decompiled_code:
double dequeue()
{
_DWORD *v0; // rax
int *v1; // rdi
double v3; // [rsp+8h] [rbp-10h]

v0 = (_DWORD *)q;
v1 = *(int **)(q + 8);
*(_QWORD *)(q + 8) = *((_QWORD *)v1 + 1);
v3 = (double)*v1;
--*v0;
free(v1);
return v3;
}

original_code:
double
dequeue ()
{
  struct node *tmp = q->front;
  q->front = q->front->next;
  double retval = tmp->data;
  q->contains--;
  free (tmp);
  return retval;
}

canonical_original_code:
double dequeue()
{
  struct node *tmp = q->front;
  q->front = q->front->next;
  double retval = tmp->data;
  q->contains--;
  free (tmp);
  return retval;
}

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

variable_types: retval double

return_type: double


BusyWork

decompiled_code:
void __fastcall __noreturn BusyWork(void *a1)
{
int v1; // ebx
double v2; // xmm0_8
double v3; // [rsp+8h] [rbp-10h]

v1 = 1000000;
v3 = 0.0;
do
{
v2 = (double)(int)random() + v3;
v3 = v2;
--v1;
}
while ( v1 );
printf("result = %e\n", v2);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebx
double v2; // xmm0_8
double v3; // [rsp+8h] [rbp-10h]

v1 = 1000000;
v3 = 0.0;
do
{
v2 = (double)(int)random() + v3;
v3 = v2;
--v1;
}
while ( v1 );
printf("result = %e\n", v2);
pthread_exit(0LL);
}

original_code:
void *BusyWork(void *null)
{
   int i;
   double result=0.0;
   for (i=0; i<1000000; i++)
   {
     result = result + (double)random();
   }
   printf("result = %e\n",result);
   pthread_exit((void *) 0);
}

canonical_original_code:
void *BusyWork(void *null)
{
   int i;
   double result = 0.0;
   for (i=0; i<1000000; i++)
   {
     result = result + (double)random();
   }
   printf("result = %e\n",result);
   pthread_exit((void *) 0);
}

variable_types: i int

variable_types: result double

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbp
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // eax
__int64 v7; // rbx
void *thread_return[8]; // [rsp+Ch] [rbp-7Ch] BYREF
pthread_t newthread[7]; // [rsp+50h] [rbp-38h] 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 illustrate thread join operation\n ");
puts("\n\t\t..........................................................................");
pthread_attr_init((pthread_attr_t *)((char *)thread_return + 4));
pthread_attr_setdetachstate((pthread_attr_t *)((char *)thread_return + 4), 0);
v3 = newthread;
v4 = 0;
while ( 1 )
{
printf("Creating thread %d\n", v4);
v5 = pthread_create(v3, (const pthread_attr_t *)((char *)thread_return + 4), (void *(*)(void *))BusyWork, 0LL);
if ( v5 )
break;
++v4;
++v3;
if ( v4 == 4 )
{
v6 = pthread_attr_destroy((pthread_attr_t *)((char *)thread_return + 4));
v7 = 0LL;
if ( !v6 )
{
do
{
pthread_join(newthread[v7], thread_return);
printf("Completed join with thread %d status= %d\n", (unsigned int)v7++, LODWORD(thread_return[0]));
}
while ( v7 != 4 );
pthread_exit(0LL);
}
printf("ERROR; return code from pthread_attr_destroy() is %d\n", v6);
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

return_type: int


dotprod

decompiled_code:
void __fastcall __noreturn dotprod(void *a1)
{
int v1; // eax
double v2; // [rsp+8h] [rbp-10h]

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
{
v2 = *(double *)(dotstr + 8LL * (_QWORD)a1) * *(double *)(qword_404128 + 8LL * (_QWORD)a1) + v2;
a1 = (char *)a1 + 1;
}
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; // [rsp+8h] [rbp-10h]

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
{
v2 = *(double *)(dotstr + 8LL * (_QWORD)a1) * *(double *)(qword_404128 + 8LL * (_QWORD)a1) + v2;
a1 = (char *)a1 + 1;
}
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: 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 *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v4; // rbx
__int64 i; // rax
unsigned int v6; // eax
unsigned int v7; // eax
pthread_t *v8; // r13
char *v9; // r12
unsigned int v10; // eax
unsigned int v11; // eax
__int64 v12; // r12
unsigned int v13; // eax
pthread_attr_t v14; // [rsp+0h] [rbp-68h] BYREF
void *thread_return; // [rsp+3Ch] [rbp-2Ch] 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(&v14);
if ( v7 )
{
printf("ERROR; return code from pthread_attr_init() is %d\n", v7);
exit(-1);
}
pthread_attr_setdetachstate(&v14, 0);
v8 = &callThd;
v9 = 0LL;
while ( 1 )
{
v10 = pthread_create(v8, &v14, (void *(*)(void *))dotprod, v9);
if ( v10 )
break;
++v9;
++v8;
if ( v9 == (char *)4 )
{
v11 = pthread_attr_destroy(&v14);
v12 = 0LL;
if ( !v11 )
{
do
pthread_join(*(&callThd + v12++), &thread_return);
while ( v12 != 4 );
printf("Sum = %f \n", *(double *)&qword_404130);
free(v3);
free(v4);
v13 = pthread_mutex_destroy(&mutexsum);
if ( v13 )
{
printf("ERROR; return code from pthread_mutex_destroy() is %d\n", v13);
exit(-1);
}
pthread_exit(0LL);
}
printf("\n ERROR : return code from pthread_attr_destroy() is %d\n", v11);
exit(-1);
}
}
printf("ERROR; return code from pthread_create() is %d\n", v10);
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 *


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

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

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

v1 = 10;
while ( 1 )
{
pthread_mutex_lock(&count_mutex);
if ( ++count == 12 )
{
pthread_cond_signal(&count_threshold_cv);
printf("inc_count(): thread %d, count = %d Threshold reached.\n", *(unsigned int *)a1, (unsigned int)count);
}
printf("inc_count(): thread %d, count = %d, unlocking mutex\n", *(unsigned int *)a1, (unsigned int)count);
pthread_mutex_unlock(&count_mutex);
v2 = 1000;
do
{
random();
--v2;
}
while ( v2 );
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: i 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
unsigned int v6; // eax
unsigned int v7; // eax
pthread_t *v8; // rbx
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
pthread_attr_t v12; // [rsp+0h] [rbp-78h] BYREF
pthread_t newthread; // [rsp+40h] [rbp-38h] BYREF
pthread_t v14; // [rsp+48h] [rbp-30h] BYREF
pthread_t v15; // [rsp+50h] [rbp-28h] BYREF
char v16; // [rsp+58h] [rbp-20h] 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(&v12);
if ( v4 )
{
printf("ERROR; return code from pthread_attr_init() is %d\n", v4);
exit(-1);
}
pthread_attr_setdetachstate(&v12, 0);
v5 = pthread_create(&newthread, &v12, (void *(*)(void *))inc_count, &thread_ids);
if ( v5 )
{
printf("ERROR; return code from pthread_create() is %d\n", v5);
exit(-1);
}
v6 = pthread_create(&v14, &v12, (void *(*)(void *))inc_count, &unk_4040B4);
if ( v6 )
{
printf("ERROR; return code from pthread_create() is %d\n", v6);
exit(-1);
}
v7 = pthread_create(&v15, &v12, (void *(*)(void *))watch_count, &unk_4040B8);
if ( !v7 )
{
v8 = &newthread;
while ( 1 )
{
v9 = pthread_join(*v8, 0LL);
if ( v9 )
break;
if ( ++v8 == (pthread_t *)&v16 )
{
printf("Main(): Waited on %d threads. Done.\n", 3LL);
v10 = pthread_attr_destroy(&v12);
if ( v10 )
{
printf("ERROR; return code from pthread_attr_destroy() is %d\n", v10);
exit(-1);
}
v11 = pthread_mutex_destroy(&count_mutex);
if ( v11 )
{
printf("ERROR; return code from pthread_mutex_destroy() is %d\n", v11);
exit(-1);
}
pthread_cond_destroy(&count_threshold_cv);
pthread_exit(0LL);
}
}
printf("ERROR; return code from pthread_join() is %d\n", v9);
exit(-1);
}
printf("ERROR; return code from pthread_create() is %d\n", v7);
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
double **v3; // rsi
double **v4; // r8
double *v5; // rax
int v6; // edx

v2 = dist_row * ((_DWORD)a1 - 1);
if ( v2 < v2 + dist_row )
{
v3 = (double **)((char *)InMat + 8 * v2);
v4 = (double **)((char *)InMat + 8 * v2 + 8 * (unsigned __int64)(unsigned int)(dist_row - 1) + 8);
do
{
v6 = 0;
if ( col > 0 )
{
v5 = *v3;
v6 = 0;
do
v6 = (int)((double)v6 + *v5++);
while ( v5 != &(*v3)[(unsigned int)(col - 1) + 1] );
}
if ( v1 < v6 )
v1 = v6;
++v3;
}
while ( v3 != 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
double **v3; // rsi
double **v4; // r8
double *v5; // rax
int v6; // edx

v2 = dist_row * ((_DWORD)a1 - 1);
if ( v2 < v2 + dist_row )
{
v3 = (double **)((char *)InMat + 8 * v2);
v4 = (double **)((char *)InMat + 8 * v2 + 8 * (unsigned __int64)(unsigned int)(dist_row - 1) + 8);
do
{
v6 = 0;
if ( col > 0 )
{
v5 = *v3;
v6 = 0;
do
v6 = (int)((double)v6 + *v5++);
while ( v5 != &(*v3)[(unsigned int)(col - 1) + 1] );
}
if ( v1 < v6 )
v1 = v6;
++v3;
}
while ( v3 != 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

decompiled_code:
void __fastcall jacobi(void *a1)
{
unsigned int v1; // er9
int v2; // er11
__int64 v3; // r10
__int64 v4; // r8
int v5; // edi
__int64 i; // rdx
__int64 v7; // rax
__int64 v8; // rcx
__int64 v9; // rsi
__int64 v10; // rax
__int64 v11; // rax

if ( (int)a1 > 0 )
{
v1 = (unsigned int)a1;
*(_QWORD *)Bloc_X = *(_QWORD *)RHS_Vector;
v2 = (_DWORD)a1 - 1;
v3 = 8LL * (unsigned int)((_DWORD)a1 - 1);
v4 = 0LL;
v5 = 0;
for ( i = 0LL; ; i += 8LL )
{
++v5;
if ( i == v3 )
break;
v9 = i + 8;
v10 = i + 8;
do
{
*(double *)((char *)Bloc_X + i) = *(double *)((char *)Bloc_X + i)
- *(double *)(*(_QWORD *)((char *)Matrix_A + i) + v10)
* *(double *)((char *)X_Old + v10);
v10 += 8LL;
}
while ( v10 != 8 * (v4 + (unsigned int)(v2 - v5) + 2) );
*(double *)((char *)Bloc_X + i) = *(double *)((char *)Bloc_X + i)
/ *(double *)(*(_QWORD *)((char *)Matrix_A + i) + i);
*(_QWORD *)((char *)Bloc_X + v9) = *(_QWORD *)((char *)RHS_Vector + v9);
if ( v5 > 0 )
{
v7 = 0LL;
do
{
*(double *)((char *)Bloc_X + v9) = *(double *)((char *)Bloc_X + v9)
- *(double *)(*(_QWORD *)((char *)Matrix_A + v9) + v7)
* *(double *)((char *)X_Old + v7);
v8 = v7;
v7 += 8LL;
}
while ( v8 != i );
}
++v4;
}
*(double *)((char *)Bloc_X + i) = *(double *)((char *)Bloc_X + i)
/ *(double *)(*(_QWORD *)((char *)Matrix_A + i) + i);
v11 = 0LL;
do
{
*(_QWORD *)((char *)X_New + v11) = *(_QWORD *)((char *)Bloc_X + v11);
v11 += 8LL;
}
while ( v11 != 8LL * v1 );
}
}

canonical_decompiled_code:
void __fastcall func7(void *a1)
{
unsigned int v1; // er9
int v2; // er11
__int64 v3; // r10
__int64 v4; // r8
int v5; // edi
__int64 i; // rdx
__int64 v7; // rax
__int64 v8; // rcx
__int64 v9; // rsi
__int64 v10; // rax
__int64 v11; // rax

if ( (int)a1 > 0 )
{
v1 = (unsigned int)a1;
*(_QWORD *)Bloc_X = *(_QWORD *)RHS_Vector;
v2 = (_DWORD)a1 - 1;
v3 = 8LL * (unsigned int)((_DWORD)a1 - 1);
v4 = 0LL;
v5 = 0;
for ( i = 0LL; ; i += 8LL )
{
++v5;
if ( i == v3 )
break;
v9 = i + 8;
v10 = i + 8;
do
{
*(double *)((char *)Bloc_X + i) = *(double *)((char *)Bloc_X + i)
- *(double *)(*(_QWORD *)((char *)Matrix_A + i) + v10)
* *(double *)((char *)X_Old + v10);
v10 += 8LL;
}
while ( v10 != 8 * (v4 + (unsigned int)(v2 - v5) + 2) );
*(double *)((char *)Bloc_X + i) = *(double *)((char *)Bloc_X + i)
/ *(double *)(*(_QWORD *)((char *)Matrix_A + i) + i);
*(_QWORD *)((char *)Bloc_X + v9) = *(_QWORD *)((char *)RHS_Vector + v9);
if ( v5 > 0 )
{
v7 = 0LL;
do
{
*(double *)((char *)Bloc_X + v9) = *(double *)((char *)Bloc_X + v9)
- *(double *)(*(_QWORD *)((char *)Matrix_A + v9) + v7)
* *(double *)((char *)X_Old + v7);
v8 = v7;
v7 += 8LL;
}
while ( v8 != i );
}
++v4;
}
*(double *)((char *)Bloc_X + i) = *(double *)((char *)Bloc_X + i)
/ *(double *)(*(_QWORD *)((char *)Matrix_A + i) + i);
v11 = 0LL;
do
{
*(_QWORD *)((char *)X_New + v11) = *(_QWORD *)((char *)Bloc_X + v11);
v11 += 8LL;
}
while ( v11 != 8LL * v1 );
}
}

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


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)
{
if ( a1 % a2 )
a1 = a2 * (a1 / a2 + 1);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
if ( a1 % a2 )
a1 = a2 * (a1 / a2 + 1);
return a1;
}

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

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx

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

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; // edi
unsigned int v1; // ebx
int v2; // eax
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF
int optval[3]; // [rsp+2Ch] [rbp-Ch] BYREF

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

canonical_decompiled_code:
__int64 func1()
{
int v0; // edi
unsigned int v1; // ebx
int v2; // eax
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF
int optval[3]; // [rsp+2Ch] [rbp-Ch] BYREF

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

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; // r12
socklen_t addr_len[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = (char *)malloc(0x10uLL);
addr_len[0] = 8;
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->events = 1;
v4->data.u64 = (uint64_t)v5;
if ( epoll_ctl(epfd, 1, v2, v4) < 0 )
{
perror("epoll_ctl()");
}
else
{
v5[1] = v2;
*((_QWORD *)v5 + 1) = v0;
*((_QWORD *)v5 + 2) = v4;
init_client(v5);
}
}
}
}

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

v0 = (char *)malloc(0x10uLL);
addr_len[0] = 8;
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->events = 1;
v4->data.u64 = (uint64_t)v5;
if ( epoll_ctl(epfd, 1, v2, v4) < 0 )
{
perror("epoll_ctl()");
}
else
{
v5[1] = v2;
*((_QWORD *)v5 + 1) = v0;
*((_QWORD *)v5 + 2) = v4;
init_client(v5);
}
}
}
}

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
__int64 v1; // rbp
unsigned __int64 v2; // rbx
struct epoll_event *v3; // rax

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

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

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

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

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

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

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

*(_DWORD *)(a1 + 16) = 4096;
result = malloc(0x1000uLL);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 20) = 0;
*(_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)
{
int v2; // eax
__int64 v3; // rcx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 20);
if ( 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)
{
int v2; // eax
__int64 v3; // rcx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 20);
if ( 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


decompiled_code:
void __fastcall put_byte(__int64 a1, int a2, int a3)
{
int v3; // eax
__int64 v4; // rdx

v3 = *(_DWORD *)(a1 + 20);
if ( v3 >= *(_DWORD *)(a1 + 16) )
{
perror("WARNING: Buffer overflow in put_byte");
}
else
{
switch ( a3 )
{
case 2:
LOBYTE(a2) = 0x80 - a2;
break;
case 3:
a2 = -a2;
break;
case 1:
LOBYTE(a2) = a2 + 0x80;
break;
}
v4 = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 20) = v3 + 1;
*(_BYTE *)(v4 + v3) = a2;
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2, int a3)
{
int v3; // eax
__int64 v4; // rdx

v3 = *(_DWORD *)(a1 + 20);
if ( v3 >= *(_DWORD *)(a1 + 16) )
{
perror("WARNING: Buffer overflow in put_byte");
}
else
{
switch ( a3 )
{
case 2:
LOBYTE(a2) = 0x80 - a2;
break;
case 3:
a2 = -a2;
break;
case 1:
LOBYTE(a2) = a2 + 0x80;
break;
}
v4 = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 20) = v3 + 1;
*(_BYTE *)(v4 + v3) = a2;
}
}

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
{
put_byte(a1, v3, 0);
v3 = *v4++;
}
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, int a2, int a3, int a4)
{
if ( a3 )
{
if ( a3 == 1 )
{
put_byte(a1, a2, a4);
put_byte(a1, a2 >> 8, 0);
}
}
else
{
put_byte(a1, a2 >> 8, 0);
put_byte(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;
}


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


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


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


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 *


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


decompiled_code:
__int64 __fastcall isaac_next_int(__int64 a1)
{
int v1; // eax

v1 = *(_DWORD *)(*(_QWORD *)a1 + 8LL);
*(_DWORD *)(*(_QWORD *)a1 + 8LL) = v1 - 1;
if ( !v1 )
{
do_isaac(a1);
*(_DWORD *)(*(_QWORD *)a1 + 8LL) = 255;
}
return *(unsigned int *)(**(_QWORD **)a1 + 4LL * *(unsigned int *)(*(_QWORD *)a1 + 8LL));
}

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(&tv, 0LL);
reactor_poll();
world_tick();
world_sync();
world_reset();
gettimeofday(&v0, 0LL);
usleep(
1000
* (600
- (int)((double)(LODWORD(v0.tv_usec) - LODWORD(tv.tv_usec)) / 1000.0
+ (double)(1000 * (LODWORD(v0.tv_sec) - LODWORD(tv.tv_sec)))
+ 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(&tv, 0LL);
reactor_poll();
world_tick();
world_sync();
world_reset();
gettimeofday(&v0, 0LL);
usleep(
1000
* (600
- (int)((double)(LODWORD(v0.tv_usec) - LODWORD(tv.tv_usec)) / 1000.0
+ (double)(1000 * (LODWORD(v0.tv_sec) - LODWORD(tv.tv_sec)))
+ 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:
void *xgetcwd()
{
int *v0; // r13
void *v1; // rbx
unsigned int v2; // er12
int v3; // er14

v0 = _errno_location();
*v0 = 0;
v1 = (void *)xmalloc(4098LL);
*v0 = 0;
v2 = 4098;
while ( !getcwd((char *)v1, v2) )
{
v3 = *v0;
if ( *v0 != 34 )
{
free(v1);
*v0 = v3;
return 0LL;
}
v2 += 32;
v1 = (void *)xrealloc(v1, v2);
*v0 = 0;
}
return v1;
}

canonical_decompiled_code:
void *func0()
{
int *v0; // r13
void *v1; // rbx
unsigned int v2; // er12
int v3; // er14

v0 = _errno_location();
*v0 = 0;
v1 = (void *)xmalloc(4098LL);
*v0 = 0;
v2 = 4098;
while ( !getcwd((char *)v1, v2) )
{
v3 = *v0;
if ( *v0 != 34 )
{
free(v1);
*v0 = v3;
return 0LL;
}
v2 += 32;
v1 = (void *)xrealloc(v1, v2);
*v0 = 0;
}
return v1;
}

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

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

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

result = a2;
*a1 = 0;
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

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

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

result = a2;
*(_DWORD *)a1 = 2;
*(_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

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

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

result = a2;
*(_DWORD *)a1 = 3;
*(_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

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

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

result = a2;
*(_DWORD *)a1 = 1;
*(_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) = *(_QWORD *)(result + 16);
*(_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) = *(_QWORD *)(result + 16);
*(_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; // rbp

v2 = newItem();
if ( v2 )
{
if ( *a1 > a2 && *a1 )
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; // rbp

v2 = newItem();
if ( v2 )
{
if ( *a1 > a2 && *a1 )
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);
}