consumer

repo: marciso/bqueue-code

decompiled_code:
void *__fastcall consumer(void *a1)
{
unsigned __int64 v1; // r14
pthread_barrier_t *v2; // r13
unsigned int v3; // er12
__int64 v4; // rbp
char *v5; // rbx
__int64 v6; // rax
unsigned __int64 v7; // rcx
__int64 v8; // rdx
char v10[8]; // [rsp+8h] [rbp-C0h] BYREF
cpu_set_t cpuset; // [rsp+10h] [rbp-B8h] BYREF

v1 = *(unsigned int *)a1;
v2 = (pthread_barrier_t *)*((_QWORD *)a1 + 1);
v3 = *((_DWORD *)a1 + 4);
memset(&cpuset, 0, sizeof(cpuset));
if ( (unsigned int)v1 <= 0x3FF )
cpuset.__bits[v1 >> 6] |= 1LL << v1;
printf("consumer %d: ---%d----\n", v1, (unsigned int)(2 * v1));
if ( sched_setaffinity(0, 0x80uLL, &cpuset) < 0 )
{
perror("Error: sched_setaffinity");
}
else
{
v4 = 200000000LL;
puts("Consumer created...");
pthread_barrier_wait(v2);
v5 = (char *)&queues + 65728 * v1;
*((_QWORD *)v5 + 16) = read_tsc();
do
{
while ( (unsigned int)dequeue(v5, v10) )
;
--v4;
}
while ( v4 );
v6 = read_tsc();
v7 = v6 - qword_680[8216 * v1];
qword_688[8216 * v1] = v6;
printf("consumer: %ld cycles/op\n", v7 / 0xBEBC201);
v8 = (0x5798EE063611088DLL * (unsigned __int128)(unsigned __int64)(qword_688[8216 * v1] - qword_680[8216 * v1])) >> 64;
results[2 * v3] = (v8 + ((unsigned __int64)(qword_688[8216 * v1] - qword_680[8216 * v1] - v8) >> 1)) >> 27;
pthread_barrier_wait(v2);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
unsigned __int64 v1; // r14
pthread_barrier_t *v2; // r13
unsigned int v3; // er12
__int64 v4; // rbp
char *v5; // rbx
__int64 v6; // rax
unsigned __int64 v7; // rcx
__int64 v8; // rdx
char v10[8]; // [rsp+8h] [rbp-C0h] BYREF
cpu_set_t cpuset; // [rsp+10h] [rbp-B8h] BYREF

v1 = *(unsigned int *)a1;
v2 = (pthread_barrier_t *)*((_QWORD *)a1 + 1);
v3 = *((_DWORD *)a1 + 4);
memset(&cpuset, 0, sizeof(cpuset));
if ( (unsigned int)v1 <= 0x3FF )
cpuset.__bits[v1 >> 6] |= 1LL << v1;
printf("consumer %d: ---%d----\n", v1, (unsigned int)(2 * v1));
if ( sched_setaffinity(0, 0x80uLL, &cpuset) < 0 )
{
perror("Error: sched_setaffinity");
}
else
{
v4 = 200000000LL;
puts("Consumer created...");
pthread_barrier_wait(v2);
v5 = (char *)&queues + 65728 * v1;
*((_QWORD *)v5 + 16) = read_tsc();
do
{
while ( (unsigned int)dequeue(v5, v10) )
;
--v4;
}
while ( v4 );
v6 = read_tsc();
v7 = v6 - qword_680[8216 * v1];
qword_688[8216 * v1] = v6;
printf("consumer: %ld cycles/op\n", v7 / 0xBEBC201);
v8 = (0x5798EE063611088DLL * (unsigned __int128)(unsigned __int64)(qword_688[8216 * v1] - qword_680[8216 * v1])) >> 64;
results[2 * v3] = (v8 + ((unsigned __int64)(qword_688[8216 * v1] - qword_680[8216 * v1] - v8) >> 1)) >> 27;
pthread_barrier_wait(v2);
}
return 0LL;
}

original_code:
void * consumer(void *arg)
{
 uint32_t cpu_id, r;
 uint64_t value;
 cpu_set_t cur_mask;
 uint64_t i;
 struct init_info * init = (struct init_info *) arg;
 cpu_id = init->cpu_id;
 pthread_barrier_t *barrier = init->barrier;
  r = init->r;
 do __builtin_memset (&cur_mask, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (cpu_id); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cur_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 printf("consumer %d:  ---%d----\n", cpu_id, 2*cpu_id);
 if (sched_setaffinity(0, sizeof(cur_mask), &cur_mask) < 0) {
  perror("Error: sched_setaffinity");
  return ((void *)0);
 }
 printf("Consumer created...\n");
 pthread_barrier_wait(barrier);
 queues[cpu_id].start_c = read_tsc();
 for (i = 1; i <= 200000000; i++) {
  while( dequeue(&queues[cpu_id], &value) != 0 );
 }
 queues[cpu_id].stop_c = read_tsc();
 printf("consumer: %" "l" "d" " cycles/op\n",
  ((queues[cpu_id].stop_c - queues[cpu_id].start_c) / (200000000 + 1)));
  results[r].cons = ((queues[cpu_id].stop_c - queues[cpu_id].start_c) / (200000000 + 1));
 pthread_barrier_wait(barrier);
 return ((void *)0);
}

canonical_original_code:
void *consumer(void *arg)
{
 unsigned int cpu_id; unsigned int r;
 unsigned long value;
 struct cpu_set_t cur_mask;
 unsigned long i;
 struct init_info *init = (struct init_info *) arg;
 cpu_id = init->cpu_id;
 union pthread_barrier_t *barrier = init->barrier;
  r = init->r;
 do __builtin_memset (&cur_mask, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (cpu_id); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cur_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 printf("consumer %d:  ---%d----\n", cpu_id, 2*cpu_id);
 if (sched_setaffinity(0, sizeof(cur_mask), &cur_mask) < 0) {
  perror("Error: sched_setaffinity");
  return ((void *)0);
 }
 printf("Consumer created...\n");
 pthread_barrier_wait(barrier);
 queues[cpu_id].start_c = read_tsc();
 for (i = 1; i <= 200000000; i++) {
  while( dequeue(&queues[cpu_id], &value) != 0 );
 }
 queues[cpu_id].stop_c = read_tsc();
 printf("consumer: %" "l" "d" " cycles/op\n",
  ((queues[cpu_id].stop_c - queues[cpu_id].start_c) / (200000000 + 1)));
  results[r].cons = ((queues[cpu_id].stop_c - queues[cpu_id].start_c) / (200000000 + 1));
 pthread_barrier_wait(barrier);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types:
r
unsigned int

variable_types:
value
unsigned long

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

variable_types:
i
unsigned long

variable_types: struct init_info { unsigned int cpu_id; union pthread_barrier_t { char __size[32]; long __align; } *barrier; unsigned int r; } *

return_type: void *

user_defined_types: struct init_info { unsigned int cpu_id; union pthread_barrier_t *barrier; unsigned int r; }


producer

decompiled_code:
void __fastcall producer(__int64 a1, unsigned int a2, unsigned int a3)
{
pthread_barrier_t *v3; // r15
__int64 v4; // rbp
__int64 v5; // r14
char *v6; // rbx
unsigned __int64 v7; // r12
cpu_set_t cpuset; // [rsp+10h] [rbp-B8h] BYREF

v3 = *(pthread_barrier_t **)(a1 + 8);
cpuset.__bits[0] = 1LL;
memset(&cpuset.__bits[1], 0, 0x78uLL);
printf("producer %d: ---%d----\n", 0LL, 1LL);
if ( sched_setaffinity(0, 0x80uLL, &cpuset) < 0 )
{
perror("Error: sched_setaffinity");
}
else
{
v4 = 1LL;
pthread_barrier_wait(v3);
v5 = read_tsc();
do
{
v6 = (char *)&unk_106C0;
if ( a2 > 1 )
{
do
{
while ( (unsigned int)enqueue(v6, v4) )
;
v6 += 65728;
}
while ( v6 != (char *)&unk_20780 + 65728 * a2 - 131456 );
}
++v4;
}
while ( v4 != 200000513 );
v7 = (read_tsc() - v5) / (unsigned __int64)(200000001 * a2 - 200000001);
printf("producer %ld cycles/op\n", v7);
results[2 * a3 + 1] = v7;
pthread_barrier_wait(v3);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
pthread_barrier_t *v3; // r15
__int64 v4; // rbp
__int64 v5; // r14
char *v6; // rbx
unsigned __int64 v7; // r12
cpu_set_t cpuset; // [rsp+10h] [rbp-B8h] BYREF

v3 = *(pthread_barrier_t **)(a1 + 8);
cpuset.__bits[0] = 1LL;
memset(&cpuset.__bits[1], 0, 0x78uLL);
printf("producer %d: ---%d----\n", 0LL, 1LL);
if ( sched_setaffinity(0, 0x80uLL, &cpuset) < 0 )
{
perror("Error: sched_setaffinity");
}
else
{
v4 = 1LL;
pthread_barrier_wait(v3);
v5 = read_tsc();
do
{
v6 = (char *)&unk_106C0;
if ( a2 > 1 )
{
do
{
while ( (unsigned int)enqueue(v6, v4) )
;
v6 += 65728;
}
while ( v6 != (char *)&unk_20780 + 65728 * a2 - 131456 );
}
++v4;
}
while ( v4 != 200000513 );
v7 = (read_tsc() - v5) / (unsigned __int64)(200000001 * a2 - 200000001);
printf("producer %ld cycles/op\n", v7);
results[2 * a3 + 1] = v7;
pthread_barrier_wait(v3);
}
}

original_code:
void producer(void *arg, uint32_t num, uint32_t r)
{
 uint64_t start_p;
 uint64_t stop_p;
 uint64_t i;
 int32_t j;
 cpu_set_t cur_mask;
 struct init_info * init = (struct init_info *) arg;
 pthread_barrier_t *barrier = init->barrier;
 do __builtin_memset (&cur_mask, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (0); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cur_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 printf("producer %d:  ---%d----\n", 0, 1);
 if (sched_setaffinity(0, sizeof(cur_mask), &cur_mask) < 0) {
  perror("Error: sched_setaffinity");
  return ;
 }
 pthread_barrier_wait(barrier);
 start_p = read_tsc();
 for (i = 1; i <= 200000000 + ((1024 * 8)/16); i++) {
  for (j=1; j<num; j++) {
   while ( enqueue(&queues[j], (uint64_t)i) != 0);
  }
 }
 stop_p = read_tsc();
 printf("producer %" "l" "d" " cycles/op\n", (stop_p - start_p) / ((200000000 + 1)*(num -1)));
  results[r].prod = (stop_p - start_p) / ((200000000 + 1)*(num -1));
 pthread_barrier_wait(barrier);
}

canonical_original_code:
void producer(void *arg, unsigned int num, unsigned int r)
{
 unsigned long start_p;
 unsigned long stop_p;
 unsigned long i;
 int j;
 struct cpu_set_t cur_mask;
 struct init_info *init = (struct init_info *) arg;
 union pthread_barrier_t *barrier = init->barrier;
 do __builtin_memset (&cur_mask, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (0); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cur_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 printf("producer %d:  ---%d----\n", 0, 1);
 if (sched_setaffinity(0, sizeof(cur_mask), &cur_mask) < 0) {
  perror("Error: sched_setaffinity");
  return ;
 }
 pthread_barrier_wait(barrier);
 start_p = read_tsc();
 for (i = 1; i <= 200000000 + ((1024 * 8)/16); i++) {
  for (j=1; j<num; j++) {
   while ( enqueue(&queues[j], (unsigned long)i) != 0);
  }
 }
 stop_p = read_tsc();
 printf("producer %" "l" "d" " cycles/op\n", (stop_p - start_p) / ((200000000 + 1)*(num -1)));
  results[r].prod = (stop_p - start_p) / ((200000000 + 1)*(num -1));
 pthread_barrier_wait(barrier);
}

variable_types:
num
unsigned int

variable_types: j int

variable_types: union pthread_barrier_t { char __size[32]; long __align; } *

return_type: void

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // eax
const char *v5; // rbx
unsigned int v6; // eax
const char *v7; // rdi
unsigned __int64 v8; // rbx
int v9; // ebp
void *v10; // rcx
int v11; // eax
int v12; // er13
pthread_t newthread; // [rsp+8h] [rbp-90h] BYREF
pthread_barrier_t barrier; // [rsp+10h] [rbp-88h] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-68h] BYREF

v3 = 2;
if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
v4 = atoi(*(const char **)&argc);
v3 = v4;
if ( v4 <= 1 )
{
*(_QWORD *)&argc = "Minimum core number is 2";
v3 = 2;
puts("Minimum core number is 2");
}
else if ( v4 > 32 )
{
argv = (const char **)(&loc_1F + 1);
*(_QWORD *)&argc = "Maximum core number is %d\n";
v3 = 32;
printf("Maximum core number is %d\n", 32LL);
}
}
v5 = (const char *)&queues;
v6 = read_tsc(*(_QWORD *)&argc, argv, envp);
srand(v6);
do
{
v7 = v5;
v5 += 65728;
queue_init(v7);
}
while ( "consumer %d: ---%d----\n" != v5 );
if ( pthread_barrier_init(&barrier, 0LL, v3) )
goto LABEL_14;
if ( pthread_attr_init(&attr) )
goto LABEL_14;
v8 = (unsigned int)((_DWORD)&info + 24);
v9 = 1;
do
{
*(_DWORD *)v8 = v9;
v10 = (void *)v8;
*(_QWORD *)(v8 + 8) = &barrier;
++v9;
v8 += 24LL;
*(_DWORD *)(v8 - 8) = 0;
v11 = pthread_create(&newthread, &attr, consumer, v10);
v12 = v11;
}
while ( v3 != v9 );
if ( v11 )
{
LABEL_14:
v12 = 1;
perror("BW");
}
else
{
info = 0;
*((_QWORD *)&info + 1) = &barrier;
*(&info + 4) = 0;
producer((__int64)&info, v3, 0);
puts(".");
puts("Done!");
printf("producers: ");
printf("%ld ", results[1]);
printf("\nconsumers: ");
printf("%ld ", results[0]);
putchar(10);
}
return v12;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // eax
const char *v5; // rbx
unsigned int v6; // eax
const char *v7; // rdi
unsigned __int64 v8; // rbx
int v9; // ebp
void *v10; // rcx
int v11; // eax
int v12; // er13
pthread_t newthread; // [rsp+8h] [rbp-90h] BYREF
pthread_barrier_t barrier; // [rsp+10h] [rbp-88h] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-68h] BYREF

v3 = 2;
if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
v4 = atoi(*(const char **)&argc);
v3 = v4;
if ( v4 <= 1 )
{
*(_QWORD *)&argc = "Minimum core number is 2";
v3 = 2;
puts("Minimum core number is 2");
}
else if ( v4 > 32 )
{
argv = (const char **)(&loc_1F + 1);
*(_QWORD *)&argc = "Maximum core number is %d\n";
v3 = 32;
printf("Maximum core number is %d\n", 32LL);
}
}
v5 = (const char *)&queues;
v6 = read_tsc(*(_QWORD *)&argc, argv, envp);
srand(v6);
do
{
v7 = v5;
v5 += 65728;
queue_init(v7);
}
while ( "consumer %d: ---%d----\n" != v5 );
if ( pthread_barrier_init(&barrier, 0LL, v3) )
goto LABEL_14;
if ( pthread_attr_init(&attr) )
goto LABEL_14;
v8 = (unsigned int)((_DWORD)&info + 24);
v9 = 1;
do
{
*(_DWORD *)v8 = v9;
v10 = (void *)v8;
*(_QWORD *)(v8 + 8) = &barrier;
++v9;
v8 += 24LL;
*(_DWORD *)(v8 - 8) = 0;
v11 = pthread_create(&newthread, &attr, consumer, v10);
v12 = v11;
}
while ( v3 != v9 );
if ( v11 )
{
LABEL_14:
v12 = 1;
perror("BW");
}
else
{
info = 0;
*((_QWORD *)&info + 1) = &barrier;
*(&info + 4) = 0;
func1((__int64)&info, v3, 0);
puts(".");
puts("Done!");
printf("producers: ");
printf("%ld ", results[1]);
printf("\nconsumers: ");
printf("%ld ", results[0]);
putchar(10);
}
return v12;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t consumer_thread;
 pthread_attr_t consumer_attr;
 pthread_barrier_t barrier;
 int error , i, max_th = 2, c;
 if (argc > 1) {
  max_th = atoi(argv[1]);
 }
 if (max_th < 2) {
  max_th = 2;
  printf("Minimum core number is 2\n");
 }
 if (max_th > 32) {
  max_th = 32;
  printf("Maximum core number is %d\n", max_th);
 }
 srand((unsigned int)read_tsc());
 for (i=0; i<32; i++) {
  queue_init(&queues[i]);
 }
 error = pthread_barrier_init(&barrier, ((void *)0), max_th);
 if (error != 0) {
  perror("BW");
  return 1;
 }
 error = pthread_attr_init(&consumer_attr);
 if (error != 0) {
  perror("BW");
  return 1;
 }
  for(c = 0; c < (1); ++c ) {
    for (i=1; i<max_th; i++) {
      (info[i].cpu_id) = i;
      (info[i].barrier) = &barrier;
      (info[i].r) = c;
      error = pthread_create(&consumer_thread, &consumer_attr,
            consumer, (&info[i]));
    }
    if (error != 0) {
      perror("BW");
      return 1;
    }
    (info[0].cpu_id) = 0;
    (info[0].barrier) = &barrier;
    (info[0].r) = c;
    producer((&info[0]), max_th, c);
    printf(".\n");
  }
 printf("Done!\n");
  printf("producers: ");
  for(c = 0; c < (1); ++c ) { printf("%" "l" "d" " ", results[c].prod); }
  printf("\nconsumers: ");
  for(c = 0; c < (1); ++c ) { printf("%" "l" "d" " ", results[c].cons); }
  printf("\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long consumer_thread;
 union pthread_attr_t consumer_attr;
 union pthread_barrier_t barrier;
 int error; int i; int max_th = 2; int c;
 if (argc > 1) {
  max_th = atoi(argv[1]);
 }
 if (max_th < 2) {
  max_th = 2;
  printf("Minimum core number is 2\n");
 }
 if (max_th > 32) {
  max_th = 32;
  printf("Maximum core number is %d\n", max_th);
 }
 srand((unsigned int)read_tsc());
 for (i=0; i<32; i++) {
  queue_init(&queues[i]);
 }
 error = pthread_barrier_init(&barrier, ((void *)0), max_th);
 if (error != 0) {
  perror("BW");
  return 1;
 }
 error = pthread_attr_init(&consumer_attr);
 if (error != 0) {
  perror("BW");
  return 1;
 }
  for(c = 0; c < (1); ++c ) {
    for (i=1; i<max_th; i++) {
      (info[i].cpu_id) = i;
      (info[i].barrier) = &barrier;
      (info[i].r) = c;
      error = pthread_create(&consumer_thread, &consumer_attr,
            consumer, (&info[i]));
    }
    if (error != 0) {
      perror("BW");
      return 1;
    }
    (info[0].cpu_id) = 0;
    (info[0].barrier) = &barrier;
    (info[0].r) = c;
    producer((&info[0]), max_th, c);
    printf(".\n");
  }
 printf("Done!\n");
  printf("producers: ");
  for(c = 0; c < (1); ++c ) { printf("%" "l" "d" " ", results[c].prod); }
  printf("\nconsumers: ");
  for(c = 0; c < (1); ++c ) { printf("%" "l" "d" " ", results[c].cons); }
  printf("\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: union pthread_barrier_t { char __size[32]; long __align; }

variable_types: error int

variable_types: i int

variable_types: c int

return_type: int


decompiled_code:
void *__fastcall queue_init(void *a1)
{
return memset(a1, 0, 0x100C0uLL);
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
return memset(a1, 0, 0x100C0uLL);
}

original_code:
void queue_init(struct queue_t *q)
{
 memset(q, 0, sizeof(struct queue_t));
}

variable_types: struct queue_t { unsigned int head; unsigned int tail; unsigned long start_c; unsigned long stop_c; unsigned long data[-1]; } *


enqueue

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

if ( *(_QWORD *)&a1[2 * *a1 + 48] )
return 0xFFFFFFFFLL;
*(_QWORD *)&a1[2 * (*a1)++ + 48] = a2;
result = 0LL;
if ( *a1 > 0x1FFFu )
*a1 = 0;
return result;
}

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

if ( *(_QWORD *)&a1[2 * *a1 + 48] )
return 0xFFFFFFFFLL;
*(_QWORD *)&a1[2 * (*a1)++ + 48] = a2;
result = 0LL;
if ( *a1 > 0x1FFFu )
*a1 = 0;
return result;
}

original_code:
int enqueue(struct queue_t * q, uint64_t value)
{
 if ( q->data[q->head] )
  return -1;
 q->data[q->head] = value;
 q->head ++;
 if ( q->head >= (1024 * 8) ) {
  q->head = 0;
 }
 return 0;
}

canonical_original_code:
int enqueue(struct queue_t *q, unsigned long value)
{
 if ( q->data[q->head] )
  return -1;
 q->data[q->head] = value;
 q->head ++;
 if ( q->head >= (1024 * 8) ) {
  q->head = 0;
 }
 return 0;
}

user_defined_types: struct queue_t { unsigned int head; unsigned int tail; unsigned long start_c; unsigned long stop_c; unsigned long data[-1]; }


dequeue

original_code:
int dequeue(struct queue_t * q, uint64_t * value)
{
 if ( !q->data[q->tail] )
  return -2;
 *value = q->data[q->tail];
 q->data[q->tail] = ELEMENT_ZERO;
 q->tail ++;
 if ( q->tail >= (1024 * 8) )
  q->tail = 0;
 return 0;
}

canonical_original_code:
int dequeue(struct queue_t *q, unsigned long *value)
{
 if ( !q->data[q->tail] )
  return -2;
 *value = q->data[q->tail];
 q->data[q->tail] = ELEMENT_ZERO;
 q->tail ++;
 if ( q->tail >= (1024 * 8) )
  q->tail = 0;
 return 0;
}

variable_types:
value
unsigned long *


myrand

original_code:
int myrand(unsigned long * next) {
 *next = *next * 1103515245 + 12345;
 return((unsigned)(*next/65536) % 32768);
}

canonical_original_code:
int myrand(unsigned long *next) {
 *next = *next * 1103515245 + 12345;
 return((unsigned int)(*next/65536) % 32768);
}

variable_types:
next
unsigned long *


decompiled_code:
unsigned int P1L()
{
puts("Sono il processo P1L");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func8()
{
puts("Sono il processo P1L");
return sleep(1u);
}

original_code: void P1L() { puts("Sono il processo " "P1L" ); sleep(1); }


decompiled_code:
unsigned int P1R()
{
puts("Sono il processo P1R");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func9()
{
puts("Sono il processo P1R");
return sleep(1u);
}

original_code: void P1R() { puts("Sono il processo " "P1R" ); sleep(1); }


decompiled_code:
unsigned int P2L()
{
puts("Sono il processo P2L");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func11()
{
puts("Sono il processo P2L");
return sleep(1u);
}

original_code: void P2L() { puts("Sono il processo " "P2L" ); sleep(1); }


decompiled_code:
unsigned int P2R()
{
puts("Sono il processo P2R");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func12()
{
puts("Sono il processo P2R");
return sleep(1u);
}

original_code: void P2R() { puts("Sono il processo " "P2R" ); sleep(1); }


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
char *v5; // r12
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-8Ch] BYREF
__int64 v8; // [rsp+14h] [rbp-84h]
__int64 v9; // [rsp+1Ch] [rbp-7Ch]
char v10; // [rsp+24h] [rbp-74h] BYREF
__int64 v11[13]; // [rsp+30h] [rbp-68h]

v3 = 1;
v4 = 0;
v8 = 0x400000003LL;
v5 = (char *)&stat_loc.__iptr + 4;
v11[0] = (__int64)P1;
v11[1] = (__int64)P1R;
v11[2] = (__int64)P1L;
v11[3] = (__int64)P2;
v11[4] = (__int64)P2R;
v11[5] = (__int64)P2L;
v11[6] = (__int64)P3;
v9 = 0x700000006LL;
while ( v3 <= v4 )
{
v3 = v4;
do
LABEL_8:
*(_QWORD *)&argc = &stat_loc;
while ( wait((__WAIT_STATUS)&stat_loc) != -1 );
v5 += 4;
if ( &v10 == v5 )
return 0;
v4 = v3;
v3 = *(_DWORD *)v5;
}
while ( fork() )
{
if ( ++v4 == v3 )
goto LABEL_8;
}
((void (__fastcall *)(_QWORD, const char **))v11[v4])(*(_QWORD *)&argc, argv);
return 0;
}

original_code:
int main(int argc, char**argv){
  int i, j, st;
  func tree[] = { P1, P1R, P1L, P2, P2R, P2L, P3 };
  int idx[] = { 1, 3, 4, 6, 7 };
  for(i = 0, j=0; i < sizeof(idx)/sizeof(int); i++){
    for(;j<idx[i];j++){
      if(fork() == 0){
 tree[j]();
 return 0;
      }
    }
    while( wait(&st) != -1 ) ;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int i; int j; int st;
  void (*tree[])() = { P1, P1R, P1L, P2, P2R, P2L, P3 };
  int idx[] = { 1, 3, 4, 6, 7 };
  for(i = 0, j=0; i < sizeof(idx)/sizeof(int); i++){
    for(;j<idx[i];j++){
      if(fork() == 0){
 tree[j]();
 return 0;
      }
    }
    while( wait(&st) != -1 ) ;
  }
  return 0;
}

variable_types:
argv
char **

variable_types: st int

variable_types:
tree
void (*[])()

variable_types:
idx
int []


decompiled_code:
unsigned int P1()
{
puts("Sono il processo P1");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func7()
{
puts("Sono il processo P1");
return sleep(1u);
}

original_code: void P1() { puts("Sono il processo " "P1" ); sleep(1); }


decompiled_code:
unsigned int P2()
{
puts("Sono il processo P2");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func10()
{
puts("Sono il processo P2");
return sleep(1u);
}

original_code: void P2() { puts("Sono il processo " "P2" ); sleep(1); }


decompiled_code:
unsigned int P3()
{
puts("Sono il processo P3");
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func13()
{
puts("Sono il processo P3");
return sleep(1u);
}

original_code: void P3() { puts("Sono il processo " "P3" ); sleep(1); }


original_code:
void
heap_fix_up (
  heap_t *hp,
  int idx
)
{
  int *qp=hp->qp, *pq=hp->pq;
  int i=qp[idx], p=(((i) - 1) / 2), t;
  char *iv, *pv;
  while (i > 0) {
    iv =(char*) hp->data + hp->elem_size * pq[i];
    pv = (char*)hp->data + hp->elem_size * pq[p];
    if ((*hp->cmp)((void*)iv, (void*)pv) <= 0) {
      return;
    }
    t = pq[i]; pq[i] = pq[p]; pq[p] = t;
    qp[pq[i]] = i; qp[pq[p]] = p;
    i = p; p = (((p) - 1) / 2);
  }
}

canonical_original_code:
void heap_fix_up(struct heap_s *hp, int idx)
{
  int *qp = hp->qp; int *pq = hp->pq;
  int i = qp[idx]; int p = (((i) - 1) / 2); int t;
  char *iv; char *pv;
  while (i > 0) {
    iv =(char *) hp->data + hp->elem_size * pq[i];
    pv = (char *)hp->data + hp->elem_size * pq[p];
    if ((*hp->cmp)((void *)iv, (void *)pv) <= 0) {
      return;
    }
    t = pq[i]; pq[i] = pq[p]; pq[p] = t;
    qp[pq[i]] = i; qp[pq[p]] = p;
    i = p; p = (((p) - 1) / 2);
  }
}

variable_types: struct heap_s { void *data; int num; int size; int elem_size; int (*cmp)(void *lv, void *rv); int *qp; int *pq; } *

variable_types: idx int

variable_types:
qp
int *

variable_types:
pq
int *

variable_types: p int

variable_types: t int

variable_types:
iv
char *

variable_types:
pv
char *


original_code:
void
heap_insert (
  heap_t *hp,
  int idx
)
{
  ((hp->qp[idx]<0) ? (void) (0) : __assert_fail ("hp->qp[idx]<0", "heap.c", 155, __extension__ __PRETTY_FUNCTION__));
  hp->qp[idx] = hp->num;
  hp->pq[hp->num++] = idx;
  heap_fix_up(hp, idx);
}

canonical_original_code:
void heap_insert(struct heap_s *hp, int idx)
{
  ((hp->qp[idx]<0) ? (void) (0) : __assert_fail ("hp->qp[idx]<0", "heap.c", 155, __extension__ __PRETTY_FUNCTION__));
  hp->qp[idx] = hp->num;
  hp->pq[hp->num++] = idx;
  heap_fix_up(hp, idx);
}

user_defined_types: struct heap_s { void *data; int num; int size; int elem_size; int (*cmp)(void *lv, void *rv); int *qp; int *pq; }


original_code:
void
heap_fix_down (
  heap_t *hp,
  int idx
)
{
  int *qp=hp->qp, *pq=hp->pq;
  int i=hp->qp[idx], l, p, r, t;
  char *iv, *lv, *rv;
  do {
    p = i; l = (2 * (i) + 1); r = (2 * (i) + 2);
    iv = (char*)hp->data + hp->elem_size * pq[i];
    if (l < hp->num) {
      lv = (char*)hp->data + hp->elem_size * pq[l];
      if ((*hp->cmp)((void*)lv, (void*)iv) > 0) {
        i = l; iv = lv;
      }
    }
    if (r < hp->num) {
      rv = (char*)hp->data + hp->elem_size * pq[r];
      if ((*hp->cmp)((void*)rv, (void*)iv) > 0) {
        i = r; iv = rv;
      }
    }
    if (i != p) {
      t = pq[i]; pq[i] = pq[p]; pq[p] = t;
      qp[pq[i]] = i, qp[pq[p]] = p;
    }
  } while (i != p);
}

canonical_original_code:
void heap_fix_down(struct heap_s *hp, int idx)
{
  int *qp = hp->qp; int *pq = hp->pq;
  int i = hp->qp[idx]; int l; int p; int r; int t;
  char *iv; char *lv; char *rv;
  do {
    p = i; l = (2 * (i) + 1); r = (2 * (i) + 2);
    iv = (char *)hp->data + hp->elem_size * pq[i];
    if (l < hp->num) {
      lv = (char *)hp->data + hp->elem_size * pq[l];
      if ((*hp->cmp)((void *)lv, (void *)iv) > 0) {
        i = l; iv = lv;
      }
    }
    if (r < hp->num) {
      rv = (char *)hp->data + hp->elem_size * pq[r];
      if ((*hp->cmp)((void *)rv, (void *)iv) > 0) {
        i = r; iv = rv;
      }
    }
    if (i != p) {
      t = pq[i]; pq[i] = pq[p]; pq[p] = t;
      qp[pq[i]] = i, qp[pq[p]] = p;
    }
  } while (i != p);
}

variable_types: i int

variable_types: l int

variable_types: r int

variable_types:
lv
char *

variable_types:
rv
char *


original_code:
int
heap_remove (
  heap_t *hp,
  int idx
)
{
  int i, pos=hp->qp[idx];
  char *iv, *xv;
  ((pos >= 0) ? (void) (0) : __assert_fail ("pos >= 0", "heap.c", 177, __extension__ __PRETTY_FUNCTION__));
  i = hp->pq[--hp->num];
  hp->pq[pos] = i;
  hp->qp[i] = pos;
  hp->qp[idx] = -1;
  if (hp->num>1 && i!=idx) {
    iv = (char*)hp->data + hp->elem_size * i;
    xv = (char*)hp->data + hp->elem_size * idx;
    if ((*hp->cmp)((void*)iv, (void*)xv) > 0) {
      heap_fix_up(hp, i);
    } else {
      heap_fix_down(hp, i);
    }
  }
  return idx;
}

canonical_original_code:
int heap_remove(struct heap_s *hp, int idx)
{
  int i; int pos = hp->qp[idx];
  char *iv; char *xv;
  ((pos >= 0) ? (void) (0) : __assert_fail ("pos >= 0", "heap.c", 177, __extension__ __PRETTY_FUNCTION__));
  i = hp->pq[--hp->num];
  hp->pq[pos] = i;
  hp->qp[i] = pos;
  hp->qp[idx] = -1;
  if (hp->num>1 && i!=idx) {
    iv = (char *)hp->data + hp->elem_size * i;
    xv = (char *)hp->data + hp->elem_size * idx;
    if ((*hp->cmp)((void *)iv, (void *)xv) > 0) {
      heap_fix_up(hp, i);
    } else {
      heap_fix_down(hp, i);
    }
  }
  return idx;
}

variable_types: pos int

variable_types:
xv
char *


decompiled_code:
__int64 __fastcall heap_extract(__int64 a1)
{
return heap_remove(a1, **(_DWORD **)(a1 + 40));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return func4(a1, **(_DWORD **)(a1 + 40));
}

original_code:
int
heap_extract (
  heap_t *hp
)
{
  return heap_remove(hp, hp->pq[0]);
}

canonical_original_code:
int heap_extract(struct heap_s *hp)
{
  return heap_remove(hp, hp->pq[0]);
}


decompiled_code:
_BOOL8 __fastcall heap_is_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == 0;
}

original_code:
int
heap_is_empty (
  heap_t *hp
)
{
  return !hp->num;
}

canonical_original_code:
int heap_is_empty(struct heap_s *hp)
{
  return !hp->num;
}


decompiled_code:
_BOOL8 __fastcall is_in_heap(__int64 a1, int a2)
{
return *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, int a2)
{
return *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2) >= 0;
}

original_code:
int
is_in_heap (
  heap_t *hp,
  int idx
)
{
  return hp->qp[idx] >= 0;
}

canonical_original_code:
int is_in_heap(struct heap_s *hp, int idx)
{
  return hp->qp[idx] >= 0;
}


decompiled_code:
__int64 __fastcall heap_free(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}
return 0LL;
}

original_code:
heap_t *
heap_free (
  heap_t *hp
)
{
  if (hp) {
    free(hp->qp);
    free(hp->pq);
    free(hp);
  }
  return ((void *)0);
}

canonical_original_code:
struct heap_s *heap_free(struct heap_s *hp)
{
  if (hp) {
    free(hp->qp);
    free(hp->pq);
    free(hp);
  }
  return ((void *)0);
}

variable_types:
hp
struct heap_s *

return_type: struct heap_s { void *data; int num; int size; int elem_size; int (*cmp)(void *lv, void *rv); int *qp; int *pq; } *


QuickSort

original_code:
void QuickSort(int *list, int beg, int end)
{
  int piv; int tmp;
  int l,r,p;
  while (beg<end){
    l = beg; p = (beg+end)/2; r = end;
    piv = list[p];
    while (1){
      while ( (l<=r) && ( ((list[l])-(piv)) <= 0 ) ) l++;
      while ( (l<=r) && ( ((list[r])-(piv)) > 0 ) ) r--;
      if (l>r) break;
      tmp=list[l]; list[l]=list[r]; list[r]=tmp;
      if (p==r) p=l;
      l++; r--;
    }
    list[p]=list[r]; list[r]=piv;
    r--;
    if ((r-beg)<(end-l)){
      QuickSort(list, beg, r);
      beg=l;
    }
    else{
      QuickSort(list, l, end);
      end=r;
    }
  }
}

canonical_original_code:
void QuickSort(int *list, int beg, int end)
{
  int piv; int tmp;
  int l; int r; int p;
  while (beg<end){
    l = beg; p = (beg+end)/2; r = end;
    piv = list[p];
    while (1){
      while ( (l<=r) && ( ((list[l])-(piv)) <= 0 ) ) l++;
      while ( (l<=r) && ( ((list[r])-(piv)) > 0 ) ) r--;
      if (l>r) break;
      tmp=list[l]; list[l]=list[r]; list[r]=tmp;
      if (p==r) p=l;
      l++; r--;
    }
    list[p]=list[r]; list[r]=piv;
    r--;
    if ((r-beg)<(end-l)){
      QuickSort(list, beg, r);
      beg=l;
    }
    else{
      QuickSort(list, l, end);
      end=r;
    }
  }
}

variable_types:
list
int *

variable_types: beg int

variable_types: end int

variable_types: piv int

variable_types: tmp int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
__int64 v5; // rbx
char **v6; // rbp
void *v7; // rax
void **v8; // rbx
pthread_t *v9; // r12
pthread_t *v10; // r13
unsigned int v11; // er15
char *v12; // rax
const char *v13; // rsi
char *v14; // rax
char *v15; // rax
const char *v16; // rsi
char *v17; // rax
char **v18; // rcx
pthread_t *v19; // rdi
pthread_t v20; // rdi
int v22; // [rsp+Ch] [rbp-4Ch]
char **ptr; // [rsp+10h] [rbp-48h]
void *v24; // [rsp+18h] [rbp-40h]

v4 = atoi(argv[3]);
v5 = v4;
v22 = v4;
ptr = (char **)malloc(16LL * v4);
v6 = ptr;
v7 = malloc(8 * v5);
v24 = v7;
if ( (int)v5 > 0 )
{
v8 = (void **)ptr;
v9 = (pthread_t *)v7;
v10 = (pthread_t *)v7;
v11 = 0;
do
{
++v11;
v12 = (char *)malloc(0x64uLL);
v13 = argv[1];
*v6 = v12;
v14 = stpcpy(v12, v13);
sprintf(v14, "%d.txt", v11);
v15 = (char *)malloc(0x64uLL);
v16 = argv[2];
v6[1] = v15;
v17 = stpcpy(v15, v16);
sprintf(v17, "%d.txt", v11);
v18 = v6;
v19 = v10;
v6 += 2;
++v10;
pthread_create(v19, 0LL, ordina, v18);
}
while ( v11 != v22 );
do
{
v20 = *v9;
v8 += 2;
++v9;
pthread_join(v20, 0LL);
free(*(v8 - 2));
free(*(v8 - 1));
}
while ( v8 != (void **)&ptr[2 * v11] );
}
free(ptr);
free(v24);
return 0;
}

original_code:
int main(int argc, char** argv){
  char *pointer;
  files *args;
  int tot, i;
  pthread_t *tid;
  tot=atoi(argv[3]);
  args=malloc(sizeof(files)*tot);
  tid=malloc(sizeof(pthread_t)*tot);
  for(i=0;i<tot;i++){
    args[i].nome_r=malloc(sizeof(char)*100);
    strcpy(args[i].nome_r,argv[1]);
    pointer=strchr(args[i].nome_r,'\0');
    sprintf(pointer,"%d.txt",i+1);
    args[i].nome_w=malloc(sizeof(char)*100);
    strcpy(args[i].nome_w,argv[2]);
    pointer=strchr(args[i].nome_w,'\0');
    sprintf(pointer,"%d.txt",i+1);
    pthread_create(&tid[i],((void *)0),ordina,(void*) &args[i]);
  }
  for(i=0; i<tot; i++){
    pthread_join(tid[i], ((void *)0));
    free(args[i].nome_r);
    free(args[i].nome_w);
  }
  free(args);
  free(tid);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  char *pointer;
  struct Files *args;
  int tot; int i;
  unsigned long *tid;
  tot=atoi(argv[3]);
  args=malloc(sizeof(files)*tot);
  tid=malloc(sizeof(pthread_t)*tot);
  for(i=0;i<tot;i++){
    args[i].nome_r=malloc(sizeof(char)*100);
    strcpy(args[i].nome_r,argv[1]);
    pointer=strchr(args[i].nome_r,'\0');
    sprintf(pointer,"%d.txt",i+1);
    args[i].nome_w=malloc(sizeof(char)*100);
    strcpy(args[i].nome_w,argv[2]);
    pointer=strchr(args[i].nome_w,'\0');
    sprintf(pointer,"%d.txt",i+1);
    pthread_create(&tid[i],((void *)0),ordina,(void *) &args[i]);
  }
  for(i=0; i<tot; i++){
    pthread_join(tid[i], ((void *)0));
    free(args[i].nome_r);
    free(args[i].nome_w);
  }
  free(args);
  free(tid);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
pointer
char *

variable_types: struct Files { char *nome_r; char *nome_w; } *

variable_types: tot int

variable_types:
tid
unsigned long *


p

decompiled_code:
__int64 p()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 1LL;
}

original_code:
int p() {
  return 1;
}

canonical_original_code:
int p() {
  return 1;
}


argSplit

decompiled_code:
char *__fastcall argSplit(const char *a1)
{
int v1; // edx
const char *v2; // rbx
char v3; // al
char *v4; // rax
char *result; // rax
size_t v6; // rbx

v1 = i_3 + 1;
if ( a1 )
{
v2 = a1;
if ( !i_3 )
goto LABEL_5;
*a1 = 0;
do
{
++v2;
LABEL_5:
v3 = *v2;
}
while ( *v2 == 32 );
if ( v3 != 10 && v3 )
{
i_3 = v1;
v4 = strchr(v2, 32);
argSplit(v4);
result = (char *)r_2;
*(_QWORD *)(r_2 + 8LL * --i_3) = v2;
return result;
}
*v2 = 0;
}
v6 = 8LL * v1;
result = (char *)malloc(v6);
r_2 = (__int64)result;
*(_QWORD *)&result[v6 - 8] = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1)
{
int v1; // edx
const char *v2; // rbx
char v3; // al
char *v4; // rax
char *result; // rax
size_t v6; // rbx

v1 = i_3 + 1;
if ( a1 )
{
v2 = a1;
if ( !i_3 )
goto LABEL_5;
*a1 = 0;
do
{
++v2;
LABEL_5:
v3 = *v2;
}
while ( *v2 == 32 );
if ( v3 != 10 && v3 )
{
i_3 = v1;
v4 = strchr(v2, 32);
func8(v4);
result = (char *)r_2;
*(_QWORD *)(r_2 + 8LL * --i_3) = v2;
return result;
}
*v2 = 0;
}
v6 = 8LL * v1;
result = (char *)malloc(v6);
r_2 = (__int64)result;
*(_QWORD *)&result[v6 - 8] = 0LL;
return result;
}

original_code:
char** argSplit(char*str) {
  static char **r;
  static int i = 0;
  if(str == ((void *)0)){
    r = malloc((i+1) * sizeof(char**));
    r[i] = ((void *)0);
    return r;
  }
  if(i){
    *str= '\0';
    str++;
  }
  while(*str == ' ')
    str++;
  if(*str == '\n' || *str == '\0'){
    *str = '\0';
    r = malloc((i+1) * sizeof(char**));
    r[i] = ((void *)0);
    return r;
  }
  i++;
  (void)argSplit(strchr(str, ' '));
  i--;
  r[i] = str;
  return r;
}

canonical_original_code:
char **argSplit(char *str) {
  static char **r;
  static int i = 0;
  if(str == ((void *)0)){
    r = malloc((i+1) * sizeof(char **));
    r[i] = ((void *)0);
    return r;
  }
  if(i){
    *str= '\0';
    str++;
  }
  while(*str == ' ')
    str++;
  if(*str == '\n' || *str == '\0'){
    *str = '\0';
    r = malloc((i+1) * sizeof(char **));
    r[i] = ((void *)0);
    return r;
  }
  i++;
  (void)argSplit(strchr(str, ' '));
  i--;
  r[i] = str;
  return r;
}

variable_types:
str
char *

variable_types:
r
char **

variable_types: i int

return_type: char **


heapcmp

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

v2 = 1;
if ( *a1 != -1 && *a2 != -1 )
v2 = *a1 - *a2;
return v2;
}

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

v2 = 1;
if ( *a1 != -1 && *a2 != -1 )
v2 = *a1 - *a2;
return v2;
}

original_code:
static int heapcmp (void *a, void *b){
 if(*(int*)a == -1 || *(int*)b == -1)
  return 1;
 return *(int*)a - *(int*)b;
}

canonical_original_code:
static int heapcmp(void *a, void *b){
 if(*(int *)a == -1 || *(int *)b == -1)
  return 1;
 return *(int *)a - *(int *)b;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
unsigned __int64 __fastcall edge_new(unsigned int a1, unsigned int a2)
{
return __PAIR64__(a2, a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
return __PAIR64__(a2, a1);
}

original_code:
edge edge_new(int from, int to, int w){
 edge r;
 r.from = from;
 r.to = to;
 r.w = w;
 return r;
}

canonical_original_code:
struct edge edge_new(int from, int to, int w){
 struct edge r;
 r.from = from;
 r.to = to;
 r.w = w;
 return r;
}

variable_types: from int

variable_types: to int

variable_types: w int

variable_types: struct edge { unsigned int from; float w; }


decompiled_code:
unsigned __int64 __fastcall graph_insert(__int64 a1, unsigned __int64 a2, float a3)
{
unsigned __int64 result; // rax
unsigned __int64 v4; // rcx
_DWORD *v5; // rcx

result = HIDWORD(a2);
if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x34u, "graph_insert");
v4 = *(_QWORD *)(a1 + 8);
if ( (unsigned int)a2 >= v4 || v4 <= HIDWORD(a2) )
_assert_fail("e.from < g->v && e.to < g->v", "graph.c", 0x35u, "graph_insert");
v5 = (_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2));
if ( (*(_BYTE *)(a1 + 24) & 1) != 0 )
*v5 = (int)a3;
else
*v5 = 1;
if ( (_DWORD)a2 == HIDWORD(a2) )
*(_BYTE *)(a1 + 24) |= 2u;
++*(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, unsigned __int64 a2, float a3)
{
unsigned __int64 result; // rax
unsigned __int64 v4; // rcx
_DWORD *v5; // rcx

result = HIDWORD(a2);
if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x34u, "graph_insert");
v4 = *(_QWORD *)(a1 + 8);
if ( (unsigned int)a2 >= v4 || v4 <= HIDWORD(a2) )
_assert_fail("e.from < g->v && e.to < g->v", "graph.c", 0x35u, "graph_insert");
v5 = (_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2));
if ( (*(_BYTE *)(a1 + 24) & 1) != 0 )
*v5 = (int)a3;
else
*v5 = 1;
if ( (_DWORD)a2 == HIDWORD(a2) )
*(_BYTE *)(a1 + 24) |= 2u;
++*(_QWORD *)(a1 + 16);
return result;
}

original_code:
void graph_insert(graph g, edge e){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 52, __extension__ __PRETTY_FUNCTION__));
 ((e.from < g->v && e.to < g->v) ? (void) (0) : __assert_fail ("e.from < g->v && e.to < g->v", "graph.c", 53, __extension__ __PRETTY_FUNCTION__));
 if(g->orientato)
  g->adj[e.from][e.to] = e.w;
 else
  g->adj[e.from][e.to] = 1;
 if(e.from == e.to)
  g->has_gaps = 1;
 g->e++;
}

canonical_original_code:
void graph_insert(struct graph *g, struct edge e){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 52, __extension__ __PRETTY_FUNCTION__));
 ((e.from < g->v && e.to < g->v) ? (void) (0) : __assert_fail ("e.from < g->v && e.to < g->v", "graph.c", 53, __extension__ __PRETTY_FUNCTION__));
 if(g->orientato)
  g->adj[e.from][e.to] = e.w;
 else
  g->adj[e.from][e.to] = 1;
 if(e.from == e.to)
  g->has_gaps = 1;
 g->e++;
}

variable_types: struct graph { int **adj; unsigned long v; unsigned long e; unsigned int orientato; int connesso; } *

user_defined_types: struct edge { unsigned int from; float w; }


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

if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x41u, "graph_remove");
v2 = a1[1];
if ( (unsigned int)a2 >= v2 || (result = HIDWORD(a2), v2 <= HIDWORD(a2)) )
_assert_fail("e.from < g->v && e.to < g->v", "graph.c", 0x42u, "graph_remove");
v4 = *a1;
*((_BYTE *)a1 + 24) |= 0xCu;
*(_DWORD *)(*(_QWORD *)(v4 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2)) = 0;
--a1[2];
return result;
}

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

if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x41u, "graph_remove");
v2 = a1[1];
if ( (unsigned int)a2 >= v2 || (result = HIDWORD(a2), v2 <= HIDWORD(a2)) )
_assert_fail("e.from < g->v && e.to < g->v", "graph.c", 0x42u, "graph_remove");
v4 = *a1;
*((_BYTE *)a1 + 24) |= 0xCu;
*(_DWORD *)(*(_QWORD *)(v4 + 8LL * (unsigned int)a2) + 4LL * HIDWORD(a2)) = 0;
--a1[2];
return result;
}

original_code:
void graph_remove(graph g, edge e){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 65, __extension__ __PRETTY_FUNCTION__));
 ((e.from < g->v && e.to < g->v) ? (void) (0) : __assert_fail ("e.from < g->v && e.to < g->v", "graph.c", 66, __extension__ __PRETTY_FUNCTION__));
 g->connesso = -1;
 g->adj[e.from][e.to] = 0;
 g->e--;
}

canonical_original_code:
void graph_remove(struct graph *g, struct edge e){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 65, __extension__ __PRETTY_FUNCTION__));
 ((e.from < g->v && e.to < g->v) ? (void) (0) : __assert_fail ("e.from < g->v && e.to < g->v", "graph.c", 66, __extension__ __PRETTY_FUNCTION__));
 g->connesso = -1;
 g->adj[e.from][e.to] = 0;
 g->e--;
}

user_defined_types: struct graph { int **adj; unsigned long v; unsigned long e; unsigned int orientato; int connesso; }


decompiled_code:
void __fastcall graph_free(void *ptr)
{
if ( !ptr )
_assert_fail("g != NULL", "graph.c", 0x4Bu, "graph_free");
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( !ptr )
_assert_fail("g != NULL", "graph.c", 0x4Bu, "graph_free");
free(*(void **)ptr);
free(ptr);
}

original_code:
void graph_free(graph g){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 75, __extension__ __PRETTY_FUNCTION__));
 free(g->adj);
 free(g);
}

canonical_original_code:
void graph_free(struct graph *g){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 75, __extension__ __PRETTY_FUNCTION__));
 free(g->adj);
 free(g);
}


decompiled_code:
__int64 __fastcall graph_vertex(__int64 a1)
{
if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x52u, "graph_vertex");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
_assert_fail("g != NULL", "graph.c", 0x52u, "graph_vertex");
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t graph_vertex(graph g){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 82, __extension__ __PRETTY_FUNCTION__));
 return g->v;
}

canonical_original_code:
unsigned long graph_vertex(struct graph *g){
 ((g != ((void *)0)) ? (void) (0) : __assert_fail ("g != NULL", "graph.c", 82, __extension__ __PRETTY_FUNCTION__));
 return g->v;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall graph_is_connected(__int64 a1)
{
return (unsigned int)((char)(16 * *(_BYTE *)(a1 + 24)) >> 6);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return (unsigned int)((char)(16 * *(_BYTE *)(a1 + 24)) >> 6);
}

original_code:
int graph_is_connected(graph g){
 return g->connesso;
}

canonical_original_code:
int graph_is_connected(struct graph *g){
 return g->connesso;
}


original_code:
edge * graph_edges(graph g){
 int i, j, es;
 edge*e;
 if(g == ((void *)0))
  return ((void *)0);
 e = malloc(sizeof(edge) * g->e);
 for(i = es = 0; i < g->v; i++)
  for(j = 0; j < g->v; j++)
   if(g->adj[i][j]){
    e[es] = edge_new(i, j, g->adj[i][j]);
    es++;
   }
 return e;
}

canonical_original_code:
struct edge *graph_edges(struct graph *g){
 int i; int j; int es;
 struct edge *e;
 if(g == ((void *)0))
  return ((void *)0);
 e = malloc(sizeof(edge) * g->e);
 for(i = es = 0; i < g->v; i++)
  for(j = 0; j < g->v; j++)
   if(g->adj[i][j]){
    e[es] = edge_new(i, j, g->adj[i][j]);
    es++;
   }
 return e;
}

variable_types: j int

variable_types: es int

variable_types: struct edge { unsigned int from; float w; } *


decompiled_code:
void graph_dfv()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void graph_dfv(graph g, int s, void*data, void (*visit)(int, void*)){
}

canonical_original_code:
void graph_dfv(struct graph *g, int s, void *data, void (*visit)(int, void *)){
}

variable_types: s int

variable_types:
data
void *

variable_types:
visit
void (*)(int, void *)


decompiled_code:
_DWORD *list_alloc()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

original_code:
list_t *list_alloc()
{
  list_t *lp = (list_t *)malloc(sizeof(list_t));
  if (lp != ((void *)0)) {
    lp->head = ((void *)0);
    lp->num = 0;
  }
  return lp;
}

canonical_original_code:
struct list *list_alloc()
{
  struct list *lp = (list_t *)malloc(sizeof(list_t));
  if (lp != ((void *)0)) {
    lp->head = ((void *)0);
    lp->num = 0;
  }
  return lp;
}

variable_types: struct list { struct listNode { void *data; struct listNode *next; } *head; int num; } *

user_defined_types: struct list { struct listNode *head; int num; }


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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 8);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 8);
return result;
}

original_code:
int list_num(list_t *lp)
{
  return (lp ? lp->num : 0);
}

canonical_original_code:
int list_num(struct list *lp)
{
  return (lp ? lp->num : 0);
}

user_defined_types: struct listNode { void *data; struct listNode *next; }


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

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = newListNode(a2);
if ( !v2 )
return 0LL;
v2[1] = *(_QWORD *)a1;
*(_QWORD *)a1 = v2;
result = (unsigned int)(*(_DWORD *)(a1 + 8) + 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = newListNode(a2);
if ( !v2 )
return 0LL;
v2[1] = *(_QWORD *)a1;
*(_QWORD *)a1 = v2;
result = (unsigned int)(*(_DWORD *)(a1 + 8) + 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
int list_insert(list_t *lp, void *data)
{
  listNode_t *tmp = ((void *)0);
  if (lp == ((void *)0))
    return -1;
  tmp = newListNode(data);
  if (tmp == ((void *)0))
    return 0;
  tmp->next = lp->head;
  lp->head = tmp;
  return ++lp->num;
}

canonical_original_code:
int list_insert(struct list *lp, void *data)
{
  struct listNode *tmp = ((void *)0);
  if (lp == ((void *)0))
    return -1;
  tmp = newListNode(data);
  if (tmp == ((void *)0))
    return 0;
  tmp->next = lp->head;
  lp->head = tmp;
  return ++lp->num;
}

variable_types: struct listNode { void *data; struct listNode *next; } *


original_code:
void *list_remove(list_t *lp, void *data, int (*cmp)(void *, void *))
{
  listNode_t *prev, *succ;
  void *tmp;
  if ((list_num(lp) == 0))
    return ((void *)0);
  prev = lp->head;
  if (cmp(prev->data, data) == 0) {
    lp->num--;
    lp->head = prev->next;
    tmp = prev->data;
    free(prev);
    return tmp;
  }
  succ = prev->next;
  while (succ != ((void *)0)) {
    if (cmp(succ->data, data) == 0) {
      lp->num--;
      prev->next = succ->next;
      tmp = succ->data;
      free(succ);
      return tmp;
    }
    prev = succ;
    succ = succ->next;
  }
  return ((void *)0);
}

canonical_original_code:
void *list_remove(struct list *lp, void *data, int (*cmp)(void *, void *))
{
  struct listNode *prev; struct listNode *succ;
  void *tmp;
  if ((list_num(lp) == 0))
    return ((void *)0);
  prev = lp->head;
  if (cmp(prev->data, data) == 0) {
    lp->num--;
    lp->head = prev->next;
    tmp = prev->data;
    free(prev);
    return tmp;
  }
  succ = prev->next;
  while (succ != ((void *)0)) {
    if (cmp(succ->data, data) == 0) {
      lp->num--;
      prev->next = succ->next;
      tmp = succ->data;
      free(succ);
      return tmp;
    }
    prev = succ;
    succ = succ->next;
  }
  return ((void *)0);
}

variable_types:
cmp
int (*)(void *, void *)

variable_types:
tmp
void *


decompiled_code:
void __fastcall list_free(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *i; // rbp

if ( ptr )
{
for ( i = *(_QWORD **)ptr; *(_QWORD *)ptr; i = *(_QWORD **)ptr )
{
*(_QWORD *)ptr = i[1];
if ( a2 )
a2(*i);
free(i);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *i; // rbp

if ( ptr )
{
for ( i = *(_QWORD **)ptr; *(_QWORD *)ptr; i = *(_QWORD **)ptr )
{
*(_QWORD *)ptr = i[1];
if ( a2 )
a2(*i);
free(i);
}
free(ptr);
}
}

original_code:
void list_free(list_t *lp, void (*quit)(void *))
{
  listNode_t *tmp;
  if (lp == ((void *)0))
    return;
  while (lp->head != ((void *)0)) {
    tmp = lp->head;
    lp->head = tmp->next;
    if (quit != ((void *)0))
      (*quit)(tmp->data);
    free(tmp);
  }
  free(lp);
}

canonical_original_code:
void list_free(struct list *lp, void (*quit)(void *))
{
  struct listNode *tmp;
  if (lp == ((void *)0))
    return;
  while (lp->head != ((void *)0)) {
    tmp = lp->head;
    lp->head = tmp->next;
    if (quit != ((void *)0))
      (*quit)(tmp->data);
    free(tmp);
  }
  free(lp);
}

variable_types:
quit
void (*)(void *)


decompiled_code:
unsigned int P4()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P4 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func10()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P4 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P4() { printf("Sono il processo " "P4" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P5()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P5 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func11()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P5 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P5() { printf("Sono il processo " "P5" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P6()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P6 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func12()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P6 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P6() { printf("Sono il processo " "P6" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P7()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P7 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func13()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P7 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P7() { printf("Sono il processo " "P7" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P8()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P8 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func14()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P8 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P8() { printf("Sono il processo " "P8" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P9()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P9 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func15()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P9 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P9() { printf("Sono il processo " "P9" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // ebx
char *v5; // rbp
int v6; // er12
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-9Ch] BYREF
__int64 v9; // [rsp+14h] [rbp-94h]
__int64 v10; // [rsp+1Ch] [rbp-8Ch]
char v11; // [rsp+24h] [rbp-84h] BYREF
__int64 v12[15]; // [rsp+30h] [rbp-78h]

v3 = 1;
v4 = 0;
v9 = 0x600000003LL;
v5 = (char *)&stat_loc.__iptr + 4;
v12[0] = (__int64)P1;
v12[1] = (__int64)P2;
v12[2] = (__int64)P3;
v12[3] = (__int64)P4;
v12[4] = (__int64)P5;
v12[5] = (__int64)P6;
v12[6] = (__int64)P7;
v12[7] = (__int64)P8;
v12[8] = (__int64)P9;
v10 = 0x900000008LL;
while ( v3 <= v4 )
{
do
{
LABEL_8:
*(_QWORD *)&argc = &stat_loc;
v6 = wait((__WAIT_STATUS)&stat_loc);
}
while ( v6 != -1 );
if ( *__errno_location() != 10 )
{
fwrite(&unk_402128, 1uLL, 0x16uLL, stderr);
return v6;
}
v5 += 4;
if ( &v11 == v5 )
return 0;
v3 = *(_DWORD *)v5;
}
while ( 1 )
{
v6 = fork();
if ( !v6 )
break;
if ( ++v4 == v3 )
goto LABEL_8;
}
((void (__fastcall *)(_QWORD, const char **))v12[v4])(*(_QWORD *)&argc, argv);
return v6;
}

original_code:
int main(int argc, char**argv){
  int i, j, st;
  func tree[] = { P1, P2, P3, P4, P5, P6, P7, P8, P9 };
  int idx[] = { 1, 3, 6, 8, 9 };
  for(i = 0, j=0; i < sizeof(idx)/sizeof(int); i++){
    for(;j<idx[i];j++){
      if(fork() == 0){
        tree[j]();
        return 0;
      }
    }
    while( wait(&st) != -1 ) ;
    if(10 != (*__errno_location ())){
      fprintf(stderr, "C'è stato un errore.\n");
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int i; int j; int st;
  void (*tree[])() = { P1, P2, P3, P4, P5, P6, P7, P8, P9 };
  int idx[] = { 1, 3, 6, 8, 9 };
  for(i = 0, j=0; i < sizeof(idx)/sizeof(int); i++){
    for(;j<idx[i];j++){
      if(fork() == 0){
        tree[j]();
        return 0;
      }
    }
    while( wait(&st) != -1 ) ;
    if(10 != (*__errno_location ())){
      fprintf(stderr, "C'è stato un errore.\n");
      return -1;
    }
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: st int

variable_types:
tree
void (*[])()

variable_types:
idx
int []


decompiled_code:
unsigned int P1()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P1 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func7()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P1 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P1() { printf("Sono il processo " "P1" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P2()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P2 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func8()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P2 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P2() { printf("Sono il processo " "P2" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


decompiled_code:
unsigned int P3()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P3 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

canonical_decompiled_code:
unsigned int func9()
{
unsigned int v0; // eax
int v1; // eax

v0 = getpid();
printf("Sono il processo P3 di pid: %d\n", v0);
v1 = rand();
return sleep(v1 % 5);
}

original_code: void P3() { printf("Sono il processo " "P3" " di pid: %d\n", getpid() ); sleep(rand() % 5); }


original_code:
static void *delete_min(bst_t **rootptr)
{
   bst_t *node;
   void *val;
   while ((*rootptr)->left != ((void *)0))
      rootptr = &((*rootptr)->left);
   node = *rootptr;
   val = node->data;
   *rootptr = (*rootptr)->right;
   free(node);
   return val;
}

canonical_original_code:
static void *delete_min(struct bst **rootptr)
{
   struct bst *node;
   void *val;
   while ((*rootptr)->left != ((void *)0))
      rootptr = &((*rootptr)->left);
   node = *rootptr;
   val = node->data;
   *rootptr = (*rootptr)->right;
   free(node);
   return val;
}

variable_types: struct bst { void *data; struct bst *left; struct bst *right; } **

variable_types:
val
void *


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

if ( !a1 )
return 0LL;
do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return *(_QWORD *)v1;
}

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

if ( !a1 )
return 0LL;
do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return *(_QWORD *)v1;
}

original_code:
void *bst_min(bst_t *root)
{
   if (root == ((void *)0))
      return ((void *)0);
   while (root->left != ((void *)0))
      root = root->left;
   return root->data;
}

canonical_original_code:
void *bst_min(struct bst *root)
{
   if (root == ((void *)0))
      return ((void *)0);
   while (root->left != ((void *)0))
      root = root->left;
   return root->data;
}

variable_types: struct bst { void *data; struct bst *left; struct bst *right; } *


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

if ( !a1 )
return 0LL;
do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return *(_QWORD *)v1;
}

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

if ( !a1 )
return 0LL;
do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return *(_QWORD *)v1;
}

original_code:
void *bst_max(bst_t *root)
{
   if (root == ((void *)0))
      return ((void *)0);
   while (root->right != ((void *)0))
      root = root->right;
   return root->data;
}

canonical_original_code:
void *bst_max(struct bst *root)
{
   if (root == ((void *)0))
      return ((void *)0);
   while (root->right != ((void *)0))
      root = root->right;
   return root->data;
}

user_defined_types: struct bst { void *data; struct bst *left; struct bst *right; }


decompiled_code:
__int64 __fastcall bst_search(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD))
{
_QWORD *v4; // rbx
int i; // eax
_QWORD *v6; // rax
bool v7; // sf

if ( !a1 )
return 0LL;
v4 = a1;
for ( i = a3(a2, *a1); ; i = a3(a2, *v6) )
{
v7 = i < 0;
if ( !i )
return *v4;
v6 = (_QWORD *)v4[1];
if ( !v7 )
v6 = (_QWORD *)v4[2];
v4 = v6;
if ( !v6 )
break;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD))
{
_QWORD *v4; // rbx
int i; // eax
_QWORD *v6; // rax
bool v7; // sf

if ( !a1 )
return 0LL;
v4 = a1;
for ( i = a3(a2, *a1); ; i = a3(a2, *v6) )
{
v7 = i < 0;
if ( !i )
return *v4;
v6 = (_QWORD *)v4[1];
if ( !v7 )
v6 = (_QWORD *)v4[2];
v4 = v6;
if ( !v6 )
break;
}
return 0LL;
}

original_code:
void *bst_search(bst_t *root, void *key, int (*cmp)(void *, void *))
{
 int _cmp;
 while (root != ((void *)0)) {
  _cmp = (*cmp)(key, root->data);
  if (_cmp == 0)
   return root->data;
  if (_cmp < 0)
   root = root->left;
  else
   root = root->right;
 }
 return ((void *)0);
}

canonical_original_code:
void *bst_search(struct bst *root, void *key, int (*cmp)(void *, void *))
{
 int _cmp;
 while (root != ((void *)0)) {
  _cmp = (*cmp)(key, root->data);
  if (_cmp == 0)
   return root->data;
  if (_cmp < 0)
   root = root->left;
  else
   root = root->right;
 }
 return ((void *)0);
}

variable_types:
key
void *


decompiled_code:
__int64 __fastcall bst_visit(_QWORD *a1, unsigned int a2, __int64 (__fastcall *a3)(_QWORD, __int64), __int64 a4)
{
__int64 result; // rax

while ( a1 )
{
if ( a2 != -1 )
{
while ( 1 )
{
bst_visit(a1[1], a2, a3, a4);
if ( a2 )
break;
result = a3(*a1, a4);
a1 = (_QWORD *)a1[2];
if ( !a1 )
return result;
}
result = bst_visit(a1[2], a2, a3, a4);
if ( a2 == 1 )
result = a3(*a1, a4);
return result;
}
a3(*a1, a4);
result = bst_visit(a1[1], 0xFFFFFFFFLL, a3, a4);
a1 = (_QWORD *)a1[2];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, unsigned int a2, __int64 (__fastcall *a3)(_QWORD, __int64), __int64 a4)
{
__int64 result; // rax

while ( a1 )
{
if ( a2 != -1 )
{
while ( 1 )
{
func6(a1[1], a2, a3, a4);
if ( a2 )
break;
result = a3(*a1, a4);
a1 = (_QWORD *)a1[2];
if ( !a1 )
return result;
}
result = func6(a1[2], a2, a3, a4);
if ( a2 == 1 )
result = a3(*a1, a4);
return result;
}
a3(*a1, a4);
result = func6(a1[1], 0xFFFFFFFFLL, a3, a4);
a1 = (_QWORD *)a1[2];
}
return result;
}

original_code:
void bst_visit(bst_t *root, int way, void (*visit)(void *, void *), void *ptr)
{
   if (root == ((void *)0))
      return;
   if (way == -1)
      (*visit)(root->data, ptr);
   bst_visit(root->left, way, visit, ptr);
   if (way == 0)
      (*visit)(root->data, ptr);
   bst_visit(root->right, way, visit, ptr);
   if (way == 1)
      (*visit)(root->data, ptr);
}

canonical_original_code:
void bst_visit(struct bst *root, int way, void (*visit)(void *, void *), void *ptr)
{
   if (root == ((void *)0))
      return;
   if (way == -1)
      (*visit)(root->data, ptr);
   bst_visit(root->left, way, visit, ptr);
   if (way == 0)
      (*visit)(root->data, ptr);
   bst_visit(root->right, way, visit, ptr);
   if (way == 1)
      (*visit)(root->data, ptr);
}

variable_types: way int

variable_types:
visit
void (*)(void *, void *)

variable_types:
ptr
void *


decompiled_code:
void __fastcall bst_free(void *ptr, void (__fastcall *a2)(_QWORD))
{
if ( ptr )
{
bst_free(*((void **)ptr + 1));
bst_free(*((void **)ptr + 2));
if ( a2 )
a2(*(_QWORD *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr, void (__fastcall *a2)(_QWORD))
{
if ( ptr )
{
func8(*((void **)ptr + 1));
func8(*((void **)ptr + 2));
if ( a2 )
a2(*(_QWORD *)ptr);
free(ptr);
}
}

original_code:
void bst_free(bst_t *root, void (*quit)(void *))
{
   if (root == ((void *)0))
      return;
   bst_free(root->left, quit);
   bst_free(root->right, quit);
   if (quit != ((void *)0))
      (*quit)(root->data);
   free(root);
}

canonical_original_code:
void bst_free(struct bst *root, void (*quit)(void *))
{
   if (root == ((void *)0))
      return;
   bst_free(root->left, quit);
   bst_free(root->right, quit);
   if (quit != ((void *)0))
      (*quit)(root->data);
   free(root);
}


decompiled_code:
int __fastcall file_copy(int fd, int a2)
{
int v2; // eax

while ( 1 )
{
v2 = read(fd, &buff_0, 0x1000uLL);
if ( !v2 )
break;
write(a2, &buff_0, v2);
}
close(fd);
return close(a2);
}

canonical_decompiled_code:
int __fastcall func7(int fd, int a2)
{
int v2; // eax

while ( 1 )
{
v2 = read(fd, &buff_0, 0x1000uLL);
if ( !v2 )
break;
write(a2, &buff_0, v2);
}
close(fd);
return close(a2);
}

original_code:
void file_copy(int fdf, int fdt){
  static char buff[4096];
  int r;
  while((r = read(fdf, buff, 4096))){
    write(fdt, buff, r);
  }
  close(fdf);
  close(fdt);
}

variable_types: fdf int

variable_types: fdt int

variable_types:
buff
char [4096]

variable_types: r int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
puts("Utilizzo: copy <from> <to>");
else
dir_copy((char *)argv[1], (char *)argv[2]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
puts("Utilizzo: copy <from> <to>");
else
func9((char *)argv[1], (char *)argv[2]);
return 0;
}

original_code:
int main(int argc, char *argv[]){
  if(argc < 3){
    puts("Utilizzo: copy <from> <to>");
    return 0;
  }
  dir_copy(argv[1], argv[2]);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


find

decompiled_code:
__int64 __fastcall find(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int (__fastcall *a5)(__int64, __int64))
{
__int64 v7; // r12
__int64 v9; // rbx

if ( !a2 )
return 0xFFFFFFFFLL;
v7 = -a3;
v9 = a2;
while ( 1 )
{
a1 += v7;
if ( !a5(a1, a4) )
break;
if ( !--v9 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(v9 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int (__fastcall *a5)(__int64, __int64))
{
__int64 v7; // r12
__int64 v9; // rbx

if ( !a2 )
return 0xFFFFFFFFLL;
v7 = -a3;
v9 = a2;
while ( 1 )
{
a1 += v7;
if ( !a5(a1, a4) )
break;
if ( !--v9 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(v9 - 1);
}

original_code:
int find(const void*haystack, size_t n, size_t s, const void *needle, int (*compare)(const void*, const void*)){
 const char*_m = (const char*)haystack;
 if(n == 0)
  return -1;
 while(n){
  _m -= s;
  if(compare(_m, needle) == 0) return n-1;
  n--;
 }
 return -1;
}

canonical_original_code:
int find(void *haystack, unsigned long n, unsigned long s, void *needle, int (*compare)(void *, void *)){
 char *_m = (const char*)haystack;
 if(n == 0)
  return -1;
 while(n){
  _m -= s;
  if(compare(_m, needle) == 0) return n-1;
  n--;
 }
 return -1;
}

variable_types:
haystack
void *

variable_types:
n
unsigned long

variable_types:
s
unsigned long

variable_types:
needle
void *

variable_types:
compare
int (*)(void *, void *)


bracket

decompiled_code:
__int64 __fastcall bracket(_BYTE *a1, double *a2)
{
char v2; // al
_BYTE *v3; // rbx
char *v4; // rax
char v5; // dl
char *v6; // rdi
char i; // dl
char *v8; // rbx
__int64 result; // rax
char j; // al
int v11; // [rsp+4h] [rbp-24h]
double v12[4]; // [rsp+8h] [rbp-20h] BYREF

v12[0] = 0.0;
if ( !a1 || (v2 = *a1, v3 = a1, !*a1) )
{
error = 1;
return 0LL;
}
for ( ; v2 == 32; ++v3 )
v2 = v3[1];
if ( (v2 & 0xDF) == 91 || v2 == 40 )
{
v4 = (char *)bracket(v3 + 1, v12);
}
else
{
if ( !(unsigned int)__isoc99_sscanf() )
{
LABEL_34:
error = 2;
return 0LL;
}
v4 = &v3[v11];
}
v5 = *v4;
v6 = v4 + 1;
if ( (*v4 & 0xDF) != 93 )
{
while ( v5 != 41 )
{
if ( !v5 )
{
error = 3;
break;
}
if ( error )
break;
for ( i = *v4; i == 32; ++v6 )
{
i = *v6;
v4 = v6;
}
v8 = v6;
switch ( i )
{
case '-':
result = bracket(v6, &tmp_1);
*a2 = v12[0] - *(double *)&tmp_1;
return result;
case '|':
for ( j = v4[1]; j == 32; ++v8 )
j = v8[1];
if ( (j & 0xDF) == 91 || j == 40 )
{
v4 = (char *)bracket(v8 + 1, &tmp_1);
}
else
{
if ( !(unsigned int)__isoc99_sscanf() )
goto LABEL_34;
v4 = &v8[v11];
}
v6 = v4 + 1;
v12[0] = v12[0] * *(double *)&tmp_1 / (fabs(v12[0]) + *(double *)&tmp_1);
v5 = *v4;
if ( (*v4 & 0xDF) == 93 )
goto LABEL_18;
break;
case '+':
result = bracket(v6, &tmp_1);
*a2 = v12[0] + *(double *)&tmp_1;
return result;
default:
error = 2;
v5 = *v4;
if ( (*v4 & 0xDF) == 93 )
goto LABEL_18;
break;
}
}
}
LABEL_18:
result = (__int64)v6;
*a2 = v12[0];
return result;
}

original_code:
const char* bracket(const char*c, double*res){
  static double tmp;
  double larg = 0;
  int n;
  if(c == ((void *)0) || *c == '\0'){
    error = empty;
    return 0;
  }
  while(*c == ' ')
    c++;
  if(*c == '(' || *c == '[' || *c == '{')
    c = bracket(c+1, &larg);
  else if(!sscanf(c, "%lf%n", &larg, &n)){
    error = badformat;
    return ((void *)0);
  }
  else
    c += n;
  while(*c != '}' && *c != ']' && *c != ')' && *c != '\0' && error == none){
    while(*c == ' ')
      c++;
    switch(*c) {
    case '|':
      c++;
      while(*c == ' ') c++;
      if(*c == '(' || *c == '[' || *c == '{')
 c = bracket(c+1, &tmp);
      else if(!sscanf(c, "%lf%n", &tmp, &n)){
 error = badformat;
 return 0;
      }
      else
 c +=n;
      larg = larg * tmp / (fabs(larg) + tmp);
      break;
    case '+':
      c = bracket(c+1, &tmp);
      *res = larg + tmp;
      return c;
    case '-':
      c = bracket(c+1, &tmp);
      *res = larg - tmp;
      return c;
    default:
      error = badformat;
    }
  }
  if(*c == '\0')
    error = parmismatch;
  *res = larg;
  return c+1;
}

canonical_original_code:
char *bracket(char *c, double *res){
  static double tmp;
  double larg = 0;
  int n;
  if(c == ((void *)0) || *c == '\0'){
    error = empty;
    return 0;
  }
  while(*c == ' ')
    c++;
  if(*c == '(' || *c == '[' || *c == '{')
    c = bracket(c+1, &larg);
  else if(!sscanf(c, "%lf%n", &larg, &n)){
    error = badformat;
    return ((void *)0);
  }
  else
    c += n;
  while(*c != '}' && *c != ']' && *c != ')' && *c != '\0' && error == none){
    while(*c == ' ')
      c++;
    switch(*c) {
    case '|':
      c++;
      while(*c == ' ') c++;
      if(*c == '(' || *c == '[' || *c == '{')
 c = bracket(c+1, &tmp);
      else if(!sscanf(c, "%lf%n", &tmp, &n)){
 error = badformat;
 return 0;
      }
      else
 c +=n;
      larg = larg * tmp / (fabs(larg) + tmp);
      break;
    case '+':
      c = bracket(c+1, &tmp);
      *res = larg + tmp;
      return c;
    case '-':
      c = bracket(c+1, &tmp);
      *res = larg - tmp;
      return c;
    default:
      error = badformat;
    }
  }
  if(*c == '\0')
    error = parmismatch;
  *res = larg;
  return c+1;
}

variable_types:
c
char *

variable_types:
res
double *

variable_types: tmp double

variable_types: larg double

variable_types: n int

return_type: char *


eval

decompiled_code:
double __fastcall eval(char *a1)
{
char v1; // al
__int64 *v2; // rsi
unsigned __int8 *v3; // rax
unsigned __int8 v4; // dl
__int64 v5; // rdx
double v7; // xmm0_8
unsigned __int8 *v8; // rbx
unsigned __int8 i; // al
double v10; // rbx
int v11; // [rsp+14h] [rbp-14h]
__int64 v12[2]; // [rsp+18h] [rbp-10h] BYREF

v12[0] = 0LL;
if ( !a1 || (v1 = *a1) == 0 )
{
error = 1;
return 0.0;
}
while ( v1 == 32 )
v1 = *++a1;
if ( (v1 & 0xDF) == 91 || v1 == 40 )
{
v2 = v12;
v3 = (unsigned __int8 *)bracket(a1 + 1, (double *)v12);
}
else
{
v2 = (__int64 *)"%lf%n";
if ( !(unsigned int)__isoc99_sscanf() )
{
LABEL_34:
error = 2;
return 0.0;
}
v3 = (unsigned __int8 *)&a1[v11];
}
v4 = *v3;
LOBYTE(v2) = *v3 != 0;
if ( v4 != 41 && v4 != 0 )
{
while ( (v4 & 0xDF) != 93 && !error )
{
while ( 1 )
{
v5 = *v3;
if ( (_BYTE)v5 != 32 )
break;
++v3;
}
switch ( (_BYTE)v5 )
{
case '-':
v10 = *(double *)v12;
return v10 - eval(v3 + 1, v2, v5);
case '|':
v8 = v3 + 1;
for ( i = v3[1]; i == 32; ++v8 )
i = v8[1];
if ( (i & 0xDF) == 91 || i == 40 )
{
v2 = &tmp_0;
v3 = (unsigned __int8 *)bracket(v8 + 1, (double *)&tmp_0);
}
else
{
v2 = (__int64 *)"%lf%n";
if ( !(unsigned int)__isoc99_sscanf() )
goto LABEL_34;
v3 = &v8[v11];
}
*(double *)v12 = *(double *)v12 * *(double *)&tmp_0 / (fabs(*(double *)v12) + *(double *)&tmp_0);
break;
case '+':
v7 = eval(v3 + 1, v2, v5);
return v7 + *(double *)v12;
default:
error = 2;
break;
}
v4 = *v3;
LOBYTE(v2) = *v3 != 41;
if ( v4 == 0 || v4 == 41 )
return *(double *)v12;
}
}
return *(double *)v12;
}

original_code:
double eval(const char*c) {
  static double tmp;
  double larg = 0;
  int n;
  if(c == ((void *)0) || *c == '\0'){
    error = empty;
    return 0;
  }
  while(*c == ' ')
    c++;
  if(*c == '(' || *c == '[' || *c == '{')
    c = bracket(c+1, &larg);
  else if(!sscanf(c, "%lf%n", &larg, &n)){
    error = badformat;
    return 0;
  }
  else
    c += n;
  while(*c != '}' && *c != ']' && *c != ')' && *c != '\0' && error == none){
    while(*c == ' ')
      c++;
    switch(*c) {
    case '|':
      c++;
      while(*c == ' ') c++;
      if(*c == '(' || *c == '[' || *c == '{')
 c = bracket(c+1, &tmp);
      else if(!sscanf(c, "%lf%n", &tmp, &n)){
 error = badformat;
 return 0;
      }
      else
 c += n;
      larg = larg * tmp / (fabs(larg) + tmp);
      break;
    case '+':
      return larg + eval(c+1);
    case '-':
      return larg - eval(c+1);
    default:
      error = badformat;
    }
  }
  return larg;
}

canonical_original_code:
double eval(char *c) {
  static double tmp;
  double larg = 0;
  int n;
  if(c == ((void *)0) || *c == '\0'){
    error = empty;
    return 0;
  }
  while(*c == ' ')
    c++;
  if(*c == '(' || *c == '[' || *c == '{')
    c = bracket(c+1, &larg);
  else if(!sscanf(c, "%lf%n", &larg, &n)){
    error = badformat;
    return 0;
  }
  else
    c += n;
  while(*c != '}' && *c != ']' && *c != ')' && *c != '\0' && error == none){
    while(*c == ' ')
      c++;
    switch(*c) {
    case '|':
      c++;
      while(*c == ' ') c++;
      if(*c == '(' || *c == '[' || *c == '{')
 c = bracket(c+1, &tmp);
      else if(!sscanf(c, "%lf%n", &tmp, &n)){
 error = badformat;
 return 0;
      }
      else
 c += n;
      larg = larg * tmp / (fabs(larg) + tmp);
      break;
    case '+':
      return larg + eval(c+1);
    case '-':
      return larg - eval(c+1);
    default:
      error = badformat;
    }
  }
  return larg;
}

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
const char **v4; // rbp
__int64 v5; // rbx

if ( argc <= 1 )
{
puts("Utilizzo:\n\teval expression1 [expression2 [...] ]");
}
else
{
v4 = argv;
v5 = 1LL;
do
{
while ( 1 )
{
eval(v4[v5], argv, envp);
argv = (const char **)v4[v5];
printf("%s = %lf\n", (const char *)argv, v3);
if ( error )
break;
if ( argc == ++v5 )
return 0;
}
argv = (const char **)(unsigned int)v5++;
printf("Errore nell'argomento %d: %s\n", argv, errs_2[error - 1]);
error = 0;
}
while ( argc != v5 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
const char **v4; // rbp
__int64 v5; // rbx

if ( argc <= 1 )
{
puts("Utilizzo:\n\teval expression1 [expression2 [...] ]");
}
else
{
v4 = argv;
v5 = 1LL;
do
{
while ( 1 )
{
func8(v4[v5], argv, envp);
argv = (const char **)v4[v5];
printf("%s = %lf\n", (const char *)argv, v3);
if ( error )
break;
if ( argc == ++v5 )
return 0;
}
argv = (const char **)(unsigned int)v5++;
printf("Errore nell'argomento %d: %s\n", argv, errs_2[error - 1]);
error = 0;
}
while ( argc != v5 );
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  int i;
  static const char* errs [] = {
    "Stringa vuota",
    "Errore di formattazione",
    "Errore di parentesizzazione"
  };
  if(argc < 2) {
    printf("Utilizzo:\n\teval expression1 [expression2 [...] ]\n");
    return 0;
  }
  for(i = 1; i<argc; i++){
    printf("%s = %lf\n", argv[i], eval(argv[i]));
    if(error){
      printf("Errore nell'argomento %d: %s\n", i, errs[(int)error-1]);
      error = none;
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int i;
  static char *errs[] = {
    "Stringa vuota",
    "Errore di formattazione",
    "Errore di parentesizzazione"
  };
  if(argc < 2) {
    printf("Utilizzo:\n\teval expression1 [expression2 [...] ]\n");
    return 0;
  }
  for(i = 1; i<argc; i++){
    printf("%s = %lf\n", argv[i], eval(argv[i]));
    if(error){
      printf("Errore nell'argomento %d: %s\n", i, errs[(int)error-1]);
      error = none;
    }
  }
  return 0;
}

variable_types: i int

variable_types:
errs
char *[]


decompiled_code:
__int64 __fastcall stack_pop(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // r12

if ( !a1 )
return 0LL;
*a2 = *a1;
v2 = a1[1];
free(a1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // r12

if ( !a1 )
return 0LL;
*a2 = *a1;
v2 = a1[1];
free(a1);
return v2;
}

original_code:
stack_t *stack_pop(stack_t *sp, void **valptr)
{
  stack_t *node = sp;
  if (sp == ((void *)0))
     return ((void *)0);
  *valptr = sp->data;
  sp = sp->next;
  free(node);
  return sp;
}

canonical_original_code:
struct stack *stack_pop(struct stack *sp, void **valptr)
{
  struct stack *node = sp;
  if (sp == ((void *)0))
     return ((void *)0);
  *valptr = sp->data;
  sp = sp->next;
  free(node);
  return sp;
}

variable_types:
sp
struct stack *

variable_types:
valptr
void **

variable_types: struct stack { void *data; struct stack *next; } *


Queue

repo: marcobenatto/graphollock

decompiled_code:
__int64 __fastcall Queue(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(int *)(a1 + 4);
if ( (int)result >= *(_DWORD *)(a1 + 8) )
{
fwrite("Don't have space enought in the queue...fisinhing....\n", 1uLL, 0x36uLL, stderr);
exit(12);
}
v3 = *(_QWORD *)(a1 + 16);
*(_DWORD *)(a1 + 4) = result + 1;
*(_DWORD *)(v3 + 4 * result) = a2;
return result;
}

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

result = *(int *)(a1 + 4);
if ( (int)result >= *(_DWORD *)(a1 + 8) )
{
fwrite("Don't have space enought in the queue...fisinhing....\n", 1uLL, 0x36uLL, stderr);
exit(12);
}
v3 = *(_QWORD *)(a1 + 16);
*(_DWORD *)(a1 + 4) = result + 1;
*(_DWORD *)(v3 + 4 * result) = a2;
return result;
}

original_code:
void Queue(queue *q, int v){
 if (q->end >= q->size){
  fprintf(stderr, "Don't have space enought in the queue...fisinhing....\n");
  exit(12);
 }
 q->data[q->end++] = v;
}

canonical_original_code:
void Queue(struct queue *q, int v){
 if (q->end >= q->size){
  fprintf(stderr, "Don't have space enought in the queue...fisinhing....\n");
  exit(12);
 }
 q->data[q->end++] = v;
}

variable_types: struct queue { int start; int end; int size; int *data; } *

variable_types: v int


Dequeue

decompiled_code:
__int64 __fastcall Dequeue(int *a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = *a1;
if ( (int)v1 >= a1[1] )
{
fwrite("Don't have space enought in the queue...fisinhing....\n", 1uLL, 0x36uLL, stderr);
exit(12);
}
v2 = *((_QWORD *)a1 + 2);
*a1 = v1 + 1;
return *(unsigned int *)(v2 + 4 * v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = *a1;
if ( (int)v1 >= a1[1] )
{
fwrite("Don't have space enought in the queue...fisinhing....\n", 1uLL, 0x36uLL, stderr);
exit(12);
}
v2 = *((_QWORD *)a1 + 2);
*a1 = v1 + 1;
return *(unsigned int *)(v2 + 4 * v1);
}

original_code:
int Dequeue(queue *q){
 if (q->start >= q->end){
  fprintf(stderr, "Don't have space enought in the queue...fisinhing....\n");
  exit(12);
 }
 return q->data[q->start++];
}

canonical_original_code:
int Dequeue(struct queue *q){
 if (q->start >= q->end){
  fprintf(stderr, "Don't have space enought in the queue...fisinhing....\n");
  exit(12);
 }
 return q->data[q->start++];
}

user_defined_types: struct queue { int start; int end; int size; int *data; }


DestroyQueue

decompiled_code:
void __fastcall DestroyQueue(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void DestroyQueue(queue *q){
 free(q->data);
 free(q);
}

canonical_original_code:
void DestroyQueue(struct queue *q){
 free(q->data);
 free(q);
}


decompiled_code:
void __fastcall destroy_matrix(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
void destroy_matrix(unsigned int **m, int l, int c)
{
 int i;
 for (i = 0; i < l; i++)
  free(*(m + i));
 free(m);
}

variable_types:
m
unsigned int **

variable_types: l int

variable_types: c int


original_code:
void handle_line(unsigned int **m, char *line, int l, int actual_line)
{
 int i;
    char aux;
 short aux2;
 for (i = 0; i < l; i++)
 {
  aux = *(line + i);
  aux2 = atoi(&aux);
  *(*(m + actual_line) + i) = aux2;
 }
}

variable_types:
line
char *

variable_types: aux char


decompiled_code:
int __fastcall print_matrix(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // r14
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // rdx
int result; // eax

if ( a2 > 0 )
{
v3 = a1;
v5 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
v7 = *(unsigned int *)(*v3 + v6);
v6 += 4LL;
fprintf(stdout, "%d ", v7);
}
while ( v5 != v6 );
}
++v3;
result = fputc(10, stdout);
}
while ( v3 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // r14
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // rdx
int result; // eax

if ( a2 > 0 )
{
v3 = a1;
v5 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
v7 = *(unsigned int *)(*v3 + v6);
v6 += 4LL;
fprintf(stdout, "%d ", v7);
}
while ( v5 != v6 );
}
++v3;
result = fputc(10, stdout);
}
while ( v3 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

original_code:
void print_matrix(unsigned int **m, int l, int c)
{
 int i, j;
 for (i = 0; i < l; i++)
 {
  for(j = 0; j < c; j++){
   fprintf(stdout, "%d ", *(*(m + i) + j));
  }
  fprintf(stdout, "\n");
 }
}

canonical_original_code:
void print_matrix(unsigned int **m, int l, int c)
{
 int i; int j;
 for (i = 0; i < l; i++)
 {
  for(j = 0; j < c; j++){
   fprintf(stdout, "%d ", *(*(m + i) + j));
  }
  fprintf(stdout, "\n");
 }
}

variable_types: j int


repo: marcocarnut/rxe

decompiled_code:
void __fastcall __noreturn kmalloc_failed(unsigned int a1, const char *a2, unsigned int a3)
{
fprintf(stderr, "Can't get %d bytes of memory at %s line %d.", a1, a2, a3);
exit(111);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1, const char *a2, unsigned int a3)
{
fprintf(stderr, "Can't get %d bytes of memory at %s line %d.", a1, a2, a3);
exit(111);
}

original_code:
void kmalloc_failed(size_t size, char *file, int line)
{
    fprintf(stderr,"Can't get %d bytes of memory at %s line %d.",
        (int)size,file,line);
    exit(111);
}

canonical_original_code:
void kmalloc_failed(unsigned long size, char *file, int line)
{
    fprintf(stderr,"Can't get %d bytes of memory at %s line %d.",
        (int)size,file,line);
    exit(111);
}

variable_types:
size
unsigned long

variable_types:
file
char *

variable_types: line int


decompiled_code:
void __fastcall rxe_set_alloc(__int64 a1, __int64 a2, __int64 a3)
{
rxe_mem_alloc = a1;
rxe_mem_free = a2;
rxe_mem_alloc_failed = a3;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
rxe_mem_alloc = a1;
rxe_mem_free = a2;
rxe_mem_alloc_failed = a3;
}

original_code:
void rxe_set_alloc(
    void * (*malloc_func)(size_t),
    void (*free_func)(void *),
    void (*fail_func)(size_t size, char *file, int line)
)
{
    rxe_mem_alloc = malloc_func;
    rxe_mem_free = free_func;
    rxe_mem_alloc_failed = fail_func;
}

canonical_original_code:
void rxe_set_alloc(void *(*malloc_func)(unsigned long), void (*free_func)(void *), void (*fail_func)(unsigned long size, char *file, int line))
{
    rxe_mem_alloc = malloc_func;
    rxe_mem_free = free_func;
    rxe_mem_alloc_failed = fail_func;
}

variable_types: void (*)(unsigned long size, char *file, int line)


decompiled_code:
void rxe_init()
{
rxe_initialized = 1;
rxe_set_alloc((__int64)&malloc, (__int64)&free, (__int64)kmalloc_failed);
}

canonical_decompiled_code:
void func2()
{
rxe_initialized = 1;
func1((__int64)&malloc, (__int64)&free, (__int64)kmalloc_failed);
}

original_code:
void rxe_init(void)
{
    int n;
    rxe_initialized = 1;
    rxe_set_alloc(malloc,free,kmalloc_failed);
}

canonical_original_code:
void rxe_init()
{
    int n;
    rxe_initialized = 1;
    rxe_set_alloc(malloc,free,kmalloc_failed);
}

variable_types: n int


original_code:
char *rxe_current(char *str, int maxlen, struct rxe *rxe)
{
    if (maxlen<=0) return;
    str[0] = 0;
    struct rxe_alt *alt = rxe->curr;
    struct rxe_node *node;
    for ( node = alt->head ; node ; node = node->next ) {
        if (node->rxe) {
            char *new_str = rxe_current(str,maxlen,node->rxe);
            maxlen -= new_str - str;
            str = new_str;
        } else {
            if (maxlen>0) {
                *str++ = node->str[node->iterator];
                maxlen--;
            }
        }
    }
    *str = 0;
    return str;
}

variable_types:
str
char *

variable_types: maxlen int

variable_types: struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe *rxe; struct rxe_node *prev; struct rxe_node *next; } *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } *

variable_types: struct rxe_alt { int nnodes; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } *rxe; struct rxe_node *prev; struct rxe_node *next; } *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *

variable_types: struct rxe_node { int len; char *str; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; struct rxe_node *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } *rxe; struct rxe_node *prev; struct rxe_node *next; } *

user_defined_types: struct rxe { int nalts; enum rxe_parse_status status; struct rxe_alt *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table *brt; int flags; }


original_code:
int rxe_iterate(struct rxe *rxe)
{
    if (!rxe || !rxe->curr) return 1;
    struct rxe_alt *alt = rxe->curr;
    if (!alt) return 1;
    struct rxe_node *node = alt->tail;
    int carry = 1;
    if (node) {
        while (carry) {
            if (node->rxe && !node->is_backref) {
                carry = rxe_iterate(node->rxe);
            }
            if (carry) {
                if (++node->iterator >= node->len) {
                    node->iterator = 0;
                    node = node->prev;
                    if (!node) break;
                } else {
                    carry = 0;
                }
            }
        }
    }
    if (carry) {
        alt = alt->next;
        if (alt) {
            rxe->curr = alt;
            carry = 0;
        } else {
            rxe->curr = rxe->head;
        }
    }
    return carry;
}

variable_types: carry int

user_defined_types: struct rxe_alt { int nnodes; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; struct rxe_node *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; }

user_defined_types: struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe *rxe; struct rxe_node *prev; struct rxe_node *next; }

user_defined_types: enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 }

user_defined_types: struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; }

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


original_code:
int rxe_seek(struct rxe *rxe, mpz_t pos)
{
    if (!rxe) return;
    mpz_t q,r,p,n;
    __gmpz_init(q);
    __gmpz_init(r);
    __gmpz_init(n);
    __gmpz_init_set(p,pos);
    struct rxe_alt *alt;
    struct rxe_node *node = ((void *)0);
    for ( alt = rxe->tail ; alt ; alt = alt->prev ) {
        if (__gmpz_cmp(alt->start,pos)<=0) {
            rxe->curr = alt;
            node = alt->tail;
            __gmpz_sub(p,p,alt->start);
            break;
        }
    }
    for ( ; node ; node = node->prev ) {
        if (node->is_backref) continue;
        __gmpz_set(n, node->rxe ? node->rxe->nitems : node->nitems);
        ((void) sizeof ((((n)->_mp_size < 0 ? -1 : (n)->_mp_size > 0)!=0) ? 1 : 0), __extension__ ({ if (((n)->_mp_size < 0 ? -1 : (n)->_mp_size > 0)!=0) ; else __assert_fail ("mpz_sgn(n)!=0", "rxe.c", 158, __extension__ __PRETTY_FUNCTION__); }));
        __gmpz_tdiv_qr(q,r,p,n);
        __gmpz_set(p,q);
        if (node->rxe) {
            rxe_seek(node->rxe,r);
            __gmpz_set(n,node->rxe->nitems);
        } else {
            node->iterator = __gmpz_get_ui(r);
        }
    }
    if (((q)->_mp_size < 0 ? -1 : (q)->_mp_size > 0)>0 && (__builtin_constant_p (1) && (1) == 0 ? ((n)->_mp_size < 0 ? -1 : (n)->_mp_size > 0) : __gmpz_cmp_ui (n,1))>0 || ((p)->_mp_size < 0 ? -1 : (p)->_mp_size > 0)>0)
        return 1;
    return 0;
}

canonical_original_code:
int rxe_seek(struct rxe *rxe, struct __mpz_struct pos[1])
{
    if (!rxe) return;
    struct __mpz_struct q[1]; struct __mpz_struct r[1]; struct __mpz_struct p[1]; struct __mpz_struct n[1];
    __gmpz_init(q);
    __gmpz_init(r);
    __gmpz_init(n);
    __gmpz_init_set(p,pos);
    struct rxe_alt *alt;
    struct rxe_node *node = ((void *)0);
    for ( alt = rxe->tail ; alt ; alt = alt->prev ) {
        if (__gmpz_cmp(alt->start,pos)<=0) {
            rxe->curr = alt;
            node = alt->tail;
            __gmpz_sub(p,p,alt->start);
            break;
        }
    }
    for ( ; node ; node = node->prev ) {
        if (node->is_backref) continue;
        __gmpz_set(n, node->rxe ? node->rxe->nitems : node->nitems);
        ((void) sizeof ((((n)->_mp_size < 0 ? -1 : (n)->_mp_size > 0)!=0) ? 1 : 0), __extension__ ({ if (((n)->_mp_size < 0 ? -1 : (n)->_mp_size > 0)!=0) ; else __assert_fail ("mpz_sgn(n)!=0", "rxe.c", 158, __extension__ __PRETTY_FUNCTION__); }));
        __gmpz_tdiv_qr(q,r,p,n);
        __gmpz_set(p,q);
        if (node->rxe) {
            rxe_seek(node->rxe,r);
            __gmpz_set(n,node->rxe->nitems);
        } else {
            node->iterator = __gmpz_get_ui(r);
        }
    }
    if (((q)->_mp_size < 0 ? -1 : (q)->_mp_size > 0)>0 && (__builtin_constant_p (1) && (1) == 0 ? ((n)->_mp_size < 0 ? -1 : (n)->_mp_size > 0) : __gmpz_cmp_ui (n,1))>0 || ((p)->_mp_size < 0 ? -1 : (p)->_mp_size > 0)>0)
        return 1;
    return 0;
}

variable_types:
pos
struct __mpz_struct [1]

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]


decompiled_code:
__int64 __fastcall rxe_free(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

v2 = *(_QWORD *)(a1 + 8);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 72);
rxe_free_alt(v3);
}
if ( (*(_BYTE *)(a1 + 56) & 2) != 0 )
rxe_backref_table_free(*(_QWORD *)(a1 + 48));
_gmpz_clear(a1 + 32);
return rxe_mem_free(a1);
}

original_code:
void rxe_free(struct rxe *rxe)
{
    struct rxe_alt *alt,*next;
    for ( alt = rxe->head ; alt ; alt = next ) {
        next = alt->next;
        rxe_free_alt(alt);
    }
    if (rxe->flags & 2)
        rxe_backref_table_free(rxe->brt);
    __gmpz_clear(rxe->nitems);
    rxe_mem_free(rxe);
}

canonical_original_code:
void rxe_free(struct rxe *rxe)
{
    struct rxe_alt *alt; struct rxe_alt *next;
    for ( alt = rxe->head ; alt ; alt = next ) {
        next = alt->next;
        rxe_free_alt(alt);
    }
    if (rxe->flags & 2)
        rxe_backref_table_free(rxe->brt);
    __gmpz_clear(rxe->nitems);
    rxe_mem_free(rxe);
}


original_code:
struct rxe *rxe_new(void)
{
    struct rxe *rxe = ((struct rxe *)kmalloc(sizeof(struct rxe)*(1),"rxe.c",187));
    rxe->head = rxe-> tail = rxe->curr = ((void *)0);
    rxe->nalts = 0;
    rxe->brt = ((void *)0);
    rxe->flags = 0;
    __gmpz_init(rxe->nitems);
    return rxe;
}

canonical_original_code:
struct rxe *rxe_new()
{
    struct rxe *rxe = ((struct rxe *)kmalloc(sizeof(struct rxe)*(1),"rxe.c",187));
    rxe->head = rxe-> tail = rxe->curr = ((void *)0);
    rxe->nalts = 0;
    rxe->brt = ((void *)0);
    rxe->flags = 0;
    __gmpz_init(rxe->nitems);
    return rxe;
}

return_type: struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe *rxe; struct rxe_node *prev; struct rxe_node *next; } *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } *


decompiled_code:
__int64 __fastcall rxe_node_deep_clone(__int64 a1, int *a2, int a3)
{
__int64 v4; // rax
__int64 v5; // rdi
int *v6; // rbp
__int64 v7; // rdi
void *v8; // rax
size_t v9; // rdx

v4 = rxe_new_node();
v5 = *((_QWORD *)a2 + 7);
v6 = (int *)v4;
if ( v5 )
{
if ( !a2[13] && !a3 )
v5 = rxe_deep_clone();
*((_QWORD *)v6 + 7) = v5;
}
v7 = *a2;
if ( (_DWORD)v7 )
{
*v6 = v7;
if ( (int)v7 > 255 )
_assert_fail("src_node->len<256", "rxe.c", 0xD0u, "rxe_node_deep_clone");
v8 = kmalloc(v7, (__int64)"rxe.c", 0xD1u);
v9 = *v6;
*((_QWORD *)v6 + 1) = v8;
memcpy(v8, *((const void **)a2 + 1), v9);
}
v6[13] = a2[13];
return _gmpz_set(v6 + 4, a2 + 4);
}

original_code:
void rxe_node_deep_clone(struct rxe_alt *alt, struct rxe_node *src_node, int shallow)
{
    struct rxe_node *dst_node = rxe_new_node(alt);
    if (src_node->rxe) {
        if (src_node->is_backref) {
            dst_node->rxe = src_node->rxe;
        } else {
            dst_node->rxe = shallow ? src_node->rxe : rxe_deep_clone(src_node->rxe);
        }
    }
    if (src_node->len) {
        dst_node->len = src_node->len;
        ((void) sizeof ((src_node->len<256) ? 1 : 0), __extension__ ({ if (src_node->len<256) ; else __assert_fail ("src_node->len<256", "rxe.c", 208, __extension__ __PRETTY_FUNCTION__); }));
        dst_node->str = ((char *)kmalloc(sizeof(char)*(dst_node->len),"rxe.c",209));
        memcpy(dst_node->str,src_node->str,dst_node->len);
    }
    dst_node->is_backref = src_node->is_backref;
    __gmpz_set(dst_node->nitems,src_node->nitems);
}

variable_types: shallow int


decompiled_code:
__int64 __fastcall rxe_backref_table_new(int a1)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = kmalloc(16LL, "bkreftbl.c", 24LL);
*(_DWORD *)(v1 + 4) = a1;
v2 = v1;
*(_DWORD *)v1 = 0;
*(_QWORD *)(v1 + 8) = kmalloc(8LL * a1, "bkreftbl.c", 27LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = kmalloc(16LL, "bkreftbl.c", 24LL);
*(_DWORD *)(v1 + 4) = a1;
v2 = v1;
*(_DWORD *)v1 = 0;
*(_QWORD *)(v1 + 8) = kmalloc(8LL * a1, "bkreftbl.c", 27LL);
return v2;
}

original_code:
struct rxe_backref_table *rxe_backref_table_new(int size_hint)
{
    struct rxe_backref_table *brt;
    brt = ((struct rxe_backref_table *)kmalloc(sizeof(struct rxe_backref_table)*(1),"bkreftbl.c",24));
    brt->nbackrefs = 0;
    brt->maxbackrefs = size_hint;
    brt->bkref = ((struct rxe * *)kmalloc(sizeof(struct rxe *)*(size_hint),"bkreftbl.c",27));
    return brt;
}

canonical_original_code:
struct rxe_backref_table *rxe_backref_table_new(int size_hint)
{
    struct rxe_backref_table *brt;
    brt = ((struct rxe_backref_table *)kmalloc(sizeof(struct rxe_backref_table)*(1),"bkreftbl.c",24));
    brt->nbackrefs = 0;
    brt->maxbackrefs = size_hint;
    brt->bkref = ((struct rxe **)kmalloc(sizeof(struct rxe *)*(size_hint),"bkreftbl.c",27));
    return brt;
}

variable_types: struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe *rxe; struct rxe_node *prev; struct rxe_node *next; } *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table *brt; int flags; } **bkref; } *