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

result = Bitstream_Normal(a1, 64LL);
if ( (_DWORD)result )
{
*a2 = Bitstream_Read(a1, 64LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a1, 64LL);
if ( (_DWORD)result )
{
*a2 = Bitstream_Read(a1, 64LL);
result = 1LL;
}
return result;
}

original_code:
int Onboard_telephone_numbers_Core_1_Decode_Bit(Bitstream* stream, Onboard_telephone_numbers_Core_1* p)
{
    if (Bitstream_Normal(stream, 64))
    {
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Onboard_telephone_numbers_Core_1_Decode_Bit(struct Bitstream *stream, struct Onboard_telephone_numbers_Core_1 *p)
{
    if (Bitstream_Normal(stream, 64))
    {
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

user_defined_types: struct Onboard_telephone_numbers_Core_1 { unsigned long NID_RADIO; }


repo: openETCS/dataDictionary

decompiled_code:
__int64 __fastcall Onboard_telephone_numbers_Core_1_Encode_Int(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v3; // rdx
int v4; // eax

v3 = *a3;
v4 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = v4 + 1;
*(_DWORD *)(a2 + 4LL * v4) = v3;
return 1LL;
}

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

canonical_original_code:
int Onboard_telephone_numbers_Core_1_Encode_Int(struct MetadataElement_T_Common_Types_Pkg *data, int *stream, struct Onboard_telephone_numbers_Core_1 *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 *

variable_types: struct Onboard_telephone_numbers_Core_1 { unsigned long NID_RADIO; } *

return_type: int


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

v3 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = v3 + 1;
*a3 = *(int *)(a2 + 4LL * v3);
return 1LL;
}

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

canonical_original_code:
int Onboard_telephone_numbers_Core_1_Decode_Int(struct MetadataElement_T_Common_Types_Pkg *data, int *stream, struct Onboard_telephone_numbers_Core_1 *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 UpperBitsNotSet64(unsigned __int64 a1, int a2)
{
_BOOL8 result; // rax

result = 1LL;
if ( a2 != 64 )
result = 1LL << a2 > a1;
return result;
}

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

result = 1LL;
if ( a2 != 64 )
result = 1LL << a2 > a1;
return result;
}

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:
_BOOL8 __fastcall ListOfBalisesInSRAuthority_1_UpperBitsNotSet(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbp
_BOOL8 result; // rax

v1 = *a1;
result = UpperBitsNotSet64(*a1, 1);
if ( v1 != 1 )
{
if ( !result )
return result;
return UpperBitsNotSet64(a1[2], 14);
}
if ( result )
{
result = UpperBitsNotSet64(a1[1], 10);
if ( result )
return UpperBitsNotSet64(a1[2], 14);
}
return result;
}

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

v1 = *a1;
result = func0(*a1, 1);
if ( v1 != 1 )
{
if ( !result )
return result;
return func0(a1[2], 14);
}
if ( result )
{
result = func0(a1[1], 10);
if ( result )
return func0(a1[2], 14);
}
return result;
}

original_code:
int ListOfBalisesInSRAuthority_1_UpperBitsNotSet(const ListOfBalisesInSRAuthority_1* p)
{
    int status = 1;
    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);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ListOfBalisesInSRAuthority_1_UpperBitsNotSet(struct ListOfBalisesInSRAuthority_1 *p)
{
    int status = 1;
    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);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ListOfBalisesInSRAuthority_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; } *

variable_types: status int


decompiled_code:
__int64 __fastcall ListOfBalisesInSRAuthority_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 15LL) )
return 0xFFFFFFFFLL;
if ( !ListOfBalisesInSRAuthority_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 1LL, *a1);
if ( *a1 == 1 )
Bitstream_Write(a2, 10LL, a1[1]);
Bitstream_Write(a2, 14LL, a1[2]);
return 1LL;
}

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

original_code:
int ListOfBalisesInSRAuthority_1_EncodeBit(const ListOfBalisesInSRAuthority_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        if (ListOfBalisesInSRAuthority_1_UpperBitsNotSet(p))
        {
            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);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ListOfBalisesInSRAuthority_1_EncodeBit(struct ListOfBalisesInSRAuthority_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        if (ListOfBalisesInSRAuthority_1_UpperBitsNotSet(p))
        {
            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);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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

user_defined_types: struct ListOfBalisesInSRAuthority_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; }


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

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

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

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

original_code:
int ListOfBalisesInSRAuthority_1_DecodeBit(ListOfBalisesInSRAuthority_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(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);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ListOfBalisesInSRAuthority_1_DecodeBit(struct ListOfBalisesInSRAuthority_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(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);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

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


original_code:
int ListOfBalisesInSRAuthority_1_EncodeInt(const ListOfBalisesInSRAuthority_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->Q_NEWCOUNTRY;
    stream[(*startAddress)++] = p->NID_C;
    stream[(*startAddress)++] = p->NID_BG;
    return 1;
}

canonical_original_code:
int ListOfBalisesInSRAuthority_1_EncodeInt(struct ListOfBalisesInSRAuthority_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->Q_NEWCOUNTRY;
    stream[(*startAddress)++] = p->NID_C;
    stream[(*startAddress)++] = p->NID_BG;
    return 1;
}

variable_types:
startAddress
int *


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

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

original_code:
int ListOfBalisesInSRAuthority_1_DecodeInt(ListOfBalisesInSRAuthority_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->Q_NEWCOUNTRY = stream[(*startAddress)++];
    p->NID_C = stream[(*startAddress)++];
    p->NID_BG = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int ListOfBalisesInSRAuthority_1_DecodeInt(struct ListOfBalisesInSRAuthority_1 *p, int *startAddress, int *stream)
{
    p->Q_NEWCOUNTRY = stream[(*startAddress)++];
    p->NID_C = stream[(*startAddress)++];
    p->NID_BG = stream[(*startAddress)++];
    return 1;
}


decompiled_code:
_BOOL8 __fastcall ReversingSupervisionInformation_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL8 result; // rax

result = UpperBitsNotSet64(a1[2], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[3], 13);
if ( result )
{
result = UpperBitsNotSet64(a1[4], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[5], 15);
if ( result )
result = UpperBitsNotSet64(a1[6], 7);
}
}
}
return result;
}

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

result = func0(a1[2], 2);
if ( result )
{
result = func0(a1[3], 13);
if ( result )
{
result = func0(a1[4], 2);
if ( result )
{
result = func0(a1[5], 15);
if ( result )
result = func0(a1[6], 7);
}
}
}
return result;
}

original_code:
int ReversingSupervisionInformation_UpperBitsNotSet(const ReversingSupervisionInformation* 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_REVERSE, 15);
    status = status && UpperBitsNotSet64(p->V_REVERSE, 7) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ReversingSupervisionInformation_UpperBitsNotSet(struct ReversingSupervisionInformation *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_REVERSE, 15);
    status = status && UpperBitsNotSet64(p->V_REVERSE, 7) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ReversingSupervisionInformation { 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_REVERSE; unsigned long V_REVERSE; } *

user_defined_types: struct ReversingSupervisionInformation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_REVERSE; unsigned long V_REVERSE; }


decompiled_code:
__int64 __fastcall ReversingSupervisionInformation_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 39LL) )
return 0xFFFFFFFFLL;
if ( !ReversingSupervisionInformation_UpperBitsNotSet(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, 7LL, a1[6]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 39LL) )
return 0xFFFFFFFFLL;
if ( !func2(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, 7LL, a1[6]);
return 1LL;
}

original_code:
int ReversingSupervisionInformation_EncodeBit(const ReversingSupervisionInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 39))
    {
        if (ReversingSupervisionInformation_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_REVERSE);
            Bitstream_Write(stream, 7, p->V_REVERSE);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ReversingSupervisionInformation_EncodeBit(struct ReversingSupervisionInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 39))
    {
        if (ReversingSupervisionInformation_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_REVERSE);
            Bitstream_Write(stream, 7, p->V_REVERSE);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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


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

result = Bitstream_Normal(a2, 39LL);
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, 7LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 39LL);
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, 7LL);
result = 1LL;
}
return result;
}

original_code:
int ReversingSupervisionInformation_DecodeBit(ReversingSupervisionInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 39))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_REVERSE = Bitstream_Read(stream, 15);
        }
        {
            p->V_REVERSE = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ReversingSupervisionInformation_DecodeBit(struct ReversingSupervisionInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 39))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_REVERSE = Bitstream_Read(stream, 15);
        }
        {
            p->V_REVERSE = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int ReversingSupervisionInformation_EncodeInt(const ReversingSupervisionInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 139;
    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_REVERSE;
    stream[startAddress++] = p->V_REVERSE;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int ReversingSupervisionInformation_EncodeInt(struct ReversingSupervisionInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 139;
    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_REVERSE;
    stream[startAddress++] = p->V_REVERSE;
    data->endAddress = startAddress-1;
    return 1;
}

variable_types: startAddress int


original_code:
int ReversingSupervisionInformation_DecodeInt(ReversingSupervisionInformation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 139)
    {
         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_REVERSE = stream[startAddress++];
    p->V_REVERSE = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int ReversingSupervisionInformation_DecodeInt(struct ReversingSupervisionInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 139)
    {
         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_REVERSE = stream[startAddress++];
    p->V_REVERSE = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


decompiled_code:
__int64 *ReversingSupervisionInformation_New()
{
__int64 *v0; // rbx

if ( ReversingSupervisionInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)ReversingSupervisionInformationMemoryTop > 7 )
return 0LL;
v0 = &ReversingSupervisionInformationMemory[7 * ReversingSupervisionInformationMemoryTop++];
}
else
{
v0 = &ReversingSupervisionInformationMemory[7 * ReversingSupervisionInformationMemoryFreeList];
ReversingSupervisionInformationMemoryFreeList = *v0;
}
ReversingSupervisionInformation_Init(v0);
return v0;
}

canonical_decompiled_code:
__int64 *func7()
{
__int64 *v0; // rbx

if ( ReversingSupervisionInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)ReversingSupervisionInformationMemoryTop > 7 )
return 0LL;
v0 = &ReversingSupervisionInformationMemory[7 * ReversingSupervisionInformationMemoryTop++];
}
else
{
v0 = &ReversingSupervisionInformationMemory[7 * ReversingSupervisionInformationMemoryFreeList];
ReversingSupervisionInformationMemoryFreeList = *v0;
}
func1(v0);
return v0;
}

original_code:
ReversingSupervisionInformation* ReversingSupervisionInformation_New(void)
{
    ReversingSupervisionInformation* ptr;
    if (ReversingSupervisionInformationMemoryFreeList != (-1))
    {
        ptr = &ReversingSupervisionInformationMemory[ReversingSupervisionInformationMemoryFreeList];
        ReversingSupervisionInformationMemoryFreeList = ReversingSupervisionInformationMemory[ReversingSupervisionInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (ReversingSupervisionInformationMemoryTop < 8)
    {
        ptr = &ReversingSupervisionInformationMemory[ReversingSupervisionInformationMemoryTop];
        ReversingSupervisionInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ReversingSupervisionInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct ReversingSupervisionInformation *ReversingSupervisionInformation_New()
{
    struct ReversingSupervisionInformation *ptr;
    if (ReversingSupervisionInformationMemoryFreeList != (-1))
    {
        ptr = &ReversingSupervisionInformationMemory[ReversingSupervisionInformationMemoryFreeList];
        ReversingSupervisionInformationMemoryFreeList = ReversingSupervisionInformationMemory[ReversingSupervisionInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (ReversingSupervisionInformationMemoryTop < 8)
    {
        ptr = &ReversingSupervisionInformationMemory[ReversingSupervisionInformationMemoryTop];
        ReversingSupervisionInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ReversingSupervisionInformation_Init(ptr);
    return ptr;
}

return_type: struct ReversingSupervisionInformation { 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_REVERSE; unsigned long V_REVERSE; } *


decompiled_code:
__int64 __fastcall ReversingSupervisionInformation_Delete(_QWORD *a1)
{
__int64 result; // rax

*a1 = ReversingSupervisionInformationMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
ReversingSupervisionInformationMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL * (a1 - ReversingSupervisionInformationMemory);
return result;
}

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

*a1 = ReversingSupervisionInformationMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
ReversingSupervisionInformationMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL * (a1 - ReversingSupervisionInformationMemory);
return result;
}

original_code:
void ReversingSupervisionInformation_Delete(ReversingSupervisionInformation* ptr)
{
    ptr->header.NID_PACKET = ReversingSupervisionInformationMemoryFreeList;
    ReversingSupervisionInformationMemoryFreeList = ptr - ReversingSupervisionInformationMemory;
}

canonical_original_code:
void ReversingSupervisionInformation_Delete(struct ReversingSupervisionInformation *ptr)
{
    ptr->header.NID_PACKET = ReversingSupervisionInformationMemoryFreeList;
    ReversingSupervisionInformationMemoryFreeList = ptr - ReversingSupervisionInformationMemory;
}

return_type: void


decompiled_code:
_BOOL8 __fastcall PositionReportParameters_1_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL8 result; // rax

result = UpperBitsNotSet64(*a1, 15);
if ( result )
result = UpperBitsNotSet64(a1[1], 1);
return result;
}

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

result = func0(*a1, 15);
if ( result )
result = func0(a1[1], 1);
return result;
}

original_code:
int PositionReportParameters_1_UpperBitsNotSet(const PositionReportParameters_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_LOC, 15);
    status = status && UpperBitsNotSet64(p->Q_LGTLOC, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int PositionReportParameters_1_UpperBitsNotSet(struct PositionReportParameters_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_LOC, 15);
    status = status && UpperBitsNotSet64(p->Q_LGTLOC, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct PositionReportParameters_1 { unsigned long D_LOC; unsigned long Q_LGTLOC; } *


decompiled_code:
__int64 __fastcall PositionReportParameters_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 16LL) )
return 0xFFFFFFFFLL;
if ( !PositionReportParameters_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 1LL, a1[1]);
return 1LL;
}

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

original_code:
int PositionReportParameters_1_EncodeBit(const PositionReportParameters_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        if (PositionReportParameters_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_LOC);
            Bitstream_Write(stream, 1, p->Q_LGTLOC);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int PositionReportParameters_1_EncodeBit(struct PositionReportParameters_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        if (PositionReportParameters_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_LOC);
            Bitstream_Write(stream, 1, p->Q_LGTLOC);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct PositionReportParameters_1 { unsigned long D_LOC; unsigned long Q_LGTLOC; }


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

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

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

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

original_code:
int PositionReportParameters_1_DecodeBit(PositionReportParameters_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        {
            p->D_LOC = Bitstream_Read(stream, 15);
        }
        {
            p->Q_LGTLOC = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int PositionReportParameters_1_DecodeBit(struct PositionReportParameters_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        {
            p->D_LOC = Bitstream_Read(stream, 15);
        }
        {
            p->Q_LGTLOC = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


decompiled_code:
__int64 __fastcall PositionReportParameters_1_EncodeInt(__int64 *a1, _DWORD *a2, __int64 a3)
{
__int64 v3; // rcx
int v4; // eax
__int64 v5; // rcx
int v6; // eax

v3 = *a1;
v4 = (*a2)++;
*(_DWORD *)(a3 + 4LL * v4) = v3;
v5 = a1[1];
v6 = (*a2)++;
*(_DWORD *)(a3 + 4LL * v6) = v5;
return 1LL;
}

original_code:
int PositionReportParameters_1_EncodeInt(const PositionReportParameters_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->D_LOC;
    stream[(*startAddress)++] = p->Q_LGTLOC;
    return 1;
}

canonical_original_code:
int PositionReportParameters_1_EncodeInt(struct PositionReportParameters_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->D_LOC;
    stream[(*startAddress)++] = p->Q_LGTLOC;
    return 1;
}


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

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

original_code:
int PositionReportParameters_1_DecodeInt(PositionReportParameters_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->D_LOC = stream[(*startAddress)++];
    p->Q_LGTLOC = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int PositionReportParameters_1_DecodeInt(struct PositionReportParameters_1 *p, int *startAddress, int *stream)
{
    p->D_LOC = stream[(*startAddress)++];
    p->Q_LGTLOC = stream[(*startAddress)++];
    return 1;
}


decompiled_code:
_BOOL8 __fastcall ValidatedTrainData_1_UpperBitsNotSet(unsigned __int64 *a1)
{
return UpperBitsNotSet64(*a1, 8);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int64 *a1)
{
return func0(*a1, 8);
}

original_code:
int ValidatedTrainData_1_UpperBitsNotSet(const ValidatedTrainData_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->M_TRACTION, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ValidatedTrainData_1_UpperBitsNotSet(struct ValidatedTrainData_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->M_TRACTION, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ValidatedTrainData_1 { unsigned long M_TRACTION; } *


decompiled_code:
__int64 __fastcall ValidatedTrainData_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 8LL) )
return 0xFFFFFFFFLL;
if ( !ValidatedTrainData_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 8LL, *a1);
return 1LL;
}

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

original_code:
int ValidatedTrainData_1_EncodeBit(const ValidatedTrainData_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        if (ValidatedTrainData_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 8, p->M_TRACTION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ValidatedTrainData_1_EncodeBit(struct ValidatedTrainData_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        if (ValidatedTrainData_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 8, p->M_TRACTION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct ValidatedTrainData_1 { unsigned long M_TRACTION; }


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

result = Bitstream_Normal(a2, 8LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 8LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 8LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 8LL);
result = 1LL;
}
return result;
}

original_code:
int ValidatedTrainData_1_DecodeBit(ValidatedTrainData_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        {
            p->M_TRACTION = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ValidatedTrainData_1_DecodeBit(struct ValidatedTrainData_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        {
            p->M_TRACTION = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


decompiled_code:
__int64 __fastcall ValidatedTrainData_1_EncodeInt(__int64 *a1, _DWORD *a2, __int64 a3)
{
__int64 v3; // rcx
int v4; // eax

v3 = *a1;
v4 = (*a2)++;
*(_DWORD *)(a3 + 4LL * v4) = v3;
return 1LL;
}

original_code:
int ValidatedTrainData_1_EncodeInt(const ValidatedTrainData_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->M_TRACTION;
    return 1;
}

canonical_original_code:
int ValidatedTrainData_1_EncodeInt(struct ValidatedTrainData_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->M_TRACTION;
    return 1;
}


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

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

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

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

original_code:
int ValidatedTrainData_1_DecodeInt(ValidatedTrainData_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->M_TRACTION = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int ValidatedTrainData_1_DecodeInt(struct ValidatedTrainData_1 *p, int *startAddress, int *stream)
{
    p->M_TRACTION = stream[(*startAddress)++];
    return 1;
}


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

result = 1LL;
if ( a2 != 64 )
result = 1LL << a2 > a1;
return result;
}

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 Level23TransitionInformation_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 13);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(a1 + 24), 24);
return result;
}

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

result = func0(*(_QWORD *)(a1 + 16), 13);
if ( result )
result = func0(*(_QWORD *)(a1 + 24), 24);
return result;
}

original_code:
int Level23TransitionInformation_UpperBitsNotSet(const Level23TransitionInformation* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->NID_LTRBG, 24);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Level23TransitionInformation_UpperBitsNotSet(struct Level23TransitionInformation *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->NID_LTRBG, 24);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct Level23TransitionInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long NID_LTRBG; } *

user_defined_types: struct Level23TransitionInformation { struct PacketHeader header; unsigned long L_PACKET; unsigned long NID_LTRBG; }


decompiled_code:
__int64 __fastcall Level23TransitionInformation_EncodeBit(__int64 a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 37LL) )
return 0xFFFFFFFFLL;
if ( !Level23TransitionInformation_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 13LL, *(_QWORD *)(a1 + 16));
Bitstream_Write(a2, 24LL, *(_QWORD *)(a1 + 24));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 37LL) )
return 0xFFFFFFFFLL;
if ( !func2(a1) )
return 4294967294LL;
Bitstream_Write(a2, 13LL, *(_QWORD *)(a1 + 16));
Bitstream_Write(a2, 24LL, *(_QWORD *)(a1 + 24));
return 1LL;
}

original_code:
int Level23TransitionInformation_EncodeBit(const Level23TransitionInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 37))
    {
        if (Level23TransitionInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 24, p->NID_LTRBG);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int Level23TransitionInformation_EncodeBit(struct Level23TransitionInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 37))
    {
        if (Level23TransitionInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 24, p->NID_LTRBG);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

result = Bitstream_Normal(a2, 37LL);
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 16) = Bitstream_Read(a2, 13LL);
*(_QWORD *)(a1 + 24) = Bitstream_Read(a2, 24LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 37LL);
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 16) = Bitstream_Read(a2, 13LL);
*(_QWORD *)(a1 + 24) = Bitstream_Read(a2, 24LL);
result = 1LL;
}
return result;
}

original_code:
int Level23TransitionInformation_DecodeBit(Level23TransitionInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 37))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->NID_LTRBG = Bitstream_Read(stream, 24);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Level23TransitionInformation_DecodeBit(struct Level23TransitionInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 37))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->NID_LTRBG = Bitstream_Read(stream, 24);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int Level23TransitionInformation_EncodeInt(const Level23TransitionInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 9;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->NID_LTRBG;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int Level23TransitionInformation_EncodeInt(struct Level23TransitionInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 9;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->NID_LTRBG;
    data->endAddress = startAddress-1;
    return 1;
}


decompiled_code:
_BOOL8 __fastcall Level23TransitionInformation_DecodeInt(_QWORD *a1, _DWORD *a2, __int64 a3)
{
_BOOL8 result; // rax
int v4; // eax

result = 0LL;
if ( *a2 == 9 )
{
v4 = a2[3];
*a1 = *(int *)(a3 + 4LL * v4);
a1[2] = *(int *)(a3 + 4LL * v4 + 4);
a1[3] = *(int *)(a3 + 4LL * v4 + 8);
result = a2[4] == v4 + 2;
}
return result;
}

original_code:
int Level23TransitionInformation_DecodeInt(Level23TransitionInformation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 9)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->NID_LTRBG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int Level23TransitionInformation_DecodeInt(struct Level23TransitionInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 9)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->NID_LTRBG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


decompiled_code:
__int64 *Level23TransitionInformation_New()
{
__int64 *v0; // rbx

if ( Level23TransitionInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)Level23TransitionInformationMemoryTop > 7 )
return 0LL;
v0 = &Level23TransitionInformationMemory[4 * Level23TransitionInformationMemoryTop++];
}
else
{
v0 = &Level23TransitionInformationMemory[4 * Level23TransitionInformationMemoryFreeList];
Level23TransitionInformationMemoryFreeList = *v0;
}
Level23TransitionInformation_Init(v0);
return v0;
}

canonical_decompiled_code:
__int64 *func7()
{
__int64 *v0; // rbx

if ( Level23TransitionInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)Level23TransitionInformationMemoryTop > 7 )
return 0LL;
v0 = &Level23TransitionInformationMemory[4 * Level23TransitionInformationMemoryTop++];
}
else
{
v0 = &Level23TransitionInformationMemory[4 * Level23TransitionInformationMemoryFreeList];
Level23TransitionInformationMemoryFreeList = *v0;
}
func1(v0);
return v0;
}

original_code:
Level23TransitionInformation* Level23TransitionInformation_New(void)
{
    Level23TransitionInformation* ptr;
    if (Level23TransitionInformationMemoryFreeList != (-1))
    {
        ptr = &Level23TransitionInformationMemory[Level23TransitionInformationMemoryFreeList];
        Level23TransitionInformationMemoryFreeList = Level23TransitionInformationMemory[Level23TransitionInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (Level23TransitionInformationMemoryTop < 8)
    {
        ptr = &Level23TransitionInformationMemory[Level23TransitionInformationMemoryTop];
        Level23TransitionInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    Level23TransitionInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct Level23TransitionInformation *Level23TransitionInformation_New()
{
    struct Level23TransitionInformation *ptr;
    if (Level23TransitionInformationMemoryFreeList != (-1))
    {
        ptr = &Level23TransitionInformationMemory[Level23TransitionInformationMemoryFreeList];
        Level23TransitionInformationMemoryFreeList = Level23TransitionInformationMemory[Level23TransitionInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (Level23TransitionInformationMemoryTop < 8)
    {
        ptr = &Level23TransitionInformationMemory[Level23TransitionInformationMemoryTop];
        Level23TransitionInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    Level23TransitionInformation_Init(ptr);
    return ptr;
}

return_type: struct Level23TransitionInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long NID_LTRBG; } *


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

result = Level23TransitionInformationMemoryFreeList;
*(_QWORD *)a1 = Level23TransitionInformationMemoryFreeList;
Level23TransitionInformationMemoryFreeList = (a1 - (char *)Level23TransitionInformationMemory) >> 5;
return result;
}

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

result = Level23TransitionInformationMemoryFreeList;
*(_QWORD *)a1 = Level23TransitionInformationMemoryFreeList;
Level23TransitionInformationMemoryFreeList = (a1 - (char *)Level23TransitionInformationMemory) >> 5;
return result;
}

original_code:
void Level23TransitionInformation_Delete(Level23TransitionInformation* ptr)
{
    ptr->header.NID_PACKET = Level23TransitionInformationMemoryFreeList;
    Level23TransitionInformationMemoryFreeList = ptr - Level23TransitionInformationMemory;
}

canonical_original_code:
void Level23TransitionInformation_Delete(struct Level23TransitionInformation *ptr)
{
    ptr->header.NID_PACKET = Level23TransitionInformationMemoryFreeList;
    Level23TransitionInformationMemoryFreeList = ptr - Level23TransitionInformationMemory;
}


decompiled_code:
_BOOL8 __fastcall ConditionalLevelTransitionOrder_1_UpperBitsNotSet(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbp
_BOOL8 result; // rax

v1 = *a1;
result = UpperBitsNotSet64(*a1, 3);
if ( v1 != 1 )
return result;
if ( result )
result = UpperBitsNotSet64(a1[1], 8);
return result;
}

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

v1 = *a1;
result = func0(*a1, 3);
if ( v1 != 1 )
return result;
if ( result )
result = func0(a1[1], 8);
return result;
}

original_code:
int ConditionalLevelTransitionOrder_1_UpperBitsNotSet(const ConditionalLevelTransitionOrder_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->M_LEVELTR, 3) ;
    if (p->M_LEVELTR == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ConditionalLevelTransitionOrder_1_UpperBitsNotSet(struct ConditionalLevelTransitionOrder_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->M_LEVELTR, 3) ;
    if (p->M_LEVELTR == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ConditionalLevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; } *


decompiled_code:
__int64 __fastcall ConditionalLevelTransitionOrder_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
__int64 result; // rax

if ( !(unsigned int)Bitstream_Normal(a2, 3LL) )
return 0xFFFFFFFFLL;
if ( !ConditionalLevelTransitionOrder_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 3LL, *a1);
result = 1LL;
if ( *a1 == 1 )
{
Bitstream_Write(a2, 8LL, a1[1]);
result = 1LL;
}
return result;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 3LL) )
return 0xFFFFFFFFLL;
if ( !func1(a1) )
return 4294967294LL;
Bitstream_Write(a2, 3LL, *a1);
result = 1LL;
if ( *a1 == 1 )
{
Bitstream_Write(a2, 8LL, a1[1]);
result = 1LL;
}
return result;
}

original_code:
int ConditionalLevelTransitionOrder_1_EncodeBit(const ConditionalLevelTransitionOrder_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 3))
    {
        if (ConditionalLevelTransitionOrder_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ConditionalLevelTransitionOrder_1_EncodeBit(struct ConditionalLevelTransitionOrder_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 3))
    {
        if (ConditionalLevelTransitionOrder_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct ConditionalLevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; }


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

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

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

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

original_code:
int ConditionalLevelTransitionOrder_1_DecodeBit(ConditionalLevelTransitionOrder_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 3))
    {
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ConditionalLevelTransitionOrder_1_DecodeBit(struct ConditionalLevelTransitionOrder_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 3))
    {
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


decompiled_code:
__int64 __fastcall ConditionalLevelTransitionOrder_1_EncodeInt(__int64 *a1, _DWORD *a2, __int64 a3)
{
__int64 v3; // rcx
int v4; // eax
__int64 v5; // rcx
int v6; // eax

v3 = *a1;
v4 = (*a2)++;
*(_DWORD *)(a3 + 4LL * v4) = v3;
v5 = a1[1];
v6 = (*a2)++;
*(_DWORD *)(a3 + 4LL * v6) = v5;
return 1LL;
}

original_code:
int ConditionalLevelTransitionOrder_1_EncodeInt(const ConditionalLevelTransitionOrder_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->M_LEVELTR;
    stream[(*startAddress)++] = p->NID_STM;
    return 1;
}

canonical_original_code:
int ConditionalLevelTransitionOrder_1_EncodeInt(struct ConditionalLevelTransitionOrder_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->M_LEVELTR;
    stream[(*startAddress)++] = p->NID_STM;
    return 1;
}


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

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

original_code:
int ConditionalLevelTransitionOrder_1_DecodeInt(ConditionalLevelTransitionOrder_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->M_LEVELTR = stream[(*startAddress)++];
    p->NID_STM = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int ConditionalLevelTransitionOrder_1_DecodeInt(struct ConditionalLevelTransitionOrder_1 *p, int *startAddress, int *stream)
{
    p->M_LEVELTR = stream[(*startAddress)++];
    p->NID_STM = stream[(*startAddress)++];
    return 1;
}


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

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

original_code:
int EndOfInformation_UpperBitsNotSet(const EndOfInformation* p)
{
    int status = 1;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int EndOfInformation_UpperBitsNotSet(struct EndOfInformation *p)
{
    int status = 1;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct EndOfInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; } *

user_defined_types: struct EndOfInformation { struct PacketHeader header; }


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

if ( (unsigned int)Bitstream_Normal(a2, 0LL) )
result = (unsigned int)EndOfInformation_UpperBitsNotSet(a1) == 0 ? -2 : 1;
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( (unsigned int)Bitstream_Normal(a2, 0LL) )
result = (unsigned int)func1(a1) == 0 ? -2 : 1;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int EndOfInformation_EncodeBit(const EndOfInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 0))
    {
        if (EndOfInformation_UpperBitsNotSet(p))
        {
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int EndOfInformation_EncodeBit(struct EndOfInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 0))
    {
        if (EndOfInformation_UpperBitsNotSet(p))
        {
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


decompiled_code:
_BOOL8 __fastcall EndOfInformation_DecodeBit(__int64 a1, __int64 a2)
{
return (unsigned int)Bitstream_Normal(a2, 0LL) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, __int64 a2)
{
return (unsigned int)Bitstream_Normal(a2, 0LL) != 0;
}

original_code:
int EndOfInformation_DecodeBit(EndOfInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 0))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int EndOfInformation_DecodeBit(struct EndOfInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 0))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}


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

*(_DWORD *)a2 = 255;
*(_BYTE *)(a2 + 8) = 1;
v3 = *(_DWORD *)(a2 + 12);
*(_DWORD *)(a3 + 4LL * v3) = *a1;
*(_DWORD *)(a2 + 16) = v3;
return 1LL;
}

original_code:
int EndOfInformation_EncodeInt(const EndOfInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 255;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int EndOfInformation_EncodeInt(struct EndOfInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 255;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    data->endAddress = startAddress-1;
    return 1;
}

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


decompiled_code:
_BOOL8 __fastcall EndOfInformation_DecodeInt(_QWORD *a1, _DWORD *a2, __int64 a3)
{
_BOOL8 result; // rax
int v4; // eax

result = 0LL;
if ( *a2 == 255 )
{
v4 = a2[3];
*a1 = *(int *)(a3 + 4LL * v4);
result = a2[4] == v4;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_QWORD *a1, _DWORD *a2, __int64 a3)
{
_BOOL8 result; // rax
int v4; // eax

result = 0LL;
if ( *a2 == 255 )
{
v4 = a2[3];
*a1 = *(int *)(a3 + 4LL * v4);
result = a2[4] == v4;
}
return result;
}

original_code:
int EndOfInformation_DecodeInt(EndOfInformation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 255)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int EndOfInformation_DecodeInt(struct EndOfInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 255)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

variable_types:
stream
int *


decompiled_code:
__int64 *EndOfInformation_New()
{
__int64 *v0; // rbx

if ( EndOfInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)EndOfInformationMemoryTop > 7 )
return 0LL;
v0 = &EndOfInformationMemory[2 * EndOfInformationMemoryTop++];
}
else
{
v0 = &EndOfInformationMemory[2 * EndOfInformationMemoryFreeList];
EndOfInformationMemoryFreeList = *v0;
}
EndOfInformation_Init(v0);
return v0;
}

canonical_decompiled_code:
__int64 *func6()
{
__int64 *v0; // rbx

if ( EndOfInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)EndOfInformationMemoryTop > 7 )
return 0LL;
v0 = &EndOfInformationMemory[2 * EndOfInformationMemoryTop++];
}
else
{
v0 = &EndOfInformationMemory[2 * EndOfInformationMemoryFreeList];
EndOfInformationMemoryFreeList = *v0;
}
func0(v0);
return v0;
}

original_code:
EndOfInformation* EndOfInformation_New(void)
{
    EndOfInformation* ptr;
    if (EndOfInformationMemoryFreeList != (-1))
    {
        ptr = &EndOfInformationMemory[EndOfInformationMemoryFreeList];
        EndOfInformationMemoryFreeList = EndOfInformationMemory[EndOfInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (EndOfInformationMemoryTop < 8)
    {
        ptr = &EndOfInformationMemory[EndOfInformationMemoryTop];
        EndOfInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    EndOfInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct EndOfInformation *EndOfInformation_New()
{
    struct EndOfInformation *ptr;
    if (EndOfInformationMemoryFreeList != (-1))
    {
        ptr = &EndOfInformationMemory[EndOfInformationMemoryFreeList];
        EndOfInformationMemoryFreeList = EndOfInformationMemory[EndOfInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (EndOfInformationMemoryTop < 8)
    {
        ptr = &EndOfInformationMemory[EndOfInformationMemoryTop];
        EndOfInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    EndOfInformation_Init(ptr);
    return ptr;
}

return_type: struct EndOfInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; } *


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

result = EndOfInformationMemoryFreeList;
*(_QWORD *)a1 = EndOfInformationMemoryFreeList;
EndOfInformationMemoryFreeList = (a1 - (char *)EndOfInformationMemory) >> 4;
return result;
}

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

result = EndOfInformationMemoryFreeList;
*(_QWORD *)a1 = EndOfInformationMemoryFreeList;
EndOfInformationMemoryFreeList = (a1 - (char *)EndOfInformationMemory) >> 4;
return result;
}

original_code:
void EndOfInformation_Delete(EndOfInformation* ptr)
{
    ptr->header.NID_PACKET = EndOfInformationMemoryFreeList;
    EndOfInformationMemoryFreeList = ptr - EndOfInformationMemory;
}

canonical_original_code:
void EndOfInformation_Delete(struct EndOfInformation *ptr)
{
    ptr->header.NID_PACKET = EndOfInformationMemoryFreeList;
    EndOfInformationMemoryFreeList = ptr - EndOfInformationMemory;
}


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

result = 1LL;
if ( a2 != 64 )
result = 1LL << a2 > a1;
return result;
}

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

result = 1LL;
if ( a2 != 64 )
result = 1LL << a2 > a1;
return result;
}

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 AxleLoadSpeedProfile_2_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned int i; // ebx

v1 = UpperBitsNotSet64(*a1, 15);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[1], 15);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[2], 1);
if ( v1 )
v1 = UpperBitsNotSet64(a1[3], 5);
}
}
for ( i = 0; i < a1[3]; ++i )
{
if ( v1 )
v1 = AxleLoadSpeedProfile_2_1_UpperBitsNotSet(&a1[2 * i + 4]) != 0;
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned int i; // ebx

v1 = func0(*a1, 15);
if ( v1 )
{
v1 = func0(a1[1], 15);
if ( v1 )
{
v1 = func0(a1[2], 1);
if ( v1 )
v1 = func0(a1[3], 5);
}
}
for ( i = 0; i < a1[3]; ++i )
{
if ( v1 )
v1 = AxleLoadSpeedProfile_2_1_UpperBitsNotSet(&a1[2 * i + 4]) != 0;
}
return v1;
}

original_code:
int AxleLoadSpeedProfile_2_UpperBitsNotSet(const AxleLoadSpeedProfile_2* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->L_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->N_ITER_2_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_2_1; ++i)
    {
        status = status && AxleLoadSpeedProfile_2_1_UpperBitsNotSet(&(p->sub_2_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_2_UpperBitsNotSet(struct AxleLoadSpeedProfile_2 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->L_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->N_ITER_2_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_2_1; ++i)
    {
        status = status && AxleLoadSpeedProfile_2_1_UpperBitsNotSet(&(p->sub_2_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct AxleLoadSpeedProfile_2 { unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct AxleLoadSpeedProfile_2_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_2_1[31]; } *

variable_types:
i
unsigned int

user_defined_types: struct AxleLoadSpeedProfile_2 { unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct AxleLoadSpeedProfile_2_1 sub_2_1[31]; }


decompiled_code:
__int64 __fastcall AxleLoadSpeedProfile_2_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // ebx

if ( !(unsigned int)Bitstream_Normal(a2, 36LL) )
return 0xFFFFFFFFLL;
if ( !AxleLoadSpeedProfile_2_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 15LL, a1[1]);
Bitstream_Write(a2, 1LL, a1[2]);
Bitstream_Write(a2, 5LL, a1[3]);
if ( !a1[3] )
return 1LL;
v2 = 0;
do
AxleLoadSpeedProfile_2_1_EncodeBit(&a1[2 * v2++ + 4], a2);
while ( v2 < a1[3] );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // ebx

if ( !(unsigned int)Bitstream_Normal(a2, 36LL) )
return 0xFFFFFFFFLL;
if ( !func1(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 15LL, a1[1]);
Bitstream_Write(a2, 1LL, a1[2]);
Bitstream_Write(a2, 5LL, a1[3]);
if ( !a1[3] )
return 1LL;
v2 = 0;
do
AxleLoadSpeedProfile_2_1_EncodeBit(&a1[2 * v2++ + 4], a2);
while ( v2 < a1[3] );
return 1LL;
}

original_code:
int AxleLoadSpeedProfile_2_EncodeBit(const AxleLoadSpeedProfile_2* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 36))
    {
        if (AxleLoadSpeedProfile_2_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_AXLELOAD);
            Bitstream_Write(stream, 15, p->L_AXLELOAD);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 5, p->N_ITER_2_1);
            for (uint32_t i = 0; i < p->N_ITER_2_1; ++i)
            {
                AxleLoadSpeedProfile_2_1_EncodeBit(&(p->sub_2_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_2_EncodeBit(struct AxleLoadSpeedProfile_2 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 36))
    {
        if (AxleLoadSpeedProfile_2_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_AXLELOAD);
            Bitstream_Write(stream, 15, p->L_AXLELOAD);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 5, p->N_ITER_2_1);
            for (unsigned int i = 0; i < p->N_ITER_2_1; ++i)
            {
                AxleLoadSpeedProfile_2_1_EncodeBit(&(p->sub_2_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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


decompiled_code:
__int64 __fastcall AxleLoadSpeedProfile_2_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // ebx

result = Bitstream_Normal(a2, 36LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 15LL);
a1[1] = Bitstream_Read(a2, 15LL);
a1[2] = Bitstream_Read(a2, 1LL);
v3 = Bitstream_Read(a2, 5LL);
a1[3] = v3;
if ( v3 )
{
v4 = 0;
do
AxleLoadSpeedProfile_2_1_DecodeBit(&a1[2 * v4++ + 4], a2);
while ( (unsigned __int64)v4 < a1[3] );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

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

result = Bitstream_Normal(a2, 36LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 15LL);
a1[1] = Bitstream_Read(a2, 15LL);
a1[2] = Bitstream_Read(a2, 1LL);
v3 = Bitstream_Read(a2, 5LL);
a1[3] = v3;
if ( v3 )
{
v4 = 0;
do
AxleLoadSpeedProfile_2_1_DecodeBit(&a1[2 * v4++ + 4], a2);
while ( (unsigned __int64)v4 < a1[3] );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int AxleLoadSpeedProfile_2_DecodeBit(AxleLoadSpeedProfile_2* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 36))
    {
        {
            p->D_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->L_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
    {
            p->N_ITER_2_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_2_1; ++i)
        {
            AxleLoadSpeedProfile_2_1_DecodeBit(&(p->sub_2_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_2_DecodeBit(struct AxleLoadSpeedProfile_2 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 36))
    {
        {
            p->D_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->L_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
    {
            p->N_ITER_2_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_2_1; ++i)
        {
            AxleLoadSpeedProfile_2_1_DecodeBit(&(p->sub_2_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int AxleLoadSpeedProfile_2_EncodeInt(const AxleLoadSpeedProfile_2* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->D_AXLELOAD;
    stream[(*startAddress)++] = p->L_AXLELOAD;
    stream[(*startAddress)++] = p->Q_FRONT;
    stream[(*startAddress)++] = p->N_ITER_2_1;
    for (uint32_t i = 0; i < p->N_ITER_2_1; ++i)
    {
        AxleLoadSpeedProfile_2_1_EncodeInt(&(p->sub_2_1[i]), startAddress, stream);
    }
    return 1;
}

canonical_original_code:
int AxleLoadSpeedProfile_2_EncodeInt(struct AxleLoadSpeedProfile_2 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->D_AXLELOAD;
    stream[(*startAddress)++] = p->L_AXLELOAD;
    stream[(*startAddress)++] = p->Q_FRONT;
    stream[(*startAddress)++] = p->N_ITER_2_1;
    for (unsigned int i = 0; i < p->N_ITER_2_1; ++i)
    {
        AxleLoadSpeedProfile_2_1_EncodeInt(&(p->sub_2_1[i]), startAddress, stream);
    }
    return 1;
}


decompiled_code:
__int64 __fastcall AxleLoadSpeedProfile_2_DecodeInt(_QWORD *a1, _DWORD *a2, __int64 a3)
{
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
__int64 v8; // rax
unsigned int v9; // ebx

v4 = (*a2)++;
*a1 = *(int *)(a3 + 4LL * v4);
v5 = (*a2)++;
a1[1] = *(int *)(a3 + 4LL * v5);
v6 = (*a2)++;
a1[2] = *(int *)(a3 + 4LL * v6);
v7 = (*a2)++;
v8 = *(int *)(a3 + 4LL * v7);
a1[3] = v8;
if ( v8 )
{
v9 = 0;
do
AxleLoadSpeedProfile_2_1_DecodeInt(&a1[2 * v9++ + 4], a2, a3);
while ( (unsigned __int64)v9 < a1[3] );
}
return 1LL;
}

original_code:
int AxleLoadSpeedProfile_2_DecodeInt(AxleLoadSpeedProfile_2* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->D_AXLELOAD = stream[(*startAddress)++];
    p->L_AXLELOAD = stream[(*startAddress)++];
    p->Q_FRONT = stream[(*startAddress)++];
    p->N_ITER_2_1 = stream[(*startAddress)++];
    for (uint32_t i = 0; i < p->N_ITER_2_1; ++i)
    {
        AxleLoadSpeedProfile_2_1_DecodeInt(&(p->sub_2_1[i]), startAddress, stream);
    }
    return 1;
}

canonical_original_code:
int AxleLoadSpeedProfile_2_DecodeInt(struct AxleLoadSpeedProfile_2 *p, int *startAddress, int *stream)
{
    p->D_AXLELOAD = stream[(*startAddress)++];
    p->L_AXLELOAD = stream[(*startAddress)++];
    p->Q_FRONT = stream[(*startAddress)++];
    p->N_ITER_2_1 = stream[(*startAddress)++];
    for (unsigned int i = 0; i < p->N_ITER_2_1; ++i)
    {
        AxleLoadSpeedProfile_2_1_DecodeInt(&(p->sub_2_1[i]), startAddress, stream);
    }
    return 1;
}


decompiled_code:
_BOOL8 __fastcall StopIfInStaffResponsible_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL8 result; // rax

result = UpperBitsNotSet64(a1[2], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[3], 13);
if ( result )
result = UpperBitsNotSet64(a1[4], 1);
}
return result;
}

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

result = func0(a1[2], 2);
if ( result )
{
result = func0(a1[3], 13);
if ( result )
result = func0(a1[4], 1);
}
return result;
}

original_code:
int StopIfInStaffResponsible_UpperBitsNotSet(const StopIfInStaffResponsible* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SRSTOP, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int StopIfInStaffResponsible_UpperBitsNotSet(struct StopIfInStaffResponsible *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SRSTOP, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct StopIfInStaffResponsible { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SRSTOP; } *

user_defined_types: struct StopIfInStaffResponsible { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SRSTOP; }


decompiled_code:
__int64 __fastcall StopIfInStaffResponsible_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 16LL) )
return 0xFFFFFFFFLL;
if ( !StopIfInStaffResponsible_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
return 1LL;
}

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

original_code:
int StopIfInStaffResponsible_EncodeBit(const StopIfInStaffResponsible* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        if (StopIfInStaffResponsible_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_SRSTOP);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int StopIfInStaffResponsible_EncodeBit(struct StopIfInStaffResponsible *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        if (StopIfInStaffResponsible_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_SRSTOP);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

result = Bitstream_Normal(a2, 16LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = 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, 16LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 1LL);
result = 1LL;
}
return result;
}

original_code:
int StopIfInStaffResponsible_DecodeBit(StopIfInStaffResponsible* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SRSTOP = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int StopIfInStaffResponsible_DecodeBit(struct StopIfInStaffResponsible *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SRSTOP = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int StopIfInStaffResponsible_EncodeInt(const StopIfInStaffResponsible* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 137;
    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_SRSTOP;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int StopIfInStaffResponsible_EncodeInt(struct StopIfInStaffResponsible *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 137;
    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_SRSTOP;
    data->endAddress = startAddress-1;
    return 1;
}


decompiled_code:
_BOOL8 __fastcall StopIfInStaffResponsible_DecodeInt(_QWORD *a1, _DWORD *a2, __int64 a3)
{
_BOOL8 result; // rax
int v4; // eax

result = 0LL;
if ( *a2 == 137 )
{
v4 = a2[3];
*a1 = *(int *)(a3 + 4LL * v4);
a1[2] = *(int *)(a3 + 4LL * v4 + 4);
a1[3] = *(int *)(a3 + 4LL * v4 + 8);
a1[4] = *(int *)(a3 + 4LL * v4 + 12);
result = a2[4] == v4 + 3;
}
return result;
}

original_code:
int StopIfInStaffResponsible_DecodeInt(StopIfInStaffResponsible* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 137)
    {
         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_SRSTOP = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int StopIfInStaffResponsible_DecodeInt(struct StopIfInStaffResponsible *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 137)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SRSTOP = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


decompiled_code:
__int64 *StopIfInStaffResponsible_New()
{
__int64 *v0; // rbx

if ( StopIfInStaffResponsibleMemoryFreeList == -1 )
{
if ( (unsigned __int64)StopIfInStaffResponsibleMemoryTop > 7 )
return 0LL;
v0 = &StopIfInStaffResponsibleMemory[5 * StopIfInStaffResponsibleMemoryTop++];
}
else
{
v0 = &StopIfInStaffResponsibleMemory[5 * StopIfInStaffResponsibleMemoryFreeList];
StopIfInStaffResponsibleMemoryFreeList = *v0;
}
StopIfInStaffResponsible_Init(v0);
return v0;
}

canonical_decompiled_code:
__int64 *func7()
{
__int64 *v0; // rbx

if ( StopIfInStaffResponsibleMemoryFreeList == -1 )
{
if ( (unsigned __int64)StopIfInStaffResponsibleMemoryTop > 7 )
return 0LL;
v0 = &StopIfInStaffResponsibleMemory[5 * StopIfInStaffResponsibleMemoryTop++];
}
else
{
v0 = &StopIfInStaffResponsibleMemory[5 * StopIfInStaffResponsibleMemoryFreeList];
StopIfInStaffResponsibleMemoryFreeList = *v0;
}
func1(v0);
return v0;
}

original_code:
StopIfInStaffResponsible* StopIfInStaffResponsible_New(void)
{
    StopIfInStaffResponsible* ptr;
    if (StopIfInStaffResponsibleMemoryFreeList != (-1))
    {
        ptr = &StopIfInStaffResponsibleMemory[StopIfInStaffResponsibleMemoryFreeList];
        StopIfInStaffResponsibleMemoryFreeList = StopIfInStaffResponsibleMemory[StopIfInStaffResponsibleMemoryFreeList].header.NID_PACKET;
    }
    else if (StopIfInStaffResponsibleMemoryTop < 8)
    {
        ptr = &StopIfInStaffResponsibleMemory[StopIfInStaffResponsibleMemoryTop];
        StopIfInStaffResponsibleMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    StopIfInStaffResponsible_Init(ptr);
    return ptr;
}

canonical_original_code:
struct StopIfInStaffResponsible *StopIfInStaffResponsible_New()
{
    struct StopIfInStaffResponsible *ptr;
    if (StopIfInStaffResponsibleMemoryFreeList != (-1))
    {
        ptr = &StopIfInStaffResponsibleMemory[StopIfInStaffResponsibleMemoryFreeList];
        StopIfInStaffResponsibleMemoryFreeList = StopIfInStaffResponsibleMemory[StopIfInStaffResponsibleMemoryFreeList].header.NID_PACKET;
    }
    else if (StopIfInStaffResponsibleMemoryTop < 8)
    {
        ptr = &StopIfInStaffResponsibleMemory[StopIfInStaffResponsibleMemoryTop];
        StopIfInStaffResponsibleMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    StopIfInStaffResponsible_Init(ptr);
    return ptr;
}

return_type: struct StopIfInStaffResponsible { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SRSTOP; } *


decompiled_code:
unsigned __int64 __fastcall StopIfInStaffResponsible_Delete(_QWORD *a1)
{
unsigned __int64 result; // rax

*a1 = StopIfInStaffResponsibleMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
StopIfInStaffResponsibleMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL * (a1 - StopIfInStaffResponsibleMemory);
return result;
}

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

*a1 = StopIfInStaffResponsibleMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
StopIfInStaffResponsibleMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL * (a1 - StopIfInStaffResponsibleMemory);
return result;
}

original_code:
void StopIfInStaffResponsible_Delete(StopIfInStaffResponsible* ptr)
{
    ptr->header.NID_PACKET = StopIfInStaffResponsibleMemoryFreeList;
    StopIfInStaffResponsibleMemoryFreeList = ptr - StopIfInStaffResponsibleMemory;
}

canonical_original_code:
void StopIfInStaffResponsible_Delete(struct StopIfInStaffResponsible *ptr)
{
    ptr->header.NID_PACKET = StopIfInStaffResponsibleMemoryFreeList;
    StopIfInStaffResponsibleMemoryFreeList = ptr - StopIfInStaffResponsibleMemory;
}


decompiled_code:
_BOOL8 __fastcall TelegramHeader_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL8 result; // rax

result = UpperBitsNotSet64(*a1, 1);
if ( result )
{
result = UpperBitsNotSet64(a1[1], 7);
if ( result )
{
result = UpperBitsNotSet64(a1[2], 1);
if ( result )
{
result = UpperBitsNotSet64(a1[3], 3);
if ( result )
{
result = UpperBitsNotSet64(a1[4], 3);
if ( result )
{
result = UpperBitsNotSet64(a1[5], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[6], 8);
if ( result )
{
result = UpperBitsNotSet64(a1[7], 10);
if ( result )
{
result = UpperBitsNotSet64(a1[8], 14);
if ( result )
result = UpperBitsNotSet64(a1[9], 1);
}
}
}
}
}
}
}
}
return result;
}

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

result = func0(*a1, 1);
if ( result )
{
result = func0(a1[1], 7);
if ( result )
{
result = func0(a1[2], 1);
if ( result )
{
result = func0(a1[3], 3);
if ( result )
{
result = func0(a1[4], 3);
if ( result )
{
result = func0(a1[5], 2);
if ( result )
{
result = func0(a1[6], 8);
if ( result )
{
result = func0(a1[7], 10);
if ( result )
{
result = func0(a1[8], 14);
if ( result )
result = func0(a1[9], 1);
}
}
}
}
}
}
}
}
return result;
}

original_code:
static inline
int TelegramHeader_UpperBitsNotSet(const TelegramHeader* p)
{
    if (UpperBitsNotSet64(p->Q_UPDOWN, 1) &&
        UpperBitsNotSet64(p->M_VERSION, 7) &&
        UpperBitsNotSet64(p->Q_MEDIA, 1) &&
        UpperBitsNotSet64(p->N_PIG, 3) &&
        UpperBitsNotSet64(p->N_TOTAL, 3) &&
        UpperBitsNotSet64(p->M_DUP, 2) &&
        UpperBitsNotSet64(p->M_MCOUNT, 8) &&
        UpperBitsNotSet64(p->NID_C, 10) &&
        UpperBitsNotSet64(p->NID_BG, 14) &&
        UpperBitsNotSet64(p->Q_LINK, 1))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
static inline int TelegramHeader_UpperBitsNotSet(struct TelegramHeader *p)
{
    if (UpperBitsNotSet64(p->Q_UPDOWN, 1) &&
        UpperBitsNotSet64(p->M_VERSION, 7) &&
        UpperBitsNotSet64(p->Q_MEDIA, 1) &&
        UpperBitsNotSet64(p->N_PIG, 3) &&
        UpperBitsNotSet64(p->N_TOTAL, 3) &&
        UpperBitsNotSet64(p->M_DUP, 2) &&
        UpperBitsNotSet64(p->M_MCOUNT, 8) &&
        UpperBitsNotSet64(p->NID_C, 10) &&
        UpperBitsNotSet64(p->NID_BG, 14) &&
        UpperBitsNotSet64(p->Q_LINK, 1))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct TelegramHeader { unsigned long Q_UPDOWN; unsigned long M_VERSION; unsigned long Q_MEDIA; unsigned long N_PIG; unsigned long N_TOTAL; unsigned long M_DUP; unsigned long M_MCOUNT; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINK; } *


original_code:
static inline int TelegramHeader_Equal(const TelegramHeader* a, const TelegramHeader* b)
{
    return (a->Q_UPDOWN == b->Q_UPDOWN) &&
           (a->M_VERSION == b->M_VERSION) &&
           (a->Q_MEDIA == b->Q_MEDIA) &&
           (a->N_PIG == b->N_PIG) &&
           (a->N_TOTAL == b->N_TOTAL) &&
           (a->M_DUP == b->M_DUP) &&
           (a->M_MCOUNT == b->M_MCOUNT) &&
           (a->NID_C == b->NID_C) &&
           (a->NID_BG == b->NID_BG) &&
           (a->Q_LINK == b->Q_LINK);
}

canonical_original_code:
static inline int TelegramHeader_Equal(struct TelegramHeader *a, struct TelegramHeader *b)
{
    return (a->Q_UPDOWN == b->Q_UPDOWN) &&
           (a->M_VERSION == b->M_VERSION) &&
           (a->Q_MEDIA == b->Q_MEDIA) &&
           (a->N_PIG == b->N_PIG) &&
           (a->N_TOTAL == b->N_TOTAL) &&
           (a->M_DUP == b->M_DUP) &&
           (a->M_MCOUNT == b->M_MCOUNT) &&
           (a->NID_C == b->NID_C) &&
           (a->NID_BG == b->NID_BG) &&
           (a->Q_LINK == b->Q_LINK);
}

variable_types:
b
struct TelegramHeader *

user_defined_types: struct TelegramHeader { unsigned long Q_UPDOWN; unsigned long M_VERSION; unsigned long Q_MEDIA; unsigned long N_PIG; unsigned long N_TOTAL; unsigned long M_DUP; unsigned long M_MCOUNT; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINK; }


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

LODWORD(result) = *(_DWORD *)(a1 + 400);
if ( (unsigned int)result > 0x31 )
_assert_fail("s->size < 50", "..//Telegram/PacketSequence.h", 0x2Au, "PacketSequence_Add");
*(_DWORD *)(a1 + 400) = result + 1;
result = (unsigned int)result;
*(_QWORD *)(a1 + 8LL * (unsigned int)result) = a2;
return result;
}

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

LODWORD(result) = *(_DWORD *)(a1 + 400);
if ( (unsigned int)result > 0x31 )
_assert_fail("s->size < 50", "..//Telegram/PacketSequence.h", 0x2Au, "PacketSequence_Add");
*(_DWORD *)(a1 + 400) = result + 1;
result = (unsigned int)result;
*(_QWORD *)(a1 + 8LL * (unsigned int)result) = a2;
return result;
}

original_code:
static inline void PacketSequence_Add(PacketSequence* s, PacketHeader* h)
{
    ((s->size < 50) ? (void) (0) : __assert_fail ("s->size < 50", "..//Telegram/PacketSequence.h", 42, __extension__ __PRETTY_FUNCTION__));
    s->header[s->size++] = h;
}

canonical_original_code:
static inline void PacketSequence_Add(struct PacketSequence *s, struct PacketHeader *h)
{
    ((s->size < 50) ? (void) (0) : __assert_fail ("s->size < 50", "..//Telegram/PacketSequence.h", 42, __extension__ __PRETTY_FUNCTION__));
    s->header[s->size++] = h;
}

variable_types: struct PacketSequence { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } *header[50]; unsigned int size; } *

variable_types:
h
struct PacketHeader *

user_defined_types: struct PacketSequence { struct PacketHeader *header[50]; unsigned int size; }


decompiled_code:
__int64 __fastcall EurobaliseTelegram_Add(__int64 a1, __int64 a2)
{
return PacketSequence_Add(a1 + 80, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return func7(a1 + 80, a2);
}

original_code:
static inline void EurobaliseTelegram_Add(EurobaliseTelegram* t, PacketHeader* p)
{
    PacketSequence_Add(&t->packets, p);
}

canonical_original_code:
static inline void EurobaliseTelegram_Add(struct EurobaliseTelegram *t, struct PacketHeader *p)
{
    PacketSequence_Add(&t->packets, p);
}

variable_types: struct EurobaliseTelegram { struct TelegramHeader { unsigned long Q_UPDOWN; unsigned long M_VERSION; unsigned long Q_MEDIA; unsigned long N_PIG; unsigned long N_TOTAL; unsigned long M_DUP; unsigned long M_MCOUNT; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINK; } header; struct PacketSequence { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } *header[50]; unsigned int size; } packets; } *

variable_types:
p
struct PacketHeader *

user_defined_types: struct EurobaliseTelegram { struct TelegramHeader header; struct PacketSequence packets; }


decompiled_code:
__int64 __fastcall PacketSequence_Get(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a1 + 400);
if ( v2 > 0x31 )
_assert_fail("s->size < 50", "..//Telegram/PacketSequence.h", 0x30u, "PacketSequence_Get");
if ( v2 <= a2 )
_assert_fail("i < s->size", "..//Telegram/PacketSequence.h", 0x31u, "PacketSequence_Get");
return *(_QWORD *)(a1 + 8LL * a2);
}

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

v2 = *(_DWORD *)(a1 + 400);
if ( v2 > 0x31 )
_assert_fail("s->size < 50", "..//Telegram/PacketSequence.h", 0x30u, "PacketSequence_Get");
if ( v2 <= a2 )
_assert_fail("i < s->size", "..//Telegram/PacketSequence.h", 0x31u, "PacketSequence_Get");
return *(_QWORD *)(a1 + 8LL * a2);
}

original_code:
static inline const PacketHeader* PacketSequence_Get(const PacketSequence* s, uint32_t i)
{
    ((s->size < 50) ? (void) (0) : __assert_fail ("s->size < 50", "..//Telegram/PacketSequence.h", 48, __extension__ __PRETTY_FUNCTION__));
    ((i < s->size) ? (void) (0) : __assert_fail ("i < s->size", "..//Telegram/PacketSequence.h", 49, __extension__ __PRETTY_FUNCTION__));
    return s->header[i];
}

canonical_original_code:
static inline struct PacketHeader *PacketSequence_Get(struct PacketSequence *s, unsigned int i)
{
    ((s->size < 50) ? (void) (0) : __assert_fail ("s->size < 50", "..//Telegram/PacketSequence.h", 48, __extension__ __PRETTY_FUNCTION__));
    ((i < s->size) ? (void) (0) : __assert_fail ("i < s->size", "..//Telegram/PacketSequence.h", 49, __extension__ __PRETTY_FUNCTION__));
    return s->header[i];
}

variable_types: struct PacketSequence { struct PacketHeader *header[50]; unsigned int size; } *

return_type: struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } *


decompiled_code:
__int64 __fastcall EurobaliseTelegram_Get(__int64 a1, unsigned int a2)
{
return PacketSequence_Get(a1 + 80, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2)
{
return func9(a1 + 80, a2);
}

original_code:
static inline const PacketHeader* EurobaliseTelegram_Get(const EurobaliseTelegram* t, uint32_t i)
{
    return PacketSequence_Get(&t->packets, i);
}

canonical_original_code:
static inline struct PacketHeader *EurobaliseTelegram_Get(struct EurobaliseTelegram *t, unsigned int i)
{
    return PacketSequence_Get(&t->packets, i);
}

variable_types: struct EurobaliseTelegram { struct TelegramHeader { unsigned long Q_UPDOWN; unsigned long M_VERSION; unsigned long Q_MEDIA; unsigned long N_PIG; unsigned long N_TOTAL; unsigned long M_DUP; unsigned long M_MCOUNT; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINK; } header; struct PacketSequence { struct PacketHeader *header[50]; unsigned int size; } packets; } *


decompiled_code:
__int64 __fastcall PacketSequence_Back(__int64 a1)
{
int v1; // esi

v1 = *(_DWORD *)(a1 + 400);
if ( !v1 )
_assert_fail("s->size > 0", "..//Telegram/PacketSequence.h", 0x38u, "PacketSequence_Back");
return PacketSequence_Get(a1, v1 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // esi

v1 = *(_DWORD *)(a1 + 400);
if ( !v1 )
_assert_fail("s->size > 0", "..//Telegram/PacketSequence.h", 0x38u, "PacketSequence_Back");
return func9(a1, v1 - 1);
}

original_code:
static inline const PacketHeader* PacketSequence_Back(const PacketSequence* s)
{
    ((s->size > 0) ? (void) (0) : __assert_fail ("s->size > 0", "..//Telegram/PacketSequence.h", 56, __extension__ __PRETTY_FUNCTION__));
    return PacketSequence_Get(s, s->size - 1);
}

canonical_original_code:
static inline struct PacketHeader *PacketSequence_Back(struct PacketSequence *s)
{
    ((s->size > 0) ? (void) (0) : __assert_fail ("s->size > 0", "..//Telegram/PacketSequence.h", 56, __extension__ __PRETTY_FUNCTION__));
    return PacketSequence_Get(s, s->size - 1);
}


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

result = Bitstream_Normal(a1, 50LL);
if ( (_DWORD)result )
{
*a2 = Bitstream_Read(a1, 1LL);
a2[1] = Bitstream_Read(a1, 7LL);
a2[2] = Bitstream_Read(a1, 1LL);
a2[3] = Bitstream_Read(a1, 3LL);
a2[4] = Bitstream_Read(a1, 3LL);
a2[5] = Bitstream_Read(a1, 2LL);
a2[6] = Bitstream_Read(a1, 8LL);
a2[7] = Bitstream_Read(a1, 10LL);
a2[8] = Bitstream_Read(a1, 14LL);
a2[9] = Bitstream_Read(a1, 1LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a1, 50LL);
if ( (_DWORD)result )
{
*a2 = Bitstream_Read(a1, 1LL);
a2[1] = Bitstream_Read(a1, 7LL);
a2[2] = Bitstream_Read(a1, 1LL);
a2[3] = Bitstream_Read(a1, 3LL);
a2[4] = Bitstream_Read(a1, 3LL);
a2[5] = Bitstream_Read(a1, 2LL);
a2[6] = Bitstream_Read(a1, 8LL);
a2[7] = Bitstream_Read(a1, 10LL);
a2[8] = Bitstream_Read(a1, 14LL);
a2[9] = Bitstream_Read(a1, 1LL);
result = 1LL;
}
return result;
}

original_code:
static inline
int TelegramHeader_DecodeBit(Bitstream* stream, TelegramHeader* p)
{
    if (Bitstream_Normal(stream, 50))
    {
        {
            p->Q_UPDOWN = Bitstream_Read(stream, 1);
        }
        {
            p->M_VERSION = Bitstream_Read(stream, 7);
        }
        {
            p->Q_MEDIA = Bitstream_Read(stream, 1);
        }
        {
            p->N_PIG = Bitstream_Read(stream, 3);
        }
        {
            p->N_TOTAL = Bitstream_Read(stream, 3);
        }
        {
            p->M_DUP = Bitstream_Read(stream, 2);
        }
        {
            p->M_MCOUNT = Bitstream_Read(stream, 8);
        }
        {
            p->NID_C = Bitstream_Read(stream, 10);
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        {
            p->Q_LINK = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
static inline int TelegramHeader_DecodeBit(struct Bitstream *stream, struct TelegramHeader *p)
{
    if (Bitstream_Normal(stream, 50))
    {
        {
            p->Q_UPDOWN = Bitstream_Read(stream, 1);
        }
        {
            p->M_VERSION = Bitstream_Read(stream, 7);
        }
        {
            p->Q_MEDIA = Bitstream_Read(stream, 1);
        }
        {
            p->N_PIG = Bitstream_Read(stream, 3);
        }
        {
            p->N_TOTAL = Bitstream_Read(stream, 3);
        }
        {
            p->M_DUP = Bitstream_Read(stream, 2);
        }
        {
            p->M_MCOUNT = Bitstream_Read(stream, 8);
        }
        {
            p->NID_C = Bitstream_Read(stream, 10);
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        {
            p->Q_LINK = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

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


decompiled_code:
__int64 __fastcall TelegramHeader_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 50LL) )
return 0xFFFFFFFFLL;
if ( !TelegramHeader_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 1LL, *a1);
Bitstream_Write(a2, 7LL, a1[1]);
Bitstream_Write(a2, 1LL, a1[2]);
Bitstream_Write(a2, 3LL, a1[3]);
Bitstream_Write(a2, 3LL, a1[4]);
Bitstream_Write(a2, 2LL, a1[5]);
Bitstream_Write(a2, 8LL, a1[6]);
Bitstream_Write(a2, 10LL, a1[7]);
Bitstream_Write(a2, 14LL, a1[8]);
Bitstream_Write(a2, 1LL, a1[9]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 50LL) )
return 0xFFFFFFFFLL;
if ( !func2(a1) )
return 4294967294LL;
Bitstream_Write(a2, 1LL, *a1);
Bitstream_Write(a2, 7LL, a1[1]);
Bitstream_Write(a2, 1LL, a1[2]);
Bitstream_Write(a2, 3LL, a1[3]);
Bitstream_Write(a2, 3LL, a1[4]);
Bitstream_Write(a2, 2LL, a1[5]);
Bitstream_Write(a2, 8LL, a1[6]);
Bitstream_Write(a2, 10LL, a1[7]);
Bitstream_Write(a2, 14LL, a1[8]);
Bitstream_Write(a2, 1LL, a1[9]);
return 1LL;
}

original_code:
static inline
int TelegramHeader_EncodeBit(const TelegramHeader* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 50))
    {
        if (TelegramHeader_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 1, p->Q_UPDOWN);
            Bitstream_Write(stream, 7, p->M_VERSION);
            Bitstream_Write(stream, 1, p->Q_MEDIA);
            Bitstream_Write(stream, 3, p->N_PIG);
            Bitstream_Write(stream, 3, p->N_TOTAL);
            Bitstream_Write(stream, 2, p->M_DUP);
            Bitstream_Write(stream, 8, p->M_MCOUNT);
            Bitstream_Write(stream, 10, p->NID_C);
            Bitstream_Write(stream, 14, p->NID_BG);
            Bitstream_Write(stream, 1, p->Q_LINK);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
static inline int TelegramHeader_EncodeBit(struct TelegramHeader *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 50))
    {
        if (TelegramHeader_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 1, p->Q_UPDOWN);
            Bitstream_Write(stream, 7, p->M_VERSION);
            Bitstream_Write(stream, 1, p->Q_MEDIA);
            Bitstream_Write(stream, 3, p->N_PIG);
            Bitstream_Write(stream, 3, p->N_TOTAL);
            Bitstream_Write(stream, 2, p->M_DUP);
            Bitstream_Write(stream, 8, p->M_MCOUNT);
            Bitstream_Write(stream, 10, p->NID_C);
            Bitstream_Write(stream, 14, p->NID_BG);
            Bitstream_Write(stream, 1, p->Q_LINK);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}