Bind

decompiled_code:
int __fastcall Bind(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
result = fatal_sys_exit("bind error");
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
result = fatal_sys_exit("bind error");
return result;
}

original_code:
void
Bind(int fd, const struct sockaddr *sa, socklen_t salen)
{
  if (bind(fd, sa, salen) < 0)
    fatal_sys_exit("bind error");
}

canonical_original_code:
void Bind(int fd, struct sockaddr *sa, unsigned int salen)
{
  if (bind(fd, sa, salen) < 0)
    fatal_sys_exit("bind error");
}

variable_types:
salen
unsigned int

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


Connect

repo: schwannden/libsnp

decompiled_code:
int __fastcall Connect(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = connect(a1, a2, a3);
if ( result < 0 )
result = fatal_sys_exit("connect error");
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = connect(a1, a2, a3);
if ( result < 0 )
result = fatal_sys_exit("connect error");
return result;
}

original_code:
void
Connect(int fd, const struct sockaddr *sa, socklen_t salen)
{
  if (connect(fd, sa, salen) < 0)
    fatal_sys_exit("connect error");
}

canonical_original_code:
void Connect(int fd, struct sockaddr *sa, unsigned int salen)
{
  if (connect(fd, sa, salen) < 0)
    fatal_sys_exit("connect error");
}

variable_types: fd int

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

return_type: void


Getpeername

decompiled_code:
int __fastcall Getpeername(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = getpeername(a1, a2, a3);
if ( result < 0 )
result = fatal_sys_exit("getpeername error");
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = getpeername(a1, a2, a3);
if ( result < 0 )
result = fatal_sys_exit("getpeername error");
return result;
}

original_code:
void
Getpeername(int fd, struct sockaddr *sa, socklen_t *salenptr)
{
  if (getpeername(fd, sa, salenptr) < 0)
    fatal_sys_exit("getpeername error");
}

canonical_original_code:
void Getpeername(int fd, struct sockaddr *sa, unsigned int *salenptr)
{
  if (getpeername(fd, sa, salenptr) < 0)
    fatal_sys_exit("getpeername error");
}

variable_types:
salenptr
unsigned int *


Getsockname

decompiled_code:
int __fastcall Getsockname(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = getsockname(a1, a2, a3);
if ( result < 0 )
result = fatal_sys_exit("getsockname error");
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = getsockname(a1, a2, a3);
if ( result < 0 )
result = fatal_sys_exit("getsockname error");
return result;
}

original_code:
void
Getsockname(int fd, struct sockaddr *sa, socklen_t *salenptr)
{
  if (getsockname(fd, sa, salenptr) < 0)
    fatal_sys_exit("getsockname error");
}

canonical_original_code:
void Getsockname(int fd, struct sockaddr *sa, unsigned int *salenptr)
{
  if (getsockname(fd, sa, salenptr) < 0)
    fatal_sys_exit("getsockname error");
}


Getsockopt

decompiled_code:
int __fastcall Getsockopt(int a1, int a2, int a3, void *a4, socklen_t *a5)
{
int result; // eax

result = getsockopt(a1, a2, a3, a4, a5);
if ( result < 0 )
result = fatal_sys_exit("getsockopt error");
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2, int a3, void *a4, socklen_t *a5)
{
int result; // eax

result = getsockopt(a1, a2, a3, a4, a5);
if ( result < 0 )
result = fatal_sys_exit("getsockopt error");
return result;
}

original_code:
void
Getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlenptr)
{
  if (getsockopt(fd, level, optname, optval, optlenptr) < 0)
    fatal_sys_exit("getsockopt error");
}

canonical_original_code:
void Getsockopt(int fd, int level, int optname, void *optval, unsigned int *optlenptr)
{
  if (getsockopt(fd, level, optname, optval, optlenptr) < 0)
    fatal_sys_exit("getsockopt error");
}

variable_types: level int

variable_types: optname int

variable_types:
optval
void *

variable_types:
optlenptr
unsigned int *


Setsockopt

decompiled_code:
int __fastcall Setsockopt(int a1, int a2, int a3, const void *a4, socklen_t a5)
{
int result; // eax

result = setsockopt(a1, a2, a3, a4, a5);
if ( result < 0 )
result = err_sys("setsockopt error");
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2, int a3, const void *a4, socklen_t a5)
{
int result; // eax

result = setsockopt(a1, a2, a3, a4, a5);
if ( result < 0 )
result = err_sys("setsockopt error");
return result;
}

original_code:
void
Setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
{
 if (setsockopt(fd, level, optname, optval, optlen) < 0)
  err_sys("setsockopt error");
}

canonical_original_code:
void Setsockopt(int fd, int level, int optname, void *optval, unsigned int optlen)
{
 if (setsockopt(fd, level, optname, optval, optlen) < 0)
  err_sys("setsockopt error");
}

variable_types:
optlen
unsigned int


Shutdown

decompiled_code:
int __fastcall Shutdown(int a1, int a2)
{
int result; // eax

result = shutdown(a1, a2);
if ( result < 0 )
result = fatal_sys_exit("shutdown error");
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2)
{
int result; // eax

result = shutdown(a1, a2);
if ( result < 0 )
result = fatal_sys_exit("shutdown error");
return result;
}

original_code:
void
Shutdown(int fd, int how)
{
  if (shutdown(fd, how) < 0)
    fatal_sys_exit("shutdown error");
}

variable_types: how int


Sockatmark

decompiled_code:
__int64 __fastcall Sockatmark(int a1)
{
int v1; // ebx

v1 = sockatmark(a1);
if ( v1 < 0 )
fatal_sys_exit("sockatmark error");
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
int v1; // ebx

v1 = sockatmark(a1);
if ( v1 < 0 )
fatal_sys_exit("sockatmark error");
return (unsigned int)v1;
}

original_code:
int
Sockatmark(int fd)
{
  int n;
  if ( (n = sockatmark(fd)) < 0)
    fatal_sys_exit("sockatmark error");
  return(n);
}

variable_types: n int

return_type: int


Socket

decompiled_code:
__int64 __fastcall Socket(int a1, int a2, int a3)
{
int v3; // ebx

v3 = socket(a1, a2, a3);
if ( v3 < 0 )
fatal_sys_exit("socket error");
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2, int a3)
{
int v3; // ebx

v3 = socket(a1, a2, a3);
if ( v3 < 0 )
fatal_sys_exit("socket error");
return (unsigned int)v3;
}

original_code:
int
Socket(int family, int type, int protocol)
{
  int n;
  if ( (n = socket(family, type, protocol)) < 0)
    fatal_sys_exit("socket error");
  return(n);
}

variable_types: family int

variable_types: type int

variable_types: protocol int


Socketpair

decompiled_code:
int __fastcall Socketpair(int a1, int a2, int a3, int *a4)
{
int result; // eax

result = socketpair(a1, a2, a3, a4);
if ( result < 0 )
result = fatal_sys_exit("socketpair error");
return result;
}

canonical_decompiled_code:
int __fastcall func12(int a1, int a2, int a3, int *a4)
{
int result; // eax

result = socketpair(a1, a2, a3, a4);
if ( result < 0 )
result = fatal_sys_exit("socketpair error");
return result;
}

original_code:
void
Socketpair(int family, int type, int protocol, int *fd)
{
  int n;
  if ( (n = socketpair(family, type, protocol, fd)) < 0)
    fatal_sys_exit("socketpair error");
}

variable_types:
fd
int *


Listen

decompiled_code:
int __fastcall Listen(int fd, int n)
{
char *v3; // rax
int result; // eax

v3 = getenv("LISTENQ");
if ( v3 )
n = atoi(v3);
result = listen(fd, n);
if ( result < 0 )
result = fatal_sys_exit("listen error");
return result;
}

canonical_decompiled_code:
int __fastcall func13(int fd, int n)
{
char *v3; // rax
int result; // eax

v3 = getenv("LISTENQ");
if ( v3 )
n = atoi(v3);
result = listen(fd, n);
if ( result < 0 )
result = fatal_sys_exit("listen error");
return result;
}

original_code:
void
Listen(int fd, int backlog)
{
  char *ptr;
  if ( (ptr = getenv("LISTENQ")) != ((void *)0))
    backlog = atoi(ptr);
  if (listen(fd, backlog) < 0)
    fatal_sys_exit("listen error");
}

variable_types: backlog int

variable_types:
ptr
char *


Readn

decompiled_code:
signed __int64 __fastcall Readn(int a1, void *a2, size_t a3)
{
signed __int64 v3; // rbx

v3 = readn(a1, a2, a3);
if ( v3 < 0 )
fatal_sys_exit("readn error");
return v3;
}

canonical_decompiled_code:
signed __int64 __fastcall func1(int a1, void *a2, size_t a3)
{
signed __int64 v3; // rbx

v3 = func0(a1, a2, a3);
if ( v3 < 0 )
fatal_sys_exit("readn error");
return v3;
}

original_code:
ssize_t
Readn( int fd, void* buf, size_t n )
{
  ssize_t number_read;
  if( (number_read = readn(fd, buf, n)) < 0 )
  fatal_sys_exit( "readn error" );
  return number_read;
}

canonical_original_code:
long Readn(int fd, void *buf, unsigned long n)
{
  long number_read;
  if( (number_read = readn(fd, buf, n)) < 0 )
  fatal_sys_exit( "readn error" );
  return number_read;
}

variable_types:
buf
void *

variable_types:
n
unsigned long

return_type: long


writen

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

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
LABEL_3:
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 >= 0 )
return -1LL;
if ( *_errno_location() == 4 )
{
v6 = 0LL;
goto LABEL_3;
}
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;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
LABEL_3:
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 >= 0 )
return -1LL;
if ( *_errno_location() == 4 )
{
v6 = 0LL;
goto LABEL_3;
}
return -1LL;
}

original_code:
ssize_t
writen( int fd, const void* vptr, size_t n )
{
  size_t bytes_left = n;
  ssize_t bytes_written;
  const char* ptr = vptr;
  while( bytes_left > 0 ) {
  if( (bytes_written = write(fd, ptr, bytes_left)) <= 0 )
    if( bytes_written < 0 && (*__errno_location ()) == 4 )
      bytes_written = 0;
    else
    return -1;
  bytes_left -= bytes_written;
  ptr += bytes_written;
  }
  return n;
}

canonical_original_code:
long writen(int fd, void *vptr, unsigned long n)
{
  unsigned long bytes_left = n;
  long bytes_written;
  char *ptr = vptr;
  while( bytes_left > 0 ) {
  if( (bytes_written = write(fd, ptr, bytes_left)) <= 0 )
    if( bytes_written < 0 && (*__errno_location ()) == 4 )
      bytes_written = 0;
    else
    return -1;
  bytes_left -= bytes_written;
  ptr += bytes_written;
  }
  return n;
}

variable_types: fd int

variable_types:
vptr
void *


Writen

decompiled_code:
size_t __fastcall Writen(int a1, void *a2, size_t a3)
{
size_t result; // rax

result = writen(a1, a2, a3);
if ( result != a3 )
result = fatal_sys_exit("writen error");
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(int a1, void *a2, size_t a3)
{
size_t result; // rax

result = func2(a1, a2, a3);
if ( result != a3 )
result = fatal_sys_exit("writen error");
return result;
}

original_code:
void
Writen( int fd, const void *ptr, size_t nbytes )
{
  if (writen(fd, ptr, nbytes) != nbytes)
    fatal_sys_exit("writen error");
}

canonical_original_code:
void Writen(int fd, void *ptr, unsigned long nbytes)
{
  if (writen(fd, ptr, nbytes) != nbytes)
    fatal_sys_exit("writen error");
}

variable_types:
ptr
void *

variable_types:
nbytes
unsigned long


decompiled_code:
ssize_t __fastcall my_read(int fd, _BYTE *a2)
{
__int64 v2; // rax
ssize_t result; // rax

if ( readline_buff_size > 0 )
goto LABEL_2;
while ( 1 )
{
result = read(fd, readline_buff, 0x400uLL);
readline_buff_size = result;
if ( result >= 0 )
break;
*_errno_location() = 4;
}
if ( result )
{
readline_buff_front = 0LL;
LABEL_2:
v2 = readline_buff_front++;
*a2 = readline_buff[v2];
--readline_buff_size;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd, _BYTE *a2)
{
__int64 v2; // rax
ssize_t result; // rax

if ( readline_buff_size > 0 )
goto LABEL_2;
while ( 1 )
{
result = read(fd, readline_buff, 0x400uLL);
readline_buff_size = result;
if ( result >= 0 )
break;
*_errno_location() = 4;
}
if ( result )
{
readline_buff_front = 0LL;
LABEL_2:
v2 = readline_buff_front++;
*a2 = readline_buff[v2];
--readline_buff_size;
result = 1LL;
}
return result;
}

original_code:
ssize_t
my_read( int fd, char* ptr )
{
  if( readline_buff_size <= 0 ){
again:
  if( (readline_buff_size = read( fd, readline_buff, sizeof(readline_buff))) < 0 )
    if( (*__errno_location ()) = 4 )
    goto again;
    else
    return -1;
  else if( readline_buff_size == 0 )
    return 0;
  else
    readline_buff_front = 0;
  }
  *ptr = readline_buff[ readline_buff_front++ ];
  readline_buff_size--;
  return 1;
}

canonical_original_code:
long my_read(int fd, char *ptr)
{
  if( readline_buff_size <= 0 ){
again:
  if( (readline_buff_size = read( fd, readline_buff, sizeof(readline_buff))) < 0 )
    if( (*__errno_location ()) = 4 )
    goto again;
    else
    return -1;
  else if( readline_buff_size == 0 )
    return 0;
  else
    readline_buff_front = 0;
  }
  *ptr = readline_buff[ readline_buff_front++ ];
  readline_buff_size--;
  return 1;
}


readline

original_code:
ssize_t
readline( int fd, void* void_ptr, size_t maxline )
{
  ssize_t bytes_read, read_status;
  char* ptr = void_ptr;
  for( bytes_read = 1 ; bytes_read < maxline ; bytes_read++ )
    if( (read_status = my_read( fd, ptr )) == 1 ) {
      if( *ptr++ == '\n' ){
      *ptr = '\0';
      return bytes_read;
      }
    } else if( read_status == 0 ) {
      *ptr = '\0';
      return bytes_read-1;
    } else
      return -1;
}

canonical_original_code:
long readline(int fd, void *void_ptr, unsigned long maxline)
{
  long bytes_read; long read_status;
  char *ptr = void_ptr;
  for( bytes_read = 1 ; bytes_read < maxline ; bytes_read++ )
    if( (read_status = my_read( fd, ptr )) == 1 ) {
      if( *ptr++ == '\n' ){
      *ptr = '\0';
      return bytes_read;
      }
    } else if( read_status == 0 ) {
      *ptr = '\0';
      return bytes_read-1;
    } else
      return -1;
}

variable_types:
maxline
unsigned long


readlinebuf

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

result = readline_buff_size;
if ( readline_buff_size > 0 )
*a1 = &readline_buff[readline_buff_front];
return result;
}

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

result = readline_buff_size;
if ( readline_buff_size > 0 )
*a1 = &readline_buff[readline_buff_front];
return result;
}

original_code:
ssize_t
readlinebuf( void** ptrptr )
{
  if( readline_buff_size > 0 )
  *ptrptr = readline_buff+readline_buff_front;
  return readline_buff_size;
}

canonical_original_code:
long readlinebuf(void **ptrptr)
{
  if( readline_buff_size > 0 )
  *ptrptr = readline_buff+readline_buff_front;
  return readline_buff_size;
}

variable_types:
ptrptr
void **


Readline

decompiled_code:
__int64 __fastcall Readline(int a1, _BYTE *a2, unsigned __int64 a3)
{
__int64 v3; // rbx

v3 = readline(a1, a2, a3);
if ( v3 < 0 )
fatal_sys_exit("readline error");
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, _BYTE *a2, unsigned __int64 a3)
{
__int64 v3; // rbx

v3 = func5(a1, a2, a3);
if ( v3 < 0 )
fatal_sys_exit("readline error");
return v3;
}

original_code:
ssize_t
Readline( int fd, void* target_ptr, size_t maxline )
{
  ssize_t n;
  if( (n = readline( fd, target_ptr, maxline )) < 0 )
  fatal_sys_exit( "readline error" );
  return n;
}

canonical_original_code:
long Readline(int fd, void *target_ptr, unsigned long maxline)
{
  long n;
  if( (n = readline( fd, target_ptr, maxline )) < 0 )
  fatal_sys_exit( "readline error" );
  return n;
}

variable_types: n long


decompiled_code:
struct addrinfo *__fastcall host_serv(const char *a1, const char *a2, int a3, int a4)
{
bool v4; // zf
struct addrinfo *result; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

req.ai_protocol = 0;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_flags = 2;
req.ai_family = a3;
req.ai_socktype = a4;
v4 = getaddrinfo(a1, a2, &req, &pai) == 0;
result = 0LL;
if ( v4 )
result = pai;
return result;
}

canonical_decompiled_code:
struct addrinfo *__fastcall func8(const char *a1, const char *a2, int a3, int a4)
{
bool v4; // zf
struct addrinfo *result; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

req.ai_protocol = 0;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_flags = 2;
req.ai_family = a3;
req.ai_socktype = a4;
v4 = getaddrinfo(a1, a2, &req, &pai) == 0;
result = 0LL;
if ( v4 )
result = pai;
return result;
}

original_code:
struct addrinfo*
host_serv(const char *host, const char *serv, int family, int socktype)
{
  int n;
  struct addrinfo hints, *res;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = 0x0002;
  hints.ai_family = family;
  hints.ai_socktype = socktype;
  if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
    return(((void *)0));
  return(res);
}

canonical_original_code:
struct addrinfo *host_serv(char *host, char *serv, int family, int socktype)
{
  int n;
  struct addrinfo hints; struct addrinfo *res;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = 0x0002;
  hints.ai_family = family;
  hints.ai_socktype = socktype;
  if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
    return(((void *)0));
  return(res);
}

variable_types:
host
char *

variable_types:
serv
char *

variable_types: socktype int

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

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


decompiled_code:
struct addrinfo *__fastcall Host_serv(const char *a1, const char *a2, int a3, int a4)
{
const char *v4; // rbx
const char *v5; // rbp
int v6; // eax
const char *v8; // rcx
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v4 = a1;
v5 = a2;
req.ai_protocol = 0;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_flags = 2;
req.ai_family = a3;
req.ai_socktype = a4;
v6 = getaddrinfo(a1, a2, &req, &pai);
if ( v6 )
{
v8 = gai_strerror(v6);
if ( !a2 )
v5 = "(no service name)";
if ( !a1 )
v4 = "(no hostname)";
err_quit("host_serv error for %s, %s: %s", v4, v5, v8);
}
return pai;
}

canonical_decompiled_code:
struct addrinfo *__fastcall func9(const char *a1, const char *a2, int a3, int a4)
{
const char *v4; // rbx
const char *v5; // rbp
int v6; // eax
const char *v8; // rcx
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v4 = a1;
v5 = a2;
req.ai_protocol = 0;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_flags = 2;
req.ai_family = a3;
req.ai_socktype = a4;
v6 = getaddrinfo(a1, a2, &req, &pai);
if ( v6 )
{
v8 = gai_strerror(v6);
if ( !a2 )
v5 = "(no service name)";
if ( !a1 )
v4 = "(no hostname)";
err_quit("host_serv error for %s, %s: %s", v4, v5, v8);
}
return pai;
}

original_code:
struct addrinfo *
Host_serv(const char *host, const char *serv, int family, int socktype)
{
  int n;
  struct addrinfo hints, *res;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = 0x0002;
  hints.ai_family = family;
  hints.ai_socktype = socktype;
  if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
    err_quit("host_serv error for %s, %s: %s",
         (host == ((void *)0)) ? "(no hostname)" : host,
         (serv == ((void *)0)) ? "(no service name)" : serv,
         gai_strerror(n));
  return(res);
}

canonical_original_code:
struct addrinfo *Host_serv(char *host, char *serv, int family, int socktype)
{
  int n;
  struct addrinfo hints; struct addrinfo *res;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = 0x0002;
  hints.ai_family = family;
  hints.ai_socktype = socktype;
  if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
    err_quit("host_serv error for %s, %s: %s",
         (host == ((void *)0)) ? "(no hostname)" : host,
         (serv == ((void *)0)) ? "(no service name)" : serv,
         gai_strerror(n));
  return(res);
}

variable_types: family int

variable_types: n int

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


decompiled_code:
__int64 __fastcall Sctp_sendmsg(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // ebx

v4 = sctp_sendmsg(a1, a2, a3, a4);
if ( v4 < 0 )
fatal_sys_exit("sctp_sendmsg error");
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // ebx

v4 = sctp_sendmsg(a1, a2, a3, a4);
if ( v4 < 0 )
fatal_sys_exit("sctp_sendmsg error");
return (unsigned int)v4;
}

original_code:
int
Sctp_sendmsg (int sock_fd, void* data, size_t len, SA* to,
              socklen_t tolen, uint32_t ppid, uint32_t flags,
              uint16_t stream_no, uint32_t timetolive, uint32_t context)
{
  int ret;
  ret = sctp_sendmsg (sock_fd, data, len, to, tolen, ppid, flags,
                      stream_no, timetolive, context);
  if (ret < 0)
    fatal_sys_exit ("sctp_sendmsg error");
  return ret;
}

canonical_original_code:
int Sctp_sendmsg(int sock_fd, void *data, unsigned long len, struct sockaddr *to, unsigned int tolen, unsigned int ppid, unsigned int flags, unsigned short stream_no, unsigned int timetolive, unsigned int context)
{
  int ret;
  ret = sctp_sendmsg (sock_fd, data, len, to, tolen, ppid, flags,
                      stream_no, timetolive, context);
  if (ret < 0)
    fatal_sys_exit ("sctp_sendmsg error");
  return ret;
}

variable_types:
data
void *

variable_types:
len
unsigned long

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

variable_types:
tolen
unsigned int

variable_types:
ppid
unsigned int

variable_types:
flags
unsigned int

variable_types:
timetolive
unsigned int

variable_types:
context
unsigned int

variable_types: ret int


decompiled_code:
const char *__fastcall sock_ntop(unsigned __int16 *a1, unsigned int a2)
{
unsigned __int16 v2; // cx
const char *result; // rax
unsigned __int16 v4; // cx
char s[16]; // [rsp+8h] [rbp-10h] BYREF

v2 = *a1;
if ( *a1 == 1 )
{
if ( *((_BYTE *)a1 + 2) )
snprintf(str_0, 0x80uLL, "%s", (const char *)a1 + 2);
else
strcpy(str_0, "(no pathname bound)");
result = str_0;
}
else if ( v2 == 2 )
{
result = inet_ntop(2, a1 + 2, str_0, 0x80u);
if ( result )
{
v4 = _bswap_16(a1[1]);
result = str_0;
if ( v4 )
{
snprintf(s, 8uLL, ":%d", v4);
strcat(str_0, s);
result = str_0;
}
}
}
else
{
snprintf(str_0, 0x80uLL, "sock_ntop: unknown AF_xxx: %d, len %d", v2, a2);
result = str_0;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(unsigned __int16 *a1, unsigned int a2)
{
unsigned __int16 v2; // cx
const char *result; // rax
unsigned __int16 v4; // cx
char s[16]; // [rsp+8h] [rbp-10h] BYREF

v2 = *a1;
if ( *a1 == 1 )
{
if ( *((_BYTE *)a1 + 2) )
snprintf(str_0, 0x80uLL, "%s", (const char *)a1 + 2);
else
strcpy(str_0, "(no pathname bound)");
result = str_0;
}
else if ( v2 == 2 )
{
result = inet_ntop(2, a1 + 2, str_0, 0x80u);
if ( result )
{
v4 = func0(a1[1]);
result = str_0;
if ( v4 )
{
snprintf(s, 8uLL, ":%d", v4);
strcat(str_0, s);
result = str_0;
}
}
}
else
{
snprintf(str_0, 0x80uLL, "sock_ntop: unknown AF_xxx: %d, len %d", v2, a2);
result = str_0;
}
return result;
}

original_code:
char *
sock_ntop(const struct sockaddr *sa, socklen_t salen)
{
    char portstr[8];
    static char str[128];
  switch (sa->sa_family) {
  case 2: {
    struct sockaddr_in *sin = (struct sockaddr_in *) sa;
    if (inet_ntop(2, &sin->sin_addr, str, sizeof(str)) == ((void *)0))
      return(((void *)0));
    if (ntohs(sin->sin_port) != 0) {
      snprintf(portstr, sizeof(portstr), ":%d", ntohs(sin->sin_port));
      strcat(str, portstr);
    }
    return(str);
  }
  case 1: {
    struct sockaddr_un *unp = (struct sockaddr_un *) sa;
    if (unp->sun_path[0] == 0)
      strcpy(str, "(no pathname bound)");
    else
      snprintf(str, sizeof(str), "%s", unp->sun_path);
    return(str);
  }
  default:
    snprintf(str, sizeof(str), "sock_ntop: unknown AF_xxx: %d, len %d",
         sa->sa_family, salen);
    return(str);
  }
    return (((void *)0));
}

canonical_original_code:
char *sock_ntop(struct sockaddr *sa, unsigned int salen)
{
    char portstr[8];
    static char str[128];
  switch (sa->sa_family) {
  case 2: {
    struct sockaddr_in *sin = (struct sockaddr_in *) sa;
    if (inet_ntop(2, &sin->sin_addr, str, sizeof(str)) == ((void *)0))
      return(((void *)0));
    if (ntohs(sin->sin_port) != 0) {
      snprintf(portstr, sizeof(portstr), ":%d", ntohs(sin->sin_port));
      strcat(str, portstr);
    }
    return(str);
  }
  case 1: {
    struct sockaddr_un *unp = (struct sockaddr_un *) sa;
    if (unp->sun_path[0] == 0)
      strcpy(str, "(no pathname bound)");
    else
      snprintf(str, sizeof(str), "%s", unp->sun_path);
    return(str);
  }
  default:
    snprintf(str, sizeof(str), "sock_ntop: unknown AF_xxx: %d, len %d",
         sa->sa_family, salen);
    return(str);
  }
    return (((void *)0));
}

variable_types:
salen
unsigned int

variable_types:
portstr
char [8]

variable_types:
str
char [128]

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: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

return_type: char *

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


decompiled_code:
const char *__fastcall Sock_ntop(unsigned __int16 *a1, unsigned int a2)
{
const char *v2; // rbx

v2 = sock_ntop(a1, a2);
if ( !v2 )
err_sys("sock_ntop error");
return v2;
}

canonical_decompiled_code:
const char *__fastcall func9(unsigned __int16 *a1, unsigned int a2)
{
const char *v2; // rbx

v2 = func8(a1, a2);
if ( !v2 )
err_sys("sock_ntop error");
return v2;
}

original_code:
char *
Sock_ntop(const struct sockaddr *sa, socklen_t salen)
{
  char *ptr;
  if ( (ptr = sock_ntop(sa, salen)) == ((void *)0))
    err_sys("sock_ntop error");
  return(ptr);
}

canonical_original_code:
char *Sock_ntop(struct sockaddr *sa, unsigned int salen)
{
  char *ptr;
  if ( (ptr = sock_ntop(sa, salen)) == ((void *)0))
    err_sys("sock_ntop error");
  return(ptr);
}

variable_types:
ptr
char *


decompiled_code:
int __fastcall sctp_list_addresses(unsigned __int16 *a1, _QWORD *a2)
{
int v3; // ebp
int result; // eax
const char *v5; // rax

v3 = 0;
if ( (int)a2 <= 0 )
return fatal_user_exit("error sctp_list_addresses: cannot list %n addresses", a2);
do
{
v5 = Sock_ntop(a1, 0x10u);
result = fprintf(stderr, "[INFO] (%s:%d) %d. %s\n", "sctp.c", 238LL, (unsigned int)++v3, v5);
if ( *a1 != 2 )
result = fatal_user_exit("sctp_list_addresses unknown AF");
a1 += 8;
}
while ( v3 != (_DWORD)a2 );
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned __int16 *a1, _QWORD *a2)
{
int v3; // ebp
int result; // eax
const char *v5; // rax

v3 = 0;
if ( (int)a2 <= 0 )
return fatal_user_exit("error sctp_list_addresses: cannot list %n addresses", a2);
do
{
v5 = func9(a1, 0x10u);
result = fprintf(stderr, "[INFO] (%s:%d) %d. %s\n", "sctp.c", 238LL, (unsigned int)++v3, v5);
if ( *a1 != 2 )
result = fatal_user_exit("sctp_list_addresses unknown AF");
a1 += 8;
}
while ( v3 != (_DWORD)a2 );
return result;
}

original_code:
void
sctp_list_addresses (struct sockaddr_storage* addrs, int n)
{
  if (n<1)
    fatal_user_exit ("error sctp_list_addresses: cannot list %n addresses", n);
  struct sockaddr_storage* current;
  int i, socklen;
  current = addrs;
  for (i = 0 ; i < n ; i++)
    {
      fprintf(stderr, "[INFO]  (%s:%d) " "    %d. %s" "\n", "sctp.c", 238, i+1, Sock_ntop ((SA*)current, socklen));
      switch (current->ss_family)
        {
          case 2: socklen = sizeof (struct sockaddr_in); break;
          default: fatal_user_exit ("sctp_list_addresses unknown AF");
        }
      current = (struct sockaddr_storage*) ((char*) current + socklen);
    }
}

canonical_original_code:
void sctp_list_addresses(struct sockaddr_storage *addrs, int n)
{
  if (n<1)
    fatal_user_exit ("error sctp_list_addresses: cannot list %n addresses", n);
  struct sockaddr_storage *current;
  int i; int socklen;
  current = addrs;
  for (i = 0 ; i < n ; i++)
    {
      fprintf(stderr, "[INFO]  (%s:%d) " "    %d. %s" "\n", "sctp.c", 238, i+1, Sock_ntop ((struct sockaddr *)current, socklen));
      switch (current->ss_family)
        {
          case 2: socklen = sizeof (struct sockaddr_in); break;
          default: fatal_user_exit ("sctp_list_addresses unknown AF");
        }
      current = (struct sockaddr_storage *) ((char *) current + socklen);
    }
}

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } *

variable_types: i int

variable_types: socklen int


decompiled_code:
__int64 Sctp_bindx()
{
int v0; // ebx

v0 = sctp_bindx();
if ( v0 < 0 )
err_sys("sctp_bindx error");
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebx

v0 = sctp_bindx();
if ( v0 < 0 )
err_sys("sctp_bindx error");
return (unsigned int)v0;
}

original_code:
int
Sctp_bindx(int sock_fd,struct sockaddr_storage *at,int num,int op)
{
  int ret;
  ret = sctp_bindx (sock_fd, (struct sockaddr*) at, num, op);
  if (ret < 0)
    err_sys("sctp_bindx error");
  return ret;
}

canonical_original_code:
int Sctp_bindx(int sock_fd, struct sockaddr_storage *at, int num, int op)
{
  int ret;
  ret = sctp_bindx (sock_fd, (struct sockaddr *) at, num, op);
  if (ret < 0)
    err_sys("sctp_bindx error");
  return ret;
}

variable_types: num int

variable_types: op int

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


decompiled_code:
__int64 __fastcall sctp_bind_arg_list(unsigned int a1, _QWORD *a2, int a3)
{
int v3; // er15
char *v4; // r12
_QWORD *v5; // rbp
struct addrinfo *v6; // rbx
void *ptr; // [rsp+0h] [rbp-58h]
char s[66]; // [rsp+16h] [rbp-42h] BYREF

v3 = a3;
v4 = (char *)calloc(a3, 0x80uLL);
ptr = v4;
sprintf(s, "%d", 9987LL);
if ( v3 <= 0 )
{
v3 = 0;
}
else
{
v5 = a2;
do
{
v6 = (struct addrinfo *)Host_serv(*v5, s, 0LL, 5LL);
memcpy(v4, v6->ai_addr, v6->ai_addrlen);
freeaddrinfo(v6);
v4 += v6->ai_addrlen;
++v5;
}
while ( v5 != &a2[(unsigned int)(v3 - 1) + 1] );
}
Sctp_bindx(a1, ptr, (unsigned int)v3, 1LL);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, _QWORD *a2, int a3)
{
int v3; // er15
char *v4; // r12
_QWORD *v5; // rbp
struct addrinfo *v6; // rbx
void *ptr; // [rsp+0h] [rbp-58h]
char s[66]; // [rsp+16h] [rbp-42h] BYREF

v3 = a3;
v4 = (char *)calloc(a3, 0x80uLL);
ptr = v4;
sprintf(s, "%d", 9987LL);
if ( v3 <= 0 )
{
v3 = 0;
}
else
{
v5 = a2;
do
{
v6 = (struct addrinfo *)Host_serv(*v5, s, 0LL, 5LL);
memcpy(v4, v6->ai_addr, v6->ai_addrlen);
freeaddrinfo(v6);
v4 += v6->ai_addrlen;
++v5;
}
while ( v5 != &a2[(unsigned int)(v3 - 1) + 1] );
}
func12(a1, ptr, (unsigned int)v3, 1LL);
free(ptr);
return 0LL;
}

original_code:
int
sctp_bind_arg_list(int sock_fd, char **argv, int argc)
{
  struct addrinfo *addr;
  char *bindbuf, *p, portbuf[10];
  int addrcnt=0;
  int i;
  bindbuf = (char *) calloc (argc, sizeof (struct sockaddr_storage));
  p = bindbuf;
  sprintf(portbuf, "%d", 9987);
  for( i=0; i<argc; i++ )
    {
      addr = Host_serv(argv[i], portbuf, 0, SOCK_SEQPACKET);
      memcpy(p, addr->ai_addr, addr->ai_addrlen);
      freeaddrinfo(addr);
      addrcnt++;
      p += addr->ai_addrlen;
    }
  Sctp_bindx ( sock_fd, (struct sockaddr_storage*) bindbuf, addrcnt, 0x01);
  free (bindbuf);
  return 0;
}

canonical_original_code:
int sctp_bind_arg_list(int sock_fd, char **argv, int argc)
{
  struct addrinfo *addr;
  char *bindbuf; char *p; char portbuf[10];
  int addrcnt = 0;
  int i;
  bindbuf = (char *) calloc (argc, sizeof (struct sockaddr_storage));
  p = bindbuf;
  sprintf(portbuf, "%d", 9987);
  for( i=0; i<argc; i++ )
    {
      addr = Host_serv(argv[i], portbuf, 0, SOCK_SEQPACKET);
      memcpy(p, addr->ai_addr, addr->ai_addrlen);
      freeaddrinfo(addr);
      addrcnt++;
      p += addr->ai_addrlen;
    }
  Sctp_bindx ( sock_fd, (struct sockaddr_storage *) bindbuf, addrcnt, 0x01);
  free (bindbuf);
  return 0;
}

variable_types:
argv
char **

variable_types: argc int

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

variable_types:
bindbuf
char *

variable_types:
p
char *

variable_types:
portbuf
char [10]

variable_types: addrcnt int


Fork

decompiled_code:
__int64 Fork()
{
unsigned int v0; // ebx

v0 = fork();
if ( v0 == -1 )
fatal_sys_exit("fork error");
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx

v0 = fork();
if ( v0 == -1 )
fatal_sys_exit("fork error");
return v0;
}

original_code:
pid_t
Fork(void)
{
  pid_t pid;
  if ( (pid = fork()) == -1)
    fatal_sys_exit("fork error");
  return(pid);
}

canonical_original_code:
int Fork()
{
  int pid;
  if ( (pid = fork()) == -1)
    fatal_sys_exit("fork error");
  return(pid);
}

variable_types: pid int


Malloc

decompiled_code:
void *__fastcall Malloc(size_t a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
fatal_sys_exit("malloc error");
return v1;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
fatal_sys_exit("malloc error");
return v1;
}

original_code:
void*
Malloc(size_t size)
{
  void* buf = malloc (size);
  if (buf == ((void *)0))
    fatal_sys_exit ("malloc error");
  return buf;
}

canonical_original_code:
void *Malloc(unsigned long size)
{
  void *buf = malloc (size);
  if (buf == ((void *)0))
    fatal_sys_exit ("malloc error");
  return buf;
}

variable_types:
size
unsigned long

variable_types:
buf
void *

return_type: void *


Close

decompiled_code:
int __fastcall Close(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
result = fatal_sys_exit("close error");
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
result = fatal_sys_exit("close error");
return result;
}

original_code:
void
Close(int fd)
{
  if (close(fd) == -1)
    fatal_sys_exit("close error");
}

variable_types: fd int


Sigaction

decompiled_code:
__int64 __fastcall Sigaction(int a1, const struct sigaction *a2, struct sigaction *a3)
{
int v3; // eax

if ( a1 == 14 )
v3 = a2->sa_flags | 0x20000000;
else
v3 = a2->sa_flags | 0x10000000;
a2->sa_flags = v3;
if ( sigaction(a1, a2, a3) < 0 )
fatal_sys_exit("sigaction error");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const struct sigaction *a2, struct sigaction *a3)
{
int v3; // eax

if ( a1 == 14 )
v3 = a2->sa_flags | 0x20000000;
else
v3 = a2->sa_flags | 0x10000000;
a2->sa_flags = v3;
if ( sigaction(a1, a2, a3) < 0 )
fatal_sys_exit("sigaction error");
return 0LL;
}

original_code:
int Sigaction( int sig, struct sigaction* ptrNewDisp, struct sigaction* ptrOldDisp )
{
  if( sig == 14 ) {
  ptrNewDisp->sa_flags |= 0x20000000;
  } else {
  ptrNewDisp->sa_flags |= 0x10000000;
  }
  if( (sigaction( sig, ptrNewDisp, ptrOldDisp ) < 0) )
  fatal_sys_exit( "sigaction error" );
  return 0;
}

canonical_original_code:
int Sigaction(int sig, struct sigaction *ptrNewDisp, struct sigaction *ptrOldDisp)
{
  if( sig == 14 ) {
  ptrNewDisp->sa_flags |= 0x20000000;
  } else {
  ptrNewDisp->sa_flags |= 0x10000000;
  }
  if( (sigaction( sig, ptrNewDisp, ptrOldDisp ) < 0) )
  fatal_sys_exit( "sigaction error" );
  return 0;
}

variable_types: sig int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); } *

variable_types:
ptrOldDisp
struct sigaction *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


Recv

decompiled_code:
ssize_t __fastcall Recv(int a1, void *a2, size_t a3, int a4)
{
ssize_t v4; // rbx

v4 = recv(a1, a2, a3, a4);
if ( v4 < 0 )
fatal_sys_exit("recv error");
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1, void *a2, size_t a3, int a4)
{
ssize_t v4; // rbx

v4 = recv(a1, a2, a3, a4);
if ( v4 < 0 )
fatal_sys_exit("recv error");
return v4;
}

original_code:
ssize_t
Recv(int fd, void *ptr, size_t nbytes, int flags)
{
  ssize_t n;
  if ( (n = recv(fd, ptr, nbytes, flags)) < 0)
    fatal_sys_exit("recv error");
  return(n);
}

canonical_original_code:
long Recv(int fd, void *ptr, unsigned long nbytes, int flags)
{
  long n;
  if ( (n = recv(fd, ptr, nbytes, flags)) < 0)
    fatal_sys_exit("recv error");
  return(n);
}

variable_types:
ptr
void *

variable_types:
nbytes
unsigned long

variable_types: flags int

variable_types: n long


Recvfrom

decompiled_code:
ssize_t __fastcall Recvfrom(int a1, void *a2, size_t a3, int a4, struct sockaddr *a5, socklen_t *a6)
{
ssize_t v6; // rbx

v6 = recvfrom(a1, a2, a3, a4, a5, a6);
if ( v6 < 0 )
fatal_sys_exit("recvfrom error");
return v6;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int a1, void *a2, size_t a3, int a4, struct sockaddr *a5, socklen_t *a6)
{
ssize_t v6; // rbx

v6 = recvfrom(a1, a2, a3, a4, a5, a6);
if ( v6 < 0 )
fatal_sys_exit("recvfrom error");
return v6;
}

original_code:
ssize_t
Recvfrom(int fd, void *ptr, size_t nbytes, int flags,
     struct sockaddr *sa, socklen_t *salenptr)
{
  ssize_t n;
  if ( (n = recvfrom(fd, ptr, nbytes, flags, sa, salenptr)) < 0)
    fatal_sys_exit("recvfrom error");
  return(n);
}

canonical_original_code:
long Recvfrom(int fd, void *ptr, unsigned long nbytes, int flags, struct sockaddr *sa, unsigned int *salenptr)
{
  long n;
  if ( (n = recvfrom(fd, ptr, nbytes, flags, sa, salenptr)) < 0)
    fatal_sys_exit("recvfrom error");
  return(n);
}

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

variable_types:
salenptr
unsigned int *


Recvmsg

decompiled_code:
ssize_t __fastcall Recvmsg(int a1, struct msghdr *a2, int a3)
{
ssize_t v3; // rbx

v3 = recvmsg(a1, a2, a3);
if ( v3 < 0 )
fatal_sys_exit("recvmsg error");
return v3;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int a1, struct msghdr *a2, int a3)
{
ssize_t v3; // rbx

v3 = recvmsg(a1, a2, a3);
if ( v3 < 0 )
fatal_sys_exit("recvmsg error");
return v3;
}

original_code:
ssize_t
Recvmsg(int fd, struct msghdr *msg, int flags)
{
  ssize_t n;
  if ( (n = recvmsg(fd, msg, flags)) < 0)
    fatal_sys_exit("recvmsg error");
  return(n);
}

canonical_original_code:
long Recvmsg(int fd, struct msghdr *msg, int flags)
{
  long n;
  if ( (n = recvmsg(fd, msg, flags)) < 0)
    fatal_sys_exit("recvmsg error");
  return(n);
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


Select

decompiled_code:
__int64 __fastcall Select(int a1, fd_set *a2, fd_set *a3, fd_set *a4, struct timeval *a5)
{
int v5; // ebx

v5 = select(a1, a2, a3, a4, a5);
if ( v5 < 0 )
fatal_sys_exit("select error");
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, fd_set *a2, fd_set *a3, fd_set *a4, struct timeval *a5)
{
int v5; // ebx

v5 = select(a1, a2, a3, a4, a5);
if ( v5 < 0 )
fatal_sys_exit("select error");
return (unsigned int)v5;
}

original_code:
int
Select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
       struct timeval *timeout)
{
  int n;
  if ( (n = select(nfds, readfds, writefds, exceptfds, timeout)) < 0)
    fatal_sys_exit("select error");
  return(n);
}

canonical_original_code:
int Select(int nfds, struct fd_set *readfds, struct fd_set *writefds, struct fd_set *exceptfds, struct timeval *timeout)
{
  int n;
  if ( (n = select(nfds, readfds, writefds, exceptfds, timeout)) < 0)
    fatal_sys_exit("select error");
  return(n);
}

variable_types: nfds int

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

variable_types:
writefds
struct fd_set *

variable_types:
exceptfds
struct fd_set *

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

variable_types: n int


Send

decompiled_code:
ssize_t __fastcall Send(int a1, const void *a2, size_t a3, int a4)
{
ssize_t result; // rax

result = send(a1, a2, a3, a4);
if ( result != a3 )
result = fatal_sys_exit("send error");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(int a1, const void *a2, size_t a3, int a4)
{
ssize_t result; // rax

result = send(a1, a2, a3, a4);
if ( result != a3 )
result = fatal_sys_exit("send error");
return result;
}

original_code:
void
Send(int fd, const void *ptr, size_t nbytes, int flags)
{
  if (send(fd, ptr, nbytes, flags) != (ssize_t)nbytes)
    fatal_sys_exit("send error");
}

canonical_original_code:
void Send(int fd, void *ptr, unsigned long nbytes, int flags)
{
  if (send(fd, ptr, nbytes, flags) != (long)nbytes)
    fatal_sys_exit("send error");
}

variable_types: fd int


Sendto

decompiled_code:
ssize_t __fastcall Sendto(int a1, const void *a2, size_t a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
ssize_t result; // rax

result = sendto(a1, a2, a3, a4, a5, a6);
if ( result != a3 )
result = fatal_sys_exit("sendto error");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, const void *a2, size_t a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
ssize_t result; // rax

result = sendto(a1, a2, a3, a4, a5, a6);
if ( result != a3 )
result = fatal_sys_exit("sendto error");
return result;
}

original_code:
void
Sendto(int fd, const void *ptr, size_t nbytes, int flags,
     const struct sockaddr *sa, socklen_t salen)
{
  if (sendto(fd, ptr, nbytes, flags, sa, salen) != (ssize_t)nbytes)
    fatal_sys_exit("sendto error");
}

canonical_original_code:
void Sendto(int fd, void *ptr, unsigned long nbytes, int flags, struct sockaddr *sa, unsigned int salen)
{
  if (sendto(fd, ptr, nbytes, flags, sa, salen) != (long)nbytes)
    fatal_sys_exit("sendto error");
}

variable_types:
salen
unsigned int


Sendmsg

decompiled_code:
ssize_t __fastcall Sendmsg(int fd, struct msghdr *message, int flags)
{
size_t v6; // rcx
struct iovec *v7; // rsi
__int64 v8; // rbx
unsigned int v9; // edx
__int64 v10; // rax
ssize_t result; // rax

v6 = message->msg_iovlen;
if ( v6 )
{
v7 = message->msg_iov;
v8 = 0LL;
v9 = 0;
v10 = 0LL;
do
{
v8 += v7[v10].iov_len;
v10 = ++v9;
}
while ( v9 < v6 );
}
else
{
v8 = 0LL;
}
result = sendmsg(fd, message, flags);
if ( result != v8 )
result = fatal_sys_exit("sendmsg error");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func6(int fd, struct msghdr *message, int flags)
{
size_t v6; // rcx
struct iovec *v7; // rsi
__int64 v8; // rbx
unsigned int v9; // edx
__int64 v10; // rax
ssize_t result; // rax

v6 = message->msg_iovlen;
if ( v6 )
{
v7 = message->msg_iov;
v8 = 0LL;
v9 = 0;
v10 = 0LL;
do
{
v8 += v7[v10].iov_len;
v10 = ++v9;
}
while ( v9 < v6 );
}
else
{
v8 = 0LL;
}
result = sendmsg(fd, message, flags);
if ( result != v8 )
result = fatal_sys_exit("sendmsg error");
return result;
}

original_code:
void
Sendmsg(int fd, const struct msghdr *msg, int flags)
{
  unsigned int i;
  ssize_t nbytes;
  nbytes = 0;
  for (i = 0; i < msg->msg_iovlen; i++)
    nbytes += msg->msg_iov[i].iov_len;
  if (sendmsg(fd, msg, flags) != nbytes)
    fatal_sys_exit("sendmsg error");
}

canonical_original_code:
void Sendmsg(int fd, struct msghdr *msg, int flags)
{
  unsigned int i;
  long nbytes;
  nbytes = 0;
  for (i = 0; i < msg->msg_iovlen; i++)
    nbytes += msg->msg_iov[i].iov_len;
  if (sendmsg(fd, msg, flags) != nbytes)
    fatal_sys_exit("sendmsg error");
}

variable_types:
i
unsigned int

variable_types: nbytes long

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


Read

decompiled_code:
__int64 __fastcall Read(int fd, void *buf, size_t nbytes)
{
int v4; // er13

while ( 1 )
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 )
break;
if ( *_errno_location() != 4 )
{
fatal_sys_exit("read error");
return v4;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, void *buf, size_t nbytes)
{
int v4; // er13

while ( 1 )
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 )
break;
if ( *_errno_location() != 4 )
{
fatal_sys_exit("read error");
return v4;
}
}
return v4;
}

original_code:
ssize_t
Read( int fd, void* buf, size_t n )
{
  int bytes_read;
again:
  if( (bytes_read = read(fd, buf, n)) < 0 )
  if( (*__errno_location ()) == 4 )
    goto again;
  else
    fatal_sys_exit( "read error" );
  return bytes_read;
}

canonical_original_code:
long Read(int fd, void *buf, unsigned long n)
{
  int bytes_read;
again:
  if( (bytes_read = read(fd, buf, n)) < 0 )
  if( (*__errno_location ()) == 4 )
    goto again;
  else
    fatal_sys_exit( "read error" );
  return bytes_read;
}

variable_types:
buf
void *

variable_types:
n
unsigned long


routine

repo: scoiatael/OpSysProgramming

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

if ( !a1 )
__assert_fail("barrier!=NULL", "10.c", 7u, "routine");
v1 = pthread_self();
printf(" thread id: %lld\n", v1);
if ( (unsigned int)(pthread_barrier_wait((pthread_barrier_t *)a1) + 1) > 1 )
puts("pthread_barrier_wait failed");
return 0LL;
}

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

if ( !a1 )
__assert_fail("barrier!=NULL", "10.c", 7u, "routine");
v1 = pthread_self();
printf(" thread id: %lld\n", v1);
if ( (unsigned int)(pthread_barrier_wait((pthread_barrier_t *)a1) + 1) > 1 )
puts("pthread_barrier_wait failed");
return 0LL;
}

original_code:
void* routine(void* barrier)
{
  ((void) sizeof ((barrier!=((void *)0)) ? 1 : 0), __extension__ ({ if (barrier!=((void *)0)) ; else __assert_fail ("barrier!=NULL", "10.c", 7, __extension__ __PRETTY_FUNCTION__); }));
  printf(" thread id: %lld\n", (long long int)pthread_self());
  int r;
  r = pthread_barrier_wait((pthread_barrier_t*) barrier);
  if(r != -1 && r != 0)
  {
    printf("pthread_barrier_wait failed\n");
  }
  return ((void *)0);
}

canonical_original_code:
void *routine(void *barrier)
{
  ((void) sizeof ((barrier!=((void *)0)) ? 1 : 0), __extension__ ({ if (barrier!=((void *)0)) ; else __assert_fail ("barrier!=NULL", "10.c", 7, __extension__ __PRETTY_FUNCTION__); }));
  printf(" thread id: %lld\n", (long long)pthread_self());
  int r;
  r = pthread_barrier_wait((union pthread_barrier_t *) barrier);
  if(r != -1 && r != 0)
  {
    printf("pthread_barrier_wait failed\n");
  }
  return ((void *)0);
}

variable_types:
barrier
void *

variable_types: r int

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbp
unsigned int i; // ebx
unsigned int v5; // eax
__int64 v7; // [rsp+0h] [rbp-98h] BYREF
pthread_barrier_t barrier; // [rsp+20h] [rbp-78h] BYREF
char s[88]; // [rsp+40h] [rbp-58h] BYREF

pthread_barrier_init(&barrier, 0LL, 5u);
v3 = (pthread_t *)&v7;
for ( i = 0; i != 4; ++i )
{
sprintf(s, "thread nr %d creation failed", i);
if ( pthread_create(v3, 0LL, routine, &barrier) )
perror(s);
++v3;
}
v5 = getpid();
sprintf(s, "ps -T -%d", v5);
system(s);
pthread_barrier_wait(&barrier);
return 0;
}

original_code:
int main(void)
{
  char str[64];
  pthread_barrier_t barrier;
  pthread_barrier_init(&barrier, ((void *)0), 4 +1);
  pthread_t threads[4];
  for (int i = 0; i < 4; i++) {
    sprintf(str, "thread nr %d creation failed", i);
    { if(pthread_create(&threads[i],((void *)0),&routine, (void*) &barrier) != 0) { perror(str); } };
  }
  sprintf(str, "ps -T -%d", getpid());
  system(str);
  pthread_barrier_wait(&barrier);
  return 0;
}

canonical_original_code:
int main()
{
  char str[64];
  union pthread_barrier_t barrier;
  pthread_barrier_init(&barrier, ((void *)0), 4 +1);
  unsigned long threads[4];
  for (int i = 0; i < 4; i++) {
    sprintf(str, "thread nr %d creation failed", i);
    { if(pthread_create(&threads[i],((void *)0),&routine, (void *) &barrier) != 0) { perror(str); } };
  }
  sprintf(str, "ps -T -%d", getpid());
  system(str);
  pthread_barrier_wait(&barrier);
  return 0;
}

variable_types:
str
char [64]

variable_types: union pthread_barrier_t { char __size[32]; long __align; }

variable_types:
threads
unsigned long [4]

variable_types: i int


decompiled_code:
int atexit_function()
{
return printf("pid %d: atexit function called.\n", (unsigned int)pid);
}

canonical_decompiled_code:
int func7()
{
return printf("pid %d: atexit function called.\n", (unsigned int)pid);
}

original_code:
void atexit_function()
{
  printf("pid %d: atexit function called.\n", pid);
}


desc

decompiled_code:
__int64 desc()
{
puts(
"./5 { help | signal | exit {VAL{ | _exit {VAL} | pause | VAL }\n"
" VAL specifies value returned by program with exit/_exit/return");
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
puts(
"./5 { help | signal | exit {VAL{ | _exit {VAL} | pause | VAL }\n"
" VAL specifies value returned by program with exit/_exit/return");
return 1LL;
}

original_code:
int desc()
{
  printf("./5 { help | signal | exit {VAL{ | _exit {VAL} | pause | VAL }\n VAL specifies value returned by program with exit/_exit/return\n");
  return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
const char *v8; // rdi
__int64 v9; // rcx
int v10; // ebx
__pid_t v11; // eax
int v12; // ebx
const char *v13; // rbx
int v14; // eax
int v15; // eax

pid = getpid();
v5 = argc == 0;
v6 = argc == 1;
if ( argc <= 1 )
goto LABEL_31;
v7 = argv[1];
v8 = "help";
v9 = 5LL;
do
{
if ( !v9 )
break;
v5 = *v7 < (unsigned int)*v8;
v6 = *v7++ == *v8++;
--v9;
}
while ( v6 );
v10 = (char)((!v5 && !v6) - v5);
if ( (!v5 && !v6) == v5 )
{
desc(v8, v7);
}
else
{
LABEL_31:
if ( (unsigned int)atexit(atexit_function) )
perror("atexit failed");
v11 = fork();
v12 = v11;
if ( v11 == -1 )
{
perror("fork failed");
}
else if ( v11 > 0 )
{
printf("ppid: %d, child id:%d\n", (unsigned int)pid, (unsigned int)v11);
pid = v12;
}
if ( argc <= 1 )
{
v10 = 0;
}
else
{
v13 = argv[1];
if ( !strcmp(v13, "abort") )
abort();
v14 = strcmp(v13, "exit");
if ( !v14 )
{
if ( argc > 2 )
v14 = atoi(argv[2]);
exit(v14);
}
v15 = strcmp(v13, "_exit");
if ( !v15 )
{
if ( argc > 2 )
v15 = atoi(argv[2]);
_exit(v15);
}
if ( !strcmp(v13, "signal") )
pause();
v10 = atoi(argv[1]);
}
}
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
const char *v8; // rdi
__int64 v9; // rcx
int v10; // ebx
__pid_t v11; // eax
int v12; // ebx
const char *v13; // rbx
int v14; // eax
int v15; // eax

pid = getpid();
v5 = argc == 0;
v6 = argc == 1;
if ( argc <= 1 )
goto LABEL_31;
v7 = argv[1];
v8 = "help";
v9 = 5LL;
do
{
if ( !v9 )
break;
v5 = *v7 < (unsigned int)*v8;
v6 = *v7++ == *v8++;
--v9;
}
while ( v6 );
v10 = (char)((!v5 && !v6) - v5);
if ( (!v5 && !v6) == v5 )
{
func8(v8, v7);
}
else
{
LABEL_31:
if ( (unsigned int)func11(atexit_function) )
perror("atexit failed");
v11 = fork();
v12 = v11;
if ( v11 == -1 )
{
perror("fork failed");
}
else if ( v11 > 0 )
{
printf("ppid: %d, child id:%d\n", (unsigned int)pid, (unsigned int)v11);
pid = v12;
}
if ( argc <= 1 )
{
v10 = 0;
}
else
{
v13 = argv[1];
if ( !strcmp(v13, "abort") )
abort();
v14 = strcmp(v13, "exit");
if ( !v14 )
{
if ( argc > 2 )
v14 = atoi(argv[2]);
exit(v14);
}
v15 = strcmp(v13, "_exit");
if ( !v15 )
{
if ( argc > 2 )
v15 = atoi(argv[2]);
_exit(v15);
}
if ( !strcmp(v13, "signal") )
pause();
v10 = atoi(argv[1]);
}
}
return v10;
}

original_code:
int main(int argc, const char *argv[])
{
  pid = getpid();
  if(argc > 1) { if(strcmp(argv[1],"help")==0) {desc(); return 0;}; }
  { if(atexit(&atexit_function) != 0) { perror("atexit failed"); } };
  pid_t p;
  { { if((p=fork()) == -1) { perror("fork failed"); } } };
  if(p > 0) {
    printf("ppid: %d, child id:%d\n", pid, p);
    pid = p;
  }
  if(argc>1) {
    if(strcmp(argv[1],"abort")==0) {abort();};
    if(strcmp(argv[1],"exit")==0) {int ret = 0; if (argc > 2) { ret = atoi(argv[2]); } exit(ret);};
    if(strcmp(argv[1],"_exit")==0) {int ret = 0; if (argc > 2) { ret = atoi(argv[2]); } _exit(ret);};
    if(strcmp(argv[1],"signal")==0) {pause();};
  }
  int ret = 0;
  if(argc > 1) {
    ret = atoi(argv[1]);
  }
  return ret;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  pid = getpid();
  if(argc > 1) { if(strcmp(argv[1],"help")==0) {desc(); return 0;}; }
  { if(atexit(&atexit_function) != 0) { perror("atexit failed"); } };
  int p;
  { { if((p=fork()) == -1) { perror("fork failed"); } } };
  if(p > 0) {
    printf("ppid: %d, child id:%d\n", pid, p);
    pid = p;
  }
  if(argc>1) {
    if(strcmp(argv[1],"abort")==0) {abort();};
    if(strcmp(argv[1],"exit")==0) {int ret = 0; if (argc > 2) { ret = atoi(argv[2]); } exit(ret);};
    if(strcmp(argv[1],"_exit")==0) {int ret = 0; if (argc > 2) { ret = atoi(argv[2]); } _exit(ret);};
    if(strcmp(argv[1],"signal")==0) {pause();};
  }
  int ret = 0;
  if(argc > 1) {
    ret = atoi(argv[1]);
  }
  return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: p int

variable_types: ret int


decompiled_code:
int printEd_Wd()
{
char *v0; // rbx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

v0 = getenv("EDITOR");
if ( !v0 )
perror("getenv failed");
printf(" EDITOR=%s\n", v0);
if ( !getcwd(v2, 0x400uLL) )
perror("getcwd failed");
return printf(" cwd=%s\n", v2);
}

canonical_decompiled_code:
int func7()
{
char *v0; // rbx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

v0 = getenv("EDITOR");
if ( !v0 )
perror("getenv failed");
printf(" EDITOR=%s\n", v0);
if ( !getcwd(v2, 0x400uLL) )
perror("getcwd failed");
return printf(" cwd=%s\n", v2);
}

original_code:
void printEd_Wd()
{
  char* bufE = getenv("EDITOR");
  { if(bufE==((void *)0)) { perror("getenv failed"); } };
  printf(" EDITOR=%s\n", bufE);
  char bufCWD[1024];
  { if(getcwd(bufCWD, 1024)==((void *)0)) { perror("getcwd failed"); } };
  printf(" cwd=%s\n", bufCWD);
}

canonical_original_code:
void printEd_Wd()
{
  char *bufE = getenv("EDITOR");
  { if(bufE==((void *)0)) { perror("getenv failed"); } };
  printf(" EDITOR=%s\n", bufE);
  char bufCWD[1024];
  { if(getcwd(bufCWD, 1024)==((void *)0)) { perror("getcwd failed"); } };
  printf(" cwd=%s\n", bufCWD);
}

variable_types:
bufE
char *

variable_types:
bufCWD
char [1024]


funPEW

decompiled_code:
int __fastcall funPEW(int a1)
{
int result; // eax

if ( a1 == 1 )
result = printEd_Wd();
else
result = puts("Error");
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
int result; // eax

if ( a1 == 1 )
result = func7();
else
result = puts("Error");
return result;
}

original_code:
void funPEW(int sig)
{
  if(sig==1)
    printEd_Wd();
  else
    printf("Error\n");
}

variable_types: sig int


decompiled_code:
int __fastcall print_env(int a1, const char **a2, const char **a3)
{
const char **v4; // rbx
const char *v5; // rsi
const char **v6; // rbp

printf("%s args and environment:\n", *a2);
if ( a1 > 1 )
{
v4 = a2 + 1;
do
printf(" %s\n", *v4++);
while ( v4 != &a2[(unsigned int)(a1 - 2) + 2] );
}
v5 = *a3;
if ( *a3 )
{
v6 = a3 + 1;
do
{
printf(" %s \n", v5);
v5 = *v6++;
}
while ( v5 );
}
return printEd_Wd();
}

canonical_decompiled_code:
int __fastcall func9(int a1, const char **a2, const char **a3)
{
const char **v4; // rbx
const char *v5; // rsi
const char **v6; // rbp

printf("%s args and environment:\n", *a2);
if ( a1 > 1 )
{
v4 = a2 + 1;
do
printf(" %s\n", *v4++);
while ( v4 != &a2[(unsigned int)(a1 - 2) + 2] );
}
v5 = *a3;
if ( *a3 )
{
v6 = a3 + 1;
do
{
printf(" %s \n", v5);
v5 = *v6++;
}
while ( v5 );
}
return func7();
}

original_code:
void print_env(int argc, char* argv[], char* envp[])
{
  printf("%s args and environment:\n", argv[0]);
  for(int i=1; i< argc; i++) {
    printf(" %s\n", argv[i]);
  }
  for(int i=0; envp[i] != ((void *)0); i++) {
    printf(" %s \n", envp[i]);
  }
  printEd_Wd();
}

canonical_original_code:
void print_env(int argc, char *argv[], char *envp[])
{
  printf("%s args and environment:\n", argv[0]);
  for(int i = 1; i< argc; i++) {
    printf(" %s\n", argv[i]);
  }
  for(int i = 0; envp[i] != ((void *)0); i++) {
    printf(" %s \n", envp[i]);
  }
  printEd_Wd();
}

variable_types:
envp
char *[]


decompiled_code:
void __fastcall setEd_Wd(char *value, char *path)
{
if ( setenv("EDITOR", value, 1) == -1 )
perror("setenv failed");
if ( chdir(path) == -1 )
perror("chdir failed");
}

canonical_decompiled_code:
void __fastcall func10(char *value, char *path)
{
if ( setenv("EDITOR", value, 1) == -1 )
perror("setenv failed");
if ( chdir(path) == -1 )
perror("chdir failed");
}

original_code:
void setEd_Wd(const char* Ed, const char* Wd)
{
  { { if((setenv("EDITOR",Ed,1)) == -1) { perror("setenv failed"); } } };
  { { if((chdir(Wd)) == -1) { perror("chdir failed"); } } };
}

canonical_original_code:
void setEd_Wd(char *Ed, char *Wd)
{
  { { if((setenv("EDITOR",Ed,1)) == -1) { perror("setenv failed"); } } };
  { { if((chdir(Wd)) == -1) { perror("chdir failed"); } } };
}

variable_types:
Ed
char *

variable_types:
Wd
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
__pid_t v4; // ebx
struct sigaction v6; // [rsp+0h] [rbp-A8h] BYREF

memset(&v6.sa_mask, 0, 0x90uLL);
v6.sa_handler = (__sighandler_t)printEd_Wd;
if ( sigaction(1, &v6, 0LL) == -1 )
perror("signal set failed");
printEd_Wd();
setEd_Wd("vim", "/home");
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
perror("fork failed");
}
else if ( v3 )
{
if ( v3 > 0 )
{
system("sleep 1");
setEd_Wd("nano", "/");
printEd_Wd();
kill(v4, 1);
}
}
else
{
pause();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
__pid_t v4; // ebx
struct sigaction v6; // [rsp+0h] [rbp-A8h] BYREF

memset(&v6.sa_mask, 0, 0x90uLL);
v6.sa_handler = (__sighandler_t)printEd_Wd;
if ( sigaction(1, &v6, 0LL) == -1 )
perror("signal set failed");
func7();
func10("vim", "/home");
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
perror("fork failed");
}
else if ( v3 )
{
if ( v3 > 0 )
{
system("sleep 1");
func10("nano", "/");
func7();
kill(v4, 1);
}
}
else
{
pause();
}
return 0;
}

original_code:
int main(void)
{
  struct sigaction act;
  memset(&act, 0, sizeof(act));
  act.__sigaction_handler.sa_handler=&printEd_Wd;
  { { if((sigaction(1,&act,((void *)0))) == -1) { perror("signal set failed"); } } };;
  printEd_Wd();
  setEd_Wd("vim","/home");
  pid_t p;
  { { if((p=fork()) == -1) { perror("fork failed"); } } };
  if(p==0){
    pause();
  } else if(p>0){
    system("sleep 1");
    setEd_Wd("nano","/");
    printEd_Wd();
    kill(p,1);
  }
  return 0;
}

canonical_original_code:
int main()
{
  struct sigaction act;
  memset(&act, 0, sizeof(act));
  act.__sigaction_handler.sa_handler=&printEd_Wd;
  { { if((sigaction(1,&act,((void *)0))) == -1) { perror("signal set failed"); } } };;
  printEd_Wd();
  setEd_Wd("vim","/home");
  int p;
  { { if((p=fork()) == -1) { perror("fork failed"); } } };
  if(p==0){
    pause();
  } else if(p>0){
    system("sleep 1");
    setEd_Wd("nano","/");
    printEd_Wd();
    kill(p,1);
  }
  return 0;
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }


badArgs

decompiled_code:
__int64 badArgs()
{
puts("Usage: <command> arg where arg is either no-limit or limited");
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
puts("Usage: <command> arg where arg is either no-limit or limited");
return 1LL;
}

original_code:
int badArgs()
{
  printf("Usage: <command> arg where arg is either no-limit or limited\n");
  return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
const char *v4; // rdi
__int64 v5; // rdx
int v6; // ebp
__pid_t v7; // er13
__int64 v8; // r12
int v9; // ebx
__pid_t v10; // eax
struct rlimit v12[4]; // [rsp+0h] [rbp-A8h] BYREF
char s[104]; // [rsp+40h] [rbp-68h] BYREF

if ( argc == 1 )
return badArgs(1, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "limited") )
{
v12[0].rlim_cur = 50LL;
v12[0].rlim_max = 50LL;
if ( setrlimit(__RLIMIT_NPROC, v12) == -1 )
perror("setrlimit failed");
}
else
{
v4 = v3;
if ( strcmp(v3, "no-limit") )
return badArgs(v4, "no-limit", v5);
}
if ( setpgid(0, 0) == -1 )
perror("setpgid failed ");
v7 = getpid();
v8 = (unsigned int)getpgid(0);
printf("PGID=%d\n", v8);
puts("forking..");
v9 = 0;
do
{
putchar(61);
fflush(_bss_start);
v10 = fork();
v6 = v10;
++v9;
}
while ( v9 <= 99 && v10 > 0 );
if ( v10 )
{
puts(" done.");
sprintf(s, "ps f -o pgrp,pid,command --ppid %d", (unsigned int)v8);
if ( system(s) == -1 )
perror("'system' call failed ");
if ( v6 == -1 )
{
sprintf((char *)v12, "Fork failed (created %d processes) ", (unsigned int)v9);
perror((const char *)v12);
}
else if ( system("sleep 5") == -1 )
{
perror("'system' call failed ");
}
killpg(v7, 2);
v6 = 0;
}
else
{
pause();
}
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
const char *v4; // rdi
__int64 v5; // rdx
int v6; // ebp
__pid_t v7; // er13
__int64 v8; // r12
int v9; // ebx
__pid_t v10; // eax
struct rlimit v12[4]; // [rsp+0h] [rbp-A8h] BYREF
char s[104]; // [rsp+40h] [rbp-68h] BYREF

if ( argc == 1 )
return func7(1, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "limited") )
{
v12[0].rlim_cur = 50LL;
v12[0].rlim_max = 50LL;
if ( setrlimit(__RLIMIT_NPROC, v12) == -1 )
perror("setrlimit failed");
}
else
{
v4 = v3;
if ( strcmp(v3, "no-limit") )
return func7(v4, "no-limit", v5);
}
if ( setpgid(0, 0) == -1 )
perror("setpgid failed ");
v7 = getpid();
v8 = (unsigned int)getpgid(0);
printf("PGID=%d\n", v8);
puts("forking..");
v9 = 0;
do
{
putchar(61);
fflush(_bss_start);
v10 = fork();
v6 = v10;
++v9;
}
while ( v9 <= 99 && v10 > 0 );
if ( v10 )
{
puts(" done.");
sprintf(s, "ps f -o pgrp,pid,command --ppid %d", (unsigned int)v8);
if ( system(s) == -1 )
perror("'system' call failed ");
if ( v6 == -1 )
{
sprintf((char *)v12, "Fork failed (created %d processes) ", (unsigned int)v9);
perror((const char *)v12);
}
else if ( system("sleep 5") == -1 )
{
perror("'system' call failed ");
}
killpg(v7, 2);
v6 = 0;
}
else
{
pause();
}
return v6;
}

original_code:
int main(int argc, const char *argv[])
{
  if(argc == 1) {
    return badArgs();
  }
  int gdarg=0;
  if(strcmp(argv[1],"limited")==0)
  {
    gdarg++;
    struct rlimit limit;
    memset(&limit, 0, sizeof(limit));
    limit.rlim_cur=50;
    limit.rlim_max=50;
    { { if((setrlimit(__RLIMIT_NPROC, &limit)) == -1) { perror("setrlimit failed"); } } };
  }
  if(strcmp(argv[1],"no-limit")==0)
  {
    gdarg++;
  }
  if(gdarg==0)
  {
    return badArgs();
  }
  if( setpgid(0, 0) == -1)
    perror("setpgid failed ");
  pid_t pid = getpid();
  pid_t pgid = getpgid(0);
  printf("PGID=%d\n", pgid);
  int parent = 1;
  printf("forking..\n");
  int i;
  for(i = 0; (i<100) && (parent > 0); i++) {
    putchar('=');
    fflush(stdout);
    parent = fork();
  }
  if(parent == 0) {
    pause();
    return 0;
  }
  printf(" done.\n");
  char cmd[64];
  sprintf(cmd,"ps f -o pgrp,pid,command --ppid %d", pgid);
  { { if((system(cmd)) == -1) { perror("'system' call failed "); } } };;
  if(parent == -1) {
    char desc[64];
    sprintf(desc, "Fork failed (created %d processes) ", i);
    perror(desc);
  } else {
    { { if((system("sleep 5")) == -1) { perror("'system' call failed "); } } };;
  }
  killpg(pid,2);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if(argc == 1) {
    return badArgs();
  }
  int gdarg = 0;
  if(strcmp(argv[1],"limited")==0)
  {
    gdarg++;
    struct rlimit limit;
    memset(&limit, 0, sizeof(limit));
    limit.rlim_cur=50;
    limit.rlim_max=50;
    { { if((setrlimit(__RLIMIT_NPROC, &limit)) == -1) { perror("setrlimit failed"); } } };
  }
  if(strcmp(argv[1],"no-limit")==0)
  {
    gdarg++;
  }
  if(gdarg==0)
  {
    return badArgs();
  }
  if( setpgid(0, 0) == -1)
    perror("setpgid failed ");
  int pid = getpid();
  int pgid = getpgid(0);
  printf("PGID=%d\n", pgid);
  int parent = 1;
  printf("forking..\n");
  int i;
  for(i = 0; (i<100) && (parent > 0); i++) {
    putchar('=');
    fflush(stdout);
    parent = fork();
  }
  if(parent == 0) {
    pause();
    return 0;
  }
  printf(" done.\n");
  char cmd[64];
  sprintf(cmd,"ps f -o pgrp,pid,command --ppid %d", pgid);
  { { if((system(cmd)) == -1) { perror("'system' call failed "); } } };;
  if(parent == -1) {
    char desc[64];
    sprintf(desc, "Fork failed (created %d processes) ", i);
    perror(desc);
  } else {
    { { if((system("sleep 5")) == -1) { perror("'system' call failed "); } } };;
  }
  killpg(pid,2);
  return 0;
}

variable_types: gdarg int

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types: pid int

variable_types: pgid int

variable_types: parent int

variable_types:
cmd
char [64]

variable_types:
desc
char [64]


id

decompiled_code:
__int64 id()
{
__uid_t v0; // er12
struct passwd *v1; // rbx
__gid_t v2; // er13
void *v3; // rbp
struct group *v4; // rax
__int64 v5; // rbx
struct group *v6; // rax
int ngroups[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = getuid();
v1 = getpwuid(v0);
v2 = getgid();
ngroups[0] = 0;
v3 = malloc(0x80uLL);
if ( getgrouplist(v1->pw_name, v1->pw_gid, (__gid_t *)v3, ngroups) == -1 )
{
free(v3);
v3 = malloc(4LL * (ngroups[0] + 1));
getgrouplist(v1->pw_name, v1->pw_gid, (__gid_t *)v3, ngroups);
}
v4 = getgrgid(v2);
printf("user=%s(%d) grp=%s(%d)\ngroups= ", v1->pw_name, v0, v4->gr_name, v2);
if ( ngroups[0] > 0 )
{
v5 = 0LL;
do
{
v6 = getgrgid(*((_DWORD *)v3 + v5));
printf("%s(%d) ", v6->gr_name, v6->gr_gid);
++v5;
}
while ( ngroups[0] > (int)v5 );
}
putchar(10);
free(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
__uid_t v0; // er12
struct passwd *v1; // rbx
__gid_t v2; // er13
void *v3; // rbp
struct group *v4; // rax
__int64 v5; // rbx
struct group *v6; // rax
int ngroups[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = getuid();
v1 = getpwuid(v0);
v2 = getgid();
ngroups[0] = 0;
v3 = malloc(0x80uLL);
if ( getgrouplist(v1->pw_name, v1->pw_gid, (__gid_t *)v3, ngroups) == -1 )
{
free(v3);
v3 = malloc(4LL * (ngroups[0] + 1));
getgrouplist(v1->pw_name, v1->pw_gid, (__gid_t *)v3, ngroups);
}
v4 = getgrgid(v2);
printf("user=%s(%d) grp=%s(%d)\ngroups= ", v1->pw_name, v0, v4->gr_name, v2);
if ( ngroups[0] > 0 )
{
v5 = 0LL;
do
{
v6 = getgrgid(*((_DWORD *)v3 + v5));
printf("%s(%d) ", v6->gr_name, v6->gr_gid);
++v5;
}
while ( ngroups[0] > (int)v5 );
}
putchar(10);
free(v3);
return 0LL;
}

original_code:
int id()
{
  uid_t uid = getuid();
  struct passwd* pwuid = getpwuid(uid);
  gid_t gid = getgid();
  int grpNr=0;
  gid_t* groups = malloc(32*sizeof(gid));;
  int r = getgrouplist(pwuid->pw_name,pwuid->pw_gid, groups, &grpNr);
  if(r==-1) {
    free(groups);
    groups = malloc((grpNr+1) * sizeof(gid_t));
    r = getgrouplist(pwuid->pw_name,pwuid->pw_gid, groups, &grpNr);
  }
  struct group* grp = getgrgid(gid);
  printf("user=%s(%d) grp=%s(%d)\ngroups= ", pwuid->pw_name, uid, grp->gr_name, gid);
  for(int i=0; i< grpNr;i++) {
    grp = getgrgid(groups[i]);
    printf("%s(%d) ", grp->gr_name, grp->gr_gid);
  }
  putchar('\n');
  free(groups);
  return 0;
}

canonical_original_code:
int id()
{
  unsigned int uid = getuid();
  struct passwd *pwuid = getpwuid(uid);
  unsigned int gid = getgid();
  int grpNr = 0;
  unsigned int *groups = malloc(32*sizeof(gid));;
  int r = getgrouplist(pwuid->pw_name,pwuid->pw_gid, groups, &grpNr);
  if(r==-1) {
    free(groups);
    groups = malloc((grpNr+1) * sizeof(gid_t));
    r = getgrouplist(pwuid->pw_name,pwuid->pw_gid, groups, &grpNr);
  }
  struct group *grp = getgrgid(gid);
  printf("user=%s(%d) grp=%s(%d)\ngroups= ", pwuid->pw_name, uid, grp->gr_name, gid);
  for(int i = 0; i< grpNr;i++) {
    grp = getgrgid(groups[i]);
    printf("%s(%d) ", grp->gr_name, grp->gr_gid);
  }
  putchar('\n');
  free(groups);
  return 0;
}

variable_types:
uid
unsigned int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
gid
unsigned int

variable_types: grpNr int

variable_types:
groups
unsigned int *

variable_types: r int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return id(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func7(argc, argv, envp);
}

original_code:
int main()
{
  return id();
}

canonical_original_code:
int main()
{
  return id();
}


decompiled_code:
__int64 __fastcall get1B(char *a1)
{
return (unsigned int)*a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
return (unsigned int)*a1;
}

original_code:
int get1B(char* mem)
{
  return (int) * mem;
}

canonical_original_code:
int get1B(char *mem)
{
  return (int) * mem;
}

variable_types:
mem
char *


decompiled_code:
__int64 __fastcall set1BTrue(_BYTE *a1)
{
*a1 = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
*a1 = 1;
return 1LL;
}

original_code:
int set1BTrue(char* mem)
{
  return (*mem = (1>0));
}

canonical_original_code:
int set1BTrue(char *mem)
{
  return (*mem = (1>0));
}


decompiled_code:
__int64 __fastcall set1BFalse(_BYTE *a1)
{
*a1 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
*a1 = 0;
return 0LL;
}

original_code:
int set1BFalse(char* mem)
{
  return (*mem = (1<0));
}

canonical_original_code:
int set1BFalse(char *mem)
{
  return (*mem = (1<0));
}


printPid

decompiled_code:
void __noreturn printPid()
{
fprintf(stderr, "-->pid %d closing\n", (unsigned int)pid);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3()
{
fprintf(stderr, "-->pid %d closing\n", (unsigned int)pid);
exit(1);
}

original_code:
void printPid(int sig __attribute__((unused)))
{
  fprintf(stderr, "-->pid %d closing\n", pid);
  _exit(1);
}

canonical_original_code:
void printPid(int sig)
{
  fprintf(stderr, "-->pid %d closing\n", pid);
  _exit(1);
}

variable_types: sig int


delay

decompiled_code:
void __fastcall delay(int a1, int a2)
{
int v2; // edx
struct timespec v3[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = a2 + rand() % (a1 - a2);
v3[0].tv_nsec = v2 % 1000000000;
v3[0].tv_sec = v2 / 1000000000;
if ( nanosleep(v3, v3) == -1 )
perror("nanosleep");
}

canonical_decompiled_code:
void __fastcall func4(int a1, int a2)
{
int v2; // edx
struct timespec v3[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = a2 + rand() % (a1 - a2);
v3[0].tv_nsec = v2 % 1000000000;
v3[0].tv_sec = v2 / 1000000000;
if ( nanosleep(v3, v3) == -1 )
perror("nanosleep");
}

original_code:
void delay(int r, int m)
{
  struct timespec nSleepTime;
  memset(&nSleepTime, 0, sizeof(struct timespec));
  int t = rand() % (r-m) + m;
  nSleepTime.tv_nsec = t % (1000000000);
  nSleepTime.tv_sec = t / (1000000000);
  { { if((nanosleep(&nSleepTime, &nSleepTime)) == -1) { perror("nanosleep"); } } };
}

variable_types: m int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: t int


qinit

decompiled_code:
__int64 __fastcall qinit(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // er14
int v3; // er13
int v4; // er12
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = pthread_mutexattr_init(&attr);
if ( v1 == -1 )
perror("attr init");
v2 = pthread_mutexattr_setpshared(&attr, 1);
if ( v2 == -1 )
perror("attr set");
v3 = pthread_mutex_init(mutex, &attr);
if ( v3 == -1 )
perror("mutex init failed");
v4 = sem_init((sem_t *)(&mutex[1].__align + 1), 1, 0);
if ( v4 == -1 )
perror("sem init failed");
mutex[1].__lock = 0;
return v4 | v3 | v2 | (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // er14
int v3; // er13
int v4; // er12
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = pthread_mutexattr_init(&attr);
if ( v1 == -1 )
perror("attr init");
v2 = pthread_mutexattr_setpshared(&attr, 1);
if ( v2 == -1 )
perror("attr set");
v3 = pthread_mutex_init(mutex, &attr);
if ( v3 == -1 )
perror("mutex init failed");
v4 = sem_init((sem_t *)(&mutex[1].__align + 1), 1, 0);
if ( v4 == -1 )
perror("sem init failed");
mutex[1].__lock = 0;
return v4 | v3 | v2 | (unsigned int)v1;
}

original_code:
int qinit(queue_t* q)
{
  int r1, r2, r3, r4;
  pthread_mutexattr_t p;
  { { if((r1 = pthread_mutexattr_init(&p)) == -1) { perror("attr init"); } } };
  { { if((r2 = pthread_mutexattr_setpshared(&p, PTHREAD_PROCESS_SHARED)) == -1) { perror("attr set"); } } };
  { { if((r3 = pthread_mutex_init(&q->prot, &p)) == -1) { perror("mutex init failed"); } } };
  { { if((r4 = sem_init(&q->sem, 1, 0)) == -1) { perror("sem init failed"); } } };
  q->count = 0;
  return (r1 | r2 | r3 | r4);
}

canonical_original_code:
int qinit(struct queue *q)
{
  int r1; int r2; int r3; int r4;
  union pthread_mutexattr_t p;
  { { if((r1 = pthread_mutexattr_init(&p)) == -1) { perror("attr init"); } } };
  { { if((r2 = pthread_mutexattr_setpshared(&p, PTHREAD_PROCESS_SHARED)) == -1) { perror("attr set"); } } };
  { { if((r3 = pthread_mutex_init(&q->prot, &p)) == -1) { perror("mutex init failed"); } } };
  { { if((r4 = sem_init(&q->sem, 1, 0)) == -1) { perror("sem init failed"); } } };
  q->count = 0;
  return (r1 | r2 | r3 | r4);
}

variable_types: struct queue { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } prot; int count; union sem_t { char __size[32]; long __align; } sem; } *

variable_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: struct queue { union pthread_mutex_t prot; int count; union sem_t sem; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


qrelease

decompiled_code:
__int64 __fastcall qrelease(pthread_mutex_t *mutex, char a2)
{
int v2; // er14
int v3; // er15
int v4; // ebx
int v5; // eax

if ( a2 )
{
v4 = mutex[1].__lock;
if ( v4 > 0 )
goto LABEL_11;
return v3 | (unsigned int)v2;
}
v3 = pthread_mutex_lock(mutex);
if ( v3 == -1 )
perror("qmutex lck");
v4 = mutex[1].__lock;
if ( v4 <= 0 )
{
LABEL_7:
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
return v3 | (unsigned int)v2;
}
LABEL_11:
while ( 1 )
{
v5 = sem_post((sem_t *)(&mutex[1].__align + 1));
if ( v5 == -1 )
break;
if ( --v4 <= 0 || v5 )
goto LABEL_13;
}
perror("qmutex pst");
LABEL_13:
if ( !a2 )
goto LABEL_7;
return v3 | (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(pthread_mutex_t *mutex, char a2)
{
int v2; // er14
int v3; // er15
int v4; // ebx
int v5; // eax

if ( a2 )
{
v4 = mutex[1].__lock;
if ( v4 > 0 )
goto LABEL_11;
return v3 | (unsigned int)v2;
}
v3 = pthread_mutex_lock(mutex);
if ( v3 == -1 )
perror("qmutex lck");
v4 = mutex[1].__lock;
if ( v4 <= 0 )
{
LABEL_7:
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
return v3 | (unsigned int)v2;
}
LABEL_11:
while ( 1 )
{
v5 = sem_post((sem_t *)(&mutex[1].__align + 1));
if ( v5 == -1 )
break;
if ( --v4 <= 0 || v5 )
goto LABEL_13;
}
perror("qmutex pst");
LABEL_13:
if ( !a2 )
goto LABEL_7;
return v3 | (unsigned int)v2;
}

original_code:
int qrelease(queue_t* q, char has_lock)
{
  int r1, r2, r3 = 0;
  if(!has_lock) {
    { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  }
  for(int i = q->count ; i > 0 && r3 == 0; i = i - 1) {
    { { if((r3 = sem_post(&q->sem)) == -1) { perror("qmutex pst"); } } };
  }
  if(!has_lock) {
    { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  }
  return (r1 | r2);
}

canonical_original_code:
int qrelease(struct queue *q, char has_lock)
{
  int r1; int r2; int r3 = 0;
  if(!has_lock) {
    { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  }
  for(int i = q->count; i > 0 && r3 == 0; i = i - 1) {
    { { if((r3 = sem_post(&q->sem)) == -1) { perror("qmutex pst"); } } };
  }
  if(!has_lock) {
    { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  }
  return (r1 | r2);
}

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

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


qdestroy

decompiled_code:
__int64 __fastcall qdestroy(pthread_mutex_t *mutex)
{
unsigned int v1; // ebx
int v2; // er12
int v3; // ebp

v1 = qrelease(mutex, 0);
v2 = pthread_mutex_destroy(mutex);
if ( v2 == -1 )
perror("qmtx dstr");
v3 = sem_destroy((sem_t *)(&mutex[1].__align + 1));
if ( v3 == -1 )
perror("qsem dstr");
return v3 | v2 | v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(pthread_mutex_t *mutex)
{
unsigned int v1; // ebx
int v2; // er12
int v3; // ebp

v1 = func6(mutex, 0);
v2 = pthread_mutex_destroy(mutex);
if ( v2 == -1 )
perror("qmtx dstr");
v3 = sem_destroy((sem_t *)(&mutex[1].__align + 1));
if ( v3 == -1 )
perror("qsem dstr");
return v3 | v2 | v1;
}

original_code:
int qdestroy(queue_t* q)
{
  int r1, r2,r3;
  r3 = qrelease(q, (1<0));
  { { if((r1 = pthread_mutex_destroy(&q->prot)) == -1) { perror("qmtx dstr"); } } };
  { { if((r2 = sem_destroy(&q->sem)) == -1) { perror("qsem dstr"); } } };
  return (r1 | r2 | r3);
}

canonical_original_code:
int qdestroy(struct queue *q)
{
  int r1; int r2; int r3;
  r3 = qrelease(q, (1<0));
  { { if((r1 = pthread_mutex_destroy(&q->prot)) == -1) { perror("qmtx dstr"); } } };
  { { if((r2 = sem_destroy(&q->sem)) == -1) { perror("qsem dstr"); } } };
  return (r1 | r2 | r3);
}


qwait

decompiled_code:
__int64 __fastcall qwait(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // er14
int v3; // er13
int v4; // er12
int v5; // ebp

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
++mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
v3 = sem_wait((sem_t *)(&mutex[1].__align + 1));
if ( v3 == -1 )
perror("qsem wt");
v4 = pthread_mutex_lock(mutex);
if ( v4 == -1 )
perror("qmutex lck");
--mutex[1].__lock;
v5 = pthread_mutex_unlock(mutex);
if ( v5 == -1 )
perror("qmutex ulck");
return v5 | v4 | v3 | v2 | (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // er14
int v3; // er13
int v4; // er12
int v5; // ebp

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
++mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
v3 = sem_wait((sem_t *)(&mutex[1].__align + 1));
if ( v3 == -1 )
perror("qsem wt");
v4 = pthread_mutex_lock(mutex);
if ( v4 == -1 )
perror("qmutex lck");
--mutex[1].__lock;
v5 = pthread_mutex_unlock(mutex);
if ( v5 == -1 )
perror("qmutex ulck");
return v5 | v4 | v3 | v2 | (unsigned int)v1;
}

original_code:
int qwait(queue_t* q)
{
  int r1, r2, r3, r4, r5;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count++;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  { { if((r3 = sem_wait(&q->sem)) == -1) { perror("qsem wt"); } } };
  { { if((r4 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count = q->count - 1;
  { { if((r5 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2 | r3 | r4 | r5);
}

canonical_original_code:
int qwait(struct queue *q)
{
  int r1; int r2; int r3; int r4; int r5;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count++;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  { { if((r3 = sem_wait(&q->sem)) == -1) { perror("qsem wt"); } } };
  { { if((r4 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count = q->count - 1;
  { { if((r5 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2 | r3 | r4 | r5);
}


qincr

decompiled_code:
__int64 __fastcall qincr(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // ebp

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
++mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
return v2 | (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // ebp

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
++mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
return v2 | (unsigned int)v1;
}

original_code:
int qincr(queue_t* q)
{
  int r1, r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count++;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2);
}

canonical_original_code:
int qincr(struct queue *q)
{
  int r1; int r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count++;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2);
}


qdecr

decompiled_code:
__int64 __fastcall qdecr(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // ebp

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
--mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
return v2 | (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // ebp

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
--mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
return v2 | (unsigned int)v1;
}

original_code:
int qdecr(queue_t* q)
{
  int r1, r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count = q->count - 1;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2);
}

canonical_original_code:
int qdecr(struct queue *q)
{
  int r1; int r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count = q->count - 1;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2);
}


decompiled_code:
__int64 __fastcall qget_count(pthread_mutex_t *mutex)
{
int v1; // ebx
unsigned int v2; // er12
int v3; // eax
int v4; // ebx

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
{
perror("qmutex lck");
if ( pthread_mutex_unlock(mutex) != -1 )
return (unsigned int)-1;
LABEL_8:
perror("qmutex ulck");
return (unsigned int)-1;
}
v2 = mutex[1].__lock;
v3 = pthread_mutex_unlock(mutex);
if ( v3 == -1 )
goto LABEL_8;
v4 = v3 | v1;
if ( v4 )
v2 = v4;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(pthread_mutex_t *mutex)
{
int v1; // ebx
unsigned int v2; // er12
int v3; // eax
int v4; // ebx

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
{
perror("qmutex lck");
if ( pthread_mutex_unlock(mutex) != -1 )
return (unsigned int)-1;
LABEL_8:
perror("qmutex ulck");
return (unsigned int)-1;
}
v2 = mutex[1].__lock;
v3 = pthread_mutex_unlock(mutex);
if ( v3 == -1 )
goto LABEL_8;
v4 = v3 | v1;
if ( v4 )
v2 = v4;
return v2;
}

original_code:
int qget_count(queue_t* q)
{
  int c, r1, r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  c = q->count;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  r1 = r1 | r2;
  return (r1 == 0) ? c : r1;
}

canonical_original_code:
int qget_count(struct queue *q)
{
  int c; int r1; int r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  c = q->count;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  r1 = r1 | r2;
  return (r1 == 0) ? c : r1;
}

variable_types: c int


qreset

decompiled_code:
__int64 __fastcall qreset(pthread_mutex_t *mutex, char a2)
{
int v2; // er13
int v3; // er14

if ( !a2 )
{
v3 = pthread_mutex_lock(mutex);
if ( v3 == -1 )
perror("qmutex lck");
}
while ( sem_trywait((sem_t *)(&mutex[1].__align + 1)) != -1 )
;
if ( !a2 )
{
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
}
return v3 | (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(pthread_mutex_t *mutex, char a2)
{
int v2; // er13
int v3; // er14

if ( !a2 )
{
v3 = pthread_mutex_lock(mutex);
if ( v3 == -1 )
perror("qmutex lck");
}
while ( sem_trywait((sem_t *)(&mutex[1].__align + 1)) != -1 )
;
if ( !a2 )
{
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror("qmutex ulck");
}
return v3 | (unsigned int)v2;
}

original_code:
int qreset(queue_t* q, char has_lock)
{
  int r1, r2, r3 = 0;
  if(!has_lock) {
    { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  }
  do {
    r3 = sem_trywait(&q->sem);
  } while(r3 != -1);
  if(!has_lock) {
    { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  }
  return (r1 | r2);
}

canonical_original_code:
int qreset(struct queue *q, char has_lock)
{
  int r1; int r2; int r3 = 0;
  if(!has_lock) {
    { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  }
  do {
    r3 = sem_trywait(&q->sem);
  } while(r3 != -1);
  if(!has_lock) {
    { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  }
  return (r1 | r2);
}


decompiled_code:
__int64 __fastcall protmem_init(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-1Ch] BYREF

if ( pthread_mutexattr_init(&attr) == -1 )
perror("attr init");
if ( pthread_mutexattr_setpshared(&attr, 1) == -1 )
perror("attr set");
v2 = pthread_mutex_init((pthread_mutex_t *)(a1 + 8), &attr);
if ( v2 == -1 )
perror("mutex init failed");
*(_QWORD *)a1 = a2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-1Ch] BYREF

if ( pthread_mutexattr_init(&attr) == -1 )
perror("attr init");
if ( pthread_mutexattr_setpshared(&attr, 1) == -1 )
perror("attr set");
v2 = pthread_mutex_init((pthread_mutex_t *)(a1 + 8), &attr);
if ( v2 == -1 )
perror("mutex init failed");
*(_QWORD *)a1 = a2;
return v2;
}

original_code:
int protmem_init(protmem_t* pr, char* m)
{
  int r1;
  pthread_mutexattr_t p;
  { { if((pthread_mutexattr_init(&p)) == -1) { perror("attr init"); } } };
  { { if((pthread_mutexattr_setpshared(&p, PTHREAD_PROCESS_SHARED)) == -1) { perror("attr set"); } } };
  { { if((r1 = pthread_mutex_init(&pr->prot, &p)) == -1) { perror("mutex init failed"); } } };
  pr->mem = m;
  return r1;
}

canonical_original_code:
int protmem_init(struct protmem *pr, char *m)
{
  int r1;
  union pthread_mutexattr_t p;
  { { if((pthread_mutexattr_init(&p)) == -1) { perror("attr init"); } } };
  { { if((pthread_mutexattr_setpshared(&p, PTHREAD_PROCESS_SHARED)) == -1) { perror("attr set"); } } };
  { { if((r1 = pthread_mutex_init(&pr->prot, &p)) == -1) { perror("mutex init failed"); } } };
  pr->mem = m;
  return r1;
}

variable_types: struct protmem { char *mem; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } prot; } *

variable_types:
m
char *

user_defined_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: struct protmem { char *mem; union pthread_mutex_t prot; }


decompiled_code:
__int64 __fastcall protmem_f(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
pthread_mutex_t *v2; // r13
unsigned int v3; // ebx
unsigned int v4; // ebp
int v5; // eax
int v6; // ebx

v2 = (pthread_mutex_t *)(a1 + 1);
v3 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 1));
if ( v3 == -1 )
{
perror("qmutex lck");
a2(*a1);
if ( pthread_mutex_unlock(v2) != -1 )
return v3;
LABEL_8:
perror("qmutex ulck");
return (unsigned int)-1;
}
v4 = ((__int64 (__fastcall *)(_QWORD))a2)(*a1);
v5 = pthread_mutex_unlock(v2);
if ( v5 == -1 )
goto LABEL_8;
v6 = v5 | v3;
if ( v6 )
v4 = v6;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
pthread_mutex_t *v2; // r13
unsigned int v3; // ebx
unsigned int v4; // ebp
int v5; // eax
int v6; // ebx

v2 = (pthread_mutex_t *)(a1 + 1);
v3 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 1));
if ( v3 == -1 )
{
perror("qmutex lck");
a2(*a1);
if ( pthread_mutex_unlock(v2) != -1 )
return v3;
LABEL_8:
perror("qmutex ulck");
return (unsigned int)-1;
}
v4 = ((__int64 (__fastcall *)(_QWORD))a2)(*a1);
v5 = pthread_mutex_unlock(v2);
if ( v5 == -1 )
goto LABEL_8;
v6 = v5 | v3;
if ( v6 )
v4 = v6;
return v4;
}

original_code:
int protmem_f(protmem_t* p, int (*f) (char*))
{
  int r, r1, r2;
  { { if((r1 = pthread_mutex_lock(&p->prot)) == -1) { perror("qmutex lck"); } } };
  r = (*f)(p->mem);
  { { if((r2 = pthread_mutex_unlock(&p->prot)) == -1) { perror("qmutex ulck"); } } };
  r1 = r1 | r2;
  return (r1 == 0) ? r : r1;
}

canonical_original_code:
int protmem_f(struct protmem *p, int (*f)(char *))
{
  int r; int r1; int r2;
  { { if((r1 = pthread_mutex_lock(&p->prot)) == -1) { perror("qmutex lck"); } } };
  r = (*f)(p->mem);
  { { if((r2 = pthread_mutex_unlock(&p->prot)) == -1) { perror("qmutex ulck"); } } };
  r1 = r1 | r2;
  return (r1 == 0) ? r : r1;
}

variable_types:
f
int (*)(char *)


decompiled_code:
__int64 __fastcall protmem_destroy(__int64 a1)
{
unsigned int v1; // ebx

v1 = pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
if ( v1 == -1 )
perror("protmem dstr");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
unsigned int v1; // ebx

v1 = pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
if ( v1 == -1 )
perror("protmem dstr");
return v1;
}

original_code:
int protmem_destroy(protmem_t* p)
{
  int r;
  { { if((r = pthread_mutex_destroy(&p->prot)) == -1) { perror("protmem dstr"); } } };
  return r;
}

canonical_original_code:
int protmem_destroy(struct protmem *p)
{
  int r;
  { { if((r = pthread_mutex_destroy(&p->prot)) == -1) { perror("protmem dstr"); } } };
  return r;
}


openSharedMem

decompiled_code:
__int64 __fastcall openSharedMem(char *name, unsigned int *a2, _BYTE *a3)
{
int v4; // eax
unsigned int v5; // ebx

v4 = shm_open(name, 194, 0x180u);
*a2 = v4;
if ( v4 == -1 )
{
v5 = -1;
if ( *_errno_location() == 17 )
{
if ( a3 )
*a3 = 1;
v5 = shm_open(name, 2, 0x180u);
*a2 = v5;
}
}
else
{
if ( a3 )
*a3 = 0;
v5 = *a2;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *name, unsigned int *a2, _BYTE *a3)
{
int v4; // eax
unsigned int v5; // ebx

v4 = shm_open(name, 194, 0x180u);
*a2 = v4;
if ( v4 == -1 )
{
v5 = -1;
if ( *_errno_location() == 17 )
{
if ( a3 )
*a3 = 1;
v5 = shm_open(name, 2, 0x180u);
*a2 = v5;
}
}
else
{
if ( a3 )
*a3 = 0;
v5 = *a2;
}
return v5;
}

original_code:
int openSharedMem(const char* name, int* fd, char* existed)
{
  int flags = 0200 | 0400;
  (*fd) = shm_open(name, 02 | 0100 | 0200, flags);
  if((*fd) == -1) {
    if((*__errno_location ()) == 17) {
      if(existed != ((void *)0)) {
        (*existed) = 1 > 0;
      }
      (*fd) = shm_open(name, 02, flags);
      return (*fd);
    } else {
      { { if((1 > 0) == -1) { perror("shm_open failed"); } } };
      return (*fd);
    }
  } else {
    if(existed != ((void *)0)) {
      (*existed) = 1 < 0;
    }
    return (*fd);
  }
}

canonical_original_code:
int openSharedMem(char *name, int *fd, char *existed)
{
  int flags = 0200 | 0400;
  (*fd) = shm_open(name, 02 | 0100 | 0200, flags);
  if((*fd) == -1) {
    if((*__errno_location ()) == 17) {
      if(existed != ((void *)0)) {
        (*existed) = 1 > 0;
      }
      (*fd) = shm_open(name, 02, flags);
      return (*fd);
    } else {
      { { if((1 > 0) == -1) { perror("shm_open failed"); } } };
      return (*fd);
    }
  } else {
    if(existed != ((void *)0)) {
      (*existed) = 1 < 0;
    }
    return (*fd);
  }
}

variable_types:
name
char *

variable_types:
fd
int *

variable_types:
existed
char *

variable_types: flags int


bopen

decompiled_code:
__int64 bopen()
{
int v0; // edx
__int64 result; // rax
char v2; // [rsp+Bh] [rbp-Dh] BYREF
unsigned int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = openSharedMem("/my_barrier", fd, &v2);
result = -1LL;
if ( v0 != -1 )
{
if ( v2 )
{
result = (__int64)mmap(0LL, 0x228uLL, 3, 1, fd[0], 0LL);
}
else
{
*_errno_location() = 2;
shm_unlink("/my_barrier");
result = -1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
int v0; // edx
__int64 result; // rax
char v2; // [rsp+Bh] [rbp-Dh] BYREF
unsigned int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = func16("/my_barrier", fd, &v2);
result = -1LL;
if ( v0 != -1 )
{
if ( v2 )
{
result = (__int64)mmap(0LL, 0x228uLL, 3, 1, fd[0], 0LL);
}
else
{
*_errno_location() = 2;
shm_unlink("/my_barrier");
result = -1LL;
}
}
return result;
}

original_code:
barrier_t* bopen()
{
  int fd;
  char existed;
  if(openSharedMem("/my_barrier", &fd, &existed) == -1) {
    return (barrier_t*) - 1;
  }
  if(!existed) {
    (*__errno_location ()) = 2;
    shm_unlink("/my_barrier");
    return (barrier_t*) - 1;
  }
  barrier_t *mem = (barrier_t*) mmap(((void *)0), sizeof(barrier_t), 0x1 | 0x2, 0x01, fd, 0);
  return mem;
}

canonical_original_code:
struct barrier *bopen()
{
  int fd;
  char existed;
  if(openSharedMem("/my_barrier", &fd, &existed) == -1) {
    return (struct barrier *) - 1;
  }
  if(!existed) {
    (*__errno_location ()) = 2;
    shm_unlink("/my_barrier");
    return (struct barrier *) - 1;
  }
  struct barrier *mem = (barrier_t*) mmap(((void *)0), sizeof(barrier_t), 0x1 | 0x2, 0x01, fd, 0);
  return mem;
}

variable_types: fd int

variable_types: existed char

variable_types: struct barrier { int max_val; char name[256]; char _m; struct protmem { char *mem; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } prot; } releasing; struct queue { union pthread_mutex_t prot; int count; union sem_t { char __size[32]; long __align; } sem; } entrance; struct queue exit; struct queue critical; } *

user_defined_types: struct barrier { int max_val; char name[256]; char _m; struct protmem releasing; struct queue entrance; struct queue exit; struct queue critical; }