decompiled_code:
__int64 __fastcall Route_Suitability_Data_Encode_Bit(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v4; // rax
unsigned int v5; // er12
__int64 v6; // rax

if ( !(unsigned int)Bitstream_Normal(a1, 18LL) )
return 0xFFFFFFFFLL;
if ( !Route_Suitability_Data_UpperBitsNotSet(a2) )
return 4294967294LL;
Bitstream_Write(a1, 2LL, *a2);
Bitstream_Write(a1, 13LL, a2[1]);
Bitstream_Write(a1, 2LL, a2[2]);
Bitstream_Write(a1, 1LL, a2[3]);
v2 = a2[3];
if ( v2 == 1 )
{
Bitstream_Write(a1, 15LL, a2[4]);
v2 = a2[3];
}
if ( !v2 )
{
Bitstream_Write(a1, 15LL, a2[5]);
Bitstream_Write(a1, 2LL, a2[6]);
v4 = a2[6];
if ( !v4 )
{
Bitstream_Write(a1, 8LL, a2[7]);
v4 = a2[6];
}
if ( v4 == 1 )
{
Bitstream_Write(a1, 7LL, a2[8]);
v4 = a2[6];
}
if ( v4 == 2 )
{
Bitstream_Write(a1, 4LL, a2[9]);
if ( a2[6] == 2 )
{
if ( a2[9] )
Bitstream_Write(a1, 10LL, a2[10]);
}
}
Bitstream_Write(a1, 5LL, a2[11]);
if ( a2[11] )
{
v5 = 0;
v6 = 0LL;
do
{
Route_Suitability_Data_Core_1_Encode_Bit(a1, &a2[6 * v6 + 12]);
v6 = ++v5;
}
while ( v5 < a2[11] );
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v4; // rax
unsigned int v5; // er12
__int64 v6; // rax

if ( !(unsigned int)Bitstream_Normal(a1, 18LL) )
return 0xFFFFFFFFLL;
if ( !func1(a2) )
return 4294967294LL;
Bitstream_Write(a1, 2LL, *a2);
Bitstream_Write(a1, 13LL, a2[1]);
Bitstream_Write(a1, 2LL, a2[2]);
Bitstream_Write(a1, 1LL, a2[3]);
v2 = a2[3];
if ( v2 == 1 )
{
Bitstream_Write(a1, 15LL, a2[4]);
v2 = a2[3];
}
if ( !v2 )
{
Bitstream_Write(a1, 15LL, a2[5]);
Bitstream_Write(a1, 2LL, a2[6]);
v4 = a2[6];
if ( !v4 )
{
Bitstream_Write(a1, 8LL, a2[7]);
v4 = a2[6];
}
if ( v4 == 1 )
{
Bitstream_Write(a1, 7LL, a2[8]);
v4 = a2[6];
}
if ( v4 == 2 )
{
Bitstream_Write(a1, 4LL, a2[9]);
if ( a2[6] == 2 )
{
if ( a2[9] )
Bitstream_Write(a1, 10LL, a2[10]);
}
}
Bitstream_Write(a1, 5LL, a2[11]);
if ( a2[11] )
{
v5 = 0;
v6 = 0LL;
do
{
Route_Suitability_Data_Core_1_Encode_Bit(a1, &a2[6 * v6 + 12]);
v6 = ++v5;
}
while ( v5 < a2[11] );
}
}
return 1LL;
}

original_code:
int Route_Suitability_Data_Encode_Bit(Bitstream* stream, const Route_Suitability_Data_Core* p)
{
    if (Bitstream_Normal(stream, 25))
    {
        if (Route_Suitability_Data_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_TRACKINIT);
            if (p->Q_TRACKINIT == 1)
            {
                Bitstream_Write(stream, 15, p->D_TRACKINIT);
            }
            if (p->Q_TRACKINIT == 0)
            {
                Bitstream_Write(stream, 15, p->D_SUITABILITY);
            }
            Bitstream_Write(stream, 2, p->Q_SUITABILITY);
            if (p->Q_SUITABILITY == 0)
            {
                Bitstream_Write(stream, 8, p->M_LOADINGGAUGE);
            }
            if (p->Q_SUITABILITY == 1)
            {
                Bitstream_Write(stream, 7, p->M_AXLELOAD);
            }
            if (p->Q_SUITABILITY == 2)
            {
                Bitstream_Write(stream, 8, p->M_TRACTION);
            }
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                Route_Suitability_Data_Core_1_Encode_Bit(stream, &(p->sub_1[i]));
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int Route_Suitability_Data_Encode_Bit(struct Bitstream *stream, struct Route_Suitability_Data_Core *p)
{
    if (Bitstream_Normal(stream, 25))
    {
        if (Route_Suitability_Data_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_TRACKINIT);
            if (p->Q_TRACKINIT == 1)
            {
                Bitstream_Write(stream, 15, p->D_TRACKINIT);
            }
            if (p->Q_TRACKINIT == 0)
            {
                Bitstream_Write(stream, 15, p->D_SUITABILITY);
            }
            Bitstream_Write(stream, 2, p->Q_SUITABILITY);
            if (p->Q_SUITABILITY == 0)
            {
                Bitstream_Write(stream, 8, p->M_LOADINGGAUGE);
            }
            if (p->Q_SUITABILITY == 1)
            {
                Bitstream_Write(stream, 7, p->M_AXLELOAD);
            }
            if (p->Q_SUITABILITY == 2)
            {
                Bitstream_Write(stream, 8, p->M_TRACTION);
            }
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                Route_Suitability_Data_Core_1_Encode_Bit(stream, &(p->sub_1[i]));
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

variable_types: struct Route_Suitability_Data_Core { unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_TRACKINIT; unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; unsigned long N_ITER_1; struct Route_Suitability_Data_Core_1 { unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; } sub_1[31]; } *

user_defined_types: struct Route_Suitability_Data_Core { unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_TRACKINIT; unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; unsigned long N_ITER_1; struct Route_Suitability_Data_Core_1 sub_1[31]; }


repo: openETCS/dataDictionary

decompiled_code:
__int64 __fastcall Route_Suitability_Data_Decode_Bit(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
unsigned int v6; // er12
__int64 v7; // rax
__int64 v8; // rax
bool v9; // zf

result = Bitstream_Normal(a1, 18LL);
if ( (_DWORD)result )
{
*a2 = Bitstream_Read(a1, 2LL);
a2[1] = Bitstream_Read(a1, 13LL);
a2[2] = Bitstream_Read(a1, 2LL);
v3 = Bitstream_Read(a1, 1LL);
a2[3] = v3;
if ( v3 == 1 )
{
a2[4] = Bitstream_Read(a1, 15LL);
v3 = a2[3];
}
if ( !v3 )
{
a2[5] = Bitstream_Read(a1, 15LL);
v4 = Bitstream_Read(a1, 2LL);
a2[6] = v4;
if ( !v4 )
{
a2[7] = Bitstream_Read(a1, 8LL);
v4 = a2[6];
}
if ( v4 == 1 )
{
a2[8] = Bitstream_Read(a1, 7LL);
v4 = a2[6];
}
if ( v4 == 2 )
{
v8 = Bitstream_Read(a1, 4LL);
v9 = a2[6] == 2LL;
a2[9] = v8;
if ( v9 )
{
if ( v8 )
a2[10] = Bitstream_Read(a1, 10LL);
}
}
v5 = Bitstream_Read(a1, 5LL);
a2[11] = v5;
if ( v5 )
{
v6 = 0;
v7 = 0LL;
do
{
Route_Suitability_Data_Core_1_Decode_Bit(a1, &a2[6 * v7 + 12]);
v7 = ++v6;
}
while ( (unsigned __int64)v6 < a2[11] );
}
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
unsigned int v6; // er12
__int64 v7; // rax
__int64 v8; // rax
bool v9; // zf

result = Bitstream_Normal(a1, 18LL);
if ( (_DWORD)result )
{
*a2 = Bitstream_Read(a1, 2LL);
a2[1] = Bitstream_Read(a1, 13LL);
a2[2] = Bitstream_Read(a1, 2LL);
v3 = Bitstream_Read(a1, 1LL);
a2[3] = v3;
if ( v3 == 1 )
{
a2[4] = Bitstream_Read(a1, 15LL);
v3 = a2[3];
}
if ( !v3 )
{
a2[5] = Bitstream_Read(a1, 15LL);
v4 = Bitstream_Read(a1, 2LL);
a2[6] = v4;
if ( !v4 )
{
a2[7] = Bitstream_Read(a1, 8LL);
v4 = a2[6];
}
if ( v4 == 1 )
{
a2[8] = Bitstream_Read(a1, 7LL);
v4 = a2[6];
}
if ( v4 == 2 )
{
v8 = Bitstream_Read(a1, 4LL);
v9 = a2[6] == 2LL;
a2[9] = v8;
if ( v9 )
{
if ( v8 )
a2[10] = Bitstream_Read(a1, 10LL);
}
}
v5 = Bitstream_Read(a1, 5LL);
a2[11] = v5;
if ( v5 )
{
v6 = 0;
v7 = 0LL;
do
{
Route_Suitability_Data_Core_1_Decode_Bit(a1, &a2[6 * v7 + 12]);
v7 = ++v6;
}
while ( (unsigned __int64)v6 < a2[11] );
}
}
result = 1LL;
}
return result;
}

original_code:
int Route_Suitability_Data_Decode_Bit(Bitstream* stream, Route_Suitability_Data_Core* p)
{
    if (Bitstream_Normal(stream, 25))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TRACKINIT = Bitstream_Read(stream, 1);
        }
        if (p->Q_TRACKINIT == 1)
        {
            {
                p->D_TRACKINIT = Bitstream_Read(stream, 15);
            }
        }
        if (p->Q_TRACKINIT == 0)
        {
            {
                p->D_SUITABILITY = Bitstream_Read(stream, 15);
            }
        }
        {
            p->Q_SUITABILITY = Bitstream_Read(stream, 2);
        }
        if (p->Q_SUITABILITY == 0)
        {
            {
                p->M_LOADINGGAUGE = Bitstream_Read(stream, 8);
            }
        }
        if (p->Q_SUITABILITY == 1)
        {
            {
                p->M_AXLELOAD = Bitstream_Read(stream, 7);
            }
        }
        if (p->Q_SUITABILITY == 2)
        {
            {
                p->M_TRACTION = Bitstream_Read(stream, 8);
            }
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            Route_Suitability_Data_Core_1_Decode_Bit(stream, &(p->sub_1[i]));
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Route_Suitability_Data_Decode_Bit(struct Bitstream *stream, struct Route_Suitability_Data_Core *p)
{
    if (Bitstream_Normal(stream, 25))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TRACKINIT = Bitstream_Read(stream, 1);
        }
        if (p->Q_TRACKINIT == 1)
        {
            {
                p->D_TRACKINIT = Bitstream_Read(stream, 15);
            }
        }
        if (p->Q_TRACKINIT == 0)
        {
            {
                p->D_SUITABILITY = Bitstream_Read(stream, 15);
            }
        }
        {
            p->Q_SUITABILITY = Bitstream_Read(stream, 2);
        }
        if (p->Q_SUITABILITY == 0)
        {
            {
                p->M_LOADINGGAUGE = Bitstream_Read(stream, 8);
            }
        }
        if (p->Q_SUITABILITY == 1)
        {
            {
                p->M_AXLELOAD = Bitstream_Read(stream, 7);
            }
        }
        if (p->Q_SUITABILITY == 2)
        {
            {
                p->M_TRACTION = Bitstream_Read(stream, 8);
            }
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            Route_Suitability_Data_Core_1_Decode_Bit(stream, &(p->sub_1[i]));
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct Bitstream { unsigned char *addr; unsigned int size; unsigned int bitpos; } *

variable_types:
i
unsigned int

return_type: int

user_defined_types: struct Route_Suitability_Data_Core_1 { unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; }


original_code:
int Route_Suitability_Data_Encode_Int(PacketInfo* data, kcg_int* stream, const Route_Suitability_Data_Core* p)
{
    return 0;
}

canonical_original_code:
int Route_Suitability_Data_Encode_Int(struct MetadataElement_T_Common_Types_Pkg *data, int *stream, struct Route_Suitability_Data_Core *p)
{
    return 0;
}

variable_types: struct MetadataElement_T_Common_Types_Pkg { int nid_packet; int q_dir; unsigned char valid; int startAddress; int endAddress; } *

variable_types:
stream
int *


original_code:
int Route_Suitability_Data_Decode_Int(PacketInfo* data, const kcg_int* stream, Route_Suitability_Data_Core* p)
{
    return 0;
}

canonical_original_code:
int Route_Suitability_Data_Decode_Int(struct MetadataElement_T_Common_Types_Pkg *data, int *stream, struct Route_Suitability_Data_Core *p)
{
    return 0;
}

user_defined_types: struct MetadataElement_T_Common_Types_Pkg { int nid_packet; int q_dir; unsigned char valid; int startAddress; int endAddress; }


decompiled_code:
_BOOL8 __fastcall AxleLoadSpeedProfile_1_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx

result = UpperBitsNotSet64_constprop_0(*a1);
if ( result )
result = UpperBitsNotSet64_constprop_0(*(_QWORD *)(v2 + 8));
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int64 *a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx

result = func0(*a1);
if ( result )
result = func0(*(_QWORD *)(v2 + 8));
return result;
}

original_code:
int AxleLoadSpeedProfile_1_UpperBitsNotSet(const AxleLoadSpeedProfile_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->M_AXLELOAD, 7) ;
    status = status && UpperBitsNotSet64(p->V_AXLELOAD, 7) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_1_UpperBitsNotSet(struct AxleLoadSpeedProfile_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->M_AXLELOAD, 7) ;
    status = status && UpperBitsNotSet64(p->V_AXLELOAD, 7) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct AxleLoadSpeedProfile_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } *

variable_types: status int


decompiled_code:
__int64 __fastcall AxleLoadSpeedProfile_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 14LL) )
return 0xFFFFFFFFLL;
if ( !AxleLoadSpeedProfile_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 7LL, *a1);
Bitstream_Write(a2, 7LL, a1[1]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 14LL) )
return 0xFFFFFFFFLL;
if ( !func1(a1) )
return 4294967294LL;
Bitstream_Write(a2, 7LL, *a1);
Bitstream_Write(a2, 7LL, a1[1]);
return 1LL;
}

original_code:
int AxleLoadSpeedProfile_1_EncodeBit(const AxleLoadSpeedProfile_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 14))
    {
        if (AxleLoadSpeedProfile_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 7, p->M_AXLELOAD);
            Bitstream_Write(stream, 7, p->V_AXLELOAD);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_1_EncodeBit(struct AxleLoadSpeedProfile_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 14))
    {
        if (AxleLoadSpeedProfile_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 7, p->M_AXLELOAD);
            Bitstream_Write(stream, 7, p->V_AXLELOAD);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct AxleLoadSpeedProfile_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; }

user_defined_types: struct Bitstream { unsigned char *addr; unsigned int size; unsigned int bitpos; }


decompiled_code:
__int64 __fastcall AxleLoadSpeedProfile_1_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = Bitstream_Normal(a2, 14LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 7LL);
a1[1] = Bitstream_Read(a2, 7LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = Bitstream_Normal(a2, 14LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 7LL);
a1[1] = Bitstream_Read(a2, 7LL);
result = 1LL;
}
return result;
}

original_code:
int AxleLoadSpeedProfile_1_DecodeBit(AxleLoadSpeedProfile_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 14))
    {
        {
            p->M_AXLELOAD = Bitstream_Read(stream, 7);
        }
        {
            p->V_AXLELOAD = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_1_DecodeBit(struct AxleLoadSpeedProfile_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 14))
    {
        {
            p->M_AXLELOAD = Bitstream_Read(stream, 7);
        }
        {
            p->V_AXLELOAD = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int AxleLoadSpeedProfile_1_EncodeInt(const AxleLoadSpeedProfile_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->M_AXLELOAD;
    stream[(*startAddress)++] = p->V_AXLELOAD;
    return 1;
}

canonical_original_code:
int AxleLoadSpeedProfile_1_EncodeInt(struct AxleLoadSpeedProfile_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->M_AXLELOAD;
    stream[(*startAddress)++] = p->V_AXLELOAD;
    return 1;
}

variable_types:
startAddress
int *


decompiled_code:
__int64 __fastcall AxleLoadSpeedProfile_1_DecodeInt(_QWORD *a1, _DWORD *a2, __int64 a3)
{
int v3; // eax

v3 = (*a2)++;
*a1 = *(int *)(a3 + 4LL * v3);
*a2 = v3 + 2;
a1[1] = *(int *)(a3 + 4LL * v3 + 4);
return 1LL;
}

original_code:
int AxleLoadSpeedProfile_1_DecodeInt(AxleLoadSpeedProfile_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->M_AXLELOAD = stream[(*startAddress)++];
    p->V_AXLELOAD = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int AxleLoadSpeedProfile_1_DecodeInt(struct AxleLoadSpeedProfile_1 *p, int *startAddress, int *stream)
{
    p->M_AXLELOAD = stream[(*startAddress)++];
    p->V_AXLELOAD = stream[(*startAddress)++];
    return 1;
}


decompiled_code:
_BOOL8 __fastcall UpperBitsNotSet64(unsigned __int64 a1, char a2)
{
return 1LL << a2 > a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int64 a1, char a2)
{
return 1LL << a2 > a1;
}

original_code:
static inline int UpperBitsNotSet64(uint64_t value, uint32_t length)
{
    if (length == 64)
    {
        return 1;
    }
    else
    {
        const uint64_t MaxValue = ((uint64_t) 1) << length;
        return value < MaxValue;
    }
}

canonical_original_code:
static inline int UpperBitsNotSet64(unsigned long value, unsigned int length)
{
    if (length == 64)
    {
        return 1;
    }
    else
    {
        unsigned long MaxValue = ((uint64_t) 1) << length;
        return value < MaxValue;
    }
}

variable_types:
value
unsigned long

variable_types:
length
unsigned int

variable_types:
MaxValue
unsigned long


decompiled_code:
__int64 __fastcall Packet_for_sending_plain_text_messages_Encode_Bit(__int64 a1, unsigned __int64 *a2)
{
if ( !(unsigned int)Bitstream_Normal(a1, 92LL) )
return 0xFFFFFFFFLL;
if ( Packet_for_sending_plain_text_messages_UpperBitsNotSet(a2) )
{
Bitstream_Write(a1, 2LL, *a2);
Bitstream_Write(a1, 13LL, a2[1]);
Bitstream_Write(a1, 2LL, a2[2]);
Bitstream_Write(a1, 2LL, a2[3]);
Bitstream_Write(a1, 1LL, a2[4]);
Bitstream_Write(a1, 15LL, a2[5]);
Bitstream_Write(a1, 4LL, a2[6]);
Bitstream_Write(a1, 3LL, a2[7]);
if ( a2[7] == 1 )
Bitstream_Write(a1, 8LL, a2[8]);
Bitstream_Write(a1, 15LL, a2[9]);
Bitstream_Write(a1, 10LL, a2[10]);
Bitstream_Write(a1, 4LL, a2[11]);
Bitstream_Write(a1, 3LL, a2[12]);
if ( a2[12] == 1 )
Bitstream_Write(a1, 8LL, a2[13]);
Bitstream_Write(a1, 2LL, a2[14]);
if ( a2[14] )
{
Bitstream_Write(a1, 1LL, a2[15]);
Bitstream_Write(a1, 1LL, a2[16]);
if ( a2[16] != 1 )
goto LABEL_9;
}
else if ( a2[16] != 1 )
{
LABEL_9:
Bitstream_Write(a1, 8LL, a2[20]);
Bitstream_Write(a1, 8LL, a2[21]);
return 1LL;
}
Bitstream_Write(a1, 8LL, a2[17]);
Bitstream_Write(a1, 10LL, a2[18]);
Bitstream_Write(a1, 14LL, a2[19]);
goto LABEL_9;
}
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 *a2)
{
if ( !(unsigned int)Bitstream_Normal(a1, 92LL) )
return 0xFFFFFFFFLL;
if ( func1(a2) )
{
Bitstream_Write(a1, 2LL, *a2);
Bitstream_Write(a1, 13LL, a2[1]);
Bitstream_Write(a1, 2LL, a2[2]);
Bitstream_Write(a1, 2LL, a2[3]);
Bitstream_Write(a1, 1LL, a2[4]);
Bitstream_Write(a1, 15LL, a2[5]);
Bitstream_Write(a1, 4LL, a2[6]);
Bitstream_Write(a1, 3LL, a2[7]);
if ( a2[7] == 1 )
Bitstream_Write(a1, 8LL, a2[8]);
Bitstream_Write(a1, 15LL, a2[9]);
Bitstream_Write(a1, 10LL, a2[10]);
Bitstream_Write(a1, 4LL, a2[11]);
Bitstream_Write(a1, 3LL, a2[12]);
if ( a2[12] == 1 )
Bitstream_Write(a1, 8LL, a2[13]);
Bitstream_Write(a1, 2LL, a2[14]);
if ( a2[14] )
{
Bitstream_Write(a1, 1LL, a2[15]);
Bitstream_Write(a1, 1LL, a2[16]);
if ( a2[16] != 1 )
goto LABEL_9;
}
else if ( a2[16] != 1 )
{
LABEL_9:
Bitstream_Write(a1, 8LL, a2[20]);
Bitstream_Write(a1, 8LL, a2[21]);
return 1LL;
}
Bitstream_Write(a1, 8LL, a2[17]);
Bitstream_Write(a1, 10LL, a2[18]);
Bitstream_Write(a1, 14LL, a2[19]);
goto LABEL_9;
}
return 4294967294LL;
}

original_code:
int Packet_for_sending_plain_text_messages_Encode_Bit(Bitstream* stream, const Packet_for_sending_plain_text_messages_Core* p)
{
    if (Bitstream_Normal(stream, 92))
    {
        if (Packet_for_sending_plain_text_messages_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 2, p->Q_TEXTCLASS);
            Bitstream_Write(stream, 1, p->Q_TEXTDISPLAY);
            Bitstream_Write(stream, 15, p->D_TEXTDISPLAY);
            Bitstream_Write(stream, 4, p->M_MODETEXTDISPLAY_0);
            Bitstream_Write(stream, 3, p->M_LEVELTEXTDISPLAY_0);
            if (p->M_LEVELTEXTDISPLAY_0 == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM_0);
            }
            Bitstream_Write(stream, 15, p->L_TEXTDISPLAY);
            Bitstream_Write(stream, 10, p->T_TEXTDISPLAY);
            Bitstream_Write(stream, 4, p->M_MODETEXTDISPLAY_1);
            Bitstream_Write(stream, 3, p->M_LEVELTEXTDISPLAY_1);
            if (p->M_LEVELTEXTDISPLAY_1 == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM_1);
            }
            Bitstream_Write(stream, 2, p->Q_TEXTCONFIRM);
            Bitstream_Write(stream, 8, p->L_TEXT);
            Bitstream_Write(stream, 8, p->X_TEXT);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int Packet_for_sending_plain_text_messages_Encode_Bit(struct Bitstream *stream, struct Packet_for_sending_plain_text_messages_Core *p)
{
    if (Bitstream_Normal(stream, 92))
    {
        if (Packet_for_sending_plain_text_messages_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 2, p->Q_TEXTCLASS);
            Bitstream_Write(stream, 1, p->Q_TEXTDISPLAY);
            Bitstream_Write(stream, 15, p->D_TEXTDISPLAY);
            Bitstream_Write(stream, 4, p->M_MODETEXTDISPLAY_0);
            Bitstream_Write(stream, 3, p->M_LEVELTEXTDISPLAY_0);
            if (p->M_LEVELTEXTDISPLAY_0 == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM_0);
            }
            Bitstream_Write(stream, 15, p->L_TEXTDISPLAY);
            Bitstream_Write(stream, 10, p->T_TEXTDISPLAY);
            Bitstream_Write(stream, 4, p->M_MODETEXTDISPLAY_1);
            Bitstream_Write(stream, 3, p->M_LEVELTEXTDISPLAY_1);
            if (p->M_LEVELTEXTDISPLAY_1 == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM_1);
            }
            Bitstream_Write(stream, 2, p->Q_TEXTCONFIRM);
            Bitstream_Write(stream, 8, p->L_TEXT);
            Bitstream_Write(stream, 8, p->X_TEXT);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

variable_types: struct Packet_for_sending_plain_text_messages_Core { unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TEXTCLASS; unsigned long Q_TEXTDISPLAY; unsigned long D_TEXTDISPLAY; unsigned long M_MODETEXTDISPLAY_0; unsigned long M_LEVELTEXTDISPLAY_0; unsigned long NID_STM_0; unsigned long L_TEXTDISPLAY; unsigned long T_TEXTDISPLAY; unsigned long M_MODETEXTDISPLAY_1; unsigned long M_LEVELTEXTDISPLAY_1; unsigned long NID_STM_1; unsigned long Q_TEXTCONFIRM; unsigned long L_TEXT; unsigned long X_TEXT; } *


decompiled_code:
__int64 __fastcall Packet_for_sending_plain_text_messages_Decode_Bit(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

result = Bitstream_Normal(a1, 92LL);
if ( (_DWORD)result )
{
*a2 = Bitstream_Read(a1, 2LL);
a2[1] = Bitstream_Read(a1, 13LL);
a2[2] = Bitstream_Read(a1, 2LL);
a2[3] = Bitstream_Read(a1, 2LL);
a2[4] = Bitstream_Read(a1, 1LL);
a2[5] = Bitstream_Read(a1, 15LL);
a2[6] = Bitstream_Read(a1, 4LL);
v3 = Bitstream_Read(a1, 3LL);
a2[7] = v3;
if ( v3 == 1 )
a2[8] = Bitstream_Read(a1, 8LL);
a2[9] = Bitstream_Read(a1, 15LL);
a2[10] = Bitstream_Read(a1, 10LL);
a2[11] = Bitstream_Read(a1, 4LL);
v4 = Bitstream_Read(a1, 3LL);
a2[12] = v4;
if ( v4 == 1 )
a2[13] = Bitstream_Read(a1, 8LL);
v5 = Bitstream_Read(a1, 2LL);
a2[14] = v5;
if ( v5 )
{
a2[15] = Bitstream_Read(a1, 1LL);
v6 = Bitstream_Read(a1, 1LL);
a2[16] = v6;
}
else
{
v6 = a2[16];
}
if ( v6 == 1 )
{
a2[17] = Bitstream_Read(a1, 8LL);
a2[18] = Bitstream_Read(a1, 10LL);
a2[19] = Bitstream_Read(a1, 14LL);
}
a2[20] = Bitstream_Read(a1, 8LL);
a2[21] = Bitstream_Read(a1, 8LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

result = Bitstream_Normal(a1, 92LL);
if ( (_DWORD)result )
{
*a2 = Bitstream_Read(a1, 2LL);
a2[1] = Bitstream_Read(a1, 13LL);
a2[2] = Bitstream_Read(a1, 2LL);
a2[3] = Bitstream_Read(a1, 2LL);
a2[4] = Bitstream_Read(a1, 1LL);
a2[5] = Bitstream_Read(a1, 15LL);
a2[6] = Bitstream_Read(a1, 4LL);
v3 = Bitstream_Read(a1, 3LL);
a2[7] = v3;
if ( v3 == 1 )
a2[8] = Bitstream_Read(a1, 8LL);
a2[9] = Bitstream_Read(a1, 15LL);
a2[10] = Bitstream_Read(a1, 10LL);
a2[11] = Bitstream_Read(a1, 4LL);
v4 = Bitstream_Read(a1, 3LL);
a2[12] = v4;
if ( v4 == 1 )
a2[13] = Bitstream_Read(a1, 8LL);
v5 = Bitstream_Read(a1, 2LL);
a2[14] = v5;
if ( v5 )
{
a2[15] = Bitstream_Read(a1, 1LL);
v6 = Bitstream_Read(a1, 1LL);
a2[16] = v6;
}
else
{
v6 = a2[16];
}
if ( v6 == 1 )
{
a2[17] = Bitstream_Read(a1, 8LL);
a2[18] = Bitstream_Read(a1, 10LL);
a2[19] = Bitstream_Read(a1, 14LL);
}
a2[20] = Bitstream_Read(a1, 8LL);
a2[21] = Bitstream_Read(a1, 8LL);
result = 1LL;
}
return result;
}

original_code:
int Packet_for_sending_plain_text_messages_Decode_Bit(Bitstream* stream, Packet_for_sending_plain_text_messages_Core* p)
{
    if (Bitstream_Normal(stream, 92))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TEXTCLASS = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TEXTDISPLAY = Bitstream_Read(stream, 1);
        }
        {
            p->D_TEXTDISPLAY = Bitstream_Read(stream, 15);
        }
        {
            p->M_MODETEXTDISPLAY_0 = Bitstream_Read(stream, 4);
        }
        {
            p->M_LEVELTEXTDISPLAY_0 = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTEXTDISPLAY_0 == 1)
        {
            {
                p->NID_STM_0 = Bitstream_Read(stream, 8);
            }
        }
        {
            p->L_TEXTDISPLAY = Bitstream_Read(stream, 15);
        }
        {
            p->T_TEXTDISPLAY = Bitstream_Read(stream, 10);
        }
        {
            p->M_MODETEXTDISPLAY_1 = Bitstream_Read(stream, 4);
        }
        {
            p->M_LEVELTEXTDISPLAY_1 = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTEXTDISPLAY_1 == 1)
        {
            {
                p->NID_STM_1 = Bitstream_Read(stream, 8);
            }
        }
        {
            p->Q_TEXTCONFIRM = Bitstream_Read(stream, 2);
        }
        {
            p->L_TEXT = Bitstream_Read(stream, 8);
        }
        {
            p->X_TEXT = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Packet_for_sending_plain_text_messages_Decode_Bit(struct Bitstream *stream, struct Packet_for_sending_plain_text_messages_Core *p)
{
    if (Bitstream_Normal(stream, 92))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TEXTCLASS = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TEXTDISPLAY = Bitstream_Read(stream, 1);
        }
        {
            p->D_TEXTDISPLAY = Bitstream_Read(stream, 15);
        }
        {
            p->M_MODETEXTDISPLAY_0 = Bitstream_Read(stream, 4);
        }
        {
            p->M_LEVELTEXTDISPLAY_0 = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTEXTDISPLAY_0 == 1)
        {
            {
                p->NID_STM_0 = Bitstream_Read(stream, 8);
            }
        }
        {
            p->L_TEXTDISPLAY = Bitstream_Read(stream, 15);
        }
        {
            p->T_TEXTDISPLAY = Bitstream_Read(stream, 10);
        }
        {
            p->M_MODETEXTDISPLAY_1 = Bitstream_Read(stream, 4);
        }
        {
            p->M_LEVELTEXTDISPLAY_1 = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTEXTDISPLAY_1 == 1)
        {
            {
                p->NID_STM_1 = Bitstream_Read(stream, 8);
            }
        }
        {
            p->Q_TEXTCONFIRM = Bitstream_Read(stream, 2);
        }
        {
            p->L_TEXT = Bitstream_Read(stream, 8);
        }
        {
            p->X_TEXT = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

user_defined_types: struct Packet_for_sending_plain_text_messages_Core { unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TEXTCLASS; unsigned long Q_TEXTDISPLAY; unsigned long D_TEXTDISPLAY; unsigned long M_MODETEXTDISPLAY_0; unsigned long M_LEVELTEXTDISPLAY_0; unsigned long NID_STM_0; unsigned long L_TEXTDISPLAY; unsigned long T_TEXTDISPLAY; unsigned long M_MODETEXTDISPLAY_1; unsigned long M_LEVELTEXTDISPLAY_1; unsigned long NID_STM_1; unsigned long Q_TEXTCONFIRM; unsigned long L_TEXT; unsigned long X_TEXT; }


original_code:
int Packet_for_sending_plain_text_messages_Encode_Int(PacketInfo* data, kcg_int* stream, const Packet_for_sending_plain_text_messages_Core* p)
{
    return 0;
}

canonical_original_code:
int Packet_for_sending_plain_text_messages_Encode_Int(struct MetadataElement_T_Common_Types_Pkg *data, int *stream, struct Packet_for_sending_plain_text_messages_Core *p)
{
    return 0;
}


original_code:
int Packet_for_sending_plain_text_messages_Decode_Int(PacketInfo* data, const kcg_int* stream, Packet_for_sending_plain_text_messages_Core* p)
{
    return 0;
}

canonical_original_code:
int Packet_for_sending_plain_text_messages_Decode_Int(struct MetadataElement_T_Common_Types_Pkg *data, int *stream, struct Packet_for_sending_plain_text_messages_Core *p)
{
    return 0;
}


decompiled_code:
_BOOL8 __fastcall Linking_1_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rdi
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx

result = UpperBitsNotSet64(*a1, 15);
if ( result )
{
v3 = *(_QWORD *)(v2 + 8);
result = UpperBitsNotSet64(v3, 1);
if ( result && (v3 != 1 || (result = UpperBitsNotSet64(*(_QWORD *)(v4 + 16), 10))) )
{
result = UpperBitsNotSet64(*(_QWORD *)(v4 + 24), 14);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v5 + 32), 1);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v6 + 40), 2);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v7 + 48), 6);
}
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int64 *a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rdi
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx

result = func0(*a1, 15);
if ( result )
{
v3 = *(_QWORD *)(v2 + 8);
result = func0(v3, 1);
if ( result && (v3 != 1 || (result = func0(*(_QWORD *)(v4 + 16), 10))) )
{
result = func0(*(_QWORD *)(v4 + 24), 14);
if ( result )
{
result = func0(*(_QWORD *)(v5 + 32), 1);
if ( result )
{
result = func0(*(_QWORD *)(v6 + 40), 2);
if ( result )
result = func0(*(_QWORD *)(v7 + 48), 6);
}
}
}
}
return result;
}

original_code:
int Linking_1_UpperBitsNotSet(const Linking_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_LINK, 15);
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    status = status && UpperBitsNotSet64(p->Q_LINKORIENTATION, 1) ;
    status = status && UpperBitsNotSet64(p->Q_LINKREACTION, 2) ;
    status = status && UpperBitsNotSet64(p->Q_LOCACC, 6) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Linking_1_UpperBitsNotSet(struct Linking_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_LINK, 15);
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    status = status && UpperBitsNotSet64(p->Q_LINKORIENTATION, 1) ;
    status = status && UpperBitsNotSet64(p->Q_LINKREACTION, 2) ;
    status = status && UpperBitsNotSet64(p->Q_LOCACC, 6) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct Linking_1 { unsigned long D_LINK; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINKORIENTATION; unsigned long Q_LINKREACTION; unsigned long Q_LOCACC; } *


decompiled_code:
__int64 __fastcall Linking_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 39LL) )
return 0xFFFFFFFFLL;
if ( !Linking_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 1LL, a1[1]);
if ( a1[1] == 1 )
Bitstream_Write(a2, 10LL, a1[2]);
Bitstream_Write(a2, 14LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
Bitstream_Write(a2, 2LL, a1[5]);
Bitstream_Write(a2, 6LL, a1[6]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 39LL) )
return 0xFFFFFFFFLL;
if ( !func1(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 1LL, a1[1]);
if ( a1[1] == 1 )
Bitstream_Write(a2, 10LL, a1[2]);
Bitstream_Write(a2, 14LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
Bitstream_Write(a2, 2LL, a1[5]);
Bitstream_Write(a2, 6LL, a1[6]);
return 1LL;
}

original_code:
int Linking_1_EncodeBit(const Linking_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 39))
    {
        if (Linking_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_LINK);
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            Bitstream_Write(stream, 1, p->Q_LINKORIENTATION);
            Bitstream_Write(stream, 2, p->Q_LINKREACTION);
            Bitstream_Write(stream, 6, p->Q_LOCACC);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int Linking_1_EncodeBit(struct Linking_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 39))
    {
        if (Linking_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_LINK);
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            Bitstream_Write(stream, 1, p->Q_LINKORIENTATION);
            Bitstream_Write(stream, 2, p->Q_LINKREACTION);
            Bitstream_Write(stream, 6, p->Q_LOCACC);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct Linking_1 { unsigned long D_LINK; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINKORIENTATION; unsigned long Q_LINKREACTION; unsigned long Q_LOCACC; }


decompiled_code:
__int64 __fastcall Linking_1_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax

result = Bitstream_Normal(a2, 39LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 15LL);
v3 = Bitstream_Read(a2, 1LL);
a1[1] = v3;
if ( v3 == 1 )
a1[2] = Bitstream_Read(a2, 10LL);
a1[3] = Bitstream_Read(a2, 14LL);
a1[4] = Bitstream_Read(a2, 1LL);
a1[5] = Bitstream_Read(a2, 2LL);
a1[6] = Bitstream_Read(a2, 6LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax

result = Bitstream_Normal(a2, 39LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 15LL);
v3 = Bitstream_Read(a2, 1LL);
a1[1] = v3;
if ( v3 == 1 )
a1[2] = Bitstream_Read(a2, 10LL);
a1[3] = Bitstream_Read(a2, 14LL);
a1[4] = Bitstream_Read(a2, 1LL);
a1[5] = Bitstream_Read(a2, 2LL);
a1[6] = Bitstream_Read(a2, 6LL);
result = 1LL;
}
return result;
}

original_code:
int Linking_1_DecodeBit(Linking_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 39))
    {
        {
            p->D_LINK = Bitstream_Read(stream, 15);
        }
        {
            p->Q_NEWCOUNTRY = Bitstream_Read(stream, 1);
        }
        if (p->Q_NEWCOUNTRY == 1)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        {
            p->Q_LINKORIENTATION = Bitstream_Read(stream, 1);
        }
        {
            p->Q_LINKREACTION = Bitstream_Read(stream, 2);
        }
        {
            p->Q_LOCACC = Bitstream_Read(stream, 6);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Linking_1_DecodeBit(struct Linking_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 39))
    {
        {
            p->D_LINK = Bitstream_Read(stream, 15);
        }
        {
            p->Q_NEWCOUNTRY = Bitstream_Read(stream, 1);
        }
        if (p->Q_NEWCOUNTRY == 1)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        {
            p->Q_LINKORIENTATION = Bitstream_Read(stream, 1);
        }
        {
            p->Q_LINKREACTION = Bitstream_Read(stream, 2);
        }
        {
            p->Q_LOCACC = Bitstream_Read(stream, 6);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int Linking_1_EncodeInt(const Linking_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->D_LINK;
    stream[(*startAddress)++] = p->Q_NEWCOUNTRY;
    stream[(*startAddress)++] = p->NID_C;
    stream[(*startAddress)++] = p->NID_BG;
    stream[(*startAddress)++] = p->Q_LINKORIENTATION;
    stream[(*startAddress)++] = p->Q_LINKREACTION;
    stream[(*startAddress)++] = p->Q_LOCACC;
    return 1;
}

canonical_original_code:
int Linking_1_EncodeInt(struct Linking_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->D_LINK;
    stream[(*startAddress)++] = p->Q_NEWCOUNTRY;
    stream[(*startAddress)++] = p->NID_C;
    stream[(*startAddress)++] = p->NID_BG;
    stream[(*startAddress)++] = p->Q_LINKORIENTATION;
    stream[(*startAddress)++] = p->Q_LINKREACTION;
    stream[(*startAddress)++] = p->Q_LOCACC;
    return 1;
}


original_code:
int Linking_1_DecodeInt(Linking_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->D_LINK = stream[(*startAddress)++];
    p->Q_NEWCOUNTRY = stream[(*startAddress)++];
    p->NID_C = stream[(*startAddress)++];
    p->NID_BG = stream[(*startAddress)++];
    p->Q_LINKORIENTATION = stream[(*startAddress)++];
    p->Q_LINKREACTION = stream[(*startAddress)++];
    p->Q_LOCACC = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int Linking_1_DecodeInt(struct Linking_1 *p, int *startAddress, int *stream)
{
    p->D_LINK = stream[(*startAddress)++];
    p->Q_NEWCOUNTRY = stream[(*startAddress)++];
    p->NID_C = stream[(*startAddress)++];
    p->NID_BG = stream[(*startAddress)++];
    p->Q_LINKORIENTATION = stream[(*startAddress)++];
    p->Q_LINKREACTION = stream[(*startAddress)++];
    p->Q_LOCACC = stream[(*startAddress)++];
    return 1;
}


decompiled_code:
_BOOL8 __fastcall ModeProfile_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
_BOOL4 v3; // eax
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
int v6; // er8

v1 = UpperBitsNotSet64(a1[2], 2);
v2 = a1[10];
if ( !v1
|| !UpperBitsNotSet64(a1[3], 13)
|| !UpperBitsNotSet64(a1[4], 2)
|| !UpperBitsNotSet64(a1[5], 15)
|| !UpperBitsNotSet64(a1[6], 2)
|| !UpperBitsNotSet64(a1[7], 7)
|| !UpperBitsNotSet64(a1[8], 15)
|| !UpperBitsNotSet64(a1[9], 15) )
{
if ( !v2 )
return 0LL;
LODWORD(v4) = 0;
do
{
LABEL_17:
if ( (unsigned int)(v4 + 1) >= v2 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v2 );
return 0LL;
}
v3 = UpperBitsNotSet64(v2, 5);
if ( v2 )
{
LODWORD(v4) = 0;
if ( v3 )
{
v5 = 0LL;
while ( 1 )
{
v6 = ModeProfile_1_UpperBitsNotSet(&a1[5 * v5 + 11]);
v5 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v6 )
break;
if ( a1[10] <= v5 )
return 1LL;
}
v2 = a1[10];
if ( v2 > v5 )
goto LABEL_17;
return 0LL;
}
goto LABEL_17;
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
_BOOL4 v3; // eax
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
int v6; // er8

v1 = func0(a1[2], 2);
v2 = a1[10];
if ( !v1
|| !func0(a1[3], 13)
|| !func0(a1[4], 2)
|| !func0(a1[5], 15)
|| !func0(a1[6], 2)
|| !func0(a1[7], 7)
|| !func0(a1[8], 15)
|| !func0(a1[9], 15) )
{
if ( !v2 )
return 0LL;
LODWORD(v4) = 0;
do
{
LABEL_17:
if ( (unsigned int)(v4 + 1) >= v2 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v2 );
return 0LL;
}
v3 = func0(v2, 5);
if ( v2 )
{
LODWORD(v4) = 0;
if ( v3 )
{
v5 = 0LL;
while ( 1 )
{
v6 = ModeProfile_1_UpperBitsNotSet(&a1[5 * v5 + 11]);
v5 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v6 )
break;
if ( a1[10] <= v5 )
return 1LL;
}
v2 = a1[10];
if ( v2 > v5 )
goto LABEL_17;
return 0LL;
}
goto LABEL_17;
}
return v3;
}

original_code:
int ModeProfile_UpperBitsNotSet(const ModeProfile* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_MAMODE, 15);
    status = status && UpperBitsNotSet64(p->M_MAMODE, 2) ;
    status = status && UpperBitsNotSet64(p->V_MAMODE, 7) ;
    status = status && UpperBitsNotSet64(p->L_MAMODE, 15);
    status = status && UpperBitsNotSet64(p->L_ACKMAMODE, 15);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ModeProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ModeProfile_UpperBitsNotSet(struct ModeProfile *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_MAMODE, 15);
    status = status && UpperBitsNotSet64(p->M_MAMODE, 2) ;
    status = status && UpperBitsNotSet64(p->V_MAMODE, 7) ;
    status = status && UpperBitsNotSet64(p->L_MAMODE, 15);
    status = status && UpperBitsNotSet64(p->L_ACKMAMODE, 15);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ModeProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ModeProfile { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_MAMODE; unsigned long M_MAMODE; unsigned long V_MAMODE; unsigned long L_MAMODE; unsigned long L_ACKMAMODE; unsigned long N_ITER_1; struct ModeProfile_1 { unsigned long D_MAMODE; unsigned long M_MAMODE; unsigned long V_MAMODE; unsigned long L_MAMODE; unsigned long L_ACKMAMODE; } sub_1[31]; } *

user_defined_types: struct ModeProfile { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_MAMODE; unsigned long M_MAMODE; unsigned long V_MAMODE; unsigned long L_MAMODE; unsigned long L_ACKMAMODE; unsigned long N_ITER_1; struct ModeProfile_1 sub_1[31]; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 76LL) )
return 0xFFFFFFFFLL;
if ( !ModeProfile_UpperBitsNotSet(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 2LL, a1[6]);
Bitstream_Write(a2, 7LL, a1[7]);
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 15LL, a1[9]);
Bitstream_Write(a2, 5LL, a1[10]);
v3 = 0LL;
if ( a1[10] )
{
do
{
ModeProfile_1_EncodeBit(&a1[5 * v3 + 11], a2);
v3 = ++v2;
}
while ( v2 < a1[10] );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 v3; // rax

if ( !(unsigned int)Bitstream_Normal(a2, 76LL) )
return 0xFFFFFFFFLL;
if ( !func3(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 2LL, a1[6]);
Bitstream_Write(a2, 7LL, a1[7]);
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 15LL, a1[9]);
Bitstream_Write(a2, 5LL, a1[10]);
v3 = 0LL;
if ( a1[10] )
{
do
{
ModeProfile_1_EncodeBit(&a1[5 * v3 + 11], a2);
v3 = ++v2;
}
while ( v2 < a1[10] );
}
return 1LL;
}

original_code:
int ModeProfile_EncodeBit(const ModeProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 76))
    {
        if (ModeProfile_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_MAMODE);
            Bitstream_Write(stream, 2, p->M_MAMODE);
            Bitstream_Write(stream, 7, p->V_MAMODE);
            Bitstream_Write(stream, 15, p->L_MAMODE);
            Bitstream_Write(stream, 15, p->L_ACKMAMODE);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                ModeProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ModeProfile_EncodeBit(struct ModeProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 76))
    {
        if (ModeProfile_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_MAMODE);
            Bitstream_Write(stream, 2, p->M_MAMODE);
            Bitstream_Write(stream, 7, p->V_MAMODE);
            Bitstream_Write(stream, 15, p->L_MAMODE);
            Bitstream_Write(stream, 15, p->L_ACKMAMODE);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                ModeProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct PacketHeader { unsigned long NID_PACKET; unsigned long list; }

user_defined_types: struct ModeProfile_1 { unsigned long D_MAMODE; unsigned long M_MAMODE; unsigned long V_MAMODE; unsigned long L_MAMODE; unsigned long L_ACKMAMODE; }


decompiled_code:
__int64 __fastcall ModeProfile_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // er12
__int64 v4; // rdx
__int64 v5; // rax

result = Bitstream_Normal(a2, 76LL);
if ( (_DWORD)result )
{
v3 = 0;
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 2LL);
a1[5] = Bitstream_Read(a2, 15LL);
a1[6] = Bitstream_Read(a2, 2LL);
a1[7] = Bitstream_Read(a2, 7LL);
a1[8] = Bitstream_Read(a2, 15LL);
a1[9] = Bitstream_Read(a2, 15LL);
v4 = Bitstream_Read(a2, 5LL);
a1[10] = v4;
v5 = 0LL;
if ( v4 )
{
do
{
ModeProfile_1_DecodeBit(&a1[5 * v5 + 11], a2);
v5 = ++v3;
}
while ( (unsigned __int64)v3 < a1[10] );
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // er12
__int64 v4; // rdx
__int64 v5; // rax

result = Bitstream_Normal(a2, 76LL);
if ( (_DWORD)result )
{
v3 = 0;
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 2LL);
a1[5] = Bitstream_Read(a2, 15LL);
a1[6] = Bitstream_Read(a2, 2LL);
a1[7] = Bitstream_Read(a2, 7LL);
a1[8] = Bitstream_Read(a2, 15LL);
a1[9] = Bitstream_Read(a2, 15LL);
v4 = Bitstream_Read(a2, 5LL);
a1[10] = v4;
v5 = 0LL;
if ( v4 )
{
do
{
ModeProfile_1_DecodeBit(&a1[5 * v5 + 11], a2);
v5 = ++v3;
}
while ( (unsigned __int64)v3 < a1[10] );
}
result = 1LL;
}
return result;
}

original_code:
int ModeProfile_DecodeBit(ModeProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 76))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_MAMODE = Bitstream_Read(stream, 15);
        }
        {
            p->M_MAMODE = Bitstream_Read(stream, 2);
        }
        {
            p->V_MAMODE = Bitstream_Read(stream, 7);
        }
        {
            p->L_MAMODE = Bitstream_Read(stream, 15);
        }
        {
            p->L_ACKMAMODE = Bitstream_Read(stream, 15);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            ModeProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ModeProfile_DecodeBit(struct ModeProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 76))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_MAMODE = Bitstream_Read(stream, 15);
        }
        {
            p->M_MAMODE = Bitstream_Read(stream, 2);
        }
        {
            p->V_MAMODE = Bitstream_Read(stream, 7);
        }
        {
            p->L_MAMODE = Bitstream_Read(stream, 15);
        }
        {
            p->L_ACKMAMODE = Bitstream_Read(stream, 15);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            ModeProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int ModeProfile_EncodeInt(const ModeProfile* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 80;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->D_MAMODE;
    stream[startAddress++] = p->M_MAMODE;
    stream[startAddress++] = p->V_MAMODE;
    stream[startAddress++] = p->L_MAMODE;
    stream[startAddress++] = p->L_ACKMAMODE;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ModeProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int ModeProfile_EncodeInt(struct ModeProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 80;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->D_MAMODE;
    stream[startAddress++] = p->M_MAMODE;
    stream[startAddress++] = p->V_MAMODE;
    stream[startAddress++] = p->L_MAMODE;
    stream[startAddress++] = p->L_ACKMAMODE;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ModeProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

variable_types: startAddress int


original_code:
int ModeProfile_DecodeInt(ModeProfile* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 80)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->D_MAMODE = stream[startAddress++];
    p->M_MAMODE = stream[startAddress++];
    p->V_MAMODE = stream[startAddress++];
    p->L_MAMODE = stream[startAddress++];
    p->L_ACKMAMODE = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ModeProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int ModeProfile_DecodeInt(struct ModeProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 80)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->D_MAMODE = stream[startAddress++];
    p->M_MAMODE = stream[startAddress++];
    p->V_MAMODE = stream[startAddress++];
    p->L_MAMODE = stream[startAddress++];
    p->L_ACKMAMODE = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ModeProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


decompiled_code:
__int64 ModeProfile_New()
{
__int64 *v0; // r8
__int64 v1; // r8
__int64 v3; // r8

if ( ModeProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)ModeProfileMemoryTop > 7 )
return 0LL;
v3 = 166 * ModeProfileMemoryTop++;
v0 = &ModeProfileMemory[v3];
}
else
{
v0 = &ModeProfileMemory[166 * ModeProfileMemoryFreeList];
ModeProfileMemoryFreeList = *v0;
}
ModeProfile_Init(v0);
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 *v0; // r8
__int64 v1; // r8
__int64 v3; // r8

if ( ModeProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)ModeProfileMemoryTop > 7 )
return 0LL;
v3 = 166 * ModeProfileMemoryTop++;
v0 = &ModeProfileMemory[v3];
}
else
{
v0 = &ModeProfileMemory[166 * ModeProfileMemoryFreeList];
ModeProfileMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
ModeProfile* ModeProfile_New(void)
{
    ModeProfile* ptr;
    if (ModeProfileMemoryFreeList != (-1))
    {
        ptr = &ModeProfileMemory[ModeProfileMemoryFreeList];
        ModeProfileMemoryFreeList = ModeProfileMemory[ModeProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (ModeProfileMemoryTop < 8)
    {
        ptr = &ModeProfileMemory[ModeProfileMemoryTop];
        ModeProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ModeProfile_Init(ptr);
    return ptr;
}

canonical_original_code:
struct ModeProfile *ModeProfile_New()
{
    struct ModeProfile *ptr;
    if (ModeProfileMemoryFreeList != (-1))
    {
        ptr = &ModeProfileMemory[ModeProfileMemoryFreeList];
        ModeProfileMemoryFreeList = ModeProfileMemory[ModeProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (ModeProfileMemoryTop < 8)
    {
        ptr = &ModeProfileMemory[ModeProfileMemoryTop];
        ModeProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ModeProfile_Init(ptr);
    return ptr;
}

return_type: struct ModeProfile { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_MAMODE; unsigned long M_MAMODE; unsigned long V_MAMODE; unsigned long L_MAMODE; unsigned long L_ACKMAMODE; unsigned long N_ITER_1; struct ModeProfile_1 { unsigned long D_MAMODE; unsigned long M_MAMODE; unsigned long V_MAMODE; unsigned long L_MAMODE; unsigned long L_ACKMAMODE; } sub_1[31]; } *


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

*(_QWORD *)a1 = ModeProfileMemoryFreeList;
result = 0xA3784A062B2E43DBLL;
ModeProfileMemoryFreeList = 0xA3784A062B2E43DBLL * ((a1 - (char *)ModeProfileMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = ModeProfileMemoryFreeList;
result = 0xA3784A062B2E43DBLL;
ModeProfileMemoryFreeList = 0xA3784A062B2E43DBLL * ((a1 - (char *)ModeProfileMemory) >> 4);
return result;
}

original_code:
void ModeProfile_Delete(ModeProfile* ptr)
{
    ptr->header.NID_PACKET = ModeProfileMemoryFreeList;
    ModeProfileMemoryFreeList = ptr - ModeProfileMemory;
}

canonical_original_code:
void ModeProfile_Delete(struct ModeProfile *ptr)
{
    ptr->header.NID_PACKET = ModeProfileMemoryFreeList;
    ModeProfileMemoryFreeList = ptr - ModeProfileMemory;
}

return_type: void


original_code:
static inline int UpperBitsNotSet64(uint64_t value, uint32_t length)
{
    if (length == 64)
    {
        return 1;
    }
    else
    {
        const uint64_t MaxValue = ((uint64_t) 1) << length;
        return value < MaxValue;
    }
}

canonical_original_code:
static inline int UpperBitsNotSet64(unsigned long value, unsigned int length)
{
    if (length == 64)
    {
        return 1;
    }
    else
    {
        unsigned long MaxValue = ((uint64_t) 1) << length;
        return value < MaxValue;
    }
}


decompiled_code:
_BOOL8 __fastcall ValidatedTrainData_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rbp
unsigned __int64 v4; // rdx
unsigned __int64 v6; // rbp
_BOOL4 v7; // eax
unsigned __int64 v8; // rax
int v9; // er8
_BOOL4 v10; // eax
unsigned __int64 v11; // rax
int v12; // er8

v1 = UpperBitsNotSet64(a1[2], 13);
v2 = a1[10];
if ( !v1
|| !UpperBitsNotSet64(a1[3], 32)
|| !UpperBitsNotSet64(a1[4], 15)
|| !UpperBitsNotSet64(a1[5], 12)
|| !UpperBitsNotSet64(a1[6], 7)
|| !UpperBitsNotSet64(a1[7], 8)
|| !UpperBitsNotSet64(a1[8], 7)
|| !UpperBitsNotSet64(a1[9], 2) )
{
LODWORD(v3) = 0;
if ( !v2 )
goto LABEL_6;
goto LABEL_4;
}
v7 = UpperBitsNotSet64(v2, 5);
if ( v2 )
{
LODWORD(v3) = 0;
if ( v7 )
{
v8 = 0LL;
while ( 1 )
{
v9 = ValidatedTrainData_1_UpperBitsNotSet(&a1[v8 + 11]);
v8 = (unsigned int)(v3 + 1);
LODWORD(v3) = v3 + 1;
if ( !v9 )
break;
if ( a1[10] <= v8 )
goto LABEL_26;
}
v2 = a1[10];
if ( v2 <= v8 )
{
v4 = a1[42];
if ( v4 )
goto LABEL_8;
return 0LL;
}
}
do
{
LABEL_4:
if ( (unsigned int)(v3 + 1) >= v2 )
break;
v3 = (unsigned int)(v3 + 2);
}
while ( v3 < v2 );
LABEL_6:
v4 = a1[42];
if ( v4 )
{
LABEL_8:
LODWORD(v6) = 0;
do
{
LABEL_9:
if ( (unsigned int)(v6 + 1) >= v4 )
break;
v6 = (unsigned int)(v6 + 2);
}
while ( v6 < v4 );
}
return 0LL;
}
if ( !v7 )
goto LABEL_6;
LABEL_26:
v10 = UpperBitsNotSet64(a1[42], 5);
if ( v4 )
{
LODWORD(v6) = 0;
if ( v10 )
{
v11 = 0LL;
while ( 1 )
{
v12 = ValidatedTrainData_2_UpperBitsNotSet(&a1[v11 + 43]);
v11 = (unsigned int)(v6 + 1);
LODWORD(v6) = v6 + 1;
if ( !v12 )
break;
if ( a1[42] <= v11 )
return 1LL;
}
v4 = a1[42];
if ( v4 > v11 )
goto LABEL_9;
return 0LL;
}
goto LABEL_9;
}
return v10;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rbp
unsigned __int64 v4; // rdx
unsigned __int64 v6; // rbp
_BOOL4 v7; // eax
unsigned __int64 v8; // rax
int v9; // er8
_BOOL4 v10; // eax
unsigned __int64 v11; // rax
int v12; // er8

v1 = func0(a1[2], 13);
v2 = a1[10];
if ( !v1
|| !func0(a1[3], 32)
|| !func0(a1[4], 15)
|| !func0(a1[5], 12)
|| !func0(a1[6], 7)
|| !func0(a1[7], 8)
|| !func0(a1[8], 7)
|| !func0(a1[9], 2) )
{
LODWORD(v3) = 0;
if ( !v2 )
goto LABEL_6;
goto LABEL_4;
}
v7 = func0(v2, 5);
if ( v2 )
{
LODWORD(v3) = 0;
if ( v7 )
{
v8 = 0LL;
while ( 1 )
{
v9 = ValidatedTrainData_1_UpperBitsNotSet(&a1[v8 + 11]);
v8 = (unsigned int)(v3 + 1);
LODWORD(v3) = v3 + 1;
if ( !v9 )
break;
if ( a1[10] <= v8 )
goto LABEL_26;
}
v2 = a1[10];
if ( v2 <= v8 )
{
v4 = a1[42];
if ( v4 )
goto LABEL_8;
return 0LL;
}
}
do
{
LABEL_4:
if ( (unsigned int)(v3 + 1) >= v2 )
break;
v3 = (unsigned int)(v3 + 2);
}
while ( v3 < v2 );
LABEL_6:
v4 = a1[42];
if ( v4 )
{
LABEL_8:
LODWORD(v6) = 0;
do
{
LABEL_9:
if ( (unsigned int)(v6 + 1) >= v4 )
break;
v6 = (unsigned int)(v6 + 2);
}
while ( v6 < v4 );
}
return 0LL;
}
if ( !v7 )
goto LABEL_6;
LABEL_26:
v10 = func0(a1[42], 5);
if ( v4 )
{
LODWORD(v6) = 0;
if ( v10 )
{
v11 = 0LL;
while ( 1 )
{
v12 = ValidatedTrainData_2_UpperBitsNotSet(&a1[v11 + 43]);
v11 = (unsigned int)(v6 + 1);
LODWORD(v6) = v6 + 1;
if ( !v12 )
break;
if ( a1[42] <= v11 )
return 1LL;
}
v4 = a1[42];
if ( v4 > v11 )
goto LABEL_9;
return 0LL;
}
goto LABEL_9;
}
return v10;
}

original_code:
int ValidatedTrainData_UpperBitsNotSet(const ValidatedTrainData* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->NID_OPERATIONAL, 32);
    status = status && UpperBitsNotSet64(p->NC_TRAIN, 15);
    status = status && UpperBitsNotSet64(p->L_TRAIN, 12);
    status = status && UpperBitsNotSet64(p->V_MAXTRAIN, 7) ;
    status = status && UpperBitsNotSet64(p->M_LOADINGGAUGE, 8) ;
    status = status && UpperBitsNotSet64(p->M_AXLELOAD, 7) ;
    status = status && UpperBitsNotSet64(p->M_AIRTIGHT, 2) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ValidatedTrainData_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->N_ITER_2, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        status = status && ValidatedTrainData_2_UpperBitsNotSet(&(p->sub_2[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ValidatedTrainData_UpperBitsNotSet(struct ValidatedTrainData *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->NID_OPERATIONAL, 32);
    status = status && UpperBitsNotSet64(p->NC_TRAIN, 15);
    status = status && UpperBitsNotSet64(p->L_TRAIN, 12);
    status = status && UpperBitsNotSet64(p->V_MAXTRAIN, 7) ;
    status = status && UpperBitsNotSet64(p->M_LOADINGGAUGE, 8) ;
    status = status && UpperBitsNotSet64(p->M_AXLELOAD, 7) ;
    status = status && UpperBitsNotSet64(p->M_AIRTIGHT, 2) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ValidatedTrainData_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->N_ITER_2, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        status = status && ValidatedTrainData_2_UpperBitsNotSet(&(p->sub_2[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ValidatedTrainData { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long NID_OPERATIONAL; unsigned long NC_TRAIN; unsigned long L_TRAIN; unsigned long V_MAXTRAIN; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_AIRTIGHT; unsigned long N_ITER_1; struct ValidatedTrainData_1 { unsigned long M_TRACTION; } sub_1[31]; unsigned long N_ITER_2; struct ValidatedTrainData_2 { unsigned long NID_STM; } sub_2[31]; } *

user_defined_types: struct ValidatedTrainData { struct PacketHeader header; unsigned long L_PACKET; unsigned long NID_OPERATIONAL; unsigned long NC_TRAIN; unsigned long L_TRAIN; unsigned long V_MAXTRAIN; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_AIRTIGHT; unsigned long N_ITER_1; struct ValidatedTrainData_1 sub_1[31]; unsigned long N_ITER_2; struct ValidatedTrainData_2 sub_2[31]; }


decompiled_code:
__int64 __fastcall ValidatedTrainData_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rax
unsigned int v4; // er12
__int64 v5; // rax

if ( !(unsigned int)Bitstream_Normal(a2, 106LL) )
return 0xFFFFFFFFLL;
if ( !ValidatedTrainData_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 13LL, a1[2]);
Bitstream_Write(a2, 32LL, a1[3]);
Bitstream_Write(a2, 15LL, a1[4]);
Bitstream_Write(a2, 12LL, a1[5]);
Bitstream_Write(a2, 7LL, a1[6]);
Bitstream_Write(a2, 8LL, a1[7]);
Bitstream_Write(a2, 7LL, a1[8]);
Bitstream_Write(a2, 2LL, a1[9]);
Bitstream_Write(a2, 5LL, a1[10]);
if ( a1[10] )
{
v2 = 0;
v3 = 0LL;
do
{
ValidatedTrainData_1_EncodeBit(&a1[v3 + 11], a2);
v3 = ++v2;
}
while ( v2 < a1[10] );
}
v4 = 0;
Bitstream_Write(a2, 5LL, a1[42]);
v5 = 0LL;
if ( a1[42] )
{
do
{
ValidatedTrainData_2_EncodeBit(&a1[v5 + 43], a2);
v5 = ++v4;
}
while ( v4 < a1[42] );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rax
unsigned int v4; // er12
__int64 v5; // rax

if ( !(unsigned int)Bitstream_Normal(a2, 106LL) )
return 0xFFFFFFFFLL;
if ( !func4(a1) )
return 4294967294LL;
Bitstream_Write(a2, 13LL, a1[2]);
Bitstream_Write(a2, 32LL, a1[3]);
Bitstream_Write(a2, 15LL, a1[4]);
Bitstream_Write(a2, 12LL, a1[5]);
Bitstream_Write(a2, 7LL, a1[6]);
Bitstream_Write(a2, 8LL, a1[7]);
Bitstream_Write(a2, 7LL, a1[8]);
Bitstream_Write(a2, 2LL, a1[9]);
Bitstream_Write(a2, 5LL, a1[10]);
if ( a1[10] )
{
v2 = 0;
v3 = 0LL;
do
{
ValidatedTrainData_1_EncodeBit(&a1[v3 + 11], a2);
v3 = ++v2;
}
while ( v2 < a1[10] );
}
v4 = 0;
Bitstream_Write(a2, 5LL, a1[42]);
v5 = 0LL;
if ( a1[42] )
{
do
{
ValidatedTrainData_2_EncodeBit(&a1[v5 + 43], a2);
v5 = ++v4;
}
while ( v4 < a1[42] );
}
return 1LL;
}

original_code:
int ValidatedTrainData_EncodeBit(const ValidatedTrainData* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 106))
    {
        if (ValidatedTrainData_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 32, p->NID_OPERATIONAL);
            Bitstream_Write(stream, 15, p->NC_TRAIN);
            Bitstream_Write(stream, 12, p->L_TRAIN);
            Bitstream_Write(stream, 7, p->V_MAXTRAIN);
            Bitstream_Write(stream, 8, p->M_LOADINGGAUGE);
            Bitstream_Write(stream, 7, p->M_AXLELOAD);
            Bitstream_Write(stream, 2, p->M_AIRTIGHT);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                ValidatedTrainData_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 5, p->N_ITER_2);
            for (uint32_t i = 0; i < p->N_ITER_2; ++i)
            {
                ValidatedTrainData_2_EncodeBit(&(p->sub_2[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ValidatedTrainData_EncodeBit(struct ValidatedTrainData *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 106))
    {
        if (ValidatedTrainData_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 32, p->NID_OPERATIONAL);
            Bitstream_Write(stream, 15, p->NC_TRAIN);
            Bitstream_Write(stream, 12, p->L_TRAIN);
            Bitstream_Write(stream, 7, p->V_MAXTRAIN);
            Bitstream_Write(stream, 8, p->M_LOADINGGAUGE);
            Bitstream_Write(stream, 7, p->M_AXLELOAD);
            Bitstream_Write(stream, 2, p->M_AIRTIGHT);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                ValidatedTrainData_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 5, p->N_ITER_2);
            for (unsigned int i = 0; i < p->N_ITER_2; ++i)
            {
                ValidatedTrainData_2_EncodeBit(&(p->sub_2[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct ValidatedTrainData_1 { unsigned long M_TRACTION; }

user_defined_types: struct ValidatedTrainData_2 { unsigned long NID_STM; }


decompiled_code:
__int64 __fastcall ValidatedTrainData_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // er12
__int64 v5; // rax
unsigned int v6; // er12
__int64 v7; // rdx
__int64 v8; // rax

result = Bitstream_Normal(a2, 106LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 13LL);
a1[3] = Bitstream_Read(a2, 32LL);
a1[4] = Bitstream_Read(a2, 15LL);
a1[5] = Bitstream_Read(a2, 12LL);
a1[6] = Bitstream_Read(a2, 7LL);
a1[7] = Bitstream_Read(a2, 8LL);
a1[8] = Bitstream_Read(a2, 7LL);
a1[9] = Bitstream_Read(a2, 2LL);
v3 = Bitstream_Read(a2, 5LL);
a1[10] = v3;
if ( v3 )
{
v4 = 0;
v5 = 0LL;
do
{
ValidatedTrainData_1_DecodeBit(&a1[v5 + 11], a2);
v5 = ++v4;
}
while ( (unsigned __int64)v4 < a1[10] );
}
v6 = 0;
v7 = Bitstream_Read(a2, 5LL);
a1[42] = v7;
v8 = 0LL;
if ( v7 )
{
do
{
ValidatedTrainData_2_DecodeBit(&a1[v8 + 43], a2);
v8 = ++v6;
}
while ( (unsigned __int64)v6 < a1[42] );
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // er12
__int64 v5; // rax
unsigned int v6; // er12
__int64 v7; // rdx
__int64 v8; // rax

result = Bitstream_Normal(a2, 106LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 13LL);
a1[3] = Bitstream_Read(a2, 32LL);
a1[4] = Bitstream_Read(a2, 15LL);
a1[5] = Bitstream_Read(a2, 12LL);
a1[6] = Bitstream_Read(a2, 7LL);
a1[7] = Bitstream_Read(a2, 8LL);
a1[8] = Bitstream_Read(a2, 7LL);
a1[9] = Bitstream_Read(a2, 2LL);
v3 = Bitstream_Read(a2, 5LL);
a1[10] = v3;
if ( v3 )
{
v4 = 0;
v5 = 0LL;
do
{
ValidatedTrainData_1_DecodeBit(&a1[v5 + 11], a2);
v5 = ++v4;
}
while ( (unsigned __int64)v4 < a1[10] );
}
v6 = 0;
v7 = Bitstream_Read(a2, 5LL);
a1[42] = v7;
v8 = 0LL;
if ( v7 )
{
do
{
ValidatedTrainData_2_DecodeBit(&a1[v8 + 43], a2);
v8 = ++v6;
}
while ( (unsigned __int64)v6 < a1[42] );
}
result = 1LL;
}
return result;
}

original_code:
int ValidatedTrainData_DecodeBit(ValidatedTrainData* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 106))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->NID_OPERATIONAL = Bitstream_Read(stream, 32);
        }
        {
            p->NC_TRAIN = Bitstream_Read(stream, 15);
        }
        {
            p->L_TRAIN = Bitstream_Read(stream, 12);
        }
        {
            p->V_MAXTRAIN = Bitstream_Read(stream, 7);
        }
        {
            p->M_LOADINGGAUGE = Bitstream_Read(stream, 8);
        }
        {
            p->M_AXLELOAD = Bitstream_Read(stream, 7);
        }
        {
            p->M_AIRTIGHT = Bitstream_Read(stream, 2);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            ValidatedTrainData_1_DecodeBit(&(p->sub_1[i]), stream);
        }
    {
            p->N_ITER_2 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_2; ++i)
        {
            ValidatedTrainData_2_DecodeBit(&(p->sub_2[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ValidatedTrainData_DecodeBit(struct ValidatedTrainData *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 106))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->NID_OPERATIONAL = Bitstream_Read(stream, 32);
        }
        {
            p->NC_TRAIN = Bitstream_Read(stream, 15);
        }
        {
            p->L_TRAIN = Bitstream_Read(stream, 12);
        }
        {
            p->V_MAXTRAIN = Bitstream_Read(stream, 7);
        }
        {
            p->M_LOADINGGAUGE = Bitstream_Read(stream, 8);
        }
        {
            p->M_AXLELOAD = Bitstream_Read(stream, 7);
        }
        {
            p->M_AIRTIGHT = Bitstream_Read(stream, 2);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            ValidatedTrainData_1_DecodeBit(&(p->sub_1[i]), stream);
        }
    {
            p->N_ITER_2 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_2; ++i)
        {
            ValidatedTrainData_2_DecodeBit(&(p->sub_2[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int ValidatedTrainData_EncodeInt(const ValidatedTrainData* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 11;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->NID_OPERATIONAL;
    stream[startAddress++] = p->NC_TRAIN;
    stream[startAddress++] = p->L_TRAIN;
    stream[startAddress++] = p->V_MAXTRAIN;
    stream[startAddress++] = p->M_LOADINGGAUGE;
    stream[startAddress++] = p->M_AXLELOAD;
    stream[startAddress++] = p->M_AIRTIGHT;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ValidatedTrainData_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    stream[startAddress++] = p->N_ITER_2;
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        ValidatedTrainData_2_EncodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int ValidatedTrainData_EncodeInt(struct ValidatedTrainData *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 11;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->NID_OPERATIONAL;
    stream[startAddress++] = p->NC_TRAIN;
    stream[startAddress++] = p->L_TRAIN;
    stream[startAddress++] = p->V_MAXTRAIN;
    stream[startAddress++] = p->M_LOADINGGAUGE;
    stream[startAddress++] = p->M_AXLELOAD;
    stream[startAddress++] = p->M_AIRTIGHT;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ValidatedTrainData_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    stream[startAddress++] = p->N_ITER_2;
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        ValidatedTrainData_2_EncodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int ValidatedTrainData_DecodeInt(ValidatedTrainData* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 11)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->NID_OPERATIONAL = stream[startAddress++];
    p->NC_TRAIN = stream[startAddress++];
    p->L_TRAIN = stream[startAddress++];
    p->V_MAXTRAIN = stream[startAddress++];
    p->M_LOADINGGAUGE = stream[startAddress++];
    p->M_AXLELOAD = stream[startAddress++];
    p->M_AIRTIGHT = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ValidatedTrainData_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    p->N_ITER_2 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        ValidatedTrainData_2_DecodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int ValidatedTrainData_DecodeInt(struct ValidatedTrainData *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 11)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->NID_OPERATIONAL = stream[startAddress++];
    p->NC_TRAIN = stream[startAddress++];
    p->L_TRAIN = stream[startAddress++];
    p->V_MAXTRAIN = stream[startAddress++];
    p->M_LOADINGGAUGE = stream[startAddress++];
    p->M_AXLELOAD = stream[startAddress++];
    p->M_AIRTIGHT = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ValidatedTrainData_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    p->N_ITER_2 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        ValidatedTrainData_2_DecodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


decompiled_code:
__int64 ValidatedTrainData_New()
{
__int64 *v0; // r8
__int64 v1; // r8
__int64 v3; // r8

if ( ValidatedTrainDataMemoryFreeList == -1 )
{
if ( (unsigned __int64)ValidatedTrainDataMemoryTop > 7 )
return 0LL;
v3 = 74 * ValidatedTrainDataMemoryTop++;
v0 = &ValidatedTrainDataMemory[v3];
}
else
{
v0 = &ValidatedTrainDataMemory[74 * ValidatedTrainDataMemoryFreeList];
ValidatedTrainDataMemoryFreeList = *v0;
}
ValidatedTrainData_Init(v0);
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 *v0; // r8
__int64 v1; // r8
__int64 v3; // r8

if ( ValidatedTrainDataMemoryFreeList == -1 )
{
if ( (unsigned __int64)ValidatedTrainDataMemoryTop > 7 )
return 0LL;
v3 = 74 * ValidatedTrainDataMemoryTop++;
v0 = &ValidatedTrainDataMemory[v3];
}
else
{
v0 = &ValidatedTrainDataMemory[74 * ValidatedTrainDataMemoryFreeList];
ValidatedTrainDataMemoryFreeList = *v0;
}
func3(v0);
return v1;
}

original_code:
ValidatedTrainData* ValidatedTrainData_New(void)
{
    ValidatedTrainData* ptr;
    if (ValidatedTrainDataMemoryFreeList != (-1))
    {
        ptr = &ValidatedTrainDataMemory[ValidatedTrainDataMemoryFreeList];
        ValidatedTrainDataMemoryFreeList = ValidatedTrainDataMemory[ValidatedTrainDataMemoryFreeList].header.NID_PACKET;
    }
    else if (ValidatedTrainDataMemoryTop < 8)
    {
        ptr = &ValidatedTrainDataMemory[ValidatedTrainDataMemoryTop];
        ValidatedTrainDataMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ValidatedTrainData_Init(ptr);
    return ptr;
}

canonical_original_code:
struct ValidatedTrainData *ValidatedTrainData_New()
{
    struct ValidatedTrainData *ptr;
    if (ValidatedTrainDataMemoryFreeList != (-1))
    {
        ptr = &ValidatedTrainDataMemory[ValidatedTrainDataMemoryFreeList];
        ValidatedTrainDataMemoryFreeList = ValidatedTrainDataMemory[ValidatedTrainDataMemoryFreeList].header.NID_PACKET;
    }
    else if (ValidatedTrainDataMemoryTop < 8)
    {
        ptr = &ValidatedTrainDataMemory[ValidatedTrainDataMemoryTop];
        ValidatedTrainDataMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ValidatedTrainData_Init(ptr);
    return ptr;
}

return_type: struct ValidatedTrainData { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long NID_OPERATIONAL; unsigned long NC_TRAIN; unsigned long L_TRAIN; unsigned long V_MAXTRAIN; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_AIRTIGHT; unsigned long N_ITER_1; struct ValidatedTrainData_1 { unsigned long M_TRACTION; } sub_1[31]; unsigned long N_ITER_2; struct ValidatedTrainData_2 { unsigned long NID_STM; } sub_2[31]; } *


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

*(_QWORD *)a1 = ValidatedTrainDataMemoryFreeList;
result = 0x14C1BACF914C1BADLL;
ValidatedTrainDataMemoryFreeList = 0x14C1BACF914C1BADLL * ((a1 - (char *)ValidatedTrainDataMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = ValidatedTrainDataMemoryFreeList;
result = 0x14C1BACF914C1BADLL;
ValidatedTrainDataMemoryFreeList = 0x14C1BACF914C1BADLL * ((a1 - (char *)ValidatedTrainDataMemory) >> 4);
return result;
}

original_code:
void ValidatedTrainData_Delete(ValidatedTrainData* ptr)
{
    ptr->header.NID_PACKET = ValidatedTrainDataMemoryFreeList;
    ValidatedTrainDataMemoryFreeList = ptr - ValidatedTrainDataMemory;
}

canonical_original_code:
void ValidatedTrainData_Delete(struct ValidatedTrainData *ptr)
{
    ptr->header.NID_PACKET = ValidatedTrainDataMemoryFreeList;
    ValidatedTrainDataMemoryFreeList = ptr - ValidatedTrainDataMemory;
}


decompiled_code:
_BOOL8 __fastcall AdhesionFactor_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 13);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 32), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v4 + 40), 15);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v5 + 48), 15);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v6 + 56), 1);
}
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx

result = func0(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = func0(*(_QWORD *)(v2 + 24), 13);
if ( result )
{
result = func0(*(_QWORD *)(v3 + 32), 2);
if ( result )
{
result = func0(*(_QWORD *)(v4 + 40), 15);
if ( result )
{
result = func0(*(_QWORD *)(v5 + 48), 15);
if ( result )
result = func0(*(_QWORD *)(v6 + 56), 1);
}
}
}
}
return result;
}

original_code:
int AdhesionFactor_UpperBitsNotSet(const AdhesionFactor* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_ADHESION, 15);
    status = status && UpperBitsNotSet64(p->L_ADHESION, 15);
    status = status && UpperBitsNotSet64(p->M_ADHESION, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AdhesionFactor_UpperBitsNotSet(struct AdhesionFactor *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_ADHESION, 15);
    status = status && UpperBitsNotSet64(p->L_ADHESION, 15);
    status = status && UpperBitsNotSet64(p->M_ADHESION, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct AdhesionFactor { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_ADHESION; unsigned long L_ADHESION; unsigned long M_ADHESION; } *

user_defined_types: struct AdhesionFactor { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_ADHESION; unsigned long L_ADHESION; unsigned long M_ADHESION; }


decompiled_code:
__int64 __fastcall AdhesionFactor_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 48LL) )
return 0xFFFFFFFFLL;
if ( !AdhesionFactor_UpperBitsNotSet((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 1LL, a1[7]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 48LL) )
return 0xFFFFFFFFLL;
if ( !func2((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 1LL, a1[7]);
return 1LL;
}

original_code:
int AdhesionFactor_EncodeBit(const AdhesionFactor* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 48))
    {
        if (AdhesionFactor_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_ADHESION);
            Bitstream_Write(stream, 15, p->L_ADHESION);
            Bitstream_Write(stream, 1, p->M_ADHESION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int AdhesionFactor_EncodeBit(struct AdhesionFactor *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 48))
    {
        if (AdhesionFactor_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_ADHESION);
            Bitstream_Write(stream, 15, p->L_ADHESION);
            Bitstream_Write(stream, 1, p->M_ADHESION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


decompiled_code:
__int64 __fastcall AdhesionFactor_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = Bitstream_Normal(a2, 48LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 2LL);
a1[5] = Bitstream_Read(a2, 15LL);
a1[6] = Bitstream_Read(a2, 15LL);
a1[7] = Bitstream_Read(a2, 1LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = Bitstream_Normal(a2, 48LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 2LL);
a1[5] = Bitstream_Read(a2, 15LL);
a1[6] = Bitstream_Read(a2, 15LL);
a1[7] = Bitstream_Read(a2, 1LL);
result = 1LL;
}
return result;
}

original_code:
int AdhesionFactor_DecodeBit(AdhesionFactor* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 48))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_ADHESION = Bitstream_Read(stream, 15);
        }
        {
            p->L_ADHESION = Bitstream_Read(stream, 15);
        }
        {
            p->M_ADHESION = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AdhesionFactor_DecodeBit(struct AdhesionFactor *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 48))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_ADHESION = Bitstream_Read(stream, 15);
        }
        {
            p->L_ADHESION = Bitstream_Read(stream, 15);
        }
        {
            p->M_ADHESION = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int AdhesionFactor_EncodeInt(const AdhesionFactor* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 71;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->D_ADHESION;
    stream[startAddress++] = p->L_ADHESION;
    stream[startAddress++] = p->M_ADHESION;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int AdhesionFactor_EncodeInt(struct AdhesionFactor *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 71;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->D_ADHESION;
    stream[startAddress++] = p->L_ADHESION;
    stream[startAddress++] = p->M_ADHESION;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int AdhesionFactor_DecodeInt(AdhesionFactor* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 71)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->D_ADHESION = stream[startAddress++];
    p->L_ADHESION = stream[startAddress++];
    p->M_ADHESION = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int AdhesionFactor_DecodeInt(struct AdhesionFactor *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 71)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->D_ADHESION = stream[startAddress++];
    p->L_ADHESION = stream[startAddress++];
    p->M_ADHESION = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


decompiled_code:
__int64 AdhesionFactor_New()
{
__int64 *v0; // r8
__int64 v1; // r8
__int64 v3; // r8

if ( AdhesionFactorMemoryFreeList == -1 )
{
if ( (unsigned __int64)AdhesionFactorMemoryTop > 7 )
return 0LL;
v3 = AdhesionFactorMemoryTop++ << 6;
v0 = (__int64 *)((char *)AdhesionFactorMemory + v3);
}
else
{
v0 = &AdhesionFactorMemory[8 * AdhesionFactorMemoryFreeList];
AdhesionFactorMemoryFreeList = *v0;
}
AdhesionFactor_Init(v0);
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 *v0; // r8
__int64 v1; // r8
__int64 v3; // r8

if ( AdhesionFactorMemoryFreeList == -1 )
{
if ( (unsigned __int64)AdhesionFactorMemoryTop > 7 )
return 0LL;
v3 = AdhesionFactorMemoryTop++ << 6;
v0 = (__int64 *)((char *)AdhesionFactorMemory + v3);
}
else
{
v0 = &AdhesionFactorMemory[8 * AdhesionFactorMemoryFreeList];
AdhesionFactorMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
AdhesionFactor* AdhesionFactor_New(void)
{
    AdhesionFactor* ptr;
    if (AdhesionFactorMemoryFreeList != (-1))
    {
        ptr = &AdhesionFactorMemory[AdhesionFactorMemoryFreeList];
        AdhesionFactorMemoryFreeList = AdhesionFactorMemory[AdhesionFactorMemoryFreeList].header.NID_PACKET;
    }
    else if (AdhesionFactorMemoryTop < 8)
    {
        ptr = &AdhesionFactorMemory[AdhesionFactorMemoryTop];
        AdhesionFactorMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    AdhesionFactor_Init(ptr);
    return ptr;
}

canonical_original_code:
struct AdhesionFactor *AdhesionFactor_New()
{
    struct AdhesionFactor *ptr;
    if (AdhesionFactorMemoryFreeList != (-1))
    {
        ptr = &AdhesionFactorMemory[AdhesionFactorMemoryFreeList];
        AdhesionFactorMemoryFreeList = AdhesionFactorMemory[AdhesionFactorMemoryFreeList].header.NID_PACKET;
    }
    else if (AdhesionFactorMemoryTop < 8)
    {
        ptr = &AdhesionFactorMemory[AdhesionFactorMemoryTop];
        AdhesionFactorMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    AdhesionFactor_Init(ptr);
    return ptr;
}

return_type: struct AdhesionFactor { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_ADHESION; unsigned long L_ADHESION; unsigned long M_ADHESION; } *


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

result = AdhesionFactorMemoryFreeList;
*(_QWORD *)a1 = AdhesionFactorMemoryFreeList;
AdhesionFactorMemoryFreeList = (a1 - (char *)AdhesionFactorMemory) >> 6;
return result;
}

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

result = AdhesionFactorMemoryFreeList;
*(_QWORD *)a1 = AdhesionFactorMemoryFreeList;
AdhesionFactorMemoryFreeList = (a1 - (char *)AdhesionFactorMemory) >> 6;
return result;
}

original_code:
void AdhesionFactor_Delete(AdhesionFactor* ptr)
{
    ptr->header.NID_PACKET = AdhesionFactorMemoryFreeList;
    AdhesionFactorMemoryFreeList = ptr - AdhesionFactorMemory;
}

canonical_original_code:
void AdhesionFactor_Delete(struct AdhesionFactor *ptr)
{
    ptr->header.NID_PACKET = AdhesionFactorMemoryFreeList;
    AdhesionFactorMemoryFreeList = ptr - AdhesionFactorMemory;
}