decompiled_code:
bool __fastcall pk_canNpcSee(int a1, int a2, _DWORD *a3)
{
int v3; // eax
bool result; // al
int v5; // ecx
int v6; // ecx

v3 = a3[235];
switch ( v3 )
{
case 2:
v5 = a3[228];
result = 0;
if ( v5 <= a1 || a3[229] != a2 )
return result;
return (int)abs32(v5 - a1) / 16 <= a3[4];
case 1:
v5 = a3[228];
result = 0;
if ( v5 >= a1 || a3[229] != a2 )
return result;
return (int)abs32(v5 - a1) / 16 <= a3[4];
case 3:
result = 0;
if ( a3[228] == a1 )
{
v6 = a3[229];
if ( v6 > a2 )
return (int)abs32(v6 - a2) / 16 <= a3[4];
}
break;
case 4:
result = 0;
if ( a3[228] == a1 )
{
v6 = a3[229];
if ( v6 < a2 )
return (int)abs32(v6 - a2) / 16 <= a3[4];
}
break;
default:
result = 0;
break;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func7(int a1, int a2, _DWORD *a3)
{
int v3; // eax
bool result; // al
int v5; // ecx
int v6; // ecx

v3 = a3[235];
switch ( v3 )
{
case 2:
v5 = a3[228];
result = 0;
if ( v5 <= a1 || a3[229] != a2 )
return result;
return (int)abs32(v5 - a1) / 16 <= a3[4];
case 1:
v5 = a3[228];
result = 0;
if ( v5 >= a1 || a3[229] != a2 )
return result;
return (int)abs32(v5 - a1) / 16 <= a3[4];
case 3:
result = 0;
if ( a3[228] == a1 )
{
v6 = a3[229];
if ( v6 > a2 )
return (int)abs32(v6 - a2) / 16 <= a3[4];
}
break;
case 4:
result = 0;
if ( a3[228] == a1 )
{
v6 = a3[229];
if ( v6 < a2 )
return (int)abs32(v6 - a2) / 16 <= a3[4];
}
break;
default:
result = 0;
break;
}
return result;
}

original_code:
_Bool pk_canNpcSee(int x, int y, npc_t* npc) {
 _Bool out = 0;
 if(npc->mover.dir == 2 && x < npc->mover.x && y == npc->mover.y &&
  abs(npc->mover.x-x)/16 <= npc->reach) {
  out = 1;
 } else if(npc->mover.dir == 1 && x > npc->mover.x && y == npc->mover.y &&
  abs(npc->mover.x-x)/16 <= npc->reach) {
  out = 1;
 } else if(npc->mover.dir == 3 && x == npc->mover.x && y < npc->mover.y &&
  abs(npc->mover.y-y)/16 <= npc->reach) {
  out = 1;
 } else if(npc->mover.dir == 4 && x == npc->mover.x && y > npc->mover.y &&
  abs(npc->mover.y-y)/16 <= npc->reach) {
  out = 1;
 }
 return out;
}

canonical_original_code:
_Bool pk_canNpcSee(int x, int y, struct npc_t *npc) {
 _Bool out = 0;
 if(npc->mover.dir == 2 && x < npc->mover.x && y == npc->mover.y &&
  abs(npc->mover.x-x)/16 <= npc->reach) {
  out = 1;
 } else if(npc->mover.dir == 1 && x > npc->mover.x && y == npc->mover.y &&
  abs(npc->mover.x-x)/16 <= npc->reach) {
  out = 1;
 } else if(npc->mover.dir == 3 && x == npc->mover.x && y < npc->mover.y &&
  abs(npc->mover.y-y)/16 <= npc->reach) {
  out = 1;
 } else if(npc->mover.dir == 4 && x == npc->mover.x && y > npc->mover.y &&
  abs(npc->mover.y-y)/16 <= npc->reach) {
  out = 1;
 }
 return out;
}

variable_types: x int

variable_types: y int


repo: velovix/super-glitch-engine

decompiled_code:
__int64 __fastcall pk_aggroNpc(int a1, int a2, __int64 a3)
{
__int64 result; // rax

*(_DWORD *)(a3 + 24) = 5;
*(_DWORD *)(a3 + 32) = 0;
*(_BYTE *)(a3 + 47) = 1;
*(_BYTE *)(a3 + 44) = 1;
*(_DWORD *)(a3 + 28) = 30;
result = *(unsigned int *)(a3 + 940);
switch ( (_DWORD)result )
{
case 2:
result = *(unsigned int *)(a3 + 912);
if ( (int)result > a1 && *(_DWORD *)(a3 + 916) == a2 )
{
result = (unsigned int)((int)abs32(result - a1) / 16);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1 + 16;
*(_DWORD *)(a3 + 8) = a2;
}
}
break;
case 1:
result = *(unsigned int *)(a3 + 912);
if ( (int)result < a1 && *(_DWORD *)(a3 + 916) == a2 )
{
result = (unsigned int)((int)abs32(result - a1) / 16);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1 - 16;
*(_DWORD *)(a3 + 8) = a2;
}
}
break;
case 3:
if ( *(_DWORD *)(a3 + 912) == a1 )
{
result = *(unsigned int *)(a3 + 916);
if ( (int)result < a2 )
{
result = (unsigned int)((int)abs32(result - a2) / 16);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1;
*(_DWORD *)(a3 + 8) = a2 - 16;
}
}
}
break;
default:
if ( (_DWORD)result == 4 && *(_DWORD *)(a3 + 912) == a1 )
{
result = *(unsigned int *)(a3 + 916);
if ( (int)result > a2 )
{
result = (unsigned int)((int)abs32(result - a2) / 16);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1;
*(_DWORD *)(a3 + 8) = a2 + 16;
}
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, __int64 a3)
{
__int64 result; // rax

*(_DWORD *)(a3 + 24) = 5;
*(_DWORD *)(a3 + 32) = 0;
*(_BYTE *)(a3 + 47) = 1;
*(_BYTE *)(a3 + 44) = 1;
*(_DWORD *)(a3 + 28) = 30;
result = *(unsigned int *)(a3 + 940);
switch ( (_DWORD)result )
{
case 2:
result = *(unsigned int *)(a3 + 912);
if ( (int)result > a1 && *(_DWORD *)(a3 + 916) == a2 )
{
result = (unsigned int)((int)abs32(result - a1) / 16);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1 + 16;
*(_DWORD *)(a3 + 8) = a2;
}
}
break;
case 1:
result = *(unsigned int *)(a3 + 912);
if ( (int)result < a1 && *(_DWORD *)(a3 + 916) == a2 )
{
result = (unsigned int)((int)abs32(result - a1) / 16);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1 - 16;
*(_DWORD *)(a3 + 8) = a2;
}
}
break;
case 3:
if ( *(_DWORD *)(a3 + 912) == a1 )
{
result = *(unsigned int *)(a3 + 916);
if ( (int)result < a2 )
{
result = (unsigned int)((int)abs32(result - a2) / 16);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1;
*(_DWORD *)(a3 + 8) = a2 - 16;
}
}
}
break;
default:
if ( (_DWORD)result == 4 && *(_DWORD *)(a3 + 912) == a1 )
{
result = *(unsigned int *)(a3 + 916);
if ( (int)result > a2 )
{
result = (unsigned int)((int)abs32(result - a2) / 16);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1;
*(_DWORD *)(a3 + 8) = a2 + 16;
}
}
}
break;
}
return result;
}

original_code:
void pk_aggroNpc(int tX, int tY, npc_t* npc) {
 npc->aiType = 5;
 npc->dest = 0;
 npc->aggro = 1;
 npc->fought = 1;
 npc->actClock = 30;
 if(npc->mover.dir == 2 && tX < npc->mover.x && tY == npc->mover.y &&
  abs(npc->mover.x-tX)/16 <= npc->reach) {
  npc->destX[npc->dest] = tX+16;
  npc->destY[npc->dest] = tY;
 } else if(npc->mover.dir == 1 && tX > npc->mover.x && tY == npc->mover.y &&
  abs(npc->mover.x-tX)/16 <= npc->reach) {
  npc->destX[npc->dest] = tX-16;
  npc->destY[npc->dest] = tY;
 } else if(npc->mover.dir == 3 && tX == npc->mover.x && tY > npc->mover.y &&
  abs(npc->mover.y-tY)/16 <= npc->reach) {
  npc->destX[npc->dest] = tX;
  npc->destY[npc->dest] = tY-16;
 } else if(npc->mover.dir == 4 && tX == npc->mover.x && tY < npc->mover.y &&
  abs(npc->mover.y-tY)/16 <= npc->reach) {
  npc->destX[npc->dest] = tX;
  npc->destY[npc->dest] = tY+16;
 }
}

canonical_original_code:
void pk_aggroNpc(int tX, int tY, struct npc_t *npc) {
 npc->aiType = 5;
 npc->dest = 0;
 npc->aggro = 1;
 npc->fought = 1;
 npc->actClock = 30;
 if(npc->mover.dir == 2 && tX < npc->mover.x && tY == npc->mover.y &&
  abs(npc->mover.x-tX)/16 <= npc->reach) {
  npc->destX[npc->dest] = tX+16;
  npc->destY[npc->dest] = tY;
 } else if(npc->mover.dir == 1 && tX > npc->mover.x && tY == npc->mover.y &&
  abs(npc->mover.x-tX)/16 <= npc->reach) {
  npc->destX[npc->dest] = tX-16;
  npc->destY[npc->dest] = tY;
 } else if(npc->mover.dir == 3 && tX == npc->mover.x && tY > npc->mover.y &&
  abs(npc->mover.y-tY)/16 <= npc->reach) {
  npc->destX[npc->dest] = tX;
  npc->destY[npc->dest] = tY-16;
 } else if(npc->mover.dir == 4 && tX == npc->mover.x && tY < npc->mover.y &&
  abs(npc->mover.y-tY)/16 <= npc->reach) {
  npc->destX[npc->dest] = tX;
  npc->destY[npc->dest] = tY+16;
 }
}

variable_types: tX int

variable_types: tY int

variable_types: struct npc_t { int destX[2]; int destY[2]; int reach; _Bool fought; struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; } monsters[6]; struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } mover; struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; } dialog; char msg1[128]; char msg2[128]; char msg3[128]; } *

return_type: void

user_defined_types: struct npc_t { int destX[2]; int destY[2]; int reach; _Bool fought; struct monster_t monsters[6]; struct charMover_t mover; struct window_t dialog; char msg1[128]; char msg2[128]; char msg3[128]; }

user_defined_types: struct monster_t { int experience; char name[10]; struct monFileObj_t *id; _Bool shiny; struct stats_t stats; struct moveMask_t moves[4]; int condition; }

user_defined_types: struct monFileObj_t { struct monBasic_f basic; struct monStats_f stats; struct monMovelist_f movelist; struct monExperience_f experience; struct monEvolution_f evolution; struct monAesthetics_f aesthetics; struct monOthers_f etc; }

user_defined_types: struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; }


decompiled_code:
unsigned __int64 __fastcall pk_doMoveEvent(unsigned __int64 a1, signed int a2, __int64 a3, __int64 a4)
{
unsigned __int64 result; // rax

result = HIDWORD(a1);
if ( (_DWORD)a1 == 1 )
{
result = (unsigned int)a2;
if ( HIDWORD(a1) == 1 )
{
result = (unsigned int)(*(_DWORD *)(a4 + 60) + a2 / -5);
if ( (result & 0x80000000) != 0LL )
result = 0LL;
*(_DWORD *)(a4 + 60) = result;
}
else if ( HIDWORD(a1) == 2 )
{
result = (unsigned int)(*(_DWORD *)(a3 + 60) + a2 / -5);
if ( (result & 0x80000000) != 0LL )
result = 0LL;
*(_DWORD *)(a3 + 60) = result;
}
}
else if ( (_DWORD)a1 == 2 )
{
if ( HIDWORD(a1) == 1 )
{
*(_DWORD *)(a4 + 140) = 2;
}
else if ( HIDWORD(a1) == 2 )
{
*(_DWORD *)(a3 + 140) = 2;
}
}
return result;
}

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

result = HIDWORD(a1);
if ( (_DWORD)a1 == 1 )
{
result = (unsigned int)a2;
if ( HIDWORD(a1) == 1 )
{
result = (unsigned int)(*(_DWORD *)(a4 + 60) + a2 / -5);
if ( (result & 0x80000000) != 0LL )
result = 0LL;
*(_DWORD *)(a4 + 60) = result;
}
else if ( HIDWORD(a1) == 2 )
{
result = (unsigned int)(*(_DWORD *)(a3 + 60) + a2 / -5);
if ( (result & 0x80000000) != 0LL )
result = 0LL;
*(_DWORD *)(a3 + 60) = result;
}
}
else if ( (_DWORD)a1 == 2 )
{
if ( HIDWORD(a1) == 1 )
{
*(_DWORD *)(a4 + 140) = 2;
}
else if ( HIDWORD(a1) == 2 )
{
*(_DWORD *)(a3 + 140) = 2;
}
}
return result;
}

original_code:
void pk_doMoveEvent(moveEvent_t event, monster_t* a, monster_t* d) {
 switch(event.type) {
 case 1:
  switch(event.target) {
  case 2:
   a->stats.mHp -= event.value/5;
   if(a->stats.mHp < 0) {
    a->stats.mHp = 0;
   }
   break;
  case 1:
   d->stats.mHp -= event.value/5;
   if(d->stats.mHp < 0) {
    d->stats.mHp = 0;
   }
   break;
  }
  break;
 case 2:
  switch(event.target) {
  case 2:
   a->condition = 2;
   break;
  case 1:
   d->condition = 2;
   break;
  }
  break;
 }
}

canonical_original_code:
void pk_doMoveEvent(struct moveEvent_t event, struct monster_t *a, struct monster_t *d) {
 switch(event.type) {
 case 1:
  switch(event.target) {
  case 2:
   a->stats.mHp -= event.value/5;
   if(a->stats.mHp < 0) {
    a->stats.mHp = 0;
   }
   break;
  case 1:
   d->stats.mHp -= event.value/5;
   if(d->stats.mHp < 0) {
    d->stats.mHp = 0;
   }
   break;
  }
  break;
 case 2:
  switch(event.target) {
  case 2:
   a->condition = 2;
   break;
  case 1:
   d->condition = 2;
   break;
  }
  break;
 }
}

variable_types: struct moveEvent_t { int type; int target; int value; }

variable_types: struct monster_t { int experience; char name[10]; struct monFileObj_t { struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; } basic; struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; } stats; struct monMovelist_f { unsigned int natLearnedCnt; struct monNatMoveEntry_f { unsigned int move; unsigned char level; } *natLearned; unsigned int tmLearnedCnt; unsigned int *tmLearned; } movelist; struct monExperience_f { unsigned char type; } experience; struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; } evolution; struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; } aesthetics; struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; } etc; } *id; _Bool shiny; struct stats_t { int hp; int mHp; } stats; struct moveMask_t { int cpp; int value; } moves[4]; int condition; } *

variable_types:
d
struct monster_t *


original_code:
_Bool pk_useMove(int numb, monster_t* mon) {
 if(mon->moves[numb].cpp > 0) {
  mon->moves[numb].cpp--;
  return 1;
 } else {
  return 0;
 }
}

canonical_original_code:
_Bool pk_useMove(int numb, struct monster_t *mon) {
 if(mon->moves[numb].cpp > 0) {
  mon->moves[numb].cpp--;
  return 1;
 } else {
  return 0;
 }
}

variable_types: numb int

user_defined_types: struct moveMask_t { int cpp; int value; }

user_defined_types: struct monBasic_f { unsigned char name[10]; unsigned char type1; unsigned char type2; unsigned int height; unsigned int weight; }

user_defined_types: struct monStats_f { unsigned char b_hp; unsigned char b_att; unsigned char b_def; unsigned char b_spAtt; unsigned char b_spDef; unsigned char b_speed; unsigned char ev_hp; unsigned char ev_att; unsigned char ev_def; unsigned char ev_spAtt; unsigned char ev_spDef; unsigned char ev_speed; }

user_defined_types: struct monExperience_f { unsigned char type; }

user_defined_types: struct monEvolution_f { unsigned char evolves; unsigned int mon; unsigned char level; }

user_defined_types: struct monAesthetics_f { unsigned int battleSprite; unsigned int icon; unsigned int body; unsigned int footprint; unsigned int cry; }

user_defined_types: struct monOthers_f { unsigned char species[13]; unsigned char genderless; unsigned char malePerc; unsigned int ability; unsigned char catchRate; unsigned int heldItem; }

user_defined_types: struct monNatMoveEntry_f { unsigned int move; unsigned char level; }


original_code:
_Bool pk_parseMoveScript(unsigned char *script, int scriptLen, move_t *obj) {
 if(script[0] == ' ') {
  return 0;
 }
 obj->eventCnt = 0;
 int inc = 0;
 while(inc < scriptLen) {
  if(script[inc] == '%') {
   obj->eventCnt++;
  }
  inc++;
 }
 obj->events = (moveEvent_t*)malloc(obj->eventCnt*sizeof(moveEvent_t));
 inc = 0;
 for(int i=0; i<obj->eventCnt; i++) {
  if(script[inc] == '\n') {
   inc++;
  }
  if(script[inc] != '%') {
   return 0;
  }
  inc++;
  switch(script[inc]) {
  case 'd':
   obj->events[i].type = 1;
   break;
  case 'p':
   obj->events[i].type = 2;
   break;
  }
  if(script[inc+1] != ' ') {
   return 0;
  }
  inc+=2;
  switch(script[inc]) {
  case 't':
   obj->events[i].target = 1;
   break;
  case 'u':
   obj->events[i].target = 2;
   break;
  }
  if(script[inc+1] != ' ') {
   return 0;
  }
  inc+=2;
  int valDigits = 0;
  while(script[inc] >= 48 && script[inc] < 58 && inc < scriptLen) {
   valDigits++;
   inc++;
  }
  inc-=valDigits;
  int digits[3];
  obj->events[i].value = 0;
  for(int j=0; j<3; j++) {
   if(valDigits >= 3-j) {
    digits[j] = (int)script[inc]-48;
    inc++;
   } else {
    digits[j] = 0;
   }
  }
  obj->events[i].value = (digits[0]*100)+(digits[1]*10)+(digits[2]);
 }
 return 1;
}

canonical_original_code:
_Bool pk_parseMoveScript(unsigned char *script, int scriptLen, struct move_t *obj) {
 if(script[0] == ' ') {
  return 0;
 }
 obj->eventCnt = 0;
 int inc = 0;
 while(inc < scriptLen) {
  if(script[inc] == '%') {
   obj->eventCnt++;
  }
  inc++;
 }
 obj->events = (struct moveEvent_t *)malloc(obj->eventCnt*sizeof(moveEvent_t));
 inc = 0;
 for(int i = 0; i<obj->eventCnt; i++) {
  if(script[inc] == '\n') {
   inc++;
  }
  if(script[inc] != '%') {
   return 0;
  }
  inc++;
  switch(script[inc]) {
  case 'd':
   obj->events[i].type = 1;
   break;
  case 'p':
   obj->events[i].type = 2;
   break;
  }
  if(script[inc+1] != ' ') {
   return 0;
  }
  inc+=2;
  switch(script[inc]) {
  case 't':
   obj->events[i].target = 1;
   break;
  case 'u':
   obj->events[i].target = 2;
   break;
  }
  if(script[inc+1] != ' ') {
   return 0;
  }
  inc+=2;
  int valDigits = 0;
  while(script[inc] >= 48 && script[inc] < 58 && inc < scriptLen) {
   valDigits++;
   inc++;
  }
  inc-=valDigits;
  int digits[3];
  obj->events[i].value = 0;
  for(int j = 0; j<3; j++) {
   if(valDigits >= 3-j) {
    digits[j] = (int)script[inc]-48;
    inc++;
   } else {
    digits[j] = 0;
   }
  }
  obj->events[i].value = (digits[0]*100)+(digits[1]*10)+(digits[2]);
 }
 return 1;
}

variable_types:
script
unsigned char *

variable_types: scriptLen int

variable_types: struct move_t { int bpp; char name[12]; struct moveEvent_t { int type; int target; int value; } *events; int eventCnt; } *

variable_types: inc int

variable_types: i int

variable_types: valDigits int

variable_types:
digits
int [3]

variable_types: j int

user_defined_types: struct move_t { int bpp; char name[12]; struct moveEvent_t *events; int eventCnt; }


repo: veltzer/except

decompiled_code:
void __fastcall __noreturn except_error(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
static inline void except_error(const char* name) {
 if(throw) {
  except_throw(name);
 } else {
  perror(name);
  exit(1);
 }
}

canonical_original_code:
static inline void except_error(char *name) {
 if(throw) {
  except_throw(name);
 } else {
  perror(name);
  exit(1);
 }
}

variable_types:
name
char *


ioctl

decompiled_code:
__int64 ioctl()
{
__int64 result; // rax

result = p_ioctl();
if ( (_DWORD)result == -1 )
except_error("ioctl");
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax

result = p_ioctl();
if ( (_DWORD)result == -1 )
func7("ioctl");
return result;
}

original_code:
int ioctl(int d,unsigned long int request,...) {
 except_debug("in ioctl");
 int ret=p_ioctl(d,request);
 if(ret==-1) {
  except_error("ioctl");
 }
 return ret;
}

canonical_original_code:
int ioctl(int d, unsigned long request, ...) {
 except_debug("in ioctl");
 int ret = p_ioctl(d,request);
 if(ret==-1) {
  except_error("ioctl");
 }
 return ret;
}

variable_types: d int

variable_types:
request
unsigned long

variable_types: ret int

return_type: int


malloc

decompiled_code:
__int64 malloc()
{
__int64 result; // rax

result = p_malloc();
if ( !result )
except_error("malloc");
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax

result = p_malloc();
if ( !result )
func7("malloc");
return result;
}

original_code:
void* malloc(size_t size) {
 except_debug("in malloc");
 void* ret=p_malloc(size);
 if(ret==((void *)0)) {
  except_error("malloc");
 }
 return ret;
}

canonical_original_code:
void *malloc(unsigned long size) {
 except_debug("in malloc");
 void *ret = p_malloc(size);
 if(ret==((void *)0)) {
  except_error("malloc");
 }
 return ret;
}

variable_types:
size
unsigned long

variable_types:
ret
void *

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
ioctl(6, 9uLL, envp);
return 0;
}

original_code:
int main(int argc,char** argv,char ** envp) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
 malloc(70000000);
 ioctl(6,9);
#pragma GCC diagnostic pop
 return 0;
}

canonical_original_code:
int main(int argc, char **argv, char **envp) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
 malloc(70000000);
 ioctl(6,9);
#pragma GCC diagnostic pop
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
envp
char **


getLINES

repo: veltzer/jnacurses

decompiled_code:
__int64 getLINES()
{
return (unsigned int)LINES;
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned int)LINES;
}

original_code:
int getLINES(void) {
 return LINES;
}

canonical_original_code:
int getLINES() {
 return LINES;
}


getCOLS

decompiled_code:
__int64 getCOLS()
{
return (unsigned int)COLS;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)COLS;
}

original_code:
int getCOLS(void) {
 return COLS;
}

canonical_original_code:
int getCOLS() {
 return COLS;
}


RandomMove

repo: veltzer/xmeltdown

decompiled_code:
__int64 RandomMove()
{
int v0; // edx
__int64 v1; // rcx
__int64 *v2; // rax
__int64 result; // rax

do
v0 = rand() % numread;
while ( lastnum_0 == v0 );
lastnum_0 = v0;
v1 = tweenskel;
v2 = (__int64 *)(skellist + 8LL * v0);
fromskel[0] = tweenskel;
toskel = *v2;
fromskel[1] = tweenskel;
*(&toskel + 1) = *v2;
fromskel[2] = v1;
result = *v2;
*(&toskel + 2) = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edx
__int64 v1; // rcx
__int64 *v2; // rax
__int64 result; // rax

do
v0 = rand() % numread;
while ( lastnum_0 == v0 );
lastnum_0 = v0;
v1 = tweenskel;
v2 = (__int64 *)(skellist + 8LL * v0);
fromskel[0] = tweenskel;
toskel = *v2;
fromskel[1] = tweenskel;
*(&toskel + 1) = *v2;
fromskel[2] = v1;
result = *v2;
*(&toskel + 2) = result;
return result;
}

original_code:
void RandomMove()
{
 int i;
 int randnum;
 static int lastnum=999;
 do {
  randnum=rand()%numread;
 } while (randnum == lastnum);
 lastnum=randnum;
 for (i=0; i < 3; i++) {
  fromskel[i]=tweenskel[0];
  toskel[i]=skellist[randnum];
 }
}

canonical_original_code:
void RandomMove()
{
 int i;
 int randnum;
 static int lastnum = 999;
 do {
  randnum=rand()%numread;
 } while (randnum == lastnum);
 lastnum=randnum;
 for (i=0; i < 3; i++) {
  fromskel[i]=tweenskel[0];
  toskel[i]=skellist[randnum];
 }
}

variable_types: randnum int

variable_types: lastnum int


ClearFrame

decompiled_code:
int ClearFrame()
{
return XClearWindow(dpy, buffer[1]);
}

canonical_decompiled_code:
int func3()
{
return XClearWindow(dpy, buffer[1]);
}

original_code:
void ClearFrame() {
 XClearWindow(dpy, buffer[!curbuf]);
}


ShowFrame

decompiled_code:
int __fastcall ShowFrame(int a1)
{
XMapWindow(dpy, buffer[a1 == 0]);
return XUnmapWindow(dpy, buffer[a1]);
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
XMapWindow(dpy, buffer[a1 == 0]);
return XUnmapWindow(dpy, buffer[a1]);
}

original_code:
void ShowFrame(int curbuf)
{
 XMapWindow(dpy, buffer[!curbuf]);
 XUnmapWindow(dpy, buffer[curbuf]);
}

variable_types: curbuf int


decompiled_code:
int __fastcall clock_usleep(unsigned __int64 a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240;
v2.tv_usec = a1 % 0xF4240;
return select(0, 0LL, 0LL, 0LL, &v2);
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int64 a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240;
v2.tv_usec = a1 % 0xF4240;
return select(0, 0LL, 0LL, 0LL, &v2);
}

original_code:
void clock_usleep (unsigned long usecs)
{
 struct timeval tv;
 tv.tv_sec=usecs/1000000L;
 tv.tv_usec=usecs%1000000L;
 (void) select (0, 0, 0, 0, &tv);
}

canonical_original_code:
void clock_usleep(unsigned long usecs)
{
 struct timeval tv;
 tv.tv_sec=usecs/1000000L;
 tv.tv_usec=usecs%1000000L;
 (void) select (0, 0, 0, 0, &tv);
}

variable_types:
usecs
unsigned long

variable_types: struct timeval { long tv_sec; long tv_usec; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // eax
char *v5; // r12
XGCValues v6; // [rsp+0h] [rbp-A8h] BYREF

if ( argc > 1 )
{
v3 = argv[1];
v4 = 10;
if ( argc > 2 )
v4 = atoi(argv[2]);
steps = v4;
v5 = 0LL;
if ( argc == 4 )
v5 = (char *)argv[3];
tweenskel[0] = (__int64)&tween;
tweenskel[1] = (__int64)&tween + 368;
tweenskel[2] = (__int64)&tween + 736;
Initialize((unsigned int)argc, argv, envp);
XSelectInput(dpy, win, 32773LL);
v6.line_width = 0;
v6.line_style = 0;
v6.function = 0;
set_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v6);
v6.line_width = 0;
v6.line_style = 0;
v6.function = 15;
unset_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v6);
v6.line_width = 0;
v6.line_style = 0;
v6.function = 5;
noop_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v6);
v6.line_width = 0;
v6.line_style = 0;
v6.function = 10;
neg_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v6);
skellist = (__int64)ReadFile(v3);
if ( v5 )
v5 = ReadRoutineFile(v5);
DanceMainLoop((int *)v5);
}
printf("Usage: %s posefile [framecount [routinefile]\n", *argv);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // eax
char *v5; // r12
XGCValues v6; // [rsp+0h] [rbp-A8h] BYREF

if ( argc > 1 )
{
v3 = argv[1];
v4 = 10;
if ( argc > 2 )
v4 = atoi(argv[2]);
steps = v4;
v5 = 0LL;
if ( argc == 4 )
v5 = (char *)argv[3];
tweenskel[0] = (__int64)&tween;
tweenskel[1] = (__int64)&tween + 368;
tweenskel[2] = (__int64)&tween + 736;
Initialize((unsigned int)argc, argv, envp);
XSelectInput(dpy, win, 32773LL);
v6.line_width = 0;
v6.line_style = 0;
v6.function = 0;
set_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v6);
v6.line_width = 0;
v6.line_style = 0;
v6.function = 15;
unset_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v6);
v6.line_width = 0;
v6.line_style = 0;
v6.function = 5;
noop_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v6);
v6.line_width = 0;
v6.line_style = 0;
v6.function = 10;
neg_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v6);
skellist = (__int64)ReadFile(v3);
if ( v5 )
v5 = func5(v5);
func8((int *)v5);
}
printf("Usage: %s posefile [framecount [routinefile]\n", *argv);
exit(1);
}

original_code:
int main(int argc, char** argv)
{
 char* posefile;
 char* routinefile;
 XGCValues my_gcvalues;
 int i;
 int* routine=((void *)0);
 if (argc < 2) {
  printf ("Usage: %s posefile [framecount [routinefile]\n", argv[0]);
  exit (1);
 }
 posefile=argv[1];
 if (argc >= 3)
  steps=atoi(argv[2]);
 else
  steps=10;
 if (argc == 4)
  routinefile=argv[3];
 else
  routinefile=((void *)0);
 for (i=0; i < 3; i++)
  tweenskel[i]=&tween[i];
 Initialize(argc, argv);
 XSelectInput(dpy, win,
  (1L<<15)|(1L<<2)|(1L<<0));
 my_gcvalues.line_width=0;
 my_gcvalues.line_style=0;
 my_gcvalues.function=0x0;
 set_gc=XCreateGC(dpy, win,
  (1L<<0)|(1L<<4)|(1L<<5),
  &my_gcvalues);
 my_gcvalues.line_width=0;
 my_gcvalues.line_style=0;
 my_gcvalues.function=0xf;
 unset_gc=XCreateGC(dpy, win,
  (1L<<0)|(1L<<4)|(1L<<5),
  &my_gcvalues);
 my_gcvalues.line_width=0;
 my_gcvalues.line_style=0;
 my_gcvalues.function=0x5;
 noop_gc=XCreateGC(dpy, win,
  (1L<<0)|(1L<<4)|(1L<<5),
  &my_gcvalues);
 my_gcvalues.line_width=0;
 my_gcvalues.line_style=0;
 my_gcvalues.function=0xa;
 neg_gc=XCreateGC(dpy, win,
  (1L<<0)|(1L<<4)|(1L<<5),
  &my_gcvalues);
 skellist=ReadFile(posefile);
 if (routinefile)
  routine=ReadRoutineFile(routinefile);
 DanceMainLoop(routine);
 return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *posefile;
 char *routinefile;
 struct XGCValues my_gcvalues;
 int i;
 int *routine = ((void *)0);
 if (argc < 2) {
  printf ("Usage: %s posefile [framecount [routinefile]\n", argv[0]);
  exit (1);
 }
 posefile=argv[1];
 if (argc >= 3)
  steps=atoi(argv[2]);
 else
  steps=10;
 if (argc == 4)
  routinefile=argv[3];
 else
  routinefile=((void *)0);
 for (i=0; i < 3; i++)
  tweenskel[i]=&tween[i];
 Initialize(argc, argv);
 XSelectInput(dpy, win,
  (1L<<15)|(1L<<2)|(1L<<0));
 my_gcvalues.line_width=0;
 my_gcvalues.line_style=0;
 my_gcvalues.function=0x0;
 set_gc=XCreateGC(dpy, win,
  (1L<<0)|(1L<<4)|(1L<<5),
  &my_gcvalues);
 my_gcvalues.line_width=0;
 my_gcvalues.line_style=0;
 my_gcvalues.function=0xf;
 unset_gc=XCreateGC(dpy, win,
  (1L<<0)|(1L<<4)|(1L<<5),
  &my_gcvalues);
 my_gcvalues.line_width=0;
 my_gcvalues.line_style=0;
 my_gcvalues.function=0x5;
 noop_gc=XCreateGC(dpy, win,
  (1L<<0)|(1L<<4)|(1L<<5),
  &my_gcvalues);
 my_gcvalues.line_width=0;
 my_gcvalues.line_style=0;
 my_gcvalues.function=0xa;
 neg_gc=XCreateGC(dpy, win,
  (1L<<0)|(1L<<4)|(1L<<5),
  &my_gcvalues);
 skellist=ReadFile(posefile);
 if (routinefile)
  routine=ReadRoutineFile(routinefile);
 DanceMainLoop(routine);
 return(0);
}

variable_types:
posefile
char *

variable_types:
routinefile
char *

variable_types: struct XGCValues { int function; unsigned long plane_mask; unsigned long foreground; unsigned long background; int line_width; int line_style; int cap_style; int join_style; int fill_style; int fill_rule; int arc_mode; unsigned long tile; unsigned long stipple; int ts_x_origin; int ts_y_origin; unsigned long font; int subwindow_mode; int graphics_exposures; int clip_x_origin; int clip_y_origin; unsigned long clip_mask; int dash_offset; char dashes; }

variable_types: i int

variable_types:
routine
int *


DrawGrid

decompiled_code:
int DrawGrid()
{
GC *v0; // rbp
int i; // ebx
int result; // eax

v0 = (GC *)&gc_list;
for ( i = 0; i != 160; i += 10 )
{
XDrawLine(dpy, win, *v0, i, 0, i, 400);
result = XDrawLine(dpy, win, *v0++, 0, i, 400, i);
}
return result;
}

canonical_decompiled_code:
int func8()
{
GC *v0; // rbp
int i; // ebx
int result; // eax

v0 = (GC *)&gc_list;
for ( i = 0; i != 160; i += 10 )
{
XDrawLine(dpy, win, *v0, i, 0, i, 400);
result = XDrawLine(dpy, win, *v0++, 0, i, 400, i);
}
return result;
}

original_code:
void DrawGrid(void) {
 int fromx, fromy, tox, toy;
 int counter;
 for (counter=0; counter < 16; counter++) {
  fromx=counter*10;
  fromy=0;
  tox=counter*10;
  toy=400;
  XDrawLine(dpy, win,
   gc_list[counter],
   fromx, fromy, tox, toy);
  fromx=0;
  fromy=counter*10;
  tox=400;
  toy=counter*10;
  XDrawLine(dpy, win,
   gc_list[counter],
   fromx, fromy, tox, toy);
 }
}

canonical_original_code:
void DrawGrid() {
 int fromx; int fromy; int tox; int toy;
 int counter;
 for (counter=0; counter < 16; counter++) {
  fromx=counter*10;
  fromy=0;
  tox=counter*10;
  toy=400;
  XDrawLine(dpy, win,
   gc_list[counter],
   fromx, fromy, tox, toy);
  fromx=0;
  fromy=counter*10;
  tox=400;
  toy=counter*10;
  XDrawLine(dpy, win,
   gc_list[counter],
   fromx, fromy, tox, toy);
 }
}

variable_types: fromx int

variable_types: fromy int

variable_types: tox int

variable_types: toy int

variable_types: counter int


Initialize

decompiled_code:
int __fastcall Initialize(int a1, char **a2)
{
Display *v3; // rax
Display *v4; // rdi
Window *v5; // rax
XSizeHints v7; // [rsp+0h] [rbp-68h] BYREF

v3 = XOpenDisplay("");
dpy = v3;
if ( !v3 )
{
printf("Error: Can't open display.");
exit(-1);
}
v4 = v3;
v7.width = 400;
v7.height = 400;
v7.flags = 8LL;
v5 = (Window *)&v3->screens[(__int64)v3->default_screen];
win = XCreateSimpleWindow(v4, v5[2], 0, 0, 0x190u, 0x190u, 4u, v5[12], v5[11]);
XSetStandardProperties(dpy, win, "GC demo", "stickman", 0LL, a2, a1, &v7);
return XMapWindow(dpy, win);
}

canonical_decompiled_code:
int __fastcall func7(int a1, char **a2)
{
Display *v3; // rax
Display *v4; // rdi
Window *v5; // rax
XSizeHints v7; // [rsp+0h] [rbp-68h] BYREF

v3 = XOpenDisplay("");
dpy = v3;
if ( !v3 )
{
printf("Error: Can't open display.");
exit(-1);
}
v4 = v3;
v7.width = 400;
v7.height = 400;
v7.flags = 8LL;
v5 = (Window *)&v3->screens[(__int64)v3->default_screen];
win = XCreateSimpleWindow(v4, v5[2], 0, 0, 0x190u, 0x190u, 4u, v5[12], v5[11]);
XSetStandardProperties(dpy, win, "GC demo", "stickman", 0LL, a2, a1, &v7);
return XMapWindow(dpy, win);
}

original_code:
void Initialize(int argc, char** argv)
{
 XSizeHints size_hints;
 if (!(dpy=XOpenDisplay(""))) {
  printf ("Error: Can't open display.");
  exit(-1);
 }
 screen=(((_XPrivDisplay)(dpy))->default_screen);
 size_hints.width=400;
 size_hints.height=400;
 size_hints.flags=(1L << 3);
 win=XCreateSimpleWindow(dpy,
  ((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy))->default_screen)])->root),
  0, 0,
  size_hints.width,
  size_hints.height,
  4,
  ((&((_XPrivDisplay)(dpy))->screens[screen])->black_pixel),
  ((&((_XPrivDisplay)(dpy))->screens[screen])->white_pixel));
 XSetStandardProperties (dpy, win, "GC demo",
  "stickman",
  0L, argv, argc, &size_hints);
 XMapWindow(dpy, win);
}

canonical_original_code:
void Initialize(int argc, char **argv)
{
 struct XSizeHints size_hints;
 if (!(dpy=XOpenDisplay(""))) {
  printf ("Error: Can't open display.");
  exit(-1);
 }
 screen=(((_XPrivDisplay)(dpy))->default_screen);
 size_hints.width=400;
 size_hints.height=400;
 size_hints.flags=(1L << 3);
 win=XCreateSimpleWindow(dpy,
  ((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy))->default_screen)])->root),
  0, 0,
  size_hints.width,
  size_hints.height,
  4,
  ((&((_XPrivDisplay)(dpy))->screens[screen])->black_pixel),
  ((&((_XPrivDisplay)(dpy))->screens[screen])->white_pixel));
 XSetStandardProperties (dpy, win, "GC demo",
  "stickman",
  0L, argv, argc, &size_hints);
 XMapWindow(dpy, win);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct XSizeHints { long flags; int x; int width; int min_width; int max_width; int width_inc; struct { int x; int y; } min_aspect; int base_width; int win_gravity; }


allocatePipes

original_code:
void allocatePipes(cmdLine *head)
{
  if (!head || !head->next)
    return;
  *((int**)&head->outputPipe) = (int*) (malloc(2 * sizeof(int)));
  *((int**)&head->next->inputPipe) = head->outputPipe;
  allocatePipes(head->next);
}

canonical_original_code:
void allocatePipes(struct cmdLine *head)
{
  if (!head || !head->next)
    return;
  *((int **)&head->outputPipe) = (int *) (malloc(2 * sizeof(int)));
  *((int **)&head->next->inputPipe) = head->outputPipe;
  allocatePipes(head->next);
}

variable_types: struct cmdLine { char *arguments[256]; int argCount; char *inputRedirect; char *outputRedirect; char blocking; int *inputPipe; int *outputPipe; struct cmdLine *next; } *


cloneFirstWord

decompiled_code:
char *__fastcall cloneFirstWord(char *a1)
{
const char *v1; // rbp
char *v2; // rdi
char *v4; // r12
size_t v5; // rbx
char v6; // al

v1 = 0LL;
while ( 1 )
{
v6 = *a1;
if ( *a1 != 32 )
break;
if ( v1 )
{
v2 = a1 - 1;
goto LABEL_7;
}
LABEL_8:
++a1;
}
if ( v6 <= 32 )
{
if ( !v6 )
goto LABEL_3;
goto LABEL_12;
}
if ( (v6 & 0xFD) != 60 )
{
LABEL_12:
if ( !v1 )
v1 = a1;
goto LABEL_8;
}
LABEL_3:
v2 = a1 - 1;
if ( !v1 )
return (char *)v1;
LABEL_7:
v4 = (char *)malloc(v2 - v1 + 2);
v5 = (int)v2 - (int)v1 + 1;
strncpy(v4, v1, v5);
v4[v5] = 0;
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1)
{
const char *v1; // rbp
char *v2; // rdi
char *v4; // r12
size_t v5; // rbx
char v6; // al

v1 = 0LL;
while ( 1 )
{
v6 = *a1;
if ( *a1 != 32 )
break;
if ( v1 )
{
v2 = a1 - 1;
goto LABEL_7;
}
LABEL_8:
++a1;
}
if ( v6 <= 32 )
{
if ( !v6 )
goto LABEL_3;
goto LABEL_12;
}
if ( (v6 & 0xFD) != 60 )
{
LABEL_12:
if ( !v1 )
v1 = a1;
goto LABEL_8;
}
LABEL_3:
v2 = a1 - 1;
if ( !v1 )
return (char *)v1;
LABEL_7:
v4 = (char *)malloc(v2 - v1 + 2);
v5 = (int)v2 - (int)v1 + 1;
strncpy(v4, v1, v5);
v4[v5] = 0;
return v4;
}

original_code:
char* cloneFirstWord(char* str)
{
    char* start = ((void *)0);
    char* end = ((void *)0);
    char* word;
    while (!end) {
        switch (*str) {
            case '>':
            case '<':
            case 0:
                end = str - 1;
                break;
            case ' ':
                if (start)
                    end = str - 1;
                break;
            default:
                if (!start)
                    start = str;
                break;
        }
        str++;
    }
    if (start == ((void *)0))
        return ((void *)0);
    word = (char*) malloc(end-start+2);
    strncpy(word, start, ((int)(end-start)+1)) ;
    word[ (int)((end-start)+1)] = 0;
    return word;
}

canonical_original_code:
char *cloneFirstWord(char *str)
{
    char *start = ((void *)0);
    char *end = ((void *)0);
    char *word;
    while (!end) {
        switch (*str) {
            case '>':
            case '<':
            case 0:
                end = str - 1;
                break;
            case ' ':
                if (start)
                    end = str - 1;
                break;
            default:
                if (!start)
                    start = str;
                break;
        }
        str++;
    }
    if (start == ((void *)0))
        return ((void *)0);
    word = (char *) malloc(end-start+2);
    strncpy(word, start, ((int)(end-start)+1)) ;
    word[ (int)((end-start)+1)] = 0;
    return word;
}

variable_types:
str
char *

variable_types:
start
char *

variable_types:
end
char *

variable_types:
word
char *

return_type: char *


extractRedirections

decompiled_code:
char *__fastcall extractRedirections(const char *a1, __int64 a2)
{
void *v2; // rdi
char *result; // rax
char *v4; // rbx
void *v5; // rdi

while ( 1 )
{
result = strpbrk(a1, "<>");
v4 = result;
if ( !result )
break;
if ( *result == 60 )
{
v2 = *(void **)(a2 + 2056);
if ( v2 )
free(v2);
*(_QWORD *)(a2 + 2056) = cloneFirstWord(v4 + 1);
}
else
{
v5 = *(void **)(a2 + 2064);
if ( v5 )
free(v5);
*(_QWORD *)(a2 + 2064) = cloneFirstWord(v4 + 1);
}
a1 = v4 + 1;
*v4 = 0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, __int64 a2)
{
void *v2; // rdi
char *result; // rax
char *v4; // rbx
void *v5; // rdi

while ( 1 )
{
result = strpbrk(a1, "<>");
v4 = result;
if ( !result )
break;
if ( *result == 60 )
{
v2 = *(void **)(a2 + 2056);
if ( v2 )
free(v2);
*(_QWORD *)(a2 + 2056) = func1(v4 + 1);
}
else
{
v5 = *(void **)(a2 + 2064);
if ( v5 )
free(v5);
*(_QWORD *)(a2 + 2064) = func1(v4 + 1);
}
a1 = v4 + 1;
*v4 = 0;
}
return result;
}

original_code:
void extractRedirections(char* strLine, cmdLine *pCmdLine)
{
    char* s = strLine;
    while ( (s = strpbrk(s,"<>")) ) {
        if (*s == '<') {
            if(pCmdLine->inputRedirect) free((void*)pCmdLine->inputRedirect);
            pCmdLine->inputRedirect = cloneFirstWord(s+1);
        }
        else {
            if(pCmdLine->outputRedirect) free((void*)pCmdLine->outputRedirect);
            pCmdLine->outputRedirect = cloneFirstWord(s+1);
        }
        *s++ = 0;
    }
}

canonical_original_code:
void extractRedirections(char *strLine, struct cmdLine *pCmdLine)
{
    char *s = strLine;
    while ( (s = strpbrk(s,"<>")) ) {
        if (*s == '<') {
            if(pCmdLine->inputRedirect) free((void *)pCmdLine->inputRedirect);
            pCmdLine->inputRedirect = cloneFirstWord(s+1);
        }
        else {
            if(pCmdLine->outputRedirect) free((void *)pCmdLine->outputRedirect);
            pCmdLine->outputRedirect = cloneFirstWord(s+1);
        }
        *s++ = 0;
    }
}

variable_types:
strLine
char *

variable_types:
s
char *

user_defined_types: struct cmdLine { char *arguments[256]; int argCount; char *inputRedirect; char *outputRedirect; char blocking; int *inputPipe; int *outputPipe; struct cmdLine *next; }


strClone

decompiled_code:
char *__fastcall strClone(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

original_code:
char* strClone(const char* source)
{
    char* clone = (char*)malloc(strlen(source) + 1);
    strcpy(clone, source);
    return clone;
}

canonical_original_code:
char *strClone(char *source)
{
    char *clone = (char*)malloc(strlen(source) + 1);
    strcpy(clone, source);
    return clone;
}

variable_types:
source
char *

variable_types:
clone
char *


isEmpty

decompiled_code:
__int64 __fastcall isEmpty(char *a1)
{
char *v1; // rbp
char v2; // bl

v1 = a1;
if ( !a1 )
return 1LL;
while ( 1 )
{
v2 = *v1;
if ( !*v1 )
break;
++v1;
if ( ((*_ctype_b_loc())[v2] & 0x2000) == 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char *v1; // rbp
char v2; // bl

v1 = a1;
if ( !a1 )
return 1LL;
while ( 1 )
{
v2 = *v1;
if ( !*v1 )
break;
++v1;
if ( ((*_ctype_b_loc())[v2] & 0x2000) == 0 )
return 0LL;
}
return 1LL;
}

original_code:
int isEmpty(const char* str)
{
  if (!str)
    return 1;
  while (*str)
    if (!((*__ctype_b_loc ())[(int) ((*(str++)))] & (unsigned short int) _ISspace))
      return 0;
  return 1;
}

canonical_original_code:
int isEmpty(char *str)
{
  if (!str)
    return 1;
  while (*str)
    if (!((*__ctype_b_loc ())[(int) ((*(str++)))] & (unsigned short) _ISspace))
      return 0;
  return 1;
}


freeCmdLines

original_code:
void freeCmdLines(cmdLine* pCmdLine)
{
  int i;
  if (!pCmdLine)
    return;
  if(pCmdLine->outputPipe) free((void*)pCmdLine->outputPipe);
  if(pCmdLine->inputRedirect) free((void*)pCmdLine->inputRedirect);
  if(pCmdLine->outputRedirect) free((void*)pCmdLine->outputRedirect);
  for (i=0; i<pCmdLine->argCount; ++i)
      if(pCmdLine->arguments[i]) free((void*)pCmdLine->arguments[i]);
  if (pCmdLine->next)
   freeCmdLines(pCmdLine->next);
  if(pCmdLine) free((void*)pCmdLine);
}

canonical_original_code:
void freeCmdLines(struct cmdLine *pCmdLine)
{
  int i;
  if (!pCmdLine)
    return;
  if(pCmdLine->outputPipe) free((void *)pCmdLine->outputPipe);
  if(pCmdLine->inputRedirect) free((void *)pCmdLine->inputRedirect);
  if(pCmdLine->outputRedirect) free((void *)pCmdLine->outputRedirect);
  for (i=0; i<pCmdLine->argCount; ++i)
      if(pCmdLine->arguments[i]) free((void *)pCmdLine->arguments[i]);
  if (pCmdLine->next)
   freeCmdLines(pCmdLine->next);
  if(pCmdLine) free((void *)pCmdLine);
}

variable_types: i int


replaceCmdArg

decompiled_code:
__int64 __fastcall replaceCmdArg(__int64 a1, int a2, char *a3)
{
__int64 result; // rax
void *v6; // rdi

result = 0LL;
if ( *(_DWORD *)(a1 + 2048) > a2 )
{
v6 = *(void **)(a1 + 8LL * a2);
if ( v6 )
free(v6);
*(_QWORD *)(a1 + 8LL * a2) = strClone(a3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, char *a3)
{
__int64 result; // rax
void *v6; // rdi

result = 0LL;
if ( *(_DWORD *)(a1 + 2048) > a2 )
{
v6 = *(void **)(a1 + 8LL * a2);
if ( v6 )
free(v6);
*(_QWORD *)(a1 + 8LL * a2) = func3(a3);
result = 1LL;
}
return result;
}

original_code:
int replaceCmdArg(cmdLine *pCmdLine, int num, const char* newString)
{
  if (num >= pCmdLine->argCount)
    return 0;
  if(pCmdLine->arguments[num]) free((void*)pCmdLine->arguments[num]);
  ((char**)pCmdLine->arguments)[num] = strClone(newString);
  return 1;
}

canonical_original_code:
int replaceCmdArg(struct cmdLine *pCmdLine, int num, char *newString)
{
  if (num >= pCmdLine->argCount)
    return 0;
  if(pCmdLine->arguments[num]) free((void *)pCmdLine->arguments[num]);
  ((char **)pCmdLine->arguments)[num] = strClone(newString);
  return 1;
}

variable_types: num int

variable_types:
newString
char *


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

if ( a1 )
result = printf("%s - %d\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 16));
return result;
}

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

if ( a1 )
result = printf("%s - %d\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 16));
return result;
}

original_code:
void print_entry(entry * node){
 if(node != ((void *)0)){
  printf("%s - %d\n",node->lastname,node->count);
 }
}

canonical_original_code:
void print_entry(struct entry *node){
 if(node != ((void *)0)){
  printf("%s - %d\n",node->lastname,node->count);
 }
}

variable_types: struct entry { struct entry *next; char *lastname; int count; } *


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = (_QWORD *)*a1;
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = (_QWORD *)*a1;
}
while ( a1 );
return result;
}

original_code:
int list_length(entry* list){
 int ans=0 ;
 struct entry *current=list;
 while ( current != ((void *)0) ){
  ans++;
  current=current->next;
 }
 return ans;
}

canonical_original_code:
int list_length(struct entry *list){
 int ans = 0;
 struct entry *current = list;
 while ( current != ((void *)0) ){
  ans++;
  current=current->next;
 }
 return ans;
}

variable_types: ans int

user_defined_types: struct entry { struct entry *next; char *lastname; int count; }


decompiled_code:
void __fastcall free_list(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)*v1;
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)*v1;
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

original_code:
void free_list(entry* list){
 struct entry *current=list;
 struct entry *toDelete=list;
 while ( current != ((void *)0) ){
  current=current->next;
  free(toDelete->lastname);
  free(toDelete);
  toDelete=current;
 }
}

canonical_original_code:
void free_list(struct entry *list){
 struct entry *current = list;
 struct entry *toDelete = list;
 while ( current != ((void *)0) ){
  current=current->next;
  free(toDelete->lastname);
  free(toDelete);
  toDelete=current;
 }
}


testLL

decompiled_code:
void testLL()
{
_QWORD *v0; // rax
_QWORD *v1; // rax
_QWORD *v2; // rbx
unsigned int v3; // eax

v0 = register_entry(0LL, "last_name1");
v1 = register_entry(v0, "last_name1");
v2 = register_entry(v1, "last_name2");
v3 = list_length(v2);
printf("list contains %d entries:\n", v3);
foreach(v2, (__int64 (__fastcall *)(_QWORD *))print_entry);
free_list(v2);
}

canonical_decompiled_code:
void func4()
{
_QWORD *v0; // rax
_QWORD *v1; // rax
_QWORD *v2; // rbx
unsigned int v3; // eax

v0 = register_entry(0LL, "last_name1");
v1 = register_entry(v0, "last_name1");
v2 = register_entry(v1, "last_name2");
v3 = func2(v2);
printf("list contains %d entries:\n", v3);
func1(v2, (__int64 (__fastcall *)(_QWORD *))print_entry);
func3(v2);
}

original_code:
void testLL(){
  entry * list = register_entry(((void *)0), "last_name1");
  list = register_entry(list , "last_name1");
  list = register_entry(list , "last_name2");
  printf("list contains %d entries:\n", list_length(list));
  foreach(list, print_entry);
  free_list(list);
}

canonical_original_code:
void testLL(){
  struct entry *list = register_entry(((void *)0), "last_name1");
  list = register_entry(list , "last_name1");
  list = register_entry(list , "last_name2");
  printf("list contains %d entries:\n", list_length(list));
  foreach(list, print_entry);
  free_list(list);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi

v3 = argv[1];
if ( v3 )
task1b(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi

v3 = argv[1];
if ( v3 )
func5(v3);
return 0;
}

original_code:
int main(int argc, char **argv) {
 if(argv[1] != ((void *)0)){
   task1b(argv[1]);
 }
 return 0;
}

variable_types: argc int


checkEnv

decompiled_code:
__int64 checkEnv()
{
__int64 v0; // rax
int v1; // edx
__int64 result; // rax

if ( *environ )
{
v0 = 1LL;
do
v1 = v0++;
while ( environ[v0 - 1] );
}
else
{
v1 = 0;
}
result = 0LL;
if ( env_count != v1 )
{
if ( env_count <= v1 )
{
env_count = v1;
result = 1LL;
}
else
{
env_count = v1;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
int v1; // edx
__int64 result; // rax

if ( *environ )
{
v0 = 1LL;
do
v1 = v0++;
while ( environ[v0 - 1] );
}
else
{
v1 = 0;
}
result = 0LL;
if ( env_count != v1 )
{
if ( env_count <= v1 )
{
env_count = v1;
result = 1LL;
}
else
{
env_count = v1;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int checkEnv(){
 int i=0;
 while(environ[i]){
  i++;
 }
 if(i==env_count){
  return 0;
 }
 else if(i<env_count){
  env_count=i;
  return -1;
 }
 else{
  env_count=i;
  return 1;
 }
}

canonical_original_code:
int checkEnv(){
 int i = 0;
 while(environ[i]){
  i++;
 }
 if(i==env_count){
  return 0;
 }
 else if(i<env_count){
  env_count=i;
  return -1;
 }
 else{
  env_count=i;
  return 1;
 }
}


createPipes

decompiled_code:
void __fastcall createPipes(__int64 a1)
{
__int64 i; // rbx
int *v2; // rax

for ( i = a1; *(_QWORD *)(i + 2096); i = *(_QWORD *)(i + 2096) )
{
if ( pipe(*(int **)(i + 2088)) < 0 )
{
perror("Error in creating pipes");
v2 = _errno_location();
exit(*v2);
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
__int64 i; // rbx
int *v2; // rax

for ( i = a1; *(_QWORD *)(i + 2096); i = *(_QWORD *)(i + 2096) )
{
if ( pipe(*(int **)(i + 2088)) < 0 )
{
perror("Error in creating pipes");
v2 = _errno_location();
exit(*v2);
}
}
}

original_code:
void createPipes(cmdLine* pCmdLine){
 while (pCmdLine->next) {
  if (pipe(pCmdLine->outputPipe)<0){
   perror("Error in creating pipes");
   exit((*__errno_location ()));
  }
  pCmdLine=pCmdLine->next;
 }
}

canonical_original_code:
void createPipes(struct cmdLine *pCmdLine){
 while (pCmdLine->next) {
  if (pipe(pCmdLine->outputPipe)<0){
   perror("Error in creating pipes");
   exit((*__errno_location ()));
  }
  pCmdLine=pCmdLine->next;
 }
}


bubbleSort

original_code:
void bubbleSort(int numbers[], int array_size)
{
  int i, j;
  int * temp;
  for (i = (array_size - 1); i > 0; i--)
  {
    for (j = 1; j <= i; j++)
    {
      if (numbers[j-1] > numbers[j])
      {
    temp = (int*)malloc(sizeof(int*));
        *temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = *temp;
    free(temp);
      }
    }
  }
}

canonical_original_code:
void bubbleSort(int numbers[], int array_size)
{
  int i; int j;
  int *temp;
  for (i = (array_size - 1); i > 0; i--)
  {
    for (j = 1; j <= i; j++)
    {
      if (numbers[j-1] > numbers[j])
      {
    temp = (int *)malloc(sizeof(int *));
        *temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = *temp;
    free(temp);
      }
    }
  }
}

variable_types:
numbers
int []

variable_types: j int

variable_types:
temp
int *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int *v4; // r13
const char **v5; // rbx
int *v6; // rbp
unsigned int *v7; // rbx

v3 = argc - 1;
v4 = (int *)calloc(argc - 1, 4uLL);
printf("Original array:");
if ( argc - 1 >= 0 )
{
v5 = argv + 1;
v6 = v4;
do
{
if ( !*v5 )
break;
printf(" %s", *v5);
*v6++ = atoi(*v5++);
}
while ( v5 != &argv[(unsigned int)(argc - 1) + 2] );
}
putchar(10);
bubbleSort(v4, v3);
printf("Sorted array:");
if ( v3 > 0 )
{
v7 = (unsigned int *)v4;
do
printf(" %d", *v7++);
while ( v7 != (unsigned int *)&v4[argc - 2 + 1] );
}
putchar(10);
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int *v4; // r13
const char **v5; // rbx
int *v6; // rbp
unsigned int *v7; // rbx

v3 = argc - 1;
v4 = (int *)calloc(argc - 1, 4uLL);
printf("Original array:");
if ( argc - 1 >= 0 )
{
v5 = argv + 1;
v6 = v4;
do
{
if ( !*v5 )
break;
printf(" %s", *v5);
*v6++ = atoi(*v5++);
}
while ( v5 != &argv[(unsigned int)(argc - 1) + 2] );
}
putchar(10);
func0(v4, v3);
printf("Sorted array:");
if ( v3 > 0 )
{
v7 = (unsigned int *)v4;
do
printf(" %d", *v7++);
while ( v7 != (unsigned int *)&v4[argc - 2 + 1] );
}
putchar(10);
free(v4);
return 0;
}

original_code:
int main(int argc, char **argv) {
  char **arr = argv+1;
  int i, n = argc-1;
  int * numbers=(int*)calloc(n,sizeof(int));
  printf("Original array:");
  for(i = 0; (i<=n && arr[i] != ((void *)0)); ++i){
    printf(" %s", arr[i]);
    numbers[i]=atoi(arr[i]);
  }
  printf("\n");
  bubbleSort(numbers, n);
  printf("Sorted array:");
  for(i = 0; i<n; ++i)
    printf(" %d", numbers[i]);
  printf("\n");
  free(numbers);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  char **arr = argv+1;
  int i; int n = argc-1;
  int *numbers = (int*)calloc(n,sizeof(int));
  printf("Original array:");
  for(i = 0; (i<=n && arr[i] != ((void *)0)); ++i){
    printf(" %s", arr[i]);
    numbers[i]=atoi(arr[i]);
  }
  printf("\n");
  bubbleSort(numbers, n);
  printf("Sorted array:");
  for(i = 0; i<n; ++i)
    printf(" %d", numbers[i]);
  printf("\n");
  free(numbers);
  return 0;
}

variable_types:
argv
char **

variable_types:
arr
char **

variable_types: n int

variable_types:
numbers
int *


checksum

decompiled_code:
__int64 __fastcall checksum(unsigned __int16 *a1, unsigned __int16 a2)
{
unsigned int v2; // esi
unsigned __int16 *v3; // rax
__int64 v4; // rcx

v2 = a2 >> 1;
if ( v2 )
{
v3 = a1;
v4 = (__int64)&a1[v2];
v2 = 0;
do
v2 += *v3++;
while ( v3 != (unsigned __int16 *)v4 );
}
return ~(v2 + HIWORD(v2));
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int16 *a1, unsigned __int16 a2)
{
unsigned int v2; // esi
unsigned __int16 *v3; // rax
__int64 v4; // rcx

v2 = a2 >> 1;
if ( v2 )
{
v3 = a1;
v4 = (__int64)&a1[v2];
v2 = 0;
do
v2 += *v3++;
while ( v3 != (unsigned __int16 *)v4 );
}
return ~(v2 + HIWORD(v2));
}

original_code:
uint16_t checksum(uint16_t *buf, uint16_t buf_size)
{
 unsigned u;
 uint32_t sum = 0;
 buf_size /= 2;
 for(u = 0; u < buf_size; u++)
  sum += buf[u];
 return ~ ((sum & 0xFFFF) + (sum >> 16));
}

canonical_original_code:
unsigned short checksum(unsigned short *buf, unsigned short buf_size)
{
 unsigned int u;
 unsigned int sum = 0;
 buf_size /= 2;
 for(u = 0; u < buf_size; u++)
  sum += buf[u];
 return ~ ((sum & 0xFFFF) + (sum >> 16));
}

variable_types:
buf
unsigned short *

variable_types:
u
unsigned int

variable_types:
sum
unsigned int

return_type: unsigned short


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
unsigned int i; // ebp
ssize_t v6; // rax
struct sockaddr v8; // [rsp+0h] [rbp-2028h] BYREF
char v9[4096]; // [rsp+10h] [rbp-2018h] BYREF
unsigned __int16 buf; // [rsp+1010h] [rbp-1018h] BYREF
__int16 v11; // [rsp+1012h] [rbp-1016h]
__int16 v12; // [rsp+1014h] [rbp-1014h]
__int16 v13; // [rsp+1016h] [rbp-1012h]

if ( argc == 3 )
{
v3 = socket(2, 3, 1);
if ( v3 == -1 )
{
fwrite(&unk_402198, 1uLL, 0x34uLL, _bss_start);
}
else
{
v4 = atoi(argv[2]);
buf = 8;
v12 = -11646;
v8.sa_family = 2;
*(_WORD *)v8.sa_data = 0;
inet_aton(argv[1], (struct in_addr *)&v8.sa_data[2]);
putchar(10);
if ( (unsigned int)(v4 + 1) > 1 )
{
for ( i = 1; ; ++i )
{
v13 = (_WORD)i << 8;
v11 = 0;
v11 = checksum(&buf, 8u);
sendto(v3, &buf, 0x6CuLL, 0, &v8, 0x10u);
printf(&format, i);
do
{
sleep(1u);
v6 = recv(v3, v9, 0x1000uLL, 64);
}
while ( v6 < 0 );
if ( v6 > 0 && !v9[160] )
puts(&s);
if ( v4 == i )
break;
}
}
putchar(10);
close(v3);
v3 = 0;
}
}
else
{
fwrite(&unk_402008, 1uLL, 0x18EuLL, _bss_start);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
unsigned int i; // ebp
ssize_t v6; // rax
struct sockaddr v8; // [rsp+0h] [rbp-2028h] BYREF
char v9[4096]; // [rsp+10h] [rbp-2018h] BYREF
unsigned __int16 buf; // [rsp+1010h] [rbp-1018h] BYREF
__int16 v11; // [rsp+1012h] [rbp-1016h]
__int16 v12; // [rsp+1014h] [rbp-1014h]
__int16 v13; // [rsp+1016h] [rbp-1012h]

if ( argc == 3 )
{
v3 = socket(2, 3, 1);
if ( v3 == -1 )
{
fwrite(&unk_402198, 1uLL, 0x34uLL, _bss_start);
}
else
{
v4 = atoi(argv[2]);
buf = 8;
v12 = -11646;
v8.sa_family = 2;
*(_WORD *)v8.sa_data = 0;
inet_aton(argv[1], (struct in_addr *)&v8.sa_data[2]);
putchar(10);
if ( (unsigned int)(v4 + 1) > 1 )
{
for ( i = 1; ; ++i )
{
v13 = (_WORD)i << 8;
v11 = 0;
v11 = func7(&buf, 8u);
sendto(v3, &buf, 0x6CuLL, 0, &v8, 0x10u);
printf(&format, i);
do
{
sleep(1u);
v6 = recv(v3, v9, 0x1000uLL, 64);
}
while ( v6 < 0 );
if ( v6 > 0 && !v9[160] )
puts(&s);
if ( v4 == i )
break;
}
}
putchar(10);
close(v3);
v3 = 0;
}
}
else
{
fwrite(&unk_402008, 1uLL, 0x18EuLL, _bss_start);
v3 = -1;
}
return v3;
}

original_code:
int main(const int argc, const char *argv[])
{
 if(argc != 3)
 {
  fprintf(stderr, "\nПрограмме передано недостаточное количество аргументов\n\nФормат вызова: ./program IP NUM\n\nЗдесь:\n\n\tIP\t-\tIPv4-адрес сетевого узла - получателя пакетов типа ECHO протокола ICMP;\n\tNUM\t-\tколичество отправляемых пакетов типа ECHO протокола ICMP.\n\n");
  return -1;
 }
 int sock = socket(2, SOCK_RAW, IPPROTO_ICMP);
 if(sock == -1)
 {
  fprintf(stderr, "\nОшибка при создании сокета\n\n");
  return -1;
 }
 unsigned u, max_u = atoi(argv[2]) + 1;
 ssize_t size;
 uint8_t echo_buf[4096], echo_reply_buf[4096];
 struct sockaddr_in addr;
 struct icmphdr *echo_hdr = (struct icmphdr *) echo_buf, *echo_reply_hdr = (struct icmphdr *) echo_reply_buf + sizeof(struct iphdr);
 echo_hdr->type = 8;
 echo_hdr->code = 0;
 echo_hdr->un.echo.id = 53890;
 addr.sin_family = 2;
 addr.sin_port = 0;
 inet_aton(argv[1], & addr.sin_addr);
 printf("\n");
 for(u = 1; u < max_u; u++)
 {
  echo_hdr->un.echo.sequence = u << 8;
  echo_hdr->checksum = 0;
  echo_hdr->checksum = checksum((uint16_t *) echo_hdr, sizeof(struct icmphdr));
  sendto(sock, echo_buf, sizeof(struct icmphdr) + 100, 0, (struct sockaddr *) & addr, sizeof(struct sockaddr_in));
  printf("Пакет %u отправлен -> ", u);
  do
  {
   sleep(1);
   size = recv(sock, echo_reply_buf, 4096, MSG_DONTWAIT);
  }
  while (size < 0);
  if(size > 0)
   if(echo_reply_hdr->type == 0)
    printf("ответ получен\n");
 }
 printf("\n");
 close(sock);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc != 3)
 {
  fprintf(stderr, "\nПрограмме передано недостаточное количество аргументов\n\nФормат вызова: ./program IP NUM\n\nЗдесь:\n\n\tIP\t-\tIPv4-адрес сетевого узла - получателя пакетов типа ECHO протокола ICMP;\n\tNUM\t-\tколичество отправляемых пакетов типа ECHO протокола ICMP.\n\n");
  return -1;
 }
 int sock = socket(2, SOCK_RAW, IPPROTO_ICMP);
 if(sock == -1)
 {
  fprintf(stderr, "\nОшибка при создании сокета\n\n");
  return -1;
 }
 unsigned int u; unsigned int max_u = atoi(argv[2]) + 1;
 long size;
 unsigned char echo_buf[4096]; unsigned char echo_reply_buf[4096];
 struct sockaddr_in addr;
 struct icmphdr *echo_hdr = (struct icmphdr *) echo_buf; struct icmphdr *echo_reply_hdr = (struct icmphdr *) echo_reply_buf + sizeof(struct iphdr);
 echo_hdr->type = 8;
 echo_hdr->code = 0;
 echo_hdr->un.echo.id = 53890;
 addr.sin_family = 2;
 addr.sin_port = 0;
 inet_aton(argv[1], & addr.sin_addr);
 printf("\n");
 for(u = 1; u < max_u; u++)
 {
  echo_hdr->un.echo.sequence = u << 8;
  echo_hdr->checksum = 0;
  echo_hdr->checksum = checksum((unsigned short *) echo_hdr, sizeof(struct icmphdr));
  sendto(sock, echo_buf, sizeof(struct icmphdr) + 100, 0, (struct sockaddr *) & addr, sizeof(struct sockaddr_in));
  printf("Пакет %u отправлен -> ", u);
  do
  {
   sleep(1);
   size = recv(sock, echo_reply_buf, 4096, MSG_DONTWAIT);
  }
  while (size < 0);
  if(size > 0)
   if(echo_reply_hdr->type == 0)
    printf("ответ получен\n");
 }
 printf("\n");
 close(sock);
 return 0;
}

variable_types:
argv
char *[]

variable_types: sock int

variable_types: size long

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 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 __unused; unsigned short mtu; } frag; unsigned char reserved[4]; } un; } *

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 { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall get_iface_id(int fd, const char *a2)
{
__int64 result; // rax
char v3[16]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v4; // [rsp+10h] [rbp-28h]

strcpy(v3, a2);
if ( ioctl(fd, 0x8933uLL, v3) )
result = 0xFFFFFFFFLL;
else
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, const char *a2)
{
__int64 result; // rax
char v3[16]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v4; // [rsp+10h] [rbp-28h]

strcpy(v3, a2);
if ( ioctl(fd, 0x8933uLL, v3) )
result = 0xFFFFFFFFLL;
else
result = v4;
return result;
}

original_code:
int get_iface_id(int sock, const char* device_name)
{
 struct ifreq req;
 strcpy(req.ifr_ifrn.ifrn_name, device_name);
 if(ioctl(sock, 0x8933, & req))
  return -1;
 return req.ifr_ifru.ifru_ivalue;
}

canonical_original_code:
int get_iface_id(int sock, char *device_name)
{
 struct ifreq req;
 strcpy(req.ifr_ifrn.ifrn_name, device_name);
 if(ioctl(sock, 0x8933, & req))
  return -1;
 return req.ifr_ifru.ifru_ivalue;
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
__int64 __fastcall set_mac(_BYTE *a1, const char *a2)
{
char *v3; // rbx
char v5[18]; // [rsp+0h] [rbp-38h] BYREF
char v6; // [rsp+12h] [rbp-26h] BYREF

if ( strlen(a2) != 17 )
return 0xFFFFFFFFLL;
strcpy(v5, a2);
v3 = v5;
do
{
v3[2] = 0;
*a1 = strtoul(v3, 0LL, 16);
v3 += 3;
++a1;
}
while ( v3 != &v6 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, const char *a2)
{
char *v3; // rbx
char v5[18]; // [rsp+0h] [rbp-38h] BYREF
char v6; // [rsp+12h] [rbp-26h] BYREF

if ( strlen(a2) != 17 )
return 0xFFFFFFFFLL;
strcpy(v5, a2);
v3 = v5;
do
{
v3[2] = 0;
*a1 = strtoul(v3, 0LL, 16);
v3 += 3;
++a1;
}
while ( v3 != &v6 );
return 0LL;
}

original_code:
int set_mac(uint8_t *buf, const char *mac)
{
 if(strlen(mac) != 17)
  return -1;
 unsigned u, v;
 char temp[18];
 strcpy(temp, mac);
 for(u = 0, v = 0; u < 17; u += 3, v ++)
 {
  temp[u + 2] = '\0';
  buf[v] = strtoul(temp + u, ((void *)0), 16);
 }
 return 0;
}

canonical_original_code:
int set_mac(unsigned char *buf, char *mac)
{
 if(strlen(mac) != 17)
  return -1;
 unsigned int u; unsigned int v;
 char temp[18];
 strcpy(temp, mac);
 for(u = 0, v = 0; u < 17; u += 3, v ++)
 {
  temp[u + 2] = '\0';
  buf[v] = strtoul(temp + u, ((void *)0), 16);
 }
 return 0;
}

variable_types:
buf
unsigned char *

variable_types:
mac
char *

variable_types:
v
unsigned int

variable_types:
temp
char [18]


original_code:
int set_ip(uint8_t *buf, const char *ip)
{
 int v;
 unsigned mask = 0xFF000000;
 in_addr_t addr = inet_addr(ip);
 for(v = 3; v >= 0; v--, mask >>= 8)
  buf[v] = (addr & mask) >> (v << 3);
 return 0;
}

canonical_original_code:
int set_ip(unsigned char *buf, char *ip)
{
 int v;
 unsigned int mask = 0xFF000000;
 unsigned int addr = inet_addr(ip);
 for(v = 3; v >= 0; v--, mask >>= 8)
  buf[v] = (addr & mask) >> (v << 3);
 return 0;
}

variable_types:
ip
char *

variable_types: v int

variable_types:
mask
unsigned int

variable_types:
addr
unsigned int


original_code:
char *mac_to_str(const uint8_t *mac)
{
 char *temp = malloc(18 * sizeof(char));
 if(temp == ((void *)0))
  return ((void *)0);
 sprintf(temp, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
 return temp;
}

canonical_original_code:
char *mac_to_str(unsigned char *mac)
{
 char *temp = malloc(18 * sizeof(char));
 if(temp == ((void *)0))
  return ((void *)0);
 sprintf(temp, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
 return temp;
}

variable_types:
mac
unsigned char *

variable_types:
temp
char *


original_code:
int main(const int argc, const char *argv[])
{
 if(argc != 5)
 {
  fprintf(stderr, "\nПрограмме передано недостаточное количество аргументов\n\nФормат вызова: ./program IFACE IMAC IIP OIP\n\nЗдесь:\n\n\tIFACE\t-\tимя сетевого интерфейса сетевого адаптера сетевого узла - отправителя;\n\tIMAC\t-\tMAC-адрес сетевого адаптера сетевого узла - отправителя;\n\tIIP\t-\tIPv4-адрес сетевого узла - отправителя;\n\tOIP\t-\tIPv4-адрес, соответствующий MAC-адрес для которого необходимо определить.\n\n");
  return -1;
 }
 int sock = socket(17, SOCK_DGRAM, htons(0x0806));
 if(sock == -1)
 {
  fprintf(stderr, "\nОшибка: создать сокет не удалось\n\n");
  return -1;
 }
 uint8_t buf[4096];
 struct arphdr *hdr = (struct arphdr *) buf;
 size_t aoff = sizeof(struct arphdr);
 hdr->ar_hrd = htons(1);
 hdr->ar_pro = htons(0x0800);
 hdr->ar_hln = 6;
 hdr->ar_pln = 4;
 hdr->ar_op = htons(1);
 if(set_mac(buf + aoff, argv[2]))
 {
  fprintf(stderr, "\nОшибка при копировании MAC-адреса сетевого адаптера сетевого узла - отправителя в буфер\n\n");
  close(sock);
  return -1;
 }
 if(set_ip(buf + aoff + 6, argv[3]))
 {
  fprintf(stderr, "\nОшибка при копировании IP-адреса сетевого узла - отправителя в буфер\n\n");
  close(sock);
  return -1;
 }
 buf[aoff + 10] = 0;
 buf[aoff + 11] = 0;
 buf[aoff + 12] = 0;
 buf[aoff + 13] = 0;
 buf[aoff + 14] = 0;
 buf[aoff + 15] = 0;
 if(set_ip(buf + aoff + 16, argv[4]))
 {
  fprintf(stderr, "\nОшибка при копировании IP-адреса сетевого узла - получателя в буфер\n\n");
  close(sock);
  return -1;
 }
 struct sockaddr_ll addr;
 memset(& addr, 0, sizeof(struct sockaddr_ll));
 addr.sll_family = 17;
 addr.sll_protocol = htons(0x0806);
 addr.sll_hatype = 1;
 addr.sll_pkttype = 1;
 addr.sll_halen = 6;
 memset(addr.sll_addr, 0xFF, 8);
 if(
  (addr.sll_ifindex = get_iface_id(sock, argv[1])) == -1
   )
 {
  fprintf(stderr, "\nОшибка при получении идентификатора сетевого интерфейса\n\n");
  close(sock);
  return -1;
 }
 ssize_t size = sendto(sock, buf, aoff + 20, 0, (struct sockaddr *) & addr, sizeof(struct sockaddr_ll));
 if(size > 0)
 {
  char *temp;
  do
   size = recv(sock, buf, 4096, 0);
  while(ntohs(hdr->ar_op) != 2);
  if(
   (size > 0)
   &&
   (temp = mac_to_str(buf + aoff + 10)) != ((void *)0)
    )
  {
   printf("\nПолучен ARP-ответ: %s -> %s\n\n", argv[4], temp);
   free(temp);
  }
  else
  {
   fprintf(stderr, "\nОшибка при получении ARP-ответа\n\n");
   close(sock);
   return -1;
  }
 }
 else
 {
  fprintf(stderr, "\nОшибка при отправлении ARP-запроса\n\n");
  close(sock);
  return -1;
 }
 close(sock);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc != 5)
 {
  fprintf(stderr, "\nПрограмме передано недостаточное количество аргументов\n\nФормат вызова: ./program IFACE IMAC IIP OIP\n\nЗдесь:\n\n\tIFACE\t-\tимя сетевого интерфейса сетевого адаптера сетевого узла - отправителя;\n\tIMAC\t-\tMAC-адрес сетевого адаптера сетевого узла - отправителя;\n\tIIP\t-\tIPv4-адрес сетевого узла - отправителя;\n\tOIP\t-\tIPv4-адрес, соответствующий MAC-адрес для которого необходимо определить.\n\n");
  return -1;
 }
 int sock = socket(17, SOCK_DGRAM, htons(0x0806));
 if(sock == -1)
 {
  fprintf(stderr, "\nОшибка: создать сокет не удалось\n\n");
  return -1;
 }
 unsigned char buf[4096];
 struct arphdr *hdr = (struct arphdr *) buf;
 unsigned long aoff = sizeof(struct arphdr);
 hdr->ar_hrd = htons(1);
 hdr->ar_pro = htons(0x0800);
 hdr->ar_hln = 6;
 hdr->ar_pln = 4;
 hdr->ar_op = htons(1);
 if(set_mac(buf + aoff, argv[2]))
 {
  fprintf(stderr, "\nОшибка при копировании MAC-адреса сетевого адаптера сетевого узла - отправителя в буфер\n\n");
  close(sock);
  return -1;
 }
 if(set_ip(buf + aoff + 6, argv[3]))
 {
  fprintf(stderr, "\nОшибка при копировании IP-адреса сетевого узла - отправителя в буфер\n\n");
  close(sock);
  return -1;
 }
 buf[aoff + 10] = 0;
 buf[aoff + 11] = 0;
 buf[aoff + 12] = 0;
 buf[aoff + 13] = 0;
 buf[aoff + 14] = 0;
 buf[aoff + 15] = 0;
 if(set_ip(buf + aoff + 16, argv[4]))
 {
  fprintf(stderr, "\nОшибка при копировании IP-адреса сетевого узла - получателя в буфер\n\n");
  close(sock);
  return -1;
 }
 struct sockaddr_ll addr;
 memset(& addr, 0, sizeof(struct sockaddr_ll));
 addr.sll_family = 17;
 addr.sll_protocol = htons(0x0806);
 addr.sll_hatype = 1;
 addr.sll_pkttype = 1;
 addr.sll_halen = 6;
 memset(addr.sll_addr, 0xFF, 8);
 if(
  (addr.sll_ifindex = get_iface_id(sock, argv[1])) == -1
   )
 {
  fprintf(stderr, "\nОшибка при получении идентификатора сетевого интерфейса\n\n");
  close(sock);
  return -1;
 }
 long size = sendto(sock, buf, aoff + 20, 0, (struct sockaddr *) & addr, sizeof(struct sockaddr_ll));
 if(size > 0)
 {
  char *temp;
  do
   size = recv(sock, buf, 4096, 0);
  while(ntohs(hdr->ar_op) != 2);
  if(
   (size > 0)
   &&
   (temp = mac_to_str(buf + aoff + 10)) != ((void *)0)
    )
  {
   printf("\nПолучен ARP-ответ: %s -> %s\n\n", argv[4], temp);
   free(temp);
  }
  else
  {
   fprintf(stderr, "\nОшибка при получении ARP-ответа\n\n");
   close(sock);
   return -1;
  }
 }
 else
 {
  fprintf(stderr, "\nОшибка при отправлении ARP-запроса\n\n");
  close(sock);
  return -1;
 }
 close(sock);
 return 0;
}

variable_types: argc int

variable_types:
buf
unsigned char [4096]

variable_types: struct arphdr { unsigned short ar_hrd; unsigned short ar_pro; unsigned char ar_hln; unsigned char ar_pln; unsigned short ar_op; } *

variable_types:
aoff
unsigned long

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }


decompiled_code:
void __noreturn SIGINT_handler()
{
if ( sock != -1 )
{
if ( is_promisc )
{
word_4040D0 ^= 0x100u;
ioctl(sock, 0x8914uLL, req);
}
close(sock);
}
puts(s);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
if ( sock != -1 )
{
if ( is_promisc )
{
word_4040D0 ^= 0x100u;
ioctl(sock, 0x8914uLL, req);
}
close(sock);
}
puts(s);
exit(0);
}

original_code:
void SIGINT_handler(int notused)
{
 if(sock != -1)
 {
  if(is_promisc)
  {
   req.ifr_ifru.ifru_flags ^= IFF_PROMISC;
   ioctl(sock, 0x8914, & req);
  }
  close(sock);
 }
 printf("\n-----> Останов прослушивания <-----\n\n");
 exit(0);
}

variable_types: notused int


error

decompiled_code:
__int64 __fastcall error(__int64 a1)
{
fprintf(stderr, format, a1);
if ( sock != -1 )
close(sock);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
fprintf(stderr, format, a1);
if ( sock != -1 )
close(sock);
return 0xFFFFFFFFLL;
}

original_code:
int error(const char *mes)
{
 fprintf(stderr, "[Ошибка] %s\n\n", mes);
 if(sock != -1)
  close(sock);
 return -1;
}

canonical_original_code:
int error(char *mes)
{
 fprintf(stderr, "[Ошибка] %s\n\n", mes);
 if(sock != -1)
  close(sock);
 return -1;
}

variable_types:
mes
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v4; // bp
int v5; // ebx
ssize_t v6; // rbx
in_addr_t v7; // er15
unsigned int v8; // er12
unsigned __int16 v9; // r13
char *v10; // rax
char *v11; // rax
unsigned __int16 v12; // [rsp+Eh] [rbp-104Ah]
char buf[12]; // [rsp+10h] [rbp-1048h] BYREF
__int16 v14; // [rsp+1Ch] [rbp-103Ch]
char v15; // [rsp+27h] [rbp-1031h]
struct in_addr in; // [rsp+2Ah] [rbp-102Eh]
struct in_addr v17; // [rsp+2Eh] [rbp-102Ah]
__int16 v18; // [rsp+32h] [rbp-1026h]
__int16 v19; // [rsp+34h] [rbp-1024h]
unsigned __int8 v20; // [rsp+3Eh] [rbp-101Ah]
char v21; // [rsp+3Fh] [rbp-1019h]

putchar(10);
if ( argc != 2 )
return error((__int64)&unk_402048);
if ( signal(2, (__sighandler_t)SIGINT_handler) == (__sighandler_t)-1LL )
return error((__int64)&unk_402128);
v4 = _bswap_16(2048);
v5 = socket(17, 3, v4);
sock = v5;
if ( v5 == -1 )
return error((__int64)&unk_402180);
strcpy(req, argv[1]);
if ( ioctl(v5, 0x8913uLL, req) )
return error((__int64)&unk_4021B0);
word_4040D0 |= 0x100u;
if ( !ioctl(sock, 0x8914uLL, req) )
{
is_promisc = 1;
puts(asc_402290);
while ( 1 )
{
do
{
do
v6 = recv(sock, buf, 0x1000uLL, 0);
while ( v6 <= 0 );
}
while ( v4 != v14 || v15 != 6 );
v7 = v17.s_addr;
v8 = 4 * (v20 >> 4) + 34;
v9 = _bswap_16(v18);
v10 = inet_ntoa(in);
printf("[ %s:%u -> ", v10, v9);
v12 = _bswap_16(v19);
v11 = inet_ntoa((struct in_addr)v7);
printf(aSUD, v11, v12, v6, v6 - v8);
if ( (v21 & 1) != 0 )
printf("FIN ");
if ( (v21 & 2) != 0 )
printf("SYN ");
if ( (v21 & 4) != 0 )
printf("RST ");
if ( (v21 & 8) != 0 )
printf("PUSH ");
if ( (v21 & 0x10) != 0 )
printf("ACK ");
if ( (v21 & 0x20) != 0 )
printf("URG ");
printf("] ");
if ( v8 == v6 )
{
putchar(10);
}
else
{
if ( *((_BYTE *)&v12 + v6 + 1) == 10 )
*((_BYTE *)&v12 + v6 + 1) = 0;
printf("[ %s ]\n", &buf[v8]);
}
}
}
return error((__int64)&unk_402220);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v4; // bp
int v5; // ebx
ssize_t v6; // rbx
in_addr_t v7; // er15
unsigned int v8; // er12
unsigned __int16 v9; // r13
char *v10; // rax
char *v11; // rax
unsigned __int16 v12; // [rsp+Eh] [rbp-104Ah]
char buf[12]; // [rsp+10h] [rbp-1048h] BYREF
__int16 v14; // [rsp+1Ch] [rbp-103Ch]
char v15; // [rsp+27h] [rbp-1031h]
struct in_addr in; // [rsp+2Ah] [rbp-102Eh]
struct in_addr v17; // [rsp+2Eh] [rbp-102Ah]
__int16 v18; // [rsp+32h] [rbp-1026h]
__int16 v19; // [rsp+34h] [rbp-1024h]
unsigned __int8 v20; // [rsp+3Eh] [rbp-101Ah]
char v21; // [rsp+3Fh] [rbp-1019h]

putchar(10);
if ( argc != 2 )
return func9((__int64)&unk_402048);
if ( signal(2, (__sighandler_t)SIGINT_handler) == (__sighandler_t)-1LL )
return func9((__int64)&unk_402128);
v4 = func8(2048);
v5 = socket(17, 3, v4);
sock = v5;
if ( v5 == -1 )
return func9((__int64)&unk_402180);
strcpy(req, argv[1]);
if ( ioctl(v5, 0x8913uLL, req) )
return func9((__int64)&unk_4021B0);
word_4040D0 |= 0x100u;
if ( !ioctl(sock, 0x8914uLL, req) )
{
is_promisc = 1;
puts(asc_402290);
while ( 1 )
{
do
{
do
v6 = recv(sock, buf, 0x1000uLL, 0);
while ( v6 <= 0 );
}
while ( v4 != v14 || v15 != 6 );
v7 = v17.s_addr;
v8 = 4 * (v20 >> 4) + 34;
v9 = func8(v18);
v10 = inet_ntoa(in);
printf("[ %s:%u -> ", v10, v9);
v12 = func8(v19);
v11 = inet_ntoa((struct in_addr)v7);
printf(aSUD, v11, v12, v6, v6 - v8);
if ( (v21 & 1) != 0 )
printf("FIN ");
if ( (v21 & 2) != 0 )
printf("SYN ");
if ( (v21 & 4) != 0 )
printf("RST ");
if ( (v21 & 8) != 0 )
printf("PUSH ");
if ( (v21 & 0x10) != 0 )
printf("ACK ");
if ( (v21 & 0x20) != 0 )
printf("URG ");
printf("] ");
if ( v8 == v6 )
{
putchar(10);
}
else
{
if ( *((_BYTE *)&v12 + v6 + 1) == 10 )
*((_BYTE *)&v12 + v6 + 1) = 0;
printf("[ %s ]\n", &buf[v8]);
}
}
}
return func9((__int64)&unk_402220);
}

original_code:
int main(const int argc, const char *argv[])
{
 printf("\n");
 if(argc != 2)
  return error("Программе передано недостаточное количество аргументов\n\nФормат вызова: ./program ИМЯ_ПРОСЛУШИВАЕМОГО_СЕТЕВОГО_ИНТЕРФЕЙСА");
 if(signal(2, & SIGINT_handler) == ((__sighandler_t) -1))
  return error("Невозможно установить обработчик сигнала SIGINT");
 sock = socket(17, SOCK_RAW, htons(0x0800));
 if (sock == -1)
  return error("Невозможно создать сокет");
 strcpy(req.ifr_ifrn.ifrn_name, argv[1]);
 if(ioctl(sock, 0x8913, & req))
  return error("Невозможно получить набор параметров сетевого адаптера\n");
 req.ifr_ifru.ifru_flags |= IFF_PROMISC;
 if(ioctl(sock, 0x8914, & req))
  return error("Невозможно перевести сетевой адаптер в неразборчивый режим\n");
 is_promisc = 1;
 char buf[4096 + 1];
 unsigned tcp_data_offset;
 ssize_t get_bytes;
 struct in_addr saddr, daddr;
 struct ethhdr *eth_header = (struct ethhdr *) buf;
 struct iphdr *ip_header = (struct iphdr *) (buf + sizeof(struct ethhdr));
 struct tcphdr *tcp_header = (struct tcphdr *) (buf + (sizeof(struct ethhdr) + sizeof(struct iphdr)));
 printf("-----> Запуск прослушивания <-----\n\n");
 while(1)
 {
  if(
   (get_bytes = recv(sock, buf, 4096, 0)) > 0
   &&
   (eth_header->h_proto == htons(0x0800))
   &&
   (ip_header->protocol == IPPROTO_TCP)
    )
  {
   saddr.s_addr = ip_header->saddr;
   daddr.s_addr = ip_header->daddr;
   tcp_data_offset = (sizeof(struct ethhdr) + sizeof(struct iphdr)) + tcp_header->doff * 4;
   printf("[ %s:%u -> ", inet_ntoa(saddr), ntohs(tcp_header->source));
   printf("%s:%u ] [ %d байт, %d байт данных ] [ ", inet_ntoa(daddr), ntohs(tcp_header->dest), get_bytes, get_bytes - tcp_data_offset);
   if(tcp_header->fin)
    printf("FIN ");
   if(tcp_header->syn)
    printf("SYN ");
   if(tcp_header->rst)
    printf("RST ");
   if(tcp_header->psh)
    printf("PUSH ");
   if(tcp_header->ack)
    printf("ACK ");
   if(tcp_header->urg)
    printf("URG ");
   printf("] ");
   if(tcp_data_offset != get_bytes)
   {
    if(buf[get_bytes - 1] == 0x0A)
     buf[get_bytes - 1] = '\0';
    printf("[ %s ]\n", buf + tcp_data_offset);
   }
   else
    printf("\n");
  }
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 printf("\n");
 if(argc != 2)
  return error("Программе передано недостаточное количество аргументов\n\nФормат вызова: ./program ИМЯ_ПРОСЛУШИВАЕМОГО_СЕТЕВОГО_ИНТЕРФЕЙСА");
 if(signal(2, & SIGINT_handler) == ((__sighandler_t) -1))
  return error("Невозможно установить обработчик сигнала SIGINT");
 sock = socket(17, SOCK_RAW, htons(0x0800));
 if (sock == -1)
  return error("Невозможно создать сокет");
 strcpy(req.ifr_ifrn.ifrn_name, argv[1]);
 if(ioctl(sock, 0x8913, & req))
  return error("Невозможно получить набор параметров сетевого адаптера\n");
 req.ifr_ifru.ifru_flags |= IFF_PROMISC;
 if(ioctl(sock, 0x8914, & req))
  return error("Невозможно перевести сетевой адаптер в неразборчивый режим\n");
 is_promisc = 1;
 char buf[-1];
 unsigned int tcp_data_offset;
 long get_bytes;
 struct in_addr saddr; struct in_addr daddr;
 struct ethhdr *eth_header = (struct ethhdr *) buf;
 struct iphdr *ip_header = (struct iphdr *) (buf + sizeof(struct ethhdr));
 struct tcphdr *tcp_header = (struct tcphdr *) (buf + (sizeof(struct ethhdr) + sizeof(struct iphdr)));
 printf("-----> Запуск прослушивания <-----\n\n");
 while(1)
 {
  if(
   (get_bytes = recv(sock, buf, 4096, 0)) > 0
   &&
   (eth_header->h_proto == htons(0x0800))
   &&
   (ip_header->protocol == IPPROTO_TCP)
    )
  {
   saddr.s_addr = ip_header->saddr;
   daddr.s_addr = ip_header->daddr;
   tcp_data_offset = (sizeof(struct ethhdr) + sizeof(struct iphdr)) + tcp_header->doff * 4;
   printf("[ %s:%u -> ", inet_ntoa(saddr), ntohs(tcp_header->source));
   printf("%s:%u ] [ %d байт, %d байт данных ] [ ", inet_ntoa(daddr), ntohs(tcp_header->dest), get_bytes, get_bytes - tcp_data_offset);
   if(tcp_header->fin)
    printf("FIN ");
   if(tcp_header->syn)
    printf("SYN ");
   if(tcp_header->rst)
    printf("RST ");
   if(tcp_header->psh)
    printf("PUSH ");
   if(tcp_header->ack)
    printf("ACK ");
   if(tcp_header->urg)
    printf("URG ");
   printf("] ");
   if(tcp_data_offset != get_bytes)
   {
    if(buf[get_bytes - 1] == 0x0A)
     buf[get_bytes - 1] = '\0';
    printf("[ %s ]\n", buf + tcp_data_offset);
   }
   else
    printf("\n");
  }
 }
}

variable_types:
argv
char *[]

variable_types:
buf
char [-1]

variable_types:
saddr
struct in_addr { unsigned int s_addr; }

variable_types:
daddr
struct in_addr { unsigned int s_addr; }

variable_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; } *

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: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } *


decompiled_code:
double normal_distrib()
{
int v0; // ebx
double v1; // xmm0_8
double v3; // [rsp+8h] [rbp-10h]

v0 = 12;
v3 = 0.0;
do
{
v1 = drand48() + v3;
v3 = v1;
--v0;
}
while ( v0 );
return (v1 - 6.0) / 6.0;
}

original_code:
double normal_distrib()
{
 unsigned k;
 double epsilon;
 for(k = 0, epsilon = 0; k < 12; k++)
  epsilon += drand48();
 return (epsilon - 6) / 6;
}

canonical_original_code:
double normal_distrib()
{
 unsigned int k;
 double epsilon;
 for(k = 0, epsilon = 0; k < 12; k++)
  epsilon += drand48();
 return (epsilon - 6) / 6;
}

variable_types:
k
unsigned int

variable_types: epsilon double

return_type: double


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
int v5; // er14
void *v6; // r12
__int64 v7; // rax
unsigned int v8; // ebp
int result; // eax
struct timespec v10; // [rsp+40h] [rbp-48h] BYREF
struct timespec tp; // [rsp+50h] [rbp-38h] BYREF

if ( argc == 4 )
{
v3 = atoi(argv[2]);
v4 = atoi(argv[3]);
if ( (unsigned int)v3 <= 2 )
{
fwrite(&unk_402050, 1uLL, 0x88uLL, stderr);
result = -1;
}
else
{
v5 = v4;
v6 = calloc(v4, 8uLL);
v7 = lrand48();
srand48(v7);
atoi(argv[1]);
omp_set_num_threads();
v8 = omp_get_max_threads();
clock_gettime(0, &tp);
GOMP_parallel();
clock_gettime(0, &v10);
printf(
format,
v8,
0.0,
0.0 / (double)v5,
(double)v3 / (double)(v3 - 2),
(double)(LODWORD(v10.tv_sec) - LODWORD(tp.tv_sec) + 1)
+ (double)(LODWORD(v10.tv_nsec) - LODWORD(tp.tv_nsec)) / 1000000000.0);
free(v6);
result = 0;
}
}
else
{
fwrite(&unk_402008, 1uLL, 0x46uLL, stderr);
result = -1;
}
return result;
}

original_code:
int main(const int argc, const char * argv[])
{
 if(argc != 4)
 {
  fprintf(stderr, "\nНедостаточно или избыток аргументов\n\n");
  return -1;
 }
 unsigned u, v, t_ind, t_num, n = atoi(argv[2]), N = atoi(argv[3]);
 if(n < 3)
 {
  fprintf(stderr, "\nЧисло степеней свободы распределения Стьюдента должно быть больше двух)\n\n");
  return -1;
 }
 double tx, su, m = 0, d = 0, * x = calloc(N, sizeof(double));
 struct timespec ts_before, ts_after;
 srand48(lrand48());
 omp_set_num_threads(atoi(argv[1]));
 t_num = omp_get_max_threads();
 clock_gettime(0, & ts_before);

#pragma omp parallel private(t_ind, u, v, tx, su)
 {
  t_ind = omp_get_thread_num();
  for(u = t_ind; u < N; u += t_num)
  {
   for(v = 0, tx = 0; v < n; v++)
   {
    su = normal_distrib();
    tx += su * su;
   }
   x[u] = tx = normal_distrib() / sqrt(tx / n);

#pragma omp critical
   {
    m += tx;
   }
  }

#pragma omp barrier

#pragma omp single
  {
   m /= (double) N;
  }

#pragma omp barrier
  for(u = t_ind; u < N; u += t_num)
  {
   tx = x[u] - m;

#pragma omp critical
   {
    d += tx * tx;
   }
  }
 }
 d /= (double) N;
 clock_gettime(0, & ts_after);
 printf("\nМатематическое ожидание:\n\n\tЭмпирическое = %lf\n\tТеоретическое = 0\n\nДисперсия:\n\n\tЭмпирическая = %lf\n\tТеоретическая = %lf\n\nРасчет выполнили %d поток(а; ов) за %lf секунд(ы)\n\n", m, d, n / (double) (n - 2), t_num, ts_after.tv_sec - ts_before.tv_sec + 1 + (ts_after.tv_nsec - ts_before.tv_nsec) / 1000000000.0);
 free(x);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc != 4)
 {
  fprintf(stderr, "\nНедостаточно или избыток аргументов\n\n");
  return -1;
 }
 unsigned int u; unsigned int v; unsigned int t_ind; unsigned int t_num; unsigned int n = atoi(argv[2]); unsigned int N = atoi(argv[3]);
 if(n < 3)
 {
  fprintf(stderr, "\nЧисло степеней свободы распределения Стьюдента должно быть больше двух)\n\n");
  return -1;
 }
 double tx; double su; double m = 0; double d = 0; double *x = calloc(N, sizeof(double));
 struct timespec ts_before; struct timespec ts_after;
 srand48(lrand48());
 omp_set_num_threads(atoi(argv[1]));
 t_num = omp_get_max_threads();
 clock_gettime(0, & ts_before);

#pragma omp parallel private(t_ind, u, v, tx, su)
 {
  t_ind = omp_get_thread_num();
  for(u = t_ind; u < N; u += t_num)
  {
   for(v = 0, tx = 0; v < n; v++)
   {
    su = normal_distrib();
    tx += su * su;
   }
   x[u] = tx = normal_distrib() / sqrt(tx / n);

#pragma omp critical
   {
    m += tx;
   }
  }

#pragma omp barrier

#pragma omp single
  {
   m /= (double) N;
  }

#pragma omp barrier
  for(u = t_ind; u < N; u += t_num)
  {
   tx = x[u] - m;

#pragma omp critical
   {
    d += tx * tx;
   }
  }
 }
 d /= (double) N;
 clock_gettime(0, & ts_after);
 printf("\nМатематическое ожидание:\n\n\tЭмпирическое = %lf\n\tТеоретическое = 0\n\nДисперсия:\n\n\tЭмпирическая = %lf\n\tТеоретическая = %lf\n\nРасчет выполнили %d поток(а; ов) за %lf секунд(ы)\n\n", m, d, n / (double) (n - 2), t_num, ts_after.tv_sec - ts_before.tv_sec + 1 + (ts_after.tv_nsec - ts_before.tv_nsec) / 1000000000.0);
 free(x);
 return 0;
}

variable_types:
u
unsigned int

variable_types:
v
unsigned int

variable_types:
n
unsigned int

variable_types:
N
unsigned int

variable_types: tx double

variable_types: su double

variable_types: m double

variable_types: d double

variable_types:
x
double *

variable_types: struct timespec { long tv_sec; long tv_nsec; }


printIndentation

repo: vgramer/TP-compil

decompiled_code:
int printIndentation()
{
int v0; // ebx
int result; // eax

if ( indent > 0 )
{
v0 = 0;
do
{
result = printf(" ");
++v0;
}
while ( indent > v0 );
}
return result;
}

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

if ( indent > 0 )
{
v0 = 0;
do
{
result = printf(" ");
++v0;
}
while ( indent > v0 );
}
return result;
}

original_code:
void printIndentation(){
 int i=0;
 for(i=0;i<indent;i++){
   printf("    ");
 }
}

canonical_original_code:
void printIndentation(){
 int i = 0;
 for(i=0;i<indent;i++){
   printf("    ");
 }
}

variable_types: i int


pprintGet

decompiled_code:
int pprintGet()
{
return printf("LIRE()");
}

canonical_decompiled_code:
int func1()
{
return printf("LIRE()");
}

original_code:
void pprintGet() {
  printf("LIRE()");
}

canonical_original_code:
void pprintGet() {
  printf("LIRE()");
}


concate

decompiled_code:
char *__fastcall concate(const char **a1, const char *a2)
{
char *v2; // r13
size_t v3; // r12
size_t v4; // rax
char *v5; // rax
char *result; // rax

v2 = (char *)*a1;
v3 = strlen(*a1);
v4 = strlen(a2);
v5 = (char *)realloc(v2, v3 + v4 + 1);
*a1 = v5;
if ( !v5 )
{
printf("\n\n------------------------\n ERROR CAN NOT REALOCC MEMORY !!!! \n------------------------");
exit(1);
}
result = strcat(v5, a2);
*a1 = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char **a1, const char *a2)
{
char *v2; // r13
size_t v3; // r12
size_t v4; // rax
char *v5; // rax
char *result; // rax

v2 = (char *)*a1;
v3 = strlen(*a1);
v4 = strlen(a2);
v5 = (char *)realloc(v2, v3 + v4 + 1);
*a1 = v5;
if ( !v5 )
{
printf("\n\n------------------------\n ERROR CAN NOT REALOCC MEMORY !!!! \n------------------------");
exit(1);
}
result = strcat(v5, a2);
*a1 = result;
return result;
}

original_code:
void concate(char** source, const char* stringToConcate)
{
 *source = (char*)realloc(*source, sizeof(char) * (strlen(*source) + strlen(stringToConcate) +1) );
 if(*source == 0)
 {
  printf("\n\n------------------------\n ERROR CAN NOT REALOCC MEMORY !!!! \n------------------------");
  exit(1);
 }
 *source =strcat(*source, stringToConcate);
}

canonical_original_code:
void concate(char **source, char *stringToConcate)
{
 *source = (char *)realloc(*source, sizeof(char) * (strlen(*source) + strlen(stringToConcate) +1) );
 if(*source == 0)
 {
  printf("\n\n------------------------\n ERROR CAN NOT REALOCC MEMORY !!!! \n------------------------");
  exit(1);
 }
 *source =strcat(*source, stringToConcate);
}

variable_types:
source
char **

variable_types:
stringToConcate
char *


genIndentation

decompiled_code:
char *__fastcall genIndentation(const char **a1)
{
int v1; // ebx
char *result; // rax

if ( indentation > 0 )
{
v1 = 0;
do
{
result = concate(a1, " ");
++v1;
}
while ( indentation > v1 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char **a1)
{
int v1; // ebx
char *result; // rax

if ( indentation > 0 )
{
v1 = 0;
do
{
result = func0(a1, " ");
++v1;
}
while ( indentation > v1 );
}
return result;
}

original_code:
void genIndentation(char** generated_code){
 int i=0;
 for(i=0;i<indentation;i++){
   concate(generated_code, "    ");
 }
}

canonical_original_code:
void genIndentation(char **generated_code){
 int i = 0;
 for(i=0;i<indentation;i++){
   concate(generated_code, "    ");
 }
}


genGet

decompiled_code:
char *__fastcall genGet(const char **a1)
{
return concate(a1, "__ask_int_value()");
}

canonical_decompiled_code:
char *__fastcall func4(const char **a1)
{
return func0(a1, "__ask_int_value()");
}

original_code:
void genGet(char** generated_code) {
  concate(generated_code, "__ask_int_value()");
}

canonical_original_code:
void genGet(char **generated_code) {
  concate(generated_code, "__ask_int_value()");
}


repo: vhbsoft/triton

decompiled_code:
int __fastcall w_UDPTrainGenerator(void *a1)
{
int result; // eax

result = UDPTrainReceiver(*((_QWORD *)a1 + 1), (char *)a1 + 16, *(unsigned int *)a1);
if ( result )
result = fprintf(stderr, "ERROR #%d: UDP Train Receiver Error", 7LL);
return result;
}

canonical_decompiled_code:
int __fastcall func0(void *a1)
{
int result; // eax

result = UDPTrainReceiver(*((_QWORD *)a1 + 1), (char *)a1 + 16, *(unsigned int *)a1);
if ( result )
result = fprintf(stderr, "ERROR #%d: UDP Train Receiver Error", 7LL);
return result;
}

original_code:
void w_UDPTrainGenerator(struct thread_data* td)
{
 if(UDPTrainReceiver(td->send_buffer, &(td->send_buffer_length), td->probe_packet_length) != 0)
 {
  fprintf(stderr, "ERROR #%d: UDP Train Receiver Error", UDP_TRAIN_RECEIVER_FAILED);
      return;
 }
}

canonical_original_code:
void w_UDPTrainGenerator(struct thread_data *td)
{
 if(UDPTrainReceiver(td->send_buffer, &(td->send_buffer_length), td->probe_packet_length) != 0)
 {
  fprintf(stderr, "ERROR #%d: UDP Train Receiver Error", UDP_TRAIN_RECEIVER_FAILED);
      return;
 }
}

variable_types: struct thread_data { int probe_packet_length; char *send_buffer; unsigned long send_buffer_length; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // rax
int result; // eax
pthread_t newthread; // [rsp+8h] [rbp-40h] BYREF
int arg; // [rsp+10h] [rbp-38h] BYREF
void *v7; // [rsp+18h] [rbp-30h]
__int64 v8; // [rsp+20h] [rbp-28h]
int v9; // [rsp+2Ch] [rbp-1Ch] BYREF
char v10[12]; // [rsp+30h] [rbp-18h] BYREF
char v11[12]; // [rsp+3Ch] [rbp-Ch] BYREF

while ( 1 )
{
v3 = &send_buffer;
do
*v3++ = 0;
while ( v3 != (_BYTE *)(unsigned int)((_DWORD)&send_buffer + 150000) );
send_buffer_length = 0LL;
if ( (unsigned int)PreExperimentTCPReceiver(v11, v10, &v9) )
{
fprintf(stderr, "ERROR #%d: PreExperiment TCP Receiver Error", 3LL);
return 3;
}
puts("Pre is done");
arg = v9;
v7 = &send_buffer;
v8 = send_buffer_length;
result = pthread_create(&newthread, 0LL, (void *(*)(void *))w_UDPTrainGenerator, &arg);
if ( result == -1 )
return result;
puts("UDP is done");
if ( (unsigned int)PostExperimentTCPReceiver(&send_buffer, &unk_249F0) )
break;
puts("Post is done");
pthread_kill(newthread, 2);
pthread_join(newthread, 0LL);
}
fprintf(stderr, "ERROR #%d: PostExperiment TCP Receiver Error", 5LL);
return 5;
}

original_code:
int main(int argc, char *argv[])
{
  int num_of_packets;
  unsigned long inter_packet_departure_spacing;
  int probe_packet_length;
  while(1)
  {
  int i;
  for(i=0; i<150000;i++){
    send_buffer[i] = 0;
  }
  send_buffer_length = 0;
  if(PreExperimentTCPReceiver(&num_of_packets, &inter_packet_departure_spacing,
                              &probe_packet_length) != 0)
  {
    fprintf(stderr, "ERROR #%d: PreExperiment TCP Receiver Error", PRE_EXPERIMENT_TCP_RECEIVER_FAILED);
    return PRE_EXPERIMENT_TCP_RECEIVER_FAILED;
  }
 printf("Pre is done\n");
 pthread_t t0;
 struct thread_data td;
 td.probe_packet_length = probe_packet_length;
 td.send_buffer = send_buffer;
 td.send_buffer_length = send_buffer_length;
 if (pthread_create(&t0, ((void *)0), (void*)w_UDPTrainGenerator, (void*) &td) == -1)
  return -1;
 printf("UDP is done\n");
  if(PostExperimentTCPReceiver( send_buffer, 150000) != 0)
  {
    fprintf(stderr, "ERROR #%d: PostExperiment TCP Receiver Error", POST_EXPERIMENT_TCP_RECEIVER_FAILED);
    return POST_EXPERIMENT_TCP_RECEIVER_FAILED;
  }
 printf("Post is done\n");
 pthread_kill(t0,2);
 pthread_join(t0, ((void *)0));
  }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int num_of_packets;
  unsigned long inter_packet_departure_spacing;
  int probe_packet_length;
  while(1)
  {
  int i;
  for(i=0; i<150000;i++){
    send_buffer[i] = 0;
  }
  send_buffer_length = 0;
  if(PreExperimentTCPReceiver(&num_of_packets, &inter_packet_departure_spacing,
                              &probe_packet_length) != 0)
  {
    fprintf(stderr, "ERROR #%d: PreExperiment TCP Receiver Error", PRE_EXPERIMENT_TCP_RECEIVER_FAILED);
    return PRE_EXPERIMENT_TCP_RECEIVER_FAILED;
  }
 printf("Pre is done\n");
 unsigned long t0;
 struct thread_data td;
 td.probe_packet_length = probe_packet_length;
 td.send_buffer = send_buffer;
 td.send_buffer_length = send_buffer_length;
 if (pthread_create(&t0, ((void *)0), (void *)w_UDPTrainGenerator, (void *) &td) == -1)
  return -1;
 printf("UDP is done\n");
  if(PostExperimentTCPReceiver( send_buffer, 150000) != 0)
  {
    fprintf(stderr, "ERROR #%d: PostExperiment TCP Receiver Error", POST_EXPERIMENT_TCP_RECEIVER_FAILED);
    return POST_EXPERIMENT_TCP_RECEIVER_FAILED;
  }
 printf("Post is done\n");
 pthread_kill(t0,2);
 pthread_join(t0, ((void *)0));
  }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct thread_data { int probe_packet_length; char *send_buffer; unsigned long send_buffer_length; }


decompiled_code:
void __noreturn handle_shutdown()
{
if ( recv_socket )
close(recv_socket);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __noreturn func0()
{
if ( recv_socket )
close(recv_socket);
pthread_exit(0LL);
}

original_code:
void handle_shutdown(int sig)
{
        if (recv_socket)
         close(recv_socket);
        pthread_exit(((void *)0));
}

variable_types: sig int