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

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

original_code:
int ErrorReporting_EncodeBit(const ErrorReporting* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 21))
    {
        if (ErrorReporting_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 8, p->M_ERROR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ErrorReporting_EncodeBit(struct ErrorReporting *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 21))
    {
        if (ErrorReporting_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 8, p->M_ERROR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


repo: openETCS/dataDictionary

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

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

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

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

original_code:
int ErrorReporting_DecodeBit(ErrorReporting* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 21))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->M_ERROR = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ErrorReporting_DecodeBit(struct ErrorReporting *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 21))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->M_ERROR = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ErrorReporting { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long M_ERROR; } *

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

return_type: int

user_defined_types: struct ErrorReporting { struct PacketHeader header; unsigned long L_PACKET; unsigned long M_ERROR; }


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

canonical_original_code:
int ErrorReporting_EncodeInt(struct ErrorReporting *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 4;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->M_ERROR;
    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; } *

variable_types:
stream
int *

variable_types: startAddress int

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


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

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

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


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

if ( ErrorReportingMemoryFreeList == -1 )
{
if ( (unsigned __int64)ErrorReportingMemoryTop > 7 )
return 0LL;
v3 = 4 * ErrorReportingMemoryTop++;
v0 = &ErrorReportingMemory[v3];
}
else
{
v0 = &ErrorReportingMemory[4 * ErrorReportingMemoryFreeList];
ErrorReportingMemoryFreeList = *v0;
}
ErrorReporting_Init(v0);
return v1;
}

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

if ( ErrorReportingMemoryFreeList == -1 )
{
if ( (unsigned __int64)ErrorReportingMemoryTop > 7 )
return 0LL;
v3 = 4 * ErrorReportingMemoryTop++;
v0 = &ErrorReportingMemory[v3];
}
else
{
v0 = &ErrorReportingMemory[4 * ErrorReportingMemoryFreeList];
ErrorReportingMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
ErrorReporting* ErrorReporting_New(void)
{
    ErrorReporting* ptr;
    if (ErrorReportingMemoryFreeList != (-1))
    {
        ptr = &ErrorReportingMemory[ErrorReportingMemoryFreeList];
        ErrorReportingMemoryFreeList = ErrorReportingMemory[ErrorReportingMemoryFreeList].header.NID_PACKET;
    }
    else if (ErrorReportingMemoryTop < 8)
    {
        ptr = &ErrorReportingMemory[ErrorReportingMemoryTop];
        ErrorReportingMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ErrorReporting_Init(ptr);
    return ptr;
}

canonical_original_code:
struct ErrorReporting *ErrorReporting_New()
{
    struct ErrorReporting *ptr;
    if (ErrorReportingMemoryFreeList != (-1))
    {
        ptr = &ErrorReportingMemory[ErrorReportingMemoryFreeList];
        ErrorReportingMemoryFreeList = ErrorReportingMemory[ErrorReportingMemoryFreeList].header.NID_PACKET;
    }
    else if (ErrorReportingMemoryTop < 8)
    {
        ptr = &ErrorReportingMemory[ErrorReportingMemoryTop];
        ErrorReportingMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ErrorReporting_Init(ptr);
    return ptr;
}

return_type: struct ErrorReporting { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long M_ERROR; } *


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

result = ErrorReportingMemoryFreeList;
*(_QWORD *)a1 = ErrorReportingMemoryFreeList;
ErrorReportingMemoryFreeList = (a1 - (char *)ErrorReportingMemory) >> 5;
return result;
}

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

result = ErrorReportingMemoryFreeList;
*(_QWORD *)a1 = ErrorReportingMemoryFreeList;
ErrorReportingMemoryFreeList = (a1 - (char *)ErrorReportingMemory) >> 5;
return result;
}

original_code:
void ErrorReporting_Delete(ErrorReporting* ptr)
{
    ptr->header.NID_PACKET = ErrorReportingMemoryFreeList;
    ErrorReportingMemoryFreeList = ptr - ErrorReportingMemory;
}

canonical_original_code:
void ErrorReporting_Delete(struct ErrorReporting *ptr)
{
    ptr->header.NID_PACKET = ErrorReportingMemoryFreeList;
    ErrorReportingMemoryFreeList = ptr - ErrorReportingMemory;
}

return_type: void


decompiled_code:
_BOOL8 __fastcall ValidatedTrainData_2_UpperBitsNotSet(unsigned __int64 *a1)
{
return UpperBitsNotSet64_constprop_0(*a1);
}

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

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

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

variable_types: struct ValidatedTrainData_2 { unsigned long NID_STM; } *

variable_types: status int


decompiled_code:
__int64 __fastcall ValidatedTrainData_2_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 8LL) )
return 0xFFFFFFFFLL;
if ( !ValidatedTrainData_2_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_2_EncodeBit(const ValidatedTrainData_2* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        if (ValidatedTrainData_2_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 8, p->NID_STM);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ValidatedTrainData_2_EncodeBit(struct ValidatedTrainData_2 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        if (ValidatedTrainData_2_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 8, p->NID_STM);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct ValidatedTrainData_2 { unsigned long NID_STM; }

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


decompiled_code:
__int64 __fastcall ValidatedTrainData_2_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_2_DecodeBit(ValidatedTrainData_2* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        {
            p->NID_STM = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

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


decompiled_code:
__int64 __fastcall ValidatedTrainData_2_EncodeInt(__int64 *a1, int *a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rcx

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

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

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

variable_types:
startAddress
int *


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

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

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

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


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

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

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

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

variable_types:
value
unsigned long

variable_types:
length
unsigned int

variable_types:
MaxValue
unsigned long


decompiled_code:
_BOOL8 __fastcall DangerForShuntingInformation_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 13);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 32), 1);
}
return result;
}

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

result = func0(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = func0(*(_QWORD *)(v2 + 24), 13);
if ( result )
result = func0(*(_QWORD *)(v3 + 32), 1);
}
return result;
}

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

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

variable_types: struct DangerForShuntingInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_ASPECT; } *

user_defined_types: struct DangerForShuntingInformation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_ASPECT; }


decompiled_code:
__int64 __fastcall DangerForShuntingInformation_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 16LL) )
return 0xFFFFFFFFLL;
if ( !DangerForShuntingInformation_UpperBitsNotSet((__int64)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(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 16LL) )
return 0xFFFFFFFFLL;
if ( !func2((__int64)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 DangerForShuntingInformation_EncodeBit(const DangerForShuntingInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        if (DangerForShuntingInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_ASPECT);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int DangerForShuntingInformation_EncodeBit(struct DangerForShuntingInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        if (DangerForShuntingInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_ASPECT);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


decompiled_code:
__int64 __fastcall DangerForShuntingInformation_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 DangerForShuntingInformation_DecodeBit(DangerForShuntingInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 16))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_ASPECT = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int DangerForShuntingInformation_DecodeBit(struct DangerForShuntingInformation *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_ASPECT = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int DangerForShuntingInformation_EncodeInt(const DangerForShuntingInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 132;
    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_ASPECT;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int DangerForShuntingInformation_EncodeInt(struct DangerForShuntingInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 132;
    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_ASPECT;
    data->endAddress = startAddress-1;
    return 1;
}


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

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


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

if ( DangerForShuntingInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)DangerForShuntingInformationMemoryTop > 7 )
return 0LL;
v3 = 5 * DangerForShuntingInformationMemoryTop++;
v0 = &DangerForShuntingInformationMemory[v3];
}
else
{
v0 = &DangerForShuntingInformationMemory[5 * DangerForShuntingInformationMemoryFreeList];
DangerForShuntingInformationMemoryFreeList = *v0;
}
DangerForShuntingInformation_Init(v0);
return v1;
}

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

if ( DangerForShuntingInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)DangerForShuntingInformationMemoryTop > 7 )
return 0LL;
v3 = 5 * DangerForShuntingInformationMemoryTop++;
v0 = &DangerForShuntingInformationMemory[v3];
}
else
{
v0 = &DangerForShuntingInformationMemory[5 * DangerForShuntingInformationMemoryFreeList];
DangerForShuntingInformationMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
DangerForShuntingInformation* DangerForShuntingInformation_New(void)
{
    DangerForShuntingInformation* ptr;
    if (DangerForShuntingInformationMemoryFreeList != (-1))
    {
        ptr = &DangerForShuntingInformationMemory[DangerForShuntingInformationMemoryFreeList];
        DangerForShuntingInformationMemoryFreeList = DangerForShuntingInformationMemory[DangerForShuntingInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (DangerForShuntingInformationMemoryTop < 8)
    {
        ptr = &DangerForShuntingInformationMemory[DangerForShuntingInformationMemoryTop];
        DangerForShuntingInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DangerForShuntingInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct DangerForShuntingInformation *DangerForShuntingInformation_New()
{
    struct DangerForShuntingInformation *ptr;
    if (DangerForShuntingInformationMemoryFreeList != (-1))
    {
        ptr = &DangerForShuntingInformationMemory[DangerForShuntingInformationMemoryFreeList];
        DangerForShuntingInformationMemoryFreeList = DangerForShuntingInformationMemory[DangerForShuntingInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (DangerForShuntingInformationMemoryTop < 8)
    {
        ptr = &DangerForShuntingInformationMemory[DangerForShuntingInformationMemoryTop];
        DangerForShuntingInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DangerForShuntingInformation_Init(ptr);
    return ptr;
}

return_type: struct DangerForShuntingInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_ASPECT; } *


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

*a1 = DangerForShuntingInformationMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
DangerForShuntingInformationMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL * (a1 - DangerForShuntingInformationMemory);
return result;
}

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

*a1 = DangerForShuntingInformationMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
DangerForShuntingInformationMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL * (a1 - DangerForShuntingInformationMemory);
return result;
}

original_code:
void DangerForShuntingInformation_Delete(DangerForShuntingInformation* ptr)
{
    ptr->header.NID_PACKET = DangerForShuntingInformationMemoryFreeList;
    DangerForShuntingInformationMemoryFreeList = ptr - DangerForShuntingInformationMemory;
}

canonical_original_code:
void DangerForShuntingInformation_Delete(struct DangerForShuntingInformation *ptr)
{
    ptr->header.NID_PACKET = DangerForShuntingInformationMemoryFreeList;
    DangerForShuntingInformationMemoryFreeList = ptr - DangerForShuntingInformationMemory;
}


decompiled_code:
_BOOL8 __fastcall TemporarySpeedRestrictionRevocation_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 13);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 32), 8);
}
return result;
}

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

result = func0(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = func0(*(_QWORD *)(v2 + 24), 13);
if ( result )
result = func0(*(_QWORD *)(v3 + 32), 8);
}
return result;
}

original_code:
int TemporarySpeedRestrictionRevocation_UpperBitsNotSet(const TemporarySpeedRestrictionRevocation* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->NID_TSR, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TemporarySpeedRestrictionRevocation_UpperBitsNotSet(struct TemporarySpeedRestrictionRevocation *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->NID_TSR, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct TemporarySpeedRestrictionRevocation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long NID_TSR; } *

user_defined_types: struct TemporarySpeedRestrictionRevocation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long NID_TSR; }


decompiled_code:
__int64 __fastcall TemporarySpeedRestrictionRevocation_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 23LL) )
return 0xFFFFFFFFLL;
if ( !TemporarySpeedRestrictionRevocation_UpperBitsNotSet((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 8LL, a1[4]);
return 1LL;
}

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

original_code:
int TemporarySpeedRestrictionRevocation_EncodeBit(const TemporarySpeedRestrictionRevocation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 23))
    {
        if (TemporarySpeedRestrictionRevocation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 8, p->NID_TSR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int TemporarySpeedRestrictionRevocation_EncodeBit(struct TemporarySpeedRestrictionRevocation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 23))
    {
        if (TemporarySpeedRestrictionRevocation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 8, p->NID_TSR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

result = Bitstream_Normal(a2, 23LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 8LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 23LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 8LL);
result = 1LL;
}
return result;
}

original_code:
int TemporarySpeedRestrictionRevocation_DecodeBit(TemporarySpeedRestrictionRevocation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 23))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->NID_TSR = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TemporarySpeedRestrictionRevocation_DecodeBit(struct TemporarySpeedRestrictionRevocation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 23))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->NID_TSR = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int TemporarySpeedRestrictionRevocation_EncodeInt(const TemporarySpeedRestrictionRevocation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 66;
    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->NID_TSR;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int TemporarySpeedRestrictionRevocation_EncodeInt(struct TemporarySpeedRestrictionRevocation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 66;
    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->NID_TSR;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int TemporarySpeedRestrictionRevocation_DecodeInt(TemporarySpeedRestrictionRevocation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 66)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->NID_TSR = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

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


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

if ( TemporarySpeedRestrictionRevocationMemoryFreeList == -1 )
{
if ( (unsigned __int64)TemporarySpeedRestrictionRevocationMemoryTop > 7 )
return 0LL;
v3 = 5 * TemporarySpeedRestrictionRevocationMemoryTop++;
v0 = &TemporarySpeedRestrictionRevocationMemory[v3];
}
else
{
v0 = &TemporarySpeedRestrictionRevocationMemory[5 * TemporarySpeedRestrictionRevocationMemoryFreeList];
TemporarySpeedRestrictionRevocationMemoryFreeList = *v0;
}
TemporarySpeedRestrictionRevocation_Init(v0);
return v1;
}

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

if ( TemporarySpeedRestrictionRevocationMemoryFreeList == -1 )
{
if ( (unsigned __int64)TemporarySpeedRestrictionRevocationMemoryTop > 7 )
return 0LL;
v3 = 5 * TemporarySpeedRestrictionRevocationMemoryTop++;
v0 = &TemporarySpeedRestrictionRevocationMemory[v3];
}
else
{
v0 = &TemporarySpeedRestrictionRevocationMemory[5 * TemporarySpeedRestrictionRevocationMemoryFreeList];
TemporarySpeedRestrictionRevocationMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
TemporarySpeedRestrictionRevocation* TemporarySpeedRestrictionRevocation_New(void)
{
    TemporarySpeedRestrictionRevocation* ptr;
    if (TemporarySpeedRestrictionRevocationMemoryFreeList != (-1))
    {
        ptr = &TemporarySpeedRestrictionRevocationMemory[TemporarySpeedRestrictionRevocationMemoryFreeList];
        TemporarySpeedRestrictionRevocationMemoryFreeList = TemporarySpeedRestrictionRevocationMemory[TemporarySpeedRestrictionRevocationMemoryFreeList].header.NID_PACKET;
    }
    else if (TemporarySpeedRestrictionRevocationMemoryTop < 8)
    {
        ptr = &TemporarySpeedRestrictionRevocationMemory[TemporarySpeedRestrictionRevocationMemoryTop];
        TemporarySpeedRestrictionRevocationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    TemporarySpeedRestrictionRevocation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct TemporarySpeedRestrictionRevocation *TemporarySpeedRestrictionRevocation_New()
{
    struct TemporarySpeedRestrictionRevocation *ptr;
    if (TemporarySpeedRestrictionRevocationMemoryFreeList != (-1))
    {
        ptr = &TemporarySpeedRestrictionRevocationMemory[TemporarySpeedRestrictionRevocationMemoryFreeList];
        TemporarySpeedRestrictionRevocationMemoryFreeList = TemporarySpeedRestrictionRevocationMemory[TemporarySpeedRestrictionRevocationMemoryFreeList].header.NID_PACKET;
    }
    else if (TemporarySpeedRestrictionRevocationMemoryTop < 8)
    {
        ptr = &TemporarySpeedRestrictionRevocationMemory[TemporarySpeedRestrictionRevocationMemoryTop];
        TemporarySpeedRestrictionRevocationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    TemporarySpeedRestrictionRevocation_Init(ptr);
    return ptr;
}

return_type: struct TemporarySpeedRestrictionRevocation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long NID_TSR; } *


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

*a1 = TemporarySpeedRestrictionRevocationMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
TemporarySpeedRestrictionRevocationMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL
* (a1 - TemporarySpeedRestrictionRevocationMemory);
return result;
}

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

*a1 = TemporarySpeedRestrictionRevocationMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
TemporarySpeedRestrictionRevocationMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL
* (a1 - TemporarySpeedRestrictionRevocationMemory);
return result;
}

original_code:
void TemporarySpeedRestrictionRevocation_Delete(TemporarySpeedRestrictionRevocation* ptr)
{
    ptr->header.NID_PACKET = TemporarySpeedRestrictionRevocationMemoryFreeList;
    TemporarySpeedRestrictionRevocationMemoryFreeList = ptr - TemporarySpeedRestrictionRevocationMemory;
}

canonical_original_code:
void TemporarySpeedRestrictionRevocation_Delete(struct TemporarySpeedRestrictionRevocation *ptr)
{
    ptr->header.NID_PACKET = TemporarySpeedRestrictionRevocationMemoryFreeList;
    TemporarySpeedRestrictionRevocationMemoryFreeList = ptr - TemporarySpeedRestrictionRevocationMemory;
}


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

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

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

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

original_code:
int DefaultGradientForTemporarySpeedRestriction_UpperBitsNotSet(const DefaultGradientForTemporarySpeedRestriction* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_GDIR, 1) ;
    status = status && UpperBitsNotSet64(p->G_TSR, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int DefaultGradientForTemporarySpeedRestriction_UpperBitsNotSet(struct DefaultGradientForTemporarySpeedRestriction *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_GDIR, 1) ;
    status = status && UpperBitsNotSet64(p->G_TSR, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct DefaultGradientForTemporarySpeedRestriction { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_GDIR; unsigned long G_TSR; } *

user_defined_types: struct DefaultGradientForTemporarySpeedRestriction { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_GDIR; unsigned long G_TSR; }


decompiled_code:
__int64 __fastcall DefaultGradientForTemporarySpeedRestriction_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 24LL) )
return 0xFFFFFFFFLL;
if ( !DefaultGradientForTemporarySpeedRestriction_UpperBitsNotSet((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
Bitstream_Write(a2, 8LL, a1[5]);
return 1LL;
}

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

original_code:
int DefaultGradientForTemporarySpeedRestriction_EncodeBit(const DefaultGradientForTemporarySpeedRestriction* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 24))
    {
        if (DefaultGradientForTemporarySpeedRestriction_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_GDIR);
            Bitstream_Write(stream, 8, p->G_TSR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int DefaultGradientForTemporarySpeedRestriction_EncodeBit(struct DefaultGradientForTemporarySpeedRestriction *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 24))
    {
        if (DefaultGradientForTemporarySpeedRestriction_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_GDIR);
            Bitstream_Write(stream, 8, p->G_TSR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

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

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

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

original_code:
int DefaultGradientForTemporarySpeedRestriction_DecodeBit(DefaultGradientForTemporarySpeedRestriction* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 24))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_GDIR = Bitstream_Read(stream, 1);
        }
        {
            p->G_TSR = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int DefaultGradientForTemporarySpeedRestriction_DecodeBit(struct DefaultGradientForTemporarySpeedRestriction *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 24))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_GDIR = Bitstream_Read(stream, 1);
        }
        {
            p->G_TSR = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int DefaultGradientForTemporarySpeedRestriction_EncodeInt(const DefaultGradientForTemporarySpeedRestriction* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 141;
    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_GDIR;
    stream[startAddress++] = p->G_TSR;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int DefaultGradientForTemporarySpeedRestriction_EncodeInt(struct DefaultGradientForTemporarySpeedRestriction *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 141;
    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_GDIR;
    stream[startAddress++] = p->G_TSR;
    data->endAddress = startAddress-1;
    return 1;
}


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

canonical_original_code:
int DefaultGradientForTemporarySpeedRestriction_DecodeInt(struct DefaultGradientForTemporarySpeedRestriction *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 141)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_GDIR = stream[startAddress++];
    p->G_TSR = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


decompiled_code:
void DefaultGradientForTemporarySpeedRestriction_New()
{
__int64 *v0; // rdi
__int64 v1; // rax

if ( DefaultGradientForTemporarySpeedRestrictionMemoryFreeList == -1 )
{
if ( (unsigned __int64)DefaultGradientForTemporarySpeedRestrictionMemoryTop <= 7 )
{
v1 = 6 * DefaultGradientForTemporarySpeedRestrictionMemoryTop++;
DefaultGradientForTemporarySpeedRestriction_Init(&DefaultGradientForTemporarySpeedRestrictionMemory[v1]);
}
}
else
{
v0 = &DefaultGradientForTemporarySpeedRestrictionMemory[6
* DefaultGradientForTemporarySpeedRestrictionMemoryFreeList];
DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = *v0;
DefaultGradientForTemporarySpeedRestriction_Init(v0);
}
}

canonical_decompiled_code:
void func7()
{
__int64 *v0; // rdi
__int64 v1; // rax

if ( DefaultGradientForTemporarySpeedRestrictionMemoryFreeList == -1 )
{
if ( (unsigned __int64)DefaultGradientForTemporarySpeedRestrictionMemoryTop <= 7 )
{
v1 = 6 * DefaultGradientForTemporarySpeedRestrictionMemoryTop++;
func1(&DefaultGradientForTemporarySpeedRestrictionMemory[v1]);
}
}
else
{
v0 = &DefaultGradientForTemporarySpeedRestrictionMemory[6
* DefaultGradientForTemporarySpeedRestrictionMemoryFreeList];
DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = *v0;
func1(v0);
}
}

original_code:
DefaultGradientForTemporarySpeedRestriction* DefaultGradientForTemporarySpeedRestriction_New(void)
{
    DefaultGradientForTemporarySpeedRestriction* ptr;
    if (DefaultGradientForTemporarySpeedRestrictionMemoryFreeList != (-1))
    {
        ptr = &DefaultGradientForTemporarySpeedRestrictionMemory[DefaultGradientForTemporarySpeedRestrictionMemoryFreeList];
        DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = DefaultGradientForTemporarySpeedRestrictionMemory[DefaultGradientForTemporarySpeedRestrictionMemoryFreeList].header.NID_PACKET;
    }
    else if (DefaultGradientForTemporarySpeedRestrictionMemoryTop < 8)
    {
        ptr = &DefaultGradientForTemporarySpeedRestrictionMemory[DefaultGradientForTemporarySpeedRestrictionMemoryTop];
        DefaultGradientForTemporarySpeedRestrictionMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DefaultGradientForTemporarySpeedRestriction_Init(ptr);
    return ptr;
}

canonical_original_code:
struct DefaultGradientForTemporarySpeedRestriction *DefaultGradientForTemporarySpeedRestriction_New()
{
    struct DefaultGradientForTemporarySpeedRestriction *ptr;
    if (DefaultGradientForTemporarySpeedRestrictionMemoryFreeList != (-1))
    {
        ptr = &DefaultGradientForTemporarySpeedRestrictionMemory[DefaultGradientForTemporarySpeedRestrictionMemoryFreeList];
        DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = DefaultGradientForTemporarySpeedRestrictionMemory[DefaultGradientForTemporarySpeedRestrictionMemoryFreeList].header.NID_PACKET;
    }
    else if (DefaultGradientForTemporarySpeedRestrictionMemoryTop < 8)
    {
        ptr = &DefaultGradientForTemporarySpeedRestrictionMemory[DefaultGradientForTemporarySpeedRestrictionMemoryTop];
        DefaultGradientForTemporarySpeedRestrictionMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DefaultGradientForTemporarySpeedRestriction_Init(ptr);
    return ptr;
}

return_type: struct DefaultGradientForTemporarySpeedRestriction { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_GDIR; unsigned long G_TSR; } *


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

*(_QWORD *)a1 = DefaultGradientForTemporarySpeedRestrictionMemoryFreeList;
result = 0xAAAAAAAAAAAAAAABLL;
DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = 0xAAAAAAAAAAAAAAABLL
* ((a1
- (char *)DefaultGradientForTemporarySpeedRestrictionMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = DefaultGradientForTemporarySpeedRestrictionMemoryFreeList;
result = 0xAAAAAAAAAAAAAAABLL;
DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = 0xAAAAAAAAAAAAAAABLL
* ((a1
- (char *)DefaultGradientForTemporarySpeedRestrictionMemory) >> 4);
return result;
}

original_code:
void DefaultGradientForTemporarySpeedRestriction_Delete(DefaultGradientForTemporarySpeedRestriction* ptr)
{
    ptr->header.NID_PACKET = DefaultGradientForTemporarySpeedRestrictionMemoryFreeList;
    DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = ptr - DefaultGradientForTemporarySpeedRestrictionMemory;
}

canonical_original_code:
void DefaultGradientForTemporarySpeedRestriction_Delete(struct DefaultGradientForTemporarySpeedRestriction *ptr)
{
    ptr->header.NID_PACKET = DefaultGradientForTemporarySpeedRestrictionMemoryFreeList;
    DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = ptr - DefaultGradientForTemporarySpeedRestrictionMemory;
}


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 InternationalStaticSpeedProfile_2_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v2; // eax
unsigned __int64 v3; // rdx
_BOOL4 v4; // eax
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rdi
int v7; // eax

v2 = UpperBitsNotSet64(*a1, 15);
v3 = a1[3];
if ( !v2 || !UpperBitsNotSet64(a1[1], 7) || !UpperBitsNotSet64(a1[2], 1) )
{
if ( !v3 )
return 0LL;
LODWORD(v5) = 0;
do
{
LABEL_12:
if ( (unsigned int)(v5 + 1) >= v3 )
break;
v5 = (unsigned int)(v5 + 2);
}
while ( v5 < v3 );
return 0LL;
}
v4 = UpperBitsNotSet64(v3, 5);
if ( v3 )
{
LODWORD(v5) = 0;
if ( v4 )
{
v6 = 0LL;
while ( 1 )
{
v7 = InternationalStaticSpeedProfile_2_1_UpperBitsNotSet(&a1[2 * v6 + 4]);
v6 = (unsigned int)(v5 + 1);
LODWORD(v5) = v5 + 1;
if ( !v7 )
break;
if ( a1[3] <= v6 )
return 1LL;
}
v3 = a1[3];
if ( v3 > v6 )
goto LABEL_12;
return 0LL;
}
goto LABEL_12;
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int64 *a1)
{
_BOOL4 v2; // eax
unsigned __int64 v3; // rdx
_BOOL4 v4; // eax
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rdi
int v7; // eax

v2 = func0(*a1, 15);
v3 = a1[3];
if ( !v2 || !func0(a1[1], 7) || !func0(a1[2], 1) )
{
if ( !v3 )
return 0LL;
LODWORD(v5) = 0;
do
{
LABEL_12:
if ( (unsigned int)(v5 + 1) >= v3 )
break;
v5 = (unsigned int)(v5 + 2);
}
while ( v5 < v3 );
return 0LL;
}
v4 = func0(v3, 5);
if ( v3 )
{
LODWORD(v5) = 0;
if ( v4 )
{
v6 = 0LL;
while ( 1 )
{
v7 = InternationalStaticSpeedProfile_2_1_UpperBitsNotSet(&a1[2 * v6 + 4]);
v6 = (unsigned int)(v5 + 1);
LODWORD(v5) = v5 + 1;
if ( !v7 )
break;
if ( a1[3] <= v6 )
return 1LL;
}
v3 = a1[3];
if ( v3 > v6 )
goto LABEL_12;
return 0LL;
}
goto LABEL_12;
}
return v4;
}

original_code:
int InternationalStaticSpeedProfile_2_UpperBitsNotSet(const InternationalStaticSpeedProfile_2* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_STATIC, 15);
    status = status && UpperBitsNotSet64(p->V_STATIC, 7) ;
    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 && InternationalStaticSpeedProfile_2_1_UpperBitsNotSet(&(p->sub_2_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int InternationalStaticSpeedProfile_2_UpperBitsNotSet(struct InternationalStaticSpeedProfile_2 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_STATIC, 15);
    status = status && UpperBitsNotSet64(p->V_STATIC, 7) ;
    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 && InternationalStaticSpeedProfile_2_1_UpperBitsNotSet(&(p->sub_2_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct InternationalStaticSpeedProfile_2 { unsigned long D_STATIC; unsigned long V_STATIC; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct InternationalStaticSpeedProfile_2_1 { unsigned long NC_DIFF; unsigned long V_DIFF; } sub_2_1[31]; } *

variable_types:
i
unsigned int

user_defined_types: struct InternationalStaticSpeedProfile_2 { unsigned long D_STATIC; unsigned long V_STATIC; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct InternationalStaticSpeedProfile_2_1 sub_2_1[31]; }


decompiled_code:
__int64 __fastcall InternationalStaticSpeedProfile_2_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rdi

if ( !(unsigned int)Bitstream_Normal(a2, 28LL) )
return 0xFFFFFFFFLL;
if ( !InternationalStaticSpeedProfile_2_UpperBitsNotSet(a1) )
return 4294967294LL;
v3 = 0;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 7LL, a1[1]);
Bitstream_Write(a2, 1LL, a1[2]);
Bitstream_Write(a2, 5LL, a1[3]);
v4 = 0LL;
if ( a1[3] )
{
do
{
InternationalStaticSpeedProfile_2_1_EncodeBit(&a1[2 * v4 + 4], a2);
v4 = ++v3;
}
while ( v3 < a1[3] );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 *a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rdi

if ( !(unsigned int)Bitstream_Normal(a2, 28LL) )
return 0xFFFFFFFFLL;
if ( !func1(a1) )
return 4294967294LL;
v3 = 0;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 7LL, a1[1]);
Bitstream_Write(a2, 1LL, a1[2]);
Bitstream_Write(a2, 5LL, a1[3]);
v4 = 0LL;
if ( a1[3] )
{
do
{
InternationalStaticSpeedProfile_2_1_EncodeBit(&a1[2 * v4 + 4], a2);
v4 = ++v3;
}
while ( v3 < a1[3] );
}
return 1LL;
}

original_code:
int InternationalStaticSpeedProfile_2_EncodeBit(const InternationalStaticSpeedProfile_2* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 28))
    {
        if (InternationalStaticSpeedProfile_2_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_STATIC);
            Bitstream_Write(stream, 7, p->V_STATIC);
            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)
            {
                InternationalStaticSpeedProfile_2_1_EncodeBit(&(p->sub_2_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int InternationalStaticSpeedProfile_2_EncodeBit(struct InternationalStaticSpeedProfile_2 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 28))
    {
        if (InternationalStaticSpeedProfile_2_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_STATIC);
            Bitstream_Write(stream, 7, p->V_STATIC);
            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)
            {
                InternationalStaticSpeedProfile_2_1_EncodeBit(&(p->sub_2_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct InternationalStaticSpeedProfile_2_1 { unsigned long NC_DIFF; unsigned long V_DIFF; }


decompiled_code:
__int64 __fastcall InternationalStaticSpeedProfile_2_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
unsigned int v4; // er12
__int64 v5; // rax
__int64 v6; // rdi

result = Bitstream_Normal(a2, 28LL);
if ( (_DWORD)result )
{
v4 = 0;
*a1 = Bitstream_Read(a2, 15LL);
a1[1] = Bitstream_Read(a2, 7LL);
a1[2] = Bitstream_Read(a2, 1LL);
v5 = Bitstream_Read(a2, 5LL);
v6 = 0LL;
a1[3] = v5;
if ( v5 )
{
do
{
InternationalStaticSpeedProfile_2_1_DecodeBit(&a1[2 * v6 + 4], a2);
v6 = ++v4;
}
while ( (unsigned __int64)v4 < a1[3] );
}
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 28LL);
if ( (_DWORD)result )
{
v4 = 0;
*a1 = Bitstream_Read(a2, 15LL);
a1[1] = Bitstream_Read(a2, 7LL);
a1[2] = Bitstream_Read(a2, 1LL);
v5 = Bitstream_Read(a2, 5LL);
v6 = 0LL;
a1[3] = v5;
if ( v5 )
{
do
{
InternationalStaticSpeedProfile_2_1_DecodeBit(&a1[2 * v6 + 4], a2);
v6 = ++v4;
}
while ( (unsigned __int64)v4 < a1[3] );
}
result = 1LL;
}
return result;
}

original_code:
int InternationalStaticSpeedProfile_2_DecodeBit(InternationalStaticSpeedProfile_2* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 28))
    {
        {
            p->D_STATIC = Bitstream_Read(stream, 15);
        }
        {
            p->V_STATIC = Bitstream_Read(stream, 7);
        }
        {
            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)
        {
            InternationalStaticSpeedProfile_2_1_DecodeBit(&(p->sub_2_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int InternationalStaticSpeedProfile_2_DecodeBit(struct InternationalStaticSpeedProfile_2 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 28))
    {
        {
            p->D_STATIC = Bitstream_Read(stream, 15);
        }
        {
            p->V_STATIC = Bitstream_Read(stream, 7);
        }
        {
            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)
        {
            InternationalStaticSpeedProfile_2_1_DecodeBit(&(p->sub_2_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int InternationalStaticSpeedProfile_2_EncodeInt(const InternationalStaticSpeedProfile_2* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->D_STATIC;
    stream[(*startAddress)++] = p->V_STATIC;
    stream[(*startAddress)++] = p->Q_FRONT;
    stream[(*startAddress)++] = p->N_ITER_2_1;
    for (uint32_t i = 0; i < p->N_ITER_2_1; ++i)
    {
        InternationalStaticSpeedProfile_2_1_EncodeInt(&(p->sub_2_1[i]), startAddress, stream);
    }
    return 1;
}

canonical_original_code:
int InternationalStaticSpeedProfile_2_EncodeInt(struct InternationalStaticSpeedProfile_2 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->D_STATIC;
    stream[(*startAddress)++] = p->V_STATIC;
    stream[(*startAddress)++] = p->Q_FRONT;
    stream[(*startAddress)++] = p->N_ITER_2_1;
    for (unsigned int i = 0; i < p->N_ITER_2_1; ++i)
    {
        InternationalStaticSpeedProfile_2_1_EncodeInt(&(p->sub_2_1[i]), startAddress, stream);
    }
    return 1;
}


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

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

original_code:
int InternationalStaticSpeedProfile_2_DecodeInt(InternationalStaticSpeedProfile_2* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->D_STATIC = stream[(*startAddress)++];
    p->V_STATIC = 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)
    {
        InternationalStaticSpeedProfile_2_1_DecodeInt(&(p->sub_2_1[i]), startAddress, stream);
    }
    return 1;
}

canonical_original_code:
int InternationalStaticSpeedProfile_2_DecodeInt(struct InternationalStaticSpeedProfile_2 *p, int *startAddress, int *stream)
{
    p->D_STATIC = stream[(*startAddress)++];
    p->V_STATIC = 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)
    {
        InternationalStaticSpeedProfile_2_1_DecodeInt(&(p->sub_2_1[i]), startAddress, stream);
    }
    return 1;
}


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

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

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

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

original_code:
int LevelTransitionOrder_UpperBitsNotSet(const LevelTransitionOrder* 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_LEVELTR, 15);
    status = status && UpperBitsNotSet64(p->M_LEVELTR, 3) ;
    if (p->M_LEVELTR == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    status = status && UpperBitsNotSet64(p->L_ACKLEVELTR, 15);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && LevelTransitionOrder_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int LevelTransitionOrder_UpperBitsNotSet(struct LevelTransitionOrder *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_LEVELTR, 15);
    status = status && UpperBitsNotSet64(p->M_LEVELTR, 3) ;
    if (p->M_LEVELTR == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    status = status && UpperBitsNotSet64(p->L_ACKLEVELTR, 15);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && LevelTransitionOrder_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct LevelTransitionOrder { 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_LEVELTR; unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; unsigned long N_ITER_1; struct LevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; } sub_1[31]; } *

user_defined_types: struct LevelTransitionOrder { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_LEVELTR; unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; unsigned long N_ITER_1; struct LevelTransitionOrder_1 sub_1[31]; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 55LL) )
return 0xFFFFFFFFLL;
if ( !LevelTransitionOrder_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, 3LL, a1[6]);
if ( a1[6] == 1 )
Bitstream_Write(a2, 8LL, a1[7]);
v2 = 0;
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 5LL, a1[9]);
v3 = 0LL;
if ( a1[9] )
{
do
{
LevelTransitionOrder_1_EncodeBit(&a1[3 * v3 + 10], a2);
v3 = ++v2;
}
while ( v2 < a1[9] );
}
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 55LL) )
return 0xFFFFFFFFLL;
if ( !func3(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, 3LL, a1[6]);
if ( a1[6] == 1 )
Bitstream_Write(a2, 8LL, a1[7]);
v2 = 0;
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 5LL, a1[9]);
v3 = 0LL;
if ( a1[9] )
{
do
{
LevelTransitionOrder_1_EncodeBit(&a1[3 * v3 + 10], a2);
v3 = ++v2;
}
while ( v2 < a1[9] );
}
return 1LL;
}

original_code:
int LevelTransitionOrder_EncodeBit(const LevelTransitionOrder* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 55))
    {
        if (LevelTransitionOrder_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_LEVELTR);
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            Bitstream_Write(stream, 15, p->L_ACKLEVELTR);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                LevelTransitionOrder_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int LevelTransitionOrder_EncodeBit(struct LevelTransitionOrder *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 55))
    {
        if (LevelTransitionOrder_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_LEVELTR);
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            Bitstream_Write(stream, 15, p->L_ACKLEVELTR);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                LevelTransitionOrder_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct LevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; }


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

result = Bitstream_Normal(a2, 55LL);
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);
v3 = Bitstream_Read(a2, 3LL);
a1[6] = v3;
if ( v3 == 1 )
a1[7] = Bitstream_Read(a2, 8LL);
v4 = 0;
a1[8] = Bitstream_Read(a2, 15LL);
v5 = Bitstream_Read(a2, 5LL);
a1[9] = v5;
v6 = 0LL;
if ( v5 )
{
do
{
LevelTransitionOrder_1_DecodeBit(&a1[3 * v6 + 10], a2);
v6 = ++v4;
}
while ( (unsigned __int64)v4 < a1[9] );
}
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 55LL);
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);
v3 = Bitstream_Read(a2, 3LL);
a1[6] = v3;
if ( v3 == 1 )
a1[7] = Bitstream_Read(a2, 8LL);
v4 = 0;
a1[8] = Bitstream_Read(a2, 15LL);
v5 = Bitstream_Read(a2, 5LL);
a1[9] = v5;
v6 = 0LL;
if ( v5 )
{
do
{
LevelTransitionOrder_1_DecodeBit(&a1[3 * v6 + 10], a2);
v6 = ++v4;
}
while ( (unsigned __int64)v4 < a1[9] );
}
result = 1LL;
}
return result;
}

original_code:
int LevelTransitionOrder_DecodeBit(LevelTransitionOrder* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 55))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_LEVELTR = Bitstream_Read(stream, 15);
        }
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        {
            p->L_ACKLEVELTR = Bitstream_Read(stream, 15);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            LevelTransitionOrder_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int LevelTransitionOrder_DecodeBit(struct LevelTransitionOrder *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 55))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_LEVELTR = Bitstream_Read(stream, 15);
        }
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        {
            p->L_ACKLEVELTR = Bitstream_Read(stream, 15);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            LevelTransitionOrder_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int LevelTransitionOrder_EncodeInt(const LevelTransitionOrder* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 41;
    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_LEVELTR;
    stream[startAddress++] = p->M_LEVELTR;
    stream[startAddress++] = p->NID_STM;
    stream[startAddress++] = p->L_ACKLEVELTR;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        LevelTransitionOrder_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int LevelTransitionOrder_EncodeInt(struct LevelTransitionOrder *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 41;
    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_LEVELTR;
    stream[startAddress++] = p->M_LEVELTR;
    stream[startAddress++] = p->NID_STM;
    stream[startAddress++] = p->L_ACKLEVELTR;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        LevelTransitionOrder_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int LevelTransitionOrder_DecodeInt(LevelTransitionOrder* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 41)
    {
         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_LEVELTR = stream[startAddress++];
    p->M_LEVELTR = stream[startAddress++];
    p->NID_STM = stream[startAddress++];
    p->L_ACKLEVELTR = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        LevelTransitionOrder_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int LevelTransitionOrder_DecodeInt(struct LevelTransitionOrder *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 41)
    {
         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_LEVELTR = stream[startAddress++];
    p->M_LEVELTR = stream[startAddress++];
    p->NID_STM = stream[startAddress++];
    p->L_ACKLEVELTR = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        LevelTransitionOrder_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( LevelTransitionOrderMemoryFreeList == -1 )
{
if ( (unsigned __int64)LevelTransitionOrderMemoryTop > 7 )
return 0LL;
v3 = 103 * LevelTransitionOrderMemoryTop++;
v0 = &LevelTransitionOrderMemory[v3];
}
else
{
v0 = &LevelTransitionOrderMemory[103 * LevelTransitionOrderMemoryFreeList];
LevelTransitionOrderMemoryFreeList = *v0;
}
LevelTransitionOrder_Init(v0);
return v1;
}

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

if ( LevelTransitionOrderMemoryFreeList == -1 )
{
if ( (unsigned __int64)LevelTransitionOrderMemoryTop > 7 )
return 0LL;
v3 = 103 * LevelTransitionOrderMemoryTop++;
v0 = &LevelTransitionOrderMemory[v3];
}
else
{
v0 = &LevelTransitionOrderMemory[103 * LevelTransitionOrderMemoryFreeList];
LevelTransitionOrderMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
LevelTransitionOrder* LevelTransitionOrder_New(void)
{
    LevelTransitionOrder* ptr;
    if (LevelTransitionOrderMemoryFreeList != (-1))
    {
        ptr = &LevelTransitionOrderMemory[LevelTransitionOrderMemoryFreeList];
        LevelTransitionOrderMemoryFreeList = LevelTransitionOrderMemory[LevelTransitionOrderMemoryFreeList].header.NID_PACKET;
    }
    else if (LevelTransitionOrderMemoryTop < 8)
    {
        ptr = &LevelTransitionOrderMemory[LevelTransitionOrderMemoryTop];
        LevelTransitionOrderMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    LevelTransitionOrder_Init(ptr);
    return ptr;
}

canonical_original_code:
struct LevelTransitionOrder *LevelTransitionOrder_New()
{
    struct LevelTransitionOrder *ptr;
    if (LevelTransitionOrderMemoryFreeList != (-1))
    {
        ptr = &LevelTransitionOrderMemory[LevelTransitionOrderMemoryFreeList];
        LevelTransitionOrderMemoryFreeList = LevelTransitionOrderMemory[LevelTransitionOrderMemoryFreeList].header.NID_PACKET;
    }
    else if (LevelTransitionOrderMemoryTop < 8)
    {
        ptr = &LevelTransitionOrderMemory[LevelTransitionOrderMemoryTop];
        LevelTransitionOrderMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    LevelTransitionOrder_Init(ptr);
    return ptr;
}

return_type: struct LevelTransitionOrder { 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_LEVELTR; unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; unsigned long N_ITER_1; struct LevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; } sub_1[31]; } *


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

*a1 = LevelTransitionOrderMemoryFreeList;
result = 0xDAB7EC1DD3431B57LL;
LevelTransitionOrderMemoryFreeList = 0xDAB7EC1DD3431B57LL * (a1 - LevelTransitionOrderMemory);
return result;
}

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

*a1 = LevelTransitionOrderMemoryFreeList;
result = 0xDAB7EC1DD3431B57LL;
LevelTransitionOrderMemoryFreeList = 0xDAB7EC1DD3431B57LL * (a1 - LevelTransitionOrderMemory);
return result;
}

original_code:
void LevelTransitionOrder_Delete(LevelTransitionOrder* ptr)
{
    ptr->header.NID_PACKET = LevelTransitionOrderMemoryFreeList;
    LevelTransitionOrderMemoryFreeList = ptr - LevelTransitionOrderMemory;
}

canonical_original_code:
void LevelTransitionOrder_Delete(struct LevelTransitionOrder *ptr)
{
    ptr->header.NID_PACKET = LevelTransitionOrderMemoryFreeList;
    LevelTransitionOrderMemoryFreeList = ptr - LevelTransitionOrderMemory;
}


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

v1 = UpperBitsNotSet64(a1[2], 2);
v2 = a1[4];
if ( !v1 || !UpperBitsNotSet64(a1[3], 13) )
{
if ( !v2 )
return 0LL;
LODWORD(v4) = 0;
do
{
LABEL_8:
if ( (unsigned int)(v4 + 1) >= v2 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v2 );
return 0LL;
}
v3 = UpperBitsNotSet64(v2, 5);
if ( v2 )
{
LODWORD(v4) = 0;
if ( v3 )
{
v5 = 0LL;
while ( 1 )
{
v6 = ListOfBalisesForSHArea_1_UpperBitsNotSet(&a1[3 * v5 + 5]);
v5 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v6 )
break;
if ( a1[4] <= v5 )
return 1LL;
}
v2 = a1[4];
if ( v2 <= v5 )
return 0LL;
}
goto LABEL_8;
}
return v3;
}

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

v1 = func0(a1[2], 2);
v2 = a1[4];
if ( !v1 || !func0(a1[3], 13) )
{
if ( !v2 )
return 0LL;
LODWORD(v4) = 0;
do
{
LABEL_8:
if ( (unsigned int)(v4 + 1) >= v2 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v2 );
return 0LL;
}
v3 = func0(v2, 5);
if ( v2 )
{
LODWORD(v4) = 0;
if ( v3 )
{
v5 = 0LL;
while ( 1 )
{
v6 = ListOfBalisesForSHArea_1_UpperBitsNotSet(&a1[3 * v5 + 5]);
v5 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v6 )
break;
if ( a1[4] <= v5 )
return 1LL;
}
v2 = a1[4];
if ( v2 <= v5 )
return 0LL;
}
goto LABEL_8;
}
return v3;
}

original_code:
int ListOfBalisesForSHArea_UpperBitsNotSet(const ListOfBalisesForSHArea* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ListOfBalisesForSHArea_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ListOfBalisesForSHArea_UpperBitsNotSet(struct ListOfBalisesForSHArea *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ListOfBalisesForSHArea_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ListOfBalisesForSHArea { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long N_ITER_1; struct ListOfBalisesForSHArea_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; } sub_1[31]; } *

user_defined_types: struct ListOfBalisesForSHArea { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long N_ITER_1; struct ListOfBalisesForSHArea_1 sub_1[31]; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 20LL) )
return 0xFFFFFFFFLL;
if ( !ListOfBalisesForSHArea_UpperBitsNotSet(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 5LL, a1[4]);
v3 = 0LL;
if ( a1[4] )
{
do
{
ListOfBalisesForSHArea_1_EncodeBit(&a1[3 * v3 + 5], a2);
v3 = ++v2;
}
while ( v2 < a1[4] );
}
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 20LL) )
return 0xFFFFFFFFLL;
if ( !func3(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 5LL, a1[4]);
v3 = 0LL;
if ( a1[4] )
{
do
{
ListOfBalisesForSHArea_1_EncodeBit(&a1[3 * v3 + 5], a2);
v3 = ++v2;
}
while ( v2 < a1[4] );
}
return 1LL;
}

original_code:
int ListOfBalisesForSHArea_EncodeBit(const ListOfBalisesForSHArea* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 20))
    {
        if (ListOfBalisesForSHArea_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                ListOfBalisesForSHArea_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ListOfBalisesForSHArea_EncodeBit(struct ListOfBalisesForSHArea *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 20))
    {
        if (ListOfBalisesForSHArea_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                ListOfBalisesForSHArea_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            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 ListOfBalisesForSHArea_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; }


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

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

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

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

original_code:
int ListOfBalisesForSHArea_DecodeBit(ListOfBalisesForSHArea* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 20))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            ListOfBalisesForSHArea_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ListOfBalisesForSHArea_DecodeBit(struct ListOfBalisesForSHArea *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 20))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            ListOfBalisesForSHArea_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int ListOfBalisesForSHArea_EncodeInt(const ListOfBalisesForSHArea* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 49;
    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->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ListOfBalisesForSHArea_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int ListOfBalisesForSHArea_EncodeInt(struct ListOfBalisesForSHArea *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 49;
    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->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ListOfBalisesForSHArea_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    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; } *


original_code:
int ListOfBalisesForSHArea_DecodeInt(ListOfBalisesForSHArea* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 49)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ListOfBalisesForSHArea_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int ListOfBalisesForSHArea_DecodeInt(struct ListOfBalisesForSHArea *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 49)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ListOfBalisesForSHArea_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

variable_types:
stream
int *


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

if ( ListOfBalisesForSHAreaMemoryFreeList == -1 )
{
if ( (unsigned __int64)ListOfBalisesForSHAreaMemoryTop > 7 )
return 0LL;
v3 = 98 * ListOfBalisesForSHAreaMemoryTop++;
v0 = &ListOfBalisesForSHAreaMemory[v3];
}
else
{
v0 = &ListOfBalisesForSHAreaMemory[98 * ListOfBalisesForSHAreaMemoryFreeList];
ListOfBalisesForSHAreaMemoryFreeList = *v0;
}
ListOfBalisesForSHArea_Init(v0);
return v1;
}

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

if ( ListOfBalisesForSHAreaMemoryFreeList == -1 )
{
if ( (unsigned __int64)ListOfBalisesForSHAreaMemoryTop > 7 )
return 0LL;
v3 = 98 * ListOfBalisesForSHAreaMemoryTop++;
v0 = &ListOfBalisesForSHAreaMemory[v3];
}
else
{
v0 = &ListOfBalisesForSHAreaMemory[98 * ListOfBalisesForSHAreaMemoryFreeList];
ListOfBalisesForSHAreaMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
ListOfBalisesForSHArea* ListOfBalisesForSHArea_New(void)
{
    ListOfBalisesForSHArea* ptr;
    if (ListOfBalisesForSHAreaMemoryFreeList != (-1))
    {
        ptr = &ListOfBalisesForSHAreaMemory[ListOfBalisesForSHAreaMemoryFreeList];
        ListOfBalisesForSHAreaMemoryFreeList = ListOfBalisesForSHAreaMemory[ListOfBalisesForSHAreaMemoryFreeList].header.NID_PACKET;
    }
    else if (ListOfBalisesForSHAreaMemoryTop < 8)
    {
        ptr = &ListOfBalisesForSHAreaMemory[ListOfBalisesForSHAreaMemoryTop];
        ListOfBalisesForSHAreaMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ListOfBalisesForSHArea_Init(ptr);
    return ptr;
}

canonical_original_code:
struct ListOfBalisesForSHArea *ListOfBalisesForSHArea_New()
{
    struct ListOfBalisesForSHArea *ptr;
    if (ListOfBalisesForSHAreaMemoryFreeList != (-1))
    {
        ptr = &ListOfBalisesForSHAreaMemory[ListOfBalisesForSHAreaMemoryFreeList];
        ListOfBalisesForSHAreaMemoryFreeList = ListOfBalisesForSHAreaMemory[ListOfBalisesForSHAreaMemoryFreeList].header.NID_PACKET;
    }
    else if (ListOfBalisesForSHAreaMemoryTop < 8)
    {
        ptr = &ListOfBalisesForSHAreaMemory[ListOfBalisesForSHAreaMemoryTop];
        ListOfBalisesForSHAreaMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ListOfBalisesForSHArea_Init(ptr);
    return ptr;
}

return_type: struct ListOfBalisesForSHArea { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long N_ITER_1; struct ListOfBalisesForSHArea_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; } sub_1[31]; } *


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

*(_QWORD *)a1 = ListOfBalisesForSHAreaMemoryFreeList;
result = 0x7D6343EB1A1F58D1LL;
ListOfBalisesForSHAreaMemoryFreeList = 0x7D6343EB1A1F58D1LL * ((a1 - (char *)ListOfBalisesForSHAreaMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = ListOfBalisesForSHAreaMemoryFreeList;
result = 0x7D6343EB1A1F58D1LL;
ListOfBalisesForSHAreaMemoryFreeList = 0x7D6343EB1A1F58D1LL * ((a1 - (char *)ListOfBalisesForSHAreaMemory) >> 4);
return result;
}

original_code:
void ListOfBalisesForSHArea_Delete(ListOfBalisesForSHArea* ptr)
{
    ptr->header.NID_PACKET = ListOfBalisesForSHAreaMemoryFreeList;
    ListOfBalisesForSHAreaMemoryFreeList = ptr - ListOfBalisesForSHAreaMemory;
}

canonical_original_code:
void ListOfBalisesForSHArea_Delete(struct ListOfBalisesForSHArea *ptr)
{
    ptr->header.NID_PACKET = ListOfBalisesForSHAreaMemoryFreeList;
    ListOfBalisesForSHAreaMemoryFreeList = ptr - ListOfBalisesForSHAreaMemory;
}


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

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

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

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