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

v2 = (char *)pool_alloc(2LL, "vattr_hashstats", 257LL, "vattr.c");
sprintf(
v2,
"Vattr stats: %d size, %d alloc, %d free, %d name lookups\r\n",
24LL,
(unsigned int)vstats_count,
(unsigned int)vstats_freecnt,
(unsigned int)vstats_lookups);
notify_check(a1, a1, v2, 0LL, 3085LL, 0LL);
return pool_free(2LL, &v2, 268LL, "vattr.c");
}

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

v2 = (char *)pool_alloc(2LL, "vattr_hashstats", 257LL, "vattr.c");
sprintf(
v2,
"Vattr stats: %d size, %d alloc, %d free, %d name lookups\r\n",
24LL,
(unsigned int)vstats_count,
(unsigned int)vstats_freecnt,
(unsigned int)vstats_lookups);
notify_check(a1, a1, v2, 0LL, 3085LL, 0LL);
return pool_free(2LL, &v2, 268LL, "vattr.c");
}

original_code:
void list_vhashstats(dbref player)
{
char *buff;
 buff = pool_alloc(2,"vattr_hashstats",257,"vattr.c");
 sprintf(buff, "Vattr stats:  %d size, %d alloc, %d free, %d name lookups\r\n",
  sizeof(VATTR), vstats_count, vstats_freecnt, vstats_lookups);
 notify_check(player,player,buff,0, 1|(2048|8|1024)|(4), 0);
 pool_free(2,((char **)&(buff)),268,"vattr.c");
}

canonical_original_code:
void list_vhashstats(int player)
{
char *buff;
 buff = pool_alloc(2,"vattr_hashstats",257,"vattr.c");
 sprintf(buff, "Vattr stats:  %d size, %d alloc, %d free, %d name lookups\r\n",
  sizeof(VATTR), vstats_count, vstats_freecnt, vstats_lookups);
 notify_check(player,player,buff,0, 1|(2048|8|1024)|(4), 0);
 pool_free(2,((char **)&(buff)),268,"vattr.c");
}

variable_types: player int

variable_types:
buff
char *


repo: kenneaal/RhostMUSH

decompiled_code:
__int64 sum_vhashstats()
{
return (unsigned int)(vstats_name_cnt + 24 * vstats_count);
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned int)(vstats_name_cnt + 24 * vstats_count);
}

original_code:
int sum_vhashstats(dbref player)
{
   int val;
   val = (sizeof(VATTR) * vstats_count) + vstats_name_cnt;
   return(val);
}

canonical_original_code:
int sum_vhashstats(int player)
{
   int val;
   val = (sizeof(VATTR) * vstats_count) + vstats_name_cnt;
   return(val);
}

variable_types: val int

return_type: int


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

result = (unsigned int)-mudstate[224];
if ( (int)result < 0 || mudstate[224] == 0 )
result = 1LL;
return result;
}

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

result = (unsigned int)-mudstate[224];
if ( (int)result < 0 || mudstate[224] == 0 )
result = 1LL;
return result;
}

original_code:
int next_timer(void)
{
int result;
 result = mudstate.dump_counter;
 if (mudstate.check_counter < result)
  result = mudstate.check_counter;
 if (mudstate.idle_counter < result)
  result = mudstate.idle_counter;
 if (mudstate.rwho_counter < result)
  result = mudstate.rwho_counter;
 if (mudstate.mstats_counter < result)
  result = mudstate.mstats_counter;
 result =- mudstate.now;
 if (result <= 0)
  result = 1;
 return result;
}

canonical_original_code:
int next_timer()
{
int result;
 result = mudstate.dump_counter;
 if (mudstate.check_counter < result)
  result = mudstate.check_counter;
 if (mudstate.idle_counter < result)
  result = mudstate.idle_counter;
 if (mudstate.rwho_counter < result)
  result = mudstate.rwho_counter;
 if (mudstate.mstats_counter < result)
  result = mudstate.mstats_counter;
 result =- mudstate.now;
 if (result <= 0)
  result = 1;
 return result;
}

variable_types: result int


decompiled_code:
unsigned int init_timer()
{
time_t v0; // rax
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rsi
__int64 v4; // rdx
unsigned int v5; // eax

mudstate[113] = mudstate[112];
v0 = time(0LL);
v1 = mudconf[1805];
v2 = mudconf[1803];
mudstate[112] = v0;
if ( !(_DWORD)v1 )
v1 = v2;
v3 = mudconf[1804];
mudstate[114] = v0 + v1;
v4 = mudconf[1806];
if ( !(_DWORD)v4 )
v4 = v3;
mudstate[115] = v0 + v4;
mudstate[116] = v0 + mudconf[1809];
mudstate[117] = v0 + mudconf[2005];
mudstate[118] = v0 + 15;
v5 = next_timer();
return alarm(v5);
}

canonical_decompiled_code:
unsigned int func1()
{
time_t v0; // rax
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rsi
__int64 v4; // rdx
unsigned int v5; // eax

mudstate[113] = mudstate[112];
v0 = time(0LL);
v1 = mudconf[1805];
v2 = mudconf[1803];
mudstate[112] = v0;
if ( !(_DWORD)v1 )
v1 = v2;
v3 = mudconf[1804];
mudstate[114] = v0 + v1;
v4 = mudconf[1806];
if ( !(_DWORD)v4 )
v4 = v3;
mudstate[115] = v0 + v4;
mudstate[116] = v0 + mudconf[1809];
mudstate[117] = v0 + mudconf[2005];
mudstate[118] = v0 + 15;
v5 = func0();
return alarm(v5);
}

original_code:
void init_timer(void)
{
 mudstate.lastnow = mudstate.now;
 mudstate.now = time(((void *)0));
 mudstate.dump_counter = ((mudconf.dump_offset == 0) ?
  mudconf.dump_interval : mudconf.dump_offset) + mudstate.now;
 mudstate.check_counter = ((mudconf.check_offset == 0) ?
  mudconf.check_interval : mudconf.check_offset) + mudstate.now;
 mudstate.idle_counter = mudconf.idle_interval + mudstate.now;
 mudstate.rwho_counter = mudconf.rwho_interval + mudstate.now;
 mudstate.mstats_counter = 15 + mudstate.now;
 alarm (next_timer());
}

canonical_original_code:
void init_timer()
{
 mudstate.lastnow = mudstate.now;
 mudstate.now = time(((void *)0));
 mudstate.dump_counter = ((mudconf.dump_offset == 0) ?
  mudconf.dump_interval : mudconf.dump_offset) + mudstate.now;
 mudstate.check_counter = ((mudconf.check_offset == 0) ?
  mudconf.check_interval : mudconf.check_offset) + mudstate.now;
 mudstate.idle_counter = mudconf.idle_interval + mudstate.now;
 mudstate.rwho_counter = mudconf.rwho_interval + mudstate.now;
 mudstate.mstats_counter = 15 + mudstate.now;
 alarm (next_timer());
}

return_type: void


dispatch

decompiled_code:
unsigned int dispatch()
{
unsigned int result; // eax
__int64 v1; // rbx
__int64 v2; // rax
int v3; // edx
__int64 v4; // rax
int v5; // edx
unsigned int v6; // eax
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
int v11; // ebp
int v12; // ecx
__int64 v13; // rax
__int64 v14; // rdx
struct rusage v15; // [rsp+0h] [rbp-A8h] BYREF

result = HIDWORD(mudstate[111]);
v1 = mudstate[188];
mudstate[188] = "< dispatch >";
if ( result )
{
v2 = mudstate[112];
HIDWORD(mudstate[111]) = 0;
mudstate[113] = v2;
mudstate[112] = time(0LL);
do_second();
local_second();
v3 = mudconf[2025];
v4 = mudstate[112];
if ( (v3 & 0x10) != 0 && mudstate[115] <= v4 )
{
v9 = mudconf[1804];
mudstate[188] = "< dbck >";
mudstate[115] = v9 + v4;
cache_reset(0LL);
do_dbck(0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
cache_reset(0LL);
pcache_trim();
v3 = mudconf[2025];
v4 = mudstate[112];
}
if ( (v3 & 8) != 0 && mudstate[114] <= v4 )
{
v8 = mudconf[1803];
mudstate[188] = "< dump >";
mudstate[114] = v8 + v4;
fork_and_dump(0LL, 0LL);
v3 = mudconf[2025];
v4 = mudstate[112];
}
if ( (v3 & 0x20) != 0 && mudstate[116] <= v4 )
{
v7 = mudconf[1809];
mudstate[188] = "< idlecheck >";
mudstate[116] = v7 + v4;
cache_reset(0LL);
check_idle();
v4 = mudstate[112];
}
if ( mudstate[118] <= v4 )
{
mudstate[118] = v4 + 15;
v5 = mudstate[908];
if ( v5 >= 0 && *((int *)&mudstate[907] + v5) < v4 )
{
v11 = 1 - v5;
getrusage(RUSAGE_SELF, &v15);
v12 = v15.ru_ixrss;
LODWORD(mudstate[908]) = v11;
v13 = v11 + 1808LL;
v14 = v11 + 1812LL;
*((_DWORD *)mudstate + v13) = v12;
*((_DWORD *)&mudstate[1] + v13) = v15.ru_idrss;
*((_DWORD *)mudstate + v14) = v15.ru_isrss;
v4 = mudstate[112];
*((_DWORD *)&mudstate[1] + v14) = v4;
}
}
if ( (mudconf[2025] & 0x40) != 0 && mudstate[117] <= v4 )
{
v10 = mudconf[2005];
mudstate[188] = "< rwho update >";
mudstate[117] = v10 + v4;
rwho_update();
}
v6 = next_timer();
result = alarm(v6);
mudstate[188] = v1;
}
return result;
}

canonical_decompiled_code:
unsigned int func2()
{
unsigned int result; // eax
__int64 v1; // rbx
__int64 v2; // rax
int v3; // edx
__int64 v4; // rax
int v5; // edx
unsigned int v6; // eax
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
int v11; // ebp
int v12; // ecx
__int64 v13; // rax
__int64 v14; // rdx
struct rusage v15; // [rsp+0h] [rbp-A8h] BYREF

result = HIDWORD(mudstate[111]);
v1 = mudstate[188];
mudstate[188] = "< dispatch >";
if ( result )
{
v2 = mudstate[112];
HIDWORD(mudstate[111]) = 0;
mudstate[113] = v2;
mudstate[112] = time(0LL);
do_second();
local_second();
v3 = mudconf[2025];
v4 = mudstate[112];
if ( (v3 & 0x10) != 0 && mudstate[115] <= v4 )
{
v9 = mudconf[1804];
mudstate[188] = "< dbck >";
mudstate[115] = v9 + v4;
cache_reset(0LL);
do_dbck(0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
cache_reset(0LL);
pcache_trim();
v3 = mudconf[2025];
v4 = mudstate[112];
}
if ( (v3 & 8) != 0 && mudstate[114] <= v4 )
{
v8 = mudconf[1803];
mudstate[188] = "< dump >";
mudstate[114] = v8 + v4;
fork_and_dump(0LL, 0LL);
v3 = mudconf[2025];
v4 = mudstate[112];
}
if ( (v3 & 0x20) != 0 && mudstate[116] <= v4 )
{
v7 = mudconf[1809];
mudstate[188] = "< idlecheck >";
mudstate[116] = v7 + v4;
cache_reset(0LL);
check_idle();
v4 = mudstate[112];
}
if ( mudstate[118] <= v4 )
{
mudstate[118] = v4 + 15;
v5 = mudstate[908];
if ( v5 >= 0 && *((int *)&mudstate[907] + v5) < v4 )
{
v11 = 1 - v5;
getrusage(RUSAGE_SELF, &v15);
v12 = v15.ru_ixrss;
LODWORD(mudstate[908]) = v11;
v13 = v11 + 1808LL;
v14 = v11 + 1812LL;
*((_DWORD *)mudstate + v13) = v12;
*((_DWORD *)&mudstate[1] + v13) = v15.ru_idrss;
*((_DWORD *)mudstate + v14) = v15.ru_isrss;
v4 = mudstate[112];
*((_DWORD *)&mudstate[1] + v14) = v4;
}
}
if ( (mudconf[2025] & 0x40) != 0 && mudstate[117] <= v4 )
{
v10 = mudconf[2005];
mudstate[188] = "< rwho update >";
mudstate[117] = v10 + v4;
rwho_update();
}
v6 = func0();
result = alarm(v6);
mudstate[188] = v1;
}
return result;
}

original_code:
void dispatch(void)
{
char *cmdsave;
 cmdsave = mudstate.debug_cmd;
 mudstate.debug_cmd = (char *)"< dispatch >";
 if (!mudstate.alarm_triggered) return;
 mudstate.alarm_triggered = 0;
 mudstate.lastnow = mudstate.now;
 mudstate.now = time(((void *)0));
 do_second();
 local_second();
 if ((mudconf.control_flags & 0x0010) &&
     (mudstate.check_counter <= mudstate.now)) {
  mudstate.check_counter = mudconf.check_interval + mudstate.now;
  mudstate.debug_cmd = (char *)"< dbck >";
  cache_reset(0);
  do_dbck ((-1), (-1), 0);
  cache_reset(0);
  pcache_trim();
 }
 if ((mudconf.control_flags & 0x0008) &&
     (mudstate.dump_counter <= mudstate.now)) {
  mudstate.dump_counter = mudconf.dump_interval + mudstate.now;
  mudstate.debug_cmd = (char *)"< dump >";
  fork_and_dump(0, (char *)((void *)0));
 }
 if ((mudconf.control_flags & 0x0020) &&
     (mudstate.idle_counter <= mudstate.now)) {
  mudstate.idle_counter = mudconf.idle_interval + mudstate.now;
  mudstate.debug_cmd = (char *)"< idlecheck >";
  cache_reset(0);
  check_idle();
 }
 if (mudstate.mstats_counter <= mudstate.now) {
  int curr;
  mudstate.mstats_counter = 15 + mudstate.now;
  curr = mudstate.mstat_curr;
  if ( (curr >= 0 ) && (mudstate.now > mudstate.mstat_secs[curr]) ) {
   struct rusage usage;
   curr = 1-curr;
   getrusage(RUSAGE_SELF, &usage);
   mudstate.mstat_ixrss[curr] = usage.ru_ixrss;
   mudstate.mstat_idrss[curr] = usage.ru_idrss;
   mudstate.mstat_isrss[curr] = usage.ru_isrss;
   mudstate.mstat_secs[curr] = mudstate.now;
   mudstate.mstat_curr = curr;
  }
 }
 if ((mudconf.control_flags & 0x0040) &&
     (mudstate.rwho_counter <= mudstate.now)) {
  mudstate.rwho_counter = mudconf.rwho_interval + mudstate.now;
  mudstate.debug_cmd = (char *)"< rwho update >";
  rwho_update();
 }
 alarm (next_timer());
 mudstate.debug_cmd = cmdsave;
}

canonical_original_code:
void dispatch()
{
char *cmdsave;
 cmdsave = mudstate.debug_cmd;
 mudstate.debug_cmd = (char *)"< dispatch >";
 if (!mudstate.alarm_triggered) return;
 mudstate.alarm_triggered = 0;
 mudstate.lastnow = mudstate.now;
 mudstate.now = time(((void *)0));
 do_second();
 local_second();
 if ((mudconf.control_flags & 0x0010) &&
     (mudstate.check_counter <= mudstate.now)) {
  mudstate.check_counter = mudconf.check_interval + mudstate.now;
  mudstate.debug_cmd = (char *)"< dbck >";
  cache_reset(0);
  do_dbck ((-1), (-1), 0);
  cache_reset(0);
  pcache_trim();
 }
 if ((mudconf.control_flags & 0x0008) &&
     (mudstate.dump_counter <= mudstate.now)) {
  mudstate.dump_counter = mudconf.dump_interval + mudstate.now;
  mudstate.debug_cmd = (char *)"< dump >";
  fork_and_dump(0, (char *)((void *)0));
 }
 if ((mudconf.control_flags & 0x0020) &&
     (mudstate.idle_counter <= mudstate.now)) {
  mudstate.idle_counter = mudconf.idle_interval + mudstate.now;
  mudstate.debug_cmd = (char *)"< idlecheck >";
  cache_reset(0);
  check_idle();
 }
 if (mudstate.mstats_counter <= mudstate.now) {
  int curr;
  mudstate.mstats_counter = 15 + mudstate.now;
  curr = mudstate.mstat_curr;
  if ( (curr >= 0 ) && (mudstate.now > mudstate.mstat_secs[curr]) ) {
   struct rusage usage;
   curr = 1-curr;
   getrusage(RUSAGE_SELF, &usage);
   mudstate.mstat_ixrss[curr] = usage.ru_ixrss;
   mudstate.mstat_idrss[curr] = usage.ru_idrss;
   mudstate.mstat_isrss[curr] = usage.ru_isrss;
   mudstate.mstat_secs[curr] = mudstate.now;
   mudstate.mstat_curr = curr;
  }
 }
 if ((mudconf.control_flags & 0x0040) &&
     (mudstate.rwho_counter <= mudstate.now)) {
  mudstate.rwho_counter = mudconf.rwho_interval + mudstate.now;
  mudstate.debug_cmd = (char *)"< rwho update >";
  rwho_update();
 }
 alarm (next_timer());
 mudstate.debug_cmd = cmdsave;
}

variable_types:
cmdsave
char *

variable_types: curr int

variable_types: struct rusage { struct timeval { long tv_sec; long tv_usec; } ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }

user_defined_types: struct rusage { struct timeval ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }


decompiled_code:
int __fastcall do_timewarp(unsigned int a1, unsigned int a2, int a3, const char *a4)
{
int result; // eax
__int64 v7; // rbp

result = atoi(a4);
v7 = result;
if ( !a3 || (a3 & 1) != 0 )
result = do_queue(a1, a2, 2LL, a4);
if ( (a3 & 2) != 0 )
{
result = v7;
mudstate[114] -= (int)v7;
}
if ( (a3 & 4) != 0 )
{
result = v7;
mudstate[115] -= (int)v7;
}
if ( (a3 & 8) != 0 )
{
result = v7;
mudstate[116] -= (int)v7;
}
if ( (a3 & 0x10) != 0 )
mudstate[117] -= v7;
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, unsigned int a2, int a3, const char *a4)
{
int result; // eax
__int64 v7; // rbp

result = atoi(a4);
v7 = result;
if ( !a3 || (a3 & 1) != 0 )
result = do_queue(a1, a2, 2LL, a4);
if ( (a3 & 2) != 0 )
{
result = v7;
mudstate[114] -= (int)v7;
}
if ( (a3 & 4) != 0 )
{
result = v7;
mudstate[115] -= (int)v7;
}
if ( (a3 & 8) != 0 )
{
result = v7;
mudstate[116] -= (int)v7;
}
if ( (a3 & 0x10) != 0 )
mudstate[117] -= v7;
return result;
}

original_code:
void do_timewarp (dbref player, dbref cause, int key, char *arg)
{
int secs;
 secs = atoi(arg);
 if ((key == 0) || (key & 1))
  do_queue(player, cause, 2, arg);
 if (key & 2)
  mudstate.dump_counter -= secs;
 if (key & 4)
  mudstate.check_counter -= secs;
 if (key & 8)
  mudstate.idle_counter -= secs;
 if (key & 16)
  mudstate.rwho_counter -= secs;
}

canonical_original_code:
void do_timewarp(int player, int cause, int key, char *arg)
{
int secs;
 secs = atoi(arg);
 if ((key == 0) || (key & 1))
  do_queue(player, cause, 2, arg);
 if (key & 2)
  mudstate.dump_counter -= secs;
 if (key & 4)
  mudstate.check_counter -= secs;
 if (key & 8)
  mudstate.idle_counter -= secs;
 if (key & 16)
  mudstate.rwho_counter -= secs;
}

variable_types: cause int

variable_types: key int

variable_types:
arg
char *

variable_types: secs int


original_code:
int quick_wild_internal(char *tstr, char *dstr, int *pLoopCntr)
{
 if (*pLoopCntr > mudconf.wildmatch_lim) {
    return 0;
 }
 (*pLoopCntr)++;
 if ( (*tstr == '\0') && (*dstr == '\0') ) {
           return 1;
        }
        if ( (*tstr == '\0') ) {
           return 0;
        }
 while (*tstr != '*') {
  switch (*tstr) {
  case '?':
   if (!*dstr)
     return 0;
   break;
  case '\\':
   tstr++;
  default:
   if (((*dstr != *tstr) && (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short int) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) != ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short int) _ISupper) ? tolower((int)*tstr) : ((int)*tstr))))))
     return 0;
   if (!*dstr)
     return 1;
  }
                if ( *tstr )
     tstr++;
                if ( *dstr )
     dstr++;
 }
        if ( *tstr )
    tstr++;
 if (!*tstr)
   return 1;
 while ((*tstr == '?') || (*tstr == '*')) {
   if (*tstr == '?') {
     if (!*dstr)
       return 0;
     dstr++;
   }
   tstr++;
 }
 if (*tstr == '\\')
   tstr++;
 if (!*tstr)
   return 1;
 while (*dstr) {
  if (((*dstr == *tstr) || (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short int) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) == ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short int) _ISupper) ? tolower((int)*tstr) : ((int)*tstr))))) &&
      quick_wild_internal(tstr+1, dstr+1, pLoopCntr)) return 1;
  dstr++;
 }
 return 0;
}

canonical_original_code:
int quick_wild_internal(char *tstr, char *dstr, int *pLoopCntr)
{
 if (*pLoopCntr > mudconf.wildmatch_lim) {
    return 0;
 }
 (*pLoopCntr)++;
 if ( (*tstr == '\0') && (*dstr == '\0') ) {
           return 1;
        }
        if ( (*tstr == '\0') ) {
           return 0;
        }
 while (*tstr != '*') {
  switch (*tstr) {
  case '?':
   if (!*dstr)
     return 0;
   break;
  case '\\':
   tstr++;
  default:
   if (((*dstr != *tstr) && (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) != ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short) _ISupper) ? tolower((int)*tstr) : ((int)*tstr))))))
     return 0;
   if (!*dstr)
     return 1;
  }
                if ( *tstr )
     tstr++;
                if ( *dstr )
     dstr++;
 }
        if ( *tstr )
    tstr++;
 if (!*tstr)
   return 1;
 while ((*tstr == '?') || (*tstr == '*')) {
   if (*tstr == '?') {
     if (!*dstr)
       return 0;
     dstr++;
   }
   tstr++;
 }
 if (*tstr == '\\')
   tstr++;
 if (!*tstr)
   return 1;
 while (*dstr) {
  if (((*dstr == *tstr) || (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) == ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short) _ISupper) ? tolower((int)*tstr) : ((int)*tstr))))) &&
      quick_wild_internal(tstr+1, dstr+1, pLoopCntr)) return 1;
  dstr++;
 }
 return 0;
}

variable_types:
tstr
char *

variable_types:
dstr
char *

variable_types:
pLoopCntr
int *


decompiled_code:
_BOOL8 __fastcall quick_wild(_BYTE *a1, char *a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 0;
return quick_wild_internal(a1, a2, v3);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_BYTE *a1, char *a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 0;
return func0(a1, a2, v3);
}

original_code:
int quick_wild(char *tstr, char *dstr) {
  int loopCntr = 0;
  return quick_wild_internal(tstr, dstr, &loopCntr);
}

variable_types: loopCntr int


original_code:
int wild1(char *tstr, char *dstr, int arg, int *pLoopCntr)
{
  char *datapos;
  int argpos, numextra;
        if ( *pLoopCntr > mudconf.wildmatch_lim )
           return 0;
 (*pLoopCntr)++;
 while (*tstr != '*') {
  switch (*tstr) {
  case '?':
   if (!*dstr)
     return 0;
   arglist[arg][0] = *dstr;
   arglist[arg][1] = '\0';
   arg++;
   if (arg >= numargs)
     return quick_wild_internal(tstr+1, dstr+1, pLoopCntr);
   break;
  case '\\':
   tstr++;
  default:
   if (((*dstr != *tstr) && (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short int) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) != ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short int) _ISupper) ? tolower((int)*tstr) : ((int)*tstr))))))
     return 0;
   if (!*dstr)
     return 1;
  }
  tstr++;
  dstr++;
 }
 if (!tstr[1]) {
   strncpy(arglist[arg], dstr, 4000 - 1);
   arglist[arg][4000 - 1] = '\0';
   return 1;
 }
 datapos = dstr;
 argpos = arg;
 do {
   if (argpos < arg) {
     arglist[argpos][0] = '\0';
     argpos++;
     if (argpos >= numargs)
       return quick_wild_internal(tstr, dstr, pLoopCntr);
     while (argpos < arg) {
       arglist[argpos][0] = *datapos;
       arglist[argpos][1] = '\0';
       datapos++;
       argpos++;
       if (argpos >= numargs)
  return quick_wild_internal(tstr, dstr, pLoopCntr);
     }
   }
   tstr++;
   arg++;
   numextra = 0;
   while (*tstr == '?') {
     if (!*dstr)
       return 0;
     tstr++;
     dstr++;
     arg++;
     numextra++;
   }
 } while (*tstr == '*');
 if (*tstr == '\\')
   tstr++;
 while (1) {
   if (*tstr)
     while (((*dstr != *tstr) && (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short int) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) != ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short int) _ISupper) ? tolower((int)*tstr) : ((int)*tstr)))))) {
       if (!*dstr) return 0;
       dstr++;
     }
   else
     while (*dstr) dstr++;
   if (!*dstr ||
       ((arg<numargs) ? wild1(tstr+1, dstr+1, arg, pLoopCntr)
        : quick_wild_internal(tstr+1, dstr+1, pLoopCntr))) {
     strncpy(arglist[argpos], datapos,
      (dstr - datapos) - numextra);
     arglist[argpos][(dstr - datapos) - numextra] = '\0';
     datapos = dstr - numextra;
     argpos++;
     while (numextra) {
       if (argpos >= numargs) return 1;
       arglist[argpos][0] = *datapos;
       arglist[argpos][1] = '\0';
       datapos++;
       argpos++;
       numextra--;
     }
     return 1;
   } else {
     dstr++;
   }
 }
}

canonical_original_code:
int wild1(char *tstr, char *dstr, int arg, int *pLoopCntr)
{
  char *datapos;
  int argpos; int numextra;
        if ( *pLoopCntr > mudconf.wildmatch_lim )
           return 0;
 (*pLoopCntr)++;
 while (*tstr != '*') {
  switch (*tstr) {
  case '?':
   if (!*dstr)
     return 0;
   arglist[arg][0] = *dstr;
   arglist[arg][1] = '\0';
   arg++;
   if (arg >= numargs)
     return quick_wild_internal(tstr+1, dstr+1, pLoopCntr);
   break;
  case '\\':
   tstr++;
  default:
   if (((*dstr != *tstr) && (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) != ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short) _ISupper) ? tolower((int)*tstr) : ((int)*tstr))))))
     return 0;
   if (!*dstr)
     return 1;
  }
  tstr++;
  dstr++;
 }
 if (!tstr[1]) {
   strncpy(arglist[arg], dstr, 4000 - 1);
   arglist[arg][4000 - 1] = '\0';
   return 1;
 }
 datapos = dstr;
 argpos = arg;
 do {
   if (argpos < arg) {
     arglist[argpos][0] = '\0';
     argpos++;
     if (argpos >= numargs)
       return quick_wild_internal(tstr, dstr, pLoopCntr);
     while (argpos < arg) {
       arglist[argpos][0] = *datapos;
       arglist[argpos][1] = '\0';
       datapos++;
       argpos++;
       if (argpos >= numargs)
  return quick_wild_internal(tstr, dstr, pLoopCntr);
     }
   }
   tstr++;
   arg++;
   numextra = 0;
   while (*tstr == '?') {
     if (!*dstr)
       return 0;
     tstr++;
     dstr++;
     arg++;
     numextra++;
   }
 } while (*tstr == '*');
 if (*tstr == '\\')
   tstr++;
 while (1) {
   if (*tstr)
     while (((*dstr != *tstr) && (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) != ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short) _ISupper) ? tolower((int)*tstr) : ((int)*tstr)))))) {
       if (!*dstr) return 0;
       dstr++;
     }
   else
     while (*dstr) dstr++;
   if (!*dstr ||
       ((arg<numargs) ? wild1(tstr+1, dstr+1, arg, pLoopCntr)
        : quick_wild_internal(tstr+1, dstr+1, pLoopCntr))) {
     strncpy(arglist[argpos], datapos,
      (dstr - datapos) - numextra);
     arglist[argpos][(dstr - datapos) - numextra] = '\0';
     datapos = dstr - numextra;
     argpos++;
     while (numextra) {
       if (argpos >= numargs) return 1;
       arglist[argpos][0] = *datapos;
       arglist[argpos][1] = '\0';
       datapos++;
       argpos++;
       numextra--;
     }
     return 1;
   } else {
     dstr++;
   }
 }
}

variable_types: arg int

variable_types:
datapos
char *

variable_types: argpos int

variable_types: numextra int


wild

original_code:
int wild(char *tstr, char *dstr, char *args[], int nargs)
{
  int i, value;
  char *scan;
  int loopCntr = 0;
 for (i=0; i<nargs; i++) args[i] = ((void *)0);
 while ((*tstr != '*') && (*tstr != '?')) {
  if (*tstr == '\\') tstr++;
  if (((*dstr != *tstr) && (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short int) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) != ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short int) _ISupper) ? tolower((int)*tstr) : ((int)*tstr)))))) return 0;
  if (!*dstr) return 1;
  tstr++;
  dstr++;
 }
 i = 0;
 scan = tstr;
 while (*scan && (i < nargs)) {
  switch (*scan) {
  case '?':
   args[i] = pool_alloc(2,"wild.?",379,"wild.c");
   i++;
   break;
  case '*':
   args[i] = pool_alloc(2,"wild.*",383,"wild.c");
   i++;
  }
  scan++;
 }
 arglist = args;
 numargs = nargs;
 value = nargs ? wild1(tstr, dstr, 0, &loopCntr) : quick_wild_internal(tstr, dstr, &loopCntr);
 for (i=0; i<nargs; i++)
  if ((args[i] != ((void *)0)) && (!*args[i] || !value)) {
   pool_free(2,((char **)&(args[i])),416,"wild.c");
   args[i] = ((void *)0);
  }
 return value;
}

canonical_original_code:
int wild(char *tstr, char *dstr, char *args[], int nargs)
{
  int i; int value;
  char *scan;
  int loopCntr = 0;
 for (i=0; i<nargs; i++) args[i] = ((void *)0);
 while ((*tstr != '*') && (*tstr != '?')) {
  if (*tstr == '\\') tstr++;
  if (((*dstr != *tstr) && (((((*__ctype_b_loc ())[(int) (((int)*dstr))] & (unsigned short) _ISupper) ? tolower((int)*dstr) : ((int)*dstr))) != ((((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short) _ISupper) ? tolower((int)*tstr) : ((int)*tstr)))))) return 0;
  if (!*dstr) return 1;
  tstr++;
  dstr++;
 }
 i = 0;
 scan = tstr;
 while (*scan && (i < nargs)) {
  switch (*scan) {
  case '?':
   args[i] = pool_alloc(2,"wild.?",379,"wild.c");
   i++;
   break;
  case '*':
   args[i] = pool_alloc(2,"wild.*",383,"wild.c");
   i++;
  }
  scan++;
 }
 arglist = args;
 numargs = nargs;
 value = nargs ? wild1(tstr, dstr, 0, &loopCntr) : quick_wild_internal(tstr, dstr, &loopCntr);
 for (i=0; i<nargs; i++)
  if ((args[i] != ((void *)0)) && (!*args[i] || !value)) {
   pool_free(2,((char **)&(args[i])),416,"wild.c");
   args[i] = ((void *)0);
  }
 return value;
}

variable_types:
args
char *[]

variable_types: nargs int

variable_types: i int

variable_types: value int

variable_types:
scan
char *


decompiled_code:
_BOOL8 __fastcall wild_match(__int64 a1, char *a2, void *a3, int a4, int a5)
{
const unsigned __int16 **v5; // rax
__int64 v6; // rcx
_BOOL8 result; // rax
const unsigned __int16 **v8; // rax
__int64 v9; // rcx
int v10; // ebp
int v11; // ebp

if ( !a5 )
goto LABEL_9;
if ( *(_BYTE *)a1 != 60 )
{
if ( *(_BYTE *)a1 == 62 )
{
if ( a4 > 0 )
memset(a3, 0, 8LL * a4);
v5 = _ctype_b_loc();
v6 = *(char *)(a1 + 1);
if ( ((*v5)[v6] & 0x800) == 0 && (_BYTE)v6 != 45 )
return (unsigned int)strcmp((const char *)(a1 + 1), a2) >> 31;
v10 = atoi((const char *)(a1 + 1));
return v10 < atoi(a2);
}
LABEL_9:
if ( a4 )
result = wild((char *)a1, a2, (char *)a3, a4);
else
result = quick_wild((_BYTE *)a1, a2);
return result;
}
if ( a4 > 0 )
memset(a3, 0, 8LL * a4);
v8 = _ctype_b_loc();
v9 = *(char *)(a1 + 1);
if ( ((*v8)[v9] & 0x800) == 0 && (_BYTE)v9 != 45 )
return strcmp((const char *)(a1 + 1), a2) > 0;
v11 = atoi((const char *)(a1 + 1));
return v11 > atoi(a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, char *a2, void *a3, int a4, int a5)
{
const unsigned __int16 **v5; // rax
__int64 v6; // rcx
_BOOL8 result; // rax
const unsigned __int16 **v8; // rax
__int64 v9; // rcx
int v10; // ebp
int v11; // ebp

if ( !a5 )
goto LABEL_9;
if ( *(_BYTE *)a1 != 60 )
{
if ( *(_BYTE *)a1 == 62 )
{
if ( a4 > 0 )
memset(a3, 0, 8LL * a4);
v5 = _ctype_b_loc();
v6 = *(char *)(a1 + 1);
if ( ((*v5)[v6] & 0x800) == 0 && (_BYTE)v6 != 45 )
return (unsigned int)strcmp((const char *)(a1 + 1), a2) >> 31;
v10 = atoi((const char *)(a1 + 1));
return v10 < atoi(a2);
}
LABEL_9:
if ( a4 )
result = func3((char *)a1, a2, (char *)a3, a4);
else
result = func1((_BYTE *)a1, a2);
return result;
}
if ( a4 > 0 )
memset(a3, 0, 8LL * a4);
v8 = _ctype_b_loc();
v9 = *(char *)(a1 + 1);
if ( ((*v8)[v9] & 0x800) == 0 && (_BYTE)v9 != 45 )
return strcmp((const char *)(a1 + 1), a2) > 0;
v11 = atoi((const char *)(a1 + 1));
return v11 > atoi(a2);
}

original_code:
int wild_match(char *tstr, char *dstr, char *args[], int nargs, int ck_arith)
{
  int i;
 if (ck_arith) {
  switch (*tstr) {
  case '>':
   for (i=0; i<nargs; i++) args[i] = ((void *)0);
   tstr++;
   if (((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short int) _ISdigit) || (*tstr == '-'))
    return (atoi(tstr) < atoi(dstr));
   else
    return (strcmp(tstr, dstr) < 0);
  case '<':
   for (i=0; i<nargs; i++) args[i] = ((void *)0);
   tstr++;
   if (((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short int) _ISdigit) || (*tstr == '-'))
    return (atoi(tstr) > atoi(dstr));
   else
    return (strcmp(tstr, dstr) > 0);
  }
 }
 return nargs ? wild(tstr, dstr, args, nargs) : quick_wild(tstr, dstr);
}

canonical_original_code:
int wild_match(char *tstr, char *dstr, char *args[], int nargs, int ck_arith)
{
  int i;
 if (ck_arith) {
  switch (*tstr) {
  case '>':
   for (i=0; i<nargs; i++) args[i] = ((void *)0);
   tstr++;
   if (((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short) _ISdigit) || (*tstr == '-'))
    return (atoi(tstr) < atoi(dstr));
   else
    return (strcmp(tstr, dstr) < 0);
  case '<':
   for (i=0; i<nargs; i++) args[i] = ((void *)0);
   tstr++;
   if (((*__ctype_b_loc ())[(int) (((int)*tstr))] & (unsigned short) _ISdigit) || (*tstr == '-'))
    return (atoi(tstr) > atoi(dstr));
   else
    return (strcmp(tstr, dstr) > 0);
  }
 }
 return nargs ? wild(tstr, dstr, args, nargs) : quick_wild(tstr, dstr);
}


decompiled_code:
__int64 init_compress()
{
__int64 result; // rax
__int64 v1; // rdi
_BYTE *v2; // rdx
_BYTE *v3; // rax
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rax
char *v7; // rdx
char v8; // si

result = mudconf[1879];
if ( (_DWORD)result )
{
if ( !compress_buf )
compress_buf = pool_alloc(2LL, "init_compress", 61LL, "compress.c");
v1 = token_table;
if ( !token_table )
{
token_table = (__int64)malloc(0x4000uLL);
v1 = token_table;
}
v2 = (_BYTE *)(v1 + 0x4000);
do
{
v3 = v2 - 0x4000;
do
{
*v3 = 0;
v3 += 128;
}
while ( v2 != v3 );
v2 += 0x4000;
}
while ( (_BYTE *)(v1 + 2113536) != v2 );
v4 = 0LL;
v5 = 32LL;
v6 = 101LL;
while ( 1 )
{
v8 = v4++;
result = v1 + (v6 << 14);
*(_BYTE *)(result + (v5 << 7)) = v8 | 0x80;
if ( v4 == 128 )
break;
v7 = tokens[v4];
v6 = *v7;
v5 = v7[1];
}
table_initialized = 1;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rdi
_BYTE *v2; // rdx
_BYTE *v3; // rax
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rax
char *v7; // rdx
char v8; // si

result = mudconf[1879];
if ( (_DWORD)result )
{
if ( !compress_buf )
compress_buf = pool_alloc(2LL, "init_compress", 61LL, "compress.c");
v1 = token_table;
if ( !token_table )
{
token_table = (__int64)malloc(0x4000uLL);
v1 = token_table;
}
v2 = (_BYTE *)(v1 + 0x4000);
do
{
v3 = v2 - 0x4000;
do
{
*v3 = 0;
v3 += 128;
}
while ( v2 != v3 );
v2 += 0x4000;
}
while ( (_BYTE *)(v1 + 2113536) != v2 );
v4 = 0LL;
v5 = 32LL;
v6 = 101LL;
while ( 1 )
{
v8 = v4++;
result = v1 + (v6 << 14);
*(_BYTE *)(result + (v5 << 7)) = v8 | 0x80;
if ( v4 == 128 )
break;
v7 = tokens[v4];
v6 = *v7;
v5 = v7[1];
}
table_initialized = 1;
}
return result;
}

original_code:
static void
init_compress(void)
{
    if (mudconf.intern_comp) {
 int i;
 int j;
 if (!compress_buf)
     compress_buf = pool_alloc(2,"init_compress",61,"compress.c");
 if (!token_table)
     token_table = (TOKTAB *) malloc(sizeof(TOKTAB));
 for (i = 0; i < (128); i++) {
     for (j = 0; j < (128); j++) {
  *token_table[i][j] = 0;
     }
 }
 for (i = 0; i < (128); i++) {
     *token_table[(int) tokens[i][0]] [(int) tokens[i][1]] = i | 0x80;
 }
 table_initialized = 1;
    }
}

canonical_original_code:
static void init_compress()
{
    if (mudconf.intern_comp) {
 int i;
 int j;
 if (!compress_buf)
     compress_buf = pool_alloc(2,"init_compress",61,"compress.c");
 if (!token_table)
     token_table = (char (*)[-1][-1]) malloc(sizeof(TOKTAB));
 for (i = 0; i < (128); i++) {
     for (j = 0; j < (128); j++) {
  *token_table[i][j] = 0;
     }
 }
 for (i = 0; i < (128); i++) {
     *token_table[(int) tokens[i][0]] [(int) tokens[i][1]] = i | 0x80;
 }
 table_initialized = 1;
    }
}

variable_types: j int


compress

decompiled_code:
char *__fastcall compress(char *a1, int a2)
{
char *v2; // r12
char v3; // si
__int64 v4; // r8
__int64 v5; // rdi
char *v6; // rcx
__int64 v7; // rax
char v8; // al

v2 = a1;
if ( mudconf[1879] && a2 != 253 )
{
if ( !table_initialized )
init_compress();
v3 = *a1;
v4 = compress_buf;
if ( *a1 )
{
v5 = token_table;
v6 = (char *)compress_buf;
while ( 1 )
{
v7 = v2[1];
if ( !(_BYTE)v7 )
break;
v8 = *(_BYTE *)(v5 + ((__int64)v3 << 14) + (v7 << 7));
if ( v8 )
{
v2 += 2;
*v6++ = v8;
v3 = *v2;
if ( !*v2 )
goto LABEL_11;
}
else
{
++v2;
*v6++ = v3;
v3 = *v2;
if ( !*v2 )
goto LABEL_11;
}
}
strcpy(v6, v2);
}
else
{
v6 = (char *)compress_buf;
LABEL_11:
*v6 = 0;
}
v2 = (char *)v4;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, int a2)
{
char *v2; // r12
char v3; // si
__int64 v4; // r8
__int64 v5; // rdi
char *v6; // rcx
__int64 v7; // rax
char v8; // al

v2 = a1;
if ( mudconf[1879] && a2 != 253 )
{
if ( !table_initialized )
func0();
v3 = *a1;
v4 = compress_buf;
if ( *a1 )
{
v5 = token_table;
v6 = (char *)compress_buf;
while ( 1 )
{
v7 = v2[1];
if ( !(_BYTE)v7 )
break;
v8 = *(_BYTE *)(v5 + ((__int64)v3 << 14) + (v7 << 7));
if ( v8 )
{
v2 += 2;
*v6++ = v8;
v3 = *v2;
if ( !*v2 )
goto LABEL_11;
}
else
{
++v2;
*v6++ = v3;
v3 = *v2;
if ( !*v2 )
goto LABEL_11;
}
}
strcpy(v6, v2);
}
else
{
v6 = (char *)compress_buf;
LABEL_11:
*v6 = 0;
}
v2 = (char *)v4;
}
return v2;
}

original_code:
const char *
compress(const char *s, int atr)
{
    if (mudconf.intern_comp && (atr != 253)) {
 char *to;
 char token;
 if (!table_initialized)
     init_compress();
 for (to = compress_buf; s[0] && s[1]; to++) {
     if ((token = *token_table[(int)s[0]][(int)s[1]])) {
  *to = token;
  s += 2;
     } else {
  *to = s[0];
  s++;
     }
 }
 while ((*to++ = *s++));
 return compress_buf;
    } else
 return s;
}

canonical_original_code:
char *compress(char *s, int atr)
{
    if (mudconf.intern_comp && (atr != 253)) {
 char *to;
 char token;
 if (!table_initialized)
     init_compress();
 for (to = compress_buf; s[0] && s[1]; to++) {
     if ((token = *token_table[(int)s[0]][(int)s[1]])) {
  *to = token;
  s += 2;
     } else {
  *to = s[0];
  s++;
     }
 }
 while ((*to++ = *s++));
 return compress_buf;
    } else
 return s;
}

variable_types:
s
char *

variable_types: atr int

variable_types:
to
char *

variable_types: token char

return_type: char *


decompiled_code:
char *__fastcall uncompress_str(char *dest, const char *a2, __int64 a3, __int64 a4)
{
char *v4; // rdx
char v5; // al
char *v6; // rax

if ( !mudconf[1879] || (_DWORD)a3 == 253 )
return strcpy(dest, a2);
if ( !a2 )
uncompress_str_cold(dest, 0LL, a3, a4, dest);
v4 = dest;
while ( 1 )
{
v5 = *a2;
if ( !*a2 )
break;
if ( v5 >= 0 )
{
*v4++ = v5;
}
else
{
v4 += 2;
v6 = tokens[*a2 & 0x7F];
*(v4 - 2) = *v6;
*(v4 - 1) = v6[1];
}
++a2;
}
*v4 = 0;
return dest;
}

canonical_decompiled_code:
char *__fastcall func3(char *dest, const char *a2, __int64 a3, __int64 a4)
{
char *v4; // rdx
char v5; // al
char *v6; // rax

if ( !mudconf[1879] || (_DWORD)a3 == 253 )
return strcpy(dest, a2);
if ( !a2 )
func4(dest, 0LL, a3, a4, dest);
v4 = dest;
while ( 1 )
{
v5 = *a2;
if ( !*a2 )
break;
if ( v5 >= 0 )
{
*v4++ = v5;
}
else
{
v4 += 2;
v6 = tokens[*a2 & 0x7F];
*(v4 - 2) = *v6;
*(v4 - 1) = v6[1];
}
++a2;
}
*v4 = 0;
return dest;
}

original_code:
char *
uncompress_str(char *dest, const char *s, int atr)
{
    if (mudconf.intern_comp && (atr != 253)) {
 char *to;
 const char *token;
 for (to = dest; s && *s; s++) {
     if (*s & 0x80) {
  token = tokens[*s & 0x7f];
  *to++ = *token++;
  *to++ = *token;
     } else {
  *to++ = *s;
     }
 }
 *to++ = *s;
 return (dest);
    } else {
 strcpy(dest, s);
 return dest;
    }
}

canonical_original_code:
char *uncompress_str(char *dest, char *s, int atr)
{
    if (mudconf.intern_comp && (atr != 253)) {
 char *to;
 char *token;
 for (to = dest; s && *s; s++) {
     if (*s & 0x80) {
  token = tokens[*s & 0x7f];
  *to++ = *token++;
  *to++ = *token;
     } else {
  *to++ = *s;
     }
 }
 *to++ = *s;
 return (dest);
    } else {
 strcpy(dest, s);
 return dest;
    }
}

variable_types:
dest
char *

variable_types:
token
char *


original_code:
static FBLOCK *
fcache_fill(FBLOCK * fp, char ch)
{
    FBLOCK *tfp;
    if (fp->hdr.nchars >= (200 - sizeof(FBLKHDR))) {
 tfp = fp;
 fp = (FBLOCK *) pool_alloc(1,"fcache_fill",93,"file_c.c");
 fp->hdr.nxt = ((void *)0);
 fp->hdr.nchars = 0;
 tfp->hdr.nxt = fp;
    }
    fp->data[fp->hdr.nchars++] = ch;
    return fp;
}

canonical_original_code:
static struct filecache_block *fcache_fill(struct filecache_block *fp, char ch)
{
    struct filecache_block *tfp;
    if (fp->hdr.nchars >= (200 - sizeof(FBLKHDR))) {
 tfp = fp;
 fp = (struct filecache_block *) pool_alloc(1,"fcache_fill",93,"file_c.c");
 fp->hdr.nxt = ((void *)0);
 fp->hdr.nchars = 0;
 tfp->hdr.nxt = fp;
    }
    fp->data[fp->hdr.nchars++] = ch;
    return fp;
}

variable_types:
fp
struct filecache_block *

variable_types: ch char

variable_types: struct filecache_block { struct filecache_block_hdr { struct filecache_block *nxt; int nchars; } hdr; char data[-1]; } *

user_defined_types: struct filecache_block { struct filecache_block_hdr hdr; char data[-1]; }


decompiled_code:
__int64 __fastcall fcache_read(__int64 *a1, const char *a2)
{
_QWORD *v2; // rbx
unsigned int v3; // er13
int v4; // ebp
unsigned int v5; // er12
__int64 v6; // rax
void *v7; // rsi
int v8; // er14
int v9; // eax
_BYTE *v10; // r8
__int64 v11; // rbx
__int64 i; // r15
__int64 v13; // rax
char v14; // si
__int64 v15; // rax
void *buf; // [rsp+18h] [rbp-50h] BYREF
char *v19; // [rsp+20h] [rbp-48h] BYREF
__int64 v20[8]; // [rsp+28h] [rbp-40h] BYREF

v2 = (_QWORD *)*a1;
for ( v20[0] = (__int64)v2; v2; v20[0] = (__int64)v2 )
{
v2 = (_QWORD *)*v2;
pool_free(1LL, v20, 115LL, "file_c.c");
}
*a1 = 0LL;
v3 = tf_open(a2, 0LL);
if ( v3 == -1 )
{
if ( *((char *)&mudconf + 8105) < 0 && (unsigned int)start_log("FIL", "OPEN") )
{
buf = (void *)pool_alloc(1LL, "fcache_read.LOG", 127LL, "file_c.c");
sprintf((char *)buf, "Couldn't open file '%.100s'.", a2);
log_text(buf);
pool_free(1LL, &buf, 130LL, "file_c.c");
end_log();
}
v5 = -1;
tf_close(0xFFFFFFFFLL);
}
else
{
v4 = 0;
v5 = 0;
buf = (void *)pool_alloc(2LL, "fcache_read.temp", 135LL, "file_c.c");
v6 = pool_alloc(1LL, "fcache_read.first", 139LL, "file_c.c");
v7 = buf;
v20[0] = v6;
v8 = *((_DWORD *)&mudconf + 4630);
*(_QWORD *)v6 = 0LL;
*(_DWORD *)(v6 + 8) = 0;
*a1 = v6;
v9 = read(v3, v7, 0xFA0uLL);
while ( v9 > 0 )
{
v10 = buf;
v11 = v9;
for ( i = 0LL; i != v11; ++i )
{
while ( 1 )
{
v14 = v10[i];
if ( v14 != 10 )
break;
++i;
v5 += 2;
v20[0] = fcache_fill(v20[0], 13);
v15 = fcache_fill(v20[0], 10);
v10 = buf;
v20[0] = v15;
if ( i == v11 )
goto LABEL_13;
}
if ( v14 != 13 && v14 )
{
++v5;
v13 = fcache_fill(v20[0], v14);
v10 = buf;
v20[0] = v13;
}
}
LABEL_13:
++v4;
v9 = read(v3, v10, 0xFA0uLL);
if ( v8 < v4 )
{
if ( *((char *)&mudconf + 8105) < 0 && (unsigned int)start_log("FIL", "OPEN") )
{
v19 = (char *)pool_alloc(1LL, "fcache_read.LOG", 169LL, "file_c.c");
sprintf(v19, "Error with file '%.100s' (too large).", a2);
log_text(v19);
pool_free(1LL, &v19, 172LL, "file_c.c");
end_log();
}
break;
}
}
pool_free(2LL, &buf, 177LL, "file_c.c");
tf_close(v3);
if ( !*(_DWORD *)(v20[0] + 8) )
{
*a1 = 0LL;
pool_free(1LL, v20, 184LL, "file_c.c");
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, const char *a2)
{
_QWORD *v2; // rbx
unsigned int v3; // er13
int v4; // ebp
unsigned int v5; // er12
__int64 v6; // rax
void *v7; // rsi
int v8; // er14
int v9; // eax
_BYTE *v10; // r8
__int64 v11; // rbx
__int64 i; // r15
__int64 v13; // rax
char v14; // si
__int64 v15; // rax
void *buf; // [rsp+18h] [rbp-50h] BYREF
char *v19; // [rsp+20h] [rbp-48h] BYREF
__int64 v20[8]; // [rsp+28h] [rbp-40h] BYREF

v2 = (_QWORD *)*a1;
for ( v20[0] = (__int64)v2; v2; v20[0] = (__int64)v2 )
{
v2 = (_QWORD *)*v2;
pool_free(1LL, v20, 115LL, "file_c.c");
}
*a1 = 0LL;
v3 = tf_open(a2, 0LL);
if ( v3 == -1 )
{
if ( *((char *)&mudconf + 8105) < 0 && (unsigned int)start_log("FIL", "OPEN") )
{
buf = (void *)pool_alloc(1LL, "fcache_read.LOG", 127LL, "file_c.c");
sprintf((char *)buf, "Couldn't open file '%.100s'.", a2);
log_text(buf);
pool_free(1LL, &buf, 130LL, "file_c.c");
end_log();
}
v5 = -1;
tf_close(0xFFFFFFFFLL);
}
else
{
v4 = 0;
v5 = 0;
buf = (void *)pool_alloc(2LL, "fcache_read.temp", 135LL, "file_c.c");
v6 = pool_alloc(1LL, "fcache_read.first", 139LL, "file_c.c");
v7 = buf;
v20[0] = v6;
v8 = *((_DWORD *)&mudconf + 4630);
*(_QWORD *)v6 = 0LL;
*(_DWORD *)(v6 + 8) = 0;
*a1 = v6;
v9 = read(v3, v7, 0xFA0uLL);
while ( v9 > 0 )
{
v10 = buf;
v11 = v9;
for ( i = 0LL; i != v11; ++i )
{
while ( 1 )
{
v14 = v10[i];
if ( v14 != 10 )
break;
++i;
v5 += 2;
v20[0] = func0(v20[0], 13);
v15 = func0(v20[0], 10);
v10 = buf;
v20[0] = v15;
if ( i == v11 )
goto LABEL_13;
}
if ( v14 != 13 && v14 )
{
++v5;
v13 = func0(v20[0], v14);
v10 = buf;
v20[0] = v13;
}
}
LABEL_13:
++v4;
v9 = read(v3, v10, 0xFA0uLL);
if ( v8 < v4 )
{
if ( *((char *)&mudconf + 8105) < 0 && (unsigned int)start_log("FIL", "OPEN") )
{
v19 = (char *)pool_alloc(1LL, "fcache_read.LOG", 169LL, "file_c.c");
sprintf(v19, "Error with file '%.100s' (too large).", a2);
log_text(v19);
pool_free(1LL, &v19, 172LL, "file_c.c");
end_log();
}
break;
}
}
pool_free(2LL, &buf, 177LL, "file_c.c");
tf_close(v3);
if ( !*(_DWORD *)(v20[0] + 8) )
{
*a1 = 0LL;
pool_free(1LL, v20, 184LL, "file_c.c");
}
}
return v5;
}

original_code:
static int
fcache_read(FBLOCK ** cp, char *filename)
{
    int n, nmax, tchars, fd;
    char *buff, *buff2;
    FBLOCK *fp, *tfp;
    int max_lines, tot_lines;
    fp = *cp;
    while (fp != ((void *)0)) {
 tfp = fp->hdr.nxt;
 pool_free(1,((char **)&(fp)),115,"file_c.c");
 fp = tfp;
    }
    *cp = ((void *)0);
    if ((fd = tf_open(filename, 00)) == -1) {
 if ((((0x00008000) & mudconf.log_options) != 0) && start_log("FIL", "OPEN")) {
     buff = pool_alloc(1,"fcache_read.LOG",127,"file_c.c");
 sprintf(buff, "Couldn't open file '%.100s'.", filename);
 log_text(buff);
 pool_free(1,((char **)&(buff)),130,"file_c.c");
 end_log(); }
     tf_close(fd);
 return -1;
    }
    buff = pool_alloc(2,"fcache_read.temp",135,"file_c.c");
    fp = (FBLOCK *) pool_alloc(1,"fcache_read.first",139,"file_c.c");
    fp->hdr.nxt = ((void *)0);
    fp->hdr.nchars = 0;
    *cp = fp;
    tchars = 0;
    max_lines = mudconf.nonindxtxt_maxlines;
    tot_lines = 0;
    nmax = read(fd, buff, 4000);
    while (nmax > 0) {
 for (n = 0; n < nmax; n++) {
     switch (buff[n]) {
     case '\n':
  fp = fcache_fill(fp, '\r');
  fp = fcache_fill(fp, '\n');
  tchars += 2;
     case '\0':
     case '\r':
  break;
     default:
  fp = fcache_fill(fp, buff[n]);
  tchars++;
     }
 }
 nmax = read(fd, buff, 4000);
        tot_lines++;
        if ( tot_lines > max_lines ) {
    if ((((0x00008000) & mudconf.log_options) != 0) && start_log("FIL", "OPEN")) {
       buff2 = pool_alloc(1,"fcache_read.LOG",169,"file_c.c");
       sprintf(buff2, "Error with file '%.100s' (too large).", filename);
       log_text(buff2);
       pool_free(1,((char **)&(buff2)),172,"file_c.c");
    end_log(); }
           break;
        }
    }
    pool_free(2,((char **)&(buff)),177,"file_c.c");
    tf_close(fd);
    if (fp->hdr.nchars == 0) {
 *cp = ((void *)0);
 pool_free(1,((char **)&(fp)),184,"file_c.c");
    }
    return tchars;
}

canonical_original_code:
static int fcache_read(struct filecache_block **cp, char *filename)
{
    int n; int nmax; int tchars; int fd;
    char *buff; char *buff2;
    struct filecache_block *fp; struct filecache_block *tfp;
    int max_lines; int tot_lines;
    fp = *cp;
    while (fp != ((void *)0)) {
 tfp = fp->hdr.nxt;
 pool_free(1,((char **)&(fp)),115,"file_c.c");
 fp = tfp;
    }
    *cp = ((void *)0);
    if ((fd = tf_open(filename, 00)) == -1) {
 if ((((0x00008000) & mudconf.log_options) != 0) && start_log("FIL", "OPEN")) {
     buff = pool_alloc(1,"fcache_read.LOG",127,"file_c.c");
 sprintf(buff, "Couldn't open file '%.100s'.", filename);
 log_text(buff);
 pool_free(1,((char **)&(buff)),130,"file_c.c");
 end_log(); }
     tf_close(fd);
 return -1;
    }
    buff = pool_alloc(2,"fcache_read.temp",135,"file_c.c");
    fp = (struct filecache_block *) pool_alloc(1,"fcache_read.first",139,"file_c.c");
    fp->hdr.nxt = ((void *)0);
    fp->hdr.nchars = 0;
    *cp = fp;
    tchars = 0;
    max_lines = mudconf.nonindxtxt_maxlines;
    tot_lines = 0;
    nmax = read(fd, buff, 4000);
    while (nmax > 0) {
 for (n = 0; n < nmax; n++) {
     switch (buff[n]) {
     case '\n':
  fp = fcache_fill(fp, '\r');
  fp = fcache_fill(fp, '\n');
  tchars += 2;
     case '\0':
     case '\r':
  break;
     default:
  fp = fcache_fill(fp, buff[n]);
  tchars++;
     }
 }
 nmax = read(fd, buff, 4000);
        tot_lines++;
        if ( tot_lines > max_lines ) {
    if ((((0x00008000) & mudconf.log_options) != 0) && start_log("FIL", "OPEN")) {
       buff2 = pool_alloc(1,"fcache_read.LOG",169,"file_c.c");
       sprintf(buff2, "Error with file '%.100s' (too large).", filename);
       log_text(buff2);
       pool_free(1,((char **)&(buff2)),172,"file_c.c");
    end_log(); }
           break;
        }
    }
    pool_free(2,((char **)&(buff)),177,"file_c.c");
    tf_close(fd);
    if (fp->hdr.nchars == 0) {
 *cp = ((void *)0);
 pool_free(1,((char **)&(fp)),184,"file_c.c");
    }
    return tchars;
}

variable_types: struct filecache_block { struct filecache_block_hdr { struct filecache_block *nxt; int nchars; } hdr; char data[-1]; } **

variable_types:
filename
char *

variable_types: n int

variable_types: nmax int

variable_types: tchars int

variable_types: fd int

variable_types:
buff
char *


decompiled_code:
void __fastcall fcache_rawdump(int fd, unsigned int a2)
{
__int64 *v2; // r12
int v3; // ebx
char *v4; // r13
int v5; // eax

if ( a2 <= 0xD )
{
v2 = (__int64 *)*(&fcache + 3 * (int)a2 + 1);
if ( v2 )
{
while ( 1 )
{
v3 = *((_DWORD *)v2 + 2);
v4 = (char *)(v2 + 2);
if ( v3 > 0 )
break;
LABEL_8:
v2 = (__int64 *)*v2;
if ( !v2 )
return;
}
while ( 1 )
{
v5 = write(fd, v4, v3);
if ( v5 < 0 )
break;
v3 -= v5;
v4 += v5;
if ( v3 <= 0 )
goto LABEL_8;
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(int fd, unsigned int a2)
{
__int64 *v2; // r12
int v3; // ebx
char *v4; // r13
int v5; // eax

if ( a2 <= 0xD )
{
v2 = (__int64 *)*(&fcache + 3 * (int)a2 + 1);
if ( v2 )
{
while ( 1 )
{
v3 = *((_DWORD *)v2 + 2);
v4 = (char *)(v2 + 2);
if ( v3 > 0 )
break;
LABEL_8:
v2 = (__int64 *)*v2;
if ( !v2 )
return;
}
while ( 1 )
{
v5 = write(fd, v4, v3);
if ( v5 < 0 )
break;
v3 -= v5;
v4 += v5;
if ( v3 <= 0 )
goto LABEL_8;
}
}
}
}

original_code:
void
fcache_rawdump(int fd, int num)
{
    int cnt, remaining;
    char *start;
    FBLOCK *fp;
    if ((num < 0) || (num > 13))
 return;
    fp = fcache[num].fileblock;
    while (fp != ((void *)0)) {
 start = fp->data;
 remaining = fp->hdr.nchars;
 while (remaining > 0) {
     cnt = write(fd, start, remaining);
     if (cnt < 0)
  return;
     remaining -= cnt;
     start += cnt;
 }
 fp = fp->hdr.nxt;
    }
    return;
}

canonical_original_code:
void fcache_rawdump(int fd, int num)
{
    int cnt; int remaining;
    char *start;
    struct filecache_block *fp;
    if ((num < 0) || (num > 13))
 return;
    fp = fcache[num].fileblock;
    while (fp != ((void *)0)) {
 start = fp->data;
 remaining = fp->hdr.nchars;
 while (remaining > 0) {
     cnt = write(fd, start, remaining);
     if (cnt < 0)
  return;
     remaining -= cnt;
     start += cnt;
 }
 fp = fp->hdr.nxt;
    }
    return;
}

variable_types: num int

variable_types: cnt int

variable_types: remaining int

variable_types:
start
char *

user_defined_types: struct filecache_block_hdr { struct filecache_block *nxt; int nchars; }


decompiled_code:
__int64 __fastcall do_list_file(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
signed int v4; // eax
__int64 result; // rax

v4 = real_search_nametab(a1, &list_files, a4, "file_c.c", 74LL);
if ( v4 < 0 )
result = real_display_nametab((unsigned int)a1, &list_files, "Unknown file. Use one of:", 1LL, "file_c.c", 76LL);
else
result = fcache_send((unsigned int)a1, v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
signed int v4; // eax
__int64 result; // rax

v4 = real_search_nametab(a1, &list_files, a4, "file_c.c", 74LL);
if ( v4 < 0 )
result = real_display_nametab((unsigned int)a1, &list_files, "Unknown file. Use one of:", 1LL, "file_c.c", 76LL);
else
result = func4((unsigned int)a1, v4);
return result;
}

original_code:
void
do_list_file(dbref player, dbref cause, int extra, char *arg)
{
    int flagvalue;
    flagvalue = real_search_nametab(player, list_files, arg, "file_c.c", 74);
    if (flagvalue < 0) {
 real_display_nametab(player, list_files, (char *) "Unknown file.  Use one of:", 1, "file_c.c", 76);
 return;
    }
    fcache_send(player, flagvalue);
}

canonical_original_code:
void do_list_file(int player, int cause, int extra, char *arg)
{
    int flagvalue;
    flagvalue = real_search_nametab(player, list_files, arg, "file_c.c", 74);
    if (flagvalue < 0) {
 real_display_nametab(player, list_files, (char *) "Unknown file.  Use one of:", 1, "file_c.c", 76);
 return;
    }
    fcache_send(player, flagvalue);
}

variable_types: player int

variable_types: cause int

variable_types: extra int

variable_types:
arg
char *

variable_types: flagvalue int


decompiled_code:
__int64 __fastcall fcache_load(unsigned int a1)
{
char *v2; // rax
const char *v3; // rcx
void **v4; // rbx
unsigned int v5; // eax
void *v6; // rdi
_BYTE *v8; // [rsp+8h] [rbp-E0h] BYREF
_BYTE *v9; // [rsp+10h] [rbp-D8h] BYREF
char *v10; // [rsp+18h] [rbp-D0h] BYREF
char s[200]; // [rsp+20h] [rbp-C8h] BYREF

v9 = (_BYTE *)pool_alloc(2LL, "fcache_load.lbuf", 248LL, "file_c.c");
v8 = v9;
v2 = (char *)pool_alloc(0LL, "fcache_load.sbuf", 249LL, "file_c.c");
v3 = (const char *)fcache;
v10 = v2;
if ( fcache )
{
v4 = &fcache;
do
{
while ( 1 )
{
sprintf(s, "%s/%s", (const char *)(unsigned int)((_DWORD)&mudconf + 148), v3);
v5 = fcache_read((__int64 *)v4 + 1, s);
if ( a1 != -1 && (*(_BYTE *)(db + 88LL * (int)a1 + 41) & 8) == 0 )
break;
v3 = (const char *)v4[3];
v4 += 3;
if ( !v3 )
goto LABEL_9;
}
sprintf(v10, "%d", v5);
if ( v4 == &fcache )
safe_copy_str("File sizes: ", v8, &v9, 3998LL);
else
safe_copy_str(" ", v8, &v9, 3998LL);
v6 = v4[2];
v4 += 3;
safe_copy_str(v6, v8, &v9, 3998LL);
safe_copy_str("...", v8, &v9, 3998LL);
safe_copy_str(v10, v8, &v9, 3998LL);
v3 = (const char *)*v4;
}
while ( *v4 );
}
LABEL_9:
*v9 = 0;
if ( a1 != -1 && (*(_BYTE *)(db + 88LL * (int)a1 + 41) & 8) == 0 )
notify_check(a1, a1, v8, 0LL, "le '%.100s' (too large).", 0LL);
pool_free(2LL, &v8, 268LL, "file_c.c");
return pool_free(0LL, &v10, 269LL, "file_c.c");
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
char *v2; // rax
const char *v3; // rcx
void **v4; // rbx
unsigned int v5; // eax
void *v6; // rdi
_BYTE *v8; // [rsp+8h] [rbp-E0h] BYREF
_BYTE *v9; // [rsp+10h] [rbp-D8h] BYREF
char *v10; // [rsp+18h] [rbp-D0h] BYREF
char s[200]; // [rsp+20h] [rbp-C8h] BYREF

v9 = (_BYTE *)pool_alloc(2LL, "fcache_load.lbuf", 248LL, "file_c.c");
v8 = v9;
v2 = (char *)pool_alloc(0LL, "fcache_load.sbuf", 249LL, "file_c.c");
v3 = (const char *)fcache;
v10 = v2;
if ( fcache )
{
v4 = &fcache;
do
{
while ( 1 )
{
sprintf(s, "%s/%s", (const char *)(unsigned int)((_DWORD)&mudconf + 148), v3);
v5 = func1((__int64 *)v4 + 1, s);
if ( a1 != -1 && (*(_BYTE *)(db + 88LL * (int)a1 + 41) & 8) == 0 )
break;
v3 = (const char *)v4[3];
v4 += 3;
if ( !v3 )
goto LABEL_9;
}
sprintf(v10, "%d", v5);
if ( v4 == &fcache )
safe_copy_str("File sizes: ", v8, &v9, 3998LL);
else
safe_copy_str(" ", v8, &v9, 3998LL);
v6 = v4[2];
v4 += 3;
safe_copy_str(v6, v8, &v9, 3998LL);
safe_copy_str("...", v8, &v9, 3998LL);
safe_copy_str(v10, v8, &v9, 3998LL);
v3 = (const char *)*v4;
}
while ( *v4 );
}
LABEL_9:
*v9 = 0;
if ( a1 != -1 && (*(_BYTE *)(db + 88LL * (int)a1 + 41) & 8) == 0 )
notify_check(a1, a1, v8, 0LL, "le '%.100s' (too large).", 0LL);
pool_free(2LL, &v8, 268LL, "file_c.c");
return pool_free(0LL, &v10, 269LL, "file_c.c");
}

original_code:
void
fcache_load(dbref player)
{
    FCACHE *fp;
    char *buff, *bufc, *sbuf, filename[129 + 32];
    int i;
    buff = bufc = pool_alloc(2,"fcache_load.lbuf",248,"file_c.c");
    sbuf = pool_alloc(0,"fcache_load.sbuf",249,"file_c.c");
    for (fp = fcache; fp->filename; fp++) {
        sprintf(filename, "%s/%s", mudconf.txt_dir, fp->filename);
 i = fcache_read(&fp->fileblock, filename);
 if ((player != (-1)) && !((db[player].flags & 0x00000800) != 0)) {
     sprintf(sbuf, "%d", i);
     if (fp == fcache)
  safe_copy_str((char *) "File sizes: ",buff,&bufc,(4000 -2));
     else
  safe_copy_str((char *) "  ",buff,&bufc,(4000 -2));
     safe_copy_str((char *) fp->desc,buff,&bufc,(4000 -2));
     safe_copy_str((char *) "...",buff,&bufc,(4000 -2));
     safe_copy_str(sbuf,buff,&bufc,(4000 -2));
 }
    }
    *bufc = '\0';
    if ((player != (-1)) && !((db[player].flags & 0x00000800) != 0)) {
 notify_check(player,player,buff,0, 1|(2048|8|1024)|(4), 0);
    }
    pool_free(2,((char **)&(buff)),268,"file_c.c");
    pool_free(0,((char **)&(sbuf)),269,"file_c.c");
}

canonical_original_code:
void fcache_load(int player)
{
    struct filecache_hdr *fp;
    char *buff; char *bufc; char *sbuf; char filename[-1];
    int i;
    buff = bufc = pool_alloc(2,"fcache_load.lbuf",248,"file_c.c");
    sbuf = pool_alloc(0,"fcache_load.sbuf",249,"file_c.c");
    for (fp = fcache; fp->filename; fp++) {
        sprintf(filename, "%s/%s", mudconf.txt_dir, fp->filename);
 i = fcache_read(&fp->fileblock, filename);
 if ((player != (-1)) && !((db[player].flags & 0x00000800) != 0)) {
     sprintf(sbuf, "%d", i);
     if (fp == fcache)
  safe_copy_str((char *) "File sizes: ",buff,&bufc,(4000 -2));
     else
  safe_copy_str((char *) "  ",buff,&bufc,(4000 -2));
     safe_copy_str((char *) fp->desc,buff,&bufc,(4000 -2));
     safe_copy_str((char *) "...",buff,&bufc,(4000 -2));
     safe_copy_str(sbuf,buff,&bufc,(4000 -2));
 }
    }
    *bufc = '\0';
    if ((player != (-1)) && !((db[player].flags & 0x00000800) != 0)) {
 notify_check(player,player,buff,0, 1|(2048|8|1024)|(4), 0);
    }
    pool_free(2,((char **)&(buff)),268,"file_c.c");
    pool_free(0,((char **)&(sbuf)),269,"file_c.c");
}

variable_types: struct filecache_hdr { char *filename; struct filecache_block { struct filecache_block_hdr { struct filecache_block *nxt; int nchars; } hdr; char data[-1]; } *fileblock; char *desc; } *

variable_types:
bufc
char *

variable_types:
sbuf
char *

variable_types:
filename
char [-1]

variable_types: i int

user_defined_types: struct filecache_hdr { char *filename; struct filecache_block *fileblock; char *desc; }


decompiled_code:
__int64 fcache_init()
{
void **v0; // rax

if ( fcache )
{
v0 = &fcache;
do
{
v0[1] = 0LL;
v0 += 3;
}
while ( *v0 );
}
return fcache_load(0xFFFFFFFF);
}

canonical_decompiled_code:
__int64 func7()
{
void **v0; // rax

if ( fcache )
{
v0 = &fcache;
do
{
v0[1] = 0LL;
v0 += 3;
}
while ( *v0 );
}
return func6(0xFFFFFFFF);
}

original_code:
void
fcache_init(void)
{
    FCACHE *fp;
    for (fp = fcache; fp->filename; fp++) {
 fp->fileblock = ((void *)0);
    }
    fcache_load((-1));
}

canonical_original_code:
void fcache_init()
{
    struct filecache_hdr *fp;
    for (fp = fcache; fp->filename; fp++) {
 fp->fileblock = ((void *)0);
    }
    fcache_load((-1));
}


original_code:
int obj_siz(Obj *o)
{
 int i;
 int siz;
 siz = (sizeof(Objname) + sizeof(int));
 for(i = 0; i < o->at_count; i++)
  siz += (((o->atrs)[i]).size + (sizeof(int) * 2));
 return(siz);
}

canonical_original_code:
int obj_siz(struct Obj *o)
{
 int i;
 int siz;
 siz = (sizeof(Objname) + sizeof(int));
 for(i = 0; i < o->at_count; i++)
  siz += (((o->atrs)[i]).size + (sizeof(int) * 2));
 return(siz);
}

variable_types: struct Obj { unsigned int name; int at_count; struct Attrib { int attrnum; int size; char *data; } *atrs; } *

variable_types: siz int

user_defined_types: struct Obj { unsigned int name; int at_count; struct Attrib *atrs; }


dpfirsthash

original_code:
int dpfirsthash(const char *kbuf, int ksiz){
  const unsigned char *p;
  unsigned int sum;
  int i;
  ((void) (0));
  p = (const unsigned char *)kbuf;
  sum = 751;
  for(i = 0; i < ksiz; i++){
    sum = sum * 31 + p[i];
  }
  return (sum * 87767623) & 0x7FFFFFFF;
}

canonical_original_code:
int dpfirsthash(char *kbuf, int ksiz){
  unsigned char *p;
  unsigned int sum;
  int i;
  ((void) (0));
  p = (unsigned char *)kbuf;
  sum = 751;
  for(i = 0; i < ksiz; i++){
    sum = sum * 31 + p[i];
  }
  return (sum * 87767623) & 0x7FFFFFFF;
}

variable_types:
kbuf
char *

variable_types: ksiz int

variable_types:
p
unsigned char *

variable_types:
sum
unsigned int


dpsecondhash

decompiled_code:
__int64 __fastcall dpsecondhash(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned __int8 *v3; // rdx
__int64 v4; // rsi
int v5; // eax

v2 = a2 - 1;
if ( a2 - 1 < 0 )
return 1212507733LL;
v3 = (unsigned __int8 *)(a1 + (int)v2);
v4 = a1 + a2 - 2 - v2;
v5 = 19780211;
do
v5 = 37 * v5 + *v3--;
while ( (unsigned __int8 *)v4 != v3 );
return (43321879 * v5) & 0x7FFFFFFF;
}

original_code:
int dpsecondhash(const char *kbuf, int ksiz){
  const unsigned char *p;
  unsigned int sum;
  int i;
  ((void) (0));
  p = (const unsigned char *)kbuf;
  sum = 19780211;
  for(i = ksiz - 1; i >= 0; i--){
    sum = sum * 37 + p[i];
  }
  return (sum * 43321879) & 0x7FFFFFFF;
}

canonical_original_code:
int dpsecondhash(char *kbuf, int ksiz){
  unsigned char *p;
  unsigned int sum;
  int i;
  ((void) (0));
  p = (unsigned char *)kbuf;
  sum = 19780211;
  for(i = ksiz - 1; i >= 0; i--){
    sum = sum * 37 + p[i];
  }
  return (sum * 43321879) & 0x7FFFFFFF;
}


dpthirdhash

decompiled_code:
__int64 __fastcall dpthirdhash(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned __int8 *v3; // rdx
__int64 v4; // rsi
int v5; // eax
int v6; // ecx

v2 = a2 - 1;
if ( a2 - 1 < 0 )
return 1681303583LL;
v3 = (unsigned __int8 *)(a1 + (int)v2);
v4 = a1 + a2 - 2 - v2;
v5 = 774831917;
do
{
v6 = *v3--;
v5 = v6 + 29 * v5;
}
while ( (unsigned __int8 *)v4 != v3 );
return (5157883 * v5) & 0x7FFFFFFF;
}

original_code:
int dpthirdhash(const char *kbuf, int ksiz){
  const unsigned char *p;
  unsigned int sum;
  int i;
  ((void) (0));
  p = (const unsigned char *)kbuf;
  sum = 774831917;
  for(i = ksiz - 1; i >= 0; i--){
    sum = sum * 29 + p[i];
  }
  return (sum * 5157883) & 0x7FFFFFFF;
}

canonical_original_code:
int dpthirdhash(char *kbuf, int ksiz){
  unsigned char *p;
  unsigned int sum;
  int i;
  ((void) (0));
  p = (unsigned char *)kbuf;
  sum = 774831917;
  for(i = ksiz - 1; i >= 0; i--){
    sum = sum * 29 + p[i];
  }
  return (sum * 5157883) & 0x7FFFFFFF;
}


setrandstr

original_code:
int setrandstr(char *buf){
  int i, len;
  len = rand() % (12 - 4) + 4 + 1;
  for(i = 0; i < len; i++){
    buf[i] = rand() % 256;
  }
  buf[len] = '\0';
  return len;
}

canonical_original_code:
int setrandstr(char *buf){
  int i; int len;
  len = rand() % (12 - 4) + 4 + 1;
  for(i = 0; i < len; i++){
    buf[i] = rand() % 256;
  }
  buf[len] = '\0';
  return len;
}

variable_types:
buf
char *

variable_types: len int


printcol

original_code:
void printcol(const char *name, int (*hfunc)(const char *, int), int rnum, int bnum){
  int *array, i, len, col;
  char buf[32];
  if(!(array = calloc(bnum, sizeof(int)))) return;
  for(i = 1; i <= rnum; i++){
    len = setrandstr(buf);
    array[hfunc(buf, len) % bnum]++;
  }
  col = 0;
  for(i = 0; i < bnum; i++){
    if(array[i] > 1) col += array[i] - 1;
  }
  printf("collision rate: %5.2f%% (%8d) by %s\n",
         ((double)col / (double)rnum) * 100.0, col, name);
  free(array);
}

canonical_original_code:
void printcol(char *name, int (*hfunc)(char *, int), int rnum, int bnum){
  int *array; int i; int len; int col;
  char buf[32];
  if(!(array = calloc(bnum, sizeof(int)))) return;
  for(i = 1; i <= rnum; i++){
    len = setrandstr(buf);
    array[hfunc(buf, len) % bnum]++;
  }
  col = 0;
  for(i = 0; i < bnum; i++){
    if(array[i] > 1) col += array[i] - 1;
  }
  printf("collision rate: %5.2f%% (%8d) by %s\n",
         ((double)col / (double)rnum) * 100.0, col, name);
  free(array);
}

variable_types:
name
char *

variable_types:
hfunc
int (*)(char *, int)

variable_types: rnum int

variable_types: bnum int

variable_types:
array
int *

variable_types: col int

variable_types:
buf
char [32]


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "%s: test unit for hash functions\n\n", a1);
fwrite("usage:\n", 1uLL, 7uLL, stderr);
fprintf(stderr, " %s rnum bnum : print collision rate\n", a1);
fprintf(stderr, " %s rnum : print values\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
fprintf(stderr, "%s: test unit for hash functions\n\n", a1);
fwrite("usage:\n", 1uLL, 7uLL, stderr);
fprintf(stderr, " %s rnum bnum : print collision rate\n", a1);
fprintf(stderr, " %s rnum : print values\n", a1);
exit(1);
}

original_code:
void usage(const char *progname){
  fprintf(stderr, "%s: test unit for hash functions\n\n", progname);
  fprintf(stderr, "usage:\n");
  fprintf(stderr, "  %s rnum bnum  : print collision rate\n", progname);
  fprintf(stderr, "  %s rnum       : print values\n", progname);
  exit(1);
}

canonical_original_code:
void usage(char *progname){
  fprintf(stderr, "%s: test unit for hash functions\n\n", progname);
  fprintf(stderr, "usage:\n");
  fprintf(stderr, "  %s rnum bnum  : print collision rate\n", progname);
  fprintf(stderr, "  %s rnum       : print values\n", progname);
  exit(1);
}

variable_types:
progname
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
unsigned int v5; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // ebx
int v10; // eax
int v11; // ebp
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned __int8 v15[72]; // [rsp+0h] [rbp-48h] BYREF

if ( argc <= 1 )
{
v7 = time(0LL);
srand(v7);
goto LABEL_8;
}
v3 = atoi(argv[1]);
if ( argc == 2 )
{
v8 = time(0LL);
srand(v8);
}
else
{
v4 = atoi(argv[2]);
v5 = time(0LL);
srand(v5);
if ( v3 <= 0 )
goto LABEL_8;
if ( v4 > 0 )
{
printf("number of records: %d\n", (unsigned int)v3);
printf("number of buckets: %d\n", (unsigned int)v4);
printcol("dpfirsthash", (__int64 (__fastcall *)(_BYTE *, _QWORD))dpfirsthash, v3, v4);
printcol("dpsecondhash", (__int64 (__fastcall *)(_BYTE *, _QWORD))dpsecondhash, v3, v4);
printcol("dpthirdhash", (__int64 (__fastcall *)(_BYTE *, _QWORD))dpthirdhash, v3, v4);
return 0;
}
}
if ( v3 <= 0 )
LABEL_8:
usage(*argv);
if ( v3 != 1 )
{
v9 = 1;
do
{
v10 = sprintf((char *)v15, "%X", v9++);
v11 = v10;
printf("%s", (const char *)v15);
v12 = dpfirsthash(v15, v11);
printf("\t%10d", v12);
v13 = dpsecondhash((__int64)v15, v11);
printf("\t%10d", v13);
v14 = dpthirdhash((__int64)v15, v11);
printf("\t%10d", v14);
putchar(10);
}
while ( v3 != v9 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
unsigned int v5; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // ebx
int v10; // eax
int v11; // ebp
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned __int8 v15[72]; // [rsp+0h] [rbp-48h] BYREF

if ( argc <= 1 )
{
v7 = time(0LL);
srand(v7);
goto LABEL_8;
}
v3 = atoi(argv[1]);
if ( argc == 2 )
{
v8 = time(0LL);
srand(v8);
}
else
{
v4 = atoi(argv[2]);
v5 = time(0LL);
srand(v5);
if ( v3 <= 0 )
goto LABEL_8;
if ( v4 > 0 )
{
printf("number of records: %d\n", (unsigned int)v3);
printf("number of buckets: %d\n", (unsigned int)v4);
func5("dpfirsthash", (__int64 (__fastcall *)(_BYTE *, _QWORD))dpfirsthash, v3, v4);
func5("dpsecondhash", (__int64 (__fastcall *)(_BYTE *, _QWORD))dpsecondhash, v3, v4);
func5("dpthirdhash", (__int64 (__fastcall *)(_BYTE *, _QWORD))dpthirdhash, v3, v4);
return 0;
}
}
if ( v3 <= 0 )
LABEL_8:
func3(*argv);
if ( v3 != 1 )
{
v9 = 1;
do
{
v10 = sprintf((char *)v15, "%X", v9++);
v11 = v10;
printf("%s", (const char *)v15);
v12 = func0(v15, v11);
printf("\t%10d", v12);
v13 = func1((__int64)v15, v11);
printf("\t%10d", v13);
v14 = func2((__int64)v15, v11);
printf("\t%10d", v14);
putchar(10);
}
while ( v3 != v9 );
}
return 0;
}

original_code:
int main(int argc, char **argv){
  int rnum, bnum, i, len;
  char buf[32];
  rnum = argc > 1 ? atoi(argv[1]) : -1;
  bnum = argc > 2 ? atoi(argv[2]) : -1;
  srand(time(((void *)0)));
  if(rnum > 0 && bnum > 0){
    printf("number of records: %d\n", rnum);
    printf("number of buckets: %d\n", bnum);
    printcol("dpfirsthash", dpfirsthash, rnum, bnum);
    printcol("dpsecondhash", dpsecondhash, rnum, bnum);
    printcol("dpthirdhash", dpthirdhash, rnum, bnum);
  } else if(rnum > 0){
    for(i = 1; i < rnum; i++){
      len = sprintf(buf, "%X", i);
      printf("%s", buf);
      printf("\t%10d", dpfirsthash(buf, len));
      printf("\t%10d", dpsecondhash(buf, len));
      printf("\t%10d", dpthirdhash(buf, len));
      printf("\n");
    }
  } else {
    usage(argv[0]);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int rnum; int bnum; int i; int len;
  char buf[32];
  rnum = argc > 1 ? atoi(argv[1]) : -1;
  bnum = argc > 2 ? atoi(argv[2]) : -1;
  srand(time(((void *)0)));
  if(rnum > 0 && bnum > 0){
    printf("number of records: %d\n", rnum);
    printf("number of buckets: %d\n", bnum);
    printcol("dpfirsthash", dpfirsthash, rnum, bnum);
    printcol("dpsecondhash", dpsecondhash, rnum, bnum);
    printcol("dpthirdhash", dpthirdhash, rnum, bnum);
  } else if(rnum > 0){
    for(i = 1; i < rnum; i++){
      len = sprintf(buf, "%X", i);
      printf("%s", buf);
      printf("\t%10d", dpfirsthash(buf, len));
      printf("\t%10d", dpsecondhash(buf, len));
      printf("\t%10d", dpthirdhash(buf, len));
      printf("\n");
    }
  } else {
    usage(argv[0]);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int


decompiled_code:
__int64 local_sqlite_init()
{
__int64 result; // rax
char *v1; // rbp
char **v2; // r14
char v3; // bl
char *v4; // r12
const unsigned __int16 **v5; // r15
char **v6; // rsi
char *v7; // [rsp+8h] [rbp-D0h]
struct stat v8; // [rsp+10h] [rbp-C8h] BYREF

if ( stat((const char *)(unsigned int)((_DWORD)&mudconf + 32844), &v8) == -1 )
{
result = (__int64)getcwd(tempbuff2, 0xFA0uLL);
if ( *((int *)&mudconf + 2026) < 0 )
{
result = start_log("SQL", "FAIL");
if ( (_DWORD)result )
{
sprintf(
tempbuff,
"stat - unable to read database path '%s/%s'",
tempbuff2,
(const char *)(unsigned int)((_DWORD)&mudconf + 32844));
log_text(tempbuff);
result = end_log();
}
}
}
else if ( (v8.st_mode & 0x4000) != 0 )
{
result = pool_alloc(0LL, "init_sqlite_functab", 335LL, "sqlite.c");
v1 = mysql_fun_table_0;
v2 = &mysql_fun_table_0;
v7 = (char *)result;
if ( mysql_fun_table_0 )
{
do
{
v3 = *v1;
v4 = v7;
if ( *v1 )
{
v4 = v7;
v5 = _ctype_b_loc();
do
{
if ( ((*v5)[v3] & 0x100) != 0 )
v3 = (*_ctype_tolower_loc())[v3];
++v1;
*v4++ = v3;
v3 = *v1;
}
while ( *v1 );
}
*v4 = 0;
v6 = v2;
v2 += 4;
result = real_hashadd2(v7, v6, (unsigned int)((_DWORD)&mudstate + 5928), 1LL, "sqlite.c", 345LL);
v1 = *v2;
}
while ( *v2 );
}
}
else
{
getcwd(tempbuff2, 0xFA0uLL);
sprintf(
tempbuff,
"stat - %s/%s is not a directory",
tempbuff2,
(const char *)(unsigned int)((_DWORD)&mudconf + 32844));
result = *((unsigned int *)&mudconf + 2026);
if ( (int)result < 0 )
{
result = start_log("SQL", "FAIL");
if ( (_DWORD)result )
{
log_text(tempbuff);
result = end_log();
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char *v1; // rbp
char **v2; // r14
char v3; // bl
char *v4; // r12
const unsigned __int16 **v5; // r15
char **v6; // rsi
char *v7; // [rsp+8h] [rbp-D0h]
struct stat v8; // [rsp+10h] [rbp-C8h] BYREF

if ( stat((const char *)(unsigned int)((_DWORD)&mudconf + 32844), &v8) == -1 )
{
result = (__int64)getcwd(tempbuff2, 0xFA0uLL);
if ( *((int *)&mudconf + 2026) < 0 )
{
result = start_log("SQL", "FAIL");
if ( (_DWORD)result )
{
sprintf(
tempbuff,
"stat - unable to read database path '%s/%s'",
tempbuff2,
(const char *)(unsigned int)((_DWORD)&mudconf + 32844));
log_text(tempbuff);
result = end_log();
}
}
}
else if ( (v8.st_mode & 0x4000) != 0 )
{
result = pool_alloc(0LL, "init_sqlite_functab", 335LL, "sqlite.c");
v1 = mysql_fun_table_0;
v2 = &mysql_fun_table_0;
v7 = (char *)result;
if ( mysql_fun_table_0 )
{
do
{
v3 = *v1;
v4 = v7;
if ( *v1 )
{
v4 = v7;
v5 = _ctype_b_loc();
do
{
if ( ((*v5)[v3] & 0x100) != 0 )
v3 = (*_ctype_tolower_loc())[v3];
++v1;
*v4++ = v3;
v3 = *v1;
}
while ( *v1 );
}
*v4 = 0;
v6 = v2;
v2 += 4;
result = real_hashadd2(v7, v6, (unsigned int)((_DWORD)&mudstate + 5928), 1LL, "sqlite.c", 345LL);
v1 = *v2;
}
while ( *v2 );
}
}
else
{
getcwd(tempbuff2, 0xFA0uLL);
sprintf(
tempbuff,
"stat - %s/%s is not a directory",
tempbuff2,
(const char *)(unsigned int)((_DWORD)&mudconf + 32844));
result = *((unsigned int *)&mudconf + 2026);
if ( (int)result < 0 )
{
result = start_log("SQL", "FAIL");
if ( (_DWORD)result )
{
log_text(tempbuff);
result = end_log();
}
}
}
return result;
}

original_code:
void local_sqlite_init(void) {
   FUN *fp;
   char *buff, *cp, *dp;
   struct stat sb;
   if( stat( mudconf.sqlite_db_path, &sb ) == -1 ) {
      getcwd( tempbuff2, 4000 );
      if ((((0x80000000) & mudconf.log_options) != 0) && start_log("SQL", "FAIL")) {
         sprintf( tempbuff, "stat - unable to read database path '%s/%s'", tempbuff2, mudconf.sqlite_db_path );
         log_text(tempbuff);
      end_log(); }
      return;
   }
   if( ~sb.st_mode & 0040000 ) {
      getcwd( tempbuff2, 4000 );
      sprintf( tempbuff, "stat - %s/%s is not a directory", tempbuff2, mudconf.sqlite_db_path );
      if ((((0x80000000) & mudconf.log_options) != 0) && start_log("SQL", "FAIL")) {
         log_text(tempbuff);
      end_log(); }
      return;
   }
   static FUN mysql_fun_table[] = {
      {"SQLITE_QUERY", local_fun_sqlite_query, 0, 1, 0x00000002, 0 },
      {((void *)0), ((void *)0), 0, 0, 0, 0}
   };
   buff = pool_alloc(0,"init_sqlite_functab",335,"sqlite.c");
   for (fp = mysql_fun_table ; fp->name ; fp++) {
      cp = (char *) fp->name;
      dp = buff;
      while (*cp) {
         *dp = (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short int) _ISupper) ? tolower(*cp) : (*cp));
         cp++;
         dp++;
      }
      *dp = '\0';
      real_hashadd2(buff, (int *) fp, &mudstate.func_htab, 1, "sqlite.c", 345);
   }
}

canonical_original_code:
void local_sqlite_init() {
   struct fun *fp;
   char *buff; char *cp; char *dp;
   struct stat sb;
   if( stat( mudconf.sqlite_db_path, &sb ) == -1 ) {
      getcwd( tempbuff2, 4000 );
      if ((((0x80000000) & mudconf.log_options) != 0) && start_log("SQL", "FAIL")) {
         sprintf( tempbuff, "stat - unable to read database path '%s/%s'", tempbuff2, mudconf.sqlite_db_path );
         log_text(tempbuff);
      end_log(); }
      return;
   }
   if( ~sb.st_mode & 0040000 ) {
      getcwd( tempbuff2, 4000 );
      sprintf( tempbuff, "stat - %s/%s is not a directory", tempbuff2, mudconf.sqlite_db_path );
      if ((((0x80000000) & mudconf.log_options) != 0) && start_log("SQL", "FAIL")) {
         log_text(tempbuff);
      end_log(); }
      return;
   }
   static struct fun mysql_fun_table[] = {
      {"SQLITE_QUERY", local_fun_sqlite_query, 0, 1, 0x00000002, 0 },
      {((void *)0), ((void *)0), 0, 0, 0, 0}
   };
   buff = pool_alloc(0,"init_sqlite_functab",335,"sqlite.c");
   for (fp = mysql_fun_table ; fp->name ; fp++) {
      cp = (char *) fp->name;
      dp = buff;
      while (*cp) {
         *dp = (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short) _ISupper) ? tolower(*cp) : (*cp));
         cp++;
         dp++;
      }
      *dp = '\0';
      real_hashadd2(buff, (int *) fp, &mudstate.func_htab, 1, "sqlite.c", 345);
   }
}

variable_types: struct fun { char *name; void (*fun)(char *, char **, int, int, int, char *[], int, char *[], int); int nargs; int flags; int perms; int perms2; } *

variable_types:
buff
char *

variable_types:
cp
char *

variable_types:
dp
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: struct fun { char *name; void (*fun)(char *, char **, int, int, int, char *[], int, char *[], int); int nargs; int flags; int perms; int perms2; } []

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void skip_whitespace()
{
__int64 v0; // rbp
__int64 v1; // rbx
const unsigned __int16 *v2; // rdx
char v3; // al

v0 = parsebuf;
v1 = *(char *)parsebuf;
if ( (_BYTE)v1 )
{
v2 = *_ctype_b_loc();
v3 = 0;
while ( (v2[v1] & 0x2000) != 0 )
{
v1 = *(char *)++v0;
v3 = 1;
if ( !(_BYTE)v1 )
goto LABEL_6;
}
if ( !v3 )
return;
LABEL_6:
parsebuf = v0;
}
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rbp
__int64 v1; // rbx
const unsigned __int16 *v2; // rdx
char v3; // al

v0 = parsebuf;
v1 = *(char *)parsebuf;
if ( (_BYTE)v1 )
{
v2 = *_ctype_b_loc();
v3 = 0;
while ( (v2[v1] & 0x2000) != 0 )
{
v1 = *(char *)++v0;
v3 = 1;
if ( !(_BYTE)v1 )
goto LABEL_6;
}
if ( !v3 )
return;
LABEL_6:
parsebuf = v0;
}
}

original_code:
static void
skip_whitespace(void)
{
    while (*parsebuf && ((*__ctype_b_loc ())[(int) (((int)*parsebuf))] & (unsigned short int) _ISspace))
 parsebuf++;
}

canonical_original_code:
static void skip_whitespace()
{
    while (*parsebuf && ((*__ctype_b_loc ())[(int) (((int)*parsebuf))] & (unsigned short) _ISspace))
 parsebuf++;
}


decompiled_code:
void *__fastcall unparse_boolexp_quiet(__int64 a1, char *a2)
{
_BYTE *v2; // rax

buftop = (__int64)&boolexp_buf;
unparse_boolexp1(a1, a2, 3, 2LL);
v2 = (_BYTE *)buftop++;
*v2 = 0;
return &boolexp_buf;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, char *a2)
{
_BYTE *v2; // rax

buftop = (__int64)&boolexp_buf;
func1(a1, a2, 3, 2LL);
v2 = (_BYTE *)buftop++;
*v2 = 0;
return &boolexp_buf;
}

original_code:
char *unparse_boolexp_quiet(dbref player, BOOLEXP *b)
{
 buftop = boolexp_buf;
 unparse_boolexp1(player, b, 3, 2);
 *buftop++ = '\0';
 return boolexp_buf;
}

canonical_original_code:
char *unparse_boolexp_quiet(int player, struct boolexp *b)
{
 buftop = boolexp_buf;
 unparse_boolexp1(player, b, 3, 2);
 *buftop++ = '\0';
 return boolexp_buf;
}

variable_types: player int

variable_types: struct boolexp { char type; struct boolexp *sub1; struct boolexp *sub2; int thing; } *


decompiled_code:
void *__fastcall unparse_boolexp(__int64 a1, char *a2)
{
_BYTE *v2; // rax

buftop = (__int64)&boolexp_buf;
unparse_boolexp1(a1, a2, 3, 1LL);
v2 = (_BYTE *)buftop++;
*v2 = 0;
return &boolexp_buf;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, char *a2)
{
_BYTE *v2; // rax

buftop = (__int64)&boolexp_buf;
func1(a1, a2, 3, 1LL);
v2 = (_BYTE *)buftop++;
*v2 = 0;
return &boolexp_buf;
}

original_code:
char *unparse_boolexp(dbref player, BOOLEXP *b)
{
 buftop = boolexp_buf;
 unparse_boolexp1(player, b, 3, 1);
 *buftop++ = '\0';
 return boolexp_buf;
}

canonical_original_code:
char *unparse_boolexp(int player, struct boolexp *b)
{
 buftop = boolexp_buf;
 unparse_boolexp1(player, b, 3, 1);
 *buftop++ = '\0';
 return boolexp_buf;
}

user_defined_types: struct boolexp { char type; struct boolexp *sub1; struct boolexp *sub2; int thing; }


decompiled_code:
void *__fastcall unparse_boolexp_decompile(__int64 a1, char *a2)
{
_BYTE *v2; // rax

buftop = (__int64)&boolexp_buf;
unparse_boolexp1(a1, a2, 3, 3LL);
v2 = (_BYTE *)buftop++;
*v2 = 0;
return &boolexp_buf;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, char *a2)
{
_BYTE *v2; // rax

buftop = (__int64)&boolexp_buf;
func1(a1, a2, 3, 3LL);
v2 = (_BYTE *)buftop++;
*v2 = 0;
return &boolexp_buf;
}

original_code:
char *unparse_boolexp_decompile(dbref player, BOOLEXP *b)
{
 buftop = boolexp_buf;
 unparse_boolexp1(player, b, 3, 3);
 *buftop++ = '\0';
 return boolexp_buf;
}

canonical_original_code:
char *unparse_boolexp_decompile(int player, struct boolexp *b)
{
 buftop = boolexp_buf;
 unparse_boolexp1(player, b, 3, 3);
 *buftop++ = '\0';
 return boolexp_buf;
}


decompiled_code:
void *__fastcall unparse_boolexp_function(__int64 a1, char *a2)
{
_BYTE *v2; // rax

buftop = (__int64)&boolexp_buf;
unparse_boolexp1(a1, a2, 3, 4LL);
v2 = (_BYTE *)buftop++;
*v2 = 0;
return &boolexp_buf;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, char *a2)
{
_BYTE *v2; // rax

buftop = (__int64)&boolexp_buf;
func1(a1, a2, 3, 4LL);
v2 = (_BYTE *)buftop++;
*v2 = 0;
return &boolexp_buf;
}

original_code:
char *unparse_boolexp_function(dbref player, BOOLEXP *b)
{
 buftop = boolexp_buf;
 unparse_boolexp1(player, b, 3, 4);
 *buftop++ = '\0';
 return boolexp_buf;
}

canonical_original_code:
char *unparse_boolexp_function(int player, struct boolexp *b)
{
 buftop = boolexp_buf;
 unparse_boolexp1(player, b, 3, 4);
 *buftop++ = '\0';
 return boolexp_buf;
}


printdebug

decompiled_code:
int printdebug()
{
unsigned int *v0; // rax
unsigned int v1; // ebx
__int64 v2; // r9
const char *v3; // r8
__int64 v4; // rcx

fprintf(stderr, "%s: debug stack depth = %d\n", (const char *)programname, *((unsigned int *)debugmem + 3));
v0 = (unsigned int *)debugmem;
if ( *((int *)debugmem + 3) > 0 )
{
v1 = 0;
do
{
v2 = v0[2 * v1 + 6];
v3 = (const char *)*((_QWORD *)&aDebugFilenameArray + (int)v0[2 * v1 + 5]);
v4 = v1++;
fprintf(stderr, "%s: stackframe %d = %s, line %d\n", (const char *)programname, v4, v3, v2);
v0 = (unsigned int *)debugmem;
}
while ( *((_DWORD *)debugmem + 3) > (signed int)v1 );
}
return fprintf(stderr, "\n%s: last db fetch was for #%d\n", (const char *)programname, v0[2]);
}

canonical_decompiled_code:
int func0()
{
unsigned int *v0; // rax
unsigned int v1; // ebx
__int64 v2; // r9
const char *v3; // r8
__int64 v4; // rcx

fprintf(stderr, "%s: debug stack depth = %d\n", (const char *)programname, *((unsigned int *)debugmem + 3));
v0 = (unsigned int *)debugmem;
if ( *((int *)debugmem + 3) > 0 )
{
v1 = 0;
do
{
v2 = v0[2 * v1 + 6];
v3 = (const char *)*((_QWORD *)&aDebugFilenameArray + (int)v0[2 * v1 + 5]);
v4 = v1++;
fprintf(stderr, "%s: stackframe %d = %s, line %d\n", (const char *)programname, v4, v3, v2);
v0 = (unsigned int *)debugmem;
}
while ( *((_DWORD *)debugmem + 3) > (signed int)v1 );
}
return fprintf(stderr, "\n%s: last db fetch was for #%d\n", (const char *)programname, v0[2]);
}

original_code:
void printdebug( void )
{
  int idx;
  fprintf(stderr, "%s: debug stack depth = %d\n", programname,
          debugmem->stacktop);
  for( idx = 0; idx < debugmem->stacktop; idx++) {
      fprintf(stderr, "%s: stackframe %d = %s, line %d\n", programname,
              idx, aDebugFilenameArray[debugmem->callstack[idx].filenum],
              debugmem->callstack[idx].linenum);
  }
  fprintf(stderr, "\n%s: last db fetch was for #%d\n", programname,
          debugmem->lastdbfetch);
}

canonical_original_code:
void printdebug()
{
  int idx;
  fprintf(stderr, "%s: debug stack depth = %d\n", programname,
          debugmem->stacktop);
  for( idx = 0; idx < debugmem->stacktop; idx++) {
      fprintf(stderr, "%s: stackframe %d = %s, line %d\n", programname,
              idx, aDebugFilenameArray[debugmem->callstack[idx].filenum],
              debugmem->callstack[idx].linenum);
  }
  fprintf(stderr, "\n%s: last db fetch was for #%d\n", programname,
          debugmem->lastdbfetch);
}

variable_types: idx int


decompiled_code:
void handle_usr1()
{
fprintf(stderr, "\n%s: caught SIGUSR1\n", (const char *)programname);
printdebug();
signal(10, handle_usr1);
}

canonical_decompiled_code:
void func1()
{
fprintf(stderr, "\n%s: caught SIGUSR1\n", (const char *)programname);
func0();
signal(10, handle_usr1);
}

original_code:
void handle_usr1(int sig)
{
   fprintf(stderr, "\n%s: caught SIGUSR1\n", programname);
   printdebug();
   signal(10, handle_usr1);
}

variable_types: sig int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rsi
_DWORD *v5; // rbx
__pid_t v6; // eax
__int64 v7; // rcx
__int64 v8; // rdx
FILE *v9; // rdi
_DWORD *v10; // rax
const char *v11; // rdx
FILE *v12; // rdi
const char *v13; // rcx
__pid_t v14; // eax
__pid_t v15; // ebx
__WAIT_STATUS stat_loc; // [rsp+4h] [rbp-24h] BYREF
int shmid[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = *argv;
programname = (__int64)v4;
if ( argc <= 2 )
{
printf("usage: %s <shared mem key> <prog name>\n", v4);
exit(1);
}
if ( (int)_isoc99_sscanf(argv[1], "%d", (char *)&stat_loc.__iptr + 4) < 0 )
{
fprintf(stderr, "** debug_id must be an integer, not '%s' **\n", argv[1]);
exit(1);
}
v5 = (_DWORD *)shmConnect(HIDWORD(stat_loc.__iptr), 1LL, shmid);
debugmem = v5;
v6 = getpid();
v7 = (unsigned int)shmid[0];
v8 = HIDWORD(stat_loc.__iptr);
v5[1] = v6;
v9 = stderr;
*(_DWORD *)debugmem = -1;
fprintf(v9, "Master IPC Debugging stack created w/ key = %d [shared memory id: %d]\n", v8, v7);
v10 = debugmem;
v11 = (const char *)programname;
v12 = stderr;
*((_QWORD *)debugmem + 1) = 0xFFFFFFFFLL;
v13 = argv[2];
v10[4] = 0;
fprintf(v12, "%s: initiating %s\n", v11, v13);
v14 = fork();
v15 = v14;
if ( v14 < 0 )
{
perror("fork");
exit(1);
}
if ( !v14 )
{
execv(argv[2], (char *const *)argv + 2);
perror("execv");
exit(1);
}
signal(10, (__sighandler_t)handle_usr1);
while ( wait((__WAIT_STATUS)&stat_loc) != v15 )
;
fprintf(stderr, "%s: %s exited with status %d\n", (const char *)programname, argv[2], LODWORD(stat_loc.__uptr));
printdebug();
shmdt(debugmem);
shmctl(shmid[0], 0, 0LL);
fprintf(stderr, "%s: exiting\n", (const char *)programname);
return (int)stat_loc.__uptr;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rsi
_DWORD *v5; // rbx
__pid_t v6; // eax
__int64 v7; // rcx
__int64 v8; // rdx
FILE *v9; // rdi
_DWORD *v10; // rax
const char *v11; // rdx
FILE *v12; // rdi
const char *v13; // rcx
__pid_t v14; // eax
__pid_t v15; // ebx
__WAIT_STATUS stat_loc; // [rsp+4h] [rbp-24h] BYREF
int shmid[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = *argv;
programname = (__int64)v4;
if ( argc <= 2 )
{
printf("usage: %s <shared mem key> <prog name>\n", v4);
exit(1);
}
if ( (int)_isoc99_sscanf(argv[1], "%d", (char *)&stat_loc.__iptr + 4) < 0 )
{
fprintf(stderr, "** debug_id must be an integer, not '%s' **\n", argv[1]);
exit(1);
}
v5 = (_DWORD *)shmConnect(HIDWORD(stat_loc.__iptr), 1LL, shmid);
debugmem = v5;
v6 = getpid();
v7 = (unsigned int)shmid[0];
v8 = HIDWORD(stat_loc.__iptr);
v5[1] = v6;
v9 = stderr;
*(_DWORD *)debugmem = -1;
fprintf(v9, "Master IPC Debugging stack created w/ key = %d [shared memory id: %d]\n", v8, v7);
v10 = debugmem;
v11 = (const char *)programname;
v12 = stderr;
*((_QWORD *)debugmem + 1) = 0xFFFFFFFFLL;
v13 = argv[2];
v10[4] = 0;
fprintf(v12, "%s: initiating %s\n", v11, v13);
v14 = fork();
v15 = v14;
if ( v14 < 0 )
{
perror("fork");
exit(1);
}
if ( !v14 )
{
execv(argv[2], (char *const *)argv + 2);
perror("execv");
exit(1);
}
signal(10, (__sighandler_t)handle_usr1);
while ( wait((__WAIT_STATUS)&stat_loc) != v15 )
;
fprintf(stderr, "%s: %s exited with status %d\n", (const char *)programname, argv[2], LODWORD(stat_loc.__uptr));
func0();
shmdt(debugmem);
shmctl(shmid[0], 0, 0LL);
fprintf(stderr, "%s: exiting\n", (const char *)programname);
return (int)stat_loc.__uptr;
}

original_code:
int main( int argc, char *argv[] )
{
  int status;
  int pid;
  int debug_id;
  int shmid;
  int foo;
  programname = argv[0];
  if( argc < 3 ) {
    printf("usage: %s <shared mem key> <prog name>\n", programname);
    exit(1);
  }
  foo = sscanf(argv[1], "%d", &debug_id);
  if ( foo < 0) {
    fprintf(stderr, "** debug_id must be an integer, not '%s' **\n", argv[1]);
    exit(1);
  }
  debugmem = shmConnect(debug_id, 1, &shmid);
  debugmem->debugport = getpid();
  debugmem->mushport = -1;
  fprintf(stderr, "Master IPC Debugging stack created w/ key = %d [shared memory id: %d]\n",
          debug_id, shmid);
  { debugmem->lastdbfetch = -1; debugmem->stacktop = 0; debugmem->stackval = 0; };
  fprintf(stderr, "%s: initiating %s\n", programname, argv[2]);
  if( (pid = fork()) < 0 ) {
    perror("fork");
    exit(1);
  }
  if( pid == 0 ) {
    execv(argv[2], argv + 2);
    perror("execv");
    exit(1);
  }
  signal(10, handle_usr1);
  while( wait(&status) != pid ) {
  }
  fprintf(stderr, "%s: %s exited with status %d\n", programname,
                  argv[2], status);
  printdebug();
  shmdt((const void *)debugmem);
  shmctl(shmid, 0, ((void *)0));
  fprintf(stderr, "%s: exiting\n", programname);
  return status;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int status;
  int pid;
  int debug_id;
  int shmid;
  int foo;
  programname = argv[0];
  if( argc < 3 ) {
    printf("usage: %s <shared mem key> <prog name>\n", programname);
    exit(1);
  }
  foo = sscanf(argv[1], "%d", &debug_id);
  if ( foo < 0) {
    fprintf(stderr, "** debug_id must be an integer, not '%s' **\n", argv[1]);
    exit(1);
  }
  debugmem = shmConnect(debug_id, 1, &shmid);
  debugmem->debugport = getpid();
  debugmem->mushport = -1;
  fprintf(stderr, "Master IPC Debugging stack created w/ key = %d [shared memory id: %d]\n",
          debug_id, shmid);
  { debugmem->lastdbfetch = -1; debugmem->stacktop = 0; debugmem->stackval = 0; };
  fprintf(stderr, "%s: initiating %s\n", programname, argv[2]);
  if( (pid = fork()) < 0 ) {
    perror("fork");
    exit(1);
  }
  if( pid == 0 ) {
    execv(argv[2], argv + 2);
    perror("execv");
    exit(1);
  }
  signal(10, handle_usr1);
  while( wait(&status) != pid ) {
  }
  fprintf(stderr, "%s: %s exited with status %d\n", programname,
                  argv[2], status);
  printdebug();
  shmdt((void *)debugmem);
  shmctl(shmid, 0, ((void *)0));
  fprintf(stderr, "%s: exiting\n", programname);
  return status;
}

variable_types:
argv
char *[]

variable_types: status int

variable_types: pid int

variable_types: shmid int

variable_types: foo int


decompiled_code:
char *real_tprintf(const char *a1, unsigned int a2, char *a3, __int64 *a4, const char *a5, ...)
{
char *v7; // r12
int v9; // er14
int v10; // ebx
size_t v11; // rsi
int v12; // eax
char *v13; // rbx
__int64 v14; // r13
char *v16; // [rsp+10h] [rbp-108h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-100h] BYREF

va_start(arg, a5);
v7 = a3;
if ( !a3 )
{
a4 = (__int64 *)&v16;
v16 = (char *)getTrackedBuffer();
v7 = v16;
}
v9 = getBufferSize(v7);
v10 = v9 - 1;
if ( v9 <= 0 )
{
fprintf(stderr, "ERR: (%s:%d) Unknown pool passed to safe_tprintf.\n", a1, a2);
v11 = v9;
if ( v9 >= 0 )
goto LABEL_5;
}
else
{
v9 = v10 - *(_DWORD *)a4 + (_DWORD)v7;
v11 = v9;
if ( v9 >= 0 )
goto LABEL_5;
}
v9 = 0;
fprintf(stderr, "WRN: (%s:%d) Zero length buffer in safe_tprintf.\n", a1, a2);
v11 = 0LL;
LABEL_5:
v12 = vsnprintf(v7, v11, a5, arg);
v13 = &v7[v10];
v14 = v12;
*v13 = 0;
if ( v12 < 0 )
{
fprintf(stderr, "ERR: (%s:%d) vsnprintf returned error code (%d).\n", a1, a2, (unsigned int)v12);
goto LABEL_12;
}
if ( v9 >= v12 )
{
LABEL_12:
*a4 += v14 + 1;
return v7;
}
if ( !*a4 )
v13 = 0LL;
*a4 = (__int64)v13;
return v7;
}

canonical_decompiled_code:
char *func1(const char *a1, unsigned int a2, char *a3, __int64 *a4, const char *a5, ...)
{
char *v7; // r12
int v9; // er14
int v10; // ebx
size_t v11; // rsi
int v12; // eax
char *v13; // rbx
__int64 v14; // r13
char *v16; // [rsp+10h] [rbp-108h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-100h] BYREF

va_start(arg, a5);
v7 = a3;
if ( !a3 )
{
a4 = (__int64 *)&v16;
v16 = (char *)func0();
v7 = v16;
}
v9 = getBufferSize(v7);
v10 = v9 - 1;
if ( v9 <= 0 )
{
fprintf(stderr, "ERR: (%s:%d) Unknown pool passed to safe_tprintf.\n", a1, a2);
v11 = v9;
if ( v9 >= 0 )
goto LABEL_5;
}
else
{
v9 = v10 - *(_DWORD *)a4 + (_DWORD)v7;
v11 = v9;
if ( v9 >= 0 )
goto LABEL_5;
}
v9 = 0;
fprintf(stderr, "WRN: (%s:%d) Zero length buffer in safe_tprintf.\n", a1, a2);
v11 = 0LL;
LABEL_5:
v12 = vsnprintf(v7, v11, a5, arg);
v13 = &v7[v10];
v14 = v12;
*v13 = 0;
if ( v12 < 0 )
{
fprintf(stderr, "ERR: (%s:%d) vsnprintf returned error code (%d).\n", a1, a2, (unsigned int)v12);
goto LABEL_12;
}
if ( v9 >= v12 )
{
LABEL_12:
*a4 += v14 + 1;
return v7;
}
if ( !*a4 )
v13 = 0LL;
*a4 = (__int64)v13;
return v7;
}

original_code:
char *real_tprintf(char *filename, int lineNo,
     char *buff, char **bp, char *format, ...)
{
  int length, end, ret;
  char *bp2;
  va_list ap;
  __builtin_va_start(ap,format);
  if (buff == ((void *)0)) {
    buff = getTrackedBuffer();
    bp2 = buff;
    bp = &bp2;
  }
  length = getBufferSize(buff);
  end = length - 1;
  if (length > 0) {
    length -= (*bp - buff) + 1;
  } else {
    fprintf(stderr,
     "ERR: (%s:%d) Unknown pool passed to safe_tprintf.\n",
     filename, lineNo);
  }
  if (length < 0) {
    length = 0;
    fprintf(stderr,
     "WRN: (%s:%d) Zero length buffer in safe_tprintf.\n",
     filename, lineNo);
  }
  ret = vsnprintf(buff, length, format, ap);
  __builtin_va_end(ap);
  buff[end] = '\0';
  if (ret < 0) {
     fprintf(stderr,
      "ERR: (%s:%d) vsnprintf returned error code (%d).\n",
      filename, lineNo, ret);
  }
  if (ret <= length) {
     *bp += ret + 1;
  } else {
     for (bp2 = *bp; bp2 != '\0' && bp2 != &buff[end]; bp2++);
     *bp = bp2;
  }
  return buff;
}

canonical_original_code:
char *real_tprintf(char *filename, int lineNo, char *buff, char **bp, char *format, ...)
{
  int length; int end; int ret;
  char *bp2;
  __builtin_va_list ap;
  __builtin_va_start(ap,format);
  if (buff == ((void *)0)) {
    buff = getTrackedBuffer();
    bp2 = buff;
    bp = &bp2;
  }
  length = getBufferSize(buff);
  end = length - 1;
  if (length > 0) {
    length -= (*bp - buff) + 1;
  } else {
    fprintf(stderr,
     "ERR: (%s:%d) Unknown pool passed to safe_tprintf.\n",
     filename, lineNo);
  }
  if (length < 0) {
    length = 0;
    fprintf(stderr,
     "WRN: (%s:%d) Zero length buffer in safe_tprintf.\n",
     filename, lineNo);
  }
  ret = vsnprintf(buff, length, format, ap);
  __builtin_va_end(ap);
  buff[end] = '\0';
  if (ret < 0) {
     fprintf(stderr,
      "ERR: (%s:%d) vsnprintf returned error code (%d).\n",
      filename, lineNo, ret);
  }
  if (ret <= length) {
     *bp += ret + 1;
  } else {
     for (bp2 = *bp; bp2 != '\0' && bp2 != &buff[end]; bp2++);
     *bp = bp2;
  }
  return buff;
}

variable_types:
filename
char *

variable_types: lineNo int

variable_types:
bp
char **

variable_types:
format
char *

variable_types: length int

variable_types: end int

variable_types: ret int


freeTrackedBuffers

decompiled_code:
void freeTrackedBuffers()
{
int v0; // er15
int *v1; // r14
int *i; // r12
int v3; // eax
int *v4; // rbp
int v5; // ebx
int v6; // eax
int v7; // edx

v0 = 0;
v1 = 0LL;
for ( i = (int *)&bufferList; ; v1 = i )
{
v3 = i[20];
v4 = i;
v5 = 0;
if ( v3 > 0 )
{
do
{
pool_free(2LL, v4, 205LL, "tprintf.c");
v6 = i[20];
v7 = v0 + 1 + v5++;
v4 += 2;
}
while ( v6 > v5 );
v3 = v6 - v5;
v0 = v7;
}
i[20] = v3;
if ( v3 )
{
if ( (mudconf[8104] & 8) != 0 && (unsigned int)start_log("ASSERT", "FAIL") )
{
log_text("Assertion failed, raise a bug report: '#x'");
end_log();
}
mudstate[13] = 1;
}
i = (int *)*((_QWORD *)i + 11);
if ( !v1 )
break;
free(v1);
if ( !i )
goto LABEL_12;
LABEL_10:
;
}
qword_4D8 = 0LL;
if ( i )
goto LABEL_10;
LABEL_12:
if ( v0 )
{
++qword_470;
qword_468 += v0;
dword_464 -= v0;
if ( dword_464 )
_assert_fail("bufferStats.current == 0", "tprintf.c", 0xE9u, "freeTrackedBuffers");
}
}

canonical_decompiled_code:
void func2()
{
int v0; // er15
int *v1; // r14
int *i; // r12
int v3; // eax
int *v4; // rbp
int v5; // ebx
int v6; // eax
int v7; // edx

v0 = 0;
v1 = 0LL;
for ( i = (int *)&bufferList; ; v1 = i )
{
v3 = i[20];
v4 = i;
v5 = 0;
if ( v3 > 0 )
{
do
{
pool_free(2LL, v4, 205LL, "tprintf.c");
v6 = i[20];
v7 = v0 + 1 + v5++;
v4 += 2;
}
while ( v6 > v5 );
v3 = v6 - v5;
v0 = v7;
}
i[20] = v3;
if ( v3 )
{
if ( (mudconf[8104] & 8) != 0 && (unsigned int)start_log("ASSERT", "FAIL") )
{
log_text("Assertion failed, raise a bug report: '#x'");
end_log();
}
mudstate[13] = 1;
}
i = (int *)*((_QWORD *)i + 11);
if ( !v1 )
break;
free(v1);
if ( !i )
goto LABEL_12;
LABEL_10:
;
}
qword_4D8 = 0LL;
if ( i )
goto LABEL_10;
LABEL_12:
if ( v0 )
{
++qword_470;
qword_468 += v0;
dword_464 -= v0;
if ( dword_464 )
_assert_fail("bufferStats.current == 0", "tprintf.c", 0xE9u, "freeTrackedBuffers");
}
}

original_code:
void freeTrackedBuffers(void) {
  tprintf_list_t *pList = &bufferList;
  tprintf_list_t *pCurrentList = ((void *)0);
  int nFreed = 0;
  int i;
  while (pList != ((void *)0)) {
    for ( i = 0 ; i < pList->nInUse ; i++) {
      pool_free(2,((char **)&(pList->pBuff[i])),205,"tprintf.c");
      nFreed++;
    }
    pList->nInUse -= i;
    if (! (pList->nInUse == 0) ) { if ((((0x00000008) & mudconf.log_options) != 0) && start_log("ASSERT", "FAIL")) {; log_text("Assertion failed, raise a bug report: '#x'"); end_log(); }; mudstate.panicking = 1; };
    pList = pList->pNext;
    if (pCurrentList != ((void *)0)) {
      free(pCurrentList);
    } else {
      bufferList.pNext = ((void *)0);
    }
    pCurrentList = pList;
  };
  if ( nFreed > 0 ) {
    bufferStats.cummulativeLength += nFreed;
    bufferStats.numberOfCalls++;
    bufferStats.current -= nFreed;
    ((void) sizeof ((bufferStats.current == 0) ? 1 : 0), __extension__ ({ if (bufferStats.current == 0) ; else __assert_fail ("bufferStats.current == 0", "tprintf.c", 233, __extension__ __PRETTY_FUNCTION__); }));
  }
}

canonical_original_code:
void freeTrackedBuffers() {
  struct _tprintf_list *pList = &bufferList;
  struct _tprintf_list *pCurrentList = ((void *)0);
  int nFreed = 0;
  int i;
  while (pList != ((void *)0)) {
    for ( i = 0 ; i < pList->nInUse ; i++) {
      pool_free(2,((char **)&(pList->pBuff[i])),205,"tprintf.c");
      nFreed++;
    }
    pList->nInUse -= i;
    if (! (pList->nInUse == 0) ) { if ((((0x00000008) & mudconf.log_options) != 0) && start_log("ASSERT", "FAIL")) {; log_text("Assertion failed, raise a bug report: '#x'"); end_log(); }; mudstate.panicking = 1; };
    pList = pList->pNext;
    if (pCurrentList != ((void *)0)) {
      free(pCurrentList);
    } else {
      bufferList.pNext = ((void *)0);
    }
    pCurrentList = pList;
  };
  if ( nFreed > 0 ) {
    bufferStats.cummulativeLength += nFreed;
    bufferStats.numberOfCalls++;
    bufferStats.current -= nFreed;
    ((void) sizeof ((bufferStats.current == 0) ? 1 : 0), __extension__ ({ if (bufferStats.current == 0) ; else __assert_fail ("bufferStats.current == 0", "tprintf.c", 233, __extension__ __PRETTY_FUNCTION__); }));
  }
}

variable_types: struct _tprintf_list { char *pBuff[10]; int nInUse; struct _tprintf_list *pNext; } *

variable_types: nFreed int

variable_types: i int


showTrackedBufferStats

decompiled_code:
__int64 __fastcall showTrackedBufferStats(unsigned int a1)
{
__int64 v1; // rax
char *v2; // rax

v1 = (unsigned int)dword_464;
if ( qword_470 > 0 )
v1 = qword_468 / qword_470;
v2 = real_tprintf(
"tprintf.c",
0xFAu,
0LL,
0LL,
"\nTprintf Stats Current Maximum Average\n %-5d %-5d %-5d",
(unsigned int)dword_464,
(unsigned int)bufferStats,
v1);
return notify_check(a1, a1, v2, 0LL, 3085LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 v1; // rax
char *v2; // rax

v1 = (unsigned int)dword_464;
if ( qword_470 > 0 )
v1 = qword_468 / qword_470;
v2 = func1(
"tprintf.c",
0xFAu,
0LL,
0LL,
"\nTprintf Stats Current Maximum Average\n %-5d %-5d %-5d",
(unsigned int)dword_464,
(unsigned int)bufferStats,
v1);
return notify_check(a1, a1, v2, 0LL, 3085LL, 0LL);
}

original_code:
void showTrackedBufferStats(dbref player) {
  char *buff = ((void *)0);
  int avg = 0;
  if (bufferStats.numberOfCalls > 0) {
      avg = bufferStats.cummulativeLength / bufferStats.numberOfCalls;
  } else {
      avg = bufferStats.current;
  }
  buff = real_tprintf("tprintf.c", 250, ((void *)0), ((void *)0), "\nTprintf Stats   Current  Maximum   Average\n" "                %-5d    %-5d     %-5d", bufferStats.current, bufferStats.maxLength, avg);
  notify_check(player,player,buff,0, 1|(2048|8|1024)|(4), 0);
}

canonical_original_code:
void showTrackedBufferStats(int player) {
  char *buff = ((void *)0);
  int avg = 0;
  if (bufferStats.numberOfCalls > 0) {
      avg = bufferStats.cummulativeLength / bufferStats.numberOfCalls;
  } else {
      avg = bufferStats.current;
  }
  buff = real_tprintf("tprintf.c", 250, ((void *)0), ((void *)0), "\nTprintf Stats   Current  Maximum   Average\n" "                %-5d    %-5d     %-5d", bufferStats.current, bufferStats.maxLength, avg);
  notify_check(player,player,buff,0, 1|(2048|8|1024)|(4), 0);
}

variable_types: player int

variable_types:
buff
char *

variable_types: avg int