decompiled_code:
_BOOL8 __fastcall InternationalStaticSpeedProfile_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rbp
unsigned __int64 v4; // rdx
unsigned __int64 v6; // rbp
_BOOL4 v7; // eax
unsigned __int64 v8; // rax
int v9; // er8
_BOOL4 v10; // eax
unsigned __int64 v11; // rcx
int v12; // eax

v1 = UpperBitsNotSet64(a1[2], 2);
v2 = a1[8];
if ( !v1
|| !UpperBitsNotSet64(a1[3], 13)
|| !UpperBitsNotSet64(a1[4], 2)
|| !UpperBitsNotSet64(a1[5], 15)
|| !UpperBitsNotSet64(a1[6], 7)
|| !UpperBitsNotSet64(a1[7], 1) )
{
LODWORD(v3) = 0;
if ( !v2 )
goto LABEL_6;
goto LABEL_4;
}
v7 = UpperBitsNotSet64(v2, 5);
if ( v2 )
{
LODWORD(v3) = 0;
if ( v7 )
{
v8 = 0LL;
while ( 1 )
{
v9 = InternationalStaticSpeedProfile_1_UpperBitsNotSet(&a1[2 * v8 + 9]);
v8 = (unsigned int)(v3 + 1);
LODWORD(v3) = v3 + 1;
if ( !v9 )
break;
if ( a1[8] <= v8 )
goto LABEL_24;
}
v2 = a1[8];
if ( v2 <= v8 )
{
v4 = a1[71];
if ( v4 )
goto LABEL_8;
return 0LL;
}
}
do
{
LABEL_4:
if ( (unsigned int)(v3 + 1) >= v2 )
break;
v3 = (unsigned int)(v3 + 2);
}
while ( v3 < v2 );
LABEL_6:
v4 = a1[71];
if ( v4 )
{
LABEL_8:
LODWORD(v6) = 0;
do
{
LABEL_9:
if ( (unsigned int)(v6 + 1) >= v4 )
break;
v6 = (unsigned int)(v6 + 2);
}
while ( v6 < v4 );
}
return 0LL;
}
if ( !v7 )
goto LABEL_6;
LABEL_24:
v10 = UpperBitsNotSet64(a1[71], 5);
if ( v4 )
{
LODWORD(v6) = 0;
if ( v10 )
{
v11 = 0LL;
while ( 1 )
{
v12 = InternationalStaticSpeedProfile_2_UpperBitsNotSet(&a1[66 * v11 + 72]);
v11 = (unsigned int)(v6 + 1);
LODWORD(v6) = v6 + 1;
if ( !v12 )
break;
if ( v11 >= a1[71] )
return 1LL;
}
v4 = a1[71];
if ( v11 < v4 )
goto LABEL_9;
return 0LL;
}
goto LABEL_9;
}
return v10;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rbp
unsigned __int64 v4; // rdx
unsigned __int64 v6; // rbp
_BOOL4 v7; // eax
unsigned __int64 v8; // rax
int v9; // er8
_BOOL4 v10; // eax
unsigned __int64 v11; // rcx
int v12; // eax

v1 = func0(a1[2], 2);
v2 = a1[8];
if ( !v1
|| !func0(a1[3], 13)
|| !func0(a1[4], 2)
|| !func0(a1[5], 15)
|| !func0(a1[6], 7)
|| !func0(a1[7], 1) )
{
LODWORD(v3) = 0;
if ( !v2 )
goto LABEL_6;
goto LABEL_4;
}
v7 = func0(v2, 5);
if ( v2 )
{
LODWORD(v3) = 0;
if ( v7 )
{
v8 = 0LL;
while ( 1 )
{
v9 = InternationalStaticSpeedProfile_1_UpperBitsNotSet(&a1[2 * v8 + 9]);
v8 = (unsigned int)(v3 + 1);
LODWORD(v3) = v3 + 1;
if ( !v9 )
break;
if ( a1[8] <= v8 )
goto LABEL_24;
}
v2 = a1[8];
if ( v2 <= v8 )
{
v4 = a1[71];
if ( v4 )
goto LABEL_8;
return 0LL;
}
}
do
{
LABEL_4:
if ( (unsigned int)(v3 + 1) >= v2 )
break;
v3 = (unsigned int)(v3 + 2);
}
while ( v3 < v2 );
LABEL_6:
v4 = a1[71];
if ( v4 )
{
LABEL_8:
LODWORD(v6) = 0;
do
{
LABEL_9:
if ( (unsigned int)(v6 + 1) >= v4 )
break;
v6 = (unsigned int)(v6 + 2);
}
while ( v6 < v4 );
}
return 0LL;
}
if ( !v7 )
goto LABEL_6;
LABEL_24:
v10 = func0(a1[71], 5);
if ( v4 )
{
LODWORD(v6) = 0;
if ( v10 )
{
v11 = 0LL;
while ( 1 )
{
v12 = InternationalStaticSpeedProfile_2_UpperBitsNotSet(&a1[66 * v11 + 72]);
v11 = (unsigned int)(v6 + 1);
LODWORD(v6) = v6 + 1;
if ( !v12 )
break;
if ( v11 >= a1[71] )
return 1LL;
}
v4 = a1[71];
if ( v11 < v4 )
goto LABEL_9;
return 0LL;
}
goto LABEL_9;
}
return v10;
}

original_code:
int InternationalStaticSpeedProfile_UpperBitsNotSet(const InternationalStaticSpeedProfile* 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_STATIC, 15);
    status = status && UpperBitsNotSet64(p->V_STATIC, 7) ;
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && InternationalStaticSpeedProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->N_ITER_2, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        status = status && InternationalStaticSpeedProfile_2_UpperBitsNotSet(&(p->sub_2[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int InternationalStaticSpeedProfile_UpperBitsNotSet(struct InternationalStaticSpeedProfile *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_STATIC, 15);
    status = status && UpperBitsNotSet64(p->V_STATIC, 7) ;
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && InternationalStaticSpeedProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->N_ITER_2, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        status = status && InternationalStaticSpeedProfile_2_UpperBitsNotSet(&(p->sub_2[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct InternationalStaticSpeedProfile { 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_STATIC; unsigned long V_STATIC; unsigned long Q_FRONT; unsigned long N_ITER_1; struct InternationalStaticSpeedProfile_1 { unsigned long NC_DIFF; unsigned long V_DIFF; } sub_1[31]; unsigned long N_ITER_2; struct InternationalStaticSpeedProfile_2 { unsigned long D_STATIC; unsigned long V_STATIC; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct InternationalStaticSpeedProfile_2_1 { unsigned long NC_DIFF; unsigned long V_DIFF; } sub_2_1[31]; } sub_2[31]; } *

user_defined_types: struct InternationalStaticSpeedProfile { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_STATIC; unsigned long V_STATIC; unsigned long Q_FRONT; unsigned long N_ITER_1; struct InternationalStaticSpeedProfile_1 sub_1[31]; unsigned long N_ITER_2; struct InternationalStaticSpeedProfile_2 sub_2[31]; }

user_defined_types: struct InternationalStaticSpeedProfile_2 { unsigned long D_STATIC; unsigned long V_STATIC; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct InternationalStaticSpeedProfile_2_1 sub_2_1[31]; }


repo: openETCS/dataDictionary

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

if ( !(unsigned int)Bitstream_Normal(a2, 50LL) )
return 0xFFFFFFFFLL;
if ( !InternationalStaticSpeedProfile_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, 7LL, a1[6]);
Bitstream_Write(a2, 1LL, a1[7]);
Bitstream_Write(a2, 5LL, a1[8]);
if ( a1[8] )
{
v2 = 0;
v3 = 0LL;
do
{
InternationalStaticSpeedProfile_1_EncodeBit(&a1[2 * v3 + 9], a2);
v3 = ++v2;
}
while ( v2 < a1[8] );
}
v4 = 0;
Bitstream_Write(a2, 5LL, a1[71]);
v5 = 0LL;
if ( a1[71] )
{
do
{
InternationalStaticSpeedProfile_2_EncodeBit(&a1[66 * v5 + 72], a2);
v5 = ++v4;
}
while ( v4 < a1[71] );
}
return 1LL;
}

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

if ( !(unsigned int)Bitstream_Normal(a2, 50LL) )
return 0xFFFFFFFFLL;
if ( !func5(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, 7LL, a1[6]);
Bitstream_Write(a2, 1LL, a1[7]);
Bitstream_Write(a2, 5LL, a1[8]);
if ( a1[8] )
{
v2 = 0;
v3 = 0LL;
do
{
InternationalStaticSpeedProfile_1_EncodeBit(&a1[2 * v3 + 9], a2);
v3 = ++v2;
}
while ( v2 < a1[8] );
}
v4 = 0;
Bitstream_Write(a2, 5LL, a1[71]);
v5 = 0LL;
if ( a1[71] )
{
do
{
InternationalStaticSpeedProfile_2_EncodeBit(&a1[66 * v5 + 72], a2);
v5 = ++v4;
}
while ( v4 < a1[71] );
}
return 1LL;
}

original_code:
int InternationalStaticSpeedProfile_EncodeBit(const InternationalStaticSpeedProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 50))
    {
        if (InternationalStaticSpeedProfile_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_STATIC);
            Bitstream_Write(stream, 7, p->V_STATIC);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                InternationalStaticSpeedProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 5, p->N_ITER_2);
            for (uint32_t i = 0; i < p->N_ITER_2; ++i)
            {
                InternationalStaticSpeedProfile_2_EncodeBit(&(p->sub_2[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int InternationalStaticSpeedProfile_EncodeBit(struct InternationalStaticSpeedProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 50))
    {
        if (InternationalStaticSpeedProfile_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_STATIC);
            Bitstream_Write(stream, 7, p->V_STATIC);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                InternationalStaticSpeedProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 5, p->N_ITER_2);
            for (unsigned int i = 0; i < p->N_ITER_2; ++i)
            {
                InternationalStaticSpeedProfile_2_EncodeBit(&(p->sub_2[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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

variable_types:
i
unsigned int

return_type: int

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

user_defined_types: struct InternationalStaticSpeedProfile_1 { unsigned long NC_DIFF; unsigned long V_DIFF; }

user_defined_types: struct InternationalStaticSpeedProfile_2_1 { unsigned long NC_DIFF; unsigned long V_DIFF; }


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

result = Bitstream_Normal(a2, 50LL);
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, 7LL);
a1[7] = Bitstream_Read(a2, 1LL);
v3 = Bitstream_Read(a2, 5LL);
a1[8] = v3;
if ( v3 )
{
v4 = 0;
v5 = 0LL;
do
{
InternationalStaticSpeedProfile_1_DecodeBit(&a1[2 * v5 + 9], a2);
v5 = ++v4;
}
while ( (unsigned __int64)v4 < a1[8] );
}
v6 = 0;
v7 = Bitstream_Read(a2, 5LL);
v8 = 0LL;
a1[71] = v7;
if ( v7 )
{
do
{
InternationalStaticSpeedProfile_2_DecodeBit(&a1[66 * v8 + 72], a2);
v8 = ++v6;
}
while ( (unsigned __int64)v6 < a1[71] );
}
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 50LL);
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, 7LL);
a1[7] = Bitstream_Read(a2, 1LL);
v3 = Bitstream_Read(a2, 5LL);
a1[8] = v3;
if ( v3 )
{
v4 = 0;
v5 = 0LL;
do
{
InternationalStaticSpeedProfile_1_DecodeBit(&a1[2 * v5 + 9], a2);
v5 = ++v4;
}
while ( (unsigned __int64)v4 < a1[8] );
}
v6 = 0;
v7 = Bitstream_Read(a2, 5LL);
v8 = 0LL;
a1[71] = v7;
if ( v7 )
{
do
{
InternationalStaticSpeedProfile_2_DecodeBit(&a1[66 * v8 + 72], a2);
v8 = ++v6;
}
while ( (unsigned __int64)v6 < a1[71] );
}
result = 1LL;
}
return result;
}

original_code:
int InternationalStaticSpeedProfile_DecodeBit(InternationalStaticSpeedProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 50))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_STATIC = Bitstream_Read(stream, 15);
        }
        {
            p->V_STATIC = Bitstream_Read(stream, 7);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            InternationalStaticSpeedProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
    {
            p->N_ITER_2 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_2; ++i)
        {
            InternationalStaticSpeedProfile_2_DecodeBit(&(p->sub_2[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int InternationalStaticSpeedProfile_DecodeBit(struct InternationalStaticSpeedProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 50))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_STATIC = Bitstream_Read(stream, 15);
        }
        {
            p->V_STATIC = Bitstream_Read(stream, 7);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            InternationalStaticSpeedProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
    {
            p->N_ITER_2 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_2; ++i)
        {
            InternationalStaticSpeedProfile_2_DecodeBit(&(p->sub_2[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

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


original_code:
int InternationalStaticSpeedProfile_EncodeInt(const InternationalStaticSpeedProfile* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 27;
    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_2 + 1;
    stream[startAddress++] = p->D_STATIC;
    stream[startAddress++] = p->V_STATIC;
    stream[startAddress++] = p->Q_FRONT;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        InternationalStaticSpeedProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        InternationalStaticSpeedProfile_2_EncodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int InternationalStaticSpeedProfile_EncodeInt(struct InternationalStaticSpeedProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 27;
    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_2 + 1;
    stream[startAddress++] = p->D_STATIC;
    stream[startAddress++] = p->V_STATIC;
    stream[startAddress++] = p->Q_FRONT;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        InternationalStaticSpeedProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        InternationalStaticSpeedProfile_2_EncodeInt(&(p->sub_2[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 InternationalStaticSpeedProfile_DecodeInt(InternationalStaticSpeedProfile* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 27)
    {
         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_2 = stream[startAddress++] - 1;
    p->D_STATIC = stream[startAddress++];
    p->V_STATIC = stream[startAddress++];
    p->Q_FRONT = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        InternationalStaticSpeedProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        InternationalStaticSpeedProfile_2_DecodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int InternationalStaticSpeedProfile_DecodeInt(struct InternationalStaticSpeedProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 27)
    {
         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_2 = stream[startAddress++] - 1;
    p->D_STATIC = stream[startAddress++];
    p->V_STATIC = stream[startAddress++];
    p->Q_FRONT = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        InternationalStaticSpeedProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        InternationalStaticSpeedProfile_2_DecodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

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


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

if ( InternationalStaticSpeedProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)InternationalStaticSpeedProfileMemoryTop > 7 )
return 0LL;
v3 = 2118 * InternationalStaticSpeedProfileMemoryTop++;
v0 = &InternationalStaticSpeedProfileMemory[v3];
}
else
{
v0 = &InternationalStaticSpeedProfileMemory[2118 * InternationalStaticSpeedProfileMemoryFreeList];
InternationalStaticSpeedProfileMemoryFreeList = *v0;
}
InternationalStaticSpeedProfile_Init(v0);
return v1;
}

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

if ( InternationalStaticSpeedProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)InternationalStaticSpeedProfileMemoryTop > 7 )
return 0LL;
v3 = 2118 * InternationalStaticSpeedProfileMemoryTop++;
v0 = &InternationalStaticSpeedProfileMemory[v3];
}
else
{
v0 = &InternationalStaticSpeedProfileMemory[2118 * InternationalStaticSpeedProfileMemoryFreeList];
InternationalStaticSpeedProfileMemoryFreeList = *v0;
}
func4(v0);
return v1;
}

original_code:
InternationalStaticSpeedProfile* InternationalStaticSpeedProfile_New(void)
{
    InternationalStaticSpeedProfile* ptr;
    if (InternationalStaticSpeedProfileMemoryFreeList != (-1))
    {
        ptr = &InternationalStaticSpeedProfileMemory[InternationalStaticSpeedProfileMemoryFreeList];
        InternationalStaticSpeedProfileMemoryFreeList = InternationalStaticSpeedProfileMemory[InternationalStaticSpeedProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (InternationalStaticSpeedProfileMemoryTop < 8)
    {
        ptr = &InternationalStaticSpeedProfileMemory[InternationalStaticSpeedProfileMemoryTop];
        InternationalStaticSpeedProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    InternationalStaticSpeedProfile_Init(ptr);
    return ptr;
}

canonical_original_code:
struct InternationalStaticSpeedProfile *InternationalStaticSpeedProfile_New()
{
    struct InternationalStaticSpeedProfile *ptr;
    if (InternationalStaticSpeedProfileMemoryFreeList != (-1))
    {
        ptr = &InternationalStaticSpeedProfileMemory[InternationalStaticSpeedProfileMemoryFreeList];
        InternationalStaticSpeedProfileMemoryFreeList = InternationalStaticSpeedProfileMemory[InternationalStaticSpeedProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (InternationalStaticSpeedProfileMemoryTop < 8)
    {
        ptr = &InternationalStaticSpeedProfileMemory[InternationalStaticSpeedProfileMemoryTop];
        InternationalStaticSpeedProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    InternationalStaticSpeedProfile_Init(ptr);
    return ptr;
}

return_type: struct InternationalStaticSpeedProfile { 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_STATIC; unsigned long V_STATIC; unsigned long Q_FRONT; unsigned long N_ITER_1; struct InternationalStaticSpeedProfile_1 { unsigned long NC_DIFF; unsigned long V_DIFF; } sub_1[31]; unsigned long N_ITER_2; struct InternationalStaticSpeedProfile_2 { unsigned long D_STATIC; unsigned long V_STATIC; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct InternationalStaticSpeedProfile_2_1 { unsigned long NC_DIFF; unsigned long V_DIFF; } sub_2_1[31]; } sub_2[31]; } *


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

*(_QWORD *)a1 = InternationalStaticSpeedProfileMemoryFreeList;
result = 0x7DF1FAAE88D2CB8BLL;
InternationalStaticSpeedProfileMemoryFreeList = 0x7DF1FAAE88D2CB8BLL
* ((a1 - (char *)InternationalStaticSpeedProfileMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = InternationalStaticSpeedProfileMemoryFreeList;
result = 0x7DF1FAAE88D2CB8BLL;
InternationalStaticSpeedProfileMemoryFreeList = 0x7DF1FAAE88D2CB8BLL
* ((a1 - (char *)InternationalStaticSpeedProfileMemory) >> 4);
return result;
}

original_code:
void InternationalStaticSpeedProfile_Delete(InternationalStaticSpeedProfile* ptr)
{
    ptr->header.NID_PACKET = InternationalStaticSpeedProfileMemoryFreeList;
    InternationalStaticSpeedProfileMemoryFreeList = ptr - InternationalStaticSpeedProfileMemory;
}

canonical_original_code:
void InternationalStaticSpeedProfile_Delete(struct InternationalStaticSpeedProfile *ptr)
{
    ptr->header.NID_PACKET = InternationalStaticSpeedProfileMemoryFreeList;
    InternationalStaticSpeedProfileMemoryFreeList = ptr - InternationalStaticSpeedProfileMemory;
}

return_type: void


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 DataUsedByApplicationsOutsideTheERTMSETCSSystem_UpperBitsNotSet(__int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx

result = UpperBitsNotSet64(*(_QWORD *)(a1 + 16), 13);
if ( result )
{
result = UpperBitsNotSet64(*(_QWORD *)(v2 + 24), 9);
if ( result )
result = UpperBitsNotSet64(*(_QWORD *)(v3 + 32), 64);
}
return result;
}

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

result = func0(*(_QWORD *)(a1 + 16), 13);
if ( result )
{
result = func0(*(_QWORD *)(v2 + 24), 9);
if ( result )
result = func0(*(_QWORD *)(v3 + 32), 64);
}
return result;
}

original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_UpperBitsNotSet(const DataUsedByApplicationsOutsideTheERTMSETCSSystem* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->NID_XUSER, 9) ;
    status = status && UpperBitsNotSet64(p->Other_data_depending_on__NID_XUSER, 64);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_UpperBitsNotSet(struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->NID_XUSER, 9) ;
    status = status && UpperBitsNotSet64(p->Other_data_depending_on__NID_XUSER, 64);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct DataUsedByApplicationsOutsideTheERTMSETCSSystem { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long NID_XUSER; unsigned long Other_data_depending_on__NID_XUSER; } *

variable_types: status int

user_defined_types: struct DataUsedByApplicationsOutsideTheERTMSETCSSystem { struct PacketHeader header; unsigned long L_PACKET; unsigned long NID_XUSER; unsigned long Other_data_depending_on__NID_XUSER; }


decompiled_code:
__int64 __fastcall DataUsedByApplicationsOutsideTheERTMSETCSSystem_EncodeBit(_QWORD *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 86LL) )
return 0xFFFFFFFFLL;
if ( !DataUsedByApplicationsOutsideTheERTMSETCSSystem_UpperBitsNotSet((__int64)a1) )
return 4294967294LL;
Bitstream_Write(a2, 13LL, a1[2]);
Bitstream_Write(a2, 9LL, a1[3]);
Bitstream_Write(a2, 64LL, a1[4]);
return 1LL;
}

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

original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_EncodeBit(const DataUsedByApplicationsOutsideTheERTMSETCSSystem* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 86))
    {
        if (DataUsedByApplicationsOutsideTheERTMSETCSSystem_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 9, p->NID_XUSER);
            Bitstream_Write(stream, 64, p->Other_data_depending_on__NID_XUSER);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_EncodeBit(struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 86))
    {
        if (DataUsedByApplicationsOutsideTheERTMSETCSSystem_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 9, p->NID_XUSER);
            Bitstream_Write(stream, 64, p->Other_data_depending_on__NID_XUSER);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

result = Bitstream_Normal(a2, 86LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 13LL);
a1[3] = Bitstream_Read(a2, 9LL);
a1[4] = Bitstream_Read(a2, 64LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 86LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 13LL);
a1[3] = Bitstream_Read(a2, 9LL);
a1[4] = Bitstream_Read(a2, 64LL);
result = 1LL;
}
return result;
}

original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_DecodeBit(DataUsedByApplicationsOutsideTheERTMSETCSSystem* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 86))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->NID_XUSER = Bitstream_Read(stream, 9);
        }
        {
            p->Other_data_depending_on__NID_XUSER = Bitstream_Read(stream, 64);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_DecodeBit(struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 86))
    {
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->NID_XUSER = Bitstream_Read(stream, 9);
        }
        {
            p->Other_data_depending_on__NID_XUSER = Bitstream_Read(stream, 64);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_EncodeInt(const DataUsedByApplicationsOutsideTheERTMSETCSSystem* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 44;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->NID_XUSER;
    stream[startAddress++] = p->Other_data_depending_on__NID_XUSER;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_EncodeInt(struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 44;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->NID_XUSER;
    stream[startAddress++] = p->Other_data_depending_on__NID_XUSER;
    data->endAddress = startAddress-1;
    return 1;
}


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

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

original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_DecodeInt(DataUsedByApplicationsOutsideTheERTMSETCSSystem* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 44)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->NID_XUSER = stream[startAddress++];
    p->Other_data_depending_on__NID_XUSER = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int DataUsedByApplicationsOutsideTheERTMSETCSSystem_DecodeInt(struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 44)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->NID_XUSER = stream[startAddress++];
    p->Other_data_depending_on__NID_XUSER = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList == -1 )
{
if ( (unsigned __int64)DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop > 7 )
return 0LL;
v3 = 5 * DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop++;
v0 = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[v3];
}
else
{
v0 = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[5
* DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList];
DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = *v0;
}
DataUsedByApplicationsOutsideTheERTMSETCSSystem_Init(v0);
return v1;
}

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

if ( DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList == -1 )
{
if ( (unsigned __int64)DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop > 7 )
return 0LL;
v3 = 5 * DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop++;
v0 = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[v3];
}
else
{
v0 = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[5
* DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList];
DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = *v0;
}
func1(v0);
return v1;
}

original_code:
DataUsedByApplicationsOutsideTheERTMSETCSSystem* DataUsedByApplicationsOutsideTheERTMSETCSSystem_New(void)
{
    DataUsedByApplicationsOutsideTheERTMSETCSSystem* ptr;
    if (DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList != (-1))
    {
        ptr = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList];
        DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList].header.NID_PACKET;
    }
    else if (DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop < 8)
    {
        ptr = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop];
        DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DataUsedByApplicationsOutsideTheERTMSETCSSystem_Init(ptr);
    return ptr;
}

canonical_original_code:
struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *DataUsedByApplicationsOutsideTheERTMSETCSSystem_New()
{
    struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *ptr;
    if (DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList != (-1))
    {
        ptr = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList];
        DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList].header.NID_PACKET;
    }
    else if (DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop < 8)
    {
        ptr = &DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory[DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop];
        DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    DataUsedByApplicationsOutsideTheERTMSETCSSystem_Init(ptr);
    return ptr;
}

return_type: struct DataUsedByApplicationsOutsideTheERTMSETCSSystem { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long L_PACKET; unsigned long NID_XUSER; unsigned long Other_data_depending_on__NID_XUSER; } *


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

*a1 = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL
* (a1
- DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory);
return result;
}

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

*a1 = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList;
result = 0xCCCCCCCCCCCCCCCDLL;
DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = 0xCCCCCCCCCCCCCCCDLL
* (a1
- DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory);
return result;
}

original_code:
void DataUsedByApplicationsOutsideTheERTMSETCSSystem_Delete(DataUsedByApplicationsOutsideTheERTMSETCSSystem* ptr)
{
    ptr->header.NID_PACKET = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList;
    DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = ptr - DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory;
}

canonical_original_code:
void DataUsedByApplicationsOutsideTheERTMSETCSSystem_Delete(struct DataUsedByApplicationsOutsideTheERTMSETCSSystem *ptr)
{
    ptr->header.NID_PACKET = DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList;
    DataUsedByApplicationsOutsideTheERTMSETCSSystemMemoryFreeList = ptr - DataUsedByApplicationsOutsideTheERTMSETCSSystemMemory;
}


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

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


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

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

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

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

original_code:
int LevelTransitionOrder_1_UpperBitsNotSet(const LevelTransitionOrder_1* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->M_LEVELTR, 3) ;
    if (p->M_LEVELTR == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    status = status && UpperBitsNotSet64(p->L_ACKLEVELTR, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int LevelTransitionOrder_1_UpperBitsNotSet(struct LevelTransitionOrder_1 *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->M_LEVELTR, 3) ;
    if (p->M_LEVELTR == 1)
    {
        status = status && UpperBitsNotSet64(p->NID_STM, 8) ;
    }
    status = status && UpperBitsNotSet64(p->L_ACKLEVELTR, 15);
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct LevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; } *


decompiled_code:
__int64 __fastcall LevelTransitionOrder_1_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 18LL) )
return 0xFFFFFFFFLL;
if ( !LevelTransitionOrder_1_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 3LL, *a1);
if ( *a1 == 1 )
Bitstream_Write(a2, 8LL, a1[1]);
Bitstream_Write(a2, 15LL, a1[2]);
return 1LL;
}

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

original_code:
int LevelTransitionOrder_1_EncodeBit(const LevelTransitionOrder_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        if (LevelTransitionOrder_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            Bitstream_Write(stream, 15, p->L_ACKLEVELTR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int LevelTransitionOrder_1_EncodeBit(struct LevelTransitionOrder_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        if (LevelTransitionOrder_1_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 3, p->M_LEVELTR);
            if (p->M_LEVELTR == 1)
            {
                Bitstream_Write(stream, 8, p->NID_STM);
            }
            Bitstream_Write(stream, 15, p->L_ACKLEVELTR);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct LevelTransitionOrder_1 { unsigned long M_LEVELTR; unsigned long NID_STM; unsigned long L_ACKLEVELTR; }


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

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

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

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

original_code:
int LevelTransitionOrder_1_DecodeBit(LevelTransitionOrder_1* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        {
            p->L_ACKLEVELTR = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int LevelTransitionOrder_1_DecodeBit(struct LevelTransitionOrder_1 *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 18))
    {
        {
            p->M_LEVELTR = Bitstream_Read(stream, 3);
        }
        if (p->M_LEVELTR == 1)
        {
            {
                p->NID_STM = Bitstream_Read(stream, 8);
            }
        }
        {
            p->L_ACKLEVELTR = Bitstream_Read(stream, 15);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int LevelTransitionOrder_1_EncodeInt(const LevelTransitionOrder_1* p, kcg_int* startAddress, kcg_int* stream)
{
    stream[(*startAddress)++] = p->M_LEVELTR;
    stream[(*startAddress)++] = p->NID_STM;
    stream[(*startAddress)++] = p->L_ACKLEVELTR;
    return 1;
}

canonical_original_code:
int LevelTransitionOrder_1_EncodeInt(struct LevelTransitionOrder_1 *p, int *startAddress, int *stream)
{
    stream[(*startAddress)++] = p->M_LEVELTR;
    stream[(*startAddress)++] = p->NID_STM;
    stream[(*startAddress)++] = p->L_ACKLEVELTR;
    return 1;
}

variable_types:
startAddress
int *


original_code:
int LevelTransitionOrder_1_DecodeInt(LevelTransitionOrder_1* p, kcg_int* startAddress, const kcg_int* stream)
{
    p->M_LEVELTR = stream[(*startAddress)++];
    p->NID_STM = stream[(*startAddress)++];
    p->L_ACKLEVELTR = stream[(*startAddress)++];
    return 1;
}

canonical_original_code:
int LevelTransitionOrder_1_DecodeInt(struct LevelTransitionOrder_1 *p, int *startAddress, int *stream)
{
    p->M_LEVELTR = stream[(*startAddress)++];
    p->NID_STM = stream[(*startAddress)++];
    p->L_ACKLEVELTR = stream[(*startAddress)++];
    return 1;
}


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

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

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

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

original_code:
int GradientProfile_UpperBitsNotSet(const GradientProfile* 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_GRADIENT, 15);
    status = status && UpperBitsNotSet64(p->Q_GDIR, 1) ;
    status = status && UpperBitsNotSet64(p->G_A, 8) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && GradientProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int GradientProfile_UpperBitsNotSet(struct GradientProfile *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_GRADIENT, 15);
    status = status && UpperBitsNotSet64(p->Q_GDIR, 1) ;
    status = status && UpperBitsNotSet64(p->G_A, 8) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && GradientProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct GradientProfile { 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_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; unsigned long N_ITER_1; struct GradientProfile_1 { unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; } sub_1[31]; } *

user_defined_types: struct GradientProfile { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; unsigned long N_ITER_1; struct GradientProfile_1 sub_1[31]; }


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

if ( !(unsigned int)Bitstream_Normal(a2, 46LL) )
return 0xFFFFFFFFLL;
if ( !GradientProfile_UpperBitsNotSet(a1) )
return 4294967294LL;
v2 = 0;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 15LL, a1[5]);
Bitstream_Write(a2, 1LL, a1[6]);
Bitstream_Write(a2, 8LL, a1[7]);
Bitstream_Write(a2, 5LL, a1[8]);
v3 = 0LL;
if ( a1[8] )
{
do
{
GradientProfile_1_EncodeBit(&a1[3 * v3 + 9], a2);
v3 = ++v2;
}
while ( v2 < a1[8] );
}
return 1LL;
}

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

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

original_code:
int GradientProfile_EncodeBit(const GradientProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 46))
    {
        if (GradientProfile_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_GRADIENT);
            Bitstream_Write(stream, 1, p->Q_GDIR);
            Bitstream_Write(stream, 8, p->G_A);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                GradientProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int GradientProfile_EncodeBit(struct GradientProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 46))
    {
        if (GradientProfile_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_GRADIENT);
            Bitstream_Write(stream, 1, p->Q_GDIR);
            Bitstream_Write(stream, 8, p->G_A);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                GradientProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

user_defined_types: struct GradientProfile_1 { unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; }


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

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

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

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

original_code:
int GradientProfile_DecodeBit(GradientProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 46))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_GRADIENT = Bitstream_Read(stream, 15);
        }
        {
            p->Q_GDIR = Bitstream_Read(stream, 1);
        }
        {
            p->G_A = Bitstream_Read(stream, 8);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            GradientProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int GradientProfile_DecodeBit(struct GradientProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 46))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_GRADIENT = Bitstream_Read(stream, 15);
        }
        {
            p->Q_GDIR = Bitstream_Read(stream, 1);
        }
        {
            p->G_A = Bitstream_Read(stream, 8);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            GradientProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int GradientProfile_EncodeInt(const GradientProfile* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 21;
    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_GRADIENT;
    stream[startAddress++] = p->Q_GDIR;
    stream[startAddress++] = p->G_A;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        GradientProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int GradientProfile_EncodeInt(struct GradientProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 21;
    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_GRADIENT;
    stream[startAddress++] = p->Q_GDIR;
    stream[startAddress++] = p->G_A;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        GradientProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int GradientProfile_DecodeInt(GradientProfile* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 21)
    {
         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_GRADIENT = stream[startAddress++];
    p->Q_GDIR = stream[startAddress++];
    p->G_A = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        GradientProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int GradientProfile_DecodeInt(struct GradientProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 21)
    {
         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_GRADIENT = stream[startAddress++];
    p->Q_GDIR = stream[startAddress++];
    p->G_A = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        GradientProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( GradientProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)GradientProfileMemoryTop > 7 )
return 0LL;
v3 = 102 * GradientProfileMemoryTop++;
v0 = &GradientProfileMemory[v3];
}
else
{
v0 = &GradientProfileMemory[102 * GradientProfileMemoryFreeList];
GradientProfileMemoryFreeList = *v0;
}
GradientProfile_Init(v0);
return v1;
}

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

if ( GradientProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)GradientProfileMemoryTop > 7 )
return 0LL;
v3 = 102 * GradientProfileMemoryTop++;
v0 = &GradientProfileMemory[v3];
}
else
{
v0 = &GradientProfileMemory[102 * GradientProfileMemoryFreeList];
GradientProfileMemoryFreeList = *v0;
}
func2(v0);
return v1;
}

original_code:
GradientProfile* GradientProfile_New(void)
{
    GradientProfile* ptr;
    if (GradientProfileMemoryFreeList != (-1))
    {
        ptr = &GradientProfileMemory[GradientProfileMemoryFreeList];
        GradientProfileMemoryFreeList = GradientProfileMemory[GradientProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (GradientProfileMemoryTop < 8)
    {
        ptr = &GradientProfileMemory[GradientProfileMemoryTop];
        GradientProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    GradientProfile_Init(ptr);
    return ptr;
}

canonical_original_code:
struct GradientProfile *GradientProfile_New()
{
    struct GradientProfile *ptr;
    if (GradientProfileMemoryFreeList != (-1))
    {
        ptr = &GradientProfileMemory[GradientProfileMemoryFreeList];
        GradientProfileMemoryFreeList = GradientProfileMemory[GradientProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (GradientProfileMemoryTop < 8)
    {
        ptr = &GradientProfileMemory[GradientProfileMemoryTop];
        GradientProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    GradientProfile_Init(ptr);
    return ptr;
}

return_type: struct GradientProfile { 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_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; unsigned long N_ITER_1; struct GradientProfile_1 { unsigned long D_GRADIENT; unsigned long Q_GDIR; unsigned long G_A; } sub_1[31]; } *


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

*(_QWORD *)a1 = GradientProfileMemoryFreeList;
result = 0xFAFAFAFAFAFAFAFBLL;
GradientProfileMemoryFreeList = 0xFAFAFAFAFAFAFAFBLL * ((a1 - (char *)GradientProfileMemory) >> 4);
return result;
}

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

*(_QWORD *)a1 = GradientProfileMemoryFreeList;
result = 0xFAFAFAFAFAFAFAFBLL;
GradientProfileMemoryFreeList = 0xFAFAFAFAFAFAFAFBLL * ((a1 - (char *)GradientProfileMemory) >> 4);
return result;
}

original_code:
void GradientProfile_Delete(GradientProfile* ptr)
{
    ptr->header.NID_PACKET = GradientProfileMemoryFreeList;
    GradientProfileMemoryFreeList = ptr - GradientProfileMemory;
}

canonical_original_code:
void GradientProfile_Delete(struct GradientProfile *ptr)
{
    ptr->header.NID_PACKET = GradientProfileMemoryFreeList;
    GradientProfileMemoryFreeList = ptr - GradientProfileMemory;
}


decompiled_code:
_BOOL8 __fastcall AxleLoadSpeedProfile_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v2; // eax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // rbp
unsigned __int64 v5; // rdx
unsigned __int64 v7; // rbp
_BOOL4 v8; // eax
unsigned __int64 v9; // rdi
int v10; // eax
_BOOL4 v11; // eax
unsigned __int64 v12; // rcx
int v13; // eax

v2 = UpperBitsNotSet64(a1[2], 2);
v3 = a1[9];
if ( !v2
|| !UpperBitsNotSet64(a1[3], 13)
|| !UpperBitsNotSet64(a1[4], 2)
|| !UpperBitsNotSet64(a1[5], 1)
|| !UpperBitsNotSet64(a1[6], 15)
|| !UpperBitsNotSet64(a1[7], 15)
|| !UpperBitsNotSet64(a1[8], 1) )
{
LODWORD(v4) = 0;
if ( !v3 )
goto LABEL_6;
goto LABEL_4;
}
v8 = UpperBitsNotSet64(v3, 5);
if ( v3 )
{
LODWORD(v4) = 0;
if ( v8 )
{
v9 = 0LL;
while ( 1 )
{
v10 = AxleLoadSpeedProfile_1_UpperBitsNotSet(&a1[2 * v9 + 10]);
v9 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v10 )
break;
if ( a1[9] <= v9 )
goto LABEL_25;
}
v3 = a1[9];
if ( v3 <= v9 )
{
v5 = a1[72];
if ( v5 )
goto LABEL_8;
return 0LL;
}
}
do
{
LABEL_4:
if ( (unsigned int)(v4 + 1) >= v3 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v3 );
LABEL_6:
v5 = a1[72];
if ( v5 )
{
LABEL_8:
LODWORD(v7) = 0;
do
{
LABEL_9:
if ( (unsigned int)(v7 + 1) >= v5 )
break;
v7 = (unsigned int)(v7 + 2);
}
while ( v7 < v5 );
}
return 0LL;
}
if ( !v8 )
goto LABEL_6;
LABEL_25:
v11 = UpperBitsNotSet64(a1[72], 5);
if ( v5 )
{
LODWORD(v7) = 0;
if ( v11 )
{
v12 = 0LL;
while ( 1 )
{
v13 = AxleLoadSpeedProfile_2_UpperBitsNotSet(&a1[66 * v12 + 73]);
v12 = (unsigned int)(v7 + 1);
LODWORD(v7) = v7 + 1;
if ( !v13 )
break;
if ( a1[72] <= v12 )
return 1LL;
}
v5 = a1[72];
if ( v5 > v12 )
goto LABEL_9;
return 0LL;
}
goto LABEL_9;
}
return v11;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned __int64 *a1)
{
_BOOL4 v2; // eax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // rbp
unsigned __int64 v5; // rdx
unsigned __int64 v7; // rbp
_BOOL4 v8; // eax
unsigned __int64 v9; // rdi
int v10; // eax
_BOOL4 v11; // eax
unsigned __int64 v12; // rcx
int v13; // eax

v2 = func0(a1[2], 2);
v3 = a1[9];
if ( !v2
|| !func0(a1[3], 13)
|| !func0(a1[4], 2)
|| !func0(a1[5], 1)
|| !func0(a1[6], 15)
|| !func0(a1[7], 15)
|| !func0(a1[8], 1) )
{
LODWORD(v4) = 0;
if ( !v3 )
goto LABEL_6;
goto LABEL_4;
}
v8 = func0(v3, 5);
if ( v3 )
{
LODWORD(v4) = 0;
if ( v8 )
{
v9 = 0LL;
while ( 1 )
{
v10 = AxleLoadSpeedProfile_1_UpperBitsNotSet(&a1[2 * v9 + 10]);
v9 = (unsigned int)(v4 + 1);
LODWORD(v4) = v4 + 1;
if ( !v10 )
break;
if ( a1[9] <= v9 )
goto LABEL_25;
}
v3 = a1[9];
if ( v3 <= v9 )
{
v5 = a1[72];
if ( v5 )
goto LABEL_8;
return 0LL;
}
}
do
{
LABEL_4:
if ( (unsigned int)(v4 + 1) >= v3 )
break;
v4 = (unsigned int)(v4 + 2);
}
while ( v4 < v3 );
LABEL_6:
v5 = a1[72];
if ( v5 )
{
LABEL_8:
LODWORD(v7) = 0;
do
{
LABEL_9:
if ( (unsigned int)(v7 + 1) >= v5 )
break;
v7 = (unsigned int)(v7 + 2);
}
while ( v7 < v5 );
}
return 0LL;
}
if ( !v8 )
goto LABEL_6;
LABEL_25:
v11 = func0(a1[72], 5);
if ( v5 )
{
LODWORD(v7) = 0;
if ( v11 )
{
v12 = 0LL;
while ( 1 )
{
v13 = AxleLoadSpeedProfile_2_UpperBitsNotSet(&a1[66 * v12 + 73]);
v12 = (unsigned int)(v7 + 1);
LODWORD(v7) = v7 + 1;
if ( !v13 )
break;
if ( a1[72] <= v12 )
return 1LL;
}
v5 = a1[72];
if ( v5 > v12 )
goto LABEL_9;
return 0LL;
}
goto LABEL_9;
}
return v11;
}

original_code:
int AxleLoadSpeedProfile_UpperBitsNotSet(const AxleLoadSpeedProfile* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->Q_TRACKINIT, 1) ;
    status = status && UpperBitsNotSet64(p->D_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->L_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && AxleLoadSpeedProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->N_ITER_2, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        status = status && AxleLoadSpeedProfile_2_UpperBitsNotSet(&(p->sub_2[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_UpperBitsNotSet(struct AxleLoadSpeedProfile *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->Q_TRACKINIT, 1) ;
    status = status && UpperBitsNotSet64(p->D_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->L_AXLELOAD, 15);
    status = status && UpperBitsNotSet64(p->Q_FRONT, 1) ;
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && AxleLoadSpeedProfile_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    status = status && UpperBitsNotSet64(p->N_ITER_2, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        status = status && AxleLoadSpeedProfile_2_UpperBitsNotSet(&(p->sub_2[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct AxleLoadSpeedProfile { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_1; struct AxleLoadSpeedProfile_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_1[31]; unsigned long N_ITER_2; struct AxleLoadSpeedProfile_2 { unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct AxleLoadSpeedProfile_2_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_2_1[31]; } sub_2[31]; } *

user_defined_types: struct AxleLoadSpeedProfile { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_1; struct AxleLoadSpeedProfile_1 sub_1[31]; unsigned long N_ITER_2; struct AxleLoadSpeedProfile_2 sub_2[31]; }

user_defined_types: struct AxleLoadSpeedProfile_2 { unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct AxleLoadSpeedProfile_2_1 sub_2_1[31]; }


decompiled_code:
__int64 __fastcall AxleLoadSpeedProfile_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rdi
unsigned int v5; // er12
__int64 v6; // rdx

if ( !(unsigned int)Bitstream_Normal(a2, 59LL) )
return 0xFFFFFFFFLL;
if ( !AxleLoadSpeedProfile_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 1LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
Bitstream_Write(a2, 5LL, a1[9]);
if ( a1[9] )
{
v3 = 0;
v4 = 0LL;
do
{
AxleLoadSpeedProfile_1_EncodeBit(&a1[2 * v4 + 10], a2);
v4 = ++v3;
}
while ( v3 < a1[9] );
}
v5 = 0;
Bitstream_Write(a2, 5LL, a1[72]);
v6 = 0LL;
if ( a1[72] )
{
do
{
AxleLoadSpeedProfile_2_EncodeBit(&a1[66 * v6 + 73], a2);
v6 = ++v5;
}
while ( v5 < a1[72] );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 *a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rdi
unsigned int v5; // er12
__int64 v6; // rdx

if ( !(unsigned int)Bitstream_Normal(a2, 59LL) )
return 0xFFFFFFFFLL;
if ( !func5(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 1LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
Bitstream_Write(a2, 5LL, a1[9]);
if ( a1[9] )
{
v3 = 0;
v4 = 0LL;
do
{
AxleLoadSpeedProfile_1_EncodeBit(&a1[2 * v4 + 10], a2);
v4 = ++v3;
}
while ( v3 < a1[9] );
}
v5 = 0;
Bitstream_Write(a2, 5LL, a1[72]);
v6 = 0LL;
if ( a1[72] )
{
do
{
AxleLoadSpeedProfile_2_EncodeBit(&a1[66 * v6 + 73], a2);
v6 = ++v5;
}
while ( v5 < a1[72] );
}
return 1LL;
}

original_code:
int AxleLoadSpeedProfile_EncodeBit(const AxleLoadSpeedProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 59))
    {
        if (AxleLoadSpeedProfile_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_TRACKINIT);
            Bitstream_Write(stream, 15, p->D_AXLELOAD);
            Bitstream_Write(stream, 15, p->L_AXLELOAD);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                AxleLoadSpeedProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 5, p->N_ITER_2);
            for (uint32_t i = 0; i < p->N_ITER_2; ++i)
            {
                AxleLoadSpeedProfile_2_EncodeBit(&(p->sub_2[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_EncodeBit(struct AxleLoadSpeedProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 59))
    {
        if (AxleLoadSpeedProfile_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_TRACKINIT);
            Bitstream_Write(stream, 15, p->D_AXLELOAD);
            Bitstream_Write(stream, 15, p->L_AXLELOAD);
            Bitstream_Write(stream, 1, p->Q_FRONT);
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                AxleLoadSpeedProfile_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            Bitstream_Write(stream, 5, p->N_ITER_2);
            for (unsigned int i = 0; i < p->N_ITER_2; ++i)
            {
                AxleLoadSpeedProfile_2_EncodeBit(&(p->sub_2[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

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

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


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

result = Bitstream_Normal(a2, 59LL);
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, 1LL);
a1[6] = Bitstream_Read(a2, 15LL);
a1[7] = Bitstream_Read(a2, 15LL);
a1[8] = Bitstream_Read(a2, 1LL);
v4 = Bitstream_Read(a2, 5LL);
a1[9] = v4;
if ( v4 )
{
v5 = 0;
v6 = 0LL;
do
{
AxleLoadSpeedProfile_1_DecodeBit(&a1[2 * v6 + 10], a2);
v6 = ++v5;
}
while ( (unsigned __int64)v5 < a1[9] );
}
v7 = 0;
v8 = Bitstream_Read(a2, 5LL);
v9 = 0LL;
a1[72] = v8;
if ( v8 )
{
do
{
AxleLoadSpeedProfile_2_DecodeBit(&a1[66 * v9 + 73], a2);
v9 = ++v7;
}
while ( (unsigned __int64)v7 < a1[72] );
}
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 59LL);
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, 1LL);
a1[6] = Bitstream_Read(a2, 15LL);
a1[7] = Bitstream_Read(a2, 15LL);
a1[8] = Bitstream_Read(a2, 1LL);
v4 = Bitstream_Read(a2, 5LL);
a1[9] = v4;
if ( v4 )
{
v5 = 0;
v6 = 0LL;
do
{
AxleLoadSpeedProfile_1_DecodeBit(&a1[2 * v6 + 10], a2);
v6 = ++v5;
}
while ( (unsigned __int64)v5 < a1[9] );
}
v7 = 0;
v8 = Bitstream_Read(a2, 5LL);
v9 = 0LL;
a1[72] = v8;
if ( v8 )
{
do
{
AxleLoadSpeedProfile_2_DecodeBit(&a1[66 * v9 + 73], a2);
v9 = ++v7;
}
while ( (unsigned __int64)v7 < a1[72] );
}
result = 1LL;
}
return result;
}

original_code:
int AxleLoadSpeedProfile_DecodeBit(AxleLoadSpeedProfile* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 59))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TRACKINIT = Bitstream_Read(stream, 1);
        }
        {
            p->D_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->L_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            AxleLoadSpeedProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
    {
            p->N_ITER_2 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_2; ++i)
        {
            AxleLoadSpeedProfile_2_DecodeBit(&(p->sub_2[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int AxleLoadSpeedProfile_DecodeBit(struct AxleLoadSpeedProfile *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 59))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TRACKINIT = Bitstream_Read(stream, 1);
        }
        {
            p->D_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->L_AXLELOAD = Bitstream_Read(stream, 15);
        }
        {
            p->Q_FRONT = Bitstream_Read(stream, 1);
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            AxleLoadSpeedProfile_1_DecodeBit(&(p->sub_1[i]), stream);
        }
    {
            p->N_ITER_2 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_2; ++i)
        {
            AxleLoadSpeedProfile_2_DecodeBit(&(p->sub_2[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int AxleLoadSpeedProfile_EncodeInt(const AxleLoadSpeedProfile* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 51;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->Q_TRACKINIT;
    stream[startAddress++] = p->D_AXLELOAD;
    stream[startAddress++] = p->L_AXLELOAD;
    stream[startAddress++] = p->Q_FRONT;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        AxleLoadSpeedProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    stream[startAddress++] = p->N_ITER_2;
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        AxleLoadSpeedProfile_2_EncodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int AxleLoadSpeedProfile_EncodeInt(struct AxleLoadSpeedProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 51;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->Q_TRACKINIT;
    stream[startAddress++] = p->D_AXLELOAD;
    stream[startAddress++] = p->L_AXLELOAD;
    stream[startAddress++] = p->Q_FRONT;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        AxleLoadSpeedProfile_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    stream[startAddress++] = p->N_ITER_2;
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        AxleLoadSpeedProfile_2_EncodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int AxleLoadSpeedProfile_DecodeInt(AxleLoadSpeedProfile* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 51)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->Q_TRACKINIT = stream[startAddress++];
    p->D_AXLELOAD = stream[startAddress++];
    p->L_AXLELOAD = stream[startAddress++];
    p->Q_FRONT = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        AxleLoadSpeedProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    p->N_ITER_2 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_2; ++i)
    {
        AxleLoadSpeedProfile_2_DecodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int AxleLoadSpeedProfile_DecodeInt(struct AxleLoadSpeedProfile *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 51)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->Q_TRACKINIT = stream[startAddress++];
    p->D_AXLELOAD = stream[startAddress++];
    p->L_AXLELOAD = stream[startAddress++];
    p->Q_FRONT = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        AxleLoadSpeedProfile_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    p->N_ITER_2 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_2; ++i)
    {
        AxleLoadSpeedProfile_2_DecodeInt(&(p->sub_2[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}


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

if ( AxleLoadSpeedProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)AxleLoadSpeedProfileMemoryTop > 7 )
return 0LL;
v3 = 2119 * AxleLoadSpeedProfileMemoryTop++;
v0 = &AxleLoadSpeedProfileMemory[v3];
}
else
{
v0 = &AxleLoadSpeedProfileMemory[2119 * AxleLoadSpeedProfileMemoryFreeList];
AxleLoadSpeedProfileMemoryFreeList = *v0;
}
AxleLoadSpeedProfile_Init(v0);
return v1;
}

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

if ( AxleLoadSpeedProfileMemoryFreeList == -1 )
{
if ( (unsigned __int64)AxleLoadSpeedProfileMemoryTop > 7 )
return 0LL;
v3 = 2119 * AxleLoadSpeedProfileMemoryTop++;
v0 = &AxleLoadSpeedProfileMemory[v3];
}
else
{
v0 = &AxleLoadSpeedProfileMemory[2119 * AxleLoadSpeedProfileMemoryFreeList];
AxleLoadSpeedProfileMemoryFreeList = *v0;
}
func4(v0);
return v1;
}

original_code:
AxleLoadSpeedProfile* AxleLoadSpeedProfile_New(void)
{
    AxleLoadSpeedProfile* ptr;
    if (AxleLoadSpeedProfileMemoryFreeList != (-1))
    {
        ptr = &AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryFreeList];
        AxleLoadSpeedProfileMemoryFreeList = AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (AxleLoadSpeedProfileMemoryTop < 8)
    {
        ptr = &AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryTop];
        AxleLoadSpeedProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    AxleLoadSpeedProfile_Init(ptr);
    return ptr;
}

canonical_original_code:
struct AxleLoadSpeedProfile *AxleLoadSpeedProfile_New()
{
    struct AxleLoadSpeedProfile *ptr;
    if (AxleLoadSpeedProfileMemoryFreeList != (-1))
    {
        ptr = &AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryFreeList];
        AxleLoadSpeedProfileMemoryFreeList = AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryFreeList].header.NID_PACKET;
    }
    else if (AxleLoadSpeedProfileMemoryTop < 8)
    {
        ptr = &AxleLoadSpeedProfileMemory[AxleLoadSpeedProfileMemoryTop];
        AxleLoadSpeedProfileMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    AxleLoadSpeedProfile_Init(ptr);
    return ptr;
}

return_type: struct AxleLoadSpeedProfile { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_1; struct AxleLoadSpeedProfile_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_1[31]; unsigned long N_ITER_2; struct AxleLoadSpeedProfile_2 { unsigned long D_AXLELOAD; unsigned long L_AXLELOAD; unsigned long Q_FRONT; unsigned long N_ITER_2_1; struct AxleLoadSpeedProfile_2_1 { unsigned long M_AXLELOAD; unsigned long V_AXLELOAD; } sub_2_1[31]; } sub_2[31]; } *


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

*a1 = AxleLoadSpeedProfileMemoryFreeList;
result = 0x8C432BDACA3D2177LL;
AxleLoadSpeedProfileMemoryFreeList = 0x8C432BDACA3D2177LL * (a1 - AxleLoadSpeedProfileMemory);
return result;
}

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

*a1 = AxleLoadSpeedProfileMemoryFreeList;
result = 0x8C432BDACA3D2177LL;
AxleLoadSpeedProfileMemoryFreeList = 0x8C432BDACA3D2177LL * (a1 - AxleLoadSpeedProfileMemory);
return result;
}

original_code:
void AxleLoadSpeedProfile_Delete(AxleLoadSpeedProfile* ptr)
{
    ptr->header.NID_PACKET = AxleLoadSpeedProfileMemoryFreeList;
    AxleLoadSpeedProfileMemoryFreeList = ptr - AxleLoadSpeedProfileMemory;
}

canonical_original_code:
void AxleLoadSpeedProfile_Delete(struct AxleLoadSpeedProfile *ptr)
{
    ptr->header.NID_PACKET = AxleLoadSpeedProfileMemoryFreeList;
    AxleLoadSpeedProfileMemoryFreeList = ptr - AxleLoadSpeedProfileMemory;
}


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


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

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

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

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

original_code:
int RBCTransitionOrder_UpperBitsNotSet(const RBCTransitionOrder* 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_RBCTR, 15);
    status = status && UpperBitsNotSet64(p->NID_C, 10);
    status = status && UpperBitsNotSet64(p->NID_RBC, 14);
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    status = status && UpperBitsNotSet64(p->Q_SLEEPSESSION, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RBCTransitionOrder_UpperBitsNotSet(struct RBCTransitionOrder *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_RBCTR, 15);
    status = status && UpperBitsNotSet64(p->NID_C, 10);
    status = status && UpperBitsNotSet64(p->NID_RBC, 14);
    status = status && UpperBitsNotSet64(p->NID_RADIO, 64);
    status = status && UpperBitsNotSet64(p->Q_SLEEPSESSION, 1) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct RBCTransitionOrder { 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_RBCTR; unsigned long NID_C; unsigned long NID_RBC; unsigned long NID_RADIO; unsigned long Q_SLEEPSESSION; } *

user_defined_types: struct RBCTransitionOrder { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long D_RBCTR; unsigned long NID_C; unsigned long NID_RBC; unsigned long NID_RADIO; unsigned long Q_SLEEPSESSION; }


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

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

original_code:
int RBCTransitionOrder_EncodeBit(const RBCTransitionOrder* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 121))
    {
        if (RBCTransitionOrder_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_RBCTR);
            Bitstream_Write(stream, 10, p->NID_C);
            Bitstream_Write(stream, 14, p->NID_RBC);
            Bitstream_Write(stream, 64, p->NID_RADIO);
            Bitstream_Write(stream, 1, p->Q_SLEEPSESSION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int RBCTransitionOrder_EncodeBit(struct RBCTransitionOrder *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 121))
    {
        if (RBCTransitionOrder_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_RBCTR);
            Bitstream_Write(stream, 10, p->NID_C);
            Bitstream_Write(stream, 14, p->NID_RBC);
            Bitstream_Write(stream, 64, p->NID_RADIO);
            Bitstream_Write(stream, 1, p->Q_SLEEPSESSION);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


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

result = Bitstream_Normal(a2, 121LL);
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, 10LL);
a1[7] = Bitstream_Read(a2, 14LL);
a1[8] = Bitstream_Read(a2, 64LL);
a1[9] = Bitstream_Read(a2, 1LL);
result = 1LL;
}
return result;
}

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

result = Bitstream_Normal(a2, 121LL);
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, 10LL);
a1[7] = Bitstream_Read(a2, 14LL);
a1[8] = Bitstream_Read(a2, 64LL);
a1[9] = Bitstream_Read(a2, 1LL);
result = 1LL;
}
return result;
}

original_code:
int RBCTransitionOrder_DecodeBit(RBCTransitionOrder* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 121))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_RBCTR = Bitstream_Read(stream, 15);
        }
        {
            p->NID_C = Bitstream_Read(stream, 10);
        }
        {
            p->NID_RBC = Bitstream_Read(stream, 14);
        }
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        {
            p->Q_SLEEPSESSION = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RBCTransitionOrder_DecodeBit(struct RBCTransitionOrder *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 121))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->D_RBCTR = Bitstream_Read(stream, 15);
        }
        {
            p->NID_C = Bitstream_Read(stream, 10);
        }
        {
            p->NID_RBC = Bitstream_Read(stream, 14);
        }
        {
            p->NID_RADIO = Bitstream_Read(stream, 64);
        }
        {
            p->Q_SLEEPSESSION = Bitstream_Read(stream, 1);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}


original_code:
int RBCTransitionOrder_EncodeInt(const RBCTransitionOrder* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 131;
    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_RBCTR;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_RBC;
    stream[startAddress++] = p->NID_RADIO;
    stream[startAddress++] = p->Q_SLEEPSESSION;
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int RBCTransitionOrder_EncodeInt(struct RBCTransitionOrder *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 131;
    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_RBCTR;
    stream[startAddress++] = p->NID_C;
    stream[startAddress++] = p->NID_RBC;
    stream[startAddress++] = p->NID_RADIO;
    stream[startAddress++] = p->Q_SLEEPSESSION;
    data->endAddress = startAddress-1;
    return 1;
}


original_code:
int RBCTransitionOrder_DecodeInt(RBCTransitionOrder* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 131)
    {
         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_RBCTR = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_RBC = stream[startAddress++];
    p->NID_RADIO = stream[startAddress++];
    p->Q_SLEEPSESSION = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int RBCTransitionOrder_DecodeInt(struct RBCTransitionOrder *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 131)
    {
         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_RBCTR = stream[startAddress++];
    p->NID_C = stream[startAddress++];
    p->NID_RBC = stream[startAddress++];
    p->NID_RADIO = stream[startAddress++];
    p->Q_SLEEPSESSION = stream[startAddress++];
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}