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

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

original_code:
static inline
int PacketHeader_EncodeBit(const PacketHeader* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        if (PacketHeader_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 8, p->NID_PACKET);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
static inline int PacketHeader_EncodeBit(struct PacketHeader *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 8))
    {
        if (PacketHeader_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 8, p->NID_PACKET);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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


repo: openETCS/dataDictionary

decompiled_code:
__int64 __fastcall EurobaliseTelegram_Clear(_QWORD *a1)
{
TelegramHeader_Init(a1);
return PacketSequence_Clear(a1 + 10);
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1)
{
func1(a1);
return PacketSequence_Clear(a1 + 10);
}

original_code:
void EurobaliseTelegram_Clear(EurobaliseTelegram* t)
{
    TelegramHeader_Init(&t->header);
    PacketSequence_Clear(&t->packets);
}

canonical_original_code:
void EurobaliseTelegram_Clear(struct EurobaliseTelegram *t)
{
    TelegramHeader_Init(&t->header);
    PacketSequence_Clear(&t->packets);
}

variable_types: struct EurobaliseTelegram { struct TelegramHeader { unsigned long Q_UPDOWN; unsigned long M_VERSION; unsigned long Q_MEDIA; unsigned long N_PIG; unsigned long N_TOTAL; unsigned long M_DUP; unsigned long M_MCOUNT; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINK; } header; struct PacketSequence { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } *header[50]; unsigned int size; } packets; } *

return_type: void

user_defined_types: struct EurobaliseTelegram { struct TelegramHeader header; struct PacketSequence packets; }

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


decompiled_code:
_BOOL8 __fastcall EurobaliseTelegram_Equal(_QWORD *a1, _QWORD *a2)
{
_BOOL8 result; // rax

result = TelegramHeader_Equal(a1, a2);
if ( result )
result = (unsigned int)PacketSequence_Equal(a1 + 10, a2 + 10) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func18(_QWORD *a1, _QWORD *a2)
{
_BOOL8 result; // rax

result = func3(a1, a2);
if ( result )
result = (unsigned int)PacketSequence_Equal(a1 + 10, a2 + 10) != 0;
return result;
}

original_code:
int EurobaliseTelegram_Equal(const EurobaliseTelegram* a, const EurobaliseTelegram* b)
{
    return TelegramHeader_Equal(&a->header, &b->header) &&
           PacketSequence_Equal(&a->packets, &b->packets);
}

canonical_original_code:
int EurobaliseTelegram_Equal(struct EurobaliseTelegram *a, struct EurobaliseTelegram *b)
{
    return TelegramHeader_Equal(&a->header, &b->header) &&
           PacketSequence_Equal(&a->packets, &b->packets);
}

variable_types:
b
struct EurobaliseTelegram *

return_type: int

user_defined_types: struct TelegramHeader { unsigned long Q_UPDOWN; unsigned long M_VERSION; unsigned long Q_MEDIA; unsigned long N_PIG; unsigned long N_TOTAL; unsigned long M_DUP; unsigned long M_MCOUNT; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINK; }

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


decompiled_code:
__int64 __fastcall EurobaliseTelegram_DecodeBit(_QWORD *a1, __int64 a2)
{
unsigned int v2; // er15
unsigned int v3; // er12
unsigned int v4; // er14
__int64 v5; // rsi
__int64 v6; // rax
__int64 v7; // rbx
unsigned int v8; // eax
__int64 v10; // [rsp+0h] [rbp-48h] BYREF
__int64 v11; // [rsp+8h] [rbp-40h]

if ( (unsigned int)TelegramHeader_DecodeBit(a2, a1) != 1 )
return 0;
v2 = 1;
v3 = *(_DWORD *)(a2 + 12);
v4 = v3 + 1023;
if ( v3 < 0xFFFFFC01 )
{
while ( 1 )
{
v10 = 0LL;
v11 = 0LL;
PacketHeader_DecodeBit(&v10, a2);
if ( v10 == 255 )
break;
if ( *a1 == 1LL )
{
v6 = PacketFactory_TrackToTrain(v10, v11);
v7 = v6;
if ( !v6 )
return 0;
}
else
{
if ( *a1 )
_assert_fail(
"t->header.Q_UPDOWN == 0",
"..//Telegram/EurobaliseTelegram.c",
0x69u,
"EurobaliseTelegram_DecodeBit");
v6 = PacketFactory_TrainToTrack(v10, v11);
v7 = v6;
if ( !v6 )
return 0;
}
EurobaliseTelegram_Add((__int64)a1, v6);
Packet_DecodeBit(v7, a2);
v3 += Packet_Length(v7);
v8 = *(_DWORD *)(a2 + 12);
if ( v8 > v4 )
return v2;
if ( v8 != v3 )
return 0;
}
v5 = PacketFactory_BothWays(255LL, v11);
if ( !v5 )
_assert_fail("ptr", "..//Telegram/EurobaliseTelegram.c", 0x50u, "EurobaliseTelegram_DecodeBit");
EurobaliseTelegram_Add((__int64)a1, v5);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, __int64 a2)
{
unsigned int v2; // er15
unsigned int v3; // er12
unsigned int v4; // er14
__int64 v5; // rsi
__int64 v6; // rax
__int64 v7; // rbx
unsigned int v8; // eax
__int64 v10; // [rsp+0h] [rbp-48h] BYREF
__int64 v11; // [rsp+8h] [rbp-40h]

if ( (unsigned int)func12(a2, a1) != 1 )
return 0;
v2 = 1;
v3 = *(_DWORD *)(a2 + 12);
v4 = v3 + 1023;
if ( v3 < 0xFFFFFC01 )
{
while ( 1 )
{
v10 = 0LL;
v11 = 0LL;
func13(&v10, a2);
if ( v10 == 255 )
break;
if ( *a1 == 1LL )
{
v6 = PacketFactory_TrackToTrain(v10, v11);
v7 = v6;
if ( !v6 )
return 0;
}
else
{
if ( *a1 )
_assert_fail(
"t->header.Q_UPDOWN == 0",
"..//Telegram/EurobaliseTelegram.c",
0x69u,
"EurobaliseTelegram_DecodeBit");
v6 = PacketFactory_TrainToTrack(v10, v11);
v7 = v6;
if ( !v6 )
return 0;
}
func8((__int64)a1, v6);
Packet_DecodeBit(v7, a2);
v3 += Packet_Length(v7);
v8 = *(_DWORD *)(a2 + 12);
if ( v8 > v4 )
return v2;
if ( v8 != v3 )
return 0;
}
v5 = PacketFactory_BothWays(255LL, v11);
if ( !v5 )
_assert_fail("ptr", "..//Telegram/EurobaliseTelegram.c", 0x50u, "EurobaliseTelegram_DecodeBit");
func8((__int64)a1, v5);
}
return v2;
}

original_code:
int EurobaliseTelegram_DecodeBit(EurobaliseTelegram* t, Bitstream* stream)
{
    if (TelegramHeader_DecodeBit(stream, &t->header) != 1)
    {
        return 0;
    }
    const uint32_t old_pos = stream->bitpos;
    uint32_t current_pos = stream->bitpos;
    while (stream->bitpos <= 1023 + old_pos)
    {
        if (current_pos != stream->bitpos)
        {
            return 0;
        }
        PacketHeader packet_header = {0, 0};
        PacketHeader_DecodeBit(&packet_header, stream);
        PacketHeader* ptr = 0;
        if (packet_header.NID_PACKET == 255)
        {
            ptr = PacketFactory_BothWays(packet_header);
            ((ptr) ? (void) (0) : __assert_fail ("ptr", "..//Telegram/EurobaliseTelegram.c", 80, __extension__ __PRETTY_FUNCTION__));
            EurobaliseTelegram_Add(t, ptr);
            break;
        }
        if (t->header.Q_UPDOWN == 1)
        {
            ptr = PacketFactory_TrackToTrain(packet_header);
            if (ptr)
            {
                EurobaliseTelegram_Add(t, ptr);
            }
            else
            {
                return 0;
            }
        }
        else
        {
            ((t->header.Q_UPDOWN == 0) ? (void) (0) : __assert_fail ("t->header.Q_UPDOWN == 0", "..//Telegram/EurobaliseTelegram.c", 105, __extension__ __PRETTY_FUNCTION__));
            ptr = PacketFactory_TrainToTrack(packet_header);
            if (ptr)
            {
                EurobaliseTelegram_Add(t, ptr);
            }
            else
            {
                return 0;
            }
        }
        if (ptr)
        {
            Packet_DecodeBit(ptr, stream);
            current_pos += Packet_Length(ptr);
        }
    }
    return 1;
}

canonical_original_code:
int EurobaliseTelegram_DecodeBit(struct EurobaliseTelegram *t, struct Bitstream *stream)
{
    if (TelegramHeader_DecodeBit(stream, &t->header) != 1)
    {
        return 0;
    }
    unsigned int old_pos = stream->bitpos;
    unsigned int current_pos = stream->bitpos;
    while (stream->bitpos <= 1023 + old_pos)
    {
        if (current_pos != stream->bitpos)
        {
            return 0;
        }
        struct PacketHeader packet_header = {0, 0};
        PacketHeader_DecodeBit(&packet_header, stream);
        struct PacketHeader *ptr = 0;
        if (packet_header.NID_PACKET == 255)
        {
            ptr = PacketFactory_BothWays(packet_header);
            ((ptr) ? (void) (0) : __assert_fail ("ptr", "..//Telegram/EurobaliseTelegram.c", 80, __extension__ __PRETTY_FUNCTION__));
            EurobaliseTelegram_Add(t, ptr);
            break;
        }
        if (t->header.Q_UPDOWN == 1)
        {
            ptr = PacketFactory_TrackToTrain(packet_header);
            if (ptr)
            {
                EurobaliseTelegram_Add(t, ptr);
            }
            else
            {
                return 0;
            }
        }
        else
        {
            ((t->header.Q_UPDOWN == 0) ? (void) (0) : __assert_fail ("t->header.Q_UPDOWN == 0", "..//Telegram/EurobaliseTelegram.c", 105, __extension__ __PRETTY_FUNCTION__));
            ptr = PacketFactory_TrainToTrack(packet_header);
            if (ptr)
            {
                EurobaliseTelegram_Add(t, ptr);
            }
            else
            {
                return 0;
            }
        }
        if (ptr)
        {
            Packet_DecodeBit(ptr, stream);
            current_pos += Packet_Length(ptr);
        }
    }
    return 1;
}

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

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


decompiled_code:
__int64 __fastcall EurobaliseTelegram_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // er13
int v4; // er14
unsigned int v5; // ebx
unsigned int v6; // er14
unsigned __int64 *v7; // rax
__int64 v8; // rax

v2 = 0;
if ( (unsigned int)TelegramHeader_EncodeBit(a1, a2) == 1 )
{
v2 = 1;
v4 = *(_DWORD *)(a2 + 12);
if ( *(_QWORD *)PacketSequence_Back((__int64)(a1 + 10)) != 255LL )
_assert_fail(
"PacketSequence_Back(&t->packets)->NID_PACKET == 255",
"..//Telegram/EurobaliseTelegram.c",
0x8Cu,
"EurobaliseTelegram_EncodeBit");
v5 = 0;
v6 = v4 + 1023;
while ( (unsigned int)EurobaliseTelegram_Size((__int64)a1) > v5 )
{
if ( *(_DWORD *)(a2 + 12) > v6 )
return 0;
v7 = (unsigned __int64 *)EurobaliseTelegram_Get((__int64)a1, v5);
if ( (unsigned int)PacketHeader_EncodeBit(v7, a2) != 1 )
return 0;
v8 = EurobaliseTelegram_Get((__int64)a1, v5);
if ( (unsigned int)Packet_EncodeBit(v8, a2) != 1 )
return 0;
++v5;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // er13
int v4; // er14
unsigned int v5; // ebx
unsigned int v6; // er14
unsigned __int64 *v7; // rax
__int64 v8; // rax

v2 = 0;
if ( (unsigned int)func14(a1, a2) == 1 )
{
v2 = 1;
v4 = *(_DWORD *)(a2 + 12);
if ( *(_QWORD *)func11((__int64)(a1 + 10)) != 255LL )
_assert_fail(
"PacketSequence_Back(&t->packets)->NID_PACKET == 255",
"..//Telegram/EurobaliseTelegram.c",
0x8Cu,
"EurobaliseTelegram_EncodeBit");
v5 = 0;
v6 = v4 + 1023;
while ( (unsigned int)func5((__int64)a1) > v5 )
{
if ( *(_DWORD *)(a2 + 12) > v6 )
return 0;
v7 = (unsigned __int64 *)func10((__int64)a1, v5);
if ( (unsigned int)func15(v7, a2) != 1 )
return 0;
v8 = func10((__int64)a1, v5);
if ( (unsigned int)Packet_EncodeBit(v8, a2) != 1 )
return 0;
++v5;
}
}
return v2;
}

original_code:
int EurobaliseTelegram_EncodeBit(const EurobaliseTelegram* t, Bitstream* stream)
{
    if (TelegramHeader_EncodeBit(&t->header, stream) != 1)
    {
        return 0;
    }
    uint32_t old_pos = stream->bitpos;
    ((PacketSequence_Back(&t->packets)->NID_PACKET == 255) ? (void) (0) : __assert_fail ("PacketSequence_Back(&t->packets)->NID_PACKET == 255", "..//Telegram/EurobaliseTelegram.c", 140, __extension__ __PRETTY_FUNCTION__));
    for (uint32_t i = 0; i < EurobaliseTelegram_Size(t); ++i)
    {
        if (stream->bitpos > 1023 + old_pos)
        {
            return 0;
        }
        if (PacketHeader_EncodeBit(EurobaliseTelegram_Get(t, i), stream) != 1)
        {
            return 0;
        }
        if (Packet_EncodeBit(EurobaliseTelegram_Get(t, i), stream) != 1)
        {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int EurobaliseTelegram_EncodeBit(struct EurobaliseTelegram *t, struct Bitstream *stream)
{
    if (TelegramHeader_EncodeBit(&t->header, stream) != 1)
    {
        return 0;
    }
    unsigned int old_pos = stream->bitpos;
    ((PacketSequence_Back(&t->packets)->NID_PACKET == 255) ? (void) (0) : __assert_fail ("PacketSequence_Back(&t->packets)->NID_PACKET == 255", "..//Telegram/EurobaliseTelegram.c", 140, __extension__ __PRETTY_FUNCTION__));
    for (unsigned int i = 0; i < EurobaliseTelegram_Size(t); ++i)
    {
        if (stream->bitpos > 1023 + old_pos)
        {
            return 0;
        }
        if (PacketHeader_EncodeBit(EurobaliseTelegram_Get(t, i), stream) != 1)
        {
            return 0;
        }
        if (Packet_EncodeBit(EurobaliseTelegram_Get(t, i), stream) != 1)
        {
            return 0;
        }
    }
    return 1;
}

variable_types:
i
unsigned int

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


decompiled_code:
__int64 __fastcall EurobaliseTelegram_EncodeInt(__int64 a1)
{
return PacketSequence_EncodeInt(a1 + 80);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
return PacketSequence_EncodeInt(a1 + 80);
}

original_code:
int EurobaliseTelegram_EncodeInt(const EurobaliseTelegram* t, CompressedPackets* packetStruct)
{
    return PacketSequence_EncodeInt(&(t->packets), packetStruct);
}

canonical_original_code:
int EurobaliseTelegram_EncodeInt(struct EurobaliseTelegram *t, struct CompressedPackets_T_Common_Types_Pkg *packetStruct)
{
    return PacketSequence_EncodeInt(&(t->packets), packetStruct);
}

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

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


decompiled_code:
__int64 __fastcall EurobaliseTelegram_DecodeInt(_QWORD *a1, __int64 a2)
{
return PacketSequence_DecodeInt(a1 + 10, *a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func22(_QWORD *a1, __int64 a2)
{
return PacketSequence_DecodeInt(a1 + 10, *a1, a2);
}

original_code:
int EurobaliseTelegram_DecodeInt(EurobaliseTelegram* t, const CompressedPackets* packetStruct)
{
    return PacketSequence_DecodeInt(&(t->packets), t->header.Q_UPDOWN, packetStruct);;
}

canonical_original_code:
int EurobaliseTelegram_DecodeInt(struct EurobaliseTelegram *t, struct CompressedPackets_T_Common_Types_Pkg *packetStruct)
{
    return PacketSequence_DecodeInt(&(t->packets), t->header.Q_UPDOWN, packetStruct);;
}

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


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

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

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

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

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

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

variable_types:
value
unsigned long

variable_types:
length
unsigned int

variable_types:
MaxValue
unsigned long


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

v1 = UpperBitsNotSet64(a1[2], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[3], 13);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[4], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[5], 15);
if ( v1 )
v1 = UpperBitsNotSet64(a1[6], 1);
}
}
}
if ( a1[6] == 1 )
{
if ( !v1 )
goto LABEL_15;
v1 = UpperBitsNotSet64(a1[7], 10);
if ( !v1 )
goto LABEL_15;
}
else if ( !v1 )
{
goto LABEL_15;
}
v1 = UpperBitsNotSet64(a1[8], 14);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[9], 1);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[10], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[11], 6);
if ( v1 )
v1 = UpperBitsNotSet64(a1[12], 5);
}
}
}
LABEL_15:
for ( i = 0; i < a1[12]; ++i )
{
if ( v1 )
v1 = Linking_1_UpperBitsNotSet(&a1[7 * i + 13]) != 0;
}
return v1;
}

original_code:
int Linking_UpperBitsNotSet(const Linking* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_LINK, 15);
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    status = status && UpperBitsNotSet64(p->Q_LINKORIENTATION, 1) ;
    status = status && UpperBitsNotSet64(p->Q_LINKREACTION, 2) ;
    status = status && UpperBitsNotSet64(p->Q_LOCACC, 6) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && Linking_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Linking_UpperBitsNotSet(struct Linking *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->D_LINK, 15);
    status = status && UpperBitsNotSet64(p->Q_NEWCOUNTRY, 1) ;
    if (p->Q_NEWCOUNTRY == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_C, 10);
    }
    status = status && UpperBitsNotSet64(p->NID_BG, 14);
    status = status && UpperBitsNotSet64(p->Q_LINKORIENTATION, 1) ;
    status = status && UpperBitsNotSet64(p->Q_LINKREACTION, 2) ;
    status = status && UpperBitsNotSet64(p->Q_LOCACC, 6) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && Linking_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct Linking { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_LINK; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINKORIENTATION; unsigned long Q_LINKREACTION; unsigned long Q_LOCACC; unsigned long N_ITER_1; struct Linking_1 { unsigned long D_LINK; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINKORIENTATION; unsigned long Q_LINKREACTION; unsigned long Q_LOCACC; } sub_1[31]; } *

variable_types: status int

user_defined_types: struct Linking { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_LINK; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINKORIENTATION; unsigned long Q_LINKREACTION; unsigned long Q_LOCACC; unsigned long N_ITER_1; struct Linking_1 sub_1[31]; }


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

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

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

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

original_code:
int Linking_EncodeBit(const Linking* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 61))
    {
        if (Linking_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_LINK);
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            Bitstream_Write(stream, 1, p->Q_LINKORIENTATION);
            Bitstream_Write(stream, 2, p->Q_LINKREACTION);
            Bitstream_Write(stream, 6, p->Q_LOCACC);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                Linking_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int Linking_EncodeBit(struct Linking *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 61))
    {
        if (Linking_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 15, p->D_LINK);
            Bitstream_Write(stream, 1, p->Q_NEWCOUNTRY);
            if (p->Q_NEWCOUNTRY == 1)
            {
                Bitstream_Write(stream, 10, p->NID_C);
            }
            Bitstream_Write(stream, 14, p->NID_BG);
            Bitstream_Write(stream, 1, p->Q_LINKORIENTATION);
            Bitstream_Write(stream, 2, p->Q_LINKREACTION);
            Bitstream_Write(stream, 6, p->Q_LOCACC);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                Linking_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct Linking_1 { unsigned long D_LINK; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINKORIENTATION; unsigned long Q_LINKREACTION; unsigned long Q_LOCACC; }


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

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

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

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

original_code:
int Linking_DecodeBit(Linking* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 61))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_LINK = Bitstream_Read(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);
        }
        {
            p->Q_LINKORIENTATION = Bitstream_Read(stream, 1);
        }
        {
            p->Q_LINKREACTION = Bitstream_Read(stream, 2);
        }
        {
            p->Q_LOCACC = Bitstream_Read(stream, 6);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            Linking_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int Linking_DecodeBit(struct Linking *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 61))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_LINK = Bitstream_Read(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);
        }
        {
            p->Q_LINKORIENTATION = Bitstream_Read(stream, 1);
        }
        {
            p->Q_LINKREACTION = Bitstream_Read(stream, 2);
        }
        {
            p->Q_LOCACC = Bitstream_Read(stream, 6);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            Linking_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int Linking_EncodeInt(const Linking* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 5;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->D_LINK;
    stream[startAddress++] = p->Q_NEWCOUNTRY;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_BG;
    stream[startAddress++] = p->Q_LINKORIENTATION;
    stream[startAddress++] = p->Q_LINKREACTION;
    stream[startAddress++] = p->Q_LOCACC;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        Linking_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int Linking_EncodeInt(struct Linking *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 5;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->N_ITER_1 + 1;
    stream[startAddress++] = p->D_LINK;
    stream[startAddress++] = p->Q_NEWCOUNTRY;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_BG;
    stream[startAddress++] = p->Q_LINKORIENTATION;
    stream[startAddress++] = p->Q_LINKREACTION;
    stream[startAddress++] = p->Q_LOCACC;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        Linking_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

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

variable_types:
stream
int *

variable_types: startAddress int


original_code:
int Linking_DecodeInt(Linking* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 5)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->D_LINK = stream[startAddress++];
    p->Q_NEWCOUNTRY = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    p->Q_LINKORIENTATION = stream[startAddress++];
    p->Q_LINKREACTION = stream[startAddress++];
    p->Q_LOCACC = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        Linking_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int Linking_DecodeInt(struct Linking *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 5)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++] - 1;
    p->D_LINK = stream[startAddress++];
    p->Q_NEWCOUNTRY = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_BG = stream[startAddress++];
    p->Q_LINKORIENTATION = stream[startAddress++];
    p->Q_LINKREACTION = stream[startAddress++];
    p->Q_LOCACC = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        Linking_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( LinkingMemoryFreeList == -1 )
{
if ( (unsigned __int64)LinkingMemoryTop > 7 )
return 0LL;
v0 = &LinkingMemory[230 * LinkingMemoryTop++];
}
else
{
v0 = &LinkingMemory[230 * LinkingMemoryFreeList];
LinkingMemoryFreeList = *v0;
}
Linking_Init(v0);
return v0;
}

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

if ( LinkingMemoryFreeList == -1 )
{
if ( (unsigned __int64)LinkingMemoryTop > 7 )
return 0LL;
v0 = &LinkingMemory[230 * LinkingMemoryTop++];
}
else
{
v0 = &LinkingMemory[230 * LinkingMemoryFreeList];
LinkingMemoryFreeList = *v0;
}
func2(v0);
return v0;
}

original_code:
Linking* Linking_New(void)
{
    Linking* ptr;
    if (LinkingMemoryFreeList != (-1))
    {
        ptr = &LinkingMemory[LinkingMemoryFreeList];
        LinkingMemoryFreeList = LinkingMemory[LinkingMemoryFreeList].header.NID_PACKET;
    }
    else if (LinkingMemoryTop < 8)
    {
        ptr = &LinkingMemory[LinkingMemoryTop];
        LinkingMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    Linking_Init(ptr);
    return ptr;
}

canonical_original_code:
struct Linking *Linking_New()
{
    struct Linking *ptr;
    if (LinkingMemoryFreeList != (-1))
    {
        ptr = &LinkingMemory[LinkingMemoryFreeList];
        LinkingMemoryFreeList = LinkingMemory[LinkingMemoryFreeList].header.NID_PACKET;
    }
    else if (LinkingMemoryTop < 8)
    {
        ptr = &LinkingMemory[LinkingMemoryTop];
        LinkingMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    Linking_Init(ptr);
    return ptr;
}

return_type: struct Linking { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_LINK; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINKORIENTATION; unsigned long Q_LINKREACTION; unsigned long Q_LOCACC; unsigned long N_ITER_1; struct Linking_1 { unsigned long D_LINK; unsigned long Q_NEWCOUNTRY; unsigned long NID_C; unsigned long NID_BG; unsigned long Q_LINKORIENTATION; unsigned long Q_LINKREACTION; unsigned long Q_LOCACC; } sub_1[31]; } *


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

*(_QWORD *)a1 = LinkingMemoryFreeList;
result = 0x2A4BAFDC61F2A4BBLL;
LinkingMemoryFreeList = 0x2A4BAFDC61F2A4BBLL * ((a1 - (char *)LinkingMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = LinkingMemoryFreeList;
result = 0x2A4BAFDC61F2A4BBLL;
LinkingMemoryFreeList = 0x2A4BAFDC61F2A4BBLL * ((a1 - (char *)LinkingMemory) >> 4);
return result;
}

original_code:
void Linking_Delete(Linking* ptr)
{
    ptr->header.NID_PACKET = LinkingMemoryFreeList;
    LinkingMemoryFreeList = ptr - LinkingMemory;
}

canonical_original_code:
void Linking_Delete(struct Linking *ptr)
{
    ptr->header.NID_PACKET = LinkingMemoryFreeList;
    LinkingMemoryFreeList = ptr - LinkingMemory;
}


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

v1 = UpperBitsNotSet64(a1[2], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[3], 13);
if ( v1 )
v1 = UpperBitsNotSet64(a1[4], 3);
}
if ( a1[4] != 1 )
{
if ( !v1 )
goto LABEL_7;
goto LABEL_6;
}
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[5], 8);
if ( v1 )
{
LABEL_6:
v1 = UpperBitsNotSet64(a1[6], 5);
goto LABEL_7;
}
}
LABEL_7:
for ( i = 0; i < a1[6]; ++i )
{
if ( v1 )
v1 = ConditionalLevelTransitionOrder_1_UpperBitsNotSet(&a1[2 * i + 7]) != 0;
}
return v1;
}

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

v1 = func0(a1[2], 2);
if ( v1 )
{
v1 = func0(a1[3], 13);
if ( v1 )
v1 = func0(a1[4], 3);
}
if ( a1[4] != 1 )
{
if ( !v1 )
goto LABEL_7;
goto LABEL_6;
}
if ( v1 )
{
v1 = func0(a1[5], 8);
if ( v1 )
{
LABEL_6:
v1 = func0(a1[6], 5);
goto LABEL_7;
}
}
LABEL_7:
for ( i = 0; i < a1[6]; ++i )
{
if ( v1 )
v1 = ConditionalLevelTransitionOrder_1_UpperBitsNotSet(&a1[2 * i + 7]) != 0;
}
return v1;
}

original_code:
int ConditionalLevelTransitionOrder_UpperBitsNotSet(const ConditionalLevelTransitionOrder* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->M_LEVELTR, 3) ;
    if (p->M_LEVELTR == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ConditionalLevelTransitionOrder_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ConditionalLevelTransitionOrder_UpperBitsNotSet(struct ConditionalLevelTransitionOrder *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->M_LEVELTR, 3) ;
    if (p->M_LEVELTR == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && ConditionalLevelTransitionOrder_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ConditionalLevelTransitionOrder { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long N_ITER_1; struct ConditionalLevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; } sub_1[31]; } *

user_defined_types: struct ConditionalLevelTransitionOrder { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long N_ITER_1; struct ConditionalLevelTransitionOrder_1 sub_1[31]; }


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

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

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

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

original_code:
int ConditionalLevelTransitionOrder_EncodeBit(const ConditionalLevelTransitionOrder* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 23))
    {
        if (ConditionalLevelTransitionOrder_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                ConditionalLevelTransitionOrder_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ConditionalLevelTransitionOrder_EncodeBit(struct ConditionalLevelTransitionOrder *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 23))
    {
        if (ConditionalLevelTransitionOrder_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                ConditionalLevelTransitionOrder_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct ConditionalLevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; }


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

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

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

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

original_code:
int ConditionalLevelTransitionOrder_DecodeBit(ConditionalLevelTransitionOrder* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 23))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            ConditionalLevelTransitionOrder_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ConditionalLevelTransitionOrder_DecodeBit(struct ConditionalLevelTransitionOrder *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 23))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            ConditionalLevelTransitionOrder_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


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

canonical_original_code:
int ConditionalLevelTransitionOrder_EncodeInt(struct ConditionalLevelTransitionOrder *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 46;
    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 - +1;
    stream[startAddress++] = p->M_LEVELTR;
    stream[startAddress++] = p->NID_STM;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ConditionalLevelTransitionOrder_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


decompiled_code:
_BOOL8 __fastcall ConditionalLevelTransitionOrder_DecodeInt(_QWORD *a1, _DWORD *a2, __int64 a3)
{
_BOOL8 result; // rax
int v5; // edx
__int64 v6; // rcx
__int64 v7; // rax
unsigned int v8; // ebx
int v9[11]; // [rsp+0h] [rbp-2Ch] BYREF

result = 0LL;
if ( *a2 == 46 )
{
v5 = a2[3];
v6 = 4LL * v5;
*a1 = *(int *)(a3 + v6);
a1[2] = *(int *)(a3 + v6 + 4);
a1[3] = *(int *)(a3 + v6 + 8);
v7 = *(_DWORD *)(a3 + v6 + 12) - 1;
a1[6] = v7;
a1[4] = *(int *)(a3 + v6 + 16);
v9[0] = v5 + 6;
a1[5] = *(int *)(a3 + v6 + 20);
if ( v7 )
{
v8 = 0;
do
ConditionalLevelTransitionOrder_1_DecodeInt(&a1[2 * v8++ + 7], v9, a3);
while ( (unsigned __int64)v8 < a1[6] );
}
result = v9[0] - 1 == a2[4];
}
return result;
}

original_code:
int ConditionalLevelTransitionOrder_DecodeInt(ConditionalLevelTransitionOrder* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 46)
    {
         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++] - 1;
    p->M_LEVELTR = stream[startAddress++];
    p->NID_STM = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        ConditionalLevelTransitionOrder_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int ConditionalLevelTransitionOrder_DecodeInt(struct ConditionalLevelTransitionOrder *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 46)
    {
         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++] - 1;
    p->M_LEVELTR = stream[startAddress++];
    p->NID_STM = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        ConditionalLevelTransitionOrder_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( ConditionalLevelTransitionOrderMemoryFreeList == -1 )
{
if ( (unsigned __int64)ConditionalLevelTransitionOrderMemoryTop > 7 )
return 0LL;
v0 = &ConditionalLevelTransitionOrderMemory[69 * ConditionalLevelTransitionOrderMemoryTop++];
}
else
{
v0 = &ConditionalLevelTransitionOrderMemory[69 * ConditionalLevelTransitionOrderMemoryFreeList];
ConditionalLevelTransitionOrderMemoryFreeList = *v0;
}
ConditionalLevelTransitionOrder_Init(v0);
return v0;
}

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

if ( ConditionalLevelTransitionOrderMemoryFreeList == -1 )
{
if ( (unsigned __int64)ConditionalLevelTransitionOrderMemoryTop > 7 )
return 0LL;
v0 = &ConditionalLevelTransitionOrderMemory[69 * ConditionalLevelTransitionOrderMemoryTop++];
}
else
{
v0 = &ConditionalLevelTransitionOrderMemory[69 * ConditionalLevelTransitionOrderMemoryFreeList];
ConditionalLevelTransitionOrderMemoryFreeList = *v0;
}
func2(v0);
return v0;
}

original_code:
ConditionalLevelTransitionOrder* ConditionalLevelTransitionOrder_New(void)
{
    ConditionalLevelTransitionOrder* ptr;
    if (ConditionalLevelTransitionOrderMemoryFreeList != (-1))
    {
        ptr = &ConditionalLevelTransitionOrderMemory[ConditionalLevelTransitionOrderMemoryFreeList];
        ConditionalLevelTransitionOrderMemoryFreeList = ConditionalLevelTransitionOrderMemory[ConditionalLevelTransitionOrderMemoryFreeList].header.NID_PACKET;
    }
    else if (ConditionalLevelTransitionOrderMemoryTop < 8)
    {
        ptr = &ConditionalLevelTransitionOrderMemory[ConditionalLevelTransitionOrderMemoryTop];
        ConditionalLevelTransitionOrderMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ConditionalLevelTransitionOrder_Init(ptr);
    return ptr;
}

canonical_original_code:
struct ConditionalLevelTransitionOrder *ConditionalLevelTransitionOrder_New()
{
    struct ConditionalLevelTransitionOrder *ptr;
    if (ConditionalLevelTransitionOrderMemoryFreeList != (-1))
    {
        ptr = &ConditionalLevelTransitionOrderMemory[ConditionalLevelTransitionOrderMemoryFreeList];
        ConditionalLevelTransitionOrderMemoryFreeList = ConditionalLevelTransitionOrderMemory[ConditionalLevelTransitionOrderMemoryFreeList].header.NID_PACKET;
    }
    else if (ConditionalLevelTransitionOrderMemoryTop < 8)
    {
        ptr = &ConditionalLevelTransitionOrderMemory[ConditionalLevelTransitionOrderMemoryTop];
        ConditionalLevelTransitionOrderMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ConditionalLevelTransitionOrder_Init(ptr);
    return ptr;
}

return_type: struct ConditionalLevelTransitionOrder { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long N_ITER_1; struct ConditionalLevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; } sub_1[31]; } *


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

*a1 = ConditionalLevelTransitionOrderMemoryFreeList;
result = 0xF128CFC4A33F128DLL;
ConditionalLevelTransitionOrderMemoryFreeList = 0xF128CFC4A33F128DLL * (a1 - ConditionalLevelTransitionOrderMemory);
return result;
}

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

*a1 = ConditionalLevelTransitionOrderMemoryFreeList;
result = 0xF128CFC4A33F128DLL;
ConditionalLevelTransitionOrderMemoryFreeList = 0xF128CFC4A33F128DLL * (a1 - ConditionalLevelTransitionOrderMemory);
return result;
}

original_code:
void ConditionalLevelTransitionOrder_Delete(ConditionalLevelTransitionOrder* ptr)
{
    ptr->header.NID_PACKET = ConditionalLevelTransitionOrderMemoryFreeList;
    ConditionalLevelTransitionOrderMemoryFreeList = ptr - ConditionalLevelTransitionOrderMemory;
}

canonical_original_code:
void ConditionalLevelTransitionOrder_Delete(struct ConditionalLevelTransitionOrder *ptr)
{
    ptr->header.NID_PACKET = ConditionalLevelTransitionOrderMemoryFreeList;
    ConditionalLevelTransitionOrderMemoryFreeList = ptr - ConditionalLevelTransitionOrderMemory;
}


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

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

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

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

original_code:
int PositionReportBasedOnTwoBaliseGroups_UpperBitsNotSet(const PositionReportBasedOnTwoBaliseGroups* 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->NID_PRVLRBG, 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 PositionReportBasedOnTwoBaliseGroups_UpperBitsNotSet(struct PositionReportBasedOnTwoBaliseGroups *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->NID_PRVLRBG, 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 PositionReportBasedOnTwoBaliseGroups { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LRBG; unsigned long NID_PRVLRBG; unsigned long D_LRBG; unsigned long Q_DIRLRBG; unsigned long Q_DLRBG; unsigned long L_DOUBTOVER; unsigned long L_DOUBTUNDER; unsigned long Q_LENGTH; unsigned long L_TRAININT; unsigned long V_TRAIN; unsigned long Q_DIRTRAIN; unsigned long M_MODE; unsigned long M_LEVEL; unsigned long NID_STM; } *

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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


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

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


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

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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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


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

v1 = *a1;
result = UpperBitsNotSet64(*a1, 1);
if ( v1 == 1 )
{
if ( !result )
return result;
result = UpperBitsNotSet64(a1[1], 10);
if ( !result )
return result;
}
else if ( !result )
{
return result;
}
result = UpperBitsNotSet64(a1[2], 14);
if ( result )
{
result = UpperBitsNotSet64(a1[3], 15);
if ( result )
{
result = UpperBitsNotSet64(a1[4], 1);
if ( result )
result = UpperBitsNotSet64(a1[5], 20);
}
}
return result;
}

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

v1 = *a1;
result = func0(*a1, 1);
if ( v1 == 1 )
{
if ( !result )
return result;
result = func0(a1[1], 10);
if ( !result )
return result;
}
else if ( !result )
{
return result;
}
result = func0(a1[2], 14);
if ( result )
{
result = func0(a1[3], 15);
if ( result )
{
result = func0(a1[4], 1);
if ( result )
result = func0(a1[5], 20);
}
}
return result;
}

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

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

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


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

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

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

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

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


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

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

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

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

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

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


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

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

variable_types:
startAddress
int *


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

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


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

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

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

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

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


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

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

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

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

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

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

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

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


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

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


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

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


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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

variable_types:
h
struct PacketHeader *


decompiled_code:
__int64 __fastcall PacketSequence_Clear(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

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

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

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

variable_types:
i
unsigned int


decompiled_code:
_BOOL8 __fastcall PacketSequence_Equal(__int64 a1, __int64 a2)
{
int v2; // edx
_BOOL8 result; // rax
unsigned int v4; // ebx

v2 = *(_DWORD *)(a1 + 400);
result = 0LL;
if ( v2 == *(_DWORD *)(a2 + 400) )
{
if ( v2 )
{
v4 = 0;
result = 1LL;
do
{
if ( result )
result = (unsigned int)Packet_Equal(*(_QWORD *)(a1 + 8LL * v4), *(_QWORD *)(a2 + 8LL * v4)) != 0;
++v4;
}
while ( *(_DWORD *)(a1 + 400) > v4 );
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // edx
_BOOL8 result; // rax
unsigned int v4; // ebx

v2 = *(_DWORD *)(a1 + 400);
result = 0LL;
if ( v2 == *(_DWORD *)(a2 + 400) )
{
if ( v2 )
{
v4 = 0;
result = 1LL;
do
{
if ( result )
result = (unsigned int)Packet_Equal(*(_QWORD *)(a1 + 8LL * v4), *(_QWORD *)(a2 + 8LL * v4)) != 0;
++v4;
}
while ( *(_DWORD *)(a1 + 400) > v4 );
}
else
{
result = 1LL;
}
}
return result;
}

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

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

variable_types:
b
struct PacketSequence *


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

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

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

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

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