updateScreen

decompiled_code:
int __fastcall updateScreen(__int64 a1)
{
int v1; // ebp
int *v2; // r14
char *v3; // r13
int i; // ebx
char v5; // al
int v6; // esi

v1 = 0;
v2 = *(int **)(a1 + 16);
v3 = *(char **)(a1 + 8);
wclear(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( v2[1] > 0 )
{
do
{
for ( i = 0; *v2 > i; ++i )
{
v5 = getMapTile((__int64)v2, v1, i);
v6 = i;
mvprintw(v1, v6, "%c", (unsigned int)v5);
}
++v1;
}
while ( v2[1] > v1 );
}
if ( v3 )
mvprintw(*((_DWORD *)v3 + 1), *((_DWORD *)v3 + 2), "%c", (unsigned int)*v3);
if ( (unsigned __int8)getMapTile(
*(_QWORD *)(a1 + 16),
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL),
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 8LL)) == 62 )
{
drawMap(a1);
++levelReached;
}
return wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}

original_code:
void updateScreen(game_t *game)
{
    int x, y;
    map_t *map = game->map;
    player_t *player = game->player;
    wclear(stdscr);
    for (y = 0; y < map->height; ++y) {
 for (x = 0; x < map->width; ++x) {
     mvprintw(y, x, "%c", getMapTile(map, y, x));
 }
    }
    if (player) {
 mvprintw(player->y, player->x, "%c", player->ch);
    }
    if (getMapTile(game->map, game->player->y,
     game->player->x) == '>') {
     drawMap(game);
     ++levelReached;
    }
    wrefresh(stdscr);
}

canonical_original_code:
void updateScreen(struct game_s *game)
{
    int x; int y;
    struct map_s *map = game->map;
    struct player_s *player = game->player;
    wclear(stdscr);
    for (y = 0; y < map->height; ++y) {
 for (x = 0; x < map->width; ++x) {
     mvprintw(y, x, "%c", getMapTile(map, y, x));
 }
    }
    if (player) {
 mvprintw(player->y, player->x, "%c", player->ch);
    }
    if (getMapTile(game->map, game->player->y,
     game->player->x) == '>') {
     drawMap(game);
     ++levelReached;
    }
    wrefresh(stdscr);
}

variable_types: struct game_s { int running; struct player_s { char ch; int y; int x; } *player; struct map_s { int width; char *data; } *map; struct map_s *oldMap; } *


processInput

repo: ZackMason/rougelike

decompiled_code:
int __fastcall processInput(__int64 a1)
{
int result; // eax
__int64 v2; // rcx
int v3; // edx
int v4; // edx
__int64 v5; // rcx
__int64 v6; // r8
int v7; // ecx
int v8; // ecx
__int64 v9; // r8

result = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( result > 263 )
{
if ( result == 351 )
result = drawMap(a1);
}
else if ( result > 257 )
{
result -= 258;
switch ( result )
{
case 0:
v6 = *(_QWORD *)(a1 + 8);
v7 = *(_DWORD *)(v6 + 4) + 1;
goto LABEL_12;
case 1:
v6 = *(_QWORD *)(a1 + 8);
v7 = *(_DWORD *)(v6 + 4) - 1;
LABEL_12:
result = getMapTile(*(_QWORD *)(a1 + 16), v7, *(_DWORD *)(v6 + 8));
if ( (_BYTE)result != 35 )
*(_DWORD *)(v9 + 4) = v8;
return result;
case 2:
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)(v2 + 8) - 1;
goto LABEL_5;
case 3:
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)(v2 + 8) + 1;
LABEL_5:
result = getMapTile(*(_QWORD *)(a1 + 16), *(_DWORD *)(v2 + 4), v3);
if ( (_BYTE)result != 35 )
*(_DWORD *)(v5 + 8) = v4;
break;
case 5:
*(_DWORD *)a1 = 0;
break;
default:
return result;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1)
{
int result; // eax
__int64 v2; // rcx
int v3; // edx
int v4; // edx
__int64 v5; // rcx
__int64 v6; // r8
int v7; // ecx
int v8; // ecx
__int64 v9; // r8

result = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( result > 263 )
{
if ( result == 351 )
result = func14(a1);
}
else if ( result > 257 )
{
result -= 258;
switch ( result )
{
case 0:
v6 = *(_QWORD *)(a1 + 8);
v7 = *(_DWORD *)(v6 + 4) + 1;
goto LABEL_12;
case 1:
v6 = *(_QWORD *)(a1 + 8);
v7 = *(_DWORD *)(v6 + 4) - 1;
LABEL_12:
result = func8(*(_QWORD *)(a1 + 16), v7, *(_DWORD *)(v6 + 8));
if ( (_BYTE)result != 35 )
*(_DWORD *)(v9 + 4) = v8;
return result;
case 2:
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)(v2 + 8) - 1;
goto LABEL_5;
case 3:
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)(v2 + 8) + 1;
LABEL_5:
result = func8(*(_QWORD *)(a1 + 16), *(_DWORD *)(v2 + 4), v3);
if ( (_BYTE)result != 35 )
*(_DWORD *)(v5 + 8) = v4;
break;
case 5:
*(_DWORD *)a1 = 0;
break;
default:
return result;
}
}
return result;
}

original_code:
void processInput(game_t *game)
{
    int c = wgetch(stdscr);
    switch (c) {
    case 0403:
 if (getMapTile(game->map, game->player->y - 1,
         game->player->x) != '#') {
     game->player->y -= 1;
 }
 break;
    case 0402:
 if (getMapTile(game->map, game->player->y + 1,
         game->player->x) != '#') {
     game->player->y += 1;
 }
 break;
    case 0404:
 if (getMapTile(game->map, game->player->y,
         game->player->x - 1) != '#') {
     game->player->x -= 1;
 }
 break;
    case 0405:
 if (getMapTile(game->map, game->player->y,
         game->player->x + 1) != '#') {
     game->player->x += 1;
 }
 break;
    case 0407:
 game->running = 0;
 break;
    case 0537:
 drawMap(game);
 break;
    }
}

canonical_original_code:
void processInput(struct game_s *game)
{
    int c = wgetch(stdscr);
    switch (c) {
    case 0403:
 if (getMapTile(game->map, game->player->y - 1,
         game->player->x) != '#') {
     game->player->y -= 1;
 }
 break;
    case 0402:
 if (getMapTile(game->map, game->player->y + 1,
         game->player->x) != '#') {
     game->player->y += 1;
 }
 break;
    case 0404:
 if (getMapTile(game->map, game->player->y,
         game->player->x - 1) != '#') {
     game->player->x -= 1;
 }
 break;
    case 0405:
 if (getMapTile(game->map, game->player->y,
         game->player->x + 1) != '#') {
     game->player->x += 1;
 }
 break;
    case 0407:
 game->running = 0;
 break;
    case 0537:
 drawMap(game);
 break;
    }
}

variable_types: c int

return_type: void

user_defined_types: struct game_s { int running; struct player_s *player; struct map_s *map; struct map_s *oldMap; }

user_defined_types: struct player_s { char ch; int y; int x; }


startup

decompiled_code:
int __fastcall startup(_DWORD *a1)
{
initscr();
keypad(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
drawMap((__int64)a1);
*a1 = 1;
return curs_set(0);
}

canonical_decompiled_code:
int __fastcall func17(_DWORD *a1)
{
initscr();
keypad(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
func14((__int64)a1);
*a1 = 1;
return curs_set(0);
}

original_code:
void startup(game_t *game)
{
    initscr();
    keypad(stdscr, 1);
    drawMap(game);
    game->running = 1;
    curs_set(0);
}

canonical_original_code:
void startup(struct game_s *game)
{
    initscr();
    keypad(stdscr, 1);
    drawMap(game);
    game->running = 1;
    curs_set(0);
}


repo: ZeWaren/DatabaseFS

decompiled_code:
__int64 __fastcall make_shortcut_hostsection(__int64 a1, int a2, __int64 a3)
{
int v4; // er13
unsigned int v5; // er13
const char *v7; // rbp
size_t v8; // rax
char *v9; // rbp
const char *v10; // r12
size_t v11; // rax

v4 = strlen(*(const char **)(a3 + 200));
v5 = v4 + strlen(*(const char **)(a3 + 208)) + 9;
if ( (int)v5 > a2 )
return 0LL;
*(_WORD *)a1 = v5;
*(_WORD *)(a1 + 2) = 66;
*(_BYTE *)(a1 + 4) = -126;
v7 = *(const char **)(a3 + 200);
v8 = strlen(v7);
memcpy((void *)(a1 + 5), v7, v8 + 1);
v9 = (char *)(a1 + 5 + strlen(*(const char **)(a3 + 200)) + 1);
v10 = *(const char **)(a3 + 208);
v11 = strlen(v10);
memcpy(v9, v10, v11 + 1);
*(_WORD *)&v9[strlen(*(const char **)(a3 + 208)) + 1] = 2;
return v5;
}

original_code:
int make_shortcut_hostsection(char *buffer, int bufsize, struct shortcut *scut)
{
 int sectionlen;
 sectionlen = strlen(scut->hostdata[0]) + strlen(scut->hostdata[1]) + 9;
 if ( sectionlen > bufsize ) return 0;
 *(short int *)buffer = sectionlen;
 buffer += 2;
 *(short int *)buffer = 66;
 buffer += 2;
 *buffer++ = 130;
 memcpy(buffer, scut->hostdata[0], strlen(scut->hostdata[0])+1);
 buffer += strlen(scut->hostdata[0]) + 1;
 memcpy(buffer, scut->hostdata[1], strlen(scut->hostdata[1])+1);
 buffer += strlen(scut->hostdata[1]) + 1;
 *(short int *)buffer = 2;
 buffer += 2;
 return sectionlen;
}

canonical_original_code:
int make_shortcut_hostsection(char *buffer, int bufsize, struct shortcut *scut)
{
 int sectionlen;
 sectionlen = strlen(scut->hostdata[0]) + strlen(scut->hostdata[1]) + 9;
 if ( sectionlen > bufsize ) return 0;
 *(short *)buffer = sectionlen;
 buffer += 2;
 *(short *)buffer = 66;
 buffer += 2;
 *buffer++ = 130;
 memcpy(buffer, scut->hostdata[0], strlen(scut->hostdata[0])+1);
 buffer += strlen(scut->hostdata[0]) + 1;
 memcpy(buffer, scut->hostdata[1], strlen(scut->hostdata[1])+1);
 buffer += strlen(scut->hostdata[1]) + 1;
 *(short *)buffer = 2;
 buffer += 2;
 return sectionlen;
}

variable_types:
buffer
char *

variable_types: bufsize int

variable_types: struct shortcut { char garbage[200]; char *hostdata[2]; char *sharedata[3]; char *filedata[2]; char *pathdata[2]; char *unicodedata; int unicodelen; } *

variable_types: sectionlen int

return_type: int


original_code:
int make_shortcut_sharesection(char *buffer, int bufsize, struct shortcut *scut)
{
 int sectionlen;
 sectionlen = strlen(scut->sharedata[0]) + strlen(scut->sharedata[1]) +
    strlen(scut->sharedata[2]) + 10;
 if ( sectionlen > bufsize ) return 0;
 *(short int *)buffer = sectionlen;
 buffer += 2;
 *buffer++ = 0xc3;
 *buffer++ = 0x01;
 *buffer++ = 0xc5;
 memcpy(buffer, scut->sharedata[0], strlen(scut->sharedata[0])+1);
 buffer += strlen(scut->sharedata[0]) + 1;
 memcpy(buffer, scut->sharedata[1], strlen(scut->sharedata[1])+1);
 buffer += strlen(scut->sharedata[1]) + 1;
 memcpy(buffer, scut->sharedata[2], strlen(scut->sharedata[2])+1);
 buffer += strlen(scut->sharedata[2]) + 1;
 *(short int *)buffer = 2;
 buffer += 2;
 return sectionlen;
}

canonical_original_code:
int make_shortcut_sharesection(char *buffer, int bufsize, struct shortcut *scut)
{
 int sectionlen;
 sectionlen = strlen(scut->sharedata[0]) + strlen(scut->sharedata[1]) +
    strlen(scut->sharedata[2]) + 10;
 if ( sectionlen > bufsize ) return 0;
 *(short *)buffer = sectionlen;
 buffer += 2;
 *buffer++ = 0xc3;
 *buffer++ = 0x01;
 *buffer++ = 0xc5;
 memcpy(buffer, scut->sharedata[0], strlen(scut->sharedata[0])+1);
 buffer += strlen(scut->sharedata[0]) + 1;
 memcpy(buffer, scut->sharedata[1], strlen(scut->sharedata[1])+1);
 buffer += strlen(scut->sharedata[1]) + 1;
 memcpy(buffer, scut->sharedata[2], strlen(scut->sharedata[2])+1);
 buffer += strlen(scut->sharedata[2]) + 1;
 *(short *)buffer = 2;
 buffer += 2;
 return sectionlen;
}

user_defined_types: struct shortcut { char garbage[200]; char *hostdata[2]; char *sharedata[3]; char *filedata[2]; char *pathdata[2]; char *unicodedata; int unicodelen; }


original_code:
int make_shortcut_filesection(char *buffer, int bufsize, struct shortcut *scut)
{
 int sectionlen;
 char moremagic[] = {
  0x32, 0x00, 0x03, 0xD0, 0x42, 0x00, 0xAD, 0x2C,
  0xE6, 0x8D, 0x80, 0x00 };
 sectionlen = strlen(scut->filedata[0]) + strlen(scut->filedata[1]) + 16;
 if ( sectionlen > bufsize ) return 0;
 *(short int *)buffer = sectionlen;
 buffer += 2;
 memcpy(buffer, moremagic, 12);
 buffer += 12;
 memcpy(buffer, scut->filedata[0], strlen(scut->filedata[0])+1);
 buffer += strlen(scut->filedata[0]) + 1;
 memcpy(buffer, scut->filedata[1], strlen(scut->filedata[1])+1);
 buffer += strlen(scut->filedata[1]) + 1;
 *(short int *)buffer = 0x00;
 return sectionlen;
}

canonical_original_code:
int make_shortcut_filesection(char *buffer, int bufsize, struct shortcut *scut)
{
 int sectionlen;
 char moremagic[] = {
  0x32, 0x00, 0x03, 0xD0, 0x42, 0x00, 0xAD, 0x2C,
  0xE6, 0x8D, 0x80, 0x00 };
 sectionlen = strlen(scut->filedata[0]) + strlen(scut->filedata[1]) + 16;
 if ( sectionlen > bufsize ) return 0;
 *(short *)buffer = sectionlen;
 buffer += 2;
 memcpy(buffer, moremagic, 12);
 buffer += 12;
 memcpy(buffer, scut->filedata[0], strlen(scut->filedata[0])+1);
 buffer += strlen(scut->filedata[0]) + 1;
 memcpy(buffer, scut->filedata[1], strlen(scut->filedata[1])+1);
 buffer += strlen(scut->filedata[1]) + 1;
 *(short *)buffer = 0x00;
 return sectionlen;
}

variable_types:
moremagic
char []


original_code:
int make_shortcut_pathsection(char *buffer, int bufsize, struct shortcut *scut)
{
 int sectionlen;
 char magic[] = {
  0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
  0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x02, 0x00, };
 sectionlen = strlen(scut->pathdata[0]) + strlen(scut->pathdata[1]) + 50;
 if ( sectionlen > bufsize ) return 0;
 buffer += 2;
 *(short int *)buffer = sectionlen;
 buffer += 1;
 memcpy(buffer, magic, sizeof(magic));
 buffer += sizeof(magic);
 memcpy(buffer, scut->pathdata[0], strlen(scut->pathdata[0])+1);
 buffer += strlen(scut->pathdata[0])+1;
 memcpy(buffer, scut->pathdata[1], strlen(scut->pathdata[1])+1);
 buffer += strlen(scut->pathdata[1])+1;
 return sectionlen;
}

canonical_original_code:
int make_shortcut_pathsection(char *buffer, int bufsize, struct shortcut *scut)
{
 int sectionlen;
 char magic[] = {
  0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
  0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x02, 0x00, };
 sectionlen = strlen(scut->pathdata[0]) + strlen(scut->pathdata[1]) + 50;
 if ( sectionlen > bufsize ) return 0;
 buffer += 2;
 *(short *)buffer = sectionlen;
 buffer += 1;
 memcpy(buffer, magic, sizeof(magic));
 buffer += sizeof(magic);
 memcpy(buffer, scut->pathdata[0], strlen(scut->pathdata[0])+1);
 buffer += strlen(scut->pathdata[0])+1;
 memcpy(buffer, scut->pathdata[1], strlen(scut->pathdata[1])+1);
 buffer += strlen(scut->pathdata[1])+1;
 return sectionlen;
}

variable_types:
magic
char []


original_code:
int easy_shortcut(const char *host, const char *share, const char *path, struct shortcut *template, char *buffer, int bufsize)
{
 int i, size;
 char *myhost = (char *)MALLOC(strlen(host) + 3);
 char *sharedata = (char *)MALLOC(strlen(host) + strlen(share) + 4);
 sprintf(myhost, "\\\\%s", host);
 sprintf(sharedata, "\\\\%s\\%s", host, share);
 template->hostdata[0] = myhost;
 template->hostdata[1] = share;
 template->sharedata[0] = sharedata;
 template->sharedata[1] = "Microsoft Network";
 template->sharedata[2] = "some bogus share";
 template->filedata[0] = path;
 template->filedata[1] = "ABCDEF~1.MP3";
 template->pathdata[0] = "";
 template->pathdata[1] = path;
 template->unicodelen = strlen(sharedata);
 template->unicodedata = (char *)MALLOC(template->unicodelen * 2 + 16);
 memset(template->unicodedata, 0x00, template->unicodelen * 2);
 for (i = 0; i < strlen(sharedata) + 1; i++)
  template->unicodedata[i * 2] = sharedata[i];
 size = make_shortcut(buffer, bufsize, template);
 FREE(template->unicodedata);
 FREE(myhost);
 FREE(sharedata);
 return size;
}

canonical_original_code:
int easy_shortcut(char *host, char *share, char *path, struct shortcut *template, char *buffer, int bufsize)
{
 int i; int size;
 char *myhost = (char *)MALLOC(strlen(host) + 3);
 char *sharedata = (char *)MALLOC(strlen(host) + strlen(share) + 4);
 sprintf(myhost, "\\\\%s", host);
 sprintf(sharedata, "\\\\%s\\%s", host, share);
 template->hostdata[0] = myhost;
 template->hostdata[1] = share;
 template->sharedata[0] = sharedata;
 template->sharedata[1] = "Microsoft Network";
 template->sharedata[2] = "some bogus share";
 template->filedata[0] = path;
 template->filedata[1] = "ABCDEF~1.MP3";
 template->pathdata[0] = "";
 template->pathdata[1] = path;
 template->unicodelen = strlen(sharedata);
 template->unicodedata = (char *)MALLOC(template->unicodelen * 2 + 16);
 memset(template->unicodedata, 0x00, template->unicodelen * 2);
 for (i = 0; i < strlen(sharedata) + 1; i++)
  template->unicodedata[i * 2] = sharedata[i];
 size = make_shortcut(buffer, bufsize, template);
 FREE(template->unicodedata);
 FREE(myhost);
 FREE(sharedata);
 return size;
}

variable_types:
host
char *

variable_types:
share
char *

variable_types:
path
char *

variable_types: i int

variable_types: size int

variable_types:
myhost
char *

variable_types:
sharedata
char *


decompiled_code:
char *__fastcall get_string_option(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
char *result; // rax

v2 = parse_table;
if ( !parse_table )
goto LABEL_6;
v3 = 0LL;
while ( strcmp(v2, s2) )
{
++v3;
v2 = (&parse_table)[4 * v3];
if ( !v2 )
goto LABEL_6;
}
v2 = (const char *)qword_2B8[4 * (int)v3];
if ( !v2 )
result = (&off_2B0)[4 * (int)v3];
else
LABEL_6:
result = (char *)v2;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
char *result; // rax

v2 = parse_table;
if ( !parse_table )
goto LABEL_6;
v3 = 0LL;
while ( strcmp(v2, s2) )
{
++v3;
v2 = (&parse_table)[4 * v3];
if ( !v2 )
goto LABEL_6;
}
v2 = (const char *)qword_2B8[4 * (int)v3];
if ( !v2 )
result = (&off_2B0)[4 * (int)v3];
else
LABEL_6:
result = (char *)v2;
return result;
}

original_code:
char *get_string_option(const char *option)
{
 int i;
 for (i=0; parse_table[i].option; i++) {
  if ( strcmp(parse_table[i].option, option) == 0 )
   return ( parse_table[i].value == ((void *)0) )
    ? parse_table[i].defaultval
    : parse_table[i].value;
 }
 return ((void *)0);
}

canonical_original_code:
char *get_string_option(char *option)
{
 int i;
 for (i=0; parse_table[i].option; i++) {
  if ( strcmp(parse_table[i].option, option) == 0 )
   return ( parse_table[i].value == ((void *)0) )
    ? parse_table[i].defaultval
    : parse_table[i].value;
 }
 return ((void *)0);
}

variable_types:
option
char *

return_type: char *


decompiled_code:
__int64 cleanup_config()
{
__int64 *v0; // rbx
__int64 result; // rax

if ( parse_table )
{
v0 = qword_2B8;
do
{
while ( !*(_BYTE *)*v0 )
{
v0 += 4;
if ( !*(v0 - 3) )
return result;
}
v0 += 4;
result = FREE();
}
while ( *(v0 - 3) );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 *v0; // rbx
__int64 result; // rax

if ( parse_table )
{
v0 = qword_2B8;
do
{
while ( !*(_BYTE *)*v0 )
{
v0 += 4;
if ( !*(v0 - 3) )
return result;
}
v0 += 4;
result = FREE();
}
while ( *(v0 - 3) );
}
return result;
}

original_code:
void cleanup_config()
{
 int i;
 for (i = 0; parse_table[i].option; i++)
  if ( *(char *)parse_table[i].value != ((void *)0) )
   FREE(parse_table[i].value);
}


skipleadingpath

repo: Zeno-/bach

decompiled_code:
char *__fastcall skipleadingpath(char *s)
{
char *v2; // rbx
const unsigned __int16 *v3; // rcx
__int64 v4; // rdx

while ( 1 )
{
v2 = strpbrk(s, "\\/");
if ( !v2 )
break;
v3 = *_ctype_b_loc();
while ( 1 )
{
v4 = v2[1];
if ( (v3[v4] & 0x2000) == 0 )
break;
++v2;
}
if ( !(_BYTE)v4 )
break;
s = v2 + 1;
}
return s;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
char *v2; // rbx
const unsigned __int16 *v3; // rcx
__int64 v4; // rdx

while ( 1 )
{
v2 = strpbrk(s, "\\/");
if ( !v2 )
break;
v3 = *_ctype_b_loc();
while ( 1 )
{
v4 = v2[1];
if ( (v3[v4] & 0x2000) == 0 )
break;
++v2;
}
if ( !(_BYTE)v4 )
break;
s = v2 + 1;
}
return s;
}

original_code:
static const char *
skipleadingpath(const char *s)
{
    const char *p;
    while ((p = strpbrk(s, "\\/"))) {
        while (((*__ctype_b_loc ())[(int) ((*(p + 1)))] & (unsigned short int) _ISspace))
            p++;
        if (*(p + 1) == '\0')
            break;
        s = p + 1;
    }
    return s;
}

canonical_original_code:
static char *skipleadingpath(char *s)
{
    char *p;
    while ((p = strpbrk(s, "\\/"))) {
        while (((*__ctype_b_loc ())[(int) ((*(p + 1)))] & (unsigned short) _ISspace))
            p++;
        if (*(p + 1) == '\0')
            break;
        s = p + 1;
    }
    return s;
}

variable_types:
s
char *

variable_types:
p
char *


progname

decompiled_code:
char *__fastcall progname(int a1, char **a2)
{
char *result; // rax

result = "bach";
if ( a1 && **a2 )
{
result = skipleadingpath(*a2);
if ( !*result )
result = "bach";
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(int a1, char **a2)
{
char *result; // rax

result = "bach";
if ( a1 && **a2 )
{
result = func0(*a2);
if ( !*result )
result = "bach";
}
return result;
}

original_code:
static const char *
progname(int argc, char **argv)
{
    const char *s;
    if (argc == 0 || *argv[0] == '\0')
        return "bach";
    s = skipleadingpath(argv[0]);
    return *s == '\0' ? "bach" : s;
}

canonical_original_code:
static char *progname(int argc, char **argv)
{
    char *s;
    if (argc == 0 || *argv[0] == '\0')
        return "bach";
    s = skipleadingpath(argv[0]);
    return *s == '\0' ? "bach" : s;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall run_lua(__int64 a1)
{
*(_QWORD *)(a1 + 8) = "/home/crobbins/code/bach/lua/examples/test.lua";
return zvm_lua_runscript("/home/crobbins/code/bach/lua/examples/test.lua");
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
*(_QWORD *)(a1 + 8) = "/home/crobbins/code/bach/lua/examples/test.lua";
return zvm_lua_runscript("/home/crobbins/code/bach/lua/examples/test.lua");
}

original_code:
static int
run_lua(struct setup *setup)
{
    setup->luafilename = "/home/crobbins/code/bach/lua/examples/test.lua";
    return zvm_lua_runscript(setup->luafilename);
}

variable_types: struct setup { int runmode; char *luafilename; } *


decompiled_code:
// attributes: thunk
__int64 run_tests()
{
return vputest_genterrain();
}

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

original_code:
static void
run_tests(void)
{
        vputest_genterrain();
}

canonical_original_code:
static void run_tests()
{
        vputest_genterrain();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
char *v5; // rax
_DWORD v7[10]; // [rsp+0h] [rbp-28h] BYREF

testcpuinstructions();
v3 = parseargs_constprop_0(v7);
if ( v3 == 2 )
return run_lua((__int64)v7);
if ( v3 > 2 )
{
v4 = 1;
if ( v3 == 3 )
v4 = run_normal_constprop_0();
}
else
{
v4 = 1;
if ( (unsigned int)v3 <= 1 )
{
v5 = progname(argc, (char **)argv);
printusage(v5, stderr);
}
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
char *v5; // rax
_DWORD v7[10]; // [rsp+0h] [rbp-28h] BYREF

func7();
v3 = func5(v7);
if ( v3 == 2 )
return func3((__int64)v7);
if ( v3 > 2 )
{
v4 = 1;
if ( v3 == 3 )
v4 = func6();
}
else
{
v4 = 1;
if ( (unsigned int)v3 <= 1 )
{
v5 = func1(argc, (char **)argv);
func2(v5, stderr);
}
}
return v4;
}

original_code:
int main(int argc, char **argv)
{
    int r = 1;
    struct setup setup;
    testcpuinstructions();
    switch (parseargs(argc, argv, &setup)) {
    case RUNMODE_SHOWUSAGE:
    case RUNMODE_ERR_PARSEARGS:
        printusage(progname(argc, argv), stderr);
        break;
    case RUNMODE_LUA:
        r = run_lua(&setup);
        break;
    case RUNMODE_NORMAL:
        r = run_normal(&setup);
        break;
    }
    return r;
}

variable_types: r int

variable_types: struct setup { int runmode; char *luafilename; }


initqueue

original_code:
static enum eventsyserr
initqueue(EventSys *esys, eventflags eventflags)
{
    if ((esys->events = malloc(1024 * sizeof *esys->events)) == ((void *)0))
        return ESYSERR_MALLOC;
    esys->equeue.eventflags = eventflags;
    esys->equeue.maxsz = 1024;
    esys->equeue.back = 0;
    esys->equeue.front = 0;
    esys->equeue.fullbehaviour = EVENTQUEUE_WHENFULL_RMOLD;
    return ESYSERR_NONE;
}

canonical_original_code:
static enum eventsyserr initqueue(struct eventsys *esys, unsigned short eventflags)
{
    if ((esys->events = malloc(1024 * sizeof *esys->events)) == ((void *)0))
        return ESYSERR_MALLOC;
    esys->equeue.eventflags = eventflags;
    esys->equeue.maxsz = 1024;
    esys->equeue.back = 0;
    esys->equeue.front = 0;
    esys->equeue.fullbehaviour = EVENTQUEUE_WHENFULL_RMOLD;
    return ESYSERR_NONE;
}

variable_types: struct eventsys { struct eventqueue { unsigned short eventflags; int fullbehaviour; int maxsz; int front; } equeue; struct event { unsigned short type; union { struct kybdevent { int scancode; int ascii; unsigned char modkeys; } kybd; struct mouseevent { int x; unsigned char buttonstate; } mouse; unsigned char quit; } data; } *events; } *

variable_types:
eventflags
unsigned short

return_type: enum eventsyserr { ESYSERR_NONE=0, ESYSERR_MALLOC=1 }

user_defined_types: struct eventsys { struct eventqueue equeue; struct event *events; }

user_defined_types: struct event { unsigned short type; union { struct kybdevent kybd; struct mouseevent mouse; unsigned char quit; } data; }


cleanup

decompiled_code:
void __fastcall cleanup(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
inline static void
cleanup(EventSys *esys)
{
    if (esys->events) {
        free(esys->events);
    }
    free(esys);
}

canonical_original_code:
inline static void cleanup(struct eventsys *esys)
{
    if (esys->events) {
        free(esys->events);
    }
    free(esys);
}

user_defined_types: struct eventqueue { unsigned short eventflags; int fullbehaviour; int maxsz; int front; }

user_defined_types: struct kybdevent { int scancode; int ascii; unsigned char modkeys; }

user_defined_types: struct mouseevent { int x; unsigned char buttonstate; }


decompiled_code:
__int64 __fastcall eq_peek(__int64 a1)
{
int v2; // edi
__int64 v3; // rdx
__m128i *v4; // rcx
int v5; // eax
__m128i v6; // xmm0
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( eq_isempty_isra_0(v2, *(_DWORD *)(a1 + 16)) )
{
fprintf(stderr, "Warning: %s:%d: %s\n", "hal/sdl/hal_events.c", 147LL, "Attempt to get/peek empty event queue.");
result = 0LL;
}
else
{
v5 = v2 - 1;
if ( !v2 )
v5 = *(_DWORD *)(v3 + 8) - 1;
v6 = _mm_loadu_si128((const __m128i *)(*(_QWORD *)(v3 + 24) + 16LL * v5));
result = 1LL;
*v4 = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v2; // edi
__int64 v3; // rdx
__m128i *v4; // rcx
int v5; // eax
__m128i v6; // xmm0
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( func2(v2, *(_DWORD *)(a1 + 16)) )
{
fprintf(stderr, "Warning: %s:%d: %s\n", "hal/sdl/hal_events.c", 147LL, "Attempt to get/peek empty event queue.");
result = 0LL;
}
else
{
v5 = v2 - 1;
if ( !v2 )
v5 = *(_DWORD *)(v3 + 8) - 1;
v6 = _mm_loadu_si128((const __m128i *)(*(_QWORD *)(v3 + 24) + 16LL * v5));
result = 1LL;
*v4 = v6;
}
return result;
}

original_code:
inline static int
eq_peek(EventSys *esys, struct event *e)
{
    int headpos;
    if (eq_isempty(esys)) {
        fprintf(stderr, "Warning: %s:%d: %s\n", "hal/sdl/hal_events.c", 147, ("Attempt to get/peek empty event queue."));
        return 0;
    }
    if (esys->equeue.front == 0)
        headpos = esys->equeue.maxsz - 1;
    else
        headpos = esys->equeue.front - 1;
    memcpy(e, &esys->events[headpos], sizeof *e);
    return 1;
}

canonical_original_code:
inline static int eq_peek(struct eventsys *esys, struct event *e)
{
    int headpos;
    if (eq_isempty(esys)) {
        fprintf(stderr, "Warning: %s:%d: %s\n", "hal/sdl/hal_events.c", 147, ("Attempt to get/peek empty event queue."));
        return 0;
    }
    if (esys->equeue.front == 0)
        headpos = esys->equeue.maxsz - 1;
    else
        headpos = esys->equeue.front - 1;
    memcpy(e, &esys->events[headpos], sizeof *e);
    return 1;
}

variable_types:
e
struct event *

variable_types: headpos int


decompiled_code:
int __fastcall eq_rem(__int64 a1)
{
int v1; // edx
__int64 v2; // rcx
int v3; // edx
unsigned int v4; // kr00_4
int result; // eax

if ( eq_isempty_isra_0(*(_DWORD *)(a1 + 12), *(_DWORD *)(a1 + 16)) )
return fprintf(
stderr,
"Warning: %s:%d: %s\n",
"hal/sdl/hal_events.c",
181LL,
"Attempt to remove from empty event queue.");
v4 = v1 + 1;
v3 = (v1 + 1) >> 31;
result = __SPAIR64__(v3, v4) / *(int *)(v2 + 8);
*(_DWORD *)(v2 + 16) = __SPAIR64__(v3, v4) % *(int *)(v2 + 8);
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
int v1; // edx
__int64 v2; // rcx
int v3; // edx
unsigned int v4; // kr00_4
int result; // eax

if ( func2(*(_DWORD *)(a1 + 12), *(_DWORD *)(a1 + 16)) )
return fprintf(
stderr,
"Warning: %s:%d: %s\n",
"hal/sdl/hal_events.c",
181LL,
"Attempt to remove from empty event queue.");
v4 = v1 + 1;
v3 = (v1 + 1) >> 31;
result = __SPAIR64__(v3, v4) / *(int *)(v2 + 8);
*(_DWORD *)(v2 + 16) = __SPAIR64__(v3, v4) % *(int *)(v2 + 8);
return result;
}

original_code:
inline static void
eq_rem(EventSys *esys)
{
    if (eq_isempty(esys)) {
        fprintf(stderr, "Warning: %s:%d: %s\n", "hal/sdl/hal_events.c", 181, ("Attempt to remove from empty event queue."));
        return;
    }
    esys->equeue.back = (esys->equeue.back + 1) % esys->equeue.maxsz;
}

canonical_original_code:
inline static void eq_rem(struct eventsys *esys)
{
    if (eq_isempty(esys)) {
        fprintf(stderr, "Warning: %s:%d: %s\n", "hal/sdl/hal_events.c", 181, ("Attempt to remove from empty event queue."));
        return;
    }
    esys->equeue.back = (esys->equeue.back + 1) % esys->equeue.maxsz;
}


original_code:
inline static void
eq_add(EventSys *esys, const struct event *e)
{
    if (eq_isfull(esys)) {
        if (esys->equeue.fullbehaviour == EVENTQUEUE_WHENFULL_RMOLD)
            eq_rem(esys);
        else
            return;
    }
    memcpy(&esys->events[esys->equeue.front], e, sizeof *e);
    esys->equeue.front = (esys->equeue.front + 1) % esys->equeue.maxsz;
}

canonical_original_code:
inline static void eq_add(struct eventsys *esys, struct event *e)
{
    if (eq_isfull(esys)) {
        if (esys->equeue.fullbehaviour == EVENTQUEUE_WHENFULL_RMOLD)
            eq_rem(esys);
        else
            return;
    }
    memcpy(&esys->events[esys->equeue.front], e, sizeof *e);
    esys->equeue.front = (esys->equeue.front + 1) % esys->equeue.maxsz;
}


decompiled_code:
void __fastcall evsys_stopeventsys(void *a1)
{
if ( a1 )
cleanup(a1);
}

canonical_decompiled_code:
void __fastcall func9(void *a1)
{
if ( a1 )
func1(a1);
}

original_code:
void evsys_stopeventsys(EventSys *esys)
{
    if (esys)
        cleanup(esys);
}

canonical_original_code:
void evsys_stopeventsys(struct eventsys *esys)
{
    if (esys)
        cleanup(esys);
}


decompiled_code:
__int64 evsys_wait()
{
return SDL_WaitEvent(0LL);
}

canonical_decompiled_code:
__int64 func10()
{
return SDL_WaitEvent(0LL);
}

original_code:
void evsys_wait(EventSys *esys)
{
    (void)esys;
    SDL_WaitEvent(((void *)0));
}

canonical_original_code:
void evsys_wait(struct eventsys *esys)
{
    (void)esys;
    SDL_WaitEvent(((void *)0));
}


decompiled_code:
_BOOL8 __fastcall evsys_hasevents(__int64 a1)
{
return !eq_isempty_isra_0(*(_DWORD *)(a1 + 12), *(_DWORD *)(a1 + 16));
}

original_code:
int evsys_hasevents(EventSys *esys)
{
    return !eq_isempty(esys);
}

canonical_original_code:
int evsys_hasevents(struct eventsys *esys)
{
    return !eq_isempty(esys);
}


decompiled_code:
__int64 __fastcall evsys_getevent(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+Ch] [rbp-Ch]

result = eq_peek(a1);
if ( (_DWORD)result )
{
v2 = result;
eq_rem(a1);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+Ch] [rbp-Ch]

result = func3(a1);
if ( (_DWORD)result )
{
v2 = result;
func4(a1);
result = v2;
}
return result;
}

original_code:
int evsys_getevent(EventSys *esys, struct event *e)
{
    int r;
    if ((r = eq_peek(esys, e)))
        eq_rem(esys);
    return r;
}

canonical_original_code:
int evsys_getevent(struct eventsys *esys, struct event *e)
{
    int r;
    if ((r = eq_peek(esys, e)))
        eq_rem(esys);
    return r;
}


decompiled_code:
__int64 __fastcall evsys_poll(__int16 *a1)
{
int v1; // edx

if ( evsys_hasevents((__int64)a1) )
return evsys_getevent((__int64)a1);
if ( v1 == 1 )
{
if ( !(unsigned int)SDL_PollEvent(0LL) )
return 0LL;
}
else if ( !v1 )
{
evsys_wait(a1);
if ( !(unsigned int)eq_processbackend(a1) )
return 0LL;
return evsys_getevent((__int64)a1);
}
if ( !(unsigned int)eq_processbackend(a1) )
return 0LL;
return evsys_getevent((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int16 *a1)
{
int v1; // edx

if ( func11((__int64)a1) )
return func12((__int64)a1);
if ( v1 == 1 )
{
if ( !(unsigned int)SDL_PollEvent(0LL) )
return 0LL;
}
else if ( !v1 )
{
func10(a1);
if ( !(unsigned int)func7(a1) )
return 0LL;
return func12((__int64)a1);
}
if ( !(unsigned int)func7(a1) )
return 0LL;
return func12((__int64)a1);
}

original_code:
int evsys_poll(EventSys *esys, struct event *e,
               enum eventpollbehaviour pollbehaviour)
{
    if (evsys_hasevents(esys))
        return evsys_getevent(esys, e);
    if (pollbehaviour == EQ_POLL_NONBLOCKING && !SDL_PollEvent(((void *)0)))
        return 0;
    else if (pollbehaviour == EQ_POLL_BLOCKING)
        evsys_wait(esys);
    if (eq_processbackend(esys))
        return evsys_getevent(esys, e);
    return 0;
}

canonical_original_code:
int evsys_poll(struct eventsys *esys, struct event *e, enum eventpollbehaviour pollbehaviour)
{
    if (evsys_hasevents(esys))
        return evsys_getevent(esys, e);
    if (pollbehaviour == EQ_POLL_NONBLOCKING && !SDL_PollEvent(((void *)0)))
        return 0;
    else if (pollbehaviour == EQ_POLL_BLOCKING)
        evsys_wait(esys);
    if (eq_processbackend(esys))
        return evsys_getevent(esys, e);
    return 0;
}

variable_types: enum eventpollbehaviour { EQ_POLL_BLOCKING=0, EQ_POLL_NONBLOCKING=1 }


decompiled_code:
__int64 __fastcall evsys_waitforquit(__int16 *a1)
{
__m128i v2; // [rsp+0h] [rbp-18h] BYREF

do
{
while ( !(unsigned int)evsys_poll(a1) )
;
}
while ( (v2.m128i_i8[0] & 1) == 0 );
return eq_add((__int64)a1, &v2);
}

original_code:
void evsys_waitforquit(EventSys *esys)
{
    struct event e;
    while (1) {
        if (evsys_poll(esys, &e, EQ_POLL_BLOCKING))
            if (e.type & EVENT_QUIT)
                break;
    }
    eq_add(esys, &e);
}

canonical_original_code:
void evsys_waitforquit(struct eventsys *esys)
{
    struct event e;
    while (1) {
        if (evsys_poll(esys, &e, EQ_POLL_BLOCKING))
            if (e.type & EVENT_QUIT)
                break;
    }
    eq_add(esys, &e);
}

variable_types: struct event { unsigned short type; union { struct kybdevent { int scancode; int ascii; unsigned char modkeys; } kybd; struct mouseevent { int x; unsigned char buttonstate; } mouse; unsigned char quit; } data; }


decompiled_code:
// attributes: thunk
__int64 __fastcall evsys_peekevent(__int64 a1)
{
return eq_peek(a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func3(a1);
}

original_code:
int evsys_peekevent(EventSys *esys, struct event *e)
{
    return eq_peek(esys, e);
}

canonical_original_code:
int evsys_peekevent(struct eventsys *esys, struct event *e)
{
    return eq_peek(esys, e);
}


interpolate

decompiled_code:
double __fastcall interpolate(double a1, double a2, double a3)
{
return (1.0 - a3) * a1 + a3 * a2;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3)
{
return (1.0 - a3) * a1 + a3 * a2;
}

original_code:
inline static double
interpolate(double x0, double x1, double alpha)
{
    return x0 * (1.0 - alpha) + alpha * x1;
}

variable_types: alpha double

return_type: double


genrandarr

decompiled_code:
char *__fastcall genrandarr(int a1, int a2)
{
int v2; // ebp
char *v3; // rax
char *v4; // r12
double *v5; // rbx
char *v6; // rbp

v2 = a2 * a1;
v3 = (char *)malloc(8LL * a2 * a1);
if ( !v3 )
{
perror("genrandr()");
exit(1);
}
v4 = v3;
if ( v2 > 0 )
{
v5 = (double *)v3;
v6 = &v3[8 * v2];
do
*v5++ = (double)rand() / 2147483647.0;
while ( v5 != (double *)v6 );
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(int a1, int a2)
{
int v2; // ebp
char *v3; // rax
char *v4; // r12
double *v5; // rbx
char *v6; // rbp

v2 = a2 * a1;
v3 = (char *)malloc(8LL * a2 * a1);
if ( !v3 )
{
perror("genrandr()");
exit(1);
}
v4 = v3;
if ( v2 > 0 )
{
v5 = (double *)v3;
v6 = &v3[8 * v2];
do
*v5++ = (double)rand() / 2147483647.0;
while ( v5 != (double *)v6 );
}
return v4;
}

original_code:
static double *
genrandarr(int w, int h)
{
    double *ra;
    int i, n;
    n = w * h;
    if ( (ra = malloc(n * sizeof *ra)) == ((void *)0)) {
        perror("genrandr()");
        exit(1);
    }
    for (i = 0; i < n; i++)
        ra[i] = (double)rand() / 2147483647;
    return ra;
}

canonical_original_code:
static double *genrandarr(int w, int h)
{
    double *ra;
    int i; int n;
    n = w * h;
    if ( (ra = malloc(n * sizeof *ra)) == ((void *)0)) {
        perror("genrandr()");
        exit(1);
    }
    for (i = 0; i < n; i++)
        ra[i] = (double)rand() / 2147483647;
    return ra;
}

variable_types: w int

variable_types: h int

variable_types:
ra
double *

variable_types: i int

variable_types: n int

return_type: double *


decompiled_code:
__int64 hal_init()
{
__int64 result; // rax
int v1; // er8

result = 0LL;
if ( !isinitialised )
{
v1 = SDL_Init(32LL);
result = 1LL;
if ( !v1 )
{
isinitialised = 1;
SDL_WM_SetCaption("BACH - BAsic ArCHitecture Emulator", 0LL);
atexit((void (*)(void))&SDL_Quit);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // er8

result = 0LL;
if ( !isinitialised )
{
v1 = SDL_Init(32LL);
result = 1LL;
if ( !v1 )
{
isinitialised = 1;
SDL_WM_SetCaption("BACH - BAsic ArCHitecture Emulator", 0LL);
atexit((void (*)(void))&SDL_Quit);
result = 0LL;
}
}
return result;
}

original_code:
enum hal_error
hal_init(void)
{
    if (isinitialised)
        return HAL_NOERROR;
    if (SDL_Init(0x00000020) != 0)
        return HAL_INIT_FAIL;
    isinitialised = 1;
    SDL_WM_SetCaption("BACH - BAsic ArCHitecture Emulator", ((void *)0));
    atexit(SDL_Quit);
    return HAL_NOERROR;
}

canonical_original_code:
enum hal_error hal_init()
{
    if (isinitialised)
        return HAL_NOERROR;
    if (SDL_Init(0x00000020) != 0)
        return HAL_INIT_FAIL;
    isinitialised = 1;
    SDL_WM_SetCaption("BACH - BAsic ArCHitecture Emulator", ((void *)0));
    atexit(SDL_Quit);
    return HAL_NOERROR;
}

return_type: enum hal_error { HAL_NOERROR=0, HAL_INIT_FAIL=1, HAL_INIT_VIDEO_FAIL=2, HAL_INIT_KYBDMOUSE_FAIL=3 }


decompiled_code:
__int64 hal_isinitalised()
{
return (unsigned int)isinitialised;
}

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

original_code:
int hal_isinitalised(void)
{
    return isinitialised;
}

canonical_original_code:
int hal_isinitalised()
{
    return isinitialised;
}


decompiled_code:
void *__fastcall vidfont_getnamedfont(const char *a1)
{
void *v1; // r8

v1 = &vidfont8x8;
if ( strcmp("8x8", a1) )
{
v1 = &vidfont8x14;
if ( strcmp("8x14", a1) )
{
v1 = &vidfont8x16;
if ( strcmp("8x16", a1) )
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
void *__fastcall func0(const char *a1)
{
void *v1; // r8

v1 = &vidfont8x8;
if ( strcmp("8x8", a1) )
{
v1 = &vidfont8x14;
if ( strcmp("8x14", a1) )
{
v1 = &vidfont8x16;
if ( strcmp("8x16", a1) )
v1 = 0LL;
}
}
return v1;
}

original_code:
const struct vidfont8 *vidfont_getnamedfont(const char *name)
{
    if (strcmp("8x8", name) == 0)
        return &vidfont8x8;
    else if (strcmp("8x14", name) == 0)
        return &vidfont8x14;
    else if (strcmp("8x16", name) == 0)
        return &vidfont8x16;
    return ((void *)0);
}

canonical_original_code:
struct vidfont8 *vidfont_getnamedfont(char *name)
{
    if (strcmp("8x8", name) == 0)
        return &vidfont8x8;
    else if (strcmp("8x14", name) == 0)
        return &vidfont8x14;
    else if (strcmp("8x16", name) == 0)
        return &vidfont8x16;
    return ((void *)0);
}

variable_types:
name
char *

return_type: struct vidfont8 { unsigned int height; unsigned char *pixeldata; } *


decompiled_code:
__int64 __fastcall vidfont_getglyph(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8) + (unsigned int)(*(_DWORD *)a1 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8) + (unsigned int)(*(_DWORD *)a1 * a2);
}

original_code:
const unsigned char *vidfont_getglyph(const struct vidfont8 *font, int ch)
{
    return font->pixeldata + ch * font->height;
}

canonical_original_code:
unsigned char *vidfont_getglyph(struct vidfont8 *font, int ch)
{
    return font->pixeldata + ch * font->height;
}

variable_types: struct vidfont8 { unsigned int height; unsigned char *pixeldata; } *

variable_types: ch int

return_type: unsigned char *


destroyNFA

repo: ZeyuMi/MiLex

decompiled_code:
__int64 destroyNFA()
{
stateNum = 0;
return destroyGraph();
}

canonical_decompiled_code:
__int64 func0()
{
stateNum = 0;
return destroyGraph();
}

original_code:
void destroyNFA(){
 stateNum = 0;
 destroyGraph();
}


pop

decompiled_code:
__int64 pop()
{
int v0; // eax

v0 = topp;
if ( !topp )
return -1LL;
--topp;
return *((_QWORD *)stack + v0 - 1);
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax

v0 = topp;
if ( !topp )
return -1LL;
--topp;
return *((_QWORD *)stack + v0 - 1);
}

original_code:
struct NFASection pop(){
 if(topp == 0){
  struct NFASection t = {-1,-1};
  return t;
 }
 else
  return stack[--topp];
}

variable_types: struct NFASection { int start; int end; }


constructFromRE

decompiled_code:
__int64 __fastcall constructFromRE(_BYTE *a1, __int64 a2, __int64 a3)
{
char v3; // bl
_BYTE *v4; // r13
unsigned int v5; // ebp
__int64 v6; // r15
__int64 v7; // r12
__int64 v8; // r15
__int64 v9; // rdx
__int64 v10; // r12
unsigned int v11; // er14
__int64 v12; // rbx
__int64 v13; // rdi
__int64 v14; // rbx
__int64 v16; // r12
__int64 v17; // r12
__int64 v18; // r15
unsigned int v19; // er12
__int64 v20; // rbx
__int64 v21; // rdi
unsigned __int64 v22; // r12
__int64 v23; // rdx
__int64 v24; // rax
unsigned int v25; // ebx
__int64 v26; // [rsp+0h] [rbp-48h]

v3 = *a1;
v26 = a2;
if ( *a1 )
{
v4 = a1;
v5 = 0;
a3 = 0xFFFFFFFFLL;
do
{
while ( v3 == 124 )
{
v8 = pop(a1, 0LL, a3);
v10 = pop(a1, 0LL, v9);
v11 = stateNum + 1;
v13 = (unsigned int)(stateNum + 1);
stateNum += 2;
v12 = (unsigned int)stateNum;
addVertex(v13, 0LL);
addVertex((unsigned int)v12, 0LL);
addEdge(v11, (unsigned int)v8, 0xFFFFFFFFLL);
addEdge(v11, (unsigned int)v10, 0xFFFFFFFFLL);
addEdge(v8 >> 32, (unsigned int)v12, 0xFFFFFFFFLL);
a2 = (unsigned int)v12;
addEdge(v10 >> 32, (unsigned int)v12, 0xFFFFFFFFLL);
a1 = (_BYTE *)((v12 << 32) | v11);
push((__int64)a1);
a3 = v5++;
v3 = v4[v5];
if ( !v3 )
goto LABEL_12;
}
if ( v3 == 63 )
{
v16 = pop(a1, a2, a3);
a2 = v16 >> 32;
addEdge((unsigned int)v16, v16 >> 32, 0xFFFFFFFFLL);
a1 = (_BYTE *)v16;
push(v16);
a3 = v5;
}
else if ( v3 == 43 )
{
v17 = pop(a1, a2, a3);
a2 = (unsigned int)v17;
addEdge(v17 >> 32, (unsigned int)v17, 0xFFFFFFFFLL);
a1 = (_BYTE *)v17;
push(v17);
a3 = v5;
}
else if ( v3 == 42 )
{
v18 = pop(a1, a2, a3);
addEdge(HIDWORD(v18), (unsigned int)v18, 0xFFFFFFFFLL);
v19 = stateNum + 1;
v21 = (unsigned int)(stateNum + 1);
stateNum += 2;
v20 = (unsigned int)stateNum;
addVertex(v21, 0LL);
addVertex((unsigned int)v20, 0LL);
addEdge(v19, (unsigned int)v18, 0xFFFFFFFFLL);
addEdge(HIDWORD(v18), (unsigned int)v20, 0xFFFFFFFFLL);
a2 = (unsigned int)v20;
addEdge(v19, (unsigned int)v20, 0xFFFFFFFFLL);
a1 = (_BYTE *)((v20 << 32) | v19);
push((__int64)a1);
a3 = v5;
}
else if ( v3 == -2 )
{
v22 = pop(a1, a2, a3);
v24 = pop(a1, a2, v23);
a2 = (unsigned int)v22;
v25 = v24;
addEdge(v24 >> 32, (unsigned int)v22, 0xFFFFFFFFLL);
a1 = (_BYTE *)((HIDWORD(v22) << 32) | v25);
push((__int64)a1);
a3 = v5;
}
else
{
if ( v3 == 92 )
{
v5 = a3 + 2;
v3 = v4[(int)a3 + 2];
if ( !v3 )
error((int)"invalid Regular expression.", a2, (const char *)a3);
}
v6 = (unsigned int)(stateNum + 1);
stateNum += 2;
v7 = (unsigned int)stateNum;
addVertex(v6, 0LL);
addVertex((unsigned int)v7, 0LL);
a2 = (unsigned int)v7;
addEdge((unsigned int)v6, (unsigned int)v7, (unsigned int)v3);
a1 = (_BYTE *)((v7 << 32) | v6);
push((__int64)a1);
a3 = v5;
}
v3 = v4[++v5];
}
while ( v3 );
}
LABEL_12:
v14 = pop(a1, a2, a3);
addActionToVertex(v14 >> 32, v26);
return (unsigned int)v14;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 a2, __int64 a3)
{
char v3; // bl
_BYTE *v4; // r13
unsigned int v5; // ebp
__int64 v6; // r15
__int64 v7; // r12
__int64 v8; // r15
__int64 v9; // rdx
__int64 v10; // r12
unsigned int v11; // er14
__int64 v12; // rbx
__int64 v13; // rdi
__int64 v14; // rbx
__int64 v16; // r12
__int64 v17; // r12
__int64 v18; // r15
unsigned int v19; // er12
__int64 v20; // rbx
__int64 v21; // rdi
unsigned __int64 v22; // r12
__int64 v23; // rdx
__int64 v24; // rax
unsigned int v25; // ebx
__int64 v26; // [rsp+0h] [rbp-48h]

v3 = *a1;
v26 = a2;
if ( *a1 )
{
v4 = a1;
v5 = 0;
a3 = 0xFFFFFFFFLL;
do
{
while ( v3 == 124 )
{
v8 = func1(a1, 0LL, a3);
v10 = func1(a1, 0LL, v9);
v11 = stateNum + 1;
v13 = (unsigned int)(stateNum + 1);
stateNum += 2;
v12 = (unsigned int)stateNum;
addVertex(v13, 0LL);
addVertex((unsigned int)v12, 0LL);
addEdge(v11, (unsigned int)v8, 0xFFFFFFFFLL);
addEdge(v11, (unsigned int)v10, 0xFFFFFFFFLL);
addEdge(v8 >> 32, (unsigned int)v12, 0xFFFFFFFFLL);
a2 = (unsigned int)v12;
addEdge(v10 >> 32, (unsigned int)v12, 0xFFFFFFFFLL);
a1 = (_BYTE *)((v12 << 32) | v11);
push((__int64)a1);
a3 = v5++;
v3 = v4[v5];
if ( !v3 )
goto LABEL_12;
}
if ( v3 == 63 )
{
v16 = func1(a1, a2, a3);
a2 = v16 >> 32;
addEdge((unsigned int)v16, v16 >> 32, 0xFFFFFFFFLL);
a1 = (_BYTE *)v16;
push(v16);
a3 = v5;
}
else if ( v3 == 43 )
{
v17 = func1(a1, a2, a3);
a2 = (unsigned int)v17;
addEdge(v17 >> 32, (unsigned int)v17, 0xFFFFFFFFLL);
a1 = (_BYTE *)v17;
push(v17);
a3 = v5;
}
else if ( v3 == 42 )
{
v18 = func1(a1, a2, a3);
addEdge(HIDWORD(v18), (unsigned int)v18, 0xFFFFFFFFLL);
v19 = stateNum + 1;
v21 = (unsigned int)(stateNum + 1);
stateNum += 2;
v20 = (unsigned int)stateNum;
addVertex(v21, 0LL);
addVertex((unsigned int)v20, 0LL);
addEdge(v19, (unsigned int)v18, 0xFFFFFFFFLL);
addEdge(HIDWORD(v18), (unsigned int)v20, 0xFFFFFFFFLL);
a2 = (unsigned int)v20;
addEdge(v19, (unsigned int)v20, 0xFFFFFFFFLL);
a1 = (_BYTE *)((v20 << 32) | v19);
push((__int64)a1);
a3 = v5;
}
else if ( v3 == -2 )
{
v22 = func1(a1, a2, a3);
v24 = func1(a1, a2, v23);
a2 = (unsigned int)v22;
v25 = v24;
addEdge(v24 >> 32, (unsigned int)v22, 0xFFFFFFFFLL);
a1 = (_BYTE *)((HIDWORD(v22) << 32) | v25);
push((__int64)a1);
a3 = v5;
}
else
{
if ( v3 == 92 )
{
v5 = a3 + 2;
v3 = v4[(int)a3 + 2];
if ( !v3 )
error((int)"invalid Regular expression.", a2, (const char *)a3);
}
v6 = (unsigned int)(stateNum + 1);
stateNum += 2;
v7 = (unsigned int)stateNum;
addVertex(v6, 0LL);
addVertex((unsigned int)v7, 0LL);
a2 = (unsigned int)v7;
addEdge((unsigned int)v6, (unsigned int)v7, (unsigned int)v3);
a1 = (_BYTE *)((v7 << 32) | v6);
push((__int64)a1);
a3 = v5;
}
v3 = v4[++v5];
}
while ( v3 );
}
LABEL_12:
v14 = func1(a1, a2, a3);
addActionToVertex(v14 >> 32, v26);
return (unsigned int)v14;
}

original_code:
int constructFromRE(char *postRE, char *action){
 int pos = -1;
 char c;
 int start , end;
 start = end = -1;
 while(1){
  pos++;
  c = *(postRE+pos);
  if('\0' == c){
   struct NFASection temp = pop();
   addActionToVertex(temp.end, action);
   return temp.start;
  }else if('|' == c){
   struct NFASection temp1 = pop();
   struct NFASection temp2 = pop();
   start = ++stateNum;
   end = ++stateNum;
   addVertex(start, ((void *)0));
   addVertex(end, ((void *)0));
   addEdge(start, temp1.start, -1);
   addEdge(start, temp2.start, -1);
   addEdge(temp1.end, end, -1);
   addEdge(temp2.end, end, -1);
   struct NFASection temp = {start, end};
   push(temp);
  }else if('?' == c){
   struct NFASection temp1 = pop();
   addEdge(temp1.start, temp1.end, -1);
   push(temp1);
  }else if('+' == c){
   struct NFASection temp1 = pop();
   addEdge(temp1.end, temp1.start, -1);
   push(temp1);
  }else if('*' == c){
   struct NFASection temp1 = pop();
   addEdge(temp1.end, temp1.start, -1);
   start = ++stateNum;
   end = ++stateNum;
   addVertex(start, ((void *)0));
   addVertex(end, ((void *)0));
   addEdge(start, temp1.start, -1);
   addEdge(temp1.end, end, -1);
   addEdge(start, end, -1);
   struct NFASection temp = {start, end};
   push(temp);
  }else if(-2 == c){
   struct NFASection temp2 = pop();
   struct NFASection temp1 = pop();
   addEdge(temp1.end, temp2.start, -1);
   struct NFASection temp = {temp1.start, temp2.end};
   push(temp);
  }else{
   if('\\' == c){
    pos++;
    c = *(postRE+pos);
   }
   if('\0' == c)
    error("invalid Regular expression.");
   start = ++stateNum;
   end = ++stateNum;
   addVertex(start, ((void *)0));
   addVertex(end, ((void *)0));
   addEdge(start, end, c);
   struct NFASection temp = {start, end};
   push(temp);
  }
 }
}

canonical_original_code:
int constructFromRE(char *postRE, char *action){
 int pos = -1;
 char c;
 int start; int end;
 start = end = -1;
 while(1){
  pos++;
  c = *(postRE+pos);
  if('\0' == c){
   struct NFASection temp = pop();
   addActionToVertex(temp.end, action);
   return temp.start;
  }else if('|' == c){
   struct NFASection temp1 = pop();
   struct NFASection temp2 = pop();
   start = ++stateNum;
   end = ++stateNum;
   addVertex(start, ((void *)0));
   addVertex(end, ((void *)0));
   addEdge(start, temp1.start, -1);
   addEdge(start, temp2.start, -1);
   addEdge(temp1.end, end, -1);
   addEdge(temp2.end, end, -1);
   struct NFASection temp = {start, end};
   push(temp);
  }else if('?' == c){
   struct NFASection temp1 = pop();
   addEdge(temp1.start, temp1.end, -1);
   push(temp1);
  }else if('+' == c){
   struct NFASection temp1 = pop();
   addEdge(temp1.end, temp1.start, -1);
   push(temp1);
  }else if('*' == c){
   struct NFASection temp1 = pop();
   addEdge(temp1.end, temp1.start, -1);
   start = ++stateNum;
   end = ++stateNum;
   addVertex(start, ((void *)0));
   addVertex(end, ((void *)0));
   addEdge(start, temp1.start, -1);
   addEdge(temp1.end, end, -1);
   addEdge(start, end, -1);
   struct NFASection temp = {start, end};
   push(temp);
  }else if(-2 == c){
   struct NFASection temp2 = pop();
   struct NFASection temp1 = pop();
   addEdge(temp1.end, temp2.start, -1);
   struct NFASection temp = {temp1.start, temp2.end};
   push(temp);
  }else{
   if('\\' == c){
    pos++;
    c = *(postRE+pos);
   }
   if('\0' == c)
    error("invalid Regular expression.");
   start = ++stateNum;
   end = ++stateNum;
   addVertex(start, ((void *)0));
   addVertex(end, ((void *)0));
   addEdge(start, end, c);
   struct NFASection temp = {start, end};
   push(temp);
  }
 }
}

variable_types:
postRE
char *

variable_types:
action
char *

variable_types: pos int

variable_types: c char

variable_types: start int

variable_types: end int

user_defined_types: struct NFASection { int start; int end; }


constructNFA

decompiled_code:
void constructNFA()
{
unsigned int v0; // er12
_QWORD *v1; // rbx
_BYTE *v2; // rbp
__int64 v3; // rdx
__int64 v4; // rsi

v1 = (_QWORD *)regexps;
v0 = ++stateNum;
addVertex((unsigned int)stateNum, 0LL);
for ( ; v1; v1 = (_QWORD *)v1[2] )
{
v2 = (_BYTE *)infixToPostfix(*v1);
v4 = (unsigned int)constructFromRE(v2, v1[1], v3);
addEdge(v0, v4, 0xFFFFFFFFLL);
free(v2);
}
}

canonical_decompiled_code:
void func3()
{
unsigned int v0; // er12
_QWORD *v1; // rbx
_BYTE *v2; // rbp
__int64 v3; // rdx
__int64 v4; // rsi

v1 = (_QWORD *)regexps;
v0 = ++stateNum;
addVertex((unsigned int)stateNum, 0LL);
for ( ; v1; v1 = (_QWORD *)v1[2] )
{
v2 = (_BYTE *)infixToPostfix(*v1);
v4 = (unsigned int)func2(v2, v1[1], v3);
addEdge(v0, v4, 0xFFFFFFFFLL);
free(v2);
}
}

original_code:
void constructNFA(){
 struct REentry *retemp = regexps;
 int startPoint = ++stateNum;
 addVertex(startPoint, ((void *)0));
 while(((void *)0) != retemp){
  char *postfix = infixToPostfix(retemp->regexp);
  int childgraph = constructFromRE(postfix, retemp->action);
  addEdge(startPoint, childgraph, -1);
  free(postfix);
  retemp = retemp->next;
 }
}

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

variable_types: startPoint int

variable_types:
postfix
char *

variable_types: childgraph int


addDFANewState

decompiled_code:
void *__fastcall addDFANewState(int a1, __int64 a2)
{
void *result; // rax
_QWORD *v3; // rax
_QWORD *v4; // rbp
_DWORD *v5; // rax
_QWORD *v6; // r13
_DWORD *v7; // rax
_QWORD *v8; // rbp

result = getEntry(a1);
if ( !result )
{
v3 = table;
if ( table )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[3];
}
while ( v3 );
v5 = malloc(0x20uLL);
*v5 = a1;
v6 = v5;
result = calloc(0x200uLL, 1uLL);
v6[2] = a2;
v6[1] = result;
v6[3] = 0LL;
v4[3] = v6;
}
else
{
v7 = malloc(0x20uLL);
*v7 = a1;
v8 = v7;
result = calloc(0x200uLL, 1uLL);
v8[2] = a2;
v8[1] = result;
v8[3] = 0LL;
table = v8;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1, __int64 a2)
{
void *result; // rax
_QWORD *v3; // rax
_QWORD *v4; // rbp
_DWORD *v5; // rax
_QWORD *v6; // r13
_DWORD *v7; // rax
_QWORD *v8; // rbp

result = getEntry(a1);
if ( !result )
{
v3 = table;
if ( table )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[3];
}
while ( v3 );
v5 = malloc(0x20uLL);
*v5 = a1;
v6 = v5;
result = calloc(0x200uLL, 1uLL);
v6[2] = a2;
v6[1] = result;
v6[3] = 0LL;
v4[3] = v6;
}
else
{
v7 = malloc(0x20uLL);
*v7 = a1;
v8 = v7;
result = calloc(0x200uLL, 1uLL);
v8[2] = a2;
v8[1] = result;
v8[3] = 0LL;
table = v8;
}
}
return result;
}

original_code:
void addDFANewState(int state, char *action){
 struct dfaTTEntry *temp = getEntry(state);
 if(((void *)0) != temp)
  return;
 temp = table;
 struct dfaTTEntry *pre = ((void *)0);
 while(((void *)0) != temp){
  pre = temp;
  temp = temp->next;
 }
 temp = malloc(sizeof(struct dfaTTEntry));
 temp->state = state;
 temp->trans = malloc(sizeof(int) * 128);
 temp->action = action;
 int i = 0;
 while(i < 128){
  (temp->trans)[i] = 0;
  i++;
 }
 temp->next = ((void *)0);
 if(((void *)0) == table)
  table = temp;
 else
  pre->next = temp;
}

variable_types: state int

variable_types: struct dfaTTEntry { int state; int *trans; char *action; struct dfaTTEntry *next; } *


printDFATransTable

decompiled_code:
int printDFATransTable()
{
unsigned int *v0; // rbp
__int64 v1; // rbx
__int64 v2; // rsi
__int64 v3; // rdx
const char *v4; // rsi

v0 = (unsigned int *)table;
if ( table )
{
do
{
v1 = 0LL;
printf("state%d: ", *v0);
do
{
while ( 1 )
{
v2 = *(unsigned int *)(*((_QWORD *)v0 + 1) + 4 * v1);
if ( (_DWORD)v2 )
break;
if ( ++v1 == 128 )
goto LABEL_6;
}
v3 = (unsigned int)v1++;
printf("connects to state%d by %d,", v2, v3);
}
while ( v1 != 128 );
LABEL_6:
v4 = (const char *)*((_QWORD *)v0 + 2);
if ( v4 )
printf("action is %s", v4);
putchar(10);
v0 = (unsigned int *)*((_QWORD *)v0 + 3);
}
while ( v0 );
}
return putchar(10);
}

canonical_decompiled_code:
int func1()
{
unsigned int *v0; // rbp
__int64 v1; // rbx
__int64 v2; // rsi
__int64 v3; // rdx
const char *v4; // rsi

v0 = (unsigned int *)table;
if ( table )
{
do
{
v1 = 0LL;
printf("state%d: ", *v0);
do
{
while ( 1 )
{
v2 = *(unsigned int *)(*((_QWORD *)v0 + 1) + 4 * v1);
if ( (_DWORD)v2 )
break;
if ( ++v1 == 128 )
goto LABEL_6;
}
v3 = (unsigned int)v1++;
printf("connects to state%d by %d,", v2, v3);
}
while ( v1 != 128 );
LABEL_6:
v4 = (const char *)*((_QWORD *)v0 + 2);
if ( v4 )
printf("action is %s", v4);
putchar(10);
v0 = (unsigned int *)*((_QWORD *)v0 + 3);
}
while ( v0 );
}
return putchar(10);
}

original_code:
void printDFATransTable(){
 struct dfaTTEntry *temp = table;
 while(((void *)0) != temp){
  printf("state%d: ", temp->state);
  int i = 0;
  while(i < 128){
   if(0 != (temp->trans)[i])
    printf("connects to state%d by %d,", (temp->trans)[i], i);
   i++;
  }
  if(((void *)0) != temp->action)
   printf("action is %s", temp->action);
  printf("\n");
  temp = temp->next;
 }
 printf("\n");
}

variable_types: i int

user_defined_types: struct dfaTTEntry { int state; int *trans; char *action; struct dfaTTEntry *next; }


destroyDFATransTable

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

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

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

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

original_code:
void destroyDFATransTable(){
 struct dfaTTEntry *temp = table;
 struct dfaTTEntry *next = ((void *)0);
 while(((void *)0) != temp){
  next = temp->next;
  temp->state = 0;
  free(temp->trans);
  temp->trans = ((void *)0);
  temp->next = ((void *)0);
  free(temp);
  temp = next;
 }
 table = ((void *)0);
}


getTable

decompiled_code:
void *getTable()
{
return table;
}

canonical_decompiled_code:
void *func3()
{
return table;
}

original_code:
struct dfaTTEntry *getTable(){
 return table;
}

return_type: struct dfaTTEntry { int state; int *trans; char *action; struct dfaTTEntry *next; } *


getTableEntryNum

decompiled_code:
__int64 getTableEntryNum()
{
_QWORD *v0; // rax
unsigned int v1; // er8

v0 = table;
v1 = 0;
if ( table )
{
do
{
v0 = (_QWORD *)v0[3];
++v1;
}
while ( v0 );
}
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
_QWORD *v0; // rax
unsigned int v1; // er8

v0 = table;
v1 = 0;
if ( table )
{
do
{
v0 = (_QWORD *)v0[3];
++v1;
}
while ( v0 );
}
return v1;
}

original_code:
int getTableEntryNum(){
 struct dfaTTEntry *temp = table;
 int num = 0;
 while(((void *)0) != temp){
  num++;
  temp = temp->next;
 }
 return num;
}

variable_types: num int


printGraph

decompiled_code:
int printGraph()
{
unsigned int *v0; // rbp
unsigned int **i; // rbx
const char *v2; // rsi

v0 = (unsigned int *)graph;
if ( graph )
{
do
{
printf("vertex%d connects to ", *v0);
for ( i = (unsigned int **)*((_QWORD *)v0 + 2); i; i = (unsigned int **)i[2] )
printf("vertex%d labeled %c, ", **i, (unsigned int)*((char *)i + 8));
v2 = (const char *)*((_QWORD *)v0 + 1);
if ( v2 )
printf("action is %s.", v2);
putchar(10);
v0 = (unsigned int *)*((_QWORD *)v0 + 3);
}
while ( v0 );
}
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
unsigned int *v0; // rbp
unsigned int **i; // rbx
const char *v2; // rsi

v0 = (unsigned int *)graph;
if ( graph )
{
do
{
printf("vertex%d connects to ", *v0);
for ( i = (unsigned int **)*((_QWORD *)v0 + 2); i; i = (unsigned int **)i[2] )
printf("vertex%d labeled %c, ", **i, (unsigned int)*((char *)i + 8));
v2 = (const char *)*((_QWORD *)v0 + 1);
if ( v2 )
printf("action is %s.", v2);
putchar(10);
v0 = (unsigned int *)*((_QWORD *)v0 + 3);
}
while ( v0 );
}
return putchar(10);
}

original_code:
void printGraph(){
 struct vertex *vertexTemp = graph;
 while(((void *)0) != vertexTemp){
  printf("vertex%d connects to ", vertexTemp->state);
  struct edge *edgeTemp = vertexTemp->edges;
  while(((void *)0) != edgeTemp){
   printf("vertex%d labeled %c, ", edgeTemp->connectsTo->state, edgeTemp->symbol);
   edgeTemp = edgeTemp->next;
  }
  if(((void *)0) != vertexTemp->action)
   printf("action is %s.", vertexTemp->action);
  printf("\n");
  vertexTemp = vertexTemp->next;
 }
 printf("\n");
}

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

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


destroyEdge

decompiled_code:
void __fastcall destroyEdge(_QWORD *a1)
{
if ( a1 )
{
if ( a1[2] )
destroyEdge();
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
if ( a1 )
{
if ( a1[2] )
func1();
free(a1);
}
}

original_code:
void destroyEdge(struct edge *e){
 if(((void *)0) == e)
  return;
 if(((void *)0) != e->next){
  destroyEdge(e->next);
 }
 e->connectsTo = ((void *)0);
 e->next = ((void *)0);
 free(e);
}

user_defined_types: struct edge { struct vertex *connectsTo; char symbol; struct edge *next; }

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


destroyVertex

decompiled_code:
void __fastcall destroyVertex(__int64 a1)
{
if ( *(_QWORD *)(a1 + 24) )
destroyVertex();
destroyEdge(*(_QWORD **)(a1 + 16));
free((void *)a1);
}

original_code:
void destroyVertex(struct vertex *v){
 if(((void *)0) != v->next){
  destroyVertex(v->next);
 }
 destroyEdge(v->edges);
 v->next = ((void *)0);
 v->edges = ((void *)0);
 v->action = ((void *)0);
 free(v);
}


destroyGraph

decompiled_code:
void destroyGraph()
{
if ( graph )
{
destroyVertex(graph);
graph = 0LL;
}
}

canonical_decompiled_code:
void func3()
{
if ( graph )
{
func2(graph);
graph = 0LL;
}
}

original_code:
void destroyGraph(){
 if(((void *)0) != graph){
  destroyVertex(graph);
  graph = ((void *)0);
 }
}


isVertexExist

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

result = graph;
if ( !graph )
return 0LL;
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
return result;
}
return 1LL;
}

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

result = graph;
if ( !graph )
return 0LL;
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int isVertexExist(int state){
 struct vertex *temp = graph;
 while(((void *)0) != temp){
  if(temp->state == state)
   return 1;
  temp = temp->next;
 }
 return 0;
}


addVertex

decompiled_code:
__int64 __fastcall addVertex(int a1, __int64 a2)
{
int v2; // er8
__int64 result; // rax
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rcx

v2 = isVertexExist(a1);
result = 0LL;
if ( !v2 )
{
v4 = malloc(0x20uLL);
*(_DWORD *)v4 = a1;
v5 = (__int64)v4;
v4[2] = 0LL;
v4[1] = a2;
v4[3] = 0LL;
v6 = graph;
if ( graph )
{
do
{
v7 = v6;
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
*(_QWORD *)(v7 + 24) = v5;
result = 1LL;
}
else
{
graph = v5;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2)
{
int v2; // er8
__int64 result; // rax
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rcx

v2 = func4(a1);
result = 0LL;
if ( !v2 )
{
v4 = malloc(0x20uLL);
*(_DWORD *)v4 = a1;
v5 = (__int64)v4;
v4[2] = 0LL;
v4[1] = a2;
v4[3] = 0LL;
v6 = graph;
if ( graph )
{
do
{
v7 = v6;
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
*(_QWORD *)(v7 + 24) = v5;
result = 1LL;
}
else
{
graph = v5;
result = 1LL;
}
}
return result;
}

original_code:
int addVertex(int state, char *action){
 if(isVertexExist(state))
   return 0;
 struct vertex *v = malloc(sizeof(struct vertex));
 v->state = state;
 v->edges = ((void *)0);
 v->action = action;
 v->next = ((void *)0);
 if(((void *)0) == graph){
  graph = v;
 }else{
  struct vertex *temp = graph;
  while(((void *)0) != temp->next){
   temp = temp->next;
  }
  temp->next = v;
 }
 return 1;
}


getVertex

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

for ( result = graph; result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = graph; result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
struct vertex *getVertex(int state){
 struct vertex *temp = graph;
 while(((void *)0) != temp){
  if(temp->state == state)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

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


reachByEdgeSymbol

decompiled_code:
void *__fastcall reachByEdgeSymbol(int a1, char a2)
{
void *v2; // r13
unsigned int v3; // er12
unsigned int *i; // rbx
int v5; // eax

v2 = 0LL;
if ( (unsigned int)isVertexExist(a1) )
{
v3 = initializeIntBuffer();
for ( i = *(unsigned int **)(getVertex(a1) + 16); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
while ( *((_BYTE *)i + 8) != a2 )
{
i = (unsigned int *)*((_QWORD *)i + 2);
if ( !i )
goto LABEL_7;
}
addIntElement(v3, **(unsigned int **)i);
}
LABEL_7:
addIntElement(v3, 0xFFFFFFFFLL);
v5 = intSize(v3);
v2 = malloc(4LL * v5);
fillIntArrayWithBuffer(v3, v2);
destroyIntBuffer(v3);
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func7(int a1, char a2)
{
void *v2; // r13
unsigned int v3; // er12
unsigned int *i; // rbx
int v5; // eax

v2 = 0LL;
if ( (unsigned int)func4(a1) )
{
v3 = initializeIntBuffer();
for ( i = *(unsigned int **)(func6(a1) + 16); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
while ( *((_BYTE *)i + 8) != a2 )
{
i = (unsigned int *)*((_QWORD *)i + 2);
if ( !i )
goto LABEL_7;
}
addIntElement(v3, **(unsigned int **)i);
}
LABEL_7:
addIntElement(v3, 0xFFFFFFFFLL);
v5 = intSize(v3);
v2 = malloc(4LL * v5);
fillIntArrayWithBuffer(v3, v2);
destroyIntBuffer(v3);
}
return v2;
}

original_code:
int *reachByEdgeSymbol(int state, char symbol){
 if(!isVertexExist(state))
  return ((void *)0);
 int bufferid = initializeIntBuffer();
 struct vertex *vertexTemp = getVertex(state);
 struct edge *edgeTemp = vertexTemp->edges;
 while(((void *)0) != edgeTemp){
  if(symbol == edgeTemp->symbol)
   addIntElement(bufferid, edgeTemp->connectsTo->state);
  edgeTemp = edgeTemp->next;
 }
 addIntElement(bufferid, -1);
 int *result = malloc(intSize(bufferid) * sizeof(int));
 fillIntArrayWithBuffer(bufferid, result);
 destroyIntBuffer(bufferid);
 return result;
}

variable_types: symbol char

variable_types: bufferid int

variable_types:
result
int *

return_type: int *


addActionToVertex

decompiled_code:
__int64 __fastcall addActionToVertex(int a1, __int64 a2)
{
__int64 result; // rax

result = isVertexExist(a1);
if ( (_DWORD)result )
{
*(_QWORD *)(getVertex(a1) + 8) = a2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
__int64 result; // rax

result = func4(a1);
if ( (_DWORD)result )
{
*(_QWORD *)(func6(a1) + 8) = a2;
result = 1LL;
}
return result;
}

original_code:
int addActionToVertex(int state, char *action){
 if(!isVertexExist(state))
  return 0;
 struct vertex *temp = getVertex(state);
 temp->action = action;
 return 1;
}

variable_types:
action
char *


getAction

decompiled_code:
__int64 __fastcall getAction(int *a1)
{
int v1; // edi
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v1 = *a1;
if ( v1 == -1 )
return 0LL;
while ( 1 )
{
v2 = getVertex(v1);
if ( v2 )
{
result = *(_QWORD *)(v2 + 8);
if ( result )
break;
}
v1 = *(_DWORD *)(v3 + 4);
if ( v1 == -1 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1)
{
int v1; // edi
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v1 = *a1;
if ( v1 == -1 )
return 0LL;
while ( 1 )
{
v2 = func6(v1);
if ( v2 )
{
result = *(_QWORD *)(v2 + 8);
if ( result )
break;
}
v1 = *(_DWORD *)(v3 + 4);
if ( v1 == -1 )
return 0LL;
}
return result;
}

original_code:
char *getAction(int *states){
 int temp = 0;
 while(-1 != (temp = *states)){
  struct vertex *vertexTemp = getVertex(temp);
  if(((void *)0) != vertexTemp && ((void *)0) != vertexTemp->action)
   return vertexTemp->action;
  states++;
 }
 return ((void *)0);
}

variable_types:
states
int *

variable_types: temp int


isConnectTo

decompiled_code:
__int64 __fastcall isConnectTo(int a1, int a2)
{
__int64 result; // rax
int v3; // er8

result = isVertexExist(a1);
if ( (_DWORD)result )
{
result = isVertexExist(a2);
if ( (_DWORD)result )
{
result = *(_QWORD *)(getVertex(v3) + 16);
if ( result )
{
while ( **(_DWORD **)result != a2 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
result = 1LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
__int64 result; // rax
int v3; // er8

result = func4(a1);
if ( (_DWORD)result )
{
result = func4(a2);
if ( (_DWORD)result )
{
result = *(_QWORD *)(func6(v3) + 16);
if ( result )
{
while ( **(_DWORD **)result != a2 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
result = 1LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
int isConnectTo(int state1, int state2){
 if(!isVertexExist(state1) || !isVertexExist(state2))
  return 0;
 struct vertex *v1 = getVertex(state1);
 struct edge *edgetemp = v1->edges;
 while(((void *)0) != edgetemp){
  if(edgetemp->connectsTo->state == state2)
   return 1;
  edgetemp = edgetemp->next;
 }
 return 0;
}


addEdge

decompiled_code:
__int64 __fastcall addEdge(int a1, int a2)
{
__int64 result; // rax
char v3; // dl
int v4; // er9
char v5; // bl
int v6; // er8
int v7; // er9
__int64 v8; // rbp
__int64 v9; // r12
_BYTE *v10; // rax
_BYTE *v11; // rcx
__int64 v12; // rax
__int64 v13; // rdx

result = isVertexExist(a1);
if ( (_DWORD)result )
{
result = isVertexExist(a2);
if ( (_DWORD)result )
{
v5 = v3;
v6 = isConnectTo(v4, a2);
result = 0LL;
if ( !v6 )
{
v8 = getVertex(v7);
v9 = getVertex(a2);
v10 = malloc(0x18uLL);
*(_QWORD *)v10 = v9;
v11 = v10;
v10[8] = v5;
*((_QWORD *)v10 + 2) = 0LL;
v12 = *(_QWORD *)(v8 + 16);
if ( v12 )
{
do
{
v13 = v12;
v12 = *(_QWORD *)(v12 + 16);
}
while ( v12 );
*(_QWORD *)(v13 + 16) = v11;
result = 1LL;
}
else
{
*(_QWORD *)(v8 + 16) = v11;
result = 1LL;
}
}
}
}
return result;
}

original_code:
int addEdge(int state1, int state2, char symbol){
 if(!isVertexExist(state1) || !isVertexExist(state2))
  return 0;
 if(isConnectTo(state1,state2))
  return 0;
 struct vertex *v1 = getVertex(state1);
 struct vertex *v2 = getVertex(state2);
 struct edge *newEdge = malloc(sizeof(struct edge));
 newEdge->connectsTo = v2;
 newEdge->symbol = symbol;
 newEdge->next = ((void *)0);
 struct edge *edgetemp = v1->edges;
 if(((void *)0) == edgetemp){
  v1->edges = newEdge;
 }else{
  while(((void *)0) != edgetemp->next){
   edgetemp = edgetemp->next;
  }
  edgetemp->next = newEdge;
 }
 return 1;
}


getGraph

decompiled_code:
__int64 getGraph()
{
return graph;
}

canonical_decompiled_code:
__int64 func12()
{
return graph;
}

original_code:
struct vertex *getGraph(){
 return graph;
}


getCharBuffer

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

result = charBufferList;
if ( charBufferList )
{
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 32);
if ( !result )
return result;
}
result = *(_QWORD *)(result + 8);
}
return result;
}

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

result = charBufferList;
if ( charBufferList )
{
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 32);
if ( !result )
return result;
}
result = *(_QWORD *)(result + 8);
}
return result;
}

original_code:
char *getCharBuffer(int id){
 charEntry *temp = charBufferList;
 while(((void *)0) != temp){
  if(temp->id == id)
   return temp->buffer;
  temp = temp->next;
 }
 return ((void *)0);
}

canonical_original_code:
char *getCharBuffer(int id){
 struct charBufferEntry *temp = charBufferList;
 while(((void *)0) != temp){
  if(temp->id == id)
   return temp->buffer;
  temp = temp->next;
 }
 return ((void *)0);
}

variable_types: id int

variable_types: struct charBufferEntry { int id; char *buffer; char *bufp; int buffersize; struct charBufferEntry *next; } *


findCharEntry

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

for ( result = charBufferList; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = charBufferList; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
charEntry *findCharEntry(int id){
 charEntry *temp = charBufferList;
 while(((void *)0) != temp){
  if(temp->id == id)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct charBufferEntry *findCharEntry(int id){
 struct charBufferEntry *temp = charBufferList;
 while(((void *)0) != temp){
  if(temp->id == id)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

return_type: struct charBufferEntry { int id; char *buffer; char *bufp; int buffersize; struct charBufferEntry *next; } *


findPreCharEntry

decompiled_code:
__int64 __fastcall findPreCharEntry(int a1)
{
__int64 i; // r8
_DWORD *v2; // rax

for ( i = charBufferList; ; i = *(_QWORD *)(i + 32) )
{
if ( !i )
return i;
v2 = *(_DWORD **)(i + 32);
if ( !v2 )
break;
if ( *v2 == a1 )
return i;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 i; // r8
_DWORD *v2; // rax

for ( i = charBufferList; ; i = *(_QWORD *)(i + 32) )
{
if ( !i )
return i;
v2 = *(_DWORD **)(i + 32);
if ( !v2 )
break;
if ( *v2 == a1 )
return i;
}
return 0LL;
}

original_code:
charEntry *findPreCharEntry(int id){
 charEntry *temp = charBufferList;
 while(((void *)0) != temp && ((void *)0) != temp->next){
  if(temp->next->id == id)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct charBufferEntry *findPreCharEntry(int id){
 struct charBufferEntry *temp = charBufferList;
 while(((void *)0) != temp && ((void *)0) != temp->next){
  if(temp->next->id == id)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

user_defined_types: struct charBufferEntry { int id; char *buffer; char *bufp; int buffersize; struct charBufferEntry *next; }


findIntEntry

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

for ( result = intBufferList; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = intBufferList; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
intEntry *findIntEntry(int id){
 intEntry *temp = intBufferList;
 while(((void *)0) != temp){
  if(temp->id == id)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct intBufferEntry *findIntEntry(int id){
 struct intBufferEntry *temp = intBufferList;
 while(((void *)0) != temp){
  if(temp->id == id)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

variable_types: struct intBufferEntry { int id; int *buffer; int *bufp; int buffersize; struct intBufferEntry *next; } *


findPreIntEntry

decompiled_code:
__int64 __fastcall findPreIntEntry(int a1)
{
__int64 i; // r8
_DWORD *v2; // rax

for ( i = intBufferList; ; i = *(_QWORD *)(i + 32) )
{
if ( !i )
return i;
v2 = *(_DWORD **)(i + 32);
if ( !v2 )
break;
if ( *v2 == a1 )
return i;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 i; // r8
_DWORD *v2; // rax

for ( i = intBufferList; ; i = *(_QWORD *)(i + 32) )
{
if ( !i )
return i;
v2 = *(_DWORD **)(i + 32);
if ( !v2 )
break;
if ( *v2 == a1 )
return i;
}
return 0LL;
}

original_code:
intEntry *findPreIntEntry(int id){
 intEntry *temp = intBufferList;
 while(((void *)0) != temp && ((void *)0) != temp->next){
  if(temp->next->id == id)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct intBufferEntry *findPreIntEntry(int id){
 struct intBufferEntry *temp = intBufferList;
 while(((void *)0) != temp && ((void *)0) != temp->next){
  if(temp->next->id == id)
   return temp;
  temp = temp->next;
 }
 return ((void *)0);
}

return_type: struct intBufferEntry { int id; int *buffer; int *bufp; int buffersize; struct intBufferEntry *next; } *


removeCharLast

decompiled_code:
__int64 __fastcall removeCharLast(int a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = findCharEntry(a1);
if ( result )
{
v2 = *(_QWORD *)(result + 16);
if ( v2 != *(_QWORD *)(result + 8) )
*(_QWORD *)(result + 16) = v2 - 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = func1(a1);
if ( result )
{
v2 = *(_QWORD *)(result + 16);
if ( v2 != *(_QWORD *)(result + 8) )
*(_QWORD *)(result + 16) = v2 - 1;
}
return result;
}

original_code:
void removeCharLast(int id){
 charEntry *temp = findCharEntry(id);
 if(((void *)0) == temp)
  return;
 if(temp->bufp == temp->buffer)
  return;
 else
  (temp->bufp)--;
}

canonical_original_code:
void removeCharLast(int id){
 struct charBufferEntry *temp = findCharEntry(id);
 if(((void *)0) == temp)
  return;
 if(temp->bufp == temp->buffer)
  return;
 else
  (temp->bufp)--;
}


removeIntLast

decompiled_code:
__int64 __fastcall removeIntLast(int a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = findIntEntry(a1);
if ( result )
{
v2 = *(_QWORD *)(result + 16);
if ( v2 != *(_QWORD *)(result + 8) )
*(_QWORD *)(result + 16) = v2 - 4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = func3(a1);
if ( result )
{
v2 = *(_QWORD *)(result + 16);
if ( v2 != *(_QWORD *)(result + 8) )
*(_QWORD *)(result + 16) = v2 - 4;
}
return result;
}

original_code:
void removeIntLast(int id){
 intEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return;
 if(temp->bufp == temp->buffer)
  return;
 else
  (temp->bufp)--;
}

canonical_original_code:
void removeIntLast(int id){
 struct intBufferEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return;
 if(temp->bufp == temp->buffer)
  return;
 else
  (temp->bufp)--;
}

user_defined_types: struct intBufferEntry { int id; int *buffer; int *bufp; int buffersize; struct intBufferEntry *next; }


destroyCharBuffer

decompiled_code:
void __fastcall destroyCharBuffer(int a1)
{
__int64 v1; // rbx
void *v2; // rdi
__int64 v3; // rax

v1 = charBufferList;
if ( *(_DWORD *)charBufferList == a1 )
{
charBufferList = *(_QWORD *)(charBufferList + 32);
LABEL_3:
*(_DWORD *)v1 = 0;
v2 = *(void **)(v1 + 8);
*(_DWORD *)(v1 + 24) = 0;
free(v2);
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_QWORD *)(v1 + 32) = 0LL;
return;
}
v3 = findPreCharEntry(a1);
if ( v3 )
{
v1 = *(_QWORD *)(v3 + 32);
*(_QWORD *)(v3 + 32) = *(_QWORD *)(v1 + 32);
goto LABEL_3;
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
__int64 v1; // rbx
void *v2; // rdi
__int64 v3; // rax

v1 = charBufferList;
if ( *(_DWORD *)charBufferList == a1 )
{
charBufferList = *(_QWORD *)(charBufferList + 32);
LABEL_3:
*(_DWORD *)v1 = 0;
v2 = *(void **)(v1 + 8);
*(_DWORD *)(v1 + 24) = 0;
free(v2);
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_QWORD *)(v1 + 32) = 0LL;
return;
}
v3 = func2(a1);
if ( v3 )
{
v1 = *(_QWORD *)(v3 + 32);
*(_QWORD *)(v3 + 32) = *(_QWORD *)(v1 + 32);
goto LABEL_3;
}
}

original_code:
void destroyCharBuffer(int id){
 charEntry *temp = ((void *)0);
 if(charBufferList->id == id){
  temp = charBufferList;
  charBufferList = charBufferList->next;
 }else{
  charEntry *pre = findPreCharEntry(id);
  if(((void *)0) == pre)
   return;
  temp = pre->next;
  pre->next = pre->next->next;
 }
 temp->id = 0;
 temp->buffersize = 0;
 free(temp->buffer);
 temp->bufp = temp->buffer = 0;
 temp->next = ((void *)0);
}

canonical_original_code:
void destroyCharBuffer(int id){
 struct charBufferEntry *temp = ((void *)0);
 if(charBufferList->id == id){
  temp = charBufferList;
  charBufferList = charBufferList->next;
 }else{
  struct charBufferEntry *pre = findPreCharEntry(id);
  if(((void *)0) == pre)
   return;
  temp = pre->next;
  pre->next = pre->next->next;
 }
 temp->id = 0;
 temp->buffersize = 0;
 free(temp->buffer);
 temp->bufp = temp->buffer = 0;
 temp->next = ((void *)0);
}


destroyIntBuffer

decompiled_code:
void __fastcall destroyIntBuffer(int a1)
{
__int64 v1; // rbx
void *v2; // rdi
__int64 v3; // rax

v1 = intBufferList;
if ( *(_DWORD *)intBufferList == a1 )
{
intBufferList = *(_QWORD *)(intBufferList + 32);
LABEL_3:
*(_DWORD *)v1 = 0;
v2 = *(void **)(v1 + 8);
*(_DWORD *)(v1 + 24) = 0;
free(v2);
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_QWORD *)(v1 + 32) = 0LL;
return;
}
v3 = findPreIntEntry(a1);
if ( v3 )
{
v1 = *(_QWORD *)(v3 + 32);
*(_QWORD *)(v3 + 32) = *(_QWORD *)(v1 + 32);
goto LABEL_3;
}
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
__int64 v1; // rbx
void *v2; // rdi
__int64 v3; // rax

v1 = intBufferList;
if ( *(_DWORD *)intBufferList == a1 )
{
intBufferList = *(_QWORD *)(intBufferList + 32);
LABEL_3:
*(_DWORD *)v1 = 0;
v2 = *(void **)(v1 + 8);
*(_DWORD *)(v1 + 24) = 0;
free(v2);
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_QWORD *)(v1 + 32) = 0LL;
return;
}
v3 = func4(a1);
if ( v3 )
{
v1 = *(_QWORD *)(v3 + 32);
*(_QWORD *)(v3 + 32) = *(_QWORD *)(v1 + 32);
goto LABEL_3;
}
}

original_code:
void destroyIntBuffer(int id){
 intEntry *temp = ((void *)0);
 if(intBufferList->id == id){
  temp = intBufferList;
  intBufferList = intBufferList->next;
 }else{
  intEntry *pre = findPreIntEntry(id);
  if(((void *)0) == pre)
   return;
  temp = pre->next;
  pre->next = pre->next->next;
 }
 temp->id = 0;
 temp->buffersize = 0;
 free(temp->buffer);
 temp->bufp = temp->buffer = 0;
 temp->next = ((void *)0);
}

canonical_original_code:
void destroyIntBuffer(int id){
 struct intBufferEntry *temp = ((void *)0);
 if(intBufferList->id == id){
  temp = intBufferList;
  intBufferList = intBufferList->next;
 }else{
  struct intBufferEntry *pre = findPreIntEntry(id);
  if(((void *)0) == pre)
   return;
  temp = pre->next;
  pre->next = pre->next->next;
 }
 temp->id = 0;
 temp->buffersize = 0;
 free(temp->buffer);
 temp->bufp = temp->buffer = 0;
 temp->next = ((void *)0);
}


rewindCharPointer

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

result = findCharEntry(a1);
if ( result )
*(_QWORD *)(result + 16) = *(_QWORD *)(result + 8);
return result;
}

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

result = func1(a1);
if ( result )
*(_QWORD *)(result + 16) = *(_QWORD *)(result + 8);
return result;
}

original_code:
void rewindCharPointer(int id){
 charEntry *temp = findCharEntry(id);
 if(((void *)0) == temp)
  return;
 temp->bufp = temp->buffer;
}

canonical_original_code:
void rewindCharPointer(int id){
 struct charBufferEntry *temp = findCharEntry(id);
 if(((void *)0) == temp)
  return;
 temp->bufp = temp->buffer;
}


rewindIntPointer

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

result = findIntEntry(a1);
if ( result )
*(_QWORD *)(result + 16) = *(_QWORD *)(result + 8);
return result;
}

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

result = func3(a1);
if ( result )
*(_QWORD *)(result + 16) = *(_QWORD *)(result + 8);
return result;
}

original_code:
void rewindIntPointer(int id){
 intEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return;
 temp->bufp = temp->buffer;
}

canonical_original_code:
void rewindIntPointer(int id){
 struct intBufferEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return;
 temp->bufp = temp->buffer;
}


charSize

decompiled_code:
__int64 __fastcall charSize(int a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = findCharEntry(a1);
if ( v1 )
result = (unsigned int)*(_QWORD *)(v1 + 16) - *(_DWORD *)(v1 + 8);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = func1(a1);
if ( v1 )
result = (unsigned int)*(_QWORD *)(v1 + 16) - *(_DWORD *)(v1 + 8);
else
result = 0LL;
return result;
}

original_code:
int charSize(int id){
 charEntry *temp = findCharEntry(id);
 if(((void *)0) == temp)
  return 0;
 return temp->bufp - temp->buffer;
}

canonical_original_code:
int charSize(int id){
 struct charBufferEntry *temp = findCharEntry(id);
 if(((void *)0) == temp)
  return 0;
 return temp->bufp - temp->buffer;
}


intSize

decompiled_code:
__int64 __fastcall intSize(int a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = findIntEntry(a1);
if ( v1 )
result = (__int64)(*(_QWORD *)(v1 + 16) - *(_QWORD *)(v1 + 8)) >> 2;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = func3(a1);
if ( v1 )
result = (__int64)(*(_QWORD *)(v1 + 16) - *(_QWORD *)(v1 + 8)) >> 2;
else
result = 0LL;
return result;
}

original_code:
int intSize(int id){
 intEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return 0;
 return temp->bufp - temp->buffer;
}

canonical_original_code:
int intSize(int id){
 struct intBufferEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return 0;
 return temp->bufp - temp->buffer;
}


fillIntArrayWithBuffer

decompiled_code:
__int64 __fastcall fillIntArrayWithBuffer(int a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdi
__int64 v5; // rcx

result = findIntEntry(a1);
if ( result )
{
result = intSize(a1);
if ( (int)result > 0 )
{
v4 = *(_QWORD *)(v3 + 8);
v5 = (int)result;
for ( result = 0LL; result != v5; ++result )
*(_DWORD *)(a2 + 4 * result) = *(_DWORD *)(v4 + 4 * result);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdi
__int64 v5; // rcx

result = func3(a1);
if ( result )
{
result = func12(a1);
if ( (int)result > 0 )
{
v4 = *(_QWORD *)(v3 + 8);
v5 = (int)result;
for ( result = 0LL; result != v5; ++result )
*(_DWORD *)(a2 + 4 * result) = *(_DWORD *)(v4 + 4 * result);
}
}
return result;
}

original_code:
void fillIntArrayWithBuffer(int id, int *array){
 intEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return;
 int size = intSize(id);
 int i = 0;
 while(i < size){
  *(array+i) = *((temp->buffer)+i);
  i++;
 }
}

canonical_original_code:
void fillIntArrayWithBuffer(int id, int *array){
 struct intBufferEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return;
 int size = intSize(id);
 int i = 0;
 while(i < size){
  *(array+i) = *((temp->buffer)+i);
  i++;
 }
}

variable_types:
array
int *

variable_types: size int


isInIntBuffer

decompiled_code:
__int64 __fastcall isInIntBuffer(int a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
_DWORD *v4; // rax
_DWORD *v5; // rdx

v2 = findIntEntry(a1);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = *(_DWORD **)(v2 + 8);
v5 = *(_DWORD **)(v3 + 16);
if ( v4 == v5 )
return 0LL;
while ( *v4 != a2 )
{
if ( ++v4 == v5 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
_DWORD *v4; // rax
_DWORD *v5; // rdx

v2 = func3(a1);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = *(_DWORD **)(v2 + 8);
v5 = *(_DWORD **)(v3 + 16);
if ( v4 == v5 )
return 0LL;
while ( *v4 != a2 )
{
if ( ++v4 == v5 )
return 0LL;
}
return 1LL;
}

original_code:
int isInIntBuffer(int id, int i){
 intEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return 0;
 int *tempBufp = temp->buffer;
 while(tempBufp != temp->bufp){
  if(*tempBufp == i)
   return 1;
  tempBufp++;
 }
 return 0;
}

canonical_original_code:
int isInIntBuffer(int id, int i){
 struct intBufferEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return 0;
 int *tempBufp = temp->buffer;
 while(tempBufp != temp->bufp){
  if(*tempBufp == i)
   return 1;
  tempBufp++;
 }
 return 0;
}

variable_types:
tempBufp
int *


memError

decompiled_code:
size_t memError()
{
return fwrite("memory error!\n", 1uLL, 0xEuLL, stderr);
}

canonical_decompiled_code:
size_t func15()
{
return fwrite("memory error!\n", 1uLL, 0xEuLL, stderr);
}

original_code:
void memError(){
 fprintf(stderr, "memory error!\n");
}


initializeCharBuffer

decompiled_code:
__int64 initializeCharBuffer()
{
__int64 v0; // rax
__int64 v1; // rbp
_DWORD *v2; // rbx
int v3; // eax
unsigned int v4; // er12
void *v5; // rax
bool v6; // zf
__int64 result; // rax

v0 = charBufferList;
if ( charBufferList )
{
do
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( v0 );
}
else
{
v1 = 0LL;
}
v2 = malloc(0x28uLL);
if ( !v2 )
memError();
v3 = charNum;
v2[6] = 100;
v4 = v3 + 1;
charNum = v3 + 1;
*v2 = v3 + 1;
v5 = malloc(0x64uLL);
*((_QWORD *)v2 + 1) = v5;
*((_QWORD *)v2 + 2) = v5;
if ( !v5 )
{
memError();
v4 = charNum;
}
v6 = charBufferList == 0;
*((_QWORD *)v2 + 4) = 0LL;
if ( v6 )
{
result = v4;
charBufferList = (__int64)v2;
}
else
{
*(_QWORD *)(v1 + 32) = v2;
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 v0; // rax
__int64 v1; // rbp
_DWORD *v2; // rbx
int v3; // eax
unsigned int v4; // er12
void *v5; // rax
bool v6; // zf
__int64 result; // rax

v0 = charBufferList;
if ( charBufferList )
{
do
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( v0 );
}
else
{
v1 = 0LL;
}
v2 = malloc(0x28uLL);
if ( !v2 )
func15();
v3 = charNum;
v2[6] = 100;
v4 = v3 + 1;
charNum = v3 + 1;
*v2 = v3 + 1;
v5 = malloc(0x64uLL);
*((_QWORD *)v2 + 1) = v5;
*((_QWORD *)v2 + 2) = v5;
if ( !v5 )
{
func15();
v4 = charNum;
}
v6 = charBufferList == 0;
*((_QWORD *)v2 + 4) = 0LL;
if ( v6 )
{
result = v4;
charBufferList = (__int64)v2;
}
else
{
*(_QWORD *)(v1 + 32) = v2;
result = v4;
}
return result;
}

original_code:
int initializeCharBuffer(){
 charEntry *temp = charBufferList;
 charEntry *pre = ((void *)0);
 while(((void *)0) != temp){
  pre = temp;
  temp = temp->next;
 }
 temp = malloc(sizeof(charEntry));
 if(((void *)0) == temp)
  memError();
 temp->id = ++charNum;
 temp->buffersize = 100;
 temp->bufp = temp->buffer = malloc(100);
 if(((void *)0) == temp->bufp)
  memError();
 temp->next = ((void *)0);
 if(((void *)0) == charBufferList)
  charBufferList = temp;
 else
  pre->next = temp;
 return charNum;
}

canonical_original_code:
int initializeCharBuffer(){
 struct charBufferEntry *temp = charBufferList;
 struct charBufferEntry *pre = ((void *)0);
 while(((void *)0) != temp){
  pre = temp;
  temp = temp->next;
 }
 temp = malloc(sizeof(charEntry));
 if(((void *)0) == temp)
  memError();
 temp->id = ++charNum;
 temp->buffersize = 100;
 temp->bufp = temp->buffer = malloc(100);
 if(((void *)0) == temp->bufp)
  memError();
 temp->next = ((void *)0);
 if(((void *)0) == charBufferList)
  charBufferList = temp;
 else
  pre->next = temp;
 return charNum;
}


initializeIntBuffer

decompiled_code:
__int64 initializeIntBuffer()
{
__int64 v0; // rax
__int64 v1; // rbp
_DWORD *v2; // rbx
int v3; // eax
unsigned int v4; // er12
void *v5; // rax
bool v6; // zf
__int64 result; // rax

v0 = intBufferList;
if ( intBufferList )
{
do
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( v0 );
}
else
{
v1 = 0LL;
}
v2 = malloc(0x28uLL);
if ( !v2 )
memError();
v3 = intNum;
v2[6] = 100;
v4 = v3 + 1;
intNum = v3 + 1;
*v2 = v3 + 1;
v5 = malloc(0x190uLL);
*((_QWORD *)v2 + 1) = v5;
*((_QWORD *)v2 + 2) = v5;
if ( !v5 )
{
memError();
v4 = intNum;
}
v6 = intBufferList == 0;
*((_QWORD *)v2 + 4) = 0LL;
if ( v6 )
{
result = v4;
intBufferList = (__int64)v2;
}
else
{
*(_QWORD *)(v1 + 32) = v2;
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 v0; // rax
__int64 v1; // rbp
_DWORD *v2; // rbx
int v3; // eax
unsigned int v4; // er12
void *v5; // rax
bool v6; // zf
__int64 result; // rax

v0 = intBufferList;
if ( intBufferList )
{
do
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( v0 );
}
else
{
v1 = 0LL;
}
v2 = malloc(0x28uLL);
if ( !v2 )
func15();
v3 = intNum;
v2[6] = 100;
v4 = v3 + 1;
intNum = v3 + 1;
*v2 = v3 + 1;
v5 = malloc(0x190uLL);
*((_QWORD *)v2 + 1) = v5;
*((_QWORD *)v2 + 2) = v5;
if ( !v5 )
{
func15();
v4 = intNum;
}
v6 = intBufferList == 0;
*((_QWORD *)v2 + 4) = 0LL;
if ( v6 )
{
result = v4;
intBufferList = (__int64)v2;
}
else
{
*(_QWORD *)(v1 + 32) = v2;
result = v4;
}
return result;
}

original_code:
int initializeIntBuffer(){
 intEntry *temp = intBufferList;
 intEntry *pre = ((void *)0);
 while(((void *)0) != temp){
  pre = temp;
  temp = temp->next;
 }
 temp = malloc(sizeof(intEntry));
 if(((void *)0) == temp)
  memError();
 temp->id = ++intNum;
 temp->buffersize = 100;
 temp->bufp = temp->buffer = malloc(sizeof(int) * 100);
 if(((void *)0) == temp->bufp)
  memError();
 temp->next = ((void *)0);
 if(((void *)0) == intBufferList)
  intBufferList = temp;
 else
  pre->next = temp;
 return intNum;
}

canonical_original_code:
int initializeIntBuffer(){
 struct intBufferEntry *temp = intBufferList;
 struct intBufferEntry *pre = ((void *)0);
 while(((void *)0) != temp){
  pre = temp;
  temp = temp->next;
 }
 temp = malloc(sizeof(intEntry));
 if(((void *)0) == temp)
  memError();
 temp->id = ++intNum;
 temp->buffersize = 100;
 temp->bufp = temp->buffer = malloc(sizeof(int) * 100);
 if(((void *)0) == temp->bufp)
  memError();
 temp->next = ((void *)0);
 if(((void *)0) == intBufferList)
  intBufferList = temp;
 else
  pre->next = temp;
 return intNum;
}


addCharElement

decompiled_code:
__int64 __fastcall addCharElement(int a1, char a2)
{
__int64 result; // rax
__int64 v3; // rbx
void *v4; // r12
signed __int64 v5; // r13
void *v6; // rax
void *v7; // rdi

result = findCharEntry(a1);
if ( result )
{
v3 = result;
result = *(_QWORD *)(result + 16);
v4 = *(void **)(v3 + 8);
v5 = *(int *)(v3 + 24);
if ( result - (__int64)v4 >= v5 )
{
*(_DWORD *)(v3 + 24) = 2 * v5;
v6 = malloc(2 * (int)v5);
*(_QWORD *)(v3 + 8) = v6;
v7 = v6;
if ( !v6 )
{
memError();
v7 = *(void **)(v3 + 8);
v5 = *(_DWORD *)(v3 + 24) / 2;
}
memcpy(v7, v4, v5);
free(v4);
result = *(_QWORD *)(v3 + 8) + *(_DWORD *)(v3 + 24) / 2;
}
*(_QWORD *)(v3 + 16) = result + 1;
*(_BYTE *)result = a2;
}
return result;
}

original_code:
void addCharElement(int id, char c){
 charEntry *temp = findCharEntry(id);
 if(((void *)0) == temp)
  return;
 if(temp->bufp - temp->buffer >= temp->buffersize){
  temp->buffersize *= 2;
  char *old = temp->buffer;
  temp->buffer = malloc(temp->buffersize);
  if(temp->buffer == ((void *)0))
   memError();
  memcpy((void *)temp->buffer, (void *)old, (temp->buffersize)/2);
  free(old);
  temp->bufp = temp->buffer + ((temp->buffersize)/2);
 }
 *((temp->bufp)++) = c;
}

canonical_original_code:
void addCharElement(int id, char c){
 struct charBufferEntry *temp = findCharEntry(id);
 if(((void *)0) == temp)
  return;
 if(temp->bufp - temp->buffer >= temp->buffersize){
  temp->buffersize *= 2;
  char *old = temp->buffer;
  temp->buffer = malloc(temp->buffersize);
  if(temp->buffer == ((void *)0))
   memError();
  memcpy((void *)temp->buffer, (void *)old, (temp->buffersize)/2);
  free(old);
  temp->bufp = temp->buffer + ((temp->buffersize)/2);
 }
 *((temp->bufp)++) = c;
}

variable_types: c char

variable_types:
old
char *


addCharElements

decompiled_code:
__int64 __fastcall addCharElements(int a1, char *a2)
{
char *v2; // rbx
char v3; // si
__int64 result; // rax

v2 = a2;
v3 = *a2;
if ( v3 )
{
do
{
++v2;
result = addCharElement(a1, v3);
v3 = *v2;
}
while ( *v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1, char *a2)
{
char *v2; // rbx
char v3; // si
__int64 result; // rax

v2 = a2;
v3 = *a2;
if ( v3 )
{
do
{
++v2;
result = func18(a1, v3);
v3 = *v2;
}
while ( *v2 );
}
return result;
}

original_code:
void addCharElements(int id, char *s){
 while('\0' != *s){
  addCharElement(id, *s);
  s++;
 }
}

variable_types:
s
char *


addIntElement

original_code:
void addIntElement(int id, int i){
 intEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return;
 if(temp->bufp - temp->buffer >= temp->buffersize){
  temp->buffersize *= 2;
  int *old = temp->buffer;
  temp->buffer = malloc(sizeof(int) * temp->buffersize);
  if(temp->buffer == ((void *)0))
   memError();
  memcpy((void *)temp->buffer, (void *)old, sizeof(int) * (temp->buffersize)/2);
  free(old);
  temp->bufp = temp->buffer + ((temp->buffersize)/2);
 }
 *((temp->bufp)++) = i;
}

canonical_original_code:
void addIntElement(int id, int i){
 struct intBufferEntry *temp = findIntEntry(id);
 if(((void *)0) == temp)
  return;
 if(temp->bufp - temp->buffer >= temp->buffersize){
  temp->buffersize *= 2;
  int *old = temp->buffer;
  temp->buffer = malloc(sizeof(int) * temp->buffersize);
  if(temp->buffer == ((void *)0))
   memError();
  memcpy((void *)temp->buffer, (void *)old, sizeof(int) * (temp->buffersize)/2);
  free(old);
  temp->bufp = temp->buffer + ((temp->buffersize)/2);
 }
 *((temp->bufp)++) = i;
}

variable_types: i int

variable_types:
old
int *


isOperator

decompiled_code:
__int64 __fastcall isOperator(char a1)
{
return ((unsigned __int8)(a1 - 40) <= 3u) | (unsigned __int8)(a1 == 63 || a1 == -2 || a1 == 124);
}

original_code:
int isOperator(char c){
 if('*' == c)
  return 1;
 else if(-2 == c)
  return 1;
 else if('|' == c)
  return 1;
 else if('?' == c)
  return 1;
 else if('+' == c)
  return 1;
 else if('(' == c)
  return 1;
 else if(')' == c)
  return 1;
 else
  return 0;
}


getPrecedence

decompiled_code:
__int64 __fastcall getPrecedence(char a1, int a2)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 42) <= 1u || a1 == 63 )
return 10LL;
if ( a1 == -2 )
return 5LL;
result = 1LL;
if ( a1 != 124 )
{
if ( a1 == 40 )
result = a2 == 0 ? 0xB : 0;
else
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, int a2)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 42) <= 1u || a1 == 63 )
return 10LL;
if ( a1 == -2 )
return 5LL;
result = 1LL;
if ( a1 != 124 )
{
if ( a1 == 40 )
result = a2 == 0 ? 0xB : 0;
else
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int getPrecedence(char c, int instack){
 if('?' == c || '+' == c || '*' == c)
  return 10;
 else if(-2 == c)
  return 5;
 else if('|' == c)
  return 1;
 else if('(' == c){
  if(instack)
   return 0;
  else
   return 11;
 }else
  return -1;
}

variable_types: instack int