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

canonical_decompiled_code:
int func9()
{
return puts("TestSlaveB_NMT_Slave_Communications_Reset_Callback");
}

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

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


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

canonical_decompiled_code:
int func10()
{
return puts("TestSlaveB_StoreConfiguration");
}

original_code:
void TestSlaveB_StoreConfiguration(CO_Data* d, unsigned char *error, unsigned char *spec_error)
{
 printf ("TestSlaveB_StoreConfiguration\n");
}

canonical_original_code:
void TestSlaveB_StoreConfiguration(struct struct_CO_Data *d, unsigned char *error, unsigned char *spec_error)
{
 printf ("TestSlaveB_StoreConfiguration\n");
}

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:
error
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); }


canReceiveLoop

decompiled_code:
void __fastcall canReceiveLoop(__int64 a1)
{
char v1[36]; // [rsp+0h] [rbp-24h] BYREF

while ( *(_BYTE *)a1 )
{
if ( (unsigned __int8)canReceive_driver(*(_QWORD *)(a1 + 8), v1) )
break;
EnterMutex();
canDispatch(*(_QWORD *)(a1 + 24), v1);
LeaveMutex();
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
char v1[36]; // [rsp+0h] [rbp-24h] BYREF

while ( *(_BYTE *)a1 )
{
if ( (unsigned __int8)canReceive_driver(*(_QWORD *)(a1 + 8), v1) )
break;
EnterMutex();
canDispatch(*(_QWORD *)(a1 + 24), v1);
LeaveMutex();
}
}

original_code:
void canReceiveLoop(CAN_PORT port)
{
       Message m;
       while (((CANPort*)port)->used) {
               if ((* canReceive_driver)(((CANPort*)port)->fd, &m) != 0)
                       break;
               EnterMutex();
               canDispatch(((CANPort*)port)->d, &m);
               LeaveMutex();
       }
}

canonical_original_code:
void canReceiveLoop(void *port)
{
       struct Message m;
       while (((struct CANPort *)port)->used) {
               if ((* canReceive_driver)(((struct CANPort *)port)->fd, &m) != 0)
                       break;
               EnterMutex();
               canDispatch(((struct CANPort *)port)->d, &m);
               LeaveMutex();
       }
}

variable_types:
port
void *

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

user_defined_types: struct CANPort { char used; void *fd; void *receiveTask; struct struct_CO_Data *d; }

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


UnLoadCanDriver

decompiled_code:
__int64 __fastcall UnLoadCanDriver(void *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
dlclose(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
dlclose(a1);
return 0LL;
}

original_code:
unsigned char UnLoadCanDriver(LIB_HANDLE handle)
{
 if(handle!=((void *)0))
 {
  dlclose(handle);
  handle=((void *)0);
  return 0;
 }
 return -1;
}

canonical_original_code:
unsigned char UnLoadCanDriver(void *handle)
{
 if(handle!=((void *)0))
 {
  dlclose(handle);
  handle=((void *)0);
  return 0;
 }
 return -1;
}

variable_types:
handle
void *

return_type: unsigned char


LoadCanDriver

decompiled_code:
void *__fastcall LoadCanDriver(const char *a1)
{
void *v1; // rax
void *v2; // r12
char *v3; // rax
void *v4; // rdi
char *v6; // rax

v1 = dlopen(a1, 1);
v2 = v1;
if ( v1 )
{
canReceive_driver = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym(v1, "canReceive_driver");
v3 = dlerror();
if ( v3 )
goto LABEL_7;
canSend_driver = dlsym(v2, "canSend_driver");
v3 = dlerror();
if ( v3
|| (canOpen_driver = dlsym(v2, "canOpen_driver"), (v3 = dlerror()) != 0LL)
|| (canChangeBaudRate_driver = dlsym(v2, "canChangeBaudRate_driver"), (v3 = dlerror()) != 0LL)
|| (canClose_driver = dlsym(v2, "canClose_driver"), (v3 = dlerror()) != 0LL) )
{
LABEL_7:
fprintf(stderr, "%s\n", v3);
v4 = v2;
v2 = 0LL;
UnLoadCanDriver(v4);
}
}
else
{
v6 = dlerror();
fprintf(stderr, "%s\n", v6);
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func2(const char *a1)
{
void *v1; // rax
void *v2; // r12
char *v3; // rax
void *v4; // rdi
char *v6; // rax

v1 = dlopen(a1, 1);
v2 = v1;
if ( v1 )
{
canReceive_driver = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym(v1, "canReceive_driver");
v3 = dlerror();
if ( v3 )
goto LABEL_7;
canSend_driver = dlsym(v2, "canSend_driver");
v3 = dlerror();
if ( v3
|| (canOpen_driver = dlsym(v2, "canOpen_driver"), (v3 = dlerror()) != 0LL)
|| (canChangeBaudRate_driver = dlsym(v2, "canChangeBaudRate_driver"), (v3 = dlerror()) != 0LL)
|| (canClose_driver = dlsym(v2, "canClose_driver"), (v3 = dlerror()) != 0LL) )
{
LABEL_7:
fprintf(stderr, "%s\n", v3);
v4 = v2;
v2 = 0LL;
func1(v4);
}
}
else
{
v6 = dlerror();
fprintf(stderr, "%s\n", v6);
}
return v2;
}

original_code:
LIB_HANDLE LoadCanDriver(const char* driver_name)
{
 LIB_HANDLE handle = ((void *)0);
 char *error;
 if(handle==((void *)0))
 {
  handle = dlopen(driver_name, 0x00001);
 }
 if (!handle) {
  fprintf (stderr, "%s\n", dlerror());
         return ((void *)0);
 }
 *(void **) (&canReceive_driver) = dlsym(handle, "canReceive""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 *(void **) (&canSend_driver) = dlsym(handle, "canSend""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 *(void **) (&canOpen_driver) = dlsym(handle, "canOpen""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 *(void **) (&canChangeBaudRate_driver) = dlsym(handle, "canChangeBaudRate""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 *(void **) (&canClose_driver) = dlsym(handle, "canClose""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 return handle;
}

canonical_original_code:
void *LoadCanDriver(char *driver_name)
{
 void *handle = ((void *)0);
 char *error;
 if(handle==((void *)0))
 {
  handle = dlopen(driver_name, 0x00001);
 }
 if (!handle) {
  fprintf (stderr, "%s\n", dlerror());
         return ((void *)0);
 }
 *(void **) (&canReceive_driver) = dlsym(handle, "canReceive""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 *(void **) (&canSend_driver) = dlsym(handle, "canSend""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 *(void **) (&canOpen_driver) = dlsym(handle, "canOpen""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 *(void **) (&canChangeBaudRate_driver) = dlsym(handle, "canChangeBaudRate""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 *(void **) (&canClose_driver) = dlsym(handle, "canClose""_driver"); if ((error = dlerror()) != ((void *)0)) { fprintf (stderr, "%s\n", error); UnLoadCanDriver(handle); return ((void *)0); }
 return handle;
}

variable_types:
error
char *

return_type: void *


canSend

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

if ( a1 )
result = canSend_driver(*(_QWORD *)(a1 + 8));
else
result = 1LL;
return result;
}

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

if ( a1 )
result = canSend_driver(*(_QWORD *)(a1 + 8));
else
result = 1LL;
return result;
}

original_code:
unsigned char canSend(CAN_PORT port, Message *m)
{
 if(port){
  unsigned char res;
  res = (* canSend_driver)(((CANPort*)port)->fd, m);
  return res;
 }
 return 1;
}

canonical_original_code:
unsigned char canSend(void *port, struct Message *m)
{
 if(port){
  unsigned char res;
  res = (* canSend_driver)(((struct CANPort *)port)->fd, m);
  return res;
 }
 return 1;
}

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

variable_types:
res
unsigned char


canOpen

decompiled_code:
__int64 __fastcall canOpen(__int64 a1, __int64 a2)
{
int v2; // ebx
_BYTE *v3; // rax
__int64 v4; // r12
char *v5; // rax

v2 = 0;
v3 = &canports;
do
{
if ( !*v3 )
break;
++v2;
v3 += 32;
}
while ( v2 != 16 );
if ( canOpen_driver )
{
v4 = canOpen_driver();
if ( v4 )
{
v5 = (char *)&canports + 32 * v2;
*((_QWORD *)v5 + 1) = v4;
v4 = (__int64)v5;
*v5 = 1;
*((_QWORD *)v5 + 3) = a2;
*(_QWORD *)(a2 + 1408) = v5;
CreateReceiveTask(v5, v5 + 16, canReceiveLoop);
}
}
else
{
v4 = 0LL;
fwrite("CanOpen : Can Driver dll not loaded\n", 1uLL, 0x24uLL, stderr);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ebx
_BYTE *v3; // rax
__int64 v4; // r12
char *v5; // rax

v2 = 0;
v3 = &canports;
do
{
if ( !*v3 )
break;
++v2;
v3 += 32;
}
while ( v2 != 16 );
if ( canOpen_driver )
{
v4 = canOpen_driver();
if ( v4 )
{
v5 = (char *)&canports + 32 * v2;
*((_QWORD *)v5 + 1) = v4;
v4 = (__int64)v5;
*v5 = 1;
*((_QWORD *)v5 + 3) = a2;
*(_QWORD *)(a2 + 1408) = v5;
CreateReceiveTask(v5, v5 + 16, canReceiveLoop);
}
}
else
{
v4 = 0LL;
fwrite("CanOpen : Can Driver dll not loaded\n", 1uLL, 0x24uLL, stderr);
}
return v4;
}

original_code:
CAN_PORT canOpen(s_BOARD *board, CO_Data * d)
{
 int i;
 for(i=0; i < 16; i++)
 {
  if(!canports[i].used)
  break;
 }
 if (&(* canOpen_driver)==((void *)0)) {
         fprintf(stderr,"CanOpen : Can Driver dll not loaded\n");
         return ((void *)0);
 }
 CAN_HANDLE fd0 = (* canOpen_driver)(board);
 if(fd0){
  canports[i].used = 1;
  canports[i].fd = fd0;
  canports[i].d = d;
  d->canHandle = (CAN_PORT)&canports[i];
  CreateReceiveTask(&(canports[i]), &canports[i].receiveTask, &canReceiveLoop);
  return (CAN_PORT)&canports[i];
 }else{
         ;
  return ((void *)0);
 }
}

canonical_original_code:
void *canOpen(struct struct_s_BOARD *board, struct struct_CO_Data *d)
{
 int i;
 for(i=0; i < 16; i++)
 {
  if(!canports[i].used)
  break;
 }
 if (&(* canOpen_driver)==((void *)0)) {
         fprintf(stderr,"CanOpen : Can Driver dll not loaded\n");
         return ((void *)0);
 }
 void *fd0 = (* canOpen_driver)(board);
 if(fd0){
  canports[i].used = 1;
  canports[i].fd = fd0;
  canports[i].d = d;
  d->canHandle = (CAN_PORT)&canports[i];
  CreateReceiveTask(&(canports[i]), &canports[i].receiveTask, &canReceiveLoop);
  return (CAN_PORT)&canports[i];
 }else{
         ;
  return ((void *)0);
 }
}

variable_types: struct struct_s_BOARD { char *busname; char *baudrate; } *

variable_types: i int

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


canClose

decompiled_code:
__int64 __fastcall canClose(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // rbx

v1 = 0;
v2 = *(_QWORD *)(a1 + 1408);
if ( v2 )
{
*(_BYTE *)v2 = 0;
v1 = canClose_driver(*(_QWORD *)(v2 + 8));
WaitReceiveTaskEnd(v2 + 16);
*(_QWORD *)(a1 + 1408) = 0LL;
}
return v1;
}

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

v1 = 0;
v2 = *(_QWORD *)(a1 + 1408);
if ( v2 )
{
*(_BYTE *)v2 = 0;
v1 = canClose_driver(*(_QWORD *)(v2 + 8));
WaitReceiveTaskEnd(v2 + 16);
*(_QWORD *)(a1 + 1408) = 0LL;
}
return v1;
}

original_code:
int canClose(CO_Data * d)
{
 int res = 0;
 CANPort* port = (CANPort*)d->canHandle;
    if(port){
        ((CANPort*)d->canHandle)->used = 0;
        res = (* canClose_driver)(port->fd);
        WaitReceiveTaskEnd(&port->receiveTask);
        d->canHandle = ((void *)0);
    }
 return res;
}

canonical_original_code:
int canClose(struct struct_CO_Data *d)
{
 int res = 0;
 struct CANPort *port = (CANPort*)d->canHandle;
    if(port){
        ((struct CANPort *)d->canHandle)->used = 0;
        res = (* canClose_driver)(port->fd);
        WaitReceiveTaskEnd(&port->receiveTask);
        d->canHandle = ((void *)0);
    }
 return res;
}

variable_types: res int

variable_types: struct CANPort { char used; void *fd; void *receiveTask; 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; } *

return_type: int


canChangeBaudRate

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

if ( a1 )
result = canChangeBaudRate_driver(*(_QWORD *)(a1 + 8));
else
result = 1LL;
return result;
}

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

if ( a1 )
result = canChangeBaudRate_driver(*(_QWORD *)(a1 + 8));
else
result = 1LL;
return result;
}

original_code:
unsigned char canChangeBaudRate(CAN_PORT port, char* baud)
{
   if(port){
  unsigned char res;
  res = (* canChangeBaudRate_driver)(((CANPort*)port)->fd, baud);
  return res;
 }
 return 1;
}

canonical_original_code:
unsigned char canChangeBaudRate(void *port, char *baud)
{
   if(port){
  unsigned char res;
  res = (* canChangeBaudRate_driver)(((struct CANPort *)port)->fd, baud);
  return res;
 }
 return 1;
}

variable_types:
baud
char *


InitNode

decompiled_code:
__int64 InitNode()
{
setNodeId(&SillySlave_Data, (unsigned __int8)slaveNode);
return setState(&SillySlave_Data, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
setNodeId(&SillySlave_Data, (unsigned __int8)slaveNode);
return setState(&SillySlave_Data, 0LL);
}

original_code:
void InitNode(CO_Data* d, unsigned long int id)
{
    setNodeId(&SillySlave_Data, slaveNode);
    setState(&SillySlave_Data, Initialisation);
}

canonical_original_code:
void InitNode(struct struct_CO_Data *d, unsigned long id)
{
    setNodeId(&SillySlave_Data, slaveNode);
    setState(&SillySlave_Data, Initialisation);
}

variable_types:
id
unsigned long


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

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

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

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

variable_types:
heartbeatID
unsigned char


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

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

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

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

variable_types:
wIndex
unsigned short

variable_types:
bSubindex
unsigned char


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

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

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

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

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:
nodeID
unsigned char

variable_types:
errCode
unsigned short

variable_types:
errReg
unsigned char


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

canonical_decompiled_code:
int func5()
{
return puts("SillySlave_preOperational");
}

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

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


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

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

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

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


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

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

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

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


decompiled_code:
void *SillySlave_post_sync()
{
void *result; // rax

puts("SillySlave_post_sync: ");
result = &LifeSignal;
++LifeSignal;
return result;
}

canonical_decompiled_code:
void *func8()
{
void *result; // rax

puts("SillySlave_post_sync: ");
result = &LifeSignal;
++LifeSignal;
return result;
}

original_code:
void SillySlave_post_sync(CO_Data* d)
{
    printf("SillySlave_post_sync: \n");
    LifeSignal++;
}

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


decompiled_code:
int SillySlave_post_TPDO()
{
puts("SillySlave_post_TPDO: ");
return printf("LifeSignal = %u\n", LifeSignal);
}

canonical_decompiled_code:
int func9()
{
puts("SillySlave_post_TPDO: ");
return printf("LifeSignal = %u\n", LifeSignal);
}

original_code:
void SillySlave_post_TPDO(CO_Data* d)
{
    printf("SillySlave_post_TPDO: \n");
    printf("LifeSignal = %u\n", LifeSignal);
}

canonical_original_code:
void SillySlave_post_TPDO(struct struct_CO_Data *d)
{
    printf("SillySlave_post_TPDO: \n");
    printf("LifeSignal = %u\n", LifeSignal);
}


decompiled_code:
void *SillySlave_initialisation()
{
void *result; // rax
char v1; // [rsp+7h] [rbp-11h] BYREF
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 385LL;
v1 = 8;
puts("SillySlave_initialisation");
setODentry(&SillySlave_Data, 6144LL, 1LL, &v2, &v1, 0LL, 0LL);
result = &LifeSignal;
LifeSignal = 0;
return result;
}

canonical_decompiled_code:
void *func10()
{
void *result; // rax
char v1; // [rsp+7h] [rbp-11h] BYREF
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 385LL;
v1 = 8;
puts("SillySlave_initialisation");
setODentry(&SillySlave_Data, 6144LL, 1LL, &v2, &v1, 0LL, 0LL);
result = &LifeSignal;
LifeSignal = 0;
return result;
}

original_code:
void SillySlave_initialisation(CO_Data* d )
{
    unsigned long int PDO1_COBID = 0x0180 + 0x1;
    unsigned char size = sizeof(PDO1_COBID);
    printf("SillySlave_initialisation\n");
    _setODentry( &SillySlave_Data, 0x1800, 0x01, &PDO1_COBID, &size, 0x00, 0);
    LifeSignal = 0;
}

canonical_original_code:
void SillySlave_initialisation(struct struct_CO_Data *d)
{
    unsigned long PDO1_COBID = 0x0180 + 0x1;
    unsigned char size = sizeof(PDO1_COBID);
    printf("SillySlave_initialisation\n");
    _setODentry( &SillySlave_Data, 0x1800, 0x01, &PDO1_COBID, &size, 0x00, 0);
    LifeSignal = 0;
}

variable_types:
size
unsigned char


InitCANdevice

decompiled_code:
__int64 __fastcall InitCANdevice(unsigned __int8 a1, __int64 a2, char a3)
{
__int64 result; // rax
char s[2]; // [rsp+7h] [rbp-41h] BYREF
char v6[7]; // [rsp+9h] [rbp-3Fh] BYREF
char *v7; // [rsp+10h] [rbp-38h] BYREF
char *v8; // [rsp+18h] [rbp-30h]

sprintf(s, "%u", a1);
sprintf(v6, "%uK", a2);
v7 = s;
slaveNode = a3;
v8 = v6;
SillySlave_Data[83] = SillySlave_heartbeatError;
SillySlave_Data[72] = SillySlave_initialisation;
SillySlave_Data[73] = SillySlave_preOperational;
SillySlave_Data[74] = SillySlave_operational;
SillySlave_Data[75] = SillySlave_stopped;
SillySlave_Data[171] = SillySlave_post_sync;
SillySlave_Data[172] = SillySlave_post_TPDO;
SillySlave_Data[178] = SillySlave_storeODSubIndex;
SillySlave_Data[194] = SillySlave_post_emcy;
TimerInit();
if ( canOpen(&v7, SillySlave_Data) )
{
puts("\nInitCANdevice(), canOpen() OK, starting timer loop...");
StartTimerLoop(InitNode);
pause();
puts("\nFinishing.");
StopTimerLoop(Exit);
result = 0LL;
}
else
{
printf("\n\aInitCANdevice() CAN bus %s opening error, baudrate=%s\n", v7, v8);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1, __int64 a2, char a3)
{
__int64 result; // rax
char s[2]; // [rsp+7h] [rbp-41h] BYREF
char v6[7]; // [rsp+9h] [rbp-3Fh] BYREF
char *v7; // [rsp+10h] [rbp-38h] BYREF
char *v8; // [rsp+18h] [rbp-30h]

sprintf(s, "%u", a1);
sprintf(v6, "%uK", a2);
v7 = s;
slaveNode = a3;
v8 = v6;
SillySlave_Data[83] = SillySlave_heartbeatError;
SillySlave_Data[72] = SillySlave_initialisation;
SillySlave_Data[73] = SillySlave_preOperational;
SillySlave_Data[74] = SillySlave_operational;
SillySlave_Data[75] = SillySlave_stopped;
SillySlave_Data[171] = SillySlave_post_sync;
SillySlave_Data[172] = SillySlave_post_TPDO;
SillySlave_Data[178] = SillySlave_storeODSubIndex;
SillySlave_Data[194] = SillySlave_post_emcy;
TimerInit();
if ( canOpen(&v7, SillySlave_Data) )
{
puts("\nInitCANdevice(), canOpen() OK, starting timer loop...");
StartTimerLoop(InitNode);
pause();
puts("\nFinishing.");
StopTimerLoop(Exit);
result = 0LL;
}
else
{
printf("\n\aInitCANdevice() CAN bus %s opening error, baudrate=%s\n", v7, v8);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
signed char InitCANdevice( unsigned char bus, unsigned long int baudrate, unsigned char node )
{
char busName[2];
char baudRate[7];
s_BOARD board;
    sprintf(busName, "%u", bus);
    sprintf(baudRate, "%uK", baudrate);
    board.busname = busName;
    board.baudrate = baudRate;
    slaveNode = node;
    SillySlave_Data.heartbeatError = SillySlave_heartbeatError;
    SillySlave_Data.initialisation = SillySlave_initialisation;
    SillySlave_Data.preOperational = SillySlave_preOperational;
    SillySlave_Data.operational = SillySlave_operational;
    SillySlave_Data.stopped = SillySlave_stopped;
    SillySlave_Data.post_sync = SillySlave_post_sync;
    SillySlave_Data.post_TPDO = SillySlave_post_TPDO;
    SillySlave_Data.storeODSubIndex = SillySlave_storeODSubIndex;
    SillySlave_Data.post_emcy = SillySlave_post_emcy;
 TimerInit();
    if(!canOpen(&board, &SillySlave_Data))
    {
        printf("\n\aInitCANdevice() CAN bus %s opening error, baudrate=%s\n",board.busname, board.baudrate);
        return -1;
    }
    printf("\nInitCANdevice(), canOpen() OK, starting timer loop...\n");
    StartTimerLoop(&InitNode);
 pause();
 printf("\nFinishing.\n");
 StopTimerLoop(&Exit);
    return 0;
}

canonical_original_code:
char InitCANdevice(unsigned char bus, unsigned long baudrate, unsigned char node)
{
char busName[2];
char baudRate[7];
struct struct_s_BOARD board;
    sprintf(busName, "%u", bus);
    sprintf(baudRate, "%uK", baudrate);
    board.busname = busName;
    board.baudrate = baudRate;
    slaveNode = node;
    SillySlave_Data.heartbeatError = SillySlave_heartbeatError;
    SillySlave_Data.initialisation = SillySlave_initialisation;
    SillySlave_Data.preOperational = SillySlave_preOperational;
    SillySlave_Data.operational = SillySlave_operational;
    SillySlave_Data.stopped = SillySlave_stopped;
    SillySlave_Data.post_sync = SillySlave_post_sync;
    SillySlave_Data.post_TPDO = SillySlave_post_TPDO;
    SillySlave_Data.storeODSubIndex = SillySlave_storeODSubIndex;
    SillySlave_Data.post_emcy = SillySlave_post_emcy;
 TimerInit();
    if(!canOpen(&board, &SillySlave_Data))
    {
        printf("\n\aInitCANdevice() CAN bus %s opening error, baudrate=%s\n",board.busname, board.baudrate);
        return -1;
    }
    printf("\nInitCANdevice(), canOpen() OK, starting timer loop...\n");
    StartTimerLoop(&InitNode);
 pause();
 printf("\nFinishing.\n");
 StopTimerLoop(&Exit);
    return 0;
}

variable_types:
bus
unsigned char

variable_types:
baudrate
unsigned long

variable_types:
node
unsigned char

variable_types:
busName
char [2]

variable_types:
baudRate
char [7]

variable_types: struct struct_s_BOARD { char *busname; char *baudrate; }

return_type: char


Exit

decompiled_code:
__int64 Exit()
{
return setState(&SillySlave_Data, 4LL);
}

canonical_decompiled_code:
__int64 func1()
{
return setState(&SillySlave_Data, 4LL);
}

original_code:
void Exit(CO_Data* d, unsigned long int id)
{
    setState(&SillySlave_Data, Stopped);
}

canonical_original_code:
void Exit(struct struct_CO_Data *d, unsigned long id)
{
    setState(&SillySlave_Data, Stopped);
}


decompiled_code:
int CANOpenShellOD_initialisation()
{
return puts("Node_initialisation");
}

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

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

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


decompiled_code:
int CANOpenShellOD_preOperational()
{
return puts("Node_preOperational");
}

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

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

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


decompiled_code:
int CANOpenShellOD_operational()
{
return puts("Node_operational");
}

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

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

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


decompiled_code:
int CANOpenShellOD_stopped()
{
return puts("Node_stopped");
}

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

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

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


decompiled_code:
int __fastcall CANOpenShellOD_post_SlaveBootup(__int64 a1, unsigned __int8 a2)
{
return printf("Slave %x boot up\n", a2);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, unsigned __int8 a2)
{
return printf("Slave %x boot up\n", a2);
}

original_code:
void CANOpenShellOD_post_SlaveBootup(CO_Data* d, unsigned char nodeid)
{
 printf("Slave %x boot up\n", nodeid);
}

canonical_original_code:
void CANOpenShellOD_post_SlaveBootup(struct struct_CO_Data *d, unsigned char nodeid)
{
 printf("Slave %x boot up\n", nodeid);
}

variable_types:
nodeid
unsigned char


CheckReadSDO

decompiled_code:
__int64 __fastcall CheckReadSDO(__int64 a1, unsigned __int8 a2)
{
__int64 v3; // [rsp+8h] [rbp-30h] BYREF
__int64 v4; // [rsp+10h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+18h] [rbp-20h] BYREF

v4 = 0LL;
v5[0] = 64LL;
if ( (unsigned __int8)getReadResultNetworkDict(CANOpenShellOD_Data, a2, &v4, v5, &v3) == 1 )
printf("\nResult : %x\n", v4);
else
printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", a2, v3);
return closeSDOtransfer(CANOpenShellOD_Data, a2, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int8 a2)
{
__int64 v3; // [rsp+8h] [rbp-30h] BYREF
__int64 v4; // [rsp+10h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+18h] [rbp-20h] BYREF

v4 = 0LL;
v5[0] = 64LL;
if ( (unsigned __int8)getReadResultNetworkDict(CANOpenShellOD_Data, a2, &v4, v5, &v3) == 1 )
printf("\nResult : %x\n", v4);
else
printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", a2, v3);
return closeSDOtransfer(CANOpenShellOD_Data, a2, 2LL);
}

original_code:
void CheckReadSDO(CO_Data* d, unsigned char nodeid)
{
 unsigned long int abortCode;
 unsigned long int data=0;
 unsigned long int size=64;
 if(getReadResultNetworkDict(CANOpenShellOD_Data, nodeid, &data, &size, &abortCode) != 0x1)
  printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
 else
  printf("\nResult : %x\n", data);
 closeSDOtransfer(CANOpenShellOD_Data, nodeid, 0x2);
}

canonical_original_code:
void CheckReadSDO(struct struct_CO_Data *d, unsigned char nodeid)
{
 unsigned long abortCode;
 unsigned long data = 0;
 unsigned long size = 64;
 if(getReadResultNetworkDict(CANOpenShellOD_Data, nodeid, &data, &size, &abortCode) != 0x1)
  printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
 else
  printf("\nResult : %x\n", data);
 closeSDOtransfer(CANOpenShellOD_Data, nodeid, 0x2);
}

variable_types:
abortCode
unsigned long

variable_types:
data
unsigned long

variable_types:
size
unsigned long


CheckWriteSDO

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

if ( (unsigned __int8)getWriteResultNetworkDict(CANOpenShellOD_Data, a2, v3) == 1 )
puts("\nSend data OK");
else
printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", a2, v3[0]);
return closeSDOtransfer(CANOpenShellOD_Data, a2, 2LL);
}

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

if ( (unsigned __int8)getWriteResultNetworkDict(CANOpenShellOD_Data, a2, v3) == 1 )
puts("\nSend data OK");
else
printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", a2, v3[0]);
return closeSDOtransfer(CANOpenShellOD_Data, a2, 2LL);
}

original_code:
void CheckWriteSDO(CO_Data* d, unsigned char nodeid)
{
 unsigned long int abortCode;
 if(getWriteResultNetworkDict(CANOpenShellOD_Data, nodeid, &abortCode) != 0x1)
  printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
 else
  printf("\nSend data OK\n");
 closeSDOtransfer(CANOpenShellOD_Data, nodeid, 0x2);
}

canonical_original_code:
void CheckWriteSDO(struct struct_CO_Data *d, unsigned char nodeid)
{
 unsigned long abortCode;
 if(getWriteResultNetworkDict(CANOpenShellOD_Data, nodeid, &abortCode) != 0x1)
  printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
 else
  printf("\nSend data OK\n");
 closeSDOtransfer(CANOpenShellOD_Data, nodeid, 0x2);
}


Init

decompiled_code:
void **Init()
{
void **result; // rax

result = &Board;
if ( *(&Board + 1) )
result = (void **)setState(CANOpenShellOD_Data, 0LL);
return result;
}

canonical_decompiled_code:
void **func8()
{
void **result; // rax

result = &Board;
if ( *(&Board + 1) )
result = (void **)setState(CANOpenShellOD_Data, 0LL);
return result;
}

original_code:
void Init(CO_Data* d, unsigned long int id)
{
 if(Board.baudrate)
 {
  setState(CANOpenShellOD_Data, Initialisation);
 }
}

canonical_original_code:
void Init(struct struct_CO_Data *d, unsigned long id)
{
 if(Board.baudrate)
 {
  setState(CANOpenShellOD_Data, Initialisation);
 }
}

variable_types:
id
unsigned long


decompiled_code:
void CANOpenShellOD_post_TPDO()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void CANOpenShellOD_post_TPDO(CO_Data* d)
{
}

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


SleepFunction

decompiled_code:
// attributes: thunk
unsigned int SleepFunction(unsigned int seconds)
{
return sleep(seconds);
}

canonical_decompiled_code:
unsigned int func11(unsigned int seconds)
{
return sleep(seconds);
}

original_code:
void SleepFunction(int second)
{
 sleep(second);
}

variable_types: second int


StartNode

decompiled_code:
__int64 __fastcall StartNode(unsigned __int8 a1)
{
return masterSendNMTstateChange(CANOpenShellOD_Data, a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 a1)
{
return masterSendNMTstateChange(CANOpenShellOD_Data, a1, 1LL);
}

original_code:
void StartNode(unsigned char nodeid)
{
 masterSendNMTstateChange(CANOpenShellOD_Data, nodeid, 0x01);
}


StopNode

decompiled_code:
__int64 __fastcall StopNode(unsigned __int8 a1)
{
return masterSendNMTstateChange(CANOpenShellOD_Data, a1, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 a1)
{
return masterSendNMTstateChange(CANOpenShellOD_Data, a1, 2LL);
}

original_code:
void StopNode(unsigned char nodeid)
{
 masterSendNMTstateChange(CANOpenShellOD_Data, nodeid, 0x02);
}


ResetNode

decompiled_code:
__int64 __fastcall ResetNode(unsigned __int8 a1)
{
return masterSendNMTstateChange(CANOpenShellOD_Data, a1, 129LL);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 a1)
{
return masterSendNMTstateChange(CANOpenShellOD_Data, a1, 129LL);
}

original_code:
void ResetNode(unsigned char nodeid)
{
 masterSendNMTstateChange(CANOpenShellOD_Data, nodeid, 0x81);
}


DiscoverNodes

decompiled_code:
__int64 DiscoverNodes()
{
puts("Wait for Slave nodes bootup...\n");
return ResetNode(0);
}

canonical_decompiled_code:
__int64 func15()
{
puts("Wait for Slave nodes bootup...\n");
return func14(0);
}

original_code:
void DiscoverNodes()
{
 printf("Wait for Slave nodes bootup...\n\n");
 ResetNode(0x00);
}


GetSlaveNodeInfo

decompiled_code:
__int64 __fastcall GetSlaveNodeInfo(unsigned __int8 a1)
{
__int64 result; // rax
__int64 v2; // rsi
__int64 v3; // rcx

result = ++get_info_step[0];
switch ( get_info_step[0] )
{
case 0u:
return result;
case 1u:
puts("##################################");
printf("#### Informations for node %x ####\n", a1);
puts("##################################");
return readNetworkDictCallback(CANOpenShellOD_Data, a1, "#### Informations for node %x ####\n", 0LL);
case 2u:
v2 = a1;
v3 = 1LL;
goto LABEL_3;
case 3u:
v2 = a1;
v3 = 2LL;
goto LABEL_3;
case 4u:
v2 = a1;
v3 = 3LL;
LABEL_3:
readNetworkDictCallback(CANOpenShellOD_Data, v2, "de %x ####\n", v3);
result = 0LL;
break;
case 5u:
get_info_step[0] = 0;
break;
default:
JUMPOUT(0x38ELL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int8 a1)
{
__int64 result; // rax
__int64 v2; // rsi
__int64 v3; // rcx

result = ++get_info_step[0];
switch ( get_info_step[0] )
{
case 0u:
return result;
case 1u:
puts("##################################");
printf("#### Informations for node %x ####\n", a1);
puts("##################################");
return readNetworkDictCallback(CANOpenShellOD_Data, a1, "#### Informations for node %x ####\n", 0LL);
case 2u:
v2 = a1;
v3 = 1LL;
goto LABEL_3;
case 3u:
v2 = a1;
v3 = 2LL;
goto LABEL_3;
case 4u:
v2 = a1;
v3 = 3LL;
LABEL_3:
readNetworkDictCallback(CANOpenShellOD_Data, v2, "de %x ####\n", v3);
result = 0LL;
break;
case 5u:
get_info_step[0] = 0;
break;
default:
JUMPOUT(0x38ELL);
}
return result;
}

original_code:
void GetSlaveNodeInfo(unsigned char nodeid)
{
  switch(++get_info_step)
  {
   case 1:
    printf("##################################\n");
    printf("#### Informations for node %x ####\n", nodeid);
    printf("##################################\n");
    readNetworkDictCallback(CANOpenShellOD_Data, nodeid, 0x1000, 0x00, 0, CheckReadInfoSDO, 0);
    break;
   case 2:
    readNetworkDictCallback(CANOpenShellOD_Data, nodeid, 0x1018, 0x01, 0, CheckReadInfoSDO, 0);
    break;
   case 3:
    readNetworkDictCallback(CANOpenShellOD_Data, nodeid, 0x1018, 0x02, 0, CheckReadInfoSDO, 0);
    break;
   case 4:
    readNetworkDictCallback(CANOpenShellOD_Data, nodeid, 0x1018, 0x03, 0, CheckReadInfoSDO, 0);
    break;
   case 5:
    get_info_step = 0;
  }
}


CheckReadInfoSDO

decompiled_code:
__int64 __fastcall CheckReadInfoSDO(__int64 a1, unsigned __int8 a2)
{
__int64 v3; // [rsp+8h] [rbp-30h] BYREF
__int64 v4; // [rsp+10h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+18h] [rbp-20h] BYREF

v4 = 0LL;
v5[0] = 64LL;
if ( (unsigned __int8)getReadResultNetworkDict(CANOpenShellOD_Data, a2, &v4, v5, &v3) == 1 )
{
if ( get_info_step[0] == 3 )
{
printf("Product Code : %x\n", v4);
}
else if ( (int)get_info_step[0] > 3 )
{
if ( get_info_step[0] == 4 )
printf("Revision Number : %x\n", v4);
}
else if ( get_info_step[0] == 1 )
{
printf("Device type : %x\n", v4);
}
else if ( get_info_step[0] == 2 )
{
printf("Vendor ID : %x\n", v4);
}
}
else
{
printf("Master : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", a2, v3);
}
closeSDOtransfer(CANOpenShellOD_Data, a2, 2LL);
return GetSlaveNodeInfo(a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned __int8 a2)
{
__int64 v3; // [rsp+8h] [rbp-30h] BYREF
__int64 v4; // [rsp+10h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+18h] [rbp-20h] BYREF

v4 = 0LL;
v5[0] = 64LL;
if ( (unsigned __int8)getReadResultNetworkDict(CANOpenShellOD_Data, a2, &v4, v5, &v3) == 1 )
{
if ( get_info_step[0] == 3 )
{
printf("Product Code : %x\n", v4);
}
else if ( (int)get_info_step[0] > 3 )
{
if ( get_info_step[0] == 4 )
printf("Revision Number : %x\n", v4);
}
else if ( get_info_step[0] == 1 )
{
printf("Device type : %x\n", v4);
}
else if ( get_info_step[0] == 2 )
{
printf("Vendor ID : %x\n", v4);
}
}
else
{
printf("Master : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", a2, v3);
}
closeSDOtransfer(CANOpenShellOD_Data, a2, 2LL);
return func16(a2);
}

original_code:
void CheckReadInfoSDO(CO_Data* d, unsigned char nodeid)
{
 unsigned long int abortCode;
 unsigned long int data=0;
 unsigned long int size=64;
 if(getReadResultNetworkDict(CANOpenShellOD_Data, nodeid, &data, &size, &abortCode) != 0x1)
  printf("Master : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
 else
 {
  switch(get_info_step)
  {
   case 1:
     printf("Device type     : %x\n", data);
     break;
   case 2:
     printf("Vendor ID       : %x\n", data);
     break;
   case 3:
     printf("Product Code    : %x\n", data);
     break;
   case 4:
     printf("Revision Number : %x\n", data);
     break;
  }
 }
 closeSDOtransfer(CANOpenShellOD_Data, nodeid, 0x2);
 GetSlaveNodeInfo(nodeid);
}

canonical_original_code:
void CheckReadInfoSDO(struct struct_CO_Data *d, unsigned char nodeid)
{
 unsigned long abortCode;
 unsigned long data = 0;
 unsigned long size = 64;
 if(getReadResultNetworkDict(CANOpenShellOD_Data, nodeid, &data, &size, &abortCode) != 0x1)
  printf("Master : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
 else
 {
  switch(get_info_step)
  {
   case 1:
     printf("Device type     : %x\n", data);
     break;
   case 2:
     printf("Vendor ID       : %x\n", data);
     break;
   case 3:
     printf("Product Code    : %x\n", data);
     break;
   case 4:
     printf("Revision Number : %x\n", data);
     break;
  }
 }
 closeSDOtransfer(CANOpenShellOD_Data, nodeid, 0x2);
 GetSlaveNodeInfo(nodeid);
}

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


ReadDeviceEntry

decompiled_code:
int __fastcall ReadDeviceEntry(const char *a1)
{
int v2; // [rsp-10h] [rbp-28h]
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "rsdo#%2x,%4x,%2x", &v3, &v4, &v5) != 3 )
return printf("Wrong command : %s\n", a1);
puts("##################################");
puts("#### Read SDO ####");
puts("##################################");
printf("NodeId : %2.2x\n", v3);
printf("Index : %4.4x\n", v4);
printf("SubIndex : %2.2x\n", v5);
readNetworkDictCallback(
CANOpenShellOD_Data,
(unsigned __int8)v3,
(const char *)(unsigned __int16)v4,
(unsigned __int8)v5,
0LL,
CheckReadSDO,
0LL);
return v2;
}

canonical_decompiled_code:
int __fastcall func18(const char *a1)
{
int v2; // [rsp-10h] [rbp-28h]
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "rsdo#%2x,%4x,%2x", &v3, &v4, &v5) != 3 )
return printf("Wrong command : %s\n", a1);
puts("##################################");
puts("#### Read SDO ####");
puts("##################################");
printf("NodeId : %2.2x\n", v3);
printf("Index : %4.4x\n", v4);
printf("SubIndex : %2.2x\n", v5);
readNetworkDictCallback(
CANOpenShellOD_Data,
(unsigned __int8)v3,
(const char *)(unsigned __int16)v4,
(unsigned __int8)v5,
0LL,
CheckReadSDO,
0LL);
return v2;
}

original_code:
void ReadDeviceEntry(char* sdo)
{
 int ret=0;
 int nodeid;
 int index;
 int subindex;
 int datatype = 0;
 ret = sscanf(sdo, "rsdo#%2x,%4x,%2x", &nodeid, &index, &subindex);
 if (ret == 3)
 {
  printf("##################################\n");
  printf("#### Read SDO                 ####\n");
  printf("##################################\n");
  printf("NodeId   : %2.2x\n", nodeid);
  printf("Index    : %4.4x\n", index);
  printf("SubIndex : %2.2x\n", subindex);
  readNetworkDictCallback(CANOpenShellOD_Data, (unsigned char)nodeid, (unsigned short)index, (unsigned char)subindex, (unsigned char)datatype, CheckReadSDO, 0);
 }
 else
  printf("Wrong command  : %s\n", sdo);
}

canonical_original_code:
void ReadDeviceEntry(char *sdo)
{
 int ret = 0;
 int nodeid;
 int index;
 int subindex;
 int datatype = 0;
 ret = sscanf(sdo, "rsdo#%2x,%4x,%2x", &nodeid, &index, &subindex);
 if (ret == 3)
 {
  printf("##################################\n");
  printf("#### Read SDO                 ####\n");
  printf("##################################\n");
  printf("NodeId   : %2.2x\n", nodeid);
  printf("Index    : %4.4x\n", index);
  printf("SubIndex : %2.2x\n", subindex);
  readNetworkDictCallback(CANOpenShellOD_Data, (unsigned char)nodeid, (unsigned short)index, (unsigned char)subindex, (unsigned char)datatype, CheckReadSDO, 0);
 }
 else
  printf("Wrong command  : %s\n", sdo);
}

variable_types:
sdo
char *

variable_types: ret int

variable_types: nodeid int

variable_types: index int

variable_types: subindex int

variable_types: datatype int


WriteDeviceEntry

decompiled_code:
int __fastcall WriteDeviceEntry(const char *a1)
{
unsigned int v2; // [rsp+14h] [rbp-2Ch] BYREF
unsigned int v3; // [rsp+18h] [rbp-28h] BYREF
unsigned int v4; // [rsp+1Ch] [rbp-24h] BYREF
unsigned int v5; // [rsp+20h] [rbp-20h] BYREF
unsigned int v6[7]; // [rsp+24h] [rbp-1Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "wsdo#%2x,%4x,%2x,%2x,%x", &v2, &v3, &v4, &v5, v6) != 5 )
return printf("Wrong command : %s\n", a1);
puts("##################################");
puts("#### Write SDO ####");
puts("##################################");
printf("NodeId : %2.2x\n", v2);
printf("Index : %4.4x\n", v3);
printf("SubIndex : %2.2x\n", v4);
printf("Size : %2.2x\n", v5);
printf("Data : %x\n", v6[0]);
return writeNetworkDictCallBack(
CANOpenShellOD_Data,
(unsigned __int8)v2,
(unsigned __int16)v3,
(unsigned __int8)v4,
(int)v5,
0LL,
v6,
CheckWriteSDO,
0LL);
}

canonical_decompiled_code:
int __fastcall func19(const char *a1)
{
unsigned int v2; // [rsp+14h] [rbp-2Ch] BYREF
unsigned int v3; // [rsp+18h] [rbp-28h] BYREF
unsigned int v4; // [rsp+1Ch] [rbp-24h] BYREF
unsigned int v5; // [rsp+20h] [rbp-20h] BYREF
unsigned int v6[7]; // [rsp+24h] [rbp-1Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "wsdo#%2x,%4x,%2x,%2x,%x", &v2, &v3, &v4, &v5, v6) != 5 )
return printf("Wrong command : %s\n", a1);
puts("##################################");
puts("#### Write SDO ####");
puts("##################################");
printf("NodeId : %2.2x\n", v2);
printf("Index : %4.4x\n", v3);
printf("SubIndex : %2.2x\n", v4);
printf("Size : %2.2x\n", v5);
printf("Data : %x\n", v6[0]);
return writeNetworkDictCallBack(
CANOpenShellOD_Data,
(unsigned __int8)v2,
(unsigned __int16)v3,
(unsigned __int8)v4,
(int)v5,
0LL,
v6,
CheckWriteSDO,
0LL);
}

original_code:
void WriteDeviceEntry(char* sdo)
{
 int ret=0;
 int nodeid;
 int index;
 int subindex;
 int size;
 int data;
 ret = sscanf(sdo, "wsdo#%2x,%4x,%2x,%2x,%x", &nodeid , &index, &subindex, &size, &data);
 if (ret == 5)
 {
  printf("##################################\n");
  printf("#### Write SDO                ####\n");
  printf("##################################\n");
  printf("NodeId   : %2.2x\n", nodeid);
  printf("Index    : %4.4x\n", index);
  printf("SubIndex : %2.2x\n", subindex);
  printf("Size     : %2.2x\n", size);
  printf("Data     : %x\n", data);
  writeNetworkDictCallBack(CANOpenShellOD_Data, nodeid, index, subindex, size, 0, &data, CheckWriteSDO, 0);
 }
 else
  printf("Wrong command  : %s\n", sdo);
}

canonical_original_code:
void WriteDeviceEntry(char *sdo)
{
 int ret = 0;
 int nodeid;
 int index;
 int subindex;
 int size;
 int data;
 ret = sscanf(sdo, "wsdo#%2x,%4x,%2x,%2x,%x", &nodeid , &index, &subindex, &size, &data);
 if (ret == 5)
 {
  printf("##################################\n");
  printf("#### Write SDO                ####\n");
  printf("##################################\n");
  printf("NodeId   : %2.2x\n", nodeid);
  printf("Index    : %4.4x\n", index);
  printf("SubIndex : %2.2x\n", subindex);
  printf("Size     : %2.2x\n", size);
  printf("Data     : %x\n", data);
  writeNetworkDictCallBack(CANOpenShellOD_Data, nodeid, index, subindex, size, 0, &data, CheckWriteSDO, 0);
 }
 else
  printf("Wrong command  : %s\n", sdo);
}

variable_types: size int

variable_types: data int


NodeInit

decompiled_code:
__int64 __fastcall NodeInit(unsigned __int8 a1, int a2)
{
void *v2; // rax
_QWORD *v3; // rsi

if ( a2 )
v2 = &CANOpenShellMasterOD_Data;
else
v2 = &CANOpenShellSlaveOD_Data;
CANOpenShellOD_Data = v2;
LoadCanDriver(&LibraryPath);
v3 = (_QWORD *)CANOpenShellOD_Data;
*(_QWORD *)(CANOpenShellOD_Data + 576LL) = CANOpenShellOD_initialisation;
v3[73] = CANOpenShellOD_preOperational;
v3[74] = CANOpenShellOD_operational;
v3[75] = CANOpenShellOD_stopped;
v3[171] = CANOpenShellOD_post_sync_localalias;
v3[172] = CANOpenShellOD_post_TPDO;
v3[173] = CANOpenShellOD_post_SlaveBootup;
if ( !canOpen(&Board) )
return 2LL;
setNodeId(CANOpenShellOD_Data, a1);
StartTimerLoop(Init);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned __int8 a1, int a2)
{
void *v2; // rax
_QWORD *v3; // rsi

if ( a2 )
v2 = &CANOpenShellMasterOD_Data;
else
v2 = &CANOpenShellSlaveOD_Data;
CANOpenShellOD_Data = v2;
LoadCanDriver(&LibraryPath);
v3 = (_QWORD *)CANOpenShellOD_Data;
*(_QWORD *)(CANOpenShellOD_Data + 576LL) = CANOpenShellOD_initialisation;
v3[73] = CANOpenShellOD_preOperational;
v3[74] = CANOpenShellOD_operational;
v3[75] = CANOpenShellOD_stopped;
v3[171] = CANOpenShellOD_post_sync_localalias;
v3[172] = CANOpenShellOD_post_TPDO;
v3[173] = CANOpenShellOD_post_SlaveBootup;
if ( !canOpen(&Board) )
return 2LL;
setNodeId(CANOpenShellOD_Data, a1);
StartTimerLoop(Init);
return 0LL;
}

original_code:
int NodeInit(int NodeID, int NodeType)
{
 if(NodeType)
  CANOpenShellOD_Data = &CANOpenShellMasterOD_Data;
 else
  CANOpenShellOD_Data = &CANOpenShellSlaveOD_Data;
 LoadCanDriver(LibraryPath);
 CANOpenShellOD_Data->initialisation = CANOpenShellOD_initialisation;
 CANOpenShellOD_Data->preOperational = CANOpenShellOD_preOperational;
 CANOpenShellOD_Data->operational = CANOpenShellOD_operational;
 CANOpenShellOD_Data->stopped = CANOpenShellOD_stopped;
 CANOpenShellOD_Data->post_sync = CANOpenShellOD_post_sync;
 CANOpenShellOD_Data->post_TPDO = CANOpenShellOD_post_TPDO;
 CANOpenShellOD_Data->post_SlaveBootup=CANOpenShellOD_post_SlaveBootup;
 if(!canOpen(&Board,CANOpenShellOD_Data)) return 2;
 setNodeId(CANOpenShellOD_Data, NodeID);
 StartTimerLoop(&Init);
 return 0;
}

variable_types: NodeID int

variable_types: NodeType int


decompiled_code:
int help_menu()
{
puts(" MANDATORY COMMAND (must be the first command):");
puts(" load#CanLibraryPath,channel,baudrate,nodeid,type (0:slave, 1:master)");
putchar(10);
puts(" NETWORK: (if nodeid=0x00 : broadcast)");
puts(" ssta#nodeid : Start a node");
puts(" ssto#nodeid : Stop a node");
puts(" srst#nodeid : Reset a node");
puts(" scan : Reset all nodes and print message when bootup");
puts(" wait#seconds : Sleep for n seconds");
putchar(10);
puts(" SDO: (size in bytes)");
puts(" info#nodeid");
puts(" rsdo#nodeid,index,subindex : read sdo");
puts(" ex : rsdo#42,1018,01");
puts(" wsdo#nodeid,index,subindex,size,data : write sdo");
puts(" ex : wsdo#42,6200,01,01,FF");
putchar(10);
puts(" Note: All numbers are hex");
putchar(10);
puts(" help : Display this menu");
puts(" quit : Quit application");
putchar(10);
return putchar(10);
}

canonical_decompiled_code:
int func21()
{
puts(" MANDATORY COMMAND (must be the first command):");
puts(" load#CanLibraryPath,channel,baudrate,nodeid,type (0:slave, 1:master)");
putchar(10);
puts(" NETWORK: (if nodeid=0x00 : broadcast)");
puts(" ssta#nodeid : Start a node");
puts(" ssto#nodeid : Stop a node");
puts(" srst#nodeid : Reset a node");
puts(" scan : Reset all nodes and print message when bootup");
puts(" wait#seconds : Sleep for n seconds");
putchar(10);
puts(" SDO: (size in bytes)");
puts(" info#nodeid");
puts(" rsdo#nodeid,index,subindex : read sdo");
puts(" ex : rsdo#42,1018,01");
puts(" wsdo#nodeid,index,subindex,size,data : write sdo");
puts(" ex : wsdo#42,6200,01,01,FF");
putchar(10);
puts(" Note: All numbers are hex");
putchar(10);
puts(" help : Display this menu");
puts(" quit : Quit application");
putchar(10);
return putchar(10);
}

original_code:
void help_menu(void)
{
 printf("   MANDATORY COMMAND (must be the first command):\n");
 printf("     load#CanLibraryPath,channel,baudrate,nodeid,type (0:slave, 1:master)\n");
 printf("\n");
 printf("   NETWORK: (if nodeid=0x00 : broadcast)\n");
 printf("     ssta#nodeid : Start a node\n");
 printf("     ssto#nodeid : Stop a node\n");
 printf("     srst#nodeid : Reset a node\n");
 printf("     scan : Reset all nodes and print message when bootup\n");
 printf("     wait#seconds : Sleep for n seconds\n");
 printf("\n");
 printf("   SDO: (size in bytes)\n");
 printf("     info#nodeid\n");
 printf("     rsdo#nodeid,index,subindex : read sdo\n");
 printf("        ex : rsdo#42,1018,01\n");
 printf("     wsdo#nodeid,index,subindex,size,data : write sdo\n");
 printf("        ex : wsdo#42,6200,01,01,FF\n");
 printf("\n");
 printf("   Note: All numbers are hex\n");
 printf("\n");
 printf("     help : Display this menu\n");
 printf("     quit : Quit application\n");
 printf("\n");
 printf("\n");
}

canonical_original_code:
void help_menu()
{
 printf("   MANDATORY COMMAND (must be the first command):\n");
 printf("     load#CanLibraryPath,channel,baudrate,nodeid,type (0:slave, 1:master)\n");
 printf("\n");
 printf("   NETWORK: (if nodeid=0x00 : broadcast)\n");
 printf("     ssta#nodeid : Start a node\n");
 printf("     ssto#nodeid : Stop a node\n");
 printf("     srst#nodeid : Reset a node\n");
 printf("     scan : Reset all nodes and print message when bootup\n");
 printf("     wait#seconds : Sleep for n seconds\n");
 printf("\n");
 printf("   SDO: (size in bytes)\n");
 printf("     info#nodeid\n");
 printf("     rsdo#nodeid,index,subindex : read sdo\n");
 printf("        ex : rsdo#42,1018,01\n");
 printf("     wsdo#nodeid,index,subindex,size,data : write sdo\n");
 printf("        ex : wsdo#42,6200,01,01,FF\n");
 printf("\n");
 printf("   Note: All numbers are hex\n");
 printf("\n");
 printf("     help : Display this menu\n");
 printf("     quit : Quit application\n");
 printf("\n");
 printf("\n");
}


ExtractNodeId

decompiled_code:
__int64 __fastcall ExtractNodeId(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, "%2x", &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, "%2x", &v2);
return v2;
}

original_code:
int ExtractNodeId(char *command) {
 int nodeid;
 sscanf(command, "%2x", &nodeid);
 return nodeid;
}

variable_types:
command
char *


ProcessCommand

decompiled_code:
__int64 __fastcall ProcessCommand(const char *a1, const char *a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 result; // rax
unsigned __int8 v5; // al
unsigned __int8 v6; // al
unsigned __int8 v7; // al
unsigned __int8 v8; // al
__int64 v9; // [rsp-10h] [rbp-28h]
unsigned int seconds; // [rsp+4h] [rbp-14h] BYREF
int v11; // [rsp+8h] [rbp-10h] BYREF
int v12; // [rsp+Ch] [rbp-Ch] BYREF

seconds = 0;
EnterMutex();
v2 = *a1 | ((a1[1] | ((a1[2] | (a1[3] << 8)) << 8)) << 8);
if ( v2 == 1868983913 )
{
v8 = ExtractNodeId((__int64)(a1 + 5));
a1 = (const char *)v8;
GetSlaveNodeInfo(v8);
goto LABEL_8;
}
if ( v2 > 0x6F666E69 )
{
if ( v2 == 1953068401 )
{
((void (*)(void))LeaveMutex)();
result = 1LL;
}
else
{
if ( v2 > 0x74697571 )
{
if ( v2 == 1953722995 )
{
v5 = ExtractNodeId((__int64)(a1 + 5));
a1 = (const char *)v5;
ResetNode(v5);
goto LABEL_8;
}
LABEL_21:
help_menu();
goto LABEL_8;
}
if ( v2 == 1869902707 )
{
v7 = ExtractNodeId((__int64)(a1 + 5));
a1 = (const char *)v7;
StopNode(v7);
goto LABEL_8;
}
if ( v2 != 1953063287 )
goto LABEL_21;
a2 = "wait#%d";
if ( (unsigned int)_isoc99_sscanf(a1, "wait#%d", &seconds) != 1 )
goto LABEL_8;
((void (*)(void))LeaveMutex)();
SleepFunction(seconds);
result = 0LL;
}
}
else
{
if ( v2 == 1851876211 )
{
DiscoverNodes();
goto LABEL_8;
}
if ( v2 > 0x6E616373 )
{
if ( v2 == 1868854130 )
{
ReadDeviceEntry(a1);
goto LABEL_8;
}
if ( v2 == 1868854135 )
{
WriteDeviceEntry(a1);
LABEL_8:
LeaveMutex(a1, a2, v3);
return 0LL;
}
goto LABEL_21;
}
if ( v2 == 1635021683 )
{
v6 = ExtractNodeId((__int64)(a1 + 5));
a1 = (const char *)v6;
StartNode(v6);
goto LABEL_8;
}
if ( v2 != 1684107116 )
goto LABEL_21;
a2 = "load#%100[^,],%30[^,],%4[^,],%d,%d";
if ( (unsigned int)_isoc99_sscanf(
a1,
"load#%100[^,],%30[^,],%4[^,],%d,%d",
&LibraryPath,
&BoardBusName,
&BoardBaudRate,
&v11,
&v12) != 5 )
{
a1 = "Invalid load parameters";
puts("Invalid load parameters");
goto LABEL_8;
}
LeaveMutex(a1, "load#%100[^,],%30[^,],%4[^,],%d,%d", v9);
result = NodeInit(v11, v12);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(const char *a1, const char *a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 result; // rax
unsigned __int8 v5; // al
unsigned __int8 v6; // al
unsigned __int8 v7; // al
unsigned __int8 v8; // al
__int64 v9; // [rsp-10h] [rbp-28h]
unsigned int seconds; // [rsp+4h] [rbp-14h] BYREF
int v11; // [rsp+8h] [rbp-10h] BYREF
int v12; // [rsp+Ch] [rbp-Ch] BYREF

seconds = 0;
EnterMutex();
v2 = *a1 | ((a1[1] | ((a1[2] | (a1[3] << 8)) << 8)) << 8);
if ( v2 == 1868983913 )
{
v8 = func22((__int64)(a1 + 5));
a1 = (const char *)v8;
func16(v8);
goto LABEL_8;
}
if ( v2 > 0x6F666E69 )
{
if ( v2 == 1953068401 )
{
((void (*)(void))LeaveMutex)();
result = 1LL;
}
else
{
if ( v2 > 0x74697571 )
{
if ( v2 == 1953722995 )
{
v5 = func22((__int64)(a1 + 5));
a1 = (const char *)v5;
func14(v5);
goto LABEL_8;
}
LABEL_21:
func21();
goto LABEL_8;
}
if ( v2 == 1869902707 )
{
v7 = func22((__int64)(a1 + 5));
a1 = (const char *)v7;
func13(v7);
goto LABEL_8;
}
if ( v2 != 1953063287 )
goto LABEL_21;
a2 = "wait#%d";
if ( (unsigned int)_isoc99_sscanf(a1, "wait#%d", &seconds) != 1 )
goto LABEL_8;
((void (*)(void))LeaveMutex)();
func11(seconds);
result = 0LL;
}
}
else
{
if ( v2 == 1851876211 )
{
func15();
goto LABEL_8;
}
if ( v2 > 0x6E616373 )
{
if ( v2 == 1868854130 )
{
func18(a1);
goto LABEL_8;
}
if ( v2 == 1868854135 )
{
func19(a1);
LABEL_8:
LeaveMutex(a1, a2, v3);
return 0LL;
}
goto LABEL_21;
}
if ( v2 == 1635021683 )
{
v6 = func22((__int64)(a1 + 5));
a1 = (const char *)v6;
func12(v6);
goto LABEL_8;
}
if ( v2 != 1684107116 )
goto LABEL_21;
a2 = "load#%100[^,],%30[^,],%4[^,],%d,%d";
if ( (unsigned int)_isoc99_sscanf(
a1,
"load#%100[^,],%30[^,],%4[^,],%d,%d",
&LibraryPath,
&BoardBusName,
&BoardBaudRate,
&v11,
&v12) != 5 )
{
a1 = "Invalid load parameters";
puts("Invalid load parameters");
goto LABEL_8;
}
LeaveMutex(a1, "load#%100[^,],%30[^,],%4[^,],%d,%d", v9);
result = func20(v11, v12);
}
return result;
}

original_code:
int ProcessCommand(char* command)
{
 int ret = 0;
 int sec = 0;
 int NodeID;
 int NodeType;
 EnterMutex();
 switch(((((unsigned int)0 | (char)command[3] << 8) | (char)command[2]) << 8 | (char)command[1]) << 8 | (char)command[0])
 {
  case ((((unsigned int)0 | (char)'p' << 8) | (char)'l') << 8 | (char)'e') << 8 | (char)'h' :
     help_menu();
     break;
  case ((((unsigned int)0 | (char)'a' << 8) | (char)'t') << 8 | (char)'s') << 8 | (char)'s' :
     StartNode(ExtractNodeId(command + 5));
     break;
  case ((((unsigned int)0 | (char)'o' << 8) | (char)'t') << 8 | (char)'s') << 8 | (char)'s' :
     StopNode(ExtractNodeId(command + 5));
     break;
  case ((((unsigned int)0 | (char)'t' << 8) | (char)'s') << 8 | (char)'r') << 8 | (char)'s' :
     ResetNode(ExtractNodeId(command + 5));
     break;
  case ((((unsigned int)0 | (char)'o' << 8) | (char)'f') << 8 | (char)'n') << 8 | (char)'i' :
     GetSlaveNodeInfo(ExtractNodeId(command + 5));
     break;
  case ((((unsigned int)0 | (char)'o' << 8) | (char)'d') << 8 | (char)'s') << 8 | (char)'r' :
     ReadDeviceEntry(command);
     break;
  case ((((unsigned int)0 | (char)'o' << 8) | (char)'d') << 8 | (char)'s') << 8 | (char)'w' :
     WriteDeviceEntry(command);
     break;
  case ((((unsigned int)0 | (char)'n' << 8) | (char)'a') << 8 | (char)'c') << 8 | (char)'s' :
     DiscoverNodes();
     break;
  case ((((unsigned int)0 | (char)'t' << 8) | (char)'i') << 8 | (char)'a') << 8 | (char)'w' :
     ret = sscanf(command, "wait#%d", &sec);
     if(ret == 1) {
      LeaveMutex();
      SleepFunction(sec);
      return 0;
     }
     break;
  case ((((unsigned int)0 | (char)'t' << 8) | (char)'i') << 8 | (char)'u') << 8 | (char)'q' :
     LeaveMutex();
     return 1;
  case ((((unsigned int)0 | (char)'d' << 8) | (char)'a') << 8 | (char)'o') << 8 | (char)'l' :
     ret = sscanf(command, "load#%100[^,],%30[^,],%4[^,],%d,%d",
       LibraryPath,
       BoardBusName,
       BoardBaudRate,
       &NodeID,
       &NodeType);
     if(ret == 5)
     {
      LeaveMutex();
      ret = NodeInit(NodeID, NodeType);
      return ret;
     }
     else
     {
      printf("Invalid load parameters\n");
     }
     break;
  default :
     help_menu();
 }
 LeaveMutex();
 return 0;
}

canonical_original_code:
int ProcessCommand(char *command)
{
 int ret = 0;
 int sec = 0;
 int NodeID;
 int NodeType;
 EnterMutex();
 switch(((((unsigned int)0 | (char)command[3] << 8) | (char)command[2]) << 8 | (char)command[1]) << 8 | (char)command[0])
 {
  case ((((unsigned int)0 | (char)'p' << 8) | (char)'l') << 8 | (char)'e') << 8 | (char)'h' :
     help_menu();
     break;
  case ((((unsigned int)0 | (char)'a' << 8) | (char)'t') << 8 | (char)'s') << 8 | (char)'s' :
     StartNode(ExtractNodeId(command + 5));
     break;
  case ((((unsigned int)0 | (char)'o' << 8) | (char)'t') << 8 | (char)'s') << 8 | (char)'s' :
     StopNode(ExtractNodeId(command + 5));
     break;
  case ((((unsigned int)0 | (char)'t' << 8) | (char)'s') << 8 | (char)'r') << 8 | (char)'s' :
     ResetNode(ExtractNodeId(command + 5));
     break;
  case ((((unsigned int)0 | (char)'o' << 8) | (char)'f') << 8 | (char)'n') << 8 | (char)'i' :
     GetSlaveNodeInfo(ExtractNodeId(command + 5));
     break;
  case ((((unsigned int)0 | (char)'o' << 8) | (char)'d') << 8 | (char)'s') << 8 | (char)'r' :
     ReadDeviceEntry(command);
     break;
  case ((((unsigned int)0 | (char)'o' << 8) | (char)'d') << 8 | (char)'s') << 8 | (char)'w' :
     WriteDeviceEntry(command);
     break;
  case ((((unsigned int)0 | (char)'n' << 8) | (char)'a') << 8 | (char)'c') << 8 | (char)'s' :
     DiscoverNodes();
     break;
  case ((((unsigned int)0 | (char)'t' << 8) | (char)'i') << 8 | (char)'a') << 8 | (char)'w' :
     ret = sscanf(command, "wait#%d", &sec);
     if(ret == 1) {
      LeaveMutex();
      SleepFunction(sec);
      return 0;
     }
     break;
  case ((((unsigned int)0 | (char)'t' << 8) | (char)'i') << 8 | (char)'u') << 8 | (char)'q' :
     LeaveMutex();
     return 1;
  case ((((unsigned int)0 | (char)'d' << 8) | (char)'a') << 8 | (char)'o') << 8 | (char)'l' :
     ret = sscanf(command, "load#%100[^,],%30[^,],%4[^,],%d,%d",
       LibraryPath,
       BoardBusName,
       BoardBaudRate,
       &NodeID,
       &NodeType);
     if(ret == 5)
     {
      LeaveMutex();
      ret = NodeInit(NodeID, NodeType);
      return ret;
     }
     else
     {
      printf("Invalid load parameters\n");
     }
     break;
  default :
     help_menu();
 }
 LeaveMutex();
 return 0;
}

variable_types: sec int


Exit

decompiled_code:
char Exit()
{
bool v0; // zf
char result; // al

v0 = strcmp((const char *)*(&Board + 1), "none") == 0;
result = !v0;
if ( !v0 )
{
masterSendNMTstateChange(CANOpenShellOD_Data, 0LL, 129LL);
result = setState(CANOpenShellOD_Data, 4LL);
}
return result;
}

canonical_decompiled_code:
char func9()
{
bool v0; // zf
char result; // al

v0 = strcmp((const char *)*(&Board + 1), "none") == 0;
result = !v0;
if ( !v0 )
{
masterSendNMTstateChange(CANOpenShellOD_Data, 0LL, 129LL);
result = setState(CANOpenShellOD_Data, 4LL);
}
return result;
}

original_code:
void Exit(CO_Data* d, unsigned long int nodeid)
{
 if(strcmp(Board.baudrate, "none"))
 {
  masterSendNMTstateChange(CANOpenShellOD_Data, 0 , 0x81);
  setState(CANOpenShellOD_Data, Stopped);
 }
}

canonical_original_code:
void Exit(struct struct_CO_Data *d, unsigned long nodeid)
{
 if(strcmp(Board.baudrate, "none"))
 {
  masterSendNMTstateChange(CANOpenShellOD_Data, 0 , 0x81);
  setState(CANOpenShellOD_Data, Stopped);
 }
}

variable_types:
nodeid
unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int v4; // ebx
char v6[248]; // [rsp+0h] [rbp-F8h] BYREF

if ( argc <= 1 )
{
help_menu();
exit(1);
}
TimerInit(argc, argv, envp);
v3 = argv + 1;
while ( (unsigned int)ProcessCommand(*v3, (const char *)argv) != 2 )
{
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
{
do
{
fgets(v6, 200, stdin);
system("clear");
v4 = ProcessCommand(v6, (const char *)&loc_C8);
fflush(stdout);
}
while ( v4 != 1 );
puts("Finishing.");
StopTimerLoop(Exit);
canClose(CANOpenShellOD_Data);
break;
}
}
TimerCleanup();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int v4; // ebx
char v6[248]; // [rsp+0h] [rbp-F8h] BYREF

if ( argc <= 1 )
{
func21();
exit(1);
}
TimerInit(argc, argv, envp);
v3 = argv + 1;
while ( (unsigned int)func23(*v3, (const char *)argv) != 2 )
{
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
{
do
{
fgets(v6, 200, stdin);
system("clear");
v4 = func23(v6, (const char *)&loc_C8);
fflush(stdout);
}
while ( v4 != 1 );
puts("Finishing.");
StopTimerLoop(Exit);
canClose(CANOpenShellOD_Data);
break;
}
}
TimerCleanup();
return 0;
}

original_code:
int main(int argc, char** argv)
{
 extern char *optarg;
 char command[200];
 char* res;
 int ret=0;
 int sysret=0;
 int i=0;
 if(argc < 2)
 {
  help_menu();
  exit(1);
 }
 TimerInit();
 for(i=1 ; i<argc ; i++)
 {
  if(ProcessCommand(argv[i]) == 2) goto init_fail;
 }
 while(ret != 1)
 {
  res = fgets(command, sizeof(command), stdin);
  sysret = system("clear");
  ret = ProcessCommand(command);
  fflush(stdout);
 }
 printf("Finishing.\n");
 StopTimerLoop(&Exit);
 canClose(CANOpenShellOD_Data);
init_fail:
 TimerCleanup();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 extern char *optarg;
 char command[200];
 char *res;
 int ret = 0;
 int sysret = 0;
 int i = 0;
 if(argc < 2)
 {
  help_menu();
  exit(1);
 }
 TimerInit();
 for(i=1 ; i<argc ; i++)
 {
  if(ProcessCommand(argv[i]) == 2) goto init_fail;
 }
 while(ret != 1)
 {
  res = fgets(command, sizeof(command), stdin);
  sysret = system("clear");
  ret = ProcessCommand(command);
  fflush(stdout);
 }
 printf("Finishing.\n");
 StopTimerLoop(&Exit);
 canClose(CANOpenShellOD_Data);
init_fail:
 TimerCleanup();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
optarg
char *

variable_types:
command
char [200]

variable_types:
res
char *

variable_types: sysret int

variable_types: i int


decompiled_code:
void *__fastcall unixtimer_canReceiveLoop(void *a1)
{
unixtimer_ReceiveLoop_task_proc(a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
unixtimer_ReceiveLoop_task_proc(a1);
return 0LL;
}

original_code:
void* unixtimer_canReceiveLoop(void* port)
{
    unixtimer_ReceiveLoop_task_proc((CAN_PORT)port);
    return ((void *)0);
}

canonical_original_code:
void *unixtimer_canReceiveLoop(void *port)
{
    unixtimer_ReceiveLoop_task_proc((void *)port);
    return ((void *)0);
}

variable_types:
port
void *


TimerCleanup

decompiled_code:
void TimerCleanup()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void TimerCleanup(void)
{
}

canonical_original_code:
void TimerCleanup()
{
}


EnterMutex

decompiled_code:
int EnterMutex()
{
int result; // eax

result = pthread_mutex_lock(&CanFestival_mutex);
if ( result )
result = fwrite("pthread_mutex_lock() failed\n", 1uLL, 0x1CuLL, stderr);
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

result = pthread_mutex_lock(&CanFestival_mutex);
if ( result )
result = fwrite("pthread_mutex_lock() failed\n", 1uLL, 0x1CuLL, stderr);
return result;
}

original_code:
void EnterMutex(void)
{
 if(pthread_mutex_lock(&CanFestival_mutex)) {
  fprintf(stderr, "pthread_mutex_lock() failed\n");
 }
}

canonical_original_code:
void EnterMutex()
{
 if(pthread_mutex_lock(&CanFestival_mutex)) {
  fprintf(stderr, "pthread_mutex_lock() failed\n");
 }
}


LeaveMutex

decompiled_code:
int LeaveMutex()
{
int result; // eax

result = pthread_mutex_unlock(&CanFestival_mutex);
if ( result )
result = fwrite("pthread_mutex_unlock() failed\n", 1uLL, 0x1EuLL, stderr);
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

result = pthread_mutex_unlock(&CanFestival_mutex);
if ( result )
result = fwrite("pthread_mutex_unlock() failed\n", 1uLL, 0x1EuLL, stderr);
return result;
}

original_code:
void LeaveMutex(void)
{
 if(pthread_mutex_unlock(&CanFestival_mutex)) {
  fprintf(stderr, "pthread_mutex_unlock() failed\n");
 }
}

canonical_original_code:
void LeaveMutex()
{
 if(pthread_mutex_unlock(&CanFestival_mutex)) {
  fprintf(stderr, "pthread_mutex_unlock() failed\n");
 }
}


decompiled_code:
int timer_notify()
{
if ( gettimeofday(&last_sig, 0LL) )
perror("gettimeofday()");
EnterMutex();
TimeDispatch();
return LeaveMutex();
}

canonical_decompiled_code:
int func4()
{
if ( gettimeofday(&last_sig, 0LL) )
perror("gettimeofday()");
func2();
TimeDispatch();
return func3();
}

original_code:
void timer_notify(sigval_t val)
{
 if(gettimeofday(&last_sig,((void *)0))) {
  perror("gettimeofday()");
 }
 EnterMutex();
 TimeDispatch();
 LeaveMutex();
}

canonical_original_code:
void timer_notify(union sigval val)
{
 if(gettimeofday(&last_sig,((void *)0))) {
  perror("gettimeofday()");
 }
 EnterMutex();
 TimeDispatch();
 LeaveMutex();
}

variable_types: union sigval { int sival_int; void *sival_ptr; }


TimerInit

decompiled_code:
void TimerInit()
{
struct sigevent v0; // [rsp+0h] [rbp-48h] BYREF

if ( gettimeofday(&last_sig, 0LL) )
perror("gettimeofday()");
*(_OWORD *)&v0.sigev_value.sival_int = 0LL;
v0._sigev_un._sigev_thread._attribute = 0LL;
v0.sigev_notify = 2;
v0._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_notify;
*((_OWORD *)&v0._sigev_un._sigev_thread + 1) = 0LL;
*((_OWORD *)&v0._sigev_un._sigev_thread + 2) = 0LL;
if ( timer_create(0, &v0, &timer) )
perror("timer_create()");
}

canonical_decompiled_code:
void func5()
{
struct sigevent v0; // [rsp+0h] [rbp-48h] BYREF

if ( gettimeofday(&last_sig, 0LL) )
perror("gettimeofday()");
*(_OWORD *)&v0.sigev_value.sival_int = 0LL;
v0._sigev_un._sigev_thread._attribute = 0LL;
v0.sigev_notify = 2;
v0._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_notify;
*((_OWORD *)&v0._sigev_un._sigev_thread + 1) = 0LL;
*((_OWORD *)&v0._sigev_un._sigev_thread + 2) = 0LL;
if ( timer_create(0, &v0, &timer) )
perror("timer_create()");
}

original_code:
void TimerInit(void)
{
 struct sigevent sigev;
 if(gettimeofday(&last_sig,((void *)0))){
  perror("gettimeofday()");
 }
 memset (&sigev, 0, sizeof (struct sigevent));
 sigev.sigev_value.sival_int = 0;
 sigev.sigev_notify = SIGEV_THREAD;
 sigev._sigev_un._sigev_thread._attribute = ((void *)0);
 sigev._sigev_un._sigev_thread._function = timer_notify;
 if(timer_create (0, &sigev, &timer)) {
  perror("timer_create()");
 }
}

canonical_original_code:
void TimerInit()
{
 struct sigevent sigev;
 if(gettimeofday(&last_sig,((void *)0))){
  perror("gettimeofday()");
 }
 memset (&sigev, 0, sizeof (struct sigevent));
 sigev.sigev_value.sival_int = 0;
 sigev.sigev_notify = SIGEV_THREAD;
 sigev._sigev_un._sigev_thread._attribute = ((void *)0);
 sigev._sigev_un._sigev_thread._function = timer_notify;
 if(timer_create (0, &sigev, &timer)) {
  perror("timer_create()");
 }
}

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }


StopTimerLoop

decompiled_code:
int __fastcall StopTimerLoop(void (__fastcall *a1)(_QWORD, _QWORD))
{
EnterMutex();
if ( timer_delete(timer) )
perror("timer_delete()");
a1(0LL, 0LL);
return LeaveMutex();
}

canonical_decompiled_code:
int __fastcall func6(void (__fastcall *a1)(_QWORD, _QWORD))
{
func2();
if ( timer_delete(timer) )
perror("timer_delete()");
a1(0LL, 0LL);
return func3();
}

original_code:
void StopTimerLoop(TimerCallback_t exitfunction)
{
 EnterMutex();
 if(timer_delete (timer)) {
  perror("timer_delete()");
 }
 exitfunction(((void *)0),0);
 LeaveMutex();
}

canonical_original_code:
void StopTimerLoop(void (*exitfunction)(struct struct_CO_Data *d, unsigned long id))
{
 EnterMutex();
 if(timer_delete (timer)) {
  perror("timer_delete()");
 }
 exitfunction(((void *)0),0);
 LeaveMutex();
}

variable_types: void (*)(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, unsigned long id)


StartTimerLoop

decompiled_code:
int __fastcall StartTimerLoop(__int64 a1)
{
EnterMutex();
SetAlarm(0LL, 0LL, a1, 0LL, 0LL);
return LeaveMutex();
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
func2();
SetAlarm(0LL, 0LL, a1, 0LL, 0LL);
return func3();
}

original_code:
void StartTimerLoop(TimerCallback_t init_callback)
{
 EnterMutex();
 SetAlarm(((void *)0), 0, init_callback, 0, 0);
 LeaveMutex();
}

canonical_original_code:
void StartTimerLoop(void (*init_callback)(struct struct_CO_Data *d, unsigned long id))
{
 EnterMutex();
 SetAlarm(((void *)0), 0, init_callback, 0, 0);
 LeaveMutex();
}


decompiled_code:
void canReceiveLoop_signal()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void canReceiveLoop_signal(int sig)
{
}

canonical_original_code:
void canReceiveLoop_signal(int sig)
{
}

variable_types: sig int


CreateReceiveTask

decompiled_code:
void __fastcall CreateReceiveTask(void *arg, pthread_t *newthread, __int64 (__fastcall *a3)(_QWORD))
{
unixtimer_ReceiveLoop_task_proc = a3;
if ( pthread_create(newthread, 0LL, unixtimer_canReceiveLoop, arg) )
perror("pthread_create()");
}

canonical_decompiled_code:
void __fastcall func9(void *arg, pthread_t *newthread, __int64 (__fastcall *a3)(_QWORD))
{
unixtimer_ReceiveLoop_task_proc = a3;
if ( pthread_create(newthread, 0LL, unixtimer_canReceiveLoop, arg) )
perror("pthread_create()");
}

original_code:
void CreateReceiveTask(CAN_PORT port, void** Thread, void* ReceiveLoopPtr)
{
    unixtimer_ReceiveLoop_task_proc = ReceiveLoopPtr;
 if(pthread_create(Thread, ((void *)0), unixtimer_canReceiveLoop, (void*)port)) {
  perror("pthread_create()");
 }
}

canonical_original_code:
void CreateReceiveTask(void *port, void **Thread, void *ReceiveLoopPtr)
{
    unixtimer_ReceiveLoop_task_proc = ReceiveLoopPtr;
 if(pthread_create(Thread, ((void *)0), unixtimer_canReceiveLoop, (void *)port)) {
  perror("pthread_create()");
 }
}

variable_types:
Thread
void **

variable_types:
ReceiveLoopPtr
void *


WaitReceiveTaskEnd

decompiled_code:
void __fastcall WaitReceiveTaskEnd(pthread_t *a1)
{
if ( !pthread_kill(*a1, 15) )
{
if ( !pthread_join(*a1, 0LL) )
return;
LABEL_5:
perror("pthread_join()");
return;
}
perror("pthread_kill()");
if ( pthread_join(*a1, 0LL) )
goto LABEL_5;
}

canonical_decompiled_code:
void __fastcall func10(pthread_t *a1)
{
if ( !pthread_kill(*a1, 15) )
{
if ( !pthread_join(*a1, 0LL) )
return;
LABEL_5:
perror("pthread_join()");
return;
}
perror("pthread_kill()");
if ( pthread_join(*a1, 0LL) )
goto LABEL_5;
}

original_code:
void WaitReceiveTaskEnd(void* *Thread)
{
 if(pthread_kill(*Thread, 15)) {
  perror("pthread_kill()");
 }
 if(pthread_join(*Thread, ((void *)0))) {
  perror("pthread_join()");
 }
}

canonical_original_code:
void WaitReceiveTaskEnd(void **Thread)
{
 if(pthread_kill(*Thread, 15)) {
  perror("pthread_kill()");
 }
 if(pthread_join(*Thread, ((void *)0))) {
  perror("pthread_join()");
 }
}