decompiled_code:
void __fastcall CServerTcpIP_DelClient(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rax
_QWORD *v4; // rcx

if ( a2 && a1 )
{
v2 = *(_QWORD **)(a1 + 56);
if ( v2 )
{
if ( v2 == a2 )
{
CServerTcpIP_FreeClient(a2);
*(_QWORD *)(a1 + 56) = a2[3];
--*(_DWORD *)(a1 + 64);
}
else
{
v3 = (_QWORD *)v2[3];
v4 = 0LL;
while ( v3 != a2 )
{
v4 = v3;
if ( !v3[3] )
{
printf("%s @ %d : Client fantome !\n", "CServerTcpIP_DelClient", 164LL);
return;
}
v3 = (_QWORD *)v3[3];
}
v4[3] = a2[3];
--*(_DWORD *)(a1 + 64);
CServerTcpIP_FreeClient(a2);
}
}
else
{
printf("%s @ %d : Client fantome !\n", "CServerTcpIP_DelClient", 147LL);
}
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rax
_QWORD *v4; // rcx

if ( a2 && a1 )
{
v2 = *(_QWORD **)(a1 + 56);
if ( v2 )
{
if ( v2 == a2 )
{
func6(a2);
*(_QWORD *)(a1 + 56) = a2[3];
--*(_DWORD *)(a1 + 64);
}
else
{
v3 = (_QWORD *)v2[3];
v4 = 0LL;
while ( v3 != a2 )
{
v4 = v3;
if ( !v3[3] )
{
printf("%s @ %d : Client fantome !\n", "CServerTcpIP_DelClient", 164LL);
return;
}
v3 = (_QWORD *)v3[3];
}
v4[3] = a2[3];
--*(_DWORD *)(a1 + 64);
func6(a2);
}
}
else
{
printf("%s @ %d : Client fantome !\n", "CServerTcpIP_DelClient", 147LL);
}
}
}

original_code:
void CServerTcpIP_DelClient (CServerTcpIP *this, Client *client)
{
 Client *curseur;
 Client *curseur_prec = ((void *)0);
 if (this == (CServerTcpIP *) ((void *)0))
  return;
 if (client == (Client *) ((void *)0))
  return;
 if (this->m_clistClients == (Client *) ((void *)0)) {
  printf("%s @ %d : " "Client fantome !\n", __FUNCTION__, 147);
  return;
 }
 if (this->m_clistClients == client) {
  CServerTcpIP_FreeClient (client);
  this->m_clistClients = client->next;
  this->m_iClientNumber = this->m_iClientNumber - 1;
  return;
 }
 curseur = this->m_clistClients->next;
 while (curseur != client) {
  curseur_prec = curseur;
  curseur = curseur->next;
  if (curseur == (Client *) ((void *)0)){
   printf("%s @ %d : " "Client fantome !\n", __FUNCTION__, 164);
   return;
  }
 }
 curseur_prec->next = curseur->next;
 this->m_iClientNumber = this->m_iClientNumber - 1;
 CServerTcpIP_FreeClient (curseur);
}

canonical_original_code:
void CServerTcpIP_DelClient(struct _CServerTcpIP *this, struct _Client *client)
{
 struct _Client *curseur;
 struct _Client *curseur_prec = ((void *)0);
 if (this == (struct _CServerTcpIP *) ((void *)0))
  return;
 if (client == (struct _Client *) ((void *)0))
  return;
 if (this->m_clistClients == (struct _Client *) ((void *)0)) {
  printf("%s @ %d : " "Client fantome !\n", __FUNCTION__, 147);
  return;
 }
 if (this->m_clistClients == client) {
  CServerTcpIP_FreeClient (client);
  this->m_clistClients = client->next;
  this->m_iClientNumber = this->m_iClientNumber - 1;
  return;
 }
 curseur = this->m_clistClients->next;
 while (curseur != client) {
  curseur_prec = curseur;
  curseur = curseur->next;
  if (curseur == (struct _Client *) ((void *)0)){
   printf("%s @ %d : " "Client fantome !\n", __FUNCTION__, 164);
   return;
  }
 }
 curseur_prec->next = curseur->next;
 this->m_iClientNumber = this->m_iClientNumber - 1;
 CServerTcpIP_FreeClient (curseur);
}


decompiled_code:
void __fastcall __noreturn CServerTcpIP_Runtime(void *a1)
{
int v1; // eax
__int64 v2; // rbx
_QWORD *v3; // r15
int v4; // eax
char *v5; // rax
unsigned __int16 v6; // ax
void (__fastcall *v7)(void *, _QWORD *, _QWORD); // rax
__int16 v8; // ax
void (__fastcall *v9)(char *, _QWORD, void *, __int64, _QWORD); // r15
__int64 v10; // rax
_QWORD *v11; // rax
int v12; // er13
struct pollfd *v13; // rbp
__int64 v14; // rdx
struct pollfd *v15; // rax
int v16; // [rsp+8h] [rbp-2870h]
char *v17; // [rsp+8h] [rbp-2870h]
int v18; // [rsp+10h] [rbp-2868h]
socklen_t addr_len; // [rsp+2Ch] [rbp-284Ch] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-2848h] BYREF
char s[10296]; // [rsp+40h] [rbp-2838h] BYREF

addr_len = 16;
pthread_setcancelstate(0, 0LL);
pthread_setcanceltype(0, 0LL);
LABEL_26:
while ( 1 )
{
v12 = *((_DWORD *)a1 + 16);
v13 = (struct pollfd *)malloc(8LL * (v12 + 1));
if ( v13 )
break;
printf("%s @ %d : Erreur critique sur l'allocation de pfd\n", "CServerTcpIP_Runtime", 253LL);
}
v13->fd = *((_DWORD *)a1 + 10);
v13->events = 3;
v14 = *((_QWORD *)a1 + 7);
if ( v12 > 0 )
{
v15 = v13 + 1;
do
{
v15->fd = *(_DWORD *)v14;
v15->events = 3;
v14 = *(_QWORD *)(v14 + 24);
++v15;
}
while ( v15 != &v13[(unsigned int)(v12 - 1) + 2] );
}
do
{
LABEL_4:
while ( 1 )
{
pthread_testcancel();
v1 = poll(v13, v12 + 1, 5000);
if ( v1 >= 0 )
break;
printf("%s @ %d : Erreur sur le poll\n", "CServerTcpIP_Runtime", 276LL);
}
}
while ( !v1 || v12 + 1 <= 0 );
v2 = 0LL;
v16 = 0;
while ( 1 )
{
v8 = v13[v2].revents;
if ( (v8 & 3) != 0 )
{
if ( (_DWORD)v2 )
{
memset(s, 0, 0x2800uLL);
v18 = recv(v13[v2].fd, s, 0x2800uLL, 0);
if ( v18 <= 0 )
{
LABEL_21:
v11 = (_QWORD *)CServerTcpIP_FindClient((__int64)a1, v13[v2].fd);
CServerTcpIP_DelClient((__int64)a1, v11);
LABEL_22:
if ( v12 <= (int)v2 )
goto LABEL_25;
v16 = 1;
goto LABEL_15;
}
v9 = (void (__fastcall *)(char *, _QWORD, void *, __int64, _QWORD))*((_QWORD *)a1 + 9);
if ( v9 )
{
v10 = CServerTcpIP_FindClient((__int64)a1, v13[v2].fd);
v9(s, (unsigned int)v18, a1, v10, *((_QWORD *)a1 + 11));
}
}
else
{
v3 = malloc(0x20uLL);
v4 = accept(*((_DWORD *)a1 + 10), &addr, &addr_len);
*(_DWORD *)v3 = v4;
if ( v4 >= 0 )
{
v3[3] = 0LL;
v5 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v17 = strdup(v5);
v3[1] = v17;
v6 = _bswap_16(*(__int16 *)addr.sa_data);
*((_DWORD *)v3 + 4) = v6;
printf("%s @ %d : Connection de IP=%s:%d\n", "CServerTcpIP_Runtime", 296LL, v17, v6);
CServerTcpIP_AddClient((__int64)a1, (__int64)v3);
v7 = (void (__fastcall *)(void *, _QWORD *, _QWORD))*((_QWORD *)a1 + 10);
if ( v7 )
v7(a1, v3, *((_QWORD *)a1 + 11));
goto LABEL_22;
}
free(v3);
}
}
else if ( (v8 & 0x18) != 0 )
{
goto LABEL_21;
}
if ( v12 <= (int)v2 )
{
if ( v16 )
{
LABEL_25:
free(v13);
goto LABEL_26;
}
goto LABEL_4;
}
LABEL_15:
++v2;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
int v1; // eax
__int64 v2; // rbx
_QWORD *v3; // r15
int v4; // eax
char *v5; // rax
unsigned __int16 v6; // ax
void (__fastcall *v7)(void *, _QWORD *, _QWORD); // rax
__int16 v8; // ax
void (__fastcall *v9)(char *, _QWORD, void *, __int64, _QWORD); // r15
__int64 v10; // rax
_QWORD *v11; // rax
int v12; // er13
struct pollfd *v13; // rbp
__int64 v14; // rdx
struct pollfd *v15; // rax
int v16; // [rsp+8h] [rbp-2870h]
char *v17; // [rsp+8h] [rbp-2870h]
int v18; // [rsp+10h] [rbp-2868h]
socklen_t addr_len; // [rsp+2Ch] [rbp-284Ch] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-2848h] BYREF
char s[10296]; // [rsp+40h] [rbp-2838h] BYREF

addr_len = 16;
pthread_setcancelstate(0, 0LL);
pthread_setcanceltype(0, 0LL);
LABEL_26:
while ( 1 )
{
v12 = *((_DWORD *)a1 + 16);
v13 = (struct pollfd *)malloc(8LL * (v12 + 1));
if ( v13 )
break;
printf("%s @ %d : Erreur critique sur l'allocation de pfd\n", "CServerTcpIP_Runtime", 253LL);
}
v13->fd = *((_DWORD *)a1 + 10);
v13->events = 3;
v14 = *((_QWORD *)a1 + 7);
if ( v12 > 0 )
{
v15 = v13 + 1;
do
{
v15->fd = *(_DWORD *)v14;
v15->events = 3;
v14 = *(_QWORD *)(v14 + 24);
++v15;
}
while ( v15 != &v13[(unsigned int)(v12 - 1) + 2] );
}
do
{
LABEL_4:
while ( 1 )
{
pthread_testcancel();
v1 = poll(v13, v12 + 1, 5000);
if ( v1 >= 0 )
break;
printf("%s @ %d : Erreur sur le poll\n", "CServerTcpIP_Runtime", 276LL);
}
}
while ( !v1 || v12 + 1 <= 0 );
v2 = 0LL;
v16 = 0;
while ( 1 )
{
v8 = v13[v2].revents;
if ( (v8 & 3) != 0 )
{
if ( (_DWORD)v2 )
{
memset(s, 0, 0x2800uLL);
v18 = recv(v13[v2].fd, s, 0x2800uLL, 0);
if ( v18 <= 0 )
{
LABEL_21:
v11 = (_QWORD *)func5((__int64)a1, v13[v2].fd);
func8((__int64)a1, v11);
LABEL_22:
if ( v12 <= (int)v2 )
goto LABEL_25;
v16 = 1;
goto LABEL_15;
}
v9 = (void (__fastcall *)(char *, _QWORD, void *, __int64, _QWORD))*((_QWORD *)a1 + 9);
if ( v9 )
{
v10 = func5((__int64)a1, v13[v2].fd);
v9(s, (unsigned int)v18, a1, v10, *((_QWORD *)a1 + 11));
}
}
else
{
v3 = malloc(0x20uLL);
v4 = accept(*((_DWORD *)a1 + 10), &addr, &addr_len);
*(_DWORD *)v3 = v4;
if ( v4 >= 0 )
{
v3[3] = 0LL;
v5 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v17 = strdup(v5);
v3[1] = v17;
v6 = func1(*(__int16 *)addr.sa_data);
*((_DWORD *)v3 + 4) = v6;
printf("%s @ %d : Connection de IP=%s:%d\n", "CServerTcpIP_Runtime", 296LL, v17, v6);
func7((__int64)a1, (__int64)v3);
v7 = (void (__fastcall *)(void *, _QWORD *, _QWORD))*((_QWORD *)a1 + 10);
if ( v7 )
v7(a1, v3, *((_QWORD *)a1 + 11));
goto LABEL_22;
}
free(v3);
}
}
else if ( (v8 & 0x18) != 0 )
{
goto LABEL_21;
}
if ( v12 <= (int)v2 )
{
if ( v16 )
{
LABEL_25:
free(v13);
goto LABEL_26;
}
goto LABEL_4;
}
LABEL_15:
++v2;
}
}

original_code:
void *
CServerTcpIP_Runtime (void *pdata)
{
 CServerTcpIP *this = (CServerTcpIP *)pdata;
 char buffer_rx[(10*1024)];
 int i, ret, readed;
 int pfd_size;
 struct pollfd *pfd = ((void *)0);
 Client *curseur;
 Client *welcome;
 struct sockaddr_in addr_client;
 unsigned int size_addr_client = sizeof(struct sockaddr_in);
 int flag;
 pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, ((void *)0));
 pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, ((void *)0));
 while (1)
 {
  if (pfd != (struct pollfd *) ((void *)0))
   free (pfd);
  pfd_size = 1 + this->m_iClientNumber;
  pfd = (struct pollfd *) malloc (pfd_size * sizeof (struct pollfd));
  if (pfd == (struct pollfd *) ((void *)0)) {
   printf("%s @ %d : " "Erreur critique sur l'allocation de pfd\n", __FUNCTION__, 253);
   continue;
  }
  pfd[0].fd = this->m_fdListen;
  pfd[0].events = 0x001 | 0x002;
  curseur = this->m_clistClients;
  for (i=0; i<(pfd_size-1); i++) {
   pfd[i+1].fd = curseur->fd;
   pfd[i+1].events = 0x001 | 0x002;
   curseur = curseur->next;
  }
  flag = 0;
  do {
   pthread_testcancel ();
   ret = poll (pfd, pfd_size, 5000 );
   if (ret < 0) {
    printf("%s @ %d : " "Erreur sur le poll\n", __FUNCTION__, 276);
   } else if (ret == 0) {
    do {} while(0);
   } else {
    for (i=0; i<pfd_size; i++) {
     if (pfd[i].revents & (0x001 | 0x002)) {
      if (i == 0) {
       welcome = (Client *) malloc (sizeof (Client));
       welcome->fd = accept(this->m_fdListen, (struct sockaddr *) &addr_client, &size_addr_client);
       if (welcome->fd < 0) {
        free (welcome);
       } else {
        welcome->next = ((void *)0);
        welcome->adresseIP = strdup(inet_ntoa(addr_client.sin_addr));
        welcome->port = ntohs(addr_client.sin_port);
        printf("%s @ %d : " "Connection de IP=%s:%d\n", __FUNCTION__, 296, welcome->adresseIP, welcome->port);
        CServerTcpIP_AddClient (this, welcome);
        if (this->m_connect_callback != (CServerTcpIP_connect_t) ((void *)0)) {
         this->m_connect_callback (this, welcome, this->m_pvPrivateData);
        }
        flag = 1;
       }
      } else {
       memset (buffer_rx, '\0', (10*1024));
       readed = recv (pfd[i].fd, buffer_rx, (10*1024), 0);
       if (readed <= 0) {
        CServerTcpIP_DelClient (this, CServerTcpIP_FindClient (this, pfd[i].fd));
        flag = 1;
       } else {
        if (this->m_callback != (CServerTcpIP_rx_t) ((void *)0)) {
         Client *tmp = CServerTcpIP_FindClient (this, pfd[i].fd);
         this->m_callback (buffer_rx, readed, this, tmp, this->m_pvPrivateData);
        }
       }
      }
     } else if (pfd[i].revents & (0x008 | 0x010)) {
      CServerTcpIP_DelClient (this, CServerTcpIP_FindClient (this, pfd[i].fd));
      flag = 1;
     }
    }
   }
  } while (!flag);
 }
}

canonical_original_code:
void *CServerTcpIP_Runtime(void *pdata)
{
 struct _CServerTcpIP *this = (CServerTcpIP *)pdata;
 char buffer_rx[-1];
 int i; int ret; int readed;
 int pfd_size;
 struct pollfd *pfd = ((void *)0);
 struct _Client *curseur;
 struct _Client *welcome;
 struct sockaddr_in addr_client;
 unsigned int size_addr_client = sizeof(struct sockaddr_in);
 int flag;
 pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, ((void *)0));
 pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, ((void *)0));
 while (1)
 {
  if (pfd != (struct pollfd *) ((void *)0))
   free (pfd);
  pfd_size = 1 + this->m_iClientNumber;
  pfd = (struct pollfd *) malloc (pfd_size * sizeof (struct pollfd));
  if (pfd == (struct pollfd *) ((void *)0)) {
   printf("%s @ %d : " "Erreur critique sur l'allocation de pfd\n", __FUNCTION__, 253);
   continue;
  }
  pfd[0].fd = this->m_fdListen;
  pfd[0].events = 0x001 | 0x002;
  curseur = this->m_clistClients;
  for (i=0; i<(pfd_size-1); i++) {
   pfd[i+1].fd = curseur->fd;
   pfd[i+1].events = 0x001 | 0x002;
   curseur = curseur->next;
  }
  flag = 0;
  do {
   pthread_testcancel ();
   ret = poll (pfd, pfd_size, 5000 );
   if (ret < 0) {
    printf("%s @ %d : " "Erreur sur le poll\n", __FUNCTION__, 276);
   } else if (ret == 0) {
    do {} while(0);
   } else {
    for (i=0; i<pfd_size; i++) {
     if (pfd[i].revents & (0x001 | 0x002)) {
      if (i == 0) {
       welcome = (struct _Client *) malloc (sizeof (Client));
       welcome->fd = accept(this->m_fdListen, (struct sockaddr *) &addr_client, &size_addr_client);
       if (welcome->fd < 0) {
        free (welcome);
       } else {
        welcome->next = ((void *)0);
        welcome->adresseIP = strdup(inet_ntoa(addr_client.sin_addr));
        welcome->port = ntohs(addr_client.sin_port);
        printf("%s @ %d : " "Connection de IP=%s:%d\n", __FUNCTION__, 296, welcome->adresseIP, welcome->port);
        CServerTcpIP_AddClient (this, welcome);
        if (this->m_connect_callback != (CServerTcpIP_connect_t) ((void *)0)) {
         this->m_connect_callback (this, welcome, this->m_pvPrivateData);
        }
        flag = 1;
       }
      } else {
       memset (buffer_rx, '\0', (10*1024));
       readed = recv (pfd[i].fd, buffer_rx, (10*1024), 0);
       if (readed <= 0) {
        CServerTcpIP_DelClient (this, CServerTcpIP_FindClient (this, pfd[i].fd));
        flag = 1;
       } else {
        if (this->m_callback != (CServerTcpIP_rx_t) ((void *)0)) {
         struct _Client *tmp = CServerTcpIP_FindClient (this, pfd[i].fd);
         this->m_callback (buffer_rx, readed, this, tmp, this->m_pvPrivateData);
        }
       }
      }
     } else if (pfd[i].revents & (0x008 | 0x010)) {
      CServerTcpIP_DelClient (this, CServerTcpIP_FindClient (this, pfd[i].fd));
      flag = 1;
     }
    }
   }
  } while (!flag);
 }
}

variable_types:
pdata
void *

variable_types: struct _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; } *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; } *

variable_types: i int

variable_types: ret int

variable_types: readed int

variable_types: struct pollfd { int fd; short events; short revents; } *

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: flag int

return_type: void *

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 _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; }

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


decompiled_code:
__int64 __fastcall CServerTcpIP_Stop(__int64 a1)
{
int v1; // eax
__int64 result; // rax
_QWORD *v3; // rsi

if ( *(int *)(a1 + 40) < 0 )
{
printf("%s @ %d : Warning listen socket may be not started !\n", "CServerTcpIP_Stop", 182LL);
result = 0xFFFFFFFFLL;
}
else
{
if ( pthread_cancel(*(_QWORD *)(a1 + 48)) < 0 )
{
printf("%s @ %d : No thread to stop !\n", "CServerTcpIP_Stop", 189LL);
}
else
{
v1 = pthread_join(*(_QWORD *)(a1 + 48), 0LL);
if ( !v1 || v1 == -3 )
printf("%s @ %d : Reception thread stopped\n", "CServerTcpIP_Stop", 193LL);
else
printf("%s @ %d : Can't join the Reception thread !\n", "CServerTcpIP_Stop", 195LL);
}
shutdown(*(_DWORD *)(a1 + 40), 2);
close(*(_DWORD *)(a1 + 40));
*(_DWORD *)(a1 + 40) = -1;
v3 = *(_QWORD **)(a1 + 56);
if ( v3 )
{
do
{
CServerTcpIP_DelClient(a1, v3);
v3 = *(_QWORD **)(a1 + 56);
}
while ( v3 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // eax
__int64 result; // rax
_QWORD *v3; // rsi

if ( *(int *)(a1 + 40) < 0 )
{
printf("%s @ %d : Warning listen socket may be not started !\n", "CServerTcpIP_Stop", 182LL);
result = 0xFFFFFFFFLL;
}
else
{
if ( pthread_cancel(*(_QWORD *)(a1 + 48)) < 0 )
{
printf("%s @ %d : No thread to stop !\n", "CServerTcpIP_Stop", 189LL);
}
else
{
v1 = pthread_join(*(_QWORD *)(a1 + 48), 0LL);
if ( !v1 || v1 == -3 )
printf("%s @ %d : Reception thread stopped\n", "CServerTcpIP_Stop", 193LL);
else
printf("%s @ %d : Can't join the Reception thread !\n", "CServerTcpIP_Stop", 195LL);
}
shutdown(*(_DWORD *)(a1 + 40), 2);
close(*(_DWORD *)(a1 + 40));
*(_DWORD *)(a1 + 40) = -1;
v3 = *(_QWORD **)(a1 + 56);
if ( v3 )
{
do
{
func8(a1, v3);
v3 = *(_QWORD **)(a1 + 56);
}
while ( v3 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int
CServerTcpIP_Stop (CServerTcpIP *this)
{
 int ret;
 if (this->m_fdListen < 0) {
  printf("%s @ %d : " "Warning listen socket may be not started !\n", __FUNCTION__, 182);
  return -1;
 }
 ret = pthread_cancel (this->m_threadListen);
 if (ret < 0) {
  printf("%s @ %d : " "No thread to stop !\n", __FUNCTION__, 189);
 } else {
  ret = pthread_join (this->m_threadListen, ((void *)0));
  if (ret == 0 || ret == -3) {
   printf("%s @ %d : " "Reception thread stopped\n", __FUNCTION__, 193);
  } else {
   printf("%s @ %d : " "Can't join the Reception thread !\n", __FUNCTION__, 195);
  }
 }
 shutdown (this->m_fdListen, SHUT_RDWR);
 close (this->m_fdListen);
 this->m_fdListen = -1;
 while (this->m_clistClients != (Client *)((void *)0)) {
  do {} while(0);
  CServerTcpIP_DelClient (this, this->m_clistClients);
 }
 return 0;
}

canonical_original_code:
static int CServerTcpIP_Stop(struct _CServerTcpIP *this)
{
 int ret;
 if (this->m_fdListen < 0) {
  printf("%s @ %d : " "Warning listen socket may be not started !\n", __FUNCTION__, 182);
  return -1;
 }
 ret = pthread_cancel (this->m_threadListen);
 if (ret < 0) {
  printf("%s @ %d : " "No thread to stop !\n", __FUNCTION__, 189);
 } else {
  ret = pthread_join (this->m_threadListen, ((void *)0));
  if (ret == 0 || ret == -3) {
   printf("%s @ %d : " "Reception thread stopped\n", __FUNCTION__, 193);
  } else {
   printf("%s @ %d : " "Can't join the Reception thread !\n", __FUNCTION__, 195);
  }
 }
 shutdown (this->m_fdListen, SHUT_RDWR);
 close (this->m_fdListen);
 this->m_fdListen = -1;
 while (this->m_clistClients != (struct _Client *)((void *)0)) {
  do {} while(0);
  CServerTcpIP_DelClient (this, this->m_clistClients);
 }
 return 0;
}

return_type: int

user_defined_types: struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; }


decompiled_code:
void __fastcall CServerTcpIP_Free(void *ptr)
{
CServerTcpIP_Stop((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
func10((__int64)ptr);
free(ptr);
}

original_code:
static void
CServerTcpIP_Free (CServerTcpIP *this)
{
 CServerTcpIP_Stop (this);
 free (this);
}

canonical_original_code:
static void CServerTcpIP_Free(struct _CServerTcpIP *this)
{
 CServerTcpIP_Stop (this);
 free (this);
}

return_type: void


decompiled_code:
__int64 __fastcall CServerTcpIP_Send(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
unsigned int v6; // eax
__int64 result; // rax
unsigned int *i; // rbx

if ( a2 )
{
v6 = secure_send(*(_DWORD *)a2, a3, a4, 64);
if ( v6 == a4 )
{
result = a4;
}
else
{
printf("%s @ %d : Ret = %d, buffer_size = %d\n", "CServerTcpIP_Send", 400LL, v6, a4);
printf(
"%s @ %d : Erreur lors de l'envoie d'un message au client %s:%d\n",
"CServerTcpIP_Send",
401LL,
*(const char **)(a2 + 8),
*(unsigned int *)(a2 + 16));
close(*(_DWORD *)a2);
CServerTcpIP_DelClient(a1, (_QWORD *)a2);
result = 0xFFFFFFFFLL;
}
}
else
{
for ( i = *(unsigned int **)(a1 + 56); i; i = (unsigned int *)*((_QWORD *)i + 3) )
{
printf("%s @ %d : Destinataire : %p, fd = %d\n", "CServerTcpIP_Send", 383LL, i, *i);
if ( (unsigned int)secure_send(*i, a3, a4, 64) != a4 )
{
printf(
"%s @ %d : Erreur lors de l'envoie d'un message au client %s:%d\n",
"CServerTcpIP_Send",
385LL,
*((const char **)i + 1),
i[4]);
close(*i);
CServerTcpIP_DelClient(a1, i);
}
}
result = a4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
unsigned int v6; // eax
__int64 result; // rax
unsigned int *i; // rbx

if ( a2 )
{
v6 = func4(*(_DWORD *)a2, a3, a4, 64);
if ( v6 == a4 )
{
result = a4;
}
else
{
printf("%s @ %d : Ret = %d, buffer_size = %d\n", "CServerTcpIP_Send", 400LL, v6, a4);
printf(
"%s @ %d : Erreur lors de l'envoie d'un message au client %s:%d\n",
"CServerTcpIP_Send",
401LL,
*(const char **)(a2 + 8),
*(unsigned int *)(a2 + 16));
close(*(_DWORD *)a2);
func8(a1, (_QWORD *)a2);
result = 0xFFFFFFFFLL;
}
}
else
{
for ( i = *(unsigned int **)(a1 + 56); i; i = (unsigned int *)*((_QWORD *)i + 3) )
{
printf("%s @ %d : Destinataire : %p, fd = %d\n", "CServerTcpIP_Send", 383LL, i, *i);
if ( (unsigned int)func4(*i, a3, a4, 64) != a4 )
{
printf(
"%s @ %d : Erreur lors de l'envoie d'un message au client %s:%d\n",
"CServerTcpIP_Send",
385LL,
*((const char **)i + 1),
i[4]);
close(*i);
func8(a1, i);
}
}
result = a4;
}
return result;
}

original_code:
static int
CServerTcpIP_Send (CServerTcpIP* this, Client *to, char *buffer, unsigned int buffer_size)
{
 int ret;
 if (to == (Client *) ((void *)0)){
  to = this->m_clistClients;
  while (to != (Client *) ((void *)0)) {
   printf("%s @ %d : " "Destinataire : %p, fd = %d\n", __FUNCTION__, 383, to, to->fd);
   if (secure_send (to->fd, buffer, buffer_size, MSG_DONTWAIT) != buffer_size) {
    printf("%s @ %d : " "Erreur lors de l'envoie d'un message au client %s:%d\n", __FUNCTION__, 385, to->adresseIP, to->port);
    close (to->fd);
    CServerTcpIP_DelClient (this, to);
   }
   to = to->next;
  }
  return buffer_size;
 } else {
  ret = secure_send (to->fd, buffer, buffer_size, MSG_DONTWAIT);
  if (ret != buffer_size) {
   printf("%s @ %d : " "Ret = %d, buffer_size = %d\n", __FUNCTION__, 400, ret, buffer_size);
   printf("%s @ %d : " "Erreur lors de l'envoie d'un message au client %s:%d\n", __FUNCTION__, 401, to->adresseIP, to->port);
   close (to->fd);
   CServerTcpIP_DelClient (this, to);
   return -1;
  }
 }
 return buffer_size;
}

canonical_original_code:
static int CServerTcpIP_Send(struct _CServerTcpIP *this, struct _Client *to, char *buffer, unsigned int buffer_size)
{
 int ret;
 if (to == (struct _Client *) ((void *)0)){
  to = this->m_clistClients;
  while (to != (struct _Client *) ((void *)0)) {
   printf("%s @ %d : " "Destinataire : %p, fd = %d\n", __FUNCTION__, 383, to, to->fd);
   if (secure_send (to->fd, buffer, buffer_size, MSG_DONTWAIT) != buffer_size) {
    printf("%s @ %d : " "Erreur lors de l'envoie d'un message au client %s:%d\n", __FUNCTION__, 385, to->adresseIP, to->port);
    close (to->fd);
    CServerTcpIP_DelClient (this, to);
   }
   to = to->next;
  }
  return buffer_size;
 } else {
  ret = secure_send (to->fd, buffer, buffer_size, MSG_DONTWAIT);
  if (ret != buffer_size) {
   printf("%s @ %d : " "Ret = %d, buffer_size = %d\n", __FUNCTION__, 400, ret, buffer_size);
   printf("%s @ %d : " "Erreur lors de l'envoie d'un message au client %s:%d\n", __FUNCTION__, 401, to->adresseIP, to->port);
   close (to->fd);
   CServerTcpIP_DelClient (this, to);
   return -1;
  }
 }
 return buffer_size;
}

variable_types:
to
struct _Client *

variable_types:
buffer
char *


original_code:
static void can_rx(struct can_frame cf)
{
    struct bind_rx * ptr_bind;
    for(ptr_bind = binds_rx; ptr_bind < ptr_bind_rx_max; ptr_bind++)
    {
 if( (cf.can_id & ptr_bind->mask) == (ptr_bind->id & ptr_bind->mask))
 {
     if(ptr_bind->pmem != ((void *)0))
  memcpy(ptr_bind->pmem, cf.data, (((ptr_bind->len)<(cf.can_dlc))? (ptr_bind->len) : (cf.can_dlc)));
     if(ptr_bind->callback != ((void *)0))
  ptr_bind->callback(this, cf);
 }
    }
}

canonical_original_code:
static void can_rx(struct can_frame cf)
{
    struct bind_rx *ptr_bind;
    for(ptr_bind = binds_rx; ptr_bind < ptr_bind_rx_max; ptr_bind++)
    {
 if( (cf.can_id & ptr_bind->mask) == (ptr_bind->id & ptr_bind->mask))
 {
     if(ptr_bind->pmem != ((void *)0))
  memcpy(ptr_bind->pmem, cf.data, (((ptr_bind->len)<(cf.can_dlc))? (ptr_bind->len) : (cf.can_dlc)));
     if(ptr_bind->callback != ((void *)0))
  ptr_bind->callback(this, cf);
 }
    }
}

variable_types: struct bind_rx { unsigned short id; unsigned short mask; void *pmem; unsigned char len; void (*callback)(struct _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; } *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; } *this, struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; } cf); } *

user_defined_types: struct bind_rx { unsigned short id; unsigned short mask; void *pmem; unsigned char len; void (*callback)(struct _CServerTcpIP *this, struct can_frame cf); }


decompiled_code:
void __fastcall __noreturn can_thread_fct(void *a1)
{
int v1; // eax
int v2; // edi
int i; // edi
int v4; // eax
int v5; // edi
int v6; // edx
__int64 v7[2]; // [rsp+0h] [rbp-A8h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-98h] BYREF
fd_set v9; // [rsp+20h] [rbp-88h] BYREF

while ( continu )
{
memset(&v9, 0, sizeof(v9));
v5 = socket_can;
v9.fds_bits[socket_can / 64] |= 1LL << (socket_can % 64);
v6 = fifofd_rd;
v9.fds_bits[fifofd_rd / 64] |= 1LL << (fifofd_rd % 64);
timeout.tv_sec = 0LL;
timeout.tv_usec = 100000LL;
if ( v5 < v6 )
v5 = v6;
for ( i = v5 + 1; select(i, &v9, 0LL, 0LL, &timeout) > 0; i = v1 + 1 )
{
if ( (v9.fds_bits[socket_can / 64] & (1LL << (socket_can % 64))) != 0 )
{
recv(socket_can, v7, 0x10uLL, 0);
can_rx(v7[0], v7[1]);
}
if ( (v9.fds_bits[fifofd_rd / 64] & (1LL << (fifofd_rd % 64))) != 0 )
{
v4 = read(fifofd_rd, v7, 0x10uLL);
if ( v4 == 16 )
{
write(socket_can, v7, 0x10uLL);
}
else if ( v4 == -1 )
{
if ( *_errno_location() != 11 )
perror("Read from fifo");
}
else if ( v4 )
{
fwrite("Incomplete read from fifo", 1uLL, 0x19uLL, stderr);
}
}
memset(&v9, 0, sizeof(v9));
v1 = socket_can;
v9.fds_bits[socket_can / 64] |= 1LL << (socket_can % 64);
v2 = fifofd_rd;
v9.fds_bits[fifofd_rd / 64] |= 1LL << (fifofd_rd % 64);
if ( v1 < v2 )
v1 = v2;
}
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
int v1; // eax
int v2; // edi
int i; // edi
int v4; // eax
int v5; // edi
int v6; // edx
__int64 v7[2]; // [rsp+0h] [rbp-A8h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-98h] BYREF
fd_set v9; // [rsp+20h] [rbp-88h] BYREF

while ( continu )
{
memset(&v9, 0, sizeof(v9));
v5 = socket_can;
v9.fds_bits[socket_can / 64] |= 1LL << (socket_can % 64);
v6 = fifofd_rd;
v9.fds_bits[fifofd_rd / 64] |= 1LL << (fifofd_rd % 64);
timeout.tv_sec = 0LL;
timeout.tv_usec = 100000LL;
if ( v5 < v6 )
v5 = v6;
for ( i = v5 + 1; select(i, &v9, 0LL, 0LL, &timeout) > 0; i = v1 + 1 )
{
if ( (v9.fds_bits[socket_can / 64] & (1LL << (socket_can % 64))) != 0 )
{
recv(socket_can, v7, 0x10uLL, 0);
func0(v7[0], v7[1]);
}
if ( (v9.fds_bits[fifofd_rd / 64] & (1LL << (fifofd_rd % 64))) != 0 )
{
v4 = read(fifofd_rd, v7, 0x10uLL);
if ( v4 == 16 )
{
write(socket_can, v7, 0x10uLL);
}
else if ( v4 == -1 )
{
if ( *_errno_location() != 11 )
perror("Read from fifo");
}
else if ( v4 )
{
fwrite("Incomplete read from fifo", 1uLL, 0x19uLL, stderr);
}
}
memset(&v9, 0, sizeof(v9));
v1 = socket_can;
v9.fds_bits[socket_can / 64] |= 1LL << (socket_can % 64);
v2 = fifofd_rd;
v9.fds_bits[fifofd_rd / 64] |= 1LL << (fifofd_rd % 64);
if ( v1 < v2 )
v1 = v2;
}
}
pthread_exit(0LL);
}

original_code:
static void * can_thread_fct(void* args)
{
    fd_set readfds;
    struct timeval timeout;
    int ndfs;
    struct can_frame msg;
    args = args;
    while(continu)
    {
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&readfds)->__fds_bits)[((socket_can) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_can) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&readfds)->__fds_bits)[((fifofd_rd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fifofd_rd) % (8 * (int) sizeof (__fd_mask)))))));
 timeout.tv_sec = 0;
 timeout.tv_usec = 100000;
 ndfs = (((socket_can)>(fifofd_rd))? (socket_can) : (fifofd_rd)) + 1;
 while(select(ndfs, &readfds, ((void *)0), ((void *)0), &timeout) > 0)
 {
     if(((((&readfds)->__fds_bits)[((socket_can) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_can) % (8 * (int) sizeof (__fd_mask)))))) != 0))
     {
  int err;
  if(!(err = recv(socket_can, &msg, sizeof(msg), 0)) == sizeof(msg))
  {
      if(err == -1) perror("Recv from socket can");
      else fprintf(stderr, "Incomplete read from socket can");
  }
  can_rx(msg);
     }
     if(((((&readfds)->__fds_bits)[((fifofd_rd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fifofd_rd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
     {
  int err;
  if ((err=read(fifofd_rd, &msg, sizeof(msg))) == sizeof(msg))
  {
      if(!(err = write(socket_can, &msg, sizeof(msg))) == sizeof(msg))
      {
   if(err== -1)
       perror("Writing on socket can");
   else
       fprintf(stderr, "Incomplete Write on socket can");
      }
  }
  else
  {
      if(err == -1)
      {
   if((*__errno_location ()) != 11)
       perror("Read from fifo");
      }
      else
      {
   if(!err == 0)
       fprintf(stderr, "Incomplete read from fifo");
      }
  }
     }
     do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
     ((void) (((&readfds)->__fds_bits)[((socket_can) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_can) % (8 * (int) sizeof (__fd_mask)))))));
     ((void) (((&readfds)->__fds_bits)[((fifofd_rd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fifofd_rd) % (8 * (int) sizeof (__fd_mask)))))));
     ndfs = (((socket_can)>(fifofd_rd))? (socket_can) : (fifofd_rd)) + 1;
 }
    }
    pthread_exit(((void *)0));
}

canonical_original_code:
static void *can_thread_fct(void *args)
{
    struct fd_set readfds;
    struct timeval timeout;
    int ndfs;
    struct can_frame msg;
    args = args;
    while(continu)
    {
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&readfds)->__fds_bits)[((socket_can) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_can) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&readfds)->__fds_bits)[((fifofd_rd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fifofd_rd) % (8 * (int) sizeof (__fd_mask)))))));
 timeout.tv_sec = 0;
 timeout.tv_usec = 100000;
 ndfs = (((socket_can)>(fifofd_rd))? (socket_can) : (fifofd_rd)) + 1;
 while(select(ndfs, &readfds, ((void *)0), ((void *)0), &timeout) > 0)
 {
     if(((((&readfds)->__fds_bits)[((socket_can) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_can) % (8 * (int) sizeof (__fd_mask)))))) != 0))
     {
  int err;
  if(!(err = recv(socket_can, &msg, sizeof(msg), 0)) == sizeof(msg))
  {
      if(err == -1) perror("Recv from socket can");
      else fprintf(stderr, "Incomplete read from socket can");
  }
  can_rx(msg);
     }
     if(((((&readfds)->__fds_bits)[((fifofd_rd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fifofd_rd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
     {
  int err;
  if ((err=read(fifofd_rd, &msg, sizeof(msg))) == sizeof(msg))
  {
      if(!(err = write(socket_can, &msg, sizeof(msg))) == sizeof(msg))
      {
   if(err== -1)
       perror("Writing on socket can");
   else
       fprintf(stderr, "Incomplete Write on socket can");
      }
  }
  else
  {
      if(err == -1)
      {
   if((*__errno_location ()) != 11)
       perror("Read from fifo");
      }
      else
      {
   if(!err == 0)
       fprintf(stderr, "Incomplete read from fifo");
      }
  }
     }
     do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
     ((void) (((&readfds)->__fds_bits)[((socket_can) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_can) % (8 * (int) sizeof (__fd_mask)))))));
     ((void) (((&readfds)->__fds_bits)[((fifofd_rd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fifofd_rd) % (8 * (int) sizeof (__fd_mask)))))));
     ndfs = (((socket_can)>(fifofd_rd))? (socket_can) : (fifofd_rd)) + 1;
 }
    }
    pthread_exit(((void *)0));
}

variable_types:
args
void *

variable_types:
readfds
struct fd_set { long __fds_bits[-1]; }

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

variable_types: ndfs int

variable_types: struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; }

variable_types: err int


decompiled_code:
int __fastcall can_init(char *src)
{
int result; // eax
int v2; // ebx
struct itimerval v3; // [rsp+0h] [rbp-68h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-48h] BYREF
char dest[16]; // [rsp+30h] [rbp-38h] BYREF
int v6; // [rsp+40h] [rbp-28h]

result = 5;
if ( !can_ok )
{
socket_can = socket(29, 3, 1);
if ( socket_can < 0 )
{
perror("socket");
result = 1;
}
else
{
addr.sa_family = 29;
if ( src )
{
strcpy(dest, src);
}
else
{
fwrite("Utilisation de \"can0\" comme interface can par defaut\n", 1uLL, 0x35uLL, stderr);
strcpy(dest, "can0");
}
v2 = socket_can;
if ( ioctl(socket_can, 0x8933uLL, dest) < 0 )
{
perror("SIOCGIFINDEX");
result = 1;
}
else
{
*(_DWORD *)&addr.sa_data[2] = v6;
if ( bind(v2, &addr, 0x10u) < 0 )
{
perror("bind");
result = 1;
}
else
{
while ( tmpnam(fifo) && mkfifo(fifo, 0x180u) )
{
if ( *_errno_location() != 17 )
{
perror("Fifo");
return 2;
}
}
fifofd_rd = open(fifo, 2048);
if ( fifofd_rd < 0 )
{
perror("open error");
result = 2;
}
else
{
fifofd_wr = open(fifo, 1);
if ( fifofd_wr < 0 )
{
perror("open(myfunc) error");
result = 2;
}
else if ( pthread_create(&can_thread, 0LL, (void *(*)(void *))can_thread_fct, 0LL) )
{
perror("erreur pthread");
result = 3;
}
else
{
signal(14, can_tx_periodique);
v3.it_interval.tv_sec = 0LL;
v3.it_interval.tv_usec = 10000LL;
v3.it_value.tv_sec = 0LL;
v3.it_value.tv_usec = 10000LL;
result = setitimer(ITIMER_REAL, &v3, 0LL);
if ( result )
{
perror("setitimer");
result = 4;
}
else
{
can_ok = 1;
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *src)
{
int result; // eax
int v2; // ebx
struct itimerval v3; // [rsp+0h] [rbp-68h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-48h] BYREF
char dest[16]; // [rsp+30h] [rbp-38h] BYREF
int v6; // [rsp+40h] [rbp-28h]

result = 5;
if ( !can_ok )
{
socket_can = socket(29, 3, 1);
if ( socket_can < 0 )
{
perror("socket");
result = 1;
}
else
{
addr.sa_family = 29;
if ( src )
{
strcpy(dest, src);
}
else
{
fwrite("Utilisation de \"can0\" comme interface can par defaut\n", 1uLL, 0x35uLL, stderr);
strcpy(dest, "can0");
}
v2 = socket_can;
if ( ioctl(socket_can, 0x8933uLL, dest) < 0 )
{
perror("SIOCGIFINDEX");
result = 1;
}
else
{
*(_DWORD *)&addr.sa_data[2] = v6;
if ( bind(v2, &addr, 0x10u) < 0 )
{
perror("bind");
result = 1;
}
else
{
while ( tmpnam(fifo) && mkfifo(fifo, 0x180u) )
{
if ( *_errno_location() != 17 )
{
perror("Fifo");
return 2;
}
}
fifofd_rd = open(fifo, 2048);
if ( fifofd_rd < 0 )
{
perror("open error");
result = 2;
}
else
{
fifofd_wr = open(fifo, 1);
if ( fifofd_wr < 0 )
{
perror("open(myfunc) error");
result = 2;
}
else if ( pthread_create(&can_thread, 0LL, (void *(*)(void *))can_thread_fct, 0LL) )
{
perror("erreur pthread");
result = 3;
}
else
{
signal(14, can_tx_periodique);
v3.it_interval.tv_sec = 0LL;
v3.it_interval.tv_usec = 10000LL;
v3.it_value.tv_sec = 0LL;
v3.it_value.tv_usec = 10000LL;
result = setitimer(ITIMER_REAL, &v3, 0LL);
if ( result )
{
perror("setitimer");
result = 4;
}
else
{
can_ok = 1;
}
}
}
}
}
}
}
return result;
}

original_code:
int can_init(const char * iface_can)
{
    struct ifreq ifr;
    struct sockaddr_can addr;
    struct itimerval interval;
    if(!can_ok)
    {
 if ((socket_can = socket(29, SOCK_RAW, 1)) < 0) {
  perror("socket");
  return 1;
 }
 addr.can_family = 29;
 if(iface_can == ((void *)0))
 {
     fprintf(stderr, "Utilisation de \"can0\" comme interface can par defaut\n");
     strcpy(ifr.ifr_ifrn.ifrn_name, "can0");
 }
 else strcpy(ifr.ifr_ifrn.ifrn_name, iface_can);
 if (ioctl(socket_can, 0x8933, &ifr) < 0) {
  perror("SIOCGIFINDEX");
  return 1;
 }
 addr.can_ifindex = ifr.ifr_ifru.ifru_ivalue;
 if (bind(socket_can, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
  perror("bind");
  return 1;
 }
 while ((tmpnam(fifo)) != ((void *)0)){
     if (mkfifo(fifo, 0600) == 0)
  break;
     if ((*__errno_location ()) != 17)
     {
  perror("Fifo");
  return 2;
     }
 }
 if (fifo == ((void *)0)) return 2;
 if ((fifofd_rd = open(fifo, 00 | 04000)) < 0) {
     perror("open error");
     return 2;
 }
 if ((fifofd_wr= open(fifo, 01)) < 0) {
     perror("open(myfunc) error");
     return 2;
 }
 if (pthread_create(&can_thread, ((void *)0), can_thread_fct, (void *) ((void *)0))) {
     perror("erreur pthread");
     return 3;
 }
 signal(14, can_tx_periodique);
 interval.it_interval.tv_sec = 0;
 interval.it_interval.tv_usec = 10000;
 interval.it_value.tv_sec = 0;
 interval.it_value.tv_usec = 10000;
 if(setitimer(ITIMER_REAL,& interval, ((void *)0)))
 {
     perror("setitimer");
     return 4;
 }
 can_ok = 1;
    }
    else return 5;
    return 0;
}

canonical_original_code:
int can_init(char *iface_can)
{
    struct ifreq ifr;
    struct sockaddr_can addr;
    struct itimerval interval;
    if(!can_ok)
    {
 if ((socket_can = socket(29, SOCK_RAW, 1)) < 0) {
  perror("socket");
  return 1;
 }
 addr.can_family = 29;
 if(iface_can == ((void *)0))
 {
     fprintf(stderr, "Utilisation de \"can0\" comme interface can par defaut\n");
     strcpy(ifr.ifr_ifrn.ifrn_name, "can0");
 }
 else strcpy(ifr.ifr_ifrn.ifrn_name, iface_can);
 if (ioctl(socket_can, 0x8933, &ifr) < 0) {
  perror("SIOCGIFINDEX");
  return 1;
 }
 addr.can_ifindex = ifr.ifr_ifru.ifru_ivalue;
 if (bind(socket_can, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
  perror("bind");
  return 1;
 }
 while ((tmpnam(fifo)) != ((void *)0)){
     if (mkfifo(fifo, 0600) == 0)
  break;
     if ((*__errno_location ()) != 17)
     {
  perror("Fifo");
  return 2;
     }
 }
 if (fifo == ((void *)0)) return 2;
 if ((fifofd_rd = open(fifo, 00 | 04000)) < 0) {
     perror("open error");
     return 2;
 }
 if ((fifofd_wr= open(fifo, 01)) < 0) {
     perror("open(myfunc) error");
     return 2;
 }
 if (pthread_create(&can_thread, ((void *)0), can_thread_fct, (void *) ((void *)0))) {
     perror("erreur pthread");
     return 3;
 }
 signal(14, can_tx_periodique);
 interval.it_interval.tv_sec = 0;
 interval.it_interval.tv_usec = 10000;
 interval.it_value.tv_sec = 0;
 interval.it_value.tv_usec = 10000;
 if(setitimer(ITIMER_REAL,& interval, ((void *)0)))
 {
     perror("setitimer");
     return 4;
 }
 can_ok = 1;
    }
    else return 5;
    return 0;
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: struct sockaddr_can { unsigned short can_family; int can_ifindex; union { struct { unsigned int rx_id; } tp; } can_addr; }

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
__int64 can_close()
{
continu = 0;
pthread_join(can_thread, 0LL);
close(socket_can);
close(fifofd_rd);
close(fifofd_wr);
unlink(fifo);
can_ok = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
continu = 0;
pthread_join(can_thread, 0LL);
close(socket_can);
close(fifofd_rd);
close(fifofd_wr);
unlink(fifo);
can_ok = 0;
return 0LL;
}

original_code:
int can_close(void)
{
 continu = 0;
 pthread_join(can_thread, ((void *)0));
 close(socket_can);
 close(fifofd_rd);
 close(fifofd_wr);
 unlink(fifo);
 can_ok = 0;
 return 0;
}

canonical_original_code:
int can_close()
{
 continu = 0;
 pthread_join(can_thread, ((void *)0));
 close(socket_can);
 close(fifofd_rd);
 close(fifofd_wr);
 unlink(fifo);
 can_ok = 0;
 return 0;
}


decompiled_code:
__int64 can_isok()
{
return (unsigned int)can_ok;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)can_ok;
}

original_code:
int can_isok()
{
    return can_ok;
}

canonical_original_code:
int can_isok()
{
    return can_ok;
}


decompiled_code:
__int64 __fastcall can_send(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a1;
v4[1] = a2;
v2 = write(fifofd_wr, v4, 0x10uLL);
result = 0LL;
if ( v2 != 16 )
{
perror("Write on fifo");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a1;
v4[1] = a2;
v2 = write(fifofd_wr, v4, 0x10uLL);
result = 0LL;
if ( v2 != 16 )
{
perror("Write on fifo");
result = 1LL;
}
return result;
}

original_code:
int can_send(struct can_frame msg)
{
 int nbytes;
 if ((nbytes = write(fifofd_wr, &msg, sizeof(msg))) != sizeof(msg)) {
  perror("Write on fifo");
  return 1;
 }
 return 0;
}

variable_types: nbytes int

user_defined_types: struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; }


decompiled_code:
void __fastcall can_tx_periodique(int a1)
{
const void **v1; // rbx
__int64 v2; // [rsp+0h] [rbp-38h]
__int64 dest; // [rsp+8h] [rbp-30h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

if ( a1 == 14 )
{
gettimeofday(&tv, 0LL);
if ( ptr_bind_tx_max > &binds_tx )
{
v1 = (const void **)&binds_tx;
do
{
if ( (char *)(unsigned int)(1000 * (LODWORD(tv.tv_sec) - *((_DWORD *)v1 + 8))
+ (LODWORD(tv.tv_usec) - *((_DWORD *)v1 + 10)) / 1000) >= (char *)v1[3] - 3 )
{
LODWORD(v2) = *(unsigned __int16 *)v1;
BYTE4(v2) = *((_WORD *)v1 + 8);
memcpy(&dest, v1[1], *((unsigned __int16 *)v1 + 8));
can_send(v2, dest);
*((__m128i *)v1 + 2) = _mm_loadu_si128((const __m128i *)&tv);
}
v1 += 6;
}
while ( ptr_bind_tx_max > v1 );
}
}
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
const void **v1; // rbx
__int64 v2; // [rsp+0h] [rbp-38h]
__int64 dest; // [rsp+8h] [rbp-30h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

if ( a1 == 14 )
{
gettimeofday(&tv, 0LL);
if ( ptr_bind_tx_max > &binds_tx )
{
v1 = (const void **)&binds_tx;
do
{
if ( (char *)(unsigned int)(1000 * (LODWORD(tv.tv_sec) - *((_DWORD *)v1 + 8))
+ (LODWORD(tv.tv_usec) - *((_DWORD *)v1 + 10)) / 1000) >= (char *)v1[3] - 3 )
{
LODWORD(v2) = *(unsigned __int16 *)v1;
BYTE4(v2) = *((_WORD *)v1 + 8);
memcpy(&dest, v1[1], *((unsigned __int16 *)v1 + 8));
func5(v2, dest);
*((__m128i *)v1 + 2) = _mm_loadu_si128((const __m128i *)&tv);
}
v1 += 6;
}
while ( ptr_bind_tx_max > v1 );
}
}
}

original_code:
static void can_tx_periodique(int signo)
{
    struct timeval now;
    struct bind_tx * ptr_bind;
    struct can_frame cf;
    if(signo != 14)
 return;
    gettimeofday(&now, ((void *)0));
    for(ptr_bind = binds_tx; ptr_bind < ptr_bind_tx_max; ptr_bind++)
    {
 if( (unsigned)(1000*(now.tv_sec - ptr_bind->last_send.tv_sec)
     + (now.tv_usec - ptr_bind->last_send.tv_usec)/1000)
     >= (ptr_bind->period - 3))
 {
     cf.can_id = ptr_bind->id;
     cf.can_dlc = ptr_bind->len;
     memcpy(cf.data, ptr_bind->pmem, ptr_bind->len);
     can_send(cf);
     memcpy(&(ptr_bind->last_send), &now, sizeof(struct timeval));
 }
    }
}

canonical_original_code:
static void can_tx_periodique(int signo)
{
    struct timeval now;
    struct bind_tx *ptr_bind;
    struct can_frame cf;
    if(signo != 14)
 return;
    gettimeofday(&now, ((void *)0));
    for(ptr_bind = binds_tx; ptr_bind < ptr_bind_tx_max; ptr_bind++)
    {
 if( (unsigned int)(1000*(now.tv_sec - ptr_bind->last_send.tv_sec)
     + (now.tv_usec - ptr_bind->last_send.tv_usec)/1000)
     >= (ptr_bind->period - 3))
 {
     cf.can_id = ptr_bind->id;
     cf.can_dlc = ptr_bind->len;
     memcpy(cf.data, ptr_bind->pmem, ptr_bind->len);
     can_send(cf);
     memcpy(&(ptr_bind->last_send), &now, sizeof(struct timeval));
 }
    }
}

variable_types: signo int

variable_types: struct bind_tx { unsigned short id; void *pmem; unsigned short len; unsigned long period; struct timeval { long tv_sec; long tv_usec; } last_send; } *

user_defined_types: struct bind_tx { unsigned short id; void *pmem; unsigned short len; unsigned long period; struct timeval last_send; }


decompiled_code:
__int64 __fastcall can_bind_send(unsigned __int16 a1, __suseconds_t a2, __int16 a3, __suseconds_t a4)
{
struct timeval *v4; // rbx
__int64 result; // rax

v4 = (struct timeval *)ptr_bind_tx_max;
if ( (_BYTE *)ptr_bind_tx_max - (_BYTE *)&binds_tx > 432 )
{
fwrite("lib_can : Trop de binds: augmenter MAX_TX_BINDS\n", 1uLL, 0x30uLL, stderr);
result = 3LL;
}
else
{
result = 1LL;
if ( a1 <= 0x7FFu )
{
*(_WORD *)ptr_bind_tx_max = a1;
if ( !a3 )
a2 = 0LL;
v4->tv_usec = a2;
LOWORD(v4[1].tv_sec) = a3;
result = 2LL;
if ( a4 )
{
v4[1].tv_usec = a4;
gettimeofday(v4 + 2, 0LL);
ptr_bind_tx_max = &v4[3];
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int16 a1, __suseconds_t a2, __int16 a3, __suseconds_t a4)
{
struct timeval *v4; // rbx
__int64 result; // rax

v4 = (struct timeval *)ptr_bind_tx_max;
if ( (_BYTE *)ptr_bind_tx_max - (_BYTE *)&binds_tx > 432 )
{
fwrite("lib_can : Trop de binds: augmenter MAX_TX_BINDS\n", 1uLL, 0x30uLL, stderr);
result = 3LL;
}
else
{
result = 1LL;
if ( a1 <= 0x7FFu )
{
*(_WORD *)ptr_bind_tx_max = a1;
if ( !a3 )
a2 = 0LL;
v4->tv_usec = a2;
LOWORD(v4[1].tv_sec) = a3;
result = 2LL;
if ( a4 )
{
v4[1].tv_usec = a4;
gettimeofday(v4 + 2, 0LL);
ptr_bind_tx_max = &v4[3];
result = 0LL;
}
}
}
return result;
}

original_code:
int can_bind_send(unsigned short ID, void * zone, unsigned short zone_length, unsigned long period)
{
    if((ptr_bind_tx_max - binds_tx) < 10)
    {
 if(!(ID<=0x7FF)) return 1;
 ptr_bind_tx_max->id = ID;
 if(zone_length > 0) ptr_bind_tx_max->pmem = zone;
 else ptr_bind_tx_max->pmem = ((void *)0);
 ptr_bind_tx_max->len = zone_length;
 if(period==0) return 2;
 ptr_bind_tx_max->period = period;
 gettimeofday(&( ptr_bind_tx_max->last_send), ((void *)0));
 ptr_bind_tx_max++;
    }
    else
    {
 fprintf(stderr, "lib_can : Trop de binds: augmenter MAX_TX_BINDS\n");
 return 3;
    }
    return 0;
}

canonical_original_code:
int can_bind_send(unsigned short ID, void *zone, unsigned short zone_length, unsigned long period)
{
    if((ptr_bind_tx_max - binds_tx) < 10)
    {
 if(!(ID<=0x7FF)) return 1;
 ptr_bind_tx_max->id = ID;
 if(zone_length > 0) ptr_bind_tx_max->pmem = zone;
 else ptr_bind_tx_max->pmem = ((void *)0);
 ptr_bind_tx_max->len = zone_length;
 if(period==0) return 2;
 ptr_bind_tx_max->period = period;
 gettimeofday(&( ptr_bind_tx_max->last_send), ((void *)0));
 ptr_bind_tx_max++;
    }
    else
    {
 fprintf(stderr, "lib_can : Trop de binds: augmenter MAX_TX_BINDS\n");
 return 3;
    }
    return 0;
}

variable_types:
ID
unsigned short

variable_types:
zone
void *

variable_types:
period
unsigned long


decompiled_code:
__int64 __fastcall can_bind_receive(unsigned __int16 a1, unsigned __int16 a2, __int64 a3, __int16 a4, __int64 a5)
{
_WORD *v5; // rax
unsigned int v6; // er9
__int64 result; // rax

v5 = ptr_bind_rx_max;
if ( (_BYTE *)ptr_bind_rx_max - (_BYTE *)&binds_rx > 288 )
{
fwrite("lib_can : Trop de binds : augmenter MAX_RX_BINDS\n", 1uLL, 0x31uLL, stderr);
result = 3LL;
}
else
{
v6 = 1;
if ( a1 <= 0x7FFu )
{
*(_WORD *)ptr_bind_rx_max = a1;
v6 = 2;
if ( a2 <= 0x7FFu )
{
v5[1] = a2;
if ( !a4 )
a3 = 0LL;
*((_QWORD *)v5 + 1) = a3;
*((_BYTE *)v5 + 16) = a4;
*((_QWORD *)v5 + 3) = a5;
ptr_bind_rx_max = v5 + 16;
v6 = 0;
}
}
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int16 a1, unsigned __int16 a2, __int64 a3, __int16 a4, __int64 a5)
{
_WORD *v5; // rax
unsigned int v6; // er9
__int64 result; // rax

v5 = ptr_bind_rx_max;
if ( (_BYTE *)ptr_bind_rx_max - (_BYTE *)&binds_rx > 288 )
{
fwrite("lib_can : Trop de binds : augmenter MAX_RX_BINDS\n", 1uLL, 0x31uLL, stderr);
result = 3LL;
}
else
{
v6 = 1;
if ( a1 <= 0x7FFu )
{
*(_WORD *)ptr_bind_rx_max = a1;
v6 = 2;
if ( a2 <= 0x7FFu )
{
v5[1] = a2;
if ( !a4 )
a3 = 0LL;
*((_QWORD *)v5 + 1) = a3;
*((_BYTE *)v5 + 16) = a4;
*((_QWORD *)v5 + 3) = a5;
ptr_bind_rx_max = v5 + 16;
v6 = 0;
}
}
result = v6;
}
return result;
}

original_code:
int can_bind_receive(unsigned short ID, unsigned short mask,
    void * zone, unsigned short zone_length, void (*callback)(CServerTcpIP *this, struct can_frame cf))
{
    if((ptr_bind_rx_max - binds_rx)<10)
    {
 if(!(ID<=0x7FF)) return 1;
 ptr_bind_rx_max->id = ID;
 if(!(mask<=0x7FF)) return 2;
 ptr_bind_rx_max->mask = mask;
 if(zone_length > 0) ptr_bind_rx_max->pmem = zone;
 else ptr_bind_rx_max->pmem = ((void *)0);
 ptr_bind_rx_max->len = zone_length;
 ptr_bind_rx_max->callback = callback;
 ptr_bind_rx_max++;
    }
    else
    {
 fprintf(stderr, "lib_can : Trop de binds : augmenter MAX_RX_BINDS\n");
 return 3;
    }
    return 0;
}

canonical_original_code:
int can_bind_receive(unsigned short ID, unsigned short mask, void *zone, unsigned short zone_length, void (*callback)(struct _CServerTcpIP *this, struct can_frame cf))
{
    if((ptr_bind_rx_max - binds_rx)<10)
    {
 if(!(ID<=0x7FF)) return 1;
 ptr_bind_rx_max->id = ID;
 if(!(mask<=0x7FF)) return 2;
 ptr_bind_rx_max->mask = mask;
 if(zone_length > 0) ptr_bind_rx_max->pmem = zone;
 else ptr_bind_rx_max->pmem = ((void *)0);
 ptr_bind_rx_max->len = zone_length;
 ptr_bind_rx_max->callback = callback;
 ptr_bind_rx_max++;
    }
    else
    {
 fprintf(stderr, "lib_can : Trop de binds : augmenter MAX_RX_BINDS\n");
 return 3;
    }
    return 0;
}

variable_types:
mask
unsigned short

variable_types: void (*)(struct _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; } *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; } *this, struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; } cf)


DieWithError

decompiled_code:
void __fastcall __noreturn DieWithError(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void DieWithError(const char *errorMessage)
{
 perror(errorMessage);
 exit(1);
}

canonical_original_code:
void DieWithError(char *errorMessage)
{
 perror(errorMessage);
 exit(1);
}

variable_types:
errorMessage
char *


GetIP

decompiled_code:
__int64 __fastcall GetIP(char *dest)
{
unsigned int v1; // ebx
char *v3; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-D0h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-C8h] BYREF
char name[152]; // [rsp+40h] [rbp-98h] BYREF

gethostname(name, 0x80uLL);
*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v1 = 1;
if ( !getaddrinfo(name, 0LL, &req, &pai) )
{
v1 = 0;
v3 = inet_ntoa(*(struct in_addr *)&pai->ai_addr->sa_data[2]);
strcpy(dest, v3);
freeaddrinfo(pai);
printf("IP: %s\n", dest);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *dest)
{
unsigned int v1; // ebx
char *v3; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-D0h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-C8h] BYREF
char name[152]; // [rsp+40h] [rbp-98h] BYREF

gethostname(name, 0x80uLL);
*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v1 = 1;
if ( !getaddrinfo(name, 0LL, &req, &pai) )
{
v1 = 0;
v3 = inet_ntoa(*(struct in_addr *)&pai->ai_addr->sa_data[2]);
strcpy(dest, v3);
freeaddrinfo(pai);
printf("IP: %s\n", dest);
}
return v1;
}

original_code:
int GetIP(char *IP) {
 char hostname[128];
 struct addrinfo hints, *res;
 struct in_addr addr;
 int err;
 gethostname(hostname, sizeof(hostname));
 memset(&hints, 0, sizeof(hints));
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_family = 2;
 if (getaddrinfo(hostname, ((void *)0), &hints, &res) != 0) {
  return 1;
 }
 addr.s_addr = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr;
 strcpy(IP, inet_ntoa(addr));
 freeaddrinfo(res);
 printf("IP: %s\n", IP);
 return 0;
}

canonical_original_code:
int GetIP(char *IP) {
 char hostname[128];
 struct addrinfo hints; struct addrinfo *res;
 struct in_addr addr;
 int err;
 gethostname(hostname, sizeof(hostname));
 memset(&hints, 0, sizeof(hints));
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_family = 2;
 if (getaddrinfo(hostname, ((void *)0), &hints, &res) != 0) {
  return 1;
 }
 addr.s_addr = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr;
 strcpy(IP, inet_ntoa(addr));
 freeaddrinfo(res);
 printf("IP: %s\n", IP);
 return 0;
}

variable_types:
IP
char *

variable_types:
hostname
char [128]

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
addr
struct in_addr { unsigned int s_addr; }

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
const char *v4; // r14
__int16 v5; // r13
unsigned int v6; // eax
int v7; // eax
int v8; // ebp
int v9; // er13
unsigned int v10; // er12
FILE *v11; // r15
int v12; // eax
FILE *v13; // r15
FILE *v14; // r15
int v15; // [rsp+Ch] [rbp-BCh]
char src[26]; // [rsp+10h] [rbp-B8h] BYREF
char buf[6]; // [rsp+2Ah] [rbp-9Eh] BYREF
__int64 optval[2]; // [rsp+30h] [rbp-98h] BYREF
char dest[16]; // [rsp+40h] [rbp-88h] BYREF
int v20; // [rsp+50h] [rbp-78h]
int v21; // [rsp+54h] [rbp-74h]
unsigned int v22; // [rsp+58h] [rbp-70h]
char v23; // [rsp+5Ch] [rbp-6Ch]
socklen_t addr_len; // [rsp+6Ch] [rbp-5Ch] BYREF
struct sockaddr v25; // [rsp+70h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+80h] [rbp-48h] BYREF

v3 = fopen("./inc.txt", "w");
fwrite("0\n", 1uLL, 2uLL, v3);
fclose(v3);
if ( (unsigned int)(argc - 3) <= 1 )
{
v4 = argv[1];
v5 = 7;
if ( argc == 4 )
v5 = atoi(argv[2]);
v6 = time(0LL);
srand(v6);
optval[0] = 3LL;
optval[1] = 0LL;
if ( (unsigned int)GetIP(src) )
DieWithError("Error retrieving IP Address");
v7 = socket(2, 2, 17);
v8 = v7;
if ( v7 >= 0 )
{
if ( setsockopt(v7, 1, 20, optval, 0x10u) )
DieWithError("setsockopt() failed");
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr(v4);
*(_WORD *)addr.sa_data = _bswap_16(v5);
v9 = rand() % 21;
v10 = 1;
while ( 1 )
{
if ( v9 == v10 )
{
v12 = rand();
v9 = v12 % 21 + v10;
if ( (((unsigned __int8)(v12 % 21) + (_BYTE)v10) & 1) == 0 )
{
v13 = fopen("./inc.txt", "r");
v15 = fgetc(v13);
fclose(v13);
v14 = fopen("./inc.txt", "w");
fprintf(v14, "%d\n", (unsigned int)(v15 - 47));
fclose(v14);
}
}
v11 = fopen("./inc.txt", "r");
strcpy(dest, src);
v20 = fgetc(v11) - 48;
v21 = atoi(argv[3]);
v22 = v10;
v23 = rand() % 26 + 97;
fclose(v11);
if ( sendto(v8, dest, 0x20uLL, 0, &addr, 0x10u) != 32 )
DieWithError("sendto() sent a different number of bytes than expected");
addr_len = 16;
while ( recvfrom(v8, buf, 5uLL, 0, &v25, &addr_len) != 5 )
{
if ( sendto(v8, dest, 0x20uLL, 0, &addr, 0x10u) != 32 )
DieWithError("sendto() sent a different number of bytes than expected");
}
if ( *(_DWORD *)&addr.sa_data[2] != *(_DWORD *)&v25.sa_data[2] )
{
fwrite("Error: received a packet from unknown source.\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
buf[5] = 0;
printf("Received %d: %s\n", v10, buf);
sleep(0);
if ( ++v10 == 21 )
{
close(v8);
exit(0);
}
}
}
DieWithError("socket() failed");
}
fprintf(stderr, "Usage: %s <Server IP> <Port Number> <Client Number>\n", *argv);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
const char *v4; // r14
__int16 v5; // r13
unsigned int v6; // eax
int v7; // eax
int v8; // ebp
int v9; // er13
unsigned int v10; // er12
FILE *v11; // r15
int v12; // eax
FILE *v13; // r15
FILE *v14; // r15
int v15; // [rsp+Ch] [rbp-BCh]
char src[26]; // [rsp+10h] [rbp-B8h] BYREF
char buf[6]; // [rsp+2Ah] [rbp-9Eh] BYREF
__int64 optval[2]; // [rsp+30h] [rbp-98h] BYREF
char dest[16]; // [rsp+40h] [rbp-88h] BYREF
int v20; // [rsp+50h] [rbp-78h]
int v21; // [rsp+54h] [rbp-74h]
unsigned int v22; // [rsp+58h] [rbp-70h]
char v23; // [rsp+5Ch] [rbp-6Ch]
socklen_t addr_len; // [rsp+6Ch] [rbp-5Ch] BYREF
struct sockaddr v25; // [rsp+70h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+80h] [rbp-48h] BYREF

v3 = fopen("./inc.txt", "w");
fwrite("0\n", 1uLL, 2uLL, v3);
fclose(v3);
if ( (unsigned int)(argc - 3) <= 1 )
{
v4 = argv[1];
v5 = 7;
if ( argc == 4 )
v5 = atoi(argv[2]);
v6 = time(0LL);
srand(v6);
optval[0] = 3LL;
optval[1] = 0LL;
if ( (unsigned int)func9(src) )
func8("Error retrieving IP Address");
v7 = socket(2, 2, 17);
v8 = v7;
if ( v7 >= 0 )
{
if ( setsockopt(v7, 1, 20, optval, 0x10u) )
func8("setsockopt() failed");
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr(v4);
*(_WORD *)addr.sa_data = func7(v5);
v9 = rand() % 21;
v10 = 1;
while ( 1 )
{
if ( v9 == v10 )
{
v12 = rand();
v9 = v12 % 21 + v10;
if ( (((unsigned __int8)(v12 % 21) + (_BYTE)v10) & 1) == 0 )
{
v13 = fopen("./inc.txt", "r");
v15 = fgetc(v13);
fclose(v13);
v14 = fopen("./inc.txt", "w");
fprintf(v14, "%d\n", (unsigned int)(v15 - 47));
fclose(v14);
}
}
v11 = fopen("./inc.txt", "r");
strcpy(dest, src);
v20 = fgetc(v11) - 48;
v21 = atoi(argv[3]);
v22 = v10;
v23 = rand() % 26 + 97;
fclose(v11);
if ( sendto(v8, dest, 0x20uLL, 0, &addr, 0x10u) != 32 )
func8("sendto() sent a different number of bytes than expected");
addr_len = 16;
while ( recvfrom(v8, buf, 5uLL, 0, &v25, &addr_len) != 5 )
{
if ( sendto(v8, dest, 0x20uLL, 0, &addr, 0x10u) != 32 )
func8("sendto() sent a different number of bytes than expected");
}
if ( *(_DWORD *)&addr.sa_data[2] != *(_DWORD *)&v25.sa_data[2] )
{
fwrite("Error: received a packet from unknown source.\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
buf[5] = 0;
printf("Received %d: %s\n", v10, buf);
sleep(0);
if ( ++v10 == 21 )
{
close(v8);
exit(0);
}
}
}
func8("socket() failed");
}
fprintf(stderr, "Usage: %s <Server IP> <Port Number> <Client Number>\n", *argv);
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
 int sock;
 struct sockaddr_in echoServAddr;
 struct sockaddr_in echoClntAddr;
 unsigned int cliAddrLen;
 char echoBuffer[255];
 struct request clientRequest;
 struct client clients[100];
 unsigned short echoServPort;
 int recvMsgSize;
 char message[5];
 int i, tableSize;
 int found;
 int fail, drop, noRespond;
 if (argc != 2)
 {
  fprintf(stderr,"Usage:	%s <UDP SERVER PORT>\n", argv[0]);
  exit(1);
 }
 echoServPort = atoi(argv[1]);
 for(i = 0; i < 5; i++) {
  message[i] = ' ';
 }
 tableSize = 0;
 drop = 0;
 noRespond = 0;
 srand(time(0));
 if ((sock = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0)
  DieWithError("socket() failed");
 memset(&echoServAddr, 0, sizeof(echoServAddr));
 echoServAddr.sin_family = 2;
 echoServAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 echoServAddr.sin_port = htons(echoServPort);
 if (bind(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
  DieWithError("bind() failed");
 for (;;)
 {
  found = 0;
  fail = rand()%10;
  if(fail == 8)
   drop = 1;
  else if(fail == 9)
   noRespond = 1;
  cliAddrLen = sizeof(echoClntAddr);
  if ((recvMsgSize = recvfrom(sock, &clientRequest, sizeof(clientRequest), 0,
   (struct sockaddr *) &echoClntAddr, &cliAddrLen)) < 0)
   DieWithError("recvfrom() failed");
  printf("Handling client...\nIP: %s\nIncarnation Number: %d\nClient Number: %d\nRequest number: %d\nData: %c\n\n", clientRequest.client_ip, clientRequest.inc, clientRequest.client, clientRequest.req, clientRequest.c);
  for(i = 0; i < 100; i++) {
   if(drop) {
    found = 1;
    break;
   }
   if(!tableSize) {
    break;
   }
   if(clientRequest.inc == clients[i].inc && clientRequest.client == clients[i].client &&
   !strcmp(clientRequest.client_ip, clients[i].processorNumber)) {
    if(clientRequest.req < clients[i].req) {
     found = 1;
     break;
    }
    else if(clientRequest.req == clients[i].req) {
     found = 1;
     if(noRespond)
      break;
     if (sendto(sock, message, sizeof(message), 0,
     (struct sockaddr *) &echoClntAddr, sizeof(echoClntAddr)) != sizeof(message))
      DieWithError("sendto() sent a different number of bytes than expected");
     break;
    }
    else {
     found = 1;
     clients[i].req = clientRequest.req;
     for(i = 4; i > 0; i--) {
      message[i] = message[i-1];
     }
     message[0] = clientRequest.c;
     if(noRespond)
      break;
     if (sendto(sock, message, sizeof(message), 0,
     (struct sockaddr *) &echoClntAddr, sizeof(echoClntAddr)) != sizeof(message))
      DieWithError("sendto() sent a different number of bytes than expected");
     break;
    }
   }
  }
  if(!found) {
   clients[tableSize].inc = clientRequest.inc;
   clients[tableSize].client = clientRequest.client;
   clients[tableSize].req = clientRequest.req;
   strcpy(clients[tableSize].processorNumber, clientRequest.client_ip);
   clients[i].req = clientRequest.req;
   for(i = 4; i > 0; i--) {
    message[i] = message[i-1];
   }
   message[0] = clientRequest.c;
   if (sendto(sock, message, sizeof(message), 0,
   (struct sockaddr *) &echoClntAddr, sizeof(echoClntAddr)) != sizeof(message))
    DieWithError("sendto() sent a different number of bytes than expected");
   tableSize = (tableSize+1)%100;
  }
  if(drop) {
   printf("Failure: Dropping request\n");
   drop = 0;
  }
  if(noRespond) {
   noRespond = 0;
   printf("Failure: Not responding\n");
  }
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int sock;
 struct sockaddr_in echoServAddr;
 struct sockaddr_in echoClntAddr;
 unsigned int cliAddrLen;
 char echoBuffer[255];
 struct request clientRequest;
 struct client clients[100];
 unsigned short echoServPort;
 int recvMsgSize;
 char message[5];
 int i; int tableSize;
 int found;
 int fail; int drop; int noRespond;
 if (argc != 2)
 {
  fprintf(stderr,"Usage:	%s <UDP SERVER PORT>\n", argv[0]);
  exit(1);
 }
 echoServPort = atoi(argv[1]);
 for(i = 0; i < 5; i++) {
  message[i] = ' ';
 }
 tableSize = 0;
 drop = 0;
 noRespond = 0;
 srand(time(0));
 if ((sock = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0)
  DieWithError("socket() failed");
 memset(&echoServAddr, 0, sizeof(echoServAddr));
 echoServAddr.sin_family = 2;
 echoServAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 echoServAddr.sin_port = htons(echoServPort);
 if (bind(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
  DieWithError("bind() failed");
 for (;;)
 {
  found = 0;
  fail = rand()%10;
  if(fail == 8)
   drop = 1;
  else if(fail == 9)
   noRespond = 1;
  cliAddrLen = sizeof(echoClntAddr);
  if ((recvMsgSize = recvfrom(sock, &clientRequest, sizeof(clientRequest), 0,
   (struct sockaddr *) &echoClntAddr, &cliAddrLen)) < 0)
   DieWithError("recvfrom() failed");
  printf("Handling client...\nIP: %s\nIncarnation Number: %d\nClient Number: %d\nRequest number: %d\nData: %c\n\n", clientRequest.client_ip, clientRequest.inc, clientRequest.client, clientRequest.req, clientRequest.c);
  for(i = 0; i < 100; i++) {
   if(drop) {
    found = 1;
    break;
   }
   if(!tableSize) {
    break;
   }
   if(clientRequest.inc == clients[i].inc && clientRequest.client == clients[i].client &&
   !strcmp(clientRequest.client_ip, clients[i].processorNumber)) {
    if(clientRequest.req < clients[i].req) {
     found = 1;
     break;
    }
    else if(clientRequest.req == clients[i].req) {
     found = 1;
     if(noRespond)
      break;
     if (sendto(sock, message, sizeof(message), 0,
     (struct sockaddr *) &echoClntAddr, sizeof(echoClntAddr)) != sizeof(message))
      DieWithError("sendto() sent a different number of bytes than expected");
     break;
    }
    else {
     found = 1;
     clients[i].req = clientRequest.req;
     for(i = 4; i > 0; i--) {
      message[i] = message[i-1];
     }
     message[0] = clientRequest.c;
     if(noRespond)
      break;
     if (sendto(sock, message, sizeof(message), 0,
     (struct sockaddr *) &echoClntAddr, sizeof(echoClntAddr)) != sizeof(message))
      DieWithError("sendto() sent a different number of bytes than expected");
     break;
    }
   }
  }
  if(!found) {
   clients[tableSize].inc = clientRequest.inc;
   clients[tableSize].client = clientRequest.client;
   clients[tableSize].req = clientRequest.req;
   strcpy(clients[tableSize].processorNumber, clientRequest.client_ip);
   clients[i].req = clientRequest.req;
   for(i = 4; i > 0; i--) {
    message[i] = message[i-1];
   }
   message[0] = clientRequest.c;
   if (sendto(sock, message, sizeof(message), 0,
   (struct sockaddr *) &echoClntAddr, sizeof(echoClntAddr)) != sizeof(message))
    DieWithError("sendto() sent a different number of bytes than expected");
   tableSize = (tableSize+1)%100;
  }
  if(drop) {
   printf("Failure: Dropping request\n");
   drop = 0;
  }
  if(noRespond) {
   noRespond = 0;
   printf("Failure: Not responding\n");
  }
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: sock int

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:
cliAddrLen
unsigned int

variable_types:
echoBuffer
char [255]

variable_types: struct request { char client_ip[16]; int inc; int client; int req; char c; }

variable_types: struct client { char processorNumber[16]; int inc; int client; int req; } [100]

variable_types:
echoServPort
unsigned short

variable_types: recvMsgSize int

variable_types:
message
char [5]

variable_types: i int

variable_types: tableSize int

variable_types: found int

variable_types: fail int

variable_types: drop int

variable_types: noRespond int


createEmptyList

repo: ACCITD/ITD

decompiled_code:
_QWORD *createEmptyList()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
if ( result )
{
result[2] = 0LL;
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 6) = 0;
*((_DWORD *)result + 7) = 0;
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
if ( result )
{
result[2] = 0LL;
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 6) = 0;
*((_DWORD *)result + 7) = 0;
}
return result;
}

original_code:
List* createEmptyList(void){
 List* list = (List*) malloc(sizeof(List));
 if(list == ((void *)0)) return ((void *)0);
 list->head = list->cursor = list->bottom = ((void *)0);
 list->size = 0;
 list->position = 0;
 return list;
}

canonical_original_code:
struct list *createEmptyList(){
 struct list *list = (List*) malloc(sizeof(List));
 if(list == ((void *)0)) return ((void *)0);
 list->head = list->cursor = list->bottom = ((void *)0);
 list->size = 0;
 list->position = 0;
 return list;
}

variable_types: struct list { struct cell { struct cell *next; struct cell *previous; void *userData; } *head; struct cell *cursor; struct cell *bottom; int size; int position; } *

user_defined_types: struct list { struct cell *head; struct cell *cursor; struct cell *bottom; int size; int position; }


currentCell

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

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

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

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

original_code:
Cell* currentCell(List* list){
 if(list == ((void *)0)) return ((void *)0);
 return list->cursor;
}

canonical_original_code:
struct cell *currentCell(struct list *list){
 if(list == ((void *)0)) return ((void *)0);
 return list->cursor;
}

variable_types: struct list { struct cell *head; struct cell *cursor; struct cell *bottom; int size; int position; } *

return_type: struct cell { struct cell *next; struct cell *previous; void *userData; } *


nextCell

decompiled_code:
__int64 __fastcall nextCell(__int64 *a1)
{
__int64 *v1; // rax
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = (__int64 *)a1[1];
if ( v1 )
{
result = *v1;
if ( result )
{
a1[1] = result;
++*((_DWORD *)a1 + 7);
}
}
else
{
result = *a1;
a1[1] = *a1;
++*((_DWORD *)a1 + 7);
}
return result;
}

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

if ( !a1 )
return 0LL;
v1 = (__int64 *)a1[1];
if ( v1 )
{
result = *v1;
if ( result )
{
a1[1] = result;
++*((_DWORD *)a1 + 7);
}
}
else
{
result = *a1;
a1[1] = *a1;
++*((_DWORD *)a1 + 7);
}
return result;
}

original_code:
Cell* nextCell(List* list){
 if(list == ((void *)0)) return ((void *)0);
 if(list->cursor == ((void *)0)){
  list->cursor = list->head;
  list->position++;
  return list->cursor;
 }
 if(list->cursor->next == ((void *)0)) return ((void *)0);
 list->cursor = list->cursor->next;
 list->position++;
 return list->cursor;
}

canonical_original_code:
struct cell *nextCell(struct list *list){
 if(list == ((void *)0)) return ((void *)0);
 if(list->cursor == ((void *)0)){
  list->cursor = list->head;
  list->position++;
  return list->cursor;
 }
 if(list->cursor->next == ((void *)0)) return ((void *)0);
 list->cursor = list->cursor->next;
 list->position++;
 return list->cursor;
}

user_defined_types: struct cell { struct cell *next; struct cell *previous; void *userData; }


previousCell

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
if ( result )
{
result = *(_QWORD *)(result + 8);
*(_QWORD *)(a1 + 8) = result;
--*(_DWORD *)(a1 + 28);
}
return result;
}

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
if ( result )
{
result = *(_QWORD *)(result + 8);
*(_QWORD *)(a1 + 8) = result;
--*(_DWORD *)(a1 + 28);
}
return result;
}

original_code:
Cell* previousCell(List* list){
 if(list == ((void *)0)) return ((void *)0);
 if(list->cursor == ((void *)0)){
  return ((void *)0);
 }
 list->cursor = list->cursor->previous;
 list->position--;
 return list->cursor;
}

canonical_original_code:
struct cell *previousCell(struct list *list){
 if(list == ((void *)0)) return ((void *)0);
 if(list->cursor == ((void *)0)){
  return ((void *)0);
 }
 list->cursor = list->cursor->previous;
 list->position--;
 return list->cursor;
}


nextData

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

result = nextCell(a1);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

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

result = func2(a1);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

original_code:
void* nextData(List* list){
 Cell* c = nextCell(list);
 if(c) return c->userData;
 return ((void *)0);
}

canonical_original_code:
void *nextData(struct list *list){
 struct cell *c = nextCell(list);
 if(c) return c->userData;
 return ((void *)0);
}

variable_types: struct cell { struct cell *next; struct cell *previous; void *userData; } *


previousData

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

result = previousCell(a1);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

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

result = func3(a1);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

original_code:
void* previousData(List* list){
 Cell* c = previousCell(list);
 if(c) return c->userData;
 return ((void *)0);
}

canonical_original_code:
void *previousData(struct list *list){
 struct cell *c = previousCell(list);
 if(c) return c->userData;
 return ((void *)0);
}


currentData

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

result = currentCell(a1);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

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

result = func1(a1);
if ( result )
result = *(_QWORD *)(result + 16);
return result;
}

original_code:
void* currentData(List* list){
 Cell* c = currentCell(list);
 if(c) return c->userData;
 return ((void *)0);
}

canonical_original_code:
void *currentData(struct list *list){
 struct cell *c = currentCell(list);
 if(c) return c->userData;
 return ((void *)0);
}


goToHeadList

decompiled_code:
void __fastcall goToHeadList(__int64 a1)
{
if ( a1 )
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 28) = 0;
}
}

original_code:
void goToHeadList(List* list){
 if(list == ((void *)0)) return;
 list->cursor = ((void *)0);
 list->position = 0;
}

canonical_original_code:
void goToHeadList(struct list *list){
 if(list == ((void *)0)) return;
 list->cursor = ((void *)0);
 list->position = 0;
}


goToBottomCell

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 28) = *(_DWORD *)(a1 + 24);
return result;
}

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 28) = *(_DWORD *)(a1 + 24);
return result;
}

original_code:
Cell* goToBottomCell(List* list){
 if(list == ((void *)0)) return ((void *)0);
 list->cursor = list->bottom;
 list->position = list->size;
 return list->cursor;
}

canonical_original_code:
struct cell *goToBottomCell(struct list *list){
 if(list == ((void *)0)) return ((void *)0);
 list->cursor = list->bottom;
 list->position = list->size;
 return list->cursor;
}


getCellByPosition

decompiled_code:
__int64 __fastcall getCellByPosition(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

v2 = goToPosition(a1, a2);
result = 0LL;
if ( v2 )
result = *(_QWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

v2 = func10(a1, a2);
result = 0LL;
if ( v2 )
result = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
Cell* getCellByPosition(List* list, int position){
 if(goToPosition(list, position))
  return list->cursor;
 return ((void *)0);
}

canonical_original_code:
struct cell *getCellByPosition(struct list *list, int position){
 if(goToPosition(list, position))
  return list->cursor;
 return ((void *)0);
}

variable_types: position int


freeCellByPosition

decompiled_code:
void __fastcall freeCellByPosition(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = delCellByPosition(a1, a2);
free(v2);
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = delCellByPosition(a1, a2);
free(v2);
}

original_code:
void freeCellByPosition(List* list, int position){
 void* data = delCellByPosition(list,position);
 free(data);
}

canonical_original_code:
void freeCellByPosition(struct list *list, int position){
 void *data = delCellByPosition(list,position);
 free(data);
}

variable_types:
data
void *


freeCellInList

decompiled_code:
void __fastcall freeCellInList(__int64 a1, _QWORD **a2)
{
_QWORD *v2; // rax

v2 = delCellInList(a1, a2);
free(v2);
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, _QWORD **a2)
{
_QWORD *v2; // rax

v2 = delCellInList(a1, a2);
free(v2);
}

original_code:
void freeCellInList(List* list, Cell* c){
 void* data = delCellInList(list,c);
 free(data);
}

canonical_original_code:
void freeCellInList(struct list *list, struct cell *c){
 void *data = delCellInList(list,c);
 free(data);
}

variable_types:
c
struct cell *


freeBottomCell

decompiled_code:
void __fastcall freeBottomCell(__int64 a1)
{
if ( a1 )
freeCellInList(a1, *(_QWORD ***)(a1 + 16));
}

original_code:
void freeBottomCell(List* list){
 if(list == ((void *)0)) return;
 freeCellInList(list, list->bottom);
}

canonical_original_code:
void freeBottomCell(struct list *list){
 if(list == ((void *)0)) return;
 freeCellInList(list, list->bottom);
}


freeCell

decompiled_code:
void __fastcall freeCell(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void freeCell(Cell* c){
 free(c->userData);
 free(c);
}

canonical_original_code:
void freeCell(struct cell *c){
 free(c->userData);
 free(c);
}


freeList

decompiled_code:
void __fastcall freeList(void *ptr)
{
_QWORD **v1; // rsi

if ( ptr && *((int *)ptr + 6) > 0 )
{
goToHeadList((__int64)ptr);
while ( 1 )
{
v1 = (_QWORD **)nextCell((__int64 *)ptr);
if ( !v1 )
break;
freeCellInList((__int64)ptr, v1);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
_QWORD **v1; // rsi

if ( ptr && *((int *)ptr + 6) > 0 )
{
func8((__int64)ptr);
while ( 1 )
{
v1 = (_QWORD **)func2((__int64 *)ptr);
if ( !v1 )
break;
func13((__int64)ptr, v1);
}
free(ptr);
}
}

original_code:
void freeList(List* list){
 if(list == ((void *)0)) return;
 if(list->size <= 0) return;
 Cell* c = ((void *)0);
 goToHeadList(list);
 while( (c = nextCell(list) ) != ((void *)0)){
  freeCellInList(list, c);
 }
 free(list);
}

canonical_original_code:
void freeList(struct list *list){
 if(list == ((void *)0)) return;
 if(list->size <= 0) return;
 struct cell *c = ((void *)0);
 goToHeadList(list);
 while( (c = nextCell(list) ) != ((void *)0)){
  freeCellInList(list, c);
 }
 free(list);
}


freeListComplete

decompiled_code:
void __fastcall freeListComplete(void *ptr)
{
_QWORD **i; // rsi

if ( ptr && *((int *)ptr + 6) > 0 )
{
goToHeadList((__int64)ptr);
nextCell((__int64 *)ptr);
for ( i = (_QWORD **)currentCell((__int64)ptr); i; i = (_QWORD **)currentCell((__int64)ptr) )
freeCellInList((__int64)ptr, i);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
_QWORD **i; // rsi

if ( ptr && *((int *)ptr + 6) > 0 )
{
func8((__int64)ptr);
func2((__int64 *)ptr);
for ( i = (_QWORD **)func1((__int64)ptr); i; i = (_QWORD **)func1((__int64)ptr) )
func13((__int64)ptr, i);
free(ptr);
}
}

original_code:
void freeListComplete(List* list){
 if(list == ((void *)0)) return;
 if(list->size <= 0) return;
 Cell* c = ((void *)0);
 goToHeadList(list);
 nextCell(list);
 c = currentCell(list);
 while( c != ((void *)0)){
  freeCellInList(list, c);
  c = currentCell(list);
 }
 free(list);
}

canonical_original_code:
void freeListComplete(struct list *list){
 if(list == ((void *)0)) return;
 if(list->size <= 0) return;
 struct cell *c = ((void *)0);
 goToHeadList(list);
 nextCell(list);
 c = currentCell(list);
 while( c != ((void *)0)){
  freeCellInList(list, c);
  c = currentCell(list);
 }
 free(list);
}


restoreListState

original_code:
void restoreListState(ListState* state){
 if(state == ((void *)0) || state->savedList == ((void *)0))
  return;
 Cell* curCell = ((void *)0);
 goToHeadList(state->savedList);
 if(state->savedCell == ((void *)0)){
  return;
 }
 curCell = nextCell(state->savedList);
 while( curCell != ((void *)0) ){
  if(curCell == state->savedCell){
   return;
  }
  curCell = nextCell(state->savedList);
 }
 if(curCell != ((void *)0)
 || state->savedList->size < state->savedPosition) return;
 goToHeadList(state->savedList);
 while(state->savedList->position != state->savedPosition ){
  nextCell(state->savedList);
 }
}

canonical_original_code:
void restoreListState(struct list_state *state){
 if(state == ((void *)0) || state->savedList == ((void *)0))
  return;
 struct cell *curCell = ((void *)0);
 goToHeadList(state->savedList);
 if(state->savedCell == ((void *)0)){
  return;
 }
 curCell = nextCell(state->savedList);
 while( curCell != ((void *)0) ){
  if(curCell == state->savedCell){
   return;
  }
  curCell = nextCell(state->savedList);
 }
 if(curCell != ((void *)0)
 || state->savedList->size < state->savedPosition) return;
 goToHeadList(state->savedList);
 while(state->savedList->position != state->savedPosition ){
  nextCell(state->savedList);
 }
}

variable_types: struct list_state { struct list { struct cell { struct cell *next; struct cell *previous; void *userData; } *head; struct cell *cursor; struct cell *bottom; int size; int position; } *savedList; struct cell *savedCell; int savedPosition; } *

user_defined_types: struct list_state { struct list *savedList; struct cell *savedCell; int savedPosition; }


listCountElem

decompiled_code:
__int64 __fastcall listCountElem(__int64 *a1)
{
unsigned int v1; // ebx
_QWORD *v2; // r12

v1 = 0;
if ( a1 )
{
v2 = saveListState((__int64)a1);
goToHeadList((__int64)a1);
while ( nextCell(a1) )
++v1;
restoreListState((__int64)v2);
free(v2);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 *a1)
{
unsigned int v1; // ebx
_QWORD *v2; // r12

v1 = 0;
if ( a1 )
{
v2 = saveListState((__int64)a1);
func8((__int64)a1);
while ( func2(a1) )
++v1;
func18((__int64)v2);
free(v2);
}
return v1;
}

original_code:
int listCountElem(List* list){
 int size = 0;
 if(list == ((void *)0)) return size;
 ListState* state = saveListState(list);
 goToHeadList(list);
 while(nextCell(list) != ((void *)0)) size++;
 restoreListState(state);
 free(state);
 return size;
}

canonical_original_code:
int listCountElem(struct list *list){
 int size = 0;
 if(list == ((void *)0)) return size;
 struct list_state *state = saveListState(list);
 goToHeadList(list);
 while(nextCell(list) != ((void *)0)) size++;
 restoreListState(state);
 free(state);
 return size;
}

variable_types: size int


goToCell

decompiled_code:
__int64 __fastcall goToCell(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = saveListState(a1);
goToHeadList(a1);
do
v3 = nextCell((__int64 *)a1);
while ( v3 && a2 != v3 );
if ( v3 )
{
free(v2);
result = *(unsigned int *)(a1 + 28);
}
else
{
restoreListState((__int64)v2);
free(v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = saveListState(a1);
func8(a1);
do
v3 = func2((__int64 *)a1);
while ( v3 && a2 != v3 );
if ( v3 )
{
free(v2);
result = *(unsigned int *)(a1 + 28);
}
else
{
func18((__int64)v2);
free(v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int goToCell(List* list, Cell* cell){
 if(list == ((void *)0) || cell == ((void *)0))
  return -1;
 Cell* currentCell = ((void *)0);
 ListState* state = saveListState(list);
 goToHeadList(list);
 while( ( currentCell = nextCell(list) ) != cell
  && currentCell != ((void *)0));
 if(currentCell == ((void *)0)){
  restoreListState(state);
  free(state);
  return -1;
 }
 free(state);
 return list->position;
}

canonical_original_code:
int goToCell(struct list *list, struct cell *cell){
 if(list == ((void *)0) || cell == ((void *)0))
  return -1;
 struct cell *currentCell = ((void *)0);
 struct list_state *state = saveListState(list);
 goToHeadList(list);
 while( ( currentCell = nextCell(list) ) != cell
  && currentCell != ((void *)0));
 if(currentCell == ((void *)0)){
  restoreListState(state);
  free(state);
  return -1;
 }
 free(state);
 return list->position;
}

variable_types:
cell
struct cell *


goToData

decompiled_code:
__int64 __fastcall goToData(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = saveListState(a1);
goToHeadList(a1);
do
v3 = nextData((__int64 *)a1);
while ( v3 && a2 != v3 );
if ( v3 )
{
free(v2);
result = *(unsigned int *)(a1 + 28);
}
else
{
restoreListState((__int64)v2);
free(v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = saveListState(a1);
func8(a1);
do
v3 = func4((__int64 *)a1);
while ( v3 && a2 != v3 );
if ( v3 )
{
free(v2);
result = *(unsigned int *)(a1 + 28);
}
else
{
func18((__int64)v2);
free(v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int goToData(List* list, void* userData){
 if(list == ((void *)0) || userData == ((void *)0))
  return -1;
 void* currentData = ((void *)0);
 ListState* state = saveListState(list);
 goToHeadList(list);
 while( ( currentData = nextData(list) ) != userData
  && currentData != ((void *)0) );
 if(currentData == ((void *)0)){
  restoreListState(state);
  free(state);
  return -1;
 }
 free(state);
 return list->position;
}

canonical_original_code:
int goToData(struct list *list, void *userData){
 if(list == ((void *)0) || userData == ((void *)0))
  return -1;
 void *currentData = ((void *)0);
 struct list_state *state = saveListState(list);
 goToHeadList(list);
 while( ( currentData = nextData(list) ) != userData
  && currentData != ((void *)0) );
 if(currentData == ((void *)0)){
  restoreListState(state);
  free(state);
  return -1;
 }
 free(state);
 return list->position;
}

variable_types:
userData
void *

variable_types:
currentData
void *


dumpList

decompiled_code:
void __fastcall dumpList(__int64 *a1)
{
_QWORD *v1; // r12
unsigned int v2; // ebp
const void *v3; // rax
const void *v4; // rsi
const void *v5; // rsi

if ( a1 )
{
printf("\n--------------Affichage Liste (Adresse : %p)--------------\n\n", a1);
if ( isListEmpty((__int64)a1) )
{
puts("\tListe vide.");
}
else
{
v1 = saveListState((__int64)a1);
goToHeadList((__int64)a1);
v2 = 1;
while ( nextCell(a1) )
{
v3 = (const void *)currentCell((__int64)a1);
printf("\n\tCellule %d) Adresse : %p", v2, v3);
v4 = *(const void **)a1[1];
if ( v4 )
printf("Next Cell : %p\n", v4);
else
puts("Next Cell : None");
v5 = *(const void **)(a1[1] + 8);
if ( v5 )
printf("Previous Cell: %p\n", v5);
else
puts("Previous Cell : None");
++v2;
}
printf("\n----->Fin Affichage Liste (Adresse : %p)\n", a1);
restoreListState((__int64)v1);
free(v1);
}
}
}

canonical_decompiled_code:
void __fastcall func22(__int64 *a1)
{
_QWORD *v1; // r12
unsigned int v2; // ebp
const void *v3; // rax
const void *v4; // rsi
const void *v5; // rsi

if ( a1 )
{
printf("\n--------------Affichage Liste (Adresse : %p)--------------\n\n", a1);
if ( func7((__int64)a1) )
{
puts("\tListe vide.");
}
else
{
v1 = saveListState((__int64)a1);
func8((__int64)a1);
v2 = 1;
while ( func2(a1) )
{
v3 = (const void *)func1((__int64)a1);
printf("\n\tCellule %d) Adresse : %p", v2, v3);
v4 = *(const void **)a1[1];
if ( v4 )
printf("Next Cell : %p\n", v4);
else
puts("Next Cell : None");
v5 = *(const void **)(a1[1] + 8);
if ( v5 )
printf("Previous Cell: %p\n", v5);
else
puts("Previous Cell : None");
++v2;
}
printf("\n----->Fin Affichage Liste (Adresse : %p)\n", a1);
func18((__int64)v1);
free(v1);
}
}
}

original_code:
void dumpList(List* list){
 if(list == ((void *)0)) return;
 int cnt = 1;
 printf("\n--------------Affichage Liste (Adresse : %p)--------------\n\n", list);
 if(isListEmpty(list)){
  printf("\tListe vide.\n");
  return;
 }
 ListState* state = saveListState(list);
 goToHeadList(list);
 while(nextCell(list) != ((void *)0)){
  printf("\n\tCellule %d)  Adresse : %p", cnt, currentCell(list));
  if(list->cursor->next != ((void *)0))
   printf("Next Cell : %p\n", list->cursor->next);
  else
   printf("Next Cell : None\n");
  if(list->cursor->previous != ((void *)0))
   printf("Previous Cell: %p\n", list->cursor->previous);
  else
   printf("Previous Cell : None\n");
  cnt++;
 }
 printf("\n----->Fin Affichage Liste (Adresse : %p)\n", list);
 restoreListState(state);
 free(state);
}

canonical_original_code:
void dumpList(struct list *list){
 if(list == ((void *)0)) return;
 int cnt = 1;
 printf("\n--------------Affichage Liste (Adresse : %p)--------------\n\n", list);
 if(isListEmpty(list)){
  printf("\tListe vide.\n");
  return;
 }
 struct list_state *state = saveListState(list);
 goToHeadList(list);
 while(nextCell(list) != ((void *)0)){
  printf("\n\tCellule %d)  Adresse : %p", cnt, currentCell(list));
  if(list->cursor->next != ((void *)0))
   printf("Next Cell : %p\n", list->cursor->next);
  else
   printf("Next Cell : None\n");
  if(list->cursor->previous != ((void *)0))
   printf("Previous Cell: %p\n", list->cursor->previous);
  else
   printf("Previous Cell : None\n");
  cnt++;
 }
 printf("\n----->Fin Affichage Liste (Adresse : %p)\n", list);
 restoreListState(state);
 free(state);
}

variable_types: cnt int


Vector

decompiled_code:
__m128i __fastcall Vector(double a1, double a2, double a3)
{
__m128i v4; // [rsp+24h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = *(float *)&a3 - *(float *)&a1;
*(float *)&v4.m128i_i32[1] = *((float *)&a3 + 1) - *((float *)&a1 + 1);
return _mm_loadl_epi64(&v4);
}

original_code:
Vector3D Vector(Point3D A, Point3D B){
 Vector3D v;
 v.x = B.x - A.x;
 v.y = B.y - A.y;
 v.z = B.z - A.z;
 return v;
}

canonical_original_code:
struct Vector3D Vector(struct Point3D A, struct Point3D B){
 struct Vector3D v;
 v.x = B.x - A.x;
 v.y = B.y - A.y;
 v.z = B.z - A.z;
 return v;
}

variable_types: struct Point3D { float x; float y; float z; }

variable_types:
B
struct Point3D

variable_types: struct Vector3D { float x; float y; float z; }


PointPlusVector

decompiled_code:
__m128i __fastcall PointPlusVector(double a1, double a2, double a3)
{
__m128i v4; // [rsp+24h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = *(float *)&a1 + *(float *)&a3;
*(float *)&v4.m128i_i32[1] = *((float *)&a1 + 1) + *((float *)&a3 + 1);
return _mm_loadl_epi64(&v4);
}

original_code:
Point3D PointPlusVector(Point3D P, Vector3D V){
 Point3D newPoint;
 newPoint.x = P.x + V.x;
 newPoint.y = P.y + V.y;
 newPoint.z = P.z + V.z;
 return newPoint;
}

canonical_original_code:
struct Point3D PointPlusVector(struct Point3D P, struct Vector3D V){
 struct Point3D newPoint;
 newPoint.x = P.x + V.x;
 newPoint.y = P.y + V.y;
 newPoint.z = P.z + V.z;
 return newPoint;
}

variable_types:
P
struct Point3D

return_type: struct Point3D { float x; float y; float z; }

user_defined_types: struct Vector3D { float x; float y; float z; }


VectorXYZ

decompiled_code:
__m128i __fastcall VectorXYZ(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

canonical_decompiled_code:
__m128i __fastcall func0(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

original_code:
Vector3D VectorXYZ(float x, float y, float z){
 Vector3D newVector;
 newVector.x = x;
 newVector.y = y;
 newVector.z = z;
 return newVector;
}

canonical_original_code:
struct Vector3D VectorXYZ(float x, float y, float z){
 struct Vector3D newVector;
 newVector.x = x;
 newVector.y = y;
 newVector.z = z;
 return newVector;
}

variable_types: x float

variable_types: y float

variable_types: z float

return_type: struct Vector3D { float x; float y; float z; }


AddVectors

decompiled_code:
__m128i __fastcall AddVectors(double a1, double a2, double a3)
{
__m128i v4; // [rsp+24h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = *(float *)&a1 + *(float *)&a3;
*(float *)&v4.m128i_i32[1] = *((float *)&a1 + 1) + *((float *)&a3 + 1);
return _mm_loadl_epi64(&v4);
}

original_code:
Vector3D AddVectors(Vector3D Vector1, Vector3D Vector2){
 Vector3D newVector;
 newVector.x = Vector1.x + Vector2.x;
 newVector.y = Vector1.y + Vector2.y;
 newVector.z = Vector1.z + Vector2.z;
 return newVector;
}

canonical_original_code:
struct Vector3D AddVectors(struct Vector3D Vector1, struct Vector3D Vector2){
 struct Vector3D newVector;
 newVector.x = Vector1.x + Vector2.x;
 newVector.y = Vector1.y + Vector2.y;
 newVector.z = Vector1.z + Vector2.z;
 return newVector;
}


SubVectors

decompiled_code:
__m128i __fastcall SubVectors(double a1, double a2, double a3)
{
__m128i v4; // [rsp+24h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = *(float *)&a1 - *(float *)&a3;
*(float *)&v4.m128i_i32[1] = *((float *)&a1 + 1) - *((float *)&a3 + 1);
return _mm_loadl_epi64(&v4);
}

original_code:
Vector3D SubVectors(Vector3D Vector1, Vector3D Vector2){
 Vector3D newVector;
 newVector.x = Vector1.x - Vector2.x;
 newVector.y = Vector1.y - Vector2.y;
 newVector.z = Vector1.z - Vector2.z;
 return newVector;
}

canonical_original_code:
struct Vector3D SubVectors(struct Vector3D Vector1, struct Vector3D Vector2){
 struct Vector3D newVector;
 newVector.x = Vector1.x - Vector2.x;
 newVector.y = Vector1.y - Vector2.y;
 newVector.z = Vector1.z - Vector2.z;
 return newVector;
}


MultVector

decompiled_code:
__m128i __fastcall MultVector(double a1, double a2, float a3)
{
__m128i v4; // [rsp+14h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = a3 * *(float *)&a1;
*(float *)&v4.m128i_i32[1] = a3 * *((float *)&a1 + 1);
return _mm_loadl_epi64(&v4);
}

canonical_decompiled_code:
__m128i __fastcall func3(double a1, double a2, float a3)
{
__m128i v4; // [rsp+14h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = a3 * *(float *)&a1;
*(float *)&v4.m128i_i32[1] = a3 * *((float *)&a1 + 1);
return _mm_loadl_epi64(&v4);
}

original_code:
Vector3D MultVector(Vector3D V, float scalar){
 Vector3D newVector;
 newVector.x = V.x*scalar;
 newVector.y = V.y*scalar;
 newVector.z = V.z*scalar;
 return newVector;
}

canonical_original_code:
struct Vector3D MultVector(struct Vector3D V, float scalar){
 struct Vector3D newVector;
 newVector.x = V.x*scalar;
 newVector.y = V.y*scalar;
 newVector.z = V.z*scalar;
 return newVector;
}

variable_types:
V
struct Vector3D

variable_types: scalar float


DivVector

decompiled_code:
__m128i __fastcall DivVector(double a1, double a2, float a3)
{
__m128i v4; // [rsp+14h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = *(float *)&a1 / a3;
*(float *)&v4.m128i_i32[1] = *((float *)&a1 + 1) / a3;
return _mm_loadl_epi64(&v4);
}

canonical_decompiled_code:
__m128i __fastcall func4(double a1, double a2, float a3)
{
__m128i v4; // [rsp+14h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = *(float *)&a1 / a3;
*(float *)&v4.m128i_i32[1] = *((float *)&a1 + 1) / a3;
return _mm_loadl_epi64(&v4);
}

original_code:
Vector3D DivVector(Vector3D V, float scalar){
 Vector3D newVector;
 newVector.x = V.x/scalar;
 newVector.y = V.y/scalar;
 newVector.z = V.z/scalar;
 return newVector;
}

canonical_original_code:
struct Vector3D DivVector(struct Vector3D V, float scalar){
 struct Vector3D newVector;
 newVector.x = V.x/scalar;
 newVector.y = V.y/scalar;
 newVector.z = V.z/scalar;
 return newVector;
}