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

if ( DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList == -1 )
{
if ( (unsigned __int64)DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop > 7 )
return 0LL;
v0 = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[5
* DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop++];
}
else
{
v0 = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[5
* DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList];
DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = *v0;
}
DataUsedByApplicationsOutsideTheERTMSETCSSystem_Init(v0);
return v0;
}

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

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

original_code:
DataUsedByApplicationsOutsideTheERTMSETCSSystem* DataUsedByApplicationsOutsideTheERTMSETCSSystem_New(void)
{
    DataUsedByApplicationsOutsideTheERTMSETCSSystem* ptr;
    if (DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList != (-1))
    {
        ptr = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList];
        DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList].header.NID_PACKET;
    }
    else if (DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop < 8)
    {
        ptr = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop];
        DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DataUsedByApplicationsOutsideTheERTMSETCSSystem_Init(ptr);
    return ptr;
}

canonical_original_code:
struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *DataUsedByApplicationsOutsideTheERTMSETCSSystem_New()
{
    struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *ptr;
    if (DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList != (-1))
    {
        ptr = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList];
        DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList].header.NID_PACKET;
    }
    else if (DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop < 8)
    {
        ptr = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop];
        DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DataUsedByApplicationsOutsideTheERTMSETCSSystem_Init(ptr);
    return ptr;
}

return_type: struct DataUsedByApplicationsOutsideTheERTMSETCSSystem { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long NID_XUSER; unsigned long Other_data_depending_on__NID_XUSER; } *


repo: openETCS/dataDictionary

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

*a1 = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL
* (a1
- DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory);
return result;
}

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

*a1 = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL
* (a1
- DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory);
return result;
}

original_code:
void DataUsedByApplicationsOutsideTheERTMSETCSSystem_Delete(DataUsedByApplicationsOutsideTheERTMSETCSSystem* ptr)
{
    ptr->header.NID_PACKET = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList;
    DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = ptr - DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory;
}

canonical_original_code:
void DataUsedByApplicationsOutsideTheERTMSETCSSystem_Delete(struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *ptr)
{
    ptr->header.NID_PACKET = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList;
    DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = ptr - DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory;
}

variable_types: struct DataUsedByApplicationsOutsideTheERTMSETCSSystem { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long NID_XUSER; unsigned long Other_data_depending_on__NID_XUSER; } *

return_type: void

user_defined_types: struct DataUsedByApplicationsOutsideTheERTMSETCSSystem { struct PacketHeader header; unsigned long L_PACKET; unsigned long NID_XUSER; unsigned long Other_data_depending_on__NID_XUSER; }


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

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

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

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

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

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

variable_types:
value
unsigned long

variable_types:
length
unsigned int

variable_types:
MaxValue
unsigned long

return_type: int


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

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

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

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

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

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

variable_types: struct LevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; } *

variable_types: status int


decompiled_code:
__int64 __fastcall LevelTransitionOrder_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 18LL) )
return 0xFFFFFFFFLL;
if ( !LevelTransitionOrder_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 3LL, *a1);
if ( *a1 == 1 )
Bitstream_Write(a2, 8LL, a1[1]);
Bitstream_Write(a2, 15LL, a1[2]);
return 1LL;
}

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

original_code:
int LevelTransitionOrder_1_EncodeBit(const LevelTransitionOrder_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        if (LevelTransitionOrder_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            Bitstream_Write(stream, 15, p->L_ACKLEVELTR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int LevelTransitionOrder_1_EncodeBit(struct LevelTransitionOrder_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        if (LevelTransitionOrder_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            Bitstream_Write(stream, 15, p->L_ACKLEVELTR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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

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


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

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

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

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

original_code:
int LevelTransitionOrder_1_DecodeBit(LevelTransitionOrder_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        {
            p->L_ACKLEVELTR = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

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

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


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

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

variable_types:
startAddress
int *

variable_types:
stream
int *


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

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


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

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

original_code:
int GradientProfile_UpperBitsNotSet(const GradientProfile* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_GRADIENT, 15);
    status = status && UpperBitsNotSet64(p->Q_GDIR, 1) ;
    status = status && UpperBitsNotSet64(p->G_A, 8) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && GradientProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int GradientProfile_UpperBitsNotSet(struct GradientProfile *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_GRADIENT, 15);
    status = status && UpperBitsNotSet64(p->Q_GDIR, 1) ;
    status = status && UpperBitsNotSet64(p->G_A, 8) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && GradientProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct GradientProfile { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; unsigned long N_ITER_1; struct GradientProfile_1 { unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; } sub_1[31]; } *

variable_types:
i
unsigned int

user_defined_types: struct GradientProfile { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; unsigned long N_ITER_1; struct GradientProfile_1 sub_1[31]; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 46LL) )
return 0xFFFFFFFFLL;
if ( !GradientProfile_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 1LL, a1[6]);
Bitstream_Write(a2, 8LL, a1[7]);
Bitstream_Write(a2, 5LL, a1[8]);
if ( !a1[8] )
return 1LL;
v2 = 0;
do
GradientProfile_1_EncodeBit(&a1[3 * v2++ + 9], a2);
while ( v2 < a1[8] );
return 1LL;
}

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

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

original_code:
int GradientProfile_EncodeBit(const GradientProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 46))
    {
        if (GradientProfile_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_GRADIENT);
            Bitstream_Write(stream, 1, p->Q_GDIR);
            Bitstream_Write(stream, 8, p->G_A);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                GradientProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int GradientProfile_EncodeBit(struct GradientProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 46))
    {
        if (GradientProfile_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_GRADIENT);
            Bitstream_Write(stream, 1, p->Q_GDIR);
            Bitstream_Write(stream, 8, p->G_A);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                GradientProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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

user_defined_types: struct GradientProfile_1 { unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; }


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

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

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

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

original_code:
int GradientProfile_DecodeBit(GradientProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 46))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_GRADIENT = Bitstream_Read(stream, 15);
        }
        {
            p->Q_GDIR = Bitstream_Read(stream, 1);
        }
        {
            p->G_A = Bitstream_Read(stream, 8);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            GradientProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int GradientProfile_DecodeBit(struct GradientProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 46))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_GRADIENT = Bitstream_Read(stream, 15);
        }
        {
            p->Q_GDIR = Bitstream_Read(stream, 1);
        }
        {
            p->G_A = Bitstream_Read(stream, 8);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            GradientProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int GradientProfile_EncodeInt(const GradientProfile* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 21;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->D_GRADIENT;
    stream[startAddress++] = p->Q_GDIR;
    stream[startAddress++] = p->G_A;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        GradientProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int GradientProfile_EncodeInt(struct GradientProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 21;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->D_GRADIENT;
    stream[startAddress++] = p->Q_GDIR;
    stream[startAddress++] = p->G_A;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        GradientProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

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

variable_types: startAddress int


original_code:
int GradientProfile_DecodeInt(GradientProfile* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 21)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->D_GRADIENT = stream[startAddress++];
    p->Q_GDIR = stream[startAddress++];
    p->G_A = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        GradientProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int GradientProfile_DecodeInt(struct GradientProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 21)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->D_GRADIENT = stream[startAddress++];
    p->Q_GDIR = stream[startAddress++];
    p->G_A = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        GradientProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

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


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

if ( GradientProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)GradientProfileMemoryTop > 7 )
return 0LL;
v0 = &GradientProfileMemory[102 * GradientProfileMemoryTop++];
}
else
{
v0 = &GradientProfileMemory[102 * GradientProfileMemoryFreeList];
GradientProfileMemoryFreeList = *v0;
}
GradientProfile_Init(v0);
return v0;
}

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

if ( GradientProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)GradientProfileMemoryTop > 7 )
return 0LL;
v0 = &GradientProfileMemory[102 * GradientProfileMemoryTop++];
}
else
{
v0 = &GradientProfileMemory[102 * GradientProfileMemoryFreeList];
GradientProfileMemoryFreeList = *v0;
}
func2(v0);
return v0;
}

original_code:
GradientProfile* GradientProfile_New(void)
{
    GradientProfile* ptr;
    if (GradientProfileMemoryFreeList != (-1))
    {
        ptr = &GradientProfileMemory[GradientProfileMemoryFreeList];
        GradientProfileMemoryFreeList = GradientProfileMemory[GradientProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (GradientProfileMemoryTop < 8)
    {
        ptr = &GradientProfileMemory[GradientProfileMemoryTop];
        GradientProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    GradientProfile_Init(ptr);
    return ptr;
}

canonical_original_code:
struct GradientProfile *GradientProfile_New()
{
    struct GradientProfile *ptr;
    if (GradientProfileMemoryFreeList != (-1))
    {
        ptr = &GradientProfileMemory[GradientProfileMemoryFreeList];
        GradientProfileMemoryFreeList = GradientProfileMemory[GradientProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (GradientProfileMemoryTop < 8)
    {
        ptr = &GradientProfileMemory[GradientProfileMemoryTop];
        GradientProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    GradientProfile_Init(ptr);
    return ptr;
}

return_type: struct GradientProfile { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; unsigned long N_ITER_1; struct GradientProfile_1 { unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; } sub_1[31]; } *


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

*(_QWORD *)a1 = GradientProfileMemoryFreeList;
result = 0xFAFAFAFAFAFAFAFBLL;
GradientProfileMemoryFreeList = 0xFAFAFAFAFAFAFAFBLL * ((a1 - (char *)GradientProfileMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = GradientProfileMemoryFreeList;
result = 0xFAFAFAFAFAFAFAFBLL;
GradientProfileMemoryFreeList = 0xFAFAFAFAFAFAFAFBLL * ((a1 - (char *)GradientProfileMemory) >> 4);
return result;
}

original_code:
void GradientProfile_Delete(GradientProfile* ptr)
{
    ptr->header.NID_PACKET = GradientProfileMemoryFreeList;
    GradientProfileMemoryFreeList = ptr - GradientProfileMemory;
}

canonical_original_code:
void GradientProfile_Delete(struct GradientProfile *ptr)
{
    ptr->header.NID_PACKET = GradientProfileMemoryFreeList;
    GradientProfileMemoryFreeList = ptr - GradientProfileMemory;
}


decompiled_code:
_BOOL8 __fastcall AxleLoadSpeedProfile_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned int i; // ebp
unsigned int j; // ebp

v1 = UpperBitsNotSet64(a1[2], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[3], 13);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[4], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[5], 1);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[6], 15);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[7], 15);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[8], 1);
if ( v1 )
v1 = UpperBitsNotSet64(a1[9], 5);
}
}
}
}
}
}
for ( i = 0; i < a1[9]; ++i )
{
if ( v1 )
v1 = AxleLoadSpeedProfile_1_UpperBitsNotSet(&a1[2 * i + 10]) != 0;
}
if ( v1 )
v1 = UpperBitsNotSet64(a1[72], 5);
for ( j = 0; j < a1[72]; ++j )
{
if ( v1 )
v1 = AxleLoadSpeedProfile_2_UpperBitsNotSet(&a1[66 * j + 73]) != 0;
}
return v1;
}

original_code:
int AxleLoadSpeedProfile_UpperBitsNotSet(const AxleLoadSpeedProfile* 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_TRACKINIT, 1) ;
    status = status && UpperBitsNotSet64(p->D_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->L_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && AxleLoadSpeedProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->N_ITER_2, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        status = status && AxleLoadSpeedProfile_2_UpperBitsNotSet(&(p->sub_2[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_UpperBitsNotSet(struct AxleLoadSpeedProfile *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_TRACKINIT, 1) ;
    status = status && UpperBitsNotSet64(p->D_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->L_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && AxleLoadSpeedProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->N_ITER_2, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        status = status && AxleLoadSpeedProfile_2_UpperBitsNotSet(&(p->sub_2[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct AxleLoadSpeedProfile { 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_TRACKINIT; unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_1; struct AxleLoadSpeedProfile_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_1[31]; unsigned long N_ITER_2; struct AxleLoadSpeedProfile_2 { unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct AxleLoadSpeedProfile_2_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_2_1[31]; } sub_2[31]; } *

user_defined_types: struct AxleLoadSpeedProfile { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_1; struct AxleLoadSpeedProfile_1 sub_1[31]; unsigned long N_ITER_2; struct AxleLoadSpeedProfile_2 sub_2[31]; }

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


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

if ( !(unsigned int)Bitstream_Normal(a2, 59LL) )
return 0xFFFFFFFFLL;
if ( !AxleLoadSpeedProfile_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, 1LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
Bitstream_Write(a2, 5LL, a1[9]);
if ( a1[9] )
{
v2 = 0;
do
AxleLoadSpeedProfile_1_EncodeBit(&a1[2 * v2++ + 10], a2);
while ( v2 < a1[9] );
}
Bitstream_Write(a2, 5LL, a1[72]);
if ( !a1[72] )
return 1LL;
v3 = 0;
do
AxleLoadSpeedProfile_2_EncodeBit(&a1[66 * v3++ + 73], a2);
while ( v3 < a1[72] );
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 59LL) )
return 0xFFFFFFFFLL;
if ( !func5(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, 15LL, a1[6]);
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
Bitstream_Write(a2, 5LL, a1[9]);
if ( a1[9] )
{
v2 = 0;
do
AxleLoadSpeedProfile_1_EncodeBit(&a1[2 * v2++ + 10], a2);
while ( v2 < a1[9] );
}
Bitstream_Write(a2, 5LL, a1[72]);
if ( !a1[72] )
return 1LL;
v3 = 0;
do
AxleLoadSpeedProfile_2_EncodeBit(&a1[66 * v3++ + 73], a2);
while ( v3 < a1[72] );
return 1LL;
}

original_code:
int AxleLoadSpeedProfile_EncodeBit(const AxleLoadSpeedProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 59))
    {
        if (AxleLoadSpeedProfile_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_TRACKINIT);
            Bitstream_Write(stream, 15, p->D_AXLELOAD);
            Bitstream_Write(stream, 15, p->L_AXLELOAD);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                AxleLoadSpeedProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 5, p->N_ITER_2);
            for (uint32_t i = 0; i < p->N_ITER_2; ++i)
            {
                AxleLoadSpeedProfile_2_EncodeBit(&(p->sub_2[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_EncodeBit(struct AxleLoadSpeedProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 59))
    {
        if (AxleLoadSpeedProfile_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_TRACKINIT);
            Bitstream_Write(stream, 15, p->D_AXLELOAD);
            Bitstream_Write(stream, 15, p->L_AXLELOAD);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                AxleLoadSpeedProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 5, p->N_ITER_2);
            for (unsigned int i = 0; i < p->N_ITER_2; ++i)
            {
                AxleLoadSpeedProfile_2_EncodeBit(&(p->sub_2[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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

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


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

result = Bitstream_Normal(a2, 59LL);
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, 15LL);
a1[7] = Bitstream_Read(a2, 15LL);
a1[8] = Bitstream_Read(a2, 1LL);
v3 = Bitstream_Read(a2, 5LL);
a1[9] = v3;
if ( v3 )
{
v4 = 0;
do
AxleLoadSpeedProfile_1_DecodeBit(&a1[2 * v4++ + 10], a2);
while ( (unsigned __int64)v4 < a1[9] );
}
v5 = Bitstream_Read(a2, 5LL);
a1[72] = v5;
if ( v5 )
{
v6 = 0;
do
AxleLoadSpeedProfile_2_DecodeBit(&a1[66 * v6++ + 73], a2);
while ( (unsigned __int64)v6 < a1[72] );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

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

result = Bitstream_Normal(a2, 59LL);
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, 15LL);
a1[7] = Bitstream_Read(a2, 15LL);
a1[8] = Bitstream_Read(a2, 1LL);
v3 = Bitstream_Read(a2, 5LL);
a1[9] = v3;
if ( v3 )
{
v4 = 0;
do
AxleLoadSpeedProfile_1_DecodeBit(&a1[2 * v4++ + 10], a2);
while ( (unsigned __int64)v4 < a1[9] );
}
v5 = Bitstream_Read(a2, 5LL);
a1[72] = v5;
if ( v5 )
{
v6 = 0;
do
AxleLoadSpeedProfile_2_DecodeBit(&a1[66 * v6++ + 73], a2);
while ( (unsigned __int64)v6 < a1[72] );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int AxleLoadSpeedProfile_DecodeBit(AxleLoadSpeedProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 59))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TRACKINIT = Bitstream_Read(stream, 1);
        }
        {
            p->D_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->L_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            AxleLoadSpeedProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
    {
            p->N_ITER_2 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_2; ++i)
        {
            AxleLoadSpeedProfile_2_DecodeBit(&(p->sub_2[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_DecodeBit(struct AxleLoadSpeedProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 59))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TRACKINIT = Bitstream_Read(stream, 1);
        }
        {
            p->D_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->L_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            AxleLoadSpeedProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
    {
            p->N_ITER_2 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_2; ++i)
        {
            AxleLoadSpeedProfile_2_DecodeBit(&(p->sub_2[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int AxleLoadSpeedProfile_EncodeInt(const AxleLoadSpeedProfile* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 51;
    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_TRACKINIT;
    stream[startAddress++] = p->D_AXLELOAD;
    stream[startAddress++] = p->L_AXLELOAD;
    stream[startAddress++] = p->Q_FRONT;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        AxleLoadSpeedProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    stream[startAddress++] = p->N_ITER_2;
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        AxleLoadSpeedProfile_2_EncodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int AxleLoadSpeedProfile_EncodeInt(struct AxleLoadSpeedProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 51;
    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_TRACKINIT;
    stream[startAddress++] = p->D_AXLELOAD;
    stream[startAddress++] = p->L_AXLELOAD;
    stream[startAddress++] = p->Q_FRONT;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        AxleLoadSpeedProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    stream[startAddress++] = p->N_ITER_2;
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        AxleLoadSpeedProfile_2_EncodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int AxleLoadSpeedProfile_DecodeInt(AxleLoadSpeedProfile* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 51)
    {
         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_TRACKINIT = stream[startAddress++];
    p->D_AXLELOAD = stream[startAddress++];
    p->L_AXLELOAD = stream[startAddress++];
    p->Q_FRONT = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        AxleLoadSpeedProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    p->N_ITER_2 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        AxleLoadSpeedProfile_2_DecodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int AxleLoadSpeedProfile_DecodeInt(struct AxleLoadSpeedProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 51)
    {
         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_TRACKINIT = stream[startAddress++];
    p->D_AXLELOAD = stream[startAddress++];
    p->L_AXLELOAD = stream[startAddress++];
    p->Q_FRONT = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        AxleLoadSpeedProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    p->N_ITER_2 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        AxleLoadSpeedProfile_2_DecodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( AxleLoadSpeedProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)AxleLoadSpeedProfileMemoryTop > 7 )
return 0LL;
v0 = &AxleLoadSpeedProfileMemory[2119 * AxleLoadSpeedProfileMemoryTop++];
}
else
{
v0 = &AxleLoadSpeedProfileMemory[2119 * AxleLoadSpeedProfileMemoryFreeList];
AxleLoadSpeedProfileMemoryFreeList = *v0;
}
AxleLoadSpeedProfile_Init(v0);
return v0;
}

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

if ( AxleLoadSpeedProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)AxleLoadSpeedProfileMemoryTop > 7 )
return 0LL;
v0 = &AxleLoadSpeedProfileMemory[2119 * AxleLoadSpeedProfileMemoryTop++];
}
else
{
v0 = &AxleLoadSpeedProfileMemory[2119 * AxleLoadSpeedProfileMemoryFreeList];
AxleLoadSpeedProfileMemoryFreeList = *v0;
}
func4(v0);
return v0;
}

original_code:
AxleLoadSpeedProfile* AxleLoadSpeedProfile_New(void)
{
    AxleLoadSpeedProfile* ptr;
    if (AxleLoadSpeedProfileMemoryFreeList != (-1))
    {
        ptr = &AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryFreeList];
        AxleLoadSpeedProfileMemoryFreeList = AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (AxleLoadSpeedProfileMemoryTop < 8)
    {
        ptr = &AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryTop];
        AxleLoadSpeedProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    AxleLoadSpeedProfile_Init(ptr);
    return ptr;
}

canonical_original_code:
struct AxleLoadSpeedProfile *AxleLoadSpeedProfile_New()
{
    struct AxleLoadSpeedProfile *ptr;
    if (AxleLoadSpeedProfileMemoryFreeList != (-1))
    {
        ptr = &AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryFreeList];
        AxleLoadSpeedProfileMemoryFreeList = AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (AxleLoadSpeedProfileMemoryTop < 8)
    {
        ptr = &AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryTop];
        AxleLoadSpeedProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    AxleLoadSpeedProfile_Init(ptr);
    return ptr;
}

return_type: struct AxleLoadSpeedProfile { 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_TRACKINIT; unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_1; struct AxleLoadSpeedProfile_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_1[31]; unsigned long N_ITER_2; struct AxleLoadSpeedProfile_2 { unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct AxleLoadSpeedProfile_2_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_2_1[31]; } sub_2[31]; } *


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

*a1 = AxleLoadSpeedProfileMemoryFreeList;
result = 0x8C432BDACA3D2177LL;
AxleLoadSpeedProfileMemoryFreeList = 0x8C432BDACA3D2177LL * (a1 - AxleLoadSpeedProfileMemory);
return result;
}

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

*a1 = AxleLoadSpeedProfileMemoryFreeList;
result = 0x8C432BDACA3D2177LL;
AxleLoadSpeedProfileMemoryFreeList = 0x8C432BDACA3D2177LL * (a1 - AxleLoadSpeedProfileMemory);
return result;
}

original_code:
void AxleLoadSpeedProfile_Delete(AxleLoadSpeedProfile* ptr)
{
    ptr->header.NID_PACKET = AxleLoadSpeedProfileMemoryFreeList;
    AxleLoadSpeedProfileMemoryFreeList = ptr - AxleLoadSpeedProfileMemory;
}

canonical_original_code:
void AxleLoadSpeedProfile_Delete(struct AxleLoadSpeedProfile *ptr)
{
    ptr->header.NID_PACKET = AxleLoadSpeedProfileMemoryFreeList;
    AxleLoadSpeedProfileMemoryFreeList = ptr - AxleLoadSpeedProfileMemory;
}


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

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

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

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

original_code:
int RBCTransitionOrder_UpperBitsNotSet(const RBCTransitionOrder* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_RBCTR, 15);
    status = status && UpperBitsNotSet64(p->NID_C, 10);
    status = status && UpperBitsNotSet64(p->NID_RBC, 14);
    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 RBCTransitionOrder_UpperBitsNotSet(struct RBCTransitionOrder *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_RBCTR, 15);
    status = status && UpperBitsNotSet64(p->NID_C, 10);
    status = status && UpperBitsNotSet64(p->NID_RBC, 14);
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    status = status && UpperBitsNotSet64(p->Q_SLEEPSESSION, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct RBCTransitionOrder { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_RBCTR; unsigned long NID_C; unsigned long NID_RBC; unsigned long NID_RADIO; unsigned long Q_SLEEPSESSION; } *

user_defined_types: struct RBCTransitionOrder { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_RBCTR; unsigned long NID_C; unsigned long NID_RBC; unsigned long NID_RADIO; unsigned long Q_SLEEPSESSION; }


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

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

original_code:
int RBCTransitionOrder_EncodeBit(const RBCTransitionOrder* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 121))
    {
        if (RBCTransitionOrder_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_RBCTR);
            Bitstream_Write(stream, 10, p->NID_C);
            Bitstream_Write(stream, 14, p->NID_RBC);
            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 RBCTransitionOrder_EncodeBit(struct RBCTransitionOrder *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 121))
    {
        if (RBCTransitionOrder_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_RBCTR);
            Bitstream_Write(stream, 10, p->NID_C);
            Bitstream_Write(stream, 14, p->NID_RBC);
            Bitstream_Write(stream, 64, p->NID_RADIO);
            Bitstream_Write(stream, 1, p->Q_SLEEPSESSION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

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

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

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

original_code:
int RBCTransitionOrder_DecodeBit(RBCTransitionOrder* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 121))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_RBCTR = Bitstream_Read(stream, 15);
        }
        {
            p->NID_C = Bitstream_Read(stream, 10);
        }
        {
            p->NID_RBC = Bitstream_Read(stream, 14);
        }
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        {
            p->Q_SLEEPSESSION = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RBCTransitionOrder_DecodeBit(struct RBCTransitionOrder *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 121))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_RBCTR = Bitstream_Read(stream, 15);
        }
        {
            p->NID_C = Bitstream_Read(stream, 10);
        }
        {
            p->NID_RBC = Bitstream_Read(stream, 14);
        }
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        {
            p->Q_SLEEPSESSION = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int RBCTransitionOrder_EncodeInt(const RBCTransitionOrder* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 131;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->D_RBCTR;
    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 RBCTransitionOrder_EncodeInt(struct RBCTransitionOrder *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 131;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->D_RBCTR;
    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;
}


original_code:
int RBCTransitionOrder_DecodeInt(RBCTransitionOrder* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 131)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->D_RBCTR = 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 RBCTransitionOrder_DecodeInt(struct RBCTransitionOrder *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 131)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->D_RBCTR = 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 *RBCTransitionOrder_New()
{
__int64 *v0; // rbx

if ( RBCTransitionOrderMemoryFreeList == -1 )
{
if ( (unsigned __int64)RBCTransitionOrderMemoryTop > 7 )
return 0LL;
v0 = &RBCTransitionOrderMemory[10 * RBCTransitionOrderMemoryTop++];
}
else
{
v0 = &RBCTransitionOrderMemory[10 * RBCTransitionOrderMemoryFreeList];
RBCTransitionOrderMemoryFreeList = *v0;
}
RBCTransitionOrder_Init(v0);
return v0;
}

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

if ( RBCTransitionOrderMemoryFreeList == -1 )
{
if ( (unsigned __int64)RBCTransitionOrderMemoryTop > 7 )
return 0LL;
v0 = &RBCTransitionOrderMemory[10 * RBCTransitionOrderMemoryTop++];
}
else
{
v0 = &RBCTransitionOrderMemory[10 * RBCTransitionOrderMemoryFreeList];
RBCTransitionOrderMemoryFreeList = *v0;
}
func1(v0);
return v0;
}

original_code:
RBCTransitionOrder* RBCTransitionOrder_New(void)
{
    RBCTransitionOrder* ptr;
    if (RBCTransitionOrderMemoryFreeList != (-1))
    {
        ptr = &RBCTransitionOrderMemory[RBCTransitionOrderMemoryFreeList];
        RBCTransitionOrderMemoryFreeList = RBCTransitionOrderMemory[RBCTransitionOrderMemoryFreeList].header.NID_PACKET;
    }
    else if (RBCTransitionOrderMemoryTop < 8)
    {
        ptr = &RBCTransitionOrderMemory[RBCTransitionOrderMemoryTop];
        RBCTransitionOrderMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RBCTransitionOrder_Init(ptr);
    return ptr;
}

canonical_original_code:
struct RBCTransitionOrder *RBCTransitionOrder_New()
{
    struct RBCTransitionOrder *ptr;
    if (RBCTransitionOrderMemoryFreeList != (-1))
    {
        ptr = &RBCTransitionOrderMemory[RBCTransitionOrderMemoryFreeList];
        RBCTransitionOrderMemoryFreeList = RBCTransitionOrderMemory[RBCTransitionOrderMemoryFreeList].header.NID_PACKET;
    }
    else if (RBCTransitionOrderMemoryTop < 8)
    {
        ptr = &RBCTransitionOrderMemory[RBCTransitionOrderMemoryTop];
        RBCTransitionOrderMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RBCTransitionOrder_Init(ptr);
    return ptr;
}

return_type: struct RBCTransitionOrder { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_RBCTR; unsigned long NID_C; unsigned long NID_RBC; unsigned long NID_RADIO; unsigned long Q_SLEEPSESSION; } *


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

*(_QWORD *)a1 = RBCTransitionOrderMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
RBCTransitionOrderMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL * ((a1 - (char *)RBCTransitionOrderMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = RBCTransitionOrderMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
RBCTransitionOrderMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL * ((a1 - (char *)RBCTransitionOrderMemory) >> 4);
return result;
}

original_code:
void RBCTransitionOrder_Delete(RBCTransitionOrder* ptr)
{
    ptr->header.NID_PACKET = RBCTransitionOrderMemoryFreeList;
    RBCTransitionOrderMemoryFreeList = ptr - RBCTransitionOrderMemory;
}

canonical_original_code:
void RBCTransitionOrder_Delete(struct RBCTransitionOrder *ptr)
{
    ptr->header.NID_PACKET = RBCTransitionOrderMemoryFreeList;
    RBCTransitionOrderMemoryFreeList = ptr - RBCTransitionOrderMemory;
}


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

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

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

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

original_code:
int MovementAuthorityRequestParameters_UpperBitsNotSet(const MovementAuthorityRequestParameters* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->T_MAR, 8) ;
    status = status && UpperBitsNotSet64(p->T_TIMEOUTRQST, 10);
    status = status && UpperBitsNotSet64(p->T_CYCRQST, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int MovementAuthorityRequestParameters_UpperBitsNotSet(struct MovementAuthorityRequestParameters *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->T_MAR, 8) ;
    status = status && UpperBitsNotSet64(p->T_TIMEOUTRQST, 10);
    status = status && UpperBitsNotSet64(p->T_CYCRQST, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct MovementAuthorityRequestParameters { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long T_MAR; unsigned long T_TIMEOUTRQST; unsigned long T_CYCRQST; } *

user_defined_types: struct MovementAuthorityRequestParameters { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long T_MAR; unsigned long T_TIMEOUTRQST; unsigned long T_CYCRQST; }


decompiled_code:
__int64 __fastcall MovementAuthorityRequestParameters_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 41LL) )
return 0xFFFFFFFFLL;
if ( !MovementAuthorityRequestParameters_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 8LL, a1[4]);
Bitstream_Write(a2, 10LL, a1[5]);
Bitstream_Write(a2, 8LL, a1[6]);
return 1LL;
}

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

original_code:
int MovementAuthorityRequestParameters_EncodeBit(const MovementAuthorityRequestParameters* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 41))
    {
        if (MovementAuthorityRequestParameters_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 8, p->T_MAR);
            Bitstream_Write(stream, 10, p->T_TIMEOUTRQST);
            Bitstream_Write(stream, 8, p->T_CYCRQST);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int MovementAuthorityRequestParameters_EncodeBit(struct MovementAuthorityRequestParameters *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 41))
    {
        if (MovementAuthorityRequestParameters_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 8, p->T_MAR);
            Bitstream_Write(stream, 10, p->T_TIMEOUTRQST);
            Bitstream_Write(stream, 8, p->T_CYCRQST);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

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

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

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

original_code:
int MovementAuthorityRequestParameters_DecodeBit(MovementAuthorityRequestParameters* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 41))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->T_MAR = Bitstream_Read(stream, 8);
        }
        {
            p->T_TIMEOUTRQST = Bitstream_Read(stream, 10);
        }
        {
            p->T_CYCRQST = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int MovementAuthorityRequestParameters_DecodeBit(struct MovementAuthorityRequestParameters *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 41))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->T_MAR = Bitstream_Read(stream, 8);
        }
        {
            p->T_TIMEOUTRQST = Bitstream_Read(stream, 10);
        }
        {
            p->T_CYCRQST = Bitstream_Read(stream, 8);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int MovementAuthorityRequestParameters_EncodeInt(const MovementAuthorityRequestParameters* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 57;
    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->T_MAR;
    stream[startAddress++] = p->T_TIMEOUTRQST;
    stream[startAddress++] = p->T_CYCRQST;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int MovementAuthorityRequestParameters_EncodeInt(struct MovementAuthorityRequestParameters *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 57;
    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->T_MAR;
    stream[startAddress++] = p->T_TIMEOUTRQST;
    stream[startAddress++] = p->T_CYCRQST;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int MovementAuthorityRequestParameters_DecodeInt(MovementAuthorityRequestParameters* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 57)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->T_MAR = stream[startAddress++];
    p->T_TIMEOUTRQST = stream[startAddress++];
    p->T_CYCRQST = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int MovementAuthorityRequestParameters_DecodeInt(struct MovementAuthorityRequestParameters *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 57)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->T_MAR = stream[startAddress++];
    p->T_TIMEOUTRQST = stream[startAddress++];
    p->T_CYCRQST = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( MovementAuthorityRequestParametersMemoryFreeList == -1 )
{
if ( (unsigned __int64)MovementAuthorityRequestParametersMemoryTop > 7 )
return 0LL;
v0 = &MovementAuthorityRequestParametersMemory[7 * MovementAuthorityRequestParametersMemoryTop++];
}
else
{
v0 = &MovementAuthorityRequestParametersMemory[7 * MovementAuthorityRequestParametersMemoryFreeList];
MovementAuthorityRequestParametersMemoryFreeList = *v0;
}
MovementAuthorityRequestParameters_Init(v0);
return v0;
}

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

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

original_code:
MovementAuthorityRequestParameters* MovementAuthorityRequestParameters_New(void)
{
    MovementAuthorityRequestParameters* ptr;
    if (MovementAuthorityRequestParametersMemoryFreeList != (-1))
    {
        ptr = &MovementAuthorityRequestParametersMemory[MovementAuthorityRequestParametersMemoryFreeList];
        MovementAuthorityRequestParametersMemoryFreeList = MovementAuthorityRequestParametersMemory[MovementAuthorityRequestParametersMemoryFreeList].header.NID_PACKET;
    }
    else if (MovementAuthorityRequestParametersMemoryTop < 8)
    {
        ptr = &MovementAuthorityRequestParametersMemory[MovementAuthorityRequestParametersMemoryTop];
        MovementAuthorityRequestParametersMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    MovementAuthorityRequestParameters_Init(ptr);
    return ptr;
}

canonical_original_code:
struct MovementAuthorityRequestParameters *MovementAuthorityRequestParameters_New()
{
    struct MovementAuthorityRequestParameters *ptr;
    if (MovementAuthorityRequestParametersMemoryFreeList != (-1))
    {
        ptr = &MovementAuthorityRequestParametersMemory[MovementAuthorityRequestParametersMemoryFreeList];
        MovementAuthorityRequestParametersMemoryFreeList = MovementAuthorityRequestParametersMemory[MovementAuthorityRequestParametersMemoryFreeList].header.NID_PACKET;
    }
    else if (MovementAuthorityRequestParametersMemoryTop < 8)
    {
        ptr = &MovementAuthorityRequestParametersMemory[MovementAuthorityRequestParametersMemoryTop];
        MovementAuthorityRequestParametersMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    MovementAuthorityRequestParameters_Init(ptr);
    return ptr;
}

return_type: struct MovementAuthorityRequestParameters { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long T_MAR; unsigned long T_TIMEOUTRQST; unsigned long T_CYCRQST; } *


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

*a1 = MovementAuthorityRequestParametersMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
MovementAuthorityRequestParametersMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL
* (a1 - MovementAuthorityRequestParametersMemory);
return result;
}

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

*a1 = MovementAuthorityRequestParametersMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
MovementAuthorityRequestParametersMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL
* (a1 - MovementAuthorityRequestParametersMemory);
return result;
}

original_code:
void MovementAuthorityRequestParameters_Delete(MovementAuthorityRequestParameters* ptr)
{
    ptr->header.NID_PACKET = MovementAuthorityRequestParametersMemoryFreeList;
    MovementAuthorityRequestParametersMemoryFreeList = ptr - MovementAuthorityRequestParametersMemory;
}

canonical_original_code:
void MovementAuthorityRequestParameters_Delete(struct MovementAuthorityRequestParameters *ptr)
{
    ptr->header.NID_PACKET = MovementAuthorityRequestParametersMemoryFreeList;
    MovementAuthorityRequestParametersMemoryFreeList = ptr - MovementAuthorityRequestParametersMemory;
}


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

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

original_code:
int National_Values_Core_1_Encode_Bit(Bitstream* stream, const National_Values_Core_1* p)
{
    if (Bitstream_Normal(stream, 10))
    {
        if (National_Values_Core_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 10, p->NID_C);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int National_Values_Core_1_Encode_Bit(struct Bitstream *stream, struct National_Values_Core_1 *p)
{
    if (Bitstream_Normal(stream, 10))
    {
        if (National_Values_Core_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 10, p->NID_C);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

variable_types: struct National_Values_Core_1 { unsigned long NID_C; } *


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

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

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

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

original_code:
int National_Values_Core_1_Decode_Bit(Bitstream* stream, National_Values_Core_1* p)
{
    if (Bitstream_Normal(stream, 10))
    {
        {
            p->NID_C = Bitstream_Read(stream, 10);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int National_Values_Core_1_Decode_Bit(struct Bitstream *stream, struct National_Values_Core_1 *p)
{
    if (Bitstream_Normal(stream, 10))
    {
        {
            p->NID_C = Bitstream_Read(stream, 10);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

user_defined_types: struct National_Values_Core_1 { unsigned long NID_C; }


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

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

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

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


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

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

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

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


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

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

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

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

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

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


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

result = UpperBitsNotSet64(a1[2], 2);
if ( !result )
{
if ( a1[9] != 1 )
return result;
LABEL_10:
if ( !result )
return result;
result = UpperBitsNotSet64(a1[10], 8);
if ( !result )
return result;
goto LABEL_18;
}
if ( UpperBitsNotSet64(a1[3], 13)
&& UpperBitsNotSet64(a1[4], 2)
&& UpperBitsNotSet64(a1[5], 2)
&& UpperBitsNotSet64(a1[6], 1) )
{
result = UpperBitsNotSet64(a1[7], 15);
if ( result )
{
result = UpperBitsNotSet64(a1[8], 4);
if ( result )
result = UpperBitsNotSet64(a1[9], 3);
}
if ( a1[9] == 1 )
goto LABEL_10;
}
else
{
result = 0LL;
if ( a1[9] == 1 )
return result;
}
if ( !result )
return result;
LABEL_18:
result = UpperBitsNotSet64(a1[11], 15);
if ( result )
{
result = UpperBitsNotSet64(a1[12], 10);
if ( result )
{
result = UpperBitsNotSet64(a1[13], 4);
if ( result )
{
v2 = a1[14];
result = UpperBitsNotSet64(v2, 3);
if ( v2 == 1 )
{
if ( !result )
return result;
result = UpperBitsNotSet64(a1[15], 8);
if ( !result )
return result;
}
else if ( !result )
{
return result;
}
result = UpperBitsNotSet64(a1[16], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[17], 8);
if ( result )
result = UpperBitsNotSet64(a1[18], 8);
}
}
}
}
return result;
}

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

result = func0(a1[2], 2);
if ( !result )
{
if ( a1[9] != 1 )
return result;
LABEL_10:
if ( !result )
return result;
result = func0(a1[10], 8);
if ( !result )
return result;
goto LABEL_18;
}
if ( func0(a1[3], 13)
&& func0(a1[4], 2)
&& func0(a1[5], 2)
&& func0(a1[6], 1) )
{
result = func0(a1[7], 15);
if ( result )
{
result = func0(a1[8], 4);
if ( result )
result = func0(a1[9], 3);
}
if ( a1[9] == 1 )
goto LABEL_10;
}
else
{
result = 0LL;
if ( a1[9] == 1 )
return result;
}
if ( !result )
return result;
LABEL_18:
result = func0(a1[11], 15);
if ( result )
{
result = func0(a1[12], 10);
if ( result )
{
result = func0(a1[13], 4);
if ( result )
{
v2 = a1[14];
result = func0(v2, 3);
if ( v2 == 1 )
{
if ( !result )
return result;
result = func0(a1[15], 8);
if ( !result )
return result;
}
else if ( !result )
{
return result;
}
result = func0(a1[16], 2);
if ( result )
{
result = func0(a1[17], 8);
if ( result )
result = func0(a1[18], 8);
}
}
}
}
return result;
}

original_code:
int PacketForSendingPlainTextMessages_UpperBitsNotSet(const PacketForSendingPlainTextMessages* 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_TEXTCLASS, 2) ;
    status = status && UpperBitsNotSet64(p->Q_TEXTDISPLAY, 1) ;
    status = status && UpperBitsNotSet64(p->D_TEXTDISPLAY, 15);
    status = status && UpperBitsNotSet64(p->M_MODETEXTDISPLAY_0, 4) ;
    status = status && UpperBitsNotSet64(p->M_LEVELTEXTDISPLAY_0, 3) ;
    if (p->M_LEVELTEXTDISPLAY_0 == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM_0, 8) ;
    }
    status = status && UpperBitsNotSet64(p->L_TEXTDISPLAY, 15);
    status = status && UpperBitsNotSet64(p->T_TEXTDISPLAY, 10);
    status = status && UpperBitsNotSet64(p->M_MODETEXTDISPLAY_1, 4) ;
    status = status && UpperBitsNotSet64(p->M_LEVELTEXTDISPLAY_1, 3) ;
    if (p->M_LEVELTEXTDISPLAY_1 == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM_1, 8) ;
    }
    status = status && UpperBitsNotSet64(p->Q_TEXTCONFIRM, 2) ;
    status = status && UpperBitsNotSet64(p->L_TEXT, 8) ;
    status = status && UpperBitsNotSet64(p->X_TEXT, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int PacketForSendingPlainTextMessages_UpperBitsNotSet(struct PacketForSendingPlainTextMessages *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_TEXTCLASS, 2) ;
    status = status && UpperBitsNotSet64(p->Q_TEXTDISPLAY, 1) ;
    status = status && UpperBitsNotSet64(p->D_TEXTDISPLAY, 15);
    status = status && UpperBitsNotSet64(p->M_MODETEXTDISPLAY_0, 4) ;
    status = status && UpperBitsNotSet64(p->M_LEVELTEXTDISPLAY_0, 3) ;
    if (p->M_LEVELTEXTDISPLAY_0 == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM_0, 8) ;
    }
    status = status && UpperBitsNotSet64(p->L_TEXTDISPLAY, 15);
    status = status && UpperBitsNotSet64(p->T_TEXTDISPLAY, 10);
    status = status && UpperBitsNotSet64(p->M_MODETEXTDISPLAY_1, 4) ;
    status = status && UpperBitsNotSet64(p->M_LEVELTEXTDISPLAY_1, 3) ;
    if (p->M_LEVELTEXTDISPLAY_1 == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM_1, 8) ;
    }
    status = status && UpperBitsNotSet64(p->Q_TEXTCONFIRM, 2) ;
    status = status && UpperBitsNotSet64(p->L_TEXT, 8) ;
    status = status && UpperBitsNotSet64(p->X_TEXT, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct PacketForSendingPlainTextMessages { 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_TEXTCLASS; unsigned long Q_TEXTDISPLAY; unsigned long D_TEXTDISPLAY; unsigned long M_MODETEXTDISPLAY_0; unsigned long M_LEVELTEXTDISPLAY_0; unsigned long NID_STM_0; unsigned long L_TEXTDISPLAY; unsigned long T_TEXTDISPLAY; unsigned long M_MODETEXTDISPLAY_1; unsigned long M_LEVELTEXTDISPLAY_1; unsigned long NID_STM_1; unsigned long Q_TEXTCONFIRM; unsigned long L_TEXT; unsigned long X_TEXT; } *

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


decompiled_code:
__int64 __fastcall PacketForSendingPlainTextMessages_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 92LL) )
return 0xFFFFFFFFLL;
if ( !PacketForSendingPlainTextMessages_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, 2LL, a1[5]);
Bitstream_Write(a2, 1LL, a1[6]);
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 4LL, a1[8]);
Bitstream_Write(a2, 3LL, a1[9]);
if ( a1[9] == 1 )
Bitstream_Write(a2, 8LL, a1[10]);
Bitstream_Write(a2, 15LL, a1[11]);
Bitstream_Write(a2, 10LL, a1[12]);
Bitstream_Write(a2, 4LL, a1[13]);
Bitstream_Write(a2, 3LL, a1[14]);
if ( a1[14] == 1 )
Bitstream_Write(a2, 8LL, a1[15]);
Bitstream_Write(a2, 2LL, a1[16]);
Bitstream_Write(a2, 8LL, a1[17]);
Bitstream_Write(a2, 8LL, a1[18]);
return 1LL;
}

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

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

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


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

result = Bitstream_Normal(a2, 92LL);
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, 2LL);
a1[6] = Bitstream_Read(a2, 1LL);
a1[7] = Bitstream_Read(a2, 15LL);
a1[8] = Bitstream_Read(a2, 4LL);
v3 = Bitstream_Read(a2, 3LL);
a1[9] = v3;
if ( v3 == 1 )
a1[10] = Bitstream_Read(a2, 8LL);
a1[11] = Bitstream_Read(a2, 15LL);
a1[12] = Bitstream_Read(a2, 10LL);
a1[13] = Bitstream_Read(a2, 4LL);
v4 = Bitstream_Read(a2, 3LL);
a1[14] = v4;
if ( v4 == 1 )
a1[15] = Bitstream_Read(a2, 8LL);
a1[16] = Bitstream_Read(a2, 2LL);
a1[17] = Bitstream_Read(a2, 8LL);
a1[18] = Bitstream_Read(a2, 8LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 92LL);
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, 2LL);
a1[6] = Bitstream_Read(a2, 1LL);
a1[7] = Bitstream_Read(a2, 15LL);
a1[8] = Bitstream_Read(a2, 4LL);
v3 = Bitstream_Read(a2, 3LL);
a1[9] = v3;
if ( v3 == 1 )
a1[10] = Bitstream_Read(a2, 8LL);
a1[11] = Bitstream_Read(a2, 15LL);
a1[12] = Bitstream_Read(a2, 10LL);
a1[13] = Bitstream_Read(a2, 4LL);
v4 = Bitstream_Read(a2, 3LL);
a1[14] = v4;
if ( v4 == 1 )
a1[15] = Bitstream_Read(a2, 8LL);
a1[16] = Bitstream_Read(a2, 2LL);
a1[17] = Bitstream_Read(a2, 8LL);
a1[18] = Bitstream_Read(a2, 8LL);
result = 1LL;
}
return result;
}

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

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