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

if ( !a2 )
{
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_constprop_0(*i, a3, a4) != 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);
}
}
return a4;
}
v6 = secure_send_constprop_0(*(_DWORD *)a2, a3, a4);
if ( v6 == a4 )
return a4;
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);
return 0xFFFFFFFFLL;
}

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

if ( !a2 )
{
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)func2(*i, a3, a4) != 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);
}
}
return a4;
}
v6 = func2(*(_DWORD *)a2, a3, a4);
if ( v6 == a4 )
return a4;
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);
return 0xFFFFFFFFLL;
}

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

return_type: void

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

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


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

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

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

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

return_type: void *


decompiled_code:
int __fastcall can_init(char *src)
{
int result; // eax
int v2; // ebp
char *v3; // rdx
struct sockaddr v4; // [rsp+0h] [rbp-78h] BYREF
struct itimerval newa; // [rsp+10h] [rbp-68h] BYREF
char dest[16]; // [rsp+30h] [rbp-48h] BYREF
int v7; // [rsp+40h] [rbp-38h]

result = 5;
if ( !can_ok )
{
socket_can = socket(29, 3, 1);
v2 = socket_can;
if ( socket_can < 0 )
{
perror("socket");
result = 1;
}
else
{
v4.sa_family = 29;
if ( src )
{
v3 = strcpy(dest, src);
}
else
{
fwrite("Utilisation de \"can0\" comme interface can par defaut\n", 1uLL, 0x35uLL, stderr);
v2 = socket_can;
v3 = dest;
strcpy(dest, "can0");
}
if ( ioctl(v2, 0x8933uLL, v3) < 0 )
{
perror("SIOCGIFINDEX");
result = 1;
}
else
{
*(_DWORD *)&v4.sa_data[2] = v7;
if ( bind(v2, &v4, 0x10u) >= 0 )
{
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);
newa.it_interval.tv_sec = 0LL;
newa.it_interval.tv_usec = 10000LL;
newa.it_value.tv_sec = 0LL;
newa.it_value.tv_usec = 10000LL;
result = setitimer(ITIMER_REAL, &newa, 0LL);
if ( result )
{
perror("setitimer");
result = 4;
}
else
{
can_ok = 1;
}
}
}
}
else
{
perror("bind");
result = 1;
}
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *src)
{
int result; // eax
int v2; // ebp
char *v3; // rdx
struct sockaddr v4; // [rsp+0h] [rbp-78h] BYREF
struct itimerval newa; // [rsp+10h] [rbp-68h] BYREF
char dest[16]; // [rsp+30h] [rbp-48h] BYREF
int v7; // [rsp+40h] [rbp-38h]

result = 5;
if ( !can_ok )
{
socket_can = socket(29, 3, 1);
v2 = socket_can;
if ( socket_can < 0 )
{
perror("socket");
result = 1;
}
else
{
v4.sa_family = 29;
if ( src )
{
v3 = strcpy(dest, src);
}
else
{
fwrite("Utilisation de \"can0\" comme interface can par defaut\n", 1uLL, 0x35uLL, stderr);
v2 = socket_can;
v3 = dest;
strcpy(dest, "can0");
}
if ( ioctl(v2, 0x8933uLL, v3) < 0 )
{
perror("SIOCGIFINDEX");
result = 1;
}
else
{
*(_DWORD *)&v4.sa_data[2] = v7;
if ( bind(v2, &v4, 0x10u) >= 0 )
{
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);
newa.it_interval.tv_sec = 0LL;
newa.it_interval.tv_usec = 10000LL;
newa.it_value.tv_sec = 0LL;
newa.it_value.tv_usec = 10000LL;
result = setitimer(ITIMER_REAL, &newa, 0LL);
if ( result )
{
perror("setitimer");
result = 4;
}
else
{
can_ok = 1;
}
}
}
}
else
{
perror("bind");
result = 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; }

return_type: int

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()
{
__int64 result; // rax

continu = 0;
pthread_join(can_thread, 0LL);
close(socket_can);
close(fifofd_rd);
close(fifofd_wr);
unlink(fifo);
result = 0LL;
can_ok = 0;
return result;
}

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

continu = 0;
pthread_join(can_thread, 0LL);
close(socket_can);
close(fifofd_rd);
close(fifofd_wr);
unlink(fifo);
result = 0LL;
can_ok = 0;
return result;
}

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; // er8
__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; // er8
__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]; }


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, __int64 a2, __int16 a3, __int64 a4)
{
char *v4; // rbx
__int64 result; // rax

v4 = (char *)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;
*((_WORD *)v4 + 8) = a3;
result = 2LL;
*((_QWORD *)v4 + 1) = a2;
if ( a4 )
{
*((_QWORD *)v4 + 3) = a4;
gettimeofday((struct timeval *)v4 + 2, 0LL);
ptr_bind_tx_max = v4 + 48;
result = 0LL;
}
}
}
return result;
}

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

v4 = (char *)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;
*((_WORD *)v4 + 8) = a3;
result = 2LL;
*((_QWORD *)v4 + 1) = a2;
if ( a4 )
{
*((_QWORD *)v4 + 3) = a4;
gettimeofday((struct timeval *)v4 + 2, 0LL);
ptr_bind_tx_max = v4 + 48;
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
_QWORD *v7; // rax
__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;
*((_BYTE *)v5 + 16) = a4;
v7 = v5 + 16;
v6 = 0;
*(v7 - 1) = a5;
*(v7 - 3) = a3;
ptr_bind_rx_max = v7;
}
}
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
_QWORD *v7; // rax
__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;
*((_BYTE *)v5 + 16) = a4;
v7 = v5 + 16;
v6 = 0;
*(v7 - 1) = a5;
*(v7 - 3) = a3;
ptr_bind_rx_max = v7;
}
}
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)


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v4; // rbp
const char *v5; // r14
unsigned __int16 v6; // r13
unsigned int v7; // eax
int v8; // eax
int v9; // ebp
unsigned int v10; // ebx
int v11; // er13
FILE *v12; // r15
int v13; // eax
const char *v14; // rdi
int v15; // eax
__int64 v16; // rsi
int v17; // eax
int v18; // er15
FILE *stream; // [rsp+8h] [rbp-B0h]
FILE *streama; // [rsp+8h] [rbp-B0h]
socklen_t addr_len; // [rsp+14h] [rbp-A4h] BYREF
char buf[6]; // [rsp+1Ah] [rbp-9Eh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-98h] BYREF
struct sockaddr v24; // [rsp+30h] [rbp-88h] BYREF
__int64 optval[2]; // [rsp+40h] [rbp-78h] BYREF
char src[16]; // [rsp+50h] [rbp-68h] BYREF
char dest[16]; // [rsp+60h] [rbp-58h] BYREF
int v28; // [rsp+70h] [rbp-48h]
int v29; // [rsp+74h] [rbp-44h]
unsigned int v30; // [rsp+78h] [rbp-40h]
char v31; // [rsp+7Ch] [rbp-3Ch]

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

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v4; // rbp
const char *v5; // r14
unsigned __int16 v6; // r13
unsigned int v7; // eax
int v8; // eax
int v9; // ebp
unsigned int v10; // ebx
int v11; // er13
FILE *v12; // r15
int v13; // eax
const char *v14; // rdi
int v15; // eax
__int64 v16; // rsi
int v17; // eax
int v18; // er15
FILE *stream; // [rsp+8h] [rbp-B0h]
FILE *streama; // [rsp+8h] [rbp-B0h]
socklen_t addr_len; // [rsp+14h] [rbp-A4h] BYREF
char buf[6]; // [rsp+1Ah] [rbp-9Eh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-98h] BYREF
struct sockaddr v24; // [rsp+30h] [rbp-88h] BYREF
__int64 optval[2]; // [rsp+40h] [rbp-78h] BYREF
char src[16]; // [rsp+50h] [rbp-68h] BYREF
char dest[16]; // [rsp+60h] [rbp-58h] BYREF
int v28; // [rsp+70h] [rbp-48h]
int v29; // [rsp+74h] [rbp-44h]
unsigned int v30; // [rsp+78h] [rbp-40h]
char v31; // [rsp+7Ch] [rbp-3Ch]

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

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

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

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


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; // er12
char *v2; // 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

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

canonical_decompiled_code:
__int64 __fastcall func9(char *dest)
{
unsigned int v1; // er12
char *v2; // 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

v1 = 1;
gethostname(name, 0x80uLL);
*(_OWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( !getaddrinfo(name, 0LL, &req, &pai) )
{
v1 = 0;
v2 = inet_ntoa(*(struct in_addr *)&pai->ai_addr->sa_data[2]);
strcpy(dest, v2);
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; }

variable_types: err int

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


createEmptyList

repo: ACCITD/ITD

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

result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
}
return result;
}

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

result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
}
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 )
{
++*((_DWORD *)a1 + 7);
a1[1] = result;
}
}
else
{
result = *a1;
++*((_DWORD *)a1 + 7);
a1[1] = result;
}
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 )
{
++*((_DWORD *)a1 + 7);
a1[1] = result;
}
}
else
{
result = *a1;
++*((_DWORD *)a1 + 7);
a1[1] = result;
}
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);
--*(_DWORD *)(a1 + 28);
*(_QWORD *)(a1 + 8) = result;
}
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);
--*(_DWORD *)(a1 + 28);
*(_QWORD *)(a1 + 8) = result;
}
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
int v2; // edx

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

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 16);
v2 = *(_DWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 28) = v2;
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; // er8
__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; // er8
__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)
{
void *v2; // rax

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

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

v2 = (void *)func14(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, __int64 *a2)
{
void *v2; // rax

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

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

v2 = (void *)func12(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, *(__int64 **)(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 func18(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)
{
__int64 *v1; // rsi

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

canonical_decompiled_code:
void __fastcall func19(void *ptr)
{
__int64 *v1; // rsi

if ( ptr && *((int *)ptr + 6) > 0 )
{
func8((__int64)ptr);
while ( 1 )
{
v1 = (__int64 *)func2((__int64 *)ptr);
if ( !v1 )
break;
func16((__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)
{
__int64 *i; // rsi

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

canonical_decompiled_code:
void __fastcall func20(void *ptr)
{
__int64 *i; // rsi

if ( ptr && *((int *)ptr + 6) > 0 )
{
func8((__int64)ptr);
func2((__int64 *)ptr);
for ( i = (__int64 *)func1((__int64)ptr); i; i = (__int64 *)func1((__int64)ptr) )
func16((__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; // er12
__int64 *v2; // r8
void *v3; // r8

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

canonical_decompiled_code:
__int64 __fastcall func22(__int64 *a1)
{
unsigned int v1; // er12
__int64 *v2; // r8
void *v3; // r8

v1 = 0;
if ( a1 )
{
saveListState((__int64)a1);
func8((__int64)a1);
while ( func2(a1) )
++v1;
func21(v2);
free(v3);
}
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)
{
__int64 v2; // rax
void *v3; // r8
void *v5; // r8

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

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // r8
void *v5; // r8

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

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)
{
__int64 v2; // rax
void *v3; // r8
void *v5; // r8

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

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // r8
void *v5; // r8

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

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)
{
unsigned int v1; // ebx
__int64 *v2; // rax
__int64 *v3; // r12
const void *v4; // rsi
const void *v5; // rax
const void *v6; // rsi

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

canonical_decompiled_code:
void __fastcall func25(__int64 *a1)
{
unsigned int v1; // ebx
__int64 *v2; // rax
__int64 *v3; // r12
const void *v4; // rsi
const void *v5; // rax
const void *v6; // rsi

if ( a1 )
{
printf("\n--------------Affichage Liste (Adresse : %p)--------------\n\n", a1);
if ( func7((__int64)a1) )
{
puts("\tListe vide.");
return;
}
saveListState((__int64)a1);
v1 = 1;
func8((__int64)a1);
v3 = v2;
while ( 1 )
{
if ( !func2(a1) )
{
printf("\n----->Fin Affichage Liste (Adresse : %p)\n", a1);
func21(v3);
free(v3);
return;
}
v5 = (const void *)func1((__int64)a1);
printf("\n\tCellule %d) Adresse : %p", v1, v5);
v6 = *(const void **)a1[1];
if ( v6 )
{
printf("Next Cell : %p\n", v6);
v4 = *(const void **)(a1[1] + 8);
if ( v4 )
goto LABEL_5;
}
else
{
puts("Next Cell : None");
v4 = *(const void **)(a1[1] + 8);
if ( v4 )
{
LABEL_5:
printf("Previous Cell: %p\n", v4);
goto LABEL_6;
}
}
puts("Previous Cell : None");
LABEL_6:
++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[1] = *((float *)&a1 + 1) + *((float *)&a3 + 1);
*(float *)v4.m128i_i32 = *(float *)&a1 + *(float *)&a3;
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[1] = *((float *)&a1 + 1) + *((float *)&a3 + 1);
*(float *)v4.m128i_i32 = *(float *)&a1 + *(float *)&a3;
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[1] = *((float *)&a1 + 1) - *((float *)&a3 + 1);
*(float *)v4.m128i_i32 = *(float *)&a1 - *(float *)&a3;
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[1] = *((float *)&a1 + 1) * a3;
*(float *)v4.m128i_i32 = *(float *)&a1 * a3;
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[1] = *((float *)&a1 + 1) * a3;
*(float *)v4.m128i_i32 = *(float *)&a1 * a3;
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[1] = *((float *)&a1 + 1) / a3;
*(float *)v4.m128i_i32 = *(float *)&a1 / 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[1] = *((float *)&a1 + 1) / a3;
*(float *)v4.m128i_i32 = *(float *)&a1 / 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;
}


DotProduct

decompiled_code:
float __fastcall DotProduct(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

canonical_decompiled_code:
float __fastcall func5(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

original_code:
float DotProduct(Vector3D Vector1, Vector3D Vector2){
 return Vector1.x*Vector2.x + Vector1.y*Vector2.y + Vector1.z*Vector2.z;
}

canonical_original_code:
float DotProduct(struct Vector3D Vector1, struct Vector3D Vector2){
 return Vector1.x*Vector2.x + Vector1.y*Vector2.y + Vector1.z*Vector2.z;
}

return_type: float


Norm

decompiled_code:
void __fastcall Norm(double a1, float a2)
{
float v2; // xmm0_4

v2 = (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
if ( v2 < 0.0 )
sqrtf(v2);
}

canonical_decompiled_code:
void __fastcall func6(double a1, float a2)
{
float v2; // xmm0_4

v2 = (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
if ( v2 < 0.0 )
sqrtf(v2);
}

original_code:
float Norm(Vector3D V){
 return sqrt(V.x*V.x + V.y*V.y + V.z*V.z);
}

canonical_original_code:
float Norm(struct Vector3D V){
 return sqrt(V.x*V.x + V.y*V.y + V.z*V.z);
}


Normalize

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

Norm(a1, a2);
*(float *)v3.m128i_i32 = *(float *)&a1 / *(float *)&a1;
*(float *)&v3.m128i_i32[1] = *((float *)&a1 + 1) / *(float *)&a1;
return _mm_loadl_epi64(&v3);
}

original_code:
Vector3D Normalize(Vector3D V){
 Vector3D newVector;
 float norm = Norm(V);
 newVector.x = V.x / norm;
 newVector.y = V.y / norm;
 newVector.z = V.z / norm;
 return newVector;
}

canonical_original_code:
struct Vector3D Normalize(struct Vector3D V){
 struct Vector3D newVector;
 float norm = Norm(V);
 newVector.x = V.x / norm;
 newVector.y = V.y / norm;
 newVector.z = V.z / norm;
 return newVector;
}

variable_types: norm float


dumpVector

decompiled_code:
int __fastcall dumpVector(double a1, float a2)
{
puts("\nDump vector :");
printf("\tx : %f\n", *(float *)&a1);
printf("\ty : %f\n", *((float *)&a1 + 1));
return printf("\tz : %f\n", a2);
}

canonical_decompiled_code:
int __fastcall func8(double a1, float a2)
{
puts("\nDump vector :");
printf("\tx : %f\n", *(float *)&a1);
printf("\ty : %f\n", *((float *)&a1 + 1));
return printf("\tz : %f\n", a2);
}

original_code:
void dumpVector(Vector3D vect){
 printf("\nDump vector :\n");
 printf("\tx : %f\n", vect.x);
 printf("\ty : %f\n", vect.y);
 printf("\tz : %f\n", vect.z);
}

canonical_original_code:
void dumpVector(struct Vector3D vect){
 printf("\nDump vector :\n");
 printf("\tx : %f\n", vect.x);
 printf("\ty : %f\n", vect.y);
 printf("\tz : %f\n", vect.z);
}


createEmptyTowerStat

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

result = malloc(0x40uLL);
if ( result )
{
*result = 0x6400000064LL;
result[1] = 0xBE000000B4LL;
result[2] = 0x280000003CLL;
result[3] = 0x9600000078LL;
result[4] = 0x3200000028LL;
result[5] = 0x5000000096LL;
result[6] = 0x6400000028LL;
result[7] = 0xFA00000118LL;
}
return result;
}

original_code:
TowerStat* createEmptyTowerStat(){
 TowerStat* towerstat = (TowerStat*) malloc(sizeof(TowerStat));
 if(towerstat == ((void *)0)) return ((void *)0);
 towerstat->powerR=100;
 towerstat->rateR=100;
 towerstat->rangeR=180;
 towerstat->costR=190;
 towerstat->powerL=60;
 towerstat->rateL=40;
 towerstat->rangeL=120;
 towerstat->costL=150;
 towerstat->powerM=40;
 towerstat->rateM=50;
 towerstat->rangeM=150;
 towerstat->costM=80;
 towerstat->powerH=40;
 towerstat->rateH=100;
 towerstat->rangeH=280;
 towerstat->costH=250;
 return towerstat;
}

canonical_original_code:
struct TowerStat *createEmptyTowerStat(){
 struct TowerStat *towerstat = (TowerStat*) malloc(sizeof(TowerStat));
 if(towerstat == ((void *)0)) return ((void *)0);
 towerstat->powerR=100;
 towerstat->rateR=100;
 towerstat->rangeR=180;
 towerstat->costR=190;
 towerstat->powerL=60;
 towerstat->rateL=40;
 towerstat->rangeL=120;
 towerstat->costL=150;
 towerstat->powerM=40;
 towerstat->rateM=50;
 towerstat->rangeM=150;
 towerstat->costM=80;
 towerstat->powerH=40;
 towerstat->rateH=100;
 towerstat->rangeH=280;
 towerstat->costH=250;
 return towerstat;
}

variable_types: struct TowerStat { int powerR; int rateR; int rangeR; int costR; int powerL; int rateL; int rangeL; int costL; int powerM; int rateM; int rangeM; int costM; int powerH; int rateH; int rangeH; int costH; } *


drawMonster

original_code:
void drawMonster(const Monster* monster){
 if(monster == ((void *)0)) return;
 GLuint monsterTexture = 0;
 Vector3D direction = Normalize(monster->direction);
 float factorX = DotProduct(direction, ITD_X_AXIS);
 float factorY = DotProduct(direction, ITD_Y_AXIS);
 float epsilon = 0.4;
 switch(monster->type){
  case BLUE_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_GAUCHE;
   }
   else if (fabs(factorX) >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DROITE;
   }
   else if ( fabs(factorX + 0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID;
  break;
  case ORANGE_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_GAUCHE;
   }
   else if (factorX >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DROITE;
   }
   else if (fabs(factorX+0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID;
  break;
  case GREEN_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_GAUCHE;
   }
   else if (factorX >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DROITE;
   }
   else if (fabs(factorX+0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID;
  break;
  default : return;
  break;
 }
 glPushMatrix();
 glColor3ub(255,255,255);
 glTranslatef(monster->position.x, monster->position.y, monster->position.z);
 glPushMatrix();
 glScalef(MONSTER_WIDTH_PX,MONSTER_WIDTH_PX,1.0);
 drawTexturedQuad(monsterTexture);
 glPopMatrix();
 float fullBarSize = (MONSTER_WIDTH_PX / 1.2);
 float barSize = monster->life / ((float)monster->maxLife) * fullBarSize;
 float decalY = - (MONSTER_WIDTH_PX / 1.2 - barSize) / 2.0;
 glPushMatrix();
 glTranslatef(MONSTER_WIDTH_PX / 2.0 + 10 , 0., 0.);
 glScalef(4.0, fullBarSize, 1.);
 glColor3ub(255,0,0);
 drawQuad();
 glPopMatrix();
 glPushMatrix();
 glTranslatef(MONSTER_WIDTH_PX / 2.0 + 10 , decalY, 0.);
 glColor3ub(0,255,0);
 glScalef(4.0, barSize, 1.);
 drawQuad();
 glPopMatrix();
 glPopMatrix();
}

canonical_original_code:
void drawMonster(struct Monster *monster){
 if(monster == ((void *)0)) return;
 unsigned int monsterTexture = 0;
 struct Vector3D direction = Normalize(monster->direction);
 float factorX = DotProduct(direction, ITD_X_AXIS);
 float factorY = DotProduct(direction, ITD_Y_AXIS);
 float epsilon = 0.4;
 switch(monster->type){
  case BLUE_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_GAUCHE;
   }
   else if (fabs(factorX) >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DROITE;
   }
   else if ( fabs(factorX + 0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID;
  break;
  case ORANGE_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_GAUCHE;
   }
   else if (factorX >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DROITE;
   }
   else if (fabs(factorX+0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID;
  break;
  case GREEN_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_GAUCHE;
   }
   else if (factorX >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DROITE;
   }
   else if (fabs(factorX+0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID;
  break;
  default : return;
  break;
 }
 glPushMatrix();
 glColor3ub(255,255,255);
 glTranslatef(monster->position.x, monster->position.y, monster->position.z);
 glPushMatrix();
 glScalef(MONSTER_WIDTH_PX,MONSTER_WIDTH_PX,1.0);
 drawTexturedQuad(monsterTexture);
 glPopMatrix();
 float fullBarSize = (MONSTER_WIDTH_PX / 1.2);
 float barSize = monster->life / ((float)monster->maxLife) * fullBarSize;
 float decalY = - (MONSTER_WIDTH_PX / 1.2 - barSize) / 2.0;
 glPushMatrix();
 glTranslatef(MONSTER_WIDTH_PX / 2.0 + 10 , 0., 0.);
 glScalef(4.0, fullBarSize, 1.);
 glColor3ub(255,0,0);
 drawQuad();
 glPopMatrix();
 glPushMatrix();
 glTranslatef(MONSTER_WIDTH_PX / 2.0 + 10 , decalY, 0.);
 glColor3ub(0,255,0);
 glScalef(4.0, barSize, 1.);
 drawQuad();
 glPopMatrix();
 glPopMatrix();
}

variable_types: struct Monster { enum MonsterType { BLUE_OCTOPUS=0, ORANGE_OCTOPUS=1, GREEN_OCTOPUS=2 } type; int life; int maxLife; int rocketResistance; int laserResistance; int gunResistance; int hybridResistance; int money; int speed; struct Point3D { float x; float y; float z; } position; struct Point3D realPosition; struct Point3D destination; struct Vector3D { float x; float y; float z; } direction; int nbTurnsSinceLastMove; } *

variable_types:
monsterTexture
unsigned int

variable_types: factorX float

variable_types: factorY float

variable_types: epsilon float

variable_types: fullBarSize float

variable_types: barSize float

variable_types: decalY float

user_defined_types: struct Monster { enum MonsterType type; int life; int maxLife; int rocketResistance; int laserResistance; int gunResistance; int hybridResistance; int money; int speed; struct Point3D position; struct Point3D realPosition; struct Point3D destination; struct Vector3D direction; int nbTurnsSinceLastMove; }


createMissile

decompiled_code:
char *__fastcall createMissile(int a1, double a2, float a3, double a4, float a5)
{
char *v5; // r12

v5 = (char *)malloc(0x20uLL);
if ( v5 )
{
*((_DWORD *)v5 + 6) = a1;
*(double *)v5 = a2;
*((float *)v5 + 2) = a3;
*(double *)(v5 + 12) = a4;
*((float *)v5 + 5) = a5;
}
else
{
fwrite(&unk_E70, 1uLL, 0x2CuLL, stderr);
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func3(int a1, double a2, float a3, double a4, float a5)
{
char *v5; // r12

v5 = (char *)malloc(0x20uLL);
if ( v5 )
{
*((_DWORD *)v5 + 6) = a1;
*(double *)v5 = a2;
*((float *)v5 + 2) = a3;
*(double *)(v5 + 12) = a4;
*((float *)v5 + 5) = a5;
}
else
{
fwrite(&unk_E70, 1uLL, 0x2CuLL, stderr);
}
return v5;
}

original_code:
Missile* createMissile(Point3D startPoint, Point3D endPoint, Uint32 startTime){
 Missile* missile = (Missile*) malloc(sizeof(Missile));
 if(missile == ((void *)0)) {
  fprintf(stderr, "Erreur fatale : plus de mémoire disponible\n");
  return ((void *)0);
 }
 missile->startPoint = startPoint;
 missile->endPoint = endPoint;
 missile->startTime = startTime;
 return missile;
}

canonical_original_code:
struct Missile *createMissile(struct Point3D startPoint, struct Point3D endPoint, unsigned int startTime){
 struct Missile *missile = (Missile*) malloc(sizeof(Missile));
 if(missile == ((void *)0)) {
  fprintf(stderr, "Erreur fatale : plus de mémoire disponible\n");
  return ((void *)0);
 }
 missile->startPoint = startPoint;
 missile->endPoint = endPoint;
 missile->startTime = startTime;
 return missile;
}

variable_types:
startPoint
struct Point3D

variable_types:
endPoint
struct Point3D

variable_types:
startTime
unsigned int

variable_types: struct Missile { struct Point3D { float x; float y; float z; } startPoint; struct Point3D endPoint; unsigned int startTime; struct Color3u { unsigned char red; unsigned char green; unsigned char blue; } color; } *

user_defined_types: struct Missile { struct Point3D startPoint; struct Point3D endPoint; unsigned int startTime; struct Color3u color; }


PointXYZ

decompiled_code:
__m128i __fastcall PointXYZ(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:
Point3D PointXYZ(float x, float y, float z){
 Point3D p;
 p.x = x;
 p.y = y;
 p.z = z;
 return p;
}

canonical_original_code:
struct Point3D PointXYZ(float x, float y, float z){
 struct Point3D p;
 p.x = x;
 p.y = y;
 p.z = z;
 return p;
}

variable_types: x float

variable_types: y float

variable_types: z float

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


dumpPoint

decompiled_code:
int __fastcall dumpPoint(double a1, float a2)
{
puts("\nDump point :");
printf("\tx : %f\n", *(float *)&a1);
printf("\ty : %f\n", *((float *)&a1 + 1));
return printf("\tz : %f\n", a2);
}

canonical_decompiled_code:
int __fastcall func2(double a1, float a2)
{
puts("\nDump point :");
printf("\tx : %f\n", *(float *)&a1);
printf("\ty : %f\n", *((float *)&a1 + 1));
return printf("\tz : %f\n", a2);
}

original_code:
void dumpPoint(Point3D point){
 printf("\nDump point :\n");
 printf("\tx : %f\n", point.x);
 printf("\ty : %f\n", point.y);
 printf("\tz : %f\n", point.z);
}

canonical_original_code:
void dumpPoint(struct Point3D point){
 printf("\nDump point :\n");
 printf("\tx : %f\n", point.x);
 printf("\ty : %f\n", point.y);
 printf("\tz : %f\n", point.z);
}

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


decompiled_code:
int __fastcall print_results(unsigned __int8 *a1)
{
__int64 v1; // rbx
int result; // eax

v1 = 2LL;
puts("Final state:");
printf("r0: %X\tr1: %X\n", *a1, a1[1]);
puts("Memory:");
printf("%X ", a1[2]);
do
{
result = printf("%X ", a1[v1 + 1]);
if ( (v1 & 3) == 0 )
result = putchar(10);
++v1;
}
while ( v1 != 17 );
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int8 *a1)
{
__int64 v1; // rbx
int result; // eax

v1 = 2LL;
puts("Final state:");
printf("r0: %X\tr1: %X\n", *a1, a1[1]);
puts("Memory:");
printf("%X ", a1[2]);
do
{
result = printf("%X ", a1[v1 + 1]);
if ( (v1 & 3) == 0 )
result = putchar(10);
++v1;
}
while ( v1 != 17 );
return result;
}

original_code:
void print_results(processor * p) {
    printf("Final state:\n");
    printf("r0: %X\tr1: %X\n", p->r0, p->r1);
    printf("Memory:\n");
    int i;
    for (i = 0; i < 16; ++i) {
        printf("%X ", p->mem[i]);
        if ((i + 1) % 4 == 0) {
            printf("\n");
        }
    }
}

canonical_original_code:
void print_results(struct processor *p) {
    printf("Final state:\n");
    printf("r0: %X\tr1: %X\n", p->r0, p->r1);
    printf("Memory:\n");
    int i;
    for (i = 0; i < 16; ++i) {
        printf("%X ", p->mem[i]);
        if ((i + 1) % 4 == 0) {
            printf("\n");
        }
    }
}

variable_types: struct processor { unsigned char r0; unsigned char r1; unsigned char mem[16]; } *

variable_types: i int