decompiled_code:
__int64 __fastcall PacketSequence_DecodeInt(__int64 a1, __int64 a2, int *a3)
{
int *i; // rbx
__int64 v5; // rsi
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rdi
int *v10; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, int *a3)
{
int *i; // rbx
__int64 v5; // rsi
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rdi
int *v10; // [rsp+8h] [rbp-40h]

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

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

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

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


repo: openETCS/dataDictionary

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

return_type: int


decompiled_code:
_BOOL8 __fastcall RouteSuitabilityData_1_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v1; // ebx
unsigned __int64 v2; // rax

v1 = UpperBitsNotSet64(*a1, 15);
if ( v1 )
v1 = UpperBitsNotSet64(a1[1], 2);
v2 = a1[1];
if ( v2 )
{
if ( v2 == 1 )
{
if ( v1 && !UpperBitsNotSet64(a1[3], 7) )
v1 = 0;
}
else if ( v2 == 2 && v1 )
{
v1 = UpperBitsNotSet64(a1[4], 8);
}
}
else if ( v1 )
{
v1 = UpperBitsNotSet64(a1[2], 8);
}
return v1;
}

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

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

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

variable_types: status int


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

if ( !(unsigned int)Bitstream_Normal(a2, 17LL) )
return 0xFFFFFFFFLL;
if ( !RouteSuitabilityData_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 2LL, a1[1]);
if ( !a1[1] )
Bitstream_Write(a2, 8LL, a1[2]);
if ( a1[1] == 1 )
Bitstream_Write(a2, 7LL, a1[3]);
result = 1LL;
if ( a1[1] == 2 )
{
Bitstream_Write(a2, 8LL, a1[4]);
result = 1LL;
}
return result;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 17LL) )
return 0xFFFFFFFFLL;
if ( !func1(a1) )
return 4294967294LL;
Bitstream_Write(a2, 15LL, *a1);
Bitstream_Write(a2, 2LL, a1[1]);
if ( !a1[1] )
Bitstream_Write(a2, 8LL, a1[2]);
if ( a1[1] == 1 )
Bitstream_Write(a2, 7LL, a1[3]);
result = 1LL;
if ( a1[1] == 2 )
{
Bitstream_Write(a2, 8LL, a1[4]);
result = 1LL;
}
return result;
}

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

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

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

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


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

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

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

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

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

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

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


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

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

variable_types:
startAddress
int *

variable_types:
stream
int *


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

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


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

result = UpperBitsNotSet64(a1[2], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[3], 13);
if ( result )
{
v2 = a1[4];
result = UpperBitsNotSet64(v2, 1);
if ( v2 != 1 )
{
if ( !result )
return result;
return UpperBitsNotSet64(a1[6], 14);
}
if ( result )
{
result = UpperBitsNotSet64(a1[5], 10);
if ( result )
return UpperBitsNotSet64(a1[6], 14);
}
}
}
return result;
}

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

result = func0(a1[2], 2);
if ( result )
{
result = func0(a1[3], 13);
if ( result )
{
v2 = a1[4];
result = func0(v2, 1);
if ( v2 != 1 )
{
if ( !result )
return result;
return func0(a1[6], 14);
}
if ( result )
{
result = func0(a1[5], 10);
if ( result )
return func0(a1[6], 14);
}
}
}
return result;
}

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

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

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

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


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

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

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

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

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


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

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

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

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

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

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


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

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

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

variable_types: startAddress int


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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

return_type: void


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

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

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

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

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

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

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

variable_types:
i
unsigned int

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


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

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

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

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

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

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

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


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

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

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

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

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

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


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

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


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

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


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

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

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

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

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

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

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


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

*a1 = Level23MovementAuthorityMemoryFreeList;
result = 0xD4766BF908B51D9BLL;
Level23MovementAuthorityMemoryFreeList = 0xD4766BF908B51D9BLL * (a1 - Level23MovementAuthorityMemory);
return result;
}

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

*a1 = Level23MovementAuthorityMemoryFreeList;
result = 0xD4766BF908B51D9BLL;
Level23MovementAuthorityMemoryFreeList = 0xD4766BF908B51D9BLL * (a1 - Level23MovementAuthorityMemory);
return result;
}

original_code:
void Level23MovementAuthority_Delete(Level23MovementAuthority* ptr)
{
    ptr->header.NID_PACKET = Level23MovementAuthorityMemoryFreeList;
    Level23MovementAuthorityMemoryFreeList = ptr - Level23MovementAuthorityMemory;
}

canonical_original_code:
void Level23MovementAuthority_Delete(struct Level23MovementAuthority *ptr)
{
    ptr->header.NID_PACKET = Level23MovementAuthorityMemoryFreeList;
    Level23MovementAuthorityMemoryFreeList = ptr - Level23MovementAuthorityMemory;
}


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

result = UpperBitsNotSet64(a1[2], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[3], 13);
if ( result )
{
result = UpperBitsNotSet64(a1[4], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[5], 15);
if ( result )
result = UpperBitsNotSet64(a1[6], 15);
}
}
}
return result;
}

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

result = func0(a1[2], 2);
if ( result )
{
result = func0(a1[3], 13);
if ( result )
{
result = func0(a1[4], 2);
if ( result )
{
result = func0(a1[5], 15);
if ( result )
result = func0(a1[6], 15);
}
}
}
return result;
}

original_code:
int ReversingAreaInformation_UpperBitsNotSet(const ReversingAreaInformation* 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_STARTREVERSE, 15);
    status = status && UpperBitsNotSet64(p->L_REVERSEAREA, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ReversingAreaInformation_UpperBitsNotSet(struct ReversingAreaInformation *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_STARTREVERSE, 15);
    status = status && UpperBitsNotSet64(p->L_REVERSEAREA, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct ReversingAreaInformation { 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_STARTREVERSE; unsigned long L_REVERSEAREA; } *

user_defined_types: struct ReversingAreaInformation { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_STARTREVERSE; unsigned long L_REVERSEAREA; }


decompiled_code:
__int64 __fastcall ReversingAreaInformation_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 47LL) )
return 0xFFFFFFFFLL;
if ( !ReversingAreaInformation_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, 15LL, a1[6]);
return 1LL;
}

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

original_code:
int ReversingAreaInformation_EncodeBit(const ReversingAreaInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 47))
    {
        if (ReversingAreaInformation_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_STARTREVERSE);
            Bitstream_Write(stream, 15, p->L_REVERSEAREA);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int ReversingAreaInformation_EncodeBit(struct ReversingAreaInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 47))
    {
        if (ReversingAreaInformation_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_STARTREVERSE);
            Bitstream_Write(stream, 15, p->L_REVERSEAREA);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

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

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

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

original_code:
int ReversingAreaInformation_DecodeBit(ReversingAreaInformation* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 47))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_STARTREVERSE = Bitstream_Read(stream, 15);
        }
        {
            p->L_REVERSEAREA = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int ReversingAreaInformation_DecodeBit(struct ReversingAreaInformation *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 47))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_STARTREVERSE = Bitstream_Read(stream, 15);
        }
        {
            p->L_REVERSEAREA = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int ReversingAreaInformation_EncodeInt(const ReversingAreaInformation* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 138;
    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->D_STARTREVERSE;
    stream[startAddress++] = p->L_REVERSEAREA;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int ReversingAreaInformation_EncodeInt(struct ReversingAreaInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 138;
    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->D_STARTREVERSE;
    stream[startAddress++] = p->L_REVERSEAREA;
    data->endAddress = startAddress-1;
    return 1;
}


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

canonical_original_code:
int ReversingAreaInformation_DecodeInt(struct ReversingAreaInformation *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 138)
    {
         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->D_STARTREVERSE = stream[startAddress++];
    p->L_REVERSEAREA = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( ReversingAreaInformationMemoryFreeList == -1 )
{
if ( (unsigned __int64)ReversingAreaInformationMemoryTop > 7 )
return 0LL;
v0 = &ReversingAreaInformationMemory[7 * ReversingAreaInformationMemoryTop++];
}
else
{
v0 = &ReversingAreaInformationMemory[7 * ReversingAreaInformationMemoryFreeList];
ReversingAreaInformationMemoryFreeList = *v0;
}
ReversingAreaInformation_Init(v0);
return v0;
}

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

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

original_code:
ReversingAreaInformation* ReversingAreaInformation_New(void)
{
    ReversingAreaInformation* ptr;
    if (ReversingAreaInformationMemoryFreeList != (-1))
    {
        ptr = &ReversingAreaInformationMemory[ReversingAreaInformationMemoryFreeList];
        ReversingAreaInformationMemoryFreeList = ReversingAreaInformationMemory[ReversingAreaInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (ReversingAreaInformationMemoryTop < 8)
    {
        ptr = &ReversingAreaInformationMemory[ReversingAreaInformationMemoryTop];
        ReversingAreaInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ReversingAreaInformation_Init(ptr);
    return ptr;
}

canonical_original_code:
struct ReversingAreaInformation *ReversingAreaInformation_New()
{
    struct ReversingAreaInformation *ptr;
    if (ReversingAreaInformationMemoryFreeList != (-1))
    {
        ptr = &ReversingAreaInformationMemory[ReversingAreaInformationMemoryFreeList];
        ReversingAreaInformationMemoryFreeList = ReversingAreaInformationMemory[ReversingAreaInformationMemoryFreeList].header.NID_PACKET;
    }
    else if (ReversingAreaInformationMemoryTop < 8)
    {
        ptr = &ReversingAreaInformationMemory[ReversingAreaInformationMemoryTop];
        ReversingAreaInformationMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    ReversingAreaInformation_Init(ptr);
    return ptr;
}

return_type: struct ReversingAreaInformation { 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_STARTREVERSE; unsigned long L_REVERSEAREA; } *


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

*a1 = ReversingAreaInformationMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
ReversingAreaInformationMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL * (a1 - ReversingAreaInformationMemory);
return result;
}

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

*a1 = ReversingAreaInformationMemoryFreeList;
result = 0x6DB6DB6DB6DB6DB7LL;
ReversingAreaInformationMemoryFreeList = 0x6DB6DB6DB6DB6DB7LL * (a1 - ReversingAreaInformationMemory);
return result;
}

original_code:
void ReversingAreaInformation_Delete(ReversingAreaInformation* ptr)
{
    ptr->header.NID_PACKET = ReversingAreaInformationMemoryFreeList;
    ReversingAreaInformationMemoryFreeList = ptr - ReversingAreaInformationMemory;
}

canonical_original_code:
void ReversingAreaInformation_Delete(struct ReversingAreaInformation *ptr)
{
    ptr->header.NID_PACKET = ReversingAreaInformationMemoryFreeList;
    ReversingAreaInformationMemoryFreeList = ptr - ReversingAreaInformationMemory;
}