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

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

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

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

original_code:
int PositionReportBasedOnTwoBaliseGroups_EncodeBit(const PositionReportBasedOnTwoBaliseGroups* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 130))
    {
        if (PositionReportBasedOnTwoBaliseGroups_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, 24, p->NID_PRVLRBG);
            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 PositionReportBasedOnTwoBaliseGroups_EncodeBit(struct PositionReportBasedOnTwoBaliseGroups *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 130))
    {
        if (PositionReportBasedOnTwoBaliseGroups_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, 24, p->NID_PRVLRBG);
            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;
    }
}


repo: openETCS/dataDictionary

decompiled_code:
__int64 __fastcall PositionReportBasedOnTwoBaliseGroups_DecodeBit(_QWORD *a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v4; // rax
__int64 v5; // rax

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

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

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

original_code:
int PositionReportBasedOnTwoBaliseGroups_DecodeBit(PositionReportBasedOnTwoBaliseGroups* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 130))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_LRBG = Bitstream_Read(stream, 24);
        }
        {
            p->NID_PRVLRBG = 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 PositionReportBasedOnTwoBaliseGroups_DecodeBit(struct PositionReportBasedOnTwoBaliseGroups *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 130))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_LRBG = Bitstream_Read(stream, 24);
        }
        {
            p->NID_PRVLRBG = 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;
    }
}

variable_types: struct PositionReportBasedOnTwoBaliseGroups { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LRBG; unsigned long NID_PRVLRBG; 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; } *

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

return_type: int

user_defined_types: struct PositionReportBasedOnTwoBaliseGroups { struct PacketHeader header; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LRBG; unsigned long NID_PRVLRBG; 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; }


original_code:
int PositionReportBasedOnTwoBaliseGroups_EncodeInt(const PositionReportBasedOnTwoBaliseGroups* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 1;
    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->NID_PRVLRBG;
    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 PositionReportBasedOnTwoBaliseGroups_EncodeInt(struct PositionReportBasedOnTwoBaliseGroups *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 1;
    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->NID_PRVLRBG;
    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;
}

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

variable_types:
stream
int *

variable_types: startAddress int

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


original_code:
int PositionReportBasedOnTwoBaliseGroups_DecodeInt(PositionReportBasedOnTwoBaliseGroups* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 1)
    {
         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->NID_PRVLRBG = 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 PositionReportBasedOnTwoBaliseGroups_DecodeInt(struct PositionReportBasedOnTwoBaliseGroups *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 1)
    {
         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->NID_PRVLRBG = 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;
}

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


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

if ( PositionReportBasedOnTwoBaliseGroupsMemoryFreeList == -1 )
{
if ( (unsigned __int64)PositionReportBasedOnTwoBaliseGroupsMemoryTop <= 7 )
{
v1 = 18 * PositionReportBasedOnTwoBaliseGroupsMemoryTop++;
PositionReportBasedOnTwoBaliseGroups_Init(&PositionReportBasedOnTwoBaliseGroupsMemory[v1]);
}
}
else
{
v0 = &PositionReportBasedOnTwoBaliseGroupsMemory[18 * PositionReportBasedOnTwoBaliseGroupsMemoryFreeList];
PositionReportBasedOnTwoBaliseGroupsMemoryFreeList = *v0;
PositionReportBasedOnTwoBaliseGroups_Init(v0);
}
}

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

if ( PositionReportBasedOnTwoBaliseGroupsMemoryFreeList == -1 )
{
if ( (unsigned __int64)PositionReportBasedOnTwoBaliseGroupsMemoryTop <= 7 )
{
v1 = 18 * PositionReportBasedOnTwoBaliseGroupsMemoryTop++;
func1(&PositionReportBasedOnTwoBaliseGroupsMemory[v1]);
}
}
else
{
v0 = &PositionReportBasedOnTwoBaliseGroupsMemory[18 * PositionReportBasedOnTwoBaliseGroupsMemoryFreeList];
PositionReportBasedOnTwoBaliseGroupsMemoryFreeList = *v0;
func1(v0);
}
}

original_code:
PositionReportBasedOnTwoBaliseGroups* PositionReportBasedOnTwoBaliseGroups_New(void)
{
    PositionReportBasedOnTwoBaliseGroups* ptr;
    if (PositionReportBasedOnTwoBaliseGroupsMemoryFreeList != (-1))
    {
        ptr = &PositionReportBasedOnTwoBaliseGroupsMemory[PositionReportBasedOnTwoBaliseGroupsMemoryFreeList];
        PositionReportBasedOnTwoBaliseGroupsMemoryFreeList = PositionReportBasedOnTwoBaliseGroupsMemory[PositionReportBasedOnTwoBaliseGroupsMemoryFreeList].header.NID_PACKET;
    }
    else if (PositionReportBasedOnTwoBaliseGroupsMemoryTop < 8)
    {
        ptr = &PositionReportBasedOnTwoBaliseGroupsMemory[PositionReportBasedOnTwoBaliseGroupsMemoryTop];
        PositionReportBasedOnTwoBaliseGroupsMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    PositionReportBasedOnTwoBaliseGroups_Init(ptr);
    return ptr;
}

canonical_original_code:
struct PositionReportBasedOnTwoBaliseGroups *PositionReportBasedOnTwoBaliseGroups_New()
{
    struct PositionReportBasedOnTwoBaliseGroups *ptr;
    if (PositionReportBasedOnTwoBaliseGroupsMemoryFreeList != (-1))
    {
        ptr = &PositionReportBasedOnTwoBaliseGroupsMemory[PositionReportBasedOnTwoBaliseGroupsMemoryFreeList];
        PositionReportBasedOnTwoBaliseGroupsMemoryFreeList = PositionReportBasedOnTwoBaliseGroupsMemory[PositionReportBasedOnTwoBaliseGroupsMemoryFreeList].header.NID_PACKET;
    }
    else if (PositionReportBasedOnTwoBaliseGroupsMemoryTop < 8)
    {
        ptr = &PositionReportBasedOnTwoBaliseGroupsMemory[PositionReportBasedOnTwoBaliseGroupsMemoryTop];
        PositionReportBasedOnTwoBaliseGroupsMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    PositionReportBasedOnTwoBaliseGroups_Init(ptr);
    return ptr;
}

return_type: struct PositionReportBasedOnTwoBaliseGroups { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LRBG; unsigned long NID_PRVLRBG; 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:
unsigned __int64 __fastcall PositionReportBasedOnTwoBaliseGroups_Delete(char *a1)
{
unsigned __int64 result; // rax

*(_QWORD *)a1 = PositionReportBasedOnTwoBaliseGroupsMemoryFreeList;
result = 0x8E38E38E38E38E39LL;
PositionReportBasedOnTwoBaliseGroupsMemoryFreeList = 0x8E38E38E38E38E39LL
* ((a1 - (char *)PositionReportBasedOnTwoBaliseGroupsMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = PositionReportBasedOnTwoBaliseGroupsMemoryFreeList;
result = 0x8E38E38E38E38E39LL;
PositionReportBasedOnTwoBaliseGroupsMemoryFreeList = 0x8E38E38E38E38E39LL
* ((a1 - (char *)PositionReportBasedOnTwoBaliseGroupsMemory) >> 4);
return result;
}

original_code:
void PositionReportBasedOnTwoBaliseGroups_Delete(PositionReportBasedOnTwoBaliseGroups* ptr)
{
    ptr->header.NID_PACKET = PositionReportBasedOnTwoBaliseGroupsMemoryFreeList;
    PositionReportBasedOnTwoBaliseGroupsMemoryFreeList = ptr - PositionReportBasedOnTwoBaliseGroupsMemory;
}

canonical_original_code:
void PositionReportBasedOnTwoBaliseGroups_Delete(struct PositionReportBasedOnTwoBaliseGroups *ptr)
{
    ptr->header.NID_PACKET = PositionReportBasedOnTwoBaliseGroupsMemoryFreeList;
    PositionReportBasedOnTwoBaliseGroupsMemoryFreeList = ptr - PositionReportBasedOnTwoBaliseGroupsMemory;
}

return_type: void


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

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

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 GeographicalPositionInformation_1_UpperBitsNotSet(unsigned __int64 *a1)
{
unsigned __int64 v1; // rdi
_BOOL8 result; // rax
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx

v1 = *a1;
result = UpperBitsNotSet64(v1, 1);
if ( result && (v1 != 1 || (result = UpperBitsNotSet64(*(_QWORD *)(v3 + 8), 10))) )
{
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 16), 14);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v4 + 24), 15);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v5 + 32), 1);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v6 + 40), 20);
}
}
}
return result;
}

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

v1 = *a1;
result = func0(v1, 1);
if ( result && (v1 != 1 || (result = func0(*(_QWORD *)(v3 + 8), 10))) )
{
result = func0(*(_QWORD *)(v3 + 16), 14);
if ( result )
{
result = func0(*(_QWORD *)(v4 + 24), 15);
if ( result )
{
result = func0(*(_QWORD *)(v5 + 32), 1);
if ( result )
result = func0(*(_QWORD *)(v6 + 40), 20);
}
}
}
return result;
}

original_code:
int GeographicalPositionInformation_1_UpperBitsNotSet(const GeographicalPositionInformation_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    status = status && UpperBitsNotSet64(p->D_POSOFF, 15);
    status = status && UpperBitsNotSet64(p->Q_MPOSITION, 1) ;
    status = status && UpperBitsNotSet64(p->M_POSITION, 20);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int GeographicalPositionInformation_1_UpperBitsNotSet(struct GeographicalPositionInformation_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    status = status && UpperBitsNotSet64(p->D_POSOFF, 15);
    status = status && UpperBitsNotSet64(p->Q_MPOSITION, 1) ;
    status = status && UpperBitsNotSet64(p->M_POSITION, 20);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct GeographicalPositionInformation_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long D_POSOFF; unsigned long Q_MPOSITION; unsigned long M_POSITION; } *

variable_types: status int


decompiled_code:
__int64 __fastcall GeographicalPositionInformation_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 51LL) )
return 0xFFFFFFFFLL;
if ( !GeographicalPositionInformation_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 1LL, *a1);
if ( *a1 == 1 )
Bitstream_Write(a2, 10LL, a1[1]);
Bitstream_Write(a2, 14LL, a1[2]);
Bitstream_Write(a2, 15LL, a1[3]);
Bitstream_Write(a2, 1LL, a1[4]);
Bitstream_Write(a2, 20LL, a1[5]);
return 1LL;
}

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

original_code:
int GeographicalPositionInformation_1_EncodeBit(const GeographicalPositionInformation_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 51))
    {
        if (GeographicalPositionInformation_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            Bitstream_Write(stream, 15, p->D_POSOFF);
            Bitstream_Write(stream, 1, p->Q_MPOSITION);
            Bitstream_Write(stream, 20, p->M_POSITION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int GeographicalPositionInformation_1_EncodeBit(struct GeographicalPositionInformation_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 51))
    {
        if (GeographicalPositionInformation_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            Bitstream_Write(stream, 15, p->D_POSOFF);
            Bitstream_Write(stream, 1, p->Q_MPOSITION);
            Bitstream_Write(stream, 20, p->M_POSITION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct GeographicalPositionInformation_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long D_POSOFF; unsigned long Q_MPOSITION; unsigned long M_POSITION; }

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


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

result = Bitstream_Normal(a2, 51LL);
if ( (_DWORD)result )
{
v3 = Bitstream_Read(a2, 1LL);
*a1 = v3;
if ( v3 == 1 )
a1[1] = Bitstream_Read(a2, 10LL);
a1[2] = Bitstream_Read(a2, 14LL);
a1[3] = Bitstream_Read(a2, 15LL);
a1[4] = Bitstream_Read(a2, 1LL);
a1[5] = Bitstream_Read(a2, 20LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 51LL);
if ( (_DWORD)result )
{
v3 = Bitstream_Read(a2, 1LL);
*a1 = v3;
if ( v3 == 1 )
a1[1] = Bitstream_Read(a2, 10LL);
a1[2] = Bitstream_Read(a2, 14LL);
a1[3] = Bitstream_Read(a2, 15LL);
a1[4] = Bitstream_Read(a2, 1LL);
a1[5] = Bitstream_Read(a2, 20LL);
result = 1LL;
}
return result;
}

original_code:
int GeographicalPositionInformation_1_DecodeBit(GeographicalPositionInformation_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 51))
    {
        {
            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);
        }
        {
            p->D_POSOFF = Bitstream_Read(stream, 15);
        }
        {
            p->Q_MPOSITION = Bitstream_Read(stream, 1);
        }
        {
            p->M_POSITION = Bitstream_Read(stream, 20);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int GeographicalPositionInformation_1_DecodeBit(struct GeographicalPositionInformation_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 51))
    {
        {
            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);
        }
        {
            p->D_POSOFF = Bitstream_Read(stream, 15);
        }
        {
            p->Q_MPOSITION = Bitstream_Read(stream, 1);
        }
        {
            p->M_POSITION = Bitstream_Read(stream, 20);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int GeographicalPositionInformation_1_EncodeInt(const GeographicalPositionInformation_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->Q_NEWCOUNTRY;
    stream[(*startAddress)++] = p->NID_C;
    stream[(*startAddress)++] = p->NID_BG;
    stream[(*startAddress)++] = p->D_POSOFF;
    stream[(*startAddress)++] = p->Q_MPOSITION;
    stream[(*startAddress)++] = p->M_POSITION;
    return 1;
}

canonical_original_code:
int GeographicalPositionInformation_1_EncodeInt(struct GeographicalPositionInformation_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->Q_NEWCOUNTRY;
    stream[(*startAddress)++] = p->NID_C;
    stream[(*startAddress)++] = p->NID_BG;
    stream[(*startAddress)++] = p->D_POSOFF;
    stream[(*startAddress)++] = p->Q_MPOSITION;
    stream[(*startAddress)++] = p->M_POSITION;
    return 1;
}

variable_types:
startAddress
int *


original_code:
int GeographicalPositionInformation_1_DecodeInt(GeographicalPositionInformation_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->Q_NEWCOUNTRY = stream[(*startAddress)++];
    p->NID_C = stream[(*startAddress)++];
    p->NID_BG = stream[(*startAddress)++];
    p->D_POSOFF = stream[(*startAddress)++];
    p->Q_MPOSITION = stream[(*startAddress)++];
    p->M_POSITION = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int GeographicalPositionInformation_1_DecodeInt(struct GeographicalPositionInformation_1 *p, int *startAddress, int *stream)
{
    p->Q_NEWCOUNTRY = stream[(*startAddress)++];
    p->NID_C = stream[(*startAddress)++];
    p->NID_BG = stream[(*startAddress)++];
    p->D_POSOFF = stream[(*startAddress)++];
    p->Q_MPOSITION = stream[(*startAddress)++];
    p->M_POSITION = stream[(*startAddress)++];
    return 1;
}


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

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


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

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

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

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

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


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

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

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

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

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

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

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


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

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


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

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


decompiled_code:
__int64 __fastcall PacketSequence_Get(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a1 + 400);
if ( v2 > 0x31 )
_assert_fail("s->size < 50", "..//Telegram/PacketSequence.h", 0x30u, "PacketSequence_Get");
if ( v2 <= a2 )
_assert_fail("i < s->size", "..//Telegram/PacketSequence.h", 0x31u, "PacketSequence_Get");
return *(_QWORD *)(a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a1 + 400);
if ( v2 > 0x31 )
_assert_fail("s->size < 50", "..//Telegram/PacketSequence.h", 0x30u, "PacketSequence_Get");
if ( v2 <= a2 )
_assert_fail("i < s->size", "..//Telegram/PacketSequence.h", 0x31u, "PacketSequence_Get");
return *(_QWORD *)(a1 + 8LL * a2);
}

original_code:
static inline const PacketHeader* PacketSequence_Get(const PacketSequence* s, uint32_t i)
{
    ((s->size < 50) ? (void) (0) : __assert_fail ("s->size < 50", "..//Telegram/PacketSequence.h", 48, __extension__ __PRETTY_FUNCTION__));
    ((i < s->size) ? (void) (0) : __assert_fail ("i < s->size", "..//Telegram/PacketSequence.h", 49, __extension__ __PRETTY_FUNCTION__));
    return s->header[i];
}

canonical_original_code:
static inline struct PacketHeader *PacketSequence_Get(struct PacketSequence *s, unsigned int i)
{
    ((s->size < 50) ? (void) (0) : __assert_fail ("s->size < 50", "..//Telegram/PacketSequence.h", 48, __extension__ __PRETTY_FUNCTION__));
    ((i < s->size) ? (void) (0) : __assert_fail ("i < s->size", "..//Telegram/PacketSequence.h", 49, __extension__ __PRETTY_FUNCTION__));
    return s->header[i];
}

variable_types: struct PacketSequence { struct PacketHeader *header[50]; unsigned int size; } *

variable_types:
i
unsigned int

return_type: struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } *


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

result = *(unsigned int *)(a1 + 400);
if ( (unsigned int)result > 0x31 )
_assert_fail("s->size < 50", "..//Telegram/PacketSequence.h", 0x2Au, "PacketSequence_Add");
*(_DWORD *)(a1 + 400) = result + 1;
*(_QWORD *)(a1 + 8 * result) = a2;
return result;
}

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

result = *(unsigned int *)(a1 + 400);
if ( (unsigned int)result > 0x31 )
_assert_fail("s->size < 50", "..//Telegram/PacketSequence.h", 0x2Au, "PacketSequence_Add");
*(_DWORD *)(a1 + 400) = result + 1;
*(_QWORD *)(a1 + 8 * result) = a2;
return result;
}

original_code:
static inline void PacketSequence_Add(PacketSequence* s, PacketHeader* h)
{
    ((s->size < 50) ? (void) (0) : __assert_fail ("s->size < 50", "..//Telegram/PacketSequence.h", 42, __extension__ __PRETTY_FUNCTION__));
    s->header[s->size++] = h;
}

canonical_original_code:
static inline void PacketSequence_Add(struct PacketSequence *s, struct PacketHeader *h)
{
    ((s->size < 50) ? (void) (0) : __assert_fail ("s->size < 50", "..//Telegram/PacketSequence.h", 42, __extension__ __PRETTY_FUNCTION__));
    s->header[s->size++] = h;
}

variable_types: struct PacketSequence { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } *header[50]; unsigned int size; } *

variable_types:
h
struct PacketHeader *

user_defined_types: struct PacketSequence { struct PacketHeader *header[50]; unsigned int size; }


decompiled_code:
__int64 __fastcall PacketSequence_Clear(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rdi

result = *(unsigned int *)(a1 + 400);
if ( (_DWORD)result )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1 + 8 * v3++);
result = Packet_Delete(v4);
}
while ( *(_DWORD *)(a1 + 400) > (unsigned int)v3 );
}
*(_DWORD *)(a1 + 400) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rdi

result = *(unsigned int *)(a1 + 400);
if ( (_DWORD)result )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1 + 8 * v3++);
result = Packet_Delete(v4);
}
while ( *(_DWORD *)(a1 + 400) > (unsigned int)v3 );
}
*(_DWORD *)(a1 + 400) = 0;
return result;
}

original_code:
void PacketSequence_Clear(PacketSequence* p)
{
    for (uint32_t i = 0; i < p->size; ++i)
    {
        Packet_Delete(p->header[i]);
    }
    p->size = 0;
}

canonical_original_code:
void PacketSequence_Clear(struct PacketSequence *p)
{
    for (unsigned int i = 0; i < p->size; ++i)
    {
        Packet_Delete(p->header[i]);
    }
    p->size = 0;
}


decompiled_code:
__int64 __fastcall PacketSequence_Equal(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v4; // r12
int v5; // eax
unsigned int v6; // edx
unsigned int i; // ecx

v2 = *(_DWORD *)(a1 + 400);
if ( v2 != *(_DWORD *)(a2 + 400) )
return 0LL;
v4 = 0LL;
if ( !v2 )
return 1LL;
while ( 1 )
{
v5 = Packet_Equal(*(_QWORD *)(a1 + 8 * v4), *(_QWORD *)(a2 + 8 * v4));
v6 = v4 + 1;
if ( !v5 )
break;
if ( *(_DWORD *)(a1 + 400) <= (unsigned int)++v4 )
return 1LL;
}
for ( i = *(_DWORD *)(a1 + 400); v6 < i; v6 += 2 )
{
if ( v6 + 1 >= i )
break;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v4; // r12
int v5; // eax
unsigned int v6; // edx
unsigned int i; // ecx

v2 = *(_DWORD *)(a1 + 400);
if ( v2 != *(_DWORD *)(a2 + 400) )
return 0LL;
v4 = 0LL;
if ( !v2 )
return 1LL;
while ( 1 )
{
v5 = Packet_Equal(*(_QWORD *)(a1 + 8 * v4), *(_QWORD *)(a2 + 8 * v4));
v6 = v4 + 1;
if ( !v5 )
break;
if ( *(_DWORD *)(a1 + 400) <= (unsigned int)++v4 )
return 1LL;
}
for ( i = *(_DWORD *)(a1 + 400); v6 < i; v6 += 2 )
{
if ( v6 + 1 >= i )
break;
}
return 0LL;
}

original_code:
int PacketSequence_Equal(const PacketSequence* a, const PacketSequence* b)
{
    if (a->size == b->size)
    {
        int status = 1;
        for (uint32_t i = 0; i < a->size; ++i)
        {
            status = status && Packet_Equal(a->header[i], b->header[i]);
        }
        return status;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int PacketSequence_Equal(struct PacketSequence *a, struct PacketSequence *b)
{
    if (a->size == b->size)
    {
        int status = 1;
        for (unsigned int i = 0; i < a->size; ++i)
        {
            status = status && Packet_Equal(a->header[i], b->header[i]);
        }
        return status;
    }
    else
    {
        return 0;
    }
}

variable_types:
b
struct PacketSequence *


decompiled_code:
_BOOL8 __fastcall PacketSequence_EncodeInt(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er13
int v4; // eax
int v5; // eax
unsigned int v6; // edx
__int64 v7; // rax
__int64 v9; // rdx

if ( *(_DWORD *)(a1 + 400) )
{
v2 = a2;
v3 = 0;
v4 = 0;
do
{
*(_DWORD *)(v2 + 12) = v4;
v7 = PacketSequence_Get(a1, v3);
if ( (unsigned int)Packet_EncodeInt(v7, v2, a2 + 600) != 1 )
return 0LL;
v5 = *(_DWORD *)(v2 + 16);
v6 = *(_DWORD *)(a1 + 400);
++v3;
v2 += 20LL;
v4 = v5 + 1;
}
while ( v6 > v3 );
v9 = v6 - 1;
}
else
{
v9 = 0xFFFFFFFFLL;
}
return *(_DWORD *)(a2 + 20 * v9) == 255;
}

original_code:
int PacketSequence_EncodeInt(const PacketSequence* p, CompressedPackets* packetStruct)
{
    kcg_int startAddress = 0;
    for (uint32_t i = 0; i < p->size; ++i)
    {
        packetStruct->PacketHeaders[i].startAddress = startAddress;
        if (Packet_EncodeInt(PacketSequence_Get(p, i), &(packetStruct->PacketHeaders[i]), packetStruct->PacketData) != 1)
 {
             return 0;
        }
        startAddress = packetStruct->PacketHeaders[i].endAddress + 1;
    }
    if (packetStruct->PacketHeaders[p->size-1].nid_packet != 255)
    {
        return 0;
    }
    return 1;
}

canonical_original_code:
int PacketSequence_EncodeInt(struct PacketSequence *p, struct CompressedPackets_T_Common_Types_Pkg *packetStruct)
{
    int startAddress = 0;
    for (unsigned int i = 0; i < p->size; ++i)
    {
        packetStruct->PacketHeaders[i].startAddress = startAddress;
        if (Packet_EncodeInt(PacketSequence_Get(p, i), &(packetStruct->PacketHeaders[i]), packetStruct->PacketData) != 1)
 {
             return 0;
        }
        startAddress = packetStruct->PacketHeaders[i].endAddress + 1;
    }
    if (packetStruct->PacketHeaders[p->size-1].nid_packet != 255)
    {
        return 0;
    }
    return 1;
}

variable_types: struct CompressedPackets_T_Common_Types_Pkg { struct MetadataElement_T_Common_Types_Pkg { int nid_packet; int q_dir; unsigned char valid; int startAddress; int endAddress; } PacketHeaders[30]; int PacketData[500]; } *

user_defined_types: struct CompressedPackets_T_Common_Types_Pkg { struct MetadataElement_T_Common_Types_Pkg PacketHeaders[30]; int PacketData[500]; }


decompiled_code:
__int64 __fastcall PacketSequence_DecodeInt(__int64 a1, __int64 a2, int *a3)
{
int *v3; // r14
int *i; // rbx
__int64 v6; // rdi
__int64 v7; // rbp
__int64 v9; // rsi

v3 = a3 + 150;
for ( i = a3; ; i += 5 )
{
if ( *((_BYTE *)i + 8) != 1 )
continue;
v6 = *i;
if ( v6 == 255 )
break;
if ( a2 == 1 )
{
v7 = PacketFactory_TrackToTrain(v6, 0LL);
if ( !v7 )
return 0LL;
}
else
{
if ( a2 )
_assert_fail("q_updown == 0", "..//Telegram/PacketSequence.c", 0x94u, "PacketSequence_DecodeInt");
v7 = PacketFactory_TrainToTrack(v6, 0LL);
if ( !v7 )
return 0LL;
}
PacketSequence_Add(a1, v7);
Packet_DecodeInt(v7, i, v3);
}
v9 = PacketFactory_BothWays(255LL, 0LL);
if ( !v9 )
_assert_fail("ptr", "..//Telegram/PacketSequence.c", 0x7Fu, "PacketSequence_DecodeInt");
PacketSequence_Add(a1, v9);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int *a3)
{
int *v3; // r14
int *i; // rbx
__int64 v6; // rdi
__int64 v7; // rbp
__int64 v9; // rsi

v3 = a3 + 150;
for ( i = a3; ; i += 5 )
{
if ( *((_BYTE *)i + 8) != 1 )
continue;
v6 = *i;
if ( v6 == 255 )
break;
if ( a2 == 1 )
{
v7 = PacketFactory_TrackToTrain(v6, 0LL);
if ( !v7 )
return 0LL;
}
else
{
if ( a2 )
_assert_fail("q_updown == 0", "..//Telegram/PacketSequence.c", 0x94u, "PacketSequence_DecodeInt");
v7 = PacketFactory_TrainToTrack(v6, 0LL);
if ( !v7 )
return 0LL;
}
func1(a1, v7);
Packet_DecodeInt(v7, i, v3);
}
v9 = PacketFactory_BothWays(255LL, 0LL);
if ( !v9 )
_assert_fail("ptr", "..//Telegram/PacketSequence.c", 0x7Fu, "PacketSequence_DecodeInt");
func1(a1, v9);
return 1LL;
}

original_code:
int PacketSequence_DecodeInt(PacketSequence* p, uint64_t q_updown, const CompressedPackets* packetStruct)
{
    for (uint32_t i = 0; i < 50; ++i)
    {
        if (packetStruct->PacketHeaders[i].valid == 1)
        {
     PacketHeader packet_header = {0, 0};
            PacketHeader* ptr = 0;
     packet_header.NID_PACKET = packetStruct->PacketHeaders[i].nid_packet;
     if (packet_header.NID_PACKET == 255)
     {
                ptr = PacketFactory_BothWays(packet_header);
  ((ptr) ? (void) (0) : __assert_fail ("ptr", "..//Telegram/PacketSequence.c", 127, __extension__ __PRETTY_FUNCTION__));
  PacketSequence_Add(p, ptr);
  break;
     }
     if (q_updown == 1)
     {
                ptr = PacketFactory_TrackToTrain(packet_header);
  if (ptr)
  {
                    PacketSequence_Add(p, ptr);
  }
  else
  {
      return 0;
  }
     }
     else
     {
                ((q_updown == 0) ? (void) (0) : __assert_fail ("q_updown == 0", "..//Telegram/PacketSequence.c", 148, __extension__ __PRETTY_FUNCTION__));
  ptr = PacketFactory_TrainToTrack(packet_header);
  if (ptr)
  {
                    PacketSequence_Add(p, ptr);
  }
  else
  {
      return 0;
  }
     }
     if (ptr)
     {
                Packet_DecodeInt(ptr, &(packetStruct->PacketHeaders[i]), packetStruct->PacketData);
     }
     else
     {
                return 0;
     }
        }
    }
    return 1;
}

canonical_original_code:
int PacketSequence_DecodeInt(struct PacketSequence *p, unsigned long q_updown, struct CompressedPackets_T_Common_Types_Pkg *packetStruct)
{
    for (unsigned int i = 0; i < 50; ++i)
    {
        if (packetStruct->PacketHeaders[i].valid == 1)
        {
     struct PacketHeader packet_header = {0, 0};
            struct PacketHeader *ptr = 0;
     packet_header.NID_PACKET = packetStruct->PacketHeaders[i].nid_packet;
     if (packet_header.NID_PACKET == 255)
     {
                ptr = PacketFactory_BothWays(packet_header);
  ((ptr) ? (void) (0) : __assert_fail ("ptr", "..//Telegram/PacketSequence.c", 127, __extension__ __PRETTY_FUNCTION__));
  PacketSequence_Add(p, ptr);
  break;
     }
     if (q_updown == 1)
     {
                ptr = PacketFactory_TrackToTrain(packet_header);
  if (ptr)
  {
                    PacketSequence_Add(p, ptr);
  }
  else
  {
      return 0;
  }
     }
     else
     {
                ((q_updown == 0) ? (void) (0) : __assert_fail ("q_updown == 0", "..//Telegram/PacketSequence.c", 148, __extension__ __PRETTY_FUNCTION__));
  ptr = PacketFactory_TrainToTrack(packet_header);
  if (ptr)
  {
                    PacketSequence_Add(p, ptr);
  }
  else
  {
      return 0;
  }
     }
     if (ptr)
     {
                Packet_DecodeInt(ptr, &(packetStruct->PacketHeaders[i]), packetStruct->PacketData);
     }
     else
     {
                return 0;
     }
        }
    }
    return 1;
}

variable_types: struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } *


decompiled_code:
__int64 __fastcall RouteSuitabilityData_1_UpperBitsNotSet(unsigned __int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rdi
_QWORD *v4; // rdx
unsigned __int64 v5; // rdi

result = UpperBitsNotSet64(*a1, 15);
if ( (_DWORD)result )
{
v3 = *(_QWORD *)(v2 + 8);
result = UpperBitsNotSet64(v3, 2);
if ( (_DWORD)result )
{
switch ( v3 )
{
case 0uLL:
v5 = v4[2];
return UpperBitsNotSet64(v5, 8);
case 1uLL:
result = UpperBitsNotSet64(v4[3], 7);
break;
case 2uLL:
v5 = v4[4];
return UpperBitsNotSet64(v5, 8);
default:
result = 1LL;
break;
}
}
}
return result;
}

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

result = func0(*a1, 15);
if ( (_DWORD)result )
{
v3 = *(_QWORD *)(v2 + 8);
result = func0(v3, 2);
if ( (_DWORD)result )
{
switch ( v3 )
{
case 0uLL:
v5 = v4[2];
return func0(v5, 8);
case 1uLL:
result = func0(v4[3], 7);
break;
case 2uLL:
v5 = v4[4];
return func0(v5, 8);
default:
result = 1LL;
break;
}
}
}
return result;
}

original_code:
int RouteSuitabilityData_1_UpperBitsNotSet(const RouteSuitabilityData_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_SUITABILITY, 15);
    status = status && UpperBitsNotSet64(p->Q_SUITABILITY, 2) ;
    if (p->Q_SUITABILITY == 0)
    {
        status = status && UpperBitsNotSet64(p->M_LOADINGGAUGE, 8) ;
    }
    if (p->Q_SUITABILITY == 1)
    {
        status = status && UpperBitsNotSet64(p->M_AXLELOAD, 7) ;
    }
    if (p->Q_SUITABILITY == 2)
    {
        status = status && UpperBitsNotSet64(p->M_TRACTION, 8) ;
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RouteSuitabilityData_1_UpperBitsNotSet(struct RouteSuitabilityData_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_SUITABILITY, 15);
    status = status && UpperBitsNotSet64(p->Q_SUITABILITY, 2) ;
    if (p->Q_SUITABILITY == 0)
    {
        status = status && UpperBitsNotSet64(p->M_LOADINGGAUGE, 8) ;
    }
    if (p->Q_SUITABILITY == 1)
    {
        status = status && UpperBitsNotSet64(p->M_AXLELOAD, 7) ;
    }
    if (p->Q_SUITABILITY == 2)
    {
        status = status && UpperBitsNotSet64(p->M_TRACTION, 8) ;
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct RouteSuitabilityData_1 { unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; } *


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

if ( !(unsigned int)Bitstream_Normal(a2, 17LL) )
return (unsigned int)-1;
if ( !(unsigned int)RouteSuitabilityData_1_UpperBitsNotSet(a1) )
return (unsigned int)-2;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 2LL, a1[1]);
v2 = a1[1];
if ( v2 )
{
if ( v2 != 1 )
goto LABEL_5;
LABEL_8:
v3 = 1;
Bitstream_Write(a2, 7LL, a1[3]);
if ( a1[1] != 2 )
return v3;
goto LABEL_9;
}
Bitstream_Write(a2, 8LL, a1[2]);
v2 = a1[1];
if ( v2 == 1 )
goto LABEL_8;
LABEL_5:
v3 = 1;
if ( v2 != 2 )
return v3;
LABEL_9:
Bitstream_Write(a2, 8LL, a1[4]);
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 17LL) )
return (unsigned int)-1;
if ( !(unsigned int)func1(a1) )
return (unsigned int)-2;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 2LL, a1[1]);
v2 = a1[1];
if ( v2 )
{
if ( v2 != 1 )
goto LABEL_5;
LABEL_8:
v3 = 1;
Bitstream_Write(a2, 7LL, a1[3]);
if ( a1[1] != 2 )
return v3;
goto LABEL_9;
}
Bitstream_Write(a2, 8LL, a1[2]);
v2 = a1[1];
if ( v2 == 1 )
goto LABEL_8;
LABEL_5:
v3 = 1;
if ( v2 != 2 )
return v3;
LABEL_9:
Bitstream_Write(a2, 8LL, a1[4]);
return 1LL;
}

original_code:
int RouteSuitabilityData_1_EncodeBit(const RouteSuitabilityData_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 17))
    {
        if (RouteSuitabilityData_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_SUITABILITY);
            Bitstream_Write(stream, 2, p->Q_SUITABILITY);
            if (p->Q_SUITABILITY == 0)
            {
                Bitstream_Write(stream, 8, p->M_LOADINGGAUGE);
            }
            if (p->Q_SUITABILITY == 1)
            {
                Bitstream_Write(stream, 7, p->M_AXLELOAD);
            }
            if (p->Q_SUITABILITY == 2)
            {
                Bitstream_Write(stream, 8, p->M_TRACTION);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int RouteSuitabilityData_1_EncodeBit(struct RouteSuitabilityData_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 17))
    {
        if (RouteSuitabilityData_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_SUITABILITY);
            Bitstream_Write(stream, 2, p->Q_SUITABILITY);
            if (p->Q_SUITABILITY == 0)
            {
                Bitstream_Write(stream, 8, p->M_LOADINGGAUGE);
            }
            if (p->Q_SUITABILITY == 1)
            {
                Bitstream_Write(stream, 7, p->M_AXLELOAD);
            }
            if (p->Q_SUITABILITY == 2)
            {
                Bitstream_Write(stream, 8, p->M_TRACTION);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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

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


decompiled_code:
__int64 __fastcall RouteSuitabilityData_1_DecodeBit(_QWORD *a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v4; // rax

v2 = Bitstream_Normal(a2, 17LL);
if ( v2 )
{
*a1 = Bitstream_Read(a2, 15LL);
v4 = Bitstream_Read(a2, 2LL);
a1[1] = v4;
if ( !v4 )
{
a1[2] = Bitstream_Read(a2, 8LL);
v4 = a1[1];
}
if ( v4 == 1 )
{
a1[3] = Bitstream_Read(a2, 7LL);
v4 = a1[1];
}
v2 = 1;
if ( v4 == 2 )
a1[4] = Bitstream_Read(a2, 8LL);
}
return v2;
}

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

v2 = Bitstream_Normal(a2, 17LL);
if ( v2 )
{
*a1 = Bitstream_Read(a2, 15LL);
v4 = Bitstream_Read(a2, 2LL);
a1[1] = v4;
if ( !v4 )
{
a1[2] = Bitstream_Read(a2, 8LL);
v4 = a1[1];
}
if ( v4 == 1 )
{
a1[3] = Bitstream_Read(a2, 7LL);
v4 = a1[1];
}
v2 = 1;
if ( v4 == 2 )
a1[4] = Bitstream_Read(a2, 8LL);
}
return v2;
}

original_code:
int RouteSuitabilityData_1_DecodeBit(RouteSuitabilityData_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 17))
    {
        {
            p->D_SUITABILITY = Bitstream_Read(stream, 15);
        }
        {
            p->Q_SUITABILITY = Bitstream_Read(stream, 2);
        }
        if (p->Q_SUITABILITY == 0)
        {
            {
                p->M_LOADINGGAUGE = Bitstream_Read(stream, 8);
            }
        }
        if (p->Q_SUITABILITY == 1)
        {
            {
                p->M_AXLELOAD = Bitstream_Read(stream, 7);
            }
        }
        if (p->Q_SUITABILITY == 2)
        {
            {
                p->M_TRACTION = Bitstream_Read(stream, 8);
            }
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RouteSuitabilityData_1_DecodeBit(struct RouteSuitabilityData_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 17))
    {
        {
            p->D_SUITABILITY = Bitstream_Read(stream, 15);
        }
        {
            p->Q_SUITABILITY = Bitstream_Read(stream, 2);
        }
        if (p->Q_SUITABILITY == 0)
        {
            {
                p->M_LOADINGGAUGE = Bitstream_Read(stream, 8);
            }
        }
        if (p->Q_SUITABILITY == 1)
        {
            {
                p->M_AXLELOAD = Bitstream_Read(stream, 7);
            }
        }
        if (p->Q_SUITABILITY == 2)
        {
            {
                p->M_TRACTION = Bitstream_Read(stream, 8);
            }
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int RouteSuitabilityData_1_EncodeInt(const RouteSuitabilityData_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->D_SUITABILITY;
    stream[(*startAddress)++] = p->Q_SUITABILITY;
    stream[(*startAddress)++] = p->M_LOADINGGAUGE;
    stream[(*startAddress)++] = p->M_AXLELOAD;
    stream[(*startAddress)++] = p->M_TRACTION;
    return 1;
}

canonical_original_code:
int RouteSuitabilityData_1_EncodeInt(struct RouteSuitabilityData_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->D_SUITABILITY;
    stream[(*startAddress)++] = p->Q_SUITABILITY;
    stream[(*startAddress)++] = p->M_LOADINGGAUGE;
    stream[(*startAddress)++] = p->M_AXLELOAD;
    stream[(*startAddress)++] = p->M_TRACTION;
    return 1;
}

variable_types:
stream
int *


original_code:
int RouteSuitabilityData_1_DecodeInt(RouteSuitabilityData_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->D_SUITABILITY = stream[(*startAddress)++];
    p->Q_SUITABILITY = stream[(*startAddress)++];
    p->M_LOADINGGAUGE = stream[(*startAddress)++];
    p->M_AXLELOAD = stream[(*startAddress)++];
    p->M_TRACTION = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int RouteSuitabilityData_1_DecodeInt(struct RouteSuitabilityData_1 *p, int *startAddress, int *stream)
{
    p->D_SUITABILITY = stream[(*startAddress)++];
    p->Q_SUITABILITY = stream[(*startAddress)++];
    p->M_LOADINGGAUGE = stream[(*startAddress)++];
    p->M_AXLELOAD = stream[(*startAddress)++];
    p->M_TRACTION = stream[(*startAddress)++];
    return 1;
}


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


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

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

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

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

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

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall InfillLocationReference_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 InfillLocationReference_DecodeBit(InfillLocationReference* 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 InfillLocationReference_DecodeBit(struct InfillLocationReference *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 30))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_NEWCOUNTRY = Bitstream_Read(stream, 1);
        }
        if (p->Q_NEWCOUNTRY == 1)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int InfillLocationReference_EncodeInt(const InfillLocationReference* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 136;
    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 InfillLocationReference_EncodeInt(struct InfillLocationReference *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 136;
    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 MetadataElement_T_Common_Types_Pkg { int nid_packet; int q_dir; unsigned char valid; int startAddress; int endAddress; } *

variable_types: startAddress int


original_code:
int InfillLocationReference_DecodeInt(InfillLocationReference* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 136)
    {
         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 InfillLocationReference_DecodeInt(struct InfillLocationReference *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 136)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_NEWCOUNTRY = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( InfillLocationReferenceMemoryFreeList == -1 )
{
if ( (unsigned __int64)InfillLocationReferenceMemoryTop > 7 )
return 0LL;
v3 = 7 * InfillLocationReferenceMemoryTop++;
v0 = &InfillLocationReferenceMemory[v3];
}
else
{
v0 = &InfillLocationReferenceMemory[7 * InfillLocationReferenceMemoryFreeList];
InfillLocationReferenceMemoryFreeList = *v0;
}
InfillLocationReference_Init(v0);
return v1;
}

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

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

original_code:
InfillLocationReference* InfillLocationReference_New(void)
{
    InfillLocationReference* ptr;
    if (InfillLocationReferenceMemoryFreeList != (-1))
    {
        ptr = &InfillLocationReferenceMemory[InfillLocationReferenceMemoryFreeList];
        InfillLocationReferenceMemoryFreeList = InfillLocationReferenceMemory[InfillLocationReferenceMemoryFreeList].header.NID_PACKET;
    }
    else if (InfillLocationReferenceMemoryTop < 8)
    {
        ptr = &InfillLocationReferenceMemory[InfillLocationReferenceMemoryTop];
        InfillLocationReferenceMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    InfillLocationReference_Init(ptr);
    return ptr;
}

canonical_original_code:
struct InfillLocationReference *InfillLocationReference_New()
{
    struct InfillLocationReference *ptr;
    if (InfillLocationReferenceMemoryFreeList != (-1))
    {
        ptr = &InfillLocationReferenceMemory[InfillLocationReferenceMemoryFreeList];
        InfillLocationReferenceMemoryFreeList = InfillLocationReferenceMemory[InfillLocationReferenceMemoryFreeList].header.NID_PACKET;
    }
    else if (InfillLocationReferenceMemoryTop < 8)
    {
        ptr = &InfillLocationReferenceMemory[InfillLocationReferenceMemoryTop];
        InfillLocationReferenceMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    InfillLocationReference_Init(ptr);
    return ptr;
}

return_type: struct InfillLocationReference { 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 InfillLocationReference_Delete(_QWORD *a1)
{
__int64 result; // rax

*a1 = InfillLocationReferenceMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
InfillLocationReferenceMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL * (a1 - InfillLocationReferenceMemory);
return result;
}

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

*a1 = InfillLocationReferenceMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
InfillLocationReferenceMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL * (a1 - InfillLocationReferenceMemory);
return result;
}

original_code:
void InfillLocationReference_Delete(InfillLocationReference* ptr)
{
    ptr->header.NID_PACKET = InfillLocationReferenceMemoryFreeList;
    InfillLocationReferenceMemoryFreeList = ptr - InfillLocationReferenceMemory;
}

canonical_original_code:
void InfillLocationReference_Delete(struct InfillLocationReference *ptr)
{
    ptr->header.NID_PACKET = InfillLocationReferenceMemoryFreeList;
    InfillLocationReferenceMemoryFreeList = ptr - InfillLocationReferenceMemory;
}


decompiled_code:
_BOOL8 __fastcall Level23MovementAuthority_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v2; // eax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // rbx
_BOOL4 v6; // eax
unsigned __int64 v7; // rdi
int v8; // eax

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

original_code:
int Level23MovementAuthority_UpperBitsNotSet(const Level23MovementAuthority* 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_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 && Level23MovementAuthority_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 Level23MovementAuthority_UpperBitsNotSet(struct Level23MovementAuthority *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_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 && Level23MovementAuthority_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 Level23MovementAuthority { 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_LOA; unsigned long T_LOA; unsigned long N_ITER_1; struct Level23MovementAuthority_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: status int

user_defined_types: struct Level23MovementAuthority { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long V_LOA; unsigned long T_LOA; unsigned long N_ITER_1; struct Level23MovementAuthority_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 Level23MovementAuthority_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rdi

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

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

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

original_code:
int Level23MovementAuthority_EncodeBit(const Level23MovementAuthority* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 177))
    {
        if (Level23MovementAuthority_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_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)
            {
                Level23MovementAuthority_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 Level23MovementAuthority_EncodeBit(struct Level23MovementAuthority *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 177))
    {
        if (Level23MovementAuthority_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_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)
            {
                Level23MovementAuthority_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 Level23MovementAuthority_1 { unsigned long L_SECTION; unsigned long Q_SECTIONTIMER; unsigned long T_SECTIONTIMER; unsigned long D_SECTIONTIMERSTOPLOC; }


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

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

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

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

original_code:
int Level23MovementAuthority_DecodeBit(Level23MovementAuthority* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 177))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            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)
        {
            Level23MovementAuthority_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 Level23MovementAuthority_DecodeBit(struct Level23MovementAuthority *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 177))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            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)
        {
            Level23MovementAuthority_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 Level23MovementAuthority_EncodeInt(const Level23MovementAuthority* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 15;
    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_LOA;
    stream[startAddress++] = p->T_LOA;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        Level23MovementAuthority_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 Level23MovementAuthority_EncodeInt(struct Level23MovementAuthority *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 15;
    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_LOA;
    stream[startAddress++] = p->T_LOA;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        Level23MovementAuthority_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 Level23MovementAuthority_DecodeInt(Level23MovementAuthority* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 15)
    {
         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_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)
    {
        Level23MovementAuthority_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 Level23MovementAuthority_DecodeInt(struct Level23MovementAuthority *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 15)
    {
         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_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)
    {
        Level23MovementAuthority_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 Level23MovementAuthority_New()
{
__int64 *v0; // r8
__int64 v1; // r8
__int64 v3; // r8

if ( Level23MovementAuthorityMemoryFreeList == -1 )
{
if ( (unsigned __int64)Level23MovementAuthorityMemoryTop > 7 )
return 0LL;
v3 = 147 * Level23MovementAuthorityMemoryTop++;
v0 = &Level23MovementAuthorityMemory[v3];
}
else
{
v0 = &Level23MovementAuthorityMemory[147 * Level23MovementAuthorityMemoryFreeList];
Level23MovementAuthorityMemoryFreeList = *v0;
}
Level23MovementAuthority_Init(v0);
return v1;
}

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

if ( Level23MovementAuthorityMemoryFreeList == -1 )
{
if ( (unsigned __int64)Level23MovementAuthorityMemoryTop > 7 )
return 0LL;
v3 = 147 * Level23MovementAuthorityMemoryTop++;
v0 = &Level23MovementAuthorityMemory[v3];
}
else
{
v0 = &Level23MovementAuthorityMemory[147 * Level23MovementAuthorityMemoryFreeList];
Level23MovementAuthorityMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
Level23MovementAuthority* Level23MovementAuthority_New(void)
{
    Level23MovementAuthority* ptr;
    if (Level23MovementAuthorityMemoryFreeList != (-1))
    {
        ptr = &Level23MovementAuthorityMemory[Level23MovementAuthorityMemoryFreeList];
        Level23MovementAuthorityMemoryFreeList = Level23MovementAuthorityMemory[Level23MovementAuthorityMemoryFreeList].header.NID_PACKET;
    }
    else if (Level23MovementAuthorityMemoryTop < 8)
    {
        ptr = &Level23MovementAuthorityMemory[Level23MovementAuthorityMemoryTop];
        Level23MovementAuthorityMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    Level23MovementAuthority_Init(ptr);
    return ptr;
}

canonical_original_code:
struct Level23MovementAuthority *Level23MovementAuthority_New()
{
    struct Level23MovementAuthority *ptr;
    if (Level23MovementAuthorityMemoryFreeList != (-1))
    {
        ptr = &Level23MovementAuthorityMemory[Level23MovementAuthorityMemoryFreeList];
        Level23MovementAuthorityMemoryFreeList = Level23MovementAuthorityMemory[Level23MovementAuthorityMemoryFreeList].header.NID_PACKET;
    }
    else if (Level23MovementAuthorityMemoryTop < 8)
    {
        ptr = &Level23MovementAuthorityMemory[Level23MovementAuthorityMemoryTop];
        Level23MovementAuthorityMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    Level23MovementAuthority_Init(ptr);
    return ptr;
}

return_type: struct Level23MovementAuthority { 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_LOA; unsigned long T_LOA; unsigned long N_ITER_1; struct Level23MovementAuthority_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; } *