icatalloc

decompiled_code:
void *__fastcall icatalloc(void *ptr, char *src)
{
void *v2; // rbx
int v3; // eax
int v4; // er13
int v5; // er12
void *v6; // rax

v2 = ptr;
if ( src )
{
v3 = strlen(src);
v4 = v3;
if ( ptr )
{
if ( !v3 )
return v2;
v5 = strlen((const char *)ptr);
}
else
{
v5 = 0;
}
v6 = realloc(ptr, v5 + v4 + 1);
v2 = v6;
if ( v6 )
strcpy((char *)v6 + v5, src);
}
else if ( !ptr )
{
v2 = malloc(1uLL);
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func0(void *ptr, char *src)
{
void *v2; // rbx
int v3; // eax
int v4; // er13
int v5; // er12
void *v6; // rax

v2 = ptr;
if ( src )
{
v3 = strlen(src);
v4 = v3;
if ( ptr )
{
if ( !v3 )
return v2;
v5 = strlen((const char *)ptr);
}
else
{
v5 = 0;
}
v6 = realloc(ptr, v5 + v4 + 1);
v2 = v6;
if ( v6 )
strcpy((char *)v6 + v5, src);
}
else if ( !ptr )
{
v2 = malloc(1uLL);
}
return v2;
}

original_code:
char *
icatalloc(char *const old, const char *const new)
{
 register char * result;
 register int oldsize, newsize;
 newsize = (new == ((void *)0)) ? 0 : strlen(new);
 if (old == ((void *)0))
  oldsize = 0;
 else if (newsize == 0)
  return old;
 else oldsize = strlen(old);
 if ((result = realloc(old, oldsize + newsize + 1)) != ((void *)0))
  if (new != ((void *)0))
   (void) strcpy(result + oldsize, new);
 return result;
}

canonical_original_code:
char *icatalloc(char *old, char *new)
{
 register char *result;
 register int oldsize; register int newsize;
 newsize = (new == ((void *)0)) ? 0 : strlen(new);
 if (old == ((void *)0))
  oldsize = 0;
 else if (newsize == 0)
  return old;
 else oldsize = strlen(old);
 if ((result = realloc(old, oldsize + newsize + 1)) != ((void *)0))
  if (new != ((void *)0))
   (void) strcpy(result + oldsize, new);
 return result;
}

variable_types:
old
char *

variable_types:
new
char *

variable_types:
result
char *

variable_types: oldsize int

variable_types: newsize int


icpyalloc

repo: phyw/tzdata

decompiled_code:
void *__fastcall icpyalloc(char *src)
{
return icatalloc(0LL, src);
}

canonical_decompiled_code:
void *__fastcall func1(char *src)
{
return func0(0LL, src);
}

original_code:
char *
icpyalloc(const char *const string)
{
 return icatalloc(((void *)0), string);
}

canonical_original_code:
char *icpyalloc(char *string)
{
 return icatalloc(((void *)0), string);
}

variable_types:
string
char *

return_type: char *


scheck

original_code:
const char *
scheck(const char *const string, const char *const format)
{
 register char * fbuf;
 register const char * fp;
 register char * tp;
 register int c;
 register const char * result;
 char dummy;
 result = "";
 if (string == ((void *)0) || format == ((void *)0))
  return result;
 fbuf = malloc(2 * strlen(format) + 4);
 if (fbuf == ((void *)0))
  return result;
 fp = format;
 tp = fbuf;
 while ((*tp++ = c = *fp++) != '\0') {
  if (c != '%')
   continue;
  if (*fp == '%') {
   *tp++ = *fp++;
   continue;
  }
  *tp++ = '*';
  if (*fp == '*')
   ++fp;
  while (((unsigned)(*fp) - '0' <= 9))
   *tp++ = *fp++;
  if (*fp == 'l' || *fp == 'h')
   *tp++ = *fp++;
  else if (*fp == '[')
   do *tp++ = *fp++;
    while (*fp != '\0' && *fp != ']');
  if ((*tp++ = *fp++) == '\0')
   break;
 }
 *(tp - 1) = '%';
 *tp++ = 'c';
 *tp = '\0';
 if (sscanf(string, fbuf, &dummy) != 1)
  result = format;
 free(fbuf);
 return result;
}

canonical_original_code:
char *scheck(char *string, char *format)
{
 register char *fbuf;
 register char *fp;
 register char *tp;
 register int c;
 register char *result;
 char dummy;
 result = "";
 if (string == ((void *)0) || format == ((void *)0))
  return result;
 fbuf = malloc(2 * strlen(format) + 4);
 if (fbuf == ((void *)0))
  return result;
 fp = format;
 tp = fbuf;
 while ((*tp++ = c = *fp++) != '\0') {
  if (c != '%')
   continue;
  if (*fp == '%') {
   *tp++ = *fp++;
   continue;
  }
  *tp++ = '*';
  if (*fp == '*')
   ++fp;
  while (((unsigned int)(*fp) - '0' <= 9))
   *tp++ = *fp++;
  if (*fp == 'l' || *fp == 'h')
   *tp++ = *fp++;
  else if (*fp == '[')
   do *tp++ = *fp++;
    while (*fp != '\0' && *fp != ']');
  if ((*tp++ = *fp++) == '\0')
   break;
 }
 *(tp - 1) = '%';
 *tp++ = 'c';
 *tp = '\0';
 if (sscanf(string, fbuf, &dummy) != 1)
  result = format;
 free(fbuf);
 return result;
}

variable_types:
format
char *

variable_types:
fbuf
char *

variable_types:
fp
char *

variable_types:
tp
char *

variable_types: c int

variable_types: dummy char


difftime

decompiled_code:
double __fastcall difftime(__int64 a1, __int64 a2)
{
double result; // xmm0_8
__int64 v3; // rsi
double v4; // xmm0_8
__int64 v5; // rdi

if ( a1 >= 0 != a2 < 0 )
return (double)((int)a1 - (int)a2);
if ( a1 >= 0 )
{
v5 = a1 - a2;
if ( v5 < 0 )
result = (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1)) + (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1));
else
result = (double)(int)v5;
}
else
{
v3 = a2 - a1;
if ( v3 < 0 )
v4 = (double)(int)(v3 & 1 | ((unsigned __int64)v3 >> 1)) + (double)(int)(v3 & 1 | ((unsigned __int64)v3 >> 1));
else
v4 = (double)(int)v3;
*(_QWORD *)&result = *(_QWORD *)&v4 ^ LC0;
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, __int64 a2)
{
double result; // xmm0_8
__int64 v3; // rsi
double v4; // xmm0_8
__int64 v5; // rdi

if ( a1 >= 0 != a2 < 0 )
return (double)((int)a1 - (int)a2);
if ( a1 >= 0 )
{
v5 = a1 - a2;
if ( v5 < 0 )
result = (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1)) + (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1));
else
result = (double)(int)v5;
}
else
{
v3 = a2 - a1;
if ( v3 < 0 )
v4 = (double)(int)(v3 & 1 | ((unsigned __int64)v3 >> 1)) + (double)(int)(v3 & 1 | ((unsigned __int64)v3 >> 1));
else
v4 = (double)(int)v3;
*(_QWORD *)&result = *(_QWORD *)&v4 ^ LC0;
}
return result;
}

original_code:
double
difftime(const time_t time1, const time_t time0)
{
 if (sizeof (double) > sizeof (time_t))
  return (double) time1 - (double) time0;
 if (!(((time_t) 0.5) != 0.5)) {
  return time1 - time0;
 }
 if (!(((time_t) -1) < 0)) {
  if (time1 >= time0)
   return time1 - time0;
  else return -((double) (time0 - time1));
 }
 if ((time1 < 0) == (time0 < 0))
  return time1 - time0;
 if (sizeof (unsigned long) < sizeof (time_t))
  return (double) time1 - (double) time0;
 if (time1 >= 0 )
  return (unsigned long) time1 +
   (unsigned long) (-(time0 + 1)) + 1;
 return -(double) ((unsigned long) time0 +
  (unsigned long) (-(time1 + 1)) + 1);
}

canonical_original_code:
double difftime(long time1, long time0)
{
 if (sizeof (double) > sizeof (time_t))
  return (double) time1 - (double) time0;
 if (!(((long) 0.5) != 0.5)) {
  return time1 - time0;
 }
 if (!(((time_t) -1) < 0)) {
  if (time1 >= time0)
   return time1 - time0;
  else return -((double) (time0 - time1));
 }
 if ((time1 < 0) == (time0 < 0))
  return time1 - time0;
 if (sizeof (unsigned long) < sizeof (time_t))
  return (double) time1 - (double) time0;
 if (time1 >= 0 )
  return (unsigned long) time1 +
   (unsigned long) (-(time0 + 1)) + 1;
 return -(double) ((unsigned long) time0 +
  (unsigned long) (-(time1 + 1)) + 1);
}

return_type: double


main

canonical_name: main

repo: picosync/workingDraft

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return 0;
}

original_code: int main() {}

canonical_original_code: int main() {}

return_type: int


cyoBaseXXValidate

decompiled_code:
__int64 __fastcall cyoBaseXXValidate(char *a1, unsigned __int64 a2, unsigned __int64 a3, unsigned __int64 a4, unsigned __int8 a5, __int64 a6)
{
int v7; // er8

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 % a3 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0LL;
while ( *a1 >= 0 )
{
if ( *(_BYTE *)(a6 + (unsigned __int8)*a1) > a5 )
{
if ( a4 >= a2 )
{
v7 = a5 + 1;
do
{
if ( *a1 < 0 )
break;
if ( *(unsigned __int8 *)(a6 + (unsigned __int8)*a1) != v7 )
break;
++a1;
if ( !--a2 )
break;
}
while ( a4 >= a2 );
}
return a2 != 0 ? 0xFFFFFFFE : 0;
}
++a1;
if ( !--a2 )
return 0LL;
}
return a2 != 0 ? 0xFFFFFFFE : 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, unsigned __int64 a2, unsigned __int64 a3, unsigned __int64 a4, unsigned __int8 a5, __int64 a6)
{
int v7; // er8

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 % a3 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0LL;
while ( *a1 >= 0 )
{
if ( *(_BYTE *)(a6 + (unsigned __int8)*a1) > a5 )
{
if ( a4 >= a2 )
{
v7 = a5 + 1;
do
{
if ( *a1 < 0 )
break;
if ( *(unsigned __int8 *)(a6 + (unsigned __int8)*a1) != v7 )
break;
++a1;
if ( !--a2 )
break;
}
while ( a4 >= a2 );
}
return a2 != 0 ? 0xFFFFFFFE : 0;
}
++a1;
if ( !--a2 )
return 0LL;
}
return a2 != 0 ? 0xFFFFFFFE : 0;
}

original_code:
static int cyoBaseXXValidate( const char* src, size_t size, size_t inputBytes, size_t maxPadding,
                              unsigned char maxValue, const unsigned char table[] )
{
    if (!src)
        return -1;
    if (size % inputBytes != 0)
        return -1;
    for (; size >= 1; --size, ++src)
    {
        unsigned char ch = *src;
        if ((ch >= 0x80) || (table[ ch ] > maxValue))
            break;
    }
    for (; 1 <= size && size <= maxPadding; --size, ++src)
    {
        unsigned char ch = *src;
        if ((ch >= 0x80) || (table[ ch ] != maxValue + 1))
            break;
    }
    if (size != 0)
        return -2;
    return 0;
}

canonical_original_code:
static int cyoBaseXXValidate(char *src, unsigned long size, unsigned long inputBytes, unsigned long maxPadding, unsigned char maxValue, unsigned char table[])
{
    if (!src)
        return -1;
    if (size % inputBytes != 0)
        return -1;
    for (; size >= 1; --size, ++src)
    {
        unsigned char ch = *src;
        if ((ch >= 0x80) || (table[ ch ] > maxValue))
            break;
    }
    for (; 1 <= size && size <= maxPadding; --size, ++src)
    {
        unsigned char ch = *src;
        if ((ch >= 0x80) || (table[ ch ] != maxValue + 1))
            break;
    }
    if (size != 0)
        return -2;
    return 0;
}

variable_types:
src
char *

variable_types:
size
unsigned long

variable_types:
inputBytes
unsigned long

variable_types:
maxPadding
unsigned long

variable_types:
maxValue
unsigned char

variable_types:
table
unsigned char []

variable_types:
ch
unsigned char


cyoBaseXXDecodeGetLength

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

result = 0LL;
if ( !(a1 % a2) )
result = a3 * ((a1 + a2 - 1) / a2) + 1;
return result;
}

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

result = 0LL;
if ( !(a1 % a2) )
result = a3 * ((a1 + a2 - 1) / a2) + 1;
return result;
}

original_code:
static size_t cyoBaseXXDecodeGetLength( size_t size, size_t inputBytes, size_t outputBytes )
{
    if (size % inputBytes != 0)
        return 0;
    return (((size + inputBytes - 1) / inputBytes) * outputBytes) + 1;
}

canonical_original_code:
static unsigned long cyoBaseXXDecodeGetLength(unsigned long size, unsigned long inputBytes, unsigned long outputBytes)
{
    if (size % inputBytes != 0)
        return 0;
    return (((size + inputBytes - 1) / inputBytes) * outputBytes) + 1;
}

variable_types:
outputBytes
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall cyoBase16Validate(char *a1, unsigned __int64 a2)
{
return cyoBaseXXValidate(a1, a2, 2uLL, 0LL, 0xFu, (__int64)&BASE16_TABLE);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, unsigned __int64 a2)
{
return func0(a1, a2, 2uLL, 0LL, 0xFu, (__int64)&BASE16_TABLE);
}

original_code:
int cyoBase16Validate( const char* src, size_t size )
{
    return cyoBaseXXValidate( src, size, BASE16_INPUT, BASE16_MAX_PADDING, BASE16_MAX_VALUE, BASE16_TABLE );
}

canonical_original_code:
int cyoBase16Validate(char *src, unsigned long size)
{
    return cyoBaseXXValidate( src, size, BASE16_INPUT, BASE16_MAX_PADDING, BASE16_MAX_VALUE, BASE16_TABLE );
}


decompiled_code:
unsigned __int64 __fastcall cyoBase16DecodeGetLength(unsigned __int64 a1)
{
return cyoBaseXXDecodeGetLength(a1, 2uLL, 1LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int64 a1)
{
return func1(a1, 2uLL, 1LL);
}

original_code:
size_t cyoBase16DecodeGetLength( size_t size )
{
    return cyoBaseXXDecodeGetLength( size, BASE16_INPUT, BASE16_OUTPUT );
}

canonical_original_code:
unsigned long cyoBase16DecodeGetLength(unsigned long size)
{
    return cyoBaseXXDecodeGetLength( size, BASE16_INPUT, BASE16_OUTPUT );
}


decompiled_code:
__int64 __fastcall cyoBase16Decode(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rcx
__int64 v5; // r9
__int64 v6; // rsi
char v7; // al
char v8; // dl
char v9; // al
char v10; // dl

v4 = a3;
if ( !a1 || !a2 )
return 0LL;
v5 = a3 & 1;
if ( (a3 & 1) != 0 )
return 0LL;
if ( a3 )
{
v6 = a3 & 1;
while ( 1 )
{
v7 = *(_BYTE *)(a2 + 2 * v6);
v8 = *(_BYTE *)(a2 + 2 * v6 + 1);
v4 -= 2LL;
if ( v7 < 0 )
break;
if ( v8 < 0 )
break;
v9 = BASE16_TABLE[(unsigned __int8)v7];
v10 = BASE16_TABLE[(unsigned __int8)v8];
if ( (unsigned __int8)v9 > 0xFu || (unsigned __int8)v10 > 0xFu )
break;
*a1++ = v10 | (16 * v9);
++v6;
if ( !v4 )
goto LABEL_11;
}
}
else
{
v6 = 0LL;
LABEL_11:
*a1 = 0;
v5 = v6;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rcx
__int64 v5; // r9
__int64 v6; // rsi
char v7; // al
char v8; // dl
char v9; // al
char v10; // dl

v4 = a3;
if ( !a1 || !a2 )
return 0LL;
v5 = a3 & 1;
if ( (a3 & 1) != 0 )
return 0LL;
if ( a3 )
{
v6 = a3 & 1;
while ( 1 )
{
v7 = *(_BYTE *)(a2 + 2 * v6);
v8 = *(_BYTE *)(a2 + 2 * v6 + 1);
v4 -= 2LL;
if ( v7 < 0 )
break;
if ( v8 < 0 )
break;
v9 = BASE16_TABLE[(unsigned __int8)v7];
v10 = BASE16_TABLE[(unsigned __int8)v8];
if ( (unsigned __int8)v9 > 0xFu || (unsigned __int8)v10 > 0xFu )
break;
*a1++ = v10 | (16 * v9);
++v6;
if ( !v4 )
goto LABEL_11;
}
}
else
{
v6 = 0LL;
LABEL_11:
*a1 = 0;
v5 = v6;
}
return v5;
}

original_code:
size_t cyoBase16Decode( void* dest, const char* src, size_t size )
{
    if (dest && src && (size % BASE16_INPUT == 0))
    {
        unsigned char* pDest = (unsigned char*)dest;
        size_t dwSrcSize = size;
        size_t dwDestSize = 0;
        unsigned char in1, in2;
        while (dwSrcSize >= 1)
        {
            in1 = *src++;
            in2 = *src++;
            dwSrcSize -= BASE16_INPUT;
            if (in1 >= 0x80 || in2 >= 0x80)
                return 0;
            in1 = BASE16_TABLE[ in1 ];
            in2 = BASE16_TABLE[ in2 ];
            if (in1 > BASE16_MAX_VALUE || in2 > BASE16_MAX_VALUE)
                return 0;
            *pDest++ = ((in1 << 4) | in2);
            dwDestSize += BASE16_OUTPUT;
        }
        *pDest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

canonical_original_code:
unsigned long cyoBase16Decode(void *dest, char *src, unsigned long size)
{
    if (dest && src && (size % BASE16_INPUT == 0))
    {
        unsigned char *pDest = (unsigned char*)dest;
        unsigned long dwSrcSize = size;
        unsigned long dwDestSize = 0;
        unsigned char in1; unsigned char in2;
        while (dwSrcSize >= 1)
        {
            in1 = *src++;
            in2 = *src++;
            dwSrcSize -= BASE16_INPUT;
            if (in1 >= 0x80 || in2 >= 0x80)
                return 0;
            in1 = BASE16_TABLE[ in1 ];
            in2 = BASE16_TABLE[ in2 ];
            if (in1 > BASE16_MAX_VALUE || in2 > BASE16_MAX_VALUE)
                return 0;
            *pDest++ = ((in1 << 4) | in2);
            dwDestSize += BASE16_OUTPUT;
        }
        *pDest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

variable_types:
dest
void *

variable_types:
pDest
unsigned char *

variable_types:
dwSrcSize
unsigned long

variable_types:
dwDestSize
unsigned long


decompiled_code:
__int64 __fastcall cyoBase32Validate(char *a1, unsigned __int64 a2)
{
return cyoBaseXXValidate(a1, a2, 8uLL, 6uLL, 0x1Fu, (__int64)&BASE32_TABLE);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, unsigned __int64 a2)
{
return func0(a1, a2, 8uLL, 6uLL, 0x1Fu, (__int64)&BASE32_TABLE);
}

original_code:
int cyoBase32Validate( const char* src, size_t size )
{
    return cyoBaseXXValidate( src, size, BASE32_INPUT, BASE32_MAX_PADDING, BASE32_MAX_VALUE, BASE32_TABLE );
}

canonical_original_code:
int cyoBase32Validate(char *src, unsigned long size)
{
    return cyoBaseXXValidate( src, size, BASE32_INPUT, BASE32_MAX_PADDING, BASE32_MAX_VALUE, BASE32_TABLE );
}


decompiled_code:
unsigned __int64 __fastcall cyoBase32DecodeGetLength(unsigned __int64 a1)
{
return cyoBaseXXDecodeGetLength(a1, 8uLL, 5LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(unsigned __int64 a1)
{
return func1(a1, 8uLL, 5LL);
}

original_code:
size_t cyoBase32DecodeGetLength( size_t size )
{
    return cyoBaseXXDecodeGetLength( size, BASE32_INPUT, BASE32_OUTPUT );
}

canonical_original_code:
unsigned long cyoBase32DecodeGetLength(unsigned long size)
{
    return cyoBaseXXDecodeGetLength( size, BASE32_INPUT, BASE32_OUTPUT );
}


original_code:
size_t cyoBase32Decode( void* dest, const char* src, size_t size )
{
    if (dest && src && (size % BASE32_INPUT == 0))
    {
        unsigned char* pDest = (unsigned char*)dest;
        size_t dwSrcSize = size;
        size_t dwDestSize = 0;
        unsigned char in1, in2, in3, in4, in5, in6, in7, in8;
        while (dwSrcSize >= 1)
        {
            in1 = *src++;
            in2 = *src++;
            in3 = *src++;
            in4 = *src++;
            in5 = *src++;
            in6 = *src++;
            in7 = *src++;
            in8 = *src++;
            dwSrcSize -= BASE32_INPUT;
            if ( in1 >= 0x80 || in2 >= 0x80 || in3 >= 0x80 || in4 >= 0x80
                || in5 >= 0x80 || in6 >= 0x80 || in7 >= 0x80 || in8 >= 0x80)
                return 0;
            in1 = BASE32_TABLE[ in1 ];
            in2 = BASE32_TABLE[ in2 ];
            in3 = BASE32_TABLE[ in3 ];
            in4 = BASE32_TABLE[ in4 ];
            in5 = BASE32_TABLE[ in5 ];
            in6 = BASE32_TABLE[ in6 ];
            in7 = BASE32_TABLE[ in7 ];
            in8 = BASE32_TABLE[ in8 ];
            if (in1 > BASE32_MAX_VALUE || in2 > BASE32_MAX_VALUE)
                return 0;
            if ( in3 > BASE32_MAX_VALUE + 1 || in4 > BASE32_MAX_VALUE + 1 || in5 > BASE32_MAX_VALUE + 1
                || in6 > BASE32_MAX_VALUE + 1 || in7 > BASE32_MAX_VALUE + 1 || in8 > BASE32_MAX_VALUE + 1)
                return 0;
            *pDest++ = ((in1 & 0x1f) << 3) | ((in2 & 0x1c) >> 2);
            *pDest++ = ((in2 & 0x03) << 6) | ((in3 & 0x1f) << 1) | ((in4 & 0x10) >> 4);
            *pDest++ = ((in4 & 0x0f) << 4) | ((in5 & 0x1e) >> 1);
            *pDest++ = ((in5 & 0x01) << 7) | ((in6 & 0x1f) << 2) | ((in7 & 0x18) >> 3);
            *pDest++ = ((in7 & 0x07) << 5) | (in8 & 0x1f);
            dwDestSize += BASE32_OUTPUT;
            if (in8 == BASE32_MAX_VALUE + 1)
            {
                --dwDestSize;
                ((void) sizeof (((in7 == BASE32_MAX_VALUE + 1 && in6 == BASE32_MAX_VALUE + 1) || (in7 != BASE32_MAX_VALUE + 1)) ? 1 : 0), __extension__ ({ if ((in7 == BASE32_MAX_VALUE + 1 && in6 == BASE32_MAX_VALUE + 1) || (in7 != BASE32_MAX_VALUE + 1)) ; else __assert_fail ("(in7 == BASE32_MAX_VALUE + 1 && in6 == BASE32_MAX_VALUE + 1) || (in7 != BASE32_MAX_VALUE + 1)", "src/CyoDecode.c", 272, __extension__ __PRETTY_FUNCTION__); }));
                if (in6 == BASE32_MAX_VALUE + 1)
                {
                    --dwDestSize;
                    if (in5 == BASE32_MAX_VALUE + 1)
                    {
                        --dwDestSize;
                        ((void) sizeof (((in4 == BASE32_MAX_VALUE + 1 && in3 == BASE32_MAX_VALUE + 1) || (in4 != BASE32_MAX_VALUE + 1)) ? 1 : 0), __extension__ ({ if ((in4 == BASE32_MAX_VALUE + 1 && in3 == BASE32_MAX_VALUE + 1) || (in4 != BASE32_MAX_VALUE + 1)) ; else __assert_fail ("(in4 == BASE32_MAX_VALUE + 1 && in3 == BASE32_MAX_VALUE + 1) || (in4 != BASE32_MAX_VALUE + 1)", "src/CyoDecode.c", 279, __extension__ __PRETTY_FUNCTION__); }));
                        if (in3 == BASE32_MAX_VALUE + 1)
                        {
                            --dwDestSize;
                        }
                    }
                }
            }
        }
        *pDest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

canonical_original_code:
unsigned long cyoBase32Decode(void *dest, char *src, unsigned long size)
{
    if (dest && src && (size % BASE32_INPUT == 0))
    {
        unsigned char *pDest = (unsigned char*)dest;
        unsigned long dwSrcSize = size;
        unsigned long dwDestSize = 0;
        unsigned char in1; unsigned char in2; unsigned char in3; unsigned char in4; unsigned char in5; unsigned char in6; unsigned char in7; unsigned char in8;
        while (dwSrcSize >= 1)
        {
            in1 = *src++;
            in2 = *src++;
            in3 = *src++;
            in4 = *src++;
            in5 = *src++;
            in6 = *src++;
            in7 = *src++;
            in8 = *src++;
            dwSrcSize -= BASE32_INPUT;
            if ( in1 >= 0x80 || in2 >= 0x80 || in3 >= 0x80 || in4 >= 0x80
                || in5 >= 0x80 || in6 >= 0x80 || in7 >= 0x80 || in8 >= 0x80)
                return 0;
            in1 = BASE32_TABLE[ in1 ];
            in2 = BASE32_TABLE[ in2 ];
            in3 = BASE32_TABLE[ in3 ];
            in4 = BASE32_TABLE[ in4 ];
            in5 = BASE32_TABLE[ in5 ];
            in6 = BASE32_TABLE[ in6 ];
            in7 = BASE32_TABLE[ in7 ];
            in8 = BASE32_TABLE[ in8 ];
            if (in1 > BASE32_MAX_VALUE || in2 > BASE32_MAX_VALUE)
                return 0;
            if ( in3 > BASE32_MAX_VALUE + 1 || in4 > BASE32_MAX_VALUE + 1 || in5 > BASE32_MAX_VALUE + 1
                || in6 > BASE32_MAX_VALUE + 1 || in7 > BASE32_MAX_VALUE + 1 || in8 > BASE32_MAX_VALUE + 1)
                return 0;
            *pDest++ = ((in1 & 0x1f) << 3) | ((in2 & 0x1c) >> 2);
            *pDest++ = ((in2 & 0x03) << 6) | ((in3 & 0x1f) << 1) | ((in4 & 0x10) >> 4);
            *pDest++ = ((in4 & 0x0f) << 4) | ((in5 & 0x1e) >> 1);
            *pDest++ = ((in5 & 0x01) << 7) | ((in6 & 0x1f) << 2) | ((in7 & 0x18) >> 3);
            *pDest++ = ((in7 & 0x07) << 5) | (in8 & 0x1f);
            dwDestSize += BASE32_OUTPUT;
            if (in8 == BASE32_MAX_VALUE + 1)
            {
                --dwDestSize;
                ((void) sizeof (((in7 == BASE32_MAX_VALUE + 1 && in6 == BASE32_MAX_VALUE + 1) || (in7 != BASE32_MAX_VALUE + 1)) ? 1 : 0), __extension__ ({ if ((in7 == BASE32_MAX_VALUE + 1 && in6 == BASE32_MAX_VALUE + 1) || (in7 != BASE32_MAX_VALUE + 1)) ; else __assert_fail ("(in7 == BASE32_MAX_VALUE + 1 && in6 == BASE32_MAX_VALUE + 1) || (in7 != BASE32_MAX_VALUE + 1)", "src/CyoDecode.c", 272, __extension__ __PRETTY_FUNCTION__); }));
                if (in6 == BASE32_MAX_VALUE + 1)
                {
                    --dwDestSize;
                    if (in5 == BASE32_MAX_VALUE + 1)
                    {
                        --dwDestSize;
                        ((void) sizeof (((in4 == BASE32_MAX_VALUE + 1 && in3 == BASE32_MAX_VALUE + 1) || (in4 != BASE32_MAX_VALUE + 1)) ? 1 : 0), __extension__ ({ if ((in4 == BASE32_MAX_VALUE + 1 && in3 == BASE32_MAX_VALUE + 1) || (in4 != BASE32_MAX_VALUE + 1)) ; else __assert_fail ("(in4 == BASE32_MAX_VALUE + 1 && in3 == BASE32_MAX_VALUE + 1) || (in4 != BASE32_MAX_VALUE + 1)", "src/CyoDecode.c", 279, __extension__ __PRETTY_FUNCTION__); }));
                        if (in3 == BASE32_MAX_VALUE + 1)
                        {
                            --dwDestSize;
                        }
                    }
                }
            }
        }
        *pDest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}


decompiled_code:
__int64 __fastcall cyoBase64Validate(char *a1, unsigned __int64 a2)
{
return cyoBaseXXValidate(a1, a2, 4uLL, 2uLL, 0x3Fu, (__int64)&BASE64_TABLE);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, unsigned __int64 a2)
{
return func0(a1, a2, 4uLL, 2uLL, 0x3Fu, (__int64)&BASE64_TABLE);
}

original_code:
int cyoBase64Validate( const char* src, size_t size )
{
    return cyoBaseXXValidate( src, size, BASE64_INPUT, BASE64_MAX_PADDING, BASE64_MAX_VALUE, BASE64_TABLE );
}

canonical_original_code:
int cyoBase64Validate(char *src, unsigned long size)
{
    return cyoBaseXXValidate( src, size, BASE64_INPUT, BASE64_MAX_PADDING, BASE64_MAX_VALUE, BASE64_TABLE );
}


decompiled_code:
unsigned __int64 __fastcall cyoBase64DecodeGetLength(unsigned __int64 a1)
{
return cyoBaseXXDecodeGetLength(a1, 4uLL, 3LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(unsigned __int64 a1)
{
return func1(a1, 4uLL, 3LL);
}

original_code:
size_t cyoBase64DecodeGetLength( size_t size )
{
    return cyoBaseXXDecodeGetLength( size, BASE64_INPUT, BASE64_OUTPUT );
}

canonical_original_code:
unsigned long cyoBase64DecodeGetLength(unsigned long size)
{
    return cyoBaseXXDecodeGetLength( size, BASE64_INPUT, BASE64_OUTPUT );
}


original_code:
size_t cyoBase64Decode( void* dest, const char* src, size_t size )
{
    if (dest && src && (size % BASE64_INPUT == 0))
    {
        unsigned char* pDest = (unsigned char*)dest;
        size_t dwSrcSize = size;
        size_t dwDestSize = 0;
        unsigned char in1, in2, in3, in4;
        while (dwSrcSize >= 1)
        {
            in1 = *src++;
            in2 = *src++;
            in3 = *src++;
            in4 = *src++;
            dwSrcSize -= BASE64_INPUT;
            if (in1 >= 0x80 || in2 >= 0x80 || in3 >= 0x80 || in4 >= 0x80)
                return 0;
            in1 = BASE64_TABLE[ in1 ];
            in2 = BASE64_TABLE[ in2 ];
            in3 = BASE64_TABLE[ in3 ];
            in4 = BASE64_TABLE[ in4 ];
            if (in1 > BASE64_MAX_VALUE || in2 > BASE64_MAX_VALUE)
                return 0;
            if (in3 > BASE64_MAX_VALUE + 1 || in4 > BASE64_MAX_VALUE + 1)
                return 0;
            *pDest++ = ((in1 & 0x3f) << 2) | ((in2 & 0x30) >> 4);
            *pDest++ = ((in2 & 0x0f) << 4) | ((in3 & 0x3c) >> 2);
            *pDest++ = ((in3 & 0x03) << 6) | (in4 & 0x3f);
            dwDestSize += BASE64_OUTPUT;
            if (in4 == BASE64_MAX_VALUE + 1)
            {
                --dwDestSize;
                if (in3 == BASE64_MAX_VALUE + 1)
                {
                    --dwDestSize;
                }
            }
        }
        *pDest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

canonical_original_code:
unsigned long cyoBase64Decode(void *dest, char *src, unsigned long size)
{
    if (dest && src && (size % BASE64_INPUT == 0))
    {
        unsigned char *pDest = (unsigned char*)dest;
        unsigned long dwSrcSize = size;
        unsigned long dwDestSize = 0;
        unsigned char in1; unsigned char in2; unsigned char in3; unsigned char in4;
        while (dwSrcSize >= 1)
        {
            in1 = *src++;
            in2 = *src++;
            in3 = *src++;
            in4 = *src++;
            dwSrcSize -= BASE64_INPUT;
            if (in1 >= 0x80 || in2 >= 0x80 || in3 >= 0x80 || in4 >= 0x80)
                return 0;
            in1 = BASE64_TABLE[ in1 ];
            in2 = BASE64_TABLE[ in2 ];
            in3 = BASE64_TABLE[ in3 ];
            in4 = BASE64_TABLE[ in4 ];
            if (in1 > BASE64_MAX_VALUE || in2 > BASE64_MAX_VALUE)
                return 0;
            if (in3 > BASE64_MAX_VALUE + 1 || in4 > BASE64_MAX_VALUE + 1)
                return 0;
            *pDest++ = ((in1 & 0x3f) << 2) | ((in2 & 0x30) >> 4);
            *pDest++ = ((in2 & 0x0f) << 4) | ((in3 & 0x3c) >> 2);
            *pDest++ = ((in3 & 0x03) << 6) | (in4 & 0x3f);
            dwDestSize += BASE64_OUTPUT;
            if (in4 == BASE64_MAX_VALUE + 1)
            {
                --dwDestSize;
                if (in3 == BASE64_MAX_VALUE + 1)
                {
                    --dwDestSize;
                }
            }
        }
        *pDest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}


cyoBaseXXEncodeGetLength

decompiled_code:
unsigned __int64 __fastcall cyoBaseXXEncodeGetLength(__int64 a1, unsigned __int64 a2, __int64 a3)
{
return a3 * ((a2 + a1 - 1) / a2) + 1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned __int64 a2, __int64 a3)
{
return a3 * ((a2 + a1 - 1) / a2) + 1;
}

original_code:
static size_t cyoBaseXXEncodeGetLength( size_t size, size_t inputBytes, size_t outputBytes )
{
    return (((size + inputBytes - 1) / inputBytes) * outputBytes) + 1;
}

canonical_original_code:
static unsigned long cyoBaseXXEncodeGetLength(unsigned long size, unsigned long inputBytes, unsigned long outputBytes)
{
    return (((size + inputBytes - 1) / inputBytes) * outputBytes) + 1;
}


decompiled_code:
unsigned __int64 __fastcall cyoBase16EncodeGetLength(__int64 a1)
{
return cyoBaseXXEncodeGetLength(a1, 1uLL, 2LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1)
{
return func0(a1, 1uLL, 2LL);
}

original_code:
size_t cyoBase16EncodeGetLength( size_t size )
{
    return cyoBaseXXEncodeGetLength( size, BASE16_INPUT, BASE16_OUTPUT );
}

canonical_original_code:
unsigned long cyoBase16EncodeGetLength(unsigned long size)
{
    return cyoBaseXXEncodeGetLength( size, BASE16_INPUT, BASE16_OUTPUT );
}


decompiled_code:
__int64 __fastcall cyoBase16Encode(_BYTE *a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int8 *v5; // r9
_BYTE *v6; // rdx
unsigned __int8 v7; // al
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
if ( a3 )
{
v5 = &a2[a3];
v6 = a1;
do
{
v7 = *a2++;
*v6 = byte_4DB[v7 >> 4];
v6 += 2;
*(v6 - 1) = byte_4DB[v7 & 0xF];
}
while ( a2 != v5 );
result = 2 * a3;
a1 += 2 * a3;
}
else
{
result = 0LL;
}
*a1 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int8 *v5; // r9
_BYTE *v6; // rdx
unsigned __int8 v7; // al
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
if ( a3 )
{
v5 = &a2[a3];
v6 = a1;
do
{
v7 = *a2++;
*v6 = byte_4DB[v7 >> 4];
v6 += 2;
*(v6 - 1) = byte_4DB[v7 & 0xF];
}
while ( a2 != v5 );
result = 2 * a3;
a1 += 2 * a3;
}
else
{
result = 0LL;
}
*a1 = 0;
return result;
}

original_code:
size_t cyoBase16Encode( char* dest, const void* src, size_t size )
{
    if (dest && src)
    {
        unsigned char* pSrc = (unsigned char*)src;
        size_t dwSrcSize = size;
        size_t dwDestSize = 0;
        unsigned char ch;
        while (dwSrcSize >= 1)
        {
            ch = *pSrc++;
            dwSrcSize -= BASE16_INPUT;
            *dest++ = BASE16_TABLE[ (ch & 0xf0) >> 4 ];
            *dest++ = BASE16_TABLE[ (ch & 0x0f) ];
            dwDestSize += BASE16_OUTPUT;
        }
        *dest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

canonical_original_code:
unsigned long cyoBase16Encode(char *dest, void *src, unsigned long size)
{
    if (dest && src)
    {
        unsigned char *pSrc = (unsigned char*)src;
        unsigned long dwSrcSize = size;
        unsigned long dwDestSize = 0;
        unsigned char ch;
        while (dwSrcSize >= 1)
        {
            ch = *pSrc++;
            dwSrcSize -= BASE16_INPUT;
            *dest++ = BASE16_TABLE[ (ch & 0xf0) >> 4 ];
            *dest++ = BASE16_TABLE[ (ch & 0x0f) ];
            dwDestSize += BASE16_OUTPUT;
        }
        *dest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

variable_types:
dest
char *

variable_types:
src
void *

variable_types:
pSrc
unsigned char *


decompiled_code:
unsigned __int64 __fastcall cyoBase32EncodeGetLength(__int64 a1)
{
return cyoBaseXXEncodeGetLength(a1, 5uLL, 8LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1)
{
return func0(a1, 5uLL, 8LL);
}

original_code:
size_t cyoBase32EncodeGetLength( size_t size )
{
    return cyoBaseXXEncodeGetLength( size, BASE32_INPUT, BASE32_OUTPUT );
}

canonical_original_code:
unsigned long cyoBase32EncodeGetLength(unsigned long size)
{
    return cyoBaseXXEncodeGetLength( size, BASE32_INPUT, BASE32_OUTPUT );
}


original_code:
size_t cyoBase32Encode( char* dest, const void* src, size_t size )
{
    if (dest && src)
    {
        unsigned char* pSrc = (unsigned char*)src;
        size_t dwSrcSize = size;
        size_t dwDestSize = 0;
        size_t dwBlockSize;
        unsigned char n1, n2, n3, n4, n5, n6, n7, n8;
        while (dwSrcSize >= 1)
        {
            dwBlockSize = (dwSrcSize < BASE32_INPUT ? dwSrcSize : BASE32_INPUT);
            n1 = n2 = n3 = n4 = n5 = n6 = n7 = n8 = 0;
            switch (dwBlockSize)
            {
            case 5:
                n8 = (pSrc[ 4 ] & 0x1f);
                n7 = ((pSrc[ 4 ] & 0xe0) >> 5);
            case 4:
                n7 |= ((pSrc[ 3 ] & 0x03) << 3);
                n6 = ((pSrc[ 3 ] & 0x7c) >> 2);
                n5 = ((pSrc[ 3 ] & 0x80) >> 7);
            case 3:
                n5 |= ((pSrc[ 2 ] & 0x0f) << 1);
                n4 = ((pSrc[ 2 ] & 0xf0) >> 4);
            case 2:
                n4 |= ((pSrc[ 1 ] & 0x01) << 4);
                n3 = ((pSrc[ 1 ] & 0x3e) >> 1);
                n2 = ((pSrc[ 1 ] & 0xc0) >> 6);
            case 1:
                n2 |= ((pSrc[ 0 ] & 0x07) << 2);
                n1 = ((pSrc[ 0 ] & 0xf8) >> 3);
                break;
            default:
                ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/CyoEncode.c", 149, __extension__ __PRETTY_FUNCTION__); }));
            }
            pSrc += dwBlockSize;
            dwSrcSize -= dwBlockSize;
            ((void) sizeof ((n1 <= 31) ? 1 : 0), __extension__ ({ if (n1 <= 31) ; else __assert_fail ("n1 <= 31", "src/CyoEncode.c", 155, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n2 <= 31) ? 1 : 0), __extension__ ({ if (n2 <= 31) ; else __assert_fail ("n2 <= 31", "src/CyoEncode.c", 156, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n3 <= 31) ? 1 : 0), __extension__ ({ if (n3 <= 31) ; else __assert_fail ("n3 <= 31", "src/CyoEncode.c", 157, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n4 <= 31) ? 1 : 0), __extension__ ({ if (n4 <= 31) ; else __assert_fail ("n4 <= 31", "src/CyoEncode.c", 158, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n5 <= 31) ? 1 : 0), __extension__ ({ if (n5 <= 31) ; else __assert_fail ("n5 <= 31", "src/CyoEncode.c", 159, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n6 <= 31) ? 1 : 0), __extension__ ({ if (n6 <= 31) ; else __assert_fail ("n6 <= 31", "src/CyoEncode.c", 160, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n7 <= 31) ? 1 : 0), __extension__ ({ if (n7 <= 31) ; else __assert_fail ("n7 <= 31", "src/CyoEncode.c", 161, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n8 <= 31) ? 1 : 0), __extension__ ({ if (n8 <= 31) ; else __assert_fail ("n8 <= 31", "src/CyoEncode.c", 162, __extension__ __PRETTY_FUNCTION__); }));
            switch (dwBlockSize)
            {
            case 1: n3 = n4 = 32;
            case 2: n5 = 32;
            case 3: n6 = n7 = 32;
            case 4: n8 = 32;
            case 5:
                break;
            default:
                ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/CyoEncode.c", 175, __extension__ __PRETTY_FUNCTION__); }));
            }
            *dest++ = BASE32_TABLE[ n1 ];
            *dest++ = BASE32_TABLE[ n2 ];
            *dest++ = BASE32_TABLE[ n3 ];
            *dest++ = BASE32_TABLE[ n4 ];
            *dest++ = BASE32_TABLE[ n5 ];
            *dest++ = BASE32_TABLE[ n6 ];
            *dest++ = BASE32_TABLE[ n7 ];
            *dest++ = BASE32_TABLE[ n8 ];
            dwDestSize += BASE32_OUTPUT;
        }
        *dest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

canonical_original_code:
unsigned long cyoBase32Encode(char *dest, void *src, unsigned long size)
{
    if (dest && src)
    {
        unsigned char *pSrc = (unsigned char*)src;
        unsigned long dwSrcSize = size;
        unsigned long dwDestSize = 0;
        unsigned long dwBlockSize;
        unsigned char n1; unsigned char n2; unsigned char n3; unsigned char n4; unsigned char n5; unsigned char n6; unsigned char n7; unsigned char n8;
        while (dwSrcSize >= 1)
        {
            dwBlockSize = (dwSrcSize < BASE32_INPUT ? dwSrcSize : BASE32_INPUT);
            n1 = n2 = n3 = n4 = n5 = n6 = n7 = n8 = 0;
            switch (dwBlockSize)
            {
            case 5:
                n8 = (pSrc[ 4 ] & 0x1f);
                n7 = ((pSrc[ 4 ] & 0xe0) >> 5);
            case 4:
                n7 |= ((pSrc[ 3 ] & 0x03) << 3);
                n6 = ((pSrc[ 3 ] & 0x7c) >> 2);
                n5 = ((pSrc[ 3 ] & 0x80) >> 7);
            case 3:
                n5 |= ((pSrc[ 2 ] & 0x0f) << 1);
                n4 = ((pSrc[ 2 ] & 0xf0) >> 4);
            case 2:
                n4 |= ((pSrc[ 1 ] & 0x01) << 4);
                n3 = ((pSrc[ 1 ] & 0x3e) >> 1);
                n2 = ((pSrc[ 1 ] & 0xc0) >> 6);
            case 1:
                n2 |= ((pSrc[ 0 ] & 0x07) << 2);
                n1 = ((pSrc[ 0 ] & 0xf8) >> 3);
                break;
            default:
                ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/CyoEncode.c", 149, __extension__ __PRETTY_FUNCTION__); }));
            }
            pSrc += dwBlockSize;
            dwSrcSize -= dwBlockSize;
            ((void) sizeof ((n1 <= 31) ? 1 : 0), __extension__ ({ if (n1 <= 31) ; else __assert_fail ("n1 <= 31", "src/CyoEncode.c", 155, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n2 <= 31) ? 1 : 0), __extension__ ({ if (n2 <= 31) ; else __assert_fail ("n2 <= 31", "src/CyoEncode.c", 156, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n3 <= 31) ? 1 : 0), __extension__ ({ if (n3 <= 31) ; else __assert_fail ("n3 <= 31", "src/CyoEncode.c", 157, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n4 <= 31) ? 1 : 0), __extension__ ({ if (n4 <= 31) ; else __assert_fail ("n4 <= 31", "src/CyoEncode.c", 158, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n5 <= 31) ? 1 : 0), __extension__ ({ if (n5 <= 31) ; else __assert_fail ("n5 <= 31", "src/CyoEncode.c", 159, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n6 <= 31) ? 1 : 0), __extension__ ({ if (n6 <= 31) ; else __assert_fail ("n6 <= 31", "src/CyoEncode.c", 160, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n7 <= 31) ? 1 : 0), __extension__ ({ if (n7 <= 31) ; else __assert_fail ("n7 <= 31", "src/CyoEncode.c", 161, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n8 <= 31) ? 1 : 0), __extension__ ({ if (n8 <= 31) ; else __assert_fail ("n8 <= 31", "src/CyoEncode.c", 162, __extension__ __PRETTY_FUNCTION__); }));
            switch (dwBlockSize)
            {
            case 1: n3 = n4 = 32;
            case 2: n5 = 32;
            case 3: n6 = n7 = 32;
            case 4: n8 = 32;
            case 5:
                break;
            default:
                ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/CyoEncode.c", 175, __extension__ __PRETTY_FUNCTION__); }));
            }
            *dest++ = BASE32_TABLE[ n1 ];
            *dest++ = BASE32_TABLE[ n2 ];
            *dest++ = BASE32_TABLE[ n3 ];
            *dest++ = BASE32_TABLE[ n4 ];
            *dest++ = BASE32_TABLE[ n5 ];
            *dest++ = BASE32_TABLE[ n6 ];
            *dest++ = BASE32_TABLE[ n7 ];
            *dest++ = BASE32_TABLE[ n8 ];
            dwDestSize += BASE32_OUTPUT;
        }
        *dest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

variable_types:
dwBlockSize
unsigned long


decompiled_code:
unsigned __int64 __fastcall cyoBase64EncodeGetLength(__int64 a1)
{
return cyoBaseXXEncodeGetLength(a1, 3uLL, 4LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1)
{
return func0(a1, 3uLL, 4LL);
}

original_code:
size_t cyoBase64EncodeGetLength( size_t size )
{
    return cyoBaseXXEncodeGetLength( size, BASE64_INPUT, BASE64_OUTPUT );
}

canonical_original_code:
unsigned long cyoBase64EncodeGetLength(unsigned long size)
{
    return cyoBaseXXEncodeGetLength( size, BASE64_INPUT, BASE64_OUTPUT );
}


original_code:
size_t cyoBase64Encode( char* dest, const void* src, size_t size )
{
    if (dest && src)
    {
        unsigned char* pSrc = (unsigned char*)src;
        size_t dwSrcSize = size;
        size_t dwDestSize = 0;
        size_t dwBlockSize = 0;
        unsigned char n1, n2, n3, n4;
        while (dwSrcSize >= 1)
        {
            dwBlockSize = (dwSrcSize < BASE64_INPUT ? dwSrcSize : BASE64_INPUT);
            n1 = n2 = n3 = n4 = 0;
            switch (dwBlockSize)
            {
            case 3:
                n4 = (pSrc[ 2 ] & 0x3f);
                n3 = ((pSrc[ 2 ] & 0xc0) >> 6);
            case 2:
                n3 |= ((pSrc[ 1 ] & 0x0f) << 2);
                n2 = ((pSrc[ 1 ] & 0xf0) >> 4);
            case 1:
                n2 |= ((pSrc[ 0 ] & 0x03) << 4);
                n1 = ((pSrc[ 0 ] & 0xfc) >> 2);
                break;
            default:
                ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/CyoEncode.c", 247, __extension__ __PRETTY_FUNCTION__); }));
            }
            pSrc += dwBlockSize;
            dwSrcSize -= dwBlockSize;
            ((void) sizeof ((n1 <= 63) ? 1 : 0), __extension__ ({ if (n1 <= 63) ; else __assert_fail ("n1 <= 63", "src/CyoEncode.c", 253, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n2 <= 63) ? 1 : 0), __extension__ ({ if (n2 <= 63) ; else __assert_fail ("n2 <= 63", "src/CyoEncode.c", 254, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n3 <= 63) ? 1 : 0), __extension__ ({ if (n3 <= 63) ; else __assert_fail ("n3 <= 63", "src/CyoEncode.c", 255, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n4 <= 63) ? 1 : 0), __extension__ ({ if (n4 <= 63) ; else __assert_fail ("n4 <= 63", "src/CyoEncode.c", 256, __extension__ __PRETTY_FUNCTION__); }));
            switch (dwBlockSize)
            {
            case 1: n3 = 64;
            case 2: n4 = 64;
            case 3:
                break;
            default:
                ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/CyoEncode.c", 267, __extension__ __PRETTY_FUNCTION__); }));
            }
            *dest++ = BASE64_TABLE[ n1 ];
            *dest++ = BASE64_TABLE[ n2 ];
            *dest++ = BASE64_TABLE[ n3 ];
            *dest++ = BASE64_TABLE[ n4 ];
            dwDestSize += BASE64_OUTPUT;
        }
        *dest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}

canonical_original_code:
unsigned long cyoBase64Encode(char *dest, void *src, unsigned long size)
{
    if (dest && src)
    {
        unsigned char *pSrc = (unsigned char*)src;
        unsigned long dwSrcSize = size;
        unsigned long dwDestSize = 0;
        unsigned long dwBlockSize = 0;
        unsigned char n1; unsigned char n2; unsigned char n3; unsigned char n4;
        while (dwSrcSize >= 1)
        {
            dwBlockSize = (dwSrcSize < BASE64_INPUT ? dwSrcSize : BASE64_INPUT);
            n1 = n2 = n3 = n4 = 0;
            switch (dwBlockSize)
            {
            case 3:
                n4 = (pSrc[ 2 ] & 0x3f);
                n3 = ((pSrc[ 2 ] & 0xc0) >> 6);
            case 2:
                n3 |= ((pSrc[ 1 ] & 0x0f) << 2);
                n2 = ((pSrc[ 1 ] & 0xf0) >> 4);
            case 1:
                n2 |= ((pSrc[ 0 ] & 0x03) << 4);
                n1 = ((pSrc[ 0 ] & 0xfc) >> 2);
                break;
            default:
                ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/CyoEncode.c", 247, __extension__ __PRETTY_FUNCTION__); }));
            }
            pSrc += dwBlockSize;
            dwSrcSize -= dwBlockSize;
            ((void) sizeof ((n1 <= 63) ? 1 : 0), __extension__ ({ if (n1 <= 63) ; else __assert_fail ("n1 <= 63", "src/CyoEncode.c", 253, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n2 <= 63) ? 1 : 0), __extension__ ({ if (n2 <= 63) ; else __assert_fail ("n2 <= 63", "src/CyoEncode.c", 254, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n3 <= 63) ? 1 : 0), __extension__ ({ if (n3 <= 63) ; else __assert_fail ("n3 <= 63", "src/CyoEncode.c", 255, __extension__ __PRETTY_FUNCTION__); }));
            ((void) sizeof ((n4 <= 63) ? 1 : 0), __extension__ ({ if (n4 <= 63) ; else __assert_fail ("n4 <= 63", "src/CyoEncode.c", 256, __extension__ __PRETTY_FUNCTION__); }));
            switch (dwBlockSize)
            {
            case 1: n3 = 64;
            case 2: n4 = 64;
            case 3:
                break;
            default:
                ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/CyoEncode.c", 267, __extension__ __PRETTY_FUNCTION__); }));
            }
            *dest++ = BASE64_TABLE[ n1 ];
            *dest++ = BASE64_TABLE[ n2 ];
            *dest++ = BASE64_TABLE[ n3 ];
            *dest++ = BASE64_TABLE[ n4 ];
            dwDestSize += BASE64_OUTPUT;
        }
        *dest++ = '\x0';
        return dwDestSize;
    }
    else
        return 0;
}


ps

repo: pidh/toyCrypt

decompiled_code:
int __fastcall ps(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx

v1 = a1;
do
printf("%02x ", *v1++);
while ( v1 != a1 + 16 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx

v1 = a1;
do
printf("%02x ", *v1++);
while ( v1 != a1 + 16 );
return putchar(10);
}

original_code:
static void
ps(u1 *s)
{
 int i;
 for(i = 0;i < 16;i++)
  printf("%02x ", s[i]);
 printf("\n");
}

canonical_original_code:
static void ps(unsigned char *s)
{
 int i;
 for(i = 0;i < 16;i++)
  printf("%02x ", s[i]);
 printf("\n");
}

variable_types:
s
unsigned char *

variable_types: i int

return_type: void


check

decompiled_code:
int __fastcall check(void *s2, void *a2, __int64 a3, unsigned int a4, const char *a5)
{
__int64 v6; // rax
__int64 v7; // rbx
__int128 v9[3]; // [rsp+0h] [rbp-38h] BYREF

v9[0] = (__int128)_mm_loadu_si128((const __m128i *)s2);
v6 = AES_Init(a3, a4);
if ( !v6 )
return puts("no memory");
v7 = v6;
AES_Cipher(v6, v9);
ps((unsigned __int8 *)v9);
if ( memcmp(v9, a2, 0x10uLL) )
printf("%s-cipher is wrong\n", a5);
v9[0] = (__int128)_mm_loadu_si128((const __m128i *)a2);
AES_InvCipher(v7, v9);
ps((unsigned __int8 *)v9);
if ( memcmp(v9, s2, 0x10uLL) )
printf("%s-invcipher is wrong\n", a5);
return AES_Finish(v7);
}

canonical_decompiled_code:
int __fastcall func8(void *s2, void *a2, __int64 a3, unsigned int a4, const char *a5)
{
__int64 v6; // rax
__int64 v7; // rbx
__int128 v9[3]; // [rsp+0h] [rbp-38h] BYREF

v9[0] = (__int128)_mm_loadu_si128((const __m128i *)s2);
v6 = AES_Init(a3, a4);
if ( !v6 )
return puts("no memory");
v7 = v6;
func17(v6, v9);
func7((unsigned __int8 *)v9);
if ( memcmp(v9, a2, 0x10uLL) )
printf("%s-cipher is wrong\n", a5);
v9[0] = (__int128)_mm_loadu_si128((const __m128i *)a2);
func18(v7, v9);
func7((unsigned __int8 *)v9);
if ( memcmp(v9, s2, 0x10uLL) )
printf("%s-invcipher is wrong\n", a5);
return func19(v7);
}

original_code:
static void
check(u1 *plain, u1 *cipher, u1 *key, int Nk, char *title)
{
 void *ctx;
 u1 data[4 * 4];
 memcpy(data, plain, 4 * 4);
 ctx = AES_Init(key, Nk);
 if(ctx == ((void *)0)) {
  printf("no memory\n");
  return;
 }
 AES_Cipher(ctx, data);
 ps(data);
 if(memcmp(data, cipher, 4 * 4))
  printf("%s-cipher is wrong\n", title);
 memcpy(data, cipher, 4 * 4);
 AES_InvCipher(ctx, data);
 ps(data);
 if(memcmp(data, plain, 4 * 4))
  printf("%s-invcipher is wrong\n", title);
 AES_Finish(ctx);
}

canonical_original_code:
static void check(unsigned char *plain, unsigned char *cipher, unsigned char *key, int Nk, char *title)
{
 void *ctx;
 unsigned char data[-1];
 memcpy(data, plain, 4 * 4);
 ctx = AES_Init(key, Nk);
 if(ctx == ((void *)0)) {
  printf("no memory\n");
  return;
 }
 AES_Cipher(ctx, data);
 ps(data);
 if(memcmp(data, cipher, 4 * 4))
  printf("%s-cipher is wrong\n", title);
 memcpy(data, cipher, 4 * 4);
 AES_InvCipher(ctx, data);
 ps(data);
 if(memcmp(data, plain, 4 * 4))
  printf("%s-invcipher is wrong\n", title);
 AES_Finish(ctx);
}

variable_types:
plain
unsigned char *

variable_types:
cipher
unsigned char *

variable_types:
key
unsigned char *

variable_types: Nk int

variable_types:
title
char *

variable_types:
ctx
void *

variable_types:
data
unsigned char [-1]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
check(&plain128, &cipher128, (__int64)&key128, 4u, "AES-128");
check(&plain128_2, &cipher128_2, (__int64)&key128_2, 4u, "AES-128_2");
check(&plain192, &cipher192, (__int64)&key192, 6u, "AES-192");
check(&plain256, &cipher256, (__int64)&key256, 8u, "AES-256");
return 0;
}

variable_types: ac int

variable_types:
av
char *[]


original_code:
int
HMAC_SHA256_Calc(const u1 *text, int text_len, const u1 *key, int key_len, u1 *digest)
{
 u1 tmp[32];
 u1 pad[64];
 void *ctx;
 int i;
 if(key_len > 64) {
  ctx = SHA256_Init();
  if(ctx == ((void *)0))
   return(-1);
  SHA256_Calc(ctx, key, key_len);
  SHA256_Finish(ctx, tmp);
  key = tmp;
  key_len = sizeof(tmp);
 }
 memset(pad, 0x36, sizeof(pad));
 for(i = 0;i < key_len;i++)
  pad[i] ^= key[i];
 ctx = SHA256_Init();
 if(ctx == ((void *)0))
  return(-1);
 SHA256_Calc(ctx, pad, sizeof(pad));
 SHA256_Calc(ctx, text, text_len);
 SHA256_Finish(ctx, digest);
 for(i = 0;i < sizeof(pad);i++)
  pad[i] ^= 0x5c ^ 0x36;
 ctx = SHA256_Init();
 if(ctx == ((void *)0))
  return(-1);
 SHA256_Calc(ctx, pad, sizeof(pad));
 SHA256_Calc(ctx, digest, 32);
 SHA256_Finish(ctx, digest);
 return(0);
}

canonical_original_code:
int HMAC_SHA256_Calc(unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest)
{
 unsigned char tmp[32];
 unsigned char pad[64];
 void *ctx;
 int i;
 if(key_len > 64) {
  ctx = SHA256_Init();
  if(ctx == ((void *)0))
   return(-1);
  SHA256_Calc(ctx, key, key_len);
  SHA256_Finish(ctx, tmp);
  key = tmp;
  key_len = sizeof(tmp);
 }
 memset(pad, 0x36, sizeof(pad));
 for(i = 0;i < key_len;i++)
  pad[i] ^= key[i];
 ctx = SHA256_Init();
 if(ctx == ((void *)0))
  return(-1);
 SHA256_Calc(ctx, pad, sizeof(pad));
 SHA256_Calc(ctx, text, text_len);
 SHA256_Finish(ctx, digest);
 for(i = 0;i < sizeof(pad);i++)
  pad[i] ^= 0x5c ^ 0x36;
 ctx = SHA256_Init();
 if(ctx == ((void *)0))
  return(-1);
 SHA256_Calc(ctx, pad, sizeof(pad));
 SHA256_Calc(ctx, digest, 32);
 SHA256_Finish(ctx, digest);
 return(0);
}

variable_types:
text
unsigned char *

variable_types:
digest
unsigned char *

variable_types:
tmp
unsigned char [32]

variable_types:
pad
unsigned char [64]


Hash

variable_types:
M
unsigned char *

variable_types: struct SHA1_CTX { unsigned int H0; unsigned int W[80]; unsigned int lenM; unsigned int total; unsigned char M[-1]; } *

variable_types: t int

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int

variable_types:
e
unsigned int

variable_types:
T
unsigned int


original_code:
void *
SHA1_Init(void)
{
 SHA1_CTX *ctx;
 ctx = malloc(sizeof(SHA1_CTX));
 if(ctx == ((void *)0))
  return(((void *)0));
 ctx->H0 = 0x67452301;
 ctx->H1 = 0xefcdab89;
 ctx->H2 = 0x98badcfe;
 ctx->H3 = 0x10325476;
 ctx->H4 = 0xc3d2e1f0;
 ctx->lenM = 0;
 ctx->total = 0;
 return((void *)ctx);
}

canonical_original_code:
void *SHA1_Init()
{
 struct SHA1_CTX *ctx;
 ctx = malloc(sizeof(SHA1_CTX));
 if(ctx == ((void *)0))
  return(((void *)0));
 ctx->H0 = 0x67452301;
 ctx->H1 = 0xefcdab89;
 ctx->H2 = 0x98badcfe;
 ctx->H3 = 0x10325476;
 ctx->H4 = 0xc3d2e1f0;
 ctx->lenM = 0;
 ctx->total = 0;
 return((void *)ctx);
}

return_type: void *

user_defined_types: struct SHA1_CTX { unsigned int H0; unsigned int W[80]; unsigned int lenM; unsigned int total; unsigned char M[-1]; }


decompiled_code:
__int64 __fastcall SHA1_Calc(_DWORD *a1, unsigned int *a2, unsigned int a3)
{
unsigned int *v3; // rbx
unsigned int v4; // er13
__int64 result; // rax
int v6; // er14
size_t v7; // rbp
unsigned int *v8; // rbp

v3 = a2;
v4 = a3;
result = (unsigned int)a1[85];
a1[86] += a3;
if ( (_DWORD)result )
{
v6 = result + a3;
if ( (unsigned int)result + a3 <= 0x3F )
{
result = (__int64)memcpy((char *)a1 + (unsigned int)result + 348, a2, a3);
a1[85] += v4;
return result;
}
v7 = (unsigned int)(64 - result);
memcpy((char *)a1 + (unsigned int)result + 348, a2, v7);
result = Hash(a1, a1 + 87);
v3 = (unsigned int *)((char *)a2 + v7);
v4 = v6 - 64;
a1[85] = 0;
}
if ( v4 <= 0x3F )
{
v8 = v3;
}
else
{
v8 = &v3[16 * (unsigned __int64)(((v4 - 64) >> 6) + 1)];
do
{
result = Hash(a1, v3);
v3 += 16;
}
while ( v3 != v8 );
v4 &= 0x3Fu;
}
if ( v4 )
{
result = (__int64)memcpy(a1 + 87, v8, v4);
a1[85] = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, unsigned int *a2, unsigned int a3)
{
unsigned int *v3; // rbx
unsigned int v4; // er13
__int64 result; // rax
int v6; // er14
size_t v7; // rbp
unsigned int *v8; // rbp

v3 = a2;
v4 = a3;
result = (unsigned int)a1[85];
a1[86] += a3;
if ( (_DWORD)result )
{
v6 = result + a3;
if ( (unsigned int)result + a3 <= 0x3F )
{
result = (__int64)memcpy((char *)a1 + (unsigned int)result + 348, a2, a3);
a1[85] += v4;
return result;
}
v7 = (unsigned int)(64 - result);
memcpy((char *)a1 + (unsigned int)result + 348, a2, v7);
result = func8(a1, a1 + 87);
v3 = (unsigned int *)((char *)a2 + v7);
v4 = v6 - 64;
a1[85] = 0;
}
if ( v4 <= 0x3F )
{
v8 = v3;
}
else
{
v8 = &v3[16 * (unsigned __int64)(((v4 - 64) >> 6) + 1)];
do
{
result = func8(a1, v3);
v3 += 16;
}
while ( v3 != v8 );
v4 &= 0x3Fu;
}
if ( v4 )
{
result = (__int64)memcpy(a1 + 87, v8, v4);
a1[85] = v4;
}
return result;
}

original_code:
void
SHA1_Calc(void *_ctx, u1 *b, u4 len)
{
 SHA1_CTX *ctx = (SHA1_CTX *)_ctx;
 u4 lenM = ctx->lenM;
 ctx->total += len;
 if(lenM) {
  if(lenM + len < 64) {
   memcpy(ctx->M + lenM, b, len);
   ctx->lenM += len;
   return;
  }
  memcpy(ctx->M + lenM, b, 64 - lenM);
  Hash(ctx, ctx->M);
  b += 64 - lenM;
  len -= 64 - lenM;
  ctx->lenM = 0;
 }
 while(len >= 64) {
  Hash(ctx, b);
  b += 64;
  len -= 64;
 }
 if(len) {
  memcpy(ctx->M, b, len);
  ctx->lenM = len;
 }
}

canonical_original_code:
void SHA1_Calc(void *_ctx, unsigned char *b, unsigned int len)
{
 struct SHA1_CTX *ctx = (SHA1_CTX *)_ctx;
 unsigned int lenM = ctx->lenM;
 ctx->total += len;
 if(lenM) {
  if(lenM + len < 64) {
   memcpy(ctx->M + lenM, b, len);
   ctx->lenM += len;
   return;
  }
  memcpy(ctx->M + lenM, b, 64 - lenM);
  Hash(ctx, ctx->M);
  b += 64 - lenM;
  len -= 64 - lenM;
  ctx->lenM = 0;
 }
 while(len >= 64) {
  Hash(ctx, b);
  b += 64;
  len -= 64;
 }
 if(len) {
  memcpy(ctx->M, b, len);
  ctx->lenM = len;
 }
}

variable_types:
b
unsigned char *

variable_types:
len
unsigned int

variable_types:
lenM
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rbx
float v6; // xmm0_4
float v8; // [rsp+Ch] [rbp-1Ch]

initRand(argc, argv, envp);
v3 = 1000000LL;
v4 = 0LL;
do
{
v4 += (int)getRand(10LL);
--v3;
}
while ( v3 );
printf("getRand() Average %d\n", v4 / 1000000);
v5 = 1000000LL;
v8 = 0.0;
do
{
v6 = getSRand() + v8;
v8 = v6;
--v5;
}
while ( v5 );
printf("getSRand() Average %f\n", (float)(v6 / 1000000.0));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rbx
float v6; // xmm0_4
float v8; // [rsp+Ch] [rbp-1Ch]

func7(argc, argv, envp);
v3 = 1000000LL;
v4 = 0LL;
do
{
v4 += (int)func9(10LL);
--v3;
}
while ( v3 );
printf("getRand() Average %d\n", v4 / 1000000);
v5 = 1000000LL;
v8 = 0.0;
do
{
v6 = func8() + v8;
v8 = v6;
--v5;
}
while ( v5 );
printf("getSRand() Average %f\n", (float)(v6 / 1000000.0));
return 0;
}

original_code:
int main() {
  long i;
  long isum;
  float fsum;
  initRand();
  isum = 0L;
  for (i = 0; i < 1000000L; i++) {
    isum += getRand(10);
  }
  printf("getRand() Average %d\n", (int) (isum / 1000000L));
  fsum = 0.0;
  for (i = 0; i < 1000000L; i++) {
    fsum += getSRand();
  }
  printf("getSRand() Average %f\n", (fsum / (float) 1000000L));
  return 0;
}

variable_types: i long

variable_types: isum long

variable_types: fsum float


initRand

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

v0 = time(0LL);
srand(v0);
}

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

v0 = time(0LL);
srand(v0);
}

original_code:
void initRand() {
  time_t seed;
  seed = time(((void *)0));
  srand(seed);
  return;
}

canonical_original_code:
void initRand() {
  long seed;
  seed = time(((void *)0));
  srand(seed);
  return;
}

variable_types: seed long


getSRand

decompiled_code:
float getSRand()
{
return (float)rand() * 4.6566129e-10;
}

canonical_decompiled_code:
float func8()
{
return (float)rand() * 4.6566129e-10;
}

original_code:
float getSRand() {
  float randvalue;
  randvalue = ((float) rand() / (float) 2147483647);
  return randvalue;
}

variable_types: randvalue float

return_type: float


getRand

decompiled_code:
__int64 __fastcall getRand(int a1)
{
return (unsigned int)(int)((float)((float)a1 * (float)rand()) * 4.656612873077393e-10);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return (unsigned int)(int)((float)((float)a1 * (float)rand()) * 4.656612873077393e-10);
}

original_code:
int getRand(int max) {
  int randvalue;
  randvalue = (int) ((float) max * rand() / (2147483647 + 1.0));
  return randvalue;
}

variable_types: max int

variable_types: randvalue int


getSRand

canonical_decompiled_code:
float func6()
{
return (float)rand() * 4.6566129e-10;
}

canonical_original_code:
float getSRand() {
  float randvalue;
  randvalue = ((float) rand() / (float) 2147483647);
  return randvalue;
}


getRand

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)(int)((float)((float)a1 * (float)rand()) * 4.656612873077393e-10);
}

canonical_original_code:
int getRand(int max) {
  int randvalue;
  randvalue = (int) ((float) max * rand() / (2147483647 + 1.0));
  return randvalue;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1("--- Hello World 1---", argv, envp);
fflush(stdout);
func2("--- Hello World 2---");
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8("--- Hello World 1---", argv, envp);
fflush(stdout);
func7("--- Hello World 2---");
return 1;
}

canonical_original_code:
int main() {
  long i;
  long isum;
  float fsum;
  initRand();
  isum = 0L;
  for (i = 0; i < 1000000L; i++) {
    isum += getRand(10);
  }
  printf("getRand() Average %d\n", (int) (isum / 1000000L));
  fsum = 0.0;
  for (i = 0; i < 1000000L; i++) {
    fsum += getSRand();
  }
  printf("getSRand() Average %f\n", (fsum / (float) 1000000L));
  return 0;
}


expconv

repo: piefel/lgrind

original_code:
static void expconv(void)
{
   register char *cs;
   register char c;
   register char *acs;
   register int temp;
   acs = ((void *)0);
   cs = ((void *)0);
   while (*ure != '\0') {
   switch (c = *ure++) {
   case '\\':
  switch (c = *ure++) {
  default:
  if (cs == ((void *)0) || (*cs & 2) == 0) {
     cs = ccre;
     *cs = 2;
     (*(cs+1)) = 1;
     ccre += 2;
  } else
     (*(cs+1))++;
  *ccre++ = c;
  break;
  case 'a':
  case 'd':
  case 'e':
  case 'p':
  if (acs != ((void *)0) && acs != cs) {
     do {
    temp = (*(acs+2));
    (*(acs+2)) = ccre - acs;
    acs -= temp;
     } while (temp != 0);
     acs = ((void *)0);
  }
  cs = ccre;
  *cs = 4;
  (*(cs+1)) = c;
     ccre = (cs+2);
     break;
  }
  break;
      case '^':
      case '$':
  if (acs != ((void *)0) && acs != cs) {
     do {
        temp = (*(acs+2));
        (*(acs+2)) = ccre - acs;
        acs -= temp;
     } while (temp != 0);
     acs = ((void *)0);
  }
  cs = ccre;
  *cs = 4;
  (*(cs+1)) = c;
  ccre = (cs+2);
  break;
      case '?':
  if (cs)
  *cs = *cs | 1;
  break;
      case '(':
  if (acs != ((void *)0) && acs != cs) {
     do {
        temp = (*(acs+2));
        (*(acs+2)) = ccre - acs;
        acs -= temp;
     } while (temp != 0);
     acs = ((void *)0);
  }
  cs = ccre;
  *cs = 16;
  (*(cs+1)) = '(';
  ccre = (cs+3);
  expconv();
  (*(cs+2)) = ccre - cs;
  break;
      case ')':
  if (acs != ((void *)0)) {
     do {
        temp = (*(acs+2));
        (*(acs+2)) = ccre - acs;
        acs -= temp;
     } while (temp != 0);
     acs = ((void *)0);
  }
  cs = ccre;
  *cs = 4;
  (*(cs+1)) = c;
  ccre = (cs+2);
  return;
      case '|':
  if (acs != ((void *)0) && acs != cs)
     (*(ccre+2)) = ccre - acs;
  else
     (*(ccre+2)) = 0;
  *cs |= 8;
  cs = ccre;
  *cs = 16;
  (*(cs+1)) = '|';
  ccre = (cs+3);
  acs = cs;
  break;
      default:
  if (cs == ((void *)0) || (*cs & 2) == 0) {
     cs = ccre;
     *cs = 2;
     (*(cs+1)) = 1;
     ccre = (cs+2);
  } else
     (*(cs+1))++;
  *ccre++ = c;
  break;
      }
   }
   if (acs != ((void *)0)) {
      do {
  temp = (*(acs+2));
  (*(acs+2)) = ccre - acs;
  acs -= temp;
      } while (temp != 0);
      acs = ((void *)0);
   }
   return;
}

canonical_original_code:
static void expconv()
{
   register char *cs;
   register char c;
   register char *acs;
   register int temp;
   acs = ((void *)0);
   cs = ((void *)0);
   while (*ure != '\0') {
   switch (c = *ure++) {
   case '\\':
  switch (c = *ure++) {
  default:
  if (cs == ((void *)0) || (*cs & 2) == 0) {
     cs = ccre;
     *cs = 2;
     (*(cs+1)) = 1;
     ccre += 2;
  } else
     (*(cs+1))++;
  *ccre++ = c;
  break;
  case 'a':
  case 'd':
  case 'e':
  case 'p':
  if (acs != ((void *)0) && acs != cs) {
     do {
    temp = (*(acs+2));
    (*(acs+2)) = ccre - acs;
    acs -= temp;
     } while (temp != 0);
     acs = ((void *)0);
  }
  cs = ccre;
  *cs = 4;
  (*(cs+1)) = c;
     ccre = (cs+2);
     break;
  }
  break;
      case '^':
      case '$':
  if (acs != ((void *)0) && acs != cs) {
     do {
        temp = (*(acs+2));
        (*(acs+2)) = ccre - acs;
        acs -= temp;
     } while (temp != 0);
     acs = ((void *)0);
  }
  cs = ccre;
  *cs = 4;
  (*(cs+1)) = c;
  ccre = (cs+2);
  break;
      case '?':
  if (cs)
  *cs = *cs | 1;
  break;
      case '(':
  if (acs != ((void *)0) && acs != cs) {
     do {
        temp = (*(acs+2));
        (*(acs+2)) = ccre - acs;
        acs -= temp;
     } while (temp != 0);
     acs = ((void *)0);
  }
  cs = ccre;
  *cs = 16;
  (*(cs+1)) = '(';
  ccre = (cs+3);
  expconv();
  (*(cs+2)) = ccre - cs;
  break;
      case ')':
  if (acs != ((void *)0)) {
     do {
        temp = (*(acs+2));
        (*(acs+2)) = ccre - acs;
        acs -= temp;
     } while (temp != 0);
     acs = ((void *)0);
  }
  cs = ccre;
  *cs = 4;
  (*(cs+1)) = c;
  ccre = (cs+2);
  return;
      case '|':
  if (acs != ((void *)0) && acs != cs)
     (*(ccre+2)) = ccre - acs;
  else
     (*(ccre+2)) = 0;
  *cs |= 8;
  cs = ccre;
  *cs = 16;
  (*(cs+1)) = '|';
  ccre = (cs+3);
  acs = cs;
  break;
      default:
  if (cs == ((void *)0) || (*cs & 2) == 0) {
     cs = ccre;
     *cs = 2;
     (*(cs+1)) = 1;
     ccre = (cs+2);
  } else
     (*(cs+1))++;
  *ccre++ = c;
  break;
      }
   }
   if (acs != ((void *)0)) {
      do {
  temp = (*(acs+2));
  (*(acs+2)) = ccre - acs;
  acs -= temp;
      } while (temp != 0);
      acs = ((void *)0);
   }
   return;
}

variable_types:
cs
char *

variable_types: c char

variable_types:
acs
char *

variable_types: temp int


decompiled_code:
__int64 __fastcall lc_strncmp(char *a1, char *a2, __int64 a3)
{
char *v3; // rbx
const unsigned __int16 *v6; // r15
char *v7; // r14
int v8; // er13
__int64 v9; // r12
__int32_t v10; // eax

if ( !a3 )
return 0LL;
v3 = a1;
v6 = *_ctype_b_loc();
v7 = &a1[a3];
while ( 1 )
{
v8 = *a2;
v9 = *v3;
v10 = *v3;
if ( (v6[v9] & 0x100) != 0 )
v10 = (*_ctype_tolower_loc())[v9];
if ( v8 != v10 )
break;
++a2;
if ( v7 == ++v3 )
return 0LL;
}
return 1LL;
}

original_code:
int lc_strncmp(register const char *s1, register const char *s2, register size_t len)
{
   while (len-- > 0)
      if (*s2 - (((*__ctype_b_loc ())[(int) (((*s1)))] & (unsigned short int) _ISupper) ? tolower((*s1)) : (*s1)))
  return 1;
      else
  s2++, s1++;
   return 0;
}

canonical_original_code:
int lc_strncmp(char *s1, char *s2, unsigned long len)
{
   while (len-- > 0)
      if (*s2 - (((*__ctype_b_loc ())[(int) (((*s1)))] & (unsigned short) _ISupper) ? tolower((*s1)) : (*s1)))
  return 1;
      else
  s2++, s1++;
   return 0;
}

variable_types:
len
unsigned long


expmatch

original_code:
char *expmatch(
   register char *s,
   register char *re,
   char **strtptr,
   char *mstring)
{
   register char *cs;
   register char *ptr, *s1;
   register char c;
   boolean matched;
   if (strtptr)
      *strtptr = '\0';
   if (re == ((void *)0))
      return ((void *)0);
   cs = re;
   matched = 0;
   while (*cs) {
      switch (*cs & (16 | 2 | 4)) {
      case 2:
  matched = !((*re_strncmp)(s, (cs+2), (*(cs+1))));
  if (matched) {
     s += (*(cs+1));
     cs = (cs+2+*(cs+1));
  } else if (*cs & 8) {
     cs = (cs+2+*(cs+1));
  } else if (*cs & 1) {
     cs = (cs+2+*(cs+1));
     matched = 1;
  } else {
     return ((void *)0);
  }
  break;
      case 16:
  switch ((*(cs+1))) {
  case '|':
     if (matched)
        cs = (cs+*(cs+2));
     else
        cs = (cs+3);
     break;
  case '(':
     ptr = expmatch(s, (cs+3), strtptr, mstring);
     if (ptr != ((void *)0)) {
        matched = 1;
        s = ptr;
     } else if (*cs & 8) {
        matched = 0;
     } else if (*cs & 1) {
        matched = 1;
     } else {
        return ((void *)0);
     }
     cs = (cs+*(cs+2));
     break;
  }
  break;
      case 4:
  switch ((*(cs+1))) {
  case 'p':
     s1 = s;
     do {
        ptr = expmatch(s1, (cs+2), strtptr, mstring);
        if (ptr != ((void *)0) && s1 != s) {
    if (mstring) {
       strncpy(mstring, s, (size_t)(s1 - s));
       mstring[(int)(s1 - s)] = '\0';
    }
    return ptr;
        } else if (ptr != ((void *)0) && (*cs & 1)) {
    return ptr;
        } else if (ptr != ((void *)0)) {
    return ((void *)0);
        }
        if (!((*__ctype_b_loc ())[(int) ((*s1))] & (unsigned short int) _ISalnum) && !strchr(l_id, *s1))
    return ((void *)0);
        if (*s1 == '\\')
    _escaped = _escaped ? 0 : 1;
        else
    _escaped = 0;
     } while (*s1++);
     return ((void *)0);
  case 'a':
     s1 = s;
     do {
        if(*(ptr = (cs+2)) == 2) {
    c = *(ptr+2);
    while(*s1 && *s1 != c)
       s1++;
    if (*s1 == 0)
       return ((void *)0);
    if ((ptr+2+*(ptr+1)) == 0 && (s1 != s || *cs & 1)) {
       if (strtptr)
   *strtptr = s1;
       cs = ptr;
       s = s1;
       break;
    }
        }
        ptr = expmatch(s1, (cs+2), strtptr, mstring);
        if (ptr != ((void *)0) && (s1 != s || *cs & 1)) {
    if (strtptr)
       *strtptr = s1;
    return ptr;
        } else if (ptr != ((void *)0)) {
    return ((void *)0);
        }
        if (*s1 == '\\')
    _escaped = _escaped ? 0 : 1;
        else
    _escaped = 0;
     } while (*s1++);
     return ((void *)0);
  case 'e':
     if (_escaped)
        return ((void *)0);
     cs = (cs+2);
     break;
  case 'd':
     ptr = s;
     while (*s == ' ' || *s == '\t')
        s++;
     if (s != ptr || s == _sstart) {
        matched = 1;
        cs = (cs+2);
     } else if (*s == '\n' || *s == '\0') {
        matched = 1;
        cs = (cs+2);
     } else if (*cs & 8) {
        matched = 0;
        cs = (cs+2);
     } else if (*cs & 1) {
        matched = 1;
        cs = (cs+2);
     } else
        return ((void *)0);
     break;
  case '$':
     if (*s == '\0' || *s == '\n') {
        matched = 1;
        cs = (cs+2);
     } else if (*cs & 8) {
        matched = 0;
        cs = (cs+2);
     } else if (*cs & 1) {
        matched = 1;
        cs = (cs+2);
     } else
        return ((void *)0);
     break;
  case '^':
     if (s == _sstart) {
        matched = 1;
        cs = (cs+2);
     } else if (*cs & 8) {
        matched = 0;
        cs = (cs+2);
     } else if (*cs & 1) {
        matched = 1;
        cs = (cs+2);
     } else
        return ((void *)0);
     break;
  case ')':
     return s;
  }
  break;
      }
   }
   return s;
}

canonical_original_code:
char *expmatch(char *s, char *re, char **strtptr, char *mstring)
{
   register char *cs;
   register char *ptr; register char *s1;
   register char c;
   int matched;
   if (strtptr)
      *strtptr = '\0';
   if (re == ((void *)0))
      return ((void *)0);
   cs = re;
   matched = 0;
   while (*cs) {
      switch (*cs & (16 | 2 | 4)) {
      case 2:
  matched = !((*re_strncmp)(s, (cs+2), (*(cs+1))));
  if (matched) {
     s += (*(cs+1));
     cs = (cs+2+*(cs+1));
  } else if (*cs & 8) {
     cs = (cs+2+*(cs+1));
  } else if (*cs & 1) {
     cs = (cs+2+*(cs+1));
     matched = 1;
  } else {
     return ((void *)0);
  }
  break;
      case 16:
  switch ((*(cs+1))) {
  case '|':
     if (matched)
        cs = (cs+*(cs+2));
     else
        cs = (cs+3);
     break;
  case '(':
     ptr = expmatch(s, (cs+3), strtptr, mstring);
     if (ptr != ((void *)0)) {
        matched = 1;
        s = ptr;
     } else if (*cs & 8) {
        matched = 0;
     } else if (*cs & 1) {
        matched = 1;
     } else {
        return ((void *)0);
     }
     cs = (cs+*(cs+2));
     break;
  }
  break;
      case 4:
  switch ((*(cs+1))) {
  case 'p':
     s1 = s;
     do {
        ptr = expmatch(s1, (cs+2), strtptr, mstring);
        if (ptr != ((void *)0) && s1 != s) {
    if (mstring) {
       strncpy(mstring, s, (unsigned long)(s1 - s));
       mstring[(int)(s1 - s)] = '\0';
    }
    return ptr;
        } else if (ptr != ((void *)0) && (*cs & 1)) {
    return ptr;
        } else if (ptr != ((void *)0)) {
    return ((void *)0);
        }
        if (!((*__ctype_b_loc ())[(int) ((*s1))] & (unsigned short) _ISalnum) && !strchr(l_id, *s1))
    return ((void *)0);
        if (*s1 == '\\')
    _escaped = _escaped ? 0 : 1;
        else
    _escaped = 0;
     } while (*s1++);
     return ((void *)0);
  case 'a':
     s1 = s;
     do {
        if(*(ptr = (cs+2)) == 2) {
    c = *(ptr+2);
    while(*s1 && *s1 != c)
       s1++;
    if (*s1 == 0)
       return ((void *)0);
    if ((ptr+2+*(ptr+1)) == 0 && (s1 != s || *cs & 1)) {
       if (strtptr)
   *strtptr = s1;
       cs = ptr;
       s = s1;
       break;
    }
        }
        ptr = expmatch(s1, (cs+2), strtptr, mstring);
        if (ptr != ((void *)0) && (s1 != s || *cs & 1)) {
    if (strtptr)
       *strtptr = s1;
    return ptr;
        } else if (ptr != ((void *)0)) {
    return ((void *)0);
        }
        if (*s1 == '\\')
    _escaped = _escaped ? 0 : 1;
        else
    _escaped = 0;
     } while (*s1++);
     return ((void *)0);
  case 'e':
     if (_escaped)
        return ((void *)0);
     cs = (cs+2);
     break;
  case 'd':
     ptr = s;
     while (*s == ' ' || *s == '\t')
        s++;
     if (s != ptr || s == _sstart) {
        matched = 1;
        cs = (cs+2);
     } else if (*s == '\n' || *s == '\0') {
        matched = 1;
        cs = (cs+2);
     } else if (*cs & 8) {
        matched = 0;
        cs = (cs+2);
     } else if (*cs & 1) {
        matched = 1;
        cs = (cs+2);
     } else
        return ((void *)0);
     break;
  case '$':
     if (*s == '\0' || *s == '\n') {
        matched = 1;
        cs = (cs+2);
     } else if (*cs & 8) {
        matched = 0;
        cs = (cs+2);
     } else if (*cs & 1) {
        matched = 1;
        cs = (cs+2);
     } else
        return ((void *)0);
     break;
  case '^':
     if (s == _sstart) {
        matched = 1;
        cs = (cs+2);
     } else if (*cs & 8) {
        matched = 0;
        cs = (cs+2);
     } else if (*cs & 1) {
        matched = 1;
        cs = (cs+2);
     } else
        return ((void *)0);
     break;
  case ')':
     return s;
  }
  break;
      }
   }
   return s;
}

variable_types:
s
char *

variable_types:
re
char *

variable_types:
strtptr
char **

variable_types:
mstring
char *

variable_types:
ptr
char *

variable_types: matched int


tnamatch

decompiled_code:
__int64 __fastcall tnamatch(_BYTE *a1)
{
char *v1; // rbx
__int64 result; // rax
char v4; // bp
_BYTE *v5; // rdi
char v6; // dl
char v7; // al
char v8; // al
const __int32_t *v9; // rcx

v1 = tbuf;
result = 0LL;
if ( *tbuf != 35 )
{
v4 = *a1;
while ( 1 )
{
if ( !v4 )
goto LABEL_4;
v9 = *_ctype_toupper_loc();
v5 = a1;
v6 = v4;
while ( v9[v6] == v9[*v1] )
{
++v1;
v6 = *++v5;
if ( !*v5 )
goto LABEL_4;
}
if ( v6 )
{
v8 = *v1;
if ( v8 == 58 || v8 == 0 || v8 == 124 )
goto LABEL_8;
}
else
{
LABEL_4:
v7 = *v1;
if ( v7 == 58 || v7 == 124 || !v7 )
return 1LL;
}
do
v8 = *++v1;
while ( v8 != 58 && v8 != 0 && v8 != 124 );
LABEL_8:
if ( !v8 || v8 == 58 )
return 0LL;
++v1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
char *v1; // rbx
__int64 result; // rax
char v4; // bp
_BYTE *v5; // rdi
char v6; // dl
char v7; // al
char v8; // al
const __int32_t *v9; // rcx

v1 = tbuf;
result = 0LL;
if ( *tbuf != 35 )
{
v4 = *a1;
while ( 1 )
{
if ( !v4 )
goto LABEL_4;
v9 = *_ctype_toupper_loc();
v5 = a1;
v6 = v4;
while ( v9[v6] == v9[*v1] )
{
++v1;
v6 = *++v5;
if ( !*v5 )
goto LABEL_4;
}
if ( v6 )
{
v8 = *v1;
if ( v8 == 58 || v8 == 0 || v8 == 124 )
goto LABEL_8;
}
else
{
LABEL_4:
v7 = *v1;
if ( v7 == 58 || v7 == 124 || !v7 )
return 1LL;
}
do
v8 = *++v1;
while ( v8 != 58 && v8 != 0 && v8 != 124 );
LABEL_8:
if ( !v8 || v8 == 58 )
return 0LL;
++v1;
}
}
return result;
}

original_code:
static int tnamatch(char *np)
{
   register char *Np, *Bp;
   Bp = tbuf;
   if (*Bp == '#')
      return 0;
   for (;;) {
      for (Np = np; *Np && toupper(*Bp) == toupper(*Np); Bp++, Np++)
   continue;
      if (*Np == '\0' && (*Bp == '|' || *Bp == ':' || *Bp == '\0'))
   return 1;
      while (*Bp != '\0' && *Bp != ':' && *Bp != '|')
   Bp++;
      if (*Bp == '\0' || *Bp == ':')
   return 0;
      Bp++;
   }
}

canonical_original_code:
static int tnamatch(char *np)
{
   register char *Np; register char *Bp;
   Bp = tbuf;
   if (*Bp == '#')
      return 0;
   for (;;) {
      for (Np = np; *Np && toupper(*Bp) == toupper(*Np); Bp++, Np++)
   continue;
      if (*Np == '\0' && (*Bp == '|' || *Bp == ':' || *Bp == '\0'))
   return 1;
      while (*Bp != '\0' && *Bp != ':' && *Bp != '|')
   Bp++;
      if (*Bp == '\0' || *Bp == ':')
   return 0;
      Bp++;
   }
}

variable_types:
np
char *

variable_types:
Np
char *

variable_types:
Bp
char *


tgetnum

decompiled_code:
__int64 __fastcall tgetnum(_BYTE *a1)
{
char *v2; // rdi
char *v3; // rax
char v4; // dl
char v5; // dl
char *v6; // rbx
int v7; // ebp
const unsigned __int16 *v8; // rsi
unsigned int i; // edx
char v10; // al

v2 = tbuf;
do
{
while ( 1 )
{
v3 = tskip(v2);
if ( !*v3 )
return (unsigned int)-1;
v2 = v3 + 1;
if ( *v3 == *a1 )
{
v4 = v3[1];
if ( v4 )
{
v2 = v3 + 2;
if ( v4 == a1[1] )
break;
}
}
}
v5 = v3[2];
if ( v5 == 64 )
return (unsigned int)-1;
}
while ( v5 != 35 );
v6 = v3 + 3;
v7 = 2 * (v3[3] != 48) + 8;
v8 = *_ctype_b_loc();
for ( i = 0; ; i = v7 * i + v10 - 48 )
{
v10 = *v6;
if ( (v8[*v6] & 0x800) == 0 )
break;
++v6;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
char *v2; // rdi
char *v3; // rax
char v4; // dl
char v5; // dl
char *v6; // rbx
int v7; // ebp
const unsigned __int16 *v8; // rsi
unsigned int i; // edx
char v10; // al

v2 = tbuf;
do
{
while ( 1 )
{
v3 = tskip(v2);
if ( !*v3 )
return (unsigned int)-1;
v2 = v3 + 1;
if ( *v3 == *a1 )
{
v4 = v3[1];
if ( v4 )
{
v2 = v3 + 2;
if ( v4 == a1[1] )
break;
}
}
}
v5 = v3[2];
if ( v5 == 64 )
return (unsigned int)-1;
}
while ( v5 != 35 );
v6 = v3 + 3;
v7 = 2 * (v3[3] != 48) + 8;
v8 = *_ctype_b_loc();
for ( i = 0; ; i = v7 * i + v10 - 48 )
{
v10 = *v6;
if ( (v8[*v6] & 0x800) == 0 )
break;
++v6;
}
return i;
}

original_code:
int tgetnum(char *id)
{
   register int i, base;
   register char *bp = tbuf;
   for (;;) {
      bp = tskip(bp);
      if (*bp == '\0')
  return -1;
      if (*bp++ != id[0] || *bp == '\0' || *bp++ != id[1])
  continue;
      if (*bp == '@')
  return -1;
      if (*bp != '#')
  continue;
      bp++;
      base = 10;
      if (*bp == '0')
  base = 8;
      i = 0;
      while (((*__ctype_b_loc ())[(int) ((*bp))] & (unsigned short int) _ISdigit))
  i *= base, i += *bp++ - '0';
      return i;
   }
}

canonical_original_code:
int tgetnum(char *id)
{
   register int i; register int base;
   register char *bp = tbuf;
   for (;;) {
      bp = tskip(bp);
      if (*bp == '\0')
  return -1;
      if (*bp++ != id[0] || *bp == '\0' || *bp++ != id[1])
  continue;
      if (*bp == '@')
  return -1;
      if (*bp != '#')
  continue;
      bp++;
      base = 10;
      if (*bp == '0')
  base = 8;
      i = 0;
      while (((*__ctype_b_loc ())[(int) ((*bp))] & (unsigned short) _ISdigit))
  i *= base, i += *bp++ - '0';
      return i;
   }
}

variable_types:
id
char *

variable_types: i int

variable_types: base int

variable_types:
bp
char *


tgetflag

decompiled_code:
__int64 __fastcall tgetflag(_BYTE *a1)
{
char *v2; // rdi
_BYTE *v3; // rax
char v4; // dl
char v5; // al

v2 = tbuf;
while ( 1 )
{
while ( 1 )
{
v3 = tskip(v2);
if ( !*v3 )
return 0LL;
v2 = v3 + 1;
if ( *v3 == *a1 )
{
v4 = v3[1];
if ( v4 )
{
v2 = v3 + 2;
if ( v4 == a1[1] )
break;
}
}
}
v5 = v3[2];
if ( !v5 || v5 == 58 )
break;
if ( v5 == 64 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
char *v2; // rdi
_BYTE *v3; // rax
char v4; // dl
char v5; // al

v2 = tbuf;
while ( 1 )
{
while ( 1 )
{
v3 = tskip(v2);
if ( !*v3 )
return 0LL;
v2 = v3 + 1;
if ( *v3 == *a1 )
{
v4 = v3[1];
if ( v4 )
{
v2 = v3 + 2;
if ( v4 == a1[1] )
break;
}
}
}
v5 = v3[2];
if ( !v5 || v5 == 58 )
break;
if ( v5 == 64 )
return 0LL;
}
return 1LL;
}

original_code:
int tgetflag(char *id)
{
   register char *bp = tbuf;
   for (;;) {
      bp = tskip(bp);
      if (!*bp)
  return 0;
      if (*bp++ == id[0] && *bp != 0 && *bp++ == id[1]) {
  if (!*bp || *bp == ':')
     return 1;
  else if (*bp == '@')
     return 0;
      }
   }
}


tnchktc

decompiled_code:
__int64 tnchktc()
{
char *v0; // rbx
size_t v1; // rax
char *v2; // rbp
unsigned int v3; // er12
char *i; // rax
char *v6; // r13
char v7[8192]; // [rsp+0h] [rbp-2038h] BYREF
char dest[56]; // [rsp+2000h] [rbp-38h] BYREF

v0 = tbuf;
v1 = (size_t)&v0[strlen(tbuf) - 2];
while ( 1 )
{
v2 = (char *)v1--;
if ( *(_BYTE *)v1 == 58 )
break;
if ( (unsigned __int64)v0 > v1 )
return 0;
}
v3 = 1;
if ( *(_BYTE *)(v1 + 1) == 116 && *(_BYTE *)(v1 + 2) == 99 )
{
strcpy(dest, (const char *)(v1 + 4));
for ( i = dest; *i != 58; ++i )
;
*i = 0;
if ( ++hopcount > 32 )
{
fwrite("Infinite tc= loop\n", 1uLL, 0x12uLL, stderr);
v3 = 0;
}
else
{
v3 = tgetent(v7, dest, (const char *)filename);
if ( v3 == 1 )
{
if ( v7[0] == 58 )
{
v6 = v7;
}
else
{
v6 = v7;
do
++v6;
while ( *v6 != 58 );
}
if ( (int)(strlen(v6) + (_DWORD)v2 - (_DWORD)v0) > 0x2000 )
{
fwrite("LGrind entry too long\n", 1uLL, 0x16uLL, stderr);
v6[0x2000 - ((int)v2 - (int)tbuf)] = 0;
}
strcpy(v2, v6 + 1);
tbuf = v0;
}
else
{
v3 = 0;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 func4()
{
char *v0; // rbx
size_t v1; // rax
char *v2; // rbp
unsigned int v3; // er12
char *i; // rax
char *v6; // r13
char v7[8192]; // [rsp+0h] [rbp-2038h] BYREF
char dest[56]; // [rsp+2000h] [rbp-38h] BYREF

v0 = tbuf;
v1 = (size_t)&v0[strlen(tbuf) - 2];
while ( 1 )
{
v2 = (char *)v1--;
if ( *(_BYTE *)v1 == 58 )
break;
if ( (unsigned __int64)v0 > v1 )
return 0;
}
v3 = 1;
if ( *(_BYTE *)(v1 + 1) == 116 && *(_BYTE *)(v1 + 2) == 99 )
{
strcpy(dest, (const char *)(v1 + 4));
for ( i = dest; *i != 58; ++i )
;
*i = 0;
if ( ++hopcount > 32 )
{
fwrite("Infinite tc= loop\n", 1uLL, 0x12uLL, stderr);
v3 = 0;
}
else
{
v3 = func3(v7, dest, (const char *)filename);
if ( v3 == 1 )
{
if ( v7[0] == 58 )
{
v6 = v7;
}
else
{
v6 = v7;
do
++v6;
while ( *v6 != 58 );
}
if ( (int)(strlen(v6) + (_DWORD)v2 - (_DWORD)v0) > 0x2000 )
{
fwrite("LGrind entry too long\n", 1uLL, 0x16uLL, stderr);
v6[0x2000 - ((int)v2 - (int)tbuf)] = 0;
}
strcpy(v2, v6 + 1);
tbuf = v0;
}
else
{
v3 = 0;
}
}
}
return v3;
}

original_code:
static int tnchktc(void)
{
   register char *p, *q;
   char tcname[16];
   char tcbuf[8192];
   char *holdtbuf = tbuf;
   int l;
   p = tbuf + strlen(tbuf) - 2;
   while (*--p != ':')
      if (p < tbuf) {
  return 0;
      }
   p++;
   if (p[0] != 't' || p[1] != 'c')
      return 1;
   strcpy(tcname,p+3);
   q = tcname;
   while (q && *q != ':')
      q++;
   *q = '\0';
   if (++hopcount > 32) {
      fprintf(stderr, "Infinite tc= loop\n");
      return 0;
   }
   if (tgetent(tcbuf, tcname, filename) != 1)
      return 0;
   for (q = tcbuf; *q != ':'; q++)
      ;
   l = (int)(p - holdtbuf + strlen(q));
   if (l > 8192) {
      fprintf(stderr, "LGrind entry too long\n");
      q[(int)(8192 - (p-tbuf))] = '\0';
   }
   strcpy(p, q+1);
   tbuf = holdtbuf;
   return 1;
}

canonical_original_code:
static int tnchktc()
{
   register char *p; register char *q;
   char tcname[16];
   char tcbuf[8192];
   char *holdtbuf = tbuf;
   int l;
   p = tbuf + strlen(tbuf) - 2;
   while (*--p != ':')
      if (p < tbuf) {
  return 0;
      }
   p++;
   if (p[0] != 't' || p[1] != 'c')
      return 1;
   strcpy(tcname,p+3);
   q = tcname;
   while (q && *q != ':')
      q++;
   *q = '\0';
   if (++hopcount > 32) {
      fprintf(stderr, "Infinite tc= loop\n");
      return 0;
   }
   if (tgetent(tcbuf, tcname, filename) != 1)
      return 0;
   for (q = tcbuf; *q != ':'; q++)
      ;
   l = (int)(p - holdtbuf + strlen(q));
   if (l > 8192) {
      fprintf(stderr, "LGrind entry too long\n");
      q[(int)(8192 - (p-tbuf))] = '\0';
   }
   strcpy(p, q+1);
   tbuf = holdtbuf;
   return 1;
}

variable_types:
p
char *

variable_types:
q
char *

variable_types:
tcname
char [16]

variable_types:
tcbuf
char [8192]

variable_types:
holdtbuf
char *

variable_types: l int


repo: pielo/select

decompiled_code:
__int64 __fastcall ft_putc(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

original_code:
int ft_putc(int c)
{
 write(1, &c, 1);
 return (1);
}

variable_types: c int


pushData

repo: pierinz/citofonoweb

decompiled_code:
__int64 __fastcall pushData(char *src)
{
unsigned int v1; // ebx

if ( ((unsigned __int16)*current + 64) % (qsize << 6) == (unsigned __int16)*start )
return (unsigned int)-1;
f_elock(fd);
strcpy((char *)queue + (unsigned __int16)*current, src);
*current = ((unsigned __int16)*current + 64) % (qsize << 6);
msync(queue, msize, 4);
v1 = (qsize << 6) - abs32((unsigned __int16)*start - (unsigned __int16)*current);
if ( qsize << 6 == v1 )
v1 = 0;
f_unlock(fd);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
unsigned int v1; // ebx

if ( ((unsigned __int16)*current + 64) % (qsize << 6) == (unsigned __int16)*start )
return (unsigned int)-1;
f_elock(fd);
strcpy((char *)queue + (unsigned __int16)*current, src);
*current = ((unsigned __int16)*current + 64) % (qsize << 6);
msync(queue, msize, 4);
v1 = (qsize << 6) - abs32((unsigned __int16)*start - (unsigned __int16)*current);
if ( qsize << 6 == v1 )
v1 = 0;
f_unlock(fd);
return v1;
}

original_code:
int pushData(char* param) {
 int qfree;
 if ((*current + 64) % (qsize * 64) == *start) {
  return -1;
 }
 f_elock(fd);
 sprintf(queue + *current, "%s", param);
 *current = (*current + 64) % (qsize * 64);
 msync(queue, msize, 4);
 qfree = (qsize * 64) - abs(*start - *current);
 if (qfree == qsize * 64) {
  qfree = 0;
 }
 f_unlock(fd);
 return qfree;
}

canonical_original_code:
int pushData(char *param) {
 int qfree;
 if ((*current + 64) % (qsize * 64) == *start) {
  return -1;
 }
 f_elock(fd);
 sprintf(queue + *current, "%s", param);
 *current = (*current + 64) % (qsize * 64);
 msync(queue, msize, 4);
 qfree = (qsize * 64) - abs(*start - *current);
 if (qfree == qsize * 64) {
  qfree = 0;
 }
 f_unlock(fd);
 return qfree;
}

variable_types:
param
char *

variable_types: qfree int


popData

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

result = 0LL;
if ( *current != *start )
{
f_elock(fd);
if ( a1 )
strcpy(*a1, (const char *)queue + (unsigned __int16)*start);
*start = ((unsigned __int16)*start + 64) % (qsize << 6);
msync(queue, msize, 4);
f_unlock(fd);
result = abs32((unsigned __int16)*current - (unsigned __int16)*start);
}
return result;
}

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

result = 0LL;
if ( *current != *start )
{
f_elock(fd);
if ( a1 )
strcpy(*a1, (const char *)queue + (unsigned __int16)*start);
*start = ((unsigned __int16)*start + 64) % (qsize << 6);
msync(queue, msize, 4);
f_unlock(fd);
result = abs32((unsigned __int16)*current - (unsigned __int16)*start);
}
return result;
}

original_code:
int popData(char** result) {
 if (abs(*current - *start) == 0) {
  return 0;
 }
 f_elock(fd);
 if (result != ((void *)0)) {
  sprintf(*result, "%s", queue + *start);
 }
 *start = (*start + 64) % (qsize * 64);
 msync(queue, msize, 4);
 f_unlock(fd);
 return abs(*current - *start);
}

canonical_original_code:
int popData(char **result) {
 if (abs(*current - *start) == 0) {
  return 0;
 }
 f_elock(fd);
 if (result != ((void *)0)) {
  sprintf(*result, "%s", queue + *start);
 }
 *start = (*start + 64) % (qsize * 64);
 msync(queue, msize, 4);
 f_unlock(fd);
 return abs(*current - *start);
}

variable_types:
result
char **


pickData

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

result = 0LL;
if ( *current != *start )
{
f_elock(fd);
strcpy(*a1, (const char *)queue + (unsigned __int16)*start);
f_unlock(fd);
result = abs32((unsigned __int16)*current - (unsigned __int16)*start);
}
return result;
}

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

result = 0LL;
if ( *current != *start )
{
f_elock(fd);
strcpy(*a1, (const char *)queue + (unsigned __int16)*start);
f_unlock(fd);
result = abs32((unsigned __int16)*current - (unsigned __int16)*start);
}
return result;
}

original_code:
int pickData(char** result) {
 if (abs(*current - *start) == 0) {
  return 0;
 }
 f_elock(fd);
 sprintf(*result, "%s", queue + *start);
 f_unlock(fd);
 return abs(*current - *start);
}

canonical_original_code:
int pickData(char **result) {
 if (abs(*current - *start) == 0) {
  return 0;
 }
 f_elock(fd);
 sprintf(*result, "%s", queue + *start);
 f_unlock(fd);
 return abs(*current - *start);
}


logmessage

decompiled_code:
int __fastcall logmessage(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char sa[40]; // [rsp+10h] [rbp-28h] BYREF

time(&timer);
v1 = localtime(&timer);
strftime(sa, 0x16uLL, "%d/%m/%y %H:%M:%S - ", v1);
pthread_mutex_lock(&mutex);
fputs(sa, flog);
fputs(s, flog);
fputc(10, flog);
fflush(flog);
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int __fastcall func1(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char sa[40]; // [rsp+10h] [rbp-28h] BYREF

time(&timer);
v1 = localtime(&timer);
strftime(sa, 0x16uLL, "%d/%m/%y %H:%M:%S - ", v1);
pthread_mutex_lock(&mutex);
fputs(sa, flog);
fputs(s, flog);
fputc(10, flog);
fflush(flog);
return pthread_mutex_unlock(&mutex);
}

original_code:
void logmessage(char *message) {
 char buffer[22];
 time_t rawtime;
 struct tm * timeinfo;
 time(&rawtime);
 timeinfo = localtime(&rawtime);
 strftime(buffer, 22, "%d/%m/%y %H:%M:%S - ", timeinfo);
 pthread_mutex_lock(&mutex);
 fputs(buffer, flog);
 fputs(message, flog);
 fputs("\n", flog);
 fflush(flog);
 pthread_mutex_unlock(&mutex);
}

canonical_original_code:
void logmessage(char *message) {
 char buffer[22];
 long rawtime;
 struct tm *timeinfo;
 time(&rawtime);
 timeinfo = localtime(&rawtime);
 strftime(buffer, 22, "%d/%m/%y %H:%M:%S - ", timeinfo);
 pthread_mutex_lock(&mutex);
 fputs(buffer, flog);
 fputs(message, flog);
 fputs("\n", flog);
 fflush(flog);
 pthread_mutex_unlock(&mutex);
}

variable_types:
message
char *

variable_types:
buffer
char [22]

variable_types: rawtime long

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


rotate

decompiled_code:
int rotate()
{
pthread_mutex_lock(&mutex);
fclose(flog);
while ( !access(logfile, 0) )
usleep(0x4E20u);
flog = fopen(logfile, "a");
pthread_mutex_unlock(&mutex);
fwrite("Logfile rotated.", 1uLL, 0x10uLL, stderr);
return logmessage("Logfile rotated.");
}

canonical_decompiled_code:
int func4()
{
pthread_mutex_lock(&mutex);
fclose(flog);
while ( !access(logfile, 0) )
usleep(0x4E20u);
flog = fopen(logfile, "a");
pthread_mutex_unlock(&mutex);
fwrite("Logfile rotated.", 1uLL, 0x10uLL, stderr);
return func1("Logfile rotated.");
}

original_code:
void rotate() {
 pthread_mutex_lock(&mutex);
 fclose(flog);
 while (access(logfile, 0) == 0) {
  usleep(20000);
 }
 flog = fopen(logfile, "a");
 pthread_mutex_unlock(&mutex);
 fprintf(stderr, "Logfile rotated.");
 logmessage("Logfile rotated.");
}


clean

decompiled_code:
void clean()
{
if ( flog )
fclose(flog);
free(logfile);
free(source);
free(helper);
}

canonical_decompiled_code:
void func5()
{
if ( flog )
fclose(flog);
free(logfile);
free(source);
free(helper);
}

original_code:
void clean() {
 if (flog)
  fclose(flog);
 free(logfile);
 free(source);
 free(helper);
}


fatal

decompiled_code:
void __fastcall __noreturn fatal(char *s)
{
fprintf(stderr, "%s\n", s);
logmessage(s);
fwrite("Fatal error - program terminated.\n", 1uLL, 0x22uLL, stderr);
logmessage("Fatal error - program terminated.");
clean();
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(char *s)
{
fprintf(stderr, "%s\n", s);
func1(s);
fwrite("Fatal error - program terminated.\n", 1uLL, 0x22uLL, stderr);
func1("Fatal error - program terminated.");
func5();
exit(1);
}

original_code:
void fatal(char* message) {
 fprintf(stderr, "%s\n", message);
 logmessage(message);
 fprintf(stderr, "Fatal error - program terminated.\n");
 logmessage("Fatal error - program terminated.");
 clean();
 exit(1);
}

canonical_original_code:
void fatal(char *message) {
 fprintf(stderr, "%s\n", message);
 logmessage(message);
 fprintf(stderr, "Fatal error - program terminated.\n");
 logmessage("Fatal error - program terminated.");
 clean();
 exit(1);
}


GPIOValid

decompiled_code:
__int64 GPIOValid()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func11()
{
return 1LL;
}

original_code:
int GPIOValid(int pin) {
 return 1;
}

canonical_original_code:
int GPIOValid(int pin) {
 return 1;
}

variable_types: pin int


GPIOExport

decompiled_code:
__int64 __fastcall GPIOExport(unsigned int a1)
{
unsigned int v1; // ebp
int v3; // eax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

snprintf(v4, 0x23uLL, "/sys/class/gpio/gpio%d/", a1);
v1 = 0;
if ( access(v4, 1) == -1 )
{
v1 = open("/sys/class/gpio/export", 1);
if ( v1 == -1 )
{
fwrite("Failed to open export for writing!\n", 1uLL, 0x23uLL, stderr);
}
else
{
v3 = snprintf(v4, 3uLL, "%d", a1);
if ( write(v1, v4, v3) == -1 )
{
fwrite("Failed to export gpio!\n", 1uLL, 0x17uLL, stderr);
v1 = -1;
}
else
{
close(v1);
usleep(0x30D40u);
v1 = 0;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
unsigned int v1; // ebp
int v3; // eax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

snprintf(v4, 0x23uLL, "/sys/class/gpio/gpio%d/", a1);
v1 = 0;
if ( access(v4, 1) == -1 )
{
v1 = open("/sys/class/gpio/export", 1);
if ( v1 == -1 )
{
fwrite("Failed to open export for writing!\n", 1uLL, 0x23uLL, stderr);
}
else
{
v3 = snprintf(v4, 3uLL, "%d", a1);
if ( write(v1, v4, v3) == -1 )
{
fwrite("Failed to export gpio!\n", 1uLL, 0x17uLL, stderr);
v1 = -1;
}
else
{
close(v1);
usleep(0x30D40u);
v1 = 0;
}
}
}
return v1;
}

original_code:
int GPIOExport(int pin) {
 char buffer[35];
 ssize_t bytes_written;
 int fd;
 snprintf(buffer, 35, "/sys/class/gpio/gpio%d/", pin);
 if (access(buffer, 1) != -1) {
  return (0);
 }
 fd = open("/sys/class/gpio/export", 01);
 if (-1 == fd) {
  fprintf(stderr, "Failed to open export for writing!\n");
  return (-1);
 }
 bytes_written = snprintf(buffer, 3, "%d", pin);
 if (-1 == write(fd, buffer, bytes_written)) {
  fprintf(stderr, "Failed to export gpio!\n");
  return (-1);
 }
 close(fd);
 usleep(200000);
 return (0);
}

canonical_original_code:
int GPIOExport(int pin) {
 char buffer[35];
 long bytes_written;
 int fd;
 snprintf(buffer, 35, "/sys/class/gpio/gpio%d/", pin);
 if (access(buffer, 1) != -1) {
  return (0);
 }
 fd = open("/sys/class/gpio/export", 01);
 if (-1 == fd) {
  fprintf(stderr, "Failed to open export for writing!\n");
  return (-1);
 }
 bytes_written = snprintf(buffer, 3, "%d", pin);
 if (-1 == write(fd, buffer, bytes_written)) {
  fprintf(stderr, "Failed to export gpio!\n");
  return (-1);
 }
 close(fd);
 usleep(200000);
 return (0);
}

variable_types:
buffer
char [35]

variable_types: fd int


GPIOUnexport

decompiled_code:
__int64 __fastcall GPIOUnexport(unsigned int a1)
{
unsigned int v1; // ebx
int v2; // eax
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v1 = open("/sys/class/gpio/unexport", 1);
if ( v1 == -1 )
{
fwrite("Failed to open unexport for writing!\n", 1uLL, 0x25uLL, stderr);
}
else
{
v2 = snprintf(s, 3uLL, "%d", a1);
write(v1, s, v2);
close(v1);
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
unsigned int v1; // ebx
int v2; // eax
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v1 = open("/sys/class/gpio/unexport", 1);
if ( v1 == -1 )
{
fwrite("Failed to open unexport for writing!\n", 1uLL, 0x25uLL, stderr);
}
else
{
v2 = snprintf(s, 3uLL, "%d", a1);
write(v1, s, v2);
close(v1);
v1 = 0;
}
return v1;
}

original_code:
int GPIOUnexport(int pin) {
 char buffer[3];
 ssize_t bytes_written;
 int fd;
 fd = open("/sys/class/gpio/unexport", 01);
 if (-1 == fd) {
  fprintf(stderr, "Failed to open unexport for writing!\n");
  return (-1);
 }
 bytes_written = snprintf(buffer, 3, "%d", pin);
 write(fd, buffer, bytes_written);
 close(fd);
 return (0);
}

canonical_original_code:
int GPIOUnexport(int pin) {
 char buffer[3];
 long bytes_written;
 int fd;
 fd = open("/sys/class/gpio/unexport", 01);
 if (-1 == fd) {
  fprintf(stderr, "Failed to open unexport for writing!\n");
  return (-1);
 }
 bytes_written = snprintf(buffer, 3, "%d", pin);
 write(fd, buffer, bytes_written);
 close(fd);
 return (0);
}

variable_types:
buffer
char [3]


GPIODirection

decompiled_code:
__int64 __fastcall GPIODirection(unsigned int a1, int a2)
{
int v2; // ebx
int v3; // eax
unsigned int v4; // ebp
size_t v5; // rdx
const char *v6; // rbx
char v8[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = a2;
snprintf(v8, 0x23uLL, "/sys/class/gpio/gpio%d/direction", a1);
v3 = open(v8, 1);
v4 = v3;
if ( v3 == -1 )
{
fprintf(stderr, "Failed to open gpio direction %s for writing!\n", v8);
}
else
{
v5 = 2LL;
if ( a2 )
{
v5 = 3LL;
v2 = 3;
}
v6 = (const char *)(v2 + 4203147LL);
if ( write(v3, v6, v5) == -1 )
{
fprintf(stderr, "Failed to set direction %s on %s!\n", v6, v8);
v4 = -1;
}
else
{
close(v4);
v4 = 0;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, int a2)
{
int v2; // ebx
int v3; // eax
unsigned int v4; // ebp
size_t v5; // rdx
const char *v6; // rbx
char v8[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = a2;
snprintf(v8, 0x23uLL, "/sys/class/gpio/gpio%d/direction", a1);
v3 = open(v8, 1);
v4 = v3;
if ( v3 == -1 )
{
fprintf(stderr, "Failed to open gpio direction %s for writing!\n", v8);
}
else
{
v5 = 2LL;
if ( a2 )
{
v5 = 3LL;
v2 = 3;
}
v6 = (const char *)(v2 + 4203147LL);
if ( write(v3, v6, v5) == -1 )
{
fprintf(stderr, "Failed to set direction %s on %s!\n", v6, v8);
v4 = -1;
}
else
{
close(v4);
v4 = 0;
}
}
return v4;
}

original_code:
int GPIODirection(int pin, int dir) {
 static const char s_directions_str[] = "in\0out";
 char path[35];
 int fd;
 snprintf(path, 35, "/sys/class/gpio/gpio%d/direction", pin);
 fd = open(path, 01);
 if (-1 == fd) {
  fprintf(stderr, "Failed to open gpio direction %s for writing!\n", path);
  return (-1);
 }
 if (-1 == write(fd, &s_directions_str[0 == dir ? 0 : 3], 0 == dir ? 2 : 3)) {
  fprintf(stderr, "Failed to set direction %s on %s!\n", &s_directions_str[0 == dir ? 0 : 3], path);
  return (-1);
 }
 close(fd);
 return (0);
}

canonical_original_code:
int GPIODirection(int pin, int dir) {
 static char s_directions_str[] = "in\0out";
 char path[35];
 int fd;
 snprintf(path, 35, "/sys/class/gpio/gpio%d/direction", pin);
 fd = open(path, 01);
 if (-1 == fd) {
  fprintf(stderr, "Failed to open gpio direction %s for writing!\n", path);
  return (-1);
 }
 if (-1 == write(fd, &s_directions_str[0 == dir ? 0 : 3], 0 == dir ? 2 : 3)) {
  fprintf(stderr, "Failed to set direction %s on %s!\n", &s_directions_str[0 == dir ? 0 : 3], path);
  return (-1);
 }
 close(fd);
 return (0);
}

variable_types: dir int

variable_types:
path
char [35]


GPIORead

decompiled_code:
__int64 __fastcall GPIORead(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
char buf[3]; // [rsp+Dh] [rbp-2Bh] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

snprintf(s, 0x1EuLL, "/sys/class/gpio/gpio%d/value", a1);
v1 = open(s, 0);
v2 = v1;
if ( v1 == -1 )
{
fwrite("Failed to open gpio value for reading!\n", 1uLL, 0x27uLL, stderr);
}
else if ( read(v1, buf, 3uLL) == -1 )
{
fwrite("Failed to read value!\n", 1uLL, 0x16uLL, stderr);
v2 = -1;
}
else
{
close(v2);
v2 = atoi(buf);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
char buf[3]; // [rsp+Dh] [rbp-2Bh] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

snprintf(s, 0x1EuLL, "/sys/class/gpio/gpio%d/value", a1);
v1 = open(s, 0);
v2 = v1;
if ( v1 == -1 )
{
fwrite("Failed to open gpio value for reading!\n", 1uLL, 0x27uLL, stderr);
}
else if ( read(v1, buf, 3uLL) == -1 )
{
fwrite("Failed to read value!\n", 1uLL, 0x16uLL, stderr);
v2 = -1;
}
else
{
close(v2);
v2 = atoi(buf);
}
return v2;
}

original_code:
int GPIORead(int pin) {
 char path[30];
 char value_str[3];
 int fd;
 snprintf(path, 30, "/sys/class/gpio/gpio%d/value", pin);
 fd = open(path, 00);
 if (-1 == fd) {
  fprintf(stderr, "Failed to open gpio value for reading!\n");
  return (-1);
 }
 if (-1 == read(fd, value_str, 3)) {
  fprintf(stderr, "Failed to read value!\n");
  return (-1);
 }
 close(fd);
 return (atoi(value_str));
}

variable_types:
path
char [30]