unpack

decompiled_code:
__int64 __fastcall unpack(void *src, char **a2)
{
const char *v3; // r14
size_t v4; // rbp
size_t v5; // rbx
const char *v6; // rax
char v7; // dl
const char *v8; // rbp
__int64 v9; // r15
__int64 v10; // rax
char *v11; // rcx
int v12; // esi
__int64 v13; // rcx
char *v14; // rdx
char *v15; // rax
__int64 result; // rax

printmsg(3LL, "UnPack\n");
v3 = *(&cfg + 1);
v4 = strlen(v3);
v5 = strlen((const char *)src);
v6 = (const char *)malloc(v4 + v5 + 8);
if ( v6 )
{
v7 = *v3;
v8 = v6;
v9 = 1LL;
v10 = 1LL;
v11 = (char *)v8;
if ( *v3 != 32 )
{
do
{
v8[v10 - 1] = v7;
v12 = v10;
v13 = v10++;
v7 = v3[v10 - 1];
}
while ( v7 != 32 );
v11 = (char *)&v8[v13];
v9 = v12 + 1;
}
*v11 = 32;
v8[v9] = 0;
v14 = (char *)&v8[strlen(v8)];
*(_DWORD *)v14 = 1886221374;
v14[4] = 32;
v15 = stpcpy(v14 + 5, &v3[v9]);
*v15 = 32;
memcpy(v15 + 1, src, v5 + 1);
system(v8);
findnames(a2, "tmp");
system("delete tmp");
result = 0LL;
}
else
{
printf(0LL, "Can't allocate memory", &unk_736);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, char **a2)
{
const char *v3; // r14
size_t v4; // rbp
size_t v5; // rbx
const char *v6; // rax
char v7; // dl
const char *v8; // rbp
__int64 v9; // r15
__int64 v10; // rax
char *v11; // rcx
int v12; // esi
__int64 v13; // rcx
char *v14; // rdx
char *v15; // rax
__int64 result; // rax

printmsg(3LL, "UnPack\n");
v3 = *(&cfg + 1);
v4 = strlen(v3);
v5 = strlen((const char *)src);
v6 = (const char *)malloc(v4 + v5 + 8);
if ( v6 )
{
v7 = *v3;
v8 = v6;
v9 = 1LL;
v10 = 1LL;
v11 = (char *)v8;
if ( *v3 != 32 )
{
do
{
v8[v10 - 1] = v7;
v12 = v10;
v13 = v10++;
v7 = v3[v10 - 1];
}
while ( v7 != 32 );
v11 = (char *)&v8[v13];
v9 = v12 + 1;
}
*v11 = 32;
v8[v9] = 0;
v14 = (char *)&v8[strlen(v8)];
*(_DWORD *)v14 = 1886221374;
v14[4] = 32;
v15 = stpcpy(v14 + 5, &v3[v9]);
*v15 = 32;
memcpy(v15 + 1, src, v5 + 1);
system(v8);
func2(a2, "tmp");
system("delete tmp");
result = 0LL;
}
else
{
printf(0LL, "Can't allocate memory", &unk_736);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int unpack(char *name,struct namelist **root) {
char *buf;
int pos;
 printmsg(3,"UnPack\n");
 buf=malloc(sizeof(char)*(strlen(cfg.UNPACK)+strlen(name)+strlen(">tmp ")+3));
 if (buf==((void *)0)) {
  printf(0,"Can't allocate memory","");
  return(-1);
 }
 pos=0;
 while(cfg.UNPACK[pos]!=' ') {
  buf[pos]=cfg.UNPACK[pos];
  pos++;
 }
 buf[pos]=cfg.UNPACK[pos];
 pos++;
 buf[pos]='\0';
 strcat(buf,">tmp ");
 strcat(buf,&(cfg.UNPACK[pos]));
 strcat(buf," ");
 strcat(buf,name);
 system(buf);
 findnames(root,"tmp");
 system("delete tmp");
 return(0);
}

canonical_original_code:
int unpack(char *name, struct namelist **root) {
char *buf;
int pos;
 printmsg(3,"UnPack\n");
 buf=malloc(sizeof(char)*(strlen(cfg.UNPACK)+strlen(name)+strlen(">tmp ")+3));
 if (buf==((void *)0)) {
  printf(0,"Can't allocate memory","");
  return(-1);
 }
 pos=0;
 while(cfg.UNPACK[pos]!=' ') {
  buf[pos]=cfg.UNPACK[pos];
  pos++;
 }
 buf[pos]=cfg.UNPACK[pos];
 pos++;
 buf[pos]='\0';
 strcat(buf,">tmp ");
 strcat(buf,&(cfg.UNPACK[pos]));
 strcat(buf," ");
 strcat(buf,name);
 system(buf);
 findnames(root,"tmp");
 system("delete tmp");
 return(0);
}

variable_types: struct namelist { char name[13]; struct namelist *next; } **

variable_types: pos int


extractpackets

repo: ricojansen/packman

decompiled_code:
__int64 __fastcall extractpackets(__int64 a1, __int64 a2, __int64 a3)
{
const char *v5; // rsi
char *v6; // rax
char *v7; // rbp
char *v8; // rax
const char *v9; // rsi
char *v10; // rax
const char *v11; // rsi
char *src; // [rsp+8h] [rbp-100h] BYREF
char v14[64]; // [rsp+10h] [rbp-F8h] BYREF
__int64 v15; // [rsp+50h] [rbp-B8h]
__int64 v16; // [rsp+58h] [rbp-B0h]
char dest[168]; // [rsp+60h] [rbp-A8h] BYREF

v5 = *(&cfg + 3);
v16 = 0LL;
v15 = 0LL;
src = 0LL;
if ( v5 )
{
v6 = stpcpy(dest, v5);
strcpy(v6, *(const char **)(a1 + 16));
}
else
{
strcpy(dest, *(const char **)(a1 + 16));
}
unpack(dest, &src);
v7 = src;
if ( src )
{
do
{
sprintf(dest, "\nProcessing : %s\n", v7);
printmsg(1LL, dest);
v11 = *(&cfg + 3);
if ( v11 )
{
v8 = stpcpy(dest, v11);
strcpy(v8, v7);
}
else
{
strcpy(dest, v7);
}
readpacket(dest, v14);
modifypacket(v14, a2, a3);
writepacket(dest, v14);
v9 = *(&cfg + 7);
if ( v9 )
{
v10 = stpcpy(dest, v9);
strcpy(v10, v7);
writepacket(dest, v14);
}
cleanuppacket(v14);
v7 = (char *)*((_QWORD *)v7 + 2);
}
while ( v7 );
v7 = src;
}
cleanupnamelist(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
const char *v5; // rsi
char *v6; // rax
char *v7; // rbp
char *v8; // rax
const char *v9; // rsi
char *v10; // rax
const char *v11; // rsi
char *src; // [rsp+8h] [rbp-100h] BYREF
char v14[64]; // [rsp+10h] [rbp-F8h] BYREF
__int64 v15; // [rsp+50h] [rbp-B8h]
__int64 v16; // [rsp+58h] [rbp-B0h]
char dest[168]; // [rsp+60h] [rbp-A8h] BYREF

v5 = *(&cfg + 3);
v16 = 0LL;
v15 = 0LL;
src = 0LL;
if ( v5 )
{
v6 = stpcpy(dest, v5);
strcpy(v6, *(const char **)(a1 + 16));
}
else
{
strcpy(dest, *(const char **)(a1 + 16));
}
func3(dest, &src);
v7 = src;
if ( src )
{
do
{
sprintf(dest, "\nProcessing : %s\n", v7);
printmsg(1LL, dest);
v11 = *(&cfg + 3);
if ( v11 )
{
v8 = stpcpy(dest, v11);
strcpy(v8, v7);
}
else
{
strcpy(dest, v7);
}
readpacket(dest, v14);
modifypacket(v14, a2, a3);
writepacket(dest, v14);
v9 = *(&cfg + 7);
if ( v9 )
{
v10 = stpcpy(dest, v9);
strcpy(v10, v7);
writepacket(dest, v14);
}
cleanuppacket(v14);
v7 = (char *)*((_QWORD *)v7 + 2);
}
while ( v7 );
v7 = src;
}
cleanupnamelist(v7);
return 0LL;
}

original_code:
int extractpackets(char *argv[],struct reroutetab *rrt,struct kludges *kl) {
struct packet pakt;
struct namelist *root,*wlk;
char txt[128];
 pakt.thread=((void *)0);
 pakt.root=((void *)0);
 root=((void *)0);
 if (cfg.INBOUND!=((void *)0)) {
  strcpy(txt,cfg.INBOUND);
  strcat(txt,argv[2]);
 } else {
  strcpy(txt,argv[2]);
 }
 unpack(txt,&root);
 wlk=root;
 while(wlk!=((void *)0)) {
  sprintf(txt,"\nProcessing : %s\n",wlk->name);
  printmsg(1,txt);
  if (cfg.INBOUND!=((void *)0)) {
   strcpy(txt,cfg.INBOUND);
   strcat(txt,wlk->name);
  } else {
   strcpy(txt,wlk->name);
  }
  readpacket(txt,&pakt);
  modifypacket(&pakt,rrt,kl);
  writepacket(txt,&pakt);
  if (cfg.BACKUP!=((void *)0)) {
   strcpy(txt,cfg.BACKUP);
   strcat(txt,wlk->name);
   writepacket(txt,&pakt);
  }
  cleanuppacket(&pakt);
  wlk=wlk->next;
 }
 cleanupnamelist(root);
 return(0);
}

canonical_original_code:
int extractpackets(char *argv[], struct reroutetab *rrt, struct kludges *kl) {
struct packet pakt;
struct namelist *root; struct namelist *wlk;
char txt[128];
 pakt.thread=((void *)0);
 pakt.root=((void *)0);
 root=((void *)0);
 if (cfg.INBOUND!=((void *)0)) {
  strcpy(txt,cfg.INBOUND);
  strcat(txt,argv[2]);
 } else {
  strcpy(txt,argv[2]);
 }
 unpack(txt,&root);
 wlk=root;
 while(wlk!=((void *)0)) {
  sprintf(txt,"\nProcessing : %s\n",wlk->name);
  printmsg(1,txt);
  if (cfg.INBOUND!=((void *)0)) {
   strcpy(txt,cfg.INBOUND);
   strcat(txt,wlk->name);
  } else {
   strcpy(txt,wlk->name);
  }
  readpacket(txt,&pakt);
  modifypacket(&pakt,rrt,kl);
  writepacket(txt,&pakt);
  if (cfg.BACKUP!=((void *)0)) {
   strcpy(txt,cfg.BACKUP);
   strcat(txt,wlk->name);
   writepacket(txt,&pakt);
  }
  cleanuppacket(&pakt);
  wlk=wlk->next;
 }
 cleanupnamelist(root);
 return(0);
}

variable_types:
argv
char *[]

variable_types: struct reroutetab { struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *orgroot; struct rrlist *dstroot; } *

variable_types: struct kludges { struct kludgelist { struct kludgelist *next; struct kludge { char *kludge; char *spec; char *repl; } klg; } *root; } *

variable_types: struct packet { struct PacketHeader { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char yearLO; unsigned char yearHI; unsigned char monthLO; unsigned char monthHI; unsigned char dayLO; unsigned char dayHI; unsigned char hourLO; unsigned char hourHI; unsigned char minuteLO; unsigned char minuteHI; unsigned char secondLO; unsigned char secondHI; unsigned char baudLO; unsigned char baudHI; unsigned char ID1; unsigned char ID2; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char prodcode; unsigned char serialno; unsigned char password[8]; unsigned char origZoneLO; unsigned char origZoneHI; unsigned char destZoneLO; unsigned char destZoneHI; unsigned char fill[20]; } pkh; struct msglist { struct msglist *next; struct PackedMessage { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char AttributeLO; unsigned char AttributeHI; unsigned char costLO; unsigned char costHI; unsigned char DateTime[20]; } pmsg; char FromUser[36]; char ToUser[36]; char Subject[72]; char *Text; } *root; }

variable_types: struct namelist { char name[13]; struct namelist *next; } *

variable_types:
txt
char [128]

return_type: int

user_defined_types: struct packet { struct PacketHeader pkh; struct msglist *root; }

user_defined_types: struct reroutetab { struct rrlist *orgroot; struct rrlist *dstroot; }

user_defined_types: struct kludges { struct kludgelist *root; }

user_defined_types: struct msglist { struct msglist *next; struct PackedMessage pmsg; char FromUser[36]; char ToUser[36]; char Subject[72]; char *Text; }

user_defined_types: struct rrlist { struct rrlist *next; struct fidaddr in; }

user_defined_types: struct kludgelist { struct kludgelist *next; struct kludge klg; }


decide

decompiled_code:
__int64 __fastcall decide(int a1, int a2, int a3)
{
int v3; // eax
__int64 result; // rax

if ( a1 == -1 )
{
LOBYTE(v3) = a2 != -1;
result = (unsigned int)(v3 + 1);
}
else
{
LOBYTE(v3) = a1 == a3;
result = (unsigned int)(2 * v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
int v3; // eax
__int64 result; // rax

if ( a1 == -1 )
{
LOBYTE(v3) = a2 != -1;
result = (unsigned int)(v3 + 1);
}
else
{
LOBYTE(v3) = a1 == a3;
result = (unsigned int)(2 * v3);
}
return result;
}

original_code:
char decide(int in,int out,int chg) {
char match;
 match=(0);
 if (in==(-1)) {
  if (out==(-1)) {
   match=(1);
  } else {
   match=(2);
  }
 } else {
  if (chg==in) {
   match=(2);
  }
 }
 return(match);
}

canonical_original_code:
char decide(int in, int out, int chg) {
char match;
 match=(0);
 if (in==(-1)) {
  if (out==(-1)) {
   match=(1);
  } else {
   match=(2);
  }
 } else {
  if (chg==in) {
   match=(2);
  }
 }
 return(match);
}

variable_types: in int

variable_types: out int

variable_types: chg int

variable_types: match char

return_type: char


dochange

original_code:
int dochange(struct fidaddr *chg,struct rrlist *root) {
int rtn=0;
char txt[255];
char matchZone,matchNet,matchNode,matchPoint;
 printmsg(3,"DoChange\n");
 while(root!=((void *)0) && rtn==0) {
  matchZone=matchNet=matchNode=matchPoint=(0);
  matchZone=decide(root->in.Zone,root->out.Zone,chg->Zone);
  matchNet=decide(root->in.Net,root->out.Net,chg->Net);
  matchNode=decide(root->in.Node,root->out.Node,chg->Node);
  matchPoint=decide(root->in.Point,root->out.Point,chg->Point);
  if (matchZone!=(0) && matchNet!=(0) && matchNode!=(0) && matchPoint!=(0)) {
   sprintf(txt,"Address modified from : %d:%d/%d.%d",chg->Zone,chg->Net,chg->Node,chg->Point);
   printmsg(1,txt);
   if (matchZone==(2)) {
    chg->Zone=root->out.Zone;
   }
   if (matchNet==(2)) {
    chg->Net=root->out.Net;
   }
   if (matchNode==(2)) {
    chg->Node=root->out.Node;
   }
   if (matchPoint==(2)) {
    chg->Point=root->out.Point;
   }
   sprintf(txt," to %d:%d/%d.%d\n",chg->Zone,chg->Net,chg->Node,chg->Point);
   printmsg(1,txt);
   rtn=1;
  }
  root=root->next;
 }
 return(rtn);
}

canonical_original_code:
int dochange(struct fidaddr *chg, struct rrlist *root) {
int rtn = 0;
char txt[255];
char matchZone; char matchNet; char matchNode; char matchPoint;
 printmsg(3,"DoChange\n");
 while(root!=((void *)0) && rtn==0) {
  matchZone=matchNet=matchNode=matchPoint=(0);
  matchZone=decide(root->in.Zone,root->out.Zone,chg->Zone);
  matchNet=decide(root->in.Net,root->out.Net,chg->Net);
  matchNode=decide(root->in.Node,root->out.Node,chg->Node);
  matchPoint=decide(root->in.Point,root->out.Point,chg->Point);
  if (matchZone!=(0) && matchNet!=(0) && matchNode!=(0) && matchPoint!=(0)) {
   sprintf(txt,"Address modified from : %d:%d/%d.%d",chg->Zone,chg->Net,chg->Node,chg->Point);
   printmsg(1,txt);
   if (matchZone==(2)) {
    chg->Zone=root->out.Zone;
   }
   if (matchNet==(2)) {
    chg->Net=root->out.Net;
   }
   if (matchNode==(2)) {
    chg->Node=root->out.Node;
   }
   if (matchPoint==(2)) {
    chg->Point=root->out.Point;
   }
   sprintf(txt," to %d:%d/%d.%d\n",chg->Zone,chg->Net,chg->Node,chg->Point);
   printmsg(1,txt);
   rtn=1;
  }
  root=root->next;
 }
 return(rtn);
}

variable_types: struct fidaddr { int Zone; int Net; int Node; int Point; } *

variable_types: struct rrlist { struct rrlist *next; struct fidaddr in; } *

variable_types: rtn int

variable_types:
txt
char [255]

variable_types: matchZone char

variable_types: matchNet char

variable_types: matchNode char

variable_types: matchPoint char


changeaddr

decompiled_code:
__int64 __fastcall changeaddr(__int64 a1, unsigned int a2, unsigned int a3, __int64 *a4, unsigned int *a5, int a6)
{
char *v11; // rax
char *v12; // rbp

printmsg(3LL, "ChangeAddr\n");
if ( (unsigned int)dochange(a5, a4) == 1 )
{
v11 = (char *)malloc(0x19uLL);
*v11 = 0;
v12 = v11;
if ( a6 <= 7 )
{
switch ( a6 )
{
case 2:
sprintf(v11, "%d/%d", a5[1], a5[2]);
goto LABEL_8;
case 3:
sprintf(v11, "%d:%d/%d", *a5, a5[1], a5[2]);
goto LABEL_8;
case 1:
sprintf(v11, "%d", a5[2]);
goto LABEL_8;
}
}
else
{
switch ( a6 )
{
case 11:
sprintf(v11, "%d/%d.%d", a5[1], a5[2], a5[3]);
goto LABEL_8;
case 12:
sprintf(v11, "%d:%d/%d.%d", *a5, a5[1], a5[2], a5[3]);
goto LABEL_8;
case 10:
sprintf(v11, "%d.%d", a5[2], a5[3]);
goto LABEL_8;
}
}
printmsg(0LL, "Address rebuild error\n");
LABEL_8:
replacestring(a1, a3, a2, v12);
free(v12);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, unsigned int a3, __int64 *a4, unsigned int *a5, int a6)
{
char *v11; // rax
char *v12; // rbp

printmsg(3LL, "ChangeAddr\n");
if ( (unsigned int)func1(a5, a4) == 1 )
{
v11 = (char *)malloc(0x19uLL);
*v11 = 0;
v12 = v11;
if ( a6 <= 7 )
{
switch ( a6 )
{
case 2:
sprintf(v11, "%d/%d", a5[1], a5[2]);
goto LABEL_8;
case 3:
sprintf(v11, "%d:%d/%d", *a5, a5[1], a5[2]);
goto LABEL_8;
case 1:
sprintf(v11, "%d", a5[2]);
goto LABEL_8;
}
}
else
{
switch ( a6 )
{
case 11:
sprintf(v11, "%d/%d.%d", a5[1], a5[2], a5[3]);
goto LABEL_8;
case 12:
sprintf(v11, "%d:%d/%d.%d", *a5, a5[1], a5[2], a5[3]);
goto LABEL_8;
case 10:
sprintf(v11, "%d.%d", a5[2], a5[3]);
goto LABEL_8;
}
}
printmsg(0LL, "Address rebuild error\n");
LABEL_8:
replacestring(a1, a3, a2, v12);
free(v12);
}
return 0LL;
}

original_code:
int changeaddr(char **text,int pos,int lentxt,struct rrlist *root,struct fidaddr *fd,int type) {
 printmsg(3,"ChangeAddr\n");
 if (dochange(fd,root)==1) {
  char *buf;
  buf=(char *)malloc(sizeof(char)*25);
  buf[0]='\0';
  if (type<8) {
   switch(type) {
    case 3 : sprintf(buf,"%d:%d/%d",fd->Zone,fd->Net,fd->Node);
       break;
    case 2 : sprintf(buf,"%d/%d",fd->Net,fd->Node);
       break;
    case 1 : sprintf(buf,"%d",fd->Node);
       break;
    default: printmsg(0,"Address rebuild error\n");
       break;
   }
  } else {
   type-=8;
   switch(type) {
    case 4 : sprintf(buf,"%d:%d/%d.%d",fd->Zone,fd->Net,fd->Node,fd->Point);
       break;
    case 3 : sprintf(buf,"%d/%d.%d",fd->Net,fd->Node,fd->Point);
       break;
    case 2 : sprintf(buf,"%d.%d",fd->Node,fd->Point);
       break;
    default: printmsg(0,"Address rebuild error\n");
       break;
   }
  }
  replacestring(text,lentxt,pos,buf);
  free((void *)buf);
 }
 return(0);
}

canonical_original_code:
int changeaddr(char **text, int pos, int lentxt, struct rrlist *root, struct fidaddr *fd, int type) {
 printmsg(3,"ChangeAddr\n");
 if (dochange(fd,root)==1) {
  char *buf;
  buf=(char *)malloc(sizeof(char)*25);
  buf[0]='\0';
  if (type<8) {
   switch(type) {
    case 3 : sprintf(buf,"%d:%d/%d",fd->Zone,fd->Net,fd->Node);
       break;
    case 2 : sprintf(buf,"%d/%d",fd->Net,fd->Node);
       break;
    case 1 : sprintf(buf,"%d",fd->Node);
       break;
    default: printmsg(0,"Address rebuild error\n");
       break;
   }
  } else {
   type-=8;
   switch(type) {
    case 4 : sprintf(buf,"%d:%d/%d.%d",fd->Zone,fd->Net,fd->Node,fd->Point);
       break;
    case 3 : sprintf(buf,"%d/%d.%d",fd->Net,fd->Node,fd->Point);
       break;
    case 2 : sprintf(buf,"%d.%d",fd->Node,fd->Point);
       break;
    default: printmsg(0,"Address rebuild error\n");
       break;
   }
  }
  replacestring(text,lentxt,pos,buf);
  free((void *)buf);
 }
 return(0);
}

variable_types:
text
char **

variable_types: pos int

variable_types: lentxt int

variable_types: struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *

variable_types:
fd
struct fidaddr *

variable_types: type int

variable_types:
buf
char *


printmsg

decompiled_code:
__int64 __fastcall printmsg(int a1, const char *a2)
{
if ( cfg[10] > a1 )
fputs(a2, stderr);
if ( !logfile || cfg[11] <= a1 )
return 0LL;
fputs(a2, logfile);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char *a2)
{
if ( cfg[10] > a1 )
fputs(a2, stderr);
if ( !logfile || cfg[11] <= a1 )
return 0LL;
fputs(a2, logfile);
return 0LL;
}

original_code:
int printmsg(int level,char *msg) {
 if (cfg.VERBOSE>level) {
  fprintf(stderr,"%s",msg);
 }
 if (logfile!=((void *)0) && cfg.LOGLEVEL>level) {
  fprintf(logfile,"%s",msg);
 }
 return(0);
}

canonical_original_code:
int printmsg(int level, char *msg) {
 if (cfg.VERBOSE>level) {
  fprintf(stderr,"%s",msg);
 }
 if (logfile!=((void *)0) && cfg.LOGLEVEL>level) {
  fprintf(logfile,"%s",msg);
 }
 return(0);
}

variable_types: level int

variable_types:
msg
char *


replacestring

original_code:
int replacestring(char **text,int replacelen,int pos,char *string) {
int q,l,shift,len;
char *tmp,*ps;
 printmsg(3,"Replacestring\n");
 len=strlen(string);
 shift=len-replacelen;
 ps=(*text)+pos;
 if (shift!=0) {
  if (shift<0) {
   l=strlen(ps+replacelen);
   for (q=0;q<=l;q++) ps[len+q]=ps[replacelen+q];
   tmp=realloc(*text,strlen(*text)+1);
   if (tmp==((void *)0)) {
    printmsg(0,"Can't reallocate memory\n");
    return(-1);
   }
   *text=tmp;
   ps=*text+pos;
  } else {
   tmp=realloc(*text,strlen(*text)+shift+1);
   if (tmp==((void *)0)) {
    printmsg(0,"Can't reallocate memory\n");
    return(-1);
   }
   *text=tmp;
   ps=*text+pos;
   l=strlen(ps+replacelen);
   for (q=l;q>=0;q--) ps[q+len]=ps[q+replacelen];
  }
 }
 for (q=0;q<len;q++) ps[q]=string[q];
 return(0);
}

canonical_original_code:
int replacestring(char **text, int replacelen, int pos, char *string) {
int q; int l; int shift; int len;
char *tmp; char *ps;
 printmsg(3,"Replacestring\n");
 len=strlen(string);
 shift=len-replacelen;
 ps=(*text)+pos;
 if (shift!=0) {
  if (shift<0) {
   l=strlen(ps+replacelen);
   for (q=0;q<=l;q++) ps[len+q]=ps[replacelen+q];
   tmp=realloc(*text,strlen(*text)+1);
   if (tmp==((void *)0)) {
    printmsg(0,"Can't reallocate memory\n");
    return(-1);
   }
   *text=tmp;
   ps=*text+pos;
  } else {
   tmp=realloc(*text,strlen(*text)+shift+1);
   if (tmp==((void *)0)) {
    printmsg(0,"Can't reallocate memory\n");
    return(-1);
   }
   *text=tmp;
   ps=*text+pos;
   l=strlen(ps+replacelen);
   for (q=l;q>=0;q--) ps[q+len]=ps[q+replacelen];
  }
 }
 for (q=0;q<len;q++) ps[q]=string[q];
 return(0);
}

variable_types: replacelen int

variable_types:
string
char *

variable_types: q int

variable_types: l int

variable_types: shift int

variable_types: len int

variable_types:
tmp
char *

variable_types:
ps
char *


getnum

original_code:
int getnum(int *num,char **line) {
 if ((((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short int) _ISalnum) && !((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short int) _ISalpha))) {
  *num=(int)(**line-'0');
  (*line)++;
  while((((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short int) _ISalnum) && !((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short int) _ISalpha))) {
   *num=*num*10+(int)(**line-'0');
   (*line)++;
  }
  return(0);
 } else {
  return(-1);
 }
}

canonical_original_code:
int getnum(int *num, char **line) {
 if ((((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short) _ISalnum) && !((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short) _ISalpha))) {
  *num=(int)(**line-'0');
  (*line)++;
  while((((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short) _ISalnum) && !((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short) _ISalpha))) {
   *num=*num*10+(int)(**line-'0');
   (*line)++;
  }
  return(0);
 } else {
  return(-1);
 }
}

variable_types:
num
int *

variable_types:
line
char **


strtoupper

decompiled_code:
__int64 __fastcall strtoupper(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( (_BYTE)v1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( (_BYTE)v1 );
}
return 0LL;
}

original_code:
int strtoupper(char *str) {
 while(*str!='\0') {
  *str=toupper(*str);
  str++;
 }
 return(0);
}

variable_types:
str
char *


cleanup

decompiled_code:
__int64 __fastcall cleanup(__int64 a1, _QWORD **a2)
{
_QWORD *v3; // rdi
_QWORD *i; // rdi
_QWORD *v5; // rbx
_QWORD *v6; // rbp
void *v7; // rdi
void *v8; // rdi

v3 = *(_QWORD **)a1;
if ( !v3 )
goto LABEL_5;
do
{
*(_QWORD *)a1 = *v3;
free(v3);
v3 = *(_QWORD **)a1;
}
while ( *(_QWORD *)a1 );
for ( i = *(_QWORD **)(a1 + 16); i; i = *(_QWORD **)(a1 + 16) )
{
*(_QWORD *)(a1 + 16) = *i;
free(i);
LABEL_5:
;
}
v5 = *a2;
while ( v5 )
{
v6 = v5;
v5 = (_QWORD *)*v5;
free((void *)v6[1]);
v7 = (void *)v6[2];
if ( v7 )
free(v7);
v8 = (void *)v6[3];
if ( v8 && v8 != (void *)NIL )
free(v8);
free(v6);
}
return 0LL;
}

original_code:
int cleanup(struct reroutetab *rrt,struct kludges *kl) {
struct rrlist *wlk;
struct kludgelist *walkto,*wlkto;
 while(rrt->orgroot!=((void *)0)) {
  wlk=rrt->orgroot;
  rrt->orgroot=rrt->orgroot->next;
  free((void *)wlk);
 }
 while(rrt->dstroot!=((void *)0)) {
  wlk=rrt->dstroot;
  rrt->dstroot=rrt->dstroot->next;
  free((void *)wlk);
 }
 walkto=kl->root;
 while(walkto!=((void *)0)) {
  wlkto=walkto;
  walkto=walkto->next;
  free((void *)wlkto->klg.kludge);
  if (wlkto->klg.spec!=((void *)0)) {
   free((void *)wlkto->klg.spec);
  }
  if (wlkto->klg.repl!=((void *)0) && wlkto->klg.repl!=NIL) {
   free((void *)wlkto->klg.repl);
  }
  free((void *)wlkto);
 }
 return(0);
}

canonical_original_code:
int cleanup(struct reroutetab *rrt, struct kludges *kl) {
struct rrlist *wlk;
struct kludgelist *walkto; struct kludgelist *wlkto;
 while(rrt->orgroot!=((void *)0)) {
  wlk=rrt->orgroot;
  rrt->orgroot=rrt->orgroot->next;
  free((void *)wlk);
 }
 while(rrt->dstroot!=((void *)0)) {
  wlk=rrt->dstroot;
  rrt->dstroot=rrt->dstroot->next;
  free((void *)wlk);
 }
 walkto=kl->root;
 while(walkto!=((void *)0)) {
  wlkto=walkto;
  walkto=walkto->next;
  free((void *)wlkto->klg.kludge);
  if (wlkto->klg.spec!=((void *)0)) {
   free((void *)wlkto->klg.spec);
  }
  if (wlkto->klg.repl!=((void *)0) && wlkto->klg.repl!=NIL) {
   free((void *)wlkto->klg.repl);
  }
  free((void *)wlkto);
 }
 return(0);
}

variable_types: struct reroutetab { struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *orgroot; struct rrlist *dstroot; } *

variable_types: struct kludges { struct kludgelist { struct kludgelist *next; struct kludge { char *kludge; char *spec; char *repl; } klg; } *root; } *


cleanuppacket

decompiled_code:
__int64 __fastcall cleanuppacket(__int64 a1)
{
void **v1; // rbx
void **v2; // rbp
__int64 result; // rax

v1 = *(void ***)(a1 + 64);
while ( v1 )
{
v2 = v1;
v1 = (void **)*v1;
free(v2[23]);
free(v2);
}
*(_QWORD *)(a1 + 64) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 72) = 0LL;
return result;
}

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

v1 = *(void ***)(a1 + 64);
while ( v1 )
{
v2 = v1;
v1 = (void **)*v1;
free(v2[23]);
free(v2);
}
*(_QWORD *)(a1 + 64) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 72) = 0LL;
return result;
}

original_code:
int cleanuppacket(struct packet *pakt) {
struct msglist *walk,*ttmp;
 walk=pakt->root;
 while(walk!=((void *)0)) {
  ttmp=walk;
  walk=walk->next;
  free((void *)ttmp->Text);
  free((void *)ttmp);
 }
 pakt->root=((void *)0);
 pakt->thread=((void *)0);
 return(0);
}

canonical_original_code:
int cleanuppacket(struct packet *pakt) {
struct msglist *walk; struct msglist *ttmp;
 walk=pakt->root;
 while(walk!=((void *)0)) {
  ttmp=walk;
  walk=walk->next;
  free((void *)ttmp->Text);
  free((void *)ttmp);
 }
 pakt->root=((void *)0);
 pakt->thread=((void *)0);
 return(0);
}

variable_types: struct packet { struct PacketHeader { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char yearLO; unsigned char yearHI; unsigned char monthLO; unsigned char monthHI; unsigned char dayLO; unsigned char dayHI; unsigned char hourLO; unsigned char hourHI; unsigned char minuteLO; unsigned char minuteHI; unsigned char secondLO; unsigned char secondHI; unsigned char baudLO; unsigned char baudHI; unsigned char ID1; unsigned char ID2; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char prodcode; unsigned char serialno; unsigned char password[8]; unsigned char origZoneLO; unsigned char origZoneHI; unsigned char destZoneLO; unsigned char destZoneHI; unsigned char fill[20]; } pkh; struct msglist { struct msglist *next; struct PackedMessage { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char AttributeLO; unsigned char AttributeHI; unsigned char costLO; unsigned char costHI; unsigned char DateTime[20]; } pmsg; char FromUser[36]; char ToUser[36]; char Subject[72]; char *Text; } *root; } *


cleanupnamelist

decompiled_code:
__int64 __fastcall cleanupnamelist(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
while ( v1 );
return 0LL;
}

original_code:
int cleanupnamelist(struct namelist *root) {
struct namelist *tmp;
 while(root!=((void *)0)) {
  tmp=root;
  root=root->next;
  free(tmp);
 }
 return(0);
}

variable_types: struct namelist { char name[13]; struct namelist *next; } *


parseaddress

original_code:
int parseaddress(char *line,struct fidaddr *fid,char wild) {
char symbol;
int transport,type;
 printmsg(3,"ParseAddress\n");
 fid->Zone=fid->Net=fid->Node=fid->Point=0;
 if (wild==(00) || *line!='*') {
  if (getnum(&transport,&line)==-1) {
   goto NUMERROR;
  }
 } else {
  transport=(-1);
  line++;
 }
 START: symbol=*line;line++; keepSTART:
     type=1;
     switch(symbol) {
      case ':' :
         fid->Zone=transport;
         if (*line!='*' || wild==(00)) {
          if (getnum(&transport,&line)==-1) {
           goto NUMERROR;
          }
         } else {
          transport=(-1);
          line++;
         }
         goto ADDR3OR4;
      case '/' :
         fid->Net=transport;
         if (*line!='*' || wild==(00)) {
          if (getnum(&transport,&line)==-1) {
           goto NUMERROR;
          }
         } else {
          transport=(-1);
          line++;
         }
         goto ADDR2OR3;
      case '.' :
         fid->Node=transport;
         if (*line!='*' || wild==(00)) {
          if (getnum(&transport,&line)==-1) {
           goto NUMERROR;
          }
         } else {
          transport=(-1);
          line++;
         }
         goto ADDR2;
      default:
         fid->Node=transport;
         goto END;
     }
 ADDR3OR4: symbol=*line;line++; keepADDR3OR4:type+=1;
     if (symbol=='/') {
      fid->Net=transport;
      if (*line!='*' || wild==(00)) {
       if (getnum(&transport,&line)==-1) {
        goto NUMERROR;
       }
      } else {
       transport=(-1);
       line++;
      }
      goto ADDR2OR3;
     } else {
      goto ERROR;
     }
 ADDR2OR3: symbol=*line;line++; keepADDR2OR3:type+=1;
     if (symbol=='.') {
      fid->Node=transport;
      if (*line!='*' || wild==(00)) {
       if (getnum(&transport,&line)==-1) {
        goto NUMERROR;
       }
      } else {
       transport=(-1);
       line++;
      }
      goto ADDR2;
     } else {
      fid->Node=transport;
      goto END;
     }
 ADDR2: symbol=*line;line++; keepADDR2: type+=1;
     type+=8;
     fid->Point=transport;
     goto END;
 ERROR: symbol=*line;line++; keepERROR: printmsg(0,"Parse error malformed address\n");
     type=-1;
     goto END;
 NUMERROR: symbol=*line;line++; keepNUMERROR:printmsg(0,"Parse error invalid address\n");
     type=-1;
     goto END;
 END: symbol=*line;line++; keepEND: return(type);
}

canonical_original_code:
int parseaddress(char *line, struct fidaddr *fid, char wild) {
char symbol;
int transport; int type;
 printmsg(3,"ParseAddress\n");
 fid->Zone=fid->Net=fid->Node=fid->Point=0;
 if (wild==(00) || *line!='*') {
  if (getnum(&transport,&line)==-1) {
   goto NUMERROR;
  }
 } else {
  transport=(-1);
  line++;
 }
 START: symbol=*line;line++; keepSTART:
     type=1;
     switch(symbol) {
      case ':' :
         fid->Zone=transport;
         if (*line!='*' || wild==(00)) {
          if (getnum(&transport,&line)==-1) {
           goto NUMERROR;
          }
         } else {
          transport=(-1);
          line++;
         }
         goto ADDR3OR4;
      case '/' :
         fid->Net=transport;
         if (*line!='*' || wild==(00)) {
          if (getnum(&transport,&line)==-1) {
           goto NUMERROR;
          }
         } else {
          transport=(-1);
          line++;
         }
         goto ADDR2OR3;
      case '.' :
         fid->Node=transport;
         if (*line!='*' || wild==(00)) {
          if (getnum(&transport,&line)==-1) {
           goto NUMERROR;
          }
         } else {
          transport=(-1);
          line++;
         }
         goto ADDR2;
      default:
         fid->Node=transport;
         goto END;
     }
 ADDR3OR4: symbol=*line;line++; keepADDR3OR4:type+=1;
     if (symbol=='/') {
      fid->Net=transport;
      if (*line!='*' || wild==(00)) {
       if (getnum(&transport,&line)==-1) {
        goto NUMERROR;
       }
      } else {
       transport=(-1);
       line++;
      }
      goto ADDR2OR3;
     } else {
      goto ERROR;
     }
 ADDR2OR3: symbol=*line;line++; keepADDR2OR3:type+=1;
     if (symbol=='.') {
      fid->Node=transport;
      if (*line!='*' || wild==(00)) {
       if (getnum(&transport,&line)==-1) {
        goto NUMERROR;
       }
      } else {
       transport=(-1);
       line++;
      }
      goto ADDR2;
     } else {
      fid->Node=transport;
      goto END;
     }
 ADDR2: symbol=*line;line++; keepADDR2: type+=1;
     type+=8;
     fid->Point=transport;
     goto END;
 ERROR: symbol=*line;line++; keepERROR: printmsg(0,"Parse error malformed address\n");
     type=-1;
     goto END;
 NUMERROR: symbol=*line;line++; keepNUMERROR:printmsg(0,"Parse error invalid address\n");
     type=-1;
     goto END;
 END: symbol=*line;line++; keepEND: return(type);
}

variable_types:
line
char *

variable_types: struct fidaddr { int Zone; int Net; int Node; int Point; } *

variable_types: wild char

variable_types: symbol char

variable_types: transport int

variable_types: type int


parsespec

original_code:
int parsespec(char **text,int *pos,struct kludge *klg,struct reroutetab *rrt) {
char symbol;
char *line;
char *rep;
int repeat,type=0,keep=0,len;
 printmsg(3,"ParseSpec\n");
 line=klg->spec;
 rep=klg->repl;
 LOOP: symbol=*line;line++; keepLOOP: switch(symbol) {
      case '%' : goto TOKEN;
      case '\0': goto keepEND;
      default : if ((*text)[*pos]!=symbol) {
         printmsg(0,"Kludge spefication doesn't match\n");
         type=-1;
         goto keepEND;
           } else {
         rep++;
         (*pos)++;
         goto LOOP;
           }
     }
 TOKEN: symbol=*line;line++; keepTOKEN: if ((((*__ctype_b_loc ())[(int) ((symbol))] & (unsigned short int) _ISalnum) && !((*__ctype_b_loc ())[(int) ((symbol))] & (unsigned short int) _ISalpha))) {
      line--;
      getnum(&repeat,&line);
      goto TYPE;
     } else {
      switch(symbol) {
       case '%' : if ((*text)[*pos]!=symbol) {
          printmsg(0,"Kludge specification doesn't match\n");
          type=-1;
          goto keepEND;
            } else {
          rep++;
          (*pos)++;
          keep=0;
          goto LOOP;
            }
       case 's' : if (!keep) {
             len=0;
             while((*text)[*pos+len]!=(0x0D)) len++;
             replacestring(text,len,*pos,rep);
            }
            keep=0;
            goto keepEND;
       case 'k' : keep=1;
            goto TOKEN;
       default: printmsg(0,"Invalid kludge specification\n");
            type=-1;
            goto keepEND;
      }
     }
 TYPE: symbol=*line;line++; keepTYPE: switch(symbol) {
      case 'a' : if (repeat==0) { char *oldrep;
          oldrep=rep;
          while((*text)[*pos]!=(0x0D)) {
           doaddress(text,pos,&rep,rrt,keep);
           rep=oldrep;
           if ((*text)[*pos]!=(0x0D)) {
            while(!(((*__ctype_b_loc ())[(int) (((*text)[*pos]))] & (unsigned short int) _ISalnum) && !((*__ctype_b_loc ())[(int) (((*text)[*pos]))] & (unsigned short int) _ISalpha))) (*pos)++;
           }
          }
           } else {
          while(repeat--) {
           doaddress(text,pos,&rep,rrt,keep);
          }
           }
           keep=0;
           goto LOOP;
      case 'w' : if (repeat==0) { char *oldrep;
          oldrep=rep;
          while(*rep!='\0') {
           doword(text,pos,&rep,keep);
           rep=oldrep;
          }
           } else {
          while(repeat--) {
           doword(text,pos,&rep,keep);
          }
           }
           keep=0;
           goto LOOP;
      case 'n' : if (repeat==0) { char *oldrep;
          oldrep=rep;
          while(*rep!='\0') {
           donum(text,pos,&rep,keep);
           rep=oldrep;
          }
           } else {
          while(repeat--) {
           donum(text,pos,&rep,keep);
          }
           }
           keep=0;
           goto LOOP;
      default: keep=0;
           printmsg(0,"Unknown token in kludge specification\n");
           goto LOOP;
     }
 END: symbol=*line;line++; keepEND: return(type);
}

canonical_original_code:
int parsespec(char **text, int *pos, struct kludge *klg, struct reroutetab *rrt) {
char symbol;
char *line;
char *rep;
int repeat; int type = 0; int keep = 0; int len;
 printmsg(3,"ParseSpec\n");
 line=klg->spec;
 rep=klg->repl;
 LOOP: symbol=*line;line++; keepLOOP: switch(symbol) {
      case '%' : goto TOKEN;
      case '\0': goto keepEND;
      default : if ((*text)[*pos]!=symbol) {
         printmsg(0,"Kludge spefication doesn't match\n");
         type=-1;
         goto keepEND;
           } else {
         rep++;
         (*pos)++;
         goto LOOP;
           }
     }
 TOKEN: symbol=*line;line++; keepTOKEN: if ((((*__ctype_b_loc ())[(int) ((symbol))] & (unsigned short) _ISalnum) && !((*__ctype_b_loc ())[(int) ((symbol))] & (unsigned short) _ISalpha))) {
      line--;
      getnum(&repeat,&line);
      goto TYPE;
     } else {
      switch(symbol) {
       case '%' : if ((*text)[*pos]!=symbol) {
          printmsg(0,"Kludge specification doesn't match\n");
          type=-1;
          goto keepEND;
            } else {
          rep++;
          (*pos)++;
          keep=0;
          goto LOOP;
            }
       case 's' : if (!keep) {
             len=0;
             while((*text)[*pos+len]!=(0x0D)) len++;
             replacestring(text,len,*pos,rep);
            }
            keep=0;
            goto keepEND;
       case 'k' : keep=1;
            goto TOKEN;
       default: printmsg(0,"Invalid kludge specification\n");
            type=-1;
            goto keepEND;
      }
     }
 TYPE: symbol=*line;line++; keepTYPE: switch(symbol) {
      case 'a' : if (repeat==0) { char *oldrep;
          oldrep=rep;
          while((*text)[*pos]!=(0x0D)) {
           doaddress(text,pos,&rep,rrt,keep);
           rep=oldrep;
           if ((*text)[*pos]!=(0x0D)) {
            while(!(((*__ctype_b_loc ())[(int) (((*text)[*pos]))] & (unsigned short) _ISalnum) && !((*__ctype_b_loc ())[(int) (((*text)[*pos]))] & (unsigned short) _ISalpha))) (*pos)++;
           }
          }
           } else {
          while(repeat--) {
           doaddress(text,pos,&rep,rrt,keep);
          }
           }
           keep=0;
           goto LOOP;
      case 'w' : if (repeat==0) { char *oldrep;
          oldrep=rep;
          while(*rep!='\0') {
           doword(text,pos,&rep,keep);
           rep=oldrep;
          }
           } else {
          while(repeat--) {
           doword(text,pos,&rep,keep);
          }
           }
           keep=0;
           goto LOOP;
      case 'n' : if (repeat==0) { char *oldrep;
          oldrep=rep;
          while(*rep!='\0') {
           donum(text,pos,&rep,keep);
           rep=oldrep;
          }
           } else {
          while(repeat--) {
           donum(text,pos,&rep,keep);
          }
           }
           keep=0;
           goto LOOP;
      default: keep=0;
           printmsg(0,"Unknown token in kludge specification\n");
           goto LOOP;
     }
 END: symbol=*line;line++; keepEND: return(type);
}

variable_types:
text
char **

variable_types:
pos
int *

variable_types: struct kludge { char *kludge; char *spec; char *repl; } *

variable_types:
rep
char *

variable_types: repeat int

variable_types: keep int

variable_types:
oldrep
char *

user_defined_types: struct fidaddr { int Zone; int Net; int Node; int Point; }


kludgereplace

original_code:
int kludgereplace(char **text,int *pos,struct kludgelist *klq,struct reroutetab *rrt) {
struct kludgelist *wlk;
int qq;
char txt[255];
 printmsg(3,"KludgeReplace\n");
 printmsg(1,"Kludge  : ");
 qq=0;
 while((*text)[*pos+qq]!=(0x0D)) {
  txt[qq]=(*text)[*pos+qq];
  qq++;
 }
 txt[qq]='\0';
 strcat(txt," -> ");
 printmsg(1,txt);
 wlk=klq;
 while(strncmp(wlk->klg.kludge,(*text)+*pos,strlen(wlk->klg.kludge))!=0) {
  wlk=wlk->next;
  if (wlk==((void *)0)) {
   printmsg(1,"Not found\n");
   return(-1);
  }
 }
 if (wlk->klg.repl==((void *)0)) {
   printmsg(1,"No Action\n");
   return(0);
 }
 if (wlk->klg.repl==NIL) {
  int len=0;
  printmsg(1,"Remove\n");
  while((*text)[*pos+len]!=(0x0D)) len++;
  len++;
  (*pos)--;
  replacestring(text,len+1,*pos,"");
        return(0);
 } else {
  printmsg(1,"Modify\n");
        (*pos)+=strlen(wlk->klg.kludge);
        parsespec(text,pos,&(wlk->klg),rrt);
        return(0);
    }
}

canonical_original_code:
int kludgereplace(char **text, int *pos, struct kludgelist *klq, struct reroutetab *rrt) {
struct kludgelist *wlk;
int qq;
char txt[255];
 printmsg(3,"KludgeReplace\n");
 printmsg(1,"Kludge  : ");
 qq=0;
 while((*text)[*pos+qq]!=(0x0D)) {
  txt[qq]=(*text)[*pos+qq];
  qq++;
 }
 txt[qq]='\0';
 strcat(txt," -> ");
 printmsg(1,txt);
 wlk=klq;
 while(strncmp(wlk->klg.kludge,(*text)+*pos,strlen(wlk->klg.kludge))!=0) {
  wlk=wlk->next;
  if (wlk==((void *)0)) {
   printmsg(1,"Not found\n");
   return(-1);
  }
 }
 if (wlk->klg.repl==((void *)0)) {
   printmsg(1,"No Action\n");
   return(0);
 }
 if (wlk->klg.repl==NIL) {
  int len = 0;
  printmsg(1,"Remove\n");
  while((*text)[*pos+len]!=(0x0D)) len++;
  len++;
  (*pos)--;
  replacestring(text,len+1,*pos,"");
        return(0);
 } else {
  printmsg(1,"Modify\n");
        (*pos)+=strlen(wlk->klg.kludge);
        parsespec(text,pos,&(wlk->klg),rrt);
        return(0);
    }
}

variable_types: struct kludgelist { struct kludgelist *next; struct kludge { char *kludge; char *spec; char *repl; } klg; } *

variable_types: struct reroutetab { struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *orgroot; struct rrlist *dstroot; } *

variable_types: qq int

variable_types:
txt
char [255]

variable_types: len int


parserepl

decompiled_code:
__int64 __fastcall parserepl(_QWORD *a1)
{
_BYTE *v1; // rax
char v2; // dl
_BYTE *v3; // rbx
__int64 result; // rax

printmsg(3LL, "ParseRepl\n");
v1 = (_BYTE *)*a1;
if ( *(_BYTE *)*a1 == 37 )
{
v2 = v1[1];
v3 = v1 + 2;
result = 2LL;
if ( v2 != 100 )
{
result = 1LL;
if ( v2 != 111 )
{
printmsg(0LL, "Unknown token in replacement specification\n");
result = 0xFFFFFFFFLL;
}
}
}
else
{
v3 = v1 + 1;
printmsg(0LL, "Replacement specification doesn't match\n");
result = 0xFFFFFFFFLL;
}
*a1 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
_BYTE *v1; // rax
char v2; // dl
_BYTE *v3; // rbx
__int64 result; // rax

printmsg(3LL, "ParseRepl\n");
v1 = (_BYTE *)*a1;
if ( *(_BYTE *)*a1 == 37 )
{
v2 = v1[1];
v3 = v1 + 2;
result = 2LL;
if ( v2 != 100 )
{
result = 1LL;
if ( v2 != 111 )
{
printmsg(0LL, "Unknown token in replacement specification\n");
result = 0xFFFFFFFFLL;
}
}
}
else
{
v3 = v1 + 1;
printmsg(0LL, "Replacement specification doesn't match\n");
result = 0xFFFFFFFFLL;
}
*a1 = v3;
return result;
}

original_code:
int parserepl(char **rep) {
char *line;
char symbol;
int type=0;
 printmsg(3,"ParseRepl\n");
 line=*rep;
 BEGIN: symbol=*line;line++; keepBEGIN: switch(symbol) {
      case '%' : goto TYPE;
      default: printmsg(0,"Replacement specification doesn't match\n");
           type=-1;
           goto keepEND;
     }
 TYPE: symbol=*line;line++; keepTYPE: switch(symbol) {
      case 'o' : type=1;
           goto keepEND;
      case 'd' : type=2;
           goto keepEND;
      default: printmsg(0,"Unknown token in replacement specification\n");
           type=-1;
           goto keepEND;
     }
 END: symbol=*line;line++; keepEND: *rep=line;
     return(type);
}

canonical_original_code:
int parserepl(char **rep) {
char *line;
char symbol;
int type = 0;
 printmsg(3,"ParseRepl\n");
 line=*rep;
 BEGIN: symbol=*line;line++; keepBEGIN: switch(symbol) {
      case '%' : goto TYPE;
      default: printmsg(0,"Replacement specification doesn't match\n");
           type=-1;
           goto keepEND;
     }
 TYPE: symbol=*line;line++; keepTYPE: switch(symbol) {
      case 'o' : type=1;
           goto keepEND;
      case 'd' : type=2;
           goto keepEND;
      default: printmsg(0,"Unknown token in replacement specification\n");
           type=-1;
           goto keepEND;
     }
 END: symbol=*line;line++; keepEND: *rep=line;
     return(type);
}

variable_types:
rep
char **

variable_types:
line
char *


repo: ricpelo/elcirculo

decompiled_code:
__int64 __fastcall deduce_magic(void *s2, int a2)
{
size_t v2; // rdx
int v3; // er13
void *v5; // rdi
const void **v6; // rbx

v2 = 2LL;
v3 = 0;
v5 = &unk_36C;
v6 = (const void **)&off_3D8;
while ( a2 < (int)v2 || memcmp(v5, s2, v2) )
{
v5 = (void *)*v6;
v6 += 3;
++v3;
if ( !v5 )
return 0LL;
v2 = *((int *)v6 - 2);
}
return (__int64)*(&off_3C8 + 3 * v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(void *s2, int a2)
{
size_t v2; // rdx
int v3; // er13
void *v5; // rdi
const void **v6; // rbx

v2 = 2LL;
v3 = 0;
v5 = &unk_36C;
v6 = (const void **)&off_3D8;
while ( a2 < (int)v2 || memcmp(v5, s2, v2) )
{
v5 = (void *)*v6;
v6 += 3;
++v3;
if ( !v5 )
return 0LL;
v2 = *((int *)v6 - 2);
}
return (__int64)*(&off_3C8 + 3 * v3);
}

original_code:
static char *deduce_magic(void *sf, int32 extent)
{
 int i;
 for(i=0;magic[i].magic;i++)
 if (extent >= magic[i].len && memcmp(magic[i].magic,sf,magic[i].len)==0)
  return magic[i].name;
 return ((void *)0);
}

canonical_original_code:
static char *deduce_magic(void *sf, int extent)
{
 int i;
 for(i=0;magic[i].magic;i++)
 if (extent >= magic[i].len && memcmp(magic[i].magic,sf,magic[i].len)==0)
  return magic[i].name;
 return ((void *)0);
}

variable_types:
sf
void *

variable_types: extent int

variable_types: i int

return_type: char *


original_code:
int32 executable_treaty(int32 selector,
                   void *story_file, int32 extent,
                   void *output, int32 output_extent)
{
 int32 ll, csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((signed) strlen("http://http://en.wikipedia.org/wiki/Executable")+1)) return -3; } while (0);
                strcpy((char *) output,"http://http://en.wikipedia.org/wiki/Executable");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"executable",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".exe")+1) < 512 ? (strlen(".exe")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".exe", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
  case 0x309:
                return 0;
  case 0x106:
  case 0x107:
  case 0x30A:
                return 0;
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

canonical_original_code:
int executable_treaty(int selector, void *story_file, int extent, void *output, int output_extent)
{
 int ll; int csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((int) strlen("http://http://en.wikipedia.org/wiki/Executable")+1)) return -3; } while (0);
                strcpy((char *) output,"http://http://en.wikipedia.org/wiki/Executable");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"executable",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".exe")+1) < 512 ? (strlen(".exe")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".exe", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
  case 0x309:
                return 0;
  case 0x106:
  case 0x107:
  case 0x30A:
                return 0;
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

variable_types: selector int

variable_types:
output
void *

variable_types: ll int

variable_types: csf int


decompiled_code:
_BOOL8 __fastcall claim_story_file(void *a1, int a2)
{
return deduce_magic(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(void *a1, int a2)
{
return func0(a1, a2) != 0;
}

original_code:
static int32 claim_story_file(void *sf, int32 extent)
{
 if (deduce_magic(sf,extent)) return 1;
 return 0;
}

canonical_original_code:
static int claim_story_file(void *sf, int extent)
{
 if (deduce_magic(sf,extent)) return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall get_story_file_IFID(void *a1, int a2, char *a3, int a4)
{
const char *v6; // rax
const char *v7; // rbp
size_t v8; // rax
int v9; // edx
size_t v10; // rbx
__int64 result; // rax

v6 = (const char *)deduce_magic(a1, a2);
if ( !v6 )
return 0LL;
v7 = v6;
v8 = strlen(v6);
v9 = v8 + 1;
v10 = v8;
result = 4294967293LL;
if ( v9 < a4 )
{
memcpy(a3, v7, v10);
*(_WORD *)&a3[v10] = 45;
result = 4294967292LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *a1, int a2, char *a3, int a4)
{
const char *v6; // rax
const char *v7; // rbp
size_t v8; // rax
int v9; // edx
size_t v10; // rbx
__int64 result; // rax

v6 = (const char *)func0(a1, a2);
if ( !v6 )
return 0LL;
v7 = v6;
v8 = strlen(v6);
v9 = v8 + 1;
v10 = v8;
result = 4294967293LL;
if ( v9 < a4 )
{
memcpy(a3, v7, v10);
*(_WORD *)&a3[v10] = 45;
result = 4294967292LL;
}
return result;
}

original_code:
static int32 get_story_file_IFID(void *sf, int32 extent, char *output, int32 output_extent)
{
 char *o;
 o=deduce_magic(sf,extent);
 if (!o) return 0;
 do { if (output_extent < ((signed) strlen(o)+2)) return -3; } while (0);
 strcpy(output,o);
 strcat(output,"-");
 return -4;
}

canonical_original_code:
static int get_story_file_IFID(void *sf, int extent, char *output, int output_extent)
{
 char *o;
 o=deduce_magic(sf,extent);
 if (!o) return 0;
 do { if (output_extent < ((int) strlen(o)+2)) return -3; } while (0);
 strcpy(output,o);
 strcat(output,"-");
 return -4;
}

variable_types:
output
char *

variable_types:
o
char *


decompiled_code:
size_t __fastcall get_story_file_extension(__int64 a1, int a2, const char *a3, int a4)
{
char v5; // dl
int v7; // ecx
__int64 v8; // rax
unsigned int i; // eax
__int64 v10; // rdx

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v5 = 101;
v7 = 1;
v8 = 2LL;
do
{
if ( v5 == 44 )
break;
v5 = byte_36F[v8];
v7 = v8++;
}
while ( v5 );
if ( a4 <= v7 )
return 4294967293LL;
if ( v7 )
{
for ( i = 0; i < v7; ++i )
{
v10 = i;
a3[v10] = byte_36F[v10];
}
}
a3[v7] = 0;
return strlen(a3);
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1, int a2, const char *a3, int a4)
{
char v5; // dl
int v7; // ecx
__int64 v8; // rax
unsigned int i; // eax
__int64 v10; // rdx

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v5 = 101;
v7 = 1;
v8 = 2LL;
do
{
if ( v5 == 44 )
break;
v5 = byte_36F[v8];
v7 = v8++;
}
while ( v5 );
if ( a4 <= v7 )
return 4294967293LL;
if ( v7 )
{
for ( i = 0; i < v7; ++i )
{
v10 = i;
a3[v10] = byte_36F[v10];
}
}
a3[v7] = 0;
return strlen(a3);
}

original_code:
static int32 get_story_file_extension(void *sf, int32 extent, char *out, int32 output_extent)
{
 int i;
 if (!sf || !extent) return -1;
 for(i=0;".exe"[i] && ".exe"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".exe",i);
 out[i]=0;
 return strlen(out);
}

canonical_original_code:
static int get_story_file_extension(void *sf, int extent, char *out, int output_extent)
{
 int i;
 if (!sf || !extent) return -1;
 for(i=0;".exe"[i] && ".exe"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".exe",i);
 out[i]=0;
 return strlen(out);
}

variable_types:
out
char *


decompiled_code:
__int64 __fastcall read_l9_int(unsigned __int16 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 *a1)
{
return *a1;
}

original_code:
static int32 read_l9_int(unsigned char *sf)
{
 return ((int32) sf[1]) << 8 | sf[0];
}

canonical_original_code:
static int read_l9_int(unsigned char *sf)
{
 return ((int) sf[1]) << 8 | sf[0];
}

variable_types:
sf
unsigned char *


original_code:
static int v2_recognition (unsigned char *sf, int32 extent, int32 *l, unsigned char *c)
{
  int32 i, j;
  for (i=0;i<extent-20;i++)
    if ((read_l9_int(sf+i+4) == 0x0020) &&
        (read_l9_int(sf+i+0x0a) == 0x8000) &&
        (read_l9_int(sf+i+0x14) == read_l9_int(sf+i+0x16)))
    {
      *l=read_l9_int(sf+i+0x1c);
      if (*l && *l+i <=extent)
       {
         *c=0;
         for(j=0;j<=*l;j++)
          *c+=sf[i+j];
         return 2;
       }
    }
 return 0;
}

canonical_original_code:
static int v2_recognition(unsigned char *sf, int extent, int *l, unsigned char *c)
{
  int i; int j;
  for (i=0;i<extent-20;i++)
    if ((read_l9_int(sf+i+4) == 0x0020) &&
        (read_l9_int(sf+i+0x0a) == 0x8000) &&
        (read_l9_int(sf+i+0x14) == read_l9_int(sf+i+0x16)))
    {
      *l=read_l9_int(sf+i+0x1c);
      if (*l && *l+i <=extent)
       {
         *c=0;
         for(j=0;j<=*l;j++)
          *c+=sf[i+j];
         return 2;
       }
    }
 return 0;
}

variable_types:
l
int *

variable_types:
c
unsigned char *

variable_types: j int


variable_types: phase int

variable_types: end int

variable_types: checksum char


decompiled_code:
char *__fastcall get_l9_ifid(int a1, char a2)
{
_DWORD *v2; // rax
int v3; // ecx
int v4; // edx

v2 = &unk_C64;
v3 = 0;
v4 = 14897;
do
{
if ( a1 == v4 && *(_BYTE *)v2 == a2 )
return (&off_C68)[2 * v3];
v4 = v2[3];
v2 += 4;
++v3;
}
while ( v4 );
return 0LL;
}

original_code:
static char *get_l9_ifid(int32 length, unsigned char chk)
{
 int i;
 for(i=0;l9_registry[i].length;i++)
  if (length==l9_registry[i].length && chk==l9_registry[i].chk) return l9_registry[i].ifid;
 return ((void *)0);
}

canonical_original_code:
static char *get_l9_ifid(int length, unsigned char chk)
{
 int i;
 for(i=0;l9_registry[i].length;i++)
  if (length==l9_registry[i].length && chk==l9_registry[i].chk) return l9_registry[i].ifid;
 return ((void *)0);
}

variable_types: length int

variable_types:
chk
unsigned char


original_code:
static int v1_recognition(unsigned char *sf, int32 extent, char **ifid)
{
  int32 i;
  unsigned char a = 0xff, b = 0xff;
  for (i=0;i<extent-20;i++)
   if (memcmp(sf+i,"ATTAC",5)==0 && sf[i+5]==0xcb)
   {
    a = sf[i+6];
    break;
   }
  for (;i<(extent-20);i++)
   if (memcmp(sf+i,"BUNC",4)==0 && sf[i+4]==0xc8)
   {
    b = sf[i + 5];
    break;
   }
  if (a == 0xff && b == 0xff)
   return 0;
  if (a == 0x14 && b == 0xff) *ifid="LEVEL9-006";
  else if (a == 0x15 && b == 0x5d) *ifid="LEVEL9-013";
  else if (a == 0x1a && b == 0x24) *ifid="LEVEL9-005";
  else if (a == 0x20 && b == 0x3b) *ifid="LEVEL9-003";
  else *ifid=((void *)0);
  return 1;
}

canonical_original_code:
static int v1_recognition(unsigned char *sf, int extent, char **ifid)
{
  int i;
  unsigned char a = 0xff; unsigned char b = 0xff;
  for (i=0;i<extent-20;i++)
   if (memcmp(sf+i,"ATTAC",5)==0 && sf[i+5]==0xcb)
   {
    a = sf[i+6];
    break;
   }
  for (;i<(extent-20);i++)
   if (memcmp(sf+i,"BUNC",4)==0 && sf[i+4]==0xc8)
   {
    b = sf[i + 5];
    break;
   }
  if (a == 0xff && b == 0xff)
   return 0;
  if (a == 0x14 && b == 0xff) *ifid="LEVEL9-006";
  else if (a == 0x15 && b == 0x5d) *ifid="LEVEL9-013";
  else if (a == 0x1a && b == 0x24) *ifid="LEVEL9-005";
  else if (a == 0x20 && b == 0x3b) *ifid="LEVEL9-003";
  else *ifid=((void *)0);
  return 1;
}

variable_types: extent int

variable_types:
ifid
char **

variable_types: i int

variable_types:
a
unsigned char

variable_types:
b
unsigned char


original_code:
int32 level9_treaty(int32 selector,
                   void *story_file, int32 extent,
                   void *output, int32 output_extent)
{
 int32 ll, csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((signed) strlen("http://www.if-legends.org/~l9memorial/html/home.html")+1)) return -3; } while (0);
                strcpy((char *) output,"http://www.if-legends.org/~l9memorial/html/home.html");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"level9",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".l9,.sna")+1) < 512 ? (strlen(".l9,.sna")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".l9,.sna", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
  case 0x309:
                return 0;
  case 0x106:
  case 0x107:
  case 0x30A:
                return 0;
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

canonical_original_code:
int level9_treaty(int selector, void *story_file, int extent, void *output, int output_extent)
{
 int ll; int csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((int) strlen("http://www.if-legends.org/~l9memorial/html/home.html")+1)) return -3; } while (0);
                strcpy((char *) output,"http://www.if-legends.org/~l9memorial/html/home.html");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"level9",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".l9,.sna")+1) < 512 ? (strlen(".l9,.sna")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".l9,.sna", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
  case 0x309:
                return 0;
  case 0x106:
  case 0x107:
  case 0x30A:
                return 0;
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

variable_types: selector int

variable_types:
output
void *

variable_types: ll int

variable_types: csf int


original_code:
static int32 get_story_file_extension(void *sf, int32 extent, char *out, int32 output_extent)
{
 int i;
 if (!sf || !extent) return -1;
 for(i=0;".l9,.sna"[i] && ".l9,.sna"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".l9,.sna",i);
 out[i]=0;
 return strlen(out);
}

canonical_original_code:
static int get_story_file_extension(void *sf, int extent, char *out, int output_extent)
{
 int i;
 if (!sf || !extent) return -1;
 for(i=0;".l9,.sna"[i] && ".l9,.sna"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".l9,.sna",i);
 out[i]=0;
 return strlen(out);
}

variable_types:
sf
void *

variable_types:
out
char *


decompiled_code:
__int64 __fastcall get_story_file_IFID(__int64 a1, int a2, void *a3, int a4)
{
unsigned int v6; // eax
char *v7; // r12
size_t v8; // rax
__int64 result; // rax
__int64 v10; // rdx
char *s; // [rsp+8h] [rbp-20h] BYREF

s = 0LL;
v6 = get_l9_version_constprop_0(a1, a2, &s);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = s;
if ( s )
{
v8 = strlen(s);
if ( a4 <= (int)v8 )
{
result = 4294967293LL;
}
else
{
memcpy(a3, v7, v8 + 1);
result = 1LL;
}
}
else
{
v10 = v6;
result = 4294967293LL;
if ( a4 > 9 )
{
sprintf((char *)a3, "LEVEL9-%d-", v10);
result = 4294967292LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, void *a3, int a4)
{
unsigned int v6; // eax
char *v7; // r12
size_t v8; // rax
__int64 result; // rax
__int64 v10; // rdx
char *s; // [rsp+8h] [rbp-20h] BYREF

s = 0LL;
v6 = func6(a1, a2, &s);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = s;
if ( s )
{
v8 = strlen(s);
if ( a4 <= (int)v8 )
{
result = 4294967293LL;
}
else
{
memcpy(a3, v7, v8 + 1);
result = 1LL;
}
}
else
{
v10 = v6;
result = 4294967293LL;
if ( a4 > 9 )
{
sprintf((char *)a3, "LEVEL9-%d-", v10);
result = 4294967292LL;
}
}
return result;
}

original_code:
static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)
{
 char *ifid=((void *)0);
 int i=get_l9_version((unsigned char *)story_file, extent, &ifid);
 if (!i) return -1;
 if (ifid)
 {
   do { if (output_extent < ((signed) strlen(ifid)+1)) return -3; } while (0);
   strcpy(output,ifid);
   return 1;
 }
 do { if (output_extent < (10)) return -3; } while (0);
 sprintf(output,"LEVEL9-%d-",i);
 return -4;
}

canonical_original_code:
static int get_story_file_IFID(void *story_file, int extent, char *output, int output_extent)
{
 char *ifid = ((void *)0);
 int i = get_l9_version((unsigned char *)story_file, extent, &ifid);
 if (!i) return -1;
 if (ifid)
 {
   do { if (output_extent < ((int) strlen(ifid)+1)) return -3; } while (0);
   strcpy(output,ifid);
   return 1;
 }
 do { if (output_extent < (10)) return -3; } while (0);
 sprintf(output,"LEVEL9-%d-",i);
 return -4;
}

variable_types:
output
char *

variable_types:
ifid
char *


decompiled_code:
__int64 __fastcall claim_story_file(__int64 a1, int a2)
{
int v2; // er8
__int64 result; // rax
char *v4; // [rsp+8h] [rbp-8h] BYREF

v4 = 0LL;
v2 = get_l9_version_constprop_0(a1, a2, &v4);
result = 0xFFFFFFFFLL;
if ( v2 )
result = v4 != 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
int v2; // er8
__int64 result; // rax
char *v4; // [rsp+8h] [rbp-8h] BYREF

v4 = 0LL;
v2 = func6(a1, a2, &v4);
result = 0xFFFFFFFFLL;
if ( v2 )
result = v4 != 0LL;
return result;
}

original_code:
static int32 claim_story_file(void *story, int32 extent)
{
 char *ifid=((void *)0);
 if (get_l9_version((unsigned char *) story,extent, &ifid))
  if (ifid) return 1;
  else return 0;
 return -1;
}

canonical_original_code:
static int claim_story_file(void *story, int extent)
{
 char *ifid = ((void *)0);
 if (get_l9_version((unsigned char *) story,extent, &ifid))
  if (ifid) return 1;
  else return 0;
 return -1;
}

variable_types:
story
void *


decompiled_code:
int print_preamble()
{
const char *v0; // rsi
int result; // eax
char v2; // al
char *v3; // rdx
int v4; // ebx

if ( ErrorReport > 0 && input_file >= ErrorReport )
{
v0 = *(const char **)(InputFiles + 16LL * ErrorReport - 16);
result = error_format;
if ( v0 )
{
LABEL_4:
if ( result != 1 )
{
if ( result != 2 )
{
if ( result )
return result;
goto LABEL_13;
}
return printf("File \"%s\"; Line %d\t# ", v0, (unsigned int)*(&ErrorReport + 4));
}
v2 = *v0;
if ( *v0 )
{
v3 = (char *)(v0 + 1);
v4 = 0;
do
{
while ( v2 == 47 )
{
v2 = *v3++;
v4 = -1;
if ( !v2 )
goto LABEL_25;
}
if ( v2 == 46 )
v4 = 0;
v2 = *v3++;
}
while ( v2 );
LABEL_25:
printf("%s", v0);
if ( !v4 )
return printf("(%d): ", (unsigned int)*(&ErrorReport + 4));
v0 = ".inf";
}
LABEL_28:
printf("%s", v0);
return printf("(%d): ", (unsigned int)*(&ErrorReport + 4));
}
}
else
{
v0 = (const char *)*((_QWORD *)&ErrorReport + 1);
result = error_format;
if ( v0 )
goto LABEL_4;
}
if ( result == 1 )
{
v0 = (const char *)&unk_DC4;
goto LABEL_28;
}
if ( result == 2 )
{
v0 = (const char *)&unk_DC4;
return printf("File \"%s\"; Line %d\t# ", v0, (unsigned int)*(&ErrorReport + 4));
}
if ( result )
return result;
v0 = (const char *)&unk_DC4;
LABEL_13:
if ( !*(&ErrorReport + 5) )
printf("\"%s\", ", v0);
return printf("line %d: ", (unsigned int)*(&ErrorReport + 4));
}

canonical_decompiled_code:
int func0()
{
const char *v0; // rsi
int result; // eax
char v2; // al
char *v3; // rdx
int v4; // ebx

if ( ErrorReport > 0 && input_file >= ErrorReport )
{
v0 = *(const char **)(InputFiles + 16LL * ErrorReport - 16);
result = error_format;
if ( v0 )
{
LABEL_4:
if ( result != 1 )
{
if ( result != 2 )
{
if ( result )
return result;
goto LABEL_13;
}
return printf("File \"%s\"; Line %d\t# ", v0, (unsigned int)*(&ErrorReport + 4));
}
v2 = *v0;
if ( *v0 )
{
v3 = (char *)(v0 + 1);
v4 = 0;
do
{
while ( v2 == 47 )
{
v2 = *v3++;
v4 = -1;
if ( !v2 )
goto LABEL_25;
}
if ( v2 == 46 )
v4 = 0;
v2 = *v3++;
}
while ( v2 );
LABEL_25:
printf("%s", v0);
if ( !v4 )
return printf("(%d): ", (unsigned int)*(&ErrorReport + 4));
v0 = ".inf";
}
LABEL_28:
printf("%s", v0);
return printf("(%d): ", (unsigned int)*(&ErrorReport + 4));
}
}
else
{
v0 = (const char *)*((_QWORD *)&ErrorReport + 1);
result = error_format;
if ( v0 )
goto LABEL_4;
}
if ( result == 1 )
{
v0 = (const char *)&unk_DC4;
goto LABEL_28;
}
if ( result == 2 )
{
v0 = (const char *)&unk_DC4;
return printf("File \"%s\"; Line %d\t# ", v0, (unsigned int)*(&ErrorReport + 4));
}
if ( result )
return result;
v0 = (const char *)&unk_DC4;
LABEL_13:
if ( !*(&ErrorReport + 5) )
printf("\"%s\", ", v0);
return printf("line %d: ", (unsigned int)*(&ErrorReport + 4));
}

original_code:
static void print_preamble(void)
{
    int j, with_extension_flag = 0; char *p;
    j = ErrorReport.file_number;
    if (j <= 0 || j > input_file) p = ErrorReport.source;
    else p = InputFiles[j-1].filename;
    if (!p) p = "";
    switch(error_format)
    {
        case 0:
            if (!(ErrorReport.main_flag)) printf("\"%s\", ", p);
            printf("line %d: ", ErrorReport.line_number);
            break;
        case 1:
            for (j=0; p[j]!=0; j++)
            { if (p[j] == '/') with_extension_flag = -1;
                if (p[j] == '.') with_extension_flag = 0;
            }
            printf("%s", p);
            if (with_extension_flag) printf("%s", ".inf");
            printf("(%d): ", ErrorReport.line_number);
            break;
        case 2:
            printf("File \"%s\"; Line %d\t# ", p, ErrorReport.line_number);
            break;
    }
}

canonical_original_code:
static void print_preamble()
{
    int j; int with_extension_flag = 0; char *p;
    j = ErrorReport.file_number;
    if (j <= 0 || j > input_file) p = ErrorReport.source;
    else p = InputFiles[j-1].filename;
    if (!p) p = "";
    switch(error_format)
    {
        case 0:
            if (!(ErrorReport.main_flag)) printf("\"%s\", ", p);
            printf("line %d: ", ErrorReport.line_number);
            break;
        case 1:
            for (j=0; p[j]!=0; j++)
            { if (p[j] == '/') with_extension_flag = -1;
                if (p[j] == '.') with_extension_flag = 0;
            }
            printf("%s", p);
            if (with_extension_flag) printf("%s", ".inf");
            printf("(%d): ", ErrorReport.line_number);
            break;
        case 2:
            printf("File \"%s\"; Line %d\t# ", p, ErrorReport.line_number);
            break;
    }
}

variable_types: j int

variable_types:
p
char *

return_type: void


decompiled_code:
size_t ellipsize_error_message_buff()
{
size_t result; // rax

result = strlen(error_message_buff);
if ( result == 255 )
dword_DBF = 3026478;
return result;
}

canonical_decompiled_code:
size_t func1()
{
size_t result; // rax

result = strlen(error_message_buff);
if ( result == 255 )
dword_DBF = 3026478;
return result;
}

original_code:
static void ellipsize_error_message_buff(void)
{
    if (strlen(error_message_buff) == (256)-1)
        strcat(error_message_buff, "...");
}

canonical_original_code:
static void ellipsize_error_message_buff()
{
    if (strlen(error_message_buff) == (256)-1)
        strcat(error_message_buff, "...");
}


warning

decompiled_code:
int __fastcall warning(const char *a1)
{
int result; // eax

result = nowarnings_switch;
if ( !nowarnings_switch )
return message(2, a1);
++no_suppressed_warnings;
return result;
}

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

result = nowarnings_switch;
if ( !nowarnings_switch )
return func2(2, a1);
++no_suppressed_warnings;
return result;
}

original_code:
extern void warning(char *s1)
{ if (nowarnings_switch) { no_suppressed_warnings++; return; }
    message(2,s1);
}


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

result = nowarnings_switch;
if ( nowarnings_switch )
{
++no_suppressed_warnings;
}
else
{
snprintf(error_message_buff, 0x100uLL, "%s %d.", a1, a2);
ellipsize_error_message_buff();
result = message(2, error_message_buff);
}
return result;
}

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

result = nowarnings_switch;
if ( nowarnings_switch )
{
++no_suppressed_warnings;
}
else
{
snprintf(error_message_buff, 0x100uLL, "%s %d.", a1, a2);
func1();
result = func2(2, error_message_buff);
}
return result;
}

original_code:
extern void warning_numbered(char *s1, int val)
{ if (nowarnings_switch) { no_suppressed_warnings++; return; }
    snprintf(error_message_buff, (256),"%s %d.", s1, val);
    ellipsize_error_message_buff();
    message(2,error_message_buff);
}

variable_types: val int


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

result = nowarnings_switch;
if ( nowarnings_switch )
{
++no_suppressed_warnings;
}
else
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
ellipsize_error_message_buff();
result = message(2, error_message_buff);
}
return result;
}

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

result = nowarnings_switch;
if ( nowarnings_switch )
{
++no_suppressed_warnings;
}
else
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
func1();
result = func2(2, error_message_buff);
}
return result;
}

original_code:
extern void warning_named(char *s1, char *s2)
{
    if (nowarnings_switch) { no_suppressed_warnings++; return; }
    snprintf(error_message_buff, (256),"%s \"%s\"", s1, s2);
    ellipsize_error_message_buff();
    message(2,error_message_buff);
}


decompiled_code:
int __fastcall dbnu_warning(const char *a1, const char *a2, int a3)
{
int result; // eax
int v4; // er12
__int64 v5; // rbp
__int64 v6; // rbx
int v7; // er13

result = nowarnings_switch;
if ( nowarnings_switch )
{
++no_suppressed_warnings;
}
else
{
v4 = ErrorReport;
v5 = *((_QWORD *)&ErrorReport + 1);
v6 = *((_QWORD *)&ErrorReport + 2);
if ( a3 != -1 )
{
ErrorReport = a3 / 0x800000;
*(&ErrorReport + 4) = a3 % 0x800000;
*(&ErrorReport + 5) = a3 / 0x800000 == 1;
}
snprintf(error_message_buff, 0x100uLL, "%s \"%s\" declared but not used", a1, a2);
ellipsize_error_message_buff();
v7 = concise_switch;
concise_switch = -1;
result = message(2, error_message_buff);
concise_switch = v7;
ErrorReport = v4;
*((_QWORD *)&ErrorReport + 1) = v5;
*((_QWORD *)&ErrorReport + 2) = v6;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, const char *a2, int a3)
{
int result; // eax
int v4; // er12
__int64 v5; // rbp
__int64 v6; // rbx
int v7; // er13

result = nowarnings_switch;
if ( nowarnings_switch )
{
++no_suppressed_warnings;
}
else
{
v4 = ErrorReport;
v5 = *((_QWORD *)&ErrorReport + 1);
v6 = *((_QWORD *)&ErrorReport + 2);
if ( a3 != -1 )
{
ErrorReport = a3 / 0x800000;
*(&ErrorReport + 4) = a3 % 0x800000;
*(&ErrorReport + 5) = a3 / 0x800000 == 1;
}
snprintf(error_message_buff, 0x100uLL, "%s \"%s\" declared but not used", a1, a2);
func1();
v7 = concise_switch;
concise_switch = -1;
result = func2(2, error_message_buff);
concise_switch = v7;
ErrorReport = v4;
*((_QWORD *)&ErrorReport + 1) = v5;
*((_QWORD *)&ErrorReport + 2) = v6;
}
return result;
}

original_code:
extern void dbnu_warning(char *type, char *name, int32 report_line)
{ int i;
    ErrorPosition E = ErrorReport;
    if (nowarnings_switch) { no_suppressed_warnings++; return; }
    if (report_line != -1)
    { ErrorReport.file_number = report_line/(0x800000L);
        ErrorReport.line_number = report_line%(0x800000L);
        ErrorReport.main_flag = (ErrorReport.file_number == 1);
    }
    snprintf(error_message_buff, (256), "%s \"%s\" declared but not used", type, name);
    ellipsize_error_message_buff();
    i = concise_switch; concise_switch = -1;
    message(2,error_message_buff);
    concise_switch = i;
    ErrorReport = E;
}

canonical_original_code:
extern void dbnu_warning(char *type, char *name, int report_line)
{ int i;
    struct ErrorPosition_s E = ErrorReport;
    if (nowarnings_switch) { no_suppressed_warnings++; return; }
    if (report_line != -1)
    { ErrorReport.file_number = report_line/(0x800000L);
        ErrorReport.line_number = report_line%(0x800000L);
        ErrorReport.main_flag = (ErrorReport.file_number == 1);
    }
    snprintf(error_message_buff, (256), "%s \"%s\" declared but not used", type, name);
    ellipsize_error_message_buff();
    i = concise_switch; concise_switch = -1;
    message(2,error_message_buff);
    concise_switch = i;
    ErrorReport = E;
}

variable_types:
type
char *

variable_types:
name
char *

variable_types: struct ErrorPosition_s { int file_number; char *source; int line_number; int main_flag; }


decompiled_code:
void __fastcall uncalled_routine_warning(const char *a1, const char *a2, int a3)
{
int v3; // er12
__int64 v4; // rbp
__int64 v5; // rbx
int v6; // er13

if ( nowarnings_switch )
{
++no_suppressed_warnings;
}
else
{
v3 = ErrorReport;
v4 = *((_QWORD *)&ErrorReport + 1);
v5 = *((_QWORD *)&ErrorReport + 2);
if ( a3 != -1 )
{
ErrorReport = a3 / 0x800000;
*(&ErrorReport + 4) = a3 % 0x800000;
*(&ErrorReport + 5) = a3 / 0x800000 == 1;
}
if ( OMIT_UNUSED_ROUTINES )
snprintf(error_message_buff, 0x100uLL, "%s \"%s\" unused and omitted", a1, a2);
else
snprintf(error_message_buff, 0x100uLL, "%s \"%s\" unused (not omitted)", a1, a2);
ellipsize_error_message_buff();
v6 = concise_switch;
concise_switch = -1;
message(2, error_message_buff);
concise_switch = v6;
ErrorReport = v3;
*((_QWORD *)&ErrorReport + 1) = v4;
*((_QWORD *)&ErrorReport + 2) = v5;
}
}

canonical_decompiled_code:
void __fastcall func7(const char *a1, const char *a2, int a3)
{
int v3; // er12
__int64 v4; // rbp
__int64 v5; // rbx
int v6; // er13

if ( nowarnings_switch )
{
++no_suppressed_warnings;
}
else
{
v3 = ErrorReport;
v4 = *((_QWORD *)&ErrorReport + 1);
v5 = *((_QWORD *)&ErrorReport + 2);
if ( a3 != -1 )
{
ErrorReport = a3 / 0x800000;
*(&ErrorReport + 4) = a3 % 0x800000;
*(&ErrorReport + 5) = a3 / 0x800000 == 1;
}
if ( OMIT_UNUSED_ROUTINES )
snprintf(error_message_buff, 0x100uLL, "%s \"%s\" unused and omitted", a1, a2);
else
snprintf(error_message_buff, 0x100uLL, "%s \"%s\" unused (not omitted)", a1, a2);
func1();
v6 = concise_switch;
concise_switch = -1;
func2(2, error_message_buff);
concise_switch = v6;
ErrorReport = v3;
*((_QWORD *)&ErrorReport + 1) = v4;
*((_QWORD *)&ErrorReport + 2) = v5;
}
}

original_code:
extern void uncalled_routine_warning(char *type, char *name, int32 report_line)
{ int i;
    ErrorPosition E = ErrorReport;
    if (nowarnings_switch) { no_suppressed_warnings++; return; }
    if (report_line != -1)
    { ErrorReport.file_number = report_line/(0x800000L);
        ErrorReport.line_number = report_line%(0x800000L);
        ErrorReport.main_flag = (ErrorReport.file_number == 1);
    }
    if (OMIT_UNUSED_ROUTINES)
        snprintf(error_message_buff, (256), "%s \"%s\" unused and omitted", type, name);
    else
        snprintf(error_message_buff, (256), "%s \"%s\" unused (not omitted)", type, name);
    ellipsize_error_message_buff();
    i = concise_switch; concise_switch = -1;
    message(2,error_message_buff);
    concise_switch = i;
    ErrorReport = E;
}

canonical_original_code:
extern void uncalled_routine_warning(char *type, char *name, int report_line)
{ int i;
    struct ErrorPosition_s E = ErrorReport;
    if (nowarnings_switch) { no_suppressed_warnings++; return; }
    if (report_line != -1)
    { ErrorReport.file_number = report_line/(0x800000L);
        ErrorReport.line_number = report_line%(0x800000L);
        ErrorReport.main_flag = (ErrorReport.file_number == 1);
    }
    if (OMIT_UNUSED_ROUTINES)
        snprintf(error_message_buff, (256), "%s \"%s\" unused and omitted", type, name);
    else
        snprintf(error_message_buff, (256), "%s \"%s\" unused (not omitted)", type, name);
    ellipsize_error_message_buff();
    i = concise_switch; concise_switch = -1;
    message(2,error_message_buff);
    concise_switch = i;
    ErrorReport = E;
}

variable_types: i int

user_defined_types: struct ErrorPosition_s { int file_number; char *source; int line_number; int main_flag; }


decompiled_code:
int __fastcall obsolete_warning(const char *a1)
{
int result; // eax

result = is_systemfile();
if ( result != 1 )
{
result = nowarnings_switch | obsolete_switch;
if ( nowarnings_switch | obsolete_switch )
{
++no_suppressed_warnings;
}
else
{
snprintf(error_message_buff, 0x100uLL, "Obsolete usage: %s", a1);
ellipsize_error_message_buff();
result = message(2, error_message_buff);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
int result; // eax

result = is_systemfile();
if ( result != 1 )
{
result = nowarnings_switch | obsolete_switch;
if ( nowarnings_switch | obsolete_switch )
{
++no_suppressed_warnings;
}
else
{
snprintf(error_message_buff, 0x100uLL, "Obsolete usage: %s", a1);
func1();
result = func2(2, error_message_buff);
}
}
return result;
}

original_code:
extern void obsolete_warning(char *s1)
{ if (is_systemfile()==1) return;
    if (obsolete_switch || nowarnings_switch)
    { no_suppressed_warnings++; return; }
    snprintf(error_message_buff, (256), "Obsolete usage: %s",s1);
    ellipsize_error_message_buff();
    message(2,error_message_buff);
}


decompiled_code:
int print_sorry_message()
{
return printf(
"***********************************************************************\n"
"* 'Compiler errors' should never occur if Inform is working properly. *\n"
"* This is version %d.%02d of Inform, dated %20s: so *\n"
"* if that was more than six months ago, there may be a more recent *\n"
"* version available, from which the problem may have been removed. *\n"
"* If not, please report this fault to: graham@gnelson.demon.co.uk *\n"
"* and if at all possible, please include your source code, as faults *\n"
"* such as these are rare and often difficult to reproduce. Sorry. *\n"
"***********************************************************************\n",
6LL,
32LL,
"14th October 2012");
}

canonical_decompiled_code:
int func9()
{
return printf(
"***********************************************************************\n"
"* 'Compiler errors' should never occur if Inform is working properly. *\n"
"* This is version %d.%02d of Inform, dated %20s: so *\n"
"* if that was more than six months ago, there may be a more recent *\n"
"* version available, from which the problem may have been removed. *\n"
"* If not, please report this fault to: graham@gnelson.demon.co.uk *\n"
"* and if at all possible, please include your source code, as faults *\n"
"* such as these are rare and often difficult to reproduce. Sorry. *\n"
"***********************************************************************\n",
6LL,
32LL,
"14th October 2012");
}

original_code:
extern void print_sorry_message(void)
{ printf(
"***********************************************************************\n* 'Compiler errors' should never occur if Inform is working properly. *\n* This is version %d.%02d of Inform, dated %20s: so      *\n* if that was more than six months ago, there may be a more recent    *\n* version available, from which the problem may have been removed.    *\n* If not, please report this fault to:   graham@gnelson.demon.co.uk   *\n* and if at all possible, please include your source code, as faults  *\n* such as these are rare and often difficult to reproduce.  Sorry.    *\n***********************************************************************\n",
    (1632/100)%10, 1632%100, "14th October 2012");
}

canonical_original_code:
extern void print_sorry_message()
{ printf(
"***********************************************************************\n* 'Compiler errors' should never occur if Inform is working properly. *\n* This is version %d.%02d of Inform, dated %20s: so      *\n* if that was more than six months ago, there may be a more recent    *\n* version available, from which the problem may have been removed.    *\n* If not, please report this fault to:   graham@gnelson.demon.co.uk   *\n* and if at all possible, please include your source code, as faults  *\n* such as these are rare and often difficult to reproduce.  Sorry.    *\n***********************************************************************\n",
    (1632/100)%10, 1632%100, "14th October 2012");
}


fatalerror

decompiled_code:
void __fastcall __noreturn fatalerror(const char *a1)
{
print_preamble();
printf("Fatal error: %s\n", a1);
if ( no_compiler_errors > 0 )
print_sorry_message();
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
func0();
printf("Fatal error: %s\n", a1);
if ( no_compiler_errors > 0 )
func9();
exit(1);
}

original_code:
extern void fatalerror(char *s)
{ print_preamble();
    printf("Fatal error: %s\n",s);
    if (no_compiler_errors > 0) print_sorry_message();
    exit(1);
}

variable_types:
s
char *


decompiled_code:
void __fastcall __noreturn fatalerror_named(const char *a1, const char *a2)
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
ellipsize_error_message_buff();
fatalerror(error_message_buff);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(const char *a1, const char *a2)
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
func1();
func10(error_message_buff);
}

original_code:
extern void fatalerror_named(char *m, char *fn)
{ snprintf(error_message_buff, (256), "%s \"%s\"", m, fn);
    ellipsize_error_message_buff();
    fatalerror(error_message_buff);
}

variable_types:
m
char *

variable_types:
fn
char *


decompiled_code:
void __fastcall __noreturn memory_out_error(unsigned int a1, unsigned int a2, const char *a3)
{
if ( a2 == 1 )
snprintf(error_message_buff, 0x100uLL, "Run out of memory allocating %d bytes for %s", a1, a3);
else
snprintf(error_message_buff, 0x100uLL, "Run out of memory allocating array of %dx%d bytes for %s", a2, a1, a3);
ellipsize_error_message_buff();
fatalerror(error_message_buff);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(unsigned int a1, unsigned int a2, const char *a3)
{
if ( a2 == 1 )
snprintf(error_message_buff, 0x100uLL, "Run out of memory allocating %d bytes for %s", a1, a3);
else
snprintf(error_message_buff, 0x100uLL, "Run out of memory allocating array of %dx%d bytes for %s", a2, a1, a3);
func1();
func10(error_message_buff);
}

original_code:
extern void memory_out_error(int32 size, int32 howmany, char *name)
{ if (howmany == 1)
        snprintf(error_message_buff, (256),
            "Run out of memory allocating %d bytes for %s", size, name);
    else
        snprintf(error_message_buff, (256),
            "Run out of memory allocating array of %dx%d bytes for %s",
                howmany, size, name);
    ellipsize_error_message_buff();
    fatalerror(error_message_buff);
}

canonical_original_code:
extern void memory_out_error(int size, int howmany, char *name)
{ if (howmany == 1)
        snprintf(error_message_buff, (256),
            "Run out of memory allocating %d bytes for %s", size, name);
    else
        snprintf(error_message_buff, (256),
            "Run out of memory allocating array of %dx%d bytes for %s",
                howmany, size, name);
    ellipsize_error_message_buff();
    fatalerror(error_message_buff);
}

variable_types: size int

variable_types: howmany int


memoryerror

decompiled_code:
void __fastcall __noreturn memoryerror(const char *a1, int a2)
{
snprintf(
error_message_buff,
0x100uLL,
"The memory setting %s (which is %ld at present) has been exceeded. Try running Inform again with $%s=<some-larger-n"
"umber> on the command line.",
a1,
a2,
a1);
ellipsize_error_message_buff();
fatalerror(error_message_buff);
}

canonical_decompiled_code:
void __fastcall __noreturn func13(const char *a1, int a2)
{
snprintf(
error_message_buff,
0x100uLL,
"The memory setting %s (which is %ld at present) has been exceeded. Try running Inform again with $%s=<some-larger-n"
"umber> on the command line.",
a1,
a2,
a1);
func1();
func10(error_message_buff);
}

original_code:
extern void memoryerror(char *s, int32 size)
{
    snprintf(error_message_buff, (256),
        "The memory setting %s (which is %ld at present) has been exceeded.  Try running Inform again with $%s=<some-larger-number> on the command line.",s,(long int) size,s);
    ellipsize_error_message_buff();
    fatalerror(error_message_buff);
}

canonical_original_code:
extern void memoryerror(char *s, int size)
{
    snprintf(error_message_buff, (256),
        "The memory setting %s (which is %ld at present) has been exceeded.  Try running Inform again with $%s=<some-larger-number> on the command line.",s,(long) size,s);
    ellipsize_error_message_buff();
    fatalerror(error_message_buff);
}


error

decompiled_code:
int __fastcall error(const char *a1)
{
if ( no_errors == 100 )
fatalerror("Too many errors: giving up");
return message(1, a1);
}

canonical_decompiled_code:
int __fastcall func14(const char *a1)
{
if ( no_errors == 100 )
func10("Too many errors: giving up");
return func2(1, a1);
}

original_code:
extern void error(char *s)
{ if (no_errors == 100)
        fatalerror("Too many errors: giving up");
    errors[no_errors] = no_syntax_lines;
    message(1,s);
}


decompiled_code:
int __fastcall error_named(const char *a1, const char *a2)
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
ellipsize_error_message_buff();
return error(error_message_buff);
}

canonical_decompiled_code:
int __fastcall func15(const char *a1, const char *a2)
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
func1();
return func14(error_message_buff);
}

original_code:
extern void error_named(char *s1, char *s2)
{ snprintf(error_message_buff, (256),"%s \"%s\"",s1,s2);
    ellipsize_error_message_buff();
    error(error_message_buff);
}


decompiled_code:
int __fastcall no_such_label(const char *a1)
{
return error_named("No such label as", a1);
}

canonical_decompiled_code:
int __fastcall func16(const char *a1)
{
return func15("No such label as", a1);
}

original_code:
extern void no_such_label(char *lname)
{ error_named("No such label as",lname);
}

variable_types:
lname
char *


decompiled_code:
int __fastcall error_numbered(const char *a1, unsigned int a2)
{
snprintf(error_message_buff, 0x100uLL, "%s %d.", a1, a2);
ellipsize_error_message_buff();
return error(error_message_buff);
}

canonical_decompiled_code:
int __fastcall func17(const char *a1, unsigned int a2)
{
snprintf(error_message_buff, 0x100uLL, "%s %d.", a1, a2);
func1();
return func14(error_message_buff);
}

original_code:
extern void error_numbered(char *s1, int val)
{
    snprintf(error_message_buff, (256),"%s %d.",s1,val);
    ellipsize_error_message_buff();
    error(error_message_buff);
}


decompiled_code:
int __fastcall error_named_at(const char *a1, const char *a2, int a3)
{
int v3; // er12
__int64 v4; // rbp
__int64 v5; // rbx
int v6; // er13
int result; // eax

v3 = ErrorReport;
v4 = *((_QWORD *)&ErrorReport + 1);
v5 = *((_QWORD *)&ErrorReport + 2);
if ( a3 != -1 )
{
ErrorReport = a3 / 0x800000;
*(&ErrorReport + 4) = a3 % 0x800000;
*(&ErrorReport + 5) = a3 / 0x800000 == 1;
}
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
ellipsize_error_message_buff();
v6 = concise_switch;
concise_switch = -1;
result = error(error_message_buff);
ErrorReport = v3;
*((_QWORD *)&ErrorReport + 1) = v4;
*((_QWORD *)&ErrorReport + 2) = v5;
concise_switch = v6;
return result;
}

canonical_decompiled_code:
int __fastcall func18(const char *a1, const char *a2, int a3)
{
int v3; // er12
__int64 v4; // rbp
__int64 v5; // rbx
int v6; // er13
int result; // eax

v3 = ErrorReport;
v4 = *((_QWORD *)&ErrorReport + 1);
v5 = *((_QWORD *)&ErrorReport + 2);
if ( a3 != -1 )
{
ErrorReport = a3 / 0x800000;
*(&ErrorReport + 4) = a3 % 0x800000;
*(&ErrorReport + 5) = a3 / 0x800000 == 1;
}
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
func1();
v6 = concise_switch;
concise_switch = -1;
result = func14(error_message_buff);
ErrorReport = v3;
*((_QWORD *)&ErrorReport + 1) = v4;
*((_QWORD *)&ErrorReport + 2) = v5;
concise_switch = v6;
return result;
}

original_code:
extern void error_named_at(char *s1, char *s2, int32 report_line)
{ int i;
    ErrorPosition E = ErrorReport;
    if (report_line != -1)
    { ErrorReport.file_number = report_line/(0x800000L);
        ErrorReport.line_number = report_line%(0x800000L);
        ErrorReport.main_flag = (ErrorReport.file_number == 1);
    }
    snprintf(error_message_buff, (256),"%s \"%s\"",s1,s2);
    ellipsize_error_message_buff();
    i = concise_switch; concise_switch = -1;
    error(error_message_buff);
    ErrorReport = E; concise_switch = i;
}

canonical_original_code:
extern void error_named_at(char *s1, char *s2, int report_line)
{ int i;
    struct ErrorPosition_s E = ErrorReport;
    if (report_line != -1)
    { ErrorReport.file_number = report_line/(0x800000L);
        ErrorReport.line_number = report_line%(0x800000L);
        ErrorReport.main_flag = (ErrorReport.file_number == 1);
    }
    snprintf(error_message_buff, (256),"%s \"%s\"",s1,s2);
    ellipsize_error_message_buff();
    i = concise_switch; concise_switch = -1;
    error(error_message_buff);
    ErrorReport = E; concise_switch = i;
}


decompiled_code:
int __fastcall ebf_error(const char *a1, const char *a2)
{
snprintf(error_message_buff, 0x100uLL, "Expected %s but found %s", a1, a2);
ellipsize_error_message_buff();
return error(error_message_buff);
}

canonical_decompiled_code:
int __fastcall func19(const char *a1, const char *a2)
{
snprintf(error_message_buff, 0x100uLL, "Expected %s but found %s", a1, a2);
func1();
return func14(error_message_buff);
}

original_code:
extern void ebf_error(char *s1, char *s2)
{ snprintf(error_message_buff, (256), "Expected %s but found %s", s1, s2);
    ellipsize_error_message_buff();
    error(error_message_buff);
}


decompiled_code:
int __fastcall char_error(const char *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
const char *v5; // rax
size_t v6; // rax

v2 = iso_to_unicode(a2);
v3 = v2;
if ( character_set_unicode )
{
snprintf(error_message_buff, 0x100uLL, "%s (unicode) $%04x", a1, (unsigned int)v2);
}
else
{
if ( v2 > 255 )
{
v5 = (const char *)name_of_iso_set(character_set_setting);
snprintf(error_message_buff, 0x100uLL, "%s (unicode) $%04x = (ISO %s) $%02x", a1, v3, v5, a2);
goto LABEL_7;
}
snprintf(error_message_buff, 0x100uLL, "%s (ISO Latin1) $%02x", a1, (unsigned int)v2);
}
if ( v3 - 32 <= 0x5E || v3 - 161 <= 0x5E && character_set_setting == 1 && !character_set_unicode )
{
v6 = strlen(error_message_buff);
snprintf(&error_message_buff[v6], 256 - (int)v6, ", i.e., '%c'", v3);
}
LABEL_7:
ellipsize_error_message_buff();
return error(error_message_buff);
}

canonical_decompiled_code:
int __fastcall func20(const char *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
const char *v5; // rax
size_t v6; // rax

v2 = iso_to_unicode(a2);
v3 = v2;
if ( character_set_unicode )
{
snprintf(error_message_buff, 0x100uLL, "%s (unicode) $%04x", a1, (unsigned int)v2);
}
else
{
if ( v2 > 255 )
{
v5 = (const char *)name_of_iso_set(character_set_setting);
snprintf(error_message_buff, 0x100uLL, "%s (unicode) $%04x = (ISO %s) $%02x", a1, v3, v5, a2);
goto LABEL_7;
}
snprintf(error_message_buff, 0x100uLL, "%s (ISO Latin1) $%02x", a1, (unsigned int)v2);
}
if ( v3 - 32 <= 0x5E || v3 - 161 <= 0x5E && character_set_setting == 1 && !character_set_unicode )
{
v6 = strlen(error_message_buff);
snprintf(&error_message_buff[v6], 256 - (int)v6, ", i.e., '%c'", v3);
}
LABEL_7:
func1();
return func14(error_message_buff);
}

original_code:
extern void char_error(char *s, int ch)
{ int32 uni;
    uni = iso_to_unicode(ch);
    if (character_set_unicode)
        snprintf(error_message_buff, (256), "%s (unicode) $%04x", s, uni);
    else if (uni >= 0x100)
    { snprintf(error_message_buff, (256),
            "%s (unicode) $%04x = (ISO %s) $%02x", s, uni,
            name_of_iso_set(character_set_setting), ch);
    }
    else
        snprintf(error_message_buff, (256), "%s (ISO Latin1) $%02x", s, uni);
    if (((uni>=32) && (uni<127))
        || (((uni >= 0xa1) && (uni <= 0xff))
        && (character_set_setting==1) && (!character_set_unicode)))
    { int curlen = strlen(error_message_buff);
        snprintf(error_message_buff+curlen, (256)-curlen,
            ", i.e., '%c'", uni);
    }
    ellipsize_error_message_buff();
    error(error_message_buff);
}

canonical_original_code:
extern void char_error(char *s, int ch)
{ int uni;
    uni = iso_to_unicode(ch);
    if (character_set_unicode)
        snprintf(error_message_buff, (256), "%s (unicode) $%04x", s, uni);
    else if (uni >= 0x100)
    { snprintf(error_message_buff, (256),
            "%s (unicode) $%04x = (ISO %s) $%02x", s, uni,
            name_of_iso_set(character_set_setting), ch);
    }
    else
        snprintf(error_message_buff, (256), "%s (ISO Latin1) $%02x", s, uni);
    if (((uni>=32) && (uni<127))
        || (((uni >= 0xa1) && (uni <= 0xff))
        && (character_set_setting==1) && (!character_set_unicode)))
    { int curlen = strlen(error_message_buff);
        snprintf(error_message_buff+curlen, (256)-curlen,
            ", i.e., '%c'", uni);
    }
    ellipsize_error_message_buff();
    error(error_message_buff);
}

variable_types: ch int

variable_types: uni int

variable_types: curlen int


decompiled_code:
int __fastcall unicode_char_error(const char *a1, unsigned int a2)
{
size_t v3; // rax

if ( (int)a2 <= 255 )
{
snprintf(error_message_buff, 0x100uLL, "%s (ISO Latin1) $%02x", a1, a2);
if ( a2 - 32 <= 0x5E )
{
LABEL_7:
v3 = strlen(error_message_buff);
snprintf(&error_message_buff[v3], 256 - (int)v3, ", i.e., '%c'", a2);
goto LABEL_5;
}
}
else
{
snprintf(error_message_buff, 0x100uLL, "%s (unicode) $%04x", a1, a2);
}
if ( a2 - 161 <= 0x5E && character_set_setting == 1 && !character_set_unicode )
goto LABEL_7;
LABEL_5:
ellipsize_error_message_buff();
return error(error_message_buff);
}

canonical_decompiled_code:
int __fastcall func21(const char *a1, unsigned int a2)
{
size_t v3; // rax

if ( (int)a2 <= 255 )
{
snprintf(error_message_buff, 0x100uLL, "%s (ISO Latin1) $%02x", a1, a2);
if ( a2 - 32 <= 0x5E )
{
LABEL_7:
v3 = strlen(error_message_buff);
snprintf(&error_message_buff[v3], 256 - (int)v3, ", i.e., '%c'", a2);
goto LABEL_5;
}
}
else
{
snprintf(error_message_buff, 0x100uLL, "%s (unicode) $%04x", a1, a2);
}
if ( a2 - 161 <= 0x5E && character_set_setting == 1 && !character_set_unicode )
goto LABEL_7;
LABEL_5:
func1();
return func14(error_message_buff);
}

original_code:
extern void unicode_char_error(char *s, int32 uni)
{
    if (uni >= 0x100)
        snprintf(error_message_buff, (256), "%s (unicode) $%04x", s, uni);
    else
        snprintf(error_message_buff, (256), "%s (ISO Latin1) $%02x", s, uni);
    if (((uni>=32) && (uni<127))
        || (((uni >= 0xa1) && (uni <= 0xff))
        && (character_set_setting==1) && (!character_set_unicode)))
    { int curlen = strlen(error_message_buff);
        snprintf(error_message_buff+curlen, (256)-curlen,
            ", i.e., '%c'", uni);
    }
    ellipsize_error_message_buff();
    error(error_message_buff);
}

canonical_original_code:
extern void unicode_char_error(char *s, int uni)
{
    if (uni >= 0x100)
        snprintf(error_message_buff, (256), "%s (unicode) $%04x", s, uni);
    else
        snprintf(error_message_buff, (256), "%s (ISO Latin1) $%02x", s, uni);
    if (((uni>=32) && (uni<127))
        || (((uni >= 0xa1) && (uni <= 0xff))
        && (character_set_setting==1) && (!character_set_unicode)))
    { int curlen = strlen(error_message_buff);
        snprintf(error_message_buff+curlen, (256)-curlen,
            ", i.e., '%c'", uni);
    }
    ellipsize_error_message_buff();
    error(error_message_buff);
}


decompiled_code:
int __fastcall link_error(const char *a1)
{
if ( no_errors == 100 )
fatalerror("Too many errors: giving up");
return message(3, a1);
}

canonical_decompiled_code:
int __fastcall func22(const char *a1)
{
if ( no_errors == 100 )
func10("Too many errors: giving up");
return func2(3, a1);
}

original_code:
extern void link_error(char *s)
{ if (no_errors==100) fatalerror("Too many errors: giving up");
    errors[no_errors] = no_syntax_lines;
    message(3,s);
}


decompiled_code:
int __fastcall link_error_named(const char *a1, const char *a2)
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
ellipsize_error_message_buff();
return link_error(error_message_buff);
}

canonical_decompiled_code:
int __fastcall func23(const char *a1, const char *a2)
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
func1();
return func22(error_message_buff);
}

original_code:
extern void link_error_named(char *s1, char *s2)
{ snprintf(error_message_buff, (256),"%s \"%s\"",s1,s2);
    ellipsize_error_message_buff();
    link_error(error_message_buff);
}


decompiled_code:
__int64 __fastcall compiler_error(const char *a1)
{
if ( no_link_errors > 0 || no_errors > 0 )
return 0LL;
if ( no_compiler_errors == 100 )
fatalerror("Too many compiler errors: giving up");
message(4, a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func24(const char *a1)
{
if ( no_link_errors > 0 || no_errors > 0 )
return 0LL;
if ( no_compiler_errors == 100 )
func10("Too many compiler errors: giving up");
func2(4, a1);
return 0xFFFFFFFFLL;
}

original_code:
extern int compiler_error(char *s)
{ if (no_link_errors > 0) return 0;
    if (no_errors > 0) return 0;
    if (no_compiler_errors==100)
        fatalerror("Too many compiler errors: giving up");
    message(4,s);
    return -1;
}


decompiled_code:
__int64 __fastcall compiler_error_named(const char *a1, const char *a2)
{
__int64 result; // rax

result = 0LL;
if ( no_link_errors <= 0 && no_errors <= 0 )
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
ellipsize_error_message_buff();
compiler_error(error_message_buff);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func25(const char *a1, const char *a2)
{
__int64 result; // rax

result = 0LL;
if ( no_link_errors <= 0 && no_errors <= 0 )
{
snprintf(error_message_buff, 0x100uLL, "%s \"%s\"", a1, a2);
func1();
func24(error_message_buff);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
extern int compiler_error_named(char *s1, char *s2)
{ if (no_link_errors > 0) return 0;
    if (no_errors > 0) return 0;
    snprintf(error_message_buff, (256), "%s \"%s\"",s1,s2);
    ellipsize_error_message_buff();
    compiler_error(error_message_buff);
    return -1;
}


decompiled_code:
void init_errors_vars()
{
forerrors_buff = 0LL;
no_errors = 0;
no_warnings = 0;
no_suppressed_warnings = 0;
no_compiler_errors = 0;
}

canonical_decompiled_code:
void func26()
{
forerrors_buff = 0LL;
no_errors = 0;
no_warnings = 0;
no_suppressed_warnings = 0;
no_compiler_errors = 0;
}

original_code:
extern void init_errors_vars(void)
{ forerrors_buff = ((void *)0);
    no_errors = 0; no_warnings = 0; no_suppressed_warnings = 0;
    no_compiler_errors = 0;
}

canonical_original_code:
extern void init_errors_vars()
{ forerrors_buff = ((void *)0);
    no_errors = 0; no_warnings = 0; no_suppressed_warnings = 0;
    no_compiler_errors = 0;
}