OscBmpWriteHdrInfo

canonical_original_code:
static inline void OscBmpWriteHdrInfo(unsigned char *pHdr, int width, int height, short colorDepth, int headerSize)
{
 int imageSize; int dataOffset; int fileSize;
 imageSize = (((int)width*(colorDepth/8) + 3)/4)*4*height;
 fileSize = imageSize + headerSize;
 dataOffset = headerSize;
 { { *((unsigned char *) (&pHdr[2])) = (unsigned char) (((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (fileSize) << 8 | (unsigned short) (fileSize) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((fileSize) >> 16) << 8 | (unsigned short) ((fileSize) >> 16) >> 8))))) >> 16) >> 8); *((unsigned char *) (&pHdr[2]) + 1) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (fileSize) << 8 | (unsigned short) (fileSize) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((fileSize) >> 16) << 8 | (unsigned short) ((fileSize) >> 16) >> 8))))) >> 16); }; { *((unsigned char *) ((unsigned short *) (&pHdr[2]) + 1)) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (fileSize) << 8 | (unsigned short) (fileSize) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((fileSize) >> 16) << 8 | (unsigned short) ((fileSize) >> 16) >> 8))))) >> 8); *((unsigned char *) ((unsigned short *) (&pHdr[2]) + 1) + 1) = (unsigned char) (((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (fileSize) << 8 | (unsigned short) (fileSize) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((fileSize) >> 16) << 8 | (unsigned short) ((fileSize) >> 16) >> 8))))); }; };
 { { *((unsigned char *) (&pHdr[10])) = (unsigned char) (((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (dataOffset) << 8 | (unsigned short) (dataOffset) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((dataOffset) >> 16) << 8 | (unsigned short) ((dataOffset) >> 16) >> 8))))) >> 16) >> 8); *((unsigned char *) (&pHdr[10]) + 1) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (dataOffset) << 8 | (unsigned short) (dataOffset) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((dataOffset) >> 16) << 8 | (unsigned short) ((dataOffset) >> 16) >> 8))))) >> 16); }; { *((unsigned char *) ((unsigned short *) (&pHdr[10]) + 1)) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (dataOffset) << 8 | (unsigned short) (dataOffset) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((dataOffset) >> 16) << 8 | (unsigned short) ((dataOffset) >> 16) >> 8))))) >> 8); *((unsigned char *) ((unsigned short *) (&pHdr[10]) + 1) + 1) = (unsigned char) (((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (dataOffset) << 8 | (unsigned short) (dataOffset) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((dataOffset) >> 16) << 8 | (unsigned short) ((dataOffset) >> 16) >> 8))))); }; };
 { { *((unsigned char *) (&pHdr[18])) = (unsigned char) (((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (width) << 8 | (unsigned short) (width) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((width) >> 16) << 8 | (unsigned short) ((width) >> 16) >> 8))))) >> 16) >> 8); *((unsigned char *) (&pHdr[18]) + 1) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (width) << 8 | (unsigned short) (width) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((width) >> 16) << 8 | (unsigned short) ((width) >> 16) >> 8))))) >> 16); }; { *((unsigned char *) ((unsigned short *) (&pHdr[18]) + 1)) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (width) << 8 | (unsigned short) (width) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((width) >> 16) << 8 | (unsigned short) ((width) >> 16) >> 8))))) >> 8); *((unsigned char *) ((unsigned short *) (&pHdr[18]) + 1) + 1) = (unsigned char) (((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (width) << 8 | (unsigned short) (width) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((width) >> 16) << 8 | (unsigned short) ((width) >> 16) >> 8))))); }; };
 { { *((unsigned char *) (&pHdr[22])) = (unsigned char) (((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (height) << 8 | (unsigned short) (height) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((height) >> 16) << 8 | (unsigned short) ((height) >> 16) >> 8))))) >> 16) >> 8); *((unsigned char *) (&pHdr[22]) + 1) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (height) << 8 | (unsigned short) (height) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((height) >> 16) << 8 | (unsigned short) ((height) >> 16) >> 8))))) >> 16); }; { *((unsigned char *) ((unsigned short *) (&pHdr[22]) + 1)) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (height) << 8 | (unsigned short) (height) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((height) >> 16) << 8 | (unsigned short) ((height) >> 16) >> 8))))) >> 8); *((unsigned char *) ((unsigned short *) (&pHdr[22]) + 1) + 1) = (unsigned char) (((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (height) << 8 | (unsigned short) (height) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((height) >> 16) << 8 | (unsigned short) ((height) >> 16) >> 8))))); }; };
 { *((unsigned char *) (&pHdr[28])) = (unsigned char) ((((unsigned short) ((unsigned short) (colorDepth) << 8 | (unsigned short) (colorDepth) >> 8))) >> 8); *((unsigned char *) (&pHdr[28]) + 1) = (unsigned char) (((unsigned short) ((unsigned short) (colorDepth) << 8 | (unsigned short) (colorDepth) >> 8))); };
 { { *((unsigned char *) (&pHdr[34])) = (unsigned char) (((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (imageSize) << 8 | (unsigned short) (imageSize) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((imageSize) >> 16) << 8 | (unsigned short) ((imageSize) >> 16) >> 8))))) >> 16) >> 8); *((unsigned char *) (&pHdr[34]) + 1) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (imageSize) << 8 | (unsigned short) (imageSize) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((imageSize) >> 16) << 8 | (unsigned short) ((imageSize) >> 16) >> 8))))) >> 16); }; { *((unsigned char *) ((unsigned short *) (&pHdr[34]) + 1)) = (unsigned char) ((((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (imageSize) << 8 | (unsigned short) (imageSize) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((imageSize) >> 16) << 8 | (unsigned short) ((imageSize) >> 16) >> 8))))) >> 8); *((unsigned char *) ((unsigned short *) (&pHdr[34]) + 1) + 1) = (unsigned char) (((unsigned int) ((unsigned int) ((unsigned short) ((unsigned short) (imageSize) << 8 | (unsigned short) (imageSize) >> 8)) << 16 | (unsigned int) ((unsigned short) ((unsigned short) ((imageSize) >> 16) << 8 | (unsigned short) ((imageSize) >> 16) >> 8))))); }; };
}

variable_types:
pHdr
unsigned char *

variable_types: width int

variable_types: height int

variable_types: colorDepth short

variable_types: headerSize int

variable_types: imageSize int

variable_types: dataOffset int

variable_types: fileSize int


OscBmpReverseRowOrder

decompiled_code:
__int64 __fastcall OscBmpReverseRowOrder(__int64 *a1)
{
int v1; // eax
__int64 v2; // r14
int v3; // eax
int v4; // er13
void *v5; // r15
unsigned __int16 v6; // bx
unsigned int v7; // ecx
int v8; // ebp
int v9; // ebx
void *v10; // rbx
__int64 result; // rax
void *dest; // [rsp+8h] [rbp-50h]
unsigned int v13; // [rsp+14h] [rbp-44h]

v1 = *((_DWORD *)a1 + 3);
v2 = *a1;
if ( v1 == 8 )
{
v3 = 3;
}
else
{
if ( v1 )
return 4294966696LL;
v3 = 1;
}
v4 = v3 * *((unsigned __int16 *)a1 + 4);
v5 = malloc(v4);
if ( v5 )
{
v6 = *((_WORD *)a1 + 5);
v7 = 0;
v8 = 0;
if ( v6 >> 1 )
{
do
{
v9 = v6 - v8;
v13 = v7;
++v8;
dest = (void *)(v2 + v7);
memcpy(v5, dest, v4);
v10 = (void *)(v2 + (unsigned int)(v4 * (v9 - 1)));
memcpy(dest, v10, v4);
memcpy(v10, v5, v4);
v6 = *((_WORD *)a1 + 5);
v7 = v4 + v13;
}
while ( v6 >> 1 > v8 );
}
free(v5);
result = 0LL;
}
else
{
OscLog(2LL, "%s: Memory allocation failed!\n", "OscBmpReverseRowOrder");
result = 4294967291LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
int v1; // eax
__int64 v2; // r14
int v3; // eax
int v4; // er13
void *v5; // r15
unsigned __int16 v6; // bx
unsigned int v7; // ecx
int v8; // ebp
int v9; // ebx
void *v10; // rbx
__int64 result; // rax
void *dest; // [rsp+8h] [rbp-50h]
unsigned int v13; // [rsp+14h] [rbp-44h]

v1 = *((_DWORD *)a1 + 3);
v2 = *a1;
if ( v1 == 8 )
{
v3 = 3;
}
else
{
if ( v1 )
return 4294966696LL;
v3 = 1;
}
v4 = v3 * *((unsigned __int16 *)a1 + 4);
v5 = malloc(v4);
if ( v5 )
{
v6 = *((_WORD *)a1 + 5);
v7 = 0;
v8 = 0;
if ( v6 >> 1 )
{
do
{
v9 = v6 - v8;
v13 = v7;
++v8;
dest = (void *)(v2 + v7);
memcpy(v5, dest, v4);
v10 = (void *)(v2 + (unsigned int)(v4 * (v9 - 1)));
memcpy(dest, v10, v4);
memcpy(v10, v5, v4);
v6 = *((_WORD *)a1 + 5);
v7 = v4 + v13;
}
while ( v6 >> 1 > v8 );
}
free(v5);
result = 0LL;
}
else
{
OscLog(2LL, "%s: Memory allocation failed!\n", "OscBmpReverseRowOrder");
result = 4294967291LL;
}
return result;
}

original_code:
static OSC_ERR OscBmpReverseRowOrder(struct OSC_PICTURE *pPic)
{
 void *pTempRow;
 uint8 bytesPerPixel;
 uint32 rowLength;
 int i;
 uint32 curFIndex, curBIndex;
 uint8 *pData = (uint8*)pPic->data;
 if(pPic->type == OSC_PICTURE_BGR_24)
 {
  bytesPerPixel = 3;
 } else if(pPic->type == OSC_PICTURE_GREYSCALE) {
  bytesPerPixel = 1;
 } else {
  return -EUNSUPPORTED_FORMAT;
 }
 rowLength = pPic->width * bytesPerPixel;
 pTempRow = (void*)malloc(rowLength);
 if(!pTempRow)
 {
  OscLog(CRITICAL, "%s: Memory allocation failed!\n", __func__);
  return -EOUT_OF_MEMORY;
 }
 for(i = 0; i < pPic->height/2; i++)
 {
  curFIndex = i * rowLength;
  curBIndex = (pPic->height - i - 1) * rowLength;
  memcpy(pTempRow, &pData[curFIndex], rowLength);
  memcpy(&pData[curFIndex], &pData[curBIndex], rowLength);
  memcpy(&pData[curBIndex], pTempRow, rowLength);
 }
 free(pTempRow);
 return 0;
}

canonical_original_code:
static int OscBmpReverseRowOrder(struct OSC_PICTURE *pPic)
{
 void *pTempRow;
 unsigned char bytesPerPixel;
 unsigned int rowLength;
 int i;
 unsigned int curFIndex; unsigned int curBIndex;
 unsigned char *pData = (uint8*)pPic->data;
 if(pPic->type == OSC_PICTURE_BGR_24)
 {
  bytesPerPixel = 3;
 } else if(pPic->type == OSC_PICTURE_GREYSCALE) {
  bytesPerPixel = 1;
 } else {
  return -EUNSUPPORTED_FORMAT;
 }
 rowLength = pPic->width * bytesPerPixel;
 pTempRow = (void *)malloc(rowLength);
 if(!pTempRow)
 {
  OscLog(CRITICAL, "%s: Memory allocation failed!\n", __func__);
  return -EOUT_OF_MEMORY;
 }
 for(i = 0; i < pPic->height/2; i++)
 {
  curFIndex = i * rowLength;
  curBIndex = (pPic->height - i - 1) * rowLength;
  memcpy(pTempRow, &pData[curFIndex], rowLength);
  memcpy(&pData[curFIndex], &pData[curBIndex], rowLength);
  memcpy(&pData[curBIndex], pTempRow, rowLength);
 }
 free(pTempRow);
 return 0;
}

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:
pTempRow
void *

variable_types:
bytesPerPixel
unsigned char

variable_types:
rowLength
unsigned int

variable_types: i int

variable_types:
curFIndex
unsigned int

variable_types:
curBIndex
unsigned int

variable_types:
pData
unsigned char *

return_type: int

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


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

result = 16LL;
if ( a1 != 2 )
{
if ( a1 <= 2 )
{
result = 8LL;
if ( a1 == 1 )
result = 24LL;
}
else if ( a1 == 3 )
{
result = 24LL;
}
else
{
result = a1 - 8 < 2 ? 24 : 8;
}
}
return result;
}

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

result = 16LL;
if ( a1 != 2 )
{
if ( a1 <= 2 )
{
result = 8LL;
if ( a1 == 1 )
result = 24LL;
}
else if ( a1 == 3 )
{
result = 24LL;
}
else
{
result = a1 - 8 < 2 ? 24 : 8;
}
}
return result;
}

original_code:
uint8 OSC_PICTURE_TYPE_COLOR_DEPTH(enum EnOscPictureType enType)
{
 switch (enType)
 {
 case OSC_PICTURE_BGR_24:
  return 24;
 case OSC_PICTURE_RGB_24:
  return 24;
 case OSC_PICTURE_YUV_444:
  return 24;
 case OSC_PICTURE_YUV_422:
  return 16;
 case OSC_PICTURE_YUV_420:
  return 24;
 case OSC_PICTURE_YUV_400:
  return 8;
 default:
  return 8;
 }
}

canonical_original_code:
unsigned char OSC_PICTURE_TYPE_COLOR_DEPTH(enum EnOscPictureType enType)
{
 switch (enType)
 {
 case OSC_PICTURE_BGR_24:
  return 24;
 case OSC_PICTURE_RGB_24:
  return 24;
 case OSC_PICTURE_YUV_444:
  return 24;
 case OSC_PICTURE_YUV_422:
  return 16;
 case OSC_PICTURE_YUV_420:
  return 24;
 case OSC_PICTURE_YUV_400:
  return 8;
 default:
  return 8;
 }
}

variable_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 }

return_type: unsigned char


ThrowEvent

decompiled_code:
__int64 __fastcall ThrowEvent(__int64 a1, unsigned int a2)
{
return HsmOnEvent(a1, (char *)&mainStateMsg + 4 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
return HsmOnEvent(a1, (char *)&mainStateMsg + 4 * a2);
}

original_code:
void ThrowEvent(struct MainState *pHsm, unsigned int evt)
{
 const Msg *pMsg = &mainStateMsg[evt];
 HsmOnEvent((Hsm*)pHsm, pMsg);
}

canonical_original_code:
void ThrowEvent(struct MainState *pHsm, unsigned int evt)
{
 struct Msg *pMsg = &mainStateMsg[evt];
 HsmOnEvent((struct Hsm *)pHsm, pMsg);
}

variable_types: struct MainState { struct Hsm { char *name; struct State { struct State *super; struct Msg { int evt; } *(*hndlr)(struct Hsm *, struct Msg *); char *name; } *curr; struct State *next; struct State *source; struct State top; } super; struct State showGray; } *

variable_types:
evt
unsigned int

variable_types:
pMsg
struct Msg { int evt; } *

return_type: void

user_defined_types: struct MainState { struct Hsm super; struct State showGray; }

user_defined_types: struct Hsm { char *name; struct State *curr; struct State *next; struct State *source; struct State top; }

user_defined_types: struct State { struct State *super; struct Msg *(*hndlr)(struct Hsm *, struct Msg *); char *name; }


HandleIpcRequests

decompiled_code:
__int64 __fastcall HandleIpcRequests(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax
unsigned int v4; // er12
int v6; // eax
unsigned int v7; // eax
int v8; // eax
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = CheckIpcRequests(v9);
if ( v1 )
{
v2 = v1;
if ( v1 != -901 )
{
OscLog(3LL, "%s: IPC request error! (%d)\n", "HandleIpcRequests", v1);
return v2;
}
}
else
{
switch ( v9[0] )
{
case 0u:
ThrowEvent(a1, 2u);
break;
case 1u:
ThrowEvent(a1, 3u);
break;
case 2u:
v7 = **((_DWORD **)&data + 157927);
if ( v7 <= 5 )
{
*((_DWORD *)&data + 315860) = v7;
ThrowEvent(a1, 4u);
}
else
{
OscLog(
3LL,
"%obtained unknown image type: %u! Will leave unchanged\n",
*((unsigned int *)&data + 315860),
v9[0]);
}
break;
case 3u:
v8 = **((_DWORD **)&data + 157927);
if ( *((_DWORD *)&data + 315861) != v8 )
{
*((_BYTE *)&data + 1263360) = 1;
*((_DWORD *)&data + 315861) = v8;
}
goto LABEL_10;
case 4u:
v6 = **((_DWORD **)&data + 157927);
if ( *((_DWORD *)&data + 315862) != v6 )
*((_DWORD *)&data + 315862) = v6;
LABEL_10:
*((_DWORD *)&data + 315856) = 1;
break;
default:
OscLog(3LL, "%s: Unkown IPC parameter ID (%d)!\n", "HandleIpcRequests", v9[0]);
*((_DWORD *)&data + 315856) = 2;
break;
}
}
v3 = AckIpcRequests();
v4 = v3;
if ( v3 )
OscLog(3LL, "%s: IPC acknowledge error! (%d)\n", "HandleIpcRequests", v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax
unsigned int v4; // er12
int v6; // eax
unsigned int v7; // eax
int v8; // eax
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = CheckIpcRequests(v9);
if ( v1 )
{
v2 = v1;
if ( v1 != -901 )
{
OscLog(3LL, "%s: IPC request error! (%d)\n", "HandleIpcRequests", v1);
return v2;
}
}
else
{
switch ( v9[0] )
{
case 0u:
func1(a1, 2u);
break;
case 1u:
func1(a1, 3u);
break;
case 2u:
v7 = **((_DWORD **)&data + 157927);
if ( v7 <= 5 )
{
*((_DWORD *)&data + 315860) = v7;
func1(a1, 4u);
}
else
{
OscLog(
3LL,
"%obtained unknown image type: %u! Will leave unchanged\n",
*((unsigned int *)&data + 315860),
v9[0]);
}
break;
case 3u:
v8 = **((_DWORD **)&data + 157927);
if ( *((_DWORD *)&data + 315861) != v8 )
{
*((_BYTE *)&data + 1263360) = 1;
*((_DWORD *)&data + 315861) = v8;
}
goto LABEL_10;
case 4u:
v6 = **((_DWORD **)&data + 157927);
if ( *((_DWORD *)&data + 315862) != v6 )
*((_DWORD *)&data + 315862) = v6;
LABEL_10:
*((_DWORD *)&data + 315856) = 1;
break;
default:
OscLog(3LL, "%s: Unkown IPC parameter ID (%d)!\n", "HandleIpcRequests", v9[0]);
*((_DWORD *)&data + 315856) = 2;
break;
}
}
v3 = AckIpcRequests();
v4 = v3;
if ( v3 )
OscLog(3LL, "%s: IPC acknowledge error! (%d)\n", "HandleIpcRequests", v3);
return v4;
}

original_code:
static OSC_ERR HandleIpcRequests(MainState *pMainState)
{
 OSC_ERR err;
 uint32 paramId;
 struct IPC_DATA *pIpc = &data.ipc;
 struct OSC_IPC_REQUEST *pReq = &pIpc->req;
 err = CheckIpcRequests(&paramId);
 if (err == SUCCESS)
 {
  switch(paramId)
  {
  case GET_APP_STATE:
   ThrowEvent(pMainState, IPC_GET_APP_STATE_EVT);
   break;
  case GET_NEW_IMG:
   ThrowEvent(pMainState, IPC_GET_NEW_IMG_EVT);
   break;
  case SET_IMAGE_TYPE:
  {
   unsigned int ImgTyp = *((unsigned int*)data.ipc.req.pAddr);
   if(MAX_NUM_IMG <= ImgTyp)
   {
    OscLog(ERROR, "%obtained unknown image type: %u! Will leave unchanged\n", data.ipc.state.nImageType);
   }
   else
   {
    data.ipc.state.nImageType = ImgTyp;
    ThrowEvent(pMainState, IPC_SET_IMAGE_TYPE_EVT);
   }
   break;
  }
  case SET_EXPOSURE_TIME:
   if(data.ipc.state.nExposureTime != *((int*)pReq->pAddr))
   {
    data.nExposureTimeChanged = 1;
    data.ipc.state.nExposureTime = *((int*)pReq->pAddr);
   }
   data.ipc.enReqState = REQ_STATE_ACK_PENDING;
   break;
  case SET_THRESHOLD:
   if(data.ipc.state.nThreshold != *((int*)pReq->pAddr))
   {
    data.ipc.state.nThreshold = *((int*)pReq->pAddr);
   }
   data.ipc.enReqState = REQ_STATE_ACK_PENDING;
   break;
  default:
   OscLog(ERROR, "%s: Unkown IPC parameter ID (%d)!\n", __func__, paramId);
   data.ipc.enReqState = REQ_STATE_NACK_PENDING;
   break;
  }
 }
 else if (err == -ENO_MSG_AVAIL)
 {
 }
 else
 {
  OscLog(ERROR, "%s: IPC request error! (%d)\n", __func__, err);
  return err;
 }
 err = AckIpcRequests();
 if (err != SUCCESS)
 {
  OscLog(ERROR, "%s: IPC acknowledge error! (%d)\n", __func__, err);
 }
 return err;
}

canonical_original_code:
static int HandleIpcRequests(struct MainState *pMainState)
{
 int err;
 unsigned int paramId;
 struct IPC_DATA *pIpc = &data.ipc;
 struct OSC_IPC_REQUEST *pReq = &pIpc->req;
 err = CheckIpcRequests(&paramId);
 if (err == SUCCESS)
 {
  switch(paramId)
  {
  case GET_APP_STATE:
   ThrowEvent(pMainState, IPC_GET_APP_STATE_EVT);
   break;
  case GET_NEW_IMG:
   ThrowEvent(pMainState, IPC_GET_NEW_IMG_EVT);
   break;
  case SET_IMAGE_TYPE:
  {
   unsigned int ImgTyp = *((unsigned int*)data.ipc.req.pAddr);
   if(MAX_NUM_IMG <= ImgTyp)
   {
    OscLog(ERROR, "%obtained unknown image type: %u! Will leave unchanged\n", data.ipc.state.nImageType);
   }
   else
   {
    data.ipc.state.nImageType = ImgTyp;
    ThrowEvent(pMainState, IPC_SET_IMAGE_TYPE_EVT);
   }
   break;
  }
  case SET_EXPOSURE_TIME:
   if(data.ipc.state.nExposureTime != *((int *)pReq->pAddr))
   {
    data.nExposureTimeChanged = 1;
    data.ipc.state.nExposureTime = *((int *)pReq->pAddr);
   }
   data.ipc.enReqState = REQ_STATE_ACK_PENDING;
   break;
  case SET_THRESHOLD:
   if(data.ipc.state.nThreshold != *((int *)pReq->pAddr))
   {
    data.ipc.state.nThreshold = *((int *)pReq->pAddr);
   }
   data.ipc.enReqState = REQ_STATE_ACK_PENDING;
   break;
  default:
   OscLog(ERROR, "%s: Unkown IPC parameter ID (%d)!\n", __func__, paramId);
   data.ipc.enReqState = REQ_STATE_NACK_PENDING;
   break;
  }
 }
 else if (err == -ENO_MSG_AVAIL)
 {
 }
 else
 {
  OscLog(ERROR, "%s: IPC request error! (%d)\n", __func__, err);
  return err;
 }
 err = AckIpcRequests();
 if (err != SUCCESS)
 {
  OscLog(ERROR, "%s: IPC acknowledge error! (%d)\n", __func__, err);
 }
 return err;
}

variable_types: err int

variable_types:
paramId
unsigned 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; } *

variable_types:
ImgTyp
unsigned int

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


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 func3(__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; // er8
__int64 v3; // rax
__int64 v4; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, char a2)
{
int v2; // er8
__int64 v3; // rax
__int64 v4; // rdx

v2 = (unsigned __int8)*a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 1LL;
while ( 1 )
{
v4 = (int)v3;
if ( a1[v3] == a2 )
break;
if ( ++v3 == v2 + 1 )
return 0xFFFFFFFFLL;
}
if ( (_DWORD)v3 == v2 )
v4 = 0LL;
return (unsigned __int8)a1[v4 + 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:
ret
unsigned char


OscCamMultiBufferCreate

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

if ( *(_BYTE *)a1 )
OscLog(5LL, "%s: \t\t\t\tReplacing existing multibuffer.\n", "OscCamMultiBufferCreate");
*(_BYTE *)a1 = a2;
v4 = a1 + 1;
if ( a2 >= 8u )
{
*(_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);
}
v5 = *(_BYTE *)(a1 + 1);
*(_BYTE *)(a1 + 10) = -1;
*(_BYTE *)(a1 + 9) = v5;
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 []

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; // si
__int64 result; // rax

v1 = a1[9];
a1[9] = OscCamMultiBufferGetNext(a1, v1);
result = (unsigned __int8)a1[10];
if ( (_BYTE)result == 0xFF )
{
a1[10] = v1;
}
else if ( (_BYTE)result == v1 )
{
result = OscCamMultiBufferGetNext(a1, v1);
a1[10] = result;
}
return result;
}

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

v1 = a1[9];
a1[9] = func0(a1, v1);
result = (unsigned __int8)a1[10];
if ( (_BYTE)result == 0xFF )
{
a1[10] = v1;
}
else if ( (_BYTE)result == v1 )
{
result = func0(a1, v1);
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


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)
{
unsigned int v1; // esi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
unsigned int v1; // esi
__int64 result; // rax

v1 = gpio[40];
if ( a1 )
{
result = OscGpioWrite(6LL, (v1 >> 1) & 1);
gpio[40] |= 0x10u;
}
else
{
result = 0LL;
gpio[40] = v1 & 0xFFFFFFEF;
}
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_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 *v3; // rax
char *v4; // rax
char v6[16]; // [rsp+0h] [rbp-38h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

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

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

v2 = OscSimGetCurTimeStep();
sprintf(v6, "%%0%uu", *((unsigned int *)src + 256));
sprintf(s, v6, v2);
v3 = stpcpy(dest, src);
v4 = stpcpy(v3, s);
return strcpy(v4, 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; // er12

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);
return v2;
}
*a1 = *((_DWORD *)&data + 315853);
return 0LL;
}

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

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);
return v2;
}
*a1 = *((_DWORD *)&data + 315853);
return 0LL;
}

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


AckIpcRequests

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

v0 = *((_DWORD *)&data + 315856);
if ( !v0 )
return 0LL;
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; // eax
__int64 result; // rax

v0 = *((_DWORD *)&data + 315856);
if ( !v0 )
return 0LL;
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
{
while ( v3 < (unsigned int)result )
{
result = 2 * ((unsigned int)result - v3) + 1;
if ( !--v4 )
return result;
}
result = (unsigned int)(2 * result);
--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
{
while ( v3 < (unsigned int)result )
{
result = 2 * ((unsigned int)result - v3) + 1;
if ( !--v4 )
return result;
}
result = (unsigned int)(2 * result);
--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 v6; // rdx
__int64 result; // rax

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

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

v6 = 63LL;
do
{
result = (unsigned int)((*(unsigned __int16 *)(a2 + 2 * v6) * *(__int16 *)(a1 + 2 * v6) + 0x4000) >> 15);
*(_WORD *)(a3 + 2LL * (unsigned __int8)zigzag_table[v6]) = result;
}
while ( v6-- != 0 );
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)
{
__int64 result; // rax

*a1 = 2;
result = 0LL;
*a2 = 1;
*a3 = 2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, _BYTE *a2, _BYTE *a3)
{
__int64 result; // rax

*a1 = 2;
result = 0LL;
*a2 = 1;
*a3 = 2;
return result;
}

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 || (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 || (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)
{
__int64 v6; // r14
_BYTE *v7; // r13
_BYTE *v8; // rbx
int v9; // ebp
int v11; // er12
_BYTE *v13; // [rsp+8h] [rbp-70h]
unsigned int v14; // [rsp+14h] [rbp-64h]
int v16; // [rsp+1Ch] [rbp-5Ch]
__int64 v17; // [rsp+28h] [rbp-50h]
__int64 v18; // [rsp+30h] [rbp-48h]
unsigned int v19; // [rsp+38h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _BYTE *a2, unsigned int a3, int a4, unsigned __int8 *a5, int a6)
{
__int64 v6; // r14
_BYTE *v7; // r13
_BYTE *v8; // rbx
int v9; // ebp
int v11; // er12
_BYTE *v13; // [rsp+8h] [rbp-70h]
unsigned int v14; // [rsp+14h] [rbp-64h]
int v16; // [rsp+1Ch] [rbp-5Ch]
__int64 v17; // [rsp+28h] [rbp-50h]
__int64 v18; // [rsp+30h] [rbp-48h]
unsigned int v19; // [rsp+38h] [rbp-40h]

v6 = a3;
v7 = &a2[-a3];
v19 = a6;
v13 = &a2[a3];
if ( a4 )
{
v8 = a2;
v9 = 0;
v18 = (__int64)&a5[2 * a3];
v11 = a6;
v17 = (__int64)&a5[3 * a3];
v14 = 0;
v16 = a4 - 1;
do
{
if ( v9 )
{
if ( v16 == v9 )
debayerBilinearPreprocRowFirstOrLast(a5, (unsigned int)v6, v7, v8);
else
debayerBilinearPreprocRow(a5, (unsigned int)v6, v7, v8, v13);
}
else
{
debayerBilinearPreprocRowFirstOrLast(a5, (unsigned int)v6, v13, v8);
}
if ( v11 )
{
if ( v11 != 3 )
{
OscLog(3LL, "%s: Unsupported bayer order encountered! (%d)\n", "DebayerBilinearBGR", v19);
return 4294967272LL;
}
v11 = 0;
grgrToBgr((_BYTE *)(a1 + v14), a5, (__int64)&a5[v6], v18, v17, v8, v6);
}
else
{
v11 = 3;
bgbgToBgr((_BYTE *)(a1 + v14), a5, (__int64)&a5[v6], v18, v17, v8, v6);
}
v13 += v6;
v8 += v6;
v7 += v6;
v14 += 3 * v6;
++v9;
}
while ( a4 != v9 );
}
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 v6; // er11
int v7; // ebx

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

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

do
{
result = func0(a1, a2, a3);
v7 = result;
if ( v6 < (int)result )
result = func1(a1, (unsigned int)v6, (unsigned int)result);
a2 = v7 + 1;
}
while ( v7 + 1 < 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 v7; // eax
unsigned int v8; // er12
int v9; // edi
int v10; // edi
int v11; // edi
int pipedes[2]; // [rsp+8h] [rbp-40h] BYREF
int v14[2]; // [rsp+10h] [rbp-38h] BYREF
int v15[2]; // [rsp+18h] [rbp-30h] BYREF

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

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

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

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
unsigned __int64 v3; // r8
__int64 v4; // rax
float v5; // xmm0_4
float v6; // xmm1_4
float v7; // xmm3_4
float v8; // xmm2_4
__int64 v9; // rdx
_BYTE _0[3]; // [rsp+0h] [rbp+0h] BYREF

v2 = alloca(4LL * a2);
variance(a1, (__int64)_0, a2);
v3 >>= 2;
v4 = 2LL;
v5 = *((float *)&loc_4 + v3);
v6 = v5 - *(float *)(4 * v3);
do
{
v7 = v5;
v5 = *(float *)&_0[4 * v4];
v8 = v6;
v9 = (int)v4++;
v6 = v5 - v7;
}
while ( (float)(v5 - v7) >= v8 );
return a1[v9 - 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 v3; // r12
__int64 v4; // rdx
void *v5; // rsp
__int64 result; // rax
__int64 v7; // rdx
_QWORD v8[6]; // [rsp+0h] [rbp-30h] BYREF

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

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

v3 = a3;
v4 = 8LL * a3;
v5 = alloca(v4);
memcpy(v8, src, v4);
func2((__int64)v8, v3);
result = func6(v8, v3);
if ( (int)v3 > 0 )
{
v7 = (int)result;
for ( result = 0LL; result != v3; ++result )
{
if ( *((_QWORD *)src + result) >= v7 )
*(_BYTE *)(a2 + result) = 0;
}
}
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:
const char *__fastcall findstring(const char *a1, __int64 a2, const char *a3)
{
int v4; // ebp
const char *v5; // rax
const char *v6; // r15
char v7; // al
char v8; // bl
char v9; // al
char *v11; // rdi

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

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

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

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:
// attributes: thunk
__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:
// attributes: thunk
__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 *s)
{
bool v2; // cf
bool v3; // zf
int v4; // eax
__int64 v5; // rcx
const char *v6; // rdi
char *v7; // rsi
unsigned int v8; // er12
socklen_t v10; // eax
int optval; // [rsp+0h] [rbp-50h] BYREF
int v12; // [rsp+4h] [rbp-4Ch] BYREF
__m128i buf; // [rsp+8h] [rbp-48h] BYREF
__m128i v14; // [rsp+18h] [rbp-38h] BYREF
unsigned int v15; // [rsp+28h] [rbp-28h]

optval = 0xFFFF;
v15 = 0;
buf = 0LL;
v14 = 0LL;
if ( (unsigned int)enable_capability_raw() == -1 )
return (unsigned int)-1;
v4 = socket(10, 3, 58);
v5 = 7LL;
v6 = "unspec";
v7 = s;
do
{
if ( !v5 )
break;
v2 = (unsigned __int8)*v7 < (unsigned int)*v6;
v3 = *v7++ == *v6++;
--v5;
}
while ( v3 );
v8 = v4;
if ( (!v2 && !v3) != v2 )
{
v10 = strlen(s);
v6 = (const char *)v8;
v7 = (_BYTE *)(enable_capability_raw + 1);
if ( setsockopt(v8, 1, 25, s, v10) < 0 )
{
perror("setsockopt(SO_BINTDODEVICE)");
LABEL_17:
close(v8);
return (unsigned int)-1;
}
}
if ( (unsigned int)disable_capability_raw(v6, v7) == -1 )
return (unsigned int)-1;
if ( v8 == -1 )
{
perror("socket() fails");
return v8;
}
if ( setsockopt(v8, 1, 8, &optval, 4u) < 0 )
{
perror("setsockopt(SO_RCVBUF)");
goto LABEL_17;
}
v12 = 1;
if ( setsockopt(v8, 41, 49, &v12, 4u) < 0 )
{
perror("setsockopt(IP_PKTINFO)");
goto LABEL_17;
}
if ( !inet_pton(10, "ff02::1a", &buf) )
{
perror("inet_pton");
goto LABEL_17;
}
v14 = _mm_loadu_si128(&buf);
v15 = if_nametoindex(s);
if ( setsockopt(v8, 41, 20, &v14, 0x14u) < 0 )
{
perror("setsockopt(IPV6_JOIN_GROUP)");
goto LABEL_17;
}
v12 = 255;
if ( setsockopt(v8, 41, 16, &v12, 4u) < 0 )
{
perror("setsockopt(IPV6_UNICAST_HOPS)");
goto LABEL_17;
}
if ( setsockopt(v8, 41, 18, &v12, 4u) < 0 )
{
perror("setsockopt(IPV6_MULTICAST_HOPS");
goto LABEL_17;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s)
{
bool v2; // cf
bool v3; // zf
int v4; // eax
__int64 v5; // rcx
const char *v6; // rdi
char *v7; // rsi
unsigned int v8; // er12
socklen_t v10; // eax
int optval; // [rsp+0h] [rbp-50h] BYREF
int v12; // [rsp+4h] [rbp-4Ch] BYREF
__m128i buf; // [rsp+8h] [rbp-48h] BYREF
__m128i v14; // [rsp+18h] [rbp-38h] BYREF
unsigned int v15; // [rsp+28h] [rbp-28h]

optval = 0xFFFF;
v15 = 0;
buf = 0LL;
v14 = 0LL;
if ( (unsigned int)func0() == -1 )
return (unsigned int)-1;
v4 = socket(10, 3, 58);
v5 = 7LL;
v6 = "unspec";
v7 = s;
do
{
if ( !v5 )
break;
v2 = (unsigned __int8)*v7 < (unsigned int)*v6;
v3 = *v7++ == *v6++;
--v5;
}
while ( v3 );
v8 = v4;
if ( (!v2 && !v3) != v2 )
{
v10 = strlen(s);
v6 = (const char *)v8;
v7 = (_BYTE *)(enable_capability_raw + 1);
if ( setsockopt(v8, 1, 25, s, v10) < 0 )
{
perror("setsockopt(SO_BINTDODEVICE)");
LABEL_17:
close(v8);
return (unsigned int)-1;
}
}
if ( (unsigned int)func1(v6, v7) == -1 )
return (unsigned int)-1;
if ( v8 == -1 )
{
perror("socket() fails");
return v8;
}
if ( setsockopt(v8, 1, 8, &optval, 4u) < 0 )
{
perror("setsockopt(SO_RCVBUF)");
goto LABEL_17;
}
v12 = 1;
if ( setsockopt(v8, 41, 49, &v12, 4u) < 0 )
{
perror("setsockopt(IP_PKTINFO)");
goto LABEL_17;
}
if ( !inet_pton(10, "ff02::1a", &buf) )
{
perror("inet_pton");
goto LABEL_17;
}
v14 = _mm_loadu_si128(&buf);
v15 = if_nametoindex(s);
if ( setsockopt(v8, 41, 20, &v14, 0x14u) < 0 )
{
perror("setsockopt(IPV6_JOIN_GROUP)");
goto LABEL_17;
}
v12 = 255;
if ( setsockopt(v8, 41, 16, &v12, 4u) < 0 )
{
perror("setsockopt(IPV6_UNICAST_HOPS)");
goto LABEL_17;
}
if ( setsockopt(v8, 41, 18, &v12, 4u) < 0 )
{
perror("setsockopt(IPV6_MULTICAST_HOPS");
goto LABEL_17;
}
return v8;
}

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(unsigned int a1, const char *a2, const void *a3, size_t a4)
{
const __m128i *v6; // roff
__int64 v7; // rdx
__int64 v8; // rcx
const struct sockaddr *v9; // r8
socklen_t v10; // er9
ssize_t result; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-80h] BYREF
__m128i v13; // [rsp+8h] [rbp-78h] BYREF
__int64 v14; // [rsp+18h] [rbp-68h]
int v15; // [rsp+20h] [rbp-60h]
struct addrinfo req; // [rsp+28h] [rbp-58h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_family = 10;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a2, 0LL, &req, &pai) )
{
fwrite("unknown host\n", 1uLL, 0xDuLL, stderr);
result = 4294967294LL;
}
else
{
v6 = (const __m128i *)pai->ai_addr;
v13 = _mm_loadu_si128(v6);
v14 = v6[1].m128i_i64[0];
v15 = v6[1].m128i_i32[2];
freeaddrinfo(pai);
v13.m128i_i16[1] = _bswap_16_constprop_0(a1, 0LL, v7, v8, &v13, 28LL);
result = sendto(a1, a3, a4, 2048, v9, v10);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func6(unsigned int a1, const char *a2, const void *a3, size_t a4)
{
const __m128i *v6; // roff
__int64 v7; // rdx
__int64 v8; // rcx
const struct sockaddr *v9; // r8
socklen_t v10; // er9
ssize_t result; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-80h] BYREF
__m128i v13; // [rsp+8h] [rbp-78h] BYREF
__int64 v14; // [rsp+18h] [rbp-68h]
int v15; // [rsp+20h] [rbp-60h]
struct addrinfo req; // [rsp+28h] [rbp-58h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_family = 10;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a2, 0LL, &req, &pai) )
{
fwrite("unknown host\n", 1uLL, 0xDuLL, stderr);
result = 4294967294LL;
}
else
{
v6 = (const __m128i *)pai->ai_addr;
v13 = _mm_loadu_si128(v6);
v14 = v6[1].m128i_i64[0];
v15 = v6[1].m128i_i32[2];
freeaddrinfo(pai);
v13.m128i_i16[1] = func2(a1, 0LL, v7, v8, &v13, 28LL);
result = sendto(a1, a3, a4, 2048, v9, v10);
}
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; // r15
__int64 v15[2]; // [rsp+0h] [rbp-8C8h] BYREF
__int128 cp; // [rsp+10h] [rbp-8B8h] BYREF
__int64 v17; // [rsp+20h] [rbp-8A8h]
int v18; // [rsp+28h] [rbp-8A0h]
__int128 v19; // [rsp+30h] [rbp-898h]
__int64 v20; // [rsp+40h] [rbp-888h]
int v21; // [rsp+48h] [rbp-880h]
struct msghdr message; // [rsp+50h] [rbp-878h] BYREF
char v23; // [rsp+90h] [rbp-838h] BYREF

v15[0] = (__int64)s;
message.msg_name = &cp;
message.msg_iov = (iovec *)v15;
cp = 0LL;
v19 = 0LL;
v15[1] = a3;
message.msg_namelen = 28;
message.msg_iovlen = 1LL;
message.msg_flags = 0;
message.msg_control = &v23;
message.msg_controllen = 2048LL;
v17 = 0LL;
v18 = 0;
v20 = 0LL;
v21 = 0;
memset(s, 0, a3);
v12 = recvmsg(fd, &message, (unsigned __int8)(a9 == 0) << 6);
inet_ntop(10, (char *)&cp + 8, 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; // r15
__int64 v15[2]; // [rsp+0h] [rbp-8C8h] BYREF
__int128 cp; // [rsp+10h] [rbp-8B8h] BYREF
__int64 v17; // [rsp+20h] [rbp-8A8h]
int v18; // [rsp+28h] [rbp-8A0h]
__int128 v19; // [rsp+30h] [rbp-898h]
__int64 v20; // [rsp+40h] [rbp-888h]
int v21; // [rsp+48h] [rbp-880h]
struct msghdr message; // [rsp+50h] [rbp-878h] BYREF
char v23; // [rsp+90h] [rbp-838h] BYREF

v15[0] = (__int64)s;
message.msg_name = &cp;
message.msg_iov = (iovec *)v15;
cp = 0LL;
v19 = 0LL;
v15[1] = a3;
message.msg_namelen = 28;
message.msg_iovlen = 1LL;
message.msg_flags = 0;
message.msg_control = &v23;
message.msg_controllen = 2048LL;
v17 = 0LL;
v18 = 0;
v20 = 0LL;
v21 = 0;
memset(s, 0, a3);
v12 = recvmsg(fd, &message, (unsigned __int8)(a9 == 0) << 6);
inet_ntop(10, (char *)&cp + 8, 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; }