main

repo: Dorvaryn/ServerVideo

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
__int64 v4; // rbp
int i; // ebx
__int64 v6; // rbp
int j; // ebx
char *v8; // rcx
char v9; // al
__int64 v10; // rbp
int k; // er13
__int64 l; // rbx
__int64 v13; // rbp
int m; // er13
__int64 n; // rbx
__int64 v16; // rbp
int ii; // er13
__int64 jj; // rbx
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
int v21; // [rsp+10h] [rbp-68h] BYREF
void *v22; // [rsp+18h] [rbp-60h]
int v23; // [rsp+20h] [rbp-58h] BYREF
void *v24; // [rsp+28h] [rbp-50h]
int v25; // [rsp+30h] [rbp-48h] BYREF
void *ptr; // [rsp+38h] [rbp-40h]
struct epoll_event event; // [rsp+44h] [rbp-34h] BYREF

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
v3 = epoll_create(10);
if ( v3 == -1 )
perror("epollfd");
event.events = 1;
event.data.fd = 0;
if ( epoll_ctl(v3, 1, 0, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev)");
v25 = 0;
ptr = malloc(0x600uLL);
v23 = 0;
v24 = malloc(0x600uLL);
v21 = 0;
v22 = malloc(0x600uLL);
catalogue = (void *)buildCatalogue(v3, &v25, &v23, &v21);
if ( v21 > 0 )
{
v4 = 0LL;
for ( i = 0; i < v21; ++i )
{
pthread_create(&newthread, 0LL, (void *(*)(void *))&multiFlux, (char *)v22 + v4);
pthread_detach(newthread);
v4 += 48LL;
}
}
if ( v23 > 0 )
{
v6 = 0LL;
for ( j = 0; j < v23; ++j )
{
v8 = (char *)v24 + v6;
v9 = *((_BYTE *)v24 + v6 + 16);
if ( v9 == 2 )
{
pthread_create(&newthread, 0LL, (void *(*)(void *))&udp_pull, v8);
pthread_detach(newthread);
}
else if ( v9 == 3 )
{
pthread_create(&newthread, 0LL, (void *(*)(void *))&udp_push, v8);
pthread_detach(newthread);
}
v6 += 48LL;
}
}
central(v3, (__int64)&v25);
if ( v25 > 0 )
{
v10 = 0LL;
for ( k = 0; k < v25; ++k )
{
close(*(_DWORD *)((char *)ptr + v10));
for ( l = 0LL; l != 0x2000; l += 8LL )
{
free(*(void **)(*(_QWORD *)((char *)ptr + v10 + 40) + l));
*(_QWORD *)(*(_QWORD *)((char *)ptr + v10 + 40) + l) = 0LL;
}
free(*(void **)((char *)ptr + v10 + 40));
*(_QWORD *)((char *)ptr + v10 + 40) = 0LL;
v10 += 48LL;
}
}
free(ptr);
ptr = 0LL;
if ( v23 > 0 )
{
v13 = 0LL;
for ( m = 0; m < v23; ++m )
{
close(*(_DWORD *)((char *)v24 + v13));
for ( n = 0LL; n != 0x2000; n += 8LL )
{
free(*(void **)(*(_QWORD *)((char *)v24 + v13 + 40) + n));
*(_QWORD *)(*(_QWORD *)((char *)v24 + v13 + 40) + n) = 0LL;
}
free(*(void **)((char *)v24 + v13 + 40));
*(_QWORD *)((char *)v24 + v13 + 40) = 0LL;
v13 += 48LL;
}
}
free(v24);
v24 = 0LL;
if ( v21 > 0 )
{
v16 = 0LL;
for ( ii = 0; ii < v21; ++ii )
{
close(*(_DWORD *)((char *)v22 + v16));
for ( jj = 0LL; jj != 0x2000; jj += 8LL )
{
free(*(void **)(*(_QWORD *)((char *)v22 + v16 + 40) + jj));
*(_QWORD *)(*(_QWORD *)((char *)v22 + v16 + 40) + jj) = 0LL;
}
free(*(void **)((char *)v22 + v16 + 40));
*(_QWORD *)((char *)v22 + v16 + 40) = 0LL;
v16 += 48LL;
}
}
free(v22);
v22 = 0LL;
free(catalogue);
catalogue = 0LL;
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
__int64 v4; // rbp
int i; // ebx
__int64 v6; // rbp
int j; // ebx
char *v8; // rcx
char v9; // al
__int64 v10; // rbp
int k; // er13
__int64 l; // rbx
__int64 v13; // rbp
int m; // er13
__int64 n; // rbx
__int64 v16; // rbp
int ii; // er13
__int64 jj; // rbx
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
int v21; // [rsp+10h] [rbp-68h] BYREF
void *v22; // [rsp+18h] [rbp-60h]
int v23; // [rsp+20h] [rbp-58h] BYREF
void *v24; // [rsp+28h] [rbp-50h]
int v25; // [rsp+30h] [rbp-48h] BYREF
void *ptr; // [rsp+38h] [rbp-40h]
struct epoll_event event; // [rsp+44h] [rbp-34h] BYREF

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
v3 = epoll_create(10);
if ( v3 == -1 )
perror("epollfd");
event.events = 1;
event.data.fd = 0;
if ( epoll_ctl(v3, 1, 0, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev)");
v25 = 0;
ptr = malloc(0x600uLL);
v23 = 0;
v24 = malloc(0x600uLL);
v21 = 0;
v22 = malloc(0x600uLL);
catalogue = (void *)buildCatalogue(v3, &v25, &v23, &v21);
if ( v21 > 0 )
{
v4 = 0LL;
for ( i = 0; i < v21; ++i )
{
pthread_create(&newthread, 0LL, (void *(*)(void *))&multiFlux, (char *)v22 + v4);
pthread_detach(newthread);
v4 += 48LL;
}
}
if ( v23 > 0 )
{
v6 = 0LL;
for ( j = 0; j < v23; ++j )
{
v8 = (char *)v24 + v6;
v9 = *((_BYTE *)v24 + v6 + 16);
if ( v9 == 2 )
{
pthread_create(&newthread, 0LL, (void *(*)(void *))&udp_pull, v8);
pthread_detach(newthread);
}
else if ( v9 == 3 )
{
pthread_create(&newthread, 0LL, (void *(*)(void *))&udp_push, v8);
pthread_detach(newthread);
}
v6 += 48LL;
}
}
func0(v3, (__int64)&v25);
if ( v25 > 0 )
{
v10 = 0LL;
for ( k = 0; k < v25; ++k )
{
close(*(_DWORD *)((char *)ptr + v10));
for ( l = 0LL; l != 0x2000; l += 8LL )
{
free(*(void **)(*(_QWORD *)((char *)ptr + v10 + 40) + l));
*(_QWORD *)(*(_QWORD *)((char *)ptr + v10 + 40) + l) = 0LL;
}
free(*(void **)((char *)ptr + v10 + 40));
*(_QWORD *)((char *)ptr + v10 + 40) = 0LL;
v10 += 48LL;
}
}
free(ptr);
ptr = 0LL;
if ( v23 > 0 )
{
v13 = 0LL;
for ( m = 0; m < v23; ++m )
{
close(*(_DWORD *)((char *)v24 + v13));
for ( n = 0LL; n != 0x2000; n += 8LL )
{
free(*(void **)(*(_QWORD *)((char *)v24 + v13 + 40) + n));
*(_QWORD *)(*(_QWORD *)((char *)v24 + v13 + 40) + n) = 0LL;
}
free(*(void **)((char *)v24 + v13 + 40));
*(_QWORD *)((char *)v24 + v13 + 40) = 0LL;
v13 += 48LL;
}
}
free(v24);
v24 = 0LL;
if ( v21 > 0 )
{
v16 = 0LL;
for ( ii = 0; ii < v21; ++ii )
{
close(*(_DWORD *)((char *)v22 + v16));
for ( jj = 0LL; jj != 0x2000; jj += 8LL )
{
free(*(void **)(*(_QWORD *)((char *)v22 + v16 + 40) + jj));
*(_QWORD *)(*(_QWORD *)((char *)v22 + v16 + 40) + jj) = 0LL;
}
free(*(void **)((char *)v22 + v16 + 40));
*(_QWORD *)((char *)v22 + v16 + 40) = 0LL;
v16 += 48LL;
}
}
free(v22);
v22 = 0LL;
free(catalogue);
catalogue = 0LL;
close(v3);
return 0;
}

original_code:
int main(int argc, char ** argv)
{
  struct epoll_event ev;
  memset(&ev, 0, sizeof(struct epoll_event));
  int epollfd;
  epollfd = epoll_create(10);
  if(epollfd == -1) { perror("epollfd");};
  ev.events = EPOLLIN;
  ev.data.fd = 0;
  if(epoll_ctl(epollfd, 1, 0, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev)");};
  struct tabFlux tabFluxTCP;
  tabFluxTCP.nbFlux = 0;
  tabFluxTCP.flux = (struct flux *)malloc(32*sizeof(struct flux));
  struct tabFlux tabFluxUDP;
  tabFluxUDP.nbFlux = 0;
  tabFluxUDP.flux = (struct flux *)malloc(32*sizeof(struct flux));
  struct tabFlux tabFluxMCAST;
  tabFluxMCAST.nbFlux = 0;
  tabFluxMCAST.flux = (struct flux *)malloc(32*sizeof(struct flux));
  catalogue = buildCatalogue(epollfd, &tabFluxTCP, &tabFluxUDP, &tabFluxMCAST);
  int i;
  for(i = 0; i < tabFluxMCAST.nbFlux; i++) {
   pthread_t thread;
   pthread_create(&thread, ((void *)0), multiFlux, (void*)&tabFluxMCAST.flux[i]);
   pthread_detach(thread);
  }
  for(i = 0; i < tabFluxUDP.nbFlux; i++)
  {
   if(tabFluxUDP.flux[i].infosVideo.type == 2)
   {
    pthread_t thread;
    pthread_create(&thread, ((void *)0), udp_pull, (void*)&tabFluxUDP.flux[i]);
    pthread_detach(thread);
   }
   else if(tabFluxUDP.flux[i].infosVideo.type == 3)
   {
    pthread_t thread;
    pthread_create(&thread, ((void *)0), udp_push, (void*)&tabFluxUDP.flux[i]);
    pthread_detach(thread);
   }
  }
  central(epollfd, &tabFluxTCP, &tabFluxUDP);
  int j;
  for(i = 0; i < tabFluxTCP.nbFlux; i++) {
      close(tabFluxTCP.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxTCP.flux[i].infosVideo.images[j]);
    tabFluxTCP.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxTCP.flux[i].infosVideo.images);
   tabFluxTCP.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxTCP.flux);
  tabFluxTCP.flux = ((void *)0);
  for(i = 0; i < tabFluxUDP.nbFlux; i++) {
      close(tabFluxUDP.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxUDP.flux[i].infosVideo.images[j]);
    tabFluxUDP.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxUDP.flux[i].infosVideo.images);
   tabFluxUDP.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxUDP.flux);
  tabFluxUDP.flux = ((void *)0);
  for(i = 0; i < tabFluxMCAST.nbFlux; i++) {
      close(tabFluxMCAST.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxMCAST.flux[i].infosVideo.images[j]);
    tabFluxMCAST.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxMCAST.flux[i].infosVideo.images);
   tabFluxMCAST.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxMCAST.flux);
  tabFluxMCAST.flux = ((void *)0);
  free(catalogue);
  catalogue = ((void *)0);
  close(epollfd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct epoll_event ev;
  memset(&ev, 0, sizeof(struct epoll_event));
  int epollfd;
  epollfd = epoll_create(10);
  if(epollfd == -1) { perror("epollfd");};
  ev.events = EPOLLIN;
  ev.data.fd = 0;
  if(epoll_ctl(epollfd, 1, 0, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev)");};
  struct tabFlux tabFluxTCP;
  tabFluxTCP.nbFlux = 0;
  tabFluxTCP.flux = (struct flux *)malloc(32*sizeof(struct flux));
  struct tabFlux tabFluxUDP;
  tabFluxUDP.nbFlux = 0;
  tabFluxUDP.flux = (struct flux *)malloc(32*sizeof(struct flux));
  struct tabFlux tabFluxMCAST;
  tabFluxMCAST.nbFlux = 0;
  tabFluxMCAST.flux = (struct flux *)malloc(32*sizeof(struct flux));
  catalogue = buildCatalogue(epollfd, &tabFluxTCP, &tabFluxUDP, &tabFluxMCAST);
  int i;
  for(i = 0; i < tabFluxMCAST.nbFlux; i++) {
   unsigned long thread;
   pthread_create(&thread, ((void *)0), multiFlux, (void *)&tabFluxMCAST.flux[i]);
   pthread_detach(thread);
  }
  for(i = 0; i < tabFluxUDP.nbFlux; i++)
  {
   if(tabFluxUDP.flux[i].infosVideo.type == 2)
   {
    unsigned long thread;
    pthread_create(&thread, ((void *)0), udp_pull, (void *)&tabFluxUDP.flux[i]);
    pthread_detach(thread);
   }
   else if(tabFluxUDP.flux[i].infosVideo.type == 3)
   {
    unsigned long thread;
    pthread_create(&thread, ((void *)0), udp_push, (void *)&tabFluxUDP.flux[i]);
    pthread_detach(thread);
   }
  }
  central(epollfd, &tabFluxTCP, &tabFluxUDP);
  int j;
  for(i = 0; i < tabFluxTCP.nbFlux; i++) {
      close(tabFluxTCP.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxTCP.flux[i].infosVideo.images[j]);
    tabFluxTCP.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxTCP.flux[i].infosVideo.images);
   tabFluxTCP.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxTCP.flux);
  tabFluxTCP.flux = ((void *)0);
  for(i = 0; i < tabFluxUDP.nbFlux; i++) {
      close(tabFluxUDP.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxUDP.flux[i].infosVideo.images[j]);
    tabFluxUDP.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxUDP.flux[i].infosVideo.images);
   tabFluxUDP.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxUDP.flux);
  tabFluxUDP.flux = ((void *)0);
  for(i = 0; i < tabFluxMCAST.nbFlux; i++) {
      close(tabFluxMCAST.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxMCAST.flux[i].infosVideo.images[j]);
    tabFluxMCAST.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxMCAST.flux[i].infosVideo.images);
   tabFluxMCAST.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxMCAST.flux);
  tabFluxMCAST.flux = ((void *)0);
  free(catalogue);
  catalogue = ((void *)0);
  close(epollfd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }

variable_types: epollfd int

variable_types: struct tabFlux { int nbFlux; struct flux { int sock; int port; char *adresse; struct infosVideo { char type; double fps; int nbImages; char **images; } infosVideo; } *flux; }

variable_types:
thread
unsigned long

variable_types: j int

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

user_defined_types: struct tabFlux { int nbFlux; struct flux *flux; }

user_defined_types: struct flux { int sock; int port; char *adresse; struct infosVideo infosVideo; }


getTime

decompiled_code:
double getTime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func2()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double getTime() {
 struct timeval timev;
 gettimeofday(&timev, ((void *)0));
 double micro = (double)timev.tv_usec;
 double sec = (double)timev.tv_sec;
 return sec + micro/1000000;
}

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

variable_types: micro double

variable_types: sec double

return_type: double


timeInterval

decompiled_code:
__m128 __fastcall timeInterval(double a1, __m128 a2)
{
if ( *(double *)a2.m128_u64 > a1 )
*(double *)a2.m128_u64 = *(double *)a2.m128_u64 - a1;
return a2;
}

original_code:
double timeInterval(double t1, double t2) {
    return (t1 < t2 ? t2-t1 : t2);
}


decompiled_code:
void __fastcall send_get_answer(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2, 0) == -1 )
perror("send(fd, catalogue, strlen(catalogue), 0)");
}

canonical_decompiled_code:
void __fastcall func4(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2, 0) == -1 )
perror("send(fd, catalogue, strlen(catalogue), 0)");
}

original_code:
void send_get_answer(int fd, char * catalogue)
{
 if(send(fd, catalogue, strlen(catalogue), 0) == -1) { perror("send(fd, catalogue, strlen(catalogue), 0)");};
}

canonical_original_code:
void send_get_answer(int fd, char *catalogue)
{
 if(send(fd, catalogue, strlen(catalogue), 0) == -1) { perror("send(fd, catalogue, strlen(catalogue), 0)");};
}

variable_types: fd int

variable_types:
catalogue
char *

return_type: void


createSockEventTCP

decompiled_code:
__int64 __fastcall createSockEventTCP(int epfd, __int16 a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
__int64 v4; // rdx
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 1, 0);
if ( v2 == -1 )
perror("sock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
v4 = v3;
BYTE1(v4) = BYTE1(v3) | 8;
if ( fcntl(v2, 4, v4) == -1 )
perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");
*(_DWORD *)&addr.sa_data[10] = 0;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
if ( bind(v2, &addr, 0x10u) == -1 )
perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");
if ( listen(v2, 10) == -1 )
perror("listen(sock, 10)");
event.events = -2147483647;
event.data.u64 = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(int epfd, __int16 a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
__int64 v4; // rdx
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 1, 0);
if ( v2 == -1 )
perror("sock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
v4 = v3;
BYTE1(v4) = BYTE1(v3) | 8;
if ( fcntl(v2, 4, v4) == -1 )
perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");
*(_DWORD *)&addr.sa_data[10] = 0;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func0(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(a2);
if ( bind(v2, &addr, 0x10u) == -1 )
perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");
if ( listen(v2, 10) == -1 )
perror("listen(sock, 10)");
event.events = -2147483647;
event.data.u64 = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");
return v2;
}

original_code:
int createSockEventTCP(int epollfd, int port)
{
 int sock = socket(2, SOCK_STREAM, 0);
 if(sock == -1) { perror("sock");};
 int flags = fcntl(sock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(sock,4,flags|04000) == -1) { perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");};
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(struct sockaddr_in));
 saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");};
 if(listen(sock, 10) == -1) { perror("listen(sock, 10)");};
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = sock;
 if(epoll_ctl(epollfd, 1, sock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");};
 return sock;
}

canonical_original_code:
int createSockEventTCP(int epollfd, int port)
{
 int sock = socket(2, SOCK_STREAM, 0);
 if(sock == -1) { perror("sock");};
 int flags = fcntl(sock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(sock,4,flags|04000) == -1) { perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");};
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(struct sockaddr_in));
 saddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");};
 if(listen(sock, 10) == -1) { perror("listen(sock, 10)");};
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = sock;
 if(epoll_ctl(epollfd, 1, sock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");};
 return sock;
}

variable_types: port int

variable_types: sock int

variable_types: flags 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]; }

return_type: 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: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }

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


createSockEventUDP

decompiled_code:
__int64 __fastcall createSockEventUDP(int epfd, __int16 a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
__int64 v4; // rdx
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 2, 0);
if ( v2 == -1 )
perror("sock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
v4 = v3;
BYTE1(v4) = BYTE1(v3) | 8;
if ( fcntl(v2, 4, v4) == -1 )
perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");
*(_DWORD *)&addr.sa_data[10] = 0;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
if ( bind(v2, &addr, 0x10u) == -1 )
perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");
event.events = -2147483647;
event.data.u64 = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(int epfd, __int16 a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
__int64 v4; // rdx
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 2, 0);
if ( v2 == -1 )
perror("sock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
v4 = v3;
BYTE1(v4) = BYTE1(v3) | 8;
if ( fcntl(v2, 4, v4) == -1 )
perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");
*(_DWORD *)&addr.sa_data[10] = 0;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func0(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(a2);
if ( bind(v2, &addr, 0x10u) == -1 )
perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");
event.events = -2147483647;
event.data.u64 = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");
return v2;
}

original_code:
int createSockEventUDP(int epollfd, int port)
{
 int sock = socket(2, SOCK_DGRAM, 0);
 if(sock == -1) { perror("sock");};
 int flags = fcntl(sock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(sock,4,flags|04000) == -1) { perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");};
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(struct sockaddr_in));
 saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");};
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = sock;
 if(epoll_ctl(epollfd, 1, sock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");};
 return sock;
}

canonical_original_code:
int createSockEventUDP(int epollfd, int port)
{
 int sock = socket(2, SOCK_DGRAM, 0);
 if(sock == -1) { perror("sock");};
 int flags = fcntl(sock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(sock,4,flags|04000) == -1) { perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");};
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(struct sockaddr_in));
 saddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");};
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = sock;
 if(epoll_ctl(epollfd, 1, sock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");};
 return sock;
}


createSockClientEvent

decompiled_code:
__int64 __fastcall createSockClientEvent(int epfd, int fd)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
__int64 v4; // rdx
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
struct epoll_event event; // [rsp+24h] [rbp-24h] BYREF

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr_len = 16;
v2 = accept(fd, &addr, &addr_len);
if ( v2 == -1 )
perror("csock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
v4 = v3;
BYTE1(v4) = BYTE1(v3) | 8;
if ( fcntl(v2, 4, v4) == -1 )
perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");
event.events = -2147483643;
event.data.fd = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int epfd, int fd)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
__int64 v4; // rdx
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
struct epoll_event event; // [rsp+24h] [rbp-24h] BYREF

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr_len = 16;
v2 = accept(fd, &addr, &addr_len);
if ( v2 == -1 )
perror("csock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
v4 = v3;
BYTE1(v4) = BYTE1(v3) | 8;
if ( fcntl(v2, 4, v4) == -1 )
perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");
event.events = -2147483643;
event.data.fd = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
return v2;
}

original_code:
int createSockClientEvent(int epollfd, int sock)
{
 int csock;
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 struct sockaddr_in saddr_client;
 memset(&saddr_client, 0, sizeof(struct sockaddr_in));
 socklen_t size_addr = sizeof(struct sockaddr_in);
 csock = accept(sock, (struct sockaddr *)&saddr_client, &size_addr);
 if(csock == -1) { perror("csock");}
 int flags = fcntl(csock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(csock,4,flags|04000) == -1) { perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");};
 ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
 ev.data.fd = csock;
 if(epoll_ctl(epollfd, 1, csock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");};
 return csock;
}

canonical_original_code:
int createSockClientEvent(int epollfd, int sock)
{
 int csock;
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 struct sockaddr_in saddr_client;
 memset(&saddr_client, 0, sizeof(struct sockaddr_in));
 unsigned int size_addr = sizeof(struct sockaddr_in);
 csock = accept(sock, (struct sockaddr *)&saddr_client, &size_addr);
 if(csock == -1) { perror("csock");}
 int flags = fcntl(csock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(csock,4,flags|04000) == -1) { perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");};
 ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
 ev.data.fd = csock;
 if(epoll_ctl(epollfd, 1, csock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");};
 return csock;
}

variable_types: csock int


createFichier

original_code:
void createFichier(int epollfd, struct tabFlux * tabFlux, int port, int * baseFichierCourante, int type)
{
 if (tabFlux->nbFlux >= *baseFichierCourante)
 {
  *baseFichierCourante *=2;
  struct flux * temp;
  temp = (struct flux *) realloc(tabFlux->flux,
    *baseFichierCourante*sizeof(struct flux));
  if (temp!=((void *)0))
  {
   tabFlux->flux = temp;
  }
  else
  {
   free (tabFlux->flux);
   puts ("Error (re)allocating memory");
   exit (1);
  }
 }
 if( type == 0 || type == 1 )
 {
  tabFlux->flux[tabFlux->nbFlux].sock = createSockEventTCP(epollfd,port);
 }
 tabFlux->flux[tabFlux->nbFlux].port = port;
 tabFlux->flux[tabFlux->nbFlux].infosVideo.nbImages = 0;
 tabFlux->flux[tabFlux->nbFlux].infosVideo.images = (char **)malloc(1024*sizeof(char*));
 int k;
 for (k = 0; k < 1024; k++)
 {
  tabFlux->flux[tabFlux->nbFlux].infosVideo.images[k] = (char *)malloc(512*sizeof(char));
 }
 tabFlux->nbFlux++;
}

canonical_original_code:
void createFichier(int epollfd, struct tabFlux *tabFlux, int port, int *baseFichierCourante, int type)
{
 if (tabFlux->nbFlux >= *baseFichierCourante)
 {
  *baseFichierCourante *=2;
  struct flux *temp;
  temp = (struct flux *) realloc(tabFlux->flux,
    *baseFichierCourante*sizeof(struct flux));
  if (temp!=((void *)0))
  {
   tabFlux->flux = temp;
  }
  else
  {
   free (tabFlux->flux);
   puts ("Error (re)allocating memory");
   exit (1);
  }
 }
 if( type == 0 || type == 1 )
 {
  tabFlux->flux[tabFlux->nbFlux].sock = createSockEventTCP(epollfd,port);
 }
 tabFlux->flux[tabFlux->nbFlux].port = port;
 tabFlux->flux[tabFlux->nbFlux].infosVideo.nbImages = 0;
 tabFlux->flux[tabFlux->nbFlux].infosVideo.images = (char **)malloc(1024*sizeof(char *));
 int k;
 for (k = 0; k < 1024; k++)
 {
  tabFlux->flux[tabFlux->nbFlux].infosVideo.images[k] = (char *)malloc(512*sizeof(char));
 }
 tabFlux->nbFlux++;
}

variable_types: struct tabFlux { int nbFlux; struct flux { int sock; int port; char *adresse; struct infosVideo { char type; double fps; int nbImages; char **images; } infosVideo; } *flux; } *

variable_types:
baseFichierCourante
int *

variable_types: type int

variable_types: k int


addImage

decompiled_code:
char *__fastcall addImage(char *src, __int64 a2)
{
char *result; // rax

result = strcpy(*(char **)(*(_QWORD *)(a2 + 24) + 8LL * *(int *)(a2 + 16)), src);
++*(_DWORD *)(a2 + 16);
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *src, __int64 a2)
{
char *result; // rax

result = strcpy(*(char **)(*(_QWORD *)(a2 + 24) + 8LL * *(int *)(a2 + 16)), src);
++*(_DWORD *)(a2 + 16);
return result;
}

original_code:
void addImage(char * uneImage, struct infosVideo * infos)
{
 strcpy(infos->images[infos->nbImages], uneImage);
 infos->nbImages++;
}

canonical_original_code:
void addImage(char *uneImage, struct infosVideo *infos)
{
 strcpy(infos->images[infos->nbImages], uneImage);
 infos->nbImages++;
}

variable_types:
uneImage
char *

variable_types: struct infosVideo { char type; double fps; int nbImages; char **images; } *


createEventPull

decompiled_code:
void __fastcall createEventPull(int a1, unsigned int a2)
{
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

event.events = -2147483644;
event.data.u64 = a2;
if ( epoll_ctl(a1, 1, a2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
}

canonical_decompiled_code:
void __fastcall func11(int a1, unsigned int a2)
{
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

event.events = -2147483644;
event.data.u64 = a2;
if ( epoll_ctl(a1, 1, a2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
}

original_code:
void createEventPull(int epollfd, int csock)
{
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLOUT | EPOLLET;
 ev.data.fd = csock;
 if(epoll_ctl(epollfd, 1, csock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");};
}

variable_types: epollfd int

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }


createEventPush

decompiled_code:
void __fastcall createEventPush(int a1, unsigned int a2)
{
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

event.events = 4;
event.data.u64 = a2;
if ( epoll_ctl(a1, 1, a2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
}

canonical_decompiled_code:
void __fastcall func12(int a1, unsigned int a2)
{
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

event.events = 4;
event.data.u64 = a2;
if ( epoll_ctl(a1, 1, a2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
}

original_code:
void createEventPush(int epollfd, int csock)
{
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLOUT;
 ev.data.fd = csock;
 if(epoll_ctl(epollfd, 1, csock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");};
}


connectDataTCP

decompiled_code:
__int64 __fastcall connectDataTCP(int a1, int a2, __int16 a3, int a4)
{
unsigned int v6; // ebx
unsigned int v7; // ebp
__int64 v8; // rdx
socklen_t len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
len = 16;
if ( getpeername(a2, &addr, &len) == -1 )
perror("getpeername(sock, (struct sockaddr*)&addr, &len)");
*(_WORD *)addr.sa_data = _bswap_16(a3);
v6 = socket(2, 1, 0);
v7 = fcntl(v6, 3, 2048LL);
if ( v7 == -1 )
perror("flags");
v8 = v7;
BYTE1(v8) = BYTE1(v7) | 8;
if ( fcntl(v6, 4, v8) == -1 )
perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");
if ( v6 == -1 )
perror("csock");
if ( connect(v6, &addr, len) == -1 )
perror("connect(csock, (struct sockaddr *)&addr, len)");
if ( a4 )
{
if ( a4 == 1 )
createEventPush(a1, v6);
}
else
{
createEventPull(a1, v6);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2, __int16 a3, int a4)
{
unsigned int v6; // ebx
unsigned int v7; // ebp
__int64 v8; // rdx
socklen_t len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
len = 16;
if ( getpeername(a2, &addr, &len) == -1 )
perror("getpeername(sock, (struct sockaddr*)&addr, &len)");
*(_WORD *)addr.sa_data = func1(a3);
v6 = socket(2, 1, 0);
v7 = fcntl(v6, 3, 2048LL);
if ( v7 == -1 )
perror("flags");
v8 = v7;
BYTE1(v8) = BYTE1(v7) | 8;
if ( fcntl(v6, 4, v8) == -1 )
perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");
if ( v6 == -1 )
perror("csock");
if ( connect(v6, &addr, len) == -1 )
perror("connect(csock, (struct sockaddr *)&addr, len)");
if ( a4 )
{
if ( a4 == 1 )
func12(a1, v6);
}
else
{
func11(a1, v6);
}
return v6;
}

original_code:
int connectDataTCP(int epollfd, int sock, int port, int type)
{
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 int csock;
 socklen_t len = sizeof(struct sockaddr_in);
 if(getpeername(sock, (struct sockaddr*)&addr, &len) == -1) { perror("getpeername(sock, (struct sockaddr*)&addr, &len)");};
 addr.sin_port = htons(port);
 csock = socket(2, SOCK_STREAM, 0);
 int flags = fcntl(csock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(csock,4,flags|04000) == -1) { perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");};
 if(csock == -1) { perror("csock");};
 if(connect(csock, (struct sockaddr *)&addr, len) == -1) { perror("connect(csock, (struct sockaddr *)&addr, len)");};
 if(type == 0)
 {
  createEventPull(epollfd, csock);
 }
 else if(type == 1)
 {
  createEventPush(epollfd, csock);
 }
    return csock;
}

canonical_original_code:
int connectDataTCP(int epollfd, int sock, int port, int type)
{
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 int csock;
 unsigned int len = sizeof(struct sockaddr_in);
 if(getpeername(sock, (struct sockaddr *)&addr, &len) == -1) { perror("getpeername(sock, (struct sockaddr*)&addr, &len)");};
 addr.sin_port = htons(port);
 csock = socket(2, SOCK_STREAM, 0);
 int flags = fcntl(csock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(csock,4,flags|04000) == -1) { perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");};
 if(csock == -1) { perror("csock");};
 if(connect(csock, (struct sockaddr *)&addr, len) == -1) { perror("connect(csock, (struct sockaddr *)&addr, len)");};
 if(type == 0)
 {
  createEventPull(epollfd, csock);
 }
 else if(type == 1)
 {
  createEventPush(epollfd, csock);
 }
    return csock;
}

variable_types:
len
unsigned int


multiCatalogue

decompiled_code:
void __fastcall __noreturn multiCatalogue(char *s)
{
int v1; // er12
char *v2; // rbp
int v3; // ebx
int v4; // eax
struct sockaddr v5; // [rsp+0h] [rbp-38h] BYREF

v1 = socket(2, 2, 0);
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[6] = 0LL;
*(_DWORD *)&v5.sa_data[2] = inet_addr("225.6.7.8");
*(_WORD *)v5.sa_data = _bswap_16(4567);
while ( 1 )
{
v3 = strlen(s);
v2 = s;
do
{
v4 = sendto(v1, v2, v3, 0, &v5, 0x10u);
if ( v4 == -1 )
{
perror("nbSent");
}
else if ( v4 > 0 )
{
v2 += v4;
v3 -= v4;
}
}
while ( v3 > 0 );
sleep(1u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(char *s)
{
int v1; // er12
char *v2; // rbp
int v3; // ebx
int v4; // eax
struct sockaddr v5; // [rsp+0h] [rbp-38h] BYREF

v1 = socket(2, 2, 0);
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[6] = 0LL;
*(_DWORD *)&v5.sa_data[2] = inet_addr("225.6.7.8");
*(_WORD *)v5.sa_data = func0(4567);
while ( 1 )
{
v3 = strlen(s);
v2 = s;
do
{
v4 = sendto(v1, v2, v3, 0, &v5, 0x10u);
if ( v4 == -1 )
{
perror("nbSent");
}
else if ( v4 > 0 )
{
v2 += v4;
v3 -= v4;
}
}
while ( v3 > 0 );
sleep(1u);
}
}

original_code:
void* multiCatalogue(void* args) {
 char * origineBuffer = (char *)args;
 int clientSocket = socket(2, SOCK_DGRAM, 0);
 struct sockaddr_in dest_addr;
 memset(&dest_addr,0,sizeof(dest_addr));
 dest_addr.sin_family = 2;
 dest_addr.sin_addr.s_addr = inet_addr("225.6.7.8");
 dest_addr.sin_port = htons(4567);
 while(1)
 {
  char * buffer = origineBuffer;
  int bufLen = strlen(origineBuffer);
  int nbSent = 0;
  do
  {
   nbSent = sendto(clientSocket, buffer, bufLen, 0,
     (struct sockaddr*)&dest_addr, sizeof(struct sockaddr));
   if(nbSent == -1) { perror("nbSent");};
   if( nbSent > 0)
   {
    buffer += nbSent;
    bufLen -= nbSent;
   }
  } while (bufLen > 0);
  sleep(1);
 }
 return ((void *)0);
}

canonical_original_code:
void *multiCatalogue(void *args) {
 char *origineBuffer = (char *)args;
 int clientSocket = socket(2, SOCK_DGRAM, 0);
 struct sockaddr_in dest_addr;
 memset(&dest_addr,0,sizeof(dest_addr));
 dest_addr.sin_family = 2;
 dest_addr.sin_addr.s_addr = inet_addr("225.6.7.8");
 dest_addr.sin_port = htons(4567);
 while(1)
 {
  char *buffer = origineBuffer;
  int bufLen = strlen(origineBuffer);
  int nbSent = 0;
  do
  {
   nbSent = sendto(clientSocket, buffer, bufLen, 0,
     (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
   if(nbSent == -1) { perror("nbSent");};
   if( nbSent > 0)
   {
    buffer += nbSent;
    bufLen -= nbSent;
   }
  } while (bufLen > 0);
  sleep(1);
 }
 return ((void *)0);
}

variable_types:
args
void *

variable_types:
origineBuffer
char *

variable_types: clientSocket int

variable_types:
buffer
char *

variable_types: bufLen int

variable_types: nbSent int

return_type: void *


parseInt

decompiled_code:
__int64 __fastcall parseInt(const char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rcx
char *v3; // rsi
__int64 result; // rax

if ( !strcmp(a1, "-1") )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = *_ctype_b_loc();
v3 = (char *)(a1 + 1);
LODWORD(result) = 0;
while ( (v2[v1] & 0x800) != 0 )
{
result = (unsigned int)(v1 + 10 * result - 48);
v1 = *v3++;
if ( !v1 )
return result;
}
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rcx
char *v3; // rsi
__int64 result; // rax

if ( !strcmp(a1, "-1") )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = *_ctype_b_loc();
v3 = (char *)(a1 + 1);
LODWORD(result) = 0;
while ( (v2[v1] & 0x800) != 0 )
{
result = (unsigned int)(v1 + 10 * result - 48);
v1 = *v3++;
if ( !v1 )
return result;
}
return 4294967294LL;
}

original_code:
int parseInt(char* entier) {
 if(strcmp(entier, "-1") == 0) {
  return -1;
 }
 int res = 0;
 int i;
 for(i = 0; entier[i] != '\0'; i++) {
  char c = entier[i];
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
   res = res*10+(c-'0');
  } else {
   return -2;
  }
 }
 return res;
}

canonical_original_code:
int parseInt(char *entier) {
 if(strcmp(entier, "-1") == 0) {
  return -1;
 }
 int res = 0;
 int i;
 for(i = 0; entier[i] != '\0'; i++) {
  char c = entier[i];
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
   res = res*10+(c-'0');
  } else {
   return -2;
  }
 }
 return res;
}

variable_types:
entier
char *

variable_types: res int

variable_types: i int

variable_types: c char


initReq

original_code:
void initReq(struct requete* req) {
 req->type = (-1);
 req->isOver = 0;
 req->imgId = -2;
 req->listenPort = -1;
 req->fragmentSize = -1;
 req->inWord = 0;
 req->space = 0;
 req->crlfCounter = 0;
 req->mot = 0;
 req->motPosition = 0;
 req->reqPosition = 0;
}

canonical_original_code:
void initReq(struct requete *req) {
 req->type = (-1);
 req->isOver = 0;
 req->imgId = -2;
 req->listenPort = -1;
 req->fragmentSize = -1;
 req->inWord = 0;
 req->space = 0;
 req->crlfCounter = 0;
 req->mot = 0;
 req->motPosition = 0;
 req->reqPosition = 0;
}

variable_types: struct requete { int type; int isOver; int imgId; int listenPort; int fragmentSize; int inWord; int space; int crlfCounter; char *mot; int motPosition; int reqPosition; } *


decompiled_code:
const char *build_date()
{
return "00 / 00 / 00";
}

canonical_decompiled_code:
const char *func0()
{
return "00 / 00 / 00";
}

original_code:
char * build_date()
{
 return "00 / 00 / 00";
}

return_type: char *


decompiled_code:
void *__fastcall build_http_header(char *src, unsigned int a2)
{
void *v2; // rbx
const char *v3; // rax
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = malloc(0x100uLL);
memset(v2, 0, 0x100uLL);
strcat((char *)v2, "HTTP/1.1 200 OK\r\nDate: ");
v3 = build_date();
strcat((char *)v2, v3);
strcat((char *)v2, "\r\nServer: ServLib (Unix) (Arch/Linux)\r\nAccept-Ranges: bytes\r\nContent-Length: ");
v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
sprintf((char *)v5, "%d", a2);
strcat((char *)v2, (const char *)v5);
strcat((char *)v2, "\r\nConnection: close\r\nContent-Type: ");
strcat((char *)v2, src);
strcat((char *)v2, "; charset=UTF-8\r\n\r\n");
return v2;
}

canonical_decompiled_code:
void *__fastcall func1(char *src, unsigned int a2)
{
void *v2; // rbx
const char *v3; // rax
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = malloc(0x100uLL);
memset(v2, 0, 0x100uLL);
strcat((char *)v2, "HTTP/1.1 200 OK\r\nDate: ");
v3 = func0();
strcat((char *)v2, v3);
strcat((char *)v2, "\r\nServer: ServLib (Unix) (Arch/Linux)\r\nAccept-Ranges: bytes\r\nContent-Length: ");
v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
sprintf((char *)v5, "%d", a2);
strcat((char *)v2, (const char *)v5);
strcat((char *)v2, "\r\nConnection: close\r\nContent-Type: ");
strcat((char *)v2, src);
strcat((char *)v2, "; charset=UTF-8\r\n\r\n");
return v2;
}

original_code:
char * build_http_header(char * type, int size)
{
 char * header = malloc(256 * sizeof(char));
 memset(header, '\0', 256);
 strcat(header, "HTTP/1.1 200 OK\r\nDate: ");
 strcat(header, build_date());
 strcat(header, "\r\nServer: ServLib (Unix) (Arch/Linux)\r\nAccept-Ranges: bytes\r\nContent-Length: ");
 char tmp[32] = {'\0'};
 sprintf(tmp, "%d", size);
 strcat(header, tmp);
 strcat(header, "\r\nConnection: close\r\nContent-Type: ");
 strcat(header, type);
 strcat(header, "; charset=UTF-8\r\n\r\n");
 return header;
}

canonical_original_code:
char *build_http_header(char *type, int size)
{
 char *header = malloc(256 * sizeof(char));
 memset(header, '\0', 256);
 strcat(header, "HTTP/1.1 200 OK\r\nDate: ");
 strcat(header, build_date());
 strcat(header, "\r\nServer: ServLib (Unix) (Arch/Linux)\r\nAccept-Ranges: bytes\r\nContent-Length: ");
 char tmp[32] = {'\0'};
 sprintf(tmp, "%d", size);
 strcat(header, tmp);
 strcat(header, "\r\nConnection: close\r\nContent-Type: ");
 strcat(header, type);
 strcat(header, "; charset=UTF-8\r\n\r\n");
 return header;
}

variable_types:
type
char *

variable_types: size int

variable_types:
header
char *

variable_types:
tmp
char [32]


isPaired

decompiled_code:
__int64 __fastcall isPaired(char a1, char a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // ebx
unsigned int v5; // ebp

LOBYTE(v4) = a2 == 93 && a1 != 91;
if ( (_BYTE)v4 )
{
puts("Closing square bracket not preceded by opening square bracket.");
v4 = 0;
}
else
{
LOBYTE(a4) = a2 == 41 && a1 != 40;
v5 = a4;
if ( (_BYTE)a4 )
{
puts("Closing parentheses not preceded by opening parentheses.");
}
else if ( a1 != 123 && a2 == 125 )
{
puts("Closing bracket not preceded by opening bracket.");
v4 = v5;
}
else
{
LOBYTE(v4) = a2 == 93 && a1 == 91;
if ( (_BYTE)v4 )
{
puts("Found matching square brackets '[]'.");
}
else
{
LOBYTE(v4) = a2 == 41 && a1 == 40;
if ( (_BYTE)v4 )
{
puts("Found matching parentheses '()'.");
}
else
{
LOBYTE(v4) = a2 == 125 && a1 == 123;
if ( (_BYTE)v4 )
puts("Found matching brackets '{}'.");
}
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, char a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // ebx
unsigned int v5; // ebp

LOBYTE(v4) = a2 == 93 && a1 != 91;
if ( (_BYTE)v4 )
{
puts("Closing square bracket not preceded by opening square bracket.");
v4 = 0;
}
else
{
LOBYTE(a4) = a2 == 41 && a1 != 40;
v5 = a4;
if ( (_BYTE)a4 )
{
puts("Closing parentheses not preceded by opening parentheses.");
}
else if ( a1 != 123 && a2 == 125 )
{
puts("Closing bracket not preceded by opening bracket.");
v4 = v5;
}
else
{
LOBYTE(v4) = a2 == 93 && a1 == 91;
if ( (_BYTE)v4 )
{
puts("Found matching square brackets '[]'.");
}
else
{
LOBYTE(v4) = a2 == 41 && a1 == 40;
if ( (_BYTE)v4 )
{
puts("Found matching parentheses '()'.");
}
else
{
LOBYTE(v4) = a2 == 125 && a1 == 123;
if ( (_BYTE)v4 )
puts("Found matching brackets '{}'.");
}
}
}
}
return v4;
}

original_code:
_Bool isPaired(char openBracket, char closeBracket) {
    if (closeBracket == ']' && openBracket != '[') {
        printf("Closing square bracket not preceded by opening square bracket.\n");
        return 0;
    }
    if (closeBracket == ')' && openBracket != '(') {
        printf("Closing parentheses not preceded by opening parentheses.\n");
        return 0;
    }
    if (closeBracket == '}' && openBracket != '{') {
        printf("Closing bracket not preceded by opening bracket.\n");
        return 0;
    }
    if (closeBracket == ']' && openBracket == '[') {
        printf("Found matching square brackets '[]'.\n");
        return 1;
    }
    if (closeBracket == ')' && openBracket == '(') {
        printf("Found matching parentheses '()'.\n");
        return 1;
    }
    if (closeBracket == '}' && openBracket == '{') {
        printf("Found matching brackets '{}'.\n");
        return 1;
    }
}

variable_types: openBracket char

variable_types: closeBracket char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax

v3 = time(0LL);
srand(v3);
do
{
printf("Time Duration: ");
v4 = __isoc99_scanf();
}
while ( v4 != 1 );
do
{
do
{
printf("Arrival Air Probobility: ");
v5 = __isoc99_scanf();
}
while ( 0.0 > 1.0 );
}
while ( v5 != 1 );
do
{
do
{
printf("Arrival Ground Probobility: ");
v6 = __isoc99_scanf();
}
while ( 0.0 > 1.0 );
}
while ( v6 != 1 );
puts("\n");
simulate(0, 0.0, 0.0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax

v3 = time(0LL);
srand(v3);
do
{
printf("Time Duration: ");
v4 = __isoc99_scanf();
}
while ( v4 != 1 );
do
{
do
{
printf("Arrival Air Probobility: ");
v5 = __isoc99_scanf();
}
while ( 0.0 > 1.0 );
}
while ( v5 != 1 );
do
{
do
{
printf("Arrival Ground Probobility: ");
v6 = __isoc99_scanf();
}
while ( 0.0 > 1.0 );
}
while ( v6 != 1 );
puts("\n");
func14(0, 0.0, 0.0);
return 0;
}

original_code:
int main(int argc, char** argv) {
   srand(time(((void *)0)));
   int result = 0;
   int timeDuration = 0;
   double arrivalAirProb = 0;
   double arrivalGroundProb = 0;
   while (result != 1) {
   printf("Time Duration: ");
   result = scanf("%d", &timeDuration);
   if (timeDuration > 100) {
   result = 0;
   }
   }
   result = 0;
   while (result != 1) {
   printf("Arrival Air Probobility: ");
   result = scanf("%lf", &arrivalAirProb);
   if (arrivalAirProb > 1) {
   result = 0;
   }
   }
   result = 0;
   while (result != 1) {
   printf("Arrival Ground Probobility: ");
   result = scanf("%lf", &arrivalGroundProb);
   if (arrivalGroundProb > 1) {
   result = 0;
   }
   }
   printf("\n\n");
   simulate(timeDuration, arrivalAirProb, arrivalGroundProb);
   return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
   srand(time(((void *)0)));
   int result = 0;
   int timeDuration = 0;
   double arrivalAirProb = 0;
   double arrivalGroundProb = 0;
   while (result != 1) {
   printf("Time Duration: ");
   result = scanf("%d", &timeDuration);
   if (timeDuration > 100) {
   result = 0;
   }
   }
   result = 0;
   while (result != 1) {
   printf("Arrival Air Probobility: ");
   result = scanf("%lf", &arrivalAirProb);
   if (arrivalAirProb > 1) {
   result = 0;
   }
   }
   result = 0;
   while (result != 1) {
   printf("Arrival Ground Probobility: ");
   result = scanf("%lf", &arrivalGroundProb);
   if (arrivalGroundProb > 1) {
   result = 0;
   }
   }
   printf("\n\n");
   simulate(timeDuration, arrivalAirProb, arrivalGroundProb);
   return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: result int

variable_types: timeDuration int

variable_types: arrivalAirProb double

variable_types: arrivalGroundProb double


addToAir

decompiled_code:
void addToAir()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
_Bool addToAir(double arrivalAirProb) {
}


addToGroud

decompiled_code:
void addToGroud()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
_Bool addToGroud(double arrivalGroudProb) {
}

variable_types: arrivalGroudProb double


getData

decompiled_code:
_BOOL8 getData()
{
_BOOL4 v0; // edx
size_t v2; // [rsp+0h] [rbp-18h] BYREF
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = (char *)malloc(0x50uLL);
v2 = 8LL;
while ( 1 )
{
printf("(y/n) -> ");
if ( (unsigned int)getline(&lineptr, &v2, stdin) == -1 )
{
puts("INPUT ERROR.");
exit(1);
}
strtok(lineptr, "\n");
if ( !strcmp(lineptr, "y") )
break;
if ( !strcmp(lineptr, "n") || !strcmp(lineptr, "yes") || !strcmp(lineptr, "no") )
{
v0 = strcmp(lineptr, "yes") == 0;
goto LABEL_8;
}
*lineptr = 0;
}
v0 = 1;
LABEL_8:
*lineptr = 0;
return v0;
}

canonical_decompiled_code:
_BOOL8 func15()
{
_BOOL4 v0; // edx
size_t v2; // [rsp+0h] [rbp-18h] BYREF
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = (char *)malloc(0x50uLL);
v2 = 8LL;
while ( 1 )
{
printf("(y/n) -> ");
if ( (unsigned int)getline(&lineptr, &v2, stdin) == -1 )
{
puts("INPUT ERROR.");
exit(1);
}
strtok(lineptr, "\n");
if ( !strcmp(lineptr, "y") )
break;
if ( !strcmp(lineptr, "n") || !strcmp(lineptr, "yes") || !strcmp(lineptr, "no") )
{
v0 = strcmp(lineptr, "yes") == 0;
goto LABEL_8;
}
*lineptr = 0;
}
v0 = 1;
LABEL_8:
*lineptr = 0;
return v0;
}

original_code:
int getData() {
        char *response = (char*) malloc(sizeof (char)*80);
        size_t responseSize = sizeof (response);
        int bytes_read = 1;
        while (1) {
            printf("(y/n) -> ");
            bytes_read = getline(&response, &responseSize, stdin);
            if (bytes_read == -1) {
                printf("INPUT ERROR.\n");
                exit(1);
            } else {
                strtok(response, "\n");
            }
            if (strcmp(response, "y") == 0 || strcmp(response, "n") == 0 || strcmp(response, "yes") == 0 || strcmp(response, "no") == 0) {
                break;
            } else {
                *response = 0;
                continue;
            }
        }
        if (strcmp(response, "y") == 0 || strcmp(response, "yes") == 0) {
            *response = 0;
            return 1;
        } else {
            *response = 0;
            return 0;
        }
    }

canonical_original_code:
int getData() {
        char *response = (char*) malloc(sizeof (char)*80);
        unsigned long responseSize = sizeof (response);
        int bytes_read = 1;
        while (1) {
            printf("(y/n) -> ");
            bytes_read = getline(&response, &responseSize, stdin);
            if (bytes_read == -1) {
                printf("INPUT ERROR.\n");
                exit(1);
            } else {
                strtok(response, "\n");
            }
            if (strcmp(response, "y") == 0 || strcmp(response, "n") == 0 || strcmp(response, "yes") == 0 || strcmp(response, "no") == 0) {
                break;
            } else {
                *response = 0;
                continue;
            }
        }
        if (strcmp(response, "y") == 0 || strcmp(response, "yes") == 0) {
            *response = 0;
            return 1;
        } else {
            *response = 0;
            return 0;
        }
    }

variable_types:
response
char *

variable_types:
responseSize
unsigned long


setprogname

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

v1 = __xpg_basename(a1);
return strncpy(progname, v1, 0xFEuLL);
}

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

v1 = __xpg_basename(a1);
return strncpy(progname, v1, 0xFEuLL);
}

original_code:
void setprogname(char* str) {
    strncpy(progname, __xpg_basename(str), 254);
}

canonical_original_code:
void setprogname(char *str) {
    strncpy(progname, __xpg_basename(str), 254);
}

variable_types:
str
char *


errmsg

decompiled_code:
void __fastcall errmsg(char *src)
{
size_t v1; // rax
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

strcpy(v2, progname);
strcpy(&v2[strlen(v2)], ": ");
v1 = strlen(v2);
strncat(v2, src, 1024 - v1);
perror(v2);
}

canonical_decompiled_code:
void __fastcall func9(char *src)
{
size_t v1; // rax
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

strcpy(v2, progname);
strcpy(&v2[strlen(v2)], ": ");
v1 = strlen(v2);
strncat(v2, src, 1024 - v1);
perror(v2);
}

original_code:
void errmsg(const char* str) {
    char buffer[1024];
    strcpy(buffer,progname);
    strcat(buffer, ": ");
    strncat(buffer, str, 1024-strlen(buffer));
    perror(buffer);
}

canonical_original_code:
void errmsg(char *str) {
    char buffer[1024];
    strcpy(buffer,progname);
    strcat(buffer, ": ");
    strncat(buffer, str, 1024-strlen(buffer));
    perror(buffer);
}

variable_types:
buffer
char [1024]


getDistance

variable_types: struct GpsPoint { double latitude; double longitude; }

variable_types: dLat double

variable_types: dLon double

variable_types: a double

variable_types: c double


getBearing

variable_types: x double

variable_types: y double

variable_types: bearing double

user_defined_types: struct GpsPoint { double latitude; double longitude; }


getHeading

decompiled_code:
double __fastcall getHeading(double a1, double a2, double a3, double a4)
{
return getBearing(a3, a4, a1, a2);
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2, double a3, double a4)
{
return func1(a3, a4, a1, a2);
}

original_code:
double getHeading( GpsPoint curr, GpsPoint prev )
{
 return getBearing( prev, curr );
}

canonical_original_code:
double getHeading(struct GpsPoint curr, struct GpsPoint prev)
{
 return getBearing( prev, curr );
}

variable_types:
prev
struct GpsPoint


destroyWaypointList

decompiled_code:
void __fastcall destroyWaypointList(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
}

original_code:
void destroyWaypointList( WaypointListNode *head )
{
 while( head != ((void *)0) )
 {
  WaypointListNode *temp = head;
  head = head->next;
  free( temp );
 }
}

canonical_original_code:
void destroyWaypointList(struct WaypointListNode *head)
{
 while( head != ((void *)0) )
 {
  struct WaypointListNode *temp = head;
  head = head->next;
  free( temp );
 }
}

variable_types: struct WaypointListNode { struct GpsPoint { double latitude; double longitude; } waypoint; struct WaypointListNode *next; } *

user_defined_types: struct WaypointListNode { struct GpsPoint waypoint; struct WaypointListNode *next; }


createTcpClientConnection

decompiled_code:
__int64 __fastcall createTcpClientConnection(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
fwrite("getaddrinfo() failure.\n", 1uLL, 0x17uLL, stderr);
v4 = -1;
}
else
{
v2 = pai;
if ( pai )
{
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 && connect(v3, v2->ai_addr, v2->ai_addrlen) != -1 )
break;
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_9;
}
freeaddrinfo(pai);
}
else
{
LABEL_9:
fwrite("connect() failure.\n", 1uLL, 0x13uLL, stderr);
v4 = -1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
fwrite("getaddrinfo() failure.\n", 1uLL, 0x17uLL, stderr);
v4 = -1;
}
else
{
v2 = pai;
if ( pai )
{
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 && connect(v3, v2->ai_addr, v2->ai_addrlen) != -1 )
break;
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_9;
}
freeaddrinfo(pai);
}
else
{
LABEL_9:
fwrite("connect() failure.\n", 1uLL, 0x13uLL, stderr);
v4 = -1;
}
}
return v4;
}

original_code:
int createTcpClientConnection( const char *hostname, const char *port )
{
 int sockfd;
 struct addrinfo hints;
 struct addrinfo *servinfo;
 memset( &hints, 0, sizeof( hints ) );
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 if( getaddrinfo( hostname, port, &hints, &servinfo ) != 0 )
 {
  fprintf( stderr, "getaddrinfo() failure.\n" );
  return -1;
 }
 struct addrinfo *p = ((void *)0);
 for( p = servinfo; p != ((void *)0); p = p->ai_next )
 {
  sockfd = socket( p->ai_family, p->ai_socktype, p->ai_protocol );
  if( sockfd == -1 )
  {
   continue;
  }
  if( connect( sockfd, p->ai_addr, p->ai_addrlen ) == -1 )
  {
   continue;
  }
  break;
 }
 if( p == ((void *)0) )
 {
  fprintf( stderr, "connect() failure.\n" );
  return -1;
 }
 freeaddrinfo( servinfo );
 return sockfd;
}

canonical_original_code:
int createTcpClientConnection(char *hostname, char *port)
{
 int sockfd;
 struct addrinfo hints;
 struct addrinfo *servinfo;
 memset( &hints, 0, sizeof( hints ) );
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 if( getaddrinfo( hostname, port, &hints, &servinfo ) != 0 )
 {
  fprintf( stderr, "getaddrinfo() failure.\n" );
  return -1;
 }
 struct addrinfo *p = ((void *)0);
 for( p = servinfo; p != ((void *)0); p = p->ai_next )
 {
  sockfd = socket( p->ai_family, p->ai_socktype, p->ai_protocol );
  if( sockfd == -1 )
  {
   continue;
  }
  if( connect( sockfd, p->ai_addr, p->ai_addrlen ) == -1 )
  {
   continue;
  }
  break;
 }
 if( p == ((void *)0) )
 {
  fprintf( stderr, "connect() failure.\n" );
  return -1;
 }
 freeaddrinfo( servinfo );
 return sockfd;
}

variable_types:
hostname
char *

variable_types:
port
char *

variable_types: sockfd int

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

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


createUdpClientConnection

decompiled_code:
__int64 __fastcall createUdpClientConnection(char *cp, char *nptr, __int64 a3)
{
unsigned int v4; // ebp
__int16 v5; // ax
int *v7; // rax
int *v8; // rax

v4 = socket(2, 2, 17);
if ( v4 == -1 )
{
v7 = _errno_location();
fprintf(stderr, "socket() failure, errno = %d.\n", (unsigned int)*v7);
}
else
{
*(_QWORD *)a3 = 0LL;
*(_QWORD *)(a3 + 8) = 0LL;
*(_WORD *)a3 = 2;
v5 = atoi(nptr);
*(_WORD *)(a3 + 2) = _bswap_16(v5);
if ( !inet_aton(cp, (struct in_addr *)(a3 + 4)) )
{
v8 = _errno_location();
fprintf(stderr, "inet_aton() failure, errno = %d.\n", (unsigned int)*v8);
v4 = -1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *cp, char *nptr, __int64 a3)
{
unsigned int v4; // ebp
__int16 v5; // ax
int *v7; // rax
int *v8; // rax

v4 = socket(2, 2, 17);
if ( v4 == -1 )
{
v7 = _errno_location();
fprintf(stderr, "socket() failure, errno = %d.\n", (unsigned int)*v7);
}
else
{
*(_QWORD *)a3 = 0LL;
*(_QWORD *)(a3 + 8) = 0LL;
*(_WORD *)a3 = 2;
v5 = atoi(nptr);
*(_WORD *)(a3 + 2) = func0(v5);
if ( !inet_aton(cp, (struct in_addr *)(a3 + 4)) )
{
v8 = _errno_location();
fprintf(stderr, "inet_aton() failure, errno = %d.\n", (unsigned int)*v8);
v4 = -1;
}
}
return v4;
}

original_code:
int createUdpClientConnection( const char *hostname, const char *port, struct sockaddr_in *theiraddr )
{
 int sockfd = socket( 2, SOCK_DGRAM, IPPROTO_UDP );
 if( sockfd == -1 )
 {
  fprintf( stderr, "socket() failure, errno = %d.\n", (*__errno_location ()) );
  return -1;
 }
 memset( (char *)theiraddr, 0, sizeof( *theiraddr ) );
 theiraddr->sin_family = 2;
 theiraddr->sin_port = htons( atoi( port ) );
 if( inet_aton( hostname, &theiraddr->sin_addr ) == 0 )
 {
  fprintf( stderr, "inet_aton() failure, errno = %d.\n", (*__errno_location ()) );
  return -1;
 }
 return sockfd;
}

canonical_original_code:
int createUdpClientConnection(char *hostname, char *port, struct sockaddr_in *theiraddr)
{
 int sockfd = socket( 2, SOCK_DGRAM, IPPROTO_UDP );
 if( sockfd == -1 )
 {
  fprintf( stderr, "socket() failure, errno = %d.\n", (*__errno_location ()) );
  return -1;
 }
 memset( (char *)theiraddr, 0, sizeof( *theiraddr ) );
 theiraddr->sin_family = 2;
 theiraddr->sin_port = htons( atoi( port ) );
 if( inet_aton( hostname, &theiraddr->sin_addr ) == 0 )
 {
  fprintf( stderr, "inet_aton() failure, errno = %d.\n", (*__errno_location ()) );
  return -1;
 }
 return sockfd;
}

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


sendCommand

decompiled_code:
ssize_t __fastcall sendCommand(void *buf)
{
ssize_t result; // rax

result = sendto(droneCmdSock, buf, 0x50uLL, 0, &droneCmdAddr, 0x10u);
if ( result < 0 )
{
fwrite("Error sending command to drone.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(void *buf)
{
ssize_t result; // rax

result = sendto(droneCmdSock, buf, 0x50uLL, 0, &droneCmdAddr, 0x10u);
if ( result < 0 )
{
fwrite("Error sending command to drone.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

original_code:
void sendCommand( const char *cmd )
{
 if( sendto( droneCmdSock, cmd, 80, 0, (struct sockaddr *)&droneCmdAddr, sizeof( droneCmdAddr ) ) < 0 )
 {
  fprintf( stderr, "Error sending command to drone.\n" );
  exit( 1 );
 }
}

canonical_original_code:
void sendCommand(char *cmd)
{
 if( sendto( droneCmdSock, cmd, 80, 0, (struct sockaddr *)&droneCmdAddr, sizeof( droneCmdAddr ) ) < 0 )
 {
  fprintf( stderr, "Error sending command to drone.\n" );
  exit( 1 );
 }
}

variable_types:
cmd
char *


droneTakeOff

decompiled_code:
ssize_t droneTakeOff()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*REF=%u,290718208\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func1()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*REF=%u,290718208\r", v0);
return func0(v2);
}

original_code:
void droneTakeOff()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*REF=%u,290718208\r", droneSeqNum++ );
 sendCommand( cmd );
}

variable_types:
cmd
char [80]


droneLand

decompiled_code:
ssize_t droneLand()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*REF=%u,290717696\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func2()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*REF=%u,290717696\r", v0);
return func0(v2);
}

original_code:
void droneLand()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*REF=%u,290717696\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneHover

decompiled_code:
ssize_t droneHover()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func3()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,0\r", v0);
return func0(v2);
}

original_code:
void droneHover()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneUp

decompiled_code:
ssize_t droneUp()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,1045220557,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func4()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,1045220557,0\r", v0);
return func0(v2);
}

original_code:
void droneUp()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,1045220557,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneDown

decompiled_code:
ssize_t droneDown()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,-1102263091,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func5()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,-1102263091,0\r", v0);
return func0(v2);
}

original_code:
void droneDown()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,-1102263091,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneForward

decompiled_code:
ssize_t droneForward()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,-1102263091,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func6()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,-1102263091,0,0\r", v0);
return func0(v2);
}

original_code:
void droneForward()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,-1102263091,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneBack

decompiled_code:
ssize_t droneBack()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,1045220557,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func7()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,1045220557,0,0\r", v0);
return func0(v2);
}

original_code:
void droneBack()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,1045220557,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneLeft

decompiled_code:
ssize_t droneLeft()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,-1102263091,0,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func8()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,-1102263091,0,0,0\r", v0);
return func0(v2);
}

original_code:
void droneLeft()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,-1102263091,0,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneRight

decompiled_code:
ssize_t droneRight()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,1045220557,0,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func9()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,1045220557,0,0,0\r", v0);
return func0(v2);
}

original_code:
void droneRight()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,1045220557,0,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneRotateLeft

decompiled_code:
ssize_t droneRotateLeft()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,-1085485875\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func10()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,-1085485875\r", v0);
return func0(v2);
}

original_code:
void droneRotateLeft()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,0,-1085485875\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneRotateRight

decompiled_code:
ssize_t droneRotateRight()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,1061997773\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func11()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,1061997773\r", v0);
return func0(v2);
}

original_code:
void droneRotateRight()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,0,1061997773\r", droneSeqNum++ );
 sendCommand( cmd );
}


navdataInit

decompiled_code:
ssize_t navdataInit()
{
__int64 v0; // rcx
__int64 v1; // rcx
__int64 v2; // rcx
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*CONFIG=%d,\"general:navdata_demo\",\"TRUE\"\r", v0);
sendCommand(v4);
v1 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*CTRL=%d,0\r", v1);
sendCommand(v4);
v2 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*FTRIM=%d,\r", v2);
return sendCommand(v4);
}

canonical_decompiled_code:
ssize_t func12()
{
__int64 v0; // rcx
__int64 v1; // rcx
__int64 v2; // rcx
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*CONFIG=%d,\"general:navdata_demo\",\"TRUE\"\r", v0);
func0(v4);
v1 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*CTRL=%d,0\r", v1);
func0(v4);
v2 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*FTRIM=%d,\r", v2);
return func0(v4);
}

original_code:
void navdataInit()
{
  char cmd[80];
  snprintf( cmd, 80, "AT*CONFIG=%d,\"general:navdata_demo\",\"TRUE\"\r", droneSeqNum++ );
  sendCommand( cmd );
  snprintf( cmd, 80, "AT*CTRL=%d,0\r", droneSeqNum++ );
  sendCommand( cmd );
  snprintf( cmd, 80, "AT*FTRIM=%d,\r", droneSeqNum++ );
  sendCommand( cmd );
}


navdataKeepAlive

decompiled_code:
ssize_t navdataKeepAlive()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*COMWDG=%d\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func13()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*COMWDG=%d\r", v0);
return func0(v2);
}

original_code:
void navdataKeepAlive()
{
  char cmd[80];
  snprintf( cmd, 80, "AT*COMWDG=%d\r", droneSeqNum++ );
  sendCommand( cmd );
}


createNavdataSocket

decompiled_code:
int createNavdataSocket()
{
struct hostent *v0; // rbx
int v1; // eax
int result; // eax

v0 = gethostbyname("192.168.1.1");
droneAddr_navdata.sa_family = v0->h_addrtype;
*(_WORD *)droneAddr_navdata.sa_data = _bswap_16(5554);
memcpy((void *)(unsigned int)((_DWORD)&droneAddr_navdata + 4), *(const void **)v0->h_addr_list, v0->h_length);
clientAddr_navdata.sa_family = 2;
*(_DWORD *)&clientAddr_navdata.sa_data[2] = _bswap_32(0);
*(_WORD *)clientAddr_navdata.sa_data = _bswap_16(0);
v1 = socket(2, 2, 0);
navDataSock = v1;
if ( v1 < 0 )
{
printf("%s: cannot open socket \n", *(const char **)v0->h_addr_list);
exit(1);
}
result = bind(v1, &clientAddr_navdata, 0x10u);
if ( result < 0 )
{
printf("%d: cannot bind port\n", 5554LL);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
struct hostent *v0; // rbx
int v1; // eax
int result; // eax

v0 = gethostbyname("192.168.1.1");
droneAddr_navdata.sa_family = v0->h_addrtype;
*(_WORD *)droneAddr_navdata.sa_data = func1(5554);
memcpy((void *)(unsigned int)((_DWORD)&droneAddr_navdata + 4), *(const void **)v0->h_addr_list, v0->h_length);
clientAddr_navdata.sa_family = 2;
*(_DWORD *)&clientAddr_navdata.sa_data[2] = func0(0);
*(_WORD *)clientAddr_navdata.sa_data = func1(0);
v1 = socket(2, 2, 0);
navDataSock = v1;
if ( v1 < 0 )
{
printf("%s: cannot open socket \n", *(const char **)v0->h_addr_list);
exit(1);
}
result = bind(v1, &clientAddr_navdata, 0x10u);
if ( result < 0 )
{
printf("%d: cannot bind port\n", 5554LL);
exit(1);
}
return result;
}

original_code:
void createNavdataSocket() {
  struct hostent *h;
  h = gethostbyname("192.168.1.1");
  droneAddr_navdata.sin_family = h->h_addrtype;
  droneAddr_navdata.sin_port = htons(5554);
  memcpy((char *) &(droneAddr_navdata.sin_addr.s_addr), h->h_addr_list[0], h->h_length);
  clientAddr_navdata.sin_family = 2;
  clientAddr_navdata.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  clientAddr_navdata.sin_port = htons(0);
  navDataSock = socket(2,SOCK_DGRAM,0);
  if(navDataSock<0) {
    printf("%s: cannot open socket \n", h->h_addr_list[0]);
    exit(1);
  }
  if(bind(navDataSock, (struct sockaddr *) &clientAddr_navdata, sizeof(clientAddr_navdata))<0) {
    printf("%d: cannot bind port\n", 5554);
    exit(1);
  }
}

canonical_original_code:
void createNavdataSocket() {
  struct hostent *h;
  h = gethostbyname("192.168.1.1");
  droneAddr_navdata.sin_family = h->h_addrtype;
  droneAddr_navdata.sin_port = htons(5554);
  memcpy((char *) &(droneAddr_navdata.sin_addr.s_addr), h->h_addr_list[0], h->h_length);
  clientAddr_navdata.sin_family = 2;
  clientAddr_navdata.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  clientAddr_navdata.sin_port = htons(0);
  navDataSock = socket(2,SOCK_DGRAM,0);
  if(navDataSock<0) {
    printf("%s: cannot open socket \n", h->h_addr_list[0]);
    exit(1);
  }
  if(bind(navDataSock, (struct sockaddr *) &clientAddr_navdata, sizeof(clientAddr_navdata))<0) {
    printf("%d: cannot bind port\n", 5554);
    exit(1);
  }
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


sendNavData

decompiled_code:
ssize_t __fastcall sendNavData(void *buf)
{
size_t v1; // rax
ssize_t result; // rax

v1 = strlen((const char *)buf);
result = sendto(navDataSock, buf, v1 + 1, 0, &droneAddr_navdata, 0x10u);
if ( result < 0 )
{
fwrite("Error sending navdata to drone.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(void *buf)
{
size_t v1; // rax
ssize_t result; // rax

v1 = strlen((const char *)buf);
result = sendto(navDataSock, buf, v1 + 1, 0, &droneAddr_navdata, 0x10u);
if ( result < 0 )
{
fwrite("Error sending navdata to drone.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

original_code:
void sendNavData( char *cmd )
{
 if( sendto( navDataSock, cmd, strlen(cmd)+1, 0, (struct sockaddr *) &droneAddr_navdata, sizeof( droneAddr_navdata ) ) < 0 )
 {
  fprintf( stderr, "Error sending navdata to drone.\n" );
  exit( 1 );
 }
}

canonical_original_code:
void sendNavData(char *cmd)
{
 if( sendto( navDataSock, cmd, strlen(cmd)+1, 0, (struct sockaddr *) &droneAddr_navdata, sizeof( droneAddr_navdata ) ) < 0 )
 {
  fprintf( stderr, "Error sending navdata to drone.\n" );
  exit( 1 );
 }
}


tickleNavData

decompiled_code:
ssize_t tickleNavData()
{
return sendNavData(&unk_1E1);
}

canonical_decompiled_code:
ssize_t func4()
{
return func3(&unk_1E1);
}

original_code:
void tickleNavData()
{
  sendNavData ("\x01\x00");
}


usage

repo: EPCCed/epcc-openacc-benchmarks

decompiled_code:
int __fastcall usage(const char **a1)
{
return printf(
"Usage: %s \n\t--reps <repetitions> (default %d)\n\t--datasize <datasize> (default %d bytes)\n",
*a1,
10LL,
0x100000LL);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1)
{
return printf(
"Usage: %s \n\t--reps <repetitions> (default %d)\n\t--datasize <datasize> (default %d bytes)\n",
*a1,
10LL,
0x100000LL);
}

original_code:
void usage(char *argv[]) {
  printf("Usage: %s \n"
         "\t--reps <repetitions> (default %d)\n"
         "\t--datasize <datasize> (default %d bytes)\n",
         argv[0],
         10, 1048576);
}

variable_types:
argv
char *[]


decompiled_code:
void __fastcall parse_args(int a1, const char **a2)
{
__int64 v2; // rbx
const char **v3; // r13
const char **v4; // r13

if ( a1 > 1 )
{
v2 = 1LL;
do
{
if ( !strcmp(a2[v2], "--reps") )
{
v4 = &a2[(int)v2 + 1];
reps = atoi(*v4);
if ( !reps )
{
printf("Invalid integer:--reps: %s\n", *v4);
usage(a2);
exit(1);
}
}
else
{
if ( strcmp(a2[v2], "--datasize") )
{
if ( !strcmp(a2[v2], "-h") )
{
usage(a2);
exit(0);
}
printf("Invalid parameters: %s\n", a2[v2]);
usage(a2);
exit(1);
}
v3 = &a2[(int)v2 + 1];
datasize = atoi(*v3);
if ( !datasize )
{
printf("Invalid integer:--datasize: %s\n", *v3);
usage(a2);
exit(1);
}
}
v2 += 2LL;
}
while ( v2 != 2LL * ((unsigned int)(a1 - 2) >> 1) + 3 );
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, const char **a2)
{
__int64 v2; // rbx
const char **v3; // r13
const char **v4; // r13

if ( a1 > 1 )
{
v2 = 1LL;
do
{
if ( !strcmp(a2[v2], "--reps") )
{
v4 = &a2[(int)v2 + 1];
reps = atoi(*v4);
if ( !reps )
{
printf("Invalid integer:--reps: %s\n", *v4);
func0(a2);
exit(1);
}
}
else
{
if ( strcmp(a2[v2], "--datasize") )
{
if ( !strcmp(a2[v2], "-h") )
{
func0(a2);
exit(0);
}
printf("Invalid parameters: %s\n", a2[v2]);
func0(a2);
exit(1);
}
v3 = &a2[(int)v2 + 1];
datasize = atoi(*v3);
if ( !datasize )
{
printf("Invalid integer:--datasize: %s\n", *v3);
func0(a2);
exit(1);
}
}
v2 += 2LL;
}
while ( v2 != 2LL * ((unsigned int)(a1 - 2) >> 1) + 3 );
}
}

original_code:
void parse_args(int argc, char *argv[]) {
  int arg;
  for (arg = 1; arg < argc; arg++) {
    if (strcmp(argv[arg], "--reps") == 0) {
      reps = atoi(argv[++arg]);
      if (reps == 0) {
        printf("Invalid integer:--reps: %s\n", argv[arg]);
        usage(argv);
        exit(1);
      }
    } else if (strcmp(argv[arg], "--datasize") == 0) {
      datasize = atoi(argv[++arg]);
      if (datasize == 0) {
        printf("Invalid integer:--datasize: %s\n", argv[arg]);
        usage(argv);
        exit(1);
      }
    } else if (strcmp(argv[arg], "-h") == 0) {
      usage(argv);
      exit(0);
    } else {
      printf("Invalid parameters: %s\n", argv[arg]);
      usage(argv);
      exit(1);
    }
  }
}

variable_types: argc int

variable_types: arg int


stats

original_code:
void stats(double *mtp, double *sdp) {
  double meantime, totaltime, sumsq, mintime, maxtime, sd;
  int i, good_reps;
  mintime = 1.0e10;
  maxtime = 0.;
  totaltime = 0.;
  good_reps = 0;
  for (i = 0; i < reps; i++) {
    if (times[i] != 0){
      mintime = (mintime < times[i]) ? mintime : times[i];
      maxtime = (maxtime > times[i]) ? maxtime : times[i];
      totaltime += times[i];
      good_reps++;
    }
  }
  meantime = totaltime / good_reps;
  sumsq = 0;
  for (i = 0; i < reps; i++) {
    if (times[i] != 0){
      sumsq += (times[i] - meantime) * (times[i] - meantime);
    }
  }
  sd = sqrt(sumsq / good_reps);
  *mtp = meantime;
  *sdp = sd;
}

canonical_original_code:
void stats(double *mtp, double *sdp) {
  double meantime; double totaltime; double sumsq; double mintime; double maxtime; double sd;
  int i; int good_reps;
  mintime = 1.0e10;
  maxtime = 0.;
  totaltime = 0.;
  good_reps = 0;
  for (i = 0; i < reps; i++) {
    if (times[i] != 0){
      mintime = (mintime < times[i]) ? mintime : times[i];
      maxtime = (maxtime > times[i]) ? maxtime : times[i];
      totaltime += times[i];
      good_reps++;
    }
  }
  meantime = totaltime / good_reps;
  sumsq = 0;
  for (i = 0; i < reps; i++) {
    if (times[i] != 0){
      sumsq += (times[i] - meantime) * (times[i] - meantime);
    }
  }
  sd = sqrt(sumsq / good_reps);
  *mtp = meantime;
  *sdp = sd;
}

variable_types:
mtp
double *

variable_types:
sdp
double *

variable_types: meantime double

variable_types: totaltime double

variable_types: sumsq double

variable_types: mintime double

variable_types: maxtime double

variable_types: sd double

variable_types: i int


decompiled_code:
int __fastcall print_results(const char *a1, double a2, double a3)
{
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v4, "COMPILER");
return printf("%s %s %d %f %f\n", v4, a1, (unsigned int)datasize, a2 * 1000000.0, a3 * 1.96 * 1000000.0);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, double a2, double a3)
{
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v4, "COMPILER");
return printf("%s %s %d %f %f\n", v4, a1, (unsigned int)datasize, a2 * 1000000.0, a3 * 1.96 * 1000000.0);
}

original_code:
void print_results(char *name, double testtime, double testsd) {
  char compiler[20];
  sprintf(compiler, "COMPILER");
  printf("%s %s %d %f %f\n", compiler, name, datasize, testtime*1e6, 1.96*testsd*1e6);
}

variable_types:
name
char *

variable_types: testtime double

variable_types: testsd double

variable_types:
compiler
char [20]


init

decompiled_code:
void *__fastcall init(int a1, const char **a2)
{
void *result; // rax

parse_args(a1, a2);
if ( reps == -1 )
reps = 10;
if ( datasize == -1 )
datasize = 0x100000;
result = malloc(8LL * reps);
times = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func4(int a1, const char **a2)
{
void *result; // rax

func1(a1, a2);
if ( reps == -1 )
reps = 10;
if ( datasize == -1 )
datasize = 0x100000;
result = malloc(8LL * reps);
times = result;
return result;
}

original_code:
void init(int argc, char **argv)
{
  parse_args(argc, argv);
  if (reps == -1) {
    reps = 10;
  }
  if (datasize == (unsigned int)-1) {
    datasize = 1048576;
  }
  times = (double *)malloc((reps) * sizeof(double));
}

variable_types:
argv
char **


finalise

decompiled_code:
void finalise()
{
free(times);
}

canonical_decompiled_code:
void func5()
{
free(times);
}

original_code:
void finalise(void) {
  free(times);
}

canonical_original_code:
void finalise() {
  free(times);
}


benchmark

decompiled_code:
int __fastcall benchmark(const char *a1, double (*a2)(void))
{
__int64 v2; // rbp
int v3; // ebx
double v4; // xmm0_8

if ( reps > 0 )
{
v2 = 0LL;
v3 = 0;
do
{
v4 = a2();
if ( v4 == -10000.0 )
{
printf("Memory allocation failure in %s\n", a1);
*(_QWORD *)((char *)times + v2) = 0LL;
}
else if ( v4 == -11000.0 )
{
printf("CPU/GPU mismatch in %s\n", a1);
*(_QWORD *)((char *)times + v2) = 0LL;
}
else
{
*(double *)((char *)times + v2) = v4;
}
++v3;
v2 += 8LL;
}
while ( reps > v3 );
}
stats((double *)&testtime, (double *)&testsd);
return print_results(a1, *(double *)&testtime, *(double *)&testsd);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, double (*a2)(void))
{
__int64 v2; // rbp
int v3; // ebx
double v4; // xmm0_8

if ( reps > 0 )
{
v2 = 0LL;
v3 = 0;
do
{
v4 = a2();
if ( v4 == -10000.0 )
{
printf("Memory allocation failure in %s\n", a1);
*(_QWORD *)((char *)times + v2) = 0LL;
}
else if ( v4 == -11000.0 )
{
printf("CPU/GPU mismatch in %s\n", a1);
*(_QWORD *)((char *)times + v2) = 0LL;
}
else
{
*(double *)((char *)times + v2) = v4;
}
++v3;
v2 += 8LL;
}
while ( reps > v3 );
}
func2((double *)&testtime, (double *)&testsd);
return func3(a1, *(double *)&testtime, *(double *)&testsd);
}

original_code:
void benchmark(char *name, double (*test)(void))
{
  int i = 0;
  double tmp = 0;
  for (i=0; i<reps; i++) {
    tmp = test();
    if (tmp == -10000){
      printf("Memory allocation failure in %s\n", name);
      times[i] = 0;
    }
    else if (tmp == -11000){
      printf("CPU/GPU mismatch in %s\n", name);
      times[i] = 0;
    }
    else{
      times[i] = tmp;
    }
  }
  stats(&testtime, &testsd);
  print_results(name, testtime, testsd);
}

canonical_original_code:
void benchmark(char *name, double (*test)())
{
  int i = 0;
  double tmp = 0;
  for (i=0; i<reps; i++) {
    tmp = test();
    if (tmp == -10000){
      printf("Memory allocation failure in %s\n", name);
      times[i] = 0;
    }
    else if (tmp == -11000){
      printf("CPU/GPU mismatch in %s\n", name);
      times[i] = 0;
    }
    else{
      times[i] = tmp;
    }
  }
  stats(&testtime, &testsd);
  print_results(name, testtime, testsd);
}

variable_types:
test
double (*)()

variable_types: tmp double


wul

decompiled_code:
void wul()
{
double *v0; // rbp
char *v1; // rax
char *v2; // r12
double *v3; // rbx
__int64 i; // rax

v0 = (double *)malloc(0x10000uLL);
v1 = (char *)malloc(0x10000uLL);
v2 = v1;
if ( !v0 || !v1 )
puts("Unable to allocate memory in wul.");
v3 = v0;
do
*v3++ = (double)rand() * 4.656612873077393e-10;
while ( v3 != v0 + 0x2000 );
for ( i = 0LL; i != 0x2000; ++i )
*(double *)&v2[i * 8] = v0[i] + v0[i];
if ( *v0 < 0.0 )
puts("Error in WUL");
free(v0);
free(v2);
}

canonical_decompiled_code:
void func0()
{
double *v0; // rbp
char *v1; // rax
char *v2; // r12
double *v3; // rbx
__int64 i; // rax

v0 = (double *)malloc(0x10000uLL);
v1 = (char *)malloc(0x10000uLL);
v2 = v1;
if ( !v0 || !v1 )
puts("Unable to allocate memory in wul.");
v3 = v0;
do
*v3++ = (double)rand() * 4.656612873077393e-10;
while ( v3 != v0 + 0x2000 );
for ( i = 0LL; i != 0x2000; ++i )
*(double *)&v2[i * 8] = v0[i] + v0[i];
if ( *v0 < 0.0 )
puts("Error in WUL");
free(v0);
free(v2);
}

original_code:
void wul(){
  int data = 8192;
  double *arr_a = (double *)malloc(sizeof(double) * data);
  double *arr_b = (double *)malloc(sizeof(double) * data);
  int i = 0;
  if (arr_a==((void *)0)||arr_b==((void *)0)) {
      printf("Unable to allocate memory in wul.\n");
  }
  for (i=0;i<data;i++){
    arr_a[i] = (double) (rand()/(1.0+2147483647));
  }
#pragma acc data copy(arr_b[0:data]), copyin(arr_a[0:data])
  {
#pragma acc parallel loop
    for (i=0;i<data;i++){
      arr_b[i] = arr_a[i] * 2;
    }
  }
  if (arr_a[0] < 0){
    printf("Error in WUL\n");
  }
  free(arr_a);
  free(arr_b);
}

variable_types: data int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

init(argc, argv, envp);
wul();
strcpy(v4, "ContigH2D");
benchmark(v4, &contig_htod);
strcpy(v4, "ContigD2H");
benchmark(v4, &contig_dtoh);
strcpy(v4, "SlicedD2H");
benchmark(v4, &sliced_dtoh);
strcpy(v4, "SlicedH2D");
benchmark(v4, &sliced_htod);
strcpy(v4, "Kernels_If");
benchmark(v4, &kernels_if);
strcpy(v4, "Parallel_If");
benchmark(v4, &parallel_if);
strcpy(v4, "Parallel_private");
benchmark(v4, &parallel_private);
strcpy(v4, "Parallel_1stprivate");
benchmark(v4, &parallel_firstprivate);
strcpy(v4, "Kernels_combined");
benchmark(v4, &kernels_combined);
strcpy(v4, "Parallel_combined");
benchmark(v4, &parallel_combined);
strcpy(v4, "Update_Host");
benchmark(v4, &update);
strcpy(v4, "Kernels_Invocation");
benchmark(v4, &kernels_invoc);
strcpy(v4, "Parallel_Invocation");
benchmark(v4, &parallel_invoc);
strcpy(v4, "Parallel_Reduction");
benchmark(v4, &parallel_reduction);
strcpy(v4, "Kernels_Reduction");
benchmark(v4, &kernels_reduction);
strcpy(v4, "2MM");
benchmark(v4, &twomm);
strcpy(v4, "3MM");
benchmark(v4, &threemm);
strcpy(v4, "ATAX");
benchmark(v4, &atax);
strcpy(v4, "BICG");
benchmark(v4, &bicg);
strcpy(v4, "MVT");
benchmark(v4, &mvt);
strcpy(v4, "SYRK");
benchmark(v4, &syrk);
strcpy(v4, "COV");
benchmark(v4, &covariance);
strcpy(v4, "COR");
benchmark(v4, &correlation);
strcpy(v4, "SYR2K");
benchmark(v4, &syr2k);
strcpy(v4, "GESUMMV");
benchmark(v4, &gesummv);
strcpy(v4, "GEMM");
benchmark(v4, &gemm);
strcpy(v4, "2DCONV");
benchmark(v4, &twodconv);
strcpy(v4, "3DCONV");
benchmark(v4, &threedconv);
strcpy(v4, "27S");
benchmark(v4, &stencil);
strcpy(v4, "LE2D");
benchmark(v4, &le_main);
strcpy(v4, "HIMENO");
benchmark(v4, &himeno_main);
finalise();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

init(argc, argv, envp);
func0();
strcpy(v4, "ContigH2D");
benchmark(v4, &contig_htod);
strcpy(v4, "ContigD2H");
benchmark(v4, &contig_dtoh);
strcpy(v4, "SlicedD2H");
benchmark(v4, &sliced_dtoh);
strcpy(v4, "SlicedH2D");
benchmark(v4, &sliced_htod);
strcpy(v4, "Kernels_If");
benchmark(v4, &kernels_if);
strcpy(v4, "Parallel_If");
benchmark(v4, &parallel_if);
strcpy(v4, "Parallel_private");
benchmark(v4, &parallel_private);
strcpy(v4, "Parallel_1stprivate");
benchmark(v4, &parallel_firstprivate);
strcpy(v4, "Kernels_combined");
benchmark(v4, &kernels_combined);
strcpy(v4, "Parallel_combined");
benchmark(v4, &parallel_combined);
strcpy(v4, "Update_Host");
benchmark(v4, &update);
strcpy(v4, "Kernels_Invocation");
benchmark(v4, &kernels_invoc);
strcpy(v4, "Parallel_Invocation");
benchmark(v4, &parallel_invoc);
strcpy(v4, "Parallel_Reduction");
benchmark(v4, &parallel_reduction);
strcpy(v4, "Kernels_Reduction");
benchmark(v4, &kernels_reduction);
strcpy(v4, "2MM");
benchmark(v4, &twomm);
strcpy(v4, "3MM");
benchmark(v4, &threemm);
strcpy(v4, "ATAX");
benchmark(v4, &atax);
strcpy(v4, "BICG");
benchmark(v4, &bicg);
strcpy(v4, "MVT");
benchmark(v4, &mvt);
strcpy(v4, "SYRK");
benchmark(v4, &syrk);
strcpy(v4, "COV");
benchmark(v4, &covariance);
strcpy(v4, "COR");
benchmark(v4, &correlation);
strcpy(v4, "SYR2K");
benchmark(v4, &syr2k);
strcpy(v4, "GESUMMV");
benchmark(v4, &gesummv);
strcpy(v4, "GEMM");
benchmark(v4, &gemm);
strcpy(v4, "2DCONV");
benchmark(v4, &twodconv);
strcpy(v4, "3DCONV");
benchmark(v4, &threedconv);
strcpy(v4, "27S");
benchmark(v4, &stencil);
strcpy(v4, "LE2D");
benchmark(v4, &le_main);
strcpy(v4, "HIMENO");
benchmark(v4, &himeno_main);
finalise();
return 0;
}

original_code:
int main(int argc, char **argv) {
  char testName[32];
  init(argc, argv);
  wul();
  sprintf(testName, "ContigH2D");
  benchmark(testName, &contig_htod);
  sprintf(testName, "ContigD2H");
  benchmark(testName, &contig_dtoh);
  sprintf(testName, "SlicedD2H");
  benchmark(testName, &sliced_dtoh);
  sprintf(testName, "SlicedH2D");
  benchmark(testName, &sliced_htod);
  sprintf(testName, "Kernels_If");
  benchmark(testName, &kernels_if);
  sprintf(testName, "Parallel_If");
  benchmark(testName, &parallel_if);
  sprintf(testName, "Parallel_private");
  benchmark(testName, &parallel_private);
  sprintf(testName, "Parallel_1stprivate");
  benchmark(testName, &parallel_firstprivate);
  sprintf(testName, "Kernels_combined");
  benchmark(testName, &kernels_combined);
  sprintf(testName, "Parallel_combined");
  benchmark(testName, &parallel_combined);
  sprintf(testName, "Update_Host");
  benchmark(testName, &update);
  sprintf(testName, "Kernels_Invocation");
  benchmark(testName, &kernels_invoc);
  sprintf(testName, "Parallel_Invocation");
  benchmark(testName, &parallel_invoc);
  sprintf(testName, "Parallel_Reduction");
  benchmark(testName, &parallel_reduction);
  sprintf(testName, "Kernels_Reduction");
  benchmark(testName, &kernels_reduction);
  sprintf(testName, "2MM");
  benchmark(testName, &twomm);
  sprintf(testName, "3MM");
  benchmark(testName, &threemm);
  sprintf(testName, "ATAX");
  benchmark(testName, &atax);
  sprintf(testName, "BICG");
  benchmark(testName, &bicg);
  sprintf(testName, "MVT");
  benchmark(testName, &mvt);
  sprintf(testName, "SYRK");
  benchmark(testName, &syrk);
  sprintf(testName, "COV");
  benchmark(testName, &covariance);
  sprintf(testName, "COR");
  benchmark(testName, &correlation);
  sprintf(testName, "SYR2K");
  benchmark(testName, &syr2k);
  sprintf(testName, "GESUMMV");
  benchmark(testName, &gesummv);
  sprintf(testName, "GEMM");
  benchmark(testName, &gemm);
  sprintf(testName, "2DCONV");
  benchmark(testName, &twodconv);
  sprintf(testName, "3DCONV");
  benchmark(testName, &threedconv);
  sprintf(testName, "27S");
  benchmark(testName, &stencil);
  sprintf(testName, "LE2D");
  benchmark(testName, &le_main);
  sprintf(testName, "HIMENO");
  benchmark(testName, &himeno_main);
  finalise();
  return 0;
}

variable_types: argc int

variable_types:
testName
char [32]


repo: Earlz/microforth

decompiled_code:
int test_push_pop_works()
{
int result; // eax
_BYTE v1[56]; // [rsp+0h] [rbp-38h] BYREF

mf_init(v1, 100LL);
mf_push(v1, 4660LL);
++minunit_assert;
if ( mf_pop(v1) == 4660 )
{
putchar(46);
mf_push(v1, 17767LL);
mf_push(v1, 43981LL);
mf_push(v1, 65315LL);
++minunit_assert;
if ( mf_pop(v1) == 65315 )
{
putchar(46);
++minunit_assert;
if ( mf_pop(v1) == 43981 )
{
putchar(46);
++minunit_assert;
if ( mf_pop(v1) == 17767 )
{
putchar(46);
result = mf_destroy(v1);
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
53LL,
"mf_pop(&mf)==0x4567");
minunit_status = 1;
}
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
52LL,
"mf_pop(&mf)==0xabcd");
minunit_status = 1;
}
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
51LL,
"mf_pop(&mf)==0xff23");
minunit_status = 1;
}
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
46LL,
"mf_pop(&mf) == 0x1234");
minunit_status = 1;
}
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax
_BYTE v1[56]; // [rsp+0h] [rbp-38h] BYREF

func13(v1, 100LL);
func11(v1, 4660LL);
++minunit_assert;
if ( func12(v1) == 4660 )
{
putchar(46);
func11(v1, 17767LL);
func11(v1, 43981LL);
func11(v1, 65315LL);
++minunit_assert;
if ( func12(v1) == 65315 )
{
putchar(46);
++minunit_assert;
if ( func12(v1) == 43981 )
{
putchar(46);
++minunit_assert;
if ( func12(v1) == 17767 )
{
putchar(46);
result = func14(v1);
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
53LL,
"mf_pop(&mf)==0x4567");
minunit_status = 1;
}
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
52LL,
"mf_pop(&mf)==0xabcd");
minunit_status = 1;
}
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
51LL,
"mf_pop(&mf)==0xff23");
minunit_status = 1;
}
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
46LL,
"mf_pop(&mf) == 0x1234");
minunit_status = 1;
}
return result;
}

original_code:
static void test_push_pop_works()
{
  mf_state_t mf;
  mf_init(&mf, 100);
  mf_push(&mf, 0x1234);
  do { minunit_assert++; if (!(mf_pop(&mf) == 0x1234)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 46, "mf_pop(&mf) == 0x1234"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_push(&mf, 0x4567);
  mf_push(&mf, 0xabcd);
  mf_push(&mf, 0xff23);
  do { minunit_assert++; if (!(mf_pop(&mf)==0xff23)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 51, "mf_pop(&mf)==0xff23"); minunit_status = 1; return; } else { printf("."); }} while(0);
  do { minunit_assert++; if (!(mf_pop(&mf)==0xabcd)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 52, "mf_pop(&mf)==0xabcd"); minunit_status = 1; return; } else { printf("."); }} while(0);
  do { minunit_assert++; if (!(mf_pop(&mf)==0x4567)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 53, "mf_pop(&mf)==0x4567"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_destroy(&mf);
}

canonical_original_code:
static void test_push_pop_works()
{
  struct mf_state mf;
  mf_init(&mf, 100);
  mf_push(&mf, 0x1234);
  do { minunit_assert++; if (!(mf_pop(&mf) == 0x1234)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 46, "mf_pop(&mf) == 0x1234"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_push(&mf, 0x4567);
  mf_push(&mf, 0xabcd);
  mf_push(&mf, 0xff23);
  do { minunit_assert++; if (!(mf_pop(&mf)==0xff23)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 51, "mf_pop(&mf)==0xff23"); minunit_status = 1; return; } else { printf("."); }} while(0);
  do { minunit_assert++; if (!(mf_pop(&mf)==0xabcd)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 52, "mf_pop(&mf)==0xabcd"); minunit_status = 1; return; } else { printf("."); }} while(0);
  do { minunit_assert++; if (!(mf_pop(&mf)==0x4567)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 53, "mf_pop(&mf)==0x4567"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_destroy(&mf);
}

variable_types: struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry { struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state *state, char *context); } word; struct mf_word_entry *next; } *words; }

user_defined_types: struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry *words; }

user_defined_types: struct mf_word_entry { struct mf_word_t word; struct mf_word_entry *next; }