decompiled_code:
char *list_new()
{
char *v0; // rbx
_QWORD *v1; // rax

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

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

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

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


repo: inau/Cloaked-computing-machine

decompiled_code:
int __fastcall list_add(__int64 a1, __int64 a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL) = a2;
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
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;
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
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 *

return_type: void

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

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

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

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


creator

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

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

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

v1 = (unsigned int **)func10();
*v1 = (unsigned int *)malloc(4uLL);
v2 = num++;
**v1 = v2;
v3 = rand();
sleep(v3 % 2 + 1);
printf("Adding Element: %d\n", **v1);
func8(fifo, (__int64)v1);
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;
}

variable_types:
param
void *

return_type: void *


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

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // eax
__int64 v5; // r12
void *v6; // rsp
__int64 v7; // rbx
int result; // eax
pthread_attr_t *v9; // rbx
pthread_attr_t attr; // [rsp+0h] [rbp-70h] BYREF
pthread_t newthread[7]; // [rsp+38h] [rbp-38h] 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 = (__int64)list_new();
v6 = alloca(8LL * (int)v5);
pthread_attr_init(&attr);
if ( (int)v5 > 0 )
{
v7 = 0LL;
do
{
if ( (int)v5 / 2 <= (int)v7 )
pthread_create(newthread, &attr, destroyer, 0LL);
else
pthread_create(newthread, &attr, creator, 0LL);
*(_QWORD *)&attr.__size[8 * v7++] = newthread[0];
}
while ( v7 != (unsigned int)v5 );
v9 = &attr;
do
{
pthread_join(v9->__align, 0LL);
v9 = (pthread_attr_t *)((char *)v9 + 8);
}
while ( v9 != (pthread_attr_t *)&attr.__size[8 * (unsigned int)(v5 - 1) + 8] );
}
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; // r12
void *v6; // rsp
__int64 v7; // rbx
int result; // eax
pthread_attr_t *v9; // rbx
pthread_attr_t attr; // [rsp+0h] [rbp-70h] BYREF
pthread_t newthread[7]; // [rsp+38h] [rbp-38h] 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 = (__int64)func7();
v6 = alloca(8LL * (int)v5);
pthread_attr_init(&attr);
if ( (int)v5 > 0 )
{
v7 = 0LL;
do
{
if ( (int)v5 / 2 <= (int)v7 )
pthread_create(newthread, &attr, destroyer, 0LL);
else
pthread_create(newthread, &attr, creator, 0LL);
*(_QWORD *)&attr.__size[8 * v7++] = newthread[0];
}
while ( v7 != (unsigned int)v5 );
v9 = &attr;
do
{
pthread_join(v9->__align, 0LL);
v9 = (pthread_attr_t *)((char *)v9 + 8);
}
while ( v9 != (pthread_attr_t *)&attr.__size[8 * (unsigned int)(v5 - 1) + 8] );
}
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:
tids
unsigned long [-1]

variable_types:
tid
unsigned long

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

variable_types: i int

variable_types: z int

return_type: int


runner

decompiled_code:
void __fastcall __noreturn runner(void *a1)
{
int v1; // ebx
int v2; // er13
double v3; // xmm0_8
double v4; // xmm0_8

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

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebx
int v2; // er13
double v3; // xmm0_8
double v4; // xmm0_8

v1 = *(_DWORD *)a1;
v2 = *((_DWORD *)a1 + 1);
*((_QWORD *)a1 + 1) = 0LL;
if ( v1 <= v2 )
{
do
{
v3 = (double)v1;
if ( (double)v1 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
*((double *)a1 + 1) = v4 + *((double *)a1 + 1);
++v1;
}
while ( v2 + 1 != v1 );
}
printf("RUNNER [ Start: %d || End: %d || Result: %f ] \n", *(unsigned int *)a1, (unsigned int)v2, *((double *)a1 + 1));
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: 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)
{
int v3; // eax
int v4; // er14
int v5; // eax
int v6; // er13
void *v7; // rsp
void *v8; // rsp
void *v10; // rsp
void *v11; // rsp
_QWORD *v12; // rbx
_BYTE *v13; // r12
void *v14; // rax
__int64 v15; // r12
__int64 v16; // rbx
__int64 v17; // r14
__int64 v18; // rsi
int v19; // er13
float v20; // xmm0_4
int *v21; // rcx
pthread_t v22; // rdx
__int64 v23; // r12
pthread_t *v24; // rbx
__int64 v25; // r13
double v26; // xmm0_8
int v27; // ebx
_BYTE v28[8]; // [rsp+0h] [rbp-C0h] BYREF
__int64 v29; // [rsp+8h] [rbp-B8h]
_BYTE *v30; // [rsp+10h] [rbp-B0h]
unsigned __int64 v31; // [rsp+18h] [rbp-A8h]
void *ptr; // [rsp+20h] [rbp-A0h]
clock_t v33; // [rsp+28h] [rbp-98h]
_BYTE *v34; // [rsp+30h] [rbp-90h]
pthread_t *v35; // [rsp+38h] [rbp-88h]
__int64 v36; // [rsp+40h] [rbp-80h]
_BYTE *v37; // [rsp+48h] [rbp-78h]
pthread_attr_t attr; // [rsp+50h] [rbp-70h] BYREF
pthread_t newthread[7]; // [rsp+88h] [rbp-38h] BYREF

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

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

variable_types: s int

variable_types: e int

variable_types: diff float

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


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

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

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)
{
int v1; // eax
__int64 result; // rax

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

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

v1 = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = v1;
result = 4LL * v1;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + result) *= *(_DWORD *)(*(_QWORD *)(a1 + 8) + 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)
{
int v1; // edx
_DWORD *v2; // rsi
__int64 result; // rax

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

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

v1 = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = v1;
v2 = (_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * v1);
result = (unsigned int)(*v2 / *(v2 - 1));
*v2 = 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);
}


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 result; // eax
unsigned int v2; // eax

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

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int result; // eax
unsigned int v2; // eax

result = *(_DWORD *)a1 - 1;
for ( *(_DWORD *)(a1 + 16) = result; !*(_DWORD *)(a1 + 36); ++*(_DWORD *)(a1 + 32) )
{
result = *(_DWORD *)(a1 + 32);
if ( result >= *(_DWORD *)(a1 + 48) )
break;
printf("Executing opcode: %d\n", *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4LL * result));
v2 = *(_DWORD *)(*(_QWORD *)(a1 + 40) + 4LL * *(int *)(a1 + 32));
if ( v2 > 8 )
{
result = puts(" Invalid opcode!");
*(_DWORD *)(a1 + 52) = -1;
return result;
}
result = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)(a1 + 24) + 8LL * (int)v2))(a1);
}
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; // rbx
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;
  }
}


repo: ingramj/cba

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


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:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[40]; // [rsp+0h] [rbp-28h] BYREF

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

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

func7((__int64)v4, 1000LL, 4);
func11((__int64)v4, "Abracadabra");
if ( (unsigned int)func12((__int64)v4, "Abracadabra") )
puts("Abracadabra!");
if ( (unsigned int)func12((__int64)v4, "Alacazzam") )
puts("Alacazzam!");
func8((__int64)v4);
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


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)
{
__int64 v1; // rbx
unsigned __int64 result; // rax

if ( !a1 )
__assert_fail("ba", "src/cba.c", 0x22u, "check");
v1 = a1[1];
if ( v1 < 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 ( v1 != result )
__assert_fail("ba->array_sz == uint_array_size(ba->bits)", "src/cba.c", 0x27u, "check");
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func15(__int64 *a1)
{
__int64 v1; // rbx
unsigned __int64 result; // rax

if ( !a1 )
__assert_fail("ba", "src/cba.c", 0x22u, "check");
v1 = a1[1];
if ( v1 < 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 ( v1 != 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)
{
func15(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(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

func15(a1);
v2 = func14(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(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

func15(a1);
v2 = func14(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 = func15(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(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

func15(a1);
v2 = func14(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 = func15(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(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

func15(a1);
v2 = func14(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

check(a1);
v4 = index(a1, a2);
result = 0xFFFFFFFFLL;
if ( v4 >= 0 )
{
if ( a3 )
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v4 >> 5)) |= 1 << v4;
else
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v4 >> 5)) &= ~(1 << v4);
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 func8(__int64 *a1)
{
__int64 v1; // rbx
unsigned __int64 result; // rax

if ( !a1 )
__assert_fail("ba", "src/cba.c", 0x22u, "check");
v1 = a1[1];
if ( v1 < 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 ( v1 != 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)
{
func8(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

func8(a1);
v2 = func7(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

func8(a1);
v2 = func7(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 = func8(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

func8(a1);
v2 = func7(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 = func8(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

func8(a1);
v2 = func7(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 func18(__int64 *a1, __int64 a2, int a3)
{
__int64 v4; // rcx
__int64 result; // rax

func8(a1);
v4 = func7(a1, a2);
result = 0xFFFFFFFFLL;
if ( v4 >= 0 )
{
if ( a3 )
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v4 >> 5)) |= 1 << v4;
else
*(_DWORD *)(a1[2] + 4 * ((unsigned __int64)v4 >> 5)) &= ~(1 << v4);
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; // ebx
unsigned int v4; // ebp

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; // ebx
unsigned int v4; // ebp

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
__int64 v1; // rcx

result = --seq_stack_p;
v1 = 3LL * seq_stack_p;
seq_stack[2 * v1] = 0;
dword_1128[2 * v1] = 0;
return result;
}

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

result = --seq_stack_p;
v1 = 3LL * seq_stack_p;
seq_stack[2 * v1] = 0;
dword_1128[2 * v1] = 0;
return result;
}

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 v2; // eax
__int64 v3; // rdx
__int64 result; // rax
void *v5; // rax
void *v6; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax
void *v5; // rax
void *v6; // rax

if ( !a1 )
_assert_fail("s != NULL", "evaluate.c", 0x9Fu, "addto_seq");
v2 = *(_DWORD *)(a1 + 4);
if ( v2 )
{
if ( v2 <= *(_DWORD *)(a1 + 8) )
{
v6 = realloc(*(void **)(a1 + 16), 8LL * v2);
if ( !v6 )
_assert_fail("new_vals != NULL", "evaluate.c", 0xA7u, "addto_seq");
*(_QWORD *)(a1 + 16) = v6;
*(_DWORD *)(a1 + 4) *= 2;
}
}
else
{
v5 = calloc(8uLL, 4uLL);
*(_QWORD *)(a1 + 16) = v5;
if ( !v5 )
_assert_fail("s->vals != NULL", "evaluate.c", 0xA3u, "addto_seq");
*(_DWORD *)(a1 + 4) = 8;
}
v3 = *(_QWORD *)(a1 + 16);
LODWORD(result) = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = result + 1;
result = (int)result;
*(_DWORD *)(v3 + 4LL * (int)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)
{
int v5; // esi
__int64 v6; // r13
__int64 v7; // rbx
__int64 result; // rax
const char *v9; // r8
const char *v10; // rcx

if ( !a1 )
_assert_fail("dest != NULL", "evaluate.c", 0xB5u, "copyn_seq");
if ( !a2 )
_assert_fail("src != NULL", "evaluate.c", 0xB6u, "copyn_seq");
v5 = *(_DWORD *)(a2 + 8);
if ( a3 && !v5 )
{
fwrite("there aren't any dice to keep!\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
else if ( v5 < a3 )
{
v9 = "is";
if ( v5 != 1 )
v9 = "are";
v10 = "die";
if ( a3 != 1 )
v10 = "dice";
fprintf(stderr, "can't keep %d %s, there %s only %d!\n", (unsigned int)a3, v10, v9, (unsigned int)v5);
result = 0xFFFFFFFFLL;
}
else
{
qsort(*(void **)(a2 + 16), v5, 4uLL, (__compar_fn_t)compare_int_descending);
*(_DWORD *)(a1 + 8) = 0;
if ( a3 <= 0 )
{
result = 0LL;
}
else
{
v6 = 4LL * (unsigned int)(a3 - 1) + 4;
v7 = 0LL;
do
{
addto_seq(a1, *(_DWORD *)(*(_QWORD *)(a2 + 16) + v7));
v7 += 4LL;
}
while ( v7 != v6 );
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3)
{
int v5; // esi
__int64 v6; // r13
__int64 v7; // rbx
__int64 result; // rax
const char *v9; // r8
const char *v10; // rcx

if ( !a1 )
_assert_fail("dest != NULL", "evaluate.c", 0xB5u, "copyn_seq");
if ( !a2 )
_assert_fail("src != NULL", "evaluate.c", 0xB6u, "copyn_seq");
v5 = *(_DWORD *)(a2 + 8);
if ( a3 && !v5 )
{
fwrite("there aren't any dice to keep!\n", 1uLL, 0x1FuLL, stderr);
result = 0xFFFFFFFFLL;
}
else if ( v5 < a3 )
{
v9 = "is";
if ( v5 != 1 )
v9 = "are";
v10 = "die";
if ( a3 != 1 )
v10 = "dice";
fprintf(stderr, "can't keep %d %s, there %s only %d!\n", (unsigned int)a3, v10, v9, (unsigned int)v5);
result = 0xFFFFFFFFLL;
}
else
{
qsort(*(void **)(a2 + 16), v5, 4uLL, (__compar_fn_t)compare_int_descending);
*(_DWORD *)(a1 + 8) = 0;
if ( a3 <= 0 )
{
result = 0LL;
}
else
{
v6 = 4LL * (unsigned int)(a3 - 1) + 4;
v7 = 0LL;
do
{
func2(a1, *(_DWORD *)(*(_QWORD *)(a2 + 16) + v7));
v7 += 4LL;
}
while ( v7 != v6 );
result = 0LL;
}
}
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; }


decompiled_code:
__int64 __fastcall eval_op(__int64 a1, __int64 a2)
{
unsigned int v2; // edx
__int64 result; // rax
int v4; // er12
int v5; // ebp
__int64 v6; // rdx
int v7; // ebx
unsigned int v8; // er12
int v9; // eax
int v10; // ebp
int *v11; // rsi
__int64 v12; // rdx
__int64 v13; // rbp
__int64 v14; // rbx
int v15; // ebp
int v16; // er12
__int64 v17; // rdx
int v18; // ebx
int v19; // er12
int v20; // ebp
__int64 v21; // rdx
int v22; // ebx
int v23; // ebp
int v24; // er12
__int64 v25; // rdx
int v26; // ebx
int v27; // er12
int v28; // ebp
__int64 v29; // rdx
int v30; // ebx
int v31[4]; // [rsp+0h] [rbp-38h] BYREF
void *ptr; // [rsp+10h] [rbp-28h]

v31[2] = 0;
v31[1] = 0;
v31[0] = 0;
ptr = 0LL;
if ( seq_stack_p <= 1 )
{
fwrite("not enough operands\n", 1uLL, 0x14uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v2 = a1 + 6;
if ( (unsigned int)a1 < 0xFFFFFFFA )
{
fwrite("unrecognized operation\n", 1uLL, 0x17uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
switch ( (int)a1 )
{
case -6:
v27 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v2);
v28 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v29);
v30 = seq_stack_p;
addto_seq((__int64)&seq_stack[6 * seq_stack_p], v28 - v27);
seq_stack_p = v30 + 1;
result = 0LL;
break;
case -5:
v23 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v2);
v24 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v25);
v26 = seq_stack_p;
addto_seq((__int64)&seq_stack[6 * seq_stack_p], v23 + v24);
seq_stack_p = v26 + 1;
result = 0LL;
break;
case -4:
v19 = seq_stack[6 * seq_stack_p - 6];
if ( v19 )
{
pop_seq_stack(a1, a2, v2);
v20 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v21);
v22 = seq_stack_p;
addto_seq((__int64)&seq_stack[6 * seq_stack_p], v20 / v19);
seq_stack_p = v22 + 1;
result = 0LL;
}
else
{
fwrite("attempted to divide by 0\n", 1uLL, 0x19uLL, stderr);
result = 0xFFFFFFFFLL;
}
break;
case -3:
v15 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v2);
v16 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v17);
v18 = seq_stack_p;
addto_seq((__int64)&seq_stack[6 * seq_stack_p], v16 * v15);
seq_stack_p = v18 + 1;
result = 0LL;
break;
case -2:
v10 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v2);
v11 = &seq_stack[6 * seq_stack_p - 6];
if ( (int)copyn_seq((__int64)v31, (__int64)v11, v10) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
pop_seq_stack(v31, v11, v12);
if ( v10 > 0 )
{
v13 = 4LL * (unsigned int)v10;
v14 = 0LL;
do
{
addto_seq((__int64)&seq_stack[6 * seq_stack_p], *(_DWORD *)((char *)ptr + v14));
v14 += 4LL;
}
while ( v14 != v13 );
}
++seq_stack_p;
free(ptr);
result = 0LL;
}
break;
case -1:
v4 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v2);
v5 = seq_stack[6 * seq_stack_p - 6];
pop_seq_stack(a1, a2, v6);
if ( v4 )
{
v7 = 0;
v8 = v4 + 1;
if ( v5 > 0 )
{
do
{
v9 = random_range(1LL, v8);
addto_seq((__int64)&seq_stack[6 * seq_stack_p], v9);
++v7;
}
while ( v5 != v7 );
}
++seq_stack_p;
result = 0LL;
}
else
{
fwrite("cannot roll a zero-sided die\n", 1uLL, 0x1DuLL, stderr);
result = (unsigned int)a1;
}
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned int v2; // edx
__int64 result; // rax
int v4; // er12
int v5; // ebp
__int64 v6; // rdx
int v7; // ebx
unsigned int v8; // er12
int v9; // eax
int v10; // ebp
int *v11; // rsi
__int64 v12; // rdx
__int64 v13; // rbp
__int64 v14; // rbx
int v15; // ebp
int v16; // er12
__int64 v17; // rdx
int v18; // ebx
int v19; // er12
int v20; // ebp
__int64 v21; // rdx
int v22; // ebx
int v23; // ebp
int v24; // er12
__int64 v25; // rdx
int v26; // ebx
int v27; // er12
int v28; // ebp
__int64 v29; // rdx
int v30; // ebx
int v31[4]; // [rsp+0h] [rbp-38h] BYREF
void *ptr; // [rsp+10h] [rbp-28h]

v31[2] = 0;
v31[1] = 0;
v31[0] = 0;
ptr = 0LL;
if ( seq_stack_p <= 1 )
{
fwrite("not enough operands\n", 1uLL, 0x14uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v2 = a1 + 6;
if ( (unsigned int)a1 < 0xFFFFFFFA )
{
fwrite("unrecognized operation\n", 1uLL, 0x17uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
switch ( (int)a1 )
{
case -6:
v27 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v2);
v28 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v29);
v30 = seq_stack_p;
func2((__int64)&seq_stack[6 * seq_stack_p], v28 - v27);
seq_stack_p = v30 + 1;
result = 0LL;
break;
case -5:
v23 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v2);
v24 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v25);
v26 = seq_stack_p;
func2((__int64)&seq_stack[6 * seq_stack_p], v23 + v24);
seq_stack_p = v26 + 1;
result = 0LL;
break;
case -4:
v19 = seq_stack[6 * seq_stack_p - 6];
if ( v19 )
{
func1(a1, a2, v2);
v20 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v21);
v22 = seq_stack_p;
func2((__int64)&seq_stack[6 * seq_stack_p], v20 / v19);
seq_stack_p = v22 + 1;
result = 0LL;
}
else
{
fwrite("attempted to divide by 0\n", 1uLL, 0x19uLL, stderr);
result = 0xFFFFFFFFLL;
}
break;
case -3:
v15 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v2);
v16 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v17);
v18 = seq_stack_p;
func2((__int64)&seq_stack[6 * seq_stack_p], v16 * v15);
seq_stack_p = v18 + 1;
result = 0LL;
break;
case -2:
v10 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v2);
v11 = &seq_stack[6 * seq_stack_p - 6];
if ( (int)func4((__int64)v31, (__int64)v11, v10) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
func1(v31, v11, v12);
if ( v10 > 0 )
{
v13 = 4LL * (unsigned int)v10;
v14 = 0LL;
do
{
func2((__int64)&seq_stack[6 * seq_stack_p], *(_DWORD *)((char *)ptr + v14));
v14 += 4LL;
}
while ( v14 != v13 );
}
++seq_stack_p;
free(ptr);
result = 0LL;
}
break;
case -1:
v4 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v2);
v5 = seq_stack[6 * seq_stack_p - 6];
func1(a1, a2, v6);
if ( v4 )
{
v7 = 0;
v8 = v4 + 1;
if ( v5 > 0 )
{
do
{
v9 = random_range(1LL, v8);
func2((__int64)&seq_stack[6 * seq_stack_p], v9);
++v7;
}
while ( v5 != v7 );
}
++seq_stack_p;
result = 0LL;
}
else
{
fwrite("cannot roll a zero-sided die\n", 1uLL, 0x1DuLL, stderr);
result = (unsigned int)a1;
}
break;
}
}
}
return result;
}

original_code:
static int
eval_op(int op)
{
 int i, n1, n2;
 seq_t *s1, s2;
 s2.sum = s2.cap = s2.size = 0;
 s2.vals = ((void *)0);
 if (seq_stack_p < 2) {
  fprintf(stderr, "not enough operands\n");
  return -1;
 }
 switch (op) {
 case -1:
  n2 = seq_stack[seq_stack_p - 1].sum;
  pop_seq_stack();
  n1 = seq_stack[seq_stack_p - 1].sum;
  pop_seq_stack();
  if (n2 == 0) {
   fprintf(stderr, "cannot roll a zero-sided die\n");
   return -1;
  }
  for (i = 0; i < n1; i++) {
   addto_seq(&seq_stack[seq_stack_p], random_range(1, n2+1));
  }
  seq_stack_p++;
  break;
 case -2:
  n1 = seq_stack[seq_stack_p - 1].sum;
  pop_seq_stack();
  s1 = &seq_stack[seq_stack_p - 1];
  if (copyn_seq(&s2, s1, n1) < 0) {
   return -1;
  }
  pop_seq_stack();
  for (i = 0; i < n1; i++) {
   addto_seq(&seq_stack[seq_stack_p], s2.vals[i]);
  }
  seq_stack_p++;
  free(s2.vals);
  break;
 case -3:
  do { n2 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); n1 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); addto_seq(&seq_stack[seq_stack_p], n1 * n2); seq_stack_p++; } while (0);
  break;
 case -4:
  if (seq_stack[seq_stack_p - 1].sum == 0) {
   fprintf(stderr, "attempted to divide by 0\n");
   return -1;
  }
  do { n2 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); n1 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); addto_seq(&seq_stack[seq_stack_p], n1 / n2); seq_stack_p++; } while (0);
  break;
 case -5:
  do { n2 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); n1 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); addto_seq(&seq_stack[seq_stack_p], n1 + n2); seq_stack_p++; } while (0);
  break;
 case -6:
  do { n2 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); n1 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); addto_seq(&seq_stack[seq_stack_p], n1 - n2); seq_stack_p++; } while (0);
  break;
 default:
  fprintf(stderr, "unrecognized operation\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
static int eval_op(int op)
{
 int i; int n1; int n2;
 struct seq *s1; struct seq s2;
 s2.sum = s2.cap = s2.size = 0;
 s2.vals = ((void *)0);
 if (seq_stack_p < 2) {
  fprintf(stderr, "not enough operands\n");
  return -1;
 }
 switch (op) {
 case -1:
  n2 = seq_stack[seq_stack_p - 1].sum;
  pop_seq_stack();
  n1 = seq_stack[seq_stack_p - 1].sum;
  pop_seq_stack();
  if (n2 == 0) {
   fprintf(stderr, "cannot roll a zero-sided die\n");
   return -1;
  }
  for (i = 0; i < n1; i++) {
   addto_seq(&seq_stack[seq_stack_p], random_range(1, n2+1));
  }
  seq_stack_p++;
  break;
 case -2:
  n1 = seq_stack[seq_stack_p - 1].sum;
  pop_seq_stack();
  s1 = &seq_stack[seq_stack_p - 1];
  if (copyn_seq(&s2, s1, n1) < 0) {
   return -1;
  }
  pop_seq_stack();
  for (i = 0; i < n1; i++) {
   addto_seq(&seq_stack[seq_stack_p], s2.vals[i]);
  }
  seq_stack_p++;
  free(s2.vals);
  break;
 case -3:
  do { n2 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); n1 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); addto_seq(&seq_stack[seq_stack_p], n1 * n2); seq_stack_p++; } while (0);
  break;
 case -4:
  if (seq_stack[seq_stack_p - 1].sum == 0) {
   fprintf(stderr, "attempted to divide by 0\n");
   return -1;
  }
  do { n2 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); n1 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); addto_seq(&seq_stack[seq_stack_p], n1 / n2); seq_stack_p++; } while (0);
  break;
 case -5:
  do { n2 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); n1 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); addto_seq(&seq_stack[seq_stack_p], n1 + n2); seq_stack_p++; } while (0);
  break;
 case -6:
  do { n2 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); n1 = seq_stack[seq_stack_p - 1].sum; pop_seq_stack(); addto_seq(&seq_stack[seq_stack_p], n1 - n2); seq_stack_p++; } while (0);
  break;
 default:
  fprintf(stderr, "unrecognized operation\n");
  return -1;
 }
 return 0;
}

variable_types: op int

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


decompiled_code:
void cleanup_evaluator()
{
clean_seq_stack();
op_stack_p = 0;
}

canonical_decompiled_code:
void func6()
{
func3();
op_stack_p = 0;
}

original_code:
void
cleanup_evaluator(void)
{
 clean_seq_stack();
 op_stack_p = 0;
}


evaluate

decompiled_code:
__int64 __fastcall evaluate(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // rdi
int v4; // ebp
int v5; // ebx
__int64 v6; // rdi
int v7; // ecx
__int64 v8; // rdi
__int64 result; // rax
int v10; // eax
__int64 v11; // rsi

v2 = get_token();
if ( (unsigned int)(v2 + 10) <= 1 )
{
LABEL_2:
while ( op_stack_p > 0 )
{
v3 = (unsigned int)op_stack[op_stack_p - 1];
if ( (unsigned int)(v3 + 8) <= 1 )
goto LABEL_32;
--op_stack_p;
if ( (int)eval_op(v3, a2) < 0 )
goto LABEL_24;
}
if ( seq_stack_p > 1 )
{
fprintf(stderr, "%d values left on the sequence stack; should be 1\n", (unsigned int)seq_stack_p);
result = 0xFFFFFFFFLL;
}
else
{
result = 0xFFFFFFFFLL;
if ( seq_stack_p )
{
v11 = (unsigned int)seq_stack[0];
printf("%d\n", (unsigned int)seq_stack[0]);
pop_seq_stack("%d\n", v11);
result = (unsigned int)-(v2 != -9);
}
}
return result;
}
while ( 1 )
{
if ( v2 >= 0 )
{
v4 = seq_stack_p;
if ( seq_stack_p > 1023 )
{
fprintf(stderr, "%s\n", "sequence stack overflow");
goto LABEL_24;
}
a2 = (unsigned int)v2;
addto_seq((__int64)&seq_stack[6 * seq_stack_p], v2);
seq_stack_p = v4 + 1;
goto LABEL_7;
}
if ( v2 >= -6 )
{
while ( 1 )
{
v7 = op_stack_p;
if ( op_stack_p <= 0 )
break;
a2 = (unsigned int)(op_stack_p - 1);
v8 = (unsigned int)op_stack[(int)a2];
if ( precedence[~v2] > precedence[~op_stack[(int)a2]] )
{
if ( op_stack_p > 511 )
goto LABEL_26;
break;
}
--op_stack_p;
if ( (int)eval_op(v8, a2) < 0 )
goto LABEL_24;
}
++op_stack_p;
op_stack[v7] = v2;
goto LABEL_7;
}
if ( v2 != -7 )
break;
v10 = op_stack_p;
if ( op_stack_p > 511 )
{
LABEL_26:
fprintf(stderr, "%s\n", "operator stack overflow");
goto LABEL_24;
}
++op_stack_p;
op_stack[v10] = -7;
LABEL_7:
v2 = get_token();
if ( (unsigned int)(v2 + 10) <= 1 )
goto LABEL_2;
}
if ( v2 != -8 )
goto LABEL_7;
v5 = 0;
while ( op_stack_p > 0 )
{
v6 = (unsigned int)op_stack[op_stack_p - 1];
if ( (_DWORD)v6 == -7 )
{
--op_stack_p;
if ( v5 > 0 )
goto LABEL_7;
goto LABEL_39;
}
++v5;
--op_stack_p;
if ( (int)eval_op(v6, a2) < 0 )
goto LABEL_24;
}
if ( v5 > 0 )
{
LABEL_32:
fprintf(stderr, "%s\n", "mismatched parentheses");
goto LABEL_24;
}
LABEL_39:
fprintf(stderr, "%s\n", "missing operator");
LABEL_24:
cleanup_evaluator();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // rdi
int v4; // ebp
int v5; // ebx
__int64 v6; // rdi
int v7; // ecx
__int64 v8; // rdi
__int64 result; // rax
int v10; // eax
__int64 v11; // rsi

v2 = get_token();
if ( (unsigned int)(v2 + 10) <= 1 )
{
LABEL_2:
while ( op_stack_p > 0 )
{
v3 = (unsigned int)op_stack[op_stack_p - 1];
if ( (unsigned int)(v3 + 8) <= 1 )
goto LABEL_32;
--op_stack_p;
if ( (int)func5(v3, a2) < 0 )
goto LABEL_24;
}
if ( seq_stack_p > 1 )
{
fprintf(stderr, "%d values left on the sequence stack; should be 1\n", (unsigned int)seq_stack_p);
result = 0xFFFFFFFFLL;
}
else
{
result = 0xFFFFFFFFLL;
if ( seq_stack_p )
{
v11 = (unsigned int)seq_stack[0];
printf("%d\n", (unsigned int)seq_stack[0]);
func1("%d\n", v11);
result = (unsigned int)-(v2 != -9);
}
}
return result;
}
while ( 1 )
{
if ( v2 >= 0 )
{
v4 = seq_stack_p;
if ( seq_stack_p > 1023 )
{
fprintf(stderr, "%s\n", "sequence stack overflow");
goto LABEL_24;
}
a2 = (unsigned int)v2;
func2((__int64)&seq_stack[6 * seq_stack_p], v2);
seq_stack_p = v4 + 1;
goto LABEL_7;
}
if ( v2 >= -6 )
{
while ( 1 )
{
v7 = op_stack_p;
if ( op_stack_p <= 0 )
break;
a2 = (unsigned int)(op_stack_p - 1);
v8 = (unsigned int)op_stack[(int)a2];
if ( precedence[~v2] > precedence[~op_stack[(int)a2]] )
{
if ( op_stack_p > 511 )
goto LABEL_26;
break;
}
--op_stack_p;
if ( (int)func5(v8, a2) < 0 )
goto LABEL_24;
}
++op_stack_p;
op_stack[v7] = v2;
goto LABEL_7;
}
if ( v2 != -7 )
break;
v10 = op_stack_p;
if ( op_stack_p > 511 )
{
LABEL_26:
fprintf(stderr, "%s\n", "operator stack overflow");
goto LABEL_24;
}
++op_stack_p;
op_stack[v10] = -7;
LABEL_7:
v2 = get_token();
if ( (unsigned int)(v2 + 10) <= 1 )
goto LABEL_2;
}
if ( v2 != -8 )
goto LABEL_7;
v5 = 0;
while ( op_stack_p > 0 )
{
v6 = (unsigned int)op_stack[op_stack_p - 1];
if ( (_DWORD)v6 == -7 )
{
--op_stack_p;
if ( v5 > 0 )
goto LABEL_7;
goto LABEL_39;
}
++v5;
--op_stack_p;
if ( (int)func5(v6, a2) < 0 )
goto LABEL_24;
}
if ( v5 > 0 )
{
LABEL_32:
fprintf(stderr, "%s\n", "mismatched parentheses");
goto LABEL_24;
}
LABEL_39:
fprintf(stderr, "%s\n", "missing operator");
LABEL_24:
func6();
return 1LL;
}

original_code:
int
evaluate(void)
{
 int tok;
 tok = get_token();
 while (tok != -9 && tok != -10) {
  if (tok >= 0) {
   do { if (!(seq_stack_p < 1024)) { fprintf(stderr, "%s\n", "sequence stack overflow"); goto error; }} while (0);
   addto_seq(&seq_stack[seq_stack_p], tok);
   seq_stack_p++;
  } else if (tok >= -6) {
   while (op_stack_p > 0) {
    int cur_prec = precedence[-tok - 1];
    int top_op = op_stack[op_stack_p - 1];
    int top_prec = precedence[-top_op - 1];
    if (top_prec < cur_prec) {
     break;
    }
    op_stack_p--;
    if (eval_op(top_op) < 0) {
     goto error;
    }
   }
   do { if (!(op_stack_p < 512)) { fprintf(stderr, "%s\n", "operator stack overflow"); goto error; }} while (0);
   op_stack[op_stack_p++] = tok;
  } else if (tok == -7) {
   do { if (!(op_stack_p < 512)) { fprintf(stderr, "%s\n", "operator stack overflow"); goto error; }} while (0);
   op_stack[op_stack_p++] = tok;
  } else if (tok == -8) {
   int matched = 0;
   int op_count = 0;
   while (op_stack_p > 0) {
    int top_op = op_stack[op_stack_p - 1];
    if (top_op == -7) {
     matched = 1;
     op_stack_p--;
     break;
    }
    op_count++;
    op_stack_p--;
    if (eval_op(top_op) < 0) {
     goto error;
    }
   }
   do { if (!(op_count > 0)) { fprintf(stderr, "%s\n", "missing operator"); goto error; }} while (0);
   do { if (!(matched)) { fprintf(stderr, "%s\n", "mismatched parentheses"); goto error; }} while (0);
  }
  tok = get_token();
 }
 while (op_stack_p > 0) {
  int top_op = op_stack[op_stack_p - 1];
  do { if (!(top_op != -7 && top_op != -8)) { fprintf(stderr, "%s\n", "mismatched parentheses"); goto error; }} while (0);
  op_stack_p--;
  if (eval_op(top_op) < 0) {
   goto error;
  }
 }
 if (seq_stack_p > 1) {
  fprintf(stderr, "%d values left on the sequence stack; should be 1\n",
   seq_stack_p);
  return -1;
 } else if (seq_stack_p == 0) {
  return -1;
 }
 printf("%d\n", seq_stack[0].sum);
 pop_seq_stack();
 if (tok == -9) {
  return 0;
 }
 return -1;
error:
 cleanup_evaluator();
 return 1;
}

canonical_original_code:
int evaluate()
{
 int tok;
 tok = get_token();
 while (tok != -9 && tok != -10) {
  if (tok >= 0) {
   do { if (!(seq_stack_p < 1024)) { fprintf(stderr, "%s\n", "sequence stack overflow"); goto error; }} while (0);
   addto_seq(&seq_stack[seq_stack_p], tok);
   seq_stack_p++;
  } else if (tok >= -6) {
   while (op_stack_p > 0) {
    int cur_prec = precedence[-tok - 1];
    int top_op = op_stack[op_stack_p - 1];
    int top_prec = precedence[-top_op - 1];
    if (top_prec < cur_prec) {
     break;
    }
    op_stack_p--;
    if (eval_op(top_op) < 0) {
     goto error;
    }
   }
   do { if (!(op_stack_p < 512)) { fprintf(stderr, "%s\n", "operator stack overflow"); goto error; }} while (0);
   op_stack[op_stack_p++] = tok;
  } else if (tok == -7) {
   do { if (!(op_stack_p < 512)) { fprintf(stderr, "%s\n", "operator stack overflow"); goto error; }} while (0);
   op_stack[op_stack_p++] = tok;
  } else if (tok == -8) {
   int matched = 0;
   int op_count = 0;
   while (op_stack_p > 0) {
    int top_op = op_stack[op_stack_p - 1];
    if (top_op == -7) {
     matched = 1;
     op_stack_p--;
     break;
    }
    op_count++;
    op_stack_p--;
    if (eval_op(top_op) < 0) {
     goto error;
    }
   }
   do { if (!(op_count > 0)) { fprintf(stderr, "%s\n", "missing operator"); goto error; }} while (0);
   do { if (!(matched)) { fprintf(stderr, "%s\n", "mismatched parentheses"); goto error; }} while (0);
  }
  tok = get_token();
 }
 while (op_stack_p > 0) {
  int top_op = op_stack[op_stack_p - 1];
  do { if (!(top_op != -7 && top_op != -8)) { fprintf(stderr, "%s\n", "mismatched parentheses"); goto error; }} while (0);
  op_stack_p--;
  if (eval_op(top_op) < 0) {
   goto error;
  }
 }
 if (seq_stack_p > 1) {
  fprintf(stderr, "%d values left on the sequence stack; should be 1\n",
   seq_stack_p);
  return -1;
 } else if (seq_stack_p == 0) {
  return -1;
 }
 printf("%d\n", seq_stack[0].sum);
 pop_seq_stack();
 if (tok == -9) {
  return 0;
 }
 return -1;
error:
 cleanup_evaluator();
 return 1;
}

variable_types: tok int

variable_types: matched int


digit

decompiled_code:
_BOOL8 __fastcall digit(int a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

variable_types: c int


decompiled_code:
int __fastcall read_int(char a1)
{
char *v1; // r12
int i; // ebp
int v3; // ebx
char nptr; // [rsp+5h] [rbp-23h] BYREF
char v6[34]; // [rsp+6h] [rbp-22h] BYREF

nptr = a1;
v6[9] = 0;
v1 = v6;
for ( i = 1; i != 10; ++i )
{
v3 = getc(stdin);
if ( !digit(v3) )
{
*(&nptr + i) = 0;
goto LABEL_7;
}
*v1++ = v3;
}
v3 = getc(stdin);
if ( digit(v3) )
{
fwrite("integer constant has too many digits\n", 1uLL, 0x25uLL, stderr);
return -10;
}
LABEL_7:
ungetc(v3, stdin);
return atoi(&nptr);
}

canonical_decompiled_code:
int __fastcall func1(char a1)
{
char *v1; // r12
int i; // ebp
int v3; // ebx
char nptr; // [rsp+5h] [rbp-23h] BYREF
char v6[34]; // [rsp+6h] [rbp-22h] BYREF

nptr = a1;
v6[9] = 0;
v1 = v6;
for ( i = 1; i != 10; ++i )
{
v3 = getc(stdin);
if ( !func0(v3) )
{
*(&nptr + i) = 0;
goto LABEL_7;
}
*v1++ = v3;
}
v3 = getc(stdin);
if ( func0(v3) )
{
fwrite("integer constant has too many digits\n", 1uLL, 0x25uLL, stderr);
return -10;
}
LABEL_7:
ungetc(v3, stdin);
return atoi(&nptr);
}

original_code:
static int
read_int(char first)
{
 char buf[11];
 int peek, i;
 buf[0] = first;
 buf[10] = '\0';
 for (i = 1; i < 10; i++) {
  peek = getc(stdin);
  if (digit(peek)) {
   buf[i] = peek;
  } else {
   buf[i] = '\0';
   break;
  }
 }
 if (i == 10) {
  peek = getc(stdin);
  if (digit(peek)) {
   fprintf(stderr, "integer constant has too many digits\n");
   return -10;
  }
 }
 ungetc(peek, stdin);
 return atoi(buf);
}

canonical_original_code:
static int read_int(char first)
{
 char buf[11];
 int peek; int i;
 buf[0] = first;
 buf[10] = '\0';
 for (i = 1; i < 10; i++) {
  peek = getc(stdin);
  if (digit(peek)) {
   buf[i] = peek;
  } else {
   buf[i] = '\0';
   break;
  }
 }
 if (i == 10) {
  peek = getc(stdin);
  if (digit(peek)) {
   fprintf(stderr, "integer constant has too many digits\n");
   return -10;
  }
 }
 ungetc(peek, stdin);
 return atoi(buf);
}

variable_types: first char

variable_types:
buf
char [11]

variable_types: peek int


decompiled_code:
int get_token()
{
int v0; // eax
int result; // eax

do
{
do
v0 = getc(stdin);
while ( v0 == 32 );
}
while ( v0 == 9 );
switch ( v0 )
{
case -1:
result = -10;
break;
case 10:
result = -9;
break;
case 37:
result = 100;
break;
case 40:
result = -7;
break;
case 41:
result = -8;
break;
case 42:
result = -3;
break;
case 43:
result = -5;
break;
case 45:
result = -6;
break;
case 47:
result = -4;
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
result = read_int(v0);
break;
case 68:
case 100:
result = -1;
break;
case 75:
case 107:
result = -2;
break;
default:
fwrite("unrecognized character\n", 1uLL, 0x17uLL, stderr);
result = -10;
break;
}
return result;
}

canonical_decompiled_code:
int func2()
{
int v0; // eax
int result; // eax

do
{
do
v0 = getc(stdin);
while ( v0 == 32 );
}
while ( v0 == 9 );
switch ( v0 )
{
case -1:
result = -10;
break;
case 10:
result = -9;
break;
case 37:
result = 100;
break;
case 40:
result = -7;
break;
case 41:
result = -8;
break;
case 42:
result = -3;
break;
case 43:
result = -5;
break;
case 45:
result = -6;
break;
case 47:
result = -4;
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
result = func1(v0);
break;
case 68:
case 100:
result = -1;
break;
case 75:
case 107:
result = -2;
break;
default:
fwrite("unrecognized character\n", 1uLL, 0x17uLL, stderr);
result = -10;
break;
}
return result;
}

original_code:
int
get_token(void)
{
 int peek;
 int tok = -10;
 do {
  peek = getc(stdin);
 } while (peek == ' ' || peek == '\t');
 switch (peek) {
 case '0': case '1': case '2': case '3': case '4':
 case '5': case '6': case '7': case '8': case '9':
  tok = read_int(peek);
  break;
 case '%':
  tok = 100;
  break;
 case 'd': case 'D':
  tok = -1;
  break;
 case 'k': case 'K':
  tok = -2;
  break;
 case '*':
  tok = -3;
  break;
 case '/':
  tok = -4;
  break;
 case '+':
  tok = -5;
  break;
 case '-':
  tok = -6;
  break;
 case '(':
  tok = -7;
  break;
 case ')':
  tok = -8;
  break;
 case '\n':
  tok = -9;
  break;
 case (-1):
  tok = -10;
  break;
 default:
  fprintf(stderr, "unrecognized character\n");
 }
 return tok;
}

canonical_original_code:
int get_token()
{
 int peek;
 int tok = -10;
 do {
  peek = getc(stdin);
 } while (peek == ' ' || peek == '\t');
 switch (peek) {
 case '0': case '1': case '2': case '3': case '4':
 case '5': case '6': case '7': case '8': case '9':
  tok = read_int(peek);
  break;
 case '%':
  tok = 100;
  break;
 case 'd': case 'D':
  tok = -1;
  break;
 case 'k': case 'K':
  tok = -2;
  break;
 case '*':
  tok = -3;
  break;
 case '/':
  tok = -4;
  break;
 case '+':
  tok = -5;
  break;
 case '-':
  tok = -6;
  break;
 case '(':
  tok = -7;
  break;
 case ')':
  tok = -8;
  break;
 case '\n':
  tok = -9;
  break;
 case (-1):
  tok = -10;
  break;
 default:
  fprintf(stderr, "unrecognized character\n");
 }
 return tok;
}


decompiled_code:
size_t print_banner()
{
return fwrite(
"Dice Roller v0.1.1\nCopyright (c) 2013 Jim Ingram <ingramj@gmail.com>\nctrl-d to quit\n",
1uLL,
0x54uLL,
stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"Dice Roller v0.1.1\nCopyright (c) 2013 Jim Ingram <ingramj@gmail.com>\nctrl-d to quit\n",
1uLL,
0x54uLL,
stderr);
}

original_code:
static void print_banner(void)
{
 fprintf(stderr, "Dice Roller v0.1.1\n"
         "Copyright (c) 2013 Jim Ingram <ingramj@gmail.com>\n"
         "ctrl-d to quit\n");
}

canonical_original_code:
static void print_banner()
{
 fprintf(stderr, "Dice Roller v0.1.1\n"
         "Copyright (c) 2013 Jim Ingram <ingramj@gmail.com>\n"
         "ctrl-d to quit\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
print_banner();
seed_random(argc, argv);
fwrite("> ", 1uLL, 2uLL, stderr);
while ( (int)evaluate() >= 0 )
fwrite("> ", 1uLL, 2uLL, stderr);
fputc(10, stderr);
cleanup_evaluator();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0();
seed_random(argc, argv);
fwrite("> ", 1uLL, 2uLL, stderr);
while ( (int)evaluate() >= 0 )
fwrite("> ", 1uLL, 2uLL, stderr);
fputc(10, stderr);
cleanup_evaluator();
return 0;
}

original_code:
int
main(void)
{
 print_banner();
 seed_random();
 fprintf(stderr, "> ");
 while (evaluate() >= 0) {
  fprintf(stderr, "> ");
 }
 fprintf(stderr, "\n");
 cleanup_evaluator();
 return 0;
}

canonical_original_code:
int main()
{
 print_banner();
 seed_random();
 fprintf(stderr, "> ");
 while (evaluate() >= 0) {
  fprintf(stderr, "> ");
 }
 fprintf(stderr, "\n");
 cleanup_evaluator();
 return 0;
}


decompiled_code:
void seed_random()
{
unsigned int v0; // ebx
__pid_t v1; // eax
unsigned int v2; // eax
unsigned int v3; // ebx

v0 = time(0LL);
v1 = getpid();
v2 = ((v1 ^ v0 ^ ((v1 ^ v0) << 19)) >> 11) ^ v1 ^ v0 ^ ((v1 ^ v0) << 19);
v3 = v2 ^ (v2 << 9);
fprintf(stderr, "seed = %u\n", v3);
srandom(v3);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // ebx
__pid_t v1; // eax
unsigned int v2; // eax
unsigned int v3; // ebx

v0 = time(0LL);
v1 = getpid();
v2 = ((v1 ^ v0 ^ ((v1 ^ v0) << 19)) >> 11) ^ v1 ^ v0 ^ ((v1 ^ v0) << 19);
v3 = v2 ^ (v2 << 9);
fprintf(stderr, "seed = %u\n", v3);
srandom(v3);
}

original_code:
void
seed_random(void)
{
 unsigned int seed = time(((void *)0)) ^ getpid();
 seed ^= (seed << 19);
 seed ^= (seed >> 11);
 seed ^= (seed << 9);
 fprintf(stderr, "seed = %u\n", seed);
 srandom(seed);
}

canonical_original_code:
void seed_random()
{
 unsigned int seed = time(((void *)0)) ^ getpid();
 seed ^= (seed << 19);
 seed ^= (seed >> 11);
 seed ^= (seed << 9);
 fprintf(stderr, "seed = %u\n", seed);
 srandom(seed);
}

variable_types:
seed
unsigned int


decompiled_code:
__int64 __fastcall random_range(unsigned int a1, int a2)
{
__int64 result; // rax
int v3; // esi
int v4; // eax

if ( a1 == a2 )
return 0xFFFFFFFFLL;
result = a1;
if ( a2 - 1 != a1 )
{
v3 = a2 - a1;
do
v4 = random();
while ( 0x7FFFFFFF - 0x7FFFFFFF % v3 < v4 );
result = a1 + v4 / (0x7FFFFFFF / v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
__int64 result; // rax
int v3; // esi
int v4; // eax

if ( a1 == a2 )
return 0xFFFFFFFFLL;
result = a1;
if ( a2 - 1 != a1 )
{
v3 = a2 - a1;
do
v4 = random();
while ( 0x7FFFFFFF - 0x7FFFFFFF % v3 < v4 );
result = a1 + v4 / (0x7FFFFFFF / v3);
}
return result;
}

original_code:
int
random_range(int min, int max)
{
 int range, bucket, remainder, r;
 if (min == max) {
  return -1;
 } else if (min == max - 1) {
  return min;
 }
 range = max - min;
 bucket = 2147483647 / range;
 remainder = 2147483647 % range;
 while ((r = random()) > (2147483647 - remainder))
  ;
 return min + (r / bucket);
}

canonical_original_code:
int random_range(int min, int max)
{
 int range; int bucket; int remainder; int r;
 if (min == max) {
  return -1;
 } else if (min == max - 1) {
  return min;
 }
 range = max - min;
 bucket = 2147483647 / range;
 remainder = 2147483647 % range;
 while ((r = random()) > (2147483647 - remainder))
  ;
 return min + (r / bucket);
}

variable_types: min int

variable_types: max int

variable_types: range int

variable_types: bucket int

variable_types: remainder int

variable_types: r int