main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct stat *v3; // rbx
int v4; // ebx

v3 = (struct stat *)malloc(0x90uLL);
summary = (char *)malloc(0x2710uLL);
virusCount = 0;
if ( argc <= 2 )
exit(1);
sigFile = (char *)argv[1];
signatures = (__int64)mapSignatures(sigFile);
if ( signatures )
{
lstat(sigFile, v3);
sigcount = SLODWORD(v3->st_size) / 8;
free(v3);
recursedir(argv[2], (void (__fastcall *)(__int64 *))scanFile);
v4 = 20;
do
{
putchar(61);
--v4;
}
while ( v4 );
puts("");
puts("Scan summary:");
printf("%d viruses detected.\n", (unsigned int)virusCount);
printf("%s", summary);
exit(0);
}
fwrite("Missing signature file?", 1uLL, 0x17uLL, stderr);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct stat *v3; // rbx
int v4; // ebx

v3 = (struct stat *)malloc(0x90uLL);
summary = (char *)malloc(0x2710uLL);
virusCount = 0;
if ( argc <= 2 )
exit(1);
sigFile = (char *)argv[1];
signatures = (__int64)func11(sigFile);
if ( signatures )
{
func17(sigFile, v3);
sigcount = SLODWORD(v3->st_size) / 8;
free(v3);
func13(argv[2], (void (__fastcall *)(__int64 *))scanFile);
v4 = 20;
do
{
putchar(61);
--v4;
}
while ( v4 );
puts("");
puts("Scan summary:");
printf("%d viruses detected.\n", (unsigned int)virusCount);
printf("%s", summary);
exit(0);
}
fwrite("Missing signature file?", 1uLL, 0x17uLL, stderr);
exit(0);
}

original_code:
int main(int argc, char **argv){
    int i;
    struct stat *buf = (struct stat* )malloc(sizeof(struct stat));
    summary = (char*)malloc(sizeof(char)*10000);
    virusCount = 0;
    if (argc < 3)
        exit(1);
    sigFile = argv[1];
    signatures = mapSignatures(sigFile);
    if (signatures == ((void *)0)){
        fputs("Missing signature file?",stderr);
        exit(0);
    }
    lstat(sigFile,buf);
    sigcount = ((int)buf->st_size)/8;
    free(buf);
    recursedir(argv[2],&scanFile);
    for(i = 0; i < 20; i++){
        printf("=");
    }
    puts("");
    puts("Scan summary:");
    printf("%d viruses detected.\n",virusCount);
    printf("%s",summary);
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv){
    int i;
    struct stat *buf = (struct stat* )malloc(sizeof(struct stat));
    summary = (char *)malloc(sizeof(char)*10000);
    virusCount = 0;
    if (argc < 3)
        exit(1);
    sigFile = argv[1];
    signatures = mapSignatures(sigFile);
    if (signatures == ((void *)0)){
        fputs("Missing signature file?",stderr);
        exit(0);
    }
    lstat(sigFile,buf);
    sigcount = ((int)buf->st_size)/8;
    free(buf);
    recursedir(argv[2],&scanFile);
    for(i = 0; i < 20; i++){
        printf("=");
    }
    puts("");
    puts("Scan summary:");
    printf("%d viruses detected.\n",virusCount);
    printf("%s",summary);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } *


decompiled_code:
__int64 __fastcall DL_ISO8583_DEFS_1993_GetHandler(__int64 a1)
{
return DL_ISO8583_COMMON_SetHandler(&iso8583_1993_fields, 129LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return DL_ISO8583_COMMON_SetHandler(&iso8583_1993_fields, 129LL, a1);
}

original_code:
void DL_ISO8583_DEFS_1993_GetHandler ( DL_ISO8583_HANDLER *oHandler )
{
 DL_ISO8583_COMMON_SetHandler(
  _iso8583_1993_fields,
  (DL_UINT8)(sizeof(_iso8583_1993_fields)/sizeof(DL_ISO8583_FIELD_DEF)),
  oHandler);
 return;
}

canonical_original_code:
void DL_ISO8583_DEFS_1993_GetHandler(struct DL_ISO8583_HANDLER_S *oHandler)
{
 DL_ISO8583_COMMON_SetHandler(
  _iso8583_1993_fields,
  (DL_UINT8)(sizeof(_iso8583_1993_fields)/sizeof(DL_ISO8583_FIELD_DEF)),
  oHandler);
 return;
}

variable_types: struct DL_ISO8583_HANDLER_S { struct DL_ISO8583_FIELD_DEF_S { unsigned char fieldType; unsigned int len; unsigned char varLen; } *fieldArr; unsigned char fieldItems; } *

return_type: void

user_defined_types: struct DL_ISO8583_HANDLER_S { struct DL_ISO8583_FIELD_DEF_S *fieldArr; unsigned char fieldItems; }


decompiled_code:
char *__fastcall DL_STR_GetEnv(char *name)
{
char *v1; // rdx
char *result; // rax

v1 = getenv(name);
result = (char *)&kDL_STR_EmptyStr;
if ( v1 )
result = getenv(name);
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *name)
{
char *v1; // rdx
char *result; // rax

v1 = getenv(name);
result = (char *)&kDL_STR_EmptyStr;
if ( v1 )
result = getenv(name);
return result;
}

original_code:
DL_CHAR *DL_STR_GetEnv ( const DL_CHAR *iEnvStr )
{
    return ((getenv(iEnvStr))==((void *)0)?kDL_STR_EmptyStr:(getenv(iEnvStr)));
}

canonical_original_code:
unsigned char *DL_STR_GetEnv(unsigned char *iEnvStr)
{
    return ((getenv(iEnvStr))==((void *)0)?kDL_STR_EmptyStr:(getenv(iEnvStr)));
}

variable_types:
iEnvStr
unsigned char *

return_type: unsigned char *


decompiled_code:
size_t __fastcall DL_STR_StrLen(const char *a1)
{
size_t result; // rax

result = 0LL;
if ( a1 )
result = strlen(a1);
return result;
}

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

result = 0LL;
if ( a1 )
result = strlen(a1);
return result;
}

original_code:
int DL_STR_StrLen ( const DL_CHAR *iStr )
{
 int len = 0;
 if ( iStr != ((void *)0) )
  len = (int)strlen(iStr);
 return len;
}

canonical_original_code:
int DL_STR_StrLen(unsigned char *iStr)
{
 int len = 0;
 if ( iStr != ((void *)0) )
  len = (int)strlen(iStr);
 return len;
}

variable_types:
iStr
unsigned char *

variable_types: len int

return_type: int


decompiled_code:
__int64 __fastcall DL_STR_StrLenExWS(char *a1)
{
char v1; // al
unsigned int v2; // ecx

if ( !a1 )
a1 = (char *)&kDL_STR_EmptyStr;
v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
if ( (unsigned __int8)(v1 - 9) > 4u )
v2 -= (v1 == 32) - 1;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
char v1; // al
unsigned int v2; // ecx

if ( !a1 )
a1 = (char *)&kDL_STR_EmptyStr;
v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
if ( (unsigned __int8)(v1 - 9) > 4u )
v2 -= (v1 == 32) - 1;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

original_code:
int DL_STR_StrLenExWS ( const DL_CHAR *iStr )
{
    int len = 0;
    iStr = ((iStr)==((void *)0)?kDL_STR_EmptyStr:(iStr));
    while ( *iStr != 0x00 )
    {
  if ( !((((*iStr)>=0x09)&&((*iStr)<=0x0D))||((*iStr)==0x20) ) )
   len++;
        iStr++;
    }
    return len;
}

canonical_original_code:
int DL_STR_StrLenExWS(unsigned char *iStr)
{
    int len = 0;
    iStr = ((iStr)==((void *)0)?kDL_STR_EmptyStr:(iStr));
    while ( *iStr != 0x00 )
    {
  if ( !((((*iStr)>=0x09)&&((*iStr)<=0x0D))||((*iStr)==0x20) ) )
   len++;
        iStr++;
    }
    return len;
}


decompiled_code:
__int64 __fastcall DL_STR_StrNCmp(_BYTE *a1, unsigned __int8 *a2, int a3, int a4)
{
_BYTE *v4; // r14
unsigned __int8 *v5; // r12
__int64 v7; // r13
unsigned __int8 v8; // bp
int v9; // ebx
int v10; // eax

v4 = a1;
v5 = a2;
if ( !a1 )
v4 = &kDL_STR_EmptyStr;
if ( !a2 )
v5 = (unsigned __int8 *)&kDL_STR_EmptyStr;
if ( a4 < 0 )
return 0LL;
v7 = 0LL;
while ( 1 )
{
LOBYTE(v9) = v4[v7];
if ( !(_BYTE)v9 )
return (unsigned int)-(*v5 != 0);
v8 = *v5;
if ( !*v5 )
return 1LL;
if ( a3 )
{
v9 = toupper((unsigned __int8)v9);
v10 = toupper(v8);
}
else
{
v9 = (unsigned __int8)v9;
v10 = v8;
}
if ( v9 < v10 )
return 0xFFFFFFFFLL;
if ( v9 > v10 )
break;
++v5;
if ( a4 < (int)++v7 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, unsigned __int8 *a2, int a3, int a4)
{
_BYTE *v4; // r14
unsigned __int8 *v5; // r12
__int64 v7; // r13
unsigned __int8 v8; // bp
int v9; // ebx
int v10; // eax

v4 = a1;
v5 = a2;
if ( !a1 )
v4 = &kDL_STR_EmptyStr;
if ( !a2 )
v5 = (unsigned __int8 *)&kDL_STR_EmptyStr;
if ( a4 < 0 )
return 0LL;
v7 = 0LL;
while ( 1 )
{
LOBYTE(v9) = v4[v7];
if ( !(_BYTE)v9 )
return (unsigned int)-(*v5 != 0);
v8 = *v5;
if ( !*v5 )
return 1LL;
if ( a3 )
{
v9 = toupper((unsigned __int8)v9);
v10 = toupper(v8);
}
else
{
v9 = (unsigned __int8)v9;
v10 = v8;
}
if ( v9 < v10 )
return 0xFFFFFFFFLL;
if ( v9 > v10 )
break;
++v5;
if ( a4 < (int)++v7 )
return 0LL;
}
return 1LL;
}

original_code:
int DL_STR_StrNCmp ( const DL_CHAR *iStr1,
         const DL_CHAR *iStr2,
         int iIgnoreCase,
         int iMaxChars )
{
 int retVal = 0;
 int ch1,ch2;
 int charCnt = 0;
 iStr1 = (((DL_CHAR*)iStr1)==((void *)0)?kDL_STR_EmptyStr:((DL_CHAR*)iStr1));
 iStr2 = (((DL_CHAR*)iStr2)==((void *)0)?kDL_STR_EmptyStr:((DL_CHAR*)iStr2));
 while ( charCnt <= iMaxChars )
 {
  if ( !(*iStr1) && !(*iStr2) )
  {
   retVal = 0;
   break;
  }
  else if ( !(*iStr1) )
  {
   retVal = -1;
   break;
  }
  else if ( !(*iStr2) )
  {
   retVal = 1;
   break;
  }
  else
  {
   if ( iIgnoreCase )
   {
    ch1 = toupper((int)*iStr1);
    ch2 = toupper((int)*iStr2);
   }
   else
   {
    ch1 = (int)*iStr1;
    ch2 = (int)*iStr2;
   }
   if ( ch1 < ch2 )
   {
    retVal = -1;
    break;
   }
   else if ( ch1 > ch2 )
   {
    retVal = 1;
    break;
   }
  }
  iStr1++;
  iStr2++;
  charCnt++;
 }
 return retVal;
}

canonical_original_code:
int DL_STR_StrNCmp(unsigned char *iStr1, unsigned char *iStr2, int iIgnoreCase, int iMaxChars)
{
 int retVal = 0;
 int ch1; int ch2;
 int charCnt = 0;
 iStr1 = (((unsigned char *)iStr1)==((void *)0)?kDL_STR_EmptyStr:((unsigned char *)iStr1));
 iStr2 = (((unsigned char *)iStr2)==((void *)0)?kDL_STR_EmptyStr:((unsigned char *)iStr2));
 while ( charCnt <= iMaxChars )
 {
  if ( !(*iStr1) && !(*iStr2) )
  {
   retVal = 0;
   break;
  }
  else if ( !(*iStr1) )
  {
   retVal = -1;
   break;
  }
  else if ( !(*iStr2) )
  {
   retVal = 1;
   break;
  }
  else
  {
   if ( iIgnoreCase )
   {
    ch1 = toupper((int)*iStr1);
    ch2 = toupper((int)*iStr2);
   }
   else
   {
    ch1 = (int)*iStr1;
    ch2 = (int)*iStr2;
   }
   if ( ch1 < ch2 )
   {
    retVal = -1;
    break;
   }
   else if ( ch1 > ch2 )
   {
    retVal = 1;
    break;
   }
  }
  iStr1++;
  iStr2++;
  charCnt++;
 }
 return retVal;
}

variable_types: iIgnoreCase int

variable_types: iMaxChars int

variable_types: retVal int

variable_types: charCnt int


decompiled_code:
__int64 __fastcall DL_STR_StrCmp(char *a1, char *a2, int a3)
{
int v4; // ebx
int v5; // eax

v4 = DL_STR_StrLen(a1);
v5 = DL_STR_StrLen(a2);
if ( v4 >= v5 )
v5 = v4;
return DL_STR_StrNCmp(a1, (unsigned __int8 *)a2, a3, v5);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, char *a2, int a3)
{
int v4; // ebx
int v5; // eax

v4 = func2(a1);
v5 = func2(a2);
if ( v4 >= v5 )
v5 = v4;
return func4(a1, (unsigned __int8 *)a2, a3, v5);
}

original_code:
int DL_STR_StrCmp ( const DL_CHAR *iStr1,
           const DL_CHAR *iStr2,
        int iIgnoreCase )
{
 return DL_STR_StrNCmp(iStr1,iStr2,iIgnoreCase,
        ((DL_STR_StrLen(iStr1))>(DL_STR_StrLen(iStr2))?(DL_STR_StrLen(iStr1)):(DL_STR_StrLen(iStr2))));
}

canonical_original_code:
int DL_STR_StrCmp(unsigned char *iStr1, unsigned char *iStr2, int iIgnoreCase)
{
 return DL_STR_StrNCmp(iStr1,iStr2,iIgnoreCase,
        ((DL_STR_StrLen(iStr1))>(DL_STR_StrLen(iStr2))?(DL_STR_StrLen(iStr1)):(DL_STR_StrLen(iStr2))));
}


decompiled_code:
void __fastcall DL_STR_StrCpy(void *dest, void *src, int a3)
{
if ( src )
{
if ( (int)DL_STR_StrLen((const char *)src) > a3 )
{
memcpy(dest, src, a3);
*((_BYTE *)dest + a3) = 0;
}
else
{
strcpy((char *)dest, (const char *)src);
}
}
else
{
*(_BYTE *)dest = 0;
}
}

canonical_decompiled_code:
void __fastcall func6(void *dest, void *src, int a3)
{
if ( src )
{
if ( (int)func2((const char *)src) > a3 )
{
memcpy(dest, src, a3);
*((_BYTE *)dest + a3) = 0;
}
else
{
strcpy((char *)dest, (const char *)src);
}
}
else
{
*(_BYTE *)dest = 0;
}
}

original_code:
void DL_STR_StrCpy ( DL_CHAR *ioToPtr,
         const DL_CHAR *iFromPtr,
         int iMaxChars )
{
 if ( iFromPtr == ((void *)0) )
 {
  ioToPtr[0] = 0x00;
 }
 else if ( DL_STR_StrLen(iFromPtr) <= iMaxChars )
 {
  (void)strcpy(ioToPtr,iFromPtr);
 }
 else
 {
  ((void)memcpy((void*)(ioToPtr),(void*)(iFromPtr),(size_t)(iMaxChars)));
  ioToPtr[iMaxChars] = 0x00;
 }
 return;
}

canonical_original_code:
void DL_STR_StrCpy(unsigned char *ioToPtr, unsigned char *iFromPtr, int iMaxChars)
{
 if ( iFromPtr == ((void *)0) )
 {
  ioToPtr[0] = 0x00;
 }
 else if ( DL_STR_StrLen(iFromPtr) <= iMaxChars )
 {
  (void)strcpy(ioToPtr,iFromPtr);
 }
 else
 {
  ((void)memcpy((void *)(ioToPtr),(void *)(iFromPtr),(unsigned long)(iMaxChars)));
  ioToPtr[iMaxChars] = 0x00;
 }
 return;
}

variable_types:
ioToPtr
unsigned char *

variable_types:
iFromPtr
unsigned char *


decompiled_code:
__int64 __fastcall DL_STR_StrNDup(void *src, __int64 a2, void **a3)
{
__int64 v3; // r12

*a3 = 0LL;
v3 = 1LL;
if ( src )
{
v3 = DL_MEM_malloc(a2 + 1, a3);
if ( !v3 )
DL_STR_StrCpy(*a3, src, a2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *src, __int64 a2, void **a3)
{
__int64 v3; // r12

*a3 = 0LL;
v3 = 1LL;
if ( src )
{
v3 = DL_MEM_malloc(a2 + 1, a3);
if ( !v3 )
func6(*a3, src, a2);
}
return v3;
}

original_code:
DL_ERR DL_STR_StrNDup ( const DL_CHAR *iStr,
         DL_UINT32 iMaxChars,
      DL_CHAR **oStr )
{
 DL_ERR err = (DL_ERR)0;
 *oStr = ((void *)0);
 if ( ((void *)0) == iStr )
 {
  err = (DL_ERR)1;
 }
 else if ( err = DL_MEM_malloc(iMaxChars+1,oStr) )
 {
 }
 else
 {
  DL_STR_StrCpy(*oStr,iStr,iMaxChars);
 }
 return err;
}

canonical_original_code:
unsigned long DL_STR_StrNDup(unsigned char *iStr, unsigned long iMaxChars, unsigned char **oStr)
{
 unsigned long err = (DL_ERR)0;
 *oStr = ((void *)0);
 if ( ((void *)0) == iStr )
 {
  err = (unsigned long)1;
 }
 else if ( err = DL_MEM_malloc(iMaxChars+1,oStr) )
 {
 }
 else
 {
  DL_STR_StrCpy(*oStr,iStr,iMaxChars);
 }
 return err;
}

variable_types:
iMaxChars
unsigned long

variable_types:
oStr
unsigned char **

variable_types:
err
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall DL_STR_StrDup(void *src, void **a2)
{
int v2; // eax

v2 = DL_STR_StrLen((const char *)src);
return DL_STR_StrNDup(src, v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(void *src, void **a2)
{
int v2; // eax

v2 = func2((const char *)src);
return func7(src, v2, a2);
}

original_code:
DL_ERR DL_STR_StrDup ( const DL_CHAR *iStr,
        DL_CHAR **oStr )
{
 return DL_STR_StrNDup(iStr,DL_STR_StrLen(iStr),oStr);
}

canonical_original_code:
unsigned long DL_STR_StrDup(unsigned char *iStr, unsigned char **oStr)
{
 return DL_STR_StrNDup(iStr,DL_STR_StrLen(iStr),oStr);
}


decompiled_code:
__int64 __fastcall DL_STR_StrCat(const char *a1, const char *a2, _QWORD *a3)
{
const char *v3; // rbp
const char *v4; // rbx
int v6; // er13
__int64 v7; // r14
int v9; // [rsp+Ch] [rbp-3Ch]

v3 = a1;
v4 = a2;
*a3 = 0LL;
if ( !a1 )
v3 = (const char *)&kDL_STR_EmptyStr;
if ( !a2 )
v4 = (const char *)&kDL_STR_EmptyStr;
v6 = DL_STR_StrLen(v3);
v9 = DL_STR_StrLen(v4);
v7 = DL_MEM_malloc(v6 + v9 + 1, a3);
if ( !v7 )
{
memcpy(a3, v3, v6);
memcpy(&a3[v6], v4, v9);
a3[v6 + v9] = 0LL;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, const char *a2, _QWORD *a3)
{
const char *v3; // rbp
const char *v4; // rbx
int v6; // er13
__int64 v7; // r14
int v9; // [rsp+Ch] [rbp-3Ch]

v3 = a1;
v4 = a2;
*a3 = 0LL;
if ( !a1 )
v3 = (const char *)&kDL_STR_EmptyStr;
if ( !a2 )
v4 = (const char *)&kDL_STR_EmptyStr;
v6 = func2(v3);
v9 = func2(v4);
v7 = DL_MEM_malloc(v6 + v9 + 1, a3);
if ( !v7 )
{
memcpy(a3, v3, v6);
memcpy(&a3[v6], v4, v9);
a3[v6 + v9] = 0LL;
}
return v7;
}

original_code:
DL_ERR DL_STR_StrCat ( const DL_CHAR *iStr1,
        const DL_CHAR *iStr2,
        DL_CHAR **oStr )
{
 DL_ERR err = (DL_ERR)0;
 int str1len = 0;
 int str2len = 0;
 *oStr = ((void *)0);
 iStr1 = ((iStr1)==((void *)0)?kDL_STR_EmptyStr:(iStr1));
 iStr2 = ((iStr2)==((void *)0)?kDL_STR_EmptyStr:(iStr2));
 str1len = DL_STR_StrLen(iStr1);
 str2len = DL_STR_StrLen(iStr2);
 err = DL_MEM_malloc(str1len+str2len+1,oStr);
 if ( !err )
 {
  ((void)memcpy((void*)(oStr),(void*)(iStr1),(size_t)(str1len)));
  ((void)memcpy((void*)(oStr+str1len),(void*)(iStr2),(size_t)(str2len)));
  oStr[str1len+str2len] = 0x00;
 }
 return err;
}

canonical_original_code:
unsigned long DL_STR_StrCat(unsigned char *iStr1, unsigned char *iStr2, unsigned char **oStr)
{
 unsigned long err = (DL_ERR)0;
 int str1len = 0;
 int str2len = 0;
 *oStr = ((void *)0);
 iStr1 = ((iStr1)==((void *)0)?kDL_STR_EmptyStr:(iStr1));
 iStr2 = ((iStr2)==((void *)0)?kDL_STR_EmptyStr:(iStr2));
 str1len = DL_STR_StrLen(iStr1);
 str2len = DL_STR_StrLen(iStr2);
 err = DL_MEM_malloc(str1len+str2len+1,oStr);
 if ( !err )
 {
  ((void)memcpy((void *)(oStr),(void *)(iStr1),(unsigned long)(str1len)));
  ((void)memcpy((void *)(oStr+str1len),(void *)(iStr2),(unsigned long)(str2len)));
  oStr[str1len+str2len] = 0x00;
 }
 return err;
}


decompiled_code:
const char *__fastcall DL_STR_RTrim(const char *a1, char a2)
{
const char *v2; // rbx
const char *result; // rax

v2 = a1;
if ( !a1 )
v2 = (const char *)&kDL_STR_EmptyStr;
result = &v2[(int)DL_STR_StrLen(v2)];
if ( v2 < result )
{
do
{
if ( *--result != a2 )
break;
*result = 0;
}
while ( v2 != result );
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func11(const char *a1, char a2)
{
const char *v2; // rbx
const char *result; // rax

v2 = a1;
if ( !a1 )
v2 = (const char *)&kDL_STR_EmptyStr;
result = &v2[(int)func2(v2)];
if ( v2 < result )
{
do
{
if ( *--result != a2 )
break;
*result = 0;
}
while ( v2 != result );
}
return result;
}

original_code:
void DL_STR_RTrim ( DL_CHAR *ioStr,
     DL_CHAR iTrimCh )
{
 DL_CHAR *ptr = ((void *)0);
 ioStr = ((ioStr)==((void *)0)?kDL_STR_EmptyStr:(ioStr));
 ptr = ioStr + DL_STR_StrLen(ioStr);
 while ( ptr > ioStr )
 {
  --ptr;
  if ( *ptr == iTrimCh )
   *ptr = 0x00;
  else
   break;
 }
 return;
}

canonical_original_code:
void DL_STR_RTrim(unsigned char *ioStr, unsigned char iTrimCh)
{
 unsigned char *ptr = ((void *)0);
 ioStr = ((ioStr)==((void *)0)?kDL_STR_EmptyStr:(ioStr));
 ptr = ioStr + DL_STR_StrLen(ioStr);
 while ( ptr > ioStr )
 {
  --ptr;
  if ( *ptr == iTrimCh )
   *ptr = 0x00;
  else
   break;
 }
 return;
}

variable_types:
ioStr
unsigned char *

variable_types:
iTrimCh
unsigned char

variable_types:
ptr
unsigned char *


decompiled_code:
void __fastcall DL_STR_ToUpper(_BYTE *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // al

if ( a1 )
{
v1 = a1 + 1;
if ( *a1 )
{
do
{
v2 = toupper(*v1);
*v1++ = v2;
}
while ( v2 );
}
}
}

canonical_decompiled_code:
void __fastcall func12(_BYTE *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // al

if ( a1 )
{
v1 = a1 + 1;
if ( *a1 )
{
do
{
v2 = toupper(*v1);
*v1++ = v2;
}
while ( v2 );
}
}
}

original_code:
void DL_STR_ToUpper ( DL_CHAR *ioStr )
{
 if ( ioStr != ((void *)0) )
 {
  while ( *ioStr++ != 0x00 )
  {
   *ioStr = (DL_CHAR)toupper((int)*ioStr);
  }
 }
 return;
}

canonical_original_code:
void DL_STR_ToUpper(unsigned char *ioStr)
{
 if ( ioStr != ((void *)0) )
 {
  while ( *ioStr++ != 0x00 )
  {
   *ioStr = (unsigned char)toupper((int)*ioStr);
  }
 }
 return;
}


decompiled_code:
__int64 __fastcall DL_STR_IsNumeric(char *a1)
{
__int64 result; // rax
char v2; // al

result = 0LL;
if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
do
{
if ( (unsigned __int8)(v2 - 48) > 9u )
return 0LL;
v2 = *++a1;
}
while ( *a1 );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1)
{
__int64 result; // rax
char v2; // al

result = 0LL;
if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
do
{
if ( (unsigned __int8)(v2 - 48) > 9u )
return 0LL;
v2 = *++a1;
}
while ( *a1 );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int DL_STR_IsNumeric ( const DL_CHAR *iStr )
{
 int ok = 0;
 if ( iStr != ((void *)0) )
 {
  ok = 1;
  while ( (*iStr != 0x00) && ok )
  {
   if ( !((*iStr >= '0') && (*iStr <= '9')) )
    ok = 0;
   iStr++;
  }
 }
 return ok;
}

canonical_original_code:
int DL_STR_IsNumeric(unsigned char *iStr)
{
 int ok = 0;
 if ( iStr != ((void *)0) )
 {
  ok = 1;
  while ( (*iStr != 0x00) && ok )
  {
   if ( !((*iStr >= '0') && (*iStr <= '9')) )
    ok = 0;
   iStr++;
  }
 }
 return ok;
}

variable_types: ok int


decompiled_code:
_BOOL8 __fastcall DL_STR_Validate(const char *a1, int a2, int a3, const char *a4)
{
_BOOL4 v4; // ebx
int v7; // er14
__int64 i; // rbp

v4 = 0;
if ( a1 )
{
v4 = 1;
if ( a2 != -1 )
v4 = (int)DL_STR_StrLen(a1) >= a2;
if ( a3 != -1 && v4 && (int)DL_STR_StrLen(a1) > a3 )
{
v4 = 0;
}
else if ( a4 && v4 )
{
v7 = DL_STR_StrLen(a1);
for ( i = 0LL; v4 && v7 > (int)i; ++i )
{
if ( !strchr(a4, (unsigned __int8)a1[i]) )
v4 = 0;
}
}
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(const char *a1, int a2, int a3, const char *a4)
{
_BOOL4 v4; // ebx
int v7; // er14
__int64 i; // rbp

v4 = 0;
if ( a1 )
{
v4 = 1;
if ( a2 != -1 )
v4 = (int)func2(a1) >= a2;
if ( a3 != -1 && v4 && (int)func2(a1) > a3 )
{
v4 = 0;
}
else if ( a4 && v4 )
{
v7 = func2(a1);
for ( i = 0LL; v4 && v7 > (int)i; ++i )
{
if ( !strchr(a4, (unsigned __int8)a1[i]) )
v4 = 0;
}
}
}
return v4;
}

original_code:
int DL_STR_Validate ( const DL_CHAR *iStr,
       int iMinLen,
          int iMaxLen,
       const DL_CHAR *iValidChars )
{
 int ok = 0;
 int i;
 if ( iStr != ((void *)0) )
 {
  ok = 1;
  if ( (iMinLen != -1) && ((int)DL_STR_StrLen(iStr) < iMinLen) )
   ok = 0;
  if ( ok && (iMaxLen != -1) && ((int)DL_STR_StrLen(iStr) > iMaxLen) )
   ok = 0;
  if ( ok && (iValidChars != ((void *)0)) )
  {
   for ( i=0 ; (i<(int)DL_STR_StrLen(iStr)) && ok ; i++ )
    if ( strchr(iValidChars,(int)(iStr[i])) == ((void *)0) )
     ok = 0;
  }
 }
 return ok;
}

canonical_original_code:
int DL_STR_Validate(unsigned char *iStr, int iMinLen, int iMaxLen, unsigned char *iValidChars)
{
 int ok = 0;
 int i;
 if ( iStr != ((void *)0) )
 {
  ok = 1;
  if ( (iMinLen != -1) && ((int)DL_STR_StrLen(iStr) < iMinLen) )
   ok = 0;
  if ( ok && (iMaxLen != -1) && ((int)DL_STR_StrLen(iStr) > iMaxLen) )
   ok = 0;
  if ( ok && (iValidChars != ((void *)0)) )
  {
   for ( i=0 ; (i<(int)DL_STR_StrLen(iStr)) && ok ; i++ )
    if ( strchr(iValidChars,(int)(iStr[i])) == ((void *)0) )
     ok = 0;
  }
 }
 return ok;
}

variable_types: iMinLen int

variable_types: iMaxLen int

variable_types:
iValidChars
unsigned char *

variable_types: i int


decompiled_code:
char *__fastcall DL_STR_Contains(_BYTE *a1, const char *a2)
{
_BYTE *v2; // rbx
char *result; // rax
unsigned __int8 v5; // si

if ( !a1 )
return 0LL;
v2 = a1;
result = 0LL;
if ( a2 )
{
v5 = *a1;
if ( *a1 )
{
while ( 1 )
{
result = strchr(a2, v5);
if ( result )
break;
v5 = *++v2;
if ( !*v2 )
return result;
}
result = (_BYTE *)(unescape_string + 1);
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func15(_BYTE *a1, const char *a2)
{
_BYTE *v2; // rbx
char *result; // rax
unsigned __int8 v5; // si

if ( !a1 )
return 0LL;
v2 = a1;
result = 0LL;
if ( a2 )
{
v5 = *a1;
if ( *a1 )
{
while ( 1 )
{
result = strchr(a2, v5);
if ( result )
break;
v5 = *++v2;
if ( !*v2 )
return result;
}
result = (_BYTE *)(unescape_string + 1);
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int DL_STR_Contains ( const DL_CHAR *iStr,
       const DL_CHAR *iContains )
{
 int ret = 0;
 if ( (iStr != ((void *)0)) && (iContains != ((void *)0)) )
 {
  while ( *iStr != 0x00 )
  {
   if ( strchr(iContains,(int)(*iStr)) != ((void *)0) )
   {
    ret = 1;
    break;
   }
   iStr++;
  }
 }
 return ret;
}

canonical_original_code:
int DL_STR_Contains(unsigned char *iStr, unsigned char *iContains)
{
 int ret = 0;
 if ( (iStr != ((void *)0)) && (iContains != ((void *)0)) )
 {
  while ( *iStr != 0x00 )
  {
   if ( strchr(iContains,(int)(*iStr)) != ((void *)0) )
   {
    ret = 1;
    break;
   }
   iStr++;
  }
 }
 return ret;
}

variable_types:
iStr
unsigned char *

variable_types:
iContains
unsigned char *

variable_types: ret int


decompiled_code:
__int64 __fastcall DL_STR_EncapsulateStr(const char *a1, char a2, void **a3)
{
const char *v3; // rbx
int v5; // eax
__int64 v6; // r14
char *v7; // rdx
char *v8; // rdx
char v9; // al
void *ptr; // [rsp+8h] [rbp-30h] BYREF

v3 = a1;
ptr = 0LL;
*a3 = 0LL;
v5 = DL_STR_StrLen(a1);
v6 = DL_MEM_malloc(2 * v5 + 3, &ptr);
if ( !v6 )
{
v7 = (char *)ptr;
*(_BYTE *)ptr = a2;
v8 = v7 + 1;
v9 = *a1;
if ( *a1 )
{
do
{
if ( a2 == v9 )
{
*v8 = 92;
v8[1] = a2;
v8 += 2;
}
else if ( v9 == 92 )
{
*v8 = 92;
v8[1] = 92;
v8 += 2;
}
else
{
*v8++ = v9;
}
v9 = *++v3;
}
while ( *v3 );
}
*v8 = a2;
v8[1] = 0;
v6 = DL_STR_StrDup(ptr, a3);
}
if ( ptr )
free(ptr);
return v6;
}

original_code:
DL_ERR DL_STR_EncapsulateStr ( const DL_CHAR *iStr,
          DL_CHAR iEncapChar,
          DL_CHAR **oStr )
{
 DL_ERR err = (DL_ERR)0;
 DL_CHAR *bufPtr = ((void *)0);
 *oStr = ((void *)0);
 err = DL_MEM_malloc((DL_STR_StrLen(iStr)*2)+2+1,&bufPtr);
 if ( !err )
 {
  DL_CHAR *readPtr = (DL_CHAR*)iStr;
  DL_CHAR *writePtr = (DL_CHAR*)bufPtr;
  writePtr[0] = iEncapChar;
  writePtr += 1;
  while ( 0x00 != *readPtr )
  {
   if ( iEncapChar == *readPtr )
   {
    writePtr[0] = 0x5C;
    writePtr[1] = iEncapChar;
    writePtr += 2;
   }
   else if ( 0x5C == *readPtr )
   {
    writePtr[0] = 0x5C;
    writePtr[1] = 0x5C;
    writePtr += 2;
   }
   else
   {
    writePtr[0] = readPtr[0];
    writePtr++;
   }
   readPtr++;
  }
  writePtr[0] = iEncapChar;
  writePtr[1] = 0x00;
  writePtr += 2;
  err = DL_STR_StrDup(bufPtr,oStr);
 }
 { if ( (bufPtr) != ((void *)0) ) { free(bufPtr) ; (bufPtr) = ((void *)0) ; } };
 return err;
}

canonical_original_code:
unsigned long DL_STR_EncapsulateStr(unsigned char *iStr, unsigned char iEncapChar, unsigned char **oStr)
{
 unsigned long err = (DL_ERR)0;
 unsigned char *bufPtr = ((void *)0);
 *oStr = ((void *)0);
 err = DL_MEM_malloc((DL_STR_StrLen(iStr)*2)+2+1,&bufPtr);
 if ( !err )
 {
  unsigned char *readPtr = (DL_CHAR*)iStr;
  unsigned char *writePtr = (DL_CHAR*)bufPtr;
  writePtr[0] = iEncapChar;
  writePtr += 1;
  while ( 0x00 != *readPtr )
  {
   if ( iEncapChar == *readPtr )
   {
    writePtr[0] = 0x5C;
    writePtr[1] = iEncapChar;
    writePtr += 2;
   }
   else if ( 0x5C == *readPtr )
   {
    writePtr[0] = 0x5C;
    writePtr[1] = 0x5C;
    writePtr += 2;
   }
   else
   {
    writePtr[0] = readPtr[0];
    writePtr++;
   }
   readPtr++;
  }
  writePtr[0] = iEncapChar;
  writePtr[1] = 0x00;
  writePtr += 2;
  err = DL_STR_StrDup(bufPtr,oStr);
 }
 { if ( (bufPtr) != ((void *)0) ) { free(bufPtr) ; (bufPtr) = ((void *)0) ; } };
 return err;
}

variable_types:
iEncapChar
unsigned char

variable_types:
bufPtr
unsigned char *

variable_types:
readPtr
unsigned char *

variable_types:
writePtr
unsigned char *


decompiled_code:
__int64 __fastcall DL_STR_GetEncapsulatedStr(_BYTE *a1, char a2, void **a3, _QWORD *a4)
{
__int64 v7; // r14
char *v9; // rdi
char v10; // al
char *v11; // rbx

*a3 = 0LL;
*a4 = a1;
v7 = 1LL;
if ( *a1 != a2 )
goto LABEL_2;
v9 = a1 + 1;
v10 = a1[1];
if ( !v10 )
{
v7 = 1LL;
LABEL_2:
if ( *a3 )
{
free(*a3);
*a3 = 0LL;
}
*a4 = a1;
return v7;
}
v11 = v9;
while ( v10 == 92 )
{
if ( !v11[1] )
{
v7 = 1LL;
goto LABEL_2;
}
v11 += 2;
LABEL_11:
v10 = *v11;
if ( !*v11 )
{
v7 = 1LL;
goto LABEL_2;
}
}
if ( a2 != v10 )
{
++v11;
goto LABEL_11;
}
v7 = DL_STR_StrNDup(v9, v11 - a1 - 1, a3);
if ( v7 )
goto LABEL_2;
*a4 = v11 + 1;
unescape_string(92LL, (unsigned __int8 *)*a3);
return v7;
}

original_code:
DL_ERR DL_STR_GetEncapsulatedStr ( const DL_CHAR *iStr,
           DL_CHAR iEncapChar,
           DL_CHAR **oDataStr,
           DL_CHAR **oNextPtr )
{
 DL_ERR err = (DL_ERR)0;
 DL_CHAR *startPtr = (DL_CHAR*)iStr;
 *oDataStr = ((void *)0);
 *oNextPtr = (DL_CHAR*)iStr;
 if ( *startPtr != iEncapChar )
 {
  err = (DL_ERR)1;
 }
 else
 {
  DL_CHAR *endPtr = startPtr + 1;
  while ( 1 )
  {
   if ( *endPtr == 0x00 )
   {
    err = (DL_ERR)1;
    break;
   }
   else if ( 0x5C == *endPtr )
   {
    endPtr++;
    if ( *endPtr == 0x00 )
    {
     err = (DL_ERR)1;
     break;
    }
    endPtr++;
   }
   else if ( *endPtr == iEncapChar )
   {
    break;
   }
   else
   {
    endPtr++;
   }
  }
  if ( !err )
  {
   err = DL_STR_StrNDup(startPtr+1,endPtr-startPtr-1,oDataStr);
   if ( !err )
   {
    *oNextPtr = endPtr + 1;
    unescape_string(0x5C,*oDataStr);
   }
  }
 }
 if ( err )
 {
  { if ( (*oDataStr) != ((void *)0) ) { free(*oDataStr) ; (*oDataStr) = ((void *)0) ; } };
  *oNextPtr = (DL_CHAR*)iStr;
 }
 return err;
}

canonical_original_code:
unsigned long DL_STR_GetEncapsulatedStr(unsigned char *iStr, unsigned char iEncapChar, unsigned char **oDataStr, unsigned char **oNextPtr)
{
 unsigned long err = (DL_ERR)0;
 unsigned char *startPtr = (DL_CHAR*)iStr;
 *oDataStr = ((void *)0);
 *oNextPtr = (unsigned char *)iStr;
 if ( *startPtr != iEncapChar )
 {
  err = (unsigned long)1;
 }
 else
 {
  unsigned char *endPtr = startPtr + 1;
  while ( 1 )
  {
   if ( *endPtr == 0x00 )
   {
    err = (unsigned long)1;
    break;
   }
   else if ( 0x5C == *endPtr )
   {
    endPtr++;
    if ( *endPtr == 0x00 )
    {
     err = (unsigned long)1;
     break;
    }
    endPtr++;
   }
   else if ( *endPtr == iEncapChar )
   {
    break;
   }
   else
   {
    endPtr++;
   }
  }
  if ( !err )
  {
   err = DL_STR_StrNDup(startPtr+1,endPtr-startPtr-1,oDataStr);
   if ( !err )
   {
    *oNextPtr = endPtr + 1;
    unescape_string(0x5C,*oDataStr);
   }
  }
 }
 if ( err )
 {
  { if ( (*oDataStr) != ((void *)0) ) { free(*oDataStr) ; (*oDataStr) = ((void *)0) ; } };
  *oNextPtr = (unsigned char *)iStr;
 }
 return err;
}

variable_types:
oDataStr
unsigned char **

variable_types:
oNextPtr
unsigned char **

variable_types:
startPtr
unsigned char *

variable_types:
endPtr
unsigned char *


decompiled_code:
__int64 __fastcall DL_MEM_callocWithInit(size_t a1, size_t a2, _QWORD *a3)
{
__int64 v3; // rbx
void *v6; // rdi

v3 = a1;
*a3 = 0LL;
if ( a1 )
{
v6 = calloc(a1, a2);
*a3 = v6;
if ( v6 )
{
memset(v6, 0, a2 * v3);
v3 = 0LL;
}
else
{
v3 = 1000LL;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(size_t a1, size_t a2, _QWORD *a3)
{
__int64 v3; // rbx
void *v6; // rdi

v3 = a1;
*a3 = 0LL;
if ( a1 )
{
v6 = calloc(a1, a2);
*a3 = v6;
if ( v6 )
{
memset(v6, 0, a2 * v3);
v3 = 0LL;
}
else
{
v3 = 1000LL;
}
}
return v3;
}

original_code:
DL_ERR DL_MEM_callocWithInit ( DL_UINT32 numItems,
          size_t itemSize,
          void **out )
{
 DL_ERR err = 0;
 *out = ((void *)0);
 if ( numItems > 0 )
 {
  if ( (*out = (void*)calloc(numItems,itemSize)) == ((void *)0) )
  {
   err = (DL_ERR)(1000+0);
  }
  else
  {
   ((void)memset((void*)(*out),(int)(0),(size_t)(numItems*itemSize)));
  }
 }
 if ( err )
 {
  { if ( (*out) != ((void *)0) ) { free(*out) ; (*out) = ((void *)0) ; } };
 }
 return err;
}

canonical_original_code:
unsigned long DL_MEM_callocWithInit(unsigned long numItems, unsigned long itemSize, void **out)
{
 unsigned long err = 0;
 *out = ((void *)0);
 if ( numItems > 0 )
 {
  if ( (*out = (void *)calloc(numItems,itemSize)) == ((void *)0) )
  {
   err = (DL_ERR)(1000+0);
  }
  else
  {
   ((void)memset((void *)(*out),(int)(0),(unsigned long)(numItems*itemSize)));
  }
 }
 if ( err )
 {
  { if ( (*out) != ((void *)0) ) { free(*out) ; (*out) = ((void *)0) ; } };
 }
 return err;
}

variable_types:
numItems
unsigned long

variable_types:
itemSize
unsigned long

variable_types:
out
void **

variable_types:
err
unsigned long


decompiled_code:
__int64 __fastcall DL_MEM_malloc(size_t a1, _QWORD *a2)
{
return DL_MEM_callocWithInit(1uLL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(size_t a1, _QWORD *a2)
{
return func0(1uLL, a1, a2);
}

original_code:
DL_ERR DL_MEM_malloc ( DL_UINT32 iNumBytes,
        void **oPtr )
{
 DL_ERR err = 0;
 err = DL_MEM_callocWithInit(1,iNumBytes,oPtr);
 return err;
}

canonical_original_code:
unsigned long DL_MEM_malloc(unsigned long iNumBytes, void **oPtr)
{
 unsigned long err = 0;
 err = DL_MEM_callocWithInit(1,iNumBytes,oPtr);
 return err;
}

variable_types:
iNumBytes
unsigned long

variable_types:
oPtr
void **


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

*a3 = 0LL;
a3[259] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 8) & 0xFFFFFFF8) + 2080) >> 3));
if ( a1 )
{
*a3 = a1;
a3[1] = a1 + a2;
}
return result;
}

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

*a3 = 0LL;
a3[259] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 8) & 0xFFFFFFF8) + 2080) >> 3));
if ( a1 )
{
*a3 = a1;
a3[1] = a1 + a2;
}
return result;
}

original_code:
void DL_ISO8583_MSG_Init ( DL_UINT8 *_iStaticBuf,
               DL_UINT16 _iStaticBufSize,
               DL_ISO8583_MSG *ioMsg )
{
 ((void)memset((void*)((void*)ioMsg),(int)(0),(size_t)(sizeof(DL_ISO8583_MSG))));
 if ( _iStaticBuf )
 {
  ioMsg->sPtrNext = _iStaticBuf;
  ioMsg->sPtrEnd = (ioMsg->sPtrNext) + _iStaticBufSize;
 }
 return;
}

canonical_original_code:
void DL_ISO8583_MSG_Init(unsigned char *_iStaticBuf, unsigned int _iStaticBufSize, struct DL_ISO8583_MSG_S *ioMsg)
{
 ((void)memset((void *)((void *)ioMsg),(int)(0),(unsigned long)(sizeof(DL_ISO8583_MSG))));
 if ( _iStaticBuf )
 {
  ioMsg->sPtrNext = _iStaticBuf;
  ioMsg->sPtrEnd = (ioMsg->sPtrNext) + _iStaticBufSize;
 }
 return;
}

variable_types: struct DL_ISO8583_MSG_S { unsigned char *sPtrNext; unsigned char *sPtrEnd; struct DL_ISO8583_MSG_FIELD_S { unsigned int len; unsigned char *ptr; } field[-1]; } *

user_defined_types: struct DL_ISO8583_MSG_S { unsigned char *sPtrNext; unsigned char *sPtrEnd; struct DL_ISO8583_MSG_FIELD_S field[-1]; }


decompiled_code:
__int64 __fastcall DL_ISO8583_MSG_Free(_QWORD *a1)
{
__int64 result; // rax
void **v2; // rbx

if ( !*a1 )
{
v2 = (void **)(a1 + 3);
do
{
if ( *v2 )
{
free(*v2);
*v2 = 0LL;
}
v2 += 2;
}
while ( v2 != a1 + 261 );
}
*a1 = 0LL;
a1[259] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 2080) >> 3));
return result;
}

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

if ( !*a1 )
{
v2 = (void **)(a1 + 3);
do
{
if ( *v2 )
{
free(*v2);
*v2 = 0LL;
}
v2 += 2;
}
while ( v2 != a1 + 261 );
}
*a1 = 0LL;
a1[259] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 2080) >> 3));
return result;
}

original_code:
void DL_ISO8583_MSG_Free ( DL_ISO8583_MSG *ioMsg )
{
 if ( ((void *)0) == ioMsg->sPtrNext )
 {
  int i;
  for ( i=0; i<=128 ; i++ )
  {
   { if ( (ioMsg->field[i].ptr) != ((void *)0) ) { free(ioMsg->field[i].ptr) ; (ioMsg->field[i].ptr) = ((void *)0) ; } };
  }
 }
 ((void)memset((void*)((void*)ioMsg),(int)(0),(size_t)(sizeof(DL_ISO8583_MSG))));
 return;
}

canonical_original_code:
void DL_ISO8583_MSG_Free(struct DL_ISO8583_MSG_S *ioMsg)
{
 if ( ((void *)0) == ioMsg->sPtrNext )
 {
  int i;
  for ( i=0; i<=128 ; i++ )
  {
   { if ( (ioMsg->field[i].ptr) != ((void *)0) ) { free(ioMsg->field[i].ptr) ; (ioMsg->field[i].ptr) = ((void *)0) ; } };
  }
 }
 ((void)memset((void *)((void *)ioMsg),(int)(0),(unsigned long)(sizeof(DL_ISO8583_MSG))));
 return;
}

variable_types: i int

user_defined_types: struct DL_ISO8583_MSG_FIELD_S { unsigned int len; unsigned char *ptr; }


decompiled_code:
__int64 __fastcall DL_ISO8583_MSG_SetField_Bin(__int64 a1, const void *a2, unsigned int a3, __int64 a4)
{
__int64 v4; // rbx
void *dest; // [rsp+8h] [rbp-20h] BYREF

dest = 0LL;
v4 = 1LL;
if ( (unsigned int)a1 <= 0x80 )
{
v4 = DL_ISO8583_MSG_AllocField(a1, a3, a4, &dest);
if ( !v4 )
{
memcpy(dest, a2, a3);
*((_BYTE *)dest + a3) = 0;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2, unsigned int a3, __int64 a4)
{
__int64 v4; // rbx
void *dest; // [rsp+8h] [rbp-20h] BYREF

dest = 0LL;
v4 = 1LL;
if ( (unsigned int)a1 <= 0x80 )
{
v4 = DL_ISO8583_MSG_AllocField(a1, a3, a4, &dest);
if ( !v4 )
{
memcpy(dest, a2, a3);
*((_BYTE *)dest + a3) = 0;
}
}
return v4;
}

original_code:
DL_ERR DL_ISO8583_MSG_SetField_Bin ( DL_UINT16 iField,
                      const DL_UINT8 *_iData,
                      DL_UINT16 _iDataLen,
                      DL_ISO8583_MSG *ioMsg )
{
 DL_ERR err = (DL_ERR)0;
 DL_UINT8 *ptr = ((void *)0);
 if ( iField > 128 )
  return (DL_ERR)1;
 err = _DL_ISO8583_MSG_AllocField(iField,_iDataLen,ioMsg,&ptr);
 if ( !err )
 {
  ((void)memcpy((void*)(ptr),(void*)(_iData),(size_t)(_iDataLen)));
  ptr[_iDataLen] = 0x00;
 }
 return err;
}

canonical_original_code:
unsigned long DL_ISO8583_MSG_SetField_Bin(unsigned int iField, unsigned char *_iData, unsigned int _iDataLen, struct DL_ISO8583_MSG_S *ioMsg)
{
 unsigned long err = (DL_ERR)0;
 unsigned char *ptr = ((void *)0);
 if ( iField > 128 )
  return (unsigned long)1;
 err = _DL_ISO8583_MSG_AllocField(iField,_iDataLen,ioMsg,&ptr);
 if ( !err )
 {
  ((void)memcpy((void *)(ptr),(void *)(_iData),(unsigned long)(_iDataLen)));
  ptr[_iDataLen] = 0x00;
 }
 return err;
}

variable_types:
iField
unsigned int

variable_types:
ptr
unsigned char *


decompiled_code:
__int64 __fastcall DL_ISO8583_MSG_SetField_Str(unsigned int a1, const void *a2, __int64 a3)
{
unsigned int v4; // eax

v4 = DL_STR_StrLen(a2);
return DL_ISO8583_MSG_SetField_Bin(a1, a2, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, const void *a2, __int64 a3)
{
unsigned int v4; // eax

v4 = DL_STR_StrLen(a2);
return func2(a1, a2, v4, a3);
}

original_code:
DL_ERR DL_ISO8583_MSG_SetField_Str ( DL_UINT16 iField,
                      const DL_UINT8 *iDataStr,
                   DL_ISO8583_MSG *ioMsg )
{
 DL_ERR err = (DL_ERR)0;
 err = DL_ISO8583_MSG_SetField_Bin(iField,
           iDataStr,
           (DL_UINT16)DL_STR_StrLen(iDataStr),
           ioMsg);
 return err;
}

canonical_original_code:
unsigned long DL_ISO8583_MSG_SetField_Str(unsigned int iField, unsigned char *iDataStr, struct DL_ISO8583_MSG_S *ioMsg)
{
 unsigned long err = (DL_ERR)0;
 err = DL_ISO8583_MSG_SetField_Bin(iField,
           iDataStr,
           (unsigned int)DL_STR_StrLen(iDataStr),
           ioMsg);
 return err;
}

variable_types:
iDataStr
unsigned char *


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

if ( a2 && a1 <= 0x80 )
result = *(_QWORD *)(16LL * a1 + a2 + 24) != 0LL;
else
result = 0LL;
return result;
}

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

if ( a2 && a1 <= 0x80 )
result = *(_QWORD *)(16LL * a1 + a2 + 24) != 0LL;
else
result = 0LL;
return result;
}

original_code:
int DL_ISO8583_MSG_HaveField ( DL_UINT16 iField,
                const DL_ISO8583_MSG *iMsg )
{
 if ( (((void *)0) != iMsg) &&
   (iField <= 128) &&
   (((void *)0) != iMsg->field[iField].ptr) )
 {
  return 1;
 }
 return 0;
}

canonical_original_code:
int DL_ISO8583_MSG_HaveField(unsigned int iField, struct DL_ISO8583_MSG_S *iMsg)
{
 if ( (((void *)0) != iMsg) &&
   (iField <= 128) &&
   (((void *)0) != iMsg->field[iField].ptr) )
 {
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall DL_ISO8583_MSG_GetField_Str(unsigned int a1, __int64 a2, _QWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

*a3 = 0LL;
if ( !a2 || a1 > 0x80 )
return 1LL;
v3 = *(_QWORD *)(16LL * a1 + a2 + 24);
result = 1LL;
if ( v3 )
{
*a3 = v3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2, _QWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

*a3 = 0LL;
if ( !a2 || a1 > 0x80 )
return 1LL;
v3 = *(_QWORD *)(16LL * a1 + a2 + 24);
result = 1LL;
if ( v3 )
{
*a3 = v3;
result = 0LL;
}
return result;
}

original_code:
DL_ERR DL_ISO8583_MSG_GetField_Str ( DL_UINT16 iField,
                const DL_ISO8583_MSG *iMsg,
          DL_UINT8 **oPtr )
{
 DL_ERR err = (DL_ERR)1;
 *oPtr = ((void *)0);
 if ( (((void *)0) != iMsg) &&
   (iField <= 128) &&
   (((void *)0) != iMsg->field[iField].ptr) )
 {
  err = (DL_ERR)0;
  *oPtr = iMsg->field[iField].ptr;
 }
 return err;
}

canonical_original_code:
unsigned long DL_ISO8583_MSG_GetField_Str(unsigned int iField, struct DL_ISO8583_MSG_S *iMsg, unsigned char **oPtr)
{
 unsigned long err = (DL_ERR)1;
 *oPtr = ((void *)0);
 if ( (((void *)0) != iMsg) &&
   (iField <= 128) &&
   (((void *)0) != iMsg->field[iField].ptr) )
 {
  err = (unsigned long)0;
  *oPtr = iMsg->field[iField].ptr;
 }
 return err;
}

variable_types:
oPtr
unsigned char **


decompiled_code:
__int64 __fastcall DL_ISO8583_MSG_GetField_Bin(unsigned int a1, __int64 a2, _QWORD *a3, _DWORD *a4)
{
__int64 v4; // rdi
__int64 v5; // rsi
__int64 result; // rax

*a3 = 0LL;
*a4 = 0;
if ( !a2 || a1 > 0x80 )
return 1LL;
v4 = a2 + 16LL * a1;
v5 = *(_QWORD *)(v4 + 24);
result = 1LL;
if ( v5 )
{
*a3 = v5;
*a4 = *(_DWORD *)(v4 + 16);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, __int64 a2, _QWORD *a3, _DWORD *a4)
{
__int64 v4; // rdi
__int64 v5; // rsi
__int64 result; // rax

*a3 = 0LL;
*a4 = 0;
if ( !a2 || a1 > 0x80 )
return 1LL;
v4 = a2 + 16LL * a1;
v5 = *(_QWORD *)(v4 + 24);
result = 1LL;
if ( v5 )
{
*a3 = v5;
*a4 = *(_DWORD *)(v4 + 16);
result = 0LL;
}
return result;
}

original_code:
DL_ERR DL_ISO8583_MSG_GetField_Bin ( DL_UINT16 iField,
             const DL_ISO8583_MSG *iMsg,
          DL_UINT8 **oPtr,
          DL_UINT16 *oByteLen )
{
 DL_ERR err = (DL_ERR)1;
 *oPtr = ((void *)0);
 *oByteLen = 0;
 if ( (((void *)0) != iMsg) &&
   (iField <= 128) &&
   (((void *)0) != iMsg->field[iField].ptr) )
 {
  err = (DL_ERR)0;
  *oPtr = iMsg->field[iField].ptr;
  *oByteLen = iMsg->field[iField].len;
 }
 return err;
}

canonical_original_code:
unsigned long DL_ISO8583_MSG_GetField_Bin(unsigned int iField, struct DL_ISO8583_MSG_S *iMsg, unsigned char **oPtr, unsigned int *oByteLen)
{
 unsigned long err = (DL_ERR)1;
 *oPtr = ((void *)0);
 *oByteLen = 0;
 if ( (((void *)0) != iMsg) &&
   (iField <= 128) &&
   (((void *)0) != iMsg->field[iField].ptr) )
 {
  err = (unsigned long)0;
  *oPtr = iMsg->field[iField].ptr;
  *oByteLen = iMsg->field[iField].len;
 }
 return err;
}

variable_types:
oByteLen
unsigned int *


original_code:
DL_ERR DL_ISO8583_MSG_Pack ( const DL_ISO8583_HANDLER *iHandler,
              const DL_ISO8583_MSG *iMsg,
                       DL_UINT8 *ioByteArr,
                    DL_UINT16 *oNumBytes )
{
 DL_ERR err = (DL_ERR)0;
 DL_UINT8 *curPtr = ioByteArr;
 DL_UINT16 fieldIdx;
 *oNumBytes = 0;
 for ( fieldIdx=0 ; (fieldIdx<((iHandler->fieldItems)<(128 +1)?(iHandler->fieldItems):(128 +1))) && !err ; fieldIdx++ )
 {
  if ( (((void *)0) != iMsg->field[fieldIdx].ptr) ||
    (10==(iHandler->fieldArr[fieldIdx].fieldType)) )
  {
   err = _DL_ISO8583_FIELD_Pack(fieldIdx,iMsg,iHandler,&curPtr);
  }
 }
 if ( !err )
 {
  *oNumBytes = (int)(curPtr - ioByteArr);
 }
 return err;
}

canonical_original_code:
unsigned long DL_ISO8583_MSG_Pack(struct DL_ISO8583_HANDLER_S *iHandler, struct DL_ISO8583_MSG_S *iMsg, unsigned char *ioByteArr, unsigned int *oNumBytes)
{
 unsigned long err = (DL_ERR)0;
 unsigned char *curPtr = ioByteArr;
 unsigned int fieldIdx;
 *oNumBytes = 0;
 for ( fieldIdx=0 ; (fieldIdx<((iHandler->fieldItems)<(128 +1)?(iHandler->fieldItems):(128 +1))) && !err ; fieldIdx++ )
 {
  if ( (((void *)0) != iMsg->field[fieldIdx].ptr) ||
    (10==(iHandler->fieldArr[fieldIdx].fieldType)) )
  {
   err = _DL_ISO8583_FIELD_Pack(fieldIdx,iMsg,iHandler,&curPtr);
  }
 }
 if ( !err )
 {
  *oNumBytes = (int)(curPtr - ioByteArr);
 }
 return err;
}

variable_types: struct DL_ISO8583_HANDLER_S { struct DL_ISO8583_FIELD_DEF_S { unsigned char fieldType; unsigned int len; unsigned char varLen; } *fieldArr; unsigned char fieldItems; } *

variable_types:
ioByteArr
unsigned char *

variable_types:
oNumBytes
unsigned int *

variable_types:
curPtr
unsigned char *

variable_types:
fieldIdx
unsigned int


decompiled_code:
__int64 __fastcall DL_ISO8583_MSG_Unpack(__int64 a1, unsigned __int64 a2, unsigned int a3, __int64 a4)
{
unsigned __int64 v5; // r12
unsigned __int8 v6; // r14
unsigned int v7; // er14
__int64 result; // rax
unsigned int v9; // ebx
char v10; // dl
__int64 v11[8]; // [rsp+8h] [rbp-40h] BYREF

v11[0] = a2;
v5 = a2 + a3;
v6 = *(_BYTE *)(a1 + 8);
if ( v6 > 0x81u )
{
v7 = 128;
}
else
{
v7 = v6 - 1;
if ( !v7 )
return v11[0] != v5;
}
if ( a2 >= v5 )
{
v9 = 0;
goto LABEL_15;
}
v9 = 0;
while ( 1 )
{
result = DL_ISO8583_FIELD_Unpack(v9, a4, a1, v11);
v10 = *(_BYTE *)(*(_QWORD *)a1 + 12LL * v9++);
if ( result || v9 >= v7 )
break;
if ( v11[0] >= v5 || v10 == 10 )
{
LABEL_15:
while ( v11[0] < v5 )
{
result = 0LL;
if ( *(_DWORD *)(16LL * v9 + a4 + 16) )
result = DL_ISO8583_FIELD_Unpack(v9, a4, a1, v11);
++v9;
if ( result || v9 >= v7 )
goto LABEL_18;
}
return v11[0] != v5;
}
}
LABEL_18:
if ( result )
return result;
return v11[0] != v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int64 a2, unsigned int a3, __int64 a4)
{
unsigned __int64 v5; // r12
unsigned __int8 v6; // r14
unsigned int v7; // er14
__int64 result; // rax
unsigned int v9; // ebx
char v10; // dl
__int64 v11[8]; // [rsp+8h] [rbp-40h] BYREF

v11[0] = a2;
v5 = a2 + a3;
v6 = *(_BYTE *)(a1 + 8);
if ( v6 > 0x81u )
{
v7 = 128;
}
else
{
v7 = v6 - 1;
if ( !v7 )
return v11[0] != v5;
}
if ( a2 >= v5 )
{
v9 = 0;
goto LABEL_15;
}
v9 = 0;
while ( 1 )
{
result = DL_ISO8583_FIELD_Unpack(v9, a4, a1, v11);
v10 = *(_BYTE *)(*(_QWORD *)a1 + 12LL * v9++);
if ( result || v9 >= v7 )
break;
if ( v11[0] >= v5 || v10 == 10 )
{
LABEL_15:
while ( v11[0] < v5 )
{
result = 0LL;
if ( *(_DWORD *)(16LL * v9 + a4 + 16) )
result = DL_ISO8583_FIELD_Unpack(v9, a4, a1, v11);
++v9;
if ( result || v9 >= v7 )
goto LABEL_18;
}
return v11[0] != v5;
}
}
LABEL_18:
if ( result )
return result;
return v11[0] != v5;
}

original_code:
DL_ERR DL_ISO8583_MSG_Unpack ( const DL_ISO8583_HANDLER *iHandler,
                const DL_UINT8 *iByteArr,
                      DL_UINT16 iByteArrSize,
                      DL_ISO8583_MSG *ioMsg )
{
 DL_ERR err = (DL_ERR)0;
 DL_UINT8 *curPtr = (DL_UINT8*)iByteArr;
 DL_UINT8 *endPtr = curPtr + iByteArrSize;
 DL_UINT16 curFieldIdx = 0;
 DL_UINT16 maxFieldIdx = ((128)<((iHandler->fieldItems)-1)?(128):((iHandler->fieldItems)-1));
 int haveBitmap = 0;
 while ( !err && (curFieldIdx < maxFieldIdx) && (curPtr < endPtr) && !haveBitmap )
 {
  err = _DL_ISO8583_FIELD_Unpack(curFieldIdx,ioMsg,iHandler,&curPtr);
  if ( (10==(iHandler->fieldArr[curFieldIdx].fieldType)) )
   haveBitmap = 1;
  curFieldIdx++;
 }
 while ( !err && (curFieldIdx < maxFieldIdx) && (curPtr < endPtr) )
 {
  if ( 0 != ioMsg->field[curFieldIdx].len )
  {
   err = _DL_ISO8583_FIELD_Unpack(curFieldIdx,ioMsg,iHandler,&curPtr);
  }
  curFieldIdx++;
 }
 if ( !err && (curPtr != endPtr) )
  err = (DL_ERR)1;
 return err;
}

canonical_original_code:
unsigned long DL_ISO8583_MSG_Unpack(struct DL_ISO8583_HANDLER_S *iHandler, unsigned char *iByteArr, unsigned int iByteArrSize, struct DL_ISO8583_MSG_S *ioMsg)
{
 unsigned long err = (DL_ERR)0;
 unsigned char *curPtr = (DL_UINT8*)iByteArr;
 unsigned char *endPtr = curPtr + iByteArrSize;
 unsigned int curFieldIdx = 0;
 unsigned int maxFieldIdx = ((128)<((iHandler->fieldItems)-1)?(128):((iHandler->fieldItems)-1));
 int haveBitmap = 0;
 while ( !err && (curFieldIdx < maxFieldIdx) && (curPtr < endPtr) && !haveBitmap )
 {
  err = _DL_ISO8583_FIELD_Unpack(curFieldIdx,ioMsg,iHandler,&curPtr);
  if ( (10==(iHandler->fieldArr[curFieldIdx].fieldType)) )
   haveBitmap = 1;
  curFieldIdx++;
 }
 while ( !err && (curFieldIdx < maxFieldIdx) && (curPtr < endPtr) )
 {
  if ( 0 != ioMsg->field[curFieldIdx].len )
  {
   err = _DL_ISO8583_FIELD_Unpack(curFieldIdx,ioMsg,iHandler,&curPtr);
  }
  curFieldIdx++;
 }
 if ( !err && (curPtr != endPtr) )
  err = (unsigned long)1;
 return err;
}

variable_types:
iByteArr
unsigned char *

variable_types:
iByteArrSize
unsigned int

variable_types:
endPtr
unsigned char *

variable_types:
curFieldIdx
unsigned int

variable_types:
maxFieldIdx
unsigned int

variable_types: haveBitmap int

user_defined_types: struct DL_ISO8583_FIELD_DEF_S { unsigned char fieldType; unsigned int len; unsigned char varLen; }


getMSec

decompiled_code:
__suseconds_t getMSec()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
return tv.tv_usec / 1000 % 1000;
}

canonical_decompiled_code:
__suseconds_t func0()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
return tv.tv_usec / 1000 % 1000;
}

original_code:
static DL_UINT32 getMSec ( void )
{
 DL_UINT32 ret = 0;
 {
  struct timeval tv;
  struct timezone tz;
  gettimeofday(&tv, &tz);
  ret = (DL_UINT32)((tv.tv_usec / 1000) % 1000);
 }
 return ret;
}

canonical_original_code:
static unsigned long getMSec()
{
 unsigned long ret = 0;
 {
  struct timeval tv;
  struct timezone tz;
  gettimeofday(&tv, &tz);
  ret = (DL_UINT32)((tv.tv_usec / 1000) % 1000);
 }
 return ret;
}

variable_types:
ret
unsigned long

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

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


decompiled_code:
__suseconds_t __fastcall DL_TIMER_Start(_QWORD *a1)
{
__suseconds_t result; // rax

*a1 = 0LL;
a1[1] = 0LL;
*a1 = DL_TIME_GetUTCSeconds();
result = getMSec();
a1[1] = result;
return result;
}

canonical_decompiled_code:
__suseconds_t __fastcall func1(_QWORD *a1)
{
__suseconds_t result; // rax

*a1 = 0LL;
a1[1] = 0LL;
*a1 = DL_TIME_GetUTCSeconds();
result = func0();
a1[1] = result;
return result;
}

original_code:
void DL_TIMER_Start ( DL_TIMER *oTimer )
{
 ((void)memset((void*)(oTimer),(int)(0),(size_t)(sizeof(DL_TIMER))));
 oTimer->sec = DL_TIME_GetUTCSeconds();
 oTimer->msec = getMSec();
 return;
}

canonical_original_code:
void DL_TIMER_Start(struct DL_TIMER_S *oTimer)
{
 ((void)memset((void *)(oTimer),(int)(0),(unsigned long)(sizeof(DL_TIMER))));
 oTimer->sec = DL_TIME_GetUTCSeconds();
 oTimer->msec = getMSec();
 return;
}

variable_types: struct DL_TIMER_S { unsigned long sec; unsigned long msec; } *


decompiled_code:
__int64 __fastcall DL_TIMER_GetDuration(int a1, __int64 a2)
{
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

DL_TIMER_Start(v3);
return 1000 * (LODWORD(v3[0]) - a1) + (unsigned int)((v3[1] - a2) % 0x3E8uLL);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

func1(v3);
return 1000 * (LODWORD(v3[0]) - a1) + (unsigned int)((v3[1] - a2) % 0x3E8uLL);
}

original_code:
DL_UINT32 DL_TIMER_GetDuration ( DL_TIMER iTimer )
{
 DL_UINT32 durMs = 0;
 DL_TIMER tmpTimer;
 DL_TIMER_Start(&tmpTimer);
 durMs = ( ((tmpTimer.sec - iTimer.sec) * 1000) +
        ((tmpTimer.msec - iTimer.msec) % 1000) )
   & 0xffffffffL;
 return durMs;
}

canonical_original_code:
unsigned long DL_TIMER_GetDuration(struct DL_TIMER_S iTimer)
{
 unsigned long durMs = 0;
 struct DL_TIMER_S tmpTimer;
 DL_TIMER_Start(&tmpTimer);
 durMs = ( ((tmpTimer.sec - iTimer.sec) * 1000) +
        ((tmpTimer.msec - iTimer.msec) % 1000) )
   & 0xffffffffL;
 return durMs;
}

variable_types: struct DL_TIMER_S { unsigned long sec; unsigned long msec; }

variable_types:
durMs
unsigned long


repo: mregmi/manrix

decompiled_code:
void *get_cpu()
{
return &cpus;
}

canonical_decompiled_code:
void *func0()
{
return &cpus;
}

original_code:
static inline struct cpu *get_cpu()
{
 return ((struct cpu *)&cpus[0]);
}

return_type: struct cpu { struct thread { struct linked_list { void *next; } thread_list; struct thread *next; struct thread *waiting; struct linked_list runq; int tid; struct context { struct regs { unsigned int eip; unsigned int esp; unsigned int cr3; } uregs; int irqflag; void (*handler)(); } context; unsigned int stack; unsigned int states; struct process { struct linked_list threads; struct linked_list child; struct linked_list proclist; struct vm_map { struct vm_map_entry { struct linked_list entries; unsigned int start; unsigned int end; struct vm_object { struct linked_list page; struct atomic_t { int value; } ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } vn; struct spinlock { int lock; } lock; } *object; unsigned short type; unsigned short attr; struct spinlock lock; } *vmentry; struct pmap { struct linked_list plist; unsigned int *pdbr; struct spinlock lock; } *pmap; unsigned int size; struct atomic_t ref_count; unsigned int start; unsigned int end; struct vm_map_entry *hint; unsigned int private; int attr; struct spinlock vmlock; } *map; int pid; int uid; int gid; int session; struct process *parent; struct process *next; long start_time; long user_time; long system_time; struct linked_list timer; struct timer { struct linked_list tlist; struct linked_list pproc; unsigned long long timeout; long nextarm; struct sigevent { int sigev_notify; int sigev_signo; union sigval { int sigval_int; void *sigval_ptr; } handler; } sigv; struct thread *owner; int flag; int clkid; int timer_id; struct timer *next; } *alarm; int flag; int status; int exit_status; struct linked_list sigqueue; struct sigaction { int sa_mask; int sa_flags; union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo { int si_signo; int si_code; int si_errno; int si_pid; void *si_addr; int si_status; union sigval si_value; }, void *); } action; } action[32]; struct spinlock siglock; struct stack { void *ss_sp; unsigned int ss_size; int ss_flags; } ss; struct syncstruct { struct linked_list syncs; long id; } sync; struct fd { int fd_max; int fd_hint; unsigned int bitmap; struct inodev { unsigned int inode; unsigned int device; } cwd; char cwdstr[256]; unsigned int fileptr[-1]; struct spinlock lock; } fd; struct spinlock lock; } *proc; struct thread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; } attr; int priority_dyn; int bound; int time_slice; int schedule; int exitstat; int sa_mask; int sigpending; struct message { union { unsigned int w3; unsigned int snd_bufsize; } m1; union { unsigned int w4; void *rcv_ptr; } m2; union { unsigned int w5; unsigned int rcv_bufsize; } m3; unsigned int dummy1; int tid; union { unsigned int w2; void *snd_ptr; } m4; unsigned int w1; unsigned short dummy; } msg; struct linked_list rcvq; struct linked_list sndq; int cpu; } *idle; } *

user_defined_types: struct thread { struct linked_list thread_list; struct thread *next; struct thread *waiting; struct linked_list runq; int tid; struct context context; unsigned int stack; unsigned int states; struct process *proc; struct thread_attr attr; int priority_dyn; int bound; int time_slice; int schedule; int exitstat; int sa_mask; int sigpending; struct message msg; struct linked_list rcvq; struct linked_list sndq; int cpu; }

user_defined_types: struct context { struct regs uregs; int irqflag; void (*handler)(); }

user_defined_types: struct thread_attr { int flags; struct sched_param prio; void *stackaddr; unsigned int stack_size; int policy; }

user_defined_types: struct process { struct linked_list threads; struct linked_list child; struct linked_list proclist; struct vm_map *map; int pid; int uid; int gid; int session; struct process *parent; struct process *next; long start_time; long user_time; long system_time; struct linked_list timer; struct timer *alarm; int flag; int status; int exit_status; struct linked_list sigqueue; struct sigaction action[32]; struct spinlock siglock; struct stack ss; struct syncstruct sync; struct fd fd; struct spinlock lock; }

user_defined_types: struct fd { int fd_max; int fd_hint; unsigned int bitmap; struct inodev cwd; char cwdstr[256]; unsigned int fileptr[-1]; struct spinlock lock; }

user_defined_types: struct vm_map { struct vm_map_entry *vmentry; struct pmap *pmap; unsigned int size; struct atomic_t ref_count; unsigned int start; unsigned int end; struct vm_map_entry *hint; unsigned int private; int attr; struct spinlock vmlock; }

user_defined_types: struct timer { struct linked_list tlist; struct linked_list pproc; unsigned long long timeout; long nextarm; struct sigevent sigv; struct thread *owner; int flag; int clkid; int timer_id; struct timer *next; }

user_defined_types: struct sigaction { int sa_mask; int sa_flags; union handler action; }

user_defined_types: struct sigevent { int sigev_notify; int sigev_signo; union sigval handler; }

user_defined_types: union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo, void *); }

user_defined_types: struct vm_map_entry { struct linked_list entries; unsigned int start; unsigned int end; struct vm_object *object; unsigned short type; unsigned short attr; struct spinlock lock; }

user_defined_types: struct vm_object { struct linked_list page; struct atomic_t ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object vn; struct spinlock lock; }


decompiled_code:
// attributes: thunk
void __noreturn idle_thread()
{
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func1()
{
while ( 1 )
;
}

original_code:
void idle_thread()
{
 int index = 0;
 while(1)
 {
  index++;
 }
}

variable_types: index int


decompiled_code:
void __noreturn ManRiX_main()
{
__int64 v0; // rbx

arch_setup();
vm_init();
process_init();
sched_init();
IRQ_init();
time_init();
modules_init();
init = 1;
v0 = init_thread;
*(_DWORD *)(init_thread + 100LL) = 46;
*(_QWORD *)get_cpu() = v0;
_enable();
idle_thread();
}

canonical_decompiled_code:
void __noreturn func2()
{
__int64 v0; // rbx

arch_setup();
vm_init();
process_init();
sched_init();
IRQ_init();
time_init();
modules_init();
init = 1;
v0 = init_thread;
*(_DWORD *)(init_thread + 100LL) = 46;
*(_QWORD *)func0() = v0;
_enable();
func1();
}

original_code:
void ManRiX_main()
{
 struct cpu *cpu;
 arch_setup();
 vm_init();
 process_init();
 sched_init();
 IRQ_init();
 time_init();
 modules_init();
 init = 1;
 init_thread->attr.prio.sched_priority = 46;
 cpu = get_cpu();
 cpu->idle = init_thread;
 asm("sti\n\t");
 idle_thread();
}

variable_types: struct cpu { struct thread { struct linked_list { void *next; } thread_list; struct thread *next; struct thread *waiting; struct linked_list runq; int tid; struct context { struct regs { unsigned int eip; unsigned int esp; unsigned int cr3; } uregs; int irqflag; void (*handler)(); } context; unsigned int stack; unsigned int states; struct process { struct linked_list threads; struct linked_list child; struct linked_list proclist; struct vm_map { struct vm_map_entry { struct linked_list entries; unsigned int start; unsigned int end; struct vm_object { struct linked_list page; struct atomic_t { int value; } ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } vn; struct spinlock { int lock; } lock; } *object; unsigned short type; unsigned short attr; struct spinlock lock; } *vmentry; struct pmap { struct linked_list plist; unsigned int *pdbr; struct spinlock lock; } *pmap; unsigned int size; struct atomic_t ref_count; unsigned int start; unsigned int end; struct vm_map_entry *hint; unsigned int private; int attr; struct spinlock vmlock; } *map; int pid; int uid; int gid; int session; struct process *parent; struct process *next; long start_time; long user_time; long system_time; struct linked_list timer; struct timer { struct linked_list tlist; struct linked_list pproc; unsigned long long timeout; long nextarm; struct sigevent { int sigev_notify; int sigev_signo; union sigval { int sigval_int; void *sigval_ptr; } handler; } sigv; struct thread *owner; int flag; int clkid; int timer_id; struct timer *next; } *alarm; int flag; int status; int exit_status; struct linked_list sigqueue; struct sigaction { int sa_mask; int sa_flags; union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo { int si_signo; int si_code; int si_errno; int si_pid; void *si_addr; int si_status; union sigval si_value; }, void *); } action; } action[32]; struct spinlock siglock; struct stack { void *ss_sp; unsigned int ss_size; int ss_flags; } ss; struct syncstruct { struct linked_list syncs; long id; } sync; struct fd { int fd_max; int fd_hint; unsigned int bitmap; struct inodev { unsigned int inode; unsigned int device; } cwd; char cwdstr[256]; unsigned int fileptr[-1]; struct spinlock lock; } fd; struct spinlock lock; } *proc; struct thread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; } attr; int priority_dyn; int bound; int time_slice; int schedule; int exitstat; int sa_mask; int sigpending; struct message { union { unsigned int w3; unsigned int snd_bufsize; } m1; union { unsigned int w4; void *rcv_ptr; } m2; union { unsigned int w5; unsigned int rcv_bufsize; } m3; unsigned int dummy1; int tid; union { unsigned int w2; void *snd_ptr; } m4; unsigned int w1; unsigned short dummy; } msg; struct linked_list rcvq; struct linked_list sndq; int cpu; } *idle; } *


chmod

original_code:
int chmod(const char *path, mode_t mode)
{
 struct message msg;
 int length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length;
 msg.m2.w4 = mode;
 msg.w1 = 10;
 send_message(2, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

canonical_original_code:
int chmod(char *path, int mode)
{
 struct message msg;
 int length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length;
 msg.m2.w4 = mode;
 msg.w1 = 10;
 send_message(2, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

variable_types:
path
char *

variable_types: mode int

variable_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; }

variable_types: length int


stat

original_code:
int stat(const char *__restrict path, struct stat *__restrict buf)
{
 struct message msg;
 int length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length + 1;
 msg.m2.rcv_ptr = buf;
 msg.m3.rcv_bufsize = sizeof(struct stat);
 msg.flags |= 0x40;
 msg.w1 = 11;
 send_message(2, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

canonical_original_code:
int stat(char *path, struct stat *buf)
{
 struct message msg;
 int length;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length + 1;
 msg.m2.rcv_ptr = buf;
 msg.m3.rcv_bufsize = sizeof(struct stat);
 msg.flags |= 0x40;
 msg.w1 = 11;
 send_message(2, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

variable_types: struct stat { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; } *

user_defined_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; }


fstat

original_code:
int fstat(int fildes, struct stat *buf)
{
 struct message msg;
 msg.flags = 0x40;
 msg.m2.rcv_ptr = buf;
 msg.m3.rcv_bufsize = sizeof(struct stat);
 msg.w1 = 12;
 send_message(2, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

variable_types: fildes int

user_defined_types: struct stat { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; }


strlen

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
__int64 v1; // rcx
bool v2; // zf

v1 = 0xFFFFFFFFLL;
do
{
if ( !v1 )
break;
v2 = *a1++ == 0;
--v1;
}
while ( !v2 );
return (unsigned int)(-(int)v1 - 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rcx
bool v2; // zf

v1 = 0xFFFFFFFFLL;
do
{
if ( !v1 )
break;
v2 = *a1++ == 0;
--v1;
}
while ( !v2 );
return (unsigned int)(-(int)v1 - 2);
}

original_code:
static inline size_t strlen(const char * s)
{
int d0;
register int __res;
__asm__ __volatile__(
 "repne\n\t"
 "scasb\n\t"
 "notl %0\n\t"
 "decl %0"
 :"=c" (__res), "=&D" (d0) :"1" (s),"a" (0), "0" (0xffffffffu));
return __res;
}

canonical_original_code:
static inline unsigned int strlen(char *s)
{
int d0;
register int __res;
__asm__ __volatile__(
 "repne\n\t"
 "scasb\n\t"
 "notl %0\n\t"
 "decl %0"
 :"=c" (__res), "=&D" (d0) :"1" (s),"a" (0), "0" (0xffffffffu));
return __res;
}

variable_types:
s
char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall put_ascii(unsigned __int8 a1)
{
unsigned int v1; // ebx

v1 = (unsigned __int8)table_code1[a1 - 1];
put_char((unsigned __int8)v1, ttys + 3168LL * termindex + 1144, 1LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
unsigned int v1; // ebx

v1 = (unsigned __int8)table_code1[a1 - 1];
put_char((unsigned __int8)v1, ttys + 3168LL * termindex + 1144, 1LL);
return v1;
}

original_code:
unsigned char put_ascii(unsigned char scancode)
{
 unsigned char ascii;
 struct winattr *wattr = &(ttys[termindex]).t_win;
 ascii = table_code1[scancode-1];
 put_char(ascii, wattr, 1);
 return ascii;
}

variable_types:
scancode
unsigned char

variable_types:
ascii
unsigned char

variable_types: struct winattr { int current_x; int max_x; int attr; char scrbuf[-1]; } *

return_type: unsigned char


open

original_code:
int open(const char *path, int oflag, ... )
{
 struct message msg;
 int length, ret,server;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length+1;
 msg.w1 = 1;
 msg.m2.w4 = oflag;
 send_message(2, &msg);
 ret = msg.w1;
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 if(((msg.m2.w4 & 0xF000) == 0x8000) || ((msg.m2.w4 & 0xF000) == 0x4000))
  goto out;
 msg.flags = 1|0x20;
 msg.w1 = 1;
 if((ret >= 0) && (ret < 3))
  server = 1;
 else
  server = ((ret >> 16) & 0xFFFF);
 send_message(server, &msg);
out:
 return ret;
}

canonical_original_code:
int open(char *path, int oflag, ...)
{
 struct message msg;
 int length; int ret; int server;
 length = strlen(path);
 if(length > 256)
  msg.flags = 4;
 else
  msg.flags = 2;
 msg.m4.snd_ptr = (void *)path;
 msg.m1.snd_bufsize = length+1;
 msg.w1 = 1;
 msg.m2.w4 = oflag;
 send_message(2, &msg);
 ret = msg.w1;
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 if(((msg.m2.w4 & 0xF000) == 0x8000) || ((msg.m2.w4 & 0xF000) == 0x4000))
  goto out;
 msg.flags = 1|0x20;
 msg.w1 = 1;
 if((ret >= 0) && (ret < 3))
  server = 1;
 else
  server = ((ret >> 16) & 0xFFFF);
 send_message(server, &msg);
out:
 return ret;
}

variable_types: oflag int

variable_types: ret int

variable_types: server int


decompiled_code:
__int64 __fastcall read_entry(_BYTE *a1, FILE *a2)
{
_BYTE *v3; // rdx
char v4; // al

while ( 1 )
{
v4 = fgetc(a2);
if ( v4 == -1 )
break;
if ( v4 == 35 )
{
while ( fgetc(a2) != 10 )
;
v3 = a1;
}
else
{
v3 = a1 + 1;
*a1 = v4;
if ( v4 == 10 )
{
a1[1] = 0;
return 0LL;
}
}
a1 = v3;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, FILE *a2)
{
_BYTE *v3; // rdx
char v4; // al

while ( 1 )
{
v4 = fgetc(a2);
if ( v4 == -1 )
break;
if ( v4 == 35 )
{
while ( fgetc(a2) != 10 )
;
v3 = a1;
}
else
{
v3 = a1 + 1;
*a1 = v4;
if ( v4 == 10 )
{
a1[1] = 0;
return 0LL;
}
}
a1 = v3;
}
return 1LL;
}

original_code:
int read_entry(char *prog, FILE *fs)
{
 char c = 'c';
 while(c != '\n')
 {
  c = fgetc(fs);
  if(c == (-1))
   return 1;
  if(c == '#')
  {
   while(fgetc(fs) != '\n') ;
   continue;
  }
  *prog++ = c;
 }
 *prog = '\0';
 return 0;
}

canonical_original_code:
int read_entry(char *prog, struct __filestream *fs)
{
 char c = 'c';
 while(c != '\n')
 {
  c = fgetc(fs);
  if(c == (-1))
   return 1;
  if(c == '#')
  {
   while(fgetc(fs) != '\n') ;
   continue;
  }
  *prog++ = c;
 }
 *prog = '\0';
 return 0;
}

variable_types:
prog
char *

variable_types: struct __filestream { int fd; char *data; unsigned int allocation; unsigned int size; unsigned int offset; } *

variable_types: c char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int result; // eax

printf("\nStarting INIT version 1.0 ...");
v3 = open("/dev/console", 1024);
if ( v3 < 0 )
{
printf("Error opening file /dev/console. %d", errno);
result = 1;
}
else
{
v4 = v3;
dup(v3);
dup(v4);
if ( open("/etc/inittab", 1024) < 0 )
{
printf("Error opening file /etc/inittab. %d", errno);
result = 1;
}
else
{
printf("Init Process Over \n");
execv("/bin/login", 0LL);
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 int fd, status;
 pid_t child;
 FILE *fd1;
 char *prog;
 char *exec, *parm;
 printf("\nStarting INIT version 1.0 ...");
 fd = open("/dev/console", 0x400);
 if(fd < 0)
 {
  printf("Error opening file /dev/console. %d", errno);
  return 1;
 }
 dup(fd);
 dup(fd);
 fd = open("/etc/inittab", 0x400);
 if(fd < 0)
 {
  printf("Error opening file /etc/inittab. %d", errno);
  return 1;
 }
 printf("Init Process Over \n");
 execv("/bin/login", ((void *) 0));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd; int status;
 int child;
 struct __filestream *fd1;
 char *prog;
 char *exec; char *parm;
 printf("\nStarting INIT version 1.0 ...");
 fd = open("/dev/console", 0x400);
 if(fd < 0)
 {
  printf("Error opening file /dev/console. %d", errno);
  return 1;
 }
 dup(fd);
 dup(fd);
 fd = open("/etc/inittab", 0x400);
 if(fd < 0)
 {
  printf("Error opening file /etc/inittab. %d", errno);
  return 1;
 }
 printf("Init Process Over \n");
 execv("/bin/login", ((void *) 0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fd int

variable_types: status int

variable_types: child int

variable_types:
exec
char *

variable_types:
parm
char *

user_defined_types: struct __filestream { int fd; char *data; unsigned int allocation; unsigned int size; unsigned int offset; }


decompiled_code:
__int64 __fastcall data_request(__int64 a1, char *a2, _DWORD *a3)
{
__int64 result; // rax
_QWORD *v5; // rdi
_DWORD v6[8]; // [rsp-18h] [rbp-48h] BYREF
__int64 v7; // [rsp+8h] [rbp-28h]

if ( !a2 )
return 0xFFFFFFFFLL;
result = get_openfile(a1, *(unsigned int *)a2, v6);
if ( (int)result >= 0 )
{
v5 = (_QWORD *)find_vnode(v7, v6[6]);
if ( v5 )
{
if ( a2[32] >= 0 )
result = elf_read_data(v5, a2, a3);
else
result = read_file_data(v5, (__int64)a2, a3);
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, char *a2, _DWORD *a3)
{
__int64 result; // rax
_QWORD *v5; // rdi
_DWORD v6[8]; // [rsp-18h] [rbp-48h] BYREF
__int64 v7; // [rsp+8h] [rbp-28h]

if ( !a2 )
return 0xFFFFFFFFLL;
result = get_openfile(a1, *(unsigned int *)a2, v6);
if ( (int)result >= 0 )
{
v5 = (_QWORD *)find_vnode(v7, v6[6]);
if ( v5 )
{
if ( a2[32] >= 0 )
result = elf_read_data(v5, a2, a3);
else
result = func5(v5, (__int64)a2, a3);
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int data_request(vm_map_entry_t entry, vm_offset_t va)
{
 struct message msg;
 vm_map_t map = get_current()->proc->map;
 struct vn_object *vno = &entry->object->vn;
 struct vm_page *page;
 int pages, ret, size;
 vm_offset_t addr = va;
 kprintf("Faulted at %X XX", va);
 if((va >= vno->noload_start) && (va <= vno->noload_end))
 {
  kprintf("Zero filled in                    data_request: %X %X ", vno->noload_start,vno->noload_end);
  return alloc_zero_fill_page(map, entry, va);
 }
 vno->va = va;
 vno->page_size = 0x1000;
 msg.flags = 2|8;
 msg.m4.snd_ptr = vno;
 msg.m1.snd_bufsize = sizeof(struct vn_object);
 if(vno->blk_size > 0x1000)
  size = vno->blk_size;
 else
  size = 0x1000;
 msg.m3.rcv_bufsize = size;
 msg.w1 = 0;
 msg.tid = vno->pager_id;
 msg.m2.rcv_ptr = (void *)((va) = (((vm_offset_t)(va)) & ~(0x1000 -1)));
 pages = msg.m3.rcv_bufsize/0x1000;
 do{
  ((addr) = (((vm_offset_t)(addr)) & ~(0x1000 -1)));
  page = page_alloc(entry->object, addr);
  pmap_enter(map->pmap, page->base, addr, 0x002|0x004);
  addr += 0x1000;
 }while(--pages);
 ret = send_message(msg.tid, &msg);
 if(ret < 0)
 {
 }
 if(vno->map_type & 0x80)
  vno->offset += size;
 invlpg(((void *)0));
 kprintf(" Fault Done\n");
 return 0;
}

canonical_original_code:
int data_request(struct vm_map_entry *entry, unsigned int va)
{
 struct message msg;
 struct vm_map *map = get_current()->proc->map;
 struct vn_object *vno = &entry->object->vn;
 struct vm_page *page;
 int pages; int ret; int size;
 unsigned int addr = va;
 kprintf("Faulted at %X XX", va);
 if((va >= vno->noload_start) && (va <= vno->noload_end))
 {
  kprintf("Zero filled in                    data_request: %X %X ", vno->noload_start,vno->noload_end);
  return alloc_zero_fill_page(map, entry, va);
 }
 vno->va = va;
 vno->page_size = 0x1000;
 msg.flags = 2|8;
 msg.m4.snd_ptr = vno;
 msg.m1.snd_bufsize = sizeof(struct vn_object);
 if(vno->blk_size > 0x1000)
  size = vno->blk_size;
 else
  size = 0x1000;
 msg.m3.rcv_bufsize = size;
 msg.w1 = 0;
 msg.tid = vno->pager_id;
 msg.m2.rcv_ptr = (void *)((va) = (((vm_offset_t)(va)) & ~(0x1000 -1)));
 pages = msg.m3.rcv_bufsize/0x1000;
 do{
  ((addr) = (((vm_offset_t)(addr)) & ~(0x1000 -1)));
  page = page_alloc(entry->object, addr);
  pmap_enter(map->pmap, page->base, addr, 0x002|0x004);
  addr += 0x1000;
 }while(--pages);
 ret = send_message(msg.tid, &msg);
 if(ret < 0)
 {
 }
 if(vno->map_type & 0x80)
  vno->offset += size;
 invlpg(((void *)0));
 kprintf(" Fault Done\n");
 return 0;
}

variable_types:
va
unsigned int

variable_types: struct message { union { unsigned int w3; unsigned int snd_bufsize; } m1; union { unsigned int w4; void *rcv_ptr; } m2; union { unsigned int w5; unsigned int rcv_bufsize; } m3; unsigned int dummy1; int tid; union { unsigned int w2; void *snd_ptr; } m4; unsigned int w1; unsigned short dummy; }

variable_types: struct vm_map { struct vm_map_entry { struct linked_list { void *next; } entries; unsigned int start; unsigned int end; struct vm_object { struct linked_list page; struct atomic_t { int value; } ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } vn; struct spinlock { int lock; } lock; } *object; unsigned short type; unsigned short attr; struct spinlock lock; } *vmentry; struct pmap { struct linked_list plist; unsigned int *pdbr; struct spinlock lock; } *pmap; unsigned int size; struct atomic_t ref_count; unsigned int start; unsigned int end; struct vm_map_entry *hint; unsigned int private; int attr; struct spinlock vmlock; } *

variable_types: struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } *

variable_types: struct vm_page { struct linked_list { void *next; } pagelist; struct vm_page *next; unsigned int base; struct vm_object { struct linked_list page; struct atomic_t { int value; } ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } vn; struct spinlock { int lock; } lock; } *object; unsigned int offset; struct atomic_t count; unsigned short flags; struct spinlock lock; } *

variable_types: pages int

variable_types: size int

variable_types:
addr
unsigned int

user_defined_types: struct vm_page { struct linked_list pagelist; struct vm_page *next; unsigned int base; struct vm_object *object; unsigned int offset; struct atomic_t count; unsigned short flags; struct spinlock lock; }


getcwd

decompiled_code:
__int64 __fastcall getcwd(__int64 a1, int a2)
{
__int64 v2; // rbx
unsigned int v3; // eax
int v4; // eax

if ( a2 )
{
v2 = a1;
v3 = pthread_self();
v4 = syscall_get_cwd(v3, 0LL, a1);
if ( v4 < 0 )
{
errno = -v4;
v2 = 0LL;
}
}
else
{
errno = 29;
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 v2; // rbx
unsigned int v3; // eax
int v4; // eax

if ( a2 )
{
v2 = a1;
v3 = pthread_self();
v4 = func0(v3, 0LL, a1);
if ( v4 < 0 )
{
errno = -v4;
v2 = 0LL;
}
}
else
{
errno = 29;
v2 = 0LL;
}
return v2;
}

original_code:
char *getcwd(char *buf, size_t size)
{
 int ret;
 if(!size)
 {
  ((errno) = (0x1d));
  return ((void *) 0);
 }
 ret = syscall_get_cwd(pthread_self(), ((void *) 0), buf);
 if(ret < 0)
 {
  ((errno) = (-ret));
  return ((void *) 0);
 }
 return buf;
}

canonical_original_code:
char *getcwd(char *buf, unsigned int size)
{
 int ret;
 if(!size)
 {
  ((errno) = (0x1d));
  return ((void *) 0);
 }
 ret = syscall_get_cwd(pthread_self(), ((void *) 0), buf);
 if(ret < 0)
 {
  ((errno) = (-ret));
  return ((void *) 0);
 }
 return buf;
}

variable_types:
buf
char *

variable_types:
size
unsigned int

variable_types: ret int

return_type: char *


original_code:
int ext2_read_sb(struct vfs *vfs)
{
 struct ext2_super_block sb;
 struct ext2_group_desc *gd;
 int ret;
 int index = 1, ngroups;
 ret = blk_strategy(1, vfs->vfs_dev, 1, sizeof(struct ext2_super_block), (void *)&sb);
 if(ret < 0)
  return ret;
 if(sb.s_magic != 0xEF53)
  return -0x50;
 vfs->blk_size = (1024 << (&sb)->s_log_block_size);
 ngroups = sb.s_blocks_count/((&sb)->s_blocks_per_group);
 gd = (struct ext2_group_desc *) malloc(sizeof(struct ext2_group_desc) * ngroups);
 if(!gd)
  return -0x31;
 memset(gd, 0, sizeof(struct ext2_group_desc) * ngroups);
 if(vfs->blk_size <= 1024)
  index = 2;
 memcpy((char *)&vfs->sb.ext2_sb.ext2, (char *)&sb, sizeof(struct ext2_super_block));
 read_group_desc(vfs, index, gd);
 vfs->sb.ext2_sb.gdes = gd;
 return 0;
}

canonical_original_code:
int ext2_read_sb(struct vfs *vfs)
{
 struct ext2_super_block sb;
 struct ext2_group_desc *gd;
 int ret;
 int index = 1; int ngroups;
 ret = blk_strategy(1, vfs->vfs_dev, 1, sizeof(struct ext2_super_block), (void *)&sb);
 if(ret < 0)
  return ret;
 if(sb.s_magic != 0xEF53)
  return -0x50;
 vfs->blk_size = (1024 << (&sb)->s_log_block_size);
 ngroups = sb.s_blocks_count/((&sb)->s_blocks_per_group);
 gd = (struct ext2_group_desc *) malloc(sizeof(struct ext2_group_desc) * ngroups);
 if(!gd)
  return -0x31;
 memset(gd, 0, sizeof(struct ext2_group_desc) * ngroups);
 if(vfs->blk_size <= 1024)
  index = 2;
 memcpy((char *)&vfs->sb.ext2_sb.ext2, (char *)&sb, sizeof(struct ext2_super_block));
 read_group_desc(vfs, index, gd);
 vfs->sb.ext2_sb.gdes = gd;
 return 0;
}

variable_types: struct vfs { struct linked_list { void *next; } vfs_next; struct vnode { unsigned short v_flag; int v_count; struct vfs *v_fsmounted; struct vfs *vfsp; int v_inum; unsigned long v_rdev; int v_type; struct linked_list v_freelist; struct vnode *v_next; struct vnodeops { int (*vop_open)(struct file { int f_access; unsigned long f_offset; int f_ref; struct indev { int inode; unsigned long dev; } vnode; } *, struct vnode *, int); int (*vop_close)(struct file *, struct vnode *); int (*vop_read)(struct file *, struct vnode *, void *, unsigned int); int (*vop_write)(struct file *, struct vnode *, void *, unsigned int); int (*vop_strategy)(); int (*vop_ioctl)(); int (*vop_create)(); int (*vop_remove)(); int (*vop_link)(); int (*vop_unlink)(); int (*vop_rename)(); int (*vop_mkdir)(); int (*vop_rmdir)(); int (*vop_readdir)(); int (*vop_symlink)(); int (*vop_poll)(); int (*vop_read_inode)(struct vnode *, int); unsigned long (*vop_bmap)(struct vnode *, unsigned long); void (*vop_write_inode)(struct vnode *); int (*vop_namei)(struct vnode *, char *, struct nameidata { struct vnode *vn; struct userid { int uid; int gid; } id; struct vfs *vfs; char *path; int mode; int access; } *); void (*vop_get_attr)(struct vnode *, struct vattr { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; } *); void (*vop_put_attr)(struct vnode *, struct vattr *); int (*vop_req_iospace)(int, int); } *ops; void *data; struct mrx_mutex { struct mrx_mutexattr { int type; int pshared; int protocol; } mattr; int counter; int sync_id; } smlock; union inode { struct ext2inode { unsigned short i_mode; unsigned short i_uid; unsigned long i_size; unsigned long i_atime; unsigned long i_ctime; unsigned long i_mtime; unsigned long i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned long i_blocks; unsigned long i_flags; union { struct { unsigned long l_i_reserved1; } linux1; struct { unsigned long h_i_translator; } hurd1; struct { unsigned long m_i_reserved1; } masix1; } osd1; unsigned long i_block[-1]; unsigned long i_generation; unsigned long i_file_acl; unsigned long i_dir_acl; unsigned long i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned long l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned short h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned long m_i_reserved2[2]; } masix2; } osd2; } ext2inode; } v_ino; } *vfs_mpoint; unsigned long vfs_dev; unsigned int blk_size; union { struct ext2sb { struct ext2_super_block { unsigned long s_inodes_count; unsigned long s_blocks_count; unsigned long s_r_blocks_count; unsigned long s_free_blocks_count; unsigned long s_free_inodes_count; unsigned long s_first_data_block; unsigned long s_log_block_size; unsigned long s_log_frag_size; unsigned long s_blocks_per_group; unsigned long s_frags_per_group; unsigned long s_inodes_per_group; unsigned long s_mtime; unsigned long s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_pad; unsigned short s_minor_rev_level; unsigned long s_lastcheck; unsigned long s_checkinterval; unsigned long s_creator_os; unsigned long s_rev_level; unsigned short s_def_resuid; unsigned short s_def_regid; unsigned long s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned long s_feature_compat; unsigned long s_feature_incompat; unsigned long s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned long s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_padding1; unsigned long s_reserved[204]; } ext2; struct ext2_group_desc { unsigned long bg_block_bitmap; unsigned long bg_inode_bitmap; unsigned long bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned long bg_reserved[3]; } *gdes; } ext2_sb; struct fat_super_block { int ino_val; int fat_type; char fatbs[512]; void *bsptr; } fat; } sb; struct vfsops { int (*vfs_mount)(); int (*vfs_unmount)(); int (*vfs_statvfs)(); int (*vfs_sync)(); } *ops; struct mrx_mutex lock; } *

variable_types: index int

variable_types: ngroups int

user_defined_types: struct vfs { struct linked_list vfs_next; struct vnode *vfs_mpoint; unsigned long vfs_dev; unsigned int blk_size; union { struct ext2sb ext2_sb; struct fat_super_block fat; } sb; struct vfsops *ops; struct mrx_mutex lock; }

user_defined_types: struct vnode { unsigned short v_flag; int v_count; struct vfs *v_fsmounted; struct vfs *vfsp; int v_inum; unsigned long v_rdev; int v_type; struct linked_list v_freelist; struct vnode *v_next; struct vnodeops *ops; void *data; struct mrx_mutex smlock; union inode v_ino; }

user_defined_types: struct ext2sb { struct ext2_super_block ext2; struct ext2_group_desc *gdes; }

user_defined_types: struct mrx_mutex { struct mrx_mutexattr mattr; int counter; int sync_id; }

user_defined_types: union inode { struct ext2inode ext2inode; }

user_defined_types: struct vnodeops { int (*vop_open)(struct file *, struct vnode *, int); int (*vop_close)(struct file *, struct vnode *); int (*vop_read)(struct file *, struct vnode *, void *, unsigned int); int (*vop_write)(struct file *, struct vnode *, void *, unsigned int); int (*vop_strategy)(); int (*vop_ioctl)(); int (*vop_create)(); int (*vop_remove)(); int (*vop_link)(); int (*vop_unlink)(); int (*vop_rename)(); int (*vop_mkdir)(); int (*vop_rmdir)(); int (*vop_readdir)(); int (*vop_symlink)(); int (*vop_poll)(); int (*vop_read_inode)(struct vnode *, int); unsigned long (*vop_bmap)(struct vnode *, unsigned long); void (*vop_write_inode)(struct vnode *); int (*vop_namei)(struct vnode *, char *, struct nameidata *); void (*vop_get_attr)(struct vnode *, struct vattr *); void (*vop_put_attr)(struct vnode *, struct vattr *); int (*vop_req_iospace)(int, int); }

user_defined_types: struct file { int f_access; unsigned long f_offset; int f_ref; struct indev vnode; }

user_defined_types: struct nameidata { struct vnode *vn; struct userid id; struct vfs *vfs; char *path; int mode; int access; }


decompiled_code:
_DWORD *arch_setup()
{
_DWORD *result; // rax

init_memory();
pmap_pre_init();
init_paging();
setup_descriptors();
setup_traps();
pic_init(32LL, 40LL);
result = (_DWORD *)kernel_map[2];
*result = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

init_memory();
pmap_pre_init();
init_paging();
setup_descriptors();
setup_traps();
pic_init(32LL, 40LL);
result = (_DWORD *)kernel_map[2];
*result = 0;
return result;
}

original_code:
void arch_setup()
{
 init_memory();
 pmap_pre_init();
 init_paging();
 setup_descriptors();
 setup_traps();
 pic_init(0x20, 0x28);
 kernel_map.pdbr[0] = 0;
}


worker

decompiled_code:
void *__fastcall worker(void *a1)
{
((void (__fastcall *)(char *))svr_func[*((int *)a1 + 3)])((char *)a1 + 16);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1)
{
((void (__fastcall *)(char *))svr_func[*((int *)a1 + 3)])((char *)a1 + 16);
return 0LL;
}

original_code:
void *worker(poolstruct_t pool)
{
 fptr_t ptr;
 ptr = con_func[pool->request];
 ptr(&pool->msg);
 return ((void *) 0);
}

canonical_original_code:
void *worker(struct poolstruct *pool)
{
 int (*ptr)(struct message *);
 ptr = con_func[pool->request];
 ptr(&pool->msg);
 return ((void *) 0);
}

variable_types: struct poolstruct { int flag; int owner_id; int reply; int request; struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; } msg; char data[256]; } *

variable_types: int (*)(struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; } *)

return_type: void *

user_defined_types: struct poolstruct { int flag; int owner_id; int reply; int request; struct message msg; char data[256]; }


decompiled_code:
int handle_full()
{
char *v0; // rax
char *v1; // rbx
struct sched_param param; // [rsp+Ch] [rbp-2Ch] BYREF
char v4[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = (char *)malloc(0x150uLL);
if ( v0 )
{
v1 = v0;
pthread_attr_init((pthread_attr_t *)v4);
param.__sched_priority = 66;
pthread_attr_setschedparam((pthread_attr_t *)v4, &param);
LODWORD(v0) = pthread_create((pthread_t *)(v1 + 4), (const pthread_attr_t *)v4, worker, v1);
}
return (int)v0;
}

canonical_decompiled_code:
int func7()
{
char *v0; // rax
char *v1; // rbx
struct sched_param param; // [rsp+Ch] [rbp-2Ch] BYREF
char v4[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = (char *)malloc(0x150uLL);
if ( v0 )
{
v1 = v0;
pthread_attr_init((pthread_attr_t *)v4);
param.__sched_priority = 66;
pthread_attr_setschedparam((pthread_attr_t *)v4, &param);
LODWORD(v0) = pthread_create((pthread_t *)(v1 + 4), (const pthread_attr_t *)v4, worker, v1);
}
return (int)v0;
}

original_code:
void handle_full(void *ptr)
{
 pthread_attr_t attr;
 struct sched_param parm;
 poolstruct_t thr;
 thr = (poolstruct_t)malloc(sizeof(struct poolstruct));
 if(thr == ((void *) 0))
  return ;
 scr_write("OH serious error.");
 pthread_attr_init(&attr);
 parm.sched_priority = 66;
 pthread_attr_setschedparam(&attr, &parm);
 pthread_create(&thr->owner_id, &attr, (pthtype_t)worker, thr);
}

canonical_original_code:
void handle_full(void *ptr)
{
 struct pthread_attr attr;
 struct sched_param parm;
 struct poolstruct *thr;
 thr = (struct poolstruct *)malloc(sizeof(struct poolstruct));
 if(thr == ((void *) 0))
  return ;
 scr_write("OH serious error.");
 pthread_attr_init(&attr);
 parm.sched_priority = 66;
 pthread_attr_setschedparam(&attr, &parm);
 pthread_create(&thr->owner_id, &attr, (void *(*)(void *))worker, thr);
}

variable_types:
ptr
void *

variable_types: struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; }

user_defined_types: struct pthread_attr { int flags; struct sched_param prio; void *stackaddr; unsigned int stack_size; int policy; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("\nInitializing MISC I/O Mngr\n");
syscall_change_iopl(3LL);
*(&svrpool + 1) = (__int64)handle_full;
*((_DWORD *)&svrpool + 4) = 0;
if ( (int)pool_init(&svrpool, 5LL, svr_worker) < 0 )
printf("Pool Failed");
pci_init();
msg_loop(&svrpool, 27LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("\nInitializing MISC I/O Mngr\n");
func0(3LL);
*(&svrpool + 1) = (__int64)handle_full;
*((_DWORD *)&svrpool + 4) = 0;
if ( (int)pool_init(&svrpool, 5LL, svr_worker) < 0 )
printf("Pool Failed");
pci_init();
msg_loop(&svrpool, 27LL);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int ret;
 termindex = 0;
 syscall_change_iopl(3);
 ttys = (struct terminal *) malloc(sizeof(struct terminal) * ntty);
 if(!ttys)
  con_panic("Not Enough Memory.\n", 0x31);
 ret = console_init();
 if(ret == -1)
  return 1;
 keyb_init();
 scr_write("CONMNGR: Initializing Console Manager: \n");
 ttypool.altworker = (pthtype_t)handle_full;
 ttypool.pool_bitmap = 0;
 ret = pool_init(&ttypool, 5, (pthtype_t)tty_worker);
 if(ret < 0)
  con_panic("Pool Failed", 1);
 msg_loop(&ttypool, 27);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ret;
 termindex = 0;
 syscall_change_iopl(3);
 ttys = (struct terminal *) malloc(sizeof(struct terminal) * ntty);
 if(!ttys)
  con_panic("Not Enough Memory.\n", 0x31);
 ret = console_init();
 if(ret == -1)
  return 1;
 keyb_init();
 scr_write("CONMNGR: Initializing Console Manager: \n");
 ttypool.altworker = (void *(*)(void *))handle_full;
 ttypool.pool_bitmap = 0;
 ret = pool_init(&ttypool, 5, (void *(*)(void *))tty_worker);
 if(ret < 0)
  con_panic("Pool Failed", 1);
 msg_loop(&ttypool, 27);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

user_defined_types: struct terminal { struct termios t_termios; struct termqueue t_input; struct termqueue t_output; struct winattr t_win; int pgid; }

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; }

user_defined_types: struct termqueue { unsigned char queue[512]; unsigned char last_scancode; int end; unsigned long keyflag; int led; int flag; int thread; }

user_defined_types: struct winattr { int current_x; int max_x; int attr; char scrbuf[-1]; }


worker

decompiled_code:
void *__fastcall worker(void *a1)
{
syscall_change_iopl(3LL);
(*(&fs_work + *((int *)a1 + 3)))((char *)a1 + 16);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
func0(3LL);
(*(&fs_work + *((int *)a1 + 3)))((char *)a1 + 16);
return 0LL;
}

user_defined_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; }


canonical_decompiled_code:
int func3()
{
char *v0; // rax
char *v1; // rbx
struct sched_param param; // [rsp+Ch] [rbp-2Ch] BYREF
char v4[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = (char *)malloc(0x150uLL);
if ( v0 )
{
v1 = v0;
pthread_attr_init((pthread_attr_t *)v4);
param.__sched_priority = 66;
pthread_attr_setschedparam((pthread_attr_t *)v4, &param);
LODWORD(v0) = pthread_create((pthread_t *)(v1 + 4), (const pthread_attr_t *)v4, worker, v1);
}
return (int)v0;
}

variable_types: struct sched_param { int sched_priority; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rdi
unsigned int v5; // ebx

printf("\nFSIO manager Initializing.... ");
syscall_change_iopl(3LL);
io_main();
v4 = (char *)argv[1];
if ( argc > 1 && v4 )
v5 = simple_atoi(v4);
else
v5 = 7;
printf("disk is %d argc %d ", v5, (unsigned int)argc);
vfs_init("ext2", (int)(v5 | 0x10000));
*(_QWORD *)&thrpool[2] = handle_full;
thrpool[4] = 0;
pool_init(thrpool, 5LL, fs_worker);
printf("FSIO Done ");
msg_loop(thrpool, 27LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rdi
unsigned int v5; // ebx

printf("\nFSIO manager Initializing.... ");
func0(3LL);
io_main();
v4 = (char *)argv[1];
if ( argc > 1 && v4 )
v5 = func4(v4);
else
v5 = 7;
printf("disk is %d argc %d ", v5, (unsigned int)argc);
vfs_init("ext2", (int)(v5 | 0x10000));
*(_QWORD *)&thrpool[2] = handle_full;
thrpool[4] = 0;
pool_init(thrpool, 5LL, fs_worker);
printf("FSIO Done ");
msg_loop(thrpool, 27LL);
return 0;
}


strcmp

decompiled_code:
__int64 __fastcall strcmp(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 *v4; // rsi
unsigned __int8 v5; // al
bool v6; // cf
__int64 result; // rax

v4 = a1;
while ( 1 )
{
v5 = *v4++;
v6 = *a2 < v5;
if ( *a2++ != v5 )
break;
if ( !v5 )
return 0LL;
}
result = (unsigned int)-v6;
LOBYTE(result) = v6 ? -1 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 *v4; // rsi
unsigned __int8 v5; // al
bool v6; // cf
__int64 result; // rax

v4 = a1;
while ( 1 )
{
v5 = *v4++;
v6 = *a2 < v5;
if ( *a2++ != v5 )
break;
if ( !v5 )
return 0LL;
}
result = (unsigned int)-v6;
LOBYTE(result) = v6 ? -1 : 1;
return result;
}

original_code:
static inline int strcmp(const char * cs,const char * ct)
{
int d0, d1;
register int __res;
__asm__ __volatile__(
 "1:\tlodsb\n\t"
 "scasb\n\t"
 "jne 2f\n\t"
 "testb %%al,%%al\n\t"
 "jne 1b\n\t"
 "xorl %%eax,%%eax\n\t"
 "jmp 3f\n"
 "2:\tsbbl %%eax,%%eax\n\t"
 "orb $1,%%al\n"
 "3:"
 :"=a" (__res), "=&S" (d0), "=&D" (d1)
       :"1" (cs),"2" (ct));
return __res;
}

canonical_original_code:
static inline int strcmp(char *cs, char *ct)
{
int d0; int d1;
register int __res;
__asm__ __volatile__(
 "1:\tlodsb\n\t"
 "scasb\n\t"
 "jne 2f\n\t"
 "testb %%al,%%al\n\t"
 "jne 1b\n\t"
 "xorl %%eax,%%eax\n\t"
 "jmp 3f\n"
 "2:\tsbbl %%eax,%%eax\n\t"
 "orb $1,%%al\n"
 "3:"
 :"=a" (__res), "=&S" (d0), "=&D" (d1)
       :"1" (cs),"2" (ct));
return __res;
}

variable_types:
cs
char *

variable_types:
ct
char *


main

repo: mreiferson/libevbuffsock

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned __int64 v4; // rcx

v3 = new_buffer(0x10uLL);
buffer_add(v3, "asdf", 4LL);
buffer_add(v3, "1234567890", 10LL);
buffer_add(v3, "ghjk", 4LL);
buffer_drain(v3, 8LL);
buffer_add(v3, "1234567890", 10LL);
buffer_add(v3, "!@#$%^", 6LL);
if ( *(_QWORD *)(v3 + 24) != 32LL )
__assert_fail("buf->length == 32", "test.c", 0x11u, "main");
v4 = 27LL;
if ( *(_QWORD *)(v3 + 16) <= 0x1BuLL )
v4 = *(_QWORD *)(v3 + 16);
if ( memcmp(&unk_402032, *(const void **)v3, v4) )
__assert_fail("strncmp(\"567890ghjk1234567890!@#$%^\", buf->data, buf->offset) == 0", "test.c", 0x12u, "main");
return 0;
}

original_code:
int main(int argc, char **argv)
{
    struct Buffer *buf;
    buf = new_buffer(16, 64);
    buffer_add(buf, "asdf", 4);
    buffer_add(buf, "1234567890", 10);
    buffer_add(buf, "ghjk", 4);
    buffer_drain(buf, 8);
    buffer_add(buf, "1234567890", 10);
    buffer_add(buf, "!@#$%^", 6);
    ((void) sizeof ((buf->length == 32) ? 1 : 0), __extension__ ({ if (buf->length == 32) ; else __assert_fail ("buf->length == 32", "test.c", 17, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp("567890ghjk1234567890!@#$%^", buf->data, buf->offset) == 0) ? 1 : 0), __extension__ ({ if (strncmp("567890ghjk1234567890!@#$%^", buf->data, buf->offset) == 0) ; else __assert_fail ("strncmp(\"567890ghjk1234567890!@#$%^\", buf->data, buf->offset) == 0", "test.c", 18, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
argv
char **

variable_types: struct Buffer { char *data; char *orig; unsigned long offset; unsigned long length; unsigned long capacity; } *


decompiled_code:
void __fastcall free_buffer(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void free_buffer(struct Buffer *buf)
{
    if (buf) {
        free(buf->orig);
        free(buf);
    }
}

user_defined_types: struct Buffer { char *data; char *orig; unsigned long offset; unsigned long length; unsigned long capacity; }