original_code:
void pk_setDoorData(int doorCnt, doorEntry_t* doorData, map_t* map) {
 if(map->doorAlloced) {
  free(map->doorData);
 }
 map->doorData = (doorEntry_t*)malloc(doorCnt*sizeof(doorEntry_t));
 map->doorAlloced = 1;
 for(int i=0; i<doorCnt; i++) {
  if(!pk_isSolid(map->data[doorData[i].x+(doorData[i].y*map->width)], map)) {
   doorData[i].type = 1;
  } else {
   doorData[i].type = 2;
  }
  map->doorData[i] = doorData[i];
 }
 map->doorCnt = doorCnt;
}

canonical_original_code:
void pk_setDoorData(int doorCnt, struct doorEntry_t *doorData, struct map_t *map) {
 if(map->doorAlloced) {
  free(map->doorData);
 }
 map->doorData = (struct doorEntry_t *)malloc(doorCnt*sizeof(doorEntry_t));
 map->doorAlloced = 1;
 for(int i = 0; i<doorCnt; i++) {
  if(!pk_isSolid(map->data[doorData[i].x+(doorData[i].y*map->width)], map)) {
   doorData[i].type = 1;
  } else {
   doorData[i].type = 2;
  }
  map->doorData[i] = doorData[i];
 }
 map->doorCnt = doorCnt;
}

variable_types: doorCnt int

variable_types: struct doorEntry_t { unsigned char dest; unsigned int x; unsigned int destX; unsigned int type; } *

variable_types: struct map_t { int width; unsigned char *data; unsigned char *cData; unsigned char *tileColData; struct doorEntry_t *doorData; struct npcEntry_t { unsigned char value; unsigned int x; } *npcData; int doorCnt; _Bool doorAlloced; } *


repo: velovix/super-glitch-engine

decompiled_code:
void *__fastcall pk_setNpcData(int a1, const void *a2, __int64 a3)
{
void *result; // rax

if ( *(_BYTE *)(a3 + 61) )
free(*(void **)(a3 + 40));
result = malloc(12LL * a1);
*(_BYTE *)(a3 + 61) = 1;
*(_QWORD *)(a3 + 40) = result;
if ( a1 > 0 )
result = memcpy(result, a2, 12LL * a1);
*(_DWORD *)(a3 + 52) = a1;
return result;
}

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

if ( *(_BYTE *)(a3 + 61) )
free(*(void **)(a3 + 40));
result = malloc(12LL * a1);
*(_BYTE *)(a3 + 61) = 1;
*(_QWORD *)(a3 + 40) = result;
if ( a1 > 0 )
result = memcpy(result, a2, 12LL * a1);
*(_DWORD *)(a3 + 52) = a1;
return result;
}

original_code:
void pk_setNpcData(int npcCnt, npcEntry_t *npcData, map_t* map) {
 if(map->npcAlloced) {
  free(map->npcData);
 }
 map->npcData = (npcEntry_t*)malloc(npcCnt*sizeof(npcEntry_t));
 map->npcAlloced = 1;
 for(int i=0; i<npcCnt; i++) {
  map->npcData[i] = npcData[i];
 }
 map->npcCnt = npcCnt;
}

canonical_original_code:
void pk_setNpcData(int npcCnt, struct npcEntry_t *npcData, struct map_t *map) {
 if(map->npcAlloced) {
  free(map->npcData);
 }
 map->npcData = (struct npcEntry_t *)malloc(npcCnt*sizeof(npcEntry_t));
 map->npcAlloced = 1;
 for(int i = 0; i<npcCnt; i++) {
  map->npcData[i] = npcData[i];
 }
 map->npcCnt = npcCnt;
}

variable_types: npcCnt int

variable_types: struct npcEntry_t { unsigned char value; unsigned int x; } *

variable_types: struct map_t { int width; unsigned char *data; unsigned char *cData; unsigned char *tileColData; struct doorEntry_t { unsigned char dest; unsigned int x; unsigned int destX; unsigned int type; } *doorData; struct npcEntry_t *npcData; int doorCnt; _Bool doorAlloced; } *

variable_types: i int

return_type: void

user_defined_types: struct map_t { int width; unsigned char *data; unsigned char *cData; unsigned char *tileColData; struct doorEntry_t *doorData; struct npcEntry_t *npcData; int doorCnt; _Bool doorAlloced; }


original_code:
void pk_initChar(int s_x, int s_y, charMover_t* obj) {
 obj->x = s_x;
 obj->y = s_y;
 obj->lastX = s_x;
 obj->lastY = s_y;
 obj->nextX = s_x;
 obj->nextY = s_y;
 obj->dir = 2;
 obj->step = 0;
 obj->animCycle = 0;
}

canonical_original_code:
void pk_initChar(int s_x, int s_y, struct charMover_t *obj) {
 obj->x = s_x;
 obj->y = s_y;
 obj->lastX = s_x;
 obj->lastY = s_y;
 obj->nextX = s_x;
 obj->nextY = s_y;
 obj->dir = 2;
 obj->step = 0;
 obj->animCycle = 0;
}

variable_types: struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; } *


decompiled_code:
__int64 __fastcall pk_getCharFrame(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, __int64 a10, char a11)
{
__int64 result; // rax

if ( HIDWORD(a10) == 3 )
{
result = (unsigned int)(a1 + 7);
if ( (int)a10 > 8 )
result = (unsigned int)(a11 == 0) + a1 + 8;
}
else if ( SHIDWORD(a10) > 3 )
{
if ( HIDWORD(a10) != 4 )
return 1LL;
result = (unsigned int)(a1 + 4);
if ( (int)a10 > 8 )
result = (unsigned int)(a11 == 0) + a1 + 5;
}
else
{
if ( HIDWORD(a10) != 1 )
{
if ( HIDWORD(a10) == 2 )
return a1 + (unsigned int)((int)a10 > 8);
return 1LL;
}
result = (unsigned int)((int)a10 > 8) + a1 + 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, __int64 a10, char a11)
{
__int64 result; // rax

if ( HIDWORD(a10) == 3 )
{
result = (unsigned int)(a1 + 7);
if ( (int)a10 > 8 )
result = (unsigned int)(a11 == 0) + a1 + 8;
}
else if ( SHIDWORD(a10) > 3 )
{
if ( HIDWORD(a10) != 4 )
return 1LL;
result = (unsigned int)(a1 + 4);
if ( (int)a10 > 8 )
result = (unsigned int)(a11 == 0) + a1 + 5;
}
else
{
if ( HIDWORD(a10) != 1 )
{
if ( HIDWORD(a10) == 2 )
return a1 + (unsigned int)((int)a10 > 8);
return 1LL;
}
result = (unsigned int)((int)a10 > 8) + a1 + 2;
}
return result;
}

original_code:
int pk_getCharFrame(int spriteOffset, charMover_t obj) {
 switch(obj.dir) {
 case 2:
  if(obj.animCycle > 16/2) {
   return spriteOffset+1;
  } else {
   return spriteOffset;
  }
  break;
 case 1:
  if(obj.animCycle > 16/2) {
   return spriteOffset+3;
  } else {
   return spriteOffset+2;
  }
 case 3:
  if(obj.animCycle > 16/2) {
   if(obj.step) return spriteOffset+8;
   if(!obj.step) return spriteOffset+9;
  } else {
   return spriteOffset+7;
  }
  break;
 case 4:
  if(obj.animCycle > 16/2) {
   if(obj.step) return spriteOffset+5;
   if(!obj.step) return spriteOffset+6;
  } else {
   return spriteOffset+4;
  }
  break;
 }
 return 1;
}

canonical_original_code:
int pk_getCharFrame(int spriteOffset, struct charMover_t obj) {
 switch(obj.dir) {
 case 2:
  if(obj.animCycle > 16/2) {
   return spriteOffset+1;
  } else {
   return spriteOffset;
  }
  break;
 case 1:
  if(obj.animCycle > 16/2) {
   return spriteOffset+3;
  } else {
   return spriteOffset+2;
  }
 case 3:
  if(obj.animCycle > 16/2) {
   if(obj.step) return spriteOffset+8;
   if(!obj.step) return spriteOffset+9;
  } else {
   return spriteOffset+7;
  }
  break;
 case 4:
  if(obj.animCycle > 16/2) {
   if(obj.step) return spriteOffset+5;
   if(!obj.step) return spriteOffset+6;
  } else {
   return spriteOffset+4;
  }
  break;
 }
 return 1;
}

variable_types: spriteOffset int

variable_types: struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; }

return_type: int


decompiled_code:
__int64 __fastcall pk_faceChar(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, int a10, int a11, __int64 a12)
{
__int64 result; // rax

result = 2LL;
if ( (int)a7 <= (int)a12 )
{
result = 1LL;
if ( (int)a7 >= (int)a12 )
{
result = 4LL;
if ( SHIDWORD(a7) <= SHIDWORD(a12) )
result = 3LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, int a10, int a11, __int64 a12)
{
__int64 result; // rax

result = 2LL;
if ( (int)a7 <= (int)a12 )
{
result = 1LL;
if ( (int)a7 >= (int)a12 )
{
result = 4LL;
if ( SHIDWORD(a7) <= SHIDWORD(a12) )
result = 3LL;
}
}
return result;
}

original_code:
int pk_faceChar(charMover_t p, charMover_t t) {
 if(p.x > t.x) {
  return 2;
 } else if(p.x < t.x) {
  return 1;
 } else if(p.y > t.y) {
  return 4;
 } else if(p.y < t.y) {
  return 3;
 }
}

canonical_original_code:
int pk_faceChar(struct charMover_t p, struct charMover_t t) {
 if(p.x > t.x) {
  return 2;
 } else if(p.x < t.x) {
  return 1;
 } else if(p.y > t.y) {
  return 4;
 } else if(p.y < t.y) {
  return 3;
 }
}

variable_types:
t
struct charMover_t

user_defined_types: struct charMover_t { int x; int nextX; int lastX; int animCycle; _Bool step; }


decompiled_code:
bool __fastcall pk_isFinishedMoving(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
bool result; // al

result = 0;
if ( (_DWORD)a7 == (_DWORD)a8 )
result = HIDWORD(a7) == HIDWORD(a8);
return result;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
bool result; // al

result = 0;
if ( (_DWORD)a7 == (_DWORD)a8 )
result = HIDWORD(a7) == HIDWORD(a8);
return result;
}

original_code:
_Bool pk_isFinishedMoving(charMover_t obj) {
 if(obj.x == obj.nextX && obj.y == obj.nextY) {
  return 1;
 }
 return 0;
}

canonical_original_code:
_Bool pk_isFinishedMoving(struct charMover_t obj) {
 if(obj.x == obj.nextX && obj.y == obj.nextY) {
  return 1;
 }
 return 0;
}


original_code:
void pk_moveChar(int dir, _Bool move, charMover_t* obj) {
 if(pk_isFinishedMoving(*obj)) {
  if(dir == 2 && move) {
   obj->nextX = obj->x - 16;
   obj->nextY = obj->y;
  } else if(dir == 1 && move) {
   obj->nextX = obj->x + 16;
   obj->nextY = obj->y;
  } else if(dir == 3 && move) {
   obj->nextX = obj->x;
   obj->nextY = obj->y - 16;
  } else if(dir == 4 && move) {
   obj->nextX = obj->x;
   obj->nextY = obj->y + 16;
  }
  obj->dir = dir;
  if(obj->animCycle == 0) {
   obj->animCycle = 16;
   obj->step = !obj->step;
  }
 }
}

canonical_original_code:
void pk_moveChar(int dir, _Bool move, struct charMover_t *obj) {
 if(pk_isFinishedMoving(*obj)) {
  if(dir == 2 && move) {
   obj->nextX = obj->x - 16;
   obj->nextY = obj->y;
  } else if(dir == 1 && move) {
   obj->nextX = obj->x + 16;
   obj->nextY = obj->y;
  } else if(dir == 3 && move) {
   obj->nextX = obj->x;
   obj->nextY = obj->y - 16;
  } else if(dir == 4 && move) {
   obj->nextX = obj->x;
   obj->nextY = obj->y + 16;
  }
  obj->dir = dir;
  if(obj->animCycle == 0) {
   obj->animCycle = 16;
   obj->step = !obj->step;
  }
 }
}

variable_types: dir int


original_code:
void pk_updateChar(charMover_t* obj) {
 if(obj->x > obj->nextX) {
  obj->x--;
 } else if(obj->x < obj->nextX) {
  obj->x++;
 } else if(obj->y > obj->nextY) {
  obj->y--;
 } else if(obj->y < obj->nextY) {
  obj->y++;
 }
 if(obj->animCycle > 0) {
  obj->animCycle --;
 }
 if(pk_isFinishedMoving(*obj)) {
  obj->lastX = obj->x;
  obj->lastY = obj->y;
 }
}

canonical_original_code:
void pk_updateChar(struct charMover_t *obj) {
 if(obj->x > obj->nextX) {
  obj->x--;
 } else if(obj->x < obj->nextX) {
  obj->x++;
 } else if(obj->y > obj->nextY) {
  obj->y--;
 } else if(obj->y < obj->nextY) {
  obj->y++;
 }
 if(obj->animCycle > 0) {
  obj->animCycle --;
 }
 if(pk_isFinishedMoving(*obj)) {
  obj->lastX = obj->x;
  obj->lastY = obj->y;
 }
}


original_code:
void pk_clearWindow(window_t* window) {
 for(int y=0; y<window->h; y++) {
  for(int x=0; x<window->w; x++) {
   if(x==0 && y==0) {
    window->dispTiles[x+(y*window->w)] = 0 +69;
   } else if(x==window->w-1 && y==0) {
    window->dispTiles[x+(y*window->w)] = 0 +70;
   } else if(x==window->w-1 && y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +71;
   } else if(x==0 && y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +72;
   } else if(x==0 || x==window->w-1) {
    window->dispTiles[x+(y*window->w)] = 0 +74;
   } else if(y==0 || y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +73;
   } else {
    window->dispTiles[x+(y*window->w)] = 0 +62;
   }
  }
 }
}

canonical_original_code:
void pk_clearWindow(struct window_t *window) {
 for(int y = 0; y<window->h; y++) {
  for(int x = 0; x<window->w; x++) {
   if(x==0 && y==0) {
    window->dispTiles[x+(y*window->w)] = 0 +69;
   } else if(x==window->w-1 && y==0) {
    window->dispTiles[x+(y*window->w)] = 0 +70;
   } else if(x==window->w-1 && y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +71;
   } else if(x==0 && y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +72;
   } else if(x==0 || x==window->w-1) {
    window->dispTiles[x+(y*window->w)] = 0 +74;
   } else if(y==0 || y==window->h-1) {
    window->dispTiles[x+(y*window->w)] = 0 +73;
   } else {
    window->dispTiles[x+(y*window->w)] = 0 +62;
   }
  }
 }
}

variable_types: struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; } *

variable_types: y int

variable_types: x int


original_code:
void pk_initWindow(int s_x, int s_y, int s_w, int s_h, _Bool s_closeable, _Bool dispDelay, window_t* window) {
 window->x = s_x;
 window->y = s_y;
 window->w = s_w;
 window->h = s_h;
 window->dispChar = window->startLag = 0;
 window->dispDelay = 3;
 window->optCnt = window->optW = window->optH = 0;
 window->active = window->finished = 0;
 window->closeable = s_closeable;
 window->selection = -1;
 window->scrollNumb = 1;
 pk_clearWindow(window);
}

canonical_original_code:
void pk_initWindow(int s_x, int s_y, int s_w, int s_h, _Bool s_closeable, _Bool dispDelay, struct window_t *window) {
 window->x = s_x;
 window->y = s_y;
 window->w = s_w;
 window->h = s_h;
 window->dispChar = window->startLag = 0;
 window->dispDelay = 3;
 window->optCnt = window->optW = window->optH = 0;
 window->active = window->finished = 0;
 window->closeable = s_closeable;
 window->selection = -1;
 window->scrollNumb = 1;
 pk_clearWindow(window);
}

user_defined_types: struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; }


decompiled_code:
__int64 __fastcall pk_moveSelArrow(int a1, _DWORD *a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx

result = (unsigned int)a2[4];
if ( a1 == 3 )
{
if ( (int)a2[7] > 1 )
{
result = (unsigned int)(result - a2[6]);
a2[4] = result;
}
LABEL_5:
v3 = a2[5];
if ( (int)result >= 0 )
goto LABEL_6;
LABEL_11:
result = (unsigned int)(v3 + result);
a2[4] = result;
return result;
}
if ( a1 != 4 )
{
if ( a1 == 1 )
{
v5 = a2[6];
if ( v5 > 1 )
{
result = (unsigned int)(v5 + result - 1);
a2[4] = result;
}
}
else if ( a1 == 2 )
{
v4 = a2[6];
if ( v4 > 1 )
{
result = (unsigned int)(result - (v4 - 1));
a2[4] = result;
}
}
goto LABEL_5;
}
if ( (int)a2[7] <= 1 )
goto LABEL_5;
result = (unsigned int)(a2[6] + result);
v3 = a2[5];
a2[4] = result;
if ( (int)result < 0 )
goto LABEL_11;
LABEL_6:
if ( v3 <= (int)result )
{
result = (unsigned int)(result - v3);
a2[4] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, _DWORD *a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx

result = (unsigned int)a2[4];
if ( a1 == 3 )
{
if ( (int)a2[7] > 1 )
{
result = (unsigned int)(result - a2[6]);
a2[4] = result;
}
LABEL_5:
v3 = a2[5];
if ( (int)result >= 0 )
goto LABEL_6;
LABEL_11:
result = (unsigned int)(v3 + result);
a2[4] = result;
return result;
}
if ( a1 != 4 )
{
if ( a1 == 1 )
{
v5 = a2[6];
if ( v5 > 1 )
{
result = (unsigned int)(v5 + result - 1);
a2[4] = result;
}
}
else if ( a1 == 2 )
{
v4 = a2[6];
if ( v4 > 1 )
{
result = (unsigned int)(result - (v4 - 1));
a2[4] = result;
}
}
goto LABEL_5;
}
if ( (int)a2[7] <= 1 )
goto LABEL_5;
result = (unsigned int)(a2[6] + result);
v3 = a2[5];
a2[4] = result;
if ( (int)result < 0 )
goto LABEL_11;
LABEL_6:
if ( v3 <= (int)result )
{
result = (unsigned int)(result - v3);
a2[4] = result;
}
return result;
}

original_code:
void pk_moveSelArrow(int dir, window_t* window) {
 if(dir == 3) {
  if(window->optH > 1) {
   window->selOpt -= window->optW;
  }
 } else if(dir == 4) {
  if(window->optH > 1) {
   window->selOpt += window->optW;
  }
 } else if(dir == 1) {
  if(window->optW > 1) {
   window->selOpt += window->optW-1;
  }
 } else if(dir == 2) {
  if(window->optW > 1) {
   window->selOpt -= window->optW-1;
  }
 }
 if(window->selOpt < 0) {
  window->selOpt = window->optCnt + window->selOpt;
 } else if(window->selOpt >= window->optCnt) {
  window->selOpt = window->selOpt - window->optCnt;
 }
}

canonical_original_code:
void pk_moveSelArrow(int dir, struct window_t *window) {
 if(dir == 3) {
  if(window->optH > 1) {
   window->selOpt -= window->optW;
  }
 } else if(dir == 4) {
  if(window->optH > 1) {
   window->selOpt += window->optW;
  }
 } else if(dir == 1) {
  if(window->optW > 1) {
   window->selOpt += window->optW-1;
  }
 } else if(dir == 2) {
  if(window->optW > 1) {
   window->selOpt -= window->optW-1;
  }
 }
 if(window->selOpt < 0) {
  window->selOpt = window->optCnt + window->selOpt;
 } else if(window->selOpt >= window->optCnt) {
  window->selOpt = window->selOpt - window->optCnt;
 }
}


decompiled_code:
__int64 __fastcall pk_isWindowFinished(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15)
{
return BYTE6(a15);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15)
{
return BYTE6(a15);
}

original_code:
_Bool pk_isWindowFinished(window_t window) {
 return window.finished;
}

canonical_original_code:
_Bool pk_isWindowFinished(struct window_t window) {
 return window.finished;
}

variable_types: struct window_t { int x; int selOpt; int strLength; int start; _Bool active; char text[128]; int dispTiles[-1]; }


decompiled_code:
__int64 __fastcall pk_getCharValue(unsigned __int8 a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 65) <= 0x19u )
return (unsigned int)a1 - 65;
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return (unsigned int)a1 - 71;
if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned __int8)(a1 + 4);
switch ( a1 )
{
case ' ':
return 62LL;
case '+':
return 201LL;
case '^':
return 200LL;
case '!':
return 64LL;
case '?':
return 65LL;
case '.':
return 63LL;
case '"':
return 66LL;
case '|':
return 202LL;
case '/':
return 75LL;
}
result = 62LL;
if ( a1 == 123 )
result = 203LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 65) <= 0x19u )
return (unsigned int)a1 - 65;
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return (unsigned int)a1 - 71;
if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned __int8)(a1 + 4);
switch ( a1 )
{
case ' ':
return 62LL;
case '+':
return 201LL;
case '^':
return 200LL;
case '!':
return 64LL;
case '?':
return 65LL;
case '.':
return 63LL;
case '"':
return 66LL;
case '|':
return 202LL;
case '/':
return 75LL;
}
result = 62LL;
if ( a1 == 123 )
result = 203LL;
return result;
}

variable_types: c char


original_code:
void pk_updateWindow(window_t* window) {
 if(window->active) {
  if(window->startLag > 0) {
   window->startLag--;
   return;
  }
  if(window->dispChar < window->stop) {
   if(window->dispDelay <= 0) {
    window->dispChar++;
    window->dispDelay = 1;
   } else {
    window->dispDelay--;
   }
  }
  int x, y;
  x = y = 1;
  int lastOptDraw = 0;
  for(int i=window->start; i<window->dispChar; i++) {
   if(pk_getCharValue(window->text[i]) == 200) {
    x=1;
    y++;
   } else if(pk_getCharValue(window->text[i]) == 201) {
    if(lastOptDraw == window->selOpt) {
     window->dispTiles[x+(y*window->w)] = 0 +68;
    } else {
     window->dispTiles[x+(y*window->w)] = 0 +62;
    }
    x++;
    lastOptDraw++;
   } else {
    window->dispTiles[x+(y*window->w)] = pk_getCharValue(window->text[i]);
    x++;
   }
  }
 } else {
  window->dispDelay = 5;
 }
}

canonical_original_code:
void pk_updateWindow(struct window_t *window) {
 if(window->active) {
  if(window->startLag > 0) {
   window->startLag--;
   return;
  }
  if(window->dispChar < window->stop) {
   if(window->dispDelay <= 0) {
    window->dispChar++;
    window->dispDelay = 1;
   } else {
    window->dispDelay--;
   }
  }
  int x; int y;
  x = y = 1;
  int lastOptDraw = 0;
  for(int i = window->start; i<window->dispChar; i++) {
   if(pk_getCharValue(window->text[i]) == 200) {
    x=1;
    y++;
   } else if(pk_getCharValue(window->text[i]) == 201) {
    if(lastOptDraw == window->selOpt) {
     window->dispTiles[x+(y*window->w)] = 0 +68;
    } else {
     window->dispTiles[x+(y*window->w)] = 0 +62;
    }
    x++;
    lastOptDraw++;
   } else {
    window->dispTiles[x+(y*window->w)] = pk_getCharValue(window->text[i]);
    x++;
   }
  }
 } else {
  window->dispDelay = 5;
 }
}

variable_types: lastOptDraw int


decompiled_code:
__int64 __fastcall pk_fullWindowScroll(int a1, __int64 a2)
{
__int64 i; // rdx
int v4; // esi
__int64 result; // rax
__int64 v6; // rdx
int v7; // ecx
__int64 v8; // rdx
__int64 v9; // rdx

pk_clearWindow((_DWORD *)a2);
for ( i = 1LL; i != 129; i = v6 + 1 )
{
v4 = i;
result = (unsigned int)pk_getCharValue(*(_BYTE *)(a2 + i + 71)) == 203;
if ( (_DWORD)result + v7 == a1 )
{
*(_DWORD *)(a2 + 52) = v6;
goto LABEL_5;
}
}
v4 = *(_DWORD *)(a2 + 52);
LABEL_5:
if ( v4 <= 127 )
{
v8 = v4;
while ( 1 )
{
result = (unsigned int)pk_getCharValue(*(_BYTE *)(a2 + v8 + 72)) - 202;
if ( (unsigned int)result <= 1 )
break;
v8 = v9 + 1;
if ( (int)v8 > 127 )
goto LABEL_10;
}
*(_DWORD *)(a2 + 56) = v9;
}
LABEL_10:
if ( !*(_BYTE *)(a2 + 69) )
v4 = *(_DWORD *)(a2 + 56);
*(_DWORD *)(a2 + 36) = v4;
return result;
}

original_code:
void pk_fullWindowScroll(int scrollCnt, window_t* window) {
 pk_clearWindow(window);
 int cnt = 0;
 for(int i=0; i<128; i++) {
  if(pk_getCharValue(window->text[i]) == 203) {
   cnt++;
  }
  if(cnt == scrollCnt) {
   window->start = i+1;
   break;
  }
 }
 for(int i=window->start; i<128; i++) {
  if(pk_getCharValue(window->text[i]) == 203 || pk_getCharValue(window->text[i]) == 202) {
   window->stop = i;
   break;
  }
 }
 if(window->txtScroll) {
  window->dispChar = window->start;
 } else {
  window->dispChar = window->stop;
 }
}

canonical_original_code:
void pk_fullWindowScroll(int scrollCnt, struct window_t *window) {
 pk_clearWindow(window);
 int cnt = 0;
 for(int i = 0; i<128; i++) {
  if(pk_getCharValue(window->text[i]) == 203) {
   cnt++;
  }
  if(cnt == scrollCnt) {
   window->start = i+1;
   break;
  }
 }
 for(int i = window->start; i<128; i++) {
  if(pk_getCharValue(window->text[i]) == 203 || pk_getCharValue(window->text[i]) == 202) {
   window->stop = i;
   break;
  }
 }
 if(window->txtScroll) {
  window->dispChar = window->start;
 } else {
  window->dispChar = window->stop;
 }
}

variable_types: scrollCnt int

variable_types: cnt int


decompiled_code:
__int64 __fastcall pk_toggleWindow(__int64 a1)
{
__int64 result; // rax
bool v2; // zf

result = *(unsigned int *)(a1 + 44);
if ( (int)result <= 0 )
{
v2 = *(_BYTE *)(a1 + 68) == 1;
*(_BYTE *)(a1 + 68) ^= 1u;
if ( !v2 )
{
pk_clearWindow((_DWORD *)a1);
*(_BYTE *)(a1 + 70) = 0;
*(_DWORD *)(a1 + 44) = 10;
*(_DWORD *)(a1 + 60) = 1;
result = pk_fullWindowScroll(1, a1);
if ( *(_BYTE *)(a1 + 69) )
*(_DWORD *)(a1 + 36) = 0;
}
}
return result;
}

original_code:
void pk_toggleWindow(window_t* window) {
 if(window->startLag <= 0) {
  window->active = !window->active;
  if(window->active) {
   pk_clearWindow(window);
   window->finished = 0;
   window->startLag = 10;
   window->scrollNumb = 1;
   pk_fullWindowScroll(1, window);
   if(window->txtScroll) {
    window->dispChar = 0;
   }
  }
 }
}

canonical_original_code:
void pk_toggleWindow(struct window_t *window) {
 if(window->startLag <= 0) {
  window->active = !window->active;
  if(window->active) {
   pk_clearWindow(window);
   window->finished = 0;
   window->startLag = 10;
   window->scrollNumb = 1;
   pk_fullWindowScroll(1, window);
   if(window->txtScroll) {
    window->dispChar = 0;
   }
  }
 }
}


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

result = *(unsigned int *)(a1 + 32);
if ( *(_DWORD *)(a1 + 36) >= (int)result )
{
if ( *(_BYTE *)(a1 + 71) )
{
result = pk_toggleWindow(a1);
*(_DWORD *)(a1 + 48) = 255;
}
}
return result;
}

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

result = *(unsigned int *)(a1 + 32);
if ( *(_DWORD *)(a1 + 36) >= (int)result )
{
if ( *(_BYTE *)(a1 + 71) )
{
result = func7(a1);
*(_DWORD *)(a1 + 48) = 255;
}
}
return result;
}

original_code:
void pk_scrollWindowText(window_t* window) {
 if(window->dispChar < window->strLength) {
 } else if(window->closeable) {
  pk_toggleWindow(window);
  window->selection = 255;
 }
}

canonical_original_code:
void pk_scrollWindowText(struct window_t *window) {
 if(window->dispChar < window->strLength) {
 } else if(window->closeable) {
  pk_toggleWindow(window);
  window->selection = 255;
 }
}


decompiled_code:
__int64 __fastcall pk_selectWindow(__int64 a1)
{
__int64 result; // rax
int v2; // edx
bool v3; // zf

result = *(unsigned int *)(a1 + 36);
if ( (int)result < *(_DWORD *)(a1 + 32) )
goto LABEL_5;
v2 = *(_DWORD *)(a1 + 20);
if ( v2 > 0 )
{
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 48) = result;
return result;
}
if ( v2 )
{
LABEL_5:
if ( (int)result >= *(_DWORD *)(a1 + 56) )
{
result = *(unsigned int *)(a1 + 60);
if ( (int)result < *(_DWORD *)(a1 + 64) )
{
*(_DWORD *)(a1 + 60) = result + 1;
result = pk_fullWindowScroll((int)result + 1, a1);
}
}
}
else
{
v3 = *(_BYTE *)(a1 + 71) == 0;
*(_BYTE *)(a1 + 70) = 1;
if ( !v3 )
*(_BYTE *)(a1 + 68) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
int v2; // edx
bool v3; // zf

result = *(unsigned int *)(a1 + 36);
if ( (int)result < *(_DWORD *)(a1 + 32) )
goto LABEL_5;
v2 = *(_DWORD *)(a1 + 20);
if ( v2 > 0 )
{
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 48) = result;
return result;
}
if ( v2 )
{
LABEL_5:
if ( (int)result >= *(_DWORD *)(a1 + 56) )
{
result = *(unsigned int *)(a1 + 60);
if ( (int)result < *(_DWORD *)(a1 + 64) )
{
*(_DWORD *)(a1 + 60) = result + 1;
result = func6((int)result + 1, a1);
}
}
}
else
{
v3 = *(_BYTE *)(a1 + 71) == 0;
*(_BYTE *)(a1 + 70) = 1;
if ( !v3 )
*(_BYTE *)(a1 + 68) = 0;
}
return result;
}

original_code:
void pk_selectWindow(window_t* window) {
 if(window->dispChar >= window->strLength && window->optCnt > 0) {
  window->selection = window->selOpt;
 } else if(window->dispChar >= window->strLength && window->optCnt == 0) {
  window->finished = 1;
  if(window->closeable) {
   window->active = 0;
  }
 } else if(window->dispChar >= window->stop && window->scrollNumb < window->scrollCnt) {
  window->scrollNumb++;
  pk_fullWindowScroll(window->scrollNumb, window);
 }
}

canonical_original_code:
void pk_selectWindow(struct window_t *window) {
 if(window->dispChar >= window->strLength && window->optCnt > 0) {
  window->selection = window->selOpt;
 } else if(window->dispChar >= window->strLength && window->optCnt == 0) {
  window->finished = 1;
  if(window->closeable) {
   window->active = 0;
  }
 } else if(window->dispChar >= window->stop && window->scrollNumb < window->scrollCnt) {
  window->scrollNumb++;
  pk_fullWindowScroll(window->scrollNumb, window);
 }
}


original_code:
void pk_setWindowText(char* s_text, _Bool s_txtScroll, window_t* window) {
 pk_clearWindow(window);
 window->txtScroll = s_txtScroll;
 window->optCnt = 0;
 window->optW = window->optH = 0;
 window->scrollCnt = 0;
 window->scrollNumb = 1;
 int inc = 0;
 _Bool settingWidth = 1;
 while(pk_getCharValue(s_text[inc]) != 202) {
  window->text[inc] = s_text[inc];
  if(pk_getCharValue(s_text[inc]) == 200 && window->optCnt != 0) {
   settingWidth = 0;
   window->optH++;
  }
  if(pk_getCharValue(s_text[inc]) == 201) {
   window->optCnt++;
   if(settingWidth) {
    window->optW++;
   }
  }
  if(pk_getCharValue(s_text[inc]) == 203) {
   window->scrollCnt++;
  }
  inc++;
 }
 window->text[inc] = '|';
 if(window->txtScroll) {
  window->dispChar = 0;
 } else {
  window->dispChar = inc;
 }
 window->strLength = inc;
 window->finished = 0;
 pk_fullWindowScroll(window->scrollNumb, window);
}

canonical_original_code:
void pk_setWindowText(char *s_text, _Bool s_txtScroll, struct window_t *window) {
 pk_clearWindow(window);
 window->txtScroll = s_txtScroll;
 window->optCnt = 0;
 window->optW = window->optH = 0;
 window->scrollCnt = 0;
 window->scrollNumb = 1;
 int inc = 0;
 _Bool settingWidth = 1;
 while(pk_getCharValue(s_text[inc]) != 202) {
  window->text[inc] = s_text[inc];
  if(pk_getCharValue(s_text[inc]) == 200 && window->optCnt != 0) {
   settingWidth = 0;
   window->optH++;
  }
  if(pk_getCharValue(s_text[inc]) == 201) {
   window->optCnt++;
   if(settingWidth) {
    window->optW++;
   }
  }
  if(pk_getCharValue(s_text[inc]) == 203) {
   window->scrollCnt++;
  }
  inc++;
 }
 window->text[inc] = '|';
 if(window->txtScroll) {
  window->dispChar = 0;
 } else {
  window->dispChar = inc;
 }
 window->strLength = inc;
 window->finished = 0;
 pk_fullWindowScroll(window->scrollNumb, window);
}

variable_types: inc int


decompiled_code:
__int64 __fastcall pk_setInsWindowText(unsigned __int8 *a1, const void *a2, int a3, int a4, char a5, __int64 a6)
{
unsigned __int8 *v9; // r13
unsigned __int8 *i; // r12
unsigned __int8 v11; // di
unsigned __int8 v12; // dl

v9 = (unsigned __int8 *)malloc(0x80uLL);
for ( i = v9; ; ++i )
{
v11 = *a1++;
if ( (unsigned int)pk_getCharValue(v11) == 202 )
break;
*i = v12;
}
if ( a4 > 0 )
memcpy(&v9[a3], a2, a4);
*i = 124;
return pk_setWindowText(v9, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1, const void *a2, int a3, int a4, char a5, __int64 a6)
{
unsigned __int8 *v9; // r13
unsigned __int8 *i; // r12
unsigned __int8 v11; // di
unsigned __int8 v12; // dl

v9 = (unsigned __int8 *)malloc(0x80uLL);
for ( i = v9; ; ++i )
{
v11 = *a1++;
if ( (unsigned int)func4(v11) == 202 )
break;
*i = v12;
}
if ( a4 > 0 )
memcpy(&v9[a3], a2, a4);
*i = 124;
return func10(v9, a5, a6);
}

original_code:
void pk_setInsWindowText(char* baseText, char* insText, int insStart, int insLen, _Bool txtScroll, window_t* window) {
 char* text = (char*)malloc(128*sizeof(char));
 int inc = 0;
 while(pk_getCharValue(baseText[inc]) != 202) {
  text[inc] = baseText[inc];
  inc++;
 }
 for(int i=0; i<insLen; i++) {
  text[insStart+i] = insText[i];
 }
 text[inc] = '|';
 pk_setWindowText(text, txtScroll, window);
}

canonical_original_code:
void pk_setInsWindowText(char *baseText, char *insText, int insStart, int insLen, _Bool txtScroll, struct window_t *window) {
 char *text = (char*)malloc(128*sizeof(char));
 int inc = 0;
 while(pk_getCharValue(baseText[inc]) != 202) {
  text[inc] = baseText[inc];
  inc++;
 }
 for(int i = 0; i<insLen; i++) {
  text[insStart+i] = insText[i];
 }
 text[inc] = '|';
 pk_setWindowText(text, txtScroll, window);
}

variable_types:
baseText
char *

variable_types:
insText
char *

variable_types: insStart int

variable_types: insLen int

variable_types:
text
char *


original_code:
void pk_updateNpc(npc_t* npc, col_t col) {
 if(npc->mover.animCycle > 16) {
  npc->mover.animCycle = 0;
 }
 switch(npc->aiType) {
 case 1:
  if(npc->actClock <= 0 && !npc->pause) {
   if(npc->mover.dir == 2) {
    npc->mover.dir = 3;
   } else if(npc->mover.dir == 3) {
    npc->mover.dir = 1;
   } else if(npc->mover.dir == 1) {
    npc->mover.dir = 4;
   } else if(npc->mover.dir == 4) {
    npc->mover.dir = 2;
   }
   npc->actClock = 50;
  } else if (!npc->pause) {
   npc->actClock--;
  }
  break;
 case 3:
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   if(npc->mover.x < npc->destX[npc->dest]) {
    pk_moveChar(1, col.right, &npc->mover);
   } else if(npc->mover.x > npc->destX[npc->dest]) {
    pk_moveChar(2, col.left, &npc->mover);
   }
   if(npc->mover.y < npc->destY[npc->dest]) {
    pk_moveChar(3, col.up, &npc->mover);
   } else if(npc->mover.y > npc->destY[npc->dest]) {
    pk_moveChar(4, col.down, &npc->mover);
   }
  }
  pk_updateChar(&npc->mover);
  if(npc->mover.x == npc->destX[npc->dest] && npc->mover.y == npc->destY[npc->dest]) {
   if(npc->dest == 0) {
    npc->dest = 1;
   } else {
    npc->dest = 0;
   }
  }
  break;
 case 4:
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   int randDir = rand() % 150 + 1;
   switch(randDir) {
    case 2:
     pk_moveChar(2, col.left, &npc->mover);
     break;
    case 1:
     pk_moveChar(1, col.right, &npc->mover);
     break;
    case 4:
     pk_moveChar(4, col.down, &npc->mover);
     break;
    case 3:
     pk_moveChar(3, col.up, &npc->mover);
     break;
   }
  }
  pk_updateChar(&npc->mover);
  break;
 case 5:
  if(npc->actClock > 0) {
   npc->actClock--;
   break;
  }
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   if(npc->mover.x < npc->destX[npc->dest]) {
    pk_moveChar(1, 1, &npc->mover);
   } else if(npc->mover.x > npc->destX[npc->dest]) {
    pk_moveChar(2, 1, &npc->mover);
   }
   if(npc->mover.y < npc->destY[npc->dest]) {
    pk_moveChar(4, 1, &npc->mover);
   } else if(npc->mover.y > npc->destY[npc->dest]) {
    pk_moveChar(3, 1, &npc->mover);
   }
  }
  pk_updateChar(&npc->mover);
  break;
 }
 pk_updateWindow(&npc->dialog);
}

canonical_original_code:
void pk_updateNpc(struct npc_t *npc, struct col_t col) {
 if(npc->mover.animCycle > 16) {
  npc->mover.animCycle = 0;
 }
 switch(npc->aiType) {
 case 1:
  if(npc->actClock <= 0 && !npc->pause) {
   if(npc->mover.dir == 2) {
    npc->mover.dir = 3;
   } else if(npc->mover.dir == 3) {
    npc->mover.dir = 1;
   } else if(npc->mover.dir == 1) {
    npc->mover.dir = 4;
   } else if(npc->mover.dir == 4) {
    npc->mover.dir = 2;
   }
   npc->actClock = 50;
  } else if (!npc->pause) {
   npc->actClock--;
  }
  break;
 case 3:
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   if(npc->mover.x < npc->destX[npc->dest]) {
    pk_moveChar(1, col.right, &npc->mover);
   } else if(npc->mover.x > npc->destX[npc->dest]) {
    pk_moveChar(2, col.left, &npc->mover);
   }
   if(npc->mover.y < npc->destY[npc->dest]) {
    pk_moveChar(3, col.up, &npc->mover);
   } else if(npc->mover.y > npc->destY[npc->dest]) {
    pk_moveChar(4, col.down, &npc->mover);
   }
  }
  pk_updateChar(&npc->mover);
  if(npc->mover.x == npc->destX[npc->dest] && npc->mover.y == npc->destY[npc->dest]) {
   if(npc->dest == 0) {
    npc->dest = 1;
   } else {
    npc->dest = 0;
   }
  }
  break;
 case 4:
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   int randDir = rand() % 150 + 1;
   switch(randDir) {
    case 2:
     pk_moveChar(2, col.left, &npc->mover);
     break;
    case 1:
     pk_moveChar(1, col.right, &npc->mover);
     break;
    case 4:
     pk_moveChar(4, col.down, &npc->mover);
     break;
    case 3:
     pk_moveChar(3, col.up, &npc->mover);
     break;
   }
  }
  pk_updateChar(&npc->mover);
  break;
 case 5:
  if(npc->actClock > 0) {
   npc->actClock--;
   break;
  }
  if(pk_isFinishedMoving(npc->mover) && !npc->pause) {
   if(npc->mover.x < npc->destX[npc->dest]) {
    pk_moveChar(1, 1, &npc->mover);
   } else if(npc->mover.x > npc->destX[npc->dest]) {
    pk_moveChar(2, 1, &npc->mover);
   }
   if(npc->mover.y < npc->destY[npc->dest]) {
    pk_moveChar(4, 1, &npc->mover);
   } else if(npc->mover.y > npc->destY[npc->dest]) {
    pk_moveChar(3, 1, &npc->mover);
   }
  }
  pk_updateChar(&npc->mover);
  break;
 }
 pk_updateWindow(&npc->dialog);
}

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

variable_types:
col
struct col_t { _Bool left; }

variable_types: randDir int

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_setNpcWindow(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 v7; // rcx
__int64 v8; // rdi
unsigned __int64 result; // rax

v7 = a1 + 948;
v8 = a1 + 956;
*(_QWORD *)(v8 - 8) = a7;
result = STACK[0xCC8];
*(_QWORD *)(v8 + 3256) = STACK[0xCC8];
qmemcpy(
(void *)(v8 & 0xFFFFFFFFFFFFFFF8LL),
(char *)&a7 - (v7 - (v8 & 0xFFFFFFFFFFFFFFF8LL)),
8 * ((unsigned __int64)((unsigned int)v7 - (v8 & 0xFFFFFFF8) + 3272) >> 3));
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 v7; // rcx
__int64 v8; // rdi
unsigned __int64 result; // rax

v7 = a1 + 948;
v8 = a1 + 956;
*(_QWORD *)(v8 - 8) = a7;
result = STACK[0xCC8];
*(_QWORD *)(v8 + 3256) = STACK[0xCC8];
qmemcpy(
(void *)(v8 & 0xFFFFFFFFFFFFFFF8LL),
(char *)&a7 - (v7 - (v8 & 0xFFFFFFFFFFFFFFF8LL)),
8 * ((unsigned __int64)((unsigned int)v7 - (v8 & 0xFFFFFFF8) + 3272) >> 3));
return result;
}

original_code:
void pk_setNpcWindow(window_t s_wind, npc_t* trainer) {
 trainer->dialog = s_wind;
}

canonical_original_code:
void pk_setNpcWindow(struct window_t s_wind, struct npc_t *trainer) {
 trainer->dialog = s_wind;
}

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 dialog; char msg1[128]; char msg2[128]; char msg3[128]; } *


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

switch ( a1 )
{
case 2:
return pk_setWindowText(a2 + 4348, 1LL, a2 + 948);
case 3:
return pk_setWindowText(a2 + 4476, 1LL, a2 + 948);
case 1:
result = pk_setWindowText(a2 + 4220, 1LL, a2 + 948);
break;
}
return result;
}

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

switch ( a1 )
{
case 2:
return pk_setWindowText(a2 + 4348, 1LL, a2 + 948);
case 3:
return pk_setWindowText(a2 + 4476, 1LL, a2 + 948);
case 1:
result = pk_setWindowText(a2 + 4220, 1LL, a2 + 948);
break;
}
return result;
}

original_code:
void pk_switchMessage(int val, npc_t* trainer) {
 switch(val) {
 case 1:
  pk_setWindowText(&trainer->msg1[0], 1, &trainer->dialog);
  break;
 case 2:
  pk_setWindowText(&trainer->msg2[0], 1, &trainer->dialog);
  break;
 case 3:
  pk_setWindowText(&trainer->msg3[0], 1, &trainer->dialog);
  break;
 }
}

canonical_original_code:
void pk_switchMessage(int val, struct npc_t *trainer) {
 switch(val) {
 case 1:
  pk_setWindowText(&trainer->msg1[0], 1, &trainer->dialog);
  break;
 case 2:
  pk_setWindowText(&trainer->msg2[0], 1, &trainer->dialog);
  break;
 case 3:
  pk_setWindowText(&trainer->msg3[0], 1, &trainer->dialog);
  break;
 }
}

variable_types: val 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:
void pk_setNpcMonster(monster_t mon, npc_t* trainer) {
 if(trainer->monCnt > 5) {
  printf("[ERROR] Max monster count reached on NPC!\n");
  return;
 }
 trainer->monsters[trainer->monCnt] = mon;
 trainer->monCnt++;
}

canonical_original_code:
void pk_setNpcMonster(struct monster_t mon, struct npc_t *trainer) {
 if(trainer->monCnt > 5) {
  printf("[ERROR] Max monster count reached on NPC!\n");
  return;
 }
 trainer->monsters[trainer->monCnt] = mon;
 trainer->monCnt++;
}

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: struct npc_t { int destX[2]; int destY[2]; int reach; _Bool fought; struct monster_t 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]; } *


decompiled_code:
__int64 __fastcall pk_getNpcFrame(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, __int64 a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, int a24, int a25, int a26, int a27, int a28, int a29, int a30, int a31, int a32, int a33, int a34, int a35, int a36, int a37, int a38, int a39, int a40, int a41, int a42, int a43, int a44, int a45, int a46, int a47, int a48, int a49, int a50, int a51, int a52, int a53, int a54, int a55, int a56, int a57, int a58, int a59, int a60, int a61, int a62, int a63)
{
return pk_getCharFrame(HIDWORD(a8));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, __int64 a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, int a24, int a25, int a26, int a27, int a28, int a29, int a30, int a31, int a32, int a33, int a34, int a35, int a36, int a37, int a38, int a39, int a40, int a41, int a42, int a43, int a44, int a45, int a46, int a47, int a48, int a49, int a50, int a51, int a52, int a53, int a54, int a55, int a56, int a57, int a58, int a59, int a60, int a61, int a62, int a63)
{
return pk_getCharFrame(HIDWORD(a8));
}

original_code:
int pk_getNpcFrame(npc_t npc) {
 return pk_getCharFrame(npc.sprite, npc.mover);
}

canonical_original_code:
int pk_getNpcFrame(struct npc_t npc) {
 return pk_getCharFrame(npc.sprite, npc.mover);
}

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


decompiled_code:
void __fastcall pk_toggleNpcPause(__int64 a1)
{
*(_BYTE *)(a1 + 46) ^= 1u;
}

original_code:
void pk_toggleNpcPause(npc_t* npc) {
 npc->pause = !npc->pause;
}

canonical_original_code:
void pk_toggleNpcPause(struct npc_t *npc) {
 npc->pause = !npc->pause;
}


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


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

*(_BYTE *)(a3 + 47) = 1;
*(_QWORD *)(a3 + 24) = 0x1E00000005LL;
result = *(unsigned int *)(a3 + 940);
*(_BYTE *)(a3 + 44) = 1;
*(_DWORD *)(a3 + 32) = 0;
switch ( (_DWORD)result )
{
case 2:
result = *(unsigned int *)(a3 + 912);
if ( (int)result > a1 && *(_DWORD *)(a3 + 916) == a2 )
{
result = (unsigned int)(((int)result - a1) >> 4);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)(a3 + 8) = a2;
*(_DWORD *)a3 = a1 + 16;
}
}
break;
case 1:
result = *(unsigned int *)(a3 + 912);
if ( (int)result < a1 && *(_DWORD *)(a3 + 916) == a2 )
{
result = (unsigned int)((a1 - (int)result) >> 4);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)(a3 + 8) = a2;
*(_DWORD *)a3 = a1 - 16;
}
}
break;
case 3:
if ( *(_DWORD *)(a3 + 912) == a1 )
{
result = *(unsigned int *)(a3 + 916);
if ( (int)result < a2 )
{
result = (unsigned int)((a2 - (int)result) >> 4);
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)result - a2) >> 4);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)a3 = a1;
*(_DWORD *)(a3 + 8) = a2 + 16;
}
}
}
break;
}
return result;
}

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

*(_BYTE *)(a3 + 47) = 1;
*(_QWORD *)(a3 + 24) = 0x1E00000005LL;
result = *(unsigned int *)(a3 + 940);
*(_BYTE *)(a3 + 44) = 1;
*(_DWORD *)(a3 + 32) = 0;
switch ( (_DWORD)result )
{
case 2:
result = *(unsigned int *)(a3 + 912);
if ( (int)result > a1 && *(_DWORD *)(a3 + 916) == a2 )
{
result = (unsigned int)(((int)result - a1) >> 4);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)(a3 + 8) = a2;
*(_DWORD *)a3 = a1 + 16;
}
}
break;
case 1:
result = *(unsigned int *)(a3 + 912);
if ( (int)result < a1 && *(_DWORD *)(a3 + 916) == a2 )
{
result = (unsigned int)((a1 - (int)result) >> 4);
if ( (int)result <= *(_DWORD *)(a3 + 16) )
{
*(_DWORD *)(a3 + 8) = a2;
*(_DWORD *)a3 = a1 - 16;
}
}
break;
case 3:
if ( *(_DWORD *)(a3 + 912) == a1 )
{
result = *(unsigned int *)(a3 + 916);
if ( (int)result < a2 )
{
result = (unsigned int)((a2 - (int)result) >> 4);
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)result - a2) >> 4);
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


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

result = HIDWORD(a1);
if ( (_DWORD)a1 == 1 )
{
if ( HIDWORD(a1) == 1 )
{
result = 0LL;
v6 = *(_DWORD *)(a4 + 60) + a2 / -5;
if ( v6 < 0 )
v6 = 0;
*(_DWORD *)(a4 + 60) = v6;
}
else if ( HIDWORD(a1) == 2 )
{
result = 0LL;
v5 = *(_DWORD *)(a3 + 60) + a2 / -5;
if ( v5 < 0 )
v5 = 0;
*(_DWORD *)(a3 + 60) = v5;
}
}
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, int a2, __int64 a3, __int64 a4)
{
unsigned __int64 result; // rax
int v5; // esi
int v6; // esi

result = HIDWORD(a1);
if ( (_DWORD)a1 == 1 )
{
if ( HIDWORD(a1) == 1 )
{
result = 0LL;
v6 = *(_DWORD *)(a4 + 60) + a2 / -5;
if ( v6 < 0 )
v6 = 0;
*(_DWORD *)(a4 + 60) = v6;
}
else if ( HIDWORD(a1) == 2 )
{
result = 0LL;
v5 = *(_DWORD *)(a3 + 60) + a2 / -5;
if ( v5 < 0 )
v5 = 0;
*(_DWORD *)(a3 + 60) = v5;
}
}
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


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 func8(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 )
func8("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


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 )
func8("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; // ebx
int v1; // edx
__int64 v2; // rcx
__int64 *v3; // rax
__int64 v4; // rdx
__int64 v5; // rdx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebx
int v1; // edx
__int64 v2; // rcx
__int64 *v3; // rax
__int64 v4; // rdx
__int64 v5; // rdx
__int64 result; // rax

v0 = lastnum_0;
do
v1 = rand() % numread;
while ( v1 == v0 );
v2 = tweenskel;
lastnum_0 = v1;
v3 = (__int64 *)(skellist + 8LL * v1);
fromskel[0] = tweenskel;
v4 = *v3;
fromskel[1] = tweenskel;
toskel = v4;
v5 = *v3;
fromskel[2] = v2;
*(&toskel + 1) = v5;
result = *v3;
*(&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; // r14
char *v4; // r13
XGCValues v5; // [rsp+0h] [rbp-A8h] BYREF

if ( argc > 1 )
{
v3 = argv[1];
if ( argc == 2 )
{
steps = 10;
v4 = 0LL;
}
else
{
v4 = 0LL;
steps = atoi(argv[2]);
if ( argc == 4 )
v4 = (char *)argv[3];
}
tweenskel[0] = (__int64)&tween;
tweenskel[1] = (__int64)&tween + 368;
tweenskel[2] = (__int64)&tween + 736;
Initialize((unsigned int)argc, argv);
XSelectInput(dpy, win, 32773LL);
v5.function = 0;
*(_QWORD *)&v5.line_width = 0LL;
set_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v5);
*(_QWORD *)&v5.line_width = 0LL;
v5.function = 15;
unset_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v5);
*(_QWORD *)&v5.line_width = 0LL;
v5.function = 5;
noop_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v5);
*(_QWORD *)&v5.line_width = 0LL;
v5.function = 10;
neg_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v5);
skellist = (__int64)ReadFile(v3);
if ( v4 )
v4 = ReadRoutineFile(v4);
DanceMainLoop((int *)v4);
}
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; // r14
char *v4; // r13
XGCValues v5; // [rsp+0h] [rbp-A8h] BYREF

if ( argc > 1 )
{
v3 = argv[1];
if ( argc == 2 )
{
steps = 10;
v4 = 0LL;
}
else
{
v4 = 0LL;
steps = atoi(argv[2]);
if ( argc == 4 )
v4 = (char *)argv[3];
}
tweenskel[0] = (__int64)&tween;
tweenskel[1] = (__int64)&tween + 368;
tweenskel[2] = (__int64)&tween + 736;
Initialize((unsigned int)argc, argv);
XSelectInput(dpy, win, 32773LL);
v5.function = 0;
*(_QWORD *)&v5.line_width = 0LL;
set_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v5);
*(_QWORD *)&v5.line_width = 0LL;
v5.function = 15;
unset_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v5);
*(_QWORD *)&v5.line_width = 0LL;
v5.function = 5;
noop_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v5);
*(_QWORD *)&v5.line_width = 0LL;
v5.function = 10;
neg_gc = (__int64)XCreateGC(dpy, win, 0x31uLL, &v5);
skellist = (__int64)ReadFile(v3);
if ( v4 )
v4 = func5(v4);
func8((int *)v4);
}
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:
__int64 DrawGrid()
{
_XGC **v0; // rbp
int i; // ebx
_XGC *v2; // rdx
int v3; // er8
__int64 result; // rax
int v5; // [rsp+0h] [rbp-28h]
__int64 v6; // [rsp+0h] [rbp-28h]

v0 = (_XGC **)gc_list;
for ( i = 0; i != 160; i += 10 )
{
v2 = *v0++;
XDrawLine(dpy, win, v2, i, 0, i, 400);
v5 = i;
v3 = i;
XDrawLine(dpy, win, *(v0 - 1), 0, v3, 400, v5);
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
_XGC **v0; // rbp
int i; // ebx
_XGC *v2; // rdx
int v3; // er8
__int64 result; // rax
int v5; // [rsp+0h] [rbp-28h]
__int64 v6; // [rsp+0h] [rbp-28h]

v0 = (_XGC **)gc_list;
for ( i = 0; i != 160; i += 10 )
{
v2 = *v0++;
XDrawLine(dpy, win, v2, i, 0, i, 400);
v5 = i;
v3 = i;
XDrawLine(dpy, win, *(v0 - 1), 0, v3, 400, v5);
result = v6;
}
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.flags = 8LL;
*(_QWORD *)&v7.width = 0x19000000190LL;
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.flags = 8LL;
*(_QWORD *)&v7.width = 0x19000000190LL;
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(__int64 a1)
{
char *v1; // rdi
const char *v2; // r12
const char *v3; // rdx
char v4; // al
char *v5; // rdx
int v6; // ebx
char *v7; // rax
char *result; // rax
char *v9; // rcx

v1 = (char *)(a1 + 1);
v2 = 0LL;
v3 = v1 - 1;
v4 = *(v1 - 1);
if ( v4 == 32 )
goto LABEL_7;
LABEL_2:
if ( v4 <= 32 )
{
while ( v4 )
{
LABEL_4:
if ( !v2 )
v2 = v3;
v4 = *v1++;
v3 = v1 - 1;
if ( v4 != 32 )
goto LABEL_2;
LABEL_7:
if ( v2 )
{
v5 = v1 - 2;
goto LABEL_9;
}
while ( 1 )
{
v9 = v1;
v4 = *v1++;
v3 = v9;
if ( v4 != 32 )
break;
v4 = v9[1];
v1 = v9 + 2;
v3 = v9 + 1;
if ( v4 != 32 )
goto LABEL_2;
}
if ( v4 > 32 )
goto LABEL_3;
}
}
else
{
LABEL_3:
if ( (v4 & 0xFD) != 60 )
goto LABEL_4;
}
v5 = (char *)(v3 - 1);
if ( !v2 )
return 0LL;
LABEL_9:
v6 = (_DWORD)v5 - (_DWORD)v2 + 1;
v7 = (char *)malloc(v5 - v2 + 2);
result = strncpy(v7, v2, v6);
result[v6] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1)
{
char *v1; // rdi
const char *v2; // r12
const char *v3; // rdx
char v4; // al
char *v5; // rdx
int v6; // ebx
char *v7; // rax
char *result; // rax
char *v9; // rcx

v1 = (char *)(a1 + 1);
v2 = 0LL;
v3 = v1 - 1;
v4 = *(v1 - 1);
if ( v4 == 32 )
goto LABEL_7;
LABEL_2:
if ( v4 <= 32 )
{
while ( v4 )
{
LABEL_4:
if ( !v2 )
v2 = v3;
v4 = *v1++;
v3 = v1 - 1;
if ( v4 != 32 )
goto LABEL_2;
LABEL_7:
if ( v2 )
{
v5 = v1 - 2;
goto LABEL_9;
}
while ( 1 )
{
v9 = v1;
v4 = *v1++;
v3 = v9;
if ( v4 != 32 )
break;
v4 = v9[1];
v1 = v9 + 2;
v3 = v9 + 1;
if ( v4 != 32 )
goto LABEL_2;
}
if ( v4 > 32 )
goto LABEL_3;
}
}
else
{
LABEL_3:
if ( (v4 & 0xFD) != 60 )
goto LABEL_4;
}
v5 = (char *)(v3 - 1);
if ( !v2 )
return 0LL;
LABEL_9:
v6 = (_DWORD)v5 - (_DWORD)v2 + 1;
v7 = (char *)malloc(v5 - v2 + 2);
result = strncpy(v7, v2, v6);
result[v6] = 0;
return result;
}

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(char *s, __int64 a2)
{
void *v3; // rdi
char *result; // rax
char *v5; // rbx
void *v6; // rdi

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

canonical_decompiled_code:
char *__fastcall func2(char *s, __int64 a2)
{
void *v3; // rdi
char *result; // rax
char *v5; // rbx
void *v6; // rdi

while ( 1 )
{
result = strpbrk(s, "<>");
v5 = result;
if ( !result )
break;
if ( *result == 60 )
{
v6 = *(void **)(a2 + 2056);
if ( v6 )
free(v6);
s = v5 + 1;
*(_QWORD *)(a2 + 2056) = func1((__int64)(v5 + 1));
}
else
{
v3 = *(void **)(a2 + 2064);
if ( v3 )
free(v3);
s = v5 + 1;
*(_QWORD *)(a2 + 2064) = func1((__int64)(v5 + 1));
}
*v5 = 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:
void *__fastcall strClone(void *src)
{
size_t v1; // r12
void *v2; // rax

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

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

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

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
__int64 v2; // rbx

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

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

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

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, void *a3)
{
void *v5; // rdi

if ( *(_DWORD *)(a1 + 2048) <= a2 )
return 0LL;
v5 = *(void **)(a1 + 8LL * a2);
if ( v5 )
free(v5);
*(_QWORD *)(a1 + 8LL * a2) = strClone(a3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, void *a3)
{
void *v5; // rdi

if ( *(_DWORD *)(a1 + 2048) <= a2 )
return 0LL;
v5 = *(void **)(a1 + 8LL * a2);
if ( v5 )
free(v5);
*(_QWORD *)(a1 + 8LL * a2) = func3(a3);
return 1LL;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = (_QWORD *)*a1;
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = (_QWORD *)*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

if ( ptr )
{
v1 = (void **)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

if ( ptr )
{
v1 = (void **)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; // rbp
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; // rbp
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; // ecx
__int64 result; // rax
bool v3; // cc

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

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
int v1; // ecx
__int64 result; // rax
bool v3; // cc

if ( *environ )
{
v0 = 1LL;
do
v1 = v0++;
while ( environ[v0 - 1] );
}
else
{
v1 = 0;
}
result = 0LL;
v3 = env_count <= v1;
if ( env_count != v1 )
{
env_count = v1;
if ( v3 )
result = 1LL;
else
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 v1; // rbx
int *v2; // rax

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

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

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

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; // er14
unsigned int *v4; // r12
const char **v5; // rbx
unsigned int *v6; // r15
const char **v7; // rbp
const char *v8; // rsi
unsigned int *v9; // rbx
__int64 v10; // rsi

v3 = argc - 1;
v4 = (unsigned int *)calloc(argc - 1, 4uLL);
printf("Original array:");
if ( argc - 1 < 0 )
{
putchar(10);
bubbleSort((__int64)v4, v3);
printf("Sorted array:");
}
else
{
v5 = argv + 1;
v6 = v4;
v7 = &argv[(unsigned int)v3 + 2];
do
{
v8 = *v5;
if ( !*v5 )
break;
++v5;
++v6;
printf(" %s", v8);
*(v6 - 1) = atoi(*(v5 - 1));
}
while ( v5 != v7 );
putchar(10);
bubbleSort((__int64)v4, v3);
printf("Sorted array:");
if ( v3 > 0 )
{
v9 = v4;
do
{
v10 = *v9++;
printf(" %d", v10);
}
while ( v9 != &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; // er14
unsigned int *v4; // r12
const char **v5; // rbx
unsigned int *v6; // r15
const char **v7; // rbp
const char *v8; // rsi
unsigned int *v9; // rbx
__int64 v10; // rsi

v3 = argc - 1;
v4 = (unsigned int *)calloc(argc - 1, 4uLL);
printf("Original array:");
if ( argc - 1 < 0 )
{
putchar(10);
func0((__int64)v4, v3);
printf("Sorted array:");
}
else
{
v5 = argv + 1;
v6 = v4;
v7 = &argv[(unsigned int)v3 + 2];
do
{
v8 = *v5;
if ( !*v5 )
break;
++v5;
++v6;
printf(" %s", v8);
*(v6 - 1) = atoi(*(v5 - 1));
}
while ( v5 != v7 );
putchar(10);
func0((__int64)v4, v3);
printf("Sorted array:");
if ( v3 > 0 )
{
v9 = v4;
do
{
v10 = *v9++;
printf(" %d", v10);
}
while ( v9 != &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 __int16 v2; // si
__int64 v3; // rcx
unsigned int v4; // eax
int v5; // edx

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

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int16 *a1, unsigned __int16 a2)
{
unsigned __int16 v2; // si
__int64 v3; // rcx
unsigned int v4; // eax
int v5; // edx

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

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