MainStateConstruct

decompiled_code:
__int64 __fastcall MainStateConstruct(__int64 a1)
{
HsmCtor(a1, "MainState", MainState_top);
StateCtor(a1 + 56, "Show Gray", a1 + 32, MainState_ShowGray);
StateCtor(a1 + 80, "Show Threshold", a1 + 32, MainState_ShowThreshold);
return StateCtor(a1 + 104, "Show Background", a1 + 32, MainState_ShowBackground);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
HsmCtor(a1, "MainState", MainState_top);
StateCtor(a1 + 56, "Show Gray", a1 + 32, MainState_ShowGray);
StateCtor(a1 + 80, "Show Threshold", a1 + 32, MainState_ShowThreshold);
return StateCtor(a1 + 104, "Show Background", a1 + 32, MainState_ShowBackground);
}

original_code:
void MainStateConstruct(MainState *me)
{
 HsmCtor((Hsm *)me, "MainState", (EvtHndlr)MainState_top);
 StateCtor(&me->showGray, "Show Gray", &((Hsm *)me)->top, (EvtHndlr)MainState_ShowGray);
 StateCtor(&me->showThreshold, "Show Threshold", &((Hsm *)me)->top, (EvtHndlr)MainState_ShowThreshold);
 StateCtor(&me->showBackground, "Show Background", &((Hsm *)me)->top, (EvtHndlr)MainState_ShowBackground);
}

canonical_original_code:
void MainStateConstruct(struct MainState *me)
{
 HsmCtor((struct Hsm *)me, "MainState", (struct Msg *(*)(struct Hsm *, struct Msg *))MainState_top);
 StateCtor(&me->showGray, "Show Gray", &((struct Hsm *)me)->top, (struct Msg *(*)(struct Hsm *, struct Msg *))MainState_ShowGray);
 StateCtor(&me->showThreshold, "Show Threshold", &((struct Hsm *)me)->top, (struct Msg *(*)(struct Hsm *, struct Msg *))MainState_ShowThreshold);
 StateCtor(&me->showBackground, "Show Background", &((struct Hsm *)me)->top, (struct Msg *(*)(struct Hsm *, struct Msg *))MainState_ShowBackground);
}


OscCamMultiBufferGetNext

decompiled_code:
__int64 __fastcall OscCamMultiBufferGetNext(_BYTE *a1, char a2)
{
int v2; // ecx
__int64 v3; // rax
int v5; // edx

v2 = (unsigned __int8)*a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( a1[v3 + 1] != a2 )
{
if ( v2 <= (int)++v3 )
return 0xFFFFFFFFLL;
}
v5 = v3 + 1;
if ( (_DWORD)v3 + 1 == v2 )
v5 = 0;
return (unsigned __int8)a1[v5 + 1];
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, char a2)
{
int v2; // ecx
__int64 v3; // rax
int v5; // edx

v2 = (unsigned __int8)*a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( a1[v3 + 1] != a2 )
{
if ( v2 <= (int)++v3 )
return 0xFFFFFFFFLL;
}
v5 = v3 + 1;
if ( (_DWORD)v3 + 1 == v2 )
v5 = 0;
return (unsigned __int8)a1[v5 + 1];
}

original_code:
static uint8 OscCamMultiBufferGetNext(struct OSC_CAM_MULTIBUFFER * pMB,
  uint8 fbID)
{
 int i;
 uint8 ret;
 ret = 255;
 for (i = 0; i < pMB->multiBufferDepth; i++)
 {
  if (pMB->fbIDs[i] == fbID)
  {
   i++;
   if (i == pMB->multiBufferDepth)
   {
    i = 0;
   }
   ret = pMB->fbIDs[i];
   return ret;
  }
 }
 return ret;
}

canonical_original_code:
static unsigned char OscCamMultiBufferGetNext(struct OSC_CAM_MULTIBUFFER *pMB, unsigned char fbID)
{
 int i;
 unsigned char ret;
 ret = 255;
 for (i = 0; i < pMB->multiBufferDepth; i++)
 {
  if (pMB->fbIDs[i] == fbID)
  {
   i++;
   if (i == pMB->multiBufferDepth)
   {
    i = 0;
   }
   ret = pMB->fbIDs[i];
   return ret;
  }
 }
 return ret;
}

variable_types: struct OSC_CAM_MULTIBUFFER { unsigned char multiBufferDepth; unsigned char fbIDs[8]; unsigned char idNextCapture; unsigned char idNextSync; } *

variable_types:
fbID
unsigned char

variable_types: i int

variable_types:
ret
unsigned char

return_type: unsigned char


OscCamMultiBufferCreate

decompiled_code:
__int64 __fastcall OscCamMultiBufferCreate(__int64 a1, unsigned __int8 a2, _QWORD *a3)
{
__int64 v4; // rax

if ( *(_BYTE *)a1 )
OscLog(5LL, "%s: \t\t\t\tReplacing existing multibuffer.\n", "OscCamMultiBufferCreate");
*(_BYTE *)a1 = a2;
v4 = a1 + 1;
if ( a2 > 7u )
{
*(_QWORD *)(a1 + 1) = *a3;
*(_QWORD *)(v4 + a2 - 8) = *(_QWORD *)((char *)a3 + a2 - 8);
qmemcpy(
(void *)((a1 + 9) & 0xFFFFFFFFFFFFFFF8LL),
(char *)a3 - (v4 - ((a1 + 9) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v4 - (((_DWORD)a1 + 9) & 0xFFFFFFF8) + a2) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)(a1 + 1) = *(_DWORD *)a3;
*(_DWORD *)(v4 + a2 - 4) = *(_DWORD *)((char *)a3 + a2 - 4);
}
else if ( a2 )
{
*(_BYTE *)(a1 + 1) = *(_BYTE *)a3;
if ( (a2 & 2) != 0 )
*(_WORD *)(v4 + a2 - 2) = *(_WORD *)((char *)a3 + a2 - 2);
}
*(_BYTE *)(a1 + 9) = *(_BYTE *)(a1 + 1);
*(_BYTE *)(a1 + 10) = -1;
return 0LL;
}

original_code:
OSC_ERR OscCamMultiBufferCreate(struct OSC_CAM_MULTIBUFFER * pMB,
  const uint8 multiBufferDepth,
  const uint8 bufferIDs[])
{
 if(pMB->multiBufferDepth != 0)
 {
  OscLog(NOTICE, "%s: 				Replacing existing multibuffer.\n",
    __func__);
 }
 pMB->multiBufferDepth = multiBufferDepth;
 memcpy(&pMB->fbIDs,
   bufferIDs,
   multiBufferDepth*sizeof(uint8));
 pMB->idNextCapture = pMB->fbIDs[0];
 pMB->idNextSync = 255;
 return SUCCESS;
}

canonical_original_code:
int OscCamMultiBufferCreate(struct OSC_CAM_MULTIBUFFER *pMB, unsigned char multiBufferDepth, unsigned char bufferIDs[])
{
 if(pMB->multiBufferDepth != 0)
 {
  OscLog(NOTICE, "%s: 				Replacing existing multibuffer.\n",
    __func__);
 }
 pMB->multiBufferDepth = multiBufferDepth;
 memcpy(&pMB->fbIDs,
   bufferIDs,
   multiBufferDepth*sizeof(uint8));
 pMB->idNextCapture = pMB->fbIDs[0];
 pMB->idNextSync = 255;
 return SUCCESS;
}

variable_types:
multiBufferDepth
unsigned char

variable_types:
bufferIDs
unsigned char []

return_type: int

user_defined_types: struct OSC_CAM_MULTIBUFFER { unsigned char multiBufferDepth; unsigned char fbIDs[8]; unsigned char idNextCapture; unsigned char idNextSync; }


OscCamMultiBufferDestroy

decompiled_code:
__int64 __fastcall OscCamMultiBufferDestroy(_BYTE *a1)
{
if ( !*a1 )
OscLog(4LL, "%s: Nothing to delete.\n", "OscCamMultiBufferDestroy");
*a1 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
if ( !*a1 )
OscLog(4LL, "%s: Nothing to delete.\n", "OscCamMultiBufferDestroy");
*a1 = 0;
return 0LL;
}

original_code:
inline OSC_ERR OscCamMultiBufferDestroy(struct OSC_CAM_MULTIBUFFER * pMB)
{
 if (pMB->multiBufferDepth == 0)
 {
  OscLog(WARN, "%s: Nothing to delete.\n", __func__);
 }
 pMB->multiBufferDepth = 0;
 return SUCCESS;
}

canonical_original_code:
inline int OscCamMultiBufferDestroy(struct OSC_CAM_MULTIBUFFER *pMB)
{
 if (pMB->multiBufferDepth == 0)
 {
  OscLog(WARN, "%s: Nothing to delete.\n", __func__);
 }
 pMB->multiBufferDepth = 0;
 return SUCCESS;
}


OscCamMultiBufferGetCapBuf

decompiled_code:
__int64 __fastcall OscCamMultiBufferGetCapBuf(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 9);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 9);
}

original_code:
inline uint8 OscCamMultiBufferGetCapBuf(
  const struct OSC_CAM_MULTIBUFFER *pMB)
{
 return pMB->idNextCapture;
}

canonical_original_code:
inline unsigned char OscCamMultiBufferGetCapBuf(struct OSC_CAM_MULTIBUFFER *pMB)
{
 return pMB->idNextCapture;
}


OscCamMultiBufferCapture

decompiled_code:
__int64 __fastcall OscCamMultiBufferCapture(_BYTE *a1)
{
char v1; // bp
__int64 result; // rax
char v3; // si

v1 = a1[9];
result = OscCamMultiBufferGetNext(a1, v1);
a1[9] = result;
v3 = a1[10];
if ( v3 == -1 )
{
a1[10] = v1;
}
else if ( v3 == v1 )
{
result = OscCamMultiBufferGetNext(a1, v3);
a1[10] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
char v1; // bp
__int64 result; // rax
char v3; // si

v1 = a1[9];
result = func0(a1, v1);
a1[9] = result;
v3 = a1[10];
if ( v3 == -1 )
{
a1[10] = v1;
}
else if ( v3 == v1 )
{
result = func0(a1, v3);
a1[10] = result;
}
return result;
}

original_code:
void OscCamMultiBufferCapture(struct OSC_CAM_MULTIBUFFER *pMB)
{
 uint8 cur;
 cur = pMB->idNextCapture;
 pMB->idNextCapture =
 OscCamMultiBufferGetNext(pMB, pMB->idNextCapture);
 if(pMB->idNextSync == 255)
 {
  pMB->idNextSync = cur;
 }
 else if(pMB->idNextSync == cur)
 {
  pMB->idNextSync =
  OscCamMultiBufferGetNext(pMB, pMB->idNextSync);
 }
}

canonical_original_code:
void OscCamMultiBufferCapture(struct OSC_CAM_MULTIBUFFER *pMB)
{
 unsigned char cur;
 cur = pMB->idNextCapture;
 pMB->idNextCapture =
 OscCamMultiBufferGetNext(pMB, pMB->idNextCapture);
 if(pMB->idNextSync == 255)
 {
  pMB->idNextSync = cur;
 }
 else if(pMB->idNextSync == cur)
 {
  pMB->idNextSync =
  OscCamMultiBufferGetNext(pMB, pMB->idNextSync);
 }
}

variable_types:
cur
unsigned char

return_type: void


OscCamMultiBufferGetSyncBuf

decompiled_code:
__int64 __fastcall OscCamMultiBufferGetSyncBuf(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 10);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 10);
}

original_code:
inline uint8 OscCamMultiBufferGetSyncBuf(
  const struct OSC_CAM_MULTIBUFFER *pMB)
{
 return pMB->idNextSync;
}

canonical_original_code:
inline unsigned char OscCamMultiBufferGetSyncBuf(struct OSC_CAM_MULTIBUFFER *pMB)
{
 return pMB->idNextSync;
}


OscCamMultiBufferSync

decompiled_code:
__int64 __fastcall OscCamMultiBufferSync(_BYTE *a1)
{
__int64 result; // rax

result = OscCamMultiBufferGetNext(a1, a1[10]);
a1[10] = result;
if ( (_BYTE)result == a1[9] )
a1[10] = -1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
__int64 result; // rax

result = func0(a1, a1[10]);
a1[10] = result;
if ( (_BYTE)result == a1[9] )
a1[10] = -1;
return result;
}

original_code:
void OscCamMultiBufferSync(struct OSC_CAM_MULTIBUFFER * pMB)
{
 uint8 cur;
 cur = pMB->idNextSync;
 pMB->idNextSync =
  OscCamMultiBufferGetNext(pMB, pMB->idNextSync);
 if(pMB->idNextSync == pMB->idNextCapture)
 {
  pMB->idNextSync = 255;
 }
}

canonical_original_code:
void OscCamMultiBufferSync(struct OSC_CAM_MULTIBUFFER *pMB)
{
 unsigned char cur;
 cur = pMB->idNextSync;
 pMB->idNextSync =
  OscCamMultiBufferGetNext(pMB, pMB->idNextSync);
 if(pMB->idNextSync == pMB->idNextCapture)
 {
  pMB->idNextSync = 255;
 }
}


OscVisSobel

original_code:
OSC_ERR OscVisSobel(const uint8 *pIn, uint8 *pOut, const uint16 width, const uint16 height, const uint8 exp)
{
 uint16 x,y;
 int16 gradX, gradY, pix;
 for (y = 1; y < height-1; y++){
  for (x = 1; x < width-1; x++){
   gradX = pIn[(y-1) * width + (x-1)] - pIn[(y-1) * width + (x+1)] +
       (pIn[y * width + (x-1) ] << 1) - (pIn[y * width + (x+1) ] << 1) +
        pIn[(y+1) * width + (x-1)] - pIn[(y+1) * width + (x+1)];
   gradY = pIn[(y-1) * width + (x-1)] + (pIn[(y-1) * width + x] << 1) + pIn[(y-1) * width + (x+1)] -
        pIn[(y+1) * width + (x-1)] - (pIn[(y+1) * width + x] << 1) - pIn[(y+1) * width + (x+1)];
   pix = (gradY * gradY + gradX * gradX) >> exp;
   if(pix > 255) pix = 255;
   pOut[y * width + x] = pix;
  }
 }
 return SUCCESS;
}

canonical_original_code:
int OscVisSobel(unsigned char *pIn, unsigned char *pOut, unsigned short width, unsigned short height, unsigned char exp)
{
 unsigned short x; unsigned short y;
 short gradX; short gradY; short pix;
 for (y = 1; y < height-1; y++){
  for (x = 1; x < width-1; x++){
   gradX = pIn[(y-1) * width + (x-1)] - pIn[(y-1) * width + (x+1)] +
       (pIn[y * width + (x-1) ] << 1) - (pIn[y * width + (x+1) ] << 1) +
        pIn[(y+1) * width + (x-1)] - pIn[(y+1) * width + (x+1)];
   gradY = pIn[(y-1) * width + (x-1)] + (pIn[(y-1) * width + x] << 1) + pIn[(y-1) * width + (x+1)] -
        pIn[(y+1) * width + (x-1)] - (pIn[(y+1) * width + x] << 1) - pIn[(y+1) * width + (x+1)];
   pix = (gradY * gradY + gradX * gradX) >> exp;
   if(pix > 255) pix = 255;
   pOut[y * width + x] = pix;
  }
 }
 return SUCCESS;
}

variable_types:
pIn
unsigned char *

variable_types:
pOut
unsigned char *

variable_types:
width
unsigned short

variable_types:
height
unsigned short

variable_types:
exp
unsigned char

variable_types:
x
unsigned short

variable_types:
y
unsigned short

variable_types: gradX short

variable_types: gradY short

variable_types: pix short


OscGpioCreate

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

memset(&gpio, 0, 0x798uLL);
result = OscGpioInitPins();
if ( (_DWORD)result )
{
OscLog(3LL, "%s: Unable to intialize GPIO pins (%d)!\n", "OscGpioCreate", (unsigned int)result);
result = 4294967287LL;
}
return result;
}

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

memset(&gpio, 0, 0x798uLL);
result = OscGpioInitPins();
if ( (_DWORD)result )
{
OscLog(3LL, "%s: Unable to intialize GPIO pins (%d)!\n", "OscGpioCreate", (unsigned int)result);
result = 4294967287LL;
}
return result;
}

original_code:
OSC_ERR OscGpioCreate()
{
 OSC_ERR err = SUCCESS;
 gpio = (struct OSC_GPIO) { };
 err = OscGpioInitPins();
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to intialize GPIO pins (%d)!\n",
     __func__, err);
  return -EDEVICE;
 }
 return SUCCESS;
}

canonical_original_code:
int OscGpioCreate()
{
 int err = SUCCESS;
 gpio = (struct OSC_GPIO) { };
 err = OscGpioInitPins();
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to intialize GPIO pins (%d)!\n",
     __func__, err);
  return -EDEVICE;
 }
 return SUCCESS;
}

variable_types: err int

user_defined_types: struct OSC_GPIO { struct GPIO_PIN pins[48]; enum EnTriggerConfig enTriggerConfig; void *hWriter; void *hReader; void *phSignalOut[48]; void *phSignalIn[48]; }

user_defined_types: enum EnTriggerConfig { TRIGGER_INTERNAL=0, TRIGGER_EXTERNAL_IN2=1 }

user_defined_types: struct GPIO_PIN { int fd; struct GPIO_PIN_CONFIG *pDefConfig; int flags; _Bool bState; }

user_defined_types: struct GPIO_PIN_CONFIG { int pinNr; int defaultFlags; char name[32]; _Bool defaultState; }


OscGpioConfigSensorLedOut

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

if ( a1 )
{
result = OscGpioWrite(6LL, (gpio[40] >> 1) & 1);
gpio[40] |= 0x10u;
}
else
{
gpio[40] &= 0xFFFFFFEF;
result = 0LL;
}
return result;
}

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

if ( a1 )
{
result = OscGpioWrite(6LL, (gpio[40] >> 1) & 1);
gpio[40] |= 0x10u;
}
else
{
gpio[40] &= 0xFFFFFFEF;
result = 0LL;
}
return result;
}

original_code:
OSC_ERR OscGpioConfigSensorLedOut(_Bool bSensorLedOut)
{
 struct GPIO_PIN *pPin = &gpio.pins[GPIO_OUT2];
 OSC_ERR err = SUCCESS;
 if(bSensorLedOut)
 {
  err = OscGpioWrite(GPIO_OUT2, ((pPin->flags & 0x2) != 0));
  pPin->flags |= 0x10;
 } else {
  pPin->flags &= ~0x10;
 }
 return err;
}

canonical_original_code:
int OscGpioConfigSensorLedOut(_Bool bSensorLedOut)
{
 struct GPIO_PIN *pPin = &gpio.pins[GPIO_OUT2];
 int err = SUCCESS;
 if(bSensorLedOut)
 {
  err = OscGpioWrite(GPIO_OUT2, ((pPin->flags & 0x2) != 0));
  pPin->flags |= 0x10;
 } else {
  pPin->flags &= ~0x10;
 }
 return err;
}

variable_types: struct GPIO_PIN { int fd; struct GPIO_PIN_CONFIG { int pinNr; int defaultFlags; char name[32]; _Bool defaultState; } *pDefConfig; int flags; _Bool bState; } *


OscVisErode

original_code:
OSC_ERR OscVisErode(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut, uint8 *pTempBuffer, struct OSC_VIS_STREL *pStrEl, uint8 nRepetitions)
{
 uint16 i,j,t,r,k;
 uint16 yOffset, xOffset;
 uint8 tempPixelVal;
 uint8 nSubElements = 1;
 uint8 *pBinImgIn = (uint8*)picIn->data;
 uint8 *pBinImgOut = (uint8*)picOut->data;
 uint16 width = picIn->width;
 uint16 height = picIn->height;
 if (pStrEl->isDecomposed)
  nSubElements = pStrEl->numberOfSubElements;
 else nSubElements = 1;
 memcpy(pTempBuffer, pBinImgIn, sizeof(uint8)*width*height);
 for(k = 0; k < nRepetitions; k++)
 {
  for(r = 0; r < nSubElements; r++)
  {
   if (pStrEl->subStrEl[r].kernelHeight > 0)
    yOffset = (pStrEl->subStrEl[r].kernelHeight-1) >> 1;
   else yOffset = 0;
   if (pStrEl->subStrEl[r].kernelWidth > 0)
    xOffset = (pStrEl->subStrEl[r].kernelWidth-1) >> 1;
   else xOffset = 0;
   for(i = yOffset; i < (height - yOffset); i++)
   {
    for(j = xOffset; j < (width - xOffset); j++)
    {
     tempPixelVal = pTempBuffer[i * width + j];
     for(t = 0; t < pStrEl->subStrEl[r].arrayLength; t = t+2)
     {
      tempPixelVal = (tempPixelVal * pTempBuffer[(i + pStrEl->subStrEl[r].kernelArray[t+1])* width + (j + pStrEl->subStrEl[r].kernelArray[t])]);
     }
     pBinImgOut[i * width + j] = tempPixelVal;
    }
   }
   if (nSubElements > 1)
    memcpy(pTempBuffer, pBinImgOut, sizeof(uint8)*width*height);
  }
  if (nRepetitions > 1)
    memcpy(pTempBuffer, pBinImgOut, sizeof(uint8)*width*height);
 }
 picOut->height = height;
 picOut->width = width;
 picOut->type = OSC_PICTURE_BINARY;
 return SUCCESS;
}

canonical_original_code:
int OscVisErode(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut, unsigned char *pTempBuffer, struct OSC_VIS_STREL *pStrEl, unsigned char nRepetitions)
{
 unsigned short i; unsigned short j; unsigned short t; unsigned short r; unsigned short k;
 unsigned short yOffset; unsigned short xOffset;
 unsigned char tempPixelVal;
 unsigned char nSubElements = 1;
 unsigned char *pBinImgIn = (uint8*)picIn->data;
 unsigned char *pBinImgOut = (uint8*)picOut->data;
 unsigned short width = picIn->width;
 unsigned short height = picIn->height;
 if (pStrEl->isDecomposed)
  nSubElements = pStrEl->numberOfSubElements;
 else nSubElements = 1;
 memcpy(pTempBuffer, pBinImgIn, sizeof(uint8)*width*height);
 for(k = 0; k < nRepetitions; k++)
 {
  for(r = 0; r < nSubElements; r++)
  {
   if (pStrEl->subStrEl[r].kernelHeight > 0)
    yOffset = (pStrEl->subStrEl[r].kernelHeight-1) >> 1;
   else yOffset = 0;
   if (pStrEl->subStrEl[r].kernelWidth > 0)
    xOffset = (pStrEl->subStrEl[r].kernelWidth-1) >> 1;
   else xOffset = 0;
   for(i = yOffset; i < (height - yOffset); i++)
   {
    for(j = xOffset; j < (width - xOffset); j++)
    {
     tempPixelVal = pTempBuffer[i * width + j];
     for(t = 0; t < pStrEl->subStrEl[r].arrayLength; t = t+2)
     {
      tempPixelVal = (tempPixelVal * pTempBuffer[(i + pStrEl->subStrEl[r].kernelArray[t+1])* width + (j + pStrEl->subStrEl[r].kernelArray[t])]);
     }
     pBinImgOut[i * width + j] = tempPixelVal;
    }
   }
   if (nSubElements > 1)
    memcpy(pTempBuffer, pBinImgOut, sizeof(uint8)*width*height);
  }
  if (nRepetitions > 1)
    memcpy(pTempBuffer, pBinImgOut, sizeof(uint8)*width*height);
 }
 picOut->height = height;
 picOut->width = width;
 picOut->type = OSC_PICTURE_BINARY;
 return SUCCESS;
}

variable_types: struct OSC_PICTURE { void *data; unsigned short width; unsigned short height; enum EnOscPictureType { OSC_PICTURE_GREYSCALE=0, OSC_PICTURE_YUV_444=1, OSC_PICTURE_YUV_422=2, OSC_PICTURE_YUV_420=3, OSC_PICTURE_YUV_400=4, OSC_PICTURE_CHROM_U=5, OSC_PICTURE_CHROM_V=6, OSC_PICTURE_HUE=7, OSC_PICTURE_BGR_24=8, OSC_PICTURE_RGB_24=9, OSC_PICTURE_BINARY=10 } type; } *

variable_types:
picOut
struct OSC_PICTURE *

variable_types:
pTempBuffer
unsigned char *

variable_types: struct OSC_VIS_STREL { _Bool isDecomposed; unsigned char numberOfSubElements; struct OSC_VIS_SUBSTREL { unsigned short arrayLength; unsigned char kernelWidth; unsigned char kernelHeight; char *kernelArray; } subStrEl[4]; } *

variable_types:
nRepetitions
unsigned char

variable_types:
i
unsigned short

variable_types:
j
unsigned short

variable_types:
t
unsigned short

variable_types:
r
unsigned short

variable_types:
k
unsigned short

variable_types:
yOffset
unsigned short

variable_types:
xOffset
unsigned short

variable_types:
tempPixelVal
unsigned char

variable_types:
nSubElements
unsigned char

variable_types:
pBinImgIn
unsigned char *

variable_types:
pBinImgOut
unsigned char *

user_defined_types: struct OSC_PICTURE { void *data; unsigned short width; unsigned short height; enum EnOscPictureType type; }

user_defined_types: struct OSC_VIS_STREL { _Bool isDecomposed; unsigned char numberOfSubElements; struct OSC_VIS_SUBSTREL subStrEl[4]; }


OscVisDilate

original_code:
OSC_ERR OscVisDilate(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut, uint8 *pTempBuffer, struct OSC_VIS_STREL *pStrEl, uint8 nRepetitions)
{
 uint16 i,j,t,r,k;
 uint16 yOffset, xOffset;
 uint8 tempPixelVal;
 uint8 nSubElements = 1;
 uint8 *pBinImgIn = (uint8*)picIn->data;
 uint8 *pBinImgOut = (uint8*)picOut->data;
 uint16 width = picIn->width;
 uint16 height = picIn->height;
 if (pStrEl->isDecomposed)
  nSubElements = pStrEl->numberOfSubElements;
 else nSubElements = 1;
 memcpy(pTempBuffer, pBinImgIn, sizeof(uint8)*width*height);
 for(k = 0; k < nRepetitions; k++)
 {
  for(r = 0; r < nSubElements; r++)
  {
   if (pStrEl->subStrEl[r].kernelHeight > 0)
    yOffset = (pStrEl->subStrEl[r].kernelHeight-1) >> 1;
   else yOffset = 0;
   if (pStrEl->subStrEl[r].kernelWidth > 0)
    xOffset = (pStrEl->subStrEl[r].kernelWidth-1) >> 1;
   else xOffset = 0;
   for(i = yOffset; i < (height - yOffset); i++)
   {
    for(j = xOffset; j < (width - xOffset); j++)
    {
     tempPixelVal = pTempBuffer[i * width + j];
     for(t = 0; t < pStrEl->subStrEl[r].arrayLength; t = t+2)
     {
      tempPixelVal = (tempPixelVal || pTempBuffer[(i + pStrEl->subStrEl[r].kernelArray[t+1]) * width + (j + pStrEl->subStrEl[r].kernelArray[t])]);
     }
     pBinImgOut[i * width + j] = tempPixelVal;
    }
   }
   if (nSubElements > 1)
    memcpy(pTempBuffer, pBinImgOut, sizeof(uint8)*width*height);
  }
  if (nRepetitions > 1)
    memcpy(pTempBuffer, pBinImgOut, sizeof(uint8)*width*height);
 }
 picOut->height = height;
 picOut->width = width;
 picOut->type = OSC_PICTURE_BINARY;
 return SUCCESS;
}

canonical_original_code:
int OscVisDilate(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut, unsigned char *pTempBuffer, struct OSC_VIS_STREL *pStrEl, unsigned char nRepetitions)
{
 unsigned short i; unsigned short j; unsigned short t; unsigned short r; unsigned short k;
 unsigned short yOffset; unsigned short xOffset;
 unsigned char tempPixelVal;
 unsigned char nSubElements = 1;
 unsigned char *pBinImgIn = (uint8*)picIn->data;
 unsigned char *pBinImgOut = (uint8*)picOut->data;
 unsigned short width = picIn->width;
 unsigned short height = picIn->height;
 if (pStrEl->isDecomposed)
  nSubElements = pStrEl->numberOfSubElements;
 else nSubElements = 1;
 memcpy(pTempBuffer, pBinImgIn, sizeof(uint8)*width*height);
 for(k = 0; k < nRepetitions; k++)
 {
  for(r = 0; r < nSubElements; r++)
  {
   if (pStrEl->subStrEl[r].kernelHeight > 0)
    yOffset = (pStrEl->subStrEl[r].kernelHeight-1) >> 1;
   else yOffset = 0;
   if (pStrEl->subStrEl[r].kernelWidth > 0)
    xOffset = (pStrEl->subStrEl[r].kernelWidth-1) >> 1;
   else xOffset = 0;
   for(i = yOffset; i < (height - yOffset); i++)
   {
    for(j = xOffset; j < (width - xOffset); j++)
    {
     tempPixelVal = pTempBuffer[i * width + j];
     for(t = 0; t < pStrEl->subStrEl[r].arrayLength; t = t+2)
     {
      tempPixelVal = (tempPixelVal || pTempBuffer[(i + pStrEl->subStrEl[r].kernelArray[t+1]) * width + (j + pStrEl->subStrEl[r].kernelArray[t])]);
     }
     pBinImgOut[i * width + j] = tempPixelVal;
    }
   }
   if (nSubElements > 1)
    memcpy(pTempBuffer, pBinImgOut, sizeof(uint8)*width*height);
  }
  if (nRepetitions > 1)
    memcpy(pTempBuffer, pBinImgOut, sizeof(uint8)*width*height);
 }
 picOut->height = height;
 picOut->width = width;
 picOut->type = OSC_PICTURE_BINARY;
 return SUCCESS;
}

variable_types:
width
unsigned short

variable_types:
height
unsigned short

user_defined_types: enum EnOscPictureType { OSC_PICTURE_GREYSCALE=0, OSC_PICTURE_YUV_444=1, OSC_PICTURE_YUV_422=2, OSC_PICTURE_YUV_420=3, OSC_PICTURE_YUV_400=4, OSC_PICTURE_CHROM_U=5, OSC_PICTURE_CHROM_V=6, OSC_PICTURE_HUE=7, OSC_PICTURE_BGR_24=8, OSC_PICTURE_RGB_24=9, OSC_PICTURE_BINARY=10 }

user_defined_types: struct OSC_VIS_SUBSTREL { unsigned short arrayLength; unsigned char kernelWidth; unsigned char kernelHeight; char *kernelArray; }


OscFrdConstGetCurrentFileName

decompiled_code:
char *__fastcall OscFrdConstGetCurrentFileName(char *src, char *dest)
{
return strcpy(dest, src);
}

canonical_decompiled_code:
char *__fastcall func7(char *src, char *dest)
{
return strcpy(dest, src);
}

original_code:
static void OscFrdConstGetCurrentFileName(
  const struct OSC_FRD_CONSTANT_READER *pReader,
  char strCurName[])
{
 strcpy(strCurName, pReader->strFN);
}

canonical_original_code:
static void OscFrdConstGetCurrentFileName(struct OSC_FRD_CONSTANT_READER *pReader, char strCurName[])
{
 strcpy(strCurName, pReader->strFN);
}

variable_types: struct OSC_FRD_CONSTANT_READER { char strFN[1024]; } *

variable_types:
strCurName
char []


OscFrdSeqGetCurrentFileName

decompiled_code:
char *__fastcall OscFrdSeqGetCurrentFileName(char *src, char *dest)
{
unsigned int v2; // er12
char v4[16]; // [rsp+0h] [rbp-38h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

v2 = OscSimGetCurTimeStep();
sprintf(s, "%%0%uu", *((unsigned int *)src + 256));
sprintf(v4, s, v2);
strcpy(dest, src);
strcat(dest, v4);
return strcat(dest, src + 1028);
}

canonical_decompiled_code:
char *__fastcall func9(char *src, char *dest)
{
unsigned int v2; // er12
char v4[16]; // [rsp+0h] [rbp-38h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

v2 = OscSimGetCurTimeStep();
sprintf(s, "%%0%uu", *((unsigned int *)src + 256));
sprintf(v4, s, v2);
strcpy(dest, src);
strcat(dest, v4);
return strcat(dest, src + 1028);
}

original_code:
static void OscFrdSeqGetCurrentFileName(
  const struct OSC_FRD_SEQUENCE_READER *pReader,
  char strCurName[])
{
 char strFormat[16];
 char strSeq[16];
 uint32 curSeqNr;
 curSeqNr = OscSimGetCurTimeStep();
 sprintf(strFormat, "%%0%uu", pReader->seqNrDigits);
 sprintf(strSeq, strFormat, curSeqNr);
 strcpy(strCurName, pReader->strPrefix);
 strcat(strCurName, strSeq);
 strcat(strCurName, pReader->strSuffix);
}

canonical_original_code:
static void OscFrdSeqGetCurrentFileName(struct OSC_FRD_SEQUENCE_READER *pReader, char strCurName[])
{
 char strFormat[16];
 char strSeq[16];
 unsigned int curSeqNr;
 curSeqNr = OscSimGetCurTimeStep();
 sprintf(strFormat, "%%0%uu", pReader->seqNrDigits);
 sprintf(strSeq, strFormat, curSeqNr);
 strcpy(strCurName, pReader->strPrefix);
 strcat(strCurName, strSeq);
 strcat(strCurName, pReader->strSuffix);
}

variable_types: struct OSC_FRD_SEQUENCE_READER { char strPrefix[1024]; int seqNrDigits; char strSuffix[16]; } *

variable_types:
strFormat
char [16]

variable_types:
strSeq
char [16]

variable_types:
curSeqNr
unsigned int


CheckIpcRequests

decompiled_code:
__int64 __fastcall CheckIpcRequests(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx

if ( *((_DWORD *)&data + 315856) )
return (unsigned int)-901;
v1 = OscIpcGetRequest(*((unsigned __int8 *)&data + 1263400), (unsigned int)((_DWORD)&data + 1263408));
v2 = v1;
if ( v1 )
{
if ( v1 != -901 )
OscLog(3LL, "%s: Error getting IPC request! (%d)\n", "CheckIpcRequests", v1);
}
else
{
*a1 = *((_DWORD *)&data + 315853);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx

if ( *((_DWORD *)&data + 315856) )
return (unsigned int)-901;
v1 = OscIpcGetRequest(*((unsigned __int8 *)&data + 1263400), (unsigned int)((_DWORD)&data + 1263408));
v2 = v1;
if ( v1 )
{
if ( v1 != -901 )
OscLog(3LL, "%s: Error getting IPC request! (%d)\n", "CheckIpcRequests", v1);
}
else
{
*a1 = *((_DWORD *)&data + 315853);
}
return v2;
}

original_code:
OSC_ERR CheckIpcRequests(uint32 *pParamId)
{
 OSC_ERR err;
 struct IPC_DATA *pIpc = &data.ipc;
 struct OSC_IPC_REQUEST *pReq = &pIpc->req;
 if (pIpc->enReqState != REQ_STATE_IDLE)
 {
  return -ENO_MSG_AVAIL;
 }
 err = OscIpcGetRequest(pIpc->ipcChan, pReq);
 if (err == SUCCESS)
 {
  *pParamId = pReq->paramID;
 }
 else
 {
  if ((err == -ENO_MSG_AVAIL))
  {
  }
  else
  {
   OscLog(ERROR, "%s: Error getting IPC request! (%d)\n", __func__, err);
  }
 }
 return err;
}

canonical_original_code:
int CheckIpcRequests(unsigned int *pParamId)
{
 int err;
 struct IPC_DATA *pIpc = &data.ipc;
 struct OSC_IPC_REQUEST *pReq = &pIpc->req;
 if (pIpc->enReqState != REQ_STATE_IDLE)
 {
  return -ENO_MSG_AVAIL;
 }
 err = OscIpcGetRequest(pIpc->ipcChan, pReq);
 if (err == SUCCESS)
 {
  *pParamId = pReq->paramID;
 }
 else
 {
  if ((err == -ENO_MSG_AVAIL))
  {
  }
  else
  {
   OscLog(ERROR, "%s: Error getting IPC request! (%d)\n", __func__, err);
  }
 }
 return err;
}

variable_types:
pParamId
unsigned int *

variable_types: err int

variable_types: struct IPC_DATA { unsigned char ipcChan; struct OSC_IPC_REQUEST { enum EnRequestType { REQ_TYPE_READ=0, REQ_TYPE_WRITE=1 } enType; unsigned int paramID; void *pAddr; } req; enum EnIpcRequestState { REQ_STATE_IDLE=0, REQ_STATE_ACK_PENDING=1, REQ_STATE_NACK_PENDING=2 } enReqState; struct APPLICATION_STATE { _Bool bNewImageReady; unsigned int imageTimeStamp; enum EnAppMode { APP_OFF=0, APP_CAPTURE_ON=1 } enAppMode; unsigned int nImageType; int nExposureTime; int nThreshold; unsigned int nStepCounter; } state; } *

variable_types: struct OSC_IPC_REQUEST { enum EnRequestType { REQ_TYPE_READ=0, REQ_TYPE_WRITE=1 } enType; unsigned int paramID; void *pAddr; } *

user_defined_types: struct IPC_DATA { unsigned char ipcChan; struct OSC_IPC_REQUEST req; enum EnIpcRequestState enReqState; struct APPLICATION_STATE state; }

user_defined_types: struct OSC_IPC_REQUEST { enum EnRequestType enType; unsigned int paramID; void *pAddr; }

user_defined_types: struct APPLICATION_STATE { _Bool bNewImageReady; unsigned int imageTimeStamp; enum EnAppMode enAppMode; unsigned int nImageType; int nExposureTime; int nThreshold; unsigned int nStepCounter; }


AckIpcRequests

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

v0 = *((_DWORD *)&data + 315856);
result = 0LL;
if ( v0 )
{
result = OscIpcAckRequest(*((unsigned __int8 *)&data + 1263400), (unsigned int)((_DWORD)&data + 1263408), v0 != 2);
if ( (_DWORD)result )
{
if ( (_DWORD)result == -22 )
result = 0LL;
}
else
{
*((_DWORD *)&data + 315856) = 0;
}
}
return result;
}

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

v0 = *((_DWORD *)&data + 315856);
result = 0LL;
if ( v0 )
{
result = OscIpcAckRequest(*((unsigned __int8 *)&data + 1263400), (unsigned int)((_DWORD)&data + 1263408), v0 != 2);
if ( (_DWORD)result )
{
if ( (_DWORD)result == -22 )
result = 0LL;
}
else
{
*((_DWORD *)&data + 315856) = 0;
}
}
return result;
}

original_code:
OSC_ERR AckIpcRequests()
{
 struct IPC_DATA *pIpc = &data.ipc;
 struct OSC_IPC_REQUEST *pReq = &pIpc->req;
 OSC_ERR err;
 _Bool bSuccess;
 if (pIpc->enReqState == REQ_STATE_IDLE)
 {
  return SUCCESS;
 }
 else if (pIpc->enReqState == REQ_STATE_NACK_PENDING)
 {
  bSuccess = 0;
 }
 else
 {
  bSuccess = 1;
 }
 err = OscIpcAckRequest(pIpc->ipcChan, pReq, bSuccess);
 if (err == SUCCESS)
 {
  pIpc->enReqState = REQ_STATE_IDLE;
 }
 else if (err == -ETRY_AGAIN)
 {
  err = SUCCESS;
 }
 return err;
}

canonical_original_code:
int AckIpcRequests()
{
 struct IPC_DATA *pIpc = &data.ipc;
 struct OSC_IPC_REQUEST *pReq = &pIpc->req;
 int err;
 _Bool bSuccess;
 if (pIpc->enReqState == REQ_STATE_IDLE)
 {
  return SUCCESS;
 }
 else if (pIpc->enReqState == REQ_STATE_NACK_PENDING)
 {
  bSuccess = 0;
 }
 else
 {
  bSuccess = 1;
 }
 err = OscIpcAckRequest(pIpc->ipcChan, pReq, bSuccess);
 if (err == SUCCESS)
 {
  pIpc->enReqState = REQ_STATE_IDLE;
 }
 else if (err == -ETRY_AGAIN)
 {
  err = SUCCESS;
 }
 return err;
}

user_defined_types: enum EnIpcRequestState { REQ_STATE_IDLE=0, REQ_STATE_ACK_PENDING=1, REQ_STATE_NACK_PENDING=2 }

user_defined_types: enum EnRequestType { REQ_TYPE_READ=0, REQ_TYPE_WRITE=1 }

user_defined_types: enum EnAppMode { APP_OFF=0, APP_CAPTURE_ON=1 }


original_code:
void IpcSendImage_fr16(fract16 *f16Image, uint32 nPixels)
{
 fract16 *pSrc = f16Image;
 int i;
 uint8 *pDst = (uint8*)data.ipc.req.pAddr;
 for (i = 0; i < nPixels; i++)
 {
  *pDst = (uint8)(((uint32)((int32)(*pSrc) + 0x7fff)) >> 8);
  pSrc++;
  pDst++;
 }
}

canonical_original_code:
void IpcSendImage_fr16(short *f16Image, unsigned int nPixels)
{
 short *pSrc = f16Image;
 int i;
 unsigned char *pDst = (uint8*)data.ipc.req.pAddr;
 for (i = 0; i < nPixels; i++)
 {
  *pDst = (uint8)(((uint32)((int32)(*pSrc) + 0x7fff)) >> 8);
  pSrc++;
  pDst++;
 }
}

variable_types:
nPixels
unsigned int

variable_types:
pSrc
short *

variable_types: i int

variable_types:
pDst
unsigned char *


decompiled_code:
__int64 __fastcall DSP_Division(int a1, int a2)
{
__int64 result; // rax
unsigned int v3; // esi
__int16 v4; // dx

LODWORD(result) = a1;
v3 = a2 << 15;
v4 = 16;
do
{
if ( v3 >= (unsigned int)result )
result = (unsigned int)(2 * result);
else
result = 2 * ((unsigned int)result - v3) + 1;
--v4;
}
while ( v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 result; // rax
unsigned int v3; // esi
__int16 v4; // dx

LODWORD(result) = a1;
v3 = a2 << 15;
v4 = 16;
do
{
if ( v3 >= (unsigned int)result )
result = (unsigned int)(2 * result);
else
result = 2 * ((unsigned int)result - v3) + 1;
--v4;
}
while ( v4 );
return result;
}

original_code:
uint16 DSP_Division (uint32 numer, uint32 denom)
{
 uint16 i;
 denom <<= 15;
 for (i=16; i>0; i--)
 {
  if (numer > denom)
  {
   numer -= denom;
   numer <<= 1;
   numer++;
  }
  else
   numer <<= 1;
 }
 return (uint16) numer;
}

canonical_original_code:
unsigned short DSP_Division(unsigned int numer, unsigned int denom)
{
 unsigned short i;
 denom <<= 15;
 for (i=16; i>0; i--)
 {
  if (numer > denom)
  {
   numer -= denom;
   numer <<= 1;
   numer++;
  }
  else
   numer <<= 1;
 }
 return (unsigned short) numer;
}

variable_types:
numer
unsigned int

variable_types:
denom
unsigned int

variable_types:
i
unsigned short

return_type: unsigned short


variable_types:
index
unsigned short

variable_types:
value
unsigned int


quantization

decompiled_code:
__int64 __fastcall quantization(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rdx
__int64 result; // rax

for ( i = 63LL; i != -1; --i )
{
result = (unsigned int)((*(unsigned __int16 *)(a2 + 2 * i) * *(__int16 *)(a1 + 2 * i) + 0x4000) >> 15);
*(_WORD *)(a3 + 2LL * (unsigned __int8)zigzag_table[i]) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rdx
__int64 result; // rax

for ( i = 63LL; i != -1; --i )
{
result = (unsigned int)((*(unsigned __int16 *)(a2 + 2 * i) * *(__int16 *)(a1 + 2 * i) + 0x4000) >> 15);
*(_WORD *)(a3 + 2LL * (unsigned __int8)zigzag_table[i]) = result;
}
return result;
}

original_code:
void quantization (int16* const data, uint16* const quant_table_ptr, uint16 *Temp)
{
 int16 i;
 int32 value;
 for (i=63; i>=0; i--)
 {
  value = data [i] * quant_table_ptr [i];
  value = (value + 0x4000) >> 15;
  Temp [zigzag_table [i]] = (uint16) value;
 }
}

canonical_original_code:
void quantization(short *data, unsigned short *quant_table_ptr, unsigned short *Temp)
{
 short i;
 int value;
 for (i=63; i>=0; i--)
 {
  value = data [i] * quant_table_ptr [i];
  value = (value + 0x4000) >> 15;
  Temp [zigzag_table [i]] = (unsigned short) value;
 }
}

variable_types:
data
short *

variable_types:
Temp
unsigned short *

variable_types: i short

variable_types: value int


OscGetVersionNumber

decompiled_code:
__int64 __fastcall OscGetVersionNumber(_BYTE *a1, _BYTE *a2, _BYTE *a3)
{
*a1 = 2;
*a2 = 1;
*a3 = 2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, _BYTE *a2, _BYTE *a3)
{
*a1 = 2;
*a2 = 1;
*a3 = 2;
return 0LL;
}

original_code:
OSC_ERR OscGetVersionNumber(char *hMajor, char *hMinor, char *hPatch)
{
 *hMajor = 2;
 *hMinor = 1;
 *hPatch = 2;
 return SUCCESS;
}

canonical_original_code:
int OscGetVersionNumber(char *hMajor, char *hMinor, char *hPatch)
{
 *hMajor = 2;
 *hMinor = 1;
 *hPatch = 2;
 return SUCCESS;
}

variable_types:
hMajor
char *

variable_types:
hMinor
char *

variable_types:
hPatch
char *


OscVisDebayerBilinearBGR

decompiled_code:
__int64 __fastcall OscVisDebayerBilinearBGR(__int64 a1, __int64 a2, char a3, __int64 a4, __int64 a5, unsigned int a6)
{
if ( !a1 || !a2 )
return 4294967288LL;
if ( (a3 & 3) != 0 || !a5 )
return 4294967288LL;
if ( !a6 || a6 == 3 )
return DebayerBilinearBGR();
OscLog(3LL, "%s: Invalid bayer order supplied (%d)\n", "OscVisDebayerBilinearBGR", a6);
return 4294967288LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, char a3, __int64 a4, __int64 a5, unsigned int a6)
{
if ( !a1 || !a2 )
return 4294967288LL;
if ( (a3 & 3) != 0 || !a5 )
return 4294967288LL;
if ( !a6 || a6 == 3 )
return DebayerBilinearBGR();
OscLog(3LL, "%s: Invalid bayer order supplied (%d)\n", "OscVisDebayerBilinearBGR", a6);
return 4294967288LL;
}

original_code:
OSC_ERR OscVisDebayerBilinearBGR(uint8 *pDst,
     uint8 *pSrc,
     uint32 width,
     uint32 height,
     uint8 *pTmp,
     enum EnBayerOrder enBayerOrder)
{
  if(pDst == ((void *)0) || pSrc == ((void *)0) || (width % 4) || pTmp == ((void *)0))
    {
      return -EINVALID_PARAMETER;
    }
  if(enBayerOrder != ROW_BGBG && enBayerOrder != ROW_GRGR)
    {
      OscLog(ERROR, "%s: Invalid bayer order supplied (%d)\n", __func__, enBayerOrder);
      return -EINVALID_PARAMETER;
    }
  return DebayerBilinearBGR(pDst,
       pSrc,
       width,
       height,
       pTmp,
       enBayerOrder);
}

canonical_original_code:
int OscVisDebayerBilinearBGR(unsigned char *pDst, unsigned char *pSrc, unsigned int width, unsigned int height, unsigned char *pTmp, enum EnBayerOrder enBayerOrder)
{
  if(pDst == ((void *)0) || pSrc == ((void *)0) || (width % 4) || pTmp == ((void *)0))
    {
      return -EINVALID_PARAMETER;
    }
  if(enBayerOrder != ROW_BGBG && enBayerOrder != ROW_GRGR)
    {
      OscLog(ERROR, "%s: Invalid bayer order supplied (%d)\n", __func__, enBayerOrder);
      return -EINVALID_PARAMETER;
    }
  return DebayerBilinearBGR(pDst,
       pSrc,
       width,
       height,
       pTmp,
       enBayerOrder);
}

variable_types:
pSrc
unsigned char *

variable_types:
width
unsigned int

variable_types:
height
unsigned int

variable_types:
pTmp
unsigned char *

variable_types: enum EnBayerOrder { ROW_BGBG=0, ROW_RGRG=1, ROW_GBGB=2, ROW_GRGR=3 }


DebayerBilinearBGR

decompiled_code:
__int64 __fastcall DebayerBilinearBGR(__int64 a1, _BYTE *a2, unsigned int a3, int a4, unsigned __int8 *a5, int a6)
{
_BYTE *v6; // r14
_BYTE *v7; // r15
_BYTE *v8; // rbx
int v10; // er13
int v11; // ebp
__int64 v14; // [rsp+8h] [rbp-70h]
unsigned int v15; // [rsp+14h] [rbp-64h]
int v16; // [rsp+20h] [rbp-58h]
__int64 v18; // [rsp+28h] [rbp-50h]
__int64 v19; // [rsp+30h] [rbp-48h]
int v20; // [rsp+38h] [rbp-40h]
unsigned int v21; // [rsp+3Ch] [rbp-3Ch]

v21 = a6;
v14 = a3;
v6 = &a2[-a3];
v7 = &a2[a3];
if ( !a4 )
return 0LL;
v8 = a2;
v20 = 3 * a3;
v18 = (__int64)&a5[3 * a3];
v19 = (__int64)&a5[2 * a3];
v10 = a6;
v15 = 0;
v11 = 0;
v16 = a4 - 1;
do
{
if ( v11 )
{
if ( v16 == v11 )
debayerBilinearPreprocRowFirstOrLast(a5, a3, v6, v8);
else
debayerBilinearPreprocRow(a5, a3, v6, v8, v7);
}
else
{
debayerBilinearPreprocRowFirstOrLast(a5, a3, v7, v8);
}
if ( v10 )
{
if ( v10 != 3 )
{
OscLog(3LL, "%s: Unsupported bayer order encountered! (%d)\n", "DebayerBilinearBGR", v21);
return 4294967272LL;
}
grgrToBgr((_BYTE *)(a1 + v15), a5, (__int64)&a5[v14], v19, v18, v8, a3);
v10 = 0;
}
else
{
bgbgToBgr((_BYTE *)(a1 + v15), a5, (__int64)&a5[v14], v19, v18, v8, a3);
v10 = 3;
}
v8 += v14;
v6 += v14;
v7 += v14;
++v11;
v15 += v20;
}
while ( a4 != v11 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _BYTE *a2, unsigned int a3, int a4, unsigned __int8 *a5, int a6)
{
_BYTE *v6; // r14
_BYTE *v7; // r15
_BYTE *v8; // rbx
int v10; // er13
int v11; // ebp
__int64 v14; // [rsp+8h] [rbp-70h]
unsigned int v15; // [rsp+14h] [rbp-64h]
int v16; // [rsp+20h] [rbp-58h]
__int64 v18; // [rsp+28h] [rbp-50h]
__int64 v19; // [rsp+30h] [rbp-48h]
int v20; // [rsp+38h] [rbp-40h]
unsigned int v21; // [rsp+3Ch] [rbp-3Ch]

v21 = a6;
v14 = a3;
v6 = &a2[-a3];
v7 = &a2[a3];
if ( !a4 )
return 0LL;
v8 = a2;
v20 = 3 * a3;
v18 = (__int64)&a5[3 * a3];
v19 = (__int64)&a5[2 * a3];
v10 = a6;
v15 = 0;
v11 = 0;
v16 = a4 - 1;
do
{
if ( v11 )
{
if ( v16 == v11 )
debayerBilinearPreprocRowFirstOrLast(a5, a3, v6, v8);
else
debayerBilinearPreprocRow(a5, a3, v6, v8, v7);
}
else
{
debayerBilinearPreprocRowFirstOrLast(a5, a3, v7, v8);
}
if ( v10 )
{
if ( v10 != 3 )
{
OscLog(3LL, "%s: Unsupported bayer order encountered! (%d)\n", "DebayerBilinearBGR", v21);
return 4294967272LL;
}
grgrToBgr((_BYTE *)(a1 + v15), a5, (__int64)&a5[v14], v19, v18, v8, a3);
v10 = 0;
}
else
{
bgbgToBgr((_BYTE *)(a1 + v15), a5, (__int64)&a5[v14], v19, v18, v8, a3);
v10 = 3;
}
v8 += v14;
v6 += v14;
v7 += v14;
++v11;
v15 += v20;
}
while ( a4 != v11 );
return 0LL;
}

original_code:
OSC_ERR DebayerBilinearBGR(uint8 *pDst,
      uint8 *pSrc,
      uint32 width,
      uint32 height,
      uint8 *pTmp,
      enum EnBayerOrder enBayerOrder)
{
  uint32 row;
  uint8* pCurRow = pSrc;
  uint8* pOneRowUp = &pSrc[-(ptrdiff_t)(width)];
  uint8* pOneRowDown = &pSrc[width];
  enum EnBayerOrder enRowBayerOrder = enBayerOrder;
  for(row = 0; row < height; row++)
    {
      if(row == 0)
 {
   debayerBilinearPreprocRowFirstOrLast(pTmp,
            width,
            pOneRowDown,
            pCurRow);
 } else if(row == (height - 1)) {
   debayerBilinearPreprocRowFirstOrLast(pTmp,
            width,
            pOneRowUp,
            pCurRow);
      } else {
   debayerBilinearPreprocRow(pTmp,
        width,
        pOneRowUp,
        pCurRow,
        pOneRowDown);
      }
      switch(enRowBayerOrder)
 {
 case ROW_BGBG:
   bgbgToBgr(&pDst[row*width*3],
      pTmp,
      &pTmp[width],
      &pTmp[2*width],
      &pTmp[3*width],
      pCurRow,
      width);
   enRowBayerOrder = ROW_GRGR;
   break;
 case ROW_GRGR:
   grgrToBgr(&pDst[row*width*3],
      pTmp,
      &pTmp[width],
      &pTmp[2*width],
      &pTmp[3*width],
      pCurRow,
      width);
   enRowBayerOrder = ROW_BGBG;
   break;
 default:
   OscLog(ERROR, "%s: Unsupported bayer order encountered! (%d)\n",
   __func__, enBayerOrder);
   return -EUNSUPPORTED;
 }
      pCurRow += width;
      pOneRowUp += width;
      pOneRowDown += width;
    }
  return SUCCESS;
}

canonical_original_code:
int DebayerBilinearBGR(unsigned char *pDst, unsigned char *pSrc, unsigned int width, unsigned int height, unsigned char *pTmp, enum EnBayerOrder enBayerOrder)
{
  unsigned int row;
  unsigned char *pCurRow = pSrc;
  unsigned char *pOneRowUp = &pSrc[-(ptrdiff_t)(width)];
  unsigned char *pOneRowDown = &pSrc[width];
  enum EnBayerOrder enRowBayerOrder = enBayerOrder;
  for(row = 0; row < height; row++)
    {
      if(row == 0)
 {
   debayerBilinearPreprocRowFirstOrLast(pTmp,
            width,
            pOneRowDown,
            pCurRow);
 } else if(row == (height - 1)) {
   debayerBilinearPreprocRowFirstOrLast(pTmp,
            width,
            pOneRowUp,
            pCurRow);
      } else {
   debayerBilinearPreprocRow(pTmp,
        width,
        pOneRowUp,
        pCurRow,
        pOneRowDown);
      }
      switch(enRowBayerOrder)
 {
 case ROW_BGBG:
   bgbgToBgr(&pDst[row*width*3],
      pTmp,
      &pTmp[width],
      &pTmp[2*width],
      &pTmp[3*width],
      pCurRow,
      width);
   enRowBayerOrder = ROW_GRGR;
   break;
 case ROW_GRGR:
   grgrToBgr(&pDst[row*width*3],
      pTmp,
      &pTmp[width],
      &pTmp[2*width],
      &pTmp[3*width],
      pCurRow,
      width);
   enRowBayerOrder = ROW_BGBG;
   break;
 default:
   OscLog(ERROR, "%s: Unsupported bayer order encountered! (%d)\n",
   __func__, enBayerOrder);
   return -EUNSUPPORTED;
 }
      pCurRow += width;
      pOneRowUp += width;
      pOneRowDown += width;
    }
  return SUCCESS;
}

variable_types:
pDst
unsigned char *

variable_types:
row
unsigned int

variable_types:
pCurRow
unsigned char *

variable_types:
pOneRowUp
unsigned char *

variable_types:
pOneRowDown
unsigned char *

user_defined_types: enum EnBayerOrder { ROW_BGBG=0, ROW_RGRG=1, ROW_GBGB=2, ROW_GRGR=3 }


repo: tchebb/stripesolver

original_code:
int qs_partition (long *array, int start, int end) {
 int pivot = array[(start + end) / 2];
 int i = start - 1, j = end + 1;
 while (1) {
  do {
   ++i;
  } while (array[i] < pivot);
  do {
   --j;
  } while (array[j] > pivot);
  if (i < j) {
   long temp = array[i];
   array[i] = array[j];
   array[j] = temp;
  } else {
   return j;
  }
 }
}

canonical_original_code:
int qs_partition(long *array, int start, int end) {
 int pivot = array[(start + end) / 2];
 int i = start - 1; int j = end + 1;
 while (1) {
  do {
   ++i;
  } while (array[i] < pivot);
  do {
   --j;
  } while (array[j] > pivot);
  if (i < j) {
   long temp = array[i];
   array[i] = array[j];
   array[j] = temp;
  } else {
   return j;
  }
 }
}

variable_types:
array
long *

variable_types: start int

variable_types: end int

variable_types: pivot int

variable_types: i int

variable_types: j int

variable_types: temp long


decompiled_code:
__int64 __fastcall qs_helper(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v5; // ebx
__int64 v6; // rsi

result = qs_partition(a1, a2, a3);
v5 = result;
if ( a2 < (int)result )
result = qs_helper(a1, (unsigned int)a2, (unsigned int)result);
v6 = (unsigned int)(v5 + 1);
if ( (int)v6 < a3 )
result = qs_helper(a1, v6, (unsigned int)a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v5; // ebx
__int64 v6; // rsi

result = func0(a1, a2, a3);
v5 = result;
if ( a2 < (int)result )
result = func1(a1, (unsigned int)a2, (unsigned int)result);
v6 = (unsigned int)(v5 + 1);
if ( (int)v6 < a3 )
result = func1(a1, v6, (unsigned int)a3);
return result;
}

original_code:
void qs_helper (long *array, int start, int end) {
 int split = qs_partition(array, start, end);
 if (start < split) {
  qs_helper(array, start, split);
 }
 if (end > split + 1) {
  qs_helper(array, split + 1, end);
 }
}

canonical_original_code:
void qs_helper(long *array, int start, int end) {
 int split = qs_partition(array, start, end);
 if (start < split) {
  qs_helper(array, start, split);
 }
 if (end > split + 1) {
  qs_helper(array, split + 1, end);
 }
}

variable_types: split int


quicksort

decompiled_code:
__int64 __fastcall quicksort(__int64 a1, int a2)
{
return qs_helper(a1, 0, a2 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return func1(a1, 0, a2 - 1);
}

original_code:
void quicksort (long *array, int length) {
 qs_helper(array, 0, length - 1);
}

canonical_original_code:
void quicksort(long *array, int length) {
 qs_helper(array, 0, length - 1);
}

variable_types: length int


startguesser

decompiled_code:
__int64 __fastcall startguesser(_DWORD *a1, const char *a2, __int64 a3, __int64 a4)
{
__pid_t v6; // eax
unsigned int v7; // ebx
int v9[2]; // [rsp+8h] [rbp-40h] BYREF
int v10[2]; // [rsp+10h] [rbp-38h] BYREF
int pipedes[2]; // [rsp+18h] [rbp-30h] BYREF

if ( pipe(pipedes) == -1 || pipe(v10) == -1 || pipe(v9) == -1 )
{
perror("Error creating pipes");
exit(1);
}
v6 = fork();
v7 = v6;
if ( !v6 )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
dup2(v10[1], 1);
close(v10[0]);
close(v10[1]);
dup2(v9[1], 2);
close(v9[0]);
close(v9[1]);
if ( execl(a2, a2, a3, a4, 0LL) != -1 )
exit(0);
perror("Error executing guesser");
exit(1);
}
if ( v6 == -1 )
{
perror("Error forking");
exit(1);
}
*a1 = pipedes[1];
close(pipedes[0]);
a1[1] = v10[0];
close(v10[1]);
a1[2] = v9[0];
close(v9[1]);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, const char *a2, __int64 a3, __int64 a4)
{
__pid_t v6; // eax
unsigned int v7; // ebx
int v9[2]; // [rsp+8h] [rbp-40h] BYREF
int v10[2]; // [rsp+10h] [rbp-38h] BYREF
int pipedes[2]; // [rsp+18h] [rbp-30h] BYREF

if ( pipe(pipedes) == -1 || pipe(v10) == -1 || pipe(v9) == -1 )
{
perror("Error creating pipes");
exit(1);
}
v6 = fork();
v7 = v6;
if ( !v6 )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
dup2(v10[1], 1);
close(v10[0]);
close(v10[1]);
dup2(v9[1], 2);
close(v9[0]);
close(v9[1]);
if ( execl(a2, a2, a3, a4, 0LL) != -1 )
exit(0);
perror("Error executing guesser");
exit(1);
}
if ( v6 == -1 )
{
perror("Error forking");
exit(1);
}
*a1 = pipedes[1];
close(pipedes[0]);
a1[1] = v10[0];
close(v10[1]);
a1[2] = v9[0];
close(v9[1]);
return v7;
}

original_code:
pid_t startguesser (int fd[3], char *path, char *file, char *str) {
 int infd[2], outfd[2], errfd[2];
 if (pipe(infd) == -1 || pipe(outfd) == -1 || pipe(errfd) == -1) {
  perror("Error creating pipes");
  exit(1);
 }
 pid_t child;
 if (!(child = fork())) {
  dup2(infd[0], 0);
    close(infd[0]);
    close(infd[1]);
  dup2(outfd[1], 1);
    close(outfd[0]);
    close(outfd[1]);
  dup2(errfd[1], 2);
    close(errfd[0]);
    close(errfd[1]);
  if (execl(path, path, file, str, ((void *)0)) == -1) {
   perror("Error executing guesser");
   exit(1);
  }
  exit(0);
 }
 if (child == -1) {
  perror("Error forking");
  exit(1);
 }
 fd[0] = infd[1];
   close(infd[0]);
 fd[1] = outfd[0];
   close(outfd[1]);
 fd[2] = errfd[0];
   close(errfd[1]);
 return child;
}

canonical_original_code:
int startguesser(int fd[3], char *path, char *file, char *str) {
 int infd[2]; int outfd[2]; int errfd[2];
 if (pipe(infd) == -1 || pipe(outfd) == -1 || pipe(errfd) == -1) {
  perror("Error creating pipes");
  exit(1);
 }
 int child;
 if (!(child = fork())) {
  dup2(infd[0], 0);
    close(infd[0]);
    close(infd[1]);
  dup2(outfd[1], 1);
    close(outfd[0]);
    close(outfd[1]);
  dup2(errfd[1], 2);
    close(errfd[0]);
    close(errfd[1]);
  if (execl(path, path, file, str, ((void *)0)) == -1) {
   perror("Error executing guesser");
   exit(1);
  }
  exit(0);
 }
 if (child == -1) {
  perror("Error forking");
  exit(1);
 }
 fd[0] = infd[1];
   close(infd[0]);
 fd[1] = outfd[0];
   close(outfd[1]);
 fd[2] = errfd[0];
   close(errfd[1]);
 return child;
}

variable_types:
fd
int [3]

variable_types:
path
char *

variable_types:
file
char *

variable_types:
str
char *

variable_types:
infd
int [2]

variable_types:
outfd
int [2]

variable_types:
errfd
int [2]

variable_types: child int


findthreshhold

decompiled_code:
__int64 __fastcall findthreshhold(_QWORD *a1, int a2)
{
void *v2; // rsp
float v3; // xmm0_4
__int64 v4; // rax
int v5; // edx
float v6; // xmm1_4
_BYTE v8[3]; // [rsp+0h] [rbp-20h] BYREF
char v9[29]; // [rsp+3h] [rbp-1Dh] BYREF

v2 = alloca(4LL * a2);
variance(a1, (__int64)v8, a2);
v3 = *((float *)&loc_4 + ((unsigned __int64)v9 >> 2)) - *(float *)(4 * ((unsigned __int64)v9 >> 2));
v4 = 2LL;
do
{
v5 = v4;
v6 = v3;
v3 = *(float *)&v8[4 * v4] - *(float *)&v8[4 * v4 - 4];
++v4;
}
while ( v3 >= v6 );
return a1[v5 - 1];
}

original_code:
int findthreshhold (long *in, int length) {
 float variances[length];
 variance(in, variances, length);
 int i = 1;
 float dold, dnew;
 dnew = variances[1] - variances[0];
 do {
  ++i;
  dold = dnew;
  dnew = variances[i] - variances[i - 1];
 } while (dnew >= dold);
 return in[i - 1];
}

canonical_original_code:
int findthreshhold(long *in, int length) {
 float variances[-1];
 variance(in, variances, length);
 int i = 1;
 float dold; float dnew;
 dnew = variances[1] - variances[0];
 do {
  ++i;
  dold = dnew;
  dnew = variances[i] - variances[i - 1];
 } while (dnew >= dold);
 return in[i - 1];
}

variable_types:
in
long *

variable_types:
variances
float [-1]

variable_types: dold float

variable_types: dnew float


markoutliers

decompiled_code:
__int64 __fastcall markoutliers(void *src, __int64 a2, int a3)
{
__int64 v4; // rdx
void *v5; // rsp
__int64 result; // rax
int v7; // ecx
_QWORD v8[4]; // [rsp+0h] [rbp-20h] BYREF

v4 = 8LL * a3;
v5 = alloca(v4);
memcpy(v8, src, v4);
quicksort((__int64)v8, a3);
result = findthreshhold(v8, a3);
if ( a3 > 0 )
{
v7 = result;
result = 0LL;
do
{
if ( *((_QWORD *)src + result) >= v7 )
*(_BYTE *)(a2 + result) = 0;
++result;
}
while ( result != a3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *src, __int64 a2, int a3)
{
__int64 v4; // rdx
void *v5; // rsp
__int64 result; // rax
int v7; // ecx
_QWORD v8[4]; // [rsp+0h] [rbp-20h] BYREF

v4 = 8LL * a3;
v5 = alloca(v4);
memcpy(v8, src, v4);
func2((__int64)v8, a3);
result = func6(v8, a3);
if ( a3 > 0 )
{
v7 = result;
result = 0LL;
do
{
if ( *((_QWORD *)src + result) >= v7 )
*(_BYTE *)(a2 + result) = 0;
++result;
}
while ( result != a3 );
}
return result;
}

original_code:
void markoutliers (long *in, unsigned char *out, int length) {
 long sorted[length];
 memcpy(sorted, in, length * sizeof(long));
 quicksort(sorted, length);
 int threshhold = findthreshhold(sorted, length);
 int i;
 for (i = 0; i < length; ++i) {
  if (in[i] >= threshhold) {
   out[i] = 0;
  }
 }
}

canonical_original_code:
void markoutliers(long *in, unsigned char *out, int length) {
 long sorted[-1];
 memcpy(sorted, in, length * sizeof(long));
 quicksort(sorted, length);
 int threshhold = findthreshhold(sorted, length);
 int i;
 for (i = 0; i < length; ++i) {
  if (in[i] >= threshhold) {
   out[i] = 0;
  }
 }
}

variable_types:
out
unsigned char *

variable_types:
sorted
long [-1]

variable_types: threshhold int

variable_types: i int


guesschar

original_code:
char guesschar (char *path, char *file, char *known, char *charlist) {
 int numchars = strlen(charlist);
 int index = strlen(known);
 long times[numchars];
 unsigned char possibilities[numchars];
 known[index + 1] = '!';
 known[index + 2] = '\0';
 int i;
 for (i = 0; i < numchars; ++i) {
  possibilities[i] = 1;
 }
 int correct, firstwrong, isincorrect;
 int pass = 0;
 while ((correct = findcorrect(possibilities, numchars)) < 0 && pass <= 5) {
  isincorrect = 1;
  for (i = 0; i < numchars; ++i) {
   if (possibilities[i]) {
    known[index] = charlist[i];
    times[i] = teststring(path, file, known, &firstwrong);
    if (firstwrong == index) {
     isincorrect = 0;
    }
   }
  }
  if (isincorrect) {
   if (index == 0) {
    known[index] = '\0';
    return -2;
   } else {
    known[index - 1] = '\0';
    return -1;
   }
  }
  markoutliers(times, possibilities, numchars);
  ++pass;
 }
 if (correct < 0) {
  known[index] = '\0';
  return 0;
 } else {
  known[index + 1] = '\0';
  known[index] = charlist[correct];
  return charlist[correct];
 }
}

canonical_original_code:
char guesschar(char *path, char *file, char *known, char *charlist) {
 int numchars = strlen(charlist);
 int index = strlen(known);
 long times[-1];
 unsigned char possibilities[-1];
 known[index + 1] = '!';
 known[index + 2] = '\0';
 int i;
 for (i = 0; i < numchars; ++i) {
  possibilities[i] = 1;
 }
 int correct; int firstwrong; int isincorrect;
 int pass = 0;
 while ((correct = findcorrect(possibilities, numchars)) < 0 && pass <= 5) {
  isincorrect = 1;
  for (i = 0; i < numchars; ++i) {
   if (possibilities[i]) {
    known[index] = charlist[i];
    times[i] = teststring(path, file, known, &firstwrong);
    if (firstwrong == index) {
     isincorrect = 0;
    }
   }
  }
  if (isincorrect) {
   if (index == 0) {
    known[index] = '\0';
    return -2;
   } else {
    known[index - 1] = '\0';
    return -1;
   }
  }
  markoutliers(times, possibilities, numchars);
  ++pass;
 }
 if (correct < 0) {
  known[index] = '\0';
  return 0;
 } else {
  known[index + 1] = '\0';
  known[index] = charlist[correct];
  return charlist[correct];
 }
}

variable_types:
known
char *

variable_types:
charlist
char *

variable_types: numchars int

variable_types: index int

variable_types:
times
long [-1]

variable_types:
possibilities
unsigned char [-1]

variable_types: correct int

variable_types: firstwrong int

variable_types: isincorrect int

variable_types: pass int

return_type: char


findstring

decompiled_code:
char *__fastcall findstring(const char *a1, __int64 a2, const char *a3)
{
char *v4; // r12
int v5; // ebp
char v6; // al
char v7; // bl
char v8; // al

v4 = (char *)malloc(0x64uLL);
*v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = guesschar(a1, a2, v4, a3);
v7 = v6;
if ( v5 > 97 || !v6 )
return 0LL;
v8 = checkstring(a1, a2, (__int64)v4);
if ( v8 == 1 )
return v4;
if ( v8 == 2 )
{
LABEL_2:
free(v4);
return 0LL;
}
if ( v7 < 0 )
{
if ( v7 != -1 )
goto LABEL_2;
--v5;
}
else
{
++v5;
}
}
}

canonical_decompiled_code:
char *__fastcall func9(const char *a1, __int64 a2, const char *a3)
{
char *v4; // r12
int v5; // ebp
char v6; // al
char v7; // bl
char v8; // al

v4 = (char *)malloc(0x64uLL);
*v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = func8(a1, a2, v4, a3);
v7 = v6;
if ( v5 > 97 || !v6 )
return 0LL;
v8 = func5(a1, a2, (__int64)v4);
if ( v8 == 1 )
return v4;
if ( v8 == 2 )
{
LABEL_2:
free(v4);
return 0LL;
}
if ( v7 < 0 )
{
if ( v7 != -1 )
goto LABEL_2;
--v5;
}
else
{
++v5;
}
}
}

original_code:
char *findstring (char *path, char *file, char *charlist) {
 char *str = (char*)malloc(100);
 str[0] = '\0';
 int length = 0;
 char current;
 unsigned char result;
 while ((current = guesschar(path, file, str, charlist)) != 0 && length < 100 - 2) {
  result = checkstring(path, file, str);
  if (result == 1) {
   return str;
  } else if (result == 2) {
   free(str);
   return 0;
  }
  if (current >= 0) {
   ++length;
  } else if (current == -1) {
   --length;
  } else {
   free(str);
   return 0;
  }
 }
 return 0;
}

canonical_original_code:
char *findstring(char *path, char *file, char *charlist) {
 char *str = (char*)malloc(100);
 str[0] = '\0';
 int length = 0;
 char current;
 unsigned char result;
 while ((current = guesschar(path, file, str, charlist)) != 0 && length < 100 - 2) {
  result = checkstring(path, file, str);
  if (result == 1) {
   return str;
  } else if (result == 2) {
   free(str);
   return 0;
  }
  if (current >= 0) {
   ++length;
  } else if (current == -1) {
   --length;
  } else {
   free(str);
   return 0;
  }
 }
 return 0;
}

variable_types:
path
char *

variable_types:
file
char *

variable_types:
str
char *

variable_types: length int

variable_types: current char

variable_types:
result
unsigned char

return_type: char *


repo: tcheneau/RplIcmp

decompiled_code:
__int64 enable_capability_raw()
{
return modify_capability(13LL, 1LL);
}

canonical_decompiled_code:
__int64 func0()
{
return modify_capability(13LL, 1LL);
}

original_code: static inline int enable_capability_raw(void) { return modify_capability(13, CAP_SET); }

canonical_original_code: static inline int enable_capability_raw() { return modify_capability(13, CAP_SET); }


decompiled_code:
__int64 disable_capability_raw()
{
return modify_capability(13LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
return modify_capability(13LL, 0LL);
}

original_code: static inline int disable_capability_raw(void) { return modify_capability(13, CAP_CLEAR); }

canonical_original_code: static inline int disable_capability_raw() { return modify_capability(13, CAP_CLEAR); }


decompiled_code:
__int64 init_capability()
{
return limit_capabilities();
}

canonical_decompiled_code:
__int64 func3()
{
return limit_capabilities();
}

original_code: int init_capability(void) { return limit_capabilities(); }

canonical_original_code: int init_capability() { return limit_capabilities(); }


dropCapabilities

decompiled_code:
__int64 dropCapabilities()
{
return drop_capabilities();
}

canonical_decompiled_code:
__int64 func4()
{
return drop_capabilities();
}

original_code: int dropCapabilities(void) { return drop_capabilities(); }

canonical_original_code: int dropCapabilities() { return drop_capabilities(); }


createSocket

decompiled_code:
__int64 __fastcall createSocket(char *ifname, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v6; // ebx
bool v7; // cf
bool v8; // zf
__int64 v9; // rcx
const char *v10; // rdi
char *v11; // rsi
socklen_t v12; // eax
__m128i v14; // [rsp+0h] [rbp-48h] BYREF
__m128i v15; // [rsp+10h] [rbp-38h] BYREF
unsigned int v16; // [rsp+20h] [rbp-28h]
int v17; // [rsp+28h] [rbp-20h] BYREF
int optval[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

optval[0] = 0xFFFF;
v14 = 0uLL;
v15 = 0uLL;
v16 = 0;
v6 = enable_capability_raw(ifname, a2, a3, a4, a5);
if ( v6 != -1 )
{
v6 = socket(10, 3, 58);
v9 = 7LL;
v10 = "unspec";
v11 = ifname;
do
{
if ( !v9 )
break;
v7 = (unsigned __int8)*v11 < (unsigned int)*v10;
v8 = *v11++ == *v10++;
--v9;
}
while ( v8 );
if ( (!v7 && !v8) == v7
|| (v12 = strlen(ifname),
v11 = (_BYTE *)(enable_capability_raw + 1),
v10 = (const char *)v6,
setsockopt(v6, 1, 25, ifname, v12) >= 0) )
{
if ( (unsigned int)disable_capability_raw(v10, v11) == -1 )
return (unsigned int)-1;
if ( v6 == -1 )
{
perror("socket() fails");
return v6;
}
if ( setsockopt(v6, 1, 8, optval, 4u) < 0 )
{
perror("setsockopt(SO_RCVBUF)");
}
else
{
v17 = 1;
if ( setsockopt(v6, 41, 49, &v17, 4u) < 0 )
{
perror("setsockopt(IP_PKTINFO)");
}
else if ( inet_pton(10, "ff02::1a", &v14) )
{
v15 = _mm_loadu_si128(&v14);
v16 = if_nametoindex(ifname);
if ( setsockopt(v6, 41, 20, &v15, 0x14u) < 0 )
{
perror("setsockopt(IPV6_JOIN_GROUP)");
}
else
{
v17 = 255;
if ( setsockopt(v6, 41, 16, &v17, 4u) < 0 )
{
perror("setsockopt(IPV6_UNICAST_HOPS)");
}
else
{
if ( setsockopt(v6, 41, 18, &v17, 4u) >= 0 )
return v6;
perror("setsockopt(IPV6_MULTICAST_HOPS");
}
}
}
else
{
perror("inet_pton");
}
}
}
else
{
perror("setsockopt(SO_BINTDODEVICE)");
}
close(v6);
v6 = -1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *ifname, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v6; // ebx
bool v7; // cf
bool v8; // zf
__int64 v9; // rcx
const char *v10; // rdi
char *v11; // rsi
socklen_t v12; // eax
__m128i v14; // [rsp+0h] [rbp-48h] BYREF
__m128i v15; // [rsp+10h] [rbp-38h] BYREF
unsigned int v16; // [rsp+20h] [rbp-28h]
int v17; // [rsp+28h] [rbp-20h] BYREF
int optval[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

optval[0] = 0xFFFF;
v14 = 0uLL;
v15 = 0uLL;
v16 = 0;
v6 = func0(ifname, a2, a3, a4, a5);
if ( v6 != -1 )
{
v6 = socket(10, 3, 58);
v9 = 7LL;
v10 = "unspec";
v11 = ifname;
do
{
if ( !v9 )
break;
v7 = (unsigned __int8)*v11 < (unsigned int)*v10;
v8 = *v11++ == *v10++;
--v9;
}
while ( v8 );
if ( (!v7 && !v8) == v7
|| (v12 = strlen(ifname),
v11 = (_BYTE *)(enable_capability_raw + 1),
v10 = (const char *)v6,
setsockopt(v6, 1, 25, ifname, v12) >= 0) )
{
if ( (unsigned int)func1(v10, v11) == -1 )
return (unsigned int)-1;
if ( v6 == -1 )
{
perror("socket() fails");
return v6;
}
if ( setsockopt(v6, 1, 8, optval, 4u) < 0 )
{
perror("setsockopt(SO_RCVBUF)");
}
else
{
v17 = 1;
if ( setsockopt(v6, 41, 49, &v17, 4u) < 0 )
{
perror("setsockopt(IP_PKTINFO)");
}
else if ( inet_pton(10, "ff02::1a", &v14) )
{
v15 = _mm_loadu_si128(&v14);
v16 = if_nametoindex(ifname);
if ( setsockopt(v6, 41, 20, &v15, 0x14u) < 0 )
{
perror("setsockopt(IPV6_JOIN_GROUP)");
}
else
{
v17 = 255;
if ( setsockopt(v6, 41, 16, &v17, 4u) < 0 )
{
perror("setsockopt(IPV6_UNICAST_HOPS)");
}
else
{
if ( setsockopt(v6, 41, 18, &v17, 4u) >= 0 )
return v6;
perror("setsockopt(IPV6_MULTICAST_HOPS");
}
}
}
else
{
perror("inet_pton");
}
}
}
else
{
perror("setsockopt(SO_BINTDODEVICE)");
}
close(v6);
v6 = -1;
}
return v6;
}

original_code:
int createSocket(char * iface)
{
 int icmp_sock = 0;
 int hold = 65535;
 int sockopt;
 int err;
    struct ipv6_mreq mreq6;
    struct in6_addr mcast_group;
    memset(&mcast_group, 0, sizeof(mcast_group));
    memset(&mreq6, 0, sizeof(mreq6));
 if (enable_capability_raw() == -1)
  return -1;
 icmp_sock = socket(10, SOCK_RAW, IPPROTO_ICMPV6);
    if (strncmp(iface, "unspec", sizeof("unspec")) != 0)
    {
     err = setsockopt(icmp_sock, 1, 25, iface, strlen(iface));
     if (err < 0) {
      perror("setsockopt(SO_BINTDODEVICE)");
      goto error;
     }
    }
 if (disable_capability_raw() == -1)
  return -1;
 if (icmp_sock == -1)
 {
  perror("socket() fails");
  return icmp_sock;
 }
 err = setsockopt(icmp_sock, 1, 8, (char *)&hold, sizeof(hold));
 if (err < 0) {
        perror("setsockopt(SO_RCVBUF)");
  goto error;
 }
    sockopt = 1;
    err = setsockopt(icmp_sock, IPPROTO_IPV6, 49, &sockopt, sizeof(sockopt));
 if (err < 0) {
        perror("setsockopt(IP_PKTINFO)");
        goto error;
    }
    err = inet_pton(10, "ff02::1a", &mcast_group);
    if (err == 0) {
        perror("inet_pton");
        goto error;
    }
    memcpy(&mreq6.ipv6mr_multiaddr, &mcast_group, sizeof(struct in6_addr));
    mreq6.ipv6mr_interface = if_nametoindex(iface);
    err = setsockopt(icmp_sock, 41, 20, &mreq6, sizeof(mreq6));
    if (err < 0) {
        perror("setsockopt(IPV6_JOIN_GROUP)");
        goto error;
    }
    sockopt = 255;
    err = setsockopt(icmp_sock, IPPROTO_IPV6, 16, &sockopt, sizeof(sockopt));
    if (err < 0)
    {
        perror("setsockopt(IPV6_UNICAST_HOPS)");
        goto error;
    }
    err = setsockopt(icmp_sock, IPPROTO_IPV6, 18, &sockopt, sizeof(sockopt));
    if (err < 0)
    {
        perror("setsockopt(IPV6_MULTICAST_HOPS");
        goto error;
    }
 return icmp_sock;
error:
 close(icmp_sock);
 return -1;
}

canonical_original_code:
int createSocket(char *iface)
{
 int icmp_sock = 0;
 int hold = 65535;
 int sockopt;
 int err;
    struct ipv6_mreq mreq6;
    struct in6_addr mcast_group;
    memset(&mcast_group, 0, sizeof(mcast_group));
    memset(&mreq6, 0, sizeof(mreq6));
 if (enable_capability_raw() == -1)
  return -1;
 icmp_sock = socket(10, SOCK_RAW, IPPROTO_ICMPV6);
    if (strncmp(iface, "unspec", sizeof("unspec")) != 0)
    {
     err = setsockopt(icmp_sock, 1, 25, iface, strlen(iface));
     if (err < 0) {
      perror("setsockopt(SO_BINTDODEVICE)");
      goto error;
     }
    }
 if (disable_capability_raw() == -1)
  return -1;
 if (icmp_sock == -1)
 {
  perror("socket() fails");
  return icmp_sock;
 }
 err = setsockopt(icmp_sock, 1, 8, (char *)&hold, sizeof(hold));
 if (err < 0) {
        perror("setsockopt(SO_RCVBUF)");
  goto error;
 }
    sockopt = 1;
    err = setsockopt(icmp_sock, IPPROTO_IPV6, 49, &sockopt, sizeof(sockopt));
 if (err < 0) {
        perror("setsockopt(IP_PKTINFO)");
        goto error;
    }
    err = inet_pton(10, "ff02::1a", &mcast_group);
    if (err == 0) {
        perror("inet_pton");
        goto error;
    }
    memcpy(&mreq6.ipv6mr_multiaddr, &mcast_group, sizeof(struct in6_addr));
    mreq6.ipv6mr_interface = if_nametoindex(iface);
    err = setsockopt(icmp_sock, 41, 20, &mreq6, sizeof(mreq6));
    if (err < 0) {
        perror("setsockopt(IPV6_JOIN_GROUP)");
        goto error;
    }
    sockopt = 255;
    err = setsockopt(icmp_sock, IPPROTO_IPV6, 16, &sockopt, sizeof(sockopt));
    if (err < 0)
    {
        perror("setsockopt(IPV6_UNICAST_HOPS)");
        goto error;
    }
    err = setsockopt(icmp_sock, IPPROTO_IPV6, 18, &sockopt, sizeof(sockopt));
    if (err < 0)
    {
        perror("setsockopt(IPV6_MULTICAST_HOPS");
        goto error;
    }
 return icmp_sock;
error:
 close(icmp_sock);
 return -1;
}

variable_types:
iface
char *

variable_types: hold int

variable_types: sockopt int

variable_types: err int

variable_types: struct ipv6_mreq { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ipv6mr_multiaddr; unsigned int ipv6mr_interface; }

user_defined_types: struct ipv6_mreq { struct in6_addr ipv6mr_multiaddr; unsigned int ipv6mr_interface; }


sendMsg

decompiled_code:
ssize_t __fastcall sendMsg(int fd, char *name, void *buf, size_t n)
{
const __m128i *v6; // roff
ssize_t result; // rax
__m128i v8; // [rsp+0h] [rbp-88h] BYREF
__int64 v9; // [rsp+10h] [rbp-78h]
int v10; // [rsp+18h] [rbp-70h]
struct addrinfo *pai; // [rsp+28h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_flags = 0xA00000000LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(name, 0LL, &req, &pai) )
{
fwrite("unknown host\n", 1uLL, 0xDuLL, stderr);
result = 4294967294LL;
}
else
{
v6 = (const __m128i *)pai->ai_addr;
v8 = _mm_loadu_si128(v6);
v9 = v6[1].m128i_i64[0];
v10 = v6[1].m128i_i32[2];
freeaddrinfo(pai);
v8.m128i_i16[1] = _bswap_16(58);
result = sendto(fd, buf, n, 2048, (const struct sockaddr *)&v8, 0x1Cu);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func6(int fd, char *name, void *buf, size_t n)
{
const __m128i *v6; // roff
ssize_t result; // rax
__m128i v8; // [rsp+0h] [rbp-88h] BYREF
__int64 v9; // [rsp+10h] [rbp-78h]
int v10; // [rsp+18h] [rbp-70h]
struct addrinfo *pai; // [rsp+28h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_flags = 0xA00000000LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(name, 0LL, &req, &pai) )
{
fwrite("unknown host\n", 1uLL, 0xDuLL, stderr);
result = 4294967294LL;
}
else
{
v6 = (const __m128i *)pai->ai_addr;
v8 = _mm_loadu_si128(v6);
v9 = v6[1].m128i_i64[0];
v10 = v6[1].m128i_i32[2];
freeaddrinfo(pai);
v8.m128i_i16[1] = func2(58);
result = sendto(fd, buf, n, 2048, (const struct sockaddr *)&v8, 0x1Cu);
}
return result;
}

original_code:
int sendMsg(int icmp_sock, char * target, void * msg, size_t msg_len)
{
 int cc, gai;
 struct addrinfo hints, *ai;
 struct sockaddr_in6 whereto;
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 10;
 gai = getaddrinfo(target, ((void *)0), &hints, &ai);
 if (gai) {
  fprintf(stderr, "unknown host\n");
  return(-2);
 }
 memcpy(&whereto, ai->ai_addr, sizeof(whereto));
 freeaddrinfo(ai);
 whereto.sin6_port = htons(IPPROTO_ICMPV6);
 cc = sendto(icmp_sock, (char *) msg, msg_len, MSG_CONFIRM,
       (struct sockaddr *) &whereto,
       sizeof(struct sockaddr_in6));
 return cc;
}

canonical_original_code:
int sendMsg(int icmp_sock, char *target, void *msg, unsigned long msg_len)
{
 int cc; int gai;
 struct addrinfo hints; struct addrinfo *ai;
 struct sockaddr_in6 whereto;
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 10;
 gai = getaddrinfo(target, ((void *)0), &hints, &ai);
 if (gai) {
  fprintf(stderr, "unknown host\n");
  return(-2);
 }
 memcpy(&whereto, ai->ai_addr, sizeof(whereto));
 freeaddrinfo(ai);
 whereto.sin6_port = htons(IPPROTO_ICMPV6);
 cc = sendto(icmp_sock, (char *) msg, msg_len, MSG_CONFIRM,
       (struct sockaddr *) &whereto,
       sizeof(struct sockaddr_in6));
 return cc;
}

variable_types:
target
char *

variable_types:
msg
void *

variable_types: cc int

variable_types: gai int

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

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

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

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


recvMsg

decompiled_code:
__int64 __fastcall recvMsg(int fd, void *s, size_t a3, char *a4, socklen_t a5, char *a6, socklen_t len, __int64 a8, int a9)
{
unsigned int v12; // er13
struct cmsghdr *v13; // rbx
__int64 v15; // [rsp+0h] [rbp-8C8h] BYREF
__int64 v16[2]; // [rsp+800h] [rbp-C8h] BYREF
struct msghdr message; // [rsp+810h] [rbp-B8h] BYREF
__int64 v18; // [rsp+850h] [rbp-78h]
__int64 v19; // [rsp+858h] [rbp-70h]
__int64 v20; // [rsp+860h] [rbp-68h]
int v21; // [rsp+868h] [rbp-60h]
__int64 v22; // [rsp+870h] [rbp-58h] BYREF
__int64 cp[2]; // [rsp+878h] [rbp-50h] BYREF
int v24; // [rsp+888h] [rbp-40h]

v16[0] = (__int64)s;
v16[1] = a3;
message.msg_name = &v22;
message.msg_namelen = 28;
message.msg_iov = (iovec *)v16;
message.msg_iovlen = 1LL;
message.msg_flags = 0;
message.msg_control = &v15;
message.msg_controllen = 2048LL;
v22 = 0LL;
cp[0] = 0LL;
cp[1] = 0LL;
v24 = 0;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0;
memset(s, 0, a3);
v12 = recvmsg(fd, &message, (unsigned __int8)(a9 == 0) << 6);
inet_ntop(10, cp, a4, a5);
if ( message.msg_controllen > 0xF )
{
v13 = (struct cmsghdr *)message.msg_control;
if ( message.msg_control )
{
do
{
if ( *(_QWORD *)&v13->cmsg_level == 0x3200000029LL )
{
inet_ntop(10, v13->__cmsg_data, a6, len);
*(_DWORD *)a8 = *(_DWORD *)&v13->__cmsg_data[16];
}
v13 = _cmsg_nxthdr(&message, v13);
}
while ( v13 );
}
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *s, size_t a3, char *a4, socklen_t a5, char *a6, socklen_t len, __int64 a8, int a9)
{
unsigned int v12; // er13
struct cmsghdr *v13; // rbx
__int64 v15; // [rsp+0h] [rbp-8C8h] BYREF
__int64 v16[2]; // [rsp+800h] [rbp-C8h] BYREF
struct msghdr message; // [rsp+810h] [rbp-B8h] BYREF
__int64 v18; // [rsp+850h] [rbp-78h]
__int64 v19; // [rsp+858h] [rbp-70h]
__int64 v20; // [rsp+860h] [rbp-68h]
int v21; // [rsp+868h] [rbp-60h]
__int64 v22; // [rsp+870h] [rbp-58h] BYREF
__int64 cp[2]; // [rsp+878h] [rbp-50h] BYREF
int v24; // [rsp+888h] [rbp-40h]

v16[0] = (__int64)s;
v16[1] = a3;
message.msg_name = &v22;
message.msg_namelen = 28;
message.msg_iov = (iovec *)v16;
message.msg_iovlen = 1LL;
message.msg_flags = 0;
message.msg_control = &v15;
message.msg_controllen = 2048LL;
v22 = 0LL;
cp[0] = 0LL;
cp[1] = 0LL;
v24 = 0;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0;
memset(s, 0, a3);
v12 = recvmsg(fd, &message, (unsigned __int8)(a9 == 0) << 6);
inet_ntop(10, cp, a4, a5);
if ( message.msg_controllen > 0xF )
{
v13 = (struct cmsghdr *)message.msg_control;
if ( message.msg_control )
{
do
{
if ( *(_QWORD *)&v13->cmsg_level == 0x3200000029LL )
{
inet_ntop(10, v13->__cmsg_data, a6, len);
*(_DWORD *)a8 = *(_DWORD *)&v13->__cmsg_data[16];
}
v13 = _cmsg_nxthdr(&message, v13);
}
while ( v13 );
}
}
return v12;
}

original_code:
int recvMsg(int icmp_sock, char * buffer, size_t buflen, char * from, socklen_t from_len, char * to, socklen_t to_len, unsigned int * if_idx, int blocking)
{
 struct sockaddr_in6 from_sock;
 struct sockaddr_in6 to_sock;
 struct msghdr msg;
 struct iovec iov;
 struct cmsghdr * cmsg;
 u_char cbuf[2048];
 struct in6_pktinfo *pi = ((void *)0);
 int cc;
 iov.iov_base = buffer;
 iov.iov_len = buflen;
 msg.msg_name = &from_sock;
 msg.msg_namelen = sizeof(struct sockaddr_in6);
 msg.msg_iov = & iov;
 msg.msg_iovlen = 1;
 msg.msg_flags = 0;
 msg.msg_control = cbuf;
 msg.msg_controllen = sizeof(cbuf);
 memset((void *) &from_sock, 0, sizeof(struct sockaddr_in6));
 memset((void *) &to_sock, 0, sizeof(struct sockaddr_in6));
 memset((void *) buffer, 0, buflen);
 cc = recvmsg(icmp_sock, &msg, blocking ? 0: MSG_DONTWAIT);
    inet_ntop(10, (void *) &from_sock.sin6_addr, from, from_len);
 for (cmsg = ((size_t) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);cmsg; cmsg = __cmsg_nxthdr (&msg, cmsg))
 {
     if (cmsg->cmsg_level != IPPROTO_IPV6 ||
         cmsg->cmsg_type != 50)
          continue;
  pi = (struct in6_pktinfo *) ((cmsg)->__cmsg_data);
  inet_ntop(10, &pi->ipi6_addr, to, to_len);
  * if_idx = pi->ipi6_ifindex;
 }
 return cc;
}

canonical_original_code:
int recvMsg(int icmp_sock, char *buffer, unsigned long buflen, char *from, unsigned int from_len, char *to, unsigned int to_len, unsigned int *if_idx, int blocking)
{
 struct sockaddr_in6 from_sock;
 struct sockaddr_in6 to_sock;
 struct msghdr msg;
 struct iovec iov;
 struct cmsghdr *cmsg;
 unsigned char cbuf[2048];
 struct in6_pktinfo *pi = ((void *)0);
 int cc;
 iov.iov_base = buffer;
 iov.iov_len = buflen;
 msg.msg_name = &from_sock;
 msg.msg_namelen = sizeof(struct sockaddr_in6);
 msg.msg_iov = & iov;
 msg.msg_iovlen = 1;
 msg.msg_flags = 0;
 msg.msg_control = cbuf;
 msg.msg_controllen = sizeof(cbuf);
 memset((void *) &from_sock, 0, sizeof(struct sockaddr_in6));
 memset((void *) &to_sock, 0, sizeof(struct sockaddr_in6));
 memset((void *) buffer, 0, buflen);
 cc = recvmsg(icmp_sock, &msg, blocking ? 0: MSG_DONTWAIT);
    inet_ntop(10, (void *) &from_sock.sin6_addr, from, from_len);
 for (cmsg = ((unsigned long) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);cmsg; cmsg = __cmsg_nxthdr (&msg, cmsg))
 {
     if (cmsg->cmsg_level != IPPROTO_IPV6 ||
         cmsg->cmsg_type != 50)
          continue;
  pi = (struct in6_pktinfo *) ((cmsg)->__cmsg_data);
  inet_ntop(10, &pi->ipi6_addr, to, to_len);
  * if_idx = pi->ipi6_ifindex;
 }
 return cc;
}

variable_types:
buffer
char *

variable_types:
buflen
unsigned long

variable_types:
from
char *

variable_types:
to
char *

variable_types: blocking int

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types:
cbuf
unsigned char [2048]

variable_types: struct in6_pktinfo { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ipi6_addr; unsigned int ipi6_ifindex; } *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct in6_pktinfo { struct in6_addr ipi6_addr; unsigned int ipi6_ifindex; }


initICMPFilter

decompiled_code:
void __fastcall initICMPFilter(_QWORD *a1)
{
*a1 = -1LL;
a1[1] = -1LL;
a1[2] = -1LL;
a1[3] = -1LL;
}

original_code:
void initICMPFilter(struct icmp6_filter * filter)
{
 memset (filter, 0xFF, sizeof (struct icmp6_filter));;
}

canonical_original_code:
void initICMPFilter(struct icmp6_filter *filter)
{
 memset (filter, 0xFF, sizeof (struct icmp6_filter));;
}

variable_types: struct icmp6_filter { unsigned int icmp6_filt[8]; } *


allowTypeICMPfilter

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

result = (unsigned int)~(1 << a2);
*(_DWORD *)(a1 + 4LL * (a2 >> 5)) &= result;
return result;
}

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

result = (unsigned int)~(1 << a2);
*(_DWORD *)(a1 + 4LL * (a2 >> 5)) &= result;
return result;
}

original_code:
void allowTypeICMPfilter(struct icmp6_filter * filter, int type)
{
 ((((filter)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))));
}

canonical_original_code:
void allowTypeICMPfilter(struct icmp6_filter *filter, int type)
{
 ((((filter)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))));
}

variable_types: type int

user_defined_types: struct icmp6_filter { unsigned int icmp6_filt[8]; }


enableICMPfilter

decompiled_code:
__int64 __fastcall enableICMPfilter(int fd, void *s2)
{
int v2; // eax
int v3; // ebx
socklen_t optlen; // [rsp+Ch] [rbp-3Ch] BYREF
char optval[56]; // [rsp+10h] [rbp-38h] BYREF

optlen = 32;
v2 = setsockopt(fd, 58, 1, s2, 0x20u);
if ( v2 < 0 )
{
v3 = v2;
perror("setsockopt(ICMP6_FILTER)");
}
else
{
v3 = getsockopt(fd, 58, 1, optval, &optlen);
if ( v3 < 0 )
perror("getsockopt(ICMP6_FILTER)");
else
v3 = memcmp(optval, s2, 0x20uLL);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, void *s2)
{
int v2; // eax
int v3; // ebx
socklen_t optlen; // [rsp+Ch] [rbp-3Ch] BYREF
char optval[56]; // [rsp+10h] [rbp-38h] BYREF

optlen = 32;
v2 = setsockopt(fd, 58, 1, s2, 0x20u);
if ( v2 < 0 )
{
v3 = v2;
perror("setsockopt(ICMP6_FILTER)");
}
else
{
v3 = getsockopt(fd, 58, 1, optval, &optlen);
if ( v3 < 0 )
perror("getsockopt(ICMP6_FILTER)");
else
v3 = memcmp(optval, s2, 0x20uLL);
}
return (unsigned int)v3;
}

original_code:
int enableICMPfilter(int icmp_sock, struct icmp6_filter * filter)
{
 int err;
 struct icmp6_filter applied_filter;
 socklen_t applied_filter_len = sizeof(struct icmp6_filter);
 err = setsockopt(icmp_sock, IPPROTO_ICMPV6, 1, filter,
    sizeof(struct icmp6_filter));
 if (err < 0) {
  perror("setsockopt(ICMP6_FILTER)");
  return err;
 }
 err = getsockopt(icmp_sock, IPPROTO_ICMPV6, 1, &applied_filter,
   &applied_filter_len);
 if (err <0)
 {
  perror("getsockopt(ICMP6_FILTER)");
  return err;
 }
 return memcmp(&applied_filter, filter, sizeof(struct icmp6_filter));
}

canonical_original_code:
int enableICMPfilter(int icmp_sock, struct icmp6_filter *filter)
{
 int err;
 struct icmp6_filter applied_filter;
 unsigned int applied_filter_len = sizeof(struct icmp6_filter);
 err = setsockopt(icmp_sock, IPPROTO_ICMPV6, 1, filter,
    sizeof(struct icmp6_filter));
 if (err < 0) {
  perror("setsockopt(ICMP6_FILTER)");
  return err;
 }
 err = getsockopt(icmp_sock, IPPROTO_ICMPV6, 1, &applied_filter,
   &applied_filter_len);
 if (err <0)
 {
  perror("getsockopt(ICMP6_FILTER)");
  return err;
 }
 return memcmp(&applied_filter, filter, sizeof(struct icmp6_filter));
}

variable_types: err int

variable_types: struct icmp6_filter { unsigned int icmp6_filt[8]; }


repo: tchetch/XComp

decompiled_code:
_BOOL8 __fastcall sys_check_file(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

original_code:
int sys_check_file(const char * path)
{
    int ret = 0;
    struct stat buffer;
    if(stat(path, &buffer) == 0) {
        if(((((buffer.st_mode)) & 0170000) == (0100000))) {
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int sys_check_file(char *path)
{
    int ret = 0;
    struct stat buffer;
    if(stat(path, &buffer) == 0) {
        if(((((buffer.st_mode)) & 0170000) == (0100000))) {
            ret = 1;
        }
    }
    return ret;
}

variable_types:
path
char *

variable_types: ret int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall sys_mutex_init(pthread_mutex_t **a1)
{
__int64 result; // rax
pthread_mutex_t *v3; // rdi

result = 0LL;
if ( a1 )
{
v3 = (pthread_mutex_t *)malloc(0x28uLL);
*a1 = v3;
if ( v3 )
{
pthread_mutex_init(v3, 0LL);
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_mutex_t **a1)
{
__int64 result; // rax
pthread_mutex_t *v3; // rdi

result = 0LL;
if ( a1 )
{
v3 = (pthread_mutex_t *)malloc(0x28uLL);
*a1 = v3;
if ( v3 )
{
pthread_mutex_init(v3, 0LL);
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int sys_mutex_init(pthread_mutex_t ** mtx)
{
    int ret = 0;
    if(mtx != ((void *)0)) {
        *mtx = malloc(sizeof(**mtx));
        if(*mtx != ((void *)0)) {
            pthread_mutex_init(*mtx, ((void *)0));
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int sys_mutex_init(union pthread_mutex_t **mtx)
{
    int ret = 0;
    if(mtx != ((void *)0)) {
        *mtx = malloc(sizeof(**mtx));
        if(*mtx != ((void *)0)) {
            pthread_mutex_init(*mtx, ((void *)0));
            ret = 1;
        }
    }
    return ret;
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } **

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall sys_mutex_lock(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1);
}

canonical_decompiled_code:
int __fastcall func3(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1);
}

original_code:
int sys_mutex_lock(pthread_mutex_t * mtx)
{
    return pthread_mutex_lock(mtx);
}

canonical_original_code:
int sys_mutex_lock(union pthread_mutex_t *mtx)
{
    return pthread_mutex_lock(mtx);
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *


decompiled_code:
int __fastcall sys_mutex_unlock(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1);
}

canonical_decompiled_code:
int __fastcall func4(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1);
}

original_code:
int sys_mutex_unlock(pthread_mutex_t * mtx)
{
    return pthread_mutex_unlock(mtx);
}

canonical_original_code:
int sys_mutex_unlock(union pthread_mutex_t *mtx)
{
    return pthread_mutex_unlock(mtx);
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
void __fastcall sys_mutex_destroy(void *ptr)
{
if ( ptr )
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( ptr )
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
}
}

original_code:
void sys_mutex_destroy(pthread_mutex_t * mtx)
{
    if(mtx != ((void *)0)) {
        pthread_mutex_destroy(mtx);
        free(mtx);
    }
}

canonical_original_code:
void sys_mutex_destroy(union pthread_mutex_t *mtx)
{
    if(mtx != ((void *)0)) {
        pthread_mutex_destroy(mtx);
        free(mtx);
    }
}


decompiled_code:
int __fastcall sys_create_thread(pthread_t *a1, void *(*a2)(void *), void *a3)
{
return pthread_create(a1, 0LL, a2, a3);
}

canonical_decompiled_code:
int __fastcall func6(pthread_t *a1, void *(*a2)(void *), void *a3)
{
return pthread_create(a1, 0LL, a2, a3);
}

original_code:
int sys_create_thread(pthread_t * id, void *(*func)(void *), void * args)
{
    return pthread_create(id, ((void *)0), func, args);
}

canonical_original_code:
int sys_create_thread(unsigned long *id, void *(*func)(void *), void *args)
{
    return pthread_create(id, ((void *)0), func, args);
}

variable_types:
id
unsigned long *

variable_types:
func
void *(*)(void *)

variable_types:
args
void *


decompiled_code:
int __fastcall sys_wait_thread(pthread_t *a1)
{
return pthread_join(*a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func7(pthread_t *a1)
{
return pthread_join(*a1, 0LL);
}

original_code:
int sys_wait_thread(pthread_t * id)
{
    return pthread_join(*id, ((void *)0));
}

canonical_original_code:
int sys_wait_thread(unsigned long *id)
{
    return pthread_join(*id, ((void *)0));
}


decompiled_code:
__int64 __fastcall sstack_init(_QWORD *a1, int a2)
{
__int64 result; // rax
_QWORD *v3; // r12
void *v4; // rax

if ( a2 <= 0 )
return 0LL;
result = 0LL;
if ( a1 )
{
v3 = malloc(0x10uLL);
*a1 = v3;
if ( v3 )
{
v4 = malloc(8LL * a2);
v3[1] = v4;
if ( v4 )
{
*(_DWORD *)v3 = a2;
*((_DWORD *)v3 + 1) = 0;
result = 1LL;
}
else
{
free(v3);
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2)
{
__int64 result; // rax
_QWORD *v3; // r12
void *v4; // rax

if ( a2 <= 0 )
return 0LL;
result = 0LL;
if ( a1 )
{
v3 = malloc(0x10uLL);
*a1 = v3;
if ( v3 )
{
v4 = malloc(8LL * a2);
v3[1] = v4;
if ( v4 )
{
*(_DWORD *)v3 = a2;
*((_DWORD *)v3 + 1) = 0;
result = 1LL;
}
else
{
free(v3);
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int sstack_init(struct SStack ** s, int size)
{
    int ret = 0;
    if(s != ((void *)0)) {
        if(size > 0) {
            *s = malloc(sizeof(**s));
            if(*s != ((void *)0)) {
                (*s)->data = malloc(size * sizeof(*((*s)->data)));
                if((*s)->data == ((void *)0)) {
                    free(*s);
                } else {
                    (*s)->size = size;
                    (*s)->current = 0;
                    ret = 1;
                }
            }
        }
    }
    return ret;
}

canonical_original_code:
int sstack_init(struct SStack **s, int size)
{
    int ret = 0;
    if(s != ((void *)0)) {
        if(size > 0) {
            *s = malloc(sizeof(**s));
            if(*s != ((void *)0)) {
                (*s)->data = malloc(size * sizeof(*((*s)->data)));
                if((*s)->data == ((void *)0)) {
                    free(*s);
                } else {
                    (*s)->size = size;
                    (*s)->current = 0;
                    ret = 1;
                }
            }
        }
    }
    return ret;
}

variable_types: struct SStack { int size; int current; char **data; } **

variable_types: size int


decompiled_code:
__int64 __fastcall sstack_push(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v2 < *(_DWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2) = a2;
++*(_DWORD *)(a1 + 4);
result = 1LL;
}
return result;
}

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

if ( !a1 || !a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v2 < *(_DWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2) = a2;
++*(_DWORD *)(a1 + 4);
result = 1LL;
}
return result;
}

original_code:
int sstack_push(struct SStack * s, void * p)
{
    int ret = 0;
    if(s != ((void *)0) && p != ((void *)0)) {
        if(s->current < s->size) {
            s->data[s->current] = (char *)p;
            s->current++;
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int sstack_push(struct SStack *s, void *p)
{
    int ret = 0;
    if(s != ((void *)0) && p != ((void *)0)) {
        if(s->current < s->size) {
            s->data[s->current] = (char *)p;
            s->current++;
            ret = 1;
        }
    }
    return ret;
}

variable_types: struct SStack { int size; int current; char **data; } *

variable_types:
p
void *


decompiled_code:
__int64 __fastcall sstack_pop(int *a1, _QWORD *a2)
{
__int64 result; // rax
int v3; // edx

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
v3 = a1[1];
result = 0LL;
if ( v3 > 0 )
{
a1[1] = v3 - 1;
*a2 = **((_QWORD **)a1 + 1);
memmove(*((void **)a1 + 1), (const void *)(*((_QWORD *)a1 + 1) + 8LL), 8LL * (*a1 - 1));
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) = 0LL;
result = 1LL;
}
}
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
v3 = a1[1];
result = 0LL;
if ( v3 > 0 )
{
a1[1] = v3 - 1;
*a2 = **((_QWORD **)a1 + 1);
memmove(*((void **)a1 + 1), (const void *)(*((_QWORD *)a1 + 1) + 8LL), 8LL * (*a1 - 1));
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) = 0LL;
result = 1LL;
}
}
return result;
}

original_code:
int sstack_pop(struct SStack * s, void ** p)
{
    int ret = 0;
    if(s != ((void *)0) && p != ((void *)0)) {
        if(s->current > 0) {
            s->current--;
            *p = (void *)s->data[0];
            memmove(&(s->data[0]), &(s->data[1]), (s->size - 1) * sizeof(char *));
            s->data[s->size - 1] = ((void *)0);
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int sstack_pop(struct SStack *s, void **p)
{
    int ret = 0;
    if(s != ((void *)0) && p != ((void *)0)) {
        if(s->current > 0) {
            s->current--;
            *p = (void *)s->data[0];
            memmove(&(s->data[0]), &(s->data[1]), (s->size - 1) * sizeof(char *));
            s->data[s->size - 1] = ((void *)0);
            ret = 1;
        }
    }
    return ret;
}

variable_types:
p
void **

user_defined_types: struct SStack { int size; int current; char **data; }


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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void sstack_free(struct SStack * s)
{
    if(s != ((void *)0)) {
        if(s->data != ((void *)0)) free(s->data);
        free(s);
    }
}

canonical_original_code:
void sstack_free(struct SStack *s)
{
    if(s != ((void *)0)) {
        if(s->data != ((void *)0)) free(s->data);
        free(s);
    }
}


decompiled_code:
__int64 __fastcall bytetok_size(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int bytetok_size(Tokk b)
{
    int i = 0;
    for(i = 0; b[i] != ((void *)0); i++);
    return i;
}

canonical_original_code:
int bytetok_size(char **b)
{
    int i = 0;
    for(i = 0; b[i] != ((void *)0); i++);
    return i;
}

variable_types:
b
char **

variable_types: i int


decompiled_code:
_QWORD *group_init()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[1] = 0LL;
}
return result;
}

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

result = malloc(0x10uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[1] = 0LL;
}
return result;
}

original_code:
Group group_init(void)
{
    Group g = ((void *)0);
    g = malloc(sizeof(*g));
    if (g != ((void *)0)) {
        g->size = 0;
        g->data = ((void *)0);
    }
    return g;
}

canonical_original_code:
struct s_Group *group_init()
{
    struct s_Group *g = ((void *)0);
    g = malloc(sizeof(*g));
    if (g != ((void *)0)) {
        g->size = 0;
        g->data = ((void *)0);
    }
    return g;
}

variable_types: struct s_Group { int size; char **data; } *


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
if ( *a1 > 0 || (result = grow_group((__int64)a1, 1), (_DWORD)result) )
{
if ( !*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) || (result = grow_group((__int64)a1, 1), (_DWORD)result) )
{
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) = a2;
result = 1LL;
}
}
}
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
if ( *a1 > 0 || (result = func7((__int64)a1, 1), (_DWORD)result) )
{
if ( !*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) || (result = func7((__int64)a1, 1), (_DWORD)result) )
{
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) = a2;
result = 1LL;
}
}
}
return result;
}

original_code:
int group_append(Group g, void * p)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->data[g->size - 1] != ((void *)0)) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        g->data[g->size - 1] = p;
        ret = 1;
    }
quick_return:
    return ret;
}

canonical_original_code:
int group_append(struct s_Group *g, void *p)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->data[g->size - 1] != ((void *)0)) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        g->data[g->size - 1] = p;
        ret = 1;
    }
quick_return:
    return ret;
}

user_defined_types: struct s_Group { int size; char **data; }


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
if ( *a1 > 0 || (result = grow_group((__int64)a1, 1), (_DWORD)result) )
{
if ( !*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) || (result = grow_group((__int64)a1, 1), (_DWORD)result) )
{
if ( *a1 > 1 )
memmove((void *)(*((_QWORD *)a1 + 1) + 8LL), *((const void **)a1 + 1), 8LL * (*a1 - 1));
**((_QWORD **)a1 + 1) = a2;
result = 1LL;
}
}
}
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
if ( *a1 > 0 || (result = func7((__int64)a1, 1), (_DWORD)result) )
{
if ( !*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) || (result = func7((__int64)a1, 1), (_DWORD)result) )
{
if ( *a1 > 1 )
memmove((void *)(*((_QWORD *)a1 + 1) + 8LL), *((const void **)a1 + 1), 8LL * (*a1 - 1));
**((_QWORD **)a1 + 1) = a2;
result = 1LL;
}
}
}
return result;
}

original_code:
int group_prepend(Group g, void * p)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->data[g->size -1] != ((void *)0)) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->size > 1) {
            memmove(&(g->data[1]), &(g->data[0]), sizeof(*(g->data)) * (g->size -1));
            g->data[0] = p;
        } else {
            g->data[0] = p;
        }
        ret = 1;
    }
quick_return:
    return ret;
}

canonical_original_code:
int group_prepend(struct s_Group *g, void *p)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->data[g->size -1] != ((void *)0)) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->size > 1) {
            memmove(&(g->data[1]), &(g->data[0]), sizeof(*(g->data)) * (g->size -1));
            g->data[0] = p;
        } else {
            g->data[0] = p;
        }
        ret = 1;
    }
quick_return:
    return ret;
}