calculateCheckSum

original_code:
void calculateCheckSum(struct trame* trameAEnv) {
  char* checkSum = (char*) gMalloc(sizeof (char[2]));
  char* lSB = (char*) gMalloc(sizeof (char[2]));
  int sum = 0, i;
  memset(lSB, '\0', 2);
  for (i = 0; i < 8; i = i + 2) {
    checkSum[0] = trameAEnv->DATA[i];
    checkSum[1] = trameAEnv->DATA[i + 1];
    sum += hexToInt(checkSum);
  }
  for (i = 0; i < 8; i = i + 2) {
    checkSum[0] = trameAEnv->ID[i];
    checkSum[1] = trameAEnv->ID[i + 1];
    sum += hexToInt(checkSum);
  }
  checkSum[0] = trameAEnv->HEADER[0];
  checkSum[1] = trameAEnv->LENGHT[0];
  sum += hexToInt(checkSum);
  for (i = 0; i < 2; i = i + 2) {
    checkSum[0] = trameAEnv->ORG[i];
    checkSum[1] = trameAEnv->ORG[i + 1];
    sum += hexToInt(checkSum);
  }
  for (i = 0; i < 2; i = i + 2) {
    checkSum[0] = trameAEnv->STATUS[i];
    checkSum[1] = trameAEnv->STATUS[i + 1];
    sum += hexToInt(checkSum);
  }
  itochar(sum, checkSum, 16);
  lSB[0] = checkSum[1];
  lSB[1] = checkSum[0];
  trameAEnv->CHECKSUM = lSB;
  gFree(checkSum);
}

canonical_original_code:
void calculateCheckSum(struct trame *trameAEnv) {
  char *checkSum = (char*) gMalloc(sizeof (char[2]));
  char *lSB = (char*) gMalloc(sizeof (char[2]));
  int sum = 0; int i;
  memset(lSB, '\0', 2);
  for (i = 0; i < 8; i = i + 2) {
    checkSum[0] = trameAEnv->DATA[i];
    checkSum[1] = trameAEnv->DATA[i + 1];
    sum += hexToInt(checkSum);
  }
  for (i = 0; i < 8; i = i + 2) {
    checkSum[0] = trameAEnv->ID[i];
    checkSum[1] = trameAEnv->ID[i + 1];
    sum += hexToInt(checkSum);
  }
  checkSum[0] = trameAEnv->HEADER[0];
  checkSum[1] = trameAEnv->LENGHT[0];
  sum += hexToInt(checkSum);
  for (i = 0; i < 2; i = i + 2) {
    checkSum[0] = trameAEnv->ORG[i];
    checkSum[1] = trameAEnv->ORG[i + 1];
    sum += hexToInt(checkSum);
  }
  for (i = 0; i < 2; i = i + 2) {
    checkSum[0] = trameAEnv->STATUS[i];
    checkSum[1] = trameAEnv->STATUS[i + 1];
    sum += hexToInt(checkSum);
  }
  itochar(sum, checkSum, 16);
  lSB[0] = checkSum[1];
  lSB[1] = checkSum[0];
  trameAEnv->CHECKSUM = lSB;
  gFree(checkSum);
}

variable_types: struct trame { char *SYNC; char *HEADER; char *LENGHT; char *ORG; char *DATA; char *ID; char *STATUS; char *CHECKSUM; } *

variable_types:
checkSum
char *

variable_types:
lSB
char *

variable_types: sum int


createMessageOpen

repo: CofiTy/cofiTyHome

original_code:
void createMessageOpen(char id[9], char* trameToSend) {
  struct trame* trameAEnvoyer = (struct trame*) gMalloc(sizeof (struct trame));
  memset(trameAEnvoyer, '\0', sizeof (struct trame));
  trameAEnvoyer->DATA = "50000000";
  trameAEnvoyer->HEADER = "6";
  trameAEnvoyer->ID = id;
  trameAEnvoyer->LENGHT = "B";
  trameAEnvoyer->ORG = "05";
  trameAEnvoyer->STATUS = "10";
  trameAEnvoyer->SYNC = "A55A";
  calculateCheckSum(trameAEnvoyer);
  strcpy(trameToSend, trameAEnvoyer->SYNC);
  strcat(trameToSend, trameAEnvoyer->HEADER);
  strcat(trameToSend, trameAEnvoyer->LENGHT);
  strcat(trameToSend, trameAEnvoyer->ORG);
  strcat(trameToSend, trameAEnvoyer->DATA);
  strcat(trameToSend, trameAEnvoyer->ID);
  strcat(trameToSend, trameAEnvoyer->STATUS);
  strcat(trameToSend, trameAEnvoyer->CHECKSUM);
  gFree(trameAEnvoyer);
}

canonical_original_code:
void createMessageOpen(char id[9], char *trameToSend) {
  struct trame *trameAEnvoyer = (struct trame*) gMalloc(sizeof (struct trame));
  memset(trameAEnvoyer, '\0', sizeof (struct trame));
  trameAEnvoyer->DATA = "50000000";
  trameAEnvoyer->HEADER = "6";
  trameAEnvoyer->ID = id;
  trameAEnvoyer->LENGHT = "B";
  trameAEnvoyer->ORG = "05";
  trameAEnvoyer->STATUS = "10";
  trameAEnvoyer->SYNC = "A55A";
  calculateCheckSum(trameAEnvoyer);
  strcpy(trameToSend, trameAEnvoyer->SYNC);
  strcat(trameToSend, trameAEnvoyer->HEADER);
  strcat(trameToSend, trameAEnvoyer->LENGHT);
  strcat(trameToSend, trameAEnvoyer->ORG);
  strcat(trameToSend, trameAEnvoyer->DATA);
  strcat(trameToSend, trameAEnvoyer->ID);
  strcat(trameToSend, trameAEnvoyer->STATUS);
  strcat(trameToSend, trameAEnvoyer->CHECKSUM);
  gFree(trameAEnvoyer);
}

variable_types:
id
char [9]

variable_types:
trameToSend
char *

return_type: void

user_defined_types: struct trame { char *SYNC; char *HEADER; char *LENGHT; char *ORG; char *DATA; char *ID; char *STATUS; char *CHECKSUM; }


openCOURRANT

decompiled_code:
__int64 __fastcall openCOURRANT(const char *a1)
{
__int64 v1; // rbx

v1 = gMalloc(28LL);
*(_QWORD *)v1 = 0LL;
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_DWORD *)(v1 + 24) = 0;
createMessageOpen(a1, (char *)v1);
sensorsNetworkSend(v1, 28LL);
return gFree(v1);
}

canonical_decompiled_code:
__int64 __fastcall func29(const char *a1)
{
__int64 v1; // rbx

v1 = gMalloc(28LL);
*(_QWORD *)v1 = 0LL;
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_DWORD *)(v1 + 24) = 0;
func28(a1, (char *)v1);
sensorsNetworkSend(v1, 28LL);
return gFree(v1);
}

original_code:
void openCOURRANT(char id[9]) {
  char* trame = (char*) gMalloc(sizeof (char[28]));
  memset(trame, '\0', 28);
  createMessageOpen(id, trame);
  sensorsNetworkSend(trame, 28);
  gFree(trame);
}

canonical_original_code:
void openCOURRANT(char id[9]) {
  char *trame = (char*) gMalloc(sizeof (char[28]));
  memset(trame, '\0', 28);
  createMessageOpen(id, trame);
  sensorsNetworkSend(trame, 28);
  gFree(trame);
}

variable_types:
trame
char *


createMessageClose

decompiled_code:
__int64 __fastcall createMessageClose(const char *a1, char *a2)
{
const char **v2; // rbx

v2 = (const char **)gMalloc(64LL);
v2[4] = "70000000";
v2[1] = "6";
v2[5] = a1;
v2[2] = "B";
v2[3] = "05";
v2[6] = "10";
*v2 = "A55A";
calculateCheckSum((__int64)v2);
strcpy(a2, *v2);
strcat(a2, v2[1]);
strcat(a2, v2[2]);
strcat(a2, v2[3]);
strcat(a2, v2[4]);
strcat(a2, v2[5]);
strcat(a2, v2[6]);
strcat(a2, v2[7]);
return gFree(v2);
}

original_code:
void createMessageClose(char id[9], char* trameToSend) {
  struct trame* trameAEnvoyer = (struct trame*) gMalloc(sizeof (struct trame));
  trameAEnvoyer->DATA = "70000000";
  trameAEnvoyer->HEADER = "6";
  trameAEnvoyer->ID = id;
  trameAEnvoyer->LENGHT = "B";
  trameAEnvoyer->ORG = "05";
  trameAEnvoyer->STATUS = "10";
  trameAEnvoyer->SYNC = "A55A";
  calculateCheckSum(trameAEnvoyer);
  strcpy(trameToSend, trameAEnvoyer->SYNC);
  strcat(trameToSend, trameAEnvoyer->HEADER);
  strcat(trameToSend, trameAEnvoyer->LENGHT);
  strcat(trameToSend, trameAEnvoyer->ORG);
  strcat(trameToSend, trameAEnvoyer->DATA);
  strcat(trameToSend, trameAEnvoyer->ID);
  strcat(trameToSend, trameAEnvoyer->STATUS);
  strcat(trameToSend, trameAEnvoyer->CHECKSUM);
  gFree(trameAEnvoyer);
}

canonical_original_code:
void createMessageClose(char id[9], char *trameToSend) {
  struct trame *trameAEnvoyer = (struct trame*) gMalloc(sizeof (struct trame));
  trameAEnvoyer->DATA = "70000000";
  trameAEnvoyer->HEADER = "6";
  trameAEnvoyer->ID = id;
  trameAEnvoyer->LENGHT = "B";
  trameAEnvoyer->ORG = "05";
  trameAEnvoyer->STATUS = "10";
  trameAEnvoyer->SYNC = "A55A";
  calculateCheckSum(trameAEnvoyer);
  strcpy(trameToSend, trameAEnvoyer->SYNC);
  strcat(trameToSend, trameAEnvoyer->HEADER);
  strcat(trameToSend, trameAEnvoyer->LENGHT);
  strcat(trameToSend, trameAEnvoyer->ORG);
  strcat(trameToSend, trameAEnvoyer->DATA);
  strcat(trameToSend, trameAEnvoyer->ID);
  strcat(trameToSend, trameAEnvoyer->STATUS);
  strcat(trameToSend, trameAEnvoyer->CHECKSUM);
  gFree(trameAEnvoyer);
}


closeCOURRANT

decompiled_code:
__int64 __fastcall closeCOURRANT(const char *a1)
{
__int64 v1; // rbx

v1 = gMalloc(28LL);
*(_QWORD *)v1 = 0LL;
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_DWORD *)(v1 + 24) = 0;
createMessageClose(a1, (char *)v1);
sensorsNetworkSend(v1, 28LL);
return gFree(v1);
}

canonical_decompiled_code:
__int64 __fastcall func31(const char *a1)
{
__int64 v1; // rbx

v1 = gMalloc(28LL);
*(_QWORD *)v1 = 0LL;
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_DWORD *)(v1 + 24) = 0;
func30(a1, (char *)v1);
sensorsNetworkSend(v1, 28LL);
return gFree(v1);
}

original_code:
void closeCOURRANT(char id[9]) {
  char* trame = (char*) gMalloc(sizeof (char[28]));
  memset(trame, '\0', 28);
  createMessageClose(id, trame);
  sensorsNetworkSend(trame, 28);
  gFree(trame);
}

canonical_original_code:
void closeCOURRANT(char id[9]) {
  char *trame = (char*) gMalloc(sizeof (char[28]));
  memset(trame, '\0', 28);
  createMessageClose(id, trame);
  sensorsNetworkSend(trame, 28);
  gFree(trame);
}


getActionneur

decompiled_code:
__int64 __fastcall getActionneur(char *s2)
{
__int64 v1; // rbx

v1 = actionneurs;
if ( actionneurs )
{
while ( strcmp((const char *)(v1 + 4), s2) && strcmp((const char *)(v1 + 13), s2) )
{
v1 = *(_QWORD *)(v1 + 40);
if ( !v1 )
goto LABEL_5;
}
}
else
{
LABEL_5:
printf("Actionneur not recognized : %s !!!\n", s2);
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func32(char *s2)
{
__int64 v1; // rbx

v1 = actionneurs;
if ( actionneurs )
{
while ( strcmp((const char *)(v1 + 4), s2) && strcmp((const char *)(v1 + 13), s2) )
{
v1 = *(_QWORD *)(v1 + 40);
if ( !v1 )
goto LABEL_5;
}
}
else
{
LABEL_5:
printf("Actionneur not recognized : %s !!!\n", s2);
v1 = 0LL;
}
return v1;
}

original_code:
struct actionneur_t * getActionneur(char id_or_name[((20>9)?20:9)]) {
  struct actionneur_t * current = actionneurs;
  while (current != 0) {
    if (strcmp(current->id, id_or_name) == 0 || (current->name != ((void *)0) && strcmp(current->name, id_or_name) == 0)) {
      return current;
    }
    current = current->nextActionneur;
  }
  printf("Actionneur not recognized : %s !!!\n", id_or_name);
  return 0;
}

canonical_original_code:
struct actionneur_t *getActionneur(char id_or_name[-1]) {
  struct actionneur_t *current = actionneurs;
  while (current != 0) {
    if (strcmp(current->id, id_or_name) == 0 || (current->name != ((void *)0) && strcmp(current->name, id_or_name) == 0)) {
      return current;
    }
    current = current->nextActionneur;
  }
  printf("Actionneur not recognized : %s !!!\n", id_or_name);
  return 0;
}

variable_types: struct actionneur_t { enum typeActionneur { COURRANT=0, VOLETS=1, CAFFE=2, CHAUFFAGE=3, VIRTUALKEYBOARD=4, MYSTERE=5 } type; char id[9]; char name[20]; struct actionneur_t *nextActionneur; } *

user_defined_types: struct actionneur_t { enum typeActionneur type; char id[9]; char name[20]; struct actionneur_t *nextActionneur; }


setActionneurFct

decompiled_code:
char __fastcall setActionneurFct(__int64 a1, const char *a2)
{
bool v2; // zf
int v3; // eax

switch ( **(_DWORD **)(a1 + 8) )
{
case 0:
v2 = strcmp(a2, "open") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = openCOURRANT;
}
else
{
v2 = strcmp(a2, "close") == 0;
LOBYTE(v3) = !v2;
if ( !v2 )
goto LABEL_57;
*(_QWORD *)a1 = closeCOURRANT;
}
break;
case 1:
v2 = strcmp(a2, "open") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = openVOLETS;
}
else
{
v2 = strcmp(a2, "close") == 0;
LOBYTE(v3) = !v2;
if ( !v2 )
goto LABEL_57;
*(_QWORD *)a1 = closeVOLETS;
}
break;
case 2:
v2 = strcmp(a2, "open") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = openCAFFE;
}
else
{
v2 = strcmp(a2, "close") == 0;
LOBYTE(v3) = !v2;
if ( !v2 )
goto LABEL_57;
*(_QWORD *)a1 = closeCAFFE;
}
break;
case 3:
v2 = strcmp(a2, "open") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = openCHAUFFAGE;
}
else
{
v2 = strcmp(a2, "close") == 0;
LOBYTE(v3) = !v2;
if ( !v2 )
goto LABEL_57;
*(_QWORD *)a1 = closeCHAUFFAGE;
}
break;
case 4:
v2 = strcmp(a2, "next") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYforward;
}
else
{
v2 = strcmp(a2, "previous") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYbackwards;
}
else
{
v2 = strcmp(a2, "f1") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF1;
}
else
{
v2 = strcmp(a2, "f2") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF2;
}
else
{
v2 = strcmp(a2, "f3") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF3;
}
else
{
v2 = strcmp(a2, "f4") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF4;
}
else
{
v2 = strcmp(a2, "f5") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF5;
}
else
{
v2 = strcmp(a2, "enter") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYEnter;
}
else
{
v3 = strcmp(a2, "up");
if ( v3 )
{
v3 = strcmp(a2, "down");
if ( v3 )
{
v3 = strcmp(a2, "escape");
if ( v3 )
{
v3 = strcmp(a2, "q");
if ( v3 )
{
v3 = strcmp(a2, "d");
if ( v3 )
goto LABEL_57;
*(_QWORD *)a1 = pressKEYd;
}
else
{
*(_QWORD *)a1 = pressKEYq;
}
}
else
{
*(_QWORD *)a1 = pressKEYEscape;
}
}
else
{
*(_QWORD *)a1 = pressKEYDown;
}
}
else
{
*(_QWORD *)a1 = pressKEYUp;
}
}
}
}
}
}
}
}
}
break;
case 5:
v2 = strcmp(a2, "action") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = actionMYSTERE;
}
else
{
v2 = strcmp(a2, "fin") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = finMYSTERE;
}
else
{
v2 = strcmp(a2, "jeu") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = jeuMYSTERE;
}
else
{
v2 = strcmp(a2, "finJeu") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
*(_QWORD *)a1 = finJeuMYSTERE;
else
LABEL_57:
LOBYTE(v3) = printf("Fonction not found : %s\n", a2);
}
}
}
break;
default:
LOBYTE(v3) = puts("Actionneur: Type not found");
break;
}
return v3;
}

canonical_decompiled_code:
char __fastcall func33(__int64 a1, const char *a2)
{
bool v2; // zf
int v3; // eax

switch ( **(_DWORD **)(a1 + 8) )
{
case 0:
v2 = strcmp(a2, "open") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = openCOURRANT;
}
else
{
v2 = strcmp(a2, "close") == 0;
LOBYTE(v3) = !v2;
if ( !v2 )
goto LABEL_57;
*(_QWORD *)a1 = closeCOURRANT;
}
break;
case 1:
v2 = strcmp(a2, "open") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = openVOLETS;
}
else
{
v2 = strcmp(a2, "close") == 0;
LOBYTE(v3) = !v2;
if ( !v2 )
goto LABEL_57;
*(_QWORD *)a1 = closeVOLETS;
}
break;
case 2:
v2 = strcmp(a2, "open") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = openCAFFE;
}
else
{
v2 = strcmp(a2, "close") == 0;
LOBYTE(v3) = !v2;
if ( !v2 )
goto LABEL_57;
*(_QWORD *)a1 = closeCAFFE;
}
break;
case 3:
v2 = strcmp(a2, "open") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = openCHAUFFAGE;
}
else
{
v2 = strcmp(a2, "close") == 0;
LOBYTE(v3) = !v2;
if ( !v2 )
goto LABEL_57;
*(_QWORD *)a1 = closeCHAUFFAGE;
}
break;
case 4:
v2 = strcmp(a2, "next") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYforward;
}
else
{
v2 = strcmp(a2, "previous") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYbackwards;
}
else
{
v2 = strcmp(a2, "f1") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF1;
}
else
{
v2 = strcmp(a2, "f2") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF2;
}
else
{
v2 = strcmp(a2, "f3") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF3;
}
else
{
v2 = strcmp(a2, "f4") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF4;
}
else
{
v2 = strcmp(a2, "f5") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYF5;
}
else
{
v2 = strcmp(a2, "enter") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = pressKEYEnter;
}
else
{
v3 = strcmp(a2, "up");
if ( v3 )
{
v3 = strcmp(a2, "down");
if ( v3 )
{
v3 = strcmp(a2, "escape");
if ( v3 )
{
v3 = strcmp(a2, "q");
if ( v3 )
{
v3 = strcmp(a2, "d");
if ( v3 )
goto LABEL_57;
*(_QWORD *)a1 = pressKEYd;
}
else
{
*(_QWORD *)a1 = pressKEYq;
}
}
else
{
*(_QWORD *)a1 = pressKEYEscape;
}
}
else
{
*(_QWORD *)a1 = pressKEYDown;
}
}
else
{
*(_QWORD *)a1 = pressKEYUp;
}
}
}
}
}
}
}
}
}
break;
case 5:
v2 = strcmp(a2, "action") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = actionMYSTERE;
}
else
{
v2 = strcmp(a2, "fin") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = finMYSTERE;
}
else
{
v2 = strcmp(a2, "jeu") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
*(_QWORD *)a1 = jeuMYSTERE;
}
else
{
v2 = strcmp(a2, "finJeu") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
*(_QWORD *)a1 = finJeuMYSTERE;
else
LABEL_57:
LOBYTE(v3) = printf("Fonction not found : %s\n", a2);
}
}
}
break;
default:
LOBYTE(v3) = puts("Actionneur: Type not found");
break;
}
return v3;
}

original_code:
void setActionneurFct(struct actionFct_t * a, char fctName[20]) {
  switch (a->actionneur->type) {
    case COURRANT:
      {
        if (strcmp(fctName, "open") == 0) {
          a->fct = openCOURRANT;
        }
        else if (strcmp(fctName, "close") == 0) {
          a->fct = closeCOURRANT;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case VOLETS:
      {
        if (strcmp(fctName, "open") == 0) {
          a->fct = openVOLETS;
        }
        else if (strcmp(fctName, "close") == 0) {
          a->fct = closeVOLETS;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case CAFFE:
      {
        if (strcmp(fctName, "open") == 0) {
          a->fct = openCAFFE;
        }
        else if (strcmp(fctName, "close") == 0) {
          a->fct = closeCAFFE;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case CHAUFFAGE:
      {
        if (strcmp(fctName, "open") == 0) {
          a->fct = openCHAUFFAGE;
        }
        else if (strcmp(fctName, "close") == 0) {
          a->fct = closeCHAUFFAGE;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case VIRTUALKEYBOARD:
      {
        if (strcmp(fctName, "next") == 0) {
          a->fct = pressKEYforward;
        }
        else if (strcmp(fctName, "previous") == 0) {
          a->fct = pressKEYbackwards;
        }
        else if (strcmp(fctName, "previous") == 0) {
          a->fct = pressKEYbackwards;
        }
        else if (strcmp(fctName, "f1") == 0) {
          a->fct = pressKEYF1;
        }
        else if (strcmp(fctName, "f2") == 0) {
          a->fct = pressKEYF2;
        }
        else if (strcmp(fctName, "f3") == 0) {
          a->fct = pressKEYF3;
        }
        else if (strcmp(fctName, "f4") == 0) {
          a->fct = pressKEYF4;
        }
        else if (strcmp(fctName, "f5") == 0) {
          a->fct = pressKEYF5;
        }
        else if (strcmp(fctName, "enter") == 0) {
          a->fct = pressKEYEnter;
        }
        else if (strcmp(fctName, "up") == 0) {
          a->fct = pressKEYUp;
        }
        else if (strcmp(fctName, "down") == 0) {
          a->fct = pressKEYDown;
        }
        else if (strcmp(fctName, "escape") == 0) {
          a->fct = pressKEYEscape;
        }
        else if (strcmp(fctName, "q") == 0) {
          a->fct = pressKEYq;
        }
        else if (strcmp(fctName, "d") == 0) {
          a->fct = pressKEYd;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case MYSTERE:
      {
        if (strcmp(fctName, "action") == 0) {
          a->fct = actionMYSTERE;
        }else if (strcmp(fctName, "fin") == 0) {
          a->fct = finMYSTERE;
        }else if (strcmp(fctName, "jeu") == 0) {
          a->fct = jeuMYSTERE;
        }else if (strcmp(fctName, "finJeu") == 0) {
          a->fct = finJeuMYSTERE;
        }else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    default:
      puts("Actionneur: Type not found");
  }
}

canonical_original_code:
void setActionneurFct(struct actionFct_t *a, char fctName[20]) {
  switch (a->actionneur->type) {
    case COURRANT:
      {
        if (strcmp(fctName, "open") == 0) {
          a->fct = openCOURRANT;
        }
        else if (strcmp(fctName, "close") == 0) {
          a->fct = closeCOURRANT;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case VOLETS:
      {
        if (strcmp(fctName, "open") == 0) {
          a->fct = openVOLETS;
        }
        else if (strcmp(fctName, "close") == 0) {
          a->fct = closeVOLETS;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case CAFFE:
      {
        if (strcmp(fctName, "open") == 0) {
          a->fct = openCAFFE;
        }
        else if (strcmp(fctName, "close") == 0) {
          a->fct = closeCAFFE;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case CHAUFFAGE:
      {
        if (strcmp(fctName, "open") == 0) {
          a->fct = openCHAUFFAGE;
        }
        else if (strcmp(fctName, "close") == 0) {
          a->fct = closeCHAUFFAGE;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case VIRTUALKEYBOARD:
      {
        if (strcmp(fctName, "next") == 0) {
          a->fct = pressKEYforward;
        }
        else if (strcmp(fctName, "previous") == 0) {
          a->fct = pressKEYbackwards;
        }
        else if (strcmp(fctName, "previous") == 0) {
          a->fct = pressKEYbackwards;
        }
        else if (strcmp(fctName, "f1") == 0) {
          a->fct = pressKEYF1;
        }
        else if (strcmp(fctName, "f2") == 0) {
          a->fct = pressKEYF2;
        }
        else if (strcmp(fctName, "f3") == 0) {
          a->fct = pressKEYF3;
        }
        else if (strcmp(fctName, "f4") == 0) {
          a->fct = pressKEYF4;
        }
        else if (strcmp(fctName, "f5") == 0) {
          a->fct = pressKEYF5;
        }
        else if (strcmp(fctName, "enter") == 0) {
          a->fct = pressKEYEnter;
        }
        else if (strcmp(fctName, "up") == 0) {
          a->fct = pressKEYUp;
        }
        else if (strcmp(fctName, "down") == 0) {
          a->fct = pressKEYDown;
        }
        else if (strcmp(fctName, "escape") == 0) {
          a->fct = pressKEYEscape;
        }
        else if (strcmp(fctName, "q") == 0) {
          a->fct = pressKEYq;
        }
        else if (strcmp(fctName, "d") == 0) {
          a->fct = pressKEYd;
        }
        else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    case MYSTERE:
      {
        if (strcmp(fctName, "action") == 0) {
          a->fct = actionMYSTERE;
        }else if (strcmp(fctName, "fin") == 0) {
          a->fct = finMYSTERE;
        }else if (strcmp(fctName, "jeu") == 0) {
          a->fct = jeuMYSTERE;
        }else if (strcmp(fctName, "finJeu") == 0) {
          a->fct = finJeuMYSTERE;
        }else {
          printf("Fonction not found : %s\n", fctName);
        }
        break;
      }
    default:
      puts("Actionneur: Type not found");
  }
}

variable_types: struct actionFct_t { void (*fct)(char [9]); struct actionneur_t { enum typeActionneur { COURRANT=0, VOLETS=1, CAFFE=2, CHAUFFAGE=3, VIRTUALKEYBOARD=4, MYSTERE=5 } type; char id[9]; char name[20]; struct actionneur_t *nextActionneur; } *actionneur; struct actionFct_t *nextActionFct; } *

variable_types:
fctName
char [20]

user_defined_types: struct actionFct_t { void (*fct)(char [9]); struct actionneur_t *actionneur; struct actionFct_t *nextActionFct; }


cleanActionneurs

decompiled_code:
__int64 cleanActionneurs()
{
__int64 i; // rdi
__int64 result; // rax

for ( i = actionneurs; actionneurs; i = actionneurs )
{
actionneurs = *(_QWORD *)(i + 40);
result = gFree(i);
}
return result;
}

canonical_decompiled_code:
__int64 func34()
{
__int64 i; // rdi
__int64 result; // rax

for ( i = actionneurs; actionneurs; i = actionneurs )
{
actionneurs = *(_QWORD *)(i + 40);
result = gFree(i);
}
return result;
}

original_code:
void cleanActionneurs(){
  struct actionneur_t * cActionneur;
  while(actionneurs != ((void *)0)){
    cActionneur = actionneurs;
    actionneurs = actionneurs->nextActionneur;
    gFree(cActionneur);
  }
}

canonical_original_code:
void cleanActionneurs(){
  struct actionneur_t *cActionneur;
  while(actionneurs != ((void *)0)){
    cActionneur = actionneurs;
    actionneurs = actionneurs->nextActionneur;
    gFree(cActionneur);
  }
}

user_defined_types: enum typeActionneur { COURRANT=0, VOLETS=1, CAFFE=2, CHAUFFAGE=3, VIRTUALKEYBOARD=4, MYSTERE=5 }


tryCheckingRules

decompiled_code:
void __fastcall __noreturn tryCheckingRules(void *a1)
{
while ( 1 )
{
sem_wait(&checkRules);
applyRules();
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
while ( 1 )
{
sem_wait(&checkRules);
applyRules();
}
}

original_code:
void * tryCheckingRules()
{
    for(;;)
    {
        sem_wait((sem_t *)&checkRules);
        applyRules();
    }
}

canonical_original_code:
void *tryCheckingRules()
{
    for(;;)
    {
        sem_wait((union sem_t *)&checkRules);
        applyRules();
    }
}

return_type: void *

user_defined_types: union sem_t { char __size[32]; long __align; }


initRules

decompiled_code:
int initRules()
{
sem_init(&checkRules, 0, 0);
pthread_create(&checkR, 0LL, (void *(*)(void *))tryCheckingRules, 0LL);
return pthread_detach(checkR);
}

canonical_decompiled_code:
int func1()
{
sem_init(&checkRules, 0, 0);
pthread_create(&checkR, 0LL, (void *(*)(void *))tryCheckingRules, 0LL);
return pthread_detach(checkR);
}

original_code:
void initRules()
{
    sem_init((sem_t *)&checkRules, 0, 0);
    pthread_create(&checkR, ((void *)0), tryCheckingRules, ((void *)0));
    pthread_detach(checkR);
}

canonical_original_code:
void initRules()
{
    sem_init((union sem_t *)&checkRules, 0, 0);
    pthread_create(&checkR, ((void *)0), tryCheckingRules, ((void *)0));
    pthread_detach(checkR);
}


stopRules

decompiled_code:
int stopRules()
{
pthread_cancel(checkR);
return sem_destroy(&checkRules);
}

canonical_decompiled_code:
int func2()
{
pthread_cancel(checkR);
return sem_destroy(&checkRules);
}

original_code:
void stopRules()
{
    pthread_cancel(checkR);
    sem_destroy(&checkRules);
}


getSensor

decompiled_code:
__int64 __fastcall getSensor(char *s2)
{
__int64 i; // rbx

for ( i = sensors; i; i = *(_QWORD *)(i + 48) )
{
if ( !strcmp((const char *)(i + 4), s2) )
break;
if ( !strcmp((const char *)(i + 13), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
__int64 i; // rbx

for ( i = sensors; i; i = *(_QWORD *)(i + 48) )
{
if ( !strcmp((const char *)(i + 4), s2) )
break;
if ( !strcmp((const char *)(i + 13), s2) )
break;
}
return i;
}

original_code:
struct sensorType * getSensor(char id_or_name[((20>9)?20:9)]) {
    struct sensorType * current = sensors;
    while (current != ((void *)0)) {
        if (strcmp(current->id, id_or_name) == 0 || (current->name != ((void *)0) && strcmp(current->name, id_or_name) == 0)) {
            return current;
        }
        current = current->nextSensor;
    }
    return 0;
}

canonical_original_code:
struct sensorType *getSensor(char id_or_name[-1]) {
    struct sensorType *current = sensors;
    while (current != ((void *)0)) {
        if (strcmp(current->id, id_or_name) == 0 || (current->name != ((void *)0) && strcmp(current->name, id_or_name) == 0)) {
            return current;
        }
        current = current->nextSensor;
    }
    return 0;
}

variable_types: struct sensorType { enum typeCapteur { TEMPERATURE=0, CONTACT=1, INTERRUPTEUR=2, PRESENCE=3, HORLOGE=4 } type; char id[9]; char name[20]; void *data; struct sensorType *nextSensor; void (*decode)(char *trame, struct sensorType *); } *

user_defined_types: struct sensorType { enum typeCapteur type; char id[9]; char name[20]; void *data; struct sensorType *nextSensor; void (*decode)(char *trame, struct sensorType *); }


decodeTrame

decompiled_code:
int __fastcall decodeTrame(__int64 a1)
{
__int64 i; // rax
__int64 v2; // rax
char s2[17]; // [rsp+7h] [rbp-11h] BYREF

pthread_mutex_lock(&sensorsMutex);
for ( i = 0LL; i != 8; ++i )
s2[i] = *(_BYTE *)(a1 + i + 16);
s2[8] = 0;
v2 = getSensor(s2);
if ( v2 )
{
(*(void (__fastcall **)(__int64, __int64))(v2 + 56))(a1, v2);
sem_post(&checkRules);
}
return pthread_mutex_unlock(&sensorsMutex);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 i; // rax
__int64 v2; // rax
char s2[17]; // [rsp+7h] [rbp-11h] BYREF

pthread_mutex_lock(&sensorsMutex);
for ( i = 0LL; i != 8; ++i )
s2[i] = *(_BYTE *)(a1 + i + 16);
s2[8] = 0;
v2 = func1(s2);
if ( v2 )
{
(*(void (__fastcall **)(__int64, __int64))(v2 + 56))(a1, v2);
sem_post(&checkRules);
}
return pthread_mutex_unlock(&sensorsMutex);
}

original_code:
void decodeTrame(char* trame) {
    pthread_mutex_lock(&sensorsMutex);
    int i;
    char id[9];
    for (i = 0; i < 8; i++) {
        id[i] = trame[i + 16];
    }
    id[8] = '\0';
    sensorType* capteur = getSensor(id);
    if (capteur != ((void *)0)) {
        capteur->decode(trame, capteur);
        sem_post(&checkRules);
    }
    pthread_mutex_unlock(&sensorsMutex);
}

canonical_original_code:
void decodeTrame(char *trame) {
    pthread_mutex_lock(&sensorsMutex);
    int i;
    char id[9];
    for (i = 0; i < 8; i++) {
        id[i] = trame[i + 16];
    }
    id[8] = '\0';
    struct sensorType *capteur = getSensor(id);
    if (capteur != ((void *)0)) {
        capteur->decode(trame, capteur);
        sem_post(&checkRules);
    }
    pthread_mutex_unlock(&sensorsMutex);
}

variable_types: i int

user_defined_types: enum typeCapteur { TEMPERATURE=0, CONTACT=1, INTERRUPTEUR=2, PRESENCE=3, HORLOGE=4 }


decodePresence

decompiled_code:
int __fastcall decodePresence(_BYTE *a1, __int64 a2)
{
_BOOL4 v2; // er12
int v3; // eax
unsigned int v4; // ebp
char *v6; // [rsp+0h] [rbp-28h] BYREF
char nptr[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v2 = (((char)a1[15] >> 1) & 0x31) != 49;
nptr[0] = a1[10];
nptr[1] = a1[11];
v3 = strtol(nptr, &v6, 16);
**(_DWORD **)(a2 + 40) = v2;
v4 = (int)(float)((float)v3 + (float)v3);
*(_DWORD *)(*(_QWORD *)(a2 + 40) + 4LL) = v4;
logValue((const char *)(a2 + 4), "presence", v2);
return logValue((const char *)(a2 + 4), "luminosite", v4);
}

canonical_decompiled_code:
int __fastcall func3(_BYTE *a1, __int64 a2)
{
_BOOL4 v2; // er12
int v3; // eax
unsigned int v4; // ebp
char *v6; // [rsp+0h] [rbp-28h] BYREF
char nptr[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v2 = (((char)a1[15] >> 1) & 0x31) != 49;
nptr[0] = a1[10];
nptr[1] = a1[11];
v3 = strtol(nptr, &v6, 16);
**(_DWORD **)(a2 + 40) = v2;
v4 = (int)(float)((float)v3 + (float)v3);
*(_DWORD *)(*(_QWORD *)(a2 + 40) + 4LL) = v4;
func0((const char *)(a2 + 4), "presence", v2);
return func0((const char *)(a2 + 4), "luminosite", v4);
}

original_code:
void decodePresence(char* trame, struct sensorType* capteur) {
    int presence;
    char and = '1';
    if (((trame[15]>>1)&(and)) == and)
        presence = 0;
    else
        presence = 1;
    char data[2];
    data[0] = trame[10];
    data[1] = trame[11];
    char* valHex;
    int valDec = strtol(data, &valHex, 16);
    float lumin = 2*(float) valDec;
    ((dataPRESENCE*) capteur->data)->presence = presence;
    ((dataPRESENCE*) capteur->data)->luminosite = lumin;
    logValue(capteur->id, "presence", presence);
    logValue(capteur->id, "luminosite", lumin);
}

canonical_original_code:
void decodePresence(char *trame, struct sensorType *capteur) {
    int presence;
    char and = '1';
    if (((trame[15]>>1)&(and)) == and)
        presence = 0;
    else
        presence = 1;
    char data[2];
    data[0] = trame[10];
    data[1] = trame[11];
    char *valHex;
    int valDec = strtol(data, &valHex, 16);
    float lumin = 2*(float) valDec;
    ((struct dataPRESENCE *) capteur->data)->presence = presence;
    ((struct dataPRESENCE *) capteur->data)->luminosite = lumin;
    logValue(capteur->id, "presence", presence);
    logValue(capteur->id, "luminosite", lumin);
}

variable_types: presence int

variable_types: and char

variable_types:
data
char [2]

variable_types:
valHex
char *

variable_types: valDec int

variable_types: lumin float

user_defined_types: struct dataPRESENCE { int presence; int luminosite; }


decodeInterrupteur

decompiled_code:
int __fastcall decodeInterrupteur(__int64 a1, __int64 a2)
{
char v2; // al

v2 = *(_BYTE *)(a1 + 8);
if ( v2 == 53 )
{
**(_DWORD **)(a2 + 40) = 4;
return logValue((const char *)(a2 + 4), "switchButton", **(_DWORD **)(a2 + 40));
}
if ( v2 > 53 )
{
if ( v2 == 55 )
{
**(_DWORD **)(a2 + 40) = 3;
return logValue((const char *)(a2 + 4), "switchButton", **(_DWORD **)(a2 + 40));
}
LABEL_11:
**(_DWORD **)(a2 + 40) = 0;
return logValue((const char *)(a2 + 4), "switchButton", **(_DWORD **)(a2 + 40));
}
if ( v2 == 49 )
{
**(_DWORD **)(a2 + 40) = 2;
return logValue((const char *)(a2 + 4), "switchButton", **(_DWORD **)(a2 + 40));
}
if ( v2 != 51 )
goto LABEL_11;
**(_DWORD **)(a2 + 40) = 1;
return logValue((const char *)(a2 + 4), "switchButton", **(_DWORD **)(a2 + 40));
}

original_code:
void decodeInterrupteur(char* trame, struct sensorType* capteur) {
    char db3 = trame[8];
    switch (db3) {
        case '7':
        {
            ((dataINTERRUPTEUR*) capteur->data)->switchButton = B0;
            break;
        }
        case '5':
        {
            ((dataINTERRUPTEUR*) capteur->data)->switchButton = B1;
            break;
        }
        case '3':
        {
            ((dataINTERRUPTEUR*) capteur->data)->switchButton = A0;
            break;
        }
        case '1':
        {
            ((dataINTERRUPTEUR*) capteur->data)->switchButton = A1;
            break;
        }
        default:
        {
            ((dataINTERRUPTEUR*) capteur->data)->switchButton = NONE;
            break;
        }
    }
            logValue(capteur->id, "switchButton", ((dataINTERRUPTEUR*) capteur->data)->switchButton);
}

canonical_original_code:
void decodeInterrupteur(char *trame, struct sensorType *capteur) {
    char db3 = trame[8];
    switch (db3) {
        case '7':
        {
            ((struct dataINTERRUPTEUR *) capteur->data)->switchButton = B0;
            break;
        }
        case '5':
        {
            ((struct dataINTERRUPTEUR *) capteur->data)->switchButton = B1;
            break;
        }
        case '3':
        {
            ((struct dataINTERRUPTEUR *) capteur->data)->switchButton = A0;
            break;
        }
        case '1':
        {
            ((struct dataINTERRUPTEUR *) capteur->data)->switchButton = A1;
            break;
        }
        default:
        {
            ((struct dataINTERRUPTEUR *) capteur->data)->switchButton = NONE;
            break;
        }
    }
            logValue(capteur->id, "switchButton", ((struct dataINTERRUPTEUR *) capteur->data)->switchButton);
}

user_defined_types: struct dataINTERRUPTEUR { enum buttonPressed switchButton; }

user_defined_types: enum buttonPressed { NONE=0, A0=1, A1=2, B0=3, B1=4 }


decodeContact

decompiled_code:
int __fastcall decodeContact(__int64 a1, __int64 a2)
{
**(_DWORD **)(a2 + 40) = (*(_BYTE *)(a1 + 15) & 0x31) == 49;
return logValue((const char *)(a2 + 4), "contact", **(_DWORD **)(a2 + 40));
}

original_code:
void decodeContact(char* trame, struct sensorType* capteur) {
    char and = '1';
    if (((trame[15])&(and)) == and) {
        ((dataCONTACT*) capteur->data)->contact = 1;
    } else {
        ((dataCONTACT*) capteur->data)->contact = 0;
    }
    logValue(capteur->id, "contact", ((dataCONTACT*) capteur->data)->contact);
}

canonical_original_code:
void decodeContact(char *trame, struct sensorType *capteur) {
    char and = '1';
    if (((trame[15])&(and)) == and) {
        ((struct dataCONTACT *) capteur->data)->contact = 1;
    } else {
        ((struct dataCONTACT *) capteur->data)->contact = 0;
    }
    logValue(capteur->id, "contact", ((struct dataCONTACT *) capteur->data)->contact);
}


decodeTemperature

decompiled_code:
int __fastcall decodeTemperature(__int64 a1, __int64 a2)
{
float v2; // xmm0_4
char *v4; // [rsp+0h] [rbp-18h] BYREF
char nptr[10]; // [rsp+Eh] [rbp-Ah] BYREF

nptr[0] = *(_BYTE *)(a1 + 12);
nptr[1] = *(_BYTE *)(a1 + 13);
v2 = 40.0 - (float)((float)(int)strtol(nptr, &v4, 16) * 0.15686275);
**(_DWORD **)(a2 + 40) = (int)v2;
return logValue((const char *)(a2 + 4), "contact", (int)v2);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
float v2; // xmm0_4
char *v4; // [rsp+0h] [rbp-18h] BYREF
char nptr[10]; // [rsp+Eh] [rbp-Ah] BYREF

nptr[0] = *(_BYTE *)(a1 + 12);
nptr[1] = *(_BYTE *)(a1 + 13);
v2 = 40.0 - (float)((float)(int)strtol(nptr, &v4, 16) * 0.15686275);
**(_DWORD **)(a2 + 40) = (int)v2;
return func0((const char *)(a2 + 4), "contact", (int)v2);
}

original_code:
void decodeTemperature(char* trame, struct sensorType* capteur) {
    char data[2];
    data[0] = trame[12];
    data[1] = trame[13];
    char* valHex;
    int valDec = strtol(data, &valHex, 16);
    int temp = 40 - ((float) (40.0 / 255.0)) * valDec;
    ((dataTEMPERATURE*) capteur->data)->temp = temp;
    logValue(capteur->id, "contact", temp);
}

canonical_original_code:
void decodeTemperature(char *trame, struct sensorType *capteur) {
    char data[2];
    data[0] = trame[12];
    data[1] = trame[13];
    char *valHex;
    int valDec = strtol(data, &valHex, 16);
    int temp = 40 - ((float) (40.0 / 255.0)) * valDec;
    ((struct dataTEMPERATURE *) capteur->data)->temp = temp;
    logValue(capteur->id, "contact", temp);
}

variable_types: temp int


decodeHorloge

decompiled_code:
void decodeHorloge()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code: void decodeHorloge(char* trame, struct sensorType* capteur) {}

canonical_original_code: void decodeHorloge(char *trame, struct sensorType *capteur) {}


cleanSensors

decompiled_code:
__int64 cleanSensors()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = sensors; sensors; i = sensors )
{
sensors = *(_QWORD *)(i + 48);
gFree(*(_QWORD *)(i + 40));
result = gFree(i);
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = sensors; sensors; i = sensors )
{
sensors = *(_QWORD *)(i + 48);
gFree(*(_QWORD *)(i + 40));
result = gFree(i);
}
return result;
}

original_code:
void cleanSensors(){
  struct sensorType * cSensor;
  while(sensors != ((void *)0)){
    cSensor = sensors;
    sensors = sensors->nextSensor;
    gFree(cSensor->data);
    gFree(cSensor);
  }
}

canonical_original_code:
void cleanSensors(){
  struct sensorType *cSensor;
  while(sensors != ((void *)0)){
    cSensor = sensors;
    sensors = sensors->nextSensor;
    gFree(cSensor->data);
    gFree(cSensor);
  }
}


gFree

decompiled_code:
void __fastcall gFree(unsigned __int64 a1)
{
unsigned __int64 v1; // rcx
unsigned __int64 v2; // rax
_QWORD *v3; // rdx
__int64 v4; // rdx
_QWORD *v5; // rsi
__int64 v6; // rdx

if ( !freep )
return;
pthread_mutex_lock(&myLock);
if ( a1 == 0 || a1 < (unsigned __int64)&heap || a1 >= (unsigned __int64)&freep )
{
pthread_mutex_unlock(&myLock);
return;
}
v1 = a1 - 24;
v2 = freep;
if ( *(_BYTE *)(a1 - 8) != 42 )
{
pthread_mutex_unlock(&myLock);
return;
}
while ( v2 < v1 )
{
v3 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 > v1 || (unsigned __int64)v3 <= v2 )
goto LABEL_14;
LABEL_10:
v2 = (unsigned __int64)v3;
}
v3 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 > v2 || (unsigned __int64)v3 <= v1 )
goto LABEL_10;
LABEL_14:
v4 = *(_QWORD *)(a1 - 16);
v5 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 == v1 + 24 * v4 )
{
*(_QWORD *)(a1 - 16) = v5[1] + v4;
*(_QWORD *)(a1 - 24) = **(_QWORD **)v2;
}
else
{
*(_QWORD *)(a1 - 24) = v5;
}
v6 = *(_QWORD *)(v2 + 8);
if ( v1 == v2 + 24 * v6 )
{
*(_QWORD *)(v2 + 8) = *(_QWORD *)(a1 - 16) + v6;
*(_QWORD *)v2 = *(_QWORD *)(a1 - 24);
}
else
{
*(_QWORD *)v2 = v1;
}
freep = v2;
pthread_mutex_unlock(&myLock);
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int64 a1)
{
unsigned __int64 v1; // rcx
unsigned __int64 v2; // rax
_QWORD *v3; // rdx
__int64 v4; // rdx
_QWORD *v5; // rsi
__int64 v6; // rdx

if ( !freep )
return;
pthread_mutex_lock(&myLock);
if ( a1 == 0 || a1 < (unsigned __int64)&heap || a1 >= (unsigned __int64)&freep )
{
pthread_mutex_unlock(&myLock);
return;
}
v1 = a1 - 24;
v2 = freep;
if ( *(_BYTE *)(a1 - 8) != 42 )
{
pthread_mutex_unlock(&myLock);
return;
}
while ( v2 < v1 )
{
v3 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 > v1 || (unsigned __int64)v3 <= v2 )
goto LABEL_14;
LABEL_10:
v2 = (unsigned __int64)v3;
}
v3 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 > v2 || (unsigned __int64)v3 <= v1 )
goto LABEL_10;
LABEL_14:
v4 = *(_QWORD *)(a1 - 16);
v5 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 == v1 + 24 * v4 )
{
*(_QWORD *)(a1 - 16) = v5[1] + v4;
*(_QWORD *)(a1 - 24) = **(_QWORD **)v2;
}
else
{
*(_QWORD *)(a1 - 24) = v5;
}
v6 = *(_QWORD *)(v2 + 8);
if ( v1 == v2 + 24 * v6 )
{
*(_QWORD *)(v2 + 8) = *(_QWORD *)(a1 - 16) + v6;
*(_QWORD *)v2 = *(_QWORD *)(a1 - 24);
}
else
{
*(_QWORD *)v2 = v1;
}
freep = v2;
pthread_mutex_unlock(&myLock);
}

original_code:
void gFree(void *ap)
{
    Header *bp, *p;
    if(freep == ((void *)0))
        return;
    pthread_mutex_lock(&myLock);
    if(ap == ((void *)0)
            || (void *)ap < (void *)heap
            || (void *)ap >= (void *)(heap + 5000000))
    {
        pthread_mutex_unlock(&myLock);
        return;
    }
    bp = (Header *)ap - 1;
    if(bp->s.sCode != 42)
    {
        pthread_mutex_unlock(&myLock);
        return;
    }
    for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
    {
        if (p >= p->s.ptr && (bp > p || bp < p->s.ptr))
        {
             break;
        }
    }
    if (bp + bp->s.size == p->s.ptr)
    {
        bp->s.size += p->s.ptr->s.size;
        bp->s.ptr = p->s.ptr->s.ptr;
    }
    else
    {
        bp->s.ptr = p->s.ptr;
    }
    if (p + p->s.size == bp)
    {
        p->s.size += bp->s.size;
        p->s.ptr = bp->s.ptr;
    }
    else
    {
        p->s.ptr = bp;
    }
    freep = p;
    pthread_mutex_unlock(&myLock);
}

canonical_original_code:
void gFree(void *ap)
{
    union header *bp; union header *p;
    if(freep == ((void *)0))
        return;
    pthread_mutex_lock(&myLock);
    if(ap == ((void *)0)
            || (void *)ap < (void *)heap
            || (void *)ap >= (void *)(heap + 5000000))
    {
        pthread_mutex_unlock(&myLock);
        return;
    }
    bp = (union header *)ap - 1;
    if(bp->s.sCode != 42)
    {
        pthread_mutex_unlock(&myLock);
        return;
    }
    for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
    {
        if (p >= p->s.ptr && (bp > p || bp < p->s.ptr))
        {
             break;
        }
    }
    if (bp + bp->s.size == p->s.ptr)
    {
        bp->s.size += p->s.ptr->s.size;
        bp->s.ptr = p->s.ptr->s.ptr;
    }
    else
    {
        bp->s.ptr = p->s.ptr;
    }
    if (p + p->s.size == bp)
    {
        p->s.size += bp->s.size;
        p->s.ptr = bp->s.ptr;
    }
    else
    {
        p->s.ptr = bp;
    }
    freep = p;
    pthread_mutex_unlock(&myLock);
}

variable_types:
ap
void *

variable_types: union header { struct { union header *ptr; unsigned long size; unsigned char sCode; } s; long x; } *


initMemory

decompiled_code:
void initMemory()
{
if ( !freep )
{
freep = (__int64)&base;
base = (__int64)&base;
qword_4C4E38 = 0LL;
pthread_mutex_init(&myLock, 0LL);
qword_2E8 = (__int64)&unk_32DCD;
byte_2F0 = 42;
gFree((unsigned __int64)&unk_2F8);
}
}

canonical_decompiled_code:
void func1()
{
if ( !freep )
{
freep = (__int64)&base;
base = (__int64)&base;
qword_4C4E38 = 0LL;
pthread_mutex_init(&myLock, 0LL);
qword_2E8 = (__int64)&unk_32DCD;
byte_2F0 = 42;
func0((unsigned __int64)&unk_2F8);
}
}

original_code:
void initMemory()
{
    if(freep == ((void *)0))
    {
        Header *up;
        base.s.ptr = freep = &base;
        base.s.size = 0;
        pthread_mutex_init (&myLock, ((void *)0));
        up = (Header *) heap;
        up->s.size = 5000000/sizeof(Header);
        up->s.sCode = 42;
        gFree((void *)(up+1));
    }
}

canonical_original_code:
void initMemory()
{
    if(freep == ((void *)0))
    {
        union header *up;
        base.s.ptr = freep = &base;
        base.s.size = 0;
        pthread_mutex_init (&myLock, ((void *)0));
        up = (union header *) heap;
        up->s.size = 5000000/sizeof(Header);
        up->s.sCode = 42;
        gFree((void *)(up+1));
    }
}

user_defined_types: union header { struct { union header *ptr; unsigned long size; unsigned char sCode; } s; long x; }


destroyMemory

decompiled_code:
int destroyMemory()
{
freep = 0LL;
return pthread_mutex_destroy(&myLock);
}

canonical_decompiled_code:
int func3()
{
freep = 0LL;
return pthread_mutex_destroy(&myLock);
}

original_code:
void destroyMemory()
{
 freep = ((void *)0);
 pthread_mutex_destroy(&myLock);
}


getGMemTotal

decompiled_code:
void *getGMemTotal()
{
return &unk_4C4B40;
}

canonical_decompiled_code:
void *func4()
{
return &unk_4C4B40;
}

original_code:
unsigned long getGMemTotal()
{
    return 5000000;
}

return_type: unsigned long


getGMemFree

decompiled_code:
__int64 getGMemFree()
{
__int64 i; // rbx
_QWORD *v1; // rax

i = 0LL;
if ( freep )
{
pthread_mutex_lock(&myLock);
v1 = *(_QWORD **)freep;
for ( i = 24LL * *(_QWORD *)(*(_QWORD *)freep + 8LL); (_QWORD *)freep != v1; i += 24LL * v1[1] )
v1 = (_QWORD *)*v1;
pthread_mutex_unlock(&myLock);
}
return i;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 i; // rbx
_QWORD *v1; // rax

i = 0LL;
if ( freep )
{
pthread_mutex_lock(&myLock);
v1 = *(_QWORD **)freep;
for ( i = 24LL * *(_QWORD *)(*(_QWORD *)freep + 8LL); (_QWORD *)freep != v1; i += 24LL * v1[1] )
v1 = (_QWORD *)*v1;
pthread_mutex_unlock(&myLock);
}
return i;
}

original_code:
unsigned long getGMemFree()
{
    Header *p, *prevp;
    unsigned long sum;
    if(freep == ((void *)0))
        return 0;
    pthread_mutex_lock(&myLock);
    prevp = freep;
    sum = 0;
    for (p = prevp->s.ptr; ; prevp = p, p = p->s.ptr)
    {
        sum += p->s.size*sizeof(Header);
        if (p == freep)
            break;
    }
    pthread_mutex_unlock(&myLock);
    return sum;
}

canonical_original_code:
unsigned long getGMemFree()
{
    union header *p; union header *prevp;
    unsigned long sum;
    if(freep == ((void *)0))
        return 0;
    pthread_mutex_lock(&myLock);
    prevp = freep;
    sum = 0;
    for (p = prevp->s.ptr; ; prevp = p, p = p->s.ptr)
    {
        sum += p->s.size*sizeof(Header);
        if (p == freep)
            break;
    }
    pthread_mutex_unlock(&myLock);
    return sum;
}

variable_types:
sum
unsigned long


testEqual

decompiled_code:
_BOOL8 __fastcall testEqual(_DWORD *a1, int a2)
{
return *a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1, int a2)
{
return *a1 == a2;
}

original_code:
int testEqual(int * data, int value) {
    if (*data == value)
        return 1;
    else
        return 0;
}

canonical_original_code:
int testEqual(int *data, int value) {
    if (*data == value)
        return 1;
    else
        return 0;
}

variable_types:
data
int *

variable_types: value int

return_type: int


testGreaterOrEqual

decompiled_code:
_BOOL8 __fastcall testGreaterOrEqual(_DWORD *a1, int a2)
{
return *a1 >= a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_DWORD *a1, int a2)
{
return *a1 >= a2;
}

original_code:
int testGreaterOrEqual(int * data, int value) {
    if (*data >= value)
        return 1;
    else
        return 0;
}

canonical_original_code:
int testGreaterOrEqual(int *data, int value) {
    if (*data >= value)
        return 1;
    else
        return 0;
}


testLessOrEqual

decompiled_code:
_BOOL8 __fastcall testLessOrEqual(_DWORD *a1, int a2)
{
return *a1 <= a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1, int a2)
{
return *a1 <= a2;
}

original_code:
int testLessOrEqual(int * data, int value) {
    if (*data <= value)
        return 1;
    else
        return 0;
}

canonical_original_code:
int testLessOrEqual(int *data, int value) {
    if (*data <= value)
        return 1;
    else
        return 0;
}


testGreater

decompiled_code:
_BOOL8 __fastcall testGreater(_DWORD *a1, int a2)
{
return *a1 > a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_DWORD *a1, int a2)
{
return *a1 > a2;
}

original_code:
int testGreater(int * data, int value) {
    if (*data > value) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int testGreater(int *data, int value) {
    if (*data > value) {
        return 1;
    } else {
        return 0;
    }
}


testLess

decompiled_code:
_BOOL8 __fastcall testLess(_DWORD *a1, int a2)
{
return *a1 < a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_DWORD *a1, int a2)
{
return *a1 < a2;
}

original_code:
int testLess(int * data, int value) {
    if (*data < value)
        return 1;
    else
        return 0;
}

canonical_original_code:
int testLess(int *data, int value) {
    if (*data < value)
        return 1;
    else
        return 0;
}


testTimeLess

decompiled_code:
_BOOL8 __fastcall testTimeLess(__int64 a1, int a2)
{
return time(0LL) < a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, int a2)
{
return time(0LL) < a2;
}

original_code:
int testTimeLess(int * data, int value)
{
    if(time(((void *)0)) < value)
        return 1;
    else
        return 0;
}

canonical_original_code:
int testTimeLess(int *data, int value)
{
    if(time(((void *)0)) < value)
        return 1;
    else
        return 0;
}


testTimeMore

decompiled_code:
_BOOL8 __fastcall testTimeMore(__int64 a1, int a2)
{
return time(0LL) > a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, int a2)
{
return time(0LL) > a2;
}

original_code:
int testTimeMore(int * data, int value)
{
    if(time(((void *)0)) > value)
    {
        return 1;
    }
    else
        return 0;
}

canonical_original_code:
int testTimeMore(int *data, int value)
{
    if(time(((void *)0)) > value)
    {
        return 1;
    }
    else
        return 0;
}


setConditionName

decompiled_code:
__int64 __fastcall setConditionName(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
int v5; // edx
char dest[8]; // [rsp+7h] [rbp-21h] BYREF
char v7; // [rsp+Fh] [rbp-19h]

*(_QWORD *)dest = 0LL;
v7 = 0;
strcpy(dest, a2);
result = getSensor(dest);
v5 = *(_DWORD *)result;
if ( !*(_DWORD *)result )
{
if ( !strcmp(a3, "temp") )
{
result = *(_QWORD *)(result + 40);
*(_QWORD *)(a1 + 8) = result;
return result;
}
LABEL_16:
printf(aLaPropri, a3, a2);
exit(1);
}
switch ( v5 )
{
case 1:
if ( !strcmp(a3, "contact") )
{
result = *(_QWORD *)(result + 40);
*(_QWORD *)(a1 + 8) = result;
return result;
}
goto LABEL_16;
case 2:
if ( !strcmp(a3, "switchButton") )
{
result = *(_QWORD *)(result + 40);
*(_QWORD *)(a1 + 8) = result;
return result;
}
goto LABEL_16;
case 3:
if ( !strcmp(a3, "presence") )
{
result = *(_QWORD *)(result + 40);
*(_QWORD *)(a1 + 8) = result;
return result;
}
if ( !strcmp(a3, "luminosite") )
{
result = *(_QWORD *)(result + 40) + 4LL;
*(_QWORD *)(a1 + 8) = result;
return result;
}
goto LABEL_16;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
int v5; // edx
char dest[8]; // [rsp+7h] [rbp-21h] BYREF
char v7; // [rsp+Fh] [rbp-19h]

*(_QWORD *)dest = 0LL;
v7 = 0;
strcpy(dest, a2);
result = getSensor(dest);
v5 = *(_DWORD *)result;
if ( !*(_DWORD *)result )
{
if ( !strcmp(a3, "temp") )
{
result = *(_QWORD *)(result + 40);
*(_QWORD *)(a1 + 8) = result;
return result;
}
LABEL_16:
printf(aLaPropri, a3, a2);
exit(1);
}
switch ( v5 )
{
case 1:
if ( !strcmp(a3, "contact") )
{
result = *(_QWORD *)(result + 40);
*(_QWORD *)(a1 + 8) = result;
return result;
}
goto LABEL_16;
case 2:
if ( !strcmp(a3, "switchButton") )
{
result = *(_QWORD *)(result + 40);
*(_QWORD *)(a1 + 8) = result;
return result;
}
goto LABEL_16;
case 3:
if ( !strcmp(a3, "presence") )
{
result = *(_QWORD *)(result + 40);
*(_QWORD *)(a1 + 8) = result;
return result;
}
if ( !strcmp(a3, "luminosite") )
{
result = *(_QWORD *)(result + 40) + 4LL;
*(_QWORD *)(a1 + 8) = result;
return result;
}
goto LABEL_16;
}
return result;
}

original_code:
void setConditionName(struct condition_t * c, char sensorId[9], char cndName[20]) {
    char t[9];
    memset(t, '\0', sizeof (char) * 9);
    strcpy(t, sensorId);
    sensorType * sensor = getSensor(t);
    int ok = 0;
    if (sensor->type == TEMPERATURE) {
        if (strcmp(cndName, "temp") == 0) {
            c->data = &(((dataTEMPERATURE*) sensor->data)->temp);
        } else {
            ok = 1;
        }
    } else if (sensor->type == CONTACT) {
        if (strcmp(cndName, "contact") == 0) {
            c->data = &(((dataCONTACT*) sensor->data)->contact);
        } else {
            ok = 1;
        }
    } else if (sensor->type == INTERRUPTEUR) {
        if (strcmp(cndName, "switchButton") == 0) {
            c->data = ((int*) &(((dataINTERRUPTEUR*) sensor->data)->switchButton));
        } else {
            ok = 1;
        }
    } else if (sensor->type == PRESENCE) {
        if (strcmp(cndName, "presence") == 0) {
            c->data = &(((dataPRESENCE*) sensor->data)->presence);
        } else if (strcmp(cndName, "luminosite") == 0) {
            c->data = &(((dataPRESENCE*) sensor->data)->luminosite);
        } else {
            ok = 1;
        }
    }
    if (ok == 1) {
        printf("La propriété %s du capteur %s n'existe pas !\n", cndName, sensorId);
        exit(1);
    }
}

canonical_original_code:
void setConditionName(struct condition_t *c, char sensorId[9], char cndName[20]) {
    char t[9];
    memset(t, '\0', sizeof (char) * 9);
    strcpy(t, sensorId);
    struct sensorType *sensor = getSensor(t);
    int ok = 0;
    if (sensor->type == TEMPERATURE) {
        if (strcmp(cndName, "temp") == 0) {
            c->data = &(((struct dataTEMPERATURE *) sensor->data)->temp);
        } else {
            ok = 1;
        }
    } else if (sensor->type == CONTACT) {
        if (strcmp(cndName, "contact") == 0) {
            c->data = &(((struct dataCONTACT *) sensor->data)->contact);
        } else {
            ok = 1;
        }
    } else if (sensor->type == INTERRUPTEUR) {
        if (strcmp(cndName, "switchButton") == 0) {
            c->data = ((int *) &(((struct dataINTERRUPTEUR *) sensor->data)->switchButton));
        } else {
            ok = 1;
        }
    } else if (sensor->type == PRESENCE) {
        if (strcmp(cndName, "presence") == 0) {
            c->data = &(((struct dataPRESENCE *) sensor->data)->presence);
        } else if (strcmp(cndName, "luminosite") == 0) {
            c->data = &(((struct dataPRESENCE *) sensor->data)->luminosite);
        } else {
            ok = 1;
        }
    }
    if (ok == 1) {
        printf("La propriété %s du capteur %s n'existe pas !\n", cndName, sensorId);
        exit(1);
    }
}

variable_types: struct condition_t { int (*conditionOK)(int *, int); int *data; int value; struct condition_t *nextCondition; } *

variable_types:
sensorId
char [9]

variable_types:
cndName
char [20]

variable_types:
t
char [9]

variable_types: ok int


sensorsMsgRec

decompiled_code:
void __fastcall __noreturn sensorsMsgRec(void *a1)
{
int v1; // ebx
int v2; // eax
int v3; // edx
__int64 v4[4]; // [rsp+0h] [rbp-B8h] BYREF
char buf[152]; // [rsp+20h] [rbp-98h] BYREF

memset(buf, 0, 0x80uLL);
j = 0;
while ( (unsigned int)recv(sock, buf, 0x80uLL, 0) != -1 )
{
i = 0;
while ( 1 )
{
v1 = i;
if ( v1 >= strlen(buf) )
break;
i = v1 + 1;
v2 = j++;
v3 = j;
*((_BYTE *)v4 + v2) = buf[v1];
if ( v3 == 28 )
{
decodeTrame(v4);
j = 0;
v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
}
}
memset(buf, 0, 0x80uLL);
}
perror("nb");
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
int v1; // ebx
int v2; // eax
int v3; // edx
__int64 v4[4]; // [rsp+0h] [rbp-B8h] BYREF
char buf[152]; // [rsp+20h] [rbp-98h] BYREF

memset(buf, 0, 0x80uLL);
j = 0;
while ( (unsigned int)recv(sock, buf, 0x80uLL, 0) != -1 )
{
i = 0;
while ( 1 )
{
v1 = i;
if ( v1 >= strlen(buf) )
break;
i = v1 + 1;
v2 = j++;
v3 = j;
*((_BYTE *)v4 + v2) = buf[v1];
if ( v3 == 28 )
{
decodeTrame(v4);
j = 0;
v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
}
}
memset(buf, 0, 0x80uLL);
}
perror("nb");
exit(-1);
}

original_code:
void * sensorsMsgRec(){
  char buff[128];
  char data[32];
  int nb;
  memset(buff, '\0', 128);
  j = 0;
  for(;;)
  {
    nb = recv(sock, buff, 128, 0);
    if(nb == -1) { perror("nb");exit(-1);};
    i = 0;
    while(i < (strlen(buff))){
      data[j++] = buff[i++];
      if(j == 28){
        decodeTrame(data);
        j = 0;
        memset(data, '\0', 32);
      }
    }
    memset(buff, '\0', 128);
  }
}

canonical_original_code:
void *sensorsMsgRec(){
  char buff[128];
  char data[32];
  int nb;
  memset(buff, '\0', 128);
  j = 0;
  for(;;)
  {
    nb = recv(sock, buff, 128, 0);
    if(nb == -1) { perror("nb");exit(-1);};
    i = 0;
    while(i < (strlen(buff))){
      data[j++] = buff[i++];
      if(j == 28){
        decodeTrame(data);
        j = 0;
        memset(data, '\0', 32);
      }
    }
    memset(buff, '\0', 128);
  }
}

variable_types:
buff
char [128]

variable_types:
data
char [32]

variable_types: nb int


sensorsMsgSend

decompiled_code:
void __fastcall __noreturn sensorsMsgSend(void *a1)
{
int v1; // eax
int v2; // er12
int v3; // edx
_BYTE *v4; // rbx
int i; // ebp
int v6; // eax
_BYTE v7[8216]; // [rsp+0h] [rbp-2018h] BYREF

while ( 1 )
{
v1 = mq_receive((unsigned int)mqSensorsSend, v7, 0x2000LL, 0LL);
if ( v1 == -1 )
break;
v2 = v1;
v3 = v1;
v4 = v7;
for ( i = 0; v2 > i; v4 += v6 )
{
v6 = send(sock, v4, v3, 0);
v3 = v6;
if ( v6 == -1 )
{
perror("nb");
exit(-1);
}
i += v6;
}
}
perror("nb");
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
int v1; // eax
int v2; // er12
int v3; // edx
_BYTE *v4; // rbx
int i; // ebp
int v6; // eax
_BYTE v7[8216]; // [rsp+0h] [rbp-2018h] BYREF

while ( 1 )
{
v1 = mq_receive((unsigned int)mqSensorsSend, v7, 0x2000LL, 0LL);
if ( v1 == -1 )
break;
v2 = v1;
v3 = v1;
v4 = v7;
for ( i = 0; v2 > i; v4 += v6 )
{
v6 = send(sock, v4, v3, 0);
v3 = v6;
if ( v6 == -1 )
{
perror("nb");
exit(-1);
}
i += v6;
}
}
perror("nb");
exit(-1);
}

original_code:
void * sensorsMsgSend(){
  char buff[8192];
  int nb, nbSent, total;
  char* sending = (char *) buff;
  for(;;)
  {
    nb = mq_receive(mqSensorsSend, buff, 8192, 0);
    if(nb == -1) { perror("nb");exit(-1);};
    total = nb;
    nbSent = 0;
    while(nbSent < total)
    {
      nb = send(sock, sending, nb, 0);
      if(nb == -1) { perror("nb");exit(-1);};
      nbSent += nb;
      sending += nb;
    }
    sending = (char *) buff;
  }
}

canonical_original_code:
void *sensorsMsgSend(){
  char buff[8192];
  int nb; int nbSent; int total;
  char *sending = (char *) buff;
  for(;;)
  {
    nb = mq_receive(mqSensorsSend, buff, 8192, 0);
    if(nb == -1) { perror("nb");exit(-1);};
    total = nb;
    nbSent = 0;
    while(nbSent < total)
    {
      nb = send(sock, sending, nb, 0);
      if(nb == -1) { perror("nb");exit(-1);};
      nbSent += nb;
      sending += nb;
    }
    sending = (char *) buff;
  }
}

variable_types:
buff
char [8192]

variable_types: nbSent int

variable_types: total int

variable_types:
sending
char *


sensorsNetworkStart

decompiled_code:
int sensorsNetworkStart()
{
int v0; // edi
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

mqSensorsSend = mq_open("/SensorsMsgSend", 66LL, 448LL, 0LL);
if ( mqSensorsSend == -1 )
{
perror("mqSensorsSend");
exit(-1);
}
*(_QWORD *)&v2.sa_data[6] = 0LL;
*(_DWORD *)&v2.sa_data[2] = inet_addr(conIP);
v2.sa_family = 2;
*(_WORD *)v2.sa_data = _bswap_16(conPort);
v0 = socket(2, 1, 0);
sock = v0;
if ( v0 == -1 )
{
perror("sock");
exit(-1);
}
if ( connect(v0, &v2, 0x10u) == -1 )
{
perror("connect(sock, (struct sockaddr *)&saddr, len)");
exit(-1);
}
puts("Connected to gateway");
pthread_create(&pthreadSensorsRec, 0LL, (void *(*)(void *))sensorsMsgRec, 0LL);
pthread_detach(pthreadSensorsRec);
pthread_create(&pthreadSensorsSend, 0LL, (void *(*)(void *))sensorsMsgSend, 0LL);
return pthread_detach(pthreadSensorsSend);
}

canonical_decompiled_code:
int func3()
{
int v0; // edi
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

mqSensorsSend = mq_open("/SensorsMsgSend", 66LL, 448LL, 0LL);
if ( mqSensorsSend == -1 )
{
perror("mqSensorsSend");
exit(-1);
}
*(_QWORD *)&v2.sa_data[6] = 0LL;
*(_DWORD *)&v2.sa_data[2] = inet_addr(conIP);
v2.sa_family = 2;
*(_WORD *)v2.sa_data = func2(conPort);
v0 = socket(2, 1, 0);
sock = v0;
if ( v0 == -1 )
{
perror("sock");
exit(-1);
}
if ( connect(v0, &v2, 0x10u) == -1 )
{
perror("connect(sock, (struct sockaddr *)&saddr, len)");
exit(-1);
}
puts("Connected to gateway");
pthread_create(&pthreadSensorsRec, 0LL, (void *(*)(void *))sensorsMsgRec, 0LL);
pthread_detach(pthreadSensorsRec);
pthread_create(&pthreadSensorsSend, 0LL, (void *(*)(void *))sensorsMsgSend, 0LL);
return pthread_detach(pthreadSensorsSend);
}

original_code:
void sensorsNetworkStart(){
  mqSensorsSend = mq_open("/SensorsMsgSend", 02 | 0100, (0400|0200|0100), ((void *)0));
  if(mqSensorsSend == -1) { perror("mqSensorsSend");exit(-1);};
  struct sockaddr_in saddr;
  memset(&saddr, 0, sizeof(struct sockaddr_in));
  saddr.sin_addr.s_addr = inet_addr(conIP);
  saddr.sin_family = 2;
  saddr.sin_port = htons(conPort);
  socklen_t len = sizeof(struct sockaddr_in);
  sock = socket(2, SOCK_STREAM, 0);
  if(sock == -1) { perror("sock");exit(-1);};
  if(connect(sock, (struct sockaddr *)&saddr, len) == -1) { perror("connect(sock, (struct sockaddr *)&saddr, len)");exit(-1);};
  puts("Connected to gateway");
  pthread_create(&pthreadSensorsRec, ((void *)0), sensorsMsgRec, ((void *)0));
  pthread_detach(pthreadSensorsRec);
  pthread_create(&pthreadSensorsSend, ((void *)0), sensorsMsgSend, ((void *)0));
  pthread_detach(pthreadSensorsSend);
}

canonical_original_code:
void sensorsNetworkStart(){
  mqSensorsSend = mq_open("/SensorsMsgSend", 02 | 0100, (0400|0200|0100), ((void *)0));
  if(mqSensorsSend == -1) { perror("mqSensorsSend");exit(-1);};
  struct sockaddr_in saddr;
  memset(&saddr, 0, sizeof(struct sockaddr_in));
  saddr.sin_addr.s_addr = inet_addr(conIP);
  saddr.sin_family = 2;
  saddr.sin_port = htons(conPort);
  unsigned int len = sizeof(struct sockaddr_in);
  sock = socket(2, SOCK_STREAM, 0);
  if(sock == -1) { perror("sock");exit(-1);};
  if(connect(sock, (struct sockaddr *)&saddr, len) == -1) { perror("connect(sock, (struct sockaddr *)&saddr, len)");exit(-1);};
  puts("Connected to gateway");
  pthread_create(&pthreadSensorsRec, ((void *)0), sensorsMsgRec, ((void *)0));
  pthread_detach(pthreadSensorsRec);
  pthread_create(&pthreadSensorsSend, ((void *)0), sensorsMsgSend, ((void *)0));
  pthread_detach(pthreadSensorsSend);
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
len
unsigned int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


sensorsNetworkStop

decompiled_code:
int sensorsNetworkStop()
{
if ( pthread_cancel(pthreadSensorsRec) == -1 )
{
perror("pthread_cancel(pthreadSensorsRec)");
exit(-1);
}
if ( pthread_cancel(pthreadSensorsSend) == -1 )
{
perror("pthread_cancel(pthreadSensorsSend)");
exit(-1);
}
if ( close(sock) == -1 )
{
perror("close(sock)");
exit(-1);
}
if ( (unsigned int)mq_close((unsigned int)mqSensorsSend) == -1 )
{
perror("mq_close(mqSensorsSend)");
exit(-1);
}
return puts("Closed");
}

canonical_decompiled_code:
int func4()
{
if ( pthread_cancel(pthreadSensorsRec) == -1 )
{
perror("pthread_cancel(pthreadSensorsRec)");
exit(-1);
}
if ( pthread_cancel(pthreadSensorsSend) == -1 )
{
perror("pthread_cancel(pthreadSensorsSend)");
exit(-1);
}
if ( close(sock) == -1 )
{
perror("close(sock)");
exit(-1);
}
if ( (unsigned int)mq_close((unsigned int)mqSensorsSend) == -1 )
{
perror("mq_close(mqSensorsSend)");
exit(-1);
}
return puts("Closed");
}

original_code:
void sensorsNetworkStop(){
  if(pthread_cancel(pthreadSensorsRec) == -1) { perror("pthread_cancel(pthreadSensorsRec)");exit(-1);};
  if(pthread_cancel(pthreadSensorsSend) == -1) { perror("pthread_cancel(pthreadSensorsSend)");exit(-1);};
  if(close(sock) == -1) { perror("close(sock)");exit(-1);};
  if(mq_close(mqSensorsSend) == -1) { perror("mq_close(mqSensorsSend)");exit(-1);};
  puts("Closed");
}


sensorsNetworkSend

decompiled_code:
__int64 __fastcall sensorsNetworkSend(__int64 a1, __int64 a2)
{
return mq_send((unsigned int)mqSensorsSend, a1, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
return mq_send((unsigned int)mqSensorsSend, a1, a2, 0LL);
}

original_code:
int sensorsNetworkSend(const char * msg_ptr, size_t msg_len){
  return mq_send( mqSensorsSend, msg_ptr, msg_len, 0);
}

canonical_original_code:
int sensorsNetworkSend(char *msg_ptr, unsigned long msg_len){
  return mq_send( mqSensorsSend, msg_ptr, msg_len, 0);
}


decompiled_code:
void __noreturn child4()
{
const char *v0; // rax

while ( 1 )
{
v0 = (const char *)getCurrentThreadName();
printf("Voila voila %s\n", v0);
sleep(1u);
}
}

canonical_decompiled_code:
void __noreturn func0()
{
const char *v0; // rax

while ( 1 )
{
v0 = (const char *)getCurrentThreadName();
printf("Voila voila %s\n", v0);
sleep(1u);
}
}

original_code:
void child4()
{
  for(;;)
  {
    printf("Voila voila %s\n", getCurrentThreadName());
    sleep(1);
  }
}


decompiled_code:
void __noreturn child3()
{
const char *v0; // rax

createGThread("process 4", child4);
while ( 1 )
{
v0 = (const char *)getCurrentThreadName();
printf("Pas mal %s!\n", v0);
sleep(1u);
}
}

canonical_decompiled_code:
void __noreturn func1()
{
const char *v0; // rax

createGThread("process 4", child4);
while ( 1 )
{
v0 = (const char *)getCurrentThreadName();
printf("Pas mal %s!\n", v0);
sleep(1u);
}
}

original_code:
void child3()
{
  createGThread("process 4", &child4);
  for(;;)
  {
      printf("Pas mal %s!\n", getCurrentThreadName());
      sleep(1);
  }
}


mess

decompiled_code:
unsigned int mess()
{
const char *v0; // rax

v0 = (const char *)getCurrentThreadName();
printf("\t%s in mess\n", v0);
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func3()
{
const char *v0; // rax

v0 = (const char *)getCurrentThreadName();
printf("\t%s in mess\n", v0);
return sleep(1u);
}

original_code:
void mess()
{
    printf("\t%s in mess\n", getCurrentThreadName());
    sleep(1);
}


child

decompiled_code:
void __noreturn child()
{
const char *v0; // rax

while ( 1 )
{
v0 = (const char *)getCurrentThreadName();
printf("Yeahhh %s\n", v0);
sleep(1u);
exitCurrentThread();
}
}

canonical_decompiled_code:
void __noreturn func2()
{
const char *v0; // rax

while ( 1 )
{
v0 = (const char *)getCurrentThreadName();
printf("Yeahhh %s\n", v0);
sleep(1u);
exitCurrentThread();
}
}

original_code:
void child()
{
    for (;;)
    {
        printf("Yeahhh %s\n", getCurrentThreadName());
 sleep(1);
 exitCurrentThread();
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
initGThreadingSystem(argc, argv, envp);
createGThread("process 1", child);
createGThread("process 2", child2);
createGThread("process 3", child3);
while ( 1 )
{
puts("main");
sleep(1u);
}
}

original_code:
int main()
{
    initGThreadingSystem();
    createGThread("process 1", &child);
    createGThread("process 2", &child2);
    createGThread("process 3", &child3);
    for(;;)
    {
      printf("main\n");
      sleep(1);
    }
    return 1;
}


decompiled_code:
void __noreturn child2()
{
const char *v0; // rax
const char *v1; // rax

while ( 1 )
{
v0 = (const char *)getCurrentThreadName();
printf("%s before mess\n", v0);
mess();
v1 = (const char *)getCurrentThreadName();
printf("%s after mess\n", v1);
}
}

canonical_decompiled_code:
void __noreturn func4()
{
const char *v0; // rax
const char *v1; // rax

while ( 1 )
{
v0 = (const char *)getCurrentThreadName();
printf("%s before mess\n", v0);
func3();
v1 = (const char *)getCurrentThreadName();
printf("%s after mess\n", v1);
}
}

original_code:
void child2()
{
  for (;;)
    {
      printf("%s before mess\n", getCurrentThreadName());
        mess();
        printf("%s after mess\n", getCurrentThreadName());
    }
}


guiMsgSend

decompiled_code:
void __fastcall __noreturn guiMsgSend(void *a1)
{
int v1; // eax
int v2; // er13
int v3; // edx
_BYTE *v4; // rbx
int v5; // ebp
int v6; // eax
_BYTE v7[8232]; // [rsp+0h] [rbp-2028h] BYREF

while ( 1 )
{
memset(v7, 0, 0x2000uLL);
v1 = mq_receive(*((unsigned int *)a1 + 10), v7, 0x2000LL, 0LL);
v2 = v1;
if ( v1 == -1 )
break;
v3 = v1;
v4 = v7;
v5 = 0;
if ( v1 > 0 )
{
do
{
v6 = send(*((_DWORD *)a1 + 4), v4, v3, 0);
v3 = v6;
if ( v6 == -1 )
{
perror("nb");
exit(-1);
}
v5 += v6;
v4 += v6;
}
while ( v2 > v5 );
}
}
perror("nb");
exit(-1);
}

original_code:
void * guiMsgSend(void* data){
  char buff[8192];
  int nb, nbSent, total;
  char* sending = (char *) buff;
  Client* client = (Client*)data;
  memset(buff, '\0', 8192);
  for(;;)
  {
    nb = mq_receive(client->mqSend, buff, 8192, ((void *)0));
    if(nb == -1) { perror("nb");exit(-1);};
    total = nb;
    nbSent = 0;
    while(nbSent < total)
    {
      nb = send(client->sock, sending, nb, 0);
      if(nb == -1) { perror("nb");exit(-1);};
      nbSent += nb;
      sending += nb;
    }
    memset(buff, '\0', 8192);
    sending = (char *) buff;
  }
}

canonical_original_code:
void *guiMsgSend(void *data){
  char buff[8192];
  int nb; int nbSent; int total;
  char *sending = (char *) buff;
  struct Client *client = (Client*)data;
  memset(buff, '\0', 8192);
  for(;;)
  {
    nb = mq_receive(client->mqSend, buff, 8192, ((void *)0));
    if(nb == -1) { perror("nb");exit(-1);};
    total = nb;
    nbSent = 0;
    while(nbSent < total)
    {
      nb = send(client->sock, sending, nb, 0);
      if(nb == -1) { perror("nb");exit(-1);};
      nbSent += nb;
      sending += nb;
    }
    memset(buff, '\0', 8192);
    sending = (char *) buff;
  }
}

variable_types:
data
void *

variable_types: struct Client { struct Client *next; struct Client *previous; int sock; unsigned long pthreadRec; unsigned long pthreadSend; int mqSend; } *


guiNetworkConnexion

decompiled_code:
void __fastcall __noreturn guiNetworkConnexion(void *a1)
{
int v1; // eax
int v2; // ebp
int v3; // eax
__int64 v4; // rdx
_QWORD *v5; // rax
__int64 v6; // rax
__int64 v7; // r13
__int64 v8; // rcx
unsigned int v9; // er12
int v10; // ebx
__int64 v11; // rax
int optval; // [rsp+8h] [rbp-70h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-6Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-68h] BYREF
struct sockaddr v15; // [rsp+20h] [rbp-58h] BYREF
char s[72]; // [rsp+30h] [rbp-48h] BYREF

addr_len = 16;
*(_QWORD *)&v15.sa_family = 0LL;
*(_QWORD *)&v15.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(lisPort);
v1 = socket(2, 1, 0);
if ( v1 != -1 )
{
v2 = v1;
optval = 1;
if ( setsockopt(v1, 1, 2, &optval, 4u) != -1 )
{
v3 = bind(v2, &addr, 0x10u);
v4 = 0LL;
if ( v3 == -1 )
{
perror("bind(acceptSock, (struct sockaddr *)&saddr, sizeof(saddr))");
exit(-1);
}
while ( 1 )
{
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v9 = v4 + 1;
sprintf(s, "/mqMsgSendNb%d", v4);
if ( listen(v2, 10) == -1 )
break;
puts("Listening");
v10 = accept(v2, &v15, &addr_len);
if ( v10 == -1 )
{
perror("tmpSock");
exit(-1);
}
puts("gotConnexion");
if ( clientList )
{
v5 = (_QWORD *)gMalloc(48LL);
*(&clientList + 1) = (__int64)v5;
*v5 = clientList;
*(_QWORD *)(*(&clientList + 1) + 8) = 0LL;
v6 = *(&clientList + 1);
*(_QWORD *)(clientList + 8) = v6;
clientList = v6;
}
else
{
clientList = gMalloc(48LL);
*(_QWORD *)clientList = 0LL;
v11 = clientList;
*(_QWORD *)(clientList + 8) = 0LL;
*(&clientList + 1) = v11;
}
v7 = *(&clientList + 1);
*(_DWORD *)(v7 + 16) = v10;
*(_DWORD *)(v7 + 40) = mq_open(s, 66LL, 448LL, 0LL);
v8 = *(&clientList + 1);
if ( *(_DWORD *)(v8 + 40) == -1 )
{
perror("clientList.current->mqSend");
exit(-1);
}
pthread_create((pthread_t *)(v8 + 24), 0LL, guiMsgRec, (void *)v8);
pthread_detach(*(_QWORD *)(*(&clientList + 1) + 24));
pthread_create(
(pthread_t *)(*(&clientList + 1) + 32),
0LL,
(void *(*)(void *))guiMsgSend,
(void *)*(&clientList + 1));
pthread_detach(*(_QWORD *)(*(&clientList + 1) + 32));
v4 = v9;
}
perror("listen(acceptSock, 10)");
exit(-1);
}
perror("setsockopt(acceptSock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval)");
exit(-1);
}
perror("acceptSock");
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(void *a1)
{
int v1; // eax
int v2; // ebp
int v3; // eax
__int64 v4; // rdx
_QWORD *v5; // rax
__int64 v6; // rax
__int64 v7; // r13
__int64 v8; // rcx
unsigned int v9; // er12
int v10; // ebx
__int64 v11; // rax
int optval; // [rsp+8h] [rbp-70h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-6Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-68h] BYREF
struct sockaddr v15; // [rsp+20h] [rbp-58h] BYREF
char s[72]; // [rsp+30h] [rbp-48h] BYREF

addr_len = 16;
*(_QWORD *)&v15.sa_family = 0LL;
*(_QWORD *)&v15.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = func1(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func2(lisPort);
v1 = socket(2, 1, 0);
if ( v1 != -1 )
{
v2 = v1;
optval = 1;
if ( setsockopt(v1, 1, 2, &optval, 4u) != -1 )
{
v3 = bind(v2, &addr, 0x10u);
v4 = 0LL;
if ( v3 == -1 )
{
perror("bind(acceptSock, (struct sockaddr *)&saddr, sizeof(saddr))");
exit(-1);
}
while ( 1 )
{
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v9 = v4 + 1;
sprintf(s, "/mqMsgSendNb%d", v4);
if ( listen(v2, 10) == -1 )
break;
puts("Listening");
v10 = accept(v2, &v15, &addr_len);
if ( v10 == -1 )
{
perror("tmpSock");
exit(-1);
}
puts("gotConnexion");
if ( clientList )
{
v5 = (_QWORD *)gMalloc(48LL);
*(&clientList + 1) = (__int64)v5;
*v5 = clientList;
*(_QWORD *)(*(&clientList + 1) + 8) = 0LL;
v6 = *(&clientList + 1);
*(_QWORD *)(clientList + 8) = v6;
clientList = v6;
}
else
{
clientList = gMalloc(48LL);
*(_QWORD *)clientList = 0LL;
v11 = clientList;
*(_QWORD *)(clientList + 8) = 0LL;
*(&clientList + 1) = v11;
}
v7 = *(&clientList + 1);
*(_DWORD *)(v7 + 16) = v10;
*(_DWORD *)(v7 + 40) = mq_open(s, 66LL, 448LL, 0LL);
v8 = *(&clientList + 1);
if ( *(_DWORD *)(v8 + 40) == -1 )
{
perror("clientList.current->mqSend");
exit(-1);
}
pthread_create((pthread_t *)(v8 + 24), 0LL, guiMsgRec, (void *)v8);
pthread_detach(*(_QWORD *)(*(&clientList + 1) + 24));
pthread_create(
(pthread_t *)(*(&clientList + 1) + 32),
0LL,
(void *(*)(void *))guiMsgSend,
(void *)*(&clientList + 1));
pthread_detach(*(_QWORD *)(*(&clientList + 1) + 32));
v4 = v9;
}
perror("listen(acceptSock, 10)");
exit(-1);
}
perror("setsockopt(acceptSock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval)");
exit(-1);
}
perror("acceptSock");
exit(-1);
}

original_code:
void * guiNetworkConnexion(){
  int acceptSock, tmpSock;
  int i = 0;
  char name[32];
  struct sockaddr_in saddr_client;
  struct sockaddr_in saddr;
  socklen_t size_addr = sizeof(struct sockaddr_in);
  memset(&saddr_client, 0, sizeof(struct sockaddr_in));
  saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  saddr.sin_family = 2;
  saddr.sin_port = htons(lisPort);
  acceptSock = socket(2, SOCK_STREAM, 0);
  if(acceptSock == -1) { perror("acceptSock");exit(-1);};
  int optval;
  int optlen;
  char *optval2;
  optval = 1;
  if(setsockopt(acceptSock, 1, 2, &optval, sizeof optval) == -1) { perror("setsockopt(acceptSock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval)");exit(-1);};
  if(bind(acceptSock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(acceptSock, (struct sockaddr *)&saddr, sizeof(saddr))");exit(-1);};
  for(;;){
    memset(&saddr, 0, sizeof(struct sockaddr_in));
    sprintf(name, "/mqMsgSendNb%d", i++);
    if(listen(acceptSock, 10) == -1) { perror("listen(acceptSock, 10)");exit(-1);};
    puts("Listening");
    tmpSock = accept(acceptSock, (struct sockaddr *)&saddr_client, &size_addr);
    if(tmpSock == -1) { perror("tmpSock");exit(-1);};
    puts("gotConnexion");
    if(clientList.first == ((void *)0)){
      clientList.first = gMalloc(sizeof(Client));
      clientList.first->next = ((void *)0);
      clientList.first->previous = ((void *)0);
      clientList.current = clientList.first;
    }
    else{
      clientList.current = gMalloc(sizeof(Client));
      clientList.current->next = clientList.first;
      clientList.current->previous = ((void *)0);
      clientList.first->previous = clientList.current;
      clientList.first = clientList.current;
    }
    clientList.current->sock = tmpSock;
    clientList.current->mqSend = mq_open(name, 02 | 0100, (0400|0200|0100), ((void *)0));
    if(clientList.current->mqSend == -1) { perror("clientList.current->mqSend");exit(-1);};
    pthread_create(&clientList.current->pthreadRec, ((void *)0), guiMsgRec, (void*)clientList.current);
    pthread_detach(clientList.current->pthreadRec);
    pthread_create(&clientList.current->pthreadSend, ((void *)0), guiMsgSend, (void*)clientList.current);
    pthread_detach(clientList.current->pthreadSend);
  }
}

canonical_original_code:
void *guiNetworkConnexion(){
  int acceptSock; int tmpSock;
  int i = 0;
  char name[32];
  struct sockaddr_in saddr_client;
  struct sockaddr_in saddr;
  unsigned int size_addr = sizeof(struct sockaddr_in);
  memset(&saddr_client, 0, sizeof(struct sockaddr_in));
  saddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  saddr.sin_family = 2;
  saddr.sin_port = htons(lisPort);
  acceptSock = socket(2, SOCK_STREAM, 0);
  if(acceptSock == -1) { perror("acceptSock");exit(-1);};
  int optval;
  int optlen;
  char *optval2;
  optval = 1;
  if(setsockopt(acceptSock, 1, 2, &optval, sizeof optval) == -1) { perror("setsockopt(acceptSock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval)");exit(-1);};
  if(bind(acceptSock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(acceptSock, (struct sockaddr *)&saddr, sizeof(saddr))");exit(-1);};
  for(;;){
    memset(&saddr, 0, sizeof(struct sockaddr_in));
    sprintf(name, "/mqMsgSendNb%d", i++);
    if(listen(acceptSock, 10) == -1) { perror("listen(acceptSock, 10)");exit(-1);};
    puts("Listening");
    tmpSock = accept(acceptSock, (struct sockaddr *)&saddr_client, &size_addr);
    if(tmpSock == -1) { perror("tmpSock");exit(-1);};
    puts("gotConnexion");
    if(clientList.first == ((void *)0)){
      clientList.first = gMalloc(sizeof(Client));
      clientList.first->next = ((void *)0);
      clientList.first->previous = ((void *)0);
      clientList.current = clientList.first;
    }
    else{
      clientList.current = gMalloc(sizeof(Client));
      clientList.current->next = clientList.first;
      clientList.current->previous = ((void *)0);
      clientList.first->previous = clientList.current;
      clientList.first = clientList.current;
    }
    clientList.current->sock = tmpSock;
    clientList.current->mqSend = mq_open(name, 02 | 0100, (0400|0200|0100), ((void *)0));
    if(clientList.current->mqSend == -1) { perror("clientList.current->mqSend");exit(-1);};
    pthread_create(&clientList.current->pthreadRec, ((void *)0), guiMsgRec, (void *)clientList.current);
    pthread_detach(clientList.current->pthreadRec);
    pthread_create(&clientList.current->pthreadSend, ((void *)0), guiMsgSend, (void *)clientList.current);
    pthread_detach(clientList.current->pthreadSend);
  }
}

variable_types: acceptSock int

variable_types: tmpSock int

variable_types: i int

variable_types:
name
char [32]

variable_types: optval int

variable_types: optlen int


cleanClient

decompiled_code:
__int64 __fastcall cleanClient(__int64 a1)
{
_QWORD *v1; // rax

if ( pthread_cancel(*(_QWORD *)(a1 + 32)) == -1 )
{
perror("pthread_cancel(client->pthreadSend)");
exit(-1);
}
if ( pthread_cancel(*(_QWORD *)(a1 + 24)) == -1 )
{
perror("pthread_cancel(client->pthreadRec)");
exit(-1);
}
close(*(_DWORD *)(a1 + 16));
if ( (unsigned int)mq_close(*(unsigned int *)(a1 + 40)) == -1 )
{
perror("mq_close(client->mqSend)");
exit(-1);
}
v1 = *(_QWORD **)(a1 + 8);
*(_QWORD *)(*(_QWORD *)a1 + 8LL) = v1;
*v1 = *(_QWORD *)a1;
return gFree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_QWORD *v1; // rax

if ( pthread_cancel(*(_QWORD *)(a1 + 32)) == -1 )
{
perror("pthread_cancel(client->pthreadSend)");
exit(-1);
}
if ( pthread_cancel(*(_QWORD *)(a1 + 24)) == -1 )
{
perror("pthread_cancel(client->pthreadRec)");
exit(-1);
}
close(*(_DWORD *)(a1 + 16));
if ( (unsigned int)mq_close(*(unsigned int *)(a1 + 40)) == -1 )
{
perror("mq_close(client->mqSend)");
exit(-1);
}
v1 = *(_QWORD **)(a1 + 8);
*(_QWORD *)(*(_QWORD *)a1 + 8LL) = v1;
*v1 = *(_QWORD *)a1;
return gFree(a1);
}

original_code:
void cleanClient(Client * client){
    if(pthread_cancel(client->pthreadSend) == -1) { perror("pthread_cancel(client->pthreadSend)");exit(-1);};
    if(pthread_cancel(client->pthreadRec) == -1) { perror("pthread_cancel(client->pthreadRec)");exit(-1);};
    close(client->sock);
    if(mq_close(client->mqSend) == -1) { perror("mq_close(client->mqSend)");exit(-1);};
    client->next->previous = client->previous;
    client->previous->next = client->next;
    gFree(client);
}

canonical_original_code:
void cleanClient(struct Client *client){
    if(pthread_cancel(client->pthreadSend) == -1) { perror("pthread_cancel(client->pthreadSend)");exit(-1);};
    if(pthread_cancel(client->pthreadRec) == -1) { perror("pthread_cancel(client->pthreadRec)");exit(-1);};
    close(client->sock);
    if(mq_close(client->mqSend) == -1) { perror("mq_close(client->mqSend)");exit(-1);};
    client->next->previous = client->previous;
    client->previous->next = client->next;
    gFree(client);
}

user_defined_types: struct Client { struct Client *next; struct Client *previous; int sock; unsigned long pthreadRec; unsigned long pthreadSend; int mqSend; }


guiMsgRec

decompiled_code:
void __fastcall __noreturn guiMsgRec(void *a1)
{
int v1; // ebp
int v2; // er12
size_t i; // rbx
char v4; // al
char v5[8192]; // [rsp+0h] [rbp-4028h] BYREF
char buf[8232]; // [rsp+2000h] [rbp-2028h] BYREF

memset(buf, 0, 0x2000uLL);
memset(v5, 0, sizeof(v5));
v1 = 0;
v2 = 0;
while ( (unsigned int)recv(*((_DWORD *)a1 + 4), buf, 0x2000uLL, 0) != -1 )
{
if ( !buf[0] )
cleanClient((__int64)a1);
for ( i = 0LL; i < strlen(buf); ++i )
{
v4 = buf[i];
v5[v2] = v4;
if ( v4 == 123 )
++v1;
else
v1 -= v4 == 125;
++v2;
if ( !v1 )
{
processCommand(v5, *((unsigned int *)a1 + 10));
memset(v5, 0, sizeof(v5));
v2 = 0;
}
}
memset(buf, 0, 0x2000uLL);
}
perror("nb");
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(void *a1)
{
int v1; // ebp
int v2; // er12
size_t i; // rbx
char v4; // al
char v5[8192]; // [rsp+0h] [rbp-4028h] BYREF
char buf[8232]; // [rsp+2000h] [rbp-2028h] BYREF

memset(buf, 0, 0x2000uLL);
memset(v5, 0, sizeof(v5));
v1 = 0;
v2 = 0;
while ( (unsigned int)recv(*((_DWORD *)a1 + 4), buf, 0x2000uLL, 0) != -1 )
{
if ( !buf[0] )
func4((__int64)a1);
for ( i = 0LL; i < strlen(buf); ++i )
{
v4 = buf[i];
v5[v2] = v4;
if ( v4 == 123 )
++v1;
else
v1 -= v4 == 125;
++v2;
if ( !v1 )
{
processCommand(v5, *((unsigned int *)a1 + 10));
memset(v5, 0, sizeof(v5));
v2 = 0;
}
}
memset(buf, 0, 0x2000uLL);
}
perror("nb");
exit(-1);
}

original_code:
void * guiMsgRec(void* data){
  char buff[8192];
  char traite[8192];
  int i, j, nb, blocs;
  Client* client = (Client*)data;
  memset(buff, '\0', 8192);
  memset(traite, '\0', 8192);
  blocs = 0;
  j = 0;
  for(;;)
  {
    nb = recv(client->sock, buff, 8192, 0);
    if(nb == -1) { perror("nb");exit(-1);};
    if(strlen(buff) == 0){
      cleanClient(client);
    }
    i = 0;
    while(i < (strlen(buff))){
      traite[j++] = buff[i];
      if(buff[i] == '{'){
        ++blocs;
      } else if(buff[i] == '}'){
        --blocs;
      }
      if(blocs == 0){
        processCommand(traite, client->mqSend);
        j = 0;
        blocs = 0;
        memset(traite, '\0', 8192);
      }
      ++i;
    }
    memset(buff, '\0', 8192);
  }
}

canonical_original_code:
void *guiMsgRec(void *data){
  char buff[8192];
  char traite[8192];
  int i; int j; int nb; int blocs;
  struct Client *client = (Client*)data;
  memset(buff, '\0', 8192);
  memset(traite, '\0', 8192);
  blocs = 0;
  j = 0;
  for(;;)
  {
    nb = recv(client->sock, buff, 8192, 0);
    if(nb == -1) { perror("nb");exit(-1);};
    if(strlen(buff) == 0){
      cleanClient(client);
    }
    i = 0;
    while(i < (strlen(buff))){
      traite[j++] = buff[i];
      if(buff[i] == '{'){
        ++blocs;
      } else if(buff[i] == '}'){
        --blocs;
      }
      if(blocs == 0){
        processCommand(traite, client->mqSend);
        j = 0;
        blocs = 0;
        memset(traite, '\0', 8192);
      }
      ++i;
    }
    memset(buff, '\0', 8192);
  }
}

variable_types:
traite
char [8192]

variable_types: j int

variable_types: blocs int


guiNetworkStart

decompiled_code:
int guiNetworkStart()
{
clientList = 0LL;
pthread_create(&pthreadConnexion, 0LL, (void *(*)(void *))guiNetworkConnexion, 0LL);
return pthread_detach(pthreadConnexion);
}

canonical_decompiled_code:
int func6()
{
clientList = 0LL;
pthread_create(&pthreadConnexion, 0LL, (void *(*)(void *))guiNetworkConnexion, 0LL);
return pthread_detach(pthreadConnexion);
}

original_code:
void guiNetworkStart(){
  clientList.first = ((void *)0);
  pthread_create(&pthreadConnexion, ((void *)0), guiNetworkConnexion, ((void *)0));
  pthread_detach(pthreadConnexion);
}


guiNetworkStop

decompiled_code:
int guiNetworkStop()
{
__int64 i; // rax
__int64 *v1; // rdi

if ( pthread_cancel(pthreadConnexion) == -1 )
{
perror("pthread_cancel(pthreadConnexion)");
exit(-1);
}
for ( i = clientList; clientList; i = clientList )
{
if ( pthread_cancel(*(_QWORD *)(i + 32)) == -1 )
{
perror("pthread_cancel(clientList.first->pthreadSend)");
exit(-1);
}
if ( pthread_cancel(*(_QWORD *)(clientList + 24)) == -1 )
{
perror("pthread_cancel(clientList.first->pthreadRec)");
exit(-1);
}
close(*(_DWORD *)(clientList + 16));
if ( (unsigned int)mq_close(*(unsigned int *)(clientList + 40)) == -1 )
{
perror("mq_close(clientList.first->mqSend)");
exit(-1);
}
v1 = (__int64 *)clientList;
*(&clientList + 1) = clientList;
clientList = *v1;
gFree(v1);
}
return puts("Closed");
}

canonical_decompiled_code:
int func7()
{
__int64 i; // rax
__int64 *v1; // rdi

if ( pthread_cancel(pthreadConnexion) == -1 )
{
perror("pthread_cancel(pthreadConnexion)");
exit(-1);
}
for ( i = clientList; clientList; i = clientList )
{
if ( pthread_cancel(*(_QWORD *)(i + 32)) == -1 )
{
perror("pthread_cancel(clientList.first->pthreadSend)");
exit(-1);
}
if ( pthread_cancel(*(_QWORD *)(clientList + 24)) == -1 )
{
perror("pthread_cancel(clientList.first->pthreadRec)");
exit(-1);
}
close(*(_DWORD *)(clientList + 16));
if ( (unsigned int)mq_close(*(unsigned int *)(clientList + 40)) == -1 )
{
perror("mq_close(clientList.first->mqSend)");
exit(-1);
}
v1 = (__int64 *)clientList;
*(&clientList + 1) = clientList;
clientList = *v1;
gFree(v1);
}
return puts("Closed");
}

original_code:
void guiNetworkStop(){
  if(pthread_cancel(pthreadConnexion) == -1) { perror("pthread_cancel(pthreadConnexion)");exit(-1);};
  while(clientList.first != ((void *)0)){
    if(pthread_cancel(clientList.first->pthreadSend) == -1) { perror("pthread_cancel(clientList.first->pthreadSend)");exit(-1);};
    if(pthread_cancel(clientList.first->pthreadRec) == -1) { perror("pthread_cancel(clientList.first->pthreadRec)");exit(-1);};
    close(clientList.first->sock);
    if(mq_close(clientList.first->mqSend) == -1) { perror("mq_close(clientList.first->mqSend)");exit(-1);};
    clientList.current = clientList.first;
    clientList.first = clientList.first->next;
    gFree(clientList.current);
  }
  puts("Closed");
}


guiNetworkSend

decompiled_code:
__int64 __fastcall guiNetworkSend(__int64 a1, __int64 a2, unsigned int a3)
{
return mq_send(a3, a1, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3)
{
return mq_send(a3, a1, a2, 0LL);
}

original_code:
int guiNetworkSend(const char * msg_ptr, size_t msg_len, mqd_t mqId){
  return mq_send( mqId, msg_ptr, msg_len, 0);
}

canonical_original_code:
int guiNetworkSend(char *msg_ptr, unsigned long msg_len, int mqId){
  return mq_send( mqId, msg_ptr, msg_len, 0);
}

variable_types: mqId int


init

decompiled_code:
__int64 init()
{
__int64 v0; // rax
__int64 v1; // rax

puts("Initialisation...");
initMemory();
v0 = getGMemTotal();
printf("MemTotale: %ld\n", v0);
v1 = getGMemFree();
printf("MemFree: %ld\n", v1);
pthread_mutex_init(&sensorsMutex, 0LL);
parseAll();
parseConfig();
initRules();
startTimedCheck(60LL);
sensorsNetworkStart();
return guiNetworkStart();
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rax

puts("Initialisation...");
initMemory();
v0 = getGMemTotal();
printf("MemTotale: %ld\n", v0);
v1 = getGMemFree();
printf("MemFree: %ld\n", v1);
pthread_mutex_init(&sensorsMutex, 0LL);
parseAll();
parseConfig();
initRules();
startTimedCheck(60LL);
sensorsNetworkStart();
return guiNetworkStart();
}

original_code:
void init()
{
  printf("Initialisation...\n");
  initMemory();
  printf("MemTotale: %ld\n", getGMemTotal());
  printf("MemFree: %ld\n", getGMemFree());
  pthread_mutex_init(&sensorsMutex, ((void *)0));
  parseAll();
  parseConfig();
  initRules();
  startTimedCheck(60);
  sensorsNetworkStart();
  guiNetworkStart();
}


cleanMemory

decompiled_code:
__int64 cleanMemory()
{
cleanActions();
cleanRules();
cleanActionneurs();
return cleanSensors();
}

canonical_decompiled_code:
__int64 func1()
{
cleanActions();
cleanRules();
cleanActionneurs();
return cleanSensors();
}

original_code:
void cleanMemory(){
  cleanActions();
  cleanRules();
  cleanActionneurs();
  cleanSensors();
}


destroy

decompiled_code:
__int64 destroy()
{
guiNetworkStop();
sensorsNetworkStop();
stopTimedCheck();
stopRules();
pthread_mutex_destroy(&sensorsMutex);
cleanMemory();
gFree(nameLogRules);
return destroyMemory();
}

canonical_decompiled_code:
__int64 func2()
{
guiNetworkStop();
sensorsNetworkStop();
stopTimedCheck();
stopRules();
pthread_mutex_destroy(&sensorsMutex);
func1();
gFree(nameLogRules);
return destroyMemory();
}

original_code:
void destroy()
{
  guiNetworkStop();
  sensorsNetworkStop();
  stopTimedCheck();
  stopRules();
  pthread_mutex_destroy(&sensorsMutex);
  cleanMemory();
  gFree(nameLogRules);
  destroyMemory();
}


catchedAlarmDone

decompiled_code:
void catchedAlarmDone()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void catchedAlarmDone(int sig_num) {
}

canonical_original_code:
void catchedAlarmDone(int sig_num) {
}


catchedAlarm

decompiled_code:
void catchedAlarm()
{
sem_post(&checkRules);
alarm(sleepTime);
}

canonical_decompiled_code:
void func1()
{
sem_post(&checkRules);
alarm(sleepTime);
}

original_code:
void catchedAlarm(int sig_num) {
      sem_post(&checkRules);
      alarm(sleepTime);
}


startTimedCheck

decompiled_code:
unsigned int __fastcall startTimedCheck(unsigned int seconds)
{
signal(14, (__sighandler_t)catchedAlarm);
sleepTime = seconds;
return alarm(seconds);
}

canonical_decompiled_code:
unsigned int __fastcall func2(unsigned int seconds)
{
signal(14, (__sighandler_t)catchedAlarm);
sleepTime = seconds;
return alarm(seconds);
}

original_code:
void startTimedCheck(int nbSec){
  signal(14, catchedAlarm);
  sleepTime = nbSec;
  alarm(sleepTime);
}

variable_types: nbSec int


stopTimedCheck

decompiled_code:
__sighandler_t stopTimedCheck()
{
return signal(14, (__sighandler_t)catchedAlarmDone);
}

canonical_decompiled_code:
__sighandler_t func3()
{
return signal(14, (__sighandler_t)catchedAlarmDone);
}

original_code:
void stopTimedCheck(){
  signal(14, catchedAlarmDone);
}


watchLogRules

decompiled_code:
void watchLogRules()
{
if ( !onGoingR )
{
onGoingR = 1;
logRules = (__int64)watchLog((const char *)nameLogRules);
}
}

canonical_decompiled_code:
void func1()
{
if ( !onGoingR )
{
onGoingR = 1;
logRules = (__int64)watchLog((const char *)nameLogRules);
}
}

original_code:
void watchLogRules(){
  if(onGoingR == 0){
    onGoingR = 1;
    logRules = watchLog(nameLogRules);
  }
}


watchLogSensors

decompiled_code:
void watchLogSensors()
{
if ( !onGoingS )
{
onGoingS = 1;
logSensors = (__int64)watchLog((const char *)nameLogSensors);
}
}

canonical_decompiled_code:
void func2()
{
if ( !onGoingS )
{
onGoingS = 1;
logSensors = (__int64)watchLog((const char *)nameLogSensors);
}
}

original_code:
void watchLogSensors(){
  if(onGoingS == 0){
    onGoingS = 1;
    logSensors = watchLog(nameLogSensors);
  }
}


stopWatchingLogs

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

result = system("killall -q tail");
if ( onGoingR == 1 )
{
result = stopWatching((FILE *)logRules);
onGoingR = 0;
}
if ( onGoingS == 1 )
{
result = stopWatching((FILE *)logSensors);
onGoingS = 0;
}
return result;
}

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

result = system("killall -q tail");
if ( onGoingR == 1 )
{
result = func0((FILE *)logRules);
onGoingR = 0;
}
if ( onGoingS == 1 )
{
result = func0((FILE *)logSensors);
onGoingS = 0;
}
return result;
}

original_code:
void stopWatchingLogs(){
  system("killall -q tail");
  if(onGoingR == 1){
    stopWatching(logRules);
    onGoingR = 0;
  }
  if(onGoingS == 1){
    stopWatching(logSensors);
    onGoingS = 0;
  }
}


getAction

decompiled_code:
char *__fastcall getAction(char *s2)
{
char *v1; // rbx

v1 = actions;
if ( actions )
{
while ( strcmp(v1, s2) )
{
v1 = (char *)*((_QWORD *)v1 + 4);
if ( !v1 )
goto LABEL_4;
}
}
else
{
LABEL_4:
printf("Action not recognized : %s !!!\n", s2);
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func0(char *s2)
{
char *v1; // rbx

v1 = actions;
if ( actions )
{
while ( strcmp(v1, s2) )
{
v1 = (char *)*((_QWORD *)v1 + 4);
if ( !v1 )
goto LABEL_4;
}
}
else
{
LABEL_4:
printf("Action not recognized : %s !!!\n", s2);
v1 = 0LL;
}
return v1;
}

original_code:
struct action_t * getAction(const char nom[20]) {
  struct action_t * current = actions;
  while (current != 0) {
    if (strcmp(current->nom, nom) == 0) {
      return current;
    }
    current = current->nextAction;
  }
  printf("Action not recognized : %s !!!\n", nom);
  return 0;
}

canonical_original_code:
struct action_t *getAction(char nom[20]) {
  struct action_t *current = actions;
  while (current != 0) {
    if (strcmp(current->nom, nom) == 0) {
      return current;
    }
    current = current->nextAction;
  }
  printf("Action not recognized : %s !!!\n", nom);
  return 0;
}

variable_types:
nom
char [20]

variable_types: struct action_t { char nom[20]; struct actionFct_t { void (*fct)(char [9]); struct actionneur_t { enum typeActionneur { COURRANT=0, VOLETS=1, CAFFE=2, CHAUFFAGE=3, VIRTUALKEYBOARD=4, MYSTERE=5 } type; char id[9]; char name[20]; struct actionneur_t *nextActionneur; } *actionneur; struct actionFct_t *nextActionFct; } *actionFcts; struct action_t *nextAction; } *

user_defined_types: struct action_t { char nom[20]; struct actionFct_t *actionFcts; struct action_t *nextAction; }


applyAction

decompiled_code:
__int64 __fastcall applyAction(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *(_QWORD *)(a1 + 24); i; i = *(_QWORD *)(i + 16) )
result = (*(__int64 (__fastcall **)(__int64))i)(*(_QWORD *)(i + 8) + 4LL);
return result;
}

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

for ( i = *(_QWORD *)(a1 + 24); i; i = *(_QWORD *)(i + 16) )
result = (*(__int64 (__fastcall **)(__int64))i)(*(_QWORD *)(i + 8) + 4LL);
return result;
}

original_code:
void applyAction(struct action_t * action){
  struct actionFct_t * current = action->actionFcts;
  while (current != 0) {
    current->fct(current->actionneur->id);
    current = current->nextActionFct;
  }
}

canonical_original_code:
void applyAction(struct action_t *action){
  struct actionFct_t *current = action->actionFcts;
  while (current != 0) {
    current->fct(current->actionneur->id);
    current = current->nextActionFct;
  }
}

variable_types: struct actionFct_t { void (*fct)(char [9]); struct actionneur_t { enum typeActionneur { COURRANT=0, VOLETS=1, CAFFE=2, CHAUFFAGE=3, VIRTUALKEYBOARD=4, MYSTERE=5 } type; char id[9]; char name[20]; struct actionneur_t *nextActionneur; } *actionneur; struct actionFct_t *nextActionFct; } *


applyActionByName

decompiled_code:
__int64 __fastcall applyActionByName(char *a1)
{
char *v1; // rax

v1 = getAction(a1);
return applyAction((__int64)v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char *v1; // rax

v1 = func0(a1);
return func1((__int64)v1);
}

original_code:
void applyActionByName(const char nom[20]){
  applyAction(getAction(nom));
}

canonical_original_code:
void applyActionByName(char nom[20]){
  applyAction(getAction(nom));
}


cleanActions

decompiled_code:
void cleanActions()
{
char *v0; // rax
__int64 i; // rdi

while ( actions )
{
v0 = actions;
for ( i = *((_QWORD *)actions + 3); i; i = *((_QWORD *)actions + 3) )
{
*((_QWORD *)v0 + 3) = *(_QWORD *)(i + 16);
((void (*)(void))gFree)();
v0 = actions;
}
actions = (char *)*((_QWORD *)v0 + 4);
gFree(v0);
}
}

canonical_decompiled_code:
void func3()
{
char *v0; // rax
__int64 i; // rdi

while ( actions )
{
v0 = actions;
for ( i = *((_QWORD *)actions + 3); i; i = *((_QWORD *)actions + 3) )
{
*((_QWORD *)v0 + 3) = *(_QWORD *)(i + 16);
((void (*)(void))gFree)();
v0 = actions;
}
actions = (char *)*((_QWORD *)v0 + 4);
gFree(v0);
}
}

original_code:
void cleanActions(){
  struct action_t * cAction;
  struct actionFct_t * cActionFct;
  while(actions != ((void *)0)){
    while(actions->actionFcts != ((void *)0)){
      cActionFct = actions->actionFcts;
      actions->actionFcts = actions->actionFcts->nextActionFct;
      gFree(cActionFct);
    }
    cAction = actions;
    actions = actions->nextAction;
    gFree(cAction);
  }
}

canonical_original_code:
void cleanActions(){
  struct action_t *cAction;
  struct actionFct_t *cActionFct;
  while(actions != ((void *)0)){
    while(actions->actionFcts != ((void *)0)){
      cActionFct = actions->actionFcts;
      actions->actionFcts = actions->actionFcts->nextActionFct;
      gFree(cActionFct);
    }
    cAction = actions;
    actions = actions->nextAction;
    gFree(cAction);
  }
}