RenderLines

decompiled_code:
void RenderLines()
{
__int64 i; // rbx
__int64 v1; // rsi
__int64 v2; // rsi
__int64 v3; // rax

for ( i = 0LL; i != 0x2000; i += 64LL )
{
while ( *(int *)((char *)&vline + i) <= 0 )
{
i += 64LL;
if ( i == 0x2000 )
return;
}
v1 = *(unsigned int *)((char *)&vline + i + 12);
zlvertex = 0;
zlpoint(*(unsigned int *)((char *)&vline + i + 8), v1);
v2 = *(unsigned int *)((char *)&vline + i + 24);
zlvertex = 1;
zlpoint(*(unsigned int *)((char *)&vline + i + 20), v2);
if ( vbufferz > 0 && *((int *)&vbufferz + 1) > 0 && vvis && *((_DWORD *)&vvis + 1) )
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], *(unsigned int *)((char *)&vline + i + 4));
v3 = i;
do
{
*(_DWORD *)((char *)&vline + v3 + 8) += *(_DWORD *)((char *)&vline + v3 + 32);
v3 += 4LL;
}
while ( v3 != i + 24 );
--*(_DWORD *)((char *)&vline + i);
}
}

canonical_decompiled_code:
void func1()
{
__int64 i; // rbx
__int64 v1; // rsi
__int64 v2; // rsi
__int64 v3; // rax

for ( i = 0LL; i != 0x2000; i += 64LL )
{
while ( *(int *)((char *)&vline + i) <= 0 )
{
i += 64LL;
if ( i == 0x2000 )
return;
}
v1 = *(unsigned int *)((char *)&vline + i + 12);
zlvertex = 0;
zlpoint(*(unsigned int *)((char *)&vline + i + 8), v1);
v2 = *(unsigned int *)((char *)&vline + i + 24);
zlvertex = 1;
zlpoint(*(unsigned int *)((char *)&vline + i + 20), v2);
if ( vbufferz > 0 && *((int *)&vbufferz + 1) > 0 && vvis && *((_DWORD *)&vvis + 1) )
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], *(unsigned int *)((char *)&vline + i + 4));
v3 = i;
do
{
*(_DWORD *)((char *)&vline + v3 + 8) += *(_DWORD *)((char *)&vline + v3 + 32);
v3 += 4LL;
}
while ( v3 != i + 24 );
--*(_DWORD *)((char *)&vline + i);
}
}

original_code:
void RenderLines(void) {
 Uint8 i, k;
 for (i = 0; i < 128; i++)
  if (vline[i][0] > 0) {
   zlvertex = 0;
   zlpoint(vline[i][2], vline[i][3], -vline[i][4]);
   zlvertex = 1;
   zlpoint(vline[i][5], vline[i][6], -vline[i][7]);
   if (vbufferz[0] > 0)
    if (vbufferz[1] > 0)
     if (vvis[0])
      if (vvis[1])
       DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1],
         vbuffery[1], vline[i][1]);
   for (k = 2; k < 8; k++)
    vline[i][k] += vline[i][k + 6];
   vline[i][0]--;
  }
}

canonical_original_code:
void RenderLines() {
 unsigned char i; unsigned char k;
 for (i = 0; i < 128; i++)
  if (vline[i][0] > 0) {
   zlvertex = 0;
   zlpoint(vline[i][2], vline[i][3], -vline[i][4]);
   zlvertex = 1;
   zlpoint(vline[i][5], vline[i][6], -vline[i][7]);
   if (vbufferz[0] > 0)
    if (vbufferz[1] > 0)
     if (vvis[0])
      if (vvis[1])
       DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1],
         vbuffery[1], vline[i][1]);
   for (k = 2; k < 8; k++)
    vline[i][k] += vline[i][k + 6];
   vline[i][0]--;
  }
}

variable_types:
k
unsigned char


RenderObjects

repo: JohnnyonFlame/Worship-Vector

decompiled_code:
void RenderObjects()
{
RenderMobs();
RenderLines();
}

canonical_decompiled_code:
void func2()
{
RenderMobs();
func1();
}

original_code:
void RenderObjects(void) {
 RenderMobs();
 RenderLines();
}

return_type: void


RaiseLand

decompiled_code:
void __fastcall RaiseLand(unsigned __int8 a1, unsigned __int8 a2)
{
char *v2; // rax
char v3; // dl

if ( a1 <= 0x3Fu && a2 <= 0x3Fu )
{
v2 = (char *)&map + 64 * (__int64)(char)a1 + (char)a2;
v3 = *v2;
if ( *v2 == 1 )
{
*v2 = 2;
}
else if ( v3 == 4 )
{
*v2 = 3;
}
else if ( v3 == 6 )
{
*v2 = 5;
}
}
}

variable_types: x char

variable_types: y char


PlayerAction

decompiled_code:
__int64 PlayerAction()
{
__int64 result; // rax
__int64 v1; // r14
int v2; // ebp
int v3; // ebx
int v4; // ebp
int v5; // ebx
int v6; // er9
__int64 v7; // rdi
__int64 v8; // rsi
char v9; // dl
unsigned __int8 v10; // cl
__int64 v11; // r8
char *v12; // rcx
char *v13; // rdi
__int64 v14; // rax
__int64 v15; // rdx
int v16; // ebx
unsigned __int8 *v17; // rdx
int v18; // ebp

result = cursorvisual;
cost = 0;
if ( cursorvisual != 2 )
{
if ( cursorvisual != 3 )
{
LABEL_3:
if ( (_BYTE)result == 4 )
{
result = (unsigned __int16)sell_cost[map[64 * (__int64)byte_D5 + cy] - 11];
cost = (unsigned __int16)sell_cost[map[64 * (__int64)byte_D5 + cy] - 11];
if ( vbutton == 1 || *((_BYTE *)&vbutton + 2) == 1 )
{
PlaySound(1LL, 0LL);
funds += cost;
v14 = byte_D5;
v15 = cy;
newvline = 0x400000014LL;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
*((_DWORD *)&newvline + 3) = 1000;
v16 = v15;
v17 = &map[64 * v14 + v15];
*((_DWORD *)&newvline + 6) = 1000;
v18 = (_DWORD)v14 << 16;
LOBYTE(v14) = 9 * (*v17 != 11) + 2;
v16 <<= 16;
*((_DWORD *)&newvline + 2) = v18;
*v17 = v14;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_DWORD *)&newvline + 4) = v16;
*((_DWORD *)&newvline + 5) = v18 + 0x10000;
*((_DWORD *)&newvline + 7) = v16;
*((_QWORD *)&newvline + 5) = 0x1F40FFFFE0C0LL;
SpawnLine();
newvline = 0x400000014LL;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_QWORD *)&newvline + 5) = 0x1F4000001F40LL;
*((_DWORD *)&newvline + 2) = v18;
*((_DWORD *)&newvline + 4) = v16 + 0x10000;
*((_DWORD *)&newvline + 5) = v18 + 0x10000;
*((_DWORD *)&newvline + 7) = v16 + 0x10000;
*((_QWORD *)&newvline + 6) = 34359738370000LL;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 6) = 1000;
SpawnLine();
newvline = 0x400000014LL;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_DWORD *)&newvline + 2) = v18;
*((_DWORD *)&newvline + 4) = v16 + 0x10000;
*((_DWORD *)&newvline + 5) = v18;
*((_DWORD *)&newvline + 7) = v16;
*((_QWORD *)&newvline + 5) = -34359738360000LL;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 6) = 1000;
SpawnLine();
newvline = 0x400000014LL;
*((_DWORD *)&newvline + 2) = v18 + 0x10000;
*((_DWORD *)&newvline + 4) = v16 + 0x10000;
*((_DWORD *)&newvline + 5) = v18 + 0x10000;
*((_DWORD *)&newvline + 7) = v16;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 6) = 1000;
*((_QWORD *)&newvline + 4) = 8589934600000LL;
*((_QWORD *)&newvline + 5) = 0x1F4000001F40LL;
result = SpawnLine();
zl_vibro = 126;
}
}
return result;
}
result = (unsigned __int16)tower_cost[towermenu];
cost = (unsigned __int16)tower_cost[towermenu];
if ( (vbutton == 1 || *((_BYTE *)&vbutton + 2) == 1) && (int)result <= funds )
{
v1 = 0xF00000014LL;
funds -= result;
v2 = byte_D5;
v3 = cy;
map[64 * (__int64)byte_D5 + cy] = towermenu + 12;
v4 = v2 << 16;
v5 = v3 << 16;
LABEL_17:
newvline = v1;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_QWORD *)&newvline + 5) = 0x1F40FFFFE0C0LL;
*((_DWORD *)&newvline + 2) = v4;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 4) = v5;
*((_DWORD *)&newvline + 5) = v4 + 0x10000;
*((_DWORD *)&newvline + 6) = 1000;
*((_DWORD *)&newvline + 7) = v5;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
SpawnLine();
newvline = v1;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_QWORD *)&newvline + 5) = 0x1F4000001F40LL;
*((_QWORD *)&newvline + 6) = 34359738370000LL;
*((_DWORD *)&newvline + 2) = v4;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 4) = v5 + 0x10000;
*((_DWORD *)&newvline + 5) = v4 + 0x10000;
*((_DWORD *)&newvline + 6) = 1000;
*((_DWORD *)&newvline + 7) = v5 + 0x10000;
SpawnLine();
newvline = v1;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_QWORD *)&newvline + 5) = -34359738360000LL;
*((_DWORD *)&newvline + 2) = v4;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 4) = v5 + 0x10000;
*((_DWORD *)&newvline + 5) = v4;
*((_DWORD *)&newvline + 6) = 1000;
*((_DWORD *)&newvline + 7) = v5;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
SpawnLine();
newvline = v1;
*((_QWORD *)&newvline + 4) = 8589934600000LL;
*((_QWORD *)&newvline + 5) = 0x1F4000001F40LL;
*((_DWORD *)&newvline + 2) = v4 + 0x10000;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 4) = v5 + 0x10000;
*((_DWORD *)&newvline + 5) = v4 + 0x10000;
*((_DWORD *)&newvline + 6) = 1000;
*((_DWORD *)&newvline + 7) = v5;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
SpawnLine();
PlaySound(2LL, 0LL);
zl_vibro = 126;
result = cursorvisual;
goto LABEL_3;
}
return result;
}
v6 = byte_D5;
v7 = byte_D5;
v8 = cy;
result = (unsigned int)byte_D5;
v9 = cy;
v10 = map[64 * (__int64)byte_D5 + cy];
switch ( v10 )
{
case 0u:
cost = 10;
goto LABEL_13;
case 1u:
goto LABEL_24;
case 2u:
cost = 15;
goto LABEL_13;
case 3u:
cost = 30;
goto LABEL_13;
case 4u:
LABEL_24:
cost = 50;
goto LABEL_13;
}
if ( v10 != 5 )
{
if ( v10 != 6 )
goto LABEL_13;
goto LABEL_24;
}
cost = 40;
LABEL_13:
if ( (vbutton == 1 || *((_BYTE *)&vbutton + 2) == 1) && funds >= cost )
{
funds -= cost;
v11 = cy + 1;
v1 = 0xE00000014LL;
map[64 * (__int64)byte_D5 + cy] = 11;
v12 = (char *)&mapz + 65 * v7;
v12[v8] = 0;
v13 = (char *)&mapz + 65 * v6 + 65;
v13[v8] = 0;
v13[v11] = 0;
v12[v11] = 0;
RaiseLand(result - 1, v9 - 1);
RaiseLand(byte_D5, cy - 1);
RaiseLand(byte_D5 + 1, cy - 1);
RaiseLand(byte_D5 + 1, cy);
RaiseLand(byte_D5 + 1, cy + 1);
RaiseLand(byte_D5, cy + 1);
RaiseLand(byte_D5 - 1, cy + 1);
RaiseLand(byte_D5 - 1, cy);
v4 = byte_D5 << 16;
v5 = cy << 16;
goto LABEL_17;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // r14
int v2; // ebp
int v3; // ebx
int v4; // ebp
int v5; // ebx
int v6; // er9
__int64 v7; // rdi
__int64 v8; // rsi
char v9; // dl
unsigned __int8 v10; // cl
__int64 v11; // r8
char *v12; // rcx
char *v13; // rdi
__int64 v14; // rax
__int64 v15; // rdx
int v16; // ebx
unsigned __int8 *v17; // rdx
int v18; // ebp

result = cursorvisual;
cost = 0;
if ( cursorvisual != 2 )
{
if ( cursorvisual != 3 )
{
LABEL_3:
if ( (_BYTE)result == 4 )
{
result = (unsigned __int16)sell_cost[map[64 * (__int64)byte_D5 + cy] - 11];
cost = (unsigned __int16)sell_cost[map[64 * (__int64)byte_D5 + cy] - 11];
if ( vbutton == 1 || *((_BYTE *)&vbutton + 2) == 1 )
{
PlaySound(1LL, 0LL);
funds += cost;
v14 = byte_D5;
v15 = cy;
newvline = 0x400000014LL;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
*((_DWORD *)&newvline + 3) = 1000;
v16 = v15;
v17 = &map[64 * v14 + v15];
*((_DWORD *)&newvline + 6) = 1000;
v18 = (_DWORD)v14 << 16;
LOBYTE(v14) = 9 * (*v17 != 11) + 2;
v16 <<= 16;
*((_DWORD *)&newvline + 2) = v18;
*v17 = v14;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_DWORD *)&newvline + 4) = v16;
*((_DWORD *)&newvline + 5) = v18 + 0x10000;
*((_DWORD *)&newvline + 7) = v16;
*((_QWORD *)&newvline + 5) = 0x1F40FFFFE0C0LL;
SpawnLine();
newvline = 0x400000014LL;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_QWORD *)&newvline + 5) = 0x1F4000001F40LL;
*((_DWORD *)&newvline + 2) = v18;
*((_DWORD *)&newvline + 4) = v16 + 0x10000;
*((_DWORD *)&newvline + 5) = v18 + 0x10000;
*((_DWORD *)&newvline + 7) = v16 + 0x10000;
*((_QWORD *)&newvline + 6) = 34359738370000LL;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 6) = 1000;
SpawnLine();
newvline = 0x400000014LL;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_DWORD *)&newvline + 2) = v18;
*((_DWORD *)&newvline + 4) = v16 + 0x10000;
*((_DWORD *)&newvline + 5) = v18;
*((_DWORD *)&newvline + 7) = v16;
*((_QWORD *)&newvline + 5) = -34359738360000LL;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 6) = 1000;
SpawnLine();
newvline = 0x400000014LL;
*((_DWORD *)&newvline + 2) = v18 + 0x10000;
*((_DWORD *)&newvline + 4) = v16 + 0x10000;
*((_DWORD *)&newvline + 5) = v18 + 0x10000;
*((_DWORD *)&newvline + 7) = v16;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 6) = 1000;
*((_QWORD *)&newvline + 4) = 8589934600000LL;
*((_QWORD *)&newvline + 5) = 0x1F4000001F40LL;
result = SpawnLine();
zl_vibro = 126;
}
}
return result;
}
result = (unsigned __int16)tower_cost[towermenu];
cost = (unsigned __int16)tower_cost[towermenu];
if ( (vbutton == 1 || *((_BYTE *)&vbutton + 2) == 1) && (int)result <= funds )
{
v1 = 0xF00000014LL;
funds -= result;
v2 = byte_D5;
v3 = cy;
map[64 * (__int64)byte_D5 + cy] = towermenu + 12;
v4 = v2 << 16;
v5 = v3 << 16;
LABEL_17:
newvline = v1;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_QWORD *)&newvline + 5) = 0x1F40FFFFE0C0LL;
*((_DWORD *)&newvline + 2) = v4;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 4) = v5;
*((_DWORD *)&newvline + 5) = v4 + 0x10000;
*((_DWORD *)&newvline + 6) = 1000;
*((_DWORD *)&newvline + 7) = v5;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
SpawnLine();
newvline = v1;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_QWORD *)&newvline + 5) = 0x1F4000001F40LL;
*((_QWORD *)&newvline + 6) = 34359738370000LL;
*((_DWORD *)&newvline + 2) = v4;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 4) = v5 + 0x10000;
*((_DWORD *)&newvline + 5) = v4 + 0x10000;
*((_DWORD *)&newvline + 6) = 1000;
*((_DWORD *)&newvline + 7) = v5 + 0x10000;
SpawnLine();
newvline = v1;
*((_QWORD *)&newvline + 4) = 0x7D0FFFFE0C0LL;
*((_QWORD *)&newvline + 5) = -34359738360000LL;
*((_DWORD *)&newvline + 2) = v4;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 4) = v5 + 0x10000;
*((_DWORD *)&newvline + 5) = v4;
*((_DWORD *)&newvline + 6) = 1000;
*((_DWORD *)&newvline + 7) = v5;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
SpawnLine();
newvline = v1;
*((_QWORD *)&newvline + 4) = 8589934600000LL;
*((_QWORD *)&newvline + 5) = 0x1F4000001F40LL;
*((_DWORD *)&newvline + 2) = v4 + 0x10000;
*((_DWORD *)&newvline + 3) = 1000;
*((_DWORD *)&newvline + 4) = v5 + 0x10000;
*((_DWORD *)&newvline + 5) = v4 + 0x10000;
*((_DWORD *)&newvline + 6) = 1000;
*((_DWORD *)&newvline + 7) = v5;
*((_QWORD *)&newvline + 6) = 0xFFFFE0C0000007D0LL;
SpawnLine();
PlaySound(2LL, 0LL);
zl_vibro = 126;
result = cursorvisual;
goto LABEL_3;
}
return result;
}
v6 = byte_D5;
v7 = byte_D5;
v8 = cy;
result = (unsigned int)byte_D5;
v9 = cy;
v10 = map[64 * (__int64)byte_D5 + cy];
switch ( v10 )
{
case 0u:
cost = 10;
goto LABEL_13;
case 1u:
goto LABEL_24;
case 2u:
cost = 15;
goto LABEL_13;
case 3u:
cost = 30;
goto LABEL_13;
case 4u:
LABEL_24:
cost = 50;
goto LABEL_13;
}
if ( v10 != 5 )
{
if ( v10 != 6 )
goto LABEL_13;
goto LABEL_24;
}
cost = 40;
LABEL_13:
if ( (vbutton == 1 || *((_BYTE *)&vbutton + 2) == 1) && funds >= cost )
{
funds -= cost;
v11 = cy + 1;
v1 = 0xE00000014LL;
map[64 * (__int64)byte_D5 + cy] = 11;
v12 = (char *)&mapz + 65 * v7;
v12[v8] = 0;
v13 = (char *)&mapz + 65 * v6 + 65;
v13[v8] = 0;
v13[v11] = 0;
v12[v11] = 0;
func0(result - 1, v9 - 1);
func0(byte_D5, cy - 1);
func0(byte_D5 + 1, cy - 1);
func0(byte_D5 + 1, cy);
func0(byte_D5 + 1, cy + 1);
func0(byte_D5, cy + 1);
func0(byte_D5 - 1, cy + 1);
func0(byte_D5 - 1, cy);
v4 = byte_D5 << 16;
v5 = cy << 16;
goto LABEL_17;
}
return result;
}

original_code:
void PlayerAction(void) {
 cost = 0;
 Sint32 ccx, ccy;
 if (cursorvisual == 2) {
  if (map[cx][cy] == 0)
   cost = 10;
  else if (map[cx][cy] == 1)
   cost = 50;
  else if (map[cx][cy] == 2)
   cost = 15;
  else if (map[cx][cy] == 3)
   cost = 30;
  else if (map[cx][cy] == 4)
   cost = 50;
  else if (map[cx][cy] == 5)
   cost = 40;
  else if (map[cx][cy] == 6)
   cost = 50;
  if ((vbutton[0] == 1) | (vbutton[2] == 1))
   if (funds >= cost) {
    funds -= cost;
    map[cx][cy] = 11;
    mapz[cx][cy] = 0;
    mapz[cx + 1][cy] = 0;
    mapz[cx + 1][cy + 1] = 0;
    mapz[cx][cy + 1] = 0;
    RaiseLand(cx - 1, cy - 1);
    RaiseLand(cx, cy - 1);
    RaiseLand(cx + 1, cy - 1);
    RaiseLand(cx + 1, cy);
    RaiseLand(cx + 1, cy + 1);
    RaiseLand(cx, cy + 1);
    RaiseLand(cx - 1, cy + 1);
    RaiseLand(cx - 1, cy);
    ccx = cx * 65536 + 32768;
    ccy = cy * 65536 + 32768;
    newvline[0] = 20;
    newvline[1] = 14;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy - 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = -8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 14;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy + 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = 8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 14;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx - 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = -8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 14;
    newvline[2] = ccx + 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = 8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    PlaySound(2, 0);
    zl_vibro = 126;
   }
 } else if (cursorvisual == 3) {
  cost = tower_cost[towermenu];
  if ((vbutton[0] == 1) | (vbutton[2] == 1))
   if (funds >= cost) {
    funds -= cost;
    map[cx][cy] = 12 + towermenu;
    ccx = cx * 65536 + 32768;
    ccy = cy * 65536 + 32768;
    newvline[0] = 20;
    newvline[1] = 15;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy - 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = -8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 15;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy + 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = 8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 15;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx - 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = -8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 15;
    newvline[2] = ccx + 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = 8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    PlaySound(2, 0);
    zl_vibro = 126;
   }
 }
 if (cursorvisual == 4) {
  cost = sell_cost[map[cx][cy] - 11];
  if ((vbutton[0] == 1) | (vbutton[2] == 1)) {
   PlaySound(1, 0);
   funds += cost;
   if (map[cx][cy] == 11)
    map[cx][cy] = 2;
   else
    map[cx][cy] = 11;
   ccx = cx * 65536 + 32768;
   ccy = cy * 65536 + 32768;
   newvline[0] = 20;
   newvline[1] = 4;
   newvline[2] = ccx - 32768;
   newvline[3] = 1000;
   newvline[4] = ccy - 32768;
   newvline[5] = ccx + 32768;
   newvline[6] = 1000;
   newvline[7] = ccy - 32768;
   newvline[8] = -8000;
   newvline[9] = 2000;
   newvline[10] = -8000;
   newvline[11] = 8000;
   newvline[12] = 2000;
   newvline[13] = -8000;
   SpawnLine();
   newvline[0] = 20;
   newvline[1] = 4;
   newvline[2] = ccx - 32768;
   newvline[3] = 1000;
   newvline[4] = ccy + 32768;
   newvline[5] = ccx + 32768;
   newvline[6] = 1000;
   newvline[7] = ccy + 32768;
   newvline[8] = -8000;
   newvline[9] = 2000;
   newvline[10] = 8000;
   newvline[11] = 8000;
   newvline[12] = 2000;
   newvline[13] = 8000;
   SpawnLine();
   newvline[0] = 20;
   newvline[1] = 4;
   newvline[2] = ccx - 32768;
   newvline[3] = 1000;
   newvline[4] = ccy + 32768;
   newvline[5] = ccx - 32768;
   newvline[6] = 1000;
   newvline[7] = ccy - 32768;
   newvline[8] = -8000;
   newvline[9] = 2000;
   newvline[10] = 8000;
   newvline[11] = -8000;
   newvline[12] = 2000;
   newvline[13] = -8000;
   SpawnLine();
   newvline[0] = 20;
   newvline[1] = 4;
   newvline[2] = ccx + 32768;
   newvline[3] = 1000;
   newvline[4] = ccy + 32768;
   newvline[5] = ccx + 32768;
   newvline[6] = 1000;
   newvline[7] = ccy - 32768;
   newvline[8] = 8000;
   newvline[9] = 2000;
   newvline[10] = 8000;
   newvline[11] = 8000;
   newvline[12] = 2000;
   newvline[13] = -8000;
   SpawnLine();
   zl_vibro = 126;
  }
 }
}

canonical_original_code:
void PlayerAction() {
 cost = 0;
 int ccx; int ccy;
 if (cursorvisual == 2) {
  if (map[cx][cy] == 0)
   cost = 10;
  else if (map[cx][cy] == 1)
   cost = 50;
  else if (map[cx][cy] == 2)
   cost = 15;
  else if (map[cx][cy] == 3)
   cost = 30;
  else if (map[cx][cy] == 4)
   cost = 50;
  else if (map[cx][cy] == 5)
   cost = 40;
  else if (map[cx][cy] == 6)
   cost = 50;
  if ((vbutton[0] == 1) | (vbutton[2] == 1))
   if (funds >= cost) {
    funds -= cost;
    map[cx][cy] = 11;
    mapz[cx][cy] = 0;
    mapz[cx + 1][cy] = 0;
    mapz[cx + 1][cy + 1] = 0;
    mapz[cx][cy + 1] = 0;
    RaiseLand(cx - 1, cy - 1);
    RaiseLand(cx, cy - 1);
    RaiseLand(cx + 1, cy - 1);
    RaiseLand(cx + 1, cy);
    RaiseLand(cx + 1, cy + 1);
    RaiseLand(cx, cy + 1);
    RaiseLand(cx - 1, cy + 1);
    RaiseLand(cx - 1, cy);
    ccx = cx * 65536 + 32768;
    ccy = cy * 65536 + 32768;
    newvline[0] = 20;
    newvline[1] = 14;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy - 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = -8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 14;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy + 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = 8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 14;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx - 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = -8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 14;
    newvline[2] = ccx + 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = 8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    PlaySound(2, 0);
    zl_vibro = 126;
   }
 } else if (cursorvisual == 3) {
  cost = tower_cost[towermenu];
  if ((vbutton[0] == 1) | (vbutton[2] == 1))
   if (funds >= cost) {
    funds -= cost;
    map[cx][cy] = 12 + towermenu;
    ccx = cx * 65536 + 32768;
    ccy = cy * 65536 + 32768;
    newvline[0] = 20;
    newvline[1] = 15;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy - 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = -8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 15;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy + 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = 8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 15;
    newvline[2] = ccx - 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx - 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = -8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = -8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    newvline[0] = 20;
    newvline[1] = 15;
    newvline[2] = ccx + 32768;
    newvline[3] = 1000;
    newvline[4] = ccy + 32768;
    newvline[5] = ccx + 32768;
    newvline[6] = 1000;
    newvline[7] = ccy - 32768;
    newvline[8] = 8000;
    newvline[9] = 2000;
    newvline[10] = 8000;
    newvline[11] = 8000;
    newvline[12] = 2000;
    newvline[13] = -8000;
    SpawnLine();
    PlaySound(2, 0);
    zl_vibro = 126;
   }
 }
 if (cursorvisual == 4) {
  cost = sell_cost[map[cx][cy] - 11];
  if ((vbutton[0] == 1) | (vbutton[2] == 1)) {
   PlaySound(1, 0);
   funds += cost;
   if (map[cx][cy] == 11)
    map[cx][cy] = 2;
   else
    map[cx][cy] = 11;
   ccx = cx * 65536 + 32768;
   ccy = cy * 65536 + 32768;
   newvline[0] = 20;
   newvline[1] = 4;
   newvline[2] = ccx - 32768;
   newvline[3] = 1000;
   newvline[4] = ccy - 32768;
   newvline[5] = ccx + 32768;
   newvline[6] = 1000;
   newvline[7] = ccy - 32768;
   newvline[8] = -8000;
   newvline[9] = 2000;
   newvline[10] = -8000;
   newvline[11] = 8000;
   newvline[12] = 2000;
   newvline[13] = -8000;
   SpawnLine();
   newvline[0] = 20;
   newvline[1] = 4;
   newvline[2] = ccx - 32768;
   newvline[3] = 1000;
   newvline[4] = ccy + 32768;
   newvline[5] = ccx + 32768;
   newvline[6] = 1000;
   newvline[7] = ccy + 32768;
   newvline[8] = -8000;
   newvline[9] = 2000;
   newvline[10] = 8000;
   newvline[11] = 8000;
   newvline[12] = 2000;
   newvline[13] = 8000;
   SpawnLine();
   newvline[0] = 20;
   newvline[1] = 4;
   newvline[2] = ccx - 32768;
   newvline[3] = 1000;
   newvline[4] = ccy + 32768;
   newvline[5] = ccx - 32768;
   newvline[6] = 1000;
   newvline[7] = ccy - 32768;
   newvline[8] = -8000;
   newvline[9] = 2000;
   newvline[10] = 8000;
   newvline[11] = -8000;
   newvline[12] = 2000;
   newvline[13] = -8000;
   SpawnLine();
   newvline[0] = 20;
   newvline[1] = 4;
   newvline[2] = ccx + 32768;
   newvline[3] = 1000;
   newvline[4] = ccy + 32768;
   newvline[5] = ccx + 32768;
   newvline[6] = 1000;
   newvline[7] = ccy - 32768;
   newvline[8] = 8000;
   newvline[9] = 2000;
   newvline[10] = 8000;
   newvline[11] = 8000;
   newvline[12] = 2000;
   newvline[13] = -8000;
   SpawnLine();
   zl_vibro = 126;
  }
 }
}

variable_types: ccx int

variable_types: ccy int


PlayerIteraction

decompiled_code:
__int64 PlayerIteraction()
{
int v0; // er8
int v1; // ebx
char v2; // si
__int64 v3; // rax
int v4; // ecx
int v5; // edi
int v6; // edx
int v7; // edx
char v8; // al
int v9; // ebp
int v10; // ebx
int v11; // ecx
bool v12; // zf
char v13; // r12
int v14; // eax
int v15; // edx
int v16; // ebp
int v17; // ebx
int v18; // eax
int v19; // edx
unsigned __int8 v21; // al

v0 = zl_gsensor[3];
v1 = zl_gsensor[4];
v2 = cursormode;
v3 = 6LL * cursormode;
v4 = cm_speed[cursormode];
v5 = cm_cam[v3 + 4];
camera[0] = cm_cam[v3] + cursorx;
v6 = cm_cam[v3 + 2] - cursory;
camera[4] = v5;
camera[2] = v6;
camera[1] = cm_cam[v3 + 1];
camera[5] = cm_cam[v3 + 5] + 2 * v0;
v7 = cm_cam[v3 + 3] + 2 * v1;
v8 = dpad;
camera[3] = v7;
if ( v8 < 0 )
{
if ( dpadpower )
--dpadpower;
goto LABEL_32;
}
if ( (unsigned __int8)v2 <= 3u && dpadpower <= 0xEu )
++dpadpower;
v9 = v4;
if ( (unsigned __int8)(v8 - 1) > 2u )
{
if ( (unsigned __int8)(v8 - 5) <= 2u )
{
v9 = -v4;
goto LABEL_4;
}
LABEL_32:
v9 = 0;
}
LABEL_4:
if ( (unsigned __int8)v8 <= 1u || (v10 = 0, v8 == 7) )
v10 = -v4;
v11 = v10 + v4;
if ( (unsigned __int8)(v8 - 3) < 3u )
v10 = v11;
if ( (unsigned __int8)v2 <= 2u )
{
camera[4] = v5 + v9 / 250;
camera[3] = v10 / 250 + v7;
}
v12 = vbutton[5] == 1;
lastcursormode = v2;
if ( v12 )
{
PlaySound(0LL, 0LL);
zl_vibro = 100;
cursormode = ((unsigned int)cursormode + 1) % 5;
}
if ( vbutton[4] != 1 )
{
LABEL_13:
if ( vbutton[8] != 1 )
goto LABEL_14;
LABEL_38:
v13 = 4;
PlaySound(0LL, 0LL);
cursormode = 4;
lastcursormode = 0;
goto LABEL_15;
}
if ( !cursormode )
{
cursormode = 4;
PlaySound(0LL, 0LL);
goto LABEL_13;
}
PlaySound(0LL, 0LL);
--cursormode;
v12 = vbutton[8] == 1;
zl_vibro = 100;
if ( v12 )
goto LABEL_38;
LABEL_14:
v13 = cursormode;
if ( lastcursormode == cursormode )
{
++cursormodecount;
goto LABEL_16;
}
LABEL_15:
memset(&scrbuf, 15, 0x12C00uLL);
cursormodecount = 0;
LABEL_16:
v14 = cursorx;
v15 = cursory;
v16 = cursorx + v9;
if ( (unsigned int)(v16 - 1) <= 0x3FFFFE && *((_BYTE *)&mapunlock + 8 * (v16 >> 19) + cursory / 0x80000) <= wave )
{
cursorx = v16;
v14 = v16;
}
v17 = cursory + v10;
if ( (unsigned int)(v17 - 1) <= 0x3FFFFE && *((_BYTE *)&mapunlock + 8 * (v14 / 0x80000) + (v17 >> 19)) <= wave )
{
cursory = v17;
v15 = v17;
}
v18 = v14 >> 16;
v19 = v15 >> 16;
byte_D5 = v18;
cy = v19;
if ( v13 == 1 )
{
cursorvisual = 1;
v21 = map[64 * (__int64)(char)v18 + (char)v19];
if ( v21 <= 8u )
{
cursorvisual = 2;
PlayerAction();
return ProcAi();
}
if ( v21 == 11 )
cursorvisual = 3;
}
else
{
if ( v13 == 2 )
{
cursorvisual = (unsigned __int8)(map[64 * (__int64)(char)v18 + (char)v19] - 11) < 9u ? 4 : 1;
PlayerAction();
return ProcAi();
}
cursorvisual = 0;
}
PlayerAction();
return ProcAi();
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // er8
int v1; // ebx
char v2; // si
__int64 v3; // rax
int v4; // ecx
int v5; // edi
int v6; // edx
int v7; // edx
char v8; // al
int v9; // ebp
int v10; // ebx
int v11; // ecx
bool v12; // zf
char v13; // r12
int v14; // eax
int v15; // edx
int v16; // ebp
int v17; // ebx
int v18; // eax
int v19; // edx
unsigned __int8 v21; // al

v0 = zl_gsensor[3];
v1 = zl_gsensor[4];
v2 = cursormode;
v3 = 6LL * cursormode;
v4 = cm_speed[cursormode];
v5 = cm_cam[v3 + 4];
camera[0] = cm_cam[v3] + cursorx;
v6 = cm_cam[v3 + 2] - cursory;
camera[4] = v5;
camera[2] = v6;
camera[1] = cm_cam[v3 + 1];
camera[5] = cm_cam[v3 + 5] + 2 * v0;
v7 = cm_cam[v3 + 3] + 2 * v1;
v8 = dpad;
camera[3] = v7;
if ( v8 < 0 )
{
if ( dpadpower )
--dpadpower;
goto LABEL_32;
}
if ( (unsigned __int8)v2 <= 3u && dpadpower <= 0xEu )
++dpadpower;
v9 = v4;
if ( (unsigned __int8)(v8 - 1) > 2u )
{
if ( (unsigned __int8)(v8 - 5) <= 2u )
{
v9 = -v4;
goto LABEL_4;
}
LABEL_32:
v9 = 0;
}
LABEL_4:
if ( (unsigned __int8)v8 <= 1u || (v10 = 0, v8 == 7) )
v10 = -v4;
v11 = v10 + v4;
if ( (unsigned __int8)(v8 - 3) < 3u )
v10 = v11;
if ( (unsigned __int8)v2 <= 2u )
{
camera[4] = v5 + v9 / 250;
camera[3] = v10 / 250 + v7;
}
v12 = vbutton[5] == 1;
lastcursormode = v2;
if ( v12 )
{
PlaySound(0LL, 0LL);
zl_vibro = 100;
cursormode = ((unsigned int)cursormode + 1) % 5;
}
if ( vbutton[4] != 1 )
{
LABEL_13:
if ( vbutton[8] != 1 )
goto LABEL_14;
LABEL_38:
v13 = 4;
PlaySound(0LL, 0LL);
cursormode = 4;
lastcursormode = 0;
goto LABEL_15;
}
if ( !cursormode )
{
cursormode = 4;
PlaySound(0LL, 0LL);
goto LABEL_13;
}
PlaySound(0LL, 0LL);
--cursormode;
v12 = vbutton[8] == 1;
zl_vibro = 100;
if ( v12 )
goto LABEL_38;
LABEL_14:
v13 = cursormode;
if ( lastcursormode == cursormode )
{
++cursormodecount;
goto LABEL_16;
}
LABEL_15:
memset(&scrbuf, 15, 0x12C00uLL);
cursormodecount = 0;
LABEL_16:
v14 = cursorx;
v15 = cursory;
v16 = cursorx + v9;
if ( (unsigned int)(v16 - 1) <= 0x3FFFFE && *((_BYTE *)&mapunlock + 8 * (v16 >> 19) + cursory / 0x80000) <= wave )
{
cursorx = v16;
v14 = v16;
}
v17 = cursory + v10;
if ( (unsigned int)(v17 - 1) <= 0x3FFFFE && *((_BYTE *)&mapunlock + 8 * (v14 / 0x80000) + (v17 >> 19)) <= wave )
{
cursory = v17;
v15 = v17;
}
v18 = v14 >> 16;
v19 = v15 >> 16;
byte_D5 = v18;
cy = v19;
if ( v13 == 1 )
{
cursorvisual = 1;
v21 = map[64 * (__int64)(char)v18 + (char)v19];
if ( v21 <= 8u )
{
cursorvisual = 2;
func1();
return ProcAi();
}
if ( v21 == 11 )
cursorvisual = 3;
}
else
{
if ( v13 == 2 )
{
cursorvisual = (unsigned __int8)(map[64 * (__int64)(char)v18 + (char)v19] - 11) < 9u ? 4 : 1;
func1();
return ProcAi();
}
cursorvisual = 0;
}
func1();
return ProcAi();
}

original_code:
void PlayerIteraction(void) {
 Sint32 i;
 camera[0] = cursorx + cm_cam[cursormode][0];
 camera[2] = -cursory + cm_cam[cursormode][2];
 camera[1] = +cm_cam[cursormode][1];
 camera[3] = +cm_cam[cursormode][3];
 camera[4] = +cm_cam[cursormode][4];
 camera[5] = +cm_cam[cursormode][5];
 camera[5] += 2 * zl_gsensor[3];
 camera[3] += 2 * zl_gsensor[4];
 Sint32 icx = 0, icy = 0, cspeed = cm_speed[cursormode];
 if (dpad > -1) {
  if (cursormode < 4)
   if (dpadpower < 15)
    dpadpower++;
 } else if (dpadpower > 0)
  dpadpower--;
 if ((dpad > 0) & (dpad < 4))
  icx += cspeed;
 if ((dpad > 4) & (dpad < 8))
  icx -= cspeed;
 if ((dpad == 0) | (dpad == 1) | (dpad == 7))
  icy -= cspeed;
 if ((dpad > 2) & (dpad < 6))
  icy += cspeed;
 if (cursormode < 3) {
  camera[4] += icx / 250;
  camera[3] += icy / 250;
 }
 lastcursormode = cursormode;
 if (vbutton[5] == 1) {
  PlaySound(0, 0);
  cursormode = (cursormode + 1) % 5;
  zl_vibro = 100;
 }
 if (vbutton[4] == 1)
  if (cursormode > 0) {
   PlaySound(0, 0);
   cursormode--;
   zl_vibro = 100;
  } else {
   cursormode = 4;
   PlaySound(0, 0);
  }
 if (vbutton[8] == 1) {
  PlaySound(0, 0);
  cursormode = 4;
  lastcursormode = 0;
 }
 if (lastcursormode != cursormode) {
  for (i = 0; i < 76800; i++)
   scrbuf[i] = 15;
  cursormodecount = 0;
 } else
  cursormodecount++;
 if (cursorx + icx > 0)
  if (cursorx + icx < 64 * 65536)
   if (mapunlock[(cursorx + icx) / (65536 * 8)][cursory / (8 * 65536)]
     <= wave)
    cursorx += icx;
 if (cursory + icy > 0)
  if (cursory + icy < 64 * 65536)
   if (mapunlock[(cursorx) / (65536 * 8)][(cursory + icy) / (8 * 65536)]
     <= wave)
    cursory += icy;
 cx = cursorx >> 16;
 cy = cursory >> 16;
 cursorvisual = 0;
 if (cursormode == 1) {
  cursorvisual = 1;
  if (map[cx][cy] < 9)
   cursorvisual = 2;
  else if (map[cx][cy] == 11)
   cursorvisual = 3;
 } else if (cursormode == 2) {
  cursorvisual = 1;
  if (map[cx][cy] > 10)
   if (map[cx][cy] < 20)
    cursorvisual = 4;
 }
 PlayerAction();
 ProcAi();
}

canonical_original_code:
void PlayerIteraction() {
 int i;
 camera[0] = cursorx + cm_cam[cursormode][0];
 camera[2] = -cursory + cm_cam[cursormode][2];
 camera[1] = +cm_cam[cursormode][1];
 camera[3] = +cm_cam[cursormode][3];
 camera[4] = +cm_cam[cursormode][4];
 camera[5] = +cm_cam[cursormode][5];
 camera[5] += 2 * zl_gsensor[3];
 camera[3] += 2 * zl_gsensor[4];
 int icx = 0; int icy = 0; int cspeed = cm_speed[cursormode];
 if (dpad > -1) {
  if (cursormode < 4)
   if (dpadpower < 15)
    dpadpower++;
 } else if (dpadpower > 0)
  dpadpower--;
 if ((dpad > 0) & (dpad < 4))
  icx += cspeed;
 if ((dpad > 4) & (dpad < 8))
  icx -= cspeed;
 if ((dpad == 0) | (dpad == 1) | (dpad == 7))
  icy -= cspeed;
 if ((dpad > 2) & (dpad < 6))
  icy += cspeed;
 if (cursormode < 3) {
  camera[4] += icx / 250;
  camera[3] += icy / 250;
 }
 lastcursormode = cursormode;
 if (vbutton[5] == 1) {
  PlaySound(0, 0);
  cursormode = (cursormode + 1) % 5;
  zl_vibro = 100;
 }
 if (vbutton[4] == 1)
  if (cursormode > 0) {
   PlaySound(0, 0);
   cursormode--;
   zl_vibro = 100;
  } else {
   cursormode = 4;
   PlaySound(0, 0);
  }
 if (vbutton[8] == 1) {
  PlaySound(0, 0);
  cursormode = 4;
  lastcursormode = 0;
 }
 if (lastcursormode != cursormode) {
  for (i = 0; i < 76800; i++)
   scrbuf[i] = 15;
  cursormodecount = 0;
 } else
  cursormodecount++;
 if (cursorx + icx > 0)
  if (cursorx + icx < 64 * 65536)
   if (mapunlock[(cursorx + icx) / (65536 * 8)][cursory / (8 * 65536)]
     <= wave)
    cursorx += icx;
 if (cursory + icy > 0)
  if (cursory + icy < 64 * 65536)
   if (mapunlock[(cursorx) / (65536 * 8)][(cursory + icy) / (8 * 65536)]
     <= wave)
    cursory += icy;
 cx = cursorx >> 16;
 cy = cursory >> 16;
 cursorvisual = 0;
 if (cursormode == 1) {
  cursorvisual = 1;
  if (map[cx][cy] < 9)
   cursorvisual = 2;
  else if (map[cx][cy] == 11)
   cursorvisual = 3;
 } else if (cursormode == 2) {
  cursorvisual = 1;
  if (map[cx][cy] > 10)
   if (map[cx][cy] < 20)
    cursorvisual = 4;
 }
 PlayerAction();
 ProcAi();
}

variable_types: i int

variable_types: icx int

variable_types: icy int

variable_types: cspeed int


ProcLines

decompiled_code:
void ProcLines()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void ProcLines(void) {
}

canonical_original_code:
void ProcLines() {
}


SpawnLine

original_code:
extern void SpawnLine(void) {
 Uint8 i = 0, k;
 while ((i < 128) & (vline[i][0] > 0))
  i++;
 if (i == 128)
  i = random128();
 for (k = 0; k < 16; k++)
  vline[i][k] = newvline[k];
}

canonical_original_code:
extern void SpawnLine() {
 unsigned char i = 0; unsigned char k;
 while ((i < 128) & (vline[i][0] > 0))
  i++;
 if (i == 128)
  i = random128();
 for (k = 0; k < 16; k++)
  vline[i][k] = newvline[k];
}

variable_types:
i
unsigned char


ProcBullets

decompiled_code:
void ProcBullets()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
extern void ProcBullets(void) {
}

canonical_original_code:
extern void ProcBullets() {
}


SpawnBullet

decompiled_code:
void SpawnBullet()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
extern void SpawnBullet(void) {
}

canonical_original_code:
extern void SpawnBullet() {
}


GameStep

decompiled_code:
__int64 GameStep()
{
PlayerIteraction();
RenderMap();
RenderCursor();
RenderObjects();
return RenderGameGUI();
}

canonical_decompiled_code:
__int64 func0()
{
PlayerIteraction();
RenderMap();
RenderCursor();
RenderObjects();
return RenderGameGUI();
}

original_code:
void GameStep(void) {
 PlayerIteraction();
 RenderMap();
 RenderCursor();
 RenderObjects();
 RenderGameGUI();
}

canonical_original_code:
void GameStep() {
 PlayerIteraction();
 RenderMap();
 RenderCursor();
 RenderObjects();
 RenderGameGUI();
}


ProcGameMainMenu

original_code:
void ProcGameMainMenu(void) {
 Sint32 x, y, i, xx, yy, k, l;
 for (i = 1; i < 16; i++) {
  x = 1;
  y = 20 + (count + i * 15) % 210;
  xx = 318;
  yy = 10 + (count * 3 + i * 11) % 200;
  DrawLine2(x, y, xx, yy, 7);
 }
 i = count % 1024;
 y = cbrd[0];
 k = count;
 l = 40 * f_sin[(count * 10) % 2096] / 65536;
 for (x = 0; x < 320; x++) {
  i = (((x + k) / 20) + 1) % 32;
  if (y < cbrd[i] + l)
   y++;
  else if (y > cbrd[i] + l)
   y--;
  xx = y * 320 + x;
  for (yy = y; yy > 0; yy--) {
   scrbuf[xx] = 14;
   scrbuf[76799 - xx] = 8;
   xx -= 320;
  }
 }
 y = cbrd1[0];
 k = count * 2;
 for (x = 0; x < 320; x++) {
  i = (((x + k) / 20) + 1) % 32;
  if (y < cbrd1[i])
   y++;
  else if (y > cbrd1[i])
   y--;
  xx = y * 320 + x;
  for (yy = y; yy > 0; yy--) {
   scrbuf[xx] = 0;
   scrbuf[76799 - xx] = 0;
   xx -= 320;
  }
 }
 Uint8 c;
 if ((count / 16) % 2 == 0)
  c = count / 4 % 4;
 else
  c = 4 - count / 4 % 4;
 DarkRect(160 - c, 100 - c, 310 + c, 200 + c);
 DarkRect(0, 0, 320, 30);
 DarkRect(0, 220, 320, 239);
 DrawRect(160 - c, 100 - c, 310 + c, 200 + c, 15);
 DrawRect(0, 0, 320, 30, 15);
 DrawRect(0, 220, 320, 239, 15);
 l_textstring = sprintf(s_textstring, "Linux version    ""20-Apr-2024");
 s_drawtext(32, 222, 15);
 l_textstring = sprintf(s_textstring, "WORSHIP VECTOR       by Quasist");
 s_drawtext(32, 6, 15);
 DarkRect(0, 104 + mmitem * 16, 319, 120 + mmitem * 16);
 for (i = 0; i < 6; i++) {
  l_textstring = sprintf(s_textstring, "%s", mmtt[i]);
  s_drawtext(170, 104 + i * 16, 15);
 }
 switch (gamespeed) {
 case 0:
  l_textstring = sprintf(s_textstring, "++++");
  break;
 case 1:
  l_textstring = sprintf(s_textstring, "+++.");
  break;
 case 2:
  l_textstring = sprintf(s_textstring, "++..");
  break;
 case 3:
  l_textstring = sprintf(s_textstring, "+...");
  break;
 }
 s_drawtext(258, 168, 14);
 DrawRect(162 - c, 104 + mmitem * 16, 308 + c, 120 + mmitem * 16, 14);
 dpadi = 0;
 if (olddpad2 != dpad) {
  if (dpad >= 0) {
   dpadi = 1;
  }
 } else {
  dpadi = 2;
 }
 olddpad2 = dpad;
 if (dpadi == 1) {
  if ((dpad == 4)) {
   mmitem = (mmitem + 1) % 6;
   PlaySound(0, 0);
   zl_vibro = 64;
  } else {
   if ((dpad == 0)) {
    if (mmitem) {
     mmitem = (mmitem - 1);
    } else {
     mmitem = 5;
    }
    PlaySound(0, 0);
    zl_vibro = 64;
   }
  }
 }
 if ((vbutton[0] == 1) | (vbutton[2] == 1) | (vbutton[8] == 1))
  switch (mmitem) {
  case 0:
   NextGameMode = 5;
   ResetMap();
   cursormode = 0;
   break;
  case 4:
   gamespeed = (gamespeed + 1) % 4;
   break;
  case 5:
   NextGameMode = 6;
   break;
  }
}

canonical_original_code:
void ProcGameMainMenu() {
 int x; int y; int i; int xx; int yy; int k; int l;
 for (i = 1; i < 16; i++) {
  x = 1;
  y = 20 + (count + i * 15) % 210;
  xx = 318;
  yy = 10 + (count * 3 + i * 11) % 200;
  DrawLine2(x, y, xx, yy, 7);
 }
 i = count % 1024;
 y = cbrd[0];
 k = count;
 l = 40 * f_sin[(count * 10) % 2096] / 65536;
 for (x = 0; x < 320; x++) {
  i = (((x + k) / 20) + 1) % 32;
  if (y < cbrd[i] + l)
   y++;
  else if (y > cbrd[i] + l)
   y--;
  xx = y * 320 + x;
  for (yy = y; yy > 0; yy--) {
   scrbuf[xx] = 14;
   scrbuf[76799 - xx] = 8;
   xx -= 320;
  }
 }
 y = cbrd1[0];
 k = count * 2;
 for (x = 0; x < 320; x++) {
  i = (((x + k) / 20) + 1) % 32;
  if (y < cbrd1[i])
   y++;
  else if (y > cbrd1[i])
   y--;
  xx = y * 320 + x;
  for (yy = y; yy > 0; yy--) {
   scrbuf[xx] = 0;
   scrbuf[76799 - xx] = 0;
   xx -= 320;
  }
 }
 unsigned char c;
 if ((count / 16) % 2 == 0)
  c = count / 4 % 4;
 else
  c = 4 - count / 4 % 4;
 DarkRect(160 - c, 100 - c, 310 + c, 200 + c);
 DarkRect(0, 0, 320, 30);
 DarkRect(0, 220, 320, 239);
 DrawRect(160 - c, 100 - c, 310 + c, 200 + c, 15);
 DrawRect(0, 0, 320, 30, 15);
 DrawRect(0, 220, 320, 239, 15);
 l_textstring = sprintf(s_textstring, "Linux version    ""20-Apr-2024");
 s_drawtext(32, 222, 15);
 l_textstring = sprintf(s_textstring, "WORSHIP VECTOR       by Quasist");
 s_drawtext(32, 6, 15);
 DarkRect(0, 104 + mmitem * 16, 319, 120 + mmitem * 16);
 for (i = 0; i < 6; i++) {
  l_textstring = sprintf(s_textstring, "%s", mmtt[i]);
  s_drawtext(170, 104 + i * 16, 15);
 }
 switch (gamespeed) {
 case 0:
  l_textstring = sprintf(s_textstring, "++++");
  break;
 case 1:
  l_textstring = sprintf(s_textstring, "+++.");
  break;
 case 2:
  l_textstring = sprintf(s_textstring, "++..");
  break;
 case 3:
  l_textstring = sprintf(s_textstring, "+...");
  break;
 }
 s_drawtext(258, 168, 14);
 DrawRect(162 - c, 104 + mmitem * 16, 308 + c, 120 + mmitem * 16, 14);
 dpadi = 0;
 if (olddpad2 != dpad) {
  if (dpad >= 0) {
   dpadi = 1;
  }
 } else {
  dpadi = 2;
 }
 olddpad2 = dpad;
 if (dpadi == 1) {
  if ((dpad == 4)) {
   mmitem = (mmitem + 1) % 6;
   PlaySound(0, 0);
   zl_vibro = 64;
  } else {
   if ((dpad == 0)) {
    if (mmitem) {
     mmitem = (mmitem - 1);
    } else {
     mmitem = 5;
    }
    PlaySound(0, 0);
    zl_vibro = 64;
   }
  }
 }
 if ((vbutton[0] == 1) | (vbutton[2] == 1) | (vbutton[8] == 1))
  switch (mmitem) {
  case 0:
   NextGameMode = 5;
   ResetMap();
   cursormode = 0;
   break;
  case 4:
   gamespeed = (gamespeed + 1) % 4;
   break;
  case 5:
   NextGameMode = 6;
   break;
  }
}

variable_types: x int

variable_types: y int

variable_types: xx int

variable_types: yy int

variable_types: k int

variable_types: l int

variable_types:
c
unsigned char


ResetMap

variable_types:
x
unsigned char

variable_types:
y
unsigned char


InitPalette

variable_types:
i
unsigned int

variable_types:
colors
unsigned int


PostRender

decompiled_code:
char *PostRender()
{
char *result; // rax
__int64 v1; // rdx

zlclearscene();
if ( !screenblend )
return (char *)memset(&scrbuf, 0, 0x12C00uLL);
result = 0LL;
do
{
v1 = *((unsigned __int8 *)&scrbuf + (_QWORD)result++);
result[(_QWORD)&scrbuf - 1] = *((_BYTE *)&NextColor0 + v1);
}
while ( result != (char *)76800 );
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax
__int64 v1; // rdx

zlclearscene();
if ( !screenblend )
return (char *)memset(&scrbuf, 0, 0x12C00uLL);
result = 0LL;
do
{
v1 = *((unsigned __int8 *)&scrbuf + (_QWORD)result++);
result[(_QWORD)&scrbuf - 1] = *((_BYTE *)&NextColor0 + v1);
}
while ( result != (char *)76800 );
return result;
}

original_code:
void PostRender(void) {
 U32 x, y, i;
 zlclearscene();
 if (volumedelay) {
 }
 if (screenblend == 0)
  for (i = 0; i < 76800; i++) {
   scrbuf[i] = 0;
  }
 else
  for (i = 0; i < 76800; i++) {
   scrbuf[i] = NextColor0[scrbuf[i]];
  }
}

canonical_original_code:
void PostRender() {
 unsigned long x; unsigned long y; unsigned long i;
 zlclearscene();
 if (volumedelay) {
 }
 if (screenblend == 0)
  for (i = 0; i < 76800; i++) {
   scrbuf[i] = 0;
  }
 else
  for (i = 0; i < 76800; i++) {
   scrbuf[i] = NextColor0[scrbuf[i]];
  }
}

variable_types:
x
unsigned long

variable_types:
y
unsigned long

variable_types:
i
unsigned long


ProcGameState

decompiled_code:
__int64 ProcGameState()
{
__int64 result; // rax
__int64 v1; // rax
__m128i v2; // xmm0
__m128i v3; // xmm0

switch ( GameMode )
{
case 5:
GameStep();
break;
case 6:
v1 = 3435973837LL * count;
if ( !_bittest64(&v1, 0x24u) )
{
v3 = _mm_load_si128((const __m128i *)&LC0);
*((_WORD *)&s_textstring + 8) = 18254;
s_textstring = v3;
*((_BYTE *)&s_textstring + 18) = 0;
l_textstring = 18;
s_drawtext(80LL, 120LL, 15LL);
}
v2 = _mm_load_si128((const __m128i *)&LC1);
*((_QWORD *)&s_textstring + 2) = 0x2E2E2E5449584520LL;
s_textstring = v2;
*((_BYTE *)&s_textstring + 24) = 0;
l_textstring = 24;
s_drawtext(120LL, 222LL, 15LL);
s_textstring = _mm_load_si128((const __m128i *)&LC2);
*((__m128i *)&s_textstring + 1) = _mm_load_si128((const __m128i *)&LC3);
s_drawtext(32LL, 6LL, 15LL);
DrawRect(0LL, 0LL, 320LL, 30LL, 15LL);
DrawRect(60LL, 100LL, 260LL, 150LL, 15LL);
if ( buttonpressed == 1 )
GameLoopEnabled = 0;
break;
case 4:
ProcGameMainMenu();
break;
}
result = NextGameMode;
GameMode = NextGameMode;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rax
__m128i v2; // xmm0
__m128i v3; // xmm0

switch ( GameMode )
{
case 5:
GameStep();
break;
case 6:
v1 = 3435973837LL * count;
if ( !_bittest64(&v1, 0x24u) )
{
v3 = _mm_load_si128((const __m128i *)&LC0);
*((_WORD *)&s_textstring + 8) = 18254;
s_textstring = v3;
*((_BYTE *)&s_textstring + 18) = 0;
l_textstring = 18;
s_drawtext(80LL, 120LL, 15LL);
}
v2 = _mm_load_si128((const __m128i *)&LC1);
*((_QWORD *)&s_textstring + 2) = 0x2E2E2E5449584520LL;
s_textstring = v2;
*((_BYTE *)&s_textstring + 24) = 0;
l_textstring = 24;
s_drawtext(120LL, 222LL, 15LL);
s_textstring = _mm_load_si128((const __m128i *)&LC2);
*((__m128i *)&s_textstring + 1) = _mm_load_si128((const __m128i *)&LC3);
s_drawtext(32LL, 6LL, 15LL);
DrawRect(0LL, 0LL, 320LL, 30LL, 15LL);
DrawRect(60LL, 100LL, 260LL, 150LL, 15LL);
if ( buttonpressed == 1 )
GameLoopEnabled = 0;
break;
case 4:
ProcGameMainMenu();
break;
}
result = NextGameMode;
GameMode = NextGameMode;
return result;
}

original_code:
void ProcGameState(void) {
 switch (GameMode) {
 case 0:
  break;
 case 1:
  break;
 case 2:
  break;
 case 3:
  break;
 case 4:
  ProcGameMainMenu();
  break;
 case 5:
  GameStep();
  break;
 case 6:
  if (count / 20 % 2 == 0) {
   l_textstring = sprintf(s_textstring, "THANKS FOR PLAYING");
   s_drawtext(80, 120, 15);
  }
  l_textstring = sprintf(s_textstring, "PRESS ANY KEY TO EXIT...");
  s_drawtext(120, 222, 15);
  l_textstring = sprintf(s_textstring, "WORSHIP VECTOR       by Quasist");
  s_drawtext(32, 6, 15);
  DrawRect(0, 0, 320, 30, 15);
  DrawRect(60, 100, 260, 150, 15);
  if (buttonpressed == 1)
   GameLoopEnabled = 0;
  break;
 case 7:
  break;
 }
 GameMode = NextGameMode;
}

canonical_original_code:
void ProcGameState() {
 switch (GameMode) {
 case 0:
  break;
 case 1:
  break;
 case 2:
  break;
 case 3:
  break;
 case 4:
  ProcGameMainMenu();
  break;
 case 5:
  GameStep();
  break;
 case 6:
  if (count / 20 % 2 == 0) {
   l_textstring = sprintf(s_textstring, "THANKS FOR PLAYING");
   s_drawtext(80, 120, 15);
  }
  l_textstring = sprintf(s_textstring, "PRESS ANY KEY TO EXIT...");
  s_drawtext(120, 222, 15);
  l_textstring = sprintf(s_textstring, "WORSHIP VECTOR       by Quasist");
  s_drawtext(32, 6, 15);
  DrawRect(0, 0, 320, 30, 15);
  DrawRect(60, 100, 260, 150, 15);
  if (buttonpressed == 1)
   GameLoopEnabled = 0;
  break;
 case 7:
  break;
 }
 GameMode = NextGameMode;
}


GameFrame

decompiled_code:
__int64 GameFrame()
{
PostRender();
return ProcGameState();
}

canonical_decompiled_code:
__int64 func0()
{
PostRender();
return ProcGameState();
}

original_code:
void GameFrame(void) {
 PostRender();
 ProcGameState();
}

canonical_original_code:
void GameFrame() {
 PostRender();
 ProcGameState();
}


PutChar

repo: JohnnyonFlame/textlauncher

decompiled_code:
unsigned __int64 __fastcall PutChar(__int64 a1, int a2)
{
int v2; // ecx
unsigned __int64 result; // rax
_BYTE *v4; // rdx

if ( a2 == 8 )
{
result = (unsigned int)(cur_x - 1);
if ( (result & 0x80000000) != 0LL )
result = 0LL;
cur_x = result;
}
else if ( a2 == 10
|| (v2 = 2 * cur_x,
++cur_x,
result = (unsigned int)cur_x,
v4 = (_BYTE *)(a1 + v2 + (__int64)(160 * cur_y)),
LOBYTE(v2) = fgcolor | (16 * bgcolor),
*v4 = a2,
v4[1] = v2,
(int)result > 79) )
{
result = (unsigned __int64)NewLine(a1);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, int a2)
{
int v2; // ecx
unsigned __int64 result; // rax
_BYTE *v4; // rdx

if ( a2 == 8 )
{
result = (unsigned int)(cur_x - 1);
if ( (result & 0x80000000) != 0LL )
result = 0LL;
cur_x = result;
}
else if ( a2 == 10
|| (v2 = 2 * cur_x,
++cur_x,
result = (unsigned int)cur_x,
v4 = (_BYTE *)(a1 + v2 + (__int64)(160 * cur_y)),
LOBYTE(v2) = fgcolor | (16 * bgcolor),
*v4 = a2,
v4[1] = v2,
(int)result > 79) )
{
result = (unsigned __int64)NewLine(a1);
}
return result;
}

original_code:
static void PutChar(unsigned char *screendata, int c)
{
    unsigned char *p;
    p = screendata + cur_y * 80 * 2 + cur_x * 2;
    switch (c)
    {
        case '\n':
            NewLine(screendata);
            break;
        case '\b':
            --cur_x;
            if (cur_x < 0)
                cur_x = 0;
            break;
        default:
            p[0] = c;
            p[1] = fgcolor | (bgcolor << 4);
            ++cur_x;
            if (cur_x >= 80)
            {
                NewLine(screendata);
            }
            break;
    }
}

variable_types:
screendata
unsigned char *

variable_types: c int

variable_types:
p
unsigned char *


decompiled_code:
unsigned __int64 __fastcall TXT_PutChar(int a1)
{
__int64 v1; // rax

v1 = TXT_GetScreenData();
return PutChar(v1, a1);
}

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

v1 = TXT_GetScreenData();
return func0(v1, a1);
}

original_code:
void TXT_PutChar(int c)
{
    unsigned char *screen;
    screen = TXT_GetScreenData();
    PutChar(screen, c);
}

variable_types:
screen
unsigned char *


decompiled_code:
unsigned __int64 __fastcall TXT_Puts(char *a1)
{
_BYTE *v1; // rbx
__int64 v2; // rax
int v3; // esi
__int64 i; // r9

v1 = a1;
v2 = TXT_GetScreenData();
v3 = *a1;
for ( i = v2; *v1; v3 = (char)*v1 )
{
++v1;
PutChar(i, v3);
}
return PutChar(i, 10);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(char *a1)
{
_BYTE *v1; // rbx
__int64 v2; // rax
int v3; // esi
__int64 i; // r9

v1 = a1;
v2 = TXT_GetScreenData();
v3 = *a1;
for ( i = v2; *v1; v3 = (char)*v1 )
{
++v1;
func0(i, v3);
}
return func0(i, 10);
}

original_code:
void TXT_Puts(const char *s)
{
    unsigned char *screen;
    const char *p;
    screen = TXT_GetScreenData();
    for (p=s; *p != '\0'; ++p)
    {
        PutChar(screen, *p);
    }
    PutChar(screen, '\n');
}

canonical_original_code:
void TXT_Puts(char *s)
{
    unsigned char *screen;
    char *p;
    screen = TXT_GetScreenData();
    for (p=s; *p != '\0'; ++p)
    {
        PutChar(screen, *p);
    }
    PutChar(screen, '\n');
}

variable_types:
s
char *

variable_types:
p
char *


decompiled_code:
void __fastcall TXT_GotoXY(int a1, int a2)
{
cur_x = a1;
cur_y = a2;
}

canonical_decompiled_code:
void __fastcall func3(int a1, int a2)
{
cur_x = a1;
cur_y = a2;
}

original_code:
void TXT_GotoXY(int x, int y)
{
    cur_x = x;
    cur_y = y;
}

variable_types: x int

variable_types: y int


decompiled_code:
void __fastcall TXT_FGColor(int a1)
{
fgcolor = a1;
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
fgcolor = a1;
}

original_code:
void TXT_FGColor(txt_color_t color)
{
    fgcolor = color;
}

canonical_original_code:
void TXT_FGColor(enum txt_color_t color)
{
    fgcolor = color;
}

variable_types: enum txt_color_t { TXT_COLOR_BLACK=0, TXT_COLOR_BLUE=1, TXT_COLOR_GREEN=2, TXT_COLOR_CYAN=3, TXT_COLOR_RED=4, TXT_COLOR_MAGENTA=5, TXT_COLOR_BROWN=6, TXT_COLOR_GREY=7, TXT_COLOR_DARK_GREY=8, TXT_COLOR_BRIGHT_BLUE=9, TXT_COLOR_BRIGHT_GREEN=10, TXT_COLOR_BRIGHT_CYAN=11, TXT_COLOR_BRIGHT_RED=12, TXT_COLOR_BRIGHT_MAGENTA=13, TXT_COLOR_YELLOW=14, TXT_COLOR_BRIGHT_WHITE=15 }


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

result = a1 | 8u;
if ( a2 )
a1 |= 8u;
bgcolor = a1;
return result;
}

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

result = a1 | 8u;
if ( a2 )
a1 |= 8u;
bgcolor = a1;
return result;
}

original_code:
void TXT_BGColor(int color, int blinking)
{
    bgcolor = color;
    if (blinking)
        bgcolor |= (1 << 3);
}

variable_types: color int

variable_types: blinking int


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

bgcolor = *(_DWORD *)a1;
result = *(unsigned int *)(a1 + 4);
fgcolor = *(_DWORD *)(a1 + 4);
return result;
}

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

bgcolor = *(_DWORD *)a1;
result = *(unsigned int *)(a1 + 4);
fgcolor = *(_DWORD *)(a1 + 4);
return result;
}

original_code:
void TXT_RestoreColors(txt_saved_colors_t *save)
{
    bgcolor = save->bgcolor;
    fgcolor = save->fgcolor;
}

canonical_original_code:
void TXT_RestoreColors(struct txt_saved_colors_t *save)
{
    bgcolor = save->bgcolor;
    fgcolor = save->fgcolor;
}

variable_types: struct txt_saved_colors_t { int bgcolor; int fgcolor; } *


decompiled_code:
_BYTE *TXT_ClearScreen()
{
_BYTE *result; // rax
_BYTE *v1; // rcx
char v2; // dl

result = (_BYTE *)TXT_GetScreenData();
v1 = result + 4000;
v2 = fgcolor | (16 * bgcolor);
do
{
*result = 32;
result += 2;
*(result - 1) = v2;
}
while ( result != v1 );
cur_x = 0;
cur_y = 0;
return result;
}

canonical_decompiled_code:
_BYTE *func9()
{
_BYTE *result; // rax
_BYTE *v1; // rcx
char v2; // dl

result = (_BYTE *)TXT_GetScreenData();
v1 = result + 4000;
v2 = fgcolor | (16 * bgcolor);
do
{
*result = 32;
result += 2;
*(result - 1) = v2;
}
while ( result != v1 );
cur_x = 0;
cur_y = 0;
return result;
}

original_code:
void TXT_ClearScreen(void)
{
    unsigned char *screen;
    int i;
    screen = TXT_GetScreenData();
    for (i=0; i<80 * 25; ++i)
    {
        screen[i * 2] = ' ';
        screen[i * 2 + 1] = (bgcolor << 4) | fgcolor;
    }
    cur_x = 0;
    cur_y = 0;
}

canonical_original_code:
void TXT_ClearScreen()
{
    unsigned char *screen;
    int i;
    screen = TXT_GetScreenData();
    for (i=0; i<80 * 25; ++i)
    {
        screen[i * 2] = ' ';
        screen[i * 2 + 1] = (bgcolor << 4) | fgcolor;
    }
    cur_x = 0;
    cur_y = 0;
}

variable_types: i int


decompiled_code:
_QWORD *TXT_NewCallbackTable()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
*(_DWORD *)result = 1;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
*(_DWORD *)result = 1;
return result;
}

original_code:
txt_callback_table_t *TXT_NewCallbackTable(void)
{
    txt_callback_table_t *table;
    table = malloc(sizeof(txt_callback_table_t));
    table->callbacks = ((void *)0);
    table->num_callbacks = 0;
    table->refcount = 1;
    return table;
}

canonical_original_code:
struct txt_callback_table_s *TXT_NewCallbackTable()
{
    struct txt_callback_table_s *table;
    table = malloc(sizeof(txt_callback_table_t));
    table->callbacks = ((void *)0);
    table->num_callbacks = 0;
    table->refcount = 1;
    return table;
}

variable_types: struct txt_callback_table_s { int refcount; struct txt_callback_t { char *signal_name; void (*func)(void *uncast_widget, void *user_data); void *user_data; } *callbacks; int num_callbacks; } *

user_defined_types: struct txt_callback_table_s { int refcount; struct txt_callback_t *callbacks; int num_callbacks; }


decompiled_code:
void __fastcall TXT_UnrefCallbackTable(void *ptr)
{
__int64 v2; // rbx
__int64 v3; // rax

if ( (*(_DWORD *)ptr)-- == 1 )
{
if ( *((int *)ptr + 4) > 0 )
{
v2 = 0LL;
do
{
v3 = 3 * v2++;
free(*(void **)(*((_QWORD *)ptr + 1) + 8 * v3));
}
while ( *((_DWORD *)ptr + 4) > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void TXT_UnrefCallbackTable(txt_callback_table_t *table)
{
    int i;
    --table->refcount;
    if (table->refcount == 0)
    {
        for (i=0; i<table->num_callbacks; ++i)
        {
            free(table->callbacks[i].signal_name);
        }
        free(table->callbacks);
        free(table);
    }
}

canonical_original_code:
void TXT_UnrefCallbackTable(struct txt_callback_table_s *table)
{
    int i;
    --table->refcount;
    if (table->refcount == 0)
    {
        for (i=0; i<table->num_callbacks; ++i)
        {
            free(table->callbacks[i].signal_name);
        }
        free(table->callbacks);
        free(table);
    }
}

user_defined_types: struct txt_callback_t { char *signal_name; void (*func)(void *uncast_widget, void *user_data); void *user_data; }


decompiled_code:
char *__fastcall TXT_SignalConnect(__int64 a1, const char *a2, char *a3, char *a4)
{
__int64 v6; // rbx
char *v7; // rax
__int64 v8; // rcx
char **v9; // rbp
char *result; // rax

v6 = *(_QWORD *)(a1 + 8);
v7 = (char *)realloc(*(void **)(v6 + 8), 24LL * (*(_DWORD *)(v6 + 16) + 1));
v8 = *(int *)(v6 + 16);
*(_QWORD *)(v6 + 8) = v7;
v9 = (char **)&v7[24 * v8];
*(_DWORD *)(v6 + 16) = v8 + 1;
result = strdup(a2);
v9[1] = a3;
*v9 = result;
v9[2] = a4;
return result;
}

original_code:
void TXT_SignalConnect(void * uncast_widget,
                       const char *signal_name,
                       TxtWidgetSignalFunc func,
                       void *user_data)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    txt_callback_table_t *table;
    txt_callback_t *callback;
    table = widget->callback_table;
    table->callbacks
            = realloc(table->callbacks,
                      sizeof(txt_callback_t) * (table->num_callbacks + 1));
    callback = &table->callbacks[table->num_callbacks];
    ++table->num_callbacks;
    callback->signal_name = strdup(signal_name);
    callback->func = func;
    callback->user_data = user_data;
}

canonical_original_code:
void TXT_SignalConnect(void *uncast_widget, char *signal_name, void (*func)(void *uncast_widget, void *user_data), void *user_data)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    struct txt_callback_table_s *table;
    struct txt_callback_t *callback;
    table = widget->callback_table;
    table->callbacks
            = realloc(table->callbacks,
                      sizeof(txt_callback_t) * (table->num_callbacks + 1));
    callback = &table->callbacks[table->num_callbacks];
    ++table->num_callbacks;
    callback->signal_name = strdup(signal_name);
    callback->func = func;
    callback->user_data = user_data;
}

variable_types: void (*)(void *uncast_widget, void *user_data)

variable_types: struct txt_widget_s { struct txt_widget_class_s { int (*selectable)(void *uncast_widget); void (*size_calc)(void *uncast_widget); void (*drawer)(void *uncast_widget); int (*key_press)(void *uncast_widget, int key); void (*destructor)(void *uncast_widget); void (*mouse_press)(void *uncast_widget, int x, int y, int b); void (*layout)(void *uncast_widget); void (*focus_change)(void *uncast_widget, int focused); } *widget_class; struct txt_callback_table_s { int refcount; struct txt_callback_t { char *signal_name; void (*func)(void *uncast_widget, void *user_data); void *user_data; } *callbacks; int num_callbacks; } *callback_table; int visible; enum txt_horiz_align_t { TXT_HORIZ_LEFT=0, TXT_HORIZ_CENTER=1, TXT_HORIZ_RIGHT=2 } align; int focused; int x; unsigned int w; struct txt_widget_s *parent; } *

user_defined_types: struct txt_widget_s { struct txt_widget_class_s *widget_class; struct txt_callback_table_s *callback_table; int visible; enum txt_horiz_align_t align; int focused; int x; unsigned int w; struct txt_widget_s *parent; }


decompiled_code:
void __fastcall TXT_EmitSignal(__int64 a1, const char *a2)
{
__int64 v2; // r14
__int64 v3; // rbx
__int64 v4; // rbp

v2 = *(_QWORD *)(a1 + 8);
TXT_RefCallbackTable((_DWORD *)v2);
if ( *(int *)(v2 + 16) > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(v2 + 8) + 24 * v3;
if ( !strcmp(*(const char **)v4, a2) )
(*(void (__fastcall **)(__int64, _QWORD))(v4 + 8))(a1, *(_QWORD *)(v4 + 16));
++v3;
}
while ( *(_DWORD *)(v2 + 16) > (int)v3 );
}
TXT_UnrefCallbackTable((void *)v2);
}

original_code:
void TXT_EmitSignal(void * uncast_widget, const char *signal_name)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    txt_callback_table_t *table;
    int i;
    table = widget->callback_table;
    TXT_RefCallbackTable(table);
    for (i=0; i<table->num_callbacks; ++i)
    {
        if (!strcmp(table->callbacks[i].signal_name, signal_name))
        {
            table->callbacks[i].func(widget, table->callbacks[i].user_data);
        }
    }
    TXT_UnrefCallbackTable(table);
}

canonical_original_code:
void TXT_EmitSignal(void *uncast_widget, char *signal_name)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    struct txt_callback_table_s *table;
    int i;
    table = widget->callback_table;
    TXT_RefCallbackTable(table);
    for (i=0; i<table->num_callbacks; ++i)
    {
        if (!strcmp(table->callbacks[i].signal_name, signal_name))
        {
            table->callbacks[i].func(widget, table->callbacks[i].user_data);
        }
    }
    TXT_UnrefCallbackTable(table);
}

user_defined_types: enum txt_horiz_align_t { TXT_HORIZ_LEFT=0, TXT_HORIZ_CENTER=1, TXT_HORIZ_RIGHT=2 }

user_defined_types: struct txt_widget_class_s { int (*selectable)(void *uncast_widget); void (*size_calc)(void *uncast_widget); void (*drawer)(void *uncast_widget); int (*key_press)(void *uncast_widget, int key); void (*destructor)(void *uncast_widget); void (*mouse_press)(void *uncast_widget, int x, int y, int b); void (*layout)(void *uncast_widget); void (*focus_change)(void *uncast_widget, int focused); }


decompiled_code:
__int64 __fastcall TXT_CalcWidgetSize(__int64 a1)
{
return (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)a1 + 8LL))(a1);
}

original_code:
void TXT_CalcWidgetSize(void * uncast_widget)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    widget->widget_class->size_calc(widget);
}

canonical_original_code:
void TXT_CalcWidgetSize(void *uncast_widget)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    widget->widget_class->size_calc(widget);
}


decompiled_code:
__int64 __fastcall TXT_DrawWidget(unsigned int *a1)
{
char v3[16]; // [rsp+8h] [rbp-10h] BYREF

TXT_SaveColors(v3);
TXT_GotoXY(a1[7], a1[8]);
(*(void (__fastcall **)(unsigned int *))(*(_QWORD *)a1 + 16LL))(a1);
return TXT_RestoreColors(v3);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
char v3[16]; // [rsp+8h] [rbp-10h] BYREF

TXT_SaveColors(v3);
TXT_GotoXY(a1[7], a1[8]);
(*(void (__fastcall **)(unsigned int *))(*(_QWORD *)a1 + 16LL))(a1);
return TXT_RestoreColors(v3);
}

original_code:
void TXT_DrawWidget(void * uncast_widget)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    txt_saved_colors_t colors;
    TXT_SaveColors(&colors);
    TXT_GotoXY(widget->x, widget->y);
    widget->widget_class->drawer(widget);
    TXT_RestoreColors(&colors);
}

canonical_original_code:
void TXT_DrawWidget(void *uncast_widget)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    struct txt_saved_colors_t colors;
    TXT_SaveColors(&colors);
    TXT_GotoXY(widget->x, widget->y);
    widget->widget_class->drawer(widget);
    TXT_RestoreColors(&colors);
}

variable_types: struct txt_saved_colors_t { int bgcolor; int fgcolor; }


decompiled_code:
void __fastcall TXT_DestroyWidget(void *ptr)
{
(*(void (__fastcall **)(void *))(*(_QWORD *)ptr + 32LL))(ptr);
TXT_UnrefCallbackTable(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
(*(void (__fastcall **)(void *))(*(_QWORD *)ptr + 32LL))(ptr);
func2(*((void **)ptr + 1));
free(ptr);
}

original_code:
void TXT_DestroyWidget(void * uncast_widget)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    widget->widget_class->destructor(widget);
    TXT_UnrefCallbackTable(widget->callback_table);
    free(widget);
}

canonical_original_code:
void TXT_DestroyWidget(void *uncast_widget)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    widget->widget_class->destructor(widget);
    TXT_UnrefCallbackTable(widget->callback_table);
    free(widget);
}


decompiled_code:
__int64 __fastcall TXT_WidgetKeyPress(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = *(__int64 (**)(void))(*(_QWORD *)a1 + 24LL);
if ( v1 )
result = v1();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = *(__int64 (**)(void))(*(_QWORD *)a1 + 24LL);
if ( v1 )
result = v1();
else
result = 0LL;
return result;
}

original_code:
int TXT_WidgetKeyPress(void * uncast_widget, int key)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    if (widget->widget_class->key_press != ((void *)0))
    {
        return widget->widget_class->key_press(widget, key);
    }
    return 0;
}

canonical_original_code:
int TXT_WidgetKeyPress(void *uncast_widget, int key)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    if (widget->widget_class->key_press != ((void *)0))
    {
        return widget->widget_class->key_press(widget, key);
    }
    return 0;
}

variable_types: key int

return_type: int


original_code:
void TXT_SetWidgetFocus(void * uncast_widget, int focused)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    if (widget == ((void *)0))
    {
        return;
    }
    if (widget->focused != focused)
    {
        widget->focused = focused;
        if (widget->widget_class->focus_change != ((void *)0))
        {
            widget->widget_class->focus_change(widget, focused);
        }
    }
}

canonical_original_code:
void TXT_SetWidgetFocus(void *uncast_widget, int focused)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    if (widget == ((void *)0))
    {
        return;
    }
    if (widget->focused != focused)
    {
        widget->focused = focused;
        if (widget->widget_class->focus_change != ((void *)0))
        {
            widget->widget_class->focus_change(widget, focused);
        }
    }
}

variable_types: focused int


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

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

original_code:
void TXT_SetWidgetAlign(void * uncast_widget, txt_horiz_align_t horiz_align)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    widget->align = horiz_align;
}

canonical_original_code:
void TXT_SetWidgetAlign(void *uncast_widget, enum txt_horiz_align_t horiz_align)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    widget->align = horiz_align;
}

variable_types: enum txt_horiz_align_t { TXT_HORIZ_LEFT=0, TXT_HORIZ_CENTER=1, TXT_HORIZ_RIGHT=2 }


decompiled_code:
__int64 TXT_AlwaysSelectable()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func11()
{
return 1LL;
}

original_code:
int TXT_AlwaysSelectable(void * uncast_widget)
{
    return 1;
}

canonical_original_code:
int TXT_AlwaysSelectable(void *uncast_widget)
{
    return 1;
}


decompiled_code:
__int64 TXT_NeverSelectable()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
return 0LL;
}

original_code:
int TXT_NeverSelectable(void * uncast_widget)
{
    return 0;
}

canonical_original_code:
int TXT_NeverSelectable(void *uncast_widget)
{
    return 0;
}


decompiled_code:
__int64 __fastcall TXT_SelectableWidget(__int64 (***a1)(void))
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = **a1;
if ( v1 )
result = v1();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 (***a1)(void))
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = **a1;
if ( v1 )
result = v1();
else
result = 0LL;
return result;
}

original_code:
int TXT_SelectableWidget(void * uncast_widget)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    if (widget->widget_class->selectable != ((void *)0))
    {
        return widget->widget_class->selectable(widget);
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TXT_SelectableWidget(void *uncast_widget)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    if (widget->widget_class->selectable != ((void *)0))
    {
        return widget->widget_class->selectable(widget);
    }
    else
    {
        return 0;
    }
}


decompiled_code:
__int64 __fastcall TXT_ContainsWidget(__int64 a1, __int64 a2)
{
while ( 1 )
{
if ( !a2 )
return 0LL;
if ( a1 == a2 )
break;
a2 = *(_QWORD *)(a2 + 48);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
while ( 1 )
{
if ( !a2 )
return 0LL;
if ( a1 == a2 )
break;
a2 = *(_QWORD *)(a2 + 48);
}
return 1LL;
}

original_code:
int TXT_ContainsWidget(void * uncast_haystack, void * uncast_needle)
{
    txt_widget_t *haystack = (txt_widget_t *) uncast_haystack;
    txt_widget_t *needle = (txt_widget_t *) uncast_needle;
    while (needle != ((void *)0))
    {
        if (needle == haystack)
        {
            return 1;
        }
        needle = needle->parent;
    }
    return 0;
}

canonical_original_code:
int TXT_ContainsWidget(void *uncast_haystack, void *uncast_needle)
{
    struct txt_widget_s *haystack = (txt_widget_t *) uncast_haystack;
    struct txt_widget_s *needle = (txt_widget_t *) uncast_needle;
    while (needle != ((void *)0))
    {
        if (needle == haystack)
        {
            return 1;
        }
        needle = needle->parent;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall TXT_HoveringOverWidget(_DWORD *a1)
{
__int64 v1; // rax
__int64 result; // rax
signed int v3; // eax
signed int v4; // eax
unsigned int v5; // edx
unsigned int v6; // [rsp+8h] [rbp-10h] BYREF
unsigned int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = TXT_GetActiveWindow();
if ( !v1
|| !(unsigned int)TXT_ContainsWidget(v1, (__int64)a1)
|| (TXT_GetMousePosition(&v6, v7), v3 = a1[7], v3 > (int)v6)
|| a1[9] + v3 <= v6
|| (v4 = a1[8], v4 > (int)v7[0])
|| (v5 = a1[10] + v4, result = 1LL, v5 <= v7[0]) )
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(_DWORD *a1)
{
__int64 v1; // rax
__int64 result; // rax
signed int v3; // eax
signed int v4; // eax
unsigned int v5; // edx
unsigned int v6; // [rsp+8h] [rbp-10h] BYREF
unsigned int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = TXT_GetActiveWindow();
if ( !v1
|| !(unsigned int)func14(v1, (__int64)a1)
|| (TXT_GetMousePosition(&v6, v7), v3 = a1[7], v3 > (int)v6)
|| a1[9] + v3 <= v6
|| (v4 = a1[8], v4 > (int)v7[0])
|| (v5 = a1[10] + v4, result = 1LL, v5 <= v7[0]) )
{
result = 0LL;
}
return result;
}

original_code:
int TXT_HoveringOverWidget(void * uncast_widget)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    txt_window_t *active_window;
    int x, y;
    active_window = TXT_GetActiveWindow();
    if (active_window == ((void *)0) || !TXT_ContainsWidget(active_window, widget))
    {
        return 0;
    }
    TXT_GetMousePosition(&x, &y);
    return (x >= widget->x && x < widget->x + widget->w
         && y >= widget->y && y < widget->y + widget->h);
}

canonical_original_code:
int TXT_HoveringOverWidget(void *uncast_widget)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    struct txt_window_s *active_window;
    int x; int y;
    active_window = TXT_GetActiveWindow();
    if (active_window == ((void *)0) || !TXT_ContainsWidget(active_window, widget))
    {
        return 0;
    }
    TXT_GetMousePosition(&x, &y);
    return (x >= widget->x && x < widget->x + widget->w
         && y >= widget->y && y < widget->y + widget->h);
}

variable_types: struct txt_window_s { struct txt_table_s { struct txt_widget_s { struct txt_widget_class_s { int (*selectable)(void *uncast_widget); void (*size_calc)(void *uncast_widget); void (*drawer)(void *uncast_widget); int (*key_press)(void *uncast_widget, int key); void (*destructor)(void *uncast_widget); void (*mouse_press)(void *uncast_widget, int x, int y, int b); void (*layout)(void *uncast_widget); void (*focus_change)(void *uncast_widget, int focused); } *widget_class; struct txt_callback_table_s { int refcount; struct txt_callback_t { char *signal_name; void (*func)(void *uncast_widget, void *user_data); void *user_data; } *callbacks; int num_callbacks; } *callback_table; int visible; enum txt_horiz_align_t { TXT_HORIZ_LEFT=0, TXT_HORIZ_CENTER=1, TXT_HORIZ_RIGHT=2 } align; int focused; int x; unsigned int w; struct txt_widget_s *parent; } widget; struct txt_widget_s **widgets; int num_widgets; int columns; int selected_x; int selected_y; } table; char *title; enum txt_vert_align_t { TXT_VERT_TOP=0, TXT_VERT_CENTER=1, TXT_VERT_BOTTOM=2 } vert_align; enum txt_horiz_align_t { TXT_HORIZ_LEFT=0, TXT_HORIZ_CENTER=1, TXT_HORIZ_RIGHT=2 } horiz_align; int x; struct txt_window_action_s { struct txt_widget_s widget; char *label; int key; } *actions[3]; int (*key_listener)(struct txt_window_s *window, int key, void *user_data); void *key_listener_data; int (*mouse_listener)(struct txt_window_s *window, int x, int y, int b, void *user_data); void *mouse_listener_data; int window_x; unsigned int window_w; } *

user_defined_types: struct txt_window_s { struct txt_table_s table; char *title; enum txt_vert_align_t vert_align; enum txt_horiz_align_t horiz_align; int x; struct txt_window_action_s *actions[3]; int (*key_listener)(struct txt_window_s *window, int key, void *user_data); void *key_listener_data; int (*mouse_listener)(struct txt_window_s *window, int x, int y, int b, void *user_data); void *mouse_listener_data; int window_x; unsigned int window_w; }

user_defined_types: struct txt_table_s { struct txt_widget_s widget; struct txt_widget_s **widgets; int num_widgets; int columns; int selected_x; int selected_y; }


decompiled_code:
__int64 __fastcall TXT_SetWidgetBG(_DWORD *a1)
{
__int64 result; // rax

if ( a1[6] )
return TXT_BGColor(7LL, 0LL);
result = TXT_HoveringOverWidget(a1);
if ( (_DWORD)result )
result = TXT_BGColor(3LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(_DWORD *a1)
{
__int64 result; // rax

if ( a1[6] )
return TXT_BGColor(7LL, 0LL);
result = func15(a1);
if ( (_DWORD)result )
result = TXT_BGColor(3LL, 0LL);
return result;
}

original_code:
void TXT_SetWidgetBG(void * uncast_widget)
{
    txt_widget_t *widget = (txt_widget_t *) uncast_widget;
    if (widget->focused)
    {
        TXT_BGColor(TXT_COLOR_GREY, 0);
    }
    else if (TXT_HoveringOverWidget(widget))
    {
        TXT_BGColor(TXT_COLOR_CYAN, 0);
    }
    else
    {
    }
}

canonical_original_code:
void TXT_SetWidgetBG(void *uncast_widget)
{
    struct txt_widget_s *widget = (txt_widget_t *) uncast_widget;
    if (widget->focused)
    {
        TXT_BGColor(TXT_COLOR_GREY, 0);
    }
    else if (TXT_HoveringOverWidget(widget))
    {
        TXT_BGColor(TXT_COLOR_CYAN, 0);
    }
    else
    {
    }
}


PutUnicodeChar

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

v1 = 0LL;
v2 = 199;
if ( (unsigned int)a1 > 0x7F )
{
while ( 1 )
{
if ( v2 == (_DWORD)a1 )
return TXT_PutChar((unsigned int)(v1 + 128));
if ( ++v1 == 128 )
break;
v2 = (unsigned __int16)cp437_unicode[v1];
}
a1 = 4294967208LL;
}
return TXT_PutChar(a1);
}

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

v1 = 0LL;
v2 = 199;
if ( (unsigned int)a1 > 0x7F )
{
while ( 1 )
{
if ( v2 == (_DWORD)a1 )
return TXT_PutChar((unsigned int)(v1 + 128));
if ( ++v1 == 128 )
break;
v2 = (unsigned __int16)cp437_unicode[v1];
}
a1 = 4294967208LL;
}
return TXT_PutChar(a1);
}

original_code:
static void PutUnicodeChar(unsigned int c)
{
    unsigned int i;
    if (c < 128)
    {
        TXT_PutChar(c);
        return;
    }
    for (i = 0; i < 128; ++i)
    {
        if (cp437_unicode[i] == c)
        {
            TXT_PutChar(128 + i);
            return;
        }
    }
    TXT_PutChar('\xa8');
}

variable_types:
c
unsigned int

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall TXT_DrawShadow(unsigned int a1, int a2, int a3, int a4)
{
int v6; // ebp
__int64 result; // rax
int v9; // er8
_DWORD *v10; // rcx
int v11; // esi
__int64 v12; // rdi
__int64 v13; // rdx

v6 = a2;
result = TXT_GetScreenData();
v9 = a2 + a4;
if ( v6 < v6 + a4 )
{
v10 = cliparea;
v11 = a1 + a3;
v12 = result + (int)(2 * (a1 + 80 * v6));
do
{
v13 = v12;
result = a1;
if ( (int)a1 < v11 )
{
do
{
if ( *v10 <= (int)result && v10[1] > (int)result && v10[2] <= v6 && v10[3] > v6 )
*(_BYTE *)(v13 + 1) = 8;
result = (unsigned int)(result + 1);
v13 += 2LL;
}
while ( (_DWORD)result != v11 );
}
++v6;
v12 += 160LL;
}
while ( v6 != v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, int a3, int a4)
{
int v6; // ebp
__int64 result; // rax
int v9; // er8
_DWORD *v10; // rcx
int v11; // esi
__int64 v12; // rdi
__int64 v13; // rdx

v6 = a2;
result = TXT_GetScreenData();
v9 = a2 + a4;
if ( v6 < v6 + a4 )
{
v10 = cliparea;
v11 = a1 + a3;
v12 = result + (int)(2 * (a1 + 80 * v6));
do
{
v13 = v12;
result = a1;
if ( (int)a1 < v11 )
{
do
{
if ( *v10 <= (int)result && v10[1] > (int)result && v10[2] <= v6 && v10[3] > v6 )
*(_BYTE *)(v13 + 1) = 8;
result = (unsigned int)(result + 1);
v13 += 2LL;
}
while ( (_DWORD)result != v11 );
}
++v6;
v12 += 160LL;
}
while ( v6 != v9 );
}
return result;
}

original_code:
void TXT_DrawShadow(int x, int y, int w, int h)
{
    unsigned char *screendata;
    unsigned char *p;
    int x1, y1;
    screendata = TXT_GetScreenData();
    for (y1=y; y1<y+h; ++y1)
    {
        p = screendata + (y1 * 80 + x) * 2;
        for (x1=x; x1<x+w; ++x1)
        {
            if (((x1) >= cliparea->x1 && (x1) < cliparea->x2) && ((y1) >= cliparea->y1 && (y1) < cliparea->y2))
            {
                p[1] = TXT_COLOR_DARK_GREY;
            }
            p += 2;
        }
    }
}

canonical_original_code:
void TXT_DrawShadow(int x, int y, int w, int h)
{
    unsigned char *screendata;
    unsigned char *p;
    int x1; int y1;
    screendata = TXT_GetScreenData();
    for (y1=y; y1<y+h; ++y1)
    {
        p = screendata + (y1 * 80 + x) * 2;
        for (x1=x; x1<x+w; ++x1)
        {
            if (((x1) >= cliparea->x1 && (x1) < cliparea->x2) && ((y1) >= cliparea->y1 && (y1) < cliparea->y2))
            {
                p[1] = TXT_COLOR_DARK_GREY;
            }
            p += 2;
        }
    }
}

variable_types: x int

variable_types: w int

variable_types: h int

variable_types:
screendata
unsigned char *

variable_types:
p
unsigned char *


decompiled_code:
void *__fastcall TXT_DrawSeparator(unsigned int a1, unsigned int a2, int a3)
{
__int64 v4; // rbp
void *result; // rax
int v6; // er13
unsigned __int8 *v7; // rbp
signed int v8; // ebx
int v9; // eax
_DWORD *v10; // rdx
char v11[64]; // [rsp+8h] [rbp-40h] BYREF

v4 = TXT_GetScreenData();
TXT_SaveColors(v11);
TXT_FGColor(11LL);
result = cliparea;
if ( *((_DWORD *)cliparea + 2) <= (signed int)a2 && *((_DWORD *)cliparea + 3) > (signed int)a2 )
{
v6 = a1 + a3;
v7 = (unsigned __int8 *)((int)(2 * (a1 + 80 * a2)) + v4);
if ( (int)a1 < v6 )
{
v8 = a1;
TXT_GotoXY(a1, a2);
v9 = 0;
while ( 1 )
{
v10 = cliparea;
if ( *(_DWORD *)cliparea <= v8 )
{
LABEL_6:
if ( v10[1] > v8 && *v7 == dword_950[v9] )
TXT_PutChar((unsigned int)dword_960[v9]);
}
++v8;
v7 += 2;
if ( v8 == v6 )
break;
while ( 1 )
{
TXT_GotoXY((unsigned int)v8, a2);
v9 = 0;
if ( a1 == v8 )
break;
v10 = cliparea;
v9 = 2 * (v6 - 1 == v8) + 1;
if ( *(_DWORD *)cliparea <= v8 )
goto LABEL_6;
++v8;
v7 += 2;
if ( v8 == v6 )
goto LABEL_13;
}
}
}
LABEL_13:
result = (void *)TXT_RestoreColors(v11);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(unsigned int a1, unsigned int a2, int a3)
{
__int64 v4; // rbp
void *result; // rax
int v6; // er13
unsigned __int8 *v7; // rbp
signed int v8; // ebx
int v9; // eax
_DWORD *v10; // rdx
char v11[64]; // [rsp+8h] [rbp-40h] BYREF

v4 = TXT_GetScreenData();
TXT_SaveColors(v11);
TXT_FGColor(11LL);
result = cliparea;
if ( *((_DWORD *)cliparea + 2) <= (signed int)a2 && *((_DWORD *)cliparea + 3) > (signed int)a2 )
{
v6 = a1 + a3;
v7 = (unsigned __int8 *)((int)(2 * (a1 + 80 * a2)) + v4);
if ( (int)a1 < v6 )
{
v8 = a1;
TXT_GotoXY(a1, a2);
v9 = 0;
while ( 1 )
{
v10 = cliparea;
if ( *(_DWORD *)cliparea <= v8 )
{
LABEL_6:
if ( v10[1] > v8 && *v7 == dword_950[v9] )
TXT_PutChar((unsigned int)dword_960[v9]);
}
++v8;
v7 += 2;
if ( v8 == v6 )
break;
while ( 1 )
{
TXT_GotoXY((unsigned int)v8, a2);
v9 = 0;
if ( a1 == v8 )
break;
v10 = cliparea;
v9 = 2 * (v6 - 1 == v8) + 1;
if ( *(_DWORD *)cliparea <= v8 )
goto LABEL_6;
++v8;
v7 += 2;
if ( v8 == v6 )
goto LABEL_13;
}
}
}
LABEL_13:
result = (void *)TXT_RestoreColors(v11);
}
return result;
}

original_code:
void TXT_DrawSeparator(int x, int y, int w)
{
    txt_saved_colors_t colors;
    unsigned char *data;
    int x1;
    int b;
    data = TXT_GetScreenData();
    TXT_SaveColors(&colors);
    TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
    if (!((y) >= cliparea->y1 && (y) < cliparea->y2))
    {
        return;
    }
    data += (y * 80 + x) * 2;
    for (x1=x; x1<x+w; ++x1)
    {
        TXT_GotoXY(x1, y);
        b = x1 == x ? 0 :
            x1 == x + w - 1 ? 3 :
            1;
        if (((x1) >= cliparea->x1 && (x1) < cliparea->x2))
        {
            if (*data == borders[1][b])
            {
                TXT_PutChar(borders[2][b]);
            }
        }
        data += 2;
    }
    TXT_RestoreColors(&colors);
}

canonical_original_code:
void TXT_DrawSeparator(int x, int y, int w)
{
    struct txt_saved_colors_t colors;
    unsigned char *data;
    int x1;
    int b;
    data = TXT_GetScreenData();
    TXT_SaveColors(&colors);
    TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
    if (!((y) >= cliparea->y1 && (y) < cliparea->y2))
    {
        return;
    }
    data += (y * 80 + x) * 2;
    for (x1=x; x1<x+w; ++x1)
    {
        TXT_GotoXY(x1, y);
        b = x1 == x ? 0 :
            x1 == x + w - 1 ? 3 :
            1;
        if (((x1) >= cliparea->x1 && (x1) < cliparea->x2))
        {
            if (*data == borders[1][b])
            {
                TXT_PutChar(borders[2][b]);
            }
        }
        data += 2;
    }
    TXT_RestoreColors(&colors);
}

variable_types: y int

variable_types:
data
unsigned char *

variable_types: b int

user_defined_types: struct txt_saved_colors_t { int bgcolor; int fgcolor; }


decompiled_code:
__int64 __fastcall TXT_DrawString(char *s)
{
char *v1; // r12
int *v2; // rax
unsigned int v3; // er13
int v4; // ebx
char *v5; // rbp
__int64 v6; // rdi
int v7; // eax
int v9; // [rsp+8h] [rbp-30h] BYREF
int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = s;
TXT_GetXY(&v9, v10);
v2 = (int *)cliparea;
v3 = v10[0];
v4 = v9;
if ( *((_DWORD *)cliparea + 2) <= v10[0] && v10[0] < *((_DWORD *)cliparea + 3) && *s )
{
v5 = s;
while ( 1 )
{
if ( *v2 > v4 || v2[1] <= v4 )
{
++v5;
++v4;
if ( !*v5 )
goto LABEL_10;
}
else
{
v6 = (unsigned int)v4;
++v5;
++v4;
TXT_GotoXY(v6, v3);
TXT_PutChar((unsigned int)*(v5 - 1));
v3 = v10[0];
if ( !*v5 )
{
LABEL_10:
v4 = v9;
break;
}
}
v2 = (int *)cliparea;
}
}
v7 = strlen(v1);
return TXT_GotoXY((unsigned int)(v4 + v7), v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s)
{
char *v1; // r12
int *v2; // rax
unsigned int v3; // er13
int v4; // ebx
char *v5; // rbp
__int64 v6; // rdi
int v7; // eax
int v9; // [rsp+8h] [rbp-30h] BYREF
int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = s;
TXT_GetXY(&v9, v10);
v2 = (int *)cliparea;
v3 = v10[0];
v4 = v9;
if ( *((_DWORD *)cliparea + 2) <= v10[0] && v10[0] < *((_DWORD *)cliparea + 3) && *s )
{
v5 = s;
while ( 1 )
{
if ( *v2 > v4 || v2[1] <= v4 )
{
++v5;
++v4;
if ( !*v5 )
goto LABEL_10;
}
else
{
v6 = (unsigned int)v4;
++v5;
++v4;
TXT_GotoXY(v6, v3);
TXT_PutChar((unsigned int)*(v5 - 1));
v3 = v10[0];
if ( !*v5 )
{
LABEL_10:
v4 = v9;
break;
}
}
v2 = (int *)cliparea;
}
}
v7 = strlen(v1);
return TXT_GotoXY((unsigned int)(v4 + v7), v3);
}

original_code:
void TXT_DrawString(const char *s)
{
    int x, y;
    int x1;
    const char *p;
    TXT_GetXY(&x, &y);
    if (((y) >= cliparea->y1 && (y) < cliparea->y2))
    {
        x1 = x;
        for (p = s; *p != '\0'; ++p)
        {
            if (((x1) >= cliparea->x1 && (x1) < cliparea->x2))
            {
                TXT_GotoXY(x1, y);
                TXT_PutChar(*p);
            }
            x1 += 1;
        }
    }
    TXT_GotoXY(x + strlen(s), y);
}

canonical_original_code:
void TXT_DrawString(char *s)
{
    int x; int y;
    int x1;
    char *p;
    TXT_GetXY(&x, &y);
    if (((y) >= cliparea->y1 && (y) < cliparea->y2))
    {
        x1 = x;
        for (p = s; *p != '\0'; ++p)
        {
            if (((x1) >= cliparea->x1 && (x1) < cliparea->x2))
            {
                TXT_GotoXY(x1, y);
                TXT_PutChar(*p);
            }
            x1 += 1;
        }
    }
    TXT_GotoXY(x + strlen(s), y);
}

variable_types:
s
char *

variable_types:
p
char *


decompiled_code:
__int64 __fastcall TXT_DrawDesktopBackground(char *s)
{
_BYTE *v1; // rax
_BYTE *v2; // rdx
_BYTE *v3; // rcx
_BYTE *v4; // rcx
_BYTE *v5; // rdx

v1 = (_BYTE *)TXT_GetScreenData();
v2 = v1;
v3 = v1 + 4000;
do
{
*v1 = -79;
v1 += 2;
*(v1 - 1) = 23;
}
while ( v3 != v1 );
v4 = v2;
do
{
*v4 = 32;
v4 += 2;
*(v4 - 1) = 112;
}
while ( v2 + 160 != v4 );
v5 = v2 + 3840;
do
{
*v5 = 32;
v5 += 2;
*(v5 - 1) = 112;
}
while ( v5 != v1 );
TXT_GotoXY(0LL, 0LL);
TXT_FGColor(0LL);
TXT_BGColor(7LL, 0LL);
TXT_DrawString(" ");
return TXT_DrawString(s);
}

original_code:
void TXT_DrawDesktopBackground(const char *title)
{
    int i;
    unsigned char *screendata;
    unsigned char *p;
    screendata = TXT_GetScreenData();
    p = screendata;
    for (i=0; i<80 * 25; ++i)
    {
        *p++ = 0xb1;
        *p++ = TXT_COLOR_GREY | (TXT_COLOR_BLUE << 4);
    }
    p = screendata;
    for (i=0; i<80; ++i)
    {
        *p++ = ' ';
        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
    }
    p = screendata + (25 - 1) * 80 * 2;
    for (i=0; i<80; ++i)
    {
        *p++ = ' ';
        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
    }
    TXT_GotoXY(0, 0);
    TXT_FGColor(TXT_COLOR_BLACK);
    TXT_BGColor(TXT_COLOR_GREY, 0);
    TXT_DrawString(" ");
    TXT_DrawString(title);
}

canonical_original_code:
void TXT_DrawDesktopBackground(char *title)
{
    int i;
    unsigned char *screendata;
    unsigned char *p;
    screendata = TXT_GetScreenData();
    p = screendata;
    for (i=0; i<80 * 25; ++i)
    {
        *p++ = 0xb1;
        *p++ = TXT_COLOR_GREY | (TXT_COLOR_BLUE << 4);
    }
    p = screendata;
    for (i=0; i<80; ++i)
    {
        *p++ = ' ';
        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
    }
    p = screendata + (25 - 1) * 80 * 2;
    for (i=0; i<80; ++i)
    {
        *p++ = ' ';
        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
    }
    TXT_GotoXY(0, 0);
    TXT_FGColor(TXT_COLOR_BLACK);
    TXT_BGColor(TXT_COLOR_GREY, 0);
    TXT_DrawString(" ");
    TXT_DrawString(title);
}

variable_types:
title
char *

variable_types: i int


decompiled_code:
__int64 __fastcall TXT_DrawWindowFrame(char *a1, signed int a2, int a3, int a4, int a5)
{
signed int v6; // er15
int v7; // er12
signed int v8; // edx
int v9; // eax
int v10; // ecx
signed int v11; // ebx
int v12; // ebp
__int64 v13; // r11
_DWORD *v14; // rax
unsigned int v15; // er13
int v16; // ebp
size_t v17; // rax
__int64 v19; // [rsp+8h] [rbp-60h]
int v20; // [rsp+10h] [rbp-58h]
int v21; // [rsp+14h] [rbp-54h]
char v24[64]; // [rsp+28h] [rbp-40h] BYREF

v6 = a2 + a4;
v7 = a3 + a5;
TXT_SaveColors(v24);
TXT_FGColor(11LL);
v8 = a3;
v9 = 0;
v10 = v6 - 1;
if ( a3 < v7 )
{
while ( 1 )
{
v11 = a2;
v12 = 0;
v13 = v9;
if ( a2 < v6 )
{
while ( 1 )
{
v14 = cliparea;
if ( *(_DWORD *)cliparea <= v11 )
{
LABEL_4:
if ( v14[1] > v11 && v14[2] <= v8 && v14[3] > v8 )
{
v21 = v10;
v20 = v8;
v19 = v13;
TXT_GotoXY((unsigned int)v11, (unsigned int)v8);
TXT_PutChar((unsigned int)borders[4 * v19 + v12]);
v10 = v21;
v8 = v20;
v13 = v19;
}
}
if ( ++v11 == v6 )
break;
while ( 1 )
{
v12 = 0;
if ( a2 == v11 )
break;
v14 = cliparea;
v12 = 2 * (v10 == v11) + 1;
if ( *(_DWORD *)cliparea <= v11 )
goto LABEL_4;
if ( ++v11 == v6 )
goto LABEL_12;
}
}
}
LABEL_12:
if ( ++v8 == v7 )
break;
v9 = 0;
if ( a3 != v8 )
{
if ( a3 + 2 != v8 || (v9 = 2, !a1) )
v9 = 2 * (v7 - 1 == v8) + 1;
}
}
}
v15 = a3 + 1;
if ( a1 )
{
v16 = 0;
TXT_GotoXY((unsigned int)(a2 + 1), v15);
TXT_BGColor(7LL, 0LL);
TXT_FGColor(1LL);
if ( a4 - 2 > 0 )
{
do
{
++v16;
TXT_DrawString(" ");
}
while ( v16 != a4 - 2 );
}
v17 = strlen(a1);
TXT_GotoXY(a2 + (unsigned int)((a4 - v17) >> 1), v15);
TXT_DrawString(a1);
}
TXT_DrawShadow(a2 + 2, v7, a4, 1);
TXT_DrawShadow(v6, v15, 2, a5);
return TXT_RestoreColors(v24);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, signed int a2, int a3, int a4, int a5)
{
signed int v6; // er15
int v7; // er12
signed int v8; // edx
int v9; // eax
int v10; // ecx
signed int v11; // ebx
int v12; // ebp
__int64 v13; // r11
_DWORD *v14; // rax
unsigned int v15; // er13
int v16; // ebp
size_t v17; // rax
__int64 v19; // [rsp+8h] [rbp-60h]
int v20; // [rsp+10h] [rbp-58h]
int v21; // [rsp+14h] [rbp-54h]
char v24[64]; // [rsp+28h] [rbp-40h] BYREF

v6 = a2 + a4;
v7 = a3 + a5;
TXT_SaveColors(v24);
TXT_FGColor(11LL);
v8 = a3;
v9 = 0;
v10 = v6 - 1;
if ( a3 < v7 )
{
while ( 1 )
{
v11 = a2;
v12 = 0;
v13 = v9;
if ( a2 < v6 )
{
while ( 1 )
{
v14 = cliparea;
if ( *(_DWORD *)cliparea <= v11 )
{
LABEL_4:
if ( v14[1] > v11 && v14[2] <= v8 && v14[3] > v8 )
{
v21 = v10;
v20 = v8;
v19 = v13;
TXT_GotoXY((unsigned int)v11, (unsigned int)v8);
TXT_PutChar((unsigned int)borders[4 * v19 + v12]);
v10 = v21;
v8 = v20;
v13 = v19;
}
}
if ( ++v11 == v6 )
break;
while ( 1 )
{
v12 = 0;
if ( a2 == v11 )
break;
v14 = cliparea;
v12 = 2 * (v10 == v11) + 1;
if ( *(_DWORD *)cliparea <= v11 )
goto LABEL_4;
if ( ++v11 == v6 )
goto LABEL_12;
}
}
}
LABEL_12:
if ( ++v8 == v7 )
break;
v9 = 0;
if ( a3 != v8 )
{
if ( a3 + 2 != v8 || (v9 = 2, !a1) )
v9 = 2 * (v7 - 1 == v8) + 1;
}
}
}
v15 = a3 + 1;
if ( a1 )
{
v16 = 0;
TXT_GotoXY((unsigned int)(a2 + 1), v15);
TXT_BGColor(7LL, 0LL);
TXT_FGColor(1LL);
if ( a4 - 2 > 0 )
{
do
{
++v16;
func3(" ");
}
while ( v16 != a4 - 2 );
}
v17 = strlen(a1);
TXT_GotoXY(a2 + (unsigned int)((a4 - v17) >> 1), v15);
func3(a1);
}
func1(a2 + 2, v7, a4, 1);
func1(v6, v15, 2, a5);
return TXT_RestoreColors(v24);
}

original_code:
void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h)
{
    txt_saved_colors_t colors;
    int x1, y1;
    int bx, by;
    TXT_SaveColors(&colors);
    TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
    for (y1=y; y1<y+h; ++y1)
    {
        by = y1 == y ? 0 :
             y1 == y + 2 && title != ((void *)0) ? 2 :
             y1 == y + h - 1 ? 3 : 1;
        for (x1=x; x1<x+w; ++x1)
        {
            bx = x1 == x ? 0 :
                 x1 == x + w - 1 ? 3 : 1;
            if (((x1) >= cliparea->x1 && (x1) < cliparea->x2) && ((y1) >= cliparea->y1 && (y1) < cliparea->y2))
            {
                TXT_GotoXY(x1, y1);
                TXT_PutChar(borders[by][bx]);
            }
        }
    }
    if (title != ((void *)0))
    {
        TXT_GotoXY(x + 1, y + 1);
        TXT_BGColor(TXT_COLOR_GREY, 0);
        TXT_FGColor(TXT_COLOR_BLUE);
        for (x1=0; x1<w-2; ++x1)
        {
            TXT_DrawString(" ");
        }
        TXT_GotoXY(x + (w - strlen(title)) / 2, y + 1);
        TXT_DrawString(title);
    }
    TXT_DrawShadow(x + 2, y + h, w, 1);
    TXT_DrawShadow(x + w, y + 1, 2, h);
    TXT_RestoreColors(&colors);
}

canonical_original_code:
void TXT_DrawWindowFrame(char *title, int x, int y, int w, int h)
{
    struct txt_saved_colors_t colors;
    int x1; int y1;
    int bx; int by;
    TXT_SaveColors(&colors);
    TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
    for (y1=y; y1<y+h; ++y1)
    {
        by = y1 == y ? 0 :
             y1 == y + 2 && title != ((void *)0) ? 2 :
             y1 == y + h - 1 ? 3 : 1;
        for (x1=x; x1<x+w; ++x1)
        {
            bx = x1 == x ? 0 :
                 x1 == x + w - 1 ? 3 : 1;
            if (((x1) >= cliparea->x1 && (x1) < cliparea->x2) && ((y1) >= cliparea->y1 && (y1) < cliparea->y2))
            {
                TXT_GotoXY(x1, y1);
                TXT_PutChar(borders[by][bx]);
            }
        }
    }
    if (title != ((void *)0))
    {
        TXT_GotoXY(x + 1, y + 1);
        TXT_BGColor(TXT_COLOR_GREY, 0);
        TXT_FGColor(TXT_COLOR_BLUE);
        for (x1=0; x1<w-2; ++x1)
        {
            TXT_DrawString(" ");
        }
        TXT_GotoXY(x + (w - strlen(title)) / 2, y + 1);
        TXT_DrawString(title);
    }
    TXT_DrawShadow(x + 2, y + h, w, 1);
    TXT_DrawShadow(x + w, y + 1, 2, h);
    TXT_RestoreColors(&colors);
}

variable_types: struct txt_saved_colors_t { int bgcolor; int fgcolor; }

variable_types: bx int

variable_types: by int


decompiled_code:
__int64 __fastcall TXT_DrawUTF8String(_BYTE *a1)
{
unsigned int v2; // ebp
bool v3; // zf
int v4; // ebx
unsigned int v5; // ebp
__int64 v6; // rdi
int v7; // eax
int v9; // [rsp+0h] [rbp-28h] BYREF
int v10; // [rsp+4h] [rbp-24h] BYREF
__int64 v11[4]; // [rsp+8h] [rbp-20h] BYREF

TXT_GetXY(&v9, &v10);
v2 = v10;
if ( *((_DWORD *)cliparea + 2) <= v10 && v10 < *((_DWORD *)cliparea + 3) )
{
v3 = *a1 == 0;
v4 = v9;
v11[0] = (__int64)a1;
if ( !v3 )
{
while ( 1 )
{
v5 = TXT_DecodeUTF8(v11);
if ( !v5 )
break;
if ( *(_DWORD *)cliparea > v4 || *((_DWORD *)cliparea + 1) <= v4 )
{
++v4;
if ( !*(_BYTE *)v11[0] )
break;
}
else
{
v6 = (unsigned int)v4++;
TXT_GotoXY(v6, (unsigned int)v10);
PutUnicodeChar(v5);
if ( !*(_BYTE *)v11[0] )
break;
}
}
v2 = v10;
}
}
v7 = TXT_UTF8_Strlen(a1);
return TXT_GotoXY((unsigned int)(v9 + v7), v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
unsigned int v2; // ebp
bool v3; // zf
int v4; // ebx
unsigned int v5; // ebp
__int64 v6; // rdi
int v7; // eax
int v9; // [rsp+0h] [rbp-28h] BYREF
int v10; // [rsp+4h] [rbp-24h] BYREF
__int64 v11[4]; // [rsp+8h] [rbp-20h] BYREF

TXT_GetXY(&v9, &v10);
v2 = v10;
if ( *((_DWORD *)cliparea + 2) <= v10 && v10 < *((_DWORD *)cliparea + 3) )
{
v3 = *a1 == 0;
v4 = v9;
v11[0] = (__int64)a1;
if ( !v3 )
{
while ( 1 )
{
v5 = TXT_DecodeUTF8(v11);
if ( !v5 )
break;
if ( *(_DWORD *)cliparea > v4 || *((_DWORD *)cliparea + 1) <= v4 )
{
++v4;
if ( !*(_BYTE *)v11[0] )
break;
}
else
{
v6 = (unsigned int)v4++;
TXT_GotoXY(v6, (unsigned int)v10);
func0(v5);
if ( !*(_BYTE *)v11[0] )
break;
}
}
v2 = v10;
}
}
v7 = TXT_UTF8_Strlen(a1);
return TXT_GotoXY((unsigned int)(v9 + v7), v2);
}

original_code:
void TXT_DrawUTF8String(const char *s)
{
    int x, y;
    int x1;
    const char *p;
    unsigned int c;
    TXT_GetXY(&x, &y);
    if (((y) >= cliparea->y1 && (y) < cliparea->y2))
    {
        x1 = x;
        for (p = s; *p != '\0'; )
        {
            c = TXT_DecodeUTF8(&p);
            if (c == 0)
            {
                break;
            }
            if (((x1) >= cliparea->x1 && (x1) < cliparea->x2))
            {
                TXT_GotoXY(x1, y);
                PutUnicodeChar(c);
            }
            x1 += 1;
        }
    }
    TXT_GotoXY(x + TXT_UTF8_Strlen(s), y);
}

canonical_original_code:
void TXT_DrawUTF8String(char *s)
{
    int x; int y;
    int x1;
    char *p;
    unsigned int c;
    TXT_GetXY(&x, &y);
    if (((y) >= cliparea->y1 && (y) < cliparea->y2))
    {
        x1 = x;
        for (p = s; *p != '\0'; )
        {
            c = TXT_DecodeUTF8(&p);
            if (c == 0)
            {
                break;
            }
            if (((x1) >= cliparea->x1 && (x1) < cliparea->x2))
            {
                TXT_GotoXY(x1, y);
                PutUnicodeChar(c);
            }
            x1 += 1;
        }
    }
    TXT_GotoXY(x + TXT_UTF8_Strlen(s), y);
}

variable_types:
c
unsigned int