setMonitorPosition

decompiled_code:
unsigned __int64 __fastcall setMonitorPosition(unsigned __int64 *a1, signed int a2, int a3, int a4, int a5, double a6)
{
_DWORD *v6; // rbx
__int64 v7; // rbp
int v8; // eax
bool v9; // cl
__int64 v10; // rsi
__int64 v12; // rbp
unsigned __int64 *v13; // rdx
_DWORD *v14; // rcx
unsigned int v15; // er12
int v16; // er8
int v17; // edi
unsigned int v18; // er13
int v19; // er9
int v20; // er10
_DWORD *v21; // rax
int v22; // ebx
int v23; // esi
unsigned int v24; // esi
int v25; // er11
int v26; // eax
unsigned int v27; // eax
signed int v28; // edx
signed int v29; // esi
signed int v30; // er11
signed int v31; // ebx
signed int v32; // eax
bool v33; // cc
double v34; // xmm0_8
double v35; // xmm0_8
double v36; // xmm0_8
double v37; // xmm0_8
unsigned __int64 result; // rax
int v39; // ebp
int v40; // er10
int v41; // er9
signed int v42; // esi
signed int v43; // edx
signed int v44; // ecx
signed int v45; // eax
__int64 v48; // [rsp+20h] [rbp-88h]
unsigned int v49; // [rsp+30h] [rbp-78h]
unsigned __int64 *v51; // [rsp+38h] [rbp-70h]
int v52; // [rsp+60h] [rbp-48h] BYREF
int v53; // [rsp+64h] [rbp-44h] BYREF
int v54; // [rsp+68h] [rbp-40h] BYREF
int v55[15]; // [rsp+6Ch] [rbp-3Ch] BYREF

v6 = (_DWORD *)a1[a3];
v51 = &a1[a3];
v6[5] = a4;
v6[6] = a5;
if ( a2 > 0 )
{
v7 = 1LL;
do
{
while ( 1 )
{
v10 = a1[v7 - 1];
if ( v6 == (_DWORD *)v10 || !v10 )
break;
v8 = doesOverlap(v6, v10);
v9 = a2 > (int)v7++;
if ( v8 != 0 || !v9 )
goto LABEL_7;
}
v8 = 0;
}
while ( a2 > (int)v7++ );
LABEL_7:
if ( v8 == 1 )
{
*v51 = 0LL;
getBoundingRectangle(a1, a2, &v52, &v53, &v54, v55);
v39 = v55[0];
v40 = v6[8];
*v51 = (unsigned __int64)v6;
v41 = v6[7];
v42 = abs32(v39 - v6[6]);
v43 = abs32(v40 + v6[6] - v53);
v44 = abs32(v41 + v6[5] - v52);
v45 = abs32(v54 - v6[5]);
if ( v45 > v42 )
v45 = v42;
if ( v45 > v43 )
v45 = v43;
if ( v44 <= v45 )
{
v6[5] = v52 - v41 - 1;
}
else if ( v43 == v45 )
{
v6[6] = v53 - v40 - 1;
}
else if ( v42 == v45 )
{
v6[6] = v39 + 1;
}
else
{
v6[5] = v54 + 1;
}
}
v12 = 0LL;
while ( 1 )
{
while ( 1 )
{
v13 = a1;
v49 = v12;
v14 = (_DWORD *)a1[v12];
if ( v14 )
break;
if ( a2 == ++v12 )
goto LABEL_50;
}
v48 = v12;
v15 = v14[5];
v16 = 0;
v17 = 0;
v18 = v14[6];
v19 = 0;
v20 = 0;
do
{
v21 = (_DWORD *)*v13;
if ( v14 != (_DWORD *)*v13 && v21 )
{
v22 = v21[5];
v23 = v22 + v21[7];
if ( !v20 || (int)abs32(v23 - v15) < (int)abs32(v20) )
v20 = v15 - v23;
v24 = v15 + v14[7];
if ( !v17 || (int)abs32(v22 - v24) < (int)abs32(v17) )
v17 = v22 - v24;
v25 = v21[6];
v26 = v25 + v21[8];
if ( !v19 || (int)abs32(v26 - v18) < (int)abs32(v19) )
v19 = v18 - v26;
v27 = v18 + v14[8];
if ( !v16 || (int)abs32(v25 - v27) < (int)abs32(v16) )
v16 = v25 - v27;
}
++v13;
}
while ( &a1[a2] != v13 );
v28 = abs32(v17);
v29 = abs32(v16);
v30 = abs32(v19);
v31 = abs32(v20);
v32 = v29;
if ( v28 <= v29 )
v32 = v28;
if ( v32 > v30 )
v32 = v30;
v33 = v31 <= v32;
if ( v31 <= v32 )
v32 = v31;
if ( !v33 )
{
v34 = (double)(int)v14[7] * a6;
if ( v20 < 0 )
{
if ( v34 <= (double)-v20 )
goto LABEL_37;
goto LABEL_53;
}
if ( v34 <= (double)v20 )
goto LABEL_37;
}
if ( !v20 )
goto LABEL_37;
LABEL_53:
v15 = v15 - v20 + 1;
v14[5] = v15;
LABEL_37:
if ( v30 != v32 )
{
v35 = (double)(int)v14[8] * a6;
if ( v19 < 0 )
{
if ( v35 <= (double)-v19 )
goto LABEL_41;
goto LABEL_55;
}
if ( v35 <= (double)v19 )
goto LABEL_41;
}
if ( !v19 )
goto LABEL_41;
LABEL_55:
v18 = v18 - v19 + 1;
v14[6] = v18;
LABEL_41:
if ( v29 != v32 )
{
v36 = (double)(int)v14[8] * a6;
if ( v16 < 0 )
{
if ( v36 <= (double)-v16 )
goto LABEL_45;
goto LABEL_57;
}
if ( v36 <= (double)v16 )
goto LABEL_45;
}
if ( !v16 )
goto LABEL_45;
LABEL_57:
v18 = v16 + v18 - 1;
v14[6] = v18;
LABEL_45:
if ( v28 == v32 )
goto LABEL_48;
v37 = (double)(int)v14[7] * a6;
if ( v17 >= 0 )
{
if ( v37 <= (double)v17 )
goto LABEL_49;
LABEL_48:
if ( v17 )
goto LABEL_59;
goto LABEL_49;
}
if ( v37 > (double)-v17 )
{
LABEL_59:
v15 = v17 + v15 - 1;
v14[5] = v15;
}
LABEL_49:
++v12;
printf(" Monitor %d final position: x = %d y = %d\n", v49, v15, v18);
if ( a2 == v48 + 1 )
{
LABEL_50:
v6 = (_DWORD *)*v51;
break;
}
}
}
*v51 = 0LL;
result = getBoundingRectangle(a1, a2, &v52, &v53, &v54, v55);
*v51 = (unsigned __int64)v6;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(unsigned __int64 *a1, signed int a2, int a3, int a4, int a5, double a6)
{
_DWORD *v6; // rbx
__int64 v7; // rbp
int v8; // eax
bool v9; // cl
__int64 v10; // rsi
__int64 v12; // rbp
unsigned __int64 *v13; // rdx
_DWORD *v14; // rcx
unsigned int v15; // er12
int v16; // er8
int v17; // edi
unsigned int v18; // er13
int v19; // er9
int v20; // er10
_DWORD *v21; // rax
int v22; // ebx
int v23; // esi
unsigned int v24; // esi
int v25; // er11
int v26; // eax
unsigned int v27; // eax
signed int v28; // edx
signed int v29; // esi
signed int v30; // er11
signed int v31; // ebx
signed int v32; // eax
bool v33; // cc
double v34; // xmm0_8
double v35; // xmm0_8
double v36; // xmm0_8
double v37; // xmm0_8
unsigned __int64 result; // rax
int v39; // ebp
int v40; // er10
int v41; // er9
signed int v42; // esi
signed int v43; // edx
signed int v44; // ecx
signed int v45; // eax
__int64 v48; // [rsp+20h] [rbp-88h]
unsigned int v49; // [rsp+30h] [rbp-78h]
unsigned __int64 *v51; // [rsp+38h] [rbp-70h]
int v52; // [rsp+60h] [rbp-48h] BYREF
int v53; // [rsp+64h] [rbp-44h] BYREF
int v54; // [rsp+68h] [rbp-40h] BYREF
int v55[15]; // [rsp+6Ch] [rbp-3Ch] BYREF

v6 = (_DWORD *)a1[a3];
v51 = &a1[a3];
v6[5] = a4;
v6[6] = a5;
if ( a2 > 0 )
{
v7 = 1LL;
do
{
while ( 1 )
{
v10 = a1[v7 - 1];
if ( v6 == (_DWORD *)v10 || !v10 )
break;
v8 = func6(v6, v10);
v9 = a2 > (int)v7++;
if ( v8 != 0 || !v9 )
goto LABEL_7;
}
v8 = 0;
}
while ( a2 > (int)v7++ );
LABEL_7:
if ( v8 == 1 )
{
*v51 = 0LL;
func2(a1, a2, &v52, &v53, &v54, v55);
v39 = v55[0];
v40 = v6[8];
*v51 = (unsigned __int64)v6;
v41 = v6[7];
v42 = abs32(v39 - v6[6]);
v43 = abs32(v40 + v6[6] - v53);
v44 = abs32(v41 + v6[5] - v52);
v45 = abs32(v54 - v6[5]);
if ( v45 > v42 )
v45 = v42;
if ( v45 > v43 )
v45 = v43;
if ( v44 <= v45 )
{
v6[5] = v52 - v41 - 1;
}
else if ( v43 == v45 )
{
v6[6] = v53 - v40 - 1;
}
else if ( v42 == v45 )
{
v6[6] = v39 + 1;
}
else
{
v6[5] = v54 + 1;
}
}
v12 = 0LL;
while ( 1 )
{
while ( 1 )
{
v13 = a1;
v49 = v12;
v14 = (_DWORD *)a1[v12];
if ( v14 )
break;
if ( a2 == ++v12 )
goto LABEL_50;
}
v48 = v12;
v15 = v14[5];
v16 = 0;
v17 = 0;
v18 = v14[6];
v19 = 0;
v20 = 0;
do
{
v21 = (_DWORD *)*v13;
if ( v14 != (_DWORD *)*v13 && v21 )
{
v22 = v21[5];
v23 = v22 + v21[7];
if ( !v20 || (int)abs32(v23 - v15) < (int)abs32(v20) )
v20 = v15 - v23;
v24 = v15 + v14[7];
if ( !v17 || (int)abs32(v22 - v24) < (int)abs32(v17) )
v17 = v22 - v24;
v25 = v21[6];
v26 = v25 + v21[8];
if ( !v19 || (int)abs32(v26 - v18) < (int)abs32(v19) )
v19 = v18 - v26;
v27 = v18 + v14[8];
if ( !v16 || (int)abs32(v25 - v27) < (int)abs32(v16) )
v16 = v25 - v27;
}
++v13;
}
while ( &a1[a2] != v13 );
v28 = abs32(v17);
v29 = abs32(v16);
v30 = abs32(v19);
v31 = abs32(v20);
v32 = v29;
if ( v28 <= v29 )
v32 = v28;
if ( v32 > v30 )
v32 = v30;
v33 = v31 <= v32;
if ( v31 <= v32 )
v32 = v31;
if ( !v33 )
{
v34 = (double)(int)v14[7] * a6;
if ( v20 < 0 )
{
if ( v34 <= (double)-v20 )
goto LABEL_37;
goto LABEL_53;
}
if ( v34 <= (double)v20 )
goto LABEL_37;
}
if ( !v20 )
goto LABEL_37;
LABEL_53:
v15 = v15 - v20 + 1;
v14[5] = v15;
LABEL_37:
if ( v30 != v32 )
{
v35 = (double)(int)v14[8] * a6;
if ( v19 < 0 )
{
if ( v35 <= (double)-v19 )
goto LABEL_41;
goto LABEL_55;
}
if ( v35 <= (double)v19 )
goto LABEL_41;
}
if ( !v19 )
goto LABEL_41;
LABEL_55:
v18 = v18 - v19 + 1;
v14[6] = v18;
LABEL_41:
if ( v29 != v32 )
{
v36 = (double)(int)v14[8] * a6;
if ( v16 < 0 )
{
if ( v36 <= (double)-v16 )
goto LABEL_45;
goto LABEL_57;
}
if ( v36 <= (double)v16 )
goto LABEL_45;
}
if ( !v16 )
goto LABEL_45;
LABEL_57:
v18 = v16 + v18 - 1;
v14[6] = v18;
LABEL_45:
if ( v28 == v32 )
goto LABEL_48;
v37 = (double)(int)v14[7] * a6;
if ( v17 >= 0 )
{
if ( v37 <= (double)v17 )
goto LABEL_49;
LABEL_48:
if ( v17 )
goto LABEL_59;
goto LABEL_49;
}
if ( v37 > (double)-v17 )
{
LABEL_59:
v15 = v17 + v15 - 1;
v14[5] = v15;
}
LABEL_49:
++v12;
printf(" Monitor %d final position: x = %d y = %d\n", v49, v15, v18);
if ( a2 == v48 + 1 )
{
LABEL_50:
v6 = (_DWORD *)*v51;
break;
}
}
}
*v51 = 0LL;
result = func2(a1, a2, &v52, &v53, &v54, v55);
*v51 = (unsigned __int64)v6;
return result;
}

original_code:
void setMonitorPosition( Monitor *mon[], int monLen, int numMon, int x, int y, double threshold )
{
 int i;
 int left, top, right, bottom;
 Monitor *monTemp;
 boolean overlapping;
 mon[numMon]->x = x;
 mon[numMon]->y = y;
 i = 0;
 overlapping = FALSE;
 while( i < monLen && overlapping == FALSE )
 {
  if( mon[i] != ((void *)0) && mon[i] != mon[numMon] )
  {
   overlapping = doesOverlap( mon[numMon], mon[i] );
  }
  i++;
 }
 if( overlapping == TRUE )
 {
  int dleft, dtop, dright, dbot;
  monTemp = mon[numMon];
  mon[numMon] = ((void *)0);
  getBoundingRectangle( mon, monLen, &left, &top, &right, &bottom );
  mon[numMon] = monTemp;
  dleft = mon[numMon]->x + mon[numMon]->width - left;
  dtop = mon[numMon]->y + mon[numMon]->height - top;
  dright = right - mon[numMon]->x;
  dbot = bottom - mon[numMon]->y;
  if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dright)<0?-(dright):(dright)))<(((dbot)<0?-(dbot):(dbot)))?(((dright)<0?-(dright):(dright))):(((dbot)<0?-(dbot):(dbot))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dright)<0?-(dright):(dright)))<(((dbot)<0?-(dbot):(dbot)))?(((dright)<0?-(dright):(dright))):(((dbot)<0?-(dbot):(dbot))))) == ((dleft)<0?-(dleft):(dleft)) )
  {
   mon[numMon]->x = left - mon[numMon]->width - 1;
  }
  else if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dtop)<0?-(dtop):(dtop)) )
  {
   mon[numMon]->y = top - mon[numMon]->height - 1;
  }
  else if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dbot)<0?-(dbot):(dbot)) )
  {
   mon[numMon]->y = bottom + 1;
  }
  else
  {
   mon[numMon]->x = right + 1;
  }
 }
 for( i = 0; i < monLen; i++ )
 {
  int dleft, dtop, dright, dbot, j;
  dleft = dtop = dright = dbot = 0;
  if( mon[i] != ((void *)0) )
  {
   for( j = 0; j < monLen; j++ )
   {
    if( mon[j] != ((void *)0) && mon[j] != mon[i] )
    {
     if( dleft == 0 || ((mon[j]->x + mon[j]->width - mon[i]->x)<0?-(mon[j]->x + mon[j]->width - mon[i]->x):(mon[j]->x + mon[j]->width - mon[i]->x)) < ((dleft)<0?-(dleft):(dleft)) )
     {
      dleft = mon[i]->x - ( mon[j]->x + mon[j]->width );
     }
     if( dright == 0 || ((mon[j]->x - ( mon[i]->x + mon[i]->width ))<0?-(mon[j]->x - ( mon[i]->x + mon[i]->width )):(mon[j]->x - ( mon[i]->x + mon[i]->width ))) < ((dright)<0?-(dright):(dright)) )
     {
      dright = mon[j]->x - ( mon[i]->x + mon[i]->width );
     }
     if( dtop == 0 || ((mon[j]->y + mon[j]->height - mon[i]->y)<0?-(mon[j]->y + mon[j]->height - mon[i]->y):(mon[j]->y + mon[j]->height - mon[i]->y)) < ((dtop)<0?-(dtop):(dtop)) )
     {
      dtop = mon[i]->y - ( mon[j]->y + mon[j]->height );
     }
     if( dbot == 0 || ((mon[j]->y - (mon[i]->y + mon[i]->height ))<0?-(mon[j]->y - (mon[i]->y + mon[i]->height )):(mon[j]->y - (mon[i]->y + mon[i]->height ))) < ((dbot)<0?-(dbot):(dbot)) )
     {
      dbot = mon[j]->y - ( mon[i]->y + mon[i]->height );
     }
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dleft)<0?-(dleft):(dleft)) || ((dleft)<0?-(dleft):(dleft)) < mon[i]->width * threshold )
   {
    if( dleft != 0 )
    {
     mon[i]->x = mon[i]->x - dleft + 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dtop)<0?-(dtop):(dtop)) || ((dtop)<0?-(dtop):(dtop)) < mon[i]->height * threshold )
   {
    if( dtop != 0 )
    {
     mon[i]->y = mon[i]->y - dtop + 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dbot)<0?-(dbot):(dbot)) || ((dbot)<0?-(dbot):(dbot)) < mon[i]->height * threshold )
   {
    if( dbot != 0 )
    {
     mon[i]->y = mon[i]->y + dbot - 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dright)<0?-(dright):(dright)) || ((dright)<0?-(dright):(dright)) < mon[i]->width * threshold )
   {
    if( dright != 0 )
    {
     mon[i]->x = mon[i]->x + dright - 1;
    }
   }
   printf(" Monitor %d final position: x = %d y = %d\n", i, mon[i]->x, mon[i]->y );
  }
 }
 monTemp = mon[numMon];
 mon[numMon] = ((void *)0);
 getBoundingRectangle( mon, monLen, &left, &top, &right, &bottom );
 mon[numMon] = monTemp;
}

canonical_original_code:
void setMonitorPosition(struct Monitor *mon[], int monLen, int numMon, int x, int y, double threshold)
{
 int i;
 int left; int top; int right; int bottom;
 struct Monitor *monTemp;
 enum boolean overlapping;
 mon[numMon]->x = x;
 mon[numMon]->y = y;
 i = 0;
 overlapping = FALSE;
 while( i < monLen && overlapping == FALSE )
 {
  if( mon[i] != ((void *)0) && mon[i] != mon[numMon] )
  {
   overlapping = doesOverlap( mon[numMon], mon[i] );
  }
  i++;
 }
 if( overlapping == TRUE )
 {
  int dleft; int dtop; int dright; int dbot;
  monTemp = mon[numMon];
  mon[numMon] = ((void *)0);
  getBoundingRectangle( mon, monLen, &left, &top, &right, &bottom );
  mon[numMon] = monTemp;
  dleft = mon[numMon]->x + mon[numMon]->width - left;
  dtop = mon[numMon]->y + mon[numMon]->height - top;
  dright = right - mon[numMon]->x;
  dbot = bottom - mon[numMon]->y;
  if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dright)<0?-(dright):(dright)))<(((dbot)<0?-(dbot):(dbot)))?(((dright)<0?-(dright):(dright))):(((dbot)<0?-(dbot):(dbot))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dright)<0?-(dright):(dright)))<(((dbot)<0?-(dbot):(dbot)))?(((dright)<0?-(dright):(dright))):(((dbot)<0?-(dbot):(dbot))))) == ((dleft)<0?-(dleft):(dleft)) )
  {
   mon[numMon]->x = left - mon[numMon]->width - 1;
  }
  else if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dtop)<0?-(dtop):(dtop)) )
  {
   mon[numMon]->y = top - mon[numMon]->height - 1;
  }
  else if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dbot)<0?-(dbot):(dbot)) )
  {
   mon[numMon]->y = bottom + 1;
  }
  else
  {
   mon[numMon]->x = right + 1;
  }
 }
 for( i = 0; i < monLen; i++ )
 {
  int dleft; int dtop; int dright; int dbot; int j;
  dleft = dtop = dright = dbot = 0;
  if( mon[i] != ((void *)0) )
  {
   for( j = 0; j < monLen; j++ )
   {
    if( mon[j] != ((void *)0) && mon[j] != mon[i] )
    {
     if( dleft == 0 || ((mon[j]->x + mon[j]->width - mon[i]->x)<0?-(mon[j]->x + mon[j]->width - mon[i]->x):(mon[j]->x + mon[j]->width - mon[i]->x)) < ((dleft)<0?-(dleft):(dleft)) )
     {
      dleft = mon[i]->x - ( mon[j]->x + mon[j]->width );
     }
     if( dright == 0 || ((mon[j]->x - ( mon[i]->x + mon[i]->width ))<0?-(mon[j]->x - ( mon[i]->x + mon[i]->width )):(mon[j]->x - ( mon[i]->x + mon[i]->width ))) < ((dright)<0?-(dright):(dright)) )
     {
      dright = mon[j]->x - ( mon[i]->x + mon[i]->width );
     }
     if( dtop == 0 || ((mon[j]->y + mon[j]->height - mon[i]->y)<0?-(mon[j]->y + mon[j]->height - mon[i]->y):(mon[j]->y + mon[j]->height - mon[i]->y)) < ((dtop)<0?-(dtop):(dtop)) )
     {
      dtop = mon[i]->y - ( mon[j]->y + mon[j]->height );
     }
     if( dbot == 0 || ((mon[j]->y - (mon[i]->y + mon[i]->height ))<0?-(mon[j]->y - (mon[i]->y + mon[i]->height )):(mon[j]->y - (mon[i]->y + mon[i]->height ))) < ((dbot)<0?-(dbot):(dbot)) )
     {
      dbot = mon[j]->y - ( mon[i]->y + mon[i]->height );
     }
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dleft)<0?-(dleft):(dleft)) || ((dleft)<0?-(dleft):(dleft)) < mon[i]->width * threshold )
   {
    if( dleft != 0 )
    {
     mon[i]->x = mon[i]->x - dleft + 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dtop)<0?-(dtop):(dtop)) || ((dtop)<0?-(dtop):(dtop)) < mon[i]->height * threshold )
   {
    if( dtop != 0 )
    {
     mon[i]->y = mon[i]->y - dtop + 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dbot)<0?-(dbot):(dbot)) || ((dbot)<0?-(dbot):(dbot)) < mon[i]->height * threshold )
   {
    if( dbot != 0 )
    {
     mon[i]->y = mon[i]->y + dbot - 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dright)<0?-(dright):(dright)) || ((dright)<0?-(dright):(dright)) < mon[i]->width * threshold )
   {
    if( dright != 0 )
    {
     mon[i]->x = mon[i]->x + dright - 1;
    }
   }
   printf(" Monitor %d final position: x = %d y = %d\n", i, mon[i]->x, mon[i]->y );
  }
 }
 monTemp = mon[numMon];
 mon[numMon] = ((void *)0);
 getBoundingRectangle( mon, monLen, &left, &top, &right, &bottom );
 mon[numMon] = monTemp;
}

variable_types: numMon int

variable_types: threshold double

variable_types: left int

variable_types: top int

variable_types: right int

variable_types: bottom int

variable_types:
overlapping
enum boolean { FALSE=0, TRUE=1 }

variable_types: dleft int

variable_types: dtop int

variable_types: dright int

variable_types: dbot int

variable_types: j int


setMonitorDimensions

repo: timpeskett/nmuw

decompiled_code:
unsigned __int64 __fastcall setMonitorDimensions(unsigned __int64 *a1, signed int a2, int a3, int a4, int a5, double a6)
{
_DWORD *v6; // rax
int v7; // ecx

v6 = (_DWORD *)a1[a3];
v6[7] = a4;
v7 = v6[5];
v6[8] = a5;
return setMonitorPosition(a1, a2, a3, v7, v6[6], a6);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned __int64 *a1, signed int a2, int a3, int a4, int a5, double a6)
{
_DWORD *v6; // rax
int v7; // ecx

v6 = (_DWORD *)a1[a3];
v6[7] = a4;
v7 = v6[5];
v6[8] = a5;
return func7(a1, a2, a3, v7, v6[6], a6);
}

original_code:
void setMonitorDimensions( Monitor *mon[], int monLen, int numMon, int width, int height, double threshold )
{
 mon[numMon]->width = width;
 mon[numMon]->height = height;
 setMonitorPosition( mon, monLen, numMon, mon[numMon]->x, mon[numMon]->y, threshold );
}

canonical_original_code:
void setMonitorDimensions(struct Monitor *mon[], int monLen, int numMon, int width, int height, double threshold)
{
 mon[numMon]->width = width;
 mon[numMon]->height = height;
 setMonitorPosition( mon, monLen, numMon, mon[numMon]->x, mon[numMon]->y, threshold );
}

variable_types: struct Monitor { int sockfd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr; int addr_size; int x; int width; struct { unsigned long wnd; char *wndName; } *procs; int numProcs; } *[]

variable_types: monLen int

variable_types: width int

variable_types: height int

return_type: void

user_defined_types: struct Monitor { int sockfd; struct sockaddr *addr; int addr_size; int x; int width; struct { unsigned long wnd; char *wndName; } *procs; int numProcs; }


monitorPosToPointerPos

decompiled_code:
__int64 __fastcall monitorPosToPointerPos(_DWORD **a1, unsigned int a2, int *a3, int *a4)
{
__int64 result; // rax
int v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8; // [rsp+4h] [rbp-2Ch] BYREF
int v9; // [rsp+8h] [rbp-28h] BYREF
int v10[9]; // [rsp+Ch] [rbp-24h] BYREF

result = getMonitorFromPoint(a1, a2, *a3, *a4);
if ( (_DWORD)result == -1 )
{
*a4 = -1;
*a3 = -1;
}
else
{
getMonitorPosition((__int64)a1, a2, result, &v7, &v8, &v9, v10);
*a3 -= v7;
result = v8;
*a4 -= v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD **a1, unsigned int a2, int *a3, int *a4)
{
__int64 result; // rax
int v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8; // [rsp+4h] [rbp-2Ch] BYREF
int v9; // [rsp+8h] [rbp-28h] BYREF
int v10[9]; // [rsp+Ch] [rbp-24h] BYREF

result = func5(a1, a2, *a3, *a4);
if ( (_DWORD)result == -1 )
{
*a4 = -1;
*a3 = -1;
}
else
{
func1((__int64)a1, a2, result, &v7, &v8, &v9, v10);
*a3 -= v7;
result = v8;
*a4 -= v8;
}
return result;
}

original_code:
void monitorPosToPointerPos( Monitor *mon[], int monLen, int *x, int *y )
{
 int monNum;
 monNum = getMonitorFromPoint( mon, monLen, *x, *y );
 if( monNum != -1 )
 {
  int left, top, right, bot;
  getMonitorPosition( mon, monLen, monNum, &left, &top, &right, &bot );
  *x -= left;
  *y -= top;
 }
 else
 {
  *x = *y = -1;
 }
}

canonical_original_code:
void monitorPosToPointerPos(struct Monitor *mon[], int monLen, int *x, int *y)
{
 int monNum;
 monNum = getMonitorFromPoint( mon, monLen, *x, *y );
 if( monNum != -1 )
 {
  int left; int top; int right; int bot;
  getMonitorPosition( mon, monLen, monNum, &left, &top, &right, &bot );
  *x -= left;
  *y -= top;
 }
 else
 {
  *x = *y = -1;
 }
}

variable_types:
x
int *

variable_types:
y
int *

variable_types: monNum int

variable_types: bot int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


connectMonitor

decompiled_code:
__int64 __fastcall connectMonitor(int *a1)
{
unsigned int v2; // eax
int v3; // edi

v2 = createSocket(2LL, 2LL);
*a1 = v2;
v3 = v2;
if ( v2 == -1 )
goto LABEL_4;
if ( (unsigned int)connectSocket(v2, *((_QWORD *)a1 + 1), (unsigned int)a1[4], 2000LL) != 1 )
{
v3 = *a1;
LABEL_4:
close(v3);
*a1 = -1;
return 0LL;
}
sendMsg((unsigned int)*a1, 9LL, 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1)
{
unsigned int v2; // eax
int v3; // edi

v2 = createSocket(2LL, 2LL);
*a1 = v2;
v3 = v2;
if ( v2 == -1 )
goto LABEL_4;
if ( (unsigned int)connectSocket(v2, *((_QWORD *)a1 + 1), (unsigned int)a1[4], 2000LL) != 1 )
{
v3 = *a1;
LABEL_4:
close(v3);
*a1 = -1;
return 0LL;
}
sendMsg((unsigned int)*a1, 9LL, 0LL);
return 1LL;
}

original_code:
boolean connectMonitor( Monitor *inMon )
{
 boolean success = FALSE;
 if( ( inMon->sockfd = createSocket( 2, SOCK_DGRAM ) ) != -1 )
 {
  if( connectSocket( inMon->sockfd, inMon->addr, inMon->addr_size, 2000 ) == TRUE )
  {
   sendMsg( inMon->sockfd, CONNECT, ((void *)0) );
   success = TRUE;
  }
 }
 if( success == FALSE )
 {
  close( inMon->sockfd );
  inMon->sockfd = -1;
 }
 return success;
}

canonical_original_code:
enum boolean connectMonitor(struct Monitor *inMon)
{
 enum boolean success = FALSE;
 if( ( inMon->sockfd = createSocket( 2, SOCK_DGRAM ) ) != -1 )
 {
  if( connectSocket( inMon->sockfd, inMon->addr, inMon->addr_size, 2000 ) == TRUE )
  {
   sendMsg( inMon->sockfd, CONNECT, ((void *)0) );
   success = TRUE;
  }
 }
 if( success == FALSE )
 {
  close( inMon->sockfd );
  inMon->sockfd = -1;
 }
 return success;
}

variable_types: struct Monitor { int sockfd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr; int addr_size; int x; int width; struct { unsigned long wnd; char *wndName; } *procs; int numProcs; } *

variable_types:
success
enum boolean { FALSE=0, TRUE=1 }

return_type: enum boolean { FALSE=0, TRUE=1 }


destroyMonitor

decompiled_code:
void __fastcall destroyMonitor(void *ptr)
{
__int64 v2; // rdi

if ( ptr )
{
v2 = *(unsigned int *)ptr;
if ( (_DWORD)v2 != -1 )
{
sendMsg(v2, 10LL, 0LL);
close(*(_DWORD *)ptr);
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 5));
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
__int64 v2; // rdi

if ( ptr )
{
v2 = *(unsigned int *)ptr;
if ( (_DWORD)v2 != -1 )
{
sendMsg(v2, 10LL, 0LL);
close(*(_DWORD *)ptr);
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 5));
}
free(ptr);
}

original_code:
void destroyMonitor( Monitor *inMon )
{
 if( inMon != ((void *)0) )
 {
  if( inMon->sockfd != -1 )
  {
   sendMsg( inMon->sockfd, DISCONNECT, ((void *)0) );
   close( inMon->sockfd );
   inMon->sockfd = -1;
  }
  free( inMon->addr );
  free( inMon->procs );
 }
 free( inMon );
}

canonical_original_code:
void destroyMonitor(struct Monitor *inMon)
{
 if( inMon != ((void *)0) )
 {
  if( inMon->sockfd != -1 )
  {
   sendMsg( inMon->sockfd, DISCONNECT, ((void *)0) );
   close( inMon->sockfd );
   inMon->sockfd = -1;
  }
  free( inMon->addr );
  free( inMon->procs );
 }
 free( inMon );
}


displayMonitorNumber

decompiled_code:
__int64 __fastcall displayMonitorNumber(unsigned int *a1, int a2, int a3)
{
__int64 v3; // rdi
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !a1 )
_assert_fail("inMon != NULL", "Monitor.c", 0x198u, "displayMonitorNumber");
v3 = *a1;
if ( a3 != 1 )
return sendMsg(v3, 8LL, 0LL);
v5[0] = a2;
return sendMsg(v3, 7LL, v5);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1, int a2, int a3)
{
__int64 v3; // rdi
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !a1 )
_assert_fail("inMon != NULL", "Monitor.c", 0x198u, "displayMonitorNumber");
v3 = *a1;
if ( a3 != 1 )
return sendMsg(v3, 8LL, 0LL);
v5[0] = a2;
return sendMsg(v3, 7LL, v5);
}

original_code:
void displayMonitorNumber( Monitor *inMon, int num, boolean display )
{
 MsgDisplayNum mdn;
 ((void) sizeof ((inMon != ((void *)0)) ? 1 : 0), __extension__ ({ if (inMon != ((void *)0)) ; else __assert_fail ("inMon != NULL", "Monitor.c", 408, __extension__ __PRETTY_FUNCTION__); }));
 if( display == TRUE )
 {
  mdn.monNum = num;
  sendMsg( inMon->sockfd, DISPLAYNUM, &mdn );
 }
 else
 {
  sendMsg( inMon->sockfd, STOPDISPLAYNUM, ((void *)0) );
 }
}

canonical_original_code:
void displayMonitorNumber(struct Monitor *inMon, int num, enum boolean display)
{
 struct MsgDisplayNum mdn;
 ((void) sizeof ((inMon != ((void *)0)) ? 1 : 0), __extension__ ({ if (inMon != ((void *)0)) ; else __assert_fail ("inMon != NULL", "Monitor.c", 408, __extension__ __PRETTY_FUNCTION__); }));
 if( display == TRUE )
 {
  mdn.monNum = num;
  sendMsg( inMon->sockfd, DISPLAYNUM, &mdn );
 }
 else
 {
  sendMsg( inMon->sockfd, STOPDISPLAYNUM, ((void *)0) );
 }
}

variable_types: num int

variable_types:
display
enum boolean { FALSE=0, TRUE=1 }

variable_types:
mdn
struct MsgDisplayNum { int monNum; }


countActiveMonitors

decompiled_code:
__int64 __fastcall countActiveMonitors(_QWORD *a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
LODWORD(result) = 0;
do
result = (unsigned int)result - ((*a1++ == 0LL) - 1);
while ( a1 != (_QWORD *)v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
LODWORD(result) = 0;
do
result = (unsigned int)result - ((*a1++ == 0LL) - 1);
while ( a1 != (_QWORD *)v2 );
return result;
}

original_code:
int countActiveMonitors( Monitor *mon[], int monLen )
{
 int i;
 int monCount = 0;
 for( i = 0; i < monLen; i++ )
 {
  if( mon[i] != ((void *)0) )
  {
   monCount++;
  }
 }
 return monCount;
}

canonical_original_code:
int countActiveMonitors(struct Monitor *mon[], int monLen)
{
 int i;
 int monCount = 0;
 for( i = 0; i < monLen; i++ )
 {
  if( mon[i] != ((void *)0) )
  {
   monCount++;
  }
 }
 return monCount;
}

variable_types: i int

variable_types: monCount int

return_type: int


printSerialData

decompiled_code:
int __fastcall printSerialData(_QWORD *a1, int a2, int a3)
{
int v3; // ebx
int v5; // esi
unsigned int v6; // edx
char v7; // al

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 5u, "printSerialData");
v3 = a2;
printf("Data = ");
if ( a2 <= a3 )
{
do
{
v5 = *(unsigned __int8 *)(*a1 + v3 / 8);
v6 = (unsigned int)(v3 >> 31) >> 29;
v7 = v3++ + v6;
printf("%d, ", (v5 >> (7 - ((v7 & 7) - v6))) & 1);
}
while ( a3 >= v3 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1, int a2, int a3)
{
int v3; // ebx
int v5; // esi
unsigned int v6; // edx
char v7; // al

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 5u, "printSerialData");
v3 = a2;
printf("Data = ");
if ( a2 <= a3 )
{
do
{
v5 = *(unsigned __int8 *)(*a1 + v3 / 8);
v6 = (unsigned int)(v3 >> 31) >> 29;
v7 = v3++ + v6;
printf("%d, ", (v5 >> (7 - ((v7 & 7) - v6))) & 1);
}
while ( a3 >= v3 );
}
return putchar(10);
}

original_code:
void printSerialData( SerialData *inSData, int lower, int upper )
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 5, __extension__ __PRETTY_FUNCTION__); }));
 printf( "Data = " );
 for(; lower <= upper; lower++ )
 {
  printf( "%d, ", ( !!( (inSData->sdata[lower/8]) & ( 1 << (7 - (lower % 8) ) ) ) ) );
 }
 printf("\n" );
}

canonical_original_code:
void printSerialData(struct SerialData *inSData, int lower, int upper)
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 5, __extension__ __PRETTY_FUNCTION__); }));
 printf( "Data = " );
 for(; lower <= upper; lower++ )
 {
  printf( "%d, ", ( !!( (inSData->sdata[lower/8]) & ( 1 << (7 - (lower % 8) ) ) ) ) );
 }
 printf("\n" );
}

variable_types: struct SerialData { unsigned char *sdata; short len; } *

variable_types: lower int

variable_types: upper int


isLittleEndian

decompiled_code:
__int64 isLittleEndian()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
boolean isLittleEndian( void )
{
 boolean littleEnd;
 uint16_t tester = 1;
 if( *(char*)&tester == 1 )
 {
  littleEnd = TRUE;
 }
 else
 {
  littleEnd = FALSE;
 }
 return littleEnd;
}

canonical_original_code:
enum boolean isLittleEndian()
{
 enum boolean littleEnd;
 unsigned short tester = 1;
 if( *(char *)&tester == 1 )
 {
  littleEnd = TRUE;
 }
 else
 {
  littleEnd = FALSE;
 }
 return littleEnd;
}

variable_types:
littleEnd
enum boolean { FALSE=0, TRUE=1 }

variable_types:
tester
unsigned short


bitsRequired

decompiled_code:
__int64 __fastcall bitsRequired(__int64 a1)
{
unsigned int v1; // er8
unsigned __int64 v2; // rax

v1 = a1 == 0;
v2 = abs64(a1);
if ( a1 )
{
do
{
++v1;
v2 >>= 1;
}
while ( v2 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // er8
unsigned __int64 v2; // rax

v1 = a1 == 0;
v2 = abs64(a1);
if ( a1 )
{
do
{
++v1;
v2 >>= 1;
}
while ( v2 );
}
return v1;
}

original_code:
int bitsRequired( int64_t inNum )
{
 int outBits = 0;
 uint64_t absNum;
 if( inNum == 0 )
 {
  outBits++;
 }
 absNum = ((inNum)<0?-(inNum):(inNum));
 for(; absNum > 0; absNum = absNum >> 1 )
 {
  outBits++;
 }
 return outBits;
}

canonical_original_code:
int bitsRequired(long inNum)
{
 int outBits = 0;
 unsigned long absNum;
 if( inNum == 0 )
 {
  outBits++;
 }
 absNum = ((inNum)<0?-(inNum):(inNum));
 for(; absNum > 0; absNum = absNum >> 1 )
 {
  outBits++;
 }
 return outBits;
}

variable_types: inNum long

variable_types: outBits int

variable_types:
absNum
unsigned long


decompiled_code:
unsigned __int64 __fastcall serialiseUInt8(__int64 a1, unsigned __int8 a2, int a3)
{
int v5; // eax
int v6; // ecx
_QWORD *v7; // r9
unsigned __int8 v8; // r11
int v9; // edi
int v10; // er10
unsigned __int64 result; // rax
int v12; // eax
unsigned int v13; // ecx
char v14; // dl
int v15; // er12
int v16; // eax
char v17; // cl

v5 = bitsRequired(a2);
if ( !v7 )
_assert_fail("inSData != NULL", "../serial.c", 0x4Eu, "serialiseUInt8");
v9 = v5;
v10 = v6;
result = (unsigned int)(v6 - a3);
if ( (int)result + 1 < v9 )
_assert_fail("upper - lower + 1 >= width", "../serial.c", 0x4Fu, "serialiseUInt8");
for ( ; v9 <= (int)result; result = (unsigned int)(v10 - a3) )
{
v12 = a3 + 7;
if ( a3 >= 0 )
v12 = a3;
v13 = (unsigned int)(a3 >> 31) >> 29;
v14 = a3++ + v13;
*(_BYTE *)(*v7 + (v12 >> 3)) &= ~(1 << (7 - ((v14 & 7) - v13)));
}
if ( v10 >= a3 )
{
do
{
v15 = 7 - a3 % 8;
v16 = a3 + 7;
if ( a3 >= 0 )
v16 = a3;
v17 = v10 - a3++;
result = *v7 + (v16 >> 3);
*(_BYTE *)result = ((((int)v8 >> v17) & 1) << v15) | *(_BYTE *)result & ~(1 << v15);
}
while ( a3 != v10 + 1 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, unsigned __int8 a2, int a3)
{
int v5; // eax
int v6; // ecx
_QWORD *v7; // r9
unsigned __int8 v8; // r11
int v9; // edi
int v10; // er10
unsigned __int64 result; // rax
int v12; // eax
unsigned int v13; // ecx
char v14; // dl
int v15; // er12
int v16; // eax
char v17; // cl

v5 = func2(a2);
if ( !v7 )
_assert_fail("inSData != NULL", "../serial.c", 0x4Eu, "serialiseUInt8");
v9 = v5;
v10 = v6;
result = (unsigned int)(v6 - a3);
if ( (int)result + 1 < v9 )
_assert_fail("upper - lower + 1 >= width", "../serial.c", 0x4Fu, "serialiseUInt8");
for ( ; v9 <= (int)result; result = (unsigned int)(v10 - a3) )
{
v12 = a3 + 7;
if ( a3 >= 0 )
v12 = a3;
v13 = (unsigned int)(a3 >> 31) >> 29;
v14 = a3++ + v13;
*(_BYTE *)(*v7 + (v12 >> 3)) &= ~(1 << (7 - ((v14 & 7) - v13)));
}
if ( v10 >= a3 )
{
do
{
v15 = 7 - a3 % 8;
v16 = a3 + 7;
if ( a3 >= 0 )
v16 = a3;
v17 = v10 - a3++;
result = *v7 + (v16 >> 3);
*(_BYTE *)result = ((((int)v8 >> v17) & 1) << v15) | *(_BYTE *)result & ~(1 << v15);
}
while ( a3 != v10 + 1 );
}
return result;
}

original_code:
void serialiseUInt8( SerialData *inSData, uint8_t inData, int lower, int upper )
{
 int width;
 width = bitsRequired( inData );
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= width) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= width) ; else __assert_fail ("upper - lower + 1 >= width", "../serial.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 for(; upper - lower + 1 > width; lower++ )
 {
  (inSData->sdata[lower / 8] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower / 8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 for(; lower <= upper; lower++ )
 {
  int curBit;
  curBit = ( !!( (inData) & ( 1 << (7 - (7 - ( upper - lower )) ) ) ) );
  (inSData->sdata[lower / 8] = ( (curBit) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower / 8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
}

canonical_original_code:
void serialiseUInt8(struct SerialData *inSData, unsigned char inData, int lower, int upper)
{
 int width;
 width = bitsRequired( inData );
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= width) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= width) ; else __assert_fail ("upper - lower + 1 >= width", "../serial.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 for(; upper - lower + 1 > width; lower++ )
 {
  (inSData->sdata[lower / 8] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower / 8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 for(; lower <= upper; lower++ )
 {
  int curBit;
  curBit = ( !!( (inData) & ( 1 << (7 - (7 - ( upper - lower )) ) ) ) );
  (inSData->sdata[lower / 8] = ( (curBit) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower / 8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
}

variable_types:
inData
unsigned char

variable_types: width int

variable_types: curBit int

user_defined_types: struct SerialData { unsigned char *sdata; short len; }


decompiled_code:
unsigned __int64 __fastcall serialiseInt8(__int64 a1, char a2)
{
int v2; // eax
int v3; // er9
_QWORD *v4; // r10
int v5; // ecx
_BYTE *v6; // rax
int v7; // ecx
char v8; // dl
char v9; // cl

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x3Bu, "serialiseInt8");
v2 = bitsRequired(a2);
if ( v5 < v2 )
_assert_fail("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 0x3Cu, "serialiseInt8");
v6 = (_BYTE *)(*v4 + v3 / 8);
v7 = 1 << (((unsigned int)(v3 >> 31) >> 29) - ((v3 + ((unsigned int)(v3 >> 31) >> 29)) & 7) + 7);
v8 = *v6 | v7;
v9 = *v6 & ~(_BYTE)v7;
if ( a2 >= 0 )
v8 = v9;
*v6 = v8;
return serialiseUInt8((__int64)v4, abs8(a2), v3 + 1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1, char a2)
{
int v2; // eax
int v3; // er9
_QWORD *v4; // r10
int v5; // ecx
_BYTE *v6; // rax
int v7; // ecx
char v8; // dl
char v9; // cl

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x3Bu, "serialiseInt8");
v2 = func2(a2);
if ( v5 < v2 )
_assert_fail("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 0x3Cu, "serialiseInt8");
v6 = (_BYTE *)(*v4 + v3 / 8);
v7 = 1 << (((unsigned int)(v3 >> 31) >> 29) - ((v3 + ((unsigned int)(v3 >> 31) >> 29)) & 7) + 7);
v8 = *v6 | v7;
v9 = *v6 & ~(_BYTE)v7;
if ( a2 >= 0 )
v8 = v9;
*v6 = v8;
return func3((__int64)v4, abs8(a2), v3 + 1);
}

original_code:
void serialiseInt8( SerialData *inSData, int8_t inData, int lower, int upper )
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData ) + 1) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData ) + 1) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 if( inData < 0 )
 {
  (inSData->sdata[lower/8] = ( (1) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower/8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 else
 {
  (inSData->sdata[lower/8] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower/8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 serialiseUInt8( inSData, ((inData)<0?-(inData):(inData)), lower + 1, upper );
}

canonical_original_code:
void serialiseInt8(struct SerialData *inSData, char inData, int lower, int upper)
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData ) + 1) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData ) + 1) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 if( inData < 0 )
 {
  (inSData->sdata[lower/8] = ( (1) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower/8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 else
 {
  (inSData->sdata[lower/8] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower/8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 serialiseUInt8( inSData, ((inData)<0?-(inData):(inData)), lower + 1, upper );
}

variable_types: inData char


serialiseUInt

decompiled_code:
unsigned __int64 __fastcall serialiseUInt(_QWORD *a1, __int64 a2, int a3, int a4, unsigned int a5)
{
__int64 v7; // rsi
int v8; // eax
__int64 v9; // rcx
int v10; // er9
int v11; // eax
__int64 v12; // r8
int v13; // eax
unsigned int v14; // ecx
char v15; // r9
__int64 v16; // r14
int v17; // er8
int v18; // er9
unsigned __int64 result; // rax
int v20; // er9
unsigned __int8 *v21; // r13
unsigned __int8 v22; // si
unsigned int v23; // [rsp+4h] [rbp-44h]
__int64 v24[8]; // [rsp+8h] [rbp-40h] BYREF

v24[0] = a2;
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x75u, "serialiseUInt");
v7 = a5;
v8 = bitsRequired(v24[0]);
if ( (int)v9 < v8 )
_assert_fail("upper - lower + 1 >= bitsRequired( inData )", "../serial.c", 0x76u, "serialiseUInt");
if ( (unsigned int)v7 > 8 )
_assert_fail("sizeof( inData ) >= numBytes", "../serial.c", 0x77u, "serialiseUInt");
v11 = v10 + 8;
v12 = (unsigned int)(a4 + 1);
if ( (int)v9 >= 0 )
v11 = v9;
if ( (int)v7 < v11 >> 3 )
{
do
{
v13 = a3 + 7;
if ( a3 >= 0 )
v13 = a3;
v14 = (unsigned int)(a3 >> 31) >> 29;
v15 = a3++ + v14;
*(_BYTE *)(*a1 + (v13 >> 3)) &= ~(unsigned __int8)(1 << (7 - ((v15 & 7) - v14)));
v9 = (unsigned int)(v12 - a3);
}
while ( ((int)v12 - a3) / 8 > (int)v7 );
}
v16 = -1LL;
v17 = isLittleEndian(7LL, v7, 1LL, v9, v12);
result = (unsigned int)(v18 + 7);
v20 = v18 / 8;
if ( !v17 )
{
v16 = 1LL;
result = (unsigned int)(8 - v20);
v20 = 8 - v20;
}
if ( a4 >= a3 )
{
v21 = (unsigned __int8 *)v24 + v20;
do
{
while ( 1 )
{
v22 = *v21;
if ( (a4 & 7) == 0 )
break;
v21 += v16;
v23 = ((_BYTE)a4 - (_BYTE)a3) & 7;
serialiseUInt8((__int64)a1, v22, a3);
result = v23;
a3 += v23 + 1;
if ( a3 > a4 )
return result;
}
if ( a4 == a3 )
result = serialiseUInt8((__int64)a1, v22, a4);
else
result = serialiseUInt8((__int64)a1, v22, a3);
a3 += 8;
v21 += v16;
}
while ( a3 <= a4 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_QWORD *a1, __int64 a2, int a3, int a4, unsigned int a5)
{
__int64 v7; // rsi
int v8; // eax
__int64 v9; // rcx
int v10; // er9
int v11; // eax
__int64 v12; // r8
int v13; // eax
unsigned int v14; // ecx
char v15; // r9
__int64 v16; // r14
int v17; // er8
int v18; // er9
unsigned __int64 result; // rax
int v20; // er9
unsigned __int8 *v21; // r13
unsigned __int8 v22; // si
unsigned int v23; // [rsp+4h] [rbp-44h]
__int64 v24[8]; // [rsp+8h] [rbp-40h] BYREF

v24[0] = a2;
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x75u, "serialiseUInt");
v7 = a5;
v8 = func2(v24[0]);
if ( (int)v9 < v8 )
_assert_fail("upper - lower + 1 >= bitsRequired( inData )", "../serial.c", 0x76u, "serialiseUInt");
if ( (unsigned int)v7 > 8 )
_assert_fail("sizeof( inData ) >= numBytes", "../serial.c", 0x77u, "serialiseUInt");
v11 = v10 + 8;
v12 = (unsigned int)(a4 + 1);
if ( (int)v9 >= 0 )
v11 = v9;
if ( (int)v7 < v11 >> 3 )
{
do
{
v13 = a3 + 7;
if ( a3 >= 0 )
v13 = a3;
v14 = (unsigned int)(a3 >> 31) >> 29;
v15 = a3++ + v14;
*(_BYTE *)(*a1 + (v13 >> 3)) &= ~(unsigned __int8)(1 << (7 - ((v15 & 7) - v14)));
v9 = (unsigned int)(v12 - a3);
}
while ( ((int)v12 - a3) / 8 > (int)v7 );
}
v16 = -1LL;
v17 = func1(7LL, v7, 1LL, v9, v12);
result = (unsigned int)(v18 + 7);
v20 = v18 / 8;
if ( !v17 )
{
v16 = 1LL;
result = (unsigned int)(8 - v20);
v20 = 8 - v20;
}
if ( a4 >= a3 )
{
v21 = (unsigned __int8 *)v24 + v20;
do
{
while ( 1 )
{
v22 = *v21;
if ( (a4 & 7) == 0 )
break;
v21 += v16;
v23 = ((_BYTE)a4 - (_BYTE)a3) & 7;
func3((__int64)a1, v22, a3);
result = v23;
a3 += v23 + 1;
if ( a3 > a4 )
return result;
}
if ( a4 == a3 )
result = func3((__int64)a1, v22, a4);
else
result = func3((__int64)a1, v22, a3);
a3 += 8;
v21 += v16;
}
while ( a3 <= a4 );
}
return result;
}

original_code:
void serialiseUInt( SerialData *inSData, uint64_t inData, int lower, int upper, int numBytes )
{
 int startByte, step;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData )) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData )) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData )", "../serial.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sizeof( inData ) >= numBytes) ? 1 : 0), __extension__ ({ if (sizeof( inData ) >= numBytes) ; else __assert_fail ("sizeof( inData ) >= numBytes", "../serial.c", 119, __extension__ __PRETTY_FUNCTION__); }));
 while( ( upper - lower + 1 ) / 8 > numBytes )
 {
  (inSData->sdata[ lower / 8 ] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
  lower++;
 }
 if( isLittleEndian() )
 {
  startByte = ( upper - lower ) / 8;
  step = -1;
 }
 else
 {
  startByte = sizeof( inSData ) - ( upper - lower ) / 8;
  step = 1;
 }
 while( lower <= upper )
 {
  if( upper % 8 != 0 )
  {
   serialiseUInt8( inSData, *((uint8_t*)&inData + startByte), lower, lower + ( upper - lower ) % 8 );
   lower += ( upper - lower ) % 8 + 1;
  }
  else
  {
   if( upper - lower == 0 )
   {
    serialiseUInt8( inSData, *((uint8_t*)&inData + startByte ), lower, lower );
   }
   else
   {
    serialiseUInt8( inSData, *((uint8_t*)&inData + startByte ), lower, lower + 7 );
   }
   lower += 8;
  }
  startByte += step;
 }
}

canonical_original_code:
void serialiseUInt(struct SerialData *inSData, unsigned long inData, int lower, int upper, int numBytes)
{
 int startByte; int step;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData )) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData )) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData )", "../serial.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sizeof( inData ) >= numBytes) ? 1 : 0), __extension__ ({ if (sizeof( inData ) >= numBytes) ; else __assert_fail ("sizeof( inData ) >= numBytes", "../serial.c", 119, __extension__ __PRETTY_FUNCTION__); }));
 while( ( upper - lower + 1 ) / 8 > numBytes )
 {
  (inSData->sdata[ lower / 8 ] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
  lower++;
 }
 if( isLittleEndian() )
 {
  startByte = ( upper - lower ) / 8;
  step = -1;
 }
 else
 {
  startByte = sizeof( inSData ) - ( upper - lower ) / 8;
  step = 1;
 }
 while( lower <= upper )
 {
  if( upper % 8 != 0 )
  {
   serialiseUInt8( inSData, *((unsigned char *)&inData + startByte), lower, lower + ( upper - lower ) % 8 );
   lower += ( upper - lower ) % 8 + 1;
  }
  else
  {
   if( upper - lower == 0 )
   {
    serialiseUInt8( inSData, *((unsigned char *)&inData + startByte ), lower, lower );
   }
   else
   {
    serialiseUInt8( inSData, *((unsigned char *)&inData + startByte ), lower, lower + 7 );
   }
   lower += 8;
  }
  startByte += step;
 }
}

variable_types:
inData
unsigned long

variable_types: numBytes int

variable_types: startByte int

variable_types: step int


serialiseInt

decompiled_code:
unsigned __int64 __fastcall serialiseInt(__int64 a1, __int64 a2, int a3)
{
int v5; // eax
_QWORD *v6; // r9
int v7; // er10
unsigned int v8; // er11
int v9; // ecx
_BYTE *v10; // rax
int v11; // ecx
char v12; // dl
char v13; // cl

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x61u, "serialiseInt");
v5 = bitsRequired(a2);
if ( v9 < v5 )
_assert_fail("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 0x62u, "serialiseInt");
if ( v8 > 8 )
_assert_fail("sizeof( inData ) >= numBytes", "../serial.c", 0x63u, "serialiseInt");
v10 = (_BYTE *)(*v6 + a3 / 8);
v11 = 1 << (((unsigned int)(a3 >> 31) >> 29) - ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7) + 7);
v12 = *v10 | v11;
v13 = *v10 & ~(_BYTE)v11;
if ( a2 >= 0 )
v12 = v13;
*v10 = v12;
return serialiseUInt(v6, abs64(a2), a3 + 1, v7, v8);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, __int64 a2, int a3)
{
int v5; // eax
_QWORD *v6; // r9
int v7; // er10
unsigned int v8; // er11
int v9; // ecx
_BYTE *v10; // rax
int v11; // ecx
char v12; // dl
char v13; // cl

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x61u, "serialiseInt");
v5 = func2(a2);
if ( v9 < v5 )
_assert_fail("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 0x62u, "serialiseInt");
if ( v8 > 8 )
_assert_fail("sizeof( inData ) >= numBytes", "../serial.c", 0x63u, "serialiseInt");
v10 = (_BYTE *)(*v6 + a3 / 8);
v11 = 1 << (((unsigned int)(a3 >> 31) >> 29) - ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7) + 7);
v12 = *v10 | v11;
v13 = *v10 & ~(_BYTE)v11;
if ( a2 >= 0 )
v12 = v13;
*v10 = v12;
return func5(v6, abs64(a2), a3 + 1, v7, v8);
}

original_code:
void serialiseInt( SerialData *inSData, int64_t inData, int lower, int upper, int numBytes )
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData ) + 1) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData ) + 1) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sizeof( inData ) >= numBytes) ? 1 : 0), __extension__ ({ if (sizeof( inData ) >= numBytes) ; else __assert_fail ("sizeof( inData ) >= numBytes", "../serial.c", 99, __extension__ __PRETTY_FUNCTION__); }));
 if( inData < 0 )
 {
  (inSData->sdata[ lower / 8 ] = ( (1) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 else
 {
  (inSData->sdata[ lower / 8 ] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 serialiseUInt( inSData, ((inData)<0?-(inData):(inData)), lower + 1, upper, numBytes );
}

canonical_original_code:
void serialiseInt(struct SerialData *inSData, long inData, int lower, int upper, int numBytes)
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData ) + 1) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData ) + 1) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sizeof( inData ) >= numBytes) ? 1 : 0), __extension__ ({ if (sizeof( inData ) >= numBytes) ; else __assert_fail ("sizeof( inData ) >= numBytes", "../serial.c", 99, __extension__ __PRETTY_FUNCTION__); }));
 if( inData < 0 )
 {
  (inSData->sdata[ lower / 8 ] = ( (1) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 else
 {
  (inSData->sdata[ lower / 8 ] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 serialiseUInt( inSData, ((inData)<0?-(inData):(inData)), lower + 1, upper, numBytes );
}

variable_types: inData long


decompiled_code:
__int64 __fastcall deserialiseUInt8(__int64 *a1, int a2, int a3)
{
char v4; // di
int v5; // eax
__int64 v6; // rbx
int v7; // er11
unsigned int v8; // er8
int v9; // eax
char v10; // dl
unsigned int v11; // ecx
char v12; // bp

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xA6u, "deserialiseUInt8");
v4 = a3;
v5 = a3 - a2;
if ( a3 - a2 < 0 )
_assert_fail("upper - lower >= 0", "../serial.c", 0xA7u, "deserialiseUInt8");
while ( v5 > 7 )
{
++a2;
v5 = a3 - a2;
}
if ( a3 < a2 )
return 0LL;
v6 = *a1;
v7 = a3 + 1;
v8 = 0;
do
{
v9 = a2 + 7;
v10 = v4 - a2;
if ( a2 >= 0 )
v9 = a2;
v11 = (unsigned int)(a2 >> 31) >> 29;
v12 = a2++ + v11;
v8 = ((((int)*(unsigned __int8 *)(v6 + (v9 >> 3)) >> (7 - ((v12 & 7) - v11))) & 1) << v10) | ~(1 << v10) & v8;
}
while ( a2 != v7 );
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, int a2, int a3)
{
char v4; // di
int v5; // eax
__int64 v6; // rbx
int v7; // er11
unsigned int v8; // er8
int v9; // eax
char v10; // dl
unsigned int v11; // ecx
char v12; // bp

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xA6u, "deserialiseUInt8");
v4 = a3;
v5 = a3 - a2;
if ( a3 - a2 < 0 )
_assert_fail("upper - lower >= 0", "../serial.c", 0xA7u, "deserialiseUInt8");
while ( v5 > 7 )
{
++a2;
v5 = a3 - a2;
}
if ( a3 < a2 )
return 0LL;
v6 = *a1;
v7 = a3 + 1;
v8 = 0;
do
{
v9 = a2 + 7;
v10 = v4 - a2;
if ( a2 >= 0 )
v9 = a2;
v11 = (unsigned int)(a2 >> 31) >> 29;
v12 = a2++ + v11;
v8 = ((((int)*(unsigned __int8 *)(v6 + (v9 >> 3)) >> (7 - ((v12 & 7) - v11))) & 1) << v10) | ~(1 << v10) & v8;
}
while ( a2 != v7 );
return v8;
}

original_code:
uint8_t deserialiseUInt8( const SerialData *inSData, int lower, int upper )
{
 uint8_t outInt = 0;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 166, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 0) ? 1 : 0), __extension__ ({ if (upper - lower >= 0) ; else __assert_fail ("upper - lower >= 0", "../serial.c", 167, __extension__ __PRETTY_FUNCTION__); }));
 while( upper - lower > 7 )
 {
  lower++;
 }
 for(; lower <= upper; lower++ )
 {
  int curBit;
  curBit = ( !!( (inSData->sdata[lower / 8]) & ( 1 << (7 - (lower % 8) ) ) ) );
  (outInt = ( (curBit) << ( 7 - (7 - ( upper - lower )) ) ) | ( (outInt) & ~( 1 << ( 7 - (7 - ( upper - lower )) ) ) ) );
 }
 return outInt;
}

canonical_original_code:
unsigned char deserialiseUInt8(struct SerialData *inSData, int lower, int upper)
{
 unsigned char outInt = 0;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 166, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 0) ? 1 : 0), __extension__ ({ if (upper - lower >= 0) ; else __assert_fail ("upper - lower >= 0", "../serial.c", 167, __extension__ __PRETTY_FUNCTION__); }));
 while( upper - lower > 7 )
 {
  lower++;
 }
 for(; lower <= upper; lower++ )
 {
  int curBit;
  curBit = ( !!( (inSData->sdata[lower / 8]) & ( 1 << (7 - (lower % 8) ) ) ) );
  (outInt = ( (curBit) << ( 7 - (7 - ( upper - lower )) ) ) | ( (outInt) & ~( 1 << ( 7 - (7 - ( upper - lower )) ) ) ) );
 }
 return outInt;
}

variable_types: struct SerialData { unsigned char *sdata; short len; } *

variable_types:
outInt
unsigned char

return_type: unsigned char


deserialiseUInt

decompiled_code:
__int64 __fastcall deserialiseUInt(__int64 *a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
int v5; // ebp
int v7; // edx
__int64 v8; // rdx
__int64 v9; // rcx
int v10; // edx
int v11; // edx
int v12; // ecx
__int64 v13; // r13
_BYTE *v14; // r15
int v15; // er14
int v16; // edx
int v17; // esi
__int64 v19[8]; // [rsp+8h] [rbp-40h] BYREF

v19[0] = 0LL;
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xD2u, "deserialiseUInt");
v5 = a2;
v7 = a3 - a2;
if ( v7 < 0 )
_assert_fail("upper - lower >= 0", "../serial.c", 0xD3u, "deserialiseUInt");
v8 = (unsigned int)(v7 >> 3);
v9 = (unsigned int)v8;
if ( (int)v8 > 7 )
{
do
{
++v5;
v10 = a3 - v5 + 7;
if ( a3 - v5 >= 0 )
v10 = a3 - v5;
v8 = (unsigned int)(v10 >> 3);
v9 = (unsigned int)v8;
}
while ( (unsigned int)v8 > 7 );
}
v13 = -1LL;
if ( (unsigned int)isLittleEndian(a1, a2, v8, v9, a5) )
{
v14 = (char *)v19 + v11;
if ( a3 >= v5 )
goto LABEL_13;
return 0LL;
}
v13 = 1LL;
v14 = (char *)v19 + 7 - v12;
if ( a3 < v5 )
return 0LL;
do
{
LABEL_13:
while ( (((_BYTE)a3 - (_BYTE)v5) & 7) != 0 )
{
v16 = (((_BYTE)a3 - (_BYTE)v5) & 7) + v5;
v17 = v5;
v5 = v16 + 1;
*v14 = deserialiseUInt8(a1, v17, v16);
v14 += v13;
if ( v5 > a3 )
return v19[0];
}
v15 = v5 + 8;
if ( a3 == v5 )
*v14 = deserialiseUInt8(a1, a3, a3);
else
*v14 = deserialiseUInt8(a1, v5, v15);
v5 += 8;
v14 += v13;
}
while ( v15 <= a3 );
return v19[0];
}

original_code:
uint64_t deserialiseUInt( const SerialData *inSData, int lower, int upper )
{
 uint64_t outInt = 0;
 int startByte, step;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 210, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 0) ? 1 : 0), __extension__ ({ if (upper - lower >= 0) ; else __assert_fail ("upper - lower >= 0", "../serial.c", 211, __extension__ __PRETTY_FUNCTION__); }));
 while( ( upper - lower ) / 8 > sizeof( outInt ) - 1 )
 {
  lower++;
 }
 if( isLittleEndian() )
 {
  startByte = ( upper - lower ) / 8;
  step = -1;
 }
 else
 {
  startByte = sizeof( outInt ) - 1 - ( upper - lower ) / 8;
  step = 1;
 }
 while( lower <= upper )
 {
  if( ( upper - lower ) % 8 == 0 )
  {
   if( lower == upper )
   {
    *((uint8_t*)&outInt + startByte) = deserialiseUInt8( inSData, lower, lower );
   }
   else
   {
    *((uint8_t*)&outInt + startByte) = deserialiseUInt8( inSData, lower, lower + 8 );
   }
   lower += 8;
  }
  else
  {
   *((uint8_t*)&outInt + startByte ) = deserialiseUInt8( inSData, lower, lower + ( upper - lower ) % 8 );
   lower += ( upper - lower ) % 8 + 1;
  }
  startByte += step;
 }
 return outInt;
}

canonical_original_code:
unsigned long deserialiseUInt(struct SerialData *inSData, int lower, int upper)
{
 unsigned long outInt = 0;
 int startByte; int step;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 210, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 0) ? 1 : 0), __extension__ ({ if (upper - lower >= 0) ; else __assert_fail ("upper - lower >= 0", "../serial.c", 211, __extension__ __PRETTY_FUNCTION__); }));
 while( ( upper - lower ) / 8 > sizeof( outInt ) - 1 )
 {
  lower++;
 }
 if( isLittleEndian() )
 {
  startByte = ( upper - lower ) / 8;
  step = -1;
 }
 else
 {
  startByte = sizeof( outInt ) - 1 - ( upper - lower ) / 8;
  step = 1;
 }
 while( lower <= upper )
 {
  if( ( upper - lower ) % 8 == 0 )
  {
   if( lower == upper )
   {
    *((unsigned char *)&outInt + startByte) = deserialiseUInt8( inSData, lower, lower );
   }
   else
   {
    *((unsigned char *)&outInt + startByte) = deserialiseUInt8( inSData, lower, lower + 8 );
   }
   lower += 8;
  }
  else
  {
   *((unsigned char *)&outInt + startByte ) = deserialiseUInt8( inSData, lower, lower + ( upper - lower ) % 8 );
   lower += ( upper - lower ) % 8 + 1;
  }
  startByte += step;
 }
 return outInt;
}

variable_types: lower int

variable_types: upper int

variable_types:
outInt
unsigned long

return_type: unsigned long


deserialiseInt

decompiled_code:
__int64 __fastcall deserialiseInt(__int64 *a1, int a2, unsigned int a3)
{
__int64 v3; // rbx

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xBDu, "deserialiseInt");
if ( (int)(a3 - a2) <= 0 )
_assert_fail("upper - lower >= 1", "../serial.c", 0xBEu, "deserialiseInt");
v3 = -(__int64)((((int)*(unsigned __int8 *)(*a1 + a2 / 8) >> (((unsigned int)(a2 >> 31) >> 29)
- ((a2 + ((unsigned int)(a2 >> 31) >> 29)) & 7)
+ 7)) & 1) == 0);
return ((v3 & 2) - 1)
* deserialiseUInt(
a1,
(unsigned int)(a2 + 1),
a3,
((unsigned int)(a2 >> 31) >> 29) - (((_BYTE)a2 + ((unsigned int)(a2 >> 31) >> 29)) & 7) + 7,
a3);
}

original_code:
int64_t deserialiseInt( const SerialData *inSData, int lower, int upper )
{
 int sign;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 1) ? 1 : 0), __extension__ ({ if (upper - lower >= 1) ; else __assert_fail ("upper - lower >= 1", "../serial.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 if( ( !!( (inSData->sdata[lower / 8]) & ( 1 << (7 - (lower % 8) ) ) ) ) == 1 )
 {
  sign = -1;
 }
 else
 {
  sign = 1;
 }
 return sign * deserialiseUInt( inSData, lower + 1, upper );
}

canonical_original_code:
long deserialiseInt(struct SerialData *inSData, int lower, int upper)
{
 int sign;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 1) ? 1 : 0), __extension__ ({ if (upper - lower >= 1) ; else __assert_fail ("upper - lower >= 1", "../serial.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 if( ( !!( (inSData->sdata[lower / 8]) & ( 1 << (7 - (lower % 8) ) ) ) ) == 1 )
 {
  sign = -1;
 }
 else
 {
  sign = 1;
 }
 return sign * deserialiseUInt( inSData, lower + 1, upper );
}

variable_types: sign int

return_type: long


createSocket

decompiled_code:
int __fastcall createSocket(int a1, int a2)
{
return socket(a1, a2, 0);
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2)
{
return socket(a1, a2, 0);
}

original_code:
int createSocket( int fam, int type )
{
 return socket( fam, type, 0 );
}

canonical_original_code:
int createSocket(int fam, int type)
{
 return socket( fam, type, 0 );
}

variable_types: fam int

variable_types: type int


connectSocket

decompiled_code:
_BOOL8 __fastcall connectSocket(int fd, const __m128i *a2, socklen_t a3, __int16 a4)
{
__int16 v5; // ax
unsigned int v6; // edx
__int16 v7; // bx
__m128i v8; // xmm0
const struct sockaddr *v9; // rsi
__m128i v11; // [rsp+0h] [rbp-48h] BYREF
char dest[2]; // [rsp+10h] [rbp-38h] BYREF
__int16 v13; // [rsp+12h] [rbp-36h]

v5 = _bswap_16(a4);
v7 = v5;
if ( v6 == 16 )
{
v8 = _mm_loadu_si128(a2);
v9 = (const struct sockaddr *)&v11;
v11 = v8;
v11.m128i_i16[1] = v5;
}
else
{
memcpy(dest, a2, v6);
v13 = v7;
v9 = (const struct sockaddr *)dest;
}
return connect(fd, v9, a3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int fd, const __m128i *a2, socklen_t a3, __int16 a4)
{
__int16 v5; // ax
unsigned int v6; // edx
__int16 v7; // bx
__m128i v8; // xmm0
const struct sockaddr *v9; // rsi
__m128i v11; // [rsp+0h] [rbp-48h] BYREF
char dest[2]; // [rsp+10h] [rbp-38h] BYREF
__int16 v13; // [rsp+12h] [rbp-36h]

v5 = func0(a4);
v7 = v5;
if ( v6 == 16 )
{
v8 = _mm_loadu_si128(a2);
v9 = (const struct sockaddr *)&v11;
v11 = v8;
v11.m128i_i16[1] = v5;
}
else
{
memcpy(dest, a2, v6);
v13 = v7;
v9 = (const struct sockaddr *)dest;
}
return connect(fd, v9, a3) == 0;
}

original_code:
boolean connectSocket( int sockfd, struct sockaddr *inAddr, socklen_t addrLen, int port )
{
 boolean success = FALSE;
 struct sockaddr_in addr;
 struct sockaddr_in6 addr6;
 if( addrLen == sizeof( addr ) )
 {
  memcpy( &addr, inAddr, addrLen );
  addr.sin_port = htons( port );
  inAddr = (struct sockaddr*)&addr;
 }
 else
 {
  memcpy( &addr6, inAddr, addrLen );
  addr6.sin6_port = htons( port );
  inAddr = (struct sockaddr*)&addr6;
 }
 if( connect( sockfd, inAddr, addrLen ) == 0 )
 {
  success = TRUE;
 }
 return success;
}

canonical_original_code:
enum boolean connectSocket(int sockfd, struct sockaddr *inAddr, unsigned int addrLen, int port)
{
 enum boolean success = FALSE;
 struct sockaddr_in addr;
 struct sockaddr_in6 addr6;
 if( addrLen == sizeof( addr ) )
 {
  memcpy( &addr, inAddr, addrLen );
  addr.sin_port = htons( port );
  inAddr = (struct sockaddr *)&addr;
 }
 else
 {
  memcpy( &addr6, inAddr, addrLen );
  addr6.sin6_port = htons( port );
  inAddr = (struct sockaddr *)&addr6;
 }
 if( connect( sockfd, inAddr, addrLen ) == 0 )
 {
  success = TRUE;
 }
 return success;
}

variable_types: sockfd int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; } *

variable_types:
addrLen
unsigned int

variable_types: port int

variable_types:
success
enum boolean { FALSE=0, TRUE=1 }

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


acceptConnection

decompiled_code:
_BOOL8 __fastcall acceptConnection(int fd)
{
ssize_t v1; // r8
_BOOL8 result; // rax
socklen_t addr_len; // [rsp+8h] [rbp-90h] BYREF
char buf[4]; // [rsp+Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-88h] BYREF

addr_len = 128;
v1 = recvfrom(fd, buf, 4uLL, 0, &addr, &addr_len);
result = 0LL;
if ( v1 == 4 )
result = connect(fd, &addr, addr_len) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int fd)
{
ssize_t v1; // r8
_BOOL8 result; // rax
socklen_t addr_len; // [rsp+8h] [rbp-90h] BYREF
char buf[4]; // [rsp+Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-88h] BYREF

addr_len = 128;
v1 = recvfrom(fd, buf, 4uLL, 0, &addr, &addr_len);
result = 0LL;
if ( v1 == 4 )
result = connect(fd, &addr, addr_len) == 0;
return result;
}

original_code:
boolean acceptConnection( int sockfd )
{
 char buf[4];
 struct sockaddr_storage inAddr;
 socklen_t inAddrSize;
 boolean success = FALSE;
 inAddrSize = sizeof( inAddr );
 if( recvfrom( sockfd, &buf, sizeof( buf ), 0, (struct sockaddr*)&inAddr, &inAddrSize ) == sizeof( buf ) )
 {
  if( connect( sockfd, (struct sockaddr*)&inAddr, inAddrSize ) == 0 )
  {
   success = TRUE;
  }
 }
 return success;
}

canonical_original_code:
enum boolean acceptConnection(int sockfd)
{
 char buf[4];
 struct sockaddr_storage inAddr;
 unsigned int inAddrSize;
 enum boolean success = FALSE;
 inAddrSize = sizeof( inAddr );
 if( recvfrom( sockfd, &buf, sizeof( buf ), 0, (struct sockaddr *)&inAddr, &inAddrSize ) == sizeof( buf ) )
 {
  if( connect( sockfd, (struct sockaddr *)&inAddr, inAddrSize ) == 0 )
  {
   success = TRUE;
  }
 }
 return success;
}

variable_types:
buf
char [4]

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
inAddrSize
unsigned int


waitForData

decompiled_code:
_BOOL8 __fastcall waitForData(int a1, int a2)
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = a1;
fds.events = 1;
return poll(&fds, 1uLL, a2) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1, int a2)
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = a1;
fds.events = 1;
return poll(&fds, 1uLL, a2) > 0;
}

original_code:
boolean waitForData( int sockfd, int timeout )
{
 struct pollfd sock;
 boolean success = FALSE;
 sock.fd = sockfd;
 sock.events = 0x001;
 if( poll( &sock, 1, timeout ) > 0 )
 {
  success = TRUE;
 }
 return success;
}

canonical_original_code:
enum boolean waitForData(int sockfd, int timeout)
{
 struct pollfd sock;
 enum boolean success = FALSE;
 sock.fd = sockfd;
 sock.events = 0x001;
 if( poll( &sock, 1, timeout ) > 0 )
 {
  success = TRUE;
 }
 return success;
}

variable_types: timeout int

variable_types: struct pollfd { int fd; short events; short revents; }


createListenSocket

decompiled_code:
__int64 __fastcall createListenSocket(int a1, int a2, __int64 a3)
{
unsigned int v3; // er12
int v4; // eax
struct addrinfo *v5; // rbp
int v6; // eax
__int64 result; // rax
const char *v8; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
char s[10]; // [rsp+16h] [rbp-52h] BYREF
struct addrinfo req; // [rsp+20h] [rbp-48h] BYREF

if ( (unsigned int)(a3 - 1) > 0xF423E )
_assert_fail("port > 0 && port <= 999999", "../sockhelp.c", 0x5Au, "createListenSocket");
req.ai_family = a1;
*(_OWORD *)&req.ai_socktype = 0LL;
req.ai_socktype = a2;
req.ai_next = 0LL;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addr = 0LL;
sprintf(s, "%d", a3);
v4 = getaddrinfo(0LL, s, &req, &pai);
if ( v4 )
{
v8 = gai_strerror(v4);
fprintf(stderr, "Error occured in getaddrinfo: %s\n", v8);
result = v3;
}
else
{
v5 = pai;
if ( pai )
{
do
{
v6 = socket(v5->ai_family, v5->ai_socktype, v5->ai_protocol);
v3 = v6;
if ( v6 != -1 )
{
if ( bind(v6, v5->ai_addr, v5->ai_addrlen) != -1 )
break;
close(v3);
}
v5 = v5->ai_next;
}
while ( v5 );
v5 = pai;
}
freeaddrinfo(v5);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, __int64 a3)
{
unsigned int v3; // er12
int v4; // eax
struct addrinfo *v5; // rbp
int v6; // eax
__int64 result; // rax
const char *v8; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
char s[10]; // [rsp+16h] [rbp-52h] BYREF
struct addrinfo req; // [rsp+20h] [rbp-48h] BYREF

if ( (unsigned int)(a3 - 1) > 0xF423E )
_assert_fail("port > 0 && port <= 999999", "../sockhelp.c", 0x5Au, "createListenSocket");
req.ai_family = a1;
*(_OWORD *)&req.ai_socktype = 0LL;
req.ai_socktype = a2;
req.ai_next = 0LL;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addr = 0LL;
sprintf(s, "%d", a3);
v4 = getaddrinfo(0LL, s, &req, &pai);
if ( v4 )
{
v8 = gai_strerror(v4);
fprintf(stderr, "Error occured in getaddrinfo: %s\n", v8);
result = v3;
}
else
{
v5 = pai;
if ( pai )
{
do
{
v6 = socket(v5->ai_family, v5->ai_socktype, v5->ai_protocol);
v3 = v6;
if ( v6 != -1 )
{
if ( bind(v6, v5->ai_addr, v5->ai_addrlen) != -1 )
break;
close(v3);
}
v5 = v5->ai_next;
}
while ( v5 );
v5 = pai;
}
freeaddrinfo(v5);
result = v3;
}
return result;
}

original_code:
int createListenSocket( int fam, int type, unsigned int port )
{
 struct addrinfo hints, *local, *it;
 char numString[10];
 int sockfd;
 int success;
 ((void) sizeof ((port > 0 && port <= 999999) ? 1 : 0), __extension__ ({ if (port > 0 && port <= 999999) ; else __assert_fail ("port > 0 && port <= 999999", "../sockhelp.c", 90, __extension__ __PRETTY_FUNCTION__); }));
 memset( &hints, 0, sizeof( hints ) );
 hints.ai_family = fam;
 hints.ai_socktype = type;
 hints.ai_flags = 0x0001;
 sprintf( numString, "%d", port );
 if( ( success = getaddrinfo( ((void *)0), numString, &hints, &local ) ) == 0 )
 {
  for( it = local; it != ((void *)0); it = it->ai_next )
  {
   if( ( sockfd = socket( it->ai_family, it->ai_socktype, it->ai_protocol ) ) != -1 )
   {
    if( bind( sockfd, it->ai_addr, it->ai_addrlen ) != -1 )
    {
     break;
    }
    else
    {
     close( sockfd );
    }
   }
  }
  freeaddrinfo( local );
 }
 else
 {
  fprintf( stderr, "Error occured in getaddrinfo: %s\n", gai_strerror( success ) );
 }
 return sockfd;
}

canonical_original_code:
int createListenSocket(int fam, int type, unsigned int port)
{
 struct addrinfo hints; struct addrinfo *local; struct addrinfo *it;
 char numString[10];
 int sockfd;
 int success;
 ((void) sizeof ((port > 0 && port <= 999999) ? 1 : 0), __extension__ ({ if (port > 0 && port <= 999999) ; else __assert_fail ("port > 0 && port <= 999999", "../sockhelp.c", 90, __extension__ __PRETTY_FUNCTION__); }));
 memset( &hints, 0, sizeof( hints ) );
 hints.ai_family = fam;
 hints.ai_socktype = type;
 hints.ai_flags = 0x0001;
 sprintf( numString, "%d", port );
 if( ( success = getaddrinfo( ((void *)0), numString, &hints, &local ) ) == 0 )
 {
  for( it = local; it != ((void *)0); it = it->ai_next )
  {
   if( ( sockfd = socket( it->ai_family, it->ai_socktype, it->ai_protocol ) ) != -1 )
   {
    if( bind( sockfd, it->ai_addr, it->ai_addrlen ) != -1 )
    {
     break;
    }
    else
    {
     close( sockfd );
    }
   }
  }
  freeaddrinfo( local );
 }
 else
 {
  fprintf( stderr, "Error occured in getaddrinfo: %s\n", gai_strerror( success ) );
 }
 return sockfd;
}

variable_types:
port
unsigned int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
numString
char [10]

variable_types: success int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


createBroadcastSocket

decompiled_code:
__int64 createBroadcastSocket()
{
int v0; // eax
unsigned int v1; // er12
int v3; // edi
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = socket(2, 2, 0);
v1 = v0;
if ( v0 != -1 )
{
optval[0] = 1;
if ( setsockopt(v0, 1, 6, optval, 4u) == -1 )
{
v3 = v1;
v1 = -1;
close(v3);
}
}
return v1;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
unsigned int v1; // er12
int v3; // edi
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = socket(2, 2, 0);
v1 = v0;
if ( v0 != -1 )
{
optval[0] = 1;
if ( setsockopt(v0, 1, 6, optval, 4u) == -1 )
{
v3 = v1;
v1 = -1;
close(v3);
}
}
return v1;
}

original_code:
int createBroadcastSocket( void )
{
 int sockfd, bcast;
 if( ( sockfd = socket( 2, SOCK_DGRAM, 0 ) ) == -1 )
 {
  return -1;
 }
 bcast = 1;
 if( setsockopt( sockfd, 1, 6, &bcast, sizeof( bcast ) ) == -1 )
 {
  close( sockfd );
  return -1;
 }
 return sockfd;
}

canonical_original_code:
int createBroadcastSocket()
{
 int sockfd; int bcast;
 if( ( sockfd = socket( 2, SOCK_DGRAM, 0 ) ) == -1 )
 {
  return -1;
 }
 bcast = 1;
 if( setsockopt( sockfd, 1, 6, &bcast, sizeof( bcast ) ) == -1 )
 {
  close( sockfd );
  return -1;
 }
 return sockfd;
}

variable_types: bcast int


sendBroadcast

decompiled_code:
__int64 __fastcall sendBroadcast(int fd, __int16 a2)
{
void *v2; // rdx
char buf; // [rsp+Fh] [rbp-19h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

buf = 1;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
inet_pton(2, "255.255.255.255", v2);
*(_QWORD *)&addr.sa_data[6] = 0LL;
return (unsigned int)-(sendto(fd, &buf, 1uLL, 0, &addr, 0x10u) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, __int16 a2)
{
void *v2; // rdx
char buf; // [rsp+Fh] [rbp-19h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

buf = 1;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a2);
inet_pton(2, "255.255.255.255", v2);
*(_QWORD *)&addr.sa_data[6] = 0LL;
return (unsigned int)-(sendto(fd, &buf, 1uLL, 0, &addr, 0x10u) != 1);
}

original_code:
int sendBroadcast( int sockfd, unsigned int port )
{
 struct sockaddr_in bcastaddr;
 unsigned char data = 1;
 socklen_t len;
 bcastaddr.sin_family = 2;
 bcastaddr.sin_port = htons( port );
 inet_pton( bcastaddr.sin_family, "255.255.255.255", &bcastaddr.sin_addr );
 memset( bcastaddr.sin_zero, '\0', sizeof( bcastaddr.sin_zero ) );
 len = sizeof( bcastaddr );
 if( sendto( sockfd, &data, sizeof( data ), 0, (struct sockaddr*)&bcastaddr, len ) != sizeof( data ) )
 {
  return -1;
 }
 return 0;
}

canonical_original_code:
int sendBroadcast(int sockfd, unsigned int port)
{
 struct sockaddr_in bcastaddr;
 unsigned char data = 1;
 unsigned int len;
 bcastaddr.sin_family = 2;
 bcastaddr.sin_port = htons( port );
 inet_pton( bcastaddr.sin_family, "255.255.255.255", &bcastaddr.sin_addr );
 memset( bcastaddr.sin_zero, '\0', sizeof( bcastaddr.sin_zero ) );
 len = sizeof( bcastaddr );
 if( sendto( sockfd, &data, sizeof( data ), 0, (struct sockaddr *)&bcastaddr, len ) != sizeof( data ) )
 {
  return -1;
 }
 return 0;
}

variable_types: sockfd int

variable_types:
data
unsigned char

variable_types:
len
unsigned int


recvBroadcast

decompiled_code:
_BOOL8 __fastcall recvBroadcast(int a1, struct sockaddr *a2)
{
int v2; // er8
_BOOL8 result; // rax
socklen_t v4; // [rsp+0h] [rbp-18h] BYREF
char buf[18]; // [rsp+6h] [rbp-12h] BYREF

v4 = 16;
v2 = recvfrom(a1, buf, 0xAuLL, 0, a2, &v4);
result = 1LL;
if ( v2 == 1 )
result = buf[0] != 1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1, struct sockaddr *a2)
{
int v2; // er8
_BOOL8 result; // rax
socklen_t v4; // [rsp+0h] [rbp-18h] BYREF
char buf[18]; // [rsp+6h] [rbp-12h] BYREF

v4 = 16;
v2 = recvfrom(a1, buf, 0xAuLL, 0, a2, &v4);
result = 1LL;
if ( v2 == 1 )
result = buf[0] != 1;
return result;
}

original_code:
int recvBroadcast( int sockfd, struct sockaddr_in *addr )
{
 socklen_t addrSize;
 char buf[10];
 int bytesRead;
 addrSize = sizeof( *addr );
 bytesRead = recvfrom( sockfd, &buf, sizeof( buf ), 0, (struct sockaddr*)addr, &addrSize );
 if( bytesRead == 1 && buf[0] == 1 )
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int recvBroadcast(int sockfd, struct sockaddr_in *addr)
{
 unsigned int addrSize;
 char buf[10];
 int bytesRead;
 addrSize = sizeof( *addr );
 bytesRead = recvfrom( sockfd, &buf, sizeof( buf ), 0, (struct sockaddr *)addr, &addrSize );
 if( bytesRead == 1 && buf[0] == 1 )
 {
  return 0;
 }
 return 1;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types:
addrSize
unsigned int

variable_types:
buf
char [10]

variable_types: bytesRead int


setSocketBlock

decompiled_code:
int __fastcall setSocketBlock(int a1)
{
return fcntl(a1, 4, 2048LL);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
return fcntl(a1, 4, 2048LL);
}

original_code:
int setSocketBlock( int sockfd )
{
 return fcntl( sockfd, 4, 04000 );
}

canonical_original_code:
int setSocketBlock(int sockfd)
{
 return fcntl( sockfd, 4, 04000 );
}


sendAll

decompiled_code:
__int64 __fastcall sendAll(int fd, void *buf, int a3, int a4)
{
int v6; // ebx
int v7; // eax

if ( a3 <= 0 )
return 1LL;
v6 = a3;
do
{
v7 = send(fd, buf, v6, a4);
if ( v7 == -1 )
return 0LL;
v6 -= v7;
buf = (char *)buf + v7;
}
while ( v6 > 0 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, int a3, int a4)
{
int v6; // ebx
int v7; // eax

if ( a3 <= 0 )
return 1LL;
v6 = a3;
do
{
v7 = send(fd, buf, v6, a4);
if ( v7 == -1 )
return 0LL;
v6 -= v7;
buf = (char *)buf + v7;
}
while ( v6 > 0 );
return 1LL;
}

original_code:
boolean sendAll( int sockfd, const char *data, int datSize, int flags )
{
 boolean success = TRUE;
 int bytesSent;
 while( datSize > 0 && success == TRUE )
 {
  bytesSent = send( sockfd, data, datSize, flags );
  if( bytesSent == -1 )
  {
   success = FALSE;
  }
  else
  {
   datSize -= bytesSent;
   data += bytesSent;
  }
 }
 return success;
}

canonical_original_code:
enum boolean sendAll(int sockfd, char *data, int datSize, int flags)
{
 enum boolean success = TRUE;
 int bytesSent;
 while( datSize > 0 && success == TRUE )
 {
  bytesSent = send( sockfd, data, datSize, flags );
  if( bytesSent == -1 )
  {
   success = FALSE;
  }
  else
  {
   datSize -= bytesSent;
   data += bytesSent;
  }
 }
 return success;
}

variable_types:
data
char *

variable_types: datSize int

variable_types: flags int

variable_types:
success
enum boolean { FALSE=0, TRUE=1 }

variable_types: bytesSent int


sendMsg

decompiled_code:
__int64 __fastcall sendMsg(int fd, unsigned int a2, __int64 a3)
{
__int64 (__fastcall *v4)(__int64); // rax
__int64 v5; // r14
__int64 result; // rax
int v7; // er14
unsigned int v8; // [rsp+Ch] [rbp-3Ch]
void *ptr; // [rsp+10h] [rbp-38h] BYREF
__int16 v10; // [rsp+18h] [rbp-30h]

if ( serNumEnt > a2 && (v4 = *(&serArray + a2)) != 0LL )
{
if ( !a3 )
_assert_fail("dataStruct != NULL", "../netmsg.c", 0x35u, "sendMsg");
v5 = v4(a3);
v10 = *(_WORD *)(v5 + 8) + 4;
ptr = malloc(v10);
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, *(__int16 *)(v5 + 8), 16LL, 31LL, 2LL);
memcpy((char *)ptr + 4, *(const void **)v5, *(__int16 *)(v5 + 8));
v8 = sendAll(fd, ptr, v10, 0);
free(*(void **)v5);
free((void *)v5);
free(ptr);
result = v8;
}
else
{
if ( a3 )
{
v7 = deserialiseInt(a3, 0LL, 15LL);
v10 = v7 + 4;
ptr = malloc((__int16)(v7 + 4));
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, v7, 16LL, 31LL, 4LL);
memcpy((char *)ptr + 4, (const void *)(a3 + 2), v10 - 4);
}
else
{
v10 = 4;
ptr = malloc(4uLL);
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, 0LL, 16LL, 31LL, 4LL);
}
result = sendAll(fd, ptr, v10, 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, unsigned int a2, __int64 a3)
{
__int64 (__fastcall *v4)(__int64); // rax
__int64 v5; // r14
__int64 result; // rax
int v7; // er14
unsigned int v8; // [rsp+Ch] [rbp-3Ch]
void *ptr; // [rsp+10h] [rbp-38h] BYREF
__int16 v10; // [rsp+18h] [rbp-30h]

if ( serNumEnt > a2 && (v4 = *(&serArray + a2)) != 0LL )
{
if ( !a3 )
_assert_fail("dataStruct != NULL", "../netmsg.c", 0x35u, "sendMsg");
v5 = v4(a3);
v10 = *(_WORD *)(v5 + 8) + 4;
ptr = malloc(v10);
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, *(__int16 *)(v5 + 8), 16LL, 31LL, 2LL);
memcpy((char *)ptr + 4, *(const void **)v5, *(__int16 *)(v5 + 8));
v8 = func0(fd, ptr, v10, 0);
free(*(void **)v5);
free((void *)v5);
free(ptr);
result = v8;
}
else
{
if ( a3 )
{
v7 = deserialiseInt(a3, 0LL, 15LL);
v10 = v7 + 4;
ptr = malloc((__int16)(v7 + 4));
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, v7, 16LL, 31LL, 4LL);
memcpy((char *)ptr + 4, (const void *)(a3 + 2), v10 - 4);
}
else
{
v10 = 4;
ptr = malloc(4uLL);
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, 0LL, 16LL, 31LL, 4LL);
}
result = func0(fd, ptr, v10, 0);
}
return result;
}

original_code:
boolean sendMsg( int sockfd, MsgType type, void *dataStruct )
{
 SerialData outDat, *serStruct;
 boolean success = TRUE;
 int bodyLen = 0;
 if( type >= serNumEnt || serArray[type] == ((void *)0) )
 {
  if( dataStruct != ((void *)0) )
  {
   bodyLen = deserialiseInt( dataStruct, 0, 2 * 8 - 1 );
  }
  outDat.len = 2 + 2 + bodyLen;
  outDat.sdata = malloc( outDat.len * sizeof( *outDat.sdata ) );
  serialiseUInt( &outDat, type, 0, 2 * 8 - 1, sizeof( type ) );
  serialiseInt( &outDat, bodyLen, 2 * 8, 2 * 8 + 2 * 8 - 1, sizeof( bodyLen ) );
  if( dataStruct != ((void *)0) )
  {
   memcpy( outDat.sdata + 2 + 2, (char*)dataStruct + 2, outDat.len - 2 - 2 );
  }
  success = sendAll( sockfd, (char*)outDat.sdata, outDat.len, 0);
 }
 else
 {
  ((void) sizeof ((dataStruct != ((void *)0)) ? 1 : 0), __extension__ ({ if (dataStruct != ((void *)0)) ; else __assert_fail ("dataStruct != NULL", "../netmsg.c", 53, __extension__ __PRETTY_FUNCTION__); }));
  serStruct = serArray[type]( dataStruct );
  outDat.len = serStruct->len + 2 + 2;
  outDat.sdata = malloc( ( outDat.len ) * sizeof( *serStruct->sdata ) );
         serialiseUInt( &outDat, type, 0, 2 * 8 - 1, sizeof( type ) );
  serialiseInt( &outDat, serStruct->len, 2 * 8, 2 * 8 + 2 * 8 - 1, sizeof( serStruct->len ) );
  memcpy( outDat.sdata + 2 + 2, serStruct->sdata, serStruct->len );
  success = sendAll( sockfd, (char*)outDat.sdata, outDat.len * sizeof( *outDat.sdata ), 0 );
  free( serStruct->sdata );
  free( serStruct );
  free( outDat.sdata );
 }
 return success;
}

canonical_original_code:
enum boolean sendMsg(int sockfd, enum MsgType type, void *dataStruct)
{
 struct SerialData outDat; struct SerialData *serStruct;
 enum boolean success = TRUE;
 int bodyLen = 0;
 if( type >= serNumEnt || serArray[type] == ((void *)0) )
 {
  if( dataStruct != ((void *)0) )
  {
   bodyLen = deserialiseInt( dataStruct, 0, 2 * 8 - 1 );
  }
  outDat.len = 2 + 2 + bodyLen;
  outDat.sdata = malloc( outDat.len * sizeof( *outDat.sdata ) );
  serialiseUInt( &outDat, type, 0, 2 * 8 - 1, sizeof( type ) );
  serialiseInt( &outDat, bodyLen, 2 * 8, 2 * 8 + 2 * 8 - 1, sizeof( bodyLen ) );
  if( dataStruct != ((void *)0) )
  {
   memcpy( outDat.sdata + 2 + 2, (char *)dataStruct + 2, outDat.len - 2 - 2 );
  }
  success = sendAll( sockfd, (char *)outDat.sdata, outDat.len, 0);
 }
 else
 {
  ((void) sizeof ((dataStruct != ((void *)0)) ? 1 : 0), __extension__ ({ if (dataStruct != ((void *)0)) ; else __assert_fail ("dataStruct != NULL", "../netmsg.c", 53, __extension__ __PRETTY_FUNCTION__); }));
  serStruct = serArray[type]( dataStruct );
  outDat.len = serStruct->len + 2 + 2;
  outDat.sdata = malloc( ( outDat.len ) * sizeof( *serStruct->sdata ) );
         serialiseUInt( &outDat, type, 0, 2 * 8 - 1, sizeof( type ) );
  serialiseInt( &outDat, serStruct->len, 2 * 8, 2 * 8 + 2 * 8 - 1, sizeof( serStruct->len ) );
  memcpy( outDat.sdata + 2 + 2, serStruct->sdata, serStruct->len );
  success = sendAll( sockfd, (char *)outDat.sdata, outDat.len * sizeof( *outDat.sdata ), 0 );
  free( serStruct->sdata );
  free( serStruct );
  free( outDat.sdata );
 }
 return success;
}

variable_types: enum MsgType { KEYPRESS=0, KEYRELEASE=1, POINTERSET=2, POINTERMOVE=3, POINTERPRESS=4, POINTERRELEASE=5, SETRESOLUTION=6, DISPLAYNUM=7, STOPDISPLAYNUM=8, CONNECT=9, DISCONNECT=10, ALLOW=11, DENY=12, CLOSE=13, NOMSG=14 }

variable_types:
dataStruct
void *

variable_types: struct SerialData { unsigned char *sdata; short len; } *

variable_types: bodyLen int


recvExact

decompiled_code:
__int64 __fastcall recvExact(int fd, void *buf, int a3, int a4)
{
int v6; // ebx
int v7; // eax

if ( a3 <= 0 )
return 1LL;
v6 = a3;
do
{
v7 = recv(fd, buf, v6, a4);
if ( v7 <= 0 )
return 0LL;
v6 -= v7;
buf = (char *)buf + v7;
}
while ( v6 > 0 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, int a3, int a4)
{
int v6; // ebx
int v7; // eax

if ( a3 <= 0 )
return 1LL;
v6 = a3;
do
{
v7 = recv(fd, buf, v6, a4);
if ( v7 <= 0 )
return 0LL;
v6 -= v7;
buf = (char *)buf + v7;
}
while ( v6 > 0 );
return 1LL;
}

original_code:
boolean recvExact( int sockfd, char *buf, int len, int flags )
{
 boolean success = TRUE;
 int bytesRead;
 while( success && len > 0 )
 {
  if( (bytesRead = recv( sockfd, buf, len, flags ) ) > 0 )
  {
   len -= bytesRead;
   buf += bytesRead;
  }
  else
  {
   success = FALSE;
  }
 }
 return success;
}

canonical_original_code:
enum boolean recvExact(int sockfd, char *buf, int len, int flags)
{
 enum boolean success = TRUE;
 int bytesRead;
 while( success && len > 0 )
 {
  if( (bytesRead = recv( sockfd, buf, len, flags ) ) > 0 )
  {
   len -= bytesRead;
   buf += bytesRead;
  }
  else
  {
   success = FALSE;
  }
 }
 return success;
}

variable_types:
buf
char *

variable_types: len int


CreateToggleWndDat

decompiled_code:
_DWORD *CreateToggleWndDat()
{
_DWORD *result; // rax

result = malloc(8uLL);
*result = 0;
return result;
}

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

result = malloc(8uLL);
*result = 0;
return result;
}

original_code:
static ToggleWndDat *CreateToggleWndDat( void )
{
 ToggleWndDat *twd;
 twd = malloc( sizeof( twd ) );
 twd->isToggle = FALSE;
 return twd;
}

canonical_original_code:
static struct ToggleWndDat *CreateToggleWndDat()
{
 struct ToggleWndDat *twd;
 twd = malloc( sizeof( twd ) );
 twd->isToggle = FALSE;
 return twd;
}

variable_types: struct ToggleWndDat { enum boolean { FALSE=0, TRUE=1 } isToggle; } *

user_defined_types: struct ToggleWndDat { enum boolean isToggle; }


DestroyToggleWndDat

decompiled_code:
// attributes: thunk
void DestroyToggleWndDat(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func8(void *ptr)
{
free(ptr);
}

original_code:
static void DestroyToggleWndDat( ToggleWndDat *twd )
{
 free( twd );
}

canonical_original_code:
static void DestroyToggleWndDat(struct ToggleWndDat *twd)
{
 free( twd );
}


CreateNumWndDat

decompiled_code:
_DWORD *CreateNumWndDat()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 0;
return result;
}

original_code:
NumWndDat *CreateNumWndDat( void )
{
 NumWndDat *nwd;
 nwd = malloc( sizeof( *nwd ) );
 nwd->numWnd = 0;
 return nwd;
}

canonical_original_code:
struct NumWndDat *CreateNumWndDat()
{
 struct NumWndDat *nwd;
 nwd = malloc( sizeof( *nwd ) );
 nwd->numWnd = 0;
 return nwd;
}

variable_types:
nwd
struct NumWndDat { int numWnd; } *

return_type: struct NumWndDat { int numWnd; } *


DestroyNumWndDat

decompiled_code:
// attributes: thunk
void DestroyNumWndDat(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

original_code:
void DestroyNumWndDat( NumWndDat *inData )
{
 free( inData );
}

canonical_original_code:
void DestroyNumWndDat(struct NumWndDat *inData)
{
 free( inData );
}

variable_types:
inData
struct NumWndDat { int numWnd; } *


cleanup

decompiled_code:
void cleanup(void)
{
if ( pr )
stl_reader_delete();
}

canonical_decompiled_code:
void func0(void)
{
if ( pr )
stl_reader_delete();
}

original_code:
static void cleanup(void)
{
 if (pr) stl_reader_delete(pr);
}

canonical_original_code:
static void cleanup()
{
 if (pr) stl_reader_delete(pr);
}


decompiled_code:
int __fastcall check_structure(__int64 a1)
{
char *v1; // rax
int v2; // edx
__int64 v3; // rcx
__int64 v4; // rsi
_DWORD *v5; // rax
int v6; // edx
int v7; // ecx
int v8; // edx
__int64 v9; // rcx
__int64 v10; // rsi
_DWORD *v11; // rax
int v12; // edx
int v13; // ecx
int v14; // edx
int v15; // eax
int result; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

printf("// Name of the solid: %s\n", (const char *)a1);
time(&timer);
v1 = ctime(&timer);
printf("// Generated by stl2pov 2.4.4 on %s", v1);
v2 = *(_DWORD *)(a1 + 112);
if ( v2 <= 0 )
goto LABEL_15;
v3 = *(_QWORD *)(a1 + 88);
v4 = v3 + 16LL * (unsigned int)(v2 - 1) + 28;
v5 = (_DWORD *)(v3 + 12);
v6 = 0;
do
{
v7 = *v5 < 3;
v5 += 4;
v6 += v7;
}
while ( v5 != (_DWORD *)v4 );
if ( !v6 )
LABEL_15:
puts("// - All vertices used by 3 or more triangles, good.");
v8 = *(_DWORD *)(a1 + 116);
if ( v8 <= 0 )
goto LABEL_14;
v9 = *(_QWORD *)(a1 + 96);
v10 = v9 + 20LL * (unsigned int)(v8 - 1) + 36;
v11 = (_DWORD *)(v9 + 16);
v12 = 0;
do
{
v13 = *v11 != 2;
v11 += 5;
v12 += v13;
}
while ( (_DWORD *)v10 != v11 );
if ( v12 )
{
puts("// ! Warning: some edges are not used by two triangles.");
puts("// (There might be visible gaps between triangles.)");
}
else
{
LABEL_14:
puts("// - All edges used by 2 triangles, good.");
}
v14 = *(_DWORD *)(a1 + 116);
v15 = *(_DWORD *)(a1 + 120);
if ( 2 * v14 == 3 * v15 )
{
puts("// - 2 x #edges == 3 x #triangles, good.");
v15 = *(_DWORD *)(a1 + 120);
v14 = *(_DWORD *)(a1 + 116);
}
result = *(_DWORD *)(a1 + 112) + v15 - v14;
if ( result == 2 )
result = puts("// - The solid meets Euler's Rule, good.");
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
char *v1; // rax
int v2; // edx
__int64 v3; // rcx
__int64 v4; // rsi
_DWORD *v5; // rax
int v6; // edx
int v7; // ecx
int v8; // edx
__int64 v9; // rcx
__int64 v10; // rsi
_DWORD *v11; // rax
int v12; // edx
int v13; // ecx
int v14; // edx
int v15; // eax
int result; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

printf("// Name of the solid: %s\n", (const char *)a1);
time(&timer);
v1 = ctime(&timer);
printf("// Generated by stl2pov 2.4.4 on %s", v1);
v2 = *(_DWORD *)(a1 + 112);
if ( v2 <= 0 )
goto LABEL_15;
v3 = *(_QWORD *)(a1 + 88);
v4 = v3 + 16LL * (unsigned int)(v2 - 1) + 28;
v5 = (_DWORD *)(v3 + 12);
v6 = 0;
do
{
v7 = *v5 < 3;
v5 += 4;
v6 += v7;
}
while ( v5 != (_DWORD *)v4 );
if ( !v6 )
LABEL_15:
puts("// - All vertices used by 3 or more triangles, good.");
v8 = *(_DWORD *)(a1 + 116);
if ( v8 <= 0 )
goto LABEL_14;
v9 = *(_QWORD *)(a1 + 96);
v10 = v9 + 20LL * (unsigned int)(v8 - 1) + 36;
v11 = (_DWORD *)(v9 + 16);
v12 = 0;
do
{
v13 = *v11 != 2;
v11 += 5;
v12 += v13;
}
while ( (_DWORD *)v10 != v11 );
if ( v12 )
{
puts("// ! Warning: some edges are not used by two triangles.");
puts("// (There might be visible gaps between triangles.)");
}
else
{
LABEL_14:
puts("// - All edges used by 2 triangles, good.");
}
v14 = *(_DWORD *)(a1 + 116);
v15 = *(_DWORD *)(a1 + 120);
if ( 2 * v14 == 3 * v15 )
{
puts("// - 2 x #edges == 3 x #triangles, good.");
v15 = *(_DWORD *)(a1 + 120);
v14 = *(_DWORD *)(a1 + 116);
}
result = *(_DWORD *)(a1 + 112) + v15 - v14;
if ( result == 2 )
result = puts("// - The solid meets Euler's Rule, good.");
return result;
}

original_code:
void check_structure(struct stl_reader *r)
{
 int i, open = 0;
 time_t tm;
 printf("// Name of the solid: %s\n", r->name);
 time(&tm);
 printf("// Generated by ""stl2pov"" ""2.4.4"" on %s", ctime(&tm));
 for (i=0; i<r->nv; i++) {
  if (r->v[i].refcnt<3) {
   open++;
  }
 }
 if (open==0) {
  printf("// - All vertices used by 3 or more " "triangles, good.\n");
 }
 open = 0;
 for (i=0; i<r->ne; i++) {
  if (r->e[i].refcnt!=2) {
   open++;
  }
 }
 if (open==0) {
  puts("// - All edges used by 2 triangles, good.");
 } else {
  puts("// ! Warning: some edges are not used by two triangles.");
  puts("//   (There might be visible gaps between triangles.)");
 }
 if ((2*r->ne)==(3*r->nf)) {
  puts("// - 2 x #edges == 3 x #triangles, good.");
 }
 if ((r->nf - r->ne + r->nv)==2) {
  puts("// - The solid meets Euler's Rule, good.");
 }
}

canonical_original_code:
void check_structure(struct stl_reader *r)
{
 int i; int open = 0;
 long tm;
 printf("// Name of the solid: %s\n", r->name);
 time(&tm);
 printf("// Generated by ""stl2pov"" ""2.4.4"" on %s", ctime(&tm));
 for (i=0; i<r->nv; i++) {
  if (r->v[i].refcnt<3) {
   open++;
  }
 }
 if (open==0) {
  printf("// - All vertices used by 3 or more " "triangles, good.\n");
 }
 open = 0;
 for (i=0; i<r->ne; i++) {
  if (r->e[i].refcnt!=2) {
   open++;
  }
 }
 if (open==0) {
  puts("// - All edges used by 2 triangles, good.");
 } else {
  puts("// ! Warning: some edges are not used by two triangles.");
  puts("//   (There might be visible gaps between triangles.)");
 }
 if ((2*r->ne)==(3*r->nf)) {
  puts("// - 2 x #edges == 3 x #triangles, good.");
 }
 if ((r->nf - r->ne + r->nv)==2) {
  puts("// - The solid meets Euler's Rule, good.");
 }
}

variable_types: struct stl_reader { char name[85]; struct vertex { float xyz[3]; int refcnt; } *v; struct edge { int vertex[2]; int facet[2]; int refcnt; } *e; struct facet { int vertex[3]; int edges[3]; float normal[3]; } *f; int nv; float pdone; char *buf; long buflen; int fmt; } *

variable_types: i int

variable_types: open int

variable_types: tm long

user_defined_types: struct stl_reader { char name[85]; struct vertex *v; struct edge *e; struct facet *f; int nv; float pdone; char *buf; long buflen; int fmt; }


variable_types: k int

variable_types: p double

user_defined_types: struct vertex { float xyz[3]; int refcnt; }

user_defined_types: struct edge { int vertex[2]; int facet[2]; int refcnt; }

user_defined_types: struct facet { int vertex[3]; int edges[3]; float normal[3]; }