GetTermcapInfo

decompiled_code:
int GetTermcapInfo()
{
char *v0; // rax
const char *v1; // rbp
__int64 v2; // r12
char **v3; // rbx
const char *v4; // rsi
char *v5; // rbx
char *v7[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getenv("TERM");
if ( v0 )
{
v1 = v0;
LODWORD(v0) = tgetent(&scratch, v0);
if ( (_DWORD)v0 == 1 )
{
v5 = (char *)malloc(0x2800uLL);
v7[0] = v5;
term_vi = (int)tgetstr("vi", v7);
term_ve = (int)tgetstr("ve", v7);
if ( v7[0] > v5 + 10240 )
fatal("tgetstr overflow, you must have a very sick termcap");
LODWORD(v0) = (unsigned int)realloc(v5, v7[0] - v5);
}
v2 = term_vi;
if ( !term_vi || !term_ve )
{
v3 = off_C28;
v4 = "vt100";
do
{
LODWORD(v0) = strcmp(v1, v4);
if ( !(_DWORD)v0 )
{
term_vi = (__int64)"\x1B[?25l";
term_ve = (__int64)"\x1B[?25h";
return (int)v0;
}
v4 = *v3++;
}
while ( v4 );
if ( !v2 || !term_ve )
{
term_ve = 0LL;
term_vi = 0LL;
}
}
}
return (int)v0;
}

canonical_decompiled_code:
int func2()
{
char *v0; // rax
const char *v1; // rbp
__int64 v2; // r12
char **v3; // rbx
const char *v4; // rsi
char *v5; // rbx
char *v7[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getenv("TERM");
if ( v0 )
{
v1 = v0;
LODWORD(v0) = tgetent(&scratch, v0);
if ( (_DWORD)v0 == 1 )
{
v5 = (char *)malloc(0x2800uLL);
v7[0] = v5;
term_vi = (int)tgetstr("vi", v7);
term_ve = (int)tgetstr("ve", v7);
if ( v7[0] > v5 + 10240 )
fatal("tgetstr overflow, you must have a very sick termcap");
LODWORD(v0) = (unsigned int)realloc(v5, v7[0] - v5);
}
v2 = term_vi;
if ( !term_vi || !term_ve )
{
v3 = off_C28;
v4 = "vt100";
do
{
LODWORD(v0) = strcmp(v1, v4);
if ( !(_DWORD)v0 )
{
term_vi = (__int64)"\x1B[?25l";
term_ve = (__int64)"\x1B[?25h";
return (int)v0;
}
v4 = *v3++;
}
while ( v4 );
if ( !v2 || !term_ve )
{
term_ve = 0LL;
term_vi = 0LL;
}
}
}
return (int)v0;
}

original_code:
void GetTermcapInfo(void)
{
 char *term, *buf, *data;
 int bufSize = 10240;
 if (!(term = getenv("TERM")))
  return;
 if (tgetent(scratch, term) == 1) {
  data = buf = malloc(bufSize);
  term_vi = (char *)tgetstr("vi", &data);
  term_ve = (char *)tgetstr("ve", &data);
  if (data > buf + bufSize)
   fatal("tgetstr overflow, you must have a very sick termcap");
  buf = realloc(buf, data - buf);
 }
 if (!term_vi || !term_ve) {
  static char *vts[] = {
    "vt100", "vt101", "vt102",
    "vt200", "vt220", "vt300",
    "vt320", "vt400", "vt420",
    "screen", "xterm", ((void *)0) };
  int i;
  for (i = 0; vts[i]; i++)
   if (!strcmp(term, vts[i]))
   {
    term_vi = "\033[?25l";
    term_ve = "\033[?25h";
    break;
   }
 }
 if (!term_vi || !term_ve)
  term_vi = term_ve = ((void *)0);
}

canonical_original_code:
void GetTermcapInfo()
{
 char *term; char *buf; char *data;
 int bufSize = 10240;
 if (!(term = getenv("TERM")))
  return;
 if (tgetent(scratch, term) == 1) {
  data = buf = malloc(bufSize);
  term_vi = (char *)tgetstr("vi", &data);
  term_ve = (char *)tgetstr("ve", &data);
  if (data > buf + bufSize)
   fatal("tgetstr overflow, you must have a very sick termcap");
  buf = realloc(buf, data - buf);
 }
 if (!term_vi || !term_ve) {
  static char *vts[] = {
    "vt100", "vt101", "vt102",
    "vt200", "vt220", "vt300",
    "vt320", "vt400", "vt420",
    "screen", "xterm", ((void *)0) };
  int i;
  for (i = 0; vts[i]; i++)
   if (!strcmp(term, vts[i]))
   {
    term_vi = "\033[?25l";
    term_ve = "\033[?25h";
    break;
   }
 }
 if (!term_vi || !term_ve)
  term_vi = term_ve = ((void *)0);
}

variable_types:
term
char *

variable_types:
buf
char *

variable_types:
data
char *

variable_types: bufSize int

variable_types:
vts
char *[]

variable_types: i int


OutputTermStr

repo: naphthalene/tnetris

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

if ( a1 )
{
result = fputs(a1, stdout);
if ( a2 )
result = fflush(stdout);
}
return result;
}

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

if ( a1 )
{
result = fputs(a1, stdout);
if ( a2 )
result = fflush(stdout);
}
return result;
}

original_code:
void OutputTermStr(char *str, int flush)
{
 if (str) {
  fputs(str, stdout);
  if (flush)
   fflush(stdout);
 }
}

variable_types:
str
char *

variable_types: flush int

return_type: void


InitScreens

decompiled_code:
int InitScreens()
{
int result; // eax
bool v1; // al
__int16 *v2; // rbx
char v3; // di
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

GetTermcapInfo();
BlockSignals(v4, 2LL, 0LL);
initscr();
if ( colorEnable )
{
v1 = has_colors();
haveColor = v1;
if ( v1 )
{
start_color();
v2 = (__int16 *)&unk_C82;
v3 = 1;
do
{
init_pair(v3, 0, *v2);
v2 += 2;
v3 = *((_BYTE *)v2 - 2);
}
while ( v3 );
}
}
else
{
haveColor = 0;
}
AtExit(CleanupScreens);
RestoreSignals(0LL, v4);
cbreak();
noecho();
OutputTermStr((const char *)term_vi, 0);
AddEventGen(&keyGen);
wmove(stdscr, 0, 0);
waddnstr(stdscr, "Netris ", -1);
waddnstr(stdscr, version_string, -1);
result = waddnstr(stdscr, " (C) 1994-1996,1999 Mark H. Weaver \"netris -h\" for more info", -1);
statusYPos = 22;
statusXPos = 0;
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax
bool v1; // al
__int16 *v2; // rbx
char v3; // di
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

func2();
BlockSignals(v4, 2LL, 0LL);
initscr();
if ( colorEnable )
{
v1 = has_colors();
haveColor = v1;
if ( v1 )
{
start_color();
v2 = (__int16 *)&unk_C82;
v3 = 1;
do
{
init_pair(v3, 0, *v2);
v2 += 2;
v3 = *((_BYTE *)v2 - 2);
}
while ( v3 );
}
}
else
{
haveColor = 0;
}
AtExit(CleanupScreens);
RestoreSignals(0LL, v4);
cbreak();
noecho();
func3((const char *)term_vi, 0);
AddEventGen(&keyGen);
wmove(stdscr, 0, 0);
waddnstr(stdscr, "Netris ", -1);
waddnstr(stdscr, version_string, -1);
result = waddnstr(stdscr, " (C) 1994-1996,1999 Mark H. Weaver \"netris -h\" for more info", -1);
statusYPos = 22;
statusXPos = 0;
return result;
}

original_code:
void InitScreens(void)
{
 MySigSet oldMask;
 GetTermcapInfo();
 BlockSignals(&oldMask, 2, 0);
 initscr();
 haveColor = colorEnable && has_colors();
 if (haveColor)
 {
  int i = 0;
  start_color();
  for (i = 0; myColorTable[i].type != BT_none; ++i)
   init_pair(myColorTable[i].type, 0,
     myColorTable[i].color);
 }
 AtExit(CleanupScreens);
 RestoreSignals(((void *)0), &oldMask);
 cbreak();
 noecho();
 OutputTermStr(term_vi, 0);
 AddEventGen(&keyGen);
 wmove(stdscr,(0),(0));
 waddnstr(stdscr,("Netris "),-1);
 waddnstr(stdscr,(version_string),-1);
 waddnstr(stdscr,(" (C) 1994-1996,1999  Mark H. Weaver     " "\"netris -h\" for more info"),-1);
 statusYPos = 22;
 statusXPos = 0;
}

canonical_original_code:
void InitScreens()
{
 struct __sigset_t oldMask;
 GetTermcapInfo();
 BlockSignals(&oldMask, 2, 0);
 initscr();
 haveColor = colorEnable && has_colors();
 if (haveColor)
 {
  int i = 0;
  start_color();
  for (i = 0; myColorTable[i].type != BT_none; ++i)
   init_pair(myColorTable[i].type, 0,
     myColorTable[i].color);
 }
 AtExit(CleanupScreens);
 RestoreSignals(((void *)0), &oldMask);
 cbreak();
 noecho();
 OutputTermStr(term_vi, 0);
 AddEventGen(&keyGen);
 wmove(stdscr,(0),(0));
 waddnstr(stdscr,("Netris "),-1);
 waddnstr(stdscr,(version_string),-1);
 waddnstr(stdscr,(" (C) 1994-1996,1999  Mark H. Weaver     " "\"netris -h\" for more info"),-1);
 statusYPos = 22;
 statusXPos = 0;
}

variable_types: struct __sigset_t { unsigned long __val[-1]; }


CleanupScreens

decompiled_code:
int CleanupScreens()
{
RemoveEventGen(&keyGen);
endwin();
return OutputTermStr((const char *)term_ve, 1);
}

canonical_decompiled_code:
int func5()
{
RemoveEventGen(&keyGen);
endwin();
return func3((const char *)term_ve, 1);
}

original_code:
void CleanupScreens(void)
{
 RemoveEventGen(&keyGen);
 endwin();
 OutputTermStr(term_ve, 1);
}

canonical_original_code:
void CleanupScreens()
{
 RemoveEventGen(&keyGen);
 endwin();
 OutputTermStr(term_ve, 1);
}


InitScreen

decompiled_code:
__int64 __fastcall InitScreen(int a1)
{
int v1; // edx
int v2; // eax
int v3; // ebx
__int64 result; // rax
int i; // er13
int v6; // ebx

v1 = 1;
if ( a1 )
v1 = boardXPos[a1 - 1] + 2 * *((_DWORD *)&boardWidth + a1 - 1) + 3;
boardXPos[a1] = v1;
boardYPos[a1] = 22;
v2 = v1 + 2 * *((_DWORD *)&boardWidth + a1);
if ( v2 + 2 >= statusXPos )
statusXPos = v2 + 3;
v3 = *((_DWORD *)&boardVisible + a1) - 1;
if ( v3 >= 0 )
{
do
{
wmove(stdscr, boardYPos[a1] - v3, boardXPos[a1] - 1);
waddch(stdscr, 0x7CuLL);
wmove(stdscr, boardYPos[a1] - v3, boardXPos[a1] + 2 * *((_DWORD *)&boardWidth + a1));
waddch(stdscr, 0x7CuLL);
--v3;
}
while ( v3 != -1 );
}
result = a1;
for ( i = *((_DWORD *)&boardVisible + a1); i >= -1; i -= result )
{
wmove(stdscr, boardYPos[a1] - i, boardXPos[a1] - 1);
waddch(stdscr, 0x2BuLL);
v6 = *((_DWORD *)&boardWidth + a1) - 1;
if ( v6 >= 0 )
{
do
{
waddnstr(stdscr, "--", -1);
--v6;
}
while ( v6 != -1 );
}
waddch(stdscr, 0x2BuLL);
result = (unsigned int)(*((_DWORD *)&boardVisible + a1) + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // edx
int v2; // eax
int v3; // ebx
__int64 result; // rax
int i; // er13
int v6; // ebx

v1 = 1;
if ( a1 )
v1 = boardXPos[a1 - 1] + 2 * *((_DWORD *)&boardWidth + a1 - 1) + 3;
boardXPos[a1] = v1;
boardYPos[a1] = 22;
v2 = v1 + 2 * *((_DWORD *)&boardWidth + a1);
if ( v2 + 2 >= statusXPos )
statusXPos = v2 + 3;
v3 = *((_DWORD *)&boardVisible + a1) - 1;
if ( v3 >= 0 )
{
do
{
wmove(stdscr, boardYPos[a1] - v3, boardXPos[a1] - 1);
waddch(stdscr, 0x7CuLL);
wmove(stdscr, boardYPos[a1] - v3, boardXPos[a1] + 2 * *((_DWORD *)&boardWidth + a1));
waddch(stdscr, 0x7CuLL);
--v3;
}
while ( v3 != -1 );
}
result = a1;
for ( i = *((_DWORD *)&boardVisible + a1); i >= -1; i -= result )
{
wmove(stdscr, boardYPos[a1] - i, boardXPos[a1] - 1);
waddch(stdscr, 0x2BuLL);
v6 = *((_DWORD *)&boardWidth + a1) - 1;
if ( v6 >= 0 )
{
do
{
waddnstr(stdscr, "--", -1);
--v6;
}
while ( v6 != -1 );
}
waddch(stdscr, 0x2BuLL);
result = (unsigned int)(*((_DWORD *)&boardVisible + a1) + 1);
}
return result;
}

original_code:
void InitScreen(int scr)
{
 int y, x;
 if (scr == 0)
  boardXPos[scr] = 1;
 else
  boardXPos[scr] = boardXPos[scr - 1] +
     2 * boardWidth[scr - 1] + 3;
 boardYPos[scr] = 22;
 if (statusXPos < boardXPos[scr] + 2 * boardWidth[scr] + 3)
  statusXPos = boardXPos[scr] + 2 * boardWidth[scr] + 3;
 for (y = boardVisible[scr] - 1; y >= 0; --y) {
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] - 1));
  waddch(stdscr,('|'));
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] + 2 * boardWidth[scr]));
  waddch(stdscr,('|'));
 }
 for (y = boardVisible[scr]; y >= -1; y -= boardVisible[scr] + 1) {
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] - 1));
  waddch(stdscr,('+'));
  for (x = boardWidth[scr] - 1; x >= 0; --x)
   waddnstr(stdscr,("--"),-1);
  waddch(stdscr,('+'));
 }
}

canonical_original_code:
void InitScreen(int scr)
{
 int y; int x;
 if (scr == 0)
  boardXPos[scr] = 1;
 else
  boardXPos[scr] = boardXPos[scr - 1] +
     2 * boardWidth[scr - 1] + 3;
 boardYPos[scr] = 22;
 if (statusXPos < boardXPos[scr] + 2 * boardWidth[scr] + 3)
  statusXPos = boardXPos[scr] + 2 * boardWidth[scr] + 3;
 for (y = boardVisible[scr] - 1; y >= 0; --y) {
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] - 1));
  waddch(stdscr,('|'));
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] + 2 * boardWidth[scr]));
  waddch(stdscr,('|'));
 }
 for (y = boardVisible[scr]; y >= -1; y -= boardVisible[scr] + 1) {
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] - 1));
  waddch(stdscr,('+'));
  for (x = boardWidth[scr] - 1; x >= 0; --x)
   waddnstr(stdscr,("--"),-1);
  waddch(stdscr,('+'));
 }
}

variable_types: scr int

variable_types: y int

variable_types: x int


CleanupScreen

decompiled_code:
void CleanupScreen()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void CleanupScreen(int scr)
{
}

canonical_original_code:
void CleanupScreen(int scr)
{
}


PlotBlock

decompiled_code:
int __fastcall PlotBlock(int a1, int a2, int a3, char a4)
{
int result; // eax

if ( a2 >= 0 )
{
result = a1;
if ( *((_DWORD *)&boardVisible + a1) > a2 && a3 >= 0 && *((_DWORD *)&boardWidth + a1) > a3 )
result = PlotBlock1(a1, a2, a3, a4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2, int a3, char a4)
{
int result; // eax

if ( a2 >= 0 )
{
result = a1;
if ( *((_DWORD *)&boardVisible + a1) > a2 && a3 >= 0 && *((_DWORD *)&boardWidth + a1) > a3 )
result = func1(a1, a2, a3, a4);
}
return result;
}

original_code:
void PlotBlock(int scr, int y, int x, BlockType type)
{
 if (y >= 0 && y < boardVisible[scr] && x >= 0 && x < boardWidth[scr])
  PlotBlock1(scr, y, x, type);
}

canonical_original_code:
void PlotBlock(int scr, int y, int x, char type)
{
 if (y >= 0 && y < boardVisible[scr] && x >= 0 && x < boardWidth[scr])
  PlotBlock1(scr, y, x, type);
}

variable_types: type char


PlotUnderline

decompiled_code:
int __fastcall PlotUnderline(int a1, int a2, int a3)
{
const char *v4; // rsi

wmove(stdscr, boardYPos[a1] + 1, boardXPos[a1] + 2 * a2);
v4 = "==";
if ( !a3 )
v4 = "--";
return waddnstr(stdscr, v4, -1);
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2, int a3)
{
const char *v4; // rsi

wmove(stdscr, boardYPos[a1] + 1, boardXPos[a1] + 2 * a2);
v4 = "==";
if ( !a3 )
v4 = "--";
return waddnstr(stdscr, v4, -1);
}

original_code:
void PlotUnderline(int scr, int x, int flag)
{
 wmove(stdscr,(boardYPos[scr] + 1),(boardXPos[scr] + 2 * x));
 waddnstr(stdscr,(flag ? "==" : "--"),-1);
}

variable_types: flag int


ShowDisplayInfo

decompiled_code:
int ShowDisplayInfo()
{
int result; // eax

wmove(stdscr, statusYPos - 9, statusXPos);
printw("Seed: %d", initSeed);
wclrtoeol(stdscr);
wmove(stdscr, statusYPos - 8, statusXPos);
printw("Speed: %dms", speed / 1000LL);
result = wclrtoeol(stdscr);
if ( robotEnable )
{
wmove(stdscr, statusYPos - 6, statusXPos);
if ( fairRobot )
waddnstr(stdscr, "Controlled by a fair robot", -1);
else
waddnstr(stdscr, "Controlled by a robot", -1);
result = wclrtoeol(stdscr);
}
if ( (opponentFlags & 1) != 0 )
{
wmove(stdscr, statusYPos - 5, statusXPos);
if ( (opponentFlags & 2) != 0 )
waddnstr(stdscr, "The opponent is a fair robot", -1);
else
waddnstr(stdscr, "The opponent is a robot", -1);
result = wclrtoeol(stdscr);
}
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax

wmove(stdscr, statusYPos - 9, statusXPos);
printw("Seed: %d", initSeed);
wclrtoeol(stdscr);
wmove(stdscr, statusYPos - 8, statusXPos);
printw("Speed: %dms", speed / 1000LL);
result = wclrtoeol(stdscr);
if ( robotEnable )
{
wmove(stdscr, statusYPos - 6, statusXPos);
if ( fairRobot )
waddnstr(stdscr, "Controlled by a fair robot", -1);
else
waddnstr(stdscr, "Controlled by a robot", -1);
result = wclrtoeol(stdscr);
}
if ( (opponentFlags & 1) != 0 )
{
wmove(stdscr, statusYPos - 5, statusXPos);
if ( (opponentFlags & 2) != 0 )
waddnstr(stdscr, "The opponent is a fair robot", -1);
else
waddnstr(stdscr, "The opponent is a robot", -1);
result = wclrtoeol(stdscr);
}
return result;
}

original_code:
void ShowDisplayInfo(void)
{
 wmove(stdscr,(statusYPos - 9),(statusXPos));
 printw("Seed: %d", initSeed);
 wclrtoeol(stdscr);
 wmove(stdscr,(statusYPos - 8),(statusXPos));
 printw("Speed: %dms", speed / 1000);
 wclrtoeol(stdscr);
 if (robotEnable) {
  wmove(stdscr,(statusYPos - 6),(statusXPos));
  if (fairRobot)
   waddnstr(stdscr,("Controlled by a fair robot"),-1);
  else
   waddnstr(stdscr,("Controlled by a robot"),-1);
  wclrtoeol(stdscr);
 }
 if (opponentFlags & 000001) {
  wmove(stdscr,(statusYPos - 5),(statusXPos));
  if (opponentFlags & 000002)
   waddnstr(stdscr,("The opponent is a fair robot"),-1);
  else
   waddnstr(stdscr,("The opponent is a robot"),-1);
  wclrtoeol(stdscr);
 }
}

canonical_original_code:
void ShowDisplayInfo()
{
 wmove(stdscr,(statusYPos - 9),(statusXPos));
 printw("Seed: %d", initSeed);
 wclrtoeol(stdscr);
 wmove(stdscr,(statusYPos - 8),(statusXPos));
 printw("Speed: %dms", speed / 1000);
 wclrtoeol(stdscr);
 if (robotEnable) {
  wmove(stdscr,(statusYPos - 6),(statusXPos));
  if (fairRobot)
   waddnstr(stdscr,("Controlled by a fair robot"),-1);
  else
   waddnstr(stdscr,("Controlled by a robot"),-1);
  wclrtoeol(stdscr);
 }
 if (opponentFlags & 000001) {
  wmove(stdscr,(statusYPos - 5),(statusXPos));
  if (opponentFlags & 000002)
   waddnstr(stdscr,("The opponent is a fair robot"),-1);
  else
   waddnstr(stdscr,("The opponent is a robot"),-1);
  wclrtoeol(stdscr);
 }
}


UpdateOpponentDisplay

decompiled_code:
int UpdateOpponentDisplay()
{
wmove(stdscr, 1, 0);
printw("Playing %s@%s", (const char *)&opponentName, (const char *)&opponentHost);
return wclrtoeol(stdscr);
}

canonical_decompiled_code:
int func11()
{
wmove(stdscr, 1, 0);
printw("Playing %s@%s", (const char *)&opponentName, (const char *)&opponentHost);
return wclrtoeol(stdscr);
}

original_code:
void UpdateOpponentDisplay(void)
{
 wmove(stdscr,(1),(0));
 printw("Playing %s@%s", opponentName, opponentHost);
 wclrtoeol(stdscr);
}

canonical_original_code:
void UpdateOpponentDisplay()
{
 wmove(stdscr,(1),(0));
 printw("Playing %s@%s", opponentName, opponentHost);
 wclrtoeol(stdscr);
}


ShowPause

decompiled_code:
int __fastcall ShowPause(int a1, int a2)
{
int result; // eax

wmove(stdscr, statusYPos - 3, statusXPos);
if ( a2 )
waddnstr(stdscr, "Game paused by opponent", -1);
else
wclrtoeol(stdscr);
wmove(stdscr, statusYPos - 2, statusXPos);
if ( a1 )
result = waddnstr(stdscr, "Game paused by you", -1);
else
result = wclrtoeol(stdscr);
return result;
}

canonical_decompiled_code:
int __fastcall func12(int a1, int a2)
{
int result; // eax

wmove(stdscr, statusYPos - 3, statusXPos);
if ( a2 )
waddnstr(stdscr, "Game paused by opponent", -1);
else
wclrtoeol(stdscr);
wmove(stdscr, statusYPos - 2, statusXPos);
if ( a1 )
result = waddnstr(stdscr, "Game paused by you", -1);
else
result = wclrtoeol(stdscr);
return result;
}

original_code:
void ShowPause(int pausedByMe, int pausedByThem)
{
 wmove(stdscr,(statusYPos - 3),(statusXPos));
 if (pausedByThem)
  waddnstr(stdscr,("Game paused by opponent"),-1);
 else
  wclrtoeol(stdscr);
 wmove(stdscr,(statusYPos - 2),(statusXPos));
 if (pausedByMe)
  waddnstr(stdscr,("Game paused by you"),-1);
 else
  wclrtoeol(stdscr);
}

variable_types: pausedByMe int

variable_types: pausedByThem int


Message

decompiled_code:
int __fastcall Message(char *a1)
{
wmove(stdscr, statusYPos + line_1 - 20, statusXPos);
waddnstr(stdscr, a1, -1);
wclrtoeol(stdscr);
line_1 = (line_1 + 1) % 10;
wmove(stdscr, line_1 + statusYPos - 20, statusXPos);
return wclrtoeol(stdscr);
}

canonical_decompiled_code:
int __fastcall func13(char *a1)
{
wmove(stdscr, statusYPos + line_1 - 20, statusXPos);
waddnstr(stdscr, a1, -1);
wclrtoeol(stdscr);
line_1 = (line_1 + 1) % 10;
wmove(stdscr, line_1 + statusYPos - 20, statusXPos);
return wclrtoeol(stdscr);
}

original_code:
void Message(char *s)
{
 static int line = 0;
 wmove(stdscr,(statusYPos - 20 + line),(statusXPos));
 waddnstr(stdscr,(s),-1);
 wclrtoeol(stdscr);
 line = (line + 1) % 10;
 wmove(stdscr,(statusYPos - 20 + line),(statusXPos));
 wclrtoeol(stdscr);
}

variable_types:
s
char *

variable_types: line int


RefreshScreen

decompiled_code:
int RefreshScreen()
{
signed int v0; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = (unsigned int)localtime(&timer);
strftime(timeStr_0, 0x1EuLL, "%I:%M %p", (const struct tm *)v0);
if ( strcmp(timeStr_0, dest) )
{
wmove(stdscr, statusYPos, statusXPos);
waddnstr(stdscr, timeStr_0, -1);
strcpy(dest, timeStr_0);
}
wmove(stdscr, boardYPos[0] + 1, boardXPos[0] + 2 * boardWidth + 1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func14()
{
signed int v0; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = (unsigned int)localtime(&timer);
strftime(timeStr_0, 0x1EuLL, "%I:%M %p", (const struct tm *)v0);
if ( strcmp(timeStr_0, dest) )
{
wmove(stdscr, statusYPos, statusXPos);
waddnstr(stdscr, timeStr_0, -1);
strcpy(dest, timeStr_0);
}
wmove(stdscr, boardYPos[0] + 1, boardXPos[0] + 2 * boardWidth + 1);
return wrefresh(stdscr);
}

original_code:
void RefreshScreen(void)
{
 static char timeStr[2][32];
 time_t theTime;
 time(&theTime);
 strftime(timeStr[0], 30, "%I:%M %p", localtime(&theTime));
 if (strcmp(timeStr[0], timeStr[1]))
 {
  wmove(stdscr,(statusYPos),(statusXPos));
  waddnstr(stdscr,(timeStr[0]),-1);
  strcpy(timeStr[1], timeStr[0]);
 }
 wmove(stdscr,(boardYPos[0] + 1),(boardXPos[0] + 2 * boardWidth[0] + 1));
 wrefresh(stdscr);
}

canonical_original_code:
void RefreshScreen()
{
 static char timeStr[2][32];
 long theTime;
 time(&theTime);
 strftime(timeStr[0], 30, "%I:%M %p", localtime(&theTime));
 if (strcmp(timeStr[0], timeStr[1]))
 {
  wmove(stdscr,(statusYPos),(statusXPos));
  waddnstr(stdscr,(timeStr[0]),-1);
  strcpy(timeStr[1], timeStr[0]);
 }
 wmove(stdscr,(boardYPos[0] + 1),(boardXPos[0] + 2 * boardWidth[0] + 1));
 wrefresh(stdscr);
}

variable_types:
timeStr
char [2][32]

variable_types: theTime long


ScheduleFullRedraw

decompiled_code:
int ScheduleFullRedraw()
{
int v0; // edx

v0 = -1;
if ( stdscr )
v0 = stdscr->_maxy + 1;
return wtouchln(stdscr, 0, v0, 1);
}

canonical_decompiled_code:
int func15()
{
int v0; // edx

v0 = -1;
if ( stdscr )
v0 = stdscr->_maxy + 1;
return wtouchln(stdscr, 0, v0, 1);
}

original_code:
void ScheduleFullRedraw(void)
{
 wtouchln((stdscr), 0, ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), 1);
}

canonical_original_code:
void ScheduleFullRedraw()
{
 wtouchln((stdscr), 0, ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), 1);
}


repo: nardinan/serenity

decompiled_code:
unsigned __int64 __fastcall p_object_compare(__int64 a1, __int64 a2)
{
return 0xCCCCCCCCCCCCCCCDLL * ((a1 - a2) >> 5);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2)
{
return 0xCCCCCCCCCCCCCCCDLL * ((a1 - a2) >> 5);
}

original_code:
int p_object_compare(struct o_object *object, struct o_object *other) {
  return (int)(object-other);
}

variable_types: struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } *

variable_types:
other
struct o_object *

return_type: int

user_defined_types: struct o_object { struct s_list_node head; char *kind; unsigned long size; long long hash; union pthread_mutex_t mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


original_code:
t_hash_value p_object_hash(struct o_object *object) {
  if (!object->s_flags.hashed) {
    object->hash = (t_hash_value)object;
    object->s_flags.hashed = 1;
  }
  return object->hash;
}

canonical_original_code:
long long p_object_hash(struct o_object *object) {
  if (!object->s_flags.hashed) {
    object->hash = (long long)object;
    object->s_flags.hashed = 1;
  }
  return object->hash;
}

return_type: long long

user_defined_types: struct s_list_node { struct s_list_node *next; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
char *__fastcall p_object_string(__int64 a1, char *a2, size_t a3)
{
size_t v4; // rax

v4 = snprintf(a2, a3, "<%s size: %zu>", *(const char **)(a1 + 16), *(_QWORD *)(a1 + 24));
if ( (int)v4 > a3 )
v4 = a3;
return &a2[v4];
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, char *a2, size_t a3)
{
size_t v4; // rax

v4 = snprintf(a2, a3, "<%s size: %zu>", *(const char **)(a1 + 16), *(_QWORD *)(a1 + 24));
if ( (int)v4 > a3 )
v4 = a3;
return &a2[v4];
}

original_code:
char *p_object_string(struct o_object *object, char *data, size_t size) {
  size_t written = snprintf(data, size, "<%s size: %zu>", object->kind, object->size);
  return data+((written>size)?size:written);
}

canonical_original_code:
char *p_object_string(struct o_object *object, char *data, unsigned long size) {
  unsigned long written = snprintf(data, size, "<%s size: %zu>", object->kind, object->size);
  return data+((written>size)?size:written);
}

variable_types:
data
char *

variable_types:
size
unsigned long

variable_types:
written
unsigned long

return_type: char *


decompiled_code:
_BOOL8 __fastcall p_object_trylock(__int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_trylock((pthread_mutex_t *)(a1 + 48)) == 0;
return result;
}

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

result = 0LL;
if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_trylock((pthread_mutex_t *)(a1 + 48)) == 0;
return result;
}

original_code:
int p_object_trylock(struct o_object *object) {
  int locked = 0;
  if (object->s_flags.mutexed)
    if (pthread_mutex_trylock(&(object->mutex)) == 0)
      locked = 1;
  return locked;
}

variable_types: locked int


decompiled_code:
int __fastcall p_object_lock(__int64 a1)
{
int result; // eax

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
return result;
}

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

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
return result;
}

original_code:
void p_object_lock(struct o_object *object) {
  if (object->s_flags.mutexed)
    pthread_mutex_lock(&(object->mutex));
}


decompiled_code:
int __fastcall p_object_unlock(__int64 a1)
{
int result; // eax

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
return result;
}

original_code:
void p_object_unlock(struct o_object *object) {
  if (object->s_flags.mutexed)
    pthread_mutex_unlock(&(object->mutex));
}


decompiled_code:
char *__fastcall f_object_new(__int64 a1, size_t a2, char *a3)
{
char *v3; // rbx
void *v5; // rax
__int64 v6; // rax

if ( a3 )
{
v3 = a3;
memset(a3, 0, a2);
v3[88] |= 1u;
}
else
{
v5 = calloc(1uLL, a2);
v6 = p_memory_insert(v5, "o_object.c", "f_object_new", 39LL, 0LL);
v3 = (char *)v6;
if ( !v6 )
{
p_log_write(stderr, 0LL, "o_object.c", "f_object_new", 42LL, "out of memory! I'm dying: 'bleaaargh'");
exit(1);
}
*(_BYTE *)(v6 + 88) &= 0xFEu;
}
if ( !pthread_mutex_init((pthread_mutex_t *)(v3 + 48), 0LL) )
v3[88] |= 8u;
*((_QWORD *)v3 + 2) = a1;
*((_QWORD *)v3 + 3) = a2;
p_object_hooking(v3);
return v3;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, size_t a2, char *a3)
{
char *v3; // rbx
void *v5; // rax
__int64 v6; // rax

if ( a3 )
{
v3 = a3;
memset(a3, 0, a2);
v3[88] |= 1u;
}
else
{
v5 = calloc(1uLL, a2);
v6 = p_memory_insert(v5, "o_object.c", "f_object_new", 39LL, 0LL);
v3 = (char *)v6;
if ( !v6 )
{
p_log_write(stderr, 0LL, "o_object.c", "f_object_new", 42LL, "out of memory! I'm dying: 'bleaaargh'");
exit(1);
}
*(_BYTE *)(v6 + 88) &= 0xFEu;
}
if ( !pthread_mutex_init((pthread_mutex_t *)(v3 + 48), 0LL) )
v3[88] |= 8u;
*((_QWORD *)v3 + 2) = a1;
*((_QWORD *)v3 + 3) = a2;
p_object_hooking(v3);
return v3;
}

original_code:
struct o_object *f_object_new(const char *kind, size_t size, struct o_object *supplied) {
  struct o_object *result = supplied;
  if (result) {
    memset(result, 0, size);
    result->s_flags.supplied = 1;
  } else if ((result = (struct o_object *) p_memory_insert(calloc((1),(size)),"o_object.c",__FUNCTION__,39,0)))
    result->s_flags.supplied = 0;
  else
    do{ p_log_write(stderr,e_log_level_ever,"o_object.c",__FUNCTION__,42,"out of memory! I'm dying: 'bleaaargh'"); exit(1); }while(0);;
  if (pthread_mutex_init(&(result->mutex), ((void *)0)) == 0)
    result->s_flags.mutexed = 1;
  result->kind = kind;
  result->size = size;
  p_object_hooking(result);
  return result;
}

canonical_original_code:
struct o_object *f_object_new(char *kind, unsigned long size, struct o_object *supplied) {
  struct o_object *result = supplied;
  if (result) {
    memset(result, 0, size);
    result->s_flags.supplied = 1;
  } else if ((result = (struct o_object *) p_memory_insert(calloc((1),(size)),"o_object.c",__FUNCTION__,39,0)))
    result->s_flags.supplied = 0;
  else
    do{ p_log_write(stderr,e_log_level_ever,"o_object.c",__FUNCTION__,42,"out of memory! I'm dying: 'bleaaargh'"); exit(1); }while(0);;
  if (pthread_mutex_init(&(result->mutex), ((void *)0)) == 0)
    result->s_flags.mutexed = 1;
  result->kind = kind;
  result->size = size;
  p_object_hooking(result);
  return result;
}

variable_types:
kind
char *

variable_types:
supplied
struct o_object *

return_type: struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } *


decompiled_code:
char *__fastcall f_object_new_pure(char *a1)
{
return f_object_new((__int64)"object", 0xA0uLL, a1);
}

canonical_decompiled_code:
char *__fastcall func7(char *a1)
{
return func6((__int64)"object", 0xA0uLL, a1);
}

original_code:
struct o_object *f_object_new_pure(struct o_object *supplied) {
  return f_object_new(v_object_kind, sizeof(struct o_object), supplied);
}


decompiled_code:
char *__fastcall p_object_clone(void *src)
{
char *v1; // rax
char *v2; // rbx

v1 = f_object_new(*((_QWORD *)src + 2), *((_QWORD *)src + 3), 0LL);
v2 = v1;
if ( v1 )
{
memcpy(v1, src, *((_QWORD *)src + 3));
if ( !pthread_mutex_init((pthread_mutex_t *)(v2 + 48), 0LL) )
v2[88] |= 8u;
*((_QWORD *)v2 + 4) = 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func8(void *src)
{
char *v1; // rax
char *v2; // rbx

v1 = func6(*((_QWORD *)src + 2), *((_QWORD *)src + 3), 0LL);
v2 = v1;
if ( v1 )
{
memcpy(v1, src, *((_QWORD *)src + 3));
if ( !pthread_mutex_init((pthread_mutex_t *)(v2 + 48), 0LL) )
v2[88] |= 8u;
*((_QWORD *)v2 + 4) = 0LL;
}
return v2;
}

original_code:
struct o_object *p_object_clone(struct o_object *object) {
  struct o_object *result;
  if ((result = f_object_new(object->kind, object->size, ((void *)0)))) {
    memcpy(result, object, object->size);
    if (pthread_mutex_init(&(result->mutex), ((void *)0)) == 0)
      result->s_flags.mutexed = 1;
    result->references = 0;
  }
  return result;
}

variable_types:
object
struct o_object *


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

result = a1;
if ( a1 )
++*(_QWORD *)(a1 + 32);
return result;
}

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

result = a1;
if ( a1 )
++*(_QWORD *)(a1 + 32);
return result;
}

original_code:
struct o_object *f_object_retain(struct o_object *object) {
  if (object)
    object->references++;
  return object;
}


decompiled_code:
void __fastcall p_object_delete(void *ptr)
{
if ( (*((_BYTE *)ptr + 88) & 8) != 0 )
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
if ( (*((_BYTE *)ptr + 88) & 1) != 0 )
{
memset(ptr, 0, *((_QWORD *)ptr + 3));
}
else
{
p_memory_remove(ptr, "o_object.c", "p_object_delete", 72LL, 0LL);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( (*((_BYTE *)ptr + 88) & 8) != 0 )
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
if ( (*((_BYTE *)ptr + 88) & 1) != 0 )
{
memset(ptr, 0, *((_QWORD *)ptr + 3));
}
else
{
p_memory_remove(ptr, "o_object.c", "p_object_delete", 72LL, 0LL);
free(ptr);
}
}

original_code:
void p_object_delete(struct o_object *object) {
  if (object->s_flags.mutexed)
    pthread_mutex_destroy(&(object->mutex));
  if (!object->s_flags.supplied) {
    do{ p_memory_remove((object),"o_object.c",__FUNCTION__,72,0); free(object); }while(0);
    object = ((void *)0);
  } else
    memset(object, 0, object->size);
}


decompiled_code:
void __fastcall f_object_release(void *ptr)
{
__int64 v1; // rax
void (*v2)(void); // rax

if ( ptr )
{
v1 = *((_QWORD *)ptr + 4);
if ( v1 || (*((_BYTE *)ptr + 88) & 4) != 0 )
{
*((_QWORD *)ptr + 4) = v1 - 1;
}
else
{
v2 = (void (*)(void))*((_QWORD *)ptr + 12);
if ( v2 )
v2();
p_object_delete(ptr);
}
}
}

original_code:
void f_object_release(struct o_object *object) {
  if (object) {
    if ((object->references == 0) && (!object->s_flags.pooled)) {
      if (object->s_delegate.m_delete)
        object->s_delegate.m_delete(object);
      p_object_delete(object);
    } else
      object->references--;
  }
}


decompiled_code:
__int64 __fastcall p_dictionary_hash_hooker(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 112))();
}

original_code:
extern t_hash_value p_dictionary_hash_hooker(void *key) {
  struct o_object *object = (struct o_object *)key;
  t_hash_value val = object->s_delegate.m_hash(object);
  return val;
}

canonical_original_code:
extern long long p_dictionary_hash_hooker(void *key) {
  struct o_object *object = (struct o_object *)key;
  long long val = object->s_delegate.m_hash(object);
  return val;
}

variable_types:
key
void *

variable_types:
val
long long


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

if ( a1 && a2 )
result = (*(__int64 (**)(void))(a1 + 104))();
else
result = (unsigned int)(a1 - a2);
return result;
}

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

if ( a1 && a2 )
result = (*(__int64 (**)(void))(a1 + 104))();
else
result = (unsigned int)(a1 - a2);
return result;
}

original_code:
extern int p_dictionary_compare_hooker(void *left, void *right) {
  struct o_object *object_left = (struct o_object *)left, *object_right = (struct o_object *)right;
  return (((object_left)&&(object_right))?((struct o_object *)object_left)->s_delegate.m_compare((struct o_object*)(object_left),(struct o_object*)(object_right)):((long long)(object_left))-((long long)(object_right)));
}

canonical_original_code:
extern int p_dictionary_compare_hooker(void *left, void *right) {
  struct o_object *object_left = (struct o_object *)left; struct o_object *object_right = (struct o_object *)right;
  return (((object_left)&&(object_right))?((struct o_object *)object_left)->s_delegate.m_compare((struct o_object *)(object_left),(struct o_object *)(object_right)):((long long)(object_left))-((long long)(object_right)));
}

variable_types:
left
void *

variable_types:
right
void *


decompiled_code:
__int64 __fastcall p_dictionary_get(__int64 a1, __int64 a2)
{
return f_hash_get(*(_QWORD *)(a1 + 160), a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return f_hash_get(*(_QWORD *)(a1 + 160), a2);
}

original_code:
struct o_object *p_dictionary_get(struct o_dictionary *object, struct o_object *key) {
  return (struct o_object *)f_hash_get(object->table, (void *)key);
}

variable_types: struct o_dictionary { struct o_object head; struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *table; int (*m_load)(struct o_dictionary *, struct o_stream { struct o_object head; struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }); void (*m_blocking)(struct o_stream *, int); } *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); } *

variable_types:
key
struct o_object *

user_defined_types: struct o_dictionary { struct o_object head; struct s_hash_table *table; int (*m_load)(struct o_dictionary *, struct o_stream *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); }

user_defined_types: struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket *table; }

user_defined_types: struct s_hash_bucket { long long hash; void *key; enum e_hash_kind kind; }

user_defined_types: struct o_stream { struct o_object head; struct o_string *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek); void (*m_blocking)(struct o_stream *, int); }

user_defined_types: struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); }


decompiled_code:
struct __jmp_buf_tag __fastcall p_dictionary_clone[1](__int64 a1)
{
struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))) v1; // rbp
__int64 v3; // rax
__int64 v4; // r14
unsigned __int64 v5; // r13
__int64 v6; // r12
void (__fastcall *v7)(struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))), __int64, __int64); // r15
__int64 v8; // rax
_BYTE v9[332]; // [rsp-150h] [rbp-188h] BYREF

if ( *(char **)(a1 + 16) == "dictionary" )
{
v1 = (struct __jmp_buf_tag *)p_object_clone();
v1->__saved_mask.__val[11] = 0LL;
f_hash_init(&v1->__saved_mask.__val[11], p_dictionary_compare_hooker, p_dictionary_hash_hooker);
v3 = (*(__int64 (__fastcall **)(__int64))(a1 + 200))(a1);
v4 = v3;
if ( v3 )
{
if ( *(_QWORD *)(v3 + 168) )
{
v5 = 0LL;
do
{
v6 = (*(__int64 (__fastcall **)(__int64, unsigned __int64))(v4 + 208))(v4, v5);
v7 = (void (__fastcall *)(struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))), __int64, __int64))v1->__saved_mask.__val[14];
v8 = f_hash_get(*(_QWORD *)(a1 + 160), v6);
v7(v1, v6, v8);
++v5;
}
while ( *(_QWORD *)(v4 + 168) > v5 );
}
f_object_release(v4);
}
}
else
{
v1 = v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v9, &v_exception_kind, sizeof(v9));
p_exception_fill("object is not an instance of o_dictionary", "o_dictionary.c", "p_dictionary_clone", 146LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return v1;
}

canonical_decompiled_code:
struct __jmp_buf_tag __fastcall func3[1](__int64 a1)
{
struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))) v1; // rbp
__int64 v3; // rax
__int64 v4; // r14
unsigned __int64 v5; // r13
__int64 v6; // r12
void (__fastcall *v7)(struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))), __int64, __int64); // r15
__int64 v8; // rax
_BYTE v9[332]; // [rsp-150h] [rbp-188h] BYREF

if ( *(char **)(a1 + 16) == "dictionary" )
{
v1 = (struct __jmp_buf_tag *)p_object_clone();
v1->__saved_mask.__val[11] = 0LL;
f_hash_init(&v1->__saved_mask.__val[11], p_dictionary_compare_hooker, p_dictionary_hash_hooker);
v3 = (*(__int64 (__fastcall **)(__int64))(a1 + 200))(a1);
v4 = v3;
if ( v3 )
{
if ( *(_QWORD *)(v3 + 168) )
{
v5 = 0LL;
do
{
v6 = (*(__int64 (__fastcall **)(__int64, unsigned __int64))(v4 + 208))(v4, v5);
v7 = (void (__fastcall *)(struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))), __int64, __int64))v1->__saved_mask.__val[14];
v8 = f_hash_get(*(_QWORD *)(a1 + 160), v6);
v7(v1, v6, v8);
++v5;
}
while ( *(_QWORD *)(v4 + 168) > v5 );
}
f_object_release(v4);
}
}
else
{
v1 = v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v9, &v_exception_kind, sizeof(v9));
p_exception_fill("object is not an instance of o_dictionary", "o_dictionary.c", "p_dictionary_clone", 146LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return v1;
}

original_code:
struct o_object *p_dictionary_clone(struct o_object *object) {
  struct o_dictionary *result = ((void *)0), *local_object;
  struct o_array *keys;
  struct o_object *key;
  size_t index;
  if ((local_object = ((struct o_dictionary *)(((object)->kind==v_dictionary_kind)?(object):((void *)0))))) {
    result = (struct o_dictionary *)p_object_clone(object);
    result->table = ((void *)0);
    f_hash_init(&(result->table), p_dictionary_compare_hooker, p_dictionary_hash_hooker);
    if ((keys = local_object->m_keys(local_object))) {
      for (index = 0; index < keys->size; index++) {
        key = keys->m_get(keys, index);
        result->m_insert(result, key, f_hash_get(local_object->table, key));
      }
      f_object_release((struct o_object *)keys);
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_dictionary"),"o_dictionary.c",__FUNCTION__,146); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return (o_object *)result;
}

canonical_original_code:
struct o_object *p_dictionary_clone(struct o_object *object) {
  struct o_dictionary *result = ((void *)0); struct o_dictionary *local_object;
  struct o_array *keys;
  struct o_object *key;
  unsigned long index;
  if ((local_object = ((struct o_dictionary *)(((object)->kind==v_dictionary_kind)?(object):((void *)0))))) {
    result = (struct o_dictionary *)p_object_clone(object);
    result->table = ((void *)0);
    f_hash_init(&(result->table), p_dictionary_compare_hooker, p_dictionary_hash_hooker);
    if ((keys = local_object->m_keys(local_object))) {
      for (index = 0; index < keys->size; index++) {
        key = keys->m_get(keys, index);
        result->m_insert(result, key, f_hash_get(local_object->table, key));
      }
      f_object_release((struct o_object *)keys);
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_dictionary"),"o_dictionary.c",__FUNCTION__,146); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return (struct o_object *)result;
}

variable_types: struct o_dictionary { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *table; int (*m_load)(struct o_dictionary *, struct o_stream { struct o_object head; struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }); void (*m_blocking)(struct o_stream *, int); } *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); } *

variable_types: struct o_array { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *

variable_types:
index
unsigned long


original_code:
int p_dictionary_save(struct o_dictionary *object, struct o_stream *stream) {
  struct o_string *buffer = f_string_new(((void *)0), 512, ((void *)0)), *current_string;
  struct s_hash_bucket *singleton;
  size_t index = 0, elements = (object->table->mask+1);
  int result = 1;
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      if ((current_string = f_string_new(buffer, 512, "%s=%s\n", singleton->key, singleton->value))) {
        if (stream->m_write_string(stream, current_string) == 0)
          result = 0;
        buffer = current_string;
        if (!result)
          break;
      }
  }
  if (buffer)
    do{ p_memory_remove((buffer),"o_dictionary.c",__FUNCTION__,188,0); free(buffer); }while(0);
  return result;
}

canonical_original_code:
int p_dictionary_save(struct o_dictionary *object, struct o_stream *stream) {
  struct o_string *buffer = f_string_new(((void *)0), 512, ((void *)0)); struct o_string *current_string;
  struct s_hash_bucket *singleton;
  unsigned long index = 0; unsigned long elements = (object->table->mask+1);
  int result = 1;
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      if ((current_string = f_string_new(buffer, 512, "%s=%s\n", singleton->key, singleton->value))) {
        if (stream->m_write_string(stream, current_string) == 0)
          result = 0;
        buffer = current_string;
        if (!result)
          break;
      }
  }
  if (buffer)
    do{ p_memory_remove((buffer),"o_dictionary.c",__FUNCTION__,188,0); free(buffer); }while(0);
  return result;
}

variable_types:
stream
struct o_stream *

variable_types: struct o_string { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *

variable_types: struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *

variable_types:
elements
unsigned long

variable_types: result int

user_defined_types: enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }


decompiled_code:
__int64 __fastcall p_dictionary_insert(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp
__int64 v4; // rax
unsigned int v5; // ebp
__int64 v7[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+10h] [rbp-28h]
__int64 v9; // [rsp+18h] [rbp-20h]

v7[0] = 0LL;
v7[1] = 0LL;
v8 = 0LL;
v9 = 0LL;
v3 = f_object_retain(a3);
v4 = f_object_retain(a2);
v5 = f_hash_insert(*(_QWORD *)(a1 + 160), v4, v3, s_true, v7);
if ( v8 )
{
f_object_release(a2);
f_object_release(v8);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp
__int64 v4; // rax
unsigned int v5; // ebp
__int64 v7[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+10h] [rbp-28h]
__int64 v9; // [rsp+18h] [rbp-20h]

v7[0] = 0LL;
v7[1] = 0LL;
v8 = 0LL;
v9 = 0LL;
v3 = f_object_retain(a3);
v4 = f_object_retain(a2);
v5 = f_hash_insert(*(_QWORD *)(a1 + 160), v4, v3, s_true, v7);
if ( v8 )
{
f_object_release(a2);
f_object_release(v8);
}
return v5;
}

original_code:
int p_dictionary_insert(struct o_dictionary *object, struct o_object *key, struct o_object *value) {
  struct s_hash_bucket replaced = {0};
  int result = f_hash_insert(object->table, (void*)f_object_retain((struct o_object *)key), (void*)f_object_retain((struct o_object *)value), s_true, &replaced);
  if (replaced.value) {
    f_object_release((struct o_object *)key);
    f_object_release((struct o_object *)(struct o_object *)replaced.value);
  }
  return result;
}

variable_types:
value
struct o_object *

variable_types: struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; }

user_defined_types: struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); }


original_code:
int p_dictionary_load(struct o_dictionary *object, struct o_stream *stream) {
  struct o_string *singleton, *buffer = ((void *)0);
  struct o_array *values;
  int result = 1;
  while ((singleton = stream->m_read_line(stream, buffer, 512))) {
    buffer = singleton;
    if (buffer->m_length(buffer) > 0)
      if ((values = singleton->m_split(buffer, '='))) {
        if (values->filled >= 2)
          p_dictionary_insert(object, values->m_get(values, 0), values->m_get(values, 1));
        else
          result = 0;
        f_object_release((struct o_object *)values);
        if (!result)
          break;
      }
  }
  f_object_release((struct o_object *)buffer);
  return result;
}

canonical_original_code:
int p_dictionary_load(struct o_dictionary *object, struct o_stream *stream) {
  struct o_string *singleton; struct o_string *buffer = ((void *)0);
  struct o_array *values;
  int result = 1;
  while ((singleton = stream->m_read_line(stream, buffer, 512))) {
    buffer = singleton;
    if (buffer->m_length(buffer) > 0)
      if ((values = singleton->m_split(buffer, '='))) {
        if (values->filled >= 2)
          p_dictionary_insert(object, values->m_get(values, 0), values->m_get(values, 1));
        else
          result = 0;
        f_object_release((struct o_object *)values);
        if (!result)
          break;
      }
  }
  f_object_release((struct o_object *)buffer);
  return result;
}

user_defined_types: enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 }


original_code:
struct o_array *p_dictionary_keys(struct o_dictionary *object) {
  struct o_array *result = f_array_new(((void *)0), object->table->fill);
  struct s_hash_bucket *singleton;
  size_t index = 0, position = 0, elements = (object->table->mask+1);
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      result->m_insert(result, singleton->key, position++);
  }
  return result;
}

canonical_original_code:
struct o_array *p_dictionary_keys(struct o_dictionary *object) {
  struct o_array *result = f_array_new(((void *)0), object->table->fill);
  struct s_hash_bucket *singleton;
  unsigned long index = 0; unsigned long position = 0; unsigned long elements = (object->table->mask+1);
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      result->m_insert(result, singleton->key, position++);
  }
  return result;
}

variable_types: struct o_dictionary { struct o_object head; struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *table; int (*m_load)(struct o_dictionary *, struct o_stream { struct o_object head; struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }); void (*m_blocking)(struct o_stream *, int); } *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); } *

variable_types:
position
unsigned long

return_type: struct o_array { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *


original_code:
struct o_array *p_dictionary_values(struct o_dictionary *object) {
  struct o_array *result = f_array_new(((void *)0), object->table->fill);
  struct s_hash_bucket *singleton;
  size_t index = 0, position = 0, elements = (object->table->mask+1);
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      result->m_insert(result, singleton->value, position++);
  }
  return result;
}

canonical_original_code:
struct o_array *p_dictionary_values(struct o_dictionary *object) {
  struct o_array *result = f_array_new(((void *)0), object->table->fill);
  struct s_hash_bucket *singleton;
  unsigned long index = 0; unsigned long position = 0; unsigned long elements = (object->table->mask+1);
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      result->m_insert(result, singleton->value, position++);
  }
  return result;
}


decompiled_code:
const char *__fastcall p_pool_delete(__int64 a1)
{
const char *result; // rax
_BYTE v2[332]; // [rsp-150h] [rbp-158h] BYREF

result = "pool";
if ( *(char **)(a1 + 16) == "pool" )
{
if ( *(_QWORD *)(a1 + 160) )
result = (const char *)f_list_destroy(a1 + 160);
}
else
{
result = (const char *)&v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v2, &v_exception_kind, sizeof(v2));
p_exception_fill("object is not an instance of o_pool", "o_pool.c", "p_pool_delete", 46LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 a1)
{
const char *result; // rax
_BYTE v2[332]; // [rsp-150h] [rbp-158h] BYREF

result = "pool";
if ( *(char **)(a1 + 16) == "pool" )
{
if ( *(_QWORD *)(a1 + 160) )
result = (const char *)f_list_destroy(a1 + 160);
}
else
{
result = (const char *)&v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v2, &v_exception_kind, sizeof(v2));
p_exception_fill("object is not an instance of o_pool", "o_pool.c", "p_pool_delete", 46LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return result;
}

original_code:
void p_pool_delete(struct o_object *object) {
  struct o_pool *local_object;
  if ((local_object = ((struct o_pool *)(((object)->kind==v_pool_kind)?(object):((void *)0))))) {
    if (local_object->pool)
      f_list_destroy(&(local_object->pool));
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_pool"),"o_pool.c",__FUNCTION__,46); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
}

variable_types: struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } *

variable_types: struct o_pool { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct s_list { struct s_list_node *head; unsigned long fill; } *pool; struct o_object *(*m_insert)(struct o_pool *, struct o_object *); void (*m_clean)(struct o_pool *, int); } *

user_defined_types: struct o_pool { struct o_object head; struct s_list *pool; struct o_object *(*m_insert)(struct o_pool *, struct o_object *); void (*m_clean)(struct o_pool *, int); }


decompiled_code:
struct __jmp_buf_tag __fastcall p_pool_clone[1](__int64 a1)
{
struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))) v1; // rbp
__int64 v3; // rax
__int64 v4; // rax
_BYTE v5[332]; // [rsp-150h] [rbp-168h] BYREF

if ( *(char **)(a1 + 16) == "pool" )
{
v3 = p_object_clone();
v1 = (struct __jmp_buf_tag *)v3;
if ( *(_QWORD *)(a1 + 160) )
{
f_list_init(v3 + 160);
for ( *(_QWORD *)(*(_QWORD *)(a1 + 160) + 16LL) = **(_QWORD **)(a1 + 160);
*(_QWORD *)(*(_QWORD *)(a1 + 160) + 16LL);
*(_QWORD *)(*(_QWORD *)(a1 + 160) + 16LL) = **(_QWORD **)(*(_QWORD *)(a1 + 160) + 16LL) )
{
v4 = f_object_retain();
f_list_append(v1->__saved_mask.__val[11], v4, 0LL);
}
}
}
else
{
v1 = v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v5, &v_exception_kind, sizeof(v5));
p_exception_fill("object is not an instance of o_pool", "o_pool.c", "p_pool_clone", 92LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return v1;
}

canonical_decompiled_code:
struct __jmp_buf_tag __fastcall func1[1](__int64 a1)
{
struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))) v1; // rbp
__int64 v3; // rax
__int64 v4; // rax
_BYTE v5[332]; // [rsp-150h] [rbp-168h] BYREF

if ( *(char **)(a1 + 16) == "pool" )
{
v3 = p_object_clone();
v1 = (struct __jmp_buf_tag *)v3;
if ( *(_QWORD *)(a1 + 160) )
{
f_list_init(v3 + 160);
for ( *(_QWORD *)(*(_QWORD *)(a1 + 160) + 16LL) = **(_QWORD **)(a1 + 160);
*(_QWORD *)(*(_QWORD *)(a1 + 160) + 16LL);
*(_QWORD *)(*(_QWORD *)(a1 + 160) + 16LL) = **(_QWORD **)(*(_QWORD *)(a1 + 160) + 16LL) )
{
v4 = f_object_retain();
f_list_append(v1->__saved_mask.__val[11], v4, 0LL);
}
}
}
else
{
v1 = v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v5, &v_exception_kind, sizeof(v5));
p_exception_fill("object is not an instance of o_pool", "o_pool.c", "p_pool_clone", 92LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return v1;
}

original_code:
struct o_object *p_pool_clone(struct o_object *object) {
  struct o_pool *result = ((void *)0), *local_object;
  struct o_object *value;
  if ((local_object = ((struct o_pool *)(((object)->kind==v_pool_kind)?(object):((void *)0))))) {
    result = (struct o_pool *)p_object_clone(object);
    if (local_object->pool) {
      f_list_init(&result->pool);
      for((local_object->pool)->current=(local_object->pool)->head;(((value)=(struct o_object *)(local_object->pool)->current));(local_object->pool)->current=(local_object->pool)->current->next)
        f_list_append(result->pool, (struct s_list_node *)(struct o_object*)f_object_retain((struct o_object *)value), e_list_insert_head);
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_pool"),"o_pool.c",__FUNCTION__,92); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return (struct o_object *)result;
}

canonical_original_code:
struct o_object *p_pool_clone(struct o_object *object) {
  struct o_pool *result = ((void *)0); struct o_pool *local_object;
  struct o_object *value;
  if ((local_object = ((struct o_pool *)(((object)->kind==v_pool_kind)?(object):((void *)0))))) {
    result = (struct o_pool *)p_object_clone(object);
    if (local_object->pool) {
      f_list_init(&result->pool);
      for((local_object->pool)->current=(local_object->pool)->head;(((value)=(struct o_object *)(local_object->pool)->current));(local_object->pool)->current=(local_object->pool)->current->next)
        f_list_append(result->pool, (struct s_list_node *)(struct o_object *)f_object_retain((struct o_object *)value), e_list_insert_head);
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_pool"),"o_pool.c",__FUNCTION__,92); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return (struct o_object *)result;
}

variable_types:
object
struct o_object *

user_defined_types: struct s_list { struct s_list_node *head; unsigned long fill; }


original_code:
struct o_object *p_pool_insert(struct o_pool *object, struct o_object *value) {
  if (object->pool) {
    f_list_append(object->pool, (struct s_list_node *)value, e_list_insert_head);
    value->s_flags.pooled = 1;
  }
  return value;
}

variable_types: struct o_pool { struct o_object head; struct s_list { struct s_list_node *head; unsigned long fill; } *pool; struct o_object *(*m_insert)(struct o_pool *, struct o_object *); void (*m_clean)(struct o_pool *, int); } *


decompiled_code:
const char *__fastcall f_string_append(const char **a1, const char *a2, unsigned __int64 *a3)
{
const char *v3; // r14
size_t v4; // rbx
size_t v5; // rbp
unsigned __int64 v6; // r15
void *v7; // rax
__int64 v8; // rax

v3 = *a1;
v4 = 0LL;
if ( *a1 )
v4 = strlen(*a1);
v5 = 0LL;
if ( a2 )
v5 = strlen(a2);
v6 = v4 + v5 + 1;
if ( *a3 <= v6 )
{
p_memory_remove(v3, "string.local.c", "f_string_append", 22LL, 1LL);
v7 = realloc((void *)*a1, v4 + v5 + 1);
v8 = p_memory_insert(v7, "string.local.c", "f_string_append", 22LL, 1LL);
*a1 = (const char *)v8;
if ( !v8 )
{
p_log_write(stderr, 0LL, "string.local.c", "f_string_append", 25LL, "out of memory! I'm dying: 'bleaaargh'");
exit(1);
}
*a3 = v6;
}
memcpy((void *)&(*a1)[v4], a2, v5 + 1);
return *a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char **a1, const char *a2, unsigned __int64 *a3)
{
const char *v3; // r14
size_t v4; // rbx
size_t v5; // rbp
unsigned __int64 v6; // r15
void *v7; // rax
__int64 v8; // rax

v3 = *a1;
v4 = 0LL;
if ( *a1 )
v4 = strlen(*a1);
v5 = 0LL;
if ( a2 )
v5 = strlen(a2);
v6 = v4 + v5 + 1;
if ( *a3 <= v6 )
{
p_memory_remove(v3, "string.local.c", "f_string_append", 22LL, 1LL);
v7 = realloc((void *)*a1, v4 + v5 + 1);
v8 = p_memory_insert(v7, "string.local.c", "f_string_append", 22LL, 1LL);
*a1 = (const char *)v8;
if ( !v8 )
{
p_log_write(stderr, 0LL, "string.local.c", "f_string_append", 25LL, "out of memory! I'm dying: 'bleaaargh'");
exit(1);
}
*a3 = v6;
}
memcpy((void *)&(*a1)[v4], a2, v5 + 1);
return *a1;
}

original_code:
char *f_string_append(char **string, char *suffix, size_t *space) {
  size_t size_string = ((*string)?strlen(*string):0), size_element = ((suffix)?strlen(suffix):0), total;
  if ((total = size_string+size_element+1) >= *space) {
    if ((*string = (char *) (p_memory_remove((*string),"string.local.c",__FUNCTION__,22,1), p_memory_insert(realloc((*string),(total)),"string.local.c",__FUNCTION__,22,1))))
      *space = total;
    else
      do{ p_log_write(stderr,e_log_level_ever,"string.local.c",__FUNCTION__,25,"out of memory! I'm dying: 'bleaaargh'"); exit(1); }while(0);;
  }
  memcpy((*string)+size_string, suffix, size_element+1);
  return *string;
}

canonical_original_code:
char *f_string_append(char **string, char *suffix, unsigned long *space) {
  unsigned long size_string = ((*string)?strlen(*string):0); unsigned long size_element = ((suffix)?strlen(suffix):0); unsigned long total;
  if ((total = size_string+size_element+1) >= *space) {
    if ((*string = (char *) (p_memory_remove((*string),"string.local.c",__FUNCTION__,22,1), p_memory_insert(realloc((*string),(total)),"string.local.c",__FUNCTION__,22,1))))
      *space = total;
    else
      do{ p_log_write(stderr,e_log_level_ever,"string.local.c",__FUNCTION__,25,"out of memory! I'm dying: 'bleaaargh'"); exit(1); }while(0);;
  }
  memcpy((*string)+size_string, suffix, size_element+1);
  return *string;
}

variable_types:
string
char **

variable_types:
suffix
char *

variable_types:
space
unsigned long *

variable_types:
total
unsigned long


decompiled_code:
void *__fastcall f_string_trim(void *src)
{
size_t v1; // rax
const char *v2; // rax
const char *v3; // rbx
size_t v4; // rax
char v6; // dl

v1 = 0LL;
if ( src )
v1 = strlen((const char *)src);
v2 = (char *)src + v1 - 1;
v3 = (const char *)src;
while ( 1 )
{
while ( *v3 == 32 || *v3 == 9 )
{
if ( v3 > v2 )
goto LABEL_4;
++v3;
v6 = *v2;
if ( (unsigned __int8)(*v2 - 9) > 1u )
goto LABEL_9;
LABEL_12:
*v2-- = 0;
}
if ( (unsigned __int8)(*v2 - 9) <= 1u )
{
if ( v3 > v2 )
break;
goto LABEL_12;
}
if ( (*v2 & 0xDF) != 0 || v3 > v2 )
break;
v6 = *v2;
LABEL_9:
if ( (v6 & 0xDF) == 0 )
goto LABEL_12;
}
LABEL_4:
if ( v3 > src )
{
v4 = strlen(v3);
memmove(src, v3, v4 + 1);
}
return src;
}

canonical_decompiled_code:
void *__fastcall func1(void *src)
{
size_t v1; // rax
const char *v2; // rax
const char *v3; // rbx
size_t v4; // rax
char v6; // dl

v1 = 0LL;
if ( src )
v1 = strlen((const char *)src);
v2 = (char *)src + v1 - 1;
v3 = (const char *)src;
while ( 1 )
{
while ( *v3 == 32 || *v3 == 9 )
{
if ( v3 > v2 )
goto LABEL_4;
++v3;
v6 = *v2;
if ( (unsigned __int8)(*v2 - 9) > 1u )
goto LABEL_9;
LABEL_12:
*v2-- = 0;
}
if ( (unsigned __int8)(*v2 - 9) <= 1u )
{
if ( v3 > v2 )
break;
goto LABEL_12;
}
if ( (*v2 & 0xDF) != 0 || v3 > v2 )
break;
v6 = *v2;
LABEL_9:
if ( (v6 & 0xDF) == 0 )
goto LABEL_12;
}
LABEL_4:
if ( v3 > src )
{
v4 = strlen(v3);
memmove(src, v3, v4 + 1);
}
return src;
}

original_code:
char *f_string_trim(char *string) {
  size_t length = ((string)?strlen(string):0);
  char *begin = string, *final = (string+length)-1;
  while (((((*begin)==' ')||((*begin)=='\t')) || ((((*final)==' ')||((*final)=='\t'))) || ((((*final)=='\0')||((*final)=='\n')))) && (final >= begin)) {
    if ((((*begin)==' ')||((*begin)=='\t')))
      begin++;
    if (((((*final)==' ')||((*final)=='\t'))) || ((((*final)=='\0')||((*final)=='\n')))) {
      *final = '\0';
      final--;
    }
  }
  if (begin > string)
    memmove(string, begin, ((begin)?strlen(begin):0)+1);
  return string;
}

canonical_original_code:
char *f_string_trim(char *string) {
  unsigned long length = ((string)?strlen(string):0);
  char *begin = string; char *final = (string+length)-1;
  while (((((*begin)==' ')||((*begin)=='\t')) || ((((*final)==' ')||((*final)=='\t'))) || ((((*final)=='\0')||((*final)=='\n')))) && (final >= begin)) {
    if ((((*begin)==' ')||((*begin)=='\t')))
      begin++;
    if (((((*final)==' ')||((*final)=='\t'))) || ((((*final)=='\0')||((*final)=='\n')))) {
      *final = '\0';
      final--;
    }
  }
  if (begin > string)
    memmove(string, begin, ((begin)?strlen(begin):0)+1);
  return string;
}

variable_types:
string
char *

variable_types:
length
unsigned long

variable_types:
begin
char *

variable_types:
final
char *


decompiled_code:
char *f_string_format(char *s, size_t a2, char *a3, __int64 a4, const char *a5, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a5);
f_string_format_args(s, a2, a3, a4, a5, (unsigned int *)va);
return s;
}

canonical_decompiled_code:
char *func4(char *s, size_t a2, char *a3, __int64 a4, const char *a5, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a5);
func3(s, a2, a3, a4, a5, (unsigned int *)va);
return s;
}

original_code:
char *f_string_format(char *buffer, size_t size, char *symbols, t_string_formatter functions[], char *format, ...) {
  va_list parameters;
  __builtin_va_start(parameters,format);
  f_string_format_args(buffer, size, symbols, functions, format, parameters);
  __builtin_va_end(parameters);
  return buffer;
}

canonical_original_code:
char *f_string_format(char *buffer, unsigned long size, char *symbols, char *(*functions[])(char *, unsigned long, char *, __builtin_va_list), char *format, ...) {
  __builtin_va_list parameters;
  __builtin_va_start(parameters,format);
  f_string_format_args(buffer, size, symbols, functions, format, parameters);
  __builtin_va_end(parameters);
  return buffer;
}

variable_types:
buffer
char *

variable_types:
size
unsigned long

variable_types:
symbols
char *

variable_types: char *(*[])(char *, unsigned long, char *, __builtin_va_list)

variable_types:
format
char *


original_code:
struct s_hash_bucket *p_hash_lookup(struct s_hash_table *table, void *key, t_hash_value hash) {
  t_hash_value index = hash&table->mask, shift = hash;
  struct s_hash_bucket *item, *backup = ((void *)0);
  while (1) {
    item = &table->table[index&table->mask];
    if (item->key == key)
      break;
    else if (item->kind == e_hash_kind_deleted)
      backup = item;
    else if (item->kind == e_hash_kind_empty) {
      if (backup)
        item = backup;
      break;
    } else if ((item->hash == hash) && (table->compare(item->key, key) == 0))
      break;
    index = ((index<<2)+index+shift)+1;
    shift >>= 5;
  }
  return item;
}

canonical_original_code:
struct s_hash_bucket *p_hash_lookup(struct s_hash_table *table, void *key, long long hash) {
  long long index = hash&table->mask; long long shift = hash;
  struct s_hash_bucket *item; struct s_hash_bucket *backup = ((void *)0);
  while (1) {
    item = &table->table[index&table->mask];
    if (item->key == key)
      break;
    else if (item->kind == e_hash_kind_deleted)
      backup = item;
    else if (item->kind == e_hash_kind_empty) {
      if (backup)
        item = backup;
      break;
    } else if ((item->hash == hash) && (table->compare(item->key, key) == 0))
      break;
    index = ((index<<2)+index+shift)+1;
    shift >>= 5;
  }
  return item;
}

variable_types: struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket *table; } *

variable_types:
key
void *

variable_types:
hash
long long

variable_types:
index
long long

variable_types:
shift
long long

variable_types: struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *


decompiled_code:
void __fastcall f_hash_destroy(void **a1)
{
p_memory_remove(*((_QWORD *)*a1 + 4), "hash.c", "f_hash_destroy", 75LL, 0LL);
free(*((void **)*a1 + 4));
p_memory_remove(*a1, "hash.c", "f_hash_destroy", 76LL, 0LL);
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(void **a1)
{
p_memory_remove(*((_QWORD *)*a1 + 4), "hash.c", "f_hash_destroy", 75LL, 0LL);
free(*((void **)*a1 + 4));
p_memory_remove(*a1, "hash.c", "f_hash_destroy", 76LL, 0LL);
free(*a1);
*a1 = 0LL;
}

original_code:
void f_hash_destroy(struct s_hash_table **table) {
  do{ p_memory_remove(((*table)->table),"hash.c",__FUNCTION__,75,0); free((*table)->table); }while(0);
  do{ p_memory_remove(((*table)),"hash.c",__FUNCTION__,76,0); free((*table)); }while(0);
  *table = ((void *)0);
}

variable_types: struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } **


original_code:
int f_hash_insert(struct s_hash_table *table, void *key, void *value, struct s_bool update, struct s_hash_bucket *current) {
  t_hash_value hash = table->calculate(key);
  struct s_hash_bucket *item = p_hash_lookup(table, key, hash);
  int result = 0;
  if (!item->value) {
    if (item->kind == e_hash_kind_empty)
      table->fill++;
    item->hash = hash;
    item->key = key;
    item->value = value;
  } else {
    result = 1;
    if (current)
      memcpy(current, item, sizeof(struct s_hash_bucket));
    if (((update).flag))
      item->value = value;
  }
  item->kind = e_hash_kind_fill;
  if (((table->fill)*3) > ((table->mask+1)*2))
    p_hash_resize(table, ((table->mask+1)*2));
  return result;
}

canonical_original_code:
int f_hash_insert(struct s_hash_table *table, void *key, void *value, struct s_bool update, struct s_hash_bucket *current) {
  long long hash = table->calculate(key);
  struct s_hash_bucket *item = p_hash_lookup(table, key, hash);
  int result = 0;
  if (!item->value) {
    if (item->kind == e_hash_kind_empty)
      table->fill++;
    item->hash = hash;
    item->key = key;
    item->value = value;
  } else {
    result = 1;
    if (current)
      memcpy(current, item, sizeof(struct s_hash_bucket));
    if (((update).flag))
      item->value = value;
  }
  item->kind = e_hash_kind_fill;
  if (((table->fill)*3) > ((table->mask+1)*2))
    p_hash_resize(table, ((table->mask+1)*2));
  return result;
}

variable_types: struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *

variable_types:
value
void *

variable_types:
update
struct s_bool { unsigned int flag; }

variable_types:
current
struct s_hash_bucket *

variable_types: result int


original_code:
void p_hash_resize(struct s_hash_table *table, t_hash_value dimension) {
  struct s_hash_bucket *current = table->table, *item;
  t_hash_value elements = table->mask;
  p_hash_allocate(table, dimension);
  for (; elements >= 0; elements--) {
    item = &current[elements];
    if (item->kind == e_hash_kind_fill)
      f_hash_insert(table, item->key, item->value, s_true, ((void *)0));
  }
  do{ p_memory_remove((current),"hash.c",__FUNCTION__,41,0); free(current); }while(0);
}

canonical_original_code:
void p_hash_resize(struct s_hash_table *table, long long dimension) {
  struct s_hash_bucket *current = table->table; struct s_hash_bucket *item;
  long long elements = table->mask;
  p_hash_allocate(table, dimension);
  for (; elements >= 0; elements--) {
    item = &current[elements];
    if (item->kind == e_hash_kind_fill)
      f_hash_insert(table, item->key, item->value, s_true, ((void *)0));
  }
  do{ p_memory_remove((current),"hash.c",__FUNCTION__,41,0); free(current); }while(0);
}

variable_types:
dimension
long long

variable_types:
elements
long long


original_code:
void *f_hash_get(struct s_hash_table *table, void *key) {
  t_hash_value hash = table->calculate(key);
  return p_hash_lookup(table, key, hash)->value;
}

canonical_original_code:
void *f_hash_get(struct s_hash_table *table, void *key) {
  long long hash = table->calculate(key);
  return p_hash_lookup(table, key, hash)->value;
}

return_type: void *


original_code:
int f_hash_delete(struct s_hash_table *table, void *key, struct s_hash_bucket *current) {
  t_hash_value hash = table->calculate(key);
  s_hash_bucket *item = p_hash_lookup(table, key, hash);
  int result = 0;
  if (item->kind == e_hash_kind_fill) {
    result = 1;
    if (current)
      memcpy(current, item, sizeof(struct s_hash_bucket));
    item->value = ((void *)0);
    item->kind = e_hash_kind_deleted;
    table->fill--;
  }
  return result;
}

canonical_original_code:
int f_hash_delete(struct s_hash_table *table, void *key, struct s_hash_bucket *current) {
  long long hash = table->calculate(key);
  struct s_hash_bucket *item = p_hash_lookup(table, key, hash);
  int result = 0;
  if (item->kind == e_hash_kind_fill) {
    result = 1;
    if (current)
      memcpy(current, item, sizeof(struct s_hash_bucket));
    item->value = ((void *)0);
    item->kind = e_hash_kind_deleted;
    table->fill--;
  }
  return result;
}


decompiled_code:
__int64 __fastcall p_filesystem_insert(__int64 a1)
{
return (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 160) + 184LL))(*(_QWORD *)(a1 + 160));
}

original_code:
int p_filesystem_insert(struct o_filesystem *object, struct o_string *name, struct o_stream *stream) {
  return object->files->m_insert(object->files, (struct o_object *)name, (struct o_object *)stream);
}

variable_types: struct o_filesystem { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct o_dictionary { struct o_object head; struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *table; int (*m_load)(struct o_dictionary *, struct o_stream { struct o_object head; struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }); void (*m_blocking)(struct o_stream *, int); } *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); } *files; int (*m_insert)(struct o_filesystem *, struct o_string *, struct o_stream *); struct o_stream *(*m_get)(struct o_filesystem *, struct o_string *); void (*m_store)(struct o_filesystem *, struct o_stream *); } *

variable_types:
name
struct o_string *

variable_types:
stream
struct o_stream *

user_defined_types: struct o_filesystem { struct o_object head; struct o_dictionary *files; int (*m_insert)(struct o_filesystem *, struct o_string *, struct o_stream *); struct o_stream *(*m_get)(struct o_filesystem *, struct o_string *); void (*m_store)(struct o_filesystem *, struct o_stream *); }


original_code:
struct o_stream *p_filesystem_get(struct o_filesystem *object, struct o_string *name) {
  return (struct o_stream *)object->files->m_get(object->files, (struct o_object *)name);
}

variable_types: struct o_filesystem { struct o_object head; struct o_dictionary { struct o_object head; struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *table; int (*m_load)(struct o_dictionary *, struct o_stream *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); } *files; int (*m_insert)(struct o_filesystem *, struct o_string *, struct o_stream *); struct o_stream *(*m_get)(struct o_filesystem *, struct o_string *); void (*m_store)(struct o_filesystem *, struct o_stream *); } *

return_type: struct o_stream { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }); void (*m_blocking)(struct o_stream *, int); } *


decompiled_code:
char *__fastcall p_filesystem_string(__int64 a1, char *a2, size_t a3)
{
char *v3; // rbx
size_t v6; // r13
char *v7; // rax
_BYTE v8[332]; // [rsp-150h] [rbp-178h] BYREF

v3 = a2;
if ( *(char **)(a1 + 16) == "filesystem" )
{
v6 = snprintf(a2, a3, "<filesystem: ");
if ( a3 <= v6 )
v6 = a3;
v3 = &a2[v6];
if ( a3 > v6 )
{
v7 = (char *)(*(__int64 (__fastcall **)(_QWORD, char *, size_t))(*(_QWORD *)(a1 + 160) + 120LL))(
*(_QWORD *)(a1 + 160),
v3,
a3 - v6);
v3 = v7;
if ( a3 > v7 - a2 )
{
*v7 = 62;
v3 = v7 + 1;
}
}
}
else if ( v_exception_hook )
{
qmemcpy(v8, &v_exception_kind, sizeof(v8));
p_exception_fill("object is not an instance of o_filesystem", "o_filesystem.c", "p_filesystem_string", 103LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, char *a2, size_t a3)
{
char *v3; // rbx
size_t v6; // r13
char *v7; // rax
_BYTE v8[332]; // [rsp-150h] [rbp-178h] BYREF

v3 = a2;
if ( *(char **)(a1 + 16) == "filesystem" )
{
v6 = snprintf(a2, a3, "<filesystem: ");
if ( a3 <= v6 )
v6 = a3;
v3 = &a2[v6];
if ( a3 > v6 )
{
v7 = (char *)(*(__int64 (__fastcall **)(_QWORD, char *, size_t))(*(_QWORD *)(a1 + 160) + 120LL))(
*(_QWORD *)(a1 + 160),
v3,
a3 - v6);
v3 = v7;
if ( a3 > v7 - a2 )
{
*v7 = 62;
v3 = v7 + 1;
}
}
}
else if ( v_exception_hook )
{
qmemcpy(v8, &v_exception_kind, sizeof(v8));
p_exception_fill("object is not an instance of o_filesystem", "o_filesystem.c", "p_filesystem_string", 103LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
return v3;
}

original_code:
char *p_filesystem_string(struct o_object *object, char *data, size_t size) {
  struct o_filesystem *local_object;
  size_t written;
  char *next;
  if ((local_object = ((struct o_filesystem *)(((object)->kind==v_filesystem_kind)?(object):((void *)0))))) {
    written = snprintf(data, size, "<filesystem: ");
    written = ((written>size)?size:written);
    data += written;
    if (written < size) {
      next = local_object->files->head.s_delegate.m_string((struct o_object *)local_object->files, data, (size-written));
      written += (next-data);
      data = next;
      if (written < size) {
        *data = '>';
        data++;
      }
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_filesystem"),"o_filesystem.c",__FUNCTION__,103); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return data;
}

canonical_original_code:
char *p_filesystem_string(struct o_object *object, char *data, unsigned long size) {
  struct o_filesystem *local_object;
  unsigned long written;
  char *next;
  if ((local_object = ((struct o_filesystem *)(((object)->kind==v_filesystem_kind)?(object):((void *)0))))) {
    written = snprintf(data, size, "<filesystem: ");
    written = ((written>size)?size:written);
    data += written;
    if (written < size) {
      next = local_object->files->head.s_delegate.m_string((struct o_object *)local_object->files, data, (size-written));
      written += (next-data);
      data = next;
      if (written < size) {
        *data = '>';
        data++;
      }
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_filesystem"),"o_filesystem.c",__FUNCTION__,103); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return data;
}

variable_types: struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } *

variable_types:
data
char *

variable_types:
size
unsigned long

variable_types:
written
unsigned long

variable_types:
next
char *