decompiled_code:
int __fastcall parse_descriptors(int a1, __int64 a2, __int64 a3, _QWORD *a4)
{
int v4; // er14
int result; // eax
_BYTE *v6; // rbp
int v7; // ebx
__int64 v8; // r13
int v9; // er15
int v10; // edx
unsigned __int8 v11; // di
unsigned __int8 v12; // di
unsigned __int8 v13; // di
unsigned int v14; // er15
unsigned __int8 *v15; // rbp
int v16; // er13
int v17; // er13
__int64 v18; // rbp
_BYTE *v19; // rdx
int v20; // eax
unsigned __int8 v21; // bp
__int64 v22; // r14
char *v23; // rbx
int *v24; // rax
unsigned __int8 v25; // al
char *v26; // r13
char *v27; // r15
int *v28; // rax
unsigned __int8 *v29; // r14
unsigned __int8 *v30; // rbp
char *v31; // rbp
int i; // er13
int *v33; // rax
int *v34; // rax
int *v35; // rax
__int64 v36; // rdx
int v37; // eax
__int64 v38; // rbp
unsigned int v39; // ebx
__int64 v40; // r13
int *v41; // rax
int *v42; // rax
int *v43; // rax
unsigned __int8 *v44; // rbp
__int64 v45; // r13
const unsigned __int16 **v46; // r13
unsigned __int8 *v47; // rbp
__int64 v48; // r15
unsigned __int8 v49; // di
unsigned __int8 *v50; // rbp
__int64 v51; // r13
unsigned __int8 *v52; // r14
const unsigned __int16 **v53; // r14
unsigned __int8 v54; // di
int v55; // [rsp+4h] [rbp-E4h]
int v57; // [rsp+Ch] [rbp-DCh]
unsigned int v58; // [rsp+Ch] [rbp-DCh]
int v59; // [rsp+Ch] [rbp-DCh]
__int64 v60; // [rsp+10h] [rbp-D8h]
int v62; // [rsp+20h] [rbp-C8h]
unsigned __int8 v63; // [rsp+24h] [rbp-C4h]
int v64; // [rsp+24h] [rbp-C4h]
char s[184]; // [rsp+30h] [rbp-B8h] BYREF

v4 = 0;
result = a2 + 2;
v60 = a2 + 2;
LABEL_53:
while ( a1 > v4 )
{
while ( 1 )
{
v21 = *(_BYTE *)(a2 + v4);
result = v4 + 2;
v55 = v4 + 2;
v22 = v4 + 1;
v7 = *(unsigned __int8 *)(a2 + v22);
if ( *(_BYTE *)(a2 + v22) )
break;
v4 = v55;
LABEL_119:
if ( a1 <= v4 )
return result;
}
while ( 2 )
{
if ( v21 > 0x73u )
{
if ( v21 != 0xC5 )
goto LABEL_110;
printf("<canal_radio tag=\"0x%02x\" id=\"%d\" name=\"", 197LL, *(unsigned __int8 *)(a2 + v55));
if ( v7 > 1 )
{
v6 = (_BYTE *)(a2 + v55 + 1);
do
{
if ( *v6 )
putchar((unsigned __int8)*v6);
++v6;
}
while ( v6 != (_BYTE *)((unsigned int)(v7 - 2) + v60 + v55) );
}
LABEL_117:
result = puts("\" />");
v4 = v7 + v55;
}
else
{
if ( v21 <= 2u )
{
LABEL_110:
printf("<descriptor tag=\"0x%02x\" data=\"", v21);
if ( v7 <= 0 )
{
printf("\" text=\"");
}
else
{
v50 = (unsigned __int8 *)(a2 + v55);
v51 = (__int64)&v50[v7 - 1 + 1];
v52 = v50;
do
printf("%02x", *v52++);
while ( (unsigned __int8 *)v51 != v52 );
printf("\" text=\"");
v53 = _ctype_b_loc();
do
{
v54 = *v50;
if ( ((*v53)[*v50] & 8) == 0 )
v54 = 46;
putchar(v54);
++v50;
}
while ( (unsigned __int8 *)v51 != v50 );
}
goto LABEL_117;
}
result = (unsigned __int8)(v21 - 3);
switch ( v21 )
{
case 3u:
result = printf("<audio_info tag=\"0x03\" info=\"%02x\" />\n", *(unsigned __int8 *)(a2 + v55));
v4 = v55 + v7;
goto LABEL_53;
case 6u:
result = printf("<data_stream_alignment tag=\"0x06\" data=\"%02x\" />\n", *(unsigned __int8 *)(a2 + v55));
v4 = v55 + v7;
goto LABEL_53;
case 9u:
result = *(unsigned __int8 *)(a2 + v55) << 8;
v14 = result | *(unsigned __int8 *)(a2 + v55 + 1);
if ( result == 2304 )
{
result = printf(
"<ca_system_descriptor type=\"videoguard\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",
v14,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u);
goto LABEL_32;
}
if ( result > 2304 )
{
switch ( result )
{
case 5888:
goto LABEL_31;
case 6144:
result = printf(
"<ca_system_descriptor type=\"nagra\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",
v14,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u);
goto LABEL_32;
case 2816:
result = printf(
"<ca_system_descriptor type=\"conax\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",
v14,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u);
goto LABEL_32;
}
LABEL_46:
result = printf("<ca_system_descriptor type=\"unknown\" system_id=\"0x%04x\" />\n", v14);
goto LABEL_32;
}
switch ( result )
{
case 1280:
v17 = 4;
if ( v7 > 4 )
{
v58 = result | *(unsigned __int8 *)(a2 + v55 + 1);
do
{
v18 = v55 + v17;
if ( *(_BYTE *)(a2 + v18) == 20 )
printf(
"<ca_system_descriptor type=\"viaccess\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",
v58,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u,
*(_BYTE *)(a2 + v18 + 4) & 0xF0 | (*(unsigned __int8 *)(a2 + v18 + 3) << 8) | (*(unsigned __int8 *)(a2 + v18 + 2) << 16));
result = *(unsigned __int8 *)(a2 + v18 + 1);
v17 += result + 2;
}
while ( v17 < v7 );
}
break;
case 1536:
LABEL_31:
result = printf(
"<ca_system_descriptor type=\"irdeto\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",
v14,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u);
break;
case 256:
if ( v7 > 2 )
{
v15 = (unsigned __int8 *)(a2 + v55);
v16 = 2 - (a2 + v55);
do
{
printf(
"<ca_system_descriptor type=\"seca\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",
v14,
v15[3] | (v15[2] << 8) & 0x1F00u,
v15[5] | (v15[4] << 8));
v15 += 15;
result = v16 + (_DWORD)v15;
}
while ( v7 > v16 + (int)v15 );
}
break;
default:
goto LABEL_46;
}
LABEL_32:
v4 = v7 + v55;
break;
case 0xAu:
v8 = v55 + 4;
v9 = 0;
result = v7 + v55;
v57 = v7 + v55;
if ( v7 > 3 )
{
do
{
printf("<iso_639 language=\"");
v11 = *(_BYTE *)(a2 + v8 - 4);
if ( v11 )
putchar(v11);
v12 = *(_BYTE *)(a2 + v8 - 3);
if ( v12 )
putchar(v12);
v13 = *(_BYTE *)(a2 + v8 - 2);
if ( v13 )
putchar(v13);
printf("\" type=\"%d\" />\n", *(unsigned __int8 *)(a2 + v8 - 1));
v10 = v8;
v7 = v57 - v8;
++v9;
v8 += 4LL;
result = v7 / 4;
}
while ( v7 / 4 > v9 );
v55 = v10;
}
goto LABEL_69;
case 0xBu:
result = printf(
"<system_clock tag=\"0x0b\" data=\"%02x%02x\" />\n",
*(unsigned __int8 *)(a2 + v55),
*(unsigned __int8 *)(a2 + v55 + 1));
v4 = v55 + v7;
goto LABEL_53;
case 0x40u:
if ( v7 > 0 )
{
do
--v7;
while ( v7 );
}
goto LABEL_10;
case 0x41u:
result = v55;
if ( v7 > 0 )
{
do
result += 3;
while ( v7 + v55 - result > 0 );
v55 = result;
}
LABEL_10:
v4 = v55;
goto LABEL_119;
case 0x43u:
sprintf(s, "%x", _byteswap_ulong(*(_DWORD *)(a2 + v55)));
*(_DWORD *)(a3 + 8) = 10 * atoi(s);
*(_DWORD *)(a3 + 16) = *(unsigned __int8 *)(a2 + v55 + 4 + 1) | (*(unsigned __int8 *)(a2 + v55 + 4) << 8);
v19 = (_BYTE *)(a2 + v55 + 6);
*(_DWORD *)(a3 + 20) = *v19 >> 7;
v20 = ((int)(unsigned __int8)*v19 >> 5) & 3;
if ( v20 == 2 )
{
*(_BYTE *)(a3 + 24) = 76;
}
else if ( (((int)(unsigned __int8)*v19 >> 5) & 3) == 3 )
{
*(_BYTE *)(a3 + 24) = 82;
}
else if ( v20 )
{
*(_BYTE *)(a3 + 24) = 86;
}
else
{
*(_BYTE *)(a3 + 24) = 72;
}
*(_DWORD *)(a3 + 28) = *v19 & 0x1F;
sprintf(
s,
"%x",
((*(unsigned __int8 *)(a2 + v55 + 7 + 2) << 8) | (*(unsigned __int8 *)(a2 + v55 + 7 + 1) << 16) | (*(unsigned __int8 *)(a2 + v55 + 7) << 24) | *(_BYTE *)(a2 + v55 + 7 + 3) & 0xF0u) >> 4);
*(_DWORD *)(a3 + 12) = 100 * atoi(s);
v4 = v55 + 11;
result = (unsigned int)add_transponder(a3, a4);
goto LABEL_53;
case 0x48u:
printf("<description tag=\"0x48\" type=\"%d\"", *(unsigned __int8 *)(a2 + v55));
v59 = v55 + 2;
v63 = *(_BYTE *)(a2 + v55 + 1);
v62 = v7 - v63 - 2;
printf(" provider_name=\"");
if ( v63 )
{
v23 = (char *)(a2 + v59);
do
{
v24 = xmlify(*v23);
printf("%s", (const char *)v24);
++v23;
}
while ( v23 != (char *)((unsigned int)v63 - 1 + a2 + v55 + 3) );
v59 = v55 + v63 + 2;
}
printf("\" service_name=\"");
v55 = v59 + 1;
v25 = *(_BYTE *)(a2 + v59);
v64 = v25;
v7 = v62 - (v25 + 1);
if ( v25 )
{
v26 = (char *)(a2 + v59 + 1);
v27 = (char *)((unsigned int)v25 - 1 + v60 + v59);
do
{
v28 = xmlify(*v26);
printf("%s", (const char *)v28);
++v26;
}
while ( v26 != v27 );
v55 = v59 + v64 + 1;
}
result = puts("\" />");
LABEL_69:
if ( v7 > 0 )
continue;
v4 = v55;
goto LABEL_119;
case 0x49u:
printf("<country_availability tag=\"0x49\" type=\"%d\" countries=\" ", *(_BYTE *)(a2 + v55) >> 7);
v4 = v55 + 1;
if ( v7 > 1 )
{
v29 = (unsigned __int8 *)(a2 + v4);
do
putchar(*v29++);
while ( v29 != (unsigned __int8 *)((unsigned int)(v7 - 2) + v60 + v55) );
v4 = v55 + v7;
}
result = puts("\" />");
goto LABEL_53;
case 0x4Cu:
result = printf(
"<time_shifted_copy_of tag=\"0x4c\" service_id=\"%d\" />\n",
*(unsigned __int8 *)(a2 + v55 + 1) | (*(unsigned __int8 *)(a2 + v55) << 8));
v4 = v55 + v7;
goto LABEL_53;
case 0x52u:
result = printf("<stream_id id=\"%d\" />\n", *(unsigned __int8 *)(a2 + v55));
v4 = v55 + v7;
goto LABEL_53;
case 0x53u:
printf("<ca_identifier tag=\"0x53\" length=\"%02x\">\n", (unsigned int)v7);
if ( v7 > 0 )
{
v30 = (unsigned __int8 *)(a2 + v55);
do
{
printf("<ca_system_id>%04x</ca_system_id>\n", v30[1] | (*v30 << 8));
v30 += 2;
}
while ( v30 != (unsigned __int8 *)(v60 + v55 + 2LL * ((unsigned int)(v7 - 1) >> 1)) );
}
v4 = v7 + v55;
result = puts("</ca_identifier>");
goto LABEL_53;
case 0x56u:
puts("<teletext tag=\"0x56\">");
if ( v7 <= 0 )
{
v4 = v55;
}
else
{
v31 = (char *)(a2 + v55);
for ( i = 0; i < v7; i += 5 )
{
printf("<teletext_info lang=\"");
v33 = xmlify(*v31);
printf("%s", (const char *)v33);
v34 = xmlify(v31[1]);
printf("%s", (const char *)v34);
v35 = xmlify(v31[2]);
printf("%s", (const char *)v35);
v36 = v31[3] & 7;
if ( (v31[3] & 7) == 0 )
v36 = 8LL;
printf(
"\" type=\"%d\" page=\"%d%02x\" />\n",
(unsigned __int8)v31[3] >> 3,
v36,
(unsigned __int8)v31[4]);
v37 = v55 + i + 5;
v31 += 5;
}
v4 = v37;
}
result = puts("</teletext>");
goto LABEL_53;
case 0x59u:
puts("<subtitling_descriptor tag=\"0x59\">");
if ( v7 <= 0 )
{
v4 = v55;
}
else
{
v38 = a2 + v55;
v39 = (unsigned int)(v7 - 1) >> 3;
v40 = v38 + 8 + 8LL * v39;
do
{
printf("<subtitle_stream lang=\"");
v41 = xmlify(*(_BYTE *)v38);
printf("%s", (const char *)v41);
v42 = xmlify(*(_BYTE *)(v38 + 1));
printf("%s", (const char *)v42);
v43 = xmlify(*(_BYTE *)(v38 + 2));
printf("%s", (const char *)v43);
printf(
"\" type=\"%d\" composition_page_id=\"%04x\" ancillary_page_id=\"%04x\" />\n",
*(unsigned __int8 *)(v38 + 3),
*(unsigned __int8 *)(v38 + 5) | (*(unsigned __int8 *)(v38 + 4) << 8),
*(unsigned __int8 *)(v38 + 7) | (*(unsigned __int8 *)(v38 + 6) << 8));
v38 += 8LL;
}
while ( v38 != v40 );
v4 = v55 + 8 * v39 + 8;
}
result = puts("</subtitling_descriptor>");
goto LABEL_53;
case 0x6Au:
printf("<ac3_descriptor tag=\"0x6a\" data=\"");
if ( v7 > 0 )
{
v44 = (unsigned __int8 *)(a2 + v55);
v45 = (__int64)&v44[v7 - 1 + 1];
do
printf("%02x", *v44++);
while ( v44 != (unsigned __int8 *)v45 );
}
goto LABEL_117;
case 0x73u:
printf("<default_authority_descriptor tag=\"0x%02x\" name=\"", 115LL);
if ( v7 > 0 )
{
v46 = _ctype_b_loc();
v47 = (unsigned __int8 *)(a2 + v55);
v48 = (__int64)&v47[v7 - 1 + 1];
do
{
v49 = *v47;
if ( ((*v46)[*v47] & 8) == 0 )
v49 = 46;
putchar(v49);
++v47;
}
while ( v47 != (unsigned __int8 *)v48 );
}
goto LABEL_117;
default:
goto LABEL_110;
}
}
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, __int64 a2, __int64 a3, _QWORD *a4)
{
int v4; // er14
int result; // eax
_BYTE *v6; // rbp
int v7; // ebx
__int64 v8; // r13
int v9; // er15
int v10; // edx
unsigned __int8 v11; // di
unsigned __int8 v12; // di
unsigned __int8 v13; // di
unsigned int v14; // er15
unsigned __int8 *v15; // rbp
int v16; // er13
int v17; // er13
__int64 v18; // rbp
_BYTE *v19; // rdx
int v20; // eax
unsigned __int8 v21; // bp
__int64 v22; // r14
char *v23; // rbx
int *v24; // rax
unsigned __int8 v25; // al
char *v26; // r13
char *v27; // r15
int *v28; // rax
unsigned __int8 *v29; // r14
unsigned __int8 *v30; // rbp
char *v31; // rbp
int i; // er13
int *v33; // rax
int *v34; // rax
int *v35; // rax
__int64 v36; // rdx
int v37; // eax
__int64 v38; // rbp
unsigned int v39; // ebx
__int64 v40; // r13
int *v41; // rax
int *v42; // rax
int *v43; // rax
unsigned __int8 *v44; // rbp
__int64 v45; // r13
const unsigned __int16 **v46; // r13
unsigned __int8 *v47; // rbp
__int64 v48; // r15
unsigned __int8 v49; // di
unsigned __int8 *v50; // rbp
__int64 v51; // r13
unsigned __int8 *v52; // r14
const unsigned __int16 **v53; // r14
unsigned __int8 v54; // di
int v55; // [rsp+4h] [rbp-E4h]
int v57; // [rsp+Ch] [rbp-DCh]
unsigned int v58; // [rsp+Ch] [rbp-DCh]
int v59; // [rsp+Ch] [rbp-DCh]
__int64 v60; // [rsp+10h] [rbp-D8h]
int v62; // [rsp+20h] [rbp-C8h]
unsigned __int8 v63; // [rsp+24h] [rbp-C4h]
int v64; // [rsp+24h] [rbp-C4h]
char s[184]; // [rsp+30h] [rbp-B8h] BYREF

v4 = 0;
result = a2 + 2;
v60 = a2 + 2;
LABEL_53:
while ( a1 > v4 )
{
while ( 1 )
{
v21 = *(_BYTE *)(a2 + v4);
result = v4 + 2;
v55 = v4 + 2;
v22 = v4 + 1;
v7 = *(unsigned __int8 *)(a2 + v22);
if ( *(_BYTE *)(a2 + v22) )
break;
v4 = v55;
LABEL_119:
if ( a1 <= v4 )
return result;
}
while ( 2 )
{
if ( v21 > 0x73u )
{
if ( v21 != 0xC5 )
goto LABEL_110;
printf("<canal_radio tag=\"0x%02x\" id=\"%d\" name=\"", 197LL, *(unsigned __int8 *)(a2 + v55));
if ( v7 > 1 )
{
v6 = (_BYTE *)(a2 + v55 + 1);
do
{
if ( *v6 )
putchar((unsigned __int8)*v6);
++v6;
}
while ( v6 != (_BYTE *)((unsigned int)(v7 - 2) + v60 + v55) );
}
LABEL_117:
result = puts("\" />");
v4 = v7 + v55;
}
else
{
if ( v21 <= 2u )
{
LABEL_110:
printf("<descriptor tag=\"0x%02x\" data=\"", v21);
if ( v7 <= 0 )
{
printf("\" text=\"");
}
else
{
v50 = (unsigned __int8 *)(a2 + v55);
v51 = (__int64)&v50[v7 - 1 + 1];
v52 = v50;
do
printf("%02x", *v52++);
while ( (unsigned __int8 *)v51 != v52 );
printf("\" text=\"");
v53 = _ctype_b_loc();
do
{
v54 = *v50;
if ( ((*v53)[*v50] & 8) == 0 )
v54 = 46;
putchar(v54);
++v50;
}
while ( (unsigned __int8 *)v51 != v50 );
}
goto LABEL_117;
}
result = (unsigned __int8)(v21 - 3);
switch ( v21 )
{
case 3u:
result = printf("<audio_info tag=\"0x03\" info=\"%02x\" />\n", *(unsigned __int8 *)(a2 + v55));
v4 = v55 + v7;
goto LABEL_53;
case 6u:
result = printf("<data_stream_alignment tag=\"0x06\" data=\"%02x\" />\n", *(unsigned __int8 *)(a2 + v55));
v4 = v55 + v7;
goto LABEL_53;
case 9u:
result = *(unsigned __int8 *)(a2 + v55) << 8;
v14 = result | *(unsigned __int8 *)(a2 + v55 + 1);
if ( result == 2304 )
{
result = printf(
"<ca_system_descriptor type=\"videoguard\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",
v14,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u);
goto LABEL_32;
}
if ( result > 2304 )
{
switch ( result )
{
case 5888:
goto LABEL_31;
case 6144:
result = printf(
"<ca_system_descriptor type=\"nagra\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",
v14,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u);
goto LABEL_32;
case 2816:
result = printf(
"<ca_system_descriptor type=\"conax\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",
v14,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u);
goto LABEL_32;
}
LABEL_46:
result = printf("<ca_system_descriptor type=\"unknown\" system_id=\"0x%04x\" />\n", v14);
goto LABEL_32;
}
switch ( result )
{
case 1280:
v17 = 4;
if ( v7 > 4 )
{
v58 = result | *(unsigned __int8 *)(a2 + v55 + 1);
do
{
v18 = v55 + v17;
if ( *(_BYTE *)(a2 + v18) == 20 )
printf(
"<ca_system_descriptor type=\"viaccess\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",
v58,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u,
*(_BYTE *)(a2 + v18 + 4) & 0xF0 | (*(unsigned __int8 *)(a2 + v18 + 3) << 8) | (*(unsigned __int8 *)(a2 + v18 + 2) << 16));
result = *(unsigned __int8 *)(a2 + v18 + 1);
v17 += result + 2;
}
while ( v17 < v7 );
}
break;
case 1536:
LABEL_31:
result = printf(
"<ca_system_descriptor type=\"irdeto\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",
v14,
*(unsigned __int8 *)(a2 + v55 + 3) | (*(unsigned __int8 *)(a2 + v55 + 2) << 8) & 0x1F00u);
break;
case 256:
if ( v7 > 2 )
{
v15 = (unsigned __int8 *)(a2 + v55);
v16 = 2 - (a2 + v55);
do
{
printf(
"<ca_system_descriptor type=\"seca\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",
v14,
v15[3] | (v15[2] << 8) & 0x1F00u,
v15[5] | (v15[4] << 8));
v15 += 15;
result = v16 + (_DWORD)v15;
}
while ( v7 > v16 + (int)v15 );
}
break;
default:
goto LABEL_46;
}
LABEL_32:
v4 = v7 + v55;
break;
case 0xAu:
v8 = v55 + 4;
v9 = 0;
result = v7 + v55;
v57 = v7 + v55;
if ( v7 > 3 )
{
do
{
printf("<iso_639 language=\"");
v11 = *(_BYTE *)(a2 + v8 - 4);
if ( v11 )
putchar(v11);
v12 = *(_BYTE *)(a2 + v8 - 3);
if ( v12 )
putchar(v12);
v13 = *(_BYTE *)(a2 + v8 - 2);
if ( v13 )
putchar(v13);
printf("\" type=\"%d\" />\n", *(unsigned __int8 *)(a2 + v8 - 1));
v10 = v8;
v7 = v57 - v8;
++v9;
v8 += 4LL;
result = v7 / 4;
}
while ( v7 / 4 > v9 );
v55 = v10;
}
goto LABEL_69;
case 0xBu:
result = printf(
"<system_clock tag=\"0x0b\" data=\"%02x%02x\" />\n",
*(unsigned __int8 *)(a2 + v55),
*(unsigned __int8 *)(a2 + v55 + 1));
v4 = v55 + v7;
goto LABEL_53;
case 0x40u:
if ( v7 > 0 )
{
do
--v7;
while ( v7 );
}
goto LABEL_10;
case 0x41u:
result = v55;
if ( v7 > 0 )
{
do
result += 3;
while ( v7 + v55 - result > 0 );
v55 = result;
}
LABEL_10:
v4 = v55;
goto LABEL_119;
case 0x43u:
sprintf(s, "%x", _byteswap_ulong(*(_DWORD *)(a2 + v55)));
*(_DWORD *)(a3 + 8) = 10 * atoi(s);
*(_DWORD *)(a3 + 16) = *(unsigned __int8 *)(a2 + v55 + 4 + 1) | (*(unsigned __int8 *)(a2 + v55 + 4) << 8);
v19 = (_BYTE *)(a2 + v55 + 6);
*(_DWORD *)(a3 + 20) = *v19 >> 7;
v20 = ((int)(unsigned __int8)*v19 >> 5) & 3;
if ( v20 == 2 )
{
*(_BYTE *)(a3 + 24) = 76;
}
else if ( (((int)(unsigned __int8)*v19 >> 5) & 3) == 3 )
{
*(_BYTE *)(a3 + 24) = 82;
}
else if ( v20 )
{
*(_BYTE *)(a3 + 24) = 86;
}
else
{
*(_BYTE *)(a3 + 24) = 72;
}
*(_DWORD *)(a3 + 28) = *v19 & 0x1F;
sprintf(
s,
"%x",
((*(unsigned __int8 *)(a2 + v55 + 7 + 2) << 8) | (*(unsigned __int8 *)(a2 + v55 + 7 + 1) << 16) | (*(unsigned __int8 *)(a2 + v55 + 7) << 24) | *(_BYTE *)(a2 + v55 + 7 + 3) & 0xF0u) >> 4);
*(_DWORD *)(a3 + 12) = 100 * atoi(s);
v4 = v55 + 11;
result = (unsigned int)add_transponder(a3, a4);
goto LABEL_53;
case 0x48u:
printf("<description tag=\"0x48\" type=\"%d\"", *(unsigned __int8 *)(a2 + v55));
v59 = v55 + 2;
v63 = *(_BYTE *)(a2 + v55 + 1);
v62 = v7 - v63 - 2;
printf(" provider_name=\"");
if ( v63 )
{
v23 = (char *)(a2 + v59);
do
{
v24 = func0(*v23);
printf("%s", (const char *)v24);
++v23;
}
while ( v23 != (char *)((unsigned int)v63 - 1 + a2 + v55 + 3) );
v59 = v55 + v63 + 2;
}
printf("\" service_name=\"");
v55 = v59 + 1;
v25 = *(_BYTE *)(a2 + v59);
v64 = v25;
v7 = v62 - (v25 + 1);
if ( v25 )
{
v26 = (char *)(a2 + v59 + 1);
v27 = (char *)((unsigned int)v25 - 1 + v60 + v59);
do
{
v28 = func0(*v26);
printf("%s", (const char *)v28);
++v26;
}
while ( v26 != v27 );
v55 = v59 + v64 + 1;
}
result = puts("\" />");
LABEL_69:
if ( v7 > 0 )
continue;
v4 = v55;
goto LABEL_119;
case 0x49u:
printf("<country_availability tag=\"0x49\" type=\"%d\" countries=\" ", *(_BYTE *)(a2 + v55) >> 7);
v4 = v55 + 1;
if ( v7 > 1 )
{
v29 = (unsigned __int8 *)(a2 + v4);
do
putchar(*v29++);
while ( v29 != (unsigned __int8 *)((unsigned int)(v7 - 2) + v60 + v55) );
v4 = v55 + v7;
}
result = puts("\" />");
goto LABEL_53;
case 0x4Cu:
result = printf(
"<time_shifted_copy_of tag=\"0x4c\" service_id=\"%d\" />\n",
*(unsigned __int8 *)(a2 + v55 + 1) | (*(unsigned __int8 *)(a2 + v55) << 8));
v4 = v55 + v7;
goto LABEL_53;
case 0x52u:
result = printf("<stream_id id=\"%d\" />\n", *(unsigned __int8 *)(a2 + v55));
v4 = v55 + v7;
goto LABEL_53;
case 0x53u:
printf("<ca_identifier tag=\"0x53\" length=\"%02x\">\n", (unsigned int)v7);
if ( v7 > 0 )
{
v30 = (unsigned __int8 *)(a2 + v55);
do
{
printf("<ca_system_id>%04x</ca_system_id>\n", v30[1] | (*v30 << 8));
v30 += 2;
}
while ( v30 != (unsigned __int8 *)(v60 + v55 + 2LL * ((unsigned int)(v7 - 1) >> 1)) );
}
v4 = v7 + v55;
result = puts("</ca_identifier>");
goto LABEL_53;
case 0x56u:
puts("<teletext tag=\"0x56\">");
if ( v7 <= 0 )
{
v4 = v55;
}
else
{
v31 = (char *)(a2 + v55);
for ( i = 0; i < v7; i += 5 )
{
printf("<teletext_info lang=\"");
v33 = func0(*v31);
printf("%s", (const char *)v33);
v34 = func0(v31[1]);
printf("%s", (const char *)v34);
v35 = func0(v31[2]);
printf("%s", (const char *)v35);
v36 = v31[3] & 7;
if ( (v31[3] & 7) == 0 )
v36 = 8LL;
printf(
"\" type=\"%d\" page=\"%d%02x\" />\n",
(unsigned __int8)v31[3] >> 3,
v36,
(unsigned __int8)v31[4]);
v37 = v55 + i + 5;
v31 += 5;
}
v4 = v37;
}
result = puts("</teletext>");
goto LABEL_53;
case 0x59u:
puts("<subtitling_descriptor tag=\"0x59\">");
if ( v7 <= 0 )
{
v4 = v55;
}
else
{
v38 = a2 + v55;
v39 = (unsigned int)(v7 - 1) >> 3;
v40 = v38 + 8 + 8LL * v39;
do
{
printf("<subtitle_stream lang=\"");
v41 = func0(*(_BYTE *)v38);
printf("%s", (const char *)v41);
v42 = func0(*(_BYTE *)(v38 + 1));
printf("%s", (const char *)v42);
v43 = func0(*(_BYTE *)(v38 + 2));
printf("%s", (const char *)v43);
printf(
"\" type=\"%d\" composition_page_id=\"%04x\" ancillary_page_id=\"%04x\" />\n",
*(unsigned __int8 *)(v38 + 3),
*(unsigned __int8 *)(v38 + 5) | (*(unsigned __int8 *)(v38 + 4) << 8),
*(unsigned __int8 *)(v38 + 7) | (*(unsigned __int8 *)(v38 + 6) << 8));
v38 += 8LL;
}
while ( v38 != v40 );
v4 = v55 + 8 * v39 + 8;
}
result = puts("</subtitling_descriptor>");
goto LABEL_53;
case 0x6Au:
printf("<ac3_descriptor tag=\"0x6a\" data=\"");
if ( v7 > 0 )
{
v44 = (unsigned __int8 *)(a2 + v55);
v45 = (__int64)&v44[v7 - 1 + 1];
do
printf("%02x", *v44++);
while ( v44 != (unsigned __int8 *)v45 );
}
goto LABEL_117;
case 0x73u:
printf("<default_authority_descriptor tag=\"0x%02x\" name=\"", 115LL);
if ( v7 > 0 )
{
v46 = _ctype_b_loc();
v47 = (unsigned __int8 *)(a2 + v55);
v48 = (__int64)&v47[v7 - 1 + 1];
do
{
v49 = *v47;
if ( ((*v46)[*v47] & 8) == 0 )
v49 = 46;
putchar(v49);
++v47;
}
while ( v47 != (unsigned __int8 *)v48 );
}
goto LABEL_117;
default:
goto LABEL_110;
}
}
break;
}
}
return result;
}

original_code:
void parse_descriptors(int info_len,unsigned char *buf, transponder_t* transponder, transponder_t** transponders) {
  int i=0;
  int descriptor_tag,descriptor_length,j,k,pid,id;
  int service_type;
  char tmp[128];
  unsigned int freq, pol, sr;
       while (i < info_len) {
        descriptor_tag=buf[i++];
        descriptor_length=buf[i++];
        while (descriptor_length > 0) {
          switch(descriptor_tag) {
           case 0x03:
             printf("<audio_info tag=\"0x03\" info=\"%02x\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x06:
             printf("<data_stream_alignment tag=\"0x06\" data=\"%02x\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x0a:
             for (j=0;j<((descriptor_length)/4);j++) {
               printf("<iso_639 language=\"");
               if (buf[i]!=0) printf("%c",buf[i]);
               if (buf[i+1]!=0) printf("%c",buf[i+1]);
               if (buf[i+2]!=0) printf("%c",buf[i+2]);
               printf("\" type=\"%d\" />\n",buf[i+3]);
               i+=4;
               descriptor_length-=4;
             }
             break;
           case 0x0b:
             printf("<system_clock tag=\"0x0b\" data=\"%02x%02x\" />\n",buf[i],buf[i+1]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x09:
             k=((buf[i]<<8)|buf[i+1]);
             switch(k&0xff00) {
               case 0x0100:
                 for (j=2; j<descriptor_length; j+=15)
                 {
                   pid = ((buf[i+j] & 0x1f) << 8) | buf[i+j+1];
                   id = (buf[i+j+2] << 8) | buf[i+j+3];
                   printf("<ca_system_descriptor type=\"seca\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",k,pid,id);
                 }
                 break;
               case 0x0500:
                 j = 4;
                 while (j < descriptor_length)
                 {
                   if (buf[i+j]==0x14)
                   {
                     pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                     id = (buf[i+j+2] << 16) | (buf[i+j+3] << 8) | (buf[i+j+4] & 0xf0);
                     printf("<ca_system_descriptor type=\"viaccess\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",k,pid,id);
                   }
                   j += 2+buf[i+j+1];
                 }
                 break;
               case 0x0600:
               case 0x1700:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"irdeto\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x1800:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"nagra\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x0b00:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"conax\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x0900:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"videoguard\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               default:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"unknown\" system_id=\"0x%04x\" />\n",k);
                 break;
               }
               i+=descriptor_length;
               descriptor_length=0;
               break;
           case 0x40:
             j=descriptor_length;
             while(j > 0) {
               j--;
             }
             descriptor_length=0;
             break;
           case 0x41:
             while (descriptor_length > 0) {
               i+=3;
               descriptor_length-=3;
             }
             break;
           case 0x43:
             freq=(unsigned int)(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|buf[i+3];
             sprintf(tmp,"%x",freq);
             transponder->freq=atoi(tmp)*10;
             i+=4;
             transponder->pos=(buf[i]<<8)|buf[i+1];
             i+=2;
             transponder->we_flag=(buf[i]&0x80)>>7;
             pol=(buf[i]&0x60)>>5;
             switch(pol) {
                 case 0 : transponder->pol='H'; break;
                 case 1 : transponder->pol='V'; break;
                 case 2 : transponder->pol='L'; break;
                 case 3 : transponder->pol='R'; break;
             }
             transponder->mod=buf[i]&0x1f;
             i++;
             sr=(unsigned int)(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|(buf[i+3]&0xf0);
             sr=(unsigned int)(sr >> 4);
             sprintf(tmp,"%x",sr);
             transponder->srate=atoi(tmp)*100;
             i+=4;
             descriptor_length=0;
             add_transponder(transponder,transponders);
      break;
           case 0x48:
             service_type=buf[i++];
             printf("<description tag=\"0x48\" type=\"%d\"",service_type);
             descriptor_length--;
             j=buf[i++];
             descriptor_length-=(j+1);
             printf(" provider_name=\"");;
             while(j > 0) {
               printf("%s",xmlify(buf[i++]));
               j--;
             }
             printf("\" service_name=\"");
             j=buf[i++];
             descriptor_length-=(j+1);
             while(j > 0) {
               printf("%s",xmlify(buf[i]));
               i++;
               j--;
             }
             printf("\" />\n");
             break;
           case 0x49:
             printf("<country_availability tag=\"0x49\" type=\"%d\" countries=\" ",(buf[i]&0x80)>>7);
             i++;
             j=descriptor_length-1;
             while (j > 0) {
               printf("%c",buf[i++]);
               j--;
             }
             printf("\" />\n");
             descriptor_length=0;
             break;
          case 0x4c:
             printf("<time_shifted_copy_of tag=\"0x4c\" service_id=\"%d\" />\n",(buf[i]<<8)|buf[i+1]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x52:
             printf("<stream_id id=\"%d\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x53:
             printf("<ca_identifier tag=\"0x53\" length=\"%02x\">\n",descriptor_length);
             for (j=0;j<descriptor_length;j+=2) {
               k=(buf[i+j]<<8)|buf[i+j+1];
               printf("<ca_system_id>%04x</ca_system_id>\n",k);
             }
             i+=descriptor_length;
             descriptor_length=0;
             printf("</ca_identifier>\n");
             break;
          case 0x56:
             j=0;
             printf("<teletext tag=\"0x56\">\n");
             while (j < descriptor_length) {
               printf("<teletext_info lang=\"");
               printf("%s",xmlify(buf[i]));
               printf("%s",xmlify(buf[i+1]));
               printf("%s",xmlify(buf[i+2]));
               k=(buf[i+3]&0x07);
               printf("\" type=\"%d\" page=\"%d%02x\" />\n",(buf[i+3]&0xf8)>>3,(k==0 ? 8 : k),buf[i+4]);
               i+=5;
               j+=5;
             }
             printf("</teletext>\n");
             descriptor_length=0;
             break;
          case 0x59:
             j=0;
             printf("<subtitling_descriptor tag=\"0x59\">\n");
             while (j < descriptor_length) {
               printf("<subtitle_stream lang=\"");
               printf("%s",xmlify(buf[i]));
               printf("%s",xmlify(buf[i+1]));
               printf("%s",xmlify(buf[i+2]));
               printf("\" type=\"%d\" composition_page_id=\"%04x\" ancillary_page_id=\"%04x\" />\n",buf[i+3],(buf[i+4]<<8)|buf[i+5],(buf[i+6]<<8)|buf[i+7]);
               i+=8;
               j+=8;
             }
             printf("</subtitling_descriptor>\n");
             descriptor_length=0;
             break;
          case 0x6a:
             printf("<ac3_descriptor tag=\"0x6a\" data=\"");
             for (j=0;j<descriptor_length;j++) printf("%02x",buf[i+j]);
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x73:
             printf("<default_authority_descriptor tag=\"0x%02x\" name=\"",descriptor_tag);
             for (j=0;j<descriptor_length;j++) printf("%c",(((*__ctype_b_loc ())[(int) ((buf[i+j]))] & (unsigned short int) _ISalnum) ? buf[i+j] : '.'));
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0xc5:
            printf("<canal_radio tag=\"0x%02x\" id=\"%d\" name=\"",descriptor_tag,buf[i]);
            for (j=1;j<descriptor_length;j++)
              if (buf[i+j]!=0) printf("%c",buf[i+j]);
            printf("\" />\n");
            i+=descriptor_length;
            descriptor_length=0;
            break;
          default:
             printf("<descriptor tag=\"0x%02x\" data=\"",descriptor_tag);
             for (j=0;j<descriptor_length;j++) printf("%02x",buf[i+j]);
             printf("\" text=\"");
             for (j=0;j<descriptor_length;j++) printf("%c",(((*__ctype_b_loc ())[(int) ((buf[i+j]))] & (unsigned short int) _ISalnum) ? buf[i+j] : '.'));
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          }
        }
      }
}

canonical_original_code:
void parse_descriptors(int info_len, unsigned char *buf, struct _transponder_t *transponder, struct _transponder_t **transponders) {
  int i = 0;
  int descriptor_tag; int descriptor_length; int j; int k; int pid; int id;
  int service_type;
  char tmp[128];
  unsigned int freq; unsigned int pol; unsigned int sr;
       while (i < info_len) {
        descriptor_tag=buf[i++];
        descriptor_length=buf[i++];
        while (descriptor_length > 0) {
          switch(descriptor_tag) {
           case 0x03:
             printf("<audio_info tag=\"0x03\" info=\"%02x\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x06:
             printf("<data_stream_alignment tag=\"0x06\" data=\"%02x\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x0a:
             for (j=0;j<((descriptor_length)/4);j++) {
               printf("<iso_639 language=\"");
               if (buf[i]!=0) printf("%c",buf[i]);
               if (buf[i+1]!=0) printf("%c",buf[i+1]);
               if (buf[i+2]!=0) printf("%c",buf[i+2]);
               printf("\" type=\"%d\" />\n",buf[i+3]);
               i+=4;
               descriptor_length-=4;
             }
             break;
           case 0x0b:
             printf("<system_clock tag=\"0x0b\" data=\"%02x%02x\" />\n",buf[i],buf[i+1]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x09:
             k=((buf[i]<<8)|buf[i+1]);
             switch(k&0xff00) {
               case 0x0100:
                 for (j=2; j<descriptor_length; j+=15)
                 {
                   pid = ((buf[i+j] & 0x1f) << 8) | buf[i+j+1];
                   id = (buf[i+j+2] << 8) | buf[i+j+3];
                   printf("<ca_system_descriptor type=\"seca\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",k,pid,id);
                 }
                 break;
               case 0x0500:
                 j = 4;
                 while (j < descriptor_length)
                 {
                   if (buf[i+j]==0x14)
                   {
                     pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                     id = (buf[i+j+2] << 16) | (buf[i+j+3] << 8) | (buf[i+j+4] & 0xf0);
                     printf("<ca_system_descriptor type=\"viaccess\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",k,pid,id);
                   }
                   j += 2+buf[i+j+1];
                 }
                 break;
               case 0x0600:
               case 0x1700:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"irdeto\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x1800:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"nagra\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x0b00:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"conax\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x0900:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"videoguard\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               default:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"unknown\" system_id=\"0x%04x\" />\n",k);
                 break;
               }
               i+=descriptor_length;
               descriptor_length=0;
               break;
           case 0x40:
             j=descriptor_length;
             while(j > 0) {
               j--;
             }
             descriptor_length=0;
             break;
           case 0x41:
             while (descriptor_length > 0) {
               i+=3;
               descriptor_length-=3;
             }
             break;
           case 0x43:
             freq=(unsigned int)(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|buf[i+3];
             sprintf(tmp,"%x",freq);
             transponder->freq=atoi(tmp)*10;
             i+=4;
             transponder->pos=(buf[i]<<8)|buf[i+1];
             i+=2;
             transponder->we_flag=(buf[i]&0x80)>>7;
             pol=(buf[i]&0x60)>>5;
             switch(pol) {
                 case 0 : transponder->pol='H'; break;
                 case 1 : transponder->pol='V'; break;
                 case 2 : transponder->pol='L'; break;
                 case 3 : transponder->pol='R'; break;
             }
             transponder->mod=buf[i]&0x1f;
             i++;
             sr=(unsigned int)(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|(buf[i+3]&0xf0);
             sr=(unsigned int)(sr >> 4);
             sprintf(tmp,"%x",sr);
             transponder->srate=atoi(tmp)*100;
             i+=4;
             descriptor_length=0;
             add_transponder(transponder,transponders);
      break;
           case 0x48:
             service_type=buf[i++];
             printf("<description tag=\"0x48\" type=\"%d\"",service_type);
             descriptor_length--;
             j=buf[i++];
             descriptor_length-=(j+1);
             printf(" provider_name=\"");;
             while(j > 0) {
               printf("%s",xmlify(buf[i++]));
               j--;
             }
             printf("\" service_name=\"");
             j=buf[i++];
             descriptor_length-=(j+1);
             while(j > 0) {
               printf("%s",xmlify(buf[i]));
               i++;
               j--;
             }
             printf("\" />\n");
             break;
           case 0x49:
             printf("<country_availability tag=\"0x49\" type=\"%d\" countries=\" ",(buf[i]&0x80)>>7);
             i++;
             j=descriptor_length-1;
             while (j > 0) {
               printf("%c",buf[i++]);
               j--;
             }
             printf("\" />\n");
             descriptor_length=0;
             break;
          case 0x4c:
             printf("<time_shifted_copy_of tag=\"0x4c\" service_id=\"%d\" />\n",(buf[i]<<8)|buf[i+1]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x52:
             printf("<stream_id id=\"%d\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x53:
             printf("<ca_identifier tag=\"0x53\" length=\"%02x\">\n",descriptor_length);
             for (j=0;j<descriptor_length;j+=2) {
               k=(buf[i+j]<<8)|buf[i+j+1];
               printf("<ca_system_id>%04x</ca_system_id>\n",k);
             }
             i+=descriptor_length;
             descriptor_length=0;
             printf("</ca_identifier>\n");
             break;
          case 0x56:
             j=0;
             printf("<teletext tag=\"0x56\">\n");
             while (j < descriptor_length) {
               printf("<teletext_info lang=\"");
               printf("%s",xmlify(buf[i]));
               printf("%s",xmlify(buf[i+1]));
               printf("%s",xmlify(buf[i+2]));
               k=(buf[i+3]&0x07);
               printf("\" type=\"%d\" page=\"%d%02x\" />\n",(buf[i+3]&0xf8)>>3,(k==0 ? 8 : k),buf[i+4]);
               i+=5;
               j+=5;
             }
             printf("</teletext>\n");
             descriptor_length=0;
             break;
          case 0x59:
             j=0;
             printf("<subtitling_descriptor tag=\"0x59\">\n");
             while (j < descriptor_length) {
               printf("<subtitle_stream lang=\"");
               printf("%s",xmlify(buf[i]));
               printf("%s",xmlify(buf[i+1]));
               printf("%s",xmlify(buf[i+2]));
               printf("\" type=\"%d\" composition_page_id=\"%04x\" ancillary_page_id=\"%04x\" />\n",buf[i+3],(buf[i+4]<<8)|buf[i+5],(buf[i+6]<<8)|buf[i+7]);
               i+=8;
               j+=8;
             }
             printf("</subtitling_descriptor>\n");
             descriptor_length=0;
             break;
          case 0x6a:
             printf("<ac3_descriptor tag=\"0x6a\" data=\"");
             for (j=0;j<descriptor_length;j++) printf("%02x",buf[i+j]);
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x73:
             printf("<default_authority_descriptor tag=\"0x%02x\" name=\"",descriptor_tag);
             for (j=0;j<descriptor_length;j++) printf("%c",(((*__ctype_b_loc ())[(int) ((buf[i+j]))] & (unsigned short) _ISalnum) ? buf[i+j] : '.'));
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0xc5:
            printf("<canal_radio tag=\"0x%02x\" id=\"%d\" name=\"",descriptor_tag,buf[i]);
            for (j=1;j<descriptor_length;j++)
              if (buf[i+j]!=0) printf("%c",buf[i+j]);
            printf("\" />\n");
            i+=descriptor_length;
            descriptor_length=0;
            break;
          default:
             printf("<descriptor tag=\"0x%02x\" data=\"",descriptor_tag);
             for (j=0;j<descriptor_length;j++) printf("%02x",buf[i+j]);
             printf("\" text=\"");
             for (j=0;j<descriptor_length;j++) printf("%c",(((*__ctype_b_loc ())[(int) ((buf[i+j]))] & (unsigned short) _ISalnum) ? buf[i+j] : '.'));
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          }
        }
      }
}

variable_types:
buf
unsigned char *

variable_types:
transponders
struct _transponder_t **

variable_types: j int

variable_types: k int

variable_types: pid int

variable_types: id int

variable_types:
tmp
char [128]

variable_types:
freq
unsigned int

variable_types:
pol
unsigned int

variable_types:
sr
unsigned int

user_defined_types: struct _transponder_t { int id; int onid; unsigned int freq; int srate; int pos; int we_flag; char pol; int mod; int scanned; struct _transponder_t *next; }


repo: linzhi/GameMix

decompiled_code:
int snake_init()
{
_DWORD *v0; // rax
int v1; // er13
int v2; // er14
int v3; // er12
__int64 v4; // rbp
int v5; // ebx

wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
*(&snake + 3) = 0;
snake = 1;
*(&snake + 1) = 8;
v0 = malloc(0x40uLL);
*((_QWORD *)&snake + 2) = v0;
v1 = COLS / 2;
v2 = LINES / 2;
*v0 = COLS / 2;
v0[1] = v2;
if ( wmove(stdscr, v2, v1) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v3 = v1;
v4 = 8LL;
do
{
v5 = v3++;
*(_DWORD *)(*((_QWORD *)&snake + 2) + v4) = v3;
*(_DWORD *)(*((_QWORD *)&snake + 2) + v4 + 4) = v2;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v4 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v4)) != -1 )
waddch(stdscr, 0x4FuLL);
v4 += 8LL;
}
while ( v5 + 2 - v1 < *(&snake + 1) );
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func0()
{
_DWORD *v0; // rax
int v1; // er13
int v2; // er14
int v3; // er12
__int64 v4; // rbp
int v5; // ebx

wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
*(&snake + 3) = 0;
snake = 1;
*(&snake + 1) = 8;
v0 = malloc(0x40uLL);
*((_QWORD *)&snake + 2) = v0;
v1 = COLS / 2;
v2 = LINES / 2;
*v0 = COLS / 2;
v0[1] = v2;
if ( wmove(stdscr, v2, v1) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v3 = v1;
v4 = 8LL;
do
{
v5 = v3++;
*(_DWORD *)(*((_QWORD *)&snake + 2) + v4) = v3;
*(_DWORD *)(*((_QWORD *)&snake + 2) + v4 + 4) = v2;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v4 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v4)) != -1 )
waddch(stdscr, 0x4FuLL);
v4 += 8LL;
}
while ( v5 + 2 - v1 < *(&snake + 1) );
}
return wrefresh(stdscr);
}

original_code:
void snake_init()
{
    wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    int i = 0;
    snake.score = 0;
    snake.speed = 1;
    snake.size = 8;
    snake.body = malloc((snake.size) * sizeof(struct snake_body_t));
    if (snake.body == ((void *)0))
    {
        ;
    }
    int m = COLS / 2;
    int n = LINES / 2;
    snake.body[0].x = m;
    snake.body[0].y = n;
    (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
    for (i = 1; i < snake.size; i++)
    {
        m++;
        snake.body[i].x = m;
        snake.body[i].y = n;
        (wmove((stdscr),((snake.body[i].y)),((snake.body[i].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
    }
    wrefresh(stdscr);
}

variable_types: i int

variable_types: m int

variable_types: n int

return_type: void


decompiled_code:
int snake_fruit_init()
{
unsigned int v0; // eax
int v1; // esi
__int64 v2; // rbx
_DWORD *v3; // rax

wattr_off(stdscr, 0x500uLL, 0LL);
wattr_on(stdscr, 0x300uLL, 0LL);
v0 = time(0LL);
srand(v0);
fruit = rand() % (COLS - 2) + 1;
v1 = rand() % (LINES - 2) + 1;
*(&fruit + 1) = v1;
if ( wmove(stdscr, v1, fruit) != -1 )
waddch(stdscr, 0x24uLL);
if ( *(&snake + 1) > 1 )
{
v2 = 0LL;
do
{
v3 = (_DWORD *)(*((_QWORD *)&snake + 2) + 8 * v2);
if ( fruit == *v3 && *(&fruit + 1) == v3[1] )
snake_fruit_init();
++v2;
}
while ( *(&snake + 1) - 1 > (int)v2 );
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func1()
{
unsigned int v0; // eax
int v1; // esi
__int64 v2; // rbx
_DWORD *v3; // rax

wattr_off(stdscr, 0x500uLL, 0LL);
wattr_on(stdscr, 0x300uLL, 0LL);
v0 = time(0LL);
srand(v0);
fruit = rand() % (COLS - 2) + 1;
v1 = rand() % (LINES - 2) + 1;
*(&fruit + 1) = v1;
if ( wmove(stdscr, v1, fruit) != -1 )
waddch(stdscr, 0x24uLL);
if ( *(&snake + 1) > 1 )
{
v2 = 0LL;
do
{
v3 = (_DWORD *)(*((_QWORD *)&snake + 2) + 8 * v2);
if ( fruit == *v3 && *(&fruit + 1) == v3[1] )
func1();
++v2;
}
while ( *(&snake + 1) - 1 > (int)v2 );
}
return wrefresh(stdscr);
}

original_code:
void snake_fruit_init()
{
    wattr_off(stdscr, (attr_t)(((((chtype)(((GREEN_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    wattr_on(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    srand((int)time(((void *)0)));
    int valid_fruit = 0;
    fruit.x_pos = (rand() % (COLS - 2)) + 1;
    fruit.y_pos = (rand() % (LINES - 2)) + 1;
    (wmove((stdscr),((fruit.y_pos)),((fruit.x_pos))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_FRUIT_CHAR))));
    int i;
    for (i = 0; i < (snake.size - 1); i++)
    {
        if ((fruit.x_pos == snake.body[i].x) &&
            (fruit.y_pos == snake.body[i].y))
        {
            snake_fruit_init();
        }
    }
    wrefresh(stdscr);
}


decompiled_code:
int snake_borders_init()
{
int v0; // ebx
int v1; // ebx

wclear(stdscr);
wattr_off(stdscr, 0x400uLL, 0LL);
wattr_on(stdscr, 0x500uLL, 0LL);
if ( LINES > 1 )
{
v0 = 1;
do
{
if ( wmove(stdscr, v0, 0) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, v0, COLS - 1) != -1 )
waddch(stdscr, 0x2BuLL);
++v0;
}
while ( LINES > v0 );
}
if ( COLS > 0 )
{
v1 = 0;
do
{
if ( wmove(stdscr, 0, v1) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, LINES - 1, v1) != -1 )
waddch(stdscr, 0x2BuLL);
++v1;
}
while ( COLS > v1 );
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func2()
{
int v0; // ebx
int v1; // ebx

wclear(stdscr);
wattr_off(stdscr, 0x400uLL, 0LL);
wattr_on(stdscr, 0x500uLL, 0LL);
if ( LINES > 1 )
{
v0 = 1;
do
{
if ( wmove(stdscr, v0, 0) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, v0, COLS - 1) != -1 )
waddch(stdscr, 0x2BuLL);
++v0;
}
while ( LINES > v0 );
}
if ( COLS > 0 )
{
v1 = 0;
do
{
if ( wmove(stdscr, 0, v1) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, LINES - 1, v1) != -1 )
waddch(stdscr, 0x2BuLL);
++v1;
}
while ( COLS > v1 );
}
return wrefresh(stdscr);
}


decompiled_code:
void __noreturn snake_move_init()
{
int v0; // edx
__int64 v1; // rax
int *v2; // rax

while ( 1 )
{
v2 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v2[1], *v2) != -1 )
waddch(stdscr, 0x20uLL);
v0 = *(&snake + 1);
if ( v0 - 1 > 0 )
{
v1 = 8LL * (v0 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v1) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v1 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v1 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v1 - 4);
v1 -= 8LL;
}
while ( v1 != 8 * (v0 - (unsigned __int64)(unsigned int)(v0 - 2)) - 16 );
}
**((_DWORD **)&snake + 2) -= snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
wrefresh(stdscr);
}
}

original_code:
void snake_move_init()
{
    while (1)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        int i;
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        wrefresh(stdscr);
    }
}


decompiled_code:
void *snake_increase()
{
int v0; // eax
void *result; // rax

v0 = *(&snake + 1);
*(&snake + 1) = v0 + 1;
result = realloc(*((void **)&snake + 2), 8 * (v0 + 1));
*((_QWORD *)&snake + 2) = result;
return result;
}

canonical_decompiled_code:
void *func4()
{
int v0; // eax
void *result; // rax

v0 = *(&snake + 1);
*(&snake + 1) = v0 + 1;
result = realloc(*((void **)&snake + 2), 8 * (v0 + 1));
*((_QWORD *)&snake + 2) = result;
return result;
}

original_code:
void snake_increase()
{
    int body_size = sizeof(struct snake_body_t);
    snake.size += 1;
    snake.body = realloc(snake.body, (snake.size * body_size));
    if (snake.body == ((void *)0))
    {
        ;
    }
}


decompiled_code:
_BOOL8 snake_eat_fruit()
{
_DWORD *v0; // rdx
_BOOL8 result; // rax

v0 = (_DWORD *)*((_QWORD *)&snake + 2);
result = 0LL;
if ( *v0 == fruit )
result = v0[1] == *(&fruit + 1);
return result;
}

canonical_decompiled_code:
_BOOL8 func5()
{
_DWORD *v0; // rdx
_BOOL8 result; // rax

v0 = (_DWORD *)*((_QWORD *)&snake + 2);
result = 0LL;
if ( *v0 == fruit )
result = v0[1] == *(&fruit + 1);
return result;
}

original_code:
int snake_eat_fruit()
{
    if ((snake.body[0].x == fruit.x_pos) &&
        (snake.body[0].y == fruit.y_pos))
        return 1;
    else
        return 0;
}

return_type: int


decompiled_code:
_BOOL8 snake_collide_snake()
{
_DWORD *v0; // rdx
_BOOL8 result; // rax

if ( *(&snake + 1) > 2 )
{
v0 = (_DWORD *)*((_QWORD *)&snake + 2);
result = 0LL;
if ( *v0 == v0[2] )
result = v0[1] == v0[3];
}
return result;
}

canonical_decompiled_code:
_BOOL8 func6()
{
_DWORD *v0; // rdx
_BOOL8 result; // rax

if ( *(&snake + 1) > 2 )
{
v0 = (_DWORD *)*((_QWORD *)&snake + 2);
result = 0LL;
if ( *v0 == v0[2] )
result = v0[1] == v0[3];
}
return result;
}

original_code:
int snake_collide_snake()
{
   int i;
   for (i = 1; i < (snake.size - 1); i++)
   {
        if ((snake.body[0].x == snake.body[i].x) &&
            (snake.body[0].y == snake.body[i].y))
            return 1;
        else
            return 0;
   }
}


decompiled_code:
int snake_move()
{
int result; // eax
int *v1; // rax
int v2; // edx
__int64 v3; // rax
__int64 v4; // rbp
int v5; // ebx
int *v6; // rax
int v7; // edx
__int64 v8; // rax
__int64 v9; // rbp
int v10; // ebx
int *v11; // rax
int *v12; // rax
int v13; // edx
__int64 v14; // rax
__int64 v15; // rbp
int v16; // ebx
int *v17; // rax
int *v18; // rax
int v19; // edx
__int64 v20; // rax
__int64 v21; // rbp
int v22; // ebx
int *v23; // rax
int *v24; // rax

result = key_input();
if ( key_up )
{
v6 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v6[1], *v6) != -1 )
waddch(stdscr, 0x20uLL);
v7 = *(&snake + 1);
if ( v7 - 1 > 0 )
{
v8 = 8LL * (v7 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v8) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v8 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v8 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v8 - 4);
v8 -= 8LL;
}
while ( 8 * (v7 - (unsigned __int64)(unsigned int)(v7 - 2)) - 16 != v8 );
}
*(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL) -= snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v9 = 8LL;
v10 = 1;
do
{
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v9 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v9)) != -1 )
waddch(stdscr, 0x4FuLL);
++v10;
v9 += 8LL;
}
while ( *(&snake + 1) > v10 );
}
if ( snake_eat_fruit() )
{
*(&snake + 3) += 5;
snake_increase();
v11 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v11[1], *v11) != -1 )
waddch(stdscr, 0x4FuLL);
snake_fruit_init();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( !*(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL) || snake_collide_snake() )
{
engine_show_game_over();
free(*((void **)&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_up = 0;
}
else if ( key_down )
{
v12 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v12[1], *v12) != -1 )
waddch(stdscr, 0x20uLL);
v13 = *(&snake + 1);
if ( v13 - 1 > 0 )
{
v14 = 8LL * (v13 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v14) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v14 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v14 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v14 - 4);
v14 -= 8LL;
}
while ( 8 * (v13 - (unsigned __int64)(unsigned int)(v13 - 2)) - 16 != v14 );
}
*(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL) += snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v15 = 8LL;
v16 = 1;
do
{
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v15 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v15)) != -1 )
waddch(stdscr, 0x4FuLL);
++v16;
v15 += 8LL;
}
while ( *(&snake + 1) > v16 );
}
if ( snake_eat_fruit() )
{
*(&snake + 3) += 5;
snake_increase();
v17 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v17[1], *v17) != -1 )
waddch(stdscr, 0x4FuLL);
snake_fruit_init();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL) == LINES - 1 || snake_collide_snake() )
{
engine_show_game_over();
free(*((void **)&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_down = 0;
}
else if ( key_left )
{
v18 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v18[1], *v18) != -1 )
waddch(stdscr, 0x20uLL);
v19 = *(&snake + 1);
if ( v19 - 1 > 0 )
{
v20 = 8LL * (v19 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v20) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v20 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v20 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v20 - 4);
v20 -= 8LL;
}
while ( v20 != 8 * (v19 - (unsigned __int64)(unsigned int)(v19 - 2)) - 16 );
}
**((_DWORD **)&snake + 2) -= snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v21 = 8LL;
v22 = 1;
do
{
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v21 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v21)) != -1 )
waddch(stdscr, 0x4FuLL);
++v22;
v21 += 8LL;
}
while ( *(&snake + 1) > v22 );
}
if ( snake_eat_fruit() )
{
*(&snake + 3) += 5;
snake_increase();
v23 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1));
if ( wmove(stdscr, v23[1], *v23) != -1 )
waddch(stdscr, 0x4FuLL);
snake_fruit_init();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( !**((_DWORD **)&snake + 2) || snake_collide_snake() )
{
engine_show_game_over();
free(*((void **)&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_left = 0;
}
else if ( key_right )
{
v1 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v1[1], *v1) != -1 )
waddch(stdscr, 0x20uLL);
v2 = *(&snake + 1);
if ( v2 - 1 > 0 )
{
v3 = 8LL * (v2 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v3) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v3 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v3 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v3 - 4);
v3 -= 8LL;
}
while ( v3 != 8 * (v2 - (unsigned __int64)(unsigned int)(v2 - 2)) - 16 );
}
**((_DWORD **)&snake + 2) += snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v4 = 8LL;
v5 = 1;
do
{
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v4 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v4)) != -1 )
waddch(stdscr, 0x4FuLL);
++v5;
v4 += 8LL;
}
while ( *(&snake + 1) > v5 );
}
if ( snake_eat_fruit() )
{
*(&snake + 3) += 5;
snake_increase();
v24 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v24[1], *v24) != -1 )
waddch(stdscr, 0x4FuLL);
snake_fruit_init();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( **((_DWORD **)&snake + 2) == COLS - 1 || snake_collide_snake() )
{
engine_show_game_over();
free(*((void **)&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_right = 0;
}
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax
int *v1; // rax
int v2; // edx
__int64 v3; // rax
__int64 v4; // rbp
int v5; // ebx
int *v6; // rax
int v7; // edx
__int64 v8; // rax
__int64 v9; // rbp
int v10; // ebx
int *v11; // rax
int *v12; // rax
int v13; // edx
__int64 v14; // rax
__int64 v15; // rbp
int v16; // ebx
int *v17; // rax
int *v18; // rax
int v19; // edx
__int64 v20; // rax
__int64 v21; // rbp
int v22; // ebx
int *v23; // rax
int *v24; // rax

result = key_input();
if ( key_up )
{
v6 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v6[1], *v6) != -1 )
waddch(stdscr, 0x20uLL);
v7 = *(&snake + 1);
if ( v7 - 1 > 0 )
{
v8 = 8LL * (v7 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v8) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v8 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v8 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v8 - 4);
v8 -= 8LL;
}
while ( 8 * (v7 - (unsigned __int64)(unsigned int)(v7 - 2)) - 16 != v8 );
}
*(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL) -= snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v9 = 8LL;
v10 = 1;
do
{
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v9 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v9)) != -1 )
waddch(stdscr, 0x4FuLL);
++v10;
v9 += 8LL;
}
while ( *(&snake + 1) > v10 );
}
if ( func5() )
{
*(&snake + 3) += 5;
func4();
v11 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v11[1], *v11) != -1 )
waddch(stdscr, 0x4FuLL);
func1();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( !*(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL) || func6() )
{
engine_show_game_over();
free(*((void **)&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_up = 0;
}
else if ( key_down )
{
v12 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v12[1], *v12) != -1 )
waddch(stdscr, 0x20uLL);
v13 = *(&snake + 1);
if ( v13 - 1 > 0 )
{
v14 = 8LL * (v13 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v14) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v14 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v14 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v14 - 4);
v14 -= 8LL;
}
while ( 8 * (v13 - (unsigned __int64)(unsigned int)(v13 - 2)) - 16 != v14 );
}
*(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL) += snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v15 = 8LL;
v16 = 1;
do
{
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v15 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v15)) != -1 )
waddch(stdscr, 0x4FuLL);
++v16;
v15 += 8LL;
}
while ( *(&snake + 1) > v16 );
}
if ( func5() )
{
*(&snake + 3) += 5;
func4();
v17 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v17[1], *v17) != -1 )
waddch(stdscr, 0x4FuLL);
func1();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL) == LINES - 1 || func6() )
{
engine_show_game_over();
free(*((void **)&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_down = 0;
}
else if ( key_left )
{
v18 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v18[1], *v18) != -1 )
waddch(stdscr, 0x20uLL);
v19 = *(&snake + 1);
if ( v19 - 1 > 0 )
{
v20 = 8LL * (v19 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v20) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v20 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v20 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v20 - 4);
v20 -= 8LL;
}
while ( v20 != 8 * (v19 - (unsigned __int64)(unsigned int)(v19 - 2)) - 16 );
}
**((_DWORD **)&snake + 2) -= snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v21 = 8LL;
v22 = 1;
do
{
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v21 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v21)) != -1 )
waddch(stdscr, 0x4FuLL);
++v22;
v21 += 8LL;
}
while ( *(&snake + 1) > v22 );
}
if ( func5() )
{
*(&snake + 3) += 5;
func4();
v23 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1));
if ( wmove(stdscr, v23[1], *v23) != -1 )
waddch(stdscr, 0x4FuLL);
func1();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( !**((_DWORD **)&snake + 2) || func6() )
{
engine_show_game_over();
free(*((void **)&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_left = 0;
}
else if ( key_right )
{
v1 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v1[1], *v1) != -1 )
waddch(stdscr, 0x20uLL);
v2 = *(&snake + 1);
if ( v2 - 1 > 0 )
{
v3 = 8LL * (v2 - 1);
do
{
*(_DWORD *)(*((_QWORD *)&snake + 2) + v3) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v3 - 8);
*(_DWORD *)(*((_QWORD *)&snake + 2) + v3 + 4) = *(_DWORD *)(*((_QWORD *)&snake + 2) + v3 - 4);
v3 -= 8LL;
}
while ( v3 != 8 * (v2 - (unsigned __int64)(unsigned int)(v2 - 2)) - 16 );
}
**((_DWORD **)&snake + 2) += snake;
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + 4LL), **((_DWORD **)&snake + 2)) != -1 )
waddch(stdscr, 0x58uLL);
if ( *(&snake + 1) > 1 )
{
v4 = 8LL;
v5 = 1;
do
{
if ( wmove(stdscr, *(_DWORD *)(*((_QWORD *)&snake + 2) + v4 + 4), *(_DWORD *)(*((_QWORD *)&snake + 2) + v4)) != -1 )
waddch(stdscr, 0x4FuLL);
++v5;
v4 += 8LL;
}
while ( *(&snake + 1) > v5 );
}
if ( func5() )
{
*(&snake + 3) += 5;
func4();
v24 = (int *)(*((_QWORD *)&snake + 2) + 8LL * *(&snake + 1) - 8);
if ( wmove(stdscr, v24[1], *v24) != -1 )
waddch(stdscr, 0x4FuLL);
func1();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( **((_DWORD **)&snake + 2) == COLS - 1 || func6() )
{
engine_show_game_over();
free(*((void **)&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_right = 0;
}
return result;
}

original_code:
void snake_move()
{
    key_input();
    int i, j;
    int move_up = 1;
    int move_down = 0;
    int move_left = 0;
    int move_right = 0;
    if (key_up)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].y = snake.body[0].y - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].y == 0) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_up = 0;
    }
    else if (key_down)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].y = snake.body[0].y + snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].y == LINES - 1) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_down = 0;
    }
    else if (key_left)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size].y)),((snake.body[snake.size].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].x == 0) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_left = 0;
    }
    else if (key_right)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x + snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].x == COLS - 1) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_right = 0;
    }
}

canonical_original_code:
void snake_move()
{
    key_input();
    int i; int j;
    int move_up = 1;
    int move_down = 0;
    int move_left = 0;
    int move_right = 0;
    if (key_up)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].y = snake.body[0].y - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].y == 0) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_up = 0;
    }
    else if (key_down)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].y = snake.body[0].y + snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].y == LINES - 1) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_down = 0;
    }
    else if (key_left)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size].y)),((snake.body[snake.size].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].x == 0) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_left = 0;
    }
    else if (key_right)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x + snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].x == COLS - 1) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_right = 0;
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
engine_init(argc, argv, envp);
engine_show_game_menu();
while ( 1 )
{
key_input();
if ( snake_game )
break;
if ( tank_game )
{
tank_game = 0;
}
else if ( pushbox_game )
{
pushbox_game = 0;
}
else if ( esc_key )
{
engine_exit();
}
}
engine_show_snake_game_start();
snake_borders_init();
snake_fruit_init();
snake_init();
while ( 1 )
{
do
snake_move();
while ( !esc_key );
engine_exit();
}
}

original_code:
int main(int argc, char *argv[])
{
    engine_init();
    engine_show_game_menu();
    while (1)
    {
        key_input();
        if (snake_game)
        {
            engine_show_snake_game_start();
            snake_borders_init();
            snake_fruit_init();
            snake_init();
            while (1)
            {
                snake_move();
                if (esc_key)
                {
                    engine_exit();
                }
            }
            snake_game = 0;
        }
        else if (tank_game)
        {
            tank_game = 0;
        }
        else if (pushbox_game)
        {
            pushbox_game = 0;
        }
        else if (esc_key)
        {
            engine_exit();
        }
    }
    engine_exit();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int key_input()
{
int result; // eax

result = wgetch(stdscr);
if ( result == 258 )
{
key_down = 1;
return result;
}
if ( result <= 258 )
{
if ( result == 50 )
{
tank_game = 1;
return result;
}
if ( result <= 50 )
{
if ( result == 27 )
{
LABEL_7:
esc_key = 1;
return result;
}
if ( result == 49 )
snake_game = 1;
}
else if ( result == 51 )
{
pushbox_game = 1;
}
}
else
{
if ( result == 261 )
{
key_right = 1;
return result;
}
if ( result > 261 )
{
if ( result != 343 )
return result;
key_enter = 1;
goto LABEL_7;
}
if ( result == 259 )
key_up = 1;
else
key_left = 1;
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = wgetch(stdscr);
if ( result == 258 )
{
key_down = 1;
return result;
}
if ( result <= 258 )
{
if ( result == 50 )
{
tank_game = 1;
return result;
}
if ( result <= 50 )
{
if ( result == 27 )
{
LABEL_7:
esc_key = 1;
return result;
}
if ( result == 49 )
snake_game = 1;
}
else if ( result == 51 )
{
pushbox_game = 1;
}
}
else
{
if ( result == 261 )
{
key_right = 1;
return result;
}
if ( result > 261 )
{
if ( result != 343 )
return result;
key_enter = 1;
goto LABEL_7;
}
if ( result == 259 )
key_up = 1;
else
key_left = 1;
}
return result;
}

original_code:
void key_input()
{
    int input = wgetch(stdscr);
    switch(input)
    {
        case (-1):
            break;
        case '1':
            snake_game = 1;
            break;
        case '2':
            tank_game = 1;
            break;
        case '3':
            pushbox_game = 1;
            break;
        case 0403:
            key_up = 1;
            break;
        case 0402:
            key_down = 1;
            break;
        case 0404:
            key_left = 1;
            break;
        case 0405:
            key_right = 1;
            break;
        case 0407:
            break;
        case 0527:
            key_enter = 1;
        case 27:
            esc_key = 1;
            break;
        case 32:
            break;
        default:
            break;
    }
}

variable_types: input int


decompiled_code:
int engine_exit()
{
wclear(stdscr);
wrefresh(stdscr);
return endwin();
}

canonical_decompiled_code:
int func0()
{
wclear(stdscr);
wrefresh(stdscr);
return endwin();
}

original_code:
void engine_exit()
{
    wclear(stdscr);
    wrefresh(stdscr);
    endwin();
}


decompiled_code:
int engine_init()
{
initscr();
if ( !has_colors() )
{
engine_exit();
puts("Your terminal does not support colors.");
}
start_color();
init_pair(1, 4, 0);
init_pair(3, 1, 0);
init_pair(4, 7, 0);
init_pair(5, 2, 0);
init_pair(6, 2, 1);
init_pair(2, 3, 0);
raw();
curs_set(0);
keypad(stdscr, 1);
noecho();
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func1()
{
initscr();
if ( !has_colors() )
{
func0();
puts("Your terminal does not support colors.");
}
start_color();
init_pair(1, 4, 0);
init_pair(3, 1, 0);
init_pair(4, 7, 0);
init_pair(5, 2, 0);
init_pair(6, 2, 1);
init_pair(2, 3, 0);
raw();
curs_set(0);
keypad(stdscr, 1);
noecho();
return wrefresh(stdscr);
}

original_code:
void engine_init()
{
    initscr();
    if (has_colors() == 0)
    {
        engine_exit();
        printf("%s", "Your terminal does not support colors.\n" );
    }
    start_color();
    init_pair(BLUE_BLACK, 4, 0);
    init_pair(RED_BLACK, 1, 0);
    init_pair(WHITE_BLACK, 7, 0);
    init_pair(GREEN_BLACK, 2, 0);
    init_pair(GREEN_RED, 2, 1);
    init_pair(YELLOW_BLACK, 3, 0);
    raw();
    curs_set (0);
    keypad(stdscr, 1);
    noecho();
    wrefresh(stdscr);
}


mystart

repo: lirongyuan/ELF-Reader-and-Loader

decompiled_code:
int __fastcall mystart(__int64 a1, int a2, const char **a3)
{
FUNC_TABLE = a1;
return main(a2, a3, a3);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2, const char **a3)
{
FUNC_TABLE = a1;
return main(a2, a3, a3);
}

original_code:
void mystart(FUNCPTR * func_table, int argc, char ** argv) {
  FUNC_TABLE = func_table;
  main(argc, argv);
}

canonical_original_code:
void mystart(int (**func_table)(), int argc, char **argv) {
  FUNC_TABLE = func_table;
  main(argc, argv);
}

variable_types:
argv
char **


printf

decompiled_code:
__int64 printf()
{
return (*(__int64 (**)(void))FUNC_TABLE)();
}

canonical_decompiled_code:
__int64 func1()
{
return (*(__int64 (**)(void))FUNC_TABLE)();
}

original_code:
int printf(char * s, int a1, int a2, int a3, int a4, int a5) {
  return (FUNC_TABLE[0])(s, a1, a2, a3, a4, a5);
}

canonical_original_code:
int printf(char *s, int a1, int a2, int a3, int a4, int a5) {
  return (FUNC_TABLE[0])(s, a1, a2, a3, a4, a5);
}

variable_types:
s
char *


gets

decompiled_code:
__int64 gets()
{
return (*(int (**)(void))(FUNC_TABLE + 8))();
}

canonical_decompiled_code:
__int64 func2()
{
return (*(int (**)(void))(FUNC_TABLE + 8))();
}

original_code:
char *gets(char *s){
 return (char *)(FUNC_TABLE[1])(s);
}

return_type: char *


strcpy

decompiled_code:
__int64 strcpy()
{
return (*(int (**)(void))(FUNC_TABLE + 16))();
}

canonical_decompiled_code:
__int64 func3()
{
return (*(int (**)(void))(FUNC_TABLE + 16))();
}

original_code:
char *strcpy(char *s1,char *s2){
 return (char *)(FUNC_TABLE[2])(s1,s2);
}

canonical_original_code:
char *strcpy(char *s1, char *s2){
 return (char *)(FUNC_TABLE[2])(s1,s2);
}


strlen

original_code:
int strlen(const char *s){
 return (FUNC_TABLE[3])(s);
}

canonical_original_code:
int strlen(char *s){
 return (FUNC_TABLE[3])(s);
}


scanf

original_code:
int scanf(char * s, int a1, int a2, int a3, int a4, int a5){
 return (FUNC_TABLE[4])(s,a1,a2,a3,a4,a5);
}

canonical_original_code:
int scanf(char *s, int a1, int a2, int a3, int a4, int a5){
 return (FUNC_TABLE[4])(s,a1,a2,a3,a4,a5);
}


repo: lirongyuan/Music-Generator

decompiled_code:
__int64 __fastcall assignLittleEndian4(unsigned int *a1, unsigned int a2)
{
*a1 = a2;
return HIBYTE(a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, unsigned int a2)
{
*a1 = a2;
return HIBYTE(a2);
}

original_code:
void assignLittleEndian4(unsigned char * dest, unsigned int value) {
 dest[0] = value & 0xFF;
 dest[1] = (value >> 8) & 0xFF;
 dest[2] = (value >> 16) & 0xFF;
 dest[3] = (value >> 24) & 0xFF;
}

canonical_original_code:
void assignLittleEndian4(unsigned char *dest, unsigned int value) {
 dest[0] = value & 0xFF;
 dest[1] = (value >> 8) & 0xFF;
 dest[2] = (value >> 16) & 0xFF;
 dest[3] = (value >> 24) & 0xFF;
}

variable_types:
dest
unsigned char *

variable_types:
value
unsigned int


repo: lisa-project/lisa-user

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

result = 0LL;
if ( a2 )
result = *(_QWORD *)(a1 + 24) + a2;
return result;
}

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

result = 0LL;
if ( a2 )
result = *(_QWORD *)(a1 + 24) + a2;
return result;
}

original_code:
static __inline__ void *mm_addr(struct mm_private *mm, mm_ptr_t p)
{
 return 0 == p ? ((void *)0) : (void *)(mm->area + p);
}

canonical_original_code:
static __inline__ void *mm_addr(struct mm_private *mm, unsigned int p)
{
 return 0 == p ? ((void *)0) : (void *)(mm->area + p);
}

variable_types: struct mm_private { int fd; union sem_t { char __size[32]; long __align; } *sem; int lock; char *area; unsigned long mapped_size; int init; } *

variable_types:
p
unsigned int

return_type: void *

user_defined_types: struct mm_private { int fd; union sem_t *sem; int lock; char *area; unsigned long mapped_size; int init; }


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

result = 0LL;
if ( a2 )
result = (unsigned int)(a2 - *(_DWORD *)(a1 + 24));
return result;
}

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

result = 0LL;
if ( a2 )
result = (unsigned int)(a2 - *(_DWORD *)(a1 + 24));
return result;
}

original_code:
static __inline__ mm_ptr_t mm_ptr(struct mm_private *mm, void *a)
{
 return ((void *)0) == a ? 0 : (char *)a - mm->area;
}

canonical_original_code:
static __inline__ unsigned int mm_ptr(struct mm_private *mm, void *a)
{
 return ((void *)0) == a ? 0 : (char *)a - mm->area;
}

variable_types:
a
void *

return_type: unsigned int

user_defined_types: union sem_t { char __size[32]; long __align; }


decompiled_code:
__int64 __fastcall mm_list_add_tail(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int *v4; // rax

v4 = (unsigned int *)mm_addr(a1, a3);
return _mm_list_add(a1, a2, *v4, a3);
}

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

v4 = (unsigned int *)func0(a1, a3);
return func2(a1, a2, *v4, a3);
}

original_code:
static __inline__ void mm_list_add_tail(struct mm_private *mm, mm_ptr_t new,
  mm_ptr_t head)
{
 __mm_list_add(mm, new, ((struct mm_list_head *)mm_addr((mm), (head)))->prev, head);
}

canonical_original_code:
static __inline__ void mm_list_add_tail(struct mm_private *mm, unsigned int new, unsigned int head)
{
 __mm_list_add(mm, new, ((struct mm_list_head *)mm_addr((mm), (head)))->prev, head);
}

variable_types:
new
unsigned int

variable_types:
head
unsigned int

user_defined_types: struct mm_list_head { unsigned int prev; }


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

v2 = (unsigned int *)mm_addr(a1, a2);
_mm_list_del(a1, *v2, v2[1]);
*(_DWORD *)mm_addr(a1, a2) = 0;
result = mm_addr(a1, a2);
*(_DWORD *)(result + 4) = 0;
return result;
}

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

v2 = (unsigned int *)func0(a1, a2);
func4(a1, *v2, v2[1]);
*(_DWORD *)func0(a1, a2) = 0;
result = func0(a1, a2);
*(_DWORD *)(result + 4) = 0;
return result;
}

original_code:
static __inline__ void mm_list_del(struct mm_private *mm, mm_ptr_t entry)
{
 __mm_list_del(mm, ((struct mm_list_head *)mm_addr((mm), (entry)))->prev, ((struct mm_list_head *)mm_addr((mm), (entry)))->next);
 ((struct mm_list_head *)mm_addr((mm), (entry)))->next = ((struct mm_list_head *)mm_addr((mm), (entry)))->prev = 0;
}

canonical_original_code:
static __inline__ void mm_list_del(struct mm_private *mm, unsigned int entry)
{
 __mm_list_del(mm, ((struct mm_list_head *)mm_addr((mm), (entry)))->prev, ((struct mm_list_head *)mm_addr((mm), (entry)))->next);
 ((struct mm_list_head *)mm_addr((mm), (entry)))->next = ((struct mm_list_head *)mm_addr((mm), (entry)))->prev = 0;
}

variable_types:
entry
unsigned int


decompiled_code:
_BOOL8 __fastcall mm_list_empty(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(mm_addr(a1, a2) + 4) == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(func0(a1, a2) + 4) == a2;
}

original_code:
static __inline__ int mm_list_empty(struct mm_private *mm, mm_ptr_t head)
{
 return ((struct mm_list_head *)mm_addr((mm), (head)))->next == head;
}

canonical_original_code:
static __inline__ int mm_list_empty(struct mm_private *mm, unsigned int head)
{
 return ((struct mm_list_head *)mm_addr((mm), (head)))->next == head;
}


decompiled_code:
unsigned __int64 __fastcall page_size(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = sysconf(30);
return v1 * ((v1 + a1 - 1) / v1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = sysconf(30);
return v1 * ((v1 + a1 - 1) / v1);
}

original_code:
static __inline__ size_t page_size(size_t size)
{
 size_t p_size = sysconf(_SC_PAGESIZE);
 return p_size * ((size + p_size - 1) / p_size);
}

canonical_original_code:
static __inline__ unsigned long page_size(unsigned long size)
{
 unsigned long p_size = sysconf(_SC_PAGESIZE);
 return p_size * ((size + p_size - 1) / p_size);
}

variable_types:
size
unsigned long

return_type: unsigned long


decompiled_code:
int __fastcall mm_unlock(__int64 a1)
{
int result; // eax

result = *(_DWORD *)(a1 + 16) - 1;
*(_DWORD *)(a1 + 16) = result;
if ( !result )
result = sem_post(*(sem_t **)(a1 + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
int result; // eax

result = *(_DWORD *)(a1 + 16) - 1;
*(_DWORD *)(a1 + 16) = result;
if ( !result )
result = sem_post(*(sem_t **)(a1 + 8));
return result;
}

original_code:
static __inline__ void mm_unlock(struct mm_private *mm)
{
 if (--mm->lock)
  return;
 sem_post(mm->sem);
}


original_code:
struct mm_private *mm_create(const char *name, size_t static_size, size_t dynamic_size)
{
 struct mm_private *ret;
 int unlock = 0, unlink = 0;
 ret = malloc(sizeof(struct mm_private));
 if (((void *)0) == ret)
  return ((void *)0);
 ret->fd = -1;
 ret->lock = 0;
 do {
  ret->sem = sem_open(name, 0100, 0600, 1);
  if (((sem_t *) 0) == ret->sem)
   break;
  __mm_lock(ret);
  unlock = 1;
  ret->fd = shm_open(name, 0100 | 0200 | 02, 0600);
  if (-1 == ret->fd && 17 != (*__errno_location ()))
   break;
  if (-1 == ret->fd) {
   ret->fd = shm_open(name, 02, 0600);
   ret->mapped_size = sizeof(struct mm_shared);
   if (-1 == ret->fd)
    break;
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ret->mapped_size = sizeof(struct mm_shared) +
    ((struct mm_shared *)ret->area)->static_size +
    ((struct mm_shared *)ret->area)->dynamic_size;
   munmap(ret->area, sizeof(struct mm_shared));
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ret->init = 0;
  } else {
   ret->mapped_size = page_size(static_size + dynamic_size + sizeof(struct mm_shared));
   unlink = 1;
   if (-1 == ftruncate(ret->fd, ret->mapped_size))
    break;
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ((struct mm_shared *)ret->area)->static_size = static_size;
   ((struct mm_shared *)ret->area)->dynamic_size = ret->mapped_size -
    (sizeof(struct mm_shared) + static_size);
   do { ((struct mm_list_head *)mm_addr((ret), (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh))))->next = (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh)); ((struct mm_list_head *)mm_addr((ret), (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh))))->prev = (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh)); } while (0);
   ret->init = 1;
  }
  mm_unlock(ret);
  return ret;
 } while(0);
 if (-1 != ret->fd)
  close(ret->fd);
 if (unlink)
  shm_unlink(name);
 if (unlock)
  mm_unlock(ret);
 free(ret);
 return ((void *)0);
}

canonical_original_code:
struct mm_private *mm_create(char *name, unsigned long static_size, unsigned long dynamic_size)
{
 struct mm_private *ret;
 int unlock = 0; int unlink = 0;
 ret = malloc(sizeof(struct mm_private));
 if (((void *)0) == ret)
  return ((void *)0);
 ret->fd = -1;
 ret->lock = 0;
 do {
  ret->sem = sem_open(name, 0100, 0600, 1);
  if (((union sem_t *) 0) == ret->sem)
   break;
  __mm_lock(ret);
  unlock = 1;
  ret->fd = shm_open(name, 0100 | 0200 | 02, 0600);
  if (-1 == ret->fd && 17 != (*__errno_location ()))
   break;
  if (-1 == ret->fd) {
   ret->fd = shm_open(name, 02, 0600);
   ret->mapped_size = sizeof(struct mm_shared);
   if (-1 == ret->fd)
    break;
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ret->mapped_size = sizeof(struct mm_shared) +
    ((struct mm_shared *)ret->area)->static_size +
    ((struct mm_shared *)ret->area)->dynamic_size;
   munmap(ret->area, sizeof(struct mm_shared));
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ret->init = 0;
  } else {
   ret->mapped_size = page_size(static_size + dynamic_size + sizeof(struct mm_shared));
   unlink = 1;
   if (-1 == ftruncate(ret->fd, ret->mapped_size))
    break;
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ((struct mm_shared *)ret->area)->static_size = static_size;
   ((struct mm_shared *)ret->area)->dynamic_size = ret->mapped_size -
    (sizeof(struct mm_shared) + static_size);
   do { ((struct mm_list_head *)mm_addr((ret), (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh))))->next = (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh)); ((struct mm_list_head *)mm_addr((ret), (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh))))->prev = (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh)); } while (0);
   ret->init = 1;
  }
  mm_unlock(ret);
  return ret;
 } while(0);
 if (-1 != ret->fd)
  close(ret->fd);
 if (unlink)
  shm_unlink(name);
 if (unlock)
  mm_unlock(ret);
 free(ret);
 return ((void *)0);
}

variable_types:
name
char *

variable_types: unlock int

variable_types: unlink int

return_type: struct mm_private { int fd; union sem_t { char __size[32]; long __align; } *sem; int lock; char *area; unsigned long mapped_size; int init; } *

user_defined_types: struct mm_shared { unsigned long static_size; unsigned long dynamic_size; struct mm_list_head lh; }


original_code:
void mm_lock(struct mm_private *mm)
{
 size_t mm_size;
 if (mm->lock++)
  return;
 sem_wait(mm->sem);
 mm_size = sizeof(struct mm_shared) +
  ((struct mm_shared *)mm->area)->static_size +
  ((struct mm_shared *)mm->area)->dynamic_size;
 if (mm_size <= mm->mapped_size)
  return;
 munmap(mm->area, mm->mapped_size);
 mm->mapped_size = mm_size;
 mm->area = mm_map(mm);
}

canonical_original_code:
void mm_lock(struct mm_private *mm)
{
 unsigned long mm_size;
 if (mm->lock++)
  return;
 sem_wait(mm->sem);
 mm_size = sizeof(struct mm_shared) +
  ((struct mm_shared *)mm->area)->static_size +
  ((struct mm_shared *)mm->area)->dynamic_size;
 if (mm_size <= mm->mapped_size)
  return;
 munmap(mm->area, mm->mapped_size);
 mm->mapped_size = mm_size;
 mm->area = mm_map(mm);
}


original_code:
int mm_extend(struct mm_private *mm, size_t size)
{
 size_t mm_size;
 struct mm_shared shr = *(struct mm_shared *)mm->area;
 if (!size)
  return 0;
 mm_lock(mm);
 mm_size = mm->mapped_size + size;
 if (-1 == ftruncate(mm->fd, mm_size)) {
  mm_unlock(mm);
  return 1;
 }
 munmap(mm->area, mm->mapped_size);
 mm->mapped_size = mm_size;
 mm->area = mm_map(mm);
 ((struct mm_shared *)mm->area)->static_size = shr.static_size;
 ((struct mm_shared *)mm->area)->dynamic_size = mm->mapped_size -
  (sizeof(struct mm_shared) + shr.static_size);
 ((struct mm_shared *)mm->area)->lh = shr.lh;
 mm_unlock(mm);
 return 0;
}

canonical_original_code:
int mm_extend(struct mm_private *mm, unsigned long size)
{
 unsigned long mm_size;
 struct mm_shared shr = *(struct mm_shared *)mm->area;
 if (!size)
  return 0;
 mm_lock(mm);
 mm_size = mm->mapped_size + size;
 if (-1 == ftruncate(mm->fd, mm_size)) {
  mm_unlock(mm);
  return 1;
 }
 munmap(mm->area, mm->mapped_size);
 mm->mapped_size = mm_size;
 mm->area = mm_map(mm);
 ((struct mm_shared *)mm->area)->static_size = shr.static_size;
 ((struct mm_shared *)mm->area)->dynamic_size = mm->mapped_size -
  (sizeof(struct mm_shared) + shr.static_size);
 ((struct mm_shared *)mm->area)->lh = shr.lh;
 mm_unlock(mm);
 return 0;
}

variable_types: struct mm_shared { unsigned long static_size; unsigned long dynamic_size; struct mm_list_head { unsigned int prev; } lh; }


original_code:
static int if_build_ip_list(const struct sockaddr_nl *who, const struct nlmsghdr *n,
  void *__arg)
{
 struct ifaddrmsg *ifa = ((void*)(((char*)n) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
 struct rtattr *rta_tb[(__IFA_MAX - 1)+1];
 struct build_ip_list_priv *arg = __arg;
 if (n->nlmsg_type != RTM_NEWADDR)
  return 0;
 if (n->nlmsg_len < ((sizeof(*ifa)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))
  return 0;
 if (arg->ifindex && arg->ifindex != ifa->ifa_index)
  return 0;
 parse_rtattr(rta_tb, (__IFA_MAX - 1), ((struct rtattr*)(((char*)(ifa)) + ( ((sizeof(struct ifaddrmsg))+4U -1) & ~(4U -1) ))), n->nlmsg_len - ((sizeof(*ifa)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))));
 if (rta_tb[IFA_LOCAL]) {
  struct if_addr *addr;
  addr = malloc(sizeof(*addr));
  if (addr == ((void *)0))
   return 0;
  addr->ifindex = ifa->ifa_index;
  addr->af = ifa->ifa_family;
  addr->inet = *(struct in_addr *)((void*)(((char*)(rta_tb[IFA_LOCAL])) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
  addr->prefixlen = ifa->ifa_prefixlen;
  list_add_tail(&addr->lh, arg->lh);
 }
 return 0;
}

canonical_original_code:
static int if_build_ip_list(struct sockaddr_nl *who, struct nlmsghdr *n, void *__arg)
{
 struct ifaddrmsg *ifa = ((void*)(((char*)n) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
 struct rtattr *rta_tb[-1];
 struct build_ip_list_priv *arg = __arg;
 if (n->nlmsg_type != RTM_NEWADDR)
  return 0;
 if (n->nlmsg_len < ((sizeof(*ifa)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))
  return 0;
 if (arg->ifindex && arg->ifindex != ifa->ifa_index)
  return 0;
 parse_rtattr(rta_tb, (__IFA_MAX - 1), ((struct rtattr *)(((char *)(ifa)) + ( ((sizeof(struct ifaddrmsg))+4U -1) & ~(4U -1) ))), n->nlmsg_len - ((sizeof(*ifa)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))));
 if (rta_tb[IFA_LOCAL]) {
  struct if_addr *addr;
  addr = malloc(sizeof(*addr));
  if (addr == ((void *)0))
   return 0;
  addr->ifindex = ifa->ifa_index;
  addr->af = ifa->ifa_family;
  addr->inet = *(struct in_addr *)((void *)(((char *)(rta_tb[IFA_LOCAL])) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
  addr->prefixlen = ifa->ifa_prefixlen;
  list_add_tail(&addr->lh, arg->lh);
 }
 return 0;
}

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } *

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types: struct ifaddrmsg { unsigned char ifa_family; unsigned char ifa_prefixlen; unsigned char ifa_flags; unsigned char ifa_scope; unsigned int ifa_index; } *

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *[-1]

variable_types: struct build_ip_list_priv { struct list_head { struct list_head *next; } *lh; int ifindex; } *

variable_types: struct if_addr { struct list_head { struct list_head *next; } lh; int ifindex; int af; struct in_addr { unsigned int s_addr; } inet; int prefixlen; } *

user_defined_types: struct build_ip_list_priv { struct list_head *lh; int ifindex; }

user_defined_types: struct if_addr { struct list_head lh; int ifindex; int af; struct in_addr inet; int prefixlen; }