insertREAction

decompiled_code:
char *__fastcall insertREAction(char *src)
{
size_t v1; // rax
__int64 v2; // rbp
char *v3; // rax

v1 = strlen(src);
v2 = rep;
v3 = (char *)malloc(v1 + 1);
*(_QWORD *)(v2 + 8) = v3;
return strcpy(v3, src);
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
size_t v1; // rax
__int64 v2; // rbp
char *v3; // rax

v1 = strlen(src);
v2 = rep;
v3 = (char *)malloc(v1 + 1);
*(_QWORD *)(v2 + 8) = v3;
return strcpy(v3, src);
}

original_code:
void insertREAction(char *action){
 rep->action = malloc(strlen(action)+1);
 strcpy(rep->action, action);
}


insertFuncEntry

repo: ZeyuMi/MiLex

decompiled_code:
char *__fastcall insertFuncEntry(char *src)
{
char **v1; // rax
char **v2; // rbx
size_t v3; // rax
char *v4; // rax
char *result; // rax

v1 = (char **)malloc(0x10uLL);
v2 = v1;
if ( additionalfuncs )
{
*(_QWORD *)(funcp + 8) = v1;
funcp = (__int64)v1;
}
else
{
funcp = (__int64)v1;
additionalfuncs = v1;
}
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
*v2 = v4;
result = strcpy(v4, src);
v2[1] = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *src)
{
char **v1; // rax
char **v2; // rbx
size_t v3; // rax
char *v4; // rax
char *result; // rax

v1 = (char **)malloc(0x10uLL);
v2 = v1;
if ( additionalfuncs )
{
*(_QWORD *)(funcp + 8) = v1;
funcp = (__int64)v1;
}
else
{
funcp = (__int64)v1;
additionalfuncs = v1;
}
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
*v2 = v4;
result = strcpy(v4, src);
v2[1] = 0LL;
return result;
}

original_code:
void insertFuncEntry(char *body){
 struct Funcentry *temp = malloc(sizeof(struct Funcentry));
 if(((void *)0) == additionalfuncs){
  additionalfuncs = funcp = temp;
 }else{
  funcp->next = temp;
  funcp = temp;
 }
 temp->body = malloc(strlen(body)+1);
 strcpy(temp->body, body);
 temp->next = ((void *)0);
}

variable_types:
body
char *

variable_types: struct Funcentry { char *body; struct Funcentry *next; } *

return_type: void


getch

decompiled_code:
int getch()
{
int v0; // eax

v0 = bufp;
if ( bufp <= 0 )
return getc(in);
--bufp;
return buf[v0];
}

canonical_decompiled_code:
int func5()
{
int v0; // eax

v0 = bufp;
if ( bufp <= 0 )
return getc(in);
--bufp;
return buf[v0];
}

original_code:
int getch(){
 return (bufp > 0) ? buf[bufp--] : getc(in);
}

return_type: int


readFuncSec

decompiled_code:
__int64 __fastcall readFuncSec(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
unsigned int v3; // ebp
int v4; // er13
const char *v5; // rdx
char v6; // bl
int v8; // eax
const char *v9; // rdx
char *v10; // rax
const char *v11; // rdx
const char *v12; // rdx

v2 = initializeCharBuffer();
v3 = 1;
v4 = 0;
while ( 1 )
{
v6 = getch();
if ( v6 == -1 )
break;
switch ( v3 )
{
case 1u:
if ( v6 == 47 )
{
v3 = 2;
}
else
{
v8 = isalpha(v6);
if ( v6 == 95 || v8 )
{
LODWORD(a2) = v6;
addCharElement(v2, (unsigned int)v6);
v3 = 6;
v4 = 0;
}
else if ( (unsigned __int8)(v6 - 9) > 1u && v6 != 32 )
{
error((int)"lexReader readFuncSec state0", a2, v9);
}
}
break;
case 2u:
if ( v6 == 42 )
{
v3 = 3;
}
else if ( v6 == 47 )
{
v3 = 5;
}
else
{
error((int)"lexReader readFuncSec state1", a2, v5);
}
break;
case 3u:
if ( v6 == 42 )
v3 = 4;
break;
case 4u:
if ( v6 != 42 )
v3 = 2 * (v6 != 47) + 1;
break;
case 5u:
if ( v6 == 10 )
v3 = 1;
break;
case 6u:
switch ( v6 )
{
case '"':
LODWORD(a2) = 34;
addCharElement(v2, 34LL);
v3 = 7;
break;
case '{':
++v4;
LODWORD(a2) = 123;
addCharElement(v2, 123LL);
break;
case '/':
LODWORD(a2) = 47;
addCharElement(v2, 47LL);
v3 = 8;
break;
case '}':
--v4;
LODWORD(a2) = 125;
addCharElement(v2, 125LL);
if ( !v4 )
{
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v10 = (char *)getCharBuffer(v2);
insertFuncEntry(v10);
rewindCharPointer(v2);
v3 = 1;
}
break;
default:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
break;
}
break;
case 7u:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 == 34 )
{
v3 = 6;
}
else if ( v6 == 10 )
{
error((int)"lexReader readFuncSec state6", a2, v11);
}
break;
case 8u:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 == 42 )
{
v3 = 9;
}
else if ( v6 == 47 )
{
v3 = 11;
}
else
{
error((int)"lexReader readFuncSec state7", a2, v12);
}
break;
case 9u:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 == 42 )
v3 = 10;
break;
case 0xAu:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 != 42 )
v3 = 3 * (v6 != 47) + 6;
break;
case 0xBu:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 == 10 )
v3 = 6;
break;
default:
error((int)"entering wrong state.", a2, v5);
break;
}
}
if ( v3 != 1 )
return (unsigned int)-1;
destroyCharBuffer(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
unsigned int v3; // ebp
int v4; // er13
const char *v5; // rdx
char v6; // bl
int v8; // eax
const char *v9; // rdx
char *v10; // rax
const char *v11; // rdx
const char *v12; // rdx

v2 = initializeCharBuffer();
v3 = 1;
v4 = 0;
while ( 1 )
{
v6 = func5();
if ( v6 == -1 )
break;
switch ( v3 )
{
case 1u:
if ( v6 == 47 )
{
v3 = 2;
}
else
{
v8 = isalpha(v6);
if ( v6 == 95 || v8 )
{
LODWORD(a2) = v6;
addCharElement(v2, (unsigned int)v6);
v3 = 6;
v4 = 0;
}
else if ( (unsigned __int8)(v6 - 9) > 1u && v6 != 32 )
{
error((int)"lexReader readFuncSec state0", a2, v9);
}
}
break;
case 2u:
if ( v6 == 42 )
{
v3 = 3;
}
else if ( v6 == 47 )
{
v3 = 5;
}
else
{
error((int)"lexReader readFuncSec state1", a2, v5);
}
break;
case 3u:
if ( v6 == 42 )
v3 = 4;
break;
case 4u:
if ( v6 != 42 )
v3 = 2 * (v6 != 47) + 1;
break;
case 5u:
if ( v6 == 10 )
v3 = 1;
break;
case 6u:
switch ( v6 )
{
case '"':
LODWORD(a2) = 34;
addCharElement(v2, 34LL);
v3 = 7;
break;
case '{':
++v4;
LODWORD(a2) = 123;
addCharElement(v2, 123LL);
break;
case '/':
LODWORD(a2) = 47;
addCharElement(v2, 47LL);
v3 = 8;
break;
case '}':
--v4;
LODWORD(a2) = 125;
addCharElement(v2, 125LL);
if ( !v4 )
{
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v10 = (char *)getCharBuffer(v2);
func4(v10);
rewindCharPointer(v2);
v3 = 1;
}
break;
default:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
break;
}
break;
case 7u:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 == 34 )
{
v3 = 6;
}
else if ( v6 == 10 )
{
error((int)"lexReader readFuncSec state6", a2, v11);
}
break;
case 8u:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 == 42 )
{
v3 = 9;
}
else if ( v6 == 47 )
{
v3 = 11;
}
else
{
error((int)"lexReader readFuncSec state7", a2, v12);
}
break;
case 9u:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 == 42 )
v3 = 10;
break;
case 0xAu:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 != 42 )
v3 = 3 * (v6 != 47) + 6;
break;
case 0xBu:
a2 = (unsigned int)v6;
addCharElement(v2, a2);
if ( v6 == 10 )
v3 = 6;
break;
default:
error((int)"entering wrong state.", a2, v5);
break;
}
}
if ( v3 != 1 )
return (unsigned int)-1;
destroyCharBuffer(v2);
return v3;
}

original_code:
int readFuncSec(){
 int leftBraceNum = 0;
 int bufferid = initializeCharBuffer();
 int state = STATE0;
 while(1){
  char c = getch();
  if(c == (-1)){
   if(state != STATE0)
    return -1;
   else{
    destroyCharBuffer(bufferid);
    return 1;
   }
  }
  switch(state){
   case STATE0:
    if('/' == c){
     state = STATE1;
    }else if(isalpha(c) || '_' == c){
     state = STATE5;
     leftBraceNum = 0;
     addCharElement(bufferid,c);
    }else if('\t' == c || ' ' == c || '\n' == c){
     state = STATE0;
    }else{
     error("lexReader readFuncSec state0");
    }
    break;
   case STATE1:
    if('*' == c){
     state = STATE2;
    }else if('/' == c){
     state = STATE4;
    }else{
     error("lexReader readFuncSec state1");
    }
    break;
   case STATE2:
    if('*' == c){
     state = STATE3;
    }else{
     state = STATE2;
    }
    break;
   case STATE3:
    if('*' == c){
     state = STATE3;
    }else if('/' == c){
     state = STATE0;
    }else{
     state = STATE2;
    }
    break;
   case STATE4:
    if('\n' == c){
     state = STATE0;
    }else{
     state = STATE4;
    }
    break;
   case STATE5:
    if('\"' == c){
     state = STATE6;
     addCharElement(bufferid,c);
    }else if('{' == c){
     state = STATE5;
     leftBraceNum++;
     addCharElement(bufferid,c);
    }else if('/' == c){
     state = STATE7;
     addCharElement(bufferid,c);
    }else if(c == '}'){
     leftBraceNum--;
     addCharElement(bufferid,c);
     if(0 == leftBraceNum){
      state = STATE0;
      addCharElement(bufferid, '\0');
      insertFuncEntry(getCharBuffer(bufferid));
      rewindCharPointer(bufferid);
     }else{
      state = STATE5;
     }
    }else{
     state = STATE5;
     addCharElement(bufferid,c);
    }
    break;
   case STATE6:
    addCharElement(bufferid,c);
    if('\"' == c){
     state = STATE5;
    }else if('\n' == c){
     error("lexReader readFuncSec state6");
    }else{
     state = STATE6;
    }
    break;
   case STATE7:
    addCharElement(bufferid,c);
    if('*' == c){
     state = STATE8;
    }else if('/' == c){
     state = STATE10;
    }else{
     error("lexReader readFuncSec state7");
    }
    break;
   case STATE8:
    addCharElement(bufferid,c);
    if('*' == c){
     state = STATE9;
    }else{
     state = STATE8;
    }
    break;
   case STATE9:
    addCharElement(bufferid,c);
    if('*' == c){
     state = STATE9;
    }else if('/' == c){
     state = STATE5;
    }else{
     state = STATE8;
    }
    break;
   case STATE10:
    addCharElement(bufferid,c);
    if('\n' == c){
     state = STATE5;
    }else{
     state = STATE10;
    }
    break;
   default:
    error("entering wrong state.");
  }
 }
}

variable_types: leftBraceNum int

variable_types: bufferid int

variable_types: state int

variable_types: c char


ungetch

decompiled_code:
int __fastcall ungetch(char a1)
{
int v1; // eax
__int64 v2; // rax

v1 = bufp;
if ( bufp > 98 )
{
LODWORD(v2) = puts("ERROR: buffer is full");
}
else
{
++bufp;
v2 = v1 + 1;
buf[v2] = a1;
}
return v2;
}

canonical_decompiled_code:
int __fastcall func7(char a1)
{
int v1; // eax
__int64 v2; // rax

v1 = bufp;
if ( bufp > 98 )
{
LODWORD(v2) = puts("ERROR: buffer is full");
}
else
{
++bufp;
v2 = v1 + 1;
buf[v2] = a1;
}
return v2;
}

original_code:
void ungetch(int c){
 if(bufp >= 100 -1)
  printf("ERROR: buffer is full\n");
 else
  buf[++bufp] = c;
}

variable_types: c int


readDeclareSec

decompiled_code:
int __fastcall readDeclareSec(__int64 a1, unsigned __int64 a2)
{
unsigned int v2; // ebp
void *v3; // rbx
const char *v4; // rdx
int result; // eax
char *v6; // rax
char *v7; // rax
const char *v8; // rdx
int v9; // eax

v2 = initializeCharBuffer();
v3 = &loc_1;
while ( 2 )
{
result = getch();
if ( result == -1 )
return result;
switch ( (int)v3 )
{
case 1:
if ( result == 47 )
{
LODWORD(v3) = 2;
continue;
}
if ( result == 37 )
{
LODWORD(v3) = 10;
continue;
}
if ( (unsigned int)(result - 9) > 1 && result != 32 )
goto LABEL_11;
continue;
case 2:
if ( result == 42 )
{
LODWORD(v3) = 3;
}
else if ( result == 47 )
{
LODWORD(v3) = 5;
}
else
{
v4 = (const char *)(unsigned int)(result - 9);
if ( (unsigned int)v4 <= 1 || result == 32 )
{
error((int)"lexReader readDeclareSec STATE1", a2, v4);
}
else
{
LABEL_11:
a2 = (unsigned int)(char)result;
addCharElement(v2, a2);
LODWORD(v3) = 6;
}
}
continue;
case 3:
if ( result == 42 )
LODWORD(v3) = 4;
continue;
case 4:
if ( result != 42 )
LODWORD(v3) = 2 * (result != 47) + 1;
continue;
case 5:
if ( result == 10 )
LODWORD(v3) = 1;
continue;
case 6:
if ( result == 32 || result == 9 )
{
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v6 = (char *)getCharBuffer(v2);
insertDefEntry(v6);
rewindCharPointer(v2);
LODWORD(v3) = 7;
}
else
{
if ( result != 10 )
goto LABEL_48;
error((int)"lexReader readDeclareSec STATE5", a2, (const char *)(unsigned int)v3);
}
continue;
case 7:
if ( result != 32 && result != 9 )
{
if ( result == 10 )
{
error((int)"lexReader readDeclareSec STATE6", a2, (const char *)(unsigned int)v3);
}
else
{
ungetch(result);
LODWORD(v3) = 8;
}
}
continue;
case 8:
if ( (unsigned int)(result - 9) <= 1 || result == 32 )
{
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v7 = (char *)getCharBuffer(v2);
insertDefContent(v7);
rewindCharPointer(v2);
LODWORD(v3) = 1;
continue;
}
if ( result != 34 && result != 91 )
goto LABEL_48;
a2 = (unsigned int)(char)result;
addCharElement(v2, a2);
LODWORD(v3) = 9;
continue;
case 9:
if ( result == 34 || result == 93 )
{
a2 = (unsigned int)(char)result;
addCharElement(v2, a2);
LODWORD(v3) = 8;
}
else
{
v8 = (const char *)(unsigned int)(result - 9);
if ( (unsigned int)v8 <= 1 )
{
error((int)"lexReader readDeclareSec STATE8", a2, v8);
}
else
{
LABEL_48:
a2 = (unsigned int)(char)result;
addCharElement(v2, a2);
}
}
continue;
case 10:
if ( result == 123 )
{
LODWORD(v3) = 11;
continue;
}
if ( result != 37 )
{
error((int)"lexReader readDeclareSec STATE9", a2, (const char *)(unsigned int)v3);
continue;
}
destroyCharBuffer(v2);
return 1;
case 11:
if ( result != 37 )
goto LABEL_48;
LODWORD(v3) = 12;
continue;
case 12:
if ( result == 125 )
{
v9 = charSize(v2);
declarations = (char *)malloc(v9);
a2 = getCharBuffer(v2);
strcpy(declarations, (const char *)a2);
rewindCharPointer(v2);
LODWORD(v3) = 1;
}
else
{
error((int)"lexReader readDeclareSec STATE11", a2, (const char *)(unsigned int)v3);
}
continue;
default:
error((int)"entering wrong state", a2, (const char *)(unsigned int)v3);
continue;
}
}
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, unsigned __int64 a2)
{
unsigned int v2; // ebp
void *v3; // rbx
const char *v4; // rdx
int result; // eax
char *v6; // rax
char *v7; // rax
const char *v8; // rdx
int v9; // eax

v2 = initializeCharBuffer();
v3 = &loc_1;
while ( 2 )
{
result = func5();
if ( result == -1 )
return result;
switch ( (int)v3 )
{
case 1:
if ( result == 47 )
{
LODWORD(v3) = 2;
continue;
}
if ( result == 37 )
{
LODWORD(v3) = 10;
continue;
}
if ( (unsigned int)(result - 9) > 1 && result != 32 )
goto LABEL_11;
continue;
case 2:
if ( result == 42 )
{
LODWORD(v3) = 3;
}
else if ( result == 47 )
{
LODWORD(v3) = 5;
}
else
{
v4 = (const char *)(unsigned int)(result - 9);
if ( (unsigned int)v4 <= 1 || result == 32 )
{
error((int)"lexReader readDeclareSec STATE1", a2, v4);
}
else
{
LABEL_11:
a2 = (unsigned int)(char)result;
addCharElement(v2, a2);
LODWORD(v3) = 6;
}
}
continue;
case 3:
if ( result == 42 )
LODWORD(v3) = 4;
continue;
case 4:
if ( result != 42 )
LODWORD(v3) = 2 * (result != 47) + 1;
continue;
case 5:
if ( result == 10 )
LODWORD(v3) = 1;
continue;
case 6:
if ( result == 32 || result == 9 )
{
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v6 = (char *)getCharBuffer(v2);
func0(v6);
rewindCharPointer(v2);
LODWORD(v3) = 7;
}
else
{
if ( result != 10 )
goto LABEL_48;
error((int)"lexReader readDeclareSec STATE5", a2, (const char *)(unsigned int)v3);
}
continue;
case 7:
if ( result != 32 && result != 9 )
{
if ( result == 10 )
{
error((int)"lexReader readDeclareSec STATE6", a2, (const char *)(unsigned int)v3);
}
else
{
func7(result);
LODWORD(v3) = 8;
}
}
continue;
case 8:
if ( (unsigned int)(result - 9) <= 1 || result == 32 )
{
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v7 = (char *)getCharBuffer(v2);
func1(v7);
rewindCharPointer(v2);
LODWORD(v3) = 1;
continue;
}
if ( result != 34 && result != 91 )
goto LABEL_48;
a2 = (unsigned int)(char)result;
addCharElement(v2, a2);
LODWORD(v3) = 9;
continue;
case 9:
if ( result == 34 || result == 93 )
{
a2 = (unsigned int)(char)result;
addCharElement(v2, a2);
LODWORD(v3) = 8;
}
else
{
v8 = (const char *)(unsigned int)(result - 9);
if ( (unsigned int)v8 <= 1 )
{
error((int)"lexReader readDeclareSec STATE8", a2, v8);
}
else
{
LABEL_48:
a2 = (unsigned int)(char)result;
addCharElement(v2, a2);
}
}
continue;
case 10:
if ( result == 123 )
{
LODWORD(v3) = 11;
continue;
}
if ( result != 37 )
{
error((int)"lexReader readDeclareSec STATE9", a2, (const char *)(unsigned int)v3);
continue;
}
destroyCharBuffer(v2);
return 1;
case 11:
if ( result != 37 )
goto LABEL_48;
LODWORD(v3) = 12;
continue;
case 12:
if ( result == 125 )
{
v9 = charSize(v2);
declarations = (char *)malloc(v9);
a2 = getCharBuffer(v2);
strcpy(declarations, (const char *)a2);
rewindCharPointer(v2);
LODWORD(v3) = 1;
}
else
{
error((int)"lexReader readDeclareSec STATE11", a2, (const char *)(unsigned int)v3);
}
continue;
default:
error((int)"entering wrong state", a2, (const char *)(unsigned int)v3);
continue;
}
}
}

original_code:
int readDeclareSec(){
 int bufferid = initializeCharBuffer();
 int state = STATE0;
 while(1){
  int c = getch();
  if(c == (-1))
   return -1;
  switch(state){
   case STATE0:
    if('/' == c){
     state = STATE1;
    }else if('%' == c){
     state = STATE9;
    }else if('\t' == c || ' ' == c || '\n' == c){
     state = STATE0;
    }else{
     state = STATE5;
     addCharElement(bufferid, c);
    }
    break;
   case STATE1:
    if('*' == c){
     state = STATE2;
    }else if('/' == c){
     state = STATE4;
    }else if(' ' == c || '\t' == c||'\n' == c){
     error("lexReader readDeclareSec STATE1");
    }else{
     state = STATE5;
     addCharElement(bufferid, c);
    }
    break;
   case STATE2:
    if('*' == c){
     state = STATE3;
    }else{
     state = STATE2;
    }
    break;
   case STATE3:
    if('*' == c){
     state = STATE3;
    }else if('/' == c){
     state = STATE0;
    }else{
     state = STATE2;
    }
    break;
   case STATE4:
    if('\n' == c){
     state = STATE0;
    }else{
     state = STATE4;
    }
    break;
   case STATE5:
    if(' ' == c || '\t' == c){
     state = STATE6;
     addCharElement(bufferid, '\0');
     insertDefEntry(getCharBuffer(bufferid));
     rewindCharPointer(bufferid);
    }else if('\n' == c){
     error("lexReader readDeclareSec STATE5");
    }else{
     state = STATE5;
     addCharElement(bufferid, c);
    }
    break;
   case STATE6:
    if(' ' == c || '\t' == c){
     state = STATE6;
    }else if('\n' == c){
     error("lexReader readDeclareSec STATE6");
    }else{
     state = STATE7;
     ungetch(c);
    }
    break;
   case STATE7:
    if(' ' == c || '\t' == c || '\n' == c){
     state = STATE0;
     addCharElement(bufferid, '\0');
     insertDefContent(getCharBuffer(bufferid));
     rewindCharPointer(bufferid);
    }else if('\"' == c || '[' == c){
     state = STATE8;
     addCharElement(bufferid, c);
    }else{
     state = STATE7;
     addCharElement(bufferid, c);
    }
    break;
   case STATE8:
    if('\"' == c || ']' == c){
     state = STATE7;
     addCharElement(bufferid, c);
    }else if('\n' == c || '\t' == c){
     error("lexReader readDeclareSec STATE8");
    }else{
     state = STATE8;
     addCharElement(bufferid, c);
    }
    break;
   case STATE9:
    if('{' == c){
     state = STATE10;
    }else if('%' == c){
     state = STATE0;
     destroyCharBuffer(bufferid);
     return 1;
    }else{
     error("lexReader readDeclareSec STATE9");
    }
    break;
   case STATE10:
    if('%' == c){
     state = STATE11;
    }else{
     state = STATE10;
     addCharElement(bufferid, c);
    }
    break;
   case STATE11:
    if('}' == c){
     state = STATE0;
        declarations = malloc(charSize(bufferid));
     strcpy(declarations, getCharBuffer(bufferid));
     rewindCharPointer(bufferid);
    }else{
     error("lexReader readDeclareSec STATE11");
    }
    break;
   default:
    error("entering wrong state");
  }
 }
}


readRESec

decompiled_code:
__int64 __fastcall readRESec(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
void *v3; // rbx
int v4; // eax
char *v5; // rax
const char *v6; // rdx
char *v7; // rax

v2 = initializeCharBuffer();
v3 = &loc_1;
while ( 1 )
{
v4 = getch();
if ( (_BYTE)v4 == 0xFF )
return 0xFFFFFFFFLL;
switch ( (int)v3 )
{
case 1:
if ( (_BYTE)v4 == 47 )
{
LODWORD(v3) = 2;
continue;
}
if ( (_BYTE)v4 == 37 )
{
LODWORD(v3) = 11;
continue;
}
if ( (unsigned __int8)(v4 - 9) > 1u && (_BYTE)v4 != 32 )
goto LABEL_10;
continue;
case 2:
if ( (_BYTE)v4 == 42 )
{
LODWORD(v3) = 3;
}
else if ( (_BYTE)v4 == 47 )
{
LODWORD(v3) = 5;
}
else if ( (unsigned __int8)(v4 - 9) <= 1u || (_BYTE)v4 == 32 )
{
error((int)"lexReader readRESec STATE1", a2, (const char *)(unsigned int)(v4 - 9));
}
else
{
LABEL_10:
ungetch(v4);
LODWORD(v3) = 6;
}
continue;
case 3:
if ( (_BYTE)v4 == 42 )
LODWORD(v3) = 4;
continue;
case 4:
if ( (_BYTE)v4 != 42 )
LODWORD(v3) = 2 * ((_BYTE)v4 != 47) + 1;
continue;
case 5:
if ( (_BYTE)v4 == 10 )
LODWORD(v3) = 1;
continue;
case 6:
switch ( (_BYTE)v4 )
{
case 0x20:
case 9:
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v5 = (char *)getCharBuffer(v2);
insertREEntry(v5);
rewindCharPointer(v2);
LODWORD(v3) = 9;
break;
case 0xA:
error((int)"lexReader readRESec STATE5", a2, (const char *)(unsigned int)v3);
break;
case 0x22:
LODWORD(a2) = 34;
addCharElement(v2, 34LL);
LODWORD(v3) = 7;
break;
case 0x5B:
LODWORD(a2) = 91;
addCharElement(v2, 91LL);
LODWORD(v3) = 8;
break;
default:
goto LABEL_52;
}
continue;
case 7:
if ( (_BYTE)v4 == 34 )
{
LODWORD(a2) = 34;
addCharElement(v2, 34LL);
LODWORD(v3) = 6;
continue;
}
v6 = (const char *)(unsigned int)(v4 - 9);
if ( (unsigned __int8)(v4 - 9) <= 1u )
goto LABEL_40;
goto LABEL_52;
case 8:
if ( (_BYTE)v4 == 93 )
{
LODWORD(a2) = 93;
addCharElement(v2, 93LL);
LODWORD(v3) = 6;
}
else
{
v6 = (const char *)(unsigned int)(v4 - 9);
if ( (unsigned __int8)(v4 - 9) <= 1u )
{
LABEL_40:
error((int)"lexReader readRESec STATE6", a2, v6);
}
else
{
LABEL_52:
a2 = (unsigned int)(char)v4;
addCharElement(v2, a2);
}
}
break;
case 9:
if ( (_BYTE)v4 != 32 && (_BYTE)v4 != 9 )
{
if ( (_BYTE)v4 == 123 )
LODWORD(v3) = 10;
else
error((int)"lexReader readRESec STATE7", a2, (const char *)(unsigned int)v3);
}
continue;
case 10:
if ( (_BYTE)v4 != 125 )
goto LABEL_52;
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v7 = (char *)getCharBuffer(v2);
insertREAction(v7);
rewindCharPointer(v2);
LODWORD(v3) = 1;
continue;
case 11:
if ( (_BYTE)v4 != 37 )
continue;
destroyCharBuffer(v2);
return 1LL;
default:
continue;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
void *v3; // rbx
int v4; // eax
char *v5; // rax
const char *v6; // rdx
char *v7; // rax

v2 = initializeCharBuffer();
v3 = &loc_1;
while ( 1 )
{
v4 = func5();
if ( (_BYTE)v4 == 0xFF )
return 0xFFFFFFFFLL;
switch ( (int)v3 )
{
case 1:
if ( (_BYTE)v4 == 47 )
{
LODWORD(v3) = 2;
continue;
}
if ( (_BYTE)v4 == 37 )
{
LODWORD(v3) = 11;
continue;
}
if ( (unsigned __int8)(v4 - 9) > 1u && (_BYTE)v4 != 32 )
goto LABEL_10;
continue;
case 2:
if ( (_BYTE)v4 == 42 )
{
LODWORD(v3) = 3;
}
else if ( (_BYTE)v4 == 47 )
{
LODWORD(v3) = 5;
}
else if ( (unsigned __int8)(v4 - 9) <= 1u || (_BYTE)v4 == 32 )
{
error((int)"lexReader readRESec STATE1", a2, (const char *)(unsigned int)(v4 - 9));
}
else
{
LABEL_10:
func7(v4);
LODWORD(v3) = 6;
}
continue;
case 3:
if ( (_BYTE)v4 == 42 )
LODWORD(v3) = 4;
continue;
case 4:
if ( (_BYTE)v4 != 42 )
LODWORD(v3) = 2 * ((_BYTE)v4 != 47) + 1;
continue;
case 5:
if ( (_BYTE)v4 == 10 )
LODWORD(v3) = 1;
continue;
case 6:
switch ( (_BYTE)v4 )
{
case 0x20:
case 9:
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v5 = (char *)getCharBuffer(v2);
func2(v5);
rewindCharPointer(v2);
LODWORD(v3) = 9;
break;
case 0xA:
error((int)"lexReader readRESec STATE5", a2, (const char *)(unsigned int)v3);
break;
case 0x22:
LODWORD(a2) = 34;
addCharElement(v2, 34LL);
LODWORD(v3) = 7;
break;
case 0x5B:
LODWORD(a2) = 91;
addCharElement(v2, 91LL);
LODWORD(v3) = 8;
break;
default:
goto LABEL_52;
}
continue;
case 7:
if ( (_BYTE)v4 == 34 )
{
LODWORD(a2) = 34;
addCharElement(v2, 34LL);
LODWORD(v3) = 6;
continue;
}
v6 = (const char *)(unsigned int)(v4 - 9);
if ( (unsigned __int8)(v4 - 9) <= 1u )
goto LABEL_40;
goto LABEL_52;
case 8:
if ( (_BYTE)v4 == 93 )
{
LODWORD(a2) = 93;
addCharElement(v2, 93LL);
LODWORD(v3) = 6;
}
else
{
v6 = (const char *)(unsigned int)(v4 - 9);
if ( (unsigned __int8)(v4 - 9) <= 1u )
{
LABEL_40:
error((int)"lexReader readRESec STATE6", a2, v6);
}
else
{
LABEL_52:
a2 = (unsigned int)(char)v4;
addCharElement(v2, a2);
}
}
break;
case 9:
if ( (_BYTE)v4 != 32 && (_BYTE)v4 != 9 )
{
if ( (_BYTE)v4 == 123 )
LODWORD(v3) = 10;
else
error((int)"lexReader readRESec STATE7", a2, (const char *)(unsigned int)v3);
}
continue;
case 10:
if ( (_BYTE)v4 != 125 )
goto LABEL_52;
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v7 = (char *)getCharBuffer(v2);
func3(v7);
rewindCharPointer(v2);
LODWORD(v3) = 1;
continue;
case 11:
if ( (_BYTE)v4 != 37 )
continue;
destroyCharBuffer(v2);
return 1LL;
default:
continue;
}
}
}

original_code:
int readRESec(){
 int bufferid = initializeCharBuffer();
 int state = STATE0;
 while(1){
  char c = getch();
  if(c == (-1))
   return -1;
  switch(state){
   case STATE0:
    if('/' == c){
     state = STATE1;
    }else if('%' == c){
     state = STATE10;
    }else if('\t' == c || ' ' == c || '\n' == c){
     state = STATE0;
    }else{
     state = STATE5;
     ungetch(c);
    }
    break;
   case STATE1:
    if('*' == c){
     state = STATE2;
    }else if('/' == c){
     state = STATE4;
    }else if(' ' == c || '\t' == c||'\n' == c){
     error("lexReader readRESec STATE1");
    }else{
     state = STATE5;
     ungetch(c);
    }
    break;
   case STATE2:
    if('*' == c){
     state = STATE3;
    }else{
     state = STATE2;
    }
    break;
   case STATE3:
    if('*' == c){
     state = STATE3;
    }else if('/' == c){
     state = STATE0;
    }else{
     state = STATE2;
    }
    break;
   case STATE4:
    if('\n' == c){
     state = STATE0;
    }else{
     state = STATE4;
    }
    break;
   case STATE5:
    if(' ' == c || '\t' == c){
     state = STATE8;
     addCharElement(bufferid, '\0');
     insertREEntry(getCharBuffer(bufferid));
     rewindCharPointer(bufferid);
    }else if('\n' == c){
     error("lexReader readRESec STATE5");
    }else if('\"' == c){
     state = STATE6;
     addCharElement(bufferid,c);
    }else if('[' == c){
     state = STATE7;
     addCharElement(bufferid, c);
    }else{
     state = STATE5;
     addCharElement(bufferid,c);
    }
    break;
   case STATE6:
    if('\"' == c){
     state = STATE5;
     addCharElement(bufferid,c);
    }else if('\n' == c || '\t' == c){
     error("lexReader readRESec STATE6");
    }else{
     state = STATE6;
     addCharElement(bufferid,c);
    }
    break;
   case STATE7:
    if(']' == c){
     state = STATE5;
     addCharElement(bufferid,c);
    }else if('\n' == c || '\t' == c){
     error("lexReader readRESec STATE6");
    }else{
     state = STATE7;
     addCharElement(bufferid,c);
    }
    break;
   case STATE8:
    if(' ' == c || '\t' == c){
     state = STATE8;
    }else if('{' == c){
     state = STATE9;
    }else{
     error("lexReader readRESec STATE7");
    }
    break;
   case STATE9:
    if('}' == c){
     state = STATE0;
     addCharElement(bufferid, '\0');
     insertREAction(getCharBuffer(bufferid));
     rewindCharPointer(bufferid);
    }else{
     state = STATE9;
     addCharElement(bufferid,c);
    }
    break;
   case STATE10:
    if('%' == c){
     state = STATE0;
     destroyCharBuffer(bufferid);
     return 1;
    }
    break;
   defualt:
    error("entering wrong state");
  }
 }
}


topStack

decompiled_code:
__int64 topStack()
{
if ( !stack )
return 0xFFFFFFFFLL;
if ( stack == (void *)topp )
return 0xFFFFFFFFLL;
return *(unsigned int *)(topp - 4);
}

canonical_decompiled_code:
__int64 func0()
{
if ( !stack )
return 0xFFFFFFFFLL;
if ( stack == (void *)topp )
return 0xFFFFFFFFLL;
return *(unsigned int *)(topp - 4);
}

original_code:
int topStack(){
 if(((void *)0) == stack){
  return -1;
 }else if(topp == stack){
  return -1;
 }else{
  return *(topp-1);
 }
}


popStack

decompiled_code:
__int64 popStack()
{
__int64 v0; // rax

if ( !stack )
return 0xFFFFFFFFLL;
v0 = topp;
if ( stack == (void *)topp )
return 0xFFFFFFFFLL;
topp -= 4LL;
return *(unsigned int *)(v0 - 4);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax

if ( !stack )
return 0xFFFFFFFFLL;
v0 = topp;
if ( stack == (void *)topp )
return 0xFFFFFFFFLL;
topp -= 4LL;
return *(unsigned int *)(v0 - 4);
}

original_code:
int popStack(){
 if(((void *)0) == stack){
  return -1;
 }else if(topp == stack){
  return -1;
 }else{
  return *--topp;
 }
}


clearStack

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

do
result = popStack();
while ( (_DWORD)result != -1 );
return result;
}

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

do
result = func1();
while ( (_DWORD)result != -1 );
return result;
}

original_code:
void clearStack(){
 while(-1 != popStack())
  ;
}


getUnmarkedState

decompiled_code:
unsigned int *getUnmarkedState()
{
unsigned int *result; // rax

result = (unsigned int *)table;
if ( !table )
return 0LL;
while ( result[4] )
{
result = (unsigned int *)*((_QWORD *)result + 3);
if ( !result )
return result;
}
return (unsigned int *)*result;
}

canonical_decompiled_code:
unsigned int *func0()
{
unsigned int *result; // rax

result = (unsigned int *)table;
if ( !table )
return 0LL;
while ( result[4] )
{
result = (unsigned int *)*((_QWORD *)result + 3);
if ( !result )
return result;
}
return (unsigned int *)*result;
}

original_code:
int getUnmarkedState(){
 entry *temp = table;
 while(((void *)0) != temp){
  if(0 == temp->marked)
   return temp->state;
  temp = temp->next;
 }
 return 0;
}

canonical_original_code:
int getUnmarkedState(){
 struct dfaStateTableEntry *temp = table;
 while(((void *)0) != temp){
  if(0 == temp->marked)
   return temp->state;
  temp = temp->next;
 }
 return 0;
}

variable_types: struct dfaStateTableEntry { int state; int *nfaStates; int marked; struct dfaStateTableEntry *next; } *


unmarkedStatesExist

decompiled_code:
_BOOL8 unmarkedStatesExist()
{
return (int)getUnmarkedState() > 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return (int)func0() > 0;
}

original_code:
int unmarkedStatesExist(){
 int state = getUnmarkedState();
 if(state > 0)
  return 1;
 else
  return 0;
}


destroyDFATable

decompiled_code:
void destroyDFATable()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)table;
if ( table )
{
do
{
v1 = v0;
v0 = (void **)v0[3];
free(v1[1]);
free(v1);
}
while ( v0 );
}
table = 0LL;
stateNum = 0;
}

canonical_decompiled_code:
void func2()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)table;
if ( table )
{
do
{
v1 = v0;
v0 = (void **)v0[3];
free(v1[1]);
free(v1);
}
while ( v0 );
}
table = 0LL;
stateNum = 0;
}

original_code:
void destroyDFATable(){
 entry *temp = table;
 entry *next = ((void *)0);
 while(((void *)0) != temp){
  next = temp->next;
  temp->state = 0;
  free(temp->nfaStates);
  temp->nfaStates = ((void *)0);
  temp->marked = 0;
  temp->next = ((void *)0);
  free(temp);
  temp = next;
 }
 table = ((void *)0);
 stateNum = 0;
}

canonical_original_code:
void destroyDFATable(){
 struct dfaStateTableEntry *temp = table;
 struct dfaStateTableEntry *next = ((void *)0);
 while(((void *)0) != temp){
  next = temp->next;
  temp->state = 0;
  free(temp->nfaStates);
  temp->nfaStates = ((void *)0);
  temp->marked = 0;
  temp->next = ((void *)0);
  free(temp);
  temp = next;
 }
 table = ((void *)0);
 stateNum = 0;
}

user_defined_types: struct dfaStateTableEntry { int state; int *nfaStates; int marked; struct dfaStateTableEntry *next; }


getIntArraySize

decompiled_code:
__int64 __fastcall getIntArraySize(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = 1LL;
do
v2 = v1++;
while ( *(_DWORD *)(a1 + 4 * v1 - 8) != -1 );
return v2;
}

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

v1 = 1LL;
do
v2 = v1++;
while ( *(_DWORD *)(a1 + 4 * v1 - 8) != -1 );
return v2;
}

original_code:
int getIntArraySize(int *array){
 int size = 0;
 while(-1 != *(array+(size++)))
  ;
 return size;
}

variable_types:
array
int *

variable_types: size int


compareTwoIntArray

decompiled_code:
__int64 __fastcall compareTwoIntArray(__int64 a1, __int64 a2)
{
int v2; // er12
int v3; // edx
__int64 result; // rax
__int64 i; // rax
int v6; // edx

v2 = getIntArraySize(a1);
v3 = getIntArraySize(a2);
result = 0LL;
if ( v2 == v3 )
{
for ( i = 0LL; ; i += 4LL )
{
v6 = *(_DWORD *)(a1 + i);
if ( v6 != *(_DWORD *)(a2 + i) )
break;
if ( v6 == -1 )
return 1LL;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // er12
int v3; // edx
__int64 result; // rax
__int64 i; // rax
int v6; // edx

v2 = func3(a1);
v3 = func3(a2);
result = 0LL;
if ( v2 == v3 )
{
for ( i = 0LL; ; i += 4LL )
{
v6 = *(_DWORD *)(a1 + i);
if ( v6 != *(_DWORD *)(a2 + i) )
break;
if ( v6 == -1 )
return 1LL;
}
result = 0LL;
}
return result;
}

original_code:
int compareTwoIntArray(int *A, int *B){
 int sizeA = getIntArraySize(A);
 int sizeB = getIntArraySize(B);
 if(sizeA != sizeB)
  return 0;
 int i = -1;
 while(1){
  i++;
  if(*(A+i) != *(B+i))
   return 0;
  if(-1 == *(A+i))
   return 1;
 }
}

variable_types:
A
int *

variable_types:
B
int *

variable_types: sizeA int

variable_types: sizeB int

variable_types: i int


installState

decompiled_code:
__int64 __fastcall installState(int *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbx
unsigned int v3; // er12
_QWORD *v4; // r13

v1 = table;
if ( table )
{
while ( !(unsigned int)compareTwoIntArray(v1[1], (__int64)a1) )
{
if ( !v1[3] )
{
v4 = malloc(0x20uLL);
v3 = stateNum + 1;
stateNum = v3;
*(_DWORD *)v4 = v3;
v4[1] = copyIntArray(a1);
*((_DWORD *)v4 + 4) = 0;
v4[3] = 0LL;
v1[3] = v4;
return v3;
}
v1 = (_QWORD *)v1[3];
}
v3 = *(_DWORD *)v1;
}
else
{
v2 = malloc(0x20uLL);
v3 = stateNum + 1;
stateNum = v3;
*(_DWORD *)v2 = v3;
v2[1] = copyIntArray(a1);
*((_DWORD *)v2 + 4) = 0;
v2[3] = 0LL;
table = v2;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbx
unsigned int v3; // er12
_QWORD *v4; // r13

v1 = table;
if ( table )
{
while ( !(unsigned int)func4(v1[1], (__int64)a1) )
{
if ( !v1[3] )
{
v4 = malloc(0x20uLL);
v3 = stateNum + 1;
stateNum = v3;
*(_DWORD *)v4 = v3;
v4[1] = copyIntArray(a1);
*((_DWORD *)v4 + 4) = 0;
v4[3] = 0LL;
v1[3] = v4;
return v3;
}
v1 = (_QWORD *)v1[3];
}
v3 = *(_DWORD *)v1;
}
else
{
v2 = malloc(0x20uLL);
v3 = stateNum + 1;
stateNum = v3;
*(_DWORD *)v2 = v3;
v2[1] = copyIntArray(a1);
*((_DWORD *)v2 + 4) = 0;
v2[3] = 0LL;
table = v2;
}
return v3;
}

original_code:
int installState(int *nfaStates){
 entry *temp = table;
 entry *pre = ((void *)0);
 while(((void *)0) != temp){
  if(compareTwoIntArray(temp->nfaStates, nfaStates)){
   return temp->state;
  }
  pre = temp;
  temp = temp->next;
 }
 entry *newEntry = malloc(sizeof(entry));
 newEntry->state = ++stateNum;
 newEntry->nfaStates = copyIntArray(nfaStates);
 newEntry->marked = 0;
 newEntry->next = ((void *)0);
 if(((void *)0) == table)
  table = newEntry;
 else
  pre->next = newEntry;
 return stateNum;
}

canonical_original_code:
int installState(int *nfaStates){
 struct dfaStateTableEntry *temp = table;
 struct dfaStateTableEntry *pre = ((void *)0);
 while(((void *)0) != temp){
  if(compareTwoIntArray(temp->nfaStates, nfaStates)){
   return temp->state;
  }
  pre = temp;
  temp = temp->next;
 }
 struct dfaStateTableEntry *newEntry = malloc(sizeof(entry));
 newEntry->state = ++stateNum;
 newEntry->nfaStates = copyIntArray(nfaStates);
 newEntry->marked = 0;
 newEntry->next = ((void *)0);
 if(((void *)0) == table)
  table = newEntry;
 else
  pre->next = newEntry;
 return stateNum;
}

variable_types:
nfaStates
int *


error

decompiled_code:
int __fastcall error(const char *a1)
{
return fprintf(stderr, "ERROR: %s\n", a1);
}

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

original_code:
void error(char *errorMessage){
 fprintf(stderr, "ERROR: %s\n", errorMessage);
}

variable_types:
errorMessage
char *


optimizeDFA

decompiled_code:
void optimizeDFA()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void optimizeDFA(){
}

canonical_original_code:
void optimizeDFA(){
}


output

decompiled_code:
int output()
{
__int64 i; // rbx
int result; // eax
__int64 j; // rbx
__int64 k; // rbx

for ( i = definitions; i; i = *(_QWORD *)(i + 16) )
printf("%s : %s\n", *(const char **)i, *(const char **)(i + 8));
result = puts(declarations);
for ( j = regexps; j; j = *(_QWORD *)(j + 16) )
result = printf("%s : %s\n", *(const char **)j, *(const char **)(j + 8));
for ( k = additionalfuncs; k; k = *(_QWORD *)(k + 8) )
result = puts(*(const char **)k);
return result;
}

canonical_decompiled_code:
int func0()
{
__int64 i; // rbx
int result; // eax
__int64 j; // rbx
__int64 k; // rbx

for ( i = definitions; i; i = *(_QWORD *)(i + 16) )
printf("%s : %s\n", *(const char **)i, *(const char **)(i + 8));
result = puts(declarations);
for ( j = regexps; j; j = *(_QWORD *)(j + 16) )
result = printf("%s : %s\n", *(const char **)j, *(const char **)(j + 8));
for ( k = additionalfuncs; k; k = *(_QWORD *)(k + 8) )
result = puts(*(const char **)k);
return result;
}

original_code:
void output(){
 struct Defentry *p = definitions;
 while(((void *)0) != p){
  printf("%s : %s\n", p->name, p->definition);
  p = p->next;
 }
 printf("%s\n", declarations);
 struct REentry *e = regexps;
 while(((void *)0) != e){
  printf("%s : %s\n", e->regexp, e->action);
  e = e->next;
 }
 struct Funcentry *f = additionalfuncs;
 while(((void *)0) != f){
  printf("%s\n", f->body);
  f = f->next;
 }
}

variable_types: struct Defentry { char *name; char *definition; struct Defentry *next; } *

variable_types: struct REentry { char *regexp; char *action; struct REentry *next; } *

user_defined_types: struct Funcentry { char *body; struct Funcentry *next; }


repo: Zhouxiaoqing/ztiny

decompiled_code:
int print_usage()
{
puts("Usage : twt <file-name>");
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
puts("Usage : twt <file-name>");
return putchar(10);
}

original_code:
static void print_usage() {
 printf("Usage : twt <file-name>\n");
 printf("\n");
}


main

canonical_name: main

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

if ( argc <= 1 )
{
print_usage();
exit(1);
}
listing = (__int64)stdout;
source = (__int64)fopen(argv[1], "r");
if ( !source )
{
fwrite(" [Error] No such file..", 1uLL, 0x17uLL, stdout);
exit(1);
}
v3 = parse();
print_tree(v3);
return 0;
}

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

if ( argc <= 1 )
{
func0();
exit(1);
}
listing = (__int64)stdout;
source = (__int64)fopen(argv[1], "r");
if ( !source )
{
fwrite(" [Error] No such file..", 1uLL, 0x17uLL, stdout);
exit(1);
}
v3 = parse();
print_tree(v3);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 if (argc < 2) {
  print_usage();
  exit(1);
 }
 listing = stdout;
 source = fopen(argv[1], "r");
 if (source == ((void *)0)) {
  fprintf(stdout, " [Error] No such file..");
  exit(1);
 }
 TreeNode *t = parse();
 print_tree(t);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc < 2) {
  print_usage();
  exit(1);
 }
 listing = stdout;
 source = fopen(argv[1], "r");
 if (source == ((void *)0)) {
  fprintf(stdout, " [Error] No such file..");
  exit(1);
 }
 struct _TreeNode *t = parse();
 print_tree(t);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct _TreeNode { struct _TreeNode *child[3]; struct _TreeNode *sibling; int line_no; enum NodeKind { StmtK=0, ExpK=1 } node_kind; union { enum StmtKind { IfK=0, RepeatK=1, AssignK=2, ReadK=3, WriteK=4 } sk; enum ExpKind { OpK=0, ConstK=1, IdK=2 } ek; } kind; union { enum TokenType { ENDFILE=0, ERROR=1, IF=2, THEN=3, ELSE=4, END=5, REPEAT=6, UNTIL=7, READ=8, WRITE=9, ID=10, NUM=11, ASSIGN=12, EQ=13, LT=14, PLUS=15, MINUS=16, TIMES=17, OVER=18, LPAREN=19, RPAREN=20, SEMI=21 } op; int val; char *name; } attr; enum ExpType { Void=0, Integer=1, Boolean=2 } type; } *

user_defined_types: struct _TreeNode { struct _TreeNode *child[3]; struct _TreeNode *sibling; int line_no; enum NodeKind node_kind; union { enum StmtKind sk; enum ExpKind ek; } kind; union { enum TokenType op; int val; char *name; } attr; enum ExpType type; }


decompiled_code:
int __fastcall print_token(int a1, const char *a2)
{
int result; // eax

switch ( a1 )
{
case 0:
result = fwrite("EOF\n", 1uLL, 4uLL, listing);
break;
case 1:
result = fprintf(listing, "ERROR, token string : %s \n", a2);
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
result = fprintf(listing, "Reverse words : %s \n", a2);
break;
case 10:
result = fprintf(listing, "ID, name = %s \n", a2);
break;
case 11:
result = fprintf(listing, "NUM, val = %s \n", a2);
break;
case 12:
result = fwrite(":=\n", 1uLL, 3uLL, listing);
break;
case 13:
result = fwrite("=\n", 1uLL, 2uLL, listing);
break;
case 14:
result = fwrite("<\n", 1uLL, 2uLL, listing);
break;
case 15:
result = fwrite("+\n", 1uLL, 2uLL, listing);
break;
case 16:
result = fwrite("-\n", 1uLL, 2uLL, listing);
break;
case 17:
result = fwrite("*\n", 1uLL, 2uLL, listing);
break;
case 18:
result = fwrite("/\n", 1uLL, 2uLL, listing);
break;
case 19:
result = fwrite("(\n", 1uLL, 2uLL, listing);
break;
case 20:
result = fwrite(")\n", 1uLL, 2uLL, listing);
break;
case 21:
result = fwrite(";\n", 1uLL, 2uLL, listing);
break;
default:
result = fwrite("Unknow token.\n", 1uLL, 0xEuLL, listing);
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2)
{
int result; // eax

switch ( a1 )
{
case 0:
result = fwrite("EOF\n", 1uLL, 4uLL, listing);
break;
case 1:
result = fprintf(listing, "ERROR, token string : %s \n", a2);
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
result = fprintf(listing, "Reverse words : %s \n", a2);
break;
case 10:
result = fprintf(listing, "ID, name = %s \n", a2);
break;
case 11:
result = fprintf(listing, "NUM, val = %s \n", a2);
break;
case 12:
result = fwrite(":=\n", 1uLL, 3uLL, listing);
break;
case 13:
result = fwrite("=\n", 1uLL, 2uLL, listing);
break;
case 14:
result = fwrite("<\n", 1uLL, 2uLL, listing);
break;
case 15:
result = fwrite("+\n", 1uLL, 2uLL, listing);
break;
case 16:
result = fwrite("-\n", 1uLL, 2uLL, listing);
break;
case 17:
result = fwrite("*\n", 1uLL, 2uLL, listing);
break;
case 18:
result = fwrite("/\n", 1uLL, 2uLL, listing);
break;
case 19:
result = fwrite("(\n", 1uLL, 2uLL, listing);
break;
case 20:
result = fwrite(")\n", 1uLL, 2uLL, listing);
break;
case 21:
result = fwrite(";\n", 1uLL, 2uLL, listing);
break;
default:
result = fwrite("Unknow token.\n", 1uLL, 0xEuLL, listing);
break;
}
return result;
}

original_code:
void
print_token(TokenType type, const char *token_string) {
 switch(type) {
  case IF:
  case THEN:
  case ELSE:
  case END:
  case REPEAT:
  case UNTIL:
  case READ:
  case WRITE:
   fprintf(listing, "Reverse words : %s \n", token_string);
   break;
  case ASSIGN: fprintf(listing, ":=\n"); break;
  case LT: fprintf(listing, "<\n"); break;
  case EQ: fprintf(listing, "=\n"); break;
  case LPAREN: fprintf(listing, "(\n"); break;
  case RPAREN: fprintf(listing, ")\n"); break;
  case SEMI: fprintf(listing, ";\n"); break;
  case PLUS: fprintf(listing, "+\n"); break;
  case MINUS: fprintf(listing, "-\n"); break;
  case TIMES: fprintf(listing, "*\n"); break;
  case OVER: fprintf(listing, "/\n"); break;
  case ENDFILE: fprintf(listing, "EOF\n"); break;
  case NUM:
   fprintf(listing, "NUM, val = %s \n", token_string);
   break;
  case ID:
   fprintf(listing, "ID, name = %s \n", token_string);
   break;
  case ERROR:
   fprintf(listing, "ERROR, token string : %s \n", token_string);
   break;
  default :
   fprintf(listing, "Unknow token.\n");
 }
}

canonical_original_code:
void print_token(enum TokenType type, char *token_string) {
 switch(type) {
  case IF:
  case THEN:
  case ELSE:
  case END:
  case REPEAT:
  case UNTIL:
  case READ:
  case WRITE:
   fprintf(listing, "Reverse words : %s \n", token_string);
   break;
  case ASSIGN: fprintf(listing, ":=\n"); break;
  case LT: fprintf(listing, "<\n"); break;
  case EQ: fprintf(listing, "=\n"); break;
  case LPAREN: fprintf(listing, "(\n"); break;
  case RPAREN: fprintf(listing, ")\n"); break;
  case SEMI: fprintf(listing, ";\n"); break;
  case PLUS: fprintf(listing, "+\n"); break;
  case MINUS: fprintf(listing, "-\n"); break;
  case TIMES: fprintf(listing, "*\n"); break;
  case OVER: fprintf(listing, "/\n"); break;
  case ENDFILE: fprintf(listing, "EOF\n"); break;
  case NUM:
   fprintf(listing, "NUM, val = %s \n", token_string);
   break;
  case ID:
   fprintf(listing, "ID, name = %s \n", token_string);
   break;
  case ERROR:
   fprintf(listing, "ERROR, token string : %s \n", token_string);
   break;
  default :
   fprintf(listing, "Unknow token.\n");
 }
}

variable_types: enum TokenType { ENDFILE=0, ERROR=1, IF=2, THEN=3, ELSE=4, END=5, REPEAT=6, UNTIL=7, READ=8, WRITE=9, ID=10, NUM=11, ASSIGN=12, EQ=13, LT=14, PLUS=15, MINUS=16, TIMES=17, OVER=18, LPAREN=19, RPAREN=20, SEMI=21 }


decompiled_code:
void __fastcall print_tree(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
int v3; // eax

v1 = a1;
ident_no += 2;
if ( a1 )
{
do
{
print_space();
v3 = *(_DWORD *)(v1 + 36);
if ( v3 )
{
if ( v3 == 1 )
{
v2 = *(_DWORD *)(v1 + 40);
if ( v2 == 1 )
{
fprintf(listing, "Const: %d\n", *(unsigned int *)(v1 + 48));
}
else if ( v2 == 2 )
{
fprintf(listing, "Id: %s\n", *(const char **)(v1 + 48));
}
else if ( v2 )
{
fwrite("Unknown Exp Kind. \n", 1uLL, 0x13uLL, listing);
}
else
{
fwrite("Op: ", 1uLL, 4uLL, listing);
print_token(*(_DWORD *)(v1 + 48), byte_6E8);
}
}
else
{
fwrite("Unknown type of node.\n", 1uLL, 0x16uLL, listing);
}
}
else
{
switch ( *(_DWORD *)(v1 + 40) )
{
case 0:
fwrite("If\n", 1uLL, 3uLL, listing);
break;
case 1:
fwrite("Repeat\n", 1uLL, 7uLL, listing);
break;
case 2:
fprintf(listing, "Assign to : %s \n", *(const char **)(v1 + 48));
break;
case 3:
fprintf(listing, "Read : %s \n", *(const char **)(v1 + 48));
break;
case 4:
fwrite("Write \n", 1uLL, 7uLL, listing);
break;
default:
fwrite("Unknown Stmt Kind. \n", 1uLL, 0x14uLL, listing);
break;
}
}
print_tree(*(_QWORD *)v1);
print_tree(*(_QWORD *)(v1 + 8));
print_tree(*(_QWORD *)(v1 + 16));
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
ident_no -= 2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
int v3; // eax

v1 = a1;
ident_no += 2;
if ( a1 )
{
do
{
func1();
v3 = *(_DWORD *)(v1 + 36);
if ( v3 )
{
if ( v3 == 1 )
{
v2 = *(_DWORD *)(v1 + 40);
if ( v2 == 1 )
{
fprintf(listing, "Const: %d\n", *(unsigned int *)(v1 + 48));
}
else if ( v2 == 2 )
{
fprintf(listing, "Id: %s\n", *(const char **)(v1 + 48));
}
else if ( v2 )
{
fwrite("Unknown Exp Kind. \n", 1uLL, 0x13uLL, listing);
}
else
{
fwrite("Op: ", 1uLL, 4uLL, listing);
func0(*(_DWORD *)(v1 + 48), byte_6E8);
}
}
else
{
fwrite("Unknown type of node.\n", 1uLL, 0x16uLL, listing);
}
}
else
{
switch ( *(_DWORD *)(v1 + 40) )
{
case 0:
fwrite("If\n", 1uLL, 3uLL, listing);
break;
case 1:
fwrite("Repeat\n", 1uLL, 7uLL, listing);
break;
case 2:
fprintf(listing, "Assign to : %s \n", *(const char **)(v1 + 48));
break;
case 3:
fprintf(listing, "Read : %s \n", *(const char **)(v1 + 48));
break;
case 4:
fwrite("Write \n", 1uLL, 7uLL, listing);
break;
default:
fwrite("Unknown Stmt Kind. \n", 1uLL, 0x14uLL, listing);
break;
}
}
func2(*(_QWORD *)v1);
func2(*(_QWORD *)(v1 + 8));
func2(*(_QWORD *)(v1 + 16));
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
ident_no -= 2;
}

original_code:
void print_tree(TreeNode *t) {
 ident_no += 2;
 while(t != ((void *)0)) {
  _print_space();
  if (t->node_kind == StmtK) {
   switch(t->kind.sk) {
    case IfK:
     fprintf(listing, "If\n");
     break;
    case RepeatK:
     fprintf(listing, "Repeat\n");
     break;
    case AssignK:
     fprintf(listing, "Assign to : %s \n", t->attr.name);
     break;
    case ReadK:
     fprintf(listing, "Read : %s \n", t->attr.name);
     break;
    case WriteK:
     fprintf(listing, "Write \n");
     break;
    default:
     fprintf(listing, "Unknown Stmt Kind. \n");
     break;
   }
  }else if (t->node_kind == ExpK) {
   switch(t->kind.ek) {
    case OpK:
     fprintf(listing, "Op: ");
     print_token(t->attr.op, "\0");
     break;
    case ConstK:
     fprintf(listing, "Const: %d\n", t->attr.val);
     break;
    case IdK:
     fprintf(listing, "Id: %s\n", t->attr.name);
     break;
    default:
     fprintf(listing, "Unknown Exp Kind. \n");
     break;
   }
  }else
   fprintf(listing, "Unknown type of node.\n");
  int i;
  for (i=0; i<3; i++)
   print_tree(t->child[i]);
  t = t->sibling;
 }
 ident_no -= 2;
}

canonical_original_code:
void print_tree(struct _TreeNode *t) {
 ident_no += 2;
 while(t != ((void *)0)) {
  _print_space();
  if (t->node_kind == StmtK) {
   switch(t->kind.sk) {
    case IfK:
     fprintf(listing, "If\n");
     break;
    case RepeatK:
     fprintf(listing, "Repeat\n");
     break;
    case AssignK:
     fprintf(listing, "Assign to : %s \n", t->attr.name);
     break;
    case ReadK:
     fprintf(listing, "Read : %s \n", t->attr.name);
     break;
    case WriteK:
     fprintf(listing, "Write \n");
     break;
    default:
     fprintf(listing, "Unknown Stmt Kind. \n");
     break;
   }
  }else if (t->node_kind == ExpK) {
   switch(t->kind.ek) {
    case OpK:
     fprintf(listing, "Op: ");
     print_token(t->attr.op, "\0");
     break;
    case ConstK:
     fprintf(listing, "Const: %d\n", t->attr.val);
     break;
    case IdK:
     fprintf(listing, "Id: %s\n", t->attr.name);
     break;
    default:
     fprintf(listing, "Unknown Exp Kind. \n");
     break;
   }
  }else
   fprintf(listing, "Unknown type of node.\n");
  int i;
  for (i=0; i<3; i++)
   print_tree(t->child[i]);
  t = t->sibling;
 }
 ident_no -= 2;
}

user_defined_types: enum ExpType { Void=0, Integer=1, Boolean=2 }

user_defined_types: enum StmtKind { IfK=0, RepeatK=1, AssignK=2, ReadK=3, WriteK=4 }

user_defined_types: enum TokenType { ENDFILE=0, ERROR=1, IF=2, THEN=3, ELSE=4, END=5, REPEAT=6, UNTIL=7, READ=8, WRITE=9, ID=10, NUM=11, ASSIGN=12, EQ=13, LT=14, PLUS=15, MINUS=16, TIMES=17, OVER=18, LPAREN=19, RPAREN=20, SEMI=21 }


decompiled_code:
__int64 __fastcall free_tree(void *ptr)
{
void *v1; // rbp
__int64 result; // rax

if ( ptr )
{
free_tree(*(void **)ptr);
free_tree(*((void **)ptr + 1));
free_tree(*((void **)ptr + 2));
v1 = (void *)*((_QWORD *)ptr + 3);
free(ptr);
result = free_tree(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
void *v1; // rbp
__int64 result; // rax

if ( ptr )
{
func3(*(void **)ptr);
func3(*((void **)ptr + 1));
func3(*((void **)ptr + 2));
v1 = (void *)*((_QWORD *)ptr + 3);
free(ptr);
result = func3(v1);
}
return result;
}

original_code:
void free_tree(TreeNode *t) {
 if (t == ((void *)0))
  return;
 else {
  int i;
  for (i=0; i<3; i++)
   free_tree(t->child[i]);
  TreeNode *s = t->sibling;
  free(t);
  free_tree(s);
 }
}

canonical_original_code:
void free_tree(struct _TreeNode *t) {
 if (t == ((void *)0))
  return;
 else {
  int i;
  for (i=0; i<3; i++)
   free_tree(t->child[i]);
  struct _TreeNode *s = t->sibling;
  free(t);
  free_tree(s);
 }
}


parse

decompiled_code:
_QWORD *parse()
{
double v0; // xmm0_8
int v1; // eax
_QWORD *v2; // rbx

v0 = get_token();
token = v1;
v2 = stmt_sequence(v0);
if ( !v2 )
fwrite(" [Error] parse error.", 1uLL, 0x15uLL, listing);
return v2;
}

canonical_decompiled_code:
_QWORD *func7()
{
double v0; // xmm0_8
int v1; // eax
_QWORD *v2; // rbx

v0 = get_token();
token = v1;
v2 = stmt_sequence(v0);
if ( !v2 )
fwrite(" [Error] parse error.", 1uLL, 0x15uLL, listing);
return v2;
}

original_code:
TreeNode *parse() {
 TreeNode *t = ((void *)0);
 token = get_token();
 t = _stmt_sequence();
 if (t == ((void *)0))
  fprintf(listing, " [Error] parse error.");
 return t;
}

canonical_original_code:
struct _TreeNode *parse() {
 struct _TreeNode *t = ((void *)0);
 token = get_token();
 t = _stmt_sequence();
 if (t == ((void *)0))
  fprintf(listing, " [Error] parse error.");
 return t;
}

return_type: struct _TreeNode { struct _TreeNode *child[3]; struct _TreeNode *sibling; int line_no; enum NodeKind { StmtK=0, ExpK=1 } node_kind; union { enum StmtKind { IfK=0, RepeatK=1, AssignK=2, ReadK=3, WriteK=4 } sk; enum ExpKind { OpK=0, ConstK=1, IdK=2 } ek; } kind; union { enum TokenType { ENDFILE=0, ERROR=1, IF=2, THEN=3, ELSE=4, END=5, REPEAT=6, UNTIL=7, READ=8, WRITE=9, ID=10, NUM=11, ASSIGN=12, EQ=13, LT=14, PLUS=15, MINUS=16, TIMES=17, OVER=18, LPAREN=19, RPAREN=20, SEMI=21 } op; int val; char *name; } attr; enum ExpType { Void=0, Integer=1, Boolean=2 } type; } *


decompiled_code:
void unget_next_char()
{
if ( !EOF_FLAG )
--line_pos;
}

canonical_decompiled_code:
void func0()
{
if ( !EOF_FLAG )
--line_pos;
}

original_code:
static void
unget_next_char() {
 if (!EOF_FLAG) {
  line_pos --;
 }
}


decompiled_code:
__int64 get_next_char()
{
int v0; // eax
__int64 result; // rax

v0 = line_pos;
if ( line_pos >= buff_size )
{
++line_no;
if ( fgets(line_buff, 255, source) )
{
buff_size = strlen(line_buff);
line_pos = 1;
result = (unsigned int)line_buff[0];
}
else
{
EOF_FLAG = 1;
result = 0xFFFFFFFFLL;
}
}
else
{
++line_pos;
result = (unsigned int)line_buff[v0];
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
__int64 result; // rax

v0 = line_pos;
if ( line_pos >= buff_size )
{
++line_no;
if ( fgets(line_buff, 255, source) )
{
buff_size = strlen(line_buff);
line_pos = 1;
result = (unsigned int)line_buff[0];
}
else
{
EOF_FLAG = 1;
result = 0xFFFFFFFFLL;
}
}
else
{
++line_pos;
result = (unsigned int)line_buff[v0];
}
return result;
}

original_code:
static int
get_next_char() {
 if (line_pos >= buff_size) {
  line_no ++;
  if (fgets(line_buff, 256 -1, source)) {
   buff_size = strlen(line_buff);
   line_pos = 0;
   return line_buff[line_pos++];
  }else {
   EOF_FLAG = 1;
   return (-1);
  }
 }else {
  return line_buff[line_pos++];
 }
}


decompiled_code:
__int64 __fastcall get_token()
{
unsigned int v0; // er13
int v1; // er12
unsigned int v2; // ebp
__int64 v3; // r14
unsigned __int64 v4; // rbx

v1 = 0;
v2 = 0;
v3 = 0x100002600LL;
do
{
v4 = (unsigned int)get_next_char();
switch ( v2 )
{
case 0u:
if ( is_digit(v4) )
{
v2 = 3;
goto LABEL_27;
}
v2 = is_alpha(v4);
if ( v2 )
{
v2 = 4;
goto LABEL_27;
}
if ( (unsigned int)v4 > 0x20 )
{
v2 = 1;
if ( (_DWORD)v4 != 58 )
{
v2 = 2;
if ( (_DWORD)v4 != 123 )
{
switch ( (int)v4 )
{
case -1:
v0 = 0;
v2 = 5;
break;
case 40:
v0 = 19;
v2 = 5;
goto LABEL_27;
case 41:
v0 = 20;
v2 = 5;
goto LABEL_27;
case 42:
v0 = 17;
v2 = 5;
goto LABEL_27;
case 43:
v0 = 15;
v2 = 5;
goto LABEL_27;
case 45:
v0 = 16;
v2 = 5;
goto LABEL_27;
case 47:
v0 = 18;
v2 = 5;
goto LABEL_27;
case 59:
v0 = 21;
v2 = 5;
goto LABEL_27;
case 60:
v0 = 14;
v2 = 5;
goto LABEL_27;
case 61:
v0 = 13;
v2 = 5;
goto LABEL_27;
default:
v0 = 1;
v2 = 5;
goto LABEL_27;
}
}
}
}
else if ( !_bittest64(&v3, v4) )
{
v0 = 1;
v2 = 5;
goto LABEL_27;
}
break;
case 1u:
if ( (_DWORD)v4 == 61 )
{
v0 = 12;
v2 = 5;
goto LABEL_27;
}
unget_next_char();
v0 = 1;
v2 = 5;
break;
case 2u:
if ( (_DWORD)v4 == -1 )
{
v0 = 0;
v2 = 5;
}
else if ( (_DWORD)v4 == 125 )
{
v2 = 0;
}
break;
case 3u:
if ( is_digit(v4) )
goto LABEL_27;
unget_next_char();
v0 = 11;
v2 = 5;
break;
case 4u:
if ( is_alpha(v4) )
goto LABEL_27;
unget_next_char();
v0 = 10;
v2 = 5;
break;
default:
fprintf(listing, " [Error] lex BUG, current state = %d\n", v2);
v0 = 1;
v2 = 5;
LABEL_27:
token_string[v1++] = v4;
break;
}
}
while ( v2 != 5 );
token_string[v1] = 0;
if ( v0 == 10 )
v0 = reserved_lookup(token_string);
return v0;
}

canonical_decompiled_code:
__int64 __fastcall func5()
{
unsigned int v0; // er13
int v1; // er12
unsigned int v2; // ebp
__int64 v3; // r14
unsigned __int64 v4; // rbx

v1 = 0;
v2 = 0;
v3 = 0x100002600LL;
do
{
v4 = (unsigned int)func3();
switch ( v2 )
{
case 0u:
if ( func1(v4) )
{
v2 = 3;
goto LABEL_27;
}
v2 = func2(v4);
if ( v2 )
{
v2 = 4;
goto LABEL_27;
}
if ( (unsigned int)v4 > 0x20 )
{
v2 = 1;
if ( (_DWORD)v4 != 58 )
{
v2 = 2;
if ( (_DWORD)v4 != 123 )
{
switch ( (int)v4 )
{
case -1:
v0 = 0;
v2 = 5;
break;
case 40:
v0 = 19;
v2 = 5;
goto LABEL_27;
case 41:
v0 = 20;
v2 = 5;
goto LABEL_27;
case 42:
v0 = 17;
v2 = 5;
goto LABEL_27;
case 43:
v0 = 15;
v2 = 5;
goto LABEL_27;
case 45:
v0 = 16;
v2 = 5;
goto LABEL_27;
case 47:
v0 = 18;
v2 = 5;
goto LABEL_27;
case 59:
v0 = 21;
v2 = 5;
goto LABEL_27;
case 60:
v0 = 14;
v2 = 5;
goto LABEL_27;
case 61:
v0 = 13;
v2 = 5;
goto LABEL_27;
default:
v0 = 1;
v2 = 5;
goto LABEL_27;
}
}
}
}
else if ( !_bittest64(&v3, v4) )
{
v0 = 1;
v2 = 5;
goto LABEL_27;
}
break;
case 1u:
if ( (_DWORD)v4 == 61 )
{
v0 = 12;
v2 = 5;
goto LABEL_27;
}
func0();
v0 = 1;
v2 = 5;
break;
case 2u:
if ( (_DWORD)v4 == -1 )
{
v0 = 0;
v2 = 5;
}
else if ( (_DWORD)v4 == 125 )
{
v2 = 0;
}
break;
case 3u:
if ( func1(v4) )
goto LABEL_27;
func0();
v0 = 11;
v2 = 5;
break;
case 4u:
if ( func2(v4) )
goto LABEL_27;
func0();
v0 = 10;
v2 = 5;
break;
default:
fprintf(listing, " [Error] lex BUG, current state = %d\n", v2);
v0 = 1;
v2 = 5;
LABEL_27:
token_string[v1++] = v4;
break;
}
}
while ( v2 != 5 );
token_string[v1] = 0;
if ( v0 == 10 )
v0 = func4(token_string);
return v0;
}

original_code:
TokenType get_token(void) {
 int state = START;
 int token_string_pos = 0;
 TokenType current_token;
 int save;
 while (state != DONE) {
  int c = get_next_char();
  save = 1;
  switch (state) {
   case START:
    if (_is_digit((char)c))
     state = INNUM;
    else if (_is_alpha((char)c))
     state = INID;
    else if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
     save = 0;
    else if (c == ':') {
     save = 0;
     state = INASSIGN;
    }
    else if (c == '{') {
     save = 0;
     state = INCOMMENT;
    }
    else {
     state = DONE;
     switch (c) {
      case '+': current_token = PLUS; break;
      case '-': current_token = MINUS; break;
      case '*': current_token = TIMES; break;
      case '/': current_token = OVER; break;
      case '=': current_token = EQ; break;
      case '<': current_token = LT; break;
      case '(': current_token = LPAREN; break;
      case ')': current_token = RPAREN; break;
      case ';': current_token = SEMI; break;
      case (-1):
       save = 0;
       current_token = ENDFILE;
       break;
      default :
       current_token = ERROR;
       break;
     }
    }
    break;
   case INCOMMENT:
    save = 0;
    if (c == (-1)) {
     state = DONE;
     current_token = ENDFILE;
    }else if (c == '}')
     state = START;
    break;
   case INASSIGN:
    state = DONE;
    if (c == '=')
     current_token = ASSIGN;
    else {
     unget_next_char();
     save = 0;
     current_token = ERROR;
    }
    break;
   case INNUM:
    if (!_is_digit(c)) {
     unget_next_char();
     save = 0;
     state = DONE;
     current_token = NUM;
    }
    break;
   case INID:
    if (!_is_alpha(c)) {
     unget_next_char();
     save = 0;
     state = DONE;
     current_token = ID;
    }
    break;
   case DONE :
   default :
    fprintf(listing, " [Error] lex BUG, current state = %d\n", state);
    state = DONE;
    current_token = ERROR;
    break;
  }
  if (save) {
   token_string[token_string_pos++] = (char)c;
  }
 }
 token_string[token_string_pos] = '\0';
 if (current_token == ID) {
  current_token = _reserved_lookup(token_string);
 }
 return current_token;
}

canonical_original_code:
enum TokenType get_token() {
 int state = START;
 int token_string_pos = 0;
 enum TokenType current_token;
 int save;
 while (state != DONE) {
  int c = get_next_char();
  save = 1;
  switch (state) {
   case START:
    if (_is_digit((char)c))
     state = INNUM;
    else if (_is_alpha((char)c))
     state = INID;
    else if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
     save = 0;
    else if (c == ':') {
     save = 0;
     state = INASSIGN;
    }
    else if (c == '{') {
     save = 0;
     state = INCOMMENT;
    }
    else {
     state = DONE;
     switch (c) {
      case '+': current_token = PLUS; break;
      case '-': current_token = MINUS; break;
      case '*': current_token = TIMES; break;
      case '/': current_token = OVER; break;
      case '=': current_token = EQ; break;
      case '<': current_token = LT; break;
      case '(': current_token = LPAREN; break;
      case ')': current_token = RPAREN; break;
      case ';': current_token = SEMI; break;
      case (-1):
       save = 0;
       current_token = ENDFILE;
       break;
      default :
       current_token = ERROR;
       break;
     }
    }
    break;
   case INCOMMENT:
    save = 0;
    if (c == (-1)) {
     state = DONE;
     current_token = ENDFILE;
    }else if (c == '}')
     state = START;
    break;
   case INASSIGN:
    state = DONE;
    if (c == '=')
     current_token = ASSIGN;
    else {
     unget_next_char();
     save = 0;
     current_token = ERROR;
    }
    break;
   case INNUM:
    if (!_is_digit(c)) {
     unget_next_char();
     save = 0;
     state = DONE;
     current_token = NUM;
    }
    break;
   case INID:
    if (!_is_alpha(c)) {
     unget_next_char();
     save = 0;
     state = DONE;
     current_token = ID;
    }
    break;
   case DONE :
   default :
    fprintf(listing, " [Error] lex BUG, current state = %d\n", state);
    state = DONE;
    current_token = ERROR;
    break;
  }
  if (save) {
   token_string[token_string_pos++] = (char)c;
  }
 }
 token_string[token_string_pos] = '\0';
 if (current_token == ID) {
  current_token = _reserved_lookup(token_string);
 }
 return current_token;
}

variable_types: state int

variable_types: save int

variable_types: c int

return_type: enum TokenType { ENDFILE=0, ERROR=1, IF=2, THEN=3, ELSE=4, END=5, REPEAT=6, UNTIL=7, READ=8, WRITE=9, ID=10, NUM=11, ASSIGN=12, EQ=13, LT=14, PLUS=15, MINUS=16, TIMES=17, OVER=18, LPAREN=19, RPAREN=20, SEMI=21 }


addCombination

decompiled_code:
__int64 __fastcall addCombination(int a1, int a2, int a3)
{
int v3; // er9
int v4; // eax
int v5; // eax
int *v6; // rax
__int64 v7; // rcx
__int64 result; // rax
int v9; // [rsp+0h] [rbp-Ch]
int v10; // [rsp+4h] [rbp-8h]
int v11; // [rsp+8h] [rbp-4h]

if ( a1 == a3 || a1 == a2 || a2 == a3 )
return 0LL;
v3 = s_numCombinations;
v9 = a1;
v10 = a2;
v11 = a3;
if ( a1 > a2 )
{
v9 = a2;
v10 = a1;
}
v4 = v9;
if ( a3 < v9 )
{
v9 = a3;
v11 = v4;
}
v5 = v10;
if ( v10 > v11 )
{
v10 = v11;
v11 = v5;
}
if ( s_numCombinations <= 0 )
{
LABEL_11:
v7 = 5LL * s_numCombinations;
s_combinations[v7] = v9;
dword_404064[v7] = v10;
dword_404068[v7] = v11;
dword_40406C[v7] = 0;
dword_404070[v7] = 0;
s_numCombinations = v3 + 1;
result = 1LL;
}
else
{
v6 = s_combinations;
while ( v9 != *v6 || v10 != v6[1] || v6[2] != v11 )
{
v6 += 5;
if ( (int *)((char *)&unk_404074 + 20 * (unsigned int)(s_numCombinations - 1)) == v6 )
goto LABEL_11;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, int a3)
{
int v3; // er9
int v4; // eax
int v5; // eax
int *v6; // rax
__int64 v7; // rcx
__int64 result; // rax
int v9; // [rsp+0h] [rbp-Ch]
int v10; // [rsp+4h] [rbp-8h]
int v11; // [rsp+8h] [rbp-4h]

if ( a1 == a3 || a1 == a2 || a2 == a3 )
return 0LL;
v3 = s_numCombinations;
v9 = a1;
v10 = a2;
v11 = a3;
if ( a1 > a2 )
{
v9 = a2;
v10 = a1;
}
v4 = v9;
if ( a3 < v9 )
{
v9 = a3;
v11 = v4;
}
v5 = v10;
if ( v10 > v11 )
{
v10 = v11;
v11 = v5;
}
if ( s_numCombinations <= 0 )
{
LABEL_11:
v7 = 5LL * s_numCombinations;
s_combinations[v7] = v9;
dword_404064[v7] = v10;
dword_404068[v7] = v11;
dword_40406C[v7] = 0;
dword_404070[v7] = 0;
s_numCombinations = v3 + 1;
result = 1LL;
}
else
{
v6 = s_combinations;
while ( v9 != *v6 || v10 != v6[1] || v6[2] != v11 )
{
v6 += 5;
if ( (int *)((char *)&unk_404074 + 20 * (unsigned int)(s_numCombinations - 1)) == v6 )
goto LABEL_11;
}
result = 0LL;
}
return result;
}

original_code:
static int addCombination(const int a, const int b, const int c)
{
 int i;
 const int numCombinations = s_numCombinations;
 Combination* const pNewCombination = &s_combinations[numCombinations];
 int rolls[3];
 if ((a == b) || (a == c) || (b == c))
 {
  return 0;
 }
 rolls[0] = a;
 rolls[1] = b;
 rolls[2] = c;
 for (i = 0; i < 2; i++)
 {
  int j;
  for (j = i+1; j < 3; j++)
  {
   const int rollI = rolls[i];
   const int rollJ = rolls[j];
   if (rollJ < rollI)
   {
    const int temp = rollI;
    rolls[i] = rollJ;
    rolls[j] = temp;
   }
  }
 }
 for (i = 0; i < numCombinations; i++)
 {
  const Combination* const pCombination = &s_combinations[i];
  int roll;
  int match = 1;
  for (roll = 0; roll < 3; roll++)
  {
   if (pCombination->m_roll[roll] != rolls[roll])
   {
    match = 0;
    break;
   }
  }
  if (match == 1)
  {
   return 0;
  }
 }
 pNewCombination->m_roll[0] = rolls[0];
 pNewCombination->m_roll[1] = rolls[1];
 pNewCombination->m_roll[2] = rolls[2];
 pNewCombination->m_count = 0;
 pNewCombination->m_delta = 0;
 s_numCombinations++;
 return 1;
}

canonical_original_code:
static int addCombination(int a, int b, int c)
{
 int i;
 int numCombinations = s_numCombinations;
 struct Combination *pNewCombination = &s_combinations[numCombinations];
 int rolls[3];
 if ((a == b) || (a == c) || (b == c))
 {
  return 0;
 }
 rolls[0] = a;
 rolls[1] = b;
 rolls[2] = c;
 for (i = 0; i < 2; i++)
 {
  int j;
  for (j = i+1; j < 3; j++)
  {
   int rollI = rolls[i];
   int rollJ = rolls[j];
   if (rollJ < rollI)
   {
    int temp = rollI;
    rolls[i] = rollJ;
    rolls[j] = temp;
   }
  }
 }
 for (i = 0; i < numCombinations; i++)
 {
  struct Combination *pCombination = &s_combinations[i];
  int roll;
  int match = 1;
  for (roll = 0; roll < 3; roll++)
  {
   if (pCombination->m_roll[roll] != rolls[roll])
   {
    match = 0;
    break;
   }
  }
  if (match == 1)
  {
   return 0;
  }
 }
 pNewCombination->m_roll[0] = rolls[0];
 pNewCombination->m_roll[1] = rolls[1];
 pNewCombination->m_roll[2] = rolls[2];
 pNewCombination->m_count = 0;
 pNewCombination->m_delta = 0;
 s_numCombinations++;
 return 1;
}

variable_types: a int

variable_types: b int

variable_types: numCombinations int

variable_types: struct Combination { int m_roll[3]; int m_count; int m_delta; } *

variable_types:
rolls
int [3]

variable_types: j int

variable_types: rollI int

variable_types: rollJ int

variable_types: temp int

variable_types: roll int

variable_types: match int


addRollToCombinations

decompiled_code:
void __fastcall addRollToCombinations(int a1)
{
int v1; // edx
int *v2; // rax

v1 = s_numCombinations;
if ( s_numCombinations > 0 )
{
v2 = s_combinations;
do
{
if ( *v2 == a1 || v2[1] == a1 || v2[2] == a1 )
v2[4] = 1;
v2 += 5;
}
while ( v2 != (int *)((char *)&unk_404074 + 20 * (unsigned int)(v1 - 1)) );
}
}

canonical_decompiled_code:
void __fastcall func9(int a1)
{
int v1; // edx
int *v2; // rax

v1 = s_numCombinations;
if ( s_numCombinations > 0 )
{
v2 = s_combinations;
do
{
if ( *v2 == a1 || v2[1] == a1 || v2[2] == a1 )
v2[4] = 1;
v2 += 5;
}
while ( v2 != (int *)((char *)&unk_404074 + 20 * (unsigned int)(v1 - 1)) );
}
}

original_code:
static void addRollToCombinations(const int roll)
{
 const int numCombinations = s_numCombinations;
 int i;
 for (i = 0; i < numCombinations; i++)
 {
  const Combination* const pCombination = &s_combinations[i];
  const int* const pRolls = pCombination->m_roll;
  if ((pRolls[0] == roll) || (pRolls[1] == roll) || (pRolls[2] == roll))
  {
   s_combinations[i].m_delta = 1;
  }
 }
}

canonical_original_code:
static void addRollToCombinations(int roll)
{
 int numCombinations = s_numCombinations;
 int i;
 for (i = 0; i < numCombinations; i++)
 {
  struct Combination *pCombination = &s_combinations[i];
  int *pRolls = pCombination->m_roll;
  if ((pRolls[0] == roll) || (pRolls[1] == roll) || (pRolls[2] == roll))
  {
   s_combinations[i].m_delta = 1;
  }
 }
}

variable_types: i int

variable_types:
pRolls
int *

user_defined_types: struct Combination { int m_roll[3]; int m_count; int m_delta; }


updateCombinations

decompiled_code:
__int64 updateCombinations()
{
__int64 result; // rax
__int64 v1; // rcx

result = (unsigned int)s_numCombinations;
if ( s_numCombinations > 0 )
{
v1 = 20LL * (unsigned int)s_numCombinations;
result = 0LL;
do
{
*(int *)((char *)dword_40406C + result) += *(int *)((char *)dword_404070 + result);
*(int *)((char *)dword_404070 + result) = 0;
result += 20LL;
}
while ( result != v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
__int64 v1; // rcx

result = (unsigned int)s_numCombinations;
if ( s_numCombinations > 0 )
{
v1 = 20LL * (unsigned int)s_numCombinations;
result = 0LL;
do
{
*(int *)((char *)dword_40406C + result) += *(int *)((char *)dword_404070 + result);
*(int *)((char *)dword_404070 + result) = 0;
result += 20LL;
}
while ( result != v1 );
}
return result;
}

original_code:
static void updateCombinations(void)
{
 const int numCombinations = s_numCombinations;
 int i;
 for (i = 0; i < numCombinations; i++)
 {
  Combination* const pCombination = &s_combinations[i];
  pCombination->m_count += pCombination->m_delta;
  pCombination->m_delta = 0;
 }
}

canonical_original_code:
static void updateCombinations()
{
 int numCombinations = s_numCombinations;
 int i;
 for (i = 0; i < numCombinations; i++)
 {
  struct Combination *pCombination = &s_combinations[i];
  pCombination->m_count += pCombination->m_delta;
  pCombination->m_delta = 0;
 }
}


makeCombinations

decompiled_code:
__int64 makeCombinations()
{
int v0; // er13
unsigned int v1; // ebp
int i; // er12
int v3; // ebx

v0 = 2;
v1 = 0;
while ( 1 )
{
if ( v0 + 1 <= 11 )
{
for ( i = v0 + 1; ; ++i )
{
if ( i + 1 <= 12 )
{
v3 = i + 1;
do
v1 += addCombination(v0, i, v3++);
while ( v3 != 13 );
if ( i == 11 )
break;
}
}
if ( v0 == 10 )
break;
}
++v0;
}
return v1;
}

original_code:
static int makeCombinations(void)
{
 int numComb = 0;
 int i;
 for (i = (2); i <= (12)-2; i++)
 {
  int j;
  for (j = i+1; j <= (12)-1; j++)
  {
   int k;
   for (k = j+1; k <= (12); k++)
   {
    numComb += addCombination(i, j, k);
   }
  }
 }
 return numComb;
}

canonical_original_code:
static int makeCombinations()
{
 int numComb = 0;
 int i;
 for (i = (2); i <= (12)-2; i++)
 {
  int j;
  for (j = i+1; j <= (12)-1; j++)
  {
   int k;
   for (k = j+1; k <= (12); k++)
   {
    numComb += addCombination(i, j, k);
   }
  }
 }
 return numComb;
}

variable_types: numComb int

variable_types: k int


printRolls

decompiled_code:
int printRolls()
{
__int64 i; // rbx
float v1; // xmm0_4
int result; // eax

printf("numRolls = %d\n", (unsigned int)s_nRolls);
for ( i = 2LL; i != 13; ++i )
{
v1 = (double)s_rolls[i] / (double)s_nRolls * 100.0;
result = printf("%d = %3.1f\n", (unsigned int)i, v1);
}
return result;
}

canonical_decompiled_code:
int func12()
{
__int64 i; // rbx
float v1; // xmm0_4
int result; // eax

printf("numRolls = %d\n", (unsigned int)s_nRolls);
for ( i = 2LL; i != 13; ++i )
{
v1 = (double)s_rolls[i] / (double)s_nRolls * 100.0;
result = printf("%d = %3.1f\n", (unsigned int)i, v1);
}
return result;
}

original_code:
static void printRolls(void)
{
 int i;
 printf("numRolls = %d\n", s_nRolls);
 for (i = (2); i <= (12); i++)
 {
  const double num = (double)(s_rolls[i]);
  const double total = (double)s_nRolls;
  const double ratio = num/total;
  const float pc = (float)(100.0*ratio);
  printf("%d = %3.1f\n", i, pc);
 }
}

canonical_original_code:
static void printRolls()
{
 int i;
 printf("numRolls = %d\n", s_nRolls);
 for (i = (2); i <= (12); i++)
 {
  double num = (double)(s_rolls[i]);
  double total = (double)s_nRolls;
  double ratio = num/total;
  float pc = (float)(100.0*ratio);
  printf("%d = %3.1f\n", i, pc);
 }
}

variable_types: num double

variable_types: total double

variable_types: ratio double

variable_types: pc float


printCombinations

decompiled_code:
int printCombinations()
{
int result; // eax
unsigned int *v1; // rbx
unsigned int *v2; // rbp
float v3; // xmm0_4

result = s_numCombinations;
if ( s_numCombinations > 0 )
{
v1 = (unsigned int *)s_combinations;
v2 = (unsigned int *)((char *)&unk_404074 + 20 * (unsigned int)(s_numCombinations - 1));
do
{
result = v1[3];
if ( result )
{
v3 = (double)result / (double)s_nRolls * 100.0;
result = printf("%d, %d, %d = %3.1f\n", *v1, v1[1], v1[2], v3);
}
v1 += 5;
}
while ( v1 != v2 );
}
return result;
}

canonical_decompiled_code:
int func13()
{
int result; // eax
unsigned int *v1; // rbx
unsigned int *v2; // rbp
float v3; // xmm0_4

result = s_numCombinations;
if ( s_numCombinations > 0 )
{
v1 = (unsigned int *)s_combinations;
v2 = (unsigned int *)((char *)&unk_404074 + 20 * (unsigned int)(s_numCombinations - 1));
do
{
result = v1[3];
if ( result )
{
v3 = (double)result / (double)s_nRolls * 100.0;
result = printf("%d, %d, %d = %3.1f\n", *v1, v1[1], v1[2], v3);
}
v1 += 5;
}
while ( v1 != v2 );
}
return result;
}

original_code:
static void printCombinations(void)
{
 int i;
 const int numCombinations = s_numCombinations;
 for (i = 0; i < numCombinations; i++)
 {
  const Combination* const pCombination = &s_combinations[i];
  if (pCombination->m_count != 0)
  {
   const double num = (double)(pCombination->m_count);
   const double total = (double)s_nRolls;
   const double ratio = num/total;
   const float pc = (float)(100.0*ratio);
   printf("%d, %d, %d = %3.1f\n", pCombination->m_roll[0], pCombination->m_roll[1], pCombination->m_roll[2], pc);
  }
 }
}

canonical_original_code:
static void printCombinations()
{
 int i;
 int numCombinations = s_numCombinations;
 for (i = 0; i < numCombinations; i++)
 {
  struct Combination *pCombination = &s_combinations[i];
  if (pCombination->m_count != 0)
  {
   double num = (double)(pCombination->m_count);
   double total = (double)s_nRolls;
   double ratio = num/total;
   float pc = (float)(100.0*ratio);
   printf("%d, %d, %d = %3.1f\n", pCombination->m_roll[0], pCombination->m_roll[1], pCombination->m_roll[2], pc);
  }
 }
}

variable_types: numCombinations int


rollDice

decompiled_code:
__int64 rollDice()
{
return (unsigned int)(rand() % 6 + 1);
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)(rand() % 6 + 1);
}

original_code:
static int rollDice(void)
{
 const int r = rand();
 const int dice = (r%6) + 1;
 return dice;
}

canonical_original_code:
static int rollDice()
{
 int r = rand();
 int dice = (r%6) + 1;
 return dice;
}

variable_types: r int

variable_types: dice int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rax
int *v4; // rbx
int i; // er15
int *v6; // rbp
int *v7; // r12
int v8; // ebx
int v9; // er12
int v10; // ebp
int v11; // ebx
int v12; // eax
int v13; // er13
int v14; // er14
int v15; // er11
int v16; // edi
int v17; // edx
bool v18; // r8
bool v19; // r10
bool v20; // al
int v22; // [rsp+Ch] [rbp-5Ch]
int v23; // [rsp+10h] [rbp-58h] BYREF
int v24[21]; // [rsp+14h] [rbp-54h] BYREF

printf("argc %d argv[0] '%s'\n", (unsigned int)argc, *argv);
v3 = s_rolls;
do
*v3++ = 0;
while ( v3 != (int *)&unk_4090B4 );
s_nRolls = 0;
v4 = s_combinations;
do
{
combinationInit(v4);
v4 += 5;
}
while ( v4 != &s_numCombinations );
s_numCombinations = 0;
s_numCombinations = makeCombinations();
printf("numCombinations %d\n", (unsigned int)s_numCombinations);
printCombinations();
for ( i = 0; i != 0x40000000; ++i )
{
v9 = rollDice();
v10 = rollDice();
v11 = rollDice();
v12 = rollDice();
v13 = v9 + v12;
v14 = v10 + v11;
v15 = v10 + v12;
v22 = v11 + v12;
v23 = v9 + v10;
v16 = v9 + v11;
v17 = 2;
if ( v10 == v11 )
{
v16 = v24[0];
v17 = 1;
}
v24[0] = v16;
v18 = v10 != v12;
v19 = v11 != v12;
if ( v10 != v12 && v11 != v12 )
*(&v23 + v17++) = v13;
if ( v9 != v10 && v9 != v11 && v13 != v14 )
*(&v23 + v17++) = v14;
v20 = v9 != v12;
if ( v9 + v11 != v15 && v20 && v19 && v9 != v10 )
*(&v23 + v17++) = v15;
if ( v9 + v10 != v22 && v20 && v9 != v11 && v18 && v10 != v11 )
*(&v23 + v17++) = v22;
v6 = &v23;
v7 = &v24[v17 - 1];
do
{
v8 = *v6;
addRollToCombinations(*v6);
++s_rolls[v8];
++v6;
}
while ( v6 != v7 );
updateCombinations();
++s_nRolls;
if ( (i & 0xFFFFF) == 0 )
{
printRolls();
printCombinations();
printf("numRolls %d\n", (unsigned int)s_nRolls);
}
}
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 int i;
 int count;
 printf("argc %d argv[0] '%s'\n", argc, argv[0]);
 for (i = 0; i < (12)+1; i++)
 {
  s_rolls[i] = 0;
 }
 s_nRolls = 0;
 for (i = 0; i < (1024); i++)
 {
  combinationInit(&s_combinations[i]);
 }
 s_numCombinations = 0;
 s_numCombinations = makeCombinations();
 printf("numCombinations %d\n", s_numCombinations);
 printCombinations();
 count = 0;
 do
 {
  int rollsToAdd[6];
  int placeToAdd;
  const int d1 = rollDice();
  const int d2 = rollDice();
  const int d3 = rollDice();
  const int d4 = rollDice();
  const int opt1 = d1 + d2;
  const int opt2 = d1 + d3;
  const int opt3 = d1 + d4;
  const int opt4 = d2 + d3;
  const int opt5 = d2 + d4;
  const int opt6 = d3 + d4;
  placeToAdd = 0;
  rollsToAdd[placeToAdd] = opt1;
  placeToAdd++;
  if (opt2 != opt1)
  {
   rollsToAdd[placeToAdd] = opt2;
   placeToAdd++;
  }
  if ((opt3 != opt1) && (opt3 != opt2))
  {
   rollsToAdd[placeToAdd] = opt3;
   placeToAdd++;
  }
  if ((opt4 != opt1) && (opt4 != opt2) && (opt4 != opt3))
  {
   rollsToAdd[placeToAdd] = opt4;
   placeToAdd++;
  }
  if ((opt5 != opt1) && (opt5 != opt2) && (opt5 != opt3) && (opt5 != opt4))
  {
   rollsToAdd[placeToAdd] = opt5;
   placeToAdd++;
  }
  if ((opt6 != opt1) && (opt6 != opt2) && (opt6 != opt3) && (opt6 != opt4) && (opt6 != opt5))
  {
   rollsToAdd[placeToAdd] = opt6;
   placeToAdd++;
  }
  for (i = 0; i < placeToAdd; i++)
  {
   const int roll = rollsToAdd[i];
   addRollToCombinations(roll);
   s_rolls[roll]++;
  }
  updateCombinations();
  s_nRolls++;
  if ((count % (1024*1024)) == 0)
  {
   printRolls();
   printCombinations();
   printf("numRolls %d\n", s_nRolls);
  }
  count++;
 } while (count < 1*1024*1024*1024);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i;
 int count;
 printf("argc %d argv[0] '%s'\n", argc, argv[0]);
 for (i = 0; i < (12)+1; i++)
 {
  s_rolls[i] = 0;
 }
 s_nRolls = 0;
 for (i = 0; i < (1024); i++)
 {
  combinationInit(&s_combinations[i]);
 }
 s_numCombinations = 0;
 s_numCombinations = makeCombinations();
 printf("numCombinations %d\n", s_numCombinations);
 printCombinations();
 count = 0;
 do
 {
  int rollsToAdd[6];
  int placeToAdd;
  int d1 = rollDice();
  int d2 = rollDice();
  int d3 = rollDice();
  int d4 = rollDice();
  int opt1 = d1 + d2;
  int opt2 = d1 + d3;
  int opt3 = d1 + d4;
  int opt4 = d2 + d3;
  int opt5 = d2 + d4;
  int opt6 = d3 + d4;
  placeToAdd = 0;
  rollsToAdd[placeToAdd] = opt1;
  placeToAdd++;
  if (opt2 != opt1)
  {
   rollsToAdd[placeToAdd] = opt2;
   placeToAdd++;
  }
  if ((opt3 != opt1) && (opt3 != opt2))
  {
   rollsToAdd[placeToAdd] = opt3;
   placeToAdd++;
  }
  if ((opt4 != opt1) && (opt4 != opt2) && (opt4 != opt3))
  {
   rollsToAdd[placeToAdd] = opt4;
   placeToAdd++;
  }
  if ((opt5 != opt1) && (opt5 != opt2) && (opt5 != opt3) && (opt5 != opt4))
  {
   rollsToAdd[placeToAdd] = opt5;
   placeToAdd++;
  }
  if ((opt6 != opt1) && (opt6 != opt2) && (opt6 != opt3) && (opt6 != opt4) && (opt6 != opt5))
  {
   rollsToAdd[placeToAdd] = opt6;
   placeToAdd++;
  }
  for (i = 0; i < placeToAdd; i++)
  {
   int roll = rollsToAdd[i];
   addRollToCombinations(roll);
   s_rolls[roll]++;
  }
  updateCombinations();
  s_nRolls++;
  if ((count % (1024*1024)) == 0)
  {
   printRolls();
   printCombinations();
   printf("numRolls %d\n", s_nRolls);
  }
  count++;
 } while (count < 1*1024*1024*1024);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: count int

variable_types:
rollsToAdd
int [6]

variable_types: placeToAdd int


original_code:
static void gi_Player_ComputeQSTs(gi_Player* const pThis)
{
 float level = (float)pThis->m_rawLevel;
 const float experience = pThis->m_experience;
 const float injuryFraction = ConvertInjuryToFraction(pThis->m_injury);
 float Q = (float)(pThis->m_rawQST[GI_QST_Q])/100.0f;
 float S = (float)(pThis->m_rawQST[GI_QST_S])/100.0f;
 float T = (float)(pThis->m_rawQST[GI_QST_T])/100.0f;
 level += experience;
 level *= injuryFraction;
 if (level < 1.0f)
 {
  level = 1;
 }
 Q *= level;
 S *= level;
 T *= level;
 pThis->m_level = level;
 pThis->m_QST[GI_QST_Q] = Q;
 pThis->m_QST[GI_QST_S] = S;
 pThis->m_QST[GI_QST_T] = T;
}

canonical_original_code:
static void gi_Player_ComputeQSTs(struct gi_Player *pThis)
{
 float level = (float)pThis->m_rawLevel;
 float experience = pThis->m_experience;
 float injuryFraction = ConvertInjuryToFraction(pThis->m_injury);
 float Q = (float)(pThis->m_rawQST[GI_QST_Q])/100.0f;
 float S = (float)(pThis->m_rawQST[GI_QST_S])/100.0f;
 float T = (float)(pThis->m_rawQST[GI_QST_T])/100.0f;
 level += experience;
 level *= injuryFraction;
 if (level < 1.0f)
 {
  level = 1;
 }
 Q *= level;
 S *= level;
 T *= level;
 pThis->m_level = level;
 pThis->m_QST[GI_QST_Q] = Q;
 pThis->m_QST[GI_QST_S] = S;
 pThis->m_QST[GI_QST_T] = T;
}

variable_types: struct gi_Player { char m_name[-1]; enum GI_POSITION { GI_POSITION_QB=0, GI_POSITION_RB=1, GI_POSITION_WR=2, GI_POSITION_TE=3, GI_POSITION_OC=4, GI_POSITION_OG=5, GI_POSITION_OT=6, GI_POSITION_DE=7, GI_POSITION_DT=8, GI_POSITION_IB=9, GI_POSITION_OB=10, GI_POSITION_CB=11, GI_POSITION_SF=12, GI_POSITION_R=13, GI_POSITION_K=14, GI_POSITION_P=15, GI_POSITION_SE=16, GI_POSITION_FL=17, GI_POSITION_RB1=18, GI_POSITION_RB2=19, GI_POSITION_TE1=20, GI_POSITION_TE2=21, GI_POSITION_LG=22, GI_POSITION_RG=23, GI_POSITION_LT=24, GI_POSITION_RT=25, GI_POSITION_HB=26, GI_POSITION_FB=27, GI_POSITION_FS=28, GI_POSITION_SS=29, GI_POSITION_C=30, GI_POSITION_NT=31, GI_POSITION_LE=32, GI_POSITION_RE=33, GI_POSITION_LILB=34, GI_POSITION_MILB=35, GI_POSITION_RILB=36, GI_POSITION_LOLB=37, GI_POSITION_ROLB=38, GI_POSITION_LCB=39, GI_POSITION_RCB=40, GI_POSITION_UNKNOWN=41, GI_POSITION_NUM=expr } m_position; unsigned long m_rawLevel; unsigned long m_rawQST[-1]; float m_experience; enum GI_UNIT { GI_UNIT_OFFENCE=0, GI_UNIT_DEFENCE=1, GI_UNIT_SPECIALTEAMS=2, GI_UNIT_UNKNOWN=3, GI_UNIT_NUM=expr } m_unit; unsigned long m_age; float m_level; float m_QST[-1]; enum GI_INJURY { GI_INJURY_A=0, GI_INJURY_B=1, GI_INJURY_C=2, GI_INJURY_D=3, GI_INJURY_E=4, GI_INJURY_F=5, GI_INJURY_G=6, GI_INJURY_H=7, GI_INJURY_UNKNOWN=8, GI_INJURY_NUM=expr } m_injury; } *

variable_types: level float

variable_types: experience float

variable_types: injuryFraction float

variable_types: Q float

variable_types: S float

variable_types: T float

user_defined_types: struct gi_Player { char m_name[-1]; enum GI_POSITION m_position; unsigned long m_rawLevel; unsigned long m_rawQST[-1]; float m_experience; enum GI_UNIT m_unit; unsigned long m_age; float m_level; float m_QST[-1]; enum GI_INJURY m_injury; }


original_code:
void gi_Player_Init(gi_Player* const pThis)
{
 pThis->m_name[0] = '\0';
 pThis->m_position = GI_POSITION_UNKNOWN;
 pThis->m_rawLevel = 0;
 pThis->m_rawQST[0] = 0;
 pThis->m_rawQST[1] = 0;
 pThis->m_rawQST[2] = 0;
 pThis->m_experience = 0.0f;
 pThis->m_unit = GI_UNIT_UNKNOWN;
 pThis->m_age = 0;
 pThis->m_level = 0.0f;
 pThis->m_QST[0] = 0.0f;
 pThis->m_QST[1] = 0.0f;
 pThis->m_QST[2] = 0.0f;
 pThis->m_injury = GI_INJURY_UNKNOWN;
}

canonical_original_code:
void gi_Player_Init(struct gi_Player *pThis)
{
 pThis->m_name[0] = '\0';
 pThis->m_position = GI_POSITION_UNKNOWN;
 pThis->m_rawLevel = 0;
 pThis->m_rawQST[0] = 0;
 pThis->m_rawQST[1] = 0;
 pThis->m_rawQST[2] = 0;
 pThis->m_experience = 0.0f;
 pThis->m_unit = GI_UNIT_UNKNOWN;
 pThis->m_age = 0;
 pThis->m_level = 0.0f;
 pThis->m_QST[0] = 0.0f;
 pThis->m_QST[1] = 0.0f;
 pThis->m_QST[2] = 0.0f;
 pThis->m_injury = GI_INJURY_UNKNOWN;
}

user_defined_types: enum GI_POSITION { GI_POSITION_QB=0, GI_POSITION_RB=1, GI_POSITION_WR=2, GI_POSITION_TE=3, GI_POSITION_OC=4, GI_POSITION_OG=5, GI_POSITION_OT=6, GI_POSITION_DE=7, GI_POSITION_DT=8, GI_POSITION_IB=9, GI_POSITION_OB=10, GI_POSITION_CB=11, GI_POSITION_SF=12, GI_POSITION_R=13, GI_POSITION_K=14, GI_POSITION_P=15, GI_POSITION_SE=16, GI_POSITION_FL=17, GI_POSITION_RB1=18, GI_POSITION_RB2=19, GI_POSITION_TE1=20, GI_POSITION_TE2=21, GI_POSITION_LG=22, GI_POSITION_RG=23, GI_POSITION_LT=24, GI_POSITION_RT=25, GI_POSITION_HB=26, GI_POSITION_FB=27, GI_POSITION_FS=28, GI_POSITION_SS=29, GI_POSITION_C=30, GI_POSITION_NT=31, GI_POSITION_LE=32, GI_POSITION_RE=33, GI_POSITION_LILB=34, GI_POSITION_MILB=35, GI_POSITION_RILB=36, GI_POSITION_LOLB=37, GI_POSITION_ROLB=38, GI_POSITION_LCB=39, GI_POSITION_RCB=40, GI_POSITION_UNKNOWN=41, GI_POSITION_NUM=expr }

user_defined_types: enum GI_UNIT { GI_UNIT_OFFENCE=0, GI_UNIT_DEFENCE=1, GI_UNIT_SPECIALTEAMS=2, GI_UNIT_UNKNOWN=3, GI_UNIT_NUM=expr }

user_defined_types: enum GI_INJURY { GI_INJURY_A=0, GI_INJURY_B=1, GI_INJURY_C=2, GI_INJURY_D=3, GI_INJURY_E=4, GI_INJURY_F=5, GI_INJURY_G=6, GI_INJURY_H=7, GI_INJURY_UNKNOWN=8, GI_INJURY_NUM=expr }


decompiled_code:
__int64 __fastcall gi_Player_GetName(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return a1;
}

original_code:
const char* gi_Player_GetName(const gi_Player* const pThis)
{
 return pThis->m_name;
}

canonical_original_code:
char *gi_Player_GetName(struct gi_Player *pThis)
{
 return pThis->m_name;
}

return_type: char *


decompiled_code:
__int64 __fastcall gi_Player_GetPosition(__int64 a1)
{
return *(unsigned int *)(a1 + 128);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned int *)(a1 + 128);
}

original_code:
GI_POSITION gi_Player_GetPosition(const gi_Player* const pThis)
{
 return pThis->m_position;
}

canonical_original_code:
enum GI_POSITION gi_Player_GetPosition(struct gi_Player *pThis)
{
 return pThis->m_position;
}

return_type: enum GI_POSITION { GI_POSITION_QB=0, GI_POSITION_RB=1, GI_POSITION_WR=2, GI_POSITION_TE=3, GI_POSITION_OC=4, GI_POSITION_OG=5, GI_POSITION_OT=6, GI_POSITION_DE=7, GI_POSITION_DT=8, GI_POSITION_IB=9, GI_POSITION_OB=10, GI_POSITION_CB=11, GI_POSITION_SF=12, GI_POSITION_R=13, GI_POSITION_K=14, GI_POSITION_P=15, GI_POSITION_SE=16, GI_POSITION_FL=17, GI_POSITION_RB1=18, GI_POSITION_RB2=19, GI_POSITION_TE1=20, GI_POSITION_TE2=21, GI_POSITION_LG=22, GI_POSITION_RG=23, GI_POSITION_LT=24, GI_POSITION_RT=25, GI_POSITION_HB=26, GI_POSITION_FB=27, GI_POSITION_FS=28, GI_POSITION_SS=29, GI_POSITION_C=30, GI_POSITION_NT=31, GI_POSITION_LE=32, GI_POSITION_RE=33, GI_POSITION_LILB=34, GI_POSITION_MILB=35, GI_POSITION_RILB=36, GI_POSITION_LOLB=37, GI_POSITION_ROLB=38, GI_POSITION_LCB=39, GI_POSITION_RCB=40, GI_POSITION_UNKNOWN=41, GI_POSITION_NUM=expr }


decompiled_code:
__int64 __fastcall gi_Player_GetRawLevel(__int64 a1)
{
return *(_QWORD *)(a1 + 132);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(_QWORD *)(a1 + 132);
}

original_code:
size_t gi_Player_GetRawLevel(const gi_Player* const pThis)
{
 return pThis->m_rawLevel;
}

canonical_original_code:
unsigned long gi_Player_GetRawLevel(struct gi_Player *pThis)
{
 return pThis->m_rawLevel;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall gi_Player_GetRawQST(__int64 a1)
{
return a1 + 140;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return a1 + 140;
}

original_code:
const size_t* gi_Player_GetRawQST(const gi_Player* const pThis)
{
 return pThis->m_rawQST;
}

canonical_original_code:
unsigned long *gi_Player_GetRawQST(struct gi_Player *pThis)
{
 return pThis->m_rawQST;
}

return_type: unsigned long *


decompiled_code:
float __fastcall gi_Player_GetExperience(__int64 a1)
{
return *(float *)(a1 + 180);
}

canonical_decompiled_code:
float __fastcall func10(__int64 a1)
{
return *(float *)(a1 + 180);
}

original_code:
float gi_Player_GetExperience(const gi_Player* const pThis)
{
 return pThis->m_experience;
}

canonical_original_code:
float gi_Player_GetExperience(struct gi_Player *pThis)
{
 return pThis->m_experience;
}

return_type: float


decompiled_code:
__int64 __fastcall gi_Player_GetUnit(__int64 a1)
{
return *(unsigned int *)(a1 + 184);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(unsigned int *)(a1 + 184);
}

original_code:
GI_UNIT gi_Player_GetUnit(const gi_Player* const pThis)
{
 return pThis->m_unit;
}

canonical_original_code:
enum GI_UNIT gi_Player_GetUnit(struct gi_Player *pThis)
{
 return pThis->m_unit;
}

return_type: enum GI_UNIT { GI_UNIT_OFFENCE=0, GI_UNIT_DEFENCE=1, GI_UNIT_SPECIALTEAMS=2, GI_UNIT_UNKNOWN=3, GI_UNIT_NUM=expr }


decompiled_code:
__int64 __fastcall gi_Player_GetAge(__int64 a1)
{
return *(_QWORD *)(a1 + 188);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(_QWORD *)(a1 + 188);
}

original_code:
size_t gi_Player_GetAge(const gi_Player* const pThis)
{
 return pThis->m_age;
}

canonical_original_code:
unsigned long gi_Player_GetAge(struct gi_Player *pThis)
{
 return pThis->m_age;
}


decompiled_code:
float __fastcall gi_Player_GetLevel(__int64 a1)
{
return *(float *)(a1 + 196);
}

canonical_decompiled_code:
float __fastcall func13(__int64 a1)
{
return *(float *)(a1 + 196);
}

original_code:
float gi_Player_GetLevel(const gi_Player* const pThis)
{
 return pThis->m_level;
}

canonical_original_code:
float gi_Player_GetLevel(struct gi_Player *pThis)
{
 return pThis->m_level;
}


decompiled_code:
__int64 __fastcall gi_Player_GetQST(__int64 a1)
{
return a1 + 200;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return a1 + 200;
}

original_code:
const float* gi_Player_GetQST(const gi_Player* const pThis)
{
 return pThis->m_QST;
}

canonical_original_code:
float *gi_Player_GetQST(struct gi_Player *pThis)
{
 return pThis->m_QST;
}

return_type: float *


decompiled_code:
__int64 __fastcall gi_Player_GetInjury(__int64 a1)
{
return *(unsigned int *)(a1 + 220);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return *(unsigned int *)(a1 + 220);
}

original_code:
GI_INJURY gi_Player_GetInjury(const gi_Player* const pThis)
{
 return pThis->m_injury;
}

canonical_original_code:
enum GI_INJURY gi_Player_GetInjury(struct gi_Player *pThis)
{
 return pThis->m_injury;
}

return_type: enum GI_INJURY { GI_INJURY_A=0, GI_INJURY_B=1, GI_INJURY_C=2, GI_INJURY_D=3, GI_INJURY_E=4, GI_INJURY_F=5, GI_INJURY_G=6, GI_INJURY_H=7, GI_INJURY_UNKNOWN=8, GI_INJURY_NUM=expr }


decompiled_code:
__int64 __fastcall gi_Player_GetPositionName(__int64 a1)
{
return gi_GetPositionName(*(unsigned int *)(a1 + 128));
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return gi_GetPositionName(*(unsigned int *)(a1 + 128));
}

original_code:
const char* gi_Player_GetPositionName(const gi_Player* const pThis)
{
 return gi_GetPositionName(pThis->m_position);
}

canonical_original_code:
char *gi_Player_GetPositionName(struct gi_Player *pThis)
{
 return gi_GetPositionName(pThis->m_position);
}


decompiled_code:
void __fastcall gi_Player_SetInjury(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 220) = a2;
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 220) = a2;
}

original_code:
void gi_Player_SetInjury(gi_Player* const pThis, const GI_INJURY injury)
{
 pThis->m_injury = injury;
}

canonical_original_code:
void gi_Player_SetInjury(struct gi_Player *pThis, enum GI_INJURY injury)
{
 pThis->m_injury = injury;
}

variable_types: enum GI_INJURY { GI_INJURY_A=0, GI_INJURY_B=1, GI_INJURY_C=2, GI_INJURY_D=3, GI_INJURY_E=4, GI_INJURY_F=5, GI_INJURY_G=6, GI_INJURY_H=7, GI_INJURY_UNKNOWN=8, GI_INJURY_NUM=expr }


original_code:
float gi_Player_GetSpecialTeamsLevelQST(const gi_Player* const pThis, float* const pQ, float* const pS, float* const pT)
{
 const GI_POSITION position = pThis->m_position;
 const float injuryFraction = ConvertInjuryToFraction(pThis->m_injury);
 float level = (float)(pThis->m_rawLevel);
 float experience = pThis->m_experience;
 float Q = (float)(pThis->m_rawQST[GI_QST_Q])/100.0f;
 float S = (float)(pThis->m_rawQST[GI_QST_S])/100.0f;
 float T = (float)(pThis->m_rawQST[GI_QST_T])/100.0f;
 switch (position)
 {
  case GI_POSITION_R:
  case GI_POSITION_K:
  case GI_POSITION_P:
   experience = 0.0f;
   break;
  default:
   break;
 };
 level += experience;
 level *= injuryFraction;
 if (level > 10.0f)
 {
  level = 10.0f+((level-10.0f)*0.2f);
 }
 if (level < 1.0f)
 {
  level = 1;
 }
 Q *= level;
 S *= level;
 T *= level;
 *pQ = Q;
 *pS = S;
 *pT = T;
 return level;
}

canonical_original_code:
float gi_Player_GetSpecialTeamsLevelQST(struct gi_Player *pThis, float *pQ, float *pS, float *pT)
{
 enum GI_POSITION position = pThis->m_position;
 float injuryFraction = ConvertInjuryToFraction(pThis->m_injury);
 float level = (float)(pThis->m_rawLevel);
 float experience = pThis->m_experience;
 float Q = (float)(pThis->m_rawQST[GI_QST_Q])/100.0f;
 float S = (float)(pThis->m_rawQST[GI_QST_S])/100.0f;
 float T = (float)(pThis->m_rawQST[GI_QST_T])/100.0f;
 switch (position)
 {
  case GI_POSITION_R:
  case GI_POSITION_K:
  case GI_POSITION_P:
   experience = 0.0f;
   break;
  default:
   break;
 };
 level += experience;
 level *= injuryFraction;
 if (level > 10.0f)
 {
  level = 10.0f+((level-10.0f)*0.2f);
 }
 if (level < 1.0f)
 {
  level = 1;
 }
 Q *= level;
 S *= level;
 T *= level;
 *pQ = Q;
 *pS = S;
 *pT = T;
 return level;
}

variable_types:
pQ
float *

variable_types:
pS
float *

variable_types:
pT
float *

variable_types: enum GI_POSITION { GI_POSITION_QB=0, GI_POSITION_RB=1, GI_POSITION_WR=2, GI_POSITION_TE=3, GI_POSITION_OC=4, GI_POSITION_OG=5, GI_POSITION_OT=6, GI_POSITION_DE=7, GI_POSITION_DT=8, GI_POSITION_IB=9, GI_POSITION_OB=10, GI_POSITION_CB=11, GI_POSITION_SF=12, GI_POSITION_R=13, GI_POSITION_K=14, GI_POSITION_P=15, GI_POSITION_SE=16, GI_POSITION_FL=17, GI_POSITION_RB1=18, GI_POSITION_RB2=19, GI_POSITION_TE1=20, GI_POSITION_TE2=21, GI_POSITION_LG=22, GI_POSITION_RG=23, GI_POSITION_LT=24, GI_POSITION_RT=25, GI_POSITION_HB=26, GI_POSITION_FB=27, GI_POSITION_FS=28, GI_POSITION_SS=29, GI_POSITION_C=30, GI_POSITION_NT=31, GI_POSITION_LE=32, GI_POSITION_RE=33, GI_POSITION_LILB=34, GI_POSITION_MILB=35, GI_POSITION_RILB=36, GI_POSITION_LOLB=37, GI_POSITION_ROLB=38, GI_POSITION_LCB=39, GI_POSITION_RCB=40, GI_POSITION_UNKNOWN=41, GI_POSITION_NUM=expr }


decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
__int64 v4; // r13
__int64 v5; // rbx
__int64 v6; // r12
bool v7; // cf
bool v8; // zf
__int64 v9; // rcx

if ( argc <= 0 )
{
v6 = 0LL;
}
else
{
v3 = argv;
v4 = (unsigned int)argc;
v5 = 0LL;
v6 = 0LL;
do
{
printf("argv[%d] '%s'\n", (unsigned int)v5, v3[v5]);
argv = (const char **)v3[v5];
*(_QWORD *)&argc = "-debug";
v9 = 7LL;
do
{
if ( !v9 )
break;
v7 = *(_BYTE *)argv < **(_BYTE **)&argc;
v8 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v9;
}
while ( v8 );
if ( (!v7 && !v8) == v7 )
v6 = 1LL;
++v5;
}
while ( v5 != v4 );
}
gi_Init(*(_QWORD *)&argc, argv);
gi_LoadFile("data/london_monarchs.json", v6);
gi_LoadFile("data/offence/proset.json", v6);
gi_LoadFile("data/defence/3-4.json", 1LL);
gi_LoadFile("data/defence/3-5.json", 1LL);
gi_Compute();
gi_Output();
return -1;
}

original_code:
int main(int argc, char* argv[])
{
 size_t debug = 0;
 int i;
 for (i = 0; i < argc; i++)
 {
  printf("argv[%d] '%s'\n", i, argv[i]);
  if (strcmp(argv[i], "-debug") == 0)
  {
   debug = 1;
  }
 }
 gi_Init();
 gi_LoadFile("data/london_monarchs.json", debug);
 gi_LoadFile("data/offence/proset.json", debug);
 gi_LoadFile("data/defence/3-4.json", 1);
 gi_LoadFile("data/defence/3-5.json", 1);
 gi_Compute();
 gi_Output();
 return -1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long debug = 0;
 int i;
 for (i = 0; i < argc; i++)
 {
  printf("argv[%d] '%s'\n", i, argv[i]);
  if (strcmp(argv[i], "-debug") == 0)
  {
   debug = 1;
  }
 }
 gi_Init();
 gi_LoadFile("data/london_monarchs.json", debug);
 gi_LoadFile("data/offence/proset.json", debug);
 gi_LoadFile("data/defence/3-4.json", 1);
 gi_LoadFile("data/defence/3-5.json", 1);
 gi_Compute();
 gi_Output();
 return -1;
}

variable_types: argc int

variable_types:
debug
unsigned long

variable_types: i int


decompiled_code:
void gi_Logger_Shutdown()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void gi_Logger_Shutdown(void)
{
}

canonical_original_code:
void gi_Logger_Shutdown()
{
}


decompiled_code:
__int64 gi_Logger_GetErrorStatus()
{
return (unsigned int)s_errorFlag;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)s_errorFlag;
}

original_code:
GI_BOOL gi_Logger_GetErrorStatus(void)
{
 return s_errorFlag;
}

canonical_original_code:
enum GI_BOOL gi_Logger_GetErrorStatus()
{
 return s_errorFlag;
}

return_type: enum GI_BOOL { GI_TRUE=0, GI_FALSE=1 }


decompiled_code:
void gi_Logger_ClearErrorStatus()
{
s_errorFlag = 1;
}

canonical_decompiled_code:
void func2()
{
s_errorFlag = 1;
}

original_code:
void gi_Logger_ClearErrorStatus(void)
{
 s_errorFlag = GI_FALSE;
}

canonical_original_code:
void gi_Logger_ClearErrorStatus()
{
 s_errorFlag = GI_FALSE;
}


decompiled_code:
void gi_Logger_SetErrorStatus()
{
s_errorFlag = 0;
}

canonical_decompiled_code:
void func3()
{
s_errorFlag = 0;
}

original_code:
void gi_Logger_SetErrorStatus(void)
{
 s_errorFlag = GI_TRUE;
}

canonical_original_code:
void gi_Logger_SetErrorStatus()
{
 s_errorFlag = GI_TRUE;
}


decompiled_code:
__int64 __fastcall gi_Logger_GetDefaultChannel(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 3 )
result = 0LL;
else
result = s_defaultChannels[a1];
return result;
}

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

if ( a1 > 3 )
result = 0LL;
else
result = s_defaultChannels[a1];
return result;
}

original_code:
gi_LoggerChannel* gi_Logger_GetDefaultChannel(const int channel)
{
 if ((channel < 0) || (channel >= GI_CHANNEL_NUM_DEFAULT_CHANNELS))
 {
  return ((void *)0);
 }
 return s_defaultChannels[channel];
}

canonical_original_code:
struct gi_LoggerChannel *gi_Logger_GetDefaultChannel(int channel)
{
 if ((channel < 0) || (channel >= GI_CHANNEL_NUM_DEFAULT_CHANNELS))
 {
  return ((void *)0);
 }
 return s_defaultChannels[channel];
}

variable_types: channel int

return_type: struct gi_LoggerChannel { char *m_nickName; char *m_prefixStr; char *m_outputFileName; unsigned int m_flags; } *


decompiled_code:
__int64 __fastcall gi_Logger_GetChannelFlags(unsigned int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = gi_Logger_GetDefaultChannel(a1);
result = 0LL;
if ( v1 )
result = gi_LoggerChannel_GetFlags();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = func4(a1);
result = 0LL;
if ( v1 )
result = gi_LoggerChannel_GetFlags();
return result;
}

original_code:
unsigned int gi_Logger_GetChannelFlags(const int channel)
{
 gi_LoggerChannel* const channelPtr = gi_Logger_GetDefaultChannel(channel);
 if (channelPtr)
 {
  return gi_LoggerChannel_GetFlags(channelPtr);
 }
 return 0;
}

canonical_original_code:
unsigned int gi_Logger_GetChannelFlags(int channel)
{
 struct gi_LoggerChannel *channelPtr = gi_Logger_GetDefaultChannel(channel);
 if (channelPtr)
 {
  return gi_LoggerChannel_GetFlags(channelPtr);
 }
 return 0;
}

variable_types: struct gi_LoggerChannel { char *m_nickName; char *m_prefixStr; char *m_outputFileName; unsigned int m_flags; } *

return_type: unsigned int