decompiled_code:
const char *__fastcall smb_hfieldtype(unsigned __int16 a1)
{
const char *result; // rax

switch ( a1 )
{
case 0u:
result = "Sender";
break;
case 1u:
result = "SenderAgent";
break;
case 2u:
result = "SenderNetType";
break;
case 3u:
result = "SenderNetAddr";
break;
case 4u:
result = "SenderExt";
break;
case 6u:
result = "SenderOrg";
break;
case 7u:
result = "SenderIpAddr";
break;
case 8u:
result = "SenderHostName";
break;
case 9u:
result = "SenderProtocol";
break;
case 0xAu:
result = "SenderPort";
break;
case 0x20u:
result = "ReplyTo";
break;
case 0x21u:
result = "ReplyToAgent";
break;
case 0x22u:
result = "ReplyToNetType";
break;
case 0x23u:
result = "ReplyToNetAddr";
break;
case 0x24u:
result = "ReplyToExt";
break;
case 0x30u:
result = "Recipient";
break;
case 0x31u:
result = "RecipientAgent";
break;
case 0x32u:
result = "RecipientNetType";
break;
case 0x33u:
result = "RecipientNetAddr";
break;
case 0x34u:
result = "RecipientExt";
break;
case 0x60u:
result = "Subject";
break;
case 0x61u:
result = "Summary";
break;
case 0x62u:
result = "Comment";
break;
case 0x63u:
result = "CarbonCopy";
break;
case 0x64u:
result = "Group";
break;
case 0x65u:
result = "Expiration";
break;
case 0x66u:
result = "Priority";
break;
case 0x67u:
result = "Cost";
break;
case 0xA0u:
result = "FidoCtrl";
break;
case 0xA1u:
result = "FidoArea";
break;
case 0xA2u:
result = "FidoSeenBy";
break;
case 0xA3u:
result = "FidoPath";
break;
case 0xA4u:
result = "FidoMsgID";
break;
case 0xA5u:
result = "FidoReplyID";
break;
case 0xA6u:
result = "FidoPID";
break;
case 0xA7u:
result = "FidoFlags";
break;
case 0xA8u:
result = "FidoTID";
break;
case 0xB0u:
result = "RFC822Header";
break;
case 0xB1u:
result = "RFC822MsgID";
break;
case 0xB2u:
result = "RFC822ReplyID";
break;
case 0xB3u:
result = "RFC822To";
break;
case 0xB4u:
result = "RFC822From";
break;
case 0xB5u:
result = "RFC822ReplyTo";
break;
case 0xC0u:
result = "UsenetPath";
break;
case 0xC1u:
result = "UsenetNewsgroups";
break;
case 0xD0u:
result = "SMTPCommand";
break;
case 0xD1u:
result = "SMTPReversePath";
break;
case 0xD2u:
result = "SMTPForwardPath";
break;
case 0xD8u:
result = "SMTPSysMsg";
break;
case 0xF1u:
result = "UNKNOWN";
break;
case 0xF2u:
result = "UNKNOWNASCII";
break;
case 0xFFu:
result = "UNUSED";
break;
default:
sprintf(str_4, "%02Xh", a1);
result = str_4;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(unsigned __int16 a1)
{
const char *result; // rax

switch ( a1 )
{
case 0u:
result = "Sender";
break;
case 1u:
result = "SenderAgent";
break;
case 2u:
result = "SenderNetType";
break;
case 3u:
result = "SenderNetAddr";
break;
case 4u:
result = "SenderExt";
break;
case 6u:
result = "SenderOrg";
break;
case 7u:
result = "SenderIpAddr";
break;
case 8u:
result = "SenderHostName";
break;
case 9u:
result = "SenderProtocol";
break;
case 0xAu:
result = "SenderPort";
break;
case 0x20u:
result = "ReplyTo";
break;
case 0x21u:
result = "ReplyToAgent";
break;
case 0x22u:
result = "ReplyToNetType";
break;
case 0x23u:
result = "ReplyToNetAddr";
break;
case 0x24u:
result = "ReplyToExt";
break;
case 0x30u:
result = "Recipient";
break;
case 0x31u:
result = "RecipientAgent";
break;
case 0x32u:
result = "RecipientNetType";
break;
case 0x33u:
result = "RecipientNetAddr";
break;
case 0x34u:
result = "RecipientExt";
break;
case 0x60u:
result = "Subject";
break;
case 0x61u:
result = "Summary";
break;
case 0x62u:
result = "Comment";
break;
case 0x63u:
result = "CarbonCopy";
break;
case 0x64u:
result = "Group";
break;
case 0x65u:
result = "Expiration";
break;
case 0x66u:
result = "Priority";
break;
case 0x67u:
result = "Cost";
break;
case 0xA0u:
result = "FidoCtrl";
break;
case 0xA1u:
result = "FidoArea";
break;
case 0xA2u:
result = "FidoSeenBy";
break;
case 0xA3u:
result = "FidoPath";
break;
case 0xA4u:
result = "FidoMsgID";
break;
case 0xA5u:
result = "FidoReplyID";
break;
case 0xA6u:
result = "FidoPID";
break;
case 0xA7u:
result = "FidoFlags";
break;
case 0xA8u:
result = "FidoTID";
break;
case 0xB0u:
result = "RFC822Header";
break;
case 0xB1u:
result = "RFC822MsgID";
break;
case 0xB2u:
result = "RFC822ReplyID";
break;
case 0xB3u:
result = "RFC822To";
break;
case 0xB4u:
result = "RFC822From";
break;
case 0xB5u:
result = "RFC822ReplyTo";
break;
case 0xC0u:
result = "UsenetPath";
break;
case 0xC1u:
result = "UsenetNewsgroups";
break;
case 0xD0u:
result = "SMTPCommand";
break;
case 0xD1u:
result = "SMTPReversePath";
break;
case 0xD2u:
result = "SMTPForwardPath";
break;
case 0xD8u:
result = "SMTPSysMsg";
break;
case 0xF1u:
result = "UNKNOWN";
break;
case 0xF2u:
result = "UNKNOWNASCII";
break;
case 0xFFu:
result = "UNUSED";
break;
default:
sprintf(str_4, "%02Xh", a1);
result = str_4;
break;
}
return result;
}

original_code:
char* smb_hfieldtype(ushort type)
{
 static char str[8];
 switch(type) {
  case 0x00: return("Sender");
  case 0x01: return("SenderAgent");
  case 0x02: return("SenderNetType");
  case 0x03: return("SenderNetAddr");
  case 0x04: return("SenderExt");
  case 0x06: return("SenderOrg");
  case 0x07: return("SenderIpAddr");
  case 0x08: return("SenderHostName");
  case 0x09: return("SenderProtocol");
  case 0x0a: return("SenderPort");
  case 0x20: return("ReplyTo");
  case 0x21: return("ReplyToAgent");
  case 0x22: return("ReplyToNetType");
  case 0x23: return("ReplyToNetAddr");
  case 0x24: return("ReplyToExt");
  case 0x30: return("Recipient");
  case 0x31: return("RecipientAgent");
  case 0x32: return("RecipientNetType");
  case 0x33: return("RecipientNetAddr");
  case 0x34: return("RecipientExt");
  case 0x60: return("Subject");
  case 0x61: return("Summary");
  case 0x62: return("Comment");
  case 0x63: return("CarbonCopy");
  case 0x64: return("Group");
  case 0x65: return("Expiration");
  case 0x66: return("Priority");
  case 0x67: return("Cost");
  case 0xa0: return("FidoCtrl");
  case 0xa1: return("FidoArea");
  case 0xa2: return("FidoSeenBy");
  case 0xa3: return("FidoPath");
  case 0xa4: return("FidoMsgID");
  case 0xa5: return("FidoReplyID");
  case 0xa6: return("FidoPID");
  case 0xa7: return("FidoFlags");
  case 0xa8: return("FidoTID");
  case 0xb0: return("RFC822Header");
  case 0xb1: return("RFC822MsgID");
  case 0xb2: return("RFC822ReplyID");
  case 0xb3: return("RFC822To");
  case 0xb4: return("RFC822From");
  case 0xb5: return("RFC822ReplyTo");
  case 0xc0: return("UsenetPath");
  case 0xc1: return("UsenetNewsgroups");
  case 0xd0: return("SMTPCommand");
  case 0xd1: return("SMTPReversePath");
  case 0xd2: return("SMTPForwardPath");
  case 0xd8: return("SMTPSysMsg");
  case 0xf1: return("UNKNOWN");
  case 0xf2: return("UNKNOWNASCII");
  case 0xff: return("UNUSED");
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

canonical_original_code:
char *smb_hfieldtype(unsigned short type)
{
 static char str[8];
 switch(type) {
  case 0x00: return("Sender");
  case 0x01: return("SenderAgent");
  case 0x02: return("SenderNetType");
  case 0x03: return("SenderNetAddr");
  case 0x04: return("SenderExt");
  case 0x06: return("SenderOrg");
  case 0x07: return("SenderIpAddr");
  case 0x08: return("SenderHostName");
  case 0x09: return("SenderProtocol");
  case 0x0a: return("SenderPort");
  case 0x20: return("ReplyTo");
  case 0x21: return("ReplyToAgent");
  case 0x22: return("ReplyToNetType");
  case 0x23: return("ReplyToNetAddr");
  case 0x24: return("ReplyToExt");
  case 0x30: return("Recipient");
  case 0x31: return("RecipientAgent");
  case 0x32: return("RecipientNetType");
  case 0x33: return("RecipientNetAddr");
  case 0x34: return("RecipientExt");
  case 0x60: return("Subject");
  case 0x61: return("Summary");
  case 0x62: return("Comment");
  case 0x63: return("CarbonCopy");
  case 0x64: return("Group");
  case 0x65: return("Expiration");
  case 0x66: return("Priority");
  case 0x67: return("Cost");
  case 0xa0: return("FidoCtrl");
  case 0xa1: return("FidoArea");
  case 0xa2: return("FidoSeenBy");
  case 0xa3: return("FidoPath");
  case 0xa4: return("FidoMsgID");
  case 0xa5: return("FidoReplyID");
  case 0xa6: return("FidoPID");
  case 0xa7: return("FidoFlags");
  case 0xa8: return("FidoTID");
  case 0xb0: return("RFC822Header");
  case 0xb1: return("RFC822MsgID");
  case 0xb2: return("RFC822ReplyID");
  case 0xb3: return("RFC822To");
  case 0xb4: return("RFC822From");
  case 0xb5: return("RFC822ReplyTo");
  case 0xc0: return("UsenetPath");
  case 0xc1: return("UsenetNewsgroups");
  case 0xd0: return("SMTPCommand");
  case 0xd1: return("SMTPReversePath");
  case 0xd2: return("SMTPForwardPath");
  case 0xd8: return("SMTPSysMsg");
  case 0xf1: return("UNKNOWN");
  case 0xf2: return("UNKNOWNASCII");
  case 0xff: return("UNUSED");
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

variable_types:
type
unsigned short

variable_types:
str
char [8]


repo: ftnapps/pkg-sbbs

decompiled_code:
__int64 __fastcall smb_hfieldtypelookup(char *nptr)
{
unsigned int v1; // ebx
unsigned int v2; // er12
const char *v3; // rax

v1 = 0;
if ( ((*_ctype_b_loc())[*nptr] & 0x800) != 0 )
return (unsigned int)strtol(nptr, 0LL, 0);
while ( 1 )
{
v2 = v1;
v3 = smb_hfieldtype(v1);
if ( !strcasecmp(nptr, v3) )
break;
if ( ++v1 == 256 )
return 241;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *nptr)
{
unsigned int v1; // ebx
unsigned int v2; // er12
const char *v3; // rax

v1 = 0;
if ( ((*_ctype_b_loc())[*nptr] & 0x800) != 0 )
return (unsigned int)strtol(nptr, 0LL, 0);
while ( 1 )
{
v2 = v1;
v3 = func0(v1);
if ( !strcasecmp(nptr, v3) )
break;
if ( ++v1 == 256 )
return 241;
}
return v2;
}

original_code:
ushort smb_hfieldtypelookup(const char* str)
{
 ushort type;
 if(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISdigit))
  return((ushort)strtol(str,((void *)0),0));
 for(type=0;type<=0xff;type++)
  if(strcasecmp(str,smb_hfieldtype(type))==0)
   return(type);
 return(0xf1);
}

canonical_original_code:
unsigned short smb_hfieldtypelookup(char *str)
{
 unsigned short type;
 if(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISdigit))
  return((unsigned short)strtol(str,((void *)0),0));
 for(type=0;type<=0xff;type++)
  if(strcasecmp(str,smb_hfieldtype(type))==0)
   return(type);
 return(0xf1);
}

variable_types:
str
char *

return_type: unsigned short


decompiled_code:
const char *__fastcall smb_dfieldtype(unsigned __int16 a1)
{
const char *result; // rax

result = "TEXT_TAIL";
if ( a1 != 2 )
{
result = "UNUSED";
if ( a1 != 255 )
{
result = "TEXT_BODY";
if ( a1 )
{
sprintf(str_3, "%02Xh", a1);
result = str_3;
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned __int16 a1)
{
const char *result; // rax

result = "TEXT_TAIL";
if ( a1 != 2 )
{
result = "UNUSED";
if ( a1 != 255 )
{
result = "TEXT_BODY";
if ( a1 )
{
sprintf(str_3, "%02Xh", a1);
result = str_3;
}
}
}
return result;
}

original_code:
char* smb_dfieldtype(ushort type)
{
 static char str[8];
 switch(type) {
  case 0x00: return("TEXT_BODY");
  case 0x02: return("TEXT_TAIL");
  case 0xff: return("UNUSED");
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

canonical_original_code:
char *smb_dfieldtype(unsigned short type)
{
 static char str[8];
 switch(type) {
  case 0x00: return("TEXT_BODY");
  case 0x02: return("TEXT_TAIL");
  case 0xff: return("UNUSED");
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

return_type: char *


decompiled_code:
char *__fastcall smb_hashsourcetype(unsigned __int8 a1)
{
switch ( a1 )
{
case 1u:
return (char *)smb_hfieldtype(0xB1u);
case 2u:
return (char *)smb_hfieldtype(0xA4u);
case 0u:
return (char *)smb_dfieldtype(0);
}
sprintf(str_2, "%02Xh", a1);
return str_2;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned __int8 a1)
{
switch ( a1 )
{
case 1u:
return (char *)func0(0xB1u);
case 2u:
return (char *)func0(0xA4u);
case 0u:
return (char *)func2(0);
}
sprintf(str_2, "%02Xh", a1);
return str_2;
}

original_code:
char* smb_hashsourcetype(unsigned char type)
{
 static char str[8];
 switch(type) {
  case SMB_HASH_SOURCE_BODY: return(smb_dfieldtype(0x00));
  case SMB_HASH_SOURCE_MSG_ID: return(smb_hfieldtype(0xb1));
  case SMB_HASH_SOURCE_FTN_ID: return(smb_hfieldtype(0xa4));
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

canonical_original_code:
char *smb_hashsourcetype(unsigned char type)
{
 static char str[8];
 switch(type) {
  case SMB_HASH_SOURCE_BODY: return(smb_dfieldtype(0x00));
  case SMB_HASH_SOURCE_MSG_ID: return(smb_hfieldtype(0xb1));
  case SMB_HASH_SOURCE_FTN_ID: return(smb_hfieldtype(0xa4));
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

variable_types:
type
unsigned char


decompiled_code:
const char *__fastcall smb_hashsource(__int64 a1, int a2)
{
if ( a2 == 1 )
return *(const char **)(a1 + 208);
if ( a2 == 2 )
return *(const char **)(a1 + 288);
return "hash";
}

canonical_decompiled_code:
const char *__fastcall func4(__int64 a1, int a2)
{
if ( a2 == 1 )
return *(const char **)(a1 + 208);
if ( a2 == 2 )
return *(const char **)(a1 + 288);
return "hash";
}

original_code:
char* smb_hashsource(smbmsg_t* msg, int source)
{
 switch(source) {
  case SMB_HASH_SOURCE_MSG_ID:
   return(msg->id);
  case SMB_HASH_SOURCE_FTN_ID:
   return(msg->ftn_msgid);
 }
 return("hash");
}

canonical_original_code:
char *smb_hashsource(struct smbmsg_t *msg, int source)
{
 switch(source) {
  case SMB_HASH_SOURCE_MSG_ID:
   return(msg->id);
  case SMB_HASH_SOURCE_FTN_ID:
   return(msg->ftn_msgid);
 }
 return("hash");
}

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

variable_types: source int

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

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


decompiled_code:
char *__fastcall smb_zonestr(int a1, char *a2)
{
int v2; // edx
char *result; // rax
const char *v4; // rax
__int64 v5; // r8

if ( (_WORD)a1 == 8492 )
return "BOG";
LOWORD(v2) = a1;
if ( (unsigned __int16)a1 > 0x212Cu )
{
if ( (_WORD)a1 == 16984 )
return "HST";
if ( (unsigned __int16)a1 <= 0x4258u )
{
if ( (_WORD)a1 == 16684 )
return "EST";
if ( (unsigned __int16)a1 <= 0x412Cu )
{
if ( (_WORD)a1 == 8672 )
return "VAN";
if ( (unsigned __int16)a1 <= 0x21E0u )
{
result = "WIN";
if ( (_WORD)a1 == 8552 )
return result;
if ( (_WORD)a1 == 8612 )
return "EDM";
}
else
{
result = "MID";
if ( (_WORD)a1 == 8852 )
return result;
if ( (_WORD)a1 == 16624 )
return "AST";
}
}
else
{
result = "PST";
if ( (_WORD)a1 == 16864 )
return result;
if ( (unsigned __int16)a1 <= 0x41E0u )
{
result = "CST";
if ( (_WORD)a1 == 16744 )
return result;
if ( (_WORD)a1 == 16804 )
return "MST";
}
else
{
result = "YST";
if ( (_WORD)a1 == 16924 )
return result;
}
}
}
else
{
if ( (_WORD)a1 == 0xC1A4 )
return "MDT";
if ( (unsigned __int16)a1 <= 0xC1A4u )
{
result = "EDT";
if ( (_WORD)a1 == 0xC12C )
return result;
if ( (unsigned __int16)a1 <= 0xC12Cu )
{
result = "BST";
if ( (_WORD)a1 == 17044 )
return result;
if ( (_WORD)a1 == 0xC0F0 )
return "ADT";
}
else
{
result = "CDT";
if ( (_WORD)a1 == 0xC168 )
return result;
}
}
else
{
result = "HDT";
if ( (_WORD)a1 == 0xC258 )
return result;
if ( (unsigned __int16)a1 > 0xC258u )
{
result = "BDT";
if ( (_WORD)a1 == 0xC294 )
return result;
if ( (unsigned __int16)(a1 + 1000) > 0x7D0u )
{
LABEL_84:
LOWORD(a1) = a1 & 0xFFF;
v2 = -a1;
v4 = (const char *)&unk_C86;
goto LABEL_55;
}
goto LABEL_53;
}
result = "PDT";
if ( (_WORD)a1 == 0xC1E0 )
return result;
if ( (_WORD)a1 == 0xC21C )
return "YDT";
}
}
LABEL_16:
if ( (a1 & 0x6000) == 0 )
{
LABEL_17:
LOWORD(v2) = a1 & 0xFFF;
v4 = (const char *)&unk_C86;
if ( (a1 & 0xFFF) != 0 )
v4 = "+";
goto LABEL_19;
}
goto LABEL_84;
}
if ( (_WORD)a1 == 4456 )
return "DHA";
if ( (unsigned __int16)a1 > 0x1168u )
{
if ( (_WORD)a1 == 4816 )
return "WEL";
if ( (unsigned __int16)a1 <= 0x12D0u )
{
if ( (_WORD)a1 == 4636 )
return "TOK";
if ( (unsigned __int16)a1 <= 0x121Cu )
{
result = "BAN";
if ( (_WORD)a1 == 4516 )
return result;
if ( (_WORD)a1 == 4576 )
return "HON";
}
else
{
result = "SYD";
if ( (_WORD)a1 == 4696 )
return result;
if ( (_WORD)a1 == 4756 )
return "NOU";
}
}
else
{
result = "RIO";
if ( (_WORD)a1 == 8372 )
return result;
if ( (unsigned __int16)a1 <= 0x20B4u )
{
result = "AZO";
if ( (_WORD)a1 == 8252 )
return result;
if ( (_WORD)a1 == 8312 )
return "FER";
}
else
{
result = "CAR";
if ( (_WORD)a1 == 8432 )
return result;
}
}
goto LABEL_16;
}
if ( (_WORD)a1 == 4336 )
return "DUB";
if ( (unsigned __int16)a1 > 0x10F0u )
{
result = "BOM";
if ( (_WORD)a1 == 4426 )
return result;
if ( (unsigned __int16)a1 <= 0x114Au )
{
result = "KAB";
if ( (_WORD)a1 == 4366 )
return result;
if ( (_WORD)a1 == 4396 )
return "KAR";
}
else
{
result = "KAT";
if ( (_WORD)a1 == 4441 )
return result;
}
goto LABEL_16;
}
if ( (_WORD)a1 == 4156 )
return "BER";
if ( (unsigned __int16)a1 > 0x103Cu )
{
result = "ATH";
if ( (_WORD)a1 == 4216 )
return result;
if ( (_WORD)a1 == 4276 )
return "MOS";
goto LABEL_16;
}
result = "UTC";
if ( !(_WORD)a1 )
return result;
if ( (_WORD)a1 == 4096 )
return "LON";
if ( (unsigned __int16)(a1 + 1000) > 0x7D0u )
goto LABEL_17;
LABEL_53:
v4 = "+";
if ( (__int16)a1 <= 0 )
v4 = (const char *)&unk_C86;
LABEL_55:
if ( (v2 & 0x8000u) == 0 )
{
LABEL_19:
v5 = (unsigned int)((__int16)v2 % 60);
goto LABEL_20;
}
v5 = (unsigned int)(-(__int16)v2 % 60);
LABEL_20:
sprintf(str_1, "UTC%s%d:%02u", v4, (unsigned int)((__int16)v2 / 60), v5);
result = str_1;
if ( a2 )
result = strcpy(a2, str_1);
return result;
}

canonical_decompiled_code:
char *__fastcall func5(int a1, char *a2)
{
int v2; // edx
char *result; // rax
const char *v4; // rax
__int64 v5; // r8

if ( (_WORD)a1 == 8492 )
return "BOG";
LOWORD(v2) = a1;
if ( (unsigned __int16)a1 > 0x212Cu )
{
if ( (_WORD)a1 == 16984 )
return "HST";
if ( (unsigned __int16)a1 <= 0x4258u )
{
if ( (_WORD)a1 == 16684 )
return "EST";
if ( (unsigned __int16)a1 <= 0x412Cu )
{
if ( (_WORD)a1 == 8672 )
return "VAN";
if ( (unsigned __int16)a1 <= 0x21E0u )
{
result = "WIN";
if ( (_WORD)a1 == 8552 )
return result;
if ( (_WORD)a1 == 8612 )
return "EDM";
}
else
{
result = "MID";
if ( (_WORD)a1 == 8852 )
return result;
if ( (_WORD)a1 == 16624 )
return "AST";
}
}
else
{
result = "PST";
if ( (_WORD)a1 == 16864 )
return result;
if ( (unsigned __int16)a1 <= 0x41E0u )
{
result = "CST";
if ( (_WORD)a1 == 16744 )
return result;
if ( (_WORD)a1 == 16804 )
return "MST";
}
else
{
result = "YST";
if ( (_WORD)a1 == 16924 )
return result;
}
}
}
else
{
if ( (_WORD)a1 == 0xC1A4 )
return "MDT";
if ( (unsigned __int16)a1 <= 0xC1A4u )
{
result = "EDT";
if ( (_WORD)a1 == 0xC12C )
return result;
if ( (unsigned __int16)a1 <= 0xC12Cu )
{
result = "BST";
if ( (_WORD)a1 == 17044 )
return result;
if ( (_WORD)a1 == 0xC0F0 )
return "ADT";
}
else
{
result = "CDT";
if ( (_WORD)a1 == 0xC168 )
return result;
}
}
else
{
result = "HDT";
if ( (_WORD)a1 == 0xC258 )
return result;
if ( (unsigned __int16)a1 > 0xC258u )
{
result = "BDT";
if ( (_WORD)a1 == 0xC294 )
return result;
if ( (unsigned __int16)(a1 + 1000) > 0x7D0u )
{
LABEL_84:
LOWORD(a1) = a1 & 0xFFF;
v2 = -a1;
v4 = (const char *)&unk_C86;
goto LABEL_55;
}
goto LABEL_53;
}
result = "PDT";
if ( (_WORD)a1 == 0xC1E0 )
return result;
if ( (_WORD)a1 == 0xC21C )
return "YDT";
}
}
LABEL_16:
if ( (a1 & 0x6000) == 0 )
{
LABEL_17:
LOWORD(v2) = a1 & 0xFFF;
v4 = (const char *)&unk_C86;
if ( (a1 & 0xFFF) != 0 )
v4 = "+";
goto LABEL_19;
}
goto LABEL_84;
}
if ( (_WORD)a1 == 4456 )
return "DHA";
if ( (unsigned __int16)a1 > 0x1168u )
{
if ( (_WORD)a1 == 4816 )
return "WEL";
if ( (unsigned __int16)a1 <= 0x12D0u )
{
if ( (_WORD)a1 == 4636 )
return "TOK";
if ( (unsigned __int16)a1 <= 0x121Cu )
{
result = "BAN";
if ( (_WORD)a1 == 4516 )
return result;
if ( (_WORD)a1 == 4576 )
return "HON";
}
else
{
result = "SYD";
if ( (_WORD)a1 == 4696 )
return result;
if ( (_WORD)a1 == 4756 )
return "NOU";
}
}
else
{
result = "RIO";
if ( (_WORD)a1 == 8372 )
return result;
if ( (unsigned __int16)a1 <= 0x20B4u )
{
result = "AZO";
if ( (_WORD)a1 == 8252 )
return result;
if ( (_WORD)a1 == 8312 )
return "FER";
}
else
{
result = "CAR";
if ( (_WORD)a1 == 8432 )
return result;
}
}
goto LABEL_16;
}
if ( (_WORD)a1 == 4336 )
return "DUB";
if ( (unsigned __int16)a1 > 0x10F0u )
{
result = "BOM";
if ( (_WORD)a1 == 4426 )
return result;
if ( (unsigned __int16)a1 <= 0x114Au )
{
result = "KAB";
if ( (_WORD)a1 == 4366 )
return result;
if ( (_WORD)a1 == 4396 )
return "KAR";
}
else
{
result = "KAT";
if ( (_WORD)a1 == 4441 )
return result;
}
goto LABEL_16;
}
if ( (_WORD)a1 == 4156 )
return "BER";
if ( (unsigned __int16)a1 > 0x103Cu )
{
result = "ATH";
if ( (_WORD)a1 == 4216 )
return result;
if ( (_WORD)a1 == 4276 )
return "MOS";
goto LABEL_16;
}
result = "UTC";
if ( !(_WORD)a1 )
return result;
if ( (_WORD)a1 == 4096 )
return "LON";
if ( (unsigned __int16)(a1 + 1000) > 0x7D0u )
goto LABEL_17;
LABEL_53:
v4 = "+";
if ( (__int16)a1 <= 0 )
v4 = (const char *)&unk_C86;
LABEL_55:
if ( (v2 & 0x8000u) == 0 )
{
LABEL_19:
v5 = (unsigned int)((__int16)v2 % 60);
goto LABEL_20;
}
v5 = (unsigned int)(-(__int16)v2 % 60);
LABEL_20:
sprintf(str_1, "UTC%s%d:%02u", v4, (unsigned int)((__int16)v2 / 60), v5);
result = str_1;
if ( a2 )
result = strcpy(a2, str_1);
return result;
}

original_code:
char* smb_zonestr(short zone, char* outstr)
{
 char* plus;
    static char str[32];
 switch((ushort)zone) {
  case 0: return("UTC");
  case 0x40F0: return("AST");
  case 0x412C: return("EST");
  case 0x4168: return("CST");
  case 0x41A4: return("MST");
  case 0x41E0: return("PST");
  case 0x421C: return("YST");
  case 0x4258: return("HST");
  case 0x4294: return("BST");
  case 0xC0F0: return("ADT");
  case 0xC12C: return("EDT");
  case 0xC168: return("CDT");
  case 0xC1A4: return("MDT");
  case 0xC1E0: return("PDT");
  case 0xC21C: return("YDT");
  case 0xC258: return("HDT");
  case 0xC294: return("BDT");
  case 0x2294: return("MID");
  case 0x21E0: return("VAN");
  case 0x21A4: return("EDM");
  case 0x2168: return("WIN");
  case 0x212C: return("BOG");
  case 0x20F0: return("CAR");
  case 0x20B4: return("RIO");
  case 0x2078: return("FER");
  case 0x203C: return("AZO");
  case 0x1000: return("LON");
  case 0x103C: return("BER");
  case 0x1078: return("ATH");
  case 0x10B4: return("MOS");
  case 0x10F0: return("DUB");
  case 0x110E: return("KAB");
  case 0x112C: return("KAR");
  case 0x114A: return("BOM");
  case 0x1159: return("KAT");
  case 0x1168: return("DHA");
  case 0x11A4: return("BAN");
  case 0x11E0: return("HON");
  case 0x121C: return("TOK");
  case 0x1258: return("SYD");
  case 0x1294: return("NOU");
  case 0x12D0: return("WEL");
  }
 if(!(zone<=1000 && zone>=-1000)) {
  if(zone&(0x2000|0x4000))
   zone=-(zone&0xfff);
  else
   zone&=0xfff;
 }
 if(zone>0)
  plus="+";
 else
  plus="";
 sprintf(str,"UTC%s%d:%02u", plus, zone/60, zone<0 ? (-zone)%60 : zone%60);
 if(outstr==((void *)0))
  return(str);
 strcpy(outstr,str);
 return(outstr);
}

canonical_original_code:
char *smb_zonestr(short zone, char *outstr)
{
 char *plus;
    static char str[32];
 switch((unsigned short)zone) {
  case 0: return("UTC");
  case 0x40F0: return("AST");
  case 0x412C: return("EST");
  case 0x4168: return("CST");
  case 0x41A4: return("MST");
  case 0x41E0: return("PST");
  case 0x421C: return("YST");
  case 0x4258: return("HST");
  case 0x4294: return("BST");
  case 0xC0F0: return("ADT");
  case 0xC12C: return("EDT");
  case 0xC168: return("CDT");
  case 0xC1A4: return("MDT");
  case 0xC1E0: return("PDT");
  case 0xC21C: return("YDT");
  case 0xC258: return("HDT");
  case 0xC294: return("BDT");
  case 0x2294: return("MID");
  case 0x21E0: return("VAN");
  case 0x21A4: return("EDM");
  case 0x2168: return("WIN");
  case 0x212C: return("BOG");
  case 0x20F0: return("CAR");
  case 0x20B4: return("RIO");
  case 0x2078: return("FER");
  case 0x203C: return("AZO");
  case 0x1000: return("LON");
  case 0x103C: return("BER");
  case 0x1078: return("ATH");
  case 0x10B4: return("MOS");
  case 0x10F0: return("DUB");
  case 0x110E: return("KAB");
  case 0x112C: return("KAR");
  case 0x114A: return("BOM");
  case 0x1159: return("KAT");
  case 0x1168: return("DHA");
  case 0x11A4: return("BAN");
  case 0x11E0: return("HON");
  case 0x121C: return("TOK");
  case 0x1258: return("SYD");
  case 0x1294: return("NOU");
  case 0x12D0: return("WEL");
  }
 if(!(zone<=1000 && zone>=-1000)) {
  if(zone&(0x2000|0x4000))
   zone=-(zone&0xfff);
  else
   zone&=0xfff;
 }
 if(zone>0)
  plus="+";
 else
  plus="";
 sprintf(str,"UTC%s%d:%02u", plus, zone/60, zone<0 ? (-zone)%60 : zone%60);
 if(outstr==((void *)0))
  return(str);
 strcpy(outstr,str);
 return(outstr);
}

variable_types: zone short

variable_types:
outstr
char *

variable_types:
plus
char *

variable_types:
str
char [32]


decompiled_code:
char *__fastcall smb_faddrtoa(unsigned __int16 *a1, char *a2)
{
char *result; // rax
unsigned __int16 v3; // dx
char v4[56]; // [rsp-38h] [rbp-38h] BYREF

result = "0:0/0";
if ( a1 )
{
sprintf(str_0, "%hu:%hu/%hu", *a1, a1[1], a1[2]);
v3 = a1[3];
if ( v3 )
{
sprintf(v4, ".%hu", v3);
strcat(str_0, v4);
}
result = str_0;
if ( a2 )
result = strcpy(a2, str_0);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned __int16 *a1, char *a2)
{
char *result; // rax
unsigned __int16 v3; // dx
char v4[56]; // [rsp-38h] [rbp-38h] BYREF

result = "0:0/0";
if ( a1 )
{
sprintf(str_0, "%hu:%hu/%hu", *a1, a1[1], a1[2]);
v3 = a1[3];
if ( v3 )
{
sprintf(v4, ".%hu", v3);
strcat(str_0, v4);
}
result = str_0;
if ( a2 )
result = strcpy(a2, str_0);
}
return result;
}

original_code:
char* smb_faddrtoa(fidoaddr_t* addr, char* outstr)
{
 static char str[64];
    char point[25];
 if(addr==((void *)0))
  return("0:0/0");
 sprintf(str,"%hu:%hu/%hu",addr->zone,addr->net,addr->node);
 if(addr->point) {
  sprintf(point,".%hu",addr->point);
  strcat(str,point);
 }
 if(outstr==((void *)0))
  return(str);
 strcpy(outstr,str);
 return(outstr);
}

canonical_original_code:
char *smb_faddrtoa(struct fidoaddr_t *addr, char *outstr)
{
 static char str[64];
    char point[25];
 if(addr==((void *)0))
  return("0:0/0");
 sprintf(str,"%hu:%hu/%hu",addr->zone,addr->net,addr->node);
 if(addr->point) {
  sprintf(point,".%hu",addr->point);
  strcat(str,point);
 }
 if(outstr==((void *)0))
  return(str);
 strcpy(outstr,str);
 return(outstr);
}

variable_types: struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; } *

variable_types:
str
char [64]

variable_types:
point
char [25]


original_code:
fidoaddr_t smb_atofaddr(const fidoaddr_t* sys_addr, const char *str)
{
 char *p;
 fidoaddr_t addr;
 fidoaddr_t tmp_addr={1,1,1,0};
 if(sys_addr==((void *)0))
  sys_addr=&tmp_addr;
 memset(&(addr),0,sizeof(addr));
 if((p=strchr(str,':'))!=((void *)0)) {
  addr.zone=atoi(str);
  addr.net=atoi(p+1);
 } else {
  addr.zone=sys_addr->zone;
  addr.net=atoi(str);
 }
 if(addr.zone==0)
  addr.zone=1;
 if((p=strchr(str,'/'))!=((void *)0))
  addr.node=atoi(p+1);
 else {
  if(addr.zone==sys_addr->zone)
   addr.net=sys_addr->net;
  addr.node=atoi(str);
 }
 if((p=strchr(str,'.'))!=((void *)0))
  addr.point=atoi(p+1);
 return(addr);
}

canonical_original_code:
struct fidoaddr_t smb_atofaddr(struct fidoaddr_t *sys_addr, char *str)
{
 char *p;
 struct fidoaddr_t addr;
 struct fidoaddr_t tmp_addr = {1,1,1,0};
 if(sys_addr==((void *)0))
  sys_addr=&tmp_addr;
 memset(&(addr),0,sizeof(addr));
 if((p=strchr(str,':'))!=((void *)0)) {
  addr.zone=atoi(str);
  addr.net=atoi(p+1);
 } else {
  addr.zone=sys_addr->zone;
  addr.net=atoi(str);
 }
 if(addr.zone==0)
  addr.zone=1;
 if((p=strchr(str,'/'))!=((void *)0))
  addr.node=atoi(p+1);
 else {
  if(addr.zone==sys_addr->zone)
   addr.net=sys_addr->net;
  addr.node=atoi(str);
 }
 if((p=strchr(str,'.'))!=((void *)0))
  addr.point=atoi(p+1);
 return(addr);
}

variable_types:
p
char *

variable_types: struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; }


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

if ( *(_WORD *)a1 == 2 )
result = smb_faddrtoa(*(unsigned __int16 **)(a1 + 8), 0LL);
else
result = *(char **)(a1 + 8);
return result;
}

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

if ( *(_WORD *)a1 == 2 )
result = func6(*(unsigned __int16 **)(a1 + 8), 0LL);
else
result = *(char **)(a1 + 8);
return result;
}

original_code:
char* smb_netaddr(net_t* net)
{
 if(net->type==NET_FIDO)
  return(smb_faddrtoa((fidoaddr_t*)net->addr,((void *)0)));
 return(net->addr);
}

canonical_original_code:
char *smb_netaddr(struct net_t *net)
{
 if(net->type==NET_FIDO)
  return(smb_faddrtoa((struct fidoaddr_t *)net->addr,((void *)0)));
 return(net->addr);
}

variable_types: struct net_t { unsigned short type; void *addr; } *

user_defined_types: struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; }


decompiled_code:
__int64 __fastcall smb_netaddr_type(const char *a1)
{
char *v1; // rax
const char *v2; // rbx
char v3; // bp
const unsigned __int16 *v4; // r13
unsigned __int16 v5; // r12
unsigned int v6; // edx
char v7; // al

v1 = strchr(a1, 64);
if ( !v1 )
return 0;
v2 = v1 + 1;
v3 = v1[1];
if ( !v3 )
return 1;
v4 = *_ctype_b_loc();
while ( 1 )
{
v5 = v4[v3];
if ( (v5 & 0x2000) == 0 )
break;
v3 = *++v2;
if ( !*v2 )
return 1;
}
if ( !v3 )
return 1;
if ( (v5 & 0x400) != 0 && !strchr(v2, 46) )
return 4;
v7 = *v2;
if ( !*v2 )
goto LABEL_11;
while ( (v4[v7] & 0x800) != 0 || v7 == 58 || (unsigned __int8)(v7 - 46) <= 1u )
{
v7 = *++v2;
if ( !*v2 )
goto LABEL_11;
}
if ( (v5 & 0x800) != 0 )
v6 = 2;
else
LABEL_11:
v6 = (v5 & 8) == 0 ? 1 : 5;
return v6;
}

original_code:
ushort smb_netaddr_type(const char* str)
{
 char* p;
 char* tp;
 if((p=strchr(str,'@'))==((void *)0))
  return(NET_NONE);
 p++;
 while(*(p) && ((*__ctype_b_loc ())[(int) ((*(p)))] & (unsigned short int) _ISspace)) (p)++;;
 if(*p==0)
  return(NET_UNKNOWN);
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) && strchr(p,'.')==((void *)0))
  return(NET_QWK);
 for(tp=p;*tp;tp++) {
  if(!((*__ctype_b_loc ())[(int) ((*tp))] & (unsigned short int) _ISdigit) && *tp!=':' && *tp!='/' && *tp!='.')
   break;
 }
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) && *tp)
  return(NET_FIDO);
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalnum))
  return(NET_INTERNET);
 return(NET_UNKNOWN);
}

canonical_original_code:
unsigned short smb_netaddr_type(char *str)
{
 char *p;
 char *tp;
 if((p=strchr(str,'@'))==((void *)0))
  return(NET_NONE);
 p++;
 while(*(p) && ((*__ctype_b_loc ())[(int) ((*(p)))] & (unsigned short) _ISspace)) (p)++;;
 if(*p==0)
  return(NET_UNKNOWN);
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) && strchr(p,'.')==((void *)0))
  return(NET_QWK);
 for(tp=p;*tp;tp++) {
  if(!((*__ctype_b_loc ())[(int) ((*tp))] & (unsigned short) _ISdigit) && *tp!=':' && *tp!='/' && *tp!='.')
   break;
 }
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) && *tp)
  return(NET_FIDO);
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalnum))
  return(NET_INTERNET);
 return(NET_UNKNOWN);
}

variable_types:
tp
char *


decompiled_code:
int __fastcall xp_sem_init(void **a1, int a2, int a3)
{
char *v4; // rax
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-28h] BYREF

if ( a2 )
{
*_errno_location() = 1;
result = -1;
}
else
{
v4 = (char *)malloc(0x68uLL);
*a1 = v4;
if ( v4 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(v4 + 8), 0LL) )
{
free(*a1);
*_errno_location() = 28;
result = -1;
}
else
{
result = pthread_cond_init((pthread_cond_t *)*a1 + 1, 0LL);
if ( result )
{
while ( pthread_mutex_destroy((pthread_mutex_t *)((char *)*a1 + 8)) == 16 )
{
v6.tv_sec = 0LL;
v6.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v6);
}
free(*a1);
*_errno_location() = 28;
result = -1;
}
else
{
*((_DWORD *)*a1 + 24) = a3;
*((_DWORD *)*a1 + 25) = 0;
*(_DWORD *)*a1 = 167395346;
}
}
}
else
{
*_errno_location() = 28;
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(void **a1, int a2, int a3)
{
char *v4; // rax
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-28h] BYREF

if ( a2 )
{
*_errno_location() = 1;
result = -1;
}
else
{
v4 = (char *)malloc(0x68uLL);
*a1 = v4;
if ( v4 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(v4 + 8), 0LL) )
{
free(*a1);
*_errno_location() = 28;
result = -1;
}
else
{
result = pthread_cond_init((pthread_cond_t *)*a1 + 1, 0LL);
if ( result )
{
while ( pthread_mutex_destroy((pthread_mutex_t *)((char *)*a1 + 8)) == 16 )
{
v6.tv_sec = 0LL;
v6.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v6);
}
free(*a1);
*_errno_location() = 28;
result = -1;
}
else
{
*((_DWORD *)*a1 + 24) = a3;
*((_DWORD *)*a1 + 25) = 0;
*(_DWORD *)*a1 = 167395346;
}
}
}
else
{
*_errno_location() = 28;
result = -1;
}
}
return result;
}

original_code:
int
xp_sem_init(xp_sem_t *sem, int pshared, unsigned int value)
{
 int retval;
 if (pshared != 0) {
  (*__errno_location ()) = 1;
  retval = -1;
  goto RETURN;
 }
 if (value > (0x7fffffff * 2U + 1U)) {
  (*__errno_location ()) = 22;
  retval = -1;
  goto RETURN;
 }
 *sem = (xp_sem_t)malloc(sizeof(struct xp_sem));
 if (*sem == ((void *)0)) {
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 if (pthread_mutex_init(&(*sem)->lock, ((void *)0)) != 0) {
  free(*sem);
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 if (pthread_cond_init(&(*sem)->gtzero, ((void *)0)) != 0) {
  while(pthread_mutex_destroy(&(*sem)->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); });
  free(*sem);
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 (*sem)->count = (u_int32_t)value;
 (*sem)->nwaiters = 0;
 (*sem)->magic = ((u_int32_t) 0x09fa4012);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_init(struct xp_sem **sem, int pshared, unsigned int value)
{
 int retval;
 if (pshared != 0) {
  (*__errno_location ()) = 1;
  retval = -1;
  goto RETURN;
 }
 if (value > (0x7fffffff * 2U + 1U)) {
  (*__errno_location ()) = 22;
  retval = -1;
  goto RETURN;
 }
 *sem = (struct xp_sem *)malloc(sizeof(struct xp_sem));
 if (*sem == ((void *)0)) {
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 if (pthread_mutex_init(&(*sem)->lock, ((void *)0)) != 0) {
  free(*sem);
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 if (pthread_cond_init(&(*sem)->gtzero, ((void *)0)) != 0) {
  while(pthread_mutex_destroy(&(*sem)->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); });
  free(*sem);
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 (*sem)->count = (unsigned int)value;
 (*sem)->nwaiters = 0;
 (*sem)->magic = ((unsigned int) 0x09fa4012);
 retval = 0;
  RETURN:
 return retval;
}

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

variable_types: pshared int

variable_types:
value
unsigned int

variable_types: retval int

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

return_type: int

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

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

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

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


decompiled_code:
__int64 __fastcall xp_sem_destroy(void **a1)
{
char *v2; // rdi
char *v3; // rdi
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

if ( a1 && (v2 = (char *)*a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = (char *)*a1;
if ( *((_DWORD *)*a1 + 25) )
{
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
*_errno_location() = 16;
result = 0xFFFFFFFFLL;
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
while ( pthread_mutex_destroy((pthread_mutex_t *)((char *)*a1 + 8)) == 16 )
{
v5.tv_sec = 0LL;
v5.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
while ( pthread_cond_destroy((pthread_cond_t *)*a1 + 1) == 16 )
{
v5.tv_sec = 0LL;
v5.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
*(_DWORD *)*a1 = 0;
free(*a1);
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1)
{
char *v2; // rdi
char *v3; // rdi
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

if ( a1 && (v2 = (char *)*a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = (char *)*a1;
if ( *((_DWORD *)*a1 + 25) )
{
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
*_errno_location() = 16;
result = 0xFFFFFFFFLL;
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
while ( pthread_mutex_destroy((pthread_mutex_t *)((char *)*a1 + 8)) == 16 )
{
v5.tv_sec = 0LL;
v5.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
while ( pthread_cond_destroy((pthread_cond_t *)*a1 + 1) == 16 )
{
v5.tv_sec = 0LL;
v5.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
*(_DWORD *)*a1 = 0;
free(*a1);
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_destroy(xp_sem_t *sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 if ((*sem)->nwaiters > 0) {
  pthread_mutex_unlock(&(*sem)->lock);
  (*__errno_location ()) = 16;
  retval = -1;
  goto RETURN;
 }
 pthread_mutex_unlock(&(*sem)->lock);
 while(pthread_mutex_destroy(&(*sem)->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(&(*sem)->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); });
 (*sem)->magic = 0;
 free(*sem);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_destroy(struct xp_sem **sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 if ((*sem)->nwaiters > 0) {
  pthread_mutex_unlock(&(*sem)->lock);
  (*__errno_location ()) = 16;
  retval = -1;
  goto RETURN;
 }
 pthread_mutex_unlock(&(*sem)->lock);
 while(pthread_mutex_destroy(&(*sem)->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(&(*sem)->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); });
 (*sem)->magic = 0;
 free(*sem);
 retval = 0;
  RETURN:
 return retval;
}

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

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


decompiled_code:
__int64 xp_sem_open()
{
*_errno_location() = 38;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
*_errno_location() = 38;
return 0LL;
}

original_code:
xp_sem_t *
xp_sem_open(const char *name, int oflag, ...)
{
 (*__errno_location ()) = 38;
 return ((xp_sem_t *)0);
}

canonical_original_code:
struct xp_sem **xp_sem_open(char *name, int oflag, ...)
{
 (*__errno_location ()) = 38;
 return ((struct xp_sem **)0);
}

variable_types:
name
char *

variable_types: oflag int

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


decompiled_code:
__int64 xp_sem_close()
{
*_errno_location() = 38;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
*_errno_location() = 38;
return 0xFFFFFFFFLL;
}

original_code:
int
xp_sem_close(xp_sem_t *sem)
{
 (*__errno_location ()) = 38;
 return -1;
}

canonical_original_code:
int xp_sem_close(struct xp_sem **sem)
{
 (*__errno_location ()) = 38;
 return -1;
}


decompiled_code:
__int64 xp_sem_unlink()
{
*_errno_location() = 38;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func4()
{
*_errno_location() = 38;
return 0xFFFFFFFFLL;
}

original_code:
int
xp_sem_unlink(const char *name)
{
 (*__errno_location ()) = 38;
 return -1;
}

canonical_original_code:
int xp_sem_unlink(char *name)
{
 (*__errno_location ()) = 38;
 return -1;
}


decompiled_code:
__int64 __fastcall xp_sem_wait(pthread_cond_t **a1)
{
pthread_cond_t *v2; // rdi
pthread_cond_t *v3; // rax
int i; // edx
__int64 result; // rax

if ( a1 && (v2 = *a1, v2->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v2->__align + 1));
v3 = *a1;
for ( i = (*a1)[2].__lock; !i; i = (*a1)[2].__lock )
{
++v3[2].__futex;
pthread_cond_wait(*a1 + 1, (pthread_mutex_t *)(&(*a1)->__align + 1));
--(*a1)[2].__futex;
v3 = *a1;
}
v3[2].__lock = i - 1;
pthread_mutex_unlock((pthread_mutex_t *)(&(*a1)->__align + 1));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(pthread_cond_t **a1)
{
pthread_cond_t *v2; // rdi
pthread_cond_t *v3; // rax
int i; // edx
__int64 result; // rax

if ( a1 && (v2 = *a1, v2->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v2->__align + 1));
v3 = *a1;
for ( i = (*a1)[2].__lock; !i; i = (*a1)[2].__lock )
{
++v3[2].__futex;
pthread_cond_wait(*a1 + 1, (pthread_mutex_t *)(&(*a1)->__align + 1));
--(*a1)[2].__futex;
v3 = *a1;
}
v3[2].__lock = i - 1;
pthread_mutex_unlock((pthread_mutex_t *)(&(*a1)->__align + 1));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_wait(xp_sem_t *sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 while ((*sem)->count == 0) {
  (*sem)->nwaiters++;
  pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock);
  (*sem)->nwaiters--;
 }
 (*sem)->count--;
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_wait(struct xp_sem **sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 while ((*sem)->count == 0) {
  (*sem)->nwaiters++;
  pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock);
  (*sem)->nwaiters--;
 }
 (*sem)->count--;
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}


decompiled_code:
__int64 __fastcall xp_sem_trywait(__int64 *a1)
{
__int64 v2; // rdi
int v3; // eax
unsigned int v4; // ebp

if ( a1 && (v2 = *a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = *(_DWORD *)(*a1 + 96);
if ( v3 )
{
*(_DWORD *)(*a1 + 96) = v3 - 1;
v4 = 0;
}
else
{
*_errno_location() = 11;
v4 = -1;
}
pthread_mutex_unlock((pthread_mutex_t *)(*a1 + 8));
}
else
{
*_errno_location() = 22;
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
__int64 v2; // rdi
int v3; // eax
unsigned int v4; // ebp

if ( a1 && (v2 = *a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = *(_DWORD *)(*a1 + 96);
if ( v3 )
{
*(_DWORD *)(*a1 + 96) = v3 - 1;
v4 = 0;
}
else
{
*_errno_location() = 11;
v4 = -1;
}
pthread_mutex_unlock((pthread_mutex_t *)(*a1 + 8));
}
else
{
*_errno_location() = 22;
v4 = -1;
}
return v4;
}

original_code:
int
xp_sem_trywait(xp_sem_t *sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 if ((*sem)->count > 0) {
  (*sem)->count--;
  retval = 0;
 } else {
  (*__errno_location ()) = 11;
  retval = -1;
 }
 pthread_mutex_unlock(&(*sem)->lock);
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_trywait(struct xp_sem **sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 if ((*sem)->count > 0) {
  (*sem)->count--;
  retval = 0;
 } else {
  (*__errno_location ()) = 11;
  retval = -1;
 }
 pthread_mutex_unlock(&(*sem)->lock);
  RETURN:
 return retval;
}


decompiled_code:
__int64 __fastcall xp_sem_post(pthread_cond_t **a1)
{
pthread_cond_t *v2; // rdi
__int64 result; // rax

if ( a1 && (v2 = *a1, v2->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v2->__align + 1));
++(*a1)[2].__lock;
if ( (*a1)[2].__futex )
pthread_cond_broadcast(*a1 + 1);
pthread_mutex_unlock((pthread_mutex_t *)(&(*a1)->__align + 1));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(pthread_cond_t **a1)
{
pthread_cond_t *v2; // rdi
__int64 result; // rax

if ( a1 && (v2 = *a1, v2->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v2->__align + 1));
++(*a1)[2].__lock;
if ( (*a1)[2].__futex )
pthread_cond_broadcast(*a1 + 1);
pthread_mutex_unlock((pthread_mutex_t *)(&(*a1)->__align + 1));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_post(xp_sem_t *sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 (*sem)->count++;
 if ((*sem)->nwaiters > 0) {
  pthread_cond_broadcast(&(*sem)->gtzero);
 }
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_post(struct xp_sem **sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 (*sem)->count++;
 if ((*sem)->nwaiters > 0) {
  pthread_cond_broadcast(&(*sem)->gtzero);
 }
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}


decompiled_code:
__int64 __fastcall xp_sem_getvalue(__int64 *a1, _DWORD *a2)
{
__int64 v3; // rdi
__int64 result; // rax

if ( a1 && (v3 = *a1, *(_DWORD *)v3 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v3 + 8));
*a2 = *(_DWORD *)(*a1 + 96);
pthread_mutex_unlock((pthread_mutex_t *)(*a1 + 8));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, _DWORD *a2)
{
__int64 v3; // rdi
__int64 result; // rax

if ( a1 && (v3 = *a1, *(_DWORD *)v3 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v3 + 8));
*a2 = *(_DWORD *)(*a1 + 96);
pthread_mutex_unlock((pthread_mutex_t *)(*a1 + 8));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_getvalue(xp_sem_t *sem, int *sval)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 *sval = (int)(*sem)->count;
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_getvalue(struct xp_sem **sem, int *sval)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 *sval = (int)(*sem)->count;
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

variable_types:
sval
int *


decompiled_code:
__int64 __fastcall xp_sem_setvalue(pthread_cond_t **a1, int a2)
{
pthread_cond_t *v3; // rdi
__int64 result; // rax

if ( a1 && (v3 = *a1, v3->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v3->__align + 1));
(*a1)[2].__lock = a2;
if ( (*a1)[2].__futex )
{
if ( a2 )
pthread_cond_broadcast(*a1 + 1);
}
pthread_mutex_unlock((pthread_mutex_t *)(&(*a1)->__align + 1));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(pthread_cond_t **a1, int a2)
{
pthread_cond_t *v3; // rdi
__int64 result; // rax

if ( a1 && (v3 = *a1, v3->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v3->__align + 1));
(*a1)[2].__lock = a2;
if ( (*a1)[2].__futex )
{
if ( a2 )
pthread_cond_broadcast(*a1 + 1);
}
pthread_mutex_unlock((pthread_mutex_t *)(&(*a1)->__align + 1));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_setvalue(xp_sem_t *sem, int sval)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 (*sem)->count=(u_int32_t)sval;
 if (((*sem)->nwaiters > 0) && sval) {
  pthread_cond_broadcast(&(*sem)->gtzero);
 }
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_setvalue(struct xp_sem **sem, int sval)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 (*sem)->count=(unsigned int)sval;
 if (((*sem)->nwaiters > 0) && sval) {
  pthread_cond_broadcast(&(*sem)->gtzero);
 }
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

variable_types: sval int


decompiled_code:
__int64 __fastcall xp_sem_timedwait(pthread_cond_t **a1, const struct timespec *a2)
{
pthread_cond_t *v3; // rdi
pthread_cond_t *v4; // rax
int v5; // edx
int v6; // ebx
unsigned int v7; // ebx

if ( a1 && (v3 = *a1, v3->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v3->__align + 1));
while ( 1 )
{
v4 = *a1;
v5 = (*a1)[2].__lock;
if ( v5 )
break;
++v4[2].__futex;
v6 = pthread_cond_timedwait(*a1 + 1, (pthread_mutex_t *)(&(*a1)->__align + 1), a2);
--(*a1)[2].__futex;
if ( v6 )
{
*_errno_location() = v6;
v7 = -1;
goto LABEL_7;
}
}
v4[2].__lock = v5 - 1;
v7 = 0;
LABEL_7:
pthread_mutex_unlock((pthread_mutex_t *)(&(*a1)->__align + 1));
}
else
{
*_errno_location() = 22;
v7 = -1;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func10(pthread_cond_t **a1, const struct timespec *a2)
{
pthread_cond_t *v3; // rdi
pthread_cond_t *v4; // rax
int v5; // edx
int v6; // ebx
unsigned int v7; // ebx

if ( a1 && (v3 = *a1, v3->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v3->__align + 1));
while ( 1 )
{
v4 = *a1;
v5 = (*a1)[2].__lock;
if ( v5 )
break;
++v4[2].__futex;
v6 = pthread_cond_timedwait(*a1 + 1, (pthread_mutex_t *)(&(*a1)->__align + 1), a2);
--(*a1)[2].__futex;
if ( v6 )
{
*_errno_location() = v6;
v7 = -1;
goto LABEL_7;
}
}
v4[2].__lock = v5 - 1;
v7 = 0;
LABEL_7:
pthread_mutex_unlock((pthread_mutex_t *)(&(*a1)->__align + 1));
}
else
{
*_errno_location() = 22;
v7 = -1;
}
return v7;
}

original_code:
int
xp_sem_timedwait(xp_sem_t *sem, const struct timespec *abs_timeout)
{
 int retval=0;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 while ((*sem)->count == 0) {
  (*sem)->nwaiters++;
  retval=pthread_cond_timedwait(&(*sem)->gtzero, &(*sem)->lock, abs_timeout);
  (*sem)->nwaiters--;
  if(retval) {
   (*__errno_location ())=retval;
   retval=-1;
   break;
  }
 }
 if(retval==0)
  (*sem)->count--;
 pthread_mutex_unlock(&(*sem)->lock);
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_timedwait(struct xp_sem **sem, struct timespec *abs_timeout)
{
 int retval = 0;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 while ((*sem)->count == 0) {
  (*sem)->nwaiters++;
  retval=pthread_cond_timedwait(&(*sem)->gtzero, &(*sem)->lock, abs_timeout);
  (*sem)->nwaiters--;
  if(retval) {
   (*__errno_location ())=retval;
   retval=-1;
   break;
  }
 }
 if(retval==0)
  (*sem)->count--;
 pthread_mutex_unlock(&(*sem)->lock);
  RETURN:
 return retval;
}

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


msgQueueReadList

decompiled_code:
__int64 __fastcall msgQueueReadList(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( (*(_BYTE *)(a1 + 336) & 2) != 0 && *(_QWORD *)(a1 + 320) == pthread_self() )
return a1 + 128;
return a1 + 224;
}

original_code:
static link_list_t* msgQueueReadList(msg_queue_t* q)
{
 if(q==((void *)0))
  return(((void *)0));
 if((q->flags&(1<<1))
  && q->owner_thread_id == pthread_self())
  return(&q->in);
 return(&q->out);
}

canonical_original_code:
static struct link_list *msgQueueReadList(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(((void *)0));
 if((q->flags&(1<<1))
  && q->owner_thread_id == pthread_self())
  return(&q->in);
 return(&q->out);
}

variable_types: struct msg_queue_t { char name[128]; struct link_list in; struct link_list out; unsigned long owner_thread_id; long refs; unsigned long flags; void *private_data; } *

return_type: struct link_list { struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list *list; unsigned long flags; } *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; 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; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } *

user_defined_types: struct link_list { struct list_node *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; union pthread_mutex_t mutex; struct xp_sem *sem; }


msgQueueWriteList

decompiled_code:
__int64 __fastcall msgQueueWriteList(__int64 a1)
{
pthread_t v1; // rdx
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( (*(_BYTE *)(a1 + 336) & 2) == 0 || (v1 = pthread_self(), result = a1 + 128, *(_QWORD *)(a1 + 320) == v1) )
result = a1 + 224;
return result;
}

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

if ( !a1 )
return 0LL;
if ( (*(_BYTE *)(a1 + 336) & 2) == 0 || (v1 = pthread_self(), result = a1 + 128, *(_QWORD *)(a1 + 320) == v1) )
result = a1 + 224;
return result;
}

original_code:
static link_list_t* msgQueueWriteList(msg_queue_t* q)
{
 if(q==((void *)0))
  return(((void *)0));
 if(!(q->flags&(1<<1))
  || q->owner_thread_id == pthread_self())
  return(&q->out);
 return(&q->in);
}

canonical_original_code:
static struct link_list *msgQueueWriteList(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(((void *)0));
 if(!(q->flags&(1<<1))
  || q->owner_thread_id == pthread_self())
  return(&q->out);
 return(&q->in);
}

user_defined_types: struct msg_queue_t { char name[128]; struct link_list in; struct link_list out; unsigned long owner_thread_id; long refs; unsigned long flags; void *private_data; }

user_defined_types: struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list *list; unsigned long flags; }


decompiled_code:
__int64 __fastcall list_wait(__int64 a1, __int64 a2)
{
if ( a2 < 0 )
return listSemWait();
if ( a2 )
return listSemTryWaitBlock();
return listSemTryWait();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
if ( a2 < 0 )
return listSemWait();
if ( a2 )
return listSemTryWaitBlock();
return listSemTryWait();
}

original_code:
static int list_wait(link_list_t* list, long timeout)
{
 if(timeout<0)
  return listSemWait(list);
 if(timeout==0)
  return listSemTryWait(list);
 return listSemTryWaitBlock(list,timeout);
}

canonical_original_code:
static int list_wait(struct link_list *list, long timeout)
{
 if(timeout<0)
  return listSemWait(list);
 if(timeout==0)
  return listSemTryWait(list);
 return listSemTryWaitBlock(list,timeout);
}

variable_types: struct link_list { struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list *list; unsigned long flags; } *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; 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; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } *

variable_types: timeout long


msgQueueFree

decompiled_code:
__int64 __fastcall msgQueueFree(void *ptr)
{
__int64 result; // rax

result = 0LL;
if ( ptr )
{
listFree((char *)ptr + 128);
listFree((char *)ptr + 224);
result = 1LL;
if ( (*((_BYTE *)ptr + 336) & 1) != 0 )
{
free(ptr);
result = 1LL;
}
}
return result;
}

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

result = 0LL;
if ( ptr )
{
listFree((char *)ptr + 128);
listFree((char *)ptr + 224);
result = 1LL;
if ( (*((_BYTE *)ptr + 336) & 1) != 0 )
{
free(ptr);
result = 1LL;
}
}
return result;
}

original_code:
int msgQueueFree(msg_queue_t* q)
{
 if(q==((void *)0))
  return(0);
 listFree(&q->in);
 listFree(&q->out);
 if(q->flags&(1<<0))
  free(q);
 return(1);
}

canonical_original_code:
int msgQueueFree(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(0);
 listFree(&q->in);
 listFree(&q->out);
 if(q->flags&(1<<0))
  free(q);
 return(1);
}

variable_types: struct msg_queue_t { char name[128]; struct link_list { struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list *list; unsigned long flags; } *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; 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; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } in; struct link_list out; unsigned long owner_thread_id; long refs; unsigned long flags; void *private_data; } *


msgQueueAttach

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

if ( !a1 )
return -1LL;
result = *(_QWORD *)(a1 + 328) + 1LL;
*(_QWORD *)(a1 + 328) = result;
return result;
}

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

if ( !a1 )
return -1LL;
result = *(_QWORD *)(a1 + 328) + 1LL;
*(_QWORD *)(a1 + 328) = result;
return result;
}

original_code:
long msgQueueAttach(msg_queue_t* q)
{
 if(q==((void *)0))
  return(-1);
 q->refs++;
 return(q->refs);
}

canonical_original_code:
long msgQueueAttach(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(-1);
 q->refs++;
 return(q->refs);
}

return_type: long


msgQueueDetach

decompiled_code:
__int64 __fastcall msgQueueDetach(_QWORD *a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

if ( !a1 )
return -1LL;
v1 = a1[41];
if ( v1 <= 0 )
return -1LL;
v2 = v1 - 1;
a1[41] = v2;
if ( !(_DWORD)v2 )
msgQueueFree(a1);
return (int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

if ( !a1 )
return -1LL;
v1 = a1[41];
if ( v1 <= 0 )
return -1LL;
v2 = v1 - 1;
a1[41] = v2;
if ( !(_DWORD)v2 )
func3(a1);
return (int)v2;
}

original_code:
long msgQueueDetach(msg_queue_t* q)
{
 int refs;
 if(q==((void *)0) || q->refs<1)
  return(-1);
 if((refs=--q->refs)==0)
  msgQueueFree(q);
 return(refs);
}

canonical_original_code:
long msgQueueDetach(struct msg_queue_t *q)
{
 int refs;
 if(q==((void *)0) || q->refs<1)
  return(-1);
 if((refs=--q->refs)==0)
  msgQueueFree(q);
 return(refs);
}

variable_types: refs int


msgQueueSetPrivateData

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 344);
*(_QWORD *)(a1 + 344) = a2;
return result;
}

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 344);
*(_QWORD *)(a1 + 344) = a2;
return result;
}

original_code:
void* msgQueueSetPrivateData(msg_queue_t* q, void* p)
{
 void* old;
 if(q==((void *)0))
  return(((void *)0));
 old=q->private_data;
 q->private_data=p;
 return(old);
}

canonical_original_code:
void *msgQueueSetPrivateData(struct msg_queue_t *q, void *p)
{
 void *old;
 if(q==((void *)0))
  return(((void *)0));
 old=q->private_data;
 q->private_data=p;
 return(old);
}

variable_types:
p
void *

variable_types:
old
void *

return_type: void *


msgQueueGetPrivateData

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

if ( a1 )
result = *(_QWORD *)(a1 + 344);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 344);
else
result = 0LL;
return result;
}

original_code:
void* msgQueueGetPrivateData(msg_queue_t* q)
{
 if(q==((void *)0))
  return(((void *)0));
 return(q->private_data);
}

canonical_original_code:
void *msgQueueGetPrivateData(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(((void *)0));
 return(q->private_data);
}


msgQueueReadLevel

decompiled_code:
__int64 __fastcall msgQueueReadLevel(__int64 a1)
{
__int64 v1; // rax

v1 = msgQueueReadList(a1);
return listCountNodes(v1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax

v1 = func0(a1);
return listCountNodes(v1);
}

original_code:
long msgQueueReadLevel(msg_queue_t* q)
{
 return listCountNodes(msgQueueReadList(q));
}

canonical_original_code:
long msgQueueReadLevel(struct msg_queue_t *q)
{
 return listCountNodes(msgQueueReadList(q));
}


msgQueueWait

decompiled_code:
__int64 __fastcall msgQueueWait(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // ebx

v2 = msgQueueReadList(a1);
v3 = list_wait(v2, a2);
if ( v3 == 1 )
listSemPost(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // ebx

v2 = func0(a1);
v3 = func2(v2, a2);
if ( v3 == 1 )
listSemPost(v2);
return v3;
}

original_code:
int msgQueueWait(msg_queue_t* q, long timeout)
{
 int result;
 link_list_t* list = msgQueueReadList(q);
 if((result=list_wait(list,timeout))==1)
  listSemPost(list)
  ;
 return(result);
}

canonical_original_code:
int msgQueueWait(struct msg_queue_t *q, long timeout)
{
 int result;
 struct link_list *list = msgQueueReadList(q);
 if((result=list_wait(list,timeout))==1)
  listSemPost(list)
  ;
 return(result);
}

variable_types: result int


msgQueueRead

decompiled_code:
__int64 __fastcall msgQueueRead(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = msgQueueReadList(a1);
list_wait(v2, a2);
return listRemoveNode(v2, 0LL, 0LL);
}

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

v2 = func0(a1);
func2(v2, a2);
return listRemoveNode(v2, 0LL, 0LL);
}

original_code:
void* msgQueueRead(msg_queue_t* q, long timeout)
{
 link_list_t* list = msgQueueReadList(q);
 list_wait(list,timeout);
 return listRemoveNode(list, ((list_node_t*)((void *)0)), 0);
}

canonical_original_code:
void *msgQueueRead(struct msg_queue_t *q, long timeout)
{
 struct link_list *list = msgQueueReadList(q);
 list_wait(list,timeout);
 return listRemoveNode(list, ((struct list_node *)((void *)0)), 0);
}


msgQueuePeek

decompiled_code:
__int64 __fastcall msgQueuePeek(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax

v2 = msgQueueReadList(a1);
if ( (unsigned int)list_wait(v2, a2) )
listSemPost(v2);
v3 = listFirstNode(v2);
return listNodeData(v3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax

v2 = func0(a1);
if ( (unsigned int)func2(v2, a2) )
listSemPost(v2);
v3 = listFirstNode(v2);
return listNodeData(v3);
}

original_code:
void* msgQueuePeek(msg_queue_t* q, long timeout)
{
 link_list_t* list = msgQueueReadList(q);
 if(list_wait(list,timeout))
  listSemPost(list)
  ;
 return listNodeData(listFirstNode(list));
}

canonical_original_code:
void *msgQueuePeek(struct msg_queue_t *q, long timeout)
{
 struct link_list *list = msgQueueReadList(q);
 if(list_wait(list,timeout))
  listSemPost(list)
  ;
 return listNodeData(listFirstNode(list));
}


msgQueueFind

decompiled_code:
__int64 __fastcall msgQueueFind(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
__int64 result; // rax

v4 = msgQueueReadList(a1);
result = listFindNode(v4, a2, a3);
if ( result )
result = listRemoveNode(v4, result, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
__int64 result; // rax

v4 = func0(a1);
result = listFindNode(v4, a2, a3);
if ( result )
result = listRemoveNode(v4, result, 0LL);
return result;
}

original_code:
void* msgQueueFind(msg_queue_t* q, const void* data, size_t length)
{
 link_list_t* list = msgQueueReadList(q);
 list_node_t* node;
 if((node=listFindNode(list,data,length))==((void *)0))
  return(((void *)0));
 return listRemoveNode(list,node, 0);
}

canonical_original_code:
void *msgQueueFind(struct msg_queue_t *q, void *data, unsigned long length)
{
 struct link_list *list = msgQueueReadList(q);
 struct list_node *node;
 if((node=listFindNode(list,data,length))==((void *)0))
  return(((void *)0));
 return listRemoveNode(list,node, 0);
}

variable_types:
data
void *

variable_types:
length
unsigned long

variable_types: struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list { struct list_node *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; 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; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } *list; unsigned long flags; } *


msgQueueFirstNode

decompiled_code:
__int64 __fastcall msgQueueFirstNode(__int64 a1)
{
__int64 v1; // rax

v1 = msgQueueReadList(a1);
return listFirstNode(v1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // rax

v1 = func0(a1);
return listFirstNode(v1);
}

original_code:
list_node_t* msgQueueFirstNode(msg_queue_t* q)
{
 return listFirstNode(msgQueueReadList(q));
}

canonical_original_code:
struct list_node *msgQueueFirstNode(struct msg_queue_t *q)
{
 return listFirstNode(msgQueueReadList(q));
}

return_type: struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list { struct list_node *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; 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; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } *list; unsigned long flags; } *


msgQueueLastNode

decompiled_code:
__int64 __fastcall msgQueueLastNode(__int64 a1)
{
__int64 v1; // rax

v1 = msgQueueReadList(a1);
return listLastNode(v1);
}

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

v1 = func0(a1);
return listLastNode(v1);
}

original_code:
list_node_t* msgQueueLastNode(msg_queue_t* q)
{
 return listLastNode(msgQueueReadList(q));
}

canonical_original_code:
struct list_node *msgQueueLastNode(struct msg_queue_t *q)
{
 return listLastNode(msgQueueReadList(q));
}


msgQueueWriteLevel

decompiled_code:
__int64 __fastcall msgQueueWriteLevel(__int64 a1)
{
__int64 v1; // rax

v1 = msgQueueWriteList(a1);
return listCountNodes(v1);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 v1; // rax

v1 = func1(a1);
return listCountNodes(v1);
}

original_code:
long msgQueueWriteLevel(msg_queue_t* q)
{
 return listCountNodes(msgQueueWriteList(q));
}

canonical_original_code:
long msgQueueWriteLevel(struct msg_queue_t *q)
{
 return listCountNodes(msgQueueWriteList(q));
}


msgQueueWrite

decompiled_code:
_BOOL8 __fastcall msgQueueWrite(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax

v4 = msgQueueWriteList(a1);
return listAddNodeData(v4, a2, a3, -1LL) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax

v4 = func1(a1);
return listAddNodeData(v4, a2, a3, -1LL) != 0;
}

original_code:
int msgQueueWrite(msg_queue_t* q, const void* data, size_t length)
{
 return listAddNodeData(msgQueueWriteList(q), data, length, ((list_node_t*)-1))!=((void *)0);
}

canonical_original_code:
int msgQueueWrite(struct msg_queue_t *q, void *data, unsigned long length)
{
 return listAddNodeData(msgQueueWriteList(q), data, length, ((struct list_node *)-1))!=((void *)0);
}


getstr

original_code:
static int getstr(char* str, int maxlen)
{
 char ch;
    int len=0;
 int istty;
 istty=isatty(fileno(stdin));
    while(1) {
  fread(&ch,1,1,stdin);
  if(!istty) {
   printf("%c",ch);
   fflush(stdout);
  }
        if(ch=='\r' || ch=='\n')
         break;
        if(ch=='\b' || ch==0x7f) {
         if(len) len--;
            continue;
     }
        if(len<maxlen)
   str[len++]=ch;
 }
    str[len]=0;
 return(len);
}

canonical_original_code:
static int getstr(char *str, int maxlen)
{
 char ch;
    int len = 0;
 int istty;
 istty=isatty(fileno(stdin));
    while(1) {
  fread(&ch,1,1,stdin);
  if(!istty) {
   printf("%c",ch);
   fflush(stdout);
  }
        if(ch=='\r' || ch=='\n')
         break;
        if(ch=='\b' || ch==0x7f) {
         if(len) len--;
            continue;
     }
        if(len<maxlen)
   str[len++]=ch;
 }
    str[len]=0;
 return(len);
}

variable_types:
str
char *

variable_types: maxlen int

variable_types: ch char

variable_types: len int

variable_types: istty int


getnum

decompiled_code:
__int64 __fastcall sbbs_t::getnum(sbbs_t *this, unsigned __int64 a2)
{
__int64 v3; // [rsp+10h] [rbp-10h]
char v4; // [rsp+1Eh] [rbp-2h]
char v5; // [rsp+1Fh] [rbp-1h]

v4 = 0;
v3 = 0LL;
while ( *((_QWORD *)this + 6413) )
{
v5 = sbbs_t::getkey(this, 1LL);
if ( v5 >= 0 )
{
if ( v5 == 81 )
{
sbbs_t::outchar(this, 81);
if ( (*((_QWORD *)this + 3362) & 0x40000LL) != 0 )
v5 = sbbs_t::getkey(this, 1LL);
if ( v5 != 8 && v5 != 127 )
{
LABEL_12:
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return -1LL;
}
sbbs_t::backspace(this);
}
else
{
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
goto LABEL_12;
if ( v5 == 13 )
{
LABEL_14:
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v3;
}
if ( (v5 == 8 || v5 == 127) && v4 )
{
sbbs_t::backspace(this);
v3 /= 10LL;
--v4;
}
else if ( (unsigned int)(unsigned __int8)v5 - 48 <= 9
&& a2 >= 10 * v3 + (unsigned __int64)(v5 & 0xF)
&& (v5 != 48 || v4) )
{
++v4;
v3 = (v5 & 0xF) + 10 * v3;
sbbs_t::outchar(this, v5);
if ( a2 < 10 * v3 && (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
goto LABEL_14;
}
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func1(sbbs_t *this, unsigned __int64 a2)
{
__int64 v3; // [rsp+10h] [rbp-10h]
char v4; // [rsp+1Eh] [rbp-2h]
char v5; // [rsp+1Fh] [rbp-1h]

v4 = 0;
v3 = 0LL;
while ( *((_QWORD *)this + 6413) )
{
v5 = sbbs_t::getkey(this, 1LL);
if ( v5 >= 0 )
{
if ( v5 == 81 )
{
sbbs_t::outchar(this, 81);
if ( (*((_QWORD *)this + 3362) & 0x40000LL) != 0 )
v5 = sbbs_t::getkey(this, 1LL);
if ( v5 != 8 && v5 != 127 )
{
LABEL_12:
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return -1LL;
}
sbbs_t::backspace(this);
}
else
{
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
goto LABEL_12;
if ( v5 == 13 )
{
LABEL_14:
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v3;
}
if ( (v5 == 8 || v5 == 127) && v4 )
{
sbbs_t::backspace(this);
v3 /= 10LL;
--v4;
}
else if ( (unsigned int)(unsigned __int8)v5 - 48 <= 9
&& a2 >= 10 * v3 + (unsigned __int64)(v5 & 0xF)
&& (v5 != 48 || v4) )
{
++v4;
v3 = (v5 & 0xF) + 10 * v3;
sbbs_t::outchar(this, v5);
if ( a2 < 10 * v3 && (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
goto LABEL_14;
}
}
}
}
return 0LL;
}

original_code:
int getnum(int max)
{
 unsigned char ch,n=0;
 int i=0;
 while(1) {
  ch=getkey((1<<0));
  if(ch>0x7f)
   continue;
  if(ch=='Q') {
   outchar('Q');
   { outchar('\r'); outchar('\n'); };
   break;
  }
  else if(ch==3) {
   { outchar('\r'); outchar('\n'); };
   break;
  }
  else if(ch=='\r') {
   { outchar('\r'); outchar('\n'); };
   return(i);
  }
  else if(ch=='\b' && n) {
   bputs("\b \b");
   i/=10;
   n--;
  }
  else if(((*__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) {
    { outchar('\r'); outchar('\n'); };
    return(i);
   }
  }
 }
 return(-1);
}

canonical_original_code:
int getnum(int max)
{
 unsigned char ch; unsigned char n = 0;
 int i = 0;
 while(1) {
  ch=getkey((1<<0));
  if(ch>0x7f)
   continue;
  if(ch=='Q') {
   outchar('Q');
   { outchar('\r'); outchar('\n'); };
   break;
  }
  else if(ch==3) {
   { outchar('\r'); outchar('\n'); };
   break;
  }
  else if(ch=='\r') {
   { outchar('\r'); outchar('\n'); };
   return(i);
  }
  else if(ch=='\b' && n) {
   bputs("\b \b");
   i/=10;
   n--;
  }
  else if(((*__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) {
    { outchar('\r'); outchar('\n'); };
    return(i);
   }
  }
 }
 return(-1);
}

variable_types: max int

variable_types:
ch
unsigned char

variable_types:
n
unsigned char

variable_types: i int


decompiled_code:
__int64 __fastcall semfile_check(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // edx

if ( !*a1 )
*a1 = time(0LL);
v2 = fdate(a2);
v3 = 0;
if ( v2 != -1 && *a1 < v2 )
{
*a1 = v2;
v3 = 1;
}
return v3;
}

original_code:
int semfile_check(time_t* t, const char* fname)
{
 time_t ft;
 if(*t==0)
  *t=time(((void *)0));
 if((ft=fdate(fname))==-1 || ft<=*t)
  return(0);
 *t=ft;
 return(1);
}

canonical_original_code:
int semfile_check(long *t, char *fname)
{
 long ft;
 if(*t==0)
  *t=time(((void *)0));
 if((ft=fdate(fname))==-1 || ft<=*t)
  return(0);
 *t=ft;
 return(1);
}

variable_types:
t
long *

variable_types:
fname
char *

variable_types: ft long


decompiled_code:
__int64 __fastcall semfile_list_check(__int64 *a1, __int64 *a2)
{
__int64 *v2; // rbx
__int64 v3; // rsi
__int64 v4; // r12

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
v4 = 0LL;
do
{
if ( (unsigned int)semfile_check(a1, v3) )
v4 = *v2;
v3 = *++v2;
}
while ( *v2 );
return v4;
}

original_code:
char* semfile_list_check(time_t* t, str_list_t filelist)
{
 char* signaled=((void *)0);
 size_t i;
 for(i=0;filelist[i]!=((void *)0);i++)
  if(semfile_check(t, filelist[i]))
   signaled = filelist[i];
 return(signaled);
}

canonical_original_code:
char *semfile_list_check(long *t, char **filelist)
{
 char *signaled = ((void *)0);
 unsigned long i;
 for(i=0;filelist[i]!=((void *)0);i++)
  if(semfile_check(t, filelist[i]))
   signaled = filelist[i];
 return(signaled);
}

variable_types:
filelist
char **

variable_types:
signaled
char *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall semfile_list_init(const char *a1, const char *a2, const char *a3)
{
__int64 result; // rax
char *v5; // rax
__int64 v6; // [rsp+8h] [rbp-10B0h] BYREF
char name[128]; // [rsp+10h] [rbp-10A8h] BYREF
char v8[4096]; // [rsp+90h] [rbp-1028h] BYREF
char v9; // [rsp+1090h] [rbp-28h]

result = strListInit();
v6 = result;
if ( result )
{
safe_snprintf(v8, 4097LL, "%s%s", a1, a2);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
if ( !gethostname(name, 0x80uLL) )
{
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, name);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s.%s", a1, a2, name, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
v5 = strchr(name, 46);
if ( v5 )
{
*v5 = 0;
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, name);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s.%s", a1, a2, name, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
}
}
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2, const char *a3)
{
__int64 result; // rax
char *v5; // rax
__int64 v6; // [rsp+8h] [rbp-10B0h] BYREF
char name[128]; // [rsp+10h] [rbp-10A8h] BYREF
char v8[4096]; // [rsp+90h] [rbp-1028h] BYREF
char v9; // [rsp+1090h] [rbp-28h]

result = strListInit();
v6 = result;
if ( result )
{
safe_snprintf(v8, 4097LL, "%s%s", a1, a2);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
if ( !gethostname(name, 0x80uLL) )
{
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, name);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s.%s", a1, a2, name, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
v5 = strchr(name, 46);
if ( v5 )
{
*v5 = 0;
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, name);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s.%s", a1, a2, name, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
}
}
result = v6;
}
return result;
}

original_code:
str_list_t semfile_list_init(const char* parent,
          const char* action, const char* service)
{
 char path[4096 +1];
 char hostname[128];
 char* p;
 str_list_t list;
 if((list=strListInit())==((void *)0))
  return(((void *)0));
 safe_snprintf(path,sizeof(path),"%s%s",parent,action), path[sizeof(path)-1]=0;
 strListAppend(&list, path, (~0));
 safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,service), path[sizeof(path)-1]=0;
 strListAppend(&list, path, (~0));
 if(gethostname(hostname,sizeof(hostname))==0) {
  safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,hostname), path[sizeof(path)-1]=0;
  strListAppend(&list, path, (~0));
  safe_snprintf(path,sizeof(path),"%s%s.%s.%s",parent,action,hostname,service), path[sizeof(path)-1]=0;
  strListAppend(&list, path, (~0));
  if((p=strchr(hostname,'.'))!=((void *)0)) {
   *p=0;
   safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,hostname), path[sizeof(path)-1]=0;
   strListAppend(&list, path, (~0));
   safe_snprintf(path,sizeof(path),"%s%s.%s.%s",parent,action,hostname,service), path[sizeof(path)-1]=0;
   strListAppend(&list, path, (~0));
  }
 }
 return(list);
}

canonical_original_code:
char **semfile_list_init(char *parent, char *action, char *service)
{
 char path[-1];
 char hostname[128];
 char *p;
 char **list;
 if((list=strListInit())==((void *)0))
  return(((void *)0));
 safe_snprintf(path,sizeof(path),"%s%s",parent,action), path[sizeof(path)-1]=0;
 strListAppend(&list, path, (~0));
 safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,service), path[sizeof(path)-1]=0;
 strListAppend(&list, path, (~0));
 if(gethostname(hostname,sizeof(hostname))==0) {
  safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,hostname), path[sizeof(path)-1]=0;
  strListAppend(&list, path, (~0));
  safe_snprintf(path,sizeof(path),"%s%s.%s.%s",parent,action,hostname,service), path[sizeof(path)-1]=0;
  strListAppend(&list, path, (~0));
  if((p=strchr(hostname,'.'))!=((void *)0)) {
   *p=0;
   safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,hostname), path[sizeof(path)-1]=0;
   strListAppend(&list, path, (~0));
   safe_snprintf(path,sizeof(path),"%s%s.%s.%s",parent,action,hostname,service), path[sizeof(path)-1]=0;
   strListAppend(&list, path, (~0));
  }
 }
 return(list);
}

variable_types:
parent
char *

variable_types:
action
char *

variable_types:
service
char *

variable_types:
path
char [-1]

variable_types:
hostname
char [128]

variable_types:
p
char *

variable_types:
list
char **

return_type: char **


decompiled_code:
__int64 __fastcall semfile_list_add(__int64 a1, __int64 a2)
{
return strListAppend(a1, a2, -1LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return strListAppend(a1, a2, -1LL);
}

original_code:
void semfile_list_add(str_list_t* filelist, const char* path)
{
 strListAppend(filelist, path, (~0));
}

canonical_original_code:
void semfile_list_add(char ***filelist, char *path)
{
 strListAppend(filelist, path, (~0));
}

variable_types:
filelist
char ***

variable_types:
path
char *

return_type: void


decompiled_code:
__int64 semfile_list_free()
{
return strListFree();
}

canonical_decompiled_code:
__int64 func4()
{
return strListFree();
}

original_code:
void semfile_list_free(str_list_t* filelist)
{
 strListFree(filelist);
}

canonical_original_code:
void semfile_list_free(char ***filelist)
{
 strListFree(filelist);
}


decompiled_code:
__int64 __fastcall semfile_signal(char *file, void *buf)
{
const char *v2; // rbp
int v3; // ebx
__int64 result; // rax
size_t v5; // rax
char v6[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = (const char *)buf;
if ( !buf )
{
if ( gethostname(v6, 0x80uLL) )
{
v3 = open(file, 65);
if ( v3 < 0 )
return 0LL;
goto LABEL_4;
}
v2 = v6;
}
v3 = open(file, 65);
result = 0LL;
if ( v3 < 0 )
return result;
v5 = strlen(v2);
write(v3, v2, v5);
LABEL_4:
close(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *file, void *buf)
{
const char *v2; // rbp
int v3; // ebx
__int64 result; // rax
size_t v5; // rax
char v6[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = (const char *)buf;
if ( !buf )
{
if ( gethostname(v6, 0x80uLL) )
{
v3 = open(file, 65);
if ( v3 < 0 )
return 0LL;
goto LABEL_4;
}
v2 = v6;
}
v3 = open(file, 65);
result = 0LL;
if ( v3 < 0 )
return result;
v5 = strlen(v2);
write(v3, v2, v5);
LABEL_4:
close(v3);
return 1LL;
}

original_code:
int semfile_signal(const char* fname, const char* text)
{
 int file;
 char hostname[128];
 if(text==((void *)0) && gethostname(hostname,sizeof(hostname))==0)
  text=hostname;
 if((file=open(fname,0100|01))<0)
  return(0);
 if(text!=((void *)0))
  write(file,text,strlen(text));
 close(file);
 return(1);
}

canonical_original_code:
int semfile_signal(char *fname, char *text)
{
 int file;
 char hostname[128];
 if(text==((void *)0) && gethostname(hostname,sizeof(hostname))==0)
  text=hostname;
 if((file=open(fname,0100|01))<0)
  return(0);
 if(text!=((void *)0))
  write(file,text,strlen(text));
 close(file);
 return(1);
}

variable_types:
text
char *

variable_types: file int


decompiled_code:
__int64 __fastcall ucrc16(char a1, _WORD *a2)
{
int v3; // edx
__int16 v4; // cx
__int64 result; // rax
unsigned int v6; // esi

v3 = (unsigned __int16)*a2;
v4 = 8;
do
{
result = (unsigned int)(2 * v3);
if ( a1 < 0 )
result = (2 * v3) | 1u;
a1 *= 2;
HIWORD(v6) = WORD1(result);
if ( (v3 & 0x8000u) != 0 )
{
LOWORD(v6) = result ^ 0x1021;
result = v6;
}
v3 = result;
--v4;
}
while ( v4 );
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, _WORD *a2)
{
int v3; // edx
__int16 v4; // cx
__int64 result; // rax
unsigned int v6; // esi

v3 = (unsigned __int16)*a2;
v4 = 8;
do
{
result = (unsigned int)(2 * v3);
if ( a1 < 0 )
result = (2 * v3) | 1u;
a1 *= 2;
HIWORD(v6) = WORD1(result);
if ( (v3 & 0x8000u) != 0 )
{
LOWORD(v6) = result ^ 0x1021;
result = v6;
}
v3 = result;
--v4;
}
while ( v4 );
*a2 = result;
return result;
}

original_code:
void ucrc16(unsigned char ch, ushort *rcrc) {
 ushort i, cy;
    unsigned char nch=ch;
for (i=0; i<8; i++) {
    cy=*rcrc & 0x8000;
    *rcrc<<=1;
    if (nch & 0x80) *rcrc |= 1;
    nch<<=1;
    if (cy) *rcrc ^= 0x1021; }
}

canonical_original_code:
void ucrc16(unsigned char ch, unsigned short *rcrc) {
 unsigned short i; unsigned short cy;
    unsigned char nch = ch;
for (i=0; i<8; i++) {
    cy=*rcrc & 0x8000;
    *rcrc<<=1;
    if (nch & 0x80) *rcrc |= 1;
    nch<<=1;
    if (cy) *rcrc ^= 0x1021; }
}

variable_types:
ch
unsigned char

variable_types:
rcrc
unsigned short *

variable_types:
i
unsigned short

variable_types:
cy
unsigned short

variable_types:
nch
unsigned char


unixtodstr

decompiled_code:
char *__fastcall unixtodstr(time_t a1, char *a2)
{
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
if ( a1 && (v3 = gmtime(&timer)) != 0LL )
{
if ( v3->tm_mon > 11 )
{
v3->tm_mon = 0;
++v3->tm_year;
}
if ( v3->tm_mday > 31 )
v3->tm_mday = 1;
sprintf(
a2,
"%02u/%02u/%02u",
(unsigned int)v3->tm_mday,
(unsigned int)(v3->tm_mon + 1),
(unsigned int)(v3->tm_year % 100));
}
else
{
strcpy(a2, "00/00/00");
}
return a2;
}

canonical_decompiled_code:
char *__fastcall func2(time_t a1, char *a2)
{
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
if ( a1 && (v3 = gmtime(&timer)) != 0LL )
{
if ( v3->tm_mon > 11 )
{
v3->tm_mon = 0;
++v3->tm_year;
}
if ( v3->tm_mday > 31 )
v3->tm_mday = 1;
sprintf(
a2,
"%02u/%02u/%02u",
(unsigned int)v3->tm_mday,
(unsigned int)(v3->tm_mon + 1),
(unsigned int)(v3->tm_year % 100));
}
else
{
strcpy(a2, "00/00/00");
}
return a2;
}

original_code:
char* unixtodstr(time_t unix_time, char *str)
{
 struct tm* tm;
 if(!unix_time)
  strcpy(str,"00/00/00");
 else {
  tm=gmtime(&unix_time);
  if(tm==((void *)0)) {
   strcpy(str,"00/00/00");
   return(str);
  }
  if(tm->tm_mon>11) {
   tm->tm_mon=0;
   tm->tm_year++; }
  if(tm->tm_mday>31)
   tm->tm_mday=1;
  sprintf(str,"%02u/%02u/%02u",tm->tm_mday,tm->tm_mon+1
   ,((tm->tm_year)%100));
 }
 return(str);
}

canonical_original_code:
char *unixtodstr(long unix_time, char *str)
{
 struct tm *tm;
 if(!unix_time)
  strcpy(str,"00/00/00");
 else {
  tm=gmtime(&unix_time);
  if(tm==((void *)0)) {
   strcpy(str,"00/00/00");
   return(str);
  }
  if(tm->tm_mon>11) {
   tm->tm_mon=0;
   tm->tm_year++; }
  if(tm->tm_mday>31)
   tm->tm_mday=1;
  sprintf(str,"%02u/%02u/%02u",tm->tm_mday,tm->tm_mon+1
   ,((tm->tm_year)%100));
 }
 return(str);
}

variable_types:
str
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
__int64 __fastcall x_puttext(int a1, int a2, int a3, int a4, unsigned __int8 *a5)
{
__int64 result; // rax
int v10; // er8
int v11; // esi
unsigned __int8 *v12; // rdi
unsigned __int8 v13; // cl
char v14[7]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v15; // [rsp+Ch] [rbp-2Ch]
unsigned __int8 v16; // [rsp+Dh] [rbp-2Bh]

ciolib_gettextinfo(v14);
if ( a1 <= 0 || a2 <= 0 )
return 0LL;
if ( a3 <= 0 || a4 <= 0 )
return 0LL;
result = 0LL;
if ( v16 >= a1 && v15 >= a2 )
{
if ( v15 >= a4 && v16 >= a3 && a2 <= a4 && a1 <= a3 && a5 )
{
v10 = a2 - 1;
if ( a4 <= a2 - 1 )
{
result = 1LL;
}
else
{
do
{
v11 = a1 - 1;
if ( a3 > a1 - 1 )
{
v12 = a5;
do
{
v13 = *v12;
v12 += 2;
*(_WORD *)(vmem + 2LL * (v11 + v10 * DpyCols)) = (*(v12 - 1) << 8) | v13;
++v11;
}
while ( a3 != v11 );
a5 += 2 * (unsigned int)(a3 - a1) + 2;
}
++v10;
}
while ( a4 != v10 );
result = 1LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3, int a4, unsigned __int8 *a5)
{
__int64 result; // rax
int v10; // er8
int v11; // esi
unsigned __int8 *v12; // rdi
unsigned __int8 v13; // cl
char v14[7]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v15; // [rsp+Ch] [rbp-2Ch]
unsigned __int8 v16; // [rsp+Dh] [rbp-2Bh]

ciolib_gettextinfo(v14);
if ( a1 <= 0 || a2 <= 0 )
return 0LL;
if ( a3 <= 0 || a4 <= 0 )
return 0LL;
result = 0LL;
if ( v16 >= a1 && v15 >= a2 )
{
if ( v15 >= a4 && v16 >= a3 && a2 <= a4 && a1 <= a3 && a5 )
{
v10 = a2 - 1;
if ( a4 <= a2 - 1 )
{
result = 1LL;
}
else
{
do
{
v11 = a1 - 1;
if ( a3 > a1 - 1 )
{
v12 = a5;
do
{
v13 = *v12;
v12 += 2;
*(_WORD *)(vmem + 2LL * (v11 + v10 * DpyCols)) = (*(v12 - 1) << 8) | v13;
++v11;
}
while ( a3 != v11 );
a5 += 2 * (unsigned int)(a3 - a1) + 2;
}
++v10;
}
while ( a4 != v10 );
result = 1LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int x_puttext(int sx, int sy, int ex, int ey, void *fill)
{
 int x,y;
 unsigned char *out;
 ushort sch;
 struct text_info ti;
 ciolib_gettextinfo(&ti);
 if( sx < 1
   || sy < 1
   || ex < 1
   || ey < 1
   || sx > ti.screenwidth
   || sy > ti.screenheight
   || sx > ex
   || sy > ey
   || ex > ti.screenwidth
   || ey > ti.screenheight
   || fill==((void *)0))
  return(0);
 out=fill;
 for(y=sy-1;y<ey;y++) {
  for(x=sx-1;x<ex;x++) {
   sch=*(out++);
   sch |= (*(out++))<<8;
   vmem[y*DpyCols+x]=sch;
  }
 }
 return(1);
}

canonical_original_code:
int x_puttext(int sx, int sy, int ex, int ey, void *fill)
{
 int x; int y;
 unsigned char *out;
 unsigned short sch;
 struct text_info ti;
 ciolib_gettextinfo(&ti);
 if( sx < 1
   || sy < 1
   || ex < 1
   || ey < 1
   || sx > ti.screenwidth
   || sy > ti.screenheight
   || sx > ex
   || sy > ey
   || ex > ti.screenwidth
   || ey > ti.screenheight
   || fill==((void *)0))
  return(0);
 out=fill;
 for(y=sy-1;y<ey;y++) {
  for(x=sx-1;x<ex;x++) {
   sch=*(out++);
   sch |= (*(out++))<<8;
   vmem[y*DpyCols+x]=sch;
  }
 }
 return(1);
}

variable_types: sx int

variable_types: sy int

variable_types: ex int

variable_types: ey int

variable_types:
fill
void *

variable_types: x int

variable_types: y int

variable_types:
out
unsigned char *

variable_types:
sch
unsigned short

variable_types: struct text_info { unsigned char winleft; unsigned char wintop; unsigned char winright; unsigned char winbottom; unsigned char attribute; unsigned char normattr; unsigned char currmode; unsigned char screenheight; unsigned char screenwidth; unsigned char curx; unsigned char cury; }


decompiled_code:
__int64 __fastcall x_gettext(int a1, int a2, int a3, int a4, _BYTE *a5)
{
__int64 result; // rax
int v10; // edi
int v11; // edx
_BYTE *v12; // rcx
__int16 v13; // ax
char v14[7]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v15; // [rsp+Ch] [rbp-2Ch]
unsigned __int8 v16; // [rsp+Dh] [rbp-2Bh]

ciolib_gettextinfo(v14);
if ( a1 <= 0 || a2 <= 0 )
return 0LL;
if ( a3 <= 0 || a4 <= 0 )
return 0LL;
result = 0LL;
if ( v16 >= a1 && v15 >= a2 )
{
if ( v15 >= a4 && v16 >= a3 && a2 <= a4 && a1 <= a3 && a5 )
{
v10 = a2 - 1;
if ( a4 <= a2 - 1 )
{
result = 1LL;
}
else
{
do
{
v11 = a1 - 1;
if ( a3 > a1 - 1 )
{
v12 = a5;
do
{
v13 = *(_WORD *)(vmem + 2LL * (v11 + v10 * DpyCols));
*v12 = v13;
v12 += 2;
*(v12 - 1) = HIBYTE(v13);
++v11;
}
while ( a3 != v11 );
a5 += 2 * (unsigned int)(a3 - a1) + 2;
}
++v10;
}
while ( a4 != v10 );
result = 1LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int x_gettext(int sx, int sy, int ex, int ey, void *fill)
{
 int x,y;
 unsigned char *out;
 ushort sch;
 struct text_info ti;
 ciolib_gettextinfo(&ti);
 if( sx < 1
   || sy < 1
   || ex < 1
   || ey < 1
   || sx > ti.screenwidth
   || sy > ti.screenheight
   || sx > ex
   || sy > ey
   || ex > ti.screenwidth
   || ey > ti.screenheight
   || fill==((void *)0))
  return(0);
 out=fill;
 for(y=sy-1;y<ey;y++) {
  for(x=sx-1;x<ex;x++) {
   sch=vmem[y*DpyCols+x];
   *(out++)=sch & 0xff;
   *(out++)=sch >> 8;
  }
 }
 return(1);
}

canonical_original_code:
int x_gettext(int sx, int sy, int ex, int ey, void *fill)
{
 int x; int y;
 unsigned char *out;
 unsigned short sch;
 struct text_info ti;
 ciolib_gettextinfo(&ti);
 if( sx < 1
   || sy < 1
   || ex < 1
   || ey < 1
   || sx > ti.screenwidth
   || sy > ti.screenheight
   || sx > ex
   || sy > ey
   || ex > ti.screenwidth
   || ey > ti.screenheight
   || fill==((void *)0))
  return(0);
 out=fill;
 for(y=sy-1;y<ey;y++) {
  for(x=sx-1;x<ex;x++) {
   sch=vmem[y*DpyCols+x];
   *(out++)=sch & 0xff;
   *(out++)=sch >> 8;
  }
 }
 return(1);
}

user_defined_types: struct text_info { unsigned char winleft; unsigned char wintop; unsigned char winright; unsigned char winbottom; unsigned char attribute; unsigned char normattr; unsigned char currmode; unsigned char screenheight; unsigned char screenwidth; unsigned char curx; unsigned char cury; }


decompiled_code:
void __fastcall x_textattr(__int16 a1)
{
x_curr_attr = a1 << 8;
}

canonical_decompiled_code:
void __fastcall func2(__int16 a1)
{
x_curr_attr = a1 << 8;
}

original_code:
void x_textattr(int attr)
{
 x_curr_attr=attr<<8;
}

variable_types: attr int