decompiled_code:
__int64 __fastcall fstk_RunMacroArg(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
const char *v3; // rbp
size_t v4; // rax

v1 = a1 - 48;
if ( a1 == 64 )
v1 = -1LL;
v2 = sym_FindMacroArg(v1);
if ( !v2 )
return fatalerror("No such macroargument");
v3 = (const char *)v2;
pushcontext();
nCurrentStatus = 2LL;
sprintf(tzCurrentFileName, "%c", (unsigned __int8)v1);
v4 = strlen(v3);
CurrentFlexHandle = yy_scan_bytes(v3, v4);
return yy_switch_to_buffer(CurrentFlexHandle);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
const char *v3; // rbp
size_t v4; // rax

v1 = a1 - 48;
if ( a1 == 64 )
v1 = -1LL;
v2 = sym_FindMacroArg(v1);
if ( !v2 )
return fatalerror("No such macroargument");
v3 = (const char *)v2;
func1();
nCurrentStatus = 2LL;
sprintf(tzCurrentFileName, "%c", (unsigned __int8)v1);
v4 = strlen(v3);
CurrentFlexHandle = yy_scan_bytes(v3, v4);
return yy_switch_to_buffer(CurrentFlexHandle);
}

original_code:
void fstk_RunMacroArg(SLONG s)
{
 char *sym;
 if (s == '@')
  s = -1;
 else
  s -= '0';
 if ((sym = sym_FindMacroArg(s)) != ((void *)0)) {
  pushcontext();
  nCurrentStatus = 2;
  sprintf(tzCurrentFileName, "%c", (UBYTE) s);
  CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
  yy_switch_to_buffer(CurrentFlexHandle);
 } else
  fatalerror("No such macroargument");
}

canonical_original_code:
void fstk_RunMacroArg(long s)
{
 char *sym;
 if (s == '@')
  s = -1;
 else
  s -= '0';
 if ((sym = sym_FindMacroArg(s)) != ((void *)0)) {
  pushcontext();
  nCurrentStatus = 2;
  sprintf(tzCurrentFileName, "%c", (unsigned char) s);
  CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
  yy_switch_to_buffer(CurrentFlexHandle);
 } else
  fatalerror("No such macroargument");
}

variable_types: s long

variable_types:
sym
char *


repo: vegard/rgbds-linux

decompiled_code:
void __fastcall fstk_RunRept(__int64 a1)
{
if ( a1 )
{
pushcontext();
sym_UseCurrentMacroArgs();
++nMacroCount;
sym_SetMacroArgID();
sym_UseNewMacroArgs();
nCurrentREPTBlockCount = a1;
nCurrentStatus = 3LL;
nCurrentREPTBlockSize = ulNewMacroSize;
pCurrentREPTBlock = tzNewMacro;
CurrentFlexHandle = yy_scan_bytes(tzNewMacro, ulNewMacroSize);
yy_switch_to_buffer(CurrentFlexHandle);
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
if ( a1 )
{
func1();
sym_UseCurrentMacroArgs();
++nMacroCount;
sym_SetMacroArgID();
sym_UseNewMacroArgs();
nCurrentREPTBlockCount = a1;
nCurrentStatus = 3LL;
nCurrentREPTBlockSize = ulNewMacroSize;
pCurrentREPTBlock = tzNewMacro;
CurrentFlexHandle = yy_scan_bytes(tzNewMacro, ulNewMacroSize);
yy_switch_to_buffer(CurrentFlexHandle);
}
}

original_code:
void fstk_RunRept(ULONG count)
{
 if (count) {
  pushcontext();
  sym_UseCurrentMacroArgs();
  sym_SetMacroArgID(nMacroCount++);
  sym_UseNewMacroArgs();
  nCurrentREPTBlockCount = count;
  nCurrentStatus = 3;
  nCurrentREPTBlockSize = ulNewMacroSize;
  pCurrentREPTBlock = tzNewMacro;
  CurrentFlexHandle =
      yy_scan_bytes(pCurrentREPTBlock, nCurrentREPTBlockSize);
  yy_switch_to_buffer(CurrentFlexHandle);
 }
}

canonical_original_code:
void fstk_RunRept(unsigned long count)
{
 if (count) {
  pushcontext();
  sym_UseCurrentMacroArgs();
  sym_SetMacroArgID(nMacroCount++);
  sym_UseNewMacroArgs();
  nCurrentREPTBlockCount = count;
  nCurrentStatus = 3;
  nCurrentREPTBlockSize = ulNewMacroSize;
  pCurrentREPTBlock = tzNewMacro;
  CurrentFlexHandle =
      yy_scan_bytes(pCurrentREPTBlock, nCurrentREPTBlockSize);
  yy_switch_to_buffer(CurrentFlexHandle);
 }
}

variable_types:
count
unsigned long

return_type: void


decompiled_code:
__int64 __fastcall fstk_Init(char *src)
{
FILE *v1; // rbx
__int64 result; // rax
char v3[536]; // [rsp+0h] [rbp-218h] BYREF

sym_AddString("__FILE__", src);
strcpy(v3, src);
fstk_FindFile(v3);
pFileStack = 0LL;
v1 = fopen(v3, "rt");
pCurrentFile = v1;
result = 0LL;
if ( v1 )
{
nMacroCount = 0LL;
nCurrentStatus = 0LL;
strcpy(tzCurrentFileName, v3);
CurrentFlexHandle = yy_create_buffer(v1);
yy_switch_to_buffer(CurrentFlexHandle);
nLineNo = 1LL;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *src)
{
FILE *v1; // rbx
__int64 result; // rax
char v3[536]; // [rsp+0h] [rbp-218h] BYREF

sym_AddString("__FILE__", src);
strcpy(v3, src);
fstk_FindFile(v3);
pFileStack = 0LL;
v1 = fopen(v3, "rt");
pCurrentFile = v1;
result = 0LL;
if ( v1 )
{
nMacroCount = 0LL;
nCurrentStatus = 0LL;
strcpy(tzCurrentFileName, v3);
CurrentFlexHandle = yy_create_buffer(v1);
yy_switch_to_buffer(CurrentFlexHandle);
nLineNo = 1LL;
result = 1LL;
}
return result;
}

original_code:
ULONG fstk_Init(char *s)
{
 char tzFileName[512 + 1];
 sym_AddString("__FILE__", s);
 strcpy(tzFileName, s);
 fstk_FindFile(tzFileName);
 pFileStack = ((void *)0);
 if ((pCurrentFile = fopen(tzFileName, "rt")) != ((void *)0)) {
  nMacroCount = 0;
  nCurrentStatus = 0;
  strcpy(tzCurrentFileName, tzFileName);
  CurrentFlexHandle = yy_create_buffer(pCurrentFile);
  yy_switch_to_buffer(CurrentFlexHandle);
  nLineNo = 1;
  return (1);
 } else
  return (0);
}

canonical_original_code:
unsigned long fstk_Init(char *s)
{
 char tzFileName[-1];
 sym_AddString("__FILE__", s);
 strcpy(tzFileName, s);
 fstk_FindFile(tzFileName);
 pFileStack = ((void *)0);
 if ((pCurrentFile = fopen(tzFileName, "rt")) != ((void *)0)) {
  nMacroCount = 0;
  nCurrentStatus = 0;
  strcpy(tzCurrentFileName, tzFileName);
  CurrentFlexHandle = yy_create_buffer(pCurrentFile);
  yy_switch_to_buffer(CurrentFlexHandle);
  nLineNo = 1;
  return (1);
 } else
  return (0);
}

variable_types:
s
char *

variable_types:
tzFileName
char [-1]

return_type: unsigned long


SetSymfileName

decompiled_code:
size_t __fastcall SetSymfileName(const char *a1)
{
stream = fopen(a1, "wt");
if ( !stream )
fatalerror("Unable to open symfile for writing");
return fwrite(";File generated by xLink v1.06c\n\n", 1uLL, 0x21uLL, stream);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
stream = fopen(a1, "wt");
if ( !stream )
fatalerror("Unable to open symfile for writing");
return fwrite(";File generated by xLink v1.06c\n\n", 1uLL, 0x21uLL, stream);
}

original_code:
void SetSymfileName(char *name)
{
 sf = fopen(name, "wt");
 if (!sf)
  fatalerror("Unable to open symfile for writing");
 fprintf(sf, ";File generated by xLink v" "1.06c" "\n\n");
}

variable_types:
name
char *


CloseMapfile

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

if ( mf )
{
result = fclose(mf);
mf = 0LL;
}
if ( stream )
{
result = fclose(stream);
stream = 0LL;
}
return result;
}

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

if ( mf )
{
result = fclose(mf);
mf = 0LL;
}
if ( stream )
{
result = fclose(stream);
stream = 0LL;
}
return result;
}

original_code:
void CloseMapfile(void)
{
 if (mf) {
  fclose(mf);
  mf = ((void *)0);
 }
 if (sf) {
  fclose(sf);
  sf = ((void *)0);
 }
}

canonical_original_code:
void CloseMapfile()
{
 if (mf) {
  fclose(mf);
  mf = ((void *)0);
 }
 if (sf) {
  fclose(sf);
  sf = ((void *)0);
 }
}


MapfileCloseBank

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

if ( mf )
{
if ( *((_QWORD *)&MaxAvail + currentbank) == a1 )
result = fwrite(" EMPTY\n\n", 1uLL, 9uLL, mf);
else
result = fprintf(mf, " SLACK: $%04lX bytes\n\n", a1);
}
return result;
}

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

if ( mf )
{
if ( *((_QWORD *)&MaxAvail + currentbank) == a1 )
result = fwrite(" EMPTY\n\n", 1uLL, 9uLL, mf);
else
result = fprintf(mf, " SLACK: $%04lX bytes\n\n", a1);
}
return result;
}

original_code:
void MapfileCloseBank(SLONG slack)
{
 if (!mf)
  return;
 if (slack == MaxAvail[currentbank])
  fprintf(mf, "  EMPTY\n\n");
 else
  fprintf(mf, "    SLACK: $%04lX bytes\n\n", slack);
}

canonical_original_code:
void MapfileCloseBank(long slack)
{
 if (!mf)
  return;
 if (slack == MaxAvail[currentbank])
  fprintf(mf, "  EMPTY\n\n");
 else
  fprintf(mf, "    SLACK: $%04lX bytes\n\n", slack);
}

variable_types: slack long


decompiled_code:
void on_timer_sig()
{
float v0; // [rsp+8h] [rbp-10h] BYREF
float v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

dht_get(v1, &v0);
base_save(db_sensor, v1[0], v0);
alarm(timeint);
}

canonical_decompiled_code:
void func0()
{
float v0; // [rsp+8h] [rbp-10h] BYREF
float v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

dht_get(v1, &v0);
base_save(db_sensor, v1[0], v0);
alarm(timeint);
}

original_code:
void on_timer_sig (int arg) {
  float temp, hum;
  dht_get (&temp, &hum);
  base_save (db_sensor, temp, hum);
  alarm (timeint);
}

canonical_original_code:
void on_timer_sig(int arg) {
  float temp; float hum;
  dht_get (&temp, &hum);
  base_save (db_sensor, temp, hum);
  alarm (timeint);
}

variable_types: arg int

variable_types: temp float

variable_types: hum float


decompiled_code:
void __noreturn on_exit_sig()
{
server_stop(server);
base_close(db_server);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
server_stop(server);
base_close(db_server);
exit(1);
}

original_code:
void on_exit_sig(int arg) {
  server_stop (server);
  base_close (db_server);
  exit (1);
}


decompiled_code:
int __fastcall print_usage(const char *a1)
{
printf("USAGE:\n\t%s [-p port] [-d dbpath] [-t interval] [-s]\n", a1);
puts("Options:");
puts("\t-s\tRun only HTTP server");
puts("Defaults:");
printf("\tport=%d\n", 8080LL);
printf("\tdbpath='%s'\n", "data.db");
return printf("\tinterval=%d\n", 300LL);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
printf("USAGE:\n\t%s [-p port] [-d dbpath] [-t interval] [-s]\n", a1);
puts("Options:");
puts("\t-s\tRun only HTTP server");
puts("Defaults:");
printf("\tport=%d\n", 8080LL);
printf("\tdbpath='%s'\n", "data.db");
return printf("\tinterval=%d\n", 300LL);
}

original_code:
void print_usage(char *name) {
  printf ("USAGE:\n\t%s [-p port] [-d dbpath] [-t interval] [-s]\n", name);
  printf ("Options:\n");
  printf ("\t-s\tRun only HTTP server\n");
  printf ("Defaults:\n");
  printf ("\tport=%d\n", 8080);
  printf ("\tdbpath='%s'\n", "data.db");
  printf ("\tinterval=%d\n", (5*60));
}


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

if ( (unsigned int)base_init(&db_server, dbpath) )
{
fprintf(stderr, "Cannot open base '%s'\n", (const char *)dbpath);
exit(1);
}
result = server_start((unsigned int)port, db_server);
server = result;
if ( !result )
{
fprintf(stderr, "Cannot start server on port %d\n", (unsigned int)port);
exit(1);
}
return result;
}

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

if ( (unsigned int)base_init(&db_server, dbpath) )
{
fprintf(stderr, "Cannot open base '%s'\n", (const char *)dbpath);
exit(1);
}
result = server_start((unsigned int)port, db_server);
server = result;
if ( !result )
{
fprintf(stderr, "Cannot start server on port %d\n", (unsigned int)port);
exit(1);
}
return result;
}

original_code:
void http_start (void) {
  int ret;
  ret = base_init (&db_server, dbpath);
  if (ret != 0) {
    fprintf (stderr, "Cannot open base '%s'\n", dbpath);
    exit (1);
  }
  server = server_start(port, db_server);
  if (server == ((void *)0)) {
    fprintf (stderr, "Cannot start server on port %d\n", port);
    exit (1);
  }
}

canonical_original_code:
void http_start() {
  int ret;
  ret = base_init (&db_server, dbpath);
  if (ret != 0) {
    fprintf (stderr, "Cannot open base '%s'\n", dbpath);
    exit (1);
  }
  server = server_start(port, db_server);
  if (server == ((void *)0)) {
    fprintf (stderr, "Cannot start server on port %d\n", port);
    exit (1);
  }
}

variable_types: ret int


decompiled_code:
unsigned int sensor_start()
{
if ( (unsigned int)base_init(&db_sensor, dbpath) )
{
fprintf(stderr, "Cannot open base '%s'\n", (const char *)dbpath);
exit(1);
}
signal(14, (__sighandler_t)on_timer_sig);
return alarm(timeint);
}

canonical_decompiled_code:
unsigned int func4()
{
if ( (unsigned int)base_init(&db_sensor, dbpath) )
{
fprintf(stderr, "Cannot open base '%s'\n", (const char *)dbpath);
exit(1);
}
signal(14, (__sighandler_t)on_timer_sig);
return alarm(timeint);
}

original_code:
void sensor_start(void) {
  int ret;
  ret = base_init(&db_sensor, dbpath);
  if (ret != 0) {
    fprintf (stderr, "Cannot open base '%s'\n", dbpath);
    exit (1);
  }
  signal (14, &on_timer_sig);
  alarm (timeint);
}

canonical_original_code:
void sensor_start() {
  int ret;
  ret = base_init(&db_sensor, dbpath);
  if (ret != 0) {
    fprintf (stderr, "Cannot open base '%s'\n", dbpath);
    exit (1);
  }
  signal (14, &on_timer_sig);
  alarm (timeint);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // ebx
int v5; // eax
const char *v6; // rax
int v7; // eax
__int64 v8; // r12

opterr = 0;
v3 = getopt(argc, (char *const *)argv, "hp:d:t:s");
if ( v3 != -1 )
{
if ( v3 != 63 )
abort();
v4 = optopt;
if ( (optopt & 0xFFFFFFEF) == 100 || optopt == 112 )
{
fprintf(stderr, "Option -%c requires an argument.\n", (unsigned int)optopt);
}
else if ( ((*_ctype_b_loc())[v4] & 0x4000) != 0 )
{
fprintf(stderr, "Unknown option `-%c'.\n", v4);
}
else
{
fprintf(stderr, "Unknown option character `\\x%x'.\n", v4);
}
exit(1);
}
v5 = port;
if ( port < 0 )
v5 = 8080;
port = v5;
v6 = (const char *)dbpath;
if ( !dbpath )
v6 = "data.db";
dbpath = (__int64)v6;
v7 = timeint;
if ( !timeint )
v7 = 300;
timeint = v7;
if ( optind >= argc )
{
http_start();
sensor_start();
signal(15, (__sighandler_t)on_exit_sig);
signal(2, (__sighandler_t)on_exit_sig);
while ( 1 )
pause();
}
v8 = optind;
do
printf("Non-option argument %s\n", argv[v8++]);
while ( argc > (int)v8 );
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // ebx
int v5; // eax
const char *v6; // rax
int v7; // eax
__int64 v8; // r12

opterr = 0;
v3 = getopt(argc, (char *const *)argv, "hp:d:t:s");
if ( v3 != -1 )
{
if ( v3 != 63 )
abort();
v4 = optopt;
if ( (optopt & 0xFFFFFFEF) == 100 || optopt == 112 )
{
fprintf(stderr, "Option -%c requires an argument.\n", (unsigned int)optopt);
}
else if ( ((*_ctype_b_loc())[v4] & 0x4000) != 0 )
{
fprintf(stderr, "Unknown option `-%c'.\n", v4);
}
else
{
fprintf(stderr, "Unknown option character `\\x%x'.\n", v4);
}
exit(1);
}
v5 = port;
if ( port < 0 )
v5 = 8080;
port = v5;
v6 = (const char *)dbpath;
if ( !dbpath )
v6 = "data.db";
dbpath = (__int64)v6;
v7 = timeint;
if ( !timeint )
v7 = 300;
timeint = v7;
if ( optind >= argc )
{
func3();
func4();
signal(15, (__sighandler_t)on_exit_sig);
signal(2, (__sighandler_t)on_exit_sig);
while ( 1 )
pause();
}
v8 = optind;
do
printf("Non-option argument %s\n", argv[v8++]);
while ( argc > (int)v8 );
exit(1);
}

original_code:
int main (int argc, char **argv) {
  int ret;
  int i;
  char* port_s = ((void *)0);
  char* timeint_s = ((void *)0);
  int http_only = 0;
  int c;
  opterr = 0;
  while ((c = getopt (argc, argv, "hp:d:t:s")) != -1)
    switch (c) {
    case 'h':
      print_usage (argv[0]);
      return 0;
    case 'p':
      port_s = optarg;
      port = atoi (port_s);
      break;
    case 'd':
      dbpath = optarg;
      break;
    case 't':
      timeint_s = optarg;
      ret = atoi (timeint_s);
      timeint = ret < 0 ? 0 : (unsigned int)ret;
      break;
    case 's':
      http_only = 1;
      break;
    case '?':
      if (optopt == 'p' ||
   optopt == 'd' ||
   optopt == 't')
 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
      else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short int) _ISprint))
 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
      else
 fprintf (stderr,
   "Unknown option character `\\x%x'.\n",
   optopt);
      exit (1);
    default:
      abort ();
    }
  port = port < 0 ? 8080 : port;
  dbpath = dbpath == ((void *)0) ? "data.db" : dbpath;
  timeint = timeint < 1 ? (5*60) : timeint;
  if (optind < argc) {
    for (i = optind; i < argc; i++)
      printf ("Non-option argument %s\n", argv[i]);
    exit (1);
  }
  http_start ();
  if (!http_only) {
    sensor_start ();
  }
  signal (15, &on_exit_sig);
  signal (2, &on_exit_sig);
  while (1)
    pause ();
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int ret;
  int i;
  char *port_s = ((void *)0);
  char *timeint_s = ((void *)0);
  int http_only = 0;
  int c;
  opterr = 0;
  while ((c = getopt (argc, argv, "hp:d:t:s")) != -1)
    switch (c) {
    case 'h':
      print_usage (argv[0]);
      return 0;
    case 'p':
      port_s = optarg;
      port = atoi (port_s);
      break;
    case 'd':
      dbpath = optarg;
      break;
    case 't':
      timeint_s = optarg;
      ret = atoi (timeint_s);
      timeint = ret < 0 ? 0 : (unsigned int)ret;
      break;
    case 's':
      http_only = 1;
      break;
    case '?':
      if (optopt == 'p' ||
   optopt == 'd' ||
   optopt == 't')
 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
      else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short) _ISprint))
 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
      else
 fprintf (stderr,
   "Unknown option character `\\x%x'.\n",
   optopt);
      exit (1);
    default:
      abort ();
    }
  port = port < 0 ? 8080 : port;
  dbpath = dbpath == ((void *)0) ? "data.db" : dbpath;
  timeint = timeint < 1 ? (5*60) : timeint;
  if (optind < argc) {
    for (i = optind; i < argc; i++)
      printf ("Non-option argument %s\n", argv[i]);
    exit (1);
  }
  http_start ();
  if (!http_only) {
    sensor_start ();
  }
  signal (15, &on_exit_sig);
  signal (2, &on_exit_sig);
  while (1)
    pause ();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: c int

return_type: int


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

result = (unsigned int)(1 << a1);
*(_DWORD *)(pi_mmio_gpio + 28) = result;
return result;
}

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

result = (unsigned int)(1 << a1);
*(_DWORD *)(pi_mmio_gpio + 28) = result;
return result;
}

original_code:
static inline void pi_mmio_set_high(const int gpio_number) {
  *(pi_mmio_gpio+7) = 1 << gpio_number;
}

canonical_original_code:
static inline void pi_mmio_set_high(int gpio_number) {
  *(pi_mmio_gpio+7) = 1 << gpio_number;
}


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

result = (unsigned int)(1 << a1);
*(_DWORD *)(pi_mmio_gpio + 40) = result;
return result;
}

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

result = (unsigned int)(1 << a1);
*(_DWORD *)(pi_mmio_gpio + 40) = result;
return result;
}

original_code:
static inline void pi_mmio_set_low(const int gpio_number) {
  *(pi_mmio_gpio+10) = 1 << gpio_number;
}

canonical_original_code:
static inline void pi_mmio_set_low(int gpio_number) {
  *(pi_mmio_gpio+10) = 1 << gpio_number;
}


decompiled_code:
__int64 __fastcall pi_mmio_input(char a1)
{
return *(_DWORD *)(pi_mmio_gpio + 52) & (unsigned int)(1 << a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
return *(_DWORD *)(pi_mmio_gpio + 52) & (unsigned int)(1 << a1);
}

original_code:
static inline uint32_t pi_mmio_input(const int gpio_number) {
  return *(pi_mmio_gpio+13) & (1 << gpio_number);
}

canonical_original_code:
static inline unsigned int pi_mmio_input(int gpio_number) {
  return *(pi_mmio_gpio+13) & (1 << gpio_number);
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall pi_dht_read(int a1, char a2, float *a3, float *a4)
{
int v7; // er15
unsigned int v8; // ebx
__int64 result; // rax
int v10; // eax
__int64 v11; // rax
int v12; // edx
char v13; // dl
int v14; // edi
int v15; // er10
float v16; // xmm0_4
int v17; // edx
int v18; // edx
char v19; // cl
int v20; // [rsp+1h] [rbp-18Dh]
unsigned __int8 v21; // [rsp+5h] [rbp-189h]
int v22[83]; // [rsp+6h] [rbp-188h] BYREF
int i; // [rsp+152h] [rbp-3Ch]

if ( !a3 )
return 4294967293LL;
if ( !a4 )
return 4294967293LL;
*a4 = 0.0;
*a3 = 0.0;
if ( (int)pi_mmio_init() < 0 )
return 4294967292LL;
memset(v22, 0, 0x148uLL);
pi_mmio_set_output(a2);
set_max_priority();
pi_mmio_set_high(a2);
sleep_milliseconds(500LL);
pi_mmio_set_low(a2);
busy_wait_milliseconds(20LL);
pi_mmio_set_input(a2);
for ( i = 0; i <= 49; ++i )
;
v7 = 32000;
while ( 1 )
{
v8 = pi_mmio_input(a2);
if ( !v8 )
break;
if ( !--v7 )
{
set_default_priority();
return 0xFFFFFFFFLL;
}
}
for ( i = 0; i <= 81; i += 2 )
{
while ( !(unsigned int)pi_mmio_input(a2) )
{
v10 = v22[i] + 1;
v22[i] = v10;
if ( v10 > 31999 )
{
LABEL_13:
set_default_priority();
return 0xFFFFFFFFLL;
}
}
while ( (unsigned int)pi_mmio_input(a2) )
{
v11 = i + 1;
v12 = v22[v11] + 1;
v22[v11] = v12;
if ( v12 > 31999 )
goto LABEL_13;
}
}
set_default_priority();
for ( i = 2; i <= 81; i += 2 )
v8 += v22[i];
v20 = 0;
v21 = 0;
for ( i = 3; i <= 81; i += 2 )
{
v17 = i - 3;
if ( i - 3 < 0 )
v17 = i + 12;
v18 = v17 >> 4;
v19 = 2 * *((_BYTE *)&v20 + v18);
*((_BYTE *)&v20 + v18) = v19;
if ( v22[i] >= v8 / 0x28 )
*((_BYTE *)&v20 + v18) = v19 | 1;
}
v13 = BYTE2(v20);
v14 = HIBYTE(v20);
v15 = BYTE2(v20);
if ( v21 != (unsigned __int8)(HIBYTE(v20) + BYTE2(v20) + v20 + BYTE1(v20)) )
return 4294967294LL;
if ( a1 == 11 )
{
*a3 = (float)(unsigned __int8)v20;
*a4 = (float)v15;
result = 0LL;
}
else
{
result = 0LL;
if ( a1 == 22 )
{
*a3 = (float)(BYTE1(v20) + ((unsigned __int8)v20 << 8)) / 10.0;
v16 = (float)(v14 + ((v13 & 0x7F) << 8)) / 10.0;
if ( v13 < 0 )
LODWORD(v16) ^= LC2;
*a4 = v16;
result = 0LL;
}
}
return result;
}

original_code:
int pi_dht_read(int type, int pin, float* humidity, float* temperature) {
  volatile int i;
  if (humidity == ((void *)0) || temperature == ((void *)0)) {
    return -3;
  }
  *temperature = 0.0f;
  *humidity = 0.0f;
  if (pi_mmio_init() < 0) {
    return -4;
  }
  int pulseCounts[41*2] = {0};
  pi_mmio_set_output(pin);
  set_max_priority();
  pi_mmio_set_high(pin);
  sleep_milliseconds(500);
  pi_mmio_set_low(pin);
  busy_wait_milliseconds(20);
  pi_mmio_set_input(pin);
  for (i = 0; i < 50; ++i) {
  }
  uint32_t count = 0;
  while (pi_mmio_input(pin)) {
    if (++count >= 32000) {
      set_default_priority();
      return -1;
    }
  }
  for (i=0; i < 41*2; i+=2) {
    while (!pi_mmio_input(pin)) {
      if (++pulseCounts[i] >= 32000) {
        set_default_priority();
        return -1;
      }
    }
    while (pi_mmio_input(pin)) {
      if (++pulseCounts[i+1] >= 32000) {
        set_default_priority();
        return -1;
      }
    }
  }
  set_default_priority();
  uint32_t threshold = 0;
  for (i=2; i < 41*2; i+=2) {
    threshold += pulseCounts[i];
  }
  threshold /= 41 -1;
  uint8_t data[5] = {0};
  for (i=3; i < 41*2; i+=2) {
    int index = (i-3)/16;
    data[index] <<= 1;
    if (pulseCounts[i] >= threshold) {
      data[index] |= 1;
    }
  }
  if (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) {
    if (type == 11) {
      *humidity = (float)data[0];
      *temperature = (float)data[2];
    }
    else if (type == 22) {
      *humidity = (data[0] * 256 + data[1]) / 10.0f;
      *temperature = ((data[2] & 0x7F) * 256 + data[3]) / 10.0f;
      if (data[2] & 0x80) {
        *temperature *= -1.0f;
      }
    }
    return 0;
  }
  else {
    return -2;
  }
}

canonical_original_code:
int pi_dht_read(int type, int pin, float *humidity, float *temperature) {
  int i;
  if (humidity == ((void *)0) || temperature == ((void *)0)) {
    return -3;
  }
  *temperature = 0.0f;
  *humidity = 0.0f;
  if (pi_mmio_init() < 0) {
    return -4;
  }
  int pulseCounts[-1] = {0};
  pi_mmio_set_output(pin);
  set_max_priority();
  pi_mmio_set_high(pin);
  sleep_milliseconds(500);
  pi_mmio_set_low(pin);
  busy_wait_milliseconds(20);
  pi_mmio_set_input(pin);
  for (i = 0; i < 50; ++i) {
  }
  unsigned int count = 0;
  while (pi_mmio_input(pin)) {
    if (++count >= 32000) {
      set_default_priority();
      return -1;
    }
  }
  for (i=0; i < 41*2; i+=2) {
    while (!pi_mmio_input(pin)) {
      if (++pulseCounts[i] >= 32000) {
        set_default_priority();
        return -1;
      }
    }
    while (pi_mmio_input(pin)) {
      if (++pulseCounts[i+1] >= 32000) {
        set_default_priority();
        return -1;
      }
    }
  }
  set_default_priority();
  unsigned int threshold = 0;
  for (i=2; i < 41*2; i+=2) {
    threshold += pulseCounts[i];
  }
  threshold /= 41 -1;
  unsigned char data[5] = {0};
  for (i=3; i < 41*2; i+=2) {
    int index = (i-3)/16;
    data[index] <<= 1;
    if (pulseCounts[i] >= threshold) {
      data[index] |= 1;
    }
  }
  if (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) {
    if (type == 11) {
      *humidity = (float)data[0];
      *temperature = (float)data[2];
    }
    else if (type == 22) {
      *humidity = (data[0] * 256 + data[1]) / 10.0f;
      *temperature = ((data[2] & 0x7F) * 256 + data[3]) / 10.0f;
      if (data[2] & 0x80) {
        *temperature *= -1.0f;
      }
    }
    return 0;
  }
  else {
    return -2;
  }
}

variable_types: type int

variable_types: pin int

variable_types:
humidity
float *

variable_types:
temperature
float *

variable_types:
pulseCounts
int [-1]

variable_types:
count
unsigned int

variable_types:
threshold
unsigned int

variable_types:
data
unsigned char [5]

variable_types: index int


decompiled_code:
__time_t __fastcall busy_wait_milliseconds(unsigned int a1)
{
__time_t v1; // rbx
__suseconds_t v2; // rbp
__time_t result; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
v1 = v4.tv_sec + a1 / 0x3E8;
v2 = v4.tv_usec + 1000 * (a1 % 0x3E8);
if ( v2 > 999999 )
{
++v1;
v2 -= 1000000LL;
}
while ( 1 )
{
result = v4.tv_sec;
if ( v4.tv_sec != v1 )
break;
if ( v4.tv_usec >= v2 )
return result;
LABEL_4:
gettimeofday(&v4, 0LL);
}
if ( v4.tv_sec < v1 )
goto LABEL_4;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func0(unsigned int a1)
{
__time_t v1; // rbx
__suseconds_t v2; // rbp
__time_t result; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
v1 = v4.tv_sec + a1 / 0x3E8;
v2 = v4.tv_usec + 1000 * (a1 % 0x3E8);
if ( v2 > 999999 )
{
++v1;
v2 -= 1000000LL;
}
while ( 1 )
{
result = v4.tv_sec;
if ( v4.tv_sec != v1 )
break;
if ( v4.tv_usec >= v2 )
return result;
LABEL_4:
gettimeofday(&v4, 0LL);
}
if ( v4.tv_sec < v1 )
goto LABEL_4;
return result;
}

original_code:
void busy_wait_milliseconds(uint32_t millis) {
  struct timeval deltatime;
  deltatime.tv_sec = millis / 1000;
  deltatime.tv_usec = (millis % 1000) * 1000;
  struct timeval walltime;
  gettimeofday(&walltime, ((void *)0));
  struct timeval endtime;
  do { (&endtime)->tv_sec = (&walltime)->tv_sec + (&deltatime)->tv_sec; (&endtime)->tv_usec = (&walltime)->tv_usec + (&deltatime)->tv_usec; if ((&endtime)->tv_usec >= 1000000) { ++(&endtime)->tv_sec; (&endtime)->tv_usec -= 1000000; } } while (0);
  while ((((&walltime)->tv_sec == (&endtime)->tv_sec) ? ((&walltime)->tv_usec < (&endtime)->tv_usec) : ((&walltime)->tv_sec < (&endtime)->tv_sec))) {
    gettimeofday(&walltime, ((void *)0));
  }
}

canonical_original_code:
void busy_wait_milliseconds(unsigned int millis) {
  struct timeval deltatime;
  deltatime.tv_sec = millis / 1000;
  deltatime.tv_usec = (millis % 1000) * 1000;
  struct timeval walltime;
  gettimeofday(&walltime, ((void *)0));
  struct timeval endtime;
  do { (&endtime)->tv_sec = (&walltime)->tv_sec + (&deltatime)->tv_sec; (&endtime)->tv_usec = (&walltime)->tv_usec + (&deltatime)->tv_usec; if ((&endtime)->tv_usec >= 1000000) { ++(&endtime)->tv_sec; (&endtime)->tv_usec -= 1000000; } } while (0);
  while ((((&walltime)->tv_sec == (&endtime)->tv_sec) ? ((&walltime)->tv_usec < (&endtime)->tv_usec) : ((&walltime)->tv_sec < (&endtime)->tv_sec))) {
    gettimeofday(&walltime, ((void *)0));
  }
}

variable_types:
millis
unsigned int

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
int __fastcall sleep_milliseconds(unsigned int a1)
{
int *v1; // rax
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

v3.tv_sec = a1 / 0x3E8;
v3.tv_nsec = 1000000LL * (a1 % 0x3E8);
do
{
LODWORD(v1) = clock_nanosleep(1, 0, &v3, &v3);
if ( !(_DWORD)v1 )
break;
v1 = _errno_location();
}
while ( *v1 == 4 );
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
int *v1; // rax
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

v3.tv_sec = a1 / 0x3E8;
v3.tv_nsec = 1000000LL * (a1 % 0x3E8);
do
{
LODWORD(v1) = clock_nanosleep(1, 0, &v3, &v3);
if ( !(_DWORD)v1 )
break;
v1 = _errno_location();
}
while ( *v1 == 4 );
return (int)v1;
}

original_code:
void sleep_milliseconds(uint32_t millis) {
  struct timespec sleep;
  sleep.tv_sec = millis / 1000;
  sleep.tv_nsec = (millis % 1000) * 1000000L;
  while (clock_nanosleep(1, 0, &sleep, &sleep) && (*__errno_location ()) == 4);
}

canonical_original_code:
void sleep_milliseconds(unsigned int millis) {
  struct timespec sleep;
  sleep.tv_sec = millis / 1000;
  sleep.tv_nsec = (millis % 1000) * 1000000L;
  while (clock_nanosleep(1, 0, &sleep, &sleep) && (*__errno_location ()) == 4);
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int set_max_priority()
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = sched_get_priority_max(1);
return sched_setscheduler(0, 1, &param);
}

canonical_decompiled_code:
int func2()
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = sched_get_priority_max(1);
return sched_setscheduler(0, 1, &param);
}

original_code:
void set_max_priority(void) {
  struct sched_param sched;
  memset(&sched, 0, sizeof(sched));
  sched.sched_priority = sched_get_priority_max(1);
  sched_setscheduler(0, 1, &sched);
}

canonical_original_code:
void set_max_priority() {
  struct sched_param sched;
  memset(&sched, 0, sizeof(sched));
  sched.sched_priority = sched_get_priority_max(1);
  sched_setscheduler(0, 1, &sched);
}

variable_types: struct sched_param { int sched_priority; }


decompiled_code:
int set_default_priority()
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = 0;
return sched_setscheduler(0, 0, &param);
}

canonical_decompiled_code:
int func3()
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = 0;
return sched_setscheduler(0, 0, &param);
}

original_code:
void set_default_priority(void) {
  struct sched_param sched;
  memset(&sched, 0, sizeof(sched));
  sched.sched_priority = 0;
  sched_setscheduler(0, 0, &sched);
}

canonical_original_code:
void set_default_priority() {
  struct sched_param sched;
  memset(&sched, 0, sizeof(sched));
  sched.sched_priority = 0;
  sched_setscheduler(0, 0, &sched);
}

user_defined_types: struct sched_param { int sched_priority; }


decompiled_code:
char *__fastcall buffer_est_size(__int64 a1)
{
return (char *)result_buffer - a1 + 10485760;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1)
{
return (char *)result_buffer - a1 + 10485760;
}

original_code:
long buffer_est_size (char* p) {
  char* end = result_buffer + 10*1024*1024;
  return end - p;
}

canonical_original_code:
long buffer_est_size(char *p) {
  char *end = result_buffer + 10*1024*1024;
  return end - p;
}

variable_types:
p
char *

variable_types:
end
char *

return_type: long


decompiled_code:
_BOOL8 __fastcall check_buffer(__int64 a1, __int64 a2)
{
return a1 + a2 + 1 < (unsigned __int64)result_buffer + 10485760;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, __int64 a2)
{
return a1 + a2 + 1 < (unsigned __int64)result_buffer + 10485760;
}

original_code:
int check_buffer (char* p, size_t n) {
  char* end = result_buffer + 10*1024*1024;
  return (p + n + 1) < end;
}

canonical_original_code:
int check_buffer(char *p, unsigned long n) {
  char *end = result_buffer + 10*1024*1024;
  return (p + n + 1) < end;
}

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall add_to_buffer(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
char *v3; // r13
_BOOL4 v4; // edx
__int64 result; // rax

v2 = strlen(a2);
v3 = (char *)*a1;
v4 = check_buffer(*a1, v2);
result = 1LL;
if ( v4 )
{
strcpy(v3, a2);
*a1 += v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
char *v3; // r13
_BOOL4 v4; // edx
__int64 result; // rax

v2 = strlen(a2);
v3 = (char *)*a1;
v4 = func4(*a1, v2);
result = 1LL;
if ( v4 )
{
strcpy(v3, a2);
*a1 += v2;
result = 0LL;
}
return result;
}

original_code:
int add_to_buffer (char** pp, char* str) {
  size_t len = strlen(str);
  if (!check_buffer (*pp, len))
    return 1;
  strcpy (*pp, str);
  (*pp) += len;
  return 0;
}

canonical_original_code:
int add_to_buffer(char **pp, char *str) {
  unsigned long len = strlen(str);
  if (!check_buffer (*pp, len))
    return 1;
  strcpy (*pp, str);
  (*pp) += len;
  return 0;
}

variable_types:
pp
char **

variable_types:
str
char *

variable_types:
len
unsigned long


decompiled_code:
_BOOL8 __fastcall result_iterate(__int64 *a1, int a2, __int64 a3, __int64 a4)
{
int v5; // edx
_BOOL8 result; // rax
__int64 i; // rbx
const char *v8; // r13
char *v9; // r14
char *v10; // rbp
int v11; // eax

v5 = add_to_buffer(a1, "{");
result = 1LL;
if ( !v5 )
{
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
v8 = *(const char **)(a3 + 8 * i);
if ( v8 )
{
v9 = (char *)*a1;
v10 = buffer_est_size(*a1) - 1;
v11 = snprintf(v9, (size_t)v10, "%s: '%s'", *(const char **)(a4 + 8 * i), v8);
if ( (__int64)v10 <= v11 )
return 1LL;
*a1 += v11;
if ( a2 - 1 != (_DWORD)i && (unsigned int)add_to_buffer(a1, ", ") )
return 1LL;
}
}
}
result = (unsigned int)add_to_buffer(a1, "}, ") != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 *a1, int a2, __int64 a3, __int64 a4)
{
int v5; // edx
_BOOL8 result; // rax
__int64 i; // rbx
const char *v8; // r13
char *v9; // r14
char *v10; // rbp
int v11; // eax

v5 = func5(a1, "{");
result = 1LL;
if ( !v5 )
{
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
v8 = *(const char **)(a3 + 8 * i);
if ( v8 )
{
v9 = (char *)*a1;
v10 = func3(*a1) - 1;
v11 = snprintf(v9, (size_t)v10, "%s: '%s'", *(const char **)(a4 + 8 * i), v8);
if ( (__int64)v10 <= v11 )
return 1LL;
*a1 += v11;
if ( a2 - 1 != (_DWORD)i && (unsigned int)func5(a1, ", ") )
return 1LL;
}
}
}
result = (unsigned int)func5(a1, "}, ") != 0;
}
return result;
}

original_code:
int result_iterate (void* json_v, int col_count, char** cols, char** col_names) {
  int i;
  long size, count;
  char** json = (char**)json_v;
  if (add_to_buffer (json, "{") != 0)
    return 1;
  for (i = 0; i < col_count; i++) {
    if (cols[i] == ((void *)0))
      continue;
    size = buffer_est_size (*json) - 1;
    count = snprintf (*json, (size_t)size, "%s: '%s'", col_names[i], cols[i]);
    if (count >= size)
      return 1;
    (*json) += count;
    if (i != col_count - 1)
      if (add_to_buffer (json, ", ") != 0)
 return 1;
  }
  if (add_to_buffer (json, "}, ") != 0)
    return 1;
  return 0;
}

canonical_original_code:
int result_iterate(void *json_v, int col_count, char **cols, char **col_names) {
  int i;
  long size; long count;
  char **json = (char**)json_v;
  if (add_to_buffer (json, "{") != 0)
    return 1;
  for (i = 0; i < col_count; i++) {
    if (cols[i] == ((void *)0))
      continue;
    size = buffer_est_size (*json) - 1;
    count = snprintf (*json, (unsigned long)size, "%s: '%s'", col_names[i], cols[i]);
    if (count >= size)
      return 1;
    (*json) += count;
    if (i != col_count - 1)
      if (add_to_buffer (json, ", ") != 0)
 return 1;
  }
  if (add_to_buffer (json, "}, ") != 0)
    return 1;
  return 0;
}

variable_types:
cols
char **

variable_types: i int

variable_types: size long

variable_types: count long

variable_types:
json
char **


decompiled_code:
__int64 pi_mmio_init()
{
unsigned int v0; // ebx
int v2; // eax

v0 = 0;
if ( !pi_mmio_gpio )
{
v2 = open("/dev/mem", 1052674);
v0 = v2;
if ( v2 != -1 )
{
pi_mmio_gpio = (__int64)mmap(0LL, 0x1000uLL, 3, 1, v2, 538968064LL);
close(v0);
if ( pi_mmio_gpio == -1 )
{
pi_mmio_gpio = 0LL;
v0 = -2;
}
else
{
v0 = 0;
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
int v2; // eax

v0 = 0;
if ( !pi_mmio_gpio )
{
v2 = open("/dev/mem", 1052674);
v0 = v2;
if ( v2 != -1 )
{
pi_mmio_gpio = (__int64)mmap(0LL, 0x1000uLL, 3, 1, v2, 538968064LL);
close(v0);
if ( pi_mmio_gpio == -1 )
{
pi_mmio_gpio = 0LL;
v0 = -2;
}
else
{
v0 = 0;
}
}
}
return v0;
}

canonical_original_code:
int pi_mmio_init() {
  if (pi_mmio_gpio == ((void *)0)) {
    int fd = open("/dev/mem", 02 | 04010000);
    if (fd == -1) {
      return -1;
    }
    pi_mmio_gpio = (unsigned int *)mmap(((void *)0), 4096, 0x1 | 0x2, 0x01, fd, (0x20000000 + 0x200000));
    close(fd);
    if (pi_mmio_gpio == ((void *) -1)) {
      pi_mmio_gpio = ((void *)0);
      return -2;
    }
  }
  return 0;
}

variable_types: fd int


repo: velovix/super-glitch-engine

original_code:
void pk_psetMonster(monster_t mon, player_t* player) {
 if(player->monCnt > 5) {
  printf("[ERROR] Max monster count reached on player!\n");
  return;
 }
 player->monsters[player->monCnt] = mon;
 player->monCnt++;
}

canonical_original_code:
void pk_psetMonster(struct monster_t mon, struct player_t *player) {
 if(player->monCnt > 5) {
  printf("[ERROR] Max monster count reached on player!\n");
  return;
 }
 player->monsters[player->monCnt] = mon;
 player->monCnt++;
}

variable_types: struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; }

variable_types: struct player_t { char name[12]; int sprite; _Bool pause; struct monster_t monsters[6]; struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } mover; } *

user_defined_types: struct monster_t { int experience; char name[10]; struct monFileObj_t *id; _Bool shiny; struct stats_t stats; struct moveMask_t moves[4]; int condition; }

user_defined_types: struct player_t { char name[12]; int sprite; _Bool pause; struct monster_t monsters[6]; struct charMover_t mover; }

user_defined_types: struct monFileObj_t { struct monBasic_f basic; struct monStats_f stats; struct monMovelist_f movelist; struct monExperience_f experience; struct monEvolution_f evolution; struct monAesthetics_f aesthetics; struct monOthers_f etc; }

user_defined_types: struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; }


decompiled_code:
__int64 __fastcall pk_pMove(__int64 a1, unsigned __int8 a2, __int64 a3)
{
__int64 result; // rax

if ( !*(_BYTE *)(a3 + 24) )
result = pk_moveChar(a1, a2, a3 + 896);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 a2, __int64 a3)
{
__int64 result; // rax

if ( !*(_BYTE *)(a3 + 24) )
result = pk_moveChar(a1, a2, a3 + 896);
return result;
}

original_code:
void pk_pMove(int dir, _Bool move, player_t* player) {
 if(player->pause) {
  return;
 }
 pk_moveChar(dir, move, &player->mover);
}

canonical_original_code:
void pk_pMove(int dir, _Bool move, struct player_t *player) {
 if(player->pause) {
  return;
 }
 pk_moveChar(dir, move, &player->mover);
}

variable_types: dir int

variable_types: struct player_t { char name[12]; int sprite; _Bool pause; struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; } monsters[6]; struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } mover; } *


decompiled_code:
__int64 __fastcall pk_pgetFrame(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8)
{
return pk_getCharFrame(HIDWORD(a8));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8)
{
return pk_getCharFrame(HIDWORD(a8));
}

original_code:
int pk_pgetFrame(player_t player) {
 return pk_getCharFrame(player.sprite, player.mover);
}

canonical_original_code:
int pk_pgetFrame(struct player_t player) {
 return pk_getCharFrame(player.sprite, player.mover);
}

variable_types: struct player_t { char name[12]; int sprite; _Bool pause; struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; } monsters[6]; struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } mover; }


original_code:
void pk_initMap(int w, int h, map_t* map) {
 map->width = w;
 map->height = h;
 map->data = (char*)malloc(w*h*sizeof(char));
 map->cData = (char*)malloc(w*h*sizeof(char));
 map->mapAlloced = 1;
 map->doorAlloced = map->npcAlloced = map->tileColAlloced = 0;
}

canonical_original_code:
void pk_initMap(int w, int h, struct map_t *map) {
 map->width = w;
 map->height = h;
 map->data = (char *)malloc(w*h*sizeof(char));
 map->cData = (char *)malloc(w*h*sizeof(char));
 map->mapAlloced = 1;
 map->doorAlloced = map->npcAlloced = map->tileColAlloced = 0;
}

variable_types: w int

variable_types: h int

variable_types: struct map_t { int width; unsigned char *data; unsigned char *cData; unsigned char *tileColData; struct doorEntry_t { unsigned char dest; unsigned int x; unsigned int destX; unsigned int type; } *doorData; struct npcEntry_t { unsigned char value; unsigned int x; } *npcData; int doorCnt; _Bool doorAlloced; } *

user_defined_types: struct map_t { int width; unsigned char *data; unsigned char *cData; unsigned char *tileColData; struct doorEntry_t *doorData; struct npcEntry_t *npcData; int doorCnt; _Bool doorAlloced; }


original_code:
void pk_freeMap(map_t *map) {
 if(map->mapAlloced) {
  free(map->data);
  free(map->cData);
 }
 if(map->doorAlloced) {
  free(map->doorData);
 }
 if(map->npcAlloced) {
  free(map->npcData);
 }
 if(map->tileColAlloced) {
  free(map->tileColData);
 }
}

canonical_original_code:
void pk_freeMap(struct map_t *map) {
 if(map->mapAlloced) {
  free(map->data);
  free(map->cData);
 }
 if(map->doorAlloced) {
  free(map->doorData);
 }
 if(map->npcAlloced) {
  free(map->npcData);
 }
 if(map->tileColAlloced) {
  free(map->tileColData);
 }
}

user_defined_types: struct doorEntry_t { unsigned char dest; unsigned int x; unsigned int destX; unsigned int type; }

user_defined_types: struct npcEntry_t { unsigned char value; unsigned int x; }


original_code:
col_t pk_findCols(map_t map, int x, int y) {
 col_t out;
 out.left = 1; out.right = 1; out.up = 1; out.down = 1;
 if(x+1 >= map.width) {
  out.right = 0;
 } else if(x-1 < 0) {
  out.left = 0;
 }
 if(y+1 > map.height) {
  out.down = 0;
 } else if(y-1 < 0) {
  out.up = 0;
 }
 if(map.cData[x+((y-1)*map.width)] == 1) {
  out.up = 0;
 }
 if(map.cData[x+((y+1)*map.width)] == 1) {
  out.down = 0;
 }
 if(map.cData[x+1+(y*map.width)] == 1) {
  out.right = 0;
 }
 if(map.cData[x-1+(y*map.width)] == 1) {
  out.left = 0;
 }
 return out;
}

canonical_original_code:
struct col_t pk_findCols(struct map_t map, int x, int y) {
 struct col_t out;
 out.left = 1; out.right = 1; out.up = 1; out.down = 1;
 if(x+1 >= map.width) {
  out.right = 0;
 } else if(x-1 < 0) {
  out.left = 0;
 }
 if(y+1 > map.height) {
  out.down = 0;
 } else if(y-1 < 0) {
  out.up = 0;
 }
 if(map.cData[x+((y-1)*map.width)] == 1) {
  out.up = 0;
 }
 if(map.cData[x+((y+1)*map.width)] == 1) {
  out.down = 0;
 }
 if(map.cData[x+1+(y*map.width)] == 1) {
  out.right = 0;
 }
 if(map.cData[x-1+(y*map.width)] == 1) {
  out.left = 0;
 }
 return out;
}

variable_types: struct map_t { int width; unsigned char *data; unsigned char *cData; unsigned char *tileColData; struct doorEntry_t { unsigned char dest; unsigned int x; unsigned int destX; unsigned int type; } *doorData; struct npcEntry_t { unsigned char value; unsigned int x; } *npcData; int doorCnt; _Bool doorAlloced; }

variable_types: x int

variable_types: y int

variable_types:
out
struct col_t { _Bool left; }

return_type: struct col_t { _Bool left; }


decompiled_code:
__int64 __fastcall pk_isSolid(int a1, __int64 a2)
{
int v2; // edx
unsigned __int8 *v3; // rax
__int64 v4; // rcx

v2 = *(_DWORD *)(a2 + 56);
if ( v2 <= 0 )
return 1LL;
v3 = *(unsigned __int8 **)(a2 + 24);
v4 = (__int64)&v3[v2 - 1 + 1];
while ( *v3 != a1 )
{
if ( ++v3 == (unsigned __int8 *)v4 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
int v2; // edx
unsigned __int8 *v3; // rax
__int64 v4; // rcx

v2 = *(_DWORD *)(a2 + 56);
if ( v2 <= 0 )
return 1LL;
v3 = *(unsigned __int8 **)(a2 + 24);
v4 = (__int64)&v3[v2 - 1 + 1];
while ( *v3 != a1 )
{
if ( ++v3 == (unsigned __int8 *)v4 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool pk_isSolid(int val, map_t* map) {
 for(int i=0; i<map->tileColCnt; i++) {
  if(val == map->tileColData[i]) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool pk_isSolid(int val, struct map_t *map) {
 for(int i = 0; i<map->tileColCnt; i++) {
  if(val == map->tileColData[i]) {
   return 0;
  }
 }
 return 1;
}

variable_types: val int

variable_types: i int


decompiled_code:
__int64 __fastcall pk_buildColMapM(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp

result = (unsigned int)(*(_DWORD *)(a1 + 4) * *(_DWORD *)a1);
if ( (int)result > 0 )
{
v2 = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)(a1 + 16) + v2) = pk_isSolid(*(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + v2), a1);
++v2;
result = (unsigned int)(*(_DWORD *)(a1 + 4) * *(_DWORD *)a1);
}
while ( (int)result > (int)v2 );
}
return result;
}

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

result = (unsigned int)(*(_DWORD *)(a1 + 4) * *(_DWORD *)a1);
if ( (int)result > 0 )
{
v2 = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)(a1 + 16) + v2) = func3(*(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + v2), a1);
++v2;
result = (unsigned int)(*(_DWORD *)(a1 + 4) * *(_DWORD *)a1);
}
while ( (int)result > (int)v2 );
}
return result;
}

original_code:
void pk_buildColMapM(map_t* map) {
 for(int i=0; i<map->width*map->height; i++) {
  map->cData[i] = pk_isSolid(map->data[i], map);
 }
}

canonical_original_code:
void pk_buildColMapM(struct map_t *map) {
 for(int i = 0; i<map->width*map->height; i++) {
  map->cData[i] = pk_isSolid(map->data[i], map);
 }
}


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

result = (unsigned int)(*(_DWORD *)(a1 + 4) * *(_DWORD *)a1);
if ( (int)result > 0 )
{
result = 0LL;
do
*(_BYTE *)(*(_QWORD *)(a1 + 16) + result++) = 0;
while ( *(_DWORD *)(a1 + 4) * *(_DWORD *)a1 > (int)result );
}
return result;
}

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

result = (unsigned int)(*(_DWORD *)(a1 + 4) * *(_DWORD *)a1);
if ( (int)result > 0 )
{
result = 0LL;
do
*(_BYTE *)(*(_QWORD *)(a1 + 16) + result++) = 0;
while ( *(_DWORD *)(a1 + 4) * *(_DWORD *)a1 > (int)result );
}
return result;
}

original_code:
void pk_clearColMap(map_t* map) {
 for(int i=0; i<map->width*map->height; i++) {
  map->cData[i] = 0;
 }
}

canonical_original_code:
void pk_clearColMap(struct map_t *map) {
 for(int i = 0; i<map->width*map->height; i++) {
  map->cData[i] = 0;
 }
}


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

result = (unsigned int)(*(_DWORD *)(a2 + 4) * *(_DWORD *)a2);
if ( (int)result > 0 )
{
result = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)(a2 + 8) + result) = *(_BYTE *)(a1 + result);
++result;
}
while ( *(_DWORD *)(a2 + 4) * *(_DWORD *)a2 > (int)result );
}
return result;
}

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

result = (unsigned int)(*(_DWORD *)(a2 + 4) * *(_DWORD *)a2);
if ( (int)result > 0 )
{
result = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)(a2 + 8) + result) = *(_BYTE *)(a1 + result);
++result;
}
while ( *(_DWORD *)(a2 + 4) * *(_DWORD *)a2 > (int)result );
}
return result;
}

original_code:
void pk_setTileData(unsigned char *data, map_t* map) {
 for(int i=0; i<map->width*map->height; i++) {
  map->data[i] = data[i];
 }
}

canonical_original_code:
void pk_setTileData(unsigned char *data, struct map_t *map) {
 for(int i = 0; i<map->width*map->height; i++) {
  map->data[i] = data[i];
 }
}

variable_types:
data
unsigned char *


original_code:
void pk_setDoorData(int doorCnt, doorEntry_t* doorData, map_t* map) {
 if(map->doorAlloced) {
  free(map->doorData);
 }
 map->doorData = (doorEntry_t*)malloc(doorCnt*sizeof(doorEntry_t));
 map->doorAlloced = 1;
 for(int i=0; i<doorCnt; i++) {
  if(!pk_isSolid(map->data[doorData[i].x+(doorData[i].y*map->width)], map)) {
   doorData[i].type = 1;
  } else {
   doorData[i].type = 2;
  }
  map->doorData[i] = doorData[i];
 }
 map->doorCnt = doorCnt;
}

canonical_original_code:
void pk_setDoorData(int doorCnt, struct doorEntry_t *doorData, struct map_t *map) {
 if(map->doorAlloced) {
  free(map->doorData);
 }
 map->doorData = (struct doorEntry_t *)malloc(doorCnt*sizeof(doorEntry_t));
 map->doorAlloced = 1;
 for(int i = 0; i<doorCnt; i++) {
  if(!pk_isSolid(map->data[doorData[i].x+(doorData[i].y*map->width)], map)) {
   doorData[i].type = 1;
  } else {
   doorData[i].type = 2;
  }
  map->doorData[i] = doorData[i];
 }
 map->doorCnt = doorCnt;
}

variable_types: doorCnt int

variable_types: struct doorEntry_t { unsigned char dest; unsigned int x; unsigned int destX; unsigned int type; } *

variable_types: struct map_t { int width; unsigned char *data; unsigned char *cData; unsigned char *tileColData; struct doorEntry_t *doorData; struct npcEntry_t { unsigned char value; unsigned int x; } *npcData; int doorCnt; _Bool doorAlloced; } *


decompiled_code:
void *__fastcall pk_setNpcData(int a1, __int64 a2, __int64 a3)
{
void *result; // rax
__int64 v5; // rdx

if ( *(_BYTE *)(a3 + 61) )
free(*(void **)(a3 + 40));
result = malloc(12LL * a1);
*(_QWORD *)(a3 + 40) = result;
*(_BYTE *)(a3 + 61) = 1;
if ( a1 > 0 )
{
result = 0LL;
do
{
v5 = *(_QWORD *)(a3 + 40);
*(_QWORD *)((char *)result + v5) = *(_QWORD *)((char *)result + a2);
*(_DWORD *)((char *)result + v5 + 8) = *(_DWORD *)((char *)result + a2 + 8);
result = (char *)result + 12;
}
while ( result != (void *)(12LL * (unsigned int)a1) );
}
*(_DWORD *)(a3 + 52) = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int a1, __int64 a2, __int64 a3)
{
void *result; // rax
__int64 v5; // rdx

if ( *(_BYTE *)(a3 + 61) )
free(*(void **)(a3 + 40));
result = malloc(12LL * a1);
*(_QWORD *)(a3 + 40) = result;
*(_BYTE *)(a3 + 61) = 1;
if ( a1 > 0 )
{
result = 0LL;
do
{
v5 = *(_QWORD *)(a3 + 40);
*(_QWORD *)((char *)result + v5) = *(_QWORD *)((char *)result + a2);
*(_DWORD *)((char *)result + v5 + 8) = *(_DWORD *)((char *)result + a2 + 8);
result = (char *)result + 12;
}
while ( result != (void *)(12LL * (unsigned int)a1) );
}
*(_DWORD *)(a3 + 52) = a1;
return result;
}

original_code:
void pk_setNpcData(int npcCnt, npcEntry_t *npcData, map_t* map) {
 if(map->npcAlloced) {
  free(map->npcData);
 }
 map->npcData = (npcEntry_t*)malloc(npcCnt*sizeof(npcEntry_t));
 map->npcAlloced = 1;
 for(int i=0; i<npcCnt; i++) {
  map->npcData[i] = npcData[i];
 }
 map->npcCnt = npcCnt;
}

canonical_original_code:
void pk_setNpcData(int npcCnt, struct npcEntry_t *npcData, struct map_t *map) {
 if(map->npcAlloced) {
  free(map->npcData);
 }
 map->npcData = (struct npcEntry_t *)malloc(npcCnt*sizeof(npcEntry_t));
 map->npcAlloced = 1;
 for(int i = 0; i<npcCnt; i++) {
  map->npcData[i] = npcData[i];
 }
 map->npcCnt = npcCnt;
}

variable_types: npcCnt int

variable_types: struct npcEntry_t { unsigned char value; unsigned int x; } *

variable_types: struct map_t { int width; unsigned char *data; unsigned char *cData; unsigned char *tileColData; struct doorEntry_t { unsigned char dest; unsigned int x; unsigned int destX; unsigned int type; } *doorData; struct npcEntry_t *npcData; int doorCnt; _Bool doorAlloced; } *


original_code:
void pk_initChar(int s_x, int s_y, charMover_t* obj) {
 obj->x = s_x;
 obj->y = s_y;
 obj->lastX = s_x;
 obj->lastY = s_y;
 obj->nextX = s_x;
 obj->nextY = s_y;
 obj->dir = 2;
 obj->step = 0;
 obj->animCycle = 0;
}

canonical_original_code:
void pk_initChar(int s_x, int s_y, struct charMover_t *obj) {
 obj->x = s_x;
 obj->y = s_y;
 obj->lastX = s_x;
 obj->lastY = s_y;
 obj->nextX = s_x;
 obj->nextY = s_y;
 obj->dir = 2;
 obj->step = 0;
 obj->animCycle = 0;
}

variable_types: struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } *


decompiled_code:
__int64 __fastcall pk_getCharFrame(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, __int64 a10, char a11)
{
__int64 result; // rax

if ( HIDWORD(a10) == 3 )
{
result = (unsigned int)(a1 + 7);
if ( (int)a10 > 8 )
result = (unsigned int)(a11 == 0) + a1 + 8;
}
else if ( SHIDWORD(a10) > 3 )
{
if ( HIDWORD(a10) == 4 )
{
result = (unsigned int)(a1 + 4);
if ( (int)a10 > 8 )
result = (unsigned int)(a11 == 0) + a1 + 5;
}
else
{
result = 1LL;
}
}
else if ( HIDWORD(a10) == 1 )
{
result = (unsigned int)((int)a10 > 8) + a1 + 2;
}
else if ( HIDWORD(a10) == 2 )
{
result = a1 + (unsigned int)((int)a10 > 8);
}
else
{
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, __int64 a10, char a11)
{
__int64 result; // rax

if ( HIDWORD(a10) == 3 )
{
result = (unsigned int)(a1 + 7);
if ( (int)a10 > 8 )
result = (unsigned int)(a11 == 0) + a1 + 8;
}
else if ( SHIDWORD(a10) > 3 )
{
if ( HIDWORD(a10) == 4 )
{
result = (unsigned int)(a1 + 4);
if ( (int)a10 > 8 )
result = (unsigned int)(a11 == 0) + a1 + 5;
}
else
{
result = 1LL;
}
}
else if ( HIDWORD(a10) == 1 )
{
result = (unsigned int)((int)a10 > 8) + a1 + 2;
}
else if ( HIDWORD(a10) == 2 )
{
result = a1 + (unsigned int)((int)a10 > 8);
}
else
{
result = 1LL;
}
return result;
}

original_code:
int pk_getCharFrame(int spriteOffset, charMover_t obj) {
 switch(obj.dir) {
 case 2:
  if(obj.animCycle > 16/2) {
   return spriteOffset+1;
  } else {
   return spriteOffset;
  }
  break;
 case 1:
  if(obj.animCycle > 16/2) {
   return spriteOffset+3;
  } else {
   return spriteOffset+2;
  }
 case 3:
  if(obj.animCycle > 16/2) {
   if(obj.step) return spriteOffset+8;
   if(!obj.step) return spriteOffset+9;
  } else {
   return spriteOffset+7;
  }
  break;
 case 4:
  if(obj.animCycle > 16/2) {
   if(obj.step) return spriteOffset+5;
   if(!obj.step) return spriteOffset+6;
  } else {
   return spriteOffset+4;
  }
  break;
 }
 return 1;
}

canonical_original_code:
int pk_getCharFrame(int spriteOffset, struct charMover_t obj) {
 switch(obj.dir) {
 case 2:
  if(obj.animCycle > 16/2) {
   return spriteOffset+1;
  } else {
   return spriteOffset;
  }
  break;
 case 1:
  if(obj.animCycle > 16/2) {
   return spriteOffset+3;
  } else {
   return spriteOffset+2;
  }
 case 3:
  if(obj.animCycle > 16/2) {
   if(obj.step) return spriteOffset+8;
   if(!obj.step) return spriteOffset+9;
  } else {
   return spriteOffset+7;
  }
  break;
 case 4:
  if(obj.animCycle > 16/2) {
   if(obj.step) return spriteOffset+5;
   if(!obj.step) return spriteOffset+6;
  } else {
   return spriteOffset+4;
  }
  break;
 }
 return 1;
}

variable_types: spriteOffset int

variable_types: struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; }


decompiled_code:
__int64 __fastcall pk_faceChar(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, int a10, int a11, __int64 a12)
{
__int64 result; // rax

result = 2LL;
if ( (int)a7 <= (int)a12 )
{
result = 1LL;
if ( (int)a7 >= (int)a12 )
{
result = 4LL;
if ( SHIDWORD(a7) <= SHIDWORD(a12) )
result = 3LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, int a10, int a11, __int64 a12)
{
__int64 result; // rax

result = 2LL;
if ( (int)a7 <= (int)a12 )
{
result = 1LL;
if ( (int)a7 >= (int)a12 )
{
result = 4LL;
if ( SHIDWORD(a7) <= SHIDWORD(a12) )
result = 3LL;
}
}
return result;
}

original_code:
int pk_faceChar(charMover_t p, charMover_t t) {
 if(p.x > t.x) {
  return 2;
 } else if(p.x < t.x) {
  return 1;
 } else if(p.y > t.y) {
  return 4;
 } else if(p.y < t.y) {
  return 3;
 }
}

canonical_original_code:
int pk_faceChar(struct charMover_t p, struct charMover_t t) {
 if(p.x > t.x) {
  return 2;
 } else if(p.x < t.x) {
  return 1;
 } else if(p.y > t.y) {
  return 4;
 } else if(p.y < t.y) {
  return 3;
 }
}

variable_types:
t
struct charMover_t

user_defined_types: struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; }


decompiled_code:
bool __fastcall pk_isFinishedMoving(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
bool result; // al

result = 0;
if ( (_DWORD)a7 == (_DWORD)a8 )
result = HIDWORD(a7) == HIDWORD(a8);
return result;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
bool result; // al

result = 0;
if ( (_DWORD)a7 == (_DWORD)a8 )
result = HIDWORD(a7) == HIDWORD(a8);
return result;
}

original_code:
_Bool pk_isFinishedMoving(charMover_t obj) {
 if(obj.x == obj.nextX && obj.y == obj.nextY) {
  return 1;
 }
 return 0;
}

canonical_original_code:
_Bool pk_isFinishedMoving(struct charMover_t obj) {
 if(obj.x == obj.nextX && obj.y == obj.nextY) {
  return 1;
 }
 return 0;
}


original_code:
void pk_moveChar(int dir, _Bool move, charMover_t* obj) {
 if(pk_isFinishedMoving(*obj)) {
  if(dir == 2 && move) {
   obj->nextX = obj->x - 16;
   obj->nextY = obj->y;
  } else if(dir == 1 && move) {
   obj->nextX = obj->x + 16;
   obj->nextY = obj->y;
  } else if(dir == 3 && move) {
   obj->nextX = obj->x;
   obj->nextY = obj->y - 16;
  } else if(dir == 4 && move) {
   obj->nextX = obj->x;
   obj->nextY = obj->y + 16;
  }
  obj->dir = dir;
  if(obj->animCycle == 0) {
   obj->animCycle = 16;
   obj->step = !obj->step;
  }
 }
}

canonical_original_code:
void pk_moveChar(int dir, _Bool move, struct charMover_t *obj) {
 if(pk_isFinishedMoving(*obj)) {
  if(dir == 2 && move) {
   obj->nextX = obj->x - 16;
   obj->nextY = obj->y;
  } else if(dir == 1 && move) {
   obj->nextX = obj->x + 16;
   obj->nextY = obj->y;
  } else if(dir == 3 && move) {
   obj->nextX = obj->x;
   obj->nextY = obj->y - 16;
  } else if(dir == 4 && move) {
   obj->nextX = obj->x;
   obj->nextY = obj->y + 16;
  }
  obj->dir = dir;
  if(obj->animCycle == 0) {
   obj->animCycle = 16;
   obj->step = !obj->step;
  }
 }
}

variable_types: dir int


original_code:
void pk_updateChar(charMover_t* obj) {
 if(obj->x > obj->nextX) {
  obj->x--;
 } else if(obj->x < obj->nextX) {
  obj->x++;
 } else if(obj->y > obj->nextY) {
  obj->y--;
 } else if(obj->y < obj->nextY) {
  obj->y++;
 }
 if(obj->animCycle > 0) {
  obj->animCycle --;
 }
 if(pk_isFinishedMoving(*obj)) {
  obj->lastX = obj->x;
  obj->lastY = obj->y;
 }
}

canonical_original_code:
void pk_updateChar(struct charMover_t *obj) {
 if(obj->x > obj->nextX) {
  obj->x--;
 } else if(obj->x < obj->nextX) {
  obj->x++;
 } else if(obj->y > obj->nextY) {
  obj->y--;
 } else if(obj->y < obj->nextY) {
  obj->y++;
 }
 if(obj->animCycle > 0) {
  obj->animCycle --;
 }
 if(pk_isFinishedMoving(*obj)) {
  obj->lastX = obj->x;
  obj->lastY = obj->y;
 }
}


original_code:
void pk_clearWindow(window_t* window) {
 for(int y=0; y<window->h; y++) {
  for(int x=0; x<window->w; x++) {
   if(x==0 && y==0) {
    window->dispTiles[x+(y*window->w)] = 0 +69;
   } else if(x==window->w-1 && y==0) {
    window->dispTiles[x+(y*window->w)] = 0 +70;
   } else if(x==window->w-1 && y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +71;
   } else if(x==0 && y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +72;
   } else if(x==0 || x==window->w-1) {
    window->dispTiles[x+(y*window->w)] = 0 +74;
   } else if(y==0 || y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +73;
   } else {
    window->dispTiles[x+(y*window->w)] = 0 +62;
   }
  }
 }
}

canonical_original_code:
void pk_clearWindow(struct window_t *window) {
 for(int y = 0; y<window->h; y++) {
  for(int x = 0; x<window->w; x++) {
   if(x==0 && y==0) {
    window->dispTiles[x+(y*window->w)] = 0 +69;
   } else if(x==window->w-1 && y==0) {
    window->dispTiles[x+(y*window->w)] = 0 +70;
   } else if(x==window->w-1 && y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +71;
   } else if(x==0 && y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +72;
   } else if(x==0 || x==window->w-1) {
    window->dispTiles[x+(y*window->w)] = 0 +74;
   } else if(y==0 || y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +73;
   } else {
    window->dispTiles[x+(y*window->w)] = 0 +62;
   }
  }
 }
}

variable_types: struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; } *

variable_types: x int


original_code:
void pk_initWindow(int s_x, int s_y, int s_w, int s_h, _Bool s_closeable, _Bool dispDelay, window_t* window) {
 window->x = s_x;
 window->y = s_y;
 window->w = s_w;
 window->h = s_h;
 window->dispChar = window->startLag = 0;
 window->dispDelay = 3;
 window->optCnt = window->optW = window->optH = 0;
 window->active = window->finished = 0;
 window->closeable = s_closeable;
 window->selection = -1;
 window->scrollNumb = 1;
 pk_clearWindow(window);
}

canonical_original_code:
void pk_initWindow(int s_x, int s_y, int s_w, int s_h, _Bool s_closeable, _Bool dispDelay, struct window_t *window) {
 window->x = s_x;
 window->y = s_y;
 window->w = s_w;
 window->h = s_h;
 window->dispChar = window->startLag = 0;
 window->dispDelay = 3;
 window->optCnt = window->optW = window->optH = 0;
 window->active = window->finished = 0;
 window->closeable = s_closeable;
 window->selection = -1;
 window->scrollNumb = 1;
 pk_clearWindow(window);
}

user_defined_types: struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; }


decompiled_code:
__int64 __fastcall pk_moveSelArrow(int a1, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edx
int v5; // eax

switch ( a1 )
{
case 3:
if ( (int)a2[7] > 1 )
a2[4] -= a2[6];
break;
case 4:
if ( (int)a2[7] > 1 )
a2[4] += a2[6];
break;
case 1:
v5 = a2[6];
if ( v5 > 1 )
a2[4] += v5 - 1;
break;
case 2:
v2 = a2[6];
if ( v2 > 1 )
a2[4] -= v2 - 1;
break;
}
result = (unsigned int)a2[4];
if ( (int)result < 0 )
{
result = (unsigned int)(a2[5] + result);
a2[4] = result;
}
else
{
v4 = a2[5];
if ( (int)result >= v4 )
{
result = (unsigned int)(result - v4);
a2[4] = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edx
int v5; // eax

switch ( a1 )
{
case 3:
if ( (int)a2[7] > 1 )
a2[4] -= a2[6];
break;
case 4:
if ( (int)a2[7] > 1 )
a2[4] += a2[6];
break;
case 1:
v5 = a2[6];
if ( v5 > 1 )
a2[4] += v5 - 1;
break;
case 2:
v2 = a2[6];
if ( v2 > 1 )
a2[4] -= v2 - 1;
break;
}
result = (unsigned int)a2[4];
if ( (int)result < 0 )
{
result = (unsigned int)(a2[5] + result);
a2[4] = result;
}
else
{
v4 = a2[5];
if ( (int)result >= v4 )
{
result = (unsigned int)(result - v4);
a2[4] = result;
}
}
return result;
}

original_code:
void pk_moveSelArrow(int dir, window_t* window) {
 if(dir == 3) {
  if(window->optH > 1) {
   window->selOpt -= window->optW;
  }
 } else if(dir == 4) {
  if(window->optH > 1) {
   window->selOpt += window->optW;
  }
 } else if(dir == 1) {
  if(window->optW > 1) {
   window->selOpt += window->optW-1;
  }
 } else if(dir == 2) {
  if(window->optW > 1) {
   window->selOpt -= window->optW-1;
  }
 }
 if(window->selOpt < 0) {
  window->selOpt = window->optCnt + window->selOpt;
 } else if(window->selOpt >= window->optCnt) {
  window->selOpt = window->selOpt - window->optCnt;
 }
}

canonical_original_code:
void pk_moveSelArrow(int dir, struct window_t *window) {
 if(dir == 3) {
  if(window->optH > 1) {
   window->selOpt -= window->optW;
  }
 } else if(dir == 4) {
  if(window->optH > 1) {
   window->selOpt += window->optW;
  }
 } else if(dir == 1) {
  if(window->optW > 1) {
   window->selOpt += window->optW-1;
  }
 } else if(dir == 2) {
  if(window->optW > 1) {
   window->selOpt -= window->optW-1;
  }
 }
 if(window->selOpt < 0) {
  window->selOpt = window->optCnt + window->selOpt;
 } else if(window->selOpt >= window->optCnt) {
  window->selOpt = window->selOpt - window->optCnt;
 }
}


decompiled_code:
__int64 __fastcall pk_isWindowFinished(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15)
{
return BYTE6(a15);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15)
{
return BYTE6(a15);
}

original_code:
_Bool pk_isWindowFinished(window_t window) {
 return window.finished;
}

canonical_original_code:
_Bool pk_isWindowFinished(struct window_t window) {
 return window.finished;
}

variable_types: struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; }


decompiled_code:
__int64 __fastcall pk_getCharValue(unsigned __int8 a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 65) <= 0x19u )
return (unsigned int)a1 - 65;
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return (unsigned int)a1 - 71;
if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)a1 + 4;
switch ( a1 )
{
case ' ':
return 62LL;
case '+':
return 201LL;
case '^':
return 200LL;
case '!':
return 64LL;
case '?':
return 65LL;
case '.':
return 63LL;
case '"':
return 66LL;
case '|':
return 202LL;
case '/':
return 75LL;
}
result = 203LL;
if ( a1 != 123 )
result = 62LL;
return result;
}

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

if ( (unsigned __int8)(a1 - 65) <= 0x19u )
return (unsigned int)a1 - 65;
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return (unsigned int)a1 - 71;
if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)a1 + 4;
switch ( a1 )
{
case ' ':
return 62LL;
case '+':
return 201LL;
case '^':
return 200LL;
case '!':
return 64LL;
case '?':
return 65LL;
case '.':
return 63LL;
case '"':
return 66LL;
case '|':
return 202LL;
case '/':
return 75LL;
}
result = 203LL;
if ( a1 != 123 )
result = 62LL;
return result;
}

variable_types: c char


original_code:
void pk_updateWindow(window_t* window) {
 if(window->active) {
  if(window->startLag > 0) {
   window->startLag--;
   return;
  }
  if(window->dispChar < window->stop) {
   if(window->dispDelay <= 0) {
    window->dispChar++;
    window->dispDelay = 1;
   } else {
    window->dispDelay--;
   }
  }
  int x, y;
  x = y = 1;
  int lastOptDraw = 0;
  for(int i=window->start; i<window->dispChar; i++) {
   if(pk_getCharValue(window->text[i]) == 200) {
    x=1;
    y++;
   } else if(pk_getCharValue(window->text[i]) == 201) {
    if(lastOptDraw == window->selOpt) {
     window->dispTiles[x+(y*window->w)] = 0 +68;
    } else {
     window->dispTiles[x+(y*window->w)] = 0 +62;
    }
    x++;
    lastOptDraw++;
   } else {
    window->dispTiles[x+(y*window->w)] = pk_getCharValue(window->text[i]);
    x++;
   }
  }
 } else {
  window->dispDelay = 5;
 }
}

canonical_original_code:
void pk_updateWindow(struct window_t *window) {
 if(window->active) {
  if(window->startLag > 0) {
   window->startLag--;
   return;
  }
  if(window->dispChar < window->stop) {
   if(window->dispDelay <= 0) {
    window->dispChar++;
    window->dispDelay = 1;
   } else {
    window->dispDelay--;
   }
  }
  int x; int y;
  x = y = 1;
  int lastOptDraw = 0;
  for(int i = window->start; i<window->dispChar; i++) {
   if(pk_getCharValue(window->text[i]) == 200) {
    x=1;
    y++;
   } else if(pk_getCharValue(window->text[i]) == 201) {
    if(lastOptDraw == window->selOpt) {
     window->dispTiles[x+(y*window->w)] = 0 +68;
    } else {
     window->dispTiles[x+(y*window->w)] = 0 +62;
    }
    x++;
    lastOptDraw++;
   } else {
    window->dispTiles[x+(y*window->w)] = pk_getCharValue(window->text[i]);
    x++;
   }
  }
 } else {
  window->dispDelay = 5;
 }
}

variable_types: y int

variable_types: lastOptDraw int

variable_types: i int


decompiled_code:
__int64 __fastcall pk_fullWindowScroll(int a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp
__int64 result; // rax
int v5; // er13
__int64 v6; // rbx

pk_clearWindow((_DWORD *)a2);
v2 = 0LL;
v3 = 0;
while ( 1 )
{
result = (unsigned int)pk_getCharValue(*(_BYTE *)(a2 + v2 + 72)) == 203;
v3 += result;
if ( v3 == a1 )
break;
if ( ++v2 == 128 )
goto LABEL_6;
}
*(_DWORD *)(a2 + 52) = v2 + 1;
LABEL_6:
v5 = *(_DWORD *)(a2 + 52);
if ( v5 <= 127 )
{
v6 = v5;
while ( 1 )
{
result = (unsigned int)pk_getCharValue(*(_BYTE *)(a2 + v6 + 72)) - 202;
if ( (unsigned int)result <= 1 )
break;
if ( (int)++v6 > 127 )
goto LABEL_12;
}
*(_DWORD *)(a2 + 56) = v6;
}
LABEL_12:
if ( !*(_BYTE *)(a2 + 69) )
v5 = *(_DWORD *)(a2 + 56);
*(_DWORD *)(a2 + 36) = v5;
return result;
}

original_code:
void pk_fullWindowScroll(int scrollCnt, window_t* window) {
 pk_clearWindow(window);
 int cnt = 0;
 for(int i=0; i<128; i++) {
  if(pk_getCharValue(window->text[i]) == 203) {
   cnt++;
  }
  if(cnt == scrollCnt) {
   window->start = i+1;
   break;
  }
 }
 for(int i=window->start; i<128; i++) {
  if(pk_getCharValue(window->text[i]) == 203 || pk_getCharValue(window->text[i]) == 202) {
   window->stop = i;
   break;
  }
 }
 if(window->txtScroll) {
  window->dispChar = window->start;
 } else {
  window->dispChar = window->stop;
 }
}

canonical_original_code:
void pk_fullWindowScroll(int scrollCnt, struct window_t *window) {
 pk_clearWindow(window);
 int cnt = 0;
 for(int i = 0; i<128; i++) {
  if(pk_getCharValue(window->text[i]) == 203) {
   cnt++;
  }
  if(cnt == scrollCnt) {
   window->start = i+1;
   break;
  }
 }
 for(int i = window->start; i<128; i++) {
  if(pk_getCharValue(window->text[i]) == 203 || pk_getCharValue(window->text[i]) == 202) {
   window->stop = i;
   break;
  }
 }
 if(window->txtScroll) {
  window->dispChar = window->start;
 } else {
  window->dispChar = window->stop;
 }
}

variable_types: scrollCnt int

variable_types: cnt int


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

if ( *(int *)(a1 + 44) <= 0 )
{
result = *(unsigned __int8 *)(a1 + 68) ^ 1u;
*(_BYTE *)(a1 + 68) ^= 1u;
if ( (_BYTE)result )
{
pk_clearWindow((_DWORD *)a1);
*(_BYTE *)(a1 + 70) = 0;
*(_DWORD *)(a1 + 44) = 10;
*(_DWORD *)(a1 + 60) = 1;
result = pk_fullWindowScroll(1, a1);
if ( *(_BYTE *)(a1 + 69) )
*(_DWORD *)(a1 + 36) = 0;
}
}
return result;
}

original_code:
void pk_toggleWindow(window_t* window) {
 if(window->startLag <= 0) {
  window->active = !window->active;
  if(window->active) {
   pk_clearWindow(window);
   window->finished = 0;
   window->startLag = 10;
   window->scrollNumb = 1;
   pk_fullWindowScroll(1, window);
   if(window->txtScroll) {
    window->dispChar = 0;
   }
  }
 }
}

canonical_original_code:
void pk_toggleWindow(struct window_t *window) {
 if(window->startLag <= 0) {
  window->active = !window->active;
  if(window->active) {
   pk_clearWindow(window);
   window->finished = 0;
   window->startLag = 10;
   window->scrollNumb = 1;
   pk_fullWindowScroll(1, window);
   if(window->txtScroll) {
    window->dispChar = 0;
   }
  }
 }
}


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

result = *(unsigned int *)(a1 + 32);
if ( *(_DWORD *)(a1 + 36) >= (int)result )
{
if ( *(_BYTE *)(a1 + 71) )
{
result = pk_toggleWindow(a1);
*(_DWORD *)(a1 + 48) = 255;
}
}
return result;
}

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

result = *(unsigned int *)(a1 + 32);
if ( *(_DWORD *)(a1 + 36) >= (int)result )
{
if ( *(_BYTE *)(a1 + 71) )
{
result = func7(a1);
*(_DWORD *)(a1 + 48) = 255;
}
}
return result;
}

original_code:
void pk_scrollWindowText(window_t* window) {
 if(window->dispChar < window->strLength) {
 } else if(window->closeable) {
  pk_toggleWindow(window);
  window->selection = 255;
 }
}

canonical_original_code:
void pk_scrollWindowText(struct window_t *window) {
 if(window->dispChar < window->strLength) {
 } else if(window->closeable) {
  pk_toggleWindow(window);
  window->selection = 255;
 }
}


decompiled_code:
__int64 __fastcall pk_selectWindow(__int64 a1)
{
__int64 result; // rax
int v2; // edx
int v3; // eax

result = *(unsigned int *)(a1 + 36);
if ( (int)result < *(_DWORD *)(a1 + 32) )
goto LABEL_13;
v2 = *(_DWORD *)(a1 + 20);
if ( v2 > 0 )
{
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 48) = result;
return result;
}
if ( v2 )
{
LABEL_13:
if ( (int)result >= *(_DWORD *)(a1 + 56) )
{
result = *(unsigned int *)(a1 + 60);
if ( (int)result < *(_DWORD *)(a1 + 64) )
{
v3 = result + 1;
*(_DWORD *)(a1 + 60) = v3;
result = pk_fullWindowScroll(v3, a1);
}
}
}
else
{
*(_BYTE *)(a1 + 70) = 1;
if ( *(_BYTE *)(a1 + 71) )
*(_BYTE *)(a1 + 68) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
int v2; // edx
int v3; // eax

result = *(unsigned int *)(a1 + 36);
if ( (int)result < *(_DWORD *)(a1 + 32) )
goto LABEL_13;
v2 = *(_DWORD *)(a1 + 20);
if ( v2 > 0 )
{
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 48) = result;
return result;
}
if ( v2 )
{
LABEL_13:
if ( (int)result >= *(_DWORD *)(a1 + 56) )
{
result = *(unsigned int *)(a1 + 60);
if ( (int)result < *(_DWORD *)(a1 + 64) )
{
v3 = result + 1;
*(_DWORD *)(a1 + 60) = v3;
result = func6(v3, a1);
}
}
}
else
{
*(_BYTE *)(a1 + 70) = 1;
if ( *(_BYTE *)(a1 + 71) )
*(_BYTE *)(a1 + 68) = 0;
}
return result;
}

original_code:
void pk_selectWindow(window_t* window) {
 if(window->dispChar >= window->strLength && window->optCnt > 0) {
  window->selection = window->selOpt;
 } else if(window->dispChar >= window->strLength && window->optCnt == 0) {
  window->finished = 1;
  if(window->closeable) {
   window->active = 0;
  }
 } else if(window->dispChar >= window->stop && window->scrollNumb < window->scrollCnt) {
  window->scrollNumb++;
  pk_fullWindowScroll(window->scrollNumb, window);
 }
}

canonical_original_code:
void pk_selectWindow(struct window_t *window) {
 if(window->dispChar >= window->strLength && window->optCnt > 0) {
  window->selection = window->selOpt;
 } else if(window->dispChar >= window->strLength && window->optCnt == 0) {
  window->finished = 1;
  if(window->closeable) {
   window->active = 0;
  }
 } else if(window->dispChar >= window->stop && window->scrollNumb < window->scrollCnt) {
  window->scrollNumb++;
  pk_fullWindowScroll(window->scrollNumb, window);
 }
}


original_code:
void pk_setWindowText(char* s_text, _Bool s_txtScroll, window_t* window) {
 pk_clearWindow(window);
 window->txtScroll = s_txtScroll;
 window->optCnt = 0;
 window->optW = window->optH = 0;
 window->scrollCnt = 0;
 window->scrollNumb = 1;
 int inc = 0;
 _Bool settingWidth = 1;
 while(pk_getCharValue(s_text[inc]) != 202) {
  window->text[inc] = s_text[inc];
  if(pk_getCharValue(s_text[inc]) == 200 && window->optCnt != 0) {
   settingWidth = 0;
   window->optH++;
  }
  if(pk_getCharValue(s_text[inc]) == 201) {
   window->optCnt++;
   if(settingWidth) {
    window->optW++;
   }
  }
  if(pk_getCharValue(s_text[inc]) == 203) {
   window->scrollCnt++;
  }
  inc++;
 }
 window->text[inc] = '|';
 if(window->txtScroll) {
  window->dispChar = 0;
 } else {
  window->dispChar = inc;
 }
 window->strLength = inc;
 window->finished = 0;
 pk_fullWindowScroll(window->scrollNumb, window);
}

canonical_original_code:
void pk_setWindowText(char *s_text, _Bool s_txtScroll, struct window_t *window) {
 pk_clearWindow(window);
 window->txtScroll = s_txtScroll;
 window->optCnt = 0;
 window->optW = window->optH = 0;
 window->scrollCnt = 0;
 window->scrollNumb = 1;
 int inc = 0;
 _Bool settingWidth = 1;
 while(pk_getCharValue(s_text[inc]) != 202) {
  window->text[inc] = s_text[inc];
  if(pk_getCharValue(s_text[inc]) == 200 && window->optCnt != 0) {
   settingWidth = 0;
   window->optH++;
  }
  if(pk_getCharValue(s_text[inc]) == 201) {
   window->optCnt++;
   if(settingWidth) {
    window->optW++;
   }
  }
  if(pk_getCharValue(s_text[inc]) == 203) {
   window->scrollCnt++;
  }
  inc++;
 }
 window->text[inc] = '|';
 if(window->txtScroll) {
  window->dispChar = 0;
 } else {
  window->dispChar = inc;
 }
 window->strLength = inc;
 window->finished = 0;
 pk_fullWindowScroll(window->scrollNumb, window);
}

variable_types: inc int


decompiled_code:
__int64 __fastcall pk_setInsWindowText(__int64 a1, __int64 a2, int a3, int a4, char a5, __int64 a6)
{
_BYTE *v7; // r12
__int64 i; // rbx
unsigned __int8 v9; // bp
__int64 v10; // rax

v7 = malloc(0x80uLL);
for ( i = 0LL; ; ++i )
{
v9 = *(_BYTE *)(a1 + i);
if ( (unsigned int)pk_getCharValue(v9) == 202 )
break;
v7[i] = v9;
}
if ( a4 > 0 )
{
v10 = 0LL;
do
{
v7[a3 + v10] = *(_BYTE *)(a2 + v10);
++v10;
}
while ( v10 != a4 );
}
v7[i] = 124;
return pk_setWindowText((__int64)v7, a5, a6);
}

original_code:
void pk_setInsWindowText(char* baseText, char* insText, int insStart, int insLen, _Bool txtScroll, window_t* window) {
 char* text = (char*)malloc(128*sizeof(char));
 int inc = 0;
 while(pk_getCharValue(baseText[inc]) != 202) {
  text[inc] = baseText[inc];
  inc++;
 }
 for(int i=0; i<insLen; i++) {
  text[insStart+i] = insText[i];
 }
 text[inc] = '|';
 pk_setWindowText(text, txtScroll, window);
}

canonical_original_code:
void pk_setInsWindowText(char *baseText, char *insText, int insStart, int insLen, _Bool txtScroll, struct window_t *window) {
 char *text = (char*)malloc(128*sizeof(char));
 int inc = 0;
 while(pk_getCharValue(baseText[inc]) != 202) {
  text[inc] = baseText[inc];
  inc++;
 }
 for(int i = 0; i<insLen; i++) {
  text[insStart+i] = insText[i];
 }
 text[inc] = '|';
 pk_setWindowText(text, txtScroll, window);
}

variable_types:
baseText
char *

variable_types:
insText
char *

variable_types: insStart int

variable_types: insLen int

variable_types:
text
char *


original_code:
void pk_updateNpc(npc_t* npc, col_t col) {
 if(npc->mover.animCycle > 16) {
  npc->mover.animCycle = 0;
 }
 switch(npc->aiType) {
 case 1:
  if(npc->actClock <= 0 && !npc->pause) {
   if(npc->mover.dir == 2) {
    npc->mover.dir = 3;
   } else if(npc->mover.dir == 3) {
    npc->mover.dir = 1;
   } else if(npc->mover.dir == 1) {
    npc->mover.dir = 4;
   } else if(npc->mover.dir == 4) {
    npc->mover.dir = 2;
   }
   npc->actClock = 50;
  } else if (!npc->pause) {
   npc->actClock--;
  }
  break;
 case 3:
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   if(npc->mover.x < npc->destX[npc->dest]) {
    pk_moveChar(1, col.right, &npc->mover);
   } else if(npc->mover.x > npc->destX[npc->dest]) {
    pk_moveChar(2, col.left, &npc->mover);
   }
   if(npc->mover.y < npc->destY[npc->dest]) {
    pk_moveChar(3, col.up, &npc->mover);
   } else if(npc->mover.y > npc->destY[npc->dest]) {
    pk_moveChar(4, col.down, &npc->mover);
   }
  }
  pk_updateChar(&npc->mover);
  if(npc->mover.x == npc->destX[npc->dest] && npc->mover.y == npc->destY[npc->dest]) {
   if(npc->dest == 0) {
    npc->dest = 1;
   } else {
    npc->dest = 0;
   }
  }
  break;
 case 4:
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   int randDir = rand() % 150 + 1;
   switch(randDir) {
    case 2:
     pk_moveChar(2, col.left, &npc->mover);
     break;
    case 1:
     pk_moveChar(1, col.right, &npc->mover);
     break;
    case 4:
     pk_moveChar(4, col.down, &npc->mover);
     break;
    case 3:
     pk_moveChar(3, col.up, &npc->mover);
     break;
   }
  }
  pk_updateChar(&npc->mover);
  break;
 case 5:
  if(npc->actClock > 0) {
   npc->actClock--;
   break;
  }
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   if(npc->mover.x < npc->destX[npc->dest]) {
    pk_moveChar(1, 1, &npc->mover);
   } else if(npc->mover.x > npc->destX[npc->dest]) {
    pk_moveChar(2, 1, &npc->mover);
   }
   if(npc->mover.y < npc->destY[npc->dest]) {
    pk_moveChar(4, 1, &npc->mover);
   } else if(npc->mover.y > npc->destY[npc->dest]) {
    pk_moveChar(3, 1, &npc->mover);
   }
  }
  pk_updateChar(&npc->mover);
  break;
 }
 pk_updateWindow(&npc->dialog);
}

canonical_original_code:
void pk_updateNpc(struct npc_t *npc, struct col_t col) {
 if(npc->mover.animCycle > 16) {
  npc->mover.animCycle = 0;
 }
 switch(npc->aiType) {
 case 1:
  if(npc->actClock <= 0 && !npc->pause) {
   if(npc->mover.dir == 2) {
    npc->mover.dir = 3;
   } else if(npc->mover.dir == 3) {
    npc->mover.dir = 1;
   } else if(npc->mover.dir == 1) {
    npc->mover.dir = 4;
   } else if(npc->mover.dir == 4) {
    npc->mover.dir = 2;
   }
   npc->actClock = 50;
  } else if (!npc->pause) {
   npc->actClock--;
  }
  break;
 case 3:
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   if(npc->mover.x < npc->destX[npc->dest]) {
    pk_moveChar(1, col.right, &npc->mover);
   } else if(npc->mover.x > npc->destX[npc->dest]) {
    pk_moveChar(2, col.left, &npc->mover);
   }
   if(npc->mover.y < npc->destY[npc->dest]) {
    pk_moveChar(3, col.up, &npc->mover);
   } else if(npc->mover.y > npc->destY[npc->dest]) {
    pk_moveChar(4, col.down, &npc->mover);
   }
  }
  pk_updateChar(&npc->mover);
  if(npc->mover.x == npc->destX[npc->dest] && npc->mover.y == npc->destY[npc->dest]) {
   if(npc->dest == 0) {
    npc->dest = 1;
   } else {
    npc->dest = 0;
   }
  }
  break;
 case 4:
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   int randDir = rand() % 150 + 1;
   switch(randDir) {
    case 2:
     pk_moveChar(2, col.left, &npc->mover);
     break;
    case 1:
     pk_moveChar(1, col.right, &npc->mover);
     break;
    case 4:
     pk_moveChar(4, col.down, &npc->mover);
     break;
    case 3:
     pk_moveChar(3, col.up, &npc->mover);
     break;
   }
  }
  pk_updateChar(&npc->mover);
  break;
 case 5:
  if(npc->actClock > 0) {
   npc->actClock--;
   break;
  }
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   if(npc->mover.x < npc->destX[npc->dest]) {
    pk_moveChar(1, 1, &npc->mover);
   } else if(npc->mover.x > npc->destX[npc->dest]) {
    pk_moveChar(2, 1, &npc->mover);
   }
   if(npc->mover.y < npc->destY[npc->dest]) {
    pk_moveChar(4, 1, &npc->mover);
   } else if(npc->mover.y > npc->destY[npc->dest]) {
    pk_moveChar(3, 1, &npc->mover);
   }
  }
  pk_updateChar(&npc->mover);
  break;
 }
 pk_updateWindow(&npc->dialog);
}

variable_types: struct npc_t { int destX[2]; int destY[2]; int reach; _Bool fought; struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; } monsters[6]; struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } mover; struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; } dialog; char msg1[128]; char msg2[128]; char msg3[128]; } *

variable_types:
col
struct col_t { _Bool left; }

variable_types: randDir int

user_defined_types: struct npc_t { int destX[2]; int destY[2]; int reach; _Bool fought; struct monster_t monsters[6]; struct charMover_t mover; struct window_t dialog; char msg1[128]; char msg2[128]; char msg3[128]; }


decompiled_code:
unsigned __int64 __fastcall pk_setNpcWindow(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned __int64 result; // rax

*(_QWORD *)(a1 + 948) = a7;
result = STACK[0xCC8];
*(_QWORD *)(a1 + 4212) = STACK[0xCC8];
qmemcpy(
(void *)((a1 + 956) & 0xFFFFFFFFFFFFFFF8LL),
(char *)&a7 - (a1 + 948 - ((a1 + 956) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((_DWORD)a1 + 948 - (((_DWORD)a1 + 956) & 0xFFFFFFF8) + 3272) >> 3));
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned __int64 result; // rax

*(_QWORD *)(a1 + 948) = a7;
result = STACK[0xCC8];
*(_QWORD *)(a1 + 4212) = STACK[0xCC8];
qmemcpy(
(void *)((a1 + 956) & 0xFFFFFFFFFFFFFFF8LL),
(char *)&a7 - (a1 + 948 - ((a1 + 956) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((_DWORD)a1 + 948 - (((_DWORD)a1 + 956) & 0xFFFFFFF8) + 3272) >> 3));
return result;
}

original_code:
void pk_setNpcWindow(window_t s_wind, npc_t* trainer) {
 trainer->dialog = s_wind;
}

canonical_original_code:
void pk_setNpcWindow(struct window_t s_wind, struct npc_t *trainer) {
 trainer->dialog = s_wind;
}

variable_types: struct npc_t { int destX[2]; int destY[2]; int reach; _Bool fought; struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; } monsters[6]; struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } mover; struct window_t dialog; char msg1[128]; char msg2[128]; char msg3[128]; } *


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

switch ( a1 )
{
case 2:
return pk_setWindowText(a2 + 4348, 1LL, a2 + 948);
case 3:
return pk_setWindowText(a2 + 4476, 1LL, a2 + 948);
case 1:
result = pk_setWindowText(a2 + 4220, 1LL, a2 + 948);
break;
}
return result;
}

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

switch ( a1 )
{
case 2:
return pk_setWindowText(a2 + 4348, 1LL, a2 + 948);
case 3:
return pk_setWindowText(a2 + 4476, 1LL, a2 + 948);
case 1:
result = pk_setWindowText(a2 + 4220, 1LL, a2 + 948);
break;
}
return result;
}

original_code:
void pk_switchMessage(int val, npc_t* trainer) {
 switch(val) {
 case 1:
  pk_setWindowText(&trainer->msg1[0], 1, &trainer->dialog);
  break;
 case 2:
  pk_setWindowText(&trainer->msg2[0], 1, &trainer->dialog);
  break;
 case 3:
  pk_setWindowText(&trainer->msg3[0], 1, &trainer->dialog);
  break;
 }
}

canonical_original_code:
void pk_switchMessage(int val, struct npc_t *trainer) {
 switch(val) {
 case 1:
  pk_setWindowText(&trainer->msg1[0], 1, &trainer->dialog);
  break;
 case 2:
  pk_setWindowText(&trainer->msg2[0], 1, &trainer->dialog);
  break;
 case 3:
  pk_setWindowText(&trainer->msg3[0], 1, &trainer->dialog);
  break;
 }
}

variable_types: val int

user_defined_types: struct moveMask_t { int cpp; int value; }

user_defined_types: struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; }

user_defined_types: struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; }

user_defined_types: struct monExperience_f { unsigned char type; }

user_defined_types: struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; }

user_defined_types: struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; }

user_defined_types: struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; }

user_defined_types: struct monNatMoveEntry_f { unsigned int move; unsigned char level; }


original_code:
void pk_setNpcMonster(monster_t mon, npc_t* trainer) {
 if(trainer->monCnt > 5) {
  printf("[ERROR] Max monster count reached on NPC!\n");
  return;
 }
 trainer->monsters[trainer->monCnt] = mon;
 trainer->monCnt++;
}

canonical_original_code:
void pk_setNpcMonster(struct monster_t mon, struct npc_t *trainer) {
 if(trainer->monCnt > 5) {
  printf("[ERROR] Max monster count reached on NPC!\n");
  return;
 }
 trainer->monsters[trainer->monCnt] = mon;
 trainer->monCnt++;
}

variable_types: struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; }

variable_types: struct npc_t { int destX[2]; int destY[2]; int reach; _Bool fought; struct monster_t monsters[6]; struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } mover; struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; } dialog; char msg1[128]; char msg2[128]; char msg3[128]; } *

user_defined_types: struct monster_t { int experience; char name[10]; struct monFileObj_t *id; _Bool shiny; struct stats_t stats; struct moveMask_t moves[4]; int condition; }


decompiled_code:
__int64 __fastcall pk_getNpcFrame(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, __int64 a9)
{
return pk_getCharFrame(HIDWORD(a9));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, __int64 a9)
{
return pk_getCharFrame(HIDWORD(a9));
}

original_code:
int pk_getNpcFrame(npc_t npc) {
 return pk_getCharFrame(npc.sprite, npc.mover);
}

canonical_original_code:
int pk_getNpcFrame(struct npc_t npc) {
 return pk_getCharFrame(npc.sprite, npc.mover);
}

variable_types: struct npc_t { int destX[2]; int destY[2]; int reach; _Bool fought; struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; } monsters[6]; struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } mover; struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; } dialog; char msg1[128]; char msg2[128]; char msg3[128]; }

user_defined_types: struct monFileObj_t { struct monBasic_f basic; struct monStats_f stats; struct monMovelist_f movelist; struct monExperience_f experience; struct monEvolution_f evolution; struct monAesthetics_f aesthetics; struct monOthers_f etc; }


decompiled_code:
void __fastcall pk_toggleNpcPause(__int64 a1)
{
*(_BYTE *)(a1 + 46) ^= 1u;
}

original_code:
void pk_toggleNpcPause(npc_t* npc) {
 npc->pause = !npc->pause;
}

canonical_original_code:
void pk_toggleNpcPause(struct npc_t *npc) {
 npc->pause = !npc->pause;
}

user_defined_types: struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; }