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

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

original_code:
int TrackConditionBigMetalMasses_1_EncodeBit(const TrackConditionBigMetalMasses_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        if (TrackConditionBigMetalMasses_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_TRACKCOND);
            Bitstream_Write(stream, 15, p->L_TRACKCOND);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int TrackConditionBigMetalMasses_1_EncodeBit(struct TrackConditionBigMetalMasses_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        if (TrackConditionBigMetalMasses_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_TRACKCOND);
            Bitstream_Write(stream, 15, p->L_TRACKCOND);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct TrackConditionBigMetalMasses_1 { unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; }


repo: openETCS/dataDictionary

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

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

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

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

original_code:
int TrackConditionBigMetalMasses_1_DecodeBit(TrackConditionBigMetalMasses_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        {
            p->D_TRACKCOND = Bitstream_Read(stream, 15);
        }
        {
            p->L_TRACKCOND = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TrackConditionBigMetalMasses_1_DecodeBit(struct TrackConditionBigMetalMasses_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        {
            p->D_TRACKCOND = Bitstream_Read(stream, 15);
        }
        {
            p->L_TRACKCOND = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct TrackConditionBigMetalMasses_1 { unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; } *

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

return_type: int


original_code:
int TrackConditionBigMetalMasses_1_EncodeInt(const TrackConditionBigMetalMasses_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->D_TRACKCOND;
    stream[(*startAddress)++] = p->L_TRACKCOND;
    return 1;
}

canonical_original_code:
int TrackConditionBigMetalMasses_1_EncodeInt(struct TrackConditionBigMetalMasses_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->D_TRACKCOND;
    stream[(*startAddress)++] = p->L_TRACKCOND;
    return 1;
}

variable_types:
startAddress
int *

variable_types:
stream
int *


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

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

original_code:
int TrackConditionBigMetalMasses_1_DecodeInt(TrackConditionBigMetalMasses_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->D_TRACKCOND = stream[(*startAddress)++];
    p->L_TRACKCOND = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int TrackConditionBigMetalMasses_1_DecodeInt(struct TrackConditionBigMetalMasses_1 *p, int *startAddress, int *stream)
{
    p->D_TRACKCOND = stream[(*startAddress)++];
    p->L_TRACKCOND = stream[(*startAddress)++];
    return 1;
}


decompiled_code:
_BOOL8 __fastcall UpperBitsNotSet64(unsigned __int64 a1)
{
return a1 <= 0x7F;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int64 a1)
{
return a1 <= 0x7F;
}

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

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

variable_types:
value
unsigned long

variable_types:
length
unsigned int

variable_types:
MaxValue
unsigned long


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

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

original_code:
int Axle_Load_Speed_Profile_Core_2_1_Encode_Bit(Bitstream* stream, const Axle_Load_Speed_Profile_Core_2_1* p)
{
    if (Bitstream_Normal(stream, 14))
    {
        if (Axle_Load_Speed_Profile_Core_2_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 Axle_Load_Speed_Profile_Core_2_1_Encode_Bit(struct Bitstream *stream, struct Axle_Load_Speed_Profile_Core_2_1 *p)
{
    if (Bitstream_Normal(stream, 14))
    {
        if (Axle_Load_Speed_Profile_Core_2_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;
    }
}

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

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


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

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

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

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

original_code:
int Axle_Load_Speed_Profile_Core_2_1_Decode_Bit(Bitstream* stream, Axle_Load_Speed_Profile_Core_2_1* p)
{
    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 Axle_Load_Speed_Profile_Core_2_1_Decode_Bit(struct Bitstream *stream, struct Axle_Load_Speed_Profile_Core_2_1 *p)
{
    if (Bitstream_Normal(stream, 14))
    {
        {
            p->M_AXLELOAD = Bitstream_Read(stream, 7);
        }
        {
            p->V_AXLELOAD = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

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


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

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

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


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

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

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


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

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

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

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


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

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 13);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 32), 1);
if ( result )
{
if ( *(_QWORD *)(v4 + 48) == 0x3FFFLL )
{
result = UpperBitsNotSet64(0x3FFFuLL, 14);
if ( result )
return UpperBitsNotSet64(*(_QWORD *)(v6 + 64), 1);
}
else
{
result = UpperBitsNotSet64(*(_QWORD *)(v4 + 40), 10);
if ( result )
{
result = UpperBitsNotSet64(v5, 14);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v7 + 56), 64);
if ( result )
return UpperBitsNotSet64(*(_QWORD *)(v6 + 64), 1);
}
}
}
}
}
}
return result;
}

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

result = func0(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = func0(*(_QWORD *)(v2 + 24), 13);
if ( result )
{
result = func0(*(_QWORD *)(v3 + 32), 1);
if ( result )
{
if ( *(_QWORD *)(v4 + 48) == 0x3FFFLL )
{
result = func0(0x3FFFuLL, 14);
if ( result )
return func0(*(_QWORD *)(v6 + 64), 1);
}
else
{
result = func0(*(_QWORD *)(v4 + 40), 10);
if ( result )
{
result = func0(v5, 14);
if ( result )
{
result = func0(*(_QWORD *)(v7 + 56), 64);
if ( result )
return func0(*(_QWORD *)(v6 + 64), 1);
}
}
}
}
}
}
return result;
}

original_code:
int SessionManagement_UpperBitsNotSet(const SessionManagement* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_RBC, 1) ;
    if (p->NID_RBC != 16383)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_RBC, 14);
    if (p->NID_RBC != 16383)
    {
        status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    }
    status = status && UpperBitsNotSet64(p->Q_SLEEPSESSION, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int SessionManagement_UpperBitsNotSet(struct SessionManagement *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_RBC, 1) ;
    if (p->NID_RBC != 16383)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_RBC, 14);
    if (p->NID_RBC != 16383)
    {
        status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    }
    status = status && UpperBitsNotSet64(p->Q_SLEEPSESSION, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct SessionManagement { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_RBC; unsigned long NID_C; unsigned long NID_RBC; unsigned long NID_RADIO; unsigned long Q_SLEEPSESSION; } *

variable_types: status int

user_defined_types: struct SessionManagement { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_RBC; unsigned long NID_C; unsigned long NID_RBC; unsigned long NID_RADIO; unsigned long Q_SLEEPSESSION; }


decompiled_code:
__int64 __fastcall SessionManagement_EncodeBit(_QWORD *a1, __int64 a2)
{
__int64 v2; // rdx

if ( !(unsigned int)Bitstream_Normal(a2, 31LL) )
return 0xFFFFFFFFLL;
if ( !SessionManagement_UpperBitsNotSet((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
v2 = a1[6];
if ( v2 != 0x3FFF )
{
Bitstream_Write(a2, 10LL, a1[5]);
v2 = a1[6];
}
Bitstream_Write(a2, 14LL, v2);
if ( a1[6] != 0x3FFFLL )
Bitstream_Write(a2, 64LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2)
{
__int64 v2; // rdx

if ( !(unsigned int)Bitstream_Normal(a2, 31LL) )
return 0xFFFFFFFFLL;
if ( !func2((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
v2 = a1[6];
if ( v2 != 0x3FFF )
{
Bitstream_Write(a2, 10LL, a1[5]);
v2 = a1[6];
}
Bitstream_Write(a2, 14LL, v2);
if ( a1[6] != 0x3FFFLL )
Bitstream_Write(a2, 64LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
return 1LL;
}

original_code:
int SessionManagement_EncodeBit(const SessionManagement* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 31))
    {
        if (SessionManagement_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_RBC);
            if (p->NID_RBC != 16383)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_RBC);
            if (p->NID_RBC != 16383)
            {
                Bitstream_Write(stream, 64, p->NID_RADIO);
            }
            Bitstream_Write(stream, 1, p->Q_SLEEPSESSION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int SessionManagement_EncodeBit(struct SessionManagement *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 31))
    {
        if (SessionManagement_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_RBC);
            if (p->NID_RBC != 16383)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_RBC);
            if (p->NID_RBC != 16383)
            {
                Bitstream_Write(stream, 64, p->NID_RADIO);
            }
            Bitstream_Write(stream, 1, p->Q_SLEEPSESSION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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


decompiled_code:
__int64 __fastcall SessionManagement_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
bool v4; // zf
__int64 v5; // rax

result = Bitstream_Normal(a2, 31LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
v3 = Bitstream_Read(a2, 1LL);
v4 = a1[6] == 0x3FFFLL;
a1[4] = v3;
if ( !v4 )
a1[5] = Bitstream_Read(a2, 10LL);
v5 = Bitstream_Read(a2, 14LL);
a1[6] = v5;
if ( v5 != 0x3FFF )
a1[7] = Bitstream_Read(a2, 64LL);
a1[8] = Bitstream_Read(a2, 1LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
bool v4; // zf
__int64 v5; // rax

result = Bitstream_Normal(a2, 31LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
v3 = Bitstream_Read(a2, 1LL);
v4 = a1[6] == 0x3FFFLL;
a1[4] = v3;
if ( !v4 )
a1[5] = Bitstream_Read(a2, 10LL);
v5 = Bitstream_Read(a2, 14LL);
a1[6] = v5;
if ( v5 != 0x3FFF )
a1[7] = Bitstream_Read(a2, 64LL);
a1[8] = Bitstream_Read(a2, 1LL);
result = 1LL;
}
return result;
}

original_code:
int SessionManagement_DecodeBit(SessionManagement* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 31))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_RBC = Bitstream_Read(stream, 1);
        }
        if (p->NID_RBC != 16383)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_RBC = Bitstream_Read(stream, 14);
        }
        if (p->NID_RBC != 16383)
        {
            {
                p->NID_RADIO = Bitstream_Read(stream, 64);
            }
        }
        {
            p->Q_SLEEPSESSION = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int SessionManagement_DecodeBit(struct SessionManagement *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 31))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_RBC = Bitstream_Read(stream, 1);
        }
        if (p->NID_RBC != 16383)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_RBC = Bitstream_Read(stream, 14);
        }
        if (p->NID_RBC != 16383)
        {
            {
                p->NID_RADIO = Bitstream_Read(stream, 64);
            }
        }
        {
            p->Q_SLEEPSESSION = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int SessionManagement_EncodeInt(const SessionManagement* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 42;
    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_RBC;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_RBC;
    stream[startAddress++] = p->NID_RADIO;
    stream[startAddress++] = p->Q_SLEEPSESSION;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int SessionManagement_EncodeInt(struct SessionManagement *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 42;
    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_RBC;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_RBC;
    stream[startAddress++] = p->NID_RADIO;
    stream[startAddress++] = p->Q_SLEEPSESSION;
    data->endAddress = startAddress-1;
    return 1;
}

variable_types: startAddress int


original_code:
int SessionManagement_DecodeInt(SessionManagement* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 42)
    {
         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_RBC = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_RBC = stream[startAddress++];
    p->NID_RADIO = stream[startAddress++];
    p->Q_SLEEPSESSION = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int SessionManagement_DecodeInt(struct SessionManagement *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 42)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_RBC = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_RBC = stream[startAddress++];
    p->NID_RADIO = stream[startAddress++];
    p->Q_SLEEPSESSION = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( SessionManagementMemoryFreeList == -1 )
{
if ( (unsigned __int64)SessionManagementMemoryTop > 7 )
return 0LL;
v3 = 9 * SessionManagementMemoryTop++;
v0 = &SessionManagementMemory[v3];
}
else
{
v0 = &SessionManagementMemory[9 * SessionManagementMemoryFreeList];
SessionManagementMemoryFreeList = *v0;
}
SessionManagement_Init(v0);
return v1;
}

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

if ( SessionManagementMemoryFreeList == -1 )
{
if ( (unsigned __int64)SessionManagementMemoryTop > 7 )
return 0LL;
v3 = 9 * SessionManagementMemoryTop++;
v0 = &SessionManagementMemory[v3];
}
else
{
v0 = &SessionManagementMemory[9 * SessionManagementMemoryFreeList];
SessionManagementMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
SessionManagement* SessionManagement_New(void)
{
    SessionManagement* ptr;
    if (SessionManagementMemoryFreeList != (-1))
    {
        ptr = &SessionManagementMemory[SessionManagementMemoryFreeList];
        SessionManagementMemoryFreeList = SessionManagementMemory[SessionManagementMemoryFreeList].header.NID_PACKET;
    }
    else if (SessionManagementMemoryTop < 8)
    {
        ptr = &SessionManagementMemory[SessionManagementMemoryTop];
        SessionManagementMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    SessionManagement_Init(ptr);
    return ptr;
}

canonical_original_code:
struct SessionManagement *SessionManagement_New()
{
    struct SessionManagement *ptr;
    if (SessionManagementMemoryFreeList != (-1))
    {
        ptr = &SessionManagementMemory[SessionManagementMemoryFreeList];
        SessionManagementMemoryFreeList = SessionManagementMemory[SessionManagementMemoryFreeList].header.NID_PACKET;
    }
    else if (SessionManagementMemoryTop < 8)
    {
        ptr = &SessionManagementMemory[SessionManagementMemoryTop];
        SessionManagementMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    SessionManagement_Init(ptr);
    return ptr;
}

return_type: struct SessionManagement { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_RBC; unsigned long NID_C; unsigned long NID_RBC; unsigned long NID_RADIO; unsigned long Q_SLEEPSESSION; } *


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

*a1 = SessionManagementMemoryFreeList;
result = 0x8E38E38E38E38E39LL;
SessionManagementMemoryFreeList = 0x8E38E38E38E38E39LL * (a1 - SessionManagementMemory);
return result;
}

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

*a1 = SessionManagementMemoryFreeList;
result = 0x8E38E38E38E38E39LL;
SessionManagementMemoryFreeList = 0x8E38E38E38E38E39LL * (a1 - SessionManagementMemory);
return result;
}

original_code:
void SessionManagement_Delete(SessionManagement* ptr)
{
    ptr->header.NID_PACKET = SessionManagementMemoryFreeList;
    SessionManagementMemoryFreeList = ptr - SessionManagementMemory;
}

canonical_original_code:
void SessionManagement_Delete(struct SessionManagement *ptr)
{
    ptr->header.NID_PACKET = SessionManagementMemoryFreeList;
    SessionManagementMemoryFreeList = ptr - SessionManagementMemory;
}

return_type: void


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

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


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

result = UpperBitsNotSet64(*a1, 15);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 8), 1);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 16), 10);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v4 + 24), 15);
}
}
return result;
}

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

result = func0(*a1, 15);
if ( result )
{
result = func0(*(_QWORD *)(v2 + 8), 1);
if ( result )
{
result = func0(*(_QWORD *)(v3 + 16), 10);
if ( result )
result = func0(*(_QWORD *)(v4 + 24), 15);
}
}
return result;
}

original_code:
int Level1MovementAuthority_1_UpperBitsNotSet(const Level1MovementAuthority_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_SECTION, 15);
    status = status && UpperBitsNotSet64(p->Q_SECTIONTIMER, 1) ;
    status = status && UpperBitsNotSet64(p->T_SECTIONTIMER, 10);
    status = status && UpperBitsNotSet64(p->D_SECTIONTIMERSTOPLOC, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Level1MovementAuthority_1_UpperBitsNotSet(struct Level1MovementAuthority_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_SECTION, 15);
    status = status && UpperBitsNotSet64(p->Q_SECTIONTIMER, 1) ;
    status = status && UpperBitsNotSet64(p->T_SECTIONTIMER, 10);
    status = status && UpperBitsNotSet64(p->D_SECTIONTIMERSTOPLOC, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct Level1MovementAuthority_1 { unsigned long L_SECTION; unsigned long Q_SECTIONTIMER; unsigned long T_SECTIONTIMER; unsigned long D_SECTIONTIMERSTOPLOC; } *


decompiled_code:
__int64 __fastcall Level1MovementAuthority_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 41LL) )
return 0xFFFFFFFFLL;
if ( !Level1MovementAuthority_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 1LL, a1[1]);
Bitstream_Write(a2, 10LL, a1[2]);
Bitstream_Write(a2, 15LL, a1[3]);
return 1LL;
}

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

original_code:
int Level1MovementAuthority_1_EncodeBit(const Level1MovementAuthority_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 41))
    {
        if (Level1MovementAuthority_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->L_SECTION);
            Bitstream_Write(stream, 1, p->Q_SECTIONTIMER);
            Bitstream_Write(stream, 10, p->T_SECTIONTIMER);
            Bitstream_Write(stream, 15, p->D_SECTIONTIMERSTOPLOC);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int Level1MovementAuthority_1_EncodeBit(struct Level1MovementAuthority_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 41))
    {
        if (Level1MovementAuthority_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->L_SECTION);
            Bitstream_Write(stream, 1, p->Q_SECTIONTIMER);
            Bitstream_Write(stream, 10, p->T_SECTIONTIMER);
            Bitstream_Write(stream, 15, p->D_SECTIONTIMERSTOPLOC);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct Level1MovementAuthority_1 { unsigned long L_SECTION; unsigned long Q_SECTIONTIMER; unsigned long T_SECTIONTIMER; unsigned long D_SECTIONTIMERSTOPLOC; }


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

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

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

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

original_code:
int Level1MovementAuthority_1_DecodeBit(Level1MovementAuthority_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 41))
    {
        {
            p->L_SECTION = Bitstream_Read(stream, 15);
        }
        {
            p->Q_SECTIONTIMER = Bitstream_Read(stream, 1);
        }
        {
            p->T_SECTIONTIMER = Bitstream_Read(stream, 10);
        }
        {
            p->D_SECTIONTIMERSTOPLOC = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Level1MovementAuthority_1_DecodeBit(struct Level1MovementAuthority_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 41))
    {
        {
            p->L_SECTION = Bitstream_Read(stream, 15);
        }
        {
            p->Q_SECTIONTIMER = Bitstream_Read(stream, 1);
        }
        {
            p->T_SECTIONTIMER = Bitstream_Read(stream, 10);
        }
        {
            p->D_SECTIONTIMERSTOPLOC = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int Level1MovementAuthority_1_EncodeInt(const Level1MovementAuthority_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->L_SECTION;
    stream[(*startAddress)++] = p->Q_SECTIONTIMER;
    stream[(*startAddress)++] = p->T_SECTIONTIMER;
    stream[(*startAddress)++] = p->D_SECTIONTIMERSTOPLOC;
    return 1;
}

canonical_original_code:
int Level1MovementAuthority_1_EncodeInt(struct Level1MovementAuthority_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->L_SECTION;
    stream[(*startAddress)++] = p->Q_SECTIONTIMER;
    stream[(*startAddress)++] = p->T_SECTIONTIMER;
    stream[(*startAddress)++] = p->D_SECTIONTIMERSTOPLOC;
    return 1;
}


original_code:
int Level1MovementAuthority_1_DecodeInt(Level1MovementAuthority_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->L_SECTION = stream[(*startAddress)++];
    p->Q_SECTIONTIMER = stream[(*startAddress)++];
    p->T_SECTIONTIMER = stream[(*startAddress)++];
    p->D_SECTIONTIMERSTOPLOC = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int Level1MovementAuthority_1_DecodeInt(struct Level1MovementAuthority_1 *p, int *startAddress, int *stream)
{
    p->L_SECTION = stream[(*startAddress)++];
    p->Q_SECTIONTIMER = stream[(*startAddress)++];
    p->T_SECTIONTIMER = stream[(*startAddress)++];
    p->D_SECTIONTIMERSTOPLOC = stream[(*startAddress)++];
    return 1;
}


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

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

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

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

original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_UpperBitsNotSet(const TrackAheadFreeUpToLevel23TransitionLocation* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_UpperBitsNotSet(struct TrackAheadFreeUpToLevel23TransitionLocation *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct TrackAheadFreeUpToLevel23TransitionLocation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; } *

user_defined_types: struct TrackAheadFreeUpToLevel23TransitionLocation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; }


decompiled_code:
__int64 __fastcall TrackAheadFreeUpToLevel23TransitionLocation_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 30LL) )
return 0xFFFFFFFFLL;
if ( !TrackAheadFreeUpToLevel23TransitionLocation_UpperBitsNotSet((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
if ( a1[4] == 1LL )
Bitstream_Write(a2, 10LL, a1[5]);
Bitstream_Write(a2, 14LL, a1[6]);
return 1LL;
}

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

original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_EncodeBit(const TrackAheadFreeUpToLevel23TransitionLocation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        if (TrackAheadFreeUpToLevel23TransitionLocation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_EncodeBit(struct TrackAheadFreeUpToLevel23TransitionLocation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        if (TrackAheadFreeUpToLevel23TransitionLocation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

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

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

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

original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_DecodeBit(TrackAheadFreeUpToLevel23TransitionLocation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_NEWCOUNTRY = Bitstream_Read(stream, 1);
        }
        if (p->Q_NEWCOUNTRY == 1)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_DecodeBit(struct TrackAheadFreeUpToLevel23TransitionLocation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_NEWCOUNTRY = Bitstream_Read(stream, 1);
        }
        if (p->Q_NEWCOUNTRY == 1)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_EncodeInt(const TrackAheadFreeUpToLevel23TransitionLocation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 90;
    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_NEWCOUNTRY;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_BG;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_EncodeInt(struct TrackAheadFreeUpToLevel23TransitionLocation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 90;
    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_NEWCOUNTRY;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_BG;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_DecodeInt(TrackAheadFreeUpToLevel23TransitionLocation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 90)
    {
         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_NEWCOUNTRY = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_DecodeInt(struct TrackAheadFreeUpToLevel23TransitionLocation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 90)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_NEWCOUNTRY = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList == -1 )
{
if ( (unsigned __int64)TrackAheadFreeUpToLevel23TransitionLocationMemoryTop > 7 )
return 0LL;
v3 = 7 * TrackAheadFreeUpToLevel23TransitionLocationMemoryTop++;
v0 = &TrackAheadFreeUpToLevel23TransitionLocationMemory[v3];
}
else
{
v0 = &TrackAheadFreeUpToLevel23TransitionLocationMemory[7
* TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList];
TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList = *v0;
}
TrackAheadFreeUpToLevel23TransitionLocation_Init(v0);
return v1;
}

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

if ( TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList == -1 )
{
if ( (unsigned __int64)TrackAheadFreeUpToLevel23TransitionLocationMemoryTop > 7 )
return 0LL;
v3 = 7 * TrackAheadFreeUpToLevel23TransitionLocationMemoryTop++;
v0 = &TrackAheadFreeUpToLevel23TransitionLocationMemory[v3];
}
else
{
v0 = &TrackAheadFreeUpToLevel23TransitionLocationMemory[7
* TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList];
TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
TrackAheadFreeUpToLevel23TransitionLocation* TrackAheadFreeUpToLevel23TransitionLocation_New(void)
{
    TrackAheadFreeUpToLevel23TransitionLocation* ptr;
    if (TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList != (-1))
    {
        ptr = &TrackAheadFreeUpToLevel23TransitionLocationMemory[TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList];
        TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList = TrackAheadFreeUpToLevel23TransitionLocationMemory[TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList].header.NID_PACKET;
    }
    else if (TrackAheadFreeUpToLevel23TransitionLocationMemoryTop < 8)
    {
        ptr = &TrackAheadFreeUpToLevel23TransitionLocationMemory[TrackAheadFreeUpToLevel23TransitionLocationMemoryTop];
        TrackAheadFreeUpToLevel23TransitionLocationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    TrackAheadFreeUpToLevel23TransitionLocation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct TrackAheadFreeUpToLevel23TransitionLocation *TrackAheadFreeUpToLevel23TransitionLocation_New()
{
    struct TrackAheadFreeUpToLevel23TransitionLocation *ptr;
    if (TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList != (-1))
    {
        ptr = &TrackAheadFreeUpToLevel23TransitionLocationMemory[TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList];
        TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList = TrackAheadFreeUpToLevel23TransitionLocationMemory[TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList].header.NID_PACKET;
    }
    else if (TrackAheadFreeUpToLevel23TransitionLocationMemoryTop < 8)
    {
        ptr = &TrackAheadFreeUpToLevel23TransitionLocationMemory[TrackAheadFreeUpToLevel23TransitionLocationMemoryTop];
        TrackAheadFreeUpToLevel23TransitionLocationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    TrackAheadFreeUpToLevel23TransitionLocation_Init(ptr);
    return ptr;
}

return_type: struct TrackAheadFreeUpToLevel23TransitionLocation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; } *


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

*a1 = TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL
* (a1 - TrackAheadFreeUpToLevel23TransitionLocationMemory);
return result;
}

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

*a1 = TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL
* (a1 - TrackAheadFreeUpToLevel23TransitionLocationMemory);
return result;
}

original_code:
void TrackAheadFreeUpToLevel23TransitionLocation_Delete(TrackAheadFreeUpToLevel23TransitionLocation* ptr)
{
    ptr->header.NID_PACKET = TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList;
    TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList = ptr - TrackAheadFreeUpToLevel23TransitionLocationMemory;
}

canonical_original_code:
void TrackAheadFreeUpToLevel23TransitionLocation_Delete(struct TrackAheadFreeUpToLevel23TransitionLocation *ptr)
{
    ptr->header.NID_PACKET = TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList;
    TrackAheadFreeUpToLevel23TransitionLocationMemoryFreeList = ptr - TrackAheadFreeUpToLevel23TransitionLocationMemory;
}


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 RadioInfillAreaInformation_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 13);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 32), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v4 + 40), 1);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v5 + 48), 10);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v6 + 56), 14);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v7 + 64), 64);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v8 + 72), 15);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v9 + 80), 10);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v10 + 88), 14);
}
}
}
}
}
}
}
}
return result;
}

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

result = func0(*(_QWORD *)(a1 + 16), 2);
if ( result )
{
result = func0(*(_QWORD *)(v2 + 24), 13);
if ( result )
{
result = func0(*(_QWORD *)(v3 + 32), 2);
if ( result )
{
result = func0(*(_QWORD *)(v4 + 40), 1);
if ( result )
{
result = func0(*(_QWORD *)(v5 + 48), 10);
if ( result )
{
result = func0(*(_QWORD *)(v6 + 56), 14);
if ( result )
{
result = func0(*(_QWORD *)(v7 + 64), 64);
if ( result )
{
result = func0(*(_QWORD *)(v8 + 72), 15);
if ( result )
{
result = func0(*(_QWORD *)(v9 + 80), 10);
if ( result )
result = func0(*(_QWORD *)(v10 + 88), 14);
}
}
}
}
}
}
}
}
return result;
}

original_code:
int RadioInfillAreaInformation_UpperBitsNotSet(const RadioInfillAreaInformation* 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->Q_RIU, 1) ;
    status = status && UpperBitsNotSet64(p->NID_C_0, 10);
    status = status && UpperBitsNotSet64(p->NID_RIU, 14);
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    status = status && UpperBitsNotSet64(p->D_INFILL, 15);
    status = status && UpperBitsNotSet64(p->NID_C_1, 10);
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RadioInfillAreaInformation_UpperBitsNotSet(struct RadioInfillAreaInformation *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->Q_RIU, 1) ;
    status = status && UpperBitsNotSet64(p->NID_C_0, 10);
    status = status && UpperBitsNotSet64(p->NID_RIU, 14);
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    status = status && UpperBitsNotSet64(p->D_INFILL, 15);
    status = status && UpperBitsNotSet64(p->NID_C_1, 10);
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct RadioInfillAreaInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_RIU; unsigned long NID_C_0; unsigned long NID_RIU; unsigned long NID_RADIO; unsigned long D_INFILL; unsigned long NID_C_1; unsigned long NID_BG; } *

user_defined_types: struct RadioInfillAreaInformation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_RIU; unsigned long NID_C_0; unsigned long NID_RIU; unsigned long NID_RADIO; unsigned long D_INFILL; unsigned long NID_C_1; unsigned long NID_BG; }


decompiled_code:
__int64 __fastcall RadioInfillAreaInformation_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 145LL) )
return 0xFFFFFFFFLL;
if ( !RadioInfillAreaInformation_UpperBitsNotSet((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 1LL, a1[5]);
Bitstream_Write(a2, 10LL, a1[6]);
Bitstream_Write(a2, 14LL, a1[7]);
Bitstream_Write(a2, 64LL, a1[8]);
Bitstream_Write(a2, 15LL, a1[9]);
Bitstream_Write(a2, 10LL, a1[10]);
Bitstream_Write(a2, 14LL, a1[11]);
return 1LL;
}

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

original_code:
int RadioInfillAreaInformation_EncodeBit(const RadioInfillAreaInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 145))
    {
        if (RadioInfillAreaInformation_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_RIU);
            Bitstream_Write(stream, 10, p->NID_C_0);
            Bitstream_Write(stream, 14, p->NID_RIU);
            Bitstream_Write(stream, 64, p->NID_RADIO);
            Bitstream_Write(stream, 15, p->D_INFILL);
            Bitstream_Write(stream, 10, p->NID_C_1);
            Bitstream_Write(stream, 14, p->NID_BG);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int RadioInfillAreaInformation_EncodeBit(struct RadioInfillAreaInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 145))
    {
        if (RadioInfillAreaInformation_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_RIU);
            Bitstream_Write(stream, 10, p->NID_C_0);
            Bitstream_Write(stream, 14, p->NID_RIU);
            Bitstream_Write(stream, 64, p->NID_RADIO);
            Bitstream_Write(stream, 15, p->D_INFILL);
            Bitstream_Write(stream, 10, p->NID_C_1);
            Bitstream_Write(stream, 14, p->NID_BG);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

result = Bitstream_Normal(a2, 145LL);
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, 1LL);
a1[6] = Bitstream_Read(a2, 10LL);
a1[7] = Bitstream_Read(a2, 14LL);
a1[8] = Bitstream_Read(a2, 64LL);
a1[9] = Bitstream_Read(a2, 15LL);
a1[10] = Bitstream_Read(a2, 10LL);
a1[11] = Bitstream_Read(a2, 14LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 145LL);
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, 1LL);
a1[6] = Bitstream_Read(a2, 10LL);
a1[7] = Bitstream_Read(a2, 14LL);
a1[8] = Bitstream_Read(a2, 64LL);
a1[9] = Bitstream_Read(a2, 15LL);
a1[10] = Bitstream_Read(a2, 10LL);
a1[11] = Bitstream_Read(a2, 14LL);
result = 1LL;
}
return result;
}

original_code:
int RadioInfillAreaInformation_DecodeBit(RadioInfillAreaInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 145))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_RIU = Bitstream_Read(stream, 1);
        }
        {
            p->NID_C_0 = Bitstream_Read(stream, 10);
        }
        {
            p->NID_RIU = Bitstream_Read(stream, 14);
        }
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        {
            p->D_INFILL = Bitstream_Read(stream, 15);
        }
        {
            p->NID_C_1 = Bitstream_Read(stream, 10);
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RadioInfillAreaInformation_DecodeBit(struct RadioInfillAreaInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 145))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_RIU = Bitstream_Read(stream, 1);
        }
        {
            p->NID_C_0 = Bitstream_Read(stream, 10);
        }
        {
            p->NID_RIU = Bitstream_Read(stream, 14);
        }
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        {
            p->D_INFILL = Bitstream_Read(stream, 15);
        }
        {
            p->NID_C_1 = Bitstream_Read(stream, 10);
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int RadioInfillAreaInformation_EncodeInt(const RadioInfillAreaInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 133;
    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->Q_RIU;
    stream[startAddress++] = p->NID_C_0;
    stream[startAddress++] = p->NID_RIU;
    stream[startAddress++] = p->NID_RADIO;
    stream[startAddress++] = p->D_INFILL;
    stream[startAddress++] = p->NID_C_1;
    stream[startAddress++] = p->NID_BG;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int RadioInfillAreaInformation_EncodeInt(struct RadioInfillAreaInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 133;
    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->Q_RIU;
    stream[startAddress++] = p->NID_C_0;
    stream[startAddress++] = p->NID_RIU;
    stream[startAddress++] = p->NID_RADIO;
    stream[startAddress++] = p->D_INFILL;
    stream[startAddress++] = p->NID_C_1;
    stream[startAddress++] = p->NID_BG;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int RadioInfillAreaInformation_DecodeInt(RadioInfillAreaInformation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 133)
    {
         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->Q_RIU = stream[startAddress++];
    p->NID_C_0 = stream[startAddress++];
    p->NID_RIU = stream[startAddress++];
    p->NID_RADIO = stream[startAddress++];
    p->D_INFILL = stream[startAddress++];
    p->NID_C_1 = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int RadioInfillAreaInformation_DecodeInt(struct RadioInfillAreaInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 133)
    {
         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->Q_RIU = stream[startAddress++];
    p->NID_C_0 = stream[startAddress++];
    p->NID_RIU = stream[startAddress++];
    p->NID_RADIO = stream[startAddress++];
    p->D_INFILL = stream[startAddress++];
    p->NID_C_1 = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( RadioInfillAreaInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)RadioInfillAreaInformationMemoryTop <= 7 )
{
v1 = 12 * RadioInfillAreaInformationMemoryTop++;
RadioInfillAreaInformation_Init(&RadioInfillAreaInformationMemory[v1]);
}
}
else
{
v0 = &RadioInfillAreaInformationMemory[12 * RadioInfillAreaInformationMemoryFreeList];
RadioInfillAreaInformationMemoryFreeList = *v0;
RadioInfillAreaInformation_Init(v0);
}
}

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

if ( RadioInfillAreaInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)RadioInfillAreaInformationMemoryTop <= 7 )
{
v1 = 12 * RadioInfillAreaInformationMemoryTop++;
func1(&RadioInfillAreaInformationMemory[v1]);
}
}
else
{
v0 = &RadioInfillAreaInformationMemory[12 * RadioInfillAreaInformationMemoryFreeList];
RadioInfillAreaInformationMemoryFreeList = *v0;
func1(v0);
}
}

original_code:
RadioInfillAreaInformation* RadioInfillAreaInformation_New(void)
{
    RadioInfillAreaInformation* ptr;
    if (RadioInfillAreaInformationMemoryFreeList != (-1))
    {
        ptr = &RadioInfillAreaInformationMemory[RadioInfillAreaInformationMemoryFreeList];
        RadioInfillAreaInformationMemoryFreeList = RadioInfillAreaInformationMemory[RadioInfillAreaInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (RadioInfillAreaInformationMemoryTop < 8)
    {
        ptr = &RadioInfillAreaInformationMemory[RadioInfillAreaInformationMemoryTop];
        RadioInfillAreaInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RadioInfillAreaInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct RadioInfillAreaInformation *RadioInfillAreaInformation_New()
{
    struct RadioInfillAreaInformation *ptr;
    if (RadioInfillAreaInformationMemoryFreeList != (-1))
    {
        ptr = &RadioInfillAreaInformationMemory[RadioInfillAreaInformationMemoryFreeList];
        RadioInfillAreaInformationMemoryFreeList = RadioInfillAreaInformationMemory[RadioInfillAreaInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (RadioInfillAreaInformationMemoryTop < 8)
    {
        ptr = &RadioInfillAreaInformationMemory[RadioInfillAreaInformationMemoryTop];
        RadioInfillAreaInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RadioInfillAreaInformation_Init(ptr);
    return ptr;
}

return_type: struct RadioInfillAreaInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_RIU; unsigned long NID_C_0; unsigned long NID_RIU; unsigned long NID_RADIO; unsigned long D_INFILL; unsigned long NID_C_1; unsigned long NID_BG; } *


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

*(_QWORD *)a1 = RadioInfillAreaInformationMemoryFreeList;
result = 0xAAAAAAAAAAAAAAABLL;
RadioInfillAreaInformationMemoryFreeList = 0xAAAAAAAAAAAAAAABLL
* ((a1 - (char *)RadioInfillAreaInformationMemory) >> 5);
return result;
}

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

*(_QWORD *)a1 = RadioInfillAreaInformationMemoryFreeList;
result = 0xAAAAAAAAAAAAAAABLL;
RadioInfillAreaInformationMemoryFreeList = 0xAAAAAAAAAAAAAAABLL
* ((a1 - (char *)RadioInfillAreaInformationMemory) >> 5);
return result;
}

original_code:
void RadioInfillAreaInformation_Delete(RadioInfillAreaInformation* ptr)
{
    ptr->header.NID_PACKET = RadioInfillAreaInformationMemoryFreeList;
    RadioInfillAreaInformationMemoryFreeList = ptr - RadioInfillAreaInformationMemory;
}

canonical_original_code:
void RadioInfillAreaInformation_Delete(struct RadioInfillAreaInformation *ptr)
{
    ptr->header.NID_PACKET = RadioInfillAreaInformationMemoryFreeList;
    RadioInfillAreaInformationMemoryFreeList = ptr - RadioInfillAreaInformationMemory;
}


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

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

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

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

original_code:
int ModeProfile_1_UpperBitsNotSet(const ModeProfile_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_MAMODE, 15);
    status = status && UpperBitsNotSet64(p->M_MAMODE, 2) ;
    status = status && UpperBitsNotSet64(p->V_MAMODE, 7) ;
    status = status && UpperBitsNotSet64(p->L_MAMODE, 15);
    status = status && UpperBitsNotSet64(p->L_ACKMAMODE, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ModeProfile_1_UpperBitsNotSet(struct ModeProfile_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_MAMODE, 15);
    status = status && UpperBitsNotSet64(p->M_MAMODE, 2) ;
    status = status && UpperBitsNotSet64(p->V_MAMODE, 7) ;
    status = status && UpperBitsNotSet64(p->L_MAMODE, 15);
    status = status && UpperBitsNotSet64(p->L_ACKMAMODE, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

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


decompiled_code:
__int64 __fastcall ModeProfile_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 54LL) )
return 0xFFFFFFFFLL;
if ( !ModeProfile_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 2LL, a1[1]);
Bitstream_Write(a2, 7LL, a1[2]);
Bitstream_Write(a2, 15LL, a1[3]);
Bitstream_Write(a2, 15LL, a1[4]);
return 1LL;
}

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

original_code:
int ModeProfile_1_EncodeBit(const ModeProfile_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 54))
    {
        if (ModeProfile_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_MAMODE);
            Bitstream_Write(stream, 2, p->M_MAMODE);
            Bitstream_Write(stream, 7, p->V_MAMODE);
            Bitstream_Write(stream, 15, p->L_MAMODE);
            Bitstream_Write(stream, 15, p->L_ACKMAMODE);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ModeProfile_1_EncodeBit(struct ModeProfile_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 54))
    {
        if (ModeProfile_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_MAMODE);
            Bitstream_Write(stream, 2, p->M_MAMODE);
            Bitstream_Write(stream, 7, p->V_MAMODE);
            Bitstream_Write(stream, 15, p->L_MAMODE);
            Bitstream_Write(stream, 15, p->L_ACKMAMODE);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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


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

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

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

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

original_code:
int ModeProfile_1_DecodeBit(ModeProfile_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 54))
    {
        {
            p->D_MAMODE = Bitstream_Read(stream, 15);
        }
        {
            p->M_MAMODE = Bitstream_Read(stream, 2);
        }
        {
            p->V_MAMODE = Bitstream_Read(stream, 7);
        }
        {
            p->L_MAMODE = Bitstream_Read(stream, 15);
        }
        {
            p->L_ACKMAMODE = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ModeProfile_1_DecodeBit(struct ModeProfile_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 54))
    {
        {
            p->D_MAMODE = Bitstream_Read(stream, 15);
        }
        {
            p->M_MAMODE = Bitstream_Read(stream, 2);
        }
        {
            p->V_MAMODE = Bitstream_Read(stream, 7);
        }
        {
            p->L_MAMODE = Bitstream_Read(stream, 15);
        }
        {
            p->L_ACKMAMODE = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int ModeProfile_1_EncodeInt(const ModeProfile_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->D_MAMODE;
    stream[(*startAddress)++] = p->M_MAMODE;
    stream[(*startAddress)++] = p->V_MAMODE;
    stream[(*startAddress)++] = p->L_MAMODE;
    stream[(*startAddress)++] = p->L_ACKMAMODE;
    return 1;
}

canonical_original_code:
int ModeProfile_1_EncodeInt(struct ModeProfile_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->D_MAMODE;
    stream[(*startAddress)++] = p->M_MAMODE;
    stream[(*startAddress)++] = p->V_MAMODE;
    stream[(*startAddress)++] = p->L_MAMODE;
    stream[(*startAddress)++] = p->L_ACKMAMODE;
    return 1;
}


original_code:
int ModeProfile_1_DecodeInt(ModeProfile_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->D_MAMODE = stream[(*startAddress)++];
    p->M_MAMODE = stream[(*startAddress)++];
    p->V_MAMODE = stream[(*startAddress)++];
    p->L_MAMODE = stream[(*startAddress)++];
    p->L_ACKMAMODE = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int ModeProfile_1_DecodeInt(struct ModeProfile_1 *p, int *startAddress, int *stream)
{
    p->D_MAMODE = stream[(*startAddress)++];
    p->M_MAMODE = stream[(*startAddress)++];
    p->V_MAMODE = stream[(*startAddress)++];
    p->L_MAMODE = stream[(*startAddress)++];
    p->L_ACKMAMODE = stream[(*startAddress)++];
    return 1;
}


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

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


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

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

original_code:
int Packet_for_sending_fixed_text_messages_Encode_Bit(Bitstream* stream, const Packet_for_sending_fixed_text_messages_Core* p)
{
    if (Bitstream_Normal(stream, 84))
    {
        if (Packet_for_sending_fixed_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->Q_TEXT);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int Packet_for_sending_fixed_text_messages_Encode_Bit(struct Bitstream *stream, struct Packet_for_sending_fixed_text_messages_Core *p)
{
    if (Bitstream_Normal(stream, 84))
    {
        if (Packet_for_sending_fixed_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->Q_TEXT);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

variable_types: struct Packet_for_sending_fixed_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 Q_TEXT; } *


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

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

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

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

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

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

user_defined_types: struct Packet_for_sending_fixed_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 Q_TEXT; }


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

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


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

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


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

v1 = UpperBitsNotSet64(a1[2], 2);
v2 = a1[8];
if ( !v1
|| !UpperBitsNotSet64(a1[3], 13)
|| !UpperBitsNotSet64(a1[4], 2)
|| !UpperBitsNotSet64(a1[5], 7)
|| !UpperBitsNotSet64(a1[6], 7)
|| !UpperBitsNotSet64(a1[7], 10) )
{
LODWORD(v3) = 0;
if ( v2 )
{
do
{
LABEL_4:
if ( (unsigned int)(v3 + 1) >= v2 )
break;
v3 = (unsigned int)(v3 + 2);
}
while ( v3 < v2 );
}
return 0LL;
}
v5 = UpperBitsNotSet64(v2, 5);
if ( v2 )
{
LODWORD(v3) = 0;
if ( v5 )
{
v6 = 0LL;
while ( 1 )
{
v7 = Level1MovementAuthority_1_UpperBitsNotSet(&a1[4 * v6 + 9]);
v6 = (unsigned int)(v3 + 1);
LODWORD(v3) = v3 + 1;
if ( !v7 )
break;
if ( a1[8] <= v6 )
goto LABEL_18;
}
v2 = a1[8];
if ( v2 <= v6 )
return 0LL;
}
goto LABEL_4;
}
if ( !v5 )
return 0LL;
LABEL_18:
if ( !UpperBitsNotSet64(a1[133], 15)
|| !UpperBitsNotSet64(a1[134], 1)
|| !UpperBitsNotSet64(a1[135], 10)
|| !UpperBitsNotSet64(a1[136], 15)
|| !UpperBitsNotSet64(a1[137], 1)
|| !UpperBitsNotSet64(a1[138], 10)
|| !UpperBitsNotSet64(a1[139], 15)
|| !UpperBitsNotSet64(a1[140], 1)
|| !UpperBitsNotSet64(a1[141], 15)
|| !UpperBitsNotSet64(a1[142], 7)
|| !UpperBitsNotSet64(a1[143], 1)
|| !UpperBitsNotSet64(a1[144], 15)
|| !UpperBitsNotSet64(a1[145], 10)
|| !UpperBitsNotSet64(a1[146], 15) )
{
return 0LL;
}
return UpperBitsNotSet64(a1[147], 7);
}

original_code:
int Level1MovementAuthority_UpperBitsNotSet(const Level1MovementAuthority* 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->V_MAIN, 7) ;
    status = status && UpperBitsNotSet64(p->V_LOA, 7) ;
    status = status && UpperBitsNotSet64(p->T_LOA, 10);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && Level1MovementAuthority_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->L_ENDSECTION, 15);
    status = status && UpperBitsNotSet64(p->Q_SECTIONTIMER, 1) ;
    status = status && UpperBitsNotSet64(p->T_SECTIONTIMER, 10);
    status = status && UpperBitsNotSet64(p->D_SECTIONTIMERSTOPLOC, 15);
    status = status && UpperBitsNotSet64(p->Q_ENDTIMER, 1) ;
    status = status && UpperBitsNotSet64(p->T_ENDTIMER, 10);
    status = status && UpperBitsNotSet64(p->D_ENDTIMERSTARTLOC, 15);
    status = status && UpperBitsNotSet64(p->Q_DANGERPOINT, 1) ;
    status = status && UpperBitsNotSet64(p->D_DP, 15);
    status = status && UpperBitsNotSet64(p->V_RELEASEDP, 7) ;
    status = status && UpperBitsNotSet64(p->Q_OVERLAP, 1) ;
    status = status && UpperBitsNotSet64(p->D_STARTOL, 15);
    status = status && UpperBitsNotSet64(p->T_OL, 10);
    status = status && UpperBitsNotSet64(p->D_OL, 15);
    status = status && UpperBitsNotSet64(p->V_RELEASEOL, 7) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Level1MovementAuthority_UpperBitsNotSet(struct Level1MovementAuthority *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->V_MAIN, 7) ;
    status = status && UpperBitsNotSet64(p->V_LOA, 7) ;
    status = status && UpperBitsNotSet64(p->T_LOA, 10);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && Level1MovementAuthority_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->L_ENDSECTION, 15);
    status = status && UpperBitsNotSet64(p->Q_SECTIONTIMER, 1) ;
    status = status && UpperBitsNotSet64(p->T_SECTIONTIMER, 10);
    status = status && UpperBitsNotSet64(p->D_SECTIONTIMERSTOPLOC, 15);
    status = status && UpperBitsNotSet64(p->Q_ENDTIMER, 1) ;
    status = status && UpperBitsNotSet64(p->T_ENDTIMER, 10);
    status = status && UpperBitsNotSet64(p->D_ENDTIMERSTARTLOC, 15);
    status = status && UpperBitsNotSet64(p->Q_DANGERPOINT, 1) ;
    status = status && UpperBitsNotSet64(p->D_DP, 15);
    status = status && UpperBitsNotSet64(p->V_RELEASEDP, 7) ;
    status = status && UpperBitsNotSet64(p->Q_OVERLAP, 1) ;
    status = status && UpperBitsNotSet64(p->D_STARTOL, 15);
    status = status && UpperBitsNotSet64(p->T_OL, 10);
    status = status && UpperBitsNotSet64(p->D_OL, 15);
    status = status && UpperBitsNotSet64(p->V_RELEASEOL, 7) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct Level1MovementAuthority { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long V_MAIN; unsigned long V_LOA; unsigned long T_LOA; unsigned long N_ITER_1; struct Level1MovementAuthority_1 { unsigned long L_SECTION; unsigned long Q_SECTIONTIMER; unsigned long T_SECTIONTIMER; unsigned long D_SECTIONTIMERSTOPLOC; } sub_1[31]; unsigned long L_ENDSECTION; unsigned long Q_SECTIONTIMER; unsigned long T_SECTIONTIMER; unsigned long D_SECTIONTIMERSTOPLOC; unsigned long Q_ENDTIMER; unsigned long T_ENDTIMER; unsigned long D_ENDTIMERSTARTLOC; unsigned long Q_DANGERPOINT; unsigned long D_DP; unsigned long V_RELEASEDP; unsigned long Q_OVERLAP; unsigned long D_STARTOL; unsigned long T_OL; unsigned long D_OL; unsigned long V_RELEASEOL; } *

variable_types:
i
unsigned int

user_defined_types: struct Level1MovementAuthority { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long V_MAIN; unsigned long V_LOA; unsigned long T_LOA; unsigned long N_ITER_1; struct Level1MovementAuthority_1 sub_1[31]; unsigned long L_ENDSECTION; unsigned long Q_SECTIONTIMER; unsigned long T_SECTIONTIMER; unsigned long D_SECTIONTIMERSTOPLOC; unsigned long Q_ENDTIMER; unsigned long T_ENDTIMER; unsigned long D_ENDTIMERSTARTLOC; unsigned long Q_DANGERPOINT; unsigned long D_DP; unsigned long V_RELEASEDP; unsigned long Q_OVERLAP; unsigned long D_STARTOL; unsigned long T_OL; unsigned long D_OL; unsigned long V_RELEASEOL; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 184LL) )
return 0xFFFFFFFFLL;
if ( !Level1MovementAuthority_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, 7LL, a1[5]);
Bitstream_Write(a2, 7LL, a1[6]);
Bitstream_Write(a2, 10LL, a1[7]);
Bitstream_Write(a2, 5LL, a1[8]);
if ( a1[8] )
{
v2 = 0;
v3 = 0LL;
do
{
Level1MovementAuthority_1_EncodeBit(&a1[4 * v3 + 9], a2);
v3 = ++v2;
}
while ( v2 < a1[8] );
}
Bitstream_Write(a2, 15LL, a1[133]);
Bitstream_Write(a2, 1LL, a1[134]);
Bitstream_Write(a2, 10LL, a1[135]);
Bitstream_Write(a2, 15LL, a1[136]);
Bitstream_Write(a2, 1LL, a1[137]);
Bitstream_Write(a2, 10LL, a1[138]);
Bitstream_Write(a2, 15LL, a1[139]);
Bitstream_Write(a2, 1LL, a1[140]);
Bitstream_Write(a2, 15LL, a1[141]);
Bitstream_Write(a2, 7LL, a1[142]);
Bitstream_Write(a2, 1LL, a1[143]);
Bitstream_Write(a2, 15LL, a1[144]);
Bitstream_Write(a2, 10LL, a1[145]);
Bitstream_Write(a2, 15LL, a1[146]);
Bitstream_Write(a2, 7LL, a1[147]);
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 184LL) )
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, 7LL, a1[5]);
Bitstream_Write(a2, 7LL, a1[6]);
Bitstream_Write(a2, 10LL, a1[7]);
Bitstream_Write(a2, 5LL, a1[8]);
if ( a1[8] )
{
v2 = 0;
v3 = 0LL;
do
{
Level1MovementAuthority_1_EncodeBit(&a1[4 * v3 + 9], a2);
v3 = ++v2;
}
while ( v2 < a1[8] );
}
Bitstream_Write(a2, 15LL, a1[133]);
Bitstream_Write(a2, 1LL, a1[134]);
Bitstream_Write(a2, 10LL, a1[135]);
Bitstream_Write(a2, 15LL, a1[136]);
Bitstream_Write(a2, 1LL, a1[137]);
Bitstream_Write(a2, 10LL, a1[138]);
Bitstream_Write(a2, 15LL, a1[139]);
Bitstream_Write(a2, 1LL, a1[140]);
Bitstream_Write(a2, 15LL, a1[141]);
Bitstream_Write(a2, 7LL, a1[142]);
Bitstream_Write(a2, 1LL, a1[143]);
Bitstream_Write(a2, 15LL, a1[144]);
Bitstream_Write(a2, 10LL, a1[145]);
Bitstream_Write(a2, 15LL, a1[146]);
Bitstream_Write(a2, 7LL, a1[147]);
return 1LL;
}

original_code:
int Level1MovementAuthority_EncodeBit(const Level1MovementAuthority* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 184))
    {
        if (Level1MovementAuthority_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, 7, p->V_MAIN);
            Bitstream_Write(stream, 7, p->V_LOA);
            Bitstream_Write(stream, 10, p->T_LOA);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                Level1MovementAuthority_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 15, p->L_ENDSECTION);
            Bitstream_Write(stream, 1, p->Q_SECTIONTIMER);
            Bitstream_Write(stream, 10, p->T_SECTIONTIMER);
            Bitstream_Write(stream, 15, p->D_SECTIONTIMERSTOPLOC);
            Bitstream_Write(stream, 1, p->Q_ENDTIMER);
            Bitstream_Write(stream, 10, p->T_ENDTIMER);
            Bitstream_Write(stream, 15, p->D_ENDTIMERSTARTLOC);
            Bitstream_Write(stream, 1, p->Q_DANGERPOINT);
            Bitstream_Write(stream, 15, p->D_DP);
            Bitstream_Write(stream, 7, p->V_RELEASEDP);
            Bitstream_Write(stream, 1, p->Q_OVERLAP);
            Bitstream_Write(stream, 15, p->D_STARTOL);
            Bitstream_Write(stream, 10, p->T_OL);
            Bitstream_Write(stream, 15, p->D_OL);
            Bitstream_Write(stream, 7, p->V_RELEASEOL);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int Level1MovementAuthority_EncodeBit(struct Level1MovementAuthority *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 184))
    {
        if (Level1MovementAuthority_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, 7, p->V_MAIN);
            Bitstream_Write(stream, 7, p->V_LOA);
            Bitstream_Write(stream, 10, p->T_LOA);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                Level1MovementAuthority_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 15, p->L_ENDSECTION);
            Bitstream_Write(stream, 1, p->Q_SECTIONTIMER);
            Bitstream_Write(stream, 10, p->T_SECTIONTIMER);
            Bitstream_Write(stream, 15, p->D_SECTIONTIMERSTOPLOC);
            Bitstream_Write(stream, 1, p->Q_ENDTIMER);
            Bitstream_Write(stream, 10, p->T_ENDTIMER);
            Bitstream_Write(stream, 15, p->D_ENDTIMERSTARTLOC);
            Bitstream_Write(stream, 1, p->Q_DANGERPOINT);
            Bitstream_Write(stream, 15, p->D_DP);
            Bitstream_Write(stream, 7, p->V_RELEASEDP);
            Bitstream_Write(stream, 1, p->Q_OVERLAP);
            Bitstream_Write(stream, 15, p->D_STARTOL);
            Bitstream_Write(stream, 10, p->T_OL);
            Bitstream_Write(stream, 15, p->D_OL);
            Bitstream_Write(stream, 7, p->V_RELEASEOL);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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