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

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

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

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

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

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

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


repo: openETCS/dataDictionary

original_code:
int RouteSuitabilityData_EncodeInt(const RouteSuitabilityData* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 70;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->Q_TRACKINIT;
    stream[startAddress++] = p->D_TRACKINIT;
    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;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        RouteSuitabilityData_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int RouteSuitabilityData_EncodeInt(struct RouteSuitabilityData *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 70;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->Q_TRACKINIT;
    stream[startAddress++] = p->D_TRACKINIT;
    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;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        RouteSuitabilityData_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

variable_types: struct RouteSuitabilityData { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_TRACKINIT; unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; unsigned long N_ITER_1; struct RouteSuitabilityData_1 { unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; } sub_1[31]; } *

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

variable_types:
i
unsigned int

return_type: int

user_defined_types: struct RouteSuitabilityData { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_TRACKINIT; unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; unsigned long N_ITER_1; struct RouteSuitabilityData_1 sub_1[31]; }


original_code:
int RouteSuitabilityData_DecodeInt(RouteSuitabilityData* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 70)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->Q_TRACKINIT = stream[startAddress++];
    p->D_TRACKINIT = 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 = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        RouteSuitabilityData_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int RouteSuitabilityData_DecodeInt(struct RouteSuitabilityData *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 70)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->Q_TRACKINIT = stream[startAddress++];
    p->D_TRACKINIT = 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 = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        RouteSuitabilityData_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

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

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

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 RouteSuitabilityData_New()
{
__int64 *v0; // r8
__int64 v1; // r8
__int64 v3; // r8

if ( RouteSuitabilityDataMemoryFreeList == -1 )
{
if ( (unsigned __int64)RouteSuitabilityDataMemoryTop > 7 )
return 0LL;
v3 = 168 * RouteSuitabilityDataMemoryTop++;
v0 = &RouteSuitabilityDataMemory[v3];
}
else
{
v0 = &RouteSuitabilityDataMemory[168 * RouteSuitabilityDataMemoryFreeList];
RouteSuitabilityDataMemoryFreeList = *v0;
}
RouteSuitabilityData_Init(v0);
return v1;
}

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

if ( RouteSuitabilityDataMemoryFreeList == -1 )
{
if ( (unsigned __int64)RouteSuitabilityDataMemoryTop > 7 )
return 0LL;
v3 = 168 * RouteSuitabilityDataMemoryTop++;
v0 = &RouteSuitabilityDataMemory[v3];
}
else
{
v0 = &RouteSuitabilityDataMemory[168 * RouteSuitabilityDataMemoryFreeList];
RouteSuitabilityDataMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
RouteSuitabilityData* RouteSuitabilityData_New(void)
{
    RouteSuitabilityData* ptr;
    if (RouteSuitabilityDataMemoryFreeList != (-1))
    {
        ptr = &RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryFreeList];
        RouteSuitabilityDataMemoryFreeList = RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryFreeList].header.NID_PACKET;
    }
    else if (RouteSuitabilityDataMemoryTop < 8)
    {
        ptr = &RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryTop];
        RouteSuitabilityDataMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RouteSuitabilityData_Init(ptr);
    return ptr;
}

canonical_original_code:
struct RouteSuitabilityData *RouteSuitabilityData_New()
{
    struct RouteSuitabilityData *ptr;
    if (RouteSuitabilityDataMemoryFreeList != (-1))
    {
        ptr = &RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryFreeList];
        RouteSuitabilityDataMemoryFreeList = RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryFreeList].header.NID_PACKET;
    }
    else if (RouteSuitabilityDataMemoryTop < 8)
    {
        ptr = &RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryTop];
        RouteSuitabilityDataMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RouteSuitabilityData_Init(ptr);
    return ptr;
}

return_type: struct RouteSuitabilityData { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_TRACKINIT; unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; unsigned long N_ITER_1; struct RouteSuitabilityData_1 { unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; } sub_1[31]; } *


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

*(_QWORD *)a1 = RouteSuitabilityDataMemoryFreeList;
result = 0xCF3CF3CF3CF3CF3DLL;
RouteSuitabilityDataMemoryFreeList = 0xCF3CF3CF3CF3CF3DLL * ((a1 - (char *)RouteSuitabilityDataMemory) >> 6);
return result;
}

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

*(_QWORD *)a1 = RouteSuitabilityDataMemoryFreeList;
result = 0xCF3CF3CF3CF3CF3DLL;
RouteSuitabilityDataMemoryFreeList = 0xCF3CF3CF3CF3CF3DLL * ((a1 - (char *)RouteSuitabilityDataMemory) >> 6);
return result;
}

original_code:
void RouteSuitabilityData_Delete(RouteSuitabilityData* ptr)
{
    ptr->header.NID_PACKET = RouteSuitabilityDataMemoryFreeList;
    RouteSuitabilityDataMemoryFreeList = ptr - RouteSuitabilityDataMemory;
}

canonical_original_code:
void RouteSuitabilityData_Delete(struct RouteSuitabilityData *ptr)
{
    ptr->header.NID_PACKET = RouteSuitabilityDataMemoryFreeList;
    RouteSuitabilityDataMemoryFreeList = ptr - RouteSuitabilityDataMemory;
}

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

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

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

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

original_code:
int EOLMPacket_UpperBitsNotSet(const EOLMPacket* 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->NID_LOOP, 14);
    status = status && UpperBitsNotSet64(p->D_LOOP, 15);
    status = status && UpperBitsNotSet64(p->L_LOOP, 15);
    status = status && UpperBitsNotSet64(p->Q_LOOPDIR, 1) ;
    status = status && UpperBitsNotSet64(p->Q_SSCODE, 4) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int EOLMPacket_UpperBitsNotSet(struct EOLMPacket *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->NID_LOOP, 14);
    status = status && UpperBitsNotSet64(p->D_LOOP, 15);
    status = status && UpperBitsNotSet64(p->L_LOOP, 15);
    status = status && UpperBitsNotSet64(p->Q_LOOPDIR, 1) ;
    status = status && UpperBitsNotSet64(p->Q_SSCODE, 4) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct EOLMPacket { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LOOP; unsigned long D_LOOP; unsigned long L_LOOP; unsigned long Q_LOOPDIR; unsigned long Q_SSCODE; } *

variable_types: status int

user_defined_types: struct EOLMPacket { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LOOP; unsigned long D_LOOP; unsigned long L_LOOP; unsigned long Q_LOOPDIR; unsigned long Q_SSCODE; }


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

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

original_code:
int EOLMPacket_EncodeBit(const EOLMPacket* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 66))
    {
        if (EOLMPacket_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, 14, p->NID_LOOP);
            Bitstream_Write(stream, 15, p->D_LOOP);
            Bitstream_Write(stream, 15, p->L_LOOP);
            Bitstream_Write(stream, 1, p->Q_LOOPDIR);
            Bitstream_Write(stream, 4, p->Q_SSCODE);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int EOLMPacket_EncodeBit(struct EOLMPacket *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 66))
    {
        if (EOLMPacket_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, 14, p->NID_LOOP);
            Bitstream_Write(stream, 15, p->D_LOOP);
            Bitstream_Write(stream, 15, p->L_LOOP);
            Bitstream_Write(stream, 1, p->Q_LOOPDIR);
            Bitstream_Write(stream, 4, p->Q_SSCODE);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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


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

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

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

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

original_code:
int EOLMPacket_DecodeBit(EOLMPacket* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 66))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_LOOP = Bitstream_Read(stream, 14);
        }
        {
            p->D_LOOP = Bitstream_Read(stream, 15);
        }
        {
            p->L_LOOP = Bitstream_Read(stream, 15);
        }
        {
            p->Q_LOOPDIR = Bitstream_Read(stream, 1);
        }
        {
            p->Q_SSCODE = Bitstream_Read(stream, 4);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int EOLMPacket_DecodeBit(struct EOLMPacket *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 66))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_LOOP = Bitstream_Read(stream, 14);
        }
        {
            p->D_LOOP = Bitstream_Read(stream, 15);
        }
        {
            p->L_LOOP = Bitstream_Read(stream, 15);
        }
        {
            p->Q_LOOPDIR = Bitstream_Read(stream, 1);
        }
        {
            p->Q_SSCODE = Bitstream_Read(stream, 4);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int EOLMPacket_EncodeInt(const EOLMPacket* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 134;
    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->NID_LOOP;
    stream[startAddress++] = p->D_LOOP;
    stream[startAddress++] = p->L_LOOP;
    stream[startAddress++] = p->Q_LOOPDIR;
    stream[startAddress++] = p->Q_SSCODE;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int EOLMPacket_EncodeInt(struct EOLMPacket *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 134;
    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->NID_LOOP;
    stream[startAddress++] = p->D_LOOP;
    stream[startAddress++] = p->L_LOOP;
    stream[startAddress++] = p->Q_LOOPDIR;
    stream[startAddress++] = p->Q_SSCODE;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int EOLMPacket_DecodeInt(EOLMPacket* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 134)
    {
         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->NID_LOOP = stream[startAddress++];
    p->D_LOOP = stream[startAddress++];
    p->L_LOOP = stream[startAddress++];
    p->Q_LOOPDIR = stream[startAddress++];
    p->Q_SSCODE = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int EOLMPacket_DecodeInt(struct EOLMPacket *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 134)
    {
         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->NID_LOOP = stream[startAddress++];
    p->D_LOOP = stream[startAddress++];
    p->L_LOOP = stream[startAddress++];
    p->Q_LOOPDIR = stream[startAddress++];
    p->Q_SSCODE = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( EOLMPacketMemoryFreeList == -1 )
{
if ( (unsigned __int64)EOLMPacketMemoryTop <= 7 )
{
v1 = 10 * EOLMPacketMemoryTop++;
EOLMPacket_Init(&EOLMPacketMemory[v1]);
}
}
else
{
v0 = &EOLMPacketMemory[10 * EOLMPacketMemoryFreeList];
EOLMPacketMemoryFreeList = *v0;
EOLMPacket_Init(v0);
}
}

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

if ( EOLMPacketMemoryFreeList == -1 )
{
if ( (unsigned __int64)EOLMPacketMemoryTop <= 7 )
{
v1 = 10 * EOLMPacketMemoryTop++;
func1(&EOLMPacketMemory[v1]);
}
}
else
{
v0 = &EOLMPacketMemory[10 * EOLMPacketMemoryFreeList];
EOLMPacketMemoryFreeList = *v0;
func1(v0);
}
}

original_code:
EOLMPacket* EOLMPacket_New(void)
{
    EOLMPacket* ptr;
    if (EOLMPacketMemoryFreeList != (-1))
    {
        ptr = &EOLMPacketMemory[EOLMPacketMemoryFreeList];
        EOLMPacketMemoryFreeList = EOLMPacketMemory[EOLMPacketMemoryFreeList].header.NID_PACKET;
    }
    else if (EOLMPacketMemoryTop < 8)
    {
        ptr = &EOLMPacketMemory[EOLMPacketMemoryTop];
        EOLMPacketMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    EOLMPacket_Init(ptr);
    return ptr;
}

canonical_original_code:
struct EOLMPacket *EOLMPacket_New()
{
    struct EOLMPacket *ptr;
    if (EOLMPacketMemoryFreeList != (-1))
    {
        ptr = &EOLMPacketMemory[EOLMPacketMemoryFreeList];
        EOLMPacketMemoryFreeList = EOLMPacketMemory[EOLMPacketMemoryFreeList].header.NID_PACKET;
    }
    else if (EOLMPacketMemoryTop < 8)
    {
        ptr = &EOLMPacketMemory[EOLMPacketMemoryTop];
        EOLMPacketMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    EOLMPacket_Init(ptr);
    return ptr;
}

return_type: struct EOLMPacket { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LOOP; unsigned long D_LOOP; unsigned long L_LOOP; unsigned long Q_LOOPDIR; unsigned long Q_SSCODE; } *


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

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

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

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

original_code:
void EOLMPacket_Delete(EOLMPacket* ptr)
{
    ptr->header.NID_PACKET = EOLMPacketMemoryFreeList;
    EOLMPacketMemoryFreeList = ptr - EOLMPacketMemory;
}

canonical_original_code:
void EOLMPacket_Delete(struct EOLMPacket *ptr)
{
    ptr->header.NID_PACKET = EOLMPacketMemoryFreeList;
    EOLMPacketMemoryFreeList = ptr - EOLMPacketMemory;
}


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

v2 = UpperBitsNotSet64(a1[2], 2);
v3 = a1[7];
if ( !v2
|| !UpperBitsNotSet64(a1[3], 13)
|| !UpperBitsNotSet64(a1[4], 2)
|| !UpperBitsNotSet64(a1[5], 15)
|| !UpperBitsNotSet64(a1[6], 15) )
{
if ( !v3 )
return 0LL;
LODWORD(v5) = 0;
do
{
LABEL_14:
if ( (unsigned int)(v5 + 1) >= v3 )
break;
v5 = (unsigned int)(v5 + 2);
}
while ( v5 < v3 );
return 0LL;
}
v4 = UpperBitsNotSet64(v3, 5);
if ( v3 )
{
LODWORD(v5) = 0;
if ( v4 )
{
v6 = 0LL;
while ( 1 )
{
v7 = TrackConditionBigMetalMasses_1_UpperBitsNotSet(&a1[2 * v6 + 8]);
v6 = (unsigned int)(v5 + 1);
LODWORD(v5) = v5 + 1;
if ( !v7 )
break;
if ( a1[7] <= v6 )
return 1LL;
}
v3 = a1[7];
if ( v3 > v6 )
goto LABEL_14;
return 0LL;
}
goto LABEL_14;
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(unsigned __int64 *a1)
{
_BOOL4 v2; // eax
unsigned __int64 v3; // rdx
_BOOL4 v4; // eax
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rdi
int v7; // eax

v2 = func0(a1[2], 2);
v3 = a1[7];
if ( !v2
|| !func0(a1[3], 13)
|| !func0(a1[4], 2)
|| !func0(a1[5], 15)
|| !func0(a1[6], 15) )
{
if ( !v3 )
return 0LL;
LODWORD(v5) = 0;
do
{
LABEL_14:
if ( (unsigned int)(v5 + 1) >= v3 )
break;
v5 = (unsigned int)(v5 + 2);
}
while ( v5 < v3 );
return 0LL;
}
v4 = func0(v3, 5);
if ( v3 )
{
LODWORD(v5) = 0;
if ( v4 )
{
v6 = 0LL;
while ( 1 )
{
v7 = TrackConditionBigMetalMasses_1_UpperBitsNotSet(&a1[2 * v6 + 8]);
v6 = (unsigned int)(v5 + 1);
LODWORD(v5) = v5 + 1;
if ( !v7 )
break;
if ( a1[7] <= v6 )
return 1LL;
}
v3 = a1[7];
if ( v3 > v6 )
goto LABEL_14;
return 0LL;
}
goto LABEL_14;
}
return v4;
}

original_code:
int TrackConditionBigMetalMasses_UpperBitsNotSet(const TrackConditionBigMetalMasses* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_TRACKCOND, 15);
    status = status && UpperBitsNotSet64(p->L_TRACKCOND, 15);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && TrackConditionBigMetalMasses_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TrackConditionBigMetalMasses_UpperBitsNotSet(struct TrackConditionBigMetalMasses *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_TRACKCOND, 15);
    status = status && UpperBitsNotSet64(p->L_TRACKCOND, 15);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && TrackConditionBigMetalMasses_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct TrackConditionBigMetalMasses { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; unsigned long N_ITER_1; struct TrackConditionBigMetalMasses_1 { unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; } sub_1[31]; } *

user_defined_types: struct TrackConditionBigMetalMasses { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; unsigned long N_ITER_1; struct TrackConditionBigMetalMasses_1 sub_1[31]; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 52LL) )
return 0xFFFFFFFFLL;
if ( !TrackConditionBigMetalMasses_UpperBitsNotSet(a1) )
return 4294967294LL;
v3 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 5LL, a1[7]);
v4 = 0LL;
if ( a1[7] )
{
do
{
TrackConditionBigMetalMasses_1_EncodeBit(&a1[2 * v4 + 8], a2);
v4 = ++v3;
}
while ( v3 < a1[7] );
}
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, 52LL) )
return 0xFFFFFFFFLL;
if ( !func3(a1) )
return 4294967294LL;
v3 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 5LL, a1[7]);
v4 = 0LL;
if ( a1[7] )
{
do
{
TrackConditionBigMetalMasses_1_EncodeBit(&a1[2 * v4 + 8], a2);
v4 = ++v3;
}
while ( v3 < a1[7] );
}
return 1LL;
}

original_code:
int TrackConditionBigMetalMasses_EncodeBit(const TrackConditionBigMetalMasses* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 52))
    {
        if (TrackConditionBigMetalMasses_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_TRACKCOND);
            Bitstream_Write(stream, 15, p->L_TRACKCOND);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                TrackConditionBigMetalMasses_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int TrackConditionBigMetalMasses_EncodeBit(struct TrackConditionBigMetalMasses *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 52))
    {
        if (TrackConditionBigMetalMasses_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_TRACKCOND);
            Bitstream_Write(stream, 15, p->L_TRACKCOND);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                TrackConditionBigMetalMasses_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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


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

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

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

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

original_code:
int TrackConditionBigMetalMasses_DecodeBit(TrackConditionBigMetalMasses* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 52))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_TRACKCOND = Bitstream_Read(stream, 15);
        }
        {
            p->L_TRACKCOND = Bitstream_Read(stream, 15);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            TrackConditionBigMetalMasses_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TrackConditionBigMetalMasses_DecodeBit(struct TrackConditionBigMetalMasses *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 52))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_TRACKCOND = Bitstream_Read(stream, 15);
        }
        {
            p->L_TRACKCOND = Bitstream_Read(stream, 15);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            TrackConditionBigMetalMasses_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int TrackConditionBigMetalMasses_EncodeInt(const TrackConditionBigMetalMasses* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 67;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->D_TRACKCOND;
    stream[startAddress++] = p->L_TRACKCOND;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        TrackConditionBigMetalMasses_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int TrackConditionBigMetalMasses_EncodeInt(struct TrackConditionBigMetalMasses *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 67;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->D_TRACKCOND;
    stream[startAddress++] = p->L_TRACKCOND;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        TrackConditionBigMetalMasses_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int TrackConditionBigMetalMasses_DecodeInt(TrackConditionBigMetalMasses* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 67)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->D_TRACKCOND = stream[startAddress++];
    p->L_TRACKCOND = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        TrackConditionBigMetalMasses_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int TrackConditionBigMetalMasses_DecodeInt(struct TrackConditionBigMetalMasses *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 67)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->D_TRACKCOND = stream[startAddress++];
    p->L_TRACKCOND = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        TrackConditionBigMetalMasses_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( TrackConditionBigMetalMassesMemoryFreeList == -1 )
{
if ( (unsigned __int64)TrackConditionBigMetalMassesMemoryTop > 7 )
return 0LL;
v3 = 70 * TrackConditionBigMetalMassesMemoryTop++;
v0 = &TrackConditionBigMetalMassesMemory[v3];
}
else
{
v0 = &TrackConditionBigMetalMassesMemory[70 * TrackConditionBigMetalMassesMemoryFreeList];
TrackConditionBigMetalMassesMemoryFreeList = *v0;
}
TrackConditionBigMetalMasses_Init(v0);
return v1;
}

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

if ( TrackConditionBigMetalMassesMemoryFreeList == -1 )
{
if ( (unsigned __int64)TrackConditionBigMetalMassesMemoryTop > 7 )
return 0LL;
v3 = 70 * TrackConditionBigMetalMassesMemoryTop++;
v0 = &TrackConditionBigMetalMassesMemory[v3];
}
else
{
v0 = &TrackConditionBigMetalMassesMemory[70 * TrackConditionBigMetalMassesMemoryFreeList];
TrackConditionBigMetalMassesMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
TrackConditionBigMetalMasses* TrackConditionBigMetalMasses_New(void)
{
    TrackConditionBigMetalMasses* ptr;
    if (TrackConditionBigMetalMassesMemoryFreeList != (-1))
    {
        ptr = &TrackConditionBigMetalMassesMemory[TrackConditionBigMetalMassesMemoryFreeList];
        TrackConditionBigMetalMassesMemoryFreeList = TrackConditionBigMetalMassesMemory[TrackConditionBigMetalMassesMemoryFreeList].header.NID_PACKET;
    }
    else if (TrackConditionBigMetalMassesMemoryTop < 8)
    {
        ptr = &TrackConditionBigMetalMassesMemory[TrackConditionBigMetalMassesMemoryTop];
        TrackConditionBigMetalMassesMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    TrackConditionBigMetalMasses_Init(ptr);
    return ptr;
}

canonical_original_code:
struct TrackConditionBigMetalMasses *TrackConditionBigMetalMasses_New()
{
    struct TrackConditionBigMetalMasses *ptr;
    if (TrackConditionBigMetalMassesMemoryFreeList != (-1))
    {
        ptr = &TrackConditionBigMetalMassesMemory[TrackConditionBigMetalMassesMemoryFreeList];
        TrackConditionBigMetalMassesMemoryFreeList = TrackConditionBigMetalMassesMemory[TrackConditionBigMetalMassesMemoryFreeList].header.NID_PACKET;
    }
    else if (TrackConditionBigMetalMassesMemoryTop < 8)
    {
        ptr = &TrackConditionBigMetalMassesMemory[TrackConditionBigMetalMassesMemoryTop];
        TrackConditionBigMetalMassesMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    TrackConditionBigMetalMasses_Init(ptr);
    return ptr;
}

return_type: struct TrackConditionBigMetalMasses { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; unsigned long N_ITER_1; struct TrackConditionBigMetalMasses_1 { unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; } sub_1[31]; } *


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

*(_QWORD *)a1 = TrackConditionBigMetalMassesMemoryFreeList;
result = 0xAF8AF8AF8AF8AF8BLL;
TrackConditionBigMetalMassesMemoryFreeList = 0xAF8AF8AF8AF8AF8BLL
* ((a1 - (char *)TrackConditionBigMetalMassesMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = TrackConditionBigMetalMassesMemoryFreeList;
result = 0xAF8AF8AF8AF8AF8BLL;
TrackConditionBigMetalMassesMemoryFreeList = 0xAF8AF8AF8AF8AF8BLL
* ((a1 - (char *)TrackConditionBigMetalMassesMemory) >> 4);
return result;
}

original_code:
void TrackConditionBigMetalMasses_Delete(TrackConditionBigMetalMasses* ptr)
{
    ptr->header.NID_PACKET = TrackConditionBigMetalMassesMemoryFreeList;
    TrackConditionBigMetalMassesMemoryFreeList = ptr - TrackConditionBigMetalMassesMemory;
}

canonical_original_code:
void TrackConditionBigMetalMasses_Delete(struct TrackConditionBigMetalMasses *ptr)
{
    ptr->header.NID_PACKET = TrackConditionBigMetalMassesMemoryFreeList;
    TrackConditionBigMetalMassesMemoryFreeList = ptr - TrackConditionBigMetalMassesMemory;
}


decompiled_code:
_BOOL8 __fastcall NationalValues_1_UpperBitsNotSet(unsigned __int64 *a1)
{
return UpperBitsNotSet64_constprop_0(*a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int64 *a1)
{
return func0(*a1);
}

original_code:
int NationalValues_1_UpperBitsNotSet(const NationalValues_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->NID_C, 10);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int NationalValues_1_UpperBitsNotSet(struct NationalValues_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->NID_C, 10);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct NationalValues_1 { unsigned long NID_C; } *


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

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

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

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

user_defined_types: struct NationalValues_1 { unsigned long NID_C; }


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall NationalValues_1_EncodeInt(__int64 *a1, int *a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rcx

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

original_code:
int NationalValues_1_EncodeInt(const NationalValues_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->NID_C;
    return 1;
}

canonical_original_code:
int NationalValues_1_EncodeInt(struct NationalValues_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->NID_C;
    return 1;
}

variable_types:
startAddress
int *


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

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

original_code:
int NationalValues_1_DecodeInt(NationalValues_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->NID_C = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int NationalValues_1_DecodeInt(struct NationalValues_1 *p, int *startAddress, int *stream)
{
    p->NID_C = 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;
    }
}


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

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

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

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

original_code:
int RepositioningInformation_UpperBitsNotSet(const RepositioningInformation* 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->L_SECTION, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RepositioningInformation_UpperBitsNotSet(struct RepositioningInformation *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->L_SECTION, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct RepositioningInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long L_SECTION; } *

user_defined_types: struct RepositioningInformation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long L_SECTION; }


decompiled_code:
__int64 __fastcall RepositioningInformation_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 32LL) )
return 0xFFFFFFFFLL;
if ( !RepositioningInformation_UpperBitsNotSet((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
return 1LL;
}

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

original_code:
int RepositioningInformation_EncodeBit(const RepositioningInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 32))
    {
        if (RepositioningInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->L_SECTION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int RepositioningInformation_EncodeBit(struct RepositioningInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 32))
    {
        if (RepositioningInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->L_SECTION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

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

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

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

original_code:
int RepositioningInformation_DecodeBit(RepositioningInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 32))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->L_SECTION = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RepositioningInformation_DecodeBit(struct RepositioningInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 32))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->L_SECTION = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int RepositioningInformation_EncodeInt(const RepositioningInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 16;
    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->L_SECTION;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int RepositioningInformation_EncodeInt(struct RepositioningInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 16;
    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->L_SECTION;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int RepositioningInformation_DecodeInt(RepositioningInformation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 16)
    {
         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->L_SECTION = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int RepositioningInformation_DecodeInt(struct RepositioningInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 16)
    {
         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->L_SECTION = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( RepositioningInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)RepositioningInformationMemoryTop <= 7 )
{
v1 = 6 * RepositioningInformationMemoryTop++;
RepositioningInformation_Init(&RepositioningInformationMemory[v1]);
}
}
else
{
v0 = &RepositioningInformationMemory[6 * RepositioningInformationMemoryFreeList];
RepositioningInformationMemoryFreeList = *v0;
RepositioningInformation_Init(v0);
}
}

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

if ( RepositioningInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)RepositioningInformationMemoryTop <= 7 )
{
v1 = 6 * RepositioningInformationMemoryTop++;
func1(&RepositioningInformationMemory[v1]);
}
}
else
{
v0 = &RepositioningInformationMemory[6 * RepositioningInformationMemoryFreeList];
RepositioningInformationMemoryFreeList = *v0;
func1(v0);
}
}

original_code:
RepositioningInformation* RepositioningInformation_New(void)
{
    RepositioningInformation* ptr;
    if (RepositioningInformationMemoryFreeList != (-1))
    {
        ptr = &RepositioningInformationMemory[RepositioningInformationMemoryFreeList];
        RepositioningInformationMemoryFreeList = RepositioningInformationMemory[RepositioningInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (RepositioningInformationMemoryTop < 8)
    {
        ptr = &RepositioningInformationMemory[RepositioningInformationMemoryTop];
        RepositioningInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RepositioningInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct RepositioningInformation *RepositioningInformation_New()
{
    struct RepositioningInformation *ptr;
    if (RepositioningInformationMemoryFreeList != (-1))
    {
        ptr = &RepositioningInformationMemory[RepositioningInformationMemoryFreeList];
        RepositioningInformationMemoryFreeList = RepositioningInformationMemory[RepositioningInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (RepositioningInformationMemoryTop < 8)
    {
        ptr = &RepositioningInformationMemory[RepositioningInformationMemoryTop];
        RepositioningInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RepositioningInformation_Init(ptr);
    return ptr;
}

return_type: struct RepositioningInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long L_SECTION; } *


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

*(_QWORD *)a1 = RepositioningInformationMemoryFreeList;
result = 0xAAAAAAAAAAAAAAABLL;
RepositioningInformationMemoryFreeList = 0xAAAAAAAAAAAAAAABLL * ((a1 - (char *)RepositioningInformationMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = RepositioningInformationMemoryFreeList;
result = 0xAAAAAAAAAAAAAAABLL;
RepositioningInformationMemoryFreeList = 0xAAAAAAAAAAAAAAABLL * ((a1 - (char *)RepositioningInformationMemory) >> 4);
return result;
}

original_code:
void RepositioningInformation_Delete(RepositioningInformation* ptr)
{
    ptr->header.NID_PACKET = RepositioningInformationMemoryFreeList;
    RepositioningInformationMemoryFreeList = ptr - RepositioningInformationMemory;
}

canonical_original_code:
void RepositioningInformation_Delete(struct RepositioningInformation *ptr)
{
    ptr->header.NID_PACKET = RepositioningInformationMemoryFreeList;
    RepositioningInformationMemoryFreeList = ptr - RepositioningInformationMemory;
}


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

if ( !UpperBitsNotSet64(a1[2], 2)
|| !UpperBitsNotSet64(a1[3], 13)
|| !UpperBitsNotSet64(a1[4], 2)
|| !UpperBitsNotSet64(a1[5], 1)
|| v1 == 1 && !UpperBitsNotSet64(a1[6], 10)
|| !UpperBitsNotSet64(a1[7], 14)
|| !UpperBitsNotSet64(a1[8], 15)
|| !UpperBitsNotSet64(a1[9], 1)
|| !UpperBitsNotSet64(a1[10], 20) )
{
v3 = a1[11];
if ( !v3 )
return 0LL;
LODWORD(v4) = 0;
do
{
LABEL_19:
if ( (unsigned int)(v4 + 1) >= v3 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v3 );
return 0LL;
}
v2 = UpperBitsNotSet64(a1[11], 5);
if ( v3 )
{
LODWORD(v4) = 0;
if ( v2 )
{
v5 = 0LL;
while ( 1 )
{
v6 = GeographicalPositionInformation_1_UpperBitsNotSet(&a1[6 * v5 + 12]);
v5 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v6 )
break;
if ( v5 >= a1[11] )
return 1LL;
}
v3 = a1[11];
if ( v5 < v3 )
goto LABEL_19;
return 0LL;
}
goto LABEL_19;
}
return v2;
}

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

if ( !func0(a1[2], 2)
|| !func0(a1[3], 13)
|| !func0(a1[4], 2)
|| !func0(a1[5], 1)
|| v1 == 1 && !func0(a1[6], 10)
|| !func0(a1[7], 14)
|| !func0(a1[8], 15)
|| !func0(a1[9], 1)
|| !func0(a1[10], 20) )
{
v3 = a1[11];
if ( !v3 )
return 0LL;
LODWORD(v4) = 0;
do
{
LABEL_19:
if ( (unsigned int)(v4 + 1) >= v3 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v3 );
return 0LL;
}
v2 = func0(a1[11], 5);
if ( v3 )
{
LODWORD(v4) = 0;
if ( v2 )
{
v5 = 0LL;
while ( 1 )
{
v6 = GeographicalPositionInformation_1_UpperBitsNotSet(&a1[6 * v5 + 12]);
v5 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v6 )
break;
if ( v5 >= a1[11] )
return 1LL;
}
v3 = a1[11];
if ( v5 < v3 )
goto LABEL_19;
return 0LL;
}
goto LABEL_19;
}
return v2;
}

original_code:
int GeographicalPositionInformation_UpperBitsNotSet(const GeographicalPositionInformation* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->Q_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);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && GeographicalPositionInformation_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int GeographicalPositionInformation_UpperBitsNotSet(struct GeographicalPositionInformation *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->Q_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);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && GeographicalPositionInformation_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct GeographicalPositionInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long D_POSOFF; unsigned long Q_MPOSITION; unsigned long M_POSITION; unsigned long N_ITER_1; 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; } sub_1[31]; } *

user_defined_types: struct GeographicalPositionInformation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long D_POSOFF; unsigned long Q_MPOSITION; unsigned long M_POSITION; unsigned long N_ITER_1; struct GeographicalPositionInformation_1 sub_1[31]; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 73LL) )
return 0xFFFFFFFFLL;
if ( !GeographicalPositionInformation_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 1LL, a1[5]);
if ( a1[5] == 1 )
Bitstream_Write(a2, 10LL, a1[6]);
v2 = 0;
Bitstream_Write(a2, 14LL, a1[7]);
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 1LL, a1[9]);
Bitstream_Write(a2, 20LL, a1[10]);
Bitstream_Write(a2, 5LL, a1[11]);
v3 = 0LL;
if ( a1[11] )
{
do
{
GeographicalPositionInformation_1_EncodeBit(&a1[6 * v3 + 12], a2);
v3 = ++v2;
}
while ( v2 < a1[11] );
}
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 73LL) )
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, 1LL, a1[5]);
if ( a1[5] == 1 )
Bitstream_Write(a2, 10LL, a1[6]);
v2 = 0;
Bitstream_Write(a2, 14LL, a1[7]);
Bitstream_Write(a2, 15LL, a1[8]);
Bitstream_Write(a2, 1LL, a1[9]);
Bitstream_Write(a2, 20LL, a1[10]);
Bitstream_Write(a2, 5LL, a1[11]);
v3 = 0LL;
if ( a1[11] )
{
do
{
GeographicalPositionInformation_1_EncodeBit(&a1[6 * v3 + 12], a2);
v3 = ++v2;
}
while ( v2 < a1[11] );
}
return 1LL;
}

original_code:
int GeographicalPositionInformation_EncodeBit(const GeographicalPositionInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 73))
    {
        if (GeographicalPositionInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_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);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                GeographicalPositionInformation_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int GeographicalPositionInformation_EncodeBit(struct GeographicalPositionInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 73))
    {
        if (GeographicalPositionInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_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);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                GeographicalPositionInformation_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            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; }


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

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

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

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

original_code:
int GeographicalPositionInformation_DecodeBit(GeographicalPositionInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 73))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            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);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            GeographicalPositionInformation_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int GeographicalPositionInformation_DecodeBit(struct GeographicalPositionInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 73))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            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);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            GeographicalPositionInformation_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int GeographicalPositionInformation_EncodeInt(const GeographicalPositionInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 79;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->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;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        GeographicalPositionInformation_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int GeographicalPositionInformation_EncodeInt(struct GeographicalPositionInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 79;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->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;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        GeographicalPositionInformation_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int GeographicalPositionInformation_DecodeInt(GeographicalPositionInformation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 79)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->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++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        GeographicalPositionInformation_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int GeographicalPositionInformation_DecodeInt(struct GeographicalPositionInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 79)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->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++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        GeographicalPositionInformation_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( GeographicalPositionInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)GeographicalPositionInformationMemoryTop > 7 )
return 0LL;
v3 = 198 * GeographicalPositionInformationMemoryTop++;
v0 = &GeographicalPositionInformationMemory[v3];
}
else
{
v0 = &GeographicalPositionInformationMemory[198 * GeographicalPositionInformationMemoryFreeList];
GeographicalPositionInformationMemoryFreeList = *v0;
}
GeographicalPositionInformation_Init(v0);
return v1;
}

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

if ( GeographicalPositionInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)GeographicalPositionInformationMemoryTop > 7 )
return 0LL;
v3 = 198 * GeographicalPositionInformationMemoryTop++;
v0 = &GeographicalPositionInformationMemory[v3];
}
else
{
v0 = &GeographicalPositionInformationMemory[198 * GeographicalPositionInformationMemoryFreeList];
GeographicalPositionInformationMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
GeographicalPositionInformation* GeographicalPositionInformation_New(void)
{
    GeographicalPositionInformation* ptr;
    if (GeographicalPositionInformationMemoryFreeList != (-1))
    {
        ptr = &GeographicalPositionInformationMemory[GeographicalPositionInformationMemoryFreeList];
        GeographicalPositionInformationMemoryFreeList = GeographicalPositionInformationMemory[GeographicalPositionInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (GeographicalPositionInformationMemoryTop < 8)
    {
        ptr = &GeographicalPositionInformationMemory[GeographicalPositionInformationMemoryTop];
        GeographicalPositionInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    GeographicalPositionInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct GeographicalPositionInformation *GeographicalPositionInformation_New()
{
    struct GeographicalPositionInformation *ptr;
    if (GeographicalPositionInformationMemoryFreeList != (-1))
    {
        ptr = &GeographicalPositionInformationMemory[GeographicalPositionInformationMemoryFreeList];
        GeographicalPositionInformationMemoryFreeList = GeographicalPositionInformationMemory[GeographicalPositionInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (GeographicalPositionInformationMemoryTop < 8)
    {
        ptr = &GeographicalPositionInformationMemory[GeographicalPositionInformationMemoryTop];
        GeographicalPositionInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    GeographicalPositionInformation_Init(ptr);
    return ptr;
}

return_type: struct GeographicalPositionInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long D_POSOFF; unsigned long Q_MPOSITION; unsigned long M_POSITION; unsigned long N_ITER_1; 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; } sub_1[31]; } *


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

*(_QWORD *)a1 = GeographicalPositionInformationMemoryFreeList;
result = 0xAFD6A052BF5A814BLL;
GeographicalPositionInformationMemoryFreeList = 0xAFD6A052BF5A814BLL
* ((a1 - (char *)GeographicalPositionInformationMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = GeographicalPositionInformationMemoryFreeList;
result = 0xAFD6A052BF5A814BLL;
GeographicalPositionInformationMemoryFreeList = 0xAFD6A052BF5A814BLL
* ((a1 - (char *)GeographicalPositionInformationMemory) >> 4);
return result;
}

original_code:
void GeographicalPositionInformation_Delete(GeographicalPositionInformation* ptr)
{
    ptr->header.NID_PACKET = GeographicalPositionInformationMemoryFreeList;
    GeographicalPositionInformationMemoryFreeList = ptr - GeographicalPositionInformationMemory;
}

canonical_original_code:
void GeographicalPositionInformation_Delete(struct GeographicalPositionInformation *ptr)
{
    ptr->header.NID_PACKET = GeographicalPositionInformationMemoryFreeList;
    GeographicalPositionInformationMemoryFreeList = ptr - GeographicalPositionInformationMemory;
}


decompiled_code:
_BOOL8 __fastcall DefaultBaliseLoopOrRIUInformation_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 2);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 13);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx

result = func0(*(_QWORD *)(a1 + 16), 2);
if ( result )
result = func0(*(_QWORD *)(v2 + 24), 13);
return result;
}

original_code:
int DefaultBaliseLoopOrRIUInformation_UpperBitsNotSet(const DefaultBaliseLoopOrRIUInformation* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int DefaultBaliseLoopOrRIUInformation_UpperBitsNotSet(struct DefaultBaliseLoopOrRIUInformation *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct DefaultBaliseLoopOrRIUInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; } *

user_defined_types: struct DefaultBaliseLoopOrRIUInformation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; }


decompiled_code:
__int64 __fastcall DefaultBaliseLoopOrRIUInformation_EncodeBit(__int64 a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 15LL) )
return 0xFFFFFFFFLL;
if ( !DefaultBaliseLoopOrRIUInformation_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, *(_QWORD *)(a1 + 16));
Bitstream_Write(a2, 13LL, *(_QWORD *)(a1 + 24));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 15LL) )
return 0xFFFFFFFFLL;
if ( !func2(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, *(_QWORD *)(a1 + 16));
Bitstream_Write(a2, 13LL, *(_QWORD *)(a1 + 24));
return 1LL;
}

original_code:
int DefaultBaliseLoopOrRIUInformation_EncodeBit(const DefaultBaliseLoopOrRIUInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        if (DefaultBaliseLoopOrRIUInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int DefaultBaliseLoopOrRIUInformation_EncodeBit(struct DefaultBaliseLoopOrRIUInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        if (DefaultBaliseLoopOrRIUInformation_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

result = Bitstream_Normal(a2, 15LL);
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 16) = Bitstream_Read(a2, 2LL);
*(_QWORD *)(a1 + 24) = Bitstream_Read(a2, 13LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 15LL);
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 16) = Bitstream_Read(a2, 2LL);
*(_QWORD *)(a1 + 24) = Bitstream_Read(a2, 13LL);
result = 1LL;
}
return result;
}

original_code:
int DefaultBaliseLoopOrRIUInformation_DecodeBit(DefaultBaliseLoopOrRIUInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int DefaultBaliseLoopOrRIUInformation_DecodeBit(struct DefaultBaliseLoopOrRIUInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int DefaultBaliseLoopOrRIUInformation_EncodeInt(const DefaultBaliseLoopOrRIUInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 254;
    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;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int DefaultBaliseLoopOrRIUInformation_EncodeInt(struct DefaultBaliseLoopOrRIUInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 254;
    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;
    data->endAddress = startAddress-1;
    return 1;
}


decompiled_code:
_BOOL8 __fastcall DefaultBaliseLoopOrRIUInformation_DecodeInt(_QWORD *a1, _DWORD *a2, __int64 a3)
{
_BOOL8 result; // rax
__int64 v4; // rcx
bool v5; // zf
__int64 v6; // r8
__int64 v7; // rdx

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

original_code:
int DefaultBaliseLoopOrRIUInformation_DecodeInt(DefaultBaliseLoopOrRIUInformation* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 254)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int DefaultBaliseLoopOrRIUInformation_DecodeInt(struct DefaultBaliseLoopOrRIUInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 254)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( DefaultBaliseLoopOrRIUInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)DefaultBaliseLoopOrRIUInformationMemoryTop > 7 )
return 0LL;
v3 = 4 * DefaultBaliseLoopOrRIUInformationMemoryTop++;
v0 = &DefaultBaliseLoopOrRIUInformationMemory[v3];
}
else
{
v0 = &DefaultBaliseLoopOrRIUInformationMemory[4 * DefaultBaliseLoopOrRIUInformationMemoryFreeList];
DefaultBaliseLoopOrRIUInformationMemoryFreeList = *v0;
}
DefaultBaliseLoopOrRIUInformation_Init(v0);
return v1;
}

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

if ( DefaultBaliseLoopOrRIUInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)DefaultBaliseLoopOrRIUInformationMemoryTop > 7 )
return 0LL;
v3 = 4 * DefaultBaliseLoopOrRIUInformationMemoryTop++;
v0 = &DefaultBaliseLoopOrRIUInformationMemory[v3];
}
else
{
v0 = &DefaultBaliseLoopOrRIUInformationMemory[4 * DefaultBaliseLoopOrRIUInformationMemoryFreeList];
DefaultBaliseLoopOrRIUInformationMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
DefaultBaliseLoopOrRIUInformation* DefaultBaliseLoopOrRIUInformation_New(void)
{
    DefaultBaliseLoopOrRIUInformation* ptr;
    if (DefaultBaliseLoopOrRIUInformationMemoryFreeList != (-1))
    {
        ptr = &DefaultBaliseLoopOrRIUInformationMemory[DefaultBaliseLoopOrRIUInformationMemoryFreeList];
        DefaultBaliseLoopOrRIUInformationMemoryFreeList = DefaultBaliseLoopOrRIUInformationMemory[DefaultBaliseLoopOrRIUInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (DefaultBaliseLoopOrRIUInformationMemoryTop < 8)
    {
        ptr = &DefaultBaliseLoopOrRIUInformationMemory[DefaultBaliseLoopOrRIUInformationMemoryTop];
        DefaultBaliseLoopOrRIUInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DefaultBaliseLoopOrRIUInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct DefaultBaliseLoopOrRIUInformation *DefaultBaliseLoopOrRIUInformation_New()
{
    struct DefaultBaliseLoopOrRIUInformation *ptr;
    if (DefaultBaliseLoopOrRIUInformationMemoryFreeList != (-1))
    {
        ptr = &DefaultBaliseLoopOrRIUInformationMemory[DefaultBaliseLoopOrRIUInformationMemoryFreeList];
        DefaultBaliseLoopOrRIUInformationMemoryFreeList = DefaultBaliseLoopOrRIUInformationMemory[DefaultBaliseLoopOrRIUInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (DefaultBaliseLoopOrRIUInformationMemoryTop < 8)
    {
        ptr = &DefaultBaliseLoopOrRIUInformationMemory[DefaultBaliseLoopOrRIUInformationMemoryTop];
        DefaultBaliseLoopOrRIUInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DefaultBaliseLoopOrRIUInformation_Init(ptr);
    return ptr;
}

return_type: struct DefaultBaliseLoopOrRIUInformation { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; } *


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

result = DefaultBaliseLoopOrRIUInformationMemoryFreeList;
*(_QWORD *)a1 = DefaultBaliseLoopOrRIUInformationMemoryFreeList;
DefaultBaliseLoopOrRIUInformationMemoryFreeList = (a1 - (char *)DefaultBaliseLoopOrRIUInformationMemory) >> 5;
return result;
}

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

result = DefaultBaliseLoopOrRIUInformationMemoryFreeList;
*(_QWORD *)a1 = DefaultBaliseLoopOrRIUInformationMemoryFreeList;
DefaultBaliseLoopOrRIUInformationMemoryFreeList = (a1 - (char *)DefaultBaliseLoopOrRIUInformationMemory) >> 5;
return result;
}

original_code:
void DefaultBaliseLoopOrRIUInformation_Delete(DefaultBaliseLoopOrRIUInformation* ptr)
{
    ptr->header.NID_PACKET = DefaultBaliseLoopOrRIUInformationMemoryFreeList;
    DefaultBaliseLoopOrRIUInformationMemoryFreeList = ptr - DefaultBaliseLoopOrRIUInformationMemory;
}

canonical_original_code:
void DefaultBaliseLoopOrRIUInformation_Delete(struct DefaultBaliseLoopOrRIUInformation *ptr)
{
    ptr->header.NID_PACKET = DefaultBaliseLoopOrRIUInformationMemoryFreeList;
    DefaultBaliseLoopOrRIUInformationMemoryFreeList = ptr - DefaultBaliseLoopOrRIUInformationMemory;
}


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


decompiled_code:
_BOOL8 __fastcall ErrorReporting_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 13);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 8);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx

result = func0(*(_QWORD *)(a1 + 16), 13);
if ( result )
result = func0(*(_QWORD *)(v2 + 24), 8);
return result;
}

original_code:
int ErrorReporting_UpperBitsNotSet(const ErrorReporting* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->M_ERROR, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ErrorReporting_UpperBitsNotSet(struct ErrorReporting *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->M_ERROR, 8) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ErrorReporting { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long M_ERROR; } *

user_defined_types: struct ErrorReporting { struct PacketHeader header; unsigned long L_PACKET; unsigned long M_ERROR; }