Patch

decompiled_code:
void Patch()
{
_QWORD *v0; // rbp
__int64 v1; // rax
__int64 v2; // rcx
const char *v3; // rdx
const char **i; // rbx
int v5; // edx

v0 = (_QWORD *)pSections;
if ( pSections )
{
do
{
pCurrentSection = (__int64)v0;
for ( i = (const char **)v0[8]; i; i = (const char **)i[6] )
{
nPC = (__int64)&i[2][v0[1]];
v1 = calcrpn((__int64)i);
v5 = *((_DWORD *)i + 6);
switch ( v5 )
{
case 0:
if ( (unsigned __int64)(v1 + 128) > 0x17F )
{
sprintf(&temptext, "%s(%ld) : Value must be 8-bit\n", *i, i[1]);
fatalerror(&temptext);
}
else
{
i[2][v0[5]] = v1;
}
break;
case 1:
case 3:
if ( (unsigned __int64)(v1 + 0x8000) > 0x17FFF )
{
sprintf(&temptext, "%s(%ld) : Value must be 16-bit\n", *i, i[1]);
fatalerror(&temptext);
}
else
{
v1 = (unsigned __int16)v1;
if ( v5 == 1 )
{
i[2][v0[5]] = v1;
v2 = v0[5];
v3 = i[2];
v1 >>= 8;
}
else
{
i[2][v0[5]] = BYTE1(v1);
v2 = v0[5];
v3 = i[2];
}
v3[v2 + 1] = v1;
}
break;
case 2:
*(_WORD *)&i[2][v0[5]] = v1;
i[2][v0[5] + 2] = BYTE2(v1);
i[2][v0[5] + 3] = BYTE3(v1);
break;
case 4:
i[2][v0[5]] = BYTE3(v1);
i[2][v0[5] + 1] = BYTE2(v1);
i[2][v0[5] + 2] = BYTE1(v1);
i[2][v0[5] + 3] = v1;
break;
default:
continue;
}
}
v0 = (_QWORD *)v0[9];
}
while ( v0 );
}
}

original_code:
void Patch(void)
{
 struct sSection *pSect;
 pSect = pSections;
 while (pSect) {
  struct sPatch *pPatch;
  pCurrentSection = pSect;
  pPatch = pSect->pPatches;
  while (pPatch) {
   SLONG t;
   nPC = pSect->nOrg + pPatch->nOffset;
   t = calcrpn(pPatch);
   switch (pPatch->Type) {
   case PATCH_BYTE:
    if (t >= -128 && t <= 255) {
     t &= 0xFF;
     pSect->pData[pPatch->nOffset] =
         (UBYTE) t;
    } else {
     sprintf(temptext,
      "%s(%ld) : Value must be 8-bit\n",
      pPatch->pzFilename,
      pPatch->nLineNo);
     fatalerror(temptext);
    }
    break;
   case PATCH_WORD_L:
   case PATCH_WORD_B:
    if (t >= -32768 && t <= 65535) {
     t &= 0xFFFF;
     if (pPatch->Type == PATCH_WORD_L) {
      pSect->pData[pPatch->nOffset] =
          t & 0xFF;
      pSect->pData[pPatch->nOffset +
            1] =
          (t >> 8) & 0xFF;
     } else {
      pSect->pData[pPatch->nOffset] =
          (t >> 8) & 0xFF;
      pSect->pData[pPatch->nOffset +
            1] = t & 0xFF;
     }
    } else {
     sprintf(temptext,
      "%s(%ld) : Value must be 16-bit\n",
      pPatch->pzFilename,
      pPatch->nLineNo);
     fatalerror(temptext);
    }
    break;
   case PATCH_LONG_L:
    pSect->pData[pPatch->nOffset + 0] = t & 0xFF;
    pSect->pData[pPatch->nOffset + 1] =
        (t >> 8) & 0xFF;
    pSect->pData[pPatch->nOffset + 2] =
        (t >> 16) & 0xFF;
    pSect->pData[pPatch->nOffset + 3] =
        (t >> 24) & 0xFF;
    break;
   case PATCH_LONG_B:
    pSect->pData[pPatch->nOffset + 0] =
        (t >> 24) & 0xFF;
    pSect->pData[pPatch->nOffset + 1] =
        (t >> 16) & 0xFF;
    pSect->pData[pPatch->nOffset + 2] =
        (t >> 8) & 0xFF;
    pSect->pData[pPatch->nOffset + 3] = t & 0xFF;
    break;
   }
   pPatch = pPatch->pNext;
  }
  pSect = pSect->pNext;
 }
}

canonical_original_code:
void Patch()
{
 struct sSection *pSect;
 pSect = pSections;
 while (pSect) {
  struct sPatch *pPatch;
  pCurrentSection = pSect;
  pPatch = pSect->pPatches;
  while (pPatch) {
   long t;
   nPC = pSect->nOrg + pPatch->nOffset;
   t = calcrpn(pPatch);
   switch (pPatch->Type) {
   case PATCH_BYTE:
    if (t >= -128 && t <= 255) {
     t &= 0xFF;
     pSect->pData[pPatch->nOffset] =
         (unsigned char) t;
    } else {
     sprintf(temptext,
      "%s(%ld) : Value must be 8-bit\n",
      pPatch->pzFilename,
      pPatch->nLineNo);
     fatalerror(temptext);
    }
    break;
   case PATCH_WORD_L:
   case PATCH_WORD_B:
    if (t >= -32768 && t <= 65535) {
     t &= 0xFFFF;
     if (pPatch->Type == PATCH_WORD_L) {
      pSect->pData[pPatch->nOffset] =
          t & 0xFF;
      pSect->pData[pPatch->nOffset +
            1] =
          (t >> 8) & 0xFF;
     } else {
      pSect->pData[pPatch->nOffset] =
          (t >> 8) & 0xFF;
      pSect->pData[pPatch->nOffset +
            1] = t & 0xFF;
     }
    } else {
     sprintf(temptext,
      "%s(%ld) : Value must be 16-bit\n",
      pPatch->pzFilename,
      pPatch->nLineNo);
     fatalerror(temptext);
    }
    break;
   case PATCH_LONG_L:
    pSect->pData[pPatch->nOffset + 0] = t & 0xFF;
    pSect->pData[pPatch->nOffset + 1] =
        (t >> 8) & 0xFF;
    pSect->pData[pPatch->nOffset + 2] =
        (t >> 16) & 0xFF;
    pSect->pData[pPatch->nOffset + 3] =
        (t >> 24) & 0xFF;
    break;
   case PATCH_LONG_B:
    pSect->pData[pPatch->nOffset + 0] =
        (t >> 24) & 0xFF;
    pSect->pData[pPatch->nOffset + 1] =
        (t >> 16) & 0xFF;
    pSect->pData[pPatch->nOffset + 2] =
        (t >> 8) & 0xFF;
    pSect->pData[pPatch->nOffset + 3] = t & 0xFF;
    break;
   }
   pPatch = pPatch->pNext;
  }
  pSect = pSect->pNext;
 }
}


repo: vegard/rgbds-linux

decompiled_code:
__int64 __fastcall gbgfx2bin(char a1)
{
__int64 result; // rax

result = 0LL;
while ( CurrentOptions[result + 8] != a1 )
{
if ( ++result == 4 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 result; // rax

result = 0LL;
while ( CurrentOptions[result + 8] != a1 )
{
if ( ++result == 4 )
return 0LL;
}
return result;
}

original_code:
SLONG gbgfx2bin(char ch)
{
 SLONG i;
 for (i = 0; i <= 3; i += 1) {
  if (CurrentOptions.gbgfx[i] == ch) {
   return (i);
  }
 }
 return (0);
}

canonical_original_code:
long gbgfx2bin(char ch)
{
 long i;
 for (i = 0; i <= 3; i += 1) {
  if (CurrentOptions.gbgfx[i] == ch) {
   return (i);
  }
 }
 return (0);
}

variable_types: ch char

variable_types: i long

return_type: long


decompiled_code:
_BOOL8 __fastcall binary2bin(unsigned __int8 a1)
{
_BOOL8 result; // rax

if ( a1 == CurrentOptions[12] )
result = 0LL;
else
result = CurrentOptions[13] == a1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int8 a1)
{
_BOOL8 result; // rax

if ( a1 == CurrentOptions[12] )
result = 0LL;
else
result = CurrentOptions[13] == a1;
return result;
}

original_code:
SLONG binary2bin(char ch)
{
 SLONG i;
 for (i = 0; i <= 1; i += 1) {
  if (CurrentOptions.binary[i] == ch) {
   return (i);
  }
 }
 return (0);
}

canonical_original_code:
long binary2bin(char ch)
{
 long i;
 for (i = 0; i <= 1; i += 1) {
  if (CurrentOptions.binary[i] == ch) {
   return (i);
  }
 }
 return (0);
}


decompiled_code:
__int64 __fastcall char2bin(char a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 97) <= 5u )
return a1 - 87;
if ( (unsigned __int8)(a1 - 65) <= 5u )
return a1 - 55;
result = 0LL;
if ( (unsigned __int8)(a1 - 48) <= 9u )
result = a1 - 48;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 97) <= 5u )
return a1 - 87;
if ( (unsigned __int8)(a1 - 65) <= 5u )
return a1 - 55;
result = 0LL;
if ( (unsigned __int8)(a1 - 48) <= 9u )
result = a1 - 48;
return result;
}

original_code:
SLONG char2bin(char ch)
{
 if (ch >= 'a' && ch <= 'f')
  return (ch - 'a' + 10);
 if (ch >= 'A' && ch <= 'F')
  return (ch - 'A' + 10);
 if (ch >= '0' && ch <= '9')
  return (ch - '0');
 return (0);
}


ParseFixedPoint

decompiled_code:
__int64 __fastcall ParseFixedPoint(char *nptr, __int64 a2)
{
__int64 v3; // rdi
unsigned __int64 v4; // rax
__int64 v5; // rcx

v3 = a2;
if ( a2 )
{
v4 = 0LL;
v5 = 0LL;
do
{
v4 += nptr[v5] == 46;
if ( v4 <= 1 )
{
--v3;
++v5;
}
}
while ( v3 && v4 != 2 );
}
yyunputbytes(v3);
*(_QWORD *)&yylval = (unsigned int)(int)(atof(nptr) * 65536.0);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *nptr, __int64 a2)
{
__int64 v3; // rdi
unsigned __int64 v4; // rax
__int64 v5; // rcx

v3 = a2;
if ( a2 )
{
v4 = 0LL;
v5 = 0LL;
do
{
v4 += nptr[v5] == 46;
if ( v4 <= 1 )
{
--v3;
++v5;
}
}
while ( v3 && v4 != 2 );
}
yyunputbytes(v3);
*(_QWORD *)&yylval = (unsigned int)(int)(atof(nptr) * 65536.0);
return 1LL;
}

original_code:
ULONG ParseFixedPoint(char *s, ULONG size)
{
 char dest[256];
 ULONG i = 0, dot = 0;
 while (size && dot != 2) {
  if (s[i] == '.')
   dot += 1;
  if (dot < 2) {
   dest[i] = s[i];
   size -= 1;
   i += 1;
  }
 }
 dest[i] = 0;
 yyunputbytes(size);
 yylval.nConstValue = (SLONG) (atof(s) * 65536);
 return (1);
}

canonical_original_code:
unsigned long ParseFixedPoint(char *s, unsigned long size)
{
 char dest[256];
 unsigned long i = 0; unsigned long dot = 0;
 while (size && dot != 2) {
  if (s[i] == '.')
   dot += 1;
  if (dot < 2) {
   dest[i] = s[i];
   size -= 1;
   i += 1;
  }
 }
 dest[i] = 0;
 yyunputbytes(size);
 yylval.nConstValue = (SLONG) (atof(s) * 65536);
 return (1);
}

variable_types:
s
char *

variable_types:
size
unsigned long

variable_types:
dest
char [256]

variable_types:
i
unsigned long

variable_types:
dot
unsigned long

return_type: unsigned long


PutUniqueArg

decompiled_code:
__int64 __fastcall PutUniqueArg(__int64 a1, __int64 a2)
{
__int64 v2; // rax

yyskipbytes(a2);
v2 = sym_FindMacroArg(-1LL);
yyunputstr(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rax

yyskipbytes(a2);
v2 = sym_FindMacroArg(-1LL);
yyunputstr(v2);
return 0LL;
}

original_code:
ULONG PutUniqueArg(char *src, ULONG size)
{
 src = src;
 yyskipbytes(size);
 yyunputstr(sym_FindMacroArg(-1));
 return (0);
}

canonical_original_code:
unsigned long PutUniqueArg(char *src, unsigned long size)
{
 src = src;
 yyskipbytes(size);
 yyunputstr(sym_FindMacroArg(-1));
 return (0);
}

variable_types:
src
char *


ParseSymbol

decompiled_code:
__int64 __fastcall ParseSymbol(char *a1, __int64 a2)
{
__int64 v3; // r12
int v4; // ebx
char v5; // di
char *v6; // rcx
char v7; // al
__int64 result; // rax
char v9; // dl
__int64 v10; // rax
char *v11; // rcx
char *v12; // rbx
char v13; // al
char v14; // [rsp+1h] [rbp-139h]
char v15[312]; // [rsp+2h] [rbp-138h] BYREF

if ( a2 )
{
v3 = a2;
v4 = 0;
do
{
v7 = *a1;
if ( *a1 == 92 )
{
v5 = a1[1];
if ( v5 == 64 )
{
v6 = (char *)sym_FindMacroArg(-1LL);
}
else
{
if ( (unsigned __int8)(v5 - 48) > 9u )
{
fatalerror("Malformed ID");
return 0LL;
}
v6 = (char *)sym_FindMacroArg(v5);
}
a1 += 2;
v3 -= 2LL;
if ( v6 )
{
v9 = *v6;
if ( *v6 )
{
v10 = v4 + 1;
v11 = &v6[-v4];
do
{
v4 = v10;
*(&v14 + v10++) = v9;
v9 = v11[v10 - 1];
}
while ( v9 );
}
}
}
else
{
++a1;
v15[v4] = v7;
--v3;
++v4;
}
}
while ( v3 && v4 <= 255 );
if ( v4 > 256 )
fatalerror("Symbol too long");
}
else
{
v4 = 0;
}
v15[v4] = 0;
if ( !oDontExpandStrings && sym_isString(v15) )
{
yyskipbytes((int)a2);
v12 = (char *)sym_GetStringValue(v15);
yyunputstr(v12);
v13 = *v12;
if ( *v12 )
{
do
{
++v12;
if ( v13 == 10 )
--nLineNo;
v13 = *v12;
}
while ( *v12 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
strcpy(&yylval, v15);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, __int64 a2)
{
__int64 v3; // r12
int v4; // ebx
char v5; // di
char *v6; // rcx
char v7; // al
__int64 result; // rax
char v9; // dl
__int64 v10; // rax
char *v11; // rcx
char *v12; // rbx
char v13; // al
char v14; // [rsp+1h] [rbp-139h]
char v15[312]; // [rsp+2h] [rbp-138h] BYREF

if ( a2 )
{
v3 = a2;
v4 = 0;
do
{
v7 = *a1;
if ( *a1 == 92 )
{
v5 = a1[1];
if ( v5 == 64 )
{
v6 = (char *)sym_FindMacroArg(-1LL);
}
else
{
if ( (unsigned __int8)(v5 - 48) > 9u )
{
fatalerror("Malformed ID");
return 0LL;
}
v6 = (char *)sym_FindMacroArg(v5);
}
a1 += 2;
v3 -= 2LL;
if ( v6 )
{
v9 = *v6;
if ( *v6 )
{
v10 = v4 + 1;
v11 = &v6[-v4];
do
{
v4 = v10;
*(&v14 + v10++) = v9;
v9 = v11[v10 - 1];
}
while ( v9 );
}
}
}
else
{
++a1;
v15[v4] = v7;
--v3;
++v4;
}
}
while ( v3 && v4 <= 255 );
if ( v4 > 256 )
fatalerror("Symbol too long");
}
else
{
v4 = 0;
}
v15[v4] = 0;
if ( !oDontExpandStrings && sym_isString(v15) )
{
yyskipbytes((int)a2);
v12 = (char *)sym_GetStringValue(v15);
yyunputstr(v12);
v13 = *v12;
if ( *v12 )
{
do
{
++v12;
if ( v13 == 10 )
--nLineNo;
v13 = *v12;
}
while ( *v12 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
strcpy(&yylval, v15);
result = 1LL;
}
return result;
}

original_code:
ULONG ParseSymbol(char *src, ULONG size)
{
 char dest[256 + 1];
 int copied = 0, size_backup = size;
 while (size && copied < 256) {
  if (*src == '\\') {
   char *marg;
   src += 1;
   size -= 1;
   if (*src == '@')
    marg = sym_FindMacroArg(-1);
   else if (*src >= '0' && *src <= '9')
    marg = sym_FindMacroArg(*src);
   else {
    fatalerror("Malformed ID");
    return (0);
   }
   src += 1;
   size -= 1;
   if (marg) {
    while (*marg)
     dest[copied++] = *marg++;
   }
  } else {
   dest[copied++] = *src++;
   size -= 1;
  }
 }
 if (copied > 256)
  fatalerror("Symbol too long");
 dest[copied] = 0;
 if (oDontExpandStrings == 0 && sym_isString(dest)) {
  char *s;
  yyskipbytes(size_backup);
  yyunputstr(s = sym_GetStringValue(dest));
  while (*s) {
   if (*s++ == '\n') {
    nLineNo -= 1;
   }
  }
  return (0);
 } else {
  strcpy(yylval.tzString, dest);
  return (1);
 }
}

canonical_original_code:
unsigned long ParseSymbol(char *src, unsigned long size)
{
 char dest[-1];
 int copied = 0; int size_backup = size;
 while (size && copied < 256) {
  if (*src == '\\') {
   char *marg;
   src += 1;
   size -= 1;
   if (*src == '@')
    marg = sym_FindMacroArg(-1);
   else if (*src >= '0' && *src <= '9')
    marg = sym_FindMacroArg(*src);
   else {
    fatalerror("Malformed ID");
    return (0);
   }
   src += 1;
   size -= 1;
   if (marg) {
    while (*marg)
     dest[copied++] = *marg++;
   }
  } else {
   dest[copied++] = *src++;
   size -= 1;
  }
 }
 if (copied > 256)
  fatalerror("Symbol too long");
 dest[copied] = 0;
 if (oDontExpandStrings == 0 && sym_isString(dest)) {
  char *s;
  yyskipbytes(size_backup);
  yyunputstr(s = sym_GetStringValue(dest));
  while (*s) {
   if (*s++ == '\n') {
    nLineNo -= 1;
   }
  }
  return (0);
 } else {
  strcpy(yylval.tzString, dest);
  return (1);
 }
}

variable_types:
dest
char [-1]

variable_types: copied int

variable_types:
marg
char *


PutMacroArg

decompiled_code:
__int64 __fastcall PutMacroArg(__int64 a1, __int64 a2)
{
__int64 v2; // rax

yyskipbytes(a2);
v2 = sym_FindMacroArg(*(char *)(a1 + 1) - 48);
if ( v2 )
yyunputstr(v2);
else
yyerror("Macro argument not defined");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rax

yyskipbytes(a2);
v2 = sym_FindMacroArg(*(char *)(a1 + 1) - 48);
if ( v2 )
yyunputstr(v2);
else
yyerror("Macro argument not defined");
return 0LL;
}

original_code:
ULONG PutMacroArg(char *src, ULONG size)
{
 char *s;
 yyskipbytes(size);
 if ((s = sym_FindMacroArg(src[1] - '0')) != ((void *)0)) {
  yyunputstr(s);
 } else {
  yyerror("Macro argument not defined");
 }
 return (0);
}

canonical_original_code:
unsigned long PutMacroArg(char *src, unsigned long size)
{
 char *s;
 yyskipbytes(size);
 if ((s = sym_FindMacroArg(src[1] - '0')) != ((void *)0)) {
  yyunputstr(s);
 } else {
  yyerror("Macro argument not defined");
 }
 return (0);
}


decompiled_code:
__int64 __fastcall ascii2bin(unsigned __int8 *a1)
{
unsigned __int8 *v1; // r12
char v2; // al
_BOOL8 (__fastcall *v3)(unsigned __int8); // r13
__int64 v4; // rbp
char *v5; // rbp
char v6; // di
__int64 v7; // rbx
__int64 v8; // rax
unsigned __int8 v9; // di

v1 = a1;
v2 = *a1;
if ( *a1 == 38 )
{
v1 = a1 + 1;
v3 = (_BOOL8 (__fastcall *)(unsigned __int8))char2bin;
v4 = 8LL;
goto LABEL_12;
}
if ( v2 <= 38 )
{
if ( v2 == 36 )
{
v1 = a1 + 1;
v3 = (_BOOL8 (__fastcall *)(unsigned __int8))char2bin;
v4 = 16LL;
}
else if ( v2 == 37 )
{
v1 = a1 + 1;
v3 = binary2bin;
v4 = 2LL;
}
else
{
v3 = (_BOOL8 (__fastcall *)(unsigned __int8))char2bin;
v4 = 10LL;
}
LABEL_12:
v9 = *v1;
v7 = 0LL;
if ( !*v1 )
return v7;
goto LABEL_16;
}
if ( v2 != 96 )
{
v9 = *a1;
v3 = (_BOOL8 (__fastcall *)(unsigned __int8))char2bin;
v4 = 10LL;
LABEL_16:
v7 = 0LL;
do
{
++v1;
v7 = v3(v9) + v4 * v7;
v9 = *v1;
}
while ( *v1 );
return v7;
}
v5 = (char *)(a1 + 1);
v6 = a1[1];
v7 = 0LL;
if ( v6 )
{
do
{
++v5;
v8 = gbgfx2bin(v6);
v7 = ((v8 >> 1) & 1) + (((_WORD)v8 << 8) & 0x100) + 2 * v7;
v6 = *v5;
}
while ( *v5 );
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
unsigned __int8 *v1; // r12
char v2; // al
_BOOL8 (__fastcall *v3)(unsigned __int8); // r13
__int64 v4; // rbp
char *v5; // rbp
char v6; // di
__int64 v7; // rbx
__int64 v8; // rax
unsigned __int8 v9; // di

v1 = a1;
v2 = *a1;
if ( *a1 == 38 )
{
v1 = a1 + 1;
v3 = (_BOOL8 (__fastcall *)(unsigned __int8))char2bin;
v4 = 8LL;
goto LABEL_12;
}
if ( v2 <= 38 )
{
if ( v2 == 36 )
{
v1 = a1 + 1;
v3 = (_BOOL8 (__fastcall *)(unsigned __int8))char2bin;
v4 = 16LL;
}
else if ( v2 == 37 )
{
v1 = a1 + 1;
v3 = binary2bin;
v4 = 2LL;
}
else
{
v3 = (_BOOL8 (__fastcall *)(unsigned __int8))char2bin;
v4 = 10LL;
}
LABEL_12:
v9 = *v1;
v7 = 0LL;
if ( !*v1 )
return v7;
goto LABEL_16;
}
if ( v2 != 96 )
{
v9 = *a1;
v3 = (_BOOL8 (__fastcall *)(unsigned __int8))char2bin;
v4 = 10LL;
LABEL_16:
v7 = 0LL;
do
{
++v1;
v7 = v3(v9) + v4 * v7;
v9 = *v1;
}
while ( *v1 );
return v7;
}
v5 = (char *)(a1 + 1);
v6 = a1[1];
v7 = 0LL;
if ( v6 )
{
do
{
++v5;
v8 = func0(v6);
v7 = ((v8 >> 1) & 1) + (((_WORD)v8 << 8) & 0x100) + 2 * v7;
v6 = *v5;
}
while ( *v5 );
}
return v7;
}

original_code:
SLONG ascii2bin(char *s)
{
 SLONG radix = 10;
 SLONG result = 0;
 x2bin convertfunc = char2bin;
 switch (*s) {
 case '$':
  radix = 16;
  s += 1;
  convertfunc = char2bin;
  break;
 case '&':
  radix = 8;
  s += 1;
  convertfunc = char2bin;
  break;
 case '`':
  radix = 4;
  s += 1;
  convertfunc = gbgfx2bin;
  break;
 case '%':
  radix = 2;
  s += 1;
  convertfunc = binary2bin;
  break;
 }
 if (radix == 4) {
  SLONG c;
  while (*s != '\0') {
   c = convertfunc(*s++);
   result = result * 2 + ((c & 1) << 8) + ((c & 2) >> 1);
  }
 } else {
  while (*s != '\0')
   result = result * radix + convertfunc(*s++);
 }
 return (result);
}

canonical_original_code:
long ascii2bin(char *s)
{
 long radix = 10;
 long result = 0;
 long (*convertfunc)(char ch) = char2bin;
 switch (*s) {
 case '$':
  radix = 16;
  s += 1;
  convertfunc = char2bin;
  break;
 case '&':
  radix = 8;
  s += 1;
  convertfunc = char2bin;
  break;
 case '`':
  radix = 4;
  s += 1;
  convertfunc = gbgfx2bin;
  break;
 case '%':
  radix = 2;
  s += 1;
  convertfunc = binary2bin;
  break;
 }
 if (radix == 4) {
  long c;
  while (*s != '\0') {
   c = convertfunc(*s++);
   result = result * 2 + ((c & 1) << 8) + ((c & 2) >> 1);
  }
 } else {
  while (*s != '\0')
   result = result * radix + convertfunc(*s++);
 }
 return (result);
}

variable_types: radix long

variable_types: result long

variable_types:
convertfunc
long (*)(char ch)

variable_types: c long


ParseNumber

decompiled_code:
__int64 __fastcall ParseNumber(char *src, size_t n)
{
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

strncpy(v3, src, n);
v3[n] = 0;
*(_QWORD *)&yylval = ascii2bin((unsigned __int8 *)v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *src, size_t n)
{
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

strncpy(v3, src, n);
v3[n] = 0;
*(_QWORD *)&yylval = func7((unsigned __int8 *)v3);
return 1LL;
}

original_code:
ULONG ParseNumber(char *s, ULONG size)
{
 char dest[256];
 strncpy(dest, s, size);
 dest[size] = 0;
 yylval.nConstValue = ascii2bin(dest);
 return (1);
}

canonical_original_code:
unsigned long ParseNumber(char *s, unsigned long size)
{
 char dest[256];
 strncpy(dest, s, size);
 dest[size] = 0;
 yylval.nConstValue = ascii2bin(dest);
 return (1);
}


setuplex

decompiled_code:
__int64 setuplex()
{
__int64 v0; // rbx
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // rax
__int64 v10; // rbx

lex_Init();
lex_AddStrings(&staticstrings);
lex_AddStrings(&localstrings);
v0 = lex_FloatAlloc(&tMacroArgToken);
lex_FloatAddFirstRange(v0, 92LL, 92LL);
lex_FloatAddSecondRange(v0, 48LL, 57LL);
v1 = lex_FloatAlloc(&tMacroUniqueToken);
lex_FloatAddFirstRange(v1, 92LL, 92LL);
lex_FloatAddSecondRange(v1, 64LL, 64LL);
v2 = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(v2, 48LL, 57LL);
lex_FloatAddSecondRange(v2, 48LL, 57LL);
lex_FloatAddRange(v2, 48LL, 57LL);
v3 = lex_FloatAlloc(&tNumberToken);
nBinaryID = v3;
lex_FloatAddFirstRange(v3, 37LL, 37LL);
lex_FloatAddSecondRange(v3, (unsigned __int16)(char)CurrentOptions[12], (unsigned __int16)(char)CurrentOptions[12]);
lex_FloatAddSecondRange(v3, (unsigned __int16)(char)CurrentOptions[13], (unsigned __int16)(char)CurrentOptions[13]);
lex_FloatAddRange(v3, (unsigned __int16)(char)CurrentOptions[12], (unsigned __int16)(char)CurrentOptions[12]);
lex_FloatAddRange(v3, (unsigned __int16)(char)CurrentOptions[13], (unsigned __int16)(char)CurrentOptions[13]);
v4 = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(v4, 38LL, 38LL);
lex_FloatAddSecondRange(v4, 48LL, 55LL);
lex_FloatAddRange(v4, 48LL, 55LL);
v5 = lex_FloatAlloc(&tNumberToken);
nGBGfxID = v5;
lex_FloatAddFirstRange(v5, 96LL, 96LL);
lex_FloatAddSecondRange(v5, (unsigned __int16)(char)CurrentOptions[8], (unsigned __int16)(char)CurrentOptions[8]);
lex_FloatAddSecondRange(v5, (unsigned __int16)(char)CurrentOptions[9], (unsigned __int16)(char)CurrentOptions[9]);
lex_FloatAddSecondRange(v5, (unsigned __int16)(char)CurrentOptions[10], (unsigned __int16)(char)CurrentOptions[10]);
lex_FloatAddSecondRange(v5, (unsigned __int16)(char)CurrentOptions[11], (unsigned __int16)(char)CurrentOptions[11]);
lex_FloatAddRange(v5, (unsigned __int16)(char)CurrentOptions[8], (unsigned __int16)(char)CurrentOptions[8]);
lex_FloatAddRange(v5, (unsigned __int16)(char)CurrentOptions[9], (unsigned __int16)(char)CurrentOptions[9]);
lex_FloatAddRange(v5, (unsigned __int16)(char)CurrentOptions[10], (unsigned __int16)(char)CurrentOptions[10]);
lex_FloatAddRange(v5, (unsigned __int16)(char)CurrentOptions[11], (unsigned __int16)(char)CurrentOptions[11]);
v6 = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(v6, 36LL, 36LL);
lex_FloatAddSecondRange(v6, 48LL, 57LL);
lex_FloatAddSecondRange(v6, 65LL, 70LL);
lex_FloatAddSecondRange(v6, 97LL, 102LL);
lex_FloatAddRange(v6, 48LL, 57LL);
lex_FloatAddRange(v6, 65LL, 70LL);
lex_FloatAddRange(v6, 97LL, 102LL);
v7 = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(v7, 97LL, 122LL);
lex_FloatAddFirstRange(v7, 65LL, 90LL);
lex_FloatAddFirstRange(v7, 95LL, 95LL);
lex_FloatAddSecondRange(v7, 97LL, 122LL);
lex_FloatAddSecondRange(v7, 65LL, 90LL);
lex_FloatAddSecondRange(v7, 48LL, 57LL);
lex_FloatAddSecondRange(v7, 95LL, 95LL);
lex_FloatAddSecondRange(v7, 92LL, 92LL);
lex_FloatAddSecondRange(v7, 64LL, 64LL);
lex_FloatAddSecondRange(v7, 35LL, 35LL);
lex_FloatAddRange(v7, 97LL, 122LL);
lex_FloatAddRange(v7, 65LL, 90LL);
lex_FloatAddRange(v7, 48LL, 57LL);
lex_FloatAddRange(v7, 95LL, 95LL);
lex_FloatAddRange(v7, 92LL, 92LL);
lex_FloatAddRange(v7, 64LL, 64LL);
lex_FloatAddRange(v7, 35LL, 35LL);
v8 = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(v8, 46LL, 46LL);
lex_FloatAddSecondRange(v8, 97LL, 122LL);
lex_FloatAddSecondRange(v8, 65LL, 90LL);
lex_FloatAddSecondRange(v8, 95LL, 95LL);
lex_FloatAddRange(v8, 97LL, 122LL);
lex_FloatAddRange(v8, 65LL, 90LL);
lex_FloatAddRange(v8, 48LL, 57LL);
lex_FloatAddRange(v8, 95LL, 95LL);
lex_FloatAddRange(v8, 92LL, 92LL);
lex_FloatAddRange(v8, 64LL, 64LL);
lex_FloatAddRange(v8, 35LL, 35LL);
v9 = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(v9, 64LL, 64LL);
v10 = lex_FloatAlloc(&tFixedPointToken);
lex_FloatAddFirstRange(v10, 46LL, 46LL);
lex_FloatAddFirstRange(v10, 48LL, 57LL);
lex_FloatAddSecondRange(v10, 46LL, 46LL);
lex_FloatAddSecondRange(v10, 48LL, 57LL);
lex_FloatAddRange(v10, 46LL, 46LL);
return lex_FloatAddRange(v10, 48LL, 57LL);
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rbx
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // rax
__int64 v10; // rbx

lex_Init();
lex_AddStrings(&staticstrings);
lex_AddStrings(&localstrings);
v0 = lex_FloatAlloc(&tMacroArgToken);
lex_FloatAddFirstRange(v0, 92LL, 92LL);
lex_FloatAddSecondRange(v0, 48LL, 57LL);
v1 = lex_FloatAlloc(&tMacroUniqueToken);
lex_FloatAddFirstRange(v1, 92LL, 92LL);
lex_FloatAddSecondRange(v1, 64LL, 64LL);
v2 = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(v2, 48LL, 57LL);
lex_FloatAddSecondRange(v2, 48LL, 57LL);
lex_FloatAddRange(v2, 48LL, 57LL);
v3 = lex_FloatAlloc(&tNumberToken);
nBinaryID = v3;
lex_FloatAddFirstRange(v3, 37LL, 37LL);
lex_FloatAddSecondRange(v3, (unsigned __int16)(char)CurrentOptions[12], (unsigned __int16)(char)CurrentOptions[12]);
lex_FloatAddSecondRange(v3, (unsigned __int16)(char)CurrentOptions[13], (unsigned __int16)(char)CurrentOptions[13]);
lex_FloatAddRange(v3, (unsigned __int16)(char)CurrentOptions[12], (unsigned __int16)(char)CurrentOptions[12]);
lex_FloatAddRange(v3, (unsigned __int16)(char)CurrentOptions[13], (unsigned __int16)(char)CurrentOptions[13]);
v4 = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(v4, 38LL, 38LL);
lex_FloatAddSecondRange(v4, 48LL, 55LL);
lex_FloatAddRange(v4, 48LL, 55LL);
v5 = lex_FloatAlloc(&tNumberToken);
nGBGfxID = v5;
lex_FloatAddFirstRange(v5, 96LL, 96LL);
lex_FloatAddSecondRange(v5, (unsigned __int16)(char)CurrentOptions[8], (unsigned __int16)(char)CurrentOptions[8]);
lex_FloatAddSecondRange(v5, (unsigned __int16)(char)CurrentOptions[9], (unsigned __int16)(char)CurrentOptions[9]);
lex_FloatAddSecondRange(v5, (unsigned __int16)(char)CurrentOptions[10], (unsigned __int16)(char)CurrentOptions[10]);
lex_FloatAddSecondRange(v5, (unsigned __int16)(char)CurrentOptions[11], (unsigned __int16)(char)CurrentOptions[11]);
lex_FloatAddRange(v5, (unsigned __int16)(char)CurrentOptions[8], (unsigned __int16)(char)CurrentOptions[8]);
lex_FloatAddRange(v5, (unsigned __int16)(char)CurrentOptions[9], (unsigned __int16)(char)CurrentOptions[9]);
lex_FloatAddRange(v5, (unsigned __int16)(char)CurrentOptions[10], (unsigned __int16)(char)CurrentOptions[10]);
lex_FloatAddRange(v5, (unsigned __int16)(char)CurrentOptions[11], (unsigned __int16)(char)CurrentOptions[11]);
v6 = lex_FloatAlloc(&tNumberToken);
lex_FloatAddFirstRange(v6, 36LL, 36LL);
lex_FloatAddSecondRange(v6, 48LL, 57LL);
lex_FloatAddSecondRange(v6, 65LL, 70LL);
lex_FloatAddSecondRange(v6, 97LL, 102LL);
lex_FloatAddRange(v6, 48LL, 57LL);
lex_FloatAddRange(v6, 65LL, 70LL);
lex_FloatAddRange(v6, 97LL, 102LL);
v7 = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(v7, 97LL, 122LL);
lex_FloatAddFirstRange(v7, 65LL, 90LL);
lex_FloatAddFirstRange(v7, 95LL, 95LL);
lex_FloatAddSecondRange(v7, 97LL, 122LL);
lex_FloatAddSecondRange(v7, 65LL, 90LL);
lex_FloatAddSecondRange(v7, 48LL, 57LL);
lex_FloatAddSecondRange(v7, 95LL, 95LL);
lex_FloatAddSecondRange(v7, 92LL, 92LL);
lex_FloatAddSecondRange(v7, 64LL, 64LL);
lex_FloatAddSecondRange(v7, 35LL, 35LL);
lex_FloatAddRange(v7, 97LL, 122LL);
lex_FloatAddRange(v7, 65LL, 90LL);
lex_FloatAddRange(v7, 48LL, 57LL);
lex_FloatAddRange(v7, 95LL, 95LL);
lex_FloatAddRange(v7, 92LL, 92LL);
lex_FloatAddRange(v7, 64LL, 64LL);
lex_FloatAddRange(v7, 35LL, 35LL);
v8 = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(v8, 46LL, 46LL);
lex_FloatAddSecondRange(v8, 97LL, 122LL);
lex_FloatAddSecondRange(v8, 65LL, 90LL);
lex_FloatAddSecondRange(v8, 95LL, 95LL);
lex_FloatAddRange(v8, 97LL, 122LL);
lex_FloatAddRange(v8, 65LL, 90LL);
lex_FloatAddRange(v8, 48LL, 57LL);
lex_FloatAddRange(v8, 95LL, 95LL);
lex_FloatAddRange(v8, 92LL, 92LL);
lex_FloatAddRange(v8, 64LL, 64LL);
lex_FloatAddRange(v8, 35LL, 35LL);
v9 = lex_FloatAlloc(&tIDToken);
lex_FloatAddFirstRange(v9, 64LL, 64LL);
v10 = lex_FloatAlloc(&tFixedPointToken);
lex_FloatAddFirstRange(v10, 46LL, 46LL);
lex_FloatAddFirstRange(v10, 48LL, 57LL);
lex_FloatAddSecondRange(v10, 46LL, 46LL);
lex_FloatAddSecondRange(v10, 48LL, 57LL);
lex_FloatAddRange(v10, 46LL, 46LL);
return lex_FloatAddRange(v10, 48LL, 57LL);
}

original_code:
void setuplex(void)
{
 ULONG id;
 lex_Init();
 lex_AddStrings(staticstrings);
 lex_AddStrings(localstrings);
 id = lex_FloatAlloc(&tMacroArgToken);
 lex_FloatAddFirstRange(id, '\\', '\\');
 lex_FloatAddSecondRange(id, '0', '9');
 id = lex_FloatAlloc(&tMacroUniqueToken);
 lex_FloatAddFirstRange(id, '\\', '\\');
 lex_FloatAddSecondRange(id, '@', '@');
 id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '0', '9');
 lex_FloatAddSecondRange(id, '0', '9');
 lex_FloatAddRange(id, '0', '9');
 nBinaryID = id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '%', '%');
 lex_FloatAddSecondRange(id, CurrentOptions.binary[0],
    CurrentOptions.binary[0]);
 lex_FloatAddSecondRange(id, CurrentOptions.binary[1],
    CurrentOptions.binary[1]);
 lex_FloatAddRange(id, CurrentOptions.binary[0],
     CurrentOptions.binary[0]);
 lex_FloatAddRange(id, CurrentOptions.binary[1],
     CurrentOptions.binary[1]);
 id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '&', '&');
 lex_FloatAddSecondRange(id, '0', '7');
 lex_FloatAddRange(id, '0', '7');
 nGBGfxID = id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '`', '`');
 lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[0],
    CurrentOptions.gbgfx[0]);
 lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[1],
    CurrentOptions.gbgfx[1]);
 lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[2],
    CurrentOptions.gbgfx[2]);
 lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[3],
    CurrentOptions.gbgfx[3]);
 lex_FloatAddRange(id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
 lex_FloatAddRange(id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
 lex_FloatAddRange(id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
 lex_FloatAddRange(id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
 id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '$', '$');
 lex_FloatAddSecondRange(id, '0', '9');
 lex_FloatAddSecondRange(id, 'A', 'F');
 lex_FloatAddSecondRange(id, 'a', 'f');
 lex_FloatAddRange(id, '0', '9');
 lex_FloatAddRange(id, 'A', 'F');
 lex_FloatAddRange(id, 'a', 'f');
 id = lex_FloatAlloc(&tIDToken);
 lex_FloatAddFirstRange(id, 'a', 'z');
 lex_FloatAddFirstRange(id, 'A', 'Z');
 lex_FloatAddFirstRange(id, '_', '_');
 lex_FloatAddSecondRange(id, 'a', 'z');
 lex_FloatAddSecondRange(id, 'A', 'Z');
 lex_FloatAddSecondRange(id, '0', '9');
 lex_FloatAddSecondRange(id, '_', '_');
 lex_FloatAddSecondRange(id, '\\', '\\');
 lex_FloatAddSecondRange(id, '@', '@');
 lex_FloatAddSecondRange(id, '#', '#');
 lex_FloatAddRange(id, 'a', 'z');
 lex_FloatAddRange(id, 'A', 'Z');
 lex_FloatAddRange(id, '0', '9');
 lex_FloatAddRange(id, '_', '_');
 lex_FloatAddRange(id, '\\', '\\');
 lex_FloatAddRange(id, '@', '@');
 lex_FloatAddRange(id, '#', '#');
 id = lex_FloatAlloc(&tIDToken);
 lex_FloatAddFirstRange(id, '.', '.');
 lex_FloatAddSecondRange(id, 'a', 'z');
 lex_FloatAddSecondRange(id, 'A', 'Z');
 lex_FloatAddSecondRange(id, '_', '_');
 lex_FloatAddRange(id, 'a', 'z');
 lex_FloatAddRange(id, 'A', 'Z');
 lex_FloatAddRange(id, '0', '9');
 lex_FloatAddRange(id, '_', '_');
 lex_FloatAddRange(id, '\\', '\\');
 lex_FloatAddRange(id, '@', '@');
 lex_FloatAddRange(id, '#', '#');
 id = lex_FloatAlloc(&tIDToken);
 lex_FloatAddFirstRange(id, '@', '@');
 id = lex_FloatAlloc(&tFixedPointToken);
 lex_FloatAddFirstRange(id, '.', '.');
 lex_FloatAddFirstRange(id, '0', '9');
 lex_FloatAddSecondRange(id, '.', '.');
 lex_FloatAddSecondRange(id, '0', '9');
 lex_FloatAddRange(id, '.', '.');
 lex_FloatAddRange(id, '0', '9');
}

canonical_original_code:
void setuplex()
{
 unsigned long id;
 lex_Init();
 lex_AddStrings(staticstrings);
 lex_AddStrings(localstrings);
 id = lex_FloatAlloc(&tMacroArgToken);
 lex_FloatAddFirstRange(id, '\\', '\\');
 lex_FloatAddSecondRange(id, '0', '9');
 id = lex_FloatAlloc(&tMacroUniqueToken);
 lex_FloatAddFirstRange(id, '\\', '\\');
 lex_FloatAddSecondRange(id, '@', '@');
 id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '0', '9');
 lex_FloatAddSecondRange(id, '0', '9');
 lex_FloatAddRange(id, '0', '9');
 nBinaryID = id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '%', '%');
 lex_FloatAddSecondRange(id, CurrentOptions.binary[0],
    CurrentOptions.binary[0]);
 lex_FloatAddSecondRange(id, CurrentOptions.binary[1],
    CurrentOptions.binary[1]);
 lex_FloatAddRange(id, CurrentOptions.binary[0],
     CurrentOptions.binary[0]);
 lex_FloatAddRange(id, CurrentOptions.binary[1],
     CurrentOptions.binary[1]);
 id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '&', '&');
 lex_FloatAddSecondRange(id, '0', '7');
 lex_FloatAddRange(id, '0', '7');
 nGBGfxID = id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '`', '`');
 lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[0],
    CurrentOptions.gbgfx[0]);
 lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[1],
    CurrentOptions.gbgfx[1]);
 lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[2],
    CurrentOptions.gbgfx[2]);
 lex_FloatAddSecondRange(id, CurrentOptions.gbgfx[3],
    CurrentOptions.gbgfx[3]);
 lex_FloatAddRange(id, CurrentOptions.gbgfx[0], CurrentOptions.gbgfx[0]);
 lex_FloatAddRange(id, CurrentOptions.gbgfx[1], CurrentOptions.gbgfx[1]);
 lex_FloatAddRange(id, CurrentOptions.gbgfx[2], CurrentOptions.gbgfx[2]);
 lex_FloatAddRange(id, CurrentOptions.gbgfx[3], CurrentOptions.gbgfx[3]);
 id = lex_FloatAlloc(&tNumberToken);
 lex_FloatAddFirstRange(id, '$', '$');
 lex_FloatAddSecondRange(id, '0', '9');
 lex_FloatAddSecondRange(id, 'A', 'F');
 lex_FloatAddSecondRange(id, 'a', 'f');
 lex_FloatAddRange(id, '0', '9');
 lex_FloatAddRange(id, 'A', 'F');
 lex_FloatAddRange(id, 'a', 'f');
 id = lex_FloatAlloc(&tIDToken);
 lex_FloatAddFirstRange(id, 'a', 'z');
 lex_FloatAddFirstRange(id, 'A', 'Z');
 lex_FloatAddFirstRange(id, '_', '_');
 lex_FloatAddSecondRange(id, 'a', 'z');
 lex_FloatAddSecondRange(id, 'A', 'Z');
 lex_FloatAddSecondRange(id, '0', '9');
 lex_FloatAddSecondRange(id, '_', '_');
 lex_FloatAddSecondRange(id, '\\', '\\');
 lex_FloatAddSecondRange(id, '@', '@');
 lex_FloatAddSecondRange(id, '#', '#');
 lex_FloatAddRange(id, 'a', 'z');
 lex_FloatAddRange(id, 'A', 'Z');
 lex_FloatAddRange(id, '0', '9');
 lex_FloatAddRange(id, '_', '_');
 lex_FloatAddRange(id, '\\', '\\');
 lex_FloatAddRange(id, '@', '@');
 lex_FloatAddRange(id, '#', '#');
 id = lex_FloatAlloc(&tIDToken);
 lex_FloatAddFirstRange(id, '.', '.');
 lex_FloatAddSecondRange(id, 'a', 'z');
 lex_FloatAddSecondRange(id, 'A', 'Z');
 lex_FloatAddSecondRange(id, '_', '_');
 lex_FloatAddRange(id, 'a', 'z');
 lex_FloatAddRange(id, 'A', 'Z');
 lex_FloatAddRange(id, '0', '9');
 lex_FloatAddRange(id, '_', '_');
 lex_FloatAddRange(id, '\\', '\\');
 lex_FloatAddRange(id, '@', '@');
 lex_FloatAddRange(id, '#', '#');
 id = lex_FloatAlloc(&tIDToken);
 lex_FloatAddFirstRange(id, '@', '@');
 id = lex_FloatAlloc(&tFixedPointToken);
 lex_FloatAddFirstRange(id, '.', '.');
 lex_FloatAddFirstRange(id, '0', '9');
 lex_FloatAddSecondRange(id, '.', '.');
 lex_FloatAddSecondRange(id, '0', '9');
 lex_FloatAddRange(id, '.', '.');
 lex_FloatAddRange(id, '0', '9');
}

variable_types:
id
unsigned long

return_type: void


decompiled_code:
__int64 __fastcall opt_SetCurrentOptions(const __m128i *a1)
{
__int64 result; // rax

if ( nGBGfxID != -1LL )
{
lex_FloatDeleteRange(nGBGfxID, (unsigned __int16)SBYTE8(CurrentOptions), (unsigned __int16)SBYTE8(CurrentOptions));
lex_FloatDeleteRange(nGBGfxID, (unsigned __int16)SBYTE9(CurrentOptions), (unsigned __int16)SBYTE9(CurrentOptions));
lex_FloatDeleteRange(nGBGfxID, (unsigned __int16)SBYTE10(CurrentOptions), (unsigned __int16)SBYTE10(CurrentOptions));
lex_FloatDeleteRange(nGBGfxID, (unsigned __int16)SBYTE11(CurrentOptions), (unsigned __int16)SBYTE11(CurrentOptions));
lex_FloatDeleteSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE8(CurrentOptions),
(unsigned __int16)SBYTE8(CurrentOptions));
lex_FloatDeleteSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE9(CurrentOptions),
(unsigned __int16)SBYTE9(CurrentOptions));
lex_FloatDeleteSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE10(CurrentOptions),
(unsigned __int16)SBYTE10(CurrentOptions));
lex_FloatDeleteSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE11(CurrentOptions),
(unsigned __int16)SBYTE11(CurrentOptions));
}
if ( nBinaryID != -1LL )
{
lex_FloatDeleteRange(
nBinaryID,
(unsigned __int16)SBYTE12(CurrentOptions),
(unsigned __int16)SBYTE12(CurrentOptions));
lex_FloatDeleteRange(
nBinaryID,
(unsigned __int16)SBYTE13(CurrentOptions),
(unsigned __int16)SBYTE13(CurrentOptions));
lex_FloatDeleteSecondRange(
nBinaryID,
(unsigned __int16)SBYTE12(CurrentOptions),
(unsigned __int16)SBYTE12(CurrentOptions));
lex_FloatDeleteSecondRange(
nBinaryID,
(unsigned __int16)SBYTE13(CurrentOptions),
(unsigned __int16)SBYTE13(CurrentOptions));
}
CurrentOptions = (__int128)_mm_loadu_si128(a1);
result = a1[1].m128i_i64[0];
*((_QWORD *)&CurrentOptions + 2) = result;
if ( nGBGfxID != -1LL )
{
lex_FloatAddRange(nGBGfxID, (unsigned __int16)SBYTE8(CurrentOptions), (unsigned __int16)SBYTE8(CurrentOptions));
lex_FloatAddRange(nGBGfxID, (unsigned __int16)SBYTE9(CurrentOptions), (unsigned __int16)SBYTE9(CurrentOptions));
lex_FloatAddRange(nGBGfxID, (unsigned __int16)SBYTE10(CurrentOptions), (unsigned __int16)SBYTE10(CurrentOptions));
lex_FloatAddRange(nGBGfxID, (unsigned __int16)SBYTE11(CurrentOptions), (unsigned __int16)SBYTE11(CurrentOptions));
lex_FloatAddSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE8(CurrentOptions),
(unsigned __int16)SBYTE8(CurrentOptions));
lex_FloatAddSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE9(CurrentOptions),
(unsigned __int16)SBYTE9(CurrentOptions));
lex_FloatAddSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE10(CurrentOptions),
(unsigned __int16)SBYTE10(CurrentOptions));
result = lex_FloatAddSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE11(CurrentOptions),
(unsigned __int16)SBYTE11(CurrentOptions));
}
if ( nBinaryID != -1LL )
{
lex_FloatAddRange(nBinaryID, (unsigned __int16)SBYTE12(CurrentOptions), (unsigned __int16)SBYTE12(CurrentOptions));
lex_FloatAddRange(nBinaryID, (unsigned __int16)SBYTE13(CurrentOptions), (unsigned __int16)SBYTE13(CurrentOptions));
lex_FloatAddSecondRange(
nBinaryID,
(unsigned __int16)SBYTE12(CurrentOptions),
(unsigned __int16)SBYTE12(CurrentOptions));
result = lex_FloatAddSecondRange(
nBinaryID,
(unsigned __int16)SBYTE13(CurrentOptions),
(unsigned __int16)SBYTE13(CurrentOptions));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const __m128i *a1)
{
__int64 result; // rax

if ( nGBGfxID != -1LL )
{
lex_FloatDeleteRange(nGBGfxID, (unsigned __int16)SBYTE8(CurrentOptions), (unsigned __int16)SBYTE8(CurrentOptions));
lex_FloatDeleteRange(nGBGfxID, (unsigned __int16)SBYTE9(CurrentOptions), (unsigned __int16)SBYTE9(CurrentOptions));
lex_FloatDeleteRange(nGBGfxID, (unsigned __int16)SBYTE10(CurrentOptions), (unsigned __int16)SBYTE10(CurrentOptions));
lex_FloatDeleteRange(nGBGfxID, (unsigned __int16)SBYTE11(CurrentOptions), (unsigned __int16)SBYTE11(CurrentOptions));
lex_FloatDeleteSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE8(CurrentOptions),
(unsigned __int16)SBYTE8(CurrentOptions));
lex_FloatDeleteSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE9(CurrentOptions),
(unsigned __int16)SBYTE9(CurrentOptions));
lex_FloatDeleteSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE10(CurrentOptions),
(unsigned __int16)SBYTE10(CurrentOptions));
lex_FloatDeleteSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE11(CurrentOptions),
(unsigned __int16)SBYTE11(CurrentOptions));
}
if ( nBinaryID != -1LL )
{
lex_FloatDeleteRange(
nBinaryID,
(unsigned __int16)SBYTE12(CurrentOptions),
(unsigned __int16)SBYTE12(CurrentOptions));
lex_FloatDeleteRange(
nBinaryID,
(unsigned __int16)SBYTE13(CurrentOptions),
(unsigned __int16)SBYTE13(CurrentOptions));
lex_FloatDeleteSecondRange(
nBinaryID,
(unsigned __int16)SBYTE12(CurrentOptions),
(unsigned __int16)SBYTE12(CurrentOptions));
lex_FloatDeleteSecondRange(
nBinaryID,
(unsigned __int16)SBYTE13(CurrentOptions),
(unsigned __int16)SBYTE13(CurrentOptions));
}
CurrentOptions = (__int128)_mm_loadu_si128(a1);
result = a1[1].m128i_i64[0];
*((_QWORD *)&CurrentOptions + 2) = result;
if ( nGBGfxID != -1LL )
{
lex_FloatAddRange(nGBGfxID, (unsigned __int16)SBYTE8(CurrentOptions), (unsigned __int16)SBYTE8(CurrentOptions));
lex_FloatAddRange(nGBGfxID, (unsigned __int16)SBYTE9(CurrentOptions), (unsigned __int16)SBYTE9(CurrentOptions));
lex_FloatAddRange(nGBGfxID, (unsigned __int16)SBYTE10(CurrentOptions), (unsigned __int16)SBYTE10(CurrentOptions));
lex_FloatAddRange(nGBGfxID, (unsigned __int16)SBYTE11(CurrentOptions), (unsigned __int16)SBYTE11(CurrentOptions));
lex_FloatAddSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE8(CurrentOptions),
(unsigned __int16)SBYTE8(CurrentOptions));
lex_FloatAddSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE9(CurrentOptions),
(unsigned __int16)SBYTE9(CurrentOptions));
lex_FloatAddSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE10(CurrentOptions),
(unsigned __int16)SBYTE10(CurrentOptions));
result = lex_FloatAddSecondRange(
nGBGfxID,
(unsigned __int16)SBYTE11(CurrentOptions),
(unsigned __int16)SBYTE11(CurrentOptions));
}
if ( nBinaryID != -1LL )
{
lex_FloatAddRange(nBinaryID, (unsigned __int16)SBYTE12(CurrentOptions), (unsigned __int16)SBYTE12(CurrentOptions));
lex_FloatAddRange(nBinaryID, (unsigned __int16)SBYTE13(CurrentOptions), (unsigned __int16)SBYTE13(CurrentOptions));
lex_FloatAddSecondRange(
nBinaryID,
(unsigned __int16)SBYTE12(CurrentOptions),
(unsigned __int16)SBYTE12(CurrentOptions));
result = lex_FloatAddSecondRange(
nBinaryID,
(unsigned __int16)SBYTE13(CurrentOptions),
(unsigned __int16)SBYTE13(CurrentOptions));
}
return result;
}

original_code:
void opt_SetCurrentOptions(struct sOptions *pOpt)
{
 if (nGBGfxID != -1) {
  lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[0],
         CurrentOptions.gbgfx[0]);
  lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[1],
         CurrentOptions.gbgfx[1]);
  lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[2],
         CurrentOptions.gbgfx[2]);
  lex_FloatDeleteRange(nGBGfxID, CurrentOptions.gbgfx[3],
         CurrentOptions.gbgfx[3]);
  lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
        CurrentOptions.gbgfx[0]);
  lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
        CurrentOptions.gbgfx[1]);
  lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
        CurrentOptions.gbgfx[2]);
  lex_FloatDeleteSecondRange(nGBGfxID, CurrentOptions.gbgfx[3],
        CurrentOptions.gbgfx[3]);
 }
 if (nBinaryID != -1) {
  lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[0],
         CurrentOptions.binary[0]);
  lex_FloatDeleteRange(nBinaryID, CurrentOptions.binary[1],
         CurrentOptions.binary[1]);
  lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[0],
        CurrentOptions.binary[0]);
  lex_FloatDeleteSecondRange(nBinaryID, CurrentOptions.binary[1],
        CurrentOptions.binary[1]);
 }
 CurrentOptions = *pOpt;
 if (nGBGfxID != -1) {
  lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[0],
      CurrentOptions.gbgfx[0]);
  lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[1],
      CurrentOptions.gbgfx[1]);
  lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[2],
      CurrentOptions.gbgfx[2]);
  lex_FloatAddRange(nGBGfxID, CurrentOptions.gbgfx[3],
      CurrentOptions.gbgfx[3]);
  lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[0],
     CurrentOptions.gbgfx[0]);
  lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[1],
     CurrentOptions.gbgfx[1]);
  lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[2],
     CurrentOptions.gbgfx[2]);
  lex_FloatAddSecondRange(nGBGfxID, CurrentOptions.gbgfx[3],
     CurrentOptions.gbgfx[3]);
 }
 if (nBinaryID != -1) {
  lex_FloatAddRange(nBinaryID, CurrentOptions.binary[0],
      CurrentOptions.binary[0]);
  lex_FloatAddRange(nBinaryID, CurrentOptions.binary[1],
      CurrentOptions.binary[1]);
  lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[0],
     CurrentOptions.binary[0]);
  lex_FloatAddSecondRange(nBinaryID, CurrentOptions.binary[1],
     CurrentOptions.binary[1]);
 }
}

variable_types: struct sOptions { unsigned long endian; char gbgfx[4]; char binary[2]; long fillchar; } *


yyerror

decompiled_code:
int __fastcall yyerror(const char *a1)
{
int result; // eax

printf("*ERROR*\t");
fstk_Dump();
result = printf(" :\n\t%s\n", a1);
++nErrors;
return result;
}

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

printf("*ERROR*\t");
fstk_Dump();
result = printf(" :\n\t%s\n", a1);
++nErrors;
return result;
}

original_code:
void yyerror(char *s)
{
 printf("*ERROR*\t");
 fstk_Dump();
 printf(" :\n\t%s\n", s);
 nErrors += 1;
}


decompiled_code:
__int64 __fastcall opt_Parse(__int64 a1)
{
char v1; // al
char v2; // al
const char *v3; // rbx
__m128i v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+10h] [rbp-18h] BYREF

v5 = _mm_load_si128((const __m128i *)&CurrentOptions);
v6 = *((_QWORD *)&CurrentOptions + 2);
v1 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 103 )
{
if ( strlen((const char *)(a1 + 1)) != 4 )
{
puts("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'");
exit(5);
}
v5.m128i_i32[2] = *(_DWORD *)(a1 + 1);
}
else if ( v1 > 103 )
{
if ( v1 != 122 )
goto LABEL_24;
v3 = (const char *)(a1 + 1);
if ( strlen((const char *)(a1 + 1)) > 2 )
{
puts("*ERROR*\t :\n\tInvalid argument for option 'z'");
exit(5);
}
if ( !strcmp(v3, "?") )
{
v6 = -1LL;
}
else if ( (((unsigned int)_isoc99_sscanf(v3, "%lx", &v6) + 1) & 0xFFFFFFFD) != 0 )
{
puts("*ERROR*\t :\n\tInvalid argument for option 'z'");
exit(5);
}
}
else
{
if ( v1 != 98 )
{
if ( v1 == 101 )
{
v2 = *(_BYTE *)(a1 + 1);
if ( v2 == 98 )
{
v5.m128i_i64[0] = 1LL;
puts("*WARNING*\t :\n\tEndianness forced to BIG for destination CPU");
}
else
{
if ( v2 != 108 )
{
puts("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'");
exit(5);
}
v5.m128i_i64[0] = 0LL;
puts("*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU");
}
return opt_SetCurrentOptions(&v5);
}
LABEL_24:
fatalerror("Unknown option");
}
if ( strlen((const char *)(a1 + 1)) != 2 )
{
puts("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'");
exit(5);
}
v5.m128i_i16[6] = *(_WORD *)(a1 + 1);
}
return opt_SetCurrentOptions(&v5);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
char v1; // al
char v2; // al
const char *v3; // rbx
__m128i v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+10h] [rbp-18h] BYREF

v5 = _mm_load_si128((const __m128i *)&CurrentOptions);
v6 = *((_QWORD *)&CurrentOptions + 2);
v1 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 103 )
{
if ( strlen((const char *)(a1 + 1)) != 4 )
{
puts("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'");
exit(5);
}
v5.m128i_i32[2] = *(_DWORD *)(a1 + 1);
}
else if ( v1 > 103 )
{
if ( v1 != 122 )
goto LABEL_24;
v3 = (const char *)(a1 + 1);
if ( strlen((const char *)(a1 + 1)) > 2 )
{
puts("*ERROR*\t :\n\tInvalid argument for option 'z'");
exit(5);
}
if ( !strcmp(v3, "?") )
{
v6 = -1LL;
}
else if ( (((unsigned int)_isoc99_sscanf(v3, "%lx", &v6) + 1) & 0xFFFFFFFD) != 0 )
{
puts("*ERROR*\t :\n\tInvalid argument for option 'z'");
exit(5);
}
}
else
{
if ( v1 != 98 )
{
if ( v1 == 101 )
{
v2 = *(_BYTE *)(a1 + 1);
if ( v2 == 98 )
{
v5.m128i_i64[0] = 1LL;
puts("*WARNING*\t :\n\tEndianness forced to BIG for destination CPU");
}
else
{
if ( v2 != 108 )
{
puts("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'");
exit(5);
}
v5.m128i_i64[0] = 0LL;
puts("*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU");
}
return func0(&v5);
}
LABEL_24:
func2("Unknown option");
}
if ( strlen((const char *)(a1 + 1)) != 2 )
{
puts("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'");
exit(5);
}
v5.m128i_i16[6] = *(_WORD *)(a1 + 1);
}
return func0(&v5);
}

original_code:
void opt_Parse(char *s)
{
 struct sOptions newopt;
 newopt = CurrentOptions;
 switch (s[0]) {
 case 'e':
  switch (s[1]) {
  case 'b':
   newopt.endian = 1;
   printf
       ("*WARNING*\t :\n\tEndianness forced to BIG for destination CPU\n");
   break;
  case 'l':
   newopt.endian = 0;
   printf
       ("*WARNING*\t :\n\tEndianness forced to LITTLE for destination CPU\n");
   break;
  default:
   printf
       ("*ERROR*\t :\n\tArgument to option -e must be 'b' or 'l'\n");
   exit(5);
  }
  break;
 case 'g':
  if (strlen(&s[1]) == 4) {
   newopt.gbgfx[0] = s[1];
   newopt.gbgfx[1] = s[2];
   newopt.gbgfx[2] = s[3];
   newopt.gbgfx[3] = s[4];
  } else {
   printf
       ("*ERROR*\t :\n\tMust specify exactly 4 characters for option 'g'\n");
   exit(5);
  }
  break;
 case 'b':
  if (strlen(&s[1]) == 2) {
   newopt.binary[0] = s[1];
   newopt.binary[1] = s[2];
  } else {
   printf
       ("*ERROR*\t :\n\tMust specify exactly 2 characters for option 'b'\n");
   exit(5);
  }
  break;
 case 'z':
  if (strlen(&s[1]) <= 2) {
   if (strcmp(&s[1], "?") == 0) {
    newopt.fillchar = -1;
   } else {
    int result;
    result = sscanf(&s[1], "%lx", &newopt.fillchar);
    if (!((result == (-1)) || (result == 1))) {
     printf
         ("*ERROR*\t :\n\tInvalid argument for option 'z'\n");
     exit(5);
    }
   }
  } else {
   printf
       ("*ERROR*\t :\n\tInvalid argument for option 'z'\n");
   exit(5);
  }
  break;
 default:
  fatalerror("Unknown option");
  break;
 }
 opt_SetCurrentOptions(&newopt);
}

variable_types: struct sOptions { unsigned long endian; char gbgfx[4]; char binary[2]; long fillchar; }

variable_types: result int


decompiled_code:
__m128i *opt_Push()
{
__m128i *result; // rax

result = (__m128i *)malloc(0x20uLL);
if ( !result )
fatalerror("No memory for option stack");
*result = _mm_load_si128((const __m128i *)&CurrentOptions);
result[1].m128i_i64[0] = *((_QWORD *)&CurrentOptions + 2);
result[1].m128i_i64[1] = (__int64)pOptionStack;
pOptionStack = result;
return result;
}

canonical_decompiled_code:
__m128i *func4()
{
__m128i *result; // rax

result = (__m128i *)malloc(0x20uLL);
if ( !result )
func2("No memory for option stack");
*result = _mm_load_si128((const __m128i *)&CurrentOptions);
result[1].m128i_i64[0] = *((_QWORD *)&CurrentOptions + 2);
result[1].m128i_i64[1] = (__int64)pOptionStack;
pOptionStack = result;
return result;
}

original_code:
void opt_Push(void)
{
 struct sOptionStackEntry *pOpt;
 if ((pOpt =
      (struct sOptionStackEntry *)
      malloc(sizeof(struct sOptionStackEntry))) != ((void *)0)) {
  pOpt->Options = CurrentOptions;
  pOpt->pNext = pOptionStack;
  pOptionStack = pOpt;
 } else
  fatalerror("No memory for option stack");
}

canonical_original_code:
void opt_Push()
{
 struct sOptionStackEntry *pOpt;
 if ((pOpt =
      (struct sOptionStackEntry *)
      malloc(sizeof(struct sOptionStackEntry))) != ((void *)0)) {
  pOpt->Options = CurrentOptions;
  pOpt->pNext = pOptionStack;
  pOptionStack = pOpt;
 } else
  fatalerror("No memory for option stack");
}

variable_types: struct sOptionStackEntry { struct sOptions { unsigned long endian; char gbgfx[4]; char binary[2]; long fillchar; } Options; struct sOptionStackEntry *pNext; } *

user_defined_types: struct sOptionStackEntry { struct sOptions Options; struct sOptionStackEntry *pNext; }


decompiled_code:
void opt_Pop()
{
_QWORD *v0; // rbx

v0 = pOptionStack;
if ( !pOptionStack )
fatalerror("No entries in the option stack");
opt_SetCurrentOptions((const __m128i *)pOptionStack);
pOptionStack = (void *)v0[3];
free(v0);
}

canonical_decompiled_code:
void func5()
{
_QWORD *v0; // rbx

v0 = pOptionStack;
if ( !pOptionStack )
func2("No entries in the option stack");
func0((const __m128i *)pOptionStack);
pOptionStack = (void *)v0[3];
free(v0);
}

original_code:
void opt_Pop(void)
{
 if (pOptionStack) {
  struct sOptionStackEntry *pOpt;
  pOpt = pOptionStack;
  opt_SetCurrentOptions(&(pOpt->Options));
  pOptionStack = pOpt->pNext;
  free(pOpt);
 } else
  fatalerror("No entries in the option stack");
}

canonical_original_code:
void opt_Pop()
{
 if (pOptionStack) {
  struct sOptionStackEntry *pOpt;
  pOpt = pOptionStack;
  opt_SetCurrentOptions(&(pOpt->Options));
  pOptionStack = pOpt->pNext;
  free(pOpt);
 } else
  fatalerror("No entries in the option stack");
}

user_defined_types: struct sOptions { unsigned long endian; char gbgfx[4]; char binary[2]; long fillchar; }


fatalerror

decompiled_code:
void __fastcall __noreturn fatalerror(const char *a1)
{
yyerror(a1);
exit(5);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
func1(a1);
exit(5);
}

original_code:
void fatalerror(char *s)
{
 yyerror(s);
 exit(5);
}

variable_types:
s
char *


PrintUsage

decompiled_code:
void __noreturn PrintUsage()
{
puts("RGBAsm v1.08c (part of ASMotor 1.10-linux-g74eea59)\n\nUsage: rgbasm [options] asmfile");
puts("Options:");
puts("\t-h\t\tThis text");
puts("\t-i<path>\tExtra include path");
puts("\t-o<file>\tWrite objectoutput to <file>");
puts("\t-e(l|b)\t\tChange endianness (CAUTION!)");
puts("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n\t\t\tconstants (default is 0123)");
puts("\t-b<AS>\t\tChange the two characters used for binary constants\n\t\t\t(default is 01)");
puts("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n\t\t\tdata (default is ? for random)");
exit(0);
}

canonical_decompiled_code:
void __noreturn func6()
{
puts("RGBAsm v1.08c (part of ASMotor 1.10-linux-g74eea59)\n\nUsage: rgbasm [options] asmfile");
puts("Options:");
puts("\t-h\t\tThis text");
puts("\t-i<path>\tExtra include path");
puts("\t-o<file>\tWrite objectoutput to <file>");
puts("\t-e(l|b)\t\tChange endianness (CAUTION!)");
puts("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n\t\t\tconstants (default is 0123)");
puts("\t-b<AS>\t\tChange the two characters used for binary constants\n\t\t\t(default is 01)");
puts("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n\t\t\tdata (default is ? for random)");
exit(0);
}

original_code:
void PrintUsage(void)
{
 printf("RGBAsm" " v" "1.08c" " (part of ASMotor " "1.10-linux" "-g74eea59"
        ")\n\nUsage: " "rgbasm" " [options] asmfile\n");
 printf("Options:\n");
 printf("\t-h\t\tThis text\n");
 printf("\t-i<path>\tExtra include path\n");
 printf("\t-o<file>\tWrite objectoutput to <file>\n");
 printf("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
 printf
     ("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
      "\t\t\tconstants (default is 0123)\n");
 printf
     ("\t-b<AS>\t\tChange the two characters used for binary constants\n"
      "\t\t\t(default is 01)\n");
 printf
     ("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
      "\t\t\tdata (default is ? for random)\n");
 exit(0);
}

canonical_original_code:
void PrintUsage()
{
 printf("RGBAsm" " v" "1.08c" " (part of ASMotor " "1.10-linux" "-g74eea59"
        ")\n\nUsage: " "rgbasm" " [options] asmfile\n");
 printf("Options:\n");
 printf("\t-h\t\tThis text\n");
 printf("\t-i<path>\tExtra include path\n");
 printf("\t-o<file>\tWrite objectoutput to <file>\n");
 printf("\t-e(l|b)\t\tChange endianness (CAUTION!)\n");
 printf
     ("\t-g<ASCI>\tChange the four characters used for Gameboy graphics\n"
      "\t\t\tconstants (default is 0123)\n");
 printf
     ("\t-b<AS>\t\tChange the two characters used for binary constants\n"
      "\t\t\t(default is 01)\n");
 printf
     ("\t-z<hx>\t\tSet the byte value (hex format) used for uninitialised\n"
      "\t\t\tdata (default is ? for random)\n");
 exit(0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm1_8
__int64 v4; // rdi
int v5; // ebp
const char *v6; // rdi
const char **v7; // rbx
const char **v8; // rax
__int64 v9; // rdx
const char *v10; // rbx
double v11; // xmm2_8
double v12; // xmm0_8
int result; // eax
double v14; // xmm0_8

v4 = (unsigned int)(argc - 1);
if ( !(_DWORD)v4 )
PrintUsage(v4, argv, envp);
v5 = v4;
*(_QWORD *)&DefaultOptions = 0LL;
BYTE8(DefaultOptions) = 48;
BYTE9(DefaultOptions) = 49;
BYTE10(DefaultOptions) = 50;
BYTE11(DefaultOptions) = 51;
BYTE12(DefaultOptions) = 48;
BYTE13(DefaultOptions) = 49;
*((_QWORD *)&DefaultOptions + 2) = -1LL;
opt_SetCurrentOptions((const __m128i *)&DefaultOptions);
v6 = argv[1];
if ( *v6 == 45 )
{
v7 = argv + 2;
do
{
v9 = *((unsigned __int8 *)v6 + 1);
switch ( (char)v9 )
{
case 'b':
case 'e':
case 'g':
case 'z':
opt_Parse((__int64)(v6 + 1));
break;
case 'h':
PrintUsage(v6, argv, v9);
return result;
case 'i':
fstk_AddIncludePath(v6 + 2);
break;
case 'o':
out_SetFileName(v6 + 2);
break;
default:
printf("*ERROR*\t :\n\tUnknown option '%c'\n", (unsigned int)(char)v9);
exit(5);
}
--v5;
v8 = v7;
v6 = *v7++;
}
while ( *v6 == 45 && v5 );
}
else
{
v8 = argv + 1;
}
DefaultOptions = (__int128)_mm_load_si128((const __m128i *)&CurrentOptions);
*((_QWORD *)&DefaultOptions + 2) = *((_QWORD *)&CurrentOptions + 2);
v10 = *v8;
setuplex();
printf("Assembling %s\n", v10);
nStartClock = clock();
nLineNo = 1LL;
nTotalLines = 0LL;
nIFDepth = 0LL;
nPC = 0LL;
nPass = 1LL;
nErrors = 0LL;
sym_PrepPass1();
if ( !fstk_Init(v10) )
{
printf("File '%s' not found\n", v10);
exit(5);
}
puts("Pass 1...");
yy_set_state(0LL);
opt_SetCurrentOptions((const __m128i *)&DefaultOptions);
if ( (unsigned int)yyparse() || nErrors )
{
printf("Assembly aborted in pass 1 (%ld errors)!\n", nErrors);
exit(5);
}
if ( nIFDepth )
{
printf("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n", nIFDepth);
exit(5);
}
nTotalLines = 0LL;
nLineNo = 1LL;
nIFDepth = 0LL;
nPC = 0LL;
nPass = 2LL;
nErrors = 0LL;
sym_PrepPass2();
out_PrepPass2();
fstk_Init(v10);
yy_set_state(0LL);
opt_SetCurrentOptions((const __m128i *)&DefaultOptions);
puts("Pass 2...");
if ( (unsigned int)yyparse() || nErrors )
{
printf("Assembly aborted in pass 2 (%ld errors)!\n", nErrors);
exit(5);
}
nEndClock = clock();
v11 = (double)((int)nEndClock - (int)nStartClock) / 1000000.0;
v12 = v11 * 100.0;
printf(
"Success! %ld lines in %d.%02d seconds ",
nTotalLines,
(unsigned int)(int)v11,
(unsigned int)((int)(v11 * 100.0) % 100));
if ( v11 == 0.0 )
{
puts("(INFINITY lines/minute)");
}
else
{
if ( nTotalLines < 0 )
v14 = (double)(int)(nTotalLines & 1 | ((unsigned __int64)nTotalLines >> 1))
+ (double)(int)(nTotalLines & 1 | ((unsigned __int64)nTotalLines >> 1));
else
v14 = (double)(int)nTotalLines;
v3 = 60.0 / v11;
v12 = v14 * (60.0 / v11);
printf("(%d lines/minute)\n", (unsigned int)(int)v12);
}
out_WriteObject(v12, v3, v11);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm1_8
__int64 v4; // rdi
int v5; // ebp
const char *v6; // rdi
const char **v7; // rbx
const char **v8; // rax
__int64 v9; // rdx
const char *v10; // rbx
double v11; // xmm2_8
double v12; // xmm0_8
int result; // eax
double v14; // xmm0_8

v4 = (unsigned int)(argc - 1);
if ( !(_DWORD)v4 )
func6(v4, argv, envp);
v5 = v4;
*(_QWORD *)&DefaultOptions = 0LL;
BYTE8(DefaultOptions) = 48;
BYTE9(DefaultOptions) = 49;
BYTE10(DefaultOptions) = 50;
BYTE11(DefaultOptions) = 51;
BYTE12(DefaultOptions) = 48;
BYTE13(DefaultOptions) = 49;
*((_QWORD *)&DefaultOptions + 2) = -1LL;
func0((const __m128i *)&DefaultOptions);
v6 = argv[1];
if ( *v6 == 45 )
{
v7 = argv + 2;
do
{
v9 = *((unsigned __int8 *)v6 + 1);
switch ( (char)v9 )
{
case 'b':
case 'e':
case 'g':
case 'z':
func3((__int64)(v6 + 1));
break;
case 'h':
func6(v6, argv, v9);
return result;
case 'i':
fstk_AddIncludePath(v6 + 2);
break;
case 'o':
out_SetFileName(v6 + 2);
break;
default:
printf("*ERROR*\t :\n\tUnknown option '%c'\n", (unsigned int)(char)v9);
exit(5);
}
--v5;
v8 = v7;
v6 = *v7++;
}
while ( *v6 == 45 && v5 );
}
else
{
v8 = argv + 1;
}
DefaultOptions = (__int128)_mm_load_si128((const __m128i *)&CurrentOptions);
*((_QWORD *)&DefaultOptions + 2) = *((_QWORD *)&CurrentOptions + 2);
v10 = *v8;
setuplex();
printf("Assembling %s\n", v10);
nStartClock = clock();
nLineNo = 1LL;
nTotalLines = 0LL;
nIFDepth = 0LL;
nPC = 0LL;
nPass = 1LL;
nErrors = 0LL;
sym_PrepPass1();
if ( !fstk_Init(v10) )
{
printf("File '%s' not found\n", v10);
exit(5);
}
puts("Pass 1...");
yy_set_state(0LL);
func0((const __m128i *)&DefaultOptions);
if ( (unsigned int)yyparse() || nErrors )
{
printf("Assembly aborted in pass 1 (%ld errors)!\n", nErrors);
exit(5);
}
if ( nIFDepth )
{
printf("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n", nIFDepth);
exit(5);
}
nTotalLines = 0LL;
nLineNo = 1LL;
nIFDepth = 0LL;
nPC = 0LL;
nPass = 2LL;
nErrors = 0LL;
sym_PrepPass2();
out_PrepPass2();
fstk_Init(v10);
yy_set_state(0LL);
func0((const __m128i *)&DefaultOptions);
puts("Pass 2...");
if ( (unsigned int)yyparse() || nErrors )
{
printf("Assembly aborted in pass 2 (%ld errors)!\n", nErrors);
exit(5);
}
nEndClock = clock();
v11 = (double)((int)nEndClock - (int)nStartClock) / 1000000.0;
v12 = v11 * 100.0;
printf(
"Success! %ld lines in %d.%02d seconds ",
nTotalLines,
(unsigned int)(int)v11,
(unsigned int)((int)(v11 * 100.0) % 100));
if ( v11 == 0.0 )
{
puts("(INFINITY lines/minute)");
}
else
{
if ( nTotalLines < 0 )
v14 = (double)(int)(nTotalLines & 1 | ((unsigned __int64)nTotalLines >> 1))
+ (double)(int)(nTotalLines & 1 | ((unsigned __int64)nTotalLines >> 1));
else
v14 = (double)(int)nTotalLines;
v3 = 60.0 / v11;
v12 = v14 * (60.0 / v11);
printf("(%d lines/minute)\n", (unsigned int)(int)v12);
}
out_WriteObject(v12, v3, v11);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char *tzMainfile;
 int argn = 1;
 argc -= 1;
 if (argc == 0)
  PrintUsage();
 DefaultOptions.endian = 0;
 DefaultOptions.gbgfx[0] = '0';
 DefaultOptions.gbgfx[1] = '1';
 DefaultOptions.gbgfx[2] = '2';
 DefaultOptions.gbgfx[3] = '3';
 DefaultOptions.binary[0] = '0';
 DefaultOptions.binary[1] = '1';
 DefaultOptions.fillchar = -1;
 opt_SetCurrentOptions(&DefaultOptions);
 while (argv[argn][0] == '-' && argc) {
  switch (argv[argn][1]) {
  case 'h':
   PrintUsage();
   break;
  case 'i':
   fstk_AddIncludePath(&(argv[argn][2]));
   break;
  case 'o':
   out_SetFileName(&(argv[argn][2]));
   break;
  case 'e':
  case 'g':
  case 'b':
  case 'z':
   opt_Parse(&argv[argn][1]);
   break;
  default:
   printf("*ERROR*\t :\n\tUnknown option '%c'\n",
          argv[argn][1]);
   exit(5);
   break;
  }
  argn += 1;
  argc -= 1;
 }
 DefaultOptions = CurrentOptions;
 tzMainfile = argv[argn];
 setuplex();
 printf("Assembling %s\n", tzMainfile);
 nStartClock = clock();
 nLineNo = 1;
 nTotalLines = 0;
 nIFDepth = 0;
 nPC = 0;
 nPass = 1;
 nErrors = 0;
 sym_PrepPass1();
 if (fstk_Init(tzMainfile)) {
  printf("Pass 1...\n");
  yy_set_state(LEX_STATE_NORMAL);
  opt_SetCurrentOptions(&DefaultOptions);
  if (yyparse() == 0 && nErrors == 0) {
   if (nIFDepth == 0) {
    nTotalLines = 0;
    nLineNo = 1;
    nIFDepth = 0;
    nPC = 0;
    nPass = 2;
    nErrors = 0;
    sym_PrepPass2();
    out_PrepPass2();
    fstk_Init(tzMainfile);
    yy_set_state(LEX_STATE_NORMAL);
    opt_SetCurrentOptions(&DefaultOptions);
    printf("Pass 2...\n");
    if (yyparse() == 0 && nErrors == 0) {
     double timespent;
     nEndClock = clock();
     timespent =
         ((double)(nEndClock - nStartClock))
         / (double)((__clock_t) 1000000);
     printf
         ("Success! %ld lines in %d.%02d seconds ",
          nTotalLines, (int)timespent,
          ((int)(timespent * 100.0)) % 100);
     if (timespent == 0)
      printf
          ("(INFINITY lines/minute)\n");
     else
      printf("(%d lines/minute)\n",
             (int)(60 / timespent *
            nTotalLines));
     out_WriteObject();
    } else {
     printf
         ("Assembly aborted in pass 2 (%ld errors)!\n",
          nErrors);
     exit(5);
    }
   } else {
    printf
        ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n",
         nIFDepth);
    exit(5);
   }
  } else {
   printf("Assembly aborted in pass 1 (%ld errors)!\n",
          nErrors);
   exit(5);
  }
 } else {
  printf("File '%s' not found\n", tzMainfile);
  exit(5);
 }
 return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *tzMainfile;
 int argn = 1;
 argc -= 1;
 if (argc == 0)
  PrintUsage();
 DefaultOptions.endian = 0;
 DefaultOptions.gbgfx[0] = '0';
 DefaultOptions.gbgfx[1] = '1';
 DefaultOptions.gbgfx[2] = '2';
 DefaultOptions.gbgfx[3] = '3';
 DefaultOptions.binary[0] = '0';
 DefaultOptions.binary[1] = '1';
 DefaultOptions.fillchar = -1;
 opt_SetCurrentOptions(&DefaultOptions);
 while (argv[argn][0] == '-' && argc) {
  switch (argv[argn][1]) {
  case 'h':
   PrintUsage();
   break;
  case 'i':
   fstk_AddIncludePath(&(argv[argn][2]));
   break;
  case 'o':
   out_SetFileName(&(argv[argn][2]));
   break;
  case 'e':
  case 'g':
  case 'b':
  case 'z':
   opt_Parse(&argv[argn][1]);
   break;
  default:
   printf("*ERROR*\t :\n\tUnknown option '%c'\n",
          argv[argn][1]);
   exit(5);
   break;
  }
  argn += 1;
  argc -= 1;
 }
 DefaultOptions = CurrentOptions;
 tzMainfile = argv[argn];
 setuplex();
 printf("Assembling %s\n", tzMainfile);
 nStartClock = clock();
 nLineNo = 1;
 nTotalLines = 0;
 nIFDepth = 0;
 nPC = 0;
 nPass = 1;
 nErrors = 0;
 sym_PrepPass1();
 if (fstk_Init(tzMainfile)) {
  printf("Pass 1...\n");
  yy_set_state(LEX_STATE_NORMAL);
  opt_SetCurrentOptions(&DefaultOptions);
  if (yyparse() == 0 && nErrors == 0) {
   if (nIFDepth == 0) {
    nTotalLines = 0;
    nLineNo = 1;
    nIFDepth = 0;
    nPC = 0;
    nPass = 2;
    nErrors = 0;
    sym_PrepPass2();
    out_PrepPass2();
    fstk_Init(tzMainfile);
    yy_set_state(LEX_STATE_NORMAL);
    opt_SetCurrentOptions(&DefaultOptions);
    printf("Pass 2...\n");
    if (yyparse() == 0 && nErrors == 0) {
     double timespent;
     nEndClock = clock();
     timespent =
         ((double)(nEndClock - nStartClock))
         / (double)((long) 1000000);
     printf
         ("Success! %ld lines in %d.%02d seconds ",
          nTotalLines, (int)timespent,
          ((int)(timespent * 100.0)) % 100);
     if (timespent == 0)
      printf
          ("(INFINITY lines/minute)\n");
     else
      printf("(%d lines/minute)\n",
             (int)(60 / timespent *
            nTotalLines));
     out_WriteObject();
    } else {
     printf
         ("Assembly aborted in pass 2 (%ld errors)!\n",
          nErrors);
     exit(5);
    }
   } else {
    printf
        ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n",
         nIFDepth);
    exit(5);
   }
  } else {
   printf("Assembly aborted in pass 1 (%ld errors)!\n",
          nErrors);
   exit(5);
  }
 } else {
  printf("File '%s' not found\n", tzMainfile);
  exit(5);
 }
 return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
tzMainfile
char *

variable_types: argn int

variable_types: timespent double

return_type: int


decompiled_code:
__int64 __fastcall sym_GetValue(char *s1)
{
__int64 result; // rax
__int64 v2; // rbx

if ( !strcmp(s1, "@") )
return nPC;
v2 = tHash[calchash(s1)];
if ( v2 )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
goto LABEL_6;
}
result = *(_QWORD *)(v2 + 8);
}
else
{
LABEL_6:
sprintf(&temptext, "Unknown symbol '%s'", s1);
fatalerror(&temptext);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
__int64 result; // rax
__int64 v2; // rbx

if ( !strcmp(s1, "@") )
return nPC;
v2 = tHash[func0(s1)];
if ( v2 )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
goto LABEL_6;
}
result = *(_QWORD *)(v2 + 8);
}
else
{
LABEL_6:
sprintf(&temptext, "Unknown symbol '%s'", s1);
fatalerror(&temptext);
result = 0LL;
}
return result;
}

original_code:
SLONG sym_GetValue(char *tzName)
{
 if (strcmp(tzName, "@") == 0) {
  return (nPC);
 } else {
  struct ISymbol **ppSym;
  ppSym = &(tHash[calchash(tzName)]);
  while (*ppSym) {
   if (strcmp(tzName, (*ppSym)->pzName)) {
    ppSym = &((*ppSym)->pNext);
   } else {
    return ((*ppSym)->nValue);
   }
  }
  sprintf(temptext, "Unknown symbol '%s'", tzName);
  fatalerror(temptext);
  return (0);
 }
}

canonical_original_code:
long sym_GetValue(char *tzName)
{
 if (strcmp(tzName, "@") == 0) {
  return (nPC);
 } else {
  struct ISymbol **ppSym;
  ppSym = &(tHash[calchash(tzName)]);
  while (*ppSym) {
   if (strcmp(tzName, (*ppSym)->pzName)) {
    ppSym = &((*ppSym)->pNext);
   } else {
    return ((*ppSym)->nValue);
   }
  }
  sprintf(temptext, "Unknown symbol '%s'", tzName);
  fatalerror(temptext);
  return (0);
 }
}

variable_types:
tzName
char *

variable_types: struct ISymbol { char *pzName; long nValue; long nBank; struct ISymbol *pNext; } **


decompiled_code:
__int64 __fastcall sym_GetBank(char *s1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = tHash[calchash(s1)];
if ( v1 )
{
while ( strcmp(s1, *(const char **)v1) )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
goto LABEL_4;
}
result = *(_QWORD *)(v1 + 16);
}
else
{
LABEL_4:
sprintf(&temptext, "Unknown symbol '%s'", s1);
fatalerror(&temptext);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = tHash[func0(s1)];
if ( v1 )
{
while ( strcmp(s1, *(const char **)v1) )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
goto LABEL_4;
}
result = *(_QWORD *)(v1 + 16);
}
else
{
LABEL_4:
sprintf(&temptext, "Unknown symbol '%s'", s1);
fatalerror(&temptext);
result = 0LL;
}
return result;
}

original_code:
SLONG sym_GetBank(char *tzName)
{
 struct ISymbol **ppSym;
 ppSym = &(tHash[calchash(tzName)]);
 while (*ppSym) {
  if (strcmp(tzName, (*ppSym)->pzName)) {
   ppSym = &((*ppSym)->pNext);
  } else {
   return ((*ppSym)->nBank);
  }
 }
 sprintf(temptext, "Unknown symbol '%s'", tzName);
 fatalerror(temptext);
 return (0);
}

canonical_original_code:
long sym_GetBank(char *tzName)
{
 struct ISymbol **ppSym;
 ppSym = &(tHash[calchash(tzName)]);
 while (*ppSym) {
  if (strcmp(tzName, (*ppSym)->pzName)) {
   ppSym = &((*ppSym)->pNext);
  } else {
   return ((*ppSym)->nBank);
  }
 }
 sprintf(temptext, "Unknown symbol '%s'", tzName);
 fatalerror(temptext);
 return (0);
}

user_defined_types: struct ISymbol { char *pzName; long nValue; long nBank; struct ISymbol *pNext; }


decompiled_code:
char __fastcall sym_CreateSymbol(char *src, char *a2, char a3)
{
bool v3; // zf
char **v4; // rax
char v5; // r13
char ***v7; // r12
char **i; // rbx
_QWORD *v9; // rbx
size_t v10; // rax

v3 = strcmp(src, "@") == 0;
LOBYTE(v4) = !v3;
if ( !v3 )
{
v5 = a3;
v7 = (char ***)&tHash[calchash(src)];
for ( i = *v7; *v7; i = *v7 )
{
LODWORD(v4) = strcmp(src, *i);
if ( (_DWORD)v4 )
{
v7 = (char ***)(i + 3);
}
else
{
if ( a3 == -1 )
return (char)v4;
sprintf(&temptext, "Symbol '%s' defined more than once\n", src);
fatalerror(&temptext);
}
}
v4 = (char **)malloc(0x20uLL);
v9 = v4;
*v7 = v4;
if ( v4 )
{
v10 = strlen(src);
v4 = (char **)malloc(v10 + 1);
*v9 = v4;
if ( v4 )
{
strcpy(**v7, src);
(*v7)[1] = a2;
(*v7)[2] = (char *)v5;
v4 = *v7;
(*v7)[3] = 0LL;
}
}
}
return (char)v4;
}

canonical_decompiled_code:
char __fastcall func4(char *src, char *a2, char a3)
{
bool v3; // zf
char **v4; // rax
char v5; // r13
char ***v7; // r12
char **i; // rbx
_QWORD *v9; // rbx
size_t v10; // rax

v3 = strcmp(src, "@") == 0;
LOBYTE(v4) = !v3;
if ( !v3 )
{
v5 = a3;
v7 = (char ***)&tHash[func0(src)];
for ( i = *v7; *v7; i = *v7 )
{
LODWORD(v4) = strcmp(src, *i);
if ( (_DWORD)v4 )
{
v7 = (char ***)(i + 3);
}
else
{
if ( a3 == -1 )
return (char)v4;
sprintf(&temptext, "Symbol '%s' defined more than once\n", src);
fatalerror(&temptext);
}
}
v4 = (char **)malloc(0x20uLL);
v9 = v4;
*v7 = v4;
if ( v4 )
{
v10 = strlen(src);
v4 = (char **)malloc(v10 + 1);
*v9 = v4;
if ( v4 )
{
strcpy(**v7, src);
(*v7)[1] = a2;
(*v7)[2] = (char *)v5;
v4 = *v7;
(*v7)[3] = 0LL;
}
}
}
return (char)v4;
}

original_code:
void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
{
 if (strcmp(tzName, "@") == 0)
  return;
 struct ISymbol **ppSym;
 ppSym = &(tHash[calchash(tzName)]);
 while (*ppSym) {
  if (strcmp(tzName, (*ppSym)->pzName)) {
   ppSym = &((*ppSym)->pNext);
  } else {
   if (nBank == -1)
    return;
   sprintf(temptext,
     "Symbol '%s' defined more than once\n",
     tzName);
   fatalerror(temptext);
  }
 }
 if ((*ppSym = malloc(sizeof **ppSym))) {
  if (((*ppSym)->pzName = malloc(strlen(tzName) + 1))) {
   strcpy((*ppSym)->pzName, tzName);
   (*ppSym)->nValue = nValue;
   (*ppSym)->nBank = nBank;
   (*ppSym)->pNext = ((void *)0);
  }
 }
}

canonical_original_code:
void sym_CreateSymbol(char *tzName, long nValue, char nBank)
{
 if (strcmp(tzName, "@") == 0)
  return;
 struct ISymbol **ppSym;
 ppSym = &(tHash[calchash(tzName)]);
 while (*ppSym) {
  if (strcmp(tzName, (*ppSym)->pzName)) {
   ppSym = &((*ppSym)->pNext);
  } else {
   if (nBank == -1)
    return;
   sprintf(temptext,
     "Symbol '%s' defined more than once\n",
     tzName);
   fatalerror(temptext);
  }
 }
 if ((*ppSym = malloc(sizeof **ppSym))) {
  if (((*ppSym)->pzName = malloc(strlen(tzName) + 1))) {
   strcpy((*ppSym)->pzName, tzName);
   (*ppSym)->nValue = nValue;
   (*ppSym)->nBank = nBank;
   (*ppSym)->pNext = ((void *)0);
  }
 }
}

variable_types: nValue long

variable_types: nBank char


calchash

decompiled_code:
__int64 __fastcall calchash(char *a1)
{
char v1; // al
__int64 v2; // rcx

v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
do
{
++a1;
v2 += v1;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0LL;
}
return v2 % 73;
}

original_code:
SLONG calchash(char *s)
{
 SLONG r = 0;
 while (*s)
  r += *s++;
 return (r % 73);
}

canonical_original_code:
long calchash(char *s)
{
 long r = 0;
 while (*s)
  r += *s++;
 return (r % 73);
}

variable_types: r long


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

for ( result = 0LL; result != 73; ++result )
tHash[result] = 0LL;
return result;
}

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

for ( result = 0LL; result != 73; ++result )
tHash[result] = 0LL;
return result;
}

original_code:
void sym_Init(void)
{
 SLONG i;
 for (i = 0; i < 73; i += 1)
  tHash[i] = ((void *)0);
}

canonical_original_code:
void sym_Init()
{
 long i;
 for (i = 0; i < 73; i += 1)
  tHash[i] = ((void *)0);
}

variable_types: i long


FatalError

decompiled_code:
void __fastcall __noreturn FatalError(const char *a1)
{
printf("\n***ERROR: %s\n\n", a1);
PrintUsage();
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
printf("\n***ERROR: %s\n\n", a1);
func7();
}

original_code:
void FatalError(char *s)
{
 printf("\n***ERROR: %s\n\n", s);
 PrintUsage();
}


PrintUsage

decompiled_code:
void __noreturn PrintUsage()
{
puts("RGBFix v1.02 (part of ASMotor 1.10-linux-g74eea59)\n");
puts("Usage: rgbfix [options] image[.gb]");
puts("Options:");
puts("\t-h\t\tThis text");
puts("\t-d\t\tDebug: Don't change image");
puts("\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate");
puts("\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate");
puts("\t-t<name>\tChange cartridge title field (16 characters)");
puts(
"\t-v\t\tValidate header\n"
"\t\t\tCorrects - Nintendo Character Area (0x0104)\n"
"\t\t\t\t - ROM type (0x0147)\n"
"\t\t\t\t - ROM size (0x0148)\n"
"\t\t\t\t - Checksums (0x014D-0x014F)");
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("RGBFix v1.02 (part of ASMotor 1.10-linux-g74eea59)\n");
puts("Usage: rgbfix [options] image[.gb]");
puts("Options:");
puts("\t-h\t\tThis text");
puts("\t-d\t\tDebug: Don't change image");
puts("\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate");
puts("\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate");
puts("\t-t<name>\tChange cartridge title field (16 characters)");
puts(
"\t-v\t\tValidate header\n"
"\t\t\tCorrects - Nintendo Character Area (0x0104)\n"
"\t\t\t\t - ROM type (0x0147)\n"
"\t\t\t\t - ROM size (0x0148)\n"
"\t\t\t\t - Checksums (0x014D-0x014F)");
exit(0);
}

original_code:
void PrintUsage(void)
{
 printf("RGBFix v" "1.02"
  " (part of ASMotor " "1.10-linux" "-g74eea59" ")\n\n");
 printf("Usage: rgbfix [options] image[.gb]\n");
 printf("Options:\n");
 printf("\t-h\t\tThis text\n");
 printf("\t-d\t\tDebug: Don't change image\n");
 printf("\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n");
 printf("\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n");
 printf("\t-t<name>\tChange cartridge title field (16 characters)\n");
 printf("\t-v\t\tValidate header\n\t\t\tCorrects - Nintendo Character Area (0x0104)\n\t\t\t\t - ROM type (0x0147)\n\t\t\t\t - ROM size (0x0148)\n\t\t\t\t - Checksums (0x014D-0x014F)\n");
 exit(0);
}

canonical_original_code:
void PrintUsage()
{
 printf("RGBFix v" "1.02"
  " (part of ASMotor " "1.10-linux" "-g74eea59" ")\n\n");
 printf("Usage: rgbfix [options] image[.gb]\n");
 printf("Options:\n");
 printf("\t-h\t\tThis text\n");
 printf("\t-d\t\tDebug: Don't change image\n");
 printf("\t-p\t\tPad image to valid size\n\t\t\tPads to 32/64/128/256/512kB as appropriate\n");
 printf("\t-r\t\ttRuncate image to valid size\n\t\t\tTruncates to 32/64/128/256/512kB as appropriate\n");
 printf("\t-t<name>\tChange cartridge title field (16 characters)\n");
 printf("\t-v\t\tValidate header\n\t\t\tCorrects - Nintendo Character Area (0x0104)\n\t\t\t\t - ROM type (0x0147)\n\t\t\t\t - ROM size (0x0148)\n\t\t\t\t - Checksums (0x014D-0x014F)\n");
 exit(0);
}


TruncateFileName

decompiled_code:
char *__fastcall TruncateFileName(char *dest, char *s)
{
signed __int64 i; // rax
char v3; // dl

for ( i = strlen(s) - 1; i >= 0; --i )
{
v3 = s[i];
if ( v3 == 47 )
break;
if ( v3 == 92 )
break;
}
return strcpy(dest, &s[i + 1]);
}

canonical_decompiled_code:
char *__fastcall func10(char *dest, char *s)
{
signed __int64 i; // rax
char v3; // dl

for ( i = strlen(s) - 1; i >= 0; --i )
{
v3 = s[i];
if ( v3 == 47 )
break;
if ( v3 == 92 )
break;
}
return strcpy(dest, &s[i + 1]);
}

original_code:
void TruncateFileName(char *dest, char *src)
{
 SLONG l;
 l = strlen(src) - 1;
 while ((l >= 0) && (src[l] != '\\') && (src[l] != '/'))
  l -= 1;
 strcpy(dest, &src[l + 1]);
}

canonical_original_code:
void TruncateFileName(char *dest, char *src)
{
 long l;
 l = strlen(src) - 1;
 while ((l >= 0) && (src[l] != '\\') && (src[l] != '/'))
  l -= 1;
 strcpy(dest, &src[l + 1]);
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: l long


decompiled_code:
char *__fastcall lib_Find(char *s1, char *a2)
{
char *v2; // rbx
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

v2 = s1;
TruncateFileName(v4, a2);
if ( !s1 )
return 0LL;
while ( strcmp(v2, v4) )
{
v2 = (char *)*((_QWORD *)v2 + 35);
if ( !v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func11(char *s1, char *a2)
{
char *v2; // rbx
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

v2 = s1;
func10(v4, a2);
if ( !s1 )
return 0LL;
while ( strcmp(v2, v4) )
{
v2 = (char *)*((_QWORD *)v2 + 35);
if ( !v2 )
return 0LL;
}
return v2;
}

original_code:
sLibrary *lib_Find(sLibrary * lib, char *filename)
{
 char truncname[256];
 TruncateFileName(truncname, filename);
 while (lib) {
  if (strcmp(lib->tName, truncname) == 0)
   break;
  lib = lib->pNext;
 }
 return (lib);
}

canonical_original_code:
struct LibraryWrapper *lib_Find(struct LibraryWrapper *lib, char *filename)
{
 char truncname[256];
 TruncateFileName(truncname, filename);
 while (lib) {
  if (strcmp(lib->tName, truncname) == 0)
   break;
  lib = lib->pNext;
 }
 return (lib);
}

variable_types:
lib
struct LibraryWrapper *

variable_types:
filename
char *

variable_types:
truncname
char [256]

return_type: struct LibraryWrapper { char tName[256]; unsigned short uwTime; unsigned short uwDate; long nByteLength; unsigned char *pData; struct LibraryWrapper *pNext; } *


decompiled_code:
char *__fastcall lib_DeleteModule(char *a1, char *a2)
{
char *v2; // rbx
char **v3; // rbp
void *v4; // rdi
char *s1; // [rsp+8h] [rbp-120h] BYREF
char s2[280]; // [rsp+10h] [rbp-118h] BYREF

s1 = a1;
TruncateFileName(s2, a2);
v2 = a1;
if ( a1 )
{
v3 = &s1;
while ( strcmp(v2, s2) )
{
v3 = (char **)(*v3 + 280);
v2 = *v3;
if ( !*v3 )
goto LABEL_9;
}
v4 = (void *)*((_QWORD *)v2 + 34);
if ( v4 )
free(v4);
*v3 = (char *)*((_QWORD *)v2 + 35);
free(v2);
printf("Module '%s' deleted from library\n", s2);
}
else
{
LABEL_9:
fatalerror("Module not found");
}
return s1;
}

canonical_decompiled_code:
char *__fastcall func13(char *a1, char *a2)
{
char *v2; // rbx
char **v3; // rbp
void *v4; // rdi
char *s1; // [rsp+8h] [rbp-120h] BYREF
char s2[280]; // [rsp+10h] [rbp-118h] BYREF

s1 = a1;
func10(s2, a2);
v2 = a1;
if ( a1 )
{
v3 = &s1;
while ( strcmp(v2, s2) )
{
v3 = (char **)(*v3 + 280);
v2 = *v3;
if ( !*v3 )
goto LABEL_9;
}
v4 = (void *)*((_QWORD *)v2 + 34);
if ( v4 )
free(v4);
*v3 = (char *)*((_QWORD *)v2 + 35);
free(v2);
printf("Module '%s' deleted from library\n", s2);
}
else
{
LABEL_9:
fatalerror("Module not found");
}
return s1;
}

original_code:
sLibrary *lib_DeleteModule(sLibrary * lib, char *filename)
{
 char truncname[256];
 sLibrary **pp, **first;
 BBOOL found = 0;
 pp = &lib;
 first = pp;
 TruncateFileName(truncname, filename);
 while ((*pp) && (!found)) {
  if (strcmp((*pp)->tName, truncname) == 0) {
   sLibrary *t;
   t = *pp;
   if (t->pData)
    free(t->pData);
   *pp = t->pNext;
   free(t);
   found = 1;
  }
  pp = &((*pp)->pNext);
 }
 if (!found)
  fatalerror("Module not found");
 else
  printf("Module '%s' deleted from library\n", truncname);
 return (*first);
}

canonical_original_code:
struct LibraryWrapper *lib_DeleteModule(struct LibraryWrapper *lib, char *filename)
{
 char truncname[256];
 struct LibraryWrapper **pp; struct LibraryWrapper **first;
 char found = 0;
 pp = &lib;
 first = pp;
 TruncateFileName(truncname, filename);
 while ((*pp) && (!found)) {
  if (strcmp((*pp)->tName, truncname) == 0) {
   struct LibraryWrapper *t;
   t = *pp;
   if (t->pData)
    free(t->pData);
   *pp = t->pNext;
   free(t);
   found = 1;
  }
  pp = &((*pp)->pNext);
 }
 if (!found)
  fatalerror("Module not found");
 else
  printf("Module '%s' deleted from library\n", truncname);
 return (*first);
}

variable_types: struct LibraryWrapper { char tName[256]; unsigned short uwTime; unsigned short uwDate; long nByteLength; unsigned char *pData; struct LibraryWrapper *pNext; } **

variable_types: found char


decompiled_code:
void __fastcall lib_Free(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi

v1 = ptr;
if ( ptr )
{
while ( 1 )
{
v3 = (void *)v1[34];
if ( v3 )
free(v3);
v2 = (_QWORD *)v1[35];
free(v1);
if ( !v2 )
break;
v1 = v2;
}
}
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi

v1 = ptr;
if ( ptr )
{
while ( 1 )
{
v3 = (void *)v1[34];
if ( v3 )
free(v3);
v2 = (_QWORD *)v1[35];
free(v1);
if ( !v2 )
break;
v1 = v2;
}
}
}

original_code:
void lib_Free(sLibrary * lib)
{
 while (lib) {
  sLibrary *l;
  if (lib->pData)
   free(lib->pData);
  l = lib;
  lib = lib->pNext;
  free(l);
 }
}

canonical_original_code:
void lib_Free(struct LibraryWrapper *lib)
{
 while (lib) {
  struct LibraryWrapper *l;
  if (lib->pData)
   free(lib->pData);
  l = lib;
  lib = lib->pNext;
  free(l);
 }
}

variable_types: struct LibraryWrapper { char tName[256]; unsigned short uwTime; unsigned short uwDate; long nByteLength; unsigned char *pData; struct LibraryWrapper *pNext; } *


AllocSection

decompiled_code:
_QWORD *AllocSection()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
__int64 v2; // rax
__int64 v3; // rdx
_QWORD *v4; // rax
_QWORD *v5; // rbp

v0 = &pSections;
if ( oReadLib == 1 )
v0 = &pLibSections;
v1 = v0;
v2 = *v0;
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 72);
}
while ( v2 );
v1 = (_QWORD *)(v3 + 72);
}
v4 = malloc(0x50uLL);
v5 = v4;
*v1 = v4;
if ( v4 )
{
v4[7] = tSymbols;
*(_QWORD *)(*v1 + 72LL) = 0LL;
*(_QWORD *)(*v1 + 64LL) = 0LL;
*(_BYTE *)(*v1 + 16LL) = 0;
v5 = (_QWORD *)*v1;
}
else
{
fatalerror("Out of memory!");
}
return v5;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
__int64 v2; // rax
__int64 v3; // rdx
_QWORD *v4; // rax
_QWORD *v5; // rbp

v0 = &pSections;
if ( oReadLib == 1 )
v0 = &pLibSections;
v1 = v0;
v2 = *v0;
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 72);
}
while ( v2 );
v1 = (_QWORD *)(v3 + 72);
}
v4 = malloc(0x50uLL);
v5 = v4;
*v1 = v4;
if ( v4 )
{
v4[7] = tSymbols;
*(_QWORD *)(*v1 + 72LL) = 0LL;
*(_QWORD *)(*v1 + 64LL) = 0LL;
*(_BYTE *)(*v1 + 16LL) = 0;
v5 = (_QWORD *)*v1;
}
else
{
fatalerror("Out of memory!");
}
return v5;
}

original_code:
struct sSection *AllocSection(void)
{
 struct sSection **ppSections;
 if (oReadLib == 1)
  ppSections = &pLibSections;
 else
  ppSections = &pSections;
 while (*ppSections)
  ppSections = &((*ppSections)->pNext);
 *ppSections = malloc(sizeof **ppSections);
 if (!*ppSections) {
  fatalerror("Out of memory!");
  return ((void *)0);
 }
 (*ppSections)->tSymbols = tSymbols;
 (*ppSections)->pNext = ((void *)0);
 (*ppSections)->pPatches = ((void *)0);
 (*ppSections)->oAssigned = 0;
 return *ppSections;
}

canonical_original_code:
struct sSection *AllocSection()
{
 struct sSection **ppSections;
 if (oReadLib == 1)
  ppSections = &pLibSections;
 else
  ppSections = &pSections;
 while (*ppSections)
  ppSections = &((*ppSections)->pNext);
 *ppSections = malloc(sizeof **ppSections);
 if (!*ppSections) {
  fatalerror("Out of memory!");
  return ((void *)0);
 }
 (*ppSections)->tSymbols = tSymbols;
 (*ppSections)->pNext = ((void *)0);
 (*ppSections)->pPatches = ((void *)0);
 (*ppSections)->oAssigned = 0;
 return *ppSections;
}

variable_types: struct sSection { long nBank; long nOrg; char oAssigned; long nByteSize; enum eSectionType { SECT_BSS=0, SECT_VRAM=1, SECT_CODE=2, SECT_HOME=3, SECT_HRAM=4 } Type; unsigned char *pData; long nNumberOfSymbols; struct sSymbol { char *pzName; enum eSymbolType { SYM_LOCAL=0, SYM_IMPORT=1, SYM_EXPORT=2 } Type; long nSectionID; struct sSection *pSection; long nOffset; } **tSymbols; struct sPatch { char *pzFilename; long nLineNo; long nOffset; enum ePatchType { PATCH_BYTE=0, PATCH_WORD_L=1, PATCH_LONG_L=2, PATCH_WORD_B=3, PATCH_LONG_B=4 } Type; long nRPNSize; unsigned char *pRPN; struct sPatch *pNext; char oRelocPatch; } *pPatches; struct sSection *pNext; } **

user_defined_types: struct sSection { long nBank; long nOrg; char oAssigned; long nByteSize; enum eSectionType Type; unsigned char *pData; long nNumberOfSymbols; struct sSymbol **tSymbols; struct sPatch *pPatches; struct sSection *pNext; }

user_defined_types: struct sPatch { char *pzFilename; long nLineNo; long nOffset; enum ePatchType Type; long nRPNSize; unsigned char *pRPN; struct sPatch *pNext; char oRelocPatch; }

user_defined_types: struct sSymbol { char *pzName; enum eSymbolType Type; long nSectionID; struct sSection *pSection; long nOffset; }


symboldefined

decompiled_code:
__int64 __fastcall symboldefined(const char *a1)
{
_QWORD *v1; // r13
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rax
int v5; // edx
__int64 v6; // rbp
__int64 v7; // r12

v1 = (_QWORD *)pSections;
result = 0LL;
if ( pSections )
{
while ( 1 )
{
v6 = v1[6];
if ( v6 )
break;
LABEL_9:
v1 = (_QWORD *)v1[9];
if ( !v1 )
return 0LL;
}
v7 = v1[7];
v3 = 0LL;
while ( 1 )
{
v4 = *(_QWORD *)(v7 + 8 * v3);
v5 = *(_DWORD *)(v4 + 8);
if ( (v5 == 2 || !v5 && *(_QWORD **)(v4 + 24) == v1) && !strcmp(*(const char **)v4, a1) )
break;
if ( ++v3 == v6 )
goto LABEL_9;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
_QWORD *v1; // r13
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rax
int v5; // edx
__int64 v6; // rbp
__int64 v7; // r12

v1 = (_QWORD *)pSections;
result = 0LL;
if ( pSections )
{
while ( 1 )
{
v6 = v1[6];
if ( v6 )
break;
LABEL_9:
v1 = (_QWORD *)v1[9];
if ( !v1 )
return 0LL;
}
v7 = v1[7];
v3 = 0LL;
while ( 1 )
{
v4 = *(_QWORD *)(v7 + 8 * v3);
v5 = *(_DWORD *)(v4 + 8);
if ( (v5 == 2 || !v5 && *(_QWORD **)(v4 + 24) == v1) && !strcmp(*(const char **)v4, a1) )
break;
if ( ++v3 == v6 )
goto LABEL_9;
}
result = 1LL;
}
return result;
}

original_code:
static BBOOL symboldefined(char *name)
{
 struct sSection *pSect;
 pSect = pSections;
 while (pSect) {
  ULONG i;
  for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
   if ((pSect->tSymbols[i]->Type == SYM_EXPORT)
       || ((pSect->tSymbols[i]->Type == SYM_LOCAL)
    && (pSect == pSect->tSymbols[i]->pSection))) {
    if (strcmp(pSect->tSymbols[i]->pzName, name) ==
        0)
     return (1);
   }
  }
  pSect = pSect->pNext;
 }
 return (0);
}

canonical_original_code:
static char symboldefined(char *name)
{
 struct sSection *pSect;
 pSect = pSections;
 while (pSect) {
  unsigned long i;
  for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
   if ((pSect->tSymbols[i]->Type == SYM_EXPORT)
       || ((pSect->tSymbols[i]->Type == SYM_LOCAL)
    && (pSect == pSect->tSymbols[i]->pSection))) {
    if (strcmp(pSect->tSymbols[i]->pzName, name) ==
        0)
     return (1);
   }
  }
  pSect = pSect->pNext;
 }
 return (0);
}

variable_types:
name
char *

variable_types: struct sSection { long nBank; long nOrg; char oAssigned; long nByteSize; enum eSectionType { SECT_BSS=0, SECT_VRAM=1, SECT_CODE=2, SECT_HOME=3, SECT_HRAM=4 } Type; unsigned char *pData; long nNumberOfSymbols; struct sSymbol { char *pzName; enum eSymbolType { SYM_LOCAL=0, SYM_IMPORT=1, SYM_EXPORT=2 } Type; long nSectionID; struct sSection *pSection; long nOffset; } **tSymbols; struct sPatch { char *pzFilename; long nLineNo; long nOffset; enum ePatchType { PATCH_BYTE=0, PATCH_WORD_L=1, PATCH_LONG_L=2, PATCH_WORD_B=3, PATCH_LONG_B=4 } Type; long nRPNSize; unsigned char *pRPN; struct sPatch *pNext; char oRelocPatch; } *pPatches; struct sSection *pNext; } *

variable_types:
i
unsigned long

return_type: char


addmodulecontaining

decompiled_code:
__int64 __fastcall addmodulecontaining(const char *a1)
{
_QWORD *v1; // r13
_QWORD *v2; // r15
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rax
int v6; // edx
__int64 v7; // rax
__int64 v8; // rdx
void *v9; // rdx
__int64 v10; // rbp
__int64 v11; // r12

v1 = (_QWORD *)pLibSections;
v2 = &pLibSections;
result = 0LL;
if ( pLibSections )
{
while ( 1 )
{
v10 = v1[6];
if ( v10 )
break;
LABEL_14:
v2 = v1 + 9;
v1 = (_QWORD *)v1[9];
if ( !v1 )
return 0LL;
}
v11 = v1[7];
v4 = 0LL;
while ( 1 )
{
v5 = *(_QWORD *)(v11 + 8 * v4);
v6 = *(_DWORD *)(v5 + 8);
if ( (v6 == 2 || !v6 && *(_QWORD **)(v5 + 24) == v1) && !strcmp(*(const char **)v5, a1) )
break;
if ( ++v4 == v10 )
goto LABEL_14;
}
v7 = pSections;
if ( pSections )
{
do
{
v8 = v7;
v7 = *(_QWORD *)(v7 + 72);
}
while ( v7 );
v9 = (void *)(v8 + 72);
}
else
{
v9 = &pSections;
}
*(_QWORD *)v9 = v1;
*v2 = v1[9];
*(_QWORD *)(*(_QWORD *)v9 + 72LL) = 0LL;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
_QWORD *v1; // r13
_QWORD *v2; // r15
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rax
int v6; // edx
__int64 v7; // rax
__int64 v8; // rdx
void *v9; // rdx
__int64 v10; // rbp
__int64 v11; // r12

v1 = (_QWORD *)pLibSections;
v2 = &pLibSections;
result = 0LL;
if ( pLibSections )
{
while ( 1 )
{
v10 = v1[6];
if ( v10 )
break;
LABEL_14:
v2 = v1 + 9;
v1 = (_QWORD *)v1[9];
if ( !v1 )
return 0LL;
}
v11 = v1[7];
v4 = 0LL;
while ( 1 )
{
v5 = *(_QWORD *)(v11 + 8 * v4);
v6 = *(_DWORD *)(v5 + 8);
if ( (v6 == 2 || !v6 && *(_QWORD **)(v5 + 24) == v1) && !strcmp(*(const char **)v5, a1) )
break;
if ( ++v4 == v10 )
goto LABEL_14;
}
v7 = pSections;
if ( pSections )
{
do
{
v8 = v7;
v7 = *(_QWORD *)(v7 + 72);
}
while ( v7 );
v9 = (void *)(v8 + 72);
}
else
{
v9 = &pSections;
}
*(_QWORD *)v9 = v1;
*v2 = v1[9];
*(_QWORD *)(*(_QWORD *)v9 + 72LL) = 0LL;
result = 1LL;
}
return result;
}

original_code:
static BBOOL addmodulecontaining(char *name)
{
 struct sSection **ppLSect;
 ppLSect = &pLibSections;
 while (*ppLSect) {
  ULONG i;
  for (i = 0; i < (*ppLSect)->nNumberOfSymbols; i += 1) {
   if (((*ppLSect)->tSymbols[i]->Type == SYM_EXPORT)
       || (((*ppLSect)->tSymbols[i]->Type == SYM_LOCAL)
    && ((*ppLSect) ==
        (*ppLSect)->tSymbols[i]->pSection))) {
    if (strcmp
        ((*ppLSect)->tSymbols[i]->pzName,
         name) == 0) {
     struct sSection **ppSect;
     ppSect = &pSections;
     while (*ppSect)
      ppSect = &((*ppSect)->pNext);
     *ppSect = *ppLSect;
     *ppLSect = (*ppLSect)->pNext;
     (*ppSect)->pNext = ((void *)0);
     return (1);
    }
   }
  }
  ppLSect = &((*ppLSect)->pNext);
 }
 return (0);
}

canonical_original_code:
static char addmodulecontaining(char *name)
{
 struct sSection **ppLSect;
 ppLSect = &pLibSections;
 while (*ppLSect) {
  unsigned long i;
  for (i = 0; i < (*ppLSect)->nNumberOfSymbols; i += 1) {
   if (((*ppLSect)->tSymbols[i]->Type == SYM_EXPORT)
       || (((*ppLSect)->tSymbols[i]->Type == SYM_LOCAL)
    && ((*ppLSect) ==
        (*ppLSect)->tSymbols[i]->pSection))) {
    if (strcmp
        ((*ppLSect)->tSymbols[i]->pzName,
         name) == 0) {
     struct sSection **ppSect;
     ppSect = &pSections;
     while (*ppSect)
      ppSect = &((*ppSect)->pNext);
     *ppSect = *ppLSect;
     *ppLSect = (*ppLSect)->pNext;
     (*ppSect)->pNext = ((void *)0);
     return (1);
    }
   }
  }
  ppLSect = &((*ppLSect)->pNext);
 }
 return (0);
}

user_defined_types: enum eSectionType { SECT_BSS=0, SECT_VRAM=1, SECT_CODE=2, SECT_HOME=3, SECT_HRAM=4 }

user_defined_types: enum ePatchType { PATCH_BYTE=0, PATCH_WORD_L=1, PATCH_LONG_L=2, PATCH_WORD_B=3, PATCH_LONG_B=4 }

user_defined_types: enum eSymbolType { SYM_LOCAL=0, SYM_IMPORT=1, SYM_EXPORT=2 }


AddNeededModules

decompiled_code:
void AddNeededModules()
{
__int64 j; // rcx
__int64 v1; // rdx
__int64 v2; // rax
void *v3; // rdx
_QWORD *v4; // rbp
unsigned __int64 i; // rbx
__int64 v6; // rax
const char *v7; // r12

if ( (options & 2) != 0 )
{
if ( (unsigned __int8)addmodulecontaining((const char *)&smartlinkstartsymbol) )
{
printf("Smart linking with symbol '%s'\n", (const char *)&smartlinkstartsymbol);
}
else
{
sprintf(&temptext, "Can't find start symbol '%s'", (const char *)&smartlinkstartsymbol);
fatalerror(&temptext);
}
v4 = (_QWORD *)pSections;
if ( pSections )
{
do
{
for ( i = 0LL; v4[6] > i; ++i )
{
v6 = *(_QWORD *)(v4[7] + 8 * i);
if ( *(_DWORD *)(v6 + 8) <= 1u )
{
v7 = *(const char **)v6;
if ( !(unsigned __int8)symboldefined(*(const char **)v6) )
addmodulecontaining(v7);
}
}
v4 = (_QWORD *)v4[9];
}
while ( v4 );
}
}
else
{
for ( j = pLibSections; j; *(_QWORD *)(*(_QWORD *)v3 + 72LL) = 0LL )
{
v2 = pSections;
v3 = &pSections;
if ( pSections )
{
do
{
v1 = v2;
v2 = *(_QWORD *)(v2 + 72);
}
while ( v2 );
v3 = (void *)(v1 + 72);
}
*(_QWORD *)v3 = j;
j = *(_QWORD *)(j + 72);
pLibSections = j;
}
}
}

canonical_decompiled_code:
void func2()
{
__int64 j; // rcx
__int64 v1; // rdx
__int64 v2; // rax
void *v3; // rdx
_QWORD *v4; // rbp
unsigned __int64 i; // rbx
__int64 v6; // rax
const char *v7; // r12

if ( (options & 2) != 0 )
{
if ( (unsigned __int8)func1((const char *)&smartlinkstartsymbol) )
{
printf("Smart linking with symbol '%s'\n", (const char *)&smartlinkstartsymbol);
}
else
{
sprintf(&temptext, "Can't find start symbol '%s'", (const char *)&smartlinkstartsymbol);
fatalerror(&temptext);
}
v4 = (_QWORD *)pSections;
if ( pSections )
{
do
{
for ( i = 0LL; v4[6] > i; ++i )
{
v6 = *(_QWORD *)(v4[7] + 8 * i);
if ( *(_DWORD *)(v6 + 8) <= 1u )
{
v7 = *(const char **)v6;
if ( !(unsigned __int8)func0(*(const char **)v6) )
func1(v7);
}
}
v4 = (_QWORD *)v4[9];
}
while ( v4 );
}
}
else
{
for ( j = pLibSections; j; *(_QWORD *)(*(_QWORD *)v3 + 72LL) = 0LL )
{
v2 = pSections;
v3 = &pSections;
if ( pSections )
{
do
{
v1 = v2;
v2 = *(_QWORD *)(v2 + 72);
}
while ( v2 );
v3 = (void *)(v1 + 72);
}
*(_QWORD *)v3 = j;
j = *(_QWORD *)(j + 72);
pLibSections = j;
}
}
}

original_code:
void AddNeededModules(void)
{
 struct sSection *pSect;
 if ((options & 0x02) == 0) {
  struct sSection **ppLSect;
  ppLSect = &pLibSections;
  while (*ppLSect) {
   struct sSection **ppSect;
   ppSect = &pSections;
   while (*ppSect)
    ppSect = &((*ppSect)->pNext);
   *ppSect = *ppLSect;
   *ppLSect = (*ppLSect)->pNext;
   (*ppSect)->pNext = ((void *)0);
  }
  return;
 }
 if (options & 0x02) {
  if (!addmodulecontaining(smartlinkstartsymbol)) {
   sprintf(temptext, "Can't find start symbol '%s'",
    smartlinkstartsymbol);
   fatalerror(temptext);
  } else
   printf("Smart linking with symbol '%s'\n",
          smartlinkstartsymbol);
 }
 pSect = pSections;
 while (pSect) {
  ULONG i;
  for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
   if ((pSect->tSymbols[i]->Type == SYM_IMPORT)
       || (pSect->tSymbols[i]->Type == SYM_LOCAL)) {
    if (!symboldefined(pSect->tSymbols[i]->pzName)) {
     addmodulecontaining(pSect->tSymbols[i]->
           pzName);
    }
   }
  }
  pSect = pSect->pNext;
 }
}

canonical_original_code:
void AddNeededModules()
{
 struct sSection *pSect;
 if ((options & 0x02) == 0) {
  struct sSection **ppLSect;
  ppLSect = &pLibSections;
  while (*ppLSect) {
   struct sSection **ppSect;
   ppSect = &pSections;
   while (*ppSect)
    ppSect = &((*ppSect)->pNext);
   *ppSect = *ppLSect;
   *ppLSect = (*ppLSect)->pNext;
   (*ppSect)->pNext = ((void *)0);
  }
  return;
 }
 if (options & 0x02) {
  if (!addmodulecontaining(smartlinkstartsymbol)) {
   sprintf(temptext, "Can't find start symbol '%s'",
    smartlinkstartsymbol);
   fatalerror(temptext);
  } else
   printf("Smart linking with symbol '%s'\n",
          smartlinkstartsymbol);
 }
 pSect = pSections;
 while (pSect) {
  unsigned long i;
  for (i = 0; i < pSect->nNumberOfSymbols; i += 1) {
   if ((pSect->tSymbols[i]->Type == SYM_IMPORT)
       || (pSect->tSymbols[i]->Type == SYM_LOCAL)) {
    if (!symboldefined(pSect->tSymbols[i]->pzName)) {
     addmodulecontaining(pSect->tSymbols[i]->
           pzName);
    }
   }
  }
  pSect = pSect->pNext;
 }
}


decompiled_code:
char *__fastcall out_Setname(char *src)
{
char *result; // rax

result = strcpy(tzOutname, src);
oOutput = 1;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
char *result; // rax

result = strcpy(tzOutname, src);
oOutput = 1;
return result;
}

original_code:
void out_Setname(char *tzOutputfile)
{
 strcpy(tzOutname, tzOutputfile);
 oOutput = 1;
}

variable_types:
tzOutputfile
char *


Output

decompiled_code:
void Output()
{
if ( oOutput )
{
if ( outputtype )
{
if ( outputtype == 1 )
PSION2_Output();
}
else
{
GBROM_Output();
}
}
}

canonical_decompiled_code:
void func5()
{
if ( oOutput )
{
if ( outputtype )
{
if ( outputtype == 1 )
func4();
}
else
{
func3();
}
}
}

original_code:
void Output(void)
{
 if (oOutput) {
  switch (outputtype) {
  case OUTPUT_GBROM:
   GBROM_Output();
   break;
  case OUTPUT_PSION2:
   PSION2_Output();
   break;
  }
 }
}

canonical_original_code:
void Output()
{
 if (oOutput) {
  switch (outputtype) {
  case OUTPUT_GBROM:
   GBROM_Output();
   break;
  case OUTPUT_PSION2:
   PSION2_Output();
   break;
  }
 }
}


yywrap

decompiled_code:
__int64 yywrap()
{
return popcontext();
}

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

original_code:
int yywrap(void)
{
 return (popcontext());
}

canonical_original_code:
int yywrap()
{
 return (popcontext());
}


decompiled_code:
char *__fastcall fstk_AddIncludePath(char *src)
{
__int64 v1; // rax

v1 = NextIncPath++;
return strcpy(&IncludePaths[513 * v1], src);
}

canonical_decompiled_code:
char *__fastcall func5(char *src)
{
__int64 v1; // rax

v1 = NextIncPath++;
return strcpy(&IncludePaths[513 * v1], src);
}

original_code:
void fstk_AddIncludePath(char *s)
{
 strcpy(IncludePaths[NextIncPath++], s);
}

variable_types:
s
char *