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

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

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

result = func0(a1[2], 2);
if ( result )
{
result = func0(a1[3], 13);
if ( result )
result = func0(a1[4], 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; }


repo: openETCS/dataDictionary

decompiled_code:
__int64 __fastcall TemporarySpeedRestrictionRevocation_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 23LL) )
return 0xFFFFFFFFLL;
if ( !TemporarySpeedRestrictionRevocation_UpperBitsNotSet(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(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 23LL) )
return 0xFFFFFFFFLL;
if ( !func2(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;
    }
}

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

return_type: int

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


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;
    }
}

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


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;
}

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


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

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

original_code:
int 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;
}

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 *TemporarySpeedRestrictionRevocation_New()
{
__int64 *v0; // rbx

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

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

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

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;
}

return_type: void


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

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

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

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

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

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

variable_types:
value
unsigned long

variable_types:
length
unsigned int

variable_types:
MaxValue
unsigned long


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

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

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

result = func0(a1[2], 2);
if ( result )
{
result = func0(a1[3], 13);
if ( result )
{
result = func0(a1[4], 1);
if ( result )
result = func0(a1[5], 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; } *

variable_types: status int

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(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 24LL) )
return 0xFFFFFFFFLL;
if ( !DefaultGradientForTemporarySpeedRestriction_UpperBitsNotSet(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(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 24LL) )
return 0xFFFFFFFFLL;
if ( !func2(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
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;
}


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

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

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:
__int64 *DefaultGradientForTemporarySpeedRestriction_New()
{
__int64 *v0; // rbx

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

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

if ( DefaultGradientForTemporarySpeedRestrictionMemoryFreeList == -1 )
{
if ( (unsigned __int64)DefaultGradientForTemporarySpeedRestrictionMemoryTop > 7 )
return 0LL;
v0 = &DefaultGradientForTemporarySpeedRestrictionMemory[6 * DefaultGradientForTemporarySpeedRestrictionMemoryTop++];
}
else
{
v0 = &DefaultGradientForTemporarySpeedRestrictionMemory[6
* DefaultGradientForTemporarySpeedRestrictionMemoryFreeList];
DefaultGradientForTemporarySpeedRestrictionMemoryFreeList = *v0;
}
func1(v0);
return 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;
}


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

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

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

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

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 v2; // ebx

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

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

if ( !(unsigned int)Bitstream_Normal(a2, 28LL) )
return 0xFFFFFFFFLL;
if ( !func1(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 7LL, a1[1]);
Bitstream_Write(a2, 1LL, a1[2]);
Bitstream_Write(a2, 5LL, a1[3]);
if ( !a1[3] )
return 1LL;
v2 = 0;
do
InternationalStaticSpeedProfile_2_1_EncodeBit(&a1[2 * v2++ + 4], a2);
while ( v2 < 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
__int64 v3; // rax
unsigned int v4; // ebx

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

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

result = Bitstream_Normal(a2, 28LL);
if ( (_DWORD)result )
{
*a1 = Bitstream_Read(a2, 15LL);
a1[1] = Bitstream_Read(a2, 7LL);
a1[2] = Bitstream_Read(a2, 1LL);
v3 = Bitstream_Read(a2, 5LL);
a1[3] = v3;
if ( v3 )
{
v4 = 0;
do
InternationalStaticSpeedProfile_2_1_DecodeBit(&a1[2 * v4++ + 4], a2);
while ( (unsigned __int64)v4 < a1[3] );
result = 1LL;
}
else
{
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;
    }
}


decompiled_code:
__int64 __fastcall InternationalStaticSpeedProfile_2_EncodeInt(__int64 *a1, _DWORD *a2, __int64 a3)
{
__int64 v4; // rdx
int v5; // eax
__int64 v6; // rdx
int v7; // eax
__int64 v8; // rdx
int v9; // eax
__int64 v10; // rdx
int v11; // eax
unsigned int v12; // ebx

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

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;
}

variable_types:
startAddress
int *


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

v4 = (*a2)++;
*a1 = *(int *)(a3 + 4LL * v4);
v5 = (*a2)++;
a1[1] = *(int *)(a3 + 4LL * v5);
v6 = (*a2)++;
a1[2] = *(int *)(a3 + 4LL * v6);
v7 = (*a2)++;
v8 = *(int *)(a3 + 4LL * v7);
a1[3] = v8;
if ( v8 )
{
v9 = 0;
do
InternationalStaticSpeedProfile_2_1_DecodeInt(&a1[2 * v9++ + 4], a2, a3);
while ( (unsigned __int64)v9 < 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)
{
_BOOL4 v1; // eax
unsigned int i; // ebx

v1 = UpperBitsNotSet64(a1[2], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[3], 13);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[4], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[5], 15);
if ( v1 )
v1 = UpperBitsNotSet64(a1[6], 3);
}
}
}
if ( a1[6] == 1 )
{
if ( !v1 )
goto LABEL_10;
v1 = UpperBitsNotSet64(a1[7], 8);
if ( !v1 )
goto LABEL_10;
}
else if ( !v1 )
{
goto LABEL_10;
}
v1 = UpperBitsNotSet64(a1[8], 15);
if ( v1 )
v1 = UpperBitsNotSet64(a1[9], 5);
LABEL_10:
for ( i = 0; i < a1[9]; ++i )
{
if ( v1 )
v1 = LevelTransitionOrder_1_UpperBitsNotSet(&a1[3 * i + 10]) != 0;
}
return v1;
}

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; // ebx

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

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

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]);
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 5LL, a1[9]);
if ( !a1[9] )
return 1LL;
v2 = 0;
do
LevelTransitionOrder_1_EncodeBit(&a1[3 * v2++ + 10], a2);
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
__int64 v4; // rax
unsigned int v5; // ebx

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

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

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

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

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

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

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 UpperBitsNotSet64(unsigned __int64 a1, int a2)
{
_BOOL8 result; // rax

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

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

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


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

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

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

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

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

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

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

if ( !(unsigned int)Bitstream_Normal(a2, 20LL) )
return 0xFFFFFFFFLL;
if ( !func3(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 5LL, a1[4]);
if ( !a1[4] )
return 1LL;
v2 = 0;
do
ListOfBalisesForSHArea_1_EncodeBit(&a1[3 * v2++ + 5], a2);
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;
    }
}

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
__int64 v3; // rax
unsigned int v4; // ebx

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

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

result = Bitstream_Normal(a2, 20LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
v3 = Bitstream_Read(a2, 5LL);
a1[4] = v3;
if ( v3 )
{
v4 = 0;
do
ListOfBalisesForSHArea_1_DecodeBit(&a1[3 * v4++ + 5], a2);
while ( (unsigned __int64)v4 < a1[4] );
result = 1LL;
}
else
{
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;
}


decompiled_code:
_BOOL8 __fastcall ListOfBalisesForSHArea_DecodeInt(_QWORD *a1, _DWORD *a2, __int64 a3)
{
_BOOL8 result; // rax
int v5; // edx
__int64 v6; // rax
unsigned int v7; // ebx
int v8[11]; // [rsp+0h] [rbp-2Ch] BYREF

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

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;
}


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

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

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

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

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:
__int64 __fastcall Route_Suitability_Data_Encode_Bit(__int64 a1, unsigned __int64 *a2)
{
__int64 result; // rax
unsigned int v3; // er12

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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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


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

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


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

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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

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