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

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

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

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

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

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


repo: openETCS/dataDictionary

original_code:
int TrackAheadFreeUpToLevel23TransitionLocation_EncodeInt(const TrackAheadFreeUpToLevel23TransitionLocation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 90;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_NEWCOUNTRY;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_BG;
    data->endAddress = startAddress-1;
    return 1;
}

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

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

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

variable_types:
stream
int *

variable_types: startAddress int

return_type: int

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


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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

return_type: void


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

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

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

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

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

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

variable_types:
value
unsigned long

variable_types:
length
unsigned int

variable_types:
MaxValue
unsigned long


decompiled_code:
_BOOL8 __fastcall RadioInfillAreaInformation_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], 1);
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], 15);
if ( result )
{
result = UpperBitsNotSet64(a1[10], 10);
if ( result )
result = UpperBitsNotSet64(a1[11], 14);
}
}
}
}
}
}
}
}
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], 1);
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], 15);
if ( result )
{
result = func0(a1[10], 10);
if ( result )
result = func0(a1[11], 14);
}
}
}
}
}
}
}
}
return result;
}

original_code:
int RadioInfillAreaInformation_UpperBitsNotSet(const RadioInfillAreaInformation* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->Q_RIU, 1) ;
    status = status && UpperBitsNotSet64(p->NID_C_0, 10);
    status = status && UpperBitsNotSet64(p->NID_RIU, 14);
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    status = status && UpperBitsNotSet64(p->D_INFILL, 15);
    status = status && UpperBitsNotSet64(p->NID_C_1, 10);
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RadioInfillAreaInformation_UpperBitsNotSet(struct RadioInfillAreaInformation *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->Q_RIU, 1) ;
    status = status && UpperBitsNotSet64(p->NID_C_0, 10);
    status = status && UpperBitsNotSet64(p->NID_RIU, 14);
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    status = status && UpperBitsNotSet64(p->D_INFILL, 15);
    status = status && UpperBitsNotSet64(p->NID_C_1, 10);
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

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

variable_types: status int

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


decompiled_code:
__int64 __fastcall RadioInfillAreaInformation_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 145LL) )
return 0xFFFFFFFFLL;
if ( !RadioInfillAreaInformation_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, 10LL, a1[6]);
Bitstream_Write(a2, 14LL, a1[7]);
Bitstream_Write(a2, 64LL, a1[8]);
Bitstream_Write(a2, 15LL, a1[9]);
Bitstream_Write(a2, 10LL, a1[10]);
Bitstream_Write(a2, 14LL, a1[11]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 145LL) )
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, 1LL, a1[5]);
Bitstream_Write(a2, 10LL, a1[6]);
Bitstream_Write(a2, 14LL, a1[7]);
Bitstream_Write(a2, 64LL, a1[8]);
Bitstream_Write(a2, 15LL, a1[9]);
Bitstream_Write(a2, 10LL, a1[10]);
Bitstream_Write(a2, 14LL, a1[11]);
return 1LL;
}

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

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

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


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

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

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

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

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

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

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


original_code:
int RadioInfillAreaInformation_EncodeInt(const RadioInfillAreaInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 133;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->Q_RIU;
    stream[startAddress++] = p->NID_C_0;
    stream[startAddress++] = p->NID_RIU;
    stream[startAddress++] = p->NID_RADIO;
    stream[startAddress++] = p->D_INFILL;
    stream[startAddress++] = p->NID_C_1;
    stream[startAddress++] = p->NID_BG;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int RadioInfillAreaInformation_EncodeInt(struct RadioInfillAreaInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 133;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->Q_RIU;
    stream[startAddress++] = p->NID_C_0;
    stream[startAddress++] = p->NID_RIU;
    stream[startAddress++] = p->NID_RADIO;
    stream[startAddress++] = p->D_INFILL;
    stream[startAddress++] = p->NID_C_1;
    stream[startAddress++] = p->NID_BG;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int RadioInfillAreaInformation_DecodeInt(RadioInfillAreaInformation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 133)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->Q_RIU = stream[startAddress++];
    p->NID_C_0 = stream[startAddress++];
    p->NID_RIU = stream[startAddress++];
    p->NID_RADIO = stream[startAddress++];
    p->D_INFILL = stream[startAddress++];
    p->NID_C_1 = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int RadioInfillAreaInformation_DecodeInt(struct RadioInfillAreaInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 133)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->Q_RIU = stream[startAddress++];
    p->NID_C_0 = stream[startAddress++];
    p->NID_RIU = stream[startAddress++];
    p->NID_RADIO = stream[startAddress++];
    p->D_INFILL = stream[startAddress++];
    p->NID_C_1 = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

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


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

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

variable_types:
startAddress
int *


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

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


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

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

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

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

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


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

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

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

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

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

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

user_defined_types: struct Packet_for_sending_fixed_text_messages_Core { unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TEXTCLASS; unsigned long Q_TEXTDISPLAY; unsigned long D_TEXTDISPLAY; unsigned long M_MODETEXTDISPLAY_0; unsigned long M_LEVELTEXTDISPLAY_0; unsigned long NID_STM_0; unsigned long L_TEXTDISPLAY; unsigned long T_TEXTDISPLAY; unsigned long M_MODETEXTDISPLAY_1; unsigned long M_LEVELTEXTDISPLAY_1; unsigned long NID_STM_1; unsigned long Q_TEXTCONFIRM; unsigned long Q_TEXT; }


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

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


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

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


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

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

canonical_decompiled_code:
_BOOL8 __fastcall func3(unsigned __int64 *a1)
{
_BOOL8 result; // rax
unsigned int v2; // ebx

if ( !func0(a1[2], 2) || !func0(a1[3], 13) )
{
result = 0LL;
if ( !a1[8] )
return result;
goto LABEL_28;
}
if ( !func0(a1[4], 2)
|| !func0(a1[5], 7)
|| !func0(a1[6], 7)
|| !func0(a1[7], 10) )
{
result = 0LL;
if ( !a1[8] )
return result;
goto LABEL_28;
}
result = func0(a1[8], 5);
if ( a1[8] )
{
LABEL_28:
v2 = 0;
do
{
if ( result )
result = (unsigned int)Level1MovementAuthority_1_UpperBitsNotSet(&a1[4 * v2 + 9]) != 0;
++v2;
}
while ( v2 < a1[8] );
}
if ( result )
{
result = func0(a1[133], 15);
if ( result )
{
result = func0(a1[134], 1);
if ( result )
{
result = func0(a1[135], 10);
if ( result )
{
result = func0(a1[136], 15);
if ( result )
{
result = func0(a1[137], 1);
if ( result )
{
result = func0(a1[138], 10);
if ( result )
{
result = func0(a1[139], 15);
if ( result )
{
result = func0(a1[140], 1);
if ( result )
{
result = func0(a1[141], 15);
if ( result )
{
result = func0(a1[142], 7);
if ( result )
{
result = func0(a1[143], 1);
if ( result )
{
result = func0(a1[144], 15);
if ( result )
{
result = func0(a1[145], 10);
if ( result )
{
result = func0(a1[146], 15);
if ( result )
result = func0(a1[147], 7);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

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

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

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

variable_types:
i
unsigned int

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


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

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

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

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

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

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

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


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

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

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

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

original_code:
int Level1MovementAuthority_DecodeBit(Level1MovementAuthority* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 184))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->V_MAIN = Bitstream_Read(stream, 7);
        }
        {
            p->V_LOA = Bitstream_Read(stream, 7);
        }
        {
            p->T_LOA = Bitstream_Read(stream, 10);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            Level1MovementAuthority_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        {
            p->L_ENDSECTION = Bitstream_Read(stream, 15);
        }
        {
            p->Q_SECTIONTIMER = Bitstream_Read(stream, 1);
        }
        {
            p->T_SECTIONTIMER = Bitstream_Read(stream, 10);
        }
        {
            p->D_SECTIONTIMERSTOPLOC = Bitstream_Read(stream, 15);
        }
        {
            p->Q_ENDTIMER = Bitstream_Read(stream, 1);
        }
        {
            p->T_ENDTIMER = Bitstream_Read(stream, 10);
        }
        {
            p->D_ENDTIMERSTARTLOC = Bitstream_Read(stream, 15);
        }
        {
            p->Q_DANGERPOINT = Bitstream_Read(stream, 1);
        }
        {
            p->D_DP = Bitstream_Read(stream, 15);
        }
        {
            p->V_RELEASEDP = Bitstream_Read(stream, 7);
        }
        {
            p->Q_OVERLAP = Bitstream_Read(stream, 1);
        }
        {
            p->D_STARTOL = Bitstream_Read(stream, 15);
        }
        {
            p->T_OL = Bitstream_Read(stream, 10);
        }
        {
            p->D_OL = Bitstream_Read(stream, 15);
        }
        {
            p->V_RELEASEOL = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Level1MovementAuthority_DecodeBit(struct Level1MovementAuthority *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 184))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->V_MAIN = Bitstream_Read(stream, 7);
        }
        {
            p->V_LOA = Bitstream_Read(stream, 7);
        }
        {
            p->T_LOA = Bitstream_Read(stream, 10);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            Level1MovementAuthority_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        {
            p->L_ENDSECTION = Bitstream_Read(stream, 15);
        }
        {
            p->Q_SECTIONTIMER = Bitstream_Read(stream, 1);
        }
        {
            p->T_SECTIONTIMER = Bitstream_Read(stream, 10);
        }
        {
            p->D_SECTIONTIMERSTOPLOC = Bitstream_Read(stream, 15);
        }
        {
            p->Q_ENDTIMER = Bitstream_Read(stream, 1);
        }
        {
            p->T_ENDTIMER = Bitstream_Read(stream, 10);
        }
        {
            p->D_ENDTIMERSTARTLOC = Bitstream_Read(stream, 15);
        }
        {
            p->Q_DANGERPOINT = Bitstream_Read(stream, 1);
        }
        {
            p->D_DP = Bitstream_Read(stream, 15);
        }
        {
            p->V_RELEASEDP = Bitstream_Read(stream, 7);
        }
        {
            p->Q_OVERLAP = Bitstream_Read(stream, 1);
        }
        {
            p->D_STARTOL = Bitstream_Read(stream, 15);
        }
        {
            p->T_OL = Bitstream_Read(stream, 10);
        }
        {
            p->D_OL = Bitstream_Read(stream, 15);
        }
        {
            p->V_RELEASEOL = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int Level1MovementAuthority_EncodeInt(const Level1MovementAuthority* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 12;
    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->V_MAIN;
    stream[startAddress++] = p->V_LOA;
    stream[startAddress++] = p->T_LOA;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        Level1MovementAuthority_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    stream[startAddress++] = p->L_ENDSECTION;
    stream[startAddress++] = p->Q_SECTIONTIMER;
    stream[startAddress++] = p->T_SECTIONTIMER;
    stream[startAddress++] = p->D_SECTIONTIMERSTOPLOC;
    stream[startAddress++] = p->Q_ENDTIMER;
    stream[startAddress++] = p->T_ENDTIMER;
    stream[startAddress++] = p->D_ENDTIMERSTARTLOC;
    stream[startAddress++] = p->Q_DANGERPOINT;
    stream[startAddress++] = p->D_DP;
    stream[startAddress++] = p->V_RELEASEDP;
    stream[startAddress++] = p->Q_OVERLAP;
    stream[startAddress++] = p->D_STARTOL;
    stream[startAddress++] = p->T_OL;
    stream[startAddress++] = p->D_OL;
    stream[startAddress++] = p->V_RELEASEOL;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int Level1MovementAuthority_EncodeInt(struct Level1MovementAuthority *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 12;
    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->V_MAIN;
    stream[startAddress++] = p->V_LOA;
    stream[startAddress++] = p->T_LOA;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        Level1MovementAuthority_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    stream[startAddress++] = p->L_ENDSECTION;
    stream[startAddress++] = p->Q_SECTIONTIMER;
    stream[startAddress++] = p->T_SECTIONTIMER;
    stream[startAddress++] = p->D_SECTIONTIMERSTOPLOC;
    stream[startAddress++] = p->Q_ENDTIMER;
    stream[startAddress++] = p->T_ENDTIMER;
    stream[startAddress++] = p->D_ENDTIMERSTARTLOC;
    stream[startAddress++] = p->Q_DANGERPOINT;
    stream[startAddress++] = p->D_DP;
    stream[startAddress++] = p->V_RELEASEDP;
    stream[startAddress++] = p->Q_OVERLAP;
    stream[startAddress++] = p->D_STARTOL;
    stream[startAddress++] = p->T_OL;
    stream[startAddress++] = p->D_OL;
    stream[startAddress++] = p->V_RELEASEOL;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int Level1MovementAuthority_DecodeInt(Level1MovementAuthority* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 12)
    {
         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->V_MAIN = stream[startAddress++];
    p->V_LOA = stream[startAddress++];
    p->T_LOA = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        Level1MovementAuthority_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    p->L_ENDSECTION = stream[startAddress++];
    p->Q_SECTIONTIMER = stream[startAddress++];
    p->T_SECTIONTIMER = stream[startAddress++];
    p->D_SECTIONTIMERSTOPLOC = stream[startAddress++];
    p->Q_ENDTIMER = stream[startAddress++];
    p->T_ENDTIMER = stream[startAddress++];
    p->D_ENDTIMERSTARTLOC = stream[startAddress++];
    p->Q_DANGERPOINT = stream[startAddress++];
    p->D_DP = stream[startAddress++];
    p->V_RELEASEDP = stream[startAddress++];
    p->Q_OVERLAP = stream[startAddress++];
    p->D_STARTOL = stream[startAddress++];
    p->T_OL = stream[startAddress++];
    p->D_OL = stream[startAddress++];
    p->V_RELEASEOL = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int Level1MovementAuthority_DecodeInt(struct Level1MovementAuthority *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 12)
    {
         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->V_MAIN = stream[startAddress++];
    p->V_LOA = stream[startAddress++];
    p->T_LOA = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        Level1MovementAuthority_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    p->L_ENDSECTION = stream[startAddress++];
    p->Q_SECTIONTIMER = stream[startAddress++];
    p->T_SECTIONTIMER = stream[startAddress++];
    p->D_SECTIONTIMERSTOPLOC = stream[startAddress++];
    p->Q_ENDTIMER = stream[startAddress++];
    p->T_ENDTIMER = stream[startAddress++];
    p->D_ENDTIMERSTARTLOC = stream[startAddress++];
    p->Q_DANGERPOINT = stream[startAddress++];
    p->D_DP = stream[startAddress++];
    p->V_RELEASEDP = stream[startAddress++];
    p->Q_OVERLAP = stream[startAddress++];
    p->D_STARTOL = stream[startAddress++];
    p->T_OL = stream[startAddress++];
    p->D_OL = stream[startAddress++];
    p->V_RELEASEOL = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( Level1MovementAuthorityMemoryFreeList == -1 )
{
if ( (unsigned __int64)Level1MovementAuthorityMemoryTop > 7 )
return 0LL;
v0 = &Level1MovementAuthorityMemory[148 * Level1MovementAuthorityMemoryTop++];
}
else
{
v0 = &Level1MovementAuthorityMemory[148 * Level1MovementAuthorityMemoryFreeList];
Level1MovementAuthorityMemoryFreeList = *v0;
}
Level1MovementAuthority_Init(v0);
return v0;
}

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

if ( Level1MovementAuthorityMemoryFreeList == -1 )
{
if ( (unsigned __int64)Level1MovementAuthorityMemoryTop > 7 )
return 0LL;
v0 = &Level1MovementAuthorityMemory[148 * Level1MovementAuthorityMemoryTop++];
}
else
{
v0 = &Level1MovementAuthorityMemory[148 * Level1MovementAuthorityMemoryFreeList];
Level1MovementAuthorityMemoryFreeList = *v0;
}
func2(v0);
return v0;
}

original_code:
Level1MovementAuthority* Level1MovementAuthority_New(void)
{
    Level1MovementAuthority* ptr;
    if (Level1MovementAuthorityMemoryFreeList != (-1))
    {
        ptr = &Level1MovementAuthorityMemory[Level1MovementAuthorityMemoryFreeList];
        Level1MovementAuthorityMemoryFreeList = Level1MovementAuthorityMemory[Level1MovementAuthorityMemoryFreeList].header.NID_PACKET;
    }
    else if (Level1MovementAuthorityMemoryTop < 8)
    {
        ptr = &Level1MovementAuthorityMemory[Level1MovementAuthorityMemoryTop];
        Level1MovementAuthorityMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    Level1MovementAuthority_Init(ptr);
    return ptr;
}

canonical_original_code:
struct Level1MovementAuthority *Level1MovementAuthority_New()
{
    struct Level1MovementAuthority *ptr;
    if (Level1MovementAuthorityMemoryFreeList != (-1))
    {
        ptr = &Level1MovementAuthorityMemory[Level1MovementAuthorityMemoryFreeList];
        Level1MovementAuthorityMemoryFreeList = Level1MovementAuthorityMemory[Level1MovementAuthorityMemoryFreeList].header.NID_PACKET;
    }
    else if (Level1MovementAuthorityMemoryTop < 8)
    {
        ptr = &Level1MovementAuthorityMemory[Level1MovementAuthorityMemoryTop];
        Level1MovementAuthorityMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    Level1MovementAuthority_Init(ptr);
    return ptr;
}

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


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

*(_QWORD *)a1 = Level1MovementAuthorityMemoryFreeList;
result = 0x14C1BACF914C1BADLL;
Level1MovementAuthorityMemoryFreeList = 0x14C1BACF914C1BADLL * ((a1 - (char *)Level1MovementAuthorityMemory) >> 5);
return result;
}

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

*(_QWORD *)a1 = Level1MovementAuthorityMemoryFreeList;
result = 0x14C1BACF914C1BADLL;
Level1MovementAuthorityMemoryFreeList = 0x14C1BACF914C1BADLL * ((a1 - (char *)Level1MovementAuthorityMemory) >> 5);
return result;
}

original_code:
void Level1MovementAuthority_Delete(Level1MovementAuthority* ptr)
{
    ptr->header.NID_PACKET = Level1MovementAuthorityMemoryFreeList;
    Level1MovementAuthorityMemoryFreeList = ptr - Level1MovementAuthorityMemory;
}

canonical_original_code:
void Level1MovementAuthority_Delete(struct Level1MovementAuthority *ptr)
{
    ptr->header.NID_PACKET = Level1MovementAuthorityMemoryFreeList;
    Level1MovementAuthorityMemoryFreeList = ptr - Level1MovementAuthorityMemory;
}


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

result = UpperBitsNotSet64(a1[2], 13);
if ( !result )
{
if ( a1[10] - 1 > 1 )
return result;
LABEL_23:
if ( !result )
return result;
result = UpperBitsNotSet64(a1[11], 15);
if ( !result )
return result;
goto LABEL_16;
}
if ( UpperBitsNotSet64(a1[3], 2)
&& UpperBitsNotSet64(a1[4], 24)
&& UpperBitsNotSet64(a1[5], 15)
&& UpperBitsNotSet64(a1[6], 2)
&& UpperBitsNotSet64(a1[7], 2)
&& UpperBitsNotSet64(a1[8], 15) )
{
result = UpperBitsNotSet64(a1[9], 15);
if ( result )
result = UpperBitsNotSet64(a1[10], 2);
if ( a1[10] - 1 <= 1 )
goto LABEL_23;
}
else
{
result = 0LL;
if ( a1[10] - 1 <= 1 )
return result;
}
if ( !result )
return result;
LABEL_16:
result = UpperBitsNotSet64(a1[12], 7);
if ( result )
{
result = UpperBitsNotSet64(a1[13], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[14], 4);
if ( result )
{
v2 = a1[15];
result = UpperBitsNotSet64(v2, 3);
if ( v2 == 1 )
{
if ( result )
result = UpperBitsNotSet64(a1[16], 8);
}
else
{
result = result;
}
}
}
}
return result;
}

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

result = func0(a1[2], 13);
if ( !result )
{
if ( a1[10] - 1 > 1 )
return result;
LABEL_23:
if ( !result )
return result;
result = func0(a1[11], 15);
if ( !result )
return result;
goto LABEL_16;
}
if ( func0(a1[3], 2)
&& func0(a1[4], 24)
&& func0(a1[5], 15)
&& func0(a1[6], 2)
&& func0(a1[7], 2)
&& func0(a1[8], 15) )
{
result = func0(a1[9], 15);
if ( result )
result = func0(a1[10], 2);
if ( a1[10] - 1 <= 1 )
goto LABEL_23;
}
else
{
result = 0LL;
if ( a1[10] - 1 <= 1 )
return result;
}
if ( !result )
return result;
LABEL_16:
result = func0(a1[12], 7);
if ( result )
{
result = func0(a1[13], 2);
if ( result )
{
result = func0(a1[14], 4);
if ( result )
{
v2 = a1[15];
result = func0(v2, 3);
if ( v2 == 1 )
{
if ( result )
result = func0(a1[16], 8);
}
else
{
result = result;
}
}
}
}
return result;
}

original_code:
int PositionReport_UpperBitsNotSet(const PositionReport* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->NID_LRBG, 24);
    status = status && UpperBitsNotSet64(p->D_LRBG, 15);
    status = status && UpperBitsNotSet64(p->Q_DIRLRBG, 2) ;
    status = status && UpperBitsNotSet64(p->Q_DLRBG, 2) ;
    status = status && UpperBitsNotSet64(p->L_DOUBTOVER, 15);
    status = status && UpperBitsNotSet64(p->L_DOUBTUNDER, 15);
    status = status && UpperBitsNotSet64(p->Q_LENGTH, 2) ;
    if ((p-> Q_LENGTH == 1 ) || (p->Q_LENGTH == 2))
    {
        status = status && UpperBitsNotSet64(p->L_TRAININT, 15);
    }
    status = status && UpperBitsNotSet64(p->V_TRAIN, 7) ;
    status = status && UpperBitsNotSet64(p->Q_DIRTRAIN, 2) ;
    status = status && UpperBitsNotSet64(p->M_MODE, 4) ;
    status = status && UpperBitsNotSet64(p->M_LEVEL, 3) ;
    if (p-> M_LEVEL == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int PositionReport_UpperBitsNotSet(struct PositionReport *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->NID_LRBG, 24);
    status = status && UpperBitsNotSet64(p->D_LRBG, 15);
    status = status && UpperBitsNotSet64(p->Q_DIRLRBG, 2) ;
    status = status && UpperBitsNotSet64(p->Q_DLRBG, 2) ;
    status = status && UpperBitsNotSet64(p->L_DOUBTOVER, 15);
    status = status && UpperBitsNotSet64(p->L_DOUBTUNDER, 15);
    status = status && UpperBitsNotSet64(p->Q_LENGTH, 2) ;
    if ((p-> Q_LENGTH == 1 ) || (p->Q_LENGTH == 2))
    {
        status = status && UpperBitsNotSet64(p->L_TRAININT, 15);
    }
    status = status && UpperBitsNotSet64(p->V_TRAIN, 7) ;
    status = status && UpperBitsNotSet64(p->Q_DIRTRAIN, 2) ;
    status = status && UpperBitsNotSet64(p->M_MODE, 4) ;
    status = status && UpperBitsNotSet64(p->M_LEVEL, 3) ;
    if (p-> M_LEVEL == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct PositionReport { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LRBG; unsigned long D_LRBG; unsigned long Q_DIRLRBG; unsigned long Q_DLRBG; unsigned long L_DOUBTOVER; unsigned long L_DOUBTUNDER; unsigned long Q_LENGTH; unsigned long L_TRAININT; unsigned long V_TRAIN; unsigned long Q_DIRTRAIN; unsigned long M_MODE; unsigned long M_LEVEL; unsigned long NID_STM; } *

user_defined_types: struct PositionReport { struct PacketHeader header; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LRBG; unsigned long D_LRBG; unsigned long Q_DIRLRBG; unsigned long Q_DLRBG; unsigned long L_DOUBTOVER; unsigned long L_DOUBTUNDER; unsigned long Q_LENGTH; unsigned long L_TRAININT; unsigned long V_TRAIN; unsigned long Q_DIRTRAIN; unsigned long M_MODE; unsigned long M_LEVEL; unsigned long NID_STM; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 106LL) )
return 0xFFFFFFFFLL;
if ( !PositionReport_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 13LL, a1[2]);
Bitstream_Write(a2, 2LL, a1[3]);
Bitstream_Write(a2, 24LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 2LL, a1[6]);
Bitstream_Write(a2, 2LL, a1[7]);
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 15LL, a1[9]);
Bitstream_Write(a2, 2LL, a1[10]);
if ( a1[10] - 1 <= 1 )
Bitstream_Write(a2, 15LL, a1[11]);
Bitstream_Write(a2, 7LL, a1[12]);
Bitstream_Write(a2, 2LL, a1[13]);
Bitstream_Write(a2, 4LL, a1[14]);
Bitstream_Write(a2, 3LL, a1[15]);
result = 1LL;
if ( a1[15] == 1 )
{
Bitstream_Write(a2, 8LL, a1[16]);
result = 1LL;
}
return result;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 106LL) )
return 0xFFFFFFFFLL;
if ( !func2(a1) )
return 4294967294LL;
Bitstream_Write(a2, 13LL, a1[2]);
Bitstream_Write(a2, 2LL, a1[3]);
Bitstream_Write(a2, 24LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 2LL, a1[6]);
Bitstream_Write(a2, 2LL, a1[7]);
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 15LL, a1[9]);
Bitstream_Write(a2, 2LL, a1[10]);
if ( a1[10] - 1 <= 1 )
Bitstream_Write(a2, 15LL, a1[11]);
Bitstream_Write(a2, 7LL, a1[12]);
Bitstream_Write(a2, 2LL, a1[13]);
Bitstream_Write(a2, 4LL, a1[14]);
Bitstream_Write(a2, 3LL, a1[15]);
result = 1LL;
if ( a1[15] == 1 )
{
Bitstream_Write(a2, 8LL, a1[16]);
result = 1LL;
}
return result;
}

original_code:
int PositionReport_EncodeBit(const PositionReport* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 106))
    {
        if (PositionReport_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 24, p->NID_LRBG);
            Bitstream_Write(stream, 15, p->D_LRBG);
            Bitstream_Write(stream, 2, p->Q_DIRLRBG);
            Bitstream_Write(stream, 2, p->Q_DLRBG);
            Bitstream_Write(stream, 15, p->L_DOUBTOVER);
            Bitstream_Write(stream, 15, p->L_DOUBTUNDER);
            Bitstream_Write(stream, 2, p->Q_LENGTH);
            if ((p-> Q_LENGTH == 1 ) || (p->Q_LENGTH == 2))
            {
                Bitstream_Write(stream, 15, p->L_TRAININT);
            }
            Bitstream_Write(stream, 7, p->V_TRAIN);
            Bitstream_Write(stream, 2, p->Q_DIRTRAIN);
            Bitstream_Write(stream, 4, p->M_MODE);
            Bitstream_Write(stream, 3, p->M_LEVEL);
            if (p-> M_LEVEL == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int PositionReport_EncodeBit(struct PositionReport *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 106))
    {
        if (PositionReport_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 24, p->NID_LRBG);
            Bitstream_Write(stream, 15, p->D_LRBG);
            Bitstream_Write(stream, 2, p->Q_DIRLRBG);
            Bitstream_Write(stream, 2, p->Q_DLRBG);
            Bitstream_Write(stream, 15, p->L_DOUBTOVER);
            Bitstream_Write(stream, 15, p->L_DOUBTUNDER);
            Bitstream_Write(stream, 2, p->Q_LENGTH);
            if ((p-> Q_LENGTH == 1 ) || (p->Q_LENGTH == 2))
            {
                Bitstream_Write(stream, 15, p->L_TRAININT);
            }
            Bitstream_Write(stream, 7, p->V_TRAIN);
            Bitstream_Write(stream, 2, p->Q_DIRTRAIN);
            Bitstream_Write(stream, 4, p->M_MODE);
            Bitstream_Write(stream, 3, p->M_LEVEL);
            if (p-> M_LEVEL == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

result = Bitstream_Normal(a2, 106LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 13LL);
a1[3] = Bitstream_Read(a2, 2LL);
a1[4] = Bitstream_Read(a2, 24LL);
a1[5] = Bitstream_Read(a2, 15LL);
a1[6] = Bitstream_Read(a2, 2LL);
a1[7] = Bitstream_Read(a2, 2LL);
a1[8] = Bitstream_Read(a2, 15LL);
a1[9] = Bitstream_Read(a2, 15LL);
v3 = Bitstream_Read(a2, 2LL);
a1[10] = v3;
if ( (unsigned __int64)(v3 - 1) <= 1 )
a1[11] = Bitstream_Read(a2, 15LL);
a1[12] = Bitstream_Read(a2, 7LL);
a1[13] = Bitstream_Read(a2, 2LL);
a1[14] = Bitstream_Read(a2, 4LL);
v4 = Bitstream_Read(a2, 3LL);
a1[15] = v4;
result = 1LL;
if ( v4 == 1 )
{
a1[16] = 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; // rdx

result = Bitstream_Normal(a2, 106LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 13LL);
a1[3] = Bitstream_Read(a2, 2LL);
a1[4] = Bitstream_Read(a2, 24LL);
a1[5] = Bitstream_Read(a2, 15LL);
a1[6] = Bitstream_Read(a2, 2LL);
a1[7] = Bitstream_Read(a2, 2LL);
a1[8] = Bitstream_Read(a2, 15LL);
a1[9] = Bitstream_Read(a2, 15LL);
v3 = Bitstream_Read(a2, 2LL);
a1[10] = v3;
if ( (unsigned __int64)(v3 - 1) <= 1 )
a1[11] = Bitstream_Read(a2, 15LL);
a1[12] = Bitstream_Read(a2, 7LL);
a1[13] = Bitstream_Read(a2, 2LL);
a1[14] = Bitstream_Read(a2, 4LL);
v4 = Bitstream_Read(a2, 3LL);
a1[15] = v4;
result = 1LL;
if ( v4 == 1 )
{
a1[16] = Bitstream_Read(a2, 8LL);
result = 1LL;
}
}
return result;
}

original_code:
int PositionReport_DecodeBit(PositionReport* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 106))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_LRBG = Bitstream_Read(stream, 24);
        }
        {
            p->D_LRBG = Bitstream_Read(stream, 15);
        }
        {
            p->Q_DIRLRBG = Bitstream_Read(stream, 2);
        }
        {
            p->Q_DLRBG = Bitstream_Read(stream, 2);
        }
        {
            p->L_DOUBTOVER = Bitstream_Read(stream, 15);
        }
        {
            p->L_DOUBTUNDER = Bitstream_Read(stream, 15);
        }
        {
            p->Q_LENGTH = Bitstream_Read(stream, 2);
        }
        if ((p-> Q_LENGTH == 1 ) || (p->Q_LENGTH == 2))
        {
            {
                p->L_TRAININT = Bitstream_Read(stream, 15);
            }
        }
        {
            p->V_TRAIN = Bitstream_Read(stream, 7);
        }
        {
            p->Q_DIRTRAIN = Bitstream_Read(stream, 2);
        }
        {
            p->M_MODE = Bitstream_Read(stream, 4);
        }
        {
            p->M_LEVEL = Bitstream_Read(stream, 3);
        }
        if (p-> M_LEVEL == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int PositionReport_DecodeBit(struct PositionReport *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 106))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_LRBG = Bitstream_Read(stream, 24);
        }
        {
            p->D_LRBG = Bitstream_Read(stream, 15);
        }
        {
            p->Q_DIRLRBG = Bitstream_Read(stream, 2);
        }
        {
            p->Q_DLRBG = Bitstream_Read(stream, 2);
        }
        {
            p->L_DOUBTOVER = Bitstream_Read(stream, 15);
        }
        {
            p->L_DOUBTUNDER = Bitstream_Read(stream, 15);
        }
        {
            p->Q_LENGTH = Bitstream_Read(stream, 2);
        }
        if ((p-> Q_LENGTH == 1 ) || (p->Q_LENGTH == 2))
        {
            {
                p->L_TRAININT = Bitstream_Read(stream, 15);
            }
        }
        {
            p->V_TRAIN = Bitstream_Read(stream, 7);
        }
        {
            p->Q_DIRTRAIN = Bitstream_Read(stream, 2);
        }
        {
            p->M_MODE = Bitstream_Read(stream, 4);
        }
        {
            p->M_LEVEL = Bitstream_Read(stream, 3);
        }
        if (p-> M_LEVEL == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int PositionReport_EncodeInt(const PositionReport* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 0;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->NID_LRBG;
    stream[startAddress++] = p->D_LRBG;
    stream[startAddress++] = p->Q_DIRLRBG;
    stream[startAddress++] = p->Q_DLRBG;
    stream[startAddress++] = p->L_DOUBTOVER;
    stream[startAddress++] = p->L_DOUBTUNDER;
    stream[startAddress++] = p->Q_LENGTH;
    stream[startAddress++] = p->L_TRAININT;
    stream[startAddress++] = p->V_TRAIN;
    stream[startAddress++] = p->Q_DIRTRAIN;
    stream[startAddress++] = p->M_MODE;
    stream[startAddress++] = p->M_LEVEL;
    stream[startAddress++] = p->NID_STM;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int PositionReport_EncodeInt(struct PositionReport *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 0;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->NID_LRBG;
    stream[startAddress++] = p->D_LRBG;
    stream[startAddress++] = p->Q_DIRLRBG;
    stream[startAddress++] = p->Q_DLRBG;
    stream[startAddress++] = p->L_DOUBTOVER;
    stream[startAddress++] = p->L_DOUBTUNDER;
    stream[startAddress++] = p->Q_LENGTH;
    stream[startAddress++] = p->L_TRAININT;
    stream[startAddress++] = p->V_TRAIN;
    stream[startAddress++] = p->Q_DIRTRAIN;
    stream[startAddress++] = p->M_MODE;
    stream[startAddress++] = p->M_LEVEL;
    stream[startAddress++] = p->NID_STM;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int PositionReport_DecodeInt(PositionReport* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 0)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->NID_LRBG = stream[startAddress++];
    p->D_LRBG = stream[startAddress++];
    p->Q_DIRLRBG = stream[startAddress++];
    p->Q_DLRBG = stream[startAddress++];
    p->L_DOUBTOVER = stream[startAddress++];
    p->L_DOUBTUNDER = stream[startAddress++];
    p->Q_LENGTH = stream[startAddress++];
    p->L_TRAININT = stream[startAddress++];
    p->V_TRAIN = stream[startAddress++];
    p->Q_DIRTRAIN = stream[startAddress++];
    p->M_MODE = stream[startAddress++];
    p->M_LEVEL = stream[startAddress++];
    p->NID_STM = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int PositionReport_DecodeInt(struct PositionReport *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 0)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->NID_LRBG = stream[startAddress++];
    p->D_LRBG = stream[startAddress++];
    p->Q_DIRLRBG = stream[startAddress++];
    p->Q_DLRBG = stream[startAddress++];
    p->L_DOUBTOVER = stream[startAddress++];
    p->L_DOUBTUNDER = stream[startAddress++];
    p->Q_LENGTH = stream[startAddress++];
    p->L_TRAININT = stream[startAddress++];
    p->V_TRAIN = stream[startAddress++];
    p->Q_DIRTRAIN = stream[startAddress++];
    p->M_MODE = stream[startAddress++];
    p->M_LEVEL = stream[startAddress++];
    p->NID_STM = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}