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

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

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

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

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

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


repo: openETCS/dataDictionary

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

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

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

variable_types: 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 Level1MovementAuthority { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long V_MAIN; unsigned long V_LOA; unsigned long T_LOA; unsigned long N_ITER_1; struct Level1MovementAuthority_1 sub_1[31]; unsigned long L_ENDSECTION; unsigned long Q_SECTIONTIMER; unsigned long T_SECTIONTIMER; unsigned long D_SECTIONTIMERSTOPLOC; unsigned long Q_ENDTIMER; unsigned long T_ENDTIMER; unsigned long D_ENDTIMERSTARTLOC; unsigned long Q_DANGERPOINT; unsigned long D_DP; unsigned long V_RELEASEDP; unsigned long Q_OVERLAP; unsigned long D_STARTOL; unsigned long T_OL; unsigned long D_OL; unsigned long V_RELEASEOL; }


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

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

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 Level1MovementAuthority_1 { unsigned long L_SECTION; unsigned long Q_SECTIONTIMER; unsigned long T_SECTIONTIMER; unsigned long D_SECTIONTIMERSTOPLOC; }


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

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

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

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

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

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

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


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

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

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

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

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

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

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 PositionReport_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
unsigned __int64 v10; // rdi
__int64 v11; // rdx
__int64 v12; // rdx
__int64 v13; // rdx
__int64 v14; // rdx
unsigned __int64 v15; // rdi
__int64 v16; // rdx

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 13);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 32), 24);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v4 + 40), 15);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v5 + 48), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v6 + 56), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v7 + 64), 15);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v8 + 72), 15);
if ( result )
{
v10 = *(_QWORD *)(v9 + 80);
result = UpperBitsNotSet64(v10, 2);
if ( result && (v10 - 1 > 1 || (result = UpperBitsNotSet64(*(_QWORD *)(v11 + 88), 15))) )
{
result = UpperBitsNotSet64(*(_QWORD *)(v11 + 96), 7);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v12 + 104), 2);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v13 + 112), 4);
if ( result )
{
v15 = *(_QWORD *)(v14 + 120);
result = UpperBitsNotSet64(v15, 3);
if ( result )
{
result = 1LL;
if ( v15 == 1 )
result = UpperBitsNotSet64(*(_QWORD *)(v16 + 128), 8);
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
unsigned __int64 v10; // rdi
__int64 v11; // rdx
__int64 v12; // rdx
__int64 v13; // rdx
__int64 v14; // rdx
unsigned __int64 v15; // rdi
__int64 v16; // rdx

result = func0(*(_QWORD *)(a1 + 16), 13);
if ( result )
{
result = func0(*(_QWORD *)(v2 + 24), 2);
if ( result )
{
result = func0(*(_QWORD *)(v3 + 32), 24);
if ( result )
{
result = func0(*(_QWORD *)(v4 + 40), 15);
if ( result )
{
result = func0(*(_QWORD *)(v5 + 48), 2);
if ( result )
{
result = func0(*(_QWORD *)(v6 + 56), 2);
if ( result )
{
result = func0(*(_QWORD *)(v7 + 64), 15);
if ( result )
{
result = func0(*(_QWORD *)(v8 + 72), 15);
if ( result )
{
v10 = *(_QWORD *)(v9 + 80);
result = func0(v10, 2);
if ( result && (v10 - 1 > 1 || (result = func0(*(_QWORD *)(v11 + 88), 15))) )
{
result = func0(*(_QWORD *)(v11 + 96), 7);
if ( result )
{
result = func0(*(_QWORD *)(v12 + 104), 2);
if ( result )
{
result = func0(*(_QWORD *)(v13 + 112), 4);
if ( result )
{
v15 = *(_QWORD *)(v14 + 120);
result = func0(v15, 3);
if ( result )
{
result = 1LL;
if ( v15 == 1 )
result = func0(*(_QWORD *)(v16 + 128), 8);
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

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

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

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

variable_types: status int

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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


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

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


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

if ( PositionReportMemoryFreeList == -1 )
{
if ( (unsigned __int64)PositionReportMemoryTop > 7 )
return 0LL;
v3 = 17 * PositionReportMemoryTop++;
v0 = &PositionReportMemory[v3];
}
else
{
v0 = &PositionReportMemory[17 * PositionReportMemoryFreeList];
PositionReportMemoryFreeList = *v0;
}
PositionReport_Init(v0);
return v1;
}

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

if ( PositionReportMemoryFreeList == -1 )
{
if ( (unsigned __int64)PositionReportMemoryTop > 7 )
return 0LL;
v3 = 17 * PositionReportMemoryTop++;
v0 = &PositionReportMemory[v3];
}
else
{
v0 = &PositionReportMemory[17 * PositionReportMemoryFreeList];
PositionReportMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
PositionReport* PositionReport_New(void)
{
    PositionReport* ptr;
    if (PositionReportMemoryFreeList != (-1))
    {
        ptr = &PositionReportMemory[PositionReportMemoryFreeList];
        PositionReportMemoryFreeList = PositionReportMemory[PositionReportMemoryFreeList].header.NID_PACKET;
    }
    else if (PositionReportMemoryTop < 8)
    {
        ptr = &PositionReportMemory[PositionReportMemoryTop];
        PositionReportMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    PositionReport_Init(ptr);
    return ptr;
}

canonical_original_code:
struct PositionReport *PositionReport_New()
{
    struct PositionReport *ptr;
    if (PositionReportMemoryFreeList != (-1))
    {
        ptr = &PositionReportMemory[PositionReportMemoryFreeList];
        PositionReportMemoryFreeList = PositionReportMemory[PositionReportMemoryFreeList].header.NID_PACKET;
    }
    else if (PositionReportMemoryTop < 8)
    {
        ptr = &PositionReportMemory[PositionReportMemoryTop];
        PositionReportMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    PositionReport_Init(ptr);
    return ptr;
}

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


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

*a1 = PositionReportMemoryFreeList;
result = 0xF0F0F0F0F0F0F0F1LL;
PositionReportMemoryFreeList = 0xF0F0F0F0F0F0F0F1LL * (a1 - PositionReportMemory);
return result;
}

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

*a1 = PositionReportMemoryFreeList;
result = 0xF0F0F0F0F0F0F0F1LL;
PositionReportMemoryFreeList = 0xF0F0F0F0F0F0F0F1LL * (a1 - PositionReportMemory);
return result;
}

original_code:
void PositionReport_Delete(PositionReport* ptr)
{
    ptr->header.NID_PACKET = PositionReportMemoryFreeList;
    PositionReportMemoryFreeList = ptr - PositionReportMemory;
}

canonical_original_code:
void PositionReport_Delete(struct PositionReport *ptr)
{
    ptr->header.NID_PACKET = PositionReportMemoryFreeList;
    PositionReportMemoryFreeList = ptr - PositionReportMemory;
}


decompiled_code:
_BOOL8 __fastcall OnboardTelephoneNumbers_1_UpperBitsNotSet(_QWORD *a1)
{
return (unsigned int)UpperBitsNotSet64_constprop_0(*a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1)
{
return (unsigned int)func0(*a1) != 0;
}

original_code:
int OnboardTelephoneNumbers_1_UpperBitsNotSet(const OnboardTelephoneNumbers_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int OnboardTelephoneNumbers_1_UpperBitsNotSet(struct OnboardTelephoneNumbers_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct OnboardTelephoneNumbers_1 { unsigned long NID_RADIO; } *


decompiled_code:
__int64 __fastcall OnboardTelephoneNumbers_1_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 64LL) )
return 0xFFFFFFFFLL;
if ( !OnboardTelephoneNumbers_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 64LL, *a1);
return 1LL;
}

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

original_code:
int OnboardTelephoneNumbers_1_EncodeBit(const OnboardTelephoneNumbers_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 64))
    {
        if (OnboardTelephoneNumbers_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 64, p->NID_RADIO);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int OnboardTelephoneNumbers_1_EncodeBit(struct OnboardTelephoneNumbers_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 64))
    {
        if (OnboardTelephoneNumbers_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 64, p->NID_RADIO);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct OnboardTelephoneNumbers_1 { unsigned long NID_RADIO; }


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

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

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

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

original_code:
int OnboardTelephoneNumbers_1_DecodeBit(OnboardTelephoneNumbers_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 64))
    {
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int OnboardTelephoneNumbers_1_DecodeBit(struct OnboardTelephoneNumbers_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 64))
    {
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


decompiled_code:
__int64 __fastcall OnboardTelephoneNumbers_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 OnboardTelephoneNumbers_1_EncodeInt(const OnboardTelephoneNumbers_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->NID_RADIO;
    return 1;
}

canonical_original_code:
int OnboardTelephoneNumbers_1_EncodeInt(struct OnboardTelephoneNumbers_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->NID_RADIO;
    return 1;
}

variable_types:
startAddress
int *


decompiled_code:
__int64 __fastcall OnboardTelephoneNumbers_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 OnboardTelephoneNumbers_1_DecodeInt(OnboardTelephoneNumbers_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->NID_RADIO = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int OnboardTelephoneNumbers_1_DecodeInt(struct OnboardTelephoneNumbers_1 *p, int *startAddress, int *stream)
{
    p->NID_RADIO = stream[(*startAddress)++];
    return 1;
}


decompiled_code:
_BOOL8 __fastcall ListOfBalisesForSHArea_1_UpperBitsNotSet(unsigned __int64 *a1)
{
unsigned __int64 v1; // rdi
_BOOL8 result; // rax
__int64 v3; // rdx

v1 = *a1;
result = UpperBitsNotSet64(v1, 1);
if ( result && (v1 != 1 || (result = UpperBitsNotSet64(*(_QWORD *)(v3 + 8), 10))) )
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 16), 14);
return result;
}

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

v1 = *a1;
result = func0(v1, 1);
if ( result && (v1 != 1 || (result = func0(*(_QWORD *)(v3 + 8), 10))) )
result = func0(*(_QWORD *)(v3 + 16), 14);
return result;
}

original_code:
int ListOfBalisesForSHArea_1_UpperBitsNotSet(const ListOfBalisesForSHArea_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ListOfBalisesForSHArea_1_UpperBitsNotSet(struct ListOfBalisesForSHArea_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ListOfBalisesForSHArea_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; } *


decompiled_code:
__int64 __fastcall ListOfBalisesForSHArea_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 15LL) )
return 0xFFFFFFFFLL;
if ( !ListOfBalisesForSHArea_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 1LL, *a1);
if ( *a1 == 1 )
Bitstream_Write(a2, 10LL, a1[1]);
Bitstream_Write(a2, 14LL, a1[2]);
return 1LL;
}

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

original_code:
int ListOfBalisesForSHArea_1_EncodeBit(const ListOfBalisesForSHArea_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        if (ListOfBalisesForSHArea_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ListOfBalisesForSHArea_1_EncodeBit(struct ListOfBalisesForSHArea_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        if (ListOfBalisesForSHArea_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct ListOfBalisesForSHArea_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; }


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

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

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

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

original_code:
int ListOfBalisesForSHArea_1_DecodeBit(ListOfBalisesForSHArea_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        {
            p->Q_NEWCOUNTRY = Bitstream_Read(stream, 1);
        }
        if (p->Q_NEWCOUNTRY == 1)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ListOfBalisesForSHArea_1_DecodeBit(struct ListOfBalisesForSHArea_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 15))
    {
        {
            p->Q_NEWCOUNTRY = Bitstream_Read(stream, 1);
        }
        if (p->Q_NEWCOUNTRY == 1)
        {
            {
                p->NID_C = Bitstream_Read(stream, 10);
            }
        }
        {
            p->NID_BG = Bitstream_Read(stream, 14);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


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

canonical_original_code:
int ListOfBalisesForSHArea_1_EncodeInt(struct ListOfBalisesForSHArea_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->Q_NEWCOUNTRY;
    stream[(*startAddress)++] = p->NID_C;
    stream[(*startAddress)++] = p->NID_BG;
    return 1;
}


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

canonical_original_code:
int ListOfBalisesForSHArea_1_DecodeInt(struct ListOfBalisesForSHArea_1 *p, int *startAddress, int *stream)
{
    p->Q_NEWCOUNTRY = stream[(*startAddress)++];
    p->NID_C = stream[(*startAddress)++];
    p->NID_BG = 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 TemporarySpeedRestriction_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), 8);
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), 7);
}
}
}
}
}
}
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), 8);
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), 7);
}
}
}
}
}
}
return result;
}

original_code:
int TemporarySpeedRestriction_UpperBitsNotSet(const TemporarySpeedRestriction* 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_TSR, 8) ;
    status = status && UpperBitsNotSet64(p->D_TSR, 15);
    status = status && UpperBitsNotSet64(p->L_TSR, 15);
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->V_TSR, 7) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TemporarySpeedRestriction_UpperBitsNotSet(struct TemporarySpeedRestriction *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_TSR, 8) ;
    status = status && UpperBitsNotSet64(p->D_TSR, 15);
    status = status && UpperBitsNotSet64(p->L_TSR, 15);
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->V_TSR, 7) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct TemporarySpeedRestriction { 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_TSR; unsigned long D_TSR; unsigned long L_TSR; unsigned long Q_FRONT; unsigned long V_TSR; } *

user_defined_types: struct TemporarySpeedRestriction { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_TSR; unsigned long D_TSR; unsigned long L_TSR; unsigned long Q_FRONT; unsigned long V_TSR; }


decompiled_code:
__int64 __fastcall TemporarySpeedRestriction_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 63LL) )
return 0xFFFFFFFFLL;
if ( !TemporarySpeedRestriction_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, 8LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
Bitstream_Write(a2, 7LL, a1[9]);
return 1LL;
}

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

original_code:
int TemporarySpeedRestriction_EncodeBit(const TemporarySpeedRestriction* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 63))
    {
        if (TemporarySpeedRestriction_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, 8, p->NID_TSR);
            Bitstream_Write(stream, 15, p->D_TSR);
            Bitstream_Write(stream, 15, p->L_TSR);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 7, p->V_TSR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int TemporarySpeedRestriction_EncodeBit(struct TemporarySpeedRestriction *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 63))
    {
        if (TemporarySpeedRestriction_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, 8, p->NID_TSR);
            Bitstream_Write(stream, 15, p->D_TSR);
            Bitstream_Write(stream, 15, p->L_TSR);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 7, p->V_TSR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

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

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

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

original_code:
int TemporarySpeedRestriction_DecodeBit(TemporarySpeedRestriction* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 63))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_TSR = Bitstream_Read(stream, 8);
        }
        {
            p->D_TSR = Bitstream_Read(stream, 15);
        }
        {
            p->L_TSR = Bitstream_Read(stream, 15);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
        {
            p->V_TSR = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TemporarySpeedRestriction_DecodeBit(struct TemporarySpeedRestriction *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 63))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_TSR = Bitstream_Read(stream, 8);
        }
        {
            p->D_TSR = Bitstream_Read(stream, 15);
        }
        {
            p->L_TSR = Bitstream_Read(stream, 15);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
        {
            p->V_TSR = Bitstream_Read(stream, 7);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int TemporarySpeedRestriction_EncodeInt(const TemporarySpeedRestriction* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 65;
    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_TSR;
    stream[startAddress++] = p->D_TSR;
    stream[startAddress++] = p->L_TSR;
    stream[startAddress++] = p->Q_FRONT;
    stream[startAddress++] = p->V_TSR;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int TemporarySpeedRestriction_EncodeInt(struct TemporarySpeedRestriction *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 65;
    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_TSR;
    stream[startAddress++] = p->D_TSR;
    stream[startAddress++] = p->L_TSR;
    stream[startAddress++] = p->Q_FRONT;
    stream[startAddress++] = p->V_TSR;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int TemporarySpeedRestriction_DecodeInt(TemporarySpeedRestriction* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 65)
    {
         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_TSR = stream[startAddress++];
    p->D_TSR = stream[startAddress++];
    p->L_TSR = stream[startAddress++];
    p->Q_FRONT = stream[startAddress++];
    p->V_TSR = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int TemporarySpeedRestriction_DecodeInt(struct TemporarySpeedRestriction *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 65)
    {
         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_TSR = stream[startAddress++];
    p->D_TSR = stream[startAddress++];
    p->L_TSR = stream[startAddress++];
    p->Q_FRONT = stream[startAddress++];
    p->V_TSR = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( TemporarySpeedRestrictionMemoryFreeList == -1 )
{
if ( (unsigned __int64)TemporarySpeedRestrictionMemoryTop <= 7 )
{
v1 = 10 * TemporarySpeedRestrictionMemoryTop++;
TemporarySpeedRestriction_Init(&TemporarySpeedRestrictionMemory[v1]);
}
}
else
{
v0 = &TemporarySpeedRestrictionMemory[10 * TemporarySpeedRestrictionMemoryFreeList];
TemporarySpeedRestrictionMemoryFreeList = *v0;
TemporarySpeedRestriction_Init(v0);
}
}

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

if ( TemporarySpeedRestrictionMemoryFreeList == -1 )
{
if ( (unsigned __int64)TemporarySpeedRestrictionMemoryTop <= 7 )
{
v1 = 10 * TemporarySpeedRestrictionMemoryTop++;
func1(&TemporarySpeedRestrictionMemory[v1]);
}
}
else
{
v0 = &TemporarySpeedRestrictionMemory[10 * TemporarySpeedRestrictionMemoryFreeList];
TemporarySpeedRestrictionMemoryFreeList = *v0;
func1(v0);
}
}

original_code:
TemporarySpeedRestriction* TemporarySpeedRestriction_New(void)
{
    TemporarySpeedRestriction* ptr;
    if (TemporarySpeedRestrictionMemoryFreeList != (-1))
    {
        ptr = &TemporarySpeedRestrictionMemory[TemporarySpeedRestrictionMemoryFreeList];
        TemporarySpeedRestrictionMemoryFreeList = TemporarySpeedRestrictionMemory[TemporarySpeedRestrictionMemoryFreeList].header.NID_PACKET;
    }
    else if (TemporarySpeedRestrictionMemoryTop < 8)
    {
        ptr = &TemporarySpeedRestrictionMemory[TemporarySpeedRestrictionMemoryTop];
        TemporarySpeedRestrictionMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    TemporarySpeedRestriction_Init(ptr);
    return ptr;
}

canonical_original_code:
struct TemporarySpeedRestriction *TemporarySpeedRestriction_New()
{
    struct TemporarySpeedRestriction *ptr;
    if (TemporarySpeedRestrictionMemoryFreeList != (-1))
    {
        ptr = &TemporarySpeedRestrictionMemory[TemporarySpeedRestrictionMemoryFreeList];
        TemporarySpeedRestrictionMemoryFreeList = TemporarySpeedRestrictionMemory[TemporarySpeedRestrictionMemoryFreeList].header.NID_PACKET;
    }
    else if (TemporarySpeedRestrictionMemoryTop < 8)
    {
        ptr = &TemporarySpeedRestrictionMemory[TemporarySpeedRestrictionMemoryTop];
        TemporarySpeedRestrictionMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    TemporarySpeedRestriction_Init(ptr);
    return ptr;
}

return_type: struct TemporarySpeedRestriction { 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_TSR; unsigned long D_TSR; unsigned long L_TSR; unsigned long Q_FRONT; unsigned long V_TSR; } *


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

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

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

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

original_code:
void TemporarySpeedRestriction_Delete(TemporarySpeedRestriction* ptr)
{
    ptr->header.NID_PACKET = TemporarySpeedRestrictionMemoryFreeList;
    TemporarySpeedRestrictionMemoryFreeList = ptr - TemporarySpeedRestrictionMemory;
}

canonical_original_code:
void TemporarySpeedRestriction_Delete(struct TemporarySpeedRestriction *ptr)
{
    ptr->header.NID_PACKET = TemporarySpeedRestrictionMemoryFreeList;
    TemporarySpeedRestrictionMemoryFreeList = ptr - TemporarySpeedRestrictionMemory;
}


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

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

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

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

original_code:
int ListOfBalisesInSRAuthority_UpperBitsNotSet(const ListOfBalisesInSRAuthority* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ListOfBalisesInSRAuthority_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ListOfBalisesInSRAuthority_UpperBitsNotSet(struct ListOfBalisesInSRAuthority *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ListOfBalisesInSRAuthority_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ListOfBalisesInSRAuthority { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long N_ITER_1; struct ListOfBalisesInSRAuthority_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; } sub_1[31]; } *

user_defined_types: struct ListOfBalisesInSRAuthority { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long N_ITER_1; struct ListOfBalisesInSRAuthority_1 sub_1[31]; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 20LL) )
return 0xFFFFFFFFLL;
if ( !ListOfBalisesInSRAuthority_UpperBitsNotSet(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 5LL, a1[4]);
v3 = 0LL;
if ( a1[4] )
{
do
{
ListOfBalisesInSRAuthority_1_EncodeBit(&a1[3 * v3 + 5], a2);
v3 = ++v2;
}
while ( v2 < a1[4] );
}
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 20LL) )
return 0xFFFFFFFFLL;
if ( !func3(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 5LL, a1[4]);
v3 = 0LL;
if ( a1[4] )
{
do
{
ListOfBalisesInSRAuthority_1_EncodeBit(&a1[3 * v3 + 5], a2);
v3 = ++v2;
}
while ( v2 < a1[4] );
}
return 1LL;
}

original_code:
int ListOfBalisesInSRAuthority_EncodeBit(const ListOfBalisesInSRAuthority* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 20))
    {
        if (ListOfBalisesInSRAuthority_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                ListOfBalisesInSRAuthority_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ListOfBalisesInSRAuthority_EncodeBit(struct ListOfBalisesInSRAuthority *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 20))
    {
        if (ListOfBalisesInSRAuthority_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                ListOfBalisesInSRAuthority_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct ListOfBalisesInSRAuthority_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; }


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

result = Bitstream_Normal(a2, 20LL);
if ( (_DWORD)result )
{
v3 = 0;
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
v4 = Bitstream_Read(a2, 5LL);
a1[4] = v4;
v5 = 0LL;
if ( v4 )
{
do
{
ListOfBalisesInSRAuthority_1_DecodeBit(&a1[3 * v5 + 5], a2);
v5 = ++v3;
}
while ( (unsigned __int64)v3 < a1[4] );
}
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 20LL);
if ( (_DWORD)result )
{
v3 = 0;
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
v4 = Bitstream_Read(a2, 5LL);
a1[4] = v4;
v5 = 0LL;
if ( v4 )
{
do
{
ListOfBalisesInSRAuthority_1_DecodeBit(&a1[3 * v5 + 5], a2);
v5 = ++v3;
}
while ( (unsigned __int64)v3 < a1[4] );
}
result = 1LL;
}
return result;
}

original_code:
int ListOfBalisesInSRAuthority_DecodeBit(ListOfBalisesInSRAuthority* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 20))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            ListOfBalisesInSRAuthority_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ListOfBalisesInSRAuthority_DecodeBit(struct ListOfBalisesInSRAuthority *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 20))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            ListOfBalisesInSRAuthority_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int ListOfBalisesInSRAuthority_EncodeInt(const ListOfBalisesInSRAuthority* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 63;
    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->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ListOfBalisesInSRAuthority_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int ListOfBalisesInSRAuthority_EncodeInt(struct ListOfBalisesInSRAuthority *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 63;
    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->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ListOfBalisesInSRAuthority_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int ListOfBalisesInSRAuthority_DecodeInt(ListOfBalisesInSRAuthority* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 63)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ListOfBalisesInSRAuthority_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int ListOfBalisesInSRAuthority_DecodeInt(struct ListOfBalisesInSRAuthority *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 63)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ListOfBalisesInSRAuthority_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( ListOfBalisesInSRAuthorityMemoryFreeList == -1 )
{
if ( (unsigned __int64)ListOfBalisesInSRAuthorityMemoryTop > 7 )
return 0LL;
v3 = 98 * ListOfBalisesInSRAuthorityMemoryTop++;
v0 = &ListOfBalisesInSRAuthorityMemory[v3];
}
else
{
v0 = &ListOfBalisesInSRAuthorityMemory[98 * ListOfBalisesInSRAuthorityMemoryFreeList];
ListOfBalisesInSRAuthorityMemoryFreeList = *v0;
}
ListOfBalisesInSRAuthority_Init(v0);
return v1;
}

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

if ( ListOfBalisesInSRAuthorityMemoryFreeList == -1 )
{
if ( (unsigned __int64)ListOfBalisesInSRAuthorityMemoryTop > 7 )
return 0LL;
v3 = 98 * ListOfBalisesInSRAuthorityMemoryTop++;
v0 = &ListOfBalisesInSRAuthorityMemory[v3];
}
else
{
v0 = &ListOfBalisesInSRAuthorityMemory[98 * ListOfBalisesInSRAuthorityMemoryFreeList];
ListOfBalisesInSRAuthorityMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
ListOfBalisesInSRAuthority* ListOfBalisesInSRAuthority_New(void)
{
    ListOfBalisesInSRAuthority* ptr;
    if (ListOfBalisesInSRAuthorityMemoryFreeList != (-1))
    {
        ptr = &ListOfBalisesInSRAuthorityMemory[ListOfBalisesInSRAuthorityMemoryFreeList];
        ListOfBalisesInSRAuthorityMemoryFreeList = ListOfBalisesInSRAuthorityMemory[ListOfBalisesInSRAuthorityMemoryFreeList].header.NID_PACKET;
    }
    else if (ListOfBalisesInSRAuthorityMemoryTop < 8)
    {
        ptr = &ListOfBalisesInSRAuthorityMemory[ListOfBalisesInSRAuthorityMemoryTop];
        ListOfBalisesInSRAuthorityMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ListOfBalisesInSRAuthority_Init(ptr);
    return ptr;
}

canonical_original_code:
struct ListOfBalisesInSRAuthority *ListOfBalisesInSRAuthority_New()
{
    struct ListOfBalisesInSRAuthority *ptr;
    if (ListOfBalisesInSRAuthorityMemoryFreeList != (-1))
    {
        ptr = &ListOfBalisesInSRAuthorityMemory[ListOfBalisesInSRAuthorityMemoryFreeList];
        ListOfBalisesInSRAuthorityMemoryFreeList = ListOfBalisesInSRAuthorityMemory[ListOfBalisesInSRAuthorityMemoryFreeList].header.NID_PACKET;
    }
    else if (ListOfBalisesInSRAuthorityMemoryTop < 8)
    {
        ptr = &ListOfBalisesInSRAuthorityMemory[ListOfBalisesInSRAuthorityMemoryTop];
        ListOfBalisesInSRAuthorityMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ListOfBalisesInSRAuthority_Init(ptr);
    return ptr;
}

return_type: struct ListOfBalisesInSRAuthority { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long N_ITER_1; struct ListOfBalisesInSRAuthority_1 { unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; } sub_1[31]; } *


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

*(_QWORD *)a1 = ListOfBalisesInSRAuthorityMemoryFreeList;
result = 0x7D6343EB1A1F58D1LL;
ListOfBalisesInSRAuthorityMemoryFreeList = 0x7D6343EB1A1F58D1LL
* ((a1 - (char *)ListOfBalisesInSRAuthorityMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = ListOfBalisesInSRAuthorityMemoryFreeList;
result = 0x7D6343EB1A1F58D1LL;
ListOfBalisesInSRAuthorityMemoryFreeList = 0x7D6343EB1A1F58D1LL
* ((a1 - (char *)ListOfBalisesInSRAuthorityMemory) >> 4);
return result;
}

original_code:
void ListOfBalisesInSRAuthority_Delete(ListOfBalisesInSRAuthority* ptr)
{
    ptr->header.NID_PACKET = ListOfBalisesInSRAuthorityMemoryFreeList;
    ListOfBalisesInSRAuthorityMemoryFreeList = ptr - ListOfBalisesInSRAuthorityMemory;
}

canonical_original_code:
void ListOfBalisesInSRAuthority_Delete(struct ListOfBalisesInSRAuthority *ptr)
{
    ptr->header.NID_PACKET = ListOfBalisesInSRAuthorityMemoryFreeList;
    ListOfBalisesInSRAuthorityMemoryFreeList = ptr - ListOfBalisesInSRAuthorityMemory;
}


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

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

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

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

original_code:
int TrackCondition_1_UpperBitsNotSet(const TrackCondition_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_TRACKCOND, 15);
    status = status && UpperBitsNotSet64(p->L_TRACKCOND, 15);
    status = status && UpperBitsNotSet64(p->M_TRACKCOND, 4) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TrackCondition_1_UpperBitsNotSet(struct TrackCondition_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->D_TRACKCOND, 15);
    status = status && UpperBitsNotSet64(p->L_TRACKCOND, 15);
    status = status && UpperBitsNotSet64(p->M_TRACKCOND, 4) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct TrackCondition_1 { unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; unsigned long M_TRACKCOND; } *


decompiled_code:
__int64 __fastcall TrackCondition_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 34LL) )
return 0xFFFFFFFFLL;
if ( !TrackCondition_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 15LL, a1[1]);
Bitstream_Write(a2, 4LL, a1[2]);
return 1LL;
}

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

original_code:
int TrackCondition_1_EncodeBit(const TrackCondition_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 34))
    {
        if (TrackCondition_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_TRACKCOND);
            Bitstream_Write(stream, 15, p->L_TRACKCOND);
            Bitstream_Write(stream, 4, p->M_TRACKCOND);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int TrackCondition_1_EncodeBit(struct TrackCondition_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 34))
    {
        if (TrackCondition_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 15, p->D_TRACKCOND);
            Bitstream_Write(stream, 15, p->L_TRACKCOND);
            Bitstream_Write(stream, 4, p->M_TRACKCOND);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct TrackCondition_1 { unsigned long D_TRACKCOND; unsigned long L_TRACKCOND; unsigned long M_TRACKCOND; }


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

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

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

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

original_code:
int TrackCondition_1_DecodeBit(TrackCondition_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 34))
    {
        {
            p->D_TRACKCOND = Bitstream_Read(stream, 15);
        }
        {
            p->L_TRACKCOND = Bitstream_Read(stream, 15);
        }
        {
            p->M_TRACKCOND = Bitstream_Read(stream, 4);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int TrackCondition_1_DecodeBit(struct TrackCondition_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 34))
    {
        {
            p->D_TRACKCOND = Bitstream_Read(stream, 15);
        }
        {
            p->L_TRACKCOND = Bitstream_Read(stream, 15);
        }
        {
            p->M_TRACKCOND = Bitstream_Read(stream, 4);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


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

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


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

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


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

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

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 OnboardTelephoneNumbers_UpperBitsNotSet(__int64 a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
_BOOL4 v3; // eax
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
int v6; // er8

v1 = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 13);
v2 = *(_QWORD *)(a1 + 24);
if ( !v1 )
{
if ( !v2 )
return 0LL;
LODWORD(v4) = 0;
do
{
LABEL_7:
if ( (unsigned int)(v4 + 1) >= v2 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v2 );
return 0LL;
}
v3 = UpperBitsNotSet64(*(_QWORD *)(a1 + 24), 5);
if ( v2 )
{
LODWORD(v4) = 0;
if ( v3 )
{
v5 = 0LL;
while ( 1 )
{
v6 = OnboardTelephoneNumbers_1_UpperBitsNotSet(a1 + 8 * v5 + 32);
v5 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v6 )
break;
if ( *(_QWORD *)(a1 + 24) <= v5 )
return 1LL;
}
v2 = *(_QWORD *)(a1 + 24);
if ( v2 <= v5 )
return 0LL;
}
goto LABEL_7;
}
return v3;
}

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

v1 = func0(*(_QWORD *)(a1 + 16), 13);
v2 = *(_QWORD *)(a1 + 24);
if ( !v1 )
{
if ( !v2 )
return 0LL;
LODWORD(v4) = 0;
do
{
LABEL_7:
if ( (unsigned int)(v4 + 1) >= v2 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v2 );
return 0LL;
}
v3 = func0(*(_QWORD *)(a1 + 24), 5);
if ( v2 )
{
LODWORD(v4) = 0;
if ( v3 )
{
v5 = 0LL;
while ( 1 )
{
v6 = OnboardTelephoneNumbers_1_UpperBitsNotSet(a1 + 8 * v5 + 32);
v5 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v6 )
break;
if ( *(_QWORD *)(a1 + 24) <= v5 )
return 1LL;
}
v2 = *(_QWORD *)(a1 + 24);
if ( v2 <= v5 )
return 0LL;
}
goto LABEL_7;
}
return v3;
}

original_code:
int OnboardTelephoneNumbers_UpperBitsNotSet(const OnboardTelephoneNumbers* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && OnboardTelephoneNumbers_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int OnboardTelephoneNumbers_UpperBitsNotSet(struct OnboardTelephoneNumbers *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && OnboardTelephoneNumbers_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct OnboardTelephoneNumbers { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long N_ITER_1; struct OnboardTelephoneNumbers_1 { unsigned long NID_RADIO; } sub_1[31]; } *

user_defined_types: struct OnboardTelephoneNumbers { struct PacketHeader header; unsigned long L_PACKET; unsigned long N_ITER_1; struct OnboardTelephoneNumbers_1 sub_1[31]; }


decompiled_code:
__int64 __fastcall OnboardTelephoneNumbers_EncodeBit(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
__int64 v3; // rax

if ( !(unsigned int)Bitstream_Normal(a2, 18LL) )
return 0xFFFFFFFFLL;
if ( !OnboardTelephoneNumbers_UpperBitsNotSet(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 13LL, *(_QWORD *)(a1 + 16));
Bitstream_Write(a2, 5LL, *(_QWORD *)(a1 + 24));
v3 = 0LL;
if ( *(_QWORD *)(a1 + 24) )
{
do
{
OnboardTelephoneNumbers_1_EncodeBit(a1 + 8 * v3 + 32, a2);
v3 = ++v2;
}
while ( (unsigned __int64)v2 < *(_QWORD *)(a1 + 24) );
}
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 18LL) )
return 0xFFFFFFFFLL;
if ( !func3(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 13LL, *(_QWORD *)(a1 + 16));
Bitstream_Write(a2, 5LL, *(_QWORD *)(a1 + 24));
v3 = 0LL;
if ( *(_QWORD *)(a1 + 24) )
{
do
{
OnboardTelephoneNumbers_1_EncodeBit(a1 + 8 * v3 + 32, a2);
v3 = ++v2;
}
while ( (unsigned __int64)v2 < *(_QWORD *)(a1 + 24) );
}
return 1LL;
}

original_code:
int OnboardTelephoneNumbers_EncodeBit(const OnboardTelephoneNumbers* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        if (OnboardTelephoneNumbers_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                OnboardTelephoneNumbers_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int OnboardTelephoneNumbers_EncodeBit(struct OnboardTelephoneNumbers *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        if (OnboardTelephoneNumbers_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                OnboardTelephoneNumbers_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


decompiled_code:
__int64 __fastcall OnboardTelephoneNumbers_DecodeBit(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // ebp
__int64 v4; // rdx
__int64 v5; // rax

result = Bitstream_Normal(a2, 18LL);
if ( (_DWORD)result )
{
v3 = 0;
*(_QWORD *)(a1 + 16) = Bitstream_Read(a2, 13LL);
v4 = Bitstream_Read(a2, 5LL);
*(_QWORD *)(a1 + 24) = v4;
v5 = 0LL;
if ( v4 )
{
do
{
OnboardTelephoneNumbers_1_DecodeBit(a1 + 8 * v5 + 32, a2);
v5 = ++v3;
}
while ( (unsigned __int64)v3 < *(_QWORD *)(a1 + 24) );
}
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 18LL);
if ( (_DWORD)result )
{
v3 = 0;
*(_QWORD *)(a1 + 16) = Bitstream_Read(a2, 13LL);
v4 = Bitstream_Read(a2, 5LL);
*(_QWORD *)(a1 + 24) = v4;
v5 = 0LL;
if ( v4 )
{
do
{
OnboardTelephoneNumbers_1_DecodeBit(a1 + 8 * v5 + 32, a2);
v5 = ++v3;
}
while ( (unsigned __int64)v3 < *(_QWORD *)(a1 + 24) );
}
result = 1LL;
}
return result;
}

original_code:
int OnboardTelephoneNumbers_DecodeBit(OnboardTelephoneNumbers* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            OnboardTelephoneNumbers_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int OnboardTelephoneNumbers_DecodeBit(struct OnboardTelephoneNumbers *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            OnboardTelephoneNumbers_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int OnboardTelephoneNumbers_EncodeInt(const OnboardTelephoneNumbers* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 3;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        OnboardTelephoneNumbers_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int OnboardTelephoneNumbers_EncodeInt(struct OnboardTelephoneNumbers *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 3;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        OnboardTelephoneNumbers_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

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