GetDoubleByMantissaAndExp

decompiled_code:
double __fastcall GetDoubleByMantissaAndExp(unsigned __int64 a1, int a2)
{
__int64 v2; // rdx
int v3; // eax
double result; // xmm0_8
__int64 v5; // rdx

if ( a1 )
{
v2 = qword_268;
if ( (a1 & 0xFFE0000000000000LL) != 0 )
{
do
{
a1 >>= 1;
v3 = a2 - qword_268 + 1 + v2++;
}
while ( (a1 & 0xFFE0000000000000LL) != 0 );
qword_268 = v2;
}
else if ( _bittest64((const __int64 *)&a1, 0x34u) )
{
v3 = a2;
}
else
{
v5 = qword_270;
do
{
a1 *= 2LL;
v3 = a2 + qword_270 - 1 - v5++;
}
while ( (a1 & 0x10000000000000LL) == 0 );
qword_270 = v5;
}
++qword_278;
*(_QWORD *)&result = a1 & 0xFFFFFFFFFFFFFLL | ((unsigned __int64)(unsigned int)(v3 + 1075) << 52);
}
else
{
++_gcov0_GetDoubleByMantissaAndExp;
result = 0.0;
}
return result;
}

canonical_decompiled_code:
double __fastcall func1(unsigned __int64 a1, int a2)
{
__int64 v2; // rdx
int v3; // eax
double result; // xmm0_8
__int64 v5; // rdx

if ( a1 )
{
v2 = qword_268;
if ( (a1 & 0xFFE0000000000000LL) != 0 )
{
do
{
a1 >>= 1;
v3 = a2 - qword_268 + 1 + v2++;
}
while ( (a1 & 0xFFE0000000000000LL) != 0 );
qword_268 = v2;
}
else if ( _bittest64((const __int64 *)&a1, 0x34u) )
{
v3 = a2;
}
else
{
v5 = qword_270;
do
{
a1 *= 2LL;
v3 = a2 + qword_270 - 1 - v5++;
}
while ( (a1 & 0x10000000000000LL) == 0 );
qword_270 = v5;
}
++qword_278;
*(_QWORD *)&result = a1 & 0xFFFFFFFFFFFFFLL | ((unsigned __int64)(unsigned int)(v3 + 1075) << 52);
}
else
{
++_gcov0_GetDoubleByMantissaAndExp;
result = 0.0;
}
return result;
}

original_code:
asn1Real GetDoubleByMantissaAndExp(asn1SccUint mantissa, int exponent)
{
 asn1Real ret = 1.0;
 if (mantissa == 0)
  return 0.0;
 if (exponent >= 0) {
  while (exponent) {
   ret = ret * 2.0;
   exponent--;
  }
  return (asn1Real)mantissa*ret;
 }
 else {
  exponent = -exponent;
  while (exponent) {
   ret = ret * 2.0;
   exponent--;
  }
  return ((asn1Real)mantissa) / ret;
 }
}

canonical_original_code:
double GetDoubleByMantissaAndExp(unsigned long long mantissa, int exponent)
{
 double ret = 1.0;
 if (mantissa == 0)
  return 0.0;
 if (exponent >= 0) {
  while (exponent) {
   ret = ret * 2.0;
   exponent--;
  }
  return (double)mantissa*ret;
 }
 else {
  exponent = -exponent;
  while (exponent) {
   ret = ret * 2.0;
   exponent--;
  }
  return ((double)mantissa) / ret;
 }
}

variable_types:
mantissa
unsigned long long

variable_types: exponent int

variable_types: ret double


decompiled_code:
bool __fastcall RGBCOLORS_Equal(_DWORD *a1, int *a2)
{
int v2; // eax

v2 = *a2;
++_gcov0_RGBCOLORS_Equal;
return *a1 == v2;
}

canonical_decompiled_code:
bool __fastcall func2(_DWORD *a1, int *a2)
{
int v2; // eax

v2 = *a2;
++_gcov0_RGBCOLORS_Equal;
return *a1 == v2;
}

original_code:
flag RGBCOLORS_Equal(const RGBCOLORS* pVal1, const RGBCOLORS* pVal2)
{
 flag ret=1;
 ret = (*pVal1 == *pVal2);
 return ret;
}

canonical_original_code:
_Bool RGBCOLORS_Equal(enum RGBCOLORS *pVal1, enum RGBCOLORS *pVal2)
{
 _Bool ret = 1;
 ret = (*pVal1 == *pVal2);
 return ret;
}

variable_types: enum RGBCOLORS { red=0, green=1, blue=2 } *


decompiled_code:
bool __fastcall CH1_left_Equal(_QWORD *a1, __int64 *a2)
{
__int64 v2; // rax

v2 = *a2;
++_gcov0_CH1_left_Equal;
return *a1 == v2;
}

canonical_decompiled_code:
bool __fastcall func7(_QWORD *a1, __int64 *a2)
{
__int64 v2; // rax

v2 = *a2;
++_gcov0_CH1_left_Equal;
return *a1 == v2;
}

original_code:
flag CH1_left_Equal(const CH1_left* pVal1, const CH1_left* pVal2)
{
 flag ret=1;
 ret = (*pVal1 == *pVal2);
 return ret;
}

canonical_original_code:
_Bool CH1_left_Equal(long long *pVal1, long long *pVal2)
{
 _Bool ret = 1;
 ret = (*pVal1 == *pVal2);
 return ret;
}


decompiled_code:
bool __fastcall CH1_left_Encode(__int64 *a1, __int64 a2, int *a3, char a4)
{
bool result; // al

++_gcov0_CH1_left_Encode;
if ( a4 )
{
++qword_BE8;
result = CH1_left_IsConstraintValid(a1, a3);
++qword_BF0;
if ( !result )
return result;
++qword_BF8;
}
BitStream_EncodeConstraintWholeNumber(a2, *a1, 1LL, 10LL);
++qword_C00;
return 1;
}

canonical_decompiled_code:
bool __fastcall func8(__int64 *a1, __int64 a2, int *a3, char a4)
{
bool result; // al

++_gcov0_CH1_left_Encode;
if ( a4 )
{
++qword_BE8;
result = func6(a1, a3);
++qword_BF0;
if ( !result )
return result;
++qword_BF8;
}
BitStream_EncodeConstraintWholeNumber(a2, *a1, 1LL, 10LL);
++qword_C00;
return 1;
}

original_code:
flag CH1_left_Encode(const CH1_left* pVal, BitStream* pBitStrm, int* pErrCode, flag bCheckConstraints)
{
    flag ret = 1;
 ret = bCheckConstraints ? CH1_left_IsConstraintValid(pVal, pErrCode) : 1 ;
 if (ret) {
     BitStream_EncodeConstraintWholeNumber(pBitStrm, *pVal, 1, 10);
    }
 return ret;
}

canonical_original_code:
_Bool CH1_left_Encode(long long *pVal, struct BitStream *pBitStrm, int *pErrCode, _Bool bCheckConstraints)
{
    _Bool ret = 1;
 ret = bCheckConstraints ? CH1_left_IsConstraintValid(pVal, pErrCode) : 1 ;
 if (ret) {
     BitStream_EncodeConstraintWholeNumber(pBitStrm, *pVal, 1, 10);
    }
 return ret;
}

variable_types:
pVal
long long *

variable_types: struct BitStream { unsigned char *buf; long count; long currentByte; int currentBit; } *

variable_types:
pErrCode
int *


GetCharIndex

decompiled_code:
__int64 __fastcall GetCharIndex(char a1, __int64 a2, int a3)
{
__int64 v3; // rax
char v4; // r9
unsigned int v5; // er8
__int64 v6; // rsi

++_gcov0_GetCharIndex;
if ( a3 <= 0 )
return 0;
v3 = qword_690;
v4 = 0;
v5 = 0;
v6 = a2 - qword_690;
while ( *(unsigned __int8 *)(v6 + v3) != a1 )
{
++v5;
++v3;
v4 = 1;
if ( a3 == v5 )
{
qword_690 = v3;
return 0LL;
}
}
if ( v4 )
qword_690 = v3;
++qword_688;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, __int64 a2, int a3)
{
__int64 v3; // rax
char v4; // r9
unsigned int v5; // er8
__int64 v6; // rsi

++_gcov0_GetCharIndex;
if ( a3 <= 0 )
return 0;
v3 = qword_690;
v4 = 0;
v5 = 0;
v6 = a2 - qword_690;
while ( *(unsigned __int8 *)(v6 + v3) != a1 )
{
++v5;
++v3;
v4 = 1;
if ( a3 == v5 )
{
qword_690 = v3;
return 0LL;
}
}
if ( v4 )
qword_690 = v3;
++qword_688;
return v5;
}

original_code:
int GetCharIndex(char ch, byte Set[], int setLen)
{
    int i=0;
    for(i=0; i<setLen; i++)
        if (ch == Set[i])
            return i;
    return 0;
}

canonical_original_code:
int GetCharIndex(char ch, unsigned char Set[], int setLen)
{
    int i = 0;
    for(i=0; i<setLen; i++)
        if (ch == Set[i])
            return i;
    return 0;
}

variable_types: ch char

variable_types:
Set
unsigned char []

variable_types: setLen int

variable_types: i int

return_type: int


decompiled_code:
void *__fastcall ByteStream_Init(__int64 a1, void *a2, size_t a3)
{
void *result; // rax

*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
++_gcov0_ByteStream_Init;
result = memset(a2, 0, a3);
*(_QWORD *)(a1 + 16) = 0LL;
*(_BYTE *)(a1 + 24) = 0;
return result;
}

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

*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
++_gcov0_ByteStream_Init;
result = memset(a2, 0, a3);
*(_QWORD *)(a1 + 16) = 0LL;
*(_BYTE *)(a1 + 24) = 0;
return result;
}

original_code:
void ByteStream_Init(ByteStream* pStrm, byte* buf, long count)
{
    pStrm->count = count;
    pStrm->buf = buf;
    memset(pStrm->buf,0x0,(size_t)count);
    pStrm->currentByte = 0;
    pStrm->EncodeWhiteSpace = 0;
}

canonical_original_code:
void ByteStream_Init(struct ByteStream *pStrm, unsigned char *buf, long count)
{
    pStrm->count = count;
    pStrm->buf = buf;
    memset(pStrm->buf,0x0,(unsigned long)count);
    pStrm->currentByte = 0;
    pStrm->EncodeWhiteSpace = 0;
}

variable_types: struct ByteStream { unsigned char *buf; long count; long currentByte; _Bool EncodeWhiteSpace; } *

variable_types:
buf
unsigned char *

variable_types: count long

return_type: void


decompiled_code:
__int64 __fastcall ByteStream_GetLength(__int64 a1)
{
++_gcov0_ByteStream_GetLength;
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
++_gcov0_ByteStream_GetLength;
return *(_QWORD *)(a1 + 16);
}

original_code:
asn1SccSint ByteStream_GetLength(ByteStream* pStrm)
{
    return pStrm->currentByte;
}

canonical_original_code:
long long ByteStream_GetLength(struct ByteStream *pStrm)
{
    return pStrm->currentByte;
}

return_type: long long

user_defined_types: struct ByteStream { unsigned char *buf; long count; long currentByte; _Bool EncodeWhiteSpace; }


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

if ( *(int *)a1 <= 1 )
{
++qword_708;
result = 0LL;
}
else
{
++_gcov0_ObjectIdentifier_isValid;
result = 0LL;
if ( *(_QWORD *)(a1 + 8) <= 2uLL )
{
++qword_710;
result = 1LL;
if ( *(_QWORD *)(a1 + 16) > 0x27uLL )
{
++qword_718;
result = 0LL;
}
}
}
return result;
}

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

if ( *(int *)a1 <= 1 )
{
++qword_708;
result = 0LL;
}
else
{
++_gcov0_ObjectIdentifier_isValid;
result = 0LL;
if ( *(_QWORD *)(a1 + 8) <= 2uLL )
{
++qword_710;
result = 1LL;
if ( *(_QWORD *)(a1 + 16) > 0x27uLL )
{
++qword_718;
result = 0LL;
}
}
}
return result;
}

original_code:
flag ObjectIdentifier_isValid(const Asn1ObjectIdentifier *pVal) {
 return (pVal->nCount >= 2) && (pVal->values[0] <= 2) && (pVal->values[1] <= 39);
}

canonical_original_code:
_Bool ObjectIdentifier_isValid(struct Asn1ObjectIdentifier *pVal) {
 return (pVal->nCount >= 2) && (pVal->values[0] <= 2) && (pVal->values[1] <= 39);
}

variable_types: struct Asn1ObjectIdentifier { int nCount; unsigned long long values[20]; } *


decompiled_code:
bool __fastcall RelativeOID_isValid(int *a1)
{
int v1; // eax

v1 = *a1;
++_gcov0_RelativeOID_isValid;
return v1 > 0;
}

canonical_decompiled_code:
bool __fastcall func8(int *a1)
{
int v1; // eax

v1 = *a1;
++_gcov0_RelativeOID_isValid;
return v1 > 0;
}

original_code:
flag RelativeOID_isValid(const Asn1ObjectIdentifier *pVal) {
 return pVal->nCount > 0;
}

canonical_original_code:
_Bool RelativeOID_isValid(struct Asn1ObjectIdentifier *pVal) {
 return pVal->nCount > 0;
}

user_defined_types: struct Asn1ObjectIdentifier { int nCount; unsigned long long values[20]; }


decompiled_code:
__int64 __fastcall ObjectIdentifier_equal(int *a1, _DWORD *a2, __int64 a3, __int64 a4, __int64 a5)
{
int v5; // edx
__int64 result; // rax
__int64 v7; // rax
int *v8; // rdi
_DWORD *v9; // rsi
__int64 v10; // rcx
__int64 v11; // rdx
__int64 v12; // r9

LOBYTE(a5) = a1 != 0LL && a2 != 0LL;
if ( (_BYTE)a5 )
{
++_gcov0_ObjectIdentifier_equal;
v5 = *a1;
if ( *a1 == *a2 && (++qword_750, v5 <= 20) )
{
if ( v5 > 0 )
{
v7 = qword_758 + 1;
a5 = qword_758 + 1 + (unsigned int)(v5 - 1);
v8 = &a1[-2 * qword_758];
v9 = &a2[-2 * qword_758];
do
{
v10 = *(_QWORD *)&v8[2 * v7];
v11 = *(_QWORD *)&v9[2 * v7];
v12 = v7;
if ( v7 == a5 )
{
qword_758 = v7;
LOBYTE(a5) = v10 == v11;
goto LABEL_10;
}
++v7;
}
while ( v10 == v11 );
++qword_760;
LODWORD(a5) = 0;
qword_758 = v12;
}
LABEL_10:
++qword_768;
result = (unsigned int)a5;
}
else
{
result = 0LL;
}
}
else
{
++qword_748;
result = (unsigned int)a5;
}
return result;
}

original_code:
flag ObjectIdentifier_equal(const Asn1ObjectIdentifier *pVal1, const Asn1ObjectIdentifier *pVal2) {
 int i;
 if ((pVal1 != ((void *)0)) && (pVal2 != ((void *)0)) && pVal1->nCount == pVal2->nCount && pVal1->nCount <= 20) {
  flag ret = 1;
  for (i = 0; i < pVal1->nCount && ret; i++)
  {
   ret = (pVal1->values[i] == pVal2->values[i]);
  }
  return ret;
 }
 else {
  return 0;
 }
}

canonical_original_code:
_Bool ObjectIdentifier_equal(struct Asn1ObjectIdentifier *pVal1, struct Asn1ObjectIdentifier *pVal2) {
 int i;
 if ((pVal1 != ((void *)0)) && (pVal2 != ((void *)0)) && pVal1->nCount == pVal2->nCount && pVal1->nCount <= 20) {
  _Bool ret = 1;
  for (i = 0; i < pVal1->nCount && ret; i++)
  {
   ret = (pVal1->values[i] == pVal2->values[i]);
  }
  return ret;
 }
 else {
  return 0;
 }
}


decompiled_code:
__int64 __fastcall ObjectIdentifier_subidentifiers_uper_encode(__int64 a1, _DWORD *a2, unsigned __int64 a3)
{
__int64 v3; // rcx
int v7; // er8
char *v8; // rbx
char v9; // dl
unsigned __int64 v10; // r11
int v11; // esi
char v12; // dl
__int64 result; // rax
char v14; // bl
__int64 v15; // r11
char *v16; // rdi
char v17; // r12
int v18; // ecx
__int64 v19; // rbp
char v20[40]; // [rsp+0h] [rbp-28h] BYREF

v3 = qword_948;
v7 = 0;
++_gcov0_ObjectIdentifier_subidentifiers_uper_encode;
v8 = &v20[-qword_948];
do
{
v9 = a3;
v10 = a3;
v11 = v7;
a3 >>= 7;
v12 = v9 & 0x7F;
++v7;
v8[v3++] = v12;
}
while ( v10 > 0x7F );
qword_948 = v3;
LODWORD(result) = *a2;
v14 = 0;
v15 = qword_958;
v16 = &v20[v7];
v17 = 0;
v18 = 0;
v19 = qword_950;
while ( 1 )
{
if ( v18 == v11 )
{
++v19;
v17 = 1;
}
else
{
++v15;
v12 |= 0x80u;
v14 = 1;
}
--v16;
*(_BYTE *)(a1 + (int)result) = v12;
result = (unsigned int)(*a2 + 1);
*a2 = result;
if ( v18 == v11 )
break;
v12 = *(v16 - 1);
++v18;
}
if ( v17 )
qword_950 = v19;
if ( v14 )
qword_958 = v15;
return result;
}

original_code:
void ObjectIdentifier_subidentifiers_uper_encode(byte* encodingBuf, int* pSize, asn1SccUint siValue) {
 flag lastOctet = 0;
 byte tmp[16];
 int nSize = 0;
 int i;
 while (!lastOctet)
 {
  byte curByte = siValue % 128;
  siValue = siValue / 128;
  lastOctet = (siValue == 0);
  tmp[nSize] = curByte;
  nSize++;
 }
 for (i = 0; i < nSize; i++) {
  byte curByte = (i == nSize - 1) ? tmp[nSize - i - 1] : tmp[nSize - i - 1] | 0x80;
  encodingBuf[*pSize] = curByte;
  (*pSize)++;
 }
}

canonical_original_code:
void ObjectIdentifier_subidentifiers_uper_encode(unsigned char *encodingBuf, int *pSize, unsigned long long siValue) {
 _Bool lastOctet = 0;
 unsigned char tmp[16];
 int nSize = 0;
 int i;
 while (!lastOctet)
 {
  unsigned char curByte = siValue % 128;
  siValue = siValue / 128;
  lastOctet = (siValue == 0);
  tmp[nSize] = curByte;
  nSize++;
 }
 for (i = 0; i < nSize; i++) {
  unsigned char curByte = (i == nSize - 1) ? tmp[nSize - i - 1] : tmp[nSize - i - 1] | 0x80;
  encodingBuf[*pSize] = curByte;
  (*pSize)++;
 }
}

variable_types:
encodingBuf
unsigned char *

variable_types:
pSize
int *

variable_types:
siValue
unsigned long long

variable_types:
tmp
unsigned char [16]

variable_types: nSize int

variable_types:
curByte
unsigned char


decompiled_code:
__int64 __fastcall ObjectIdentifier_uper_encode(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
unsigned __int64 v4; // rdx
__int64 result; // rax
__int64 i; // rbx
__int64 v7; // rsi
int v8; // [rsp+Ch] [rbp-ECh] BYREF
char v9[232]; // [rsp+10h] [rbp-E8h] BYREF

v2 = *(_QWORD *)(a2 + 8);
++_gcov0_ObjectIdentifier_uper_encode;
v8 = 0;
ObjectIdentifier_subidentifiers_uper_encode((__int64)v9, &v8, *(_QWORD *)(a2 + 16) + 40 * v2);
++qword_968;
if ( *(int *)a2 > 2 )
{
v3 = 2LL;
do
{
v4 = *(_QWORD *)(a2 + 8 * v3++ + 8);
ObjectIdentifier_subidentifiers_uper_encode((__int64)v9, &v8, v4);
++qword_970;
}
while ( *(_DWORD *)a2 > (int)v3 );
}
if ( v8 > 127 )
{
++qword_980;
BitStream_AppendBit(a1, 1LL);
++qword_998;
BitStream_EncodeConstraintWholeNumber(a1, v8, 0LL, 0x7FFFLL);
}
else
{
++qword_978;
BitStream_EncodeConstraintWholeNumber(a1, v8, 0LL, 255LL);
++qword_988;
}
result = (unsigned int)v8;
++qword_990;
for ( i = 0LL; v8 > (int)i; ++qword_9A0 )
{
v7 = (unsigned __int8)v9[i++];
result = BitStream_AppendByte0(a1, v7);
}
++qword_9A8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
unsigned __int64 v4; // rdx
__int64 result; // rax
__int64 i; // rbx
__int64 v7; // rsi
int v8; // [rsp+Ch] [rbp-ECh] BYREF
char v9[232]; // [rsp+10h] [rbp-E8h] BYREF

v2 = *(_QWORD *)(a2 + 8);
++_gcov0_ObjectIdentifier_uper_encode;
v8 = 0;
func0((__int64)v9, &v8, *(_QWORD *)(a2 + 16) + 40 * v2);
++qword_968;
if ( *(int *)a2 > 2 )
{
v3 = 2LL;
do
{
v4 = *(_QWORD *)(a2 + 8 * v3++ + 8);
func0((__int64)v9, &v8, v4);
++qword_970;
}
while ( *(_DWORD *)a2 > (int)v3 );
}
if ( v8 > 127 )
{
++qword_980;
BitStream_AppendBit(a1, 1LL);
++qword_998;
BitStream_EncodeConstraintWholeNumber(a1, v8, 0LL, 0x7FFFLL);
}
else
{
++qword_978;
BitStream_EncodeConstraintWholeNumber(a1, v8, 0LL, 255LL);
++qword_988;
}
result = (unsigned int)v8;
++qword_990;
for ( i = 0LL; v8 > (int)i; ++qword_9A0 )
{
v7 = (unsigned __int8)v9[i++];
result = BitStream_AppendByte0(a1, v7);
}
++qword_9A8;
return result;
}

original_code:
void ObjectIdentifier_uper_encode(BitStream* pBitStrm, const Asn1ObjectIdentifier *pVal) {
 byte tmp[20 * (sizeof(asn1SccUint) + 2)];
 int totalSize = 0;
 int i = 0;
 ObjectIdentifier_subidentifiers_uper_encode(tmp, &totalSize, pVal->values[0] * 40 + pVal->values[1]);
 for (i = 2; i < pVal->nCount; i++) {
  ObjectIdentifier_subidentifiers_uper_encode(tmp, &totalSize, pVal->values[i]);
 }
 if (totalSize <= 0x7F)
  BitStream_EncodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0xFF);
 else
 {
  BitStream_AppendBit(pBitStrm, 1);
  BitStream_EncodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0x7FFF);
 }
 for (i = 0; i < totalSize; i++) {
  BitStream_AppendByte0(pBitStrm, tmp[i]);
 }
}

canonical_original_code:
void ObjectIdentifier_uper_encode(struct BitStream *pBitStrm, struct Asn1ObjectIdentifier *pVal) {
 unsigned char tmp[-1];
 int totalSize = 0;
 int i = 0;
 ObjectIdentifier_subidentifiers_uper_encode(tmp, &totalSize, pVal->values[0] * 40 + pVal->values[1]);
 for (i = 2; i < pVal->nCount; i++) {
  ObjectIdentifier_subidentifiers_uper_encode(tmp, &totalSize, pVal->values[i]);
 }
 if (totalSize <= 0x7F)
  BitStream_EncodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0xFF);
 else
 {
  BitStream_AppendBit(pBitStrm, 1);
  BitStream_EncodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0x7FFF);
 }
 for (i = 0; i < totalSize; i++) {
  BitStream_AppendByte0(pBitStrm, tmp[i]);
 }
}

variable_types:
tmp
unsigned char [-1]

variable_types: totalSize int

user_defined_types: struct BitStream { unsigned char *buf; long count; long currentByte; int currentBit; }


decompiled_code:
__int64 __fastcall RelativeOID_uper_encode(__int64 a1, int *a2)
{
int v2; // edx
__int64 v3; // rbx
unsigned __int64 v4; // rdx
__int64 v5; // rsi
__int64 result; // rax
__int64 i; // rbx
__int64 v8; // rsi
int v9; // [rsp+Ch] [rbp-FCh] BYREF
char v10[248]; // [rsp+10h] [rbp-F8h] BYREF

v2 = *a2;
++_gcov0_RelativeOID_uper_encode;
v9 = 0;
if ( v2 <= 0 )
{
v5 = 0LL;
}
else
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)&a2[2 * v3++ + 2];
ObjectIdentifier_subidentifiers_uper_encode((__int64)v10, &v9, v4);
++qword_9C8;
}
while ( *a2 > (int)v3 );
v5 = v9;
if ( v9 > 127 )
{
++qword_9D8;
BitStream_AppendBit(a1, 1LL);
++qword_9F0;
BitStream_EncodeConstraintWholeNumber(a1, v9, 0LL, 0x7FFFLL);
goto LABEL_6;
}
}
++qword_9D0;
BitStream_EncodeConstraintWholeNumber(a1, v5, 0LL, 255LL);
++qword_9E0;
LABEL_6:
result = (unsigned int)v9;
++qword_9E8;
for ( i = 0LL; v9 > (int)i; ++qword_9F8 )
{
v8 = (unsigned __int8)v10[i++];
result = BitStream_AppendByte0(a1, v8);
}
++qword_A00;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2)
{
int v2; // edx
__int64 v3; // rbx
unsigned __int64 v4; // rdx
__int64 v5; // rsi
__int64 result; // rax
__int64 i; // rbx
__int64 v8; // rsi
int v9; // [rsp+Ch] [rbp-FCh] BYREF
char v10[248]; // [rsp+10h] [rbp-F8h] BYREF

v2 = *a2;
++_gcov0_RelativeOID_uper_encode;
v9 = 0;
if ( v2 <= 0 )
{
v5 = 0LL;
}
else
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)&a2[2 * v3++ + 2];
func0((__int64)v10, &v9, v4);
++qword_9C8;
}
while ( *a2 > (int)v3 );
v5 = v9;
if ( v9 > 127 )
{
++qword_9D8;
BitStream_AppendBit(a1, 1LL);
++qword_9F0;
BitStream_EncodeConstraintWholeNumber(a1, v9, 0LL, 0x7FFFLL);
goto LABEL_6;
}
}
++qword_9D0;
BitStream_EncodeConstraintWholeNumber(a1, v5, 0LL, 255LL);
++qword_9E0;
LABEL_6:
result = (unsigned int)v9;
++qword_9E8;
for ( i = 0LL; v9 > (int)i; ++qword_9F8 )
{
v8 = (unsigned __int8)v10[i++];
result = BitStream_AppendByte0(a1, v8);
}
++qword_A00;
return result;
}

original_code:
void RelativeOID_uper_encode(BitStream* pBitStrm, const Asn1ObjectIdentifier *pVal) {
 byte tmp[20 * (sizeof(asn1SccUint) + 2)];
 int totalSize = 0;
 int i = 0;
 for (i = 0; i < pVal->nCount; i++) {
  ObjectIdentifier_subidentifiers_uper_encode(tmp, &totalSize, pVal->values[i]);
 }
 if (totalSize <= 0x7F)
  BitStream_EncodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0xFF);
 else
 {
  BitStream_AppendBit(pBitStrm, 1);
  BitStream_EncodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0x7FFF);
 }
 for (i = 0; i < totalSize; i++) {
  BitStream_AppendByte0(pBitStrm, tmp[i]);
 }
}

canonical_original_code:
void RelativeOID_uper_encode(struct BitStream *pBitStrm, struct Asn1ObjectIdentifier *pVal) {
 unsigned char tmp[-1];
 int totalSize = 0;
 int i = 0;
 for (i = 0; i < pVal->nCount; i++) {
  ObjectIdentifier_subidentifiers_uper_encode(tmp, &totalSize, pVal->values[i]);
 }
 if (totalSize <= 0x7F)
  BitStream_EncodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0xFF);
 else
 {
  BitStream_AppendBit(pBitStrm, 1);
  BitStream_EncodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0x7FFF);
 }
 for (i = 0; i < totalSize; i++) {
  BitStream_AppendByte0(pBitStrm, tmp[i]);
 }
}

variable_types: struct BitStream { unsigned char *buf; long count; long currentByte; int currentBit; } *


decompiled_code:
__int64 __fastcall ObjectIdentifier_subidentifiers_uper_decode(__int64 a1, __int64 *a2, unsigned __int64 *a3)
{
char v4; // dl
unsigned __int64 v5; // rax
unsigned int v6; // er8
__int64 result; // rax
char v8[25]; // [rsp+1h] [rbp-19h] BYREF

++_gcov0_ObjectIdentifier_subidentifiers_uper_decode;
*a3 = 0LL;
if ( *a2 <= 0 )
{
++qword_A38;
result = 1LL;
}
else
{
while ( 1 )
{
v8[0] = 0;
v6 = BitStream_ReadByte(a1, v8);
if ( !(_BYTE)v6 )
{
++qword_A28;
return v6;
}
v4 = v8[0];
--*a2;
v5 = *a3;
++qword_A30;
*a3 = v4 & 0x7F | (v5 << 7);
if ( *a2 <= 0 )
break;
if ( v4 >= 0 )
{
++qword_A40;
return v6;
}
}
++qword_A38;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 *a2, unsigned __int64 *a3)
{
char v4; // dl
unsigned __int64 v5; // rax
unsigned int v6; // er8
__int64 result; // rax
char v8[25]; // [rsp+1h] [rbp-19h] BYREF

++_gcov0_ObjectIdentifier_subidentifiers_uper_decode;
*a3 = 0LL;
if ( *a2 <= 0 )
{
++qword_A38;
result = 1LL;
}
else
{
while ( 1 )
{
v8[0] = 0;
v6 = BitStream_ReadByte(a1, v8);
if ( !(_BYTE)v6 )
{
++qword_A28;
return v6;
}
v4 = v8[0];
--*a2;
v5 = *a3;
++qword_A30;
*a3 = v4 & 0x7F | (v5 << 7);
if ( *a2 <= 0 )
break;
if ( v4 >= 0 )
{
++qword_A40;
return v6;
}
}
++qword_A38;
result = 1LL;
}
return result;
}

original_code:
flag ObjectIdentifier_subidentifiers_uper_decode(BitStream* pBitStrm, asn1SccSint* pRemainingOctets, asn1SccUint* siValue) {
 byte curByte;
 flag bLastOctet = 0;
 asn1SccUint curOctetValue = 0;
 *siValue = 0;
 while (*pRemainingOctets > 0 && !bLastOctet)
 {
  curByte = 0;
  if (!BitStream_ReadByte(pBitStrm, &curByte))
   return 0;
  (*pRemainingOctets)--;
  bLastOctet = ((curByte & 0x80) == 0);
  curOctetValue = curByte & 0x7F;
  (*siValue) <<= 7;
  (*siValue) |= curOctetValue;
 }
 return 1;
}

canonical_original_code:
_Bool ObjectIdentifier_subidentifiers_uper_decode(struct BitStream *pBitStrm, long long *pRemainingOctets, unsigned long long *siValue) {
 unsigned char curByte;
 _Bool bLastOctet = 0;
 unsigned long long curOctetValue = 0;
 *siValue = 0;
 while (*pRemainingOctets > 0 && !bLastOctet)
 {
  curByte = 0;
  if (!BitStream_ReadByte(pBitStrm, &curByte))
   return 0;
  (*pRemainingOctets)--;
  bLastOctet = ((curByte & 0x80) == 0);
  curOctetValue = curByte & 0x7F;
  (*siValue) <<= 7;
  (*siValue) |= curOctetValue;
 }
 return 1;
}

variable_types:
pRemainingOctets
long long *

variable_types:
siValue
unsigned long long *

variable_types:
curOctetValue
unsigned long long


decompiled_code:
__int64 __fastcall ObjectIdentifier_uper_decode_lentg(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

++_gcov0_ObjectIdentifier_uper_decode_lentg;
result = BitStream_DecodeConstraintWholeNumber(a1, a2, 0LL, 255LL);
if ( (_BYTE)result )
{
++qword_A70;
if ( *a2 > 127 )
{
++qword_A78;
result = BitStream_DecodeConstraintWholeNumber(a1, v4, 0LL, 255LL);
if ( (_BYTE)result )
{
v3 = *a2;
++qword_A88;
*a2 = (LOWORD(v4[0]) | (unsigned __int16)((_WORD)v3 << 8)) & 0x7FFF;
}
else
{
++qword_A80;
}
}
}
else
{
++qword_A68;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

++_gcov0_ObjectIdentifier_uper_decode_lentg;
result = BitStream_DecodeConstraintWholeNumber(a1, a2, 0LL, 255LL);
if ( (_BYTE)result )
{
++qword_A70;
if ( *a2 > 127 )
{
++qword_A78;
result = BitStream_DecodeConstraintWholeNumber(a1, v4, 0LL, 255LL);
if ( (_BYTE)result )
{
v3 = *a2;
++qword_A88;
*a2 = (LOWORD(v4[0]) | (unsigned __int16)((_WORD)v3 << 8)) & 0x7FFF;
}
else
{
++qword_A80;
}
}
}
else
{
++qword_A68;
}
return result;
}

original_code:
flag ObjectIdentifier_uper_decode_lentg(BitStream* pBitStrm, asn1SccSint* totalSize) {
 asn1SccSint len2;
 if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0xFF))
  return 0;
 if (*totalSize > 0x7F) {
  if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &len2, 0, 0xFF))
   return 0;
  (*totalSize) <<= 8;
  (*totalSize) |= len2;
  (*totalSize) &= 0x7FFF;
 }
 return 1;
}

canonical_original_code:
_Bool ObjectIdentifier_uper_decode_lentg(struct BitStream *pBitStrm, long long *totalSize) {
 long long len2;
 if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, totalSize, 0, 0xFF))
  return 0;
 if (*totalSize > 0x7F) {
  if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &len2, 0, 0xFF))
   return 0;
  (*totalSize) <<= 8;
  (*totalSize) |= len2;
  (*totalSize) &= 0x7FFF;
 }
 return 1;
}

variable_types:
totalSize
long long *


decompiled_code:
char __fastcall ObjectIdentifier_uper_decode(__int64 a1, int *a2)
{
char result; // al
unsigned __int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // rdx
int v6; // eax
int v7; // eax
unsigned __int64 v8; // [rsp+0h] [rbp-28h] BYREF
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

++_gcov0_ObjectIdentifier_uper_decode;
ObjectIdentifier_Init(a2);
++qword_AA8;
result = ObjectIdentifier_uper_decode_lentg(a1, v9);
++qword_AB0;
if ( result )
{
++qword_AB8;
result = ObjectIdentifier_subidentifiers_uper_decode(a1, v9, &v8);
if ( result )
{
v3 = v8;
++qword_AC8;
*a2 = 2;
*((_QWORD *)a2 + 1) = v3 / 0x28;
v4 = v9[0];
*((_QWORD *)a2 + 2) = v3 % 0x28;
if ( v4 <= 0 )
{
LABEL_8:
result = v4 == 0;
++qword_AE8;
}
else
{
while ( 1 )
{
result = ObjectIdentifier_subidentifiers_uper_decode(a1, v9, &v8);
if ( !result )
break;
v5 = *a2;
++qword_AD8;
*(_QWORD *)&a2[2 * v5 + 2] = v8;
v6 = v5;
v4 = v9[0];
v7 = v6 + 1;
*a2 = v7;
if ( v4 <= 0 )
goto LABEL_8;
if ( v7 > 19 )
{
++qword_AE0;
goto LABEL_8;
}
}
++qword_AD0;
}
}
else
{
++qword_AC0;
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(__int64 a1, int *a2)
{
char result; // al
unsigned __int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // rdx
int v6; // eax
int v7; // eax
unsigned __int64 v8; // [rsp+0h] [rbp-28h] BYREF
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

++_gcov0_ObjectIdentifier_uper_decode;
ObjectIdentifier_Init(a2);
++qword_AA8;
result = func4(a1, v9);
++qword_AB0;
if ( result )
{
++qword_AB8;
result = func3(a1, v9, &v8);
if ( result )
{
v3 = v8;
++qword_AC8;
*a2 = 2;
*((_QWORD *)a2 + 1) = v3 / 0x28;
v4 = v9[0];
*((_QWORD *)a2 + 2) = v3 % 0x28;
if ( v4 <= 0 )
{
LABEL_8:
result = v4 == 0;
++qword_AE8;
}
else
{
while ( 1 )
{
result = func3(a1, v9, &v8);
if ( !result )
break;
v5 = *a2;
++qword_AD8;
*(_QWORD *)&a2[2 * v5 + 2] = v8;
v6 = v5;
v4 = v9[0];
v7 = v6 + 1;
*a2 = v7;
if ( v4 <= 0 )
goto LABEL_8;
if ( v7 > 19 )
{
++qword_AE0;
goto LABEL_8;
}
}
++qword_AD0;
}
}
else
{
++qword_AC0;
}
}
return result;
}

original_code:
flag ObjectIdentifier_uper_decode(BitStream* pBitStrm, Asn1ObjectIdentifier *pVal) {
 asn1SccUint si;
 asn1SccSint totalSize;
 ObjectIdentifier_Init(pVal);
 if (!ObjectIdentifier_uper_decode_lentg(pBitStrm, &totalSize))
  return 0;
 if (!ObjectIdentifier_subidentifiers_uper_decode(pBitStrm, &totalSize, &si))
  return 0;
 pVal->nCount = 2;
 pVal->values[0] = si / 40;
 pVal->values[1] = si % 40;
 while (totalSize > 0 && pVal->nCount < 20)
 {
  if (!ObjectIdentifier_subidentifiers_uper_decode(pBitStrm, &totalSize, &si))
   return 0;
  pVal->values[pVal->nCount] = si;
  pVal->nCount++;
 }
 return totalSize == 0;
}

canonical_original_code:
_Bool ObjectIdentifier_uper_decode(struct BitStream *pBitStrm, struct Asn1ObjectIdentifier *pVal) {
 unsigned long long si;
 long long totalSize;
 ObjectIdentifier_Init(pVal);
 if (!ObjectIdentifier_uper_decode_lentg(pBitStrm, &totalSize))
  return 0;
 if (!ObjectIdentifier_subidentifiers_uper_decode(pBitStrm, &totalSize, &si))
  return 0;
 pVal->nCount = 2;
 pVal->values[0] = si / 40;
 pVal->values[1] = si % 40;
 while (totalSize > 0 && pVal->nCount < 20)
 {
  if (!ObjectIdentifier_subidentifiers_uper_decode(pBitStrm, &totalSize, &si))
   return 0;
  pVal->values[pVal->nCount] = si;
  pVal->nCount++;
 }
 return totalSize == 0;
}

variable_types:
si
unsigned long long

variable_types:
totalSize
long long


decompiled_code:
char __fastcall RelativeOID_uper_decode(__int64 a1, int *a2)
{
char result; // al
__int64 v3; // rdx
int v4; // eax
__int64 v5; // rdx
int v6; // eax
unsigned __int64 v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

++_gcov0_RelativeOID_uper_decode;
ObjectIdentifier_Init(a2);
++qword_B08;
result = ObjectIdentifier_uper_decode_lentg(a1, v8);
++qword_B10;
if ( result )
{
v3 = v8[0];
if ( v8[0] <= 0 )
{
LABEL_8:
result = v3 == 0;
++qword_B38;
}
else
{
v4 = *a2;
while ( 1 )
{
if ( v4 > 19 )
{
++qword_B30;
goto LABEL_8;
}
result = ObjectIdentifier_subidentifiers_uper_decode(a1, v8, &v7);
if ( !result )
break;
v5 = *a2;
++qword_B28;
*(_QWORD *)&a2[2 * v5 + 2] = v7;
v6 = v5;
v3 = v8[0];
v4 = v6 + 1;
*a2 = v4;
if ( v3 <= 0 )
goto LABEL_8;
}
++qword_B20;
}
}
else
{
++qword_B18;
}
return result;
}

canonical_decompiled_code:
char __fastcall func6(__int64 a1, int *a2)
{
char result; // al
__int64 v3; // rdx
int v4; // eax
__int64 v5; // rdx
int v6; // eax
unsigned __int64 v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

++_gcov0_RelativeOID_uper_decode;
ObjectIdentifier_Init(a2);
++qword_B08;
result = func4(a1, v8);
++qword_B10;
if ( result )
{
v3 = v8[0];
if ( v8[0] <= 0 )
{
LABEL_8:
result = v3 == 0;
++qword_B38;
}
else
{
v4 = *a2;
while ( 1 )
{
if ( v4 > 19 )
{
++qword_B30;
goto LABEL_8;
}
result = func3(a1, v8, &v7);
if ( !result )
break;
v5 = *a2;
++qword_B28;
*(_QWORD *)&a2[2 * v5 + 2] = v7;
v6 = v5;
v3 = v8[0];
v4 = v6 + 1;
*a2 = v4;
if ( v3 <= 0 )
goto LABEL_8;
}
++qword_B20;
}
}
else
{
++qword_B18;
}
return result;
}

original_code:
flag RelativeOID_uper_decode(BitStream* pBitStrm, Asn1ObjectIdentifier *pVal) {
 asn1SccUint si;
 asn1SccSint totalSize;
 ObjectIdentifier_Init(pVal);
 if (!ObjectIdentifier_uper_decode_lentg(pBitStrm, &totalSize))
  return 0;
 while (totalSize > 0 && pVal->nCount < 20)
 {
  if (!ObjectIdentifier_subidentifiers_uper_decode(pBitStrm, &totalSize, &si))
   return 0;
  pVal->values[pVal->nCount] = si;
  pVal->nCount++;
 }
 return totalSize == 0;
}

canonical_original_code:
_Bool RelativeOID_uper_decode(struct BitStream *pBitStrm, struct Asn1ObjectIdentifier *pVal) {
 unsigned long long si;
 long long totalSize;
 ObjectIdentifier_Init(pVal);
 if (!ObjectIdentifier_uper_decode_lentg(pBitStrm, &totalSize))
  return 0;
 while (totalSize > 0 && pVal->nCount < 20)
 {
  if (!ObjectIdentifier_subidentifiers_uper_decode(pBitStrm, &totalSize, &si))
   return 0;
  pVal->values[pVal->nCount] = si;
  pVal->nCount++;
 }
 return totalSize == 0;
}


decompiled_code:
__int64 __fastcall RGBCOLORS_enc_dec(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_RGBCOLORS_enc_dec;
BitStream_Init(v3, &encBuff_11, 1LL);
++qword_9C8;
result = RGBCOLORS_Encode(a1, v3, a2, 1LL);
++qword_9D0;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_9D8;
BitStream_AttachBuffer(v3, &encBuff_11, 1LL);
++qword_9E0;
result = RGBCOLORS_Decode(&decodedPDU_10, v3, a2);
++qword_9E8;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_9F8;
result = RGBCOLORS_IsConstraintValid(&decodedPDU_10, a2);
++qword_A00;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_A10;
result = RGBCOLORS_Equal(a1, &decodedPDU_10);
++qword_A18;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_A20;
*a2 = 4;
}
}
else
{
++qword_A08;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_9F0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_RGBCOLORS_enc_dec;
BitStream_Init(v3, &encBuff_11, 1LL);
++qword_9C8;
result = RGBCOLORS_Encode(a1, v3, a2, 1LL);
++qword_9D0;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_9D8;
BitStream_AttachBuffer(v3, &encBuff_11, 1LL);
++qword_9E0;
result = RGBCOLORS_Decode(&decodedPDU_10, v3, a2);
++qword_9E8;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_9F8;
result = RGBCOLORS_IsConstraintValid(&decodedPDU_10, a2);
++qword_A00;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_A10;
result = RGBCOLORS_Equal(a1, &decodedPDU_10);
++qword_A18;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_A20;
*a2 = 4;
}
}
else
{
++qword_A08;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_9F0;
}
}
return result;
}

original_code:
flag RGBCOLORS_enc_dec(const RGBCOLORS* pVal, int* pErrCode)
{
    static RGBCOLORS decodedPDU;
    static byte encBuff[1];
 BitStream bitStrm;
 flag ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = RGBCOLORS_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = RGBCOLORS_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = RGBCOLORS_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = RGBCOLORS_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

canonical_original_code:
_Bool RGBCOLORS_enc_dec(enum RGBCOLORS *pVal, int *pErrCode)
{
    static enum RGBCOLORS decodedPDU;
    static unsigned char encBuff[1];
 struct BitStream bitStrm;
 _Bool ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = RGBCOLORS_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = RGBCOLORS_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = RGBCOLORS_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = RGBCOLORS_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

variable_types: enum RGBCOLORS { RGBCOLORS_red=0, green=1, blue=2 } *

variable_types:
pErrCode
int *

variable_types:
encBuff
unsigned char [1]

variable_types: struct BitStream { unsigned char *buf; long count; long currentByte; int currentBit; }


decompiled_code:
__int64 __fastcall OTHERCOLORS_enc_dec(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_OTHERCOLORS_enc_dec;
BitStream_Init(v3, &encBuff_9, 1LL);
++qword_A48;
result = OTHERCOLORS_Encode(a1, v3, a2, 1LL);
++qword_A50;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_A58;
BitStream_AttachBuffer(v3, &encBuff_9, 1LL);
++qword_A60;
result = OTHERCOLORS_Decode(&decodedPDU_8, v3, a2);
++qword_A68;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_A78;
result = OTHERCOLORS_IsConstraintValid(&decodedPDU_8, a2);
++qword_A80;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_A90;
result = OTHERCOLORS_Equal(a1, &decodedPDU_8);
++qword_A98;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_AA0;
*a2 = 4;
}
}
else
{
++qword_A88;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_A70;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_OTHERCOLORS_enc_dec;
BitStream_Init(v3, &encBuff_9, 1LL);
++qword_A48;
result = OTHERCOLORS_Encode(a1, v3, a2, 1LL);
++qword_A50;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_A58;
BitStream_AttachBuffer(v3, &encBuff_9, 1LL);
++qword_A60;
result = OTHERCOLORS_Decode(&decodedPDU_8, v3, a2);
++qword_A68;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_A78;
result = OTHERCOLORS_IsConstraintValid(&decodedPDU_8, a2);
++qword_A80;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_A90;
result = OTHERCOLORS_Equal(a1, &decodedPDU_8);
++qword_A98;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_AA0;
*a2 = 4;
}
}
else
{
++qword_A88;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_A70;
}
}
return result;
}

original_code:
flag OTHERCOLORS_enc_dec(const OTHERCOLORS* pVal, int* pErrCode)
{
    static OTHERCOLORS decodedPDU;
    static byte encBuff[1];
 BitStream bitStrm;
 flag ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = OTHERCOLORS_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = OTHERCOLORS_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = OTHERCOLORS_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = OTHERCOLORS_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

canonical_original_code:
_Bool OTHERCOLORS_enc_dec(enum OTHERCOLORS *pVal, int *pErrCode)
{
    static enum OTHERCOLORS decodedPDU;
    static unsigned char encBuff[1];
 struct BitStream bitStrm;
 _Bool ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = OTHERCOLORS_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = OTHERCOLORS_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = OTHERCOLORS_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = OTHERCOLORS_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

variable_types: enum OTHERCOLORS { OTHERCOLORS_red=0, cyan=1, magenta=2 } *


decompiled_code:
__int64 __fastcall CH2_left_enc_dec(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_CH2_left_enc_dec;
BitStream_Init(v3, &encBuff_7, 1LL);
++qword_AC8;
result = CH2_left_Encode(a1, v3, a2, 1LL);
++qword_AD0;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_AD8;
BitStream_AttachBuffer(v3, &encBuff_7, 1LL);
++qword_AE0;
result = CH2_left_Decode(&decodedPDU_6, v3, a2);
++qword_AE8;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_AF8;
result = CH2_left_IsConstraintValid(&decodedPDU_6, a2);
++qword_B00;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_B10;
result = CH2_left_Equal(a1, &decodedPDU_6);
++qword_B18;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_B20;
*a2 = 4;
}
}
else
{
++qword_B08;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_AF0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_CH2_left_enc_dec;
BitStream_Init(v3, &encBuff_7, 1LL);
++qword_AC8;
result = CH2_left_Encode(a1, v3, a2, 1LL);
++qword_AD0;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_AD8;
BitStream_AttachBuffer(v3, &encBuff_7, 1LL);
++qword_AE0;
result = CH2_left_Decode(&decodedPDU_6, v3, a2);
++qword_AE8;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_AF8;
result = CH2_left_IsConstraintValid(&decodedPDU_6, a2);
++qword_B00;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_B10;
result = CH2_left_Equal(a1, &decodedPDU_6);
++qword_B18;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_B20;
*a2 = 4;
}
}
else
{
++qword_B08;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_AF0;
}
}
return result;
}

original_code:
flag CH2_left_enc_dec(const CH2_left* pVal, int* pErrCode)
{
    static CH2_left decodedPDU;
    static byte encBuff[1];
 BitStream bitStrm;
 flag ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = CH2_left_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = CH2_left_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = CH2_left_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = CH2_left_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

canonical_original_code:
_Bool CH2_left_enc_dec(long long *pVal, int *pErrCode)
{
    static long long decodedPDU;
    static unsigned char encBuff[1];
 struct BitStream bitStrm;
 _Bool ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = CH2_left_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = CH2_left_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = CH2_left_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = CH2_left_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

variable_types:
pVal
long long *

variable_types:
decodedPDU
long long


decompiled_code:
__int64 __fastcall CH2_enc_dec(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_CH2_enc_dec;
BitStream_Init(v3, &encBuff_5, 1LL);
++qword_B48;
result = CH2_Encode(a1, v3, a2, 1LL);
++qword_B50;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_B58;
BitStream_AttachBuffer(v3, &encBuff_5, 1LL);
++qword_B60;
result = CH2_Decode(&decodedPDU_4, v3, a2);
++qword_B68;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_B78;
result = CH2_IsConstraintValid(&decodedPDU_4, a2);
++qword_B80;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_B90;
result = CH2_Equal(a1, &decodedPDU_4);
++qword_B98;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_BA0;
*a2 = 4;
}
}
else
{
++qword_B88;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_B70;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_CH2_enc_dec;
BitStream_Init(v3, &encBuff_5, 1LL);
++qword_B48;
result = CH2_Encode(a1, v3, a2, 1LL);
++qword_B50;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_B58;
BitStream_AttachBuffer(v3, &encBuff_5, 1LL);
++qword_B60;
result = CH2_Decode(&decodedPDU_4, v3, a2);
++qword_B68;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_B78;
result = CH2_IsConstraintValid(&decodedPDU_4, a2);
++qword_B80;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_B90;
result = CH2_Equal(a1, &decodedPDU_4);
++qword_B98;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_BA0;
*a2 = 4;
}
}
else
{
++qword_B88;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_B70;
}
}
return result;
}

original_code:
flag CH2_enc_dec(const CH2* pVal, int* pErrCode)
{
    static CH2 decodedPDU;
    static byte encBuff[1];
 BitStream bitStrm;
 flag ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = CH2_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = CH2_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = CH2_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = CH2_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

canonical_original_code:
_Bool CH2_enc_dec(struct CH2 *pVal, int *pErrCode)
{
    static struct CH2 decodedPDU;
    static unsigned char encBuff[1];
 struct BitStream bitStrm;
 _Bool ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = CH2_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = CH2_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = CH2_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = CH2_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

variable_types: struct CH2 { enum { CH2_NONE=0, CH2_left_PRESENT=1, center_PRESENT=2 } kind; union { long long left; enum OTHERCOLORS { OTHERCOLORS_red=0, cyan=1, magenta=2 } center; } u; } *

user_defined_types: struct CH2 { enum { CH2_NONE=0, CH2_left_PRESENT=1, center_PRESENT=2 } kind; union { long long left; enum OTHERCOLORS center; } u; }


decompiled_code:
__int64 __fastcall CH1_left_enc_dec(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_CH1_left_enc_dec;
BitStream_Init(v3, &encBuff_3, 1LL);
++qword_BC8;
result = CH1_left_Encode(a1, v3, a2, 1LL);
++qword_BD0;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_BD8;
BitStream_AttachBuffer(v3, &encBuff_3, 1LL);
++qword_BE0;
result = CH1_left_Decode(&decodedPDU_2, v3, a2);
++qword_BE8;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_BF8;
result = CH1_left_IsConstraintValid(&decodedPDU_2, a2);
++qword_C00;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_C10;
result = CH1_left_Equal(a1, &decodedPDU_2);
++qword_C18;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_C20;
*a2 = 4;
}
}
else
{
++qword_C08;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_BF0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_CH1_left_enc_dec;
BitStream_Init(v3, &encBuff_3, 1LL);
++qword_BC8;
result = CH1_left_Encode(a1, v3, a2, 1LL);
++qword_BD0;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_BD8;
BitStream_AttachBuffer(v3, &encBuff_3, 1LL);
++qword_BE0;
result = CH1_left_Decode(&decodedPDU_2, v3, a2);
++qword_BE8;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_BF8;
result = CH1_left_IsConstraintValid(&decodedPDU_2, a2);
++qword_C00;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_C10;
result = CH1_left_Equal(a1, &decodedPDU_2);
++qword_C18;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_C20;
*a2 = 4;
}
}
else
{
++qword_C08;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_BF0;
}
}
return result;
}

original_code:
flag CH1_left_enc_dec(const CH1_left* pVal, int* pErrCode)
{
    static CH1_left decodedPDU;
    static byte encBuff[1];
 BitStream bitStrm;
 flag ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = CH1_left_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = CH1_left_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = CH1_left_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = CH1_left_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

canonical_original_code:
_Bool CH1_left_enc_dec(long long *pVal, int *pErrCode)
{
    static long long decodedPDU;
    static unsigned char encBuff[1];
 struct BitStream bitStrm;
 _Bool ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = CH1_left_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = CH1_left_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = CH1_left_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = CH1_left_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}


decompiled_code:
__int64 __fastcall CH1_enc_dec(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_CH1_enc_dec;
BitStream_Init(v3, &encBuff_1, 1LL);
++qword_C48;
result = CH1_Encode(a1, v3, a2, 1LL);
++qword_C50;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_C58;
BitStream_AttachBuffer(v3, &encBuff_1, 1LL);
++qword_C60;
result = CH1_Decode(&decodedPDU_0, v3, a2);
++qword_C68;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_C78;
result = CH1_IsConstraintValid(&decodedPDU_0, a2);
++qword_C80;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_C90;
result = CH1_Equal(a1, &decodedPDU_0);
++qword_C98;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_CA0;
*a2 = 4;
}
}
else
{
++qword_C88;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_C70;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int *a2)
{
__int64 result; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_CH1_enc_dec;
BitStream_Init(v3, &encBuff_1, 1LL);
++qword_C48;
result = CH1_Encode(a1, v3, a2, 1LL);
++qword_C50;
*a2 = (unsigned __int8)result ^ 1;
if ( (_BYTE)result )
{
++qword_C58;
BitStream_AttachBuffer(v3, &encBuff_1, 1LL);
++qword_C60;
result = CH1_Decode(&decodedPDU_0, v3, a2);
++qword_C68;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_C78;
result = CH1_IsConstraintValid(&decodedPDU_0, a2);
++qword_C80;
if ( (_BYTE)result )
{
*a2 = 0;
++qword_C90;
result = CH1_Equal(a1, &decodedPDU_0);
++qword_C98;
if ( (_BYTE)result )
{
*a2 = 0;
}
else
{
++qword_CA0;
*a2 = 4;
}
}
else
{
++qword_C88;
*a2 = 3;
}
}
else
{
*a2 = 2;
++qword_C70;
}
}
return result;
}

original_code:
flag CH1_enc_dec(const CH1* pVal, int* pErrCode)
{
    static CH1 decodedPDU;
    static byte encBuff[1];
 BitStream bitStrm;
 flag ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = CH1_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = CH1_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = CH1_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = CH1_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

canonical_original_code:
_Bool CH1_enc_dec(struct CH1 *pVal, int *pErrCode)
{
    static struct CH1 decodedPDU;
    static unsigned char encBuff[1];
 struct BitStream bitStrm;
 _Bool ret;
   BitStream_Init(&bitStrm, encBuff, 1);
    ret = CH1_Encode(pVal, &bitStrm, pErrCode, 1);
    *pErrCode = ret ? 0 : 1;
    if (ret) {
        BitStream_AttachBuffer(&bitStrm, encBuff, 1);
        ret = CH1_Decode(&decodedPDU, &bitStrm, pErrCode);
        *pErrCode = ret ? 0 : 2;
        if (ret) {
            ret = CH1_IsConstraintValid(&decodedPDU, pErrCode);
            *pErrCode = ret ? 0 : 3;
            if (ret) {
                ret = CH1_Equal(pVal, &decodedPDU);
                *pErrCode = ret ? 0 : 4;
            }
        }
    }
    return ret;
}

variable_types: struct CH1 { enum { CH1_NONE=0, CH1_left_PRESENT=1, right_PRESENT=2 } kind; union { long long left; enum RGBCOLORS { RGBCOLORS_red=0, green=1, blue=2 } right; } u; } *

user_defined_types: struct CH1 { enum { CH1_NONE=0, CH1_left_PRESENT=1, right_PRESENT=2 } kind; union { long long left; enum RGBCOLORS right; } u; }


repo: ttuttle/tmips

decompiled_code:
char *__fastcall find_seg(unsigned int a1, int a2)
{
unsigned int *v2; // rdx
__int64 v3; // rcx

v2 = (unsigned int *)&segs;
v3 = 0LL;
while ( *v2 > a1 || v2[1] + *v2 - 1 < a1 || (a2 & v2[2]) != a2 )
{
v3 = (unsigned int)(v3 + 1);
v2 += 6;
if ( (_DWORD)v3 == 8 )
return 0LL;
}
return (char *)&segs + 24 * v3;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1, int a2)
{
unsigned int *v2; // rdx
__int64 v3; // rcx

v2 = (unsigned int *)&segs;
v3 = 0LL;
while ( *v2 > a1 || v2[1] + *v2 - 1 < a1 || (a2 & v2[2]) != a2 )
{
v3 = (unsigned int)(v3 + 1);
v2 += 6;
if ( (_DWORD)v3 == 8 )
return 0LL;
}
return (char *)&segs + 24 * v3;
}

original_code:
static struct segment *find_seg(uint32_t addr, int mode)
{
    unsigned i;
    for (i = 0; i < ((sizeof(segs)) / (sizeof(segs[0]))); i++) {
        if ((addr >= segs[i].base)
            && (addr <= segs[i].base + segs[i].size - 1)
            && ((mode & segs[i].flags) == mode)) {
            return &segs[i];
        }
    }
    return ((void *)0);
}

canonical_original_code:
static struct segment *find_seg(unsigned int addr, int mode)
{
    unsigned int i;
    for (i = 0; i < ((sizeof(segs)) / (sizeof(segs[0]))); i++) {
        if ((addr >= segs[i].base)
            && (addr <= segs[i].base + segs[i].size - 1)
            && ((mode & segs[i].flags) == mode)) {
            return &segs[i];
        }
    }
    return ((void *)0);
}

variable_types:
addr
unsigned int

variable_types: mode int

variable_types:
i
unsigned int

return_type: struct segment { unsigned int base; unsigned int size; int flags; char *name; } *


check

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

result = 1LL;
if ( !*(_BYTE *)(a1 + a2 + 16) )
{
result = 0LL;
if ( *(_QWORD *)(a1 + 8) )
result = (unsigned int)check() != 0;
}
return result;
}

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

result = 1LL;
if ( !*(_BYTE *)(a1 + a2 + 16) )
{
result = 0LL;
if ( *(_QWORD *)(a1 + 8) )
result = (unsigned int)func0() != 0;
}
return result;
}

original_code:
static int check(filter_t *filter, unsigned offset)
{
    return filter->allowed[offset] ||
            (filter->parent && (check(filter->parent, offset)));
}

canonical_original_code:
static int check(struct filter *filter, unsigned int offset)
{
    return filter->allowed[offset] ||
            (filter->parent && (check(filter->parent, offset)));
}

variable_types: struct filter { char *name; struct filter *parent; char allowed[-1]; } *

variable_types:
offset
unsigned int


decompiled_code:
const char **__fastcall filter_find(char *s2)
{
const char **v1; // r12
const char ***v2; // rbx

v1 = (const char **)lab1;
v2 = (const char ***)off_BE8;
do
{
if ( !strcmp(*v1, s2) )
break;
v1 = *v2++;
}
while ( v1 );
return v1;
}

canonical_decompiled_code:
const char **__fastcall func1(char *s2)
{
const char **v1; // r12
const char ***v2; // rbx

v1 = (const char **)lab1;
v2 = (const char ***)off_BE8;
do
{
if ( !strcmp(*v1, s2) )
break;
v1 = *v2++;
}
while ( v1 );
return v1;
}

original_code:
filter_t *filter_find(char *name)
{
    int i;
    for (i = 0; filters[i]; i++) {
        if (!strcmp(filters[i]->name, name)) {
            return filters[i];
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct filter *filter_find(char *name)
{
    int i;
    for (i = 0; filters[i]; i++) {
        if (!strcmp(filters[i]->name, name)) {
            return filters[i];
        }
    }
    return ((void *)0);
}

variable_types:
name
char *

variable_types: i int

return_type: struct filter { char *name; struct filter *parent; char allowed[-1]; } *


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

v2 = a2 >> 26;
if ( a2 >> 26 == 1 )
return check(a1, (HIWORD(a2) & 0x1F) + 128);
if ( v2 == 16 )
{
if ( (a2 & 0x2000000) != 0 )
result = check(a1, (a2 & 0x3F) + 192);
else
result = check(a1, ((a2 >> 21) & 0x1F) + 160);
}
else if ( v2 )
{
result = check(a1, v2);
}
else
{
result = check(a1, (a2 & 0x3F) + 64);
}
return result;
}

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

v2 = a2 >> 26;
if ( a2 >> 26 == 1 )
return func0(a1, (HIWORD(a2) & 0x1F) + 128);
if ( v2 == 16 )
{
if ( (a2 & 0x2000000) != 0 )
result = func0(a1, (a2 & 0x3F) + 192);
else
result = func0(a1, ((a2 >> 21) & 0x1F) + 160);
}
else if ( v2 )
{
result = func0(a1, v2);
}
else
{
result = func0(a1, (a2 & 0x3F) + 64);
}
return result;
}

variable_types:
ins
unsigned int

user_defined_types: struct filter { char *name; struct filter *parent; char allowed[-1]; }


decompiled_code:
_BOOL8 __fastcall filter_exc_allowed(__int64 a1, unsigned __int8 a2)
{
if ( a2 > 0x1Fu )
_assert_fail("exc_code < NUM_EXCS", "filter.c", 0xBBu, "filter_exc_allowed");
return check(a1, (unsigned int)a2 + 256);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, unsigned __int8 a2)
{
if ( a2 > 0x1Fu )
_assert_fail("exc_code < NUM_EXCS", "filter.c", 0xBBu, "filter_exc_allowed");
return func0(a1, (unsigned int)a2 + 256);
}

original_code:
int filter_exc_allowed(filter_t *filter, uint8_t exc_code)
{
    ((exc_code < NUM_EXCS) ? (void) (0) : __assert_fail ("exc_code < NUM_EXCS", "filter.c", 187, __extension__ __PRETTY_FUNCTION__));
    return check(filter, (((((0 + NUM_OPS) + NUM_FUNCTS) + NUM_REGIMMS) + NUM_COPS) + NUM_CP0_FUNCTS) + exc_code);
}

canonical_original_code:
int filter_exc_allowed(struct filter *filter, unsigned char exc_code)
{
    ((exc_code < NUM_EXCS) ? (void) (0) : __assert_fail ("exc_code < NUM_EXCS", "filter.c", 187, __extension__ __PRETTY_FUNCTION__));
    return check(filter, (((((0 + NUM_OPS) + NUM_FUNCTS) + NUM_REGIMMS) + NUM_COPS) + NUM_CP0_FUNCTS) + exc_code);
}


decompiled_code:
_BOOL8 __fastcall filter_misc(__int64 a1, int a2)
{
if ( a2 )
_assert_fail("misc >= 0 && misc < NUM_FILTER_MISCS", "filter.c", 0xC2u, "filter_misc");
return check(a1, 0x120u);
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, int a2)
{
if ( a2 )
_assert_fail("misc >= 0 && misc < NUM_FILTER_MISCS", "filter.c", 0xC2u, "filter_misc");
return func0(a1, 0x120u);
}

original_code:
int filter_misc(filter_t *filter, int misc)
{
    ((misc >= 0 && misc < NUM_FILTER_MISCS) ? (void) (0) : __assert_fail ("misc >= 0 && misc < NUM_FILTER_MISCS", "filter.c", 194, __extension__ __PRETTY_FUNCTION__));
    return check(filter, ((((((0 + NUM_OPS) + NUM_FUNCTS) + NUM_REGIMMS) + NUM_COPS) + NUM_CP0_FUNCTS) + NUM_EXCS) + misc);
}

canonical_original_code:
int filter_misc(struct filter *filter, int misc)
{
    ((misc >= 0 && misc < NUM_FILTER_MISCS) ? (void) (0) : __assert_fail ("misc >= 0 && misc < NUM_FILTER_MISCS", "filter.c", 194, __extension__ __PRETTY_FUNCTION__));
    return check(filter, ((((((0 + NUM_OPS) + NUM_FUNCTS) + NUM_REGIMMS) + NUM_COPS) + NUM_CP0_FUNCTS) + NUM_EXCS) + misc);
}

variable_types: misc int


decompiled_code:
_QWORD *mem_create()
{
_QWORD *result; // rax

result = (_QWORD *)xmalloc(8LL);
*result = 0LL;
return result;
}

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

result = (_QWORD *)xmalloc(8LL);
*result = 0LL;
return result;
}

original_code:
mem_t *mem_create(void)
{
    mem_t *m = xmalloc(sizeof(*m));
    m->regions = ((void *)0);
    return m;
}

canonical_original_code:
struct mem *mem_create()
{
    struct mem *m = xmalloc(sizeof(*m));
    m->regions = ((void *)0);
    return m;
}

variable_types: struct mem { struct mem_region { unsigned int base; struct mem_dev { unsigned int size; int (*read)(struct mem_dev *dev, unsigned int offset, unsigned int *val_out); int (*write)(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we); } *dev; struct mem_region *prev; struct mem_region *next; struct mem *mem; } *regions; } *

user_defined_types: struct mem { struct mem_region *regions; }

user_defined_types: struct mem_region { unsigned int base; struct mem_dev *dev; struct mem_region *prev; struct mem_region *next; struct mem *mem; }


original_code:
mem_region_t *mem_map(mem_t *m, uint32_t base, mem_dev_t *d)
{
    mem_region_t *r;
    r = xmalloc(sizeof(*r));
    r->base = base;
    r->dev = d;
    r->mem = m;
    r->prev = ((void *)0);
    r->next = m->regions;
    m->regions = r;
    __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_INFO, "Memory mapped at %08x-%08x (%08x)\n", base, base + d->size, d->size);
    return r;
}

canonical_original_code:
struct mem_region *mem_map(struct mem *m, unsigned int base, struct mem_dev *d)
{
    struct mem_region *r;
    r = xmalloc(sizeof(*r));
    r->base = base;
    r->dev = d;
    r->mem = m;
    r->prev = ((void *)0);
    r->next = m->regions;
    m->regions = r;
    __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_INFO, "Memory mapped at %08x-%08x (%08x)\n", base, base + d->size, d->size);
    return r;
}

variable_types:
m
struct mem *

variable_types:
base
unsigned int

variable_types:
d
struct mem_dev *

variable_types: struct mem_region { unsigned int base; struct mem_dev { unsigned int size; int (*read)(struct mem_dev *dev, unsigned int offset, unsigned int *val_out); int (*write)(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we); } *dev; struct mem_region *prev; struct mem_region *next; struct mem { struct mem_region *regions; } *mem; } *


original_code:
void mem_unmap(mem_t *m, mem_region_t *r)
{
    ((r->mem == m) ? (void) (0) : __assert_fail ("r->mem == m", "mem.c", 64, __extension__ __PRETTY_FUNCTION__));
    __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_INFO, "Memory unmapped at %08x-%08x (%08x)\n", r->base, r->base + r->dev->size, r->dev->size);
    if (r->prev) {
        r->prev->next = r->next;
    } else {
        m->regions = r->next;
    }
    if (r->next) {
        r->next->prev = r->prev;
    }
    r->mem = ((void *)0);
    free(r);
}

canonical_original_code:
void mem_unmap(struct mem *m, struct mem_region *r)
{
    ((r->mem == m) ? (void) (0) : __assert_fail ("r->mem == m", "mem.c", 64, __extension__ __PRETTY_FUNCTION__));
    __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_INFO, "Memory unmapped at %08x-%08x (%08x)\n", r->base, r->base + r->dev->size, r->dev->size);
    if (r->prev) {
        r->prev->next = r->next;
    } else {
        m->regions = r->next;
    }
    if (r->next) {
        r->next->prev = r->prev;
    }
    r->mem = ((void *)0);
    free(r);
}

variable_types:
r
struct mem_region *

user_defined_types: struct mem_dev { unsigned int size; int (*read)(struct mem_dev *dev, unsigned int offset, unsigned int *val_out); int (*write)(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we); }


decompiled_code:
void __fastcall mem_destroy(void *ptr)
{
unsigned int *i; // rsi

for ( i = *(unsigned int **)ptr; *(_QWORD *)ptr; i = *(unsigned int **)ptr )
mem_unmap(ptr, i);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
unsigned int *i; // rsi

for ( i = *(unsigned int **)ptr; *(_QWORD *)ptr; i = *(unsigned int **)ptr )
func3(ptr, i);
free(ptr);
}

original_code:
void mem_destroy(mem_t *m)
{
    while (m->regions) {
        mem_unmap(m, m->regions);
    }
    free(m);
}

canonical_original_code:
void mem_destroy(struct mem *m)
{
    while (m->regions) {
        mem_unmap(m, m->regions);
    }
    free(m);
}


decompiled_code:
__int64 __fastcall mem_read(__int64 *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // rbx

if ( (a2 & 3) != 0 )
_assert_fail("!(addr & 0x3)", "mem.c", 0x55u, "mem_read");
v4 = find_region_isra_0(*a1, a2);
v5 = v4;
if ( v4 )
{
if ( *(_QWORD *)(*(_QWORD *)(v4 + 8) + 8LL) )
{
_debug_printf(4LL, 5LL, "Reading %08x\n", a2);
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(v5 + 8) + 8LL))(
*(_QWORD *)(v5 + 8),
a2 - *(_DWORD *)v5,
a3);
}
_debug_printf(4LL, 4LL, "Attempt to read write-only memory (!) at %08x\n", a2);
}
else
{
_debug_printf(4LL, 4LL, "Attempt to read unmapped memory at %08x\n", a2);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // rbx

if ( (a2 & 3) != 0 )
_assert_fail("!(addr & 0x3)", "mem.c", 0x55u, "mem_read");
v4 = func0(*a1, a2);
v5 = v4;
if ( v4 )
{
if ( *(_QWORD *)(*(_QWORD *)(v4 + 8) + 8LL) )
{
_debug_printf(4LL, 5LL, "Reading %08x\n", a2);
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(v5 + 8) + 8LL))(
*(_QWORD *)(v5 + 8),
a2 - *(_DWORD *)v5,
a3);
}
_debug_printf(4LL, 4LL, "Attempt to read write-only memory (!) at %08x\n", a2);
}
else
{
_debug_printf(4LL, 4LL, "Attempt to read unmapped memory at %08x\n", a2);
}
return 1LL;
}

original_code:
int mem_read(mem_t *m, uint32_t addr, uint32_t *val_out)
{
    mem_region_t *r;
    ((!(addr & 0x3)) ? (void) (0) : __assert_fail ("!(addr & 0x3)", "mem.c", 85, __extension__ __PRETTY_FUNCTION__));
    r = find_region(m, addr);
    if (!r) {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_DETAIL, "Attempt to read unmapped memory at %08x\n", addr);
        return 1;
    } else if (r->dev->read) {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_TRACE, "Reading %08x\n", addr);
        return (r->dev->read)(r->dev, addr - r->base, val_out);
    } else {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_DETAIL, "Attempt to read write-only memory (!) at %08x\n", addr);
        return 1;
    }
}

canonical_original_code:
int mem_read(struct mem *m, unsigned int addr, unsigned int *val_out)
{
    struct mem_region *r;
    ((!(addr & 0x3)) ? (void) (0) : __assert_fail ("!(addr & 0x3)", "mem.c", 85, __extension__ __PRETTY_FUNCTION__));
    r = find_region(m, addr);
    if (!r) {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_DETAIL, "Attempt to read unmapped memory at %08x\n", addr);
        return 1;
    } else if (r->dev->read) {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_TRACE, "Reading %08x\n", addr);
        return (r->dev->read)(r->dev, addr - r->base, val_out);
    } else {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_DETAIL, "Attempt to read write-only memory (!) at %08x\n", addr);
        return 1;
    }
}


decompiled_code:
__int64 __fastcall mem_write(__int64 *a1, unsigned int a2, unsigned int a3, unsigned __int8 a4)
{
unsigned int v4; // er14
__int64 v6; // rax
__int64 v7; // rbx

if ( (a2 & 3) != 0 )
_assert_fail("!(addr & 0x3)", "mem.c", 0x6Au, "mem_write");
v4 = a4;
if ( (a4 & 0xF0) != 0 )
_assert_fail("!(we & ~0xF)", "mem.c", 0x6Bu, "mem_write");
v6 = find_region_isra_0(*a1, a2);
v7 = v6;
if ( v6 )
{
if ( *(_QWORD *)(*(_QWORD *)(v6 + 8) + 16LL) )
{
_debug_printf(4LL, 5LL, "Writing %08x (val=%08x, we=%01x)\n", a2, a3, v4);
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(*(_QWORD *)(v7 + 8) + 16LL))(
*(_QWORD *)(v7 + 8),
a2 - *(_DWORD *)v7,
a3,
v4);
}
_debug_printf(4LL, 4LL, "Attempt to write to read-only memory at %08x (val=%08x, we=%01x)\n", a2, a3, v4);
}
else
{
_debug_printf(4LL, 4LL, "Attempt to write to unmapped memory at %08x (val=%08x, we=%01x)\n", a2, a3, v4);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, unsigned int a2, unsigned int a3, unsigned __int8 a4)
{
unsigned int v4; // er14
__int64 v6; // rax
__int64 v7; // rbx

if ( (a2 & 3) != 0 )
_assert_fail("!(addr & 0x3)", "mem.c", 0x6Au, "mem_write");
v4 = a4;
if ( (a4 & 0xF0) != 0 )
_assert_fail("!(we & ~0xF)", "mem.c", 0x6Bu, "mem_write");
v6 = func0(*a1, a2);
v7 = v6;
if ( v6 )
{
if ( *(_QWORD *)(*(_QWORD *)(v6 + 8) + 16LL) )
{
_debug_printf(4LL, 5LL, "Writing %08x (val=%08x, we=%01x)\n", a2, a3, v4);
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(*(_QWORD *)(v7 + 8) + 16LL))(
*(_QWORD *)(v7 + 8),
a2 - *(_DWORD *)v7,
a3,
v4);
}
_debug_printf(4LL, 4LL, "Attempt to write to read-only memory at %08x (val=%08x, we=%01x)\n", a2, a3, v4);
}
else
{
_debug_printf(4LL, 4LL, "Attempt to write to unmapped memory at %08x (val=%08x, we=%01x)\n", a2, a3, v4);
}
return 1LL;
}

original_code:
int mem_write(mem_t *m, uint32_t addr, uint32_t val, uint8_t we)
{
    mem_region_t *r;
    ((!(addr & 0x3)) ? (void) (0) : __assert_fail ("!(addr & 0x3)", "mem.c", 106, __extension__ __PRETTY_FUNCTION__));
    ((!(we & ~0xF)) ? (void) (0) : __assert_fail ("!(we & ~0xF)", "mem.c", 107, __extension__ __PRETTY_FUNCTION__));
    r = find_region(m, addr);
    if (!r) {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_DETAIL, "Attempt to write to unmapped memory at %08x " "(val=%08x, we=%01x)\n", addr, val, we);
        return 1;
    } else if (r->dev->write) {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_TRACE, "Writing %08x (val=%08x, we=%01x)\n", addr, val, we);
        return (r->dev->write)(r->dev, addr - r->base, val, we);
    } else {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_DETAIL, "Attempt to write to read-only memory at %08x " "(val=%08x, we=%01x)\n", addr, val, we);
        return 1;
    }
}

canonical_original_code:
int mem_write(struct mem *m, unsigned int addr, unsigned int val, unsigned char we)
{
    struct mem_region *r;
    ((!(addr & 0x3)) ? (void) (0) : __assert_fail ("!(addr & 0x3)", "mem.c", 106, __extension__ __PRETTY_FUNCTION__));
    ((!(we & ~0xF)) ? (void) (0) : __assert_fail ("!(we & ~0xF)", "mem.c", 107, __extension__ __PRETTY_FUNCTION__));
    r = find_region(m, addr);
    if (!r) {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_DETAIL, "Attempt to write to unmapped memory at %08x " "(val=%08x, we=%01x)\n", addr, val, we);
        return 1;
    } else if (r->dev->write) {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_TRACE, "Writing %08x (val=%08x, we=%01x)\n", addr, val, we);
        return (r->dev->write)(r->dev, addr - r->base, val, we);
    } else {
        __debug_printf(DEBUG_MODULE_MEM, DEBUG_LEVEL_DETAIL, "Attempt to write to read-only memory at %08x " "(val=%08x, we=%01x)\n", addr, val, we);
        return 1;
    }
}

variable_types:
val
unsigned int

variable_types:
we
unsigned char


decompiled_code:
__int64 __fastcall ram_read(__int64 a1, unsigned int a2, _DWORD *a3)
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, _DWORD *a3)
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + a2);
return 0LL;
}

original_code:
static int ram_read(mem_dev_t *dev, uint32_t offset, uint32_t *val_out)
{
    ram_dev_t *ram = (ram_dev_t *)dev;
    uint32_t *w;
    w = (uint32_t *)((uint8_t *)ram->data + offset);
    *val_out = *w;
    return 0;
}

canonical_original_code:
static int ram_read(struct mem_dev *dev, unsigned int offset, unsigned int *val_out)
{
    struct ram_dev *ram = (ram_dev_t *)dev;
    unsigned int *w;
    w = (unsigned int *)((unsigned char *)ram->data + offset);
    *val_out = *w;
    return 0;
}

variable_types: struct mem_dev { unsigned int size; int (*read)(struct mem_dev *dev, unsigned int offset, unsigned int *val_out); int (*write)(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we); } *

variable_types: struct ram_dev { struct mem_dev { unsigned int size; int (*read)(struct mem_dev *dev, unsigned int offset, unsigned int *val_out); int (*write)(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we); } dev; void *data; } *

variable_types:
w
unsigned int *

user_defined_types: struct ram_dev { struct mem_dev dev; void *data; }


decompiled_code:
__int64 __fastcall we_to_mask(int a1)
{
__int64 result; // rax
unsigned int v2; // edx
unsigned int v3; // edx

result = (a1 << 28 >> 31) & 0xFF000000;
if ( (a1 & 4) != 0 )
result = (a1 << 28 >> 31) & 0xFF000000 | 0xFF0000;
v2 = result;
BYTE1(v2) = -1;
if ( (a1 & 2) != 0 )
result = v2;
v3 = result;
LOBYTE(v3) = -1;
if ( (a1 & 1) != 0 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
unsigned int v2; // edx
unsigned int v3; // edx

result = (a1 << 28 >> 31) & 0xFF000000;
if ( (a1 & 4) != 0 )
result = (a1 << 28 >> 31) & 0xFF000000 | 0xFF0000;
v2 = result;
BYTE1(v2) = -1;
if ( (a1 & 2) != 0 )
result = v2;
v3 = result;
LOBYTE(v3) = -1;
if ( (a1 & 1) != 0 )
result = v3;
return result;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall ram_write(__int64 a1, __int64 a2, int a3, unsigned __int8 a4)
{
int v5; // eax
int *v6; // rcx
int v7; // esi
__int64 result; // rax

v5 = we_to_mask(a4);
v7 = *v6 ^ v5 & (*v6 ^ a3);
result = 0LL;
*v6 = v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3, unsigned __int8 a4)
{
int v5; // eax
int *v6; // rcx
int v7; // esi
__int64 result; // rax

v5 = func1(a4);
v7 = *v6 ^ v5 & (*v6 ^ a3);
result = 0LL;
*v6 = v7;
return result;
}

original_code:
static int ram_write(mem_dev_t *dev, uint32_t offset, uint32_t val, uint8_t we)
{
    ram_dev_t *ram = (ram_dev_t *)dev;
    uint32_t *w;
    uint32_t mask;
    w = (uint32_t *)((uint8_t *)ram->data + offset);
    mask = we_to_mask(we);
    *w = (*w & ~mask) | (val & mask);
    return 0;
}

canonical_original_code:
static int ram_write(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we)
{
    struct ram_dev *ram = (ram_dev_t *)dev;
    unsigned int *w;
    unsigned int mask;
    w = (unsigned int *)((unsigned char *)ram->data + offset);
    mask = we_to_mask(we);
    *w = (*w & ~mask) | (val & mask);
    return 0;
}

variable_types:
mask
unsigned int


decompiled_code:
__int64 __fastcall ram_create(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // r12
_DWORD *v3; // rax
_DWORD *v4; // rdx

if ( (a1 & 3) != 0 )
_assert_fail("!(size & 0x3)", "ram.c", 0x1Bu, "ram_create");
_debug_printf(6LL, 3LL, "Creating RAM (size=%08x)\n", a1);
v1 = xmalloc(32LL);
*(_DWORD *)v1 = a1;
v2 = v1;
*(_QWORD *)(v1 + 8) = ram_read;
*(_QWORD *)(v1 + 16) = ram_write;
v3 = (_DWORD *)xmalloc(a1);
*(_QWORD *)(v2 + 24) = v3;
if ( a1 >> 2 )
{
v4 = &v3[a1 >> 2];
do
*v3++ = -559038737;
while ( v3 != v4 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // r12
_DWORD *v3; // rax
_DWORD *v4; // rdx

if ( (a1 & 3) != 0 )
_assert_fail("!(size & 0x3)", "ram.c", 0x1Bu, "ram_create");
_debug_printf(6LL, 3LL, "Creating RAM (size=%08x)\n", a1);
v1 = xmalloc(32LL);
*(_DWORD *)v1 = a1;
v2 = v1;
*(_QWORD *)(v1 + 8) = ram_read;
*(_QWORD *)(v1 + 16) = ram_write;
v3 = (_DWORD *)xmalloc(a1);
*(_QWORD *)(v2 + 24) = v3;
if ( a1 >> 2 )
{
v4 = &v3[a1 >> 2];
do
*v3++ = -559038737;
while ( v3 != v4 );
}
return v2;
}

original_code:
mem_dev_t *ram_create(uint32_t size)
{
    ram_dev_t *d;
    uint32_t i, *p;
    ((!(size & 0x3)) ? (void) (0) : __assert_fail ("!(size & 0x3)", "ram.c", 27, __extension__ __PRETTY_FUNCTION__));
    __debug_printf(DEBUG_MODULE_RAM, DEBUG_LEVEL_INFO, "Creating RAM (size=%08x)\n", size);
    d = xmalloc(sizeof(*d));
    d->dev.size = size;
    d->dev.read = &ram_read;
    d->dev.write = &ram_write;
    d->data = xmalloc(size);
    p = (uint32_t *)d->data;
    for (i = 0; i < size / 4; i++) {
     p[i] = 0xDEADBEEF;
    }
    return (mem_dev_t *)d;
}

canonical_original_code:
struct mem_dev *ram_create(unsigned int size)
{
    struct ram_dev *d;
    unsigned int i; unsigned int *p;
    ((!(size & 0x3)) ? (void) (0) : __assert_fail ("!(size & 0x3)", "ram.c", 27, __extension__ __PRETTY_FUNCTION__));
    __debug_printf(DEBUG_MODULE_RAM, DEBUG_LEVEL_INFO, "Creating RAM (size=%08x)\n", size);
    d = xmalloc(sizeof(*d));
    d->dev.size = size;
    d->dev.read = &ram_read;
    d->dev.write = &ram_write;
    d->data = xmalloc(size);
    p = (unsigned int *)d->data;
    for (i = 0; i < size / 4; i++) {
     p[i] = 0xDEADBEEF;
    }
    return (struct mem_dev *)d;
}

variable_types:
size
unsigned int

variable_types:
i
unsigned int

variable_types:
p
unsigned int *

return_type: struct mem_dev { unsigned int size; int (*read)(struct mem_dev *dev, unsigned int offset, unsigned int *val_out); int (*write)(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we); } *


decompiled_code:
void __fastcall ram_destroy(void *ptr)
{
if ( *((_QWORD *)ptr + 1) )
_assert_fail("ram->dev.read == &ram_read", "ram.c", 0x30u, "ram_destroy");
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( *((_QWORD *)ptr + 1) )
_assert_fail("ram->dev.read == &ram_read", "ram.c", 0x30u, "ram_destroy");
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void ram_destroy(mem_dev_t *dev)
{
    ram_dev_t *ram = (ram_dev_t *)dev;
    ((ram->dev.read == &ram_read) ? (void) (0) : __assert_fail ("ram->dev.read == &ram_read", "ram.c", 48, __extension__ __PRETTY_FUNCTION__));
    free(ram->data);
    free(ram);
}

canonical_original_code:
void ram_destroy(struct mem_dev *dev)
{
    struct ram_dev *ram = (ram_dev_t *)dev;
    ((ram->dev.read == &ram_read) ? (void) (0) : __assert_fail ("ram->dev.read == &ram_read", "ram.c", 48, __extension__ __PRETTY_FUNCTION__));
    free(ram->data);
    free(ram);
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
_debug_printf(8LL, 0LL, "xmalloc: malloc(%li) returned NULL\n", a1);
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
_debug_printf(8LL, 0LL, "xmalloc: malloc(%li) returned NULL\n", a1);
abort();
}
return result;
}

original_code:
void *xmalloc(size_t size) {
    void *p = malloc(size);
    if (!p) {
        __debug_printf(DEBUG_MODULE_UTIL, DEBUG_LEVEL_FATAL, "xmalloc: malloc(%li) returned NULL\n", size);
        abort();
    }
    return p;
}

canonical_original_code:
void *xmalloc(unsigned long size) {
    void *p = malloc(size);
    if (!p) {
        __debug_printf(DEBUG_MODULE_UTIL, DEBUG_LEVEL_FATAL, "xmalloc: malloc(%li) returned NULL\n", size);
        abort();
    }
    return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 __fastcall serial_write(__int64 a1, int a2, char a3, char a4)
{
int v5; // edi
int v6; // eax
int *v7; // rax
char *v8; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( a2 )
_assert_fail("offset == 0", "serial.c", 0x49u, "serial_write");
if ( (a4 & 1) == 0 )
return 0LL;
v5 = *(_DWORD *)(a1 + 28);
buf[0] = a3;
v6 = write(v5, buf, 1uLL);
if ( v6 )
{
if ( v6 < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
_debug_printf(7LL, 1LL, "serial_write: %s\n", v8);
}
return 0LL;
}
_debug_printf(7LL, 1LL, "%s", "serial_write: short write\n");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, char a3, char a4)
{
int v5; // edi
int v6; // eax
int *v7; // rax
char *v8; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( a2 )
_assert_fail("offset == 0", "serial.c", 0x49u, "serial_write");
if ( (a4 & 1) == 0 )
return 0LL;
v5 = *(_DWORD *)(a1 + 28);
buf[0] = a3;
v6 = write(v5, buf, 1uLL);
if ( v6 )
{
if ( v6 < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
_debug_printf(7LL, 1LL, "serial_write: %s\n", v8);
}
return 0LL;
}
_debug_printf(7LL, 1LL, "%s", "serial_write: short write\n");
return 0LL;
}

original_code:
static int serial_write(mem_dev_t *dev, uint32_t offset,
                        uint32_t val, uint8_t we)
{
    serial_dev_t *ser = (serial_dev_t *)dev;
    char c;
    int ret;
    ((offset == 0) ? (void) (0) : __assert_fail ("offset == 0", "serial.c", 73, __extension__ __PRETTY_FUNCTION__));
    if (!(we & 1)) {
        return 0;
    }
    c = val & 0xFF;
    ret = write(ser->outfd, &c, 1);
    if (ret == 0) {
        __debug_printf(DEBUG_MODULE_SERIAL, DEBUG_LEVEL_ERROR, "%s", "serial_write: short write\n");
    } else if (ret < 0) {
        __debug_printf(DEBUG_MODULE_SERIAL, DEBUG_LEVEL_ERROR, "serial_write: %s\n", strerror((*__errno_location ())));
    }
    return 0;
}

canonical_original_code:
static int serial_write(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we)
{
    struct serial_dev *ser = (serial_dev_t *)dev;
    char c;
    int ret;
    ((offset == 0) ? (void) (0) : __assert_fail ("offset == 0", "serial.c", 73, __extension__ __PRETTY_FUNCTION__));
    if (!(we & 1)) {
        return 0;
    }
    c = val & 0xFF;
    ret = write(ser->outfd, &c, 1);
    if (ret == 0) {
        __debug_printf(DEBUG_MODULE_SERIAL, DEBUG_LEVEL_ERROR, "%s", "serial_write: short write\n");
    } else if (ret < 0) {
        __debug_printf(DEBUG_MODULE_SERIAL, DEBUG_LEVEL_ERROR, "serial_write: %s\n", strerror((*__errno_location ())));
    }
    return 0;
}

variable_types:
offset
unsigned int

variable_types: struct serial_dev { struct mem_dev { unsigned int size; int (*read)(struct mem_dev *dev, unsigned int offset, unsigned int *val_out); int (*write)(struct mem_dev *dev, unsigned int offset, unsigned int val, unsigned char we); } dev; int infd; int outfd; } *

variable_types: c char

variable_types: ret int

user_defined_types: struct serial_dev { struct mem_dev dev; int infd; int outfd; }


decompiled_code:
__int64 __fastcall serial_read(__int64 a1, int a2, _DWORD *a3)
{
int v3; // ebx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( a2 )
_assert_fail("offset == 0", "serial.c", 0x36u, "serial_read");
v3 = 0;
if ( (int)read(*(_DWORD *)(a1 + 24), buf, 1uLL) > 0 )
{
v3 = buf[0];
BYTE1(v3) = (buf[0] >> 7) | 1;
}
*a3 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, _DWORD *a3)
{
int v3; // ebx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( a2 )
_assert_fail("offset == 0", "serial.c", 0x36u, "serial_read");
v3 = 0;
if ( (int)read(*(_DWORD *)(a1 + 24), buf, 1uLL) > 0 )
{
v3 = buf[0];
BYTE1(v3) = (buf[0] >> 7) | 1;
}
*a3 = v3;
return 0LL;
}

original_code:
static int serial_read(mem_dev_t *dev, uint32_t offset, uint32_t *val_out)
{
    serial_dev_t *ser = (serial_dev_t *)dev;
    char c;
    int ret;
    ((offset == 0) ? (void) (0) : __assert_fail ("offset == 0", "serial.c", 54, __extension__ __PRETTY_FUNCTION__));
    ret = read(ser->infd, &c, 1);
    if (ret > 0) {
        *val_out = 0x100 | c;
    } else {
        *val_out = 0;
    }
    return 0;
}

canonical_original_code:
static int serial_read(struct mem_dev *dev, unsigned int offset, unsigned int *val_out)
{
    struct serial_dev *ser = (serial_dev_t *)dev;
    char c;
    int ret;
    ((offset == 0) ? (void) (0) : __assert_fail ("offset == 0", "serial.c", 54, __extension__ __PRETTY_FUNCTION__));
    ret = read(ser->infd, &c, 1);
    if (ret > 0) {
        *val_out = 0x100 | c;
    } else {
        *val_out = 0;
    }
    return 0;
}


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

result = xmalloc(32LL);
*(_DWORD *)result = 4;
*(_QWORD *)(result + 8) = serial_read;
*(_QWORD *)(result + 16) = serial_write;
*(_DWORD *)(result + 24) = a1;
*(_DWORD *)(result + 28) = a2;
return result;
}

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

result = xmalloc(32LL);
*(_DWORD *)result = 4;
*(_QWORD *)(result + 8) = serial_read;
*(_QWORD *)(result + 16) = serial_write;
*(_DWORD *)(result + 24) = a1;
*(_DWORD *)(result + 28) = a2;
return result;
}

original_code:
mem_dev_t *serial_create(int infd, int outfd)
{
    serial_dev_t *ser;
    ser = xmalloc(sizeof(*ser));
    ser->dev.size = 0x4;
    ser->dev.read = &serial_read;
    ser->dev.write = &serial_write;
    ser->infd = infd;
    ser->outfd = outfd;
    return (mem_dev_t *)ser;
}

canonical_original_code:
struct mem_dev *serial_create(int infd, int outfd)
{
    struct serial_dev *ser;
    ser = xmalloc(sizeof(*ser));
    ser->dev.size = 0x4;
    ser->dev.read = &serial_read;
    ser->dev.write = &serial_write;
    ser->infd = infd;
    ser->outfd = outfd;
    return (struct mem_dev *)ser;
}

variable_types: infd int

variable_types: outfd int


decompiled_code:
void __fastcall serial_destroy(void *ptr)
{
int v2; // edi

close(*((_DWORD *)ptr + 6));
v2 = *((_DWORD *)ptr + 7);
if ( v2 != *((_DWORD *)ptr + 6) )
close(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
int v2; // edi

close(*((_DWORD *)ptr + 6));
v2 = *((_DWORD *)ptr + 7);
if ( v2 != *((_DWORD *)ptr + 6) )
close(v2);
free(ptr);
}

original_code:
void serial_destroy(mem_dev_t *dev)
{
    serial_dev_t *ser = (serial_dev_t *)dev;
    close(ser->infd);
    if (ser->outfd != ser->infd) {
        close(ser->outfd);
    }
    free(ser);
}

canonical_original_code:
void serial_destroy(struct mem_dev *dev)
{
    struct serial_dev *ser = (serial_dev_t *)dev;
    close(ser->infd);
    if (ser->outfd != ser->infd) {
        close(ser->outfd);
    }
    free(ser);
}


decompiled_code:
char *__fastcall debug_set_level(unsigned int a1)
{
char *result; // rax

if ( a1 > 5 )
_assert_fail("level < NUM_DEBUG_LEVELS", "debug.c", 0x12u, "debug_set_level");
result = (char *)&max_level;
do
{
*(_DWORD *)result = a1;
result += 4;
}
while ( result != "debug.c" );
return result;
}

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

if ( a1 > 5 )
_assert_fail("level < NUM_DEBUG_LEVELS", "debug.c", 0x12u, "debug_set_level");
result = (char *)&max_level;
do
{
*(_DWORD *)result = a1;
result += 4;
}
while ( result != "debug.c" );
return result;
}

original_code:
void debug_set_level(debug_level_t level)
{
    int i;
    ((level < NUM_DEBUG_LEVELS) ? (void) (0) : __assert_fail ("level < NUM_DEBUG_LEVELS", "debug.c", 18, __extension__ __PRETTY_FUNCTION__));
    for (i = 0; i < NUM_DEBUG_MODULES; i++) {
        max_level[i] = level;
    }
}

canonical_original_code:
void debug_set_level(enum debug_level_t level)
{
    int i;
    ((level < NUM_DEBUG_LEVELS) ? (void) (0) : __assert_fail ("level < NUM_DEBUG_LEVELS", "debug.c", 18, __extension__ __PRETTY_FUNCTION__));
    for (i = 0; i < NUM_DEBUG_MODULES; i++) {
        max_level[i] = level;
    }
}

variable_types: enum debug_level_t { DEBUG_LEVEL_FATAL=0, DEBUG_LEVEL_ERROR=1, DEBUG_LEVEL_WARNING=2, DEBUG_LEVEL_INFO=3, DEBUG_LEVEL_DETAIL=4, DEBUG_LEVEL_TRACE=5, NUM_DEBUG_LEVELS=6 }

variable_types: i int


decompiled_code:
char *debug_init()
{
return debug_set_level(3u);
}

canonical_decompiled_code:
char *func1()
{
return func0(3u);
}

original_code:
void debug_init(void)
{
    debug_set_level(DEBUG_LEVEL_INFO);
}

canonical_original_code:
void debug_init()
{
    debug_set_level(DEBUG_LEVEL_INFO);
}


decompiled_code:
void __fastcall debug_set_module_level(unsigned int a1, unsigned int a2)
{
if ( a1 > 9 )
_assert_fail("module < NUM_DEBUG_MODULES", "debug.c", 0x1Bu, "debug_set_module_level");
if ( a2 > 5 )
_assert_fail("level < NUM_DEBUG_LEVELS", "debug.c", 0x1Cu, "debug_set_module_level");
max_level[a1] = a2;
}

canonical_decompiled_code:
void __fastcall func2(unsigned int a1, unsigned int a2)
{
if ( a1 > 9 )
_assert_fail("module < NUM_DEBUG_MODULES", "debug.c", 0x1Bu, "debug_set_module_level");
if ( a2 > 5 )
_assert_fail("level < NUM_DEBUG_LEVELS", "debug.c", 0x1Cu, "debug_set_module_level");
max_level[a1] = a2;
}

original_code:
void debug_set_module_level(debug_module_t module, debug_level_t level)
{
    ((module < NUM_DEBUG_MODULES) ? (void) (0) : __assert_fail ("module < NUM_DEBUG_MODULES", "debug.c", 27, __extension__ __PRETTY_FUNCTION__));
    ((level < NUM_DEBUG_LEVELS) ? (void) (0) : __assert_fail ("level < NUM_DEBUG_LEVELS", "debug.c", 28, __extension__ __PRETTY_FUNCTION__));
    max_level[module] = level;
}

canonical_original_code:
void debug_set_module_level(enum debug_module_t module, enum debug_level_t level)
{
    ((module < NUM_DEBUG_MODULES) ? (void) (0) : __assert_fail ("module < NUM_DEBUG_MODULES", "debug.c", 27, __extension__ __PRETTY_FUNCTION__));
    ((level < NUM_DEBUG_LEVELS) ? (void) (0) : __assert_fail ("level < NUM_DEBUG_LEVELS", "debug.c", 28, __extension__ __PRETTY_FUNCTION__));
    max_level[module] = level;
}

variable_types: enum debug_module_t { DEBUG_MODULE_CONFIG=0, DEBUG_MODULE_CORE=1, DEBUG_MODULE_EXC=2, DEBUG_MODULE_MAIN=3, DEBUG_MODULE_MEM=4, DEBUG_MODULE_READMEMH=5, DEBUG_MODULE_RAM=6, DEBUG_MODULE_SERIAL=7, DEBUG_MODULE_UTIL=8, DEBUG_MODULE_VM=9, NUM_DEBUG_MODULES=10 }

user_defined_types: enum debug_level_t { DEBUG_LEVEL_FATAL=0, DEBUG_LEVEL_ERROR=1, DEBUG_LEVEL_WARNING=2, DEBUG_LEVEL_INFO=3, DEBUG_LEVEL_DETAIL=4, DEBUG_LEVEL_TRACE=5, NUM_DEBUG_LEVELS=6 }


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return printf(
"Usage: %s <options>\n"
"\n"
" --region|-r <base> <size> <file>\n"
" Maps RAM at the specified base address and size, and loads the\n"
" specified readmemh-format file at that address.\n"
"\n"
" --pc|-p <addr>\n"
" Sets the initial value of the program counter.\n"
"\n"
" --dump|-d <file>\n"
" Dumps the final state of the machine's registers to the specified\n"
" file. (If unspecified, the state is dumped to standard output.)\n"
"\n"
" --console|-c <addr>\n"
" Maps a serial console (connected to stdio) at the specified address.\n"
"\n"
" --filter|-f <filter>\n"
" Sets a filter to allow only instructions required for a certain lab.\n"
" Valid values of filter are: lab1, lab2, lab3\n"
"\n"
" --step|-s\n"
" Pause and dump registers after each instruction executes.\n"
"\n"
" --help|-h\n"
" Shows this help screen.\n"
"\n"
" --quiet|-q\n"
" Decreases the verbosity of the program's output.\n"
"\n"
" --verbose|-v\n"
" Increases the verbosity of the program's output.\n"
"\n"
" --version|-V\n"
" Prints the program version.\n"
"\n",
a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf(
"Usage: %s <options>\n"
"\n"
" --region|-r <base> <size> <file>\n"
" Maps RAM at the specified base address and size, and loads the\n"
" specified readmemh-format file at that address.\n"
"\n"
" --pc|-p <addr>\n"
" Sets the initial value of the program counter.\n"
"\n"
" --dump|-d <file>\n"
" Dumps the final state of the machine's registers to the specified\n"
" file. (If unspecified, the state is dumped to standard output.)\n"
"\n"
" --console|-c <addr>\n"
" Maps a serial console (connected to stdio) at the specified address.\n"
"\n"
" --filter|-f <filter>\n"
" Sets a filter to allow only instructions required for a certain lab.\n"
" Valid values of filter are: lab1, lab2, lab3\n"
"\n"
" --step|-s\n"
" Pause and dump registers after each instruction executes.\n"
"\n"
" --help|-h\n"
" Shows this help screen.\n"
"\n"
" --quiet|-q\n"
" Decreases the verbosity of the program's output.\n"
"\n"
" --verbose|-v\n"
" Increases the verbosity of the program's output.\n"
"\n"
" --version|-V\n"
" Prints the program version.\n"
"\n",
a1);
}

original_code:
static void usage(char *progn)
{
    printf(
        "Usage: %s <options>\n"
        "\n"
        "    --region|-r <base> <size> <file>\n"
        "        Maps RAM at the specified base address and size, and loads the\n"
        "        specified readmemh-format file at that address.\n"
        "\n"
        "    --pc|-p <addr>\n"
        "        Sets the initial value of the program counter.\n"
        "\n"
        "    --dump|-d <file>\n"
        "        Dumps the final state of the machine's registers to the specified\n"
        "        file.  (If unspecified, the state is dumped to standard output.)\n"
        "\n"
        "    --console|-c <addr>\n"
        "        Maps a serial console (connected to stdio) at the specified address.\n"
        "\n"
        "    --filter|-f <filter>\n"
        "        Sets a filter to allow only instructions required for a certain lab.\n"
        "        Valid values of filter are: lab1, lab2, lab3\n"
        "\n"
        "    --step|-s\n"
        "        Pause and dump registers after each instruction executes.\n"
        "\n"
        "    --help|-h\n"
        "        Shows this help screen.\n"
        "\n"
        "    --quiet|-q\n"
        "        Decreases the verbosity of the program's output.\n"
        "\n"
        "    --verbose|-v\n"
        "        Increases the verbosity of the program's output.\n"
        "\n"
        "    --version|-V\n"
        "        Prints the program version.\n"
        "\n", progn);
}

variable_types:
progn
char *


version

decompiled_code:
int version()
{
return puts(
"tmips 0.4.1 \"Ikea\"\n"
"Copyright (C) 2011 Thomas Tuttle\n"
"This is free software, and comes with no warranty.\n"
"See COPYING for details.");
}

canonical_decompiled_code:
int func2()
{
return puts(
"tmips 0.4.1 \"Ikea\"\n"
"Copyright (C) 2011 Thomas Tuttle\n"
"This is free software, and comes with no warranty.\n"
"See COPYING for details.");
}

original_code:
static void version(void)
{
    printf(
        "tmips 0.4.1 \"Ikea\"\n"
        "Copyright (C) 2011 Thomas Tuttle\n"
        "This is free software, and comes with no warranty.\n"
        "See COPYING for details.\n");
}

canonical_original_code:
static void version()
{
    printf(
        "tmips 0.4.1 \"Ikea\"\n"
        "Copyright (C) 2011 Thomas Tuttle\n"
        "This is free software, and comes with no warranty.\n"
        "See COPYING for details.\n");
}


CPUConstructor

repo: tuckerd/LC

decompiled_code:
_DWORD *CPUConstructor()
{
_DWORD *v0; // r12
__int64 v1; // rax

v0 = malloc(0x18uLL);
v1 = MemoryConstructor();
v0[4] = 0;
*((_QWORD *)v0 + 1) = v1;
*((_WORD *)v0 + 10) = 0;
*(_QWORD *)v0 = ConstructController(v1, v0 + 5);
return v0;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // r12
__int64 v1; // rax

v0 = malloc(0x18uLL);
v1 = MemoryConstructor();
v0[4] = 0;
*((_QWORD *)v0 + 1) = v1;
*((_WORD *)v0 + 10) = 0;
*(_QWORD *)v0 = ConstructController(v1, v0 + 5);
return v0;
}

original_code:
CPUPtr CPUConstructor()
{
 CPUPtr cpu = (CPUPtr) malloc(sizeof(CPU));
 cpu->memory = MemoryConstructor();
 cpu->MAR = 0x0;
 cpu->MDR = 0x0;
 cpu->PC = 0x0;
 cpu->controller = ConstructController(cpu->memory, &(cpu->PC));
 return cpu;
}

canonical_original_code:
struct CPU *CPUConstructor()
{
 struct CPU *cpu = (CPUPtr) malloc(sizeof(CPU));
 cpu->memory = MemoryConstructor();
 cpu->MAR = 0x0;
 cpu->MDR = 0x0;
 cpu->PC = 0x0;
 cpu->controller = ConstructController(cpu->memory, &(cpu->PC));
 return cpu;
}

variable_types: struct CPU { struct Controller { struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; } *alu; struct Registers { unsigned short registers[8]; } *registers; struct Memory { unsigned short *memory; int size; int capacity; } *memory; unsigned short *PC; unsigned short codes; } *controller; struct Memory *memory; unsigned short MAR; unsigned short MDR; unsigned short PC; } *

user_defined_types: struct CPU { struct Controller *controller; struct Memory *memory; unsigned short MAR; unsigned short MDR; unsigned short PC; }

user_defined_types: struct Controller { struct ALU *alu; struct Registers *registers; struct Memory *memory; unsigned short *PC; unsigned short codes; }


CPUDestructor

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

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

original_code:
void CPUDestructor(CPUPtr this)
{
 free(this->memory);
 free(this);
}

canonical_original_code:
void CPUDestructor(struct CPU *this)
{
 free(this->memory);
 free(this);
}

user_defined_types: struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; }

user_defined_types: struct Registers { unsigned short registers[8]; }

user_defined_types: struct Memory { unsigned short *memory; int size; int capacity; }


getMemoryPtr

decompiled_code:
__int64 __fastcall getMemoryPtr(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
MemoryPtr getMemoryPtr(CPUPtr this)
{
 return this->memory;
}

canonical_original_code:
struct Memory *getMemoryPtr(struct CPU *this)
{
 return this->memory;
}

variable_types: struct CPU { struct Controller { struct ALU { int mask_array[16]; unsigned short A; unsigned short flags; unsigned char c_out; } *alu; struct Registers { unsigned short registers[8]; } *registers; struct Memory *memory; unsigned short *PC; unsigned short codes; } *controller; struct Memory *memory; unsigned short MAR; unsigned short MDR; unsigned short PC; } *

return_type: struct Memory { unsigned short *memory; int size; int capacity; } *


getMAR

decompiled_code:
__int64 __fastcall getMAR(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 16);
}

original_code:
Register getMAR(CPUPtr this)
{
 return this->MAR;
}

canonical_original_code:
unsigned short getMAR(struct CPU *this)
{
 return this->MAR;
}

return_type: unsigned short


setMAR

decompiled_code:
void __fastcall setMAR(__int64 a1, __int16 a2)
{
*(_WORD *)(a1 + 16) = a2;
}

original_code:
void setMAR(CPUPtr this, Register new_mar)
{
 this->MAR = new_mar;
}

canonical_original_code:
void setMAR(struct CPU *this, unsigned short new_mar)
{
 this->MAR = new_mar;
}


getMDR

decompiled_code:
__int64 __fastcall getMDR(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 18);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 18);
}

original_code:
Register getMDR(CPUPtr this)
{
 return this->MDR;
}

canonical_original_code:
unsigned short getMDR(struct CPU *this)
{
 return this->MDR;
}


getPC

decompiled_code:
__int64 __fastcall getPC(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 20);
}

original_code:
Register getPC(CPUPtr this)
{
 return this->PC;
}

canonical_original_code:
unsigned short getPC(struct CPU *this)
{
 return this->PC;
}


setPC

decompiled_code:
void __fastcall setPC(__int64 a1, __int16 a2)
{
*(_WORD *)(a1 + 20) = a2;
}

original_code:
void setPC(CPUPtr this, Register new_pc)
{
 this->PC = new_pc;
}

canonical_original_code:
void setPC(struct CPU *this, unsigned short new_pc)
{
 this->PC = new_pc;
}


getFlagsFromCPU

decompiled_code:
__int64 __fastcall getFlagsFromCPU(_QWORD *a1)
{
return getCC(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
return getCC(*a1);
}

original_code:
unsigned short getFlagsFromCPU(CPUPtr this)
{
 return getCC(this->controller);
}

canonical_original_code:
unsigned short getFlagsFromCPU(struct CPU *this)
{
 return getCC(this->controller);
}


step

original_code:
void step(CPUPtr this)
{
 this->MAR = this->PC;
 this->PC = (this->PC) + 1;
 this->MDR = getMemory(this->memory, this->MAR);
 execute(this->controller, this->MDR);
}

canonical_original_code:
void step(struct CPU *this)
{
 this->MAR = this->PC;
 this->PC = (this->PC) + 1;
 this->MDR = getMemory(this->memory, this->MAR);
 execute(this->controller, this->MDR);
}


MemoryConstructor

decompiled_code:
_QWORD *MemoryConstructor()
{
_QWORD *v0; // r12

v0 = malloc(0x10uLL);
*v0 = calloc(0xC8uLL, 1uLL);
v0[1] = 0x6400000000LL;
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12

v0 = malloc(0x10uLL);
*v0 = calloc(0xC8uLL, 1uLL);
v0[1] = 0x6400000000LL;
return v0;
}

original_code:
MemoryPtr MemoryConstructor() {
 MemoryPtr mem = (MemoryPtr) malloc(sizeof(Memory));
 mem->memory = (Register *) malloc(sizeof(Register) * 100);
 mem->size = 0;
 mem->capacity = 100;
 int i;
 for (i = 0; i < mem->capacity; i++) {
  mem->memory[i] = 0;
 }
 return mem;
}

canonical_original_code:
struct Memory *MemoryConstructor() {
 struct Memory *mem = (MemoryPtr) malloc(sizeof(Memory));
 mem->memory = (unsigned short *) malloc(sizeof(Register) * 100);
 mem->size = 0;
 mem->capacity = 100;
 int i;
 for (i = 0; i < mem->capacity; i++) {
  mem->memory[i] = 0;
 }
 return mem;
}

variable_types: struct Memory { unsigned short *memory; int size; int capacity; } *