main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
size_t v4; // rbp
void *v5; // rax
size_t v6; // rbp
__int64 v7; // rbx
__int64 v8; // rsi
__int64 v9; // r12
__int64 v10; // r13
int v11; // ebx
char *v12; // rax
__int64 v13; // rbx
char *v14; // rsi
__int64 v15; // r12
__int64 v16; // r13
int v17; // ebx
char *v18; // rax
__int64 v19; // rbx
char *v20; // rsi
int v21; // er15
__int64 v22; // r12
__int64 v23; // r14
int v24; // ebx
size_t v25; // r13
__int64 v26; // rbp
_DWORD *v27; // rcx
__int64 v28; // rdi
__int64 v29; // rsi
__int64 v30; // rax
__int64 v31; // r9
__int64 v32; // r8
__int64 v33; // r11
__int64 v34; // r10
int v35; // edx
_QWORD *v36; // rcx
_QWORD *v37; // rax
__int64 v38; // rdi
int v39; // ebx
__int64 v40; // r12
__int64 i; // rbx
__int64 v42; // rsi
void *v44; // rbx
pthread_t *v45; // rbp
__int64 v46; // [rsp+8h] [rbp-50h]
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF

pthread_mutex_init(&lock, 0LL);
puts("Number of processes: ");
_isoc99_scanf("%d", &row);
puts("Number of resources: ");
_isoc99_scanf("%d", &col);
puts("\tFINISHED LOADING IN NB PROCESSES AND RESOURCES");
v3 = malloc(0x28uLL);
s = (__int64)v3;
v4 = 4LL * col;
*v3 = malloc(v4);
v5 = malloc(v4);
v6 = row;
v3[1] = v5;
v6 *= 4LL;
v3[2] = malloc(v6);
v3[3] = malloc(v6);
v3[4] = malloc(v6);
v7 = 0LL;
puts("\tFINISHED ALLOCATING SPACE FOR STATE");
puts("Resource vector: ");
if ( col > 0 )
{
do
{
v8 = *(_QWORD *)s + 4 * v7++;
_isoc99_scanf("%d", v8);
}
while ( col > (int)v7 );
}
v9 = 0LL;
puts("Enter max matrix: ");
if ( row > 0 )
{
do
{
v10 = *(_QWORD *)(s + 16);
v11 = col;
v12 = (char *)malloc(4LL * col);
*(_QWORD *)(8 * v9 + v10) = v12;
if ( v11 > 0 )
{
v13 = 0LL;
while ( 1 )
{
v14 = &v12[4 * v13++];
_isoc99_scanf("%d", v14);
if ( col <= (int)v13 )
break;
v12 = *(char **)(*(_QWORD *)(s + 16) + 8 * v9);
}
}
++v9;
}
while ( row > (int)v9 );
}
v15 = 0LL;
puts("Enter allocation matrix: ");
if ( row > 0 )
{
do
{
v16 = *(_QWORD *)(s + 24);
v17 = col;
v18 = (char *)malloc(4LL * col);
*(_QWORD *)(8 * v15 + v16) = v18;
if ( v17 > 0 )
{
v19 = 0LL;
while ( 1 )
{
v20 = &v18[4 * v19++];
_isoc99_scanf("%d", v20);
if ( col <= (int)v19 )
break;
v18 = *(char **)(*(_QWORD *)(s + 24) + 8 * v15);
}
}
++v15;
}
while ( row > (int)v15 );
}
putchar(10);
puts("\tFINISHED LOADING VECTORS AND MATRIXES");
v21 = row;
if ( row <= 0 )
{
v24 = col;
}
else
{
v22 = s;
v23 = col;
v24 = col;
v25 = 4LL * col;
v46 = *(_QWORD *)(s + 32);
v26 = 0LL;
do
{
v27 = malloc(v25);
*(_QWORD *)(v46 + v26) = v27;
if ( v24 > 0 )
{
v28 = *(_QWORD *)(*(_QWORD *)(v22 + 16) + v26);
v29 = *(_QWORD *)(*(_QWORD *)(v22 + 24) + v26);
v30 = 0LL;
do
{
v27[v30] = *(_DWORD *)(v28 + 4 * v30) - *(_DWORD *)(v29 + 4 * v30);
++v30;
}
while ( v23 != v30 );
}
v26 += 8LL;
}
while ( 8LL * v21 != v26 );
}
if ( v24 > 0 )
{
v31 = s;
v32 = 0LL;
v33 = *(_QWORD *)s;
v34 = *(_QWORD *)(s + 8);
while ( 1 )
{
v35 = 0;
if ( v21 > 0 )
{
v36 = *(_QWORD **)(v31 + 24);
v37 = v36 + 1;
v38 = (__int64)&v36[(unsigned int)(v21 - 1) + 1];
v35 = 0;
while ( 1 )
{
v35 += *(_DWORD *)(*v36 + 4 * v32);
v36 = v37;
if ( (_QWORD *)v38 == v37 )
break;
++v37;
}
}
*(_DWORD *)(v34 + 4 * v32) = *(_DWORD *)(v33 + 4 * v32) - v35;
if ( col <= (int)++v32 )
break;
v21 = row;
}
}
v39 = 0;
puts("Need matrix:");
if ( col > 0 )
{
do
printf("R%d ", (unsigned int)++v39);
while ( v39 < col );
}
v40 = 0LL;
putchar(10);
if ( row > 0 )
{
do
{
for ( i = 0LL; col > (int)i; ++i )
{
v42 = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8 * v40) + 4 * i);
printf("%d ", v42);
}
++v40;
putchar(10);
}
while ( row > (int)v40 );
}
printAvailable();
if ( (unsigned int)stateSafeCheck() )
{
v44 = 0LL;
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
v45 = (pthread_t *)malloc(8LL * row);
while ( row > (int)v44 )
{
pthread_create(&v45[(_QWORD)v44], 0LL, (void *(*)(void *))process_thread, v44);
v44 = (char *)v44 + 1;
}
pthread_exit(0LL);
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
size_t v4; // rbp
void *v5; // rax
size_t v6; // rbp
__int64 v7; // rbx
__int64 v8; // rsi
__int64 v9; // r12
__int64 v10; // r13
int v11; // ebx
char *v12; // rax
__int64 v13; // rbx
char *v14; // rsi
__int64 v15; // r12
__int64 v16; // r13
int v17; // ebx
char *v18; // rax
__int64 v19; // rbx
char *v20; // rsi
int v21; // er15
__int64 v22; // r12
__int64 v23; // r14
int v24; // ebx
size_t v25; // r13
__int64 v26; // rbp
_DWORD *v27; // rcx
__int64 v28; // rdi
__int64 v29; // rsi
__int64 v30; // rax
__int64 v31; // r9
__int64 v32; // r8
__int64 v33; // r11
__int64 v34; // r10
int v35; // edx
_QWORD *v36; // rcx
_QWORD *v37; // rax
__int64 v38; // rdi
int v39; // ebx
__int64 v40; // r12
__int64 i; // rbx
__int64 v42; // rsi
void *v44; // rbx
pthread_t *v45; // rbp
__int64 v46; // [rsp+8h] [rbp-50h]
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF

pthread_mutex_init(&lock, 0LL);
puts("Number of processes: ");
_isoc99_scanf("%d", &row);
puts("Number of resources: ");
_isoc99_scanf("%d", &col);
puts("\tFINISHED LOADING IN NB PROCESSES AND RESOURCES");
v3 = malloc(0x28uLL);
s = (__int64)v3;
v4 = 4LL * col;
*v3 = malloc(v4);
v5 = malloc(v4);
v6 = row;
v3[1] = v5;
v6 *= 4LL;
v3[2] = malloc(v6);
v3[3] = malloc(v6);
v3[4] = malloc(v6);
v7 = 0LL;
puts("\tFINISHED ALLOCATING SPACE FOR STATE");
puts("Resource vector: ");
if ( col > 0 )
{
do
{
v8 = *(_QWORD *)s + 4 * v7++;
_isoc99_scanf("%d", v8);
}
while ( col > (int)v7 );
}
v9 = 0LL;
puts("Enter max matrix: ");
if ( row > 0 )
{
do
{
v10 = *(_QWORD *)(s + 16);
v11 = col;
v12 = (char *)malloc(4LL * col);
*(_QWORD *)(8 * v9 + v10) = v12;
if ( v11 > 0 )
{
v13 = 0LL;
while ( 1 )
{
v14 = &v12[4 * v13++];
_isoc99_scanf("%d", v14);
if ( col <= (int)v13 )
break;
v12 = *(char **)(*(_QWORD *)(s + 16) + 8 * v9);
}
}
++v9;
}
while ( row > (int)v9 );
}
v15 = 0LL;
puts("Enter allocation matrix: ");
if ( row > 0 )
{
do
{
v16 = *(_QWORD *)(s + 24);
v17 = col;
v18 = (char *)malloc(4LL * col);
*(_QWORD *)(8 * v15 + v16) = v18;
if ( v17 > 0 )
{
v19 = 0LL;
while ( 1 )
{
v20 = &v18[4 * v19++];
_isoc99_scanf("%d", v20);
if ( col <= (int)v19 )
break;
v18 = *(char **)(*(_QWORD *)(s + 24) + 8 * v15);
}
}
++v15;
}
while ( row > (int)v15 );
}
putchar(10);
puts("\tFINISHED LOADING VECTORS AND MATRIXES");
v21 = row;
if ( row <= 0 )
{
v24 = col;
}
else
{
v22 = s;
v23 = col;
v24 = col;
v25 = 4LL * col;
v46 = *(_QWORD *)(s + 32);
v26 = 0LL;
do
{
v27 = malloc(v25);
*(_QWORD *)(v46 + v26) = v27;
if ( v24 > 0 )
{
v28 = *(_QWORD *)(*(_QWORD *)(v22 + 16) + v26);
v29 = *(_QWORD *)(*(_QWORD *)(v22 + 24) + v26);
v30 = 0LL;
do
{
v27[v30] = *(_DWORD *)(v28 + 4 * v30) - *(_DWORD *)(v29 + 4 * v30);
++v30;
}
while ( v23 != v30 );
}
v26 += 8LL;
}
while ( 8LL * v21 != v26 );
}
if ( v24 > 0 )
{
v31 = s;
v32 = 0LL;
v33 = *(_QWORD *)s;
v34 = *(_QWORD *)(s + 8);
while ( 1 )
{
v35 = 0;
if ( v21 > 0 )
{
v36 = *(_QWORD **)(v31 + 24);
v37 = v36 + 1;
v38 = (__int64)&v36[(unsigned int)(v21 - 1) + 1];
v35 = 0;
while ( 1 )
{
v35 += *(_DWORD *)(*v36 + 4 * v32);
v36 = v37;
if ( (_QWORD *)v38 == v37 )
break;
++v37;
}
}
*(_DWORD *)(v34 + 4 * v32) = *(_DWORD *)(v33 + 4 * v32) - v35;
if ( col <= (int)++v32 )
break;
v21 = row;
}
}
v39 = 0;
puts("Need matrix:");
if ( col > 0 )
{
do
printf("R%d ", (unsigned int)++v39);
while ( v39 < col );
}
v40 = 0LL;
putchar(10);
if ( row > 0 )
{
do
{
for ( i = 0LL; col > (int)i; ++i )
{
v42 = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8 * v40) + 4 * i);
printf("%d ", v42);
}
++v40;
putchar(10);
}
while ( row > (int)v40 );
}
func0();
if ( (unsigned int)func3() )
{
v44 = 0LL;
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
v45 = (pthread_t *)malloc(8LL * row);
while ( row > (int)v44 )
{
pthread_create(&v45[(_QWORD)v44], 0LL, (void *(*)(void *))process_thread, v44);
v44 = (char *)v44 + 1;
}
pthread_exit(0LL);
}
return 1;
}

original_code:
int main(int argc, char* argv[])
{
  pthread_mutex_init(&lock,((void *)0));
  int i, j;
  printf("Number of processes: \n");
  scanf("%d", &row);
  printf("Number of resources: \n");
  scanf("%d", &col);
 printf("\tFINISHED LOADING IN NB PROCESSES AND RESOURCES\n");
  s = (State *) malloc(sizeof(State));
  s->resource = (int *) malloc(col*sizeof(int));
  s->available = (int *) malloc(col*sizeof(int));
  s->max = (int **) malloc(row*sizeof(int));
  s->allocation = (int **) malloc(row*sizeof(int));
  s->need = (int **) malloc(row*sizeof(int));
  if (s == ((void *)0)) { printf("\nYou need to allocate memory for the state!\n"); exit(0); };
 printf("\tFINISHED ALLOCATING SPACE FOR STATE\n");
  printf("Resource vector: \n");
  for(i = 0; i < col; i++)
    scanf("%d", &s->resource[i]);
  printf("Enter max matrix: \n");
  for(i = 0;i < row; i++) {
   s->max[i] = (int *) malloc(col*sizeof(int));
    for(j = 0;j < col; j++) {
       scanf("%d", &s->max[i][j]);
      }
    }
  printf("Enter allocation matrix: \n");
  for(i = 0; i < row; i++) {
   s->allocation[i] = (int *) malloc(col*sizeof(int));
    for(j = 0; j < col; j++) {
      scanf("%d", &s->allocation[i][j]);
    }
  }
  printf("\n");
  printf("\tFINISHED LOADING VECTORS AND MATRIXES\n");
  for(i = 0; i < row; i++) {
   s->need[i] = (int *) malloc(col*sizeof(int));
    for(j = 0; j < col; j++) {
      s->need[i][j] = s->max[i][j] - s->allocation[i][j];
    }
  }
  for(j = 0; j < col; j++) {
    int sum = 0;
    for(i = 0; i < row; i++)
      sum += s->allocation[i][j];
    s->available[j] = s->resource[j] - sum;
  }
  printf("Need matrix:\n");
  for(i = 0; i < col; i++)
    printf("R%d ", i+1);
  printf("\n");
  for(i = 0; i < row; i++) {
    for(j = 0; j < col; j++)
      printf("%d  ",s->need[i][j]);
    printf("\n");
  }
  printAvailable();
  int safe = stateSafeCheck();
 if (safe == 0)
 {
  return 1;
 }
  struct timeval tv;
  gettimeofday(&tv, ((void *)0));
  srand(tv.tv_usec);
  pthread_t *tid = malloc(row*sizeof(pthread_t));
  for (i = 0; i < row; i++)
    pthread_create(&tid[i], ((void *)0), process_thread, (void *) (long) i);
  pthread_exit(0);
  free(tid);
  free(s->resource);
  free(s->available);
  free(s->max);
  free(s->allocation);
  free(s->need);
  free(s);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  pthread_mutex_init(&lock,((void *)0));
  int i; int j;
  printf("Number of processes: \n");
  scanf("%d", &row);
  printf("Number of resources: \n");
  scanf("%d", &col);
 printf("\tFINISHED LOADING IN NB PROCESSES AND RESOURCES\n");
  s = (struct state *) malloc(sizeof(State));
  s->resource = (int *) malloc(col*sizeof(int));
  s->available = (int *) malloc(col*sizeof(int));
  s->max = (int **) malloc(row*sizeof(int));
  s->allocation = (int **) malloc(row*sizeof(int));
  s->need = (int **) malloc(row*sizeof(int));
  if (s == ((void *)0)) { printf("\nYou need to allocate memory for the state!\n"); exit(0); };
 printf("\tFINISHED ALLOCATING SPACE FOR STATE\n");
  printf("Resource vector: \n");
  for(i = 0; i < col; i++)
    scanf("%d", &s->resource[i]);
  printf("Enter max matrix: \n");
  for(i = 0;i < row; i++) {
   s->max[i] = (int *) malloc(col*sizeof(int));
    for(j = 0;j < col; j++) {
       scanf("%d", &s->max[i][j]);
      }
    }
  printf("Enter allocation matrix: \n");
  for(i = 0; i < row; i++) {
   s->allocation[i] = (int *) malloc(col*sizeof(int));
    for(j = 0; j < col; j++) {
      scanf("%d", &s->allocation[i][j]);
    }
  }
  printf("\n");
  printf("\tFINISHED LOADING VECTORS AND MATRIXES\n");
  for(i = 0; i < row; i++) {
   s->need[i] = (int *) malloc(col*sizeof(int));
    for(j = 0; j < col; j++) {
      s->need[i][j] = s->max[i][j] - s->allocation[i][j];
    }
  }
  for(j = 0; j < col; j++) {
    int sum = 0;
    for(i = 0; i < row; i++)
      sum += s->allocation[i][j];
    s->available[j] = s->resource[j] - sum;
  }
  printf("Need matrix:\n");
  for(i = 0; i < col; i++)
    printf("R%d ", i+1);
  printf("\n");
  for(i = 0; i < row; i++) {
    for(j = 0; j < col; j++)
      printf("%d  ",s->need[i][j]);
    printf("\n");
  }
  printAvailable();
  int safe = stateSafeCheck();
 if (safe == 0)
 {
  return 1;
 }
  struct timeval tv;
  gettimeofday(&tv, ((void *)0));
  srand(tv.tv_usec);
  unsigned long *tid = malloc(row*sizeof(pthread_t));
  for (i = 0; i < row; i++)
    pthread_create(&tid[i], ((void *)0), process_thread, (void *) (long) i);
  pthread_exit(0);
  free(tid);
  free(s->resource);
  free(s->available);
  free(s->max);
  free(s->allocation);
  free(s->need);
  free(s);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: safe int

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

variable_types:
tid
unsigned long *

user_defined_types: struct state { int *resource; int *available; int **max; int **allocation; int **need; }


producer

repo: inau/Cloaked-computing-machine

decompiled_code:
int __fastcall producer(void *a1)
{
unsigned int v1; // er12
_QWORD *v2; // rbp
_DWORD *v3; // rax
int v4; // edx
__int64 v5; // rdi
__int64 v6; // rdx

v1 = *(_DWORD *)a1;
while ( 1 )
{
Sleep(1000.0);
if ( numproducts >= maxproducts )
break;
sem_wait(&empty);
sem_wait(&mutex);
if ( numproducts >= maxproducts )
{
puts("\tBreaking out of while loop!");
sem_post(&mutex);
sem_post(&full);
return printf("\tProducer %d exited\n", v1);
}
v2 = (_QWORD *)node_new();
v3 = malloc(4uLL);
v4 = numproducts;
v5 = list;
*v2 = v3;
*v3 = v4;
list_add(v5, v2);
v6 = (unsigned int)numproducts++;
printf(
"Producer %d produced item %d. \t Items in buffer: %d (out of %d) \n",
v1,
v6,
*(unsigned int *)list,
buffersize);
sem_post(&mutex);
sem_post(&full);
}
return printf("\tProducer %d exited\n", v1);
}

canonical_decompiled_code:
int __fastcall func1(void *a1)
{
unsigned int v1; // er12
_QWORD *v2; // rbp
_DWORD *v3; // rax
int v4; // edx
__int64 v5; // rdi
__int64 v6; // rdx

v1 = *(_DWORD *)a1;
while ( 1 )
{
func0(1000.0);
if ( numproducts >= maxproducts )
break;
sem_wait(&empty);
sem_wait(&mutex);
if ( numproducts >= maxproducts )
{
puts("\tBreaking out of while loop!");
sem_post(&mutex);
sem_post(&full);
return printf("\tProducer %d exited\n", v1);
}
v2 = (_QWORD *)node_new();
v3 = malloc(4uLL);
v4 = numproducts;
v5 = list;
*v2 = v3;
*v3 = v4;
list_add(v5, v2);
v6 = (unsigned int)numproducts++;
printf(
"Producer %d produced item %d. \t Items in buffer: %d (out of %d) \n",
v1,
v6,
*(unsigned int *)list,
buffersize);
sem_post(&mutex);
sem_post(&full);
}
return printf("\tProducer %d exited\n", v1);
}

original_code:
void *producer(void *param) {
 int num;
 num = *((int*)param);
 Sleep(1000);
 Node *n;
 while(numproducts < maxproducts){
  sem_wait(&empty);
  sem_wait(&mutex);
  if (numproducts >= maxproducts) {
   printf("\tBreaking out of while loop!\n");
   sem_post(&mutex);
   sem_post(&full);
   break;
  }
  n = node_new();
  n->elm = malloc(sizeof(int));
  *((int*)n->elm) = numproducts;
  list_add(list, n);
  numproducts++;
  printf("Producer %d produced item %d. \t Items in buffer: %d (out of %d) \n", num, (numproducts-1), list->len, buffersize );
  sem_post(&mutex);
  sem_post(&full);
  Sleep(1000);
 }
 printf("\tProducer %d exited\n", num);
}

canonical_original_code:
void *producer(void *param) {
 int num;
 num = *((int *)param);
 Sleep(1000);
 struct node *n;
 while(numproducts < maxproducts){
  sem_wait(&empty);
  sem_wait(&mutex);
  if (numproducts >= maxproducts) {
   printf("\tBreaking out of while loop!\n");
   sem_post(&mutex);
   sem_post(&full);
   break;
  }
  n = node_new();
  n->elm = malloc(sizeof(int));
  *((int *)n->elm) = numproducts;
  list_add(list, n);
  numproducts++;
  printf("Producer %d produced item %d. \t Items in buffer: %d (out of %d) \n", num, (numproducts-1), list->len, buffersize );
  sem_post(&mutex);
  sem_post(&full);
  Sleep(1000);
 }
 printf("\tProducer %d exited\n", num);
}

variable_types:
param
void *

variable_types: num int

variable_types: struct node { void *elm; struct node *next; } *

return_type: void *


consumer

decompiled_code:
int __fastcall consumer(void *a1)
{
unsigned int v1; // ebp
void **v2; // rbx

v1 = *(_DWORD *)a1;
Sleep(1000.0);
while ( numproducts < maxproducts || *(int *)list > 0 )
{
sem_wait(&full);
sem_wait(&mutex);
v2 = (void **)list_remove(list);
printf(
"Consumer %d consumed item %d. \t Items in buffer: %d (out of %d) \n",
v1,
*(unsigned int *)*v2,
*(unsigned int *)list,
buffersize);
free(*v2);
sem_post(&mutex);
sem_post(&empty);
Sleep(1000.0);
}
return printf("\tConsumer %d exited\n", v1);
}

canonical_decompiled_code:
int __fastcall func2(void *a1)
{
unsigned int v1; // ebp
void **v2; // rbx

v1 = *(_DWORD *)a1;
func0(1000.0);
while ( numproducts < maxproducts || *(int *)list > 0 )
{
sem_wait(&full);
sem_wait(&mutex);
v2 = (void **)list_remove(list);
printf(
"Consumer %d consumed item %d. \t Items in buffer: %d (out of %d) \n",
v1,
*(unsigned int *)*v2,
*(unsigned int *)list,
buffersize);
free(*v2);
sem_post(&mutex);
sem_post(&empty);
func0(1000.0);
}
return printf("\tConsumer %d exited\n", v1);
}

original_code:
void *consumer(void *param) {
 int num;
 num = *((int*)param);
 Sleep(1000);
 Node *n;
 while(numproducts < (maxproducts) || list->len > 0){
  sem_wait(&full);
  sem_wait(&mutex);
  n = list_remove(list);
  printf("Consumer %d consumed item %d. \t Items in buffer: %d (out of %d) \n", num, *((int*)n->elm), list->len, buffersize );
  free(n->elm);
  sem_post(&mutex);
  sem_post(&empty);
  Sleep(1000);
 }
 printf("\tConsumer %d exited\n", num);
}

canonical_original_code:
void *consumer(void *param) {
 int num;
 num = *((int *)param);
 Sleep(1000);
 struct node *n;
 while(numproducts < (maxproducts) || list->len > 0){
  sem_wait(&full);
  sem_wait(&mutex);
  n = list_remove(list);
  printf("Consumer %d consumed item %d. \t Items in buffer: %d (out of %d) \n", num, *((int *)n->elm), list->len, buffersize );
  free(n->elm);
  sem_post(&mutex);
  sem_post(&empty);
  Sleep(1000);
 }
 printf("\tConsumer %d exited\n", num);
}

user_defined_types: struct node { void *elm; struct node *next; }


Sleep

decompiled_code:
int __fastcall Sleep(float a1)
{
int v1; // eax

v1 = rand();
return usleep((int)(float)((float)((float)((float)v1 * a1) * 4.6566129e-10) * 1000.0));
}

canonical_decompiled_code:
int __fastcall func0(float a1)
{
int v1; // eax

v1 = rand();
return usleep((int)(float)((float)((float)((float)v1 * a1) * 4.6566129e-10) * 1000.0));
}

original_code:
void Sleep(float wait_time_ms)
{
 wait_time_ms = ((float)rand())*wait_time_ms / (float)2147483647;
 usleep((int) (wait_time_ms * 1e3f));
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v3; // xmm0_4
int v4; // er13
int v5; // er14
int v6; // eax
const char *v7; // rdi
int v8; // er15
void *v9; // rsp
int v10; // eax
pthread_t *v11; // rbx
__int64 v12; // r12
__int64 v13; // rsi
__int64 v14; // rsi
pthread_t *v15; // r12
pthread_t v16; // rdi
int result; // eax
__int64 v18; // [rsp+0h] [rbp-A0h] BYREF
int v19; // [rsp+8h] [rbp-98h]
int v20; // [rsp+Ch] [rbp-94h]
unsigned int arg; // [rsp+14h] [rbp-8Ch] BYREF
pthread_t newthread; // [rsp+18h] [rbp-88h] BYREF
struct timeval tv; // [rsp+20h] [rbp-80h] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-70h] BYREF

list = list_new(argc, argv, envp);
if ( argc == 5 )
{
v4 = atoi(argv[1]);
v5 = atoi(argv[2]);
v6 = atoi(argv[3]);
v7 = argv[4];
v8 = v5;
buffersize = v6;
maxproducts = atoi(v7);
sem_init(&mutex, 0, 1u);
sem_init(&empty, 0, buffersize);
sem_init(&full, 0, 0);
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
v19 = v4 + v5;
if ( v4 >= v5 )
v8 = v4;
arg = 1;
v9 = alloca(8LL * (v4 + v5));
pthread_attr_init(&attr);
v10 = 1;
v11 = (pthread_t *)&v18;
if ( v8 >= 1 )
{
v12 = 0LL;
do
{
if ( v4 < v10 )
{
if ( (int)arg <= v5 )
goto LABEL_10;
}
else
{
pthread_create(&newthread, &attr, (void *(*)(void *))producer, &arg);
v13 = arg;
v20 = v12 + 1;
*(&v18 + v12) = newthread;
printf("\tProducer %d created \n", v13);
v12 = v20;
if ( (int)arg <= v5 )
{
LABEL_10:
pthread_create(&newthread, &attr, (void *(*)(void *))consumer, &arg);
v14 = arg;
v20 = v12 + 1;
*(&v18 + v12) = newthread;
printf("\tConsumer %d created \n", v14);
v12 = v20;
goto LABEL_7;
}
}
LABEL_7:
Sleep(v3);
v10 = arg + 1;
arg = v10;
}
while ( v8 >= v10 );
}
if ( v19 > 0 )
{
v15 = (pthread_t *)(&v18 + (unsigned int)(v19 - 1) + 1);
do
{
v16 = *v11++;
pthread_join(v16, 0LL);
}
while ( v11 != v15 );
}
puts("joints done ");
result = 0;
}
else
{
fwrite("must be 4\n", 1uLL, 0xAuLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v3; // xmm0_4
int v4; // er13
int v5; // er14
int v6; // eax
const char *v7; // rdi
int v8; // er15
void *v9; // rsp
int v10; // eax
pthread_t *v11; // rbx
__int64 v12; // r12
__int64 v13; // rsi
__int64 v14; // rsi
pthread_t *v15; // r12
pthread_t v16; // rdi
int result; // eax
__int64 v18; // [rsp+0h] [rbp-A0h] BYREF
int v19; // [rsp+8h] [rbp-98h]
int v20; // [rsp+Ch] [rbp-94h]
unsigned int arg; // [rsp+14h] [rbp-8Ch] BYREF
pthread_t newthread; // [rsp+18h] [rbp-88h] BYREF
struct timeval tv; // [rsp+20h] [rbp-80h] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-70h] BYREF

list = list_new(argc, argv, envp);
if ( argc == 5 )
{
v4 = atoi(argv[1]);
v5 = atoi(argv[2]);
v6 = atoi(argv[3]);
v7 = argv[4];
v8 = v5;
buffersize = v6;
maxproducts = atoi(v7);
sem_init(&mutex, 0, 1u);
sem_init(&empty, 0, buffersize);
sem_init(&full, 0, 0);
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
v19 = v4 + v5;
if ( v4 >= v5 )
v8 = v4;
arg = 1;
v9 = alloca(8LL * (v4 + v5));
pthread_attr_init(&attr);
v10 = 1;
v11 = (pthread_t *)&v18;
if ( v8 >= 1 )
{
v12 = 0LL;
do
{
if ( v4 < v10 )
{
if ( (int)arg <= v5 )
goto LABEL_10;
}
else
{
pthread_create(&newthread, &attr, (void *(*)(void *))producer, &arg);
v13 = arg;
v20 = v12 + 1;
*(&v18 + v12) = newthread;
printf("\tProducer %d created \n", v13);
v12 = v20;
if ( (int)arg <= v5 )
{
LABEL_10:
pthread_create(&newthread, &attr, (void *(*)(void *))consumer, &arg);
v14 = arg;
v20 = v12 + 1;
*(&v18 + v12) = newthread;
printf("\tConsumer %d created \n", v14);
v12 = v20;
goto LABEL_7;
}
}
LABEL_7:
func0(v3);
v10 = arg + 1;
arg = v10;
}
while ( v8 >= v10 );
}
if ( v19 > 0 )
{
v15 = (pthread_t *)(&v18 + (unsigned int)(v19 - 1) + 1);
do
{
v16 = *v11++;
pthread_join(v16, 0LL);
}
while ( v11 != v15 );
}
puts("joints done ");
result = 0;
}
else
{
fwrite("must be 4\n", 1uLL, 0xAuLL, stderr);
result = -1;
}
return result;
}

original_code:
int main(int argc, char* argv[])
{
 list = list_new();
 int maxproducers, maxconsumers;
 if (argc != 5 ) {
      fprintf(stderr, "must be 4\n");
      return -1;
   }
   maxproducers = atoi(argv[1]);
   maxconsumers = atoi(argv[2]);
   buffersize = atoi(argv[3]);
   maxproducts = atoi(argv[4]);
   sem_init(&mutex, 0, 1);
   sem_init(&empty, 0, buffersize);
   sem_init(&full, 0, 0);
  struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 srand(tv.tv_usec);
   int tmp;
   if(maxproducers >= maxconsumers)
    tmp = maxproducers;
 else
  tmp = maxconsumers;
 int counter = 1, t = 0;
   pthread_t tids[(maxconsumers + maxproducers)];
   pthread_t tid;
   pthread_attr_t attr;
   pthread_attr_init(&attr);
   while(counter <= tmp){
    if(counter <= maxproducers){
     pthread_create(&tid, &attr, producer, &counter);
       tids[t++] = tid;
       printf("\tProducer %d created \n", counter);
    }
    if(counter <= maxconsumers){
   pthread_create(&tid, &attr, consumer, &counter);
       tids[t++] = tid;
       printf("\tConsumer %d created \n", counter);
    }
    Sleep(100);
    counter++;
   }
  int z;
  for (z = 0; z < (maxconsumers+maxproducers); z++) {
      pthread_join(tids[z], ((void *)0));
  }
  printf("joints done \n");
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 list = list_new();
 int maxproducers; int maxconsumers;
 if (argc != 5 ) {
      fprintf(stderr, "must be 4\n");
      return -1;
   }
   maxproducers = atoi(argv[1]);
   maxconsumers = atoi(argv[2]);
   buffersize = atoi(argv[3]);
   maxproducts = atoi(argv[4]);
   sem_init(&mutex, 0, 1);
   sem_init(&empty, 0, buffersize);
   sem_init(&full, 0, 0);
  struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 srand(tv.tv_usec);
   int tmp;
   if(maxproducers >= maxconsumers)
    tmp = maxproducers;
 else
  tmp = maxconsumers;
 int counter = 1; int t = 0;
   unsigned long tids[-1];
   unsigned long tid;
   union pthread_attr_t attr;
   pthread_attr_init(&attr);
   while(counter <= tmp){
    if(counter <= maxproducers){
     pthread_create(&tid, &attr, producer, &counter);
       tids[t++] = tid;
       printf("\tProducer %d created \n", counter);
    }
    if(counter <= maxconsumers){
   pthread_create(&tid, &attr, consumer, &counter);
       tids[t++] = tid;
       printf("\tConsumer %d created \n", counter);
    }
    Sleep(100);
    counter++;
   }
  int z;
  for (z = 0; z < (maxconsumers+maxproducers); z++) {
      pthread_join(tids[z], ((void *)0));
  }
  printf("joints done \n");
  return 0;
}

variable_types: maxproducers int

variable_types: maxconsumers int

variable_types: tmp int

variable_types: counter int

variable_types: t int

variable_types:
tids
unsigned long [-1]

variable_types:
tid
unsigned long

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

variable_types: z int

return_type: int

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


decompiled_code:
_DWORD *list_new()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
_QWORD *v2; // rax

v0 = malloc(0x40uLL);
*v0 = 0;
v1 = v0;
v2 = malloc(0x10uLL);
*v2 = 0LL;
v2[1] = 0LL;
*((_QWORD *)v1 + 2) = v2;
*((_QWORD *)v1 + 1) = v2;
pthread_mutex_init((pthread_mutex_t *)(v1 + 6), 0LL);
return v1;
}

canonical_decompiled_code:
_DWORD *func7()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
_QWORD *v2; // rax

v0 = malloc(0x40uLL);
*v0 = 0;
v1 = v0;
v2 = malloc(0x10uLL);
*v2 = 0LL;
v2[1] = 0LL;
*((_QWORD *)v1 + 2) = v2;
*((_QWORD *)v1 + 1) = v2;
pthread_mutex_init((pthread_mutex_t *)(v1 + 6), 0LL);
return v1;
}

original_code:
List *list_new(void)
{
  List *l;
  l = (List *) malloc(sizeof(List));
  l->len = 0;
  l->first = l->last = (Node *) malloc(sizeof(Node));
  l->first->elm = ((void *)0);
  l->first->next = ((void *)0);
  pthread_mutex_init(&l->lock,((void *)0));
  return l;
}

canonical_original_code:
struct list *list_new()
{
  struct list *l;
  l = (struct list *) malloc(sizeof(List));
  l->len = 0;
  l->first = l->last = (struct node *) malloc(sizeof(Node));
  l->first->elm = ((void *)0);
  l->first->next = ((void *)0);
  pthread_mutex_init(&l->lock,((void *)0));
  return l;
}

variable_types: struct list { int len; struct node { void *elm; struct node *next; } *first; struct node *last; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } *

user_defined_types: struct list { int len; struct node *first; struct node *last; union pthread_mutex_t lock; }

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


decompiled_code:
int __fastcall list_add(__int64 a1, __int64 a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL) = a2;
++*(_DWORD *)a1;
*(_QWORD *)(a1 + 16) = a2;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL) = a2;
++*(_DWORD *)a1;
*(_QWORD *)(a1 + 16) = a2;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}

original_code:
void list_add(List *l, Node *n)
{
 pthread_mutex_lock(&l->lock);
 l->last->next = n;
 l->last = n;
 l->len++;
 pthread_mutex_unlock(&l->lock);
}

canonical_original_code:
void list_add(struct list *l, struct node *n)
{
 pthread_mutex_lock(&l->lock);
 l->last->next = n;
 l->last = n;
 l->len++;
 pthread_mutex_unlock(&l->lock);
}

variable_types:
n
struct node *

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


original_code:
Node *list_remove(List *l)
{
 if (l->len > 0) {
  pthread_mutex_lock(&l->lock);
  Node *n1st, *n2nd;
  n1st = l->first->next;
  n2nd = n1st->next;
  l->first->next = n2nd;
  l->len--;
  if (l->len == 0) {
   l->last = l->first;
  }
  pthread_mutex_unlock(&l->lock);
  return n1st;
  } else {
   return ((void *)0);
  }
}

canonical_original_code:
struct node *list_remove(struct list *l)
{
 if (l->len > 0) {
  pthread_mutex_lock(&l->lock);
  struct node *n1st; struct node *n2nd;
  n1st = l->first->next;
  n2nd = n1st->next;
  l->first->next = n2nd;
  l->len--;
  if (l->len == 0) {
   l->last = l->first;
  }
  pthread_mutex_unlock(&l->lock);
  return n1st;
  } else {
   return ((void *)0);
  }
}

variable_types: struct list { int len; struct node *first; struct node *last; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } *

return_type: struct node { void *elm; struct node *next; } *


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
Node *node_new(void)
{
  Node *n;
  n = (Node *) malloc(sizeof(Node));
  n->elm = ((void *)0);
  n->next = ((void *)0);
  return n;
}

canonical_original_code:
struct node *node_new()
{
  struct node *n;
  n = (struct node *) malloc(sizeof(Node));
  n->elm = ((void *)0);
  n->next = ((void *)0);
  return n;
}


creator

decompiled_code:
__int64 creator()
{
unsigned int **v0; // rbp
unsigned int *v1; // rax
int v2; // edx
int v3; // eax

v0 = (unsigned int **)node_new();
v1 = (unsigned int *)malloc(4uLL);
v2 = num;
*v0 = v1;
*v1 = v2;
num = v2 + 1;
v3 = rand();
sleep(v3 % 2 + 1);
printf("Adding Element: %d\n", **v0);
list_add(fifo, (__int64)v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int **v0; // rbp
unsigned int *v1; // rax
int v2; // edx
int v3; // eax

v0 = (unsigned int **)func10();
v1 = (unsigned int *)malloc(4uLL);
v2 = num;
*v0 = v1;
*v1 = v2;
num = v2 + 1;
v3 = rand();
sleep(v3 % 2 + 1);
printf("Adding Element: %d\n", **v0);
func8(fifo, (__int64)v0);
return 0LL;
}

original_code:
void *creator(void *param) {
  Node *n = node_new();
  n->elm = malloc(sizeof(int));
  *((int*)n->elm) = num++;
  sleep((rand() % 2) + 1);
  printf("Adding Element: %d\n", *((int*)n->elm));
  list_add(fifo, n);
  return 0;
}

canonical_original_code:
void *creator(void *param) {
  struct node *n = node_new();
  n->elm = malloc(sizeof(int));
  *((int *)n->elm) = num++;
  sleep((rand() % 2) + 1);
  printf("Adding Element: %d\n", *((int *)n->elm));
  list_add(fifo, n);
  return 0;
}


destroyer

decompiled_code:
void *__fastcall destroyer(void *a1)
{
int v1; // eax
unsigned int **v2; // rax
void **v3; // rbx

v1 = rand();
sleep(v1 % 2 + 1);
v2 = (unsigned int **)list_remove(fifo);
if ( v2 )
{
v3 = (void **)v2;
printf("Destroying Element: %d\n", **v2);
free(*v3);
}
else
{
puts("No elements in list");
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func12(void *a1)
{
int v1; // eax
unsigned int **v2; // rax
void **v3; // rbx

v1 = rand();
sleep(v1 % 2 + 1);
v2 = (unsigned int **)func9(fifo);
if ( v2 )
{
v3 = (void **)v2;
printf("Destroying Element: %d\n", **v2);
free(*v3);
}
else
{
puts("No elements in list");
}
return 0LL;
}

original_code:
void *destroyer(void *param) {
  sleep((rand() % 2) + 1);
  Node *n = list_remove(fifo);
  if (n == ((void *)0)) { printf("No elements in list\n"); }
  else {
  printf("Destroying Element: %d\n", *((int*)n->elm));
  free(n->elm);
  }
  return 0;
}

canonical_original_code:
void *destroyer(void *param) {
  sleep((rand() % 2) + 1);
  struct node *n = list_remove(fifo);
  if (n == ((void *)0)) { printf("No elements in list\n"); }
  else {
  printf("Destroying Element: %d\n", *((int *)n->elm));
  free(n->elm);
  }
  return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // eax
__int64 v5; // r13
void *v6; // rsp
pthread_t *v7; // rbx
__int64 v8; // r12
void *(*v9)(void *); // rdx
pthread_t v10; // rdi
int result; // eax
__int64 v12; // [rsp+0h] [rbp-80h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-78h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-70h] BYREF

if ( argc == 1 )
{
fwrite("You must give number of threads as input!\n", 1uLL, 0x2AuLL, _bss_start);
result = -1;
}
else if ( argc > 0 && (v3 = atoi(argv[1]), v3 <= 0) )
{
fprintf(_bss_start, "Number of threads must be larger than 0. Given: %d\n", (unsigned int)v3);
result = -1;
}
else
{
v4 = time(0LL);
srand(v4);
v5 = (unsigned int)atoi(argv[1]);
printf("Number of threads: %d\n", v5);
fifo = list_new();
v6 = alloca(8LL * (int)v5);
v7 = (pthread_t *)&v12;
pthread_attr_init(&attr);
if ( (int)v5 > 0 )
{
v8 = 0LL;
do
{
v9 = (void *(*)(void *))creator;
if ( (int)v5 >> 1 <= (int)v8 )
v9 = destroyer;
pthread_create(&newthread, &attr, v9, 0LL);
*(&v12 + v8++) = newthread;
}
while ( v8 != (unsigned int)v5 );
do
{
v10 = *v7++;
pthread_join(v10, 0LL);
}
while ( v7 != (pthread_t *)(&v12 + (unsigned int)(v5 - 1) + 1) );
}
puts(" --------\nJoins done ");
printf("Elements still in list: %d\n", *(unsigned int *)fifo);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // eax
__int64 v5; // r13
void *v6; // rsp
pthread_t *v7; // rbx
__int64 v8; // r12
void *(*v9)(void *); // rdx
pthread_t v10; // rdi
int result; // eax
__int64 v12; // [rsp+0h] [rbp-80h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-78h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-70h] BYREF

if ( argc == 1 )
{
fwrite("You must give number of threads as input!\n", 1uLL, 0x2AuLL, _bss_start);
result = -1;
}
else if ( argc > 0 && (v3 = atoi(argv[1]), v3 <= 0) )
{
fprintf(_bss_start, "Number of threads must be larger than 0. Given: %d\n", (unsigned int)v3);
result = -1;
}
else
{
v4 = time(0LL);
srand(v4);
v5 = (unsigned int)atoi(argv[1]);
printf("Number of threads: %d\n", v5);
fifo = func7();
v6 = alloca(8LL * (int)v5);
v7 = (pthread_t *)&v12;
pthread_attr_init(&attr);
if ( (int)v5 > 0 )
{
v8 = 0LL;
do
{
v9 = (void *(*)(void *))creator;
if ( (int)v5 >> 1 <= (int)v8 )
v9 = destroyer;
pthread_create(&newthread, &attr, v9, 0LL);
*(&v12 + v8++) = newthread;
}
while ( v8 != (unsigned int)v5 );
do
{
v10 = *v7++;
pthread_join(v10, 0LL);
}
while ( v7 != (pthread_t *)(&v12 + (unsigned int)(v5 - 1) + 1) );
}
puts(" --------\nJoins done ");
printf("Elements still in list: %d\n", *(unsigned int *)fifo);
result = 0;
}
return result;
}

original_code:
int main(int argc, char* argv[])
{
 if (argc == 1) {
  fprintf(stderr, "You must give number of threads as input!\n");
  return -1;
 }
  if (argc > 0 && atoi(argv[1]) <= 0) {
    fprintf(stderr, "Number of threads must be larger than 0. Given: %d\n", atoi(argv[1]));
    return -1;
  }
  srand(time(((void *)0)));
  int nbthreads = atoi(argv[1]);
  printf("Number of threads: %d\n", nbthreads);
  fifo = list_new();
  pthread_t tids[nbthreads];
  pthread_t tid;
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  int i;
  for (i = 0; i < nbthreads; i++) {
  if (i < nbthreads/2) {
   pthread_create(&tid, &attr, creator, ((void *)0));
   tids[i] = tid;
  } else {
   pthread_create(&tid, &attr, destroyer, ((void *)0));
   tids[i] = tid;
  }
  }
  int z;
  for (z = 0; z < nbthreads; z++) {
  pthread_join(tids[z], ((void *)0));
  }
  printf(" --------\nJoins done \n");
  printf("Elements still in list: %d\n",fifo->len);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if (argc == 1) {
  fprintf(stderr, "You must give number of threads as input!\n");
  return -1;
 }
  if (argc > 0 && atoi(argv[1]) <= 0) {
    fprintf(stderr, "Number of threads must be larger than 0. Given: %d\n", atoi(argv[1]));
    return -1;
  }
  srand(time(((void *)0)));
  int nbthreads = atoi(argv[1]);
  printf("Number of threads: %d\n", nbthreads);
  fifo = list_new();
  unsigned long tids[-1];
  unsigned long tid;
  union pthread_attr_t attr;
  pthread_attr_init(&attr);
  int i;
  for (i = 0; i < nbthreads; i++) {
  if (i < nbthreads/2) {
   pthread_create(&tid, &attr, creator, ((void *)0));
   tids[i] = tid;
  } else {
   pthread_create(&tid, &attr, destroyer, ((void *)0));
   tids[i] = tid;
  }
  }
  int z;
  for (z = 0; z < nbthreads; z++) {
  pthread_join(tids[z], ((void *)0));
  }
  printf(" --------\nJoins done \n");
  printf("Elements still in list: %d\n",fifo->len);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nbthreads int

variable_types: i int

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


runner

decompiled_code:
void __fastcall __noreturn runner(void *a1)
{
int v1; // ebx
__int64 v2; // rdx
int v3; // ebp
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
unsigned int v7; // [rsp+0h] [rbp-24h]

v1 = *(_DWORD *)a1;
v2 = *((unsigned int *)a1 + 1);
*((_QWORD *)a1 + 1) = 0LL;
if ( v1 > (int)v2 )
{
v6 = 0.0;
}
else
{
v3 = v2 + 1;
do
{
v4 = (double)v1;
if ( (double)v1 < 0.0 )
{
v7 = v2;
v5 = sqrt(v4);
v2 = v7;
}
else
{
v5 = sqrt(v4);
}
v6 = v5 + *((double *)a1 + 1);
++v1;
*((double *)a1 + 1) = v6;
}
while ( v1 != v3 );
}
printf("RUNNER [ Start: %d || End: %d || Result: %f ] \n", *(unsigned int *)a1, v2, v6);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebx
__int64 v2; // rdx
int v3; // ebp
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
unsigned int v7; // [rsp+0h] [rbp-24h]

v1 = *(_DWORD *)a1;
v2 = *((unsigned int *)a1 + 1);
*((_QWORD *)a1 + 1) = 0LL;
if ( v1 > (int)v2 )
{
v6 = 0.0;
}
else
{
v3 = v2 + 1;
do
{
v4 = (double)v1;
if ( (double)v1 < 0.0 )
{
v7 = v2;
v5 = sqrt(v4);
v2 = v7;
}
else
{
v5 = sqrt(v4);
}
v6 = v5 + *((double *)a1 + 1);
++v1;
*((double *)a1 + 1) = v6;
}
while ( v1 != v3 );
}
printf("RUNNER [ Start: %d || End: %d || Result: %f ] \n", *(unsigned int *)a1, v2, v6);
pthread_exit(0LL);
}

original_code:
void *runner(void *param) {
    int i = ((Workload*) param)->_begin;
    int upper = ((Workload*) param)->_end;
    ((Workload*) param)->_result = 0;
    for (i; i <= upper; i++)
        ((Workload*) param)->_result += sqrt(i);
    printf("RUNNER [ Start: %d || End: %d || Result: %f ] \n", ((Workload*) param)->_begin, upper, ((Workload*) param)->_result);
    pthread_exit(0);
}

canonical_original_code:
void *runner(void *param) {
    int i = ((Workload*) param)->_begin;
    int upper = ((Workload*) param)->_end;
    ((struct workload *) param)->_result = 0;
    for (i; i <= upper; i++)
        ((struct workload *) param)->_result += sqrt(i);
    printf("RUNNER [ Start: %d || End: %d || Result: %f ] \n", ((struct workload *) param)->_begin, upper, ((struct workload *) param)->_result);
    pthread_exit(0);
}

variable_types:
param
void *

variable_types: upper int

user_defined_types: struct workload { int _begin; int _end; double _result; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // eax
int v5; // eax
int v6; // er13
signed __int64 v7; // rax
void *v8; // rsp
void *v9; // rsp
_BYTE *v10; // r15
void *v11; // rax
void *v12; // r12
clock_t v13; // rax
__int64 v14; // rbx
int v15; // er14
float v16; // xmm0_4
int *v17; // rcx
pthread_t v18; // rdx
pthread_t *v19; // r14
__int64 *v20; // rbx
__int64 v21; // r13
pthread_t v22; // rdi
double v23; // xmm0_8
__int64 v24; // rax
int v25; // ebx
signed __int64 v27; // rax
void *v28; // rsp
void *v29; // rsp
_BYTE v30[8]; // [rsp+0h] [rbp-D0h] BYREF
__int64 *v31; // [rsp+8h] [rbp-C8h]
void *ptr; // [rsp+10h] [rbp-C0h]
__int64 *v33; // [rsp+18h] [rbp-B8h]
unsigned __int64 v34; // [rsp+20h] [rbp-B0h]
clock_t v35; // [rsp+28h] [rbp-A8h]
_BYTE *v36; // [rsp+30h] [rbp-A0h]
__int64 v37; // [rsp+38h] [rbp-98h]
float v38; // [rsp+44h] [rbp-8Ch]
pthread_t *v39; // [rsp+48h] [rbp-88h]
pthread_t newthread; // [rsp+58h] [rbp-78h] BYREF
pthread_attr_t attr; // [rsp+60h] [rbp-70h] BYREF

v36 = v30;
if ( argc <= 1 )
{
fwrite("usage: a.out <integer value>\n", 1uLL, 0x1DuLL, stderr);
}
else
{
v4 = atoi(argv[1]);
v38 = *(float *)&v4;
if ( v4 < 0 )
{
fprintf(stderr, "%d must be >= 0\n", (unsigned int)v4);
}
else
{
v5 = atoi(argv[2]);
v6 = v5;
if ( argc == 2 )
{
if ( SLODWORD(v38) >= v5 )
goto LABEL_19;
goto LABEL_18;
}
if ( v5 > 0 )
{
if ( SLODWORD(v38) >= v5 )
{
sum = 0LL;
v7 = 16 * ((unsigned __int64)(8LL * v5 + 15) >> 4);
v8 = alloca(v7);
v39 = (pthread_t *)v30;
v9 = alloca(v7);
goto LABEL_7;
}
LABEL_18:
v6 = LODWORD(v38);
fprintf(stderr, "Too many threads according to calculations. Threads in use will be: %d\n", LODWORD(v38));
LABEL_19:
sum = 0LL;
v27 = 16 * ((unsigned __int64)(8LL * v6 + 15) >> 4);
v28 = alloca(v27);
v39 = (pthread_t *)v30;
v29 = alloca(v27);
if ( v6 <= 0 )
{
pthread_attr_init(&attr);
v35 = clock();
puts("joins done ");
LABEL_16:
v25 = clock();
free(v3);
printf("sum = %f\n", *(double *)&sum);
printf("Time spent %f seconds \n", (float)((float)((float)v25 - (float)(int)v35) / 1000000.0));
return 0;
}
LABEL_7:
v10 = v30;
v34 = 8LL * (unsigned int)(v6 - 1);
v33 = (__int64 *)&v30[v34 + 8];
do
{
v10 += 8;
v11 = malloc(0x10uLL);
*((_QWORD *)v10 - 1) = v11;
}
while ( v10 != &v30[8 * (v6 - 1) + 8] );
v12 = v11;
pthread_attr_init(&attr);
v13 = clock();
ptr = v12;
v35 = v13;
v37 = (unsigned int)v6;
v31 = (__int64 *)v30;
v14 = 0LL;
v38 = (float)SLODWORD(v38) / (float)v6;
do
{
v15 = (int)((float)((float)(int)v14 * v38) + 1.0);
v16 = (float)(v14 + 1) * v38;
printf("BlockSize for thread %d is %d\n", (unsigned int)v14, (unsigned int)((int)v16 - v15 + 1));
v17 = *(int **)&v30[8 * v14];
*v17 = v15;
v17[1] = (int)v16;
pthread_create(&newthread, &attr, runner, v17);
v18 = newthread;
v39[v14++] = newthread;
printf("T %d Id %d \n", (unsigned int)v14, v18);
}
while ( v37 != v14 );
v19 = v39;
v3 = ptr;
v20 = v31;
v21 = (__int64)&v39[v34 / 8 + 1];
do
{
v22 = *v19++;
pthread_join(v22, 0LL);
}
while ( v19 != (pthread_t *)v21 );
puts("joins done ");
v23 = *(double *)∑
do
{
v24 = *v20++;
v23 = v23 + *(double *)(v24 + 8);
}
while ( v20 != v33 );
sum = *(_QWORD *)&v23;
goto LABEL_16;
}
fprintf(stderr, "%d must assign > 0 threads \n", (unsigned int)v5);
}
}
return -1;
}

original_code:
int main(int argc, char *argv[]) {
    clock_t t1, t2;
    pthread_t tid;
    pthread_attr_t attr;
    if (argc < 2) {
        fprintf(stderr, "usage: a.out <integer value>\n");
        return -1;
    }
    if (atoi(argv[1]) < 0) {
        fprintf(stderr, "%d must be >= 0\n", atoi(argv[1]));
        return -1;
    }
    if (argc > 2 && atoi(argv[2]) <= 0) {
        fprintf(stderr, "%d must assign > 0 threads \n", atoi(argv[2]));
        return -1;
    }
    int MAXPROCESSES = atoi(argv[2]);
    int MAXCALCS = atoi(argv[1]);
    if (MAXPROCESSES > MAXCALCS) {
     MAXPROCESSES = MAXCALCS;
     fprintf(stderr, "Too many threads according to calculations. Threads in use will be: %d\n", MAXCALCS);
    }
    sum = 0;
    pthread_t tids[MAXPROCESSES];
    Workload * wlds[MAXPROCESSES];
    int z;
    Workload *w;
    for (z = 0; z < MAXPROCESSES; z++) {
        w = (Workload*) malloc(sizeof (Workload));
        wlds[z] = w;
    }
    pthread_attr_init(&attr);
    int t = 0, i = 0;
  t1 = clock();
  for (i; i < MAXPROCESSES; i++) {
   int s = (int)(((float) MAXCALCS / (float) MAXPROCESSES)*(float)(i)+1.0);
   int e = (int)(((float) MAXCALCS / (float) MAXPROCESSES)*(float)(i + 1));
   printf("BlockSize for thread %d is %d\n", i, e-s+1);
   wlds[i]->_begin = s;
   wlds[i]->_end = e;
   pthread_create(&tid, &attr, runner, wlds[t]);
      tids[t++] = tid;
   printf("T %d Id %d \n", t, (int) tid);
  }
    for (z = 0; z < MAXPROCESSES; z++) {
        pthread_join(tids[z], ((void *)0));
    }
    printf("joins done \n");
    for (z = 0; z < MAXPROCESSES; z++) {
        sum += wlds[z]->_result;
    }
    t2 = clock();
    free(w);
    printf("sum = %f\n", sum);
    float diff = ((float)t2 - (float)t1)/((__clock_t) 1000000);
    printf("Time spent %f seconds \n", diff);
}

canonical_original_code:
int main(int argc, char *argv[]) {
    long t1; long t2;
    unsigned long tid;
    union pthread_attr_t attr;
    if (argc < 2) {
        fprintf(stderr, "usage: a.out <integer value>\n");
        return -1;
    }
    if (atoi(argv[1]) < 0) {
        fprintf(stderr, "%d must be >= 0\n", atoi(argv[1]));
        return -1;
    }
    if (argc > 2 && atoi(argv[2]) <= 0) {
        fprintf(stderr, "%d must assign > 0 threads \n", atoi(argv[2]));
        return -1;
    }
    int MAXPROCESSES = atoi(argv[2]);
    int MAXCALCS = atoi(argv[1]);
    if (MAXPROCESSES > MAXCALCS) {
     MAXPROCESSES = MAXCALCS;
     fprintf(stderr, "Too many threads according to calculations. Threads in use will be: %d\n", MAXCALCS);
    }
    sum = 0;
    unsigned long tids[-1];
    struct workload *wlds[-1];
    int z;
    struct workload *w;
    for (z = 0; z < MAXPROCESSES; z++) {
        w = (struct workload *) malloc(sizeof (Workload));
        wlds[z] = w;
    }
    pthread_attr_init(&attr);
    int t = 0; int i = 0;
  t1 = clock();
  for (i; i < MAXPROCESSES; i++) {
   int s = (int)(((float) MAXCALCS / (float) MAXPROCESSES)*(float)(i)+1.0);
   int e = (int)(((float) MAXCALCS / (float) MAXPROCESSES)*(float)(i + 1));
   printf("BlockSize for thread %d is %d\n", i, e-s+1);
   wlds[i]->_begin = s;
   wlds[i]->_end = e;
   pthread_create(&tid, &attr, runner, wlds[t]);
      tids[t++] = tid;
   printf("T %d Id %d \n", t, (int) tid);
  }
    for (z = 0; z < MAXPROCESSES; z++) {
        pthread_join(tids[z], ((void *)0));
    }
    printf("joins done \n");
    for (z = 0; z < MAXPROCESSES; z++) {
        sum += wlds[z]->_result;
    }
    t2 = clock();
    free(w);
    printf("sum = %f\n", sum);
    float diff = ((float)t2 - (float)t1)/((__clock_t) 1000000);
    printf("Time spent %f seconds \n", diff);
}

variable_types: MAXPROCESSES int

variable_types: MAXCALCS int

variable_types: struct workload { int _begin; int _end; double _result; } *[-1]

variable_types: s int

variable_types: e int

variable_types: diff float


fdirection

repo: indigoid/dasher

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

result = 0LL;
if ( fabs(a1 - a2) >= 0.0001 )
{
result = 1LL;
if ( a1 <= a2 )
result = (unsigned int)-(a2 > a1);
}
return result;
}

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

result = 0LL;
if ( fabs(a1 - a2) >= 0.0001 )
{
result = 1LL;
if ( a1 <= a2 )
result = (unsigned int)-(a2 > a1);
}
return result;
}

original_code:
int fdirection(float r, float p) {
 if (fabs(r-p) < 0.0001)
  return 0;
 if (p < r)
  return 1;
 if (p > r)
  return -1;
 return 0;
}

variable_types: r float

variable_types: p float


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm2_8
double v4; // rbx
int v5; // eax

*(_QWORD *)&v3 = 3240099840LL;
v4 = -10.0;
while ( 1 )
{
v5 = fdirection(*(_QWORD *)&argc, argv, envp, 3.1415961, v3);
if ( !v5 )
break;
*(_QWORD *)&argc = "ref=%.6f; pos=%.6f; dir=%s\n";
argv = (const char **)(&directions)[v5 + 1];
*(float *)&v3 = v4 + 0.0005;
v4 = *(float *)&v3;
printf("ref=%.6f; pos=%.6f; dir=%s\n", 3.141596078872681, *(float *)&v3, (const char *)argv);
*(_QWORD *)&v3 = LODWORD(v3);
}
printf("ref=%.6f; pos=%.6f; dir=%s\n", 3.141596078872681, v4, off_404038);
return 0;
}

original_code:
int main(int argc, char** argv) {
 float pos = -10.0;
 float ref = 3.141596;
 int dir;
 while ((dir = fdirection(ref,pos)) != 0) {
  pos += 0.0005;
  printf("ref=%.6f; pos=%.6f; dir=%s\n",
   ref, pos, directions[dir+1]);
 }
 printf("ref=%.6f; pos=%.6f; dir=%s\n",
  ref, pos, directions[dir+1]);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 float pos = -10.0;
 float ref = 3.141596;
 int dir;
 while ((dir = fdirection(ref,pos)) != 0) {
  pos += 0.0005;
  printf("ref=%.6f; pos=%.6f; dir=%s\n",
   ref, pos, directions[dir+1]);
 }
 printf("ref=%.6f; pos=%.6f; dir=%s\n",
  ref, pos, directions[dir+1]);
 return 0;
}

variable_types:
argv
char **

variable_types: pos float

variable_types: ref float

variable_types: dir int


repo: inforichland/Stackem

decompiled_code:
__int64 __fastcall op_mul_func(__int64 a1)
{
__int64 v1; // rsi
int v2; // eax
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = v2;
result = 4LL * v2;
*(_DWORD *)(v1 + result) *= *(_DWORD *)(v1 + result - 4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rsi
int v2; // eax
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = v2;
result = 4LL * v2;
*(_DWORD *)(v1 + result) *= *(_DWORD *)(v1 + result - 4);
return result;
}

original_code:
void op_mul_func(Machine *m) {
  ((m->stackPointer)++);
  m->memory[m->stackPointer] *= m->memory[m->stackPointer - 1];
}

canonical_original_code:
void op_mul_func(struct Machine *m) {
  ((m->stackPointer)++);
  m->memory[m->stackPointer] *= m->memory[m->stackPointer - 1];
}

variable_types: struct Machine { int memorySize; int *memory; int stackPointer; void (**opcode_funcs)(struct Machine *); int programCounter; int halted; int *programCodes; int programCodesCount; int result; } *


decompiled_code:
__int64 __fastcall op_div_func(__int64 a1)
{
__int64 v1; // rcx
int v2; // edx
_DWORD *v3; // rsi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = v2;
v3 = (_DWORD *)(v1 + 4LL * v2);
result = (unsigned int)(*v3 / *(v3 - 1));
*v3 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rcx
int v2; // edx
_DWORD *v3; // rsi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = v2;
v3 = (_DWORD *)(v1 + 4LL * v2);
result = (unsigned int)(*v3 / *(v3 - 1));
*v3 = result;
return result;
}

original_code:
void op_div_func(Machine *m) {
  ((m->stackPointer)++);
  m->memory[m->stackPointer] /= m->memory[m->stackPointer - 1];
}

canonical_original_code:
void op_div_func(struct Machine *m) {
  ((m->stackPointer)++);
  m->memory[m->stackPointer] /= m->memory[m->stackPointer - 1];
}

user_defined_types: struct Machine { int memorySize; int *memory; int stackPointer; void (**opcode_funcs)(struct Machine *); int programCounter; int halted; int *programCodes; int programCodesCount; int result; }


original_code:
void op_lit_func(Machine *m) {
  push(m, m->programCodes[++m->programCounter]);
}

canonical_original_code:
void op_lit_func(struct Machine *m) {
  push(m, m->programCodes[++m->programCounter]);
}


decompiled_code:
int __fastcall op_brn_func(__int64 a1)
{
__int64 v1; // rsi

v1 = *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4LL * *(int *)(a1 + 32) + 4);
*(_DWORD *)(a1 + 32) = v1 - 1;
return printf(" Branching to: %d\n", v1);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__int64 v1; // rsi

v1 = *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4LL * *(int *)(a1 + 32) + 4);
*(_DWORD *)(a1 + 32) = v1 - 1;
return printf(" Branching to: %d\n", v1);
}

original_code:
void op_brn_func(Machine *m) {
  m->programCounter = m->programCodes[m->programCounter + 1] - 1;
  printf ("  Branching to: %d\n", m->programCounter + 1);
}

canonical_original_code:
void op_brn_func(struct Machine *m) {
  m->programCounter = m->programCodes[m->programCounter + 1] - 1;
  printf ("  Branching to: %d\n", m->programCounter + 1);
}


decompiled_code:
int __fastcall op_bze_func(__int64 a1)
{
__int64 v1; // rax
int result; // eax
__int64 v3; // rsi

v1 = *(int *)(a1 + 32);
if ( *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * *(int *)(a1 + 16)) )
{
result = v1 + 1;
*(_DWORD *)(a1 + 32) = result;
}
else
{
v3 = *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4 * v1 + 4);
*(_DWORD *)(a1 + 32) = v3 - 1;
result = printf(" Branching to: %d\n", v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 v1; // rax
int result; // eax
__int64 v3; // rsi

v1 = *(int *)(a1 + 32);
if ( *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * *(int *)(a1 + 16)) )
{
result = v1 + 1;
*(_DWORD *)(a1 + 32) = result;
}
else
{
v3 = *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4 * v1 + 4);
*(_DWORD *)(a1 + 32) = v3 - 1;
result = printf(" Branching to: %d\n", v3);
}
return result;
}

original_code:
void op_bze_func(Machine *m) {
  if (m->memory[m->stackPointer] == 0) {
    m->programCounter = m->programCodes[m->programCounter + 1] - 1;
    printf ("  Branching to: %d\n", m->programCounter + 1);
  }
  else
    m->programCounter++;
}

canonical_original_code:
void op_bze_func(struct Machine *m) {
  if (m->memory[m->stackPointer] == 0) {
    m->programCounter = m->programCodes[m->programCounter + 1] - 1;
    printf ("  Branching to: %d\n", m->programCounter + 1);
  }
  else
    m->programCounter++;
}


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

puts(" Halting");
*(_DWORD *)(a1 + 36) = 1;
result = pop(a1);
*(_DWORD *)(a1 + 52) = result;
return result;
}

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

puts(" Halting");
*(_DWORD *)(a1 + 36) = 1;
result = pop(a1);
*(_DWORD *)(a1 + 52) = result;
return result;
}

original_code:
void op_hlt_func(Machine *m) {
  printf ("  Halting\n");
  m->halted = 1;
  m->result = pop(m);
}

canonical_original_code:
void op_hlt_func(struct Machine *m) {
  printf ("  Halting\n");
  m->halted = 1;
  m->result = pop(m);
}


runMachine

decompiled_code:
int __fastcall runMachine(__int64 a1)
{
int v1; // ecx
int result; // eax
__int64 v3; // rax
int v4; // edx

v1 = *(_DWORD *)(a1 + 36);
result = *(_DWORD *)a1 - 1;
*(_DWORD *)(a1 + 16) = result;
if ( !v1 )
{
result = *(_DWORD *)(a1 + 32);
while ( *(_DWORD *)(a1 + 48) > result )
{
printf("Executing opcode: %d\n", *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4LL * result));
v3 = *(int *)(*(_QWORD *)(a1 + 40) + 4LL * *(int *)(a1 + 32));
if ( (unsigned int)v3 > 8 )
{
result = puts(" Invalid opcode!");
*(_DWORD *)(a1 + 52) = -1;
return result;
}
(*(void (__fastcall **)(__int64))(*(_QWORD *)(a1 + 24) + 8 * v3))(a1);
v4 = *(_DWORD *)(a1 + 36);
result = *(_DWORD *)(a1 + 32) + 1;
*(_DWORD *)(a1 + 32) = result;
if ( v4 )
return result;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int v1; // ecx
int result; // eax
__int64 v3; // rax
int v4; // edx

v1 = *(_DWORD *)(a1 + 36);
result = *(_DWORD *)a1 - 1;
*(_DWORD *)(a1 + 16) = result;
if ( !v1 )
{
result = *(_DWORD *)(a1 + 32);
while ( *(_DWORD *)(a1 + 48) > result )
{
printf("Executing opcode: %d\n", *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4LL * result));
v3 = *(int *)(*(_QWORD *)(a1 + 40) + 4LL * *(int *)(a1 + 32));
if ( (unsigned int)v3 > 8 )
{
result = puts(" Invalid opcode!");
*(_DWORD *)(a1 + 52) = -1;
return result;
}
(*(void (__fastcall **)(__int64))(*(_QWORD *)(a1 + 24) + 8 * v3))(a1);
v4 = *(_DWORD *)(a1 + 36);
result = *(_DWORD *)(a1 + 32) + 1;
*(_DWORD *)(a1 + 32) = result;
if ( v4 )
return result;
}
}
return result;
}

original_code:
void runMachine(Machine *m) {
  opcode_func_ptr currentOpcode;
  m->stackPointer = m->memorySize - 1;
  while (!m->halted && (m->programCounter < m->programCodesCount)) {
    printf ("Executing opcode: %d\n", m->programCodes[m->programCounter]);
    if (m->programCodes[m->programCounter] >= 0 &&
 m->programCodes[m->programCounter] < op_max) {
      currentOpcode = m->opcode_funcs[m->programCodes[m->programCounter]];
      currentOpcode(m);
      m->programCounter++;
    } else {
      printf ("  Invalid opcode!\n");
      m->result = -1;
      return;
    }
  }
}

canonical_original_code:
void runMachine(struct Machine *m) {
  void (*currentOpcode)(struct Machine *);
  m->stackPointer = m->memorySize - 1;
  while (!m->halted && (m->programCounter < m->programCodesCount)) {
    printf ("Executing opcode: %d\n", m->programCodes[m->programCounter]);
    if (m->programCodes[m->programCounter] >= 0 &&
 m->programCodes[m->programCounter] < op_max) {
      currentOpcode = m->opcode_funcs[m->programCodes[m->programCounter]];
      currentOpcode(m);
      m->programCounter++;
    } else {
      printf ("  Invalid opcode!\n");
      m->result = -1;
      return;
    }
  }
}

variable_types: void (*)(struct Machine { int memorySize; int *memory; int stackPointer; void (**opcode_funcs)(struct Machine *); int programCounter; int halted; int *programCodes; int programCodesCount; int result; } *)


destroyMachine

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

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

original_code:
void destroyMachine(Machine *m) {
  free(m->memory);
  free(m);
}

canonical_original_code:
void destroyMachine(struct Machine *m) {
  free(m->memory);
  free(m);
}


main

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

v3 = initMachine(512LL, &testCodes, 16LL, 2LL);
result = 1;
if ( v3 )
{
runMachine(v3);
printf("\nResult: %d\n", *(unsigned int *)(v3 + 52));
destroyMachine(v3);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv) {
  Machine *machine =
    initMachine(512, testCodes, sizeof(testCodes) / sizeof(int), 2);
  if (machine != ((void *)0)) {
    runMachine(machine);
    printf("\nResult: %d\n", machine->result);
    destroyMachine(machine);
    return 0;
  } else {
    return 1;
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  struct Machine *machine = initMachine(512, testCodes, sizeof(testCodes) / sizeof(int), 2);
  if (machine != ((void *)0)) {
    runMachine(machine);
    printf("\nResult: %d\n", machine->result);
    destroyMachine(machine);
    return 0;
  } else {
    return 1;
  }
}

variable_types: argc int


repo: ingramj/cba

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE savedregs[40]; // [rsp+0h] [rbp+0h] BYREF

init_bloom(savedregs, 1000LL, 4LL);
insert(savedregs, "Abracadabra");
if ( (unsigned int)lookup(savedregs, "Abracadabra") )
puts("Abracadabra!");
if ( (unsigned int)lookup(savedregs, "Alacazzam") )
puts("Alacazzam!");
free_bloom(savedregs);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE savedregs[40]; // [rsp+0h] [rbp+0h] BYREF

func7(savedregs, 1000LL, 4LL);
func11(savedregs, "Abracadabra");
if ( (unsigned int)func12(savedregs, "Abracadabra") )
puts("Abracadabra!");
if ( (unsigned int)func12(savedregs, "Alacazzam") )
puts("Alacazzam!");
func8(savedregs);
return 0;
}

original_code:
int
main(void)
{
 int passed, failed;
 passed = failed = 0;
 do { int r; printf("%-40s", "test_cba_alloc"); r = test_cba_alloc(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_allocate_zero"); r = test_allocate_zero(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_allocated_clear"); r = test_allocated_clear(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_negative_indices"); r = test_negative_indices(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_out_of_bounds"); r = test_out_of_bounds(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_set"); r = test_cba_set(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_set_all"); r = test_cba_set_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_set_all_empty"); r = test_set_all_empty(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_clear"); r = test_cba_clear(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_clear_all"); r = test_cba_clear_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_clear_all_empty"); r = test_clear_all_empty(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_set_then_clear"); r = test_set_then_clear(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_set_all_then_clear_all"); r = test_set_all_then_clear_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_toggle"); r = test_cba_toggle(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_toggle_all"); r = test_cba_toggle_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_set_even_then_toggle_all"); r = test_set_even_then_toggle_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_assign"); r = test_cba_assign(); if (r) { passed++; } else { failed++; } } while(0);
 printf("%d tests, %d passed, %d failed\n", failed + passed, passed, failed);
 return (failed ? 1 : 0);
}

canonical_original_code:
int main()
{
 int passed; int failed;
 passed = failed = 0;
 do { int r; printf("%-40s", "test_cba_alloc"); r = test_cba_alloc(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_allocate_zero"); r = test_allocate_zero(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_allocated_clear"); r = test_allocated_clear(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_negative_indices"); r = test_negative_indices(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_out_of_bounds"); r = test_out_of_bounds(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_set"); r = test_cba_set(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_set_all"); r = test_cba_set_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_set_all_empty"); r = test_set_all_empty(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_clear"); r = test_cba_clear(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_clear_all"); r = test_cba_clear_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_clear_all_empty"); r = test_clear_all_empty(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_set_then_clear"); r = test_set_then_clear(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_set_all_then_clear_all"); r = test_set_all_then_clear_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_toggle"); r = test_cba_toggle(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_toggle_all"); r = test_cba_toggle_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_set_even_then_toggle_all"); r = test_set_even_then_toggle_all(); if (r) { passed++; } else { failed++; } } while(0);
 do { int r; printf("%-40s", "test_cba_assign"); r = test_cba_assign(); if (r) { passed++; } else { failed++; } } while(0);
 printf("%d tests, %d passed, %d failed\n", failed + passed, passed, failed);
 return (failed ? 1 : 0);
}

variable_types: passed int

variable_types: failed int

variable_types: r int


original_code:
long
hash1(const char *s, long sz)
{
 long h;
 for (h = 5381; *s != '\0'; s++) {
  h = ((h << 5) + h) + (long)*s;
 }
 return h % sz;
}

canonical_original_code:
long hash1(char *s, long sz)
{
 long h;
 for (h = 5381; *s != '\0'; s++) {
  h = ((h << 5) + h) + (long)*s;
 }
 return h % sz;
}

variable_types:
s
char *

variable_types: sz long

variable_types: h long

return_type: long


decompiled_code:
__int64 __fastcall hash2(char *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rax

v2 = *a1;
if ( !(_BYTE)v2 )
return 0LL;
v3 = 0LL;
do
{
++a1;
v3 = v2 + 31 * v3;
v2 = *a1;
}
while ( (_BYTE)v2 );
return v3 % a2;
}

original_code:
long
hash2(const char *s, long sz)
{
 long h;
 for (h = 0; *s != '\0'; s++) {
  h = (long)*s + 31 * h;
 }
 return h % sz;
}

canonical_original_code:
long hash2(char *s, long sz)
{
 long h;
 for (h = 0; *s != '\0'; s++) {
  h = (long)*s + 31 * h;
 }
 return h % sz;
}


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

result = 0LL;
if ( a1 > 0 )
result = ((unsigned __int64)(a1 - 1) >> 5) + 1;
return result;
}

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

result = 0LL;
if ( a1 > 0 )
result = ((unsigned __int64)(a1 - 1) >> 5) + 1;
return result;
}

original_code:
static long
uint_array_size(long bits)
{
 return (bits <= 0) ? 0 : ((bits - 1) / ((sizeof(unsigned int)) * 8) + 1);
}

variable_types: bits long


check

decompiled_code:
unsigned __int64 __fastcall check(__int64 *a1)
{
unsigned __int64 result; // rax
__int64 v2; // rdx

if ( !a1 )
__assert_fail("ba", "src/cba.c", 0x22u, "check");
if ( a1[1] < 0 )
__assert_fail("ba->array_sz >= 0", "src/cba.c", 0x23u, "check");
if ( *a1 < 0 )
__assert_fail("ba->bits >= 0", "src/cba.c", 0x24u, "check");
if ( !*a1 && a1[2] )
__assert_fail("ba->bits != 0 || ba->array == NULL", "src/cba.c", 0x25u, "check");
result = uint_array_size(*a1);
if ( v2 != result )
__assert_fail("ba->array_sz == uint_array_size(ba->bits)", "src/cba.c", 0x27u, "check");
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func14(__int64 *a1)
{
unsigned __int64 result; // rax
__int64 v2; // rdx

if ( !a1 )
__assert_fail("ba", "src/cba.c", 0x22u, "check");
if ( a1[1] < 0 )
__assert_fail("ba->array_sz >= 0", "src/cba.c", 0x23u, "check");
if ( *a1 < 0 )
__assert_fail("ba->bits >= 0", "src/cba.c", 0x24u, "check");
if ( !*a1 && a1[2] )
__assert_fail("ba->bits != 0 || ba->array == NULL", "src/cba.c", 0x25u, "check");
result = func13(*a1);
if ( v2 != result )
__assert_fail("ba->array_sz == uint_array_size(ba->bits)", "src/cba.c", 0x27u, "check");
return result;
}

original_code:
static void
check(struct bitarray *ba)
{
 ((ba) ? (void) (0) : __assert_fail ("ba", "src/cba.c", 34, __extension__ __PRETTY_FUNCTION__));
 ((ba->array_sz >= 0) ? (void) (0) : __assert_fail ("ba->array_sz >= 0", "src/cba.c", 35, __extension__ __PRETTY_FUNCTION__));
 ((ba->bits >= 0) ? (void) (0) : __assert_fail ("ba->bits >= 0", "src/cba.c", 36, __extension__ __PRETTY_FUNCTION__));
 ((ba->bits != 0 || ba->array == ((void *)0)) ? (void) (0) : __assert_fail ("ba->bits != 0 || ba->array == NULL", "src/cba.c", 37, __extension__ __PRETTY_FUNCTION__));
 ((ba->array == ((void *)0) || ba->bits != 0) ? (void) (0) : __assert_fail ("ba->array == NULL || ba->bits != 0", "src/cba.c", 38, __extension__ __PRETTY_FUNCTION__));
 ((ba->array_sz == uint_array_size(ba->bits)) ? (void) (0) : __assert_fail ("ba->array_sz == uint_array_size(ba->bits)", "src/cba.c", 39, __extension__ __PRETTY_FUNCTION__));
}

variable_types: struct bitarray { long bits; long array_sz; unsigned int *array; } *


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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
}
free(ptr);
}

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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
}
free(ptr);
}

original_code:
void
cba_free(struct bitarray *ba)
{
 if (ba && ba->array) {
  free(ba->array);
 }
 free(ba);
}

user_defined_types: struct bitarray { long bits; long array_sz; unsigned int *array; }


decompiled_code:
__int64 __fastcall cba_size(__int64 *a1)
{
check(a1);
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 *a1)
{
func14(a1);
return *a1;
}

original_code:
long
cba_size(struct bitarray *ba)
{
 check(ba);
 return ba->bits;
}


decompiled_code:
__int64 __fastcall cba_get(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

check(a1);
v2 = index_isra_0(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
result = (*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) & (1 << v2)) != 0;
return result;
}

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

func14(a1);
v2 = func15(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
result = (*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) & (1 << v2)) != 0;
return result;
}

original_code:
int
cba_get(struct bitarray *ba, long i)
{
 unsigned int b;
 check(ba);
 i = index(ba, i);
 if (i < 0) return -1;
 b = ba->array[i / ((sizeof(unsigned int)) * 8)] & (1 << ((i) % ((sizeof(unsigned int)) * 8)));
 return (b > 0) ? 1 : 0;
}

variable_types: i long

variable_types:
b
unsigned int


decompiled_code:
__int64 __fastcall cba_set(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

check(a1);
v2 = index_isra_0(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) |= 1 << v2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

func14(a1);
v2 = func15(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) |= 1 << v2;
result = 1LL;
}
return result;
}

original_code:
int
cba_set(struct bitarray *ba, long i)
{
 check(ba);
 i = index(ba, i);
 if (i < 0) return -1;
 ba->array[i / ((sizeof(unsigned int)) * 8)] |= (1 << ((i) % ((sizeof(unsigned int)) * 8)));
 return 1;
}


decompiled_code:
unsigned __int64 __fastcall cba_set_all(__int64 *a1)
{
unsigned __int64 result; // rax
void *v3; // rdi

result = check(a1);
v3 = (void *)a1[2];
if ( v3 )
result = (unsigned __int64)memset(v3, 255, 4 * a1[1]);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func20(__int64 *a1)
{
unsigned __int64 result; // rax
void *v3; // rdi

result = func14(a1);
v3 = (void *)a1[2];
if ( v3 )
result = (unsigned __int64)memset(v3, 255, 4 * a1[1]);
return result;
}

original_code:
void
cba_set_all(struct bitarray *ba)
{
 check(ba);
 if (ba->array) {
  memset(ba->array, 0xff, (ba->array_sz * (sizeof(unsigned int))));
 }
}


decompiled_code:
__int64 __fastcall cba_clear(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

check(a1);
v2 = index_isra_0(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) &= ~(1 << v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

func14(a1);
v2 = func15(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) &= ~(1 << v2);
result = 1LL;
}
return result;
}

original_code:
int
cba_clear(struct bitarray *ba, long i)
{
 check(ba);
 i = index(ba, i);
 if (i < 0) return -1;
 ba->array[i / ((sizeof(unsigned int)) * 8)] &= ~(1 << ((i) % ((sizeof(unsigned int)) * 8)));
 return 1;
}


decompiled_code:
unsigned __int64 __fastcall cba_clear_all(__int64 *a1)
{
unsigned __int64 result; // rax
void *v3; // rdi

result = check(a1);
v3 = (void *)a1[2];
if ( v3 )
result = (unsigned __int64)memset(v3, 0, 4 * a1[1]);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func22(__int64 *a1)
{
unsigned __int64 result; // rax
void *v3; // rdi

result = func14(a1);
v3 = (void *)a1[2];
if ( v3 )
result = (unsigned __int64)memset(v3, 0, 4 * a1[1]);
return result;
}

original_code:
void
cba_clear_all(struct bitarray *ba)
{
 check(ba);
 if (ba->array) {
  memset(ba->array, 0x00, (ba->array_sz * (sizeof(unsigned int))));
 }
}


decompiled_code:
__int64 __fastcall cba_toggle(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

check(a1);
v2 = index_isra_0(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) ^= 1 << v2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

func14(a1);
v2 = func15(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) ^= 1 << v2;
result = 1LL;
}
return result;
}

original_code:
int
cba_toggle(struct bitarray *ba, long i)
{
 check(ba);
 i = index(ba, i);
 if (i < 0) return -1;
 ba->array[i / ((sizeof(unsigned int)) * 8)] ^= (1 << ((i) % ((sizeof(unsigned int)) * 8)));
 return 1;
}


decompiled_code:
__int64 __fastcall cba_assign(__int64 *a1, __int64 a2, int a3)
{
__int64 v4; // rcx
__int64 result; // rax
int *v6; // rdx
int v7; // esi
int v8; // eax

check(a1);
v4 = index_isra_0(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v4 >= 0 )
{
v6 = (int *)(a1[2] + 4 * ((unsigned __int64)v4 >> 5));
v7 = *v6;
v8 = 1 << v4;
if ( a3 )
{
*v6 = v7 | v8;
result = 1LL;
}
else
{
*v6 = v7 & ~v8;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 *a1, __int64 a2, int a3)
{
__int64 v4; // rcx
__int64 result; // rax
int *v6; // rdx
int v7; // esi
int v8; // eax

func14(a1);
v4 = func15(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v4 >= 0 )
{
v6 = (int *)(a1[2] + 4 * ((unsigned __int64)v4 >> 5));
v7 = *v6;
v8 = 1 << v4;
if ( a3 )
{
*v6 = v7 | v8;
result = 1LL;
}
else
{
*v6 = v7 & ~v8;
result = 1LL;
}
}
return result;
}

original_code:
int
cba_assign(struct bitarray *ba, long i, int v)
{
 check(ba);
 if ((i = index(ba, i)) < 0) return -1;
 if (v == 0) {
  ba->array[i / ((sizeof(unsigned int)) * 8)] &= ~(1 << ((i) % ((sizeof(unsigned int)) * 8)));
 } else {
  ba->array[i / ((sizeof(unsigned int)) * 8)] |= (1 << ((i) % ((sizeof(unsigned int)) * 8)));
 }
 return 1;
}

variable_types: v int


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

result = 0LL;
if ( a1 > 0 )
result = ((unsigned __int64)(a1 - 1) >> 5) + 1;
return result;
}

canonical_original_code:
static long uint_array_size(long bits)
{
 return (bits <= 0) ? 0 : ((bits - 1) / ((sizeof(unsigned int)) * 8) + 1);
}


canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 *a1)
{
unsigned __int64 result; // rax
__int64 v2; // rdx

if ( !a1 )
__assert_fail("ba", "src/cba.c", 0x22u, "check");
if ( a1[1] < 0 )
__assert_fail("ba->array_sz >= 0", "src/cba.c", 0x23u, "check");
if ( *a1 < 0 )
__assert_fail("ba->bits >= 0", "src/cba.c", 0x24u, "check");
if ( !*a1 && a1[2] )
__assert_fail("ba->bits != 0 || ba->array == NULL", "src/cba.c", 0x25u, "check");
result = func6(*a1);
if ( v2 != result )
__assert_fail("ba->array_sz == uint_array_size(ba->bits)", "src/cba.c", 0x27u, "check");
return result;
}

canonical_original_code:
static void check(struct bitarray *ba)
{
 ((ba) ? (void) (0) : __assert_fail ("ba", "src/cba.c", 34, __extension__ __PRETTY_FUNCTION__));
 ((ba->array_sz >= 0) ? (void) (0) : __assert_fail ("ba->array_sz >= 0", "src/cba.c", 35, __extension__ __PRETTY_FUNCTION__));
 ((ba->bits >= 0) ? (void) (0) : __assert_fail ("ba->bits >= 0", "src/cba.c", 36, __extension__ __PRETTY_FUNCTION__));
 ((ba->bits != 0 || ba->array == ((void *)0)) ? (void) (0) : __assert_fail ("ba->bits != 0 || ba->array == NULL", "src/cba.c", 37, __extension__ __PRETTY_FUNCTION__));
 ((ba->array == ((void *)0) || ba->bits != 0) ? (void) (0) : __assert_fail ("ba->array == NULL || ba->bits != 0", "src/cba.c", 38, __extension__ __PRETTY_FUNCTION__));
 ((ba->array_sz == uint_array_size(ba->bits)) ? (void) (0) : __assert_fail ("ba->array_sz == uint_array_size(ba->bits)", "src/cba.c", 39, __extension__ __PRETTY_FUNCTION__));
}


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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
}
free(ptr);
}

canonical_original_code:
void cba_free(struct bitarray *ba)
{
 if (ba && ba->array) {
  free(ba->array);
 }
 free(ba);
}


canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1)
{
func7(a1);
return *a1;
}

canonical_original_code:
long cba_size(struct bitarray *ba)
{
 check(ba);
 return ba->bits;
}


canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

func7(a1);
v2 = func8(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
result = (*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) & (1 << v2)) != 0;
return result;
}

canonical_original_code:
int cba_get(struct bitarray *ba, long i)
{
 unsigned int b;
 check(ba);
 i = index(ba, i);
 if (i < 0) return -1;
 b = ba->array[i / ((sizeof(unsigned int)) * 8)] & (1 << ((i) % ((sizeof(unsigned int)) * 8)));
 return (b > 0) ? 1 : 0;
}


canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

func7(a1);
v2 = func8(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) |= 1 << v2;
result = 1LL;
}
return result;
}

canonical_original_code:
int cba_set(struct bitarray *ba, long i)
{
 check(ba);
 i = index(ba, i);
 if (i < 0) return -1;
 ba->array[i / ((sizeof(unsigned int)) * 8)] |= (1 << ((i) % ((sizeof(unsigned int)) * 8)));
 return 1;
}


canonical_decompiled_code:
unsigned __int64 __fastcall func13(__int64 *a1)
{
unsigned __int64 result; // rax
void *v3; // rdi

result = func7(a1);
v3 = (void *)a1[2];
if ( v3 )
result = (unsigned __int64)memset(v3, 255, 4 * a1[1]);
return result;
}

canonical_original_code:
void cba_set_all(struct bitarray *ba)
{
 check(ba);
 if (ba->array) {
  memset(ba->array, 0xff, (ba->array_sz * (sizeof(unsigned int))));
 }
}


canonical_decompiled_code:
__int64 __fastcall func14(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

func7(a1);
v2 = func8(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) &= ~(1 << v2);
result = 1LL;
}
return result;
}

canonical_original_code:
int cba_clear(struct bitarray *ba, long i)
{
 check(ba);
 i = index(ba, i);
 if (i < 0) return -1;
 ba->array[i / ((sizeof(unsigned int)) * 8)] &= ~(1 << ((i) % ((sizeof(unsigned int)) * 8)));
 return 1;
}


canonical_decompiled_code:
unsigned __int64 __fastcall func15(__int64 *a1)
{
unsigned __int64 result; // rax
void *v3; // rdi

result = func7(a1);
v3 = (void *)a1[2];
if ( v3 )
result = (unsigned __int64)memset(v3, 0, 4 * a1[1]);
return result;
}

canonical_original_code:
void cba_clear_all(struct bitarray *ba)
{
 check(ba);
 if (ba->array) {
  memset(ba->array, 0x00, (ba->array_sz * (sizeof(unsigned int))));
 }
}


canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

func7(a1);
v2 = func8(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
{
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v2 >> 5)) ^= 1 << v2;
result = 1LL;
}
return result;
}

canonical_original_code:
int cba_toggle(struct bitarray *ba, long i)
{
 check(ba);
 i = index(ba, i);
 if (i < 0) return -1;
 ba->array[i / ((sizeof(unsigned int)) * 8)] ^= (1 << ((i) % ((sizeof(unsigned int)) * 8)));
 return 1;
}


canonical_decompiled_code:
__int64 __fastcall func17(__int64 *a1, __int64 a2, int a3)
{
__int64 v4; // rcx
__int64 result; // rax
int *v6; // rdx
int v7; // esi
int v8; // eax

func7(a1);
v4 = func8(*a1, a2);
result = 0xFFFFFFFFLL;
if ( v4 >= 0 )
{
v6 = (int *)(a1[2] + 4 * ((unsigned __int64)v4 >> 5));
v7 = *v6;
v8 = 1 << v4;
if ( a3 )
{
*v6 = v7 | v8;
result = 1LL;
}
else
{
*v6 = v7 & ~v8;
result = 1LL;
}
}
return result;
}

canonical_original_code:
int cba_assign(struct bitarray *ba, long i, int v)
{
 check(ba);
 if ((i = index(ba, i)) < 0) return -1;
 if (v == 0) {
  ba->array[i / ((sizeof(unsigned int)) * 8)] &= ~(1 << ((i) % ((sizeof(unsigned int)) * 8)));
 } else {
  ba->array[i / ((sizeof(unsigned int)) * 8)] |= (1 << ((i) % ((sizeof(unsigned int)) * 8)));
 }
 return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebx

printf("%-40s", "test_cba_alloc");
if ( (unsigned int)test_cba_alloc() )
{
v4 = 0;
v3 = 1;
}
else
{
v3 = 0;
v4 = 1;
}
printf("%-40s", "test_allocate_zero");
if ( (unsigned int)test_allocate_zero() )
++v3;
else
++v4;
printf("%-40s", "test_allocated_clear");
if ( (unsigned int)test_allocated_clear() )
++v3;
else
++v4;
printf("%-40s", "test_negative_indices");
if ( (unsigned int)test_negative_indices() )
++v3;
else
++v4;
printf("%-40s", "test_out_of_bounds");
if ( (unsigned int)test_out_of_bounds() )
++v3;
else
++v4;
printf("%-40s", "test_cba_set");
if ( (unsigned int)test_cba_set() )
++v3;
else
++v4;
printf("%-40s", "test_cba_set_all");
if ( (unsigned int)test_cba_set_all() )
++v3;
else
++v4;
printf("%-40s", "test_set_all_empty");
if ( (unsigned int)test_set_all_empty() )
++v3;
else
++v4;
printf("%-40s", "test_cba_clear");
if ( (unsigned int)test_cba_clear() )
++v3;
else
++v4;
printf("%-40s", "test_cba_clear_all");
if ( (unsigned int)test_cba_clear_all() )
++v3;
else
++v4;
printf("%-40s", "test_clear_all_empty");
if ( (unsigned int)test_clear_all_empty() )
++v3;
else
++v4;
printf("%-40s", "test_set_then_clear");
if ( (unsigned int)test_set_then_clear() )
++v3;
else
++v4;
printf("%-40s", "test_set_all_then_clear_all");
if ( (unsigned int)test_set_all_then_clear_all() )
++v3;
else
++v4;
printf("%-40s", "test_cba_toggle");
if ( (unsigned int)test_cba_toggle() )
++v3;
else
++v4;
printf("%-40s", "test_cba_toggle_all");
if ( (unsigned int)test_cba_toggle_all() )
++v3;
else
++v4;
printf("%-40s", "test_set_even_then_toggle_all");
if ( (unsigned int)test_set_even_then_toggle_all() )
++v3;
else
++v4;
printf("%-40s", "test_cba_assign");
if ( (unsigned int)test_cba_assign() )
++v3;
else
++v4;
printf("%d tests, %d passed, %d failed\n", v3 + v4, v3, v4);
return v4 != 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebx

printf("%-40s", "test_cba_alloc");
if ( (unsigned int)func0() )
{
v4 = 0;
v3 = 1;
}
else
{
v3 = 0;
v4 = 1;
}
printf("%-40s", "test_allocate_zero");
if ( (unsigned int)func1() )
++v3;
else
++v4;
printf("%-40s", "test_allocated_clear");
if ( (unsigned int)func2() )
++v3;
else
++v4;
printf("%-40s", "test_negative_indices");
if ( (unsigned int)func3() )
++v3;
else
++v4;
printf("%-40s", "test_out_of_bounds");
if ( (unsigned int)func4() )
++v3;
else
++v4;
printf("%-40s", "test_cba_set");
if ( (unsigned int)func5() )
++v3;
else
++v4;
printf("%-40s", "test_cba_set_all");
if ( (unsigned int)func6() )
++v3;
else
++v4;
printf("%-40s", "test_set_all_empty");
if ( (unsigned int)func7() )
++v3;
else
++v4;
printf("%-40s", "test_cba_clear");
if ( (unsigned int)func8() )
++v3;
else
++v4;
printf("%-40s", "test_cba_clear_all");
if ( (unsigned int)func9() )
++v3;
else
++v4;
printf("%-40s", "test_clear_all_empty");
if ( (unsigned int)func10() )
++v3;
else
++v4;
printf("%-40s", "test_set_then_clear");
if ( (unsigned int)func11() )
++v3;
else
++v4;
printf("%-40s", "test_set_all_then_clear_all");
if ( (unsigned int)func12() )
++v3;
else
++v4;
printf("%-40s", "test_cba_toggle");
if ( (unsigned int)func13() )
++v3;
else
++v4;
printf("%-40s", "test_cba_toggle_all");
if ( (unsigned int)func14() )
++v3;
else
++v4;
printf("%-40s", "test_set_even_then_toggle_all");
if ( (unsigned int)func15() )
++v3;
else
++v4;
printf("%-40s", "test_cba_assign");
if ( (unsigned int)func16() )
++v3;
else
++v4;
printf("%d tests, %d passed, %d failed\n", v3 + v4, v3, v4);
return v4 != 0;
}


repo: ingramj/dice

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

result = 1LL;
if ( *(_DWORD *)a1 >= *(_DWORD *)a2 )
result = (unsigned int)-(*(_DWORD *)a1 > *(_DWORD *)a2);
return result;
}

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

result = 1LL;
if ( *(_DWORD *)a1 >= *(_DWORD *)a2 )
result = (unsigned int)-(*(_DWORD *)a1 > *(_DWORD *)a2);
return result;
}

original_code:
static int
compare_int_descending(const void *ap, const void *bp)
{
 int a = *(int *)ap;
 int b = *(int *)bp;
 if (a < b) {
  return 1;
 } else if (a > b) {
  return -1;
 }
 return 0;
}

canonical_original_code:
static int compare_int_descending(void *ap, void *bp)
{
 int a = *(int *)ap;
 int b = *(int *)bp;
 if (a < b) {
  return 1;
 } else if (a > b) {
  return -1;
 }
 return 0;
}

variable_types:
ap
void *

variable_types:
bp
void *

variable_types: a int

variable_types: b int


decompiled_code:
__int64 pop_seq_stack()
{
__int64 result; // rax

result = 6LL * --seq_stack_p;
seq_stack[result] = 0;
dword_10E8[result] = 0;
return result * 4;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

result = 6LL * --seq_stack_p;
seq_stack[result] = 0;
dword_10E8[result] = 0;
return result * 4;
}

original_code:
static void
pop_seq_stack(void)
{
 seq_stack_p--;
 seq_stack[seq_stack_p].sum = 0;
 seq_stack[seq_stack_p].size = 0;
}

canonical_original_code:
static void pop_seq_stack()
{
 seq_stack_p--;
 seq_stack[seq_stack_p].sum = 0;
 seq_stack[seq_stack_p].size = 0;
}


decompiled_code:
__int64 __fastcall addto_seq(__int64 a1, int a2)
{
int v3; // edx
__int64 result; // rax
void *v5; // rdi
void *v6; // rax
void *v7; // rax

v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
result = *(int *)(a1 + 8);
v5 = *(void **)(a1 + 16);
if ( v3 <= (int)result )
{
v6 = realloc(v5, 8LL * v3);
v5 = v6;
if ( !v6 )
_assert_fail("new_vals != NULL", "evaluate.c", 0xA7u, "addto_seq");
*(_QWORD *)(a1 + 16) = v6;
result = *(int *)(a1 + 8);
*(_DWORD *)(a1 + 4) *= 2;
}
}
else
{
v7 = calloc(8uLL, 4uLL);
*(_QWORD *)(a1 + 16) = v7;
v5 = v7;
if ( !v7 )
_assert_fail("s->vals != NULL", "evaluate.c", 0xA3u, "addto_seq");
*(_DWORD *)(a1 + 4) = 8;
result = *(int *)(a1 + 8);
}
*(_DWORD *)(a1 + 8) = result + 1;
*((_DWORD *)v5 + result) = a2;
*(_DWORD *)a1 += a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
int v3; // edx
__int64 result; // rax
void *v5; // rdi
void *v6; // rax
void *v7; // rax

v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
result = *(int *)(a1 + 8);
v5 = *(void **)(a1 + 16);
if ( v3 <= (int)result )
{
v6 = realloc(v5, 8LL * v3);
v5 = v6;
if ( !v6 )
_assert_fail("new_vals != NULL", "evaluate.c", 0xA7u, "addto_seq");
*(_QWORD *)(a1 + 16) = v6;
result = *(int *)(a1 + 8);
*(_DWORD *)(a1 + 4) *= 2;
}
}
else
{
v7 = calloc(8uLL, 4uLL);
*(_QWORD *)(a1 + 16) = v7;
v5 = v7;
if ( !v7 )
_assert_fail("s->vals != NULL", "evaluate.c", 0xA3u, "addto_seq");
*(_DWORD *)(a1 + 4) = 8;
result = *(int *)(a1 + 8);
}
*(_DWORD *)(a1 + 8) = result + 1;
*((_DWORD *)v5 + result) = a2;
*(_DWORD *)a1 += a2;
return result;
}

original_code:
static void
addto_seq(seq_t *s, int val)
{
 ((void) sizeof ((s != ((void *)0)) ? 1 : 0), __extension__ ({ if (s != ((void *)0)) ; else __assert_fail ("s != NULL", "evaluate.c", 159, __extension__ __PRETTY_FUNCTION__); }));
 if (s->cap == 0) {
  s->vals = calloc(8, sizeof(int));
  ((void) sizeof ((s->vals != ((void *)0)) ? 1 : 0), __extension__ ({ if (s->vals != ((void *)0)) ; else __assert_fail ("s->vals != NULL", "evaluate.c", 163, __extension__ __PRETTY_FUNCTION__); }));
  s->cap = 8;
 } else if (s->size >= s->cap) {
  int *new_vals = realloc(s->vals, (s->cap*2) * sizeof(int));
  ((void) sizeof ((new_vals != ((void *)0)) ? 1 : 0), __extension__ ({ if (new_vals != ((void *)0)) ; else __assert_fail ("new_vals != NULL", "evaluate.c", 167, __extension__ __PRETTY_FUNCTION__); }));
  s->vals = new_vals;
  s->cap *= 2;
 }
 s->vals[s->size++] = val;
 s->sum += val;
}

canonical_original_code:
static void addto_seq(struct seq *s, int val)
{
 ((void) sizeof ((s != ((void *)0)) ? 1 : 0), __extension__ ({ if (s != ((void *)0)) ; else __assert_fail ("s != NULL", "evaluate.c", 159, __extension__ __PRETTY_FUNCTION__); }));
 if (s->cap == 0) {
  s->vals = calloc(8, sizeof(int));
  ((void) sizeof ((s->vals != ((void *)0)) ? 1 : 0), __extension__ ({ if (s->vals != ((void *)0)) ; else __assert_fail ("s->vals != NULL", "evaluate.c", 163, __extension__ __PRETTY_FUNCTION__); }));
  s->cap = 8;
 } else if (s->size >= s->cap) {
  int *new_vals = realloc(s->vals, (s->cap*2) * sizeof(int));
  ((void) sizeof ((new_vals != ((void *)0)) ? 1 : 0), __extension__ ({ if (new_vals != ((void *)0)) ; else __assert_fail ("new_vals != NULL", "evaluate.c", 167, __extension__ __PRETTY_FUNCTION__); }));
  s->vals = new_vals;
  s->cap *= 2;
 }
 s->vals[s->size++] = val;
 s->sum += val;
}

variable_types: struct seq { int sum; int cap; int size; int *vals; } *

variable_types: val int


original_code:
static void
clean_seq_stack(void)
{
 int i;
 for (i = 0; i < 1024; i++) {
  if (seq_stack[i].cap > 0) {
   seq_stack[i].cap = 0;
   free(seq_stack[i].vals);
  }
  seq_stack[i].size = seq_stack[i].sum = 0;
 }
 seq_stack_p = 0;
}

canonical_original_code:
static void clean_seq_stack()
{
 int i;
 for (i = 0; i < 1024; i++) {
  if (seq_stack[i].cap > 0) {
   seq_stack[i].cap = 0;
   free(seq_stack[i].vals);
  }
  seq_stack[i].size = seq_stack[i].sum = 0;
 }
 seq_stack_p = 0;
}

variable_types: i int


decompiled_code:
__int64 __fastcall copyn_seq(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbp
size_t v5; // rsi
__int64 result; // rax
__int64 v7; // rbp
__int64 v8; // rbx
int v9; // esi
const char *v10; // r8
const char *v11; // rcx

v4 = a3;
v5 = *(int *)(a2 + 8);
if ( (_DWORD)v5 )
{
if ( (int)v5 >= a3 )
{
qsort(*(void **)(a2 + 16), v5, 4uLL, (__compar_fn_t)compare_int_descending);
*(_DWORD *)(a1 + 8) = 0;
if ( (int)v4 > 0 )
{
v7 = 4 * v4;
v8 = 0LL;
do
{
v9 = *(_DWORD *)(*(_QWORD *)(a2 + 16) + v8);
v8 += 4LL;
addto_seq(a1, v9);
}
while ( v7 != v8 );
}
return 0LL;
}
v10 = "is";
if ( (_DWORD)v5 != 1 )
v10 = "are";
v11 = "die";
if ( a3 != 1 )
v11 = "dice";
fprintf(stderr, "can't keep %d %s, there %s only %d!\n", (unsigned int)a3, v11, v10, (unsigned int)v5);
result = 0xFFFFFFFFLL;
}
else
{
if ( !a3 )
{
qsort(*(void **)(a2 + 16), 0LL, 4uLL, (__compar_fn_t)compare_int_descending);
*(_DWORD *)(a1 + 8) = 0;
return 0LL;
}
fwrite("there aren't any dice to keep!\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbp
size_t v5; // rsi
__int64 result; // rax
__int64 v7; // rbp
__int64 v8; // rbx
int v9; // esi
const char *v10; // r8
const char *v11; // rcx

v4 = a3;
v5 = *(int *)(a2 + 8);
if ( (_DWORD)v5 )
{
if ( (int)v5 >= a3 )
{
qsort(*(void **)(a2 + 16), v5, 4uLL, (__compar_fn_t)compare_int_descending);
*(_DWORD *)(a1 + 8) = 0;
if ( (int)v4 > 0 )
{
v7 = 4 * v4;
v8 = 0LL;
do
{
v9 = *(_DWORD *)(*(_QWORD *)(a2 + 16) + v8);
v8 += 4LL;
func2(a1, v9);
}
while ( v7 != v8 );
}
return 0LL;
}
v10 = "is";
if ( (_DWORD)v5 != 1 )
v10 = "are";
v11 = "die";
if ( a3 != 1 )
v11 = "dice";
fprintf(stderr, "can't keep %d %s, there %s only %d!\n", (unsigned int)a3, v11, v10, (unsigned int)v5);
result = 0xFFFFFFFFLL;
}
else
{
if ( !a3 )
{
qsort(*(void **)(a2 + 16), 0LL, 4uLL, (__compar_fn_t)compare_int_descending);
*(_DWORD *)(a1 + 8) = 0;
return 0LL;
}
fwrite("there aren't any dice to keep!\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int
copyn_seq(seq_t *dest, seq_t *src, int num)
{
 int i;
 ((void) sizeof ((dest != ((void *)0)) ? 1 : 0), __extension__ ({ if (dest != ((void *)0)) ; else __assert_fail ("dest != NULL", "evaluate.c", 181, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "evaluate.c", 182, __extension__ __PRETTY_FUNCTION__); }));
 if (src->size == 0 && num != 0) {
  fprintf(stderr, "there aren't any dice to keep!\n");
  return -1;
 } else if (num > src->size) {
  fprintf(stderr, "can't keep %d %s, there %s only %d!\n",
          num, num == 1 ? "die" : "dice",
          src->size == 1 ? "is" : "are", src->size);
  return -1;
 }
 qsort(src->vals, src->size, sizeof(int), compare_int_descending);
 dest->size = 0;
 for (i = 0; i < num; i++) {
  addto_seq(dest, src->vals[i]);
 }
 return 0;
}

canonical_original_code:
static int copyn_seq(struct seq *dest, struct seq *src, int num)
{
 int i;
 ((void) sizeof ((dest != ((void *)0)) ? 1 : 0), __extension__ ({ if (dest != ((void *)0)) ; else __assert_fail ("dest != NULL", "evaluate.c", 181, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "evaluate.c", 182, __extension__ __PRETTY_FUNCTION__); }));
 if (src->size == 0 && num != 0) {
  fprintf(stderr, "there aren't any dice to keep!\n");
  return -1;
 } else if (num > src->size) {
  fprintf(stderr, "can't keep %d %s, there %s only %d!\n",
          num, num == 1 ? "die" : "dice",
          src->size == 1 ? "is" : "are", src->size);
  return -1;
 }
 qsort(src->vals, src->size, sizeof(int), compare_int_descending);
 dest->size = 0;
 for (i = 0; i < num; i++) {
  addto_seq(dest, src->vals[i]);
 }
 return 0;
}

variable_types:
src
struct seq *

variable_types: num int

user_defined_types: struct seq { int sum; int cap; int size; int *vals; }