main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[24]; // [rsp+0h] [rbp-18h] BYREF

_isoc99_sscanf("$Revision: 1.20 $", "%*s %s", v4);
printf("\nSynchronet Node Display/Control Utility v%s\n\n", v4);
printf("COMPILER ERROR: sizeof(node_t)=%d instead of %d\n", 19LL, 15LL);
return -1;
}

original_code:
int main(int argc, char **argv)
{
 char str[256],ctrl_dir[41],*p,debug=0;
 int sys_nodes,node_num=0,onoff=0;
 int i,j,mode=0,misc;
 int modify=0;
 int loop=0;
 int pause=0;
 long value=0;
 node_t node;
 char revision[16];
 sscanf("$Revision: 1.20 $", "%*s %s", revision);
 printf("\nSynchronet Node Display/Control Utility v%s\n\n", revision);
 if(sizeof(node_t)!=15) {
  printf("COMPILER ERROR: sizeof(node_t)=%d instead of %d\n"
   ,sizeof(node_t),15);
  return(-1);
 }
 if(argc<2) {
  printf("usage: node [/debug] [action [on|off]] [node numbers] [...]"
   "\n\n");
  printf("actions (default is list):\n\n");
  printf("list        = list status\n");
  printf("anon        = anonymous user\n");
  printf("lock        = locked\n");
  printf("intr        = interrupt\n");
  printf("down        = shut-down\n");
  printf("rerun       = rerun\n");
  printf("event       = run event\n");
  printf("nopage      = page disable\n");
  printf("noalerts    = activity alerts disable\n");
  printf("status=#    = set status value\n");
  printf("useron=#    = set useron number\n");
  printf("action=#    = set action value\n");
  printf("errors=#    = set error counter\n");
  printf("conn=#      = set connection value\n");
  printf("misc=#      = set misc value\n");
  printf("aux=#       = set aux value\n");
  printf("extaux=#    = set extended aux value\n");
  exit(0); }
 p=getenv("SBBSCTRL");
 if(p==((void *)0)) {
  printf("\7\nSBBSCTRL environment variable is not set.\n");
  printf("This environment variable must be set to your CTRL directory.");
  printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
  exit(1); }
 sprintf(ctrl_dir,"%.40s",p);
 if(ctrl_dir[strlen(ctrl_dir)-1]!='\\'
  && ctrl_dir[strlen(ctrl_dir)-1]!='/')
  strcat(ctrl_dir,"/");
 sprintf(str,"%snode.dab",ctrl_dir);
 if((nodefile=sopen(str,02|0,2))==-1) {
  printf("\7\nError %d opening %s.\n",(*__errno_location ()),str);
  exit(1); }
 sys_nodes=filelength(nodefile)/sizeof(node_t);
 if(!sys_nodes) {
  printf("%s reflects 0 nodes!\n",str);
  exit(1); }
 for(i=1;i<argc;i++) {
  if(((*__ctype_b_loc ())[(int) ((argv[i][0]))] & (unsigned short int) _ISdigit))
   node_num=atoi(argv[i]);
  else {
   node_num=onoff=value=0;
   if(!strcasecmp(argv[i],"-DEBUG"))
    debug=1;
   if(!strcasecmp(argv[i],"-LOOP"))
    loop=1;
   if(!strcasecmp(argv[i],"-PAUSE"))
    pause=1;
   else if(!strcasecmp(argv[i],"LOCK"))
    mode=MODE_LOCK;
   else if(!strcasecmp(argv[i],"ANON"))
    mode=MODE_ANON;
   else if(!strcasecmp(argv[i],"INTR"))
    mode=MODE_INTR;
   else if(!strcasecmp(argv[i],"DOWN"))
    mode=MODE_DOWN;
   else if(!strcasecmp(argv[i],"RERUN"))
    mode=MODE_RRUN;
   else if(!strcasecmp(argv[i],"EVENT"))
    mode=MODE_EVENT;
   else if(!strcasecmp(argv[i],"NOPAGE"))
    mode=MODE_NOPAGE;
   else if(!strcasecmp(argv[i],"NOALERTS"))
    mode=MODE_NOALERTS;
   else if(!strcasecmp(argv[i],"ON"))
    onoff=1;
   else if(!strcasecmp(argv[i],"OFF"))
    onoff=2;
   else if(!strncasecmp(argv[i],"STATUS=",7)) {
    mode=MODE_STATUS;
    value=atoi(argv[i]+7); }
   else if(!strncasecmp(argv[i],"ERRORS=",7)) {
    mode=MODE_ERRORS;
    value=atoi(argv[i]+7); }
   else if(!strncasecmp(argv[i],"USERON=",7)) {
    mode=MODE_USERON;
    value=atoi(argv[i]+7); }
   else if(!strncasecmp(argv[i],"ACTION=",7)) {
    mode=MODE_ACTION;
    value=atoi(argv[i]+7); }
   else if(!strncasecmp(argv[i],"CONN=",5)) {
    mode=MODE_CONN;
    value=atoi(argv[i]+5); }
   else if(!strncasecmp(argv[i],"MISC=",5)) {
    mode=MODE_MISC;
    value=atoi(argv[i]+5); }
   else if(!strncasecmp(argv[i],"AUX=",4)) {
    mode=MODE_AUX;
    value=atoi(argv[i]+4); }
   else if(!strncasecmp(argv[i],"EXTAUX=",7)) {
    mode=MODE_EXTAUX;
    value=atoi(argv[i]+7); }
   }
  if(mode!=MODE_LIST)
   modify=1;
  if((mode && node_num) || i+1==argc)
   while(1) {
    for(j=1;j<=sys_nodes;j++)
     if(!node_num || j==node_num) {
      getnodedat(j,&node,modify);
      misc=0;
      switch(mode) {
       case MODE_ANON:
        misc=(1<<0);
        break;
       case MODE_LOCK:
        misc=(1<<1);
        break;
       case MODE_INTR:
        misc=(1<<2);
        break;
       case MODE_DOWN:
                 if(node.status==NODE_WFC)
                  node.status=NODE_OFFLINE;
        else
         misc=(1<<9);
        break;
       case MODE_RRUN:
        misc=(1<<7);
        break;
       case MODE_EVENT:
        misc=(1<<8);
        break;
       case MODE_NOPAGE:
        misc=(1<<4);
        break;
       case MODE_NOALERTS:
        misc=(1<<5);
        break;
       case MODE_STATUS:
        node.status=(unsigned char)value;
        break;
       case MODE_ERRORS:
        node.errors=(unsigned char)value;
        break;
       case MODE_ACTION:
        node.action=(unsigned char)value;
        break;
       case MODE_USERON:
        node.useron=(unsigned char)value;
        break;
       case MODE_MISC:
        node.misc=(unsigned char)value;
        break;
       case MODE_CONN:
        node.connection=(unsigned char)value;
        break;
       case MODE_AUX:
        node.aux=(unsigned char)value;
        break;
       case MODE_EXTAUX:
        node.extaux=value;
        break; }
      if(misc) {
       if(onoff==0)
        node.misc^=misc;
       else if(onoff==1)
        node.misc|=misc;
       else if(onoff==2)
        node.misc&=~misc; }
      if(modify)
       putnodedat(j,node);
      printnodedat(j,node);
      if(debug) {
       printf("status=%u\n",node.status);
       printf("errors=%u\n",node.errors);
       printf("action=%d\n",node.action);
       printf("useron=%u\n",node.useron);
       printf("conn=%u\n",node.connection);
       printf("misc=%u\n",node.misc);
       printf("aux=%u\n",node.aux);
       printf("extaux=%lu\n",node.extaux);
      }
      if(pause) {
       printf("Hit enter...");
       getchar();
       printf("\n");
      }
     }
    if(!loop)
     break;
    ({ int sleep_msecs=1000; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
    ;
   }
 }
 close(nodefile);
 return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char str[256]; char ctrl_dir[41]; char *p; char debug = 0;
 int sys_nodes; int node_num = 0; int onoff = 0;
 int i; int j; int mode = 0; int misc;
 int modify = 0;
 int loop = 0;
 int pause = 0;
 long value = 0;
 struct node_t node;
 char revision[16];
 sscanf("$Revision: 1.20 $", "%*s %s", revision);
 printf("\nSynchronet Node Display/Control Utility v%s\n\n", revision);
 if(sizeof(node_t)!=15) {
  printf("COMPILER ERROR: sizeof(node_t)=%d instead of %d\n"
   ,sizeof(node_t),15);
  return(-1);
 }
 if(argc<2) {
  printf("usage: node [/debug] [action [on|off]] [node numbers] [...]"
   "\n\n");
  printf("actions (default is list):\n\n");
  printf("list        = list status\n");
  printf("anon        = anonymous user\n");
  printf("lock        = locked\n");
  printf("intr        = interrupt\n");
  printf("down        = shut-down\n");
  printf("rerun       = rerun\n");
  printf("event       = run event\n");
  printf("nopage      = page disable\n");
  printf("noalerts    = activity alerts disable\n");
  printf("status=#    = set status value\n");
  printf("useron=#    = set useron number\n");
  printf("action=#    = set action value\n");
  printf("errors=#    = set error counter\n");
  printf("conn=#      = set connection value\n");
  printf("misc=#      = set misc value\n");
  printf("aux=#       = set aux value\n");
  printf("extaux=#    = set extended aux value\n");
  exit(0); }
 p=getenv("SBBSCTRL");
 if(p==((void *)0)) {
  printf("\7\nSBBSCTRL environment variable is not set.\n");
  printf("This environment variable must be set to your CTRL directory.");
  printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
  exit(1); }
 sprintf(ctrl_dir,"%.40s",p);
 if(ctrl_dir[strlen(ctrl_dir)-1]!='\\'
  && ctrl_dir[strlen(ctrl_dir)-1]!='/')
  strcat(ctrl_dir,"/");
 sprintf(str,"%snode.dab",ctrl_dir);
 if((nodefile=sopen(str,02|0,2))==-1) {
  printf("\7\nError %d opening %s.\n",(*__errno_location ()),str);
  exit(1); }
 sys_nodes=filelength(nodefile)/sizeof(node_t);
 if(!sys_nodes) {
  printf("%s reflects 0 nodes!\n",str);
  exit(1); }
 for(i=1;i<argc;i++) {
  if(((*__ctype_b_loc ())[(int) ((argv[i][0]))] & (unsigned short) _ISdigit))
   node_num=atoi(argv[i]);
  else {
   node_num=onoff=value=0;
   if(!strcasecmp(argv[i],"-DEBUG"))
    debug=1;
   if(!strcasecmp(argv[i],"-LOOP"))
    loop=1;
   if(!strcasecmp(argv[i],"-PAUSE"))
    pause=1;
   else if(!strcasecmp(argv[i],"LOCK"))
    mode=MODE_LOCK;
   else if(!strcasecmp(argv[i],"ANON"))
    mode=MODE_ANON;
   else if(!strcasecmp(argv[i],"INTR"))
    mode=MODE_INTR;
   else if(!strcasecmp(argv[i],"DOWN"))
    mode=MODE_DOWN;
   else if(!strcasecmp(argv[i],"RERUN"))
    mode=MODE_RRUN;
   else if(!strcasecmp(argv[i],"EVENT"))
    mode=MODE_EVENT;
   else if(!strcasecmp(argv[i],"NOPAGE"))
    mode=MODE_NOPAGE;
   else if(!strcasecmp(argv[i],"NOALERTS"))
    mode=MODE_NOALERTS;
   else if(!strcasecmp(argv[i],"ON"))
    onoff=1;
   else if(!strcasecmp(argv[i],"OFF"))
    onoff=2;
   else if(!strncasecmp(argv[i],"STATUS=",7)) {
    mode=MODE_STATUS;
    value=atoi(argv[i]+7); }
   else if(!strncasecmp(argv[i],"ERRORS=",7)) {
    mode=MODE_ERRORS;
    value=atoi(argv[i]+7); }
   else if(!strncasecmp(argv[i],"USERON=",7)) {
    mode=MODE_USERON;
    value=atoi(argv[i]+7); }
   else if(!strncasecmp(argv[i],"ACTION=",7)) {
    mode=MODE_ACTION;
    value=atoi(argv[i]+7); }
   else if(!strncasecmp(argv[i],"CONN=",5)) {
    mode=MODE_CONN;
    value=atoi(argv[i]+5); }
   else if(!strncasecmp(argv[i],"MISC=",5)) {
    mode=MODE_MISC;
    value=atoi(argv[i]+5); }
   else if(!strncasecmp(argv[i],"AUX=",4)) {
    mode=MODE_AUX;
    value=atoi(argv[i]+4); }
   else if(!strncasecmp(argv[i],"EXTAUX=",7)) {
    mode=MODE_EXTAUX;
    value=atoi(argv[i]+7); }
   }
  if(mode!=MODE_LIST)
   modify=1;
  if((mode && node_num) || i+1==argc)
   while(1) {
    for(j=1;j<=sys_nodes;j++)
     if(!node_num || j==node_num) {
      getnodedat(j,&node,modify);
      misc=0;
      switch(mode) {
       case MODE_ANON:
        misc=(1<<0);
        break;
       case MODE_LOCK:
        misc=(1<<1);
        break;
       case MODE_INTR:
        misc=(1<<2);
        break;
       case MODE_DOWN:
                 if(node.status==NODE_WFC)
                  node.status=NODE_OFFLINE;
        else
         misc=(1<<9);
        break;
       case MODE_RRUN:
        misc=(1<<7);
        break;
       case MODE_EVENT:
        misc=(1<<8);
        break;
       case MODE_NOPAGE:
        misc=(1<<4);
        break;
       case MODE_NOALERTS:
        misc=(1<<5);
        break;
       case MODE_STATUS:
        node.status=(unsigned char)value;
        break;
       case MODE_ERRORS:
        node.errors=(unsigned char)value;
        break;
       case MODE_ACTION:
        node.action=(unsigned char)value;
        break;
       case MODE_USERON:
        node.useron=(unsigned char)value;
        break;
       case MODE_MISC:
        node.misc=(unsigned char)value;
        break;
       case MODE_CONN:
        node.connection=(unsigned char)value;
        break;
       case MODE_AUX:
        node.aux=(unsigned char)value;
        break;
       case MODE_EXTAUX:
        node.extaux=value;
        break; }
      if(misc) {
       if(onoff==0)
        node.misc^=misc;
       else if(onoff==1)
        node.misc|=misc;
       else if(onoff==2)
        node.misc&=~misc; }
      if(modify)
       putnodedat(j,node);
      printnodedat(j,node);
      if(debug) {
       printf("status=%u\n",node.status);
       printf("errors=%u\n",node.errors);
       printf("action=%d\n",node.action);
       printf("useron=%u\n",node.useron);
       printf("conn=%u\n",node.connection);
       printf("misc=%u\n",node.misc);
       printf("aux=%u\n",node.aux);
       printf("extaux=%lu\n",node.extaux);
      }
      if(pause) {
       printf("Hit enter...");
       getchar();
       printf("\n");
      }
     }
    if(!loop)
     break;
    ({ int sleep_msecs = 1000; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
    ;
   }
 }
 close(nodefile);
 return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
str
char [256]

variable_types:
p
char *

variable_types: debug char

variable_types: onoff int

variable_types: j int

variable_types: mode int

variable_types: misc int

variable_types: modify int

variable_types: loop int

variable_types: pause int

variable_types: value long

variable_types:
revision
char [16]


itoa

repo: ftnapps/pkg-sbbs

decompiled_code:
char *__fastcall itoa(unsigned int a1, char *a2, __int64 a3)
{
switch ( (_DWORD)a3 )
{
case 0xA:
sprintf(a2, "%u", a1);
break;
case 0x10:
sprintf(a2, "%x", a1);
break;
case 8:
sprintf(a2, "%o", a1);
break;
default:
sprintf(a2, "bad radix: %d", a3);
break;
}
return a2;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1, char *a2, __int64 a3)
{
switch ( (_DWORD)a3 )
{
case 0xA:
sprintf(a2, "%u", a1);
break;
case 0x10:
sprintf(a2, "%x", a1);
break;
case 8:
sprintf(a2, "%o", a1);
break;
default:
sprintf(a2, "bad radix: %d", a3);
break;
}
return a2;
}

original_code:
char* itoa(int val, char* str, int radix)
{
 switch(radix) {
  case 8:
   sprintf(str,"%o",val);
   break;
  case 10:
   sprintf(str,"%u",val);
   break;
  case 16:
   sprintf(str,"%x",val);
   break;
  default:
   sprintf(str,"bad radix: %d",radix);
   break;
 }
 return(str);
}

canonical_original_code:
char *itoa(int val, char *str, int radix)
{
 switch(radix) {
  case 8:
   sprintf(str,"%o",val);
   break;
  case 10:
   sprintf(str,"%u",val);
   break;
  case 16:
   sprintf(str,"%x",val);
   break;
  default:
   sprintf(str,"bad radix: %d",radix);
   break;
 }
 return(str);
}

variable_types: val int

variable_types:
str
char *

variable_types: radix int

return_type: char *


ltoa

decompiled_code:
char *__fastcall ltoa(__int64 a1, char *a2, __int64 a3)
{
switch ( (_DWORD)a3 )
{
case 0xA:
sprintf(a2, "%lu", a1);
break;
case 0x10:
sprintf(a2, "%lx", a1);
break;
case 8:
sprintf(a2, "%lo", a1);
break;
default:
sprintf(a2, "bad radix: %d", a3);
break;
}
return a2;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, char *a2, __int64 a3)
{
switch ( (_DWORD)a3 )
{
case 0xA:
sprintf(a2, "%lu", a1);
break;
case 0x10:
sprintf(a2, "%lx", a1);
break;
case 8:
sprintf(a2, "%lo", a1);
break;
default:
sprintf(a2, "bad radix: %d", a3);
break;
}
return a2;
}

original_code:
char* ltoa(long val, char* str, int radix)
{
 switch(radix) {
  case 8:
   sprintf(str,"%lo",val);
   break;
  case 10:
   sprintf(str,"%lu",val);
   break;
  case 16:
   sprintf(str,"%lx",val);
   break;
  default:
   sprintf(str,"bad radix: %d",radix);
   break;
 }
 return(str);
}

canonical_original_code:
char *ltoa(long val, char *str, int radix)
{
 switch(radix) {
  case 8:
   sprintf(str,"%lo",val);
   break;
  case 10:
   sprintf(str,"%lu",val);
   break;
  case 16:
   sprintf(str,"%lx",val);
   break;
  default:
   sprintf(str,"bad radix: %d",radix);
   break;
 }
 return(str);
}

variable_types: val long


decompiled_code:
void __fastcall smb_freemsgtxt(void *a1)
{
if ( a1 )
free(a1);
}

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

original_code:
void smb_freemsgtxt(char* buf)
{
 if(buf!=((void *)0))
  free(buf);
}

canonical_original_code:
void smb_freemsgtxt(char *buf)
{
 if(buf!=((void *)0))
  free(buf);
}

variable_types:
buf
char *

return_type: void


redrwstr

decompiled_code:
__int64 __fastcall sbbs_t::redrwstr(sbbs_t *this, char *a2, int a3, int a4, char a5)
{
__int64 result; // rax
char s[271]; // [rsp+20h] [rbp-110h] BYREF
char v11; // [rsp+12Fh] [rbp-1h]

sprintf(s, "%-*.*s", a4, a4, a2);
v11 = a3;
while ( v11-- )
sbbs_t::outchar(this, 8);
if ( (a5 & 0x10) != 0 )
sbbs_t::bputs(this, s);
else
sbbs_t::rputs(this, s);
if ( sbbs_t::term_supports(this, 2LL) )
{
sbbs_t::cleartoeol(this);
result = (unsigned int)a3;
if ( a3 < a4 )
result = sbbs_t::cursor_left(this, a4 - a3);
}
else
{
while ( v11 < *((_QWORD *)this + 6068) - 1LL )
{
sbbs_t::outchar(this, 32);
++v11;
}
while ( 1 )
{
result = (unsigned int)v11;
if ( a4 >= (int)result )
break;
sbbs_t::outchar(this, 8);
--v11;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func0(sbbs_t *this, char *a2, int a3, int a4, char a5)
{
__int64 result; // rax
char s[271]; // [rsp+20h] [rbp-110h] BYREF
char v11; // [rsp+12Fh] [rbp-1h]

sprintf(s, "%-*.*s", a4, a4, a2);
v11 = a3;
while ( v11-- )
sbbs_t::outchar(this, 8);
if ( (a5 & 0x10) != 0 )
sbbs_t::bputs(this, s);
else
sbbs_t::rputs(this, s);
if ( sbbs_t::term_supports(this, 2LL) )
{
sbbs_t::cleartoeol(this);
result = (unsigned int)a3;
if ( a3 < a4 )
result = sbbs_t::cursor_left(this, a4 - a3);
}
else
{
while ( v11 < *((_QWORD *)this + 6068) - 1LL )
{
sbbs_t::outchar(this, 32);
++v11;
}
while ( 1 )
{
result = (unsigned int)v11;
if ( a4 >= (int)result )
break;
sbbs_t::outchar(this, 8);
--v11;
}
}
return result;
}

original_code:
void redrwstr(char *strin, int i, int l, long mode)
{
 char str[256],c;
 sprintf(str,"%-*.*s",l,l,strin);
 c=i;
 while(c--)
  outchar('\b');
 if(mode&(1<<4))
  bputs(str);
 else
  rputs(str);
 if(user_misc&(1<<0)) {
  bputs("\x1b[K");
  if(i<l)
   bprintf("\x1b[%dD",l-i);
 }
 else {
  while(c<79) {
   outchar(' ');
   c++;
  }
  while(c>l) {
   outchar('\b');
   c--;
  }
 }
}

canonical_original_code:
void redrwstr(char *strin, int i, int l, long mode)
{
 char str[256]; char c;
 sprintf(str,"%-*.*s",l,l,strin);
 c=i;
 while(c--)
  outchar('\b');
 if(mode&(1<<4))
  bputs(str);
 else
  rputs(str);
 if(user_misc&(1<<0)) {
  bputs("\x1b[K");
  if(i<l)
   bprintf("\x1b[%dD",l-i);
 }
 else {
  while(c<79) {
   outchar(' ');
   c++;
  }
  while(c>l) {
   outchar('\b');
   c--;
  }
 }
}

variable_types:
strin
char *

variable_types: i int

variable_types: l int

variable_types: mode long

variable_types:
str
char [256]

variable_types: c char


freeNameServerList

decompiled_code:
__int64 __fastcall freeNameServerList(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
return strListFree(&v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
return strListFree(&v2);
}

original_code:
void freeNameServerList(str_list_t list)
{
 strListFree(&list);
}

canonical_original_code:
void freeNameServerList(char **list)
{
 strListFree(&list);
}

variable_types:
list
char **


userdatdupe

decompiled_code:
__int64 __fastcall sbbs_t::userdatdupe(sbbs_t *this, unsigned int a2, unsigned int a3, unsigned int a4, char *a5, unsigned __int8 a6)
{
unsigned int v11; // [rsp+2Ch] [rbp-4h]

sbbs_t::bputs(this, *((char **)this + 5106));
v11 = userdatdupe((char *)this + 464, a2, a3, a4, a5, a6);
sbbs_t::bputs(this, *((char **)this + 5107));
return v11;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func2(sbbs_t *this, unsigned int a2, unsigned int a3, unsigned int a4, char *a5, unsigned __int8 a6)
{
unsigned int v11; // [rsp+2Ch] [rbp-4h]

sbbs_t::bputs(this, *((char **)this + 5106));
v11 = func2((char *)this + 464, a2, a3, a4, a5, a6);
sbbs_t::bputs(this, *((char **)this + 5107));
return v11;
}

variable_types: struct scfg_t { unsigned long size; int prepped; struct grp_t { char lname[-1]; unsigned char *ar; } **grp; unsigned short total_grps; struct sub_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short grp; unsigned long misc; struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; } faddr; } **sub; unsigned short total_subs; struct lib_t { char lname[-1]; unsigned char *ar; unsigned short offline_dir; } **lib; unsigned short total_libs; struct dir_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short maxfiles; unsigned long misc; } **dir; unsigned short total_dirs; struct txtsec_t { char code[-1]; char name[41]; unsigned char *ar; } **txtsec; unsigned short total_txtsecs; struct xtrnsec_t { char code[-1]; char name[41]; unsigned char *ar; } **xtrnsec; unsigned short total_xtrnsecs; struct xtrn_t { char code[-1]; char name[41]; unsigned char *ar; unsigned char type; unsigned short sec; unsigned long cost; } **xtrn; unsigned short total_xtrns; struct mdm_result_t { unsigned short code; char str[-1]; } *mdm_result; unsigned short mdm_results; struct prot_t { char mnemonic; char name[26]; unsigned char *ar; unsigned long misc; } **prot; unsigned short total_prots; struct fextr_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fextr; unsigned short total_fextrs; struct fcomp_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fcomp; unsigned short total_fcomps; struct fview_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fview; unsigned short total_fviews; struct ftest_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **ftest; unsigned short total_ftests; struct xedit_t { char code[-1]; unsigned char *ar; unsigned long misc; unsigned char type; } **xedit; unsigned short total_xedits; struct qhub_t { char id[-1]; unsigned short time; long last; } **qhub; unsigned short total_qhubs; struct phub_t { char days; unsigned short time; long last; } **phub; unsigned short total_phubs; struct chan_t { char code[-1]; char name[26]; char arstr[-1]; unsigned char *ar; unsigned short actset; unsigned long cost; } **chan; unsigned short total_chans; struct chatact_t { char cmd[-1]; unsigned short actset; } **chatact; unsigned short total_chatacts; struct actset_t { char name[26]; } **actset; unsigned short total_actsets; struct page_t { char cmd[-1]; unsigned char *ar; unsigned long misc; } **page; unsigned short total_pages; struct event_t { char code[-1]; unsigned short node; unsigned long misc; long last; } **event; unsigned short total_events; struct dlevent_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **dlevent; unsigned short total_dlevents; struct fidoaddr_t *faddr; unsigned short total_faddrs; struct swap_t { char cmd[-1]; } **swap; unsigned short total_swaps; struct natvpgm_t { char name[13]; unsigned long misc; } **natvpgm; unsigned short total_natvpgms; struct guru_t { char code[-1]; char name[26]; unsigned char *ar; } **guru; unsigned short total_gurus; struct shell_t { char code[-1]; char name[41]; unsigned char *ar; unsigned long misc; } **shell; unsigned short total_shells; struct hotkey_t { unsigned char key; char cmd[-1]; } **hotkey; unsigned short total_hotkeys; unsigned short com_base; unsigned long com_rate; char com_port; char mdm_init[64]; unsigned long mdm_misc; unsigned short mdm_reinit; unsigned short mdm_ansdelay; unsigned char mdm_rings; long sys_misc; char sys_pass[41]; char sys_name[41]; char sys_id[-1]; char sys_psname[13]; unsigned long sys_psnum; char sys_inetaddr[128]; char sys_location[41]; short sys_timezone; char sys_daily[-1]; char sys_logon[-1]; char sys_logout[-1]; unsigned short sys_pwdays; unsigned short sys_deldays; unsigned short sys_autodel; unsigned short sys_nodes; char sys_op[41]; char sys_guru[41]; unsigned char sys_exp_warn; char sys_def_stat; char sys_phonefmt[-1]; unsigned short sys_lastnode; unsigned short sys_autonode; char sys_chat_arstr[-1]; unsigned char *sys_chat_ar; long msg_misc; long file_misc; long xtrn_misc; char node_comspec[-1]; char node_editor[-1]; char node_viewer[-1]; char node_daily[-1]; unsigned char node_scrnlen; unsigned char node_scrnblank; unsigned long node_misc; unsigned short node_valuser; unsigned short node_ivt; unsigned char node_swap; char node_swapdir[-1]; unsigned short node_minbps; unsigned short node_num; char node_phone[13]; char node_arstr[-1]; unsigned char *node_ar; unsigned long node_cost; unsigned char node_dollars_per_call; unsigned short node_sem_check; unsigned short node_stat_check; char new_install; char new_pass[41]; char new_magic[21]; char new_sif[-1]; char new_sof[-1]; char new_level; unsigned long new_flags1; unsigned long new_flags2; unsigned long new_flags3; unsigned long new_flags4; unsigned long new_exempt; unsigned long new_rest; unsigned long new_cdt; unsigned long new_min; char new_xedit[-1]; unsigned short new_shell; unsigned long new_misc; unsigned short new_expire; unsigned char new_prot; char val_level[10]; unsigned long val_flags1[10]; unsigned long val_flags2[10]; unsigned long val_flags3[10]; unsigned long val_flags4[10]; unsigned long val_exempt[10]; unsigned long val_rest[10]; unsigned long val_cdt[10]; unsigned short val_expire[10]; unsigned char level_expireto[100]; unsigned short level_timepercall[100]; long level_freecdtperday[100]; long level_misc[100]; char expired_level; unsigned long expired_flags1; unsigned long expired_flags2; unsigned long expired_flags3; unsigned long expired_flags4; unsigned long expired_exempt; unsigned long expired_rest; unsigned short min_dspace; unsigned short max_batup; unsigned short max_batdn; unsigned short max_userxfer; unsigned long max_minutes; unsigned long max_qwkmsgs; char preqwk_arstr[-1]; unsigned char *preqwk_ar; unsigned short cdt_min_value; unsigned long cdt_per_dollar; unsigned short cdt_up_pct; unsigned short cdt_dn_pct; char node_dir[-1]; char ctrl_dir[-1]; char data_dir[-1]; char text_dir[-1]; char exec_dir[-1]; char temp_dir[-1]; char mods_dir[-1]; char logs_dir[-1]; char node_path[250][-1]; unsigned short sysop_dir; unsigned short user_dir; unsigned short upload_dir; char **altpath; unsigned short altpaths; unsigned short leech_pct; unsigned short leech_sec; unsigned long netmail_cost; char netmail_dir[-1]; unsigned short netmail_misc; unsigned long inetmail_misc; unsigned long inetmail_cost; char smtpmail_sem[-1]; char inetmail_sem[-1]; char echomail_dir[-1]; char fidofile_dir[-1]; char netmail_sem[-1]; char echomail_sem[-1]; char origline[51]; char qnet_tagline[128]; long uq; unsigned long mail_maxcrcs; unsigned short mail_maxage; struct fidoaddr_t dflt_faddr; char logon_mod[-1]; char logoff_mod[-1]; char newuser_mod[-1]; char login_mod[-1]; char logout_mod[-1]; char sync_mod[-1]; char expire_mod[-1]; char scfg_cmd[-1]; unsigned char smb_retry_time; unsigned short sec_warn; unsigned short sec_hangup; char *color; unsigned long total_colors; unsigned long ctrlkey_passthru; char wfc_cmd[10][-1]; char wfc_scmd[12][-1]; unsigned short user_backup_level; unsigned short mail_backup_level; } *

variable_types:
usernumber
unsigned int

variable_types:
offset
unsigned int

variable_types:
datlen
unsigned int

variable_types:
dat
char *

variable_types: del int

variable_types:
str
char [-1]

variable_types:
i
unsigned int

variable_types: file int

variable_types: l long

variable_types: length long

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

return_type: unsigned int

user_defined_types: struct scfg_t { unsigned long size; int prepped; struct grp_t **grp; unsigned short total_grps; struct sub_t **sub; unsigned short total_subs; struct lib_t **lib; unsigned short total_libs; struct dir_t **dir; unsigned short total_dirs; struct txtsec_t **txtsec; unsigned short total_txtsecs; struct xtrnsec_t **xtrnsec; unsigned short total_xtrnsecs; struct xtrn_t **xtrn; unsigned short total_xtrns; struct mdm_result_t *mdm_result; unsigned short mdm_results; struct prot_t **prot; unsigned short total_prots; struct fextr_t **fextr; unsigned short total_fextrs; struct fcomp_t **fcomp; unsigned short total_fcomps; struct fview_t **fview; unsigned short total_fviews; struct ftest_t **ftest; unsigned short total_ftests; struct xedit_t **xedit; unsigned short total_xedits; struct qhub_t **qhub; unsigned short total_qhubs; struct phub_t **phub; unsigned short total_phubs; struct chan_t **chan; unsigned short total_chans; struct chatact_t **chatact; unsigned short total_chatacts; struct actset_t **actset; unsigned short total_actsets; struct page_t **page; unsigned short total_pages; struct event_t **event; unsigned short total_events; struct dlevent_t **dlevent; unsigned short total_dlevents; struct fidoaddr_t *faddr; unsigned short total_faddrs; struct swap_t **swap; unsigned short total_swaps; struct natvpgm_t **natvpgm; unsigned short total_natvpgms; struct guru_t **guru; unsigned short total_gurus; struct shell_t **shell; unsigned short total_shells; struct hotkey_t **hotkey; unsigned short total_hotkeys; unsigned short com_base; unsigned long com_rate; char com_port; char mdm_init[64]; unsigned long mdm_misc; unsigned short mdm_reinit; unsigned short mdm_ansdelay; unsigned char mdm_rings; long sys_misc; char sys_pass[41]; char sys_name[41]; char sys_id[-1]; char sys_psname[13]; unsigned long sys_psnum; char sys_inetaddr[128]; char sys_location[41]; short sys_timezone; char sys_daily[-1]; char sys_logon[-1]; char sys_logout[-1]; unsigned short sys_pwdays; unsigned short sys_deldays; unsigned short sys_autodel; unsigned short sys_nodes; char sys_op[41]; char sys_guru[41]; unsigned char sys_exp_warn; char sys_def_stat; char sys_phonefmt[-1]; unsigned short sys_lastnode; unsigned short sys_autonode; char sys_chat_arstr[-1]; unsigned char *sys_chat_ar; long msg_misc; long file_misc; long xtrn_misc; char node_comspec[-1]; char node_editor[-1]; char node_viewer[-1]; char node_daily[-1]; unsigned char node_scrnlen; unsigned char node_scrnblank; unsigned long node_misc; unsigned short node_valuser; unsigned short node_ivt; unsigned char node_swap; char node_swapdir[-1]; unsigned short node_minbps; unsigned short node_num; char node_phone[13]; char node_arstr[-1]; unsigned char *node_ar; unsigned long node_cost; unsigned char node_dollars_per_call; unsigned short node_sem_check; unsigned short node_stat_check; char new_install; char new_pass[41]; char new_magic[21]; char new_sif[-1]; char new_sof[-1]; char new_level; unsigned long new_flags1; unsigned long new_flags2; unsigned long new_flags3; unsigned long new_flags4; unsigned long new_exempt; unsigned long new_rest; unsigned long new_cdt; unsigned long new_min; char new_xedit[-1]; unsigned short new_shell; unsigned long new_misc; unsigned short new_expire; unsigned char new_prot; char val_level[10]; unsigned long val_flags1[10]; unsigned long val_flags2[10]; unsigned long val_flags3[10]; unsigned long val_flags4[10]; unsigned long val_exempt[10]; unsigned long val_rest[10]; unsigned long val_cdt[10]; unsigned short val_expire[10]; unsigned char level_expireto[100]; unsigned short level_timepercall[100]; long level_freecdtperday[100]; long level_misc[100]; char expired_level; unsigned long expired_flags1; unsigned long expired_flags2; unsigned long expired_flags3; unsigned long expired_flags4; unsigned long expired_exempt; unsigned long expired_rest; unsigned short min_dspace; unsigned short max_batup; unsigned short max_batdn; unsigned short max_userxfer; unsigned long max_minutes; unsigned long max_qwkmsgs; char preqwk_arstr[-1]; unsigned char *preqwk_ar; unsigned short cdt_min_value; unsigned long cdt_per_dollar; unsigned short cdt_up_pct; unsigned short cdt_dn_pct; char node_dir[-1]; char ctrl_dir[-1]; char data_dir[-1]; char text_dir[-1]; char exec_dir[-1]; char temp_dir[-1]; char mods_dir[-1]; char logs_dir[-1]; char node_path[250][-1]; unsigned short sysop_dir; unsigned short user_dir; unsigned short upload_dir; char **altpath; unsigned short altpaths; unsigned short leech_pct; unsigned short leech_sec; unsigned long netmail_cost; char netmail_dir[-1]; unsigned short netmail_misc; unsigned long inetmail_misc; unsigned long inetmail_cost; char smtpmail_sem[-1]; char inetmail_sem[-1]; char echomail_dir[-1]; char fidofile_dir[-1]; char netmail_sem[-1]; char echomail_sem[-1]; char origline[51]; char qnet_tagline[128]; long uq; unsigned long mail_maxcrcs; unsigned short mail_maxage; struct fidoaddr_t dflt_faddr; char logon_mod[-1]; char logoff_mod[-1]; char newuser_mod[-1]; char login_mod[-1]; char logout_mod[-1]; char sync_mod[-1]; char expire_mod[-1]; char scfg_cmd[-1]; unsigned char smb_retry_time; unsigned short sec_warn; unsigned short sec_hangup; char *color; unsigned long total_colors; unsigned long ctrlkey_passthru; char wfc_cmd[10][-1]; char wfc_scmd[12][-1]; unsigned short user_backup_level; unsigned short mail_backup_level; }

user_defined_types: struct sub_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short grp; unsigned long misc; struct fidoaddr_t faddr; }


decompiled_code:
__int64 __fastcall compare_index(const void *a1, const void *a2)
{
return (unsigned int)*((_QWORD *)a1 + 2) - *((_DWORD *)a2 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (unsigned int)*((_QWORD *)a1 + 2) - *((_DWORD *)a2 + 4);
}

original_code:
int compare_index(const idxrec_t* idx1, const idxrec_t* idx2)
{
 return(idx1->number - idx2->number);
}

canonical_original_code:
int compare_index(struct idxrec_t *idx1, struct idxrec_t *idx2)
{
 return(idx1->number - idx2->number);
}

variable_types: struct idxrec_t { unsigned short to; unsigned short from; unsigned short subj; unsigned short attr; unsigned long offset; unsigned long number; unsigned long time; } *

return_type: int


decompiled_code:
void unlock_msgbase(void)
{
unsigned int v0; // eax

if ( (unsigned int)smb_islocked(smb) )
{
v0 = smb_unlock(smb);
if ( v0 )
printf("smb_unlock returned %d: %s\n", v0, (const char *)(unsigned int)((_DWORD)smb + 240));
}
}

canonical_decompiled_code:
void func1(void)
{
unsigned int v0; // eax

if ( (unsigned int)smb_islocked(smb) )
{
v0 = smb_unlock(smb);
if ( v0 )
printf("smb_unlock returned %d: %s\n", v0, (const char *)(unsigned int)((_DWORD)smb + 240));
}
}

original_code:
void unlock_msgbase(void)
{
 int i;
 if(smb_islocked(&smb) && (i=smb_unlock(&smb))!=0)
  printf("smb_unlock returned %d: %s\n",i,smb.last_error);
}

canonical_original_code:
void unlock_msgbase()
{
 int i;
 if(smb_islocked(&smb) && (i=smb_unlock(&smb))!=0)
  printf("smb_unlock returned %d: %s\n",i,smb.last_error);
}

variable_types: i int


fixsmb

decompiled_code:
__int64 __fastcall fixsmb(char *src)
{
const char *v1; // rax
const char *v2; // rbx
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // ebx
unsigned int v6; // ebx
unsigned int v7; // ebx
unsigned int v8; // ebx
int v9; // eax
int v10; // eax
int v11; // eax
unsigned int v12; // eax
unsigned __int64 v13; // rbp
unsigned __int64 i; // rbx
unsigned int v15; // eax
unsigned __int64 v16; // rbp
unsigned __int64 j; // rbx
unsigned int v18; // eax
unsigned __int64 v19; // rbx
__int64 v20; // r15
float v21; // xmm0_4
float v22; // xmm1_4
__int64 v23; // r13
void *v24; // r14
unsigned int v25; // eax
unsigned int v26; // eax
unsigned int v27; // eax
unsigned int v28; // er12
__int64 v29; // rax
unsigned int v30; // eax
__int64 v32; // [rsp+8h] [rbp-210h]
char v33[8]; // [rsp+10h] [rbp-208h] BYREF
unsigned __int64 v34; // [rsp+18h] [rbp-200h]
unsigned __int16 v35; // [rsp+3Ah] [rbp-1DEh]
__int64 v36; // [rsp+44h] [rbp-1D4h]
__int64 v37; // [rsp+60h] [rbp-1B8h]
const char *v38; // [rsp+B8h] [rbp-160h]
__int64 v39; // [rsp+1A8h] [rbp-70h]
int ptr; // [rsp+1D8h] [rbp-40h] BYREF
char v41[57]; // [rsp+1DFh] [rbp-39h] BYREF

memset(smb, 0, sizeof(smb));
strncpy(smb, src, 0x7FuLL);
v1 = (const char *)getfext(smb);
if ( v1 )
{
v2 = v1;
if ( !strcasecmp(v1, ".shd") )
*v2 = 0;
}
printf("Opening %s\n", smb);
v3 = smb_open(smb);
if ( v3 )
{
printf("smb_open returned %d: %s\n", v3, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
v4 = smb_lock(smb);
if ( v4 )
{
printf("smb_lock returned %d: %s\n", v4, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
v5 = smb_locksmbhdr(smb);
if ( v5 )
{
smb_close(smb);
printf("smb_locksmbhdr returned %d: %s\n", v5, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
v6 = smb_getstatus(smb);
if ( v6 )
{
smb_unlocksmbhdr(smb);
smb_close(smb);
printf("smb_getstatus returned %d: %s\n", v6, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
if ( (smb[234] & 2) == 0 )
{
v7 = smb_open_fp(smb, (unsigned int)((_DWORD)smb + 160), 1LL);
if ( v7 )
{
smb_close(smb);
printf("smb_open_ha returned %d: %s\n", v7, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
v8 = smb_open_fp(smb, (unsigned int)((_DWORD)smb + 152), 1LL);
if ( v8 )
{
smb_close(smb);
printf("smb_open_da returned %d: %s\n", v8, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
rewind(*(FILE **)&smb[160]);
v9 = fileno(*(FILE **)&smb[160]);
ftruncate(v9, 0LL);
rewind(*(FILE **)&smb[152]);
v10 = fileno(*(FILE **)&smb[152]);
ftruncate(v10, 0LL);
}
rewind(*(FILE **)&smb[144]);
v11 = fileno(*(FILE **)&smb[144]);
ftruncate(v11, 0LL);
if ( (smb[234] & 2) != 0 )
{
v18 = fileno(*(FILE **)&smb[136]);
v16 = filelength(v18);
}
else
{
v12 = fileno(*(FILE **)&smb[128]);
v13 = filelength(v12);
ptr = 0;
if ( v13 )
{
for ( i = 0LL; i < v13; i += 256LL )
fwrite(&ptr, 2uLL, 1uLL, *(FILE **)&smb[152]);
}
v15 = fileno(*(FILE **)&smb[136]);
v16 = filelength(v15);
v41[0] = 0;
if ( !v16 )
{
v20 = 0LL;
goto LABEL_65;
}
for ( j = 0LL; j < v16; j += 256LL )
fwrite(v41, 1uLL, 1uLL, *(FILE **)&smb[160]);
}
v19 = *(_QWORD *)&smb[208];
if ( v16 > v19 )
{
v20 = 0LL;
while ( 1 )
{
if ( (v16 & 0x8000000000000000LL) != 0LL )
v21 = (float)(int)(v16 & 1 | (v16 >> 1)) + (float)(int)(v16 & 1 | (v16 >> 1));
else
v21 = (float)(int)v16;
if ( (v19 & 0x8000000000000000LL) != 0LL )
v22 = (float)(int)(v19 & 1 | (v19 >> 1)) + (float)(int)(v19 & 1 | (v19 >> 1));
else
v22 = (float)(int)v19;
printf("\r%2lu%% ", (unsigned int)(int)(100.0 / (float)(v21 / v22)));
v34 = v19;
v27 = smb_lockmsghdr(smb, v33);
if ( v27 )
{
printf("\n(%06lX) smb_lockmsghdr returned %d:\n%s\n", v19, v27, (const char *)(unsigned int)((_DWORD)smb + 240));
v23 = 256LL;
goto LABEL_47;
}
v28 = smb_getmsghdr(smb, v33);
smb_unlockmsghdr(smb, v33);
if ( v28 )
{
printf("\n(%06lX) smb_getmsghdr returned %d:\n%s\n", v19, v28, (const char *)(unsigned int)((_DWORD)smb + 240));
v23 = 256LL;
goto LABEL_47;
}
v29 = smb_getmsghdrlen(v33);
v32 = smb_hdrblocks(v29);
v23 = v32 << 8;
printf("#%-5lu (%06lX) %-25.25s ", v37, v19, v38);
if ( (v35 & 0x10) == 0 )
break;
v25 = smb_hashmsg(smb, v33, 0LL, 1LL);
if ( v25 )
{
v24 = 0LL;
LABEL_34:
printf("!ERROR %d hashing message\n", v25);
LABEL_35:
if ( v24 )
free(v24);
}
if ( (v35 & 0x10) != 0 )
{
puts("Not indexing deleted message");
goto LABEL_45;
}
if ( !v37 )
{
puts("Not indexing invalid message number (0)!");
goto LABEL_45;
}
v39 = v20;
if ( renumber )
v37 = v20 + 1;
if ( (v36 & 2) != 0 )
{
puts("Removing 'in transit' attribute");
v36 &= 0xFFFFFFFFFFFFFFFDLL;
}
v26 = smb_putmsg(smb, v33);
if ( !v26 )
{
++v20;
LABEL_45:
if ( (smb[234] & 2) == 0 )
{
fseek(*(FILE **)&smb[160], (v19 - *(_QWORD *)&smb[208]) >> 8, 0);
v41[0] = ((v35 >> 4) ^ 1) & 1;
if ( (int)v32 > 0 )
{
do
{
fputc(v41[0], *(FILE **)&smb[160]);
++v28;
}
while ( v28 != (_DWORD)v32 );
}
if ( (v35 & 0x10) == 0 )
smb_incmsg_dfields(smb, v33, 1LL);
}
smb_freemsgmem(v33);
goto LABEL_47;
}
printf("\nsmb_putmsg returned %d: %s\n", v26, (const char *)(unsigned int)((_DWORD)smb + 240));
LABEL_47:
v19 += v23;
if ( v16 <= v19 )
goto LABEL_65;
}
v24 = (void *)smb_getmsgtxt(smb, v33, 4LL);
v25 = smb_hashmsg(smb, v33, v24, 1LL);
if ( v25 )
goto LABEL_34;
goto LABEL_35;
}
v20 = 0LL;
LABEL_65:
printf("\r%79s\r100%%\n", (const char *)&unk_2CE6);
*(_QWORD *)&smb[200] = v20;
if ( renumber )
*(_QWORD *)&smb[192] = v20;
else
sort_index((__int64)smb);
printf("Saving message base status (%lu total messages).\n", v20);
v30 = smb_putstatus(smb);
if ( v30 )
printf("\nsmb_putstatus returned %d: %s\n", v30, (const char *)(unsigned int)((_DWORD)smb + 240));
smb_unlocksmbhdr(smb);
puts("Closing message base.");
smb_close(smb);
unlock_msgbase();
puts("Done.");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src)
{
const char *v1; // rax
const char *v2; // rbx
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // ebx
unsigned int v6; // ebx
unsigned int v7; // ebx
unsigned int v8; // ebx
int v9; // eax
int v10; // eax
int v11; // eax
unsigned int v12; // eax
unsigned __int64 v13; // rbp
unsigned __int64 i; // rbx
unsigned int v15; // eax
unsigned __int64 v16; // rbp
unsigned __int64 j; // rbx
unsigned int v18; // eax
unsigned __int64 v19; // rbx
__int64 v20; // r15
float v21; // xmm0_4
float v22; // xmm1_4
__int64 v23; // r13
void *v24; // r14
unsigned int v25; // eax
unsigned int v26; // eax
unsigned int v27; // eax
unsigned int v28; // er12
__int64 v29; // rax
unsigned int v30; // eax
__int64 v32; // [rsp+8h] [rbp-210h]
char v33[8]; // [rsp+10h] [rbp-208h] BYREF
unsigned __int64 v34; // [rsp+18h] [rbp-200h]
unsigned __int16 v35; // [rsp+3Ah] [rbp-1DEh]
__int64 v36; // [rsp+44h] [rbp-1D4h]
__int64 v37; // [rsp+60h] [rbp-1B8h]
const char *v38; // [rsp+B8h] [rbp-160h]
__int64 v39; // [rsp+1A8h] [rbp-70h]
int ptr; // [rsp+1D8h] [rbp-40h] BYREF
char v41[57]; // [rsp+1DFh] [rbp-39h] BYREF

memset(smb, 0, sizeof(smb));
strncpy(smb, src, 0x7FuLL);
v1 = (const char *)getfext(smb);
if ( v1 )
{
v2 = v1;
if ( !strcasecmp(v1, ".shd") )
*v2 = 0;
}
printf("Opening %s\n", smb);
v3 = smb_open(smb);
if ( v3 )
{
printf("smb_open returned %d: %s\n", v3, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
v4 = smb_lock(smb);
if ( v4 )
{
printf("smb_lock returned %d: %s\n", v4, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
v5 = smb_locksmbhdr(smb);
if ( v5 )
{
smb_close(smb);
printf("smb_locksmbhdr returned %d: %s\n", v5, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
v6 = smb_getstatus(smb);
if ( v6 )
{
smb_unlocksmbhdr(smb);
smb_close(smb);
printf("smb_getstatus returned %d: %s\n", v6, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
if ( (smb[234] & 2) == 0 )
{
v7 = smb_open_fp(smb, (unsigned int)((_DWORD)smb + 160), 1LL);
if ( v7 )
{
smb_close(smb);
printf("smb_open_ha returned %d: %s\n", v7, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
v8 = smb_open_fp(smb, (unsigned int)((_DWORD)smb + 152), 1LL);
if ( v8 )
{
smb_close(smb);
printf("smb_open_da returned %d: %s\n", v8, (const char *)(unsigned int)((_DWORD)smb + 240));
exit(1);
}
rewind(*(FILE **)&smb[160]);
v9 = fileno(*(FILE **)&smb[160]);
ftruncate(v9, 0LL);
rewind(*(FILE **)&smb[152]);
v10 = fileno(*(FILE **)&smb[152]);
ftruncate(v10, 0LL);
}
rewind(*(FILE **)&smb[144]);
v11 = fileno(*(FILE **)&smb[144]);
ftruncate(v11, 0LL);
if ( (smb[234] & 2) != 0 )
{
v18 = fileno(*(FILE **)&smb[136]);
v16 = filelength(v18);
}
else
{
v12 = fileno(*(FILE **)&smb[128]);
v13 = filelength(v12);
ptr = 0;
if ( v13 )
{
for ( i = 0LL; i < v13; i += 256LL )
fwrite(&ptr, 2uLL, 1uLL, *(FILE **)&smb[152]);
}
v15 = fileno(*(FILE **)&smb[136]);
v16 = filelength(v15);
v41[0] = 0;
if ( !v16 )
{
v20 = 0LL;
goto LABEL_65;
}
for ( j = 0LL; j < v16; j += 256LL )
fwrite(v41, 1uLL, 1uLL, *(FILE **)&smb[160]);
}
v19 = *(_QWORD *)&smb[208];
if ( v16 > v19 )
{
v20 = 0LL;
while ( 1 )
{
if ( (v16 & 0x8000000000000000LL) != 0LL )
v21 = (float)(int)(v16 & 1 | (v16 >> 1)) + (float)(int)(v16 & 1 | (v16 >> 1));
else
v21 = (float)(int)v16;
if ( (v19 & 0x8000000000000000LL) != 0LL )
v22 = (float)(int)(v19 & 1 | (v19 >> 1)) + (float)(int)(v19 & 1 | (v19 >> 1));
else
v22 = (float)(int)v19;
printf("\r%2lu%% ", (unsigned int)(int)(100.0 / (float)(v21 / v22)));
v34 = v19;
v27 = smb_lockmsghdr(smb, v33);
if ( v27 )
{
printf("\n(%06lX) smb_lockmsghdr returned %d:\n%s\n", v19, v27, (const char *)(unsigned int)((_DWORD)smb + 240));
v23 = 256LL;
goto LABEL_47;
}
v28 = smb_getmsghdr(smb, v33);
smb_unlockmsghdr(smb, v33);
if ( v28 )
{
printf("\n(%06lX) smb_getmsghdr returned %d:\n%s\n", v19, v28, (const char *)(unsigned int)((_DWORD)smb + 240));
v23 = 256LL;
goto LABEL_47;
}
v29 = smb_getmsghdrlen(v33);
v32 = smb_hdrblocks(v29);
v23 = v32 << 8;
printf("#%-5lu (%06lX) %-25.25s ", v37, v19, v38);
if ( (v35 & 0x10) == 0 )
break;
v25 = smb_hashmsg(smb, v33, 0LL, 1LL);
if ( v25 )
{
v24 = 0LL;
LABEL_34:
printf("!ERROR %d hashing message\n", v25);
LABEL_35:
if ( v24 )
free(v24);
}
if ( (v35 & 0x10) != 0 )
{
puts("Not indexing deleted message");
goto LABEL_45;
}
if ( !v37 )
{
puts("Not indexing invalid message number (0)!");
goto LABEL_45;
}
v39 = v20;
if ( renumber )
v37 = v20 + 1;
if ( (v36 & 2) != 0 )
{
puts("Removing 'in transit' attribute");
v36 &= 0xFFFFFFFFFFFFFFFDLL;
}
v26 = smb_putmsg(smb, v33);
if ( !v26 )
{
++v20;
LABEL_45:
if ( (smb[234] & 2) == 0 )
{
fseek(*(FILE **)&smb[160], (v19 - *(_QWORD *)&smb[208]) >> 8, 0);
v41[0] = ((v35 >> 4) ^ 1) & 1;
if ( (int)v32 > 0 )
{
do
{
fputc(v41[0], *(FILE **)&smb[160]);
++v28;
}
while ( v28 != (_DWORD)v32 );
}
if ( (v35 & 0x10) == 0 )
smb_incmsg_dfields(smb, v33, 1LL);
}
smb_freemsgmem(v33);
goto LABEL_47;
}
printf("\nsmb_putmsg returned %d: %s\n", v26, (const char *)(unsigned int)((_DWORD)smb + 240));
LABEL_47:
v19 += v23;
if ( v16 <= v19 )
goto LABEL_65;
}
v24 = (void *)smb_getmsgtxt(smb, v33, 4LL);
v25 = smb_hashmsg(smb, v33, v24, 1LL);
if ( v25 )
goto LABEL_34;
goto LABEL_35;
}
v20 = 0LL;
LABEL_65:
printf("\r%79s\r100%%\n", (const char *)&unk_2CE6);
*(_QWORD *)&smb[200] = v20;
if ( renumber )
*(_QWORD *)&smb[192] = v20;
else
func2((__int64)smb);
printf("Saving message base status (%lu total messages).\n", v20);
v30 = smb_putstatus(smb);
if ( v30 )
printf("\nsmb_putstatus returned %d: %s\n", v30, (const char *)(unsigned int)((_DWORD)smb + 240));
smb_unlocksmbhdr(smb);
puts("Closing message base.");
smb_close(smb);
func1();
puts("Done.");
return 0LL;
}

original_code:
int fixsmb(char* sub)
{
 char* p;
 char* text;
 char c;
 int i,w;
 ulong l,length,size,n;
 smbmsg_t msg;
 memset(&smb,0,sizeof(smb));
 (strncpy(smb.file,sub,sizeof(smb.file)), smb.file[sizeof(smb.file)-1]=0);
 if((p=getfext(smb.file))!=((void *)0) && strcasecmp(p,".shd")==0)
  *p=0;
 printf("Opening %s\n",smb.file);
 if((i=smb_open(&smb))!=0) {
  printf("smb_open returned %d: %s\n",i,smb.last_error);
  exit(1);
 }
 if((i=smb_lock(&smb))!=0) {
  printf("smb_lock returned %d: %s\n",i,smb.last_error);
  exit(1);
 }
 if((i=smb_locksmbhdr(&smb))!=0) {
  smb_close(&smb);
  printf("smb_locksmbhdr returned %d: %s\n",i,smb.last_error);
  exit(1);
 }
 if((i=smb_getstatus(&smb))!=0) {
  smb_unlocksmbhdr(&smb);
  smb_close(&smb);
  printf("smb_getstatus returned %d: %s\n",i,smb.last_error);
  exit(1);
 }
 if(!(smb.status.attr&2)) {
  if((i=smb_open_fp(&smb,&(&smb)->sha_fp,1))!=0) {
   smb_close(&smb);
   printf("smb_open_ha returned %d: %s\n",i,smb.last_error);
   exit(1);
  }
  if((i=smb_open_fp(&smb,&(&smb)->sda_fp,1))!=0) {
   smb_close(&smb);
   printf("smb_open_da returned %d: %s\n",i,smb.last_error);
   exit(1);
  }
  rewind(smb.sha_fp);
  ftruncate(fileno(smb.sha_fp),0L);
  rewind(smb.sda_fp);
  ftruncate(fileno(smb.sda_fp),0L);
 }
 rewind(smb.sid_fp);
 ftruncate(fileno(smb.sid_fp),0L);
 if(!(smb.status.attr&2)) {
  length=filelength(fileno(smb.sdt_fp));
  w=0;
  for(l=0;l<length;l+=256)
   fwrite(&w,2,1,smb.sda_fp);
  length=filelength(fileno(smb.shd_fp));
  c=0;
  for(l=0;l<length;l+=256)
   fwrite(&c,1,1,smb.sha_fp);
 } else
  length=filelength(fileno(smb.shd_fp));
 n=0;
 for(l=smb.status.header_offset;l<length;l+=size) {
  size=256;
  printf("\r%2lu%%  ",(long)(100.0/((float)length/l)));
  msg.idx.offset=l;
  if((i=smb_lockmsghdr(&smb,&msg))!=0) {
   printf("\n(%06lX) smb_lockmsghdr returned %d:\n%s\n",l,i,smb.last_error);
   continue;
  }
  i=smb_getmsghdr(&smb,&msg);
  smb_unlockmsghdr(&smb,&msg);
  if(i!=0) {
   printf("\n(%06lX) smb_getmsghdr returned %d:\n%s\n",l,i,smb.last_error);
   continue;
  }
  size=smb_hdrblocks(smb_getmsghdrlen(&msg))*256;
  printf("#%-5lu (%06lX) %-25.25s ",msg.hdr.number,l,msg.from);
  if(msg.hdr.attr&(1<<4))
   text=((void *)0);
  else
   text=smb_getmsgtxt(&smb,&msg,(1<<2));
  i=smb_hashmsg(&smb,&msg,text,1 );
  if(i!=0)
   printf("!ERROR %d hashing message\n", i);
  if(text!=((void *)0))
   free(text);
  if(msg.hdr.attr&(1<<4))
   printf("Not indexing deleted message\n");
  else if(msg.hdr.number==0)
   printf("Not indexing invalid message number (0)!\n");
  else {
   msg.offset=n;
   if(renumber)
    msg.hdr.number=n+1;
   if(msg.hdr.netattr&(1<<1)) {
    printf("Removing 'in transit' attribute\n");
    msg.hdr.netattr&=~(1<<1);
   }
   if((i=smb_putmsg(&smb,&msg))!=0) {
    printf("\nsmb_putmsg returned %d: %s\n",i,smb.last_error);
    continue;
   }
   n++;
  }
  if(!(smb.status.attr&2)) {
   fseek(smb.sha_fp,(l-smb.status.header_offset)/256,0);
   if(msg.hdr.attr&(1<<4)) c=0;
   else c=1;
   for(i=0;i<(int)(size/256);i++)
    fputc(c,smb.sha_fp);
   if(!(msg.hdr.attr&(1<<4)))
    smb_incmsg_dfields(&smb,&msg,1);
  }
  smb_freemsgmem(&msg);
 }
 printf("\r%79s\r100%%\n","");
 smb.status.total_msgs=n;
 if(renumber)
  smb.status.last_msg=n;
 else
  sort_index(&smb);
 printf("Saving message base status (%lu total messages).\n",n);
 if((i=smb_putstatus(&smb))!=0)
  printf("\nsmb_putstatus returned %d: %s\n",i,smb.last_error);
 smb_unlocksmbhdr(&smb);
 printf("Closing message base.\n");
 smb_close(&smb);
 unlock_msgbase();
 printf("Done.\n");
 return(0);
}

canonical_original_code:
int fixsmb(char *sub)
{
 char *p;
 char *text;
 char c;
 int i; int w;
 unsigned long l; unsigned long length; unsigned long size; unsigned long n;
 struct smbmsg_t msg;
 memset(&smb,0,sizeof(smb));
 (strncpy(smb.file,sub,sizeof(smb.file)), smb.file[sizeof(smb.file)-1]=0);
 if((p=getfext(smb.file))!=((void *)0) && strcasecmp(p,".shd")==0)
  *p=0;
 printf("Opening %s\n",smb.file);
 if((i=smb_open(&smb))!=0) {
  printf("smb_open returned %d: %s\n",i,smb.last_error);
  exit(1);
 }
 if((i=smb_lock(&smb))!=0) {
  printf("smb_lock returned %d: %s\n",i,smb.last_error);
  exit(1);
 }
 if((i=smb_locksmbhdr(&smb))!=0) {
  smb_close(&smb);
  printf("smb_locksmbhdr returned %d: %s\n",i,smb.last_error);
  exit(1);
 }
 if((i=smb_getstatus(&smb))!=0) {
  smb_unlocksmbhdr(&smb);
  smb_close(&smb);
  printf("smb_getstatus returned %d: %s\n",i,smb.last_error);
  exit(1);
 }
 if(!(smb.status.attr&2)) {
  if((i=smb_open_fp(&smb,&(&smb)->sha_fp,1))!=0) {
   smb_close(&smb);
   printf("smb_open_ha returned %d: %s\n",i,smb.last_error);
   exit(1);
  }
  if((i=smb_open_fp(&smb,&(&smb)->sda_fp,1))!=0) {
   smb_close(&smb);
   printf("smb_open_da returned %d: %s\n",i,smb.last_error);
   exit(1);
  }
  rewind(smb.sha_fp);
  ftruncate(fileno(smb.sha_fp),0L);
  rewind(smb.sda_fp);
  ftruncate(fileno(smb.sda_fp),0L);
 }
 rewind(smb.sid_fp);
 ftruncate(fileno(smb.sid_fp),0L);
 if(!(smb.status.attr&2)) {
  length=filelength(fileno(smb.sdt_fp));
  w=0;
  for(l=0;l<length;l+=256)
   fwrite(&w,2,1,smb.sda_fp);
  length=filelength(fileno(smb.shd_fp));
  c=0;
  for(l=0;l<length;l+=256)
   fwrite(&c,1,1,smb.sha_fp);
 } else
  length=filelength(fileno(smb.shd_fp));
 n=0;
 for(l=smb.status.header_offset;l<length;l+=size) {
  size=256;
  printf("\r%2lu%%  ",(long)(100.0/((float)length/l)));
  msg.idx.offset=l;
  if((i=smb_lockmsghdr(&smb,&msg))!=0) {
   printf("\n(%06lX) smb_lockmsghdr returned %d:\n%s\n",l,i,smb.last_error);
   continue;
  }
  i=smb_getmsghdr(&smb,&msg);
  smb_unlockmsghdr(&smb,&msg);
  if(i!=0) {
   printf("\n(%06lX) smb_getmsghdr returned %d:\n%s\n",l,i,smb.last_error);
   continue;
  }
  size=smb_hdrblocks(smb_getmsghdrlen(&msg))*256;
  printf("#%-5lu (%06lX) %-25.25s ",msg.hdr.number,l,msg.from);
  if(msg.hdr.attr&(1<<4))
   text=((void *)0);
  else
   text=smb_getmsgtxt(&smb,&msg,(1<<2));
  i=smb_hashmsg(&smb,&msg,text,1 );
  if(i!=0)
   printf("!ERROR %d hashing message\n", i);
  if(text!=((void *)0))
   free(text);
  if(msg.hdr.attr&(1<<4))
   printf("Not indexing deleted message\n");
  else if(msg.hdr.number==0)
   printf("Not indexing invalid message number (0)!\n");
  else {
   msg.offset=n;
   if(renumber)
    msg.hdr.number=n+1;
   if(msg.hdr.netattr&(1<<1)) {
    printf("Removing 'in transit' attribute\n");
    msg.hdr.netattr&=~(1<<1);
   }
   if((i=smb_putmsg(&smb,&msg))!=0) {
    printf("\nsmb_putmsg returned %d: %s\n",i,smb.last_error);
    continue;
   }
   n++;
  }
  if(!(smb.status.attr&2)) {
   fseek(smb.sha_fp,(l-smb.status.header_offset)/256,0);
   if(msg.hdr.attr&(1<<4)) c=0;
   else c=1;
   for(i=0;i<(int)(size/256);i++)
    fputc(c,smb.sha_fp);
   if(!(msg.hdr.attr&(1<<4)))
    smb_incmsg_dfields(&smb,&msg,1);
  }
  smb_freemsgmem(&msg);
 }
 printf("\r%79s\r100%%\n","");
 smb.status.total_msgs=n;
 if(renumber)
  smb.status.last_msg=n;
 else
  sort_index(&smb);
 printf("Saving message base status (%lu total messages).\n",n);
 if((i=smb_putstatus(&smb))!=0)
  printf("\nsmb_putstatus returned %d: %s\n",i,smb.last_error);
 smb_unlocksmbhdr(&smb);
 printf("Closing message base.\n");
 smb_close(&smb);
 unlock_msgbase();
 printf("Done.\n");
 return(0);
}

variable_types:
sub
char *

variable_types:
p
char *

variable_types:
text
char *

variable_types: w int

variable_types:
l
unsigned long

variable_types:
length
unsigned long

variable_types:
size
unsigned long

variable_types:
n
unsigned long

variable_types: struct smbmsg_t { struct idxrec_t { unsigned short to; unsigned short from; unsigned short subj; unsigned short attr; unsigned long offset; unsigned long number; unsigned long time; } idx; struct msghdr_t { unsigned char id[4]; unsigned short type; unsigned short version; unsigned short length; unsigned short attr; unsigned long auxattr; unsigned long netattr; struct when_t { unsigned long time; short zone; } when_written; struct when_t when_imported; unsigned long number; unsigned long thread_back; unsigned long thread_next; unsigned long thread_first; unsigned short delivery_attempts; unsigned long times_downloaded; unsigned long last_downloaded; unsigned char reserved[6]; unsigned long offset; unsigned short total_dfields; } hdr; char *to; char *summary; char *subj; unsigned short to_agent; struct net_t { unsigned short type; void *addr; } to_net; unsigned short total_hfields; struct hfield_t { unsigned short type; unsigned short length; } *hfield; void **hfield_dat; struct dfield_t { unsigned short type; unsigned long offset; unsigned long length; } *dfield; long offset; int forwarded; unsigned long expiration; unsigned long priority; unsigned long cost; unsigned long flags; }

user_defined_types: struct smbmsg_t { struct idxrec_t idx; struct msghdr_t hdr; char *to; char *summary; char *subj; unsigned short to_agent; struct net_t to_net; unsigned short total_hfields; struct hfield_t *hfield; void **hfield_dat; struct dfield_t *dfield; long offset; int forwarded; unsigned long expiration; unsigned long priority; unsigned long cost; unsigned long flags; }

user_defined_types: struct msghdr_t { unsigned char id[4]; unsigned short type; unsigned short version; unsigned short length; unsigned short attr; unsigned long auxattr; unsigned long netattr; struct when_t when_written; struct when_t when_imported; unsigned long number; unsigned long thread_back; unsigned long thread_next; unsigned long thread_first; unsigned short delivery_attempts; unsigned long times_downloaded; unsigned long last_downloaded; unsigned char reserved[6]; unsigned long offset; unsigned short total_dfields; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char **v4; // rbx
char *v5; // rdi
__int64 v6; // rbx
char **v8; // [rsp+8h] [rbp-30h] BYREF
char v9[40]; // [rsp+10h] [rbp-28h] BYREF

_isoc99_sscanf("$Revision: 1.30 $", "%*s %s", v9);
v3 = (const char *)smb_lib_ver();
printf("\nFIXSMB v2.10-%s (rev %s) SMBLIB %s - Rebuild Synchronet Message Base\n\n", "Linux", v9, v3);
v8 = (char **)strListInit();
if ( argc > 1 )
{
v4 = argv + 1;
do
{
if ( **v4 == 45 )
{
if ( !strcasecmp(*v4, "-renumber") )
renumber = 1;
}
else
{
strListAppend(&v8, *v4, -1LL);
}
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 2) + 2] );
}
if ( !strListCount(v8) )
{
printf(usage);
exit(1);
}
atexit(unlock_msgbase);
v5 = *v8;
if ( *v8 )
{
v6 = 1LL;
do
{
fixsmb(v5);
v5 = v8[v6++];
}
while ( v5 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char **v4; // rbx
char *v5; // rdi
__int64 v6; // rbx
char **v8; // [rsp+8h] [rbp-30h] BYREF
char v9[40]; // [rsp+10h] [rbp-28h] BYREF

_isoc99_sscanf("$Revision: 1.30 $", "%*s %s", v9);
v3 = (const char *)smb_lib_ver();
printf("\nFIXSMB v2.10-%s (rev %s) SMBLIB %s - Rebuild Synchronet Message Base\n\n", "Linux", v9, v3);
v8 = (char **)strListInit();
if ( argc > 1 )
{
v4 = argv + 1;
do
{
if ( **v4 == 45 )
{
if ( !strcasecmp(*v4, "-renumber") )
renumber = 1;
}
else
{
strListAppend(&v8, *v4, -1LL);
}
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 2) + 2] );
}
if ( !strListCount(v8) )
{
printf(usage);
exit(1);
}
atexit(unlock_msgbase);
v5 = *v8;
if ( *v8 )
{
v6 = 1LL;
do
{
func3(v5);
v5 = v8[v6++];
}
while ( v5 );
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 char revision[16];
 int i;
 str_list_t list;
 sscanf("$Revision: 1.30 $", "%*s %s", revision);
 printf("\nFIXSMB v2.10-%s (rev %s) SMBLIB %s - Rebuild Synchronet Message Base\n\n"
  ,"Linux",revision,smb_lib_ver());
 list=strListInit();
 for(i=1;i<argc;i++) {
  if(argv[i][0]=='-') {
   if(!strcasecmp(argv[i],"-renumber"))
    renumber=1;
  } else
   strListAppend(&list, argv[i], (~0));
 }
 if(!strListCount(list)) {
  printf(usage);
  exit(1);
 }
 atexit(unlock_msgbase);
 for(i=0;list[i]!=((void *)0);i++)
  fixsmb(list[i]);
 return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char revision[16];
 int i;
 char **list;
 sscanf("$Revision: 1.30 $", "%*s %s", revision);
 printf("\nFIXSMB v2.10-%s (rev %s) SMBLIB %s - Rebuild Synchronet Message Base\n\n"
  ,"Linux",revision,smb_lib_ver());
 list=strListInit();
 for(i=1;i<argc;i++) {
  if(argv[i][0]=='-') {
   if(!strcasecmp(argv[i],"-renumber"))
    renumber=1;
  } else
   strListAppend(&list, argv[i], (~0));
 }
 if(!strListCount(list)) {
  printf(usage);
  exit(1);
 }
 atexit(unlock_msgbase);
 for(i=0;list[i]!=((void *)0);i++)
  fixsmb(list[i]);
 return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
revision
char [16]

variable_types:
list
char **


decompiled_code:
__int64 __fastcall sem_trywait_block(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
int *v3; // rax
struct timeval v5; // [rsp+0h] [rbp-38h] BYREF
__int64 v6[5]; // [rsp+10h] [rbp-28h] BYREF

gettimeofday(&v5, 0LL);
v6[0] = v5.tv_sec + (a2 + v5.tv_usec / 1000) / 0x3E8uLL;
v6[1] = (1000000 * a2 + 1000 * v5.tv_usec) % 0x3B9ACA00uLL;
v2 = xp_sem_timedwait(a1, v6);
if ( v2 )
{
v3 = _errno_location();
if ( *v3 == 110 )
*v3 = 11;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
int *v3; // rax
struct timeval v5; // [rsp+0h] [rbp-38h] BYREF
__int64 v6[5]; // [rsp+10h] [rbp-28h] BYREF

gettimeofday(&v5, 0LL);
v6[0] = v5.tv_sec + (a2 + v5.tv_usec / 1000) / 0x3E8uLL;
v6[1] = (1000000 * a2 + 1000 * v5.tv_usec) % 0x3B9ACA00uLL;
v2 = xp_sem_timedwait(a1, v6);
if ( v2 )
{
v3 = _errno_location();
if ( *v3 == 110 )
*v3 = 11;
}
return v2;
}

original_code:
int
sem_trywait_block(xp_sem_t *sem, unsigned long timeout)
{
 int retval;
 struct timespec abstime;
 struct timeval currtime;
 gettimeofday(&currtime,((void *)0));
 abstime.tv_sec=currtime.tv_sec + (currtime.tv_usec/1000 + timeout)/1000;
 abstime.tv_nsec=(currtime.tv_usec*1000 + timeout*1000000)%1000000000;
 retval=xp_sem_timedwait(sem,&abstime);
 if(retval && (*__errno_location ())==110)
  (*__errno_location ())=11;
 return retval;
}

canonical_original_code:
int sem_trywait_block(struct xp_sem **sem, unsigned long timeout)
{
 int retval;
 struct timespec abstime;
 struct timeval currtime;
 gettimeofday(&currtime,((void *)0));
 abstime.tv_sec=currtime.tv_sec + (currtime.tv_usec/1000 + timeout)/1000;
 abstime.tv_nsec=(currtime.tv_usec*1000 + timeout*1000000)%1000000000;
 retval=xp_sem_timedwait(sem,&abstime);
 if(retval && (*__errno_location ())==110)
  (*__errno_location ())=11;
 return retval;
}

variable_types: struct xp_sem { unsigned int magic; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } **

variable_types:
timeout
unsigned long

variable_types: retval int

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

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

user_defined_types: struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t gtzero; unsigned int count; unsigned int nwaiters; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


usage

repo: fugalh/jhat

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "usage: %s <joystick device path> <x axis> <z axis>\n\n", a1);
fwrite("See /proc/bus/input/devices for the path.\n", 1uLL, 0x2AuLL, stderr);
fwrite("Use jstest to figure out the axes.\n", 1uLL, 0x23uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fprintf(stderr, "usage: %s <joystick device path> <x axis> <z axis>\n\n", a1);
fwrite("See /proc/bus/input/devices for the path.\n", 1uLL, 0x2AuLL, stderr);
fwrite("Use jstest to figure out the axes.\n", 1uLL, 0x23uLL, stderr);
exit(1);
}

original_code:
void usage(char *argv0)
{
    fprintf(stderr, "usage: %s <joystick device path> <x axis> <z axis>\n\n", argv0);
    fprintf(stderr, "See /proc/bus/input/devices for the path.\n");
    fprintf(stderr, "Use jstest to figure out the axes.\n");
    exit(1);
}


keyup

decompiled_code:
void __fastcall keyup(int fd, void *buf, _DWORD *a3)
{
size_t v4; // rax

if ( *a3 )
{
write(fd, "keyup ", 6uLL);
v4 = strlen((const char *)buf);
write(fd, buf, v4);
write(fd, "\n", 1uLL);
*a3 = 0;
}
}

canonical_decompiled_code:
void __fastcall func8(int fd, void *buf, _DWORD *a3)
{
size_t v4; // rax

if ( *a3 )
{
write(fd, "keyup ", 6uLL);
v4 = strlen((const char *)buf);
write(fd, buf, v4);
write(fd, "\n", 1uLL);
*a3 = 0;
}
}

original_code:
void keyup(int xte_fd, char *key, int *state)
{
    if (*state)
    {
 write(xte_fd, "keyup ", 6);
 write(xte_fd, key, strlen(key));
 write(xte_fd, "\n", 1);
 *state = 0;
    }
}

variable_types:
key
char *

variable_types:
state
int *


keydown

decompiled_code:
void __fastcall keydown(int fd, void *buf, _DWORD *a3)
{
size_t v4; // rax

if ( !*a3 )
{
write(fd, "keydown ", 8uLL);
v4 = strlen((const char *)buf);
write(fd, buf, v4);
write(fd, "\n", 1uLL);
*a3 = 1;
}
}

canonical_decompiled_code:
void __fastcall func9(int fd, void *buf, _DWORD *a3)
{
size_t v4; // rax

if ( !*a3 )
{
write(fd, "keydown ", 8uLL);
v4 = strlen((const char *)buf);
write(fd, buf, v4);
write(fd, "\n", 1uLL);
*a3 = 1;
}
}

original_code:
void keydown(int xte_fd, char *key, int *state)
{
    if (!*state)
    {
 write(xte_fd, "keydown ", 8);
 write(xte_fd, key, strlen(key));
 write(xte_fd, "\n", 1);
 *state = 1;
    }
}


keyboard

repo: fujiruki/Harvester

decompiled_code:
void __fastcall keyboard(char a1)
{
if ( a1 == 27 )
EXIT = 0;
}

canonical_decompiled_code:
void __fastcall func0(char a1)
{
if ( a1 == 27 )
EXIT = 0;
}

original_code:
void keyboard(unsigned char key, int x, int y)
{
 switch (key)
 {
  case '\033':
   if ('\033' != 0) {
    EXIT = 0;
   }
   break;
  case 'j':
   if (BTN1 != 0) {
    BTN1 = 0;
   }
   break;
  case 'k':
   if (BTN2 != 0) {
    BTN2 = 0;
   }
   break;
  case 'w':
   if (U_BTN != 0) {
    U_BTN = 0;
   }
   break;
  case 's':
   if (D_BTN != 0) {
    D_BTN = 0;
   }
   break;
  case 'a':
   if (L_BTN != 0) {
    L_BTN = 0;
   }
   break;
  case 'd':
   if (R_BTN != 0) {
    R_BTN = 0;
   }
   break;
  default:
   break;
 }
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


specialkey

decompiled_code:
void specialkey()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void specialkey(int key, int x, int y)
{
 switch (key) {
 }
}

variable_types: key int


decompiled_code:
void specialkey_up()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void specialkey_up(int key, int x, int y)
{
 switch (key) {
 }
}


mouse

decompiled_code:
void mouse()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void mouse(int button, int state, int x, int y)
{
 switch (button) {
  case 0x0000:
   break;
  case 0x0001:
   break;
  case 0x0002:
   break;
  default:
   break;
 }
}

variable_types: button int

variable_types: state int


decompiled_code:
__int64 __fastcall keyboard_up(int a1)
{
if ( (_BYTE)a1 == 27 )
{
EXIT = 1;
exit(0);
}
return (unsigned int)(a1 - 97);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
if ( (_BYTE)a1 == 27 )
{
EXIT = 1;
exit(0);
}
return (unsigned int)(a1 - 97);
}

original_code:
void keyboard_up(unsigned char key, int x, int y)
{
 switch (key)
 {
  case '\033':
   if ('\033' != 1) {
    EXIT = 1;
    exit(0);
   }
  case 'j':
   if (BTN1 != 1) {
    BTN1 = 1;
   }
   break;
  case 'k':
   if (BTN2 != 1) {
    BTN2 = 1;
   }
   break;
  case 'w':
   if (U_BTN != 1) {
    U_BTN = 1;
   }
   break;
  case 's':
   if (D_BTN != 1) {
    D_BTN = 1;
   }
   break;
  case 'a':
   if (L_BTN != 1) {
    L_BTN = 1;
   }
   break;
  case 'd':
   if (R_BTN != 1) {
    R_BTN = 1;
   }
   break;
  default:
   break;
 }
}


decompiled_code:
__int64 __fastcall wait_ms(int a1)
{
int v1; // ebx
clock_t v2; // rax

v1 = clock();
while ( 1 )
{
v2 = clock();
if ( (double)a1 * 1000.0 <= (double)((int)v2 - v1) )
break;
if ( v2 == -1 )
{
fwrite(&unk_7AB0, 1uLL, 0x1FuLL, stderr);
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // ebx
clock_t v2; // rax

v1 = clock();
while ( 1 )
{
v2 = clock();
if ( (double)a1 * 1000.0 <= (double)((int)v2 - v1) )
break;
if ( v2 == -1 )
{
fwrite(&unk_7AB0, 1uLL, 0x1FuLL, stderr);
return 1LL;
}
}
return 0LL;
}

original_code:
int wait_ms(long t)
{
 clock_t s_c, e_c;
 s_c = clock();
 while ((e_c=clock())-s_c < ((__clock_t) 1000000)/1000.0*t)
 {
  if (e_c == (clock_t)-1) {
   fprintf(stderr, "clock()が異常な戻り値。");
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int wait_ms(long t)
{
 long s_c; long e_c;
 s_c = clock();
 while ((e_c=clock())-s_c < ((long) 1000000)/1000.0*t)
 {
  if (e_c == (clock_t)-1) {
   fprintf(stderr, "clock()が異常な戻り値。");
   return 1;
  }
 }
 return 0;
}

variable_types: t long


original_code:
void disp_frame()
{
 int x, y;
 for (x=0; x<60; x++) {
  for (y=0; y<60; y++) {
   emu_disp_pat[y][x] = pat[y][x];
  }
 }
 wait_ms(40);
}

canonical_original_code:
void disp_frame()
{
 int x; int y;
 for (x=0; x<60; x++) {
  for (y=0; y<60; y++) {
   emu_disp_pat[y][x] = pat[y][x];
  }
 }
 wait_ms(40);
}


decompiled_code:
void *__fastcall emu_loop(void *a1)
{
void *result; // rax

for ( result = (void *)game_init(a1); !EXIT; result = (void *)disp_frame() )
game_main();
return result;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
void *result; // rax

for ( result = (void *)game_init(a1); !EXIT; result = (void *)func6() )
game_main();
return result;
}

original_code:
void *emu_loop(void* arg)
{
 game_init();
 while (EXIT == 0) {
  game_main();
  disp_frame();
 }
}

canonical_original_code:
void *emu_loop(void *arg)
{
 game_init();
 while (EXIT == 0) {
  game_main();
  disp_frame();
 }
}

variable_types:
arg
void *

return_type: void *


decompiled_code:
__int64 __fastcall pat2rgb(int a1, double *a2, double *a3, double *a4)
{
__int64 result; // rax

*a4 = (double)((a1 >> 2) & 3) / 3.0;
result = (a1 >> 4) & 3;
*a2 = (double)(int)result / 3.0;
*a3 = (double)((a1 >> 6) & 3) / 3.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, double *a2, double *a3, double *a4)
{
__int64 result; // rax

*a4 = (double)((a1 >> 2) & 3) / 3.0;
result = (a1 >> 4) & 3;
*a2 = (double)(int)result / 3.0;
*a3 = (double)((a1 >> 6) & 3) / 3.0;
return result;
}

original_code:
void pat2rgb(int draw_pat, double *r, double *g, double *b)
{
 int pat_color = draw_pat >> 2;
 *b = (pat_color & 3) / 3.0;
 pat_color >>= 2;
 *r = (pat_color & 3) / 3.0;
 pat_color >>= 2;
 *g = (pat_color & 3) / 3.0;
 return;
}

variable_types:
r
double *

variable_types:
g
double *

variable_types:
b
double *


decompiled_code:
__int64 __fastcall Emu_draw_rect(char a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
glColor3d(a6, a7, a8);
if ( a1 <= 0 )
glBegin(2LL);
else
glBegin(9LL);
glVertex2d(a2, a3);
glVertex2d(a4 + a2, a3);
glVertex2d(a4 + a2, a3 + a5);
glVertex2d(a2, a3 + a5);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
glColor3d(a6, a7, a8);
if ( a1 <= 0 )
glBegin(2LL);
else
glBegin(9LL);
glVertex2d(a2, a3);
glVertex2d(a4 + a2, a3);
glVertex2d(a4 + a2, a3 + a5);
glVertex2d(a2, a3 + a5);
return glEnd();
}

original_code:
void Emu_draw_rect(double x, double y, double w, double h, double r, double g, double b, char fill)
{
 glColor3d(r, g, b);
 if (fill>0) {
  glBegin(0x0009);
 } else {
  glBegin(0x0002);
 }
 glVertex2d(x, y);
 glVertex2d(x+w, y);
 glVertex2d(x+w, y+h);
 glVertex2d(x, y+h);
 glEnd();
}

variable_types: x double

variable_types: y double

variable_types: w double

variable_types: h double

variable_types: r double

variable_types: g double

variable_types: b double

variable_types: fill char


decompiled_code:
__int64 emu_disp_cells()
{
int *v0; // r13
int i; // er12
int *v2; // rbp
int j; // ebx
__int64 result; // rax
double v5; // [rsp+0h] [rbp-58h]
double v6; // [rsp+8h] [rbp-50h]
double v7; // [rsp+18h] [rbp-40h] BYREF
double v8; // [rsp+20h] [rbp-38h] BYREF
double v9[6]; // [rsp+28h] [rbp-30h] BYREF

v5 = *(double *)&disp_ortho;
v6 = *((double *)&disp_ortho + 1);
v0 = &emu_disp_pat;
for ( i = 0; i != 60; ++i )
{
v2 = v0;
for ( j = 0; j != 60; ++j )
{
pat2rgb(*v2, v9, &v8, &v7);
result = Emu_draw_rect(
1,
(double)i * *(double *)&cell_box + v5 + *(double *)&border_w,
(double)j * *((double *)&cell_box + 1) + v6 + *(double *)&border_w,
*(double *)&cell_size,
*((double *)&cell_size + 1),
v9[0],
v8,
v7);
v2 += 60;
}
++v0;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int *v0; // r13
int i; // er12
int *v2; // rbp
int j; // ebx
__int64 result; // rax
double v5; // [rsp+0h] [rbp-58h]
double v6; // [rsp+8h] [rbp-50h]
double v7; // [rsp+18h] [rbp-40h] BYREF
double v8; // [rsp+20h] [rbp-38h] BYREF
double v9[6]; // [rsp+28h] [rbp-30h] BYREF

v5 = *(double *)&disp_ortho;
v6 = *((double *)&disp_ortho + 1);
v0 = &emu_disp_pat;
for ( i = 0; i != 60; ++i )
{
v2 = v0;
for ( j = 0; j != 60; ++j )
{
func8(*v2, v9, &v8, &v7);
result = func9(
1,
(double)i * *(double *)&cell_box + v5 + *(double *)&border_w,
(double)j * *((double *)&cell_box + 1) + v6 + *(double *)&border_w,
*(double *)&cell_size,
*((double *)&cell_size + 1),
v9[0],
v8,
v7);
v2 += 60;
}
++v0;
}
return result;
}

original_code:
void emu_disp_cells()
{
 int x, y;
 double r, g, b;
 posd offset;
 offset.x = disp_ortho.x;
 offset.y = disp_ortho.y;
 for (x=0; x<60; x++) {
  for (y=0; y<60; y++) {
   pat2rgb(emu_disp_pat[y][x], &r, &g, &b);
   Emu_draw_rect(offset.x + x*cell_box.w +border_w,
     offset.y + y*cell_box.h +border_w, cell_size.w, cell_size.h, r, g, b, 1);
  }
 }
}

canonical_original_code:
void emu_disp_cells()
{
 int x; int y;
 double r; double g; double b;
 struct posd offset;
 offset.x = disp_ortho.x;
 offset.y = disp_ortho.y;
 for (x=0; x<60; x++) {
  for (y=0; y<60; y++) {
   pat2rgb(emu_disp_pat[y][x], &r, &g, &b);
   Emu_draw_rect(offset.x + x*cell_box.w +border_w,
     offset.y + y*cell_box.h +border_w, cell_size.w, cell_size.h, r, g, b, 1);
  }
 }
}

variable_types: x int

variable_types: y int

variable_types:
offset
struct posd { double x; }


display

decompiled_code:
__int64 display()
{
glClear(0x4000LL);
emu_disp_cells();
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func11()
{
glClear(0x4000LL);
func10();
return glutSwapBuffers();
}

original_code:
void display(void)
{
 int x, y;
 double r,g,b;
 glClear(0x00004000);
 emu_disp_cells();
 glutSwapBuffers();
}

canonical_original_code:
void display()
{
 int x; int y;
 double r; double g; double b;
 glClear(0x00004000);
 emu_disp_cells();
 glutSwapBuffers();
}


decompiled_code:
void set_cell_size()
{
double v0; // xmm2_8
double v1; // xmm3_8
__int64 v2; // xmm0_8
double v3; // xmm1_8

v0 = *(double *)&border_rate;
v1 = *(double *)&border_rate * 61.0 + 60.0;
*(double *)&cell_size = *((double *)&disp_ortho + 2) / v1;
v2 = cell_size;
v3 = *((double *)&disp_ortho + 3) / v1;
*((double *)&cell_size + 1) = v3;
*(double *)&border_w = v0 * *(double *)&v2;
*(double *)&cell_box = *(double *)&v2 + v0 * *(double *)&v2;
*((double *)&cell_box + 1) = v3 + v0 * *(double *)&v2;
}

canonical_decompiled_code:
void func12()
{
double v0; // xmm2_8
double v1; // xmm3_8
__int64 v2; // xmm0_8
double v3; // xmm1_8

v0 = *(double *)&border_rate;
v1 = *(double *)&border_rate * 61.0 + 60.0;
*(double *)&cell_size = *((double *)&disp_ortho + 2) / v1;
v2 = cell_size;
v3 = *((double *)&disp_ortho + 3) / v1;
*((double *)&cell_size + 1) = v3;
*(double *)&border_w = v0 * *(double *)&v2;
*(double *)&cell_box = *(double *)&v2 + v0 * *(double *)&v2;
*((double *)&cell_box + 1) = v3 + v0 * *(double *)&v2;
}

original_code:
void set_cell_size()
{
 cell_size.w = disp_ortho.w/( 60 + (60 +1)*border_rate );
 cell_size.h = disp_ortho.h/( 60 + (60 +1)*border_rate );
 border_w = border_rate * cell_size.w;
 cell_box.w = border_w + cell_size.w;
 cell_box.h = border_w + cell_size.h;
}


resize

decompiled_code:
__int64 __fastcall resize(int a1, int a2)
{
double v2; // xmm0_8
double v3; // xmm1_8

bdisp[2] = (double)a1;
bdisp[3] = (double)a2;
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glLoadIdentity();
v2 = (double)a1 / 200.0 + (double)a1 / 200.0;
*((double *)&disp_ortho + 2) = v2;
v3 = (double)a2 / 200.0 + (double)a2 / 200.0;
*((double *)&disp_ortho + 3) = v3;
*((double *)&disp_ortho + 1) = COERCE_DOUBLE(*(_QWORD *)&v3 ^ LC6) * 0.5;
*(double *)&disp_ortho = COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC6) * 0.5;
set_cell_size();
return glOrtho(
*(double *)&disp_ortho,
*(double *)&disp_ortho + *((double *)&disp_ortho + 2),
*((double *)&disp_ortho + 1) + *((double *)&disp_ortho + 3),
*((double *)&disp_ortho + 1),
-1.0,
1.0);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2)
{
double v2; // xmm0_8
double v3; // xmm1_8

bdisp[2] = (double)a1;
bdisp[3] = (double)a2;
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glLoadIdentity();
v2 = (double)a1 / 200.0 + (double)a1 / 200.0;
*((double *)&disp_ortho + 2) = v2;
v3 = (double)a2 / 200.0 + (double)a2 / 200.0;
*((double *)&disp_ortho + 3) = v3;
*((double *)&disp_ortho + 1) = COERCE_DOUBLE(*(_QWORD *)&v3 ^ LC6) * 0.5;
*(double *)&disp_ortho = COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC6) * 0.5;
func12();
return glOrtho(
*(double *)&disp_ortho,
*(double *)&disp_ortho + *((double *)&disp_ortho + 2),
*((double *)&disp_ortho + 1) + *((double *)&disp_ortho + 3),
*((double *)&disp_ortho + 1),
-1.0,
1.0);
}

original_code:
void resize(int w, int h)
{
 bdisp.w = w;
 bdisp.h = h;
 glViewport(0, 0, bdisp.w, bdisp.h);
 glLoadIdentity();
 disp_ortho.w = w/200.0*2;
 disp_ortho.h = h/200.0*2;
 disp_ortho.y = -disp_ortho.h/2.0;
 disp_ortho.x = -disp_ortho.w/2.0;
 set_cell_size();
 glOrtho(disp_ortho.x, disp_ortho.x+disp_ortho.w,
   disp_ortho.y+disp_ortho.h, disp_ortho.y, -1.0, 1.0);
}

variable_types: w int

variable_types: h int


decompiled_code:
__int64 display_loop()
{
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func14()
{
return glutPostRedisplay();
}

original_code:
void display_loop()
{
 glutPostRedisplay();
}


decompiled_code:
__int64 timer_display()
{
display_loop();
return glutTimerFunc(16LL, timer_display, 0LL);
}

canonical_decompiled_code:
__int64 func15()
{
func14();
return glutTimerFunc(16LL, timer_display, 0LL);
}

original_code:
void timer_display(int value)
{
 display_loop();
 glutTimerFunc(16, timer_display, 0);
}

variable_types: value int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-1Ch] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

v4[0] = argc;
init_emu((__int64)v4, argv);
if ( pthread_create(newthread, 0LL, emu_loop, 0LL) )
{
fwrite(&unk_7AD0, 1uLL, 0x16uLL, stderr);
exit(-1);
}
glutMainLoop();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t game_thread;
 int game_thread_status;
 init_emu(&argc, argv);
 game_thread_status = pthread_create(&game_thread, ((void *)0), emu_loop, 0);
 if (game_thread_status!=0) {
  fprintf(stderr, "pthreadでのエラー");
  exit(-1);
 }
 glutMainLoop();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long game_thread;
 int game_thread_status;
 init_emu(&argc, argv);
 game_thread_status = pthread_create(&game_thread, ((void *)0), emu_loop, 0);
 if (game_thread_status!=0) {
  fprintf(stderr, "pthreadでのエラー");
  exit(-1);
 }
 glutMainLoop();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __fastcall print_bit(int a1)
{
int i; // ebx
int result; // eax

printf("%d : ", (unsigned int)a1);
for ( i = 0; i != 9; ++i )
result = printf("%d", (((a1 < 0) + (unsigned __int8)(a1 >> i)) & 1) - ((unsigned int)a1 >> 31));
return result;
}

canonical_decompiled_code:
int __fastcall func16(int a1)
{
int i; // ebx
int result; // eax

printf("%d : ", (unsigned int)a1);
for ( i = 0; i != 9; ++i )
result = printf("%d", (((a1 < 0) + (unsigned __int8)(a1 >> i)) & 1) - ((unsigned int)a1 >> 31));
return result;
}

original_code:
void print_bit(int n)
{
 int i, bit;
 printf("%d : ", n);
 for (i=0; i<=8; i++) {
  printf("%d",(n >> i) % 2);
 }
}

canonical_original_code:
void print_bit(int n)
{
 int i; int bit;
 printf("%d : ", n);
 for (i=0; i<=8; i++) {
  printf("%d",(n >> i) % 2);
 }
}

variable_types: n int

variable_types: i int

variable_types: bit int


plot

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

if ( a1 <= 0x3B && a2 <= 0x3B )
{
result = (int)a1 + 60LL * (int)a2;
*((_DWORD *)&pat + result) = a3;
}
return result;
}

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

if ( a1 <= 0x3B && a2 <= 0x3B )
{
result = (int)a1 + 60LL * (int)a2;
*((_DWORD *)&pat + result) = a3;
}
return result;
}

original_code:
void plot(int x, int y, int color)
{
 if (0 <= x && x < 60 && 0<=y && y < 60)
 {
  pat[y][x] = color;
 }
}

variable_types: color int


original_code:
void draw_line(int x1, int y1, int x2, int y2, int color)
{
 int i;
 Pos dist, direc;
 int E;
 dist.x = (x2 > x1) ? (x2-x1):(x1-x2);
 dist.y = (y2 > y1) ? (y2-y1):(y1-y2);
 direc.x = (x2 > x1) ? 1 : -1;
 direc.y = (y2 > y1) ? 1 : -1;
 if ( dist.x > dist.y )
 {
  E = -dist.x;
  for ( i = 0 ; i <= dist.x ; i++ ) {
   plot( x1, y1, color );
   x1 += direc.x;
   E += 2 * dist.y;
   if ( E >= 0 ) {
    y1 += direc.y;
    E -= 2 * dist.x;
   }
  }
 } else {
  E = -dist.y;
  for ( i = 0 ; i <= dist.y ; i++ ) {
   plot( x1, y1, color );
   y1 += direc.y;
   E += 2 * dist.x;
   if ( E >= 0 ) {
    x1 += direc.x;
    E -= 2 * dist.y;
   }
  }
 }
}

canonical_original_code:
void draw_line(int x1, int y1, int x2, int y2, int color)
{
 int i;
 struct Pos dist; struct Pos direc;
 int E;
 dist.x = (x2 > x1) ? (x2-x1):(x1-x2);
 dist.y = (y2 > y1) ? (y2-y1):(y1-y2);
 direc.x = (x2 > x1) ? 1 : -1;
 direc.y = (y2 > y1) ? 1 : -1;
 if ( dist.x > dist.y )
 {
  E = -dist.x;
  for ( i = 0 ; i <= dist.x ; i++ ) {
   plot( x1, y1, color );
   x1 += direc.x;
   E += 2 * dist.y;
   if ( E >= 0 ) {
    y1 += direc.y;
    E -= 2 * dist.x;
   }
  }
 } else {
  E = -dist.y;
  for ( i = 0 ; i <= dist.y ; i++ ) {
   plot( x1, y1, color );
   y1 += direc.y;
   E += 2 * dist.x;
   if ( E >= 0 ) {
    x1 += direc.x;
    E -= 2 * dist.y;
   }
  }
 }
}

variable_types:
dist
struct Pos { int x; }

variable_types:
direc
struct Pos { int x; }

variable_types: E int


fillBox

variable_types: j int


original_code:
void simu_chara_spring(Chara *obj)
{
 float *vec, *vec_prev, f;
 float y_tmp, vy;
 int i;
 for (i=0; i<2; i++)
 {
  if (i==0) {
   vec = &(obj->p.y);
   vec_prev = &(obj->p_prev.y);
   f = obj->f.y = 0.02*(*vec - jiki.p.y);
  } else {
   vec = &(obj->p.x);
   vec_prev = &(obj->p_prev.x);
   f = obj->f.x = 0.02*(*vec - jiki.p.x);
  }
  y_tmp = *vec;
  vy = (-(*vec - *vec_prev) + f);
  if (vy < -2 || vy > 2) {
   vy = (*vec < *vec_prev) ? 2 : -2;
  }
  vy *= 0.98;
  *vec -= vy;
  *vec_prev = y_tmp;
 }
}

canonical_original_code:
void simu_chara_spring(struct Chara *obj)
{
 float *vec; float *vec_prev; float f;
 float y_tmp; float vy;
 int i;
 for (i=0; i<2; i++)
 {
  if (i==0) {
   vec = &(obj->p.y);
   vec_prev = &(obj->p_prev.y);
   f = obj->f.y = 0.02*(*vec - jiki.p.y);
  } else {
   vec = &(obj->p.x);
   vec_prev = &(obj->p_prev.x);
   f = obj->f.x = 0.02*(*vec - jiki.p.x);
  }
  y_tmp = *vec;
  vy = (-(*vec - *vec_prev) + f);
  if (vy < -2 || vy > 2) {
   vy = (*vec < *vec_prev) ? 2 : -2;
  }
  vy *= 0.98;
  *vec -= vy;
  *vec_prev = y_tmp;
 }
}

variable_types: struct Chara { struct FPos { float x; } p; struct FPos p_prev; struct FPos f; char isflying; } *

variable_types:
vec
float *

variable_types: f float

variable_types: vy float

user_defined_types: struct Chara { struct FPos p; struct FPos p_prev; struct FPos f; char isflying; }


decompiled_code:
__int64 move_tail()
{
return simu_chara_spring(tail);
}

canonical_decompiled_code:
__int64 func4()
{
return func3(tail);
}

original_code:
void move_tail()
{
 simu_chara_spring(&tail);
}


original_code:
void move_jiki()
{
 float y_tmp, vy;
 if (!L_BTN) { jiki.p.x -= 0.7; }
 if (!R_BTN) { jiki.p.x += 0.7; }
 if (!U_BTN) { jiki.p.y -= 0.7; }
 if (!D_BTN) { jiki.p.y += 0.7; }
 move_tail();
}

canonical_original_code:
void move_jiki()
{
 float y_tmp; float vy;
 if (!L_BTN) { jiki.p.x -= 0.7; }
 if (!R_BTN) { jiki.p.x += 0.7; }
 if (!U_BTN) { jiki.p.y -= 0.7; }
 if (!D_BTN) { jiki.p.y += 0.7; }
 move_tail();
}


decompiled_code:
void draw_jiki()
{
draw_line((int)jiki[0], (int)jiki[1], (int)tail[0], (int)tail[1], 0);
fillBox((int)jiki[0], (int)jiki[1], (int)(float)(jiki[0] + 1.0), (int)(float)(jiki[1] + 1.0), 48);
fillBox((int)tail[0], (int)tail[1], (int)(float)(tail[0] + 1.0), (int)(float)(tail[1] + 1.0), 12);
}

original_code:
void draw_jiki()
{
 draw_line(jiki.p.x, jiki.p.y, tail.p.x,tail.p.y, 0x00);
 fillBox(jiki.p.x, jiki.p.y, jiki.p.x+1, jiki.p.y+1, 0x30);
 fillBox(tail.p.x, tail.p.y, tail.p.x+1, tail.p.y+1, 0x0c);
}


original_code:
void draw_back()
{
 fillBox(0, 0, 60, 60, 0xff);
}


decompiled_code:
void game_init()
{
LODWORD(jiki[0]) = LC6;
LODWORD(jiki[1]) = LC7;
LODWORD(jiki[2]) = LC6;
LODWORD(jiki[3]) = LC7;
LODWORD(tail[2]) = LC8;
LODWORD(tail[3]) = LC7;
LODWORD(tail[0]) = LC8;
tail[1] = 31.0;
}

canonical_decompiled_code:
void func8()
{
LODWORD(jiki[0]) = LC6;
LODWORD(jiki[1]) = LC7;
LODWORD(jiki[2]) = LC6;
LODWORD(jiki[3]) = LC7;
LODWORD(tail[2]) = LC8;
LODWORD(tail[3]) = LC7;
LODWORD(tail[0]) = LC8;
tail[1] = 31.0;
}

original_code:
void game_init()
{
 jiki.p.x = 10;
 jiki.p.y = (60 >> 1);
 jiki.p_prev.x = jiki.p.x;
 jiki.p_prev.y = jiki.p.y;
 tail.p_prev.x = jiki.p.x - 6;
 tail.p_prev.y = jiki.p.y;
 tail.p.x = tail.p_prev.x;
 tail.p.y = tail.p_prev.y + 1;
}


decompiled_code:
void game_main()
{
move_jiki();
draw_back();
draw_jiki();
}

canonical_decompiled_code:
void func9()
{
func5();
func7();
func6();
}


repo: fumin/apiserv

decompiled_code:
__int64 __fastcall heap_node_free(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax

if ( a1 )
{
v1 = a1[3];
free(a1);
heap_node_free(a1[1]);
result = heap_node_free(v1);
}
return result;
}

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

if ( a1 )
{
v1 = a1[3];
free(a1);
func1(a1[1]);
result = func1(v1);
}
return result;
}

original_code:
void heap_node_free(heap_node *h) {
    heap_node * fc;
    if (!h)
        return;
    fc = h->first_child;
    free(h);
    heap_node_free(h->next_sibling);
    return heap_node_free(fc);
}

canonical_original_code:
void heap_node_free(struct heap_node *h) {
    struct heap_node *fc;
    if (!h)
        return;
    fc = h->first_child;
    free(h);
    heap_node_free(h->next_sibling);
    return heap_node_free(fc);
}

variable_types: struct heap_node { struct heap_node *parent; struct heap_node *next_sibling; struct heap_node *previous_sibling; struct heap_node *first_child; struct heap_node *last_child; int n_subtrees; struct connection_t { int state; int fd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } client_addr; unsigned int events; long timeout; struct heap_node *pheap_node; char req_buf[512]; char *preq_buf; int content_length; char *p_newline; char *p_end_of_init; int http_resp_code; char resp_header_buf[256]; int resp_header_len; char resp_buf[1024]; long resp_content_length; long resp_header_write_offset; long resp_body_write_offset; int static_content_fd; struct conn_writev_t { struct iovec { void *iov_base; unsigned long iov_len; } iovs[2]; struct iovec *iov; int iovcnt; } writev_s; unsigned int tcp_cork; } value; } *

user_defined_types: struct heap_node { struct heap_node *parent; struct heap_node *next_sibling; struct heap_node *previous_sibling; struct heap_node *first_child; struct heap_node *last_child; int n_subtrees; struct connection_t value; }

user_defined_types: struct connection_t { int state; int fd; struct sockaddr client_addr; unsigned int events; long timeout; struct heap_node *pheap_node; char req_buf[512]; char *preq_buf; int content_length; char *p_newline; char *p_end_of_init; int http_resp_code; char resp_header_buf[256]; int resp_header_len; char resp_buf[1024]; long resp_content_length; long resp_header_write_offset; long resp_body_write_offset; int static_content_fd; struct conn_writev_t writev_s; unsigned int tcp_cork; }

user_defined_types: struct conn_writev_t { struct iovec iovs[2]; struct iovec *iov; int iovcnt; }


decompiled_code:
void __fastcall heap_free(void *ptr)
{
g_heap_num_ele = 0;
heap_node_free(*(_QWORD **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
g_heap_num_ele = 0;
func1(*(_QWORD **)ptr);
free(ptr);
}

original_code:
void heap_free(heap *hp) {g_heap_num_ele = 0;
    heap_node_free(hp->root);
    free(hp);
}

canonical_original_code:
void heap_free(struct heap *hp) {g_heap_num_ele = 0;
    heap_node_free(hp->root);
    free(hp);
}

variable_types: struct heap { struct heap_node { struct heap_node *parent; struct heap_node *next_sibling; struct heap_node *previous_sibling; struct heap_node *first_child; struct heap_node *last_child; int n_subtrees; struct connection_t { int state; int fd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } client_addr; unsigned int events; long timeout; struct heap_node *pheap_node; char req_buf[512]; char *preq_buf; int content_length; char *p_newline; char *p_end_of_init; int http_resp_code; char resp_header_buf[256]; int resp_header_len; char resp_buf[1024]; long resp_content_length; long resp_header_write_offset; long resp_body_write_offset; int static_content_fd; struct conn_writev_t { struct iovec { void *iov_base; unsigned long iov_len; } iovs[2]; struct iovec *iov; int iovcnt; } writev_s; unsigned int tcp_cork; } value; } *root; } *


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

result = *a1;
if ( *a1 )
result = *a1 + 48;
return result;
}

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

result = *a1;
if ( *a1 )
result = *a1 + 48;
return result;
}

original_code:
struct connection_t* heap_min(heap *h){
 if (h->root == ((void *)0)) return ((void *)0);
 return &h->root->value;
}

canonical_original_code:
struct connection_t *heap_min(struct heap *h){
 if (h->root == ((void *)0)) return ((void *)0);
 return &h->root->value;
}

variable_types: struct heap { struct heap_node *root; } *

return_type: struct connection_t { int state; int fd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } client_addr; unsigned int events; long timeout; struct heap_node { struct heap_node *parent; struct heap_node *next_sibling; struct heap_node *previous_sibling; struct heap_node *first_child; struct heap_node *last_child; int n_subtrees; struct connection_t value; } *pheap_node; char req_buf[512]; char *preq_buf; int content_length; char *p_newline; char *p_end_of_init; int http_resp_code; char resp_header_buf[256]; int resp_header_len; char resp_buf[1024]; long resp_content_length; long resp_header_write_offset; long resp_body_write_offset; int static_content_fd; struct conn_writev_t { struct iovec { void *iov_base; unsigned long iov_len; } iovs[2]; struct iovec *iov; int iovcnt; } writev_s; unsigned int tcp_cork; } *


decompiled_code:
void __fastcall heap_delete_min(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12
_QWORD *v3; // rbp
_QWORD *v4; // r14
_QWORD *v5; // rax
_QWORD *v6; // rbp
_QWORD *v7; // rbp
_QWORD *v8; // r12

--g_heap_num_ele;
v1 = *(_QWORD **)a1;
v2 = *(_QWORD **)(*(_QWORD *)a1 + 24LL);
if ( !v2 )
goto LABEL_2;
while ( 1 )
{
v6 = (_QWORD *)v2[1];
heap_node_isolate(v2);
if ( !v6 )
break;
v4 = (_QWORD *)v6[1];
heap_node_isolate(v6);
v5 = heap_node_meld(v2, v6);
v1 = heap_node_meld(v1, v5);
if ( !v4 )
goto LABEL_7;
v2 = v4;
}
v1 = heap_node_meld(v1, v2);
LABEL_7:
v7 = (_QWORD *)v1[3];
if ( v7 )
{
do
{
v8 = (_QWORD *)v7[1];
if ( !v8 )
break;
heap_node_isolate(v7);
heap_node_isolate(v8);
v7 = heap_node_meld(v7, v8);
v1 = heap_node_meld(v1, v7);
}
while ( v7 );
v3 = (_QWORD *)v1[3];
if ( v3 )
*v3 = 0LL;
}
else
{
LABEL_2:
v3 = 0LL;
}
free(v1);
*(_QWORD *)a1 = v3;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12
_QWORD *v3; // rbp
_QWORD *v4; // r14
_QWORD *v5; // rax
_QWORD *v6; // rbp
_QWORD *v7; // rbp
_QWORD *v8; // r12

--g_heap_num_ele;
v1 = *(_QWORD **)a1;
v2 = *(_QWORD **)(*(_QWORD *)a1 + 24LL);
if ( !v2 )
goto LABEL_2;
while ( 1 )
{
v6 = (_QWORD *)v2[1];
func0(v2);
if ( !v6 )
break;
v4 = (_QWORD *)v6[1];
func0(v6);
v5 = heap_node_meld(v2, v6);
v1 = heap_node_meld(v1, v5);
if ( !v4 )
goto LABEL_7;
v2 = v4;
}
v1 = heap_node_meld(v1, v2);
LABEL_7:
v7 = (_QWORD *)v1[3];
if ( v7 )
{
do
{
v8 = (_QWORD *)v7[1];
if ( !v8 )
break;
func0(v7);
func0(v8);
v7 = heap_node_meld(v7, v8);
v1 = heap_node_meld(v1, v7);
}
while ( v7 );
v3 = (_QWORD *)v1[3];
if ( v3 )
*v3 = 0LL;
}
else
{
LABEL_2:
v3 = 0LL;
}
free(v1);
*(_QWORD *)a1 = v3;
}

original_code:
void heap_delete_min(heap *hp) { g_heap_num_ele--;
    heap_node *a,*b,*next_tmp,*new_root=((void *)0);
    heap_node * h = hp->root;
    a = h->first_child;
    while(a!=((void *)0))
    {
        next_tmp=((void *)0);
        b = a->next_sibling;
        heap_node_isolate(a);
        if (b) {
            next_tmp=b->next_sibling;
            heap_node_isolate(b);
            a = heap_node_meld(a,b);
        }
        h = heap_node_meld(h,a);
        a = next_tmp;
    }
    a = h->first_child;
    while(a!=((void *)0))
    {
        b = a->next_sibling;
        if (!b) break;
        heap_node_isolate(a);
        heap_node_isolate(b);
        a = heap_node_meld(a,b);
        h = heap_node_meld(h,a);
    }
    if (h->first_child) {
        new_root = h->first_child;
        h->first_child->parent=((void *)0);
    }
    free(h);
    hp->root = new_root;
}

canonical_original_code:
void heap_delete_min(struct heap *hp) { g_heap_num_ele--;
    struct heap_node *a; struct heap_node *b; struct heap_node *next_tmp; struct heap_node *new_root = ((void *)0);
    struct heap_node *h = hp->root;
    a = h->first_child;
    while(a!=((void *)0))
    {
        next_tmp=((void *)0);
        b = a->next_sibling;
        heap_node_isolate(a);
        if (b) {
            next_tmp=b->next_sibling;
            heap_node_isolate(b);
            a = heap_node_meld(a,b);
        }
        h = heap_node_meld(h,a);
        a = next_tmp;
    }
    a = h->first_child;
    while(a!=((void *)0))
    {
        b = a->next_sibling;
        if (!b) break;
        heap_node_isolate(a);
        heap_node_isolate(b);
        a = heap_node_meld(a,b);
        h = heap_node_meld(h,a);
    }
    if (h->first_child) {
        new_root = h->first_child;
        h->first_child->parent=((void *)0);
    }
    free(h);
    hp->root = new_root;
}

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


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

g_heap_num_ele = 0;
result = malloc(8uLL);
*result = 0LL;
return result;
}

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

g_heap_num_ele = 0;
result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
heap * heap_new(void) {g_heap_num_ele=0;
    heap *h;
    h = (heap*)malloc(sizeof(heap));
    h->root = ((void *)0);
    return h;
}

canonical_original_code:
struct heap *heap_new() {g_heap_num_ele=0;
    struct heap *h;
    h = (struct heap *)malloc(sizeof(heap));
    h->root = ((void *)0);
    return h;
}

return_type: struct heap { struct heap_node { struct heap_node *parent; struct heap_node *next_sibling; struct heap_node *previous_sibling; struct heap_node *first_child; struct heap_node *last_child; int n_subtrees; struct connection_t { int state; int fd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } client_addr; unsigned int events; long timeout; struct heap_node *pheap_node; char req_buf[512]; char *preq_buf; int content_length; char *p_newline; char *p_end_of_init; int http_resp_code; char resp_header_buf[256]; int resp_header_len; char resp_buf[1024]; long resp_content_length; long resp_header_write_offset; long resp_body_write_offset; int static_content_fd; struct conn_writev_t { struct iovec { void *iov_base; unsigned long iov_len; } iovs[2]; struct iovec *iov; int iovcnt; } writev_s; unsigned int tcp_cork; } value; } *root; } *


decompiled_code:
time_t log_alarm_signal_handler()
{
time_t *v0; // rbx
time_t result; // rax

v0 = gp_current_timestamp;
result = time(0LL);
*v0 = result;
return result;
}

canonical_decompiled_code:
time_t func0()
{
time_t *v0; // rbx
time_t result; // rax

v0 = gp_current_timestamp;
result = time(0LL);
*v0 = result;
return result;
}

original_code:
static void log_alarm_signal_handler(int sig) {
 *gp_current_timestamp = time(((void *)0));
}

variable_types: sig int


repo: funglaub/devd-notifier

decompiled_code:
void __noreturn display_usage()
{
puts("Usage: devd-notifier [OPTION]");
puts("Options:");
printf("%-10s %-s\n", "-f", "don't fork to background");
printf("%-10s %-s\n", "-h", "show this help");
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("Usage: devd-notifier [OPTION]");
puts("Options:");
printf("%-10s %-s\n", "-f", "don't fork to background");
printf("%-10s %-s\n", "-h", "show this help");
exit(1);
}

original_code:
void display_usage() {
  printf("Usage: devd-notifier [OPTION]\n");
  printf("Options:\n");
  printf("%-10s %-s\n", "-f", "don't fork to background");
  printf("%-10s %-s\n", "-h", "show this help");
  exit(1);
}


cleanup

decompiled_code:
void __noreturn cleanup()
{
closelog();
regfree(&regex);
notify_uninit();
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
closelog();
regfree(&regex);
notify_uninit();
exit(0);
}

original_code:
void cleanup() {
  closelog();
  regfree(&regex);
  notify_uninit();
  exit(0);
}


decompiled_code:
void __fastcall signal_handler(unsigned int a1)
{
if ( a1 == 15 || a1 == 3 )
{
syslog(5, "Received signal %i. Terminating", a1);
cleanup();
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1)
{
if ( a1 == 15 || a1 == 3 )
{
syslog(5, "Received signal %i. Terminating", a1);
func8();
}
}

original_code:
void signal_handler(int sig) {
  if(sig == 15 || sig == 3) {
    syslog(5, "Received signal %i. Terminating", sig);
    cleanup();
  }
}


daemonize

decompiled_code:
int daemonize()
{
__pid_t v0; // eax
char *v1; // rax
int result; // eax

v0 = fork();
if ( v0 < 0 )
{
perror("Error");
exit(1);
}
if ( v0 > 0 )
{
syslog(5, "forked to background with PID %i", (unsigned int)v0);
exit(0);
}
umask(0);
if ( setsid() < 0 )
{
perror("Error retrieving a new SID");
exit(1);
}
v1 = getenv("HOME");
result = chdir(v1);
if ( result < 0 )
{
perror("Error changing working directory");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func10()
{
__pid_t v0; // eax
char *v1; // rax
int result; // eax

v0 = fork();
if ( v0 < 0 )
{
perror("Error");
exit(1);
}
if ( v0 > 0 )
{
syslog(5, "forked to background with PID %i", (unsigned int)v0);
exit(0);
}
umask(0);
if ( setsid() < 0 )
{
perror("Error retrieving a new SID");
exit(1);
}
v1 = getenv("HOME");
result = chdir(v1);
if ( result < 0 )
{
perror("Error changing working directory");
exit(1);
}
return result;
}

original_code:
void daemonize() {
  pid_t pid, sid;
  pid = fork();
  if (pid < 0) {
    perror("Error");
    exit(1);
  }
  if (pid > 0) {
    syslog(5, "forked to background with PID %i", pid);
    exit(0);
  }
  umask(0);
  sid = setsid();
  if (sid < 0) {
    perror("Error retrieving a new SID");
    exit(1);
  }
  if ((chdir(getenv("HOME"))) < 0) {
    perror("Error changing working directory");
    exit(1);
  }
}

canonical_original_code:
void daemonize() {
  int pid; int sid;
  pid = fork();
  if (pid < 0) {
    perror("Error");
    exit(1);
  }
  if (pid > 0) {
    syslog(5, "forked to background with PID %i", pid);
    exit(0);
  }
  umask(0);
  sid = setsid();
  if (sid < 0) {
    perror("Error retrieving a new SID");
    exit(1);
  }
  if ((chdir(getenv("HOME"))) < 0) {
    perror("Error changing working directory");
    exit(1);
  }
}

variable_types: pid int

variable_types: sid int