OscCamGetBayerOrder

decompiled_code:
__int64 __fastcall OscCamGetBayerOrder(_DWORD *a1, unsigned __int16 a2, unsigned __int16 a3)
{
char 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)
{
char 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:
void OscGpioReaderCallback()
{
unsigned __int64 v0; // rbp
unsigned __int64 v1; // rbx
char v2; // al
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);
v2 = v3[0];
if ( (*(_BYTE *)(v1 - 4) & 2) != 0 )
v2 = v3[0] ^ 1;
*(_BYTE *)v1 = v2;
}
v1 += 24LL;
v0 += 8LL;
}
while ( (_UNKNOWN *)v1 != (_UNKNOWN *)((char *)&gpio + 1172) );
}

canonical_decompiled_code:
void func0()
{
unsigned __int64 v0; // rbp
unsigned __int64 v1; // rbx
char v2; // al
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);
v2 = v3[0];
if ( (*(_BYTE *)(v1 - 4) & 2) != 0 )
v2 = v3[0] ^ 1;
*(_BYTE *)v1 = v2;
}
v1 += 24LL;
v0 += 8LL;
}
while ( (_UNKNOWN *)v1 != (_UNKNOWN *)((char *)&gpio + 1172) );
}

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

return_type: void


OscGpioSetupPolarity

decompiled_code:
__int64 __fastcall OscGpioSetupPolarity(unsigned int a1, unsigned __int8 a2)
{
char *v2; // rdx
__int64 result; // rax

v2 = (char *)&gpio + 24 * a1;
if ( (*(_BYTE *)(*((_QWORD *)v2 + 1) + 4LL) & 2) != 0 )
a2 ^= 1u;
result = 0LL;
*((_DWORD *)v2 + 4) = *((_DWORD *)v2 + 4) & 0xFFFFFFFD | a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned __int8 a2)
{
char *v2; // rdx
__int64 result; // rax

v2 = (char *)&gpio + 24 * a1;
if ( (*(_BYTE *)(*((_QWORD *)v2 + 1) + 4LL) & 2) != 0 )
a2 ^= 1u;
result = 0LL;
*((_DWORD *)v2 + 4) = *((_DWORD *)v2 + 4) & 0xFFFFFFFD | a2;
return result;
}

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

return_type: int

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; // r8
char *v3; // rdx
int v4; // eax
__int64 result; // rax
char v6[12]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = gpio[a1 + 147];
v6[0] = a2;
if ( v2 )
{
v3 = (char *)&gpio[3 * a1];
v4 = *((_DWORD *)v3 + 4);
if ( (v4 & 1) != 0 )
{
if ( (v4 & 0x10) != 0 )
{
OscLog(
4LL,
"%s: Pin %s is reserved internally and can not currently be accessed by the application!\n",
"OscGpioWrite",
(const char *)(*((_QWORD *)v3 + 1) + 8LL));
result = 4294967285LL;
}
else
{
v3[20] = a2;
if ( (v4 & 2) != 0 )
v6[0] = a2 ^ 1;
result = OscSwrUpdateSignal(v2, v6);
}
}
else
{
OscLog(3LL, "%s: Cannot write to an input (%s)\n", "OscGpioWrite", (const char *)(*((_QWORD *)v3 + 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; // r8
char *v3; // rdx
int v4; // eax
__int64 result; // rax
char v6[12]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = gpio[a1 + 147];
v6[0] = a2;
if ( v2 )
{
v3 = (char *)&gpio[3 * a1];
v4 = *((_DWORD *)v3 + 4);
if ( (v4 & 1) != 0 )
{
if ( (v4 & 0x10) != 0 )
{
OscLog(
4LL,
"%s: Pin %s is reserved internally and can not currently be accessed by the application!\n",
"OscGpioWrite",
(const char *)(*((_QWORD *)v3 + 1) + 8LL));
result = 4294967285LL;
}
else
{
v3[20] = a2;
if ( (v4 & 2) != 0 )
v6[0] = a2 ^ 1;
result = OscSwrUpdateSignal(v2, v6);
}
}
else
{
OscLog(3LL, "%s: Cannot write to an input (%s)\n", "OscGpioWrite", (const char *)(*((_QWORD *)v3 + 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)
{
_QWORD *v2; // rdx
__int64 result; // rax

if ( gpio[a1 + 195] )
{
v2 = &gpio[3 * a1];
result = v2[2] & 0x10;
if ( (v2[2] & 0x10) != 0 )
{
OscLog(
4LL,
"%s: Pin %s is reserved internally and can not currently be accessed by the application!\n",
"OscGpioRead",
(const char *)(v2[1] + 8LL));
result = 4294967285LL;
}
else
{
*a2 = *((_BYTE *)v2 + 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)
{
_QWORD *v2; // rdx
__int64 result; // rax

if ( gpio[a1 + 195] )
{
v2 = &gpio[3 * a1];
result = v2[2] & 0x10;
if ( (v2[2] & 0x10) != 0 )
{
OscLog(
4LL,
"%s: Pin %s is reserved internally and can not currently be accessed by the application!\n",
"OscGpioRead",
(const char *)(v2[1] + 8LL));
result = 4294967285LL;
}
else
{
*a2 = *((_BYTE *)v2 + 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)
{
__int64 result; // rax

BYTE4(gpio[83]) = a1;
result = 0LL;
BYTE4(gpio[86]) = a1;
return result;
}

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

BYTE4(gpio[83]) = a1;
result = 0LL;
BYTE4(gpio[86]) = a1;
return result;
}

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

variable_types: err int


OscGpioToggleTestLed

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

BYTE4(gpio[86]) ^= 1u;
result = 0LL;
BYTE4(gpio[83]) ^= 1u;
return result;
}

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

BYTE4(gpio[86]) ^= 1u;
result = 0LL;
BYTE4(gpio[83]) ^= 1u;
return result;
}

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)
{
BYTE4(gpio[86]) = a1 != 0;
BYTE4(gpio[83]) = a2 != 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, char a2)
{
BYTE4(gpio[86]) = a1 != 0;
BYTE4(gpio[83]) = 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 )
{
BYTE4(gpio[80]) = 1;
result = 0LL;
}
else
{
OscLog(3LL, "%s: Invalid trigger config for this hardware (%d)!\n", "OscGpioConfigImageTrigger", a1);
result = 4294967288LL;
}
}
else
{
BYTE4(gpio[80]) = 0;
result = 0LL;
}
return result;
}

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

if ( a1 )
{
if ( a1 == 1 )
{
BYTE4(gpio[80]) = 1;
result = 0LL;
}
else
{
OscLog(3LL, "%s: Invalid trigger config for this hardware (%d)!\n", "OscGpioConfigImageTrigger", a1);
result = 4294967288LL;
}
}
else
{
BYTE4(gpio[80]) = 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 }


OscGpioInitPins

decompiled_code:
__int64 OscGpioInitPins()
{
char v0; // r14
__int64 v1; // rbx
unsigned int v2; // eax
__int64 v3; // rsi
unsigned int v4; // eax
__int64 v5; // r8
int v6; // eax
_QWORD *v7; // rdx
char v8; // al
unsigned int v9; // er15
__int64 v10; // rbp
unsigned int v11; // eax
unsigned int v12; // eax
char *v15; // [rsp+0h] [rbp-58h]
unsigned int v16; // [rsp+0h] [rbp-58h]
unsigned int v17; // [rsp+0h] [rbp-58h]
unsigned int v18; // [rsp+0h] [rbp-58h]
char v19; // [rsp+Fh] [rbp-49h]
int v20[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( !nrOfPins )
return 0LL;
v0 = 0;
v1 = (unsigned int)((_DWORD)&aryPinConfig + 8);
v15 = (char *)&aryPinConfig + 44 * (unsigned __int16)(nrOfPins - 1) + 52;
v19 = 0;
while ( 1 )
{
v9 = *(_DWORD *)(v1 - 8);
v10 = v1 - 8;
if ( v9 > 0x2F )
{
OscLog(3LL, "%s: Fatal! Invalid pin number for %s configured! (%d)\n", "OscGpioInitPins", (const char *)v1, v9);
return (unsigned int)-9;
}
v6 = *(_DWORD *)(v1 - 4);
if ( (v6 & 1) == 0 )
{
if ( !v0 )
{
v11 = OscSrdCreateReader("gpio_in.txt", OscGpioReaderCallback, (unsigned int)((_DWORD)gpio + 1168));
if ( v11 )
{
v17 = v11;
OscLog(3LL, "%s: Unable to create stimuli reader! (%d)\n", "OscGpioInitPins", v11);
return v17;
}
}
v0 = 1;
v12 = OscSrdRegisterSignal(gpio[146], v1, &gpio[v9 + 195]);
v5 = v12;
if ( v12 )
{
LABEL_14:
v16 = v5;
OscLog(3LL, "%s: Error registering signal %s! (%d)\n", "OscGpioInitPins", (const char *)v1, v5);
return v16;
}
goto LABEL_7;
}
if ( (v6 & 0x10) == 0 )
break;
LABEL_8:
v1 += 44LL;
v7 = &gpio[3 * (int)v9];
*((_DWORD *)v7 + 4) = v6;
v8 = *(_BYTE *)(v1 - 12);
v7[1] = v10;
*((_BYTE *)v7 + 20) = v8;
if ( (char *)v1 == v15 )
return 0;
}
if ( v19 || (v2 = OscSwrCreateWriter((unsigned int)((_DWORD)gpio + 1160), "gpio_out.txt", 1LL, 1LL)) == 0 )
{
v3 = gpio[145];
v20[0] = *(unsigned __int8 *)(v1 + 32);
v4 = OscSwrRegisterSignal(&gpio[v9 + 147], v3, v1, 0LL, v20, "%d", v15);
v19 = 1;
v5 = v4;
if ( v4 )
goto LABEL_14;
LABEL_7:
v6 = *(_DWORD *)(v1 - 4);
goto LABEL_8;
}
v18 = v2;
OscLog(3LL, "%s: Unable to create stimuli writer! (%d)\n", "OscGpioInitPins", v2);
return v18;
}

canonical_decompiled_code:
__int64 func9()
{
char v0; // r14
__int64 v1; // rbx
unsigned int v2; // eax
__int64 v3; // rsi
unsigned int v4; // eax
__int64 v5; // r8
int v6; // eax
_QWORD *v7; // rdx
char v8; // al
unsigned int v9; // er15
__int64 v10; // rbp
unsigned int v11; // eax
unsigned int v12; // eax
char *v15; // [rsp+0h] [rbp-58h]
unsigned int v16; // [rsp+0h] [rbp-58h]
unsigned int v17; // [rsp+0h] [rbp-58h]
unsigned int v18; // [rsp+0h] [rbp-58h]
char v19; // [rsp+Fh] [rbp-49h]
int v20[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( !nrOfPins )
return 0LL;
v0 = 0;
v1 = (unsigned int)((_DWORD)&aryPinConfig + 8);
v15 = (char *)&aryPinConfig + 44 * (unsigned __int16)(nrOfPins - 1) + 52;
v19 = 0;
while ( 1 )
{
v9 = *(_DWORD *)(v1 - 8);
v10 = v1 - 8;
if ( v9 > 0x2F )
{
OscLog(3LL, "%s: Fatal! Invalid pin number for %s configured! (%d)\n", "OscGpioInitPins", (const char *)v1, v9);
return (unsigned int)-9;
}
v6 = *(_DWORD *)(v1 - 4);
if ( (v6 & 1) == 0 )
{
if ( !v0 )
{
v11 = OscSrdCreateReader("gpio_in.txt", OscGpioReaderCallback, (unsigned int)((_DWORD)gpio + 1168));
if ( v11 )
{
v17 = v11;
OscLog(3LL, "%s: Unable to create stimuli reader! (%d)\n", "OscGpioInitPins", v11);
return v17;
}
}
v0 = 1;
v12 = OscSrdRegisterSignal(gpio[146], v1, &gpio[v9 + 195]);
v5 = v12;
if ( v12 )
{
LABEL_14:
v16 = v5;
OscLog(3LL, "%s: Error registering signal %s! (%d)\n", "OscGpioInitPins", (const char *)v1, v5);
return v16;
}
goto LABEL_7;
}
if ( (v6 & 0x10) == 0 )
break;
LABEL_8:
v1 += 44LL;
v7 = &gpio[3 * (int)v9];
*((_DWORD *)v7 + 4) = v6;
v8 = *(_BYTE *)(v1 - 12);
v7[1] = v10;
*((_BYTE *)v7 + 20) = v8;
if ( (char *)v1 == v15 )
return 0;
}
if ( v19 || (v2 = OscSwrCreateWriter((unsigned int)((_DWORD)gpio + 1160), "gpio_out.txt", 1LL, 1LL)) == 0 )
{
v3 = gpio[145];
v20[0] = *(unsigned __int8 *)(v1 + 32);
v4 = OscSwrRegisterSignal(&gpio[v9 + 147], v3, v1, 0LL, v20, "%d", v15);
v19 = 1;
v5 = v4;
if ( v4 )
goto LABEL_14;
LABEL_7:
v6 = *(_DWORD *)(v1 - 4);
goto LABEL_8;
}
v18 = v2;
OscLog(3LL, "%s: Unable to create stimuli writer! (%d)\n", "OscGpioInitPins", v2);
return v18;
}

original_code:
OSC_ERR OscGpioInitPins()
{
 uint16 pin;
 int pinNr;
 struct GPIO_PIN_CONFIG* pPinConfig;
 uint32 defaultValue;
 OSC_ERR err;
 _Bool bReaderCreated = 0;
 _Bool bWriterCreated = 0;
 for(pin = 0; pin < nrOfPins; pin++)
 {
  pPinConfig = &aryPinConfig[pin];
  pinNr = pPinConfig->pinNr;
  if(pinNr < 0 || pinNr >= 48)
  {
   OscLog(ERROR,
     "%s: Fatal! Invalid pin number for %s configured! (%d)\n",
     __func__, pPinConfig->name, pinNr);
   return -EDEVICE;
  }
  if(pPinConfig->defaultFlags & 0x1)
  {
   if((pPinConfig->defaultFlags & 0x10))
   {
    err = SUCCESS;
    goto skip_logging;
   }
   if(!bWriterCreated)
   {
    err = OscSwrCreateWriter(
      &gpio.hWriter, "gpio_out.txt",
      1, 1);
    if(err != SUCCESS)
    {
     OscLog(ERROR, "%s: Unable to create stimuli writer! (%d)\n",
       __func__, err);
     return err;
    }
    bWriterCreated = 1;
   }
   defaultValue = pPinConfig->defaultState ? 1 : 0;
   err = OscSwrRegisterSignal(&gpio.phSignalOut[pinNr],
     gpio.hWriter,
     pPinConfig->name,
     SWR_INTEGER,
     &defaultValue,
     "%d");
  } else {
   if(!bReaderCreated)
   {
    err = OscSrdCreateReader( "gpio_in.txt",
      &OscGpioReaderCallback,
      &gpio.hReader);
    if(err != SUCCESS)
    {
     OscLog(ERROR, "%s: Unable to create stimuli reader! (%d)\n",
       __func__, err);
     return err;
    }
    bReaderCreated = 1;
   }
   err = OscSrdRegisterSignal( gpio.hReader,
     pPinConfig->name,
     &gpio.phSignalIn[pinNr]);
  }
skip_logging:
  if((err != SUCCESS))
  {
   OscLog(ERROR, "%s: Error registering signal %s! (%d)\n",
     __func__, pPinConfig->name, err);
   return err;
  }
  gpio.pins[pinNr].pDefConfig = pPinConfig;
  gpio.pins[pinNr].flags = pPinConfig->defaultFlags;
  gpio.pins[pinNr].bState = pPinConfig->defaultState;
 }
 return SUCCESS;
}

canonical_original_code:
int OscGpioInitPins()
{
 unsigned short pin;
 int pinNr;
 struct GPIO_PIN_CONFIG *pPinConfig;
 unsigned int defaultValue;
 int err;
 _Bool bReaderCreated = 0;
 _Bool bWriterCreated = 0;
 for(pin = 0; pin < nrOfPins; pin++)
 {
  pPinConfig = &aryPinConfig[pin];
  pinNr = pPinConfig->pinNr;
  if(pinNr < 0 || pinNr >= 48)
  {
   OscLog(ERROR,
     "%s: Fatal! Invalid pin number for %s configured! (%d)\n",
     __func__, pPinConfig->name, pinNr);
   return -EDEVICE;
  }
  if(pPinConfig->defaultFlags & 0x1)
  {
   if((pPinConfig->defaultFlags & 0x10))
   {
    err = SUCCESS;
    goto skip_logging;
   }
   if(!bWriterCreated)
   {
    err = OscSwrCreateWriter(
      &gpio.hWriter, "gpio_out.txt",
      1, 1);
    if(err != SUCCESS)
    {
     OscLog(ERROR, "%s: Unable to create stimuli writer! (%d)\n",
       __func__, err);
     return err;
    }
    bWriterCreated = 1;
   }
   defaultValue = pPinConfig->defaultState ? 1 : 0;
   err = OscSwrRegisterSignal(&gpio.phSignalOut[pinNr],
     gpio.hWriter,
     pPinConfig->name,
     SWR_INTEGER,
     &defaultValue,
     "%d");
  } else {
   if(!bReaderCreated)
   {
    err = OscSrdCreateReader( "gpio_in.txt",
      &OscGpioReaderCallback,
      &gpio.hReader);
    if(err != SUCCESS)
    {
     OscLog(ERROR, "%s: Unable to create stimuli reader! (%d)\n",
       __func__, err);
     return err;
    }
    bReaderCreated = 1;
   }
   err = OscSrdRegisterSignal( gpio.hReader,
     pPinConfig->name,
     &gpio.phSignalIn[pinNr]);
  }
skip_logging:
  if((err != SUCCESS))
  {
   OscLog(ERROR, "%s: Error registering signal %s! (%d)\n",
     __func__, pPinConfig->name, err);
   return err;
  }
  gpio.pins[pinNr].pDefConfig = pPinConfig;
  gpio.pins[pinNr].flags = pPinConfig->defaultFlags;
  gpio.pins[pinNr].bState = pPinConfig->defaultState;
 }
 return SUCCESS;
}

variable_types:
pin
unsigned short

variable_types: pinNr int

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

variable_types:
defaultValue
unsigned int


OscSupCreate

decompiled_code:
__int64 OscSupCreate()
{
sup = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
sup = 0;
return 0LL;
}

original_code:
OSC_ERR OscSupCreate()
{
 sup = (struct OSC_SUP) { };
 return SUCCESS;
}

canonical_original_code:
int OscSupCreate()
{
 sup = (struct OSC_SUP) { };
 return SUCCESS;
}


OscSupWdtInit

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

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

original_code:
OSC_ERR OscSupWdtInit()
{
 return SUCCESS;
}

canonical_original_code:
int OscSupWdtInit()
{
 return SUCCESS;
}


OscSupWdtClose

decompiled_code:
__int64 OscSupWdtClose()
{
return OscSupWdtInit();
}

canonical_decompiled_code:
__int64 func2()
{
return func1();
}

original_code:
OSC_ERR OscSupWdtClose()
{
 return SUCCESS;
}

canonical_original_code:
int OscSupWdtClose()
{
 return SUCCESS;
}


OscSupWdtKeepAlive

decompiled_code:
void OscSupWdtKeepAlive()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
inline void OscSupWdtKeepAlive()
{
}

canonical_original_code:
inline void OscSupWdtKeepAlive()
{
}


OscSupCycGet

decompiled_code:
__int64 OscSupCycGet()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (unsigned int)(LODWORD(v1.tv_usec) + 1000000 * LODWORD(v1.tv_sec));
}

canonical_decompiled_code:
__int64 func4()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (unsigned int)(LODWORD(v1.tv_usec) + 1000000 * LODWORD(v1.tv_sec));
}

original_code:
inline uint32 OscSupCycGet()
{
 struct timeval tim;
 gettimeofday(&tim, ((void *)0));
 return ((uint32)tim.tv_sec*1000000+tim.tv_usec);
}

canonical_original_code:
inline unsigned int OscSupCycGet()
{
 struct timeval tim;
 gettimeofday(&tim, ((void *)0));
 return ((unsigned int)tim.tv_sec*1000000+tim.tv_usec);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: unsigned int


decompiled_code:
__suseconds_t OscSupCycGet64()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func5()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
inline long long OscSupCycGet64()
{
 struct timeval tim;
 gettimeofday(&tim, ((void *)0));
 return ((long long)tim.tv_sec*1000000+(long long)tim.tv_usec);
}

return_type: long long

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


OscSupCycToMicroSecs

decompiled_code:
__int64 __fastcall OscSupCycToMicroSecs(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
return a1;
}

original_code:
inline uint32 OscSupCycToMicroSecs(uint32 cycles)
{
 return (cycles);
}

canonical_original_code:
inline unsigned int OscSupCycToMicroSecs(unsigned int cycles)
{
 return (cycles);
}

variable_types:
cycles
unsigned int


OscSupCycToMilliSecs

decompiled_code:
unsigned __int64 __fastcall OscSupCycToMilliSecs(unsigned int a1)
{
return a1 / 0x3E8uLL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(unsigned int a1)
{
return a1 / 0x3E8uLL;
}

original_code:
inline uint32 OscSupCycToMilliSecs(uint32 cycles)
{
 return (cycles/1000);
}

canonical_original_code:
inline unsigned int OscSupCycToMilliSecs(unsigned int cycles)
{
 return (cycles/1000);
}


OscSupCycToSecs

decompiled_code:
unsigned __int64 __fastcall OscSupCycToSecs(unsigned int a1)
{
return a1 / 0xF4240uLL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned int a1)
{
return a1 / 0xF4240uLL;
}

original_code:
inline uint32 OscSupCycToSecs(uint32 cycles)
{
 return (cycles/1000000);
}

canonical_original_code:
inline unsigned int OscSupCycToSecs(unsigned int cycles)
{
 return (cycles/1000000);
}


decompiled_code:
__int64 __fastcall OscSupCycToMicroSecs64(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return a1;
}

original_code:
inline long long OscSupCycToMicroSecs64(long long cycles)
{
 return (cycles);
}

variable_types:
cycles
long long


decompiled_code:
__int64 __fastcall OscSupCycToMilliSecs64(__int64 a1)
{
return a1 / 1000;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return a1 / 1000;
}

original_code:
inline long long OscSupCycToMilliSecs64(long long cycles)
{
 return (cycles/1000);
}


decompiled_code:
__int64 __fastcall OscSupCycToSecs64(__int64 a1)
{
return a1 / 1000000;
}

original_code:
inline long long OscSupCycToSecs64(long long cycles)
{
 return (cycles/1000000);
}


decompiled_code:
void *__fastcall OscSupSramAllocL1DataA(size_t size)
{
void *result; // rax

if ( (unsigned int)size > 0x4000 )
result = 0LL;
else
result = malloc((unsigned int)size);
return result;
}

canonical_decompiled_code:
void *__fastcall func12(size_t size)
{
void *result; // rax

if ( (unsigned int)size > 0x4000 )
result = 0LL;
else
result = malloc((unsigned int)size);
return result;
}

original_code:
void* OscSupSramAllocL1DataA(unsigned int size)
{
 if(size > 0x4000)
  return ((void *)0);
 return malloc(size);
}

canonical_original_code:
void *OscSupSramAllocL1DataA(unsigned int size)
{
 if(size > 0x4000)
  return ((void *)0);
 return malloc(size);
}

variable_types:
size
unsigned int

return_type: void *


decompiled_code:
// attributes: thunk
void *__fastcall OscSupSramAllocL1DataB(size_t size)
{
return OscSupSramAllocL1DataA(size);
}

canonical_decompiled_code:
void *__fastcall func13(size_t size)
{
return func12(size);
}

original_code:
void* OscSupSramAllocL1DataB(unsigned int size)
{
 if(size > 0x4000)
  return ((void *)0);
 return malloc(size);
}

canonical_original_code:
void *OscSupSramAllocL1DataB(unsigned int size)
{
 if(size > 0x4000)
  return ((void *)0);
 return malloc(size);
}


decompiled_code:
// attributes: thunk
void *__fastcall OscSupSramAllocL1Data(size_t size)
{
return OscSupSramAllocL1DataA(size);
}

canonical_decompiled_code:
void *__fastcall func14(size_t size)
{
return func12(size);
}

original_code:
void* OscSupSramAllocL1Data(unsigned int size)
{
 if((size > 0x4000) && (size > 0x4000))
  return ((void *)0);
 return malloc(size);
}

canonical_original_code:
void *OscSupSramAllocL1Data(unsigned int size)
{
 if((size > 0x4000) && (size > 0x4000))
  return ((void *)0);
 return malloc(size);
}


decompiled_code:
void *__fastcall OscSupSramAllocL1Instr(size_t size)
{
void *result; // rax

if ( (unsigned int)size > 0xC000 )
result = 0LL;
else
result = malloc((unsigned int)size);
return result;
}

canonical_decompiled_code:
void *__fastcall func15(size_t size)
{
void *result; // rax

if ( (unsigned int)size > 0xC000 )
result = 0LL;
else
result = malloc((unsigned int)size);
return result;
}

original_code:
void* OscSupSramAllocL1Instr(unsigned int size)
{
 if(size > 0xC000)
  return ((void *)0);
 return malloc(size);
}

canonical_original_code:
void *OscSupSramAllocL1Instr(unsigned int size)
{
 if(size > 0xC000)
  return ((void *)0);
 return malloc(size);
}


OscSupSramAllocScratch

decompiled_code:
__int64 OscSupSramAllocScratch()
{
OscLog(3LL, "%s: Allocating scratchpad not supported since not supported by uClinux yet!\n", "OscSupSramAllocScratch");
return 0LL;
}

canonical_decompiled_code:
__int64 func16()
{
OscLog(3LL, "%s: Allocating scratchpad not supported since not supported by uClinux yet!\n", "OscSupSramAllocScratch");
return 0LL;
}

original_code:
void* OscSupSramAllocScratch(unsigned int size)
{
 OscLog(ERROR, "%s: Allocating scratchpad not supported since "
     "not supported by uClinux yet!\n",
     __func__);
 return ((void *)0);
}

canonical_original_code:
void *OscSupSramAllocScratch(unsigned int size)
{
 OscLog(ERROR, "%s: Allocating scratchpad not supported since "
     "not supported by uClinux yet!\n",
     __func__);
 return ((void *)0);
}


OscSupSramFree

decompiled_code:
__int64 __fastcall OscSupSramFree(void *a1)
{
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(void *a1)
{
free(a1);
return 0LL;
}

original_code:
OSC_ERR OscSupSramFree(void *pAddr)
{
 free(pAddr);
 return SUCCESS;
}

canonical_original_code:
int OscSupSramFree(void *pAddr)
{
 free(pAddr);
 return SUCCESS;
}

variable_types:
pAddr
void *


original_code:
OSC_ERR OscVisBGR2Grey(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut)
{
 uint32 outPos = 0;
 uint32 nPixels;
 uint32 pix, cacheLine, nCacheLines, nPixPerCacheLine;
 uint8 *pGrayImgOut = (uint8*)picOut->data;
 const uint16 width = picIn->width;
 const uint16 height = picIn->height;
 uint8 *pImgIn = (uint8*)picIn->data;
 uint8 *pIn_prefetch = pImgIn;
 uint8 *pIn = pImgIn;
 uint8 pointerOffset;
 nPixels = width*height;
 {};
 pointerOffset = (32/(3*sizeof(uint8))) * 3;
 pIn_prefetch += pointerOffset;
 nCacheLines = (nPixels*3*sizeof(uint8))/pointerOffset;
    nPixPerCacheLine = 32/(3*sizeof(uint8));
    for(cacheLine = 0; cacheLine < nCacheLines; cacheLine++)
    {
     {};
     pIn_prefetch += pointerOffset;
     for(pix = 0; pix < nPixPerCacheLine; pix++)
        {
         pGrayImgOut[outPos++] = (15*pIn[0] + 75*pIn[1] + 38*pIn[2]) >> 7;
         pIn += 3;
        }
    }
    picOut->width = width;
    picOut->height = height;
    picOut->type = OSC_PICTURE_GREYSCALE;
 return SUCCESS;
}

canonical_original_code:
int OscVisBGR2Grey(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut)
{
 unsigned int outPos = 0;
 unsigned int nPixels;
 unsigned int pix; unsigned int cacheLine; unsigned int nCacheLines; unsigned int nPixPerCacheLine;
 unsigned char *pGrayImgOut = (uint8*)picOut->data;
 unsigned short width = picIn->width;
 unsigned short height = picIn->height;
 unsigned char *pImgIn = (uint8*)picIn->data;
 unsigned char *pIn_prefetch = pImgIn;
 unsigned char *pIn = pImgIn;
 unsigned char pointerOffset;
 nPixels = width*height;
 {};
 pointerOffset = (32/(3*sizeof(uint8))) * 3;
 pIn_prefetch += pointerOffset;
 nCacheLines = (nPixels*3*sizeof(uint8))/pointerOffset;
    nPixPerCacheLine = 32/(3*sizeof(uint8));
    for(cacheLine = 0; cacheLine < nCacheLines; cacheLine++)
    {
     {};
     pIn_prefetch += pointerOffset;
     for(pix = 0; pix < nPixPerCacheLine; pix++)
        {
         pGrayImgOut[outPos++] = (15*pIn[0] + 75*pIn[1] + 38*pIn[2]) >> 7;
         pIn += 3;
        }
    }
    picOut->width = width;
    picOut->height = height;
    picOut->type = OSC_PICTURE_GREYSCALE;
 return SUCCESS;
}

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

variable_types:
picOut
struct OSC_PICTURE *

variable_types:
outPos
unsigned int

variable_types:
nPixels
unsigned int

variable_types:
pix
unsigned int

variable_types:
cacheLine
unsigned int

variable_types:
nCacheLines
unsigned int

variable_types:
nPixPerCacheLine
unsigned int

variable_types:
pGrayImgOut
unsigned char *

variable_types:
width
unsigned short

variable_types:
height
unsigned short

variable_types:
pImgIn
unsigned char *

variable_types:
pIn
unsigned char *

variable_types:
pointerOffset
unsigned char

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


original_code:
OSC_ERR OscVisGrey2BW(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut, uint8 threshold, _Bool bDarkIsForeground)
{
 uint8 foregroundValue, backgroundValue;
 uint8 *pGrayImgIn = (uint8*)picIn->data;
 uint8 *pBWImgOut = (uint8*)picOut->data;
 const uint16 width = picIn->width;
 const uint16 height = picIn->height;
 uint32 outPos = 0;
 uint32 nPixels;
 uint32 pix, cacheLine, nCacheLines, nPixPerCacheLine;
 uint8 *pIn_prefetch = pGrayImgIn;
 uint8 *pIn = pGrayImgIn;
 nPixels = width*height;
 if(bDarkIsForeground)
 {
  foregroundValue = 0;
  backgroundValue = 1;
 }
 else
 {
  foregroundValue = 1;
  backgroundValue = 0;
 }
 {};
 pIn_prefetch += (32);
 nCacheLines = nPixels/32;
    nPixPerCacheLine = 32;
    for(cacheLine = 0; cacheLine < nCacheLines; cacheLine++)
    {
     {};
     pIn_prefetch += (32);
     for(pix = 0; pix < nPixPerCacheLine; pix++)
        {
         if (pIn[0] > threshold)
    pBWImgOut[outPos++] = foregroundValue;
   else
    pBWImgOut[outPos++] = backgroundValue;
         pIn++;
        }
    }
    picOut->height = height;
    picOut->width = width;
    picOut->type = OSC_PICTURE_BINARY;
 return SUCCESS;
}

canonical_original_code:
int OscVisGrey2BW(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut, unsigned char threshold, _Bool bDarkIsForeground)
{
 unsigned char foregroundValue; unsigned char backgroundValue;
 unsigned char *pGrayImgIn = (uint8*)picIn->data;
 unsigned char *pBWImgOut = (uint8*)picOut->data;
 unsigned short width = picIn->width;
 unsigned short height = picIn->height;
 unsigned int outPos = 0;
 unsigned int nPixels;
 unsigned int pix; unsigned int cacheLine; unsigned int nCacheLines; unsigned int nPixPerCacheLine;
 unsigned char *pIn_prefetch = pGrayImgIn;
 unsigned char *pIn = pGrayImgIn;
 nPixels = width*height;
 if(bDarkIsForeground)
 {
  foregroundValue = 0;
  backgroundValue = 1;
 }
 else
 {
  foregroundValue = 1;
  backgroundValue = 0;
 }
 {};
 pIn_prefetch += (32);
 nCacheLines = nPixels/32;
    nPixPerCacheLine = 32;
    for(cacheLine = 0; cacheLine < nCacheLines; cacheLine++)
    {
     {};
     pIn_prefetch += (32);
     for(pix = 0; pix < nPixPerCacheLine; pix++)
        {
         if (pIn[0] > threshold)
    pBWImgOut[outPos++] = foregroundValue;
   else
    pBWImgOut[outPos++] = backgroundValue;
         pIn++;
        }
    }
    picOut->height = height;
    picOut->width = width;
    picOut->type = OSC_PICTURE_BINARY;
 return SUCCESS;
}

variable_types:
threshold
unsigned char

variable_types:
foregroundValue
unsigned char

variable_types:
backgroundValue
unsigned char

variable_types:
pGrayImgIn
unsigned char *

variable_types:
pBWImgOut
unsigned char *

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


original_code:
OSC_ERR OscVisBGR2BW(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut, uint8 threshold, _Bool bDarkIsForeground)
{
 uint8 *pImgIn = (uint8*)picIn->data;
 uint8 *pBWImgOut = (uint8*)picOut->data;
 const uint16 width = picIn->width;
 const uint16 height = picIn->height;
 uint8 foregroundValue, backgroundValue;
 uint32 outPos = 0;
 uint32 nPixels;
 uint32 pix, cacheLine, nCacheLines, nPixPerCacheLine;
 uint8 *pIn_prefetch = pImgIn;
 uint8 *pIn = pImgIn;
 uint8 pointerOffset;
 uint8 tempGrayVal;
 nPixels = width*height;
 if(bDarkIsForeground )
 {
  foregroundValue = 0;
  backgroundValue = 1;
 }
 else
 {
  foregroundValue = 1;
  backgroundValue = 0;
 }
 {};
 pointerOffset = (32/(3*sizeof(uint8))) * 3;
 pIn_prefetch += pointerOffset;
 nCacheLines = (nPixels*3*sizeof(uint8))/pointerOffset;
    nPixPerCacheLine = 32/(3*sizeof(uint8));
    for(cacheLine = 0; cacheLine < nCacheLines; cacheLine++)
    {
     {};
     pIn_prefetch += pointerOffset;
     for(pix = 0; pix < nPixPerCacheLine; pix++)
        {
         tempGrayVal = (15*pIn[0] + 75*pIn[1] + 38*pIn[2]) >> 7;
         if (tempGrayVal > threshold)
    pBWImgOut[outPos++] = foregroundValue;
   else
    pBWImgOut[outPos++] = backgroundValue;
         pIn += 3;
        }
    }
    picOut->height = height;
    picOut->width = width;
    picOut->type = OSC_PICTURE_BINARY;
 return SUCCESS;
}

canonical_original_code:
int OscVisBGR2BW(struct OSC_PICTURE *picIn, struct OSC_PICTURE *picOut, unsigned char threshold, _Bool bDarkIsForeground)
{
 unsigned char *pImgIn = (uint8*)picIn->data;
 unsigned char *pBWImgOut = (uint8*)picOut->data;
 unsigned short width = picIn->width;
 unsigned short height = picIn->height;
 unsigned char foregroundValue; unsigned char backgroundValue;
 unsigned int outPos = 0;
 unsigned int nPixels;
 unsigned int pix; unsigned int cacheLine; unsigned int nCacheLines; unsigned int nPixPerCacheLine;
 unsigned char *pIn_prefetch = pImgIn;
 unsigned char *pIn = pImgIn;
 unsigned char pointerOffset;
 unsigned char tempGrayVal;
 nPixels = width*height;
 if(bDarkIsForeground )
 {
  foregroundValue = 0;
  backgroundValue = 1;
 }
 else
 {
  foregroundValue = 1;
  backgroundValue = 0;
 }
 {};
 pointerOffset = (32/(3*sizeof(uint8))) * 3;
 pIn_prefetch += pointerOffset;
 nCacheLines = (nPixels*3*sizeof(uint8))/pointerOffset;
    nPixPerCacheLine = 32/(3*sizeof(uint8));
    for(cacheLine = 0; cacheLine < nCacheLines; cacheLine++)
    {
     {};
     pIn_prefetch += pointerOffset;
     for(pix = 0; pix < nPixPerCacheLine; pix++)
        {
         tempGrayVal = (15*pIn[0] + 75*pIn[1] + 38*pIn[2]) >> 7;
         if (tempGrayVal > threshold)
    pBWImgOut[outPos++] = foregroundValue;
   else
    pBWImgOut[outPos++] = backgroundValue;
         pIn += 3;
        }
    }
    picOut->height = height;
    picOut->width = width;
    picOut->type = OSC_PICTURE_BINARY;
 return SUCCESS;
}

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

variable_types:
picOut
struct OSC_PICTURE *

variable_types:
outPos
unsigned int

variable_types:
tempGrayVal
unsigned char


OscVisDrawBoundingBoxBW

original_code:
OSC_ERR OscVisDrawBoundingBoxBW(struct OSC_PICTURE *picIn, struct OSC_VIS_REGIONS *regions, uint8 Color)
{
  uint16 i, o;
  uint8 *pImg = (uint8*)picIn->data;
  const uint16 width = picIn->width;
  for(o = 0; o < regions->noOfObjects; o++)
  {
   for (i = regions->objects[o].bboxLeft; i < regions->objects[o].bboxRight; i += 1)
   {
     pImg[width * regions->objects[o].bboxTop + i] = Color;
     pImg[width * (regions->objects[o].bboxBottom - 1) + i] = Color;
   }
   for (i = regions->objects[o].bboxTop; i < regions->objects[o].bboxBottom-1; i += 1)
   {
     pImg[width * i + regions->objects[o].bboxLeft] = Color;
     pImg[width * i + regions->objects[o].bboxRight] = Color;
   }
  }
  return SUCCESS;
}

canonical_original_code:
int OscVisDrawBoundingBoxBW(struct OSC_PICTURE *picIn, struct OSC_VIS_REGIONS *regions, unsigned char Color)
{
  unsigned short i; unsigned short o;
  unsigned char *pImg = (uint8*)picIn->data;
  unsigned short width = picIn->width;
  for(o = 0; o < regions->noOfObjects; o++)
  {
   for (i = regions->objects[o].bboxLeft; i < regions->objects[o].bboxRight; i += 1)
   {
     pImg[width * regions->objects[o].bboxTop + i] = Color;
     pImg[width * (regions->objects[o].bboxBottom - 1) + i] = Color;
   }
   for (i = regions->objects[o].bboxTop; i < regions->objects[o].bboxBottom-1; i += 1)
   {
     pImg[width * i + regions->objects[o].bboxLeft] = Color;
     pImg[width * i + regions->objects[o].bboxRight] = Color;
   }
  }
  return SUCCESS;
}

variable_types: struct OSC_VIS_REGIONS { unsigned short noOfRuns; unsigned short noOfObjects; struct OSC_VIS_REGIONS_RUN { unsigned short row; unsigned short startColumn; unsigned short endColumn; struct OSC_VIS_REGIONS_RUN *parent; struct OSC_VIS_REGIONS_RUN *next; unsigned short label; } runs[8192]; struct OSC_VIS_REGIONS_OBJECT { struct OSC_VIS_REGIONS_RUN *root; unsigned short area; unsigned short perimeter; unsigned short centroidX; unsigned short bboxTop; } objects[1024]; } *

variable_types:
Color
unsigned char

variable_types:
i
unsigned short

variable_types:
o
unsigned short

variable_types:
pImg
unsigned char *

user_defined_types: struct OSC_VIS_REGIONS { unsigned short noOfRuns; unsigned short noOfObjects; struct OSC_VIS_REGIONS_RUN runs[8192]; struct OSC_VIS_REGIONS_OBJECT objects[1024]; }


ProcessFrame

original_code:
void ProcessFrame(uint8 *pInputImg)
{
 int c, r;
 int nc = 752/2;
 int siz = sizeof(data.u8TempImage[GRAYSCALE]);
 int Shift = 7;
 short Beta = 2;
 uint8 MaxForeground = 120;
 struct OSC_PICTURE Pic1, Pic2;
 struct OSC_VIS_REGIONS ImgRegions;
 if(data.ipc.state.nStepCounter == 1)
 {
  memcpy(data.u8TempImage[BACKGROUND], data.u8TempImage[GRAYSCALE], sizeof(data.u8TempImage[GRAYSCALE]));
  memset(data.u8TempImage[FGRCOUNTER], 0, sizeof(data.u8TempImage[FGRCOUNTER]));
 }
 else
 {
  for(r = 0; r < siz; r+= nc)
  {
   for(c = 0; c < nc; c++)
   {
    data.u8TempImage[THRESHOLD][r+c] = abs((short) data.u8TempImage[GRAYSCALE][r+c]-(short) data.u8TempImage[BACKGROUND][r+c]) < data.ipc.state.nThreshold ? 0 : 0xff;
    if(data.u8TempImage[THRESHOLD][r+c]) {
     if(data.u8TempImage[FGRCOUNTER][r+c] < MaxForeground) {
      data.u8TempImage[FGRCOUNTER][r+c]++;
     } else {
      data.u8TempImage[FGRCOUNTER][r+c] = 0;
      data.u8TempImage[BACKGROUND][r+c] = data.u8TempImage[GRAYSCALE][r+c];
     }
    } else {
     if(0 < data.u8TempImage[FGRCOUNTER][r+c]) {
      data.u8TempImage[FGRCOUNTER][r+c]--;
     }
     short Diff = Beta*((short) data.u8TempImage[GRAYSCALE][r+c] - (short) data.u8TempImage[BACKGROUND][r+c]);
     if(abs(Diff) >= 128)
      data.u8TempImage[BACKGROUND][r+c] = (uint8) ((short) data.u8TempImage[BACKGROUND][r+c] + (Diff >> Shift));
     else
     {
      if(Diff > 0 && data.u8TempImage[BACKGROUND][r+c] < 255)
        data.u8TempImage[BACKGROUND][r+c] += 1;
      else if(Diff < 0 && data.u8TempImage[BACKGROUND][r+c] > 1)
        data.u8TempImage[BACKGROUND][r+c] -= 1;
     }
    }
   }
  }
  for(r = nc; r < siz-nc; r+= nc)
  {
   for(c = 1; c < nc-1; c++)
   {
    unsigned char* p = &data.u8TempImage[THRESHOLD][r+c];
    data.u8TempImage[EROSION][r+c] = *(p-nc-1) & *(p-nc) & *(p-nc+1) &
             *(p-1) & *p & *(p+1) &
             *(p+nc-1) & *(p+nc) & *(p+nc+1);
   }
  }
  for(r = nc; r < siz-nc; r+= nc)
  {
   for(c = 1; c < nc-1; c++)
   {
    unsigned char* p = &data.u8TempImage[EROSION][r+c];
    data.u8TempImage[DILATION][r+c] = *(p-nc-1) | *(p-nc) | *(p-nc+1) |
              *(p-1) | *p | *(p+1) |
              *(p+nc-1) | *(p+nc) | *(p+nc+1);
   }
  }
  Pic1.data = data.u8TempImage[DILATION];
  Pic1.width = nc;
  Pic1.height = 480/2;
  Pic1.type = OSC_PICTURE_GREYSCALE;
  Pic2.data = data.u8TempImage[EROSION];
  Pic2.width = nc;
  Pic2.height = 480/2;
  Pic2.type = OSC_PICTURE_BINARY;
  OscVisGrey2BW(&Pic1, &Pic2, 0x80, 0);
  OscVisLabelBinary( &Pic2, &ImgRegions);
  OscVisGetRegionProperties( &ImgRegions);
  Pic2.data = data.u8TempImage[GRAYSCALE];
  OscVisDrawBoundingBoxBW( &Pic2, &ImgRegions, 255);
  OscVisDrawBoundingBoxBW( &Pic1, &ImgRegions, 128);
 }
}

canonical_original_code:
void ProcessFrame(unsigned char *pInputImg)
{
 int c; int r;
 int nc = 752/2;
 int siz = sizeof(data.u8TempImage[GRAYSCALE]);
 int Shift = 7;
 short Beta = 2;
 unsigned char MaxForeground = 120;
 struct OSC_PICTURE Pic1; struct OSC_PICTURE Pic2;
 struct OSC_VIS_REGIONS ImgRegions;
 if(data.ipc.state.nStepCounter == 1)
 {
  memcpy(data.u8TempImage[BACKGROUND], data.u8TempImage[GRAYSCALE], sizeof(data.u8TempImage[GRAYSCALE]));
  memset(data.u8TempImage[FGRCOUNTER], 0, sizeof(data.u8TempImage[FGRCOUNTER]));
 }
 else
 {
  for(r = 0; r < siz; r+= nc)
  {
   for(c = 0; c < nc; c++)
   {
    data.u8TempImage[THRESHOLD][r+c] = abs((short) data.u8TempImage[GRAYSCALE][r+c]-(short) data.u8TempImage[BACKGROUND][r+c]) < data.ipc.state.nThreshold ? 0 : 0xff;
    if(data.u8TempImage[THRESHOLD][r+c]) {
     if(data.u8TempImage[FGRCOUNTER][r+c] < MaxForeground) {
      data.u8TempImage[FGRCOUNTER][r+c]++;
     } else {
      data.u8TempImage[FGRCOUNTER][r+c] = 0;
      data.u8TempImage[BACKGROUND][r+c] = data.u8TempImage[GRAYSCALE][r+c];
     }
    } else {
     if(0 < data.u8TempImage[FGRCOUNTER][r+c]) {
      data.u8TempImage[FGRCOUNTER][r+c]--;
     }
     short Diff = Beta*((short) data.u8TempImage[GRAYSCALE][r+c] - (short) data.u8TempImage[BACKGROUND][r+c]);
     if(abs(Diff) >= 128)
      data.u8TempImage[BACKGROUND][r+c] = (uint8) ((short) data.u8TempImage[BACKGROUND][r+c] + (Diff >> Shift));
     else
     {
      if(Diff > 0 && data.u8TempImage[BACKGROUND][r+c] < 255)
        data.u8TempImage[BACKGROUND][r+c] += 1;
      else if(Diff < 0 && data.u8TempImage[BACKGROUND][r+c] > 1)
        data.u8TempImage[BACKGROUND][r+c] -= 1;
     }
    }
   }
  }
  for(r = nc; r < siz-nc; r+= nc)
  {
   for(c = 1; c < nc-1; c++)
   {
    unsigned char *p = &data.u8TempImage[THRESHOLD][r+c];
    data.u8TempImage[EROSION][r+c] = *(p-nc-1) & *(p-nc) & *(p-nc+1) &
             *(p-1) & *p & *(p+1) &
             *(p+nc-1) & *(p+nc) & *(p+nc+1);
   }
  }
  for(r = nc; r < siz-nc; r+= nc)
  {
   for(c = 1; c < nc-1; c++)
   {
    unsigned char *p = &data.u8TempImage[EROSION][r+c];
    data.u8TempImage[DILATION][r+c] = *(p-nc-1) | *(p-nc) | *(p-nc+1) |
              *(p-1) | *p | *(p+1) |
              *(p+nc-1) | *(p+nc) | *(p+nc+1);
   }
  }
  Pic1.data = data.u8TempImage[DILATION];
  Pic1.width = nc;
  Pic1.height = 480/2;
  Pic1.type = OSC_PICTURE_GREYSCALE;
  Pic2.data = data.u8TempImage[EROSION];
  Pic2.width = nc;
  Pic2.height = 480/2;
  Pic2.type = OSC_PICTURE_BINARY;
  OscVisGrey2BW(&Pic1, &Pic2, 0x80, 0);
  OscVisLabelBinary( &Pic2, &ImgRegions);
  OscVisGetRegionProperties( &ImgRegions);
  Pic2.data = data.u8TempImage[GRAYSCALE];
  OscVisDrawBoundingBoxBW( &Pic2, &ImgRegions, 255);
  OscVisDrawBoundingBoxBW( &Pic1, &ImgRegions, 128);
 }
}

variable_types:
pInputImg
unsigned char *

variable_types: c int

variable_types: r int

variable_types: nc int

variable_types: siz int

variable_types: Shift int

variable_types: Beta short

variable_types:
MaxForeground
unsigned char

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

variable_types: struct OSC_VIS_REGIONS { unsigned short noOfRuns; unsigned short noOfObjects; struct OSC_VIS_REGIONS_RUN { unsigned short row; unsigned short startColumn; unsigned short endColumn; struct OSC_VIS_REGIONS_RUN *parent; struct OSC_VIS_REGIONS_RUN *next; unsigned short label; } runs[8192]; struct OSC_VIS_REGIONS_OBJECT { struct OSC_VIS_REGIONS_RUN *root; unsigned short area; unsigned short perimeter; unsigned short centroidX; unsigned short bboxTop; } objects[1024]; }

variable_types: Diff short

variable_types:
p
unsigned char *


QueryApp

decompiled_code:
__int64 QueryApp()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 v2; // rcx
__int64 result; // rax
unsigned int v4; // eax
__int64 v5[3]; // [rsp+0h] [rbp-18h] BYREF

v0 = OscIpcGetParam((unsigned __int8)cgi, (unsigned int)((_DWORD)&cgi + 2052), 0LL, 28LL);
v1 = v0;
if ( v0 )
{
OscLog(3LL, "CGI: Error querying application! (%d)\n", v0);
result = v1;
}
else
{
v2 = *((unsigned int *)&cgi + 515);
if ( (_DWORD)v2 )
{
if ( (_DWORD)v2 == 1 )
{
if ( *(&cgi + 2052) )
{
v4 = OscIpcGetParam((unsigned __int8)cgi, (unsigned int)((_DWORD)&cgi + 2104), 1LL, &unk_16080);
v1 = v4;
if ( v4 )
{
OscLog(7LL, "CGI: Getting new image failed! (%d)\n", v4);
}
else
{
v5[1] = 15729016LL;
v5[0] = (__int64)(&cgi + 2104);
v1 = OscBmpWrite(v5, "../image.bmp");
}
}
}
else
{
OscLog(3LL, "%s: Invalid application mode (%d)!\n", "QueryApp", v2);
}
}
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 v2; // rcx
__int64 result; // rax
unsigned int v4; // eax
__int64 v5[3]; // [rsp+0h] [rbp-18h] BYREF

v0 = OscIpcGetParam((unsigned __int8)cgi, (unsigned int)((_DWORD)&cgi + 2052), 0LL, 28LL);
v1 = v0;
if ( v0 )
{
OscLog(3LL, "CGI: Error querying application! (%d)\n", v0);
result = v1;
}
else
{
v2 = *((unsigned int *)&cgi + 515);
if ( (_DWORD)v2 )
{
if ( (_DWORD)v2 == 1 )
{
if ( *(&cgi + 2052) )
{
v4 = OscIpcGetParam((unsigned __int8)cgi, (unsigned int)((_DWORD)&cgi + 2104), 1LL, &unk_16080);
v1 = v4;
if ( v4 )
{
OscLog(7LL, "CGI: Getting new image failed! (%d)\n", v4);
}
else
{
v5[1] = 15729016LL;
v5[0] = (__int64)(&cgi + 2104);
v1 = OscBmpWrite(v5, "../image.bmp");
}
}
}
else
{
OscLog(3LL, "%s: Invalid application mode (%d)!\n", "QueryApp", v2);
}
}
result = v1;
}
return result;
}

original_code:
static OSC_ERR QueryApp()
{
 OSC_ERR err;
 struct OSC_PICTURE pic;
 err = OscIpcGetParam(cgi.ipcChan, &cgi.appState, GET_APP_STATE, sizeof(struct APPLICATION_STATE));
 if (err != SUCCESS)
 {
  OscLog(ERROR, "CGI: Error querying application! (%d)\n", err);
  return err;
 }
 switch(cgi.appState.enAppMode)
 {
 case APP_OFF:
  break;
 case APP_CAPTURE_ON:
  if (cgi.appState.bNewImageReady)
  {
   err = OscIpcGetParam(cgi.ipcChan, cgi.imgBuf, GET_NEW_IMG, 752/2*480/2);
   if (err != SUCCESS)
   {
    OscLog(DEBUG, "CGI: Getting new image failed! (%d)\n", err);
    return err;
   }
   pic.width = 752/2;
   pic.height = 480/2;
   pic.type = OSC_PICTURE_GREYSCALE;
   pic.data = (void*)cgi.imgBuf;
   return OscBmpWrite(&pic, "../image.bmp");
  }
  break;
 default:
  OscLog(ERROR, "%s: Invalid application mode (%d)!\n", __func__, cgi.appState.enAppMode);
  break;
 }
 return SUCCESS;
}

canonical_original_code:
static int QueryApp()
{
 int err;
 struct OSC_PICTURE pic;
 err = OscIpcGetParam(cgi.ipcChan, &cgi.appState, GET_APP_STATE, sizeof(struct APPLICATION_STATE));
 if (err != SUCCESS)
 {
  OscLog(ERROR, "CGI: Error querying application! (%d)\n", err);
  return err;
 }
 switch(cgi.appState.enAppMode)
 {
 case APP_OFF:
  break;
 case APP_CAPTURE_ON:
  if (cgi.appState.bNewImageReady)
  {
   err = OscIpcGetParam(cgi.ipcChan, cgi.imgBuf, GET_NEW_IMG, 752/2*480/2);
   if (err != SUCCESS)
   {
    OscLog(DEBUG, "CGI: Getting new image failed! (%d)\n", err);
    return err;
   }
   pic.width = 752/2;
   pic.height = 480/2;
   pic.type = OSC_PICTURE_GREYSCALE;
   pic.data = (void *)cgi.imgBuf;
   return OscBmpWrite(&pic, "../image.bmp");
  }
  break;
 default:
  OscLog(ERROR, "%s: Invalid application mode (%d)!\n", __func__, cgi.appState.enAppMode);
  break;
 }
 return SUCCESS;
}

variable_types: err int

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

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


SetOptions

decompiled_code:
__int64 SetOptions()
{
unsigned int v1; // er12

if ( cgi[2100] )
{
v1 = OscIpcSetParam((unsigned __int8)cgi[0], (unsigned int)((_DWORD)cgi + 2096), 2LL, 4LL);
if ( v1 )
goto LABEL_6;
}
if ( cgi[2092] )
{
v1 = OscIpcSetParam((unsigned __int8)cgi[0], (unsigned int)((_DWORD)cgi + 2088), 4LL, 4LL);
if ( v1 )
{
LABEL_6:
OscLog(7LL, "CGI: Error setting option! (%d)\n", v1);
return v1;
}
if ( !cgi[2084] )
return 0LL;
}
else if ( !cgi[2084] )
{
return 0LL;
}
v1 = OscIpcSetParam((unsigned __int8)cgi[0], (unsigned int)((_DWORD)cgi + 2080), 3LL, 4LL);
if ( v1 )
goto LABEL_6;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v1; // er12

if ( cgi[2100] )
{
v1 = OscIpcSetParam((unsigned __int8)cgi[0], (unsigned int)((_DWORD)cgi + 2096), 2LL, 4LL);
if ( v1 )
goto LABEL_6;
}
if ( cgi[2092] )
{
v1 = OscIpcSetParam((unsigned __int8)cgi[0], (unsigned int)((_DWORD)cgi + 2088), 4LL, 4LL);
if ( v1 )
{
LABEL_6:
OscLog(7LL, "CGI: Error setting option! (%d)\n", v1);
return v1;
}
if ( !cgi[2084] )
return 0LL;
}
else if ( !cgi[2084] )
{
return 0LL;
}
v1 = OscIpcSetParam((unsigned __int8)cgi[0], (unsigned int)((_DWORD)cgi + 2080), 3LL, 4LL);
if ( v1 )
goto LABEL_6;
return 0LL;
}

original_code:
static OSC_ERR SetOptions()
{
 OSC_ERR err;
 struct ARGUMENT_DATA *pArgs = &cgi.args;
 if (pArgs->bImageType_supplied)
 {
  err = OscIpcSetParam(cgi.ipcChan, &pArgs->nImageType, SET_IMAGE_TYPE, sizeof(pArgs->nImageType));
  if (err != SUCCESS)
  {
   OscLog(DEBUG, "CGI: Error setting option! (%d)\n", err);
   return err;
  }
 }
 if (pArgs->bThreshold_supplied)
 {
  err = OscIpcSetParam(cgi.ipcChan, &pArgs->nThreshold, SET_THRESHOLD, sizeof(pArgs->nThreshold));
  if (err != SUCCESS)
  {
   OscLog(DEBUG, "CGI: Error setting option! (%d)\n", err);
   return err;
  }
 }
 if (pArgs->bExposureTime_supplied)
 {
  err = OscIpcSetParam(cgi.ipcChan, &pArgs->nExposureTime, SET_EXPOSURE_TIME, sizeof(pArgs->nExposureTime));
  if (err != SUCCESS)
  {
   OscLog(DEBUG, "CGI: Error setting option! (%d)\n", err);
   return err;
  }
 }
 return SUCCESS;
}

canonical_original_code:
static int SetOptions()
{
 int err;
 struct ARGUMENT_DATA *pArgs = &cgi.args;
 if (pArgs->bImageType_supplied)
 {
  err = OscIpcSetParam(cgi.ipcChan, &pArgs->nImageType, SET_IMAGE_TYPE, sizeof(pArgs->nImageType));
  if (err != SUCCESS)
  {
   OscLog(DEBUG, "CGI: Error setting option! (%d)\n", err);
   return err;
  }
 }
 if (pArgs->bThreshold_supplied)
 {
  err = OscIpcSetParam(cgi.ipcChan, &pArgs->nThreshold, SET_THRESHOLD, sizeof(pArgs->nThreshold));
  if (err != SUCCESS)
  {
   OscLog(DEBUG, "CGI: Error setting option! (%d)\n", err);
   return err;
  }
 }
 if (pArgs->bExposureTime_supplied)
 {
  err = OscIpcSetParam(cgi.ipcChan, &pArgs->nExposureTime, SET_EXPOSURE_TIME, sizeof(pArgs->nExposureTime));
  if (err != SUCCESS)
  {
   OscLog(DEBUG, "CGI: Error setting option! (%d)\n", err);
   return err;
  }
 }
 return SUCCESS;
}

variable_types: struct ARGUMENT_DATA { int nExposureTime; _Bool bExposureTime_supplied; int nThreshold; _Bool bThreshold_supplied; int nImageType; _Bool bImageType_supplied; } *


FormCGIResponse

decompiled_code:
int FormCGIResponse()
{
puts("Content-type: text/plain\n");
printf("imgTS: %u\n", cgi[514]);
printf("exposureTime: %d\n", cgi[517]);
printf("Threshold: %d\n", cgi[518]);
printf("Stepcounter: %d\n", cgi[519]);
printf("width: %d\n", 376LL);
printf("height: %d\n", 240LL);
printf("ImageType: %u\n", cgi[516]);
return fflush(stdout);
}

canonical_decompiled_code:
int func2()
{
puts("Content-type: text/plain\n");
printf("imgTS: %u\n", cgi[514]);
printf("exposureTime: %d\n", cgi[517]);
printf("Threshold: %d\n", cgi[518]);
printf("Stepcounter: %d\n", cgi[519]);
printf("width: %d\n", 376LL);
printf("height: %d\n", 240LL);
printf("ImageType: %u\n", cgi[516]);
return fflush(stdout);
}

original_code:
static void FormCGIResponse()
{
 struct APPLICATION_STATE *pAppState = &cgi.appState;
 printf("Content-type: text/plain\n\n" );
 printf("imgTS: %u\n", (unsigned int)pAppState->imageTimeStamp);
 printf("exposureTime: %d\n", pAppState->nExposureTime);
 printf("Threshold: %d\n", pAppState->nThreshold);
 printf("Stepcounter: %d\n", pAppState->nStepCounter);
 printf("width: %d\n", 752/2);
 printf("height: %d\n", 480/2);
 printf("ImageType: %u\n", pAppState->nImageType);
 fflush(stdout);
}

variable_types: struct APPLICATION_STATE { _Bool bNewImageReady; unsigned int imageTimeStamp; enum EnAppMode { APP_OFF=0, APP_CAPTURE_ON=1 } enAppMode; unsigned int nImageType; int nExposureTime; int nThreshold; unsigned int nStepCounter; } *


strtrim

decompiled_code:
char *__fastcall strtrim(const char *a1)
{
char *v1; // r12
size_t v2; // rax
int v3; // esi
char *v4; // rbx

v1 = (char *)a1;
v2 = strlen(a1);
v3 = *a1;
v4 = (char *)&a1[v2 - 1];
if ( *a1 )
{
do
{
if ( !strchr(off_1098C1, v3) )
break;
v3 = *++v1;
}
while ( (_BYTE)v3 );
}
if ( v4 > v1 )
{
do
{
if ( !strchr(off_1098C1, *v4) )
break;
--v4;
}
while ( v4 != v1 );
}
v4[1] = 0;
return v1;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1)
{
char *v1; // r12
size_t v2; // rax
int v3; // esi
char *v4; // rbx

v1 = (char *)a1;
v2 = strlen(a1);
v3 = *a1;
v4 = (char *)&a1[v2 - 1];
if ( *a1 )
{
do
{
if ( !strchr(off_1098C1, v3) )
break;
v3 = *++v1;
}
while ( (_BYTE)v3 );
}
if ( v4 > v1 )
{
do
{
if ( !strchr(off_1098C1, *v4) )
break;
--v4;
}
while ( v4 != v1 );
}
v4[1] = 0;
return v1;
}

original_code:
char * strtrim(char * str) {
 char * end = strchr(str, 0) - 1;
 while (*str != 0 && strchr(" \t\n", *str) != ((void *)0))
  str += 1;
 while (end > str && strchr(" \t\n", *end) != ((void *)0))
  end -= 1;
 *(end + 1) = 0;
 return str;
}

canonical_original_code:
char *strtrim(char *str) {
 char *end = strchr(str, 0) - 1;
 while (*str != 0 && strchr(" \t\n", *str) != ((void *)0))
  str += 1;
 while (end > str && strchr(" \t\n", *end) != ((void *)0))
  end -= 1;
 *(end + 1) = 0;
 return str;
}

variable_types:
str
char *

variable_types:
end
char *

return_type: char *


CGIParseArguments

decompiled_code:
__int64 CGIParseArguments()
{
__int64 result; // rax
char *v1; // rax
const char *v2; // rdi
char *v3; // r12
char *v4; // r13
char *v5; // rbp
int v6; // eax
_BYTE *v7; // rax
char v8[1048]; // [rsp+0h] [rbp-418h] BYREF

**(_BYTE **)&args[48] = 0;
**(_BYTE **)&args[104] = 0;
**(_BYTE **)&args[160] = 0;
while ( 1 )
{
result = (__int64)fgets(v8, 1024, stdin);
if ( !result )
break;
v1 = strchr(v8, 58);
if ( !v1 )
{
OscLog(3LL, "%s: Invalid line: \"%s\"\n", "CGIParseArguments", v8);
return 4294967288LL;
}
*v1 = 0;
v2 = v1 + 1;
v3 = args;
v4 = strtrim(v8);
v5 = strtrim(v2);
OscLog(6LL, "obtained key: %s, and Value: %s\n", v4, v5);
while ( strcmp(v3, v4) )
{
v3 += 56;
if ( v3 == &args[168] )
{
OscLog(3LL, "%s: Unknown argument encountered: \"%s\"\n", "CGIParseArguments", v4);
return 4294967288LL;
}
}
v6 = *((_DWORD *)v3 + 8);
if ( v6 )
{
switch ( v6 )
{
case 1:
if ( (unsigned int)_isoc99_sscanf(v5, "%d", *((_QWORD *)v3 + 5)) != 1 )
{
OscLog(3LL, "%s: Unable to parse int value of variable \"%s\" (%s)!\n", "CGIParseArguments", v3, v5);
return 4294967288LL;
}
break;
case 2:
if ( (unsigned int)_isoc99_sscanf(v5, "%hd", *((_QWORD *)v3 + 5)) != 1 )
{
OscLog(3LL, "%s: Unable to parse short value of variable \"%s\" (%s)!\n", "CGIParseArguments", v3, v5);
return 4294967288LL;
}
break;
case 3:
if ( !strcmp(v5, "true") )
{
**((_BYTE **)v3 + 5) = 1;
}
else
{
if ( strcmp(v5, "false") )
{
OscLog(
3LL,
"CGI %s: Unable to parse boolean value of variable \"%s\" (%s)!\n",
"CGIParseArguments",
v3,
v5);
return 4294967288LL;
}
**((_BYTE **)v3 + 5) = 0;
}
break;
}
}
else
{
strcpy(*((char **)v3 + 5), v5);
}
v7 = (_BYTE *)*((_QWORD *)v3 + 6);
if ( v7 )
*v7 = 1;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
char *v1; // rax
const char *v2; // rdi
char *v3; // r12
char *v4; // r13
char *v5; // rbp
int v6; // eax
_BYTE *v7; // rax
char v8[1048]; // [rsp+0h] [rbp-418h] BYREF

**(_BYTE **)&args[48] = 0;
**(_BYTE **)&args[104] = 0;
**(_BYTE **)&args[160] = 0;
while ( 1 )
{
result = (__int64)fgets(v8, 1024, stdin);
if ( !result )
break;
v1 = strchr(v8, 58);
if ( !v1 )
{
OscLog(3LL, "%s: Invalid line: \"%s\"\n", "CGIParseArguments", v8);
return 4294967288LL;
}
*v1 = 0;
v2 = v1 + 1;
v3 = args;
v4 = func3(v8);
v5 = func3(v2);
OscLog(6LL, "obtained key: %s, and Value: %s\n", v4, v5);
while ( strcmp(v3, v4) )
{
v3 += 56;
if ( v3 == &args[168] )
{
OscLog(3LL, "%s: Unknown argument encountered: \"%s\"\n", "CGIParseArguments", v4);
return 4294967288LL;
}
}
v6 = *((_DWORD *)v3 + 8);
if ( v6 )
{
switch ( v6 )
{
case 1:
if ( (unsigned int)_isoc99_sscanf(v5, "%d", *((_QWORD *)v3 + 5)) != 1 )
{
OscLog(3LL, "%s: Unable to parse int value of variable \"%s\" (%s)!\n", "CGIParseArguments", v3, v5);
return 4294967288LL;
}
break;
case 2:
if ( (unsigned int)_isoc99_sscanf(v5, "%hd", *((_QWORD *)v3 + 5)) != 1 )
{
OscLog(3LL, "%s: Unable to parse short value of variable \"%s\" (%s)!\n", "CGIParseArguments", v3, v5);
return 4294967288LL;
}
break;
case 3:
if ( !strcmp(v5, "true") )
{
**((_BYTE **)v3 + 5) = 1;
}
else
{
if ( strcmp(v5, "false") )
{
OscLog(
3LL,
"CGI %s: Unable to parse boolean value of variable \"%s\" (%s)!\n",
"CGIParseArguments",
v3,
v5);
return 4294967288LL;
}
**((_BYTE **)v3 + 5) = 0;
}
break;
}
}
else
{
strcpy(*((char **)v3 + 5), v5);
}
v7 = (_BYTE *)*((_QWORD *)v3 + 6);
if ( v7 )
*v7 = 1;
}
return result;
}

original_code:
static OSC_ERR CGIParseArguments()
{
 char buffer[1024];
 for (int i = 0; i < sizeof args / sizeof (struct ARGUMENT); i += 1)
 {
  *args[i].pbSupplied = 0;
 }
 while (fgets (buffer, sizeof buffer, stdin)) {
  struct ARGUMENT *pArg = ((void *)0);
  char * key, * value = strchr(buffer, ':');
  if (value == ((void *)0)) {
   OscLog(ERROR, "%s: Invalid line: \"%s\"\n", __func__, buffer);
   return -EINVALID_PARAMETER;
  }
  *value = 0;
  value += 1;
  key = strtrim(buffer);
  value = strtrim(value);
  OscLog(INFO, "obtained key: %s, and Value: %s\n", key, value);
  for (int i = 0; i < sizeof(args)/sizeof(struct ARGUMENT); i += 1) {
   if (strcmp(args[i].strName, key) == 0) {
    pArg = args + i;
    break;
   }
  }
  if (pArg == ((void *)0)) {
   OscLog(ERROR, "%s: Unknown argument encountered: \"%s\"\n", __func__, key);
   return -EINVALID_PARAMETER;
  } else {
   if (pArg->enType == STRING_ARG) {
    strcpy((char *) pArg->pData, value);
   } else if (pArg->enType == INT_ARG) {
    if (sscanf(value, "%d", (int *) pArg->pData) != 1) {
     OscLog(ERROR, "%s: Unable to parse int value of variable \"%s\" (%s)!\n", __func__, pArg->strName, value);
     return -EINVALID_PARAMETER;
    }
   } else if (pArg->enType == SHORT_ARG) {
    if (sscanf(value, "%hd", (short *) pArg->pData) != 1) {
     OscLog(ERROR, "%s: Unable to parse short value of variable \"%s\" (%s)!\n", __func__, pArg->strName, value);
     return -EINVALID_PARAMETER;
    }
   } else if (pArg->enType == BOOL_ARG) {
    if (strcmp(value, "true") == 0) {
     *((_Bool *) pArg->pData) = 1;
    } else if (strcmp(value, "false") == 0) {
     *((_Bool *) pArg->pData) = 0;
    } else {
     OscLog(ERROR, "CGI %s: Unable to parse boolean value of variable \"%s\" (%s)!\n", __func__, pArg->strName, value);
     return -EINVALID_PARAMETER;
    }
   }
   if (pArg->pbSupplied != ((void *)0))
    *pArg->pbSupplied = 1;
  }
 }
 return SUCCESS;
}

canonical_original_code:
static int CGIParseArguments()
{
 char buffer[1024];
 for (int i = 0; i < sizeof args / sizeof (struct ARGUMENT); i += 1)
 {
  *args[i].pbSupplied = 0;
 }
 while (fgets (buffer, sizeof buffer, stdin)) {
  struct ARGUMENT *pArg = ((void *)0);
  char *key; char *value = strchr(buffer, ':');
  if (value == ((void *)0)) {
   OscLog(ERROR, "%s: Invalid line: \"%s\"\n", __func__, buffer);
   return -EINVALID_PARAMETER;
  }
  *value = 0;
  value += 1;
  key = strtrim(buffer);
  value = strtrim(value);
  OscLog(INFO, "obtained key: %s, and Value: %s\n", key, value);
  for (int i = 0; i < sizeof(args)/sizeof(struct ARGUMENT); i += 1) {
   if (strcmp(args[i].strName, key) == 0) {
    pArg = args + i;
    break;
   }
  }
  if (pArg == ((void *)0)) {
   OscLog(ERROR, "%s: Unknown argument encountered: \"%s\"\n", __func__, key);
   return -EINVALID_PARAMETER;
  } else {
   if (pArg->enType == STRING_ARG) {
    strcpy((char *) pArg->pData, value);
   } else if (pArg->enType == INT_ARG) {
    if (sscanf(value, "%d", (int *) pArg->pData) != 1) {
     OscLog(ERROR, "%s: Unable to parse int value of variable \"%s\" (%s)!\n", __func__, pArg->strName, value);
     return -EINVALID_PARAMETER;
    }
   } else if (pArg->enType == SHORT_ARG) {
    if (sscanf(value, "%hd", (short *) pArg->pData) != 1) {
     OscLog(ERROR, "%s: Unable to parse short value of variable \"%s\" (%s)!\n", __func__, pArg->strName, value);
     return -EINVALID_PARAMETER;
    }
   } else if (pArg->enType == BOOL_ARG) {
    if (strcmp(value, "true") == 0) {
     *((_Bool *) pArg->pData) = 1;
    } else if (strcmp(value, "false") == 0) {
     *((_Bool *) pArg->pData) = 0;
    } else {
     OscLog(ERROR, "CGI %s: Unable to parse boolean value of variable \"%s\" (%s)!\n", __func__, pArg->strName, value);
     return -EINVALID_PARAMETER;
    }
   }
   if (pArg->pbSupplied != ((void *)0))
    *pArg->pbSupplied = 1;
  }
 }
 return SUCCESS;
}

variable_types:
buffer
char [1024]

variable_types: i int

variable_types: struct ARGUMENT { char strName[32]; enum EnArgumentType { STRING_ARG=0, INT_ARG=1, SHORT_ARG=2, BOOL_ARG=3 } enType; void *pData; _Bool *pbSupplied; } *

variable_types:
key
char *

variable_types:
value
char *

user_defined_types: struct ARGUMENT { char strName[32]; enum EnArgumentType enType; void *pData; _Bool *pbSupplied; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return mainFunction(argc, argv, envp) != 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func5(argc, argv, envp) != 0;
}

original_code:
int main(void) {
 if (mainFunction() == SUCCESS)
  return 0;
 else
  return 1;
}

canonical_original_code:
int main() {
 if (mainFunction() == SUCCESS)
  return 0;
 else
  return 1;
}


OscCpldRset

decompiled_code:
__int64 __fastcall OscCpldRset(unsigned __int16 a1, __int16 a2)
{
__int64 result; // rax

result = 0LL;
cpld[a1 + 8] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1, __int16 a2)
{
__int64 result; // rax

result = 0LL;
cpld[a1 + 8] = a2;
return result;
}

original_code:
OSC_ERR OscCpldRset(
  const uint16 regId,
  const uint16 val)
{
 cpld.reg[ regId] = val;
 return SUCCESS;
}

canonical_original_code:
int OscCpldRset(unsigned short regId, unsigned short val)
{
 cpld.reg[ regId] = val;
 return SUCCESS;
}

variable_types:
regId
unsigned short

variable_types:
val
unsigned short


OscCpldFset

decompiled_code:
__int64 __fastcall OscCpldFset(unsigned __int16 a1, __int16 a2, __int16 a3)
{
__int64 result; // rax

result = 0LL;
cpld[a1 + 8] = (a3 | ~a2) & (cpld[a1 + 8] | a2 & a3);
return result;
}

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

result = 0LL;
cpld[a1 + 8] = (a3 | ~a2) & (cpld[a1 + 8] | a2 & a3);
return result;
}

original_code:
OSC_ERR OscCpldFset(
  uint16 regId,
  uint16 field,
  uint16 val)
{
 uint16 current;
 current = cpld.reg[ regId];
 current = current | (field & val);
 current = current & ~(field & (~val));
 cpld.reg[ regId] = current;
 return SUCCESS;
}

canonical_original_code:
int OscCpldFset(unsigned short regId, unsigned short field, unsigned short val)
{
 unsigned short current;
 current = cpld.reg[ regId];
 current = current | (field & val);
 current = current & ~(field & (~val));
 cpld.reg[ regId] = current;
 return SUCCESS;
}

variable_types:
field
unsigned short

variable_types:
current
unsigned short


OscCpldRget

decompiled_code:
__int64 __fastcall OscCpldRget(unsigned __int16 a1, _WORD *a2)
{
*a2 = cpld[a1 + 8];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, _WORD *a2)
{
*a2 = cpld[a1 + 8];
return 0LL;
}

original_code:
OSC_ERR OscCpldRget(
  const uint16 regId,
  uint16* val)
{
 *val = cpld.reg[ regId];
 return SUCCESS;
}

canonical_original_code:
int OscCpldRget(unsigned short regId, unsigned short *val)
{
 *val = cpld.reg[ regId];
 return SUCCESS;
}

variable_types:
val
unsigned short *


OscCpldFget

decompiled_code:
__int64 __fastcall OscCpldFget(unsigned __int16 a1, unsigned __int16 a2, _WORD *a3)
{
*a3 = (a2 & (unsigned __int16)cpld[a1 + 8]) != 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, unsigned __int16 a2, _WORD *a3)
{
*a3 = (a2 & (unsigned __int16)cpld[a1 + 8]) != 0;
return 0LL;
}

original_code:
OSC_ERR OscCpldFget(
  const uint16 regId,
  const uint16 field,
  uint16* val)
{
 uint16 current = cpld.reg[ regId];
 if( current & field)
 {
  *val = 1;
 }
 else
 {
  *val = 0;
 }
 return SUCCESS;
}

canonical_original_code:
int OscCpldFget(unsigned short regId, unsigned short field, unsigned short *val)
{
 unsigned short current = cpld.reg[ regId];
 if( current & field)
 {
  *val = 1;
 }
 else
 {
  *val = 0;
 }
 return SUCCESS;
}


OscSwrCreate

decompiled_code:
__int64 OscSwrCreate()
{
OscSimRegisterCycleCallback(OscSwrCycleCallback);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
OscSimRegisterCycleCallback(OscSwrCycleCallback);
return 0LL;
}

original_code:
OSC_ERR OscSwrCreate()
{
 OscSimRegisterCycleCallback( &OscSwrCycleCallback);
 return SUCCESS;
}

canonical_original_code:
int OscSwrCreate()
{
 OscSimRegisterCycleCallback( &OscSwrCycleCallback);
 return SUCCESS;
}


OscSwrDestroy

decompiled_code:
__int64 OscSwrDestroy()
{
int v0; // ebp
__int64 v1; // rdx

if ( !LOWORD(swr[0]) )
return 0LL;
v0 = 0;
do
{
fflush((FILE *)swr[590 * (unsigned __int16)v0 + 1]);
fclose((FILE *)swr[590 * (unsigned __int16)v0 + 1]);
v1 = 590LL * (unsigned __int16)v0++;
OscLog(6LL, "Close %s\n", (const char *)&swr[v1 + 2]);
--LOWORD(swr[0]);
}
while ( LOWORD(swr[0]) > (unsigned __int16)v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebp
__int64 v1; // rdx

if ( !LOWORD(swr[0]) )
return 0LL;
v0 = 0;
do
{
fflush((FILE *)swr[590 * (unsigned __int16)v0 + 1]);
fclose((FILE *)swr[590 * (unsigned __int16)v0 + 1]);
v1 = 590LL * (unsigned __int16)v0++;
OscLog(6LL, "Close %s\n", (const char *)&swr[v1 + 2]);
--LOWORD(swr[0]);
}
while ( LOWORD(swr[0]) > (unsigned __int16)v0 );
return 0LL;
}

original_code:
OSC_ERR OscSwrDestroy()
{
 uint16 wrId;
 for( wrId = 0; wrId<swr.nrOfWriters; wrId++)
 {
  fflush(swr.wr[ wrId].pFile);
  fclose( swr.wr[ wrId].pFile);
  OscLog(INFO, "Close %s\n", &swr.wr[ wrId].strFile);
  swr.nrOfWriters --;
 }
 return SUCCESS;
}

canonical_original_code:
int OscSwrDestroy()
{
 unsigned short wrId;
 for( wrId = 0; wrId<swr.nrOfWriters; wrId++)
 {
  fflush(swr.wr[ wrId].pFile);
  fclose( swr.wr[ wrId].pFile);
  OscLog(INFO, "Close %s\n", &swr.wr[ wrId].strFile);
  swr.nrOfWriters --;
 }
 return SUCCESS;
}

variable_types:
wrId
unsigned short


OscSwrUpdateSignal

decompiled_code:
__int64 __fastcall OscSwrUpdateSignal(__int64 a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 1 )
{
result = 0LL;
*(_DWORD *)(a1 + 12) = *(_DWORD *)a2;
}
else if ( v2 == 2 )
{
strcpy((char *)(a1 + 12), a2);
result = 0LL;
}
else
{
if ( !v2 )
*(_DWORD *)(a1 + 12) = *(_DWORD *)a2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 1 )
{
result = 0LL;
*(_DWORD *)(a1 + 12) = *(_DWORD *)a2;
}
else if ( v2 == 2 )
{
strcpy((char *)(a1 + 12), a2);
result = 0LL;
}
else
{
if ( !v2 )
*(_DWORD *)(a1 + 12) = *(_DWORD *)a2;
result = 0LL;
}
return result;
}

original_code:
OSC_ERR OscSwrUpdateSignal(
  const void* pSignal,
  const void* pValue)
{
 struct OSC_SWR_SIGNAL* pSig;
 pSig = (void*) pSignal;
 switch( pSig->type)
 {
 case SWR_INTEGER:
  pSig->value.nValue = *(int32*)pValue;
  break;
 case SWR_FLOAT:
  pSig->value.fValue = *(float*)pValue;
  break;
 case SWR_STRING:
  strcpy( pSig->value.strValue, (char*)pValue);
 }
 return SUCCESS;
}

canonical_original_code:
int OscSwrUpdateSignal(void *pSignal, void *pValue)
{
 struct OSC_SWR_SIGNAL *pSig;
 pSig = (void *) pSignal;
 switch( pSig->type)
 {
 case SWR_INTEGER:
  pSig->value.nValue = *(int *)pValue;
  break;
 case SWR_FLOAT:
  pSig->value.fValue = *(float *)pValue;
  break;
 case SWR_STRING:
  strcpy( pSig->value.strValue, (char *)pValue);
 }
 return SUCCESS;
}

variable_types:
pSignal
void *

variable_types:
pValue
void *

variable_types: struct OSC_SWR_SIGNAL { char *strName; enum EnOscSwrSignalType { SWR_INTEGER=0, SWR_FLOAT=1, SWR_STRING=2 } type; union uOSC_SWR_VALUE { int nValue; float fValue; char strValue[200]; } value; char strFormat[20]; } *

user_defined_types: struct OSC_SWR_SIGNAL { char *strName; enum EnOscSwrSignalType type; union uOSC_SWR_VALUE value; char strFormat[20]; }


OscSwrManualReport

decompiled_code:
__int64 __fastcall OscSwrManualReport(__int64 a1)
{
OscSwrReport(a1);
return 0LL;
}

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

original_code:
OSC_ERR OscSwrManualReport( const void* pWriter)
{
 OscSwrReport( pWriter);
 return SUCCESS;
}

canonical_original_code:
int OscSwrManualReport(void *pWriter)
{
 OscSwrReport( pWriter);
 return SUCCESS;
}

variable_types:
pWriter
void *


OscSwrCycleCallback

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

if ( LOWORD(swr[0]) )
{
v0 = 0;
do
{
while ( 1 )
{
v1 = 590LL * (unsigned __int16)v0;
if ( BYTE4(swr[v1 + 10]) )
break;
if ( LOWORD(swr[0]) <= (unsigned __int16)++v0 )
return;
}
++v0;
OscSwrReport((__int64)&swr[v1 + 1]);
}
while ( LOWORD(swr[0]) > (unsigned __int16)v0 );
}
}

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

if ( LOWORD(swr[0]) )
{
v0 = 0;
do
{
while ( 1 )
{
v1 = 590LL * (unsigned __int16)v0;
if ( BYTE4(swr[v1 + 10]) )
break;
if ( LOWORD(swr[0]) <= (unsigned __int16)++v0 )
return;
}
++v0;
func5((__int64)&swr[v1 + 1]);
}
while ( LOWORD(swr[0]) > (unsigned __int16)v0 );
}
}

original_code:
void OscSwrCycleCallback( void)
{
 uint16 wrId;
 for( wrId = 0; wrId<swr.nrOfWriters; wrId++)
 {
  if( swr.wr[ wrId].bReportCyclic)
  {
   OscSwrReport( &swr.wr[ wrId]);
  }
 }
 return;
}

canonical_original_code:
void OscSwrCycleCallback()
{
 unsigned short wrId;
 for( wrId = 0; wrId<swr.nrOfWriters; wrId++)
 {
  if( swr.wr[ wrId].bReportCyclic)
  {
   OscSwrReport( &swr.wr[ wrId]);
  }
 }
 return;
}


decompiled_code:
__int64 __fastcall WrDbgImgInt16(__int64 a1, unsigned __int16 a2, unsigned __int16 a3, const char *a4, int a5)
{
int v5; // er13
_BYTE *v6; // rbp
char *v7; // rax
__int64 v8; // rax
unsigned int v9; // er12
_BYTE *v13; // [rsp+10h] [rbp-158h] BYREF
unsigned __int16 v14; // [rsp+18h] [rbp-150h]
unsigned __int16 v15; // [rsp+1Ah] [rbp-14Eh]
int v16; // [rsp+1Ch] [rbp-14Ch]
char s[16]; // [rsp+20h] [rbp-148h] BYREF
char dest[312]; // [rsp+30h] [rbp-138h] BYREF

v5 = a3 * a2;
v14 = a2;
v15 = a3;
v6 = malloc(v5);
v16 = 0;
v13 = v6;
v7 = stpcpy(dest, a4);
if ( a5 < 0 )
{
strcpy(v7, ".bmp");
}
else
{
sprintf(s, "%05u.bmp", (unsigned int)a5);
strcat(dest, s);
}
v8 = 0LL;
if ( v5 )
{
do
{
v6[v8] = (unsigned __int16)(*(_WORD *)(a1 + 2 * v8) + 0x8000) >> 8;
++v8;
}
while ( v5 != v8 );
}
v9 = OscBmpWrite(&v13, dest);
free(v6);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int16 a2, unsigned __int16 a3, const char *a4, int a5)
{
int v5; // er13
_BYTE *v6; // rbp
char *v7; // rax
__int64 v8; // rax
unsigned int v9; // er12
_BYTE *v13; // [rsp+10h] [rbp-158h] BYREF
unsigned __int16 v14; // [rsp+18h] [rbp-150h]
unsigned __int16 v15; // [rsp+1Ah] [rbp-14Eh]
int v16; // [rsp+1Ch] [rbp-14Ch]
char s[16]; // [rsp+20h] [rbp-148h] BYREF
char dest[312]; // [rsp+30h] [rbp-138h] BYREF

v5 = a3 * a2;
v14 = a2;
v15 = a3;
v6 = malloc(v5);
v16 = 0;
v13 = v6;
v7 = stpcpy(dest, a4);
if ( a5 < 0 )
{
strcpy(v7, ".bmp");
}
else
{
sprintf(s, "%05u.bmp", (unsigned int)a5);
strcat(dest, s);
}
v8 = 0LL;
if ( v5 )
{
do
{
v6[v8] = (unsigned __int16)(*(_WORD *)(a1 + 2 * v8) + 0x8000) >> 8;
++v8;
}
while ( v5 != v8 );
}
v9 = OscBmpWrite(&v13, dest);
free(v6);
return v9;
}

original_code:
OSC_ERR WrDbgImgInt16(const int16 *pData, const uint16 width, const uint16 height, const char * strPrefix, int32 seq)
{
 struct OSC_PICTURE pic;
 OSC_ERR err;
 int i;
 uint8 *pPix;
 char strName[256];
 char strTemp[16];
 pPix = (uint8*)malloc(width*height);
 pic.width = width;
 pic.height = height;
 pic.type = OSC_PICTURE_GREYSCALE;
 pic.data = (void*)pPix;
 strcpy(strName, strPrefix);
 if (seq >= 0)
 {
  sprintf(strTemp, "%05u.bmp", (unsigned int)seq);
  strcat(strName, strTemp);
 }
 else
 {
  strcat(strName, ".bmp");
 }
 for (i = 0; i < width*height; i++)
 {
  pPix[i] = (uint8)(((uint32)((int32)pData[i] + 0x8000)) >> 8);
 }
 err = OscBmpWrite(&pic, strName);
 free(pPix);
 return err;
}

canonical_original_code:
int WrDbgImgInt16(short *pData, unsigned short width, unsigned short height, char *strPrefix, int seq)
{
 struct OSC_PICTURE pic;
 int err;
 int i;
 unsigned char *pPix;
 char strName[256];
 char strTemp[16];
 pPix = (unsigned char *)malloc(width*height);
 pic.width = width;
 pic.height = height;
 pic.type = OSC_PICTURE_GREYSCALE;
 pic.data = (void *)pPix;
 strcpy(strName, strPrefix);
 if (seq >= 0)
 {
  sprintf(strTemp, "%05u.bmp", (unsigned int)seq);
  strcat(strName, strTemp);
 }
 else
 {
  strcat(strName, ".bmp");
 }
 for (i = 0; i < width*height; i++)
 {
  pPix[i] = (uint8)(((uint32)((int)pData[i] + 0x8000)) >> 8);
 }
 err = OscBmpWrite(&pic, strName);
 free(pPix);
 return err;
}

variable_types:
pData
short *

variable_types:
width
unsigned short

variable_types:
height
unsigned short

variable_types:
strPrefix
char *

variable_types: seq int

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

variable_types: err int

variable_types:
pPix
unsigned char *

variable_types:
strName
char [256]

variable_types:
strTemp
char [16]


decompiled_code:
__int64 __fastcall WrDbgImgUint16(__int64 a1, unsigned __int16 a2, unsigned __int16 a3, const char *a4, int a5)
{
int v5; // er13
_BYTE *v6; // rbp
char *v7; // rax
__int64 v8; // rax
unsigned int v9; // er12
_BYTE *v13; // [rsp+10h] [rbp-158h] BYREF
unsigned __int16 v14; // [rsp+18h] [rbp-150h]
unsigned __int16 v15; // [rsp+1Ah] [rbp-14Eh]
int v16; // [rsp+1Ch] [rbp-14Ch]
char s[16]; // [rsp+20h] [rbp-148h] BYREF
char dest[312]; // [rsp+30h] [rbp-138h] BYREF

v5 = a3 * a2;
v14 = a2;
v15 = a3;
v6 = malloc(v5);
v16 = 0;
v13 = v6;
v7 = stpcpy(dest, a4);
if ( a5 < 0 )
{
strcpy(v7, ".bmp");
}
else
{
sprintf(s, "%05u.bmp", (unsigned int)a5);
strcat(dest, s);
}
v8 = 0LL;
if ( v5 )
{
do
{
v6[v8] = *(_BYTE *)(a1 + 2 * v8 + 1);
++v8;
}
while ( v5 != v8 );
}
v9 = OscBmpWrite(&v13, dest);
free(v6);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int16 a2, unsigned __int16 a3, const char *a4, int a5)
{
int v5; // er13
_BYTE *v6; // rbp
char *v7; // rax
__int64 v8; // rax
unsigned int v9; // er12
_BYTE *v13; // [rsp+10h] [rbp-158h] BYREF
unsigned __int16 v14; // [rsp+18h] [rbp-150h]
unsigned __int16 v15; // [rsp+1Ah] [rbp-14Eh]
int v16; // [rsp+1Ch] [rbp-14Ch]
char s[16]; // [rsp+20h] [rbp-148h] BYREF
char dest[312]; // [rsp+30h] [rbp-138h] BYREF

v5 = a3 * a2;
v14 = a2;
v15 = a3;
v6 = malloc(v5);
v16 = 0;
v13 = v6;
v7 = stpcpy(dest, a4);
if ( a5 < 0 )
{
strcpy(v7, ".bmp");
}
else
{
sprintf(s, "%05u.bmp", (unsigned int)a5);
strcat(dest, s);
}
v8 = 0LL;
if ( v5 )
{
do
{
v6[v8] = *(_BYTE *)(a1 + 2 * v8 + 1);
++v8;
}
while ( v5 != v8 );
}
v9 = OscBmpWrite(&v13, dest);
free(v6);
return v9;
}

original_code:
OSC_ERR WrDbgImgUint16(const uint16 *pData, const uint16 width, const uint16 height, const char * strPrefix, int32 seq)
{
 struct OSC_PICTURE pic;
 OSC_ERR err;
 int i;
 uint8 *pPix;
 char strName[256];
 char strTemp[16];
 pPix = (uint8*)malloc(width*height);
 pic.width = width;
 pic.height = height;
 pic.type = OSC_PICTURE_GREYSCALE;
 pic.data = (void*)pPix;
 strcpy(strName, strPrefix);
 if (seq >= 0)
 {
  sprintf(strTemp, "%05u.bmp", (unsigned int)seq);
  strcat(strName, strTemp);
 }
 else
 {
  strcat(strName, ".bmp");
 }
 for (i = 0; i < width*height; i++)
 {
  pPix[i] = (uint8)(pData[i] >> 8);
 }
 err = OscBmpWrite(&pic, strName);
 free(pPix);
 return err;
}

canonical_original_code:
int WrDbgImgUint16(unsigned short *pData, unsigned short width, unsigned short height, char *strPrefix, int seq)
{
 struct OSC_PICTURE pic;
 int err;
 int i;
 unsigned char *pPix;
 char strName[256];
 char strTemp[16];
 pPix = (unsigned char *)malloc(width*height);
 pic.width = width;
 pic.height = height;
 pic.type = OSC_PICTURE_GREYSCALE;
 pic.data = (void *)pPix;
 strcpy(strName, strPrefix);
 if (seq >= 0)
 {
  sprintf(strTemp, "%05u.bmp", (unsigned int)seq);
  strcat(strName, strTemp);
 }
 else
 {
  strcat(strName, ".bmp");
 }
 for (i = 0; i < width*height; i++)
 {
  pPix[i] = (uint8)(pData[i] >> 8);
 }
 err = OscBmpWrite(&pic, strName);
 free(pPix);
 return err;
}

variable_types:
pData
unsigned short *

variable_types: i int


decompiled_code:
__int64 __fastcall WrDbgImgUint8(__int64 a1, __int16 a2, __int16 a3, const char *a4, unsigned int a5)
{
char *v6; // rax
__int64 v8; // [rsp+0h] [rbp-128h] BYREF
__int16 v9; // [rsp+8h] [rbp-120h]
__int16 v10; // [rsp+Ah] [rbp-11Eh]
int v11; // [rsp+Ch] [rbp-11Ch]
char s[16]; // [rsp+10h] [rbp-118h] BYREF
char dest[264]; // [rsp+20h] [rbp-108h] BYREF

v8 = a1;
v9 = a2;
v10 = a3;
v11 = 0;
v6 = stpcpy(dest, a4);
if ( a5 == -1 )
{
strcpy(v6, ".bmp");
}
else
{
sprintf(s, "%05u.bmp", a5);
strcat(dest, s);
}
return OscBmpWrite(&v8, dest);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int16 a2, __int16 a3, const char *a4, unsigned int a5)
{
char *v6; // rax
__int64 v8; // [rsp+0h] [rbp-128h] BYREF
__int16 v9; // [rsp+8h] [rbp-120h]
__int16 v10; // [rsp+Ah] [rbp-11Eh]
int v11; // [rsp+Ch] [rbp-11Ch]
char s[16]; // [rsp+10h] [rbp-118h] BYREF
char dest[264]; // [rsp+20h] [rbp-108h] BYREF

v8 = a1;
v9 = a2;
v10 = a3;
v11 = 0;
v6 = stpcpy(dest, a4);
if ( a5 == -1 )
{
strcpy(v6, ".bmp");
}
else
{
sprintf(s, "%05u.bmp", a5);
strcat(dest, s);
}
return OscBmpWrite(&v8, dest);
}

original_code:
OSC_ERR WrDbgImgUint8(const uint8 *pData, const uint16 width, const uint16 height, const char * strPrefix, int32 seq)
{
 struct OSC_PICTURE pic;
 OSC_ERR err;
 char strName[256];
 char strTemp[16];
 pic.width = width;
 pic.height = height;
 pic.type = OSC_PICTURE_GREYSCALE;
 pic.data = (uint8*)pData;
 strcpy(strName, strPrefix);
 if (seq != -1)
 {
  sprintf(strTemp, "%05u.bmp", (unsigned int)seq);
  strcat(strName, strTemp);
 }
 else
 {
  strcat(strName, ".bmp");
 }
 err = OscBmpWrite(&pic, strName);
 return err;
}

canonical_original_code:
int WrDbgImgUint8(unsigned char *pData, unsigned short width, unsigned short height, char *strPrefix, int seq)
{
 struct OSC_PICTURE pic;
 int err;
 char strName[256];
 char strTemp[16];
 pic.width = width;
 pic.height = height;
 pic.type = OSC_PICTURE_GREYSCALE;
 pic.data = (unsigned char *)pData;
 strcpy(strName, strPrefix);
 if (seq != -1)
 {
  sprintf(strTemp, "%05u.bmp", (unsigned int)seq);
  strcat(strName, strTemp);
 }
 else
 {
  strcat(strName, ".bmp");
 }
 err = OscBmpWrite(&pic, strName);
 return err;
}

variable_types:
pData
unsigned char *


OscLogDestroy

decompiled_code:
__int64 OscLogDestroy()
{
fclose(*(FILE **)&osc_log[2120]);
fclose(*(FILE **)&osc_log[2128]);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
fclose(*(FILE **)&osc_log[2120]);
fclose(*(FILE **)&osc_log[2128]);
return 0LL;
}

original_code:
OSC_ERR OscLogDestroy()
{
 fclose(osc_log.pLogF);
 fclose(osc_log.pSimLogF);
 return SUCCESS;
}

canonical_original_code:
int OscLogDestroy()
{
 fclose(osc_log.pLogF);
 fclose(osc_log.pSimLogF);
 return SUCCESS;
}


OscLogSetConsoleLogLevel

decompiled_code:
__int64 __fastcall OscLogSetConsoleLogLevel(int a1)
{
*(_DWORD *)&osc_log[64] = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
*(_DWORD *)&osc_log[64] = a1;
return 0LL;
}

original_code:
OSC_ERR OscLogSetConsoleLogLevel(const enum EnOscLogLevel level)
{
 osc_log.consoleLogLevel = level;
 return SUCCESS;
}

canonical_original_code:
int OscLogSetConsoleLogLevel(enum EnOscLogLevel level)
{
 osc_log.consoleLogLevel = level;
 return SUCCESS;
}

variable_types: enum EnOscLogLevel { NOLOG=-1, EMERG=0, ALERT=1, CRITICAL=2, ERROR=3, WARN=4, NOTICE=5, INFO=6, DEBUG=7, NONE=8, SIMULATION=255 }


OscLogSetFileLogLevel

decompiled_code:
__int64 __fastcall OscLogSetFileLogLevel(int a1)
{
*(_DWORD *)&osc_log[68] = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
*(_DWORD *)&osc_log[68] = a1;
return 0LL;
}

original_code:
OSC_ERR OscLogSetFileLogLevel(const enum EnOscLogLevel level)
{
 osc_log.fileLogLevel = level;
 return SUCCESS;
}

canonical_original_code:
int OscLogSetFileLogLevel(enum EnOscLogLevel level)
{
 osc_log.fileLogLevel = level;
 return SUCCESS;
}

user_defined_types: enum EnOscLogLevel { NOLOG=-1, EMERG=0, ALERT=1, CRITICAL=2, ERROR=3, WARN=4, NOTICE=5, INFO=6, DEBUG=7, NONE=8, SIMULATION=255 }


OscFatalErr

decompiled_code:
void __noreturn OscFatalErr(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
osc_log[72] = 0;
vprintf(format, arg);
va_end(arg);
va_start(arg, format);
vsprintf((char *)(unsigned int)((_DWORD)osc_log + 72), format, arg);
syslog(0, "%s", (const char *)(unsigned int)((_DWORD)osc_log + 72));
exit(1);
}

canonical_decompiled_code:
void __noreturn func5(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
osc_log[72] = 0;
vprintf(format, arg);
va_end(arg);
va_start(arg, format);
vsprintf((char *)(unsigned int)((_DWORD)osc_log + 72), format, arg);
syslog(0, "%s", (const char *)(unsigned int)((_DWORD)osc_log + 72));
exit(1);
}

original_code:
OSC_ERR OscFatalErr(const char * strFormat, ...)
{
 uint16 len = 0;
 va_list ap;
 osc_log.strTemp[0] = 0;
 __builtin_va_start(ap,strFormat);
 vprintf(strFormat, ap);
 __builtin_va_end(ap);
 __builtin_va_start(ap,strFormat);
 len += vsprintf(osc_log.strTemp, strFormat, ap);
 __builtin_va_end(ap);
 syslog(EMERG, "%s", osc_log.strTemp);
 exit(1);
}

canonical_original_code:
int OscFatalErr(char *strFormat, ...)
{
 unsigned short len = 0;
 __builtin_va_list ap;
 osc_log.strTemp[0] = 0;
 __builtin_va_start(ap,strFormat);
 vprintf(strFormat, ap);
 __builtin_va_end(ap);
 __builtin_va_start(ap,strFormat);
 len += vsprintf(osc_log.strTemp, strFormat, ap);
 __builtin_va_end(ap);
 syslog(EMERG, "%s", osc_log.strTemp);
 exit(1);
}

variable_types:
strFormat
char *

variable_types:
len
unsigned short


HsmOnEvent

original_code:
void HsmOnEvent(Hsm *me, Msg const *msg) {
 State *entryPath[8];
 register State **trace;
 register State *s;
 for (s = me->curr; s; s = s->super) {
  me->source = s;
  msg = (*(s)->hndlr)((me), (msg));
  if (msg == 0) {
   if (me->next) {
    trace = entryPath;
    *trace = 0;
    for (s = me->next; s != me->curr; s = s->super) {
     *(++trace) = s;
    }
    while (0 != (s = *trace--)) {
     (*(s)->hndlr)((me), (&entryMsg));
    }
    me->curr = me->next;
    me->next = 0;
    while ((*(me->curr)->hndlr)((me), (&startMsg)), me->next) {
     trace = entryPath;
     *trace = 0;
     for (s = me->next; s != me->curr; s = s->super) {
      *(++trace) = s;
     }
     while (0!= (s = *trace--)) {
      (*(s)->hndlr)((me), (&entryMsg));
     }
     me->curr = me->next;
     me->next = 0;
    }
   }
   break;
  }
 }
}

canonical_original_code:
void HsmOnEvent(struct Hsm *me, struct Msg *msg) {
 struct State *entryPath[8];
 register struct State **trace;
 register struct State *s;
 for (s = me->curr; s; s = s->super) {
  me->source = s;
  msg = (*(s)->hndlr)((me), (msg));
  if (msg == 0) {
   if (me->next) {
    trace = entryPath;
    *trace = 0;
    for (s = me->next; s != me->curr; s = s->super) {
     *(++trace) = s;
    }
    while (0 != (s = *trace--)) {
     (*(s)->hndlr)((me), (&entryMsg));
    }
    me->curr = me->next;
    me->next = 0;
    while ((*(me->curr)->hndlr)((me), (&startMsg)), me->next) {
     trace = entryPath;
     *trace = 0;
     for (s = me->next; s != me->curr; s = s->super) {
      *(++trace) = s;
     }
     while (0!= (s = *trace--)) {
      (*(s)->hndlr)((me), (&entryMsg));
     }
     me->curr = me->next;
     me->next = 0;
    }
   }
   break;
  }
 }
}

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

variable_types:
msg
struct Msg *

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

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

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


original_code:
void HsmExit_(Hsm *me, unsigned char toLca) {
 register State *s = me->curr;
 while (s != me->source) {
  (*(s)->hndlr)((me), (&exitMsg));
  s = s->super;
 }
 while (toLca--) {
  (*(s)->hndlr)((me), (&exitMsg));
  s = s->super;
 }
 me->curr = s;
}

canonical_original_code:
void HsmExit_(struct Hsm *me, unsigned char toLca) {
 register struct State *s = me->curr;
 while (s != me->source) {
  (*(s)->hndlr)((me), (&exitMsg));
  s = s->super;
 }
 while (toLca--) {
  (*(s)->hndlr)((me), (&exitMsg));
  s = s->super;
 }
 me->curr = s;
}

variable_types:
toLca
unsigned char

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


decompiled_code:
__int64 __fastcall HsmToLCA_(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rdx
unsigned int v3; // er8
_QWORD *v4; // rax

v2 = *(_QWORD **)(a1 + 24);
if ( v2 == a2 )
return 1LL;
v3 = 0;
if ( v2 )
{
do
{
if ( a2 )
{
if ( a2 == v2 )
return v3;
v4 = a2;
while ( 1 )
{
v4 = (_QWORD *)*v4;
if ( !v4 )
break;
if ( v4 == v2 )
return v3;
}
}
v2 = (_QWORD *)*v2;
++v3;
}
while ( v2 );
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rdx
unsigned int v3; // er8
_QWORD *v4; // rax

v2 = *(_QWORD **)(a1 + 24);
if ( v2 == a2 )
return 1LL;
v3 = 0;
if ( v2 )
{
do
{
if ( a2 )
{
if ( a2 == v2 )
return v3;
v4 = a2;
while ( 1 )
{
v4 = (_QWORD *)*v4;
if ( !v4 )
break;
if ( v4 == v2 )
return v3;
}
}
v2 = (_QWORD *)*v2;
++v3;
}
while ( v2 );
v3 = 0;
}
return v3;
}

original_code:
unsigned char HsmToLCA_(Hsm *me, State *target) {
 State *s, *t;
 unsigned char toLca = 0;
 if (me->source == target) {
  return 1;
 }
 for (s = me->source; s; ++toLca, s = s->super) {
  for (t = target; t; t = t->super) {
   if (s == t) {
    return toLca;
   }
  }
 }
 return 0;
}

canonical_original_code:
unsigned char HsmToLCA_(struct Hsm *me, struct State *target) {
 struct State *s; struct State *t;
 unsigned char toLca = 0;
 if (me->source == target) {
  return 1;
 }
 for (s = me->source; s; ++toLca, s = s->super) {
  for (t = target; t; t = t->super) {
   if (s == t) {
    return toLca;
   }
  }
 }
 return 0;
}

variable_types:
target
struct State *

return_type: unsigned char

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