infixToPostfix

decompiled_code:
void *__fastcall infixToPostfix(char *a1)
{
unsigned int v1; // eax
char v2; // r14
unsigned int v3; // ebp
int v4; // ebx
char v5; // al
int v6; // eax
int v7; // edx
char v8; // al
char v9; // al
const char *v10; // r13
size_t v11; // r14
void *v12; // r12
char v14; // al

v1 = initializeCharBuffer();
v2 = *a1;
v3 = v1;
if ( *a1 )
{
v4 = 0;
do
{
if ( (unsigned int)isOperator(v2) )
{
if ( (unsigned int)topStack() != -1 )
{
if ( v2 == 41 )
{
while ( (unsigned int)topStack() != 40 )
{
v14 = popStack();
addCharElement(v3, (unsigned int)v14);
}
popStack();
goto LABEL_5;
}
while ( (unsigned int)topStack() != -1 )
{
v5 = topStack();
getPrecedence(v5, 1);
v6 = getPrecedence(v2, 0);
if ( v7 < v6 )
break;
v8 = popStack();
addCharElement(v3, (unsigned int)v8);
}
}
pushStack((unsigned int)v2);
}
else if ( v2 == 92 )
{
++v4;
addCharElement(v3, 92LL);
addCharElement(v3, (unsigned int)a1[v4]);
}
else
{
addCharElement(v3, (unsigned int)v2);
}
LABEL_5:
v2 = a1[++v4];
}
while ( v2 );
}
while ( (unsigned int)topStack() != -1 )
{
v9 = popStack();
addCharElement(v3, (unsigned int)v9);
}
addCharElement(v3, 0LL);
v10 = (const char *)getCharBuffer(v3);
v11 = strlen(v10) + 1;
v12 = malloc(v11);
memcpy(v12, v10, v11);
destroyCharBuffer(v3);
return v12;
}

canonical_decompiled_code:
void *__fastcall func2(char *a1)
{
unsigned int v1; // eax
char v2; // r14
unsigned int v3; // ebp
int v4; // ebx
char v5; // al
int v6; // eax
int v7; // edx
char v8; // al
char v9; // al
const char *v10; // r13
size_t v11; // r14
void *v12; // r12
char v14; // al

v1 = initializeCharBuffer();
v2 = *a1;
v3 = v1;
if ( *a1 )
{
v4 = 0;
do
{
if ( (unsigned int)func0(v2) )
{
if ( (unsigned int)topStack() != -1 )
{
if ( v2 == 41 )
{
while ( (unsigned int)topStack() != 40 )
{
v14 = popStack();
addCharElement(v3, (unsigned int)v14);
}
popStack();
goto LABEL_5;
}
while ( (unsigned int)topStack() != -1 )
{
v5 = topStack();
func1(v5, 1);
v6 = func1(v2, 0);
if ( v7 < v6 )
break;
v8 = popStack();
addCharElement(v3, (unsigned int)v8);
}
}
pushStack((unsigned int)v2);
}
else if ( v2 == 92 )
{
++v4;
addCharElement(v3, 92LL);
addCharElement(v3, (unsigned int)a1[v4]);
}
else
{
addCharElement(v3, (unsigned int)v2);
}
LABEL_5:
v2 = a1[++v4];
}
while ( v2 );
}
while ( (unsigned int)topStack() != -1 )
{
v9 = popStack();
addCharElement(v3, (unsigned int)v9);
}
addCharElement(v3, 0LL);
v10 = (const char *)getCharBuffer(v3);
v11 = strlen(v10) + 1;
v12 = malloc(v11);
memcpy(v12, v10, v11);
destroyCharBuffer(v3);
return v12;
}

original_code:
char *infixToPostfix(char *origin){
 int bufferid = initializeCharBuffer();
 int pos = 0;
 char c;
 int doubleCharFlag = 0;
 while('\0' != (c = *(origin+pos))){
  if(isOperator(c)){
   if(-1 == topStack()){
    pushStack(c);
   }else{
    if(')' == c){
     while('(' != topStack()){
      addCharElement(bufferid, popStack());
     }
     popStack();
    }else{
     while(-1 != topStack() && getPrecedence(topStack(), 1) >= getPrecedence(c, 0)){
      addCharElement(bufferid, popStack());
     }
     pushStack(c);
    }
   }
  }else{
   if('\\' == c){
    addCharElement(bufferid, c);
    pos++;
    c = *(origin+pos);
    addCharElement(bufferid, c);
   }else{
    addCharElement(bufferid, c);
   }
  }
  pos++;
 }
 while(-1 != topStack()){
  addCharElement(bufferid, popStack());
 }
 addCharElement(bufferid, '\0');
 char *s = getCharBuffer(bufferid);
 char *result = malloc(strlen(s) + 1);
 strcpy(result, s);
 destroyCharBuffer(bufferid);
 return result;
}

variable_types:
origin
char *

variable_types: bufferid int

variable_types: pos int

variable_types: doubleCharFlag int

variable_types:
result
char *


destroyDFA

repo: ZeyuMi/MiLex

decompiled_code:
__int64 destroyDFA()
{
destroyDFATransTable();
return destroyDFATable();
}

canonical_decompiled_code:
__int64 func0()
{
destroyDFATransTable();
return destroyDFATable();
}

original_code:
void destroyDFA(){
 destroyDFATransTable();
 destroyDFATable();
}

return_type: void


epsilonClosure

decompiled_code:
void *__fastcall epsilonClosure(unsigned int *a1)
{
_DWORD *v1; // rbx
unsigned int v2; // eax
unsigned int v3; // ebp
unsigned int i; // er12
unsigned int v5; // eax
unsigned int *v6; // rax
unsigned int v7; // ebp
unsigned int *j; // rbx
int v9; // eax
void *v10; // r13

v1 = a1 + 1;
clearStack();
v2 = initializeIntBuffer();
v3 = *a1;
for ( i = v2; v3 != -1; v3 = *(v1 - 1) )
{
++v1;
addIntElement(i, v3);
pushStack(v3);
}
while ( 1 )
{
v5 = popStack();
if ( v5 == -1 )
break;
v6 = (unsigned int *)reachByEdgeSymbol(v5, 0xFFFFFFFFLL);
v7 = *v6;
for ( j = v6 + 1; v7 != -1; ++j )
{
if ( !(unsigned int)isInIntBuffer(i, v7) )
{
addIntElement(i, v7);
pushStack(v7);
}
v7 = *j;
}
}
addIntElement(i, 0xFFFFFFFFLL);
v9 = intSize(i);
v10 = malloc(4LL * v9);
fillIntArrayWithBuffer(i, v10);
destroyIntBuffer(i);
return v10;
}

canonical_decompiled_code:
void *__fastcall func1(unsigned int *a1)
{
_DWORD *v1; // rbx
unsigned int v2; // eax
unsigned int v3; // ebp
unsigned int i; // er12
unsigned int v5; // eax
unsigned int *v6; // rax
unsigned int v7; // ebp
unsigned int *j; // rbx
int v9; // eax
void *v10; // r13

v1 = a1 + 1;
clearStack();
v2 = initializeIntBuffer();
v3 = *a1;
for ( i = v2; v3 != -1; v3 = *(v1 - 1) )
{
++v1;
addIntElement(i, v3);
pushStack(v3);
}
while ( 1 )
{
v5 = popStack();
if ( v5 == -1 )
break;
v6 = (unsigned int *)reachByEdgeSymbol(v5, 0xFFFFFFFFLL);
v7 = *v6;
for ( j = v6 + 1; v7 != -1; ++j )
{
if ( !(unsigned int)isInIntBuffer(i, v7) )
{
addIntElement(i, v7);
pushStack(v7);
}
v7 = *j;
}
}
addIntElement(i, 0xFFFFFFFFLL);
v9 = intSize(i);
v10 = malloc(4LL * v9);
fillIntArrayWithBuffer(i, v10);
destroyIntBuffer(i);
return v10;
}

original_code:
int *epsilonClosure(int *stateSet){
 clearStack();
 int temp = -1;
 int bufferid = initializeIntBuffer();
 while(-1 != (temp = *(stateSet++))){
  addIntElement(bufferid, temp);
  pushStack(temp);
 }
 while(-1 != (temp = popStack())){
  int *reach = reachByEdgeSymbol(temp, -1);
  int tempState = -1;
  while(-1 != (tempState = *(reach++))){
   if(!isInIntBuffer(bufferid, tempState)){
    addIntElement(bufferid, tempState);
    pushStack(tempState);
   }
  }
 }
 addIntElement(bufferid, -1);
 int *result = malloc(intSize(bufferid) * sizeof(int));
 fillIntArrayWithBuffer(bufferid, result);
 destroyIntBuffer(bufferid);
 return result;
}

variable_types:
stateSet
int *

variable_types: temp int

variable_types:
reach
int *

variable_types: tempState int

variable_types:
result
int *

return_type: int *


constructDFA

decompiled_code:
__int64 constructDFA()
{
unsigned int v0; // eax
void *v1; // rbp
unsigned int v2; // er12
__int64 v3; // rax
__int64 result; // rax
unsigned int v5; // ebx
__int64 v6; // r13
unsigned int *v7; // r12
char v8; // si
unsigned int v9; // er15
unsigned int *v10; // rdi
_DWORD *v11; // rax
_DWORD *v12; // rbp
unsigned int v13; // er14
__int64 v14; // rax
unsigned int v15[16]; // [rsp+8h] [rbp-40h] BYREF

v0 = *(_DWORD *)getGraph();
v15[1] = -1;
v15[0] = v0;
v1 = epsilonClosure(v15);
v2 = installState(v1);
v3 = getAction(v1);
addDFANewState(v2, v3);
for ( result = unmarkedStatesExist(); (_DWORD)result; result = unmarkedStatesExist() )
{
v5 = 0;
v6 = (unsigned int)getUnmarkedState();
markState(v6);
v7 = (unsigned int *)getNFAStates((unsigned int)v6);
do
{
v8 = v5;
v9 = v5++;
v10 = move(v7, v8);
v11 = epsilonClosure(v10);
v12 = v11;
if ( *v11 != -1 )
{
v13 = installState(v11);
v14 = getAction(v12);
addDFANewState(v13, v14);
addDFATransTableEntry((unsigned int)v6, v13, v9);
}
}
while ( v5 != 128 );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax
void *v1; // rbp
unsigned int v2; // er12
__int64 v3; // rax
__int64 result; // rax
unsigned int v5; // ebx
__int64 v6; // r13
unsigned int *v7; // r12
char v8; // si
unsigned int v9; // er15
unsigned int *v10; // rdi
_DWORD *v11; // rax
_DWORD *v12; // rbp
unsigned int v13; // er14
__int64 v14; // rax
unsigned int v15[16]; // [rsp+8h] [rbp-40h] BYREF

v0 = *(_DWORD *)getGraph();
v15[1] = -1;
v15[0] = v0;
v1 = func1(v15);
v2 = installState(v1);
v3 = getAction(v1);
addDFANewState(v2, v3);
for ( result = unmarkedStatesExist(); (_DWORD)result; result = unmarkedStatesExist() )
{
v5 = 0;
v6 = (unsigned int)getUnmarkedState();
markState(v6);
v7 = (unsigned int *)getNFAStates((unsigned int)v6);
do
{
v8 = v5;
v9 = v5++;
v10 = move(v7, v8);
v11 = func1(v10);
v12 = v11;
if ( *v11 != -1 )
{
v13 = installState(v11);
v14 = getAction(v12);
addDFANewState(v13, v14);
addDFATransTableEntry((unsigned int)v6, v13, v9);
}
}
while ( v5 != 128 );
}
return result;
}

original_code:
void constructDFA(){
 struct vertex *graph = getGraph();
 int startPoint = graph->state;
 int firstNFAState[2] = {startPoint, -1};
 int *nfaClosure = epsilonClosure(firstNFAState);
 int dfaState = installState(nfaClosure);
 char *action = getAction(nfaClosure);
 addDFANewState(dfaState, action);
 while(unmarkedStatesExist()){
  int state = getUnmarkedState();
  markState(state);
  int *nfaStates = getNFAStates(state);
  int i = 0;
  while(i < 128){
   int *reach = move(nfaStates, i);
   int *closure = epsilonClosure(reach);
   if(-1 == closure[0]){
    i++;
    continue;
   }
   dfaState = installState(closure);
   char *action = getAction(closure);
   addDFANewState(dfaState, action);
   addDFATransTableEntry(state, dfaState, i);
   i++;
  }
 }
}

variable_types: struct vertex { int state; char *action; struct edge { struct vertex *connectsTo; char symbol; struct edge *next; } *edges; struct vertex *next; } *

variable_types: startPoint int

variable_types:
firstNFAState
int [2]

variable_types:
nfaClosure
int *

variable_types: dfaState int

variable_types:
action
char *

variable_types: state int

variable_types:
nfaStates
int *

variable_types: i int

variable_types:
closure
int *

user_defined_types: struct vertex { int state; char *action; struct edge *edges; struct vertex *next; }


insertDefEntry

decompiled_code:
void *__fastcall insertDefEntry(void *src)
{
_QWORD *v1; // rax
_QWORD *v2; // rbx
__int64 v3; // rax
size_t v4; // r12
void *v5; // rax
void *result; // rax

v1 = malloc(0x18uLL);
v2 = v1;
if ( definitions )
{
v3 = defp;
defp = (__int64)v2;
*(_QWORD *)(v3 + 16) = v2;
}
else
{
defp = (__int64)v1;
definitions = v1;
}
v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
*v2 = v5;
result = memcpy(v5, src, v4);
v2[1] = 0LL;
v2[2] = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(void *src)
{
_QWORD *v1; // rax
_QWORD *v2; // rbx
__int64 v3; // rax
size_t v4; // r12
void *v5; // rax
void *result; // rax

v1 = malloc(0x18uLL);
v2 = v1;
if ( definitions )
{
v3 = defp;
defp = (__int64)v2;
*(_QWORD *)(v3 + 16) = v2;
}
else
{
defp = (__int64)v1;
definitions = v1;
}
v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
*v2 = v5;
result = memcpy(v5, src, v4);
v2[1] = 0LL;
v2[2] = 0LL;
return result;
}

original_code:
void insertDefEntry(char *name){
 struct Defentry *temp = malloc(sizeof(struct Defentry));
 if(((void *)0) == definitions){
  definitions = defp = temp;
 }else{
  defp->next = temp;
  defp = temp;
 }
 temp->name = malloc(strlen(name)+1);
 strcpy(temp->name, name);
 temp->definition = ((void *)0);
 temp->next = ((void *)0);
}

variable_types:
name
char *

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


insertDefContent

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

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

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

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

original_code:
void insertDefContent(char *def){
 defp->definition = malloc(strlen(def)+1);
 strcpy(defp->definition, def);
}

variable_types:
def
char *


insertREEntry

decompiled_code:
void *__fastcall insertREEntry(void *src)
{
_QWORD *v1; // rax
_QWORD *v2; // rbx
__int64 v3; // rax
size_t v4; // r12
void *v5; // rax
void *result; // rax

v1 = malloc(0x18uLL);
v2 = v1;
if ( regexps )
{
v3 = rep;
rep = (__int64)v2;
*(_QWORD *)(v3 + 16) = v2;
}
else
{
rep = (__int64)v1;
regexps = v1;
}
v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
*v2 = v5;
result = memcpy(v5, src, v4);
v2[1] = 0LL;
v2[2] = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *src)
{
_QWORD *v1; // rax
_QWORD *v2; // rbx
__int64 v3; // rax
size_t v4; // r12
void *v5; // rax
void *result; // rax

v1 = malloc(0x18uLL);
v2 = v1;
if ( regexps )
{
v3 = rep;
rep = (__int64)v2;
*(_QWORD *)(v3 + 16) = v2;
}
else
{
rep = (__int64)v1;
regexps = v1;
}
v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
*v2 = v5;
result = memcpy(v5, src, v4);
v2[1] = 0LL;
v2[2] = 0LL;
return result;
}

original_code:
void insertREEntry(char *re){
 struct REentry *temp = malloc(sizeof(struct REentry));
 if(((void *)0) == regexps){
  regexps = rep = temp;
 }else{
  rep->next = temp;
  rep = temp;
 }
 temp->regexp = malloc(strlen(re)+1);
 strcpy(temp->regexp, re);
 temp->action = ((void *)0);
 temp->next = ((void *)0);
}

variable_types:
re
char *

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


insertREAction

decompiled_code:
char *__fastcall insertREAction(char *src)
{
size_t v1; // rax
__int64 v2; // rbx
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; // rbx
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

decompiled_code:
void *__fastcall insertFuncEntry(void *src)
{
_QWORD *v1; // rax
_QWORD *v2; // rbx
__int64 v3; // rax
size_t v4; // r12
void *v5; // rax
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func4(void *src)
{
_QWORD *v1; // rax
_QWORD *v2; // rbx
__int64 v3; // rax
size_t v4; // r12
void *v5; // rax
void *result; // rax

v1 = malloc(0x10uLL);
v2 = v1;
if ( additionalfuncs )
{
v3 = funcp;
funcp = (__int64)v2;
*(_QWORD *)(v3 + 8) = v2;
}
else
{
funcp = (__int64)v1;
additionalfuncs = v1;
}
v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
*v2 = v5;
result = memcpy(v5, src, v4);
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; } *


getch

decompiled_code:
int getch()
{
if ( bufp <= 0 )
return getc(in);
return buf[bufp--];
}

canonical_decompiled_code:
int func5()
{
if ( bufp <= 0 )
return getc(in);
return buf[bufp--];
}

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

return_type: int


readFuncSec

decompiled_code:
__int64 __fastcall readFuncSec(__int64 a1, int a2)
{
unsigned int v2; // ebp
char v3; // bl
unsigned int v4; // er12
const char *v5; // rdx
char v6; // al
const char *v7; // rdx
char v9; // al
char v10; // al
char v11; // al
char v12; // al
__int64 v13; // rsi
int v14; // er12
char v15; // al
char v16; // al
char v17; // bl
__int64 v18; // rsi
const char *v19; // rdx
void *v20; // rax
char v21; // al
char v22; // bl
__int64 v23; // rsi
const char *v24; // rdx
char v25; // al
char v26; // al
char v27; // bl
char v28; // al
char v29; // bl
char v30; // al
char v31; // bl

v2 = initializeCharBuffer();
while ( 1 )
{
LABEL_2:
v3 = getch();
if ( v3 == -1 )
{
LABEL_24:
destroyCharBuffer(v2);
return 1LL;
}
while ( v3 == 47 )
{
v6 = getch();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
while ( 1 )
{
if ( v6 == 42 )
{
while ( 1 )
{
v10 = getch();
if ( v10 == -1 )
return 0xFFFFFFFFLL;
if ( v10 == 42 )
{
do
{
v9 = getch();
if ( v9 == -1 )
return 0xFFFFFFFFLL;
}
while ( v9 == 42 );
if ( v9 == 47 )
break;
}
}
goto LABEL_2;
}
if ( v6 == 47 )
break;
error((int)"lexReader readFuncSec state1", a2, v7);
v6 = getch();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
}
do
{
v11 = getch();
if ( v11 == -1 )
return 0xFFFFFFFFLL;
}
while ( v11 != 10 );
v3 = getch();
if ( v3 == -1 )
goto LABEL_24;
}
v4 = v3;
if ( isalpha(v3) )
break;
if ( v3 == 95 )
{
v4 = 95;
break;
}
if ( v3 != 9 && v3 != 32 && v3 != 10 )
error((int)"lexReader readFuncSec state0", a2, v5);
}
addCharElement(v2, v4);
v12 = getch();
v13 = (unsigned int)v12;
if ( v12 == -1 )
return 0xFFFFFFFFLL;
v14 = 0;
while ( 1 )
{
if ( (_BYTE)v13 == 34 )
{
addCharElement(v2, 34LL);
while ( 1 )
{
v16 = getch();
v17 = v16;
if ( v16 == -1 )
return 0xFFFFFFFFLL;
v18 = (unsigned int)v16;
addCharElement(v2, v18);
if ( v17 == 34 )
goto LABEL_32;
if ( v17 == 10 )
error((int)"lexReader readFuncSec state6", v18, v19);
}
}
if ( (_BYTE)v13 == 123 )
{
++v14;
v13 = 123LL;
LABEL_31:
addCharElement(v2, v13);
goto LABEL_32;
}
if ( (_BYTE)v13 == 47 )
break;
if ( (_BYTE)v13 != 125 )
goto LABEL_31;
--v14;
addCharElement(v2, 125LL);
if ( !v14 )
{
a2 = 0;
addCharElement(v2, 0LL);
v20 = (void *)getCharBuffer(v2);
insertFuncEntry(v20);
rewindCharPointer(v2);
goto LABEL_2;
}
LABEL_32:
v15 = getch();
v13 = (unsigned int)v15;
if ( v15 == -1 )
return 0xFFFFFFFFLL;
}
addCharElement(v2, 47LL);
v21 = getch();
v22 = v21;
if ( v21 != -1 )
{
v23 = (unsigned int)v21;
addCharElement(v2, v23);
if ( v22 == 42 )
goto LABEL_47;
while ( v22 != 47 )
{
error((int)"lexReader readFuncSec state7", v23, v24);
v25 = getch();
v22 = v25;
if ( v25 == -1 )
return 0xFFFFFFFFLL;
v23 = (unsigned int)v25;
addCharElement(v2, v23);
if ( v22 == 42 )
{
LABEL_47:
while ( 1 )
{
v26 = getch();
v27 = v26;
if ( v26 == -1 )
return 0xFFFFFFFFLL;
addCharElement(v2, (unsigned int)v26);
if ( v27 == 42 )
{
while ( 1 )
{
v28 = getch();
v29 = v28;
if ( v28 == -1 )
return 0xFFFFFFFFLL;
addCharElement(v2, (unsigned int)v28);
if ( v29 != 42 )
{
if ( v29 != 47 )
goto LABEL_47;
goto LABEL_32;
}
}
}
}
}
}
while ( 1 )
{
v30 = getch();
v31 = v30;
if ( v30 == -1 )
break;
addCharElement(v2, (unsigned int)v30);
if ( v31 == 10 )
goto LABEL_32;
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
unsigned int v2; // ebp
char v3; // bl
unsigned int v4; // er12
const char *v5; // rdx
char v6; // al
const char *v7; // rdx
char v9; // al
char v10; // al
char v11; // al
char v12; // al
__int64 v13; // rsi
int v14; // er12
char v15; // al
char v16; // al
char v17; // bl
__int64 v18; // rsi
const char *v19; // rdx
void *v20; // rax
char v21; // al
char v22; // bl
__int64 v23; // rsi
const char *v24; // rdx
char v25; // al
char v26; // al
char v27; // bl
char v28; // al
char v29; // bl
char v30; // al
char v31; // bl

v2 = initializeCharBuffer();
while ( 1 )
{
LABEL_2:
v3 = func5();
if ( v3 == -1 )
{
LABEL_24:
destroyCharBuffer(v2);
return 1LL;
}
while ( v3 == 47 )
{
v6 = func5();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
while ( 1 )
{
if ( v6 == 42 )
{
while ( 1 )
{
v10 = func5();
if ( v10 == -1 )
return 0xFFFFFFFFLL;
if ( v10 == 42 )
{
do
{
v9 = func5();
if ( v9 == -1 )
return 0xFFFFFFFFLL;
}
while ( v9 == 42 );
if ( v9 == 47 )
break;
}
}
goto LABEL_2;
}
if ( v6 == 47 )
break;
error((int)"lexReader readFuncSec state1", a2, v7);
v6 = func5();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
}
do
{
v11 = func5();
if ( v11 == -1 )
return 0xFFFFFFFFLL;
}
while ( v11 != 10 );
v3 = func5();
if ( v3 == -1 )
goto LABEL_24;
}
v4 = v3;
if ( isalpha(v3) )
break;
if ( v3 == 95 )
{
v4 = 95;
break;
}
if ( v3 != 9 && v3 != 32 && v3 != 10 )
error((int)"lexReader readFuncSec state0", a2, v5);
}
addCharElement(v2, v4);
v12 = func5();
v13 = (unsigned int)v12;
if ( v12 == -1 )
return 0xFFFFFFFFLL;
v14 = 0;
while ( 1 )
{
if ( (_BYTE)v13 == 34 )
{
addCharElement(v2, 34LL);
while ( 1 )
{
v16 = func5();
v17 = v16;
if ( v16 == -1 )
return 0xFFFFFFFFLL;
v18 = (unsigned int)v16;
addCharElement(v2, v18);
if ( v17 == 34 )
goto LABEL_32;
if ( v17 == 10 )
error((int)"lexReader readFuncSec state6", v18, v19);
}
}
if ( (_BYTE)v13 == 123 )
{
++v14;
v13 = 123LL;
LABEL_31:
addCharElement(v2, v13);
goto LABEL_32;
}
if ( (_BYTE)v13 == 47 )
break;
if ( (_BYTE)v13 != 125 )
goto LABEL_31;
--v14;
addCharElement(v2, 125LL);
if ( !v14 )
{
a2 = 0;
addCharElement(v2, 0LL);
v20 = (void *)getCharBuffer(v2);
func4(v20);
rewindCharPointer(v2);
goto LABEL_2;
}
LABEL_32:
v15 = func5();
v13 = (unsigned int)v15;
if ( v15 == -1 )
return 0xFFFFFFFFLL;
}
addCharElement(v2, 47LL);
v21 = func5();
v22 = v21;
if ( v21 != -1 )
{
v23 = (unsigned int)v21;
addCharElement(v2, v23);
if ( v22 == 42 )
goto LABEL_47;
while ( v22 != 47 )
{
error((int)"lexReader readFuncSec state7", v23, v24);
v25 = func5();
v22 = v25;
if ( v25 == -1 )
return 0xFFFFFFFFLL;
v23 = (unsigned int)v25;
addCharElement(v2, v23);
if ( v22 == 42 )
{
LABEL_47:
while ( 1 )
{
v26 = func5();
v27 = v26;
if ( v26 == -1 )
return 0xFFFFFFFFLL;
addCharElement(v2, (unsigned int)v26);
if ( v27 == 42 )
{
while ( 1 )
{
v28 = func5();
v29 = v28;
if ( v28 == -1 )
return 0xFFFFFFFFLL;
addCharElement(v2, (unsigned int)v28);
if ( v29 != 42 )
{
if ( v29 != 47 )
goto LABEL_47;
goto LABEL_32;
}
}
}
}
}
}
while ( 1 )
{
v30 = func5();
v31 = v30;
if ( v30 == -1 )
break;
addCharElement(v2, (unsigned int)v30);
if ( v31 == 10 )
goto LABEL_32;
}
}
return 0xFFFFFFFFLL;
}

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: 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:
__int64 __fastcall readDeclareSec(__int64 a1, unsigned __int64 a2)
{
unsigned int v2; // ebp
int v3; // eax
__int64 v4; // rsi
const char *v5; // rdx
int v7; // eax
const char *v8; // rdx
int v9; // eax
int v10; // eax
const char *v11; // rdx
int v12; // eax
int v13; // eax
const char *v14; // rdx
int v15; // eax
int v16; // eax
int v17; // eax
void *v18; // rax
int v19; // eax
const char *v20; // rdx
int v21; // eax
__int64 v22; // rsi
char *v23; // rax
int v24; // eax
const char *v25; // rdx

v2 = initializeCharBuffer();
LABEL_2:
while ( 2 )
{
v3 = getch();
if ( v3 != -1 )
{
if ( v3 == 47 )
goto LABEL_30;
while ( v3 == 37 )
{
v7 = getch();
if ( v7 == -1 )
return 0xFFFFFFFFLL;
if ( v7 != 123 )
{
while ( v7 != 37 )
{
error((int)"lexReader readDeclareSec STATE9", a2, v8);
v7 = getch();
if ( v7 == -1 )
return 0xFFFFFFFFLL;
if ( v7 == 123 )
goto LABEL_19;
}
destroyCharBuffer(v2);
return 1LL;
}
LABEL_19:
v9 = getch();
if ( v9 == -1 )
return 0xFFFFFFFFLL;
while ( v9 != 37 )
{
a2 = (unsigned int)(char)v9;
addCharElement(v2, a2);
v9 = getch();
if ( v9 == -1 )
return 0xFFFFFFFFLL;
}
v10 = getch();
if ( v10 == -1 )
return 0xFFFFFFFFLL;
if ( v10 != 125 )
{
do
{
error((int)"lexReader readDeclareSec STATE11", a2, v11);
v12 = getch();
if ( v12 == -1 )
return 0xFFFFFFFFLL;
}
while ( v12 != 125 );
}
v13 = charSize(v2);
declarations = (char *)malloc(v13);
a2 = getCharBuffer(v2);
strcpy(declarations, (const char *)a2);
LABEL_28:
rewindCharPointer(v2);
v3 = getch();
if ( v3 == -1 )
return 0xFFFFFFFFLL;
if ( v3 == 47 )
{
LABEL_30:
while ( 1 )
{
v3 = getch();
switch ( v3 )
{
case -1:
return 0xFFFFFFFFLL;
case 42:
LABEL_39:
while ( 1 )
{
v16 = getch();
if ( v16 == -1 )
return 0xFFFFFFFFLL;
if ( v16 == 42 )
{
while ( 1 )
{
v15 = getch();
if ( v15 == -1 )
return 0xFFFFFFFFLL;
if ( v15 != 42 )
{
if ( v15 == 47 )
goto LABEL_2;
goto LABEL_39;
}
}
}
}
case 47:
while ( 1 )
{
v17 = getch();
if ( v17 == -1 )
return 0xFFFFFFFFLL;
if ( v17 == 10 )
goto LABEL_2;
}
}
v14 = (const char *)(unsigned int)(v3 - 9);
if ( (unsigned int)v14 > 1 && v3 != 32 )
goto LABEL_8;
error((int)"lexReader readDeclareSec STATE1", a2, v14);
}
}
}
if ( v3 == 9 || v3 == 32 || v3 == 10 )
continue;
LABEL_8:
v4 = (unsigned int)(char)v3;
addCharElement(v2, v4);
v3 = getch();
if ( v3 != -1 )
{
while ( v3 != 32 && v3 != 9 )
{
if ( v3 != 10 )
goto LABEL_8;
error((int)"lexReader readDeclareSec STATE5", v4, v5);
v3 = getch();
if ( v3 == -1 )
return 0xFFFFFFFFLL;
}
addCharElement(v2, 0LL);
v18 = (void *)getCharBuffer(v2);
insertDefEntry(v18);
rewindCharPointer(v2);
while ( 1 )
{
v19 = getch();
if ( v19 == -1 )
break;
if ( v19 != 32 && v19 != 9 )
{
if ( v19 != 10 )
{
ungetch(v19);
v21 = getch();
if ( v21 == -1 )
return 0xFFFFFFFFLL;
while ( (unsigned int)(v21 - 9) > 1 )
{
if ( v21 == 32 )
break;
v22 = (unsigned int)(char)v21;
if ( v21 == 34 || v21 == 91 )
{
LABEL_58:
addCharElement(v2, v22);
v24 = getch();
if ( v24 == -1 )
return 0xFFFFFFFFLL;
while ( v24 != 34 && v24 != 93 )
{
v25 = (const char *)(unsigned int)(v24 - 9);
if ( (unsigned int)v25 > 1 )
{
v22 = (unsigned int)(char)v24;
goto LABEL_58;
}
error((int)"lexReader readDeclareSec STATE8", v22, v25);
v24 = getch();
if ( v24 == -1 )
return 0xFFFFFFFFLL;
}
v22 = (unsigned int)(char)v24;
}
addCharElement(v2, v22);
v21 = getch();
if ( v21 == -1 )
return 0xFFFFFFFFLL;
}
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v23 = (char *)getCharBuffer(v2);
insertDefContent(v23);
goto LABEL_28;
}
error((int)"lexReader readDeclareSec STATE6", 0, v20);
}
}
}
}
return 0xFFFFFFFFLL;
}
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int64 a2)
{
unsigned int v2; // ebp
int v3; // eax
__int64 v4; // rsi
const char *v5; // rdx
int v7; // eax
const char *v8; // rdx
int v9; // eax
int v10; // eax
const char *v11; // rdx
int v12; // eax
int v13; // eax
const char *v14; // rdx
int v15; // eax
int v16; // eax
int v17; // eax
void *v18; // rax
int v19; // eax
const char *v20; // rdx
int v21; // eax
__int64 v22; // rsi
char *v23; // rax
int v24; // eax
const char *v25; // rdx

v2 = initializeCharBuffer();
LABEL_2:
while ( 2 )
{
v3 = func5();
if ( v3 != -1 )
{
if ( v3 == 47 )
goto LABEL_30;
while ( v3 == 37 )
{
v7 = func5();
if ( v7 == -1 )
return 0xFFFFFFFFLL;
if ( v7 != 123 )
{
while ( v7 != 37 )
{
error((int)"lexReader readDeclareSec STATE9", a2, v8);
v7 = func5();
if ( v7 == -1 )
return 0xFFFFFFFFLL;
if ( v7 == 123 )
goto LABEL_19;
}
destroyCharBuffer(v2);
return 1LL;
}
LABEL_19:
v9 = func5();
if ( v9 == -1 )
return 0xFFFFFFFFLL;
while ( v9 != 37 )
{
a2 = (unsigned int)(char)v9;
addCharElement(v2, a2);
v9 = func5();
if ( v9 == -1 )
return 0xFFFFFFFFLL;
}
v10 = func5();
if ( v10 == -1 )
return 0xFFFFFFFFLL;
if ( v10 != 125 )
{
do
{
error((int)"lexReader readDeclareSec STATE11", a2, v11);
v12 = func5();
if ( v12 == -1 )
return 0xFFFFFFFFLL;
}
while ( v12 != 125 );
}
v13 = charSize(v2);
declarations = (char *)malloc(v13);
a2 = getCharBuffer(v2);
strcpy(declarations, (const char *)a2);
LABEL_28:
rewindCharPointer(v2);
v3 = func5();
if ( v3 == -1 )
return 0xFFFFFFFFLL;
if ( v3 == 47 )
{
LABEL_30:
while ( 1 )
{
v3 = func5();
switch ( v3 )
{
case -1:
return 0xFFFFFFFFLL;
case 42:
LABEL_39:
while ( 1 )
{
v16 = func5();
if ( v16 == -1 )
return 0xFFFFFFFFLL;
if ( v16 == 42 )
{
while ( 1 )
{
v15 = func5();
if ( v15 == -1 )
return 0xFFFFFFFFLL;
if ( v15 != 42 )
{
if ( v15 == 47 )
goto LABEL_2;
goto LABEL_39;
}
}
}
}
case 47:
while ( 1 )
{
v17 = func5();
if ( v17 == -1 )
return 0xFFFFFFFFLL;
if ( v17 == 10 )
goto LABEL_2;
}
}
v14 = (const char *)(unsigned int)(v3 - 9);
if ( (unsigned int)v14 > 1 && v3 != 32 )
goto LABEL_8;
error((int)"lexReader readDeclareSec STATE1", a2, v14);
}
}
}
if ( v3 == 9 || v3 == 32 || v3 == 10 )
continue;
LABEL_8:
v4 = (unsigned int)(char)v3;
addCharElement(v2, v4);
v3 = func5();
if ( v3 != -1 )
{
while ( v3 != 32 && v3 != 9 )
{
if ( v3 != 10 )
goto LABEL_8;
error((int)"lexReader readDeclareSec STATE5", v4, v5);
v3 = func5();
if ( v3 == -1 )
return 0xFFFFFFFFLL;
}
addCharElement(v2, 0LL);
v18 = (void *)getCharBuffer(v2);
func0(v18);
rewindCharPointer(v2);
while ( 1 )
{
v19 = func5();
if ( v19 == -1 )
break;
if ( v19 != 32 && v19 != 9 )
{
if ( v19 != 10 )
{
func7(v19);
v21 = func5();
if ( v21 == -1 )
return 0xFFFFFFFFLL;
while ( (unsigned int)(v21 - 9) > 1 )
{
if ( v21 == 32 )
break;
v22 = (unsigned int)(char)v21;
if ( v21 == 34 || v21 == 91 )
{
LABEL_58:
addCharElement(v2, v22);
v24 = func5();
if ( v24 == -1 )
return 0xFFFFFFFFLL;
while ( v24 != 34 && v24 != 93 )
{
v25 = (const char *)(unsigned int)(v24 - 9);
if ( (unsigned int)v25 > 1 )
{
v22 = (unsigned int)(char)v24;
goto LABEL_58;
}
error((int)"lexReader readDeclareSec STATE8", v22, v25);
v24 = func5();
if ( v24 == -1 )
return 0xFFFFFFFFLL;
}
v22 = (unsigned int)(char)v24;
}
addCharElement(v2, v22);
v21 = func5();
if ( v21 == -1 )
return 0xFFFFFFFFLL;
}
LODWORD(a2) = 0;
addCharElement(v2, 0LL);
v23 = (char *)getCharBuffer(v2);
func1(v23);
goto LABEL_28;
}
error((int)"lexReader readDeclareSec STATE6", 0, v20);
}
}
}
}
return 0xFFFFFFFFLL;
}
}

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, int a2)
{
unsigned int v2; // ebp
int v3; // eax
char v5; // al
char v6; // al
char v7; // al
char v8; // al
char v9; // al
const char *v10; // rdx
__int64 v11; // rsi
char v12; // al
void *v13; // rax
char v14; // al
const char *v15; // rdx
char v16; // al
__int64 v17; // rsi
char v18; // al
char *v19; // rax
__int64 v20; // rsi
char v21; // al
const char *v22; // rdx
char v23; // al
const char *v24; // rdx
__int64 v25; // rsi

v2 = initializeCharBuffer();
LOBYTE(v3) = getch();
if ( (_BYTE)v3 != 0xFF )
{
LABEL_2:
while ( (_BYTE)v3 != 47 )
{
if ( (_BYTE)v3 == 37 )
{
while ( 1 )
{
v5 = getch();
if ( v5 == -1 )
break;
if ( v5 == 37 )
{
destroyCharBuffer(v2);
return 1LL;
}
}
return 0xFFFFFFFFLL;
}
if ( (_BYTE)v3 != 9 && (_BYTE)v3 != 32 && (_BYTE)v3 != 10 )
{
LABEL_29:
ungetch(v3);
LABEL_30:
v9 = getch();
v11 = (unsigned int)v9;
if ( v9 != -1 )
{
if ( v9 != 32 )
{
while ( (_BYTE)v11 != 9 )
{
switch ( (_BYTE)v11 )
{
case 0xA:
error((int)"lexReader readRESec STATE5", v11, v10);
goto LABEL_30;
case 0x22:
addCharElement(v2, 34LL);
while ( 1 )
{
v23 = getch();
v25 = (unsigned int)v23;
if ( v23 == -1 )
return 0xFFFFFFFFLL;
if ( v23 == 34 )
{
LABEL_65:
v11 = 34LL;
goto LABEL_36;
}
while ( (unsigned __int8)(v23 - 9) > 1u )
{
addCharElement(v2, v25);
v23 = getch();
v25 = (unsigned int)v23;
if ( v23 == -1 )
return 0xFFFFFFFFLL;
if ( v23 == 34 )
goto LABEL_65;
}
error((int)"lexReader readRESec STATE6", v25, v24);
}
case 0x5B:
v20 = 91LL;
LABEL_52:
addCharElement(v2, v20);
while ( 1 )
{
v21 = getch();
v20 = (unsigned int)v21;
if ( v21 == -1 )
return 0xFFFFFFFFLL;
if ( v21 == 93 )
{
v11 = 93LL;
goto LABEL_36;
}
if ( (unsigned __int8)(v21 - 9) > 1u )
goto LABEL_52;
error((int)"lexReader readRESec STATE6", v20, v22);
}
}
LABEL_36:
addCharElement(v2, v11);
v12 = getch();
v11 = (unsigned int)v12;
if ( v12 == -1 )
return 0xFFFFFFFFLL;
if ( v12 == 32 )
break;
}
}
addCharElement(v2, 0LL);
v13 = (void *)getCharBuffer(v2);
insertREEntry(v13);
rewindCharPointer(v2);
while ( 1 )
{
v14 = getch();
if ( v14 == -1 )
break;
while ( v14 != 32 && v14 != 9 )
{
if ( v14 == 123 )
{
v16 = getch();
v17 = (unsigned int)v16;
if ( v16 == -1 )
return 0xFFFFFFFFLL;
if ( v16 == 125 )
{
LABEL_49:
a2 = 0;
addCharElement(v2, 0LL);
v19 = (char *)getCharBuffer(v2);
insertREAction(v19);
rewindCharPointer(v2);
LOBYTE(v3) = getch();
if ( (_BYTE)v3 != 0xFF )
goto LABEL_2;
}
else
{
while ( 1 )
{
addCharElement(v2, v17);
v18 = getch();
v17 = (unsigned int)v18;
if ( v18 == -1 )
break;
if ( v18 == 125 )
goto LABEL_49;
}
}
return 0xFFFFFFFFLL;
}
error((int)"lexReader readRESec STATE7", 0, v15);
v14 = getch();
if ( v14 == -1 )
return 0xFFFFFFFFLL;
}
}
}
return 0xFFFFFFFFLL;
}
LABEL_7:
LOBYTE(v3) = getch();
if ( (_BYTE)v3 == 0xFF )
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v3 = getch();
if ( (_BYTE)v3 == 0xFF )
break;
if ( (_BYTE)v3 == 42 )
{
LABEL_22:
while ( 1 )
{
v7 = getch();
if ( v7 == -1 )
return 0xFFFFFFFFLL;
if ( v7 == 42 )
{
while ( 1 )
{
v6 = getch();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
if ( v6 != 42 )
{
if ( v6 == 47 )
goto LABEL_7;
goto LABEL_22;
}
}
}
}
}
if ( (_BYTE)v3 == 47 )
{
while ( 1 )
{
v8 = getch();
if ( v8 == -1 )
return 0xFFFFFFFFLL;
if ( v8 == 10 )
{
LOBYTE(v3) = getch();
if ( (_BYTE)v3 != 0xFF )
goto LABEL_2;
return 0xFFFFFFFFLL;
}
}
}
if ( (unsigned __int8)(v3 - 9) > 1u && (_BYTE)v3 != 32 )
goto LABEL_29;
error((int)"lexReader readRESec STATE1", a2, (const char *)(unsigned int)(v3 - 9));
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
unsigned int v2; // ebp
int v3; // eax
char v5; // al
char v6; // al
char v7; // al
char v8; // al
char v9; // al
const char *v10; // rdx
__int64 v11; // rsi
char v12; // al
void *v13; // rax
char v14; // al
const char *v15; // rdx
char v16; // al
__int64 v17; // rsi
char v18; // al
char *v19; // rax
__int64 v20; // rsi
char v21; // al
const char *v22; // rdx
char v23; // al
const char *v24; // rdx
__int64 v25; // rsi

v2 = initializeCharBuffer();
LOBYTE(v3) = func5();
if ( (_BYTE)v3 != 0xFF )
{
LABEL_2:
while ( (_BYTE)v3 != 47 )
{
if ( (_BYTE)v3 == 37 )
{
while ( 1 )
{
v5 = func5();
if ( v5 == -1 )
break;
if ( v5 == 37 )
{
destroyCharBuffer(v2);
return 1LL;
}
}
return 0xFFFFFFFFLL;
}
if ( (_BYTE)v3 != 9 && (_BYTE)v3 != 32 && (_BYTE)v3 != 10 )
{
LABEL_29:
func7(v3);
LABEL_30:
v9 = func5();
v11 = (unsigned int)v9;
if ( v9 != -1 )
{
if ( v9 != 32 )
{
while ( (_BYTE)v11 != 9 )
{
switch ( (_BYTE)v11 )
{
case 0xA:
error((int)"lexReader readRESec STATE5", v11, v10);
goto LABEL_30;
case 0x22:
addCharElement(v2, 34LL);
while ( 1 )
{
v23 = func5();
v25 = (unsigned int)v23;
if ( v23 == -1 )
return 0xFFFFFFFFLL;
if ( v23 == 34 )
{
LABEL_65:
v11 = 34LL;
goto LABEL_36;
}
while ( (unsigned __int8)(v23 - 9) > 1u )
{
addCharElement(v2, v25);
v23 = func5();
v25 = (unsigned int)v23;
if ( v23 == -1 )
return 0xFFFFFFFFLL;
if ( v23 == 34 )
goto LABEL_65;
}
error((int)"lexReader readRESec STATE6", v25, v24);
}
case 0x5B:
v20 = 91LL;
LABEL_52:
addCharElement(v2, v20);
while ( 1 )
{
v21 = func5();
v20 = (unsigned int)v21;
if ( v21 == -1 )
return 0xFFFFFFFFLL;
if ( v21 == 93 )
{
v11 = 93LL;
goto LABEL_36;
}
if ( (unsigned __int8)(v21 - 9) > 1u )
goto LABEL_52;
error((int)"lexReader readRESec STATE6", v20, v22);
}
}
LABEL_36:
addCharElement(v2, v11);
v12 = func5();
v11 = (unsigned int)v12;
if ( v12 == -1 )
return 0xFFFFFFFFLL;
if ( v12 == 32 )
break;
}
}
addCharElement(v2, 0LL);
v13 = (void *)getCharBuffer(v2);
func2(v13);
rewindCharPointer(v2);
while ( 1 )
{
v14 = func5();
if ( v14 == -1 )
break;
while ( v14 != 32 && v14 != 9 )
{
if ( v14 == 123 )
{
v16 = func5();
v17 = (unsigned int)v16;
if ( v16 == -1 )
return 0xFFFFFFFFLL;
if ( v16 == 125 )
{
LABEL_49:
a2 = 0;
addCharElement(v2, 0LL);
v19 = (char *)getCharBuffer(v2);
func3(v19);
rewindCharPointer(v2);
LOBYTE(v3) = func5();
if ( (_BYTE)v3 != 0xFF )
goto LABEL_2;
}
else
{
while ( 1 )
{
addCharElement(v2, v17);
v18 = func5();
v17 = (unsigned int)v18;
if ( v18 == -1 )
break;
if ( v18 == 125 )
goto LABEL_49;
}
}
return 0xFFFFFFFFLL;
}
error((int)"lexReader readRESec STATE7", 0, v15);
v14 = func5();
if ( v14 == -1 )
return 0xFFFFFFFFLL;
}
}
}
return 0xFFFFFFFFLL;
}
LABEL_7:
LOBYTE(v3) = func5();
if ( (_BYTE)v3 == 0xFF )
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v3 = func5();
if ( (_BYTE)v3 == 0xFF )
break;
if ( (_BYTE)v3 == 42 )
{
LABEL_22:
while ( 1 )
{
v7 = func5();
if ( v7 == -1 )
return 0xFFFFFFFFLL;
if ( v7 == 42 )
{
while ( 1 )
{
v6 = func5();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
if ( v6 != 42 )
{
if ( v6 == 47 )
goto LABEL_7;
goto LABEL_22;
}
}
}
}
}
if ( (_BYTE)v3 == 47 )
{
while ( 1 )
{
v8 = func5();
if ( v8 == -1 )
return 0xFFFFFFFFLL;
if ( v8 == 10 )
{
LOBYTE(v3) = func5();
if ( (_BYTE)v3 != 0xFF )
goto LABEL_2;
return 0xFFFFFFFFLL;
}
}
}
if ( (unsigned __int8)(v3 - 9) > 1u && (_BYTE)v3 != 32 )
goto LABEL_29;
error((int)"lexReader readRESec STATE1", a2, (const char *)(unsigned int)(v3 - 9));
}
}
return 0xFFFFFFFFLL;
}

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()
{
__int64 result; // rax

if ( !stack || stack == (void *)topp )
result = 0xFFFFFFFFLL;
else
result = *(unsigned int *)(topp - 4);
return result;
}

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

if ( !stack || stack == (void *)topp )
result = 0xFFFFFFFFLL;
else
result = *(unsigned int *)(topp - 4);
return result;
}

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 result; // rax

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

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

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

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 func3()
{
__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; // er8

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; // er8

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)
{
__int64 v2; // rcx
int v3; // er8
__int64 result; // rax
int v5; // edx
__int64 v6; // rax
int v7; // edx

getIntArraySize(a1);
v3 = getIntArraySize(a2);
result = 0LL;
if ( v5 == v3 )
{
v6 = 0LL;
do
{
v7 = *(_DWORD *)(v2 + v6);
if ( v7 != *(_DWORD *)(a2 + v6) )
return 0LL;
v6 += 4LL;
}
while ( v7 != -1 );
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
int v3; // er8
__int64 result; // rax
int v5; // edx
__int64 v6; // rax
int v7; // edx

func3(a1);
v3 = func3(a2);
result = 0LL;
if ( v5 == v3 )
{
v6 = 0LL;
do
{
v7 = *(_DWORD *)(v2 + v6);
if ( v7 != *(_DWORD *)(a2 + v6) )
return 0LL;
v6 += 4LL;
}
while ( v7 != -1 );
result = 1LL;
}
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


installState

decompiled_code:
__int64 __fastcall installState(int *a1)
{
__int64 *v1; // rbx
_DWORD *v2; // r13
unsigned int v3; // er12
_DWORD *v4; // rax
_DWORD *v5; // rbx
unsigned int v6; // er12
_DWORD *v7; // rax
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func5(int *a1)
{
__int64 *v1; // rbx
_DWORD *v2; // r13
unsigned int v3; // er12
_DWORD *v4; // rax
_DWORD *v5; // rbx
unsigned int v6; // er12
_DWORD *v7; // rax
__int64 result; // rax

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

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; } *

user_defined_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)
{
const char *v3; // rdi
__int64 v4; // rax

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

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

if ( argc <= 1 )
{
func0();
exit(1);
}
v3 = argv[1];
listing = (__int64)stdout;
source = (__int64)fopen(v3, "r");
if ( !source )
{
fwrite(" [Error] No such file..", 1uLL, 0x17uLL, stdout);
exit(1);
}
v4 = parse();
print_tree(v4);
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:
__int64 __fastcall print_tree(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
int v3; // eax
int v4; // eax

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

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

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

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;
}

variable_types: i int

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:
void __fastcall free_tree(void *ptr)
{
void **v1; // rbx
void **v2; // rdi

if ( ptr )
{
v1 = (void **)ptr;
do
{
free_tree(*v1);
free_tree(v1[1]);
free_tree(v1[2]);
v2 = v1;
v1 = (void **)v1[3];
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void **v1; // rbx
void **v2; // rdi

if ( ptr )
{
v1 = (void **)ptr;
do
{
func3(*v1);
func3(v1[1]);
func3(v1[2]);
v2 = v1;
v1 = (void **)v1[3];
free(v2);
}
while ( v1 );
}
}

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 *result; // rax

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

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

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

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:
__int64 unget_next_char()
{
__int64 result; // rax

result = (unsigned int)EOF_FLAG;
if ( !EOF_FLAG )
--line_pos;
return result;
}

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

result = (unsigned int)EOF_FLAG;
if ( !EOF_FLAG )
--line_pos;
return result;
}

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


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

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

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

if ( line_pos < buff_size )
return (unsigned int)line_buff[line_pos++];
++line_no;
if ( fgets(line_buff, 255, source) )
{
v1 = strlen(line_buff);
line_pos = 1;
buff_size = v1;
result = (unsigned int)line_buff[0];
}
else
{
EOF_FLAG = 1;
result = 0xFFFFFFFFLL;
}
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 get_token()
{
__int64 v0; // rbp
char i; // dl
char v2; // dl
char v3; // r8
_BOOL4 v4; // eax
unsigned __int64 v5; // rdx
char v6; // cl
__int64 v7; // rbx
char v8; // al
__int64 v9; // rdx
char v10; // cl
char v11; // al
__int64 v12; // rdx
__int64 result; // rax
char j; // dl
char v15; // dl
__int64 v16; // rdx
int v17; // eax

v0 = 0x100002600LL;
for ( i = get_next_char(); ; i = get_next_char() )
{
if ( is_digit(i) )
{
token_string[0] = v2;
v7 = 1LL;
for ( j = get_next_char(); is_digit(j); j = get_next_char() )
{
token_string[v7] = v15;
v7 = (int)v7 + 1;
}
unget_next_char();
result = 11LL;
LABEL_12:
token_string[v7] = 0;
return result;
}
v4 = is_alpha(v3);
v7 = v4;
if ( v4 )
{
token_string[0] = v5;
v8 = get_next_char();
if ( is_alpha(v8) )
{
do
{
token_string[v9] = v10;
v11 = get_next_char();
}
while ( is_alpha(v11) );
}
unget_next_char();
token_string[v12] = 0;
return reserved_lookup_constprop_0();
}
if ( (unsigned int)v5 > 0x20 )
break;
if ( !_bittest64(&v0, v5) )
goto LABEL_20;
LABEL_18:
;
}
if ( (_DWORD)v5 == 58 )
{
if ( (unsigned int)get_next_char() == 61 )
{
token_string[0] = 61;
result = 12LL;
v7 = 1LL;
}
else
{
unget_next_char();
result = 1LL;
}
goto LABEL_12;
}
if ( (_DWORD)v5 == 123 )
{
while ( 1 )
{
v17 = get_next_char();
if ( v17 == -1 )
break;
if ( v17 == 125 )
goto LABEL_18;
}
result = 0LL;
goto LABEL_12;
}
LABEL_20:
v16 = (unsigned int)(v5 + 1);
if ( (unsigned int)v16 > 0x3E )
{
token_string[0] = v6;
result = 1LL;
token_string[1] = 0;
return result;
}
result = (unsigned __int8)CSWTCH_21[v16];
if ( CSWTCH_22[v16] )
{
token_string[0] = v6;
v7 = 1LL;
}
token_string[v7] = 0;
if ( (_DWORD)result == 10 )
return reserved_lookup_constprop_0();
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbp
char i; // dl
char v2; // dl
char v3; // r8
_BOOL4 v4; // eax
unsigned __int64 v5; // rdx
char v6; // cl
__int64 v7; // rbx
char v8; // al
__int64 v9; // rdx
char v10; // cl
char v11; // al
__int64 v12; // rdx
__int64 result; // rax
char j; // dl
char v15; // dl
__int64 v16; // rdx
int v17; // eax

v0 = 0x100002600LL;
for ( i = func3(); ; i = func3() )
{
if ( func1(i) )
{
token_string[0] = v2;
v7 = 1LL;
for ( j = func3(); func1(j); j = func3() )
{
token_string[v7] = v15;
v7 = (int)v7 + 1;
}
func0();
result = 11LL;
LABEL_12:
token_string[v7] = 0;
return result;
}
v4 = func2(v3);
v7 = v4;
if ( v4 )
{
token_string[0] = v5;
v8 = func3();
if ( func2(v8) )
{
do
{
token_string[v9] = v10;
v11 = func3();
}
while ( func2(v11) );
}
func0();
token_string[v12] = 0;
return func4();
}
if ( (unsigned int)v5 > 0x20 )
break;
if ( !_bittest64(&v0, v5) )
goto LABEL_20;
LABEL_18:
;
}
if ( (_DWORD)v5 == 58 )
{
if ( (unsigned int)func3() == 61 )
{
token_string[0] = 61;
result = 12LL;
v7 = 1LL;
}
else
{
func0();
result = 1LL;
}
goto LABEL_12;
}
if ( (_DWORD)v5 == 123 )
{
while ( 1 )
{
v17 = func3();
if ( v17 == -1 )
break;
if ( v17 == 125 )
goto LABEL_18;
}
result = 0LL;
goto LABEL_12;
}
LABEL_20:
v16 = (unsigned int)(v5 + 1);
if ( (unsigned int)v16 > 0x3E )
{
token_string[0] = v6;
result = 1LL;
token_string[1] = 0;
return result;
}
result = (unsigned __int8)CSWTCH_21[v16];
if ( CSWTCH_22[v16] )
{
token_string[0] = v6;
v7 = 1LL;
}
token_string[v7] = 0;
if ( (_DWORD)result == 10 )
return func4();
return result;
}

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

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 }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rax
int *v4; // rdx
int v5; // er15
int v6; // er12
int v7; // ebp
int v8; // ebx
int v9; // eax
int v10; // er14
int v11; // ecx
int v12; // edi
int v13; // er13
int v14; // er11
__int64 v15; // rdx
bool v16; // r8
bool v17; // r10
__int64 v18; // rdi
__int64 v19; // r13
bool v20; // al
__int64 v21; // rsi
__int64 v22; // rax
int *v23; // rsi
int *v24; // r8
__int64 v25; // rcx
int v27; // [rsp+Ch] [rbp-5Ch]
int v28; // [rsp+10h] [rbp-58h] BYREF
int v29; // [rsp+14h] [rbp-54h]

printf("argc %d argv[0] '%s'\n", (unsigned int)argc, *argv);
v3 = &s_combinations;
dword_4090B0 = 0;
s_nRolls = 0;
v4 = &s_numCombinations;
s_rolls = 0LL;
xmmword_409090 = 0LL;
xmmword_4090A0 = 0LL;
do
v3 = (int *)combinationInit(v3, (unsigned int)argc, v4);
while ( v4 != v3 );
s_numCombinations = 0;
v5 = 0;
s_numCombinations = makeCombinations();
printf("numCombinations %d\n", (unsigned int)s_numCombinations);
printCombinations();
do
{
v6 = rollDice();
v7 = rollDice();
v8 = rollDice();
v9 = rollDice();
v10 = v7 + v8;
v11 = v6 + v7;
v12 = v6 + v8;
v27 = v8 + v9;
v13 = v6 + v9;
v14 = v7 + v9;
v15 = 2LL;
if ( v7 == v8 )
{
v12 = v29;
v15 = 1LL;
}
v29 = v12;
v16 = v7 != v9;
v17 = v8 != v9;
if ( v7 != v9 && v8 != v9 )
{
v18 = (int)v15;
v15 = (unsigned int)(v15 + 1);
*(&v28 + v18) = v13;
}
if ( v6 != v7 && v6 != v8 && v13 != v10 )
{
v19 = (int)v15;
v15 = (unsigned int)(v15 + 1);
*(&v28 + v19) = v10;
}
v20 = v6 != v9;
if ( v6 + v8 != v14 && v20 && v17 && v6 != v7 )
{
v21 = (int)v15;
v15 = (unsigned int)(v15 + 1);
*(&v28 + v21) = v14;
}
if ( v11 != v27 && v20 && v6 != v8 && v16 && v7 != v8 )
{
v22 = (int)v15;
v15 = (unsigned int)(v15 + 1);
*(&v28 + v22) = v27;
}
v23 = &v28;
v24 = &v28 + (unsigned int)(v15 - 1);
while ( 1 )
{
addRollToCombinations((unsigned int)v11, v23, v15, v11, v24);
++*((_DWORD *)&s_rolls + v25);
if ( v24 == v23 )
break;
v11 = v23[1];
++v23;
}
updateCombinations();
++s_nRolls;
if ( (v5 & 0xFFFFF) == 0 )
{
printRolls();
printCombinations();
printf("numRolls %d\n", (unsigned int)s_nRolls);
}
++v5;
}
while ( v5 != 0x40000000 );
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: count int

variable_types:
rollsToAdd
int [6]

variable_types: placeToAdd int

variable_types: roll int


addCombination

decompiled_code:
__int64 __fastcall addCombination(int a1, int a2, int a3)
{
int v3; // er8
int v4; // eax
int v5; // eax
int *v6; // rax
unsigned __int64 v8; // rax
__int64 v9; // [rsp+0h] [rbp-8h]

if ( a1 == a3 || a1 == a2 || a2 == a3 )
return 0LL;
v9 = __PAIR64__(a3, a2);
v3 = s_numCombinations;
if ( a1 > a2 )
{
v4 = a1;
LODWORD(v9) = a1;
a1 = a2;
a2 = v4;
}
if ( a1 > a3 )
{
v5 = a1;
HIDWORD(v9) = a1;
a1 = a3;
a3 = v5;
}
if ( a2 > a3 )
v9 = __PAIR64__(a2, a3);
if ( s_numCombinations > 0 )
{
v6 = s_combinations;
while ( a1 != *v6 || *(_QWORD *)(v6 + 1) != v9 )
{
v6 += 5;
if ( v6 == (int *)((char *)&unk_404074 + 20 * (unsigned int)(s_numCombinations - 1)) )
goto LABEL_15;
}
return 0LL;
}
LABEL_15:
++s_numCombinations;
v8 = 20LL * v3;
s_combinations[v8 / 4] = a1;
*(__int64 *)((char *)&qword_404064 + v8) = v9;
*(__int64 *)((char *)&qword_40406C + v8) = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, int a3)
{
int v3; // er8
int v4; // eax
int v5; // eax
int *v6; // rax
unsigned __int64 v8; // rax
__int64 v9; // [rsp+0h] [rbp-8h]

if ( a1 == a3 || a1 == a2 || a2 == a3 )
return 0LL;
v9 = __PAIR64__(a3, a2);
v3 = s_numCombinations;
if ( a1 > a2 )
{
v4 = a1;
LODWORD(v9) = a1;
a1 = a2;
a2 = v4;
}
if ( a1 > a3 )
{
v5 = a1;
HIDWORD(v9) = a1;
a1 = a3;
a3 = v5;
}
if ( a2 > a3 )
v9 = __PAIR64__(a2, a3);
if ( s_numCombinations > 0 )
{
v6 = s_combinations;
while ( a1 != *v6 || *(_QWORD *)(v6 + 1) != v9 )
{
v6 += 5;
if ( v6 == (int *)((char *)&unk_404074 + 20 * (unsigned int)(s_numCombinations - 1)) )
goto LABEL_15;
}
return 0LL;
}
LABEL_15:
++s_numCombinations;
v8 = 20LL * v3;
s_combinations[v8 / 4] = a1;
*(__int64 *)((char *)&qword_404064 + v8) = v9;
*(__int64 *)((char *)&qword_40406C + v8) = 0LL;
return 1LL;
}

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: c 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: match int


addRollToCombinations

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

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

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

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

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 = s_numCombinations;
if ( s_numCombinations > 0 )
{
result = 0LL;
v1 = 20LL * s_numCombinations;
do
{
*(_DWORD *)((char *)&qword_40406C + result) += *(_DWORD *)(result + 4210800);
result += 20LL;
*(int *)((char *)&dword_40405C + result) = 0;
}
while ( result != v1 );
}
return result;
}

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

result = s_numCombinations;
if ( s_numCombinations > 0 )
{
result = 0LL;
v1 = 20LL * s_numCombinations;
do
{
*(_DWORD *)((char *)&qword_40406C + result) += *(_DWORD *)(result + 4210800);
result += 20LL;
*(int *)((char *)&dword_40405C + result) = 0;
}
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; // er12
int v1; // ebx
int v2; // ebp
int v3; // er11
int v4; // er9
int v5; // eax
int v6; // er10
unsigned int v7; // er10

v0 = 2;
do
{
v1 = v0++;
v2 = v0;
do
{
v3 = v2++;
v4 = v2;
do
{
v5 = addCombination(v1, v3, v4);
v7 = v5 + v6;
}
while ( v4 != 13 );
}
while ( v2 != 12 );
}
while ( v0 != 11 );
return v7;
}

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 v0; // rbx
__int64 v1; // rsi
double v2; // xmm0_8
int result; // eax

v0 = 2LL;
printf("numRolls = %d\n", (unsigned int)s_nRolls);
do
{
v1 = (unsigned int)v0;
v2 = (double)*((int *)&s_rolls + v0++);
*(float *)&v2 = v2 / (double)s_nRolls * 100.0;
result = printf("%d = %3.1f\n", v1, *(float *)&v2);
}
while ( v0 != 13 );
return result;
}

canonical_decompiled_code:
int func12()
{
__int64 v0; // rbx
__int64 v1; // rsi
double v2; // xmm0_8
int result; // eax

v0 = 2LL;
printf("numRolls = %d\n", (unsigned int)s_nRolls);
do
{
v1 = (unsigned int)v0;
v2 = (double)*((int *)&s_rolls + v0++);
*(float *)&v2 = v2 / (double)s_nRolls * 100.0;
result = printf("%d = %3.1f\n", v1, *(float *)&v2);
}
while ( v0 != 13 );
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
__int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // rsi
float v6; // 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
{
while ( 1 )
{
result = v1[3];
if ( result )
break;
v1 += 5;
if ( v1 == v2 )
return result;
}
v3 = v1[2];
v4 = v1[1];
v5 = *v1;
v1 += 5;
v6 = (double)result / (double)s_nRolls * 100.0;
result = printf("%d, %d, %d = %3.1f\n", v5, v4, v3, v6);
}
while ( v1 != v2 );
}
return result;
}

canonical_decompiled_code:
int func13()
{
int result; // eax
unsigned int *v1; // rbx
unsigned int *v2; // rbp
__int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // rsi
float v6; // 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
{
while ( 1 )
{
result = v1[3];
if ( result )
break;
v1 += 5;
if ( v1 == v2 )
return result;
}
v3 = v1[2];
v4 = v1[1];
v5 = *v1;
v1 += 5;
v6 = (double)result / (double)s_nRolls * 100.0;
result = printf("%d, %d, %d = %3.1f\n", v5, v4, v3, v6);
}
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);
  }
 }
}


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