main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // eax
bool v5; // al
bool v6; // cf
bool v7; // zf
__int64 v8; // rcx
const char *v9; // rdi
char *v10; // rsi
bool v11; // cf
bool v12; // zf
char *v13; // rsi
__int64 v14; // rcx
const char *v15; // rdi
char v16; // al
bool v17; // cf
bool v18; // zf
char *v19; // rsi
__int64 v20; // rcx
const char *v21; // rdi
__int64 v23; // rax

v3 = "../../drivers/can_virtual/libcanfestival_can_virtual.so";
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "-m:s:M:S:l:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'M':
if ( !*optarg )
goto LABEL_9;
MasterBoard[1] = optarg;
break;
case 'S':
if ( !*optarg )
goto LABEL_9;
SlaveBoard[1] = optarg;
break;
case 'l':
v3 = optarg;
if ( !*optarg )
goto LABEL_9;
continue;
case 'm':
if ( !*optarg )
goto LABEL_9;
MasterBoard[0] = optarg;
break;
case 's':
if ( !*optarg )
goto LABEL_9;
SlaveBoard[0] = optarg;
break;
default:
LABEL_9:
help();
exit(1);
}
}
signal(15, (__sighandler_t)catch_signal);
signal(2, (__sighandler_t)catch_signal);
TimerInit();
if ( !LoadCanDriver(v3) )
printf("Unable to load library: %s\n", v3);
v5 = strcmp(SlaveBoard[1], "none") != 0;
v6 = 0;
v7 = !v5;
if ( !v5 )
goto LABEL_17;
TestSlave_Data[83] = &TestSlave_heartbeatError;
TestSlave_Data[72] = &TestSlave_initialisation;
TestSlave_Data[73] = &TestSlave_preOperational;
TestSlave_Data[74] = &TestSlave_operational;
TestSlave_Data[75] = &TestSlave_stopped;
TestSlave_Data[171] = &TestSlave_post_sync;
TestSlave_Data[172] = &TestSlave_post_TPDO;
TestSlave_Data[178] = &TestSlave_storeODSubIndex;
TestSlave_Data[194] = &TestSlave_post_emcy;
v23 = canOpen(SlaveBoard);
v6 = 0;
v7 = v23 == 0;
if ( v23 )
{
LABEL_17:
v8 = 5LL;
v9 = "none";
v10 = MasterBoard[1];
do
{
if ( !v8 )
break;
v6 = (unsigned __int8)*v10 < (unsigned int)*v9;
v7 = *v10++ == *v9++;
--v8;
}
while ( v7 );
if ( (!v6 && !v7) == v6 )
goto LABEL_21;
v10 = (char *)TestMaster_Data;
TestMaster_Data[83] = &TestMaster_heartbeatError;
TestMaster_Data[72] = &TestMaster_initialisation;
TestMaster_Data[73] = &TestMaster_preOperational;
TestMaster_Data[74] = &TestMaster_operational;
TestMaster_Data[75] = &TestMaster_stopped;
TestMaster_Data[171] = &TestMaster_post_sync;
TestMaster_Data[172] = &TestMaster_post_TPDO;
TestMaster_Data[194] = &TestMaster_post_emcy;
TestMaster_Data[173] = &TestMaster_post_SlaveBootup;
if ( canOpen(MasterBoard) )
{
LABEL_21:
StartTimerLoop(InitNodes, v10);
pause();
StopTimerLoop(Exit);
v13 = MasterBoard[1];
v14 = 5LL;
v15 = "none";
do
{
if ( !v14 )
break;
v11 = (unsigned __int8)*v13 < (unsigned int)*v15;
v12 = *v13++ == *v15++;
--v14;
}
while ( v12 );
v16 = (!v11 && !v12) - v11;
v17 = 0;
v18 = v16 == 0;
if ( v16 )
canClose(TestMaster_Data, v13);
}
else
{
printf("Cannot open Master Board (%s,%s)\n", MasterBoard[0], MasterBoard[1]);
}
v19 = SlaveBoard[1];
v20 = 5LL;
v21 = "none";
do
{
if ( !v20 )
break;
v17 = (unsigned __int8)*v19 < (unsigned int)*v21;
v18 = *v19++ == *v21++;
--v20;
}
while ( v18 );
if ( (!v17 && !v18) != v17 )
{
v21 = (const char *)TestSlave_Data;
canClose(TestSlave_Data, v19);
}
}
else
{
v19 = SlaveBoard[0];
v21 = "Cannot open Slave Board (%s,%s)\n";
printf("Cannot open Slave Board (%s,%s)\n", SlaveBoard[0], SlaveBoard[1]);
}
TimerCleanup(v21, v19);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // eax
bool v5; // al
bool v6; // cf
bool v7; // zf
__int64 v8; // rcx
const char *v9; // rdi
char *v10; // rsi
bool v11; // cf
bool v12; // zf
char *v13; // rsi
__int64 v14; // rcx
const char *v15; // rdi
char v16; // al
bool v17; // cf
bool v18; // zf
char *v19; // rsi
__int64 v20; // rcx
const char *v21; // rdi
__int64 v23; // rax

v3 = "../../drivers/can_virtual/libcanfestival_can_virtual.so";
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "-m:s:M:S:l:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'M':
if ( !*optarg )
goto LABEL_9;
MasterBoard[1] = optarg;
break;
case 'S':
if ( !*optarg )
goto LABEL_9;
SlaveBoard[1] = optarg;
break;
case 'l':
v3 = optarg;
if ( !*optarg )
goto LABEL_9;
continue;
case 'm':
if ( !*optarg )
goto LABEL_9;
MasterBoard[0] = optarg;
break;
case 's':
if ( !*optarg )
goto LABEL_9;
SlaveBoard[0] = optarg;
break;
default:
LABEL_9:
func4();
exit(1);
}
}
signal(15, (__sighandler_t)catch_signal);
signal(2, (__sighandler_t)catch_signal);
TimerInit();
if ( !LoadCanDriver(v3) )
printf("Unable to load library: %s\n", v3);
v5 = strcmp(SlaveBoard[1], "none") != 0;
v6 = 0;
v7 = !v5;
if ( !v5 )
goto LABEL_17;
TestSlave_Data[83] = &TestSlave_heartbeatError;
TestSlave_Data[72] = &TestSlave_initialisation;
TestSlave_Data[73] = &TestSlave_preOperational;
TestSlave_Data[74] = &TestSlave_operational;
TestSlave_Data[75] = &TestSlave_stopped;
TestSlave_Data[171] = &TestSlave_post_sync;
TestSlave_Data[172] = &TestSlave_post_TPDO;
TestSlave_Data[178] = &TestSlave_storeODSubIndex;
TestSlave_Data[194] = &TestSlave_post_emcy;
v23 = canOpen(SlaveBoard);
v6 = 0;
v7 = v23 == 0;
if ( v23 )
{
LABEL_17:
v8 = 5LL;
v9 = "none";
v10 = MasterBoard[1];
do
{
if ( !v8 )
break;
v6 = (unsigned __int8)*v10 < (unsigned int)*v9;
v7 = *v10++ == *v9++;
--v8;
}
while ( v7 );
if ( (!v6 && !v7) == v6 )
goto LABEL_21;
v10 = (char *)TestMaster_Data;
TestMaster_Data[83] = &TestMaster_heartbeatError;
TestMaster_Data[72] = &TestMaster_initialisation;
TestMaster_Data[73] = &TestMaster_preOperational;
TestMaster_Data[74] = &TestMaster_operational;
TestMaster_Data[75] = &TestMaster_stopped;
TestMaster_Data[171] = &TestMaster_post_sync;
TestMaster_Data[172] = &TestMaster_post_TPDO;
TestMaster_Data[194] = &TestMaster_post_emcy;
TestMaster_Data[173] = &TestMaster_post_SlaveBootup;
if ( canOpen(MasterBoard) )
{
LABEL_21:
StartTimerLoop(InitNodes, v10);
pause();
StopTimerLoop(Exit);
v13 = MasterBoard[1];
v14 = 5LL;
v15 = "none";
do
{
if ( !v14 )
break;
v11 = (unsigned __int8)*v13 < (unsigned int)*v15;
v12 = *v13++ == *v15++;
--v14;
}
while ( v12 );
v16 = (!v11 && !v12) - v11;
v17 = 0;
v18 = v16 == 0;
if ( v16 )
canClose(TestMaster_Data, v13);
}
else
{
printf("Cannot open Master Board (%s,%s)\n", MasterBoard[0], MasterBoard[1]);
}
v19 = SlaveBoard[1];
v20 = 5LL;
v21 = "none";
do
{
if ( !v20 )
break;
v17 = (unsigned __int8)*v19 < (unsigned int)*v21;
v18 = *v19++ == *v21++;
--v20;
}
while ( v18 );
if ( (!v17 && !v18) != v17 )
{
v21 = (const char *)TestSlave_Data;
canClose(TestSlave_Data, v19);
}
}
else
{
v19 = SlaveBoard[0];
v21 = "Cannot open Slave Board (%s,%s)\n";
printf("Cannot open Slave Board (%s,%s)\n", SlaveBoard[0], SlaveBoard[1]);
}
TimerCleanup(v21, v19);
return 0;
}

original_code:
int main(int argc,char **argv)
{
  int c;
  extern char *optarg;
  char* LibraryPath="../../drivers/can_virtual/libcanfestival_can_virtual.so";
  while ((c = getopt(argc, argv, "-m:s:M:S:l:")) != (-1))
  {
    switch(c)
    {
      case 's' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        SlaveBoard.busname = optarg;
        break;
      case 'm' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        MasterBoard.busname = optarg;
        break;
      case 'S' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        SlaveBoard.baudrate = optarg;
        break;
      case 'M' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        MasterBoard.baudrate = optarg;
        break;
      case 'l' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        LibraryPath = optarg;
        break;
      default:
        help();
        exit(1);
    }
  }
 signal(15, catch_signal);
 signal(2, catch_signal);
 TimerInit();
 if (LoadCanDriver(LibraryPath) == ((void *)0))
     printf("Unable to load library: %s\n",LibraryPath);
 if(strcmp(SlaveBoard.baudrate, "none")){
  TestSlave_Data.heartbeatError = TestSlave_heartbeatError;
  TestSlave_Data.initialisation = TestSlave_initialisation;
  TestSlave_Data.preOperational = TestSlave_preOperational;
  TestSlave_Data.operational = TestSlave_operational;
  TestSlave_Data.stopped = TestSlave_stopped;
  TestSlave_Data.post_sync = TestSlave_post_sync;
  TestSlave_Data.post_TPDO = TestSlave_post_TPDO;
  TestSlave_Data.storeODSubIndex = TestSlave_storeODSubIndex;
  TestSlave_Data.post_emcy = TestSlave_post_emcy;
  if(!canOpen(&SlaveBoard,&TestSlave_Data)){
   printf ("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate);
   goto fail_slave;
  }
 }
 if(strcmp(MasterBoard.baudrate, "none")){
  TestMaster_Data.heartbeatError = TestMaster_heartbeatError;
  TestMaster_Data.initialisation = TestMaster_initialisation;
  TestMaster_Data.preOperational = TestMaster_preOperational;
  TestMaster_Data.operational = TestMaster_operational;
  TestMaster_Data.stopped = TestMaster_stopped;
  TestMaster_Data.post_sync = TestMaster_post_sync;
  TestMaster_Data.post_TPDO = TestMaster_post_TPDO;
  TestMaster_Data.post_emcy = TestMaster_post_emcy;
  TestMaster_Data.post_SlaveBootup=TestMaster_post_SlaveBootup;
  if(!canOpen(&MasterBoard,&TestMaster_Data)){
   printf ("Cannot open Master Board (%s,%s)\n",MasterBoard.busname, MasterBoard.baudrate);
   goto fail_master;
  }
 }
 StartTimerLoop(&InitNodes);
 pause();
 StopTimerLoop(&Exit);
 if(strcmp(MasterBoard.baudrate, "none")) canClose(&TestMaster_Data);
fail_master:
 if(strcmp(SlaveBoard.baudrate, "none")) canClose(&TestSlave_Data);
fail_slave:
 TimerCleanup();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int c;
  extern char *optarg;
  char *LibraryPath = "../../drivers/can_virtual/libcanfestival_can_virtual.so";
  while ((c = getopt(argc, argv, "-m:s:M:S:l:")) != (-1))
  {
    switch(c)
    {
      case 's' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        SlaveBoard.busname = optarg;
        break;
      case 'm' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        MasterBoard.busname = optarg;
        break;
      case 'S' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        SlaveBoard.baudrate = optarg;
        break;
      case 'M' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        MasterBoard.baudrate = optarg;
        break;
      case 'l' :
        if (optarg[0] == 0)
        {
          help();
          exit(1);
        }
        LibraryPath = optarg;
        break;
      default:
        help();
        exit(1);
    }
  }
 signal(15, catch_signal);
 signal(2, catch_signal);
 TimerInit();
 if (LoadCanDriver(LibraryPath) == ((void *)0))
     printf("Unable to load library: %s\n",LibraryPath);
 if(strcmp(SlaveBoard.baudrate, "none")){
  TestSlave_Data.heartbeatError = TestSlave_heartbeatError;
  TestSlave_Data.initialisation = TestSlave_initialisation;
  TestSlave_Data.preOperational = TestSlave_preOperational;
  TestSlave_Data.operational = TestSlave_operational;
  TestSlave_Data.stopped = TestSlave_stopped;
  TestSlave_Data.post_sync = TestSlave_post_sync;
  TestSlave_Data.post_TPDO = TestSlave_post_TPDO;
  TestSlave_Data.storeODSubIndex = TestSlave_storeODSubIndex;
  TestSlave_Data.post_emcy = TestSlave_post_emcy;
  if(!canOpen(&SlaveBoard,&TestSlave_Data)){
   printf ("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate);
   goto fail_slave;
  }
 }
 if(strcmp(MasterBoard.baudrate, "none")){
  TestMaster_Data.heartbeatError = TestMaster_heartbeatError;
  TestMaster_Data.initialisation = TestMaster_initialisation;
  TestMaster_Data.preOperational = TestMaster_preOperational;
  TestMaster_Data.operational = TestMaster_operational;
  TestMaster_Data.stopped = TestMaster_stopped;
  TestMaster_Data.post_sync = TestMaster_post_sync;
  TestMaster_Data.post_TPDO = TestMaster_post_TPDO;
  TestMaster_Data.post_emcy = TestMaster_post_emcy;
  TestMaster_Data.post_SlaveBootup=TestMaster_post_SlaveBootup;
  if(!canOpen(&MasterBoard,&TestMaster_Data)){
   printf ("Cannot open Master Board (%s,%s)\n",MasterBoard.busname, MasterBoard.baudrate);
   goto fail_master;
  }
 }
 StartTimerLoop(&InitNodes);
 pause();
 StopTimerLoop(&Exit);
 if(strcmp(MasterBoard.baudrate, "none")) canClose(&TestMaster_Data);
fail_master:
 if(strcmp(SlaveBoard.baudrate, "none")) canClose(&TestSlave_Data);
fail_slave:
 TimerCleanup();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types:
optarg
char *

variable_types:
LibraryPath
char *

return_type: int


decompiled_code:
int __fastcall TestSlave_heartbeatError(__int64 a1, unsigned __int8 a2)
{
return printf("TestSlave_heartbeatError %d\n", a2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned __int8 a2)
{
return printf("TestSlave_heartbeatError %d\n", a2);
}

original_code:
void TestSlave_heartbeatError(CO_Data* d, unsigned char heartbeatID)
{
 printf ("TestSlave_heartbeatError %d\n", heartbeatID);
}

canonical_original_code:
void TestSlave_heartbeatError(struct struct_CO_Data *d, unsigned char heartbeatID)
{
 printf ("TestSlave_heartbeatError %d\n", heartbeatID);
}

variable_types: struct struct_CO_Data { unsigned char *bDeviceNodeId; struct td_indextable { struct td_subindex { unsigned char bAccessType; unsigned char bDataType; unsigned long size; void *pObject; } *pSubindex; unsigned char bSubCount; unsigned short index; } *objdict; struct struct_s_PDO_status { unsigned char transmit_type_parameter; short event_timer; short inhibit_timer; struct Message { unsigned short cob_id; unsigned char rtr; unsigned char len; unsigned char data[8]; } last_message; } *PDO_status; short *RxPDO_EventTimers; void (*RxPDO_EventTimers_Handler)(struct struct_CO_Data *, unsigned long); struct s_quick_index { unsigned short SDO_SVR; unsigned short SDO_CLT; unsigned short PDO_RCV; unsigned short PDO_RCV_MAP; unsigned short PDO_TRS; unsigned short PDO_TRS_MAP; } *firstIndex; struct s_quick_index *lastIndex; unsigned short *ObjdictSize; unsigned char *iam_a_slave; unsigned long (*valueRangeTest)(unsigned char typeValue, void *Value); struct struct_s_transfer { unsigned char CliServNbr; unsigned char whoami; unsigned char state; unsigned char toggle; unsigned long abortCode; unsigned short index; unsigned char subIndex; unsigned long count; unsigned long offset; unsigned char data[32]; unsigned char peerCRCsupport; unsigned char blksize; unsigned char ackseq; unsigned long objsize; unsigned char lastblockoffset; unsigned char seqno; unsigned char endfield; enum rxStep_t { RXSTEP_INIT=0, RXSTEP_STARTED=1, RXSTEP_END=2 } rxstep; unsigned char tmpData[8]; unsigned char dataType; short timer; void (*Callback)(struct struct_CO_Data *d, unsigned char nodeId); } transfers[4]; enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 } nodeState; struct s_state_communication { char csBoot_Up; char csSDO; char csEmergency; char csSYNC; char csLifeGuard; char csPDO; char csLSS; } CurrentCommunicationState; void (*initialisation)(struct struct_CO_Data *); void (*preOperational)(struct struct_CO_Data *); void (*operational)(struct struct_CO_Data *); void (*stopped)(struct struct_CO_Data *); void (*NMT_Slave_Node_Reset_Callback)(struct struct_CO_Data *); void (*NMT_Slave_Communications_Reset_Callback)(struct struct_CO_Data *); unsigned char *ConsumerHeartbeatCount; unsigned long *ConsumerHeartbeatEntries; short *ConsumerHeartBeatTimers; unsigned short *ProducerHeartBeatTime; short ProducerHeartBeatTimer; void (*heartbeatError)(struct struct_CO_Data *, unsigned char); enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 } NMTable[128]; short GuardTimeTimer; short LifeTimeTimer; void (*nodeguardError)(struct struct_CO_Data *, unsigned char); unsigned short *GuardTime; unsigned char *LifeTimeFactor; unsigned char nodeGuardStatus[128]; short syncTimer; unsigned long *COB_ID_Sync; unsigned long *Sync_Cycle_Period; void (*post_sync)(struct struct_CO_Data *); void (*post_TPDO)(struct struct_CO_Data *); void (*post_SlaveBootup)(struct struct_CO_Data *, unsigned char); void (*post_SlaveStateChange)(struct struct_CO_Data *, unsigned char, enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 }); unsigned char toggle; void *canHandle; struct td_indextable *(*scanIndexOD)(unsigned short wIndex, unsigned long *errorCode, unsigned long (***Callback)(struct struct_CO_Data *d, struct td_indextable *, unsigned char bSubindex)); void (*storeODSubIndex)(struct struct_CO_Data *d, unsigned short wIndex, unsigned char bSubindex); struct td_indextable *dcf_odentry; unsigned char *dcf_cursor; unsigned long dcf_entries_count; unsigned char dcf_status; unsigned long dcf_size; unsigned char *dcf_data; enum enum_errorState { Error_free=0, Error_occurred=1 } error_state; unsigned char error_history_size; unsigned char *error_number; unsigned long *error_first_element; unsigned char *error_register; unsigned long *error_cobid; struct s_errors { unsigned short errCode; unsigned char errRegMask; unsigned char active; } error_data[8]; void (*post_emcy)(struct struct_CO_Data *d, unsigned char nodeID, unsigned short errCode, unsigned char errReg); } *

variable_types:
heartbeatID
unsigned char

return_type: void

user_defined_types: struct struct_CO_Data { unsigned char *bDeviceNodeId; struct td_indextable *objdict; struct struct_s_PDO_status *PDO_status; short *RxPDO_EventTimers; void (*RxPDO_EventTimers_Handler)(struct struct_CO_Data *, unsigned long); struct s_quick_index *firstIndex; struct s_quick_index *lastIndex; unsigned short *ObjdictSize; unsigned char *iam_a_slave; unsigned long (*valueRangeTest)(unsigned char typeValue, void *Value); struct struct_s_transfer transfers[4]; enum enum_nodeState nodeState; struct s_state_communication CurrentCommunicationState; void (*initialisation)(struct struct_CO_Data *); void (*preOperational)(struct struct_CO_Data *); void (*operational)(struct struct_CO_Data *); void (*stopped)(struct struct_CO_Data *); void (*NMT_Slave_Node_Reset_Callback)(struct struct_CO_Data *); void (*NMT_Slave_Communications_Reset_Callback)(struct struct_CO_Data *); unsigned char *ConsumerHeartbeatCount; unsigned long *ConsumerHeartbeatEntries; short *ConsumerHeartBeatTimers; unsigned short *ProducerHeartBeatTime; short ProducerHeartBeatTimer; void (*heartbeatError)(struct struct_CO_Data *, unsigned char); enum enum_nodeState NMTable[128]; short GuardTimeTimer; short LifeTimeTimer; void (*nodeguardError)(struct struct_CO_Data *, unsigned char); unsigned short *GuardTime; unsigned char *LifeTimeFactor; unsigned char nodeGuardStatus[128]; short syncTimer; unsigned long *COB_ID_Sync; unsigned long *Sync_Cycle_Period; void (*post_sync)(struct struct_CO_Data *); void (*post_TPDO)(struct struct_CO_Data *); void (*post_SlaveBootup)(struct struct_CO_Data *, unsigned char); void (*post_SlaveStateChange)(struct struct_CO_Data *, unsigned char, enum enum_nodeState); unsigned char toggle; void *canHandle; struct td_indextable *(*scanIndexOD)(unsigned short wIndex, unsigned long *errorCode, unsigned long (***Callback)(struct struct_CO_Data *d, struct td_indextable *, unsigned char bSubindex)); void (*storeODSubIndex)(struct struct_CO_Data *d, unsigned short wIndex, unsigned char bSubindex); struct td_indextable *dcf_odentry; unsigned char *dcf_cursor; unsigned long dcf_entries_count; unsigned char dcf_status; unsigned long dcf_size; unsigned char *dcf_data; enum enum_errorState error_state; unsigned char error_history_size; unsigned char *error_number; unsigned long *error_first_element; unsigned char *error_register; unsigned long *error_cobid; struct s_errors error_data[8]; void (*post_emcy)(struct struct_CO_Data *d, unsigned char nodeID, unsigned short errCode, unsigned char errReg); }

user_defined_types: struct td_indextable { struct td_subindex *pSubindex; unsigned char bSubCount; unsigned short index; }

user_defined_types: struct struct_s_PDO_status { unsigned char transmit_type_parameter; short event_timer; short inhibit_timer; struct Message last_message; }

user_defined_types: struct struct_s_transfer { unsigned char CliServNbr; unsigned char whoami; unsigned char state; unsigned char toggle; unsigned long abortCode; unsigned short index; unsigned char subIndex; unsigned long count; unsigned long offset; unsigned char data[32]; unsigned char peerCRCsupport; unsigned char blksize; unsigned char ackseq; unsigned long objsize; unsigned char lastblockoffset; unsigned char seqno; unsigned char endfield; enum rxStep_t rxstep; unsigned char tmpData[8]; unsigned char dataType; short timer; void (*Callback)(struct struct_CO_Data *d, unsigned char nodeId); }


decompiled_code:
int TestSlave_initialisation()
{
return puts("TestSlave_initialisation");
}

canonical_decompiled_code:
int func1()
{
return puts("TestSlave_initialisation");
}

original_code:
void TestSlave_initialisation(CO_Data* d)
{
 printf ("TestSlave_initialisation\n");
}

canonical_original_code:
void TestSlave_initialisation(struct struct_CO_Data *d)
{
 printf ("TestSlave_initialisation\n");
}

user_defined_types: enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 }

user_defined_types: struct s_state_communication { char csBoot_Up; char csSDO; char csEmergency; char csSYNC; char csLifeGuard; char csPDO; char csLSS; }

user_defined_types: enum enum_errorState { Error_free=0, Error_occurred=1 }

user_defined_types: struct s_quick_index { unsigned short SDO_SVR; unsigned short SDO_CLT; unsigned short PDO_RCV; unsigned short PDO_RCV_MAP; unsigned short PDO_TRS; unsigned short PDO_TRS_MAP; }

user_defined_types: struct s_errors { unsigned short errCode; unsigned char errRegMask; unsigned char active; }

user_defined_types: struct Message { unsigned short cob_id; unsigned char rtr; unsigned char len; unsigned char data[8]; }

user_defined_types: enum rxStep_t { RXSTEP_INIT=0, RXSTEP_STARTED=1, RXSTEP_END=2 }

user_defined_types: struct td_subindex { unsigned char bAccessType; unsigned char bDataType; unsigned long size; void *pObject; }


decompiled_code:
int TestSlave_preOperational()
{
return puts("TestSlave_preOperational");
}

canonical_decompiled_code:
int func2()
{
return puts("TestSlave_preOperational");
}

original_code:
void TestSlave_preOperational(CO_Data* d)
{
 printf ("TestSlave_preOperational\n");
}

canonical_original_code:
void TestSlave_preOperational(struct struct_CO_Data *d)
{
 printf ("TestSlave_preOperational\n");
}


decompiled_code:
int TestSlave_operational()
{
return puts("TestSlave_operational");
}

canonical_decompiled_code:
int func3()
{
return puts("TestSlave_operational");
}

original_code:
void TestSlave_operational(CO_Data* d)
{
 printf ("TestSlave_operational\n");
}

canonical_original_code:
void TestSlave_operational(struct struct_CO_Data *d)
{
 printf ("TestSlave_operational\n");
}


decompiled_code:
int TestSlave_stopped()
{
return puts("TestSlave_stopped");
}

canonical_decompiled_code:
int func4()
{
return puts("TestSlave_stopped");
}

original_code:
void TestSlave_stopped(CO_Data* d)
{
 printf ("TestSlave_stopped\n");
}

canonical_original_code:
void TestSlave_stopped(struct struct_CO_Data *d)
{
 printf ("TestSlave_stopped\n");
}


decompiled_code:
int TestSlave_post_sync()
{
__int64 v0; // rax

puts("TestSlave_post_sync");
SlaveMap1 = 1;
SlaveMap2 = 1;
SlaveMap3 = 0;
SlaveMap4 = 0;
SlaveMap5 = 1;
SlaveMap6 = 0;
SlaveMap7 = 1;
SlaveMap8 = 0;
SlaveMap9 = 16;
SlaveMap10 = 4278255360LL;
SlaveMap11 = -21555;
v0 = SlaveMap12 + (unsigned int)((__int16)SlaveMap12 <= 128);
SlaveMap12 += (__int16)SlaveMap12 <= 128;
LODWORD(v0) = (__int16)v0;
return printf(
"Slave: %d %d %d %d %d %d %d %d %d %x %x %d %d \n",
1LL,
1LL,
0LL,
0LL,
1LL,
0LL,
1LL,
0LL,
16LL,
4278255360LL,
43981LL,
v0,
(unsigned int)SlaveMap13);
}

canonical_decompiled_code:
int func5()
{
__int64 v0; // rax

puts("TestSlave_post_sync");
SlaveMap1 = 1;
SlaveMap2 = 1;
SlaveMap3 = 0;
SlaveMap4 = 0;
SlaveMap5 = 1;
SlaveMap6 = 0;
SlaveMap7 = 1;
SlaveMap8 = 0;
SlaveMap9 = 16;
SlaveMap10 = 4278255360LL;
SlaveMap11 = -21555;
v0 = SlaveMap12 + (unsigned int)((__int16)SlaveMap12 <= 128);
SlaveMap12 += (__int16)SlaveMap12 <= 128;
LODWORD(v0) = (__int16)v0;
return printf(
"Slave: %d %d %d %d %d %d %d %d %d %x %x %d %d \n",
1LL,
1LL,
0LL,
0LL,
1LL,
0LL,
1LL,
0LL,
16LL,
4278255360LL,
43981LL,
v0,
(unsigned int)SlaveMap13);
}

original_code:
void TestSlave_post_sync(CO_Data* d)
{
      printf ("TestSlave_post_sync\n");
      SlaveMap1=1;
      SlaveMap2=1;
      SlaveMap3=0;
      SlaveMap4=0;
      SlaveMap5=1;
      SlaveMap6=0;
      SlaveMap7=1;
      SlaveMap8=0;
      SlaveMap9=16;
      SlaveMap10 = 0xff00ff00;
      SlaveMap11 = 0xabcd;
      SlaveMap12 += SlaveMap12 > 0x80 ? 0 : 1;
      printf ("Slave: %d %d %d %d %d %d %d %d %d %x %x %d %d \n", SlaveMap1, SlaveMap2, SlaveMap3, SlaveMap4, SlaveMap5, SlaveMap6, SlaveMap7, SlaveMap8, SlaveMap9, SlaveMap10, SlaveMap11, SlaveMap12, SlaveMap13);
}

canonical_original_code:
void TestSlave_post_sync(struct struct_CO_Data *d)
{
      printf ("TestSlave_post_sync\n");
      SlaveMap1=1;
      SlaveMap2=1;
      SlaveMap3=0;
      SlaveMap4=0;
      SlaveMap5=1;
      SlaveMap6=0;
      SlaveMap7=1;
      SlaveMap8=0;
      SlaveMap9=16;
      SlaveMap10 = 0xff00ff00;
      SlaveMap11 = 0xabcd;
      SlaveMap12 += SlaveMap12 > 0x80 ? 0 : 1;
      printf ("Slave: %d %d %d %d %d %d %d %d %d %x %x %d %d \n", SlaveMap1, SlaveMap2, SlaveMap3, SlaveMap4, SlaveMap5, SlaveMap6, SlaveMap7, SlaveMap8, SlaveMap9, SlaveMap10, SlaveMap11, SlaveMap12, SlaveMap13);
}


decompiled_code:
unsigned __int16 TestSlave_post_TPDO()
{
unsigned __int16 result; // ax

++SlaveMap13;
puts("TestSlave_post_TPDO");
result = __ROR2__(-21845 * SlaveMap13 + 10920, 2);
if ( result <= 0x1554u )
{
EMCY_setError(&TestSlave_Data, 16896LL, 8LL, 0LL);
result = EMCY_errorRecovered(&TestSlave_Data, 16896LL);
}
return result;
}

canonical_decompiled_code:
unsigned __int16 func6()
{
unsigned __int16 result; // ax

++SlaveMap13;
puts("TestSlave_post_TPDO");
result = __ROR2__(-21845 * SlaveMap13 + 10920, 2);
if ( result <= 0x1554u )
{
EMCY_setError(&TestSlave_Data, 16896LL, 8LL, 0LL);
result = EMCY_errorRecovered(&TestSlave_Data, 16896LL);
}
return result;
}

original_code:
void TestSlave_post_TPDO(CO_Data* d)
{
        SlaveMap13 += 1;
 printf ("TestSlave_post_TPDO\n");
 if(SlaveMap13 % 12 == 0)
 {
  EMCY_setError(&TestSlave_Data, 0x4200, 0x08, 0x0000);
  EMCY_errorRecovered(&TestSlave_Data, 0x4200);
 }
}

canonical_original_code:
void TestSlave_post_TPDO(struct struct_CO_Data *d)
{
        SlaveMap13 += 1;
 printf ("TestSlave_post_TPDO\n");
 if(SlaveMap13 % 12 == 0)
 {
  EMCY_setError(&TestSlave_Data, 0x4200, 0x08, 0x0000);
  EMCY_errorRecovered(&TestSlave_Data, 0x4200);
 }
}


decompiled_code:
int __fastcall TestSlave_storeODSubIndex(__int64 a1, unsigned __int16 a2, unsigned __int8 a3)
{
return printf("TestSlave_storeODSubIndex : %4.4x %2.2x\n", a2, a3);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, unsigned __int16 a2, unsigned __int8 a3)
{
return printf("TestSlave_storeODSubIndex : %4.4x %2.2x\n", a2, a3);
}

original_code:
void TestSlave_storeODSubIndex(CO_Data* d, unsigned short wIndex, unsigned char bSubindex)
{
 printf ("TestSlave_storeODSubIndex : %4.4x %2.2x\n", wIndex, bSubindex);
}

canonical_original_code:
void TestSlave_storeODSubIndex(struct struct_CO_Data *d, unsigned short wIndex, unsigned char bSubindex)
{
 printf ("TestSlave_storeODSubIndex : %4.4x %2.2x\n", wIndex, bSubindex);
}

variable_types:
wIndex
unsigned short

variable_types:
bSubindex
unsigned char


decompiled_code:
int __fastcall TestSlave_post_emcy(__int64 a1, unsigned __int8 a2, unsigned __int16 a3, unsigned __int8 a4)
{
return printf("Slave received EMCY message. Node: %2.2x ErrorCode: %4.4x ErrorRegister: %2.2x\n", a2, a3, a4);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, unsigned __int8 a2, unsigned __int16 a3, unsigned __int8 a4)
{
return printf("Slave received EMCY message. Node: %2.2x ErrorCode: %4.4x ErrorRegister: %2.2x\n", a2, a3, a4);
}

original_code:
void TestSlave_post_emcy(CO_Data* d, unsigned char nodeID, unsigned short errCode, unsigned char errReg)
{
 printf ("Slave received EMCY message. Node: %2.2x  ErrorCode: %4.4x  ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
}

canonical_original_code:
void TestSlave_post_emcy(struct struct_CO_Data *d, unsigned char nodeID, unsigned short errCode, unsigned char errReg)
{
 printf ("Slave received EMCY message. Node: %2.2x  ErrorCode: %4.4x  ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
}

variable_types:
nodeID
unsigned char

variable_types:
errCode
unsigned short

variable_types:
errReg
unsigned char


masterSendNMTstateChange

decompiled_code:
__int64 __fastcall masterSendNMTstateChange(__int64 a1, char a2, char a3)
{
__int64 v3; // rdi
int v5; // [rsp+4h] [rbp-14h] BYREF
char v6; // [rsp+8h] [rbp-10h]
char v7; // [rsp+9h] [rbp-Fh]

v3 = *(_QWORD *)(a1 + 1408);
v7 = a2;
v5 = 0x2000000;
v6 = a3;
return canSend(v3, &v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, char a3)
{
__int64 v3; // rdi
int v5; // [rsp+4h] [rbp-14h] BYREF
char v6; // [rsp+8h] [rbp-10h]
char v7; // [rsp+9h] [rbp-Fh]

v3 = *(_QWORD *)(a1 + 1408);
v7 = a2;
v5 = 0x2000000;
v6 = a3;
return canSend(v3, &v5);
}

original_code:
unsigned char masterSendNMTstateChange(CO_Data* d, unsigned char Node_ID, unsigned char cs)
{
  Message m;
  ;
  ;
  m.cob_id = 0x0000;
  m.rtr = 0;
  m.len = 2;
  m.data[0] = cs;
  m.data[1] = Node_ID;
  return canSend(d->canHandle,&m);
}

canonical_original_code:
unsigned char masterSendNMTstateChange(struct struct_CO_Data *d, unsigned char Node_ID, unsigned char cs)
{
  struct Message m;
  ;
  ;
  m.cob_id = 0x0000;
  m.rtr = 0;
  m.len = 2;
  m.data[0] = cs;
  m.data[1] = Node_ID;
  return canSend(d->canHandle,&m);
}

variable_types:
cs
unsigned char

variable_types: struct Message { unsigned short cob_id; unsigned char rtr; unsigned char len; unsigned char data[8]; }

return_type: unsigned char


masterSendNMTnodeguard

decompiled_code:
__int64 __fastcall masterSendNMTnodeguard(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // rdi
__int16 v4[10]; // [rsp+4h] [rbp-14h] BYREF

v2 = *(_QWORD *)(a1 + 1408);
v4[1] = 1;
v4[0] = a2 | 0x700;
return canSend(v2, v4);
}

original_code:
unsigned char masterSendNMTnodeguard(CO_Data* d, unsigned char nodeId)
{
  Message m;
  unsigned short tmp = nodeId | (0xE << 7);
  m.cob_id = (tmp);
  m.rtr = 1;
  m.len = 0;
  ;
  return canSend(d->canHandle,&m);
}

canonical_original_code:
unsigned char masterSendNMTnodeguard(struct struct_CO_Data *d, unsigned char nodeId)
{
  struct Message m;
  unsigned short tmp = nodeId | (0xE << 7);
  m.cob_id = (tmp);
  m.rtr = 1;
  m.len = 0;
  ;
  return canSend(d->canHandle,&m);
}

variable_types:
nodeId
unsigned char

variable_types:
tmp
unsigned short


masterRequestNodeState

decompiled_code:
__int64 __fastcall masterRequestNodeState(__int64 a1, unsigned __int8 a2)
{
_DWORD *v2; // rax

*(_DWORD *)(a1 + 4LL * a2 + 672) = 15;
if ( !a2 )
{
v2 = (_DWORD *)(a1 + 672);
do
*v2++ = 15;
while ( v2 != (_DWORD *)(a1 + 1184) );
}
return masterSendNMTnodeguard(a1, a2);
}

original_code:
unsigned char masterRequestNodeState(CO_Data* d, unsigned char nodeId)
{
  d->NMTable[nodeId] = Unknown_state;
  if (nodeId == 0) {
    unsigned char i = 0;
    for (i = 0 ; i < 128 ; i++) {
      d->NMTable[i] = Unknown_state;
    }
  }
  return masterSendNMTnodeguard(d,nodeId);
}

canonical_original_code:
unsigned char masterRequestNodeState(struct struct_CO_Data *d, unsigned char nodeId)
{
  d->NMTable[nodeId] = Unknown_state;
  if (nodeId == 0) {
    unsigned char i = 0;
    for (i = 0 ; i < 128 ; i++) {
      d->NMTable[i] = Unknown_state;
    }
  }
  return masterSendNMTnodeguard(d,nodeId);
}

variable_types:
i
unsigned char


CheckSDO

decompiled_code:
__int64 __fastcall CheckSDO(__int64 a1, unsigned __int8 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned __int8)getWriteResultNetworkDict(a1, a2, &v3) != 1 )
printf("Master : Failed in changing Slave's transmit type AbortCode :%4.4x \n", v3);
return closeSDOtransfer(&TestMaster_Data, a2, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned __int8)getWriteResultNetworkDict(a1, a2, &v3) != 1 )
printf("Master : Failed in changing Slave's transmit type AbortCode :%4.4x \n", v3);
return closeSDOtransfer(&TestMaster_Data, a2, 2LL);
}

original_code:
static void CheckSDO(CO_Data* d, unsigned char nodeId)
{
 unsigned long int abortCode;
 if(getWriteResultNetworkDict (d, nodeId, &abortCode) != 0x1)
  printf ("Master : Failed in changing Slave's transmit type AbortCode :%4.4x \n", abortCode);
 closeSDOtransfer(&TestMaster_Data, nodeId, 0x2);
}

canonical_original_code:
static void CheckSDO(struct struct_CO_Data *d, unsigned char nodeId)
{
 unsigned long abortCode;
 if(getWriteResultNetworkDict (d, nodeId, &abortCode) != 0x1)
  printf ("Master : Failed in changing Slave's transmit type AbortCode :%4.4x \n", abortCode);
 closeSDOtransfer(&TestMaster_Data, nodeId, 0x2);
}

variable_types:
abortCode
unsigned long


decompiled_code:
int __fastcall TestMaster_heartbeatError(__int64 a1, unsigned __int8 a2)
{
return printf("TestMaster_heartbeatError %d\n", a2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, unsigned __int8 a2)
{
return printf("TestMaster_heartbeatError %d\n", a2);
}

original_code:
void TestMaster_heartbeatError(CO_Data* d, unsigned char heartbeatID)
{
 printf ("TestMaster_heartbeatError %d\n", heartbeatID);
}

canonical_original_code:
void TestMaster_heartbeatError(struct struct_CO_Data *d, unsigned char heartbeatID)
{
 printf ("TestMaster_heartbeatError %d\n", heartbeatID);
}


decompiled_code:
int TestMaster_operational()
{
return puts("TestMaster_operational");
}

canonical_decompiled_code:
int func6()
{
return puts("TestMaster_operational");
}

original_code:
void TestMaster_operational(CO_Data* d)
{
 printf ("TestMaster_operational\n");
}

canonical_original_code:
void TestMaster_operational(struct struct_CO_Data *d)
{
 printf ("TestMaster_operational\n");
}


decompiled_code:
int TestMaster_stopped()
{
return puts("TestMaster_stopped");
}

canonical_decompiled_code:
int func7()
{
return puts("TestMaster_stopped");
}

original_code:
void TestMaster_stopped(CO_Data* d)
{
 printf ("TestMaster_stopped\n");
}

canonical_original_code:
void TestMaster_stopped(struct struct_CO_Data *d)
{
 printf ("TestMaster_stopped\n");
}


decompiled_code:
int __fastcall TestMaster_post_emcy(__int64 a1, unsigned __int8 a2, unsigned __int16 a3, unsigned __int8 a4)
{
return printf("Master received EMCY message. Node: %2.2x ErrorCode: %4.4x ErrorRegister: %2.2x\n", a2, a3, a4);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, unsigned __int8 a2, unsigned __int16 a3, unsigned __int8 a4)
{
return printf("Master received EMCY message. Node: %2.2x ErrorCode: %4.4x ErrorRegister: %2.2x\n", a2, a3, a4);
}

original_code:
void TestMaster_post_emcy(CO_Data* d, unsigned char nodeID, unsigned short errCode, unsigned char errReg)
{
 printf ("Master received EMCY message. Node: %2.2x  ErrorCode: %4.4x  ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
}

canonical_original_code:
void TestMaster_post_emcy(struct struct_CO_Data *d, unsigned char nodeID, unsigned short errCode, unsigned char errReg)
{
 printf ("Master received EMCY message. Node: %2.2x  ErrorCode: %4.4x  ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
}


OnNumberOfErrorsUpdate

decompiled_code:
__int64 __fastcall OnNumberOfErrorsUpdate(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rcx
__int64 v3; // rax

if ( !**(_BYTE **)(a1 + 1488) )
{
v1 = *(unsigned __int8 *)(a1 + 1484);
if ( (_BYTE)v1 )
{
v2 = *(_QWORD **)(a1 + 1496);
v3 = v1;
*v2 = 0LL;
v2[v3 - 1] = 0LL;
memset(
(void *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)(v3 * 8) + (_DWORD)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8)) >> 3));
}
}
return 0LL;
}

original_code:
unsigned long int OnNumberOfErrorsUpdate(CO_Data* d, const indextable * unsused_indextable, unsigned char unsused_bSubindex)
{
 unsigned char index;
 if (*d->error_number == 0)
  for (index = 0; index < d->error_history_size; ++index)
   *(d->error_first_element + index) = 0;
 else
  ;
  return 0;
}

canonical_original_code:
unsigned long OnNumberOfErrorsUpdate(struct struct_CO_Data *d, struct td_indextable *unsused_indextable, unsigned char unsused_bSubindex)
{
 unsigned char index;
 if (*d->error_number == 0)
  for (index = 0; index < d->error_history_size; ++index)
   *(d->error_first_element + index) = 0;
 else
  ;
  return 0;
}

variable_types:
index
unsigned char

return_type: unsigned long


emergencyStop

decompiled_code:
void emergencyStop()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void emergencyStop(CO_Data* d)
{
}

canonical_original_code:
void emergencyStop(struct struct_CO_Data *d)
{
}


sendEMCY

original_code:
unsigned char sendEMCY(CO_Data* d, unsigned short errCode, unsigned char errRegister, const void *Specific, unsigned char SpecificLength)
{
 Message m;
 ;
 m.cob_id = (unsigned short)(*(unsigned long int*)d->error_cobid);
 m.rtr = 0;
 m.data[0] = errCode & 0xFF;
 m.data[1] = (errCode >> 8) & 0xFF;
 m.data[2] = errRegister;
 if(Specific==((void *)0))
 {
   m.data[3] = 0;
   m.data[4] = 0;
   m.data[5] = 0;
   m.data[6] = 0;
   m.data[7] = 0;
   SpecificLength = 5;
 }
 else
 {
          if(SpecificLength>5) SpecificLength = 5;
   memcpy(&m.data[3],Specific,SpecificLength);
 }
 m.len = SpecificLength + 3;
 return canSend(d->canHandle,&m);
}

canonical_original_code:
unsigned char sendEMCY(struct struct_CO_Data *d, unsigned short errCode, unsigned char errRegister, void *Specific, unsigned char SpecificLength)
{
 struct Message m;
 ;
 m.cob_id = (unsigned short)(*(unsigned long *)d->error_cobid);
 m.rtr = 0;
 m.data[0] = errCode & 0xFF;
 m.data[1] = (errCode >> 8) & 0xFF;
 m.data[2] = errRegister;
 if(Specific==((void *)0))
 {
   m.data[3] = 0;
   m.data[4] = 0;
   m.data[5] = 0;
   m.data[6] = 0;
   m.data[7] = 0;
   SpecificLength = 5;
 }
 else
 {
          if(SpecificLength>5) SpecificLength = 5;
   memcpy(&m.data[3],Specific,SpecificLength);
 }
 m.len = SpecificLength + 3;
 return canSend(d->canHandle,&m);
}

variable_types:
errRegister
unsigned char

variable_types:
Specific
void *

variable_types:
SpecificLength
unsigned char


original_code:
unsigned char EMCY_setError(CO_Data* d, unsigned short errCode, unsigned char errRegMask, unsigned short addInfo)
{
 unsigned char index;
 unsigned char errRegister_tmp;
 for (index = 0; index < 8; ++index)
 {
  if (d->error_data[index].errCode == errCode)
  {
   if (d->error_data[index].active)
   {
    ;
    return 0;
   } else d->error_data[index].active = 1;
   break;
  }
 }
 if (index == 8)
  for (index = 0; index < 8; ++index) if (d->error_data[index].active == 0) break;
 if (index == 8)
 {
  ;
  return 1;
 }
 d->error_data[index].errCode = errCode;
 d->error_data[index].errRegMask = errRegMask;
 d->error_data[index].active = 1;
 d->error_state = Error_occurred;
 for (index = 0, errRegister_tmp = 0; index < 8; ++index)
  if (d->error_data[index].active == 1) errRegister_tmp |= d->error_data[index].errRegMask;
 *d->error_register = errRegister_tmp;
 for (index = d->error_history_size - 1; index > 0; --index)
  *(d->error_first_element + index) = *(d->error_first_element + index - 1);
 *(d->error_first_element) = errCode | ((unsigned long int)addInfo << 16);
 if(*d->error_number < d->error_history_size) ++(*d->error_number);
 if (d->CurrentCommunicationState.csEmergency)
  return sendEMCY(d, errCode, *d->error_register, ((void *)0), 0);
 else return 1;
}

canonical_original_code:
unsigned char EMCY_setError(struct struct_CO_Data *d, unsigned short errCode, unsigned char errRegMask, unsigned short addInfo)
{
 unsigned char index;
 unsigned char errRegister_tmp;
 for (index = 0; index < 8; ++index)
 {
  if (d->error_data[index].errCode == errCode)
  {
   if (d->error_data[index].active)
   {
    ;
    return 0;
   } else d->error_data[index].active = 1;
   break;
  }
 }
 if (index == 8)
  for (index = 0; index < 8; ++index) if (d->error_data[index].active == 0) break;
 if (index == 8)
 {
  ;
  return 1;
 }
 d->error_data[index].errCode = errCode;
 d->error_data[index].errRegMask = errRegMask;
 d->error_data[index].active = 1;
 d->error_state = Error_occurred;
 for (index = 0, errRegister_tmp = 0; index < 8; ++index)
  if (d->error_data[index].active == 1) errRegister_tmp |= d->error_data[index].errRegMask;
 *d->error_register = errRegister_tmp;
 for (index = d->error_history_size - 1; index > 0; --index)
  *(d->error_first_element + index) = *(d->error_first_element + index - 1);
 *(d->error_first_element) = errCode | ((unsigned long)addInfo << 16);
 if(*d->error_number < d->error_history_size) ++(*d->error_number);
 if (d->CurrentCommunicationState.csEmergency)
  return sendEMCY(d, errCode, *d->error_register, ((void *)0), 0);
 else return 1;
}

variable_types: struct struct_CO_Data { unsigned char *bDeviceNodeId; struct td_indextable { struct td_subindex { unsigned char bAccessType; unsigned char bDataType; unsigned long size; void *pObject; } *pSubindex; unsigned char bSubCount; unsigned short index; } *objdict; struct struct_s_PDO_status { unsigned char transmit_type_parameter; short event_timer; short inhibit_timer; struct Message { unsigned short cob_id; unsigned char rtr; unsigned char len; unsigned char data[8]; } last_message; } *PDO_status; short *RxPDO_EventTimers; void (*RxPDO_EventTimers_Handler)(struct struct_CO_Data *, unsigned long); struct s_quick_index { unsigned short SDO_SVR; unsigned short SDO_CLT; unsigned short PDO_RCV; unsigned short PDO_RCV_MAP; unsigned short PDO_TRS; unsigned short PDO_TRS_MAP; } *firstIndex; struct s_quick_index *lastIndex; unsigned short *ObjdictSize; unsigned char *iam_a_slave; unsigned long (*valueRangeTest)(unsigned char typeValue, void *Value); struct struct_s_transfer { unsigned char CliServNbr; unsigned char whoami; unsigned char state; unsigned char toggle; unsigned long abortCode; unsigned short index; unsigned char subIndex; unsigned long count; unsigned long offset; unsigned char data[32]; unsigned char peerCRCsupport; unsigned char blksize; unsigned char ackseq; unsigned long objsize; unsigned char lastblockoffset; unsigned char seqno; unsigned char endfield; enum rxStep_t { RXSTEP_INIT=0, RXSTEP_STARTED=1, RXSTEP_END=2 } rxstep; unsigned char tmpData[8]; unsigned char dataType; short timer; void (*Callback)(struct struct_CO_Data *d, unsigned char nodeId); } transfers[4]; enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 } nodeState; struct s_state_communication { char csBoot_Up; char csSDO; char csEmergency; char csSYNC; char csLifeGuard; char csPDO; char csLSS; } CurrentCommunicationState; void (*initialisation)(struct struct_CO_Data *); void (*preOperational)(struct struct_CO_Data *); void (*operational)(struct struct_CO_Data *); void (*stopped)(struct struct_CO_Data *); void (*NMT_Slave_Node_Reset_Callback)(struct struct_CO_Data *); void (*NMT_Slave_Communications_Reset_Callback)(struct struct_CO_Data *); unsigned char *ConsumerHeartbeatCount; unsigned long *ConsumerHeartbeatEntries; short *ConsumerHeartBeatTimers; unsigned short *ProducerHeartBeatTime; short ProducerHeartBeatTimer; void (*heartbeatError)(struct struct_CO_Data *, unsigned char); enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 } NMTable[128]; short GuardTimeTimer; short LifeTimeTimer; void (*nodeguardError)(struct struct_CO_Data *, unsigned char); unsigned short *GuardTime; unsigned char *LifeTimeFactor; unsigned char nodeGuardStatus[128]; short syncTimer; unsigned long *COB_ID_Sync; unsigned long *Sync_Cycle_Period; void (*post_sync)(struct struct_CO_Data *); void (*post_TPDO)(struct struct_CO_Data *); void (*post_SlaveBootup)(struct struct_CO_Data *, unsigned char); void (*post_SlaveStateChange)(struct struct_CO_Data *, unsigned char, enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 }); unsigned char toggle; void *canHandle; struct td_indextable *(*scanIndexOD)(unsigned short wIndex, unsigned long *errorCode, unsigned long (***Callback)(struct struct_CO_Data *d, struct td_indextable *, unsigned char bSubindex)); void (*storeODSubIndex)(struct struct_CO_Data *d, unsigned short wIndex, unsigned char bSubindex); struct td_indextable *dcf_odentry; unsigned char *dcf_cursor; unsigned long dcf_entries_count; unsigned char dcf_status; unsigned long dcf_size; unsigned char *dcf_data; enum enum_errorState { Error_free=0, Error_occurred=1 } error_state; unsigned char error_history_size; unsigned char *error_number; unsigned long *error_first_element; unsigned char *error_register; unsigned long *error_cobid; struct s_errors { unsigned short errCode; unsigned char errRegMask; unsigned char active; } error_data[8]; void (*post_emcy)(struct struct_CO_Data *d, unsigned char nodeID, unsigned short errCode, unsigned char errReg); } *

variable_types:
errRegMask
unsigned char

variable_types:
addInfo
unsigned short


original_code:
void EMCY_errorRecovered(CO_Data* d, unsigned short errCode)
{
 unsigned char index;
 unsigned char errRegister_tmp;
 unsigned char anyActiveError = 0;
 for (index = 0; index < 8; ++index)
  if (d->error_data[index].errCode == errCode) break;
 if ((index != 8) && (d->error_data[index].active == 1))
 {
  d->error_data[index].active = 0;
  for (index = 0, errRegister_tmp = 0; index < 8; ++index)
   if (d->error_data[index].active == 1)
   {
    anyActiveError = 1;
    errRegister_tmp |= d->error_data[index].errRegMask;
   }
  if(anyActiveError == 0)
  {
   d->error_state = Error_free;
   if (d->CurrentCommunicationState.csEmergency)
    sendEMCY(d, 0x0000, 0x00, ((void *)0), 0);
  }
  *d->error_register = errRegister_tmp;
 }
 else
  ;
}

canonical_original_code:
void EMCY_errorRecovered(struct struct_CO_Data *d, unsigned short errCode)
{
 unsigned char index;
 unsigned char errRegister_tmp;
 unsigned char anyActiveError = 0;
 for (index = 0; index < 8; ++index)
  if (d->error_data[index].errCode == errCode) break;
 if ((index != 8) && (d->error_data[index].active == 1))
 {
  d->error_data[index].active = 0;
  for (index = 0, errRegister_tmp = 0; index < 8; ++index)
   if (d->error_data[index].active == 1)
   {
    anyActiveError = 1;
    errRegister_tmp |= d->error_data[index].errRegMask;
   }
  if(anyActiveError == 0)
  {
   d->error_state = Error_free;
   if (d->CurrentCommunicationState.csEmergency)
    sendEMCY(d, 0x0000, 0x00, ((void *)0), 0);
  }
  *d->error_register = errRegister_tmp;
 }
 else
  ;
}

variable_types:
anyActiveError
unsigned char


proceedEMCY

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

if ( *(_BYTE *)(a2 + 3) == 8 )
result = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD, _QWORD))(a1 + 1552))(
a1,
*(_WORD *)a2 & 0x7F,
*(unsigned __int16 *)(a2 + 4),
*(unsigned __int8 *)(a2 + 6));
return result;
}

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

if ( *(_BYTE *)(a2 + 3) == 8 )
result = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD, _QWORD))(a1 + 1552))(
a1,
*(_WORD *)a2 & 0x7F,
*(unsigned __int16 *)(a2 + 4),
*(unsigned __int8 *)(a2 + 6));
return result;
}

original_code:
void proceedEMCY(CO_Data* d, Message* m)
{
 unsigned char nodeID;
 unsigned short errCode;
 unsigned char errReg;
 ;
 if ( m->len != 8) {
  ;
  return;
 }
 nodeID = m->cob_id & 0x7F;
 errCode = m->data[0] | ((unsigned short)m->data[1] << 8);
 errReg = m->data[2];
 (*d->post_emcy)(d, nodeID, errCode, errReg);
}

canonical_original_code:
void proceedEMCY(struct struct_CO_Data *d, struct Message *m)
{
 unsigned char nodeID;
 unsigned short errCode;
 unsigned char errReg;
 ;
 if ( m->len != 8) {
  ;
  return;
 }
 nodeID = m->cob_id & 0x7F;
 errCode = m->data[0] | ((unsigned short)m->data[1] << 8);
 errReg = m->data[2];
 (*d->post_emcy)(d, nodeID, errCode, errReg);
}

variable_types:
m
struct Message *

variable_types:
nodeID
unsigned char


proceedNMTstateChange

decompiled_code:
__int64 __fastcall proceedNMTstateChange(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3; // r8
unsigned __int8 v4; // si
__int64 v5; // rsi
unsigned __int8 v6; // bl
void (__fastcall *v7)(__int64); // rax
void (__fastcall *v8)(__int64); // rax

result = *(unsigned int *)(a1 + 560);
if ( (_DWORD)result == 127 || (_DWORD)result == 5 || (_DWORD)result == 4 )
{
v3 = *(_BYTE *)(a2 + 5);
if ( !v3 || **(_BYTE **)a1 == v3 )
{
v4 = *(_BYTE *)(a2 + 4);
if ( v4 == 0x80 )
{
result = (unsigned int)(result - 4);
v5 = 127LL;
if ( (unsigned int)result > 1 )
return result;
}
else if ( v4 > 0x80u )
{
if ( v4 == 0x81 )
{
v8 = *(void (__fastcall **)(__int64))(a1 + 608);
if ( v8 )
{
v8(a1);
v5 = 0LL;
return setState(a1, v5);
}
}
else
{
if ( v4 != 0x82 )
return result;
v6 = getNodeId(a1);
v7 = *(void (__fastcall **)(__int64))(a1 + 616);
if ( v7 )
v7(a1);
**(_BYTE **)a1 = -1;
setNodeId(a1, v6);
}
v5 = 0LL;
}
else if ( v4 == 1 )
{
if ( (_DWORD)result != 127 && (_DWORD)result != 4 )
return result;
v5 = 5LL;
}
else
{
if ( v4 != 2 )
return result;
v5 = 4LL;
if ( (_DWORD)result != 127 && (_DWORD)result != 5 )
return result;
}
return setState(a1, v5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3; // r8
unsigned __int8 v4; // si
__int64 v5; // rsi
unsigned __int8 v6; // bl
void (__fastcall *v7)(__int64); // rax
void (__fastcall *v8)(__int64); // rax

result = *(unsigned int *)(a1 + 560);
if ( (_DWORD)result == 127 || (_DWORD)result == 5 || (_DWORD)result == 4 )
{
v3 = *(_BYTE *)(a2 + 5);
if ( !v3 || **(_BYTE **)a1 == v3 )
{
v4 = *(_BYTE *)(a2 + 4);
if ( v4 == 0x80 )
{
result = (unsigned int)(result - 4);
v5 = 127LL;
if ( (unsigned int)result > 1 )
return result;
}
else if ( v4 > 0x80u )
{
if ( v4 == 0x81 )
{
v8 = *(void (__fastcall **)(__int64))(a1 + 608);
if ( v8 )
{
v8(a1);
v5 = 0LL;
return setState(a1, v5);
}
}
else
{
if ( v4 != 0x82 )
return result;
v6 = getNodeId(a1);
v7 = *(void (__fastcall **)(__int64))(a1 + 616);
if ( v7 )
v7(a1);
**(_BYTE **)a1 = -1;
setNodeId(a1, v6);
}
v5 = 0LL;
}
else if ( v4 == 1 )
{
if ( (_DWORD)result != 127 && (_DWORD)result != 4 )
return result;
v5 = 5LL;
}
else
{
if ( v4 != 2 )
return result;
v5 = 4LL;
if ( (_DWORD)result != 127 && (_DWORD)result != 5 )
return result;
}
return setState(a1, v5);
}
}
return result;
}

original_code:
void proceedNMTstateChange(CO_Data* d, Message *m)
{
    unsigned char d0, d1;
    d0 = m->data[0];
    d1 = m->data[1];
  if( d->nodeState == Pre_operational ||
      d->nodeState == Operational ||
      d->nodeState == Stopped ) {
    ;
    if( ( d1 == 0 ) || ( d1 == *d->bDeviceNodeId ) ){
      switch( d0){
      case 0x01:
        if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) )
          setState(d,Operational);
        break;
      case 0x02:
        if ( d->nodeState == Pre_operational ||
             d->nodeState == Operational )
          setState(d,Stopped);
        break;
      case 0x80:
        if ( d->nodeState == Operational ||
             d->nodeState == Stopped )
          setState(d,Pre_operational);
        break;
      case 0x81:
         if(d->NMT_Slave_Node_Reset_Callback != ((void *)0))
            d->NMT_Slave_Node_Reset_Callback(d);
        setState(d,Initialisation);
        break;
      case 0x82:
         {
         unsigned char currentNodeId = getNodeId(d);
            if(d->NMT_Slave_Communications_Reset_Callback != ((void *)0))
               d->NMT_Slave_Communications_Reset_Callback(d);
            *d->bDeviceNodeId = 0xFF;
            setNodeId(d, currentNodeId);
         }
         setState(d,Initialisation);
         break;
      }
    }
  }
}

canonical_original_code:
void proceedNMTstateChange(struct struct_CO_Data *d, struct Message *m)
{
    unsigned char d0; unsigned char d1;
    d0 = m->data[0];
    d1 = m->data[1];
  if( d->nodeState == Pre_operational ||
      d->nodeState == Operational ||
      d->nodeState == Stopped ) {
    ;
    if( ( d1 == 0 ) || ( d1 == *d->bDeviceNodeId ) ){
      switch( d0){
      case 0x01:
        if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) )
          setState(d,Operational);
        break;
      case 0x02:
        if ( d->nodeState == Pre_operational ||
             d->nodeState == Operational )
          setState(d,Stopped);
        break;
      case 0x80:
        if ( d->nodeState == Operational ||
             d->nodeState == Stopped )
          setState(d,Pre_operational);
        break;
      case 0x81:
         if(d->NMT_Slave_Node_Reset_Callback != ((void *)0))
            d->NMT_Slave_Node_Reset_Callback(d);
        setState(d,Initialisation);
        break;
      case 0x82:
         {
         unsigned char currentNodeId = getNodeId(d);
            if(d->NMT_Slave_Communications_Reset_Callback != ((void *)0))
               d->NMT_Slave_Communications_Reset_Callback(d);
            *d->bDeviceNodeId = 0xFF;
            setNodeId(d, currentNodeId);
         }
         setState(d,Initialisation);
         break;
      }
    }
  }
}

variable_types:
currentNodeId
unsigned char


slaveSendBootUp

decompiled_code:
__int64 __fastcall slaveSendBootUp(unsigned __int8 **a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rdi
__int16 v4[2]; // [rsp+4h] [rbp-14h] BYREF
char v5; // [rsp+8h] [rbp-10h]

v1 = *a1;
v2 = a1[176];
LOWORD(v1) = *v1;
v5 = 0;
BYTE1(v1) |= 7u;
v4[0] = (__int16)v1;
v4[1] = 256;
return canSend(v2, v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 **a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rdi
__int16 v4[2]; // [rsp+4h] [rbp-14h] BYREF
char v5; // [rsp+8h] [rbp-10h]

v1 = *a1;
v2 = a1[176];
LOWORD(v1) = *v1;
v5 = 0;
BYTE1(v1) |= 7u;
v4[0] = (__int16)v1;
v4[1] = 256;
return canSend(v2, v4);
}

original_code:
unsigned char slaveSendBootUp(CO_Data* d)
{
  Message m;
  ;
  {
   unsigned short tmp = 0xE << 7 | *d->bDeviceNodeId;
   m.cob_id = (tmp);
  }
  m.rtr = 0;
  m.len = 1;
  m.data[0] = 0x00;
  return canSend(d->canHandle,&m);
}

canonical_original_code:
unsigned char slaveSendBootUp(struct struct_CO_Data *d)
{
  struct Message m;
  ;
  {
   unsigned short tmp = 0xE << 7 | *d->bDeviceNodeId;
   m.cob_id = (tmp);
  }
  m.rtr = 0;
  m.len = 1;
  m.data[0] = 0x00;
  return canSend(d->canHandle,&m);
}


stopSYNC

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

RegisterSetODentryCallBack(a1, 4101LL, 0LL, 0LL);
RegisterSetODentryCallBack(a1, 4102LL, 0LL, 0LL);
result = DelAlarm((unsigned int)*(__int16 *)(a1 + 1344));
*(_WORD *)(a1 + 1344) = result;
return result;
}

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

RegisterSetODentryCallBack(a1, 4101LL, 0LL, 0LL);
RegisterSetODentryCallBack(a1, 4102LL, 0LL, 0LL);
result = DelAlarm((unsigned int)*(__int16 *)(a1 + 1344));
*(_WORD *)(a1 + 1344) = result;
return result;
}

original_code:
void stopSYNC(CO_Data* d)
{
    RegisterSetODentryCallBack(d, 0x1005, 0, ((void *)0));
    RegisterSetODentryCallBack(d, 0x1006, 0, ((void *)0));
 d->syncTimer = DelAlarm(d->syncTimer);
}

canonical_original_code:
void stopSYNC(struct struct_CO_Data *d)
{
    RegisterSetODentryCallBack(d, 0x1005, 0, ((void *)0));
    RegisterSetODentryCallBack(d, 0x1006, 0, ((void *)0));
 d->syncTimer = DelAlarm(d->syncTimer);
}


startSYNC

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

if ( *(_WORD *)(a1 + 1344) != 0xFFFF )
stopSYNC(a1);
RegisterSetODentryCallBack(a1, 4101LL, 0LL, OnCOB_ID_SyncUpdate);
RegisterSetODentryCallBack(a1, 4102LL, 0LL, OnCOB_ID_SyncUpdate);
result = **(_QWORD **)(a1 + 1352);
if ( (result & 0x40000000) != 0 )
{
result = **(_QWORD **)(a1 + 1360);
if ( result )
{
result = SetAlarm(
a1,
0LL,
SyncAlarm,
(unsigned __int64)(35 * result) >> 2,
(unsigned int)((unsigned __int64)(35 * result) >> 2));
*(_WORD *)(a1 + 1344) = result;
}
}
return result;
}

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

if ( *(_WORD *)(a1 + 1344) != 0xFFFF )
func0(a1);
RegisterSetODentryCallBack(a1, 4101LL, 0LL, OnCOB_ID_SyncUpdate);
RegisterSetODentryCallBack(a1, 4102LL, 0LL, OnCOB_ID_SyncUpdate);
result = **(_QWORD **)(a1 + 1352);
if ( (result & 0x40000000) != 0 )
{
result = **(_QWORD **)(a1 + 1360);
if ( result )
{
result = SetAlarm(
a1,
0LL,
SyncAlarm,
(unsigned __int64)(35 * result) >> 2,
(unsigned int)((unsigned __int64)(35 * result) >> 2));
*(_WORD *)(a1 + 1344) = result;
}
}
return result;
}

original_code:
void startSYNC(CO_Data* d)
{
 if(d->syncTimer != -1){
  stopSYNC(d);
 }
 RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate);
 RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate);
 if(*d->COB_ID_Sync & 0x40000000ul && *d->Sync_Cycle_Period)
 {
  d->syncTimer = SetAlarm(
    d,
    0 ,
    &SyncAlarm,
    ((35L**d->Sync_Cycle_Period)>>2),
    ((35L**d->Sync_Cycle_Period)>>2));
 }
}

canonical_original_code:
void startSYNC(struct struct_CO_Data *d)
{
 if(d->syncTimer != -1){
  stopSYNC(d);
 }
 RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate);
 RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate);
 if(*d->COB_ID_Sync & 0x40000000ul && *d->Sync_Cycle_Period)
 {
  d->syncTimer = SetAlarm(
    d,
    0 ,
    &SyncAlarm,
    ((35L**d->Sync_Cycle_Period)>>2),
    ((35L**d->Sync_Cycle_Period)>>2));
 }
}


decompiled_code:
__int64 __fastcall OnCOB_ID_SyncUpdate(__int64 a1)
{
startSYNC(a1);
return 0LL;
}

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

original_code:
unsigned long int OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, unsigned char unsused_bSubindex)
{
 startSYNC(d);
 return 0;
}

canonical_original_code:
unsigned long OnCOB_ID_SyncUpdate(struct struct_CO_Data *d, struct td_indextable *unsused_indextable, unsigned char unsused_bSubindex)
{
 startSYNC(d);
 return 0;
}


sendSYNCMessage

original_code:
unsigned char sendSYNCMessage(CO_Data* d)
{
  Message m;
  ;
  m.cob_id = (unsigned short)(*d->COB_ID_Sync);
  m.rtr = 0;
  m.len = 0;
  return canSend(d->canHandle,&m);
}

canonical_original_code:
unsigned char sendSYNCMessage(struct struct_CO_Data *d)
{
  struct Message m;
  ;
  m.cob_id = (unsigned short)(*d->COB_ID_Sync);
  m.rtr = 0;
  m.len = 0;
  return canSend(d->canHandle,&m);
}


proceedSYNC

original_code:
unsigned char proceedSYNC(CO_Data* d)
{
  unsigned char res;
  ;
  (*d->post_sync)(d);
  if(! d->CurrentCommunicationState.csPDO)
    return 0;
  res = _sendPDOevent(d, 1 );
  (*d->post_TPDO)(d);
  return res;
}

canonical_original_code:
unsigned char proceedSYNC(struct struct_CO_Data *d)
{
  unsigned char res;
  ;
  (*d->post_sync)(d);
  if(! d->CurrentCommunicationState.csPDO)
    return 0;
  res = _sendPDOevent(d, 1 );
  (*d->post_TPDO)(d);
  return res;
}

variable_types:
res
unsigned char


sendSYNC

decompiled_code:
__int64 __fastcall sendSYNC(__int64 a1)
{
unsigned int v1; // er12

v1 = sendSYNCMessage(a1);
proceedSYNC(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // er12

v1 = func3(a1);
func4(a1);
return v1;
}

original_code:
unsigned char sendSYNC(CO_Data* d)
{
  unsigned char res;
  res = sendSYNCMessage(d);
  proceedSYNC(d) ;
  return res ;
}

canonical_original_code:
unsigned char sendSYNC(struct struct_CO_Data *d)
{
  unsigned char res;
  res = sendSYNCMessage(d);
  proceedSYNC(d) ;
  return res ;
}


SyncAlarm

decompiled_code:
// attributes: thunk
__int64 __fastcall SyncAlarm(__int64 a1)
{
return sendSYNC(a1);
}

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

original_code:
void SyncAlarm(CO_Data* d, unsigned long int id)
{
 sendSYNC(d) ;
}

canonical_original_code:
void SyncAlarm(struct struct_CO_Data *d, unsigned long id)
{
 sendSYNC(d) ;
}

variable_types:
id
unsigned long


SetAlarm

decompiled_code:
__int64 __fastcall SetAlarm(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, int a5)
{
int v7; // edx
_QWORD *v8; // rbx
int v9; // eax
unsigned int v10; // er12
unsigned int v12; // eax
int v13; // er8
unsigned int v14; // ecx
unsigned int v16; // [rsp+8h] [rbp-40h]
int v17; // [rsp+Ch] [rbp-3Ch]

v7 = last_timer_raw[0] + 1;
if ( v7 < 0 )
return (unsigned int)-1;
v8 = &timers;
v9 = 0;
while ( 1 )
{
v10 = v9;
if ( a3 )
{
if ( !*(_BYTE *)v8 )
break;
}
++v9;
v8 += 5;
if ( (_WORD)v9 == 32 || v9 > v7 )
return (unsigned int)-1;
}
if ( v9 == v7 )
++last_timer_raw[0];
v12 = getElapsedTime();
v13 = a5;
v14 = v12 + a4;
if ( total_sleep_time > v12 && total_sleep_time - v12 > a4 )
{
v17 = a5;
total_sleep_time = v12 + a4;
v16 = v12 + a4;
setTimer(a4);
v13 = v17;
v14 = v16;
}
v8[2] = a3;
v8[1] = a1;
v8[3] = a2;
*((_DWORD *)v8 + 8) = v14;
*((_DWORD *)v8 + 9) = v13;
*(_BYTE *)v8 = 1;
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, int a5)
{
int v7; // edx
_QWORD *v8; // rbx
int v9; // eax
unsigned int v10; // er12
unsigned int v12; // eax
int v13; // er8
unsigned int v14; // ecx
unsigned int v16; // [rsp+8h] [rbp-40h]
int v17; // [rsp+Ch] [rbp-3Ch]

v7 = last_timer_raw[0] + 1;
if ( v7 < 0 )
return (unsigned int)-1;
v8 = &timers;
v9 = 0;
while ( 1 )
{
v10 = v9;
if ( a3 )
{
if ( !*(_BYTE *)v8 )
break;
}
++v9;
v8 += 5;
if ( (_WORD)v9 == 32 || v9 > v7 )
return (unsigned int)-1;
}
if ( v9 == v7 )
++last_timer_raw[0];
v12 = getElapsedTime();
v13 = a5;
v14 = v12 + a4;
if ( total_sleep_time > v12 && total_sleep_time - v12 > a4 )
{
v17 = a5;
total_sleep_time = v12 + a4;
v16 = v12 + a4;
setTimer(a4);
v13 = v17;
v14 = v16;
}
v8[2] = a3;
v8[1] = a1;
v8[3] = a2;
*((_DWORD *)v8 + 8) = v14;
*((_DWORD *)v8 + 9) = v13;
*(_BYTE *)v8 = 1;
return v10;
}

original_code:
short SetAlarm(CO_Data* d, unsigned long int id, TimerCallback_t callback, uint32_t value, uint32_t period)
{
 short row_number;
 s_timer_entry *row;
 for(row_number=0, row=timers; row_number <= last_timer_raw + 1 && row_number < 32; row_number++, row++)
 {
  if (callback &&
     row->state == 0)
  {
   uint32_t real_timer_value;
   uint32_t elapsed_time;
   if (row_number == last_timer_raw + 1) last_timer_raw++;
   elapsed_time = getElapsedTime();
   real_timer_value = value;
   real_timer_value = ((real_timer_value<~(uint32_t)0)?real_timer_value:~(uint32_t)0);
   if (total_sleep_time > elapsed_time && total_sleep_time - elapsed_time > real_timer_value)
   {
    total_sleep_time = elapsed_time + real_timer_value;
    setTimer(real_timer_value);
   }
   row->callback = callback;
   row->d = d;
   row->id = id;
   row->val = value + elapsed_time;
   row->interval = period;
   row->state = 1;
   return row_number;
  }
 }
 return -1;
}

canonical_original_code:
short SetAlarm(struct struct_CO_Data *d, unsigned long id, void (*callback)(struct struct_CO_Data *d, unsigned long id), unsigned int value, unsigned int period)
{
 short row_number;
 struct struct_s_timer_entry *row;
 for(row_number=0, row=timers; row_number <= last_timer_raw + 1 && row_number < 32; row_number++, row++)
 {
  if (callback &&
     row->state == 0)
  {
   unsigned int real_timer_value;
   unsigned int elapsed_time;
   if (row_number == last_timer_raw + 1) last_timer_raw++;
   elapsed_time = getElapsedTime();
   real_timer_value = value;
   real_timer_value = ((real_timer_value<~(unsigned int)0)?real_timer_value:~(unsigned int)0);
   if (total_sleep_time > elapsed_time && total_sleep_time - elapsed_time > real_timer_value)
   {
    total_sleep_time = elapsed_time + real_timer_value;
    setTimer(real_timer_value);
   }
   row->callback = callback;
   row->d = d;
   row->id = id;
   row->val = value + elapsed_time;
   row->interval = period;
   row->state = 1;
   return row_number;
  }
 }
 return -1;
}

variable_types: void (*)(struct struct_CO_Data *d, unsigned long id)

variable_types:
value
unsigned int

variable_types:
period
unsigned int

variable_types: struct struct_s_timer_entry { unsigned char state; struct struct_CO_Data { unsigned char *bDeviceNodeId; struct td_indextable { struct td_subindex { unsigned char bAccessType; unsigned char bDataType; unsigned long size; void *pObject; } *pSubindex; unsigned char bSubCount; unsigned short index; } *objdict; struct struct_s_PDO_status { unsigned char transmit_type_parameter; short event_timer; short inhibit_timer; struct Message { unsigned short cob_id; unsigned char rtr; unsigned char len; unsigned char data[8]; } last_message; } *PDO_status; short *RxPDO_EventTimers; void (*RxPDO_EventTimers_Handler)(struct struct_CO_Data *, unsigned long); struct s_quick_index { unsigned short SDO_SVR; unsigned short SDO_CLT; unsigned short PDO_RCV; unsigned short PDO_RCV_MAP; unsigned short PDO_TRS; unsigned short PDO_TRS_MAP; } *firstIndex; struct s_quick_index *lastIndex; unsigned short *ObjdictSize; unsigned char *iam_a_slave; unsigned long (*valueRangeTest)(unsigned char typeValue, void *Value); struct struct_s_transfer { unsigned char CliServNbr; unsigned char whoami; unsigned char state; unsigned char toggle; unsigned long abortCode; unsigned short index; unsigned char subIndex; unsigned long count; unsigned long offset; unsigned char data[32]; unsigned char peerCRCsupport; unsigned char blksize; unsigned char ackseq; unsigned long objsize; unsigned char lastblockoffset; unsigned char seqno; unsigned char endfield; enum rxStep_t { RXSTEP_INIT=0, RXSTEP_STARTED=1, RXSTEP_END=2 } rxstep; unsigned char tmpData[8]; unsigned char dataType; short timer; void (*Callback)(struct struct_CO_Data *d, unsigned char nodeId); } transfers[4]; enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 } nodeState; struct s_state_communication { char csBoot_Up; char csSDO; char csEmergency; char csSYNC; char csLifeGuard; char csPDO; char csLSS; } CurrentCommunicationState; void (*initialisation)(struct struct_CO_Data *); void (*preOperational)(struct struct_CO_Data *); void (*operational)(struct struct_CO_Data *); void (*stopped)(struct struct_CO_Data *); void (*NMT_Slave_Node_Reset_Callback)(struct struct_CO_Data *); void (*NMT_Slave_Communications_Reset_Callback)(struct struct_CO_Data *); unsigned char *ConsumerHeartbeatCount; unsigned long *ConsumerHeartbeatEntries; short *ConsumerHeartBeatTimers; unsigned short *ProducerHeartBeatTime; short ProducerHeartBeatTimer; void (*heartbeatError)(struct struct_CO_Data *, unsigned char); enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 } NMTable[128]; short GuardTimeTimer; short LifeTimeTimer; void (*nodeguardError)(struct struct_CO_Data *, unsigned char); unsigned short *GuardTime; unsigned char *LifeTimeFactor; unsigned char nodeGuardStatus[128]; short syncTimer; unsigned long *COB_ID_Sync; unsigned long *Sync_Cycle_Period; void (*post_sync)(struct struct_CO_Data *); void (*post_TPDO)(struct struct_CO_Data *); void (*post_SlaveBootup)(struct struct_CO_Data *, unsigned char); void (*post_SlaveStateChange)(struct struct_CO_Data *, unsigned char, enum enum_nodeState { Initialisation=0, Disconnected=1, Connecting=2, Preparing=2, Stopped=4, Operational=5, Pre_operational=127, Unknown_state=15 }); unsigned char toggle; void *canHandle; struct td_indextable *(*scanIndexOD)(unsigned short wIndex, unsigned long *errorCode, unsigned long (***Callback)(struct struct_CO_Data *d, struct td_indextable *, unsigned char bSubindex)); void (*storeODSubIndex)(struct struct_CO_Data *d, unsigned short wIndex, unsigned char bSubindex); struct td_indextable *dcf_odentry; unsigned char *dcf_cursor; unsigned long dcf_entries_count; unsigned char dcf_status; unsigned long dcf_size; unsigned char *dcf_data; enum enum_errorState { Error_free=0, Error_occurred=1 } error_state; unsigned char error_history_size; unsigned char *error_number; unsigned long *error_first_element; unsigned char *error_register; unsigned long *error_cobid; struct s_errors { unsigned short errCode; unsigned char errRegMask; unsigned char active; } error_data[8]; void (*post_emcy)(struct struct_CO_Data *d, unsigned char nodeID, unsigned short errCode, unsigned char errReg); } *d; void (*callback)(struct struct_CO_Data *d, unsigned long id); unsigned long id; unsigned int val; unsigned int interval; } *

return_type: short

user_defined_types: struct struct_s_timer_entry { unsigned char state; struct struct_CO_Data *d; void (*callback)(struct struct_CO_Data *d, unsigned long id); unsigned long id; unsigned int val; unsigned int interval; }


DelAlarm

decompiled_code:
__int64 __fastcall DelAlarm(__int16 a1)
{
if ( a1 != -1 )
{
if ( last_timer_raw[0] == a1 )
last_timer_raw[0] = a1 - 1;
timers[40 * a1] = 0;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
if ( a1 != -1 )
{
if ( last_timer_raw[0] == a1 )
last_timer_raw[0] = a1 - 1;
timers[40 * a1] = 0;
}
return 0xFFFFFFFFLL;
}

original_code:
short DelAlarm(short handle)
{
 ;
 if(handle != -1)
 {
  if(handle == last_timer_raw)
   last_timer_raw--;
  timers[handle].state = 0;
 }
 return -1;
}

variable_types: handle short


AnaGateReceiveCallBack

decompiled_code:
int __fastcall AnaGateReceiveCallBack(__int16 a1, __int64 a2, int a3, int a4, unsigned int a5)
{
__int64 v7; // rbx
__int64 v8; // rax

v7 = pFistAnaGatePort;
while ( *(_DWORD *)v7 != a5 )
{
v7 = *(_QWORD *)(v7 + 16);
if ( pFistAnaGatePort == v7 )
{
LODWORD(v8) = printf(
"AnaGateReceiveCallBack (AnaGate_Linux): ERROR: Can't find AnaGatePort-Objekt to the Received Handle %d\n",
a5);
return v8;
}
}
while ( 1 )
{
LODWORD(v8) = *(_DWORD *)(v7 + 32);
if ( !(_DWORD)v8 )
break;
usleep(0x1388u);
}
*(_WORD *)(v7 + 4) = a1;
*(_BYTE *)(v7 + 7) = a3;
*(_BYTE *)(v7 + 6) = a4 == 2;
if ( a3 > 0 )
{
v8 = 0LL;
do
{
*(_BYTE *)(v7 + v8 + 8) = *(_BYTE *)(a2 + v8);
++v8;
}
while ( a3 > (int)v8 );
}
*(_DWORD *)(v7 + 32) = 1;
return v8;
}

canonical_decompiled_code:
int __fastcall func0(__int16 a1, __int64 a2, int a3, int a4, unsigned int a5)
{
__int64 v7; // rbx
__int64 v8; // rax

v7 = pFistAnaGatePort;
while ( *(_DWORD *)v7 != a5 )
{
v7 = *(_QWORD *)(v7 + 16);
if ( pFistAnaGatePort == v7 )
{
LODWORD(v8) = printf(
"AnaGateReceiveCallBack (AnaGate_Linux): ERROR: Can't find AnaGatePort-Objekt to the Received Handle %d\n",
a5);
return v8;
}
}
while ( 1 )
{
LODWORD(v8) = *(_DWORD *)(v7 + 32);
if ( !(_DWORD)v8 )
break;
usleep(0x1388u);
}
*(_WORD *)(v7 + 4) = a1;
*(_BYTE *)(v7 + 7) = a3;
*(_BYTE *)(v7 + 6) = a4 == 2;
if ( a3 > 0 )
{
v8 = 0LL;
do
{
*(_BYTE *)(v7 + v8 + 8) = *(_BYTE *)(a2 + v8);
++v8;
}
while ( a3 > (int)v8 );
}
*(_DWORD *)(v7 + 32) = 1;
return v8;
}

original_code:
void AnaGateReceiveCallBack (int nIdentifier, const char* pcBuffer, int nBufferLen, int nFlags, int hHandle)
{
   int i;
   struct SAnaGatePort *pAnaGatePort = pFistAnaGatePort;
   while (pAnaGatePort->hHandle != hHandle )
   {
      pAnaGatePort = pAnaGatePort->pNext;
      if (pAnaGatePort == pFistAnaGatePort )
      {
         pAnaGatePort = ((void *)0);
         printf("AnaGateReceiveCallBack (AnaGate_Linux): ERROR: Can't find AnaGatePort-Objekt to the Received Handle %d\n",hHandle);
         return;
      }
   }
   while (pAnaGatePort->bBufferFull)
   {
      usleep(5000);
   }
   pAnaGatePort->sMsgBuffer.cob_id = nIdentifier;
   pAnaGatePort->sMsgBuffer.len= nBufferLen;
   if (nFlags == 2)
    pAnaGatePort->sMsgBuffer.rtr = 1;
   else
    pAnaGatePort->sMsgBuffer.rtr = 0;
   for (i = 0 ; i < nBufferLen; i++)
   {
      pAnaGatePort->sMsgBuffer.data[i] = pcBuffer[i];
   }
   pAnaGatePort->bBufferFull = 1;
}

canonical_original_code:
void AnaGateReceiveCallBack(int nIdentifier, char *pcBuffer, int nBufferLen, int nFlags, int hHandle)
{
   int i;
   struct SAnaGatePort *pAnaGatePort = pFistAnaGatePort;
   while (pAnaGatePort->hHandle != hHandle )
   {
      pAnaGatePort = pAnaGatePort->pNext;
      if (pAnaGatePort == pFistAnaGatePort )
      {
         pAnaGatePort = ((void *)0);
         printf("AnaGateReceiveCallBack (AnaGate_Linux): ERROR: Can't find AnaGatePort-Objekt to the Received Handle %d\n",hHandle);
         return;
      }
   }
   while (pAnaGatePort->bBufferFull)
   {
      usleep(5000);
   }
   pAnaGatePort->sMsgBuffer.cob_id = nIdentifier;
   pAnaGatePort->sMsgBuffer.len= nBufferLen;
   if (nFlags == 2)
    pAnaGatePort->sMsgBuffer.rtr = 1;
   else
    pAnaGatePort->sMsgBuffer.rtr = 0;
   for (i = 0 ; i < nBufferLen; i++)
   {
      pAnaGatePort->sMsgBuffer.data[i] = pcBuffer[i];
   }
   pAnaGatePort->bBufferFull = 1;
}

variable_types: nIdentifier int

variable_types:
pcBuffer
char *

variable_types: nBufferLen int

variable_types: nFlags int

variable_types: hHandle int

variable_types: i int

variable_types: struct SAnaGatePort { int hHandle; struct Message { unsigned short cob_id; unsigned char rtr; unsigned char len; unsigned char data[8]; } sMsgBuffer; struct SAnaGatePort *pNext; struct SAnaGatePort *pPrev; int bBufferFull; } *

user_defined_types: struct SAnaGatePort { int hHandle; struct Message sMsgBuffer; struct SAnaGatePort *pNext; struct SAnaGatePort *pPrev; int bBufferFull; }


TranslateBaudeRate

original_code:
int TranslateBaudeRate(char* optarg){
   if(!strcmp( optarg, "1M")) return 1000000;
   if(!strcmp( optarg, "800K")) return 800000;
   if(!strcmp( optarg, "500K")) return 500000;
   if(!strcmp( optarg, "250K")) return 250000;
   if(!strcmp( optarg, "125K")) return 125000;
   if(!strcmp( optarg, "100K")) return 100000;
   if(!strcmp( optarg, "50K")) return 50000;
   if(!strcmp( optarg, "20K")) return 20000;
   if(!strcmp( optarg, "10K")) return 10000;
   return 0x0000;
}

canonical_original_code:
int TranslateBaudeRate(char *optarg){
   if(!strcmp( optarg, "1M")) return 1000000;
   if(!strcmp( optarg, "800K")) return 800000;
   if(!strcmp( optarg, "500K")) return 500000;
   if(!strcmp( optarg, "250K")) return 250000;
   if(!strcmp( optarg, "125K")) return 125000;
   if(!strcmp( optarg, "100K")) return 100000;
   if(!strcmp( optarg, "50K")) return 50000;
   if(!strcmp( optarg, "20K")) return 20000;
   if(!strcmp( optarg, "10K")) return 10000;
   return 0x0000;
}

variable_types:
optarg
char *


original_code:
unsigned char canReceive_driver(CAN_HANDLE fd0, Message *m)
{
   int i;
   struct SAnaGatePort* pAnaGatePort = (struct SAnaGatePort*)fd0;
   while (pAnaGatePort->bBufferFull == 0)
   {
      usleep (5000);
   }
   m->cob_id = pAnaGatePort->sMsgBuffer.cob_id;
   m->len = pAnaGatePort->sMsgBuffer.len;
   m->rtr = pAnaGatePort->sMsgBuffer.rtr;
   for (i = 0 ; i < pAnaGatePort->sMsgBuffer.len; i++)
   {
     m->data[i] = pAnaGatePort->sMsgBuffer.data[i];
   }
   pAnaGatePort->bBufferFull = 0;
   return 0;
}

canonical_original_code:
unsigned char canReceive_driver(void *fd0, struct Message *m)
{
   int i;
   struct SAnaGatePort *pAnaGatePort = (struct SAnaGatePort*)fd0;
   while (pAnaGatePort->bBufferFull == 0)
   {
      usleep (5000);
   }
   m->cob_id = pAnaGatePort->sMsgBuffer.cob_id;
   m->len = pAnaGatePort->sMsgBuffer.len;
   m->rtr = pAnaGatePort->sMsgBuffer.rtr;
   for (i = 0 ; i < pAnaGatePort->sMsgBuffer.len; i++)
   {
     m->data[i] = pAnaGatePort->sMsgBuffer.data[i];
   }
   pAnaGatePort->bBufferFull = 0;
   return 0;
}

variable_types: struct Message { unsigned short cob_id; unsigned char rtr; unsigned char len; unsigned char data[8]; } *


decompiled_code:
__int64 __fastcall canSend_driver(unsigned int *a1, unsigned __int16 *a2)
{
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-78h] BYREF

v2 = CANWrite(*a1, *a2, a2 + 2, *((unsigned __int8 *)a2 + 3), 2 * (unsigned int)(*((_BYTE *)a2 + 2) != 0));
result = 0LL;
if ( v2 )
{
CANErrorMessage(v2, &v4, 100LL);
fprintf(stderr, "canSend_driver (AnaGate_Linux) %s \n", (const char *)v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, unsigned __int16 *a2)
{
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-78h] BYREF

v2 = CANWrite(*a1, *a2, a2 + 2, *((unsigned __int8 *)a2 + 3), 2 * (unsigned int)(*((_BYTE *)a2 + 2) != 0));
result = 0LL;
if ( v2 )
{
CANErrorMessage(v2, &v4, 100LL);
fprintf(stderr, "canSend_driver (AnaGate_Linux) %s \n", (const char *)v2);
result = 1LL;
}
return result;
}

original_code:
unsigned char canSend_driver(CAN_HANDLE fd0, Message const *m)
{
   struct SAnaGatePort* pAnaCanPort = (struct SAnaGatePort*)fd0;
   char cErrorMsg[100];
   int nRetCode;
   int nMsgTyp;
   if (m->rtr == 0)
   {
     nMsgTyp = 0;
   }
   else
   {
     nMsgTyp = 2;
   }
   if ( (nRetCode = CANWrite(pAnaCanPort->hHandle , m->cob_id,(const char*) m->data, m->len, nMsgTyp) ) )
   {
     CANErrorMessage( nRetCode, cErrorMsg ,100 );
     fprintf(stderr,"canSend_driver (AnaGate_Linux) %s \n",nRetCode);
     return 1;
   }
   return 0;
}

canonical_original_code:
unsigned char canSend_driver(void *fd0, struct Message *m)
{
   struct SAnaGatePort *pAnaCanPort = (struct SAnaGatePort*)fd0;
   char cErrorMsg[100];
   int nRetCode;
   int nMsgTyp;
   if (m->rtr == 0)
   {
     nMsgTyp = 0;
   }
   else
   {
     nMsgTyp = 2;
   }
   if ( (nRetCode = CANWrite(pAnaCanPort->hHandle , m->cob_id,(char *) m->data, m->len, nMsgTyp) ) )
   {
     CANErrorMessage( nRetCode, cErrorMsg ,100 );
     fprintf(stderr,"canSend_driver (AnaGate_Linux) %s \n",nRetCode);
     return 1;
   }
   return 0;
}

variable_types:
cErrorMsg
char [100]

variable_types: nRetCode int

variable_types: nMsgTyp int


decompiled_code:
__int64 __fastcall canChangeBaudRate_driver(unsigned int *a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdi
__int64 result; // rax
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = TranslateBaudeRate(a2);
v3 = (unsigned int)CANSetGlobals(*a1, v2, 0LL, 0LL, 1LL);
result = 0LL;
if ( (_DWORD)v3 )
{
CANErrorMessage(v3, v5, 100LL);
fprintf(stderr, "canChangeBaudRate_drive (AnaGate_Linux): %s\n", v5);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdi
__int64 result; // rax
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = func3(a2);
v3 = (unsigned int)CANSetGlobals(*a1, v2, 0LL, 0LL, 1LL);
result = 0LL;
if ( (_DWORD)v3 )
{
CANErrorMessage(v3, v5, 100LL);
fprintf(stderr, "canChangeBaudRate_drive (AnaGate_Linux): %s\n", v5);
result = 1LL;
}
return result;
}

original_code:
unsigned char canChangeBaudRate_driver( CAN_HANDLE fd0, char* baud)
{
   int nRetCode;
   char cErrorMsg[100];
   struct SAnaGatePort* pAnaGatePort = (struct SAnaGatePort*)fd0;
   if (nRetCode = CANSetGlobals (pAnaGatePort->hHandle, TranslateBaudeRate(baud), 0, 0, 1) )
   {
      CANErrorMessage( nRetCode, cErrorMsg ,100 );
      fprintf(stderr, "canChangeBaudRate_drive (AnaGate_Linux): %s\n", cErrorMsg);
      return 1;
   }
   return 0;
}

canonical_original_code:
unsigned char canChangeBaudRate_driver(void *fd0, char *baud)
{
   int nRetCode;
   char cErrorMsg[100];
   struct SAnaGatePort *pAnaGatePort = (struct SAnaGatePort*)fd0;
   if (nRetCode = CANSetGlobals (pAnaGatePort->hHandle, TranslateBaudeRate(baud), 0, 0, 1) )
   {
      CANErrorMessage( nRetCode, cErrorMsg ,100 );
      fprintf(stderr, "canChangeBaudRate_drive (AnaGate_Linux): %s\n", cErrorMsg);
      return 1;
   }
   return 0;
}

variable_types:
baud
char *


decompiled_code:
__int64 __fastcall canClose_driver(void *ptr)
{
unsigned int v1; // eax
_QWORD *v2; // rax
__int64 v3; // rdx
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

*((_DWORD *)ptr + 8) = 1;
v1 = CANCloseDevice(*(unsigned int *)ptr);
if ( v1 )
{
CANErrorMessage(v1, v5, 100LL);
fprintf(stderr, "canClose_driver (AnaGate_Linux): %s\n", v5);
printf("canClose_driver (AnaGate_Linux): %s\n", v5);
v2 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( v2 != ptr )
goto LABEL_3;
}
else
{
v2 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( v2 != ptr )
{
LABEL_3:
v3 = *((_QWORD *)ptr + 3);
v2[3] = v3;
*(_QWORD *)(v3 + 16) = v2;
free(ptr);
return 0LL;
}
}
free(ptr);
pFistAnaGatePort = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
unsigned int v1; // eax
_QWORD *v2; // rax
__int64 v3; // rdx
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

*((_DWORD *)ptr + 8) = 1;
v1 = CANCloseDevice(*(unsigned int *)ptr);
if ( v1 )
{
CANErrorMessage(v1, v5, 100LL);
fprintf(stderr, "canClose_driver (AnaGate_Linux): %s\n", v5);
printf("canClose_driver (AnaGate_Linux): %s\n", v5);
v2 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( v2 != ptr )
goto LABEL_3;
}
else
{
v2 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( v2 != ptr )
{
LABEL_3:
v3 = *((_QWORD *)ptr + 3);
v2[3] = v3;
*(_QWORD *)(v3 + 16) = v2;
free(ptr);
return 0LL;
}
}
free(ptr);
pFistAnaGatePort = 0LL;
return 0LL;
}

original_code:
int canClose_driver(CAN_HANDLE fd0)
{
   struct SAnaGatePort* pAnaGatePort = (struct SAnaGatePort*)fd0;
   char cErrorMsg[100];
   int nRetCode;
   pAnaGatePort->bBufferFull = 1;
   if ( nRetCode = CANCloseDevice(pAnaGatePort->hHandle) )
   {
     CANErrorMessage( nRetCode, cErrorMsg ,100 );
     fprintf(stderr, "canClose_driver (AnaGate_Linux): %s\n", cErrorMsg);
     printf("canClose_driver (AnaGate_Linux): %s\n", cErrorMsg);
   }
   if (pAnaGatePort->pNext == pAnaGatePort)
   {
       free (pAnaGatePort);
       pFistAnaGatePort=((void *)0);
   }
   else
   {
      pAnaGatePort->pNext->pPrev = pAnaGatePort->pPrev;
      pAnaGatePort->pPrev->pNext = pAnaGatePort->pNext;
      free (pAnaGatePort);
   }
   return 0;
}

canonical_original_code:
int canClose_driver(void *fd0)
{
   struct SAnaGatePort *pAnaGatePort = (struct SAnaGatePort*)fd0;
   char cErrorMsg[100];
   int nRetCode;
   pAnaGatePort->bBufferFull = 1;
   if ( nRetCode = CANCloseDevice(pAnaGatePort->hHandle) )
   {
     CANErrorMessage( nRetCode, cErrorMsg ,100 );
     fprintf(stderr, "canClose_driver (AnaGate_Linux): %s\n", cErrorMsg);
     printf("canClose_driver (AnaGate_Linux): %s\n", cErrorMsg);
   }
   if (pAnaGatePort->pNext == pAnaGatePort)
   {
       free (pAnaGatePort);
       pFistAnaGatePort=((void *)0);
   }
   else
   {
      pAnaGatePort->pNext->pPrev = pAnaGatePort->pPrev;
      pAnaGatePort->pPrev->pNext = pAnaGatePort->pNext;
      free (pAnaGatePort);
   }
   return 0;
}


decompiled_code:
__int64 __fastcall CANOpenShellSlaveOD_valueRangeTest(char a1, _BYTE *a2)
{
__int64 result; // rax

result = 0LL;
if ( a1 == -97 )
result = *a2 != 0 ? 0x6090030 : 0;
return result;
}

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

result = 0LL;
if ( a1 == -97 )
result = *a2 != 0 ? 0x6090030 : 0;
return result;
}

original_code:
unsigned long int CANOpenShellSlaveOD_valueRangeTest (unsigned char typeValue, void * value)
{
  switch (typeValue) {
    case 0x9F:
      if (*(unsigned char*)value != (unsigned char)0) return 0x06090030;
      break;
  }
  return 0;
}

canonical_original_code:
unsigned long CANOpenShellSlaveOD_valueRangeTest(unsigned char typeValue, void *value)
{
  switch (typeValue) {
    case 0x9F:
      if (*(unsigned char *)value != (unsigned char)0) return 0x06090030;
      break;
  }
  return 0;
}

variable_types:
typeValue
unsigned char

variable_types:
value
void *