main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
unsigned int v4; // er13
unsigned int v5; // er12
unsigned int v6; // ebp
unsigned int v7; // ebx
unsigned int v8; // er15
unsigned int v9; // er10
int v10; // eax
int v11; // edx
unsigned int v12; // er10
__int64 v13; // rsi
__int64 v14; // rax
int v15; // eax
unsigned int v16; // er10
__int64 v17; // r15
__int64 v18; // r11
__int64 v19; // rax
__int64 v20; // rax
unsigned int v21; // er10
__int64 v22; // rsi
int v23; // eax
unsigned int v24; // er10
__int64 v25; // rsi
__int64 v26; // rax
__int64 v27; // r11
int v28; // eax
int v29; // edx
int v30; // er10
__int64 v31; // rax
FILE *v32; // rdi
__int64 v33; // rdx
__int64 v35; // r11
__int64 v36; // r11
__int64 v37; // r11
__int64 v38; // rdi
__int64 v39; // rdx
__int64 v40; // [rsp+0h] [rbp-50h]
__int64 v41; // [rsp+0h] [rbp-50h]
unsigned int v42; // [rsp+0h] [rbp-50h]
int v43; // [rsp+10h] [rbp-40h]
int v44; // [rsp+14h] [rbp-3Ch]

v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
v7 = 0;
L2cache[0] = 0LL;
setLRUbitsToWay("testfile.din", "r", envp);
ifp = (__int64)fopen("testfile.din", "r");
ofp = fopen("display.txt", "w");
LABEL_2:
while ( (unsigned int)__isoc99_fscanf() != -1 )
{
++v6;
v8 = v44 >> 20;
v9 = (v44 >> 6) & 0x3FFF;
switch ( v43 )
{
case 0:
case 2:
++v5;
v15 = checkTag(v9, v8);
if ( v15 > 5 )
{
v38 = v16;
++v7;
v42 = checkLRU(v16, (unsigned int)v15);
updateLRU(v38, v42);
v19 = (int)v42;
v39 = (int)v42 + 16 * v18;
*(_DWORD *)(v39 * 16 + 4210856) = v8;
LODWORD(L2cache[v39]) = 1;
}
else
{
v40 = v15;
v17 = v15 + 16LL * (int)v16;
if ( LODWORD(L2cache[v17]) <= 2 )
{
++v3;
updateLRU(v16, (unsigned int)v15);
v19 = v40;
}
else
{
++v7;
updateLRU(v16, (unsigned int)v15);
v19 = v40;
LODWORD(L2cache[v17]) = 1;
}
}
HIDWORD(L2cache[16 * v18 + v19]) = v44;
break;
case 1:
++v4;
LODWORD(v20) = checkTag(v9, v8);
v22 = (unsigned int)v20;
if ( (int)v20 > 5 )
{
++v7;
LODWORD(v20) = checkLRU(v21, (unsigned int)v20);
v22 = (unsigned int)v20;
v20 = (int)v20;
DWORD2(L2cache[16 * v35 + (int)v20]) = v8;
}
else
{
v20 = (int)v20;
if ( LODWORD(L2cache[16 * (int)v21 + (int)v20]) > 2 )
++v7;
else
++v3;
}
v41 = v20;
updateLRU(v21, v22);
v37 = v41 + v36;
LODWORD(L2cache[v37]) = 0;
*(_DWORD *)(v37 * 16 + 4210860) = v44;
break;
case 3:
case 5:
v4 += v43 == 5;
v10 = checkTag(v9, v8);
v13 = (unsigned int)v10;
if ( v10 > 5 )
goto LABEL_6;
v14 = 16LL * (int)v12 + v10;
if ( LODWORD(L2cache[v14]) > 2 )
goto LABEL_6;
*(_DWORD *)(v14 * 16 + 4210860) = v11;
++v3;
LODWORD(L2cache[v14]) = 3;
updateLRU(v12, v13);
break;
case 4:
++v5;
v28 = checkTag(v9, v8);
if ( v28 <= 5 )
{
v31 = 16LL * v30 + v28;
if ( LODWORD(L2cache[v31]) > 2 )
goto LABEL_6;
LODWORD(L2cache[v31]) = 2;
++v3;
*(_DWORD *)(v31 * 16 + 4210860) = v29;
}
break;
case 6:
++v5;
v23 = checkTag(v9, v8);
v25 = (unsigned int)v23;
if ( v23 <= 5 )
{
v26 = 16LL * (int)v24 + v23;
if ( LODWORD(L2cache[v26]) > 2 )
{
LABEL_6:
++v7;
}
else
{
++v3;
LODWORD(L2cache[v26]) = 3;
updateLRU(v24, v25);
*(_DWORD *)(v27 + 12) = v44;
}
}
break;
case 8:
fprintf(
ofp,
"Reference %d called for the cache to be reset. No ways are valid.\n"
"---------------------------------------------------------------------\n",
v6);
v32 = ofp;
fflush(ofp);
setLRUbitsToWay(
v32,
"Reference %d called for the cache to be reset. No ways are valid.\n"
"---------------------------------------------------------------------\n",
v33);
break;
case 9:
fprintf(ofp, "Reference %d displayed only indices containing valid ways.\n", v6);
fflush(ofp);
cacheDisplay();
break;
default:
goto LABEL_2;
}
}
printf(
" Total References: %d\n"
" Reads: %d\n"
" Writes: %d\n"
" Hits: %d\n"
" Misses %d\n"
" Hit ratio: %f\n"
"---------------------------------------------------------------------\n",
v6,
v5,
v4,
(unsigned int)v3,
v7,
(float)((float)v3 / (float)(int)v6));
fflush(ofp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
unsigned int v4; // er13
unsigned int v5; // er12
unsigned int v6; // ebp
unsigned int v7; // ebx
unsigned int v8; // er15
unsigned int v9; // er10
int v10; // eax
int v11; // edx
unsigned int v12; // er10
__int64 v13; // rsi
__int64 v14; // rax
int v15; // eax
unsigned int v16; // er10
__int64 v17; // r15
__int64 v18; // r11
__int64 v19; // rax
__int64 v20; // rax
unsigned int v21; // er10
__int64 v22; // rsi
int v23; // eax
unsigned int v24; // er10
__int64 v25; // rsi
__int64 v26; // rax
__int64 v27; // r11
int v28; // eax
int v29; // edx
int v30; // er10
__int64 v31; // rax
FILE *v32; // rdi
__int64 v33; // rdx
__int64 v35; // r11
__int64 v36; // r11
__int64 v37; // r11
__int64 v38; // rdi
__int64 v39; // rdx
__int64 v40; // [rsp+0h] [rbp-50h]
__int64 v41; // [rsp+0h] [rbp-50h]
unsigned int v42; // [rsp+0h] [rbp-50h]
int v43; // [rsp+10h] [rbp-40h]
int v44; // [rsp+14h] [rbp-3Ch]

v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
v7 = 0;
L2cache[0] = 0LL;
setLRUbitsToWay("testfile.din", "r", envp);
ifp = (__int64)fopen("testfile.din", "r");
ofp = fopen("display.txt", "w");
LABEL_2:
while ( (unsigned int)__isoc99_fscanf() != -1 )
{
++v6;
v8 = v44 >> 20;
v9 = (v44 >> 6) & 0x3FFF;
switch ( v43 )
{
case 0:
case 2:
++v5;
v15 = func7(v9, v8);
if ( v15 > 5 )
{
v38 = v16;
++v7;
v42 = func8(v16, (unsigned int)v15);
func9(v38, v42);
v19 = (int)v42;
v39 = (int)v42 + 16 * v18;
*(_DWORD *)(v39 * 16 + 4210856) = v8;
LODWORD(L2cache[v39]) = 1;
}
else
{
v40 = v15;
v17 = v15 + 16LL * (int)v16;
if ( LODWORD(L2cache[v17]) <= 2 )
{
++v3;
func9(v16, (unsigned int)v15);
v19 = v40;
}
else
{
++v7;
func9(v16, (unsigned int)v15);
v19 = v40;
LODWORD(L2cache[v17]) = 1;
}
}
HIDWORD(L2cache[16 * v18 + v19]) = v44;
break;
case 1:
++v4;
LODWORD(v20) = func7(v9, v8);
v22 = (unsigned int)v20;
if ( (int)v20 > 5 )
{
++v7;
LODWORD(v20) = func8(v21, (unsigned int)v20);
v22 = (unsigned int)v20;
v20 = (int)v20;
DWORD2(L2cache[16 * v35 + (int)v20]) = v8;
}
else
{
v20 = (int)v20;
if ( LODWORD(L2cache[16 * (int)v21 + (int)v20]) > 2 )
++v7;
else
++v3;
}
v41 = v20;
func9(v21, v22);
v37 = v41 + v36;
LODWORD(L2cache[v37]) = 0;
*(_DWORD *)(v37 * 16 + 4210860) = v44;
break;
case 3:
case 5:
v4 += v43 == 5;
v10 = func7(v9, v8);
v13 = (unsigned int)v10;
if ( v10 > 5 )
goto LABEL_6;
v14 = 16LL * (int)v12 + v10;
if ( LODWORD(L2cache[v14]) > 2 )
goto LABEL_6;
*(_DWORD *)(v14 * 16 + 4210860) = v11;
++v3;
LODWORD(L2cache[v14]) = 3;
func9(v12, v13);
break;
case 4:
++v5;
v28 = func7(v9, v8);
if ( v28 <= 5 )
{
v31 = 16LL * v30 + v28;
if ( LODWORD(L2cache[v31]) > 2 )
goto LABEL_6;
LODWORD(L2cache[v31]) = 2;
++v3;
*(_DWORD *)(v31 * 16 + 4210860) = v29;
}
break;
case 6:
++v5;
v23 = func7(v9, v8);
v25 = (unsigned int)v23;
if ( v23 <= 5 )
{
v26 = 16LL * (int)v24 + v23;
if ( LODWORD(L2cache[v26]) > 2 )
{
LABEL_6:
++v7;
}
else
{
++v3;
LODWORD(L2cache[v26]) = 3;
func9(v24, v25);
*(_DWORD *)(v27 + 12) = v44;
}
}
break;
case 8:
fprintf(
ofp,
"Reference %d called for the cache to be reset. No ways are valid.\n"
"---------------------------------------------------------------------\n",
v6);
v32 = ofp;
fflush(ofp);
setLRUbitsToWay(
v32,
"Reference %d called for the cache to be reset. No ways are valid.\n"
"---------------------------------------------------------------------\n",
v33);
break;
case 9:
fprintf(ofp, "Reference %d displayed only indices containing valid ways.\n", v6);
fflush(ofp);
func11();
break;
default:
goto LABEL_2;
}
}
printf(
" Total References: %d\n"
" Reads: %d\n"
" Writes: %d\n"
" Hits: %d\n"
" Misses %d\n"
" Hit ratio: %f\n"
"---------------------------------------------------------------------\n",
v6,
v5,
v4,
(unsigned int)v3,
v7,
(float)((float)v3 / (float)(int)v6));
fflush(ofp);
return 0;
}

original_code:
int main()
{
  memset(L2cache, 0, sizeof (cacheLine));
  int refCount = 0;
  int readCount = 0;
  int writeCount = 0;
  int hitCount = 0;
  int missCount = 0;
  int hitM = 0;
  int hit = 0;
  int way;
  int n;
  int addr;
  setLRUbitsToWay();
  ifp = fopen("testfile.din", "r");
  ofp = fopen("display.txt", "w");
  while (fscanf(ifp, "%d %x\n", &n, &addr) != (-1))
  {
    int tag = addr >> 20;
    int index = (addr >> 6) & 16383;
    refCount++;
    switch (n)
    {
      case 0:
      case 2:
 readCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
    {
       hitCount++;
       updateLRU(index, way);
      }
    else
           {
       missCount++;
              updateLRU(index, way);
       L2cache[index][way].MESIbits = 1;
    }
 }
        else
   {
    missCount++;
    way = checkLRU(index);
           updateLRU(index, way);
           L2cache[index][way].tag = tag;
    L2cache[index][way].MESIbits = 1;
        }
        L2cache[index][way].address = addr;
 break;
      case 1:
 writeCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
       hitCount++;
           else
              missCount++;
        }
        else
   {
    missCount++;
    way = checkLRU(index);
           L2cache[index][way].tag = tag;
        }
        updateLRU(index, way);
        L2cache[index][way].MESIbits = 0;
        L2cache[index][way].address = addr;
      break;
      case 4:
 readCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
    {
       hitCount++;
              if (MESI == 0)
                 hitM++;
              else
                 hit++;
       L2cache[index][way].MESIbits = 2;
              L2cache[index][way].address = addr;
           }
           else
              missCount++;
        }
      break;
      case 3:
      case 5:
        if (n == 5)
           writeCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
              {
                 hitCount++;
          L2cache[index][way].MESIbits = 3;
                 L2cache[index][way].address = addr;
                 updateLRU(index, way);
              }
    else
              missCount++;
        }
        else
           missCount++;
      break;
      case 6:
 readCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
           {
              hitCount++;
              if (MESI == 0)
                 hitM++;
              L2cache[index][way].MESIbits = 3;
              updateLRU(index, way);
              L2cache[index][way].address = addr;
           }
           else
              missCount++;
       }
      break;
      case 8:
        fprintf(ofp,"Reference %d called for the cache to be reset. No ways are valid.\n"
                    "---------------------------------------------------------------------\n",
                    refCount);
        fflush(ofp);
        setLRUbitsToWay();
      break;
      case 9:
        fprintf(ofp,"Reference %d displayed only indices containing valid ways.\n",refCount);
        fflush(ofp);
        cacheDisplay();
        break;
    }
  }
  float hitRatio = (float) hitCount / refCount;
  printf(" Total References: %d\n Reads: %d\n Writes: %d\n Hits: %d\n"
         " Misses %d\n Hit ratio: %f\n"
         "---------------------------------------------------------------------\n",
         refCount,readCount,writeCount,hitCount,missCount,hitRatio);
  fflush(ofp);
  return 0;
}

variable_types: refCount int

variable_types: readCount int

variable_types: writeCount int

variable_types: hitCount int

variable_types: missCount int

variable_types: hitM int

variable_types: hit int

variable_types: way int

variable_types: n int

variable_types: addr int

variable_types: tag int

variable_types: index int

variable_types: MESI int

variable_types: hitRatio float


checkTag

decompiled_code:
__int64 __fastcall checkTag(int a1, int a2)
{
unsigned int v2; // er8
__int128 *i; // rax

v2 = 0;
for ( i = &L2cache[16 * (__int64)a1]; *((_DWORD *)i + 2) != a2; ++i )
{
if ( ++v2 == 6 )
return 16;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
unsigned int v2; // er8
__int128 *i; // rax

v2 = 0;
for ( i = &L2cache[16 * (__int64)a1]; *((_DWORD *)i + 2) != a2; ++i )
{
if ( ++v2 == 6 )
return 16;
}
return v2;
}

original_code:
int checkTag(int index, int tag)
{
  int way;
  for (way = 0; way <= 5; way++)
  {
    if (L2cache[index][way].tag == tag)
       return way;
  }
  return 16;
}

return_type: int


checkLRU

original_code:
int checkLRU(int index)
{
  int way;
  for (way = 0; way <= 5; way++)
  {
    if (L2cache[index][way].LRUbits == 0)
       return way;
  }
  return 16;
}


updateLRU

decompiled_code:
__int64 __fastcall updateLRU(int a1, int a2)
{
__int64 v2; // r9
__int64 result; // rax
int v4; // ecx
__int64 v5; // rdx
int v6; // edx

v2 = 16LL * a1;
result = 16 * (v2 + a2);
if ( *(_DWORD *)((char *)L2cache + result + 4) != 5 )
{
v4 = 0;
LABEL_3:
while ( 2 )
{
v5 = ((__int64)a1 << 8) + 4210848;
LODWORD(result) = 0;
while ( *(_DWORD *)(v5 + 4) != v4 )
{
result = (unsigned int)(result + 1);
v5 += 16LL;
if ( (_DWORD)result == 6 )
{
if ( ++v4 != 6 )
goto LABEL_3;
goto LABEL_7;
}
}
v6 = v4++ - 1;
result = 16 * (v2 + (int)result);
*(_DWORD *)(result + 4210852) = v6;
if ( v4 != 6 )
continue;
break;
}
LABEL_7:
DWORD1(L2cache[16 * a1 + a2]) = 5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
__int64 v2; // r9
__int64 result; // rax
int v4; // ecx
__int64 v5; // rdx
int v6; // edx

v2 = 16LL * a1;
result = 16 * (v2 + a2);
if ( *(_DWORD *)((char *)L2cache + result + 4) != 5 )
{
v4 = 0;
LABEL_3:
while ( 2 )
{
v5 = ((__int64)a1 << 8) + 4210848;
LODWORD(result) = 0;
while ( *(_DWORD *)(v5 + 4) != v4 )
{
result = (unsigned int)(result + 1);
v5 += 16LL;
if ( (_DWORD)result == 6 )
{
if ( ++v4 != 6 )
goto LABEL_3;
goto LABEL_7;
}
}
v6 = v4++ - 1;
result = 16 * (v2 + (int)result);
*(_DWORD *)(result + 4210852) = v6;
if ( v4 != 6 )
continue;
break;
}
LABEL_7:
DWORD1(L2cache[16 * a1 + a2]) = 5;
}
return result;
}

original_code:
void updateLRU(int index, int ourway)
{
  if (L2cache[index][ourway].LRUbits == 5)
     return;
  else
  {
     int ourbits = L2cache[index][ourway].LRUbits;
     int testbits = ourbits++;
     int testway;
     for (testbits = 0; testbits <= 5; testbits++)
     {
         testway = 0;
         while (testway <= 5)
         {
            if (testbits == L2cache[index][testway].LRUbits)
               {
                  L2cache[index][testway].LRUbits--;
                  break;
               }
            else
               testway++;
  }
     }
     L2cache[index][ourway].LRUbits = 5;
  }
}

variable_types: ourway int

variable_types: ourbits int

variable_types: testbits int

variable_types: testway int

return_type: void


testIndex

decompiled_code:
__int64 __fastcall testIndex(int a1)
{
__int64 v1; // rdx
_DWORD *v2; // rax
_DWORD *v3; // rdx

v1 = (__int64)a1 << 8;
v2 = (_DWORD *)((char *)L2cache + v1);
v3 = (_DWORD *)(v1 + 4210944);
while ( *v2 == 3 )
{
v2 += 4;
if ( v2 == v3 )
return 1LL;
}
return 0LL;
}

original_code:
int testIndex(int index, int way)
{
   for (way = 0; way <= 5; way++)
   {
       if (L2cache[index][way].MESIbits != 3)
       {
          return 0;
       }
   }
   return 1;
}


cacheDisplay

original_code:
void cacheDisplay()
{
   int index;
   int way;
   ofp = fopen("display.txt", "a");
   for (index = 0; index <= 16482; index++)
   {
      if (testIndex(index,way) == 0)
       {
           fprintf(ofp,"INDEX: 0x%-8x\n",index);
           fflush(ofp);
           for (way = 0; way <= 5; way++)
          {
             fprintf(ofp,"WAY %-8d LRU: %-4d MESI: %-10d TAG: %-8d"
                          " ADDR: 0x%-8x\n",
                          way,
                          L2cache[index][way].LRUbits,
                          L2cache[index][way].MESIbits,
                          L2cache[index][way].tag,
                          L2cache[index][way].address);
             fflush(ofp);
          }
      }
   }
   fprintf(ofp,"---------------------------------------------------------------------\n");
   fflush(ofp);
}


help

decompiled_code:
void __noreturn help()
{
puts("Usage:udp_scan\tdest\t[-s start_port]");
puts("\t\t\t[-e end_port]");
puts("\t\t\t[-i interval]");
puts("\t\t\t[-a attempts]");
puts("\t\t\t[-p payload]");
puts("\t\t\t[-w time_to_exit]");
puts("\t\t\t[-h help]");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("Usage:udp_scan\tdest\t[-s start_port]");
puts("\t\t\t[-e end_port]");
puts("\t\t\t[-i interval]");
puts("\t\t\t[-a attempts]");
puts("\t\t\t[-p payload]");
puts("\t\t\t[-w time_to_exit]");
puts("\t\t\t[-h help]");
exit(0);
}

original_code:
static void help(void)
{
 printf("Usage:udp_scan\tdest\t[-s start_port]\n");
 printf("\t\t\t[-e end_port]\n");
 printf("\t\t\t[-i interval]\n");
 printf("\t\t\t[-a attempts]\n");
 printf("\t\t\t[-p payload]\n");
 printf("\t\t\t[-w time_to_exit]\n");
 printf("\t\t\t[-h help]\n");
 exit(0);
}

canonical_original_code:
static void help()
{
 printf("Usage:udp_scan\tdest\t[-s start_port]\n");
 printf("\t\t\t[-e end_port]\n");
 printf("\t\t\t[-i interval]\n");
 printf("\t\t\t[-a attempts]\n");
 printf("\t\t\t[-p payload]\n");
 printf("\t\t\t[-w time_to_exit]\n");
 printf("\t\t\t[-h help]\n");
 exit(0);
}


alarmHanlder

decompiled_code:
unsigned int alarmHanlder()
{
return alarm(1u);
}

canonical_decompiled_code:
unsigned int func1()
{
return alarm(1u);
}

original_code:
static void alarmHanlder(int signo)
{
 alarm(1);
}

variable_types: signo int


sender

decompiled_code:
void __fastcall sender(unsigned __int16 *a1)
{
unsigned __int16 v1; // r13
int v2; // er12
unsigned __int16 j; // bx
size_t v4; // rdx
int v5; // ecx
socklen_t v6; // er9
__int16 v7; // bx
unsigned int i; // [rsp+0h] [rbp-510h]
unsigned __int16 v9; // [rsp+6h] [rbp-50Ah]
socklen_t addr_len; // [rsp+14h] [rbp-4FCh] BYREF
struct sockaddr addr; // [rsp+18h] [rbp-4F8h] BYREF
struct sockaddr v12; // [rsp+28h] [rbp-4E8h] BYREF
struct sigaction v13; // [rsp+38h] [rbp-4D8h] BYREF
char buf[1080]; // [rsp+D8h] [rbp-438h] BYREF

if ( a1 )
{
v1 = a1[1];
v9 = *a1;
v2 = socket(2, 2, 17);
if ( v2 < 0 )
{
perror("socket(AF_INET,SOCK_DGRAM,0) error");
exit(-1);
}
addr = 0LL;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = *((_DWORD *)a1 + 65);
strlen((const char *)a1 + 264);
setbuf(stdout, 0LL);
for ( i = 1; *((_DWORD *)a1 + 99) >= i; ++i )
{
printf("sending UDP packets(%d)", i);
for ( j = v9; v1 >= j; ++j )
{
*(_WORD *)addr.sa_data = _bswap_16(j);
if ( sendto(v2, a1 + 132, v4, v5, &addr, v6) < 0 )
{
perror("sendto error");
exit(-1);
}
usleep(*((_DWORD *)a1 + 98));
putchar(46);
}
printf("\ncomplete sending(%d)\n", i);
if ( *((_DWORD *)a1 + 99) == i )
break;
v7 = 20;
do
{
putchar(46);
usleep(0x186A0u);
--v7;
}
while ( v7 );
putchar(10);
}
puts("+++++++++++++++++++++++++++++\nall packets are sent!");
printf("wait %d seconds to exit!\n", *((unsigned int *)a1 + 102));
v13.sa_handler = (__sighandler_t)alarmHanlder;
sigemptyset(&v13.sa_mask);
v13.sa_flags = 0x20000000;
sigaction(14, &v13, 0LL);
alarm(*((_DWORD *)a1 + 102));
while ( recvfrom(v2, buf, 0x400uLL, 0, &v12, &addr_len) > 0 )
{
if ( *(_DWORD *)&v12.sa_data[2] == *(_DWORD *)&addr.sa_data[2] )
*(_BYTE *)(*((_QWORD *)a1 + 50) + (unsigned __int16)_bswap_16(*(__int16 *)v12.sa_data) - *a1) = 2;
}
close(v2);
}
}

canonical_decompiled_code:
void __fastcall func3(unsigned __int16 *a1)
{
unsigned __int16 v1; // r13
int v2; // er12
unsigned __int16 j; // bx
size_t v4; // rdx
int v5; // ecx
socklen_t v6; // er9
__int16 v7; // bx
unsigned int i; // [rsp+0h] [rbp-510h]
unsigned __int16 v9; // [rsp+6h] [rbp-50Ah]
socklen_t addr_len; // [rsp+14h] [rbp-4FCh] BYREF
struct sockaddr addr; // [rsp+18h] [rbp-4F8h] BYREF
struct sockaddr v12; // [rsp+28h] [rbp-4E8h] BYREF
struct sigaction v13; // [rsp+38h] [rbp-4D8h] BYREF
char buf[1080]; // [rsp+D8h] [rbp-438h] BYREF

if ( a1 )
{
v1 = a1[1];
v9 = *a1;
v2 = socket(2, 2, 17);
if ( v2 < 0 )
{
perror("socket(AF_INET,SOCK_DGRAM,0) error");
exit(-1);
}
addr = 0LL;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = *((_DWORD *)a1 + 65);
strlen((const char *)a1 + 264);
setbuf(stdout, 0LL);
for ( i = 1; *((_DWORD *)a1 + 99) >= i; ++i )
{
printf("sending UDP packets(%d)", i);
for ( j = v9; v1 >= j; ++j )
{
*(_WORD *)addr.sa_data = func2(j);
if ( sendto(v2, a1 + 132, v4, v5, &addr, v6) < 0 )
{
perror("sendto error");
exit(-1);
}
usleep(*((_DWORD *)a1 + 98));
putchar(46);
}
printf("\ncomplete sending(%d)\n", i);
if ( *((_DWORD *)a1 + 99) == i )
break;
v7 = 20;
do
{
putchar(46);
usleep(0x186A0u);
--v7;
}
while ( v7 );
putchar(10);
}
puts("+++++++++++++++++++++++++++++\nall packets are sent!");
printf("wait %d seconds to exit!\n", *((unsigned int *)a1 + 102));
v13.sa_handler = (__sighandler_t)alarmHanlder;
sigemptyset(&v13.sa_mask);
v13.sa_flags = 0x20000000;
sigaction(14, &v13, 0LL);
alarm(*((_DWORD *)a1 + 102));
while ( recvfrom(v2, buf, 0x400uLL, 0, &v12, &addr_len) > 0 )
{
if ( *(_DWORD *)&v12.sa_data[2] == *(_DWORD *)&addr.sa_data[2] )
*(_BYTE *)(*((_QWORD *)a1 + 50) + (unsigned __int16)func2(*(__int16 *)v12.sa_data) - *a1) = 2;
}
close(v2);
}
}

original_code:
void sender(struct scaninfo *arg)
{
 if (arg == ((void *)0))
  return;
 int sockfd;
 unsigned short i, start, end;
 int len, total;
 struct sockaddr_in servaddr;
 struct scaninfo *info = (struct scaninfo *) arg;
 start = info->start;
 end = info->end;
 if ((sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  perror("socket(AF_INET,SOCK_DGRAM,0) error");
  exit(-1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = 2;
 memcpy(&servaddr.sin_addr, &info->addr, sizeof(servaddr.sin_addr));
 len = strlen(info->data);
 setbuf(stdout, ((void *)0));
 for (total = 1; total <= info->attempts; total++) {
  printf("sending UDP packets(%d)", total);
  for (i = start; i <= end; i++) {
   servaddr.sin_port = htons(i);
   if (sendto(sockfd, info->data, len, 0,
        (struct sockaddr *) &servaddr,
        sizeof(servaddr)) < 0) {
    perror("sendto error");
    exit(-1);
   }
   usleep(info->interval);
   printf(".");
  }
  printf("\ncomplete sending(%d)\n", total);
  if (total == info->attempts)
   break;
  for (i = 1; i <= 20; i++) {
   printf(".");
   usleep(100000);
  }
  printf("\n");
 }
 printf("+++++++++++++++++++++++++++++\nall packets are sent!\n");
 printf("wait %d seconds to exit!\n", info->wait);
 struct sigaction act;
 act.__sigaction_handler.sa_handler = alarmHanlder;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0x20000000;
 sigaction(14, &act, ((void *)0));
 alarm(info->wait);
 char buf[1024];
 struct sockaddr_in recvaddr;
 socklen_t recvlen;
 ssize_t n;
 while ((n = recvfrom(sockfd, buf, 1024, 0,
       (struct sockaddr *) &recvaddr, &recvlen)) > 0) {
  if (recvaddr.sin_addr.s_addr == servaddr.sin_addr.s_addr) {
   unsigned short port = ntohs(recvaddr.sin_port);
   info->status[port - info->start] = 2;
  }
 }
 close(sockfd);
 return;
}

canonical_original_code:
void sender(struct scaninfo *arg)
{
 if (arg == ((void *)0))
  return;
 int sockfd;
 unsigned short i; unsigned short start; unsigned short end;
 int len; int total;
 struct sockaddr_in servaddr;
 struct scaninfo *info = (struct scaninfo *) arg;
 start = info->start;
 end = info->end;
 if ((sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  perror("socket(AF_INET,SOCK_DGRAM,0) error");
  exit(-1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = 2;
 memcpy(&servaddr.sin_addr, &info->addr, sizeof(servaddr.sin_addr));
 len = strlen(info->data);
 setbuf(stdout, ((void *)0));
 for (total = 1; total <= info->attempts; total++) {
  printf("sending UDP packets(%d)", total);
  for (i = start; i <= end; i++) {
   servaddr.sin_port = htons(i);
   if (sendto(sockfd, info->data, len, 0,
        (struct sockaddr *) &servaddr,
        sizeof(servaddr)) < 0) {
    perror("sendto error");
    exit(-1);
   }
   usleep(info->interval);
   printf(".");
  }
  printf("\ncomplete sending(%d)\n", total);
  if (total == info->attempts)
   break;
  for (i = 1; i <= 20; i++) {
   printf(".");
   usleep(100000);
  }
  printf("\n");
 }
 printf("+++++++++++++++++++++++++++++\nall packets are sent!\n");
 printf("wait %d seconds to exit!\n", info->wait);
 struct sigaction act;
 act.__sigaction_handler.sa_handler = alarmHanlder;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0x20000000;
 sigaction(14, &act, ((void *)0));
 alarm(info->wait);
 char buf[1024];
 struct sockaddr_in recvaddr;
 unsigned int recvlen;
 long n;
 while ((n = recvfrom(sockfd, buf, 1024, 0,
       (struct sockaddr *) &recvaddr, &recvlen)) > 0) {
  if (recvaddr.sin_addr.s_addr == servaddr.sin_addr.s_addr) {
   unsigned short port = ntohs(recvaddr.sin_port);
   info->status[port - info->start] = 2;
  }
 }
 close(sockfd);
 return;
}

variable_types: struct scaninfo { unsigned short start; unsigned short end; char hostname[256]; struct in_addr { unsigned int s_addr; } addr; char data[128]; unsigned int interval; unsigned int attempts; unsigned char *status; unsigned int wait; } *

variable_types: sockfd int

variable_types:
i
unsigned short

variable_types:
start
unsigned short

variable_types:
end
unsigned short

variable_types: len int

variable_types: total int

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 sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types:
buf
char [1024]

variable_types:
recvlen
unsigned int

variable_types: n long

variable_types:
port
unsigned short

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 sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct scaninfo { unsigned short start; unsigned short end; char hostname[256]; struct in_addr addr; char data[128]; unsigned int interval; unsigned int attempts; unsigned char *status; unsigned int wait; }

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

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


receiver

original_code:
void *receiver(void *arg)
{
 int sockfd;
 struct scaninfo *sip;
 struct sockaddr_in raddr;
 socklen_t len;
 char buf[4096];
 struct iphdr *ip;
 unsigned int iplen;
 struct icmphdr *icmp;
 struct udphdr *udp;
 char straddr[256];
 unsigned short start, end, total;
 unsigned short port;
 sip = (struct scaninfo *) arg;
 if (sip == ((void *)0))
  return ((void *)0);
 start = sip->start;
 end = sip->end;
 total = end - start + 1;
 if ((sockfd = socket(2, SOCK_RAW, IPPROTO_ICMP)) < 0) {
  perror("socket(AF_INET,SOCK_RAW,IPPROTO_ICMP) error");
  exit(-1);
 }
 setuid(getuid());
 memset(&raddr, 0, sizeof(raddr));
 len = sizeof(raddr);
 raddr.sin_family = 2;
 memcpy(&raddr.sin_addr, &sip->addr, sizeof(raddr.sin_addr));
 if (connect(sockfd, (struct sockaddr *) &raddr, len) < 0) {
  perror("connect error");
  exit(-1);
 }
 while (recv(sockfd, buf, 4096, 0) > 0) {
  ip = (struct iphdr *) buf;
  if (inet_ntop(2, &ip->saddr, straddr, 256) != 1)
   strncpy(straddr, "unknown", 256);
  if (ip->protocol == IPPROTO_ICMP) {
   iplen = ip->ihl << 2;
   icmp = (struct icmphdr *) (buf + iplen);
   if (icmp->type != 3 || icmp->code != 3) {
    printf
     ("an unexpected packet from %s, type = %d, code = %d\n",
      straddr, icmp->type, icmp->code);
    continue;
   }
   ip = (struct iphdr *) (buf + iplen + 8);
   iplen = ip->ihl << 2;
   udp = (struct udphdr *) ((char *) ip + iplen);
   port = ntohs(udp->dest);
   if (port < start || port > end) {
    printf("an unexpected packet from %s, udp port = %d\n",
        straddr, port);
    continue;
   }
   sip->status[port - start] = 1;
  }
 }
 close(sockfd);
 return ((void *)0);
}

canonical_original_code:
void *receiver(void *arg)
{
 int sockfd;
 struct scaninfo *sip;
 struct sockaddr_in raddr;
 unsigned int len;
 char buf[4096];
 struct iphdr *ip;
 unsigned int iplen;
 struct icmphdr *icmp;
 struct udphdr *udp;
 char straddr[256];
 unsigned short start; unsigned short end; unsigned short total;
 unsigned short port;
 sip = (struct scaninfo *) arg;
 if (sip == ((void *)0))
  return ((void *)0);
 start = sip->start;
 end = sip->end;
 total = end - start + 1;
 if ((sockfd = socket(2, SOCK_RAW, IPPROTO_ICMP)) < 0) {
  perror("socket(AF_INET,SOCK_RAW,IPPROTO_ICMP) error");
  exit(-1);
 }
 setuid(getuid());
 memset(&raddr, 0, sizeof(raddr));
 len = sizeof(raddr);
 raddr.sin_family = 2;
 memcpy(&raddr.sin_addr, &sip->addr, sizeof(raddr.sin_addr));
 if (connect(sockfd, (struct sockaddr *) &raddr, len) < 0) {
  perror("connect error");
  exit(-1);
 }
 while (recv(sockfd, buf, 4096, 0) > 0) {
  ip = (struct iphdr *) buf;
  if (inet_ntop(2, &ip->saddr, straddr, 256) != 1)
   strncpy(straddr, "unknown", 256);
  if (ip->protocol == IPPROTO_ICMP) {
   iplen = ip->ihl << 2;
   icmp = (struct icmphdr *) (buf + iplen);
   if (icmp->type != 3 || icmp->code != 3) {
    printf
     ("an unexpected packet from %s, type = %d, code = %d\n",
      straddr, icmp->type, icmp->code);
    continue;
   }
   ip = (struct iphdr *) (buf + iplen + 8);
   iplen = ip->ihl << 2;
   udp = (struct udphdr *) ((char *) ip + iplen);
   port = ntohs(udp->dest);
   if (port < start || port > end) {
    printf("an unexpected packet from %s, udp port = %d\n",
        straddr, port);
    continue;
   }
   sip->status[port - start] = 1;
  }
 }
 close(sockfd);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types:
len
unsigned int

variable_types:
buf
char [4096]

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types:
iplen
unsigned int

variable_types: struct icmphdr { unsigned char type; unsigned char code; unsigned short checksum; union { struct { unsigned short id; unsigned short sequence; } echo; unsigned int gateway; struct { unsigned short __glibc_reserved; unsigned short mtu; } frag; } un; } *

variable_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; } *

variable_types:
straddr
char [256]

variable_types:
total
unsigned short

return_type: void *


original_code:
void parse_scanpara(int argc, char *argv[], struct scaninfo *info)
{
 if (info == ((void *)0))
  return;
 memset(info, 0, sizeof(struct scaninfo));
 info->attempts = 1;
 info->interval = 500000;
 strncpy(info->data, "hello world!", 128);
 int opt;
 struct option longopts[] = {
  {"help", 0, ((void *)0), 'h'},
  {"start-port", 1, ((void *)0), 's'},
  {"end-port", 1, ((void *)0), 'e'},
  {"interval", 1, ((void *)0), 'i'},
  {"attempts", 1, ((void *)0), 'a'},
  {"payload", 1, ((void *)0), 'p'},
  {"wait", 1, ((void *)0), 'w'},
  {0, 0, 0, 0}
 };
 while ((opt =
   getopt_long(argc, argv, "hs:e:i:a:p:w:", longopts,
      ((void *)0))) != -1) {
  switch (opt) {
  case 'h':
   help();
   break;
  case 's':
   info->start = atoi(optarg);
   break;
  case 'e':
   info->end = atoi(optarg);
   break;
  case 'i':
   info->interval = atoi(optarg) * 1000;
   break;
  case 'a':
   info->attempts = atoi(optarg);
   break;
  case 'p':
   strncpy(info->data, optarg, 128);
   break;
  case 'w':
   info->wait = atoi(optarg);
   break;
  default:
   help();
   break;
  }
 }
 if (optind != argc - 1)
  help();
 if (info->start == 0 || info->end == 0 || info->end < info->start
  || info->attempts <= 0) {
  fprintf(stderr, "Invalid port number or attempts\n");
  exit(-1);
 }
 if (info->wait == 0) {
  info->wait =
   info->interval / 1000000.0 * (info->end - info->start + 1);
  if (info->wait == 0) {
   info->wait = 1;
  }
 }
 info->status =
  (unsigned char *) malloc((info->end - info->start + 1) *
         sizeof(unsigned char));
 if (info->status == ((void *)0)) {
  perror("malloc error");
  exit(-1);
 }
 memset(info->status, 0, info->end - info->start + 1);
 if (inet_pton(2, argv[optind], &info->addr) != 1) {
  struct hostent *hp;
  if ((hp = gethostbyname(argv[optind])) == ((void *)0)) {
   fprintf(stderr, "Invalid destination - %s\n", argv[optind]);
   exit(-1);
  }
  strncpy(info->hostname, argv[optind], 256);
  memcpy(&info->addr, hp->h_addr_list[0], sizeof(info->addr));
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct scaninfo { unsigned short start; unsigned short end; char hostname[256]; struct in_addr { unsigned int s_addr; } addr; char data[128]; unsigned int interval; unsigned int attempts; unsigned char *status; unsigned int wait; } *

variable_types: opt int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
void *__fastcall listen_in_port(void *a1)
{
int v1; // eax
int v2; // ebp
socklen_t v3; // edx
socklen_t v4; // er9
unsigned __int16 v5; // bx
char *v6; // rax
signed __int64 v7; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-10ACh] BYREF
struct sockaddr v10; // [rsp+10h] [rbp-10A8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-1098h] BYREF
char buf[4120]; // [rsp+A0h] [rbp-1018h] BYREF

v1 = socket(2, 2, 17);
if ( v1 < 0 )
{
perror("socket error");
exit(-1);
}
v2 = v1;
*(_QWORD *)&v10.sa_data[6] = 0LL;
v10.sa_family = 2;
*(_QWORD *)&v10.sa_data[2] = (unsigned int)_bswap_32_constprop_0((unsigned __int16)a1, &v10, 16LL);
*(_WORD *)v10.sa_data = _bswap_16((__int16)a1);
if ( bind(v2, &v10, v3) < 0 )
{
perror("bind error");
exit(-1);
}
while ( 1 )
{
v7 = recvfrom(v2, buf, 0x1000uLL, 0, &addr, &addr_len);
if ( v7 <= 0 )
break;
v4 = addr_len;
buf[v7] = 0;
sendto(v2, buf, v7, 0, &addr, v4);
v5 = _bswap_16(*(__int16 *)addr.sa_data);
v6 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("Receive from %s:%u\t%s\n", v6, v5, buf);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
int v1; // eax
int v2; // ebp
socklen_t v3; // edx
socklen_t v4; // er9
unsigned __int16 v5; // bx
char *v6; // rax
signed __int64 v7; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-10ACh] BYREF
struct sockaddr v10; // [rsp+10h] [rbp-10A8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-1098h] BYREF
char buf[4120]; // [rsp+A0h] [rbp-1018h] BYREF

v1 = socket(2, 2, 17);
if ( v1 < 0 )
{
perror("socket error");
exit(-1);
}
v2 = v1;
*(_QWORD *)&v10.sa_data[6] = 0LL;
v10.sa_family = 2;
*(_QWORD *)&v10.sa_data[2] = (unsigned int)func8((unsigned __int16)a1, &v10, 16LL);
*(_WORD *)v10.sa_data = func7((__int16)a1);
if ( bind(v2, &v10, v3) < 0 )
{
perror("bind error");
exit(-1);
}
while ( 1 )
{
v7 = recvfrom(v2, buf, 0x1000uLL, 0, &addr, &addr_len);
if ( v7 <= 0 )
break;
v4 = addr_len;
buf[v7] = 0;
sendto(v2, buf, v7, 0, &addr, v4);
v5 = func7(*(__int16 *)addr.sa_data);
v6 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("Receive from %s:%u\t%s\n", v6, v5, buf);
}
return 0LL;
}

original_code:
static void *listen_in_port(void *arg)
{
 unsigned int port = (unsigned int) (long) arg;
 int sockfd;
 struct sockaddr_in servaddr;
 if ((sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  perror("socket error");
  exit(-1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = 2;
 servaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 servaddr.sin_port = htons(port);
 if (bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
  perror("bind error");
  exit(-1);
 }
 char buf[4096];
 struct sockaddr_storage recvaddr;
 socklen_t addrlen;
 ssize_t n;
 while ((n =
   recvfrom(sockfd, buf, 4096, 0, (struct sockaddr *) &recvaddr,
      &addrlen)) > 0) {
  buf[n] = '\0';
  sendto(sockfd, buf, n, 0, (struct sockaddr *) &recvaddr, addrlen);
  printf("Receive from %s:%u\t%s\n",
      inet_ntoa(((struct sockaddr_in *) &recvaddr)->sin_addr),
      ntohs(((struct sockaddr_in *) &recvaddr)->sin_port), buf);
 }
 return ((void *)0);
}

canonical_original_code:
static void *listen_in_port(void *arg)
{
 unsigned int port = (unsigned int) (long) arg;
 int sockfd;
 struct sockaddr_in servaddr;
 if ((sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  perror("socket error");
  exit(-1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = 2;
 servaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 servaddr.sin_port = htons(port);
 if (bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
  perror("bind error");
  exit(-1);
 }
 char buf[4096];
 struct sockaddr_storage recvaddr;
 unsigned int addrlen;
 long n;
 while ((n =
   recvfrom(sockfd, buf, 4096, 0, (struct sockaddr *) &recvaddr,
      &addrlen)) > 0) {
  buf[n] = '\0';
  sendto(sockfd, buf, n, 0, (struct sockaddr *) &recvaddr, addrlen);
  printf("Receive from %s:%u\t%s\n",
      inet_ntoa(((struct sockaddr_in *) &recvaddr)->sin_addr),
      ntohs(((struct sockaddr_in *) &recvaddr)->sin_port), buf);
 }
 return ((void *)0);
}

variable_types:
port
unsigned int

variable_types: sockfd int

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_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
addrlen
unsigned int

variable_types: n long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t v3; // rbx
pthread_t v4; // rbp
const char **v5; // rbx
unsigned int v6; // eax
pthread_t newthread[4]; // [rsp+0h] [rbp-20h] BYREF

if ( argc > 1 )
{
newthread[3] = v4;
newthread[2] = v3;
v5 = argv + 1;
while ( 1 )
{
v6 = atoi(*v5);
if ( v6 )
{
if ( pthread_create(newthread, 0LL, listen_in_port, (void *)v6) < 0 )
{
perror("pthread_create error");
exit(0);
}
if ( pthread_detach(newthread[0]) < 0 )
{
perror("pthread_detach error");
exit(0);
}
}
if ( ++v5 == &argv[(unsigned int)(argc - 2) + 2] )
{
while ( 1 )
;
}
}
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 unsigned int port = 0;
 int i;
 pthread_t tid;
 if (argc <= 1)
  return;
 for (i = 1; i < argc; i++) {
  port = atoi(argv[i]);
  if (port > 0) {
   if (pthread_create
    (&tid, ((void *)0), listen_in_port, (void *) (long) port) < 0) {
    perror("pthread_create error");
    exit(0);
   }
   if (pthread_detach(tid) < 0) {
    perror("pthread_detach error");
    exit(0);
   }
  }
 }
 while (1);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned int port = 0;
 int i;
 unsigned long tid;
 if (argc <= 1)
  return;
 for (i = 1; i < argc; i++) {
  port = atoi(argv[i]);
  if (port > 0) {
   if (pthread_create
    (&tid, ((void *)0), listen_in_port, (void *) (long) port) < 0) {
    perror("pthread_create error");
    exit(0);
   }
   if (pthread_detach(tid) < 0) {
    perror("pthread_detach error");
    exit(0);
   }
  }
 }
 while (1);
 return 0;
}

variable_types: i int

variable_types:
tid
unsigned long


decompiled_code:
int show_result()
{
unsigned __int16 v0; // bp
__int64 v1; // rbx
int v2; // er12
__int64 v3; // rbx
int v4; // er12
__int64 v5; // rbx
int v6; // er12

v0 = word_1A2 + 1 - info;
printf("\nopen port:\t");
if ( v0 )
{
v1 = 0LL;
v2 = 0;
do
{
if ( *(_BYTE *)(qword_330 + v1) == 2 )
{
++v2;
printf("%d ", (unsigned int)v1 + (unsigned __int16)info);
if ( (_WORD)v2 == 10 )
{
v2 = 0;
printf("\n\t\t");
}
}
++v1;
}
while ( v0 > (unsigned __int16)v1 );
v3 = 0LL;
v4 = 0;
printf("\nclosed port:\t");
do
{
if ( *(_BYTE *)(qword_330 + v3) == 1 )
{
++v4;
printf("%d ", (unsigned int)v3 + (unsigned __int16)info);
if ( (_WORD)v4 == 10 )
{
v4 = 0;
printf("\n\t\t");
}
}
++v3;
}
while ( v0 > (unsigned __int16)v3 );
v5 = 0LL;
v6 = 0;
printf("\nunknown port:\t");
do
{
if ( !*(_BYTE *)(qword_330 + v5) )
{
++v6;
printf("%d ", (unsigned int)v5 + (unsigned __int16)info);
if ( (_WORD)v6 == 10 )
{
v6 = 0;
printf("\n\t\t");
}
}
++v5;
}
while ( v0 > (unsigned __int16)v5 );
}
else
{
printf("\nclosed port:\t");
printf("\nunknown port:\t");
}
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
unsigned __int16 v0; // bp
__int64 v1; // rbx
int v2; // er12
__int64 v3; // rbx
int v4; // er12
__int64 v5; // rbx
int v6; // er12

v0 = word_1A2 + 1 - info;
printf("\nopen port:\t");
if ( v0 )
{
v1 = 0LL;
v2 = 0;
do
{
if ( *(_BYTE *)(qword_330 + v1) == 2 )
{
++v2;
printf("%d ", (unsigned int)v1 + (unsigned __int16)info);
if ( (_WORD)v2 == 10 )
{
v2 = 0;
printf("\n\t\t");
}
}
++v1;
}
while ( v0 > (unsigned __int16)v1 );
v3 = 0LL;
v4 = 0;
printf("\nclosed port:\t");
do
{
if ( *(_BYTE *)(qword_330 + v3) == 1 )
{
++v4;
printf("%d ", (unsigned int)v3 + (unsigned __int16)info);
if ( (_WORD)v4 == 10 )
{
v4 = 0;
printf("\n\t\t");
}
}
++v3;
}
while ( v0 > (unsigned __int16)v3 );
v5 = 0LL;
v6 = 0;
printf("\nunknown port:\t");
do
{
if ( !*(_BYTE *)(qword_330 + v5) )
{
++v6;
printf("%d ", (unsigned int)v5 + (unsigned __int16)info);
if ( (_WORD)v6 == 10 )
{
v6 = 0;
printf("\n\t\t");
}
}
++v5;
}
while ( v0 > (unsigned __int16)v5 );
}
else
{
printf("\nclosed port:\t");
printf("\nunknown port:\t");
}
return putchar(10);
}

original_code:
static void show_result(void)
{
 unsigned short total;
 unsigned short i, j;
 total = info.end - info.start + 1;
 printf("\nopen port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 2) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\nclosed port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 1) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\nunknown port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 0) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\n");
}

canonical_original_code:
static void show_result()
{
 unsigned short total;
 unsigned short i; unsigned short j;
 total = info.end - info.start + 1;
 printf("\nopen port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 2) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\nclosed port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 1) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\nunknown port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 0) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\n");
}

variable_types:
i
unsigned short

variable_types:
j
unsigned short


decompiled_code:
void __noreturn sig_int()
{
show_result();
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
func0();
exit(0);
}

original_code:
static void sig_int(int signo)
{
 show_result();
 exit(0);
}

variable_types: signo int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

parse_scanpara(argc, argv, &info);
signal(2, (__sighandler_t)sig_int);
if ( pthread_create(newthread, 0LL, (void *(*)(void *))&receiver, &info) )
{
perror("pthread_create error");
exit(-1);
}
if ( pthread_detach(newthread[0]) )
{
perror("pthread_detach error");
exit(-1);
}
sender(&info);
show_result();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

parse_scanpara(argc, argv, &info);
signal(2, (__sighandler_t)sig_int);
if ( pthread_create(newthread, 0LL, (void *(*)(void *))&receiver, &info) )
{
perror("pthread_create error");
exit(-1);
}
if ( pthread_detach(newthread[0]) )
{
perror("pthread_detach error");
exit(-1);
}
sender(&info);
func0();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t rid;
 parse_scanpara(argc, argv, &info);
 if (signal(2, sig_int) < 0) {
  perror("signal error");
  exit(-1);
 }
 if (pthread_create(&rid, ((void *)0), receiver, &info) != 0) {
  perror("pthread_create error");
  exit(-1);
 }
 if (pthread_detach(rid) != 0) {
  perror("pthread_detach error");
  exit(-1);
 }
 sender(&info);
 show_result();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long rid;
 parse_scanpara(argc, argv, &info);
 if (signal(2, sig_int) < 0) {
  perror("signal error");
  exit(-1);
 }
 if (pthread_create(&rid, ((void *)0), receiver, &info) != 0) {
  perror("pthread_create error");
  exit(-1);
 }
 if (pthread_detach(rid) != 0) {
  perror("pthread_detach error");
  exit(-1);
 }
 sender(&info);
 show_result();
 return 0;
}

variable_types: argc int

variable_types:
rid
unsigned long


repo: wikimedia/analytics-kafkatee

decompiled_code:
__int64 __fastcall child_proc_find(int a1)
{
__int64 result; // rax

for ( result = child_procs; result; result = *(_QWORD *)result )
{
if ( *(_DWORD *)(result + 16) == a1 )
break;
}
return result;
}

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

for ( result = child_procs; result; result = *(_QWORD *)result )
{
if ( *(_DWORD *)(result + 16) == a1 )
break;
}
return result;
}

original_code:
static struct child_proc *child_proc_find (pid_t pid) {
 struct child_proc *cp;
 for ((cp) = ((&child_procs)->lh_first); (cp); (cp) = ((cp)->link.le_next))
  if (cp->pid == pid)
   return cp;
 return ((void *)0);
}

canonical_original_code:
static struct child_proc *child_proc_find(int pid) {
 struct child_proc *cp;
 for ((cp) = ((&child_procs)->lh_first); (cp); (cp) = ((cp)->link.le_next))
  if (cp->pid == pid)
   return cp;
 return ((void *)0);
}

variable_types: pid int

variable_types: struct child_proc { struct { struct child_proc *le_next; struct child_proc **le_prev; } link; int pid; char *cmd; long t_start; int *statusp; } *


sigchld

decompiled_code:
void sigchld()
{
_InterlockedExchange(&do_child_proc_reap, 1);
}

canonical_decompiled_code:
void func2()
{
_InterlockedExchange(&do_child_proc_reap, 1);
}

original_code:
static void sigchld (int sig) {
 __sync_lock_test_and_set(&do_child_proc_reap,1);
}

canonical_original_code:
static void sigchld(int sig) {
 __sync_lock_test_and_set(&do_child_proc_reap,1);
}

variable_types: sig int


decompiled_code:
void __fastcall child_proc_del(void *ptr)
{
__int64 v1; // rax
_QWORD *v3; // rdx
void *v4; // rdi

v1 = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
*(_QWORD *)(v1 + 8) = *((_QWORD *)ptr + 1);
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
v4 = (void *)*((_QWORD *)ptr + 3);
*v3 = v1;
free(v4);
free(ptr);
_InterlockedSub(&child_proc_cnt, 1u);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
__int64 v1; // rax
_QWORD *v3; // rdx
void *v4; // rdi

v1 = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
*(_QWORD *)(v1 + 8) = *((_QWORD *)ptr + 1);
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
v4 = (void *)*((_QWORD *)ptr + 3);
*v3 = v1;
free(v4);
free(ptr);
_InterlockedSub(&child_proc_cnt, 1u);
}

original_code:
static void child_proc_del (struct child_proc *cp) {
 do { if ((cp)->link.le_next != ((void *)0)) (cp)->link.le_next->link.le_prev = (cp)->link.le_prev; *(cp)->link.le_prev = (cp)->link.le_next; } while ( 0);
 free(cp->cmd);
 free(cp);
 __sync_sub_and_fetch(&child_proc_cnt,1);
}

canonical_original_code:
static void child_proc_del(struct child_proc *cp) {
 do { if ((cp)->link.le_next != ((void *)0)) (cp)->link.le_next->link.le_prev = (cp)->link.le_prev; *(cp)->link.le_prev = (cp)->link.le_next; } while ( 0);
 free(cp->cmd);
 free(cp);
 __sync_sub_and_fetch(&child_proc_cnt,1);
}

user_defined_types: struct child_proc { struct { struct child_proc *le_next; struct child_proc **le_prev; } link; int pid; char *cmd; long t_start; int *statusp; }


decompiled_code:
__int64 __fastcall kt_popen(char *s, _BYTE *a2, int *a3, _DWORD *a4, char *a5, size_t a6)
{
int v11; // eax
unsigned int v12; // er8
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
__pid_t v18; // eax
__int64 v19; // rcx
int v20; // ebx
struct sigaction *v21; // rdi
int v22; // edi
int pipedes[2]; // [rsp+18h] [rbp-E0h] BYREF
struct sigaction v24; // [rsp+20h] [rbp-D8h] BYREF

if ( pipe2(pipedes, 0x80000) == -1 )
{
v14 = _errno_location();
v15 = strerror(*v14);
snprintf(a5, a6, "pipe failed: %s", v15);
v12 = -1;
}
else
{
pthread_mutex_lock(&child_proc_lock);
v11 = fork();
if ( v11 == -1 )
{
pthread_mutex_unlock(&child_proc_lock);
v16 = _errno_location();
v17 = strerror(*v16);
snprintf(a5, a6, "fork failed: %s", v17);
close(pipedes[0]);
close(pipedes[1]);
v12 = -1;
}
else
{
if ( !v11 )
{
pthread_mutex_unlock(&child_proc_lock);
v18 = getpid();
setpgid(0, v18);
if ( *a2 == 119 )
{
close(pipedes[1]);
if ( pipedes[0] )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
}
}
else
{
close(pipedes[0]);
if ( pipedes[1] != 1 )
{
dup2(pipedes[1], 1);
close(pipedes[1]);
}
}
v19 = 38LL;
v20 = 1;
v21 = &v24;
while ( v19 )
{
LODWORD(v21->sa_handler) = 0;
v21 = (struct sigaction *)((char *)v21 + 4);
--v19;
}
sigemptyset(&v24.sa_mask);
do
{
v22 = v20++;
sigaction(v22, &v24, 0LL);
}
while ( v20 != 65 );
ezd_thread_sigmask(1LL, 0LL, 0xFFFFFFFFLL);
execl("/bin/sh", "sh", "-c", s, 0LL);
exit(127);
}
*a3 = v11;
child_proc_add(s, v11, a4);
pthread_mutex_unlock(&child_proc_lock);
if ( *a2 == 119 )
{
close(pipedes[0]);
v12 = pipedes[1];
}
else
{
close(pipedes[1]);
v12 = pipedes[0];
}
}
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, _BYTE *a2, int *a3, _DWORD *a4, char *a5, size_t a6)
{
int v11; // eax
unsigned int v12; // er8
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
__pid_t v18; // eax
__int64 v19; // rcx
int v20; // ebx
struct sigaction *v21; // rdi
int v22; // edi
int pipedes[2]; // [rsp+18h] [rbp-E0h] BYREF
struct sigaction v24; // [rsp+20h] [rbp-D8h] BYREF

if ( pipe2(pipedes, 0x80000) == -1 )
{
v14 = _errno_location();
v15 = strerror(*v14);
snprintf(a5, a6, "pipe failed: %s", v15);
v12 = -1;
}
else
{
pthread_mutex_lock(&child_proc_lock);
v11 = fork();
if ( v11 == -1 )
{
pthread_mutex_unlock(&child_proc_lock);
v16 = _errno_location();
v17 = strerror(*v16);
snprintf(a5, a6, "fork failed: %s", v17);
close(pipedes[0]);
close(pipedes[1]);
v12 = -1;
}
else
{
if ( !v11 )
{
pthread_mutex_unlock(&child_proc_lock);
v18 = getpid();
setpgid(0, v18);
if ( *a2 == 119 )
{
close(pipedes[1]);
if ( pipedes[0] )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
}
}
else
{
close(pipedes[0]);
if ( pipedes[1] != 1 )
{
dup2(pipedes[1], 1);
close(pipedes[1]);
}
}
v19 = 38LL;
v20 = 1;
v21 = &v24;
while ( v19 )
{
LODWORD(v21->sa_handler) = 0;
v21 = (struct sigaction *)((char *)v21 + 4);
--v19;
}
sigemptyset(&v24.sa_mask);
do
{
v22 = v20++;
sigaction(v22, &v24, 0LL);
}
while ( v20 != 65 );
ezd_thread_sigmask(1LL, 0LL, 0xFFFFFFFFLL);
execl("/bin/sh", "sh", "-c", s, 0LL);
exit(127);
}
*a3 = v11;
func1(s, v11, a4);
pthread_mutex_unlock(&child_proc_lock);
if ( *a2 == 119 )
{
close(pipedes[0]);
v12 = pipedes[1];
}
else
{
close(pipedes[1]);
v12 = pipedes[0];
}
}
}
return v12;
}

original_code:
int kt_popen (const char *cmdstring, const char *rw,
       pid_t *pidp, int *statusp,
       char *errstr, size_t errstr_size) {
 int pfd[2], i;
 pid_t pid;
 struct sigaction sig_action;
 if (pipe2(pfd, 02000000) == -1) {
  snprintf(errstr, errstr_size,
    "pipe failed: %s", strerror((*__errno_location ())));
  return -1;
 }
 pthread_mutex_lock(&child_proc_lock);
 if ((pid = fork()) == -1) {
  pthread_mutex_unlock(&child_proc_lock);
  snprintf(errstr, errstr_size,
    "fork failed: %s", strerror((*__errno_location ())));
  close(pfd[0]);
  close(pfd[1]);
  return -1;
 }
 if (pid != 0) {
  *pidp = pid;
  child_proc_add(cmdstring, pid, statusp);
  pthread_mutex_unlock(&child_proc_lock);
  if (*rw == 'w') {
   close(pfd[0]);
   return pfd[1];
  } else {
   close(pfd[1]);
   return pfd[0];
  }
 }
 pthread_mutex_unlock(&child_proc_lock);
 setpgid(0, getpid());
 if (*rw == 'w') {
  close(pfd[1]);
  if (pfd[0] != 0) {
   dup2(pfd[0], 0);
   close(pfd[0]);
  }
 } else {
  close(pfd[0]);
  if (pfd[1] != 1) {
   dup2(pfd[1], 1);
   close(pfd[1]);
  }
 }
 memset(&sig_action, 0, sizeof(sig_action));
 sig_action.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
 sig_action.sa_flags = 0;
 sigemptyset(&sig_action.sa_mask);
 for (i = 1 ; i < (64 + 1) ; i++) {
  sigaction(i, &sig_action, ((void *)0));
 }
 ezd_thread_sigmask(1, 0, -1);
 execl("/bin/sh", "sh", "-c", cmdstring, ((void *)0));
 _exit(127);
}

canonical_original_code:
int kt_popen(char *cmdstring, char *rw, int *pidp, int *statusp, char *errstr, unsigned long errstr_size) {
 int pfd[2]; int i;
 int pid;
 struct sigaction sig_action;
 if (pipe2(pfd, 02000000) == -1) {
  snprintf(errstr, errstr_size,
    "pipe failed: %s", strerror((*__errno_location ())));
  return -1;
 }
 pthread_mutex_lock(&child_proc_lock);
 if ((pid = fork()) == -1) {
  pthread_mutex_unlock(&child_proc_lock);
  snprintf(errstr, errstr_size,
    "fork failed: %s", strerror((*__errno_location ())));
  close(pfd[0]);
  close(pfd[1]);
  return -1;
 }
 if (pid != 0) {
  *pidp = pid;
  child_proc_add(cmdstring, pid, statusp);
  pthread_mutex_unlock(&child_proc_lock);
  if (*rw == 'w') {
   close(pfd[0]);
   return pfd[1];
  } else {
   close(pfd[1]);
   return pfd[0];
  }
 }
 pthread_mutex_unlock(&child_proc_lock);
 setpgid(0, getpid());
 if (*rw == 'w') {
  close(pfd[1]);
  if (pfd[0] != 0) {
   dup2(pfd[0], 0);
   close(pfd[0]);
  }
 } else {
  close(pfd[0]);
  if (pfd[1] != 1) {
   dup2(pfd[1], 1);
   close(pfd[1]);
  }
 }
 memset(&sig_action, 0, sizeof(sig_action));
 sig_action.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
 sig_action.sa_flags = 0;
 sigemptyset(&sig_action.sa_mask);
 for (i = 1 ; i < (64 + 1) ; i++) {
  sigaction(i, &sig_action, ((void *)0));
 }
 ezd_thread_sigmask(1, 0, -1);
 execl("/bin/sh", "sh", "-c", cmdstring, ((void *)0));
 _exit(127);
}

variable_types:
cmdstring
char *

variable_types:
rw
char *

variable_types:
pidp
int *

variable_types:
statusp
int *

variable_types:
errstr
char *

variable_types:
pfd
int [2]

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }


decompiled_code:
char *__fastcall exec_exitstatus(unsigned int a1)
{
unsigned __int64 v1; // rbx
char *result; // rax
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rbx

if ( (a1 & 0x7F) != 0 )
{
if ( (char)((a1 & 0x7F) + 1) <= 1 )
{
v4 = __readfsqword(0);
snprintf((char *)&ret_0 + v4, 0x80uLL, "exited with code %i", a1);
result = (char *)&ret_0 + v4;
}
else
{
v3 = __readfsqword(0);
if ( (a1 & 0x80) != 0 )
strcpy((char *)&ret_0, "core dumped");
else
snprintf((char *)&ret_0 + v3, 0x80uLL, "terminated by signal %i", a1 & 0x7F);
result = (char *)&ret_0 + v3;
}
}
else
{
v1 = __readfsqword(0);
if ( BYTE1(a1) == 127 )
{
strcpy((char *)&qword_A50, "e command");
result = (char *)&ret_0 + v1;
ret_0 = (__int128)_mm_load_si128((const __m128i *)&LC8);
}
else
{
snprintf((char *)&ret_0 + v1, 0x80uLL, "exited with status %i", BYTE1(a1));
result = (char *)&ret_0 + v1;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1)
{
unsigned __int64 v1; // rbx
char *result; // rax
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rbx

if ( (a1 & 0x7F) != 0 )
{
if ( (char)((a1 & 0x7F) + 1) <= 1 )
{
v4 = __readfsqword(0);
snprintf((char *)&ret_0 + v4, 0x80uLL, "exited with code %i", a1);
result = (char *)&ret_0 + v4;
}
else
{
v3 = __readfsqword(0);
if ( (a1 & 0x80) != 0 )
strcpy((char *)&ret_0, "core dumped");
else
snprintf((char *)&ret_0 + v3, 0x80uLL, "terminated by signal %i", a1 & 0x7F);
result = (char *)&ret_0 + v3;
}
}
else
{
v1 = __readfsqword(0);
if ( BYTE1(a1) == 127 )
{
strcpy((char *)&qword_A50, "e command");
result = (char *)&ret_0 + v1;
ret_0 = (__int128)_mm_load_si128((const __m128i *)&LC8);
}
else
{
snprintf((char *)&ret_0 + v1, 0x80uLL, "exited with status %i", BYTE1(a1));
result = (char *)&ret_0 + v1;
}
}
return result;
}

original_code:
const char *exec_exitstatus (int status) {
 static __thread char ret[128];
 if ((((status) & 0x7f) == 0)) {
  if ((((status) & 0xff00) >> 8) == 127)
   snprintf(ret, sizeof(ret),
     "could not execute command");
  else
   snprintf(ret, sizeof(ret), "exited with status %i",
     (((status) & 0xff00) >> 8));
 } else if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0)) {
  if (((status) & 0x80))
   snprintf(ret, sizeof(ret), "core dumped");
  else
   snprintf(ret, sizeof(ret), "terminated by signal %i",
     ((status) & 0x7f));
 } else
  snprintf(ret, sizeof(ret), "exited with code %i", status);
 return ret;
}

canonical_original_code:
char *exec_exitstatus(int status) {
 static __thread char ret[128];
 if ((((status) & 0x7f) == 0)) {
  if ((((status) & 0xff00) >> 8) == 127)
   snprintf(ret, sizeof(ret),
     "could not execute command");
  else
   snprintf(ret, sizeof(ret), "exited with status %i",
     (((status) & 0xff00) >> 8));
 } else if ((((char) (((status) & 0x7f) + 1) >> 1) > 0)) {
  if (((status) & 0x80))
   snprintf(ret, sizeof(ret), "core dumped");
  else
   snprintf(ret, sizeof(ret), "terminated by signal %i",
     ((status) & 0x7f));
 } else
  snprintf(ret, sizeof(ret), "exited with code %i", status);
 return ret;
}

variable_types: status int

variable_types:
ret
char [128]

return_type: char *


decompiled_code:
int child_proc_reap()
{
__int64 v0; // rbp
unsigned int v1; // ebx
char *v2; // rax
int v3; // eax
unsigned int v4; // er12
char *v6; // rax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_InterlockedExchange(&do_child_proc_reap, 0);
pthread_mutex_lock(&child_proc_lock);
while ( 1 )
{
v3 = waitpid(-1, stat_loc, 1);
v4 = v3;
if ( v3 <= 0 )
break;
v0 = child_proc_find(v3);
if ( v0 )
{
v1 = time(0LL) - *(_DWORD *)(v0 + 32);
v2 = exec_exitstatus(stat_loc[0]);
syslog(6, "Child process \"%s\" (%i) %s: ran for %i seconds", *(const char **)(v0 + 24), v4, v2, v1);
_InterlockedExchange(*(volatile __int32 **)(v0 + 40), stat_loc[0]);
child_proc_del((void *)v0);
}
else
{
v6 = exec_exitstatus(stat_loc[0]);
syslog(4, "Unknown child process (%i) %s", v4, v6);
}
}
return pthread_mutex_unlock(&child_proc_lock);
}

canonical_decompiled_code:
int func6()
{
__int64 v0; // rbp
unsigned int v1; // ebx
char *v2; // rax
int v3; // eax
unsigned int v4; // er12
char *v6; // rax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_InterlockedExchange(&do_child_proc_reap, 0);
pthread_mutex_lock(&child_proc_lock);
while ( 1 )
{
v3 = waitpid(-1, stat_loc, 1);
v4 = v3;
if ( v3 <= 0 )
break;
v0 = func0(v3);
if ( v0 )
{
v1 = time(0LL) - *(_DWORD *)(v0 + 32);
v2 = func5(stat_loc[0]);
syslog(6, "Child process \"%s\" (%i) %s: ran for %i seconds", *(const char **)(v0 + 24), v4, v2, v1);
_InterlockedExchange(*(volatile __int32 **)(v0 + 40), stat_loc[0]);
func3((void *)v0);
}
else
{
v6 = func5(stat_loc[0]);
syslog(4, "Unknown child process (%i) %s", v4, v6);
}
}
return pthread_mutex_unlock(&child_proc_lock);
}

original_code:
static void child_proc_reap (void) {
 pid_t pid;
 int st;
 __sync_lock_test_and_set(&do_child_proc_reap,0);
 pthread_mutex_lock(&child_proc_lock);
 while ((pid = waitpid(-1, &st, 1)) > 0) {
  struct child_proc *cp;
  cp = child_proc_find(pid);
  if (__builtin_expect((cp != ((void *)0)),1))
   syslog(6, "Child process \"%s\" (%i) %s: " "ran for %i seconds", cp->cmd, pid, exec_exitstatus(st), (int)(time(((void *)0)) - cp->t_start));
  else
   syslog(4, "Unknown child process (%i) %s", pid, exec_exitstatus(st));
  if (!cp)
   continue;
  __sync_lock_test_and_set(cp->statusp,st);
  child_proc_del(cp);
 }
 pthread_mutex_unlock(&child_proc_lock);
}

canonical_original_code:
static void child_proc_reap() {
 int pid;
 int st;
 __sync_lock_test_and_set(&do_child_proc_reap,0);
 pthread_mutex_lock(&child_proc_lock);
 while ((pid = waitpid(-1, &st, 1)) > 0) {
  struct child_proc *cp;
  cp = child_proc_find(pid);
  if (__builtin_expect((cp != ((void *)0)),1))
   syslog(6, "Child process \"%s\" (%i) %s: " "ran for %i seconds", cp->cmd, pid, exec_exitstatus(st), (int)(time(((void *)0)) - cp->t_start));
  else
   syslog(4, "Unknown child process (%i) %s", pid, exec_exitstatus(st));
  if (!cp)
   continue;
  __sync_lock_test_and_set(cp->statusp,st);
  child_proc_del(cp);
 }
 pthread_mutex_unlock(&child_proc_lock);
}

variable_types: st int


decompiled_code:
void *__fastcall exec_main(void *a1)
{
time_t v1; // rbx
__int64 i; // rbx
__int64 v3; // rcx

v1 = 0LL;
ezd_thread_sigmask(0LL, 0LL, 0xFFFFFFFFLL);
ezd_thread_sigmask(1LL, 17LL, 0xFFFFFFFFLL);
signal(17, (__sighandler_t)sigchld);
while ( 1 )
{
if ( conf[19] )
goto LABEL_8;
if ( child_proc_cnt <= 0 )
goto LABEL_11;
if ( v1 )
break;
v1 = time(0LL) + 10;
if ( conf[22] > 6 )
{
printf("Waiting %i seconds for %i child processes to terminate", 10LL, (unsigned int)child_proc_cnt);
putchar(10);
}
LABEL_8:
if ( do_child_proc_reap )
child_proc_reap();
usleep(0x7A120u);
}
if ( time(0LL) <= v1 )
goto LABEL_8;
LABEL_11:
pthread_mutex_lock(&child_proc_lock);
for ( i = child_procs; i; i = *(_QWORD *)i )
{
v3 = *(unsigned int *)(i + 16);
if ( (int)v3 > 0 )
{
syslog(4, "Child process \"%s\" (%i) did not terminate in %is: killing", *(const char **)(i + 24), v3, 10LL);
kill(*(_DWORD *)(i + 16), 15);
sleep(1u);
kill(*(_DWORD *)(i + 16), 9);
}
}
pthread_mutex_unlock(&child_proc_lock);
child_proc_reap();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
time_t v1; // rbx
__int64 i; // rbx
__int64 v3; // rcx

v1 = 0LL;
ezd_thread_sigmask(0LL, 0LL, 0xFFFFFFFFLL);
ezd_thread_sigmask(1LL, 17LL, 0xFFFFFFFFLL);
signal(17, (__sighandler_t)sigchld);
while ( 1 )
{
if ( conf[19] )
goto LABEL_8;
if ( child_proc_cnt <= 0 )
goto LABEL_11;
if ( v1 )
break;
v1 = time(0LL) + 10;
if ( conf[22] > 6 )
{
printf("Waiting %i seconds for %i child processes to terminate", 10LL, (unsigned int)child_proc_cnt);
putchar(10);
}
LABEL_8:
if ( do_child_proc_reap )
func6();
usleep(0x7A120u);
}
if ( time(0LL) <= v1 )
goto LABEL_8;
LABEL_11:
pthread_mutex_lock(&child_proc_lock);
for ( i = child_procs; i; i = *(_QWORD *)i )
{
v3 = *(unsigned int *)(i + 16);
if ( (int)v3 > 0 )
{
syslog(4, "Child process \"%s\" (%i) did not terminate in %is: killing", *(const char **)(i + 24), v3, 10LL);
kill(*(_DWORD *)(i + 16), 15);
sleep(1u);
kill(*(_DWORD *)(i + 16), 9);
}
}
pthread_mutex_unlock(&child_proc_lock);
func6();
return 0LL;
}

original_code:
static void *exec_main (void *ignore) {
 time_t hard_timeout = 0;
 const int gracetime = 10;
 struct child_proc *cp;
 ezd_thread_sigmask(0, 0 , -1 );
 ezd_thread_sigmask(1, 17, -1 );
 signal(17, sigchld);
 while (conf.run || child_proc_cnt > 0) {
  if (!conf.run) {
   if (!hard_timeout) {
    hard_timeout = time(((void *)0)) + gracetime;
    do { if (conf.log_level > 6) { printf("Waiting %i seconds for " "%i child processes to terminate", gracetime, child_proc_cnt); printf("\n"); } } while (0);
   } else if (hard_timeout < time(((void *)0)))
    break;
  }
  if (do_child_proc_reap)
   child_proc_reap();
  usleep(500000);
 }
 pthread_mutex_lock(&child_proc_lock);
 for ((cp) = ((&child_procs)->lh_first); (cp); (cp) = ((cp)->link.le_next)) {
  if (cp->pid <= 0)
   continue;
  syslog(4, "Child process \"%s\" (%i) did not " "terminate in %is: killing", cp->cmd, (int)cp->pid, gracetime);
  kill(cp->pid, 15);
  sleep(1);
  kill(cp->pid, 9);
 }
 pthread_mutex_unlock(&child_proc_lock);
 child_proc_reap();
 return ((void *)0);
}

canonical_original_code:
static void *exec_main(void *ignore) {
 long hard_timeout = 0;
 int gracetime = 10;
 struct child_proc *cp;
 ezd_thread_sigmask(0, 0 , -1 );
 ezd_thread_sigmask(1, 17, -1 );
 signal(17, sigchld);
 while (conf.run || child_proc_cnt > 0) {
  if (!conf.run) {
   if (!hard_timeout) {
    hard_timeout = time(((void *)0)) + gracetime;
    do { if (conf.log_level > 6) { printf("Waiting %i seconds for " "%i child processes to terminate", gracetime, child_proc_cnt); printf("\n"); } } while (0);
   } else if (hard_timeout < time(((void *)0)))
    break;
  }
  if (do_child_proc_reap)
   child_proc_reap();
  usleep(500000);
 }
 pthread_mutex_lock(&child_proc_lock);
 for ((cp) = ((&child_procs)->lh_first); (cp); (cp) = ((cp)->link.le_next)) {
  if (cp->pid <= 0)
   continue;
  syslog(4, "Child process \"%s\" (%i) did not " "terminate in %is: killing", cp->cmd, (int)cp->pid, gracetime);
  kill(cp->pid, 15);
  sleep(1);
  kill(cp->pid, 9);
 }
 pthread_mutex_unlock(&child_proc_lock);
 child_proc_reap();
 return ((void *)0);
}

variable_types:
ignore
void *

variable_types: gracetime int


decompiled_code:
int exec_term()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

return pthread_join(exec_thread, &thread_return);
}

canonical_decompiled_code:
int func8()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

return pthread_join(exec_thread, &thread_return);
}

original_code:
void exec_term (void) {
 void *ignore;
 pthread_join(exec_thread, &ignore);
}

canonical_original_code:
void exec_term() {
 void *ignore;
 pthread_join(exec_thread, &ignore);
}


decompiled_code:
int exec_init()
{
int result; // eax
char *v1; // rax

result = pthread_create(&exec_thread, 0LL, exec_main, 0LL);
if ( result )
{
v1 = strerror(result);
syslog(3, "Failed to create exec_main thread: %s", v1);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax
char *v1; // rax

result = pthread_create(&exec_thread, 0LL, exec_main, 0LL);
if ( result )
{
v1 = strerror(result);
syslog(3, "Failed to create exec_main thread: %s", v1);
exit(1);
}
return result;
}

original_code:
void exec_init (void) {
 int err;
 if ((err = pthread_create(&exec_thread, ((void *)0), exec_main, ((void *)0)))) {
  syslog(3, "Failed to create exec_main thread: %s", strerror(err));
  exit(1);
 }
}

canonical_original_code:
void exec_init() {
 int err;
 if ((err = pthread_create(&exec_thread, ((void *)0), exec_main, ((void *)0)))) {
  syslog(3, "Failed to create exec_main thread: %s", strerror(err));
  exit(1);
 }
}

variable_types: err int


ltrim

decompiled_code:
char *__fastcall ltrim(char *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
return a1;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
return a1;
}

original_code:
static char *ltrim (const char *s) {
 while (((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace))
  s++;
 return (char *)s;
}

canonical_original_code:
static char *ltrim(char *s) {
 while (((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace))
  s++;
 return (char *)s;
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall kv_parse(const char **a1, const char **a2, _QWORD *a3)
{
const char *v3; // rbx
const unsigned __int16 *v5; // rcx
__int64 v6; // rdx
unsigned int v7; // er8
char *v8; // rax
char *v9; // rax

v3 = *a1;
if ( !*a1 )
return 0LL;
v5 = *_ctype_b_loc();
while ( 1 )
{
v6 = *v3;
if ( (v5[v6] & 0x2000) == 0 )
break;
++v3;
}
v7 = 0;
if ( !(_BYTE)v6 )
return v7;
v8 = strchr(v3, 61);
if ( !v8 )
{
*a2 = v3;
v7 = 1;
*a3 = &unk_E18;
*a1 = 0LL;
return v7;
}
*v8 = 0;
*a2 = v3;
*a3 = v8 + 1;
v9 = strchr(v8 + 1, 44);
if ( v9 )
{
*v9 = 0;
v7 = 1;
*a1 = v9 + 1;
return v7;
}
*a1 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1, const char **a2, _QWORD *a3)
{
const char *v3; // rbx
const unsigned __int16 *v5; // rcx
__int64 v6; // rdx
unsigned int v7; // er8
char *v8; // rax
char *v9; // rax

v3 = *a1;
if ( !*a1 )
return 0LL;
v5 = *_ctype_b_loc();
while ( 1 )
{
v6 = *v3;
if ( (v5[v6] & 0x2000) == 0 )
break;
++v3;
}
v7 = 0;
if ( !(_BYTE)v6 )
return v7;
v8 = strchr(v3, 61);
if ( !v8 )
{
*a2 = v3;
v7 = 1;
*a3 = &unk_E18;
*a1 = 0LL;
return v7;
}
*v8 = 0;
*a2 = v3;
*a3 = v8 + 1;
v9 = strchr(v8 + 1, 44);
if ( v9 )
{
*v9 = 0;
v7 = 1;
*a1 = v9 + 1;
return v7;
}
*a1 = 0LL;
return 1LL;
}

original_code:
static int kv_parse (char **strp, const char **namep, const char **valp) {
 char *s;
 char *str = *strp;
 if (!str)
  return 0;
 while (((*__ctype_b_loc ())[(int) (((int)*str))] & (unsigned short int) _ISspace))
  str++;
 if (!*str)
  return 0;
 if (!(s = strchr(str, '='))) {
  *namep = str;
  *valp = " ";
  *strp = ((void *)0);
  return 1;
 }
 *s = '\0';
 *namep = str;
 *valp = s+1;
 if ((s = strchr(*valp, ','))) {
  *s = '\0';
  *strp = s+1;
 } else
  *strp = ((void *)0);
 return 1;
}

canonical_original_code:
static int kv_parse(char **strp, char **namep, char **valp) {
 char *s;
 char *str = *strp;
 if (!str)
  return 0;
 while (((*__ctype_b_loc ())[(int) (((int)*str))] & (unsigned short) _ISspace))
  str++;
 if (!*str)
  return 0;
 if (!(s = strchr(str, '='))) {
  *namep = str;
  *valp = " ";
  *strp = ((void *)0);
  return 1;
 }
 *s = '\0';
 *namep = str;
 *valp = s+1;
 if ((s = strchr(*valp, ','))) {
  *s = '\0';
  *strp = s+1;
 } else
  *strp = ((void *)0);
 return 1;
}

variable_types:
strp
char **

variable_types:
namep
char **

variable_types:
valp
char **

variable_types:
str
char *


decompiled_code:
int __fastcall encoding_parse(char *s1)
{
int result; // eax

result = strcasecmp(s1, "string");
if ( result )
result = strcasecmp(s1, "json") == 0 ? 1 : -1;
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1)
{
int result; // eax

result = strcasecmp(s1, "string");
if ( result )
result = strcasecmp(s1, "json") == 0 ? 1 : -1;
return result;
}

original_code:
static encoding_t encoding_parse (const char *val) {
 if (!strcasecmp(val, "string"))
  return ENC_STRING;
 else if (!strcasecmp(val, "json"))
  return ENC_JSON;
 else
  return ENC_ERROR;
}

canonical_original_code:
static enum encoding_t encoding_parse(char *val) {
 if (!strcasecmp(val, "string"))
  return ENC_STRING;
 else if (!strcasecmp(val, "json"))
  return ENC_JSON;
 else
  return ENC_ERROR;
}

variable_types:
val
char *

return_type: enum encoding_t { ENC_ERROR=-1, ENC_STRING=0, ENC_JSON=1 }


decompiled_code:
char *__fastcall str_unescape(char *a1)
{
char *v1; // rbx
char v2; // al
size_t v3; // rax
int v4; // eax
unsigned __int8 *v5; // rdx

if ( *a1 )
{
v1 = a1;
while ( 1 )
{
v4 = (unsigned __int8)*v1 - 92;
if ( *v1 == 92 )
v4 = (unsigned __int8)v1[1] - 110;
v5 = (unsigned __int8 *)v1++;
if ( !v4 )
break;
if ( *v5 == 92 )
{
v2 = 13;
if ( v5[1] != 114 )
{
v2 = 9;
if ( v5[1] != 116 )
{
if ( v5[1] != 48 )
goto LABEL_6;
v2 = 0;
}
}
goto LABEL_5;
}
LABEL_6:
if ( !*v1 )
return a1;
}
v2 = 10;
LABEL_5:
*(v1 - 1) = v2;
v3 = strlen(v1 + 1);
memmove(v1, v1 + 1, v3 + 1);
goto LABEL_6;
}
return a1;
}

original_code:
static char *str_unescape (char *str) {
 char *s = str;
 while (*s) {
  int esc = -1;
  if (!strncmp(s, "\\n", 2))
   esc = '\n';
  else if (!strncmp(s, "\\r", 2))
   esc = '\r';
  else if (!strncmp(s, "\\t", 2))
   esc = '\t';
  else if (!strncmp(s, "\\0", 2))
   esc = '\0';
  if (esc != -1) {
   *s = esc;
   memmove(s+1, s+2, strlen(s+2)+1);
  }
  s++;
 }
 return str;
}

canonical_original_code:
static char *str_unescape(char *str) {
 char *s = str;
 while (*s) {
  int esc = -1;
  if (!strncmp(s, "\\n", 2))
   esc = '\n';
  else if (!strncmp(s, "\\r", 2))
   esc = '\r';
  else if (!strncmp(s, "\\t", 2))
   esc = '\t';
  else if (!strncmp(s, "\\0", 2))
   esc = '\0';
  if (esc != -1) {
   *s = esc;
   memmove(s+1, s+2, strlen(s+2)+1);
  }
  s++;
 }
 return str;
}

variable_types: esc int


decompiled_code:
_BOOL8 __fastcall conf_tof(char *s1)
{
int v1; // eax
_BOOL4 v2; // er12
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v1 = strtoul(s1, &endptr, 0);
if ( endptr > s1 )
return v1 != 0;
v2 = 1;
if ( strcasecmp(s1, "yes") && strcasecmp(s1, "true") )
{
if ( strcasecmp(s1, "on") )
v2 = *s1 == 0;
}
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *s1)
{
int v1; // eax
_BOOL4 v2; // er12
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v1 = strtoul(s1, &endptr, 0);
if ( endptr > s1 )
return v1 != 0;
v2 = 1;
if ( strcasecmp(s1, "yes") && strcasecmp(s1, "true") )
{
if ( strcasecmp(s1, "on") )
v2 = *s1 == 0;
}
return v2;
}

original_code:
static int conf_tof (const char *val) {
 char *end;
 int i;
 i = strtoul(val, &end, 0);
 if (end > val)
  return !!i;
 if (!strcasecmp(val, "yes") ||
     !strcasecmp(val, "true") ||
     !strcasecmp(val, "on") ||
     !*val )
  return 1;
 else
  return 0;
}

canonical_original_code:
static int conf_tof(char *val) {
 char *end;
 int i;
 i = strtoul(val, &end, 0);
 if (end > val)
  return !!i;
 if (!strcasecmp(val, "yes") ||
     !strcasecmp(val, "true") ||
     !strcasecmp(val, "on") ||
     !*val )
  return 1;
 else
  return 0;
}

variable_types:
end
char *

variable_types: i int