OscDmaMemCpy

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

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; // ebx

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; // ebx

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

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

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

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

variable_types:
pSrcAddr
void *

return_type: int


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; // ebx
int v7; // edi
__int64 v8; // rax
char *v9; // rbp
int v10; // er12
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int v19; // eax
int v20; // edi
char *v21; // rax
struct sockaddr v22[9]; // [rsp+0h] [rbp-98h] 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;
}
v6 = 1;
}
else
{
v6 = 0;
}
v7 = socket(1, 1, 0);
ipc[67 * v6] = v7;
if ( (a3 & 2) != 0 && fcntl(v7, 4, 2048LL) < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
OscLog(3LL, "%s: Unable to make socket non-blocking! (%s)\n", "OscIpcRegisterChannel", v12);
return 4294966396LL;
}
v8 = 67LL * v6;
ipc[v8 + 65] = a3;
v9 = (char *)&ipc[v8 + 1];
strcpy(v9, a2);
if ( (a3 & 1) == 0 )
{
v22[0].sa_family = 1;
strcpy(v22[0].sa_data, a2);
v19 = strlen(v22[0].sa_data);
if ( connect(ipc[67 * v6], v22, v19 + 2) < 0 )
{
v20 = *_errno_location();
if ( v20 != 115 )
{
v21 = strerror(v20);
OscLog(3LL, "%s: Unable to connect socket! (%s)\n", "OscIpcRegisterChannel", v21);
close(ipc[67 * v6]);
unlink(v9);
return 4294966396LL;
}
OscLog(4LL, "%s: Socket not fully connected yet due to non-blocking operation...", "OscIpcRegisterChannel");
}
LABEL_16:
*a1 = v6;
*((_BYTE *)&ipc[134] + v6) = 1;
return 0LL;
}
v22[0].sa_family = 1;
strcpy(v22[0].sa_data, v9);
v10 = strlen(v22[0].sa_data);
unlink(v22[0].sa_data);
if ( bind(ipc[67 * v6], v22, v10 + 2) < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
OscLog(3LL, "%s: Unable to bind socket! (%s)\n", "OscIpcRegisterChannel", v14);
close(ipc[67 * v6]);
result = 4294966396LL;
}
else
{
if ( chmod(v22[0].sa_data, 0x1FFu) < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
OscLog(
4LL,
"%s: Unable to set access permissions of socket file node \"%s\"! (%s)",
"OscIpcRegisterChannel",
v22[0].sa_data,
v16);
}
if ( listen(ipc[67 * v6], 5) >= 0 )
goto LABEL_16;
v17 = _errno_location();
v18 = strerror(*v17);
OscLog(3LL, "%s: Unable to listen to socket! (%s)\n", "OscIpcRegisterChannel", v18);
close(ipc[67 * v6]);
unlink(v9);
result = 4294966396LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, const char *a2, int a3)
{
__int64 result; // rax
int v6; // ebx
int v7; // edi
__int64 v8; // rax
char *v9; // rbp
int v10; // er12
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int v19; // eax
int v20; // edi
char *v21; // rax
struct sockaddr v22[9]; // [rsp+0h] [rbp-98h] 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;
}
v6 = 1;
}
else
{
v6 = 0;
}
v7 = socket(1, 1, 0);
ipc[67 * v6] = v7;
if ( (a3 & 2) != 0 && fcntl(v7, 4, 2048LL) < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
OscLog(3LL, "%s: Unable to make socket non-blocking! (%s)\n", "OscIpcRegisterChannel", v12);
return 4294966396LL;
}
v8 = 67LL * v6;
ipc[v8 + 65] = a3;
v9 = (char *)&ipc[v8 + 1];
strcpy(v9, a2);
if ( (a3 & 1) == 0 )
{
v22[0].sa_family = 1;
strcpy(v22[0].sa_data, a2);
v19 = strlen(v22[0].sa_data);
if ( connect(ipc[67 * v6], v22, v19 + 2) < 0 )
{
v20 = *_errno_location();
if ( v20 != 115 )
{
v21 = strerror(v20);
OscLog(3LL, "%s: Unable to connect socket! (%s)\n", "OscIpcRegisterChannel", v21);
close(ipc[67 * v6]);
unlink(v9);
return 4294966396LL;
}
OscLog(4LL, "%s: Socket not fully connected yet due to non-blocking operation...", "OscIpcRegisterChannel");
}
LABEL_16:
*a1 = v6;
*((_BYTE *)&ipc[134] + v6) = 1;
return 0LL;
}
v22[0].sa_family = 1;
strcpy(v22[0].sa_data, v9);
v10 = strlen(v22[0].sa_data);
unlink(v22[0].sa_data);
if ( bind(ipc[67 * v6], v22, v10 + 2) < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
OscLog(3LL, "%s: Unable to bind socket! (%s)\n", "OscIpcRegisterChannel", v14);
close(ipc[67 * v6]);
result = 4294966396LL;
}
else
{
if ( chmod(v22[0].sa_data, 0x1FFu) < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
OscLog(
4LL,
"%s: Unable to set access permissions of socket file node \"%s\"! (%s)",
"OscIpcRegisterChannel",
v22[0].sa_data,
v16);
}
if ( listen(ipc[67 * v6], 5) >= 0 )
goto LABEL_16;
v17 = _errno_location();
v18 = strerror(*v17);
OscLog(3LL, "%s: Unable to listen to socket! (%s)\n", "OscIpcRegisterChannel", v18);
close(ipc[67 * v6]);
unlink(v9);
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)
{
int v2; // ebp
int v3; // edi

if ( a1 > 1u )
return 4294967288LL;
v2 = a1;
if ( !*((_BYTE *)&ipc[134] + a1) )
return 4294967288LL;
v3 = ipc[67 * a1];
if ( v3 > 0 )
close(v3);
if ( (ipc[67 * v2 + 65] & 1) != 0 )
unlink((const char *)&ipc[67 * a1 + 1]);
*((_BYTE *)&ipc[134] + v2) = 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]) )
{
v0 = ipc[67];
if ( v0 > 0 )
OscIpcUnregisterChannel(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)
{
int v4; // ebx
int v5; // er13
int *v6; // r13
int v7; // edi
int *v8; // rax
char *v9; // rax
unsigned int v10; // edx
int v11; // edi
char *v12; // rax
int *v13; // r14
int v14; // eax
int v15; // edi
char *v16; // rax
int *v17; // r14
int v18; // eax
__int64 v19; // rbx
socklen_t addr_len; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, void *a2, unsigned int a3)
{
int v4; // ebx
int v5; // er13
int *v6; // r13
int v7; // edi
int *v8; // rax
char *v9; // rax
unsigned int v10; // edx
int v11; // edi
char *v12; // rax
int *v13; // r14
int v14; // eax
int v15; // edi
char *v16; // rax
int *v17; // r14
int v18; // eax
__int64 v19; // rbx
socklen_t addr_len; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

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

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)
{
unsigned int v4; // ebx
int v5; // er12
__int64 result; // rax
int v7; // eax
int v8; // er13
int *v9; // rax
char *v10; // rax

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

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1, char *a2, unsigned int a3)
{
unsigned int v4; // ebx
int v5; // er12
__int64 result; // rax
int v7; // eax
int v8; // er13
int *v9; // rax
char *v10; // rax

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

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 result; // rax
int v2; // ebx
__int64 v3; // rax
__int64 *v4; // rax
int v5; // ebx
__int64 *v6; // rbp
int v7; // er14
unsigned int v8; // [rsp+8h] [rbp-30h] BYREF
unsigned int v9; // [rsp+Ch] [rbp-2Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1)
{
__int64 result; // rax
int v2; // ebx
__int64 v3; // rax
__int64 *v4; // rax
int v5; // ebx
__int64 *v6; // rbp
int v7; // er14
unsigned int v8; // [rsp+8h] [rbp-30h] BYREF
unsigned int v9; // [rsp+Ch] [rbp-2Ch] BYREF

result = _isoc99_fscanf(srd[45 * a1 + 1], "%*1[@]");
if ( (_DWORD)result != -1 )
{
if ( (_DWORD)result )
{
OscLog(3LL, "%s: Missing line opening (@ \t)\n", (const char *)srd[45 * a1 + 2]);
result = 4294967279LL;
}
else
{
v2 = _isoc99_fscanf(srd[45 * a1 + 1], "\t%u", &v9);
OscLog(7LL, "Parsing time: %d\n", v9);
if ( v2 <= 0 )
{
OscLog(3LL, "%s: Missing time value (unsigned decimal number)\n", (const char *)srd[45 * a1 + 2]);
result = 4294967279LL;
}
else
{
v3 = 45LL * a1;
HIDWORD(srd[v3 + 3]) = v9;
v4 = &srd[v3];
if ( *((_WORD *)v4 + 20) )
{
v5 = 0;
v6 = v4;
while ( 1 )
{
v7 = _isoc99_fscanf(v6[1], "\t%u", &v8);
OscLog(7LL, "Parsing value: %d\n", v8);
if ( v7 <= 0 )
break;
LOBYTE(srd[45 * a1 + 7 + 2 * (unsigned __int16)v5++]) = v8 != 0;
if ( *((_WORD *)v6 + 20) <= (unsigned __int16)v5 )
goto LABEL_8;
}
OscLog(3LL, "%s: Missing signal value (unsigned decimal number).\n", (const char *)srd[45 * a1 + 2]);
result = 4294967279LL;
}
else
{
LABEL_8:
result = _isoc99_fscanf(srd[45 * a1 + 1], "\n");
if ( (_DWORD)result )
{
OscLog(3LL, "%s: Missing end of line.\n", (const char *)srd[45 * a1 + 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:
__int64 OscSrdCycleCallback()
{
__int64 result; // rax
int v1; // ebx

result = ReadAllDescriptor();
if ( LOWORD(srd[0]) )
{
v1 = 0;
do
result = GetNext(v1++);
while ( LOWORD(srd[0]) > (unsigned __int16)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
int v1; // ebx

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

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

return_type: void


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

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

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

if ( !WORD2(sim[0]) )
return 0LL;
v0 = 0;
do
((void (*)(void))sim[(unsigned __int16)v0++ + 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

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

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

++LODWORD(sim[0]);
if ( !WORD2(sim[0]) )
return 0LL;
v0 = 0;
do
((void (*)(void))sim[(unsigned __int16)v0++ + 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 result; // rax

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

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

v1 = WORD2(sim[0]);
if ( v1 == 100 )
{
printf("Error: Maximum number of callback functions exhausted");
result = 4294966796LL;
}
else
{
sim[v1 + 1] = a1;
WORD2(sim[0]) = v1 + 1;
result = 0LL;
}
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 v2; // r14
_WORD *v3; // rax
_WORD *v4; // rbx
unsigned int v5; // eax
__int64 v6; // rbx
_WORD *v7; // rbx
__int16 v8; // r15
unsigned __int8 v9; // bp
unsigned __int8 v10; // al
unsigned __int8 v11; // r12
unsigned int v12; // edi
__int64 v13; // [rsp+0h] [rbp-48h]
__int64 v14; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
unsigned __int16 v2; // r14
_WORD *v3; // rax
_WORD *v4; // rbx
unsigned int v5; // eax
__int64 v6; // rbx
_WORD *v7; // rbx
__int16 v8; // r15
unsigned __int8 v9; // bp
unsigned __int8 v10; // al
unsigned __int8 v11; // r12
unsigned int v12; // edi
__int64 v13; // [rsp+0h] [rbp-48h]
__int64 v14; // [rsp+8h] [rbp-40h]

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

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

user_defined_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC 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;
}

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


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; // ebx
int v8; // edx
unsigned int v9; // 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");
}
else
{
cam[55] = *a1;
cam[56] = *a2;
v8 = *a3;
cam[53] = v8;
cam[54] = *a4;
v9 = v8 + LOWORD(cam[59]);
if ( v9 < 0x294 )
v9 = 660;
cam[58] = v9;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 *a1, unsigned __int16 *a2, unsigned __int16 *a3, unsigned __int16 *a4)
{
unsigned int v6; // ebx
int v8; // edx
unsigned int v9; // 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");
}
else
{
cam[55] = *a1;
cam[56] = *a2;
v8 = *a3;
cam[53] = v8;
cam[54] = *a4;
v9 = v8 + LOWORD(cam[59]);
if ( v9 < 0x294 )
v9 = 660;
cam[58] = v9;
}
return v6;
}

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)
{
unsigned __int16 v3; // si

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

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

v3 = 4 * a1;
if ( 4 * a1 >= 256 )
v3 = 255;
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, _BYTE *a2)
{
_BYTE *v2; // r8
_BYTE *v3; // rcx
__int64 v4; // rsi
__int64 result; // rax

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

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

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

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)
{
bool v1; // bl
__int64 v2; // rdx
__int64 result; // rax
__int16 v4; // si
char v5; // bp
unsigned __int16 v6; // ax
unsigned __int16 v7; // si
__int16 v8[13]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( a1 == 2 )
{
v1 = 0;
LABEL_5:
OscCamGetRegisterValue(13LL, v8);
v4 = v8[0] | 0x10;
v5 = 1;
goto LABEL_6;
}
if ( a1 > 2 )
{
v1 = 1;
result = 4294967288LL;
if ( a1 != 3 )
return result;
goto LABEL_5;
}
OscCamGetRegisterValue(13LL, v8);
v1 = a1 != 0;
v4 = v8[0] & 0xFFEF;
v5 = 0;
LABEL_6:
v6 = v4 | 0x20;
v7 = v4 & 0xFFDF;
if ( v1 )
v7 = v6;
v8[0] = v7;
OscCamSetRegisterValue(13LL, v7, v2);
LOBYTE(cam[57]) = v1;
BYTE1(cam[57]) = v5;
return 0LL;
}

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

if ( a1 == 2 )
{
v1 = 0;
LABEL_5:
OscCamGetRegisterValue(13LL, v8);
v4 = v8[0] | 0x10;
v5 = 1;
goto LABEL_6;
}
if ( a1 > 2 )
{
v1 = 1;
result = 4294967288LL;
if ( a1 != 3 )
return result;
goto LABEL_5;
}
OscCamGetRegisterValue(13LL, v8);
v1 = a1 != 0;
v4 = v8[0] & 0xFFEF;
v5 = 0;
LABEL_6:
v6 = v4 | 0x20;
v7 = v4 & 0xFFDF;
if ( v1 )
v7 = v6;
v8[0] = v7;
OscCamSetRegisterValue(13LL, v7, v2);
LOBYTE(cam[57]) = v1;
BYTE1(cam[57]) = v5;
return 0LL;
}

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
const char *v10; // rsi
__int64 v11; // rdx
__int64 v12; // rdx
unsigned int v13; // ebx
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax

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;
v10 = 0LL;
v13 = OscCamSetRegisterValue(175LL, 0LL, v11) | v9;
if ( v13 )
{
v10 = "%s: Unable to set camera registers! (%d)\n";
OscLog(3LL, "%s: Unable to set camera registers! (%d)\n", "OscCamPresetRegs", v13);
}
v14 = OscCamSetBlackLevelOffset(0xDu, (__int64)v10, v12);
if ( v14 )
OscLog(3LL, "%s: Unable to set black level! (%d)\n", "OscCamPresetRegs", v14);
v15 = OscCamSetShutterWidth(15000);
if ( v15 )
OscLog(3LL, "%s: Unable to set shutter width! (%d)\n", "OscCamPresetRegs", v15);
v16 = OscCamSetAreaOfInterest(0LL, 0LL, 0LL, 0LL);
if ( v16 )
OscLog(3LL, "%s: Unable to set area of interest! (%d)\n", "OscCamPresetRegs", v16);
v17 = OscCamSetupPerspective(0);
if ( v17 )
OscLog(3LL, "%s: Unable to set up camera perspective! (%d)\n", "OscCamPresetRegs", v17);
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
const char *v10; // rsi
__int64 v11; // rdx
__int64 v12; // rdx
unsigned int v13; // ebx
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax

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;
v10 = 0LL;
v13 = OscCamSetRegisterValue(175LL, 0LL, v11) | v9;
if ( v13 )
{
v10 = "%s: Unable to set camera registers! (%d)\n";
OscLog(3LL, "%s: Unable to set camera registers! (%d)\n", "OscCamPresetRegs", v13);
}
v14 = func3(0xDu, (__int64)v10, v12);
if ( v14 )
OscLog(3LL, "%s: Unable to set black level! (%d)\n", "OscCamPresetRegs", v14);
v15 = func0(15000);
if ( v15 )
OscLog(3LL, "%s: Unable to set shutter width! (%d)\n", "OscCamPresetRegs", v15);
v16 = OscCamSetAreaOfInterest(0LL, 0LL, 0LL, 0LL);
if ( v16 )
OscLog(3LL, "%s: Unable to set area of interest! (%d)\n", "OscCamPresetRegs", v16);
v17 = func7(0);
if ( v17 )
OscLog(3LL, "%s: Unable to set up camera perspective! (%d)\n", "OscCamPresetRegs", v17);
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;
}


OscCamGetBayerOrder

decompiled_code:
__int64 __fastcall OscCamGetBayerOrder(_DWORD *a1, unsigned __int16 a2, unsigned __int16 a3)
{
__int16 v3; // si
__int64 result; // rax

if ( a3 > 0x1DFu || a2 > 0x2EFu || !a1 )
return 4294967288LL;
v3 = a2 & 1;
if ( (a3 & 1) != 0 )
{
if ( v3 )
*a1 = 1;
else
*a1 = 3;
result = 0LL;
}
else
{
if ( v3 )
*a1 = 2;
else
*a1 = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, unsigned __int16 a2, unsigned __int16 a3)
{
__int16 v3; // si
__int64 result; // rax

if ( a3 > 0x1DFu || a2 > 0x2EFu || !a1 )
return 4294967288LL;
v3 = a2 & 1;
if ( (a3 & 1) != 0 )
{
if ( v3 )
*a1 = 1;
else
*a1 = 3;
result = 0LL;
}
else
{
if ( v3 )
*a1 = 2;
else
*a1 = 0;
result = 0LL;
}
return result;
}

original_code:
OSC_ERR OscCamGetBayerOrder(enum EnBayerOrder *pBayerOrderFirstRow,
       const uint16 xPos,
       const uint16 yPos)
{
 _Bool bFirstPixIsGreen;
 _Bool bFirstRowIsRed;
 if((pBayerOrderFirstRow == ((void *)0)) ||
  (xPos >= 752) ||
  (yPos >= 480))
 {
  return -EINVALID_PARAMETER;
 }
 bFirstRowIsRed = 0;
 bFirstPixIsGreen = 0;
 if(!(!((xPos) & 0x1)))
 {
  bFirstPixIsGreen = !bFirstPixIsGreen;
 }
 if(!(!((yPos) & 0x1)))
 {
  bFirstRowIsRed = !bFirstRowIsRed;
  bFirstPixIsGreen = !bFirstPixIsGreen;
 }
 if(bFirstRowIsRed)
 {
  if(bFirstPixIsGreen)
  {
   *pBayerOrderFirstRow = ROW_GRGR;
  } else {
   *pBayerOrderFirstRow = ROW_RGRG;
  }
 } else {
  if(bFirstPixIsGreen)
  {
   *pBayerOrderFirstRow = ROW_GBGB;
  } else {
   *pBayerOrderFirstRow = ROW_BGBG;
  }
 }
 return SUCCESS;
}

canonical_original_code:
int OscCamGetBayerOrder(enum EnBayerOrder *pBayerOrderFirstRow, unsigned short xPos, unsigned short yPos)
{
 _Bool bFirstPixIsGreen;
 _Bool bFirstRowIsRed;
 if((pBayerOrderFirstRow == ((void *)0)) ||
  (xPos >= 752) ||
  (yPos >= 480))
 {
  return -EINVALID_PARAMETER;
 }
 bFirstRowIsRed = 0;
 bFirstPixIsGreen = 0;
 if(!(!((xPos) & 0x1)))
 {
  bFirstPixIsGreen = !bFirstPixIsGreen;
 }
 if(!(!((yPos) & 0x1)))
 {
  bFirstRowIsRed = !bFirstRowIsRed;
  bFirstPixIsGreen = !bFirstPixIsGreen;
 }
 if(bFirstRowIsRed)
 {
  if(bFirstPixIsGreen)
  {
   *pBayerOrderFirstRow = ROW_GRGR;
  } else {
   *pBayerOrderFirstRow = ROW_RGRG;
  }
 } else {
  if(bFirstPixIsGreen)
  {
   *pBayerOrderFirstRow = ROW_GBGB;
  } else {
   *pBayerOrderFirstRow = ROW_BGBG;
  }
 }
 return SUCCESS;
}

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

variable_types:
xPos
unsigned short

variable_types:
yPos
unsigned short


OscGpioReaderCallback

decompiled_code:
__int64 OscGpioReaderCallback()
{
unsigned __int64 v0; // rbp
unsigned __int64 v1; // rbx
__int64 result; // rax
char v3[25]; // [rsp+Fh] [rbp-19h] BYREF

v0 = (unsigned int)((_DWORD)&gpio + 1560);
v1 = (unsigned int)((_DWORD)&gpio + 20);
do
{
if ( *(_QWORD *)v0 )
{
OscSrdGetUpdateSignal(*(_QWORD *)v0, v3);
if ( (*(_BYTE *)(v1 - 4) & 2) != 0 )
{
result = (unsigned __int8)v3[0] ^ 1u;
*(_BYTE *)v1 = v3[0] ^ 1;
}
else
{
result = (unsigned __int8)v3[0];
*(_BYTE *)v1 = v3[0];
}
}
v0 += 8LL;
v1 += 24LL;
}
while ( v1 != (_DWORD)&gpio + 1172 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int64 v0; // rbp
unsigned __int64 v1; // rbx
__int64 result; // rax
char v3[25]; // [rsp+Fh] [rbp-19h] BYREF

v0 = (unsigned int)((_DWORD)&gpio + 1560);
v1 = (unsigned int)((_DWORD)&gpio + 20);
do
{
if ( *(_QWORD *)v0 )
{
OscSrdGetUpdateSignal(*(_QWORD *)v0, v3);
if ( (*(_BYTE *)(v1 - 4) & 2) != 0 )
{
result = (unsigned __int8)v3[0] ^ 1u;
*(_BYTE *)v1 = v3[0] ^ 1;
}
else
{
result = (unsigned __int8)v3[0];
*(_BYTE *)v1 = v3[0];
}
}
v0 += 8LL;
v1 += 24LL;
}
while ( v1 != (_DWORD)&gpio + 1172 );
return result;
}

original_code:
void OscGpioReaderCallback()
{
 void *phSignalIn;
 _Bool bPolState;
 uint16 pinNr;
 for(pinNr = 0; pinNr < 48; pinNr++)
 {
  if(gpio.phSignalIn[pinNr])
  {
   phSignalIn = gpio.phSignalIn[pinNr];
   OscSrdGetUpdateSignal(phSignalIn,
     &bPolState);
   if(gpio.pins[pinNr].flags & 0x2)
   {
    gpio.pins[pinNr].bState = !bPolState;
   } else {
    gpio.pins[pinNr].bState = bPolState;
   }
  }
 }
}

canonical_original_code:
void OscGpioReaderCallback()
{
 void *phSignalIn;
 _Bool bPolState;
 unsigned short pinNr;
 for(pinNr = 0; pinNr < 48; pinNr++)
 {
  if(gpio.phSignalIn[pinNr])
  {
   phSignalIn = gpio.phSignalIn[pinNr];
   OscSrdGetUpdateSignal(phSignalIn,
     &bPolState);
   if(gpio.pins[pinNr].flags & 0x2)
   {
    gpio.pins[pinNr].bState = !bPolState;
   } else {
    gpio.pins[pinNr].bState = bPolState;
   }
  }
 }
}

variable_types:
phSignalIn
void *

variable_types:
pinNr
unsigned short


OscGpioSetupPolarity

decompiled_code:
__int64 __fastcall OscGpioSetupPolarity(unsigned int a1, unsigned __int8 a2)
{
if ( (*(_BYTE *)(*((_QWORD *)&gpio + 3 * a1 + 1) + 4LL) & 2) != 0 )
a2 ^= 1u;
*((_DWORD *)&gpio + 6 * a1 + 4) = *((_DWORD *)&gpio + 6 * a1 + 4) & 0xFFFFFFFD | a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned __int8 a2)
{
if ( (*(_BYTE *)(*((_QWORD *)&gpio + 3 * a1 + 1) + 4LL) & 2) != 0 )
a2 ^= 1u;
*((_DWORD *)&gpio + 6 * a1 + 4) = *((_DWORD *)&gpio + 6 * a1 + 4) & 0xFFFFFFFD | a2;
return 0LL;
}

original_code:
OSC_ERR OscGpioSetupPolarity(enum EnGpios enGpio, _Bool bLowActive)
{
 struct GPIO_PIN *pPin = &gpio.pins[enGpio];
 _Bool bPinLowActive;
 if(pPin->pDefConfig->defaultFlags & 0x2)
 {
  bPinLowActive = !bLowActive;
 } else {
  bPinLowActive = bLowActive;
 }
 pPin->flags = (pPin->flags & ~0x2) | bPinLowActive;
 return SUCCESS;
}

canonical_original_code:
int OscGpioSetupPolarity(enum EnGpios enGpio, _Bool bLowActive)
{
 struct GPIO_PIN *pPin = &gpio.pins[enGpio];
 _Bool bPinLowActive;
 if(pPin->pDefConfig->defaultFlags & 0x2)
 {
  bPinLowActive = !bLowActive;
 } else {
  bPinLowActive = bLowActive;
 }
 pPin->flags = (pPin->flags & ~0x2) | bPinLowActive;
 return SUCCESS;
}

variable_types: enum EnGpios { GPIO_IN1=4, GPIO_IN2=7, GPIO_OUT1=2, GPIO_OUT2=6 }

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

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


OscGpioWrite

decompiled_code:
__int64 __fastcall OscGpioWrite(unsigned int a1, char a2)
{
__int64 v2; // rcx
int v3; // eax
char v4; // dl
__int64 result; // rax
char v6[12]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = a2;
v2 = *((_QWORD *)&gpio + a1 + 147);
if ( v2 )
{
v3 = *((_DWORD *)&gpio + 6 * a1 + 4);
if ( (v3 & 1) != 0 )
{
if ( (v3 & 0x10) != 0 )
{
OscLog(
4LL,
"%s: Pin %s is reserved internally and can not currently be accessed by the application!\n",
"OscGpioWrite",
(const char *)(*((_QWORD *)&gpio + 3 * a1 + 1) + 8LL));
result = 4294967285LL;
}
else
{
v4 = v6[0];
*((_BYTE *)&gpio + 24 * a1 + 20) = v6[0];
if ( (v3 & 2) != 0 )
v6[0] = v4 ^ 1;
result = OscSwrUpdateSignal(v2, v6);
}
}
else
{
OscLog(
3LL,
"%s: Cannot write to an input (%s)\n",
"OscGpioWrite",
(const char *)(*((_QWORD *)&gpio + 3 * a1 + 1) + 8LL));
result = 4294967288LL;
}
}
else
{
OscLog(
3LL,
"%s: No file writer for pin %d found. This probably means that this GPIO is not available on your hardware platform.",
"OscGpioWrite",
a1);
result = 4294967288LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, char a2)
{
__int64 v2; // rcx
int v3; // eax
char v4; // dl
__int64 result; // rax
char v6[12]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = a2;
v2 = *((_QWORD *)&gpio + a1 + 147);
if ( v2 )
{
v3 = *((_DWORD *)&gpio + 6 * a1 + 4);
if ( (v3 & 1) != 0 )
{
if ( (v3 & 0x10) != 0 )
{
OscLog(
4LL,
"%s: Pin %s is reserved internally and can not currently be accessed by the application!\n",
"OscGpioWrite",
(const char *)(*((_QWORD *)&gpio + 3 * a1 + 1) + 8LL));
result = 4294967285LL;
}
else
{
v4 = v6[0];
*((_BYTE *)&gpio + 24 * a1 + 20) = v6[0];
if ( (v3 & 2) != 0 )
v6[0] = v4 ^ 1;
result = OscSwrUpdateSignal(v2, v6);
}
}
else
{
OscLog(
3LL,
"%s: Cannot write to an input (%s)\n",
"OscGpioWrite",
(const char *)(*((_QWORD *)&gpio + 3 * a1 + 1) + 8LL));
result = 4294967288LL;
}
}
else
{
OscLog(
3LL,
"%s: No file writer for pin %d found. This probably means that this GPIO is not available on your hardware platform.",
"OscGpioWrite",
a1);
result = 4294967288LL;
}
return result;
}

original_code:
OSC_ERR OscGpioWrite(enum EnGpios enGpio, _Bool bState)
{
 struct GPIO_PIN *pPin = &gpio.pins[enGpio];
 if((!gpio.phSignalOut[enGpio]))
 {
  OscLog(ERROR, "%s: No file writer for pin %d found. "
    "This probably "
    "means that this GPIO is not available on your "
    "hardware platform.", __func__, enGpio);
  return -EINVALID_PARAMETER;
 }
 if((!(pPin->flags & 0x1)))
 {
  OscLog(ERROR, "%s: Cannot write to an input (%s)\n",
    __func__, pPin->pDefConfig->name);
  return -EINVALID_PARAMETER;
 }
 if(pPin->flags & 0x10)
 {
  OscLog(WARN, "%s: Pin %s is reserved internally and can not "
     "currently be accessed by the application!\n",
     __func__, pPin->pDefConfig->name);
  return -EDEVICE_BUSY;
 }
 pPin->bState = bState;
 if(pPin->flags & 0x2)
 {
  bState = !bState;
 }
 return OscSwrUpdateSignal(gpio.phSignalOut[enGpio], &bState);
}

canonical_original_code:
int OscGpioWrite(enum EnGpios enGpio, _Bool bState)
{
 struct GPIO_PIN *pPin = &gpio.pins[enGpio];
 if((!gpio.phSignalOut[enGpio]))
 {
  OscLog(ERROR, "%s: No file writer for pin %d found. "
    "This probably "
    "means that this GPIO is not available on your "
    "hardware platform.", __func__, enGpio);
  return -EINVALID_PARAMETER;
 }
 if((!(pPin->flags & 0x1)))
 {
  OscLog(ERROR, "%s: Cannot write to an input (%s)\n",
    __func__, pPin->pDefConfig->name);
  return -EINVALID_PARAMETER;
 }
 if(pPin->flags & 0x10)
 {
  OscLog(WARN, "%s: Pin %s is reserved internally and can not "
     "currently be accessed by the application!\n",
     __func__, pPin->pDefConfig->name);
  return -EDEVICE_BUSY;
 }
 pPin->bState = bState;
 if(pPin->flags & 0x2)
 {
  bState = !bState;
 }
 return OscSwrUpdateSignal(gpio.phSignalOut[enGpio], &bState);
}

user_defined_types: enum EnGpios { GPIO_IN1=4, GPIO_IN2=7, GPIO_OUT1=2, GPIO_OUT2=6 }

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


OscGpioRead

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

if ( *((_QWORD *)&gpio + a1 + 195) )
{
result = *((_DWORD *)&gpio + 6 * a1 + 4) & 0x10;
if ( (*((_DWORD *)&gpio + 6 * a1 + 4) & 0x10) != 0 )
{
OscLog(
4LL,
"%s: Pin %s is reserved internally and can not currently be accessed by the application!\n",
"OscGpioRead",
(const char *)(*((_QWORD *)&gpio + 3 * a1 + 1) + 8LL));
result = 4294967285LL;
}
else
{
*a2 = *((_BYTE *)&gpio + 24 * a1 + 20);
}
}
else
{
OscLog(
3LL,
"%s: No file reader for pin %d found. This probably means that this GPIO is not available on your hardware platform.",
"OscGpioRead",
a1);
result = 4294967288LL;
}
return result;
}

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

if ( *((_QWORD *)&gpio + a1 + 195) )
{
result = *((_DWORD *)&gpio + 6 * a1 + 4) & 0x10;
if ( (*((_DWORD *)&gpio + 6 * a1 + 4) & 0x10) != 0 )
{
OscLog(
4LL,
"%s: Pin %s is reserved internally and can not currently be accessed by the application!\n",
"OscGpioRead",
(const char *)(*((_QWORD *)&gpio + 3 * a1 + 1) + 8LL));
result = 4294967285LL;
}
else
{
*a2 = *((_BYTE *)&gpio + 24 * a1 + 20);
}
}
else
{
OscLog(
3LL,
"%s: No file reader for pin %d found. This probably means that this GPIO is not available on your hardware platform.",
"OscGpioRead",
a1);
result = 4294967288LL;
}
return result;
}

original_code:
OSC_ERR OscGpioRead(enum EnGpios enGpio, _Bool *pbState)
{
 struct GPIO_PIN *pPin = &gpio.pins[enGpio];
 if((!gpio.phSignalIn[enGpio]))
 {
  OscLog(ERROR, "%s: No file reader for pin %d found. "
    "This probably "
    "means that this GPIO is not available on your "
    "hardware platform.", __func__, enGpio);
  return -EINVALID_PARAMETER;
 }
 if(pPin->flags & 0x10)
 {
  OscLog(WARN, "%s: Pin %s is reserved internally and can not "
     "currently be accessed by the application!\n",
     __func__, pPin->pDefConfig->name);
  return -EDEVICE_BUSY;
 }
 *pbState = pPin->bState;
 return SUCCESS;
}

canonical_original_code:
int OscGpioRead(enum EnGpios enGpio, _Bool *pbState)
{
 struct GPIO_PIN *pPin = &gpio.pins[enGpio];
 if((!gpio.phSignalIn[enGpio]))
 {
  OscLog(ERROR, "%s: No file reader for pin %d found. "
    "This probably "
    "means that this GPIO is not available on your "
    "hardware platform.", __func__, enGpio);
  return -EINVALID_PARAMETER;
 }
 if(pPin->flags & 0x10)
 {
  OscLog(WARN, "%s: Pin %s is reserved internally and can not "
     "currently be accessed by the application!\n",
     __func__, pPin->pDefConfig->name);
  return -EDEVICE_BUSY;
 }
 *pbState = pPin->bState;
 return SUCCESS;
}

variable_types:
pbState
_Bool *


OscGpioSetTestLed

decompiled_code:
__int64 __fastcall OscGpioSetTestLed(char a1)
{
gpio[668] = a1;
gpio[692] = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
gpio[668] = a1;
gpio[692] = a1;
return 0LL;
}

original_code:
OSC_ERR OscGpioSetTestLed(_Bool bOn)
{
 OSC_ERR err = SUCCESS;
 struct GPIO_PIN *pRed = &gpio.pins[28];
 struct GPIO_PIN *pGreen = &gpio.pins[27];
 pRed->bState = pGreen->bState = bOn;
 return err;
}

canonical_original_code:
int OscGpioSetTestLed(_Bool bOn)
{
 int err = SUCCESS;
 struct GPIO_PIN *pRed = &gpio.pins[28];
 struct GPIO_PIN *pGreen = &gpio.pins[27];
 pRed->bState = pGreen->bState = bOn;
 return err;
}


OscGpioToggleTestLed

decompiled_code:
__int64 OscGpioToggleTestLed()
{
gpio[692] ^= 1u;
gpio[668] ^= 1u;
return 0LL;
}

original_code:
OSC_ERR OscGpioToggleTestLed()
{
 OSC_ERR err = SUCCESS;
 struct GPIO_PIN *pRed = &gpio.pins[28];
 struct GPIO_PIN *pGreen = &gpio.pins[27];
 pRed->bState = !pRed->bState;
 pGreen->bState = !pGreen->bState;
 return err;
}

canonical_original_code:
int OscGpioToggleTestLed()
{
 int err = SUCCESS;
 struct GPIO_PIN *pRed = &gpio.pins[28];
 struct GPIO_PIN *pGreen = &gpio.pins[27];
 pRed->bState = !pRed->bState;
 pGreen->bState = !pGreen->bState;
 return err;
}


OscGpioTriggerImage

decompiled_code:
__int64 OscGpioTriggerImage()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 0LL;
}

original_code:
OSC_ERR OscGpioTriggerImage()
{
 return SUCCESS;
}

canonical_original_code:
int OscGpioTriggerImage()
{
 return SUCCESS;
}


OscGpioSetTestLedColor

decompiled_code:
__int64 __fastcall OscGpioSetTestLedColor(char a1, char a2)
{
gpio[692] = a1 != 0;
gpio[668] = a2 != 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, char a2)
{
gpio[692] = a1 != 0;
gpio[668] = a2 != 0;
return 0LL;
}

original_code:
OSC_ERR OscGpioSetTestLedColor(uint8 red, uint8 green)
{
 OSC_ERR err = SUCCESS;
 struct GPIO_PIN *pRed = &gpio.pins[28];
 struct GPIO_PIN *pGreen = &gpio.pins[27];
 pRed->bState = red ? 1 : 0;
 pGreen->bState = green ? 1 : 0;
 return err;
}

canonical_original_code:
int OscGpioSetTestLedColor(unsigned char red, unsigned char green)
{
 int err = SUCCESS;
 struct GPIO_PIN *pRed = &gpio.pins[28];
 struct GPIO_PIN *pGreen = &gpio.pins[27];
 pRed->bState = red ? 1 : 0;
 pGreen->bState = green ? 1 : 0;
 return err;
}

variable_types:
red
unsigned char

variable_types:
green
unsigned char


OscGpioConfigImageTrigger

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

if ( a1 )
{
if ( a1 == 1 )
{
gpio[644] = 1;
result = 0LL;
}
else
{
OscLog(3LL, "%s: Invalid trigger config for this hardware (%d)!\n", "OscGpioConfigImageTrigger", a1);
result = 4294967288LL;
}
}
else
{
gpio[644] = 0;
result = 0LL;
}
return result;
}

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

if ( a1 )
{
if ( a1 == 1 )
{
gpio[644] = 1;
result = 0LL;
}
else
{
OscLog(3LL, "%s: Invalid trigger config for this hardware (%d)!\n", "OscGpioConfigImageTrigger", a1);
result = 4294967288LL;
}
}
else
{
gpio[644] = 0;
result = 0LL;
}
return result;
}

original_code:
OSC_ERR OscGpioConfigImageTrigger(enum EnTriggerConfig enConfig)
{
 struct GPIO_PIN *pPin = &gpio.pins[26];
 if(enConfig == TRIGGER_INTERNAL)
 {
  pPin->bState = 0;
 } else if(enConfig == TRIGGER_EXTERNAL_IN2){
  pPin->bState = 1;
 } else {
  OscLog(ERROR, "%s: Invalid trigger config for this hardware (%d)!\n",
    __func__, enConfig);
  return -EINVALID_PARAMETER;
 }
 return SUCCESS;
}

canonical_original_code:
int OscGpioConfigImageTrigger(enum EnTriggerConfig enConfig)
{
 struct GPIO_PIN *pPin = &gpio.pins[26];
 if(enConfig == TRIGGER_INTERNAL)
 {
  pPin->bState = 0;
 } else if(enConfig == TRIGGER_EXTERNAL_IN2){
  pPin->bState = 1;
 } else {
  OscLog(ERROR, "%s: Invalid trigger config for this hardware (%d)!\n",
    __func__, enConfig);
  return -EINVALID_PARAMETER;
 }
 return SUCCESS;
}

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