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

switch ( a1 )
{
case 258:
result = "box, style=rounded";
break;
case 260:
case 289:
result = "circle, fixedsize = true, style=filled";
break;
case 264:
case 271:
case 288:
result = "diamond, style=filled";
break;
case 267:
result = "plain";
break;
default:
v2 = node_type(a1);
fprintf(stderr, "Help! %s is unknown!\n", v2);
result = "plaintext";
break;
}
return result;
}

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

switch ( a1 )
{
case 258:
result = "box, style=rounded";
break;
case 260:
case 289:
result = "circle, fixedsize = true, style=filled";
break;
case 264:
case 271:
case 288:
result = "diamond, style=filled";
break;
case 267:
result = "plain";
break;
default:
v2 = func0(a1);
fprintf(stderr, "Help! %s is unknown!\n", v2);
result = "plaintext";
break;
}
return result;
}

original_code:
char *node_shape(int type)
{
    switch (type) {
    case (258): return "box, style=rounded"; break;
    case (264): return "diamond, style=filled"; break;
    case (271): return "diamond, style=filled"; break;
    case (288): return "diamond, style=filled"; break;
    case (260): return "circle, fixedsize = true, style=filled"; break;
    case (289): return "circle, fixedsize = true, style=filled"; break;
    case (267): return "plain"; break;
    default: fprintf(stderr, "Help! %s is unknown!\n", node_type(type)); return "plaintext"; break;
    }
}


repo: jnoll/peos

decompiled_code:
int __fastcall print_resources(__int64 *a1)
{
__int64 *v1; // rbx
int v2; // edi
const char *v3; // rax
__int64 v4; // rax
const char *v5; // rsi
_BYTE *v6; // rbp
size_t v7; // rax
const char *v8; // rax
int v9; // edi
const char *v10; // r12

if ( a1 )
{
v1 = a1;
while ( 1 )
{
if ( !*v1 )
{
v4 = v1[1];
if ( !v4 )
break;
}
print_resources();
if ( (*v1 || (v2 = 0, v1[1])) && (v2 = *((_DWORD *)v1 + 6), v2 == 283) )
{
v8 = op_to_string(283);
printf("%s", v8);
v1 = (__int64 *)v1[1];
if ( !v1 )
goto LABEL_23;
}
else
{
v3 = op_to_string(v2);
printf(" %s ", v3);
v1 = (__int64 *)v1[1];
if ( !v1 )
goto LABEL_23;
}
}
v5 = (const char *)v1[2];
v6 = (_BYTE *)(node_type + 1);
if ( *v5 == 34 )
{
while ( 1 )
{
if ( v4 || v1[1] )
{
v7 = strlen(0LL);
if ( (unsigned __int64)v6 >= v7 )
return v7;
v9 = (char)*v6;
if ( *v6 == 34 )
return v7;
}
else
{
v10 = (const char *)v1[2];
v7 = strlen(v10);
if ( (unsigned __int64)v6 >= v7 )
return v7;
v9 = (char)v6[(_QWORD)v10];
if ( v6[(_QWORD)v10] == 34 )
return v7;
}
putchar(v9);
v4 = *v1;
++v6;
}
}
LODWORD(v7) = printf("%s", v5);
}
else
{
LABEL_23:
LODWORD(v7) = printf("[]");
}
return v7;
}

canonical_decompiled_code:
int __fastcall func4(__int64 *a1)
{
__int64 *v1; // rbx
int v2; // edi
const char *v3; // rax
__int64 v4; // rax
const char *v5; // rsi
_BYTE *v6; // rbp
size_t v7; // rax
const char *v8; // rax
int v9; // edi
const char *v10; // r12

if ( a1 )
{
v1 = a1;
while ( 1 )
{
if ( !*v1 )
{
v4 = v1[1];
if ( !v4 )
break;
}
func4();
if ( (*v1 || (v2 = 0, v1[1])) && (v2 = *((_DWORD *)v1 + 6), v2 == 283) )
{
v8 = func2(283);
printf("%s", v8);
v1 = (__int64 *)v1[1];
if ( !v1 )
goto LABEL_23;
}
else
{
v3 = func2(v2);
printf(" %s ", v3);
v1 = (__int64 *)v1[1];
if ( !v1 )
goto LABEL_23;
}
}
v5 = (const char *)v1[2];
v6 = (_BYTE *)(node_type + 1);
if ( *v5 == 34 )
{
while ( 1 )
{
if ( v4 || v1[1] )
{
v7 = strlen(0LL);
if ( (unsigned __int64)v6 >= v7 )
return v7;
v9 = (char)*v6;
if ( *v6 == 34 )
return v7;
}
else
{
v10 = (const char *)v1[2];
v7 = strlen(v10);
if ( (unsigned __int64)v6 >= v7 )
return v7;
v9 = (char)v6[(_QWORD)v10];
if ( v6[(_QWORD)v10] == 34 )
return v7;
}
putchar(v9);
v4 = *v1;
++v6;
}
}
LODWORD(v7) = printf("%s", v5);
}
else
{
LABEL_23:
LODWORD(v7) = printf("[]");
}
return v7;
}

variable_types: struct tree { struct tree *left; struct tree *right; char *sval; int ival; } *

variable_types: i int

return_type: void


decompiled_code:
void poll_vr()
{
_QWORD *v0; // rbp
__int64 v1; // rbx
__int64 v2; // rax
__int64 v3; // rax
int v4; // edx
_DWORD *v5; // rax
__int64 v6; // rax
__int64 v7; // rdi

v0 = (_QWORD *)myQueries;
if ( myQueries )
{
if ( repos_ctr <= 0 )
goto LABEL_6;
v1 = 0LL;
do
{
v2 = v1++;
v3 = ((__int64 (__fastcall *)(_QWORD *))repos_list[2 * v2])(v0);
myQueries = v3;
v0 = (_QWORD *)v3;
}
while ( repos_ctr > (int)v1 );
if ( v3 )
{
LABEL_6:
v4 = 0;
do
{
while ( 1 )
{
v6 = *v0;
v7 = *(unsigned int *)(*v0 + 16LL);
if ( !(_DWORD)v7 )
break;
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))(v6 + 352))(v7, *(_QWORD *)(v6 + 344), *(_QWORD *)(v6 + 8));
v5 = (_DWORD *)*v0;
v0 = (_QWORD *)v0[1];
v4 = 1;
*v5 = 1;
if ( !v0 )
goto LABEL_12;
}
v0 = (_QWORD *)v0[1];
if ( *(_DWORD *)v6 )
v4 = 1;
}
while ( v0 );
LABEL_12:
if ( v4 )
myQueries = filterQueryList(myQueries);
}
}
}

canonical_decompiled_code:
void func0()
{
_QWORD *v0; // rbp
__int64 v1; // rbx
__int64 v2; // rax
__int64 v3; // rax
int v4; // edx
_DWORD *v5; // rax
__int64 v6; // rax
__int64 v7; // rdi

v0 = (_QWORD *)myQueries;
if ( myQueries )
{
if ( repos_ctr <= 0 )
goto LABEL_6;
v1 = 0LL;
do
{
v2 = v1++;
v3 = ((__int64 (__fastcall *)(_QWORD *))repos_list[2 * v2])(v0);
myQueries = v3;
v0 = (_QWORD *)v3;
}
while ( repos_ctr > (int)v1 );
if ( v3 )
{
LABEL_6:
v4 = 0;
do
{
while ( 1 )
{
v6 = *v0;
v7 = *(unsigned int *)(*v0 + 16LL);
if ( !(_DWORD)v7 )
break;
(*(void (__fastcall **)(__int64, _QWORD, _QWORD))(v6 + 352))(v7, *(_QWORD *)(v6 + 344), *(_QWORD *)(v6 + 8));
v5 = (_DWORD *)*v0;
v0 = (_QWORD *)v0[1];
v4 = 1;
*v5 = 1;
if ( !v0 )
goto LABEL_12;
}
v0 = (_QWORD *)v0[1];
if ( *(_DWORD *)v6 )
v4 = 1;
}
while ( v0 );
LABEL_12:
if ( v4 )
myQueries = filterQueryList(myQueries);
}
}
}

original_code:
void poll_vr( )
{
 queryList *tempQueries ;
 int tag = 0 ;
 int i ;
 if( myQueries != ((void *)0) )
 {
  for( i = 0 ; i < repos_ctr ; i++ )
   myQueries = repos_list[i].queryTool( myQueries ) ;
  tempQueries = myQueries ;
  while( tempQueries != ((void *)0) )
  {
   if( tempQueries -> oneQuery -> numFound )
   {
    tag = 1 ;
    tempQueries -> oneQuery -> callback( tempQueries -> oneQuery -> numFound,
                    tempQueries -> oneQuery -> results,
                    tempQueries -> oneQuery -> data ) ;
    tempQueries -> oneQuery -> removeTag = 1 ;
   }
   else if( tempQueries -> oneQuery -> removeTag )
    tag = 1 ;
   tempQueries = ( queryList* ) tempQueries -> link ;
  }
  if ( tag )
   myQueries = filterQueryList( myQueries ) ;
 }
}

canonical_original_code:
void poll_vr()
{
 struct queryList *tempQueries;
 int tag = 0;
 int i;
 if( myQueries != ((void *)0) )
 {
  for( i = 0 ; i < repos_ctr ; i++ )
   myQueries = repos_list[i].queryTool( myQueries ) ;
  tempQueries = myQueries ;
  while( tempQueries != ((void *)0) )
  {
   if( tempQueries -> oneQuery -> numFound )
   {
    tag = 1 ;
    tempQueries -> oneQuery -> callback( tempQueries -> oneQuery -> numFound,
                    tempQueries -> oneQuery -> results,
                    tempQueries -> oneQuery -> data ) ;
    tempQueries -> oneQuery -> removeTag = 1 ;
   }
   else if( tempQueries -> oneQuery -> removeTag )
    tag = 1 ;
   tempQueries = ( struct queryList * ) tempQueries -> link ;
  }
  if ( tag )
   myQueries = filterQueryList( myQueries ) ;
 }
}

variable_types: struct queryList { struct query { int removeTag; int numClauses; int *data; int numFound; struct clause { char *attribute; char *operator; char *value; char *conjecture; } myClauses[10]; struct resultList { char *oneResult; struct resultList *link; } *results; void (*callback)(int, struct resultList *, void *data); } *oneQuery; struct queryList *link; } *

variable_types: tag int

user_defined_types: struct queryList { struct query *oneQuery; struct queryList *link; }

user_defined_types: struct query { int removeTag; int numClauses; int *data; int numFound; struct clause myClauses[10]; struct resultList *results; void (*callback)(int, struct resultList *, void *data); }


isValidAttribute

decompiled_code:
__int64 __fastcall isValidAttribute(char *s2)
{
char *v1; // rbx
_QWORD v3[3]; // [rsp+0h] [rbp-38h] BYREF
char v4; // [rsp+18h] [rbp-20h] BYREF

v3[1] = "DATE";
v3[2] = "NAME";
if ( s2 )
{
v1 = (char *)v3;
if ( !strcmp("ID", s2) )
return 1LL;
while ( 1 )
{
v1 += 8;
if ( v1 == &v4 )
break;
if ( !strcmp(*(const char **)v1, s2) )
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
char *v1; // rbx
_QWORD v3[3]; // [rsp+0h] [rbp-38h] BYREF
char v4; // [rsp+18h] [rbp-20h] BYREF

v3[1] = "DATE";
v3[2] = "NAME";
if ( s2 )
{
v1 = (char *)v3;
if ( !strcmp("ID", s2) )
return 1LL;
while ( 1 )
{
v1 += 8;
if ( v1 == &v4 )
break;
if ( !strcmp(*(const char **)v1, s2) )
return 1LL;
}
}
return 0LL;
}

original_code:
_Bool isValidAttribute( char *attr )
{
 int i ;
 char *attributes[3] = { "ID","DATE", "NAME" } ;
 if( attr == ((void *)0) )
  return 0;
 for( i = 0 ; i < 3 ; i++ )
 {
  if( ( strcmp( attributes[i], attr ) == 0 ) )
   return 1 ;
 }
 return 0 ;
}

canonical_original_code:
_Bool isValidAttribute(char *attr)
{
 int i;
 char *attributes[3] = { "ID","DATE", "NAME" };
 if( attr == ((void *)0) )
  return 0;
 for( i = 0 ; i < 3 ; i++ )
 {
  if( ( strcmp( attributes[i], attr ) == 0 ) )
   return 1 ;
 }
 return 0 ;
}

variable_types:
attr
char *

variable_types:
attributes
char *[3]


isValidValue

decompiled_code:
bool __fastcall isValidValue(__int64 a1)
{
return a1 != 0;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1)
{
return a1 != 0;
}

original_code:
_Bool isValidValue( char *val )
{
 if ( val == ((void *)0) )
  return 0 ;
 return 1 ;
}

canonical_original_code:
_Bool isValidValue(char *val)
{
 if ( val == ((void *)0) )
  return 0 ;
 return 1 ;
}

variable_types:
val
char *


isValidConjecture

decompiled_code:
bool __fastcall isValidConjecture(const char *a1)
{
int v1; // ecx
int v2; // edx
bool result; // al
int v4; // ecx

if ( !a1 )
return 0;
if ( !strcmp("AND", a1) )
return 1;
v1 = *(unsigned __int8 *)a1;
v2 = 79 - v1;
if ( v1 == 79 && (v4 = *((unsigned __int8 *)a1 + 1), v2 = 82 - v4, v4 == 82) )
result = a1[2] == 0;
else
result = v2 == 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func4(const char *a1)
{
int v1; // ecx
int v2; // edx
bool result; // al
int v4; // ecx

if ( !a1 )
return 0;
if ( !strcmp("AND", a1) )
return 1;
v1 = *(unsigned __int8 *)a1;
v2 = 79 - v1;
if ( v1 == 79 && (v4 = *((unsigned __int8 *)a1 + 1), v2 = 82 - v4, v4 == 82) )
result = a1[2] == 0;
else
result = v2 == 0;
return result;
}

original_code:
_Bool isValidConjecture( char *con )
{
 int i ;
 char *conjecture[2] = { "AND","OR" } ;
 if( con == ((void *)0) )
  return 0;
 for( i = 0 ; i < 2; i++ )
 {
  if( ( strcmp( conjecture[i], con ) == 0 ) )
   return 1 ;
 }
 return 0 ;
}

canonical_original_code:
_Bool isValidConjecture(char *con)
{
 int i;
 char *conjecture[2] = { "AND","OR" };
 if( con == ((void *)0) )
  return 0;
 for( i = 0 ; i < 2; i++ )
 {
  if( ( strcmp( conjecture[i], con ) == 0 ) )
   return 1 ;
 }
 return 0 ;
}

variable_types:
con
char *

variable_types:
conjecture
char *[2]


timeStampValidator

original_code:
int timeStampValidator( char *timeStamp )
{
 if( ( timeStamp + 2 )[0] == '/' &&
     ( timeStamp + 5 )[0] == '/' &&
     ( timeStamp + 10)[0] == '-' &&
     ( timeStamp + 13)[0] == ':' &&
     ( timeStamp + 16)[0] == ':' &&
     ( timeStamp + 19)[0] == '\0')
  return 1 ;
 else
  return 0 ;
}

canonical_original_code:
int timeStampValidator(char *timeStamp)
{
 if( ( timeStamp + 2 )[0] == '/' &&
     ( timeStamp + 5 )[0] == '/' &&
     ( timeStamp + 10)[0] == '-' &&
     ( timeStamp + 13)[0] == ':' &&
     ( timeStamp + 16)[0] == ':' &&
     ( timeStamp + 19)[0] == '\0')
  return 1 ;
 else
  return 0 ;
}

variable_types:
timeStamp
char *

return_type: int


isValidQuery

decompiled_code:
__int64 __fastcall isValidQuery(__int64 a1, int a2)
{
const char **v3; // rbx
unsigned int v4; // er8
int v5; // ebp
const char *v6; // rsi
__int64 v7; // rdi
char *v8; // rdi
unsigned int v10; // eax
__int64 v11; // rdx
__int64 v12; // rcx
__int128 v13; // [rsp+0h] [rbp-418h] BYREF
char v14[984]; // [rsp+10h] [rbp-408h] BYREF

v13 = 0LL;
memset(v14, 0, sizeof(v14));
if ( a2 >= 0 )
{
v3 = (const char **)(a1 + 40);
v4 = 1;
v5 = 0;
while ( 1 )
{
v7 = (__int64)*(v3 - 2);
if ( *(_BYTE *)v7 == 73 && *(_BYTE *)(v7 + 1) == 68 && !*(_BYTE *)(v7 + 2) )
break;
if ( !strcmp("DATE", (const char *)v7) )
{
v8 = (char *)*v3;
++v5;
v3 += 4;
v4 = timeStampValidator(v8);
if ( a2 < v5 )
return v4;
}
else
{
LABEL_7:
++v5;
v3 += 4;
if ( a2 < v5 )
return v4;
}
}
v6 = *v3;
strcpy((char *)&v13, *v3);
if ( (unsigned int)isFileQuery(&v13) )
{
v4 = FSqueryValidator(&v13);
}
else
{
v10 = isEMAILQuery(&v13);
v4 = v10;
if ( v10 )
v4 = EMAILqueryValidator(&v13, v6, v11, v12, v10);
}
goto LABEL_7;
}
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
const char **v3; // rbx
unsigned int v4; // er8
int v5; // ebp
const char *v6; // rsi
__int64 v7; // rdi
char *v8; // rdi
unsigned int v10; // eax
__int64 v11; // rdx
__int64 v12; // rcx
__int128 v13; // [rsp+0h] [rbp-418h] BYREF
char v14[984]; // [rsp+10h] [rbp-408h] BYREF

v13 = 0LL;
memset(v14, 0, sizeof(v14));
if ( a2 >= 0 )
{
v3 = (const char **)(a1 + 40);
v4 = 1;
v5 = 0;
while ( 1 )
{
v7 = (__int64)*(v3 - 2);
if ( *(_BYTE *)v7 == 73 && *(_BYTE *)(v7 + 1) == 68 && !*(_BYTE *)(v7 + 2) )
break;
if ( !strcmp("DATE", (const char *)v7) )
{
v8 = (char *)*v3;
++v5;
v3 += 4;
v4 = func5(v8);
if ( a2 < v5 )
return v4;
}
else
{
LABEL_7:
++v5;
v3 += 4;
if ( a2 < v5 )
return v4;
}
}
v6 = *v3;
strcpy((char *)&v13, *v3);
if ( (unsigned int)isFileQuery(&v13) )
{
v4 = FSqueryValidator(&v13);
}
else
{
v10 = isEMAILQuery(&v13);
v4 = v10;
if ( v10 )
v4 = EMAILqueryValidator(&v13, v6, v11, v12, v10);
}
goto LABEL_7;
}
return 1;
}

original_code:
int isValidQuery( query *theQuery, int numClauses )
{
 int timeStampValidator( char * ) ;
 char testValue[1000] = { '\0' } ;
 int i ;
 int validResult = 1 ;
 for( i = 0 ; i <= numClauses ; i++ )
 {
  if( strcmp( "ID", theQuery -> myClauses[i].attribute ) == 0 )
  {
   strcpy ( testValue ,theQuery -> myClauses[i].value ) ;
   if( isFileQuery( testValue ) )
    validResult = FSqueryValidator( testValue ) ;
   else if( isEMAILQuery( testValue ) )
    validResult = EMAILqueryValidator( testValue ) ;
   else
    validResult = 0 ;
  }
  else if( strcmp( "DATE", theQuery -> myClauses[i].attribute ) == 0 )
   validResult = timeStampValidator( theQuery -> myClauses[i].value ) ;
 }
 return validResult ;
}

canonical_original_code:
int isValidQuery(struct query *theQuery, int numClauses)
{
 int timeStampValidator(char *);
 char testValue[1000] = { '\0' };
 int i;
 int validResult = 1;
 for( i = 0 ; i <= numClauses ; i++ )
 {
  if( strcmp( "ID", theQuery -> myClauses[i].attribute ) == 0 )
  {
   strcpy ( testValue ,theQuery -> myClauses[i].value ) ;
   if( isFileQuery( testValue ) )
    validResult = FSqueryValidator( testValue ) ;
   else if( isEMAILQuery( testValue ) )
    validResult = EMAILqueryValidator( testValue ) ;
   else
    validResult = 0 ;
  }
  else if( strcmp( "DATE", theQuery -> myClauses[i].attribute ) == 0 )
   validResult = timeStampValidator( theQuery -> myClauses[i].value ) ;
 }
 return validResult ;
}

variable_types: struct query { int removeTag; int numClauses; int *data; int numFound; struct clause { char *attribute; char *operator; char *value; char *conjecture; } myClauses[10]; struct resultList { char *oneResult; struct resultList *link; } *results; void (*callback)(int, struct resultList *, void *data); } *

variable_types: numClauses int

variable_types:
timeStampValidator
int (char *)

variable_types:
testValue
char [1000]

variable_types: validResult int


decompiled_code:
int __fastcall query_wait(char *s, __int64 a2, __int64 a3)
{
char *v3; // r12
char *v4; // rax
int v5; // er13
int v6; // er15
char *v7; // r14
char *v8; // rax
__int64 *v9; // rbp
char *v10; // rax
const char *v11; // r14
char *v12; // rdi
int v13; // ebx
char *v14; // rax
const char *v15; // r8
char *v16; // rax
__int64 v17; // rax
int v18; // ebp
void **v19; // rbx
void *v20; // rdi
int v21; // ebx
void **v22; // r13
__int64 v23; // rdi
int v25; // [rsp+Ch] [rbp-4Ch]

v3 = (char *)malloc(0x168uLL);
v4 = strtok(s, "\n");
if ( !v4 )
goto LABEL_22;
v5 = 1;
v6 = 0;
v7 = strtok(v4, " ");
if ( !v7 )
goto LABEL_22;
while ( 2 )
{
if ( !(unsigned __int8)isValidAttribute(v7) )
{
do
{
v8 = strtok(0LL, " ");
v7 = v8;
if ( !v8 )
goto LABEL_22;
++v5;
}
while ( !(unsigned __int8)isValidAttribute(v8) );
}
v25 = v6;
v9 = (__int64 *)&v3[32 * v6];
while ( 1 )
{
v9[3] = (__int64)strdup(v7);
do
{
v10 = strtok(0LL, " ");
v11 = v10;
if ( !v10 )
{
v18 = 1;
goto LABEL_24;
}
++v5;
}
while ( !isValidOperator(v10, v9[3]) );
v9[4] = (__int64)strdup(v11);
v12 = strtok(0LL, " ");
if ( !v12 )
goto LABEL_38;
v13 = v5 + 1;
if ( !isValidValue((__int64)v12) )
{
while ( 1 )
{
v12 = strtok(0LL, " ");
if ( !v12 )
break;
++v13;
if ( isValidValue((__int64)v12) )
goto LABEL_14;
}
LABEL_38:
v18 = 2;
LABEL_24:
if ( v6 )
goto LABEL_25;
goto LABEL_27;
}
LABEL_14:
v9[5] = (__int64)strdup(v12);
do
{
v14 = strtok(0LL, " ");
if ( !v14 )
{
if ( v13 == 4 * v6 + 3 && (unsigned int)isValidQuery((__int64)v3, v6) )
{
*((_DWORD *)v3 + 1) = v6;
v23 = myQueries;
*((_DWORD *)v3 + 4) = 0;
*((_QWORD *)v3 + 44) = a2;
*(_DWORD *)v3 = 0;
*((_QWORD *)v3 + 1) = a3;
*((_QWORD *)v3 + 43) = 0LL;
*(_QWORD *)&v3[32 * v6 + 48] = 0LL;
v17 = addQueryItem(v23, v3);
myQueries = v17;
return v17;
}
v18 = 3;
goto LABEL_24;
}
++v13;
}
while ( !isValidConjecture(v14) );
++v6;
v9[6] = (__int64)strdup(v15);
v16 = strtok(0LL, " ");
v7 = v16;
if ( !v16 )
{
v18 = 4;
if ( v25 )
{
LABEL_25:
v19 = (void **)(v3 + 24);
do
{
v20 = *v19;
v19 += 4;
free(v20);
free(*(v19 - 3));
free(*(v19 - 2));
free(*(v19 - 1));
}
while ( &v3[32 * (v25 - 1) + 56] != (char *)v19 );
}
LABEL_27:
v21 = 0;
v22 = (void **)&v3[32 * v25 + 32];
while ( v21 != 2 )
{
if ( v21 == 3 )
{
free(v22[2]);
LABEL_30:
if ( ++v21 == v18 )
goto LABEL_35;
}
else
{
if ( v21 )
{
if ( v21 == 1 )
free(*(void **)&v3[32 * v25 + 32]);
goto LABEL_30;
}
v21 = 1;
free(*(void **)&v3[32 * v25 + 24]);
if ( v18 == 1 )
{
LABEL_35:
free(v3);
LODWORD(v17) = puts("invalid query...");
return v17;
}
}
}
free(v22[1]);
goto LABEL_30;
}
v5 = v13 + 1;
v9 += 4;
if ( !(unsigned __int8)isValidAttribute(v16) )
break;
v25 = v6;
}
v7 = strtok(0LL, " ");
if ( v7 )
{
v5 = v13 + 2;
continue;
}
break;
}
LABEL_22:
LODWORD(v17) = puts("empty query...");
return v17;
}

original_code:
void query_wait( char *queryString, void ( *cback )( int, resultList *, void * ), void *d )
{
 _Bool isValidAttribute( char * ) ;
 _Bool isValidOperator( char *, char * ) ;
 _Bool isValidValue( char * ) ;
 _Bool isValidConjecture( char * ) ;
 int isValidQuery( query *, int ) ;
 int validated ;
 char *word, *toParse ;
 int numParses, numClauses, numTokens ;
 query *newQuery ;
 newQuery = ( query * ) malloc ( sizeof ( query ) ) ;
 numParses = numClauses = numTokens = 0 ;
 word = toParse = ((void *)0) ;
 toParse = strtok( queryString, "\n" ) ;
 if( toParse != ((void *)0) )
  word = strtok( toParse, " " ) ;
 while( word != ((void *)0) )
 {
  numTokens++;
  if(numParses == 4)
  {
   numParses = 0;
   numClauses++;
  }
  switch( numParses )
  {
   case 0 : if( isValidAttribute( word ) )
     {
      newQuery -> myClauses[numClauses].attribute = strdup( word ) ;
      numParses++ ;
     }
     break ;
   case 1 : if( isValidOperator( word, newQuery -> myClauses[numClauses].attribute ) )
     {
      newQuery -> myClauses[numClauses].operator = strdup( word ) ;
      numParses++ ;
     }
     break ;
   case 2 : if( isValidValue( word ) )
     {
      newQuery -> myClauses[numClauses].value = strdup( word ) ;
      numParses++ ;
     }
     break ;
   case 3 : if( isValidConjecture( word ) )
     {
      newQuery -> myClauses[numClauses].conjecture = strdup( word ) ;
      numParses++ ;
     }
     break ;
  }
  word = strtok( ((void *)0), " " ) ;
 }
 validated = 0 ;
 if( ( ( numClauses * 4 + numParses ) == numTokens ) && ( numParses == 3 ) )
  validated = isValidQuery( newQuery, numClauses ) ;
 if( validated )
 {
  newQuery -> callback = cback;
  newQuery -> data = d ;
  newQuery -> numFound = 0 ;
  newQuery -> removeTag = 0 ;
  newQuery -> numClauses = numClauses ;
  newQuery -> results = ((void *)0) ;
  newQuery -> myClauses[numClauses].conjecture = ((void *)0) ;
  myQueries = addQueryItem( myQueries, newQuery ) ;
  numParses = 0 ;
 }
 else
 {
  if( numParses != 0 )
  {
   int k ;
   for( k = 0 ; k != numClauses; k++ )
   {
    free( newQuery -> myClauses[k].attribute );
    free( newQuery -> myClauses[k].operator ) ;
    free( newQuery -> myClauses[k].value ) ;
    free( newQuery -> myClauses[k].conjecture ) ;
   }
   for( k = 0 ; k < numParses ; k++ )
   {
    switch( k )
    {
     case 0 : free( newQuery -> myClauses[numClauses].attribute ) ;
       break ;
     case 1 : free( newQuery -> myClauses[numClauses].operator ) ;
       break ;
     case 2 : free( newQuery -> myClauses[numClauses].value ) ;
       break ;
     case 3 : free( newQuery -> myClauses[numClauses].conjecture ) ;
       break ;
    }
   }
   free( newQuery ) ;
   printf( "invalid query...\n" ) ;
  }
  else
   printf( "empty query...\n" ) ;
 }
}

canonical_original_code:
void query_wait(char *queryString, void (*cback)(int, struct resultList *, void *), void *d)
{
 _Bool isValidAttribute(char *);
 _Bool isValidOperator(char *, char *);
 _Bool isValidValue(char *);
 _Bool isValidConjecture(char *);
 int isValidQuery(struct query *, int);
 int validated;
 char *word; char *toParse;
 int numParses; int numClauses; int numTokens;
 struct query *newQuery;
 newQuery = ( struct query * ) malloc ( sizeof ( query ) ) ;
 numParses = numClauses = numTokens = 0 ;
 word = toParse = ((void *)0) ;
 toParse = strtok( queryString, "\n" ) ;
 if( toParse != ((void *)0) )
  word = strtok( toParse, " " ) ;
 while( word != ((void *)0) )
 {
  numTokens++;
  if(numParses == 4)
  {
   numParses = 0;
   numClauses++;
  }
  switch( numParses )
  {
   case 0 : if( isValidAttribute( word ) )
     {
      newQuery -> myClauses[numClauses].attribute = strdup( word ) ;
      numParses++ ;
     }
     break ;
   case 1 : if( isValidOperator( word, newQuery -> myClauses[numClauses].attribute ) )
     {
      newQuery -> myClauses[numClauses].operator = strdup( word ) ;
      numParses++ ;
     }
     break ;
   case 2 : if( isValidValue( word ) )
     {
      newQuery -> myClauses[numClauses].value = strdup( word ) ;
      numParses++ ;
     }
     break ;
   case 3 : if( isValidConjecture( word ) )
     {
      newQuery -> myClauses[numClauses].conjecture = strdup( word ) ;
      numParses++ ;
     }
     break ;
  }
  word = strtok( ((void *)0), " " ) ;
 }
 validated = 0 ;
 if( ( ( numClauses * 4 + numParses ) == numTokens ) && ( numParses == 3 ) )
  validated = isValidQuery( newQuery, numClauses ) ;
 if( validated )
 {
  newQuery -> callback = cback;
  newQuery -> data = d ;
  newQuery -> numFound = 0 ;
  newQuery -> removeTag = 0 ;
  newQuery -> numClauses = numClauses ;
  newQuery -> results = ((void *)0) ;
  newQuery -> myClauses[numClauses].conjecture = ((void *)0) ;
  myQueries = addQueryItem( myQueries, newQuery ) ;
  numParses = 0 ;
 }
 else
 {
  if( numParses != 0 )
  {
   int k;
   for( k = 0 ; k != numClauses; k++ )
   {
    free( newQuery -> myClauses[k].attribute );
    free( newQuery -> myClauses[k].operator ) ;
    free( newQuery -> myClauses[k].value ) ;
    free( newQuery -> myClauses[k].conjecture ) ;
   }
   for( k = 0 ; k < numParses ; k++ )
   {
    switch( k )
    {
     case 0 : free( newQuery -> myClauses[numClauses].attribute ) ;
       break ;
     case 1 : free( newQuery -> myClauses[numClauses].operator ) ;
       break ;
     case 2 : free( newQuery -> myClauses[numClauses].value ) ;
       break ;
     case 3 : free( newQuery -> myClauses[numClauses].conjecture ) ;
       break ;
    }
   }
   free( newQuery ) ;
   printf( "invalid query...\n" ) ;
  }
  else
   printf( "empty query...\n" ) ;
 }
}

variable_types:
queryString
char *

variable_types: void (*)(int, struct resultList { char *oneResult; struct resultList *link; } *, void *)

variable_types:
d
void *

variable_types:
isValidAttribute
_Bool (char *)

variable_types:
isValidOperator
_Bool (char *, char *)

variable_types:
isValidValue
_Bool (char *)

variable_types:
isValidConjecture
_Bool (char *)

variable_types: int (struct query { int removeTag; int numClauses; int *data; int numFound; struct clause { char *attribute; char *operator; char *value; char *conjecture; } myClauses[10]; struct resultList { char *oneResult; struct resultList *link; } *results; void (*callback)(int, struct resultList *, void *data); } *, int)

variable_types: validated int

variable_types:
word
char *

variable_types:
toParse
char *

variable_types: numParses int

variable_types: numTokens int

variable_types: k int


decompiled_code:
__int64 setup_fs()
{
int v0; // eax
__int64 v1; // rdx
__int64 result; // rax

v0 = repos_ctr;
v1 = 2LL * repos_ctr;
repos_list[v1] = (__int64)&FSqueryTool;
result = (unsigned int)(v0 + 1);
repos_list[v1 + 1] = (__int64)"file";
repos_ctr = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 v1; // rdx
__int64 result; // rax

v0 = repos_ctr;
v1 = 2LL * repos_ctr;
repos_list[v1] = (__int64)&FSqueryTool;
result = (unsigned int)(v0 + 1);
repos_list[v1 + 1] = (__int64)"file";
repos_ctr = result;
return result;
}

original_code:
void setup_fs( )
{
 repos_list[repos_ctr].queryTool = FSqueryTool ;
 repos_list[repos_ctr].queryToolType = "file" ;
 repos_ctr ++;
}

canonical_original_code:
void setup_fs()
{
 repos_list[repos_ctr].queryTool = FSqueryTool ;
 repos_list[repos_ctr].queryToolType = "file" ;
 repos_ctr ++;
}


decompiled_code:
__int64 setup_email()
{
int v0; // eax
__int64 v1; // rdx
__int64 result; // rax

v0 = repos_ctr;
v1 = 2LL * repos_ctr;
repos_list[v1] = (__int64)&EMAILqueryTool;
result = (unsigned int)(v0 + 1);
repos_list[v1 + 1] = (__int64)"email";
repos_ctr = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
__int64 v1; // rdx
__int64 result; // rax

v0 = repos_ctr;
v1 = 2LL * repos_ctr;
repos_list[v1] = (__int64)&EMAILqueryTool;
result = (unsigned int)(v0 + 1);
repos_list[v1 + 1] = (__int64)"email";
repos_ctr = result;
return result;
}

original_code:
void setup_email( )
{
 repos_list[repos_ctr].queryTool = EMAILqueryTool ;
 repos_list[repos_ctr].queryToolType = "email" ;
 repos_ctr ++;
}

canonical_original_code:
void setup_email()
{
 repos_list[repos_ctr].queryTool = EMAILqueryTool ;
 repos_list[repos_ctr].queryToolType = "email" ;
 repos_ctr ++;
}


decompiled_code:
__int64 setup_vr()
{
setup_fs();
return setup_email();
}

canonical_decompiled_code:
__int64 func2()
{
func0();
return func1();
}

original_code:
void setup_vr( )
{
 setup_fs( ) ;
 setup_email( ) ;
}

canonical_original_code:
void setup_vr()
{
 setup_fs( ) ;
 setup_email( ) ;
}


debug

decompiled_code:
size_t debug(const char *a1, unsigned int a2, int a3, const char *a4, ...)
{
size_t result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a4);
result = (size_t)arg[0].reg_save_area;
if ( debug_level >= a3 )
{
fwrite(&unk_164, 1uLL, 2uLL, stderr);
fprintf(stderr, "%s %d: ", a1, a2);
vfprintf(stderr, a4, arg);
result = fwrite(&unk_164, 1uLL, 2uLL, stderr);
}
return result;
}

canonical_decompiled_code:
size_t func0(const char *a1, unsigned int a2, int a3, const char *a4, ...)
{
size_t result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a4);
result = (size_t)arg[0].reg_save_area;
if ( debug_level >= a3 )
{
fwrite(&unk_164, 1uLL, 2uLL, stderr);
fprintf(stderr, "%s %d: ", a1, a2);
vfprintf(stderr, a4, arg);
result = fwrite(&unk_164, 1uLL, 2uLL, stderr);
}
return result;
}

original_code:
void
debug(const char *format, ...)
{
  va_list args;
  if (debug_flag) {
    __builtin_va_start(args,format);
    vfprintf(stderr, format, args);
    __builtin_va_end(args);
  }
}

canonical_original_code:
void debug(char *format, ...)
{
  __builtin_va_list args;
  if (debug_flag) {
    __builtin_va_start(args,format);
    vfprintf(stderr, format, args);
    __builtin_va_end(args);
  }
}

variable_types:
format
char *


decompiled_code:
void __fastcall set_debug(const char *a1)
{
if ( a1 )
debug_level = atoi(a1);
}

canonical_decompiled_code:
void __fastcall func1(const char *a1)
{
if ( a1 )
debug_level = atoi(a1);
}

original_code:
void set_debug( char *mylevel )
{
 if ( mylevel != ((void *)0) )
  debug_level = atoi( mylevel ) ;
}

canonical_original_code:
void set_debug(char *mylevel)
{
 if ( mylevel != ((void *)0) )
  debug_level = atoi( mylevel ) ;
}

variable_types:
mylevel
char *


decompiled_code:
int print_usage()
{
printf("\nUsage - \n\tpmlc [-d] [-h] [-f] [-l] [-P] ");
puts("<pml source file>");
printf("\nNote: The command \"pmlc\" performs the same function");
printf("as \"compiler\".\n The \"compiler\" command remains for ");
puts("backward compatibility.\n");
puts("\t-d : debug information. Displays data dictionary and");
puts("\t\tif gdbm, reads gdbm file.");
puts("\t-h[elp] : usage");
printf("\n\t-f[ormat] CPML|TEXT|GDBM : ");
puts("output format CPML,TEXT,GDBM");
puts("\t\tCPML output is currently equivalent to TEXT output,");
printf("\t\tthe extensions will differ. ");
puts("The format request can be");
puts("\t\tall upper case or all lower case.");
puts("\n\t-l : retains list file when output is gdbm");
printf("\t-P : retains output from C pre-processor ");
puts("filename.pml.pp)");
printf("\n\tThe pml source file extension is \"pml\". ");
printf("If no extension ");
puts("is specified\n\t\".pml\" is assumed \n");
puts("\tExamples:");
puts("\t\t compiler -fgdbm filename.pml");
puts("\t\t compiler filename -f GDBM");
return puts("\t\t compiler filename -format text");
}

canonical_decompiled_code:
int func0()
{
printf("\nUsage - \n\tpmlc [-d] [-h] [-f] [-l] [-P] ");
puts("<pml source file>");
printf("\nNote: The command \"pmlc\" performs the same function");
printf("as \"compiler\".\n The \"compiler\" command remains for ");
puts("backward compatibility.\n");
puts("\t-d : debug information. Displays data dictionary and");
puts("\t\tif gdbm, reads gdbm file.");
puts("\t-h[elp] : usage");
printf("\n\t-f[ormat] CPML|TEXT|GDBM : ");
puts("output format CPML,TEXT,GDBM");
puts("\t\tCPML output is currently equivalent to TEXT output,");
printf("\t\tthe extensions will differ. ");
puts("The format request can be");
puts("\t\tall upper case or all lower case.");
puts("\n\t-l : retains list file when output is gdbm");
printf("\t-P : retains output from C pre-processor ");
puts("filename.pml.pp)");
printf("\n\tThe pml source file extension is \"pml\". ");
printf("If no extension ");
puts("is specified\n\t\".pml\" is assumed \n");
puts("\tExamples:");
puts("\t\t compiler -fgdbm filename.pml");
puts("\t\t compiler filename -f GDBM");
return puts("\t\t compiler filename -format text");
}

original_code:
void print_usage()
{
 printf("\nUsage - \n\tpmlc [-d] [-h] [-f] [-l] [-P] ");
 printf("<pml source file>\n");
 printf("\nNote: The command \"pmlc\" performs the same function");
 printf("as \"compiler\".\n  The \"compiler\" command remains for ");
 printf("backward compatibility.\n\n");
 printf("\t-d : debug information.  Displays data dictionary and\n");
 printf("\t\tif gdbm, reads gdbm file.\n");
 printf("\t-h[elp] : usage\n");
 printf("\n\t-f[ormat]  CPML|TEXT|GDBM : ");
 printf("output format CPML,TEXT,GDBM\n");
 printf("\t\tCPML output is currently equivalent to TEXT output,\n");
 printf("\t\tthe extensions will differ.  ");
 printf("The format request can be\n");
 printf("\t\tall upper case or all lower case.\n");
 printf("\n\t-l : retains list file when output is gdbm\n");
 printf("\t-P : retains output from C pre-processor ");
 printf("filename.pml.pp)\n");
 printf("\n\tThe pml source file extension is \"pml\". ");
 printf("If no extension ");
 printf("is specified\n\t\".pml\" is assumed \n\n");
 printf("\tExamples:\n");
 printf("\t\t compiler -fgdbm filename.pml\n");
 printf("\t\t compiler filename -f GDBM\n");
 printf("\t\t compiler filename -format text\n");
}


decompiled_code:
__int64 __fastcall validate_inputs(int a1, __int64 a2, const char **a3, char *a4, _DWORD *a5, _DWORD *a6, _DWORD *a7)
{
const char *v7; // rcx
char *v9; // rbp
char *v10; // r12
int v11; // ebx
const char *v12; // r14
__int64 v13; // rdx
char *v14; // rsi
size_t v15; // r15
char *v16; // rax
int v17; // edi
size_t v18; // rbx
char *v19; // rbp
char *v20; // rax
char *v21; // r13
size_t v22; // r14
char *v23; // rax
unsigned int v24; // er15
__pid_t v25; // er13
int v26; // edi
int v28; // eax
int v29; // ecx
size_t v30; // r15
char *v31; // rax
size_t v32; // rdx
char *v33; // r15
const char *v34; // r14
char *v35; // rax
size_t i; // r14
size_t v37; // rax
char *v38; // rax
const char *v39; // rax
size_t v40; // r13
char *v41; // rax
size_t n; // [rsp+18h] [rbp-50h]

v7 = "PML input file required";
if ( a1 <= 1 )
goto LABEL_32;
v9 = 0LL;
v10 = 0LL;
v11 = 1;
while ( 1 )
{
v12 = *(const char **)(a2 + 8LL * v11);
v13 = 8LL * v11;
if ( *v12 != 45 )
{
v14 = strrchr(*(const char **)(a2 + 8LL * v11), 46);
if ( v14 )
{
if ( strcmp(v14, ".pml") )
{
v7 = "pml extension expected";
goto LABEL_32;
}
v15 = strlen(v12) + 1;
v16 = (char *)calloc(v15, 1uLL);
v10 = v16;
if ( !v16 )
goto LABEL_66;
memcpy(v16, v12, v15);
}
else
{
v30 = strlen(v12);
v31 = (char *)calloc(v30 + 5, 1uLL);
v10 = v31;
if ( !v31 )
goto LABEL_66;
v32 = v30;
v33 = &v31[v30];
memcpy(v31, v12, v32);
strcpy(v33, ".pml");
}
v17 = open(v10, 0);
if ( v17 < 0 )
{
pmlprint(0LL, 4LL, "validate_inputs", v10);
v24 = 0;
goto LABEL_26;
}
close(v17);
goto LABEL_10;
}
v28 = *((unsigned __int8 *)v12 + 1);
if ( v28 == 100 && !v12[2] )
{
*a7 = 1;
goto LABEL_10;
}
v29 = *(unsigned __int8 *)v12;
if ( v29 == 45 && v12[1] == 104 )
{
v24 = 2;
goto LABEL_26;
}
if ( *v12 != 45 )
break;
if ( v28 != 80 || v12[2] )
{
if ( v28 != 108 || v12[2] )
break;
*a6 = 1;
}
else
{
*a5 = 1;
}
LABEL_10:
if ( a1 <= ++v11 )
{
if ( v9 )
{
strcpy(a4, v9);
free(v9);
if ( v10 )
goto LABEL_13;
}
else
{
strcpy(a4, "gdbm");
if ( v10 )
{
LABEL_13:
v18 = strlen(v10);
v19 = (char *)calloc(v18 + 4, 1uLL);
*a3 = v19;
if ( !v19 )
{
pmlprint(0LL, 3LL, "validate_inputs", 0LL);
v24 = 0;
LABEL_20:
free(v10);
goto LABEL_21;
}
memcpy(v19, v10, v18);
*(_DWORD *)&v19[v18] = 7368750;
v20 = getenv("CPP");
v21 = v20;
if ( v20 )
{
v22 = strlen(v20) + 1;
v23 = (char *)calloc(v22, 1uLL);
v19 = v23;
if ( v23 )
{
v24 = 1;
memcpy(v23, v21, v22);
goto LABEL_17;
}
}
else
{
v19 = (char *)calloc(0xDuLL, 1uLL);
if ( v19 )
{
v24 = 1;
strcpy(v19, "/usr/bin/cpp");
goto LABEL_17;
}
}
v19 = 0LL;
v24 = 0;
pmlprint(1LL, 3LL, "validate_inputs", 0LL);
LABEL_17:
v25 = fork();
if ( !v25 && execlp(v19, "cpp", v10, *a3, "-P", 0LL) < 0 )
exit(1);
waitpid(v25, 0LL, 0);
v26 = open(*a3, 0);
if ( v26 < 0 )
{
pmlprint(1LL, 6LL, "validate_inputs", 0LL);
v39 = *a3;
*(_QWORD *)v39 = 0LL;
*((_DWORD *)v39 + 2) = 0;
v40 = strlen(v10) + 1;
v41 = (char *)calloc(v40, 1uLL);
*a3 = v41;
memcpy(v41, v10, v40);
*a5 = 1;
}
else
{
close(v26);
}
goto LABEL_20;
}
}
pmlprint(0LL, 0LL, "validate_inputs", "PML source code file required");
v19 = 0LL;
v24 = 0;
print_usage();
goto LABEL_21;
}
}
if ( v29 != 45 || (v24 = *((unsigned __int8 *)v12 + 1) - 102, v12[1] != 102) )
{
v7 = "Invalid flags";
LABEL_32:
v24 = 0;
pmlprint(0LL, 0LL, "validate_inputs", v7);
goto LABEL_26;
}
if ( !strcmp(*(const char **)(a2 + 8LL * v11), "-format") || !v12[2] )
{
if ( a1 <= ++v11 )
{
pmlprint(0LL, 0LL, "validate_inputs", "Incomplete argument list");
goto LABEL_26;
}
v34 = *(const char **)(a2 + v13 + 8);
n = strlen(v34) + 1;
v35 = (char *)calloc(n, 1uLL);
v9 = v35;
if ( !v35 )
goto LABEL_66;
memcpy(v35, v34, n);
goto LABEL_47;
}
v37 = strlen(*(const char **)(a2 + 8LL * v11));
v38 = (char *)calloc(v37 - 1, 1uLL);
v9 = v38;
if ( v38 )
{
strcpy(v38, v12 + 2);
LABEL_47:
for ( i = 0LL; strlen(v9) > i; ++i )
v9[i] = tolower(v9[i]);
if ( strcmp(v9, "text") && strcmp(v9, "gdbm") && strcmp(v9, "cpml") )
{
pmlprint(0LL, 0LL, "validate_inputs", "Invalid output format");
goto LABEL_26;
}
goto LABEL_10;
}
LABEL_66:
pmlprint(0LL, 3LL, "validate_inputs", 0LL);
v24 = 0;
LABEL_26:
v19 = 0LL;
print_usage();
LABEL_21:
free(v19);
return v24;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, const char **a3, char *a4, _DWORD *a5, _DWORD *a6, _DWORD *a7)
{
const char *v7; // rcx
char *v9; // rbp
char *v10; // r12
int v11; // ebx
const char *v12; // r14
__int64 v13; // rdx
char *v14; // rsi
size_t v15; // r15
char *v16; // rax
int v17; // edi
size_t v18; // rbx
char *v19; // rbp
char *v20; // rax
char *v21; // r13
size_t v22; // r14
char *v23; // rax
unsigned int v24; // er15
__pid_t v25; // er13
int v26; // edi
int v28; // eax
int v29; // ecx
size_t v30; // r15
char *v31; // rax
size_t v32; // rdx
char *v33; // r15
const char *v34; // r14
char *v35; // rax
size_t i; // r14
size_t v37; // rax
char *v38; // rax
const char *v39; // rax
size_t v40; // r13
char *v41; // rax
size_t n; // [rsp+18h] [rbp-50h]

v7 = "PML input file required";
if ( a1 <= 1 )
goto LABEL_32;
v9 = 0LL;
v10 = 0LL;
v11 = 1;
while ( 1 )
{
v12 = *(const char **)(a2 + 8LL * v11);
v13 = 8LL * v11;
if ( *v12 != 45 )
{
v14 = strrchr(*(const char **)(a2 + 8LL * v11), 46);
if ( v14 )
{
if ( strcmp(v14, ".pml") )
{
v7 = "pml extension expected";
goto LABEL_32;
}
v15 = strlen(v12) + 1;
v16 = (char *)calloc(v15, 1uLL);
v10 = v16;
if ( !v16 )
goto LABEL_66;
memcpy(v16, v12, v15);
}
else
{
v30 = strlen(v12);
v31 = (char *)calloc(v30 + 5, 1uLL);
v10 = v31;
if ( !v31 )
goto LABEL_66;
v32 = v30;
v33 = &v31[v30];
memcpy(v31, v12, v32);
strcpy(v33, ".pml");
}
v17 = open(v10, 0);
if ( v17 < 0 )
{
pmlprint(0LL, 4LL, "validate_inputs", v10);
v24 = 0;
goto LABEL_26;
}
close(v17);
goto LABEL_10;
}
v28 = *((unsigned __int8 *)v12 + 1);
if ( v28 == 100 && !v12[2] )
{
*a7 = 1;
goto LABEL_10;
}
v29 = *(unsigned __int8 *)v12;
if ( v29 == 45 && v12[1] == 104 )
{
v24 = 2;
goto LABEL_26;
}
if ( *v12 != 45 )
break;
if ( v28 != 80 || v12[2] )
{
if ( v28 != 108 || v12[2] )
break;
*a6 = 1;
}
else
{
*a5 = 1;
}
LABEL_10:
if ( a1 <= ++v11 )
{
if ( v9 )
{
strcpy(a4, v9);
free(v9);
if ( v10 )
goto LABEL_13;
}
else
{
strcpy(a4, "gdbm");
if ( v10 )
{
LABEL_13:
v18 = strlen(v10);
v19 = (char *)calloc(v18 + 4, 1uLL);
*a3 = v19;
if ( !v19 )
{
pmlprint(0LL, 3LL, "validate_inputs", 0LL);
v24 = 0;
LABEL_20:
free(v10);
goto LABEL_21;
}
memcpy(v19, v10, v18);
*(_DWORD *)&v19[v18] = 7368750;
v20 = getenv("CPP");
v21 = v20;
if ( v20 )
{
v22 = strlen(v20) + 1;
v23 = (char *)calloc(v22, 1uLL);
v19 = v23;
if ( v23 )
{
v24 = 1;
memcpy(v23, v21, v22);
goto LABEL_17;
}
}
else
{
v19 = (char *)calloc(0xDuLL, 1uLL);
if ( v19 )
{
v24 = 1;
strcpy(v19, "/usr/bin/cpp");
goto LABEL_17;
}
}
v19 = 0LL;
v24 = 0;
pmlprint(1LL, 3LL, "validate_inputs", 0LL);
LABEL_17:
v25 = fork();
if ( !v25 && execlp(v19, "cpp", v10, *a3, "-P", 0LL) < 0 )
exit(1);
waitpid(v25, 0LL, 0);
v26 = open(*a3, 0);
if ( v26 < 0 )
{
pmlprint(1LL, 6LL, "validate_inputs", 0LL);
v39 = *a3;
*(_QWORD *)v39 = 0LL;
*((_DWORD *)v39 + 2) = 0;
v40 = strlen(v10) + 1;
v41 = (char *)calloc(v40, 1uLL);
*a3 = v41;
memcpy(v41, v10, v40);
*a5 = 1;
}
else
{
close(v26);
}
goto LABEL_20;
}
}
pmlprint(0LL, 0LL, "validate_inputs", "PML source code file required");
v19 = 0LL;
v24 = 0;
func0();
goto LABEL_21;
}
}
if ( v29 != 45 || (v24 = *((unsigned __int8 *)v12 + 1) - 102, v12[1] != 102) )
{
v7 = "Invalid flags";
LABEL_32:
v24 = 0;
pmlprint(0LL, 0LL, "validate_inputs", v7);
goto LABEL_26;
}
if ( !strcmp(*(const char **)(a2 + 8LL * v11), "-format") || !v12[2] )
{
if ( a1 <= ++v11 )
{
pmlprint(0LL, 0LL, "validate_inputs", "Incomplete argument list");
goto LABEL_26;
}
v34 = *(const char **)(a2 + v13 + 8);
n = strlen(v34) + 1;
v35 = (char *)calloc(n, 1uLL);
v9 = v35;
if ( !v35 )
goto LABEL_66;
memcpy(v35, v34, n);
goto LABEL_47;
}
v37 = strlen(*(const char **)(a2 + 8LL * v11));
v38 = (char *)calloc(v37 - 1, 1uLL);
v9 = v38;
if ( v38 )
{
strcpy(v38, v12 + 2);
LABEL_47:
for ( i = 0LL; strlen(v9) > i; ++i )
v9[i] = tolower(v9[i]);
if ( strcmp(v9, "text") && strcmp(v9, "gdbm") && strcmp(v9, "cpml") )
{
pmlprint(0LL, 0LL, "validate_inputs", "Invalid output format");
goto LABEL_26;
}
goto LABEL_10;
}
LABEL_66:
pmlprint(0LL, 3LL, "validate_inputs", 0LL);
v24 = 0;
LABEL_26:
v19 = 0LL;
func0();
LABEL_21:
free(v19);
return v24;
}

original_code:
int validate_inputs(int argc, char *argv[], char **pml_filename,
    char *output_file_type,Boolean *ppout,Boolean *list,Boolean *debug)
{
 int fp;
 int returnval = 1;
 int i,j;
 char *filename = ((void *)0);
 char *output = ((void *)0);
 char *ptr = ((void *)0);
 char *module = "validate_inputs";
 char *cppenv = ((void *)0);
 char *cpppath = ((void *)0);
 char *cppcmd = "/usr/bin/cpp";
 pid_t pid;
 if (argc <= 1) {
  pmlprint(ERROR,PMLINP,module,"PML input file required");
  returnval = 0;
 }
 for(i = 1; i < argc; i++) {
  if (returnval == 0) break;
  if (argv[i][0] == '-') {
  if (strcmp(argv[i],"-d") == 0) {
   *debug = 1;
     continue;
  }
  if (strncmp(argv[i],"-h",2) == 0) {
   returnval = 2;
   break;
  }
  if (strcmp(argv[i],"-P") == 0) {
   *ppout = 1;
   continue;
  }
  if (strcmp(argv[i], "-l") == 0) {
   *list = 1;
   continue;
  }
  if (strncmp(argv[i],"-f",2) == 0) {
   if ((strcmp(argv[i],"-format") == 0) ||
       (strcmp(argv[i],"-f") == 0)) {
    i++;
    if ( i >= argc) {
     pmlprint(ERROR,PMLINP,module,
         "Incomplete argument list");
     returnval = 0;
     break;
    }
    if((output = (char *)calloc(strlen(argv[i])+1,
        sizeof(char))) == ((void *)0)) {
     pmlprint(ERROR,PMLMEM,module,((void *)0));
     returnval = 0;
     break;
    } else {
     strcpy(output,argv[i]);
    }
   } else {
      if ((output = (char *)calloc(strlen (argv[i])
        - 1, sizeof (char))) == ((void *)0)) {
     pmlprint(ERROR,PMLMEM,module,((void *)0));
     returnval = 0;
     break;
    } else {
     strcpy(output,argv[i]+2);
    }
   }
   for (j = 0; j < strlen(output); j++) {
    output[j] = tolower(output[j]);
   }
   if ((strcmp(output,"text") !=0) &&
       (strcmp(output,"gdbm") !=0) &&
       (strcmp(output,"cpml") !=0)) {
    pmlprint(ERROR,PMLINP,module,
               "Invalid output format");
    returnval = 0;
    break;
   }
   continue;
  }
  pmlprint(ERROR,PMLINP,module,"Invalid flags");
  returnval = 0;
  break;
 } else {
  ptr = (strrchr(argv[i],'.'));
  if (ptr == ((void *)0)) {
   if((filename = (char *)calloc(strlen(argv[i])+5,
       sizeof(char))) == ((void *)0)) {
    pmlprint(ERROR,PMLMEM,module,((void *)0));
    returnval = 0;
    break;
   } else {
    strcpy(filename,argv[i]);
    strcat(filename,".pml");
   }
  } else {
   if (strcmp(ptr,".pml") != 0) {
    pmlprint(ERROR,PMLINP,module,
        "pml extension expected");
    returnval = 0;
    break;
   } else {
    if((filename = (char *)calloc(strlen(argv[i])
        +1,sizeof(char))) == ((void *)0)) {
     pmlprint(ERROR,PMLMEM,module,((void *)0));
     returnval = 0;
     break;
    } else {
     strcpy(filename,argv[i]);
    }
   }
  }
  if ((fp = open(filename, 00)) < 0) {
   pmlprint(ERROR,PMLFOPN,module,filename);
   returnval = 0;
  } else {
   close(fp);
   }
  }
 }
 if (returnval == 1) {
  if (output != ((void *)0)) {
   strcpy(output_file_type, output);
   free(output);
  } else {
   strcpy(output_file_type, "gdbm");
  }
  if (filename == ((void *)0)) {
   pmlprint(ERROR,PMLINP,module,
       "PML source code file required");
   print_usage();
   returnval = 0;
  } else {
   if((*pml_filename = (char *)calloc(strlen(filename)+4,
       sizeof(char))) == ((void *)0)) {
    pmlprint(ERROR,PMLMEM,module,((void *)0));
    returnval = 0;
   } else {
    strcpy(*pml_filename, filename);
    strcat(*pml_filename,".pp");
    if ((cppenv = getenv("CPP")) != ((void *)0)) {
     if((cpppath = (char *)calloc(
         strlen(cppenv)+1,sizeof(char)))
         == ((void *)0)) {
      pmlprint(WARN,PMLMEM,
          module, ((void *)0));
      returnval = 0;
     } else {
      strcpy(cpppath,cppenv);
     }
    } else {
     if((cpppath = (char *)calloc(
         strlen(cppcmd)+1,sizeof(char)))
         == ((void *)0)) {
      pmlprint(WARN,PMLMEM,
          module, ((void *)0));
      returnval = 0;
     } else {
      strcpy(cpppath,cppcmd);
     }
    }
    pid = fork();
    if (pid == 0) {
     if (execlp(cpppath,
         "cpp",filename,*pml_filename,
         "-P",(char *) 0) < 0) {
      exit(1);
     }
    }
    waitpid(pid, ((void *)0), 0);
    if ((fp = open(*pml_filename, 00)) < 0) {
     pmlprint(WARN,PMLCPP,module,((void *)0));
     memset(*pml_filename,0,
         sizeof(filename)+4);
     *pml_filename = (char *)calloc(
         strlen(filename)+1,sizeof(char));
     strcpy(*pml_filename,filename);
     *ppout = 1;
    } else {
     close(fp);
    }
   }
   free(filename);
  }
 } else {
  print_usage();
 }
 free(cpppath);
 return returnval;
}

canonical_original_code:
int validate_inputs(int argc, char *argv[], char **pml_filename, char *output_file_type, int *ppout, int *list, int *debug)
{
 int fp;
 int returnval = 1;
 int i; int j;
 char *filename = ((void *)0);
 char *output = ((void *)0);
 char *ptr = ((void *)0);
 char *module = "validate_inputs";
 char *cppenv = ((void *)0);
 char *cpppath = ((void *)0);
 char *cppcmd = "/usr/bin/cpp";
 int pid;
 if (argc <= 1) {
  pmlprint(ERROR,PMLINP,module,"PML input file required");
  returnval = 0;
 }
 for(i = 1; i < argc; i++) {
  if (returnval == 0) break;
  if (argv[i][0] == '-') {
  if (strcmp(argv[i],"-d") == 0) {
   *debug = 1;
     continue;
  }
  if (strncmp(argv[i],"-h",2) == 0) {
   returnval = 2;
   break;
  }
  if (strcmp(argv[i],"-P") == 0) {
   *ppout = 1;
   continue;
  }
  if (strcmp(argv[i], "-l") == 0) {
   *list = 1;
   continue;
  }
  if (strncmp(argv[i],"-f",2) == 0) {
   if ((strcmp(argv[i],"-format") == 0) ||
       (strcmp(argv[i],"-f") == 0)) {
    i++;
    if ( i >= argc) {
     pmlprint(ERROR,PMLINP,module,
         "Incomplete argument list");
     returnval = 0;
     break;
    }
    if((output = (char *)calloc(strlen(argv[i])+1,
        sizeof(char))) == ((void *)0)) {
     pmlprint(ERROR,PMLMEM,module,((void *)0));
     returnval = 0;
     break;
    } else {
     strcpy(output,argv[i]);
    }
   } else {
      if ((output = (char *)calloc(strlen (argv[i])
        - 1, sizeof (char))) == ((void *)0)) {
     pmlprint(ERROR,PMLMEM,module,((void *)0));
     returnval = 0;
     break;
    } else {
     strcpy(output,argv[i]+2);
    }
   }
   for (j = 0; j < strlen(output); j++) {
    output[j] = tolower(output[j]);
   }
   if ((strcmp(output,"text") !=0) &&
       (strcmp(output,"gdbm") !=0) &&
       (strcmp(output,"cpml") !=0)) {
    pmlprint(ERROR,PMLINP,module,
               "Invalid output format");
    returnval = 0;
    break;
   }
   continue;
  }
  pmlprint(ERROR,PMLINP,module,"Invalid flags");
  returnval = 0;
  break;
 } else {
  ptr = (strrchr(argv[i],'.'));
  if (ptr == ((void *)0)) {
   if((filename = (char *)calloc(strlen(argv[i])+5,
       sizeof(char))) == ((void *)0)) {
    pmlprint(ERROR,PMLMEM,module,((void *)0));
    returnval = 0;
    break;
   } else {
    strcpy(filename,argv[i]);
    strcat(filename,".pml");
   }
  } else {
   if (strcmp(ptr,".pml") != 0) {
    pmlprint(ERROR,PMLINP,module,
        "pml extension expected");
    returnval = 0;
    break;
   } else {
    if((filename = (char *)calloc(strlen(argv[i])
        +1,sizeof(char))) == ((void *)0)) {
     pmlprint(ERROR,PMLMEM,module,((void *)0));
     returnval = 0;
     break;
    } else {
     strcpy(filename,argv[i]);
    }
   }
  }
  if ((fp = open(filename, 00)) < 0) {
   pmlprint(ERROR,PMLFOPN,module,filename);
   returnval = 0;
  } else {
   close(fp);
   }
  }
 }
 if (returnval == 1) {
  if (output != ((void *)0)) {
   strcpy(output_file_type, output);
   free(output);
  } else {
   strcpy(output_file_type, "gdbm");
  }
  if (filename == ((void *)0)) {
   pmlprint(ERROR,PMLINP,module,
       "PML source code file required");
   print_usage();
   returnval = 0;
  } else {
   if((*pml_filename = (char *)calloc(strlen(filename)+4,
       sizeof(char))) == ((void *)0)) {
    pmlprint(ERROR,PMLMEM,module,((void *)0));
    returnval = 0;
   } else {
    strcpy(*pml_filename, filename);
    strcat(*pml_filename,".pp");
    if ((cppenv = getenv("CPP")) != ((void *)0)) {
     if((cpppath = (char *)calloc(
         strlen(cppenv)+1,sizeof(char)))
         == ((void *)0)) {
      pmlprint(WARN,PMLMEM,
          module, ((void *)0));
      returnval = 0;
     } else {
      strcpy(cpppath,cppenv);
     }
    } else {
     if((cpppath = (char *)calloc(
         strlen(cppcmd)+1,sizeof(char)))
         == ((void *)0)) {
      pmlprint(WARN,PMLMEM,
          module, ((void *)0));
      returnval = 0;
     } else {
      strcpy(cpppath,cppcmd);
     }
    }
    pid = fork();
    if (pid == 0) {
     if (execlp(cpppath,
         "cpp",filename,*pml_filename,
         "-P",(char *) 0) < 0) {
      exit(1);
     }
    }
    waitpid(pid, ((void *)0), 0);
    if ((fp = open(*pml_filename, 00)) < 0) {
     pmlprint(WARN,PMLCPP,module,((void *)0));
     memset(*pml_filename,0,
         sizeof(filename)+4);
     *pml_filename = (char *)calloc(
         strlen(filename)+1,sizeof(char));
     strcpy(*pml_filename,filename);
     *ppout = 1;
    } else {
     close(fp);
    }
   }
   free(filename);
  }
 } else {
  print_usage();
 }
 free(cpppath);
 return returnval;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
ppout
int *

variable_types:
list
int *

variable_types:
debug
int *

variable_types: fp int

variable_types: returnval int

variable_types: i int

variable_types: j int

variable_types:
filename
char *

variable_types:
output
char *

variable_types:
ptr
char *

variable_types:
module
char *

variable_types:
cppenv
char *

variable_types:
cpppath
char *

variable_types:
cppcmd
char *

variable_types: pid int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v6; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v7; // [rsp+10h] [rbp-38h] BYREF
unsigned int v8; // [rsp+14h] [rbp-34h] BYREF
char v9[5]; // [rsp+1Bh] [rbp-2Dh] BYREF
char *filename; // [rsp+20h] [rbp-28h] BYREF
char v11[32]; // [rsp+28h] [rbp-20h] BYREF

v6 = 0;
v7 = 0;
v8 = 0;
pmlprint(2LL, 7LL, "main", 0LL);
v3 = validate_inputs(argc, (__int64)argv, (const char **)&filename, v9, &v6, &v7, &v8);
v4 = v3;
if ( v3 )
{
if ( v3 != 2 )
{
v4 = parse_pml(filename, v11, v8);
if ( v4 == 1 )
v4 = write_cpml(filename, v11, v9, v8, v7);
if ( !v6 )
remove(filename);
}
}
else
{
pmlprint(0LL, 0LL, "main", 0LL);
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v6; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v7; // [rsp+10h] [rbp-38h] BYREF
unsigned int v8; // [rsp+14h] [rbp-34h] BYREF
char v9[5]; // [rsp+1Bh] [rbp-2Dh] BYREF
char *filename; // [rsp+20h] [rbp-28h] BYREF
char v11[32]; // [rsp+28h] [rbp-20h] BYREF

v6 = 0;
v7 = 0;
v8 = 0;
pmlprint(2LL, 7LL, "main", 0LL);
v3 = func1(argc, (__int64)argv, (const char **)&filename, v9, &v6, &v7, &v8);
v4 = v3;
if ( v3 )
{
if ( v3 != 2 )
{
v4 = parse_pml(filename, v11, v8);
if ( v4 == 1 )
v4 = write_cpml(filename, v11, v9, v8, v7);
if ( !v6 )
remove(filename);
}
}
else
{
pmlprint(0LL, 0LL, "main", 0LL);
}
return v4;
}

original_code:
int main (int argc, char *argv[])
{
 char *pml_filename;
 char *module = "main";
 char output_file_type[5];
 data_dictionary_struct data_dictionary;
 int returnval;
 Boolean ppout = 0;
 Boolean list = 0;
 Boolean debug = 0;
 int old_format = 0;
 pmlprint(INFO,PMLVER,module,((void *)0));
 returnval = validate_inputs(argc, argv, &pml_filename, output_file_type,
     &ppout,&list,&debug);
 if (returnval == 0) {
  pmlprint(ERROR,PMLINP,module,((void *)0));
  return returnval;
 } else if (returnval == 2) {
  return returnval;
 } else {
  returnval = parse_pml(pml_filename, &data_dictionary,
      debug);
 }
 if (returnval == 1) {
  returnval = write_cpml(pml_filename, &data_dictionary,
      output_file_type,debug,list);
 }
 if (ppout == 0) {
  remove(pml_filename);
 }
 return returnval;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *pml_filename;
 char *module = "main";
 char output_file_type[5];
 struct data_dictionary_struct data_dictionary;
 int returnval;
 int ppout = 0;
 int list = 0;
 int debug = 0;
 int old_format = 0;
 pmlprint(INFO,PMLVER,module,((void *)0));
 returnval = validate_inputs(argc, argv, &pml_filename, output_file_type,
     &ppout,&list,&debug);
 if (returnval == 0) {
  pmlprint(ERROR,PMLINP,module,((void *)0));
  return returnval;
 } else if (returnval == 2) {
  return returnval;
 } else {
  returnval = parse_pml(pml_filename, &data_dictionary,
      debug);
 }
 if (returnval == 1) {
  returnval = write_cpml(pml_filename, &data_dictionary,
      output_file_type,debug,list);
 }
 if (ppout == 0) {
  remove(pml_filename);
 }
 return returnval;
}

variable_types: argc int

variable_types: struct data_dictionary_struct { struct data_dict_element_struct { char *level; char *name; char *type; char *mode; struct data_dict_attribute_list_struct { char *attribute; struct string_list_struct { char *cstring; struct string_list_struct *next_string; } *first_description; struct data_dict_attribute_list_struct *next_attribute; } *first_attribute_ptr; struct data_dict_element_struct *parent_ptr; struct data_dict_element_list_struct { struct data_dict_element_struct *data_ptr; struct data_dict_element_list_struct *next_element; } *first_child_ptr; } *root; }

variable_types: ppout int

variable_types: list int

variable_types: debug int

user_defined_types: struct data_dictionary_struct { struct data_dict_element_struct *root; }

user_defined_types: struct data_dict_element_struct { char *level; char *name; char *type; char *mode; struct data_dict_attribute_list_struct *first_attribute_ptr; struct data_dict_element_struct *parent_ptr; struct data_dict_element_list_struct *first_child_ptr; }

user_defined_types: struct data_dict_attribute_list_struct { char *attribute; struct string_list_struct *first_description; struct data_dict_attribute_list_struct *next_attribute; }


pmlprint

decompiled_code:
int __fastcall pmlprint(int a1, int a2, const char *a3, const char *a4)
{
printf("%s", pmlmsg[a1]);
if ( a3 )
printf("[%s] ", a3);
if ( a2 != 9 )
printf("%s", pmlexp[a2]);
if ( a4 )
printf("- %s", a4);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, const char *a3, const char *a4)
{
printf("%s", pmlmsg[a1]);
if ( a3 )
printf("[%s] ", a3);
if ( a2 != 9 )
printf("%s", pmlexp[a2]);
if ( a4 )
printf("- %s", a4);
return putchar(10);
}

original_code:
void
pmlprint(pmltype msgtype,pmlerr errornum,char *module,char *additional)
{
 printf("%s",pmlmsg[msgtype]);
 if(module != ((void *)0)) {
  printf("[%s] ",module);
 }
 if(errornum != PMLNULL) {
  printf("%s",pmlexp[errornum]);
 }
 if(additional != ((void *)0)) {
  printf("- %s",additional);
 }
 printf("\n");
}

canonical_original_code:
void pmlprint(enum pmlmsgtype msgtype, enum pmlerrno errornum, char *module, char *additional)
{
 printf("%s",pmlmsg[msgtype]);
 if(module != ((void *)0)) {
  printf("[%s] ",module);
 }
 if(errornum != PMLNULL) {
  printf("%s",pmlexp[errornum]);
 }
 if(additional != ((void *)0)) {
  printf("- %s",additional);
 }
 printf("\n");
}

variable_types: enum pmlmsgtype { ERROR=0, WARN=1, INFO=2 }

variable_types: enum pmlerrno { PMLINP=0, PMLSYN=1, PMLDD=2, PMLMEM=3, PMLFOPN=4, PMLPARSE=5, PMLCPP=6, PMLVER=7, PMLCOM=8, PMLNULL=9 }

variable_types:
additional
char *


ListCreate

decompiled_code:
_DWORD *ListCreate()
{
_DWORD *v0; // rax
_DWORD *v1; // r12

v0 = malloc(0x18uLL);
*(_QWORD *)v0 = 1LL;
v1 = v0;
v0[2] = 0;
*((_QWORD *)v0 + 2) = malloc(8uLL);
return v1;
}

canonical_decompiled_code:
_DWORD *func2()
{
_DWORD *v0; // rax
_DWORD *v1; // r12

v0 = malloc(0x18uLL);
*(_QWORD *)v0 = 1LL;
v1 = v0;
v0[2] = 0;
*((_QWORD *)v0 + 2) = malloc(8uLL);
return v1;
}

original_code:
List ListCreate ( )
{
    List list;
    list = (List) malloc (sizeof (struct list));
    list -> size = 1;
    list -> count = 0;
    list -> first = 0;
    list -> array = (Item *) malloc (sizeof (Item) * list -> size);
    return list;
}

canonical_original_code:
struct list *ListCreate()
{
    struct list *list;
    list = (struct list *) malloc (sizeof (struct list));
    list -> size = 1;
    list -> count = 0;
    list -> first = 0;
    list -> array = (void **) malloc (sizeof (Item) * list -> size);
    return list;
}

variable_types: struct list { int size; int count; int first; void **array; } *


debug

decompiled_code:
int debug(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = debug_flag;
if ( debug_flag )
{
va_start(arg, format);
result = vfprintf(stderr, format, arg);
}
return result;
}

canonical_decompiled_code:
int func0(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = debug_flag;
if ( debug_flag )
{
va_start(arg, format);
result = vfprintf(stderr, format, arg);
}
return result;
}

variable_types:
format
char *


readl

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

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

original_code:
static inline uint32_t readl(void *ptr)
{
 uint32_t *data = ptr;
 return *data;
}

canonical_original_code:
static inline unsigned int readl(void *ptr)
{
 unsigned int *data = ptr;
 return *data;
}

variable_types:
ptr
void *

variable_types:
data
unsigned int *

return_type: unsigned int


decompiled_code:
__int64 __fastcall mmio_normalize(__int64 *a1)
{
__int64 v1; // rbp
int v2; // eax
__int64 result; // rax

v1 = *a1 + a1[1];
v2 = getpagesize();
a1[1] = v1 & (v2 - 1);
*a1 = v1 & -v2;
result = (int)(v2 * (4 * a1[2] / (unsigned __int64)v2 + 1));
a1[4] = result;
return result;
}

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

v1 = *a1 + a1[1];
v2 = getpagesize();
a1[1] = v1 & (v2 - 1);
*a1 = v1 & -v2;
result = (int)(v2 * (4 * a1[2] / (unsigned __int64)v2 + 1));
a1[4] = result;
return result;
}

original_code:
static void mmio_normalize(struct mmio *mo)
{
 int npages = 0;
 mo->iobase += mo->offset;
 mo->offset = mo->iobase & (getpagesize() - 1);
 mo->iobase = mo->iobase & ~(getpagesize() - 1);
 npages += (mo->range * sizeof(uint32_t)) / getpagesize();
 npages += 1;
 mo->iosize = npages * getpagesize();
}

canonical_original_code:
static void mmio_normalize(struct mmio *mo)
{
 int npages = 0;
 mo->iobase += mo->offset;
 mo->offset = mo->iobase & (getpagesize() - 1);
 mo->iobase = mo->iobase & ~(getpagesize() - 1);
 npages += (mo->range * sizeof(unsigned int)) / getpagesize();
 npages += 1;
 mo->iosize = npages * getpagesize();
}

variable_types: struct mmio { unsigned long iobase; unsigned long offset; unsigned long range; void *iomem; unsigned long iosize; int kmem; } *

variable_types: npages int


decompiled_code:
int __fastcall mmio_init(__int64 a1)
{
int v2; // eax
const char *v3; // rdi
int v4; // ebp
void *v5; // rax

v2 = *(_DWORD *)(a1 + 40);
v3 = "/dev/mem";
if ( v2 )
v3 = "/dev/kmem";
v4 = open(v3, 2);
if ( v4 < 0 )
perror("open() failed");
v5 = mmap(0LL, *(_QWORD *)(a1 + 32), 3, 1, v4, *(_QWORD *)a1);
*(_QWORD *)(a1 + 24) = v5;
if ( v5 == (void *)-1LL )
perror("can't map @ %0lX");
return close(v4);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int v2; // eax
const char *v3; // rdi
int v4; // ebp
void *v5; // rax

v2 = *(_DWORD *)(a1 + 40);
v3 = "/dev/mem";
if ( v2 )
v3 = "/dev/kmem";
v4 = open(v3, 2);
if ( v4 < 0 )
perror("open() failed");
v5 = mmap(0LL, *(_QWORD *)(a1 + 32), 3, 1, v4, *(_QWORD *)a1);
*(_QWORD *)(a1 + 24) = v5;
if ( v5 == (void *)-1LL )
perror("can't map @ %0lX");
return close(v4);
}

original_code:
static void mmio_init(struct mmio *mo)
{
 char *device;
 int iofd;
 if (!mo->kmem)
  device = "/dev/mem";
 else
  device = "/dev/kmem";
 iofd = open(device, 02);
 if (iofd < 0)
  perror("open() failed");
 mo->iomem = mmap(((void *)0), mo->iosize,
    0x1|0x2,
    0x01,
    iofd, mo->iobase);
 if (mo->iomem == ((void *) -1))
  perror("can't map @ %0lX", mo->iobase);
 close(iofd);
}

variable_types:
device
char *

variable_types: iofd int

user_defined_types: struct mmio { unsigned long iobase; unsigned long offset; unsigned long range; void *iomem; unsigned long iosize; int kmem; }


decompiled_code:
__int64 __fastcall mmio_readl(__int64 a1, unsigned int a2)
{
return readl((unsigned int *)(*(_QWORD *)(a1 + 24) + *(_QWORD *)(a1 + 8) + a2));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
return func0((unsigned int *)(*(_QWORD *)(a1 + 24) + *(_QWORD *)(a1 + 8) + a2));
}

original_code:
uint32_t mmio_readl(const struct mmio *io, unsigned int offset)
{
 void *addr;
 addr = io->iomem + io->offset + offset;
 return readl(addr);
}

canonical_original_code:
unsigned int mmio_readl(struct mmio *io, unsigned int offset)
{
 void *addr;
 addr = io->iomem + io->offset + offset;
 return readl(addr);
}

variable_types:
offset
unsigned int

variable_types:
addr
void *


original_code:
int mmio_map(struct mmio *io, unsigned long base, size_t length)
{
 memset(io, 0, sizeof(*io));
 io->iobase = base;
 io->offset = 0;
 io->range = length;
 mmio_normalize(io);
 mmio_init(io);
 return 0;
}

canonical_original_code:
int mmio_map(struct mmio *io, unsigned long base, unsigned long length)
{
 memset(io, 0, sizeof(*io));
 io->iobase = base;
 io->offset = 0;
 io->range = length;
 mmio_normalize(io);
 mmio_init(io);
 return 0;
}

variable_types:
base
unsigned long

variable_types:
length
unsigned long


decompiled_code:
void __fastcall mmio_unmap(__int64 a1)
{
if ( munmap(*(void **)(a1 + 24), *(_QWORD *)(a1 + 32)) )
perror("can't unmap @ %lX");
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
*(_OWORD *)(a1 + 32) = 0LL;
}

original_code:
void mmio_unmap(struct mmio *io)
{
 if (munmap(io->iomem, io->iosize))
  perror("can't unmap @ %lX", io->iobase);
 memset(io, 0, sizeof(*io));
}


decompiled_code:
void __fastcall ws2812_fini(void *ptr)
{
if ( ptr )
{
*((_QWORD *)ptr + 1) = 3735928559LL;
*((_QWORD *)ptr + 6) = 0x1C20000000000LL;
*((_QWORD *)ptr + 2) = 0LL;
ioctl(*(_DWORD *)ptr, 0x5432uLL, (char *)ptr + 24);
close(*(_DWORD *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
*((_QWORD *)ptr + 1) = 3735928559LL;
*((_QWORD *)ptr + 6) = 0x1C20000000000LL;
*((_QWORD *)ptr + 2) = 0LL;
ioctl(*(_DWORD *)ptr, 0x5432uLL, (char *)ptr + 24);
close(*(_DWORD *)ptr);
free(ptr);
}
}

original_code:
void ws2812_fini(struct ws2812 *w)
{
  if (!w) return;
  if (!w->buf) free((char *)w->buf);
  w->buf = (char *)0xdeadbeef;
  w->buflen = 0;
  w->n_leds = 0;
  w->s.custom_divisor = 0;
  w->s.baud_base = 115200;
  ioctl(w->fd, 0x5432, &w->s);
  close(w->fd);
  w->fd = -1;
  free((char *)w);
}

variable_types: struct ws2812 { int fd; char *buf; int buflen; int n_leds; struct serial_struct { int type; int line; unsigned int port; int irq; int flags; int xmit_fifo_size; int custom_divisor; int baud_base; unsigned short close_delay; char io_type; char reserved_char[1]; int hub6; unsigned short closing_wait; unsigned short closing_wait2; unsigned char *iomem_base; unsigned short iomem_reg_shift; unsigned int port_high; unsigned long iomap_base; } s; } *

user_defined_types: struct ws2812 { int fd; char *buf; int buflen; int n_leds; struct serial_struct s; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rdi
unsigned int v5; // ebx
void *v6; // rbp
__int64 v7; // rdx

v4 = "/dev/ttyS1";
if ( argc > 1 )
v4 = (char *)argv[1];
v5 = 0;
v6 = (void *)ws2812_init(v4);
do
{
ws2812_send(v6, 0LL, &p1_1, 18LL);
v7 = v5++;
fprintf(stderr, "i=%d\n", v7);
usleep(0x186A0u);
ws2812_send(v6, 0LL, &p2_0, 18LL);
usleep(0x186A0u);
}
while ( v5 != 20 );
ws2812_fini(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rdi
unsigned int v5; // ebx
void *v6; // rbp
__int64 v7; // rdx

v4 = "/dev/ttyS1";
if ( argc > 1 )
v4 = (char *)argv[1];
v5 = 0;
v6 = (void *)ws2812_init(v4);
do
{
func8(v6, 0LL, &p1_1, 18LL);
v7 = v5++;
fprintf(stderr, "i=%d\n", v7);
usleep(0x186A0u);
func8(v6, 0LL, &p2_0, 18LL);
usleep(0x186A0u);
}
while ( v5 != 20 );
func7(v6);
return 0;
}

variable_types: ac int

variable_types:
av
char **

variable_types:
dev
char *

variable_types: i int

user_defined_types: struct serial_struct { int type; int line; unsigned int port; int irq; int flags; int xmit_fifo_size; int custom_divisor; int baud_base; unsigned short close_delay; char io_type; char reserved_char[1]; int hub6; unsigned short closing_wait; unsigned short closing_wait2; unsigned char *iomem_base; unsigned short iomem_reg_shift; unsigned int port_high; unsigned long iomap_base; }


decompiled_code:
void main_terminate()
{
thread_terminate = 1;
}

canonical_decompiled_code:
void func0()
{
thread_terminate = 1;
}

original_code:
void main_terminate(){
    thread_terminate = 1;
}


decompiled_code:
__int64 __fastcall termination_handler(unsigned int a1)
{
fprintf(stderr, "DEBUG %s:%d: termination_handler() Caught signal %d\n\n", "main.c", 35LL, a1);
main_terminate();
return netcheck_terminate();
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
fprintf(stderr, "DEBUG %s:%d: termination_handler() Caught signal %d\n\n", "main.c", 35LL, a1);
func0();
return netcheck_terminate();
}

original_code:
void termination_handler (int signum){
    fprintf(stderr, "DEBUG %s:%d: " "termination_handler() Caught signal %d\n" "\n", "main.c", 35, signum);
    main_terminate();
    netcheck_terminate();
}

canonical_original_code:
void termination_handler(int signum){
    fprintf(stderr, "DEBUG %s:%d: " "termination_handler() Caught signal %d\n" "\n", "main.c", 35, signum);
    main_terminate();
    netcheck_terminate();
}

variable_types: signum int


decompiled_code:
int __fastcall join_threads(pthread_t *a1)
{
int result; // eax

fprintf(stderr, "DEBUG %s:%d: join_threads()\n\n", "main.c", 45LL);
result = pthread_join(*a1, 0LL);
if ( result )
result = puts("main: Error joining th1");
return result;
}

canonical_decompiled_code:
int __fastcall func2(pthread_t *a1)
{
int result; // eax

fprintf(stderr, "DEBUG %s:%d: join_threads()\n\n", "main.c", 45LL);
result = pthread_join(*a1, 0LL);
if ( result )
result = puts("main: Error joining th1");
return result;
}

original_code:
void join_threads(pthread_t *th1){
    fprintf(stderr, "DEBUG %s:%d: " "join_threads()\n" "\n", "main.c", 45);
    if(pthread_join(*th1, ((void *)0))){printf("main: Error joining th1\n");}
}

canonical_original_code:
void join_threads(unsigned long *th1){
    fprintf(stderr, "DEBUG %s:%d: " "join_threads()\n" "\n", "main.c", 45);
    if(pthread_join(*th1, ((void *)0))){printf("main: Error joining th1\n");}
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread; // [rsp+8h] [rbp-B0h] BYREF
struct sigaction v5; // [rsp+10h] [rbp-A8h] BYREF

v5.sa_handler = (__sighandler_t)termination_handler;
sigemptyset(&v5.sa_mask);
v5.sa_flags = 0x10000000;
if ( sigaction(2, &v5, 0LL) == -1 )
printf("ERROR: SIGINT ctrl+C not set!");
if ( sigaction(20, &v5, 0LL) == -1 )
printf("ERROR: SIGTSTP ctrl+Z not set!");
if ( thread_terminate )
{
LABEL_12:
join_threads(&newthread);
puts("Main program done.");
exit(0);
}
while ( (unsigned int)netcheck_get_thread_status()
|| !pthread_create(&newthread, 0LL, (void *(*)(void *))&netcheck_thread, 0LL) )
{
sleep(1u);
if ( (unsigned int)netcheck_get_network_status() == 2 )
{
puts("online");
if ( thread_terminate )
goto LABEL_12;
}
else
{
puts("offline");
if ( thread_terminate )
goto LABEL_12;
}
}
puts("PTHREAD: Error starting netcheck");
return 2;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread; // [rsp+8h] [rbp-B0h] BYREF
struct sigaction v5; // [rsp+10h] [rbp-A8h] BYREF

v5.sa_handler = (__sighandler_t)termination_handler;
sigemptyset(&v5.sa_mask);
v5.sa_flags = 0x10000000;
if ( sigaction(2, &v5, 0LL) == -1 )
printf("ERROR: SIGINT ctrl+C not set!");
if ( sigaction(20, &v5, 0LL) == -1 )
printf("ERROR: SIGTSTP ctrl+Z not set!");
if ( thread_terminate )
{
LABEL_12:
func2(&newthread);
puts("Main program done.");
exit(0);
}
while ( (unsigned int)netcheck_get_thread_status()
|| !pthread_create(&newthread, 0LL, (void *(*)(void *))&netcheck_thread, 0LL) )
{
sleep(1u);
if ( (unsigned int)netcheck_get_network_status() == 2 )
{
puts("online");
if ( thread_terminate )
goto LABEL_12;
}
else
{
puts("offline");
if ( thread_terminate )
goto LABEL_12;
}
}
puts("PTHREAD: Error starting netcheck");
return 2;
}

original_code:
int main(int argc, char *argv[]){
    int online = 0;
    int netcheck_running = 0;
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = termination_handler;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0x10000000;
    if (sigaction(2, &sigIntHandler, ((void *)0)) == -1){
        printf("ERROR: SIGINT ctrl+C not set!");
    }
    if (sigaction(20, &sigIntHandler, ((void *)0)) == -1){
        printf("ERROR: SIGTSTP ctrl+Z not set!");
    }
    pthread_t th1;
 while(!thread_terminate){
        if(!netcheck_get_thread_status()){
            if(pthread_create(&th1, ((void *)0), netcheck_thread, ((void *)0))){
                printf("PTHREAD: Error starting netcheck\n");
                return 2;
            }
        }
        sleep(1);
        online = netcheck_get_network_status();
        if (online == 2){
            printf("online\n");
        } else {
            printf("offline\n");
        }
    }
    join_threads(&th1);
    printf("Main program done.\n");
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]){
    int online = 0;
    int netcheck_running = 0;
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = termination_handler;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0x10000000;
    if (sigaction(2, &sigIntHandler, ((void *)0)) == -1){
        printf("ERROR: SIGINT ctrl+C not set!");
    }
    if (sigaction(20, &sigIntHandler, ((void *)0)) == -1){
        printf("ERROR: SIGTSTP ctrl+Z not set!");
    }
    unsigned long th1;
 while(!thread_terminate){
        if(!netcheck_get_thread_status()){
            if(pthread_create(&th1, ((void *)0), netcheck_thread, ((void *)0))){
                printf("PTHREAD: Error starting netcheck\n");
                return 2;
            }
        }
        sleep(1);
        online = netcheck_get_network_status();
        if (online == 2){
            printf("online\n");
        } else {
            printf("offline\n");
        }
    }
    join_threads(&th1);
    printf("Main program done.\n");
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: online int

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

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

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


decompiled_code:
size_t __fastcall dummy_write(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v4; // r12
__int64 v6; // r13
char *v7; // rax
size_t result; // rax

v4 = a3 * a2;
v6 = a3 * a2 + *(_QWORD *)(a4 + 8);
v7 = (char *)realloc(*(void **)a4, v6 + 1);
*(_QWORD *)a4 = v7;
if ( !v7 )
{
fwrite("realloc() failed\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
memcpy(&v7[*(_QWORD *)(a4 + 8)], src, v4);
*(_BYTE *)(*(_QWORD *)a4 + v6) = 0;
result = v4;
*(_QWORD *)(a4 + 8) = v6;
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v4; // r12
__int64 v6; // r13
char *v7; // rax
size_t result; // rax

v4 = a3 * a2;
v6 = a3 * a2 + *(_QWORD *)(a4 + 8);
v7 = (char *)realloc(*(void **)a4, v6 + 1);
*(_QWORD *)a4 = v7;
if ( !v7 )
{
fwrite("realloc() failed\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
memcpy(&v7[*(_QWORD *)(a4 + 8)], src, v4);
*(_BYTE *)(*(_QWORD *)a4 + v6) = 0;
result = v4;
*(_QWORD *)(a4 + 8) = v6;
return result;
}

original_code:
size_t dummy_write(void *ptr, size_t size, size_t nmemb, struct string *s)
{
    size_t new_len = s->len + size*nmemb;
    s->ptr = realloc(s->ptr, new_len+1);
    if (s->ptr == ((void *)0)) {
        fprintf(stderr, "realloc() failed\n");
        exit(1);
    }
    memcpy(s->ptr+s->len, ptr, size*nmemb);
    s->ptr[new_len] = '\0';
    s->len = new_len;
    return size*nmemb;
}

canonical_original_code:
unsigned long dummy_write(void *ptr, unsigned long size, unsigned long nmemb, struct string *s)
{
    unsigned long new_len = s->len + size*nmemb;
    s->ptr = realloc(s->ptr, new_len+1);
    if (s->ptr == ((void *)0)) {
        fprintf(stderr, "realloc() failed\n");
        exit(1);
    }
    memcpy(s->ptr+s->len, ptr, size*nmemb);
    s->ptr[new_len] = '\0';
    s->len = new_len;
    return size*nmemb;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types: struct string { char *ptr; unsigned long len; } *

return_type: unsigned long


decompiled_code:
__int64 netcheck_get_network_status()
{
return (unsigned int)network_status;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)network_status;
}

original_code:
int netcheck_get_network_status(){
    return network_status;
}


decompiled_code:
__int64 netcheck_get_thread_status()
{
return (unsigned int)thread_status;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)thread_status;
}

original_code:
int netcheck_get_thread_status(){
    return thread_status;
}


decompiled_code:
void netcheck_terminate()
{
thread_terminate = 1;
}

canonical_decompiled_code:
void func5()
{
thread_terminate = 1;
}

original_code:
void netcheck_terminate(){
    thread_terminate = 1;
}


terminate

decompiled_code:
void __noreturn terminate()
{
gpioTerminate();
fwrite("SIGHUP/SIGTERM received\n", 1uLL, 0x18uLL, errFifo);
fflush(0LL);
fclose(errFifo);
unlink("/dev/pigerr");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
gpioTerminate();
fwrite("SIGHUP/SIGTERM received\n", 1uLL, 0x18uLL, errFifo);
fflush(0LL);
fclose(errFifo);
unlink("/dev/pigerr");
exit(0);
}

original_code:
void terminate(int signum)
{
   gpioTerminate();
   fprintf(errFifo, "SIGHUP/SIGTERM received\n");
   fflush(((void *)0));
   fclose(errFifo);
   unlink("/dev/pigerr");
   exit(0);
}


checkAddr

decompiled_code:
__int64 __fastcall checkAddr(char *name)
{
char *v1; // rsi
unsigned int v2; // er12
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v1 = getenv("PIGPIO_PORT");
*(_OWORD *)&req.ai_socktype = 0LL;
if ( !v1 )
v1 = "8888";
*(_OWORD *)&req.ai_addr = 0LL;
v2 = 0;
req.ai_socktype = 1;
req.ai_next = 0LL;
*(_QWORD *)&req.ai_flags = 0x200000002LL;
if ( !getaddrinfo(name, v1, &req, &pai) )
{
v2 = *(_DWORD *)&pai->ai_addr->sa_data[2];
freeaddrinfo(pai);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name)
{
char *v1; // rsi
unsigned int v2; // er12
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v1 = getenv("PIGPIO_PORT");
*(_OWORD *)&req.ai_socktype = 0LL;
if ( !v1 )
v1 = "8888";
*(_OWORD *)&req.ai_addr = 0LL;
v2 = 0;
req.ai_socktype = 1;
req.ai_next = 0LL;
*(_QWORD *)&req.ai_flags = 0x200000002LL;
if ( !getaddrinfo(name, v1, &req, &pai) )
{
v2 = *(_DWORD *)&pai->ai_addr->sa_data[2];
freeaddrinfo(pai);
}
return v2;
}

original_code:
static uint32_t checkAddr(char *addrStr)
{
   int err;
   struct addrinfo hints, *res;
   struct sockaddr_in *sin;
   const char *portStr;
   uint32_t addr;
   portStr = getenv("PIGPIO_PORT");
   if (!portStr) portStr = "8888";
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = 2;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags |= 0x0002;
   err = getaddrinfo(addrStr, portStr, &hints, &res);
   if (err) return 0;
   sin = (struct sockaddr_in *)res->ai_addr;
   addr = sin->sin_addr.s_addr;
   freeaddrinfo(res);
   return addr;
}

canonical_original_code:
static unsigned int checkAddr(char *addrStr)
{
   int err;
   struct addrinfo hints; struct addrinfo *res;
   struct sockaddr_in *sin;
   char *portStr;
   unsigned int addr;
   portStr = getenv("PIGPIO_PORT");
   if (!portStr) portStr = "8888";
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = 2;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags |= 0x0002;
   err = getaddrinfo(addrStr, portStr, &hints, &res);
   if (err) return 0;
   sin = (struct sockaddr_in *)res->ai_addr;
   addr = sin->sin_addr.s_addr;
   freeaddrinfo(res);
   return addr;
}

variable_types:
addrStr
char *

variable_types: err int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

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

variable_types:
portStr
char *

variable_types:
addr
unsigned int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

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


fatal

decompiled_code:
void __noreturn fatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-150h] BYREF
char s[128]; // [rsp+20h] [rbp-138h] BYREF

va_start(arg, format);
vsnprintf(s, 0x80uLL, format, arg);
fprintf(stderr, "%s\n", s);
fflush(stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-150h] BYREF
char s[128]; // [rsp+20h] [rbp-138h] BYREF

va_start(arg, format);
vsnprintf(s, 0x80uLL, format, arg);
fprintf(stderr, "%s\n", s);
fflush(stderr);
exit(1);
}

original_code:
void fatal(char *fmt, ...)
{
   char buf[128];
   va_list ap;
   __builtin_va_start(ap,fmt);
   vsnprintf(buf, sizeof(buf), fmt, ap);
   __builtin_va_end(ap);
   fprintf(stderr, "%s\n", buf);
   fflush(stderr);
   exit(1);
}

canonical_original_code:
void fatal(char *fmt, ...)
{
   char buf[128];
   __builtin_va_list ap;
   __builtin_va_start(ap,fmt);
   vsnprintf(buf, sizeof(buf), fmt, ap);
   __builtin_va_end(ap);
   fprintf(stderr, "%s\n", buf);
   fflush(stderr);
   exit(1);
}

variable_types:
fmt
char *

variable_types:
buf
char [128]


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"\n"
"pigpio V%d\n"
"Usage: sudo pigpiod [OPTION] ...\n"
" -a value, DMA mode, 0=AUTO, 1=PMAP, 2=MBOX, default AUTO\n"
" -b value, sample buffer size in ms, default 120\n"
" -c value, library internal settings, default 0\n"
" -d value, primary DMA channel, 0-14, default 14\n"
" -e value, secondary DMA channel, 0-14, default 6\n"
" -f, disable fifo interface, default enabled\n"
" -g, run in foreground (do not fork), default disabled\n"
" -k, disable socket interface, default enabled\n"
" -l, localhost socket only default local+remote\n"
" -m, disable alerts default enabled\n"
" -n IP addr, allow address, name or dotted, default allow all\n"
" -p value, socket port, 1024-32000, default 8888\n"
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n"
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n"
" -v, -V, display pigpio version and exit\n"
" -x mask, GPIO which may be updated, default board GPIO\n"
"EXAMPLE\n"
"sudo pigpiod -s 2 -b 200 -f\n"
" Set a sample rate of 2 microseconds with a 200 millisecond\n"
" buffer. Disable the fifo interface.\n"
"\n",
79LL);
}

canonical_decompiled_code:
int func4()
{
return fprintf(
stderr,
"\n"
"pigpio V%d\n"
"Usage: sudo pigpiod [OPTION] ...\n"
" -a value, DMA mode, 0=AUTO, 1=PMAP, 2=MBOX, default AUTO\n"
" -b value, sample buffer size in ms, default 120\n"
" -c value, library internal settings, default 0\n"
" -d value, primary DMA channel, 0-14, default 14\n"
" -e value, secondary DMA channel, 0-14, default 6\n"
" -f, disable fifo interface, default enabled\n"
" -g, run in foreground (do not fork), default disabled\n"
" -k, disable socket interface, default enabled\n"
" -l, localhost socket only default local+remote\n"
" -m, disable alerts default enabled\n"
" -n IP addr, allow address, name or dotted, default allow all\n"
" -p value, socket port, 1024-32000, default 8888\n"
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n"
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n"
" -v, -V, display pigpio version and exit\n"
" -x mask, GPIO which may be updated, default board GPIO\n"
"EXAMPLE\n"
"sudo pigpiod -s 2 -b 200 -f\n"
" Set a sample rate of 2 microseconds with a 200 millisecond\n"
" buffer. Disable the fifo interface.\n"
"\n",
79LL);
}

original_code:
void usage()
{
   fprintf(stderr, "\n" "pigpio V%d\n" "Usage: sudo pigpiod [OPTION] ...\n" "   -a value,   DMA mode, 0=AUTO, 1=PMAP, 2=MBOX,  default AUTO\n" "   -b value,   sample buffer size in ms,          default 120\n" "   -c value,   library internal settings,         default 0\n" "   -d value,   primary DMA channel, 0-14,         default 14\n" "   -e value,   secondary DMA channel, 0-14,       default 6\n" "   -f,         disable fifo interface,            default enabled\n" "   -g,         run in foreground (do not fork),   default disabled\n" "   -k,         disable socket interface,          default enabled\n" "   -l,         localhost socket only              default local+remote\n" "   -m,         disable alerts                     default enabled\n" "   -n IP addr, allow address, name or dotted,     default allow all\n" "   -p value,   socket port, 1024-32000,           default 8888\n" "   -s value,   sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" "   -t value,   clock peripheral, 0=PWM 1=PCM,     default PCM\n" "   -v, -V,     display pigpio version and exit\n" "   -x mask,    GPIO which may be updated,         default board GPIO\n" "EXAMPLE\n" "sudo pigpiod -s 2 -b 200 -f\n" "  Set a sample rate of 2 microseconds with a 200 millisecond\n" "  buffer.  Disable the fifo interface.\n" "\n", 79);
}


getNum

decompiled_code:
__int64 __fastcall getNum(const char *a1, _DWORD *a2)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

*a2 = 0;
result = strtoll(a1, &endptr, 0);
if ( *endptr )
{
*a2 = 1;
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, _DWORD *a2)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

*a2 = 0;
result = strtoll(a1, &endptr, 0);
if ( *endptr )
{
*a2 = 1;
result = -1LL;
}
return result;
}

original_code:
static uint64_t getNum(char *str, int *err)
{
   uint64_t val;
   char *endptr;
   *err = 0;
   val = strtoll(str, &endptr, 0);
   if (*endptr) {*err = 1; val = -1;}
   return val;
}

canonical_original_code:
static unsigned long getNum(char *str, int *err)
{
   unsigned long val;
   char *endptr;
   *err = 0;
   val = strtoll(str, &endptr, 0);
   if (*endptr) {*err = 1; val = -1;}
   return val;
}

variable_types:
str
char *

variable_types:
err
int *

variable_types:
val
unsigned long

variable_types:
endptr
char *


initOpts

decompiled_code:
int __fastcall initOpts(int argc, char **argv)
{
int result; // eax
__int64 v3; // rax
unsigned int v4; // eax
unsigned int v5; // ecx
unsigned int v6; // eax
int v7; // edx
int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
int v14[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 1 )
{
result = getopt(argc, argv, "a:b:c:d:e:fgkln:mp:s:t:x:vV");
if ( result == -1 )
break;
switch ( result )
{
case 'V':
case 'v':
printf("%d\n", 79LL);
exit(0);
case 'a':
v13 = getNum(optarg, v14);
if ( v13 > 2 )
fatal("invalid -a option (%d)", v13);
memAllocMode = v13;
break;
case 'b':
v12 = getNum(optarg, v14);
if ( v12 - 100 > 0x26AC )
fatal("invalid -b option (%d)", v12);
bufferSizeMilliseconds = v12;
break;
case 'c':
v11 = getNum(optarg, v14);
if ( v11 > 0x7FF )
fatal("invalid -c option (%x)", v11);
cfgInternals = v11;
break;
case 'd':
v10 = getNum(optarg, v14);
if ( v10 > 0xF )
fatal("invalid -d option (%d)", v10);
DMAprimaryChannel = v10;
break;
case 'e':
v9 = getNum(optarg, v14);
if ( v9 > 0xF )
fatal("invalid -e option (%d)", v9);
DMAsecondaryChannel = v9;
break;
case 'f':
ifFlags |= 1u;
break;
case 'g':
foreground = 1;
break;
case 'k':
ifFlags |= 2u;
break;
case 'l':
ifFlags |= 4u;
break;
case 'm':
ifFlags |= 8u;
break;
case 'n':
v7 = checkAddr(optarg);
if ( !v7 || (v8 = numSockNetAddr, numSockNetAddr > 255) )
fatal("invalid -n option (%s)", optarg);
sockNetAddr[numSockNetAddr] = v7;
numSockNetAddr = v8 + 1;
break;
case 'p':
v6 = getNum(optarg, v14);
if ( v6 - 1024 > 0x7900 )
fatal("invalid -p option (%d)", v6);
socketPort = v6;
break;
case 's':
v5 = getNum(optarg, v14);
if ( v5 > 0xA || ((1LL << v5) & 0x536) == 0 )
fatal("invalid -s option (%d)", v5);
clockMicros = v5;
break;
case 't':
v4 = getNum(optarg, v14);
if ( v4 > 1 )
fatal("invalid -t option (%d)", v4);
clockPeripheral = v4;
break;
case 'x':
v3 = getNum(optarg, v14);
if ( v14[0] )
fatal("invalid -x option (%s)", optarg);
updateMask = v3;
updateMaskSet = 1;
break;
default:
usage();
exit(1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int argc, char **argv)
{
int result; // eax
__int64 v3; // rax
unsigned int v4; // eax
unsigned int v5; // ecx
unsigned int v6; // eax
int v7; // edx
int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
int v14[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 1 )
{
result = getopt(argc, argv, "a:b:c:d:e:fgkln:mp:s:t:x:vV");
if ( result == -1 )
break;
switch ( result )
{
case 'V':
case 'v':
printf("%d\n", 79LL);
exit(0);
case 'a':
v13 = func2(optarg, v14);
if ( v13 > 2 )
func3("invalid -a option (%d)", v13);
memAllocMode = v13;
break;
case 'b':
v12 = func2(optarg, v14);
if ( v12 - 100 > 0x26AC )
func3("invalid -b option (%d)", v12);
bufferSizeMilliseconds = v12;
break;
case 'c':
v11 = func2(optarg, v14);
if ( v11 > 0x7FF )
func3("invalid -c option (%x)", v11);
cfgInternals = v11;
break;
case 'd':
v10 = func2(optarg, v14);
if ( v10 > 0xF )
func3("invalid -d option (%d)", v10);
DMAprimaryChannel = v10;
break;
case 'e':
v9 = func2(optarg, v14);
if ( v9 > 0xF )
func3("invalid -e option (%d)", v9);
DMAsecondaryChannel = v9;
break;
case 'f':
ifFlags |= 1u;
break;
case 'g':
foreground = 1;
break;
case 'k':
ifFlags |= 2u;
break;
case 'l':
ifFlags |= 4u;
break;
case 'm':
ifFlags |= 8u;
break;
case 'n':
v7 = func1(optarg);
if ( !v7 || (v8 = numSockNetAddr, numSockNetAddr > 255) )
func3("invalid -n option (%s)", optarg);
sockNetAddr[numSockNetAddr] = v7;
numSockNetAddr = v8 + 1;
break;
case 'p':
v6 = func2(optarg, v14);
if ( v6 - 1024 > 0x7900 )
func3("invalid -p option (%d)", v6);
socketPort = v6;
break;
case 's':
v5 = func2(optarg, v14);
if ( v5 > 0xA || ((1LL << v5) & 0x536) == 0 )
func3("invalid -s option (%d)", v5);
clockMicros = v5;
break;
case 't':
v4 = func2(optarg, v14);
if ( v4 > 1 )
func3("invalid -t option (%d)", v4);
clockPeripheral = v4;
break;
case 'x':
v3 = func2(optarg, v14);
if ( v14[0] )
func3("invalid -x option (%s)", optarg);
updateMask = v3;
updateMaskSet = 1;
break;
default:
func4();
exit(1);
}
}
return result;
}

original_code:
static void initOpts(int argc, char *argv[])
{
   int opt, err, i;
   uint32_t addr;
   int64_t mask;
   while ((opt = getopt(argc, argv, "a:b:c:d:e:fgkln:mp:s:t:x:vV")) != -1)
   {
      switch (opt)
      {
         case 'a':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i <= 2))
               memAllocMode = i;
            else fatal("invalid -a option (%d)", i);
            break;
         case 'b':
            i = getNum(optarg, &err);
            if ((i >= 100) && (i <= 10000))
               bufferSizeMilliseconds = i;
            else fatal("invalid -b option (%d)", i);
            break;
         case 'c':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i < (1<<11)))
               cfgInternals = i;
            else fatal("invalid -c option (%x)", i);
            break;
         case 'd':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i <= 15))
               DMAprimaryChannel = i;
            else fatal("invalid -d option (%d)", i);
            break;
         case 'e':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i <= 15))
               DMAsecondaryChannel = i;
            else fatal("invalid -e option (%d)", i);
            break;
         case 'f':
            ifFlags |= 1;
            break;
         case 'g':
            foreground = 1;
            break;
         case 'k':
            ifFlags |= 2;
            break;
         case 'l':
            ifFlags |= 4;
            break;
         case 'm':
            ifFlags |= 8;
            break;
         case 'n':
            addr = checkAddr(optarg);
            if (addr && (numSockNetAddr<256))
               sockNetAddr[numSockNetAddr++] = addr;
            else fatal("invalid -n option (%s)", optarg);
            break;
         case 'p':
            i = getNum(optarg, &err);
            if ((i >= 1024) && (i <= 32000))
               socketPort = i;
            else fatal("invalid -p option (%d)", i);
            break;
         case 's':
            i = getNum(optarg, &err);
            switch(i)
            {
               case 1:
               case 2:
               case 4:
               case 5:
               case 8:
               case 10:
                  clockMicros = i;
                  break;
               default:
                  fatal("invalid -s option (%d)", i);
                  break;
            }
            break;
         case 't':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i <= 1))
               clockPeripheral = i;
            else fatal("invalid -t option (%d)", i);
            break;
         case 'v':
         case 'V':
            printf("%d\n", 79);
            exit(0);
            break;
         case 'x':
            mask = getNum(optarg, &err);
            if (!err)
            {
               updateMask = mask;
               updateMaskSet = 1;
            }
            else fatal("invalid -x option (%s)", optarg);
            break;
        default:
           usage();
           exit(1);
        }
    }
}

canonical_original_code:
static void initOpts(int argc, char *argv[])
{
   int opt; int err; int i;
   unsigned int addr;
   long mask;
   while ((opt = getopt(argc, argv, "a:b:c:d:e:fgkln:mp:s:t:x:vV")) != -1)
   {
      switch (opt)
      {
         case 'a':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i <= 2))
               memAllocMode = i;
            else fatal("invalid -a option (%d)", i);
            break;
         case 'b':
            i = getNum(optarg, &err);
            if ((i >= 100) && (i <= 10000))
               bufferSizeMilliseconds = i;
            else fatal("invalid -b option (%d)", i);
            break;
         case 'c':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i < (1<<11)))
               cfgInternals = i;
            else fatal("invalid -c option (%x)", i);
            break;
         case 'd':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i <= 15))
               DMAprimaryChannel = i;
            else fatal("invalid -d option (%d)", i);
            break;
         case 'e':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i <= 15))
               DMAsecondaryChannel = i;
            else fatal("invalid -e option (%d)", i);
            break;
         case 'f':
            ifFlags |= 1;
            break;
         case 'g':
            foreground = 1;
            break;
         case 'k':
            ifFlags |= 2;
            break;
         case 'l':
            ifFlags |= 4;
            break;
         case 'm':
            ifFlags |= 8;
            break;
         case 'n':
            addr = checkAddr(optarg);
            if (addr && (numSockNetAddr<256))
               sockNetAddr[numSockNetAddr++] = addr;
            else fatal("invalid -n option (%s)", optarg);
            break;
         case 'p':
            i = getNum(optarg, &err);
            if ((i >= 1024) && (i <= 32000))
               socketPort = i;
            else fatal("invalid -p option (%d)", i);
            break;
         case 's':
            i = getNum(optarg, &err);
            switch(i)
            {
               case 1:
               case 2:
               case 4:
               case 5:
               case 8:
               case 10:
                  clockMicros = i;
                  break;
               default:
                  fatal("invalid -s option (%d)", i);
                  break;
            }
            break;
         case 't':
            i = getNum(optarg, &err);
            if ((i >= 0) && (i <= 1))
               clockPeripheral = i;
            else fatal("invalid -t option (%d)", i);
            break;
         case 'v':
         case 'V':
            printf("%d\n", 79);
            exit(0);
            break;
         case 'x':
            mask = getNum(optarg, &err);
            if (!err)
            {
               updateMask = mask;
               updateMaskSet = 1;
            }
            else fatal("invalid -x option (%s)", optarg);
            break;
        default:
           usage();
           exit(1);
        }
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: i int

variable_types: mask long