tabLineCreator

decompiled_code:
const char *__fastcall tabLineCreator(const char **a1)
{
const char *v1; // r14
__int64 v2; // rbp
char *v3; // rbx
size_t i; // rsi
size_t v5; // rax
char *v6; // rax
char *v7; // rbx
size_t v8; // r8
char *v9; // rax
const char *v10; // rax
const char *v11; // r12

if ( !a1 )
return 0LL;
v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
v3 = 0LL;
for ( i = 2 * strlen(*a1); ; i = v9 - v11 + 2 * v8 )
{
v10 = (const char *)realloc(v3, i);
v11 = v10;
if ( !v10 )
break;
if ( v2 )
*(_WORD *)&v10[strlen(v10)] = 9;
else
*v10 = 0;
++v2;
v5 = strlen(v11);
v6 = stpcpy((char *)&v11[v5], v1);
v1 = a1[v2];
v7 = v6;
if ( !v1 )
return v11;
v8 = strlen(a1[v2]);
v9 = v7;
v3 = (char *)v11;
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func3(const char **a1)
{
const char *v1; // r14
__int64 v2; // rbp
char *v3; // rbx
size_t i; // rsi
size_t v5; // rax
char *v6; // rax
char *v7; // rbx
size_t v8; // r8
char *v9; // rax
const char *v10; // rax
const char *v11; // r12

if ( !a1 )
return 0LL;
v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
v3 = 0LL;
for ( i = 2 * strlen(*a1); ; i = v9 - v11 + 2 * v8 )
{
v10 = (const char *)realloc(v3, i);
v11 = v10;
if ( !v10 )
break;
if ( v2 )
*(_WORD *)&v10[strlen(v10)] = 9;
else
*v10 = 0;
++v2;
v5 = strlen(v11);
v6 = stpcpy((char *)&v11[v5], v1);
v1 = a1[v2];
v7 = v6;
if ( !v1 )
return v11;
v8 = strlen(a1[v2]);
v9 = v7;
v3 = (char *)v11;
}
return v3;
}

original_code:
char* tabLineCreator(const str_list_t columns)
{
 char* str=((void *)0);
 char* p;
 size_t i,len;
 if(columns==((void *)0))
  return(((void *)0));
 for(i=0;columns[i]!=((void *)0);i++) {
  len=strlen(columns[i])*2;
  if(str)
   len+=strlen(str);
  if((p=realloc(str,len))==((void *)0))
   break;
  str=p;
  if(i) strcat(str,"\t");
  else *str=0;
  strcat(str,columns[i]);
 }
 return(str);
}

canonical_original_code:
char *tabLineCreator(char **columns)
{
 char *str = ((void *)0);
 char *p;
 unsigned long i; unsigned long len;
 if(columns==((void *)0))
  return(((void *)0));
 for(i=0;columns[i]!=((void *)0);i++) {
  len=strlen(columns[i])*2;
  if(str)
   len+=strlen(str);
  if((p=realloc(str,len))==((void *)0))
   break;
  str=p;
  if(i) strcat(str,"\t");
  else *str=0;
  strcat(str,columns[i]);
 }
 return(str);
}

variable_types:
str
char *


tabLineParser

repo: ftnapps/pkg-sbbs

decompiled_code:
char *__fastcall tabLineParser(char *s)
{
char *v1; // r12
char *v2; // rax
char *v3; // rsi
__int64 v4; // rbx
__int64 v5; // rdx
char *v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v8[0] = strListInit();
v1 = (char *)v8[0];
if ( v8[0] )
{
v2 = strdup(s);
v1 = v2;
if ( v2 )
{
v3 = strtok_r(v2, "\t", &v7);
if ( v3 )
{
v4 = 0LL;
do
{
v5 = v4++;
strListAppend(v8, v3, v5);
v3 = strtok_r(0LL, "\t", &v7);
}
while ( v3 );
}
free(v1);
v1 = (char *)v8[0];
}
else
{
strListFree(v8);
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func4(char *s)
{
char *v1; // r12
char *v2; // rax
char *v3; // rsi
__int64 v4; // rbx
__int64 v5; // rdx
char *v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v8[0] = strListInit();
v1 = (char *)v8[0];
if ( v8[0] )
{
v2 = strdup(s);
v1 = v2;
if ( v2 )
{
v3 = strtok_r(v2, "\t", &v7);
if ( v3 )
{
v4 = 0LL;
do
{
v5 = v4++;
strListAppend(v8, v3, v5);
v3 = strtok_r(0LL, "\t", &v7);
}
while ( v3 );
}
free(v1);
v1 = (char *)v8[0];
}
else
{
strListFree(v8);
}
}
return v1;
}

original_code:
str_list_t tabLineParser(const char* line)
{
 char* p;
 char* buf;
 char* tmp;
 size_t count=0;
 str_list_t list;
 if((list=strListInit())==((void *)0))
  return(((void *)0));
 if((buf=strdup(line))==((void *)0)) {
  strListFree(&list);
  return(((void *)0));
 }
 for(p=strtok_r(buf,"\t",&tmp);p;p=strtok_r(((void *)0),"\t",&tmp))
  strListAppend(&list,p,count++);
 free(buf);
 return(list);
}

canonical_original_code:
char **tabLineParser(char *line)
{
 char *p;
 char *buf;
 char *tmp;
 unsigned long count = 0;
 char **list;
 if((list=strListInit())==((void *)0))
  return(((void *)0));
 if((buf=strdup(line))==((void *)0)) {
  strListFree(&list);
  return(((void *)0));
 }
 for(p=strtok_r(buf,"\t",&tmp);p;p=strtok_r(((void *)0),"\t",&tmp))
  strListAppend(&list,p,count++);
 free(buf);
 return(list);
}

variable_types:
line
char *

variable_types:
p
char *

variable_types:
buf
char *

variable_types:
tmp
char *

variable_types:
count
unsigned long

variable_types:
list
char **

return_type: char **


dataCreateList

decompiled_code:
__int64 __fastcall dataCreateList(_QWORD *a1, __int64 a2, __int64 (*a3)(void))
{
__int64 result; // rax
__int64 v5; // rbx
void *v6; // rsi
_QWORD *v7; // r14
__int64 v8; // rax
__int64 v9; // rdx
void *v10; // rbp
__int64 v11[6]; // [rsp+8h] [rbp-30h] BYREF

result = strListInit();
v11[0] = result;
if ( result )
{
v5 = 0LL;
if ( a2 )
{
v5 = 1LL;
v6 = (void *)((__int64 (__fastcall *)(__int64))a3)(a2);
strListAppend(v11, v6, 0LL);
free(v6);
}
if ( a1 && *a1 )
{
v7 = &a1[-v5];
do
{
v8 = a3();
v9 = v5++;
v10 = (void *)v8;
strListAppend(v11, v8, v9);
free(v10);
}
while ( v7[v5] );
}
result = v11[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, __int64 (*a3)(void))
{
__int64 result; // rax
__int64 v5; // rbx
void *v6; // rsi
_QWORD *v7; // r14
__int64 v8; // rax
__int64 v9; // rdx
void *v10; // rbp
__int64 v11[6]; // [rsp+8h] [rbp-30h] BYREF

result = strListInit();
v11[0] = result;
if ( result )
{
v5 = 0LL;
if ( a2 )
{
v5 = 1LL;
v6 = (void *)((__int64 (__fastcall *)(__int64))a3)(a2);
strListAppend(v11, v6, 0LL);
free(v6);
}
if ( a1 && *a1 )
{
v7 = &a1[-v5];
do
{
v8 = a3();
v9 = v5++;
v10 = (void *)v8;
strListAppend(v11, v8, v9);
free(v10);
}
while ( v7[v5] );
}
result = v11[0];
}
return result;
}

original_code:
str_list_t dataCreateList(const str_list_t records[], const str_list_t columns, dataLineCreator_t lineCreator)
{
 char* p;
 str_list_t list;
 size_t i;
 size_t li=0;
 if((list=strListInit())==((void *)0))
  return(((void *)0));
 if(columns!=((void *)0)) {
  p=lineCreator(columns);
  strListAppend(&list,p,li++);
  free(p);
 }
 if(records!=((void *)0))
  for(i=0;records[i]!=((void *)0);i++) {
   p=lineCreator(records[i]);
   strListAppend(&list,p,li++);
   free(p);
  }
 return(list);
}

canonical_original_code:
char **dataCreateList(char **records[], char **columns, char *(*lineCreator)(char **))
{
 char *p;
 char **list;
 unsigned long i;
 unsigned long li = 0;
 if((list=strListInit())==((void *)0))
  return(((void *)0));
 if(columns!=((void *)0)) {
  p=lineCreator(columns);
  strListAppend(&list,p,li++);
  free(p);
 }
 if(records!=((void *)0))
  for(i=0;records[i]!=((void *)0);i++) {
   p=lineCreator(records[i]);
   strListAppend(&list,p,li++);
   free(p);
  }
 return(list);
}

variable_types:
records
char **[]

variable_types:
columns
char **

variable_types:
lineCreator
char *(*)(char **)

variable_types:
i
unsigned long

variable_types:
li
unsigned long


original_code:
size_t dns_name(unsigned char* name, size_t* namelen, size_t maxlen, unsigned char* srcbuf, unsigned char* p)
{
 size_t len=0;
 size_t plen;
 ushort offset;
 while(p && *p && (*namelen)<maxlen) {
  if(len)
   name[(*namelen)++]='.';
  if(((*p)&0xC0)==0xC0) {
   (*p)&=~0xC0;
   offset=ntohs(*(ushort*)p);
   (*p)|=0xC0;
   dns_name(name, namelen, maxlen, srcbuf, srcbuf+offset);
   return(len+2);
  }
  plen=(*p);
  if((*namelen)+plen>maxlen)
   break;
  memcpy(name+(*namelen),p+1,plen);
  (*namelen)+=plen;
  plen++;
  p+=plen;
  len+=plen;
 }
 name[(*namelen)++]=0;
 return(len+1);
}

canonical_original_code:
unsigned long dns_name(unsigned char *name, unsigned long *namelen, unsigned long maxlen, unsigned char *srcbuf, unsigned char *p)
{
 unsigned long len = 0;
 unsigned long plen;
 unsigned short offset;
 while(p && *p && (*namelen)<maxlen) {
  if(len)
   name[(*namelen)++]='.';
  if(((*p)&0xC0)==0xC0) {
   (*p)&=~0xC0;
   offset=ntohs(*(unsigned short *)p);
   (*p)|=0xC0;
   dns_name(name, namelen, maxlen, srcbuf, srcbuf+offset);
   return(len+2);
  }
  plen=(*p);
  if((*namelen)+plen>maxlen)
   break;
  memcpy(name+(*namelen),p+1,plen);
  (*namelen)+=plen;
  plen++;
  p+=plen;
  len+=plen;
 }
 name[(*namelen)++]=0;
 return(len+1);
}

variable_types:
name
unsigned char *

variable_types:
namelen
unsigned long *

variable_types:
maxlen
unsigned long

variable_types:
srcbuf
unsigned char *

variable_types:
p
unsigned char *

variable_types:
len
unsigned long

variable_types:
plen
unsigned long

variable_types:
offset
unsigned short

return_type: unsigned long


decompiled_code:
__int64 __fastcall dns_getmx(const char *a1, char *a2, char *a3, unsigned int a4, int a5, int a6, int a7)
{
int v9; // ebp
int v10; // eax
socklen_t v11; // edx
socklen_t v12; // edx
unsigned int v13; // er13
__int16 v14; // ax
int v15; // eax
int v16; // er15
unsigned __int16 v17; // ax
char v18; // al
unsigned int v19; // edx
char *v20; // r12
int v21; // er13
unsigned int v22; // er15
size_t v23; // rbx
__int64 v24; // rax
int v25; // er13
size_t v26; // rdx
int v27; // ebx
const char *v28; // r14
char *v29; // rax
__int64 v31; // rcx
int v32; // edx
__int64 v33; // rax
int v34; // ebx
int v35; // er14
int v36; // eax
int v37; // eax
_QWORD *v38; // rdx
unsigned __int64 v39; // rsi
char *v40; // rdx
char *v41; // r8
unsigned int v42; // eax
unsigned int v43; // edx
__int64 v44; // rcx
unsigned __int16 v45; // ax
int v46; // ecx
int v47; // er12
unsigned __int8 *v48; // rbp
char *v49; // rbx
int v50; // er14
__int64 v51; // rax
__int16 *v52; // rdx
__int16 v53; // ax
__int64 v54; // rdx
__int64 v55; // rcx
__int64 v56; // rbp
__int16 v57; // ax
unsigned __int16 v58; // r15
unsigned __int64 v59; // rdx
__int64 v60; // rcx
unsigned __int8 *v61; // r8
unsigned __int16 v63; // [rsp+Ch] [rbp-3B4h]
int v66; // [rsp+20h] [rbp-3A0h]
__int64 v67; // [rsp+20h] [rbp-3A0h]
int v68; // [rsp+20h] [rbp-3A0h]
size_t v69; // [rsp+50h] [rbp-370h] BYREF
__int64 v70; // [rsp+5Ah] [rbp-366h] BYREF
int v71; // [rsp+62h] [rbp-35Eh]
__int16 v72; // [rsp+66h] [rbp-35Ah]
struct sockaddr v73; // [rsp+68h] [rbp-358h] BYREF
struct timeval timeout; // [rsp+78h] [rbp-348h] BYREF
char src[128]; // [rsp+88h] [rbp-338h] BYREF
fd_set writefds; // [rsp+108h] [rbp-2B8h] BYREF
__int64 buf; // [rsp+188h] [rbp-238h] BYREF
int v78; // [rsp+190h] [rbp-230h]
__int16 v79; // [rsp+194h] [rbp-22Ch]

*a2 = 0;
*a3 = 0;
v73 = 0LL;
if ( a6 )
v9 = mail_open_socket(1LL, &unk_78C);
else
v9 = mail_open_socket(2LL, &unk_78C);
if ( v9 != -1 )
{
v10 = _bswap_32(a4);
*(_DWORD *)&v73.sa_family = 2;
*(_DWORD *)&v73.sa_data[2] = v10;
if ( !bind(v9, &v73, v11) )
{
*(_DWORD *)&v73.sa_data[2] = a5;
v73.sa_family = 2;
*(_QWORD *)&v73.sa_data[6] = 0LL;
*(_WORD *)v73.sa_data = _bswap_16(53);
v13 = connect(v9, &v73, v12);
if ( !v13 )
{
v71 = 0;
v72 = 0;
v14 = strlen(a1);
LODWORD(v70) = (unsigned __int16)_bswap_16(v14 + 18);
WORD2(v70) = _bswap_16(256);
LOWORD(v15) = _bswap_16(1);
v16 = v15;
HIWORD(v70) = v15;
v17 = _bswap_16(15);
v78 = 0;
v79 = 0;
v66 = (v16 << 16) | v17;
buf = v70;
v18 = *a1;
if ( *a1 )
{
v19 = v13;
v20 = (char *)a1;
v21 = 14;
v22 = v19;
do
{
v28 = &v20[v18 == 46];
v29 = strchr(v28, 46);
v20 = v29;
if ( v29 )
{
v23 = v29 - v28;
}
else
{
v23 = strlen(v28);
v20 = (char *)&v28[v23];
}
v24 = v21;
v25 = v21 + 1;
v26 = v23;
v69 = v23;
*((_BYTE *)&buf + v24) = v23;
v27 = v25 + v23;
memcpy((char *)&buf + v25, v28, v26);
v18 = *v20;
v21 = v27;
}
while ( *v20 );
v31 = v27;
v32 = v27;
v13 = v22;
v33 = v27 + 1;
v34 = v27 + 5;
}
else
{
v34 = 19;
v32 = 14;
v33 = 15LL;
v31 = 14LL;
}
*((_BYTE *)&buf + v31) = 0;
v35 = 0;
*(_DWORD *)((char *)&buf + v33) = v66;
if ( !a6 )
{
v35 = 2;
v34 = v32 + 3;
}
timeout.tv_usec = 0LL;
timeout.tv_sec = a7;
memset(&writefds, 0, sizeof(writefds));
v67 = v9 / 64;
writefds.fds_bits[v67] |= 1LL << (v9 % 64);
v36 = select(v9 + 1, 0LL, &writefds, 0LL, &timeout);
if ( v36 > 0 )
{
v37 = send(v9, (char *)&buf + v35, v34, 0);
if ( v34 != v37 )
{
v13 = -2;
if ( v37 != -1 )
{
LABEL_22:
mail_close_socket((unsigned int)v9);
return v13;
}
LABEL_25:
v13 = *_errno_location();
goto LABEL_22;
}
timeout.tv_usec = 0LL;
timeout.tv_sec = a7;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v67] |= 1LL << (v9 % 64);
v36 = select(v9 + 1, &writefds, 0LL, 0LL, &timeout);
if ( v36 > 0 )
{
if ( (int)recv(v9, &buf, 0x200uLL, 0) > 0 )
{
v38 = (__int64 *)((char *)&v70 + v35);
*v38 = buf;
*(_QWORD *)((char *)v38 + (unsigned int)(14 - v35) - 8) = *(__int64 *)((char *)&buf
+ (unsigned int)(14 - v35)
- 8);
v39 = (unsigned __int64)(v38 + 1) & 0xFFFFFFFFFFFFFFF8LL;
v40 = (char *)v38 - v39;
v41 = (char *)((char *)&buf - v40);
if ( (((_DWORD)v40 + 14 - v35) & 0xFFFFFFF8) >= 8 )
{
v42 = ((_DWORD)v40 + 14 - v35) & 0xFFFFFFF8;
v43 = 0;
do
{
v44 = v43;
v43 += 8;
*(_QWORD *)(v39 + v44) = *(_QWORD *)&v41[v44];
}
while ( v43 < v42 );
}
v45 = _bswap_16(v71);
v47 = v45;
if ( v45 )
{
v68 = v9;
v48 = (unsigned __int8 *)&buf + v34;
v49 = (char *)&buf + v46;
v63 = -1;
v50 = 0;
do
{
v69 = 0LL;
v51 = dns_name((__int64)src, &v69, 0x7FuLL, (__int64)v49, v48);
_bswap_16(*(_WORD *)&v48[v51 + 12]);
v53 = _bswap_16(*v52);
v48 = (unsigned __int8 *)(v54 + v55 + 14);
if ( v53 == 15 )
{
v56 = v54 + 16;
v57 = _bswap_16(*(_WORD *)(v54 + 14));
v69 = 0LL;
v58 = v57;
v48 = (unsigned __int8 *)(dns_name((__int64)src, &v69, v59, v60, v61) + v56);
if ( v58 > v63 )
{
if ( !*a3 )
strcpy(a3, src);
}
else
{
if ( *a2 )
strcpy(a3, a2);
strcpy(a2, src);
v63 = v58;
}
}
++v50;
}
while ( v47 != v50 );
v9 = v68;
}
}
if ( !*a2 )
strcpy(a2, a1);
goto LABEL_22;
}
}
v13 = -1;
if ( v36 != -1 )
goto LABEL_22;
goto LABEL_25;
}
}
mail_close_socket((unsigned int)v9);
}
return (unsigned int)*_errno_location();
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, char *a2, char *a3, unsigned int a4, int a5, int a6, int a7)
{
int v9; // ebp
int v10; // eax
socklen_t v11; // edx
socklen_t v12; // edx
unsigned int v13; // er13
__int16 v14; // ax
int v15; // eax
int v16; // er15
unsigned __int16 v17; // ax
char v18; // al
unsigned int v19; // edx
char *v20; // r12
int v21; // er13
unsigned int v22; // er15
size_t v23; // rbx
__int64 v24; // rax
int v25; // er13
size_t v26; // rdx
int v27; // ebx
const char *v28; // r14
char *v29; // rax
__int64 v31; // rcx
int v32; // edx
__int64 v33; // rax
int v34; // ebx
int v35; // er14
int v36; // eax
int v37; // eax
_QWORD *v38; // rdx
unsigned __int64 v39; // rsi
char *v40; // rdx
char *v41; // r8
unsigned int v42; // eax
unsigned int v43; // edx
__int64 v44; // rcx
unsigned __int16 v45; // ax
int v46; // ecx
int v47; // er12
unsigned __int8 *v48; // rbp
char *v49; // rbx
int v50; // er14
__int64 v51; // rax
__int16 *v52; // rdx
__int16 v53; // ax
__int64 v54; // rdx
__int64 v55; // rcx
__int64 v56; // rbp
__int16 v57; // ax
unsigned __int16 v58; // r15
unsigned __int64 v59; // rdx
__int64 v60; // rcx
unsigned __int8 *v61; // r8
unsigned __int16 v63; // [rsp+Ch] [rbp-3B4h]
int v66; // [rsp+20h] [rbp-3A0h]
__int64 v67; // [rsp+20h] [rbp-3A0h]
int v68; // [rsp+20h] [rbp-3A0h]
size_t v69; // [rsp+50h] [rbp-370h] BYREF
__int64 v70; // [rsp+5Ah] [rbp-366h] BYREF
int v71; // [rsp+62h] [rbp-35Eh]
__int16 v72; // [rsp+66h] [rbp-35Ah]
struct sockaddr v73; // [rsp+68h] [rbp-358h] BYREF
struct timeval timeout; // [rsp+78h] [rbp-348h] BYREF
char src[128]; // [rsp+88h] [rbp-338h] BYREF
fd_set writefds; // [rsp+108h] [rbp-2B8h] BYREF
__int64 buf; // [rsp+188h] [rbp-238h] BYREF
int v78; // [rsp+190h] [rbp-230h]
__int16 v79; // [rsp+194h] [rbp-22Ch]

*a2 = 0;
*a3 = 0;
v73 = 0LL;
if ( a6 )
v9 = mail_open_socket(1LL, &unk_78C);
else
v9 = mail_open_socket(2LL, &unk_78C);
if ( v9 != -1 )
{
v10 = func1(a4);
*(_DWORD *)&v73.sa_family = 2;
*(_DWORD *)&v73.sa_data[2] = v10;
if ( !bind(v9, &v73, v11) )
{
*(_DWORD *)&v73.sa_data[2] = a5;
v73.sa_family = 2;
*(_QWORD *)&v73.sa_data[6] = 0LL;
*(_WORD *)v73.sa_data = func0(53);
v13 = connect(v9, &v73, v12);
if ( !v13 )
{
v71 = 0;
v72 = 0;
v14 = strlen(a1);
LODWORD(v70) = (unsigned __int16)func0(v14 + 18);
WORD2(v70) = func0(256);
LOWORD(v15) = func0(1);
v16 = v15;
HIWORD(v70) = v15;
v17 = func0(15);
v78 = 0;
v79 = 0;
v66 = (v16 << 16) | v17;
buf = v70;
v18 = *a1;
if ( *a1 )
{
v19 = v13;
v20 = (char *)a1;
v21 = 14;
v22 = v19;
do
{
v28 = &v20[v18 == 46];
v29 = strchr(v28, 46);
v20 = v29;
if ( v29 )
{
v23 = v29 - v28;
}
else
{
v23 = strlen(v28);
v20 = (char *)&v28[v23];
}
v24 = v21;
v25 = v21 + 1;
v26 = v23;
v69 = v23;
*((_BYTE *)&buf + v24) = v23;
v27 = v25 + v23;
memcpy((char *)&buf + v25, v28, v26);
v18 = *v20;
v21 = v27;
}
while ( *v20 );
v31 = v27;
v32 = v27;
v13 = v22;
v33 = v27 + 1;
v34 = v27 + 5;
}
else
{
v34 = 19;
v32 = 14;
v33 = 15LL;
v31 = 14LL;
}
*((_BYTE *)&buf + v31) = 0;
v35 = 0;
*(_DWORD *)((char *)&buf + v33) = v66;
if ( !a6 )
{
v35 = 2;
v34 = v32 + 3;
}
timeout.tv_usec = 0LL;
timeout.tv_sec = a7;
memset(&writefds, 0, sizeof(writefds));
v67 = v9 / 64;
writefds.fds_bits[v67] |= 1LL << (v9 % 64);
v36 = select(v9 + 1, 0LL, &writefds, 0LL, &timeout);
if ( v36 > 0 )
{
v37 = send(v9, (char *)&buf + v35, v34, 0);
if ( v34 != v37 )
{
v13 = -2;
if ( v37 != -1 )
{
LABEL_22:
mail_close_socket((unsigned int)v9);
return v13;
}
LABEL_25:
v13 = *_errno_location();
goto LABEL_22;
}
timeout.tv_usec = 0LL;
timeout.tv_sec = a7;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v67] |= 1LL << (v9 % 64);
v36 = select(v9 + 1, &writefds, 0LL, 0LL, &timeout);
if ( v36 > 0 )
{
if ( (int)recv(v9, &buf, 0x200uLL, 0) > 0 )
{
v38 = (__int64 *)((char *)&v70 + v35);
*v38 = buf;
*(_QWORD *)((char *)v38 + (unsigned int)(14 - v35) - 8) = *(__int64 *)((char *)&buf
+ (unsigned int)(14 - v35)
- 8);
v39 = (unsigned __int64)(v38 + 1) & 0xFFFFFFFFFFFFFFF8LL;
v40 = (char *)v38 - v39;
v41 = (char *)((char *)&buf - v40);
if ( (((_DWORD)v40 + 14 - v35) & 0xFFFFFFF8) >= 8 )
{
v42 = ((_DWORD)v40 + 14 - v35) & 0xFFFFFFF8;
v43 = 0;
do
{
v44 = v43;
v43 += 8;
*(_QWORD *)(v39 + v44) = *(_QWORD *)&v41[v44];
}
while ( v43 < v42 );
}
v45 = func0(v71);
v47 = v45;
if ( v45 )
{
v68 = v9;
v48 = (unsigned __int8 *)&buf + v34;
v49 = (char *)&buf + v46;
v63 = -1;
v50 = 0;
do
{
v69 = 0LL;
v51 = func2((__int64)src, &v69, 0x7FuLL, (__int64)v49, v48);
func0(*(_WORD *)&v48[v51 + 12]);
v53 = func0(*v52);
v48 = (unsigned __int8 *)(v54 + v55 + 14);
if ( v53 == 15 )
{
v56 = v54 + 16;
v57 = func0(*(_WORD *)(v54 + 14));
v69 = 0LL;
v58 = v57;
v48 = (unsigned __int8 *)(func2((__int64)src, &v69, v59, v60, v61) + v56);
if ( v58 > v63 )
{
if ( !*a3 )
strcpy(a3, src);
}
else
{
if ( *a2 )
strcpy(a3, a2);
strcpy(a2, src);
v63 = v58;
}
}
++v50;
}
while ( v47 != v50 );
v9 = v68;
}
}
if ( !*a2 )
strcpy(a2, a1);
goto LABEL_22;
}
}
v13 = -1;
if ( v36 != -1 )
goto LABEL_22;
goto LABEL_25;
}
}
mail_close_socket((unsigned int)v9);
}
return (unsigned int)*_errno_location();
}

original_code:
int dns_getmx(char* name, char* mx, char* mx2
     ,ulong intf, ulong ip_addr, int use_tcp, int timeout)
{
 unsigned char* p;
 unsigned char* tp;
 char hostname[128];
 size_t namelen;
 ushort pref;
 ushort highpref=0xffff;
 int i;
 int rd;
 int len;
 int offset;
 int result;
 int answers;
 int sock;
 struct sockaddr_in addr={0};
 unsigned char msg[512];
 dns_msghdr_t msghdr;
 dns_query_t query;
 dns_rr_t* rr;
 struct timeval tv;
 fd_set socket_set;
 mx[0]=0;
 mx2[0]=0;
 if(use_tcp)
  sock = mail_open_socket(SOCK_STREAM,"dns");
 else
  sock = mail_open_socket(SOCK_DGRAM,"dns");
 if(sock == (int)(~0))
  return((*__errno_location ()));
 addr.sin_addr.s_addr = htonl(intf);
    addr.sin_family = 2;
    addr.sin_port = 0;
    result = bind(sock,(struct sockaddr *)&addr, sizeof(addr));
 if(result != 0) {
  mail_close_socket(sock);
  return((*__errno_location ()));
 }
 memset(&addr,0,sizeof(addr));
 addr.sin_addr.s_addr = ip_addr;
 addr.sin_family = 2;
 addr.sin_port = htons(53);
 if((result=connect(sock, (struct sockaddr *)&addr, sizeof(addr)))!=0) {
  mail_close_socket(sock);
  return((*__errno_location ()));
 }
 memset(&msghdr,0,sizeof(msghdr));
 len=sizeof(msghdr)+strlen(name)+sizeof(query);
 msghdr.length=htons((ushort)len);
 msghdr.bitfields=htons((1<<8));
 msghdr.qdcount=htons(1);
 query.type=htons(DNS_MX);
 query.class=htons(1);
 memcpy(msg,&msghdr,sizeof(msghdr));
 len=sizeof(msghdr);
 for(p=name;*p;p+=namelen) {
  if(*p=='.')
   p++;
  tp=strchr(p,'.');
  if(tp)
   namelen=tp-p;
  else
   namelen=strlen(p);
  *(msg+len)=(unsigned char)namelen;
  len++;
  memcpy(msg+len,p,namelen);
  len+=namelen;
 }
 *(msg+len)=0;
 len++;
 memcpy(msg+len,&query,sizeof(query));
 len+=sizeof(query);
 if(use_tcp)
  offset=0;
 else {
  offset=sizeof(msghdr.length);
  len-=sizeof(msghdr.length);
 }
 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)))))));
 i=select(sock+1,((void *)0),&socket_set,((void *)0),&tv);
 if(i<1) {
  if(i==-1)
   result=(*__errno_location ());
  else
   result=-1;
  mail_close_socket(sock);
  return(result);
 }
 i=send(sock,msg+offset,len,0);
 if(i!=len) {
  if(i==-1)
   result=(*__errno_location ());
  else
   result=-2;
  mail_close_socket(sock);
  return(result);
 }
 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)))))));
 i=select(sock+1,&socket_set,((void *)0),((void *)0),&tv);
 if(i<1) {
  if(i==-1)
   result=(*__errno_location ());
  else
   result=-1;
  mail_close_socket(sock);
  return(result);
 }
 rd=recv(sock,msg,sizeof(msg),0);
 if(rd>0) {
  memcpy(((unsigned char*)(&msghdr))+offset,msg,sizeof(msghdr)-offset);
  if(!use_tcp)
   offset=0;
  else
   offset=sizeof(msghdr.length);
  answers=ntohs(msghdr.ancount);
  p=msg+len;
  for(i=0;i<answers;i++) {
   namelen=0;
   p+=dns_name(hostname, &namelen, sizeof(hostname)-1, msg+offset, p);
   rr=(dns_rr_t*)p;
   p+=sizeof(dns_rr_t);
   len=ntohs(rr->length);
   if(ntohs(rr->type)==DNS_MX) {
    pref=ntohs(*(ushort*)p);
    p+=2;
    namelen=0;
    p+=dns_name(hostname, &namelen, sizeof(hostname)-1, msg+offset, p);
    if(pref<=highpref) {
     highpref=pref;
     if(mx[0])
      strcpy(mx2,mx);
     strcpy(mx,hostname);
    } else if(!mx2[0])
     strcpy(mx2,hostname);
   }
   else
    p+=len;
  }
 }
 if(!mx[0]) {
  strcpy(mx,name);
 }
 mail_close_socket(sock);
 return(0);
}

canonical_original_code:
int dns_getmx(char *name, char *mx, char *mx2, unsigned long intf, unsigned long ip_addr, int use_tcp, int timeout)
{
 unsigned char *p;
 unsigned char *tp;
 char hostname[128];
 unsigned long namelen;
 unsigned short pref;
 unsigned short highpref = 0xffff;
 int i;
 int rd;
 int len;
 int offset;
 int result;
 int answers;
 int sock;
 struct sockaddr_in addr = {0};
 unsigned char msg[512];
 struct dns_msghdr_t msghdr;
 struct dns_query_t query;
 struct dns_rr_t *rr;
 struct timeval tv;
 struct fd_set socket_set;
 mx[0]=0;
 mx2[0]=0;
 if(use_tcp)
  sock = mail_open_socket(SOCK_STREAM,"dns");
 else
  sock = mail_open_socket(SOCK_DGRAM,"dns");
 if(sock == (int)(~0))
  return((*__errno_location ()));
 addr.sin_addr.s_addr = htonl(intf);
    addr.sin_family = 2;
    addr.sin_port = 0;
    result = bind(sock,(struct sockaddr *)&addr, sizeof(addr));
 if(result != 0) {
  mail_close_socket(sock);
  return((*__errno_location ()));
 }
 memset(&addr,0,sizeof(addr));
 addr.sin_addr.s_addr = ip_addr;
 addr.sin_family = 2;
 addr.sin_port = htons(53);
 if((result=connect(sock, (struct sockaddr *)&addr, sizeof(addr)))!=0) {
  mail_close_socket(sock);
  return((*__errno_location ()));
 }
 memset(&msghdr,0,sizeof(msghdr));
 len=sizeof(msghdr)+strlen(name)+sizeof(query);
 msghdr.length=htons((unsigned short)len);
 msghdr.bitfields=htons((1<<8));
 msghdr.qdcount=htons(1);
 query.type=htons(DNS_MX);
 query.class=htons(1);
 memcpy(msg,&msghdr,sizeof(msghdr));
 len=sizeof(msghdr);
 for(p=name;*p;p+=namelen) {
  if(*p=='.')
   p++;
  tp=strchr(p,'.');
  if(tp)
   namelen=tp-p;
  else
   namelen=strlen(p);
  *(msg+len)=(unsigned char)namelen;
  len++;
  memcpy(msg+len,p,namelen);
  len+=namelen;
 }
 *(msg+len)=0;
 len++;
 memcpy(msg+len,&query,sizeof(query));
 len+=sizeof(query);
 if(use_tcp)
  offset=0;
 else {
  offset=sizeof(msghdr.length);
  len-=sizeof(msghdr.length);
 }
 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)))))));
 i=select(sock+1,((void *)0),&socket_set,((void *)0),&tv);
 if(i<1) {
  if(i==-1)
   result=(*__errno_location ());
  else
   result=-1;
  mail_close_socket(sock);
  return(result);
 }
 i=send(sock,msg+offset,len,0);
 if(i!=len) {
  if(i==-1)
   result=(*__errno_location ());
  else
   result=-2;
  mail_close_socket(sock);
  return(result);
 }
 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)))))));
 i=select(sock+1,&socket_set,((void *)0),((void *)0),&tv);
 if(i<1) {
  if(i==-1)
   result=(*__errno_location ());
  else
   result=-1;
  mail_close_socket(sock);
  return(result);
 }
 rd=recv(sock,msg,sizeof(msg),0);
 if(rd>0) {
  memcpy(((unsigned char *)(&msghdr))+offset,msg,sizeof(msghdr)-offset);
  if(!use_tcp)
   offset=0;
  else
   offset=sizeof(msghdr.length);
  answers=ntohs(msghdr.ancount);
  p=msg+len;
  for(i=0;i<answers;i++) {
   namelen=0;
   p+=dns_name(hostname, &namelen, sizeof(hostname)-1, msg+offset, p);
   rr=(struct dns_rr_t *)p;
   p+=sizeof(dns_rr_t);
   len=ntohs(rr->length);
   if(ntohs(rr->type)==DNS_MX) {
    pref=ntohs(*(unsigned short *)p);
    p+=2;
    namelen=0;
    p+=dns_name(hostname, &namelen, sizeof(hostname)-1, msg+offset, p);
    if(pref<=highpref) {
     highpref=pref;
     if(mx[0])
      strcpy(mx2,mx);
     strcpy(mx,hostname);
    } else if(!mx2[0])
     strcpy(mx2,hostname);
   }
   else
    p+=len;
  }
 }
 if(!mx[0]) {
  strcpy(mx,name);
 }
 mail_close_socket(sock);
 return(0);
}

variable_types:
name
char *

variable_types:
mx
char *

variable_types:
intf
unsigned long

variable_types: timeout int

variable_types:
tp
unsigned char *

variable_types:
hostname
char [128]

variable_types:
namelen
unsigned long

variable_types:
pref
unsigned short

variable_types:
highpref
unsigned short

variable_types: i int

variable_types: rd int

variable_types: len int

variable_types: offset int

variable_types: result int

variable_types: answers int

variable_types: sock int

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:
msg
unsigned char [512]

variable_types: struct dns_msghdr_t { unsigned short length; unsigned short id; unsigned short bitfields; unsigned short qdcount; unsigned short ancount; unsigned short nscount; unsigned short arcount; }

variable_types: struct dns_query_t { unsigned short type; unsigned short class; }

variable_types: struct dns_rr_t { unsigned short type; unsigned short class; unsigned long ttl; unsigned short length; } *

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

return_type: int

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


getkey

decompiled_code:
int __fastcall sbbs_t::getkey(sbbs_t *this, __int64 a2)
{
int result; // eax
__int64 v3; // rax
char v4; // al
char v5; // al
char v6; // al
char v7; // al
char v8; // al
char v9; // al
unsigned __int64 v10; // rdx
char v11; // al
const char *v13; // rax
__int64 v15; // [rsp+0h] [rbp-40h]
struct timeval timeout; // [rsp+10h] [rbp-30h] BYREF
int v17; // [rsp+28h] [rbp-18h]
char v18; // [rsp+2Dh] [rbp-13h]
unsigned __int8 v19; // [rsp+2Eh] [rbp-12h]
char v20; // [rsp+2Fh] [rbp-11h]
__int64 v21; // [rsp+30h] [rbp-10h]
char v22; // [rsp+3Fh] [rbp-1h]

v15 = a2;
v22 = 0;
v20 = sbbs_random(5LL);
v21 = 0LL;
if ( *((_QWORD *)this + 6413) && *((_BYTE *)this + 26098) == 1 )
{
v3 = *((_QWORD *)this + 6414);
BYTE1(v3) &= 0xF7u;
*((_QWORD *)this + 6414) = v3;
if ( ((*((_QWORD *)this + 6414) & 8LL) != 0 || *((_BYTE *)this + 51296) == 9) && (a2 & 0x200800) == 0 )
v15 = *((_QWORD *)this + 3362) & 0x20LL | a2;
*((_QWORD *)this + 6065) = 0LL;
*((_QWORD *)this + 6054) = time(0LL);
if ( (v15 & 0x20) != 0 )
sbbs_t::outchar(this, 32);
while ( (*((_QWORD *)this + 6414) & 0x800LL) == 0 )
{
if ( (v15 & 0x20) != 0 )
{
if ( (*((_QWORD *)this + 3362) & 0x8000LL) != 0 )
{
v4 = v22++;
if ( v4 == 3 )
{
LABEL_26:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 92);
v22 = 0;
}
else if ( v4 <= 3 )
{
if ( v4 == 2 )
{
LABEL_25:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 45);
}
else if ( v4 <= 2 )
{
if ( v4 )
{
if ( v4 == 1 )
{
LABEL_24:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 47);
}
}
else
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 124);
}
}
}
}
else
{
switch ( v20 )
{
case 0:
v5 = v22++;
if ( v5 == 3 )
goto LABEL_26;
if ( v5 <= 3 )
{
if ( v5 == 2 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -60);
}
else if ( v5 <= 2 )
{
if ( v5 )
{
if ( v5 == 1 )
goto LABEL_24;
}
else
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -77);
}
}
}
break;
case 1:
v6 = v22++;
switch ( v6 )
{
case 0:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -80);
break;
case 1:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -79);
break;
case 2:
case 4:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -78);
break;
case 3:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -37);
break;
case 5:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -79);
v22 = 0;
break;
default:
goto LABEL_78;
}
break;
case 2:
v7 = v22++;
if ( v7 == 3 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 61);
v22 = 0;
}
else if ( v7 <= 3 )
{
if ( v7 == 2 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -16);
}
else if ( v7 <= 2 )
{
if ( !v7 )
goto LABEL_25;
if ( v7 == 1 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 61);
}
}
}
break;
case 3:
v8 = v22++;
if ( v8 == 3 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -65);
v22 = 0;
}
else if ( v8 <= 3 )
{
if ( v8 == 2 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -39);
}
else if ( v8 <= 2 )
{
if ( v8 )
{
if ( v8 == 1 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -64);
}
}
else
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -38);
}
}
}
break;
case 4:
v9 = v22++;
if ( v9 == 3 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -35);
v22 = 0;
}
else if ( v9 <= 3 )
{
if ( v9 == 2 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -33);
}
else if ( v9 <= 2 )
{
if ( v9 )
{
if ( v9 == 1 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -34);
}
}
else
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -36);
}
}
}
break;
default:
break;
}
}
}
LABEL_78:
if ( (v15 & 0x20) != 0 )
v10 = 250LL;
else
v10 = 1000LL;
v19 = sbbs_t::inkey(this, v15, v10);
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
return 0;
*((_QWORD *)this + 6406) = time(0LL);
if ( v19 )
{
if ( ((v15 & 4) == 0 || !isprint((char)v19) || (unsigned int)((char)v19 - 48) <= 9)
&& ((v15 & 0x400) == 0 || !isprint((char)v19) || isalpha((char)v19))
&& ((v15 & 0x2000) == 0 || (v19 & 0x80u) == 0) )
{
if ( (v15 & 0x20) != 0 )
sbbs_t::backspace(this);
if ( (v15 & 0x10000) == 0 || (char)v19 <= 32 || (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
goto LABEL_110;
if ( (v15 & 1) != 0 )
{
v11 = toupper((char)v19);
sbbs_t::outchar(this, v11);
}
else
{
sbbs_t::outchar(this, v19);
}
do
v18 = sbbs_t::inkey(this, v15, 0x3E8uLL);
while ( !v18 && *((_QWORD *)this + 6413) && (*((_QWORD *)this + 6414) & 0x800LL) == 0 );
sbbs_t::backspace(this);
if ( v18 != 8 && v18 != 127 )
{
if ( v18 > 32 )
sbbs_t::ungetkey(this, v18);
LABEL_110:
if ( (v15 & 1) != 0 )
result = toupper((char)v19);
else
result = v19;
return result;
}
}
}
else
{
if ( (*((_QWORD *)this + 6414) & 8LL) == 0 || (*((_QWORD *)this + 6414) & 0x10LL) != 0 )
{
if ( *((_QWORD *)this + 6413)
&& (__int64)(*((_QWORD *)this + 6406) - *((_QWORD *)this + 6407)) > 1800
&& (*((_QWORD *)this + 6414) & 0x10LL) == 0 )
{
*((_QWORD *)this + 6394) &= 0xFFFFFFFFFFFFFFEDLL;
*((_QWORD *)this + 6394) |= 9uLL;
sbbs_t::bputs(this, *((char **)this + 5021));
sbbs_t::hangup(this);
}
}
else
{
sbbs_t::gettimeleft(this);
}
if ( (*((_QWORD *)this + 6414) & 8LL) != 0
&& *((_QWORD *)this + 6413)
&& *((_QWORD *)this + 6451) / 0x3CuLL < 5LL - *((_QWORD *)this + 6055)
&& *((_BYTE *)this + 26885) <= 0x59u
&& (*((_QWORD *)this + 6414) & 4LL) == 0
&& (*((_QWORD *)this + 6414) & 0x10LL) == 0 )
{
*((_QWORD *)this + 6055) = 5 - *((_QWORD *)this + 6451) / 0x3CuLL;
*((_BYTE *)this + *((int *)this + 12655) + 50612) = *((_BYTE *)this + 51144);
*((_BYTE *)this + *((int *)this + 12655) + 50616) = *((_BYTE *)this + 48448);
sprintf(
(char *)this + 513 * *((int *)this + 12655) + 48560,
"%.*s",
*((_DWORD *)this + 12785),
(const char *)this + 50624);
if ( *((int *)this + 12655) <= 3 )
++*((_DWORD *)this + 12655);
*((_DWORD *)this + 12785) = 0;
sbbs_t::attr(this, 7);
if ( *((_QWORD *)this + 6451) > 0x3BuLL )
v13 = "s";
else
v13 = nulstr;
sbbs_t::bprintf(this, *((char **)this + 5131), (unsigned __int16)*((_QWORD *)this + 6451) / 0x3Cu + 1, v13);
*((_DWORD *)this + 12785) = 0;
if ( *((_DWORD *)this + 12655) )
--*((_DWORD *)this + 12655);
sbbs_t::attr(this, *((char *)this + *((int *)this + 12655) + 50612));
sbbs_t::rputs(this, (char *)this + 513 * *((int *)this + 12655) + 48560);
*((_BYTE *)this + 48448) = *((_BYTE *)this + *((int *)this + 12655) + 50616);
}
if ( (*(_QWORD *)(*(_QWORD *)this + 32LL) & 0x100LL) == 0
&& v21 != *((_QWORD *)this + 6406)
&& (__int64)(*((_QWORD *)this + 6406) - *((_QWORD *)this + 6054)) > 59
&& !((*((_QWORD *)this + 6406) - *((_QWORD *)this + 6054)) % 60LL) )
{
sbbs_t::send_telnet_cmd(this, 0xF9u, 0);
v21 = *((_QWORD *)this + 6406);
}
if ( *((_QWORD *)this + 6413) == 2LL
&& (*((_QWORD *)this + 6394) & 0x2000LL) == 0
&& *((_QWORD *)this + 6406) - *((_QWORD *)this + 6054) >= (__int64)*((unsigned __int16 *)this + 11865) )
{
if ( (*((_QWORD *)this + 6414) & 8LL) == 0 || *((_WORD *)this + 11865) == *((_WORD *)this + 11866) )
{
sbbs_t::bputs(this, "\a\a");
}
else
{
*((_BYTE *)this + *((int *)this + 12655) + 50612) = *((_BYTE *)this + 51144);
*((_BYTE *)this + *((int *)this + 12655) + 50616) = *((_BYTE *)this + 48448);
sprintf(
(char *)this + 513 * *((int *)this + 12655) + 48560,
"%.*s",
*((_DWORD *)this + 12785),
(const char *)this + 50624);
if ( *((int *)this + 12655) <= 3 )
++*((_DWORD *)this + 12655);
*((_DWORD *)this + 12785) = 0;
sbbs_t::bputs(this, *((char **)this + 5132));
}
while ( !(unsigned __int8)sbbs_t::inkey(this, 0LL, 0x64uLL)
&& *((_QWORD *)this + 6413)
&& *((_QWORD *)this + 6406) - *((_QWORD *)this + 6054) >= (__int64)*((unsigned __int16 *)this + 11865) )
{
*((_QWORD *)this + 6406) = time(0LL);
if ( *((_QWORD *)this + 6406) - *((_QWORD *)this + 6054) >= (__int64)*((unsigned __int16 *)this + 11866) )
{
if ( *((_QWORD *)this + 6413) == 2LL )
{
*((_QWORD *)this + 6394) |= 1uLL;
*((_QWORD *)this + 6394) &= 0xFFFFFFFFFFFFFFFDLL;
}
sbbs_t::bputs(this, *((char **)this + 5022));
sbbs_t::logline(this, nulstr, "Inactive");
sbbs_t::hangup(this);
return 0;
}
}
if ( (*((_QWORD *)this + 6414) & 8LL) != 0 && *((_WORD *)this + 11865) != *((_WORD *)this + 11866) )
{
sbbs_t::bputs(this, asc_1F13);
*((_DWORD *)this + 12785) = 0;
if ( *((_DWORD *)this + 12655) )
--*((_DWORD *)this + 12655);
sbbs_t::attr(this, *((char *)this + *((int *)this + 12655) + 50612));
sbbs_t::rputs(this, (char *)this + 513 * *((int *)this + 12655) + 48560);
*((_BYTE *)this + 48448) = *((_BYTE *)this + *((int *)this + 12655) + 50616);
}
*((_QWORD *)this + 6054) = *((_QWORD *)this + 6406);
}
}
if ( !*((_QWORD *)this + 6413) )
return 0;
}
if ( (v15 & 0x20) != 0 )
sbbs_t::backspace(this);
result = 0;
}
else
{
v17 = 1;
timeout.tv_sec = 0LL;
timeout.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &timeout);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall sbbs_t::func0(sbbs_t *this, __int64 a2)
{
int result; // eax
__int64 v3; // rax
char v4; // al
char v5; // al
char v6; // al
char v7; // al
char v8; // al
char v9; // al
unsigned __int64 v10; // rdx
char v11; // al
const char *v13; // rax
__int64 v15; // [rsp+0h] [rbp-40h]
struct timeval timeout; // [rsp+10h] [rbp-30h] BYREF
int v17; // [rsp+28h] [rbp-18h]
char v18; // [rsp+2Dh] [rbp-13h]
unsigned __int8 v19; // [rsp+2Eh] [rbp-12h]
char v20; // [rsp+2Fh] [rbp-11h]
__int64 v21; // [rsp+30h] [rbp-10h]
char v22; // [rsp+3Fh] [rbp-1h]

v15 = a2;
v22 = 0;
v20 = sbbs_random(5LL);
v21 = 0LL;
if ( *((_QWORD *)this + 6413) && *((_BYTE *)this + 26098) == 1 )
{
v3 = *((_QWORD *)this + 6414);
BYTE1(v3) &= 0xF7u;
*((_QWORD *)this + 6414) = v3;
if ( ((*((_QWORD *)this + 6414) & 8LL) != 0 || *((_BYTE *)this + 51296) == 9) && (a2 & 0x200800) == 0 )
v15 = *((_QWORD *)this + 3362) & 0x20LL | a2;
*((_QWORD *)this + 6065) = 0LL;
*((_QWORD *)this + 6054) = time(0LL);
if ( (v15 & 0x20) != 0 )
sbbs_t::outchar(this, 32);
while ( (*((_QWORD *)this + 6414) & 0x800LL) == 0 )
{
if ( (v15 & 0x20) != 0 )
{
if ( (*((_QWORD *)this + 3362) & 0x8000LL) != 0 )
{
v4 = v22++;
if ( v4 == 3 )
{
LABEL_26:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 92);
v22 = 0;
}
else if ( v4 <= 3 )
{
if ( v4 == 2 )
{
LABEL_25:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 45);
}
else if ( v4 <= 2 )
{
if ( v4 )
{
if ( v4 == 1 )
{
LABEL_24:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 47);
}
}
else
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 124);
}
}
}
}
else
{
switch ( v20 )
{
case 0:
v5 = v22++;
if ( v5 == 3 )
goto LABEL_26;
if ( v5 <= 3 )
{
if ( v5 == 2 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -60);
}
else if ( v5 <= 2 )
{
if ( v5 )
{
if ( v5 == 1 )
goto LABEL_24;
}
else
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -77);
}
}
}
break;
case 1:
v6 = v22++;
switch ( v6 )
{
case 0:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -80);
break;
case 1:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -79);
break;
case 2:
case 4:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -78);
break;
case 3:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -37);
break;
case 5:
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -79);
v22 = 0;
break;
default:
goto LABEL_78;
}
break;
case 2:
v7 = v22++;
if ( v7 == 3 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 61);
v22 = 0;
}
else if ( v7 <= 3 )
{
if ( v7 == 2 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -16);
}
else if ( v7 <= 2 )
{
if ( !v7 )
goto LABEL_25;
if ( v7 == 1 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, 61);
}
}
}
break;
case 3:
v8 = v22++;
if ( v8 == 3 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -65);
v22 = 0;
}
else if ( v8 <= 3 )
{
if ( v8 == 2 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -39);
}
else if ( v8 <= 2 )
{
if ( v8 )
{
if ( v8 == 1 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -64);
}
}
else
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -38);
}
}
}
break;
case 4:
v9 = v22++;
if ( v9 == 3 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -35);
v22 = 0;
}
else if ( v9 <= 3 )
{
if ( v9 == 2 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -33);
}
else if ( v9 <= 2 )
{
if ( v9 )
{
if ( v9 == 1 )
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -34);
}
}
else
{
sbbs_t::outchar(this, 8);
sbbs_t::outchar(this, -36);
}
}
}
break;
default:
break;
}
}
}
LABEL_78:
if ( (v15 & 0x20) != 0 )
v10 = 250LL;
else
v10 = 1000LL;
v19 = sbbs_t::inkey(this, v15, v10);
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
return 0;
*((_QWORD *)this + 6406) = time(0LL);
if ( v19 )
{
if ( ((v15 & 4) == 0 || !isprint((char)v19) || (unsigned int)((char)v19 - 48) <= 9)
&& ((v15 & 0x400) == 0 || !isprint((char)v19) || isalpha((char)v19))
&& ((v15 & 0x2000) == 0 || (v19 & 0x80u) == 0) )
{
if ( (v15 & 0x20) != 0 )
sbbs_t::backspace(this);
if ( (v15 & 0x10000) == 0 || (char)v19 <= 32 || (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
goto LABEL_110;
if ( (v15 & 1) != 0 )
{
v11 = toupper((char)v19);
sbbs_t::outchar(this, v11);
}
else
{
sbbs_t::outchar(this, v19);
}
do
v18 = sbbs_t::inkey(this, v15, 0x3E8uLL);
while ( !v18 && *((_QWORD *)this + 6413) && (*((_QWORD *)this + 6414) & 0x800LL) == 0 );
sbbs_t::backspace(this);
if ( v18 != 8 && v18 != 127 )
{
if ( v18 > 32 )
sbbs_t::ungetkey(this, v18);
LABEL_110:
if ( (v15 & 1) != 0 )
result = toupper((char)v19);
else
result = v19;
return result;
}
}
}
else
{
if ( (*((_QWORD *)this + 6414) & 8LL) == 0 || (*((_QWORD *)this + 6414) & 0x10LL) != 0 )
{
if ( *((_QWORD *)this + 6413)
&& (__int64)(*((_QWORD *)this + 6406) - *((_QWORD *)this + 6407)) > 1800
&& (*((_QWORD *)this + 6414) & 0x10LL) == 0 )
{
*((_QWORD *)this + 6394) &= 0xFFFFFFFFFFFFFFEDLL;
*((_QWORD *)this + 6394) |= 9uLL;
sbbs_t::bputs(this, *((char **)this + 5021));
sbbs_t::hangup(this);
}
}
else
{
sbbs_t::gettimeleft(this);
}
if ( (*((_QWORD *)this + 6414) & 8LL) != 0
&& *((_QWORD *)this + 6413)
&& *((_QWORD *)this + 6451) / 0x3CuLL < 5LL - *((_QWORD *)this + 6055)
&& *((_BYTE *)this + 26885) <= 0x59u
&& (*((_QWORD *)this + 6414) & 4LL) == 0
&& (*((_QWORD *)this + 6414) & 0x10LL) == 0 )
{
*((_QWORD *)this + 6055) = 5 - *((_QWORD *)this + 6451) / 0x3CuLL;
*((_BYTE *)this + *((int *)this + 12655) + 50612) = *((_BYTE *)this + 51144);
*((_BYTE *)this + *((int *)this + 12655) + 50616) = *((_BYTE *)this + 48448);
sprintf(
(char *)this + 513 * *((int *)this + 12655) + 48560,
"%.*s",
*((_DWORD *)this + 12785),
(const char *)this + 50624);
if ( *((int *)this + 12655) <= 3 )
++*((_DWORD *)this + 12655);
*((_DWORD *)this + 12785) = 0;
sbbs_t::attr(this, 7);
if ( *((_QWORD *)this + 6451) > 0x3BuLL )
v13 = "s";
else
v13 = nulstr;
sbbs_t::bprintf(this, *((char **)this + 5131), (unsigned __int16)*((_QWORD *)this + 6451) / 0x3Cu + 1, v13);
*((_DWORD *)this + 12785) = 0;
if ( *((_DWORD *)this + 12655) )
--*((_DWORD *)this + 12655);
sbbs_t::attr(this, *((char *)this + *((int *)this + 12655) + 50612));
sbbs_t::rputs(this, (char *)this + 513 * *((int *)this + 12655) + 48560);
*((_BYTE *)this + 48448) = *((_BYTE *)this + *((int *)this + 12655) + 50616);
}
if ( (*(_QWORD *)(*(_QWORD *)this + 32LL) & 0x100LL) == 0
&& v21 != *((_QWORD *)this + 6406)
&& (__int64)(*((_QWORD *)this + 6406) - *((_QWORD *)this + 6054)) > 59
&& !((*((_QWORD *)this + 6406) - *((_QWORD *)this + 6054)) % 60LL) )
{
sbbs_t::send_telnet_cmd(this, 0xF9u, 0);
v21 = *((_QWORD *)this + 6406);
}
if ( *((_QWORD *)this + 6413) == 2LL
&& (*((_QWORD *)this + 6394) & 0x2000LL) == 0
&& *((_QWORD *)this + 6406) - *((_QWORD *)this + 6054) >= (__int64)*((unsigned __int16 *)this + 11865) )
{
if ( (*((_QWORD *)this + 6414) & 8LL) == 0 || *((_WORD *)this + 11865) == *((_WORD *)this + 11866) )
{
sbbs_t::bputs(this, "\a\a");
}
else
{
*((_BYTE *)this + *((int *)this + 12655) + 50612) = *((_BYTE *)this + 51144);
*((_BYTE *)this + *((int *)this + 12655) + 50616) = *((_BYTE *)this + 48448);
sprintf(
(char *)this + 513 * *((int *)this + 12655) + 48560,
"%.*s",
*((_DWORD *)this + 12785),
(const char *)this + 50624);
if ( *((int *)this + 12655) <= 3 )
++*((_DWORD *)this + 12655);
*((_DWORD *)this + 12785) = 0;
sbbs_t::bputs(this, *((char **)this + 5132));
}
while ( !(unsigned __int8)sbbs_t::inkey(this, 0LL, 0x64uLL)
&& *((_QWORD *)this + 6413)
&& *((_QWORD *)this + 6406) - *((_QWORD *)this + 6054) >= (__int64)*((unsigned __int16 *)this + 11865) )
{
*((_QWORD *)this + 6406) = time(0LL);
if ( *((_QWORD *)this + 6406) - *((_QWORD *)this + 6054) >= (__int64)*((unsigned __int16 *)this + 11866) )
{
if ( *((_QWORD *)this + 6413) == 2LL )
{
*((_QWORD *)this + 6394) |= 1uLL;
*((_QWORD *)this + 6394) &= 0xFFFFFFFFFFFFFFFDLL;
}
sbbs_t::bputs(this, *((char **)this + 5022));
sbbs_t::logline(this, nulstr, "Inactive");
sbbs_t::hangup(this);
return 0;
}
}
if ( (*((_QWORD *)this + 6414) & 8LL) != 0 && *((_WORD *)this + 11865) != *((_WORD *)this + 11866) )
{
sbbs_t::bputs(this, asc_1F13);
*((_DWORD *)this + 12785) = 0;
if ( *((_DWORD *)this + 12655) )
--*((_DWORD *)this + 12655);
sbbs_t::attr(this, *((char *)this + *((int *)this + 12655) + 50612));
sbbs_t::rputs(this, (char *)this + 513 * *((int *)this + 12655) + 48560);
*((_BYTE *)this + 48448) = *((_BYTE *)this + *((int *)this + 12655) + 50616);
}
*((_QWORD *)this + 6054) = *((_QWORD *)this + 6406);
}
}
if ( !*((_QWORD *)this + 6413) )
return 0;
}
if ( (v15 & 0x20) != 0 )
sbbs_t::backspace(this);
result = 0;
}
else
{
v17 = 1;
timeout.tv_sec = 0LL;
timeout.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &timeout);
result = 0;
}
return result;
}

original_code:
char getkey(long mode)
{
 char ch,warn=0;
 long tleft;
 time_t timeout,now;
 aborted=lncntr=0;
 timeout=time(((void *)0));
 do {
  checkline();
  ch=inkey(mode);
  now=time(((void *)0));
  if(ch) {
   if(mode&(1<<2) && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint) && !((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit))
    continue;
   if(mode&(1<<10) && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint) && !((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha))
    continue;
   if(ch=='\n') continue;
   if(mode&(1<<0))
    return(toupper(ch));
   return(ch);
  }
  checktimeleft();
  tleft=timeleft-(now-starttime);
  if((tleft/60)<(5-timeleft_warn)) {
   timeleft_warn=5-(tleft/60);
   { slatr[slcnt]=latr; sprintf(slbuf[slcnt<4 ? slcnt++ : slcnt] ,"%.*s",lbuflen,lbuf); lbuflen=0; };
   bprintf("\1n\1h\r\n\7\r\nYou only have \1r\1i%u\1n\1h minute%s "
    "left.\r\n\r\n"
    ,((unsigned short)tleft/60)+1,(tleft/60) ? "s" : "");
   { lbuflen=0; attr(slatr[--slcnt]); bputs(slbuf[slcnt]); };
  }
  if(now-timeout>=(time_t)sec_warn && !warn)
   for(warn=0;warn<5;warn++)
    outchar(7);
 } while(now-timeout<(time_t)sec_timeout);
 bputs("\r\nInactive too long.\r\n");
 exit(0);
 return(0);
}

canonical_original_code:
char getkey(long mode)
{
 char ch; char warn = 0;
 long tleft;
 long timeout; long now;
 aborted=lncntr=0;
 timeout=time(((void *)0));
 do {
  checkline();
  ch=inkey(mode);
  now=time(((void *)0));
  if(ch) {
   if(mode&(1<<2) && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint) && !((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit))
    continue;
   if(mode&(1<<10) && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint) && !((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalpha))
    continue;
   if(ch=='\n') continue;
   if(mode&(1<<0))
    return(toupper(ch));
   return(ch);
  }
  checktimeleft();
  tleft=timeleft-(now-starttime);
  if((tleft/60)<(5-timeleft_warn)) {
   timeleft_warn=5-(tleft/60);
   { slatr[slcnt]=latr; sprintf(slbuf[slcnt<4 ? slcnt++ : slcnt] ,"%.*s",lbuflen,lbuf); lbuflen=0; };
   bprintf("\1n\1h\r\n\7\r\nYou only have \1r\1i%u\1n\1h minute%s "
    "left.\r\n\r\n"
    ,((unsigned short)tleft/60)+1,(tleft/60) ? "s" : "");
   { lbuflen=0; attr(slatr[--slcnt]); bputs(slbuf[slcnt]); };
  }
  if(now-timeout>=(long)sec_warn && !warn)
   for(warn=0;warn<5;warn++)
    outchar(7);
 } while(now-timeout<(long)sec_timeout);
 bputs("\r\nInactive too long.\r\n");
 exit(0);
 return(0);
}

variable_types: mode long

variable_types: ch char

variable_types: warn char

variable_types: tleft long

variable_types: timeout long

variable_types: now long

return_type: char


mnemonics

decompiled_code:
__int64 __fastcall sbbs_t::mnemonics(sbbs_t *this, char *a2)
{
__int64 result; // rax
__int64 v3; // rax
char *v4; // [rsp+10h] [rbp-10h]
__int64 v5; // [rsp+18h] [rbp-8h]
__int64 v6; // [rsp+18h] [rbp-8h]
__int64 v7; // [rsp+18h] [rbp-8h]

if ( !strchr(a2, 126) )
goto LABEL_2;
v4 = strchr(a2, 1);
if ( !v4 )
{
if ( *a2 == 64 && a2[strlen(a2) - 1] == 64 && !strchr(a2, 32) )
{
LABEL_2:
*((_QWORD *)this + 6774) = a2;
return sbbs_t::bputs(this, a2);
}
sbbs_t::attr(this, *(char *)(*((_QWORD *)this + 2967) + 1LL));
}
v5 = 0LL;
while ( 1 )
{
result = (unsigned __int8)a2[v5];
if ( !(_BYTE)result )
break;
if ( a2[v5] == 126 && a2[v5 + 1] )
{
if ( !sbbs_t::term_supports(this, 2LL) )
sbbs_t::outchar(this, 40);
v6 = v5 + 1;
if ( !v4 )
sbbs_t::attr(this, **((char **)this + 2967));
sbbs_t::outchar(this, a2[v6]);
v5 = v6 + 1;
if ( !sbbs_t::term_supports(this, 2LL) )
sbbs_t::outchar(this, 41);
if ( !v4 )
sbbs_t::attr(this, *(char *)(*((_QWORD *)this + 2967) + 1LL));
}
else if ( a2[v5] == 1 && a2[v5 + 1] )
{
v7 = v5 + 1;
sbbs_t::ctrl_a(this, a2[v7]);
v5 = v7 + 1;
}
else
{
v3 = v5++;
sbbs_t::outchar(this, a2[v3]);
}
}
if ( !v4 )
result = sbbs_t::attr(this, *(char *)(*((_QWORD *)this + 2967) + 2LL));
return result;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func1(sbbs_t *this, char *a2)
{
__int64 result; // rax
__int64 v3; // rax
char *v4; // [rsp+10h] [rbp-10h]
__int64 v5; // [rsp+18h] [rbp-8h]
__int64 v6; // [rsp+18h] [rbp-8h]
__int64 v7; // [rsp+18h] [rbp-8h]

if ( !strchr(a2, 126) )
goto LABEL_2;
v4 = strchr(a2, 1);
if ( !v4 )
{
if ( *a2 == 64 && a2[strlen(a2) - 1] == 64 && !strchr(a2, 32) )
{
LABEL_2:
*((_QWORD *)this + 6774) = a2;
return sbbs_t::bputs(this, a2);
}
sbbs_t::attr(this, *(char *)(*((_QWORD *)this + 2967) + 1LL));
}
v5 = 0LL;
while ( 1 )
{
result = (unsigned __int8)a2[v5];
if ( !(_BYTE)result )
break;
if ( a2[v5] == 126 && a2[v5 + 1] )
{
if ( !sbbs_t::term_supports(this, 2LL) )
sbbs_t::outchar(this, 40);
v6 = v5 + 1;
if ( !v4 )
sbbs_t::attr(this, **((char **)this + 2967));
sbbs_t::outchar(this, a2[v6]);
v5 = v6 + 1;
if ( !sbbs_t::term_supports(this, 2LL) )
sbbs_t::outchar(this, 41);
if ( !v4 )
sbbs_t::attr(this, *(char *)(*((_QWORD *)this + 2967) + 1LL));
}
else if ( a2[v5] == 1 && a2[v5 + 1] )
{
v7 = v5 + 1;
sbbs_t::ctrl_a(this, a2[v7]);
v5 = v7 + 1;
}
else
{
v3 = v5++;
sbbs_t::outchar(this, a2[v3]);
}
}
if ( !v4 )
result = sbbs_t::attr(this, *(char *)(*((_QWORD *)this + 2967) + 2LL));
return result;
}

original_code:
void mnemonics(char *str)
{
 long l;
 attr(mnelow);
 l=0L;
 while(str[l]) {
  if(str[l]=='~' && str[l+1]) {
   if(!(user_misc&(1<<0)))
    outchar('(');
   l++;
   attr(mnehigh);
   outchar(str[l]);
   l++;
   if(!(user_misc&(1<<0)))
    outchar(')');
   attr(mnelow);
  }
  else
   outchar(str[l++]);
 }
 attr(LIGHTGRAY);
}

variable_types:
str
char *

variable_types: l long

return_type: void


yesno

decompiled_code:
__int64 __fastcall sbbs_t::yesno(sbbs_t *this, char *a2)
{
char v3; // [rsp+1Fh] [rbp-1h]

strcpy((char *)this + 54064, a2);
sbbs_t::getnodedat(this, *((unsigned __int16 *)this + 1212), (char *)this + 27056, 0LL);
sbbs_t::nodesync(this);
if ( (*((_QWORD *)this + 3362) & 0x200000LL) != 0 )
{
strip_ctrl((char *)this + 54064);
sbbs_t::menu(this, "yesno");
}
else
{
sbbs_t::bprintf(this, *((char **)this + 5023), a2);
}
do
{
if ( !*((_QWORD *)this + 6413) )
return 1LL;
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
v3 = *(_BYTE *)(*((_QWORD *)this + 5184) + 1LL);
else
v3 = sbbs_t::getkey(this, 65537LL);
if ( v3 == **((_BYTE **)this + 5184) || v3 == 13 )
{
if ( (unsigned int)sbbs_t::bputs(this, *((char **)this + 5024)) )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
}
*((_QWORD *)this + 6065) = 0LL;
return 1LL;
}
}
while ( v3 != *(_BYTE *)(*((_QWORD *)this + 5184) + 1LL) );
if ( (unsigned int)sbbs_t::bputs(this, *((char **)this + 5025)) )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
}
*((_QWORD *)this + 6065) = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func2(sbbs_t *this, char *a2)
{
char v3; // [rsp+1Fh] [rbp-1h]

strcpy((char *)this + 54064, a2);
sbbs_t::getnodedat(this, *((unsigned __int16 *)this + 1212), (char *)this + 27056, 0LL);
sbbs_t::nodesync(this);
if ( (*((_QWORD *)this + 3362) & 0x200000LL) != 0 )
{
strip_ctrl((char *)this + 54064);
sbbs_t::menu(this, "yesno");
}
else
{
sbbs_t::bprintf(this, *((char **)this + 5023), a2);
}
do
{
if ( !*((_QWORD *)this + 6413) )
return 1LL;
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
v3 = *(_BYTE *)(*((_QWORD *)this + 5184) + 1LL);
else
v3 = sbbs_t::func0(this, 65537LL);
if ( v3 == **((_BYTE **)this + 5184) || v3 == 13 )
{
if ( (unsigned int)sbbs_t::bputs(this, *((char **)this + 5024)) )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
}
*((_QWORD *)this + 6065) = 0LL;
return 1LL;
}
}
while ( v3 != *(_BYTE *)(*((_QWORD *)this + 5184) + 1LL) );
if ( (unsigned int)sbbs_t::bputs(this, *((char **)this + 5025)) )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
}
*((_QWORD *)this + 6065) = 0LL;
return 0LL;
}

original_code:
char yesno(char *str)
{
 char ch;
 bprintf("\1_\1b\1h%s (Y/n) ? \1w",str);
 while(1) {
  ch=getkey((1<<0));
  if(ch=='Y' || ch=='\r') {
   bputs("Yes\r\n");
   return(1); }
  if(ch=='N' || aborted) {
   bputs("No\r\n");
   return(0);
  }
 }
}


noyes

decompiled_code:
__int64 __fastcall sbbs_t::noyes(sbbs_t *this, char *a2)
{
char v3; // [rsp+1Fh] [rbp-1h]

strcpy((char *)this + 54064, a2);
sbbs_t::getnodedat(this, *((unsigned __int16 *)this + 1212), (char *)this + 27056, 0LL);
sbbs_t::nodesync(this);
if ( (*((_QWORD *)this + 3362) & 0x200000LL) != 0 )
{
strip_ctrl((char *)this + 54064);
sbbs_t::menu(this, "noyes");
}
else
{
sbbs_t::bprintf(this, *((char **)this + 5026), a2);
}
do
{
if ( !*((_QWORD *)this + 6413) )
return 1LL;
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
v3 = *(_BYTE *)(*((_QWORD *)this + 5184) + 1LL);
else
v3 = sbbs_t::getkey(this, 65537LL);
if ( v3 == *(_BYTE *)(*((_QWORD *)this + 5184) + 1LL) || v3 == 13 )
{
if ( (unsigned int)sbbs_t::bputs(this, *((char **)this + 5025)) )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
}
*((_QWORD *)this + 6065) = 0LL;
return 1LL;
}
}
while ( v3 != **((_BYTE **)this + 5184) );
if ( (unsigned int)sbbs_t::bputs(this, *((char **)this + 5024)) )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
}
*((_QWORD *)this + 6065) = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func3(sbbs_t *this, char *a2)
{
char v3; // [rsp+1Fh] [rbp-1h]

strcpy((char *)this + 54064, a2);
sbbs_t::getnodedat(this, *((unsigned __int16 *)this + 1212), (char *)this + 27056, 0LL);
sbbs_t::nodesync(this);
if ( (*((_QWORD *)this + 3362) & 0x200000LL) != 0 )
{
strip_ctrl((char *)this + 54064);
sbbs_t::menu(this, "noyes");
}
else
{
sbbs_t::bprintf(this, *((char **)this + 5026), a2);
}
do
{
if ( !*((_QWORD *)this + 6413) )
return 1LL;
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
v3 = *(_BYTE *)(*((_QWORD *)this + 5184) + 1LL);
else
v3 = sbbs_t::func0(this, 65537LL);
if ( v3 == *(_BYTE *)(*((_QWORD *)this + 5184) + 1LL) || v3 == 13 )
{
if ( (unsigned int)sbbs_t::bputs(this, *((char **)this + 5025)) )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
}
*((_QWORD *)this + 6065) = 0LL;
return 1LL;
}
}
while ( v3 != **((_BYTE **)this + 5184) );
if ( (unsigned int)sbbs_t::bputs(this, *((char **)this + 5024)) )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
}
*((_QWORD *)this + 6065) = 0LL;
return 0LL;
}

original_code:
char noyes(char *str)
{
 char ch;
 bprintf("\1_\1b\1h%s (y/N) ? \1w",str);
 while(1) {
  ch=getkey((1<<0));
  if(ch=='N' || ch=='\r' || aborted) {
   bputs("No\r\n");
   return(1); }
  if(ch=='Y') {
   bputs("Yes\r\n");
   return(0);
  }
 }
}


getkeys

decompiled_code:
__int64 __fastcall sbbs_t::getkeys(sbbs_t *this, char *a2, unsigned __int64 a3)
{
__int64 result; // rax
char dest[95]; // [rsp+20h] [rbp-70h] BYREF
unsigned __int8 v6; // [rsp+7Fh] [rbp-11h]
unsigned __int64 v7; // [rsp+80h] [rbp-10h]
char v8; // [rsp+8Eh] [rbp-2h]
char v9; // [rsp+8Fh] [rbp-1h]

v9 = 0;
v8 = 0;
v7 = 0LL;
strncpy(dest, a2, 0x51uLL);
dest[80] = 0;
strupr(dest);
while ( 1 )
{
while ( 1 )
{
do
{
if ( !*((_QWORD *)this + 6413) )
return -1LL;
v6 = sbbs_t::getkey(this, 1LL);
}
while ( a3 && (v6 & 0x80u) != 0 );
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
{
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return -1LL;
}
if ( !v6 || v9 || !strchr(dest, v6) )
break;
sbbs_t::outchar(this, v6);
if ( (*((_QWORD *)this + 3362) & 0x40000LL) == 0 || v6 <= 0x20u )
goto LABEL_22;
do
{
if ( !*((_QWORD *)this + 6413) )
break;
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
break;
v8 = sbbs_t::getkey(this, 0LL);
if ( v8 == 13 )
break;
}
while ( v8 != 8 && v8 != 127 );
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
return -1LL;
}
if ( v8 != 8 && v8 != 127 )
{
LABEL_22:
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v6;
}
sbbs_t::backspace(this);
}
if ( v6 == 13 && a3 )
break;
if ( (v6 == 8 || v6 == 127) && v9 )
{
sbbs_t::backspace(this);
v7 /= 0xAuLL;
--v9;
}
else if ( a3 && (unsigned int)v6 - 48 <= 9 && a3 >= 10 * v7 + (v6 & 0xF) && (v6 != 48 || v9) )
{
v7 *= 10LL;
++v9;
v7 += v6 & 0xF;
sbbs_t::outchar(this, v6);
if ( a3 < 10 * v7 && (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
{
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v7 | 0x80000000;
}
}
}
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
if ( v9 )
result = v7 | 0x80000000;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func4(sbbs_t *this, char *a2, unsigned __int64 a3)
{
__int64 result; // rax
char dest[95]; // [rsp+20h] [rbp-70h] BYREF
unsigned __int8 v6; // [rsp+7Fh] [rbp-11h]
unsigned __int64 v7; // [rsp+80h] [rbp-10h]
char v8; // [rsp+8Eh] [rbp-2h]
char v9; // [rsp+8Fh] [rbp-1h]

v9 = 0;
v8 = 0;
v7 = 0LL;
strncpy(dest, a2, 0x51uLL);
dest[80] = 0;
strupr(dest);
while ( 1 )
{
while ( 1 )
{
do
{
if ( !*((_QWORD *)this + 6413) )
return -1LL;
v6 = sbbs_t::func0(this, 1LL);
}
while ( a3 && (v6 & 0x80u) != 0 );
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
{
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return -1LL;
}
if ( !v6 || v9 || !strchr(dest, v6) )
break;
sbbs_t::outchar(this, v6);
if ( (*((_QWORD *)this + 3362) & 0x40000LL) == 0 || v6 <= 0x20u )
goto LABEL_22;
do
{
if ( !*((_QWORD *)this + 6413) )
break;
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
break;
v8 = sbbs_t::func0(this, 0LL);
if ( v8 == 13 )
break;
}
while ( v8 != 8 && v8 != 127 );
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
return -1LL;
}
if ( v8 != 8 && v8 != 127 )
{
LABEL_22:
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v6;
}
sbbs_t::backspace(this);
}
if ( v6 == 13 && a3 )
break;
if ( (v6 == 8 || v6 == 127) && v9 )
{
sbbs_t::backspace(this);
v7 /= 0xAuLL;
--v9;
}
else if ( a3 && (unsigned int)v6 - 48 <= 9 && a3 >= 10 * v7 + (v6 & 0xF) && (v6 != 48 || v9) )
{
v7 *= 10LL;
++v9;
v7 += v6 & 0xF;
sbbs_t::outchar(this, v6);
if ( a3 < 10 * v7 && (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
{
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v7 | 0x80000000;
}
}
}
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
if ( v9 )
result = v7 | 0x80000000;
else
result = 0LL;
return result;
}

original_code:
int getkeys(char *instr,int max)
{
 char str[256];
 unsigned char ch,n=0;
 int i=0;
 sprintf(str,"%.*s",sizeof(str)-1,instr);
 strupr(str);
 while(!aborted) {
  ch=getkey((1<<0));
  if(max && ch>0x7f)
   continue;
  if(ch && !n && (strchr(str,ch))) {
   outchar(ch);
   attr(LIGHTGRAY);
   { outchar('\r'); outchar('\n'); };
   return(ch);
  }
  if(ch=='\r' && max) {
   attr(LIGHTGRAY);
   { outchar('\r'); outchar('\n'); };
   if(n)
    return(i|0x8000);
   return(0);
  }
  if(ch=='\b' && n) {
   bputs("\b \b");
   i/=10;
   n--;
  }
  else if(max && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit) && (i*10)+(ch&0xf)<=max && (ch!='0' || n)) {
   i*=10;
   n++;
   i+=ch&0xf;
   outchar(ch);
   if(i*10>max) {
    attr(LIGHTGRAY);
    { outchar('\r'); outchar('\n'); };
    return(i|0x8000);
   }
  }
 }
 return(0);
}

canonical_original_code:
int getkeys(char *instr, int max)
{
 char str[256];
 unsigned char ch; unsigned char n = 0;
 int i = 0;
 sprintf(str,"%.*s",sizeof(str)-1,instr);
 strupr(str);
 while(!aborted) {
  ch=getkey((1<<0));
  if(max && ch>0x7f)
   continue;
  if(ch && !n && (strchr(str,ch))) {
   outchar(ch);
   attr(LIGHTGRAY);
   { outchar('\r'); outchar('\n'); };
   return(ch);
  }
  if(ch=='\r' && max) {
   attr(LIGHTGRAY);
   { outchar('\r'); outchar('\n'); };
   if(n)
    return(i|0x8000);
   return(0);
  }
  if(ch=='\b' && n) {
   bputs("\b \b");
   i/=10;
   n--;
  }
  else if(max && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit) && (i*10)+(ch&0xf)<=max && (ch!='0' || n)) {
   i*=10;
   n++;
   i+=ch&0xf;
   outchar(ch);
   if(i*10>max) {
    attr(LIGHTGRAY);
    { outchar('\r'); outchar('\n'); };
    return(i|0x8000);
   }
  }
 }
 return(0);
}

variable_types:
instr
char *

variable_types: max int

variable_types:
str
char [256]

variable_types:
ch
unsigned char

variable_types:
n
unsigned char

variable_types: i int


decompiled_code:
// attributes: thunk
__int64 js_sprintf_free()
{
return xp_asprintf_free();
}

canonical_decompiled_code:
__int64 func1()
{
return xp_asprintf_free();
}

original_code:
void
js_sprintf_free(char* p)
{
 xp_asprintf_free(p);
}

canonical_original_code:
void js_sprintf_free(char *p)
{
 xp_asprintf_free(p);
}

variable_types:
p
char *


uudecode

original_code:
int uudecode(char *target, size_t tlen, const char *source, size_t slen)
{
 int i;
 char ch;
 size_t rd=0;
 size_t wr=0;
 size_t block;
 size_t len;
 unsigned char cell[4];
 if(slen==0)
  slen=strlen(source);
 while(rd<slen && wr<tlen) {
  ch=source[rd++];
  if(ch<' ')
   continue;
  len=(ch-' ')&0x3f;
  if(len<=0 || rd>=slen)
   break;
  block=0;
  while(block<len && wr<tlen && rd<slen) {
   memset(cell,0,sizeof(cell));
   for(i=0;i<sizeof(cell) && rd<slen;i++) {
    cell[i]=source[rd++];
    if(cell[i]>=' ') cell[i]-=' ';
   }
   target[wr]=(cell[0]&0x3f)<<2;
   target[wr++]|=(cell[1]&0x30)>>4;
   target[wr]=(cell[1]&0x0f)<<4;
   target[wr++]|=(cell[2]&0x3c)>>2;
   target[wr]=(cell[2]&0x03)<<6;
   target[wr++]|=cell[3]&0x3f;
   block+=3;
  }
  while(rd<slen && source[rd]>' ')
   rd++;
  while(rd<slen && source[rd]!=0 && source[rd]<=' ')
   rd++;
 }
 return(wr);
}

canonical_original_code:
int uudecode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 int i;
 char ch;
 unsigned long rd = 0;
 unsigned long wr = 0;
 unsigned long block;
 unsigned long len;
 unsigned char cell[4];
 if(slen==0)
  slen=strlen(source);
 while(rd<slen && wr<tlen) {
  ch=source[rd++];
  if(ch<' ')
   continue;
  len=(ch-' ')&0x3f;
  if(len<=0 || rd>=slen)
   break;
  block=0;
  while(block<len && wr<tlen && rd<slen) {
   memset(cell,0,sizeof(cell));
   for(i=0;i<sizeof(cell) && rd<slen;i++) {
    cell[i]=source[rd++];
    if(cell[i]>=' ') cell[i]-=' ';
   }
   target[wr]=(cell[0]&0x3f)<<2;
   target[wr++]|=(cell[1]&0x30)>>4;
   target[wr]=(cell[1]&0x0f)<<4;
   target[wr++]|=(cell[2]&0x3c)>>2;
   target[wr]=(cell[2]&0x03)<<6;
   target[wr++]|=cell[3]&0x3f;
   block+=3;
  }
  while(rd<slen && source[rd]>' ')
   rd++;
  while(rd<slen && source[rd]!=0 && source[rd]<=' ')
   rd++;
 }
 return(wr);
}

variable_types:
target
char *

variable_types:
tlen
unsigned long

variable_types:
source
char *

variable_types:
slen
unsigned long

variable_types:
rd
unsigned long

variable_types:
wr
unsigned long

variable_types:
block
unsigned long

variable_types:
len
unsigned long

variable_types:
cell
unsigned char [4]


uuencode

original_code:
int uuencode(char *target, size_t tlen, const char *source, size_t slen)
{
 size_t rd=0;
 size_t wr=0;
 size_t block;
 size_t len;
 if(slen==0)
  slen=strlen(source);
 if(tlen<3)
  return(-1);
 tlen-=3;
 while(rd<=slen && wr<tlen) {
  len=45;
  if(rd+len>slen)
   len=slen-rd;
  if((len)==0) (len)='`'; else (len)+=' ';;
  target[wr++]=len;
  block=0;
  while(block<len && wr<tlen && rd<slen) {
   target[wr]=source[rd]>>2;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=(source[rd++]&0x03)<<4;
   target[wr]|=source[rd]>>4;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=(source[rd++]&0x0f)<<2;
   target[wr]|=source[rd]>>6;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=source[rd++]&0x3f;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   block+=3;
  }
  if(wr<tlen) {
   target[wr++]='\r';
   target[wr++]='\n';
  }
  if(rd>=slen)
   break;
 }
 if(wr<tlen)
  target[wr++]=0;
 return(wr);
}

canonical_original_code:
int uuencode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 unsigned long rd = 0;
 unsigned long wr = 0;
 unsigned long block;
 unsigned long len;
 if(slen==0)
  slen=strlen(source);
 if(tlen<3)
  return(-1);
 tlen-=3;
 while(rd<=slen && wr<tlen) {
  len=45;
  if(rd+len>slen)
   len=slen-rd;
  if((len)==0) (len)='`'; else (len)+=' ';;
  target[wr++]=len;
  block=0;
  while(block<len && wr<tlen && rd<slen) {
   target[wr]=source[rd]>>2;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=(source[rd++]&0x03)<<4;
   target[wr]|=source[rd]>>4;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=(source[rd++]&0x0f)<<2;
   target[wr]|=source[rd]>>6;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=source[rd++]&0x3f;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   block+=3;
  }
  if(wr<tlen) {
   target[wr++]='\r';
   target[wr++]='\n';
  }
  if(rd>=slen)
   break;
 }
 if(wr<tlen)
  target[wr++]=0;
 return(wr);
}


SetEvent

decompiled_code:
__int64 __fastcall SetEvent(__int64 a1)
{
__int64 result; // rax
bool v2; // zf

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v2 = *(_QWORD *)(a1 + 104) == 0LL;
*(_DWORD *)(a1 + 96) = 1;
if ( !v2 )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
bool v2; // zf

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v2 = *(_QWORD *)(a1 + 104) == 0LL;
*(_DWORD *)(a1 + 96) = 1;
if ( !v2 )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
SetEvent(xpevent_t event)
{
 if (event==((void *)0) || (event->magic != ((u_int32_t) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 event->value=1;
 if (event->nwaiters > 0) {
  pthread_cond_broadcast(&event->gtzero);
 }
 pthread_mutex_unlock(&event->lock);
 return(1);
}

canonical_original_code:
int SetEvent(struct xpevent *event)
{
 if (event==((void *)0) || (event->magic != ((unsigned int) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 event->value=1;
 if (event->nwaiters > 0) {
  pthread_cond_broadcast(&event->gtzero);
 }
 pthread_mutex_unlock(&event->lock);
 return(1);
}

variable_types: struct xpevent { 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; int value; int mreset; unsigned long nwaiters; } *

user_defined_types: struct xpevent { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t gtzero; int value; int mreset; unsigned long 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; }


ResetEvent

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

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)(a1 + 96) = 0;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)(a1 + 96) = 0;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ResetEvent(xpevent_t event)
{
 if (event==((void *)0) || (event->magic != ((u_int32_t) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 event->value=0;
 pthread_mutex_unlock(&event->lock);
 return(1);
}

canonical_original_code:
int ResetEvent(struct xpevent *event)
{
 if (event==((void *)0) || (event->magic != ((unsigned int) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 event->value=0;
 pthread_mutex_unlock(&event->lock);
 return(1);
}

user_defined_types: 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]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


CloseEvent

decompiled_code:
__int64 __fastcall CloseEvent(void *ptr)
{
__int64 result; // rax
pthread_mutex_t *v3; // r12
pthread_mutex_t *v4; // rdi
struct timeval v5[2]; // [rsp+0h] [rbp-28h] BYREF

if ( ptr && *(_DWORD *)ptr == 167395348 )
{
v3 = (pthread_mutex_t *)((char *)ptr + 8);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 8));
v4 = (pthread_mutex_t *)((char *)ptr + 8);
if ( *((_QWORD *)ptr + 13) )
{
pthread_mutex_unlock(v4);
*_errno_location() = 16;
result = 0LL;
}
else
{
pthread_mutex_unlock(v4);
while ( pthread_mutex_destroy(v3) == 16 )
{
v5[0].tv_sec = 0LL;
v5[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v5);
}
while ( pthread_cond_destroy((pthread_cond_t *)ptr + 1) == 16 )
{
v5[0].tv_sec = 0LL;
v5[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v5);
}
free(ptr);
result = 1LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
__int64 result; // rax
pthread_mutex_t *v3; // r12
pthread_mutex_t *v4; // rdi
struct timeval v5[2]; // [rsp+0h] [rbp-28h] BYREF

if ( ptr && *(_DWORD *)ptr == 167395348 )
{
v3 = (pthread_mutex_t *)((char *)ptr + 8);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 8));
v4 = (pthread_mutex_t *)((char *)ptr + 8);
if ( *((_QWORD *)ptr + 13) )
{
pthread_mutex_unlock(v4);
*_errno_location() = 16;
result = 0LL;
}
else
{
pthread_mutex_unlock(v4);
while ( pthread_mutex_destroy(v3) == 16 )
{
v5[0].tv_sec = 0LL;
v5[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v5);
}
while ( pthread_cond_destroy((pthread_cond_t *)ptr + 1) == 16 )
{
v5[0].tv_sec = 0LL;
v5[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v5);
}
free(ptr);
result = 1LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
CloseEvent(xpevent_t event)
{
 if (event==((void *)0) || (event->magic != ((u_int32_t) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 if (event->nwaiters > 0) {
  pthread_mutex_unlock(&event->lock);
  (*__errno_location ()) = 16;
  return(0);
 }
 pthread_mutex_unlock(&event->lock);
 while(pthread_mutex_destroy(&event->lock)==16)
  ({ int sleep_msecs=1; 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); });
 while(pthread_cond_destroy(&event->gtzero)==16)
  ({ int sleep_msecs=1; 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); });
 event->magic = 0;
 free(event);
 return(1);
}

canonical_original_code:
int CloseEvent(struct xpevent *event)
{
 if (event==((void *)0) || (event->magic != ((unsigned int) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 if (event->nwaiters > 0) {
  pthread_mutex_unlock(&event->lock);
  (*__errno_location ()) = 16;
  return(0);
 }
 pthread_mutex_unlock(&event->lock);
 while(pthread_mutex_destroy(&event->lock)==16)
  ({ int sleep_msecs = 1; 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); });
 while(pthread_cond_destroy(&event->gtzero)==16)
  ({ int sleep_msecs = 1; 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); });
 event->magic = 0;
 free(event);
 return(1);
}

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


WaitForEvent

decompiled_code:
__int64 __fastcall WaitForEvent(__int64 a1, __int64 a2)
{
__int64 v3; // rax
pthread_cond_t *v4; // rdi
__int64 v5; // r12
int v6; // edx
int v8; // eax
struct timespec v9; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

if ( !a1 || *(_DWORD *)a1 != 167395348 )
{
*_errno_location() = 22;
return 2LL;
}
if ( (unsigned __int64)(a2 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
{
gettimeofday(&tv, 0LL);
v9.tv_sec = tv.tv_sec + (a2 + tv.tv_usec / 1000) / 0x3E8uLL;
v9.tv_nsec = (1000000 * a2 + 1000 * tv.tv_usec) % 0x3B9ACA00uLL;
}
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( *(_DWORD *)(a1 + 96) )
{
v5 = 2LL;
goto LABEL_15;
}
v3 = *(_QWORD *)(a1 + 104);
while ( 1 )
{
*(_QWORD *)(a1 + 104) = v3 + 1;
if ( !a2 )
goto LABEL_14;
v4 = (pthread_cond_t *)(a1 + 48);
if ( a2 != -1 )
break;
v5 = pthread_cond_wait(v4, (pthread_mutex_t *)(a1 + 8));
LABEL_10:
v6 = *(_DWORD *)(a1 + 96);
v3 = *(_QWORD *)(a1 + 104) - 1LL;
*(_QWORD *)(a1 + 104) = v3;
if ( v6 )
{
if ( !v5 && !*(_DWORD *)(a1 + 100) )
*(_DWORD *)(a1 + 96) = 0;
goto LABEL_15;
}
}
v8 = pthread_cond_timedwait(v4, (pthread_mutex_t *)(a1 + 8), &v9);
v5 = v8;
if ( !v8 )
goto LABEL_10;
if ( v8 == 110LL )
{
LABEL_14:
v5 = 1LL;
goto LABEL_15;
}
*_errno_location() = v8;
v5 = 2LL;
LABEL_15:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v3; // rax
pthread_cond_t *v4; // rdi
__int64 v5; // r12
int v6; // edx
int v8; // eax
struct timespec v9; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

if ( !a1 || *(_DWORD *)a1 != 167395348 )
{
*_errno_location() = 22;
return 2LL;
}
if ( (unsigned __int64)(a2 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
{
gettimeofday(&tv, 0LL);
v9.tv_sec = tv.tv_sec + (a2 + tv.tv_usec / 1000) / 0x3E8uLL;
v9.tv_nsec = (1000000 * a2 + 1000 * tv.tv_usec) % 0x3B9ACA00uLL;
}
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( *(_DWORD *)(a1 + 96) )
{
v5 = 2LL;
goto LABEL_15;
}
v3 = *(_QWORD *)(a1 + 104);
while ( 1 )
{
*(_QWORD *)(a1 + 104) = v3 + 1;
if ( !a2 )
goto LABEL_14;
v4 = (pthread_cond_t *)(a1 + 48);
if ( a2 != -1 )
break;
v5 = pthread_cond_wait(v4, (pthread_mutex_t *)(a1 + 8));
LABEL_10:
v6 = *(_DWORD *)(a1 + 96);
v3 = *(_QWORD *)(a1 + 104) - 1LL;
*(_QWORD *)(a1 + 104) = v3;
if ( v6 )
{
if ( !v5 && !*(_DWORD *)(a1 + 100) )
*(_DWORD *)(a1 + 96) = 0;
goto LABEL_15;
}
}
v8 = pthread_cond_timedwait(v4, (pthread_mutex_t *)(a1 + 8), &v9);
v5 = v8;
if ( !v8 )
goto LABEL_10;
if ( v8 == 110LL )
{
LABEL_14:
v5 = 1LL;
goto LABEL_15;
}
*_errno_location() = v8;
v5 = 2LL;
LABEL_15:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v5;
}

original_code:
ulong
WaitForEvent(xpevent_t event, ulong ms)
{
 ulong retval=WAIT_FAILED;
 struct timespec abstime;
 struct timeval currtime;
 if (event==((void *)0) || (event->magic != ((u_int32_t) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(WAIT_FAILED);
 }
 if(ms && ms!=((ulong)(-1))) {
  gettimeofday(&currtime,((void *)0));
  abstime.tv_sec=currtime.tv_sec + (currtime.tv_usec/1000 + ms)/1000;
  abstime.tv_nsec=(currtime.tv_usec*1000 + ms*1000000)%1000000000;
 }
 pthread_mutex_lock(&event->lock);
 while (!(event->value)) {
  event->nwaiters++;
  switch(ms) {
   case 0:
    if(event->value)
     retval=0;
    else
     retval=WAIT_TIMEOUT;
    goto DONE;
    break;
   case ((ulong)(-1)):
    retval=pthread_cond_wait(&event->gtzero, &event->lock);
    break;
   default:
    retval=pthread_cond_timedwait(&event->gtzero, &event->lock, &abstime);
    if(retval) {
     if(retval==110)
      retval=WAIT_TIMEOUT;
     else {
      (*__errno_location ())=retval;
      retval=WAIT_FAILED;
     }
     goto DONE;
    }
  }
  event->nwaiters--;
 }
  DONE:
 if(retval==0) {
  retval=WAIT_OBJECT_0;
  if(!event->mreset)
   event->value=0;
 }
 pthread_mutex_unlock(&event->lock);
 return retval;
}

canonical_original_code:
unsigned long WaitForEvent(struct xpevent *event, unsigned long ms)
{
 unsigned long retval = WAIT_FAILED;
 struct timespec abstime;
 struct timeval currtime;
 if (event==((void *)0) || (event->magic != ((unsigned int) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(WAIT_FAILED);
 }
 if(ms && ms!=((ulong)(-1))) {
  gettimeofday(&currtime,((void *)0));
  abstime.tv_sec=currtime.tv_sec + (currtime.tv_usec/1000 + ms)/1000;
  abstime.tv_nsec=(currtime.tv_usec*1000 + ms*1000000)%1000000000;
 }
 pthread_mutex_lock(&event->lock);
 while (!(event->value)) {
  event->nwaiters++;
  switch(ms) {
   case 0:
    if(event->value)
     retval=0;
    else
     retval=WAIT_TIMEOUT;
    goto DONE;
    break;
   case ((ulong)(-1)):
    retval=pthread_cond_wait(&event->gtzero, &event->lock);
    break;
   default:
    retval=pthread_cond_timedwait(&event->gtzero, &event->lock, &abstime);
    if(retval) {
     if(retval==110)
      retval=WAIT_TIMEOUT;
     else {
      (*__errno_location ())=retval;
      retval=WAIT_FAILED;
     }
     goto DONE;
    }
  }
  event->nwaiters--;
 }
  DONE:
 if(retval==0) {
  retval=WAIT_OBJECT_0;
  if(!event->mreset)
   event->value=0;
 }
 pthread_mutex_unlock(&event->lock);
 return retval;
}

variable_types:
ms
unsigned long

variable_types:
retval
unsigned long

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

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


ftouch

decompiled_code:
__int64 __fastcall ftouch(__int64 a1)
{
int v1; // edi
__int64 result; // rax

v1 = nopen(a1, 65);
result = 0LL;
if ( v1 >= 0 )
{
close(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // edi
__int64 result; // rax

v1 = func0(a1, 65);
result = 0LL;
if ( v1 >= 0 )
{
close(v1);
result = 1LL;
}
return result;
}

original_code:
int ftouch(const char* fname)
{
 int file;
 if((file=nopen(fname,01|0100))<0)
  return(0);
 close(file);
 return(1);
}

canonical_original_code:
int ftouch(char *fname)
{
 int file;
 if((file=nopen(fname,01|0100))<0)
  return(0);
 close(file);
 return(1);
}

variable_types:
fname
char *

variable_types: file int


fmutex

decompiled_code:
__int64 __fastcall fmutex(char *filename, void *buf, time_t a3)
{
const char *v3; // rbp
__int64 v5; // r13
int v6; // er12
size_t v7; // rax
char v9[168]; // [rsp+0h] [rbp-A8h] BYREF

v3 = (const char *)buf;
if ( !buf && !gethostname(v9, 0x80uLL) )
v3 = v9;
if ( a3 )
{
v5 = fdate(filename);
if ( v5 >= 0 && time(0LL) - v5 > a3 && remove(filename) )
return 0LL;
}
v6 = open(filename, 193, 384LL);
if ( v6 < 0 )
return 0LL;
if ( v3 )
{
v7 = strlen(v3);
write(v6, v3, v7);
}
close(v6);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *filename, void *buf, time_t a3)
{
const char *v3; // rbp
__int64 v5; // r13
int v6; // er12
size_t v7; // rax
char v9[168]; // [rsp+0h] [rbp-A8h] BYREF

v3 = (const char *)buf;
if ( !buf && !gethostname(v9, 0x80uLL) )
v3 = v9;
if ( a3 )
{
v5 = fdate(filename);
if ( v5 >= 0 && time(0LL) - v5 > a3 && remove(filename) )
return 0LL;
}
v6 = open(filename, 193, 384LL);
if ( v6 < 0 )
return 0LL;
if ( v3 )
{
v7 = strlen(v3);
write(v6, v3, v7);
}
close(v6);
return 1LL;
}

original_code:
int fmutex(const char* fname, const char* text, long max_age)
{
 int file;
 long t;
 char hostname[128];
 if(text==((void *)0) && gethostname(hostname,sizeof(hostname))==0)
  text=hostname;
 if(max_age && (t=fdate(fname)) >= 0 && (time(((void *)0))-t) > max_age) {
  if(remove(fname)!=0)
   return(0);
 }
 if((file=open(fname,0100|01|0200,0400|0200))<0)
  return(0);
 if(text!=((void *)0))
  write(file,text,strlen(text));
 close(file);
 return(1);
}

canonical_original_code:
int fmutex(char *fname, char *text, long max_age)
{
 int file;
 long t;
 char hostname[128];
 if(text==((void *)0) && gethostname(hostname,sizeof(hostname))==0)
  text=hostname;
 if(max_age && (t=fdate(fname)) >= 0 && (time(((void *)0))-t) > max_age) {
  if(remove(fname)!=0)
   return(0);
 }
 if((file=open(fname,0100|01|0200,0400|0200))<0)
  return(0);
 if(text!=((void *)0))
  write(file,text,strlen(text));
 close(file);
 return(1);
}

variable_types:
text
char *

variable_types: t long

variable_types:
hostname
char [128]


decompiled_code:
__int64 __fastcall find_vmode(int a1)
{
__int64 result; // rax

result = 0LL;
while ( vparams[8 * result] != a1 )
{
if ( ++result == 36 )
return 0xFFFFFFFFLL;
}
return result;
}

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

result = 0LL;
while ( vparams[8 * result] != a1 )
{
if ( ++result == 36 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int find_vmode(int mode)
{
    unsigned i;
 for (i = 0; i < (sizeof(vparams) / sizeof(struct video_params)); i++)
  if (vparams[i].mode == mode)
   return i;
 return -1;
}

canonical_original_code:
int find_vmode(int mode)
{
    unsigned int i;
 for (i = 0; i < (sizeof(vparams) / sizeof(struct video_params)); i++)
  if (vparams[i].mode == mode)
   return i;
 return -1;
}

variable_types: mode int

variable_types:
i
unsigned int

user_defined_types: struct video_params { int mode; int palette; int cols; int rows; int curs_start; int curs_end; int charheight; int charwidth; }


original_code:
int load_vmode(struct video_stats *vs, int mode)
{
 int i;
 unsigned short *newvmem;
 i=find_vmode(mode);
 if(i==-1)
  return(-1);
 newvmem=(unsigned short *)realloc(vs->vmem, vparams[i].cols*vparams[i].rows*sizeof(unsigned short));
 if(newvmem==((void *)0))
  return(-1);
 vs->vmem=newvmem;
 vs->rows=vparams[i].rows;
 vs->cols=vparams[i].cols;
 vs->curs_start=vparams[i].curs_start;
 vs->curs_end=vparams[i].curs_end;
 vs->default_curs_start=vparams[i].curs_start;
 vs->default_curs_end=vparams[i].curs_end;
 if(vs->curs_row < 0)
  vs->curs_row=0;
 if(vs->curs_row >= vparams[i].rows)
  vs->curs_row=vparams[i].rows-1;
 if(vs->curs_col < 0)
  vs->curs_col=0;
 if(vs->curs_col >= vparams[i].cols)
  vs->curs_col=vparams[i].cols-1;
 vs->palette=palettes[vparams[i].palette];
 vs->charheight=vparams[i].charheight;
 vs->charwidth=vparams[i].charwidth;
 vs->mode=mode;
 return(0);
}

variable_types: struct video_stats { int rows; int cols; int curs_row; int curs_col; int curs_start; int curs_end; int default_curs_start; int default_curs_end; int mode; int charheight; int charwidth; int blink; int currattr; int scaling; unsigned char *palette; unsigned short *vmem; } *

variable_types: i int

variable_types:
newvmem
unsigned short *