unset

decompiled_code:
__int64 __fastcall unset(__int64 a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xBEu, "unset");
if ( !a2 )
_assert_fail("key != NULL", "HashTable.c", 0xBFu, "unset");
v2 = hash(a2);
result = unsetInBucket(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v2 % *(_DWORD *)(a1 + 4))), a2);
if ( !(_DWORD)result )
--*(_DWORD *)a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xBEu, "unset");
if ( !a2 )
_assert_fail("key != NULL", "HashTable.c", 0xBFu, "unset");
v2 = func1(a2);
result = func5(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v2 % *(_DWORD *)(a1 + 4))), a2);
if ( !(_DWORD)result )
--*(_DWORD *)a1;
return result;
}

original_code:
int unset(HashTable* h, const char* key) {
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 191, __extension__ __PRETTY_FUNCTION__); }));
 int r = unsetInBucket(h->buckets[hash(key) % h->capacity], key);
 if (r == 0) {
  h->size -= 1;
 }
 return r;
}

canonical_original_code:
int unset(struct HashTable *h, char *key) {
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 191, __extension__ __PRETTY_FUNCTION__); }));
 int r = unsetInBucket(h->buckets[hash(key) % h->capacity], key);
 if (r == 0) {
  h->size -= 1;
 }
 return r;
}

variable_types:
key
char *

variable_types: r int


set

repo: Pluies/DataStructures

decompiled_code:
__int64 __fastcall set(__int64 a1, char *a2, __int64 a3)
{
int v4; // er12
unsigned int v5; // ebp
int v6; // eax
int v7; // edx

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xA9u, "set");
if ( !a2 )
_assert_fail("key != NULL", "HashTable.c", 0xAAu, "set");
unset(a1, a2);
v4 = (int)hash(a2) % *(_DWORD *)(a1 + 4);
checkOrCreateBucket(a1, v4);
v5 = setInBucket(*(int **)(*(_QWORD *)(a1 + 8) + 8LL * v4), a2, a3);
if ( v5 )
return 1;
v6 = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = v6;
v7 = *(_DWORD *)(a1 + 4);
if ( (double)v6 >= (double)v7 * 0.75 )
resize(a1, 2 * v7 + 1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, char *a2, __int64 a3)
{
int v4; // er12
unsigned int v5; // ebp
int v6; // eax
int v7; // edx

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xA9u, "set");
if ( !a2 )
_assert_fail("key != NULL", "HashTable.c", 0xAAu, "set");
func11(a1, a2);
v4 = (int)func1(a2) % *(_DWORD *)(a1 + 4);
func8(a1, v4);
v5 = func4(*(int **)(*(_QWORD *)(a1 + 8) + 8LL * v4), a2, a3);
if ( v5 )
return 1;
v6 = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = v6;
v7 = *(_DWORD *)(a1 + 4);
if ( (double)v6 >= (double)v7 * 0.75 )
func9(a1, 2 * v7 + 1);
return v5;
}

original_code:
int set(HashTable* h, const char* key, void* value){
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 170, __extension__ __PRETTY_FUNCTION__); }));
 unset(h, key);
 int b = hash(key) % h->capacity;
 checkOrCreateBucket(h, b);
 if (setInBucket(h->buckets[b], key, value) == 0) {
  h->size += 1;
  if (h->size >= (0.75 * h->capacity))
   resize(h, (2*h->capacity)+1);
  return 0;
 } else {
  return 1;
 }
}

canonical_original_code:
int set(struct HashTable *h, char *key, void *value){
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 170, __extension__ __PRETTY_FUNCTION__); }));
 unset(h, key);
 int b = hash(key) % h->capacity;
 checkOrCreateBucket(h, b);
 if (setInBucket(h->buckets[b], key, value) == 0) {
  h->size += 1;
  if (h->size >= (0.75 * h->capacity))
   resize(h, (2*h->capacity)+1);
  return 0;
 } else {
  return 1;
 }
}

variable_types: struct HashTable { int size; int capacity; struct bucket { int size; int capacity; struct record { char *key; void *value; } **records; } **buckets; } *

variable_types:
value
void *

variable_types: b int

return_type: int

user_defined_types: struct HashTable { int size; int capacity; struct bucket **buckets; }

user_defined_types: struct bucket { int size; int capacity; struct record **records; }


lookup

decompiled_code:
const char *__fastcall lookup(__int64 a1, const char *a2)
{
const char *result; // rax
const char ***v3; // rbx
__int64 v4; // r13
const char **v5; // rbp

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xC8u, "lookup");
result = *(const char **)(*(_QWORD *)(a1 + 8) + 8LL * ((int)hash(a2) % *(_DWORD *)(a1 + 4)));
if ( result )
{
if ( *(int *)result <= 0 )
{
result = 0LL;
}
else
{
v3 = (const char ***)*((_QWORD *)result + 1);
v4 = (__int64)&v3[(unsigned int)(*(_DWORD *)result - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(a2, **v3) )
break;
if ( ++v3 == (const char ***)v4 )
return 0LL;
}
result = v5[1];
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(__int64 a1, const char *a2)
{
const char *result; // rax
const char ***v3; // rbx
__int64 v4; // r13
const char **v5; // rbp

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xC8u, "lookup");
result = *(const char **)(*(_QWORD *)(a1 + 8) + 8LL * ((int)func1(a2) % *(_DWORD *)(a1 + 4)));
if ( result )
{
if ( *(int *)result <= 0 )
{
result = 0LL;
}
else
{
v3 = (const char ***)*((_QWORD *)result + 1);
v4 = (__int64)&v3[(unsigned int)(*(_DWORD *)result - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(a2, **v3) )
break;
if ( ++v3 == (const char ***)v4 )
return 0LL;
}
result = v5[1];
}
}
return result;
}

original_code:
void* lookup(HashTable* h, const char* key){
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 200, __extension__ __PRETTY_FUNCTION__); }));
 int bi = hash(key) % h->capacity;
 bucket* b = h->buckets[bi];
 if (b == ((void *)0)) return ((void *)0);
 int i = 0;
 for (i=0; i < b->size; i++) {
  record* r = b->records[i];
  if (strcmp(key,r->key) == 0)
   return r->value;
 }
 return ((void *)0);
}

canonical_original_code:
void *lookup(struct HashTable *h, char *key){
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 200, __extension__ __PRETTY_FUNCTION__); }));
 int bi = hash(key) % h->capacity;
 struct bucket *b = h->buckets[bi];
 if (b == ((void *)0)) return ((void *)0);
 int i = 0;
 for (i=0; i < b->size; i++) {
  struct record *r = b->records[i];
  if (strcmp(key,r->key) == 0)
   return r->value;
 }
 return ((void *)0);
}

variable_types: bi int

variable_types: struct bucket { int size; int capacity; struct record { char *key; void *value; } **records; } *

variable_types: i int

return_type: void *


displayRecord

decompiled_code:
int __fastcall displayRecord(__int64 a1)
{
int result; // eax

if ( a1 )
result = printf("(k: %s, v: %p)", *(const char **)a1, *(const void **)(a1 + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
int result; // eax

if ( a1 )
result = printf("(k: %s, v: %p)", *(const char **)a1, *(const void **)(a1 + 8));
return result;
}

original_code:
void displayRecord(record* r){
 if (r == ((void *)0)) return;
 printf("(k: %s, v: %p)", r->key, r->value);
}

canonical_original_code:
void displayRecord(struct record *r){
 if (r == ((void *)0)) return;
 printf("(k: %s, v: %p)", r->key, r->value);
}

variable_types: struct record { char *key; void *value; } *

return_type: void


displayBucket

decompiled_code:
int __fastcall displayBucket(_DWORD *a1, __int64 a2)
{
__int64 v2; // rsi
__int64 v4; // rbp

printf("Bucket %d at %p, ", a2, a1);
if ( a1 )
{
printf("capacity %d, ", (unsigned int)a1[1]);
v2 = (unsigned int)*a1;
if ( (_DWORD)v2 )
{
printf("size %d: ", v2);
if ( (int)*a1 > 0 )
{
v4 = 0LL;
do
displayRecord(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v4++));
while ( *a1 > (int)v4 );
}
}
else
{
printf("empty.");
}
}
else
{
printf("not initialised.");
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func15(_DWORD *a1, __int64 a2)
{
__int64 v2; // rsi
__int64 v4; // rbp

printf("Bucket %d at %p, ", a2, a1);
if ( a1 )
{
printf("capacity %d, ", (unsigned int)a1[1]);
v2 = (unsigned int)*a1;
if ( (_DWORD)v2 )
{
printf("size %d: ", v2);
if ( (int)*a1 > 0 )
{
v4 = 0LL;
do
func14(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v4++));
while ( *a1 > (int)v4 );
}
}
else
{
printf("empty.");
}
}
else
{
printf("not initialised.");
}
return putchar(10);
}

original_code:
void displayBucket(bucket* b, int in){
 int i = 0;
 printf("Bucket %d at %p, ", in, b);
 if (b == ((void *)0)) {
  printf("not initialised.");
 } else {
  printf("capacity %d, ", b->capacity);
  if (b->size == 0) {
   printf("empty.");
  } else {
   printf("size %d: ", b->size);
   for (i=0; i<b->size; i++)
    displayRecord(b->records[i]);
  }
 }
 printf("\n");
}

canonical_original_code:
void displayBucket(struct bucket *b, int in){
 int i = 0;
 printf("Bucket %d at %p, ", in, b);
 if (b == ((void *)0)) {
  printf("not initialised.");
 } else {
  printf("capacity %d, ", b->capacity);
  if (b->size == 0) {
   printf("empty.");
  } else {
   printf("size %d: ", b->size);
   for (i=0; i<b->size; i++)
    displayRecord(b->records[i]);
  }
 }
 printf("\n");
}

variable_types: in int

user_defined_types: struct record { char *key; void *value; }


isEmpty

decompiled_code:
_BOOL8 __fastcall isEmpty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int isEmpty(HashTable* h){
 return h->size == 0;
}

canonical_original_code:
int isEmpty(struct HashTable *h){
 return h->size == 0;
}


create

decompiled_code:
_DWORD *create()
{
_DWORD *v0; // rbx
_QWORD *v1; // rax

v0 = malloc(0x10uLL);
*v0 = 0;
v0[1] = 1;
v1 = malloc(8uLL);
*((_QWORD *)v0 + 1) = v1;
fillWithNulls(v1, 1);
return v0;
}

canonical_decompiled_code:
_DWORD *func10()
{
_DWORD *v0; // rbx
_QWORD *v1; // rax

v0 = malloc(0x10uLL);
*v0 = 0;
v0[1] = 1;
v1 = malloc(8uLL);
*((_QWORD *)v0 + 1) = v1;
func2(v1, 1);
return v0;
}

original_code:
HashTable* create(){
 HashTable* h = malloc(sizeof(HashTable));
 h->size = 0;
 h->capacity = 1;
 h->buckets = malloc(1 * sizeof(bucket*));
 fillWithNulls((void**)h->buckets, h->capacity);
 return h;
}

canonical_original_code:
struct HashTable *create(){
 struct HashTable *h = malloc(sizeof(HashTable));
 h->size = 0;
 h->capacity = 1;
 h->buckets = malloc(1 * sizeof(struct bucket *));
 fillWithNulls((void **)h->buckets, h->capacity);
 return h;
}

return_type: struct HashTable { int size; int capacity; struct bucket { int size; int capacity; struct record { char *key; void *value; } **records; } **buckets; } *


display

decompiled_code:
int __fastcall display(unsigned int *a1)
{
__int64 v2; // rbx

if ( isEmpty(a1) )
return puts("HashTable is empty.");
printf("HashTable has %d element(s).\n", *a1);
if ( (int)a1[1] > 0 )
{
v2 = 0LL;
do
{
displayBucket(*(_DWORD **)(*((_QWORD *)a1 + 1) + 8 * v2), (unsigned int)v2);
++v2;
}
while ( (int)a1[1] > (int)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1)
{
__int64 v2; // rbx

if ( func0(a1) )
return puts("HashTable is empty.");
printf("HashTable has %d element(s).\n", *a1);
if ( (int)a1[1] > 0 )
{
v2 = 0LL;
do
{
func15(*(_DWORD **)(*((_QWORD *)a1 + 1) + 8 * v2), (unsigned int)v2);
++v2;
}
while ( (int)a1[1] > (int)v2 );
}
return putchar(10);
}

original_code:
void display(HashTable* h){
 int i = 0;
 if (isEmpty(h)) {
  printf("HashTable is empty.\n");
 } else {
  printf("HashTable has %d element(s).\n", h->size);
  for (i=0; i<h->capacity; i++)
   displayBucket(h->buckets[i], i);
  printf("\n");
 }
}

canonical_original_code:
void display(struct HashTable *h){
 int i = 0;
 if (isEmpty(h)) {
  printf("HashTable is empty.\n");
 } else {
  printf("HashTable has %d element(s).\n", h->size);
  for (i=0; i<h->capacity; i++)
   displayBucket(h->buckets[i], i);
  printf("\n");
 }
}


cleanup

decompiled_code:
__int64 __fastcall cleanup(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 1) > 0 )
{
v1 = 0LL;
do
freeBucket(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *((_DWORD *)ptr + 1) > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 1) > 0 )
{
v1 = 0LL;
do
func7(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *((_DWORD *)ptr + 1) > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int cleanup(HashTable* h){
 int i = 0;
 for (i=0; i<h->capacity; i++) {
  freeBucket(h->buckets[i]);
 }
 free(h->buckets);
 free(h);
 return 0;
}

canonical_original_code:
int cleanup(struct HashTable *h){
 int i = 0;
 for (i=0; i<h->capacity; i++) {
  freeBucket(h->buckets[i]);
 }
 free(h->buckets);
 free(h);
 return 0;
}


max

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code: int max(int a, int b){ return (a>b) ? a : b; }

variable_types: a int


maxDepth

decompiled_code:
__int64 __fastcall maxDepth(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebp
unsigned int v3; // eax

result = 0LL;
if ( a1 )
{
v2 = maxDepth(*(_QWORD *)(a1 + 24));
v3 = maxDepth(*(_QWORD *)(a1 + 16));
result = (unsigned int)max(v3, v2) + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebp
unsigned int v3; // eax

result = 0LL;
if ( a1 )
{
v2 = func2(*(_QWORD *)(a1 + 24));
v3 = func2(*(_QWORD *)(a1 + 16));
result = (unsigned int)func1(v3, v2) + 1;
}
return result;
}

original_code:
int maxDepth(node* n) {
 if (n == ((void *)0)) return 0;
 return max(maxDepth(n->rhc), maxDepth(n->lhc)) + 1;
}

canonical_original_code:
int maxDepth(struct node *n) {
 if (n == ((void *)0)) return 0;
 return max(maxDepth(n->rhc), maxDepth(n->lhc)) + 1;
}

variable_types: struct node { void *value; struct node *parent; struct node *rhc; struct node *lhc; } *


min

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code: int min(int a, int b){ return (a<b) ? a : b; }


minDepth

decompiled_code:
__int64 __fastcall minDepth(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebp
unsigned int v3; // eax

result = 0LL;
if ( a1 )
{
v2 = minDepth(*(_QWORD *)(a1 + 24));
v3 = minDepth(*(_QWORD *)(a1 + 16));
result = (unsigned int)min(v3, v2) + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebp
unsigned int v3; // eax

result = 0LL;
if ( a1 )
{
v2 = func5(*(_QWORD *)(a1 + 24));
v3 = func5(*(_QWORD *)(a1 + 16));
result = (unsigned int)func4(v3, v2) + 1;
}
return result;
}

original_code:
int minDepth(node* n) {
 if (n == ((void *)0)) return 0;
 return min(minDepth(n->rhc), minDepth(n->lhc)) + 1;
}

canonical_original_code:
int minDepth(struct node *n) {
 if (n == ((void *)0)) return 0;
 return min(minDepth(n->rhc), minDepth(n->lhc)) + 1;
}

user_defined_types: struct node { void *value; struct node *parent; struct node *rhc; struct node *lhc; }


cleanupNodes

decompiled_code:
__int64 __fastcall cleanupNodes(void *ptr)
{
if ( ptr )
{
cleanupNodes(*((void **)ptr + 2));
cleanupNodes(*((void **)ptr + 3));
free(ptr);
}
return 0LL;
}

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

original_code:
int cleanupNodes(node* n){
 if (n != ((void *)0)){
  cleanupNodes(n->rhc);
  cleanupNodes(n->lhc);
  free(n);
 }
 return 0;
}

canonical_original_code:
int cleanupNodes(struct node *n){
 if (n != ((void *)0)){
  cleanupNodes(n->rhc);
  cleanupNodes(n->lhc);
  free(n);
 }
 return 0;
}


newRecord

decompiled_code:
__int64 __fastcall newRecord(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
return a1;
}

original_code:
CatalogueRecord newRecord(int nCopies, int val)
{
 CatalogueRecord record;
 record.addr = nCopies;
 record.val = 0;
 return record;
}

canonical_original_code:
struct tagCatalogueRecord newRecord(int nCopies, int val)
{
 struct tagCatalogueRecord record;
 record.addr = nCopies;
 record.val = 0;
 return record;
}

variable_types: nCopies int

variable_types: val int

variable_types: struct tagCatalogueRecord { unsigned int addr; unsigned short val; }


printRecord

decompiled_code:
__int64 printRecord()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
return 0LL;
}

original_code:
int printRecord(CatalogueRecord record)
{
 return 0;
}

canonical_original_code:
int printRecord(struct tagCatalogueRecord record)
{
 return 0;
}

user_defined_types: struct tagCatalogueRecord { unsigned int addr; unsigned short val; }


repo: PonderingGrower/netdev

decompiled_code:
void parent_sig_chld()
{
__pid_t v0; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("sig_chld: received signal");
while ( 1 )
{
v0 = waitpid(-1, stat_loc, 1);
if ( v0 <= 0 )
break;
printf("ALERT: child %d terminated\n", (unsigned int)v0);
}
}

canonical_decompiled_code:
void func0()
{
__pid_t v0; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("sig_chld: received signal");
while ( 1 )
{
v0 = waitpid(-1, stat_loc, 1);
if ( v0 <= 0 )
break;
printf("ALERT: child %d terminated\n", (unsigned int)v0);
}
}

original_code:
void parent_sig_chld(int signo) {
    pid_t pid;
    int stat;
    printf("sig_chld: received signal\n");
    while ( (pid = waitpid(-1, &stat, 1)) > 0 ) {
        printf("ALERT: child %d terminated\n", pid);
    }
    return;
}

canonical_original_code:
void parent_sig_chld(int signo) {
    int pid;
    int stat;
    printf("sig_chld: received signal\n");
    while ( (pid = waitpid(-1, &stat, 1)) > 0 ) {
        printf("ALERT: child %d terminated\n", pid);
    }
    return;
}

variable_types: signo int

variable_types: pid int

variable_types: stat int


decompiled_code:
__int64 __fastcall netdev_listener(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int v4; // ebx
unsigned __int16 v5; // ax
char v6[16]; // [rsp+0h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr cp; // [rsp+20h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("netdev_listener: failed to create socket");
}
else
{
v2 = v1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(a1);
if ( bind(v2, &addr, 0x10u) < 0 )
{
perror("netdev_listener: failed to bind to address");
}
else
{
if ( listen(v2, 1024) >= 0 )
{
addr_len[0] = 16;
printf("netdev_listener: starting listener at port: %d\n", a1);
while ( 1 )
{
while ( 1 )
{
v4 = accept(v2, &cp, addr_len);
if ( v4 < 0 )
break;
LABEL_14:
if ( inet_ntop(cp.sa_family, &cp.sa_data[2], v6, 0x10u) )
{
v5 = _bswap_16(*(__int16 *)cp.sa_data);
printf("netdev_listener: new connection from %s:%d\n", v6, v5);
}
if ( !fork() )
{
close(v2);
proxy_server((unsigned int)v4);
exit(0);
}
close(v4);
}
if ( *_errno_location() != 4 )
{
perror("netdev_listener: accept error");
goto LABEL_14;
}
}
}
perror("netdev_listener: failed to listen");
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int v4; // ebx
unsigned __int16 v5; // ax
char v6[16]; // [rsp+0h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr cp; // [rsp+20h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("netdev_listener: failed to create socket");
}
else
{
v2 = v1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func1(0);
*(_WORD *)addr.sa_data = func2(a1);
if ( bind(v2, &addr, 0x10u) < 0 )
{
perror("netdev_listener: failed to bind to address");
}
else
{
if ( listen(v2, 1024) >= 0 )
{
addr_len[0] = 16;
printf("netdev_listener: starting listener at port: %d\n", a1);
while ( 1 )
{
while ( 1 )
{
v4 = accept(v2, &cp, addr_len);
if ( v4 < 0 )
break;
LABEL_14:
if ( inet_ntop(cp.sa_family, &cp.sa_data[2], v6, 0x10u) )
{
v5 = func2(*(__int16 *)cp.sa_data);
printf("netdev_listener: new connection from %s:%d\n", v6, v5);
}
if ( !fork() )
{
close(v2);
proxy_server((unsigned int)v4);
exit(0);
}
close(v4);
}
if ( *_errno_location() != 4 )
{
perror("netdev_listener: accept error");
goto LABEL_14;
}
}
}
perror("netdev_listener: failed to listen");
}
}
return 0xFFFFFFFFLL;
}

original_code:
int netdev_listener(
    int port)
{
    int listenfd, connfd;
    int rvalue;
    pid_t childpid;
    socklen_t clilen;
    struct sockaddr_in cliaddr, servaddr;
    char str[16];
    void *ptr;
    listenfd = socket(2, SOCK_STREAM, 0);
    if ( listenfd < 0 ) {
        perror("netdev_listener: failed to create socket");
        return -1;
    }
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    servaddr.sin_port = htons(port);
    rvalue = bind(listenfd,
                (struct sockaddr*)&servaddr,
                sizeof(servaddr));
    if ( rvalue < 0 ) {
        perror("netdev_listener: failed to bind to address");
        return -1;
    }
    rvalue = listen(listenfd, 1024);
    if ( rvalue < 0 ) {
        perror("netdev_listener: failed to listen");
        return -1;
    }
    clilen = sizeof(cliaddr);
    printf("netdev_listener: starting listener at port: %d\n", port);
    while (1) {
        connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen);
        if (connfd < 0) {
            if ((*__errno_location ()) == 4) {
                continue;
            } else {
                perror("netdev_listener: accept error");
            }
        }
        ptr = (char *)inet_ntop(cliaddr.sin_family ,
                                &cliaddr.sin_addr,
                                str,
                                sizeof(str));
        if ( ptr != ((void *)0) ) {
            printf("netdev_listener: new connection from %s:%d\n",
                    str,
                    ntohs(cliaddr.sin_port));
        }
        if ( (childpid = fork()) ==0 ) {
            close(listenfd);
            proxy_server(connfd);
            exit(0);
        }
        close(connfd);
    }
    return 0;
}

canonical_original_code:
int netdev_listener(int port)
{
    int listenfd; int connfd;
    int rvalue;
    int childpid;
    unsigned int clilen;
    struct sockaddr_in cliaddr; struct sockaddr_in servaddr;
    char str[16];
    void *ptr;
    listenfd = socket(2, SOCK_STREAM, 0);
    if ( listenfd < 0 ) {
        perror("netdev_listener: failed to create socket");
        return -1;
    }
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    servaddr.sin_port = htons(port);
    rvalue = bind(listenfd,
                (struct sockaddr *)&servaddr,
                sizeof(servaddr));
    if ( rvalue < 0 ) {
        perror("netdev_listener: failed to bind to address");
        return -1;
    }
    rvalue = listen(listenfd, 1024);
    if ( rvalue < 0 ) {
        perror("netdev_listener: failed to listen");
        return -1;
    }
    clilen = sizeof(cliaddr);
    printf("netdev_listener: starting listener at port: %d\n", port);
    while (1) {
        connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen);
        if (connfd < 0) {
            if ((*__errno_location ()) == 4) {
                continue;
            } else {
                perror("netdev_listener: accept error");
            }
        }
        ptr = (char *)inet_ntop(cliaddr.sin_family ,
                                &cliaddr.sin_addr,
                                str,
                                sizeof(str));
        if ( ptr != ((void *)0) ) {
            printf("netdev_listener: new connection from %s:%d\n",
                    str,
                    ntohs(cliaddr.sin_port));
        }
        if ( (childpid = fork()) ==0 ) {
            close(listenfd);
            proxy_server(connfd);
            exit(0);
        }
        close(connfd);
    }
    return 0;
}

variable_types: port int

variable_types: listenfd int

variable_types: connfd int

variable_types: rvalue int

variable_types: childpid int

variable_types:
clilen
unsigned int

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

variable_types:
str
char [16]

variable_types:
ptr
void *

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

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


decompiled_code:
void proxy_sig_hup()
{
unsigned int v0; // eax

v0 = getpid();
printf("sig_hup: received signal in process: %d\n", v0);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // eax

v0 = getpid();
printf("sig_hup: received signal in process: %d\n", v0);
}

original_code:
void proxy_sig_hup(int signo)
{
    printf("sig_hup: received signal in process: %d\n", getpid());
    return;
}


decompiled_code:
__sighandler_t proxy_setup_signals()
{
prctl(1, 1LL);
signal(1, (__sighandler_t)proxy_sig_hup);
return signal(2, (__sighandler_t)((char *)proxy_sig_hup + 1));
}

canonical_decompiled_code:
__sighandler_t func1()
{
prctl(1, 1LL);
signal(1, (__sighandler_t)proxy_sig_hup);
return signal(2, (__sighandler_t)((char *)proxy_sig_hup + 1));
}

original_code:
void proxy_setup_signals()
{
    prctl(1, 1);
    signal(1, proxy_sig_hup);
    signal(2, ((__sighandler_t) 1));
}

canonical_original_code:
void proxy_setup_signals()
{
    prctl(1, 1);
    signal(1, proxy_sig_hup);
    signal(2, ((void (*)(int)) 1));
}


recvall

decompiled_code:
__int64 __fastcall recvall(int fd, struct msghdr *message, int a3)
{
unsigned int v4; // ebp
int v5; // eax

v4 = 0;
while ( 1 )
{
v5 = recvmsg(fd, message, message->msg_flags);
if ( v5 == -1 )
{
perror("recvall(recvmsg)");
return (unsigned int)-1;
}
if ( !v5 )
break;
v4 += v5;
message->msg_iov->iov_base = (char *)message->msg_iov->iov_base + v5;
message->msg_iov->iov_len = (int)v4;
if ( (int)v4 >= a3 )
return v4;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, struct msghdr *message, int a3)
{
unsigned int v4; // ebp
int v5; // eax

v4 = 0;
while ( 1 )
{
v5 = recvmsg(fd, message, message->msg_flags);
if ( v5 == -1 )
{
perror("recvall(recvmsg)");
return (unsigned int)-1;
}
if ( !v5 )
break;
v4 += v5;
message->msg_iov->iov_base = (char *)message->msg_iov->iov_base + v5;
message->msg_iov->iov_len = (int)v4;
if ( (int)v4 >= a3 )
return v4;
}
return (unsigned int)-1;
}

original_code:
int recvall(int conn_fd, struct msghdr *msgh, int size) {
    int rvalue = 0, bytes = 0;
    do {
        rvalue = recvmsg(conn_fd, msgh, msgh->msg_flags);
        if (rvalue == -1) {
            perror("recvall(recvmsg)");
            return -1;
        } else if (rvalue == 0 ) {
            return -1;
        }
        bytes += rvalue;
        msgh->msg_iov->iov_base += rvalue;
        msgh->msg_iov->iov_len = bytes;
    } while (bytes < size);
    return bytes;
}

canonical_original_code:
int recvall(int conn_fd, struct msghdr *msgh, int size) {
    int rvalue = 0; int bytes = 0;
    do {
        rvalue = recvmsg(conn_fd, msgh, msgh->msg_flags);
        if (rvalue == -1) {
            perror("recvall(recvmsg)");
            return -1;
        } else if (rvalue == 0 ) {
            return -1;
        }
        bytes += rvalue;
        msgh->msg_iov->iov_base += rvalue;
        msgh->msg_iov->iov_len = bytes;
    } while (bytes < size);
    return bytes;
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

variable_types: size int

variable_types: bytes int

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


sendall

decompiled_code:
__int64 __fastcall sendall(int fd, struct msghdr *message, int a3)
{
int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er14

v4 = 0;
while ( 1 )
{
v5 = sendmsg(fd, message, message->msg_flags);
v6 = v5;
if ( v5 == -1 )
{
perror("sendmsg(sendmsg)");
return v6;
}
if ( !v5 )
break;
v4 += v5;
message->msg_iov->iov_base = (char *)message->msg_iov->iov_base + (int)v5;
message->msg_iov->iov_len = v4;
if ( v4 >= a3 )
return 0;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, struct msghdr *message, int a3)
{
int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er14

v4 = 0;
while ( 1 )
{
v5 = sendmsg(fd, message, message->msg_flags);
v6 = v5;
if ( v5 == -1 )
{
perror("sendmsg(sendmsg)");
return v6;
}
if ( !v5 )
break;
v4 += v5;
message->msg_iov->iov_base = (char *)message->msg_iov->iov_base + (int)v5;
message->msg_iov->iov_len = v4;
if ( v4 >= a3 )
return 0;
}
return (unsigned int)-1;
}

original_code:
int sendall(int conn_fd, struct msghdr *msgh, int size) {
    int rvalue = 0, bytes = 0;
    do {
        rvalue = sendmsg(conn_fd, msgh, msgh->msg_flags);
        if (rvalue == -1) {
            perror("sendmsg(sendmsg)");
            return -1;
        } else if (rvalue == 0 ) {
            return -1;
        }
        bytes += rvalue;
        msgh->msg_iov->iov_base += rvalue;
        msgh->msg_iov->iov_len = bytes;
    } while (bytes < size);
    return 0;
}

canonical_original_code:
int sendall(int conn_fd, struct msghdr *msgh, int size) {
    int rvalue = 0; int bytes = 0;
    do {
        rvalue = sendmsg(conn_fd, msgh, msgh->msg_flags);
        if (rvalue == -1) {
            perror("sendmsg(sendmsg)");
            return -1;
        } else if (rvalue == 0 ) {
            return -1;
        }
        bytes += rvalue;
        msgh->msg_iov->iov_base += rvalue;
        msgh->msg_iov->iov_len = bytes;
    } while (bytes < size);
    return 0;
}

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


signal

decompiled_code:
__int64 __fastcall signal(int sig, void (*a2)(int))
{
bool v2; // sf
__int64 result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v5.sa_flags = (sig == 14) << 28;
v2 = sigaction(sig, &v5, &v4) < 0;
result = -1LL;
if ( !v2 )
result = (__int64)v4.sa_handler;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int sig, void (*a2)(int))
{
bool v2; // sf
__int64 result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v5.sa_flags = (sig == 14) << 28;
v2 = sigaction(sig, &v5, &v4) < 0;
result = -1LL;
if ( !v2 )
result = (__int64)v4.sa_handler;
return result;
}

original_code:
Sigfunc * signal(int signo, Sigfunc *func) {
    struct sigaction act, oact;
    act.__sigaction_handler.sa_handler = func;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    if (signo == 14) {
        act.sa_flags |= 0x10000000;
    }
    if (sigaction(signo, &act, &oact) < 0)
        return ((__sighandler_t) -1);
    return oact.__sigaction_handler.sa_handler;
}

canonical_original_code:
void (*signal(int signo, void (*func)(int)))(int) {
    struct sigaction act; struct sigaction oact;
    act.__sigaction_handler.sa_handler = func;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    if (signo == 14) {
        act.sa_flags |= 0x10000000;
    }
    if (sigaction(signo, &act, &oact) < 0)
        return ((__sighandler_t) -1);
    return oact.__sigaction_handler.sa_handler;
}

variable_types:
func
void (*)(int)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

return_type: void (*)(int)

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


repo: Potent-Code/testytest

decompiled_code:
__int64 basic_test()
{
puts("This is my test!");
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
puts("This is my test!");
return 0LL;
}

canonical_original_code:
enum test_result basic_test()
{
 printf("This is my test!\n");
 return TEST_PASS;
}

return_type: enum test_result { TEST_PASS=0, TEST_FAIL=1 }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rsi
char **v4; // rbx
unsigned int v5; // er12
unsigned int v6; // er13
unsigned int v7; // ebp
int v8; // eax

v3 = Tests;
if ( Tests )
{
v4 = &Tests;
v5 = 0;
v6 = 0;
v7 = 0;
do
{
++v7;
printf("Running test %s\n", v3);
v8 = ((__int64 (*)(void))v4[2])();
if ( v8 )
v5 += v8 == 1;
else
++v6;
v4 += 3;
v3 = *v4;
}
while ( *v4 );
}
else
{
v5 = 0;
v6 = 0;
v7 = 0;
}
printf("Ran %d tests, %d passed and %d failed\n", v7, v6, v5);
return 0;
}

original_code:
int main()
{
 test_result cur_result;
 int test_count = 0;
 int tests_passed = 0;
 int tests_failed = 0;
 test_case *i;
 test_result (*test_function)(void);
 for(i = Tests; i->name; i++)
 {
  test_count++;
  printf("Running test %s\n", i->name);
  test_function = i->function;
  cur_result = test_function();
  switch(cur_result)
  {
   case TEST_PASS:
    tests_passed++;
    break;
   case TEST_FAIL:
    tests_failed++;
    break;
  }
 }
 printf("Ran %d tests, %d passed and %d failed\n", test_count, tests_passed, tests_failed);
 return 0;
}

canonical_original_code:
int main()
{
 enum test_result cur_result;
 int test_count = 0;
 int tests_passed = 0;
 int tests_failed = 0;
 struct test_case *i;
 test_result (*test_function)(void);
 for(i = Tests; i->name; i++)
 {
  test_count++;
  printf("Running test %s\n", i->name);
  test_function = i->function;
  cur_result = test_function();
  switch(cur_result)
  {
   case TEST_PASS:
    tests_passed++;
    break;
   case TEST_FAIL:
    tests_failed++;
    break;
  }
 }
 printf("Ran %d tests, %d passed and %d failed\n", test_count, tests_passed, tests_failed);
 return 0;
}

variable_types: enum test_result { TEST_PASS=0, TEST_FAIL=1 }

variable_types: struct test_case { char *name; char *description; void *function; } *


decompiled_code:
__int64 function1()
{
return 10LL;
}

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

original_code:
int function1(){
   return 10;
}

canonical_original_code:
int function1(){
   return 10;
}


decompiled_code:
__int64 function2()
{
__int64 v0; // rbx

v0 = (unsigned int)function1();
printf("%d \n", v0);
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx

v0 = (unsigned int)func7();
printf("%d \n", v0);
return (unsigned int)v0;
}

original_code:
int function2(){
   int x;
   x = function1();
   printf("%d \n",x);
   return function1();
}

variable_types: x int


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

v3 = function2(argc, argv, envp);
printf("%d \n", v3);
return 0;
}

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

v3 = func8(argc, argv, envp);
printf("%d \n", v3);
return 0;
}

original_code:
int main(){
int x;
x = function2();
printf("%d \n",x);
return 0;
}


repo: PradheepShrinivasan/MyExploration

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rax
const char *v5; // rax
unsigned int v6; // eax
char v8[20]; // [rsp+4h] [rbp-14h] BYREF

v3 = (const char *)mystrcpy("helloworld", v8, envp);
printf("strcpy of helloworld %s \n", v3);
v4 = (const char *)mystrncpy("helloworld", v8, 1LL);
printf("%s \n", v4);
v5 = (const char *)mystrncpy("helloworld", v8, 0LL);
printf("%s \n", v5);
v6 = mystrlen("helloworld");
printf("length of helloworld = %d", v6);
return 0;
}

original_code:
int main()
{
 char *current = "helloworld";
 char destination [12];
 printf ("strcpy of helloworld %s \n", mystrcpy (current, destination));
 printf ("%s \n", mystrncpy (current, destination, 1));
 printf ("%s \n", mystrncpy (current, destination, 0));
 printf ("length of helloworld = %d", mystrlen ("helloworld"));
 return 0;
}

canonical_original_code:
int main()
{
 char *current = "helloworld";
 char destination[12];
 printf ("strcpy of helloworld %s \n", mystrcpy (current, destination));
 printf ("%s \n", mystrncpy (current, destination, 1));
 printf ("%s \n", mystrncpy (current, destination, 0));
 printf ("length of helloworld = %d", mystrlen ("helloworld"));
 return 0;
}

variable_types:
current
char *

variable_types:
destination
char [12]


mystrlen

decompiled_code:
__int64 __fastcall mystrlen(_BYTE *a1)
{
_BYTE *v1; // rax
unsigned int v2; // ecx

if ( !*a1 )
return 0;
v1 = a1;
do
v2 = 1 - (_DWORD)a1 + (_DWORD)v1++;
while ( *v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
_BYTE *v1; // rax
unsigned int v2; // ecx

if ( !*a1 )
return 0;
v1 = a1;
do
v2 = 1 - (_DWORD)a1 + (_DWORD)v1++;
while ( *v1 );
return v2;
}

original_code:
int mystrlen (const char* src)
{
 int length = 0;
 while (*src)
 {
  ++length;
  ++src;
 }
 return length;
}

canonical_original_code:
int mystrlen(char *src)
{
 int length = 0;
 while (*src)
 {
  ++length;
  ++src;
 }
 return length;
}

variable_types:
src
char *

variable_types: length int


repo: PredragWang/RPC-Examples

decompiled_code:
bool_t __fastcall xdr_dir(XDR *a1, char *a2)
{
char *cpp; // [rsp+8h] [rbp-10h] BYREF

cpp = a2;
return xdr_string(a1, &cpp, 0x2000u);
}

canonical_decompiled_code:
bool_t __fastcall func0(XDR *a1, char *a2)
{
char *cpp; // [rsp+8h] [rbp-10h] BYREF

cpp = a2;
return xdr_string(a1, &cpp, 0x2000u);
}

original_code:
bool_t xdr_dir(XDR *xdrs, char *objp){
 return (xdr_string(xdrs, &objp, 8192));
}

canonical_original_code:
int xdr_dir(struct XDR *xdrs, char *objp){
 return (xdr_string(xdrs, &objp, 8192));
}

variable_types: struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *

variable_types:
objp
char *

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }


decompiled_code:
__int64 __fastcall get_file_rpc(char *msg, char *s)
{
size_t v2; // rax
__int64 v3; // rbp
unsigned int *v4; // rax
unsigned int *v5; // rbx
unsigned int v6; // eax
_DWORD v8[256]; // [rsp+0h] [rbp-438h] BYREF
__int64 v9; // [rsp+400h] [rbp-38h]

init_fp(s);
init_clnt(msg);
memset(v8, 0, sizeof(v8));
v2 = strlen(s);
if ( v2 > 0x400 )
LODWORD(v2) = 1024;
if ( (unsigned int)v2 >= 8 )
{
*(_QWORD *)((char *)&v8[-2] + (unsigned int)v2) = *(_QWORD *)&s[(unsigned int)v2 - 8];
qmemcpy(v8, s, 8LL * ((unsigned int)(v2 - 1) >> 3));
}
else if ( (v2 & 4) != 0 )
{
v8[0] = *(_DWORD *)s;
*(_DWORD *)((char *)&v8[-1] + (unsigned int)v2) = *(_DWORD *)&s[(unsigned int)v2 - 4];
}
else if ( (_DWORD)v2 )
{
LOBYTE(v8[0]) = *s;
if ( (v2 & 2) != 0 )
*(_WORD *)((char *)v8 + (unsigned int)v2 - 2) = *(_WORD *)&s[(unsigned int)v2 - 2];
}
v3 = 0LL;
do
{
v9 = v3;
v4 = (unsigned int *)get_file_1(v8, clnt);
v5 = v4;
if ( !v4 )
{
clnt_perror(clnt, msg);
fclose(fp);
exit(1);
}
v6 = *v4;
if ( v6 )
{
__writefsdword((unsigned int)&errno, v6);
perror(s);
fclose(fp);
exit(1);
}
if ( *((_QWORD *)v5 + 513) == v3 )
{
puts("Write a chunk");
fwrite(v5 + 2, 1uLL, *((_QWORD *)v5 + 514), fp);
v3 += *((_QWORD *)v5 + 514);
}
}
while ( !v5[1030] );
fclose(fp);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *msg, char *s)
{
size_t v2; // rax
__int64 v3; // rbp
unsigned int *v4; // rax
unsigned int *v5; // rbx
unsigned int v6; // eax
_DWORD v8[256]; // [rsp+0h] [rbp-438h] BYREF
__int64 v9; // [rsp+400h] [rbp-38h]

init_fp(s);
init_clnt(msg);
memset(v8, 0, sizeof(v8));
v2 = strlen(s);
if ( v2 > 0x400 )
LODWORD(v2) = 1024;
if ( (unsigned int)v2 >= 8 )
{
*(_QWORD *)((char *)&v8[-2] + (unsigned int)v2) = *(_QWORD *)&s[(unsigned int)v2 - 8];
qmemcpy(v8, s, 8LL * ((unsigned int)(v2 - 1) >> 3));
}
else if ( (v2 & 4) != 0 )
{
v8[0] = *(_DWORD *)s;
*(_DWORD *)((char *)&v8[-1] + (unsigned int)v2) = *(_DWORD *)&s[(unsigned int)v2 - 4];
}
else if ( (_DWORD)v2 )
{
LOBYTE(v8[0]) = *s;
if ( (v2 & 2) != 0 )
*(_WORD *)((char *)v8 + (unsigned int)v2 - 2) = *(_WORD *)&s[(unsigned int)v2 - 2];
}
v3 = 0LL;
do
{
v9 = v3;
v4 = (unsigned int *)get_file_1(v8, clnt);
v5 = v4;
if ( !v4 )
{
clnt_perror(clnt, msg);
fclose(fp);
exit(1);
}
v6 = *v4;
if ( v6 )
{
__writefsdword((unsigned int)&errno, v6);
perror(s);
fclose(fp);
exit(1);
}
if ( *((_QWORD *)v5 + 513) == v3 )
{
puts("Write a chunk");
fwrite(v5 + 2, 1uLL, *((_QWORD *)v5 + 514), fp);
v3 += *((_QWORD *)v5 + 514);
}
}
while ( !v5[1030] );
fclose(fp);
return 0LL;
}

original_code:
int get_file_rpc(char *host, char *f_name) {
    init_fp(f_name);
    init_clnt(host);
    size_t offset = 0;
    size_t written = 0;
    get_file_ret *ret;
    request req;
    memset(req.f_name, 0, 1024);
    memcpy(req.f_name, f_name, (strlen(f_name) <= 1024 ? strlen(f_name): 1024));
    while (1) {
        req.offset = offset;
        ret = get_file_1(&req, clnt);
        if (ret == ((void *)0)) {
            clnt_perror(clnt, host);
            fclose(fp);
            exit(1);
        }
        if (ret->errno != 0) {
            errno = ret->errno;
            perror(f_name);
            fclose(fp);
            exit(1);
        }
        if (ret->get_file_ret_u.f_chunk.offset == offset) {
            printf("Write a chunk\n");
            written = fwrite(ret->get_file_ret_u.f_chunk.data, 1,
                        ret->get_file_ret_u.f_chunk.bytes, fp);
            if (written < 0) {
                perror("Error in writing\n");
                exit(1);
            }
            offset += ret->get_file_ret_u.f_chunk.bytes;
        }
        if (ret->get_file_ret_u.f_chunk.end) break;
    }
    fclose(fp);
    return 0;
}

canonical_original_code:
int get_file_rpc(char *host, char *f_name) {
    init_fp(f_name);
    init_clnt(host);
    unsigned long offset = 0;
    unsigned long written = 0;
    struct get_file_ret *ret;
    struct request req;
    memset(req.f_name, 0, 1024);
    memcpy(req.f_name, f_name, (strlen(f_name) <= 1024 ? strlen(f_name): 1024));
    while (1) {
        req.offset = offset;
        ret = get_file_1(&req, clnt);
        if (ret == ((void *)0)) {
            clnt_perror(clnt, host);
            fclose(fp);
            exit(1);
        }
        if (ret->errno != 0) {
            errno = ret->errno;
            perror(f_name);
            fclose(fp);
            exit(1);
        }
        if (ret->get_file_ret_u.f_chunk.offset == offset) {
            printf("Write a chunk\n");
            written = fwrite(ret->get_file_ret_u.f_chunk.data, 1,
                        ret->get_file_ret_u.f_chunk.bytes, fp);
            if (written < 0) {
                perror("Error in writing\n");
                exit(1);
            }
            offset += ret->get_file_ret_u.f_chunk.bytes;
        }
        if (ret->get_file_ret_u.f_chunk.end) break;
    }
    fclose(fp);
    return 0;
}

variable_types:
host
char *

variable_types:
offset
unsigned long

variable_types:
written
unsigned long

variable_types: struct get_file_ret { int errno; union { struct filechunk { char data[4096]; unsigned long offset; unsigned long bytes; int end; } f_chunk; } get_file_ret_u; } *

variable_types: struct request { char f_name[1024]; unsigned long offset; }

user_defined_types: struct get_file_ret { int errno; union { struct filechunk f_chunk; } get_file_ret_u; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
size_t v4; // rax

if ( argc != 3 )
{
puts("Usage: ./rpc_ft_client <host> <file>");
exit(1);
}
v3 = argv[2];
v4 = strlen(v3);
printf("%s : %lu\n", v3, v4);
get_file_rpc((char *)argv[1], (char *)argv[2]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
size_t v4; // rax

if ( argc != 3 )
{
puts("Usage: ./rpc_ft_client <host> <file>");
exit(1);
}
v3 = argv[2];
v4 = strlen(v3);
printf("%s : %lu\n", v3, v4);
func0((char *)argv[1], (char *)argv[2]);
return 0;
}

original_code:
int main(int argc, char **argv) {
    if (argc != 3) {
        printf("Usage: ./rpc_ft_client <host> <file>\n");
        exit(1);
    }
    printf("%s : %lu\n", argv[2], strlen(argv[2]));
    get_file_rpc(argv[1], argv[2]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


strrev

decompiled_code:
const char *__fastcall strrev(const char *a1)
{
char *v1; // rax
char *v2; // rdx
char v3; // cl

v1 = (char *)&a1[strlen(a1) - 1];
if ( a1 < v1 )
{
v2 = (char *)a1;
do
{
v3 = *v2;
*v2 = *v1;
*v1 = v3;
++v2;
--v1;
}
while ( v2 < v1 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
char *v1; // rax
char *v2; // rdx
char v3; // cl

v1 = (char *)&a1[strlen(a1) - 1];
if ( a1 < v1 )
{
v2 = (char *)a1;
do
{
v3 = *v2;
*v2 = *v1;
*v1 = v3;
++v2;
--v1;
}
while ( v2 < v1 );
}
return a1;
}

original_code:
char *strrev(char *str)
{
 char *ptr = str;
 char *end = str + strlen(str)-1;
 char tmp;
 while (end > str) {
  tmp = *str;
  *str = *end;
  *end = tmp;
  ++str;
  --end;
 }
 return ptr;
}

variable_types:
str
char *

variable_types:
ptr
char *

variable_types:
end
char *

variable_types: tmp char

return_type: char *


decompiled_code:
char *__fastcall get_word(const char *a1, _QWORD *a2)
{
char *v2; // rbp
const unsigned __int16 **v3; // r8
char *v4; // rcx

v2 = strdup(a1);
*a2 = 0LL;
v3 = _ctype_b_loc();
while ( 1 )
{
v4 = &v2[*a2];
if ( ((*v3)[*v4] & 8) == 0 && *v4 != 95 )
break;
++*a2;
}
*v4 = 0;
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, _QWORD *a2)
{
char *v2; // rbp
const unsigned __int16 **v3; // r8
char *v4; // rcx

v2 = strdup(a1);
*a2 = 0LL;
v3 = _ctype_b_loc();
while ( 1 )
{
v4 = &v2[*a2];
if ( ((*v3)[*v4] & 8) == 0 && *v4 != 95 )
break;
++*a2;
}
*v4 = 0;
return v2;
}

original_code:
char *get_word(const char *str, size_t *len)
{
 char *cpy = strdup(str);
 for (*len=0; ((*__ctype_b_loc ())[(int) ((cpy[*len]))] & (unsigned short int) _ISalnum) || cpy[*len] == '_'; ++*len)
  ;
 cpy[*len] = '\0';
 return cpy;
}

canonical_original_code:
char *get_word(char *str, unsigned long *len)
{
 char *cpy = strdup(str);
 for (*len=0; ((*__ctype_b_loc ())[(int) ((cpy[*len]))] & (unsigned short) _ISalnum) || cpy[*len] == '_'; ++*len)
  ;
 cpy[*len] = '\0';
 return cpy;
}

variable_types:
len
unsigned long *

variable_types:
cpy
char *


decompiled_code:
int __fastcall var_compare_by_name(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int var_compare_by_name(const void *v1, const void *v2) {
 return strcmp(((variable *)v1)->name, ((variable *)v2)->name);
}

canonical_original_code:
static int var_compare_by_name(void *v1, void *v2) {
 return strcmp(((struct variable *)v1)->name, ((struct variable *)v2)->name);
}

user_defined_types: struct variable { char *name; double val; int destroy; }


decompiled_code:
__int64 variables_init()
{
const char **v0; // rbx
__int64 result; // rax

v0 = (const char **)&default_vars;
do
{
result = _variable_save(v0);
v0 += 3;
}
while ( v0 != (const char **)&unk_278 );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
const char **v0; // rbx
__int64 result; // rax

v0 = (const char **)&default_vars;
do
{
result = func0(v0);
v0 += 3;
}
while ( v0 != (const char **)&unk_278 );
return result;
}

original_code:
void variables_init(void) {
 const variable *v = &default_vars[0];
 size_t len = sizeof(default_vars) / sizeof(default_vars[0]);
 for (; len > 0; --len, ++v)
  __variable_save(v);
}

canonical_original_code:
void variables_init() {
 struct variable *v = &default_vars[0];
 unsigned long len = sizeof(default_vars) / sizeof(default_vars[0]);
 for (; len > 0; --len, ++v)
  __variable_save(v);
}

variable_types: struct variable { char *name; double val; int destroy; } *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall variable_save(char *s, double a2)
{
double *v2; // rax
double *v3; // rbx

v2 = (double *)malloc(0x18uLL);
if ( !v2 )
return 0LL;
v3 = v2;
*(_QWORD *)v2 = strdup(s);
v3[1] = a2;
*((_DWORD *)v3 + 4) = 1;
return _variable_save((const char **)v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, double a2)
{
double *v2; // rax
double *v3; // rbx

v2 = (double *)malloc(0x18uLL);
if ( !v2 )
return 0LL;
v3 = v2;
*(_QWORD *)v2 = strdup(s);
v3[1] = a2;
*((_DWORD *)v3 + 4) = 1;
return func0((const char **)v3);
}

original_code:
int variable_save(const char *name, double val) {
 variable *v;
 if ((v = malloc(sizeof(*v))) == ((void *)0))
  return 0;
 v->name = strdup(name);
 v->val = val;
 v->destroy = 1;
 return __variable_save(v);
}

canonical_original_code:
int variable_save(char *name, double val) {
 struct variable *v;
 if ((v = malloc(sizeof(*v))) == ((void *)0))
  return 0;
 v->name = strdup(name);
 v->val = val;
 v->destroy = 1;
 return __variable_save(v);
}

variable_types:
name
char *

variable_types: val double


decompiled_code:
__int64 __fastcall variable_value(const char *a1, _QWORD *a2)
{
char *v2; // rbx
void *v3; // rbp
__int64 result; // rax
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+10h] [rbp-28h]

v2 = strdup(a1);
v5[0] = (__int64)v2;
v5[1] = 0LL;
v6 = 0;
v3 = tfind(v5, &defined_vars, var_compare_by_name);
free(v2);
result = 0LL;
if ( v3 )
{
*a2 = *(_QWORD *)(*(_QWORD *)v3 + 8LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, _QWORD *a2)
{
char *v2; // rbx
void *v3; // rbp
__int64 result; // rax
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+10h] [rbp-28h]

v2 = strdup(a1);
v5[0] = (__int64)v2;
v5[1] = 0LL;
v6 = 0;
v3 = tfind(v5, &defined_vars, var_compare_by_name);
free(v2);
result = 0LL;
if ( v3 )
{
*a2 = *(_QWORD *)(*(_QWORD *)v3 + 8LL);
result = 1LL;
}
return result;
}

original_code:
int variable_value(const char *name, double *valptr) {
 char *name2 = strdup(name);
 void *found;
 variable var = { name2, 0, 0 };
 found = tfind(&var, &defined_vars, var_compare_by_name);
 free(name2);
 if (found != ((void *)0)) {
  *valptr = (*(variable **) found)->val;
  return 1;
 }
 return 0;
}

canonical_original_code:
int variable_value(char *name, double *valptr) {
 char *name2 = strdup(name);
 void *found;
 struct variable var = { name2, 0, 0 };
 found = tfind(&var, &defined_vars, var_compare_by_name);
 free(name2);
 if (found != ((void *)0)) {
  *valptr = (*(struct variable **) found)->val;
  return 1;
 }
 return 0;
}

variable_types:
valptr
double *

variable_types:
found
void *

variable_types: struct variable { char *name; double val; int destroy; }


decompiled_code:
__int64 __fastcall variable_value_c(char a1, _QWORD *a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = a1;
v3[1] = 0;
return variable_value(v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, _QWORD *a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = a1;
v3[1] = 0;
return func4(v3, a2);
}

original_code:
int variable_value_c(char c, double *valptr) {
 char buf[2];
 buf[0] = c;
 buf[1] = '\0';
 return variable_value(buf, valptr);
}

variable_types: c char

variable_types:
buf
char [2]


decompiled_code:
const void **variables_uninit()
{
const void **result; // rax
void **v1; // rbx

for ( result = (const void **)defined_vars; defined_vars; result = (const void **)defined_vars )
{
v1 = (void **)*result;
tdelete(*result, &defined_vars, (__compar_fn_t)&compare_ptr);
if ( *((_DWORD *)v1 + 4) )
{
free(*v1);
free(v1);
}
}
return result;
}

canonical_decompiled_code:
const void **func6()
{
const void **result; // rax
void **v1; // rbx

for ( result = (const void **)defined_vars; defined_vars; result = (const void **)defined_vars )
{
v1 = (void **)*result;
tdelete(*result, &defined_vars, (__compar_fn_t)&compare_ptr);
if ( *((_DWORD *)v1 + 4) )
{
free(*v1);
free(v1);
}
}
return result;
}

original_code:
void variables_uninit(void) {
 variable *v;
 while (defined_vars != ((void *)0)) {
  v = *(variable **) defined_vars;
  tdelete(v, &defined_vars, compare_ptr);
  if (v->destroy) {
   free(v->name);
   free(v);
  }
 }
}

canonical_original_code:
void variables_uninit() {
 struct variable *v;
 while (defined_vars != ((void *)0)) {
  v = *(struct variable **) defined_vars;
  tdelete(v, &defined_vars, compare_ptr);
  if (v->destroy) {
   free(v->name);
   free(v);
  }
 }
}


decompiled_code:
int commands_init()
{
const char **v0; // rbx
const char ***v1; // rax

v0 = (const char **)&default_cmds;
do
{
v1 = (const char ***)tsearch(v0, &command_list, cmd_compare_by_name);
if ( *v1 != v0 )
LODWORD(v1) = fprintf(stderr, "%s: could not insert %s\n", "commands_init", *v0);
v0 += 5;
}
while ( v0 != (const char **)&unk_AF8 );
return (int)v1;
}

canonical_decompiled_code:
int func1()
{
const char **v0; // rbx
const char ***v1; // rax

v0 = (const char **)&default_cmds;
do
{
v1 = (const char ***)tsearch(v0, &command_list, cmd_compare_by_name);
if ( *v1 != v0 )
LODWORD(v1) = fprintf(stderr, "%s: could not insert %s\n", "commands_init", *v0);
v0 += 5;
}
while ( v0 != (const char **)&unk_AF8 );
return (int)v1;
}

original_code:
static void commands_init(void) {
 const command *c = &default_cmds[0];
 void *cval;
 size_t len = num_cmds;
 for (; len > 0; --len, ++c) {
  cval = tsearch(c, &command_list, cmd_compare_by_name);
  if ((*(command **)cval) != c)
   fprintf(stderr, "%s: could not insert %s\n",
    __func__, *(char **)c);
 }
}

canonical_original_code:
static void commands_init() {
 struct command *c = &default_cmds[0];
 void *cval;
 unsigned long len = num_cmds;
 for (; len > 0; --len, ++c) {
  cval = tsearch(c, &command_list, cmd_compare_by_name);
  if ((*(struct command **)cval) != c)
   fprintf(stderr, "%s: could not insert %s\n",
    __func__, *(char **)c);
 }
}

variable_types: struct command { char *name; unsigned long nargs; void (*exec)(struct command *, void *[]); char *syntax; char *info; } *

variable_types:
cval
void *


decompiled_code:
int __fastcall cmd_compare_by_name(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func2(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int cmd_compare_by_name(const void *c1, const void *c2) {
 return strcmp(((command *)c1)->name, ((command *)c2)->name);
}

canonical_original_code:
static int cmd_compare_by_name(void *c1, void *c2) {
 return strcmp(((struct command *)c1)->name, ((struct command *)c2)->name);
}

user_defined_types: struct command { char *name; unsigned long nargs; void (*exec)(struct command *, void *[]); char *syntax; char *info; }


decompiled_code:
int __fastcall command_display(const char **a1)
{
return printf(" usage: %s %s - %s\n", *a1, a1[3], a1[4]);
}

canonical_decompiled_code:
int __fastcall func3(const char **a1)
{
return printf(" usage: %s %s - %s\n", *a1, a1[3], a1[4]);
}

original_code:
static void command_display(const command *c) {
 printf(" usage: %s %s - %s\n", c->name, c->syntax, c->info);
}

canonical_original_code:
static void command_display(struct command *c) {
 printf(" usage: %s %s - %s\n", c->name, c->syntax, c->info);
}


decompiled_code:
const void **commands_uninit()
{
const void **result; // rax

for ( result = (const void **)command_list; command_list; result = (const void **)command_list )
tdelete(*result, &command_list, (__compar_fn_t)&compare_ptr);
return result;
}

canonical_decompiled_code:
const void **func11()
{
const void **result; // rax

for ( result = (const void **)command_list; command_list; result = (const void **)command_list )
tdelete(*result, &command_list, (__compar_fn_t)&compare_ptr);
return result;
}

original_code:
static void commands_uninit(void) {
 const command *c;
 while (command_list != ((void *)0)) {
  c = *(const command **) command_list;
  tdelete(c, &command_list, compare_ptr);
 }
}

canonical_original_code:
static void commands_uninit() {
 struct command *c;
 while (command_list != ((void *)0)) {
  c = *(struct command **) command_list;
  tdelete(c, &command_list, compare_ptr);
 }
}


decompiled_code:
int repl_init()
{
int result; // eax

if ( !repl_initialized )
{
variables_init();
functions_init();
using_history();
result = commands_init();
repl_initialized = 1;
}
return result;
}

canonical_decompiled_code:
int func12()
{
int result; // eax

if ( !repl_initialized )
{
variables_init();
functions_init();
using_history();
result = func1();
repl_initialized = 1;
}
return result;
}

original_code:
void repl_init(void) {
 if (!repl_initialized) {
  variables_init();
  functions_init();
  using_history();
  commands_init();
  repl_initialized = 1;
 }
}

canonical_original_code:
void repl_init() {
 if (!repl_initialized) {
  variables_init();
  functions_init();
  using_history();
  commands_init();
  repl_initialized = 1;
 }
}


decompiled_code:
void __fastcall repl_prompt(const char *a1)
{
__int64 v1; // rax
_BYTE *v2; // rbx
const char *v3; // rax
char *v4; // rbp
_QWORD *v5; // rax
__int64 v6; // rdx
__int64 v7[16]; // [rsp+0h] [rbp-A8h] BYREF
__int64 v8; // [rsp+80h] [rbp-28h] BYREF
char *ptr; // [rsp+88h] [rbp-20h] BYREF

ptr = 0LL;
printf("Starting %s v\x1B[31m%s\x1B[0m...\n", "gPlotter", "0.1-alpha");
if ( asprintf(&ptr, "%s%s%s %%%s ", "\x1B[34m", a1, "\x1B[32m", "\x1B[0m") == -1 )
{
fprintf(stderr, "%s: could not allocate prefix\n", "repl_prompt");
}
else
{
while ( repl != 2 )
{
v1 = readline(ptr);
v2 = (_BYTE *)v1;
if ( !v1 )
break;
v3 = (const char *)get_word(v1, &v8);
v4 = (char *)v3;
if ( v3 )
{
v5 = commands_find(v3);
if ( v5 )
{
v7[1] = 0LL;
v6 = 0LL;
if ( v2[v8] )
v6 = (__int64)&v2[v8 + 1];
v7[0] = v6;
((void (__fastcall *)(_QWORD *, __int64 *))v5[2])(v5, v7);
}
else if ( *v4 )
{
fprintf(stderr, " '%s' - not a command\n", v4);
}
free(v4);
}
else
{
fwrite("unknown command\n", 1uLL, 0x10uLL, stderr);
}
free(v2);
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func13(const char *a1)
{
__int64 v1; // rax
_BYTE *v2; // rbx
const char *v3; // rax
char *v4; // rbp
_QWORD *v5; // rax
__int64 v6; // rdx
__int64 v7[16]; // [rsp+0h] [rbp-A8h] BYREF
__int64 v8; // [rsp+80h] [rbp-28h] BYREF
char *ptr; // [rsp+88h] [rbp-20h] BYREF

ptr = 0LL;
printf("Starting %s v\x1B[31m%s\x1B[0m...\n", "gPlotter", "0.1-alpha");
if ( asprintf(&ptr, "%s%s%s %%%s ", "\x1B[34m", a1, "\x1B[32m", "\x1B[0m") == -1 )
{
fprintf(stderr, "%s: could not allocate prefix\n", "repl_prompt");
}
else
{
while ( repl != 2 )
{
v1 = readline(ptr);
v2 = (_BYTE *)v1;
if ( !v1 )
break;
v3 = (const char *)get_word(v1, &v8);
v4 = (char *)v3;
if ( v3 )
{
v5 = commands_find(v3);
if ( v5 )
{
v7[1] = 0LL;
v6 = 0LL;
if ( v2[v8] )
v6 = (__int64)&v2[v8 + 1];
v7[0] = v6;
((void (__fastcall *)(_QWORD *, __int64 *))v5[2])(v5, v7);
}
else if ( *v4 )
{
fprintf(stderr, " '%s' - not a command\n", v4);
}
free(v4);
}
else
{
fwrite("unknown command\n", 1uLL, 0x10uLL, stderr);
}
free(v2);
}
}
free(ptr);
}

original_code:
void repl_prompt(const char *pre) {
 char *input;
 char *prefix = ((void *)0);
 char *cmd_word;
 const command *c;
 size_t wordlen;
 void *argv[16];
 printf("Starting %s v""\x1B[31m""%s""\x1B[0m""...\n", "gPlotter", "0.1-alpha");
 if (asprintf(&prefix, "%s%s%s %%%s ", "\x1B[34m", pre, "\x1B[32m", "\x1B[0m") == -1)
  fprintf(stderr, "%s: could not allocate prefix\n", __func__);
 else
  while (repl.state != EXIT && (input = readline(prefix)) != ((void *)0)) {
   if ((cmd_word = get_word(input, &wordlen)) != ((void *)0)) {
    if ((c = commands_find(cmd_word)) != ((void *)0)) {
     argv[1] = ((void *)0);
     argv[0] = input[wordlen] ?
        input + wordlen+1 : ((void *)0);
     c->exec(c, argv);
    } else if (*cmd_word) {
     fprintf(stderr,
      " '%s' - not a command\n",
      cmd_word);
    }
    free(cmd_word);
   } else {
    fprintf(stderr, "unknown command\n");
   }
   free(input);
  }
 free(prefix);
}

canonical_original_code:
void repl_prompt(char *pre) {
 char *input;
 char *prefix = ((void *)0);
 char *cmd_word;
 struct command *c;
 unsigned long wordlen;
 void *argv[16];
 printf("Starting %s v""\x1B[31m""%s""\x1B[0m""...\n", "gPlotter", "0.1-alpha");
 if (asprintf(&prefix, "%s%s%s %%%s ", "\x1B[34m", pre, "\x1B[32m", "\x1B[0m") == -1)
  fprintf(stderr, "%s: could not allocate prefix\n", __func__);
 else
  while (repl.state != EXIT && (input = readline(prefix)) != ((void *)0)) {
   if ((cmd_word = get_word(input, &wordlen)) != ((void *)0)) {
    if ((c = commands_find(cmd_word)) != ((void *)0)) {
     argv[1] = ((void *)0);
     argv[0] = input[wordlen] ?
        input + wordlen+1 : ((void *)0);
     c->exec(c, argv);
    } else if (*cmd_word) {
     fprintf(stderr,
      " '%s' - not a command\n",
      cmd_word);
    }
    free(cmd_word);
   } else {
    fprintf(stderr, "unknown command\n");
   }
   free(input);
  }
 free(prefix);
}

variable_types:
pre
char *

variable_types:
input
char *

variable_types:
prefix
char *

variable_types:
wordlen
unsigned long

variable_types:
argv
void *[16]


decompiled_code:
__int64 __fastcall repl_prompt_eval(__int64 a1, double a2)
{
void *v2; // rbx
__int64 v3; // rbp
void *v5; // [rsp+0h] [rbp-28h] BYREF
char *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = 0LL;
v5 = 0LL;
asprintf(&ptr, "eval[%d]: ", a1);
v2 = (void *)readline(ptr);
if ( v2 )
{
asprintf((char **)&v5, "f%d", a1);
v3 = function_new(v5, 0LL, v2);
function_eval(v3, 0LL);
printf("result: %lf\n", a2);
add_history(v2);
function_destroy(v3);
free(v2);
free(ptr);
free(v5);
}
else
{
free(ptr);
}
return (unsigned int)-(v2 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, double a2)
{
void *v2; // rbx
__int64 v3; // rbp
void *v5; // [rsp+0h] [rbp-28h] BYREF
char *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = 0LL;
v5 = 0LL;
asprintf(&ptr, "eval[%d]: ", a1);
v2 = (void *)readline(ptr);
if ( v2 )
{
asprintf((char **)&v5, "f%d", a1);
v3 = function_new(v5, 0LL, v2);
function_eval(v3, 0LL);
printf("result: %lf\n", a2);
add_history(v2);
function_destroy(v3);
free(v2);
free(ptr);
free(v5);
}
else
{
free(ptr);
}
return (unsigned int)-(v2 == 0LL);
}

original_code:
int repl_prompt_eval(long nl) {
 char *input;
 double val;
 char *prefix = ((void *)0), *temp = ((void *)0);
 function *func;
 asprintf(&prefix, "eval[%d]: ", nl);
 if ((input = readline(prefix)) != ((void *)0)) {
  asprintf(&temp, "f%d", nl);
  func = function_new(temp, ((void *)0), input);
  val = function_eval(func, ((void *)0));
  printf("result: %lf\n", val);
  add_history(input);
  function_destroy(func);
  free(input);
  free(prefix);
  free(temp);
 } else
  free(prefix);
 return input != ((void *)0) ? 0 : -1;
}

canonical_original_code:
int repl_prompt_eval(long nl) {
 char *input;
 double val;
 char *prefix = ((void *)0); char *temp = ((void *)0);
 struct function *func;
 asprintf(&prefix, "eval[%d]: ", nl);
 if ((input = readline(prefix)) != ((void *)0)) {
  asprintf(&temp, "f%d", nl);
  func = function_new(temp, ((void *)0), input);
  val = function_eval(func, ((void *)0));
  printf("result: %lf\n", val);
  add_history(input);
  function_destroy(func);
  free(input);
  free(prefix);
  free(temp);
 } else
  free(prefix);
 return input != ((void *)0) ? 0 : -1;
}

variable_types: nl long

variable_types:
temp
char *

variable_types: struct function { char *name; char *vars; unsigned long nvars; char *descr; unsigned long len; enum function_type { USER=0, NATIVE=1, ANY=2 } type; void *native_fptr; int destroy; } *

user_defined_types: struct function { char *name; char *vars; unsigned long nvars; char *descr; unsigned long len; enum function_type type; void *native_fptr; int destroy; }


decompiled_code:
const void **repl_uninit()
{
const void **result; // rax

if ( repl_initialized )
{
functions_uninit();
variables_uninit();
clear_history();
result = commands_uninit();
repl_initialized = 0;
}
return result;
}

canonical_decompiled_code:
const void **func16()
{
const void **result; // rax

if ( repl_initialized )
{
functions_uninit();
variables_uninit();
clear_history();
result = func11();
repl_initialized = 0;
}
return result;
}

original_code:
void repl_uninit(void) {
 if (repl_initialized) {
  functions_uninit();
  variables_uninit();
  clear_history();
  commands_uninit();
  repl_initialized = 0;
 }
}

canonical_original_code:
void repl_uninit() {
 if (repl_initialized) {
  functions_uninit();
  variables_uninit();
  clear_history();
  commands_uninit();
  repl_initialized = 0;
 }
}


romberg

repo: ProfessorBrunner/tpacf

original_code:
static double romberg(double z){
 int i,j,steps,denom;
 double h,r1[20 +1],r2[20 +1],sum;
 h = z;
 r1[0] = oneOverE(0.);
 r1[0] += oneOverE(z);
 r1[0] *= 0.5*h;
 i = 1;
 steps = 1;
 denom = 4.;
 for( ; ; ){
  sum = 0.;
  for(j=1;j<=steps;j++){
   sum += oneOverE(((double)j-0.5)*h);
  }
  steps = steps << 1;
  r2[0] = .5*(r1[0] + h*sum);
  denom = 4;
  for(j=0;j<i;j++){
   r2[j+1] = r2[j] + (r2[j]-r1[j])/((double)denom-1.);
   denom = denom << 2;
  }
  if(fabs(r2[i] - r1[i-1]) < 1.e-7*r1[i-1]){
   return r2[i];
  }else if(i == 20){
   fprintf(stderr,"Maximum refinement reached in romberg...ABORTING\n");
   exit(1);
  }
  h = h/2.;
  i++;
  for(j=0;j<i;j++){
   r1[j] = r2[j];
  }
 }
}

canonical_original_code:
static double romberg(double z){
 int i; int j; int steps; int denom;
 double h; double r1[-1]; double r2[-1]; double sum;
 h = z;
 r1[0] = oneOverE(0.);
 r1[0] += oneOverE(z);
 r1[0] *= 0.5*h;
 i = 1;
 steps = 1;
 denom = 4.;
 for( ; ; ){
  sum = 0.;
  for(j=1;j<=steps;j++){
   sum += oneOverE(((double)j-0.5)*h);
  }
  steps = steps << 1;
  r2[0] = .5*(r1[0] + h*sum);
  denom = 4;
  for(j=0;j<i;j++){
   r2[j+1] = r2[j] + (r2[j]-r1[j])/((double)denom-1.);
   denom = denom << 2;
  }
  if(fabs(r2[i] - r1[i-1]) < 1.e-7*r1[i-1]){
   return r2[i];
  }else if(i == 20){
   fprintf(stderr,"Maximum refinement reached in romberg...ABORTING\n");
   exit(1);
  }
  h = h/2.;
  i++;
  for(j=0;j<i;j++){
   r1[j] = r2[j];
  }
 }
}

variable_types: z double

variable_types: i int

variable_types: j int

variable_types: steps int

variable_types: denom int

variable_types: h double

variable_types: sum double

return_type: double


dm

decompiled_code:
double __fastcall dm(double a1)
{
return romberg(a1) * 3000.0;
}

canonical_decompiled_code:
double __fastcall func2(double a1)
{
return func1(a1) * 3000.0;
}

original_code:
static double dm(double z){
 return 3000.*romberg(z);
}


binBuildSpatial

decompiled_code:
double *__fastcall binBuildSpatial(double a1, double a2)
{
double *v2; // r13
int v3; // eax
double v4; // r15
double *v5; // rbp
int v6; // er12
void *v7; // r14
__int64 i; // rax
double *v9; // rbx
__int64 j; // rax

v2 = (double *)malloc(24LL * (NumBins + 2));
if ( v2 )
{
v3 = NumBins;
if ( NumBins >= 0 )
{
v4 = a1 / a2;
v5 = v2;
v6 = 0;
do
{
*v5 = pow(v4, ((double)v6 + (double)v6) / (double)v3) * (a2 * a2);
v5[2] = pow(v4, ((double)v6 - 0.5) / (double)NumBins) * a2;
v7 = malloc(8LL * (NumSamples + 1));
*((_QWORD *)v5 + 1) = v7;
if ( !v7 )
goto LABEL_5;
for ( i = 0LL; NumSamples >= (int)i; ++i )
*(_QWORD *)(*((_QWORD *)v5 + 1) + 8 * i) = 0LL;
++v6;
v3 = NumBins;
v5 += 3;
}
while ( NumBins >= v6 );
}
v9 = &v2[3 * v3 + 3];
*v9 = 0.0;
*((_QWORD *)v9 + 1) = malloc(8LL * (NumSamples + 1));
if ( !*(_QWORD *)&v2[3 * NumBins + 4] )
{
LABEL_5:
fwrite("Failed to allocate sample space in binBuild\n", 1uLL, 0x2CuLL, stderr);
return 0LL;
}
for ( j = 0LL; NumSamples >= (int)j; ++j )
*(_QWORD *)(*(_QWORD *)&v2[3 * NumBins + 4] + 8 * j) = 0LL;
}
else
{
puts("Failed to allocate memory in binBuild");
}
return v2;
}

canonical_decompiled_code:
double *__fastcall func0(double a1, double a2)
{
double *v2; // r13
int v3; // eax
double v4; // r15
double *v5; // rbp
int v6; // er12
void *v7; // r14
__int64 i; // rax
double *v9; // rbx
__int64 j; // rax

v2 = (double *)malloc(24LL * (NumBins + 2));
if ( v2 )
{
v3 = NumBins;
if ( NumBins >= 0 )
{
v4 = a1 / a2;
v5 = v2;
v6 = 0;
do
{
*v5 = pow(v4, ((double)v6 + (double)v6) / (double)v3) * (a2 * a2);
v5[2] = pow(v4, ((double)v6 - 0.5) / (double)NumBins) * a2;
v7 = malloc(8LL * (NumSamples + 1));
*((_QWORD *)v5 + 1) = v7;
if ( !v7 )
goto LABEL_5;
for ( i = 0LL; NumSamples >= (int)i; ++i )
*(_QWORD *)(*((_QWORD *)v5 + 1) + 8 * i) = 0LL;
++v6;
v3 = NumBins;
v5 += 3;
}
while ( NumBins >= v6 );
}
v9 = &v2[3 * v3 + 3];
*v9 = 0.0;
*((_QWORD *)v9 + 1) = malloc(8LL * (NumSamples + 1));
if ( !*(_QWORD *)&v2[3 * NumBins + 4] )
{
LABEL_5:
fwrite("Failed to allocate sample space in binBuild\n", 1uLL, 0x2CuLL, stderr);
return 0LL;
}
for ( j = 0LL; NumSamples >= (int)j; ++j )
*(_QWORD *)(*(_QWORD *)&v2[3 * NumBins + 4] + 8 * j) = 0LL;
}
else
{
puts("Failed to allocate memory in binBuild");
}
return v2;
}

original_code:
bin *binBuildSpatial(double minDist,double maxDist){
 int i,j;
 bin *bins;
 ;
 bins = malloc((NumBins+2)*sizeof(bin));
 if(bins == ((void *)0)){
  printf("Failed to allocate memory in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumBins;i++){
  bins[i].limit = maxDist*maxDist*pow(minDist/maxDist,(2.*(double)i)/((double)NumBins));
  bins[i].center = maxDist*pow(minDist/maxDist,((double)i-0.5)/((double)NumBins));
  bins[i].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long int));
  if(bins[i].Cnt == ((void *)0)){
   fprintf(stderr,"Failed to allocate sample space in binBuild\n");
   return ((void *)0);
  }
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 bins[NumBins+1].limit = 0.;
 bins[NumBins+1].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long int));
 if(bins[NumBins+1].Cnt == ((void *)0)){
  fprintf(stderr,"Failed to allocate sample space in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumSamples;i++){
  bins[NumBins+1].Cnt[i] = 0;
 }
 ;
 return bins;
}

canonical_original_code:
struct _bin *binBuildSpatial(double minDist, double maxDist){
 int i; int j;
 struct _bin *bins;
 ;
 bins = malloc((NumBins+2)*sizeof(bin));
 if(bins == ((void *)0)){
  printf("Failed to allocate memory in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumBins;i++){
  bins[i].limit = maxDist*maxDist*pow(minDist/maxDist,(2.*(double)i)/((double)NumBins));
  bins[i].center = maxDist*pow(minDist/maxDist,((double)i-0.5)/((double)NumBins));
  bins[i].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long));
  if(bins[i].Cnt == ((void *)0)){
   fprintf(stderr,"Failed to allocate sample space in binBuild\n");
   return ((void *)0);
  }
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 bins[NumBins+1].limit = 0.;
 bins[NumBins+1].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long));
 if(bins[NumBins+1].Cnt == ((void *)0)){
  fprintf(stderr,"Failed to allocate sample space in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumSamples;i++){
  bins[NumBins+1].Cnt[i] = 0;
 }
 ;
 return bins;
}

variable_types: minDist double

variable_types: maxDist double

variable_types: struct _bin { double limit; unsigned long long *Cnt; double center; } *


binBuildAngular

decompiled_code:
double *__fastcall binBuildAngular(double a1, double a2)
{
double *v2; // r13
int v3; // eax
double v4; // r15
double *v5; // rbp
int v6; // er12
double v7; // xmm0_8
void *v8; // r14
__int64 i; // rax
double *v10; // rbx
__int64 j; // rax

v2 = (double *)malloc(24LL * (NumBins + 2));
if ( v2 )
{
v3 = NumBins;
if ( NumBins >= 0 )
{
v4 = a1 / a2;
v5 = v2;
v6 = 0;
do
{
v7 = pow(v4, (double)v6 / (double)v3);
*v5 = cos(v7 * a2);
v5[2] = a2 * 57.29577951308232 * pow(v4, ((double)v6 - 0.5) / (double)NumBins);
v8 = malloc(8LL * (NumSamples + 1));
*((_QWORD *)v5 + 1) = v8;
if ( !v8 )
goto LABEL_5;
for ( i = 0LL; NumSamples >= (int)i; ++i )
*(_QWORD *)(*((_QWORD *)v5 + 1) + 8 * i) = 0LL;
++v6;
v3 = NumBins;
v5 += 3;
}
while ( NumBins >= v6 );
}
v10 = &v2[3 * v3 + 3];
*(_QWORD *)v10 = LC6;
*((_QWORD *)v10 + 1) = malloc(8LL * (NumSamples + 1));
if ( !*(_QWORD *)&v2[3 * NumBins + 4] )
{
LABEL_5:
fwrite("Failed to allocate sample space in binBuild\n", 1uLL, 0x2CuLL, stderr);
return 0LL;
}
for ( j = 0LL; NumSamples >= (int)j; ++j )
*(_QWORD *)(*(_QWORD *)&v2[3 * NumBins + 4] + 8 * j) = 0LL;
}
else
{
puts("Failed to allocate memory in buildbins");
}
return v2;
}

canonical_decompiled_code:
double *__fastcall func1(double a1, double a2)
{
double *v2; // r13
int v3; // eax
double v4; // r15
double *v5; // rbp
int v6; // er12
double v7; // xmm0_8
void *v8; // r14
__int64 i; // rax
double *v10; // rbx
__int64 j; // rax

v2 = (double *)malloc(24LL * (NumBins + 2));
if ( v2 )
{
v3 = NumBins;
if ( NumBins >= 0 )
{
v4 = a1 / a2;
v5 = v2;
v6 = 0;
do
{
v7 = pow(v4, (double)v6 / (double)v3);
*v5 = cos(v7 * a2);
v5[2] = a2 * 57.29577951308232 * pow(v4, ((double)v6 - 0.5) / (double)NumBins);
v8 = malloc(8LL * (NumSamples + 1));
*((_QWORD *)v5 + 1) = v8;
if ( !v8 )
goto LABEL_5;
for ( i = 0LL; NumSamples >= (int)i; ++i )
*(_QWORD *)(*((_QWORD *)v5 + 1) + 8 * i) = 0LL;
++v6;
v3 = NumBins;
v5 += 3;
}
while ( NumBins >= v6 );
}
v10 = &v2[3 * v3 + 3];
*(_QWORD *)v10 = LC6;
*((_QWORD *)v10 + 1) = malloc(8LL * (NumSamples + 1));
if ( !*(_QWORD *)&v2[3 * NumBins + 4] )
{
LABEL_5:
fwrite("Failed to allocate sample space in binBuild\n", 1uLL, 0x2CuLL, stderr);
return 0LL;
}
for ( j = 0LL; NumSamples >= (int)j; ++j )
*(_QWORD *)(*(_QWORD *)&v2[3 * NumBins + 4] + 8 * j) = 0LL;
}
else
{
puts("Failed to allocate memory in buildbins");
}
return v2;
}

original_code:
bin *binBuildAngular(double minAngle,double maxAngle){
 int i,j;
 bin *bins;
 ;
 bins = malloc((NumBins+2)*sizeof(bin));
 if(bins == ((void *)0)){
  printf("Failed to allocate memory in buildbins\n");
  return ((void *)0);
 }
 for(i=0;i<=NumBins;i++){
  bins[i].limit = cos(maxAngle*pow(minAngle/maxAngle,((double)i)/((double)NumBins)));
  bins[i].center = 180./3.14159265358979323846*maxAngle*pow(minAngle/maxAngle,((double)i-0.5)/((double)NumBins));
  bins[i].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long int));
  if(bins[i].Cnt == ((void *)0)){
   fprintf(stderr,"Failed to allocate sample space in binBuild\n");
   return ((void *)0);
  }
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 bins[NumBins+1].limit = 2.;
 bins[NumBins+1].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long int));
 if(bins[NumBins+1].Cnt == ((void *)0)){
  fprintf(stderr,"Failed to allocate sample space in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumSamples;i++){
  bins[NumBins+1].Cnt[i] = 0;
 }
 ;
 return bins;
}

canonical_original_code:
struct _bin *binBuildAngular(double minAngle, double maxAngle){
 int i; int j;
 struct _bin *bins;
 ;
 bins = malloc((NumBins+2)*sizeof(bin));
 if(bins == ((void *)0)){
  printf("Failed to allocate memory in buildbins\n");
  return ((void *)0);
 }
 for(i=0;i<=NumBins;i++){
  bins[i].limit = cos(maxAngle*pow(minAngle/maxAngle,((double)i)/((double)NumBins)));
  bins[i].center = 180./3.14159265358979323846*maxAngle*pow(minAngle/maxAngle,((double)i-0.5)/((double)NumBins));
  bins[i].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long));
  if(bins[i].Cnt == ((void *)0)){
   fprintf(stderr,"Failed to allocate sample space in binBuild\n");
   return ((void *)0);
  }
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 bins[NumBins+1].limit = 2.;
 bins[NumBins+1].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long));
 if(bins[NumBins+1].Cnt == ((void *)0)){
  fprintf(stderr,"Failed to allocate sample space in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumSamples;i++){
  bins[NumBins+1].Cnt[i] = 0;
 }
 ;
 return bins;
}

variable_types: minAngle double

variable_types: maxAngle double

return_type: struct _bin { double limit; unsigned long long *Cnt; double center; } *


binClear

decompiled_code:
void __fastcall binClear(__int64 a1)
{
_QWORD *v1; // rcx
int i; // esi
__int64 j; // rax

if ( NumBins >= -1 )
{
v1 = (_QWORD *)(a1 + 8);
for ( i = 0; ; ++i )
{
for ( j = 0LL; NumSamples >= (int)j; ++j )
*(_QWORD *)(*v1 + 8 * j) = 0LL;
v1 += 3;
if ( NumBins < i )
break;
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
_QWORD *v1; // rcx
int i; // esi
__int64 j; // rax

if ( NumBins >= -1 )
{
v1 = (_QWORD *)(a1 + 8);
for ( i = 0; ; ++i )
{
for ( j = 0LL; NumSamples >= (int)j; ++j )
*(_QWORD *)(*v1 + 8 * j) = 0LL;
v1 += 3;
if ( NumBins < i )
break;
}
}
}

original_code:
void binClear(bin bins[]){
 int i,j;
 for(i=0;i<=NumBins+1;i++){
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 return;
}

canonical_original_code:
void binClear(struct _bin bins[]){
 int i; int j;
 for(i=0;i<=NumBins+1;i++){
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 return;
}

variable_types: struct _bin { double limit; unsigned long long *Cnt; double center; } []


binFree

decompiled_code:
void __fastcall binFree(void *ptr)
{
void **v1; // rbp
int v2; // ebx
int v3; // eax

if ( NumBins >= -1 )
{
v1 = (void **)((char *)ptr + 8);
v2 = 0;
do
{
free(*v1);
v3 = v2++;
v1 += 3;
}
while ( NumBins >= v3 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void **v1; // rbp
int v2; // ebx
int v3; // eax

if ( NumBins >= -1 )
{
v1 = (void **)((char *)ptr + 8);
v2 = 0;
do
{
free(*v1);
v3 = v2++;
v1 += 3;
}
while ( NumBins >= v3 );
}
free(ptr);
}

original_code:
void binFree(bin *bins){
 int i;
 for(i=0;i<=NumBins+1;i++){
  free(bins[i].Cnt);
 }
 free(bins);
 return;
}

canonical_original_code:
void binFree(struct _bin *bins){
 int i;
 for(i=0;i<=NumBins+1;i++){
  free(bins[i].Cnt);
 }
 free(bins);
 return;
}

user_defined_types: struct _bin { double limit; unsigned long long *Cnt; double center; }


spaTreeFill

decompiled_code:
__int64 __fastcall spaTreeFill(__int64 a1)
{
__int64 v1; // rbx

v1 = a1 + 80LL * NodePos;
if ( *(_DWORD *)(v1 + 64) == 1 )
{
++NodePos;
*(_QWORD *)(v1 + 64) = ((__int64 (*)(void))spaTreeFill)();
++NodePos;
*(_QWORD *)(v1 + 72) = spaTreeFill(a1);
}
else
{
*(_QWORD *)(v1 + 64) = 0LL;
*(_QWORD *)(v1 + 72) = 0LL;
}
return v1;
}

original_code:
static spaTreeNode *spaTreeFill(spaTreeNode *root){
 spaTreeNode *node;
 node = root+NodePos;
 if((int)node->lptr == 1){
  NodePos++;
  node->lptr = spaTreeFill(root);
  NodePos++;
  node->rptr = spaTreeFill(root);
 }else{
  node->lptr = ((void *)0);
  node->rptr = ((void *)0);
 }
 return node;
}

canonical_original_code:
static struct _spaTreeNode *spaTreeFill(struct _spaTreeNode *root){
 struct _spaTreeNode *node;
 node = root+NodePos;
 if((int)node->lptr == 1){
  NodePos++;
  node->lptr = spaTreeFill(root);
  NodePos++;
  node->rptr = spaTreeFill(root);
 }else{
  node->lptr = ((void *)0);
  node->rptr = ((void *)0);
 }
 return node;
}

variable_types:
root
struct _spaTreeNode *

variable_types: struct _spaTreeNode { int Sample; int Cnt; int Start; int End; double xmin; struct _spaTreeNode *lptr; struct _spaTreeNode *rptr; } *


angTreeFill

decompiled_code:
__int64 __fastcall angTreeFill(__int64 a1)
{
__int64 v1; // rbx

v1 = a1 + 80LL * NodePos;
if ( *(_DWORD *)(v1 + 64) == 1 )
{
++NodePos;
*(_QWORD *)(v1 + 64) = ((__int64 (*)(void))angTreeFill)();
++NodePos;
*(_QWORD *)(v1 + 72) = angTreeFill(a1);
}
else
{
*(_QWORD *)(v1 + 64) = 0LL;
*(_QWORD *)(v1 + 72) = 0LL;
}
return v1;
}

original_code:
static angTreeNode *angTreeFill(angTreeNode *root){
 angTreeNode *node;
 node = root+NodePos;
 if((int)node->lptr == 1){
  NodePos++;
  node->lptr = angTreeFill(root);
  NodePos++;
  node->rptr = angTreeFill(root);
 }else{
  node->lptr = ((void *)0);
  node->rptr = ((void *)0);
 }
 return node;
}

canonical_original_code:
static struct _angTreeNode *angTreeFill(struct _angTreeNode *root){
 struct _angTreeNode *node;
 node = root+NodePos;
 if((int)node->lptr == 1){
  NodePos++;
  node->lptr = angTreeFill(root);
  NodePos++;
  node->rptr = angTreeFill(root);
 }else{
  node->lptr = ((void *)0);
  node->rptr = ((void *)0);
 }
 return node;
}

variable_types:
root
struct _angTreeNode *

variable_types: struct _angTreeNode { int Sample; int Cnt; int Start; int End; double x; double clowbound; struct _angTreeNode *lptr; struct _angTreeNode *rptr; } *


treeGetMemory

decompiled_code:
void *__fastcall treeGetMemory(void **a1, _QWORD *a2, const char *a3)
{
size_t v3; // rbx
void *result; // rax

v3 = (int)(80 * getMaxTreesize(a3));
*a1 = malloc(v3);
result = malloc(v3);
*a2 = result;
if ( !*a1 || !result )
{
fwrite("Failed to allocate tree space\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void **a1, _QWORD *a2, const char *a3)
{
size_t v3; // rbx
void *result; // rax

v3 = (int)(80 * func2(a3));
*a1 = malloc(v3);
result = malloc(v3);
*a2 = result;
if ( !*a1 || !result )
{
fwrite("Failed to allocate tree space\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
return result;
}

original_code:
void treeGetMemory(void **block1, void **block2, char *filelist){
 int max,nodesize;
 max = getMaxTreesize(filelist);
 if(AngOrSpa == 0){
  nodesize = sizeof(angTreeNode);
 }else{
  nodesize = sizeof(spaTreeNode);
 }
 *block1 = malloc(max*nodesize);
 *block2 = malloc(max*nodesize);
 if(*block1 == ((void *)0) || *block2 == ((void *)0)){
  fprintf(stderr,"Failed to allocate tree space\n");
  exit(1);
 }
 return;
}

canonical_original_code:
void treeGetMemory(void **block1, void **block2, char *filelist){
 int max; int nodesize;
 max = getMaxTreesize(filelist);
 if(AngOrSpa == 0){
  nodesize = sizeof(angTreeNode);
 }else{
  nodesize = sizeof(spaTreeNode);
 }
 *block1 = malloc(max*nodesize);
 *block2 = malloc(max*nodesize);
 if(*block1 == ((void *)0) || *block2 == ((void *)0)){
  fprintf(stderr,"Failed to allocate tree space\n");
  exit(1);
 }
 return;
}

variable_types:
filelist
char *

variable_types: max int

variable_types: nodesize int


reportTimings

decompiled_code:
int reportTimings()
{
fprintf(stdout, "Total Walltime (s):\t%f\n\n", *(double *)&wallTimeTotal);
fprintf(stdout, "\tAC - %f\t\t%f\n", *(double *)&wallTimeAC, *(double *)&wallTimeAC / *(double *)&wallTimeTotal);
fprintf(stdout, "\tCC - %f\t\t%f\n", *(double *)&wallTimeCC, *(double *)&wallTimeCC / *(double *)&wallTimeTotal);
fprintf(
stdout,
"\tData Read - %f\t%f\n",
*(double *)&wallDataRead,
*(double *)&wallDataRead / *(double *)&wallTimeTotal);
return fprintf(
stdout,
"\tTree Read - %f\t%f\n",
*(double *)&wallTreeRead,
*(double *)&wallTreeRead / *(double *)&wallTimeTotal);
}

canonical_decompiled_code:
int func1()
{
fprintf(stdout, "Total Walltime (s):\t%f\n\n", *(double *)&wallTimeTotal);
fprintf(stdout, "\tAC - %f\t\t%f\n", *(double *)&wallTimeAC, *(double *)&wallTimeAC / *(double *)&wallTimeTotal);
fprintf(stdout, "\tCC - %f\t\t%f\n", *(double *)&wallTimeCC, *(double *)&wallTimeCC / *(double *)&wallTimeTotal);
fprintf(
stdout,
"\tData Read - %f\t%f\n",
*(double *)&wallDataRead,
*(double *)&wallDataRead / *(double *)&wallTimeTotal);
return fprintf(
stdout,
"\tTree Read - %f\t%f\n",
*(double *)&wallTreeRead,
*(double *)&wallTreeRead / *(double *)&wallTimeTotal);
}

original_code:
void reportTimings(){
  fprintf(stdout,"Total Walltime (s):\t%f\n\n",wallTimeTotal);
  fprintf(stdout,"\tAC - %f\t\t%f\n",wallTimeAC,wallTimeAC/wallTimeTotal);
  fprintf(stdout,"\tCC - %f\t\t%f\n",wallTimeCC,wallTimeCC/wallTimeTotal);
  fprintf(stdout,"\tData Read - %f\t%f\n",wallDataRead,wallDataRead/wallTimeTotal);
  fprintf(stdout,"\tTree Read - %f\t%f\n",wallTreeRead,wallTreeRead/wallTimeTotal);
 return;
}


avg

original_code:
double avg(struct person * data, size_t size){
 int count = 0;
 double total = 0;
 for(;size > 0;size--, data++){
  total += data->amount;
  count++;
 }
 return total/count;
}

canonical_original_code:
double avg(struct person *data, unsigned long size){
 int count = 0;
 double total = 0;
 for(;size > 0;size--, data++){
  total += data->amount;
  count++;
 }
 return total/count;
}

variable_types: struct person { char name[11]; double amount; } *

variable_types:
size
unsigned long

variable_types: count int

variable_types: total double


calctotal

decompiled_code:
double __fastcall calctotal(__int64 a1, __int64 a2)
{
double result; // xmm0_8

if ( !a2 )
return 0.0;
result = 0.0;
do
{
result = result + *(double *)(a1 + 16);
a1 += 24LL;
--a2;
}
while ( a2 );
return result;
}

canonical_decompiled_code:
double __fastcall func8(__int64 a1, __int64 a2)
{
double result; // xmm0_8

if ( !a2 )
return 0.0;
result = 0.0;
do
{
result = result + *(double *)(a1 + 16);
a1 += 24LL;
--a2;
}
while ( a2 );
return result;
}

original_code:
double calctotal(struct person * data, size_t size){
 double total = 0;
 for(;size > 0;size--, data++)
  total += data->amount;
 return total;
}

canonical_original_code:
double calctotal(struct person *data, unsigned long size){
 double total = 0;
 for(;size > 0;size--, data++)
  total += data->amount;
 return total;
}

user_defined_types: struct person { char name[11]; double amount; }


calcdiff

decompiled_code:
void __fastcall calcdiff(__int64 a1, int a2, double a3)
{
__int64 v4; // rax
double v5; // xmm2_8
double v6; // xmm0_8

if ( a2 > 0 )
{
v4 = a1 + 24LL * (unsigned int)a2;
do
{
v6 = *(double *)(a1 + 16);
if ( a3 <= v6 )
v5 = v6 - a3;
else
v5 = a3 - v6;
*(double *)(a1 + 16) = v5;
a1 += 24LL;
}
while ( v4 != a1 );
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, double a3)
{
__int64 v4; // rax
double v5; // xmm2_8
double v6; // xmm0_8

if ( a2 > 0 )
{
v4 = a1 + 24LL * (unsigned int)a2;
do
{
v6 = *(double *)(a1 + 16);
if ( a3 <= v6 )
v5 = v6 - a3;
else
v5 = a3 - v6;
*(double *)(a1 + 16) = v5;
a1 += 24LL;
}
while ( v4 != a1 );
}
}

original_code:
void calcdiff(struct person *data, int size, double average){
 for(;size > 0;size--, data++){
  if(data->amount < average)
   data->amount = average - data->amount;
  else
   data->amount = data->amount - average;
 }
}

variable_types: size int

variable_types: average double


sortdesc

decompiled_code:
void __fastcall sortdesc(char *dest, __int64 a2)
{
int v3; // eax
__int64 v4; // rbp
double v5; // xmm0_8
double v6; // xmm1_8
char desta[67]; // [rsp+5h] [rbp-43h] BYREF

do
{
if ( a2 == 1 )
break;
v3 = 0;
v4 = 0LL;
do
{
v5 = *((double *)dest + 2);
v6 = *((double *)dest + 5);
if ( v6 > v5 )
{
*((double *)dest + 2) = v6;
*((double *)dest + 5) = v5;
strcpy(desta, dest);
strcpy(dest, dest + 24);
strcpy(dest + 24, desta);
v3 = 1;
}
++v4;
dest += 24;
}
while ( v4 != a2 - 1 );
}
while ( v3 );
}

canonical_decompiled_code:
void __fastcall func10(char *dest, __int64 a2)
{
int v3; // eax
__int64 v4; // rbp
double v5; // xmm0_8
double v6; // xmm1_8
char desta[67]; // [rsp+5h] [rbp-43h] BYREF

do
{
if ( a2 == 1 )
break;
v3 = 0;
v4 = 0LL;
do
{
v5 = *((double *)dest + 2);
v6 = *((double *)dest + 5);
if ( v6 > v5 )
{
*((double *)dest + 2) = v6;
*((double *)dest + 5) = v5;
strcpy(desta, dest);
strcpy(dest, dest + 24);
strcpy(dest + 24, desta);
v3 = 1;
}
++v4;
dest += 24;
}
while ( v4 != a2 - 1 );
}
while ( v3 );
}

original_code:
void sortdesc(struct person * data, size_t size){
 size_t i;
 int swapped;
 struct person * dataptr;
 double amountbuffer;
 char namebuffer[11];
 do{
  swapped = 0;
  for(i = 0, dataptr = data; i < size - 1; i++, dataptr++){
   if(dataptr->amount < (dataptr+1)->amount){
    amountbuffer = dataptr->amount;
    dataptr->amount = (dataptr+1)->amount;
    (dataptr+1)->amount = amountbuffer;
    strcpy(namebuffer, dataptr->name);
    strcpy(dataptr->name, (dataptr+1)->name);
    strcpy((dataptr+1)->name, namebuffer);
    swapped = 1;
   }
  }
 } while (swapped);
}

canonical_original_code:
void sortdesc(struct person *data, unsigned long size){
 unsigned long i;
 int swapped;
 struct person *dataptr;
 double amountbuffer;
 char namebuffer[11];
 do{
  swapped = 0;
  for(i = 0, dataptr = data; i < size - 1; i++, dataptr++){
   if(dataptr->amount < (dataptr+1)->amount){
    amountbuffer = dataptr->amount;
    dataptr->amount = (dataptr+1)->amount;
    (dataptr+1)->amount = amountbuffer;
    strcpy(namebuffer, dataptr->name);
    strcpy(dataptr->name, (dataptr+1)->name);
    strcpy((dataptr+1)->name, namebuffer);
    swapped = 1;
   }
  }
 } while (swapped);
}

variable_types:
i
unsigned long

variable_types: swapped int

variable_types: amountbuffer double

variable_types:
namebuffer
char [11]