NSInsert

original_code:
int NSInsert (NSObj * Root, char * String, long Value){
            NSObj * Current;
            NSObj * Previous;
 int StrLoc=0;
 if (String && String[0] && Root) {
  Current = Root->Child;
  Previous = Root;
  while (String[StrLoc]){
   if (!Current) {
    Current = AllocNSObj();
    if (!Current)
     return 0;
    Previous->Child = Current;
    Current->Character = String[StrLoc];
   } else if (String[StrLoc] < Current->Character) {
    NSObj * Temp;
    Temp = AllocNSObj();
    if (!Temp)
     return 0;
    Temp->Character = String[StrLoc];
    Previous->Child = Temp;
    Temp->Next = Current;
    Current = Temp;
   } else if (String[StrLoc] != Current->Character) {
    while (Current && String[StrLoc] > Current->Character){
     Previous = Current;
     Current = Current->Next;
    }
    if (!Current){
     Current = AllocNSObj();
     if (!Current)
      return 0;
     Previous->Next = Current;
                                 Current->Character = String[StrLoc];
    } else {
     if (String[StrLoc] != Current->Character) {
      Previous->Next = AllocNSObj();
      if (!Previous->Next)
       return 0;
      Previous->Next->Next = Current;
      Current = Previous->Next;
      Current->Character = String[StrLoc];
     }
    }
   }
   Previous = Current;
   Current = Current->Child;
   StrLoc++;
  }
  Previous->Value = Value;
  return 1;
 } else
  return 0;
}

canonical_original_code:
int NSInsert(struct NSObj *Root, char *String, long Value){
            struct NSObj *Current;
            struct NSObj *Previous;
 int StrLoc = 0;
 if (String && String[0] && Root) {
  Current = Root->Child;
  Previous = Root;
  while (String[StrLoc]){
   if (!Current) {
    Current = AllocNSObj();
    if (!Current)
     return 0;
    Previous->Child = Current;
    Current->Character = String[StrLoc];
   } else if (String[StrLoc] < Current->Character) {
    struct NSObj *Temp;
    Temp = AllocNSObj();
    if (!Temp)
     return 0;
    Temp->Character = String[StrLoc];
    Previous->Child = Temp;
    Temp->Next = Current;
    Current = Temp;
   } else if (String[StrLoc] != Current->Character) {
    while (Current && String[StrLoc] > Current->Character){
     Previous = Current;
     Current = Current->Next;
    }
    if (!Current){
     Current = AllocNSObj();
     if (!Current)
      return 0;
     Previous->Next = Current;
                                 Current->Character = String[StrLoc];
    } else {
     if (String[StrLoc] != Current->Character) {
      Previous->Next = AllocNSObj();
      if (!Previous->Next)
       return 0;
      Previous->Next->Next = Current;
      Current = Previous->Next;
      Current->Character = String[StrLoc];
     }
    }
   }
   Previous = Current;
   Current = Current->Child;
   StrLoc++;
  }
  Previous->Value = Value;
  return 1;
 } else
  return 0;
}

variable_types:
String
char *

variable_types: Value long

variable_types: StrLoc int

user_defined_types: struct NSObj { struct NSObj *Child; struct NSObj *Next; char Character; long Value; }


NSDelete

original_code:
int NSDelete (NSObj * Root, char * String){
 NSObj * Current;
 NSObj * Previous;
 NSObj * LastBranch;
 int StrLoc=0;
 if (String && String[0] && Root) {
  Current = Root->Child;
  Previous = Root;
  LastBranch = Current;
  while (Current && String[StrLoc]) {
   if (String[StrLoc] > Current->Character) {
    while (Current && String[StrLoc] > Current->Character)
     Current = Current->Next;
    if (!Current)
     break;
    if (String[StrLoc] == Current->Character)
     if (!String[StrLoc+1]) {
      NSObj * DeleteNSObj;
      NSObj * DeleteNext;
      if (!Current->Value)
       return 0;
      if(Current->Child){
       Current->Value = 0;
       return (1);
      }
      DeleteNSObj = LastBranch->Child;
      LastBranch->Child = ((void *)0);
      while (DeleteNSObj) {
       DeleteNext = DeleteNSObj->Child;
       free (DeleteNSObj);
       DeleteNSObj = DeleteNext;
      }
                           return (1);
     }
     if (Current->Value > 0)
      LastBranch = Current;
     Current = Current->Child;
   } else if (String[StrLoc] == Current->Character) {
    if (!String[StrLoc+1]) {
     NSObj * DeleteNSObj;
     NSObj * DeleteNext;
     if (!Current->Value)
      return 0;
     if(Current->Child){
      Current->Value = 0;
      return (1);
     }
     DeleteNSObj = LastBranch->Child;
     LastBranch->Child = ((void *)0);
     while (DeleteNSObj) {
      DeleteNext = DeleteNSObj->Child;
      free (DeleteNSObj);
      DeleteNSObj = DeleteNext;
     }
                          return (1);
    }
    if (Current->Value > 0)
     LastBranch = Current;
    Current = Current->Child;
   } else {
    break;
   }
   StrLoc++;
  }
 }
 return 0;
}

canonical_original_code:
int NSDelete(struct NSObj *Root, char *String){
 struct NSObj *Current;
 struct NSObj *Previous;
 struct NSObj *LastBranch;
 int StrLoc = 0;
 if (String && String[0] && Root) {
  Current = Root->Child;
  Previous = Root;
  LastBranch = Current;
  while (Current && String[StrLoc]) {
   if (String[StrLoc] > Current->Character) {
    while (Current && String[StrLoc] > Current->Character)
     Current = Current->Next;
    if (!Current)
     break;
    if (String[StrLoc] == Current->Character)
     if (!String[StrLoc+1]) {
      struct NSObj *DeleteNSObj;
      struct NSObj *DeleteNext;
      if (!Current->Value)
       return 0;
      if(Current->Child){
       Current->Value = 0;
       return (1);
      }
      DeleteNSObj = LastBranch->Child;
      LastBranch->Child = ((void *)0);
      while (DeleteNSObj) {
       DeleteNext = DeleteNSObj->Child;
       free (DeleteNSObj);
       DeleteNSObj = DeleteNext;
      }
                           return (1);
     }
     if (Current->Value > 0)
      LastBranch = Current;
     Current = Current->Child;
   } else if (String[StrLoc] == Current->Character) {
    if (!String[StrLoc+1]) {
     struct NSObj *DeleteNSObj;
     struct NSObj *DeleteNext;
     if (!Current->Value)
      return 0;
     if(Current->Child){
      Current->Value = 0;
      return (1);
     }
     DeleteNSObj = LastBranch->Child;
     LastBranch->Child = ((void *)0);
     while (DeleteNSObj) {
      DeleteNext = DeleteNSObj->Child;
      free (DeleteNSObj);
      DeleteNSObj = DeleteNext;
     }
                          return (1);
    }
    if (Current->Value > 0)
     LastBranch = Current;
    Current = Current->Child;
   } else {
    break;
   }
   StrLoc++;
  }
 }
 return 0;
}

variable_types: struct NSObj { struct NSObj *Child; struct NSObj *Next; char Character; long Value; } *

return_type: int


NameSpaceTest

decompiled_code:
__int64 NameSpaceTest()
{
__int64 v0; // r15
__int64 **v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
unsigned int i; // [rsp+Ch] [rbp-43Ch]
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

for ( i = 0; i != 11; ++i )
{
v0 = 0LL;
v1 = (__int64 **)NSCreate_localalias();
do
{
sprintf(s, "lksdfhjklsdfjklsdfhjklsdfhjklsdfh%d/test0/test1/test2/test3/test4/%d", (unsigned int)v0 / 0xAuLL, i);
NSInsert(v1, s, v0);
v2 = NSSearch(v1, s);
printf("%ld\n", v2);
NSInsert(v1, "james", 1LL);
NSInsert(v1, "rogers", 2LL);
NSInsert(v1, "bob", 3LL);
NSInsert(v1, "aaa", 3LL);
NSInsert(v1, "bobabcdefghijklmnopqrstuv", 4LL);
NSInsert(v1, "bobabcdefghij", 5LL);
NSInsert(v1, "fred", 6LL);
NSInsert(v1, "This is a very/long/test of /multiple dirs/", 7LL);
NSInsert(v1, "This is a very/long/test of /multiple dirs/me too", 8LL);
NSInsert(v1, "harry", 9LL);
NSInsert(v1, "retriever", 10LL);
v3 = NSSearch(v1, "james");
printf("%ld ", v3);
v4 = NSSearch(v1, "rogers");
printf("%ld ", v4);
v5 = NSSearch(v1, "bob");
printf("%ld ", v5);
v6 = NSSearch(v1, "aaa");
printf("%ld ", v6);
v7 = NSSearch(v1, "bobabcdefghijklmnopqrstuv");
printf("%ld ", v7);
v8 = NSSearch(v1, "bobabcdefghij");
printf("%ld ", v8);
v9 = NSSearch(v1, "fred");
printf("%ld ", v9);
v10 = NSSearch(v1, "This is a very/long/test of /multiple dirs/");
printf("%ld ", v10);
v11 = NSSearch(v1, "This is a very/long/test of /multiple dirs/me too");
printf("%ld ", v11);
v12 = NSSearch(v1, "harry");
printf("%ld ", v12);
v13 = NSSearch(v1, "retriever");
printf("%ld ", v13);
v14 = NSSearch(v1, "I don't exist");
printf("%ld ", v14);
v15 = NSDelete((char **)v1, "bobabcdefghij");
printf("%d ", v15);
v16 = NSDelete((char **)v1, "bobabcdefghij");
printf("%d ", v16);
v17 = NSDelete((char **)v1, "I don't exist");
printf("%d ", v17);
v18 = NSSearch(v1, "bob");
++v0;
printf("%ld ", v18);
v19 = NSSearch(v1, "bobabcdefghijklmnopqrstuv");
printf("%ld ", v19);
v20 = NSSearch(v1, "bobabcdefghij");
printf("%ld ", v20);
NSInsert(v1, "james", 1000LL);
v21 = NSSearch(v1, "james");
printf("%ld\n", v21);
}
while ( v0 != 10001 );
NSRelease_localalias(v1);
usleep(0);
fputc(46, stderr);
}
fputc(10, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // r15
__int64 **v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
unsigned int i; // [rsp+Ch] [rbp-43Ch]
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

for ( i = 0; i != 11; ++i )
{
v0 = 0LL;
v1 = (__int64 **)func0();
do
{
sprintf(s, "lksdfhjklsdfjklsdfhjklsdfhjklsdfh%d/test0/test1/test2/test3/test4/%d", (unsigned int)v0 / 0xAuLL, i);
func3(v1, s, v0);
v2 = func4(v1, s);
printf("%ld\n", v2);
func3(v1, "james", 1LL);
func3(v1, "rogers", 2LL);
func3(v1, "bob", 3LL);
func3(v1, "aaa", 3LL);
func3(v1, "bobabcdefghijklmnopqrstuv", 4LL);
func3(v1, "bobabcdefghij", 5LL);
func3(v1, "fred", 6LL);
func3(v1, "This is a very/long/test of /multiple dirs/", 7LL);
func3(v1, "This is a very/long/test of /multiple dirs/me too", 8LL);
func3(v1, "harry", 9LL);
func3(v1, "retriever", 10LL);
v3 = func4(v1, "james");
printf("%ld ", v3);
v4 = func4(v1, "rogers");
printf("%ld ", v4);
v5 = func4(v1, "bob");
printf("%ld ", v5);
v6 = func4(v1, "aaa");
printf("%ld ", v6);
v7 = func4(v1, "bobabcdefghijklmnopqrstuv");
printf("%ld ", v7);
v8 = func4(v1, "bobabcdefghij");
printf("%ld ", v8);
v9 = func4(v1, "fred");
printf("%ld ", v9);
v10 = func4(v1, "This is a very/long/test of /multiple dirs/");
printf("%ld ", v10);
v11 = func4(v1, "This is a very/long/test of /multiple dirs/me too");
printf("%ld ", v11);
v12 = func4(v1, "harry");
printf("%ld ", v12);
v13 = func4(v1, "retriever");
printf("%ld ", v13);
v14 = func4(v1, "I don't exist");
printf("%ld ", v14);
v15 = func5((char **)v1, "bobabcdefghij");
printf("%d ", v15);
v16 = func5((char **)v1, "bobabcdefghij");
printf("%d ", v16);
v17 = func5((char **)v1, "I don't exist");
printf("%d ", v17);
v18 = func4(v1, "bob");
++v0;
printf("%ld ", v18);
v19 = func4(v1, "bobabcdefghijklmnopqrstuv");
printf("%ld ", v19);
v20 = func4(v1, "bobabcdefghij");
printf("%ld ", v20);
func3(v1, "james", 1000LL);
v21 = func4(v1, "james");
printf("%ld\n", v21);
}
while ( v0 != 10001 );
func1(v1);
usleep(0);
fputc(46, stderr);
}
fputc(10, stderr);
return 0LL;
}

original_code:
int NameSpaceTest (){
 NSObj * NameSpace;
 int i, j;
 char string[1024];
  for (j=0; j<=10; j++) {
 NameSpace = NSCreate();
    for (i=0; i <= 10000; i++) {
 sprintf(string, "lksdfhjklsdfjklsdfhjklsdfhjklsdfh%d/test0/test1/test2/test3/test4/%d", i/10, j);
 NSInsert(NameSpace, string, i);
 printf("%ld\n", NSSearch(NameSpace, string));
 NSInsert(NameSpace, "james", 1);
 NSInsert(NameSpace, "rogers", 2);
 NSInsert(NameSpace, "bob", 3);
 NSInsert(NameSpace, "aaa", 3);
 NSInsert(NameSpace, "bobabcdefghijklmnopqrstuv", 4);
 NSInsert(NameSpace, "bobabcdefghij", 5);
 NSInsert(NameSpace, "fred", 6);
 NSInsert(NameSpace, "This is a very/long/test of /multiple dirs/", 7);
 NSInsert(NameSpace, "This is a very/long/test of /multiple dirs/me too", 8);
 NSInsert(NameSpace, "harry", 9);
 NSInsert(NameSpace, "retriever", 10);
 printf("%ld ", NSSearch(NameSpace, "james"));
 printf("%ld ", NSSearch(NameSpace, "rogers"));
 printf("%ld ", NSSearch(NameSpace, "bob"));
 printf("%ld ", NSSearch(NameSpace, "aaa"));
 printf("%ld ", NSSearch(NameSpace, "bobabcdefghijklmnopqrstuv"));
 printf("%ld ", NSSearch(NameSpace, "bobabcdefghij"));
 printf("%ld ", NSSearch(NameSpace, "fred"));
 printf("%ld ", NSSearch(NameSpace, "This is a very/long/test of /multiple dirs/"));
 printf("%ld ", NSSearch(NameSpace, "This is a very/long/test of /multiple dirs/me too"));
 printf("%ld ", NSSearch(NameSpace, "harry"));
 printf("%ld  ", NSSearch(NameSpace, "retriever"));
 printf("%ld ", NSSearch(NameSpace, "I don't exist"));
 printf("%d ", NSDelete(NameSpace, "bobabcdefghij") );
 printf("%d ", NSDelete(NameSpace, "bobabcdefghij") );
 printf("%d  ", NSDelete(NameSpace, "I don't exist") );
 printf("%ld ", NSSearch(NameSpace, "bob"));
 printf("%ld ", NSSearch(NameSpace, "bobabcdefghijklmnopqrstuv"));
 printf("%ld ", NSSearch(NameSpace, "bobabcdefghij"));
 NSInsert(NameSpace, "james", 1000);
 printf("%ld\n", NSSearch(NameSpace, "james"));
    }
 NSRelease(NameSpace);
 usleep (0);
 fprintf(stderr,".");
  }
 fprintf(stderr,"\n");
 return 0;
}

canonical_original_code:
int NameSpaceTest(){
 struct NSObj *NameSpace;
 int i; int j;
 char string[1024];
  for (j=0; j<=10; j++) {
 NameSpace = NSCreate();
    for (i=0; i <= 10000; i++) {
 sprintf(string, "lksdfhjklsdfjklsdfhjklsdfhjklsdfh%d/test0/test1/test2/test3/test4/%d", i/10, j);
 NSInsert(NameSpace, string, i);
 printf("%ld\n", NSSearch(NameSpace, string));
 NSInsert(NameSpace, "james", 1);
 NSInsert(NameSpace, "rogers", 2);
 NSInsert(NameSpace, "bob", 3);
 NSInsert(NameSpace, "aaa", 3);
 NSInsert(NameSpace, "bobabcdefghijklmnopqrstuv", 4);
 NSInsert(NameSpace, "bobabcdefghij", 5);
 NSInsert(NameSpace, "fred", 6);
 NSInsert(NameSpace, "This is a very/long/test of /multiple dirs/", 7);
 NSInsert(NameSpace, "This is a very/long/test of /multiple dirs/me too", 8);
 NSInsert(NameSpace, "harry", 9);
 NSInsert(NameSpace, "retriever", 10);
 printf("%ld ", NSSearch(NameSpace, "james"));
 printf("%ld ", NSSearch(NameSpace, "rogers"));
 printf("%ld ", NSSearch(NameSpace, "bob"));
 printf("%ld ", NSSearch(NameSpace, "aaa"));
 printf("%ld ", NSSearch(NameSpace, "bobabcdefghijklmnopqrstuv"));
 printf("%ld ", NSSearch(NameSpace, "bobabcdefghij"));
 printf("%ld ", NSSearch(NameSpace, "fred"));
 printf("%ld ", NSSearch(NameSpace, "This is a very/long/test of /multiple dirs/"));
 printf("%ld ", NSSearch(NameSpace, "This is a very/long/test of /multiple dirs/me too"));
 printf("%ld ", NSSearch(NameSpace, "harry"));
 printf("%ld  ", NSSearch(NameSpace, "retriever"));
 printf("%ld ", NSSearch(NameSpace, "I don't exist"));
 printf("%d ", NSDelete(NameSpace, "bobabcdefghij") );
 printf("%d ", NSDelete(NameSpace, "bobabcdefghij") );
 printf("%d  ", NSDelete(NameSpace, "I don't exist") );
 printf("%ld ", NSSearch(NameSpace, "bob"));
 printf("%ld ", NSSearch(NameSpace, "bobabcdefghijklmnopqrstuv"));
 printf("%ld ", NSSearch(NameSpace, "bobabcdefghij"));
 NSInsert(NameSpace, "james", 1000);
 printf("%ld\n", NSSearch(NameSpace, "james"));
    }
 NSRelease(NameSpace);
 usleep (0);
 fprintf(stderr,".");
  }
 fprintf(stderr,"\n");
 return 0;
}

variable_types: i int

variable_types: j int

variable_types:
string
char [1024]


decompiled_code:
__int64 Handle_Message()
{
DebugPrint("Handling a message.", "writer.c", 27LL, 4LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
DebugPrint("Handling a message.", "writer.c", 27LL, 4LL);
return 0LL;
}

original_code:
int Handle_Message(NodeObj instance, MsgId message, NodeObj data){
 DebugPrint ( "Handling a message.", "writer.c", 27, OBJMSGHANDLING);
 return rtrn_handled;
}

canonical_original_code:
int Handle_Message(void *instance, int message, void *data){
 DebugPrint ( "Handling a message.", "writer.c", 27, OBJMSGHANDLING);
 return rtrn_handled;
}

variable_types:
instance
void *

variable_types: message int

variable_types:
data
void *


decompiled_code:
// attributes: thunk
__int64 Class_End()
{
return Class_Start_localalias();
}

canonical_decompiled_code:
__int64 func4()
{
return func3();
}

original_code:
int
Class_End(NodeObj instance, MsgId message, NodeObj data){
 return rtrn_handled;
}

canonical_original_code:
int Class_End(void *instance, int message, void *data){
 return rtrn_handled;
}


decompiled_code:
// attributes: thunk
__int64 Instance_End()
{
return Instance_Start_localalias();
}

canonical_decompiled_code:
__int64 func6()
{
return func5();
}

original_code:
int
Instance_End(NodeObj instance, MsgId message, NodeObj data){
 return rtrn_propagate;
}

canonical_original_code:
int Instance_End(void *instance, int message, void *data){
 return rtrn_propagate;
}


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

v1 = GetPropNode(a1, "Active");
GetInt(v1);
return 1LL;
}

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

v1 = GetPropNode(a1, "Active");
GetInt(v1);
return 1LL;
}

original_code:
int
In_Intercept(NodeObj instance, NodeObj property, MsgId message, NodeObj data){
 if (GetInt(GetPropNode(instance, "Active"))){
 }
 return rtrn_propagate;
}

canonical_original_code:
int In_Intercept(void *instance, void *property, int message, void *data){
 if (GetInt(GetPropNode(instance, "Active"))){
 }
 return rtrn_propagate;
}

variable_types:
property
void *


decompiled_code:
// attributes: thunk
__int64 Activate_Intercept()
{
return Instance_Start_localalias();
}

canonical_decompiled_code:
__int64 func8()
{
return func5();
}

original_code:
int
Activate_Intercept(NodeObj instance, MsgId message, NodeObj data){
 return rtrn_propagate;
}

canonical_original_code:
int Activate_Intercept(void *instance, int message, void *data){
 return rtrn_propagate;
}


decompiled_code:
// attributes: thunk
__int64 Echo_Intercept()
{
return Instance_Start_localalias();
}

canonical_decompiled_code:
__int64 func9()
{
return func5();
}

original_code:
int
Echo_Intercept(NodeObj instance, MsgId message, NodeObj data){
 return rtrn_propagate;
}

canonical_original_code:
int Echo_Intercept(void *instance, int message, void *data){
 return rtrn_propagate;
}


main

canonical_name: main

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

v3 = NewNode();
SetPropInt();
TimeUpdate();
DebugPrint();
ProcessCmdLine(v3, (unsigned int)argc, argv);
Init(v3);
InstallObjects();
LoadDefaultApp(v3);
DebugPrint();
while ( (unsigned int)IsRunning(v3, "main.c") )
{
MainLoop(v3);
usleep(0xAu);
}
DebugPrint();
GetPropNode();
if ( (unsigned int)GetValueInt() )
{
DebugPrint();
PrintNode();
}
return 0;
}

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

v3 = NewNode();
SetPropInt();
TimeUpdate();
DebugPrint();
func14(v3, (unsigned int)argc, argv);
func12(v3);
func13();
func10(v3);
DebugPrint();
while ( (unsigned int)func9(v3, "main.c") )
{
func7(v3);
usleep(0xAu);
}
DebugPrint();
GetPropNode();
if ( (unsigned int)GetValueInt() )
{
DebugPrint();
PrintNode();
}
return 0;
}

original_code:
int
main ( int argc, char* argv[] ){
 NodeObj Main = NewNode();
 SetPropInt(Main, "State", Starting);
 TimeUpdate();
 DebugPrint ( "Entering Main", "main.c", 429, PROG_FLOW);
 ProcessCmdLine(Main, argc, argv);
 Init(Main);
 InstallObjects();
 LoadDefaultApp(Main);
 DebugPrint ( "Entering Main Loop.", "main.c", 439, PROG_FLOW);
 while(IsRunning(Main)){
  MainLoop(Main);
  usleep(10);
 }
 DebugPrint ( "No more tasks scheduled, cleaning up and exiting", "main.c", 447, PROG_FLOW);
 if (GetValueInt(GetPropNode(Main, "PrintNodes"))) {
  DebugPrint ( "Dumping Main Node on exit because -p was passed on command line.\n", "main.c", 450, PROG_FLOW);
  PrintNode(Main);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 void *Main = NewNode();
 SetPropInt(Main, "State", Starting);
 TimeUpdate();
 DebugPrint ( "Entering Main", "main.c", 429, PROG_FLOW);
 ProcessCmdLine(Main, argc, argv);
 Init(Main);
 InstallObjects();
 LoadDefaultApp(Main);
 DebugPrint ( "Entering Main Loop.", "main.c", 439, PROG_FLOW);
 while(IsRunning(Main)){
  MainLoop(Main);
  usleep(10);
 }
 DebugPrint ( "No more tasks scheduled, cleaning up and exiting", "main.c", 447, PROG_FLOW);
 if (GetValueInt(GetPropNode(Main, "PrintNodes"))) {
  DebugPrint ( "Dumping Main Node on exit because -p was passed on command line.\n", "main.c", 450, PROG_FLOW);
  PrintNode(Main);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
Main
void *


MainLoop

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

if ( (unsigned int)TimeUpdate() )
AdjustDelayedTasks();
result = ExecTasks();
if ( !(_DWORD)result )
result = SetPropInt();
return result;
}

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

if ( (unsigned int)TimeUpdate() )
AdjustDelayedTasks();
result = ExecTasks();
if ( !(_DWORD)result )
result = SetPropInt();
return result;
}

original_code:
void
MainLoop(NodeObj Main){
 long offset;
 int CountOfScheduledTasks = 0;
 offset = TimeUpdate();
 if ( offset )
  AdjustDelayedTasks (Tasks, offset);
 CountOfScheduledTasks = ExecTasks(Tasks);
 if (CountOfScheduledTasks == 0)
  SetPropInt(Main, "State", Stopping);
}

canonical_original_code:
void MainLoop(void *Main){
 long offset;
 int CountOfScheduledTasks = 0;
 offset = TimeUpdate();
 if ( offset )
  AdjustDelayedTasks (Tasks, offset);
 CountOfScheduledTasks = ExecTasks(Tasks);
 if (CountOfScheduledTasks == 0)
  SetPropInt(Main, "State", Stopping);
}

variable_types: offset long

variable_types: CountOfScheduledTasks int

return_type: void


CreateTestApp

decompiled_code:
__int64 CreateTestApp()
{
CreateContainer();
CreateObject();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropInt();
CreateObject();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropInt();
return Connect();
}

canonical_decompiled_code:
__int64 func8()
{
CreateContainer();
CreateObject();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropInt();
CreateObject();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropInt();
return Connect();
}

original_code:
void
CreateTestApp(NodeObj Main){
 NodeObj TestApp = CreateContainer(Main, "TestApp");
 NodeObj WriteFile = CreateObject(TestApp, "File");
 SetPropStr (WriteFile, "Name", "Writer");
 SetPropStr (WriteFile, "Path", "out.txt");
 SetPropStr (WriteFile, "Mode", "w");
 SetPropInt (WriteFile, "State", 1);
 NodeObj ReadFile = CreateObject(TestApp, "File");
 SetPropStr (ReadFile, "Name", "Reader");
 SetPropStr (ReadFile, "Path", "in.txt");
 SetPropStr (ReadFile, "Mode", "r");
 SetPropInt (ReadFile, "State", 1);
 Connect(ReadFile, "Out", WriteFile, "In");
}

canonical_original_code:
void CreateTestApp(void *Main){
 void *TestApp = CreateContainer(Main, "TestApp");
 void *WriteFile = CreateObject(TestApp, "File");
 SetPropStr (WriteFile, "Name", "Writer");
 SetPropStr (WriteFile, "Path", "out.txt");
 SetPropStr (WriteFile, "Mode", "w");
 SetPropInt (WriteFile, "State", 1);
 void *ReadFile = CreateObject(TestApp, "File");
 SetPropStr (ReadFile, "Name", "Reader");
 SetPropStr (ReadFile, "Path", "in.txt");
 SetPropStr (ReadFile, "Mode", "r");
 SetPropInt (ReadFile, "State", 1);
 Connect(ReadFile, "Out", WriteFile, "In");
}

variable_types:
TestApp
void *

variable_types:
WriteFile
void *

variable_types:
ReadFile
void *


IsRunning

decompiled_code:
__int64 IsRunning()
{
GetPropNode();
GetValueNode();
return GetInt();
}

canonical_decompiled_code:
__int64 func9()
{
GetPropNode();
GetValueNode();
return GetInt();
}

original_code:
int
IsRunning(NodeObj Main){
 return (GetInt((DataObj)GetValueNode(GetPropNode(Main, "State"))));
}

canonical_original_code:
int IsRunning(void *Main){
 return (GetInt((void *)GetValueNode(GetPropNode(Main, "State"))));
}


LoadDefaultApp

decompiled_code:
__int64 __fastcall LoadDefaultApp(__int64 a1)
{
DebugPrint();
return CreateTestApp(a1, "main.c");
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
DebugPrint();
return func8(a1, "main.c");
}

original_code:
void
LoadDefaultApp(NodeObj Main){
 DebugPrint ( "Entering Default Application function.", "main.c", 188, PROG_FLOW);
 CreateTestApp(Main);
}

canonical_original_code:
void LoadDefaultApp(void *Main){
 DebugPrint ( "Entering Default Application function.", "main.c", 188, PROG_FLOW);
 CreateTestApp(Main);
}


PerformTesting

decompiled_code:
__int64 PerformTesting()
{
DebugPrint();
DataTest();
NodeTest();
BuffTest();
NameSpaceTest();
return SchedTest();
}

canonical_decompiled_code:
__int64 func11()
{
DebugPrint();
DataTest();
NodeTest();
BuffTest();
NameSpaceTest();
return SchedTest();
}

original_code:
void
PerformTesting(){
 DebugPrint ( "Entering Perform Testing function.", "main.c", 195, PROG_FLOW);
 DataTest();
 NodeTest();
 BuffTest();
 NameSpaceTest();
 SchedTest();
}


Init

decompiled_code:
__int64 Init()
{
__int64 v0; // rdi
_BYTE *v1; // rax
__int64 result; // rax

DebugPrint();
SetName();
SetPropInt();
GetPropNode();
ObjSetRegObjList();
SetPropInt();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropStr();
GetPropNode();
if ( (unsigned int)GetValueInt() )
printf(
"%s %s.%s %s - (C) %s %s\n"
"%s\n"
"http://grokthink.org\n"
"\n"
" Usage: framework <options>\n"
"\n"
" Options:\n"
"\n"
" -h : This help screen\n"
" -d : Become a server process\n"
" -l <logfile> : logfile to output debug info\n"
" -p : Print Main Nodes on exit\n"
" -t : Perform Unit Testing of library functions\n"
" -v <number> : Verbose level from 0 to 9, inclusive\n"
"\n",
"Bilbo",
"0",
"1",
"Alpha",
"2009",
"James M. Rogers",
"One framework to rule them all and in the darkness bind them!");
v0 = GetPropNode();
if ( (unsigned int)GetValueInt() )
PerformTesting(v0, "UnitTest");
GetPropNode();
if ( (unsigned int)GetValueInt() )
{
DebugPrint();
become_deamon();
}
GetPropNode();
v1 = (_BYTE *)GetValueStr();
if ( v1 && *v1 )
DebugPrint();
DebugPrint();
result = CreateList();
Tasks = result;
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rdi
_BYTE *v1; // rax
__int64 result; // rax

DebugPrint();
SetName();
SetPropInt();
GetPropNode();
ObjSetRegObjList();
SetPropInt();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropStr();
SetPropStr();
GetPropNode();
if ( (unsigned int)GetValueInt() )
printf(
"%s %s.%s %s - (C) %s %s\n"
"%s\n"
"http://grokthink.org\n"
"\n"
" Usage: framework <options>\n"
"\n"
" Options:\n"
"\n"
" -h : This help screen\n"
" -d : Become a server process\n"
" -l <logfile> : logfile to output debug info\n"
" -p : Print Main Nodes on exit\n"
" -t : Perform Unit Testing of library functions\n"
" -v <number> : Verbose level from 0 to 9, inclusive\n"
"\n",
"Bilbo",
"0",
"1",
"Alpha",
"2009",
"James M. Rogers",
"One framework to rule them all and in the darkness bind them!");
v0 = GetPropNode();
if ( (unsigned int)GetValueInt() )
func11(v0, "UnitTest");
GetPropNode();
if ( (unsigned int)GetValueInt() )
{
DebugPrint();
become_deamon();
}
GetPropNode();
v1 = (_BYTE *)GetValueStr();
if ( v1 && *v1 )
DebugPrint();
DebugPrint();
result = CreateList();
Tasks = result;
return result;
}

original_code:
void
Init(NodeObj Main){
 char * logname;
 NodeObj RegObjList;
 DebugPrint ( "Entering Init function.", "main.c", 216, PROG_FLOW);
 SetName (Main, "Main");
 SetPropInt(Main, "RegObjList", 1);
 RegObjList = GetPropNode(Main, "RegObjList");
 ObjSetRegObjList(RegObjList);
 SetPropInt(Main, "State", Running);
 SetPropStr(Main, "ReleaseMajor", "0");
 SetPropStr(Main, "ReleaseName", "Bilbo");
 SetPropStr(Main, "ReleaseMinor", "1");
 SetPropStr(Main, "ReleaseLevel", "Alpha");
 SetPropStr(Main, "Copyright", "2009");
 SetPropStr(Main, "Author", "James M. Rogers");
 SetPropStr(Main, "ReleaseTag", "One framework to rule them all and in the darkness bind them!");
 if (GetValueInt(GetPropNode(Main, "printhelp"))) {
  printf ("%s %s.%s %s - (C) %s %s\n%s\nhttp://grokthink.org\n\n  Usage: framework <options>\n\n  Options:\n\n       -h              : This help screen\n       -d              : Become a server process\n       -l    <logfile> : logfile to output debug info\n       -p              : Print Main Nodes on exit\n       -t              : Perform Unit Testing of library functions\n       -v     <number> : Verbose level from 0 to 9, inclusive\n\n", "Bilbo", "0", "1", "Alpha", "2009", "James M. Rogers", "One framework to rule them all and in the darkness bind them!");
 }
 if (GetValueInt(GetPropNode(Main, "UnitTest"))) {
  PerformTesting();
 }
 if (GetValueInt(GetPropNode(Main, "deamon"))) {
  DebugPrint ( "Becoming a Deamon.", "main.c", 255, PROG_FLOW);
  become_deamon ();
 }
 logname = GetValueStr(GetPropNode(Main, "logname"));
 if (logname && strlen(logname)) {
  DebugPrint ( "Verbose Logging Enabled.", "main.c", 264, PROG_FLOW);
  ;
 }
 DebugPrint ( "Logging Level Set.", "main.c", 270, PROG_FLOW);
 Tasks = CreateList();
}

canonical_original_code:
void Init(void *Main){
 char *logname;
 void *RegObjList;
 DebugPrint ( "Entering Init function.", "main.c", 216, PROG_FLOW);
 SetName (Main, "Main");
 SetPropInt(Main, "RegObjList", 1);
 RegObjList = GetPropNode(Main, "RegObjList");
 ObjSetRegObjList(RegObjList);
 SetPropInt(Main, "State", Running);
 SetPropStr(Main, "ReleaseMajor", "0");
 SetPropStr(Main, "ReleaseName", "Bilbo");
 SetPropStr(Main, "ReleaseMinor", "1");
 SetPropStr(Main, "ReleaseLevel", "Alpha");
 SetPropStr(Main, "Copyright", "2009");
 SetPropStr(Main, "Author", "James M. Rogers");
 SetPropStr(Main, "ReleaseTag", "One framework to rule them all and in the darkness bind them!");
 if (GetValueInt(GetPropNode(Main, "printhelp"))) {
  printf ("%s %s.%s %s - (C) %s %s\n%s\nhttp://grokthink.org\n\n  Usage: framework <options>\n\n  Options:\n\n       -h              : This help screen\n       -d              : Become a server process\n       -l    <logfile> : logfile to output debug info\n       -p              : Print Main Nodes on exit\n       -t              : Perform Unit Testing of library functions\n       -v     <number> : Verbose level from 0 to 9, inclusive\n\n", "Bilbo", "0", "1", "Alpha", "2009", "James M. Rogers", "One framework to rule them all and in the darkness bind them!");
 }
 if (GetValueInt(GetPropNode(Main, "UnitTest"))) {
  PerformTesting();
 }
 if (GetValueInt(GetPropNode(Main, "deamon"))) {
  DebugPrint ( "Becoming a Deamon.", "main.c", 255, PROG_FLOW);
  become_deamon ();
 }
 logname = GetValueStr(GetPropNode(Main, "logname"));
 if (logname && strlen(logname)) {
  DebugPrint ( "Verbose Logging Enabled.", "main.c", 264, PROG_FLOW);
  ;
 }
 DebugPrint ( "Logging Level Set.", "main.c", 270, PROG_FLOW);
 Tasks = CreateList();
}

variable_types:
logname
char *

variable_types:
RegObjList
void *


InstallObjects

decompiled_code:
__int64 InstallObjects()
{
DebugPrint();
return ScanDir();
}

canonical_decompiled_code:
__int64 func13()
{
DebugPrint();
return ScanDir();
}

original_code:
void InstallObjects(void)
{
 DebugPrint ( "Entering Install Objects function.", "main.c", 280, PROG_FLOW);
        ScanDir (".", ".object", (void *) LoadObject, 8, 0, PreOrder);
}

canonical_original_code:
void InstallObjects()
{
 DebugPrint ( "Entering Install Objects function.", "main.c", 280, PROG_FLOW);
        ScanDir (".", ".object", (void *) LoadObject, 8, 0, PreOrder);
}


ProcessCmdLine

decompiled_code:
__int64 __fastcall ProcessCmdLine(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax
_BYTE **v5; // r12
int v6; // ebx
_BYTE *v7; // rax
__int64 v8; // r12
__int64 v9; // r12
const char *v10; // rdi
char v11; // r15
size_t v12; // rax

DebugPrint();
DebugPrint();
result = SetPropInt();
if ( a2 <= 0 )
return result;
DebugPrint();
DebugPrint();
result = SetPropStr();
if ( a2 == 1 )
return result;
v5 = (_BYTE **)(a3 + 8);
v6 = 1;
DebugPrint();
while ( 2 )
{
v7 = *v5;
if ( **v5 != 45 )
break;
v8 = a3 + 8LL * v6;
while ( 1 )
{
if ( *v7 != 45 )
goto LABEL_10;
if ( v7[1] == 108 && !v7[2] )
{
if ( a2 <= v6 + 1 || (v9 = 8LL * (v6 + 1), DebugPrint(), **(_BYTE **)(a3 + v9) == 45) )
{
LABEL_10:
DebugPrint();
return SetPropInt();
}
v6 += 2;
DebugPrint();
result = SetPropStr();
if ( a2 <= v6 )
return result;
v5 = (_BYTE **)(a3 + v9 + 8);
goto LABEL_6;
}
if ( v7[1] == 104 && !v7[2] || v7[1] == 116 && !v7[2] )
goto LABEL_4;
if ( v7[1] != 118 || v7[2] )
break;
if ( a2 <= v6 + 1 )
goto LABEL_10;
DebugPrint();
v10 = *(const char **)(v8 + 8);
v11 = *v10;
if ( *v10 == 45 )
goto LABEL_10;
v12 = strlen(v10);
if ( (unsigned __int8)(v11 - 48) > 9u || v12 > 1 )
goto LABEL_10;
v6 += 2;
DebugPrint();
result = SetPropInt();
if ( a2 <= v6 )
return result;
v8 += 16LL;
DebugPrint();
v7 = *(_BYTE **)v8;
if ( **(_BYTE **)v8 != 45 )
goto LABEL_4;
}
if ( v7[1] != 100 || v7[2] )
{
if ( v7[1] != 112 || v7[2] )
goto LABEL_10;
++v6;
DebugPrint();
result = SetPropInt();
if ( a2 <= v6 )
return result;
LABEL_5:
v5 = (_BYTE **)(a3 + 8LL * v6);
LABEL_6:
DebugPrint();
continue;
}
break;
}
LABEL_4:
DebugPrint();
result = SetPropInt();
if ( a2 > ++v6 )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax
_BYTE **v5; // r12
int v6; // ebx
_BYTE *v7; // rax
__int64 v8; // r12
__int64 v9; // r12
const char *v10; // rdi
char v11; // r15
size_t v12; // rax

DebugPrint();
DebugPrint();
result = SetPropInt();
if ( a2 <= 0 )
return result;
DebugPrint();
DebugPrint();
result = SetPropStr();
if ( a2 == 1 )
return result;
v5 = (_BYTE **)(a3 + 8);
v6 = 1;
DebugPrint();
while ( 2 )
{
v7 = *v5;
if ( **v5 != 45 )
break;
v8 = a3 + 8LL * v6;
while ( 1 )
{
if ( *v7 != 45 )
goto LABEL_10;
if ( v7[1] == 108 && !v7[2] )
{
if ( a2 <= v6 + 1 || (v9 = 8LL * (v6 + 1), DebugPrint(), **(_BYTE **)(a3 + v9) == 45) )
{
LABEL_10:
DebugPrint();
return SetPropInt();
}
v6 += 2;
DebugPrint();
result = SetPropStr();
if ( a2 <= v6 )
return result;
v5 = (_BYTE **)(a3 + v9 + 8);
goto LABEL_6;
}
if ( v7[1] == 104 && !v7[2] || v7[1] == 116 && !v7[2] )
goto LABEL_4;
if ( v7[1] != 118 || v7[2] )
break;
if ( a2 <= v6 + 1 )
goto LABEL_10;
DebugPrint();
v10 = *(const char **)(v8 + 8);
v11 = *v10;
if ( *v10 == 45 )
goto LABEL_10;
v12 = strlen(v10);
if ( (unsigned __int8)(v11 - 48) > 9u || v12 > 1 )
goto LABEL_10;
v6 += 2;
DebugPrint();
result = SetPropInt();
if ( a2 <= v6 )
return result;
v8 += 16LL;
DebugPrint();
v7 = *(_BYTE **)v8;
if ( **(_BYTE **)v8 != 45 )
goto LABEL_4;
}
if ( v7[1] != 100 || v7[2] )
{
if ( v7[1] != 112 || v7[2] )
goto LABEL_10;
++v6;
DebugPrint();
result = SetPropInt();
if ( a2 <= v6 )
return result;
LABEL_5:
v5 = (_BYTE **)(a3 + 8LL * v6);
LABEL_6:
DebugPrint();
continue;
}
break;
}
LABEL_4:
DebugPrint();
result = SetPropInt();
if ( a2 > ++v6 )
goto LABEL_5;
return result;
}

original_code:
void
ProcessCmdLine(NodeObj Main, int argc, char * argv[]){
 int i=0;
 int state=STORE_FILENAME;
 DebugPrint ( "Entering Process Command Line Function.", "main.c", 294, PROG_FLOW);
 DebugPrint ( "Store default verbose logging level of 1.", "main.c", 296, CMDLINEOPTS);
 SetPropInt(Main, "loglevel", 1);
 while(i < argc){
  DebugPrint ( argv[i], "main.c", 303, CMDLINEOPTS);
  switch (state){
  case STORE_LOGLEVEL:
   if ( argv[i][0]=='-' ) {
    DebugPrint ( "Option found instead of loglevel.", "main.c", 308, ERROR);
    SetPropInt(Main, "printhelp", 1);
    return;
   } else {
    if (strlen (argv[i]) > 1 || argv[i][0]-'0' < 0 || argv[i][0]-'0' > 9) {
     DebugPrint ( "Log level not between 0 to 9, inclusive.", "main.c", 314, ERROR);
     SetPropInt(Main, "printhelp", 1);
     return;
    }
    DebugPrint ( "Store log level.", "main.c", 319, CMDLINEOPTS);
    SetPropInt(Main, "loglevel", argv[i][0]-'0');
   }
   state=STORE_OPTION;
   break;
  case STORE_FILENAME:
   DebugPrint ( "Store file name.", "main.c", 326, CMDLINEOPTS);
   SetPropStr(Main, "filename", argv[i]);
   state=STORE_OPTION;
   break;
  case STORE_LOGNAME:
   if ( argv[i][0]=='-' ) {
    DebugPrint ( "Option found instead of filename.", "main.c", 338, ERROR);
    SetPropInt(Main, "printhelp", 1);
    return;
   } else {
    DebugPrint ( "Store log name.", "main.c", 342, CMDLINEOPTS);
    SetPropStr(Main, "logname", argv[i]);
   }
   state=STORE_OPTION;
   break;
  case STORE_OPTION:
   if ( argv[i][0]!='-' ) {
    DebugPrint ( "Option not found.", "main.c", 351, ERROR);
    SetPropInt(Main, "printhelp", 1);
    break;
   } else {
    if ( strcmp ( argv[i], "-l" ) == 0 ) {
     state=STORE_LOGNAME;
     break;
    }
    if (strcmp ( argv[i], "-h" ) == 0 ) {
     DebugPrint ( "Store print help file.", "main.c", 362, CMDLINEOPTS);
     SetPropInt(Main, "printhelp", 1);
     break;
    }
    if (strcmp ( argv[i], "-t" ) == 0 ) {
     DebugPrint ( "Store perform unit tests.", "main.c", 368, CMDLINEOPTS);
     SetPropInt(Main, "UnitTest", 1);
     break;
    }
    if (strcmp ( argv[i], "-v" ) == 0 ) {
     state = STORE_LOGLEVEL;
     break;
    }
    if (strcmp ( argv[i], "-d" ) == 0 ) {
     DebugPrint ( "Store become deamon.", "main.c", 379, CMDLINEOPTS);
     SetPropInt(Main, "deamon", 1);
     break;
    }
    if (strcmp ( argv[i], "-p" ) == 0 ) {
     DebugPrint ( "Store print nodes on exit.", "main.c", 385, CMDLINEOPTS);
     SetPropInt(Main, "PrintNodes", 1);
     break;
    }
    DebugPrint ( "Unknown Option.", "main.c", 390, ERROR);
    SetPropInt(Main, "printhelp", 1);
    return;
   }
   break;
  default:
   DebugPrint ( "Option Not Found.", "main.c", 398, ERROR);
   SetPropInt(Main, "printhelp", 1);
  }
  i++;
 }
 if (state == STORE_LOGNAME) {
  DebugPrint ( "Log filename not given.", "main.c", 405, ERROR);
  SetPropInt(Main, "printhelp", 1);
  return;
 }
 if (state == STORE_LOGLEVEL) {
  DebugPrint ( "Verbose log level not given.", "main.c", 411, ERROR);
  SetPropInt(Main, "printhelp", 1);
  return;
 }
}

canonical_original_code:
void ProcessCmdLine(void *Main, int argc, char *argv[]){
 int i = 0;
 int state = STORE_FILENAME;
 DebugPrint ( "Entering Process Command Line Function.", "main.c", 294, PROG_FLOW);
 DebugPrint ( "Store default verbose logging level of 1.", "main.c", 296, CMDLINEOPTS);
 SetPropInt(Main, "loglevel", 1);
 while(i < argc){
  DebugPrint ( argv[i], "main.c", 303, CMDLINEOPTS);
  switch (state){
  case STORE_LOGLEVEL:
   if ( argv[i][0]=='-' ) {
    DebugPrint ( "Option found instead of loglevel.", "main.c", 308, ERROR);
    SetPropInt(Main, "printhelp", 1);
    return;
   } else {
    if (strlen (argv[i]) > 1 || argv[i][0]-'0' < 0 || argv[i][0]-'0' > 9) {
     DebugPrint ( "Log level not between 0 to 9, inclusive.", "main.c", 314, ERROR);
     SetPropInt(Main, "printhelp", 1);
     return;
    }
    DebugPrint ( "Store log level.", "main.c", 319, CMDLINEOPTS);
    SetPropInt(Main, "loglevel", argv[i][0]-'0');
   }
   state=STORE_OPTION;
   break;
  case STORE_FILENAME:
   DebugPrint ( "Store file name.", "main.c", 326, CMDLINEOPTS);
   SetPropStr(Main, "filename", argv[i]);
   state=STORE_OPTION;
   break;
  case STORE_LOGNAME:
   if ( argv[i][0]=='-' ) {
    DebugPrint ( "Option found instead of filename.", "main.c", 338, ERROR);
    SetPropInt(Main, "printhelp", 1);
    return;
   } else {
    DebugPrint ( "Store log name.", "main.c", 342, CMDLINEOPTS);
    SetPropStr(Main, "logname", argv[i]);
   }
   state=STORE_OPTION;
   break;
  case STORE_OPTION:
   if ( argv[i][0]!='-' ) {
    DebugPrint ( "Option not found.", "main.c", 351, ERROR);
    SetPropInt(Main, "printhelp", 1);
    break;
   } else {
    if ( strcmp ( argv[i], "-l" ) == 0 ) {
     state=STORE_LOGNAME;
     break;
    }
    if (strcmp ( argv[i], "-h" ) == 0 ) {
     DebugPrint ( "Store print help file.", "main.c", 362, CMDLINEOPTS);
     SetPropInt(Main, "printhelp", 1);
     break;
    }
    if (strcmp ( argv[i], "-t" ) == 0 ) {
     DebugPrint ( "Store perform unit tests.", "main.c", 368, CMDLINEOPTS);
     SetPropInt(Main, "UnitTest", 1);
     break;
    }
    if (strcmp ( argv[i], "-v" ) == 0 ) {
     state = STORE_LOGLEVEL;
     break;
    }
    if (strcmp ( argv[i], "-d" ) == 0 ) {
     DebugPrint ( "Store become deamon.", "main.c", 379, CMDLINEOPTS);
     SetPropInt(Main, "deamon", 1);
     break;
    }
    if (strcmp ( argv[i], "-p" ) == 0 ) {
     DebugPrint ( "Store print nodes on exit.", "main.c", 385, CMDLINEOPTS);
     SetPropInt(Main, "PrintNodes", 1);
     break;
    }
    DebugPrint ( "Unknown Option.", "main.c", 390, ERROR);
    SetPropInt(Main, "printhelp", 1);
    return;
   }
   break;
  default:
   DebugPrint ( "Option Not Found.", "main.c", 398, ERROR);
   SetPropInt(Main, "printhelp", 1);
  }
  i++;
 }
 if (state == STORE_LOGNAME) {
  DebugPrint ( "Log filename not given.", "main.c", 405, ERROR);
  SetPropInt(Main, "printhelp", 1);
  return;
 }
 if (state == STORE_LOGLEVEL) {
  DebugPrint ( "Verbose log level not given.", "main.c", 411, ERROR);
  SetPropInt(Main, "printhelp", 1);
  return;
 }
}

variable_types: i int

variable_types: state int


BuffTest

decompiled_code:
__int64 BuffTest()
{
const char *v0; // r13
char *v1; // rbp
char *v2; // rbx
const char *v3; // rdi
const char *v4; // rdi
__int64 v5; // rbp
unsigned int v6; // eax
int v7; // er15
unsigned int v8; // er12
int v9; // ebx
unsigned int v10; // ebx
unsigned int v11; // eax
int v12; // ebx
int v13; // er15
int v14; // ebx
unsigned int v15; // ebx
unsigned int v16; // eax
unsigned int i; // er15
unsigned int v18; // eax
const char *v19; // rdi
const char *v21; // r8
__int64 v22; // r9
__int64 v23; // rcx
const char *v24; // rdx
__int64 v25; // rsi
char *v26; // [rsp+8h] [rbp-C3C0h]
const char *v27; // [rsp+18h] [rbp-C3B0h] BYREF
char v28[32]; // [rsp+20h] [rbp-C3A8h] BYREF
char dest[50000]; // [rsp+40h] [rbp-C388h] BYREF
char v30[56]; // [rsp+C390h] [rbp-38h] BYREF

v0 = dest;
v1 = v28;
v2 = dest;
memcpy(dest, "test\n", sizeof(dest));
v26 = v28;
do
{
v3 = v2;
v1 += 4;
v2 += 10000;
*((_DWORD *)v1 - 1) = strlen(v3);
}
while ( v2 != v30 );
if ( (unsigned int)buffTotalCount(0LL) )
puts("T01: Failed the total count should be equal to 0 ");
if ( (unsigned int)buffTotalSize(0LL) )
puts("T02: Failed the total size would be equal to 0 ");
puts("Creating a buffer of 0 bytes (will really create a buffer 1 byte long");
v4 = 0LL;
v5 = buffCreate(0LL);
if ( !v5 )
{
puts("T03: Could not buffCreate (0).");
exit(1);
}
if ( (unsigned int)buffTotalCount(0LL) != 1 )
{
v4 = "T04: Failed should be 1 ";
puts("T04: Failed should be 1 ");
}
if ( (unsigned int)buffTotalSize(v4) != 1 )
{
puts("T05: Failed Should be 1 ");
exit(1);
}
if ( (unsigned int)buffCountResetEmpty(v5) )
{
puts("Y39: Failed Should be zero ");
exit(1);
}
if ( (unsigned int)buffCountMovedForward(v5) )
{
puts("Y37: Failed Should be zero ");
exit(1);
}
if ( (unsigned int)buffCountReallocs(v5) )
{
puts("Y41: Failed Should be zero ");
exit(1);
}
if ( (unsigned int)buffCountInserts(v5) )
{
puts("Y43: Failed Should be zero");
exit(1);
}
if ( (unsigned int)buffCountRetrievals(v5) )
{
puts("Y45: Failed Should be zero");
exit(1);
}
if ( (unsigned int)buffDestroy(0LL) )
{
puts("A02: Failed buffDestroy must return a 0 if given a NULL pointer.");
exit(1);
}
if ( (unsigned int)buffAdd(0LL, "test", 5LL) )
{
puts("A03: Failed buffAdd must return a 0 if given a NULL pointer. ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 0LL) )
{
puts("A04: Failed ");
exit(1);
}
if ( (unsigned int)buffAdd(v5, "test", 0xFFFFFFFFLL) )
{
puts("A05: Failed ");
exit(1);
}
if ( (unsigned int)buffAdd(v5, 0LL, 5LL) )
{
puts("A07: Failed must return a 0 if given a NULL pointer.");
exit(1);
}
if ( (unsigned int)buffGetLine(0LL, &v27) )
{
puts("A08: Failed must return a 0 if given a NULL pointer.");
exit(1);
}
if ( (unsigned int)buffGetLine(v5, 0LL) )
{
puts("A09: Failed must return a 0 if given a NULL pointer.");
exit(1);
}
buffClear(v5);
if ( !(unsigned int)buffAdd(v5, "\ntesta\rtestbb\r\ntestccc", 22LL) )
{
puts("A10: Failed buffAdd should return a 1 on successful insert.");
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) != 1 )
{
puts("A11: Failed buffGetLine() should return a 1 and a \\n here.");
exit(1);
}
if ( (_BYTE)v27 == 10 )
{
printf("A11a: Failed should be '%x' here, found '%x'.\n", 10LL, (unsigned int)*v27);
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) != 6 )
{
puts("A12: Failed buffGetLine() should return a 6 and a 'testa\\r' here.");
exit(1);
}
if ( (_DWORD)v27 == 1953719668 && WORD2(v27) == 3425 )
{
printf("A12a: Failed should be 'testa\\r' here, found '%s'.\n", v27);
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) != 8 )
{
puts("A13: Failed buffGetLine() should return an 8 and a 'testbb\\r\\n' here.");
exit(1);
}
if ( v27 == (const char *)0xA0D626274736574LL )
{
printf("A13a: Failed should be 'testbb\r\n' here, found '%s'.\n", (const char *)0xA0D626274736574LL);
exit(1);
}
v6 = buffGetLine(v5, &v27);
if ( v6 )
{
printf("A14: Failed buffGetLine() should return a 0 and a '' here. found %s of len %d\n", v27, v6);
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "\n", 1LL) )
{
puts("A14b: Failed buffAdd should return a 1 on successful insert.");
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) != 8 )
{
puts("A14c: Failed buffGetLine() should return an 8 and a 'testccc\\n' here.");
exit(1);
}
if ( v27 == (const char *)0xA63636374736574LL )
{
printf("A14d: Failed should be 'testccc\n' here, found '%s'.\n", (const char *)0xA63636374736574LL);
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) )
{
puts("A15: Failed buffGetLine() should return a 0 in an empty buffer.");
exit(1);
}
if ( (unsigned int)buffGetBlockFromTail(0LL, &v27, 5LL) )
goto LABEL_141;
if ( (unsigned int)buffGetBlockFromTail(v5, 0LL, 5LL) )
goto LABEL_140;
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
goto LABEL_139;
if ( !(unsigned int)buffGetBlockFromTail(v5, &v27, 4LL) )
goto LABEL_138;
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
goto LABEL_161;
if ( !(unsigned int)buffGetBlockFromTail(v5, &v27, 3LL) )
goto LABEL_160;
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
goto LABEL_159;
if ( !(unsigned int)buffGetBlockFromTail(v5, &v27, 10LL) )
goto LABEL_158;
if ( (unsigned int)buffGetBlockFromHead(0LL, &v27, 5LL) )
{
LABEL_141:
puts("A16: Failed ");
exit(1);
}
if ( (unsigned int)buffGetBlockFromHead(v5, 0LL, 5LL) )
{
LABEL_140:
puts("A17: Failed ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
{
LABEL_139:
puts("A18: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetBlockFromHead(v5, &v27, 4LL) )
{
LABEL_138:
puts("A19: Failed ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
{
LABEL_161:
puts("A20: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetBlockFromHead(v5, &v27, 3LL) )
{
LABEL_160:
puts("A21: Failed ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
{
LABEL_159:
puts("A22: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetBlockFromHead(v5, &v27, 10LL) )
{
LABEL_158:
puts("A23: Failed ");
exit(1);
}
if ( (unsigned int)buffResize(0LL, 50LL) )
{
puts("H01: Failed ");
exit(1);
}
if ( (unsigned int)buffResize(0LL, 2000000LL) )
{
puts("H03: Failed ");
exit(1);
}
if ( !(unsigned int)buffResize(v5, 16000LL) )
{
puts("H04: Failed ");
exit(1);
}
if ( (unsigned int)buffReallocAdjustment(0LL, 16000LL) )
{
puts("J01: Failed ");
exit(1);
}
if ( !(unsigned int)buffReallocAdjustment(v5, 16000LL) )
{
puts("J02: Failed ");
exit(1);
}
if ( (unsigned int)buffReallocAdjustment(0LL, 1600000LL) )
{
puts("J03: Failed ");
exit(1);
}
if ( !(unsigned int)buffReallocAdjustment(v5, 16000LL) )
{
puts("J04: Failed ");
exit(1);
}
if ( (unsigned int)buffGetBuffer(0LL, &v27) )
{
puts("A24: Failed ");
exit(1);
}
if ( (unsigned int)buffGetBuffer(v5, 0LL) )
{
puts("A25: Failed ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
{
puts("A26: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetBuffer(v5, &v27) )
{
puts("A27: Failed ");
exit(1);
}
if ( (unsigned int)buffGetSize(0LL) )
{
puts("A32: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetSize(v5) )
{
puts("A33: Failed ");
exit(1);
}
if ( (unsigned int)buffGetLength(0LL) )
{
puts("A34: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetLength(v5) )
puts("A35: Failed ");
if ( (unsigned int)buffCountMovedForward(0LL) )
{
puts("A36: Failed ");
exit(1);
}
if ( (unsigned int)buffCountResetEmpty(0LL) )
{
puts("A38: Failed ");
exit(1);
}
if ( (unsigned int)buffCountReallocs(0LL) )
{
puts("A40: Failed ");
exit(1);
}
if ( (unsigned int)buffCountInserts(0LL) )
{
puts("A42: Failed ");
exit(1);
}
if ( (unsigned int)buffCountRetrievals(0LL) )
{
puts("A44: Failed ");
exit(1);
}
if ( (unsigned int)buffClear(0LL) )
{
puts("A48: Failed ");
exit(1);
}
if ( !(unsigned int)buffClear(v5) )
{
puts("A49: Failed ");
exit(1);
}
do
{
v7 = 10;
printf("\nTesting is using this string:%s", v0);
printf("Inserting and removing %d lines, 10 times to test buffer growing functionality.\n", 10000LL);
v8 = *(_DWORD *)v26;
do
{
v9 = 10000;
do
{
if ( !(unsigned int)buffAdd(v5, v0, v8) )
{
LABEL_114:
puts("M01: Failed Could not add a string.");
exit(1);
}
--v9;
}
while ( v9 );
v10 = 0;
putchar(43);
fflush(0LL);
do
{
v11 = buffGetLine(v5, &v27);
if ( v11 != v8 )
{
printf(
"M03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
v10,
v0,
v8,
v27,
v11);
exit(1);
}
++v10;
}
while ( v10 != 10000 );
putchar(45);
fflush(0LL);
--v7;
}
while ( v7 );
v12 = 3333;
putchar(10);
fflush(0LL);
printf("Inserting and removing %d lines, 30 times to test buffer move to front functionality.\n", 3333LL);
do
{
if ( !(unsigned int)buffAdd(v5, v0, v8) )
goto LABEL_114;
--v12;
}
while ( v12 );
v13 = 29;
putchar(43);
fflush(0LL);
do
{
v14 = 3333;
do
{
if ( !(unsigned int)buffAdd(v5, v0, v8) )
{
puts("M02: Failed Could not add a string.");
exit(1);
}
--v14;
}
while ( v14 );
v15 = 0;
putchar(43);
fflush(0LL);
do
{
v16 = buffGetLine(v5, &v27);
if ( v8 != v16 )
{
v21 = v27;
v22 = v16;
v23 = v8;
v24 = v0;
v25 = v15;
goto LABEL_118;
}
++v15;
}
while ( v15 != 3333 );
putchar(45);
fflush(0LL);
--v13;
}
while ( v13 );
for ( i = 0; i != 3333; ++i )
{
v18 = buffGetLine(v5, &v27);
if ( v8 != v18 )
{
v21 = v27;
v22 = v18;
v23 = v8;
v24 = v0;
v25 = i;
LABEL_118:
printf(
"C03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
v25,
v24,
v23,
v21,
v22);
exit(1);
}
}
v0 += 10000;
putchar(45);
putchar(10);
fflush(0LL);
v26 += 4;
}
while ( v30 != v0 );
putchar(10);
if ( !(unsigned int)buffCountMovedForward(v5) )
puts("Q01: Failed ");
if ( !(unsigned int)buffCountReallocs(v5) )
puts("Q02: Failed ");
if ( !(unsigned int)buffCountInserts(v5) )
puts("Q03: Failed ");
if ( !(unsigned int)buffCountRetrievals(v5) )
puts("Q04: Failed ");
puts("Destroying a buffer.");
v19 = (const char *)v5;
if ( !(unsigned int)buffDestroy(v5) )
{
v19 = "Q05: Failed Could not buffDestroy";
puts("Q05: Failed Could not buffDestroy");
}
if ( (unsigned int)buffTotalCount(v19) )
{
v19 = "Q06: Failed the total count should be equal to 0 ";
puts("Q06: Failed the total count should be equal to 0 ");
}
if ( (unsigned int)buffTotalSize(v19) )
puts("Q07: Failed the total size would be equal to 0 ");
puts("Completed tests.");
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // r13
char *v1; // rbp
char *v2; // rbx
const char *v3; // rdi
const char *v4; // rdi
__int64 v5; // rbp
unsigned int v6; // eax
int v7; // er15
unsigned int v8; // er12
int v9; // ebx
unsigned int v10; // ebx
unsigned int v11; // eax
int v12; // ebx
int v13; // er15
int v14; // ebx
unsigned int v15; // ebx
unsigned int v16; // eax
unsigned int i; // er15
unsigned int v18; // eax
const char *v19; // rdi
const char *v21; // r8
__int64 v22; // r9
__int64 v23; // rcx
const char *v24; // rdx
__int64 v25; // rsi
char *v26; // [rsp+8h] [rbp-C3C0h]
const char *v27; // [rsp+18h] [rbp-C3B0h] BYREF
char v28[32]; // [rsp+20h] [rbp-C3A8h] BYREF
char dest[50000]; // [rsp+40h] [rbp-C388h] BYREF
char v30[56]; // [rsp+C390h] [rbp-38h] BYREF

v0 = dest;
v1 = v28;
v2 = dest;
memcpy(dest, "test\n", sizeof(dest));
v26 = v28;
do
{
v3 = v2;
v1 += 4;
v2 += 10000;
*((_DWORD *)v1 - 1) = strlen(v3);
}
while ( v2 != v30 );
if ( (unsigned int)buffTotalCount(0LL) )
puts("T01: Failed the total count should be equal to 0 ");
if ( (unsigned int)buffTotalSize(0LL) )
puts("T02: Failed the total size would be equal to 0 ");
puts("Creating a buffer of 0 bytes (will really create a buffer 1 byte long");
v4 = 0LL;
v5 = buffCreate(0LL);
if ( !v5 )
{
puts("T03: Could not buffCreate (0).");
exit(1);
}
if ( (unsigned int)buffTotalCount(0LL) != 1 )
{
v4 = "T04: Failed should be 1 ";
puts("T04: Failed should be 1 ");
}
if ( (unsigned int)buffTotalSize(v4) != 1 )
{
puts("T05: Failed Should be 1 ");
exit(1);
}
if ( (unsigned int)buffCountResetEmpty(v5) )
{
puts("Y39: Failed Should be zero ");
exit(1);
}
if ( (unsigned int)buffCountMovedForward(v5) )
{
puts("Y37: Failed Should be zero ");
exit(1);
}
if ( (unsigned int)buffCountReallocs(v5) )
{
puts("Y41: Failed Should be zero ");
exit(1);
}
if ( (unsigned int)buffCountInserts(v5) )
{
puts("Y43: Failed Should be zero");
exit(1);
}
if ( (unsigned int)buffCountRetrievals(v5) )
{
puts("Y45: Failed Should be zero");
exit(1);
}
if ( (unsigned int)buffDestroy(0LL) )
{
puts("A02: Failed buffDestroy must return a 0 if given a NULL pointer.");
exit(1);
}
if ( (unsigned int)buffAdd(0LL, "test", 5LL) )
{
puts("A03: Failed buffAdd must return a 0 if given a NULL pointer. ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 0LL) )
{
puts("A04: Failed ");
exit(1);
}
if ( (unsigned int)buffAdd(v5, "test", 0xFFFFFFFFLL) )
{
puts("A05: Failed ");
exit(1);
}
if ( (unsigned int)buffAdd(v5, 0LL, 5LL) )
{
puts("A07: Failed must return a 0 if given a NULL pointer.");
exit(1);
}
if ( (unsigned int)buffGetLine(0LL, &v27) )
{
puts("A08: Failed must return a 0 if given a NULL pointer.");
exit(1);
}
if ( (unsigned int)buffGetLine(v5, 0LL) )
{
puts("A09: Failed must return a 0 if given a NULL pointer.");
exit(1);
}
buffClear(v5);
if ( !(unsigned int)buffAdd(v5, "\ntesta\rtestbb\r\ntestccc", 22LL) )
{
puts("A10: Failed buffAdd should return a 1 on successful insert.");
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) != 1 )
{
puts("A11: Failed buffGetLine() should return a 1 and a \\n here.");
exit(1);
}
if ( (_BYTE)v27 == 10 )
{
printf("A11a: Failed should be '%x' here, found '%x'.\n", 10LL, (unsigned int)*v27);
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) != 6 )
{
puts("A12: Failed buffGetLine() should return a 6 and a 'testa\\r' here.");
exit(1);
}
if ( (_DWORD)v27 == 1953719668 && WORD2(v27) == 3425 )
{
printf("A12a: Failed should be 'testa\\r' here, found '%s'.\n", v27);
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) != 8 )
{
puts("A13: Failed buffGetLine() should return an 8 and a 'testbb\\r\\n' here.");
exit(1);
}
if ( v27 == (const char *)0xA0D626274736574LL )
{
printf("A13a: Failed should be 'testbb\r\n' here, found '%s'.\n", (const char *)0xA0D626274736574LL);
exit(1);
}
v6 = buffGetLine(v5, &v27);
if ( v6 )
{
printf("A14: Failed buffGetLine() should return a 0 and a '' here. found %s of len %d\n", v27, v6);
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "\n", 1LL) )
{
puts("A14b: Failed buffAdd should return a 1 on successful insert.");
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) != 8 )
{
puts("A14c: Failed buffGetLine() should return an 8 and a 'testccc\\n' here.");
exit(1);
}
if ( v27 == (const char *)0xA63636374736574LL )
{
printf("A14d: Failed should be 'testccc\n' here, found '%s'.\n", (const char *)0xA63636374736574LL);
exit(1);
}
if ( (unsigned int)buffGetLine(v5, &v27) )
{
puts("A15: Failed buffGetLine() should return a 0 in an empty buffer.");
exit(1);
}
if ( (unsigned int)buffGetBlockFromTail(0LL, &v27, 5LL) )
goto LABEL_141;
if ( (unsigned int)buffGetBlockFromTail(v5, 0LL, 5LL) )
goto LABEL_140;
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
goto LABEL_139;
if ( !(unsigned int)buffGetBlockFromTail(v5, &v27, 4LL) )
goto LABEL_138;
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
goto LABEL_161;
if ( !(unsigned int)buffGetBlockFromTail(v5, &v27, 3LL) )
goto LABEL_160;
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
goto LABEL_159;
if ( !(unsigned int)buffGetBlockFromTail(v5, &v27, 10LL) )
goto LABEL_158;
if ( (unsigned int)buffGetBlockFromHead(0LL, &v27, 5LL) )
{
LABEL_141:
puts("A16: Failed ");
exit(1);
}
if ( (unsigned int)buffGetBlockFromHead(v5, 0LL, 5LL) )
{
LABEL_140:
puts("A17: Failed ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
{
LABEL_139:
puts("A18: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetBlockFromHead(v5, &v27, 4LL) )
{
LABEL_138:
puts("A19: Failed ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
{
LABEL_161:
puts("A20: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetBlockFromHead(v5, &v27, 3LL) )
{
LABEL_160:
puts("A21: Failed ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
{
LABEL_159:
puts("A22: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetBlockFromHead(v5, &v27, 10LL) )
{
LABEL_158:
puts("A23: Failed ");
exit(1);
}
if ( (unsigned int)buffResize(0LL, 50LL) )
{
puts("H01: Failed ");
exit(1);
}
if ( (unsigned int)buffResize(0LL, 2000000LL) )
{
puts("H03: Failed ");
exit(1);
}
if ( !(unsigned int)buffResize(v5, 16000LL) )
{
puts("H04: Failed ");
exit(1);
}
if ( (unsigned int)buffReallocAdjustment(0LL, 16000LL) )
{
puts("J01: Failed ");
exit(1);
}
if ( !(unsigned int)buffReallocAdjustment(v5, 16000LL) )
{
puts("J02: Failed ");
exit(1);
}
if ( (unsigned int)buffReallocAdjustment(0LL, 1600000LL) )
{
puts("J03: Failed ");
exit(1);
}
if ( !(unsigned int)buffReallocAdjustment(v5, 16000LL) )
{
puts("J04: Failed ");
exit(1);
}
if ( (unsigned int)buffGetBuffer(0LL, &v27) )
{
puts("A24: Failed ");
exit(1);
}
if ( (unsigned int)buffGetBuffer(v5, 0LL) )
{
puts("A25: Failed ");
exit(1);
}
if ( !(unsigned int)buffAdd(v5, "test", 4LL) )
{
puts("A26: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetBuffer(v5, &v27) )
{
puts("A27: Failed ");
exit(1);
}
if ( (unsigned int)buffGetSize(0LL) )
{
puts("A32: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetSize(v5) )
{
puts("A33: Failed ");
exit(1);
}
if ( (unsigned int)buffGetLength(0LL) )
{
puts("A34: Failed ");
exit(1);
}
if ( !(unsigned int)buffGetLength(v5) )
puts("A35: Failed ");
if ( (unsigned int)buffCountMovedForward(0LL) )
{
puts("A36: Failed ");
exit(1);
}
if ( (unsigned int)buffCountResetEmpty(0LL) )
{
puts("A38: Failed ");
exit(1);
}
if ( (unsigned int)buffCountReallocs(0LL) )
{
puts("A40: Failed ");
exit(1);
}
if ( (unsigned int)buffCountInserts(0LL) )
{
puts("A42: Failed ");
exit(1);
}
if ( (unsigned int)buffCountRetrievals(0LL) )
{
puts("A44: Failed ");
exit(1);
}
if ( (unsigned int)buffClear(0LL) )
{
puts("A48: Failed ");
exit(1);
}
if ( !(unsigned int)buffClear(v5) )
{
puts("A49: Failed ");
exit(1);
}
do
{
v7 = 10;
printf("\nTesting is using this string:%s", v0);
printf("Inserting and removing %d lines, 10 times to test buffer growing functionality.\n", 10000LL);
v8 = *(_DWORD *)v26;
do
{
v9 = 10000;
do
{
if ( !(unsigned int)buffAdd(v5, v0, v8) )
{
LABEL_114:
puts("M01: Failed Could not add a string.");
exit(1);
}
--v9;
}
while ( v9 );
v10 = 0;
putchar(43);
fflush(0LL);
do
{
v11 = buffGetLine(v5, &v27);
if ( v11 != v8 )
{
printf(
"M03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
v10,
v0,
v8,
v27,
v11);
exit(1);
}
++v10;
}
while ( v10 != 10000 );
putchar(45);
fflush(0LL);
--v7;
}
while ( v7 );
v12 = 3333;
putchar(10);
fflush(0LL);
printf("Inserting and removing %d lines, 30 times to test buffer move to front functionality.\n", 3333LL);
do
{
if ( !(unsigned int)buffAdd(v5, v0, v8) )
goto LABEL_114;
--v12;
}
while ( v12 );
v13 = 29;
putchar(43);
fflush(0LL);
do
{
v14 = 3333;
do
{
if ( !(unsigned int)buffAdd(v5, v0, v8) )
{
puts("M02: Failed Could not add a string.");
exit(1);
}
--v14;
}
while ( v14 );
v15 = 0;
putchar(43);
fflush(0LL);
do
{
v16 = buffGetLine(v5, &v27);
if ( v8 != v16 )
{
v21 = v27;
v22 = v16;
v23 = v8;
v24 = v0;
v25 = v15;
goto LABEL_118;
}
++v15;
}
while ( v15 != 3333 );
putchar(45);
fflush(0LL);
--v13;
}
while ( v13 );
for ( i = 0; i != 3333; ++i )
{
v18 = buffGetLine(v5, &v27);
if ( v8 != v18 )
{
v21 = v27;
v22 = v18;
v23 = v8;
v24 = v0;
v25 = i;
LABEL_118:
printf(
"C03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
v25,
v24,
v23,
v21,
v22);
exit(1);
}
}
v0 += 10000;
putchar(45);
putchar(10);
fflush(0LL);
v26 += 4;
}
while ( v30 != v0 );
putchar(10);
if ( !(unsigned int)buffCountMovedForward(v5) )
puts("Q01: Failed ");
if ( !(unsigned int)buffCountReallocs(v5) )
puts("Q02: Failed ");
if ( !(unsigned int)buffCountInserts(v5) )
puts("Q03: Failed ");
if ( !(unsigned int)buffCountRetrievals(v5) )
puts("Q04: Failed ");
puts("Destroying a buffer.");
v19 = (const char *)v5;
if ( !(unsigned int)buffDestroy(v5) )
{
v19 = "Q05: Failed Could not buffDestroy";
puts("Q05: Failed Could not buffDestroy");
}
if ( (unsigned int)buffTotalCount(v19) )
{
v19 = "Q06: Failed the total count should be equal to 0 ";
puts("Q06: Failed the total count should be equal to 0 ");
}
if ( (unsigned int)buffTotalSize(v19) )
puts("Q07: Failed the total size would be equal to 0 ");
puts("Completed tests.");
return 0LL;
}

original_code:
int BuffTest (){
 buff buffer;
 int i, j, k, length;
 char * resultString;
 int resultLength;
 char tStr[5][10000] = {
  "test\n",
  "01234567890\n",
  "abcdefghijklmnopqrstuvwxyz\n",
  "This is a very very very very very very very very very very very long line.\n",
  "<event originatingID=\"12345\",UnityEventID=\"3434346347\",UnityOriginator=\"QA Server\",EventCategory=\"NA\",UnityEventCategory=\"NetworkEvent\",PhysicalSource=\"Unitytest.singlestep.com\",OriginatingTime=\"05/31/2002 00:44:02\",Message=\"\",Severity=\"3\",Priority=\"1\",Assignee=\"None\",Count=\"1\",Description=\"new event 7 Something very very very very very very very naughty happenned on the network.\",State=\"UP\",Status=\"3\",Path=\"/EventGen-1.1!DBI!\",GenericKey=\"UnityStartingPolicyOutput\"/>\n"
 };
 unsigned int tStrLen[5];
 for (k=0; k < 5; k++)
  tStrLen[k] = strlen(tStr[k]);
 if ( buffTotalCount (((void *)0))) {
  printf("T01: Failed the total count should be equal to 0 \n");
 }
 if ( buffTotalSize (((void *)0))) {
  printf("T02: Failed the total size would be equal to 0 \n");
 }
 printf("Creating a buffer of 0 bytes (will really create a buffer 1 byte long\n");
 buffer = buffCreate (0);
 if (!buffer) {
  printf("T03: Could not buffCreate (0).\n");
  exit (1);
 }
 if ( buffTotalCount () != 1) {
  printf("T04: Failed should be 1 \n");
 }
 if ( buffTotalSize () != 1) {
  printf("T05: Failed Should be 1 \n");
  exit (1);
 }
 if ( buffCountResetEmpty (buffer)) {
  printf("Y39: Failed Should be zero \n");
  exit (1);
 }
 if ( buffCountMovedForward (buffer)) {
  printf("Y37: Failed Should be zero \n");
  exit (1);
 }
 if ( buffCountReallocs (buffer)) {
  printf("Y41: Failed Should be zero \n");
  exit (1);
 }
 if ( buffCountInserts (buffer)) {
  printf("Y43: Failed  Should be zero\n");
  exit (1);
 }
 if ( buffCountRetrievals (buffer)) {
  printf("Y45: Failed  Should be zero\n");
  exit (1);
 }
 if ( buffDestroy (((void *)0))) {
  printf("A02: Failed buffDestroy must return a 0 if given a NULL pointer.\n");
  exit (1);
 }
 if ( buffAdd (((void *)0), "test", 5)) {
  printf("A03: Failed buffAdd must return a 0 if given a NULL pointer. \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 0)) {
  printf("A04: Failed  \n");
  exit (1);
 }
 if ( buffAdd (buffer, "test", -1)) {
  printf("A05: Failed  \n");
  exit (1);
 }
 if ( buffAdd (buffer, ((void *)0), 5)) {
  printf("A07: Failed  must return a 0 if given a NULL pointer.\n");
  exit (1);
 }
 if ( buffGetLine (((void *)0), &resultString)) {
  printf("A08: Failed  must return a 0 if given a NULL pointer.\n");
  exit (1);
 }
 if ( buffGetLine (buffer, ((void *)0))) {
  printf("A09: Failed  must return a 0 if given a NULL pointer.\n");
  exit (1);
 }
 buffClear (buffer);
 if (!buffAdd (buffer, "\ntesta\rtestbb\r\ntestccc", 22)) {
  printf("A10: Failed  buffAdd should return a 1 on successful insert.\n");
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) != 1) {
  printf("A11: Failed buffGetLine() should return a 1 and a \\n here.\n");
  exit (1);
 }
 if (!memcmp("\n", &resultString, length)) {
  printf("A11a: Failed should be '%x' here, found '%x'.\n", '\n', *resultString);
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) != 6) {
  printf("A12: Failed buffGetLine() should return a 6 and a 'testa\\r' here.\n");
  exit (1);
 }
 if (!memcmp("testa\r", &resultString, length)) {
  printf("A12a: Failed should be 'testa\\r' here, found '%s'.\n", resultString);
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) != 8 ) {
  printf("A13: Failed buffGetLine() should return an 8 and a 'testbb\\r\\n' here.\n");
  exit (1);
 }
 if (!memcmp("testbb\r\n", &resultString, length)) {
  printf("A13a: Failed should be 'testbb\r\n' here, found '%s'.\n", resultString);
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) ) {
  printf("A14: Failed buffGetLine() should return a 0 and a '' here. found %s of len %d\n", resultString, length);
  exit (1);
 }
 if ( memcmp("", &resultString, length)) {
  printf("A14a: Failed should be '' here found '%s'.\n", resultString);
  exit (1);
 }
 if (!buffAdd (buffer, "\n", 1)) {
  printf("A14b: Failed  buffAdd should return a 1 on successful insert.\n");
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) != 8 ) {
  printf("A14c: Failed buffGetLine() should return an 8 and a 'testccc\\n' here.\n");
  exit (1);
 }
 if (!memcmp("testccc\n", &resultString, length)) {
  printf("A14d: Failed should be 'testccc\n' here, found '%s'.\n", resultString);
  exit (1);
 }
 if ( buffGetLine (buffer, &resultString)) {
  printf("A15: Failed buffGetLine() should return a 0 in an empty buffer.\n");
  exit (1);
 }
 if ( buffGetBlockFromTail(((void *)0), &resultString, 5)) {
  printf("A16: Failed  \n");
  exit (1);
 }
 if ( buffGetBlockFromTail(buffer, ((void *)0), 5)) {
  printf("A17: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A18: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromTail(buffer, &resultString, 4)) {
  printf("A19: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A20: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromTail(buffer, &resultString, 3)) {
  printf("A21: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A22: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromTail(buffer, &resultString, 10)) {
  printf("A23: Failed  \n");
  exit (1);
 }
 if ( buffGetBlockFromHead (((void *)0), &resultString, 5)) {
  printf("A16: Failed  \n");
  exit (1);
 }
 if ( buffGetBlockFromHead (buffer, ((void *)0), 5)) {
  printf("A17: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A18: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromHead (buffer, &resultString, 4)) {
  printf("A19: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A20: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromHead (buffer, &resultString, 3)) {
  printf("A21: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A22: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromHead (buffer, &resultString, 10)) {
  printf("A23: Failed  \n");
  exit (1);
 }
 if ( buffResize (((void *)0), 50)) {
  printf("H01: Failed  \n");
  exit (1);
 }
 if ( buffResize (((void *)0), 2000000)) {
  printf("H03: Failed  \n");
  exit (1);
 }
 if (!buffResize (buffer, 16000)) {
  printf("H04: Failed  \n");
  exit (1);
 }
 if (buffReallocAdjustment (((void *)0), 16000)) {
  printf("J01: Failed  \n");
  exit (1);
 }
 if (!buffReallocAdjustment (buffer, 16000)) {
  printf("J02: Failed  \n");
  exit (1);
 }
 if (buffReallocAdjustment (((void *)0), 1600000)) {
  printf("J03: Failed  \n");
  exit (1);
 }
 if (!buffReallocAdjustment (buffer, 16000)) {
  printf("J04: Failed  \n");
  exit (1);
 }
 if ( buffGetBuffer (((void *)0), &resultString)) {
  printf("A24: Failed  \n");
  exit (1);
 }
 if ( buffGetBuffer (buffer, ((void *)0))) {
  printf("A25: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A26: Failed  \n");
  exit (1);
 }
 if (!buffGetBuffer (buffer, &resultString)) {
  printf("A27: Failed  \n");
  exit (1);
 }
 if ( buffGetSize (((void *)0))) {
  printf("A32: Failed  \n");
  exit (1);
 }
 if (!buffGetSize (buffer)) {
  printf("A33: Failed  \n");
  exit (1);
 }
 if ( buffGetLength (((void *)0))) {
  printf("A34: Failed  \n");
  exit (1);
 }
 if (!buffGetLength (buffer)) {
  printf("A35: Failed  \n");
 }
 if ( buffCountMovedForward (((void *)0))) {
  printf("A36: Failed  \n");
  exit (1);
 }
 if ( buffCountResetEmpty (((void *)0))) {
  printf("A38: Failed  \n");
  exit (1);
 }
 if ( buffCountReallocs (((void *)0))) {
  printf("A40: Failed  \n");
  exit (1);
 }
 if ( buffCountInserts (((void *)0))) {
  printf("A42: Failed  \n");
  exit (1);
 }
 if ( buffCountRetrievals (((void *)0))) {
  printf("A44: Failed  \n");
  exit (1);
 }
 if ( buffClear (((void *)0))) {
  printf("A48: Failed  \n");
  exit (1);
 }
 if (!buffClear (buffer)) {
  printf("A49: Failed  \n");
  exit (1);
 }
 for (k=0; k < 5; k++) {
  printf("\nTesting is using this string:%s", tStr[k]);
  printf("Inserting and removing %d lines, 10 times to test buffer growing functionality.\n", 10000);
  for (j=0; j<10; j++){
   for (i = 0; i < 10000; i++) {
    if (!buffAdd(buffer, tStr[k], tStrLen[k])) {
     printf("M01: Failed Could not add a string.\n");
     exit (1);
    }
   }
   printf("+");
   fflush(((void *)0));
   for (i=0; i < 10000; i++) {
    if ((resultLength = buffGetLine(buffer, &resultString)) != tStrLen[k]){
     printf("M03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
      i, tStr[k], tStrLen[k], resultString, resultLength);
     exit (1);
    }
   }
   printf("-");
   fflush(((void *)0));
  }
  printf("\n");
  fflush(((void *)0));
  printf("Inserting and removing %d lines, 30 times to test buffer move to front functionality.\n", 10000/3);
  for (i = 0; i < 10000/3; i++) {
   if (!buffAdd(buffer, tStr[k], tStrLen[k])) {
    printf("M01: Failed Could not add a string.\n");
    exit (1);
   }
  }
  printf("+");
  fflush(((void *)0));
  for (j=0; j<29; j++){
   for (i = 0; i < 10000/3; i++) {
    if (!buffAdd(buffer, tStr[k], tStrLen[k])) {
     printf("M02: Failed Could not add a string.\n");
     exit (1);
    }
   }
   printf("+");
   fflush(((void *)0));
   for (i=0; i < 10000/3; i++) {
    if ((resultLength = buffGetLine(buffer, &resultString)) != tStrLen[k]){
     printf("C03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
      i, tStr[k], tStrLen[k], resultString, resultLength);
     exit (1);
    }
   }
   printf("-");
   fflush(((void *)0));
  }
  for (i=0; i < 10000/3; i++) {
   if ((resultLength = buffGetLine(buffer, &resultString)) != tStrLen[k]){
    printf("C03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
     i, tStr[k], tStrLen[k], resultString, resultLength);
    exit (1);
   }
  }
  printf("-");
  printf("\n");
  fflush(((void *)0));
 }
 printf("\n");
 if (!buffCountMovedForward (buffer)) {
  printf("Q01: Failed  \n");
 }
 if (!buffCountReallocs (buffer)) {
  printf("Q02: Failed  \n");
 }
 if (!buffCountInserts (buffer)) {
  printf("Q03: Failed  \n");
 }
 if (!buffCountRetrievals (buffer)) {
  printf("Q04: Failed  \n");
 }
 printf("Destroying a buffer.\n");
 if (!buffDestroy(buffer)) {
  printf("Q05: Failed Could not buffDestroy\n");
 }
 if ( buffTotalCount ()) {
  printf("Q06: Failed the total count should be equal to 0 \n");
 }
 if ( buffTotalSize ()) {
  printf("Q07: Failed the total size would be equal to 0 \n");
 }
 printf("Completed tests.\n");
 return 0;
}

canonical_original_code:
int BuffTest(){
 void *buffer;
 int i; int j; int k; int length;
 char *resultString;
 int resultLength;
 char tStr[5][10000] = {
  "test\n",
  "01234567890\n",
  "abcdefghijklmnopqrstuvwxyz\n",
  "This is a very very very very very very very very very very very long line.\n",
  "<event originatingID=\"12345\",UnityEventID=\"3434346347\",UnityOriginator=\"QA Server\",EventCategory=\"NA\",UnityEventCategory=\"NetworkEvent\",PhysicalSource=\"Unitytest.singlestep.com\",OriginatingTime=\"05/31/2002 00:44:02\",Message=\"\",Severity=\"3\",Priority=\"1\",Assignee=\"None\",Count=\"1\",Description=\"new event 7 Something very very very very very very very naughty happenned on the network.\",State=\"UP\",Status=\"3\",Path=\"/EventGen-1.1!DBI!\",GenericKey=\"UnityStartingPolicyOutput\"/>\n"
 };
 unsigned int tStrLen[5];
 for (k=0; k < 5; k++)
  tStrLen[k] = strlen(tStr[k]);
 if ( buffTotalCount (((void *)0))) {
  printf("T01: Failed the total count should be equal to 0 \n");
 }
 if ( buffTotalSize (((void *)0))) {
  printf("T02: Failed the total size would be equal to 0 \n");
 }
 printf("Creating a buffer of 0 bytes (will really create a buffer 1 byte long\n");
 buffer = buffCreate (0);
 if (!buffer) {
  printf("T03: Could not buffCreate (0).\n");
  exit (1);
 }
 if ( buffTotalCount () != 1) {
  printf("T04: Failed should be 1 \n");
 }
 if ( buffTotalSize () != 1) {
  printf("T05: Failed Should be 1 \n");
  exit (1);
 }
 if ( buffCountResetEmpty (buffer)) {
  printf("Y39: Failed Should be zero \n");
  exit (1);
 }
 if ( buffCountMovedForward (buffer)) {
  printf("Y37: Failed Should be zero \n");
  exit (1);
 }
 if ( buffCountReallocs (buffer)) {
  printf("Y41: Failed Should be zero \n");
  exit (1);
 }
 if ( buffCountInserts (buffer)) {
  printf("Y43: Failed  Should be zero\n");
  exit (1);
 }
 if ( buffCountRetrievals (buffer)) {
  printf("Y45: Failed  Should be zero\n");
  exit (1);
 }
 if ( buffDestroy (((void *)0))) {
  printf("A02: Failed buffDestroy must return a 0 if given a NULL pointer.\n");
  exit (1);
 }
 if ( buffAdd (((void *)0), "test", 5)) {
  printf("A03: Failed buffAdd must return a 0 if given a NULL pointer. \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 0)) {
  printf("A04: Failed  \n");
  exit (1);
 }
 if ( buffAdd (buffer, "test", -1)) {
  printf("A05: Failed  \n");
  exit (1);
 }
 if ( buffAdd (buffer, ((void *)0), 5)) {
  printf("A07: Failed  must return a 0 if given a NULL pointer.\n");
  exit (1);
 }
 if ( buffGetLine (((void *)0), &resultString)) {
  printf("A08: Failed  must return a 0 if given a NULL pointer.\n");
  exit (1);
 }
 if ( buffGetLine (buffer, ((void *)0))) {
  printf("A09: Failed  must return a 0 if given a NULL pointer.\n");
  exit (1);
 }
 buffClear (buffer);
 if (!buffAdd (buffer, "\ntesta\rtestbb\r\ntestccc", 22)) {
  printf("A10: Failed  buffAdd should return a 1 on successful insert.\n");
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) != 1) {
  printf("A11: Failed buffGetLine() should return a 1 and a \\n here.\n");
  exit (1);
 }
 if (!memcmp("\n", &resultString, length)) {
  printf("A11a: Failed should be '%x' here, found '%x'.\n", '\n', *resultString);
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) != 6) {
  printf("A12: Failed buffGetLine() should return a 6 and a 'testa\\r' here.\n");
  exit (1);
 }
 if (!memcmp("testa\r", &resultString, length)) {
  printf("A12a: Failed should be 'testa\\r' here, found '%s'.\n", resultString);
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) != 8 ) {
  printf("A13: Failed buffGetLine() should return an 8 and a 'testbb\\r\\n' here.\n");
  exit (1);
 }
 if (!memcmp("testbb\r\n", &resultString, length)) {
  printf("A13a: Failed should be 'testbb\r\n' here, found '%s'.\n", resultString);
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) ) {
  printf("A14: Failed buffGetLine() should return a 0 and a '' here. found %s of len %d\n", resultString, length);
  exit (1);
 }
 if ( memcmp("", &resultString, length)) {
  printf("A14a: Failed should be '' here found '%s'.\n", resultString);
  exit (1);
 }
 if (!buffAdd (buffer, "\n", 1)) {
  printf("A14b: Failed  buffAdd should return a 1 on successful insert.\n");
  exit (1);
 }
 if ( (length = buffGetLine (buffer, &resultString)) != 8 ) {
  printf("A14c: Failed buffGetLine() should return an 8 and a 'testccc\\n' here.\n");
  exit (1);
 }
 if (!memcmp("testccc\n", &resultString, length)) {
  printf("A14d: Failed should be 'testccc\n' here, found '%s'.\n", resultString);
  exit (1);
 }
 if ( buffGetLine (buffer, &resultString)) {
  printf("A15: Failed buffGetLine() should return a 0 in an empty buffer.\n");
  exit (1);
 }
 if ( buffGetBlockFromTail(((void *)0), &resultString, 5)) {
  printf("A16: Failed  \n");
  exit (1);
 }
 if ( buffGetBlockFromTail(buffer, ((void *)0), 5)) {
  printf("A17: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A18: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromTail(buffer, &resultString, 4)) {
  printf("A19: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A20: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromTail(buffer, &resultString, 3)) {
  printf("A21: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A22: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromTail(buffer, &resultString, 10)) {
  printf("A23: Failed  \n");
  exit (1);
 }
 if ( buffGetBlockFromHead (((void *)0), &resultString, 5)) {
  printf("A16: Failed  \n");
  exit (1);
 }
 if ( buffGetBlockFromHead (buffer, ((void *)0), 5)) {
  printf("A17: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A18: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromHead (buffer, &resultString, 4)) {
  printf("A19: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A20: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromHead (buffer, &resultString, 3)) {
  printf("A21: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A22: Failed  \n");
  exit (1);
 }
 if (!buffGetBlockFromHead (buffer, &resultString, 10)) {
  printf("A23: Failed  \n");
  exit (1);
 }
 if ( buffResize (((void *)0), 50)) {
  printf("H01: Failed  \n");
  exit (1);
 }
 if ( buffResize (((void *)0), 2000000)) {
  printf("H03: Failed  \n");
  exit (1);
 }
 if (!buffResize (buffer, 16000)) {
  printf("H04: Failed  \n");
  exit (1);
 }
 if (buffReallocAdjustment (((void *)0), 16000)) {
  printf("J01: Failed  \n");
  exit (1);
 }
 if (!buffReallocAdjustment (buffer, 16000)) {
  printf("J02: Failed  \n");
  exit (1);
 }
 if (buffReallocAdjustment (((void *)0), 1600000)) {
  printf("J03: Failed  \n");
  exit (1);
 }
 if (!buffReallocAdjustment (buffer, 16000)) {
  printf("J04: Failed  \n");
  exit (1);
 }
 if ( buffGetBuffer (((void *)0), &resultString)) {
  printf("A24: Failed  \n");
  exit (1);
 }
 if ( buffGetBuffer (buffer, ((void *)0))) {
  printf("A25: Failed  \n");
  exit (1);
 }
 if (!buffAdd (buffer, "test", 4)) {
  printf("A26: Failed  \n");
  exit (1);
 }
 if (!buffGetBuffer (buffer, &resultString)) {
  printf("A27: Failed  \n");
  exit (1);
 }
 if ( buffGetSize (((void *)0))) {
  printf("A32: Failed  \n");
  exit (1);
 }
 if (!buffGetSize (buffer)) {
  printf("A33: Failed  \n");
  exit (1);
 }
 if ( buffGetLength (((void *)0))) {
  printf("A34: Failed  \n");
  exit (1);
 }
 if (!buffGetLength (buffer)) {
  printf("A35: Failed  \n");
 }
 if ( buffCountMovedForward (((void *)0))) {
  printf("A36: Failed  \n");
  exit (1);
 }
 if ( buffCountResetEmpty (((void *)0))) {
  printf("A38: Failed  \n");
  exit (1);
 }
 if ( buffCountReallocs (((void *)0))) {
  printf("A40: Failed  \n");
  exit (1);
 }
 if ( buffCountInserts (((void *)0))) {
  printf("A42: Failed  \n");
  exit (1);
 }
 if ( buffCountRetrievals (((void *)0))) {
  printf("A44: Failed  \n");
  exit (1);
 }
 if ( buffClear (((void *)0))) {
  printf("A48: Failed  \n");
  exit (1);
 }
 if (!buffClear (buffer)) {
  printf("A49: Failed  \n");
  exit (1);
 }
 for (k=0; k < 5; k++) {
  printf("\nTesting is using this string:%s", tStr[k]);
  printf("Inserting and removing %d lines, 10 times to test buffer growing functionality.\n", 10000);
  for (j=0; j<10; j++){
   for (i = 0; i < 10000; i++) {
    if (!buffAdd(buffer, tStr[k], tStrLen[k])) {
     printf("M01: Failed Could not add a string.\n");
     exit (1);
    }
   }
   printf("+");
   fflush(((void *)0));
   for (i=0; i < 10000; i++) {
    if ((resultLength = buffGetLine(buffer, &resultString)) != tStrLen[k]){
     printf("M03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
      i, tStr[k], tStrLen[k], resultString, resultLength);
     exit (1);
    }
   }
   printf("-");
   fflush(((void *)0));
  }
  printf("\n");
  fflush(((void *)0));
  printf("Inserting and removing %d lines, 30 times to test buffer move to front functionality.\n", 10000/3);
  for (i = 0; i < 10000/3; i++) {
   if (!buffAdd(buffer, tStr[k], tStrLen[k])) {
    printf("M01: Failed Could not add a string.\n");
    exit (1);
   }
  }
  printf("+");
  fflush(((void *)0));
  for (j=0; j<29; j++){
   for (i = 0; i < 10000/3; i++) {
    if (!buffAdd(buffer, tStr[k], tStrLen[k])) {
     printf("M02: Failed Could not add a string.\n");
     exit (1);
    }
   }
   printf("+");
   fflush(((void *)0));
   for (i=0; i < 10000/3; i++) {
    if ((resultLength = buffGetLine(buffer, &resultString)) != tStrLen[k]){
     printf("C03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
      i, tStr[k], tStrLen[k], resultString, resultLength);
     exit (1);
    }
   }
   printf("-");
   fflush(((void *)0));
  }
  for (i=0; i < 10000/3; i++) {
   if ((resultLength = buffGetLine(buffer, &resultString)) != tStrLen[k]){
    printf("C03: Failed on buffGetLine on line %d expected '%s' of length %d, got '%s' of length %d\n",
     i, tStr[k], tStrLen[k], resultString, resultLength);
    exit (1);
   }
  }
  printf("-");
  printf("\n");
  fflush(((void *)0));
 }
 printf("\n");
 if (!buffCountMovedForward (buffer)) {
  printf("Q01: Failed  \n");
 }
 if (!buffCountReallocs (buffer)) {
  printf("Q02: Failed  \n");
 }
 if (!buffCountInserts (buffer)) {
  printf("Q03: Failed  \n");
 }
 if (!buffCountRetrievals (buffer)) {
  printf("Q04: Failed  \n");
 }
 printf("Destroying a buffer.\n");
 if (!buffDestroy(buffer)) {
  printf("Q05: Failed Could not buffDestroy\n");
 }
 if ( buffTotalCount ()) {
  printf("Q06: Failed the total count should be equal to 0 \n");
 }
 if ( buffTotalSize ()) {
  printf("Q07: Failed the total size would be equal to 0 \n");
 }
 printf("Completed tests.\n");
 return 0;
}

variable_types:
buffer
void *

variable_types: j int

variable_types: k int

variable_types: length int

variable_types:
resultString
char *

variable_types: resultLength int

variable_types:
tStrLen
unsigned int [5]


GetTypeStr

decompiled_code:
const char *__fastcall GetTypeStr(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "Program Flow";
break;
case 1:
result = "Error";
break;
case 2:
result = "Command Line";
break;
case 3:
result = "Register";
break;
case 4:
result = "Object Message Handling";
break;
default:
result = "Needs Finished";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "Program Flow";
break;
case 1:
result = "Error";
break;
case 2:
result = "Command Line";
break;
case 3:
result = "Register";
break;
case 4:
result = "Object Message Handling";
break;
default:
result = "Needs Finished";
break;
}
return result;
}

original_code:
char *
GetTypeStr(int type){
 switch(type){
 case PROG_FLOW:
  return "Program Flow";
 case ERROR:
  return "Error";
 case CMDLINEOPTS:
  return "Command Line";
 case REGISTER:
  return "Register";
 case OBJMSGHANDLING:
  return "Object Message Handling";
 default:
  return "Needs Finished";
 }
}

canonical_original_code:
char *GetTypeStr(int type){
 switch(type){
 case PROG_FLOW:
  return "Program Flow";
 case ERROR:
  return "Error";
 case CMDLINEOPTS:
  return "Command Line";
 case REGISTER:
  return "Register";
 case OBJMSGHANDLING:
  return "Object Message Handling";
 default:
  return "Needs Finished";
 }
}

variable_types: type int

return_type: char *


GetDateStr

decompiled_code:
const char *GetDateStr()
{
return "200812202325";
}

original_code:
char *
GetDateStr(){
 return "200812202325";
}

canonical_original_code:
char *GetDateStr(){
 return "200812202325";
}


DebugPrint

decompiled_code:
int __fastcall DebugPrint(const char *a1, const char *a2, unsigned int a3, int a4)
{
const char *v5; // rbx
const char *v6; // rax

v5 = GetTypeStr(a4);
v6 = (const char *)FormatDate(0LL);
return printf("%s\t%s %d\t%s\t%s\n", v6, a2, a3, v5, a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, const char *a2, unsigned int a3, int a4)
{
const char *v5; // rbx
const char *v6; // rax

v5 = func0(a4);
v6 = (const char *)FormatDate(0LL);
return printf("%s\t%s %d\t%s\t%s\n", v6, a2, a3, v5, a1);
}

original_code:
void
DebugPrint(char * report, char * file, int line, int type) {
 printf("%s	%s %d	%s	%s\n", FormatDate(0), file, line, GetTypeStr(type), report);
}

canonical_original_code:
void DebugPrint(char *report, char *file, int line, int type) {
 printf("%s	%s %d	%s	%s\n", FormatDate(0), file, line, GetTypeStr(type), report);
}

variable_types:
report
char *

variable_types:
file
char *

variable_types: line int


LoadObject

decompiled_code:
__int64 __fastcall LoadObject(const char *a1)
{
void *v1; // rax
void *v2; // rbp
char v4[1024]; // [rsp+0h] [rbp-1828h] BYREF
char s[1024]; // [rsp+400h] [rbp-1428h] BYREF
char buf[4136]; // [rsp+800h] [rbp-1028h] BYREF

getcwd(buf, 0x1000uLL);
fflush(0LL);
sprintf(v4, "%s/%s", buf, a1);
v1 = dlopen(v4, 1);
if ( v1 )
{
v2 = v1;
sprintf(s, "Loaded %s", a1);
DebugPrint(s, "libload.c", 43LL, 0LL);
dlsym(v2, "Handle_Message");
if ( dlerror() )
{
dlclose(v2);
DebugPrint("Failed to find HandleMessage in Library.", "libload.c", 53LL, 1LL);
}
else
{
DebugPrint("Found HandleMessage in Library.", "libload.c", 56LL, 0LL);
}
}
else
{
sprintf(s, "Failed to load %s", v4);
DebugPrint(s, "libload.c", 39LL, 0LL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
void *v1; // rax
void *v2; // rbp
char v4[1024]; // [rsp+0h] [rbp-1828h] BYREF
char s[1024]; // [rsp+400h] [rbp-1428h] BYREF
char buf[4136]; // [rsp+800h] [rbp-1028h] BYREF

getcwd(buf, 0x1000uLL);
fflush(0LL);
sprintf(v4, "%s/%s", buf, a1);
v1 = dlopen(v4, 1);
if ( v1 )
{
v2 = v1;
sprintf(s, "Loaded %s", a1);
DebugPrint(s, "libload.c", 43LL, 0LL);
dlsym(v2, "Handle_Message");
if ( dlerror() )
{
dlclose(v2);
DebugPrint("Failed to find HandleMessage in Library.", "libload.c", 53LL, 1LL);
}
else
{
DebugPrint("Found HandleMessage in Library.", "libload.c", 56LL, 0LL);
}
}
else
{
sprintf(s, "Failed to load %s", v4);
DebugPrint(s, "libload.c", 39LL, 0LL);
}
return 0LL;
}

original_code:
int
LoadObject (char *name, int depth)
{
 void *ClassHandle;
 int *ClassMsgFunc;
 char *error;
 char hereName[1024];
 char DebugMsg[1024];
        int ignore;
        char bundlePath[4096];
 ignore = (int) getcwd( bundlePath, 4096 );
 fflush(((void *)0));
 sprintf (hereName, "%s/%s", bundlePath, name);
 ClassHandle = dlopen(hereName, 0x00001);
 if (!ClassHandle) {
  sprintf((char *)&DebugMsg, "Failed to load %s", hereName);
  DebugPrint ( (char *)&DebugMsg, "libload.c", 39, PROG_FLOW);
  return 0;
 } else {
  sprintf((char *)&DebugMsg, "Loaded %s", name);
  DebugPrint ((char *)&DebugMsg, "libload.c", 43, PROG_FLOW);
 }
 ClassMsgFunc = dlsym(ClassHandle, "Handle_Message");
 if ((error = dlerror()) != ((void *)0)) {
  dlclose(ClassHandle);
  DebugPrint ( "Failed to find HandleMessage in Library.", "libload.c", 53, ERROR);
  return 0;
 } else
  DebugPrint ( "Found HandleMessage in Library.", "libload.c", 56, PROG_FLOW);
 return 0;
}

canonical_original_code:
int LoadObject(char *name, int depth)
{
 void *ClassHandle;
 int *ClassMsgFunc;
 char *error;
 char hereName[1024];
 char DebugMsg[1024];
        int ignore;
        char bundlePath[4096];
 ignore = (int) getcwd( bundlePath, 4096 );
 fflush(((void *)0));
 sprintf (hereName, "%s/%s", bundlePath, name);
 ClassHandle = dlopen(hereName, 0x00001);
 if (!ClassHandle) {
  sprintf((char *)&DebugMsg, "Failed to load %s", hereName);
  DebugPrint ( (char *)&DebugMsg, "libload.c", 39, PROG_FLOW);
  return 0;
 } else {
  sprintf((char *)&DebugMsg, "Loaded %s", name);
  DebugPrint ((char *)&DebugMsg, "libload.c", 43, PROG_FLOW);
 }
 ClassMsgFunc = dlsym(ClassHandle, "Handle_Message");
 if ((error = dlerror()) != ((void *)0)) {
  dlclose(ClassHandle);
  DebugPrint ( "Failed to find HandleMessage in Library.", "libload.c", 53, ERROR);
  return 0;
 } else
  DebugPrint ( "Found HandleMessage in Library.", "libload.c", 56, PROG_FLOW);
 return 0;
}

variable_types:
name
char *

variable_types: depth int

variable_types:
ClassHandle
void *

variable_types:
ClassMsgFunc
int *

variable_types:
error
char *

variable_types:
hereName
char [1024]

variable_types:
DebugMsg
char [1024]

variable_types: ignore int

variable_types:
bundlePath
char [4096]


decompiled_code:
int become_deamon()
{
int v0; // eax
int v1; // ebp
int i; // ebx
int v3; // edi
int result; // eax
int v5; // ebp

v0 = getdtablesize();
if ( v0 > 0 )
{
v1 = v0;
for ( i = 0; i != v1; ++i )
{
v3 = i;
close(v3);
}
}
chdir("/");
umask(0);
signal(22, handler);
signal(21, handler);
signal(20, handler);
setpgrp();
if ( fork() || (setpgrp(), fork()) )
exit(0);
result = open("/dev/tty", 2);
v5 = result;
if ( result >= 0 )
{
ioctl(result, 0x5422uLL, 0LL);
result = close(v5);
}
return result;
}

canonical_decompiled_code:
int func0()
{
int v0; // eax
int v1; // ebp
int i; // ebx
int v3; // edi
int result; // eax
int v5; // ebp

v0 = getdtablesize();
if ( v0 > 0 )
{
v1 = v0;
for ( i = 0; i != v1; ++i )
{
v3 = i;
close(v3);
}
}
chdir("/");
umask(0);
signal(22, handler);
signal(21, handler);
signal(20, handler);
setpgrp();
if ( fork() || (setpgrp(), fork()) )
exit(0);
result = open("/dev/tty", 2);
v5 = result;
if ( result >= 0 )
{
ioctl(result, 0x5422uLL, 0LL);
result = close(v5);
}
return result;
}

original_code:
void become_deamon () {
   int i, max_files, fd;
   max_files=getdtablesize();
   for (i = 0; i < max_files; i++)
      close(i);
   i = chdir("/");
   umask(0);
      signal(22, ((__sighandler_t) 1));
      signal(21, ((__sighandler_t) 1));
      signal(20, ((__sighandler_t) 1));
   setpgrp();
   if ( fork() != 0)
      exit(0);
   setpgrp();
   if ( fork() != 0)
      exit(0);
   if ( (fd = open("/dev/tty", 02)) >= 0) {
      ioctl(fd, 0x5422, (char *) 0);
      close(fd);
   }
}

canonical_original_code:
void become_deamon() {
   int i; int max_files; int fd;
   max_files=getdtablesize();
   for (i = 0; i < max_files; i++)
      close(i);
   i = chdir("/");
   umask(0);
      signal(22, ((void (*)(int)) 1));
      signal(21, ((void (*)(int)) 1));
      signal(20, ((void (*)(int)) 1));
   setpgrp();
   if ( fork() != 0)
      exit(0);
   setpgrp();
   if ( fork() != 0)
      exit(0);
   if ( (fd = open("/dev/tty", 02)) >= 0) {
      ioctl(fd, 0x5422, (char *) 0);
      close(fd);
   }
}

variable_types: i int

variable_types: fd int