OscJpgEncode

decompiled_code:
__int64 __fastcall OscJpgEncode(char **a1, const void *a2, unsigned int a3)
{
char *v5; // r15
_WORD *v6; // rbx
unsigned int v7; // esi
__int64 v8; // rax
unsigned __int16 v9; // dx
__int64 v10; // r12
unsigned __int16 v11; // ax
unsigned __int16 i; // r14
__int16 v13; // cx
unsigned __int16 v14; // bp
__int16 v15; // ax
__int64 v17; // rcx
__int64 v18; // rdx

v5 = *a1;
if ( !Image )
{
Image = (__int64)malloc(0x300uLL);
if ( !Image )
OscFatalErr("Could not allocate memory\n");
}
v6 = (_WORD *)JpegStruct;
if ( !JpegStruct )
{
JpegStruct = (__int64)malloc(0x22uLL);
v6 = (_WORD *)JpegStruct;
if ( !JpegStruct )
{
OscFatalErr("Could not allocate memory\n");
v6 = (_WORD *)JpegStruct;
}
}
v7 = *((_DWORD *)a1 + 3);
if ( v7 == 8 )
{
v17 = *((unsigned __int16 *)a1 + 5);
v18 = *((unsigned __int16 *)a1 + 4);
*((_DWORD *)a1 + 3) = 1;
BGR_2_444(v5, a2, v18, v17);
memcpy(v5, a2, 3 * *((unsigned __int16 *)a1 + 5) * *((unsigned __int16 *)a1 + 4));
v7 = *((_DWORD *)a1 + 3);
}
if ( v7 != 1 )
{
OscFatalErr("Unsupported Image Format in OscJpgEncode\n");
v7 = *((_DWORD *)a1 + 3);
}
initialization((__int64)v6, v7, *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
initialize_quantization_tables(a3);
v8 = write_markers(a2, *((unsigned int *)a1 + 3), *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
v9 = v6[3];
v10 = v8;
if ( v9 )
{
v11 = v6[2];
for ( i = 1; i <= v9; ++i )
{
if ( i >= v9 )
v13 = v6[5];
else
v13 = v6[1];
v6[6] = v13;
if ( v11 )
{
v14 = 1;
do
{
if ( v11 > v14 )
{
v6[7] = *v6;
v15 = v6[8];
}
else
{
v6[7] = v6[4];
v15 = v6[9];
}
v6[10] = v15;
++v14;
read_format(Image, v6, v5);
v10 = encodeMCU((__int64)v6, *((_DWORD *)a1 + 3), v10);
v5 += (unsigned __int16)v6[11];
v11 = v6[2];
}
while ( v11 >= v14 );
v9 = v6[3];
}
v5 += (unsigned __int16)v6[12];
}
}
close_bitstream(v10);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func2(char **a1, const void *a2, unsigned int a3)
{
char *v5; // r15
_WORD *v6; // rbx
unsigned int v7; // esi
__int64 v8; // rax
unsigned __int16 v9; // dx
__int64 v10; // r12
unsigned __int16 v11; // ax
unsigned __int16 i; // r14
__int16 v13; // cx
unsigned __int16 v14; // bp
__int16 v15; // ax
__int64 v17; // rcx
__int64 v18; // rdx

v5 = *a1;
if ( !Image )
{
Image = (__int64)malloc(0x300uLL);
if ( !Image )
OscFatalErr("Could not allocate memory\n");
}
v6 = (_WORD *)JpegStruct;
if ( !JpegStruct )
{
JpegStruct = (__int64)malloc(0x22uLL);
v6 = (_WORD *)JpegStruct;
if ( !JpegStruct )
{
OscFatalErr("Could not allocate memory\n");
v6 = (_WORD *)JpegStruct;
}
}
v7 = *((_DWORD *)a1 + 3);
if ( v7 == 8 )
{
v17 = *((unsigned __int16 *)a1 + 5);
v18 = *((unsigned __int16 *)a1 + 4);
*((_DWORD *)a1 + 3) = 1;
BGR_2_444(v5, a2, v18, v17);
memcpy(v5, a2, 3 * *((unsigned __int16 *)a1 + 5) * *((unsigned __int16 *)a1 + 4));
v7 = *((_DWORD *)a1 + 3);
}
if ( v7 != 1 )
{
OscFatalErr("Unsupported Image Format in OscJpgEncode\n");
v7 = *((_DWORD *)a1 + 3);
}
func0((__int64)v6, v7, *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
initialize_quantization_tables(a3);
v8 = write_markers(a2, *((unsigned int *)a1 + 3), *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
v9 = v6[3];
v10 = v8;
if ( v9 )
{
v11 = v6[2];
for ( i = 1; i <= v9; ++i )
{
if ( i >= v9 )
v13 = v6[5];
else
v13 = v6[1];
v6[6] = v13;
if ( v11 )
{
v14 = 1;
do
{
if ( v11 > v14 )
{
v6[7] = *v6;
v15 = v6[8];
}
else
{
v6[7] = v6[4];
v15 = v6[9];
}
v6[10] = v15;
++v14;
read_format(Image, v6, v5);
v10 = func1((__int64)v6, *((_DWORD *)a1 + 3), v10);
v5 += (unsigned __int16)v6[11];
v11 = v6[2];
}
while ( v11 >= v14 );
v9 = v6[3];
}
v5 += (unsigned __int16)v6[12];
}
}
close_bitstream(v10);
return v10;
}

original_code:
uint8* OscJpgEncode(struct OSC_PICTURE *pic, uint8 *output_ptr, uint32 quality_factor)
{
 uint16 i, j;
 uint8 *input_ptr = (uint8 *)pic->data;
 JPEG_ENCODER_STRUCTURE *jpeg_encoder_structure;
 if (Image==((void *)0)) {
  Image = malloc(sizeof(struct IMGDATA));
  if (Image == ((void *)0))
   OscFatalErr("Could not allocate memory\n");
 }
 if (JpegStruct==((void *)0)) {
  JpegStruct= malloc(sizeof(JPEG_ENCODER_STRUCTURE));
  if (JpegStruct == ((void *)0))
   OscFatalErr("Could not allocate memory\n");
 }
 jpeg_encoder_structure = JpegStruct;
 if (pic->type == OSC_PICTURE_BGR_24)
 {
  pic->type = OSC_PICTURE_YUV_444;
  BGR_2_444 (input_ptr, output_ptr, pic->width, pic->height);
  memcpy(input_ptr, output_ptr, pic->width*pic->height*3);
 }
 if (pic->type != OSC_PICTURE_YUV_444)
 {
  OscFatalErr("Unsupported Image Format in OscJpgEncode\n");
 }
 initialization (jpeg_encoder_structure, pic->type, pic->width, pic->height);
 initialize_quantization_tables (quality_factor);
 output_ptr = write_markers (output_ptr, pic->type, pic->width, pic->height);
 for (i=1; i<=jpeg_encoder_structure->vertical_mcus; i++)
 {
  if (i < jpeg_encoder_structure->vertical_mcus)
   jpeg_encoder_structure->rows = jpeg_encoder_structure->mcu_height;
  else
   jpeg_encoder_structure->rows = jpeg_encoder_structure->rows_in_bottom_mcus;
  for (j=1; j<=jpeg_encoder_structure->horizontal_mcus; j++)
  {
   if (j < jpeg_encoder_structure->horizontal_mcus)
   {
    jpeg_encoder_structure->cols = jpeg_encoder_structure->mcu_width;
    jpeg_encoder_structure->incr = jpeg_encoder_structure->length_minus_mcu_width;
   }
   else
   {
    jpeg_encoder_structure->cols = jpeg_encoder_structure->cols_in_right_mcus;
    jpeg_encoder_structure->incr = jpeg_encoder_structure->length_minus_width;
   }
   read_format (Image, jpeg_encoder_structure, input_ptr);
   output_ptr = encodeMCU (jpeg_encoder_structure, pic->type, output_ptr);
   input_ptr += jpeg_encoder_structure->mcu_width_size;
  }
  input_ptr += jpeg_encoder_structure->offset;
 }
 close_bitstream (output_ptr);
 return output_ptr;
}

canonical_original_code:
unsigned char *OscJpgEncode(struct OSC_PICTURE *pic, unsigned char *output_ptr, unsigned int quality_factor)
{
 unsigned short i; unsigned short j;
 unsigned char *input_ptr = (uint8 *)pic->data;
 struct JPEG_ENCODER_STRUCTURE *jpeg_encoder_structure;
 if (Image==((void *)0)) {
  Image = malloc(sizeof(struct IMGDATA));
  if (Image == ((void *)0))
   OscFatalErr("Could not allocate memory\n");
 }
 if (JpegStruct==((void *)0)) {
  JpegStruct= malloc(sizeof(JPEG_ENCODER_STRUCTURE));
  if (JpegStruct == ((void *)0))
   OscFatalErr("Could not allocate memory\n");
 }
 jpeg_encoder_structure = JpegStruct;
 if (pic->type == OSC_PICTURE_BGR_24)
 {
  pic->type = OSC_PICTURE_YUV_444;
  BGR_2_444 (input_ptr, output_ptr, pic->width, pic->height);
  memcpy(input_ptr, output_ptr, pic->width*pic->height*3);
 }
 if (pic->type != OSC_PICTURE_YUV_444)
 {
  OscFatalErr("Unsupported Image Format in OscJpgEncode\n");
 }
 initialization (jpeg_encoder_structure, pic->type, pic->width, pic->height);
 initialize_quantization_tables (quality_factor);
 output_ptr = write_markers (output_ptr, pic->type, pic->width, pic->height);
 for (i=1; i<=jpeg_encoder_structure->vertical_mcus; i++)
 {
  if (i < jpeg_encoder_structure->vertical_mcus)
   jpeg_encoder_structure->rows = jpeg_encoder_structure->mcu_height;
  else
   jpeg_encoder_structure->rows = jpeg_encoder_structure->rows_in_bottom_mcus;
  for (j=1; j<=jpeg_encoder_structure->horizontal_mcus; j++)
  {
   if (j < jpeg_encoder_structure->horizontal_mcus)
   {
    jpeg_encoder_structure->cols = jpeg_encoder_structure->mcu_width;
    jpeg_encoder_structure->incr = jpeg_encoder_structure->length_minus_mcu_width;
   }
   else
   {
    jpeg_encoder_structure->cols = jpeg_encoder_structure->cols_in_right_mcus;
    jpeg_encoder_structure->incr = jpeg_encoder_structure->length_minus_width;
   }
   read_format (Image, jpeg_encoder_structure, input_ptr);
   output_ptr = encodeMCU (jpeg_encoder_structure, pic->type, output_ptr);
   input_ptr += jpeg_encoder_structure->mcu_width_size;
  }
  input_ptr += jpeg_encoder_structure->offset;
 }
 close_bitstream (output_ptr);
 return output_ptr;
}

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:
i
unsigned short

variable_types:
j
unsigned short

user_defined_types: struct IMGDATA { short Y1[64]; short Y2[64]; short Y3[64]; short Y4[64]; short CB[64]; short CR[64]; }

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

user_defined_types: struct JPEG_ENCODER_STRUCTURE { unsigned short mcu_width; unsigned short mcu_height; unsigned short horizontal_mcus; unsigned short vertical_mcus; unsigned short cols_in_right_mcus; unsigned short rows_in_bottom_mcus; unsigned short rows; unsigned short cols; unsigned short length_minus_mcu_width; unsigned short length_minus_width; unsigned short incr; unsigned short mcu_width_size; unsigned short offset; short ldc1; short ldc2; short ldc3; short debug_pass; }


OscDmaCreate

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

result = 0LL;
memset(&dma, 0, 0x1F8uLL);
return result;
}

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

result = 0LL;
memset(&dma, 0, 0x1F8uLL);
return result;
}

original_code:
OSC_ERR OscDmaCreate()
{
 dma = (struct OSC_DMA) { };
 return SUCCESS;
}

canonical_original_code:
int OscDmaCreate()
{
 dma = (struct OSC_DMA) { };
 return SUCCESS;
}

return_type: int

user_defined_types: struct OSC_DMA { struct DMA_CHAIN dmaChains[2]; unsigned short nChainsAllocated; }

user_defined_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; }

user_defined_types: struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; }


OscDmaResetChain

decompiled_code:
__int64 __fastcall OscDmaResetChain(__int64 a1, __int64 a2, const char *a3)
{
__int64 result; // rax

if ( !a1 )
return OscLog(3LL, "%s: Invalid parameter!\n", a3);
*(_DWORD *)(a1 + 4) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, const char *a3)
{
__int64 result; // rax

if ( !a1 )
return OscLog(3LL, "%s: Invalid parameter!\n", a3);
*(_DWORD *)(a1 + 4) = 0;
return result;
}

original_code:
inline void OscDmaResetChain(void *hChainHandle)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 if((hChainHandle == ((void *)0)))
 {
     OscLog(ERROR, "%s: Invalid parameter!\n");
     return;
 }
 pChain->nMoves = 0;
}

variable_types:
hChainHandle
void *

variable_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; } *

return_type: void


OscDmaAllocChain

decompiled_code:
__int64 __fastcall OscDmaAllocChain(_QWORD *a1, __int64 a2)
{
unsigned __int16 v2; // ax
char *v4; // rdi
__int64 result; // rax

if ( !a1 )
return 4294967288LL;
v2 = dma[248];
if ( v2 == 2 )
{
OscLog(4LL, "%s: All DMA chains already allocated!\n", "OscDmaAllocChain");
*a1 = 0LL;
result = 4294966196LL;
}
else
{
v4 = (char *)&dma[124 * v2];
*a1 = v4;
dma[248] = v2 + 1;
OscDmaResetChain((__int64)v4, a2, (const char *)(31LL * v2));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
unsigned __int16 v2; // ax
char *v4; // rdi
__int64 result; // rax

if ( !a1 )
return 4294967288LL;
v2 = dma[248];
if ( v2 == 2 )
{
OscLog(4LL, "%s: All DMA chains already allocated!\n", "OscDmaAllocChain");
*a1 = 0LL;
result = 4294966196LL;
}
else
{
v4 = (char *)&dma[124 * v2];
*a1 = v4;
dma[248] = v2 + 1;
func1((__int64)v4, a2, (const char *)(31LL * v2));
result = 0LL;
}
return result;
}

original_code:
OSC_ERR OscDmaAllocChain(void **phChainHandle)
{
 struct DMA_CHAIN ** pChain;
 if((phChainHandle == ((void *)0)))
 {
  return -EINVALID_PARAMETER;
 }
 if((dma.nChainsAllocated == 2))
 {
  OscLog(WARN, "%s: All DMA chains already allocated!\n",
    __func__);
  *phChainHandle = ((void *)0);
  return -EDMA_NO_MORE_CHAINS_AVAILABLE;
 }
 pChain = (struct DMA_CHAIN**)phChainHandle;
 *pChain = &dma.dmaChains[dma.nChainsAllocated];
 dma.nChainsAllocated++;
 OscDmaResetChain(*pChain);
 return SUCCESS;
}

canonical_original_code:
int OscDmaAllocChain(void **phChainHandle)
{
 struct DMA_CHAIN **pChain;
 if((phChainHandle == ((void *)0)))
 {
  return -EINVALID_PARAMETER;
 }
 if((dma.nChainsAllocated == 2))
 {
  OscLog(WARN, "%s: All DMA chains already allocated!\n",
    __func__);
  *phChainHandle = ((void *)0);
  return -EDMA_NO_MORE_CHAINS_AVAILABLE;
 }
 pChain = (struct DMA_CHAIN **)phChainHandle;
 *pChain = &dma.dmaChains[dma.nChainsAllocated];
 dma.nChainsAllocated++;
 OscDmaResetChain(*pChain);
 return SUCCESS;
}

variable_types:
phChainHandle
void **

variable_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; } **


original_code:
OSC_ERR OscDmaAdd2DMove(void *hChainHandle,
  const void *pDstAddr,
  const enum EnDmaWdSize enDstWdSize,
  const uint16 dstXCount, const int32 dstXModify,
  const uint16 dstYCount, const int32 dstYModify,
  const void *pSrcAddr,
  const enum EnDmaWdSize enSrcWdSize,
  const uint16 srcXCount, const int32 srcXModify,
  const uint16 srcYCount, const int32 srcYModify)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc = &pChain->arySrcDesc[pChain->nMoves];
 struct DMA_DESC *pDstDesc = &pChain->aryDstDesc[pChain->nMoves];
 if((pChain->nMoves == 4))
 {
  return -EINVALID_PARAMETER;
 }
 pChain->nMoves++;
 pDstDesc->config = 0x00000700 | 0x00004000 | 0x00000001 | 0x00000002;
 pDstDesc->config |= enDstWdSize;
 pDstDesc->startAddr = (uintptr_t)pDstAddr;
 pDstDesc->xCount = dstXCount;
 pDstDesc->xModify = dstXModify;
 pDstDesc->yCount = dstYCount;
 pDstDesc->yModify = dstYModify;
 if(dstYCount > 1)
 {
  pDstDesc->config |= 0x00000010;
 }
 pSrcDesc->config = 0x00000700 | 0x00004000 | 0x00000001;
 pSrcDesc->config |= enSrcWdSize;
 pSrcDesc->startAddr = (uintptr_t)pSrcAddr;
 pSrcDesc->xCount = srcXCount;
 pSrcDesc->xModify = srcXModify;
 pSrcDesc->yCount = srcYCount;
 pSrcDesc->yModify = srcYModify;
 if(srcYCount > 1)
 {
  pSrcDesc->config |= 0x00000010;
 }
 {};
 {};
 return SUCCESS;
}

canonical_original_code:
int OscDmaAdd2DMove(void *hChainHandle, void *pDstAddr, enum EnDmaWdSize enDstWdSize, unsigned short dstXCount, int dstXModify, unsigned short dstYCount, int dstYModify, void *pSrcAddr, enum EnDmaWdSize enSrcWdSize, unsigned short srcXCount, int srcXModify, unsigned short srcYCount, int srcYModify)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc = &pChain->arySrcDesc[pChain->nMoves];
 struct DMA_DESC *pDstDesc = &pChain->aryDstDesc[pChain->nMoves];
 if((pChain->nMoves == 4))
 {
  return -EINVALID_PARAMETER;
 }
 pChain->nMoves++;
 pDstDesc->config = 0x00000700 | 0x00004000 | 0x00000001 | 0x00000002;
 pDstDesc->config |= enDstWdSize;
 pDstDesc->startAddr = (unsigned long)pDstAddr;
 pDstDesc->xCount = dstXCount;
 pDstDesc->xModify = dstXModify;
 pDstDesc->yCount = dstYCount;
 pDstDesc->yModify = dstYModify;
 if(dstYCount > 1)
 {
  pDstDesc->config |= 0x00000010;
 }
 pSrcDesc->config = 0x00000700 | 0x00004000 | 0x00000001;
 pSrcDesc->config |= enSrcWdSize;
 pSrcDesc->startAddr = (unsigned long)pSrcAddr;
 pSrcDesc->xCount = srcXCount;
 pSrcDesc->xModify = srcXModify;
 pSrcDesc->yCount = srcYCount;
 pSrcDesc->yModify = srcYModify;
 if(srcYCount > 1)
 {
  pSrcDesc->config |= 0x00000010;
 }
 {};
 {};
 return SUCCESS;
}

variable_types:
pDstAddr
void *

variable_types: enum EnDmaWdSize { DMA_WDSIZE_8=0, DMA_WDSIZE_16=4, DMA_WDSIZE_32=8 }

variable_types:
dstXCount
unsigned short

variable_types: dstXModify int

variable_types:
dstYCount
unsigned short

variable_types: dstYModify int

variable_types:
pSrcAddr
void *

variable_types:
srcXCount
unsigned short

variable_types: srcXModify int

variable_types:
srcYCount
unsigned short

variable_types: srcYModify int

variable_types: struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } *


original_code:
inline OSC_ERR OscDmaAdd1DMove(void *hChainHandle,
  const void *pDstAddr,
  const enum EnDmaWdSize enDstWdSize,
  const uint16 dstCount, const int32 dstModify,
  const void *pSrcAddr,
  const enum EnDmaWdSize enSrcWdSize,
  const uint16 srcCount, const int32 srcModify)
{
 return OscDmaAdd2DMove(hChainHandle,
   pDstAddr,
   enDstWdSize,
   dstCount, dstModify,
   1, 4,
   pSrcAddr,
   enSrcWdSize,
   srcCount, srcModify,
   1, 4);
}

canonical_original_code:
inline int OscDmaAdd1DMove(void *hChainHandle, void *pDstAddr, enum EnDmaWdSize enDstWdSize, unsigned short dstCount, int dstModify, void *pSrcAddr, enum EnDmaWdSize enSrcWdSize, unsigned short srcCount, int srcModify)
{
 return OscDmaAdd2DMove(hChainHandle,
   pDstAddr,
   enDstWdSize,
   dstCount, dstModify,
   1, 4,
   pSrcAddr,
   enSrcWdSize,
   srcCount, srcModify,
   1, 4);
}

variable_types:
dstCount
unsigned short

variable_types: dstModify int

variable_types:
srcCount
unsigned short

variable_types: srcModify int

user_defined_types: enum EnDmaWdSize { DMA_WDSIZE_8=0, DMA_WDSIZE_16=4, DMA_WDSIZE_32=8 }


OscDmaAddSyncPoint

original_code:
OSC_ERR OscDmaAddSyncPoint(void *hChainHandle)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc = &pChain->arySrcDesc[pChain->nMoves];
 struct DMA_DESC *pDstDesc = &pChain->aryDstDesc[pChain->nMoves];
 uintptr_t allOnesAddr = (uintptr_t)&allOnes;
 uintptr_t syncFlagAddr = (uintptr_t)&pChain->syncFlag;
 if((pChain->nMoves > 4))
 {
  return -EINVALID_PARAMETER;
 }
 pChain->nMoves++;
 pDstDesc->config = 0x00000001 | 0x00000002;
 if((pChain->nMoves > 1))
 {
  pDstDesc->config |=
   (pChain->aryDstDesc[pChain->nMoves - 2].config & 0x0000000C);
 } else {
  pDstDesc->config |= 0x00000008;
 }
 pDstDesc->startAddr = (uintptr_t)syncFlagAddr;
 pDstDesc->xCount = 1;
 pDstDesc->xModify = 4;
 pDstDesc->yCount = 1;
 pDstDesc->yModify = 4;
 pSrcDesc->config = 0x00000001;
 if((pChain->nMoves > 1))
 {
  pSrcDesc->config |=
   (pChain->arySrcDesc[pChain->nMoves - 2].config & 0x0000000C);
 } else {
  pSrcDesc->config |= 0x00000008;
 }
 pSrcDesc->startAddr = (uintptr_t)allOnesAddr;
 pSrcDesc->xCount = 1;
 pSrcDesc->xModify = 4;
 pSrcDesc->yCount = 1;
 pSrcDesc->yModify = 4;
 {};
 {};
 return SUCCESS;
}

canonical_original_code:
int OscDmaAddSyncPoint(void *hChainHandle)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc = &pChain->arySrcDesc[pChain->nMoves];
 struct DMA_DESC *pDstDesc = &pChain->aryDstDesc[pChain->nMoves];
 unsigned long allOnesAddr = (uintptr_t)&allOnes;
 unsigned long syncFlagAddr = (uintptr_t)&pChain->syncFlag;
 if((pChain->nMoves > 4))
 {
  return -EINVALID_PARAMETER;
 }
 pChain->nMoves++;
 pDstDesc->config = 0x00000001 | 0x00000002;
 if((pChain->nMoves > 1))
 {
  pDstDesc->config |=
   (pChain->aryDstDesc[pChain->nMoves - 2].config & 0x0000000C);
 } else {
  pDstDesc->config |= 0x00000008;
 }
 pDstDesc->startAddr = (unsigned long)syncFlagAddr;
 pDstDesc->xCount = 1;
 pDstDesc->xModify = 4;
 pDstDesc->yCount = 1;
 pDstDesc->yModify = 4;
 pSrcDesc->config = 0x00000001;
 if((pChain->nMoves > 1))
 {
  pSrcDesc->config |=
   (pChain->arySrcDesc[pChain->nMoves - 2].config & 0x0000000C);
 } else {
  pSrcDesc->config |= 0x00000008;
 }
 pSrcDesc->startAddr = (unsigned long)allOnesAddr;
 pSrcDesc->xCount = 1;
 pSrcDesc->xModify = 4;
 pSrcDesc->yCount = 1;
 pSrcDesc->yModify = 4;
 {};
 {};
 return SUCCESS;
}

variable_types:
hChainHandle
void *

variable_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; } *

variable_types:
allOnesAddr
unsigned long

variable_types:
syncFlagAddr
unsigned long


OscDmaMemCpy

decompiled_code:
__int64 __fastcall OscDmaMemCpy(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // er12

v4 = OscDmaAdd2DMove(a1, a2, 8, a4 >> 2, 4, 1u, 4, a3, 8, a4 >> 2, 4, 1u, 4);
if ( v4 )
OscLog(3LL, "%s: Unable to add move!\n", "OscDmaMemCpy");
else
OscDmaStart(a1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // er12

v4 = func3(a1, a2, 8, a4 >> 2, 4, 1u, 4, a3, 8, a4 >> 2, 4, 1u, 4);
if ( v4 )
OscLog(3LL, "%s: Unable to add move!\n", "OscDmaMemCpy");
else
OscDmaStart(a1);
return v4;
}

original_code:
OSC_ERR OscDmaMemCpy(void *hChainHandle,
  void *pDstAddr,
  void *pSrcAddr,
  uint32 len)
{
 OSC_ERR err;
 err = OscDmaAdd2DMove(hChainHandle,
   pDstAddr,
   DMA_WDSIZE_32,
   (len >> 2), 4,
   1, 4,
   pSrcAddr,
   DMA_WDSIZE_32,
   (len >> 2), 4,
   1, 4);
 if((err != SUCCESS))
 {
  OscLog(ERROR, "%s: Unable to add move!\n", __func__);
  return err;
 }
 OscDmaStart(hChainHandle);
 return SUCCESS;
}

canonical_original_code:
int OscDmaMemCpy(void *hChainHandle, void *pDstAddr, void *pSrcAddr, unsigned int len)
{
 int err;
 err = OscDmaAdd2DMove(hChainHandle,
   pDstAddr,
   DMA_WDSIZE_32,
   (len >> 2), 4,
   1, 4,
   pSrcAddr,
   DMA_WDSIZE_32,
   (len >> 2), 4,
   1, 4);
 if((err != SUCCESS))
 {
  OscLog(ERROR, "%s: Unable to add move!\n", __func__);
  return err;
 }
 OscDmaStart(hChainHandle);
 return SUCCESS;
}

variable_types:
pDstAddr
void *

variable_types:
len
unsigned int

variable_types: err int


OscDmaMemCpySync

decompiled_code:
__int64 __fastcall OscDmaMemCpySync(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // eax
unsigned int v5; // er12
__int64 result; // rax
unsigned int v7; // er12

v4 = OscDmaAdd2DMove(a1, a2, 8, a4 >> 2, 4, 1u, 4, a3, 8, a4 >> 2, 4, 1u, 4);
if ( v4 )
{
v7 = v4;
OscLog(3LL, "%s: Unable to add move!\n", "OscDmaMemCpySync");
result = v7;
}
else
{
v5 = OscDmaAddSyncPoint(a1);
if ( v5 )
{
OscLog(3LL, "%s: Unable to add synchronizaion point!\n", "OscDmaMemCpySync");
result = v5;
}
else
{
OscDmaStart(a1);
result = OscDmaSync(a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // eax
unsigned int v5; // er12
__int64 result; // rax
unsigned int v7; // er12

v4 = func3(a1, a2, 8, a4 >> 2, 4, 1u, 4, a3, 8, a4 >> 2, 4, 1u, 4);
if ( v4 )
{
v7 = v4;
OscLog(3LL, "%s: Unable to add move!\n", "OscDmaMemCpySync");
result = v7;
}
else
{
v5 = func5(a1);
if ( v5 )
{
OscLog(3LL, "%s: Unable to add synchronizaion point!\n", "OscDmaMemCpySync");
result = v5;
}
else
{
OscDmaStart(a1);
result = OscDmaSync(a1);
}
}
return result;
}

original_code:
OSC_ERR OscDmaMemCpySync(void *hChainHandle,
  void *pDstAddr,
  void *pSrcAddr,
  uint32 len)
{
 OSC_ERR err;
 err = OscDmaAdd2DMove(hChainHandle,
   pDstAddr,
   DMA_WDSIZE_32,
   (len >> 2), 4,
   1, 4,
   pSrcAddr,
   DMA_WDSIZE_32,
   (len >> 2), 4,
   1, 4);
 if((err != SUCCESS))
 {
  OscLog(ERROR, "%s: Unable to add move!\n", __func__);
  return err;
 }
 err = OscDmaAddSyncPoint(hChainHandle);
 if((err != SUCCESS))
 {
  OscLog(ERROR, "%s: Unable to add synchronizaion point!\n",
    __func__);
  return err;
 }
 OscDmaStart(hChainHandle);
 err = OscDmaSync(hChainHandle);
 return err;
}

canonical_original_code:
int OscDmaMemCpySync(void *hChainHandle, void *pDstAddr, void *pSrcAddr, unsigned int len)
{
 int err;
 err = OscDmaAdd2DMove(hChainHandle,
   pDstAddr,
   DMA_WDSIZE_32,
   (len >> 2), 4,
   1, 4,
   pSrcAddr,
   DMA_WDSIZE_32,
   (len >> 2), 4,
   1, 4);
 if((err != SUCCESS))
 {
  OscLog(ERROR, "%s: Unable to add move!\n", __func__);
  return err;
 }
 err = OscDmaAddSyncPoint(hChainHandle);
 if((err != SUCCESS))
 {
  OscLog(ERROR, "%s: Unable to add synchronizaion point!\n",
    __func__);
  return err;
 }
 OscDmaStart(hChainHandle);
 err = OscDmaSync(hChainHandle);
 return err;
}

variable_types:
pSrcAddr
void *


OscIpcCreate

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

result = 0LL;
memset(ipc, 0, 0x218uLL);
ipc[134] = 0;
return result;
}

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

result = 0LL;
memset(ipc, 0, 0x218uLL);
ipc[134] = 0;
return result;
}

original_code:
OSC_ERR OscIpcCreate()
{
 ipc = (struct OSC_IPC) { };
 return SUCCESS;
}

canonical_original_code:
int OscIpcCreate()
{
 ipc = (struct OSC_IPC) { };
 return SUCCESS;
}

user_defined_types: struct OSC_IPC { struct OSC_IPC_CHANNEL aryIpcChans[2]; _Bool arybIpcChansBusy[2]; }

user_defined_types: struct OSC_IPC_CHANNEL { int sock; char strSocketPath[256]; unsigned int flags; int acceptedSock; }


OscIpcRegisterChannel

decompiled_code:
__int64 __fastcall OscIpcRegisterChannel(_BYTE *a1, const char *a2, int a3)
{
__int64 result; // rax
int v6; // edi
char *v7; // r14
char *v8; // rax
int v9; // ebx
char *v10; // rax
int v11; // edi
int *v12; // rax
char *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int *v19; // rax
char *v20; // rax
int v21; // [rsp+Ch] [rbp-ACh]
struct sockaddr addr; // [rsp+10h] [rbp-A8h] BYREF

if ( !a1 || !a2 || !*a2 )
{
OscLog(3LL, "%s(0x%x, 0x%x): Invalid parameter!\n", "OscIpcRegisterChannel", a1, a2);
return 4294967288LL;
}
if ( LOBYTE(ipc[134]) )
{
if ( BYTE1(ipc[134]) )
{
OscLog(3LL, "%s: All IPC channels busy!\n", "OscIpcRegisterChannel");
return 4294967285LL;
}
v21 = 1;
}
else
{
v21 = 0;
}
v6 = socket(1, 1, 0);
ipc[67 * v21] = v6;
if ( (a3 & 2) != 0 && fcntl(v6, 4, 2048LL) < 0 )
{
v19 = _errno_location();
v20 = strerror(*v19);
OscLog(3LL, "%s: Unable to make socket non-blocking! (%s)\n", "OscIpcRegisterChannel", v20);
result = 4294966396LL;
}
else
{
v7 = (char *)&ipc[67 * v21 + 1];
ipc[67 * v21 + 65] = a3;
v8 = stpcpy(v7, a2);
addr.sa_family = 1;
if ( (a3 & 1) == 0 )
{
v10 = stpcpy(addr.sa_data, a2);
if ( connect(ipc[67 * v21], &addr, v10 - addr.sa_data + 2) < 0 )
{
v11 = *_errno_location();
if ( v11 != 115 )
{
v14 = strerror(v11);
OscLog(3LL, "%s: Unable to connect socket! (%s)\n", "OscIpcRegisterChannel", v14);
close(ipc[67 * v21]);
unlink((const char *)&ipc[67 * v21 + 1]);
return 4294966396LL;
}
OscLog(4LL, "%s: Socket not fully connected yet due to non-blocking operation...", "OscIpcRegisterChannel");
}
LABEL_15:
*a1 = v21;
result = 0LL;
*((_BYTE *)&ipc[134] + v21) = 1;
return result;
}
v9 = (_DWORD)v8 - (_DWORD)v7;
memcpy(addr.sa_data, &ipc[67 * v21 + 1], v8 - v7 + 1);
unlink(addr.sa_data);
if ( bind(ipc[67 * v21], &addr, v9 + 2) < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
OscLog(3LL, "%s: Unable to bind socket! (%s)\n", "OscIpcRegisterChannel", v16);
close(ipc[67 * v21]);
result = 4294966396LL;
}
else
{
if ( chmod(addr.sa_data, 0x1FFu) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
OscLog(
4LL,
"%s: Unable to set access permissions of socket file node \"%s\"! (%s)",
"OscIpcRegisterChannel",
addr.sa_data,
v13);
}
if ( listen(ipc[67 * v21], 5) >= 0 )
goto LABEL_15;
v17 = _errno_location();
v18 = strerror(*v17);
OscLog(3LL, "%s: Unable to listen to socket! (%s)\n", "OscIpcRegisterChannel", v18);
close(ipc[67 * v21]);
unlink((const char *)&ipc[67 * v21 + 1]);
result = 4294966396LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, const char *a2, int a3)
{
__int64 result; // rax
int v6; // edi
char *v7; // r14
char *v8; // rax
int v9; // ebx
char *v10; // rax
int v11; // edi
int *v12; // rax
char *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int *v19; // rax
char *v20; // rax
int v21; // [rsp+Ch] [rbp-ACh]
struct sockaddr addr; // [rsp+10h] [rbp-A8h] BYREF

if ( !a1 || !a2 || !*a2 )
{
OscLog(3LL, "%s(0x%x, 0x%x): Invalid parameter!\n", "OscIpcRegisterChannel", a1, a2);
return 4294967288LL;
}
if ( LOBYTE(ipc[134]) )
{
if ( BYTE1(ipc[134]) )
{
OscLog(3LL, "%s: All IPC channels busy!\n", "OscIpcRegisterChannel");
return 4294967285LL;
}
v21 = 1;
}
else
{
v21 = 0;
}
v6 = socket(1, 1, 0);
ipc[67 * v21] = v6;
if ( (a3 & 2) != 0 && fcntl(v6, 4, 2048LL) < 0 )
{
v19 = _errno_location();
v20 = strerror(*v19);
OscLog(3LL, "%s: Unable to make socket non-blocking! (%s)\n", "OscIpcRegisterChannel", v20);
result = 4294966396LL;
}
else
{
v7 = (char *)&ipc[67 * v21 + 1];
ipc[67 * v21 + 65] = a3;
v8 = stpcpy(v7, a2);
addr.sa_family = 1;
if ( (a3 & 1) == 0 )
{
v10 = stpcpy(addr.sa_data, a2);
if ( connect(ipc[67 * v21], &addr, v10 - addr.sa_data + 2) < 0 )
{
v11 = *_errno_location();
if ( v11 != 115 )
{
v14 = strerror(v11);
OscLog(3LL, "%s: Unable to connect socket! (%s)\n", "OscIpcRegisterChannel", v14);
close(ipc[67 * v21]);
unlink((const char *)&ipc[67 * v21 + 1]);
return 4294966396LL;
}
OscLog(4LL, "%s: Socket not fully connected yet due to non-blocking operation...", "OscIpcRegisterChannel");
}
LABEL_15:
*a1 = v21;
result = 0LL;
*((_BYTE *)&ipc[134] + v21) = 1;
return result;
}
v9 = (_DWORD)v8 - (_DWORD)v7;
memcpy(addr.sa_data, &ipc[67 * v21 + 1], v8 - v7 + 1);
unlink(addr.sa_data);
if ( bind(ipc[67 * v21], &addr, v9 + 2) < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
OscLog(3LL, "%s: Unable to bind socket! (%s)\n", "OscIpcRegisterChannel", v16);
close(ipc[67 * v21]);
result = 4294966396LL;
}
else
{
if ( chmod(addr.sa_data, 0x1FFu) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
OscLog(
4LL,
"%s: Unable to set access permissions of socket file node \"%s\"! (%s)",
"OscIpcRegisterChannel",
addr.sa_data,
v13);
}
if ( listen(ipc[67 * v21], 5) >= 0 )
goto LABEL_15;
v17 = _errno_location();
v18 = strerror(*v17);
OscLog(3LL, "%s: Unable to listen to socket! (%s)\n", "OscIpcRegisterChannel", v18);
close(ipc[67 * v21]);
unlink((const char *)&ipc[67 * v21 + 1]);
result = 4294966396LL;
}
}
return result;
}

original_code:
OSC_ERR OscIpcRegisterChannel(
  uint8 * pIpcChan,
  const char *strSocketPath,
  const int flags)
{
 unsigned int sock;
 struct sockaddr_un addr;
 int len, ret, chan;
 if(((pIpcChan == ((void *)0)) || (strSocketPath == ((void *)0)) || (strSocketPath[0] == '\0')))
 {
  OscLog(ERROR, "%s(0x%x, 0x%x): Invalid parameter!\n",
    __func__, pIpcChan, strSocketPath);
  return -EINVALID_PARAMETER;
 }
 for(chan = 0; chan < 2; chan++)
 {
  if(ipc.arybIpcChansBusy[chan] == 0)
  {
   break;
  }
 }
 if((chan == 2))
 {
  OscLog(ERROR, "%s: All IPC channels busy!\n", __func__);
  return -EDEVICE_BUSY;
 }
 ipc.aryIpcChans[chan].sock = socket(1, SOCK_STREAM, 0);
 if(sock < 0)
 {
  OscLog(ERROR, "%s: Error allocating socket! (%s)\n",
    __func__,
    strerror((*__errno_location ())));
  return -ESOCKET;
 }
 if(flags & F_IPC_NONBLOCKING)
 {
  ret = fcntl(ipc.aryIpcChans[chan].sock,
    4,
    04000);
  if(ret < 0)
  {
   OscLog(ERROR, "%s: Unable to make socket non-blocking! (%s)\n",
     __func__,
     strerror((*__errno_location ())));
   return -ESOCKET;
  }
 }
 ipc.aryIpcChans[chan].flags = flags;
 strcpy(ipc.aryIpcChans[chan].strSocketPath, strSocketPath);
 if(flags & F_IPC_SERVER)
 {
  addr.sun_family = 1;
  strcpy(addr.sun_path, ipc.aryIpcChans[chan].strSocketPath);
  len = strlen(addr.sun_path) + sizeof(addr.sun_family);
  unlink(addr.sun_path);
  ret = bind(ipc.aryIpcChans[chan].sock,
    (struct sockaddr *)&addr,
    len);
  if(ret < 0)
  {
   OscLog(ERROR, "%s: Unable to bind socket! (%s)\n",
     __func__,
     strerror((*__errno_location ())));
   close(ipc.aryIpcChans[chan].sock);
   return -ESOCKET;
  }
  ret = chmod(addr.sun_path, (0100 | 0400 | 0200 | (0100 >> 3) | (0400 >> 3) | (0200 >> 3) | ((0100 >> 3) >> 3) | ((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)));
  if(ret < 0)
  {
   OscLog(WARN, "%s: Unable to set access permissions of "
     "socket file node \"%s\"! (%s)",
     __func__,
     addr.sun_path,
     strerror((*__errno_location ())));
  }
  ret = listen(ipc.aryIpcChans[chan].sock, 5);
  if(ret < 0)
  {
   OscLog(ERROR, "%s: Unable to listen to socket! (%s)\n",
     __func__,
     strerror((*__errno_location ())));
   close(ipc.aryIpcChans[chan].sock);
   unlink(ipc.aryIpcChans[chan].strSocketPath);
   return -ESOCKET;
  }
 } else {
  addr.sun_family = 1;
  strcpy(addr.sun_path, strSocketPath);
  len = strlen(addr.sun_path) + sizeof(addr.sun_family);
  ret = connect(ipc.aryIpcChans[chan].sock,
    (struct sockaddr *)&addr,
    len);
  if(ret < 0)
  {
   if((*__errno_location ()) == 115)
   {
    OscLog(WARN, "%s: Socket not fully connected yet "
      "due to non-blocking operation...",
      __func__);
   } else {
    OscLog(ERROR, "%s: Unable to connect socket! (%s)\n",
      __func__,
      strerror((*__errno_location ())));
    close(ipc.aryIpcChans[chan].sock);
    unlink(ipc.aryIpcChans[chan].strSocketPath);
    return -ESOCKET;
   }
  }
 }
 *pIpcChan = chan;
 ipc.arybIpcChansBusy[chan] = 1;
 return SUCCESS;
}

canonical_original_code:
int OscIpcRegisterChannel(unsigned char *pIpcChan, char *strSocketPath, int flags)
{
 unsigned int sock;
 struct sockaddr_un addr;
 int len; int ret; int chan;
 if(((pIpcChan == ((void *)0)) || (strSocketPath == ((void *)0)) || (strSocketPath[0] == '\0')))
 {
  OscLog(ERROR, "%s(0x%x, 0x%x): Invalid parameter!\n",
    __func__, pIpcChan, strSocketPath);
  return -EINVALID_PARAMETER;
 }
 for(chan = 0; chan < 2; chan++)
 {
  if(ipc.arybIpcChansBusy[chan] == 0)
  {
   break;
  }
 }
 if((chan == 2))
 {
  OscLog(ERROR, "%s: All IPC channels busy!\n", __func__);
  return -EDEVICE_BUSY;
 }
 ipc.aryIpcChans[chan].sock = socket(1, SOCK_STREAM, 0);
 if(sock < 0)
 {
  OscLog(ERROR, "%s: Error allocating socket! (%s)\n",
    __func__,
    strerror((*__errno_location ())));
  return -ESOCKET;
 }
 if(flags & F_IPC_NONBLOCKING)
 {
  ret = fcntl(ipc.aryIpcChans[chan].sock,
    4,
    04000);
  if(ret < 0)
  {
   OscLog(ERROR, "%s: Unable to make socket non-blocking! (%s)\n",
     __func__,
     strerror((*__errno_location ())));
   return -ESOCKET;
  }
 }
 ipc.aryIpcChans[chan].flags = flags;
 strcpy(ipc.aryIpcChans[chan].strSocketPath, strSocketPath);
 if(flags & F_IPC_SERVER)
 {
  addr.sun_family = 1;
  strcpy(addr.sun_path, ipc.aryIpcChans[chan].strSocketPath);
  len = strlen(addr.sun_path) + sizeof(addr.sun_family);
  unlink(addr.sun_path);
  ret = bind(ipc.aryIpcChans[chan].sock,
    (struct sockaddr *)&addr,
    len);
  if(ret < 0)
  {
   OscLog(ERROR, "%s: Unable to bind socket! (%s)\n",
     __func__,
     strerror((*__errno_location ())));
   close(ipc.aryIpcChans[chan].sock);
   return -ESOCKET;
  }
  ret = chmod(addr.sun_path, (0100 | 0400 | 0200 | (0100 >> 3) | (0400 >> 3) | (0200 >> 3) | ((0100 >> 3) >> 3) | ((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)));
  if(ret < 0)
  {
   OscLog(WARN, "%s: Unable to set access permissions of "
     "socket file node \"%s\"! (%s)",
     __func__,
     addr.sun_path,
     strerror((*__errno_location ())));
  }
  ret = listen(ipc.aryIpcChans[chan].sock, 5);
  if(ret < 0)
  {
   OscLog(ERROR, "%s: Unable to listen to socket! (%s)\n",
     __func__,
     strerror((*__errno_location ())));
   close(ipc.aryIpcChans[chan].sock);
   unlink(ipc.aryIpcChans[chan].strSocketPath);
   return -ESOCKET;
  }
 } else {
  addr.sun_family = 1;
  strcpy(addr.sun_path, strSocketPath);
  len = strlen(addr.sun_path) + sizeof(addr.sun_family);
  ret = connect(ipc.aryIpcChans[chan].sock,
    (struct sockaddr *)&addr,
    len);
  if(ret < 0)
  {
   if((*__errno_location ()) == 115)
   {
    OscLog(WARN, "%s: Socket not fully connected yet "
      "due to non-blocking operation...",
      __func__);
   } else {
    OscLog(ERROR, "%s: Unable to connect socket! (%s)\n",
      __func__,
      strerror((*__errno_location ())));
    close(ipc.aryIpcChans[chan].sock);
    unlink(ipc.aryIpcChans[chan].strSocketPath);
    return -ESOCKET;
   }
  }
 }
 *pIpcChan = chan;
 ipc.arybIpcChansBusy[chan] = 1;
 return SUCCESS;
}

variable_types:
pIpcChan
unsigned char *

variable_types:
strSocketPath
char *

variable_types: flags int

variable_types:
sock
unsigned int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: len int

variable_types: ret int

variable_types: chan int

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


OscIpcUnregisterChannel

decompiled_code:
__int64 __fastcall OscIpcUnregisterChannel(unsigned __int8 a1)
{
__int64 v1; // rbp
int v3; // edi

if ( a1 > 1u )
return 4294967288LL;
v1 = a1;
if ( !*((_BYTE *)&ipc[134] + a1) )
return 4294967288LL;
v3 = ipc[67 * a1];
if ( v3 > 0 )
close(v3);
if ( (ipc[67 * v1 + 65] & 1) != 0 )
unlink((const char *)&ipc[67 * a1 + 1]);
*((_BYTE *)&ipc[134] + v1) = 0;
return 0LL;
}

original_code:
OSC_ERR OscIpcUnregisterChannel(uint8 chanID)
{
 struct OSC_IPC_CHANNEL *pChan;
 pChan = &ipc.aryIpcChans[chanID];
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0)))
 {
  return -EINVALID_PARAMETER;
 }
 if(pChan->sock > 0)
 {
  close(pChan->sock);
 }
 if(pChan->flags & F_IPC_SERVER)
 {
  unlink(ipc.aryIpcChans[chanID].strSocketPath);
 }
 ipc.arybIpcChansBusy[chanID] = 0;
 return SUCCESS;
}

canonical_original_code:
int OscIpcUnregisterChannel(unsigned char chanID)
{
 struct OSC_IPC_CHANNEL *pChan;
 pChan = &ipc.aryIpcChans[chanID];
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0)))
 {
  return -EINVALID_PARAMETER;
 }
 if(pChan->sock > 0)
 {
  close(pChan->sock);
 }
 if(pChan->flags & F_IPC_SERVER)
 {
  unlink(ipc.aryIpcChans[chanID].strSocketPath);
 }
 ipc.arybIpcChansBusy[chanID] = 0;
 return SUCCESS;
}

variable_types:
chanID
unsigned char

variable_types: struct OSC_IPC_CHANNEL { int sock; char strSocketPath[256]; unsigned int flags; int acceptedSock; } *


OscIpcDestroy

decompiled_code:
__int64 OscIpcDestroy()
{
int v0; // edi

if ( LOBYTE(ipc[134]) && ipc[0] > 0 )
OscIpcUnregisterChannel(ipc[0]);
if ( !BYTE1(ipc[134]) )
return 0LL;
v0 = ipc[67];
if ( v0 <= 0 )
return 0LL;
OscIpcUnregisterChannel(v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // edi

if ( LOBYTE(ipc[134]) && ipc[0] > 0 )
func2(ipc[0]);
if ( !BYTE1(ipc[134]) )
return 0LL;
v0 = ipc[67];
if ( v0 <= 0 )
return 0LL;
func2(v0);
return 0LL;
}

original_code:
OSC_ERR OscIpcDestroy()
{
 uint8 i;
 for(i = 0; i < 2; i++)
  if(ipc.arybIpcChansBusy[i] == 1)
   if(ipc.aryIpcChans[i].sock > 0)
    OscIpcUnregisterChannel(ipc.aryIpcChans[i].sock);
 return SUCCESS;
}

canonical_original_code:
int OscIpcDestroy()
{
 unsigned char i;
 for(i = 0; i < 2; i++)
  if(ipc.arybIpcChansBusy[i] == 1)
   if(ipc.aryIpcChans[i].sock > 0)
    OscIpcUnregisterChannel(ipc.aryIpcChans[i].sock);
 return SUCCESS;
}

variable_types:
i
unsigned char


OscIpcRecv

decompiled_code:
__int64 __fastcall OscIpcRecv(unsigned __int8 a1, void *a2, unsigned int a3)
{
__int64 v3; // rax
__int64 v4; // rdi
int *v6; // rbx
int v7; // er15
int *v8; // rbp
int v9; // er14
size_t v10; // rdx
int v11; // eax
int v12; // edi
unsigned int v13; // er8
int v15; // edi
int v16; // eax
char *v17; // rax
char *v18; // rax
char *v19; // rax
size_t v20; // [rsp+0h] [rbp-C8h]
__int64 v21; // [rsp+8h] [rbp-C0h]
socklen_t addr_len; // [rsp+1Ch] [rbp-ACh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A8h] BYREF

v3 = a1;
v4 = 67LL * a1;
v6 = &ipc[v4];
v7 = ipc[v4 + 65];
v21 = v3;
v8 = _errno_location();
if ( (v7 & 1) != 0 )
{
v9 = v6[66];
if ( v9 <= 0 )
{
v15 = ipc[v4];
addr_len = 110;
v16 = accept(v15, &addr, &addr_len);
v6[66] = v16;
v9 = v16;
if ( v16 < 0 )
{
if ( *v8 != 11 )
{
v18 = strerror(*v8);
OscLog(3LL, "%s: Accepting connection failed! (%s)\n", "OscIpcRecv", v18);
return (unsigned int)-900;
}
return (unsigned int)-901;
}
v10 = a3;
if ( (v6[65] & 2) == 0 )
goto LABEL_12;
if ( fcntl(v16, 4, 2048LL) < 0 )
{
v19 = strerror(*v8);
OscLog(3LL, "%s: Unable to make socket non-blocking! (%s)\n", "OscIpcRecv", v19);
return (unsigned int)-900;
}
v9 = v6[66];
v7 = v6[65];
}
v10 = a3;
if ( (v7 & 2) != 0 )
goto LABEL_4;
}
else
{
v9 = ipc[v4];
v10 = a3;
if ( (v7 & 2) != 0 )
{
LABEL_4:
v20 = v10;
*v8 = 0;
v11 = recv(v9, a2, v10, 2);
v10 = v20;
if ( a3 != v11 )
goto LABEL_5;
goto LABEL_12;
}
}
LABEL_12:
*v8 = 0;
v11 = recv(v9, a2, v10, 256);
v13 = 0;
if ( a3 == v11 )
return v13;
LABEL_5:
v12 = *v8;
if ( *v8 != 11 )
{
if ( v12 | v11 )
{
v17 = strerror(v12);
OscLog(3LL, "%s: Reading pending messages failed! (%s)\n", "OscIpcRecv", v17);
return (unsigned int)-900;
}
close(ipc[67 * v21 + 66]);
ipc[67 * v21 + 66] = -1;
}
return (unsigned int)-901;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, void *a2, unsigned int a3)
{
__int64 v3; // rax
__int64 v4; // rdi
int *v6; // rbx
int v7; // er15
int *v8; // rbp
int v9; // er14
size_t v10; // rdx
int v11; // eax
int v12; // edi
unsigned int v13; // er8
int v15; // edi
int v16; // eax
char *v17; // rax
char *v18; // rax
char *v19; // rax
size_t v20; // [rsp+0h] [rbp-C8h]
__int64 v21; // [rsp+8h] [rbp-C0h]
socklen_t addr_len; // [rsp+1Ch] [rbp-ACh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A8h] BYREF

v3 = a1;
v4 = 67LL * a1;
v6 = &ipc[v4];
v7 = ipc[v4 + 65];
v21 = v3;
v8 = _errno_location();
if ( (v7 & 1) != 0 )
{
v9 = v6[66];
if ( v9 <= 0 )
{
v15 = ipc[v4];
addr_len = 110;
v16 = accept(v15, &addr, &addr_len);
v6[66] = v16;
v9 = v16;
if ( v16 < 0 )
{
if ( *v8 != 11 )
{
v18 = strerror(*v8);
OscLog(3LL, "%s: Accepting connection failed! (%s)\n", "OscIpcRecv", v18);
return (unsigned int)-900;
}
return (unsigned int)-901;
}
v10 = a3;
if ( (v6[65] & 2) == 0 )
goto LABEL_12;
if ( fcntl(v16, 4, 2048LL) < 0 )
{
v19 = strerror(*v8);
OscLog(3LL, "%s: Unable to make socket non-blocking! (%s)\n", "OscIpcRecv", v19);
return (unsigned int)-900;
}
v9 = v6[66];
v7 = v6[65];
}
v10 = a3;
if ( (v7 & 2) != 0 )
goto LABEL_4;
}
else
{
v9 = ipc[v4];
v10 = a3;
if ( (v7 & 2) != 0 )
{
LABEL_4:
v20 = v10;
*v8 = 0;
v11 = recv(v9, a2, v10, 2);
v10 = v20;
if ( a3 != v11 )
goto LABEL_5;
goto LABEL_12;
}
}
LABEL_12:
*v8 = 0;
v11 = recv(v9, a2, v10, 256);
v13 = 0;
if ( a3 == v11 )
return v13;
LABEL_5:
v12 = *v8;
if ( *v8 != 11 )
{
if ( v12 | v11 )
{
v17 = strerror(v12);
OscLog(3LL, "%s: Reading pending messages failed! (%s)\n", "OscIpcRecv", v17);
return (unsigned int)-900;
}
close(ipc[67 * v21 + 66]);
ipc[67 * v21 + 66] = -1;
}
return (unsigned int)-901;
}

original_code:
OSC_ERR OscIpcRecv(const uint8 chanID,
  void *pData,
  const uint32 dataLen)
{
 int ret;
 struct OSC_IPC_CHANNEL *pChan;
 struct sockaddr_un remoteAddr;
 socklen_t remoteAddrLen;
 int sock;
 pChan = &ipc.aryIpcChans[chanID];
 if(pChan->flags & F_IPC_SERVER)
 {
  if(pChan->acceptedSock <= 0)
  {
   remoteAddrLen = sizeof(remoteAddr);
   pChan->acceptedSock = accept(pChan->sock,
           (struct sockaddr*)&remoteAddr,
           &remoteAddrLen);
   if(pChan->acceptedSock < 0)
   {
    if((((*__errno_location ()) == 11) || ((*__errno_location ()) == 11)))
    {
     return -ENO_MSG_AVAIL;
    } else {
     OscLog(ERROR, "%s: Accepting connection failed! (%s)\n",
       __func__, strerror((*__errno_location ())));
     return -ESOCKET;
    }
   }
   if(pChan->flags & F_IPC_NONBLOCKING)
   {
    ret = fcntl(pChan->acceptedSock,
      4,
      04000);
    if(ret < 0)
    {
     OscLog(ERROR,
       "%s: Unable to make socket non-blocking! (%s)\n",
       __func__,
       strerror((*__errno_location ())));
     return -ESOCKET;
    }
   }
  }
  sock = pChan->acceptedSock;
 } else {
  sock = pChan->sock;
 }
 if(pChan->flags & F_IPC_NONBLOCKING)
 {
  (*__errno_location ()) = 0;
  ret = recv(sock,
    pData,
    dataLen,
    MSG_PEEK);
  if(ret != dataLen)
  {
   if(((*__errno_location ()) == 11 || (*__errno_location ()) == 11))
   {
    return -ENO_MSG_AVAIL;
   } else if((*__errno_location ()) == 0 && ret == 0) {
    close(pChan->acceptedSock);
    pChan->acceptedSock = -1;
    return -ENO_MSG_AVAIL;
   } else {
    OscLog(ERROR, "%s: Reading pending messages failed! (%s)\n",
      __func__, strerror((*__errno_location ())));
    return -ESOCKET;
   }
  }
 }
 (*__errno_location ()) = 0;
 ret = recv(sock,
   pData,
   dataLen,
   MSG_WAITALL);
 if(ret != dataLen)
 {
  if(((*__errno_location ()) == 11 || (*__errno_location ()) == 11))
  {
   return -ENO_MSG_AVAIL;
  } else if((*__errno_location ()) == 0 && ret == 0) {
   close(pChan->acceptedSock);
   pChan->acceptedSock = -1;
   return -ENO_MSG_AVAIL;
  } else {
   OscLog(ERROR, "%s: Reading pending messages failed! (%s)\n",
     __func__, strerror((*__errno_location ())));
   return -ESOCKET;
  }
 }
 return SUCCESS;
}

canonical_original_code:
int OscIpcRecv(unsigned char chanID, void *pData, unsigned int dataLen)
{
 int ret;
 struct OSC_IPC_CHANNEL *pChan;
 struct sockaddr_un remoteAddr;
 unsigned int remoteAddrLen;
 int sock;
 pChan = &ipc.aryIpcChans[chanID];
 if(pChan->flags & F_IPC_SERVER)
 {
  if(pChan->acceptedSock <= 0)
  {
   remoteAddrLen = sizeof(remoteAddr);
   pChan->acceptedSock = accept(pChan->sock,
           (struct sockaddr *)&remoteAddr,
           &remoteAddrLen);
   if(pChan->acceptedSock < 0)
   {
    if((((*__errno_location ()) == 11) || ((*__errno_location ()) == 11)))
    {
     return -ENO_MSG_AVAIL;
    } else {
     OscLog(ERROR, "%s: Accepting connection failed! (%s)\n",
       __func__, strerror((*__errno_location ())));
     return -ESOCKET;
    }
   }
   if(pChan->flags & F_IPC_NONBLOCKING)
   {
    ret = fcntl(pChan->acceptedSock,
      4,
      04000);
    if(ret < 0)
    {
     OscLog(ERROR,
       "%s: Unable to make socket non-blocking! (%s)\n",
       __func__,
       strerror((*__errno_location ())));
     return -ESOCKET;
    }
   }
  }
  sock = pChan->acceptedSock;
 } else {
  sock = pChan->sock;
 }
 if(pChan->flags & F_IPC_NONBLOCKING)
 {
  (*__errno_location ()) = 0;
  ret = recv(sock,
    pData,
    dataLen,
    MSG_PEEK);
  if(ret != dataLen)
  {
   if(((*__errno_location ()) == 11 || (*__errno_location ()) == 11))
   {
    return -ENO_MSG_AVAIL;
   } else if((*__errno_location ()) == 0 && ret == 0) {
    close(pChan->acceptedSock);
    pChan->acceptedSock = -1;
    return -ENO_MSG_AVAIL;
   } else {
    OscLog(ERROR, "%s: Reading pending messages failed! (%s)\n",
      __func__, strerror((*__errno_location ())));
    return -ESOCKET;
   }
  }
 }
 (*__errno_location ()) = 0;
 ret = recv(sock,
   pData,
   dataLen,
   MSG_WAITALL);
 if(ret != dataLen)
 {
  if(((*__errno_location ()) == 11 || (*__errno_location ()) == 11))
  {
   return -ENO_MSG_AVAIL;
  } else if((*__errno_location ()) == 0 && ret == 0) {
   close(pChan->acceptedSock);
   pChan->acceptedSock = -1;
   return -ENO_MSG_AVAIL;
  } else {
   OscLog(ERROR, "%s: Reading pending messages failed! (%s)\n",
     __func__, strerror((*__errno_location ())));
   return -ESOCKET;
  }
 }
 return SUCCESS;
}

variable_types:
pData
void *

variable_types:
dataLen
unsigned int

variable_types:
remoteAddrLen
unsigned int

variable_types: sock int

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


OscIpcRecvMsg

decompiled_code:
__int64 __fastcall OscIpcRecvMsg(unsigned __int8 a1, void *a2)
{
return OscIpcRecv(a1, a2, 0xCu);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1, void *a2)
{
return func4(a1, a2, 0xCu);
}

original_code:
inline OSC_ERR OscIpcRecvMsg(const uint8 chanID,
  struct OSC_IPC_MSG *pMsg)
{
 return OscIpcRecv(chanID, pMsg, sizeof(struct OSC_IPC_MSG));
}

canonical_original_code:
inline int OscIpcRecvMsg(unsigned char chanID, struct OSC_IPC_MSG *pMsg)
{
 return OscIpcRecv(chanID, pMsg, sizeof(struct OSC_IPC_MSG));
}

variable_types: struct OSC_IPC_MSG { enum EnIpcCmds { CMD_RD_PARAM=0, CMD_WR_PARAM=1, CMD_RD_PARAM_ACK=2, CMD_WR_PARAM_ACK=3, CMD_RD_PARAM_NACK=4, CMD_WR_PARAM_NACK=5 } enCmd; unsigned int paramID; unsigned int paramProp; } *

user_defined_types: struct OSC_IPC_MSG { enum EnIpcCmds enCmd; unsigned int paramID; unsigned int paramProp; }


OscIpcSend

decompiled_code:
__int64 __fastcall OscIpcSend(unsigned __int8 a1, char *a2, unsigned int a3)
{
__int64 v3; // rdi
unsigned int v5; // ebx
int v6; // er13
size_t v7; // r12
int v8; // eax
int v9; // edi
char *v11; // rax

v3 = 67LL * a1;
v5 = a3;
if ( (ipc[v3 + 65] & 1) != 0 )
v6 = ipc[v3 + 66];
else
v6 = ipc[v3];
v7 = a3;
if ( !a3 )
return 0LL;
while ( 1 )
{
while ( 1 )
{
v8 = send(v6, a2, v7, 0);
if ( v8 == -1 )
break;
a2 += v8;
v5 -= v8;
if ( !v5 )
return 0LL;
v7 = v5;
}
v9 = *_errno_location();
if ( v9 != 11 )
break;
usleep(0x1388u);
}
v11 = strerror(v9);
OscLog(3LL, "%s: Sending to remote process failed! (%s)\n", "OscIpcSend", v11);
return 4294966396LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1, char *a2, unsigned int a3)
{
__int64 v3; // rdi
unsigned int v5; // ebx
int v6; // er13
size_t v7; // r12
int v8; // eax
int v9; // edi
char *v11; // rax

v3 = 67LL * a1;
v5 = a3;
if ( (ipc[v3 + 65] & 1) != 0 )
v6 = ipc[v3 + 66];
else
v6 = ipc[v3];
v7 = a3;
if ( !a3 )
return 0LL;
while ( 1 )
{
while ( 1 )
{
v8 = send(v6, a2, v7, 0);
if ( v8 == -1 )
break;
a2 += v8;
v5 -= v8;
if ( !v5 )
return 0LL;
v7 = v5;
}
v9 = *_errno_location();
if ( v9 != 11 )
break;
usleep(0x1388u);
}
v11 = strerror(v9);
OscLog(3LL, "%s: Sending to remote process failed! (%s)\n", "OscIpcSend", v11);
return 4294966396LL;
}

original_code:
OSC_ERR OscIpcSend(const uint8 chanID,
  const void *pData,
  uint32 dataLen)
{
 int ret = 0;
 struct OSC_IPC_CHANNEL *pChan;
 int sock;
 pChan = &ipc.aryIpcChans[chanID];
 if(pChan->flags & F_IPC_SERVER)
 {
  sock = pChan->acceptedSock;
 } else {
  sock = pChan->sock;
 }
 while ( dataLen != 0 )
 {
  ret = send(sock, pData, dataLen, 0);
  if ((ret == -1))
  {
   if ( (*__errno_location ()) == 11 )
   {
    usleep(5000);
   } else
    break;
  }
  else
  {
   dataLen -= ret;
   pData = (char*)pData + ret;
  }
 }
 if((ret == -1))
 {
  OscLog(ERROR, "%s: Sending to remote process failed! (%s)\n",
    __func__, strerror((*__errno_location ())));
  return -ESOCKET;
 }
 return SUCCESS;
}

canonical_original_code:
int OscIpcSend(unsigned char chanID, void *pData, unsigned int dataLen)
{
 int ret = 0;
 struct OSC_IPC_CHANNEL *pChan;
 int sock;
 pChan = &ipc.aryIpcChans[chanID];
 if(pChan->flags & F_IPC_SERVER)
 {
  sock = pChan->acceptedSock;
 } else {
  sock = pChan->sock;
 }
 while ( dataLen != 0 )
 {
  ret = send(sock, pData, dataLen, 0);
  if ((ret == -1))
  {
   if ( (*__errno_location ()) == 11 )
   {
    usleep(5000);
   } else
    break;
  }
  else
  {
   dataLen -= ret;
   pData = (char *)pData + ret;
  }
 }
 if((ret == -1))
 {
  OscLog(ERROR, "%s: Sending to remote process failed! (%s)\n",
    __func__, strerror((*__errno_location ())));
  return -ESOCKET;
 }
 return SUCCESS;
}


OscIpcSendMsg

decompiled_code:
__int64 __fastcall OscIpcSendMsg(unsigned __int8 a1, char *a2)
{
return OscIpcSend(a1, a2, 0xCu);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 a1, char *a2)
{
return func6(a1, a2, 0xCu);
}

original_code:
inline OSC_ERR OscIpcSendMsg(const uint8 chanID,
  const struct OSC_IPC_MSG *pMsg)
{
 return OscIpcSend(chanID, (void*)pMsg, sizeof(struct OSC_IPC_MSG));
}

canonical_original_code:
inline int OscIpcSendMsg(unsigned char chanID, struct OSC_IPC_MSG *pMsg)
{
 return OscIpcSend(chanID, (void *)pMsg, sizeof(struct OSC_IPC_MSG));
}

user_defined_types: enum EnIpcCmds { CMD_RD_PARAM=0, CMD_WR_PARAM=1, CMD_RD_PARAM_ACK=2, CMD_WR_PARAM_ACK=3, CMD_RD_PARAM_NACK=4, CMD_WR_PARAM_NACK=5 }


ReadLine

decompiled_code:
__int64 __fastcall ReadLine(unsigned __int16 a1)
{
__int64 v1; // rbp
__int64 *v2; // rbx
__int64 result; // rax
int v4; // er13
bool v5; // zf
int v6; // er13
__int64 *v7; // r14
int v8; // ebx
__int64 v9; // r12
__int64 v10; // rdi
__int64 *v11; // r12
unsigned int v12; // [rsp+8h] [rbp-30h] BYREF
unsigned int v13; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = 45LL * a1;
v2 = &srd[v1];
result = _isoc99_fscanf(srd[v1 + 1], "%*1[@]");
if ( (_DWORD)result != -1 )
{
if ( (_DWORD)result )
{
OscLog(3LL, "%s: Missing line opening (@ \t)\n", (const char *)v2[2]);
result = 4294967279LL;
}
else
{
v4 = _isoc99_fscanf(v2[1], "\t%u", &v12);
OscLog(7LL, "Parsing time: %d\n", v12);
if ( v4 <= 0 )
{
OscLog(3LL, "%s: Missing time value (unsigned decimal number)\n", (const char *)v2[2]);
result = 4294967279LL;
}
else
{
v5 = *((_WORD *)v2 + 20) == 0;
*((_DWORD *)v2 + 7) = v12;
if ( v5 )
{
LABEL_10:
v9 = 45LL * a1;
v10 = srd[v9 + 1];
v11 = &srd[v9];
result = _isoc99_fscanf(v10, "\n");
if ( (_DWORD)result )
{
OscLog(3LL, "%s: Missing end of line.\n", (const char *)v11[2]);
result = 4294967279LL;
}
}
else
{
v6 = 0;
while ( 1 )
{
v7 = &srd[v1];
v8 = _isoc99_fscanf(srd[v1 + 1], "\t%u", &v13);
OscLog(7LL, "Parsing value: %d\n", v13);
if ( v8 <= 0 )
break;
LOBYTE(srd[2 * (unsigned __int16)v6++ + 7 + v1]) = v13 != 0;
if ( *((_WORD *)v7 + 20) <= (unsigned __int16)v6 )
goto LABEL_10;
}
OscLog(3LL, "%s: Missing signal value (unsigned decimal number).\n", (const char *)v7[2]);
result = 4294967279LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1)
{
__int64 v1; // rbp
__int64 *v2; // rbx
__int64 result; // rax
int v4; // er13
bool v5; // zf
int v6; // er13
__int64 *v7; // r14
int v8; // ebx
__int64 v9; // r12
__int64 v10; // rdi
__int64 *v11; // r12
unsigned int v12; // [rsp+8h] [rbp-30h] BYREF
unsigned int v13; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = 45LL * a1;
v2 = &srd[v1];
result = _isoc99_fscanf(srd[v1 + 1], "%*1[@]");
if ( (_DWORD)result != -1 )
{
if ( (_DWORD)result )
{
OscLog(3LL, "%s: Missing line opening (@ \t)\n", (const char *)v2[2]);
result = 4294967279LL;
}
else
{
v4 = _isoc99_fscanf(v2[1], "\t%u", &v12);
OscLog(7LL, "Parsing time: %d\n", v12);
if ( v4 <= 0 )
{
OscLog(3LL, "%s: Missing time value (unsigned decimal number)\n", (const char *)v2[2]);
result = 4294967279LL;
}
else
{
v5 = *((_WORD *)v2 + 20) == 0;
*((_DWORD *)v2 + 7) = v12;
if ( v5 )
{
LABEL_10:
v9 = 45LL * a1;
v10 = srd[v9 + 1];
v11 = &srd[v9];
result = _isoc99_fscanf(v10, "\n");
if ( (_DWORD)result )
{
OscLog(3LL, "%s: Missing end of line.\n", (const char *)v11[2]);
result = 4294967279LL;
}
}
else
{
v6 = 0;
while ( 1 )
{
v7 = &srd[v1];
v8 = _isoc99_fscanf(srd[v1 + 1], "\t%u", &v13);
OscLog(7LL, "Parsing value: %d\n", v13);
if ( v8 <= 0 )
break;
LOBYTE(srd[2 * (unsigned __int16)v6++ + 7 + v1]) = v13 != 0;
if ( *((_WORD *)v7 + 20) <= (unsigned __int16)v6 )
goto LABEL_10;
}
OscLog(3LL, "%s: Missing signal value (unsigned decimal number).\n", (const char *)v7[2]);
result = 4294967279LL;
}
}
}
}
return result;
}

original_code:
OSC_ERR ReadLine( uint16 rdId)
{
 int32 ret;
 uint16 sigId;
 uint32 time;
 uint32 value;
 ret = fscanf(srd.rd[ rdId].pFile, "%*1[@]");
 if( ret == (-1))
 {
  return (-1);
 }
 if( ret != 0)
 {
  OscLog(ERROR, "%s: Missing line opening (@ \t)\n", srd.rd[ rdId].strFile);
  return -EFILE_PARSING_ERROR;
 }
 ret = fscanf(srd.rd[ rdId].pFile, "\t%u", &time);
 OscLog(DEBUG, "Parsing time: %d\n", time);
 if( ret <= 0)
 {
  OscLog(ERROR, "%s: Missing time value  (unsigned decimal number)\n", srd.rd[ rdId].strFile);
  return -EFILE_PARSING_ERROR;
 }
 srd.rd[ rdId].readTime = time;
 for( sigId= 0; sigId<srd.rd[ rdId].nrOfSignals; sigId++)
 {
  ret = fscanf(srd.rd[ rdId].pFile, "\t%u", &value);
  OscLog(DEBUG, "Parsing value: %d\n", value);
  if( ret <= 0)
  {
   OscLog(ERROR, "%s: Missing signal value (unsigned decimal number).\n",
     srd.rd[ rdId].strFile);
   return -EFILE_PARSING_ERROR;
  }
  srd.rd[ rdId].sig[ sigId].bReadValue = value;
 }
 ret = fscanf(srd.rd[ rdId].pFile, "\n");
 if( ret != 0)
 {
  OscLog(ERROR, "%s: Missing end of line.\n", srd.rd[ rdId].strFile);
  return -EFILE_PARSING_ERROR;
 }
 return SUCCESS;
}

canonical_original_code:
int ReadLine(unsigned short rdId)
{
 int ret;
 unsigned short sigId;
 unsigned int time;
 unsigned int value;
 ret = fscanf(srd.rd[ rdId].pFile, "%*1[@]");
 if( ret == (-1))
 {
  return (-1);
 }
 if( ret != 0)
 {
  OscLog(ERROR, "%s: Missing line opening (@ \t)\n", srd.rd[ rdId].strFile);
  return -EFILE_PARSING_ERROR;
 }
 ret = fscanf(srd.rd[ rdId].pFile, "\t%u", &time);
 OscLog(DEBUG, "Parsing time: %d\n", time);
 if( ret <= 0)
 {
  OscLog(ERROR, "%s: Missing time value  (unsigned decimal number)\n", srd.rd[ rdId].strFile);
  return -EFILE_PARSING_ERROR;
 }
 srd.rd[ rdId].readTime = time;
 for( sigId= 0; sigId<srd.rd[ rdId].nrOfSignals; sigId++)
 {
  ret = fscanf(srd.rd[ rdId].pFile, "\t%u", &value);
  OscLog(DEBUG, "Parsing value: %d\n", value);
  if( ret <= 0)
  {
   OscLog(ERROR, "%s: Missing signal value (unsigned decimal number).\n",
     srd.rd[ rdId].strFile);
   return -EFILE_PARSING_ERROR;
  }
  srd.rd[ rdId].sig[ sigId].bReadValue = value;
 }
 ret = fscanf(srd.rd[ rdId].pFile, "\n");
 if( ret != 0)
 {
  OscLog(ERROR, "%s: Missing end of line.\n", srd.rd[ rdId].strFile);
  return -EFILE_PARSING_ERROR;
 }
 return SUCCESS;
}

variable_types:
rdId
unsigned short

variable_types:
sigId
unsigned short

variable_types:
time
unsigned int

variable_types:
value
unsigned int


OscSrdCycleCallback

decompiled_code:
void OscSrdCycleCallback()
{
int v0; // ebx
unsigned __int16 v1; // di

ReadAllDescriptor_isra_0();
if ( LOWORD(srd[0]) )
{
v0 = 0;
do
{
v1 = v0++;
GetNext_isra_0(v1);
}
while ( LOWORD(srd[0]) > (unsigned __int16)v0 );
}
}

canonical_decompiled_code:
void func4()
{
int v0; // ebx
unsigned __int16 v1; // di

func3();
if ( LOWORD(srd[0]) )
{
v0 = 0;
do
{
v1 = v0++;
func2(v1);
}
while ( LOWORD(srd[0]) > (unsigned __int16)v0 );
}
}

original_code:
void OscSrdCycleCallback( void)
{
 uint16 rdId;
 ReadAllDescriptor();
 for( rdId = 0; rdId < srd.nrOfReaders; rdId++)
 {
  GetNext( rdId);
 }
 return;
}

canonical_original_code:
void OscSrdCycleCallback()
{
 unsigned short rdId;
 ReadAllDescriptor();
 for( rdId = 0; rdId < srd.nrOfReaders; rdId++)
 {
  GetNext( rdId);
 }
 return;
}


OscSrdGetUpdateSignal

decompiled_code:
__int64 __fastcall OscSrdGetUpdateSignal(__int64 a1, _BYTE *a2)
{
*a2 = *(_BYTE *)(a1 + 9);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _BYTE *a2)
{
*a2 = *(_BYTE *)(a1 + 9);
return 0LL;
}

original_code:
OSC_ERR OscSrdGetUpdateSignal(
   void* pSignal,
   _Bool* pbValue)
{
 struct OSC_SRD_SIGNAL* pSig;
 pSig = pSignal;
 *pbValue = pSig->bActiveValue;
 return SUCCESS;
}

canonical_original_code:
int OscSrdGetUpdateSignal(void *pSignal, _Bool *pbValue)
{
 struct OSC_SRD_SIGNAL *pSig;
 pSig = pSignal;
 *pbValue = pSig->bActiveValue;
 return SUCCESS;
}

variable_types:
pSignal
void *

variable_types:
pbValue
_Bool *

variable_types: struct OSC_SRD_SIGNAL { char *strName; _Bool bReadValue; _Bool bActiveValue; } *


OscSimCreate

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

result = 0LL;
memset(&sim, 0, 0x328uLL);
return result;
}

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

result = 0LL;
memset(&sim, 0, 0x328uLL);
return result;
}

original_code:
OSC_ERR OscSimCreate()
{
 sim = (struct OSC_SIM_OBJ) { };
 return SUCCESS;
}

canonical_original_code:
int OscSimCreate()
{
 sim = (struct OSC_SIM_OBJ) { };
 return SUCCESS;
}

user_defined_types: struct OSC_SIM_OBJ { unsigned int curTimeStep; unsigned short numCycleCallback; void (*aryCycleCallback[100])(); }


OscSimInitialize

decompiled_code:
__int64 OscSimInitialize()
{
int v0; // ebx
__int64 v1; // rax

if ( !WORD2(sim[0]) )
return 0LL;
v0 = 0;
do
{
v1 = (unsigned __int16)v0++;
((void (*)(void))sim[v1 + 1])();
}
while ( WORD2(sim[0]) > (unsigned __int16)v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx
__int64 v1; // rax

if ( !WORD2(sim[0]) )
return 0LL;
v0 = 0;
do
{
v1 = (unsigned __int16)v0++;
((void (*)(void))sim[v1 + 1])();
}
while ( WORD2(sim[0]) > (unsigned __int16)v0 );
return 0LL;
}

original_code:
OSC_ERR OscSimInitialize() {
 uint16 i;
 for( i=0; i< sim.numCycleCallback; i++)
 {
  (*sim.aryCycleCallback[ i])();
 }
 return SUCCESS;
}

canonical_original_code:
int OscSimInitialize() {
 unsigned short i;
 for( i=0; i< sim.numCycleCallback; i++)
 {
  (*sim.aryCycleCallback[ i])();
 }
 return SUCCESS;
}

variable_types:
i
unsigned short


OscSimStep

decompiled_code:
__int64 OscSimStep()
{
int v0; // ebx
__int64 v1; // rax

++LODWORD(sim[0]);
if ( !WORD2(sim[0]) )
return 0LL;
v0 = 0;
do
{
v1 = (unsigned __int16)v0++;
((void (*)(void))sim[v1 + 1])();
}
while ( WORD2(sim[0]) > (unsigned __int16)v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebx
__int64 v1; // rax

++LODWORD(sim[0]);
if ( !WORD2(sim[0]) )
return 0LL;
v0 = 0;
do
{
v1 = (unsigned __int16)v0++;
((void (*)(void))sim[v1 + 1])();
}
while ( WORD2(sim[0]) > (unsigned __int16)v0 );
return 0LL;
}

original_code:
OSC_ERR OscSimStep() {
 uint16 i;
 sim.curTimeStep++;
 for( i=0; i< sim.numCycleCallback; i++)
 {
  (*sim.aryCycleCallback[ i])();
 }
 return SUCCESS;
}

canonical_original_code:
int OscSimStep() {
 unsigned short i;
 sim.curTimeStep++;
 for( i=0; i< sim.numCycleCallback; i++)
 {
  (*sim.aryCycleCallback[ i])();
 }
 return SUCCESS;
}


OscSimGetCurTimeStep

decompiled_code:
__int64 OscSimGetCurTimeStep()
{
return LODWORD(sim[0]);
}

canonical_decompiled_code:
__int64 func3()
{
return LODWORD(sim[0]);
}

original_code:
uint32 OscSimGetCurTimeStep()
{
 return sim.curTimeStep;
}

canonical_original_code:
unsigned int OscSimGetCurTimeStep()
{
 return sim.curTimeStep;
}

return_type: unsigned int


OscSimRegisterCycleCallback

decompiled_code:
__int64 __fastcall OscSimRegisterCycleCallback(__int64 a1)
{
unsigned __int16 v1; // ax
__int64 v2; // rdx
__int64 result; // rax

v1 = WORD2(sim[0]);
if ( v1 == 100 )
{
printf("Error: Maximum number of callback functions exhausted");
result = 4294966796LL;
}
else
{
v2 = v1;
WORD2(sim[0]) = v1 + 1;
result = 0LL;
sim[v2 + 1] = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned __int16 v1; // ax
__int64 v2; // rdx
__int64 result; // rax

v1 = WORD2(sim[0]);
if ( v1 == 100 )
{
printf("Error: Maximum number of callback functions exhausted");
result = 4294966796LL;
}
else
{
v2 = v1;
WORD2(sim[0]) = v1 + 1;
result = 0LL;
sim[v2 + 1] = a1;
}
return result;
}

original_code:
OSC_ERR OscSimRegisterCycleCallback( void (*pCallback)(void))
{
 uint16 id;
 id = sim.numCycleCallback;
 if( 100 == id)
 {
  printf("Error: Maximum number of callback functions exhausted");
  return -ENUM_CALLBACK_EXHAUSTED;
 }
 sim.aryCycleCallback[ id] = pCallback;
 sim.numCycleCallback++;
 return SUCCESS;
}

canonical_original_code:
int OscSimRegisterCycleCallback(void (*pCallback)())
{
 unsigned short id;
 id = sim.numCycleCallback;
 if( 100 == id)
 {
  printf("Error: Maximum number of callback functions exhausted");
  return -ENUM_CALLBACK_EXHAUSTED;
 }
 sim.aryCycleCallback[ id] = pCallback;
 sim.numCycleCallback++;
 return SUCCESS;
}

variable_types:
pCallback
void (*)()

variable_types:
id
unsigned short


OscDmaExtractWdSize

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

result = 2LL;
if ( (a1 & 4) == 0 )
result = (a1 & 8) == 0 ? 1 : 4;
return result;
}

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

result = 2LL;
if ( (a1 & 4) == 0 )
result = (a1 & 8) == 0 ? 1 : 4;
return result;
}

original_code:
uint8 OscDmaExtractWdSize(const uint16 dmaConfigMask)
{
 if(dmaConfigMask & 0x00000004)
 {
  return 2;
 }
 else if(dmaConfigMask & 0x00000008)
 {
  return 4;
 }
 else
 {
  return 1;
 }
}

canonical_original_code:
unsigned char OscDmaExtractWdSize(unsigned short dmaConfigMask)
{
 if(dmaConfigMask & 0x00000004)
 {
  return 2;
 }
 else if(dmaConfigMask & 0x00000008)
 {
  return 4;
 }
 else
 {
  return 1;
 }
}

variable_types:
dmaConfigMask
unsigned short

return_type: unsigned char


OscDmaChanCopy

original_code:
OSC_ERR OscDmaChanCopy(const struct DMA_DESC *pDesc,
  void *pTemp,
  const uint8 wdSize)
{
 uint32 x, y;
 uint8 *pRd8 = pTemp;
 uint8 *pWr8 = pTemp;
 uint16 *pRd16 = pTemp;
 uint16 *pWr16 = pTemp;
 uint32 *pRd32 = pTemp;
 uint32 *pWr32 = pTemp;
 int16 rdModX = 1;
 int16 rdModY = 1;
 int16 wrModX = 1;
 int16 wrModY = 1;
 void * pAddr;
 pAddr = (void*)pDesc->startAddr;
 if(pDesc->config & 0x00000002)
 {
  wrModX = pDesc->xModify/wdSize;
  wrModY = pDesc->yModify/wdSize;
  pWr8 = (uint8*)pAddr;
  pWr16 = (uint16*)pAddr;
  pWr32 = (uint32*)pAddr;
 }
 else
 {
  rdModX = pDesc->xModify/wdSize;
  rdModY = pDesc->yModify/wdSize;
  pRd8 = (uint8*)pAddr;
  pRd16 = (uint16*)pAddr;
  pRd32 = (uint32*)pAddr;
 }
 switch(wdSize)
 {
 case 1:
  for(y = 0; y < pDesc->yCount; y++)
  {
   for(x = 0; x < pDesc->xCount; x++)
   {
    *pWr8 = *pRd8;
    pWr8 += wrModX;
    pRd8 += rdModX;
   }
   pWr8 -= wrModX;
   pRd8 -= rdModX;
   pWr8 += wrModY;
   pRd8 += rdModY;
  }
  break;
 case 2:
  for(y = 0; y < pDesc->yCount; y++)
  {
   for(x = 0; x < pDesc->xCount; x++)
   {
    *pWr16 = *pRd16;
    pWr16 += wrModX;
    pRd16 += rdModX;
   }
   pWr16 -= wrModX;
   pRd16 -= rdModX;
   pWr16 += wrModY;
   pRd16 += rdModY;
  }
  break;
 case 4:
  for(y = 0; y < pDesc->yCount; y++)
  {
   for(x = 0; x < pDesc->xCount; x++)
   {
    *pWr32 = *pRd32;
    pWr32 += wrModX;
    pRd32 += rdModX;
   }
   pWr32 -= wrModX;
   pRd32 -= rdModX;
   pWr32 += wrModY;
   pRd32 += rdModY;
  }
  break;
 default:
  OscLog(ERROR, "%s: Invalid word size: %d\n", __func__, wdSize);
  return -EINVALID_PARAMETER;
 }
 return SUCCESS;
}

canonical_original_code:
int OscDmaChanCopy(struct DMA_DESC *pDesc, void *pTemp, unsigned char wdSize)
{
 unsigned int x; unsigned int y;
 unsigned char *pRd8 = pTemp;
 unsigned char *pWr8 = pTemp;
 unsigned short *pRd16 = pTemp;
 unsigned short *pWr16 = pTemp;
 unsigned int *pRd32 = pTemp;
 unsigned int *pWr32 = pTemp;
 short rdModX = 1;
 short rdModY = 1;
 short wrModX = 1;
 short wrModY = 1;
 void *pAddr;
 pAddr = (void *)pDesc->startAddr;
 if(pDesc->config & 0x00000002)
 {
  wrModX = pDesc->xModify/wdSize;
  wrModY = pDesc->yModify/wdSize;
  pWr8 = (unsigned char *)pAddr;
  pWr16 = (unsigned short *)pAddr;
  pWr32 = (unsigned int *)pAddr;
 }
 else
 {
  rdModX = pDesc->xModify/wdSize;
  rdModY = pDesc->yModify/wdSize;
  pRd8 = (unsigned char *)pAddr;
  pRd16 = (unsigned short *)pAddr;
  pRd32 = (unsigned int *)pAddr;
 }
 switch(wdSize)
 {
 case 1:
  for(y = 0; y < pDesc->yCount; y++)
  {
   for(x = 0; x < pDesc->xCount; x++)
   {
    *pWr8 = *pRd8;
    pWr8 += wrModX;
    pRd8 += rdModX;
   }
   pWr8 -= wrModX;
   pRd8 -= rdModX;
   pWr8 += wrModY;
   pRd8 += rdModY;
  }
  break;
 case 2:
  for(y = 0; y < pDesc->yCount; y++)
  {
   for(x = 0; x < pDesc->xCount; x++)
   {
    *pWr16 = *pRd16;
    pWr16 += wrModX;
    pRd16 += rdModX;
   }
   pWr16 -= wrModX;
   pRd16 -= rdModX;
   pWr16 += wrModY;
   pRd16 += rdModY;
  }
  break;
 case 4:
  for(y = 0; y < pDesc->yCount; y++)
  {
   for(x = 0; x < pDesc->xCount; x++)
   {
    *pWr32 = *pRd32;
    pWr32 += wrModX;
    pRd32 += rdModX;
   }
   pWr32 -= wrModX;
   pRd32 -= rdModX;
   pWr32 += wrModY;
   pRd32 += rdModY;
  }
  break;
 default:
  OscLog(ERROR, "%s: Invalid word size: %d\n", __func__, wdSize);
  return -EINVALID_PARAMETER;
 }
 return SUCCESS;
}

variable_types: struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } *

variable_types:
pTemp
void *

variable_types:
wdSize
unsigned char

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types: rdModX short

variable_types: rdModY short

variable_types: wrModX short

variable_types: wrModY short

variable_types:
pAddr
void *


OscDmaStart

decompiled_code:
void __fastcall OscDmaStart(__int64 a1)
{
unsigned __int16 v1; // r12
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // r14
unsigned __int8 v6; // si
int v7; // edx
unsigned __int8 v8; // al
__int64 v9; // rcx
char v10; // r8
unsigned __int8 v11; // bl
size_t v12; // rdi
int *v13; // rax
int *v14; // r15
unsigned int v15; // eax

if ( *(_DWORD *)(a1 + 4) )
{
v1 = 0;
while ( 1 )
{
v3 = 24LL * v1;
v4 = a1 + v3 + 8;
v5 = a1 + v3 + 128;
v6 = OscDmaExtractWdSize(*(_WORD *)(a1 + v3 + 16));
v8 = OscDmaExtractWdSize(*(_WORD *)(a1 + 24LL * v7 + 136));
v11 = v8;
if ( !v6 || !v8 )
{
OscLog(3LL, "%s: Invalid word sizes configured!\n", "OscDmaStart");
return;
}
v12 = v6 * (unsigned int)*(unsigned __int16 *)(v9 + 18);
if ( (v10 & 0x10) != 0 )
v12 = *(unsigned __int16 *)(v9 + 22) * (unsigned int)v12;
v13 = (int *)malloc(v12);
v14 = v13;
if ( !v13 )
break;
v15 = OscDmaChanCopy(v4, v13, v6);
if ( v15 )
{
OscLog(3LL, "%s: Source channel operation failed! (%d)\n", "OscDmaStart", v15);
free(v14);
return;
}
++v1;
OscDmaChanCopy(v5, v14, v11);
free(v14);
if ( (unsigned int)v1 >= *(_DWORD *)(a1 + 4) )
return;
}
OscLog(3LL, "%s: Memory allocation failed!\n", "OscDmaStart");
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
unsigned __int16 v1; // r12
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // r14
unsigned __int8 v6; // si
int v7; // edx
unsigned __int8 v8; // al
__int64 v9; // rcx
char v10; // r8
unsigned __int8 v11; // bl
size_t v12; // rdi
int *v13; // rax
int *v14; // r15
unsigned int v15; // eax

if ( *(_DWORD *)(a1 + 4) )
{
v1 = 0;
while ( 1 )
{
v3 = 24LL * v1;
v4 = a1 + v3 + 8;
v5 = a1 + v3 + 128;
v6 = func0(*(_WORD *)(a1 + v3 + 16));
v8 = func0(*(_WORD *)(a1 + 24LL * v7 + 136));
v11 = v8;
if ( !v6 || !v8 )
{
OscLog(3LL, "%s: Invalid word sizes configured!\n", "OscDmaStart");
return;
}
v12 = v6 * (unsigned int)*(unsigned __int16 *)(v9 + 18);
if ( (v10 & 0x10) != 0 )
v12 = *(unsigned __int16 *)(v9 + 22) * (unsigned int)v12;
v13 = (int *)malloc(v12);
v14 = v13;
if ( !v13 )
break;
v15 = func1(v4, v13, v6);
if ( v15 )
{
OscLog(3LL, "%s: Source channel operation failed! (%d)\n", "OscDmaStart", v15);
free(v14);
return;
}
++v1;
func1(v5, v14, v11);
free(v14);
if ( (unsigned int)v1 >= *(_DWORD *)(a1 + 4) )
return;
}
OscLog(3LL, "%s: Memory allocation failed!\n", "OscDmaStart");
}
}

original_code:
void OscDmaStart(void *hChainHandle)
{
 OSC_ERR err;
 uint32 srcDataSize;
 uint8 srcWdSize, dstWdSize;
 uint16 move;
 void* *pTempBuffer;
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc;
 struct DMA_DESC *pDstDesc;
 for(move = 0; move < pChain->nMoves; move++)
 {
  pSrcDesc = &pChain->arySrcDesc[move];
  pDstDesc = &pChain->aryDstDesc[move];
  srcWdSize = OscDmaExtractWdSize(pSrcDesc->config);
  dstWdSize = OscDmaExtractWdSize(pDstDesc->config);
  if(srcWdSize == 0 || dstWdSize == 0)
  {
   OscLog(ERROR, "%s: Invalid word sizes configured!\n",
     __func__);
   return;
  }
  srcDataSize = srcWdSize * pSrcDesc->xCount;
  if(pSrcDesc->config & 0x00000010)
  {
   srcDataSize *= pSrcDesc->yCount;
  }
  pTempBuffer = (void*)malloc(srcDataSize);
  if(pTempBuffer == ((void *)0))
  {
   OscLog(ERROR, "%s: Memory allocation failed!\n", __func__);
   return;
  }
  err = OscDmaChanCopy(pSrcDesc, pTempBuffer, srcWdSize);
  if(err != SUCCESS)
  {
   OscLog(ERROR, "%s: Source channel operation failed! (%d)\n",
     __func__, err);
   free(pTempBuffer);
   return;
  }
  OscDmaChanCopy(pDstDesc, pTempBuffer, dstWdSize);
  if(err != SUCCESS)
  {
   OscLog(ERROR, "%s: Dest channel operation failed! (%d)\n",
      __func__, err);
   free(pTempBuffer);
   return;
  }
  free(pTempBuffer);
 }
}

canonical_original_code:
void OscDmaStart(void *hChainHandle)
{
 int err;
 unsigned int srcDataSize;
 unsigned char srcWdSize; unsigned char dstWdSize;
 unsigned short move;
 void **pTempBuffer;
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc;
 struct DMA_DESC *pDstDesc;
 for(move = 0; move < pChain->nMoves; move++)
 {
  pSrcDesc = &pChain->arySrcDesc[move];
  pDstDesc = &pChain->aryDstDesc[move];
  srcWdSize = OscDmaExtractWdSize(pSrcDesc->config);
  dstWdSize = OscDmaExtractWdSize(pDstDesc->config);
  if(srcWdSize == 0 || dstWdSize == 0)
  {
   OscLog(ERROR, "%s: Invalid word sizes configured!\n",
     __func__);
   return;
  }
  srcDataSize = srcWdSize * pSrcDesc->xCount;
  if(pSrcDesc->config & 0x00000010)
  {
   srcDataSize *= pSrcDesc->yCount;
  }
  pTempBuffer = (void *)malloc(srcDataSize);
  if(pTempBuffer == ((void *)0))
  {
   OscLog(ERROR, "%s: Memory allocation failed!\n", __func__);
   return;
  }
  err = OscDmaChanCopy(pSrcDesc, pTempBuffer, srcWdSize);
  if(err != SUCCESS)
  {
   OscLog(ERROR, "%s: Source channel operation failed! (%d)\n",
     __func__, err);
   free(pTempBuffer);
   return;
  }
  OscDmaChanCopy(pDstDesc, pTempBuffer, dstWdSize);
  if(err != SUCCESS)
  {
   OscLog(ERROR, "%s: Dest channel operation failed! (%d)\n",
      __func__, err);
   free(pTempBuffer);
   return;
  }
  free(pTempBuffer);
 }
}

variable_types:
hChainHandle
void *

variable_types: err int

variable_types:
srcDataSize
unsigned int

variable_types:
srcWdSize
unsigned char

variable_types:
dstWdSize
unsigned char

variable_types:
move
unsigned short

variable_types:
pTempBuffer
void **

variable_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; } *


OscDmaSync

decompiled_code:
__int64 __fastcall OscDmaSync(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1 == 0 ? 0xFFFFFFFA : 0;
else
result = 4294967288LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1 == 0 ? 0xFFFFFFFA : 0;
else
result = 4294967288LL;
return result;
}

original_code:
OSC_ERR OscDmaSync(void *hChainHandle)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 if(pChain == ((void *)0))
 {
  return -EINVALID_PARAMETER;
 }
 if(pChain->syncFlag != 0)
 {
  return SUCCESS;
 }
 return -ETIMEOUT;
}

canonical_original_code:
int OscDmaSync(void *hChainHandle)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 if(pChain == ((void *)0))
 {
  return -EINVALID_PARAMETER;
 }
 if(pChain->syncFlag != 0)
 {
  return SUCCESS;
 }
 return -ETIMEOUT;
}


OscCamSetShutterWidth

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

result = OscCamSetRegisterValue(
11LL,
(unsigned __int16)((unsigned int)(25 * a1 + (cam[58] >> 1)) / cam[58]),
(unsigned int)(25 * a1 + (cam[58] >> 1)) % cam[58]);
if ( !(_DWORD)result )
cam[60] = a1;
return result;
}

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

result = OscCamSetRegisterValue(
11LL,
(unsigned __int16)((unsigned int)(25 * a1 + (cam[58] >> 1)) / cam[58]),
(unsigned int)(25 * a1 + (cam[58] >> 1)) % cam[58]);
if ( !(_DWORD)result )
cam[60] = a1;
return result;
}

original_code:
OSC_ERR OscCamSetShutterWidth(const uint32 usecs)
{
 uint32 nPixelClks;
 uint16 shutterWidth;
 OSC_ERR err;
 nPixelClks = (usecs*(25000000/1000000));
 shutterWidth = (uint16)
  ((nPixelClks + cam.curCamRowClks/2)/cam.curCamRowClks);
 err = OscCamSetRegisterValue(0x0B,
   (uint16)shutterWidth);
 if(err == SUCCESS)
 {
  cam.curExpTime = usecs;
 }
 return err;
}

canonical_original_code:
int OscCamSetShutterWidth(unsigned int usecs)
{
 unsigned int nPixelClks;
 unsigned short shutterWidth;
 int err;
 nPixelClks = (usecs*(25000000/1000000));
 shutterWidth = (uint16)
  ((nPixelClks + cam.curCamRowClks/2)/cam.curCamRowClks);
 err = OscCamSetRegisterValue(0x0B,
   (unsigned short)shutterWidth);
 if(err == SUCCESS)
 {
  cam.curExpTime = usecs;
 }
 return err;
}

variable_types:
usecs
unsigned int

variable_types:
nPixelClks
unsigned int

variable_types:
shutterWidth
unsigned short


OscCamGetShutterWidth

decompiled_code:
__int64 __fastcall OscCamGetShutterWidth(unsigned int *a1)
{
__int64 result; // rax
unsigned __int16 v2[5]; // [rsp+0h] [rbp-Ah] BYREF

if ( !a1 )
return 4294967288LL;
result = OscCamGetRegisterValue(11LL, v2);
if ( (int)result >= 0 )
{
*a1 = cam[58] * (unsigned int)v2[0] / 0x19;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
__int64 result; // rax
unsigned __int16 v2[5]; // [rsp+0h] [rbp-Ah] BYREF

if ( !a1 )
return 4294967288LL;
result = OscCamGetRegisterValue(11LL, v2);
if ( (int)result >= 0 )
{
*a1 = cam[58] * (unsigned int)v2[0] / 0x19;
result = 0LL;
}
return result;
}

original_code:
OSC_ERR OscCamGetShutterWidth(uint32 * pResult)
{
 uint16 shutterWidth;
 OSC_ERR err;
 if((pResult == ((void *)0)))
 {
  return -EINVALID_PARAMETER;
 }
 err = OscCamGetRegisterValue(0x0B,
   &shutterWidth);
 if((err < 0))
 {
  return err;
 }
 *pResult =
  (uint32)shutterWidth*cam.curCamRowClks/(25000000/1000000);
 return SUCCESS;
}

canonical_original_code:
int OscCamGetShutterWidth(unsigned int *pResult)
{
 unsigned short shutterWidth;
 int err;
 if((pResult == ((void *)0)))
 {
  return -EINVALID_PARAMETER;
 }
 err = OscCamGetRegisterValue(0x0B,
   &shutterWidth);
 if((err < 0))
 {
  return err;
 }
 *pResult =
  (unsigned int)shutterWidth*cam.curCamRowClks/(25000000/1000000);
 return SUCCESS;
}

variable_types:
pResult
unsigned int *


OscCamGetAreaOfInterest

decompiled_code:
__int64 __fastcall OscCamGetAreaOfInterest(unsigned __int16 *a1, unsigned __int16 *a2, unsigned __int16 *a3, unsigned __int16 *a4)
{
unsigned int v6; // er12
__int64 result; // rax
int v8; // edx
int v9; // eax
int v10; // eax

v6 = OscCamGetRegisterValue(1LL, a1);
if ( v6
|| (v6 = OscCamGetRegisterValue(2LL, a2)) != 0
|| (v6 = OscCamGetRegisterValue(4LL, a3)) != 0
|| (v6 = OscCamGetRegisterValue(3LL, a4)) != 0 )
{
OscLog(3LL, "%s: Error retrieving area of interest from camera!\n", "OscCamGetAreaOfInterest");
result = v6;
}
else
{
v8 = *a3;
cam[55] = *a1;
v9 = *a2;
cam[53] = v8;
cam[56] = v9;
cam[54] = *a4;
v10 = v8 + LOWORD(cam[59]);
if ( v10 < 660 )
v10 = 660;
cam[58] = v10;
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 *a1, unsigned __int16 *a2, unsigned __int16 *a3, unsigned __int16 *a4)
{
unsigned int v6; // er12
__int64 result; // rax
int v8; // edx
int v9; // eax
int v10; // eax

v6 = OscCamGetRegisterValue(1LL, a1);
if ( v6
|| (v6 = OscCamGetRegisterValue(2LL, a2)) != 0
|| (v6 = OscCamGetRegisterValue(4LL, a3)) != 0
|| (v6 = OscCamGetRegisterValue(3LL, a4)) != 0 )
{
OscLog(3LL, "%s: Error retrieving area of interest from camera!\n", "OscCamGetAreaOfInterest");
result = v6;
}
else
{
v8 = *a3;
cam[55] = *a1;
v9 = *a2;
cam[53] = v8;
cam[56] = v9;
cam[54] = *a4;
v10 = v8 + LOWORD(cam[59]);
if ( v10 < 660 )
v10 = 660;
cam[58] = v10;
result = v6;
}
return result;
}

original_code:
OSC_ERR OscCamGetAreaOfInterest(uint16 *pLowX,
  uint16 *pLowY,
  uint16 *pWidth,
  uint16 *pHeight)
{
 OSC_ERR err;
 if((err = OscCamGetRegisterValue(0x01, pLowX)) ||
   (err = OscCamGetRegisterValue(0x02, pLowY)) ||
   (err = OscCamGetRegisterValue(0x04, pWidth)) ||
   (err = OscCamGetRegisterValue(0x03, pHeight)))
 {
  OscLog(ERROR, "%s: Error retrieving area of interest from "
    "camera!\n", __func__);
  return err;
 }
 cam.capWin.col_off = *pLowX;
 cam.capWin.row_off = *pLowY;
 cam.capWin.width = *pWidth;
 cam.capWin.height = *pHeight;
 cam.curCamRowClks = cam.capWin.width + cam.curHorizBlank;
 if(cam.curCamRowClks < 660)
 {
  cam.curCamRowClks = 660;
 }
 return SUCCESS;
}

canonical_original_code:
int OscCamGetAreaOfInterest(unsigned short *pLowX, unsigned short *pLowY, unsigned short *pWidth, unsigned short *pHeight)
{
 int err;
 if((err = OscCamGetRegisterValue(0x01, pLowX)) ||
   (err = OscCamGetRegisterValue(0x02, pLowY)) ||
   (err = OscCamGetRegisterValue(0x04, pWidth)) ||
   (err = OscCamGetRegisterValue(0x03, pHeight)))
 {
  OscLog(ERROR, "%s: Error retrieving area of interest from "
    "camera!\n", __func__);
  return err;
 }
 cam.capWin.col_off = *pLowX;
 cam.capWin.row_off = *pLowY;
 cam.capWin.width = *pWidth;
 cam.capWin.height = *pHeight;
 cam.curCamRowClks = cam.capWin.width + cam.curHorizBlank;
 if(cam.curCamRowClks < 660)
 {
  cam.curCamRowClks = 660;
 }
 return SUCCESS;
}

variable_types:
pLowX
unsigned short *

variable_types:
pLowY
unsigned short *

variable_types:
pWidth
unsigned short *

variable_types:
pHeight
unsigned short *


OscCamSetBlackLevelOffset

decompiled_code:
__int64 __fastcall OscCamSetBlackLevelOffset(unsigned __int16 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rsi

v3 = (unsigned __int16)(4 * a1);
if ( 4 * a1 >= 256 )
v3 = 255LL;
OscCamSetRegisterValue(114LL, v3, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rsi

v3 = (unsigned __int16)(4 * a1);
if ( 4 * a1 >= 256 )
v3 = 255LL;
OscCamSetRegisterValue(114LL, v3, a3);
return 0LL;
}

original_code:
OSC_ERR OscCamSetBlackLevelOffset(const uint16 offset)
{
 uint16 reg;
 if( (offset<<2) > 0xff)
 {
  reg = 0xff;
 }
 else
 {
  reg = offset << 2;
 }
 OscCamSetRegisterValue( 0x72 , reg);
 return SUCCESS;
}

canonical_original_code:
int OscCamSetBlackLevelOffset(unsigned short offset)
{
 unsigned short reg;
 if( (offset<<2) > 0xff)
 {
  reg = 0xff;
 }
 else
 {
  reg = offset << 2;
 }
 OscCamSetRegisterValue( 0x72 , reg);
 return SUCCESS;
}

variable_types:
offset
unsigned short

variable_types:
reg
unsigned short


OscCamGetBlackLevelOffset

decompiled_code:
__int64 __fastcall OscCamGetBlackLevelOffset(_WORD *a1)
{
unsigned __int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

OscCamGetRegisterValue(114LL, v2);
*a1 = v2[0] >> 2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_WORD *a1)
{
unsigned __int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

OscCamGetRegisterValue(114LL, v2);
*a1 = v2[0] >> 2;
return 0LL;
}

original_code:
OSC_ERR OscCamGetBlackLevelOffset(uint16 *pOffset)
{
 uint16 reg;
 OscCamGetRegisterValue( 0x72 , &reg);
 *pOffset = reg >> 2;
 return SUCCESS;
}

canonical_original_code:
int OscCamGetBlackLevelOffset(unsigned short *pOffset)
{
 unsigned short reg;
 OscCamGetRegisterValue( 0x72 , &reg);
 *pOffset = reg >> 2;
 return SUCCESS;
}

variable_types:
pOffset
unsigned short *


OscCamCreateMultiBuffer

decompiled_code:
__int64 __fastcall OscCamCreateMultiBuffer(unsigned __int8 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // r8
unsigned __int8 *v3; // rcx
__int64 v4; // rsi
__int64 v5; // rax

v2 = a2;
if ( (unsigned __int8)(a1 - 2) <= 6u )
{
v3 = a2;
v4 = (__int64)&a2[a1];
while ( 1 )
{
v5 = *v3;
if ( (unsigned __int8)v5 > 8u )
break;
if ( !*(_QWORD *)&cam[6 * v5 + 4] )
{
OscLog(3LL, "%s: \t\t\t\t\tInvalid frame buffer in multibuffer.\n", "OscCamCreateMultiBuffer");
return 4294967288LL;
}
if ( ++v3 == (unsigned __int8 *)v4 )
return OscCamMultiBufferCreate((unsigned int)((_DWORD)cam + 194), a1, v2);
}
}
OscLog(3LL, "%s(%u, 0x%x): Invalid Parameter!\n", "OscCamCreateMultiBuffer", a1, v2);
return 4294967288LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // r8
unsigned __int8 *v3; // rcx
__int64 v4; // rsi
__int64 v5; // rax

v2 = a2;
if ( (unsigned __int8)(a1 - 2) <= 6u )
{
v3 = a2;
v4 = (__int64)&a2[a1];
while ( 1 )
{
v5 = *v3;
if ( (unsigned __int8)v5 > 8u )
break;
if ( !*(_QWORD *)&cam[6 * v5 + 4] )
{
OscLog(3LL, "%s: \t\t\t\t\tInvalid frame buffer in multibuffer.\n", "OscCamCreateMultiBuffer");
return 4294967288LL;
}
if ( ++v3 == (unsigned __int8 *)v4 )
return OscCamMultiBufferCreate((unsigned int)((_DWORD)cam + 194), a1, v2);
}
}
OscLog(3LL, "%s(%u, 0x%x): Invalid Parameter!\n", "OscCamCreateMultiBuffer", a1, v2);
return 4294967288LL;
}

original_code:
OSC_ERR OscCamCreateMultiBuffer(const uint8 multiBufferDepth,
  const uint8 bufferIDs[])
{
 int i;
 struct frame_buffer * pFB;
 if((multiBufferDepth < 2) ||
     (multiBufferDepth > 8))
 {
  OscLog(ERROR, "%s(%u, 0x%x): Invalid Parameter!\n",
    __func__, multiBufferDepth, bufferIDs);
  return -EINVALID_PARAMETER;
 }
 for(i = 0; i < multiBufferDepth; i++)
 {
  if(bufferIDs[i] > 8)
  {
   OscLog(ERROR, "%s(%u, 0x%x): Invalid Parameter!\n",
     __func__, multiBufferDepth, bufferIDs);
   return -EINVALID_PARAMETER;
  }
  pFB = &cam.fbufs[bufferIDs[i]];
  if(pFB->data == ((void *)0))
  {
   OscLog(ERROR, "%s: 					Invalid frame buffer in multibuffer.\n",
     __func__);
   return -EINVALID_PARAMETER;
  }
 }
 return OscCamMultiBufferCreate(&cam.multiBuffer,
   multiBufferDepth,
   bufferIDs);
}

canonical_original_code:
int OscCamCreateMultiBuffer(unsigned char multiBufferDepth, unsigned char bufferIDs[])
{
 int i;
 struct frame_buffer *pFB;
 if((multiBufferDepth < 2) ||
     (multiBufferDepth > 8))
 {
  OscLog(ERROR, "%s(%u, 0x%x): Invalid Parameter!\n",
    __func__, multiBufferDepth, bufferIDs);
  return -EINVALID_PARAMETER;
 }
 for(i = 0; i < multiBufferDepth; i++)
 {
  if(bufferIDs[i] > 8)
  {
   OscLog(ERROR, "%s(%u, 0x%x): Invalid Parameter!\n",
     __func__, multiBufferDepth, bufferIDs);
   return -EINVALID_PARAMETER;
  }
  pFB = &cam.fbufs[bufferIDs[i]];
  if(pFB->data == ((void *)0))
  {
   OscLog(ERROR, "%s: 					Invalid frame buffer in multibuffer.\n",
     __func__);
   return -EINVALID_PARAMETER;
  }
 }
 return OscCamMultiBufferCreate(&cam.multiBuffer,
   multiBufferDepth,
   bufferIDs);
}

variable_types:
multiBufferDepth
unsigned char

variable_types:
bufferIDs
unsigned char []

variable_types: i int

variable_types: struct frame_buffer { int size; int id; int flags; void *data; } *


OscCamDeleteMultiBuffer

decompiled_code:
__int64 OscCamDeleteMultiBuffer()
{
return OscCamMultiBufferDestroy((unsigned int)((_DWORD)cam + 194));
}

canonical_decompiled_code:
__int64 func6()
{
return OscCamMultiBufferDestroy((unsigned int)((_DWORD)cam + 194));
}

original_code:
OSC_ERR OscCamDeleteMultiBuffer()
{
 return OscCamMultiBufferDestroy(&cam.multiBuffer);
}

canonical_original_code:
int OscCamDeleteMultiBuffer()
{
 return OscCamMultiBufferDestroy(&cam.multiBuffer);
}


OscCamSetupPerspective

decompiled_code:
__int64 __fastcall OscCamSetupPerspective(unsigned int a1)
{
char v1; // bp
char v2; // bl
__int64 v3; // rdx
__int16 v4; // si
__int16 v5; // ax
unsigned __int16 v6; // si
unsigned __int16 v7; // ax
__int64 result; // rax
unsigned __int16 v9[13]; // [rsp+0h] [rbp-1Ah] BYREF

if ( a1 > 3 )
return 4294967288LL;
v1 = a1 & 1;
v2 = CSWTCH_15[a1];
OscCamGetRegisterValue(13LL, v9);
if ( v2 )
v4 = v9[0] | 0x10;
else
v4 = v9[0] & 0xFFEF;
v5 = v4;
v6 = v4 & 0xFFDF;
v7 = v5 | 0x20;
if ( v1 )
v6 = v7;
v9[0] = v6;
OscCamSetRegisterValue(13LL, v6, v3);
LOBYTE(cam[57]) = v1;
result = 0LL;
BYTE1(cam[57]) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
char v1; // bp
char v2; // bl
__int64 v3; // rdx
__int16 v4; // si
__int16 v5; // ax
unsigned __int16 v6; // si
unsigned __int16 v7; // ax
__int64 result; // rax
unsigned __int16 v9[13]; // [rsp+0h] [rbp-1Ah] BYREF

if ( a1 > 3 )
return 4294967288LL;
v1 = a1 & 1;
v2 = CSWTCH_15[a1];
OscCamGetRegisterValue(13LL, v9);
if ( v2 )
v4 = v9[0] | 0x10;
else
v4 = v9[0] & 0xFFEF;
v5 = v4;
v6 = v4 & 0xFFDF;
v7 = v5 | 0x20;
if ( v1 )
v6 = v7;
v9[0] = v6;
OscCamSetRegisterValue(13LL, v6, v3);
LOBYTE(cam[57]) = v1;
result = 0LL;
BYTE1(cam[57]) = v2;
return result;
}

original_code:
OSC_ERR OscCamSetupPerspective(const enum EnOscCamPerspective perspective)
{
 uint16 reg;
 _Bool rowFlip, colFlip;
 switch(perspective)
 {
 case OSC_CAM_PERSPECTIVE_DEFAULT:
  rowFlip = 0;
  colFlip = 0;
  break;
 case OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR:
  rowFlip = 0;
  colFlip = 1;
  break;
 case OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR:
  rowFlip = 1;
  colFlip = 0;
  break;
 case OSC_CAM_PERSPECTIVE_180DEG_ROTATE:
  rowFlip = 1;
  colFlip = 1;
  break;
 default:
  return -EINVALID_PARAMETER;
 }
 OscCamGetRegisterValue( 0x0D, &reg);
 if(rowFlip){
  reg = reg | (1<<4);
 } else {
  reg = reg & (0xffff ^ (1<<4));
 }
 if(colFlip){
  reg = reg | (1<<5);
 } else {
  reg = reg & (0xffff ^ (1<<5));
 }
 OscCamSetRegisterValue( 0x0D, reg);
 cam.flipHorizontal = colFlip;
 cam.flipVertical = rowFlip;
 return SUCCESS;
}

canonical_original_code:
int OscCamSetupPerspective(enum EnOscCamPerspective perspective)
{
 unsigned short reg;
 _Bool rowFlip; _Bool colFlip;
 switch(perspective)
 {
 case OSC_CAM_PERSPECTIVE_DEFAULT:
  rowFlip = 0;
  colFlip = 0;
  break;
 case OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR:
  rowFlip = 0;
  colFlip = 1;
  break;
 case OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR:
  rowFlip = 1;
  colFlip = 0;
  break;
 case OSC_CAM_PERSPECTIVE_180DEG_ROTATE:
  rowFlip = 1;
  colFlip = 1;
  break;
 default:
  return -EINVALID_PARAMETER;
 }
 OscCamGetRegisterValue( 0x0D, &reg);
 if(rowFlip){
  reg = reg | (1<<4);
 } else {
  reg = reg & (0xffff ^ (1<<4));
 }
 if(colFlip){
  reg = reg | (1<<5);
 } else {
  reg = reg & (0xffff ^ (1<<5));
 }
 OscCamSetRegisterValue( 0x0D, reg);
 cam.flipHorizontal = colFlip;
 cam.flipVertical = rowFlip;
 return SUCCESS;
}

variable_types: enum EnOscCamPerspective { OSC_CAM_PERSPECTIVE_DEFAULT=0, OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR=1, OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR=2, OSC_CAM_PERSPECTIVE_180DEG_ROTATE=3 }


decompiled_code:
__int64 __fastcall OscCamPerspectiveStr2Enum(const char *a1, _DWORD *a2)
{
bool v2; // zf
__int64 result; // rax

v2 = strcmp(a1, "DEFAULT") == 0;
result = !v2;
if ( v2 )
{
*a2 = 0;
}
else
{
v2 = strcmp(a1, "HMIRROR") == 0;
result = !v2;
if ( v2 )
{
*a2 = 1;
}
else
{
v2 = strcmp(a1, "VMIRROR") == 0;
result = !v2;
if ( v2 )
{
*a2 = 2;
}
else
{
v2 = strcmp(a1, "ROT180") == 0;
result = !v2;
if ( v2 )
{
*a2 = 3;
}
else
{
*a2 = 0;
result = 8LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, _DWORD *a2)
{
bool v2; // zf
__int64 result; // rax

v2 = strcmp(a1, "DEFAULT") == 0;
result = !v2;
if ( v2 )
{
*a2 = 0;
}
else
{
v2 = strcmp(a1, "HMIRROR") == 0;
result = !v2;
if ( v2 )
{
*a2 = 1;
}
else
{
v2 = strcmp(a1, "VMIRROR") == 0;
result = !v2;
if ( v2 )
{
*a2 = 2;
}
else
{
v2 = strcmp(a1, "ROT180") == 0;
result = !v2;
if ( v2 )
{
*a2 = 3;
}
else
{
*a2 = 0;
result = 8LL;
}
}
}
}
return result;
}

original_code:
OSC_ERR OscCamPerspectiveStr2Enum(const char *str, enum EnOscCamPerspective *per )
{
 OSC_ERR err = SUCCESS;
 if(0 == strcmp(str, "DEFAULT") )
 {
  *per = OSC_CAM_PERSPECTIVE_DEFAULT;
 } else {
  if(0 == strcmp(str, "HMIRROR") )
  {
   *per = OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR;
  } else {
   if(0 == strcmp(str, "VMIRROR") )
   {
    *per = OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR;
   } else {
    if(0 == strcmp(str, "ROT180") )
    {
     *per = OSC_CAM_PERSPECTIVE_180DEG_ROTATE;
    } else {
     err = EINVALID_PARAMETER;
     *per = OSC_CAM_PERSPECTIVE_DEFAULT;
    }
   }
  }
 }
 return err;
}

canonical_original_code:
int OscCamPerspectiveStr2Enum(char *str, enum EnOscCamPerspective *per)
{
 int err = SUCCESS;
 if(0 == strcmp(str, "DEFAULT") )
 {
  *per = OSC_CAM_PERSPECTIVE_DEFAULT;
 } else {
  if(0 == strcmp(str, "HMIRROR") )
  {
   *per = OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR;
  } else {
   if(0 == strcmp(str, "VMIRROR") )
   {
    *per = OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR;
   } else {
    if(0 == strcmp(str, "ROT180") )
    {
     *per = OSC_CAM_PERSPECTIVE_180DEG_ROTATE;
    } else {
     err = EINVALID_PARAMETER;
     *per = OSC_CAM_PERSPECTIVE_DEFAULT;
    }
   }
  }
 }
 return err;
}

variable_types:
str
char *

variable_types: enum EnOscCamPerspective { OSC_CAM_PERSPECTIVE_DEFAULT=0, OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR=1, OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR=2, OSC_CAM_PERSPECTIVE_180DEG_ROTATE=3 } *

variable_types: err int


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

if ( a1 == 2 )
{
*(_QWORD *)a2 = 0x524F5252494D56LL;
result = 0LL;
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
{
strcpy(a2, "ROT180");
result = 0LL;
}
else
{
OscLog(3LL, "%s: Invalid perspective parameter (%d).\n", "OscCamPerspectiveEnum2Str", a1);
result = 4294967288LL;
}
}
else
{
if ( a1 )
*(_QWORD *)a2 = 0x524F5252494D48LL;
else
*(_QWORD *)a2 = 0x544C5541464544LL;
result = 0LL;
}
return result;
}

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

if ( a1 == 2 )
{
*(_QWORD *)a2 = 0x524F5252494D56LL;
result = 0LL;
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
{
strcpy(a2, "ROT180");
result = 0LL;
}
else
{
OscLog(3LL, "%s: Invalid perspective parameter (%d).\n", "OscCamPerspectiveEnum2Str", a1);
result = 4294967288LL;
}
}
else
{
if ( a1 )
*(_QWORD *)a2 = 0x524F5252494D48LL;
else
*(_QWORD *)a2 = 0x544C5541464544LL;
result = 0LL;
}
return result;
}

original_code:
OSC_ERR OscCamPerspectiveEnum2Str(const enum EnOscCamPerspective per, char *str)
{
 switch(per)
 {
 case OSC_CAM_PERSPECTIVE_DEFAULT:
  sprintf( str, "%s", "DEFAULT");
  break;
 case OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR:
  sprintf( str, "%s", "HMIRROR");
  break;
 case OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR:
  sprintf( str, "%s", "VMIRROR");
  break;
 case OSC_CAM_PERSPECTIVE_180DEG_ROTATE:
  sprintf( str, "%s", "ROT180");
  break;
 default:
  OscLog(ERROR, "%s: Invalid perspective parameter (%d).\n", __func__, per);
  return -EINVALID_PARAMETER;
 }
 return SUCCESS;
}

canonical_original_code:
int OscCamPerspectiveEnum2Str(enum EnOscCamPerspective per, char *str)
{
 switch(per)
 {
 case OSC_CAM_PERSPECTIVE_DEFAULT:
  sprintf( str, "%s", "DEFAULT");
  break;
 case OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR:
  sprintf( str, "%s", "HMIRROR");
  break;
 case OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR:
  sprintf( str, "%s", "VMIRROR");
  break;
 case OSC_CAM_PERSPECTIVE_180DEG_ROTATE:
  sprintf( str, "%s", "ROT180");
  break;
 default:
  OscLog(ERROR, "%s: Invalid perspective parameter (%d).\n", __func__, per);
  return -EINVALID_PARAMETER;
 }
 return SUCCESS;
}

user_defined_types: enum EnOscCamPerspective { OSC_CAM_PERSPECTIVE_DEFAULT=0, OSC_CAM_PERSPECTIVE_HORIZONTAL_MIRROR=1, OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR=2, OSC_CAM_PERSPECTIVE_180DEG_ROTATE=3 }


OscCamPresetRegs

decompiled_code:
__int64 __fastcall OscCamPresetRegs(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ebx
__int64 v4; // rdx
int v5; // ebx
__int64 v6; // rdx
int v7; // ebx
__int64 v8; // rdx
int v9; // ebx
__int64 v10; // rdx
unsigned int v11; // eax
__int64 v12; // rdx
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
__int64 v18; // rdx

v3 = OscCamSetRegisterValue(12LL, 3LL, a3);
usleep(0x64u);
v5 = OscCamSetRegisterValue(7LL, 920LL, v4) | v3;
v7 = OscCamSetRegisterValue(15LL, 21LL, v6) | v5;
v9 = OscCamSetRegisterValue(32LL, 981LL, v8) | v7;
v11 = v9 | OscCamSetRegisterValue(175LL, 0LL, v10);
if ( !v11 )
{
v13 = OscCamSetBlackLevelOffset(0xDu, 0LL, v12);
if ( !v13 )
goto LABEL_3;
LABEL_10:
OscLog(3LL, "%s: Unable to set black level! (%d)\n", "OscCamPresetRegs", v13);
v14 = OscCamSetShutterWidth(15000);
if ( !v14 )
goto LABEL_4;
goto LABEL_11;
}
OscLog(3LL, "%s: Unable to set camera registers! (%d)\n", "OscCamPresetRegs", v11);
v13 = OscCamSetBlackLevelOffset(0xDu, (__int64)"%s: Unable to set camera registers! (%d)\n", v18);
if ( v13 )
goto LABEL_10;
LABEL_3:
v14 = OscCamSetShutterWidth(15000);
if ( !v14 )
goto LABEL_4;
LABEL_11:
OscLog(3LL, "%s: Unable to set shutter width! (%d)\n", "OscCamPresetRegs", v14);
LABEL_4:
v15 = OscCamSetAreaOfInterest(0LL, 0LL, 0LL, 0LL);
if ( v15 )
OscLog(3LL, "%s: Unable to set area of interest! (%d)\n", "OscCamPresetRegs", v15);
v16 = OscCamSetupPerspective(0);
if ( v16 )
OscLog(3LL, "%s: Unable to set up camera perspective! (%d)\n", "OscCamPresetRegs", v16);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ebx
__int64 v4; // rdx
int v5; // ebx
__int64 v6; // rdx
int v7; // ebx
__int64 v8; // rdx
int v9; // ebx
__int64 v10; // rdx
unsigned int v11; // eax
__int64 v12; // rdx
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
__int64 v18; // rdx

v3 = OscCamSetRegisterValue(12LL, 3LL, a3);
usleep(0x64u);
v5 = OscCamSetRegisterValue(7LL, 920LL, v4) | v3;
v7 = OscCamSetRegisterValue(15LL, 21LL, v6) | v5;
v9 = OscCamSetRegisterValue(32LL, 981LL, v8) | v7;
v11 = v9 | OscCamSetRegisterValue(175LL, 0LL, v10);
if ( !v11 )
{
v13 = func3(0xDu, 0LL, v12);
if ( !v13 )
goto LABEL_3;
LABEL_10:
OscLog(3LL, "%s: Unable to set black level! (%d)\n", "OscCamPresetRegs", v13);
v14 = func0(15000);
if ( !v14 )
goto LABEL_4;
goto LABEL_11;
}
OscLog(3LL, "%s: Unable to set camera registers! (%d)\n", "OscCamPresetRegs", v11);
v13 = func3(0xDu, (__int64)"%s: Unable to set camera registers! (%d)\n", v18);
if ( v13 )
goto LABEL_10;
LABEL_3:
v14 = func0(15000);
if ( !v14 )
goto LABEL_4;
LABEL_11:
OscLog(3LL, "%s: Unable to set shutter width! (%d)\n", "OscCamPresetRegs", v14);
LABEL_4:
v15 = OscCamSetAreaOfInterest(0LL, 0LL, 0LL, 0LL);
if ( v15 )
OscLog(3LL, "%s: Unable to set area of interest! (%d)\n", "OscCamPresetRegs", v15);
v16 = func7(0);
if ( v16 )
OscLog(3LL, "%s: Unable to set up camera perspective! (%d)\n", "OscCamPresetRegs", v16);
return 0LL;
}

original_code:
OSC_ERR OscCamPresetRegs()
{
 OSC_ERR err;
 err = OscCamSetRegisterValue( 0x0C, 3);
 usleep(100);
 err |= OscCamSetRegisterValue( 0x07, 0x398);
 err |= OscCamSetRegisterValue( 0x0F, 0x0015);
 err |= OscCamSetRegisterValue( 0x20, 0x3d5);
 err |= OscCamSetRegisterValue( 0xAF, 0x0);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set camera registers! (%d)\n",
    __func__, err);
 }
 err = OscCamSetBlackLevelOffset( 13);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set black level! (%d)\n",
    __func__, err);
 }
 err = OscCamSetShutterWidth( 15000);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set shutter width! (%d)\n",
    __func__, err);
 }
 err = OscCamSetAreaOfInterest(0,0,0,0);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set area of interest! (%d)\n",
    __func__, err);
 }
 err = OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_DEFAULT);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set up camera perspective! (%d)\n",
    __func__, err);
 }
 return SUCCESS;
}

canonical_original_code:
int OscCamPresetRegs()
{
 int err;
 err = OscCamSetRegisterValue( 0x0C, 3);
 usleep(100);
 err |= OscCamSetRegisterValue( 0x07, 0x398);
 err |= OscCamSetRegisterValue( 0x0F, 0x0015);
 err |= OscCamSetRegisterValue( 0x20, 0x3d5);
 err |= OscCamSetRegisterValue( 0xAF, 0x0);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set camera registers! (%d)\n",
    __func__, err);
 }
 err = OscCamSetBlackLevelOffset( 13);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set black level! (%d)\n",
    __func__, err);
 }
 err = OscCamSetShutterWidth( 15000);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set shutter width! (%d)\n",
    __func__, err);
 }
 err = OscCamSetAreaOfInterest(0,0,0,0);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set area of interest! (%d)\n",
    __func__, err);
 }
 err = OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_DEFAULT);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Unable to set up camera perspective! (%d)\n",
    __func__, err);
 }
 return SUCCESS;
}