decompiled_code:
__int64 __fastcall b64_encode(char *a1, size_t a2, const char *a3, size_t a4)
{
size_t v4; // r13
char *v5; // r12
unsigned __int64 v6; // r15
const char *v7; // r13
const char *v8; // rbx
char *v9; // rax
__int64 result; // rax
char *v11; // rdi
char v12; // bp
_BYTE *v13; // r14
_BYTE *v14; // r12
int v15; // ebp
char *v16; // [rsp+0h] [rbp-68h]
const char *v17; // [rsp+8h] [rbp-60h]
char *ptr; // [rsp+28h] [rbp-40h]

v4 = a4;
if ( !a4 )
v4 = strlen(a3);
v5 = a1;
ptr = 0LL;
if ( a3 == a1 )
{
v9 = (char *)malloc(a2);
v5 = v9;
if ( !v9 )
return 0xFFFFFFFFLL;
ptr = v9;
}
v6 = (unsigned __int64)&v5[a2];
v7 = &a3[v4];
if ( a3 >= v7 )
{
LABEL_25:
if ( v6 > (unsigned __int64)v5 )
*v5 = 0;
if ( a3 == a1 )
{
memcpy(a1, ptr, a2);
free(ptr);
}
result = (unsigned int)((_DWORD)v5 - (_DWORD)a1);
}
else
{
v8 = a3;
while ( 1 )
{
v12 = (16 * *v8) & 0x30;
v16 = v5;
v13 = v5 + 1;
if ( (unsigned int)add_char(v5, (unsigned __int8)*v8 >> 2, 0, v6) )
{
result = 0xFFFFFFFFLL;
v11 = ptr;
if ( !ptr )
return result;
LABEL_15:
free(v11);
return 0xFFFFFFFFLL;
}
v14 = v5 + 2;
if ( (unsigned int)add_char(v13, (unsigned __int8)((unsigned __int8)v8[1] >> 4) | v12, 0, v6) )
break;
v17 = v8;
v15 = v7 == v8 + 1;
if ( (unsigned int)add_char(v14, (4 * v8[1]) & 0x3Cu | ((unsigned __int8)v8[2] >> 6), v15, v6) )
{
result = 0xFFFFFFFFLL;
v11 = ptr;
if ( !ptr )
return result;
goto LABEL_15;
}
if ( v7 == v8 + 2 )
v15 = 1;
v8 += 3;
v5 = v16 + 4;
if ( (unsigned int)add_char(v16 + 3, v17[2] & 0x3F, v15, v6) )
{
result = 0xFFFFFFFFLL;
v11 = ptr;
if ( !ptr )
return result;
goto LABEL_15;
}
if ( v7 == v8 || v7 <= v8 || v15 )
goto LABEL_25;
}
result = 0xFFFFFFFFLL;
if ( ptr )
{
free(ptr);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, size_t a2, const char *a3, size_t a4)
{
size_t v4; // r13
char *v5; // r12
unsigned __int64 v6; // r15
const char *v7; // r13
const char *v8; // rbx
char *v9; // rax
__int64 result; // rax
char *v11; // rdi
char v12; // bp
_BYTE *v13; // r14
_BYTE *v14; // r12
int v15; // ebp
char *v16; // [rsp+0h] [rbp-68h]
const char *v17; // [rsp+8h] [rbp-60h]
char *ptr; // [rsp+28h] [rbp-40h]

v4 = a4;
if ( !a4 )
v4 = strlen(a3);
v5 = a1;
ptr = 0LL;
if ( a3 == a1 )
{
v9 = (char *)malloc(a2);
v5 = v9;
if ( !v9 )
return 0xFFFFFFFFLL;
ptr = v9;
}
v6 = (unsigned __int64)&v5[a2];
v7 = &a3[v4];
if ( a3 >= v7 )
{
LABEL_25:
if ( v6 > (unsigned __int64)v5 )
*v5 = 0;
if ( a3 == a1 )
{
memcpy(a1, ptr, a2);
free(ptr);
}
result = (unsigned int)((_DWORD)v5 - (_DWORD)a1);
}
else
{
v8 = a3;
while ( 1 )
{
v12 = (16 * *v8) & 0x30;
v16 = v5;
v13 = v5 + 1;
if ( (unsigned int)func0(v5, (unsigned __int8)*v8 >> 2, 0, v6) )
{
result = 0xFFFFFFFFLL;
v11 = ptr;
if ( !ptr )
return result;
LABEL_15:
free(v11);
return 0xFFFFFFFFLL;
}
v14 = v5 + 2;
if ( (unsigned int)func0(v13, (unsigned __int8)((unsigned __int8)v8[1] >> 4) | v12, 0, v6) )
break;
v17 = v8;
v15 = v7 == v8 + 1;
if ( (unsigned int)func0(v14, (4 * v8[1]) & 0x3Cu | ((unsigned __int8)v8[2] >> 6), v15, v6) )
{
result = 0xFFFFFFFFLL;
v11 = ptr;
if ( !ptr )
return result;
goto LABEL_15;
}
if ( v7 == v8 + 2 )
v15 = 1;
v8 += 3;
v5 = v16 + 4;
if ( (unsigned int)func0(v16 + 3, v17[2] & 0x3F, v15, v6) )
{
result = 0xFFFFFFFFLL;
v11 = ptr;
if ( !ptr )
return result;
goto LABEL_15;
}
if ( v7 == v8 || v7 <= v8 || v15 )
goto LABEL_25;
}
result = 0xFFFFFFFFLL;
if ( ptr )
{
free(ptr);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int b64_encode(char *target, size_t tlen, const char *source, size_t slen) {
 const char *inp;
 char *outp;
 char *outend;
 const char *inend;
 char *tmpbuf=((void *)0);
 int done=0;
 char enc;
 int buf;
 if(slen==0)
  slen=strlen(source);
 inp=source;
 if(source==target) {
  tmpbuf=(char *)malloc(tlen);
  if(tmpbuf==((void *)0))
   return(-1);
  outp=tmpbuf;
 }
 else
  outp=target;
 outend=outp+tlen;
 inend=inp+slen;
 for(;(inp < inend) && !done;) {
  enc=*(inp++);
  buf=(enc & 0x03)<<4;
  enc=(enc&0xFC)>>2;
  if(add_char(outp++, enc, done, outend)) {
   if(tmpbuf!=((void *)0)) { free(tmpbuf); tmpbuf=((void *)0); };
   return(-1);
  }
  enc=buf|((*inp & 0xF0) >> 4);
  if(add_char(outp++, enc, done, outend)) {
   if(tmpbuf!=((void *)0)) { free(tmpbuf); tmpbuf=((void *)0); };
   return(-1);
  }
  if(inp==inend)
   done=1;
  buf=(*(inp++)<<2)&0x3C;
  enc=buf|((*inp & 0xC0)>>6);
  if(add_char(outp++, enc, done, outend)) {
   if(tmpbuf!=((void *)0)) { free(tmpbuf); tmpbuf=((void *)0); };
   return(-1);
  }
  if(inp==inend)
   done=1;
  enc=((int)*(inp++))&0x3F;
  if(add_char(outp++, enc, done, outend)) {
   if(tmpbuf!=((void *)0)) { free(tmpbuf); tmpbuf=((void *)0); };
   return(-1);
  }
  if(inp==inend)
   done=1;
 }
 if(outp<outend)
  *outp=0;
 if(target==source) {
  memcpy(target,tmpbuf,tlen);
  free(tmpbuf);
 }
 return(outp-target);
}

canonical_original_code:
int b64_encode(char *target, unsigned long tlen, char *source, unsigned long slen) {
 char *inp;
 char *outp;
 char *outend;
 char *inend;
 char *tmpbuf = ((void *)0);
 int done = 0;
 char enc;
 int buf;
 if(slen==0)
  slen=strlen(source);
 inp=source;
 if(source==target) {
  tmpbuf=(char *)malloc(tlen);
  if(tmpbuf==((void *)0))
   return(-1);
  outp=tmpbuf;
 }
 else
  outp=target;
 outend=outp+tlen;
 inend=inp+slen;
 for(;(inp < inend) && !done;) {
  enc=*(inp++);
  buf=(enc & 0x03)<<4;
  enc=(enc&0xFC)>>2;
  if(add_char(outp++, enc, done, outend)) {
   if(tmpbuf!=((void *)0)) { free(tmpbuf); tmpbuf=((void *)0); };
   return(-1);
  }
  enc=buf|((*inp & 0xF0) >> 4);
  if(add_char(outp++, enc, done, outend)) {
   if(tmpbuf!=((void *)0)) { free(tmpbuf); tmpbuf=((void *)0); };
   return(-1);
  }
  if(inp==inend)
   done=1;
  buf=(*(inp++)<<2)&0x3C;
  enc=buf|((*inp & 0xC0)>>6);
  if(add_char(outp++, enc, done, outend)) {
   if(tmpbuf!=((void *)0)) { free(tmpbuf); tmpbuf=((void *)0); };
   return(-1);
  }
  if(inp==inend)
   done=1;
  enc=((int)*(inp++))&0x3F;
  if(add_char(outp++, enc, done, outend)) {
   if(tmpbuf!=((void *)0)) { free(tmpbuf); tmpbuf=((void *)0); };
   return(-1);
  }
  if(inp==inend)
   done=1;
 }
 if(outp<outend)
  *outp=0;
 if(target==source) {
  memcpy(target,tmpbuf,tlen);
  free(tmpbuf);
 }
 return(outp-target);
}

variable_types:
tmpbuf
char *

variable_types: enc char

variable_types: buf int


repo: ftnapps/pkg-sbbs

decompiled_code:
__int64 __fastcall smb_subject_crc(char *s1)
{
char *v1; // rbx
unsigned int v2; // ebp
char *i; // rax
char *v4; // rax
char *v5; // rbx

v1 = s1;
if ( !s1 )
return (unsigned int)-1;
while ( !strncasecmp(v1, "RE:", 3uLL) )
{
for ( i = v1 + 3; *i == 32; ++i )
;
v1 = i;
}
v4 = strdup(v1);
v5 = v4;
if ( !v4 )
return (unsigned int)-1;
strlwr(v4);
v2 = crc16(v5, 0LL);
free(v5);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1)
{
char *v1; // rbx
unsigned int v2; // ebp
char *i; // rax
char *v4; // rax
char *v5; // rbx

v1 = s1;
if ( !s1 )
return (unsigned int)-1;
while ( !strncasecmp(v1, "RE:", 3uLL) )
{
for ( i = v1 + 3; *i == 32; ++i )
;
v1 = i;
}
v4 = strdup(v1);
v5 = v4;
if ( !v4 )
return (unsigned int)-1;
strlwr(v4);
v2 = crc16(v5, 0LL);
free(v5);
return v2;
}

original_code:
ushort smb_subject_crc(const char* subj)
{
 char* str;
 ushort crc;
 if(subj==((void *)0))
  return(0xffff);
 while(!strncasecmp(subj,"RE:",3)) {
  subj+=3;
  while(*subj==' ')
   subj++;
 }
 if((str=strdup(subj))==((void *)0))
  return(0xffff);
 strlwr(str);
 crc=crc16(str,0 );
 free(str);
 return(crc);
}

canonical_original_code:
unsigned short smb_subject_crc(char *subj)
{
 char *str;
 unsigned short crc;
 if(subj==((void *)0))
  return(0xffff);
 while(!strncasecmp(subj,"RE:",3)) {
  subj+=3;
  while(*subj==' ')
   subj++;
 }
 if((str=strdup(subj))==((void *)0))
  return(0xffff);
 strlwr(str);
 crc=crc16(str,0 );
 free(str);
 return(crc);
}

variable_types:
subj
char *

variable_types:
str
char *

variable_types:
crc
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall smb_name_crc(const char *a1)
{
char *v1; // rax
char *v2; // rbx
unsigned int v3; // ebp

if ( !a1 )
return (unsigned int)-1;
v1 = strdup(a1);
v2 = v1;
if ( !v1 )
return (unsigned int)-1;
strlwr(v1);
v3 = crc16(v2, 0LL);
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
char *v1; // rax
char *v2; // rbx
unsigned int v3; // ebp

if ( !a1 )
return (unsigned int)-1;
v1 = strdup(a1);
v2 = v1;
if ( !v1 )
return (unsigned int)-1;
strlwr(v1);
v3 = crc16(v2, 0LL);
free(v2);
return v3;
}

original_code:
ushort smb_name_crc(const char* name)
{
 char* str;
 ushort crc;
 if(name==((void *)0))
  return(0xffff);
 if((str=strdup(name))==((void *)0))
  return(0xffff);
 strlwr(str);
 crc=crc16(str,0 );
 free(str);
 return(crc);
}

canonical_original_code:
unsigned short smb_name_crc(char *name)
{
 char *str;
 unsigned short crc;
 if(name==((void *)0))
  return(0xffff);
 if((str=strdup(name))==((void *)0))
  return(0xffff);
 strlwr(str);
 crc=crc16(str,0 );
 free(str);
 return(crc);
}

variable_types:
name
char *


decompiled_code:
const char *__fastcall display_filename(__int64 a1, unsigned __int16 a2, unsigned __int16 a3)
{
const char *v4; // rcx
int v5; // ebp
const char *result; // rax
char buf[37]; // [rsp+3h] [rbp-25h] BYREF

v4 = *(const char **)(*(_QWORD *)(a1 + 64) + 8LL * a2);
sprintf(str_0, "%s%s.IXB", v4 + 467, v4);
v5 = nopen(str_0, 0LL);
result = "UNKNOWN";
if ( v5 != -1 )
{
lseek(v5, 22 * (a3 - 1), 0);
read(v5, buf, 0xBuLL);
close(v5);
sprintf(str_0, "%-8.8s.%c%c%c", buf, (unsigned int)buf[8], (unsigned int)buf[9], (unsigned int)buf[10]);
result = str_0;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1, unsigned __int16 a2, unsigned __int16 a3)
{
const char *v4; // rcx
int v5; // ebp
const char *result; // rax
char buf[37]; // [rsp+3h] [rbp-25h] BYREF

v4 = *(const char **)(*(_QWORD *)(a1 + 64) + 8LL * a2);
sprintf(str_0, "%s%s.IXB", v4 + 467, v4);
v5 = nopen(str_0, 0LL);
result = "UNKNOWN";
if ( v5 != -1 )
{
lseek(v5, 22 * (a3 - 1), 0);
read(v5, buf, 0xBuLL);
close(v5);
sprintf(str_0, "%-8.8s.%c%c%c", buf, (unsigned int)buf[8], (unsigned int)buf[9], (unsigned int)buf[10]);
result = str_0;
}
return result;
}

original_code:
char *display_filename(scfg_t *cfg, ushort dir_num,ushort fil_off)
{
 static char str[256];
 char fname[13];
 int file;
 sprintf(str,"%s%s.IXB",cfg->dir[dir_num]->data_dir,cfg->dir[dir_num]->code);
 if((file=nopen(str,00))==-1)
  return("UNKNOWN");
 lseek(file,(long)(22*(fil_off-1)),0);
 read(file,fname,11);
 close(file);
 sprintf(str,"%-8.8s.%c%c%c",fname,fname[8],fname[9],fname[10]);
 return(str);
}

canonical_original_code:
char *display_filename(struct scfg_t *cfg, unsigned short dir_num, unsigned short fil_off)
{
 static char str[256];
 char fname[13];
 int file;
 sprintf(str,"%s%s.IXB",cfg->dir[dir_num]->data_dir,cfg->dir[dir_num]->code);
 if((file=nopen(str,00))==-1)
  return("UNKNOWN");
 lseek(file,(long)(22*(fil_off-1)),0);
 read(file,fname,11);
 close(file);
 sprintf(str,"%-8.8s.%c%c%c",fname,fname[8],fname[9],fname[10]);
 return(str);
}

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:
str
char [256]

variable_types:
fname
char [13]

variable_types: file int

return_type: char *

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; }


bail

decompiled_code:
void __fastcall __noreturn bail(int a1)
{
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
exit(a1);
}

original_code:
void bail(int code)
{
exit(code);
}

canonical_original_code:
void bail(int code)
{
exit(code);
}

variable_types: code int

return_type: void


lputs

original_code:
long lputs(char *str)
{
    char tmp[256];
    int i,j,k;
j=strlen(str);
for(i=k=0;i<j;i++)
    if(str[i]=='\r' && str[i+1]=='\n')
        continue;
    else
        tmp[k++]=str[i];
tmp[k]=0;
return(fputs(tmp,stderr));
}

canonical_original_code:
long lputs(char *str)
{
    char tmp[256];
    int i; int j; int k;
j=strlen(str);
for(i=k=0;i<j;i++)
    if(str[i]=='\r' && str[i+1]=='\n')
        continue;
    else
        tmp[k++]=str[i];
tmp[k]=0;
return(fputs(tmp,stderr));
}

variable_types:
tmp
char [256]

variable_types: i int

variable_types: j int

variable_types: k int

return_type: long


lprintf

decompiled_code:
__int64 lprintf(char *format, ...)
{
unsigned int v1; // ebx
char v3[264]; // [rsp+0h] [rbp-1D8h] BYREF
gcc_va_list arg; // [rsp+108h] [rbp-D0h] BYREF

va_start(arg, format);
v1 = vsprintf(v3, format, arg);
lputs(v3);
return v1;
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
unsigned int v1; // ebx
char v3[264]; // [rsp+0h] [rbp-1D8h] BYREF
gcc_va_list arg; // [rsp+108h] [rbp-D0h] BYREF

va_start(arg, format);
v1 = vsprintf(v3, format, arg);
func1(v3);
return v1;
}

original_code:
int lprintf(char *fmat, ...)
{
 va_list argptr;
 char sbuf[256];
 int chcount;
__builtin_va_start(argptr,fmat);
chcount=vsprintf(sbuf,fmat,argptr);
__builtin_va_end(argptr);
lputs(sbuf);
return(chcount);
}

canonical_original_code:
int lprintf(char *fmat, ...)
{
 __builtin_va_list argptr;
 char sbuf[256];
 int chcount;
__builtin_va_start(argptr,fmat);
chcount=vsprintf(sbuf,fmat,argptr);
__builtin_va_end(argptr);
lputs(sbuf);
return(chcount);
}

variable_types:
fmat
char *

variable_types:
sbuf
char [256]

variable_types: chcount int

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // rbx
const char *v5; // r13
unsigned __int16 v6; // ax
unsigned __int16 v7; // bp
unsigned __int16 v8; // bx
unsigned __int64 v9; // r14
_QWORD *v10; // r15
_QWORD *v12; // rax
_QWORD *v13; // rax
unsigned int v14; // eax
int v15; // er14
signed __int64 v16; // rbp
unsigned __int16 v17; // ax
_QWORD *v18; // r13
char *v19; // rax
char *v20; // r12
signed __int64 v21; // r14
int v22; // er15
unsigned __int16 v23; // ax
unsigned __int16 v24; // ax
__int64 v25; // rdx
__int64 v26; // rbp
const char *v27; // rax
int v28; // ebx
__int64 v29; // rax
_QWORD *v30; // r12
unsigned __int16 v31; // dx
unsigned __int64 *v32; // r13
unsigned __int64 v33; // rax
unsigned __int64 *v34; // r12
_QWORD *v35; // rax
unsigned __int64 *v36; // r15
__int64 v37; // rdx
unsigned __int16 v38; // ax
unsigned __int64 v39; // [rsp+0h] [rbp-6228h]
unsigned __int16 v40; // [rsp+Ch] [rbp-621Ch]
__int16 v41; // [rsp+Eh] [rbp-621Ah]
const char *v42; // [rsp+18h] [rbp-6210h]
__int64 v43; // [rsp+20h] [rbp-6208h]
const char *v44; // [rsp+28h] [rbp-6200h]
unsigned __int16 v45; // [rsp+30h] [rbp-61F8h]
unsigned __int16 v46; // [rsp+32h] [rbp-61F6h]
_QWORD *v47; // [rsp+40h] [rbp-61E8h]
unsigned __int16 v48; // [rsp+4Ch] [rbp-61DCh]
unsigned __int16 v49; // [rsp+4Eh] [rbp-61DAh]
unsigned __int64 v50; // [rsp+50h] [rbp-61D8h]
unsigned __int64 *v51; // [rsp+58h] [rbp-61D0h]
__int64 s[3090]; // [rsp+60h] [rbp-61C8h] BYREF
char v53[312]; // [rsp+60F0h] [rbp-138h] BYREF

putenv("TZ=UCT0");
setvbuf(stdout, 0LL, 2, 0LL);
fprintf(stderr, "\nDUPEFIND Version %s (%s) - Synchronet Duplicate File Finder\n", "1.01", "Linux");
v3 = getenv("SBBSCTRL");
if ( !v3 )
{
fwrite("\nSBBSCTRL environment variable must be set.\n", 1uLL, 0x2CuLL, stderr);
fwrite("\nExample: export SBBSCTRL=/sbbs/ctrl\n", 1uLL, 0x25uLL, stderr);
return 1;
}
v4 = v3;
if ( argc > 1 )
{
v5 = argv[1];
if ( !strcasecmp(v5, "/?") || !strcasecmp(v5, "?") || !strcasecmp(v5, "-?") )
{
fputc(10, stderr);
fwrite("usage: DUPEFIND [start] [end]\n", 1uLL, 0x1EuLL, stderr);
fwrite("where: [start] is the starting library number to check\n", 1uLL, 0x37uLL, stderr);
fwrite(" [end] is the final library number to check\n", 1uLL, 0x34uLL, stderr);
return 0;
}
memset(s, 0, 0x6088uLL);
s[0] = 24712LL;
strncpy((char *)&s[746] + 4, v4, 0x3FuLL);
if ( (unsigned int)load_cfg(s, 0LL, 1LL, v53) )
{
chdir((const char *)&s[746] + 4);
lputs("\n");
v6 = atoi(argv[1]) - 1;
v48 = v6;
if ( argc <= 2 )
v46 = v6;
else
v46 = atoi(argv[2]) - 1;
goto LABEL_9;
}
LABEL_15:
fprintf(stderr, "!ERROR loading configuration files: %s\n", v53);
return 1;
}
memset(s, 0, 0x6088uLL);
s[0] = 24712LL;
strncpy((char *)&s[746] + 4, v4, 0x3FuLL);
if ( !(unsigned int)load_cfg(s, 0LL, 1LL, v53) )
goto LABEL_15;
chdir((const char *)&s[746] + 4);
lputs("\n");
v46 = LOWORD(s[7]) - 1;
v48 = 0;
LABEL_9:
v7 = s[9];
v47 = malloc(8LL * LOWORD(s[9]));
if ( !v47 )
{
LABEL_16:
puts("Not enough memory for CRCs.\r");
return 1;
}
v8 = 0;
if ( v7 )
{
do
{
fprintf(stderr, "Reading directory index %u of %u\r", (unsigned int)v8 + 1, v7);
sprintf(v53, "%s%s.ixb", (const char *)(*(_QWORD *)(s[8] + 8LL * v8) + 467LL), *(const char **)(s[8] + 8LL * v8));
v14 = nopen(v53, 0LL);
v15 = v14;
if ( v14 == -1 )
{
v12 = malloc(8uLL);
v47[v8] = v12;
*v12 = 0LL;
}
else
{
v16 = filelength(v14);
if ( v16 && (v17 = *(_WORD *)(*(_QWORD *)(s[8] + 8LL * v8) + 586LL), v17 <= v46) && v17 >= v48 )
{
v18 = malloc(8 * (v16 / 22) + 16);
v47[v8] = v18;
if ( !v18 )
goto LABEL_16;
*v18 = v16 / 22;
v19 = (char *)malloc(v16);
v20 = v19;
if ( v19 )
{
if ( read(v15, v19, v16) == v16 )
{
close(v15);
if ( v16 > 0 )
{
v21 = 0LL;
v22 = 1;
do
{
sprintf(v53, "%-11.11s", &v20[v21]);
strupr(v53);
v23 = v22++;
v18[v23] = crc32i(-1LL, v53, 0LL);
v21 += 22LL;
}
while ( v16 > v21 );
}
free(v20);
}
else
{
close(v15);
printf("\aError reading %s.\r\n", v53);
free(v20);
}
}
else
{
close(v15);
printf("\aError allocating memory for index %s.\r\n", v53);
}
}
else
{
close(v15);
v13 = malloc(8uLL);
v47[v8] = v13;
*v13 = 0LL;
}
}
++v8;
v7 = s[9];
}
while ( LOWORD(s[9]) > v8 );
}
lputs("\n");
if ( !LOWORD(s[9]) )
return 0;
v41 = -1;
v49 = 0;
v9 = 0LL;
v10 = 0LL;
while ( 1 )
{
v37 = *(_QWORD *)(s[8] + 8LL * v49);
v38 = *(_WORD *)(v37 + 586);
if ( v38 <= v46 && v38 >= v48 )
{
lprintf("Scanning %s %s\n", (const char *)(*(_QWORD *)(s[6] + 8LL * v38) + 41LL), (const char *)(v37 + 67));
v51 = (unsigned __int64 *)v47[v49];
v50 = *v51;
if ( *v51 > 1 )
break;
}
LABEL_57:
if ( LOWORD(s[9]) <= ++v49 )
return 0;
}
v45 = 1;
v33 = 1LL;
while ( 1 )
{
v40 = v49 + 1;
if ( (unsigned __int16)(v49 + 1) >= LOWORD(s[9]) )
break;
v34 = &v51[v33];
v35 = v10;
v36 = v34;
v30 = v35;
do
{
v31 = *(_WORD *)(*(_QWORD *)(s[8] + 8LL * v40) + 586LL);
if ( v31 <= v46 && v31 >= v48 )
{
v32 = (unsigned __int64 *)v47[v40];
v39 = *v32;
if ( *v32 > 1 )
{
v28 = 1;
v29 = 1LL;
do
{
if ( *v36 == v32[v29] )
{
if ( v45 == v41 )
{
printf(
"%-12s and : %-*s %s\n",
(const char *)&unk_C75,
15,
(const char *)(*(_QWORD *)(s[6] + 8LL * *(unsigned __int16 *)(*(_QWORD *)(s[8] + 8LL * v40) + 586LL))
+ 41LL),
(const char *)(*(_QWORD *)(s[8] + 8LL * v40) + 67LL));
}
else
{
if ( !v9 )
goto LABEL_44;
v24 = 0;
v25 = 0LL;
do
{
if ( *v36 == v30[v25] )
v24 = v9 + 1;
v25 = ++v24;
}
while ( v24 < v9 );
v41 = 0;
if ( v24 == v9 )
{
LABEL_44:
++v9;
v30 = realloc(v30, 8 * v9);
if ( !v30 )
{
puts("Out of memory reallocating\r");
return 1;
}
v41 = v45;
}
v26 = *(_QWORD *)(s[8] + 8LL * v40);
v42 = (const char *)(*(_QWORD *)(s[6] + 8LL * *(unsigned __int16 *)(v26 + 586)) + 41LL);
v43 = *(_QWORD *)(s[8] + 8LL * v49);
v44 = (const char *)(*(_QWORD *)(s[6] + 8LL * *(unsigned __int16 *)(v43 + 586)) + 41LL);
v27 = display_filename((__int64)s, v49, v45);
printf(
"\n%-12s is located in : %-*s %s\n%-12s and : %-*s %s\n",
v27,
15,
v44,
(const char *)(v43 + 67),
(const char *)&unk_C75,
15,
v42,
(const char *)(v26 + 67));
}
}
v29 = (unsigned __int16)++v28;
}
while ( (unsigned __int16)v28 < v39 );
}
}
++v40;
}
while ( LOWORD(s[9]) > v40 );
v10 = v30;
v33 = (unsigned __int16)(v45 + 1);
if ( v33 >= v50 )
goto LABEL_57;
LABEL_54:
++v45;
}
v33 = (unsigned __int16)(v45 + 1);
if ( v33 < v50 )
goto LABEL_54;
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // rbx
const char *v5; // r13
unsigned __int16 v6; // ax
unsigned __int16 v7; // bp
unsigned __int16 v8; // bx
unsigned __int64 v9; // r14
_QWORD *v10; // r15
_QWORD *v12; // rax
_QWORD *v13; // rax
unsigned int v14; // eax
int v15; // er14
signed __int64 v16; // rbp
unsigned __int16 v17; // ax
_QWORD *v18; // r13
char *v19; // rax
char *v20; // r12
signed __int64 v21; // r14
int v22; // er15
unsigned __int16 v23; // ax
unsigned __int16 v24; // ax
__int64 v25; // rdx
__int64 v26; // rbp
const char *v27; // rax
int v28; // ebx
__int64 v29; // rax
_QWORD *v30; // r12
unsigned __int16 v31; // dx
unsigned __int64 *v32; // r13
unsigned __int64 v33; // rax
unsigned __int64 *v34; // r12
_QWORD *v35; // rax
unsigned __int64 *v36; // r15
__int64 v37; // rdx
unsigned __int16 v38; // ax
unsigned __int64 v39; // [rsp+0h] [rbp-6228h]
unsigned __int16 v40; // [rsp+Ch] [rbp-621Ch]
__int16 v41; // [rsp+Eh] [rbp-621Ah]
const char *v42; // [rsp+18h] [rbp-6210h]
__int64 v43; // [rsp+20h] [rbp-6208h]
const char *v44; // [rsp+28h] [rbp-6200h]
unsigned __int16 v45; // [rsp+30h] [rbp-61F8h]
unsigned __int16 v46; // [rsp+32h] [rbp-61F6h]
_QWORD *v47; // [rsp+40h] [rbp-61E8h]
unsigned __int16 v48; // [rsp+4Ch] [rbp-61DCh]
unsigned __int16 v49; // [rsp+4Eh] [rbp-61DAh]
unsigned __int64 v50; // [rsp+50h] [rbp-61D8h]
unsigned __int64 *v51; // [rsp+58h] [rbp-61D0h]
__int64 s[3090]; // [rsp+60h] [rbp-61C8h] BYREF
char v53[312]; // [rsp+60F0h] [rbp-138h] BYREF

putenv("TZ=UCT0");
setvbuf(stdout, 0LL, 2, 0LL);
fprintf(stderr, "\nDUPEFIND Version %s (%s) - Synchronet Duplicate File Finder\n", "1.01", "Linux");
v3 = getenv("SBBSCTRL");
if ( !v3 )
{
fwrite("\nSBBSCTRL environment variable must be set.\n", 1uLL, 0x2CuLL, stderr);
fwrite("\nExample: export SBBSCTRL=/sbbs/ctrl\n", 1uLL, 0x25uLL, stderr);
return 1;
}
v4 = v3;
if ( argc > 1 )
{
v5 = argv[1];
if ( !strcasecmp(v5, "/?") || !strcasecmp(v5, "?") || !strcasecmp(v5, "-?") )
{
fputc(10, stderr);
fwrite("usage: DUPEFIND [start] [end]\n", 1uLL, 0x1EuLL, stderr);
fwrite("where: [start] is the starting library number to check\n", 1uLL, 0x37uLL, stderr);
fwrite(" [end] is the final library number to check\n", 1uLL, 0x34uLL, stderr);
return 0;
}
memset(s, 0, 0x6088uLL);
s[0] = 24712LL;
strncpy((char *)&s[746] + 4, v4, 0x3FuLL);
if ( (unsigned int)load_cfg(s, 0LL, 1LL, v53) )
{
chdir((const char *)&s[746] + 4);
func1("\n");
v6 = atoi(argv[1]) - 1;
v48 = v6;
if ( argc <= 2 )
v46 = v6;
else
v46 = atoi(argv[2]) - 1;
goto LABEL_9;
}
LABEL_15:
fprintf(stderr, "!ERROR loading configuration files: %s\n", v53);
return 1;
}
memset(s, 0, 0x6088uLL);
s[0] = 24712LL;
strncpy((char *)&s[746] + 4, v4, 0x3FuLL);
if ( !(unsigned int)load_cfg(s, 0LL, 1LL, v53) )
goto LABEL_15;
chdir((const char *)&s[746] + 4);
func1("\n");
v46 = LOWORD(s[7]) - 1;
v48 = 0;
LABEL_9:
v7 = s[9];
v47 = malloc(8LL * LOWORD(s[9]));
if ( !v47 )
{
LABEL_16:
puts("Not enough memory for CRCs.\r");
return 1;
}
v8 = 0;
if ( v7 )
{
do
{
fprintf(stderr, "Reading directory index %u of %u\r", (unsigned int)v8 + 1, v7);
sprintf(v53, "%s%s.ixb", (const char *)(*(_QWORD *)(s[8] + 8LL * v8) + 467LL), *(const char **)(s[8] + 8LL * v8));
v14 = nopen(v53, 0LL);
v15 = v14;
if ( v14 == -1 )
{
v12 = malloc(8uLL);
v47[v8] = v12;
*v12 = 0LL;
}
else
{
v16 = filelength(v14);
if ( v16 && (v17 = *(_WORD *)(*(_QWORD *)(s[8] + 8LL * v8) + 586LL), v17 <= v46) && v17 >= v48 )
{
v18 = malloc(8 * (v16 / 22) + 16);
v47[v8] = v18;
if ( !v18 )
goto LABEL_16;
*v18 = v16 / 22;
v19 = (char *)malloc(v16);
v20 = v19;
if ( v19 )
{
if ( read(v15, v19, v16) == v16 )
{
close(v15);
if ( v16 > 0 )
{
v21 = 0LL;
v22 = 1;
do
{
sprintf(v53, "%-11.11s", &v20[v21]);
strupr(v53);
v23 = v22++;
v18[v23] = crc32i(-1LL, v53, 0LL);
v21 += 22LL;
}
while ( v16 > v21 );
}
free(v20);
}
else
{
close(v15);
printf("\aError reading %s.\r\n", v53);
free(v20);
}
}
else
{
close(v15);
printf("\aError allocating memory for index %s.\r\n", v53);
}
}
else
{
close(v15);
v13 = malloc(8uLL);
v47[v8] = v13;
*v13 = 0LL;
}
}
++v8;
v7 = s[9];
}
while ( LOWORD(s[9]) > v8 );
}
func1("\n");
if ( !LOWORD(s[9]) )
return 0;
v41 = -1;
v49 = 0;
v9 = 0LL;
v10 = 0LL;
while ( 1 )
{
v37 = *(_QWORD *)(s[8] + 8LL * v49);
v38 = *(_WORD *)(v37 + 586);
if ( v38 <= v46 && v38 >= v48 )
{
func2("Scanning %s %s\n", (const char *)(*(_QWORD *)(s[6] + 8LL * v38) + 41LL), (const char *)(v37 + 67));
v51 = (unsigned __int64 *)v47[v49];
v50 = *v51;
if ( *v51 > 1 )
break;
}
LABEL_57:
if ( LOWORD(s[9]) <= ++v49 )
return 0;
}
v45 = 1;
v33 = 1LL;
while ( 1 )
{
v40 = v49 + 1;
if ( (unsigned __int16)(v49 + 1) >= LOWORD(s[9]) )
break;
v34 = &v51[v33];
v35 = v10;
v36 = v34;
v30 = v35;
do
{
v31 = *(_WORD *)(*(_QWORD *)(s[8] + 8LL * v40) + 586LL);
if ( v31 <= v46 && v31 >= v48 )
{
v32 = (unsigned __int64 *)v47[v40];
v39 = *v32;
if ( *v32 > 1 )
{
v28 = 1;
v29 = 1LL;
do
{
if ( *v36 == v32[v29] )
{
if ( v45 == v41 )
{
printf(
"%-12s and : %-*s %s\n",
(const char *)&unk_C75,
15,
(const char *)(*(_QWORD *)(s[6] + 8LL * *(unsigned __int16 *)(*(_QWORD *)(s[8] + 8LL * v40) + 586LL))
+ 41LL),
(const char *)(*(_QWORD *)(s[8] + 8LL * v40) + 67LL));
}
else
{
if ( !v9 )
goto LABEL_44;
v24 = 0;
v25 = 0LL;
do
{
if ( *v36 == v30[v25] )
v24 = v9 + 1;
v25 = ++v24;
}
while ( v24 < v9 );
v41 = 0;
if ( v24 == v9 )
{
LABEL_44:
++v9;
v30 = realloc(v30, 8 * v9);
if ( !v30 )
{
puts("Out of memory reallocating\r");
return 1;
}
v41 = v45;
}
v26 = *(_QWORD *)(s[8] + 8LL * v40);
v42 = (const char *)(*(_QWORD *)(s[6] + 8LL * *(unsigned __int16 *)(v26 + 586)) + 41LL);
v43 = *(_QWORD *)(s[8] + 8LL * v49);
v44 = (const char *)(*(_QWORD *)(s[6] + 8LL * *(unsigned __int16 *)(v43 + 586)) + 41LL);
v27 = func3((__int64)s, v49, v45);
printf(
"\n%-12s is located in : %-*s %s\n%-12s and : %-*s %s\n",
v27,
15,
v44,
(const char *)(v43 + 67),
(const char *)&unk_C75,
15,
v42,
(const char *)(v26 + 67));
}
}
v29 = (unsigned __int16)++v28;
}
while ( (unsigned __int16)v28 < v39 );
}
}
++v40;
}
while ( LOWORD(s[9]) > v40 );
v10 = v30;
v33 = (unsigned __int16)(v45 + 1);
if ( v33 >= v50 )
goto LABEL_57;
LABEL_54:
++v45;
}
v33 = (unsigned __int16)(v45 + 1);
if ( v33 < v50 )
goto LABEL_54;
return 0;
}

original_code:
int main(int argc,char **argv)
{
 char str[256],*ixbbuf,*p;
 ulong **fcrc,*foundcrc,total_found=0L;
 ushort i,j,k,h,g,start_lib=0,end_lib=0,found=-1;
 int file;
    long l,m;
 scfg_t cfg;
putenv("TZ=UCT0");
setvbuf(stdout,((void *)0),2,0);
fprintf(stderr,"\nDUPEFIND Version %s (%s) - Synchronet Duplicate File "
 "Finder\n", "1.01", "Linux");
    p=getenv("SBBSCTRL");
    if(p==((void *)0)) {
  fprintf(stderr,"\nSBBSCTRL environment variable must be set.\n");
  fprintf(stderr,"\nExample: export SBBSCTRL=/sbbs/ctrl\n");
        return(1); }
 if(argc>1 && (!strcasecmp(argv[1],"/?") || !strcasecmp(argv[1],"?") || !strcasecmp(argv[1],"-?"))) {
  fprintf(stderr,"\n");
  fprintf(stderr,"usage: DUPEFIND [start] [end]\n");
  fprintf(stderr,"where: [start] is the starting library number to check\n");
  fprintf(stderr,"       [end]   is the final library number to check\n");
  return(0); }
 memset(&cfg,0,sizeof(cfg));
 cfg.size=sizeof(cfg);
 (strncpy(cfg.ctrl_dir,p,sizeof(cfg.ctrl_dir)), cfg.ctrl_dir[sizeof(cfg.ctrl_dir)-1]=0);
 if(!load_cfg(&cfg,((void *)0),1,str)) {
  fprintf(stderr,"!ERROR loading configuration files: %s\n",str);
  return(1);
 }
 chdir(cfg.ctrl_dir);
 lputs("\n");
 start_lib=0;
 end_lib=cfg.total_libs-1;
 if(argc>1)
  start_lib=end_lib=atoi(argv[1])-1;
 if(argc>2)
        end_lib=atoi(argv[2])-1;
 if((fcrc=(ulong **)malloc(cfg.total_dirs*sizeof(ulong *)))==((void *)0)) {
  printf("Not enough memory for CRCs.\r\n");
  return(1); }
 for(i=0;i<cfg.total_dirs;i++) {
  fprintf(stderr,"Reading directory index %u of %u\r",i+1,cfg.total_dirs);
        sprintf(str,"%s%s.ixb",cfg.dir[i]->data_dir,cfg.dir[i]->code);
  if((file=nopen(str,00|0))==-1) {
   fcrc[i]=(ulong *)malloc(1*sizeof(ulong));
            fcrc[i][0]=0;
   continue; }
        l=filelength(file);
  if(!l || (cfg.dir[i]->lib<start_lib || cfg.dir[i]->lib>end_lib)) {
            close(file);
   fcrc[i]=(ulong *)malloc(1*sizeof(ulong));
   fcrc[i][0]=0;
            continue; }
  if((fcrc[i]=(ulong *)malloc((l/22+2)*sizeof(ulong)))==((void *)0)) {
            printf("Not enough memory for CRCs.\r\n");
            return(1); }
  fcrc[i][0]=(ulong)(l/22);
        if((ixbbuf=(char *)malloc(l))==((void *)0)) {
            close(file);
            printf("\7Error allocating memory for index %s.\r\n",str);
            continue; }
        if(read(file,ixbbuf,l)!=l) {
            close(file);
            printf("\7Error reading %s.\r\n",str);
   free(ixbbuf);
            continue; }
        close(file);
  j=1;
  m=0L;
  while(m<l) {
   sprintf(str,"%-11.11s",(ixbbuf+m));
   strupr(str);
   fcrc[i][j++]=crc32i(~0UL,str,0);
   m+=22; }
  free(ixbbuf); }
 lputs("\n");
 foundcrc=0L;
 for(i=0;i<cfg.total_dirs;i++) {
  if(cfg.dir[i]->lib<start_lib || cfg.dir[i]->lib>end_lib)
   continue;
  lprintf("Scanning %s %s\n",cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->sname);
  for(k=1;k<fcrc[i][0];k++) {
   for(j=i+1;j<cfg.total_dirs;j++) {
    if(cfg.dir[j]->lib<start_lib || cfg.dir[j]->lib>end_lib)
     continue;
    for(h=1;h<fcrc[j][0];h++) {
     if(fcrc[i][k]==fcrc[j][h]) {
      if(found!=k) {
       found=k;
       for(g=0;g<total_found;g++) {
        if(foundcrc[g]==fcrc[i][k])
         g=total_found+1; }
       if(g==total_found) {
        ++total_found;
        if((foundcrc=(ulong *)realloc(foundcrc
         ,total_found*sizeof(ulong)))==((void *)0)) {
        printf("Out of memory reallocating\r\n");
        return(1); } }
       else
        found=0;
       printf("\n%-12s is located in : %-*s  %s\n"
           "%-12s           and : %-*s  %s\n"
        ,display_filename(&cfg,i,k)
        ,15
        ,cfg.lib[cfg.dir[i]->lib]->sname
        ,cfg.dir[i]->sname
        ,""
        ,15
        ,cfg.lib[cfg.dir[j]->lib]->sname
        ,cfg.dir[j]->sname
        ); }
      else
       printf("%-12s           and : %-*s  %s\n"
        ,""
        ,15
        ,cfg.lib[cfg.dir[j]->lib]->sname
        ,cfg.dir[j]->sname
        ); } } } } }
 return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char str[256]; char *ixbbuf; char *p;
 unsigned long **fcrc; unsigned long *foundcrc; unsigned long total_found = 0L;
 unsigned short i; unsigned short j; unsigned short k; unsigned short h; unsigned short g; unsigned short start_lib = 0; unsigned short end_lib = 0; unsigned short found = -1;
 int file;
    long l; long m;
 struct scfg_t cfg;
putenv("TZ=UCT0");
setvbuf(stdout,((void *)0),2,0);
fprintf(stderr,"\nDUPEFIND Version %s (%s) - Synchronet Duplicate File "
 "Finder\n", "1.01", "Linux");
    p=getenv("SBBSCTRL");
    if(p==((void *)0)) {
  fprintf(stderr,"\nSBBSCTRL environment variable must be set.\n");
  fprintf(stderr,"\nExample: export SBBSCTRL=/sbbs/ctrl\n");
        return(1); }
 if(argc>1 && (!strcasecmp(argv[1],"/?") || !strcasecmp(argv[1],"?") || !strcasecmp(argv[1],"-?"))) {
  fprintf(stderr,"\n");
  fprintf(stderr,"usage: DUPEFIND [start] [end]\n");
  fprintf(stderr,"where: [start] is the starting library number to check\n");
  fprintf(stderr,"       [end]   is the final library number to check\n");
  return(0); }
 memset(&cfg,0,sizeof(cfg));
 cfg.size=sizeof(cfg);
 (strncpy(cfg.ctrl_dir,p,sizeof(cfg.ctrl_dir)), cfg.ctrl_dir[sizeof(cfg.ctrl_dir)-1]=0);
 if(!load_cfg(&cfg,((void *)0),1,str)) {
  fprintf(stderr,"!ERROR loading configuration files: %s\n",str);
  return(1);
 }
 chdir(cfg.ctrl_dir);
 lputs("\n");
 start_lib=0;
 end_lib=cfg.total_libs-1;
 if(argc>1)
  start_lib=end_lib=atoi(argv[1])-1;
 if(argc>2)
        end_lib=atoi(argv[2])-1;
 if((fcrc=(unsigned long **)malloc(cfg.total_dirs*sizeof(unsigned long *)))==((void *)0)) {
  printf("Not enough memory for CRCs.\r\n");
  return(1); }
 for(i=0;i<cfg.total_dirs;i++) {
  fprintf(stderr,"Reading directory index %u of %u\r",i+1,cfg.total_dirs);
        sprintf(str,"%s%s.ixb",cfg.dir[i]->data_dir,cfg.dir[i]->code);
  if((file=nopen(str,00|0))==-1) {
   fcrc[i]=(unsigned long *)malloc(1*sizeof(ulong));
            fcrc[i][0]=0;
   continue; }
        l=filelength(file);
  if(!l || (cfg.dir[i]->lib<start_lib || cfg.dir[i]->lib>end_lib)) {
            close(file);
   fcrc[i]=(unsigned long *)malloc(1*sizeof(ulong));
   fcrc[i][0]=0;
            continue; }
  if((fcrc[i]=(unsigned long *)malloc((l/22+2)*sizeof(ulong)))==((void *)0)) {
            printf("Not enough memory for CRCs.\r\n");
            return(1); }
  fcrc[i][0]=(ulong)(l/22);
        if((ixbbuf=(char *)malloc(l))==((void *)0)) {
            close(file);
            printf("\7Error allocating memory for index %s.\r\n",str);
            continue; }
        if(read(file,ixbbuf,l)!=l) {
            close(file);
            printf("\7Error reading %s.\r\n",str);
   free(ixbbuf);
            continue; }
        close(file);
  j=1;
  m=0L;
  while(m<l) {
   sprintf(str,"%-11.11s",(ixbbuf+m));
   strupr(str);
   fcrc[i][j++]=crc32i(~0UL,str,0);
   m+=22; }
  free(ixbbuf); }
 lputs("\n");
 foundcrc=0L;
 for(i=0;i<cfg.total_dirs;i++) {
  if(cfg.dir[i]->lib<start_lib || cfg.dir[i]->lib>end_lib)
   continue;
  lprintf("Scanning %s %s\n",cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->sname);
  for(k=1;k<fcrc[i][0];k++) {
   for(j=i+1;j<cfg.total_dirs;j++) {
    if(cfg.dir[j]->lib<start_lib || cfg.dir[j]->lib>end_lib)
     continue;
    for(h=1;h<fcrc[j][0];h++) {
     if(fcrc[i][k]==fcrc[j][h]) {
      if(found!=k) {
       found=k;
       for(g=0;g<total_found;g++) {
        if(foundcrc[g]==fcrc[i][k])
         g=total_found+1; }
       if(g==total_found) {
        ++total_found;
        if((foundcrc=(unsigned long *)realloc(foundcrc
         ,total_found*sizeof(ulong)))==((void *)0)) {
        printf("Out of memory reallocating\r\n");
        return(1); } }
       else
        found=0;
       printf("\n%-12s is located in : %-*s  %s\n"
           "%-12s           and : %-*s  %s\n"
        ,display_filename(&cfg,i,k)
        ,15
        ,cfg.lib[cfg.dir[i]->lib]->sname
        ,cfg.dir[i]->sname
        ,""
        ,15
        ,cfg.lib[cfg.dir[j]->lib]->sname
        ,cfg.dir[j]->sname
        ); }
      else
       printf("%-12s           and : %-*s  %s\n"
        ,""
        ,15
        ,cfg.lib[cfg.dir[j]->lib]->sname
        ,cfg.dir[j]->sname
        ); } } } } }
 return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
ixbbuf
char *

variable_types:
p
char *

variable_types:
fcrc
unsigned long **

variable_types:
foundcrc
unsigned long *

variable_types:
i
unsigned short

variable_types:
j
unsigned short

variable_types:
k
unsigned short

variable_types:
h
unsigned short

variable_types:
g
unsigned short

variable_types:
found
unsigned short

variable_types: l long

variable_types: m long

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; }


inkey

original_code:
int inkey(void)
{
 int c;
 c=ciolib_getch();
 if(!c || c==0xff)
  c|=(ciolib_getch()<<8);
 return(c);
}

canonical_original_code:
int inkey()
{
 int c;
 c=ciolib_getch();
 if(!c || c==0xff)
  c|=(ciolib_getch()<<8);
 return(c);
}

variable_types: c int


identify

decompiled_code:
char *__fastcall identify(const __m128i *a1, unsigned __int16 a2, char *a3, size_t a4, int a5)
{
int v6; // er12
int v7; // eax
int v8; // ebx
int v9; // eax
__int64 v10; // r14
unsigned __int16 v11; // ax
size_t v12; // rax
ssize_t v13; // r13
int v14; // eax
int *v15; // rax
int v16; // eax
int *v17; // rax
int *v18; // rax
int *v19; // rax
int *v21; // rax
int *v22; // rax
fd_set writefds; // [rsp+10h] [rbp-168h] BYREF
struct timeval timeout; // [rsp+90h] [rbp-E8h] BYREF
struct sockaddr addr; // [rsp+A0h] [rbp-D8h] BYREF
__int64 v27; // [rsp+B8h] [rbp-C0h] BYREF
char s[184]; // [rsp+C0h] [rbp-B8h] BYREF

v6 = a5;
if ( a5 < 0 )
v6 = 10;
v7 = open_socket(1LL, "ident");
v8 = v7;
if ( v7 == -1 )
{
v15 = _errno_location();
sprintf(a3, "ERROR %d creating socket", (unsigned int)*v15);
a3 = 0LL;
goto LABEL_19;
}
v27 = 1LL;
ioctl(v7, 0x5421uLL, &v27);
addr = (struct sockaddr)_mm_loadu_si128(a1);
*(_WORD *)addr.sa_data = _bswap_16(113);
v9 = connect(v8, &addr, 0x10u);
if ( v9 == -1 )
{
v16 = *_errno_location();
if ( v16 == 11 || v16 == 115 )
{
timeout.tv_sec = v6;
timeout.tv_usec = 0LL;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v8 / 64] |= 1LL << (v8 % 64);
if ( select(v8 + 1, 0LL, &writefds, 0LL, &timeout) == 1 )
goto LABEL_6;
}
LABEL_14:
v17 = _errno_location();
sprintf(a3, "ERROR %d connecting to server", (unsigned int)*v17);
a3 = 0LL;
goto LABEL_19;
}
if ( v9 )
goto LABEL_14;
LABEL_6:
v27 = 0LL;
ioctl(v8, 0x5421uLL, &v27);
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
memset(&writefds, 0, sizeof(writefds));
v10 = 1LL << (v8 % 64);
writefds.fds_bits[v8 / 64] |= v10;
if ( select(v8 + 1, 0LL, &writefds, 0LL, &timeout) <= 0 )
{
v18 = _errno_location();
sprintf(a3, "ERROR %d selecting socket for send", (unsigned int)*v18);
a3 = 0LL;
}
else
{
v11 = _bswap_16(a1->m128i_i16[1]);
sprintf(s, "%u, %u\r\n", v11, a2);
v12 = strlen(s);
v13 = write(v8, s, v12);
if ( v13 == (int)strlen(s) )
{
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v8 / 64] |= v10;
if ( select(v8 + 1, &writefds, 0LL, 0LL, &timeout) <= 0 )
{
v21 = _errno_location();
sprintf(a3, "ERROR %d detecting response", (unsigned int)*v21);
a3 = 0LL;
}
else
{
v14 = recv(v8, a3, a4, 0);
if ( v14 <= 0 )
{
v22 = _errno_location();
sprintf(a3, "ERROR %d receiving response", (unsigned int)*v22);
a3 = 0LL;
}
else
{
a3[v14] = 0;
truncsp(a3);
}
}
}
else
{
v19 = _errno_location();
sprintf(a3, "ERROR %d sending request", (unsigned int)*v19);
a3 = 0LL;
}
}
LABEL_19:
close_socket((unsigned int)v8);
return a3;
}

canonical_decompiled_code:
char *__fastcall func1(const __m128i *a1, unsigned __int16 a2, char *a3, size_t a4, int a5)
{
int v6; // er12
int v7; // eax
int v8; // ebx
int v9; // eax
__int64 v10; // r14
unsigned __int16 v11; // ax
size_t v12; // rax
ssize_t v13; // r13
int v14; // eax
int *v15; // rax
int v16; // eax
int *v17; // rax
int *v18; // rax
int *v19; // rax
int *v21; // rax
int *v22; // rax
fd_set writefds; // [rsp+10h] [rbp-168h] BYREF
struct timeval timeout; // [rsp+90h] [rbp-E8h] BYREF
struct sockaddr addr; // [rsp+A0h] [rbp-D8h] BYREF
__int64 v27; // [rsp+B8h] [rbp-C0h] BYREF
char s[184]; // [rsp+C0h] [rbp-B8h] BYREF

v6 = a5;
if ( a5 < 0 )
v6 = 10;
v7 = open_socket(1LL, "ident");
v8 = v7;
if ( v7 == -1 )
{
v15 = _errno_location();
sprintf(a3, "ERROR %d creating socket", (unsigned int)*v15);
a3 = 0LL;
goto LABEL_19;
}
v27 = 1LL;
ioctl(v7, 0x5421uLL, &v27);
addr = (struct sockaddr)_mm_loadu_si128(a1);
*(_WORD *)addr.sa_data = func0(113);
v9 = connect(v8, &addr, 0x10u);
if ( v9 == -1 )
{
v16 = *_errno_location();
if ( v16 == 11 || v16 == 115 )
{
timeout.tv_sec = v6;
timeout.tv_usec = 0LL;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v8 / 64] |= 1LL << (v8 % 64);
if ( select(v8 + 1, 0LL, &writefds, 0LL, &timeout) == 1 )
goto LABEL_6;
}
LABEL_14:
v17 = _errno_location();
sprintf(a3, "ERROR %d connecting to server", (unsigned int)*v17);
a3 = 0LL;
goto LABEL_19;
}
if ( v9 )
goto LABEL_14;
LABEL_6:
v27 = 0LL;
ioctl(v8, 0x5421uLL, &v27);
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
memset(&writefds, 0, sizeof(writefds));
v10 = 1LL << (v8 % 64);
writefds.fds_bits[v8 / 64] |= v10;
if ( select(v8 + 1, 0LL, &writefds, 0LL, &timeout) <= 0 )
{
v18 = _errno_location();
sprintf(a3, "ERROR %d selecting socket for send", (unsigned int)*v18);
a3 = 0LL;
}
else
{
v11 = func0(a1->m128i_i16[1]);
sprintf(s, "%u, %u\r\n", v11, a2);
v12 = strlen(s);
v13 = write(v8, s, v12);
if ( v13 == (int)strlen(s) )
{
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v8 / 64] |= v10;
if ( select(v8 + 1, &writefds, 0LL, 0LL, &timeout) <= 0 )
{
v21 = _errno_location();
sprintf(a3, "ERROR %d detecting response", (unsigned int)*v21);
a3 = 0LL;
}
else
{
v14 = recv(v8, a3, a4, 0);
if ( v14 <= 0 )
{
v22 = _errno_location();
sprintf(a3, "ERROR %d receiving response", (unsigned int)*v22);
a3 = 0LL;
}
else
{
a3[v14] = 0;
truncsp(a3);
}
}
}
else
{
v19 = _errno_location();
sprintf(a3, "ERROR %d sending request", (unsigned int)*v19);
a3 = 0LL;
}
}
LABEL_19:
close_socket((unsigned int)v8);
return a3;
}

original_code:
char* identify(struct sockaddr_in* client_addr, u_short local_port, char* buf
      ,size_t maxlen, int timeout)
{
 char req[128];
 char* identity=((void *)0);
 int i;
 int result;
 int rd;
 ulong val;
 int sock=(int)(~0);
 struct sockaddr_in addr;
 struct timeval tv;
 fd_set socket_set;
 if(timeout<0)
  timeout=10;
 do {
  if((sock = open_socket(SOCK_STREAM, "ident")) == (int)(~0)) {
   sprintf(buf,"ERROR %d creating socket",(*__errno_location ()));
   break;
  }
  val=1;
  ioctl(sock,0x5421,&val);
  addr=*client_addr;
  addr.sin_port=htons(113);
  result=connect(sock, (struct sockaddr*)&addr, sizeof(addr));
  if(result==-1
   && ((*__errno_location ())==11 || (*__errno_location ())==115)) {
   tv.tv_sec=timeout;
   tv.tv_usec=0;
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&socket_set)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&socket_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
   if(select(sock+1,((void *)0),&socket_set,((void *)0),&tv)==1)
    result=0;
  }
  if(result!=0) {
   sprintf(buf,"ERROR %d connecting to server",(*__errno_location ()));
   break;
  }
  val=0;
  ioctl(sock,0x5421,&val);
  tv.tv_sec=10;
  tv.tv_usec=0;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&socket_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&socket_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
  i=select(sock+1,((void *)0),&socket_set,((void *)0),&tv);
  if(i<1) {
   sprintf(buf,"ERROR %d selecting socket for send",(*__errno_location ()));
   break;
  }
  sprintf(req,"%u, %u\r\n", ntohs(client_addr->sin_port), local_port);
  if(write(sock,req,strlen(req))!=(int)strlen(req)) {
   sprintf(buf,"ERROR %d sending request",(*__errno_location ()));
   break;
  }
  tv.tv_sec=10;
  tv.tv_usec=0;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&socket_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&socket_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
  i=select(sock+1,&socket_set,((void *)0),((void *)0),&tv);
  if(i<1) {
   sprintf(buf,"ERROR %d detecting response",(*__errno_location ()));
   break;
  }
  rd=recv(sock,buf,maxlen,0);
  if(rd<1) {
   sprintf(buf,"ERROR %d receiving response",(*__errno_location ()));
   break;
  }
  buf[rd]=0;
  truncsp(buf);
  identity=buf;
 } while(0);
 close_socket(sock);
 return(identity);
}

canonical_original_code:
char *identify(struct sockaddr_in *client_addr, unsigned short local_port, char *buf, unsigned long maxlen, int timeout)
{
 char req[128];
 char *identity = ((void *)0);
 int i;
 int result;
 int rd;
 unsigned long val;
 int sock = (int)(~0);
 struct sockaddr_in addr;
 struct timeval tv;
 struct fd_set socket_set;
 if(timeout<0)
  timeout=10;
 do {
  if((sock = open_socket(SOCK_STREAM, "ident")) == (int)(~0)) {
   sprintf(buf,"ERROR %d creating socket",(*__errno_location ()));
   break;
  }
  val=1;
  ioctl(sock,0x5421,&val);
  addr=*client_addr;
  addr.sin_port=htons(113);
  result=connect(sock, (struct sockaddr *)&addr, sizeof(addr));
  if(result==-1
   && ((*__errno_location ())==11 || (*__errno_location ())==115)) {
   tv.tv_sec=timeout;
   tv.tv_usec=0;
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&socket_set)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&socket_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
   if(select(sock+1,((void *)0),&socket_set,((void *)0),&tv)==1)
    result=0;
  }
  if(result!=0) {
   sprintf(buf,"ERROR %d connecting to server",(*__errno_location ()));
   break;
  }
  val=0;
  ioctl(sock,0x5421,&val);
  tv.tv_sec=10;
  tv.tv_usec=0;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&socket_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&socket_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
  i=select(sock+1,((void *)0),&socket_set,((void *)0),&tv);
  if(i<1) {
   sprintf(buf,"ERROR %d selecting socket for send",(*__errno_location ()));
   break;
  }
  sprintf(req,"%u, %u\r\n", ntohs(client_addr->sin_port), local_port);
  if(write(sock,req,strlen(req))!=(int)strlen(req)) {
   sprintf(buf,"ERROR %d sending request",(*__errno_location ()));
   break;
  }
  tv.tv_sec=10;
  tv.tv_usec=0;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&socket_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&socket_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
  i=select(sock+1,&socket_set,((void *)0),((void *)0),&tv);
  if(i<1) {
   sprintf(buf,"ERROR %d detecting response",(*__errno_location ()));
   break;
  }
  rd=recv(sock,buf,maxlen,0);
  if(rd<1) {
   sprintf(buf,"ERROR %d receiving response",(*__errno_location ()));
   break;
  }
  buf[rd]=0;
  truncsp(buf);
  identity=buf;
 } while(0);
 close_socket(sock);
 return(identity);
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types:
buf
char *

variable_types:
maxlen
unsigned long

variable_types: timeout int

variable_types:
req
char [128]

variable_types:
identity
char *

variable_types: i int

variable_types: result int

variable_types: rd int

variable_types:
val
unsigned long

variable_types: sock int

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

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


itoa

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


getnodedat

decompiled_code:
int __fastcall getnodedat(unsigned int a1, void *a2, int a3)
{
__off_t v4; // rbp
int v5; // ebx
ssize_t v6; // rax
struct timeval v8; // [rsp+0h] [rbp-38h] BYREF

v4 = 19LL * (int)(a1 - 1);
v5 = 0;
while ( 1 )
{
lseek(nodefile, v4, 0);
if ( !a3 || (unsigned int)lock((unsigned int)nodefile, v4, 19LL) != -1 )
{
v6 = read(nodefile, a2, 0x13uLL);
if ( v6 == 19 )
break;
}
if ( ++v5 == 50 )
goto LABEL_10;
if ( v5 )
{
v8.tv_sec = 0LL;
v8.tv_usec = 100000LL;
select(0, 0LL, 0LL, 0LL, &v8);
}
}
if ( v5 <= 24 )
return v6;
LABEL_10:
LODWORD(v6) = printf("NODE.DAB (node %d) COLLISION (READ) - Count: %d\n", a1, (unsigned int)v5);
return v6;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, void *a2, int a3)
{
__off_t v4; // rbp
int v5; // ebx
ssize_t v6; // rax
struct timeval v8; // [rsp+0h] [rbp-38h] BYREF

v4 = 19LL * (int)(a1 - 1);
v5 = 0;
while ( 1 )
{
lseek(nodefile, v4, 0);
if ( !a3 || (unsigned int)lock((unsigned int)nodefile, v4, 19LL) != -1 )
{
v6 = read(nodefile, a2, 0x13uLL);
if ( v6 == 19 )
break;
}
if ( ++v5 == 50 )
goto LABEL_10;
if ( v5 )
{
v8.tv_sec = 0LL;
v8.tv_usec = 100000LL;
select(0, 0LL, 0LL, 0LL, &v8);
}
}
if ( v5 <= 24 )
return v6;
LABEL_10:
LODWORD(v6) = printf("NODE.DAB (node %d) COLLISION (READ) - Count: %d\n", a1, (unsigned int)v5);
return v6;
}

original_code:
void getnodedat(int number, node_t *node, int lockit)
{
 int count;
 number--;
 for(count=0;count<50;count++) {
  if(count)
   ({ int sleep_msecs=100; 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); });
  lseek(nodefile,(long)number*sizeof(node_t),0);
  if(lockit
   && lock(nodefile,(long)number*sizeof(node_t),sizeof(node_t))==-1)
   continue;
  if(read(nodefile,node,sizeof(node_t))==sizeof(node_t))
   break;
 }
 if(count>=(50/2))
  printf("NODE.DAB (node %d) COLLISION (READ) - Count: %d\n"
   ,number+1, count);
 else if(count==50) {
  printf("!Error reading nodefile for node %d\n",number+1);
 }
}

canonical_original_code:
void getnodedat(int number, struct node_t *node, int lockit)
{
 int count;
 number--;
 for(count=0;count<50;count++) {
  if(count)
   ({ int sleep_msecs = 100; 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); });
  lseek(nodefile,(long)number*sizeof(node_t),0);
  if(lockit
   && lock(nodefile,(long)number*sizeof(node_t),sizeof(node_t))==-1)
   continue;
  if(read(nodefile,node,sizeof(node_t))==sizeof(node_t))
   break;
 }
 if(count>=(50/2))
  printf("NODE.DAB (node %d) COLLISION (READ) - Count: %d\n"
   ,number+1, count);
 else if(count==50) {
  printf("!Error reading nodefile for node %d\n",number+1);
 }
}

variable_types: number int

variable_types: struct node_t { unsigned char status; unsigned short useron; unsigned long extaux; } *

variable_types: lockit int

variable_types: count int

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


putnodedat

decompiled_code:
int __fastcall putnodedat(unsigned int a1, int a2, int a3, int a4, int a5, int a6, char buf)
{
__off_t v7; // rbp

v7 = 19LL * (int)(a1 - 1);
lseek(nodefile, v7, 0);
if ( write(nodefile, &buf, 0x13uLL) == 19 )
return unlock((unsigned int)nodefile, v7, 19LL);
unlock((unsigned int)nodefile, v7, 19LL);
return printf("Error writing to nodefile for node %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, int a2, int a3, int a4, int a5, int a6, char buf)
{
__off_t v7; // rbp

v7 = 19LL * (int)(a1 - 1);
lseek(nodefile, v7, 0);
if ( write(nodefile, &buf, 0x13uLL) == 19 )
return unlock((unsigned int)nodefile, v7, 19LL);
unlock((unsigned int)nodefile, v7, 19LL);
return printf("Error writing to nodefile for node %d\n", a1);
}

original_code:
void putnodedat(int number, node_t node)
{
 number--;
 lseek(nodefile,(long)number*sizeof(node_t),0);
 if(write(nodefile,&node,sizeof(node_t))!=sizeof(node_t)) {
  unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
  printf("Error writing to nodefile for node %d\n",number+1);
  return; }
 unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
}

canonical_original_code:
void putnodedat(int number, struct node_t node)
{
 number--;
 lseek(nodefile,(long)number*sizeof(node_t),0);
 if(write(nodefile,&node,sizeof(node_t))!=sizeof(node_t)) {
  unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
  printf("Error writing to nodefile for node %d\n",number+1);
  return; }
 unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
}

variable_types: struct node_t { unsigned char status; unsigned short useron; unsigned long extaux; }


printnodedat

decompiled_code:
int __fastcall printnodedat(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, __int64 a8)
{
char v8; // bp
unsigned __int8 v9; // r12
unsigned __int8 v10; // r15
unsigned __int16 v11; // r13
__int16 v12; // bx
unsigned __int16 v13; // r14
__int16 v15; // si
__int64 v16; // rdx
__int64 v17; // r8
__int64 v18; // r9
const char *v19; // rax
char *v20; // rax
__int64 v21; // [rsp-20h] [rbp-68h] BYREF
__int128 v22; // [rsp-18h] [rbp-60h]
char v23[59]; // [rsp+Dh] [rbp-3Bh] BYREF

v8 = a7;
v9 = BYTE1(a7);
v10 = BYTE2(a7);
v11 = *(_WORD *)((char *)&a7 + 5);
v12 = *(_WORD *)((char *)&a7 + 7);
v13 = *(_WORD *)((char *)&a7 + 9);
printf("Node %2d: ", a1);
switch ( v8 )
{
case 0:
printf("Waiting for call");
break;
case 1:
printf("At logon prompt");
break;
case 2:
printf("New user");
printf(" applying for access ");
if ( v11 )
{
if ( v11 == 0xFFFF )
printf("via telnet");
else
printf("at %ubps", v11);
}
else
{
printf("locally");
}
break;
case 3:
case 4:
printf("User #%d", *(unsigned __int16 *)((char *)&a7 + 3));
putchar(32);
switch ( v10 )
{
case 0u:
printf("at main menu");
break;
case 1u:
printf("reading messages");
break;
case 2u:
printf("reading mail");
break;
case 3u:
printf("sending mail");
break;
case 4u:
printf("reading text files");
break;
case 5u:
printf("reading sent mail");
break;
case 6u:
printf("posting message");
break;
case 7u:
printf("posting auto-message");
break;
case 8u:
if ( v13 )
printf("running external program #%d", v13);
else
printf("at external program menu");
break;
case 9u:
printf("changing defaults");
break;
case 0xAu:
printf("at transfer menu");
break;
case 0xBu:
printf("downloading");
break;
case 0xCu:
printf("uploading");
break;
case 0xDu:
printf("transferring bidirectional");
break;
case 0xEu:
printf("listing files");
break;
case 0xFu:
printf("logging on");
break;
case 0x10u:
printf("in local chat with sysop");
break;
case 0x11u:
if ( v13 )
{
printf("in multinode chat channel %d", (unsigned __int8)v13);
if ( (v13 & 0x1F00) != 0 )
{
putchar(42);
qmemcpy(&v21, &a7, 0x13uLL);
v19 = unpackchatpass(tmp, (__int64)&a8 + 3, v16, 0LL, v17, v18, v21, v22);
printf(" %s", v19);
}
}
else
{
printf("in multinode global chat channel");
}
break;
case 0x12u:
printf("chatting with The Guru");
break;
case 0x13u:
printf("in chat section");
break;
case 0x14u:
printf("performing sysop activities");
break;
case 0x15u:
printf("transferring QWK packet");
break;
case 0x16u:
printf("in private chat with node %u", v13);
break;
case 0x17u:
printf("paging node %u for private chat", v13);
break;
case 0x18u:
printf("retrieving from device #%d", v13);
break;
default:
v20 = itoa(v10, tmp, 10LL);
printf(v20);
break;
}
if ( v11 )
{
if ( v11 == 0xFFFF )
printf(" via telnet");
else
printf(" at %ubps", v11);
}
else
{
printf(" locally");
}
if ( v10 == 11 )
{
if ( v13 <= 0x2CFu )
{
LOBYTE(v15) = 12;
if ( v13 > 0x3Bu )
v15 = v13 / 0x3Cu;
strcpy(v23, "am");
}
else
{
LOBYTE(v15) = 12;
if ( (unsigned __int16)(v13 - 720) > 0x3Bu )
LOBYTE(v15) = v13 / 0x3Cu - 12;
strcpy(v23, "pm");
}
printf(" ETA %02d:%02d %s", (unsigned int)(char)v15, v13 % 0x3Cu, v23);
}
break;
case 5:
printf("Offline");
break;
case 6:
printf("Networking");
break;
case 7:
printf("Waiting for all nodes to become inactive");
break;
case 8:
printf("Running external event");
break;
case 9:
printf("Waiting for node %d to finish external event", v13);
break;
default:
break;
}
if ( (v12 & 0x83A) != 0 )
{
printf(" (");
if ( (v12 & 0x20) != 0 )
putchar(65);
if ( (v12 & 2) != 0 )
putchar(76);
if ( (v12 & 0x808) != 0 )
putchar(77);
if ( (v12 & 0x10) != 0 )
putchar(80);
putchar(41);
}
if ( (v12 & 0x3C5) != 0 || v8 == 4 )
{
printf(" [");
if ( (v12 & 1) != 0 )
putchar(65);
if ( (v12 & 4) != 0 )
putchar(73);
if ( (v12 & 0x80u) != 0 )
putchar(82);
if ( (v12 & 0x40) != 0 )
putchar(85);
if ( v8 == 4 )
putchar(81);
if ( (v12 & 0x100) != 0 )
putchar(69);
if ( (v12 & 0x200) != 0 )
putchar(68);
if ( (v12 & 0x2000) != 0 )
putchar(67);
putchar(93);
}
if ( v9 )
printf(" %d error%c", v9, v9 >= 2u ? 0x73 : 0);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, __int64 a8)
{
char v8; // bp
unsigned __int8 v9; // r12
unsigned __int8 v10; // r15
unsigned __int16 v11; // r13
__int16 v12; // bx
unsigned __int16 v13; // r14
__int16 v15; // si
__int64 v16; // rdx
__int64 v17; // r8
__int64 v18; // r9
const char *v19; // rax
char *v20; // rax
__int64 v21; // [rsp-20h] [rbp-68h] BYREF
__int128 v22; // [rsp-18h] [rbp-60h]
char v23[59]; // [rsp+Dh] [rbp-3Bh] BYREF

v8 = a7;
v9 = BYTE1(a7);
v10 = BYTE2(a7);
v11 = *(_WORD *)((char *)&a7 + 5);
v12 = *(_WORD *)((char *)&a7 + 7);
v13 = *(_WORD *)((char *)&a7 + 9);
printf("Node %2d: ", a1);
switch ( v8 )
{
case 0:
printf("Waiting for call");
break;
case 1:
printf("At logon prompt");
break;
case 2:
printf("New user");
printf(" applying for access ");
if ( v11 )
{
if ( v11 == 0xFFFF )
printf("via telnet");
else
printf("at %ubps", v11);
}
else
{
printf("locally");
}
break;
case 3:
case 4:
printf("User #%d", *(unsigned __int16 *)((char *)&a7 + 3));
putchar(32);
switch ( v10 )
{
case 0u:
printf("at main menu");
break;
case 1u:
printf("reading messages");
break;
case 2u:
printf("reading mail");
break;
case 3u:
printf("sending mail");
break;
case 4u:
printf("reading text files");
break;
case 5u:
printf("reading sent mail");
break;
case 6u:
printf("posting message");
break;
case 7u:
printf("posting auto-message");
break;
case 8u:
if ( v13 )
printf("running external program #%d", v13);
else
printf("at external program menu");
break;
case 9u:
printf("changing defaults");
break;
case 0xAu:
printf("at transfer menu");
break;
case 0xBu:
printf("downloading");
break;
case 0xCu:
printf("uploading");
break;
case 0xDu:
printf("transferring bidirectional");
break;
case 0xEu:
printf("listing files");
break;
case 0xFu:
printf("logging on");
break;
case 0x10u:
printf("in local chat with sysop");
break;
case 0x11u:
if ( v13 )
{
printf("in multinode chat channel %d", (unsigned __int8)v13);
if ( (v13 & 0x1F00) != 0 )
{
putchar(42);
qmemcpy(&v21, &a7, 0x13uLL);
v19 = unpackchatpass(tmp, (__int64)&a8 + 3, v16, 0LL, v17, v18, v21, v22);
printf(" %s", v19);
}
}
else
{
printf("in multinode global chat channel");
}
break;
case 0x12u:
printf("chatting with The Guru");
break;
case 0x13u:
printf("in chat section");
break;
case 0x14u:
printf("performing sysop activities");
break;
case 0x15u:
printf("transferring QWK packet");
break;
case 0x16u:
printf("in private chat with node %u", v13);
break;
case 0x17u:
printf("paging node %u for private chat", v13);
break;
case 0x18u:
printf("retrieving from device #%d", v13);
break;
default:
v20 = func0(v10, tmp, 10LL);
printf(v20);
break;
}
if ( v11 )
{
if ( v11 == 0xFFFF )
printf(" via telnet");
else
printf(" at %ubps", v11);
}
else
{
printf(" locally");
}
if ( v10 == 11 )
{
if ( v13 <= 0x2CFu )
{
LOBYTE(v15) = 12;
if ( v13 > 0x3Bu )
v15 = v13 / 0x3Cu;
strcpy(v23, "am");
}
else
{
LOBYTE(v15) = 12;
if ( (unsigned __int16)(v13 - 720) > 0x3Bu )
LOBYTE(v15) = v13 / 0x3Cu - 12;
strcpy(v23, "pm");
}
printf(" ETA %02d:%02d %s", (unsigned int)(char)v15, v13 % 0x3Cu, v23);
}
break;
case 5:
printf("Offline");
break;
case 6:
printf("Networking");
break;
case 7:
printf("Waiting for all nodes to become inactive");
break;
case 8:
printf("Running external event");
break;
case 9:
printf("Waiting for node %d to finish external event", v13);
break;
default:
break;
}
if ( (v12 & 0x83A) != 0 )
{
printf(" (");
if ( (v12 & 0x20) != 0 )
putchar(65);
if ( (v12 & 2) != 0 )
putchar(76);
if ( (v12 & 0x808) != 0 )
putchar(77);
if ( (v12 & 0x10) != 0 )
putchar(80);
putchar(41);
}
if ( (v12 & 0x3C5) != 0 || v8 == 4 )
{
printf(" [");
if ( (v12 & 1) != 0 )
putchar(65);
if ( (v12 & 4) != 0 )
putchar(73);
if ( (v12 & 0x80u) != 0 )
putchar(82);
if ( (v12 & 0x40) != 0 )
putchar(85);
if ( v8 == 4 )
putchar(81);
if ( (v12 & 0x100) != 0 )
putchar(69);
if ( (v12 & 0x200) != 0 )
putchar(68);
if ( (v12 & 0x2000) != 0 )
putchar(67);
putchar(93);
}
if ( v9 )
printf(" %d error%c", v9, v9 >= 2u ? 0x73 : 0);
return putchar(10);
}

original_code:
void printnodedat(int number, node_t node)
{
    char hour,mer[3];
 printf("Node %2d: ",number);
 switch(node.status) {
  case NODE_WFC:
   printf("Waiting for call");
   break;
  case NODE_OFFLINE:
   printf("Offline");
   break;
  case NODE_NETTING:
   printf("Networking");
   break;
  case NODE_LOGON:
   printf("At logon prompt");
   break;
  case NODE_EVENT_WAITING:
   printf("Waiting for all nodes to become inactive");
   break;
  case NODE_EVENT_LIMBO:
   printf("Waiting for node %d to finish external event",node.aux);
   break;
  case NODE_EVENT_RUNNING:
   printf("Running external event");
   break;
  case NODE_NEWUSER:
   printf("New user");
   printf(" applying for access ");
   if(!node.connection)
    printf("locally");
   else if(node.connection==0xffff)
    printf("via telnet");
   else
    printf("at %ubps",node.connection);
   break;
  case NODE_QUIET:
  case NODE_INUSE:
   printf("User #%d",node.useron);
   printf(" ");
   switch(node.action) {
    case NODE_MAIN:
     printf("at main menu");
     break;
    case NODE_RMSG:
     printf("reading messages");
     break;
    case NODE_RMAL:
     printf("reading mail");
     break;
    case NODE_RSML:
     printf("reading sent mail");
     break;
    case NODE_RTXT:
     printf("reading text files");
     break;
    case NODE_PMSG:
     printf("posting message");
     break;
    case NODE_SMAL:
     printf("sending mail");
     break;
    case NODE_AMSG:
     printf("posting auto-message");
     break;
    case NODE_XTRN:
     if(!node.aux)
      printf("at external program menu");
     else
      printf("running external program #%d",node.aux);
     break;
    case NODE_DFLT:
     printf("changing defaults");
     break;
    case NODE_XFER:
     printf("at transfer menu");
     break;
    case NODE_RFSD:
     printf("retrieving from device #%d",node.aux);
     break;
    case NODE_DLNG:
     printf("downloading");
     break;
    case NODE_ULNG:
     printf("uploading");
     break;
    case NODE_BXFR:
     printf("transferring bidirectional");
     break;
    case NODE_LFIL:
     printf("listing files");
     break;
    case NODE_LOGN:
     printf("logging on");
     break;
    case NODE_LCHT:
     printf("in local chat with sysop");
     break;
    case NODE_MCHT:
     if(node.aux) {
      printf("in multinode chat channel %d",node.aux&0xff);
      if(node.aux&0x1f00) {
       putchar('*');
       printf(" %s",unpackchatpass(tmp,node)); } }
     else
      printf("in multinode global chat channel");
     break;
    case NODE_PAGE:
     printf("paging node %u for private chat",node.aux);
     break;
    case NODE_PCHT:
     printf("in private chat with node %u",node.aux);
     break;
    case NODE_GCHT:
     printf("chatting with The Guru");
     break;
    case NODE_CHAT:
     printf("in chat section");
     break;
    case NODE_TQWK:
     printf("transferring QWK packet");
     break;
    case NODE_SYSP:
     printf("performing sysop activities");
     break;
    default:
     printf(itoa(node.action,tmp,10));
     break; }
   if(!node.connection)
    printf(" locally");
   else if(node.connection==0xffff)
    printf(" via telnet");
   else
    printf(" at %ubps",node.connection);
   if(node.action==NODE_DLNG) {
    if((node.aux/60)>=12) {
     if(node.aux/60==12)
      hour=12;
     else
      hour=(node.aux/60)-12;
     strcpy(mer,"pm"); }
    else {
     if((node.aux/60)==0)
      hour=12;
     else hour=node.aux/60;
     strcpy(mer,"am"); }
    printf(" ETA %02d:%02d %s"
     ,hour,node.aux-((node.aux/60)*60),mer); }
   break; }
 if(node.misc&((1<<1)|(1<<4)|(1<<5)|(1<<3)|(1<<11))) {
  printf(" (");
  if(node.misc&(1<<5))
   putchar('A');
  if(node.misc&(1<<1))
   putchar('L');
  if(node.misc&((1<<3)|(1<<11)))
   putchar('M');
  if(node.misc&(1<<4))
   putchar('P');
  putchar(')'); }
 if(((node.misc
  &((1<<0)|(1<<6)|(1<<2)|(1<<7)|(1<<8)|(1<<9)))
  || node.status==NODE_QUIET)) {
  printf(" [");
  if(node.misc&(1<<0))
   putchar('A');
  if(node.misc&(1<<2))
   putchar('I');
  if(node.misc&(1<<7))
   putchar('R');
  if(node.misc&(1<<6))
   putchar('U');
  if(node.status==NODE_QUIET)
   putchar('Q');
  if(node.misc&(1<<8))
   putchar('E');
  if(node.misc&(1<<9))
   putchar('D');
  if(node.misc&(1<<13))
   putchar('C');
  putchar(']'); }
 if(node.errors)
  printf(" %d error%c",node.errors, node.errors>1 ? 's' : '\0' );
 printf("\n");
}

canonical_original_code:
void printnodedat(int number, struct node_t node)
{
    char hour; char mer[3];
 printf("Node %2d: ",number);
 switch(node.status) {
  case NODE_WFC:
   printf("Waiting for call");
   break;
  case NODE_OFFLINE:
   printf("Offline");
   break;
  case NODE_NETTING:
   printf("Networking");
   break;
  case NODE_LOGON:
   printf("At logon prompt");
   break;
  case NODE_EVENT_WAITING:
   printf("Waiting for all nodes to become inactive");
   break;
  case NODE_EVENT_LIMBO:
   printf("Waiting for node %d to finish external event",node.aux);
   break;
  case NODE_EVENT_RUNNING:
   printf("Running external event");
   break;
  case NODE_NEWUSER:
   printf("New user");
   printf(" applying for access ");
   if(!node.connection)
    printf("locally");
   else if(node.connection==0xffff)
    printf("via telnet");
   else
    printf("at %ubps",node.connection);
   break;
  case NODE_QUIET:
  case NODE_INUSE:
   printf("User #%d",node.useron);
   printf(" ");
   switch(node.action) {
    case NODE_MAIN:
     printf("at main menu");
     break;
    case NODE_RMSG:
     printf("reading messages");
     break;
    case NODE_RMAL:
     printf("reading mail");
     break;
    case NODE_RSML:
     printf("reading sent mail");
     break;
    case NODE_RTXT:
     printf("reading text files");
     break;
    case NODE_PMSG:
     printf("posting message");
     break;
    case NODE_SMAL:
     printf("sending mail");
     break;
    case NODE_AMSG:
     printf("posting auto-message");
     break;
    case NODE_XTRN:
     if(!node.aux)
      printf("at external program menu");
     else
      printf("running external program #%d",node.aux);
     break;
    case NODE_DFLT:
     printf("changing defaults");
     break;
    case NODE_XFER:
     printf("at transfer menu");
     break;
    case NODE_RFSD:
     printf("retrieving from device #%d",node.aux);
     break;
    case NODE_DLNG:
     printf("downloading");
     break;
    case NODE_ULNG:
     printf("uploading");
     break;
    case NODE_BXFR:
     printf("transferring bidirectional");
     break;
    case NODE_LFIL:
     printf("listing files");
     break;
    case NODE_LOGN:
     printf("logging on");
     break;
    case NODE_LCHT:
     printf("in local chat with sysop");
     break;
    case NODE_MCHT:
     if(node.aux) {
      printf("in multinode chat channel %d",node.aux&0xff);
      if(node.aux&0x1f00) {
       putchar('*');
       printf(" %s",unpackchatpass(tmp,node)); } }
     else
      printf("in multinode global chat channel");
     break;
    case NODE_PAGE:
     printf("paging node %u for private chat",node.aux);
     break;
    case NODE_PCHT:
     printf("in private chat with node %u",node.aux);
     break;
    case NODE_GCHT:
     printf("chatting with The Guru");
     break;
    case NODE_CHAT:
     printf("in chat section");
     break;
    case NODE_TQWK:
     printf("transferring QWK packet");
     break;
    case NODE_SYSP:
     printf("performing sysop activities");
     break;
    default:
     printf(itoa(node.action,tmp,10));
     break; }
   if(!node.connection)
    printf(" locally");
   else if(node.connection==0xffff)
    printf(" via telnet");
   else
    printf(" at %ubps",node.connection);
   if(node.action==NODE_DLNG) {
    if((node.aux/60)>=12) {
     if(node.aux/60==12)
      hour=12;
     else
      hour=(node.aux/60)-12;
     strcpy(mer,"pm"); }
    else {
     if((node.aux/60)==0)
      hour=12;
     else hour=node.aux/60;
     strcpy(mer,"am"); }
    printf(" ETA %02d:%02d %s"
     ,hour,node.aux-((node.aux/60)*60),mer); }
   break; }
 if(node.misc&((1<<1)|(1<<4)|(1<<5)|(1<<3)|(1<<11))) {
  printf(" (");
  if(node.misc&(1<<5))
   putchar('A');
  if(node.misc&(1<<1))
   putchar('L');
  if(node.misc&((1<<3)|(1<<11)))
   putchar('M');
  if(node.misc&(1<<4))
   putchar('P');
  putchar(')'); }
 if(((node.misc
  &((1<<0)|(1<<6)|(1<<2)|(1<<7)|(1<<8)|(1<<9)))
  || node.status==NODE_QUIET)) {
  printf(" [");
  if(node.misc&(1<<0))
   putchar('A');
  if(node.misc&(1<<2))
   putchar('I');
  if(node.misc&(1<<7))
   putchar('R');
  if(node.misc&(1<<6))
   putchar('U');
  if(node.status==NODE_QUIET)
   putchar('Q');
  if(node.misc&(1<<8))
   putchar('E');
  if(node.misc&(1<<9))
   putchar('D');
  if(node.misc&(1<<13))
   putchar('C');
  putchar(']'); }
 if(node.errors)
  printf(" %d error%c",node.errors, node.errors>1 ? 's' : '\0' );
 printf("\n");
}

variable_types: hour char

variable_types:
mer
char [3]

user_defined_types: struct node_t { unsigned char status; unsigned short useron; unsigned long extaux; }