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

v2 = a2;
if ( cErrorFunction )
cErrorFunction(a2);
if ( File_c )
{
v3 = stderrStream_o;
v4 = (void (__fastcall *)(__int64, const char *))gPuts;
if ( !stderrStream_o )
{
File_initialize();
v3 = stderrStream_o;
}
v4(v3, a2);
}
else
{
if ( (unsigned int)IsObj(a2) )
v2 = (const char *)gStringValue(a2);
fputs(v2, stderr);
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func13(__int64 a1, const char *a2)
{
const char *v2; // rbp
__int64 v3; // rdi
void (__fastcall *v4)(__int64, const char *); // rbx

v2 = a2;
if ( cErrorFunction )
cErrorFunction(a2);
if ( File_c )
{
v3 = stderrStream_o;
v4 = (void (__fastcall *)(__int64, const char *))gPuts;
if ( !stderrStream_o )
{
File_initialize();
v3 = stderrStream_o;
}
v4(v3, a2);
}
else
{
if ( (unsigned int)IsObj(a2) )
v2 = (const char *)gStringValue(a2);
fputs(v2, stderr);
}
exit(1);
}

original_code:
static objrtn Object_im_gError(object self, char *msg)
{
 if (cErrorFunction)
  cErrorFunction(msg);
  if (File_c)
  gPuts((stderrStream_o ? stderrStream_o : (File_initialize(), stderrStream_o)), msg);
 else {
  if (IsObj((object) msg))
   msg = gStringValue((object) msg);
  fprintf(stderr, "%s", msg);
 }
  exit(1);
 return self;
}

canonical_original_code:
static struct _Object_iv_t *Object_im_gError(struct _Object_iv_t *self, char *msg)
{
 if (cErrorFunction)
  cErrorFunction(msg);
  if (File_c)
  gPuts((stderrStream_o ? stderrStream_o : (File_initialize(), stderrStream_o)), msg);
 else {
  if (IsObj((struct _Object_iv_t *) msg))
   msg = gStringValue((struct _Object_iv_t *) msg);
  fprintf(stderr, "%s", msg);
 }
  exit(1);
 return self;
}

variable_types:
msg
char *


repo: blakemcbride/Dynace

original_code:
static int Object_im_gHash(object self)
{
 double t;
 t = .6125423371 * (double)(INT_PTR) self;
 t = t < 0.0 ? -t : t;
 return (int) ((sizeof(int) > 2 ? 320000001.0 : 32001.0) * (t - floor(t)));
}

canonical_original_code:
static int Object_im_gHash(struct _Object_iv_t *self)
{
 double t;
 t = .6125423371 * (double)(unsigned long) self;
 t = t < 0.0 ? -t : t;
 return (int) ((sizeof(int) > 2 ? 320000001.0 : 32001.0) * (t - floor(t)));
}

variable_types: struct _Object_iv_t { struct _Object_iv_t *cls; unsigned short tag; unsigned short siz; unsigned long sn; } *

variable_types: t double

return_type: int


decompiled_code:
__int64 Object_initialize()
{
__int64 result; // rax
__int64 v1; // rdx

result = Object_c;
if ( !done_1 )
{
v1 = *(_QWORD *)Object_c;
done_1 = 1;
gNewMethod(Method_c, "Object_cm_gSetErrorFunction", v1, gSetErrorFunction_g, Object_cm_gSetErrorFunction);
gNewMethod(Method_c, "Object_im_gError", Object_c, gError_g, Object_im_gError);
gNewMethod(Method_c, "Object_ivm_vError", Object_c, vError_g, Object_ivm_vError);
gNewMethod(
Method_c,
"Object_im_gSubclassResponsibility",
Object_c,
gSubclassResponsibility_g,
Object_im_gSubclassResponsibility);
gNewMethod(
Method_c,
"Object_im_gShouldNotImplement",
Object_c,
gShouldNotImplement_g,
Object_im_gShouldNotImplement);
gNewMethod(Method_c, "Object_im_gHash", Object_c, gHash_g, Object_im_gHash);
gNewMethod(Method_c, "Object_im_gCompare", Object_c, gCompare_g, Object_im_gCompare);
gNewMethod(Method_c, "Object_im_gIsKindOf", Object_c, gIsKindOf_g, Object_im_gIsKindOf);
gNewMethod(Method_c, "Object_im_gInit", Object_c, gInit_g, Object_im_gInit);
gNewMethod(
Method_c,
"Object_im_gObjectSerialNumber",
Object_c,
gObjectSerialNumber_g,
Object_im_gObjectSerialNumber);
gNewMethod(Method_c, "Object_im_gStringRep", Object_c, gStringRep_g, Object_im_gStringRep);
gNewMethod(Method_c, "Object_im_gStringRepValue", Object_c, gStringRepValue_g, Object_im_gStringRepValue);
gNewMethod(Method_c, "Object_im_gPrint", Object_c, gPrint_g, Object_im_gPrint);
gNewMethod(Method_c, "Object_im_gPrintValue", Object_c, gPrintValue_g, Object_im_gPrintValue);
result = Object_c;
}
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax
__int64 v1; // rdx

result = Object_c;
if ( !done_1 )
{
v1 = *(_QWORD *)Object_c;
done_1 = 1;
gNewMethod(Method_c, "Object_cm_gSetErrorFunction", v1, gSetErrorFunction_g, Object_cm_gSetErrorFunction);
gNewMethod(Method_c, "Object_im_gError", Object_c, gError_g, Object_im_gError);
gNewMethod(Method_c, "Object_ivm_vError", Object_c, vError_g, Object_ivm_vError);
gNewMethod(
Method_c,
"Object_im_gSubclassResponsibility",
Object_c,
gSubclassResponsibility_g,
Object_im_gSubclassResponsibility);
gNewMethod(
Method_c,
"Object_im_gShouldNotImplement",
Object_c,
gShouldNotImplement_g,
Object_im_gShouldNotImplement);
gNewMethod(Method_c, "Object_im_gHash", Object_c, gHash_g, Object_im_gHash);
gNewMethod(Method_c, "Object_im_gCompare", Object_c, gCompare_g, Object_im_gCompare);
gNewMethod(Method_c, "Object_im_gIsKindOf", Object_c, gIsKindOf_g, Object_im_gIsKindOf);
gNewMethod(Method_c, "Object_im_gInit", Object_c, gInit_g, Object_im_gInit);
gNewMethod(
Method_c,
"Object_im_gObjectSerialNumber",
Object_c,
gObjectSerialNumber_g,
Object_im_gObjectSerialNumber);
gNewMethod(Method_c, "Object_im_gStringRep", Object_c, gStringRep_g, Object_im_gStringRep);
gNewMethod(Method_c, "Object_im_gStringRepValue", Object_c, gStringRepValue_g, Object_im_gStringRepValue);
gNewMethod(Method_c, "Object_im_gPrint", Object_c, gPrint_g, Object_im_gPrint);
gNewMethod(Method_c, "Object_im_gPrintValue", Object_c, gPrintValue_g, Object_im_gPrintValue);
result = Object_c;
}
return result;
}

original_code:
objrtn Object_initialize(void)
{
 static int done = 0;
 if (done)
  return Object_c;
 done = 1;
 gNewMethod(Method_c, "Object_cm_gSetErrorFunction", (object) *((object *) (Object_c)), gSetErrorFunction_g, (ofun) Object_cm_gSetErrorFunction, (ofun) Object_cm_gSetErrorFunction);
 gNewMethod(Method_c, "Object_im_gError", Object_c, gError_g, (ofun) Object_im_gError, (ofun) Object_im_gError);
 gNewMethod(Method_c, "Object_ivm_vError", Object_c, vError_g, (ofun) Object_ivm_vError, (ofun) Object_ifm_vError);
 gNewMethod(Method_c, "Object_im_gSubclassResponsibility", Object_c, gSubclassResponsibility_g, (ofun) Object_im_gSubclassResponsibility, (ofun) Object_im_gSubclassResponsibility);
 gNewMethod(Method_c, "Object_im_gShouldNotImplement", Object_c, gShouldNotImplement_g, (ofun) Object_im_gShouldNotImplement, (ofun) Object_im_gShouldNotImplement);
 gNewMethod(Method_c, "Object_im_gHash", Object_c, gHash_g, (ofun) Object_im_gHash, (ofun) Object_im_gHash);
 gNewMethod(Method_c, "Object_im_gCompare", Object_c, gCompare_g, (ofun) Object_im_gCompare, (ofun) Object_im_gCompare);
 gNewMethod(Method_c, "Object_im_gIsKindOf", Object_c, gIsKindOf_g, (ofun) Object_im_gIsKindOf, (ofun) Object_im_gIsKindOf);
 gNewMethod(Method_c, "Object_im_gInit", Object_c, gInit_g, (ofun) Object_im_gInit, (ofun) Object_im_gInit);
 gNewMethod(Method_c, "Object_im_gObjectSerialNumber", Object_c, gObjectSerialNumber_g, (ofun) Object_im_gObjectSerialNumber, (ofun) Object_im_gObjectSerialNumber);
 gNewMethod(Method_c, "Object_im_gStringRep", Object_c, gStringRep_g, (ofun) Object_im_gStringRep, (ofun) Object_im_gStringRep);
 gNewMethod(Method_c, "Object_im_gStringRepValue", Object_c, gStringRepValue_g, (ofun) Object_im_gStringRepValue, (ofun) Object_im_gStringRepValue);
 gNewMethod(Method_c, "Object_im_gPrint", Object_c, gPrint_g, (ofun) Object_im_gPrint, (ofun) Object_im_gPrint);
 gNewMethod(Method_c, "Object_im_gPrintValue", Object_c, gPrintValue_g, (ofun) Object_im_gPrintValue, (ofun) Object_im_gPrintValue);
 return Object_c;
}

canonical_original_code:
struct _Object_iv_t *Object_initialize()
{
 static int done = 0;
 if (done)
  return Object_c;
 done = 1;
 gNewMethod(Method_c, "Object_cm_gSetErrorFunction", (object) *((struct _Object_iv_t **) (Object_c)), gSetErrorFunction_g, (struct _Object_iv_t *(*)()) Object_cm_gSetErrorFunction, (struct _Object_iv_t *(*)()) Object_cm_gSetErrorFunction);
 gNewMethod(Method_c, "Object_im_gError", Object_c, gError_g, (struct _Object_iv_t *(*)()) Object_im_gError, (struct _Object_iv_t *(*)()) Object_im_gError);
 gNewMethod(Method_c, "Object_ivm_vError", Object_c, vError_g, (struct _Object_iv_t *(*)()) Object_ivm_vError, (struct _Object_iv_t *(*)()) Object_ifm_vError);
 gNewMethod(Method_c, "Object_im_gSubclassResponsibility", Object_c, gSubclassResponsibility_g, (struct _Object_iv_t *(*)()) Object_im_gSubclassResponsibility, (struct _Object_iv_t *(*)()) Object_im_gSubclassResponsibility);
 gNewMethod(Method_c, "Object_im_gShouldNotImplement", Object_c, gShouldNotImplement_g, (struct _Object_iv_t *(*)()) Object_im_gShouldNotImplement, (struct _Object_iv_t *(*)()) Object_im_gShouldNotImplement);
 gNewMethod(Method_c, "Object_im_gHash", Object_c, gHash_g, (struct _Object_iv_t *(*)()) Object_im_gHash, (struct _Object_iv_t *(*)()) Object_im_gHash);
 gNewMethod(Method_c, "Object_im_gCompare", Object_c, gCompare_g, (struct _Object_iv_t *(*)()) Object_im_gCompare, (struct _Object_iv_t *(*)()) Object_im_gCompare);
 gNewMethod(Method_c, "Object_im_gIsKindOf", Object_c, gIsKindOf_g, (struct _Object_iv_t *(*)()) Object_im_gIsKindOf, (struct _Object_iv_t *(*)()) Object_im_gIsKindOf);
 gNewMethod(Method_c, "Object_im_gInit", Object_c, gInit_g, (struct _Object_iv_t *(*)()) Object_im_gInit, (struct _Object_iv_t *(*)()) Object_im_gInit);
 gNewMethod(Method_c, "Object_im_gObjectSerialNumber", Object_c, gObjectSerialNumber_g, (struct _Object_iv_t *(*)()) Object_im_gObjectSerialNumber, (struct _Object_iv_t *(*)()) Object_im_gObjectSerialNumber);
 gNewMethod(Method_c, "Object_im_gStringRep", Object_c, gStringRep_g, (struct _Object_iv_t *(*)()) Object_im_gStringRep, (struct _Object_iv_t *(*)()) Object_im_gStringRep);
 gNewMethod(Method_c, "Object_im_gStringRepValue", Object_c, gStringRepValue_g, (struct _Object_iv_t *(*)()) Object_im_gStringRepValue, (struct _Object_iv_t *(*)()) Object_im_gStringRepValue);
 gNewMethod(Method_c, "Object_im_gPrint", Object_c, gPrint_g, (struct _Object_iv_t *(*)()) Object_im_gPrint, (struct _Object_iv_t *(*)()) Object_im_gPrint);
 gNewMethod(Method_c, "Object_im_gPrintValue", Object_c, gPrintValue_g, (struct _Object_iv_t *(*)()) Object_im_gPrintValue, (struct _Object_iv_t *(*)()) Object_im_gPrintValue);
 return Object_c;
}

variable_types: done int

return_type: struct _Object_iv_t { struct _Object_iv_t *cls; unsigned short tag; unsigned short siz; unsigned long sn; } *


original_code:
void MA_free(void *arg)
{
 int i;
 Header *h = (Header *) arg;
 (void) CS;
 if (!h || (--h)->status != 'U') {
  (void) CS;
  return;
 }
 for (i=1 ; Map[i].userBytes && Map[i].userBytes <= h->size ; ++i);
 i--;
 h->status = 'F';
 if (h->next)
  *((char **) h->next) = ((void *)0);
 h->next = Map[i].h;
 Map[i].h = h;
 (void) CS;
}

canonical_original_code:
void MA_free(void *arg)
{
 int i;
 struct _header *h = (Header *) arg;
 (void) CS;
 if (!h || (--h)->status != 'U') {
  (void) CS;
  return;
 }
 for (i=1 ; Map[i].userBytes && Map[i].userBytes <= h->size ; ++i);
 i--;
 h->status = 'F';
 if (h->next)
  *((char **) h->next) = ((void *)0);
 h->next = Map[i].h;
 Map[i].h = h;
 (void) CS;
}

variable_types:
arg
void *

variable_types: i int

variable_types: struct _header { char status; struct _header *next; unsigned int rsize; unsigned int size; } *

return_type: void


original_code:
static void more_core(unsigned n)
{
 unsigned sz;
 unsigned as;
 MemBlk *mb;
 Header *h;
 sz = n > DBS ? n : DBS;
 sz = (((sz-1) / sizeof(Header)) + 1) * sizeof(Header);;
 as = sizeof(MemBlk) + sizeof(Header) + sz;
 mb = (MemBlk *) malloc(as);
 if (!mb) {
  fprintf(stderr, "\nOut of memory.\n");
  exit(1);
 }
 mb->next = MMBP;
 MMBP = mb;
 mb->size = sz + sizeof(Header);
 h = (Header *) (mb+1);
 h->status = 'U';
 h->next = ((void *)0);
 h->size = sz;
 MA_free(h+1);
}

canonical_original_code:
static void more_core(unsigned int n)
{
 unsigned int sz;
 unsigned int as;
 struct _memBlk *mb;
 struct _header *h;
 sz = n > DBS ? n : DBS;
 sz = (((sz-1) / sizeof(Header)) + 1) * sizeof(Header);;
 as = sizeof(MemBlk) + sizeof(Header) + sz;
 mb = (struct _memBlk *) malloc(as);
 if (!mb) {
  fprintf(stderr, "\nOut of memory.\n");
  exit(1);
 }
 mb->next = MMBP;
 MMBP = mb;
 mb->size = sz + sizeof(Header);
 h = (struct _header *) (mb+1);
 h->status = 'U';
 h->next = ((void *)0);
 h->size = sz;
 MA_free(h+1);
}

variable_types:
n
unsigned int

variable_types:
sz
unsigned int

variable_types:
as
unsigned int

variable_types: struct _memBlk { struct _memBlk *next; unsigned int size; } *

user_defined_types: struct _header { char status; struct _header *next; unsigned int rsize; unsigned int size; }


original_code:
void *MA_malloc(unsigned n, void *p)
{
 unsigned sz;
 int i;
 Header *h;
 Header *ph;
 Header *bh;
 Header *pbh;
 unsigned tnb;
 unsigned nbn;
 unsigned nbl;
 if (!CS_init) {
  (void) CS;
  CS_init = 1;
 }
 (void) CS;
 if (!n)
  ++n;
 sz = (((n-1) / sizeof(Header)) + 1) * sizeof(Header);;
 for (i=1 ; Map[i].userBytes && Map[i].userBytes <= sz ; ++i);
 i--;
 for (bh=pbh=ph=((void *)0), h=Map[i].h ; h ; ph=h, h=h->next)
  if (h->size == sz) {
  if (ph)
   ph->next = h->next;
  else
   Map[i].h = h->next;
  h->status = 'U';
  h->next = (Header *) p;
  h->rsize = n;
  (void) CS;
  return h+1;
 } else if (h->size > sz && (!bh || bh->size > h->size)) {
  pbh = ph;
  bh = h;
 }
 if (bh) {
  if (pbh)
   pbh->next = bh->next;
  else
   Map[i].h = bh->next;
  bh->status = 'U';
  bh->next = (Header *) p;
  bh->rsize = n;
  (void) CS;
  return bh+1;
 }
 for (i++ ; Map[i].userBytes && !Map[i].h ; ++i);
 if (!Map[i].userBytes) {
  more_core(n);
  (void) CS;
  return MA_malloc(n, p);
 }
 h = Map[i].h;
 Map[i].h = h->next;
 tnb = h->size / sizeof(Header);
 nbn = sz / sizeof(Header);
 nbl = tnb - nbn;
 if (nbl > 5) {
  bh = h + (nbn + 1);
  bh->status = 'U';
  bh->next = ((void *)0);
  bh->rsize = bh->size = (nbl - 1) * sizeof(Header);
  h->size -= nbl * sizeof(Header);
  MA_free(bh+1);
 }
 h->status = 'U';
 h->next = (Header *) p;
 h->rsize = n;
 (void) CS;
 return h+1;
}

canonical_original_code:
void *MA_malloc(unsigned int n, void *p)
{
 unsigned int sz;
 int i;
 struct _header *h;
 struct _header *ph;
 struct _header *bh;
 struct _header *pbh;
 unsigned int tnb;
 unsigned int nbn;
 unsigned int nbl;
 if (!CS_init) {
  (void) CS;
  CS_init = 1;
 }
 (void) CS;
 if (!n)
  ++n;
 sz = (((n-1) / sizeof(Header)) + 1) * sizeof(Header);;
 for (i=1 ; Map[i].userBytes && Map[i].userBytes <= sz ; ++i);
 i--;
 for (bh=pbh=ph=((void *)0), h=Map[i].h ; h ; ph=h, h=h->next)
  if (h->size == sz) {
  if (ph)
   ph->next = h->next;
  else
   Map[i].h = h->next;
  h->status = 'U';
  h->next = (struct _header *) p;
  h->rsize = n;
  (void) CS;
  return h+1;
 } else if (h->size > sz && (!bh || bh->size > h->size)) {
  pbh = ph;
  bh = h;
 }
 if (bh) {
  if (pbh)
   pbh->next = bh->next;
  else
   Map[i].h = bh->next;
  bh->status = 'U';
  bh->next = (struct _header *) p;
  bh->rsize = n;
  (void) CS;
  return bh+1;
 }
 for (i++ ; Map[i].userBytes && !Map[i].h ; ++i);
 if (!Map[i].userBytes) {
  more_core(n);
  (void) CS;
  return MA_malloc(n, p);
 }
 h = Map[i].h;
 Map[i].h = h->next;
 tnb = h->size / sizeof(Header);
 nbn = sz / sizeof(Header);
 nbl = tnb - nbn;
 if (nbl > 5) {
  bh = h + (nbn + 1);
  bh->status = 'U';
  bh->next = ((void *)0);
  bh->rsize = bh->size = (nbl - 1) * sizeof(Header);
  h->size -= nbl * sizeof(Header);
  MA_free(bh+1);
 }
 h->status = 'U';
 h->next = (struct _header *) p;
 h->rsize = n;
 (void) CS;
 return h+1;
}

variable_types:
p
void *

variable_types:
tnb
unsigned int

variable_types:
nbn
unsigned int

variable_types:
nbl
unsigned int

return_type: void *


decompiled_code:
void *__fastcall MA_calloc(size_t n, __int64 a2)
{
void *v2; // rax

v2 = (void *)MA_malloc(n, a2);
return memset(v2, 0, (unsigned int)n);
}

canonical_decompiled_code:
void *__fastcall func3(size_t n, __int64 a2)
{
void *v2; // rax

v2 = (void *)func2(n, a2);
return memset(v2, 0, (unsigned int)n);
}

original_code:
void *MA_calloc(unsigned n, void *p)
{
 p = MA_malloc(n, p);
 memset(p, 0, n);
 return p;
}

canonical_original_code:
void *MA_calloc(unsigned int n, void *p)
{
 p = MA_malloc(n, p);
 memset(p, 0, n);
 return p;
}


decompiled_code:
void *__fastcall MA_realloc(void *src, unsigned int a2)
{
__int64 v2; // r12
void *v4; // r12

v2 = 0LL;
if ( !src || *((char *)src - 24) != 85 )
return (void *)v2;
if ( *((_DWORD *)src - 1) >= a2 )
{
*((_DWORD *)src - 2) = a2;
return src;
}
v4 = (void *)MA_malloc(a2, *((_QWORD *)src - 2));
memcpy(v4, src, *((unsigned int *)src - 2));
*((_QWORD *)src - 2) = 0LL;
MA_free((__int64)src);
return v4;
}

canonical_decompiled_code:
void *__fastcall func4(void *src, unsigned int a2)
{
__int64 v2; // r12
void *v4; // r12

v2 = 0LL;
if ( !src || *((char *)src - 24) != 85 )
return (void *)v2;
if ( *((_DWORD *)src - 1) >= a2 )
{
*((_DWORD *)src - 2) = a2;
return src;
}
v4 = (void *)func2(a2, *((_QWORD *)src - 2));
memcpy(v4, src, *((unsigned int *)src - 2));
*((_QWORD *)src - 2) = 0LL;
func0((__int64)src);
return v4;
}

original_code:
void *MA_realloc(void *arg, unsigned n)
{
 char *m;
 Header *h = (Header *) arg;
 (void) CS;
 if (!h || (--h)->status != 'U') {
  (void) CS;
  return ((void *)0);
 }
 if (h->size >= n) {
  h->rsize = n;
  (void) CS;
  return h+1;
 }
 m = (char *) MA_malloc(n, h->next);
 memcpy(m, h+1, h->rsize);
 h->next = ((void *)0);
 MA_free(h+1);
 (void) CS;
 return m;
}

canonical_original_code:
void *MA_realloc(void *arg, unsigned int n)
{
 char *m;
 struct _header *h = (Header *) arg;
 (void) CS;
 if (!h || (--h)->status != 'U') {
  (void) CS;
  return ((void *)0);
 }
 if (h->size >= n) {
  h->rsize = n;
  (void) CS;
  return h+1;
 }
 m = (char *) MA_malloc(n, h->next);
 memcpy(m, h+1, h->rsize);
 h->next = ((void *)0);
 MA_free(h+1);
 (void) CS;
 return m;
}

variable_types:
m
char *


original_code:
void MA_compact(void)
{
 MemBlk *mb;
 Header *fh, *mfh = ((void *)0);
 int i;
 (void) CS;
 for (mb=MMBP ; mb ; mb = mb->next) {
  fh = compact(mb);
  if (fh) {
   fh->next = mfh;
   mfh = fh;
  }
 }
 for (i=0 ; Map[i].userBytes ; ++i)
  Map[i].h = ((void *)0);
 while (fh = mfh) {
  mfh = fh->next;
  fh->status = 'U';
  fh->next = ((void *)0);
  MA_free(fh+1);
 }
 (void) CS;
}

canonical_original_code:
void MA_compact()
{
 struct _memBlk *mb;
 struct _header *fh; struct _header *mfh = ((void *)0);
 int i;
 (void) CS;
 for (mb=MMBP ; mb ; mb = mb->next) {
  fh = compact(mb);
  if (fh) {
   fh->next = mfh;
   mfh = fh;
  }
 }
 for (i=0 ; Map[i].userBytes ; ++i)
  Map[i].h = ((void *)0);
 while (fh = mfh) {
  mfh = fh->next;
  fh->status = 'U';
  fh->next = ((void *)0);
  MA_free(fh+1);
 }
 (void) CS;
}

user_defined_types: struct _memBlk { struct _memBlk *next; unsigned int size; }


decompiled_code:
// attributes: thunk
__int64 Dynace_GetInitialPageSize()
{
return Dynace_GetPageSize();
}

canonical_decompiled_code:
__int64 func0()
{
return Dynace_GetPageSize();
}

original_code:
long Dynace_GetInitialPageSize()
{
 return Dynace_GetPageSize();
}

return_type: long


decompiled_code:
void catch_timer()
{
if ( tick_count )
--tick_count;
signal(27, catch_timer);
}

canonical_decompiled_code:
void func0()
{
if ( tick_count )
--tick_count;
signal(27, catch_timer);
}

original_code:
static void catch_timer(int sig)
{
 (void) sig;
 if (_tick_count)
  _tick_count--;
 signal(27, catch_timer);
}

variable_types: sig int


repo: blanciq/bq-killer

decompiled_code:
__m128i *new_todelete()
{
__m128i *result; // rax
__m128i v1; // xmm1

result = (__m128i *)todelete_free;
if ( todelete_free )
{
todelete_free = *(_QWORD *)todelete_free;
}
else
{
result = (__m128i *)calloc(1uLL, 0x20uLL);
if ( !result )
{
bugf("Malloc failure @ %s:%d\n", "todelete.c", 27LL);
abort();
}
}
v1 = _mm_load_si128((const __m128i *)&xmmword_EB0);
*result = _mm_load_si128((const __m128i *)&todelete_zero_0);
result[1] = v1;
result->m128i_i64[1] = (__int64)&str_empty;
result[1].m128i_i8[8] = 1;
return result;
}

canonical_decompiled_code:
__m128i *func0()
{
__m128i *result; // rax
__m128i v1; // xmm1

result = (__m128i *)todelete_free;
if ( todelete_free )
{
todelete_free = *(_QWORD *)todelete_free;
}
else
{
result = (__m128i *)calloc(1uLL, 0x20uLL);
if ( !result )
{
bugf("Malloc failure @ %s:%d\n", "todelete.c", 27LL);
abort();
}
}
v1 = _mm_load_si128((const __m128i *)&xmmword_EB0);
*result = _mm_load_si128((const __m128i *)&todelete_zero_0);
result[1] = v1;
result->m128i_i64[1] = (__int64)&str_empty;
result[1].m128i_i8[8] = 1;
return result;
}

original_code:
TODELETE_DATA *new_todelete( void )
{
    static TODELETE_DATA todelete_zero;
    TODELETE_DATA *todelete;
    if ( todelete_free == ((void *)0) )
    {
        do { if (!((todelete) = (TODELETE_DATA *) calloc ((1), sizeof(TODELETE_DATA)))) { bugf( "Malloc failure @ %s:%d\n", "todelete.c", 27 ); abort(); } } while(0);
    }
    else
    {
 todelete = todelete_free;
 todelete_free = todelete_free->next;
    }
    *todelete = todelete_zero;
    ((todelete)->valid = 1);
    todelete->name = &str_empty[ 0 ];
    todelete->timestamp = 0;
    todelete->next = ((void *)0);
    return todelete;
}

canonical_original_code:
struct todelete_data *new_todelete()
{
    static struct todelete_data todelete_zero;
    struct todelete_data *todelete;
    if ( todelete_free == ((void *)0) )
    {
        do { if (!((todelete) = (struct todelete_data *) calloc ((1), sizeof(TODELETE_DATA)))) { bugf( "Malloc failure @ %s:%d\n", "todelete.c", 27 ); abort(); } } while(0);
    }
    else
    {
 todelete = todelete_free;
 todelete_free = todelete_free->next;
    }
    *todelete = todelete_zero;
    ((todelete)->valid = 1);
    todelete->name = &str_empty[ 0 ];
    todelete->timestamp = 0;
    todelete->next = ((void *)0);
    return todelete;
}

variable_types: struct todelete_data { struct todelete_data *next; char *name; long timestamp; unsigned char valid; } *


decompiled_code:
__int64 __fastcall free_todelete(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax

if ( a1 && *(_BYTE *)(a1 + 24) )
{
v2 = *(void **)(a1 + 8);
if ( v2 != &str_empty )
{
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 8) = 0LL;
}
}
result = todelete_free;
*(_BYTE *)(a1 + 24) = 0;
*(_QWORD *)a1 = result;
todelete_free = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax

if ( a1 && *(_BYTE *)(a1 + 24) )
{
v2 = *(void **)(a1 + 8);
if ( v2 != &str_empty )
{
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 8) = 0LL;
}
}
result = todelete_free;
*(_BYTE *)(a1 + 24) = 0;
*(_QWORD *)a1 = result;
todelete_free = a1;
}
return result;
}

original_code:
void free_todelete( TODELETE_DATA *todelete )
{
    if ( !(((todelete) != ((void *)0)) && ((todelete)->valid)) )
    {
 return;
    }
    if ( (todelete->name) != &str_empty[0] ) do { if((todelete->name)) { free((todelete->name)); (todelete->name) = ((void *)0); } } while(0);
    ((todelete)->valid = 0);
    todelete->next = todelete_free;
    todelete_free = todelete;
    return;
}

canonical_original_code:
void free_todelete(struct todelete_data *todelete)
{
    if ( !(((todelete) != ((void *)0)) && ((todelete)->valid)) )
    {
 return;
    }
    if ( (todelete->name) != &str_empty[0] ) do { if((todelete->name)) { free((todelete->name)); (todelete->name) = ((void *)0); } } while(0);
    ((todelete)->valid = 0);
    todelete->next = todelete_free;
    todelete_free = todelete;
    return;
}

user_defined_types: struct todelete_data { struct todelete_data *next; char *name; long timestamp; unsigned char valid; }


decompiled_code:
__int64 __fastcall find_todelete(char *s1)
{
__int64 i; // r12

for ( i = todelete_list; i; i = *(_QWORD *)i )
{
if ( !strcmp(s1, *(const char **)(i + 8)) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
__int64 i; // r12

for ( i = todelete_list; i; i = *(_QWORD *)i )
{
if ( !strcmp(s1, *(const char **)(i + 8)) )
break;
}
return i;
}

original_code:
TODELETE_DATA *find_todelete( char *name )
{
    TODELETE_DATA *todelete = ((void *)0);
    for ( todelete = todelete_list; todelete; todelete = todelete->next )
    {
 if ( !strcmp( name, todelete->name ) )
 {
     break;
 }
    }
    return todelete;
}

canonical_original_code:
struct todelete_data *find_todelete(char *name)
{
    struct todelete_data *todelete = ((void *)0);
    for ( todelete = todelete_list; todelete; todelete = todelete->next )
    {
 if ( !strcmp( name, todelete->name ) )
 {
     break;
 }
    }
    return todelete;
}

variable_types:
name
char *

return_type: struct todelete_data { struct todelete_data *next; char *name; long timestamp; unsigned char valid; } *


decompiled_code:
void __fastcall remove_todelete(char *s1)
{
__int64 v1; // r12
_QWORD *v2; // r13
int v3; // er8
__int64 v4; // rax

v1 = todelete_list;
if ( todelete_list )
{
v2 = 0LL;
while ( 1 )
{
v3 = strcmp(s1, *(const char **)(v1 + 8));
v4 = *(_QWORD *)v1;
if ( !v3 )
break;
v2 = (_QWORD *)v1;
if ( !v4 )
return;
v1 = *(_QWORD *)v1;
}
if ( v2 )
*v2 = v4;
else
todelete_list = *(_QWORD *)v1;
free_todelete(v1);
}
}

canonical_decompiled_code:
void __fastcall func5(char *s1)
{
__int64 v1; // r12
_QWORD *v2; // r13
int v3; // er8
__int64 v4; // rax

v1 = todelete_list;
if ( todelete_list )
{
v2 = 0LL;
while ( 1 )
{
v3 = strcmp(s1, *(const char **)(v1 + 8));
v4 = *(_QWORD *)v1;
if ( !v3 )
break;
v2 = (_QWORD *)v1;
if ( !v4 )
return;
v1 = *(_QWORD *)v1;
}
if ( v2 )
*v2 = v4;
else
todelete_list = *(_QWORD *)v1;
func1(v1);
}
}

original_code:
void remove_todelete( char *name )
{
    TODELETE_DATA *todelete = ((void *)0);
    TODELETE_DATA *prev_todelete = ((void *)0);
    for ( todelete = todelete_list; todelete; todelete = todelete->next )
    {
 if ( !strcmp( name, todelete->name ) )
 {
     if ( prev_todelete )
     {
  prev_todelete->next = todelete->next;
     }
     else
     {
  todelete_list = todelete->next;
     }
     free_todelete( todelete );
     break;
 }
 prev_todelete = todelete;
    }
    return;
}

canonical_original_code:
void remove_todelete(char *name)
{
    struct todelete_data *todelete = ((void *)0);
    struct todelete_data *prev_todelete = ((void *)0);
    for ( todelete = todelete_list; todelete; todelete = todelete->next )
    {
 if ( !strcmp( name, todelete->name ) )
 {
     if ( prev_todelete )
     {
  prev_todelete->next = todelete->next;
     }
     else
     {
  todelete_list = todelete->next;
     }
     free_todelete( todelete );
     break;
 }
 prev_todelete = todelete;
    }
    return;
}


decompiled_code:
__int64 __fastcall time_diff(time_t a1, time_t a2, char a3)
{
__int64 v4; // r8
__int64 v5; // rdi
__int64 result; // rax

v4 = (unsigned int)(int)difftime(a1, a2);
v5 = (__int64)((unsigned __int128)(0x48D159E26AF37C05LL * (__int128)(v4 % 86400)) >> 64) >> 10;
result = (unsigned int)((v4 % 86400 - 3600 * (int)v5) / 60);
if ( a3 == 104 )
return (unsigned int)v5;
if ( a3 <= 104 )
{
result = (unsigned int)v4;
if ( a3 != 32 )
{
result = 0xFFFFFFFFLL;
if ( a3 == 100 )
result = (unsigned int)(v4 / 86400);
}
}
else if ( a3 != 109 )
{
if ( a3 == 115 )
result = (unsigned int)((v4 % 86400 - 3600 * (int)v5) % 60);
else
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(time_t a1, time_t a2, char a3)
{
__int64 v4; // r8
__int64 v5; // rdi
__int64 result; // rax

v4 = (unsigned int)(int)difftime(a1, a2);
v5 = (__int64)((unsigned __int128)(0x48D159E26AF37C05LL * (__int128)(v4 % 86400)) >> 64) >> 10;
result = (unsigned int)((v4 % 86400 - 3600 * (int)v5) / 60);
if ( a3 == 104 )
return (unsigned int)v5;
if ( a3 <= 104 )
{
result = (unsigned int)v4;
if ( a3 != 32 )
{
result = 0xFFFFFFFFLL;
if ( a3 == 100 )
result = (unsigned int)(v4 / 86400);
}
}
else if ( a3 != 109 )
{
if ( a3 == 115 )
result = (unsigned int)((v4 % 86400 - 3600 * (int)v5) % 60);
else
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int time_diff( time_t time1, time_t time2, char format )
{
    long diff = difftime( time1, time2 );
    long days = diff / 86400;
    int hours = ( diff - ( days * 86400 ) ) / 3600;
    int minutes = ( diff - ( days * 86400 ) - ( hours * 3600 ) ) / 60;
    int seconds = ( diff - ( days * 86400 ) - ( hours * 3600 ) - ( minutes * 60 ) );
    switch ( format )
    {
 case 's': return seconds; break;
 case 'm': return minutes; break;
 case 'h': return hours; break;
 case 'd': return days; break;
 case ' ': return diff; break;
 default: return -1; break;
    }
    return -1;
}

canonical_original_code:
int time_diff(long time1, long time2, char format)
{
    long diff = difftime( time1, time2 );
    long days = diff / 86400;
    int hours = ( diff - ( days * 86400 ) ) / 3600;
    int minutes = ( diff - ( days * 86400 ) - ( hours * 3600 ) ) / 60;
    int seconds = ( diff - ( days * 86400 ) - ( hours * 3600 ) - ( minutes * 60 ) );
    switch ( format )
    {
 case 's': return seconds; break;
 case 'm': return minutes; break;
 case 'h': return hours; break;
 case 'd': return days; break;
 case ' ': return diff; break;
 default: return -1; break;
    }
    return -1;
}

variable_types: format char

variable_types: diff long

variable_types: days long

variable_types: hours int

variable_types: minutes int

variable_types: seconds int


decompiled_code:
__int64 __fastcall todelete_time(char *a1, char a2)
{
__int64 v2; // rax
time_t v3; // r13
time_t v4; // r12
__int64 v5; // r14
unsigned int v6; // er15
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v10; // [rsp+Ch] [rbp-2034h]
char s[8240]; // [rsp+10h] [rbp-2030h] BYREF

v2 = find_todelete(a1);
v3 = current_time;
v4 = *(_QWORD *)(v2 + 16);
v5 = (int)time_diff(v4, current_time, 100);
v6 = time_diff(v4, v3, 104);
v7 = time_diff(v4, v3, 109);
if ( a2 == 104 )
{
sprintf(s, "%ldd %dh", v5, v6);
}
else if ( a2 == 109 )
{
sprintf(s, "%ldd %dh %dm", v5, v6, v7);
}
else
{
v10 = v7;
if ( a2 == 100 )
{
sprintf(s, "%ldd", v5);
}
else
{
v8 = time_diff(v4, v3, 115);
sprintf(s, "%ldd %dh %dm %ds", v5, v6, v10, v8);
}
}
return str_dup(s);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char a2)
{
__int64 v2; // rax
time_t v3; // r13
time_t v4; // r12
__int64 v5; // r14
unsigned int v6; // er15
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v10; // [rsp+Ch] [rbp-2034h]
char s[8240]; // [rsp+10h] [rbp-2030h] BYREF

v2 = func2(a1);
v3 = current_time;
v4 = *(_QWORD *)(v2 + 16);
v5 = (int)func7(v4, current_time, 100);
v6 = func7(v4, v3, 104);
v7 = func7(v4, v3, 109);
if ( a2 == 104 )
{
sprintf(s, "%ldd %dh", v5, v6);
}
else if ( a2 == 109 )
{
sprintf(s, "%ldd %dh %dm", v5, v6, v7);
}
else
{
v10 = v7;
if ( a2 == 100 )
{
sprintf(s, "%ldd", v5);
}
else
{
v8 = func7(v4, v3, 115);
sprintf(s, "%ldd %dh %dm %ds", v5, v6, v10, v8);
}
}
return str_dup(s);
}

original_code:
char *todelete_time( char *name, char format )
{
    TODELETE_DATA *todelete = find_todelete( name );
    long days = time_diff( todelete->timestamp, current_time, 'd' );
    int hours = time_diff( todelete->timestamp, current_time, 'h' );
    int minutes = time_diff( todelete->timestamp, current_time, 'm' );
    int seconds = time_diff( todelete->timestamp, current_time, 's' );
    char buf[8192];
    switch ( format )
    {
 default:
 case 's': sprintf( buf, "%ldd %dh %dm %ds", days, hours, minutes, seconds ); break;
 case 'm': sprintf( buf, "%ldd %dh %dm", days, hours, minutes ); break;
 case 'h': sprintf( buf, "%ldd %dh", days, hours ); break;
 case 'd': sprintf( buf, "%ldd", days ); break;
    }
    return str_dup( buf );
}

canonical_original_code:
char *todelete_time(char *name, char format)
{
    struct todelete_data *todelete = find_todelete( name );
    long days = time_diff( todelete->timestamp, current_time, 'd' );
    int hours = time_diff( todelete->timestamp, current_time, 'h' );
    int minutes = time_diff( todelete->timestamp, current_time, 'm' );
    int seconds = time_diff( todelete->timestamp, current_time, 's' );
    char buf[8192];
    switch ( format )
    {
 default:
 case 's': sprintf( buf, "%ldd %dh %dm %ds", days, hours, minutes, seconds ); break;
 case 'm': sprintf( buf, "%ldd %dh %dm", days, hours, minutes ); break;
 case 'h': sprintf( buf, "%ldd %dh", days, hours ); break;
 case 'd': sprintf( buf, "%ldd", days ); break;
    }
    return str_dup( buf );
}

variable_types:
buf
char [8192]

return_type: char *


decompiled_code:
__int64 __fastcall trap_limit(unsigned __int8 a1, __int16 a2, int a3)
{
return a1 + (unsigned __int16)(a2 << 8) + ((a3 << 16) & 0xFF0000u);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, __int16 a2, int a3)
{
return a1 + (unsigned __int16)(a2 << 8) + ((a3 << 16) & 0xFF0000u);
}

original_code:
int trap_limit( int level, int dex, int skill )
{
 int ret_val = 0;
 ret_val = ( level & 0xff ) + ( ( dex & 0xff ) << 8 ) + ( ( skill & 0xff ) << 16 );
 return ret_val;
}

canonical_original_code:
int trap_limit(int level, int dex, int skill)
{
 int ret_val = 0;
 ret_val = ( level & 0xff ) + ( ( dex & 0xff ) << 8 ) + ( ( skill & 0xff ) << 16 );
 return ret_val;
}

variable_types: level int

variable_types: dex int

variable_types: skill int


decompiled_code:
void __fastcall set_trap_limit(_BYTE *a1, int a2, int a3)
{
switch ( a2 )
{
case 1:
a1[48] = URANGE(1LL, a3, 29LL);
break;
case 2:
a1[50] = URANGE(1LL, a3, 99LL);
break;
case 0:
a1[49] = URANGE(3LL, a3, 27LL);
break;
}
}

canonical_decompiled_code:
void __fastcall func1(_BYTE *a1, int a2, int a3)
{
switch ( a2 )
{
case 1:
a1[48] = URANGE(1LL, a3, 29LL);
break;
case 2:
a1[50] = URANGE(1LL, a3, 99LL);
break;
case 0:
a1[49] = URANGE(3LL, a3, 27LL);
break;
}
}

original_code:
void set_trap_limit( TRAP_DATA *trap, int limit, int value )
{
 char * ptr;
 switch ( limit )
 {
  case 0:
   ptr = ( char * ) & trap->limit;
   ptr++;
   *ptr = URANGE( 3, value, 27 ) & 0xff;
   break;
  case 2:
   ptr = ( char * ) & trap->limit;
   ptr += 2;
   *ptr = URANGE( 1, value, 99 ) & 0xff;
   break;
  case 1:
   ptr = ( char * ) & trap->limit;
   *ptr = URANGE( 1, value, 29 ) & 0xff;
   break;
  default: return ;
 }
 return ;
}

canonical_original_code:
void set_trap_limit(struct trap_data *trap, int limit, int value)
{
 char *ptr;
 switch ( limit )
 {
  case 0:
   ptr = ( char * ) & trap->limit;
   ptr++;
   *ptr = URANGE( 3, value, 27 ) & 0xff;
   break;
  case 2:
   ptr = ( char * ) & trap->limit;
   ptr += 2;
   *ptr = URANGE( 1, value, 99 ) & 0xff;
   break;
  case 1:
   ptr = ( char * ) & trap->limit;
   *ptr = URANGE( 1, value, 29 ) & 0xff;
   break;
  default: return ;
 }
 return ;
}

variable_types: struct trap_data { struct trap_data *next; unsigned short vnum; unsigned char active; int level; int type; char *triggered; char *disarmed; char *failed_disarm; int limit; } *

variable_types: limit int

variable_types: value int

variable_types:
ptr
char *


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

if ( !a1 )
return 0LL;
result = *(unsigned int *)(a1 + 48);
if ( (_DWORD)result )
{
if ( a2 == 1 )
{
result = (unsigned __int8)result;
}
else if ( a2 == 2 )
{
result = BYTE2(result);
}
else
{
result = BYTE1(result);
if ( a2 )
result = 0LL;
}
}
return result;
}

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

if ( !a1 )
return 0LL;
result = *(unsigned int *)(a1 + 48);
if ( (_DWORD)result )
{
if ( a2 == 1 )
{
result = (unsigned __int8)result;
}
else if ( a2 == 2 )
{
result = BYTE2(result);
}
else
{
result = BYTE1(result);
if ( a2 )
result = 0LL;
}
}
return result;
}

original_code:
int get_limit( TRAP_DATA * trap , int limit )
{
 if ( !trap || trap->limit == 0 )
  return 0;
 switch ( limit )
 {
  case 0: return ( ( trap->limit >> 8 ) & 0xff );
  case 2: return ( ( trap->limit >> 16 ) & 0xff );
  case 1: return ( trap->limit & 0xff );
  default: return 0;
 }
 return ( trap->limit & 0xff );
}

canonical_original_code:
int get_limit(struct trap_data *trap, int limit)
{
 if ( !trap || trap->limit == 0 )
  return 0;
 switch ( limit )
 {
  case 0: return ( ( trap->limit >> 8 ) & 0xff );
  case 2: return ( ( trap->limit >> 16 ) & 0xff );
  case 1: return ( trap->limit & 0xff );
  default: return 0;
 }
 return ( trap->limit & 0xff );
}

user_defined_types: struct trap_data { struct trap_data *next; unsigned short vnum; unsigned char active; int level; int type; char *triggered; char *disarmed; char *failed_disarm; int limit; }


decompiled_code:
__int64 __fastcall flag_lookup(unsigned __int8 *a1, unsigned __int8 **a2)
{
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 4294967197LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v3) || (unsigned __int8)str_prefix(a1) )
{
v3 = v2[2];
v2 += 2;
if ( !v3 )
return 4294967197LL;
}
return *((unsigned int *)v2 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, unsigned __int8 **a2)
{
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 4294967197LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v3) || (unsigned __int8)str_prefix(a1) )
{
v3 = v2[2];
v2 += 2;
if ( !v3 )
return 4294967197LL;
}
return *((unsigned int *)v2 + 2);
}

original_code:
int flag_lookup ( const char *name, const struct flag_type *flag_table )
{
 int flag;
 for ( flag = 0; flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(flag_table[ flag ].name[ 0 ])])
       && !str_prefix( name, flag_table[ flag ].name ) )
   return flag_table[ flag ].bit;
 }
 return -99;
}

canonical_original_code:
int flag_lookup(char *name, struct flag_type *flag_table)
{
 int flag;
 for ( flag = 0; flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(flag_table[ flag ].name[ 0 ])])
       && !str_prefix( name, flag_table[ flag ].name ) )
   return flag_table[ flag ].bit;
 }
 return -99;
}

variable_types: struct flag_type { char *name; int bit; unsigned char settable; } *

variable_types: flag int


decompiled_code:
unsigned __int8 *__fastcall ext_flag_lookup(unsigned __int8 *a1, unsigned __int8 **a2)
{
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return (unsigned __int8 *)&EXT_NONE;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v3) || (unsigned __int8)str_prefix(a1) )
{
v3 = v2[3];
v2 += 3;
if ( !v3 )
return (unsigned __int8 *)&EXT_NONE;
}
return v2[1];
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func1(unsigned __int8 *a1, unsigned __int8 **a2)
{
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return (unsigned __int8 *)&EXT_NONE;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v3) || (unsigned __int8)str_prefix(a1) )
{
v3 = v2[3];
v2 += 3;
if ( !v3 )
return (unsigned __int8 *)&EXT_NONE;
}
return v2[1];
}

original_code:
BITVECT_DATA * ext_flag_lookup ( const char *name, const struct ext_flag_type * ext_flag_table )
{
 int flag;
 for ( flag = 0; ext_flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(ext_flag_table[ flag ].name[ 0 ])])
       && !str_prefix( name, ext_flag_table[ flag ].name ) )
   return ext_flag_table[ flag ].bitvect;
 }
 return &EXT_NONE;
}

canonical_original_code:
struct bitvect_data *ext_flag_lookup(char *name, struct ext_flag_type *ext_flag_table)
{
 int flag;
 for ( flag = 0; ext_flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(ext_flag_table[ flag ].name[ 0 ])])
       && !str_prefix( name, ext_flag_table[ flag ].name ) )
   return ext_flag_table[ flag ].bitvect;
 }
 return &EXT_NONE;
}

variable_types:
name
char *

variable_types: struct ext_flag_type { char *name; struct bitvect_data *bitvect; unsigned char settable; } *

return_type: struct bitvect_data { int bank; int vector; } *


decompiled_code:
__int64 __fastcall is_settable(unsigned __int8 *a1, unsigned __int8 **a2)
{
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v3) || (unsigned __int8)str_prefix(a1) )
{
v3 = v2[2];
v2 += 2;
if ( !v3 )
return 0LL;
}
return *((unsigned __int8 *)v2 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, unsigned __int8 **a2)
{
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v3) || (unsigned __int8)str_prefix(a1) )
{
v3 = v2[2];
v2 += 2;
if ( !v3 )
return 0LL;
}
return *((unsigned __int8 *)v2 + 12);
}

original_code:
bool is_settable ( const char *name, const struct flag_type *flag_table )
{
 int flag;
 for ( flag = 0; flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(flag_table[ flag ].name[ 0 ])])
       && !str_prefix( name, flag_table[ flag ].name ) )
   return flag_table[ flag ].settable;
 }
 return 0;
}

canonical_original_code:
unsigned char is_settable(char *name, struct flag_type *flag_table)
{
 int flag;
 for ( flag = 0; flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(flag_table[ flag ].name[ 0 ])])
       && !str_prefix( name, flag_table[ flag ].name ) )
   return flag_table[ flag ].settable;
 }
 return 0;
}

return_type: unsigned char

user_defined_types: struct flag_type { char *name; int bit; unsigned char settable; }


decompiled_code:
__int64 __fastcall ext_is_settable(unsigned __int8 *a1, unsigned __int8 **a2)
{
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v3) || (unsigned __int8)str_prefix(a1) )
{
v3 = v2[3];
v2 += 3;
if ( !v3 )
return 0LL;
}
return *((unsigned __int8 *)v2 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, unsigned __int8 **a2)
{
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v3) || (unsigned __int8)str_prefix(a1) )
{
v3 = v2[3];
v2 += 3;
if ( !v3 )
return 0LL;
}
return *((unsigned __int8 *)v2 + 16);
}

original_code:
bool ext_is_settable ( const char *name, const struct ext_flag_type * ext_flag_table )
{
 int flag;
 for ( flag = 0; ext_flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(ext_flag_table[ flag ].name[ 0 ])])
       && !str_prefix( name, ext_flag_table[ flag ].name ) )
   return ext_flag_table[ flag ].settable;
 }
 return 0;
}

canonical_original_code:
unsigned char ext_is_settable(char *name, struct ext_flag_type *ext_flag_table)
{
 int flag;
 for ( flag = 0; ext_flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(ext_flag_table[ flag ].name[ 0 ])])
       && !str_prefix( name, ext_flag_table[ flag ].name ) )
   return ext_flag_table[ flag ].settable;
 }
 return 0;
}

variable_types: struct ext_flag_type { char *name; struct bitvect_data { int bank; int vector; } *bitvect; unsigned char settable; } *

user_defined_types: struct ext_flag_type { char *name; struct bitvect_data *bitvect; unsigned char settable; }


decompiled_code:
__int64 __fastcall position_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)position_table[0];
if ( !position_table[0] )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)position_table[2 * v2];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)position_table[0];
if ( !position_table[0] )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)position_table[2 * v2];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

original_code:
int position_lookup ( const char *name )
{
 int pos;
 for ( pos = 0; position_table[ pos ].name != ((void *)0); pos++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(position_table[ pos ].name[ 0 ])])
       && !str_prefix( name, position_table[ pos ].name ) )
   return pos;
 }
 return -1;
}

canonical_original_code:
int position_lookup(char *name)
{
 int pos;
 for ( pos = 0; position_table[ pos ].name != ((void *)0); pos++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(position_table[ pos ].name[ 0 ])])
       && !str_prefix( name, position_table[ pos ].name ) )
   return pos;
 }
 return -1;
}

variable_types: pos int


decompiled_code:
__int64 __fastcall sex_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)sex_table;
if ( !sex_table )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)*((_QWORD *)&sex_table + v2);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)sex_table;
if ( !sex_table )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)*((_QWORD *)&sex_table + v2);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

original_code:
int sex_lookup ( const char *name )
{
 int sex;
 for ( sex = 0; sex_table[ sex ].name != ((void *)0); sex++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(sex_table[ sex ].name[ 0 ])])
       && !str_prefix( name, sex_table[ sex ].name ) )
   return sex;
 }
 return -1;
}

canonical_original_code:
int sex_lookup(char *name)
{
 int sex;
 for ( sex = 0; sex_table[ sex ].name != ((void *)0); sex++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(sex_table[ sex ].name[ 0 ])])
       && !str_prefix( name, sex_table[ sex ].name ) )
   return sex;
 }
 return -1;
}

variable_types: sex int


decompiled_code:
__int64 __fastcall gender_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)gender_table;
if ( !gender_table )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)*((_QWORD *)&gender_table + v2);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)gender_table;
if ( !gender_table )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)*((_QWORD *)&gender_table + v2);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

original_code:
int gender_lookup ( const char *name )
{
 int gender;
 for ( gender = 0; gender_table[ gender ].name != ((void *)0); gender++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(gender_table[ gender ].name[ 0 ])])
       && !str_prefix( name, gender_table[ gender ].name ) )
   return gender;
 }
 return -1;
}

canonical_original_code:
int gender_lookup(char *name)
{
 int gender;
 for ( gender = 0; gender_table[ gender ].name != ((void *)0); gender++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(gender_table[ gender ].name[ 0 ])])
       && !str_prefix( name, gender_table[ gender ].name ) )
   return gender;
 }
 return -1;
}

variable_types: gender int


decompiled_code:
__int64 __fastcall size_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)size_table;
if ( !size_table )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)*((_QWORD *)&size_table + v2);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)size_table;
if ( !size_table )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)*((_QWORD *)&size_table + v2);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

original_code:
int size_lookup ( const char *name )
{
 int size;
 for ( size = 0; size_table[ size ].name != ((void *)0); size++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(size_table[ size ].name[ 0 ])])
       && !str_prefix( name, size_table[ size ].name ) )
   return size;
 }
 return -1;
}

canonical_original_code:
int size_lookup(char *name)
{
 int size;
 for ( size = 0; size_table[ size ].name != ((void *)0); size++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(size_table[ size ].name[ 0 ])])
       && !str_prefix( name, size_table[ size ].name ) )
   return size;
 }
 return -1;
}

variable_types: size int


decompiled_code:
__int64 __fastcall race_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
unsigned __int64 v2; // rbx
unsigned int v3; // er12

v1 = (unsigned __int8 *)race_table;
if ( !race_table )
return 0LL;
v2 = (unsigned int)((_DWORD)&race_table + 216);
v3 = 0;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
v1 = *(unsigned __int8 **)v2;
v2 += 216LL;
++v3;
if ( !v1 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
unsigned __int64 v2; // rbx
unsigned int v3; // er12

v1 = (unsigned __int8 *)race_table;
if ( !race_table )
return 0LL;
v2 = (unsigned int)((_DWORD)&race_table + 216);
v3 = 0;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
v1 = *(unsigned __int8 **)v2;
v2 += 216LL;
++v3;
if ( !v1 )
return 0LL;
}
return v3;
}

original_code:
int race_lookup ( const char *name )
{
 int race;
 for ( race = 0; race_table[ race ].name != ((void *)0); race++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(race_table[ race ].name[ 0 ])])
       && !str_prefix( name, race_table[ race ].name ) )
   return race;
 }
 return 0;
}

canonical_original_code:
int race_lookup(char *name)
{
 int race;
 for ( race = 0; race_table[ race ].name != ((void *)0); race++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(race_table[ race ].name[ 0 ])])
       && !str_prefix( name, race_table[ race ].name ) )
   return race;
 }
 return 0;
}

variable_types: race int


decompiled_code:
__int64 __fastcall item_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)*((_QWORD *)&item_table + 1);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)*((_QWORD *)&item_table + 2 * v2 + 1);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)&item_table + 4 * (int)v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)*((_QWORD *)&item_table + 1);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)*((_QWORD *)&item_table + 2 * v2 + 1);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)&item_table + 4 * (int)v2);
}

original_code:
int item_lookup( const char *name )
{
 int type;
 for ( type = 0; item_table[ type ].name != ((void *)0); type++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(item_table[ type ].name[ 0 ])])
       && !str_prefix( name, item_table[ type ].name ) )
   return item_table[ type ].type;
 }
 return -1;
}

canonical_original_code:
int item_lookup(char *name)
{
 int type;
 for ( type = 0; item_table[ type ].name != ((void *)0); type++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(item_table[ type ].name[ 0 ])])
       && !str_prefix( name, item_table[ type ].name ) )
   return item_table[ type ].type;
 }
 return -1;
}

variable_types: type int


decompiled_code:
__int64 __fastcall liq_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
unsigned __int64 v2; // rbx
unsigned int v3; // er12

v1 = (unsigned __int8 *)liq_table;
if ( !liq_table )
return 0xFFFFFFFFLL;
v2 = (unsigned int)((_DWORD)&liq_table + 72);
v3 = 0;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
v1 = *(unsigned __int8 **)v2;
v2 += 72LL;
++v3;
if ( !v1 )
return 0xFFFFFFFFLL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
unsigned __int64 v2; // rbx
unsigned int v3; // er12

v1 = (unsigned __int8 *)liq_table;
if ( !liq_table )
return 0xFFFFFFFFLL;
v2 = (unsigned int)((_DWORD)&liq_table + 72);
v3 = 0;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
v1 = *(unsigned __int8 **)v2;
v2 += 72LL;
++v3;
if ( !v1 )
return 0xFFFFFFFFLL;
}
return v3;
}

original_code:
int liq_lookup ( const char *name )
{
 int liq;
 for ( liq = 0; liq_table[ liq ].liq_name != ((void *)0); liq++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(liq_table[ liq ].liq_name[ 0 ])])
       && !str_prefix( name, liq_table[ liq ].liq_name ) )
   return liq;
 }
 return -1;
}

canonical_original_code:
int liq_lookup(char *name)
{
 int liq;
 for ( liq = 0; liq_table[ liq ].liq_name != ((void *)0); liq++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(liq_table[ liq ].liq_name[ 0 ])])
       && !str_prefix( name, liq_table[ liq ].liq_name ) )
   return liq;
 }
 return -1;
}

variable_types: liq int


decompiled_code:
__int64 __fastcall tool_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)tool_table[0];
if ( !tool_table[0] )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)tool_table[2 * v2];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)tool_table[0];
if ( !tool_table[0] )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
++v2;
v1 = (unsigned __int8 *)tool_table[2 * v2];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

original_code:
int tool_lookup ( const char *name)
{
 int tool;
 for ( tool = 0; tool_table[ tool ].name != ((void *)0); tool++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[0])]) == ( upper_nopol[(unsigned char)(tool_table[tool].name[0])])
    && !str_prefix( name, tool_table[tool].name ) )
  {
   return tool;
  }
 }
 return -1;
}

canonical_original_code:
int tool_lookup(char *name)
{
 int tool;
 for ( tool = 0; tool_table[ tool ].name != ((void *)0); tool++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[0])]) == ( upper_nopol[(unsigned char)(tool_table[tool].name[0])])
    && !str_prefix( name, tool_table[tool].name ) )
  {
   return tool;
  }
 }
 return -1;
}

variable_types: tool int


decompiled_code:
__int64 __fastcall rawmaterial_lookup(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned int v2; // er12
__int64 v3; // rsi

if ( !rawmaterial_table )
return 0xFFFFFFFFLL;
v1 = (unsigned int)((_DWORD)&rawmaterial_table + 24);
v2 = 0;
while ( (unsigned __int8)str_prefix(a1) )
{
v3 = *(_QWORD *)v1;
v1 += 24LL;
++v2;
if ( !v3 )
return 0xFFFFFFFFLL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned int v2; // er12
__int64 v3; // rsi

if ( !rawmaterial_table )
return 0xFFFFFFFFLL;
v1 = (unsigned int)((_DWORD)&rawmaterial_table + 24);
v2 = 0;
while ( (unsigned __int8)str_prefix(a1) )
{
v3 = *(_QWORD *)v1;
v1 += 24LL;
++v2;
if ( !v3 )
return 0xFFFFFFFFLL;
}
return v2;
}

original_code:
int rawmaterial_lookup( const char *name )
{
 int mat;
 for ( mat = 0; rawmaterial_table[ mat ].name; ++mat )
 {
  if ( !str_prefix( name, rawmaterial_table[ mat ].name ) )
  {
   return mat;
  }
 }
 return -1;
}

canonical_original_code:
int rawmaterial_lookup(char *name)
{
 int mat;
 for ( mat = 0; rawmaterial_table[ mat ].name; ++mat )
 {
  if ( !str_prefix( name, rawmaterial_table[ mat ].name ) )
  {
   return mat;
  }
 }
 return -1;
}

variable_types: mat int


decompiled_code:
__int64 __fastcall weed_lookup(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)weed_table[0];
if ( !weed_table[0] )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
v1 = (unsigned __int8 *)weed_table[8 * ++v2];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
__int64 v2; // rbx

v1 = (unsigned __int8 *)weed_table[0];
if ( !weed_table[0] )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + *v1) || (unsigned __int8)str_prefix(a1) )
{
v1 = (unsigned __int8 *)weed_table[8 * ++v2];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

original_code:
int weed_lookup ( const char *name )
{
 int weed;
 for ( weed = 0; weed_table[ weed ].weed_name != ((void *)0); weed++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(weed_table[ weed ].weed_name[ 0 ])])
       && !str_prefix( name, weed_table[ weed ].weed_name ) )
   return weed;
 }
 return -1;
}

canonical_original_code:
int weed_lookup(char *name)
{
 int weed;
 for ( weed = 0; weed_table[ weed ].weed_name != ((void *)0); weed++ )
 {
  if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(weed_table[ weed ].weed_name[ 0 ])])
       && !str_prefix( name, weed_table[ weed ].weed_name ) )
   return weed;
 }
 return -1;
}

variable_types: weed int


decompiled_code:
__int64 __fastcall language_lookup(__int64 a1)
{
__int64 v1; // rbx

if ( !lang_table[2] )
return 0xFFFFFFFFLL;
v1 = 0LL;
while ( (unsigned __int8)str_prefix(a1) )
{
if ( !lang_table[4 * v1++ + 6] )
return 0xFFFFFFFFLL;
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 v1; // rbx

if ( !lang_table[2] )
return 0xFFFFFFFFLL;
v1 = 0LL;
while ( (unsigned __int8)str_prefix(a1) )
{
if ( !lang_table[4 * v1++ + 6] )
return 0xFFFFFFFFLL;
}
return (unsigned int)v1;
}

original_code:
int language_lookup( char *arg )
{
 int langs;
 for ( langs = 0; lang_table[ langs ].bit != 0; langs++ )
 {
  if ( !str_prefix( arg, lang_table[ langs ].name ) )
  {
   return langs;
  }
 }
 return -1;
}

canonical_original_code:
int language_lookup(char *arg)
{
 int langs;
 for ( langs = 0; lang_table[ langs ].bit != 0; langs++ )
 {
  if ( !str_prefix( arg, lang_table[ langs ].name ) )
  {
   return langs;
  }
 }
 return -1;
}

variable_types:
arg
char *

variable_types: langs int


decompiled_code:
__int64 __fastcall rem_flag(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rbx
bool v6; // zf
__int64 v7; // rbx
unsigned __int8 v8; // [rsp+Fh] [rbp-21h]

result = 0LL;
v3 = *a1;
if ( *a1 )
{
v4 = *a1;
if ( !(unsigned __int8)str_cmp(*(_QWORD *)(v3 + 8)) )
{
v5 = *(_QWORD *)(v3 + 24);
free_pflag(v3, a2);
result = 1LL;
*a1 = v5;
if ( misc[5] != v5 )
return result;
LABEL_10:
v8 = result;
save_misc_data();
return v8;
}
while ( 1 )
{
v6 = (unsigned __int8)str_cmp(*(_QWORD *)(v4 + 8)) == 0;
result = *(_QWORD *)(v4 + 24);
if ( v6 )
break;
v3 = v4;
if ( !result )
{
v7 = *a1;
goto LABEL_9;
}
v4 = *(_QWORD *)(v4 + 24);
}
*(_QWORD *)(v3 + 24) = result;
*(_QWORD *)(v4 + 24) = 0LL;
free_pflag(v4, a2);
v7 = *a1;
result = 1LL;
LABEL_9:
if ( misc[5] == v7 )
goto LABEL_10;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rbx
bool v6; // zf
__int64 v7; // rbx
unsigned __int8 v8; // [rsp+Fh] [rbp-21h]

result = 0LL;
v3 = *a1;
if ( *a1 )
{
v4 = *a1;
if ( !(unsigned __int8)str_cmp(*(_QWORD *)(v3 + 8)) )
{
v5 = *(_QWORD *)(v3 + 24);
free_pflag(v3, a2);
result = 1LL;
*a1 = v5;
if ( misc[5] != v5 )
return result;
LABEL_10:
v8 = result;
save_misc_data();
return v8;
}
while ( 1 )
{
v6 = (unsigned __int8)str_cmp(*(_QWORD *)(v4 + 8)) == 0;
result = *(_QWORD *)(v4 + 24);
if ( v6 )
break;
v3 = v4;
if ( !result )
{
v7 = *a1;
goto LABEL_9;
}
v4 = *(_QWORD *)(v4 + 24);
}
*(_QWORD *)(v3 + 24) = result;
*(_QWORD *)(v4 + 24) = 0LL;
free_pflag(v4, a2);
v7 = *a1;
result = 1LL;
LABEL_9:
if ( misc[5] == v7 )
goto LABEL_10;
}
return result;
}

original_code:
bool rem_flag( PFLAG_DATA **list, char *argument )
{
 PFLAG_DATA * tmp, *org_list, *tmp_prev;
 bool result = 0;
 org_list = *list;
 tmp = org_list;
 if ( !tmp )
  return 0;
 if ( !str_cmp( tmp->id, argument ) )
 {
  org_list = org_list->next;
  free_pflag( tmp );
  tmp = ((void *)0);
  *list = org_list;
  result = 1;
 }
 else
 {
  tmp_prev = tmp;
  for ( ;tmp;tmp = tmp->next )
  {
   if ( !str_cmp( tmp->id, argument ) )
   {
    tmp_prev->next = tmp->next;
    tmp->next = ((void *)0);
    free_pflag( tmp );
    tmp = ((void *)0);
    result = 1;
    break;
   }
   tmp_prev = tmp;
  }
 }
 if ( *list == misc.global_flag_list )
  save_misc_data();
 return result;
}

canonical_original_code:
unsigned char rem_flag(struct pflag_data **list, char *argument)
{
 struct pflag_data *tmp; struct pflag_data *org_list; struct pflag_data *tmp_prev;
 unsigned char result = 0;
 org_list = *list;
 tmp = org_list;
 if ( !tmp )
  return 0;
 if ( !str_cmp( tmp->id, argument ) )
 {
  org_list = org_list->next;
  free_pflag( tmp );
  tmp = ((void *)0);
  *list = org_list;
  result = 1;
 }
 else
 {
  tmp_prev = tmp;
  for ( ;tmp;tmp = tmp->next )
  {
   if ( !str_cmp( tmp->id, argument ) )
   {
    tmp_prev->next = tmp->next;
    tmp->next = ((void *)0);
    free_pflag( tmp );
    tmp = ((void *)0);
    result = 1;
    break;
   }
   tmp_prev = tmp;
  }
 }
 if ( *list == misc.global_flag_list )
  save_misc_data();
 return result;
}

variable_types: struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; } **

variable_types:
argument
char *

variable_types:
result
unsigned char


original_code:
PFLAG_DATA * add_flag( PFLAG_DATA **list, char *id, int duration )
{
 PFLAG_DATA * tmp;
 if ( !id || id[ 0 ] == '\0' )
  return ((void *)0);
 if ( strlen( id ) > 32 )
  return ((void *)0);
 if ( *list )
 {
  for ( tmp = *list;tmp;tmp = tmp->next )
  {
   if ( !str_cmp( tmp->id, id ) )
   {
    if ( tmp->duration != -1 )
     tmp->duration = duration;
    return tmp;
   }
  }
 }
 tmp = new_pflag();
 tmp->id = str_dup( id );
 tmp->duration = duration;
 tmp->next = ((void *)0);
 tmp->next = ( *list );
 *list = tmp;
 return tmp;
}

canonical_original_code:
struct pflag_data *add_flag(struct pflag_data **list, char *id, int duration)
{
 struct pflag_data *tmp;
 if ( !id || id[ 0 ] == '\0' )
  return ((void *)0);
 if ( strlen( id ) > 32 )
  return ((void *)0);
 if ( *list )
 {
  for ( tmp = *list;tmp;tmp = tmp->next )
  {
   if ( !str_cmp( tmp->id, id ) )
   {
    if ( tmp->duration != -1 )
     tmp->duration = duration;
    return tmp;
   }
  }
 }
 tmp = new_pflag();
 tmp->id = str_dup( id );
 tmp->duration = duration;
 tmp->next = ((void *)0);
 tmp->next = ( *list );
 *list = tmp;
 return tmp;
}

variable_types:
list
struct pflag_data **

variable_types:
id
char *

variable_types: duration int

variable_types: struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; } *


setglobalflag

decompiled_code:
__int64 __fastcall setglobalflag(_BYTE *a1)
{
const char *v2; // rax
const char *v3; // r12
int v4; // edx
int v5; // eax
char v6[520]; // [rsp+0h] [rbp-210h] BYREF

if ( !*a1 )
return 0LL;
v2 = (const char *)one_argument(a1, v6);
v3 = v2;
if ( !v6[0] )
return 0LL;
if ( *v2 && (unsigned __int8)is_number(v2) )
{
v5 = atoi(v3);
v4 = UMAX(-1LL, v5);
}
else
{
v4 = 0;
}
if ( !add_flag((__int64 *)(unsigned int)((_DWORD)misc + 40), v6, v4) )
return 0LL;
save_misc_data();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1)
{
const char *v2; // rax
const char *v3; // r12
int v4; // edx
int v5; // eax
char v6[520]; // [rsp+0h] [rbp-210h] BYREF

if ( !*a1 )
return 0LL;
v2 = (const char *)one_argument(a1, v6);
v3 = v2;
if ( !v6[0] )
return 0LL;
if ( *v2 && (unsigned __int8)is_number(v2) )
{
v5 = atoi(v3);
v4 = UMAX(-1LL, v5);
}
else
{
v4 = 0;
}
if ( !func1((__int64 *)(unsigned int)((_DWORD)misc + 40), v6, v4) )
return 0LL;
save_misc_data();
return 1LL;
}

original_code:
bool setglobalflag( char *argument )
{
 int counter;
 char arg[ 512 ];
 if ( argument[ 0 ] == '\0' )
  return 0;
 argument = one_argument( argument, arg );
 if ( arg[ 0 ] == '\0' )
  return 0;
 if ( argument[ 0 ] != '\0' && is_number( argument ) )
 {
  counter = atoi( argument );
  counter = UMAX( -1, counter );
 }
 else
  counter = 0;
 if ( !add_flag( &misc.global_flag_list, arg, counter ) )
  return 0;
 save_misc_data();
 if ( arg[ 0 ] == 'r' && arg[ 1 ] == 'e' && arg[ 2 ] == 'g' )
  return 1;
 return 1;
}

canonical_original_code:
unsigned char setglobalflag(char *argument)
{
 int counter;
 char arg[512];
 if ( argument[ 0 ] == '\0' )
  return 0;
 argument = one_argument( argument, arg );
 if ( arg[ 0 ] == '\0' )
  return 0;
 if ( argument[ 0 ] != '\0' && is_number( argument ) )
 {
  counter = atoi( argument );
  counter = UMAX( -1, counter );
 }
 else
  counter = 0;
 if ( !add_flag( &misc.global_flag_list, arg, counter ) )
  return 0;
 save_misc_data();
 if ( arg[ 0 ] == 'r' && arg[ 1 ] == 'e' && arg[ 2 ] == 'g' )
  return 1;
 return 1;
}

variable_types: counter int

variable_types:
arg
char [512]


removeglobalflag

decompiled_code:
__int64 __fastcall removeglobalflag(_BYTE *a1)
{
__int64 result; // rax

if ( *a1 )
result = rem_flag((__int64 *)(unsigned int)((_DWORD)misc + 40), (__int64)a1);
else
result = 0LL;
return result;
}

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

if ( *a1 )
result = func0((__int64 *)(unsigned int)((_DWORD)misc + 40), (__int64)a1);
else
result = 0LL;
return result;
}

original_code:
bool removeglobalflag( char *argument )
{
 if ( argument[ 0 ] == '\0' )
  return 0;
 return rem_flag( &misc.global_flag_list, argument );
}

canonical_original_code:
unsigned char removeglobalflag(char *argument)
{
 if ( argument[ 0 ] == '\0' )
  return 0;
 return rem_flag( &misc.global_flag_list, argument );
}


decompiled_code:
__int64 __fastcall flag_exists(unsigned __int8 *a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
if ( !a2 )
return 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + **(unsigned __int8 **)(v2 + 8))
|| (unsigned __int8)str_cmp(a1) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
if ( !a2 )
return 0LL;
while ( *((_BYTE *)&upper_nopol + *a1) != *((_BYTE *)&upper_nopol + **(unsigned __int8 **)(v2 + 8))
|| (unsigned __int8)str_cmp(a1) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
bool flag_exists( char *buf, PFLAG_DATA *plist )
{
 PFLAG_DATA * flag;
 for ( flag = plist; flag; flag = flag->next )
  if ( ( upper_nopol[(unsigned char)(buf[ 0 ])]) == ( upper_nopol[(unsigned char)(flag->id[ 0 ])]) && !str_cmp( buf, flag->id ) )
   return 1;
 return 0;
}

canonical_original_code:
unsigned char flag_exists(char *buf, struct pflag_data *plist)
{
 struct pflag_data *flag;
 for ( flag = plist; flag; flag = flag->next )
  if ( ( upper_nopol[(unsigned char)(buf[ 0 ])]) == ( upper_nopol[(unsigned char)(flag->id[ 0 ])]) && !str_cmp( buf, flag->id ) )
   return 1;
 return 0;
}

variable_types:
buf
char *

user_defined_types: struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; }


decompiled_code:
void update_global_flags()
{
__int64 v0; // rbx
__int64 v1; // rdx
unsigned __int8 *v2; // rdi
int v3; // eax
int v4; // eax

v0 = misc[5];
LABEL_2:
while ( v0 )
{
while ( 1 )
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 24);
v2 = *(unsigned __int8 **)(v1 + 8);
if ( *((_BYTE *)&upper_nopol + *v2) == 82
&& *((_BYTE *)&upper_nopol + v2[1]) == 69
&& *((_BYTE *)&upper_nopol + v2[2]) == 71 )
{
break;
}
v3 = *(_DWORD *)(v1 + 16);
if ( v3 <= 0 )
break;
v4 = v3 - 1;
*(_DWORD *)(v1 + 16) = v4;
if ( v4 )
{
save_misc_data();
goto LABEL_2;
}
removeglobalflag(v2);
if ( !v0 )
return;
}
}
}

original_code:
void update_global_flags()
{
 PFLAG_DATA * global_flag, * global_flag_next;
 for ( global_flag = misc.global_flag_list ; global_flag ; global_flag = global_flag_next )
 {
  global_flag_next = global_flag->next;
  if ( ( upper_nopol[(unsigned char)(global_flag->id[ 0 ])]) == 'R' &&
       ( upper_nopol[(unsigned char)(global_flag->id[ 1 ])]) == 'E' &&
       ( upper_nopol[(unsigned char)(global_flag->id[ 2 ])]) == 'G' )
   continue;
  if ( global_flag->duration > 0 )
  {
   global_flag->duration--;
   if ( global_flag->duration == 0 )
    removeglobalflag( global_flag->id );
   else
    save_misc_data();
  }
 }
}

canonical_original_code:
void update_global_flags()
{
 struct pflag_data *global_flag; struct pflag_data *global_flag_next;
 for ( global_flag = misc.global_flag_list ; global_flag ; global_flag = global_flag_next )
 {
  global_flag_next = global_flag->next;
  if ( ( upper_nopol[(unsigned char)(global_flag->id[ 0 ])]) == 'R' &&
       ( upper_nopol[(unsigned char)(global_flag->id[ 1 ])]) == 'E' &&
       ( upper_nopol[(unsigned char)(global_flag->id[ 2 ])]) == 'G' )
   continue;
  if ( global_flag->duration > 0 )
  {
   global_flag->duration--;
   if ( global_flag->duration == 0 )
    removeglobalflag( global_flag->id );
   else
    save_misc_data();
  }
 }
}


decompiled_code:
void *__fastcall zlib_alloc(__int64 a1, unsigned int a2, unsigned int a3)
{
return calloc(a2, a3);
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
return calloc(a2, a3);
}

original_code:
void *zlib_alloc(void *opaque, unsigned int items, unsigned int size)
{
    return calloc(items, size);
}

variable_types:
opaque
void *

variable_types:
items
unsigned int

variable_types:
size
unsigned int


decompiled_code:
void __fastcall zlib_free(__int64 a1, void *a2)
{
if ( a2 )
free(a2);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, void *a2)
{
if ( a2 )
free(a2);
}

original_code:
void zlib_free(void *opaque, void *address)
{
    do { if((address)) { free((address)); (address) = ((void *)0); } } while(0);
}

variable_types:
address
void *


decompiled_code:
__int64 __fastcall get_langflag(__int64 a1)
{
__int64 i; // rbx

if ( !*((_DWORD *)&lang_table + 2) )
return 0LL;
for ( i = 0LL; (unsigned __int8)str_cmp(a1, (&lang_table)[2 * i]); ++i )
{
if ( !LODWORD((&lang_table)[2 * i + 3]) )
return 0LL;
}
return LODWORD((&lang_table)[2 * (int)i + 1]);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 i; // rbx

if ( !*((_DWORD *)&lang_table + 2) )
return 0LL;
for ( i = 0LL; (unsigned __int8)str_cmp(a1, (&lang_table)[2 * i]); ++i )
{
if ( !LODWORD((&lang_table)[2 * i + 3]) )
return 0LL;
}
return LODWORD((&lang_table)[2 * (int)i + 1]);
}

original_code:
int get_langflag( char *flag )
{
 int x;
 for ( x = 0; lang_table[x].bit != 0; x++ )
  if ( !str_cmp( flag, lang_table[x].name ) )
   return lang_table[x].bit;
 return 0;
}

canonical_original_code:
int get_langflag(char *flag)
{
 int x;
 for ( x = 0; lang_table[x].bit != 0; x++ )
  if ( !str_cmp( flag, lang_table[x].name ) )
   return lang_table[x].bit;
 return 0;
}

variable_types:
flag
char *

variable_types: x int


decompiled_code:
__int64 __fastcall get_langnum(__int64 a1)
{
__int64 i; // rbx

if ( !*((_DWORD *)&lang_table + 2) )
return 0xFFFFFFFFLL;
for ( i = 0LL; (unsigned __int8)str_prefix(a1, (&lang_table)[2 * i]); ++i )
{
if ( !LODWORD((&lang_table)[2 * i + 3]) )
return 0xFFFFFFFFLL;
}
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 i; // rbx

if ( !*((_DWORD *)&lang_table + 2) )
return 0xFFFFFFFFLL;
for ( i = 0LL; (unsigned __int8)str_prefix(a1, (&lang_table)[2 * i]); ++i )
{
if ( !LODWORD((&lang_table)[2 * i + 3]) )
return 0xFFFFFFFFLL;
}
return (unsigned int)i;
}

original_code:
int get_langnum( char *flag )
{
        int x;
        for ( x = 0; lang_table[x].bit != 0; x++ )
            if ( !str_prefix( flag, lang_table[x].name ) )
                return x;
        return -1;
}

canonical_original_code:
int get_langnum(char *flag)
{
        int x;
        for ( x = 0; lang_table[x].bit != 0; x++ )
            if ( !str_prefix( flag, lang_table[x].name ) )
                return x;
        return -1;
}


translate

original_code:
char *translate(int percent, const char *in, const char *name)
{
    LCNV_DATA *cnv;
    static char buf[2 * 512 ];
    char buf2[ 2 * 512 ];
    const char *pbuf;
    char *pbuf2 = buf2;
    LANG_DATA *lng;
    if ( percent > 99 )
 return (char *) in;
    if ( !(lng=get_lang(name)) )
 if ( !(lng = get_lang("default")) )
     return (char *) in;
    for (pbuf = in; *pbuf;)
    {
 for (cnv = lng->first_precnv; cnv; cnv = cnv->next)
 {
     if (!str_prefix(cnv->old, pbuf))
     {
  if ( (percent > 0) && ( ((number_percent() + number_percent()) /2) < percent ))
  {
      strncpy(pbuf2, pbuf, cnv->olen);
      pbuf2[cnv->olen] = '\0';
      pbuf2 += cnv->olen;
  }
  else
  {
      strcpy(pbuf2, cnv->new);
      pbuf2 += cnv->nlen;
  }
  pbuf += cnv->olen;
  break;
     }
 }
 if (!cnv)
 {
     if (((*__ctype_b_loc ())[(int) ((*pbuf))] & (unsigned short int) _ISalpha) && (!percent || ((number_percent() + number_percent())/2) > percent) )
     {
  *pbuf2 = lng->alphabet[( lower_pol[(unsigned char)(*pbuf)]) - 'a'];
  if ( ((*__ctype_b_loc ())[(int) ((*pbuf))] & (unsigned short int) _ISupper) )
      *pbuf2 = ( upper_pol[(unsigned char)(*pbuf2)]);
     }
     else
  *pbuf2 = *pbuf;
     pbuf++;
     pbuf2++;
 }
    }
    *pbuf2 = '\0';
    for (pbuf = buf2, pbuf2 = buf; *pbuf;)
    {
 for (cnv = lng->first_cnv; cnv; cnv = cnv->next)
     if (!str_prefix(cnv->old, pbuf))
     {
  strcpy(pbuf2, cnv->new);
  pbuf += cnv->olen;
  pbuf2 += cnv->nlen;
  break;
     }
 if (!cnv)
     *(pbuf2++) = *(pbuf++);
    }
    *pbuf2 = '\0';
    return buf;
}

canonical_original_code:
char *translate(int percent, char *in, char *name)
{
    struct lcnv_data *cnv;
    static char buf[-1];
    char buf2[-1];
    char *pbuf;
    char *pbuf2 = buf2;
    struct lang_data *lng;
    if ( percent > 99 )
 return (char *) in;
    if ( !(lng=get_lang(name)) )
 if ( !(lng = get_lang("default")) )
     return (char *) in;
    for (pbuf = in; *pbuf;)
    {
 for (cnv = lng->first_precnv; cnv; cnv = cnv->next)
 {
     if (!str_prefix(cnv->old, pbuf))
     {
  if ( (percent > 0) && ( ((number_percent() + number_percent()) /2) < percent ))
  {
      strncpy(pbuf2, pbuf, cnv->olen);
      pbuf2[cnv->olen] = '\0';
      pbuf2 += cnv->olen;
  }
  else
  {
      strcpy(pbuf2, cnv->new);
      pbuf2 += cnv->nlen;
  }
  pbuf += cnv->olen;
  break;
     }
 }
 if (!cnv)
 {
     if (((*__ctype_b_loc ())[(int) ((*pbuf))] & (unsigned short) _ISalpha) && (!percent || ((number_percent() + number_percent())/2) > percent) )
     {
  *pbuf2 = lng->alphabet[( lower_pol[(unsigned char)(*pbuf)]) - 'a'];
  if ( ((*__ctype_b_loc ())[(int) ((*pbuf))] & (unsigned short) _ISupper) )
      *pbuf2 = ( upper_pol[(unsigned char)(*pbuf2)]);
     }
     else
  *pbuf2 = *pbuf;
     pbuf++;
     pbuf2++;
 }
    }
    *pbuf2 = '\0';
    for (pbuf = buf2, pbuf2 = buf; *pbuf;)
    {
 for (cnv = lng->first_cnv; cnv; cnv = cnv->next)
     if (!str_prefix(cnv->old, pbuf))
     {
  strcpy(pbuf2, cnv->new);
  pbuf += cnv->olen;
  pbuf2 += cnv->nlen;
  break;
     }
 if (!cnv)
     *(pbuf2++) = *(pbuf++);
    }
    *pbuf2 = '\0';
    return buf;
}

variable_types: percent int

variable_types:
in
char *

variable_types:
name
char *

variable_types:
buf
char [-1]

variable_types:
pbuf
char *

variable_types: struct lang_data { struct lang_data *next; char *name; struct lcnv_data { struct lcnv_data *next; char *old; int olen; char *new; int nlen; } *first_precnv; char *alphabet; struct lcnv_data *first_cnv; } *

user_defined_types: struct lang_data { struct lang_data *next; char *name; struct lcnv_data *first_precnv; char *alphabet; struct lcnv_data *first_cnv; }


original_code:
char *translate_gnomish( char *string )
{
    static char buf[ 8192 ];
    char *point;
    buf[0] = '\0';
    point = buf;
    while ( *string )
    {
        if ( ((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short int) _ISspace) )
        {
            if ( !((*__ctype_b_loc ())[(int) ((*( string + 1 )))] & (unsigned short int) _ISspace) )
                *point++ = ( upper_pol[(unsigned char)(*++string)]);
            string++;
        }
        else
            *point++ = *string++;
    }
    *point = '\0';
    buf[0] = ( upper_pol[(unsigned char)(buf[0])]);
    return buf;
}

canonical_original_code:
char *translate_gnomish(char *string)
{
    static char buf[8192];
    char *point;
    buf[0] = '\0';
    point = buf;
    while ( *string )
    {
        if ( ((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short) _ISspace) )
        {
            if ( !((*__ctype_b_loc ())[(int) ((*( string + 1 )))] & (unsigned short) _ISspace) )
                *point++ = ( upper_pol[(unsigned char)(*++string)]);
            string++;
        }
        else
            *point++ = *string++;
    }
    *point = '\0';
    buf[0] = ( upper_pol[(unsigned char)(buf[0])]);
    return buf;
}

variable_types:
string
char *

variable_types:
buf
char [8192]

variable_types:
point
char *


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

result = 1LL;
v2 = a1;
mt[0] = a1;
while ( 1 )
{
v2 = 1812433253 * ((unsigned int)v2 ^ (unsigned int)(v2 >> 30)) + (unsigned int)result;
mt[result] = v2;
if ( result == 623 )
break;
++result;
}
mti = 624;
return result;
}

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

result = 1LL;
v2 = a1;
mt[0] = a1;
while ( 1 )
{
v2 = 1812433253 * ((unsigned int)v2 ^ (unsigned int)(v2 >> 30)) + (unsigned int)result;
mt[result] = v2;
if ( result == 623 )
break;
++result;
}
mti = 624;
return result;
}

original_code:
void init_genrand(unsigned long s)
{
    mt[0]= s & 0xffffffffUL;
    for (mti=1; mti<624; mti++) {
        mt[mti] =
     (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
        mt[mti] &= 0xffffffffUL;
    }
}

variable_types:
s
unsigned long


variable_types:
y
unsigned long

variable_types: kk int

return_type: unsigned long


decompiled_code:
unsigned __int64 genrand_int31()
{
return genrand_int32() >> 1;
}

canonical_decompiled_code:
unsigned __int64 func3()
{
return func2() >> 1;
}

original_code:
long genrand_int31(void)
{
    return (long)(genrand_int32()>>1);
}

canonical_original_code:
long genrand_int31()
{
    return (long)(genrand_int32()>>1);
}


original_code:
double genrand_real1(void)
{
    return genrand_int32()*(1.0/4294967295.0);
}

canonical_original_code:
double genrand_real1()
{
    return genrand_int32()*(1.0/4294967295.0);
}

return_type: double


original_code:
double genrand_real2(void)
{
    return genrand_int32()*(1.0/4294967296.0);
}

canonical_original_code:
double genrand_real2()
{
    return genrand_int32()*(1.0/4294967296.0);
}


original_code:
double genrand_real3(void)
{
    return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
}


canonical_original_code:
double genrand_res53()
{
    unsigned long a = genrand_int32()>>5; unsigned long b = genrand_int32()>>6;
    return(a*67108864.0+b)*(1.0/9007199254740992.0);
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


original_code:
void init_random(long x, long y)
{
  unsigned long init[6]={0x871, 0x127, 0x003, 0x780, 0, 0}, length=6;
  init[4] = x;
  init[5] = y;
  init_by_array(init, length);
}

canonical_original_code:
void init_random(long x, long y)
{
  unsigned long init[6] = {0x871, 0x127, 0x003, 0x780, 0, 0}; unsigned long length = 6;
  init[4] = x;
  init[5] = y;
  init_by_array(init, length);
}

variable_types: x long

variable_types: y long

variable_types:
init
unsigned long [6]

variable_types:
length
unsigned long


decompiled_code:
__int64 __fastcall obj_interpret(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rax
char v5[544]; // [rsp+0h] [rbp-220h] BYREF

result = running_prog_env;
if ( *(_QWORD *)(running_prog_env + 32LL) )
{
v2 = one_argument(a1, v5);
result = *(unsigned __int8 *)obj_cmd_table[0];
if ( (_BYTE)result )
{
v3 = 0LL;
while ( v5[0] != (_BYTE)result || (unsigned __int8)str_prefix(v5) )
{
v4 = v3++;
result = *(unsigned __int8 *)obj_cmd_table[2 * v4 + 2];
if ( !(_BYTE)result )
return result;
}
obj_cmd_table[2 * (int)v3 + 1](v2);
result = tail_chain();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rax
char v5[544]; // [rsp+0h] [rbp-220h] BYREF

result = running_prog_env;
if ( *(_QWORD *)(running_prog_env + 32LL) )
{
v2 = one_argument(a1, v5);
result = *(unsigned __int8 *)obj_cmd_table[0];
if ( (_BYTE)result )
{
v3 = 0LL;
while ( v5[0] != (_BYTE)result || (unsigned __int8)str_prefix(v5) )
{
v4 = v3++;
result = *(unsigned __int8 *)obj_cmd_table[2 * v4 + 2];
if ( !(_BYTE)result )
return result;
}
obj_cmd_table[2 * (int)v3 + 1](v2);
result = tail_chain();
}
}
return result;
}

original_code:
void obj_interpret( char *argument )
{
 char command[ 512 ];
 int cmd;
 if ( !running_prog_env->obj )
  return ;
 argument = one_argument( argument, command );
 for ( cmd = 0; obj_cmd_table[ cmd ].name[ 0 ] != '\0'; cmd++ )
 {
  if ( command[ 0 ] == obj_cmd_table[ cmd ].name[ 0 ]
       && !str_prefix( command, obj_cmd_table[ cmd ].name ) )
  {
   ( *obj_cmd_table[ cmd ].prog_fun ) ( argument );
   tail_chain( );
   return ;
  }
 }
 return ;
}

canonical_original_code:
void obj_interpret(char *argument)
{
 char command[512];
 int cmd;
 if ( !running_prog_env->obj )
  return ;
 argument = one_argument( argument, command );
 for ( cmd = 0; obj_cmd_table[ cmd ].name[ 0 ] != '\0'; cmd++ )
 {
  if ( command[ 0 ] == obj_cmd_table[ cmd ].name[ 0 ]
       && !str_prefix( command, obj_cmd_table[ cmd ].name ) )
  {
   ( *obj_cmd_table[ cmd ].prog_fun ) ( argument );
   tail_chain( );
   return ;
  }
 }
 return ;
}

variable_types:
argument
char *

variable_types:
command
char [512]

variable_types: cmd int


decompiled_code:
__int64 __fastcall do_osetflag(_BYTE *a1)
{
char v2[512]; // [rsp+0h] [rbp-200h] BYREF

if ( !*a1 )
return bug_prog_format("osetflag: missing argument", a1);
expand_arg(v2, a1);
return setobjflag(*(_QWORD *)(running_prog_env + 32LL), v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
char v2[512]; // [rsp+0h] [rbp-200h] BYREF

if ( !*a1 )
return bug_prog_format("osetflag: missing argument", a1);
expand_arg(v2, a1);
return setobjflag(*(_QWORD *)(running_prog_env + 32LL), v2);
}

original_code:
void do_osetflag( char *argument )
{
 char arg[ 512 ];
 if ( argument[ 0 ] == '\0' )
 {
  bug_prog_format( "osetflag: missing argument" );
  return ;
 }
 expand_arg( arg, argument );
 setobjflag( running_prog_env->obj, arg );
 return ;
}

canonical_original_code:
void do_osetflag(char *argument)
{
 char arg[512];
 if ( argument[ 0 ] == '\0' )
 {
  bug_prog_format( "osetflag: missing argument" );
  return ;
 }
 expand_arg( arg, argument );
 setobjflag( running_prog_env->obj, arg );
 return ;
}

variable_types:
arg
char [512]


decompiled_code:
int __fastcall do_omodflag(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rbx
unsigned __int8 *v5; // rsi
__int64 v6; // rax
__int64 v7; // rsi
char v9[512]; // [rsp+0h] [rbp-810h] BYREF
char v10[512]; // [rsp+200h] [rbp-610h] BYREF
char nptr[512]; // [rsp+400h] [rbp-410h] BYREF
char v12[528]; // [rsp+600h] [rbp-210h] BYREF

v1 = one_argument(a1, v12);
expand_arg(v9, v12);
v2 = one_argument(v1, v12);
expand_arg(v10, v12);
expand_arg(nptr, v2);
if ( v9[0] && (v3 = (unsigned __int8)v10[0], v10[0]) )
{
v4 = *(_QWORD *)(*(_QWORD *)(running_prog_env + 32LL) + 96LL);
if ( v4 )
{
while ( 1 )
{
v5 = *(unsigned __int8 **)(v4 + 8);
if ( *((_BYTE *)&upper_nopol + v3) == *((_BYTE *)&upper_nopol + *v5) )
{
LODWORD(v3) = str_cmp(v10, v5);
if ( !(_BYTE)v3 )
break;
}
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
return v3;
v3 = (unsigned __int8)v10[0];
}
LODWORD(v3) = str_cmp(v9, "set");
if ( (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v9, "mod");
if ( (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v9, "rem");
if ( !(_BYTE)v3 )
{
v6 = running_prog_env;
v7 = *(_QWORD *)(v4 + 8);
*(_DWORD *)(v4 + 16) = 0;
LODWORD(v3) = removeobjflag(*(_QWORD *)(v6 + 32), v7);
}
}
else if ( nptr[0] )
{
LODWORD(v3) = is_number(nptr);
if ( (_BYTE)v3 )
{
LODWORD(v3) = atoi(nptr);
*(_DWORD *)(v4 + 16) += v3;
}
}
}
else if ( nptr[0] )
{
LODWORD(v3) = is_number(nptr);
if ( (_BYTE)v3 )
{
LODWORD(v3) = atoi(nptr);
*(_DWORD *)(v4 + 16) = v3;
}
}
}
}
else
{
LODWORD(v3) = bug_prog_format("omodflag: missing argument", v2);
}
return v3;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rbx
unsigned __int8 *v5; // rsi
__int64 v6; // rax
__int64 v7; // rsi
char v9[512]; // [rsp+0h] [rbp-810h] BYREF
char v10[512]; // [rsp+200h] [rbp-610h] BYREF
char nptr[512]; // [rsp+400h] [rbp-410h] BYREF
char v12[528]; // [rsp+600h] [rbp-210h] BYREF

v1 = one_argument(a1, v12);
expand_arg(v9, v12);
v2 = one_argument(v1, v12);
expand_arg(v10, v12);
expand_arg(nptr, v2);
if ( v9[0] && (v3 = (unsigned __int8)v10[0], v10[0]) )
{
v4 = *(_QWORD *)(*(_QWORD *)(running_prog_env + 32LL) + 96LL);
if ( v4 )
{
while ( 1 )
{
v5 = *(unsigned __int8 **)(v4 + 8);
if ( *((_BYTE *)&upper_nopol + v3) == *((_BYTE *)&upper_nopol + *v5) )
{
LODWORD(v3) = str_cmp(v10, v5);
if ( !(_BYTE)v3 )
break;
}
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
return v3;
v3 = (unsigned __int8)v10[0];
}
LODWORD(v3) = str_cmp(v9, "set");
if ( (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v9, "mod");
if ( (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v9, "rem");
if ( !(_BYTE)v3 )
{
v6 = running_prog_env;
v7 = *(_QWORD *)(v4 + 8);
*(_DWORD *)(v4 + 16) = 0;
LODWORD(v3) = removeobjflag(*(_QWORD *)(v6 + 32), v7);
}
}
else if ( nptr[0] )
{
LODWORD(v3) = is_number(nptr);
if ( (_BYTE)v3 )
{
LODWORD(v3) = atoi(nptr);
*(_DWORD *)(v4 + 16) += v3;
}
}
}
else if ( nptr[0] )
{
LODWORD(v3) = is_number(nptr);
if ( (_BYTE)v3 )
{
LODWORD(v3) = atoi(nptr);
*(_DWORD *)(v4 + 16) = v3;
}
}
}
}
else
{
LODWORD(v3) = bug_prog_format("omodflag: missing argument", v2);
}
return v3;
}

original_code:
void do_omodflag( char *argument )
{
 PFLAG_DATA * list, *tmp = ((void *)0);
 int val;
 char arg[ 512 ];
 char arg2[ 512 ];
 char arg3[ 512 ];
 char expand[ 512 ];
 argument = one_argument( argument, expand );
 expand_arg( arg, expand );
 argument = one_argument( argument, expand );
 expand_arg( arg2, expand );
 expand_arg( arg3, argument );
 if ( arg[ 0 ] == '\0' || arg2[ 0 ] == '\0' )
 {
  bug_prog_format( "omodflag: missing argument" );
  return ;
 }
 for ( list = running_prog_env->obj->pflag_list; list; list = list->next )
  if ( ( upper_nopol[(unsigned char)(arg2[ 0 ])]) == ( upper_nopol[(unsigned char)(list->id[ 0 ])]) && !str_cmp( arg2, list->id ) )
  {
   tmp = list;
   break;
  }
 if ( !tmp )
  return ;
 if ( !str_cmp( arg, "set" ) )
 {
  if ( arg3[ 0 ] == '\0' || !is_number( arg3 ) )
   return ;
  val = atoi( arg3 );
  tmp->duration = val;
  return ;
 }
 else if ( !str_cmp( arg, "mod" ) )
 {
  if ( arg3[ 0 ] == '\0' || !is_number( arg3 ) )
   return ;
  val = atoi( arg3 );
  tmp->duration += val;
 }
 else if ( !str_cmp( arg, "rem" ) )
 {
  tmp->duration = 0;
  removeobjflag( running_prog_env->obj, tmp->id );
  return ;
 }
 return ;
}

canonical_original_code:
void do_omodflag(char *argument)
{
 struct pflag_data *list; struct pflag_data *tmp = ((void *)0);
 int val;
 char arg[512];
 char arg2[512];
 char arg3[512];
 char expand[512];
 argument = one_argument( argument, expand );
 expand_arg( arg, expand );
 argument = one_argument( argument, expand );
 expand_arg( arg2, expand );
 expand_arg( arg3, argument );
 if ( arg[ 0 ] == '\0' || arg2[ 0 ] == '\0' )
 {
  bug_prog_format( "omodflag: missing argument" );
  return ;
 }
 for ( list = running_prog_env->obj->pflag_list; list; list = list->next )
  if ( ( upper_nopol[(unsigned char)(arg2[ 0 ])]) == ( upper_nopol[(unsigned char)(list->id[ 0 ])]) && !str_cmp( arg2, list->id ) )
  {
   tmp = list;
   break;
  }
 if ( !tmp )
  return ;
 if ( !str_cmp( arg, "set" ) )
 {
  if ( arg3[ 0 ] == '\0' || !is_number( arg3 ) )
   return ;
  val = atoi( arg3 );
  tmp->duration = val;
  return ;
 }
 else if ( !str_cmp( arg, "mod" ) )
 {
  if ( arg3[ 0 ] == '\0' || !is_number( arg3 ) )
   return ;
  val = atoi( arg3 );
  tmp->duration += val;
 }
 else if ( !str_cmp( arg, "rem" ) )
 {
  tmp->duration = 0;
  removeobjflag( running_prog_env->obj, tmp->id );
  return ;
 }
 return ;
}

variable_types: struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; } *

variable_types: val int

variable_types:
expand
char [512]


decompiled_code:
__int64 __fastcall do_ostring(_BYTE *a1)
{
char v2[512]; // [rsp+0h] [rbp-200h] BYREF

if ( !*a1 )
return bug_prog_format("ostring: missing argument", a1);
expand_arg(v2, a1);
return objstring(*(_QWORD *)(running_prog_env + 32LL), v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
char v2[512]; // [rsp+0h] [rbp-200h] BYREF

if ( !*a1 )
return bug_prog_format("ostring: missing argument", a1);
expand_arg(v2, a1);
return objstring(*(_QWORD *)(running_prog_env + 32LL), v2);
}

original_code:
void do_ostring( char *argument )
{
 char arg[ 512 ];
 if ( argument[ 0 ] == '\0' )
 {
  bug_prog_format( "ostring: missing argument" );
  return ;
 }
 expand_arg( arg, argument );
 objstring( running_prog_env->obj, arg );
}

canonical_original_code:
void do_ostring(char *argument)
{
 char arg[512];
 if ( argument[ 0 ] == '\0' )
 {
  bug_prog_format( "ostring: missing argument" );
  return ;
 }
 expand_arg( arg, argument );
 objstring( running_prog_env->obj, arg );
}


decompiled_code:
__int64 do_objwear()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 v2; // rdi

result = running_prog_env;
v1 = *(_QWORD *)(running_prog_env + 32LL);
v2 = *(_QWORD *)(v1 + 40);
if ( v2 )
{
equip_char(v2, v1, (unsigned int)*(__int16 *)(v1 + 306), 0LL);
result = *(_QWORD *)(running_prog_env + 32LL);
*(_WORD *)(result + 306) = -1;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 v2; // rdi

result = running_prog_env;
v1 = *(_QWORD *)(running_prog_env + 32LL);
v2 = *(_QWORD *)(v1 + 40);
if ( v2 )
{
equip_char(v2, v1, (unsigned int)*(__int16 *)(v1 + 306), 0LL);
result = *(_QWORD *)(running_prog_env + 32LL);
*(_WORD *)(result + 306) = -1;
}
return result;
}

original_code:
void do_objwear( char *argument )
{
 if ( !running_prog_env->obj->carried_by )
  return ;
 equip_char( running_prog_env->obj->carried_by, running_prog_env->obj, running_prog_env->obj->prewear_loc, 0 );
 running_prog_env->obj->prewear_loc = -1;
}

canonical_original_code:
void do_objwear(char *argument)
{
 if ( !running_prog_env->obj->carried_by )
  return ;
 equip_char( running_prog_env->obj->carried_by, running_prog_env->obj, running_prog_env->obj->prewear_loc, 0 );
 running_prog_env->obj->prewear_loc = -1;
}


decompiled_code:
__int64 do_objunwear()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 v2; // rdi

result = running_prog_env;
v1 = *(_QWORD *)(running_prog_env + 32LL);
v2 = *(_QWORD *)(v1 + 40);
if ( v2 )
result = unequip_char(v2, v1);
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 v2; // rdi

result = running_prog_env;
v1 = *(_QWORD *)(running_prog_env + 32LL);
v2 = *(_QWORD *)(v1 + 40);
if ( v2 )
result = unequip_char(v2, v1);
return result;
}

original_code:
void do_objunwear( char *argument )
{
 if ( !running_prog_env->obj->carried_by )
  return ;
 unequip_char( running_prog_env->obj->carried_by, running_prog_env->obj );
}

canonical_original_code:
void do_objunwear(char *argument)
{
 if ( !running_prog_env->obj->carried_by )
  return ;
 unequip_char( running_prog_env->obj->carried_by, running_prog_env->obj );
}


decompiled_code:
__int64 __fastcall translate_buffer(iconv_t cd, void *dest, size_t a3)
{
size_t v5; // rbx
const void *v6; // rsi
int v7; // edx
__int64 result; // rax
int *v9; // rax
char *v10; // rax
char *inbuf; // [rsp+0h] [rbp-40h] BYREF
char *outbuf; // [rsp+8h] [rbp-38h] BYREF
size_t inbytesleft; // [rsp+10h] [rbp-30h] BYREF
size_t outbytesleft[5]; // [rsp+18h] [rbp-28h] BYREF

if ( buf_2 )
{
v5 = buf_len_1 - 1;
}
else
{
v5 = 0x1FFFFFLL;
buf_len_1 = 0x200000LL;
buf_2 = malloc(0x200000uLL);
}
if ( a3 > v5 )
{
logformat("%s, %s, %d: buffer too long, sorry.", "charset_utils.c", "translate_buffer", 48LL);
result = 0LL;
}
else
{
inbuf = (char *)dest;
outbuf = (char *)buf_2;
inbytesleft = strlen((const char *)dest);
outbytesleft[0] = v5;
if ( iconv(cd, &inbuf, &inbytesleft, &outbuf, outbytesleft) == -1LL )
{
v9 = _errno_location();
v10 = strerror(*v9);
logformat("%s, %s, %d: iconv returned -1. errno=%s.", "charset_utils.c", "translate_buffer", 66LL, v10);
result = 0LL;
}
else
{
v6 = buf_2;
v7 = (_DWORD)outbuf - (_DWORD)buf_2 + 1;
*((_BYTE *)buf_2 + (int)outbuf - (int)buf_2) = 0;
memcpy(dest, v6, v7);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(iconv_t cd, void *dest, size_t a3)
{
size_t v5; // rbx
const void *v6; // rsi
int v7; // edx
__int64 result; // rax
int *v9; // rax
char *v10; // rax
char *inbuf; // [rsp+0h] [rbp-40h] BYREF
char *outbuf; // [rsp+8h] [rbp-38h] BYREF
size_t inbytesleft; // [rsp+10h] [rbp-30h] BYREF
size_t outbytesleft[5]; // [rsp+18h] [rbp-28h] BYREF

if ( buf_2 )
{
v5 = buf_len_1 - 1;
}
else
{
v5 = 0x1FFFFFLL;
buf_len_1 = 0x200000LL;
buf_2 = malloc(0x200000uLL);
}
if ( a3 > v5 )
{
logformat("%s, %s, %d: buffer too long, sorry.", "charset_utils.c", "translate_buffer", 48LL);
result = 0LL;
}
else
{
inbuf = (char *)dest;
outbuf = (char *)buf_2;
inbytesleft = strlen((const char *)dest);
outbytesleft[0] = v5;
if ( iconv(cd, &inbuf, &inbytesleft, &outbuf, outbytesleft) == -1LL )
{
v9 = _errno_location();
v10 = strerror(*v9);
logformat("%s, %s, %d: iconv returned -1. errno=%s.", "charset_utils.c", "translate_buffer", 66LL, v10);
result = 0LL;
}
else
{
v6 = buf_2;
v7 = (_DWORD)outbuf - (_DWORD)buf_2 + 1;
*((_BYTE *)buf_2 + (int)outbuf - (int)buf_2) = 0;
memcpy(dest, v6, v7);
result = 1LL;
}
}
return result;
}

original_code:
int translate_buffer(iconv_t p_iconv,
                     char * p_buffer,
                     size_t p_buffer_len)
{
  static char * buf = ((void *)0);
  static size_t buf_len = 0;
  int copy_cnt;
  if (!buf)
    {
      buf_len = 2 * 1024 * 1024;
      buf = malloc(sizeof(char) * buf_len);
    }
  if ( p_buffer_len > buf_len-1 )
    {
      logformat ( "%s, %s, %d: buffer too long, sorry.", "charset_utils.c", __func__, 48 );
      return 0;
    }
  {
    char * buf_in = p_buffer;
    char * buf_out = buf;
    size_t buf_in_left = strlen(p_buffer);
    size_t buf_out_left = buf_len-1;
    if ( -1 == iconv( p_iconv,
                      &buf_in, &buf_in_left,
                      &buf_out, &buf_out_left ) )
      {
        logformat ( "%s, %s, %d: iconv returned -1. errno=%s.", "charset_utils.c", __func__, 66, strerror((*__errno_location ())) );
        return 0;
      }
    copy_cnt = buf_out - buf;
    buf[copy_cnt] = '\0';
  }
  {
    memcpy(p_buffer, buf, copy_cnt+1);
  }
  return 1;
}

canonical_original_code:
int translate_buffer(void *p_iconv, char *p_buffer, unsigned long p_buffer_len)
{
  static char *buf = ((void *)0);
  static unsigned long buf_len = 0;
  int copy_cnt;
  if (!buf)
    {
      buf_len = 2 * 1024 * 1024;
      buf = malloc(sizeof(char) * buf_len);
    }
  if ( p_buffer_len > buf_len-1 )
    {
      logformat ( "%s, %s, %d: buffer too long, sorry.", "charset_utils.c", __func__, 48 );
      return 0;
    }
  {
    char *buf_in = p_buffer;
    char *buf_out = buf;
    unsigned long buf_in_left = strlen(p_buffer);
    unsigned long buf_out_left = buf_len-1;
    if ( -1 == iconv( p_iconv,
                      &buf_in, &buf_in_left,
                      &buf_out, &buf_out_left ) )
      {
        logformat ( "%s, %s, %d: iconv returned -1. errno=%s.", "charset_utils.c", __func__, 66, strerror((*__errno_location ())) );
        return 0;
      }
    copy_cnt = buf_out - buf;
    buf[copy_cnt] = '\0';
  }
  {
    memcpy(p_buffer, buf, copy_cnt+1);
  }
  return 1;
}

variable_types:
buf
char *