searchDILNode

decompiled_code:
__int64 __fastcall searchDILNode(__int64 *a1, int a2)
{
__int64 result; // rax

for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( *(_DWORD *)(result + 16) == a2 )
break;
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( *(_DWORD *)(result + 16) == a2 )
break;
}
return result;
}

original_code:
DILNode *searchDILNode(DILList *list, int data) {
 DILNode *point;
 for (point = list->start; point != ((void *)0) && point->data != data; point = point->next) ;
 return point;
}

canonical_original_code:
struct tagDILinkNode *searchDILNode(struct tagDILinkList *list, int data) {
 struct tagDILinkNode *point;
 for (point = list->start; point != ((void *)0) && point->data != data; point = point->next) ;
 return point;
}

variable_types: struct tagDILinkList { struct tagDILinkNode *start; struct tagDILinkNode *end; int items; } *

variable_types: data int

return_type: struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; } *


deleteDILIterator

repo: vraisamis/pjeuler-c

decompiled_code:
// attributes: thunk
void deleteDILIterator(void *ptr)
{
deleteDILNode(ptr);
}

canonical_decompiled_code:
void func6(void *ptr)
{
func0(ptr);
}

original_code:
void deleteDILIterator(DILIterator *iterator) {
 free(iterator);
}

canonical_original_code:
void deleteDILIterator(struct tagDILinkListIterator *iterator) {
 free(iterator);
}

variable_types: struct tagDILinkListIterator { struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; } *current; struct tagDILinkList { struct tagDILinkNode *start; struct tagDILinkNode *end; int items; } *target; enum enBool { FALSE=0, TRUE=1 } isForward; } *

return_type: void

user_defined_types: struct tagDILinkListIterator { struct tagDILinkNode *current; struct tagDILinkList *target; enum enBool isForward; }


hasNextDILNode

decompiled_code:
_BOOL8 __fastcall hasNextDILNode(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
boolean hasNextDILNode(DILIterator *iterator) {
 return iterator->current == ((void *)0) ? FALSE : TRUE;
}

canonical_original_code:
enum enBool hasNextDILNode(struct tagDILinkListIterator *iterator) {
 return iterator->current == ((void *)0) ? FALSE : TRUE;
}

return_type: enum enBool { FALSE=0, TRUE=1 }

user_defined_types: struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; }

user_defined_types: struct tagDILinkList { struct tagDILinkNode *start; struct tagDILinkNode *end; int items; }


nextDILNode

decompiled_code:
__int64 __fastcall nextDILNode(_DWORD *a1)
{
__int64 result; // rax

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( !a1[4] )
result = **(_QWORD **)a1;
*(_QWORD *)a1 = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( !a1[4] )
result = **(_QWORD **)a1;
*(_QWORD *)a1 = result;
return result;
}

original_code:
void nextDILNode(DILIterator *iterator) {
 iterator->current = iterator->isForward ? iterator->current->next : iterator->current->prev;
}

canonical_original_code:
void nextDILNode(struct tagDILinkListIterator *iterator) {
 iterator->current = iterator->isForward ? iterator->current->next : iterator->current->prev;
}


getCurrentDILNode

decompiled_code:
__int64 __fastcall getCurrentDILNode(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
DILNode *getCurrentDILNode(DILIterator *iterator) {
 return iterator->current;
}

canonical_original_code:
struct tagDILinkNode *getCurrentDILNode(struct tagDILinkListIterator *iterator) {
 return iterator->current;
}

variable_types: struct tagDILinkListIterator { struct tagDILinkNode *current; struct tagDILinkList { struct tagDILinkNode *start; struct tagDILinkNode *end; int items; } *target; enum enBool { FALSE=0, TRUE=1 } isForward; } *


deleteSILNode

decompiled_code:
// attributes: thunk
void deleteSILNode(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
void deleteSILNode(SILNode *node) {
 free(node);
}

canonical_original_code:
void deleteSILNode(struct tagSILinkNode *node) {
 free(node);
}

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


newSILList

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
}
else
{
putErr("can't create SILList.");
result = 0LL;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
}
else
{
putErr("can't create SILList.");
result = 0LL;
}
return result;
}

original_code:
SILList *newSILList(void) {
 SILList *list = (SILList *)malloc(sizeof(SILList));
 if (list == ((void *)0)) putErr("can't create SILList.");
 else {
  list->start = ((void *)0);
  list->end = ((void *)0);
  list->items = 0;
 }
 return list;
}

canonical_original_code:
struct tagSILinkList *newSILList() {
 struct tagSILinkList *list = (SILList *)malloc(sizeof(SILList));
 if (list == ((void *)0)) putErr("can't create SILList.");
 else {
  list->start = ((void *)0);
  list->end = ((void *)0);
  list->items = 0;
 }
 return list;
}

variable_types: struct tagSILinkList { struct tagSILinkNode { struct tagSILinkNode *next; int data; } *start; struct tagSILinkNode *end; int items; } *

user_defined_types: struct tagSILinkList { struct tagSILinkNode *start; struct tagSILinkNode *end; int items; }


initSILList

decompiled_code:
__int64 __fastcall initSILList(__int64 a1)
{
_QWORD *v2; // rdi
__int64 result; // rax

v2 = *(_QWORD **)a1;
if ( v2 )
{
do
{
*(_QWORD *)a1 = *v2;
deleteSILNode(v2);
v2 = *(_QWORD **)a1;
}
while ( *(_QWORD *)a1 );
}
*(_QWORD *)(a1 + 8) = 0LL;
result = a1;
*(_DWORD *)(a1 + 16) = 0;
return result;
}

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

v2 = *(_QWORD **)a1;
if ( v2 )
{
do
{
*(_QWORD *)a1 = *v2;
func0(v2);
v2 = *(_QWORD **)a1;
}
while ( *(_QWORD *)a1 );
}
*(_QWORD *)(a1 + 8) = 0LL;
result = a1;
*(_DWORD *)(a1 + 16) = 0;
return result;
}

original_code:
SILList *initSILList(SILList *list) {
 SILNode *node;
 for (node = list->start; node != ((void *)0); node = list->start) {
  list->start = list->start->next;
  deleteSILNode(node);
 }
 list->end = ((void *)0);
 list->items = 0;
 return list;
}

canonical_original_code:
struct tagSILinkList *initSILList(struct tagSILinkList *list) {
 struct tagSILinkNode *node;
 for (node = list->start; node != ((void *)0); node = list->start) {
  list->start = list->start->next;
  deleteSILNode(node);
 }
 list->end = ((void *)0);
 list->items = 0;
 return list;
}

variable_types:
list
struct tagSILinkList *

return_type: struct tagSILinkList { struct tagSILinkNode { struct tagSILinkNode *next; int data; } *start; struct tagSILinkNode *end; int items; } *


deleteSILList

decompiled_code:
void __fastcall deleteSILList(void *ptr)
{
initSILList((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
func2((__int64)ptr);
free(ptr);
}

original_code:
void deleteSILList(SILList *list) {
 initSILList(list);
 free(list);
}

canonical_original_code:
void deleteSILList(struct tagSILinkList *list) {
 initSILList(list);
 free(list);
}

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


addSILNodeIndex

decompiled_code:
__int64 __fastcall addSILNodeIndex(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // rcx
_QWORD *v5; // rax

if ( *(_DWORD *)(a1 + 16) >= a3 )
{
if ( a3 == -1 )
{
v3 = *(_QWORD **)(a1 + 8);
}
else
{
v3 = (_QWORD *)a1;
if ( a3 > 0 )
{
while ( *v3 )
{
v3 = (_QWORD *)*v3;
if ( !--a3 )
goto LABEL_10;
}
*v3 = a2;
*a2 = 0LL;
goto LABEL_8;
}
}
LABEL_10:
v5 = (_QWORD *)*v3;
*v3 = a2;
*a2 = v5;
if ( v5 )
return a1;
LABEL_8:
*(_QWORD *)(a1 + 8) = a2;
return a1;
}
putErr("Index out of bound.");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // rcx
_QWORD *v5; // rax

if ( *(_DWORD *)(a1 + 16) >= a3 )
{
if ( a3 == -1 )
{
v3 = *(_QWORD **)(a1 + 8);
}
else
{
v3 = (_QWORD *)a1;
if ( a3 > 0 )
{
while ( *v3 )
{
v3 = (_QWORD *)*v3;
if ( !--a3 )
goto LABEL_10;
}
*v3 = a2;
*a2 = 0LL;
goto LABEL_8;
}
}
LABEL_10:
v5 = (_QWORD *)*v3;
*v3 = a2;
*a2 = v5;
if ( v5 )
return a1;
LABEL_8:
*(_QWORD *)(a1 + 8) = a2;
return a1;
}
putErr("Index out of bound.");
return 0LL;
}

original_code:
SILList *addSILNodeIndex(SILList *list, SILNode *node, int index) {
 SILNode **point, *tmp;
 if (index > list->items) {
  putErr("Index out of bound.");
  return ((void *)0);
 }
 if (index == -1) point = &(list->end->next);
 else for (point = &(list->start); index > 0 && *point != ((void *)0); point = &((*point)->next), index--) ;
 tmp = *point;
 *point = node;
 node->next = tmp;
 if (tmp == ((void *)0)) list->end = node;
 return list;
}

canonical_original_code:
struct tagSILinkList *addSILNodeIndex(struct tagSILinkList *list, struct tagSILinkNode *node, int index) {
 struct tagSILinkNode **point; struct tagSILinkNode *tmp;
 if (index > list->items) {
  putErr("Index out of bound.");
  return ((void *)0);
 }
 if (index == -1) point = &(list->end->next);
 else for (point = &(list->start); index > 0 && *point != ((void *)0); point = &((*point)->next), index--) ;
 tmp = *point;
 *point = node;
 node->next = tmp;
 if (tmp == ((void *)0)) list->end = node;
 return list;
}

variable_types:
node
struct tagSILinkNode *

variable_types: index int

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


addSILNode

decompiled_code:
__int64 __fastcall addSILNode(__int64 a1, _QWORD *a2, __int64 *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = *a3;
result = a1;
*a3 = (__int64)a2;
*a2 = v3;
if ( !v3 )
*(_QWORD *)(a1 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _QWORD *a2, __int64 *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = *a3;
result = a1;
*a3 = (__int64)a2;
*a2 = v3;
if ( !v3 )
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
SILList *addSILNode(SILList *list, SILNode *node, SILNode **pos) {
 SILNode *tmp;
 tmp = *pos;
 *pos = node;
 node->next = tmp;
 if (tmp == ((void *)0)) list->end = node;
 return list;
}

canonical_original_code:
struct tagSILinkList *addSILNode(struct tagSILinkList *list, struct tagSILinkNode *node, struct tagSILinkNode **pos) {
 struct tagSILinkNode *tmp;
 tmp = *pos;
 *pos = node;
 node->next = tmp;
 if (tmp == ((void *)0)) list->end = node;
 return list;
}

variable_types:
pos
struct tagSILinkNode **


deleteSILIterator

decompiled_code:
// attributes: thunk
void deleteSILIterator(void *ptr)
{
deleteSILNode(ptr);
}

canonical_decompiled_code:
void func7(void *ptr)
{
func0(ptr);
}

original_code:
void deleteSILIterator(SILIterator *iterator) {
 free(iterator);
}

canonical_original_code:
void deleteSILIterator(struct tagSILinkListIterator *iterator) {
 free(iterator);
}

variable_types: struct tagSILinkListIterator { struct tagSILinkNode { struct tagSILinkNode *next; int data; } *current; struct tagSILinkList { struct tagSILinkNode *start; struct tagSILinkNode *end; int items; } *target; } *

user_defined_types: struct tagSILinkListIterator { struct tagSILinkNode *current; struct tagSILinkList *target; }


hasNextSILNode

decompiled_code:
_BOOL8 __fastcall hasNextSILNode(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
boolean hasNextSILNode(SILIterator *iterator) {
 return iterator->current != ((void *)0) ? TRUE : FALSE;
}

canonical_original_code:
enum enBool hasNextSILNode(struct tagSILinkListIterator *iterator) {
 return iterator->current != ((void *)0) ? TRUE : FALSE;
}


getCurrentSILNode

decompiled_code:
__int64 __fastcall getCurrentSILNode(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
SILNode *getCurrentSILNode(SILIterator *iterator) {
 return iterator->current;
}

canonical_original_code:
struct tagSILinkNode *getCurrentSILNode(struct tagSILinkListIterator *iterator) {
 return iterator->current;
}

variable_types: struct tagSILinkListIterator { struct tagSILinkNode *current; struct tagSILinkList { struct tagSILinkNode *start; struct tagSILinkNode *end; int items; } *target; } *

return_type: struct tagSILinkNode { struct tagSILinkNode *next; int data; } *


printSILList

decompiled_code:
_BOOL8 printSILList()
{
_QWORD **v0; // rax
_QWORD **i; // rbx
__int64 v2; // rax
_BOOL8 result; // rax

getSILIterator();
for ( i = v0; ; nextSILNode(i) )
{
result = hasNextSILNode(i);
if ( !result )
break;
v2 = getCurrentSILNode((__int64)i);
printf("%d----", *(unsigned int *)(v2 + 8));
}
return result;
}

canonical_decompiled_code:
_BOOL8 func10()
{
_QWORD **v0; // rax
_QWORD **i; // rbx
__int64 v2; // rax
_BOOL8 result; // rax

func6();
for ( i = v0; ; nextSILNode(i) )
{
result = func8(i);
if ( !result )
break;
v2 = func9((__int64)i);
printf("%d----", *(unsigned int *)(v2 + 8));
}
return result;
}

original_code:
void printSILList(SILList *list) {
 SILIterator *iterator;
 for (iterator = getSILIterator(list); hasNextSILNode(iterator); nextSILNode(iterator)) printf("%d----", getCurrentSILNode(iterator)->data);
}

canonical_original_code:
void printSILList(struct tagSILinkList *list) {
 struct tagSILinkListIterator *iterator;
 for (iterator = getSILIterator(list); hasNextSILNode(iterator); nextSILNode(iterator)) printf("%d----", getCurrentSILNode(iterator)->data);
}


putErr

decompiled_code:
int __fastcall putErr(const char *a1)
{
return fprintf(stderr, "**Error**\n%s\n++EndErr**\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "**Error**\n%s\n++EndErr**\n", a1);
}

original_code:
void putErr(char *str) {
 fprintf(stderr, "**Error**\n%s\n++EndErr**\n", str);
}

variable_types:
str
char *


gcd

decompiled_code:
__int64 __fastcall gcd(int a1, int a2)
{
__int64 result; // rax
int v3; // edx
unsigned int v4; // er8

LODWORD(result) = abs32(a1);
v3 = abs32(a2);
if ( !a2 )
return (unsigned int)result;
do
{
v4 = v3;
v3 = (int)result % v3;
LODWORD(result) = v4;
}
while ( v3 );
return v4;
}

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

LODWORD(result) = abs32(a1);
v3 = abs32(a2);
if ( !a2 )
return (unsigned int)result;
do
{
v4 = v3;
v3 = (int)result % v3;
LODWORD(result) = v4;
}
while ( v3 );
return v4;
}

original_code:
int gcd(int x1, int x2) {
 int y;
 x1 = abs(x1);
 x2 = abs(x2);
 while (x2 != 0) {
  y = x1 % x2;
  x1 = x2;
  x2 = y;
 }
 return x1;
}

variable_types: y int

return_type: int


getPrime

decompiled_code:
__int64 __fastcall getPrime(_DWORD *a1, int a2)
{
int v3; // er8
int i; // er9
int v5; // esi
__int64 v6; // rcx

v3 = 1;
if ( a2 > 0 )
{
for ( i = 0; i < a2; i += i == v5 )
{
a1[i] = ++v3;
v5 = v3 % *a1;
if ( v5 )
{
v6 = 1LL;
do
v5 = v6;
while ( v3 % a1[v6++] );
}
}
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, int a2)
{
int v3; // er8
int i; // er9
int v5; // esi
__int64 v6; // rcx

v3 = 1;
if ( a2 > 0 )
{
for ( i = 0; i < a2; i += i == v5 )
{
a1[i] = ++v3;
v5 = v3 % *a1;
if ( v5 )
{
v6 = 1LL;
do
v5 = v6;
while ( v3 % a1[v6++] );
}
}
}
return (unsigned int)v3;
}

original_code:
int getPrime(int dst[], int n) {
 int i = 0, k = 1, j;
 while (i < n) {
  dst[i] = ++k;
  for (j = 0; k % dst[j] != 0; j++) ;
  if (j == i) i++;
 }
 return k;
}

canonical_original_code:
int getPrime(int dst[], int n) {
 int i = 0; int k = 1; int j;
 while (i < n) {
  dst[i] = ++k;
  for (j = 0; k % dst[j] != 0; j++) ;
  if (j == i) i++;
 }
 return k;
}

variable_types:
dst
int []

variable_types: n int

variable_types: i int

variable_types: k int

variable_types: j int


eratosthenes

original_code:
long eratosthenes(int *ary, int length) {
 int bits = sizeof(int) * 8;
 int i, j, k, l;
 long count = 0;
 for (i = 0; i < length; i++) ary[i] = ~0x00;
 ary[0] &= ~0x03;
 for (i = 0; i < length; i++) {
  for (j = 0; j < bits; j++) {
   if (((ary[i] >> j) & 0x01) == 0x00) continue;
   count++;
   for (l = 2 * j, k = 2 * i + l / bits; k < length; l += j, k += i + l / bits) {
    l %= bits;
    ary[k] &= ~(0x01 << l);
   }
  }
 }
 return count;
}

canonical_original_code:
long eratosthenes(int *ary, int length) {
 int bits = sizeof(int) * 8;
 int i; int j; int k; int l;
 long count = 0;
 for (i = 0; i < length; i++) ary[i] = ~0x00;
 ary[0] &= ~0x03;
 for (i = 0; i < length; i++) {
  for (j = 0; j < bits; j++) {
   if (((ary[i] >> j) & 0x01) == 0x00) continue;
   count++;
   for (l = 2 * j, k = 2 * i + l / bits; k < length; l += j, k += i + l / bits) {
    l %= bits;
    ary[k] &= ~(0x01 << l);
   }
  }
 }
 return count;
}

variable_types:
ary
int *

variable_types: length int

variable_types: bits int

variable_types: l int

variable_types: count long

return_type: long


eratosToArray

decompiled_code:
__int64 __fastcall eratosToArray(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // r10
unsigned int v5; // er8
int v6; // ecx
unsigned int i; // eax
__int64 v8; // rsi

if ( a3 <= 0 )
return 0LL;
v4 = 0LL;
v5 = 0;
do
{
v6 = *(_DWORD *)(a2 + 4 * v4);
for ( i = 0; i != 32; ++i )
{
if ( _bittest(&v6, i) )
{
v8 = (int)v5++;
*(_QWORD *)(a1 + 8 * v8) = (int)(i + 32 * v4);
}
}
++v4;
}
while ( a3 != v4 );
return v5;
}

original_code:
int eratosToArray(long dst[], int era[], int srcLength) {
 int bits = sizeof(int) * 8;
 int i, j, k = 0;
 for (i = 0; i < srcLength; i++) {
  for (j = 0; j < bits; j++) {
   if (((era[i] >> j) & 0x01) == 0x1) {
    dst[k++] = i * bits + j;
   }
  }
 }
 return k;
}

canonical_original_code:
int eratosToArray(long dst[], int era[], int srcLength) {
 int bits = sizeof(int) * 8;
 int i; int j; int k = 0;
 for (i = 0; i < srcLength; i++) {
  for (j = 0; j < bits; j++) {
   if (((era[i] >> j) & 0x01) == 0x1) {
    dst[k++] = i * bits + j;
   }
  }
 }
 return k;
}

variable_types:
dst
long []

variable_types:
era
int []

variable_types: srcLength int


reverseString

decompiled_code:
char *__fastcall reverseString(_BYTE *a1, const char *a2, int a3)
{
size_t v3; // rbp
char *v4; // rax
char *result; // rax
char *v6; // r8
char v7; // dl

v3 = a3;
v4 = (char *)malloc(a3 + 1);
v4[v3] = 0;
result = strncpy(v4, a2, v3);
if ( (int)v3 > 0 )
{
v6 = result;
result += (int)v3 - 1;
do
{
v7 = *result--;
*a1++ = v7;
}
while ( result != &v6[v3 - 2 - (unsigned int)(v3 - 1)] );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(_BYTE *a1, const char *a2, int a3)
{
size_t v3; // rbp
char *v4; // rax
char *result; // rax
char *v6; // r8
char v7; // dl

v3 = a3;
v4 = (char *)malloc(a3 + 1);
v4[v3] = 0;
result = strncpy(v4, a2, v3);
if ( (int)v3 > 0 )
{
v6 = result;
result += (int)v3 - 1;
do
{
v7 = *result--;
*a1++ = v7;
}
while ( result != &v6[v3 - 2 - (unsigned int)(v3 - 1)] );
}
return result;
}

original_code:
void reverseString(char *dst, char *src, int length) {
 int i, j;
 char *str = (char *)malloc(sizeof(char) * (length + 1));
 str[length] = 0;
 strncpy(str, src, length);
 for (i = 0, j = length - 1; i < length; i++, j--) dst[i] = str[j];
}

canonical_original_code:
void reverseString(char *dst, char *src, int length) {
 int i; int j;
 char *str = (char *)malloc(sizeof(char) * (length + 1));
 str[length] = 0;
 strncpy(str, src, length);
 for (i = 0, j = length - 1; i < length; i++, j--) dst[i] = str[j];
}

variable_types:
dst
char *

variable_types:
src
char *


myCheckUserBreak

repo: vrthra/qnial

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

result = (unsigned int)userbreakrequested;
if ( userbreakrequested )
{
userbreakrequested = 0;
result = 1LL;
}
return result;
}

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

result = (unsigned int)userbreakrequested;
if ( userbreakrequested )
{
userbreakrequested = 0;
result = 1LL;
}
return result;
}

original_code:
static int
myCheckUserBreak(int code)
{
  if (userbreakrequested) {
    userbreakrequested = 0;
    return 1;
  }
  return 0;
}

variable_types: code int


controlCcatch

decompiled_code:
void __fastcall controlCcatch(int a1)
{
signal(2, controlCcatch);
if ( a1 == 2 )
userbreakrequested = 1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
signal(2, controlCcatch);
if ( a1 == 2 )
userbreakrequested = 1;
}

original_code:
static void
controlCcatch(int signo)
{
  signal(2, controlCcatch);
  if (signo != 2)
    return;
  userbreakrequested = 1;
}

variable_types: signo int


CheckErr

decompiled_code:
__int64 __fastcall CheckErr(int status)
{
__int64 result; // rax
const char *v2; // r12
const char *v3; // rax

if ( (unsigned int)((__int64 (*)(void))NC_ErrorType)() == 5
|| (unsigned int)NC_ErrorType((unsigned int)status) == 3
|| (unsigned int)NC_ErrorType((unsigned int)status) == 7
|| (result = NC_ErrorType((unsigned int)status), (_DWORD)result == 2) )
{
v2 = (const char *)NC_ErrorMessage((unsigned int)status);
v3 = (const char *)NC_ErrorTypeName((unsigned int)status);
printf("Terminated with a %s: (%s)\n", v3, v2);
exit(status);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int status)
{
__int64 result; // rax
const char *v2; // r12
const char *v3; // rax

if ( (unsigned int)((__int64 (*)(void))NC_ErrorType)() == 5
|| (unsigned int)NC_ErrorType((unsigned int)status) == 3
|| (unsigned int)NC_ErrorType((unsigned int)status) == 7
|| (result = NC_ErrorType((unsigned int)status), (_DWORD)result == 2) )
{
v2 = (const char *)NC_ErrorMessage((unsigned int)status);
v3 = (const char *)NC_ErrorTypeName((unsigned int)status);
printf("Terminated with a %s: (%s)\n", v3, v2);
exit(status);
}
return result;
}

original_code:
static void
CheckErr(int theErr)
{
  if ((NC_ErrorType(theErr) == NC_TERMINATE) ||
      (NC_ErrorType(theErr) == NC_STARTUP_ERROR) ||
      (NC_ErrorType(theErr) == NC_INTERNAL_ERROR) ||
      (NC_ErrorType(theErr) == NC_FATAL)) {
    printf("Terminated with a %s: (%s)\n", NC_ErrorTypeName(theErr),
           NC_ErrorMessage(theErr));
    exit(theErr);
  }
  return;
}

variable_types: theErr int


myReadChar

decompiled_code:
int myReadChar()
{
return getchar();
}

canonical_decompiled_code:
int func3()
{
return getchar();
}

original_code:
static char
myReadChar(void *theArg)
{
  return (char) getchar();
}

variable_types:
theArg
void *

return_type: char


decompiled_code:
size_t print_syntax()
{
return fwrite(
"\n"
" SYNTAX: nial [Wsname] [(+|-)size Wssize] [-defs Filename] [-q] [-s] \n"
" [-b] [-m] [-d] [-h]\n"
"\n"
"Wsname \tThe named workspace is loaded instead of the clearws.nws file that\n"
"\tis normally entered or created on invocation. \n"
"\n"
"-size Wssize\tBegin with a workspace size of Wssize words. The \n"
"\t\tworkspace can expand if space is available.\n"
"\n"
"+size Wssize\tFix the workspace size at Wssize words. This option is\n"
"\t\tused when very large workspaces are needed.\n"
"\n"
"-defs Filename\tAfter loading the initial workspace and executing its\n"
"\t\tLatent expression, load the file Filename.ndf using loaddefs\n"
"\t\twithout displaying it.\n"
"\n"
"-q\tStart quietly without displaying the banner and other default output.\n"
"\n"
"-s\tSupress the triggering mechanism that interrupts computation\n"
"\twhenever a fault is created.\n"
"\n"
"-m Do not display warning messages about internal buffer size changes.\n"
"\n"
"-d Turn off debugging features (improves performance)\n"
"\n"
"-b\tUse normal ASCII characters for box diagrams. (PC versions only)\n"
"\n"
"-h Display command line syntax.\n"
"\n"
"\t Examples:\n"
"\tnial\n"
"\n"
"\tnial -q appl\n"
"\n"
"\tnial +size 500000 -defs newfns\n",
1uLL,
0x449uLL,
stderr);
}

canonical_decompiled_code:
size_t func5()
{
return fwrite(
"\n"
" SYNTAX: nial [Wsname] [(+|-)size Wssize] [-defs Filename] [-q] [-s] \n"
" [-b] [-m] [-d] [-h]\n"
"\n"
"Wsname \tThe named workspace is loaded instead of the clearws.nws file that\n"
"\tis normally entered or created on invocation. \n"
"\n"
"-size Wssize\tBegin with a workspace size of Wssize words. The \n"
"\t\tworkspace can expand if space is available.\n"
"\n"
"+size Wssize\tFix the workspace size at Wssize words. This option is\n"
"\t\tused when very large workspaces are needed.\n"
"\n"
"-defs Filename\tAfter loading the initial workspace and executing its\n"
"\t\tLatent expression, load the file Filename.ndf using loaddefs\n"
"\t\twithout displaying it.\n"
"\n"
"-q\tStart quietly without displaying the banner and other default output.\n"
"\n"
"-s\tSupress the triggering mechanism that interrupts computation\n"
"\twhenever a fault is created.\n"
"\n"
"-m Do not display warning messages about internal buffer size changes.\n"
"\n"
"-d Turn off debugging features (improves performance)\n"
"\n"
"-b\tUse normal ASCII characters for box diagrams. (PC versions only)\n"
"\n"
"-h Display command line syntax.\n"
"\n"
"\t Examples:\n"
"\tnial\n"
"\n"
"\tnial -q appl\n"
"\n"
"\tnial +size 500000 -defs newfns\n",
1uLL,
0x449uLL,
stderr);
}

original_code:
static void
print_syntax()
{
  fprintf(stderr, "\n"
  "   SYNTAX: nial [Wsname] [(+|-)size Wssize] [-defs Filename] [-q] [-s] \n"
          "               [-b] [-m] [-d] [-h]\n"
          "\n"
          "Wsname 	The named workspace is loaded instead of the clearws.nws file that\n"
          "	is normally entered or created on invocation. \n"
          "\n"
          "-size Wssize	Begin with a workspace size of Wssize words. The \n"
          "		workspace can expand if space is available.\n"
          "\n"
     "+size Wssize	Fix the workspace size at Wssize words. This option is\n"
          "		used when very large workspaces are needed.\n"
          "\n"
    "-defs Filename	After loading the initial workspace and executing its\n"
          "		Latent expression, load the file Filename.ndf using loaddefs\n"
          "		without displaying it.\n"
          "\n"
          "-q	Start quietly without displaying the banner and other default output.\n"
          "\n"
          "-s	Supress the triggering mechanism that interrupts computation\n"
          "	whenever a fault is created.\n"
          "\n"
          "-m      Do not display warning messages about internal buffer size changes.\n"
          "\n"
          "-d      Turn off debugging features (improves performance)\n"
          "\n"
     "-b	Use normal ASCII characters for box diagrams. (PC versions only)\n"
          "\n"
          "-h      Display command line syntax.\n"
          "\n"
          "	   Examples:\n"
          "	nial\n"
          "\n"
          "	nial -q appl\n"
          "\n"
          "	nial +size 500000 -defs newfns\n"
  );
}


myWrite

decompiled_code:
int __fastcall myWrite(__int64 a1, const char *a2)
{
printf("%s", a2);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, const char *a2)
{
printf("%s", a2);
return fflush(stdout);
}

original_code:
static void
myWrite(void *theArg, char *theStr)
{
  printf("%s", theStr);
  fflush(stdout);
}

variable_types:
theStr
char *


myReadInput

decompiled_code:
void myReadInput()
{
char *v0; // rbp
char *v1; // rdi
char *v2; // rax

inputline = 0;
while ( 1 )
{
v0 = myReadString(stdin);
v1 = v0;
if ( !*v0 )
break;
v2 = &v0[(int)(strlen(v0) - 1)];
if ( *v2 != 92 )
{
strcat(&inputline, v0);
v1 = v0;
break;
}
*v2 = 0;
strcat(&inputline, v0);
free(v0);
}
free(v1);
}

canonical_decompiled_code:
void func7()
{
char *v0; // rbp
char *v1; // rdi
char *v2; // rax

inputline = 0;
while ( 1 )
{
v0 = func4(stdin);
v1 = v0;
if ( !*v0 )
break;
v2 = &v0[(int)(strlen(v0) - 1)];
if ( *v2 != 92 )
{
strcat(&inputline, v0);
v1 = v0;
break;
}
*v2 = 0;
strcat(&inputline, v0);
free(v0);
}
free(v1);
}

original_code:
static void
myReadInput()
{
  int lastpos,
              cont = 1;
  inputline[0] = '\0';
  while (cont) {
    char *str = myReadString(stdin);
    if (strlen(str) > 0) {
      lastpos = strlen(str) - 1;
      if (str[lastpos] == '\\')
        str[lastpos] = '\0';
      else
        cont = 0;
      strcat(inputline, str);
    }
    else
      cont = 0;
    free(str);
  }
}

canonical_original_code:
static void myReadInput()
{
  int lastpos; int cont = 1;
  inputline[0] = '\0';
  while (cont) {
    char *str = myReadString(stdin);
    if (strlen(str) > 0) {
      lastpos = strlen(str) - 1;
      if (str[lastpos] == '\\')
        str[lastpos] = '\0';
      else
        cont = 0;
      strcat(inputline, str);
    }
    else
      cont = 0;
    free(str);
  }
}

variable_types: lastpos int

variable_types: cont int

variable_types:
str
char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er13
int v5; // ebp
__int64 v6; // rax
const char *v7; // r14
__int64 v8; // rdx
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rdx
int v12; // eax
int v13; // eax
int v14; // eax
int v15; // eax
int v16; // eax
int v17; // eax
int v18; // eax
int v19; // eax
int v20; // eax
int v21; // eax
int v22; // eax
int v23; // eax
int v24; // eax
int v25; // eax
char *v26; // rsi
__int64 v27; // rbp
const char *v28; // rsi
unsigned int v29; // ebp
int v30; // eax
int v31; // eax
int v32; // eax
const char *v33; // rsi
__int64 v34; // rax
__int64 v35; // rdx
const char *v36; // r12
const char *v37; // rax
int v38; // eax
int v39; // eax
char v40[512]; // [rsp+0h] [rbp-438h] BYREF
char dest[568]; // [rsp+200h] [rbp-238h] BYREF

v4 = 1;
*(_QWORD *)(&G1 + 12) = 0x100000000LL;
*(_QWORD *)(&G1 + 6980) = 0xFFFFFFFFLL;
*((_QWORD *)&G1 + 7) = 2000000LL;
*((_QWORD *)&G1 + 3) = 0LL;
*((_QWORD *)&G1 + 4) = 0LL;
*((_DWORD *)&G1 + 12) = 0;
*((_DWORD *)&G1 + 1562) = 1;
*(_QWORD *)(&G1 + 6260) = 1LL;
*((_DWORD *)&G1 + 1670) = 0;
global_argv = (__int64)argv;
global_argc = argc;
initunixsignals(argc, argv, envp);
if ( argc <= 1 )
{
LABEL_12:
v10 = NC_CreateSessionSettings();
v11 = *((unsigned int *)&G1 + 14);
sessionSettings = v10;
v12 = NC_SetSessionSetting(v10, 100LL, v11);
CheckErr(v12);
v13 = NC_SetSessionSetting(sessionSettings, 103LL, *((unsigned int *)&G1 + 4));
CheckErr(v13);
if ( *((_DWORD *)&G1 + 12) )
{
v39 = NC_SetSessionSetting(sessionSettings, 104LL, dest);
CheckErr(v39);
}
if ( *((_DWORD *)&G1 + 7) )
{
v38 = NC_SetSessionSetting(sessionSettings, 101LL, v40);
CheckErr(v38);
}
v14 = NC_SetSessionSetting(sessionSettings, 102LL, *((unsigned int *)&G1 + 3));
CheckErr(v14);
v15 = NC_SetSessionSetting(sessionSettings, 105LL, *((unsigned int *)&G1 + 1565));
CheckErr(v15);
v16 = NC_SetCheckUserBreak(sessionSettings, myCheckUserBreak);
CheckErr(v16);
windSettings = NC_CreateWindowSettings();
v17 = NC_SetWindowSetting(windSettings, 412LL, 79LL);
CheckErr(v17);
v18 = NC_SetWindowSetting(windSettings, 400LL, *((unsigned int *)&G1 + 1562));
CheckErr(v18);
v19 = NC_SetWindowSetting(windSettings, 401LL, *((unsigned int *)&G1 + 6));
CheckErr(v19);
v20 = NC_SetWindowSetting(windSettings, 404LL, v4);
CheckErr(v20);
v21 = NC_SetWindowSetting(windSettings, 407LL, 0LL);
CheckErr(v21);
theContext = NC_CreateIOContext();
v22 = NC_SetIOMode(theContext, 4LL);
CheckErr(v22);
v23 = NC_SetWriteCommand(theContext, myWrite, stdout);
CheckErr(v23);
v24 = NC_SetReadStringCommand(theContext, myReadString, stdin);
CheckErr(v24);
v25 = NC_SetReadCharCommand(theContext, myReadChar, stdin);
CheckErr(v25);
*(&G1 + 4376) = 0;
v26 = getenv("NIALROOT");
if ( v26 )
strcpy((char *)(unsigned int)((_DWORD)&G1 + 4376), v26);
signal(2, controlCcatch);
v27 = (unsigned int)NC_InitNial(sessionSettings, windSettings, theContext);
if ( (unsigned int)NC_ErrorType(v27) != 5 )
{
CheckErr(v27);
while ( 1 )
{
while ( 1 )
{
v28 = (const char *)NC_GetPrompt(windSettings);
myWrite((__int64)stdout, v28);
userbreakrequested = 0;
myReadInput();
if ( !(unsigned int)myCheckUserBreak(3LL) )
break;
cleanup_ws();
v34 = *((int *)&G1 + 1745);
if ( (_DWORD)v34 != -1 )
{
v35 = *((_QWORD *)&G1 + 772);
--*(_DWORD *)(v35 + 4 * v34 - 12);
if ( !*(_DWORD *)(v35 + 4LL * *((int *)&G1 + 1745) - 12) )
freeit(*((int *)&G1 + 1745));
}
*((_DWORD *)&G1 + 1745) = -1;
userbreakrequested = 0;
}
if ( EOFsignalled )
break;
v29 = NC_CommandInterpret(&inputline, windSettings, theContext);
if ( (unsigned int)myCheckUserBreak(1LL) )
{
cleanup_ws();
userbreakrequested = 0;
}
else
{
if ( (unsigned int)NC_ErrorType(v29) != 1
&& (unsigned int)NC_ErrorType(v29) != 6
&& (unsigned int)NC_ErrorType(v29) != 4
&& (unsigned int)NC_ErrorType(v29) != 5 )
{
v36 = (const char *)NC_ErrorMessage(v29);
v37 = (const char *)NC_ErrorTypeName(v29);
printf("Return Code: %s ErrorTypeName : %s\n", v37, v36);
}
if ( (unsigned int)NC_ErrorType(v29) != 6
&& (unsigned int)NC_ErrorType(v29) != 1
&& (unsigned int)NC_ErrorType(v29) != 4 )
{
break;
}
}
}
NC_StopNial();
v30 = NC_DestroyIOContext(theContext);
CheckErr(v30);
v31 = NC_DestroyWindowSettings(windSettings);
CheckErr(v31);
v32 = NC_DestroySessionSettings(sessionSettings);
CheckErr(v32);
}
exit(0);
}
v5 = 1;
while ( 1 )
{
while ( 1 )
{
v7 = argv[v5];
v8 = v5;
if ( !strcmp(v7, "-size") )
{
v6 = atol(argv[v8 + 1]);
*((_DWORD *)&G1 + 4) = 1;
if ( v6 < 60000 )
v6 = 60000LL;
v5 += 2;
*((_QWORD *)&G1 + 7) = v6;
goto LABEL_6;
}
if ( strcmp(argv[v5], "+size") )
break;
v9 = atol(argv[v8 + 1]);
*((_DWORD *)&G1 + 4) = 0;
if ( v9 < 60000 )
v9 = 60000LL;
v5 += 2;
*((_QWORD *)&G1 + 7) = v9;
if ( v5 >= argc )
goto LABEL_12;
}
if ( !strcmp(argv[v5], "-defs") )
{
v33 = argv[v8 + 1];
v5 += 2;
*((_DWORD *)&G1 + 7) = 1;
strcpy(v40, v33);
}
else
{
if ( *v7 != 45 )
goto LABEL_35;
if ( v7[1] != 113 || v7[2] )
{
if ( v7[1] != 109 || v7[2] )
{
LABEL_35:
if ( !strcmp(argv[v5], "-d") )
{
*((_DWORD *)&G1 + 1565) = 0;
++v5;
}
else if ( !strcmp(v7, "-s") )
{
*((_DWORD *)&G1 + 1562) = 0;
++v5;
}
else
{
if ( !strcmp(v7, "-h") )
{
print_syntax();
exit(1);
}
if ( *v7 == 45 )
{
printf("invalid command line option: %s", v7);
exit(1);
}
++v5;
*((_DWORD *)&G1 + 12) = 1;
strcpy(dest, v7);
}
goto LABEL_6;
}
++v5;
v4 = 0;
}
else
{
*((_DWORD *)&G1 + 3) = 1;
++v5;
}
}
LABEL_6:
if ( v5 >= argc )
goto LABEL_12;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er13
int v5; // ebp
__int64 v6; // rax
const char *v7; // r14
__int64 v8; // rdx
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rdx
int v12; // eax
int v13; // eax
int v14; // eax
int v15; // eax
int v16; // eax
int v17; // eax
int v18; // eax
int v19; // eax
int v20; // eax
int v21; // eax
int v22; // eax
int v23; // eax
int v24; // eax
int v25; // eax
char *v26; // rsi
__int64 v27; // rbp
const char *v28; // rsi
unsigned int v29; // ebp
int v30; // eax
int v31; // eax
int v32; // eax
const char *v33; // rsi
__int64 v34; // rax
__int64 v35; // rdx
const char *v36; // r12
const char *v37; // rax
int v38; // eax
int v39; // eax
char v40[512]; // [rsp+0h] [rbp-438h] BYREF
char dest[568]; // [rsp+200h] [rbp-238h] BYREF

v4 = 1;
*(_QWORD *)(&G1 + 12) = 0x100000000LL;
*(_QWORD *)(&G1 + 6980) = 0xFFFFFFFFLL;
*((_QWORD *)&G1 + 7) = 2000000LL;
*((_QWORD *)&G1 + 3) = 0LL;
*((_QWORD *)&G1 + 4) = 0LL;
*((_DWORD *)&G1 + 12) = 0;
*((_DWORD *)&G1 + 1562) = 1;
*(_QWORD *)(&G1 + 6260) = 1LL;
*((_DWORD *)&G1 + 1670) = 0;
global_argv = (__int64)argv;
global_argc = argc;
initunixsignals(argc, argv, envp);
if ( argc <= 1 )
{
LABEL_12:
v10 = NC_CreateSessionSettings();
v11 = *((unsigned int *)&G1 + 14);
sessionSettings = v10;
v12 = NC_SetSessionSetting(v10, 100LL, v11);
func2(v12);
v13 = NC_SetSessionSetting(sessionSettings, 103LL, *((unsigned int *)&G1 + 4));
func2(v13);
if ( *((_DWORD *)&G1 + 12) )
{
v39 = NC_SetSessionSetting(sessionSettings, 104LL, dest);
func2(v39);
}
if ( *((_DWORD *)&G1 + 7) )
{
v38 = NC_SetSessionSetting(sessionSettings, 101LL, v40);
func2(v38);
}
v14 = NC_SetSessionSetting(sessionSettings, 102LL, *((unsigned int *)&G1 + 3));
func2(v14);
v15 = NC_SetSessionSetting(sessionSettings, 105LL, *((unsigned int *)&G1 + 1565));
func2(v15);
v16 = NC_SetCheckUserBreak(sessionSettings, myCheckUserBreak);
func2(v16);
windSettings = NC_CreateWindowSettings();
v17 = NC_SetWindowSetting(windSettings, 412LL, 79LL);
func2(v17);
v18 = NC_SetWindowSetting(windSettings, 400LL, *((unsigned int *)&G1 + 1562));
func2(v18);
v19 = NC_SetWindowSetting(windSettings, 401LL, *((unsigned int *)&G1 + 6));
func2(v19);
v20 = NC_SetWindowSetting(windSettings, 404LL, v4);
func2(v20);
v21 = NC_SetWindowSetting(windSettings, 407LL, 0LL);
func2(v21);
theContext = NC_CreateIOContext();
v22 = NC_SetIOMode(theContext, 4LL);
func2(v22);
v23 = NC_SetWriteCommand(theContext, myWrite, stdout);
func2(v23);
v24 = NC_SetReadStringCommand(theContext, myReadString, stdin);
func2(v24);
v25 = NC_SetReadCharCommand(theContext, myReadChar, stdin);
func2(v25);
*(&G1 + 4376) = 0;
v26 = getenv("NIALROOT");
if ( v26 )
strcpy((char *)(unsigned int)((_DWORD)&G1 + 4376), v26);
signal(2, controlCcatch);
v27 = (unsigned int)NC_InitNial(sessionSettings, windSettings, theContext);
if ( (unsigned int)NC_ErrorType(v27) != 5 )
{
func2(v27);
while ( 1 )
{
while ( 1 )
{
v28 = (const char *)NC_GetPrompt(windSettings);
func6((__int64)stdout, v28);
userbreakrequested = 0;
func7();
if ( !(unsigned int)func0(3LL) )
break;
cleanup_ws();
v34 = *((int *)&G1 + 1745);
if ( (_DWORD)v34 != -1 )
{
v35 = *((_QWORD *)&G1 + 772);
--*(_DWORD *)(v35 + 4 * v34 - 12);
if ( !*(_DWORD *)(v35 + 4LL * *((int *)&G1 + 1745) - 12) )
freeit(*((int *)&G1 + 1745));
}
*((_DWORD *)&G1 + 1745) = -1;
userbreakrequested = 0;
}
if ( EOFsignalled )
break;
v29 = NC_CommandInterpret(&inputline, windSettings, theContext);
if ( (unsigned int)func0(1LL) )
{
cleanup_ws();
userbreakrequested = 0;
}
else
{
if ( (unsigned int)NC_ErrorType(v29) != 1
&& (unsigned int)NC_ErrorType(v29) != 6
&& (unsigned int)NC_ErrorType(v29) != 4
&& (unsigned int)NC_ErrorType(v29) != 5 )
{
v36 = (const char *)NC_ErrorMessage(v29);
v37 = (const char *)NC_ErrorTypeName(v29);
printf("Return Code: %s ErrorTypeName : %s\n", v37, v36);
}
if ( (unsigned int)NC_ErrorType(v29) != 6
&& (unsigned int)NC_ErrorType(v29) != 1
&& (unsigned int)NC_ErrorType(v29) != 4 )
{
break;
}
}
}
NC_StopNial();
v30 = NC_DestroyIOContext(theContext);
func2(v30);
v31 = NC_DestroyWindowSettings(windSettings);
func2(v31);
v32 = NC_DestroySessionSettings(sessionSettings);
func2(v32);
}
exit(0);
}
v5 = 1;
while ( 1 )
{
while ( 1 )
{
v7 = argv[v5];
v8 = v5;
if ( !strcmp(v7, "-size") )
{
v6 = atol(argv[v8 + 1]);
*((_DWORD *)&G1 + 4) = 1;
if ( v6 < 60000 )
v6 = 60000LL;
v5 += 2;
*((_QWORD *)&G1 + 7) = v6;
goto LABEL_6;
}
if ( strcmp(argv[v5], "+size") )
break;
v9 = atol(argv[v8 + 1]);
*((_DWORD *)&G1 + 4) = 0;
if ( v9 < 60000 )
v9 = 60000LL;
v5 += 2;
*((_QWORD *)&G1 + 7) = v9;
if ( v5 >= argc )
goto LABEL_12;
}
if ( !strcmp(argv[v5], "-defs") )
{
v33 = argv[v8 + 1];
v5 += 2;
*((_DWORD *)&G1 + 7) = 1;
strcpy(v40, v33);
}
else
{
if ( *v7 != 45 )
goto LABEL_35;
if ( v7[1] != 113 || v7[2] )
{
if ( v7[1] != 109 || v7[2] )
{
LABEL_35:
if ( !strcmp(argv[v5], "-d") )
{
*((_DWORD *)&G1 + 1565) = 0;
++v5;
}
else if ( !strcmp(v7, "-s") )
{
*((_DWORD *)&G1 + 1562) = 0;
++v5;
}
else
{
if ( !strcmp(v7, "-h") )
{
func5();
exit(1);
}
if ( *v7 == 45 )
{
printf("invalid command line option: %s", v7);
exit(1);
}
++v5;
*((_DWORD *)&G1 + 12) = 1;
strcpy(dest, v7);
}
goto LABEL_6;
}
++v5;
v4 = 0;
}
else
{
*((_DWORD *)&G1 + 3) = 1;
++v5;
}
}
LABEL_6:
if ( v5 >= argc )
goto LABEL_12;
}
}

original_code:
int
main(int argc, char *memin[])
{
  int i,
              rc;
  int irc;
  int messages = 1,
              box_chars = 0;
  char indefsfnm[512],
              inloadfnm[512];
  G1.g_defssw = 0;
  G1.g_defsfnm = ((void *)0);
  G1.g_initmemsize = 2000000;
  G1.g_quiet = 0;
  G1.g_expansion = 1;
  G1.g_quiet = 0;
  G1.g_nouserinterrupts = 0;
  G1.g_loadsw = 0;
  G1.g_triggered = 1;
  G1.g_debugging_on = 1;
  G1.g_diag_messages_on = 0;
  G1.g_interpreter_running = 0;
  G1.g_lasteval = -1;
  G1.g_profile = 0;
  global_argv = memin;
  global_argc = argc;
  if (iscgiversion) {
    G1.g_quiet = 1;
    messages = 0;
    box_chars = 0;
    G1.g_triggered = 0;
    G1.g_nouserinterrupts = 1;
  }
  initunixsignals();
  if (iscgiversion)
  {
    if (argc >= 2)
    { int offset = (memin[1][0] == '\"') ? -1 : 0;
      if (strncasecmp((strlen(memin[1]) +
           memin[1] - 4 + offset), ".NDF", 4) == 0)
      {
        G1.g_defssw = 1;
        strcpy(indefsfnm, memin[1]);
      }
      else
      if (strncasecmp((strlen(memin[1]) +
           memin[1] - 4 + offset), ".NWS", 4) == 0)
      {
        G1.g_loadsw = 1;
        strcpy(inloadfnm, memin[1]);
      }
    }
  }
  else
  { i = 1;
    while (i < argc) {
      if (strcmp(memin[i], "-size") == 0) {
        G1.g_initmemsize = atol(memin[i + 1]);
        if (G1.g_initmemsize < (10000 * 4 + 20000))
          G1.g_initmemsize = (10000 * 4 + 20000);
        G1.g_expansion = 1;
        i += 2;
      }
      else if (strcmp(memin[i], "+size") == 0) {
        G1.g_initmemsize = atol(memin[i + 1]);
        if (G1.g_initmemsize < (10000 * 4 + 20000))
          G1.g_initmemsize = (10000 * 4 + 20000);
        G1.g_expansion = 0;
        i += 2;
      }
      else
      if (strcmp(memin[i], "-defs") == 0) {
        if (i < argc) {
          G1.g_defssw = 1;
          strcpy(indefsfnm, memin[i + 1]);
          i += 2;
        }
        else {
          printf("missing definition file name after -defs option\n");
          exit(1);
        }
      }
      else if (strcmp(memin[i], "-q") == 0) {
        G1.g_quiet = 1;
        i++;
      }
      else if (strcmp(memin[i], "-m") == 0) {
        messages = 0;
        i++;
      }
      else if (strcmp(memin[i], "-d") == 0) {
        G1.g_debugging_on = 0;
        i++;
      }
      else
      if (strcmp(memin[i], "-s") == 0) {
        G1.g_triggered = 0;
        i++;
      }
      else if (strcmp(memin[i], "-h") == 0) {
        print_syntax();
        exit(1);
      }
      else if (memin[i][0] == '-') {
        printf("invalid command line option: %s", memin[i]);
        exit(1);
      }
      else {
        G1.g_loadsw = 1;
        strcpy(inloadfnm, memin[i]);
        i++;
      }
    }
  }
  sessionSettings = NC_CreateSessionSettings();
  CheckErr(NC_SetSessionSetting(sessionSettings,
                                NC_WORKSPACE_SIZE, G1.g_initmemsize));
  CheckErr(NC_SetSessionSetting(sessionSettings,
                                NC_EXPANSION, G1.g_expansion));
  if (G1.g_loadsw)
    CheckErr(NC_SetSessionSetting(sessionSettings,
                                  NC_INITIAL_WORKSPACE, (int) inloadfnm));
  if (G1.g_defssw)
    CheckErr(NC_SetSessionSetting(sessionSettings,
                                  NC_INITIAL_DEFS, (int) indefsfnm));
  CheckErr(NC_SetSessionSetting(sessionSettings,
                                NC_QUIET, G1.g_quiet));
  CheckErr(NC_SetSessionSetting(sessionSettings, NC_DEBUGGING_ON, G1.g_debugging_on));
  CheckErr(NC_SetCheckUserBreak(sessionSettings, myCheckUserBreak));
  windSettings = NC_CreateWindowSettings();
  if (iscgiversion)
    CheckErr(NC_SetWindowSetting(windSettings, NC_PROMPT, (int) ""));
  CheckErr(NC_SetWindowSetting(windSettings, NC_SCREEN_WIDTH, (iscgiversion ? 0 : 79)));
  CheckErr(NC_SetWindowSetting(windSettings, NC_TRIGGERED, G1.g_triggered));
  CheckErr(NC_SetWindowSetting(windSettings, NC_NOUSERINTERRUPTS, G1.g_nouserinterrupts));
  CheckErr(NC_SetWindowSetting(windSettings, NC_MESSAGES, messages));
  CheckErr(NC_SetWindowSetting(windSettings, NC_BOX_CHARS, box_chars));
  theContext = NC_CreateIOContext();
  CheckErr(NC_SetIOMode(theContext, NC_IO_MODE));
  CheckErr(NC_SetWriteCommand(theContext, myWrite, stdout));
  CheckErr(NC_SetReadStringCommand(theContext, myReadString, stdin));
  CheckErr(NC_SetReadCharCommand(theContext, myReadChar, stdin));
  {
    char *nroot;
    G1.g_nialrootname[0] = '\0';
    nroot = getenv("NIALROOT");
    if (nroot != ((void *)0))
      strcpy(G1.g_nialrootname, nroot);
  }
  signal(2, controlCcatch);
  irc = NC_InitNial(sessionSettings, windSettings, theContext);
  if ((NC_ErrorType(irc) == NC_TERMINATE))
  {
     exit(0);
  }
  else
  {
    CheckErr(irc);
  }
  do {
retry:
    myWrite(stdout, NC_GetPrompt(windSettings));
    userbreakrequested = 0;
    awaitinginput = 1;
    myReadInput();
    if (myCheckUserBreak(NC_CS_INPUT)) {
      cleanup_ws();
      if (G1.g_lasteval != -1) {
        G1.g_mem[G1.g_lasteval-3]--;
        { nialptr _y_ = G1.g_lasteval; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
      }
      G1.g_lasteval = (-1);
      userbreakrequested = 0;
      goto retry;
    }
    if (EOFsignalled)
    {
      goto cleanup;
    }
    awaitinginput = 0;
    rc = NC_CommandInterpret(inputline, windSettings, theContext);
    if (myCheckUserBreak(NC_CS_NORMAL)) {
      cleanup_ws();
      userbreakrequested = 0;
      goto retry;
    }
    if (!((NC_ErrorType(rc) == NC_NORMAL) || (NC_ErrorType(rc) == NC_WARNING)
          || (NC_ErrorType(rc) == NC_BREAK) || (NC_ErrorType(rc) == NC_TERMINATE))) {
      printf("Return Code: %s ErrorTypeName : %s\n", NC_ErrorTypeName(rc),
             NC_ErrorMessage(rc));
    }
  } while ((NC_ErrorType(rc) == NC_WARNING) || (NC_ErrorType(rc) == NC_NORMAL) || (NC_ErrorType(rc) == NC_BREAK));
cleanup:
  NC_StopNial();
  CheckErr(NC_DestroyIOContext(theContext));
  CheckErr(NC_DestroyWindowSettings(windSettings));
  CheckErr(NC_DestroySessionSettings(sessionSettings));
  exit(0);
  return 1;
}

canonical_original_code:
int main(int argc, char *memin[])
{
  int i; int rc;
  int irc;
  int messages = 1; int box_chars = 0;
  char indefsfnm[512]; char inloadfnm[512];
  G1.g_defssw = 0;
  G1.g_defsfnm = ((void *)0);
  G1.g_initmemsize = 2000000;
  G1.g_quiet = 0;
  G1.g_expansion = 1;
  G1.g_quiet = 0;
  G1.g_nouserinterrupts = 0;
  G1.g_loadsw = 0;
  G1.g_triggered = 1;
  G1.g_debugging_on = 1;
  G1.g_diag_messages_on = 0;
  G1.g_interpreter_running = 0;
  G1.g_lasteval = -1;
  G1.g_profile = 0;
  global_argv = memin;
  global_argc = argc;
  if (iscgiversion) {
    G1.g_quiet = 1;
    messages = 0;
    box_chars = 0;
    G1.g_triggered = 0;
    G1.g_nouserinterrupts = 1;
  }
  initunixsignals();
  if (iscgiversion)
  {
    if (argc >= 2)
    { int offset = (memin[1][0] == '\"') ? -1 : 0;
      if (strncasecmp((strlen(memin[1]) +
           memin[1] - 4 + offset), ".NDF", 4) == 0)
      {
        G1.g_defssw = 1;
        strcpy(indefsfnm, memin[1]);
      }
      else
      if (strncasecmp((strlen(memin[1]) +
           memin[1] - 4 + offset), ".NWS", 4) == 0)
      {
        G1.g_loadsw = 1;
        strcpy(inloadfnm, memin[1]);
      }
    }
  }
  else
  { i = 1;
    while (i < argc) {
      if (strcmp(memin[i], "-size") == 0) {
        G1.g_initmemsize = atol(memin[i + 1]);
        if (G1.g_initmemsize < (10000 * 4 + 20000))
          G1.g_initmemsize = (10000 * 4 + 20000);
        G1.g_expansion = 1;
        i += 2;
      }
      else if (strcmp(memin[i], "+size") == 0) {
        G1.g_initmemsize = atol(memin[i + 1]);
        if (G1.g_initmemsize < (10000 * 4 + 20000))
          G1.g_initmemsize = (10000 * 4 + 20000);
        G1.g_expansion = 0;
        i += 2;
      }
      else
      if (strcmp(memin[i], "-defs") == 0) {
        if (i < argc) {
          G1.g_defssw = 1;
          strcpy(indefsfnm, memin[i + 1]);
          i += 2;
        }
        else {
          printf("missing definition file name after -defs option\n");
          exit(1);
        }
      }
      else if (strcmp(memin[i], "-q") == 0) {
        G1.g_quiet = 1;
        i++;
      }
      else if (strcmp(memin[i], "-m") == 0) {
        messages = 0;
        i++;
      }
      else if (strcmp(memin[i], "-d") == 0) {
        G1.g_debugging_on = 0;
        i++;
      }
      else
      if (strcmp(memin[i], "-s") == 0) {
        G1.g_triggered = 0;
        i++;
      }
      else if (strcmp(memin[i], "-h") == 0) {
        print_syntax();
        exit(1);
      }
      else if (memin[i][0] == '-') {
        printf("invalid command line option: %s", memin[i]);
        exit(1);
      }
      else {
        G1.g_loadsw = 1;
        strcpy(inloadfnm, memin[i]);
        i++;
      }
    }
  }
  sessionSettings = NC_CreateSessionSettings();
  CheckErr(NC_SetSessionSetting(sessionSettings,
                                NC_WORKSPACE_SIZE, G1.g_initmemsize));
  CheckErr(NC_SetSessionSetting(sessionSettings,
                                NC_EXPANSION, G1.g_expansion));
  if (G1.g_loadsw)
    CheckErr(NC_SetSessionSetting(sessionSettings,
                                  NC_INITIAL_WORKSPACE, (int) inloadfnm));
  if (G1.g_defssw)
    CheckErr(NC_SetSessionSetting(sessionSettings,
                                  NC_INITIAL_DEFS, (int) indefsfnm));
  CheckErr(NC_SetSessionSetting(sessionSettings,
                                NC_QUIET, G1.g_quiet));
  CheckErr(NC_SetSessionSetting(sessionSettings, NC_DEBUGGING_ON, G1.g_debugging_on));
  CheckErr(NC_SetCheckUserBreak(sessionSettings, myCheckUserBreak));
  windSettings = NC_CreateWindowSettings();
  if (iscgiversion)
    CheckErr(NC_SetWindowSetting(windSettings, NC_PROMPT, (int) ""));
  CheckErr(NC_SetWindowSetting(windSettings, NC_SCREEN_WIDTH, (iscgiversion ? 0 : 79)));
  CheckErr(NC_SetWindowSetting(windSettings, NC_TRIGGERED, G1.g_triggered));
  CheckErr(NC_SetWindowSetting(windSettings, NC_NOUSERINTERRUPTS, G1.g_nouserinterrupts));
  CheckErr(NC_SetWindowSetting(windSettings, NC_MESSAGES, messages));
  CheckErr(NC_SetWindowSetting(windSettings, NC_BOX_CHARS, box_chars));
  theContext = NC_CreateIOContext();
  CheckErr(NC_SetIOMode(theContext, NC_IO_MODE));
  CheckErr(NC_SetWriteCommand(theContext, myWrite, stdout));
  CheckErr(NC_SetReadStringCommand(theContext, myReadString, stdin));
  CheckErr(NC_SetReadCharCommand(theContext, myReadChar, stdin));
  {
    char *nroot;
    G1.g_nialrootname[0] = '\0';
    nroot = getenv("NIALROOT");
    if (nroot != ((void *)0))
      strcpy(G1.g_nialrootname, nroot);
  }
  signal(2, controlCcatch);
  irc = NC_InitNial(sessionSettings, windSettings, theContext);
  if ((NC_ErrorType(irc) == NC_TERMINATE))
  {
     exit(0);
  }
  else
  {
    CheckErr(irc);
  }
  do {
retry:
    myWrite(stdout, NC_GetPrompt(windSettings));
    userbreakrequested = 0;
    awaitinginput = 1;
    myReadInput();
    if (myCheckUserBreak(NC_CS_INPUT)) {
      cleanup_ws();
      if (G1.g_lasteval != -1) {
        G1.g_mem[G1.g_lasteval-3]--;
        { int _y_ = G1.g_lasteval; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
      }
      G1.g_lasteval = (-1);
      userbreakrequested = 0;
      goto retry;
    }
    if (EOFsignalled)
    {
      goto cleanup;
    }
    awaitinginput = 0;
    rc = NC_CommandInterpret(inputline, windSettings, theContext);
    if (myCheckUserBreak(NC_CS_NORMAL)) {
      cleanup_ws();
      userbreakrequested = 0;
      goto retry;
    }
    if (!((NC_ErrorType(rc) == NC_NORMAL) || (NC_ErrorType(rc) == NC_WARNING)
          || (NC_ErrorType(rc) == NC_BREAK) || (NC_ErrorType(rc) == NC_TERMINATE))) {
      printf("Return Code: %s ErrorTypeName : %s\n", NC_ErrorTypeName(rc),
             NC_ErrorMessage(rc));
    }
  } while ((NC_ErrorType(rc) == NC_WARNING) || (NC_ErrorType(rc) == NC_NORMAL) || (NC_ErrorType(rc) == NC_BREAK));
cleanup:
  NC_StopNial();
  CheckErr(NC_DestroyIOContext(theContext));
  CheckErr(NC_DestroyWindowSettings(windSettings));
  CheckErr(NC_DestroySessionSettings(sessionSettings));
  exit(0);
  return 1;
}

variable_types: argc int

variable_types:
memin
char *[]

variable_types: i int

variable_types: rc int

variable_types: irc int

variable_types: messages int

variable_types:
indefsfnm
char [512]

variable_types:
inloadfnm
char [512]

variable_types: offset int

variable_types:
nroot
char *


restoresignals

decompiled_code:
__sighandler_t restoresignals()
{
int i; // ebx
int v1; // edi
__sighandler_t result; // rax

for ( i = 0; i != 65; ++i )
{
v1 = i;
result = signal(v1, 0LL);
}
return result;
}

canonical_decompiled_code:
__sighandler_t func0()
{
int i; // ebx
int v1; // edi
__sighandler_t result; // rax

for ( i = 0; i != 65; ++i )
{
v1 = i;
result = signal(v1, 0LL);
}
return result;
}

original_code:
static void
restoresignals()
{
  int i;
  for (i = 0; i < (64 + 1); i++)
    signal(i, ((__sighandler_t) 0));
}

canonical_original_code:
static void restoresignals()
{
  int i;
  for (i = 0; i < (64 + 1); i++)
    signal(i, ((void (*)(int)) 0));
}


fpehandler

decompiled_code:
void fpehandler()
{
signal(8, fpehandler);
fp_exception = 1;
}

canonical_decompiled_code:
void func1()
{
signal(8, fpehandler);
fp_exception = 1;
}

original_code:
static void
fpehandler(int signo)
{
  signal(8, fpehandler);
  fp_exception = 1;
  fp_type = 3456;
}

variable_types: signo int


decompiled_code:
void nial_suspend()
{
__pid_t v0; // eax

fflush(stdout);
v0 = getpid();
kill(v0, 19);
}

canonical_decompiled_code:
void func2()
{
__pid_t v0; // eax

fflush(stdout);
v0 = getpid();
kill(v0, 19);
}

original_code:
void
nial_suspend(int signo)
{
  fflush(stdout);
  kill(getpid(), 19);
}


decompiled_code:
char *__fastcall get_tstamp(char *dest)
{
char *v1; // rax
char *result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = ctime(&timer);
result = strcpy(dest, v1);
dest[24] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *dest)
{
char *v1; // rax
char *result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = ctime(&timer);
result = strcpy(dest, v1);
dest[24] = 0;
return result;
}

original_code:
void
get_tstamp(char *timebuf)
{
  long etime;
  char *timestring;
  time(&etime);
  timestring = ctime(&etime);
  strcpy(timebuf, timestring);
  timebuf[24] = '\0';
}

variable_types:
timebuf
char *

variable_types: etime long

variable_types:
timestring
char *


original_code:
double
get_cputime()
{
  struct tms structtime;
  double total;
  times(&structtime);
  total = (floor((structtime.tms_stime + structtime.tms_utime) * 1000. / 100)
           / 1000.) - sttime;
  return (total);
}

variable_types: struct tms { long tms_utime; long tms_stime; long tms_cutime; long tms_cstime; }

variable_types: total double

return_type: double


inittime

decompiled_code:
void inittime()
{
sttime = 0LL;
sttime = get_cputime();
}

canonical_decompiled_code:
void func10()
{
sttime = 0LL;
sttime = func9();
}

original_code:
void
inittime()
{
  sttime = 0.;
  sttime = get_cputime();
}


decompiled_code:
char *__fastcall setup_nialroot(_BYTE *a1)
{
char *result; // rax

*a1 = 0;
result = getenv("NIALROOT");
if ( result )
{
result = stpcpy((char *)(unsigned int)((_DWORD)&G1 + 4376), result);
if ( result != &G1 + 4376 && *(result - 1) != 47 )
*(_WORD *)result = 47;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(_BYTE *a1)
{
char *result; // rax

*a1 = 0;
result = getenv("NIALROOT");
if ( result )
{
result = stpcpy((char *)(unsigned int)((_DWORD)&G1 + 4376), result);
if ( result != &G1 + 4376 && *(result - 1) != 47 )
*(_WORD *)result = 47;
}
return result;
}

original_code:
void
setup_nialroot(char *nialroot)
{
  char *nroot;
  nialroot[0] = '\0';
  nroot = getenv("NIALROOT");
  if (nroot != ((void *)0)) {
    strcpy(G1.g_nialrootname, nroot);
    if ((int) strlen(G1.g_nialrootname) > 0)
      if (G1.g_nialrootname[strlen(G1.g_nialrootname)-1] != '/')
        strcat(G1.g_nialrootname, "/");
  }
}

variable_types:
nialroot
char *


initunixsignals

decompiled_code:
__sighandler_t initunixsignals()
{
signal(21, 0LL);
signal(22, 0LL);
signal(19, 0LL);
signal(20, (__sighandler_t)nial_suspend);
return signal(3, handler);
}

canonical_decompiled_code:
__sighandler_t func12()
{
signal(21, 0LL);
signal(22, 0LL);
signal(19, 0LL);
signal(20, (__sighandler_t)nial_suspend);
return signal(3, handler);
}

original_code:
void
initunixsignals()
{
  signal(21, ((__sighandler_t) 0));
  signal(22, ((__sighandler_t) 0));
  signal(19, ((__sighandler_t) 0));
  signal(20, nial_suspend);
  signal(3, ((__sighandler_t) 1));
}

canonical_original_code:
void initunixsignals()
{
  signal(21, ((void (*)(int)) 0));
  signal(22, ((void (*)(int)) 0));
  signal(19, ((void (*)(int)) 0));
  signal(20, nial_suspend);
  signal(3, ((void (*)(int)) 1));
}


command

decompiled_code:
__int64 __fastcall command(char *a1)
{
int *v1; // rax
int *v2; // rbx
unsigned int v3; // er12

v1 = _errno_location();
*v1 = 0;
v2 = v1;
restoresignals();
v3 = system(a1);
if ( v3 )
{
if ( *v2 )
*((_QWORD *)&G1 + 643) = strerror(*v2);
else
*((_QWORD *)&G1 + 643) = "command failed";
}
initunixsignals();
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1)
{
int *v1; // rax
int *v2; // rbx
unsigned int v3; // er12

v1 = _errno_location();
*v1 = 0;
v2 = v1;
func0();
v3 = system(a1);
if ( v3 )
{
if ( *v2 )
*((_QWORD *)&G1 + 643) = strerror(*v2);
else
*((_QWORD *)&G1 + 643) = "command failed";
}
func12();
return v3;
}

original_code:
int
command(char *string)
{
  int res;
  (*__errno_location ()) = 0;
  restoresignals();
  if ((res = system(string)) != 0) {
    if ((*__errno_location ()) == 0)
      G1.g_errmsgptr = "command failed";
    else
      G1.g_errmsgptr = strerror((*__errno_location ()));
  }
  initunixsignals();
  return (res);
}

variable_types:
string
char *

variable_types: res int


calleditor

decompiled_code:
__int64 __fastcall calleditor(char *src)
{
char *v1; // rsi
char *v2; // rax
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = getenv("EDITOR");
if ( !v1 )
v1 = "vi";
v2 = stpcpy(v4, v1);
*v2 = 32;
strcpy(v2 + 1, src);
return command(v4);
}

canonical_decompiled_code:
__int64 __fastcall func14(char *src)
{
char *v1; // rsi
char *v2; // rax
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = getenv("EDITOR");
if ( !v1 )
v1 = "vi";
v2 = stpcpy(v4, v1);
*v2 = 32;
strcpy(v2 + 1, src);
return func13(v4);
}

original_code:
void
calleditor(char *flnm)
{
  char *editor;
  char editormsg[80];
  editor = getenv("EDITOR");
  if (editor == ((void *)0))
    editor = "vi";
  strcpy(editormsg, editor);
  strcat(editormsg, " ");
  strcat(editormsg, flnm);
  command(editormsg);
}

variable_types:
flnm
char *

variable_types:
editor
char *

variable_types:
editormsg
char [80]


initfpsignal

decompiled_code:
__sighandler_t initfpsignal()
{
return signal(8, (__sighandler_t)fpehandler);
}

canonical_decompiled_code:
__sighandler_t func15()
{
return signal(8, (__sighandler_t)fpehandler);
}

original_code:
void
initfpsignal()
{
  signal(8, fpehandler);
}


decompiled_code:
__int64 fp_checksignal()
{
if ( fp_exception )
{
fp_exception = 0;
exit_cover(39LL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func16()
{
if ( fp_exception )
{
fp_exception = 0;
exit_cover(39LL);
}
return 0LL;
}

original_code:
int
fp_checksignal()
{
  if (fp_exception) {
    fp_exception = 0;
    exit_cover(NC_FLOAT_EXCEPTION_W);
  }
  return 0;
}


isleep

original_code:
void
isleep(void)
{ nialptr x;
  x = (G1.g_topstack==(-1) ? stackempty() : (G1.g__x_ = G1.g_stkarea[G1.g_topstack], G1.g_stkarea[G1.g_topstack--] = (nialptr)(-1), G1.g_mem[G1.g__x_-3]--, G1.g__x_));
  if ((((*(struct skv *) &G1.g_mem[x-2])).sk[1])!=3)
  { { register nialptr _y_ = makefault("arg to sleep not an integer"); if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
  }
  else
  { int n = (*((nialint *)&G1.g_mem[x]));
    sleep(n);
    { register nialptr _y_ = G.g_Nullexpr; if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
  }
  { nialptr _y_ = x; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
}

canonical_original_code:
void isleep()
{ int x;
  x = (G1.g_topstack==(-1) ? stackempty() : (G1.g__x_ = G1.g_stkarea[G1.g_topstack], G1.g_stkarea[G1.g_topstack--] = (nialptr)(-1), G1.g_mem[G1.g__x_-3]--, G1.g__x_));
  if ((((*(struct skv *) &G1.g_mem[x-2])).sk[1])!=3)
  { { register int _y_ = makefault("arg to sleep not an integer"); if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
  }
  else
  { int n = (*((nialint *)&G1.g_mem[x]));
    sleep(n);
    { register int _y_ = G.g_Nullexpr; if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
  }
  { int _y_ = x; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
}

variable_types: x int

variable_types: n int


decompiled_code:
__int64 __fastcall NC_ErrorType(int a1)
{
int *v1; // rax
int v2; // edx

if ( !*(_QWORD *)&error_strings[2] )
return 8LL;
v1 = error_strings;
v2 = 0;
while ( *v1 != a1 )
{
v1 += 4;
++v2;
if ( !*((_QWORD *)v1 + 1) )
return 8LL;
}
return (unsigned int)error_strings[4 * v2 + 1];
}

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

if ( !*(_QWORD *)&error_strings[2] )
return 8LL;
v1 = error_strings;
v2 = 0;
while ( *v1 != a1 )
{
v1 += 4;
++v2;
if ( !*((_QWORD *)v1 + 1) )
return 8LL;
}
return (unsigned int)error_strings[4 * v2 + 1];
}

original_code:
int
NC_ErrorType(int code)
{
  int i = 0;
  while (error_strings[i].error_message) {
    if (error_strings[i].error_code == code)
      return (error_strings[i].error_type);
    i++;
  }
  return (NC_BAD_ERROR_TYPE);
}

variable_types: code int

variable_types: i int


decompiled_code:
const char *__fastcall NC_ErrorTypeName(int a1)
{
int v1; // eax
__int64 v2; // r8
int v3; // edx
_QWORD *i; // rax

v1 = NC_ErrorType(a1);
v2 = *((_QWORD *)&error_type_strings + 1);
v3 = v1;
if ( !v2 )
return "Unknown Error Type";
for ( i = &error_type_strings; *(_DWORD *)i != v3; i += 2 )
{
v2 = i[3];
if ( !v2 )
return "Unknown Error Type";
}
return (const char *)v2;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
int v1; // eax
__int64 v2; // r8
int v3; // edx
_QWORD *i; // rax

v1 = func0(a1);
v2 = *((_QWORD *)&error_type_strings + 1);
v3 = v1;
if ( !v2 )
return "Unknown Error Type";
for ( i = &error_type_strings; *(_DWORD *)i != v3; i += 2 )
{
v2 = i[3];
if ( !v2 )
return "Unknown Error Type";
}
return (const char *)v2;
}

original_code:
char *
NC_ErrorTypeName(int code)
{
  int i = 0;
  int type = NC_ErrorType(code);
  while (error_type_strings[i].error_type_name) {
    if (type == error_type_strings[i].error_type)
      return (error_type_strings[i].error_type_name);
    i++;
  }
  return ("Unknown Error Type");
}

canonical_original_code:
char *NC_ErrorTypeName(int code)
{
  int i = 0;
  int type = NC_ErrorType(code);
  while (error_type_strings[i].error_type_name) {
    if (type == error_type_strings[i].error_type)
      return (error_type_strings[i].error_type_name);
    i++;
  }
  return ("Unknown Error Type");
}

variable_types: type int

return_type: char *


decompiled_code:
const char *__fastcall NC_ErrorMessage(int a1)
{
__int64 v1; // r8
int *i; // rax

v1 = *(_QWORD *)&error_strings[2];
if ( !v1 )
return "Unknown Error Code";
for ( i = error_strings; *i != a1; i += 4 )
{
v1 = *((_QWORD *)i + 3);
if ( !v1 )
return "Unknown Error Code";
}
return (const char *)v1;
}

canonical_decompiled_code:
const char *__fastcall func2(int a1)
{
__int64 v1; // r8
int *i; // rax

v1 = *(_QWORD *)&error_strings[2];
if ( !v1 )
return "Unknown Error Code";
for ( i = error_strings; *i != a1; i += 4 )
{
v1 = *((_QWORD *)i + 3);
if ( !v1 )
return "Unknown Error Code";
}
return (const char *)v1;
}

original_code:
char *
NC_ErrorMessage(int code)
{
  int i = 0;
  while (error_strings[i].error_message) {
    if (error_strings[i].error_code == code)
      return (error_strings[i].error_message);
    i++;
  }
  return ("Unknown Error Code");
}

canonical_original_code:
char *NC_ErrorMessage(int code)
{
  int i = 0;
  while (error_strings[i].error_message) {
    if (error_strings[i].error_code == code)
      return (error_strings[i].error_message);
    i++;
  }
  return ("Unknown Error Code");
}


iGetCommandLine

decompiled_code:
void iGetCommandLine()
{
const char **v0; // rax
int v1; // ebp
__int64 v2; // rbx
__int64 v3; // r12
size_t v4; // rdi
char *v5; // rbp
int v6; // eax
const char **v7; // r12
__int64 v8; // rbx
__int64 v9; // r13
size_t v10; // rax
const char *v11; // r14

if ( global_argc <= 0 )
{
v4 = 1LL;
}
else
{
v0 = (const char **)global_argv;
v1 = 0;
v2 = global_argv + 8LL;
v3 = global_argv + 8LL + 8LL * (unsigned int)(global_argc - 1);
while ( 1 )
{
v1 += strlen(*v0) + 1;
v0 = (const char **)v2;
if ( v3 == v2 )
break;
v2 += 8LL;
}
v4 = v1 + 1;
}
v5 = (char *)malloc(v4);
if ( !v5 )
exit_cover(5LL);
v6 = global_argc;
*v5 = 0;
if ( v6 > 0 )
{
v7 = (const char **)global_argv;
v8 = global_argv + 8LL;
v9 = global_argv + 8LL + 8LL * (unsigned int)(v6 - 1);
while ( 1 )
{
v11 = *v7;
if ( strchr(*v7, 32) )
{
v10 = strlen(v5);
*(_WORD *)&v5[v10] = 34;
*(_WORD *)stpcpy(&v5[v10 + 1], *v7) = 34;
}
else
{
strcat(v5, v11);
}
v7 = (const char **)v8;
*(_WORD *)&v5[strlen(v5)] = 32;
if ( v9 == v8 )
break;
v8 += 8LL;
}
}
mkstring(v5);
free(v5);
}

canonical_decompiled_code:
void func0()
{
const char **v0; // rax
int v1; // ebp
__int64 v2; // rbx
__int64 v3; // r12
size_t v4; // rdi
char *v5; // rbp
int v6; // eax
const char **v7; // r12
__int64 v8; // rbx
__int64 v9; // r13
size_t v10; // rax
const char *v11; // r14

if ( global_argc <= 0 )
{
v4 = 1LL;
}
else
{
v0 = (const char **)global_argv;
v1 = 0;
v2 = global_argv + 8LL;
v3 = global_argv + 8LL + 8LL * (unsigned int)(global_argc - 1);
while ( 1 )
{
v1 += strlen(*v0) + 1;
v0 = (const char **)v2;
if ( v3 == v2 )
break;
v2 += 8LL;
}
v4 = v1 + 1;
}
v5 = (char *)malloc(v4);
if ( !v5 )
exit_cover(5LL);
v6 = global_argc;
*v5 = 0;
if ( v6 > 0 )
{
v7 = (const char **)global_argv;
v8 = global_argv + 8LL;
v9 = global_argv + 8LL + 8LL * (unsigned int)(v6 - 1);
while ( 1 )
{
v11 = *v7;
if ( strchr(*v7, 32) )
{
v10 = strlen(v5);
*(_WORD *)&v5[v10] = 34;
*(_WORD *)stpcpy(&v5[v10 + 1], *v7) = 34;
}
else
{
strcat(v5, v11);
}
v7 = (const char **)v8;
*(_WORD *)&v5[strlen(v5)] = 32;
if ( v9 == v8 )
break;
v8 += 8LL;
}
}
mkstring(v5);
free(v5);
}

original_code:
void
iGetCommandLine(void)
{
  int sz = 0;
  int i;
  char *tmp;
  for (i = 0; i < global_argc; i++)
    sz += strlen(global_argv[i]) + 1;
  tmp = (char *) malloc(sz + 1);
  if (!tmp)
    exit_cover(NC_MEM_ERR_F);
  strcpy(tmp, "");
  for (i = 0; i < global_argc; i++) {
    char *flg = ((void *)0);
    if ((flg = strchr(global_argv[i], ' ')))
      strcat(tmp, "\"");
    strcat(tmp, global_argv[i]);
    if (flg)
      strcat(tmp, "\"");
    strcat(tmp, " ");
  }
  mkstring(tmp);
  free(tmp);
}

canonical_original_code:
void iGetCommandLine()
{
  int sz = 0;
  int i;
  char *tmp;
  for (i = 0; i < global_argc; i++)
    sz += strlen(global_argv[i]) + 1;
  tmp = (char *) malloc(sz + 1);
  if (!tmp)
    exit_cover(NC_MEM_ERR_F);
  strcpy(tmp, "");
  for (i = 0; i < global_argc; i++) {
    char *flg = ((void *)0);
    if ((flg = strchr(global_argv[i], ' ')))
      strcat(tmp, "\"");
    strcat(tmp, global_argv[i]);
    if (flg)
      strcat(tmp, "\"");
    strcat(tmp, " ");
  }
  mkstring(tmp);
  free(tmp);
}

variable_types: sz int

variable_types:
tmp
char *

variable_types:
flg
char *


iGetEnv

original_code:
void
iGetEnv(void)
{
  nialptr z = (G1.g_topstack==(-1) ? stackempty() : (G1.g__x_ = G1.g_stkarea[G1.g_topstack], G1.g_stkarea[G1.g_topstack--] = (nialptr)(-1), G1.g_mem[G1.g__x_-3]--, G1.g__x_));
  char *arg;
  if (((((*(struct skv *) &G1.g_mem[z-2])).sk[1]) != 6) && ((((*(struct skv *) &G1.g_mem[z-2])).sk[1]) != 7) && (G1.g_mem[z-1] != 0)) {
    { register nialptr _y_ = makefault("?Must supply a string or phrase to GetEnv"); if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
    { nialptr _y_ = z; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
    return;
  }
  if (G1.g_mem[z-1] == 0)
    arg = ((void *)0);
  else
    arg = (char *)&G1.g_mem[z];
  {
    if (arg) {
      char *buf;
      buf = getenv(arg);
      mkstring((buf ? buf : ""));
      return;
    }
    else {
      nialptr res;
      int pos = 0;
      int numnames = 0;
      while (environ[pos]) {
        char *str = strdup((environ[pos]));
        char *name = strtok(str, "=");
        char *value = strtok(((void *)0), "");
        numnames++;
        mkstring(name);
        if (value)
          mkstring(value);
        else
          mkstring("");
        free(str);
        pos++;
      }
      if (numnames) {
        int i;
        res = new_create_array(1, 1, 0, &numnames);
        for (i = (numnames - 1); i >= 0; i--) {
          int two = 2;
          nialptr pr = new_create_array(1, 1, 0, &two);
          { nialptr _v_ = (G1.g_topstack==(-1) ? stackempty() : (G1.g__x_ = G1.g_stkarea[G1.g_topstack], G1.g_stkarea[G1.g_topstack--] = (nialptr)(-1), G1.g_mem[G1.g__x_-3]--, G1.g__x_)); G1.g_mem[_v_-3]++; G1.g_mem[pr+1] = _v_; };
          { nialptr _v_ = (G1.g_topstack==(-1) ? stackempty() : (G1.g__x_ = G1.g_stkarea[G1.g_topstack], G1.g_stkarea[G1.g_topstack--] = (nialptr)(-1), G1.g_mem[G1.g__x_-3]--, G1.g__x_)); G1.g_mem[_v_-3]++; G1.g_mem[pr+0] = _v_; };
          { nialptr _v_ = pr; G1.g_mem[_v_-3]++; G1.g_mem[res+i] = _v_; };
        }
        { register nialptr _y_ = res; if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
        { nialptr _y_ = z; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
        return;
      }
      else {
        { register nialptr _y_ = G.g_Null; if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
        { nialptr _y_ = z; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
        return;
      }
    }
  }
}

canonical_original_code:
void iGetEnv()
{
  int z = (G1.g_topstack==(-1) ? stackempty() : (G1.g__x_ = G1.g_stkarea[G1.g_topstack], G1.g_stkarea[G1.g_topstack--] = (nialptr)(-1), G1.g_mem[G1.g__x_-3]--, G1.g__x_));
  char *arg;
  if (((((*(struct skv *) &G1.g_mem[z-2])).sk[1]) != 6) && ((((*(struct skv *) &G1.g_mem[z-2])).sk[1]) != 7) && (G1.g_mem[z-1] != 0)) {
    { register int _y_ = makefault("?Must supply a string or phrase to GetEnv"); if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
    { int _y_ = z; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
    return;
  }
  if (G1.g_mem[z-1] == 0)
    arg = ((void *)0);
  else
    arg = (char *)&G1.g_mem[z];
  {
    if (arg) {
      char *buf;
      buf = getenv(arg);
      mkstring((buf ? buf : ""));
      return;
    }
    else {
      int res;
      int pos = 0;
      int numnames = 0;
      while (environ[pos]) {
        char *str = strdup((environ[pos]));
        char *name = strtok(str, "=");
        char *value = strtok(((void *)0), "");
        numnames++;
        mkstring(name);
        if (value)
          mkstring(value);
        else
          mkstring("");
        free(str);
        pos++;
      }
      if (numnames) {
        int i;
        res = new_create_array(1, 1, 0, &numnames);
        for (i = (numnames - 1); i >= 0; i--) {
          int two = 2;
          int pr = new_create_array(1, 1, 0, &two);
          { int _v_ = (G1.g_topstack==(-1) ? stackempty() : (G1.g__x_ = G1.g_stkarea[G1.g_topstack], G1.g_stkarea[G1.g_topstack--] = (nialptr)(-1), G1.g_mem[G1.g__x_-3]--, G1.g__x_)); G1.g_mem[_v_-3]++; G1.g_mem[pr+1] = _v_; };
          { int _v_ = (G1.g_topstack==(-1) ? stackempty() : (G1.g__x_ = G1.g_stkarea[G1.g_topstack], G1.g_stkarea[G1.g_topstack--] = (nialptr)(-1), G1.g_mem[G1.g__x_-3]--, G1.g__x_)); G1.g_mem[_v_-3]++; G1.g_mem[pr+0] = _v_; };
          { int _v_ = pr; G1.g_mem[_v_-3]++; G1.g_mem[res+i] = _v_; };
        }
        { register int _y_ = res; if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
        { int _y_ = z; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
        return;
      }
      else {
        { register int _y_ = G.g_Null; if (++G1.g_topstack == G1.g_stklim) growstack(); G1.g_stkarea[G1.g_topstack] = _y_; G1.g_mem[_y_-3]++; };
        { int _y_ = z; if (G1.g_mem[_y_-3]==0) freeit(_y_); };
        return;
      }
    }
  }
}

variable_types: z int

variable_types:
arg
char *

variable_types:
buf
char *

variable_types: pos int

variable_types: numnames int

variable_types:
str
char *

variable_types:
name
char *

variable_types:
value
char *

variable_types: two int

variable_types: pr int


freequeue

repo: vserrago/HTTP-Web-Server

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

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

original_code:
void freequeue(queue* q)
{
    free(q->array);
    free(q);
}

canonical_original_code:
void freequeue(struct queue *q)
{
    free(q->array);
    free(q);
}

variable_types: struct queue { int size; int nextin; int nextout; int *array; } *


qadd

original_code:
void qadd(queue* q, int value)
{
    if(q->array[q->nextin] != -1)
        exiterr("Error: Queue is full\n");
    q->array[q->nextin] = value;
    q->nextin++;
    q->nextin %= q->size;
}

canonical_original_code:
void qadd(struct queue *q, int value)
{
    if(q->array[q->nextin] != -1)
        exiterr("Error: Queue is full\n");
    q->array[q->nextin] = value;
    q->nextin++;
    q->nextin %= q->size;
}

variable_types: value int

user_defined_types: struct queue { int size; int nextin; int nextout; int *array; }


qrem

decompiled_code:
__int64 __fastcall qrem(__int64 a1)
{
unsigned int *v1; // rax
unsigned int v2; // er8
__int64 result; // rax

v1 = (unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * *(int *)(a1 + 8));
v2 = *v1;
if ( *v1 == -1 )
{
exiterr("Error: Removng value from empty queue\n");
v1 = (unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * *(int *)(a1 + 8));
v2 = *v1;
}
*v1 = -1;
result = v2;
*(_DWORD *)(a1 + 8) = (*(_DWORD *)(a1 + 8) + 1) % *(_DWORD *)a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int *v1; // rax
unsigned int v2; // er8
__int64 result; // rax

v1 = (unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * *(int *)(a1 + 8));
v2 = *v1;
if ( *v1 == -1 )
{
exiterr("Error: Removng value from empty queue\n");
v1 = (unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * *(int *)(a1 + 8));
v2 = *v1;
}
*v1 = -1;
result = v2;
*(_DWORD *)(a1 + 8) = (*(_DWORD *)(a1 + 8) + 1) % *(_DWORD *)a1;
return result;
}

original_code:
int qrem(queue* q)
{
    int val;
    if(q->array[q->nextout] == -1)
        exiterr("Error: Removng value from empty queue\n");
    val = q->array[q->nextout];
    q->array[q->nextout] = -1;
    q->nextout++;
    q->nextout %= q->size;
    return val;
}

canonical_original_code:
int qrem(struct queue *q)
{
    int val;
    if(q->array[q->nextout] == -1)
        exiterr("Error: Removng value from empty queue\n");
    val = q->array[q->nextout];
    q->array[q->nextout] = -1;
    q->nextout++;
    q->nextout %= q->size;
    return val;
}

variable_types: val int


qpeek

decompiled_code:
__int64 __fastcall qpeek(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * *(int *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * *(int *)(a1 + 8));
}

original_code:
int qpeek(queue* q)
{
    return q->array[q->nextout];
}

canonical_original_code:
int qpeek(struct queue *q)
{
    return q->array[q->nextout];
}


qhaselem

decompiled_code:
_BOOL8 __fastcall qhaselem(__int64 a1)
{
return (unsigned int)qpeek(a1) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return (unsigned int)func4(a1) != -1;
}

original_code:
int qhaselem(queue* q)
{
    return (qpeek(q) == -1) ? 0 : 1;
}

canonical_original_code:
int qhaselem(struct queue *q)
{
    return (qpeek(q) == -1) ? 0 : 1;
}


cpynewstr

decompiled_code:
void *__fastcall cpynewstr(void *src)
{
size_t v1; // rbx
void *v2; // rax

v1 = strlen((const char *)src);
v2 = malloc((int)v1 + 1);
return memcpy(v2, src, v1 + 1);
}

canonical_decompiled_code:
void *__fastcall func0(void *src)
{
size_t v1; // rbx
void *v2; // rax

v1 = strlen((const char *)src);
v2 = malloc((int)v1 + 1);
return memcpy(v2, src, v1 + 1);
}

original_code:
char* cpynewstr(char* source)
{
    int mlen = strlen(source)+1;
    return strcpy(malloc(mlen*sizeof(char)), source);
}

canonical_original_code:
char *cpynewstr(char *source)
{
    int mlen = strlen(source)+1;
    return strcpy(malloc(mlen*sizeof(char)), source);
}

variable_types:
source
char *

variable_types: mlen int


cmbnewstr

decompiled_code:
char *__fastcall cmbnewstr(void *src, void *a2)
{
size_t v2; // rbx
size_t v3; // rbp
char *v4; // r12

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc((int)v3 + (int)v2 + 1);
memcpy(v4, src, v2);
memcpy(&v4[v2], a2, v3 + 1);
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(void *src, void *a2)
{
size_t v2; // rbx
size_t v3; // rbp
char *v4; // r12

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc((int)v3 + (int)v2 + 1);
memcpy(v4, src, v2);
memcpy(&v4[v2], a2, v3 + 1);
return v4;
}

original_code:
char* cmbnewstr(char* str1, char* str2)
{
    int len = strlen(str1);
    len += strlen(str2);
    len += 1;
    char* cmbstr = malloc(len*sizeof(char));
    strcpy(cmbstr, str1);
    strcat(cmbstr, str2);
    return cmbstr;
}

canonical_original_code:
char *cmbnewstr(char *str1, char *str2)
{
    int len = strlen(str1);
    len += strlen(str2);
    len += 1;
    char *cmbstr = malloc(len*sizeof(char));
    strcpy(cmbstr, str1);
    strcat(cmbstr, str2);
    return cmbstr;
}

variable_types: len int

variable_types:
cmbstr
char *


handlecon

decompiled_code:
void __fastcall __noreturn handlecon(void *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp
__int64 v3; // rax
void *v4; // r12
__int64 v5; // r14
__int64 v6; // r13

while ( 1 )
{
sem_wait(&semtasks);
servlog("Task handled by thread\n");
sem_wait(&semq);
v1 = qpeek(q);
servdeblog("Peek value: %d\n", v1);
v2 = qrem(q);
sem_post(&semq);
v3 = recievereq(v2);
if ( v3 )
{
v4 = (void *)v3;
v5 = parsereq(v3);
sem_wait(&semconfig);
v6 = handlereq(v5, config);
sem_post(&semconfig);
sendresp(v2, v6);
free(v4);
freereq(v5);
freeresp(v6);
}
else
{
servlog("Connection with client lost: client closed connection\n");
}
close(v2);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp
__int64 v3; // rax
void *v4; // r12
__int64 v5; // r14
__int64 v6; // r13

while ( 1 )
{
sem_wait(&semtasks);
servlog("Task handled by thread\n");
sem_wait(&semq);
v1 = qpeek(q);
servdeblog("Peek value: %d\n", v1);
v2 = qrem(q);
sem_post(&semq);
v3 = recievereq(v2);
if ( v3 )
{
v4 = (void *)v3;
v5 = parsereq(v3);
sem_wait(&semconfig);
v6 = handlereq(v5, config);
sem_post(&semconfig);
sendresp(v2, v6);
free(v4);
freereq(v5);
freeresp(v6);
}
else
{
servlog("Connection with client lost: client closed connection\n");
}
close(v2);
}
}

original_code:
void* handlecon(void* args)
{
    int connectfd;
    for(;;)
    {
        sem_wait(&semtasks);
        servlog("Task handled by thread\n");
        sem_wait(&semq);
        {
            servdeblog("Peek value: %d\n",qpeek(q));
            connectfd = qrem(q);
        }
        sem_post(&semq);
        char* reqstr;
        if((reqstr = recievereq(connectfd)) == ((void *)0))
        {
            servlog("Connection with client lost: client closed connection\n");
            close(connectfd);
            continue;
        }
        request* req = parsereq(reqstr);
        response* resp;
        sem_wait(&semconfig);
        {
            resp = handlereq(req, config);
        }
        sem_post(&semconfig);
        sendresp(connectfd,resp);
        free(reqstr);
        freereq(req);
        freeresp(resp);
        close(connectfd);
    }
    pthread_exit(0);
}

canonical_original_code:
void *handlecon(void *args)
{
    int connectfd;
    for(;;)
    {
        sem_wait(&semtasks);
        servlog("Task handled by thread\n");
        sem_wait(&semq);
        {
            servdeblog("Peek value: %d\n",qpeek(q));
            connectfd = qrem(q);
        }
        sem_post(&semq);
        char *reqstr;
        if((reqstr = recievereq(connectfd)) == ((void *)0))
        {
            servlog("Connection with client lost: client closed connection\n");
            close(connectfd);
            continue;
        }
        struct request *req = parsereq(reqstr);
        struct response *resp;
        sem_wait(&semconfig);
        {
            resp = handlereq(req, config);
        }
        sem_post(&semconfig);
        sendresp(connectfd,resp);
        free(reqstr);
        freereq(req);
        freeresp(resp);
        close(connectfd);
    }
    pthread_exit(0);
}

variable_types:
args
void *

variable_types: connectfd int

variable_types:
reqstr
char *

variable_types: struct request { unsigned char badreq; char *reqtype; char *reqfile; char *httpver; char *content; int contlen; } *

variable_types: struct response { char *status; char *date; char *contype; char *contlenstr; char *content; int contlen; } *

return_type: void *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // r12
char *v5; // rbp
int v6; // eax
__int64 v7; // rbx
const char *v8; // rax
const char *v9; // rdx
const char *v10; // rsi
__int64 v11; // rax
__int64 v12; // rdi
__int64 v13; // rbp
_QWORD *v14; // r12
__int64 v15; // rbp
__int64 v16; // rsi
int v17; // ebp
unsigned int v18; // eax
int v19; // [rsp+0h] [rbp-138h] BYREF
socklen_t addr_len; // [rsp+4h] [rbp-134h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-130h] BYREF
struct option longopts; // [rsp+10h] [rbp-128h] BYREF
const char *v23; // [rsp+30h] [rbp-108h]
int v24; // [rsp+38h] [rbp-100h]
__int64 v25; // [rsp+40h] [rbp-F8h]
int v26; // [rsp+48h] [rbp-F0h]
const char *v27; // [rsp+50h] [rbp-E8h]
int v28; // [rsp+58h] [rbp-E0h]
__int64 v29; // [rsp+60h] [rbp-D8h]
int v30; // [rsp+68h] [rbp-D0h]
const char *v31; // [rsp+70h] [rbp-C8h]
int v32; // [rsp+78h] [rbp-C0h]
__int64 v33; // [rsp+80h] [rbp-B8h]
int v34; // [rsp+88h] [rbp-B0h]
struct sockaddr addr; // [rsp+90h] [rbp-A8h] BYREF

v3 = "localhost";
v4 = "multithread.conf";
v5 = "61000";
longopts.name = "address";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 97;
v23 = "config";
v24 = 1;
v25 = 0LL;
v26 = 99;
v27 = "debug";
v28 = 0;
v29 = 0LL;
v30 = 100;
v31 = "port";
v32 = 1;
v33 = 0LL;
v34 = 112;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "a:c:dp:", &longopts, &v19);
if ( v6 == -1 )
{
v7 = allocstserv();
*(_QWORD *)(v7 + 8) = cpynewstr(v5);
*(_QWORD *)(v7 + 16) = cpynewstr(v3);
v8 = (const char *)cpynewstr(v4);
v9 = *(const char **)(v7 + 8);
v10 = *(const char **)(v7 + 16);
*(_QWORD *)(v7 + 24) = v8;
servdeblog("Server Address: '%s', Port: '%s', Confname: '%s'\n", v10, v9, v8);
v11 = parseconf(v4);
v12 = *(unsigned int *)(v11 + 32);
config = v11;
q = createqueue(v12);
prepserv(v7);
sem_init(&semconfig, 0, 1u);
sem_init(&semq, 0, 1u);
sem_init(&semtasks, 0, 0);
v13 = *(int *)(config + 28);
v14 = malloc(8 * v13);
if ( (int)v13 > 0 )
{
v15 = 0LL;
do
{
pthread_create(&newthread, 0LL, (void *(*)(void *))handlecon, 0LL);
v16 = (unsigned int)v15;
v14[v15++] = newthread;
servdeblog("Thread %d created\n", v16);
}
while ( *(_DWORD *)(config + 28) > (int)v15 );
}
addr_len = 128;
servlog("Ready to recieve\n");
while ( 1 )
{
v17 = accept(*(_DWORD *)v7, &addr, &addr_len);
if ( v17 < 0 )
exiterr("Accept error\n");
sem_wait(&semq);
qadd(q, (unsigned int)v17);
servdeblog("Connection '%d' added to queue\n", (unsigned int)v17);
v18 = qpeek(q);
servdeblog("Nextout: %d\n", v18);
sem_post(&semtasks);
sem_post(&semq);
}
}
if ( v6 != 100 )
break;
debugflag = 1;
servdeblog("Debug mode enabled\n");
}
if ( v6 > 100 )
break;
if ( v6 == 97 )
{
v3 = optarg;
servdeblog("Address set with value '%s'\n", optarg);
}
else
{
if ( v6 != 99 )
goto LABEL_13;
v4 = optarg;
servdeblog("Configuration file set with value '%s'\n", optarg);
}
}
if ( v6 != 112 )
LABEL_13:
exit(1);
v5 = optarg;
if ( (unsigned int)(atoi(optarg) - 60000) > 0x159F )
exiterr("Portnumber is invalid\n");
servdeblog("Port set with value '%s'\n", v5);
}
}

original_code:
int main(int argc, char *argv [])
{
    char* port = "61000";
    char* address = "localhost";
    char* confname = "multithread.conf";
    stserver* serv;
    pthread_t* pthrarr;
    int opt;
    int longindex;
    int portnum;
    struct option long_options[] =
    {
        {"address", 1, ((void *)0), 'a'},
        {"config", 1, ((void *)0), 'c'},
        {"debug", 0, ((void *)0), 'd'},
        {"port", 1, ((void *)0), 'p'}
    };
    while((opt = getopt_long(argc,argv,"a:c:dp:", long_options, &longindex)) != -1)
    {
        switch(opt)
        {
            case 'a':
                address = optarg;
                servdeblog("Address set with value '%s'\n", address);
                break;
            case 'c':
                confname = optarg;
                servdeblog("Configuration file set with value '%s'\n", confname);
                break;
            case 'd':
                debugflag = 1;
                servdeblog("Debug mode enabled\n");
                break;
            case 'p':
                port = optarg;
                portnum = atoi(port);
                if(portnum < 60000 || 65535 < portnum)
                    exiterr("Portnumber is invalid\n");
                servdeblog("Port set with value '%s'\n", port);
                break;
            case '?':
            default:
                exit(1);
        }
    }
    serv = allocstserv();
    serv->port = cpynewstr(port);
    serv->address = cpynewstr(address);
    serv->confname = cpynewstr(confname);
    servdeblog("Server Address: '%s', Port: '%s', Confname: '%s'\n",
            serv->address, serv->port, serv->confname);
    config = parseconf(confname);
    q = createqueue(config->queuesize);
    prepserv(serv);
    sem_init(&semconfig, 0, 1);
    sem_init(&semq, 0, 1);
    sem_init(&semtasks, 0, 0);
    pthrarr = malloc(config->poolsize * sizeof(pthread_t));
    int i;
    pthread_t pthr;
    for(i=0; i < config->poolsize; i++)
    {
        pthread_create(&pthr,((void *)0), handlecon, 0);
        pthrarr[i] = pthr;
        servdeblog("Thread %d created\n", i);
    }
    struct sockaddr_storage socket_st;
    socklen_t addr_size = sizeof socket_st;
    servlog("Ready to recieve\n");
    for(;;)
    {
        int c = accept(serv->sock, (struct sockaddr *) &socket_st, &addr_size);
        if(c < 0)
            exiterr("Accept error\n");
        sem_wait(&semq);
        {
            qadd(q,c);
            servdeblog("Connection '%d' added to queue\n",c);
            servdeblog("Nextout: %d\n",qpeek(q));
            sem_post(&semtasks);
        }
        sem_post(&semq);
    }
    close(serv->sock);
    freeconf(config);
    freestserv(serv);
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *port = "61000";
    char *address = "localhost";
    char *confname = "multithread.conf";
    struct stserver *serv;
    unsigned long *pthrarr;
    int opt;
    int longindex;
    int portnum;
    struct option long_options[] = {
        {"address", 1, ((void *)0), 'a'},
        {"config", 1, ((void *)0), 'c'},
        {"debug", 0, ((void *)0), 'd'},
        {"port", 1, ((void *)0), 'p'}
    };
    while((opt = getopt_long(argc,argv,"a:c:dp:", long_options, &longindex)) != -1)
    {
        switch(opt)
        {
            case 'a':
                address = optarg;
                servdeblog("Address set with value '%s'\n", address);
                break;
            case 'c':
                confname = optarg;
                servdeblog("Configuration file set with value '%s'\n", confname);
                break;
            case 'd':
                debugflag = 1;
                servdeblog("Debug mode enabled\n");
                break;
            case 'p':
                port = optarg;
                portnum = atoi(port);
                if(portnum < 60000 || 65535 < portnum)
                    exiterr("Portnumber is invalid\n");
                servdeblog("Port set with value '%s'\n", port);
                break;
            case '?':
            default:
                exit(1);
        }
    }
    serv = allocstserv();
    serv->port = cpynewstr(port);
    serv->address = cpynewstr(address);
    serv->confname = cpynewstr(confname);
    servdeblog("Server Address: '%s', Port: '%s', Confname: '%s'\n",
            serv->address, serv->port, serv->confname);
    config = parseconf(confname);
    q = createqueue(config->queuesize);
    prepserv(serv);
    sem_init(&semconfig, 0, 1);
    sem_init(&semq, 0, 1);
    sem_init(&semtasks, 0, 0);
    pthrarr = malloc(config->poolsize * sizeof(pthread_t));
    int i;
    unsigned long pthr;
    for(i=0; i < config->poolsize; i++)
    {
        pthread_create(&pthr,((void *)0), handlecon, 0);
        pthrarr[i] = pthr;
        servdeblog("Thread %d created\n", i);
    }
    struct sockaddr_storage socket_st;
    unsigned int addr_size = sizeof socket_st;
    servlog("Ready to recieve\n");
    for(;;)
    {
        int c = accept(serv->sock, (struct sockaddr *) &socket_st, &addr_size);
        if(c < 0)
            exiterr("Accept error\n");
        sem_wait(&semq);
        {
            qadd(q,c);
            servdeblog("Connection '%d' added to queue\n",c);
            servdeblog("Nextout: %d\n",qpeek(q));
            sem_post(&semtasks);
        }
        sem_post(&semq);
    }
    close(serv->sock);
    freeconf(config);
    freestserv(serv);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
port
char *

variable_types:
address
char *

variable_types:
confname
char *

variable_types: struct stserver { int sock; char *port; char *address; char *confname; } *

variable_types:
pthrarr
unsigned long *

variable_types: opt int

variable_types: longindex int

variable_types: portnum int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: i int

variable_types:
pthr
unsigned long

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types: c int


repo: vserrago/cprog

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

v3 = 1;
v4 = createNode(argc, argv, envp);
bstInsert(10LL, v4);
bstInsert(4LL, v4);
bstInsert(6LL, v4);
bstInsert(9LL, v4);
bstInsert(1LL, v4);
bstInorder(v4);
putchar(10);
do
{
while ( 1 )
{
v5 = v3;
if ( !(unsigned int)bstSearch(v3, v4) )
break;
++v3;
printf("%d is in the tree\n", v5);
if ( v3 == 20 )
goto LABEL_5;
}
++v3;
printf("%d is NOT in the tree\n", v5);
}
while ( v3 != 20 );
LABEL_5:
putchar(10);
return 0;
}

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

v3 = 1;
v4 = func10(argc, argv, envp);
func11(10LL, v4);
func11(4LL, v4);
func11(6LL, v4);
func11(9LL, v4);
func11(1LL, v4);
func7(v4);
putchar(10);
do
{
while ( 1 )
{
v5 = v3;
if ( !(unsigned int)func9(v3, v4) )
break;
++v3;
printf("%d is in the tree\n", v5);
if ( v3 == 20 )
goto LABEL_5;
}
++v3;
printf("%d is NOT in the tree\n", v5);
}
while ( v3 != 20 );
LABEL_5:
putchar(10);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
    int i=0;
    bst *t;
    t = createNode();
    bstInsert(10,t);
    bstInsert(4,t);
    bstInsert(6,t);
    bstInsert(9,t);
    bstInsert(1,t);
    bstInorder(t);
    printf("\n");
    for(i=1; i<20; i++)
    {
        if(bstSearch(i,t))
            printf("%d is in the tree\n",i);
        else
            printf("%d is NOT in the tree\n",i);
    }
    printf("\n");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int i = 0;
    struct subtree *t;
    t = createNode();
    bstInsert(10,t);
    bstInsert(4,t);
    bstInsert(6,t);
    bstInsert(9,t);
    bstInsert(1,t);
    bstInorder(t);
    printf("\n");
    for(i=1; i<20; i++)
    {
        if(bstSearch(i,t))
            printf("%d is in the tree\n",i);
        else
            printf("%d is NOT in the tree\n",i);
    }
    printf("\n");
    return 0;
}

variable_types: struct subtree { int value; struct subtree *left; struct subtree *right; } *


bstInorder

decompiled_code:
int __fastcall bstInorder(unsigned int *a1)
{
__int64 v2; // rdi
int result; // eax

do
{
v2 = *((_QWORD *)a1 + 1);
if ( v2 )
bstInorder(v2);
result = printf("%d ", *a1);
a1 = (unsigned int *)*((_QWORD *)a1 + 2);
}
while ( a1 );
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
__int64 v2; // rdi
int result; // eax

do
{
v2 = *((_QWORD *)a1 + 1);
if ( v2 )
func7(v2);
result = printf("%d ", *a1);
a1 = (unsigned int *)*((_QWORD *)a1 + 2);
}
while ( a1 );
return result;
}

original_code:
void bstInorder(bst *t)
{
    if(t->left != ((void *)0))
    {
        bstInorder(t->left);
    }
    printf("%d ", t->value);
    if(t->right != ((void *)0))
        bstInorder(t->right);
}

canonical_original_code:
void bstInorder(struct subtree *t)
{
    if(t->left != ((void *)0))
    {
        bstInorder(t->left);
    }
    printf("%d ", t->value);
    if(t->right != ((void *)0))
        bstInorder(t->right);
}

user_defined_types: struct subtree { int value; struct subtree *left; struct subtree *right; }


bstRetrieve

decompiled_code:
unsigned int *__fastcall bstRetrieve(int a1, unsigned int *a2)
{
unsigned int *result; // rax

for ( result = (unsigned int *)*a2; (_DWORD)result != a1; result = (unsigned int *)*a2 )
{
if ( a1 < (int)result )
{
a2 = (unsigned int *)*((_QWORD *)a2 + 1);
if ( !a2 )
return 0LL;
}
else
{
if ( a1 <= (int)result )
return result;
a2 = (unsigned int *)*((_QWORD *)a2 + 2);
if ( !a2 )
return 0LL;
}
}
return a2;
}

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

for ( result = (unsigned int *)*a2; (_DWORD)result != a1; result = (unsigned int *)*a2 )
{
if ( a1 < (int)result )
{
a2 = (unsigned int *)*((_QWORD *)a2 + 1);
if ( !a2 )
return 0LL;
}
else
{
if ( a1 <= (int)result )
return result;
a2 = (unsigned int *)*((_QWORD *)a2 + 2);
if ( !a2 )
return 0LL;
}
}
return a2;
}

original_code:
node * bstRetrieve(int v, bst *t)
{
    if(t->value==v)
        return t;
    else if(v < t->value)
    {
        if(t->left != ((void *)0))
            return bstRetrieve(v,t->left);
        else
            return ((void *)0);
    }
    else if(t->value < v)
    {
        if(t->right != ((void *)0))
            return bstRetrieve(v,t->right);
        else
            return ((void *)0);
    }
}

canonical_original_code:
struct subtree *bstRetrieve(int v, struct subtree *t)
{
    if(t->value==v)
        return t;
    else if(v < t->value)
    {
        if(t->left != ((void *)0))
            return bstRetrieve(v,t->left);
        else
            return ((void *)0);
    }
    else if(t->value < v)
    {
        if(t->right != ((void *)0))
            return bstRetrieve(v,t->right);
        else
            return ((void *)0);
    }
}

variable_types: v int

variable_types:
t
struct subtree *

return_type: struct subtree { int value; struct subtree *left; struct subtree *right; } *


bstSearch

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

for ( result = *a2; (_DWORD)result != a1; result = *a2 )
{
if ( a1 < (int)result )
{
a2 = (unsigned int *)*((_QWORD *)a2 + 1);
if ( !a2 )
return 0LL;
}
else
{
if ( a1 <= (int)result )
return result;
a2 = (unsigned int *)*((_QWORD *)a2 + 2);
if ( !a2 )
return 0LL;
}
}
return 1LL;
}

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

for ( result = *a2; (_DWORD)result != a1; result = *a2 )
{
if ( a1 < (int)result )
{
a2 = (unsigned int *)*((_QWORD *)a2 + 1);
if ( !a2 )
return 0LL;
}
else
{
if ( a1 <= (int)result )
return result;
a2 = (unsigned int *)*((_QWORD *)a2 + 2);
if ( !a2 )
return 0LL;
}
}
return 1LL;
}

original_code:
int bstSearch(int v, bst *t)
{
    if(t->value==v)
        return 1;
    else if(v < t->value)
    {
        if(t->left != ((void *)0))
            return bstSearch(v,t->left);
        else
            return 0;
    }
    else if(t->value < v)
    {
        if(t->right != ((void *)0))
            return bstSearch(v,t->right);
        else
            return 0;
    }
}

canonical_original_code:
int bstSearch(int v, struct subtree *t)
{
    if(t->value==v)
        return 1;
    else if(v < t->value)
    {
        if(t->left != ((void *)0))
            return bstSearch(v,t->left);
        else
            return 0;
    }
    else if(t->value < v)
    {
        if(t->right != ((void *)0))
            return bstSearch(v,t->right);
        else
            return 0;
    }
}


createNode

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

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

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

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
node * createNode(void)
{
    node * n = malloc(sizeof(node));
    n->value = 0;
    n->left = ((void *)0);
    n->right = ((void *)0);
    return n;
}

canonical_original_code:
struct subtree *createNode()
{
    struct subtree *n = malloc(sizeof(node));
    n->value = 0;
    n->left = ((void *)0);
    n->right = ((void *)0);
    return n;
}