decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbp
char *v5; // rax
char *v6; // r12
const char *v7; // rsi
const char *v8; // rax
unsigned int v9; // er12
__int64 v10; // rcx
size_t v11; // rax
char v12[1024]; // [rsp+0h] [rbp-2818h] BYREF
char dest[1024]; // [rsp+400h] [rbp-2418h] BYREF
char s[8216]; // [rsp+800h] [rbp-2018h] BYREF

v3 = getenv("QUERY_STRING");
if ( v3 )
{
v4 = v3;
v5 = strchr(v3, 38);
*v5 = 0;
v6 = v5;
v7 = (const char *)get_arg_value(v4);
strcpy(v12, v7);
v8 = (const char *)get_arg_value(v6 + 1);
strcpy(dest, v8);
v9 = atoi(v12);
v10 = (unsigned int)atoi(dest);
}
else
{
v10 = 0LL;
v9 = 0;
}
sprintf(s, "<p>The answer is : %d + %d = %d\r\n", v9, v10, v9 + (unsigned int)v10);
puts("Content-type: text/html\r");
v11 = strlen(s);
printf("Content-length: %d\r\n\r\n", v11);
printf("%s", s);
fflush(_bss_start);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbp
char *v5; // rax
char *v6; // r12
const char *v7; // rsi
const char *v8; // rax
unsigned int v9; // er12
__int64 v10; // rcx
size_t v11; // rax
char v12[1024]; // [rsp+0h] [rbp-2818h] BYREF
char dest[1024]; // [rsp+400h] [rbp-2418h] BYREF
char s[8216]; // [rsp+800h] [rbp-2018h] BYREF

v3 = getenv("QUERY_STRING");
if ( v3 )
{
v4 = v3;
v5 = strchr(v3, 38);
*v5 = 0;
v6 = v5;
v7 = (const char *)func7(v4);
strcpy(v12, v7);
v8 = (const char *)func7(v6 + 1);
strcpy(dest, v8);
v9 = atoi(v12);
v10 = (unsigned int)atoi(dest);
}
else
{
v10 = 0LL;
v9 = 0;
}
sprintf(s, "<p>The answer is : %d + %d = %d\r\n", v9, v10, v9 + (unsigned int)v10);
puts("Content-type: text/html\r");
v11 = strlen(s);
printf("Content-length: %d\r\n\r\n", v11);
printf("%s", s);
fflush(_bss_start);
exit(0);
}

original_code:
int main(void) {
 char *buf, *p;
 char arg1[1024], arg2[1024], content[8192];
 int n1=0, n2=0;
 if ((buf = getenv("QUERY_STRING")) != ((void *)0)) {
  p = strchr(buf, '&');
  *p = '\0';
  strcpy(arg1, get_arg_value(buf));
  strcpy(arg2, get_arg_value(p+1));
  n1 = atoi(arg1);
  n2 = atoi(arg2);
 }
 sprintf(content, "<p>The answer is : %d + %d = %d\r\n", n1, n2, n1 + n2);
 printf("Content-type: text/html\r\n");
 printf("Content-length: %d\r\n\r\n", (int)strlen(content));
 printf("%s", content);
 fflush(stdout);
 exit(0);
}

canonical_original_code:
int main() {
 char *buf; char *p;
 char arg1[1024]; char arg2[1024]; char content[8192];
 int n1 = 0; int n2 = 0;
 if ((buf = getenv("QUERY_STRING")) != ((void *)0)) {
  p = strchr(buf, '&');
  *p = '\0';
  strcpy(arg1, get_arg_value(buf));
  strcpy(arg2, get_arg_value(p+1));
  n1 = atoi(arg1);
  n2 = atoi(arg2);
 }
 sprintf(content, "<p>The answer is : %d + %d = %d\r\n", n1, n2, n1 + n2);
 printf("Content-type: text/html\r\n");
 printf("Content-length: %d\r\n\r\n", (int)strlen(content));
 printf("%s", content);
 fflush(stdout);
 exit(0);
}

variable_types:
buf
char *

variable_types:
p
char *


repo: leonshao/network

original_code:
static ssize_t io_read(io_t *rp, char *usrbuf, size_t n) {
 int cnt;
 while (rp->io_cnt <= 0) {
  rp->io_cnt = read(rp->io_fd, rp->io_buf, sizeof(rp->io_buf));
  if (rp->io_cnt < 0) {
   if ((*__errno_location ()) != 4)
    return -1;
  }
  else if (rp->io_cnt == 0)
   return 0;
  else
   rp->io_bufptr = rp->io_buf;
 }
 cnt = n;
 if (rp->io_cnt < n)
  cnt = rp->io_cnt;
 memcpy(usrbuf, rp->io_bufptr, cnt);
 rp->io_bufptr += cnt;
 rp->io_cnt -= cnt;
 return cnt;
}

canonical_original_code:
static long io_read(struct io_t *rp, char *usrbuf, unsigned long n) {
 int cnt;
 while (rp->io_cnt <= 0) {
  rp->io_cnt = read(rp->io_fd, rp->io_buf, sizeof(rp->io_buf));
  if (rp->io_cnt < 0) {
   if ((*__errno_location ()) != 4)
    return -1;
  }
  else if (rp->io_cnt == 0)
   return 0;
  else
   rp->io_bufptr = rp->io_buf;
 }
 cnt = n;
 if (rp->io_cnt < n)
  cnt = rp->io_cnt;
 memcpy(usrbuf, rp->io_bufptr, cnt);
 rp->io_bufptr += cnt;
 rp->io_cnt -= cnt;
 return cnt;
}

variable_types: struct io_t { int io_fd; int io_cnt; char *io_bufptr; char io_buf[8192]; } *

variable_types:
usrbuf
char *

variable_types:
n
unsigned long

variable_types: cnt int

return_type: long


decompiled_code:
size_t __fastcall io_readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
if ( !nbytes )
return v3;
v5 = nbytes;
do
{
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 < 0 )
break;
if ( !v6 )
return v3;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
{
v3 -= v6;
return v3;
}
}
}
while ( *_errno_location() == 4 );
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func1(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
if ( !nbytes )
return v3;
v5 = nbytes;
do
{
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 < 0 )
break;
if ( !v6 )
return v3;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
{
v3 -= v6;
return v3;
}
}
}
while ( *_errno_location() == 4 );
return -1LL;
}

original_code:
ssize_t io_readn(int fd, void *usrbuf, size_t n) {
 size_t nleft = n;
 ssize_t nread = n;
 char *bufp = usrbuf;
 while (nleft > 0) {
  if ((nread = read(fd, bufp, nleft)) < 0) {
   if ((*__errno_location ()) == 4)
    nread = 0;
   else
    return -1;
  }
  else if (nread == 0)
   break;
  nleft -= nread;
  bufp += nread;
 }
 return (n - nread);
}

canonical_original_code:
long io_readn(int fd, void *usrbuf, unsigned long n) {
 unsigned long nleft = n;
 long nread = n;
 char *bufp = usrbuf;
 while (nleft > 0) {
  if ((nread = read(fd, bufp, nleft)) < 0) {
   if ((*__errno_location ()) == 4)
    nread = 0;
   else
    return -1;
  }
  else if (nread == 0)
   break;
  nleft -= nread;
  bufp += nread;
 }
 return (n - nread);
}

variable_types: fd int

variable_types:
usrbuf
void *

variable_types:
nleft
unsigned long

variable_types: nread long

variable_types:
bufp
char *


decompiled_code:
size_t __fastcall io_writen(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( *_errno_location() == 4 );
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func2(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( *_errno_location() == 4 );
return -1LL;
}

original_code:
ssize_t io_writen(int fd, void *usrbuf, size_t n){
 size_t nleft = n;
 ssize_t nwritten;
 char *bufp = usrbuf;
 while (nleft > 0) {
  if ((nwritten = write(fd, bufp, nleft)) <= 0) {
   if ((*__errno_location ()) == 4)
    nwritten = 0;
   else
    return -1;
  }
  nleft -= nwritten;
  bufp += nwritten;
 }
 return n;
}

canonical_original_code:
long io_writen(int fd, void *usrbuf, unsigned long n){
 unsigned long nleft = n;
 long nwritten;
 char *bufp = usrbuf;
 while (nleft > 0) {
  if ((nwritten = write(fd, bufp, nleft)) <= 0) {
   if ((*__errno_location ()) == 4)
    nwritten = 0;
   else
    return -1;
  }
  nleft -= nwritten;
  bufp += nwritten;
 }
 return n;
}

variable_types: nwritten long


decompiled_code:
__int64 __fastcall io_initbuf(__int64 a1, int a2)
{
__int64 result; // rax

result = a1 + 16;
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 8) = a1 + 16;
return result;
}

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

result = a1 + 16;
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 8) = a1 + 16;
return result;
}

original_code:
void io_initbuf(io_t *iop, int fd) {
 iop->io_fd = fd;
 iop->io_cnt = 0;
 iop->io_bufptr = iop->io_buf;
}

canonical_original_code:
void io_initbuf(struct io_t *iop, int fd) {
 iop->io_fd = fd;
 iop->io_cnt = 0;
 iop->io_bufptr = iop->io_buf;
}

return_type: void

user_defined_types: struct io_t { int io_fd; int io_cnt; char *io_bufptr; char io_buf[8192]; }


decompiled_code:
__int64 __fastcall io_readlineb(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
_BYTE *v3; // rbx
__int64 v4; // r13
int v5; // ebp
char v6; // al
int v7; // eax
__int64 result; // rax
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

v3 = a2;
if ( a3 <= 1 )
{
result = 1LL;
LABEL_9:
*v3 = 0;
}
else
{
v4 = (__int64)&a2[a3 - 1];
v5 = 1;
while ( 1 )
{
v7 = io_read(a1, v9, 1uLL);
if ( v7 != 1 )
break;
v6 = v9[0];
*v3++ = v9[0];
if ( v6 != 10 )
{
++v5;
if ( v3 != (_BYTE *)v4 )
continue;
}
goto LABEL_8;
}
if ( !v7 )
{
result = 0LL;
if ( v5 == 1 )
return result;
LABEL_8:
result = v5;
goto LABEL_9;
}
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
_BYTE *v3; // rbx
__int64 v4; // r13
int v5; // ebp
char v6; // al
int v7; // eax
__int64 result; // rax
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

v3 = a2;
if ( a3 <= 1 )
{
result = 1LL;
LABEL_9:
*v3 = 0;
}
else
{
v4 = (__int64)&a2[a3 - 1];
v5 = 1;
while ( 1 )
{
v7 = func0(a1, v9, 1uLL);
if ( v7 != 1 )
break;
v6 = v9[0];
*v3++ = v9[0];
if ( v6 != 10 )
{
++v5;
if ( v3 != (_BYTE *)v4 )
continue;
}
goto LABEL_8;
}
if ( !v7 )
{
result = 0LL;
if ( v5 == 1 )
return result;
LABEL_8:
result = v5;
goto LABEL_9;
}
result = -1LL;
}
return result;
}

original_code:
ssize_t io_readlineb(io_t *rp, void *usrbuf, size_t maxlen) {
 int n, rc;
 char c, *bufp = usrbuf;
 for (n = 1; n < maxlen; n++) {
  if ((rc = io_read(rp, &c, 1)) == 1) {
   *bufp++ = c;
   if (c == '\n') {
    break;
   }
  }
  else if (rc == 0) {
   if (n == 1)
    return 0;
   else
    break;
  }
  else
   return -1;
 }
 *bufp = 0;
 return n;
}

canonical_original_code:
long io_readlineb(struct io_t *rp, void *usrbuf, unsigned long maxlen) {
 int n; int rc;
 char c; char *bufp = usrbuf;
 for (n = 1; n < maxlen; n++) {
  if ((rc = io_read(rp, &c, 1)) == 1) {
   *bufp++ = c;
   if (c == '\n') {
    break;
   }
  }
  else if (rc == 0) {
   if (n == 1)
    return 0;
   else
    break;
  }
  else
   return -1;
 }
 *bufp = 0;
 return n;
}

variable_types:
maxlen
unsigned long

variable_types: n int

variable_types: rc int

variable_types: c char


decompiled_code:
__int64 __fastcall io_readnb(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r13
unsigned __int64 v5; // rbx
__int64 v6; // rax

v3 = a3;
v5 = a3;
if ( a3 )
{
while ( 1 )
{
while ( 1 )
{
v6 = io_read(a1, a2, v5);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
a2 += v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r13
unsigned __int64 v5; // rbx
__int64 v6; // rax

v3 = a3;
v5 = a3;
if ( a3 )
{
while ( 1 )
{
while ( 1 )
{
v6 = func0(a1, a2, v5);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
a2 += v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

original_code:
ssize_t io_readnb(io_t *rp, void *usrbuf, size_t n){
 size_t nleft = n;
 ssize_t nread;
 char *bufp = usrbuf;
 while (nleft > 0) {
  if ((nread = io_read(rp, bufp, nleft)) < 0) {
   if ((*__errno_location ()) == 4)
    nread = 0;
   else
    return -1;
  }
  else if (nread == 0)
   break;
  nleft -= nread;
  bufp += nread;
 }
 return (n - nleft);
}

canonical_original_code:
long io_readnb(struct io_t *rp, void *usrbuf, unsigned long n){
 unsigned long nleft = n;
 long nread;
 char *bufp = usrbuf;
 while (nleft > 0) {
  if ((nread = io_read(rp, bufp, nleft)) < 0) {
   if ((*__errno_location ()) == 4)
    nread = 0;
   else
    return -1;
  }
  else if (nread == 0)
   break;
  nleft -= nread;
  bufp += nread;
 }
 return (n - nleft);
}


logging

decompiled_code:
int __fastcall logging(__int64 a1)
{
int v1; // er12
size_t v2; // rax

v1 = open("log.txt", 1090, 420LL);
v2 = strlen((const char *)(a1 + 16));
io_writen(v1, (void *)(a1 + 16), v2);
return close(v1);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int v1; // er12
size_t v2; // rax

v1 = open("log.txt", 1090, 420LL);
v2 = strlen((const char *)(a1 + 16));
func2(v1, (void *)(a1 + 16), v2);
return close(v1);
}

original_code:
void logging(io_t *rp) {
 int filefd;
 filefd = open("log.txt", 02|0100|02000, 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3));
 io_writen(filefd, rp->io_buf, strlen(rp->io_buf));
 close(filefd);
}

canonical_original_code:
void logging(struct io_t *rp) {
 int filefd;
 filefd = open("log.txt", 02|0100|02000, 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3));
 io_writen(filefd, rp->io_buf, strlen(rp->io_buf));
 close(filefd);
}

variable_types: filefd int


decompiled_code:
int __fastcall io_print_buf(__int64 a1)
{
puts((const char *)(a1 + 16));
return logging(a1);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
puts((const char *)(a1 + 16));
return func6(a1);
}

original_code:
void io_print_buf(io_t *rp) {
 printf("%s\n", rp->io_buf);
 logging(rp);
}

canonical_original_code:
void io_print_buf(struct io_t *rp) {
 printf("%s\n", rp->io_buf);
 logging(rp);
}


decompiled_code:
int __fastcall io_dump_buf(const char **a1)
{
printf("io_fd: %d\n", *(unsigned int *)a1);
printf("io_cnt: %d\n", *((unsigned int *)a1 + 1));
printf("io_bufptr: %s\n", a1[1]);
return printf("io_buf: %s\n", (const char *)a1 + 16);
}

canonical_decompiled_code:
int __fastcall func8(const char **a1)
{
printf("io_fd: %d\n", *(unsigned int *)a1);
printf("io_cnt: %d\n", *((unsigned int *)a1 + 1));
printf("io_bufptr: %s\n", a1[1]);
return printf("io_buf: %s\n", (const char *)a1 + 16);
}

original_code:
void io_dump_buf(io_t *iop){
 printf("io_fd: %d\n", iop->io_fd);
 printf("io_cnt: %d\n", iop->io_cnt);
 printf("io_bufptr: %s\n", iop->io_bufptr);
 printf("io_buf: %s\n", iop->io_buf);
}

canonical_original_code:
void io_dump_buf(struct io_t *iop){
 printf("io_fd: %d\n", iop->io_fd);
 printf("io_cnt: %d\n", iop->io_cnt);
 printf("io_bufptr: %s\n", iop->io_bufptr);
 printf("io_buf: %s\n", iop->io_buf);
}


decompiled_code:
__int64 __fastcall open_clientfd(char *name, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
struct hostent *v4; // rax
socklen_t v5; // edx
struct in_addr inp; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v8[2]; // [rsp+10h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
v3 = -1;
perror("socket fail");
}
else
{
v3 = v2;
if ( inet_aton(name, &inp) )
v4 = gethostbyaddr(&inp, 4u, 2);
else
v4 = gethostbyname(name);
if ( v4 )
{
v8[0] = 0LL;
v8[0].sa_family = 2;
memmove(&v8[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)v8[0].sa_data = _bswap_16(a2);
if ( connect(v3, v8, v5) < 0 )
{
v3 = -3;
puts("connect fail!");
}
}
else
{
v3 = -2;
puts("get host fail");
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *name, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
struct hostent *v4; // rax
socklen_t v5; // edx
struct in_addr inp; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v8[2]; // [rsp+10h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
v3 = -1;
perror("socket fail");
}
else
{
v3 = v2;
if ( inet_aton(name, &inp) )
v4 = gethostbyaddr(&inp, 4u, 2);
else
v4 = gethostbyname(name);
if ( v4 )
{
v8[0] = 0LL;
v8[0].sa_family = 2;
memmove(&v8[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)v8[0].sa_data = func0(a2);
if ( connect(v3, v8, v5) < 0 )
{
v3 = -3;
puts("connect fail!");
}
}
else
{
v3 = -2;
puts("get host fail");
}
}
return v3;
}

original_code:
int open_clientfd(char *hostname, int port) {
 int clientfd;
 struct hostent *hostp;
 struct sockaddr_in serveraddr;
 struct in_addr addr;
 if ((clientfd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket fail");
  return -1;
 }
 if (inet_aton(hostname, &addr) != 0) {
  hostp = gethostbyaddr((char *)&addr,sizeof(addr),2);
 }
 else {
  hostp = gethostbyname(hostname);
 }
 if (hostp == ((void *)0)) {
  printf("get host fail\n");
  return -2;
 }
 bzero((char *)&serveraddr, sizeof(serveraddr));
 serveraddr.sin_family = 2;
 bcopy((char *)hostp->h_addr_list[0],
   (char *)&serveraddr.sin_addr.s_addr,
   hostp->h_length);
 serveraddr.sin_port = htons((uint16_t)port);
 if (connect(clientfd, (SA *)&serveraddr, sizeof(serveraddr)) < 0) {
  printf("connect fail!\n");
  return -3;
 }
 return clientfd;
}

canonical_original_code:
int open_clientfd(char *hostname, int port) {
 int clientfd;
 struct hostent *hostp;
 struct sockaddr_in serveraddr;
 struct in_addr addr;
 if ((clientfd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket fail");
  return -1;
 }
 if (inet_aton(hostname, &addr) != 0) {
  hostp = gethostbyaddr((char *)&addr,sizeof(addr),2);
 }
 else {
  hostp = gethostbyname(hostname);
 }
 if (hostp == ((void *)0)) {
  printf("get host fail\n");
  return -2;
 }
 bzero((char *)&serveraddr, sizeof(serveraddr));
 serveraddr.sin_family = 2;
 bcopy((char *)hostp->h_addr_list[0],
   (char *)&serveraddr.sin_addr.s_addr,
   hostp->h_length);
 serveraddr.sin_port = htons((unsigned short)port);
 if (connect(clientfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0) {
  printf("connect fail!\n");
  return -3;
 }
 return clientfd;
}

variable_types:
hostname
char *

variable_types: port int

variable_types: clientfd int

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

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

variable_types:
addr
struct in_addr { unsigned int s_addr; }

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: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall open_listenfd(unsigned int a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t v3; // edx
char *v4; // rax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v7[2]; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
v2 = -1;
puts("socket fail!");
}
else
{
v2 = v1;
if ( setsockopt(v1, 1, 2, &optval, 4u) < 0 )
{
v2 = -1;
puts("setsockopt fail!");
}
else
{
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
v7[0].sa_family = 2;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)_bswap_32_constprop_0((unsigned __int16)a1, v7, 16LL);
*(_WORD *)v7[0].sa_data = _bswap_16(a1);
if ( bind(v2, v7, v3) < 0 )
{
v2 = -2;
puts("bind fail!");
}
else if ( listen(v2, 512) < 0 )
{
v2 = -3;
puts("listen fail!");
}
else
{
v4 = inet_ntoa(*(struct in_addr *)&v7[0].sa_data[2]);
printf("server starts at %s:%d\n", v4, a1);
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t v3; // edx
char *v4; // rax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v7[2]; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
v2 = -1;
puts("socket fail!");
}
else
{
v2 = v1;
if ( setsockopt(v1, 1, 2, &optval, 4u) < 0 )
{
v2 = -1;
puts("setsockopt fail!");
}
else
{
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
v7[0].sa_family = 2;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)func1((unsigned __int16)a1, v7, 16LL);
*(_WORD *)v7[0].sa_data = func0(a1);
if ( bind(v2, v7, v3) < 0 )
{
v2 = -2;
puts("bind fail!");
}
else if ( listen(v2, 512) < 0 )
{
v2 = -3;
puts("listen fail!");
}
else
{
v4 = inet_ntoa(*(struct in_addr *)&v7[0].sa_data[2]);
printf("server starts at %s:%d\n", v4, a1);
}
}
}
return v2;
}

original_code:
int open_listenfd(int port) {
 int listenfd, optval=1;
 struct sockaddr_in serveraddr;
 if ((listenfd = socket(2, SOCK_STREAM, 0)) < 0) {
  printf("socket fail!\n");
  return -1;
 }
 if (setsockopt(listenfd, 1, 2,
   (const void *)&optval, sizeof(int)) < 0) {
  printf("setsockopt fail!\n");
  return -1;
 }
 bzero((char *)&serveraddr, sizeof(serveraddr));
 serveraddr.sin_family = 2;
 serveraddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 serveraddr.sin_port = htons((uint16_t)port);
 if (bind(listenfd, (SA *)&serveraddr, sizeof(serveraddr)) < 0) {
  printf("bind fail!\n");
  return -2;
 }
 if (listen(listenfd, 512) < 0) {
  printf("listen fail!\n");
  return -3;
 }
 printf("server starts at %s:%d\n", inet_ntoa(serveraddr.sin_addr), port);
 return listenfd;
}

canonical_original_code:
int open_listenfd(int port) {
 int listenfd; int optval = 1;
 struct sockaddr_in serveraddr;
 if ((listenfd = socket(2, SOCK_STREAM, 0)) < 0) {
  printf("socket fail!\n");
  return -1;
 }
 if (setsockopt(listenfd, 1, 2,
   (void *)&optval, sizeof(int)) < 0) {
  printf("setsockopt fail!\n");
  return -1;
 }
 bzero((char *)&serveraddr, sizeof(serveraddr));
 serveraddr.sin_family = 2;
 serveraddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 serveraddr.sin_port = htons((unsigned short)port);
 if (bind(listenfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0) {
  printf("bind fail!\n");
  return -2;
 }
 if (listen(listenfd, 512) < 0) {
  printf("listen fail!\n");
  return -3;
 }
 printf("server starts at %s:%d\n", inet_ntoa(serveraddr.sin_addr), port);
 return listenfd;
}

variable_types: listenfd int

variable_types: optval int


decompiled_code:
struct hostent *__fastcall check_client_addr(__int64 a1)
{
struct hostent *v1; // r12
unsigned __int16 v2; // bp
char *v3; // rax

v1 = gethostbyaddr((const void *)(a1 + 4), 4u, 2);
if ( v1 )
{
v2 = _bswap_16(*(_WORD *)(a1 + 2));
v3 = inet_ntoa(*(struct in_addr *)(a1 + 4));
printf("Get connection from %s (%s:%d)\n", v1->h_name, v3, v2);
}
return v1;
}

canonical_decompiled_code:
struct hostent *__fastcall func4(__int64 a1)
{
struct hostent *v1; // r12
unsigned __int16 v2; // bp
char *v3; // rax

v1 = gethostbyaddr((const void *)(a1 + 4), 4u, 2);
if ( v1 )
{
v2 = func0(*(_WORD *)(a1 + 2));
v3 = inet_ntoa(*(struct in_addr *)(a1 + 4));
printf("Get connection from %s (%s:%d)\n", v1->h_name, v3, v2);
}
return v1;
}

original_code:
struct hostent *check_client_addr(struct sockaddr_in *clientaddr){
 struct hostent * hostp;
 hostp = gethostbyaddr((const char *)&clientaddr->sin_addr.s_addr,
   sizeof(clientaddr->sin_addr.s_addr), 2);
 if (hostp != ((void *)0) ) {
  printf("Get connection from %s (%s:%d)\n", hostp->h_name,
    inet_ntoa(clientaddr->sin_addr), ntohs(clientaddr->sin_port));
  return hostp;
 }
 return ((void *)0);
}

canonical_original_code:
struct hostent *check_client_addr(struct sockaddr_in *clientaddr){
 struct hostent *hostp;
 hostp = gethostbyaddr((char *)&clientaddr->sin_addr.s_addr,
   sizeof(clientaddr->sin_addr.s_addr), 2);
 if (hostp != ((void *)0) ) {
  printf("Get connection from %s (%s:%d)\n", hostp->h_name,
    inet_ntoa(clientaddr->sin_addr), ntohs(clientaddr->sin_port));
  return hostp;
 }
 return ((void *)0);
}

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: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


thread

decompiled_code:
void *__fastcall thread(void *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
printf("Hello world.\tby tid: %ld\n", v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
printf("Hello world.\tby tid: %ld\n", v1);
return 0LL;
}

original_code:
void *thread(void *vargp) {
 printf("Hello world.\tby tid: %ld\n", pthread_self());
 return ((void *)0);
}

variable_types:
vargp
void *

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // ebp
pthread_t *v5; // rax
pthread_t *v6; // rbx
__int64 v7; // r12
pthread_t *v8; // rbp
pthread_t v9; // rdi

if ( argc == 2 )
{
v4 = atoi(argv[1]);
v5 = (pthread_t *)malloc(8LL * v4);
if ( v4 > 0 )
{
v6 = v5;
v7 = (__int64)&v5[(unsigned int)(v4 - 1) + 1];
v8 = v5;
do
pthread_create(v8++, 0LL, thread, 0LL);
while ( v8 != (pthread_t *)v7 );
do
{
v9 = *v6++;
pthread_join(v9, 0LL);
printf("tid: %ld finished\n", *(v6 - 1));
}
while ( v6 != (pthread_t *)v7 );
}
result = 0;
}
else
{
printf("Usage: %s thread_num\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv) {
 int n = 0, i;
 pthread_t * tidp;
 if (argc != 2) {
  printf("Usage: %s thread_num\n", argv[0]);
  return 1;
 }
 n = atoi(argv[1]);
 tidp = malloc(n * sizeof(pthread_t));
 for (i=0; i<n; i++) {
  pthread_create(&tidp[i], ((void *)0), thread, ((void *)0));
 }
 for (i=0; i<n; i++) {
  pthread_join(tidp[i], ((void *)0));
  printf("tid: %ld finished\n", tidp[i]);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int n = 0; int i;
 unsigned long *tidp;
 if (argc != 2) {
  printf("Usage: %s thread_num\n", argv[0]);
  return 1;
 }
 n = atoi(argv[1]);
 tidp = malloc(n * sizeof(pthread_t));
 for (i=0; i<n; i++) {
  pthread_create(&tidp[i], ((void *)0), thread, ((void *)0));
 }
 for (i=0; i<n; i++) {
  pthread_join(tidp[i], ((void *)0));
  printf("tid: %ld finished\n", tidp[i]);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types:
tidp
unsigned long *


even

repo: leroux/libfc

decompiled_code:
_BOOL8 __fastcall even(char a1)
{
return (a1 & 1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
return (a1 & 1) == 0;
}

original_code:
_Bool even(int a) {
  return a % 2 == 0;
}

variable_types: a int


odd

decompiled_code:
__int64 __fastcall odd(char a1)
{
return a1 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return a1 & 1;
}

original_code:
_Bool odd(int a) {
  return a % 2 != 0;
}

canonical_original_code:
_Bool odd(int a) {
  return a % 2 != 0;
}


decompiled_code:
int __fastcall list_print(int *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rsi

putchar(91);
v1 = *a1;
if ( (int)v1 > 2 )
{
v2 = 1LL;
do
{
v3 = (unsigned int)a1[v2++];
printf("%d, ", v3);
v1 = *a1;
}
while ( (int)v1 - 1 > (int)v2 );
}
return printf("%d]\n", (unsigned int)a1[v1 - 1]);
}

canonical_decompiled_code:
int __fastcall func0(int *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rsi

putchar(91);
v1 = *a1;
if ( (int)v1 > 2 )
{
v2 = 1LL;
do
{
v3 = (unsigned int)a1[v2++];
printf("%d, ", v3);
v1 = *a1;
}
while ( (int)v1 - 1 > (int)v2 );
}
return printf("%d]\n", (unsigned int)a1[v1 - 1]);
}

original_code:
void list_print(int *xs) {
  printf("[");
  int i = 0;
  for (i = 1; i < (xs[0]) - 1; i++) {
    printf("%d, ", xs[i]);
  }
  printf("%d]\n", xs[(xs[0]) - 1]);
  return;
}

variable_types:
xs
int *


head

decompiled_code:
__int64 __fastcall head(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int head(int *xs) {
  return xs[1];
}

canonical_original_code:
int head(int *xs) {
  return xs[1];
}


sum

decompiled_code:
__int64 __fastcall sum(__int64 a1)
{
return foldl(&add, 0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return foldl(&add, 0LL, a1);
}

original_code:
int sum(int *xs) {
  return foldl(add, 0, xs);
}


product

decompiled_code:
__int64 __fastcall product(__int64 a1)
{
return foldl(&mul, 1LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return foldl(&mul, 1LL, a1);
}

original_code:
int product(int *xs) {
  return foldl(mul, 1, xs);
}


foldl

decompiled_code:
__int64 __fastcall foldl(__int64 (__fastcall *a1)(__int64, __int64), unsigned int a2, int *a3)
{
__int64 v4; // rdi
__int64 v6; // rbx
__int64 v7; // rsi

v4 = a2;
if ( *a3 > 1 )
{
v6 = 1LL;
do
{
v7 = (unsigned int)a3[v6++];
LODWORD(v4) = a1(v4, v7);
}
while ( *a3 > (int)v6 );
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 (__fastcall *a1)(__int64, __int64), unsigned int a2, int *a3)
{
__int64 v4; // rdi
__int64 v6; // rbx
__int64 v7; // rsi

v4 = a2;
if ( *a3 > 1 )
{
v6 = 1LL;
do
{
v7 = (unsigned int)a3[v6++];
LODWORD(v4) = a1(v4, v7);
}
while ( *a3 > (int)v6 );
}
return (unsigned int)v4;
}

original_code:
int foldl(bfunc f, int accumulator, int *xs) {
  int i = 0;
  for (i = 1; i < (xs[0]); i++) {
    accumulator = f(accumulator, xs[i]);
  }
  return accumulator;
}

canonical_original_code:
int foldl(int (*f)(int a, int b), int accumulator, int *xs) {
  int i = 0;
  for (i = 1; i < (xs[0]); i++) {
    accumulator = f(accumulator, xs[i]);
  }
  return accumulator;
}

variable_types:
f
int (*)(int a, int b)

variable_types: accumulator int


add

decompiled_code:
__int64 __fastcall add(int a1, int a2)
{
return (unsigned int)(a1 + a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
return (unsigned int)(a1 + a2);
}

original_code:
int add(int a, int b) {
  return a + b;
}

canonical_original_code:
int add(int a, int b) {
  return a + b;
}

variable_types: b int


sub

decompiled_code:
__int64 __fastcall sub(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

original_code:
int sub(int a, int b) {
  return a - b;
}

canonical_original_code:
int sub(int a, int b) {
  return a - b;
}


mul

decompiled_code:
__int64 __fastcall mul(int a1, int a2)
{
return (unsigned int)(a2 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return (unsigned int)(a2 * a1);
}

original_code:
int mul(int a, int b) {
  return a * b;
}

canonical_original_code:
int mul(int a, int b) {
  return a * b;
}


repo: lesbeben/projetSE

decompiled_code:
__int64 __fastcall create_request(char *s1)
{
char *v1; // rbx

if ( !s1 )
{
fwrite("Impossible de traiter une commande NULL\n", 1uLL, 0x28uLL, stderr);
return 0LL;
}
v1 = dl_list;
if ( !dl_list )
{
LABEL_7:
fprintf(stderr, "Commande %.3s inconnue\n", s1);
return 0LL;
}
while ( strncmp(s1, v1, 3uLL) )
{
v1 = (char *)*((_QWORD *)v1 + 4);
if ( !v1 )
goto LABEL_7;
}
return (*((__int64 (__fastcall **)(char *))v1 + 1))(s1);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
char *v1; // rbx

if ( !s1 )
{
fwrite("Impossible de traiter une commande NULL\n", 1uLL, 0x28uLL, stderr);
return 0LL;
}
v1 = dl_list;
if ( !dl_list )
{
LABEL_7:
fprintf(stderr, "Commande %.3s inconnue\n", s1);
return 0LL;
}
while ( strncmp(s1, v1, 3uLL) )
{
v1 = (char *)*((_QWORD *)v1 + 4);
if ( !v1 )
goto LABEL_7;
}
return (*((__int64 (__fastcall **)(char *))v1 + 1))(s1);
}

original_code:
request_t* create_request(const char* cmd) {
 if (cmd != ((void *)0)) {
  dl_list_t elmnt = dl_list;
  while (elmnt != ((void *)0)) {
   if (strncmp(cmd, elmnt->cmd.cmd_name, 3) == 0) {
    return elmnt->cmd.request_cmd_func(cmd);
   }
   elmnt = elmnt->next;
  }
  fprintf(stderr, "Commande %.3s inconnue\n", cmd);
 } else {
  fprintf(stderr, "Impossible de traiter une commande NULL\n");
 }
 return ((void *)0);
}

canonical_original_code:
struct request_t *create_request(char *cmd) {
 if (cmd != ((void *)0)) {
  struct DL_LIST *elmnt = dl_list;
  while (elmnt != ((void *)0)) {
   if (strncmp(cmd, elmnt->cmd.cmd_name, 3) == 0) {
    return elmnt->cmd.request_cmd_func(cmd);
   }
   elmnt = elmnt->next;
  }
  fprintf(stderr, "Commande %.3s inconnue\n", cmd);
 } else {
  fprintf(stderr, "Impossible de traiter une commande NULL\n");
 }
 return ((void *)0);
}

variable_types:
cmd
char *

variable_types: struct DL_LIST { struct request_cmd_t { char cmd_name[4]; struct request_t { unsigned long size; int clientpid; char cmdname[4]; char data[1]; } *(*request_cmd_func)(char *); void (*help)(); } cmd; void *handler; struct DL_LIST *next; } *

user_defined_types: struct DL_LIST { struct request_cmd_t cmd; void *handler; struct DL_LIST *next; }

user_defined_types: struct request_cmd_t { char cmd_name[4]; struct request_t *(*request_cmd_func)(char *); void (*help)(); }


decompiled_code:
void __fastcall delete_request(void *a1)
{
if ( a1 )
free(a1);
else
fwrite("Impossible de supprimer une requete NULL\n", 1uLL, 0x29uLL, stderr);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
if ( a1 )
free(a1);
else
fwrite("Impossible de supprimer une requete NULL\n", 1uLL, 0x29uLL, stderr);
}

original_code:
void delete_request(request_t* req) {
 if (req != ((void *)0)) {
  free(req);
 } else {
  fprintf(stderr, "Impossible de supprimer une requete NULL\n");
 }
}

canonical_original_code:
void delete_request(struct request_t *req) {
 if (req != ((void *)0)) {
  free(req);
 } else {
  fprintf(stderr, "Impossible de supprimer une requete NULL\n");
 }
}

variable_types: struct request_t { unsigned long size; int clientpid; char cmdname[4]; char data[1]; } *


decompiled_code:
__int64 request_manager_helpAll()
{
char *i; // rbx
__int64 result; // rax

for ( i = dl_list; i; i = (char *)*((_QWORD *)i + 4) )
result = (*((__int64 (**)(void))i + 2))();
return result;
}

canonical_decompiled_code:
__int64 func3()
{
char *i; // rbx
__int64 result; // rax

for ( i = dl_list; i; i = (char *)*((_QWORD *)i + 4) )
result = (*((__int64 (**)(void))i + 2))();
return result;
}

original_code:
void request_manager_helpAll() {
 dl_list_t elmnt = dl_list;
 while (elmnt != ((void *)0)) {
  elmnt->cmd.help();
  elmnt = elmnt->next;
 }
}

canonical_original_code:
void request_manager_helpAll() {
 struct DL_LIST *elmnt = dl_list;
 while (elmnt != ((void *)0)) {
  elmnt->cmd.help();
  elmnt = elmnt->next;
 }
}

user_defined_types: struct request_t { unsigned long size; int clientpid; char cmdname[4]; char data[1]; }


decompiled_code:
int __fastcall request_manager_help(char *s1)
{
char *i; // rbx

for ( i = dl_list; i; i = (char *)*((_QWORD *)i + 4) )
{
if ( !strncmp(s1, i, 3uLL) )
(*((void (**)(void))i + 2))();
}
return fprintf(stderr, "Commande %s inconnue\n", s1);
}

canonical_decompiled_code:
int __fastcall func4(char *s1)
{
char *i; // rbx

for ( i = dl_list; i; i = (char *)*((_QWORD *)i + 4) )
{
if ( !strncmp(s1, i, 3uLL) )
(*((void (**)(void))i + 2))();
}
return fprintf(stderr, "Commande %s inconnue\n", s1);
}

original_code:
void request_manager_help(const char* cmd) {
 dl_list_t elmnt = dl_list;
 while (elmnt != ((void *)0)) {
  if (strncmp(cmd, elmnt->cmd.cmd_name, 3) == 0) {
   elmnt->cmd.help();
  }
  elmnt = elmnt->next;
 }
 fprintf(stderr, "Commande %s inconnue\n", cmd);
}

canonical_original_code:
void request_manager_help(char *cmd) {
 struct DL_LIST *elmnt = dl_list;
 while (elmnt != ((void *)0)) {
  if (strncmp(cmd, elmnt->cmd.cmd_name, 3) == 0) {
   elmnt->cmd.help();
  }
  elmnt = elmnt->next;
 }
 fprintf(stderr, "Commande %s inconnue\n", cmd);
}


decompiled_code:
void request_manager_close()
{
char *v0; // rbp
char *v1; // rbx
char *v2; // rax

v0 = dl_list;
if ( dl_list )
{
while ( 1 )
{
if ( dlclose(*((void **)v0 + 3)) == -1 )
{
v2 = dlerror();
fprintf(stderr, "dlclose : %s\n", v2);
raise(15);
}
v1 = (char *)*((_QWORD *)v0 + 4);
free(v0);
if ( !v1 )
break;
v0 = v1;
}
}
}

canonical_decompiled_code:
void func5()
{
char *v0; // rbp
char *v1; // rbx
char *v2; // rax

v0 = dl_list;
if ( dl_list )
{
while ( 1 )
{
if ( dlclose(*((void **)v0 + 3)) == -1 )
{
v2 = dlerror();
fprintf(stderr, "dlclose : %s\n", v2);
raise(15);
}
v1 = (char *)*((_QWORD *)v0 + 4);
free(v0);
if ( !v1 )
break;
v0 = v1;
}
}
}

original_code:
void request_manager_close() {
 dl_list_t elmnt = dl_list;
 while (elmnt != ((void *)0)) {
  if (dlclose(elmnt->handler) == -1) {
   fprintf(stderr, "dlclose : %s\n", dlerror());
   raise(15);
  }
  dl_list_t next = elmnt->next;
  free(elmnt);
  elmnt = next;
 }
}

canonical_original_code:
void request_manager_close() {
 struct DL_LIST *elmnt = dl_list;
 while (elmnt != ((void *)0)) {
  if (dlclose(elmnt->handler) == -1) {
   fprintf(stderr, "dlclose : %s\n", dlerror());
   raise(15);
  }
  struct DL_LIST *next = elmnt->next;
  free(elmnt);
  elmnt = next;
 }
}


send

decompiled_code:
__int64 __fastcall send(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp

result = create_request(a2);
if ( result )
{
v3 = result;
if ( (int)stream_write(a1, result, 0x2000LL) < 0 )
fwrite("Erreur d'envoie d'une requete\n", 1uLL, 0x1EuLL, stderr);
result = delete_request(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp

result = create_request(a2);
if ( result )
{
v3 = result;
if ( (int)stream_write(a1, result, 0x2000LL) < 0 )
fwrite("Erreur d'envoie d'une requete\n", 1uLL, 0x1EuLL, stderr);
result = delete_request(v3);
}
return result;
}

original_code:
void send(stream_t* stream, char* cmd, int size) {
 request_t* req = create_request(cmd);
 if (req != ((void *)0)) {
  if (stream_write(stream, req, 8192) < 0) {
   fprintf(stderr, "Erreur d'envoie d'une requete\n");
  }
  delete_request(req);
 }
}

canonical_original_code:
void send(struct stream_t *stream, char *cmd, int size) {
 struct request_t *req = create_request(cmd);
 if (req != ((void *)0)) {
  if (stream_write(stream, req, 8192) < 0) {
   fprintf(stderr, "Erreur d'envoie d'une requete\n");
  }
  delete_request(req);
 }
}

variable_types: struct stream_t { struct operation_t { int (*_create)(struct streamd_t { void *data; } *, char *, unsigned long); int (*_open)(struct streamd_t *, char *, int); int (*_close)(struct streamd_t *); int (*_read)(struct streamd_t *, void *, unsigned long); int (*_write)(struct streamd_t *, void *, unsigned long); int (*_getfd)(struct streamd_t *); int (*_unlink)(char *); char name[4]; } op; struct streamd_t sd; } *

variable_types: size int

user_defined_types: struct stream_t { struct operation_t op; struct streamd_t sd; }

user_defined_types: struct operation_t { int (*_create)(struct streamd_t *, char *, unsigned long); int (*_open)(struct streamd_t *, char *, int); int (*_close)(struct streamd_t *); int (*_read)(struct streamd_t *, void *, unsigned long); int (*_write)(struct streamd_t *, void *, unsigned long); int (*_getfd)(struct streamd_t *); int (*_unlink)(char *); char name[4]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128i v3; // xmm0
__m128i v4; // xmm1
__m128i v5; // xmm2
__m128i v6; // xmm3
__int64 v7; // rax
unsigned int v8; // er14
const char *v9; // rax
int *v10; // rbx
__int64 v11; // rax
__int64 v12; // r14
char *v14; // rsi
char *v15; // rdi
__m128i *v16; // rsi
__int64 i; // rcx
char *v18; // rsi
__int128 *v19; // rdi
__m128i *v20; // rsi
__int64 j; // rcx
__int64 v22; // rax
int v23; // eax
__int64 v24; // r15
__m128i v25; // [rsp+0h] [rbp-4928h] BYREF
__m128i v26; // [rsp+10h] [rbp-4918h] BYREF
__m128i v27; // [rsp+20h] [rbp-4908h] BYREF
__m128i v28; // [rsp+30h] [rbp-48F8h] BYREF
__int64 v29; // [rsp+40h] [rbp-48E8h]
__int128 v30[4]; // [rsp+50h] [rbp-48D8h] BYREF
__int64 v31; // [rsp+90h] [rbp-4898h]
char v32[80]; // [rsp+A0h] [rbp-4888h] BYREF
char s[512]; // [rsp+F0h] [rbp-4838h] BYREF
char v34[512]; // [rsp+2F0h] [rbp-4638h] BYREF
__int128 v35[32]; // [rsp+4F0h] [rbp-4438h] BYREF
__int128 dest[32]; // [rsp+6F0h] [rbp-4238h] BYREF
char v37[8192]; // [rsp+8F0h] [rbp-4038h] BYREF
char src[4]; // [rsp+28F0h] [rbp-2038h] BYREF
__int16 v39; // [rsp+28F4h] [rbp-2034h]

setSignals(argc, argv, envp);
manager_init();
request_manager_init();
strcpy(v34, "FIF");
manager_getstream(&v25, v34);
v3 = _mm_loadu_si128(&v25);
v4 = _mm_loadu_si128(&v26);
v5 = _mm_loadu_si128(&v27);
v6 = _mm_loadu_si128(&v28);
v31 = v29;
v30[0] = (__int128)v3;
v30[1] = (__int128)v4;
v30[2] = (__int128)v5;
v30[3] = (__int128)v6;
v7 = ((__int64 (*)(void))getRequestName)();
if ( (int)stream_open(v30, v7, 1LL) < 0 )
raise(15);
v8 = getpid();
v9 = (const char *)getAnswerPrefix();
sprintf(s, "%s%i", v9, v8);
manager_getstream(v32, "FIF");
if ( (int)stream_create(v32, s, 0x1FFFLL) < 0 || (int)stream_open(v32, s, 0LL) < 0 )
raise(15);
if ( !(unsigned int)isDone() )
{
send((__int64)v30, (__int64)"CON");
dest[0] = 0xAuLL;
stream_set_clear(src);
stream_set_add(src, v32);
if ( (int)stream_set_select(src, dest) > 0 && (int)stream_read(v32, v37, 0x1FFFLL) < 0 )
fwrite("Erreur de reception des donnees\n", 1uLL, 0x20uLL, stderr);
if ( dest[0] == 0 )
{
fwrite("Impossible de se connecter au serveur\n", 1uLL, 0x26uLL, stderr);
done();
}
}
LABEL_6:
while ( !(unsigned int)isDone() )
{
printf("Entrez une commande : ");
fflush(stdout);
fgets(src, 0x2000, stdin);
v10 = _errno_location();
if ( !*v10 )
{
if ( *(_DWORD *)src == 1414092869 )
{
strlen(src);
send((__int64)v30, (__int64)src);
done();
goto LABEL_6;
}
if ( *(_DWORD *)src == 1230259539 && (_BYTE)v39 == 78 )
{
strncpy((char *)dest, src, 0x200uLL);
strtok((char *)dest, " ");
v14 = strtok(0LL, " ");
if ( v14 )
{
strncpy(v34, v14, 3uLL);
v34[3] = 0;
stream_close(v32);
stream_unlink(v32, s);
manager_getstream(&v25, v34);
v15 = v32;
v16 = &v25;
for ( i = 18LL; i; --i )
{
*(_DWORD *)v15 = v16->m128i_i32[0];
v16 = (__m128i *)((char *)v16 + 4);
v15 += 4;
}
stream_create(v32, s, 0x1FFFLL);
stream_open(v32, s, 0LL);
strlen(src);
send((__int64)v30, (__int64)src);
printf("Changement du mode de reponse en %s\n", v34);
goto LABEL_6;
}
}
else if ( *(_DWORD *)src == 1330922835 && v39 == 21589 )
{
strncpy((char *)v35, src, 0x200uLL);
strtok((char *)v35, " ");
v18 = strtok(0LL, " ");
if ( v18 )
{
strncpy((char *)dest, v18, 3uLL);
BYTE3(dest[0]) = 0;
stream_close(v30);
manager_getstream(&v25, dest);
v19 = v30;
v20 = &v25;
for ( j = 18LL; j; --j )
{
*(_DWORD *)v19 = v20->m128i_i32[0];
v20 = (__m128i *)((char *)v20 + 4);
v19 = (__int128 *)((char *)v19 + 4);
}
v22 = getRequestName(v19, v20);
stream_open(v30, v22, 1LL);
printf("Changement du mode de requete en %s\n", (const char *)dest);
goto LABEL_6;
}
}
else if ( *(_DWORD *)src == 1347175752 )
{
request_manager_helpAll();
goto LABEL_6;
}
v11 = create_request(src);
v12 = v11;
if ( v11 )
{
if ( (int)stream_write(v30, v11, 0x2000LL) < 0 )
raise(15);
v35[0] = 0xAuLL;
stream_set_clear(dest);
stream_set_add(dest, v32);
if ( (int)stream_set_select(dest, v35) > 0 )
{
v23 = stream_read(v32, v37, 0x1FFFLL);
v24 = v23;
if ( v23 < 0 )
fwrite("Erreur de reception des donnees\n", 1uLL, 0x20uLL, stderr);
v37[v24] = 0;
puts(v37);
}
if ( v35[0] == 0 )
fwrite("Timeout de reception de donnees\n", 1uLL, 0x20uLL, stderr);
delete_request(v12);
}
}
*v10 = 0;
}
if ( (int)stream_close(v30) < 0 )
fwrite("Impossible de fermer le flux de requetes\n", 1uLL, 0x29uLL, stderr);
if ( (int)stream_close(v32) < 0 )
fwrite("Impossible de fermer le flux de reponses\n", 1uLL, 0x29uLL, stderr);
manager_clean();
manager_close();
request_manager_close();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128i v3; // xmm0
__m128i v4; // xmm1
__m128i v5; // xmm2
__m128i v6; // xmm3
__int64 v7; // rax
unsigned int v8; // er14
const char *v9; // rax
int *v10; // rbx
__int64 v11; // rax
__int64 v12; // r14
char *v14; // rsi
char *v15; // rdi
__m128i *v16; // rsi
__int64 i; // rcx
char *v18; // rsi
__int128 *v19; // rdi
__m128i *v20; // rsi
__int64 j; // rcx
__int64 v22; // rax
int v23; // eax
__int64 v24; // r15
__m128i v25; // [rsp+0h] [rbp-4928h] BYREF
__m128i v26; // [rsp+10h] [rbp-4918h] BYREF
__m128i v27; // [rsp+20h] [rbp-4908h] BYREF
__m128i v28; // [rsp+30h] [rbp-48F8h] BYREF
__int64 v29; // [rsp+40h] [rbp-48E8h]
__int128 v30[4]; // [rsp+50h] [rbp-48D8h] BYREF
__int64 v31; // [rsp+90h] [rbp-4898h]
char v32[80]; // [rsp+A0h] [rbp-4888h] BYREF
char s[512]; // [rsp+F0h] [rbp-4838h] BYREF
char v34[512]; // [rsp+2F0h] [rbp-4638h] BYREF
__int128 v35[32]; // [rsp+4F0h] [rbp-4438h] BYREF
__int128 dest[32]; // [rsp+6F0h] [rbp-4238h] BYREF
char v37[8192]; // [rsp+8F0h] [rbp-4038h] BYREF
char src[4]; // [rsp+28F0h] [rbp-2038h] BYREF
__int16 v39; // [rsp+28F4h] [rbp-2034h]

setSignals(argc, argv, envp);
manager_init();
request_manager_init();
strcpy(v34, "FIF");
manager_getstream(&v25, v34);
v3 = _mm_loadu_si128(&v25);
v4 = _mm_loadu_si128(&v26);
v5 = _mm_loadu_si128(&v27);
v6 = _mm_loadu_si128(&v28);
v31 = v29;
v30[0] = (__int128)v3;
v30[1] = (__int128)v4;
v30[2] = (__int128)v5;
v30[3] = (__int128)v6;
v7 = ((__int64 (*)(void))getRequestName)();
if ( (int)stream_open(v30, v7, 1LL) < 0 )
raise(15);
v8 = getpid();
v9 = (const char *)getAnswerPrefix();
sprintf(s, "%s%i", v9, v8);
manager_getstream(v32, "FIF");
if ( (int)stream_create(v32, s, 0x1FFFLL) < 0 || (int)stream_open(v32, s, 0LL) < 0 )
raise(15);
if ( !(unsigned int)isDone() )
{
func0((__int64)v30, (__int64)"CON");
dest[0] = 0xAuLL;
stream_set_clear(src);
stream_set_add(src, v32);
if ( (int)stream_set_select(src, dest) > 0 && (int)stream_read(v32, v37, 0x1FFFLL) < 0 )
fwrite("Erreur de reception des donnees\n", 1uLL, 0x20uLL, stderr);
if ( dest[0] == 0 )
{
fwrite("Impossible de se connecter au serveur\n", 1uLL, 0x26uLL, stderr);
done();
}
}
LABEL_6:
while ( !(unsigned int)isDone() )
{
printf("Entrez une commande : ");
fflush(stdout);
fgets(src, 0x2000, stdin);
v10 = _errno_location();
if ( !*v10 )
{
if ( *(_DWORD *)src == 1414092869 )
{
strlen(src);
func0((__int64)v30, (__int64)src);
done();
goto LABEL_6;
}
if ( *(_DWORD *)src == 1230259539 && (_BYTE)v39 == 78 )
{
strncpy((char *)dest, src, 0x200uLL);
strtok((char *)dest, " ");
v14 = strtok(0LL, " ");
if ( v14 )
{
strncpy(v34, v14, 3uLL);
v34[3] = 0;
stream_close(v32);
stream_unlink(v32, s);
manager_getstream(&v25, v34);
v15 = v32;
v16 = &v25;
for ( i = 18LL; i; --i )
{
*(_DWORD *)v15 = v16->m128i_i32[0];
v16 = (__m128i *)((char *)v16 + 4);
v15 += 4;
}
stream_create(v32, s, 0x1FFFLL);
stream_open(v32, s, 0LL);
strlen(src);
func0((__int64)v30, (__int64)src);
printf("Changement du mode de reponse en %s\n", v34);
goto LABEL_6;
}
}
else if ( *(_DWORD *)src == 1330922835 && v39 == 21589 )
{
strncpy((char *)v35, src, 0x200uLL);
strtok((char *)v35, " ");
v18 = strtok(0LL, " ");
if ( v18 )
{
strncpy((char *)dest, v18, 3uLL);
BYTE3(dest[0]) = 0;
stream_close(v30);
manager_getstream(&v25, dest);
v19 = v30;
v20 = &v25;
for ( j = 18LL; j; --j )
{
*(_DWORD *)v19 = v20->m128i_i32[0];
v20 = (__m128i *)((char *)v20 + 4);
v19 = (__int128 *)((char *)v19 + 4);
}
v22 = getRequestName(v19, v20);
stream_open(v30, v22, 1LL);
printf("Changement du mode de requete en %s\n", (const char *)dest);
goto LABEL_6;
}
}
else if ( *(_DWORD *)src == 1347175752 )
{
request_manager_helpAll();
goto LABEL_6;
}
v11 = create_request(src);
v12 = v11;
if ( v11 )
{
if ( (int)stream_write(v30, v11, 0x2000LL) < 0 )
raise(15);
v35[0] = 0xAuLL;
stream_set_clear(dest);
stream_set_add(dest, v32);
if ( (int)stream_set_select(dest, v35) > 0 )
{
v23 = stream_read(v32, v37, 0x1FFFLL);
v24 = v23;
if ( v23 < 0 )
fwrite("Erreur de reception des donnees\n", 1uLL, 0x20uLL, stderr);
v37[v24] = 0;
puts(v37);
}
if ( v35[0] == 0 )
fwrite("Timeout de reception de donnees\n", 1uLL, 0x20uLL, stderr);
delete_request(v12);
}
}
*v10 = 0;
}
if ( (int)stream_close(v30) < 0 )
fwrite("Impossible de fermer le flux de requetes\n", 1uLL, 0x29uLL, stderr);
if ( (int)stream_close(v32) < 0 )
fwrite("Impossible de fermer le flux de reponses\n", 1uLL, 0x29uLL, stderr);
manager_clean();
manager_close();
request_manager_close();
return 0;
}

original_code:
int main(int argc, char **argv) {
 setSignals();
 manager_init();
 request_manager_init();
 request_t *req = ((void *)0);
 char ans_name[512];
 char ans_buf[8192];
 char cmd_buf[8192];
 char ans_stream_type[512];
 sprintf(ans_stream_type, "%s", "FIF");
 stream_t req_str;
 req_str = manager_getstream(ans_stream_type);
 if (stream_open(&req_str, getRequestName(), 01) < 0) {
  raise(15);
 }
    sprintf(ans_name, "%s%i", getAnswerPrefix(), getpid());
    stream_t ans_str = manager_getstream("FIF");
    if (stream_create(&ans_str, ans_name, 8192 -1) < 0) {
  raise(15);
 } else {
  if (stream_open(&ans_str, ans_name, 00) < 0) {
   raise(15);
  }
 }
 if (!isDone()) {
  send(&req_str, "CON", strlen("CON"));
  struct timeval timeout = {10, 0};
  stream_set_t sset;
  stream_set_clear(&sset);
  stream_set_add(&sset, &ans_str);
  if (stream_set_select(&sset, &timeout) > 0) {
   if (stream_read(&ans_str, &ans_buf, 8192 -1) < 0) {
    fprintf(stderr, "Erreur de reception des donnees\n");
   }
  }
  if ((timeout.tv_sec == 0) && (timeout.tv_usec == 0)) {
   fprintf(stderr, "Impossible de se connecter au serveur\n");
   done();
  }
 }
 while (!isDone()) {
     printf("Entrez une commande : ");
     fflush(stdout);
  fgets(cmd_buf, 8192, stdin);
  if ((*__errno_location ()) == 0) {
   if (strncmp(cmd_buf, "EXIT", 4) == 0) {
    send(&req_str, cmd_buf, strlen(cmd_buf));
    done();
    continue;
   } else if (strncmp(cmd_buf, "SETIN", 5) == 0) {
    char buf[512];
    strncpy(buf, cmd_buf, 512);
    strtok(buf, " ");
    char* res = strtok(((void *)0), " ");
    if (res != ((void *)0)) {
     strncpy(ans_stream_type, res, 3);
     ans_stream_type[3] = '\0';
     stream_close(&ans_str);
     stream_unlink(&ans_str, ans_name);
     ans_str = manager_getstream(ans_stream_type);
     stream_create(&ans_str, ans_name, 8192 -1);
     stream_open(&ans_str, ans_name, 00);
     send(&req_str, cmd_buf, strlen(cmd_buf));
     printf("Changement du mode de reponse en %s\n", ans_stream_type);
     continue;
    }
   } else if (strncmp(cmd_buf, "SETOUT", 6) == 0) {
    char buf[512];
    strncpy(buf, cmd_buf, 512);
    strtok(buf, " ");
    char* res = strtok(((void *)0), " ");
    if (res != ((void *)0)) {
     char name[512];
     strncpy(name, res, 3);
     name[3] = '\0';
     stream_close(&req_str);
     req_str = manager_getstream(name);
     stream_open(&req_str, getRequestName(), 01);
     printf("Changement du mode de requete en %s\n", name);
     continue;
    }
   } else if (strncmp(cmd_buf, "HELP", 4) == 0) {
    request_manager_helpAll();
    continue;
   }
   req = create_request(cmd_buf);
   if (req != ((void *)0)) {
    if (stream_write(&req_str, req, 8192) < 0) {
     raise(15);
    }
    int n = 0;
    struct timeval timeout = {10, 0};
    stream_set_t sset;
    stream_set_clear(&sset);
    stream_set_add(&sset, &ans_str);
    if (stream_set_select(&sset, &timeout) > 0) {
     if ((n = stream_read(&ans_str, &ans_buf, 8192 -1)) < 0) {
      fprintf(stderr, "Erreur de reception des donnees\n");
     }
     ans_buf[n] = '\0';
     printf("%s\n", ans_buf);
    }
    if ((timeout.tv_sec == 0) && (timeout.tv_usec == 0)) {
     fprintf(stderr, "Timeout de reception de donnees\n");
    }
    delete_request(req);
   }
  }
  (*__errno_location ()) = 0;
 }
 if (stream_close(&req_str) < 0) {
  fprintf(stderr, "Impossible de fermer le flux de requetes\n");
 }
 if (stream_close(&ans_str) < 0) {
  fprintf(stderr, "Impossible de fermer le flux de reponses\n");
 }
 manager_clean();
 manager_close();
 request_manager_close();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 setSignals();
 manager_init();
 request_manager_init();
 struct request_t *req = ((void *)0);
 char ans_name[512];
 char ans_buf[8192];
 char cmd_buf[8192];
 char ans_stream_type[512];
 sprintf(ans_stream_type, "%s", "FIF");
 struct stream_t req_str;
 req_str = manager_getstream(ans_stream_type);
 if (stream_open(&req_str, getRequestName(), 01) < 0) {
  raise(15);
 }
    sprintf(ans_name, "%s%i", getAnswerPrefix(), getpid());
    struct stream_t ans_str = manager_getstream("FIF");
    if (stream_create(&ans_str, ans_name, 8192 -1) < 0) {
  raise(15);
 } else {
  if (stream_open(&ans_str, ans_name, 00) < 0) {
   raise(15);
  }
 }
 if (!isDone()) {
  send(&req_str, "CON", strlen("CON"));
  struct timeval timeout = {10, 0};
  struct stream_set_t sset;
  stream_set_clear(&sset);
  stream_set_add(&sset, &ans_str);
  if (stream_set_select(&sset, &timeout) > 0) {
   if (stream_read(&ans_str, &ans_buf, 8192 -1) < 0) {
    fprintf(stderr, "Erreur de reception des donnees\n");
   }
  }
  if ((timeout.tv_sec == 0) && (timeout.tv_usec == 0)) {
   fprintf(stderr, "Impossible de se connecter au serveur\n");
   done();
  }
 }
 while (!isDone()) {
     printf("Entrez une commande : ");
     fflush(stdout);
  fgets(cmd_buf, 8192, stdin);
  if ((*__errno_location ()) == 0) {
   if (strncmp(cmd_buf, "EXIT", 4) == 0) {
    send(&req_str, cmd_buf, strlen(cmd_buf));
    done();
    continue;
   } else if (strncmp(cmd_buf, "SETIN", 5) == 0) {
    char buf[512];
    strncpy(buf, cmd_buf, 512);
    strtok(buf, " ");
    char *res = strtok(((void *)0), " ");
    if (res != ((void *)0)) {
     strncpy(ans_stream_type, res, 3);
     ans_stream_type[3] = '\0';
     stream_close(&ans_str);
     stream_unlink(&ans_str, ans_name);
     ans_str = manager_getstream(ans_stream_type);
     stream_create(&ans_str, ans_name, 8192 -1);
     stream_open(&ans_str, ans_name, 00);
     send(&req_str, cmd_buf, strlen(cmd_buf));
     printf("Changement du mode de reponse en %s\n", ans_stream_type);
     continue;
    }
   } else if (strncmp(cmd_buf, "SETOUT", 6) == 0) {
    char buf[512];
    strncpy(buf, cmd_buf, 512);
    strtok(buf, " ");
    char *res = strtok(((void *)0), " ");
    if (res != ((void *)0)) {
     char name[512];
     strncpy(name, res, 3);
     name[3] = '\0';
     stream_close(&req_str);
     req_str = manager_getstream(name);
     stream_open(&req_str, getRequestName(), 01);
     printf("Changement du mode de requete en %s\n", name);
     continue;
    }
   } else if (strncmp(cmd_buf, "HELP", 4) == 0) {
    request_manager_helpAll();
    continue;
   }
   req = create_request(cmd_buf);
   if (req != ((void *)0)) {
    if (stream_write(&req_str, req, 8192) < 0) {
     raise(15);
    }
    int n = 0;
    struct timeval timeout = {10, 0};
    struct stream_set_t sset;
    stream_set_clear(&sset);
    stream_set_add(&sset, &ans_str);
    if (stream_set_select(&sset, &timeout) > 0) {
     if ((n = stream_read(&ans_str, &ans_buf, 8192 -1)) < 0) {
      fprintf(stderr, "Erreur de reception des donnees\n");
     }
     ans_buf[n] = '\0';
     printf("%s\n", ans_buf);
    }
    if ((timeout.tv_sec == 0) && (timeout.tv_usec == 0)) {
     fprintf(stderr, "Timeout de reception de donnees\n");
    }
    delete_request(req);
   }
  }
  (*__errno_location ()) = 0;
 }
 if (stream_close(&req_str) < 0) {
  fprintf(stderr, "Impossible de fermer le flux de requetes\n");
 }
 if (stream_close(&ans_str) < 0) {
  fprintf(stderr, "Impossible de fermer le flux de reponses\n");
 }
 manager_clean();
 manager_close();
 request_manager_close();
 return 0;
}

variable_types: struct stream_t { struct operation_t { int (*_create)(struct streamd_t { void *data; } *, char *, unsigned long); int (*_open)(struct streamd_t *, char *, int); int (*_close)(struct streamd_t *); int (*_read)(struct streamd_t *, void *, unsigned long); int (*_write)(struct streamd_t *, void *, unsigned long); int (*_getfd)(struct streamd_t *); int (*_unlink)(char *); char name[4]; } op; struct streamd_t sd; }

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

variable_types: struct stream_set_t { struct fd_set { long fds_bits[-1]; } _set; int _maxfd; }

variable_types:
buf
char [512]

variable_types:
res
char *

variable_types:
name
char [512]

variable_types: n int

user_defined_types: struct stream_set_t { struct fd_set _set; int _maxfd; }


decompiled_code:
void set_help()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void set_help() {
}

canonical_original_code:
void set_help() {
}


decompiled_code:
char *__fastcall set_request_func(char *src)
{
char *v1; // rax
char *v2; // r12
char *v3; // rax
char *v4; // rax
char v6[536]; // [rsp+0h] [rbp-218h] BYREF

v1 = (char *)malloc(0x1BuLL);
*(_QWORD *)v1 = 27LL;
v2 = v1;
strncpy(v1 + 12, src, 3uLL);
v2[15] = 0;
*((_DWORD *)v2 + 2) = getpid();
v3 = strncpy(v6, src, 0x200uLL);
strtok(v3, " ");
v4 = strtok(0LL, " ");
if ( v4 )
strncpy(v2 + 16, v4, 3uLL);
return v2;
}

canonical_decompiled_code:
char *__fastcall func7(char *src)
{
char *v1; // rax
char *v2; // r12
char *v3; // rax
char *v4; // rax
char v6[536]; // [rsp+0h] [rbp-218h] BYREF

v1 = (char *)malloc(0x1BuLL);
*(_QWORD *)v1 = 27LL;
v2 = v1;
strncpy(v1 + 12, src, 3uLL);
v2[15] = 0;
*((_DWORD *)v2 + 2) = getpid();
v3 = strncpy(v6, src, 0x200uLL);
strtok(v3, " ");
v4 = strtok(0LL, " ");
if ( v4 )
strncpy(v2 + 16, v4, 3uLL);
return v2;
}

original_code:
request_t* set_request_func(const char* cmd) {
 request_t* req = malloc(sizeof(request_t) + 3 * sizeof(char));
 req->size = sizeof(request_t) + 3 * sizeof(char);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 char buf[512];
 strncpy(buf, cmd, 512);
 strtok(buf, " ");
 char* res = strtok(((void *)0), " ");
 if (res != ((void *)0)) {
  strncpy(((char*)req->data), res, 3);
 }
 return req;
}

canonical_original_code:
struct request_t *set_request_func(char *cmd) {
 struct request_t *req = malloc(sizeof(request_t) + 3 * sizeof(char));
 req->size = sizeof(request_t) + 3 * sizeof(char);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 char buf[512];
 strncpy(buf, cmd, 512);
 strtok(buf, " ");
 char *res = strtok(((void *)0), " ");
 if (res != ((void *)0)) {
  strncpy(((char *)req->data), res, 3);
 }
 return req;
}

return_type: struct request_t { unsigned long size; int clientpid; char cmdname[4]; char data[1]; } *


decompiled_code:
__int64 __fastcall manager_addstream(__int64 a1, const char *a2)
{
_QWORD *v2; // rbx
size_t v3; // r12
void *v4; // rax
__int64 result; // rax

v2 = malloc(0x20uLL);
v3 = strlen(a2) + 1;
v4 = malloc(v3);
v2[1] = v4;
memcpy(v4, a2, v3);
*v2 = a1;
*((_DWORD *)v2 + 4) = getpid();
result = stream_list;
stream_list = (__int64)v2;
v2[3] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
_QWORD *v2; // rbx
size_t v3; // r12
void *v4; // rax
__int64 result; // rax

v2 = malloc(0x20uLL);
v3 = strlen(a2) + 1;
v4 = malloc(v3);
v2[1] = v4;
memcpy(v4, a2, v3);
*v2 = a1;
*((_DWORD *)v2 + 4) = getpid();
result = stream_list;
stream_list = (__int64)v2;
v2[3] = result;
return result;
}

original_code:
void manager_addstream(stream_t* stream, const char* name) {
 stream_list_t element = malloc(sizeof(struct STREAM_LIST));
 element->stream_name = malloc(strlen(name) + 1);
 strcpy(element->stream_name, name);
 element->stream = stream;
 element->ownerpid = getpid();
 element->next = stream_list;
 stream_list = element;
}

canonical_original_code:
void manager_addstream(struct stream_t *stream, char *name) {
 struct STREAM_LIST *element = malloc(sizeof(struct STREAM_LIST));
 element->stream_name = malloc(strlen(name) + 1);
 strcpy(element->stream_name, name);
 element->stream = stream;
 element->ownerpid = getpid();
 element->next = stream_list;
 stream_list = element;
}

variable_types:
name
char *

variable_types: struct STREAM_LIST { struct stream_t { struct operation_t { int (*_create)(struct streamd_t { void *data; } *, char *, unsigned long); int (*_open)(struct streamd_t *, char *, int); int (*_close)(struct streamd_t *); int (*_read)(struct streamd_t *, void *, unsigned long); int (*_write)(struct streamd_t *, void *, unsigned long); int (*_getfd)(struct streamd_t *); int (*_unlink)(char *); char name[4]; } op; struct streamd_t sd; } *stream; char *stream_name; int ownerpid; struct STREAM_LIST *next; } *

user_defined_types: struct STREAM_LIST { struct stream_t *stream; char *stream_name; int ownerpid; struct STREAM_LIST *next; }


decompiled_code:
void __fastcall manager_removestream(__int64 a1)
{
_QWORD *v2; // rcx
_QWORD *i; // rdi
__int64 v4; // rax

v2 = 0LL;
for ( i = (_QWORD *)stream_list; i; i = (_QWORD *)i[3] )
{
v4 = i[3];
if ( *i == a1 )
{
if ( v4 )
{
if ( v2 )
v2[3] = v4;
else
stream_list = i[3];
free(i);
}
return;
}
v2 = i;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
_QWORD *v2; // rcx
_QWORD *i; // rdi
__int64 v4; // rax

v2 = 0LL;
for ( i = (_QWORD *)stream_list; i; i = (_QWORD *)i[3] )
{
v4 = i[3];
if ( *i == a1 )
{
if ( v4 )
{
if ( v2 )
v2[3] = v4;
else
stream_list = i[3];
free(i);
}
return;
}
v2 = i;
}
}

original_code:
void manager_removestream(stream_t* stream) {
 stream_list_t prev = ((void *)0);
 stream_list_t element = ((void *)0);
 stream_list_t next = stream_list;
 while (next != ((void *)0)) {
  prev = element;
  element = next;
  next = element->next;
  if (element->stream == stream) {
   break;
  }
 }
 if (next != ((void *)0)) {
  if (prev == ((void *)0)) {
   stream_list = next;
  } else {
   prev->next = next;
  }
  free(element);
 }
}

canonical_original_code:
void manager_removestream(struct stream_t *stream) {
 struct STREAM_LIST *prev = ((void *)0);
 struct STREAM_LIST *element = ((void *)0);
 struct STREAM_LIST *next = stream_list;
 while (next != ((void *)0)) {
  prev = element;
  element = next;
  next = element->next;
  if (element->stream == stream) {
   break;
  }
 }
 if (next != ((void *)0)) {
  if (prev == ((void *)0)) {
   stream_list = next;
  } else {
   prev->next = next;
  }
  free(element);
 }
}


decompiled_code:
void manager_clean()
{
__int64 v0; // rbx
__pid_t v1; // ebp
__int64 v2; // rax
__int64 v3; // rdi

v0 = stream_list;
v1 = getpid();
while ( v0 )
{
while ( 1 )
{
v2 = v0;
v0 = *(_QWORD *)(v0 + 24);
v3 = *(_QWORD *)v2;
if ( *(_DWORD *)(v2 + 16) == v1 )
break;
manager_removestream(v3);
if ( !v0 )
goto LABEL_6;
}
stream_unlink(v3, *(_QWORD *)(v2 + 8));
}
LABEL_6:
stream_list = 0LL;
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rbx
__pid_t v1; // ebp
__int64 v2; // rax
__int64 v3; // rdi

v0 = stream_list;
v1 = getpid();
while ( v0 )
{
while ( 1 )
{
v2 = v0;
v0 = *(_QWORD *)(v0 + 24);
v3 = *(_QWORD *)v2;
if ( *(_DWORD *)(v2 + 16) == v1 )
break;
func2(v3);
if ( !v0 )
goto LABEL_6;
}
stream_unlink(v3, *(_QWORD *)(v2 + 8));
}
LABEL_6:
stream_list = 0LL;
}

original_code:
void manager_clean() {
 stream_list_t element = ((void *)0);
 stream_list_t next = stream_list;
 pid_t pid = getpid();
 while (next != ((void *)0)) {
  element = next;
  next = element->next;
  if (element->ownerpid == pid) {
   stream_unlink(element->stream, element->stream_name);
  } else {
   manager_removestream(element->stream);
  }
 }
 stream_list = ((void *)0);
}

canonical_original_code:
void manager_clean() {
 struct STREAM_LIST *element = ((void *)0);
 struct STREAM_LIST *next = stream_list;
 int pid = getpid();
 while (next != ((void *)0)) {
  element = next;
  next = element->next;
  if (element->ownerpid == pid) {
   stream_unlink(element->stream, element->stream_name);
  } else {
   manager_removestream(element->stream);
  }
 }
 stream_list = ((void *)0);
}

variable_types: pid int


decompiled_code:
void manager_close()
{
void **v0; // rbp
void **v1; // rbx
char *v2; // rax

v0 = (void **)dl_list;
if ( dl_list )
{
while ( 1 )
{
if ( dlclose(v0[8]) == -1 )
{
v2 = dlerror();
fprintf(stderr, "dlclose : %s\n", v2);
raise(15);
}
v1 = (void **)v0[9];
free(v0);
if ( !v1 )
break;
v0 = v1;
}
}
}

canonical_decompiled_code:
void func4()
{
void **v0; // rbp
void **v1; // rbx
char *v2; // rax

v0 = (void **)dl_list;
if ( dl_list )
{
while ( 1 )
{
if ( dlclose(v0[8]) == -1 )
{
v2 = dlerror();
fprintf(stderr, "dlclose : %s\n", v2);
raise(15);
}
v1 = (void **)v0[9];
free(v0);
if ( !v1 )
break;
v0 = v1;
}
}
}

original_code:
void manager_close() {
 dl_list_t elmnt = dl_list;
 while (elmnt != ((void *)0)) {
  if (dlclose(elmnt->handler) == -1) {
   fprintf(stderr, "dlclose : %s\n", dlerror());
   raise(15);
  }
  dl_list_t next = elmnt->next;
  free(elmnt);
  elmnt = next;
 }
}

canonical_original_code:
void manager_close() {
 struct DL_LIST *elmnt = dl_list;
 while (elmnt != ((void *)0)) {
  if (dlclose(elmnt->handler) == -1) {
   fprintf(stderr, "dlclose : %s\n", dlerror());
   raise(15);
  }
  struct DL_LIST *next = elmnt->next;
  free(elmnt);
  elmnt = next;
 }
}

variable_types: struct DL_LIST { struct operation_t { int (*_create)(struct streamd_t { void *data; } *, char *, unsigned long); int (*_open)(struct streamd_t *, char *, int); int (*_close)(struct streamd_t *); int (*_read)(struct streamd_t *, void *, unsigned long); int (*_write)(struct streamd_t *, void *, unsigned long); int (*_getfd)(struct streamd_t *); int (*_unlink)(char *); char name[4]; } op; void *handler; struct DL_LIST *next; } *

user_defined_types: struct DL_LIST { struct operation_t op; void *handler; struct DL_LIST *next; }


decompiled_code:
int time_help()
{
puts("Commande TIM");
puts(" Affiche l'heure du serveur");
puts(" Usage : ");
return puts(" \"TIM\"");
}

canonical_decompiled_code:
int func6()
{
puts("Commande TIM");
puts(" Affiche l'heure du serveur");
puts(" Usage : ");
return puts(" \"TIM\"");
}

original_code:
void time_help() {
    printf("Commande TIM\n");
    printf("  Affiche l'heure du serveur\n");
    printf("  Usage : \n");
    printf("    \"TIM\"\n");
}


decompiled_code:
char *__fastcall time_request_func(char *src)
{
char *v1; // rax
char *v2; // r12

v1 = (char *)malloc(0x18uLL);
*(_QWORD *)v1 = 24LL;
v2 = v1;
strncpy(v1 + 12, src, 3uLL);
v2[15] = 0;
*((_DWORD *)v2 + 2) = getpid();
return v2;
}

canonical_decompiled_code:
char *__fastcall func7(char *src)
{
char *v1; // rax
char *v2; // r12

v1 = (char *)malloc(0x18uLL);
*(_QWORD *)v1 = 24LL;
v2 = v1;
strncpy(v1 + 12, src, 3uLL);
v2[15] = 0;
*((_DWORD *)v2 + 2) = getpid();
return v2;
}

original_code:
request_t* time_request_func(const char* cmd) {
 request_t* req = malloc(sizeof(request_t));
 req->size = sizeof(request_t);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 return req;
}

canonical_original_code:
struct request_t *time_request_func(char *cmd) {
 struct request_t *req = malloc(sizeof(request_t));
 req->size = sizeof(request_t);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 return req;
}


addChild

decompiled_code:
void __fastcall addChild(int a1, int a2)
{
_QWORD *v2; // rdx
_QWORD *v3; // rax
_QWORD *v4; // rcx

if ( a2 != -1 && !(unsigned int)childExist(a1) )
{
v2 = malloc(0x10uLL);
v3 = child_list;
if ( child_list && *(_DWORD *)child_list < a1 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[1];
}
while ( v3 && *(_DWORD *)v3 < a1 );
v2[1] = v3;
*(_DWORD *)v2 = a1;
*((_DWORD *)v2 + 1) = a2;
v4[1] = v2;
}
else
{
v2[1] = child_list;
*(_DWORD *)v2 = a1;
*((_DWORD *)v2 + 1) = a2;
child_list = v2;
}
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
_QWORD *v2; // rdx
_QWORD *v3; // rax
_QWORD *v4; // rcx

if ( a2 != -1 && !(unsigned int)childExist(a1) )
{
v2 = malloc(0x10uLL);
v3 = child_list;
if ( child_list && *(_DWORD *)child_list < a1 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[1];
}
while ( v3 && *(_DWORD *)v3 < a1 );
v2[1] = v3;
*(_DWORD *)v2 = a1;
*((_DWORD *)v2 + 1) = a2;
v4[1] = v2;
}
else
{
v2[1] = child_list;
*(_DWORD *)v2 = a1;
*((_DWORD *)v2 + 1) = a2;
child_list = v2;
}
}
}

original_code:
void addChild(pid_t clientPid, int pipe) {
 if (pipe != -1) {
  if (!childExist(clientPid)) {
   child_list_t elmnt = malloc(sizeof(struct CHILD_LIST));
   child_list_t l = child_list;
   if ((l != ((void *)0)) && (l->client < clientPid)) {
    while ((l->next != ((void *)0)) && (l->next->client < clientPid)) {
     l = l->next;
    }
    elmnt->next = l->next;
    elmnt->client = clientPid;
    elmnt->pipe = pipe;
    l->next = elmnt;
   } else {
    elmnt->next = l;
    elmnt->client = clientPid;
    elmnt->pipe = pipe;
    child_list = elmnt;
   }
  }
 }
}

canonical_original_code:
void addChild(int clientPid, int pipe) {
 if (pipe != -1) {
  if (!childExist(clientPid)) {
   struct CHILD_LIST *elmnt = malloc(sizeof(struct CHILD_LIST));
   struct CHILD_LIST *l = child_list;
   if ((l != ((void *)0)) && (l->client < clientPid)) {
    while ((l->next != ((void *)0)) && (l->next->client < clientPid)) {
     l = l->next;
    }
    elmnt->next = l->next;
    elmnt->client = clientPid;
    elmnt->pipe = pipe;
    l->next = elmnt;
   } else {
    elmnt->next = l;
    elmnt->client = clientPid;
    elmnt->pipe = pipe;
    child_list = elmnt;
   }
  }
 }
}

variable_types: clientPid int

variable_types: pipe int

variable_types: struct CHILD_LIST { int client; int pipe; struct CHILD_LIST *next; } *


getPipe

decompiled_code:
__int64 __fastcall getPipe(int a1)
{
_QWORD *v1; // rax
__int64 result; // rax

v1 = child_list;
if ( !child_list )
goto LABEL_7;
while ( *(_DWORD *)v1 < a1 )
{
v1 = (_QWORD *)v1[1];
if ( !v1 )
goto LABEL_7;
}
if ( *(_DWORD *)v1 == a1 )
result = *((unsigned int *)v1 + 1);
else
LABEL_7:
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
_QWORD *v1; // rax
__int64 result; // rax

v1 = child_list;
if ( !child_list )
goto LABEL_7;
while ( *(_DWORD *)v1 < a1 )
{
v1 = (_QWORD *)v1[1];
if ( !v1 )
goto LABEL_7;
}
if ( *(_DWORD *)v1 == a1 )
result = *((unsigned int *)v1 + 1);
else
LABEL_7:
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int getPipe(pid_t clientPid) {
 child_list_t elmnt = child_list;
 while ((elmnt != ((void *)0)) && (elmnt->client < clientPid)) {
  elmnt = elmnt->next;
 }
 if ((elmnt != ((void *)0)) && (elmnt->client == clientPid)) {
  return elmnt->pipe;
 }
 return -1;
}

canonical_original_code:
int getPipe(int clientPid) {
 struct CHILD_LIST *elmnt = child_list;
 while ((elmnt != ((void *)0)) && (elmnt->client < clientPid)) {
  elmnt = elmnt->next;
 }
 if ((elmnt != ((void *)0)) && (elmnt->client == clientPid)) {
  return elmnt->pipe;
 }
 return -1;
}

user_defined_types: struct CHILD_LIST { int client; int pipe; struct CHILD_LIST *next; }


removeChild

decompiled_code:
void __fastcall removeChild(int a1)
{
_DWORD *v1; // rax
int v2; // edi
_DWORD *v3; // rdx

v1 = child_list;
if ( child_list )
{
if ( *(_DWORD *)child_list == a1 )
{
child_list = (void *)*((_QWORD *)child_list + 1);
LABEL_4:
v2 = v1[1];
*((_QWORD *)v1 + 1) = deleted;
deleted = (__int64)v1;
if ( close(v2) == -1 )
perror("close");
}
else
{
while ( 1 )
{
v3 = v1;
v1 = (_DWORD *)*((_QWORD *)v1 + 1);
if ( !v1 )
break;
if ( *v1 >= a1 )
{
if ( *v1 != a1 )
return;
*((_QWORD *)v3 + 1) = *((_QWORD *)v1 + 1);
goto LABEL_4;
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
_DWORD *v1; // rax
int v2; // edi
_DWORD *v3; // rdx

v1 = child_list;
if ( child_list )
{
if ( *(_DWORD *)child_list == a1 )
{
child_list = (void *)*((_QWORD *)child_list + 1);
LABEL_4:
v2 = v1[1];
*((_QWORD *)v1 + 1) = deleted;
deleted = (__int64)v1;
if ( close(v2) == -1 )
perror("close");
}
else
{
while ( 1 )
{
v3 = v1;
v1 = (_DWORD *)*((_QWORD *)v1 + 1);
if ( !v1 )
break;
if ( *v1 >= a1 )
{
if ( *v1 != a1 )
return;
*((_QWORD *)v3 + 1) = *((_QWORD *)v1 + 1);
goto LABEL_4;
}
}
}
}
}

original_code:
void removeChild(pid_t clientPid) {
 child_list_t l = child_list;
 if ((l != ((void *)0)) && (l->client != clientPid)) {
  while ((l->next != ((void *)0)) && (l->next->client < clientPid)) {
   l = l->next;
  }
  if ((l->next != ((void *)0)) && (l->next->client == clientPid)) {
   child_list_t elmnt = l->next;
   l->next = elmnt->next;
   elmnt->next = deleted;
   deleted = elmnt;
   if (close(elmnt->pipe) == -1) {
    perror("close");
   }
  }
 } else if ((l != ((void *)0)) && (l->client == clientPid)) {
  child_list_t elmnt = l;
  child_list = elmnt->next;
  elmnt->next = deleted;
  deleted = elmnt;
  if (close(elmnt->pipe) == -1) {
   perror("close");
  }
 }
}

canonical_original_code:
void removeChild(int clientPid) {
 struct CHILD_LIST *l = child_list;
 if ((l != ((void *)0)) && (l->client != clientPid)) {
  while ((l->next != ((void *)0)) && (l->next->client < clientPid)) {
   l = l->next;
  }
  if ((l->next != ((void *)0)) && (l->next->client == clientPid)) {
   struct CHILD_LIST *elmnt = l->next;
   l->next = elmnt->next;
   elmnt->next = deleted;
   deleted = elmnt;
   if (close(elmnt->pipe) == -1) {
    perror("close");
   }
  }
 } else if ((l != ((void *)0)) && (l->client == clientPid)) {
  struct CHILD_LIST *elmnt = l;
  child_list = elmnt->next;
  elmnt->next = deleted;
  deleted = elmnt;
  if (close(elmnt->pipe) == -1) {
   perror("close");
  }
 }
}


childsClean

decompiled_code:
__int64 childsClean()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
__int64 result; // rax

v0 = child_list;
if ( child_list )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[1];
if ( close(*((_DWORD *)v1 + 1)) == -1 )
perror("close");
free(child_list);
child_list = v0;
}
while ( v0 );
}
result = deleted;
if ( deleted )
{
do
result = *(_QWORD *)(result + 8);
while ( result );
deleted = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
__int64 result; // rax

v0 = child_list;
if ( child_list )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[1];
if ( close(*((_DWORD *)v1 + 1)) == -1 )
perror("close");
free(child_list);
child_list = v0;
}
while ( v0 );
}
result = deleted;
if ( deleted )
{
do
result = *(_QWORD *)(result + 8);
while ( result );
deleted = 0LL;
}
return result;
}

original_code:
void childsClean() {
 while (child_list != ((void *)0)) {
  child_list_t next = child_list->next;
  if (close(child_list->pipe) == -1) {
   perror("close");
  }
  free(child_list);
  child_list = next;
 }
 while (deleted != ((void *)0)) {
  child_list_t next = deleted->next;
  free(child_list);
  deleted = next;
 }
}

canonical_original_code:
void childsClean() {
 while (child_list != ((void *)0)) {
  struct CHILD_LIST *next = child_list->next;
  if (close(child_list->pipe) == -1) {
   perror("close");
  }
  free(child_list);
  child_list = next;
 }
 while (deleted != ((void *)0)) {
  struct CHILD_LIST *next = deleted->next;
  free(child_list);
  deleted = next;
 }
}


decompiled_code:
int pid_help()
{
puts("Commande PID");
puts(" Affiche le nom du processus 'numpid'");
puts(" Usage : ");
return puts(" \"PID numpid\"");
}

canonical_decompiled_code:
int func6()
{
puts("Commande PID");
puts(" Affiche le nom du processus 'numpid'");
puts(" Usage : ");
return puts(" \"PID numpid\"");
}

original_code:
void pid_help() {
    printf("Commande PID\n");
    printf("  Affiche le nom du processus 'numpid'\n");
    printf("  Usage : \n");
    printf("    \"PID numpid\"\n");
}


decompiled_code:
char *__fastcall pid_request_func(char *src)
{
int v1; // ebx
char *v2; // rax
char *v3; // r12
__pid_t v4; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
v1 = strtol(src + 3, &endptr, 0);
if ( *__errno_location() && !v1 )
{
v3 = 0LL;
fprintf(stderr, "%s n'est pas un entier\n", src + 3);
pid_help();
}
else
{
v2 = (char *)malloc(0x1CuLL);
*(_QWORD *)v2 = 28LL;
v3 = v2;
strncpy(v2 + 12, src, 3uLL);
v3[15] = 0;
v4 = getpid();
*((_DWORD *)v3 + 4) = v1;
*((_DWORD *)v3 + 2) = v4;
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func7(char *src)
{
int v1; // ebx
char *v2; // rax
char *v3; // r12
__pid_t v4; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
v1 = strtol(src + 3, &endptr, 0);
if ( *__errno_location() && !v1 )
{
v3 = 0LL;
fprintf(stderr, "%s n'est pas un entier\n", src + 3);
func6();
}
else
{
v2 = (char *)malloc(0x1CuLL);
*(_QWORD *)v2 = 28LL;
v3 = v2;
strncpy(v2 + 12, src, 3uLL);
v3[15] = 0;
v4 = getpid();
*((_DWORD *)v3 + 4) = v1;
*((_DWORD *)v3 + 2) = v4;
}
return v3;
}

original_code:
request_t* pid_request_func(const char* cmd) {
 char* tailptr[] = { ((void *)0) };
 pid_t pid = strtol(cmd + 3, tailptr, 0);
 if (((*__errno_location ()) == 34 && (pid == 0x7fffffffffffffffL || pid == (-0x7fffffffffffffffL - 1L)))
     || ((*__errno_location ()) != 0 && pid == 0)) {
     fprintf(stderr, "%s n'est pas un entier\n", cmd + 3);
     pid_help();
     return ((void *)0);
 }
 request_t* req = malloc(sizeof(request_t) + sizeof(pid_t));
 req->size = sizeof(request_t) + sizeof(pid_t);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 *((int*)req->data) = pid;
 return req;
}

canonical_original_code:
struct request_t *pid_request_func(char *cmd) {
 char *tailptr[] = { ((void *)0) };
 int pid = strtol(cmd + 3, tailptr, 0);
 if (((*__errno_location ()) == 34 && (pid == 0x7fffffffffffffffL || pid == (-0x7fffffffffffffffL - 1L)))
     || ((*__errno_location ()) != 0 && pid == 0)) {
     fprintf(stderr, "%s n'est pas un entier\n", cmd + 3);
     pid_help();
     return ((void *)0);
 }
 struct request_t *req = malloc(sizeof(request_t) + sizeof(pid_t));
 req->size = sizeof(request_t) + sizeof(pid_t);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 *((int *)req->data) = pid;
 return req;
}

variable_types:
cmd
char *

variable_types:
tailptr
char *[]

variable_types: struct request_t { unsigned long size; int clientpid; char cmdname[4]; char data[1]; } *


getRequestName

decompiled_code:
const char *getRequestName()
{
return "request_stream";
}

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

original_code:
const char* getRequestName() {
 return request_name;
}

canonical_original_code:
char *getRequestName() {
 return request_name;
}

return_type: char *


getAnswerPrefix

decompiled_code:
const char *getAnswerPrefix()
{
return "answer_stream";
}

canonical_decompiled_code:
const char *func1()
{
return "answer_stream";
}

original_code:
const char* getAnswerPrefix() {
 return answer_prefix;
}

canonical_original_code:
char *getAnswerPrefix() {
 return answer_prefix;
}


decompiled_code:
int uid_help()
{
puts("Commande UID");
puts(" Affiche le nom de l'utilisateur 'numuid'");
puts(" Usage : ");
return puts(" \"UID numuid\"");
}

canonical_decompiled_code:
int func6()
{
puts("Commande UID");
puts(" Affiche le nom de l'utilisateur 'numuid'");
puts(" Usage : ");
return puts(" \"UID numuid\"");
}

original_code:
void uid_help() {
    printf("Commande UID\n");
    printf("  Affiche le nom de l'utilisateur 'numuid'\n");
    printf("  Usage : \n");
    printf("    \"UID numuid\"\n");
}


decompiled_code:
char *__fastcall uid_request_func(char *src)
{
int v1; // ebx
char *v2; // rax
char *v3; // r12
__pid_t v4; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
v1 = strtol(src + 3, &endptr, 0);
if ( *__errno_location() && !v1 )
{
v3 = 0LL;
fprintf(stderr, "%s n'est pas un entier\n", src + 3);
uid_help();
}
else
{
v2 = (char *)malloc(0x1CuLL);
*(_QWORD *)v2 = 28LL;
v3 = v2;
strncpy(v2 + 12, src, 3uLL);
v3[15] = 0;
v4 = getpid();
*((_DWORD *)v3 + 4) = v1;
*((_DWORD *)v3 + 2) = v4;
}
return v3;
}

original_code:
request_t* uid_request_func(const char* cmd) {
 char* tailptr[] = { ((void *)0) };
 uid_t uid = strtol(cmd + 3, tailptr, 0);
 if (((*__errno_location ()) == 34 && (uid == 0x7fffffffffffffffL || uid == (-0x7fffffffffffffffL - 1L)))
     || ((*__errno_location ()) != 0 && uid == 0)) {
     fprintf(stderr, "%s n'est pas un entier\n", cmd + 3);
     uid_help();
     return ((void *)0);
 }
 request_t* req = malloc(sizeof(request_t) + sizeof(uid_t));
 req->size = sizeof(request_t) + sizeof(uid_t);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 *((int*)req->data) = uid;
 return req;
}

canonical_original_code:
struct request_t *uid_request_func(char *cmd) {
 char *tailptr[] = { ((void *)0) };
 unsigned int uid = strtol(cmd + 3, tailptr, 0);
 if (((*__errno_location ()) == 34 && (uid == 0x7fffffffffffffffL || uid == (-0x7fffffffffffffffL - 1L)))
     || ((*__errno_location ()) != 0 && uid == 0)) {
     fprintf(stderr, "%s n'est pas un entier\n", cmd + 3);
     uid_help();
     return ((void *)0);
 }
 struct request_t *req = malloc(sizeof(request_t) + sizeof(uid_t));
 req->size = sizeof(request_t) + sizeof(uid_t);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 *((int *)req->data) = uid;
 return req;
}

variable_types:
uid
unsigned int


decompiled_code:
int gid_help()
{
puts("Commande GID");
puts(" Affiche le nom du groupe 'numgid'");
puts(" Usage : ");
return puts(" \"GID numgid\"");
}

canonical_decompiled_code:
int func6()
{
puts("Commande GID");
puts(" Affiche le nom du groupe 'numgid'");
puts(" Usage : ");
return puts(" \"GID numgid\"");
}

original_code:
void gid_help() {
    printf("Commande GID\n");
    printf("  Affiche le nom du groupe 'numgid'\n");
    printf("  Usage : \n");
    printf("    \"GID numgid\"\n");
}


decompiled_code:
char *__fastcall gid_request_func(char *src)
{
int v1; // ebx
char *v2; // rax
char *v3; // r12
__pid_t v4; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
v1 = strtol(src + 3, &endptr, 0);
if ( *__errno_location() )
{
v3 = 0LL;
perror("strtol");
return v3;
}
if ( v1 || !endptr )
{
v2 = (char *)malloc(0x1CuLL);
*(_QWORD *)v2 = 28LL;
v3 = v2;
strncpy(v2 + 12, src, 3uLL);
v3[15] = 0;
v4 = getpid();
*((_DWORD *)v3 + 4) = v1;
*((_DWORD *)v3 + 2) = v4;
return v3;
}
fprintf(stderr, "%s n'est pas un entier\n", src);
gid_help();
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func7(char *src)
{
int v1; // ebx
char *v2; // rax
char *v3; // r12
__pid_t v4; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
v1 = strtol(src + 3, &endptr, 0);
if ( *__errno_location() )
{
v3 = 0LL;
perror("strtol");
return v3;
}
if ( v1 || !endptr )
{
v2 = (char *)malloc(0x1CuLL);
*(_QWORD *)v2 = 28LL;
v3 = v2;
strncpy(v2 + 12, src, 3uLL);
v3[15] = 0;
v4 = getpid();
*((_DWORD *)v3 + 4) = v1;
*((_DWORD *)v3 + 2) = v4;
return v3;
}
fprintf(stderr, "%s n'est pas un entier\n", src);
func6();
return 0LL;
}

original_code:
request_t* gid_request_func(const char* cmd) {
 char* tailptr[] = { ((void *)0) };
 gid_t gid = strtol(cmd + 3, tailptr, 0);
 if ((*__errno_location ()) != 0) {
  perror("strtol");
  return ((void *)0);
 }
 if ((gid == 0) && (tailptr[0] != ((void *)0))) {
  fprintf(stderr, "%s n'est pas un entier\n", cmd);
        gid_help();
  return ((void *)0);
 }
 request_t* req = malloc(sizeof(request_t) + sizeof(gid_t));
 req->size = sizeof(request_t) + sizeof(gid_t);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 *((int*)req->data) = gid;
 return req;
}

canonical_original_code:
struct request_t *gid_request_func(char *cmd) {
 char *tailptr[] = { ((void *)0) };
 unsigned int gid = strtol(cmd + 3, tailptr, 0);
 if ((*__errno_location ()) != 0) {
  perror("strtol");
  return ((void *)0);
 }
 if ((gid == 0) && (tailptr[0] != ((void *)0))) {
  fprintf(stderr, "%s n'est pas un entier\n", cmd);
        gid_help();
  return ((void *)0);
 }
 struct request_t *req = malloc(sizeof(request_t) + sizeof(gid_t));
 req->size = sizeof(request_t) + sizeof(gid_t);
 strncpy(req->cmdname, cmd, 3);
 req->cmdname[3] = '\0';
 req->clientpid = getpid();
 *((int *)req->data) = gid;
 return req;
}

variable_types:
gid
unsigned int


decompiled_code:
int __fastcall process_request(__m128i *a1, __int64 a2)
{
int result; // eax
unsigned int v3; // er12
const char *v4; // rax
__m128i v5; // xmm0
__m128i v6; // xmm1
__m128i v7; // xmm2
__m128i v8; // xmm3
__m128i v9; // [rsp+0h] [rbp-2268h] BYREF
__m128i v10; // [rsp+10h] [rbp-2258h] BYREF
__m128i v11; // [rsp+20h] [rbp-2248h] BYREF
__m128i v12; // [rsp+30h] [rbp-2238h] BYREF
__int64 v13; // [rsp+40h] [rbp-2228h]
char s[512]; // [rsp+50h] [rbp-2218h] BYREF
char v15[8216]; // [rsp+250h] [rbp-2018h] BYREF

result = get_answer(a2, v15, 0x2000LL);
if ( result == -2 )
{
v3 = *(_DWORD *)(a2 + 8);
v4 = (const char *)getAnswerPrefix();
sprintf(s, "%s%i", v4, v3);
if ( (int)stream_close(a1) < 0 )
fwrite("Erreur de fermeture d'un flux", 1uLL, 0x1DuLL, stderr);
manager_getstream(&v9, v15);
v5 = _mm_loadu_si128(&v9);
v6 = _mm_loadu_si128(&v10);
v7 = _mm_loadu_si128(&v11);
v8 = _mm_loadu_si128(&v12);
a1[4].m128i_i64[0] = v13;
*a1 = v5;
a1[1] = v6;
a1[2] = v7;
a1[3] = v8;
if ( (int)stream_open(a1, s, 1LL) < 0 )
raise(15);
result = printf("Changement de communication avec %d en %s\n", *(unsigned int *)(a2 + 8), v15);
}
else if ( result == -3 )
{
printf("Terminaison du client %d\n", *(unsigned int *)(a2 + 8));
result = done();
}
else if ( result >= 0 )
{
result = stream_write(a1, v15, 0x1FFFLL);
if ( result < 0 )
result = raise(15);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__m128i *a1, __int64 a2)
{
int result; // eax
unsigned int v3; // er12
const char *v4; // rax
__m128i v5; // xmm0
__m128i v6; // xmm1
__m128i v7; // xmm2
__m128i v8; // xmm3
__m128i v9; // [rsp+0h] [rbp-2268h] BYREF
__m128i v10; // [rsp+10h] [rbp-2258h] BYREF
__m128i v11; // [rsp+20h] [rbp-2248h] BYREF
__m128i v12; // [rsp+30h] [rbp-2238h] BYREF
__int64 v13; // [rsp+40h] [rbp-2228h]
char s[512]; // [rsp+50h] [rbp-2218h] BYREF
char v15[8216]; // [rsp+250h] [rbp-2018h] BYREF

result = get_answer(a2, v15, 0x2000LL);
if ( result == -2 )
{
v3 = *(_DWORD *)(a2 + 8);
v4 = (const char *)getAnswerPrefix();
sprintf(s, "%s%i", v4, v3);
if ( (int)stream_close(a1) < 0 )
fwrite("Erreur de fermeture d'un flux", 1uLL, 0x1DuLL, stderr);
manager_getstream(&v9, v15);
v5 = _mm_loadu_si128(&v9);
v6 = _mm_loadu_si128(&v10);
v7 = _mm_loadu_si128(&v11);
v8 = _mm_loadu_si128(&v12);
a1[4].m128i_i64[0] = v13;
*a1 = v5;
a1[1] = v6;
a1[2] = v7;
a1[3] = v8;
if ( (int)stream_open(a1, s, 1LL) < 0 )
raise(15);
result = printf("Changement de communication avec %d en %s\n", *(unsigned int *)(a2 + 8), v15);
}
else if ( result == -3 )
{
printf("Terminaison du client %d\n", *(unsigned int *)(a2 + 8));
result = done();
}
else if ( result >= 0 )
{
result = stream_write(a1, v15, 0x1FFFLL);
if ( result < 0 )
result = raise(15);
}
return result;
}

original_code:
static void process_request(stream_t* stream, request_t *req) {
    char buf[8192];
 int n = get_answer(req, buf, 8192);
 if (n == -2) {
  char ans_name[512];
  sprintf(ans_name, "%s%i", getAnswerPrefix(), req->clientpid);
  if (stream_close(stream) < 0) {
   fprintf(stderr, "Erreur de fermeture d'un flux");
  }
  *stream = manager_getstream(buf);
  if (stream_open(stream, ans_name, 01) < 0) {
   raise(15);
  }
  printf("Changement de communication avec %d en %s\n", req->clientpid, buf);
 } else if (n == -3) {
  printf("Terminaison du client %d\n", req->clientpid);
  done();
 } else if (n >= 0) {
  if (stream_write(stream, buf, 8192 -1) < 0) {
   raise(15);
  }
 }
}

canonical_original_code:
static void process_request(struct stream_t *stream, struct request_t *req) {
    char buf[8192];
 int n = get_answer(req, buf, 8192);
 if (n == -2) {
  char ans_name[512];
  sprintf(ans_name, "%s%i", getAnswerPrefix(), req->clientpid);
  if (stream_close(stream) < 0) {
   fprintf(stderr, "Erreur de fermeture d'un flux");
  }
  *stream = manager_getstream(buf);
  if (stream_open(stream, ans_name, 01) < 0) {
   raise(15);
  }
  printf("Changement de communication avec %d en %s\n", req->clientpid, buf);
 } else if (n == -3) {
  printf("Terminaison du client %d\n", req->clientpid);
  done();
 } else if (n >= 0) {
  if (stream_write(stream, buf, 8192 -1) < 0) {
   raise(15);
  }
 }
}

variable_types: struct stream_t { struct operation_t { int (*_create)(struct streamd_t { void *data; } *, char *, unsigned long); int (*_open)(struct streamd_t *, char *, int); int (*_close)(struct streamd_t *); int (*_read)(struct streamd_t *, void *, unsigned long); int (*_write)(struct streamd_t *, void *, unsigned long); int (*_getfd)(struct streamd_t *); int (*_unlink)(char *); char name[4]; } op; struct streamd_t sd; } *

variable_types:
buf
char [8192]


createChild

decompiled_code:
size_t __fastcall createChild(int fd, unsigned int a2)
{
const char *v2; // rax
int v3; // eax
size_t result; // rax
__m128i v5[5]; // [rsp+0h] [rbp-2268h] BYREF
char s[512]; // [rsp+50h] [rbp-2218h] BYREF
char buf[8216]; // [rsp+250h] [rbp-2018h] BYREF

setSignals();
manager_getstream(v5, "FIF");
v2 = (const char *)getAnswerPrefix();
sprintf(s, "%s%i", v2, a2);
if ( (int)stream_open(v5, s, 1LL) < 0 )
raise(15);
LABEL_3:
while ( !(unsigned int)isDone() )
{
while ( 1 )
{
v3 = read(fd, buf, 0x2000uLL);
if ( v3 > 0 )
break;
if ( v3 != -1 || (*_errno_location() & 0xFFFFFFFB) == 0 )
goto LABEL_3;
perror("read");
done();
if ( (unsigned int)isDone() )
goto LABEL_8;
}
process_request(v5, (__int64)buf);
}
LABEL_8:
result = stream_close(v5);
if ( (result & 0x80000000) != 0LL )
result = fwrite("Erreur de fermeture d'un flux", 1uLL, 0x1DuLL, stderr);
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(int fd, unsigned int a2)
{
const char *v2; // rax
int v3; // eax
size_t result; // rax
__m128i v5[5]; // [rsp+0h] [rbp-2268h] BYREF
char s[512]; // [rsp+50h] [rbp-2218h] BYREF
char buf[8216]; // [rsp+250h] [rbp-2018h] BYREF

func1();
manager_getstream(v5, "FIF");
v2 = (const char *)getAnswerPrefix();
sprintf(s, "%s%i", v2, a2);
if ( (int)stream_open(v5, s, 1LL) < 0 )
raise(15);
LABEL_3:
while ( !(unsigned int)isDone() )
{
while ( 1 )
{
v3 = read(fd, buf, 0x2000uLL);
if ( v3 > 0 )
break;
if ( v3 != -1 || (*_errno_location() & 0xFFFFFFFB) == 0 )
goto LABEL_3;
perror("read");
done();
if ( (unsigned int)isDone() )
goto LABEL_8;
}
func2(v5, (__int64)buf);
}
LABEL_8:
result = stream_close(v5);
if ( (result & 0x80000000) != 0LL )
result = fwrite("Erreur de fermeture d'un flux", 1uLL, 0x1DuLL, stderr);
return result;
}

original_code:
void createChild(int pipe, pid_t clientPid) {
 _setSignals();
 char buffer[8192];
 int n = 0;
 char ans_name[512];
 stream_t ans_str = manager_getstream("FIF");
    sprintf(ans_name, "%s%i", getAnswerPrefix(), clientPid);
    if (stream_open(&ans_str, ans_name, 01) < 0) {
  raise(15);
 }
 while (!isDone()) {
  if ((n = read(pipe, buffer, 8192)) > 0) {
   process_request(&ans_str, (request_t*) buffer);
  }
  if ((n == -1) && ((*__errno_location ()) != 4) && ((*__errno_location ()) != 0)) {
   perror("read");
   done();
  }
 }
    if (stream_close(&ans_str) < 0) {
  fprintf(stderr, "Erreur de fermeture d'un flux");
 }
}

canonical_original_code:
void createChild(int pipe, int clientPid) {
 _setSignals();
 char buffer[8192];
 int n = 0;
 char ans_name[512];
 struct stream_t ans_str = manager_getstream("FIF");
    sprintf(ans_name, "%s%i", getAnswerPrefix(), clientPid);
    if (stream_open(&ans_str, ans_name, 01) < 0) {
  raise(15);
 }
 while (!isDone()) {
  if ((n = read(pipe, buffer, 8192)) > 0) {
   process_request(&ans_str, (struct request_t *) buffer);
  }
  if ((n == -1) && ((*__errno_location ()) != 4) && ((*__errno_location ()) != 0)) {
   perror("read");
   done();
  }
 }
    if (stream_close(&ans_str) < 0) {
  fprintf(stderr, "Erreur de fermeture d'un flux");
 }
}

variable_types:
buffer
char [8192]

variable_types: struct stream_t { struct operation_t { int (*_create)(struct streamd_t { void *data; } *, char *, unsigned long); int (*_open)(struct streamd_t *, char *, int); int (*_close)(struct streamd_t *); int (*_read)(struct streamd_t *, void *, unsigned long); int (*_write)(struct streamd_t *, void *, unsigned long); int (*_getfd)(struct streamd_t *); int (*_unlink)(char *); char name[4]; } op; struct streamd_t sd; }


decompiled_code:
__int64 __fastcall exi_answer_func(__int64 a1, _BYTE *a2)
{
*a2 = 0;
return 4294967293LL;
}

original_code:
int exi_answer_func(request_t* req, char* buffer, size_t buffsize) {
 strcpy(buffer, "");
 return -3;
}

canonical_original_code:
int exi_answer_func(struct request_t *req, char *buffer, unsigned long buffsize) {
 strcpy(buffer, "");
 return -3;
}

variable_types:
buffer
char *

variable_types:
buffsize
unsigned long


getCommand

decompiled_code:
__int64 getCommand()
{
return exi_answer_cmd;
}

canonical_decompiled_code:
__int64 func6()
{
return exi_answer_cmd;
}

canonical_original_code:
struct answer_cmd_t getCommand() {
 return exi_answer_cmd;
}

return_type: struct answer_cmd_t { char cmd_name[4]; int (*answer_cmd_func)(struct request_t { unsigned long size; int clientpid; char cmdname[4]; char data[1]; } *, char *, unsigned long); }

user_defined_types: struct answer_cmd_t { char cmd_name[4]; int (*answer_cmd_func)(struct request_t *, char *, unsigned long); }


decompiled_code:
__int64 __fastcall stream_create(__int64 (__fastcall **a1)(__int64, __int64, __int64), __int64 a2, __int64 a3)
{
int v4; // ebp
int v5; // ebp

v4 = check_error_noquit(a1 == 0LL, "stream_create : stream == NULL\n");
v5 = check_error_noquit(a2 == 0, "stream_create : name == NULL\n") | v4;
if ( v5 | (unsigned int)check_error_noquit(a3 == 0, "stream_create : size <= 0\n") )
return 4294967294LL;
manager_addstream(a1, a2);
return (*a1)((__int64)(a1 + 8), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 (__fastcall **a1)(__int64, __int64, __int64), __int64 a2, __int64 a3)
{
int v4; // ebp
int v5; // ebp

v4 = check_error_noquit(a1 == 0LL, "stream_create : stream == NULL\n");
v5 = check_error_noquit(a2 == 0, "stream_create : name == NULL\n") | v4;
if ( v5 | (unsigned int)check_error_noquit(a3 == 0, "stream_create : size <= 0\n") )
return 4294967294LL;
manager_addstream(a1, a2);
return (*a1)((__int64)(a1 + 8), a2, a3);
}

original_code:
int stream_create(stream_t* stream, const char* name, size_t size) {
    int error = 0;
    error = error | check_error_noquit((stream == ((void *)0))
        , "stream_create : stream == NULL\n");
    error = error | check_error_noquit((name == ((void *)0))
        , "stream_create : name == NULL\n");
    error = error | check_error_noquit((size <= 0)
        , "stream_create : size <= 0\n");
    if (error){
  return -2;
 }
 manager_addstream(stream, name);
    return stream->op._create(&stream->sd, name, size);
}

canonical_original_code:
int stream_create(struct stream_t *stream, char *name, unsigned long size) {
    int error = 0;
    error = error | check_error_noquit((stream == ((void *)0))
        , "stream_create : stream == NULL\n");
    error = error | check_error_noquit((name == ((void *)0))
        , "stream_create : name == NULL\n");
    error = error | check_error_noquit((size <= 0)
        , "stream_create : size <= 0\n");
    if (error){
  return -2;
 }
 manager_addstream(stream, name);
    return stream->op._create(&stream->sd, name, size);
}

variable_types:
name
char *

variable_types:
size
unsigned long

variable_types: error int


decompiled_code:
__int64 __fastcall stream_open(__int64 a1, __int64 a2, unsigned int a3)
{
int v4; // ebx
int v5; // ebx
__int64 result; // rax

v4 = check_error_noquit(a1 == 0, "stream_open : stream == NULL\n");
v5 = check_error_noquit(a2 == 0, "stream_open : name == NULL\n") | v4;
if ( v5 | (unsigned int)check_error_noquit((a3 == 0) == (a3 == 1), "stream_open : oflag invalide\n") )
result = 4294967294LL;
else
result = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(a1 + 8))(a1 + 64, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
int v4; // ebx
int v5; // ebx
__int64 result; // rax

v4 = check_error_noquit(a1 == 0, "stream_open : stream == NULL\n");
v5 = check_error_noquit(a2 == 0, "stream_open : name == NULL\n") | v4;
if ( v5 | (unsigned int)check_error_noquit((a3 == 0) == (a3 == 1), "stream_open : oflag invalide\n") )
result = 4294967294LL;
else
result = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(a1 + 8))(a1 + 64, a2, a3);
return result;
}

original_code:
int stream_open(stream_t* stream, const char* name, int oflag) {
    int flagcheck = (oflag == 00) ^ (oflag == 01);
    int error = 0;
    error = error | check_error_noquit((stream == ((void *)0))
        , "stream_open : stream == NULL\n");
    error = error | check_error_noquit((name == ((void *)0))
        , "stream_open : name == NULL\n");
    error = error | check_error_noquit(!flagcheck
        , "stream_open : oflag invalide\n");
    if (error) {
        return -2;
    }
    return stream->op._open(&(stream->sd), name, oflag);
}

canonical_original_code:
int stream_open(struct stream_t *stream, char *name, int oflag) {
    int flagcheck = (oflag == 00) ^ (oflag == 01);
    int error = 0;
    error = error | check_error_noquit((stream == ((void *)0))
        , "stream_open : stream == NULL\n");
    error = error | check_error_noquit((name == ((void *)0))
        , "stream_open : name == NULL\n");
    error = error | check_error_noquit(!flagcheck
        , "stream_open : oflag invalide\n");
    if (error) {
        return -2;
    }
    return stream->op._open(&(stream->sd), name, oflag);
}

variable_types: oflag int

variable_types: flagcheck int


decompiled_code:
__int64 __fastcall stream_close(__int64 a1)
{
_BOOL4 v1; // er12
int v2; // ebp
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 64) == 0LL;
v2 = check_error_noquit(0LL, "stream_close : stream == NULL\n");
if ( (unsigned int)check_error_noquit(v1, "stream_close : Le flux n'est pas ouvert\n") | v2 )
result = 4294967294LL;
else
result = (*(__int64 (__fastcall **)(__int64))(a1 + 16))(a1 + 64);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_BOOL4 v1; // er12
int v2; // ebp
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 64) == 0LL;
v2 = check_error_noquit(0LL, "stream_close : stream == NULL\n");
if ( (unsigned int)check_error_noquit(v1, "stream_close : Le flux n'est pas ouvert\n") | v2 )
result = 4294967294LL;
else
result = (*(__int64 (__fastcall **)(__int64))(a1 + 16))(a1 + 64);
return result;
}

original_code:
int stream_close(stream_t* stream) {
    int openflag = (stream->sd.data == ((void *)0));
    int error = 0;
    error = error | check_error_noquit((stream == ((void *)0))
        , "stream_close : stream == NULL\n");
    error = error | check_error_noquit(openflag
        , "stream_close : Le flux n'est pas ouvert\n");
    if (error) {
        return -2;
    }
 return stream->op._close(&stream->sd);
}

canonical_original_code:
int stream_close(struct stream_t *stream) {
    int openflag = (stream->sd.data == ((void *)0));
    int error = 0;
    error = error | check_error_noquit((stream == ((void *)0))
        , "stream_close : stream == NULL\n");
    error = error | check_error_noquit(openflag
        , "stream_close : Le flux n'est pas ouvert\n");
    if (error) {
        return -2;
    }
 return stream->op._close(&stream->sd);
}

variable_types: openflag int