decompiled_code:
int __fastcall copy_data(int a1)
{
pthread_t newthread; // [rsp+8h] [rbp-4030h] BYREF
int v3; // [rsp+10h] [rbp-4028h] BYREF
__int64 v4; // [rsp+14h] [rbp-4024h]
int arg[2055]; // [rsp+201Ch] [rbp-201Ch] BYREF

v3 = a1;
arg[1] = a1;
v4 = 1LL;
arg[0] = 0;
arg[2] = 0;
pthread_create(&newthread, 0LL, copy_data_one_direction, arg);
copy_data_one_direction(&v3);
return pthread_join(newthread, 0LL);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
pthread_t newthread; // [rsp+8h] [rbp-4030h] BYREF
int v3; // [rsp+10h] [rbp-4028h] BYREF
__int64 v4; // [rsp+14h] [rbp-4024h]
int arg[2055]; // [rsp+201Ch] [rbp-201Ch] BYREF

v3 = a1;
arg[1] = a1;
v4 = 1LL;
arg[0] = 0;
arg[2] = 0;
pthread_create(&newthread, 0LL, copy_data_one_direction, arg);
func0(&v3);
return pthread_join(newthread, 0LL);
}

original_code:
static void
copy_data (int s)
{
  pthread_t to_s;
  struct copy_state st[2];
  st[0].in = s;
  st[0].out = 1;
  st[0].error = 0;
  st[1].in = 0;
  st[1].out = s;
  st[1].error = 0;
  pthread_create (&to_s, ((void *)0), copy_data_one_direction, &st[1]);
  copy_data_one_direction (&st[0]);
  pthread_join (to_s, ((void *)0));
}

canonical_original_code:
static void copy_data(int s)
{
  unsigned long to_s;
  struct copy_state st[2];
  st[0].in = s;
  st[0].out = 1;
  st[0].error = 0;
  st[1].in = 0;
  st[1].out = s;
  st[1].error = 0;
  pthread_create (&to_s, ((void *)0), copy_data_one_direction, &st[1]);
  copy_data_one_direction (&st[0]);
  pthread_join (to_s, ((void *)0));
}

variable_types: struct copy_state { int in; int out; int error; char buf[8192]; } [2]


decompiled_code:
int __fastcall do_listen(struct sockaddr *addr, socklen_t a2)
{
char *v3; // r13
int v4; // edi
int v5; // eax
int v6; // ebp
int v7; // er12
int v9; // eax
socklen_t len[4]; // [rsp+Ch] [rbp-BCh] BYREF
int optval; // [rsp+1Ch] [rbp-ACh] BYREF
struct sockaddr addra[10]; // [rsp+20h] [rbp-A8h] BYREF

v3 = addr->sa_data;
v4 = addr->sa_family;
len[0] = a2;
v5 = sock(v4);
v6 = v5;
if ( addr->sa_family != 1 )
v3 = 0LL;
optval = 1;
setsockopt(v5, 1, 2, &optval, 4u);
if ( bind(v6, addr, len[0]) < 0 )
{
if ( *_errno_location() == 98 )
{
if ( v3 )
{
v9 = strlen(v3);
fprintf(
stderr,
"%s: already exists; you should delete this socket if you are\n%*s not running another instance of %s.\n",
v3,
v9,
(const char *)&unk_55B,
(const char *)progname);
LABEL_12:
exit(1);
}
}
else if ( v3 )
{
LABEL_11:
perror(v3);
goto LABEL_12;
}
v3 = "bind";
goto LABEL_11;
}
if ( listen(v6, 1) < 0 )
{
perror("listen");
exit(1);
}
len[0] = 128;
memset(addra, 0, 0x80uLL);
v7 = accept(v6, addra, len);
if ( v7 < 0 )
{
perror("accept");
exit(1);
}
if ( v3 )
unlink(v3);
fwrite("[accepted connection]\n", 1uLL, 0x16uLL, stderr);
close(v6);
return copy_data(v7);
}

canonical_decompiled_code:
int __fastcall func4(struct sockaddr *addr, socklen_t a2)
{
char *v3; // r13
int v4; // edi
int v5; // eax
int v6; // ebp
int v7; // er12
int v9; // eax
socklen_t len[4]; // [rsp+Ch] [rbp-BCh] BYREF
int optval; // [rsp+1Ch] [rbp-ACh] BYREF
struct sockaddr addra[10]; // [rsp+20h] [rbp-A8h] BYREF

v3 = addr->sa_data;
v4 = addr->sa_family;
len[0] = a2;
v5 = func2(v4);
v6 = v5;
if ( addr->sa_family != 1 )
v3 = 0LL;
optval = 1;
setsockopt(v5, 1, 2, &optval, 4u);
if ( bind(v6, addr, len[0]) < 0 )
{
if ( *_errno_location() == 98 )
{
if ( v3 )
{
v9 = strlen(v3);
fprintf(
stderr,
"%s: already exists; you should delete this socket if you are\n%*s not running another instance of %s.\n",
v3,
v9,
(const char *)&unk_55B,
(const char *)progname);
LABEL_12:
exit(1);
}
}
else if ( v3 )
{
LABEL_11:
perror(v3);
goto LABEL_12;
}
v3 = "bind";
goto LABEL_11;
}
if ( listen(v6, 1) < 0 )
{
perror("listen");
exit(1);
}
len[0] = 128;
memset(addra, 0, 0x80uLL);
v7 = accept(v6, addra, len);
if ( v7 < 0 )
{
perror("accept");
exit(1);
}
if ( v3 )
unlink(v3);
fwrite("[accepted connection]\n", 1uLL, 0x16uLL, stderr);
close(v6);
return func3(v7);
}

original_code:
static void
do_listen (const struct sockaddr *sap, socklen_t len)
{
  int sl = sock (sap->sa_family);
  int r, s, n;
  const char *path = sap->sa_family == 1
    ? ((struct sockaddr_un *) sap)->sun_path : ((void *)0);
  struct sockaddr_storage garbage;
  n = 1;
  setsockopt (sl, 1, 2, (char *) &n, sizeof (n));
  r = bind (sl, sap, len);
  if (r < 0) {
    if ((*__errno_location ()) == 98 && path)
      fprintf (stderr, "%s: already exists; you should delete this socket"
        " if you are\n%*s  not running another instance of %s.\n",
        path, (int) strlen (path), "", progname);
    else
      perror (path ? path : "bind");
    exit (1);
  }
  if (listen (sl, 1) < 0) {
    perror ("listen");
    exit (1);
  }
  memset (&garbage, 0, sizeof (garbage));
  len = sizeof (garbage);
  s = accept (sl, (struct sockaddr *) &garbage, &len);
  if (s < 0) {
    perror ("accept");
    exit (1);
  }
  if (path)
    unlink (path);
  fprintf (stderr, "[accepted connection]\n");
  close (sl);
  copy_data (s);
}

canonical_original_code:
static void do_listen(struct sockaddr *sap, unsigned int len)
{
  int sl = sock (sap->sa_family);
  int r; int s; int n;
  char *path = sap->sa_family == 1
    ? ((struct sockaddr_un *) sap)->sun_path : ((void *)0);
  struct sockaddr_storage garbage;
  n = 1;
  setsockopt (sl, 1, 2, (char *) &n, sizeof (n));
  r = bind (sl, sap, len);
  if (r < 0) {
    if ((*__errno_location ()) == 98 && path)
      fprintf (stderr, "%s: already exists; you should delete this socket"
        " if you are\n%*s  not running another instance of %s.\n",
        path, (int) strlen (path), "", progname);
    else
      perror (path ? path : "bind");
    exit (1);
  }
  if (listen (sl, 1) < 0) {
    perror ("listen");
    exit (1);
  }
  memset (&garbage, 0, sizeof (garbage));
  len = sizeof (garbage);
  s = accept (sl, (struct sockaddr *) &garbage, &len);
  if (s < 0) {
    perror ("accept");
    exit (1);
  }
  if (path)
    unlink (path);
  fprintf (stderr, "[accepted connection]\n");
  close (sl);
  copy_data (s);
}

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

variable_types:
len
unsigned int

variable_types: sl int

variable_types: r int

variable_types: s int

variable_types: n int

variable_types:
path
char *

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

return_type: void


decompiled_code:
int __fastcall do_connect(struct sockaddr *addr, socklen_t len)
{
int v2; // er12

v2 = sock(addr->sa_family);
if ( connect(v2, addr, len) < 0 )
{
perror("connect");
exit(1);
}
fwrite("[established connection]\n", 1uLL, 0x19uLL, stderr);
return copy_data(v2);
}

canonical_decompiled_code:
int __fastcall func5(struct sockaddr *addr, socklen_t len)
{
int v2; // er12

v2 = func2(addr->sa_family);
if ( connect(v2, addr, len) < 0 )
{
perror("connect");
exit(1);
}
fwrite("[established connection]\n", 1uLL, 0x19uLL, stderr);
return func3(v2);
}

original_code:
static void
do_connect (const struct sockaddr *sap, socklen_t len)
{
  int s = sock (sap->sa_family);
  int r = connect (s, sap, len);
  if (r < 0) {
    perror ("connect");
    exit (1);
  }
  fprintf (stderr, "[established connection]\n");
  copy_data (s);
}

canonical_original_code:
static void do_connect(struct sockaddr *sap, unsigned int len)
{
  int s = sock (sap->sa_family);
  int r = connect (s, sap, len);
  if (r < 0) {
    perror ("connect");
    exit (1);
  }
  fprintf (stderr, "[established connection]\n");
  copy_data (s);
}

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


decompiled_code:
__int64 __fastcall get_address(_QWORD *a1, const char *a2, const char *a3)
{
int v4; // eax
struct addrinfo *v5; // r8
socklen_t v6; // ecx
sockaddr *v7; // rsi
int v9; // eax
const char *v10; // rax
const char *v11; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( a2 )
{
v4 = getaddrinfo(a2, a3, &req, &pai);
if ( v4 )
{
v11 = gai_strerror(v4);
fprintf(stderr, "%s:%s: %s\n", a2, a3, v11);
return 0xFFFFFFFFLL;
}
}
else
{
req.ai_flags = 1;
v9 = getaddrinfo(0LL, a3, &req, &pai);
if ( v9 )
{
v10 = gai_strerror(v9);
fprintf(stderr, "local port %s: %s\n", a3, v10);
return 0xFFFFFFFFLL;
}
}
v5 = pai;
v6 = pai->ai_addrlen;
if ( v6 > 0x80 )
_assert_fail("ai->ai_addrlen <= sizeof (*sa)", "uc.c", 0xA4u, "get_address");
v7 = pai->ai_addr;
if ( v6 >= 8 )
{
*a1 = *(_QWORD *)&v7->sa_family;
*(_QWORD *)((char *)a1 + v6 - 8) = *(_QWORD *)((char *)v7 + v6 - 8);
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v7 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((_DWORD)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + v6) >> 3));
}
else if ( (v6 & 4) != 0 )
{
*(_DWORD *)a1 = *(_DWORD *)&v7->sa_family;
*(_DWORD *)((char *)a1 + v6 - 4) = *(_DWORD *)((char *)v7 + v6 - 4);
}
else if ( v6 )
{
*(_BYTE *)a1 = v7->sa_family;
if ( (v6 & 2) != 0 )
*(_WORD *)((char *)a1 + v6 - 2) = *(_WORD *)((char *)v7 + v6 - 2);
}
freeaddrinfo(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, const char *a2, const char *a3)
{
int v4; // eax
struct addrinfo *v5; // r8
socklen_t v6; // ecx
sockaddr *v7; // rsi
int v9; // eax
const char *v10; // rax
const char *v11; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( a2 )
{
v4 = getaddrinfo(a2, a3, &req, &pai);
if ( v4 )
{
v11 = gai_strerror(v4);
fprintf(stderr, "%s:%s: %s\n", a2, a3, v11);
return 0xFFFFFFFFLL;
}
}
else
{
req.ai_flags = 1;
v9 = getaddrinfo(0LL, a3, &req, &pai);
if ( v9 )
{
v10 = gai_strerror(v9);
fprintf(stderr, "local port %s: %s\n", a3, v10);
return 0xFFFFFFFFLL;
}
}
v5 = pai;
v6 = pai->ai_addrlen;
if ( v6 > 0x80 )
_assert_fail("ai->ai_addrlen <= sizeof (*sa)", "uc.c", 0xA4u, "get_address");
v7 = pai->ai_addr;
if ( v6 >= 8 )
{
*a1 = *(_QWORD *)&v7->sa_family;
*(_QWORD *)((char *)a1 + v6 - 8) = *(_QWORD *)((char *)v7 + v6 - 8);
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v7 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((_DWORD)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + v6) >> 3));
}
else if ( (v6 & 4) != 0 )
{
*(_DWORD *)a1 = *(_DWORD *)&v7->sa_family;
*(_DWORD *)((char *)a1 + v6 - 4) = *(_DWORD *)((char *)v7 + v6 - 4);
}
else if ( v6 )
{
*(_BYTE *)a1 = v7->sa_family;
if ( (v6 & 2) != 0 )
*(_WORD *)((char *)a1 + v6 - 2) = *(_WORD *)((char *)v7 + v6 - 2);
}
freeaddrinfo(v5);
return 0LL;
}

original_code:
int
get_address (struct sockaddr_storage *sa, char *host, char *port)
{
  struct addrinfo hints;
  struct addrinfo *ai;
  int err;
  memset (&hints, 0, sizeof (hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  if (host) {
    err = getaddrinfo (host, port, &hints, &ai);
    if (err) {
      fprintf (stderr, "%s:%s: %s\n", host, port,
        gai_strerror (err));
      return -1;
    }
  }
  else {
    hints.ai_flags = 0x0001;
    err = getaddrinfo (((void *)0), port, &hints, &ai);
    if (err) {
      fprintf (stderr, "local port %s: %s\n", port, gai_strerror (err));
      return -1;
    }
  }
  ((void) sizeof ((ai->ai_addrlen <= sizeof (*sa)) ? 1 : 0), __extension__ ({ if (ai->ai_addrlen <= sizeof (*sa)) ; else __assert_fail ("ai->ai_addrlen <= sizeof (*sa)", "uc.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  memcpy (sa, ai->ai_addr, ai->ai_addrlen);
  freeaddrinfo (ai);
  return 0;
}

canonical_original_code:
int get_address(struct sockaddr_storage *sa, char *host, char *port)
{
  struct addrinfo hints;
  struct addrinfo *ai;
  int err;
  memset (&hints, 0, sizeof (hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  if (host) {
    err = getaddrinfo (host, port, &hints, &ai);
    if (err) {
      fprintf (stderr, "%s:%s: %s\n", host, port,
        gai_strerror (err));
      return -1;
    }
  }
  else {
    hints.ai_flags = 0x0001;
    err = getaddrinfo (((void *)0), port, &hints, &ai);
    if (err) {
      fprintf (stderr, "local port %s: %s\n", port, gai_strerror (err));
      return -1;
    }
  }
  ((void) sizeof ((ai->ai_addrlen <= sizeof (*sa)) ? 1 : 0), __extension__ ({ if (ai->ai_addrlen <= sizeof (*sa)) ; else __assert_fail ("ai->ai_addrlen <= sizeof (*sa)", "uc.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  memcpy (sa, ai->ai_addr, ai->ai_addrlen);
  freeaddrinfo (ai);
  return 0;
}

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

variable_types:
host
char *

variable_types:
port
char *

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

return_type: int

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // rax
int v5; // er12
int v6; // er13
int v7; // eax
int v8; // edx
int v9; // eax
socklen_t v10; // esi
struct sockaddr *v11; // rdi
const char *v13; // rbp
__int16 v14[56]; // [rsp+0h] [rbp-118h] BYREF
struct sockaddr addr; // [rsp+70h] [rbp-A8h] BYREF

v3 = strrchr(*argv, 47);
progname = (__int64)v3;
if ( v3 )
v4 = v3 + 1;
else
v4 = *argv;
progname = (__int64)v4;
v5 = 0;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "lu");
if ( v7 == -1 )
break;
if ( v7 == 108 )
{
v6 = 1;
}
else
{
if ( v7 != 117 )
goto LABEL_25;
v5 = 1;
}
}
v8 = optind + 1;
if ( !v5 )
{
if ( v8 == argc )
{
v9 = get_address(&addr, 0LL, argv[optind]);
goto LABEL_13;
}
if ( optind + 2 == argc )
{
v9 = get_address(&addr, argv[optind], argv[optind + 1]);
LABEL_13:
if ( v9 < 0 )
exit(1);
v10 = 16;
v11 = &addr;
if ( addr.sa_family != 2 )
v10 = 28;
goto LABEL_16;
}
LABEL_25:
usage();
}
if ( v8 != argc )
goto LABEL_25;
v13 = argv[optind];
if ( strlen(v13) > 0x6B )
{
fprintf(stderr, "socket name exceeds maximum of %d characters\n", 107LL);
exit(1);
}
memset(v14, 0, 0x6EuLL);
v14[0] = 1;
strcpy((char *)&v14[1], v13);
v11 = (struct sockaddr *)v14;
v10 = 110;
LABEL_16:
if ( v6 )
do_listen(v11, v10);
else
do_connect(v11, v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // rax
int v5; // er12
int v6; // er13
int v7; // eax
int v8; // edx
int v9; // eax
socklen_t v10; // esi
struct sockaddr *v11; // rdi
const char *v13; // rbp
__int16 v14[56]; // [rsp+0h] [rbp-118h] BYREF
struct sockaddr addr; // [rsp+70h] [rbp-A8h] BYREF

v3 = strrchr(*argv, 47);
progname = (__int64)v3;
if ( v3 )
v4 = v3 + 1;
else
v4 = *argv;
progname = (__int64)v4;
v5 = 0;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "lu");
if ( v7 == -1 )
break;
if ( v7 == 108 )
{
v6 = 1;
}
else
{
if ( v7 != 117 )
goto LABEL_25;
v5 = 1;
}
}
v8 = optind + 1;
if ( !v5 )
{
if ( v8 == argc )
{
v9 = func6(&addr, 0LL, argv[optind]);
goto LABEL_13;
}
if ( optind + 2 == argc )
{
v9 = func6(&addr, argv[optind], argv[optind + 1]);
LABEL_13:
if ( v9 < 0 )
exit(1);
v10 = 16;
v11 = &addr;
if ( addr.sa_family != 2 )
v10 = 28;
goto LABEL_16;
}
LABEL_25:
func1();
}
if ( v8 != argc )
goto LABEL_25;
v13 = argv[optind];
if ( strlen(v13) > 0x6B )
{
fprintf(stderr, "socket name exceeds maximum of %d characters\n", 107LL);
exit(1);
}
memset(v14, 0, 0x6EuLL);
v14[0] = 1;
strcpy((char *)&v14[1], v13);
v11 = (struct sockaddr *)v14;
v10 = 110;
LABEL_16:
if ( v6 )
func4(v11, v10);
else
func5(v11, v10);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
  int opt_listen = 0;
  int opt_unixdomain = 0;
  int opt;
  socklen_t len;
  struct sockaddr_un sun;
  struct sockaddr_storage ss;
  struct sockaddr *sap;
  progname = strrchr (argv[0], '/');
  if (progname)
    progname++;
  else
    progname = argv[0];
  while ((opt = getopt (argc, argv, "lu")) != -1)
    switch (opt) {
    case 'l':
      opt_listen = 1;
      break;
    case 'u':
      opt_unixdomain = 1;
      break;
    default:
      usage ();
      break;
    }
  if (opt_unixdomain) {
    if (optind + 1 != argc)
      usage ();
    if (strlen (argv[optind]) >= sizeof (sun.sun_path)) {
      fprintf (stderr, "socket name exceeds maximum of %d characters\n",
        (int) sizeof (sun.sun_path) - 1);
      exit (1);
    }
    memset (&sun, 0, sizeof (sun));
    sun.sun_family = 1;
    strcpy (sun.sun_path, argv[optind]);
    len = sizeof (sun);
    sap = (struct sockaddr *) &sun;
  }
  else {
    int ret;
    if (optind + 1 == argc)
      ret = get_address (&ss, ((void *)0), argv[optind]);
    else if (optind + 2 == argc)
      ret = get_address (&ss, argv[optind], argv[optind+1]);
    else
      usage ();
    if (ret < 0)
      exit (1);
    sap = (struct sockaddr *) &ss;
    if (ss.ss_family == 2)
      len = sizeof (struct sockaddr_in);
    else
      len = sizeof (struct sockaddr_in6);
  }
  if (opt_listen)
    do_listen (sap, len);
  else
    do_connect (sap, len);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int opt_listen = 0;
  int opt_unixdomain = 0;
  int opt;
  unsigned int len;
  struct sockaddr_un sun;
  struct sockaddr_storage ss;
  struct sockaddr *sap;
  progname = strrchr (argv[0], '/');
  if (progname)
    progname++;
  else
    progname = argv[0];
  while ((opt = getopt (argc, argv, "lu")) != -1)
    switch (opt) {
    case 'l':
      opt_listen = 1;
      break;
    case 'u':
      opt_unixdomain = 1;
      break;
    default:
      usage ();
      break;
    }
  if (opt_unixdomain) {
    if (optind + 1 != argc)
      usage ();
    if (strlen (argv[optind]) >= sizeof (sun.sun_path)) {
      fprintf (stderr, "socket name exceeds maximum of %d characters\n",
        (int) sizeof (sun.sun_path) - 1);
      exit (1);
    }
    memset (&sun, 0, sizeof (sun));
    sun.sun_family = 1;
    strcpy (sun.sun_path, argv[optind]);
    len = sizeof (sun);
    sap = (struct sockaddr *) &sun;
  }
  else {
    int ret;
    if (optind + 1 == argc)
      ret = get_address (&ss, ((void *)0), argv[optind]);
    else if (optind + 2 == argc)
      ret = get_address (&ss, argv[optind], argv[optind+1]);
    else
      usage ();
    if (ret < 0)
      exit (1);
    sap = (struct sockaddr *) &ss;
    if (ss.ss_family == 2)
      len = sizeof (struct sockaddr_in);
    else
      len = sizeof (struct sockaddr_in6);
  }
  if (opt_listen)
    do_listen (sap, len);
  else
    do_connect (sap, len);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: ret int

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

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"usage: %s { -u unix-socket | [host] tcp-port } (to connect)\n"
" %s -l { -u unix-socket | tcp-port } (to listen)\n",
(const char *)progname,
(const char *)progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
fprintf(
stderr,
"usage: %s { -u unix-socket | [host] tcp-port } (to connect)\n"
" %s -l { -u unix-socket | tcp-port } (to listen)\n",
(const char *)progname,
(const char *)progname);
exit(1);
}

original_code:
static void
usage (void)
{
  fprintf (stderr, "usage: %s { -u unix-socket | [host] tcp-port }"
    "   (to connect)\n"
    "       %s -l { -u unix-socket | tcp-port }"
    "       (to listen)\n",
    progname, progname);
  exit (1);
}

canonical_original_code:
static void usage()
{
  fprintf (stderr, "usage: %s { -u unix-socket | [host] tcp-port }"
    "   (to connect)\n"
    "       %s -l { -u unix-socket | tcp-port }"
    "       (to listen)\n",
    progname, progname);
  exit (1);
}


repo: bhdn/utp-iia-gain

original_code:
hash_iter_t hash_iter_first(struct hash_table *table, void **dataptr)
{
 struct hash_entry *found;
 hash_iter_t state;
 size_t first;
 for (first = 0;
      first < table->size && !table->entries[first];
      first++)
  ;
 if (first >= table->size) {
  state.i = table->size;
  state.current = ((void *)0);
 }
 else {
  found = table->entries[first];
  *dataptr = found->data;
  state.i = first;
  state.current = found;
 }
 return state;
}

canonical_original_code:
struct hash_iter_t_ hash_iter_first(struct hash_table *table, void **dataptr)
{
 struct hash_entry *found;
 struct hash_iter_t_ state;
 unsigned long first;
 for (first = 0;
      first < table->size && !table->entries[first];
      first++)
  ;
 if (first >= table->size) {
  state.i = table->size;
  state.current = ((void *)0);
 }
 else {
  found = table->entries[first];
  *dataptr = found->data;
  state.i = first;
  state.current = found;
 }
 return state;
}

variable_types: struct hash_table { unsigned long count; unsigned long size; struct hash_entry **entries; } *

variable_types:
dataptr
void **

variable_types: struct hash_iter_t_ { unsigned long i; struct hash_entry { unsigned long key_len; unsigned int hash; void *data; struct hash_entry *next; } *current; }

variable_types:
first
unsigned long

user_defined_types: struct hash_iter_t_ { unsigned long i; struct hash_entry *current; }


decompiled_code:
__int64 __fastcall hash_iter_next(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v4; // rdx
__int64 result; // rax
unsigned __int64 v6; // rsi

v4 = *(_QWORD *)(a3 + 24);
result = a2;
if ( v4 )
{
LABEL_2:
*a4 = *(_QWORD *)(v4 + 16);
return result;
}
v6 = *(_QWORD *)(a1 + 8);
if ( ++result < v6 )
{
while ( 1 )
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * result);
if ( v4 )
break;
if ( ++result >= v6 )
return result;
}
goto LABEL_2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v4; // rdx
__int64 result; // rax
unsigned __int64 v6; // rsi

v4 = *(_QWORD *)(a3 + 24);
result = a2;
if ( v4 )
{
LABEL_2:
*a4 = *(_QWORD *)(v4 + 16);
return result;
}
v6 = *(_QWORD *)(a1 + 8);
if ( ++result < v6 )
{
while ( 1 )
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * result);
if ( v4 )
break;
if ( ++result >= v6 )
return result;
}
goto LABEL_2;
}
return result;
}

original_code:
hash_iter_t hash_iter_next(struct hash_table *table, hash_iter_t last,
  void **dataptr)
{
 struct hash_entry *found;
 found = last.current->next;
 if (!found) {
  for (last.i++;
       last.i < table->size && !table->entries[last.i] ;
       last.i++)
   ;
  if (last.i < table->size)
   found = table->entries[last.i];
 }
 if (found) {
  *dataptr = found->data;
  last.current = found;
 }
 return last;
}

canonical_original_code:
struct hash_iter_t_ hash_iter_next(struct hash_table *table, struct hash_iter_t_ last, void **dataptr)
{
 struct hash_entry *found;
 found = last.current->next;
 if (!found) {
  for (last.i++;
       last.i < table->size && !table->entries[last.i] ;
       last.i++)
   ;
  if (last.i < table->size)
   found = table->entries[last.i];
 }
 if (found) {
  *dataptr = found->data;
  last.current = found;
 }
 return last;
}

variable_types:
last
struct hash_iter_t_

return_type: struct hash_iter_t_ { unsigned long i; struct hash_entry { unsigned long key_len; unsigned int hash; void *data; struct hash_entry *next; } *current; }

user_defined_types: struct hash_table { unsigned long count; unsigned long size; struct hash_entry **entries; }


decompiled_code:
_BOOL8 __fastcall hash_iter_done(__int64 a1, unsigned __int64 a2)
{
return *(_QWORD *)(a1 + 8) > a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, unsigned __int64 a2)
{
return *(_QWORD *)(a1 + 8) > a2;
}

original_code:
int hash_iter_done(struct hash_table *table, hash_iter_t state)
{
 return state.i < table->size;
}

canonical_original_code:
int hash_iter_done(struct hash_table *table, struct hash_iter_t_ state)
{
 return state.i < table->size;
}

variable_types: struct hash_table { unsigned long count; unsigned long size; struct hash_entry { unsigned long key_len; unsigned int hash; void *data; struct hash_entry *next; } **entries; } *

variable_types: struct hash_iter_t_ { unsigned long i; struct hash_entry *current; }


decompiled_code:
void __fastcall hash_free(void *ptr)
{
_QWORD *v2; // r8
unsigned __int64 v3; // rbx
void *v4; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( *((_QWORD *)ptr + 1) )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 )
{
hash_free_entry(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 2);
}
++v3;
}
while ( *((_QWORD *)ptr + 1) > v3 );
}
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v2; // r8
unsigned __int64 v3; // rbx
void *v4; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( *((_QWORD *)ptr + 1) )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 )
{
func3(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 2);
}
++v3;
}
while ( *((_QWORD *)ptr + 1) > v3 );
}
free(v2);
free(ptr);
}

original_code:
void hash_free(struct hash_table *table)
{
 size_t i;
 for (i = 0; i < table->size; i++)
  if (table->entries[i])
   hash_free_entry(table->entries[i]);
 free(table->entries);
 free(table);
}

canonical_original_code:
void hash_free(struct hash_table *table)
{
 unsigned long i;
 for (i = 0; i < table->size; i++)
  if (table->entries[i])
   hash_free_entry(table->entries[i]);
 free(table->entries);
 free(table);
}

variable_types:
i
unsigned long

user_defined_types: struct hash_entry { unsigned long key_len; unsigned int hash; void *data; struct hash_entry *next; }


original_code:
unsigned int get_hash(unsigned char *key, size_t key_len)
{
    unsigned int hash = 0;
    size_t i;
    for (i = 0; i < key_len; i++){
        hash += key[i];
        hash += (hash << 10);
        hash ^= (hash >> 6);
    }
    hash += (hash << 3);
    hash ^= (hash >> 11);
    hash += (hash << 15);
    return hash;
}

canonical_original_code:
unsigned int get_hash(unsigned char *key, unsigned long key_len)
{
    unsigned int hash = 0;
    unsigned long i;
    for (i = 0; i < key_len; i++){
        hash += key[i];
        hash += (hash << 10);
        hash ^= (hash >> 6);
    }
    hash += (hash << 3);
    hash ^= (hash >> 11);
    hash += (hash << 15);
    return hash;
}

variable_types:
key
unsigned char *

variable_types:
hash
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall hash_get(__int64 a1, unsigned __int8 *a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax

if ( !a4 )
a4 = get_hash(a2, a3);
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * ((unsigned __int64)a4 % *(_QWORD *)(a1 + 8)));
if ( result )
{
if ( *(_QWORD *)(result + 24) )
{
while ( *(_DWORD *)(result + 8) != a4 || *(_QWORD *)result != a3 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
return result;
}
}
result = *(_QWORD *)(result + 16);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int8 *a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax

if ( !a4 )
a4 = func5(a2, a3);
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * ((unsigned __int64)a4 % *(_QWORD *)(a1 + 8)));
if ( result )
{
if ( *(_QWORD *)(result + 24) )
{
while ( *(_DWORD *)(result + 8) != a4 || *(_QWORD *)result != a3 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
return result;
}
}
result = *(_QWORD *)(result + 16);
}
return result;
}

original_code:
void *hash_get(struct hash_table *table, unsigned char *key, size_t
  key_len, unsigned int force_hash)
{
 unsigned int hash;
 size_t pos;
 struct hash_entry *found;
 void *data = ((void *)0);
 hash = force_hash ? force_hash : get_hash(key, key_len);
 pos = hash % table->size;
 found = table->entries[pos];
 if (found) {
  if (found->next) {
   while (found) {
    if (found->hash == hash
     && found->key_len == key_len) {
     data = found->data;
     break;
    }
    found = found->next;
   }
  }
  else
   data = found->data;
 }
 return data;
}

canonical_original_code:
void *hash_get(struct hash_table *table, unsigned char *key, unsigned long key_len, unsigned int force_hash)
{
 unsigned int hash;
 unsigned long pos;
 struct hash_entry *found;
 void *data = ((void *)0);
 hash = force_hash ? force_hash : get_hash(key, key_len);
 pos = hash % table->size;
 found = table->entries[pos];
 if (found) {
  if (found->next) {
   while (found) {
    if (found->hash == hash
     && found->key_len == key_len) {
     data = found->data;
     break;
    }
    found = found->next;
   }
  }
  else
   data = found->data;
 }
 return data;
}

variable_types:
pos
unsigned long

variable_types: struct hash_entry { unsigned long key_len; unsigned int hash; void *data; struct hash_entry *next; } *

variable_types:
data
void *

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__uid_t v4; // ebp
__pid_t v6; // eax
int v7; // eax
char *v8; // rdx
const char *v9; // rsi
int v10; // eax
int v11; // [rsp+4h] [rbp-34h] BYREF
char *envpa; // [rsp+8h] [rbp-30h] BYREF
char *argva[5]; // [rsp+10h] [rbp-28h] BYREF

v11 = -1;
if ( argc <= 1 )
{
fwrite("need username\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
v3 = argv[1];
v4 = uid_for_username(v3, &v11, envp);
if ( v11 == 1 )
{
fwrite("username not found\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
if ( !fork() )
{
v6 = read_pid_from_file(PID_FILE);
if ( v11 > 1 )
{
fprintf(stderr, "could not read from file %s\n", PID_FILE);
}
else
{
if ( v11 == -1 && (kill(v6, 9), remove(PID_FILE)) )
{
v8 = PID_FILE;
v9 = "could not remove pid file %s\n";
}
else
{
write_pid_to_file(PID_FILE, &v11);
if ( v11 == 1 )
fprintf(stderr, "could not write pid to file %s\n", PID_FILE);
v7 = setuid(v4);
v8 = (char *)v3;
v9 = "couldn't change uid to user %s\n";
if ( !v7 )
{
v10 = access(KARAF, 1);
v8 = KARAF;
v9 = "can't find executable %s\n";
if ( v10 != -1 )
{
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
argva[0] = "clean";
argva[1] = 0LL;
envpa = 0LL;
execve(KARAF, argva, &envpa);
return 0;
}
}
}
fprintf(stderr, v9, v8);
}
exit(1);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__uid_t v4; // ebp
__pid_t v6; // eax
int v7; // eax
char *v8; // rdx
const char *v9; // rsi
int v10; // eax
int v11; // [rsp+4h] [rbp-34h] BYREF
char *envpa; // [rsp+8h] [rbp-30h] BYREF
char *argva[5]; // [rsp+10h] [rbp-28h] BYREF

v11 = -1;
if ( argc <= 1 )
{
fwrite("need username\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
v3 = argv[1];
v4 = func7(v3, &v11, envp);
if ( v11 == 1 )
{
fwrite("username not found\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
if ( !fork() )
{
v6 = func8(PID_FILE);
if ( v11 > 1 )
{
fprintf(stderr, "could not read from file %s\n", PID_FILE);
}
else
{
if ( v11 == -1 && (kill(v6, 9), remove(PID_FILE)) )
{
v8 = PID_FILE;
v9 = "could not remove pid file %s\n";
}
else
{
func9(PID_FILE, &v11);
if ( v11 == 1 )
fprintf(stderr, "could not write pid to file %s\n", PID_FILE);
v7 = setuid(v4);
v8 = (char *)v3;
v9 = "couldn't change uid to user %s\n";
if ( !v7 )
{
v10 = access(KARAF, 1);
v8 = KARAF;
v9 = "can't find executable %s\n";
if ( v10 != -1 )
{
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
argva[0] = "clean";
argva[1] = 0LL;
envpa = 0LL;
execve(KARAF, argva, &envpa);
return 0;
}
}
}
fprintf(stderr, v9, v8);
}
exit(1);
}
return 0;
}

original_code:
int
main(int argc, char **argv)
{
  int err, retval;
  char * username;
  uid_t uid;
  pid_t running_process;
  err = -1;
  if (argc < 2) {
    fprintf(stderr, "need username\n");
    exit(1);
  }
  username = argv[1];
  uid = uid_for_username(username, &err);
  if (err == 1) {
    fprintf(stderr, "username not found\n");
    exit(1);
  }
  if (fork() == 0) {
    running_process = read_pid_from_file(PID_FILE, &err);
    if (err > 1) {
      fprintf(stderr, "could not read from file %s\n", PID_FILE);
      exit(1);
    } else if (err == -1) {
      kill(running_process, 9);
      if (remove(PID_FILE) != 0) {
        fprintf(stderr, "could not remove pid file %s\n", PID_FILE);
        exit(1);
      }
    }
    write_pid_to_file(PID_FILE, &err);
    if (err == 1) {
      fprintf(stderr, "could not write pid to file %s\n", PID_FILE);
    }
    retval = setuid(uid);
    if (retval != 0) {
      fprintf(stderr, "couldn't change uid to user %s\n", username);
      exit(1);
    }
    if (access(KARAF, 1) == -1) {
      fprintf(stderr, "can't find executable %s\n", KARAF);
      exit(1);
    }
    freopen( "/dev/null", "r", stdin);
    freopen( "/dev/null", "w", stdout);
    freopen( "/dev/null", "w", stderr);
    char *args[] = {"clean", ((void *)0)};
    char *envp[] = {((void *)0)};
    execve(KARAF, args, envp);
  }
}

canonical_original_code:
int main(int argc, char **argv)
{
  int err; int retval;
  char *username;
  unsigned int uid;
  int running_process;
  err = -1;
  if (argc < 2) {
    fprintf(stderr, "need username\n");
    exit(1);
  }
  username = argv[1];
  uid = uid_for_username(username, &err);
  if (err == 1) {
    fprintf(stderr, "username not found\n");
    exit(1);
  }
  if (fork() == 0) {
    running_process = read_pid_from_file(PID_FILE, &err);
    if (err > 1) {
      fprintf(stderr, "could not read from file %s\n", PID_FILE);
      exit(1);
    } else if (err == -1) {
      kill(running_process, 9);
      if (remove(PID_FILE) != 0) {
        fprintf(stderr, "could not remove pid file %s\n", PID_FILE);
        exit(1);
      }
    }
    write_pid_to_file(PID_FILE, &err);
    if (err == 1) {
      fprintf(stderr, "could not write pid to file %s\n", PID_FILE);
    }
    retval = setuid(uid);
    if (retval != 0) {
      fprintf(stderr, "couldn't change uid to user %s\n", username);
      exit(1);
    }
    if (access(KARAF, 1) == -1) {
      fprintf(stderr, "can't find executable %s\n", KARAF);
      exit(1);
    }
    freopen( "/dev/null", "r", stdin);
    freopen( "/dev/null", "w", stdout);
    freopen( "/dev/null", "w", stderr);
    char *args[] = {"clean", ((void *)0)};
    char *envp[] = {((void *)0)};
    execve(KARAF, args, envp);
  }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: err int

variable_types: retval int

variable_types:
username
char *

variable_types:
uid
unsigned int

variable_types:
args
char *[]

variable_types:
envp
char *[]


decompiled_code:
struct passwd *__fastcall uid_for_username(const char *a1, _DWORD *a2)
{
struct passwd *result; // rax

result = getpwnam(a1);
if ( result )
return (struct passwd *)result->pw_uid;
*a2 = 1;
return result;
}

canonical_decompiled_code:
struct passwd *__fastcall func7(const char *a1, _DWORD *a2)
{
struct passwd *result; // rax

result = getpwnam(a1);
if ( result )
return (struct passwd *)result->pw_uid;
*a2 = 1;
return result;
}

original_code:
uid_t
uid_for_username(const char *name, int *err)
{
  struct passwd * passwd;
  passwd = getpwnam(name);
  if (passwd == ((void *)0)) {
    *err = 1;
    return 0;
  }
  return passwd->pw_uid;
}

canonical_original_code:
unsigned int uid_for_username(char *name, int *err)
{
  struct passwd *passwd;
  passwd = getpwnam(name);
  if (passwd == ((void *)0)) {
    *err = 1;
    return 0;
  }
  return passwd->pw_uid;
}

variable_types:
name
char *

variable_types:
err
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; } *


repo: bietje/RBtree

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

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

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

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

original_code:
static inline struct rbtree *tree_parent(struct rbtree *node)
{
 if(node) {
  return node->parent;
 } else {
  return ((void *)0);
 }
}

variable_types:
node
struct rbtree *

return_type: struct rbtree { struct rbtree *left; struct rbtree *right; struct rbtree *parent; struct rbtree *root; int key; enum rbtree_color_t { RED=0, BLACK=1 } color; void *data; } *

user_defined_types: struct rbtree { struct rbtree *left; struct rbtree *right; struct rbtree *parent; struct rbtree *root; int key; enum rbtree_color_t color; void *data; }


decompiled_code:
__int64 __fastcall tree_grandparent(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = tree_parent(a1);
if ( v1 )
result = tree_parent(v1);
else
result = 0LL;
return result;
}

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

v1 = func5(a1);
if ( v1 )
result = func5(v1);
else
result = 0LL;
return result;
}

original_code:
static inline struct rbtree *tree_grandparent(struct rbtree *node)
{
 struct rbtree *parent;
 if((parent = tree_parent(node)) != ((void *)0)) {
  return tree_parent(parent);
 } else {
  return ((void *)0);
 }
}

variable_types: struct rbtree { struct rbtree *left; struct rbtree *right; struct rbtree *parent; struct rbtree *root; int key; enum rbtree_color_t { RED=0, BLACK=1 } color; void *data; } *


decompiled_code:
__int64 __fastcall tree_node_has_sibling(__int64 a1)
{
_QWORD *v1; // rax

if ( !a1 )
return 0LL;
v1 = (_QWORD *)tree_parent(a1);
if ( !v1 )
return 0LL;
if ( *v1 == a1 )
return v1[1];
return *v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_QWORD *v1; // rax

if ( !a1 )
return 0LL;
v1 = (_QWORD *)func5(a1);
if ( !v1 )
return 0LL;
if ( *v1 == a1 )
return v1[1];
return *v1;
}

original_code:
static inline struct rbtree *tree_node_has_sibling(struct rbtree *node)
{
 struct rbtree *parent;
 if(node) {
  parent = tree_parent(node);
  if(parent) {
   if(node == parent->left) {
    return parent->right;
   } else {
    return parent->left;
   }
  }
 }
 return ((void *)0);
}


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

if ( !a1 )
return 0LL;
result = tree_node_has_sibling(a1);
if ( result )
{
v2 = tree_parent(a1);
if ( *(_QWORD *)v2 == a1 )
result = *(_QWORD *)(*(_QWORD *)(v2 + 8) + 8LL);
else
result = **(_QWORD **)v2;
}
return result;
}

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

if ( !a1 )
return 0LL;
result = func7(a1);
if ( result )
{
v2 = func5(a1);
if ( *(_QWORD *)v2 == a1 )
result = *(_QWORD *)(*(_QWORD *)(v2 + 8) + 8LL);
else
result = **(_QWORD **)v2;
}
return result;
}

original_code:
static inline struct rbtree *tree_node_far_nephew(struct rbtree *node)
{
 struct rbtree *parent;
 if(node && tree_node_has_sibling(node)) {
  parent = tree_parent(node);
  return (parent->left == node) ? parent->right->right : parent->left->left;
 }
 return ((void *)0);
}


decompiled_code:
_BOOL8 __fastcall tree_parent_on_left(__int64 a1)
{
__int64 v1; // rdx
_BOOL8 result; // rax

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

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

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

original_code:
static inline int tree_parent_on_left(struct rbtree *current)
{
 if(current->parent != ((void *)0) && current->parent->right == current) {
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall tree_sub_deletion(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rdx
int v5; // ecx
__int64 v6; // r9
__int64 v7; // r11
__int64 result; // rax
__int64 v9; // r10
int v10; // edi
__int64 v11; // r8
int v12; // edx
bool v13; // zf
__int64 v14; // r9
__int64 v15; // rdi
__int64 v16; // rdi
int v17; // edi
__int64 v18; // r10
__int64 v19; // rax
_QWORD *v20; // rsi

v3 = tree_node_has_sibling(a2);
v4 = tree_node_far_nephew(a2);
result = *(_QWORD *)(v6 + 16);
if ( *(_QWORD *)result == v6 )
*(_QWORD *)result = 0LL;
else
*(_QWORD *)(result + 8) = 0LL;
while ( 1 )
{
while ( 1 )
{
if ( !v3 )
goto LABEL_8;
result = *(unsigned int *)(v3 + 36);
if ( (_DWORD)result )
break;
LABEL_10:
v11 = *(_QWORD *)(v3 + 16);
v12 = *(_DWORD *)(v11 + 36);
v13 = *(_QWORD *)v11 == v3;
*(_DWORD *)(v11 + 36) = result;
*(_DWORD *)(v3 + 36) = v12;
if ( v13 )
{
tree_rotate_right_isra_0(v7, (_QWORD *)v11);
result = *(_QWORD *)(v6 + 16);
v5 = 1;
v3 = *(_QWORD *)result;
v4 = **(_QWORD **)result;
}
else
{
tree_rotate_left_isra_0(v7, v11);
result = *(_QWORD *)(v6 + 16);
v5 = 1;
v3 = *(_QWORD *)(result + 8);
v4 = *(_QWORD *)(v3 + 8);
}
}
v9 = *(_QWORD *)v3;
if ( !*(_QWORD *)v3 )
break;
v10 = *(_DWORD *)(v9 + 36);
if ( v10 == 1 )
break;
if ( (_DWORD)result == 1 )
{
if ( !v10 )
goto LABEL_31;
result = *(_QWORD *)(v3 + 8);
if ( result )
{
v17 = *(_DWORD *)(result + 36);
goto LABEL_18;
}
}
LABEL_8:
if ( v5 != 2 )
{
LODWORD(result) = *(_DWORD *)(v3 + 36);
goto LABEL_10;
}
LABEL_12:
v14 = *(_QWORD *)(v3 + 16);
*(_DWORD *)(v3 + 36) = 0;
if ( *(_DWORD *)(v14 + 36) != 1 )
{
*(_DWORD *)(v14 + 36) = 1;
return result;
}
v15 = v14;
v3 = tree_node_has_sibling(v14);
result = tree_node_far_nephew(v15);
v4 = result;
}
v16 = *(_QWORD *)(v3 + 8);
if ( !v16 )
goto LABEL_12;
v17 = *(_DWORD *)(v16 + 36);
if ( v17 == 1 )
goto LABEL_12;
if ( (_DWORD)result != 1 )
goto LABEL_8;
if ( v9 )
{
result = *(unsigned int *)(v9 + 36);
if ( !(_DWORD)result )
{
LABEL_31:
if ( !v4 )
{
LABEL_32:
tree_rotate_right_isra_0(v7, (_QWORD *)v3);
v4 = *(_QWORD *)(v18 + 8);
goto LABEL_22;
}
goto LABEL_20;
}
}
LABEL_18:
if ( v17 )
goto LABEL_8;
if ( !v4 )
goto LABEL_33;
LABEL_20:
if ( *(_DWORD *)(v4 + 36) != 1 )
{
v18 = v3;
goto LABEL_22;
}
LABEL_33:
if ( v9 != v4 )
goto LABEL_32;
tree_rotate_left_isra_0(v7, v3);
v4 = *(_QWORD *)v18;
LABEL_22:
v19 = *(_QWORD *)(v18 + 16);
*(_DWORD *)(v4 + 36) = 1;
v20 = *(_QWORD **)(v6 + 16);
*(_DWORD *)(v18 + 36) = *(_DWORD *)(v19 + 36);
*(_DWORD *)(v19 + 36) = 1;
if ( v20[1] == v18 )
result = (__int64)tree_rotate_left_isra_0(v7, (__int64)v20);
else
result = (__int64)tree_rotate_right_isra_0(v7, v20);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rdx
int v5; // ecx
__int64 v6; // r9
__int64 v7; // r11
__int64 result; // rax
__int64 v9; // r10
int v10; // edi
__int64 v11; // r8
int v12; // edx
bool v13; // zf
__int64 v14; // r9
__int64 v15; // rdi
__int64 v16; // rdi
int v17; // edi
__int64 v18; // r10
__int64 v19; // rax
_QWORD *v20; // rsi

v3 = func7(a2);
v4 = func8(a2);
result = *(_QWORD *)(v6 + 16);
if ( *(_QWORD *)result == v6 )
*(_QWORD *)result = 0LL;
else
*(_QWORD *)(result + 8) = 0LL;
while ( 1 )
{
while ( 1 )
{
if ( !v3 )
goto LABEL_8;
result = *(unsigned int *)(v3 + 36);
if ( (_DWORD)result )
break;
LABEL_10:
v11 = *(_QWORD *)(v3 + 16);
v12 = *(_DWORD *)(v11 + 36);
v13 = *(_QWORD *)v11 == v3;
*(_DWORD *)(v11 + 36) = result;
*(_DWORD *)(v3 + 36) = v12;
if ( v13 )
{
tree_rotate_right_isra_0(v7, (_QWORD *)v11);
result = *(_QWORD *)(v6 + 16);
v5 = 1;
v3 = *(_QWORD *)result;
v4 = **(_QWORD **)result;
}
else
{
tree_rotate_left_isra_0(v7, v11);
result = *(_QWORD *)(v6 + 16);
v5 = 1;
v3 = *(_QWORD *)(result + 8);
v4 = *(_QWORD *)(v3 + 8);
}
}
v9 = *(_QWORD *)v3;
if ( !*(_QWORD *)v3 )
break;
v10 = *(_DWORD *)(v9 + 36);
if ( v10 == 1 )
break;
if ( (_DWORD)result == 1 )
{
if ( !v10 )
goto LABEL_31;
result = *(_QWORD *)(v3 + 8);
if ( result )
{
v17 = *(_DWORD *)(result + 36);
goto LABEL_18;
}
}
LABEL_8:
if ( v5 != 2 )
{
LODWORD(result) = *(_DWORD *)(v3 + 36);
goto LABEL_10;
}
LABEL_12:
v14 = *(_QWORD *)(v3 + 16);
*(_DWORD *)(v3 + 36) = 0;
if ( *(_DWORD *)(v14 + 36) != 1 )
{
*(_DWORD *)(v14 + 36) = 1;
return result;
}
v15 = v14;
v3 = func7(v14);
result = func8(v15);
v4 = result;
}
v16 = *(_QWORD *)(v3 + 8);
if ( !v16 )
goto LABEL_12;
v17 = *(_DWORD *)(v16 + 36);
if ( v17 == 1 )
goto LABEL_12;
if ( (_DWORD)result != 1 )
goto LABEL_8;
if ( v9 )
{
result = *(unsigned int *)(v9 + 36);
if ( !(_DWORD)result )
{
LABEL_31:
if ( !v4 )
{
LABEL_32:
tree_rotate_right_isra_0(v7, (_QWORD *)v3);
v4 = *(_QWORD *)(v18 + 8);
goto LABEL_22;
}
goto LABEL_20;
}
}
LABEL_18:
if ( v17 )
goto LABEL_8;
if ( !v4 )
goto LABEL_33;
LABEL_20:
if ( *(_DWORD *)(v4 + 36) != 1 )
{
v18 = v3;
goto LABEL_22;
}
LABEL_33:
if ( v9 != v4 )
goto LABEL_32;
tree_rotate_left_isra_0(v7, v3);
v4 = *(_QWORD *)v18;
LABEL_22:
v19 = *(_QWORD *)(v18 + 16);
*(_DWORD *)(v4 + 36) = 1;
v20 = *(_QWORD **)(v6 + 16);
*(_DWORD *)(v18 + 36) = *(_DWORD *)(v19 + 36);
*(_DWORD *)(v19 + 36) = 1;
if ( v20[1] == v18 )
result = (__int64)tree_rotate_left_isra_0(v7, (__int64)v20);
else
result = (__int64)tree_rotate_right_isra_0(v7, v20);
return result;
}

original_code:
static void tree_sub_deletion(struct rbtree_root *root, struct rbtree *current)
{
 tree_deletion_subcase_t _case;
 struct rbtree *sibling, *fn;
 rbtree_color_t tmp;
 sibling = tree_node_has_sibling(current);
 fn = tree_node_far_nephew(current);
 if(current->parent->left == current) {
  current->parent->left = ((void *)0);
 } else {
  current->parent->right = ((void *)0);
 }
 do {
  if(sibling != ((void *)0)) {
   if(sibling->color == RED) {
    _case = TREE_SUB_DELETION_CASE0;
   } else if((!sibling->left || sibling->left->color == BLACK) &&
    (!sibling->right || sibling->right->color == BLACK)) {
    _case = TREE_SUB_DELETION_CASE1;
   } else if(sibling->color == BLACK) {
    if((sibling->left && sibling->left->color == RED) ||
     (sibling->right && sibling->right->color == RED)) {
     _case = (!fn || fn->color == BLACK) ? TREE_SUB_DELETION_CASE2 :
                  TREE_SUB_DELETION_CASE3;
    }
   }
  }
  switch(_case) {
   case TREE_SUB_DELETION_CASE0:
    tmp = sibling->parent->color;
    sibling->parent->color = sibling->color;
    sibling->color = tmp;
    if(sibling->parent->left == sibling) {
     tree_rotate_right(root, sibling->parent);
     sibling = current->parent->left;
     fn = sibling->left;
    } else {
     tree_rotate_left(root, sibling->parent);
     sibling = current->parent->right;
     fn = sibling->right;
    }
    break;
   case TREE_SUB_DELETION_CASE1:
    sibling->color = RED;
    current = sibling->parent;
    if(current->color == BLACK) {
     sibling = tree_node_has_sibling(current);
     fn = tree_node_far_nephew(current);
     break;
    } else {
     current->color = BLACK;
     _case = TREE_SUB_DELETION_TERMINATE;
     break;
    }
   case TREE_SUB_DELETION_CASE2:
    if(fn == sibling->left) {
     fn = sibling->right;
     tree_rotate_left(root, sibling);
     sibling = fn;
     fn = sibling->left;
    } else {
     fn = sibling->left;
     tree_rotate_right(root, sibling);
     sibling = fn;
     fn = sibling->right;
    }
   case TREE_SUB_DELETION_CASE3:
    fn->color = BLACK;
    sibling->color = sibling->parent->color;
    sibling->parent->color = BLACK;
   case TREE_SUB_DELETION_CASE4:
    if(current->parent->right == sibling) {
     tree_rotate_left(root, current->parent);
    } else {
     tree_rotate_right(root, current->parent);
    }
    _case = TREE_SUB_DELETION_TERMINATE;
    break;
   default:
    _case = TREE_SUB_DELETION_TERMINATE;
    break;
  }
 } while(_case);
}

canonical_original_code:
static void tree_sub_deletion(struct rbtree_root *root, struct rbtree *current)
{
 enum tree_deletion_subcase_t _case;
 struct rbtree *sibling; struct rbtree *fn;
 enum rbtree_color_t tmp;
 sibling = tree_node_has_sibling(current);
 fn = tree_node_far_nephew(current);
 if(current->parent->left == current) {
  current->parent->left = ((void *)0);
 } else {
  current->parent->right = ((void *)0);
 }
 do {
  if(sibling != ((void *)0)) {
   if(sibling->color == RED) {
    _case = TREE_SUB_DELETION_CASE0;
   } else if((!sibling->left || sibling->left->color == BLACK) &&
    (!sibling->right || sibling->right->color == BLACK)) {
    _case = TREE_SUB_DELETION_CASE1;
   } else if(sibling->color == BLACK) {
    if((sibling->left && sibling->left->color == RED) ||
     (sibling->right && sibling->right->color == RED)) {
     _case = (!fn || fn->color == BLACK) ? TREE_SUB_DELETION_CASE2 :
                  TREE_SUB_DELETION_CASE3;
    }
   }
  }
  switch(_case) {
   case TREE_SUB_DELETION_CASE0:
    tmp = sibling->parent->color;
    sibling->parent->color = sibling->color;
    sibling->color = tmp;
    if(sibling->parent->left == sibling) {
     tree_rotate_right(root, sibling->parent);
     sibling = current->parent->left;
     fn = sibling->left;
    } else {
     tree_rotate_left(root, sibling->parent);
     sibling = current->parent->right;
     fn = sibling->right;
    }
    break;
   case TREE_SUB_DELETION_CASE1:
    sibling->color = RED;
    current = sibling->parent;
    if(current->color == BLACK) {
     sibling = tree_node_has_sibling(current);
     fn = tree_node_far_nephew(current);
     break;
    } else {
     current->color = BLACK;
     _case = TREE_SUB_DELETION_TERMINATE;
     break;
    }
   case TREE_SUB_DELETION_CASE2:
    if(fn == sibling->left) {
     fn = sibling->right;
     tree_rotate_left(root, sibling);
     sibling = fn;
     fn = sibling->left;
    } else {
     fn = sibling->left;
     tree_rotate_right(root, sibling);
     sibling = fn;
     fn = sibling->right;
    }
   case TREE_SUB_DELETION_CASE3:
    fn->color = BLACK;
    sibling->color = sibling->parent->color;
    sibling->parent->color = BLACK;
   case TREE_SUB_DELETION_CASE4:
    if(current->parent->right == sibling) {
     tree_rotate_left(root, current->parent);
    } else {
     tree_rotate_right(root, current->parent);
    }
    _case = TREE_SUB_DELETION_TERMINATE;
    break;
   default:
    _case = TREE_SUB_DELETION_TERMINATE;
    break;
  }
 } while(_case);
}

variable_types: struct rbtree_root { struct rbtree { struct rbtree *left; struct rbtree *right; struct rbtree *parent; struct rbtree *root; int key; enum rbtree_color_t { RED=0, BLACK=1 } color; void *data; } *tree; unsigned long size; } *

variable_types:
current
struct rbtree *

variable_types: enum tree_deletion_subcase_t { TREE_SUB_DELETION_TERMINATE=0, TREE_SUB_DELETION_CASE0=1, TREE_SUB_DELETION_CASE1=2, TREE_SUB_DELETION_CASE2=3, TREE_SUB_DELETION_CASE3=4, TREE_SUB_DELETION_CASE4=5, TREE_SUB_DELETION_CASE5=6, TREE_SUB_DELETION_CASE6=7 }

variable_types:
tmp
enum rbtree_color_t { RED=0, BLACK=1 }

user_defined_types: struct rbtree_root { struct rbtree *tree; unsigned long size; }


decompiled_code:
__int64 __fastcall tree_rotate_swap_parent(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r9
int v4; // er10
__int64 result; // rax

if ( *(_QWORD *)(a2 + 8) == a3 )
tree_rotate_left_isra_0(a1, a2);
else
tree_rotate_right_isra_0(a1, (_QWORD *)a2);
result = *(unsigned int *)(v3 + 36);
*(_DWORD *)(a2 + 36) = result;
*(_DWORD *)(v3 + 36) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r9
int v4; // er10
__int64 result; // rax

if ( *(_QWORD *)(a2 + 8) == a3 )
tree_rotate_left_isra_0(a1, a2);
else
tree_rotate_right_isra_0(a1, (_QWORD *)a2);
result = *(unsigned int *)(v3 + 36);
*(_DWORD *)(a2 + 36) = result;
*(_DWORD *)(v3 + 36) = v4;
return result;
}

original_code:
static void tree_rotate_swap_parent(struct rbtree_root *root, struct rbtree *parent,
         struct rbtree *current)
{
 rbtree_color_t tmp = parent->color;
 if(parent->right == current) {
  tree_rotate_left(root, parent);
 } else {
  tree_rotate_right(root, parent);
 }
 parent->color = current->color;
 current->color = tmp;
}

canonical_original_code:
static void tree_rotate_swap_parent(struct rbtree_root *root, struct rbtree *parent, struct rbtree *current)
{
 enum rbtree_color_t tmp = parent->color;
 if(parent->right == current) {
  tree_rotate_left(root, parent);
 } else {
  tree_rotate_right(root, parent);
 }
 parent->color = current->color;
 current->color = tmp;
}

variable_types:
parent
struct rbtree *


decompiled_code:
__int64 __fastcall tree_insert(__int64 **a1, __int64 a2)
{
__int64 v2; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_DWORD *)(a2 + 36) = 0;
v2 = _tree_insert(a1, a2);
tree_validate_insertion((__int64 *)a1, v2);
return 0LL;
}

original_code:
int tree_insert(struct rbtree_root *root, struct rbtree *node)
{
 node->left = ((void *)0);
 node->right = ((void *)0);
 node->parent = ((void *)0);
 node->color = RED;
 tree_validate_insertion(root, __tree_insert(root, node));
 return 0;
}


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

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
struct rbtree *tree_find_rightmost(struct rbtree *tree)
{
 if(!tree) {
  return ((void *)0);
 }
 for(;;) {
  if(tree->right == ((void *)0)) {
   return tree;
  }
  tree = tree->right;
 }
}

variable_types:
tree
struct rbtree *


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

if ( !a1 )
return 0LL;
if ( *a1 )
return tree_find_rightmost(*a1);
result = tree_parent((__int64)a1);
if ( result )
{
while ( *(__int64 **)(result + 8) != a1 )
{
a1 = (__int64 *)result;
if ( !*(_QWORD *)(result + 16) )
return 0LL;
result = *(_QWORD *)(result + 16);
}
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( *a1 )
return func16(*a1);
result = func5((__int64)a1);
if ( result )
{
while ( *(__int64 **)(result + 8) != a1 )
{
a1 = (__int64 *)result;
if ( !*(_QWORD *)(result + 16) )
return 0LL;
result = *(_QWORD *)(result + 16);
}
}
return result;
}

original_code:
static struct rbtree *tree_find_predecessor(struct rbtree *tree)
{
 if(!tree) {
  return ((void *)0);
 }
 if(!tree->left) {
  struct rbtree *tmp = tree, *carriage = tree_parent(tree);
  while (carriage != ((void *)0) && carriage->right != tmp) {
   tmp = carriage;
   carriage = carriage->parent;
  }
  return carriage;
 }
 return tree_find_rightmost(tree->left);
}

canonical_original_code:
static struct rbtree *tree_find_predecessor(struct rbtree *tree)
{
 if(!tree) {
  return ((void *)0);
 }
 if(!tree->left) {
  struct rbtree *tmp = tree; struct rbtree *carriage = tree_parent(tree);
  while (carriage != ((void *)0) && carriage->right != tmp) {
   tmp = carriage;
   carriage = carriage->parent;
  }
  return carriage;
 }
 return tree_find_rightmost(tree->left);
}


decompiled_code:
__int64 __fastcall tree_find_replacement(__int64 a1)
{
__int64 result; // rax
__int64 *v2; // r9

result = (__int64)tree_find_successor(a1);
if ( result && *(_DWORD *)(result + 36) == 1 && !*(_QWORD *)result && !*(_QWORD *)(result + 8) )
result = tree_find_predecessor(v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
__int64 result; // rax
__int64 *v2; // r9

result = (__int64)tree_find_successor(a1);
if ( result && *(_DWORD *)(result + 36) == 1 && !*(_QWORD *)result && !*(_QWORD *)(result + 8) )
result = func17(v2);
return result;
}

original_code:
static struct rbtree *tree_find_replacement(struct rbtree *tree)
{
 struct rbtree *successor = tree_find_successor(tree);
 if(!successor) {
  return ((void *)0);
 }
 if(successor->color == RED || !(successor->color == BLACK && successor->left == ((void *)0)
  && successor->right == ((void *)0))) {
  return successor;
 } else {
  return tree_find_predecessor(tree);
 }
}


decompiled_code:
__int64 __fastcall tree_delete_node(__int64 **a1, __int64 *a2)
{
__int64 result; // rax

result = _tree_delete_node(a1, a2);
if ( *a1 )
*((_DWORD *)*a1 + 9) = 1;
return result;
}

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

result = func19(a1, a2);
if ( *a1 )
*((_DWORD *)*a1 + 9) = 1;
return result;
}

original_code:
int tree_delete_node(struct rbtree_root *root, struct rbtree *node)
{
 int rc = __tree_delete_node(root, node);
 if(root->tree) {
  root->tree->color = BLACK;
 }
 return rc;
}

variable_types: rc int


cmpstr

decompiled_code:
int __fastcall cmpstr(const void *a1, const void *a2)
{
return strcmp((const char *)(*(_QWORD *)a1 + 19LL), (const char *)(*(_QWORD *)a2 + 19LL));
}

canonical_decompiled_code:
int __fastcall func9(const void *a1, const void *a2)
{
return strcmp((const char *)(*(_QWORD *)a1 + 19LL), (const char *)(*(_QWORD *)a2 + 19LL));
}

original_code:
int cmpstr(const void *p1, const void *p2) {
  struct dirent * const *name_one = p1;
  struct dirent * const *name_two = p2;
  return strcmp((*name_one)->d_name, (*name_two)->d_name);
}

canonical_original_code:
int cmpstr(void *p1, void *p2) {
  struct dirent **name_one = p1;
  struct dirent **name_two = p2;
  return strcmp((*name_one)->d_name, (*name_two)->d_name);
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **


decompiled_code:
const char *__fastcall fix_path(void *src, void *a2)
{
int v2; // ebx
int v3; // er13
char *v4; // rax
const char *v5; // r12
size_t v6; // rbx

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc(v3 + v2 + 1);
v5 = v4;
if ( v2 > 0 )
{
v6 = (unsigned int)(v2 - 1) + 1LL;
memcpy(v4, src, v6);
v4 = (char *)&v5[v6];
}
*v4 = 47;
if ( v3 > 0 )
memcpy(v4 + 1, a2, (unsigned int)(v3 - 1) + 1LL);
puts(v5);
return v5;
}

canonical_decompiled_code:
const char *__fastcall func10(void *src, void *a2)
{
int v2; // ebx
int v3; // er13
char *v4; // rax
const char *v5; // r12
size_t v6; // rbx

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc(v3 + v2 + 1);
v5 = v4;
if ( v2 > 0 )
{
v6 = (unsigned int)(v2 - 1) + 1LL;
memcpy(v4, src, v6);
v4 = (char *)&v5[v6];
}
*v4 = 47;
if ( v3 > 0 )
memcpy(v4 + 1, a2, (unsigned int)(v3 - 1) + 1LL);
puts(v5);
return v5;
}

original_code:
char *fix_path(const char *folder_path, const char *file_name) {
  int i = 0;
  char *pointer;
  char *fixed_path;
  int folder_length = strlen(folder_path);
  int file_length = strlen(file_name);
  fixed_path = (char *)malloc(sizeof(char) * (folder_length + file_length + 1));
  pointer = fixed_path;
  for (i = 0; i< folder_length; i++) {
    *(pointer++) = *(folder_path++);
  }
  *(pointer++) = '/';
  for (i = 0; i< file_length; i++) {
    *(pointer++) = *(file_name++);
  }
  printf("%s\n", fixed_path);
  return fixed_path;
}

canonical_original_code:
char *fix_path(char *folder_path, char *file_name) {
  int i = 0;
  char *pointer;
  char *fixed_path;
  int folder_length = strlen(folder_path);
  int file_length = strlen(file_name);
  fixed_path = (char *)malloc(sizeof(char) * (folder_length + file_length + 1));
  pointer = fixed_path;
  for (i = 0; i< folder_length; i++) {
    *(pointer++) = *(folder_path++);
  }
  *(pointer++) = '/';
  for (i = 0; i< file_length; i++) {
    *(pointer++) = *(file_name++);
  }
  printf("%s\n", fixed_path);
  return fixed_path;
}

variable_types: i int

variable_types:
pointer
char *

return_type: char *


decompiled_code:
char *__fastcall fix_path2(void *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
void *v4; // rax
char *v5; // r8

v2 = strlen((const char *)src);
v3 = strlen(a2);
v4 = malloc(v2 + v3 + 2);
v5 = (char *)memcpy(v4, src, v2 + 1);
if ( v5[v2 - 1] != 47 )
*(_WORD *)&v5[v2] = 47;
return strcat(v5, a2);
}

canonical_decompiled_code:
char *__fastcall func11(void *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
void *v4; // rax
char *v5; // r8

v2 = strlen((const char *)src);
v3 = strlen(a2);
v4 = malloc(v2 + v3 + 2);
v5 = (char *)memcpy(v4, src, v2 + 1);
if ( v5[v2 - 1] != 47 )
*(_WORD *)&v5[v2] = 47;
return strcat(v5, a2);
}

original_code:
char *fix_path2(const char *folder_path, const char *file_name) {
  char *both = malloc(strlen(folder_path) + strlen(file_name) + 2);
  strcpy(both, folder_path);
  if (*(both + strlen(folder_path) - 1) != '/') {
    strcat(both, "/");
  }
  strcat(both, file_name);
  return both;
}

canonical_original_code:
char *fix_path2(char *folder_path, char *file_name) {
  char *both = malloc(strlen(folder_path) + strlen(file_name) + 2);
  strcpy(both, folder_path);
  if (*(both + strlen(folder_path) - 1) != '/') {
    strcat(both, "/");
  }
  strcat(both, file_name);
  return both;
}

variable_types:
both
char *


decompiled_code:
const char *__fastcall get_username(__uid_t a1)
{
struct passwd *v1; // rax
const char *result; // rax

v1 = getpwuid(a1);
if ( v1 )
result = v1->pw_name;
else
result = "Un Known";
return result;
}

canonical_decompiled_code:
const char *__fastcall func12(__uid_t a1)
{
struct passwd *v1; // rax
const char *result; // rax

v1 = getpwuid(a1);
if ( v1 )
result = v1->pw_name;
else
result = "Un Known";
return result;
}

original_code:
char *get_username(const uid_t st_uid) {
  struct passwd *entry;
  entry = getpwuid(st_uid);
  if (entry == ((void *)0)) {
    return "Un Known";
  }
  return entry->pw_name;
}

canonical_original_code:
char *get_username(unsigned int st_uid) {
  struct passwd *entry;
  entry = getpwuid(st_uid);
  if (entry == ((void *)0)) {
    return "Un Known";
  }
  return entry->pw_name;
}

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


decompiled_code:
const char *__fastcall get_groupname(__gid_t a1)
{
struct group *v1; // rax
const char *result; // rax

v1 = getgrgid(a1);
if ( v1 )
result = v1->gr_name;
else
result = "Un Known";
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(__gid_t a1)
{
struct group *v1; // rax
const char *result; // rax

v1 = getgrgid(a1);
if ( v1 )
result = v1->gr_name;
else
result = "Un Known";
return result;
}

original_code:
char *get_groupname(const gid_t st_gid) {
  struct group *entry;
  entry = getgrgid(st_gid);
  if (entry == ((void *)0)) {
    return "Un Known";
  }
  return entry->gr_name;
}

canonical_original_code:
char *get_groupname(unsigned int st_gid) {
  struct group *entry;
  entry = getgrgid(st_gid);
  if (entry == ((void *)0)) {
    return "Un Known";
  }
  return entry->gr_name;
}

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


decompiled_code:
char *__fastcall format_time(time_t a1)
{
char *v1; // r12
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = (char *)malloc(0x14uLL);
v2 = localtime(&timer);
strftime(v1, 0x14uLL, "%Y-%m-%d %H:%M:%S", v2);
return v1;
}

canonical_decompiled_code:
char *__fastcall func14(time_t a1)
{
char *v1; // r12
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = (char *)malloc(0x14uLL);
v2 = localtime(&timer);
strftime(v1, 0x14uLL, "%Y-%m-%d %H:%M:%S", v2);
return v1;
}

original_code:
char *format_time(const time_t st_time) {
  char *buf;
  int bufsize = 20;
  struct tm *ts;
  buf = malloc(sizeof(char) * bufsize);
  ts = localtime(&st_time);
  strftime(buf, bufsize, "%Y-%m-%d %H:%M:%S", ts);
  return buf;
}

canonical_original_code:
char *format_time(long st_time) {
  char *buf;
  int bufsize = 20;
  struct tm *ts;
  buf = malloc(sizeof(char) * bufsize);
  ts = localtime(&st_time);
  strftime(buf, bufsize, "%Y-%m-%d %H:%M:%S", ts);
  return buf;
}

variable_types:
buf
char *

variable_types: bufsize int

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


sort

decompiled_code:
void __fastcall sort(void *a1, int a2)
{
qsort(a1, a2, 8uLL, cmpstr);
}

canonical_decompiled_code:
void __fastcall func15(void *a1, int a2)
{
qsort(a1, a2, 8uLL, cmpstr);
}

original_code:
void sort(void **entries, int number) {
  qsort(entries, number, sizeof(*entries), cmpstr);
}

variable_types:
entries
void **

variable_types: number int


decompiled_code:
__int64 __fastcall add_new_arg(void **a1, int a2, int a3, const char *a4)
{
unsigned int v5; // er12
__int64 v7; // rbx
char *v8; // rdi
char **v9; // rbx
char *v11; // rax

v5 = a2;
v7 = a3;
v8 = (char *)*a1;
if ( a3 + 1 >= a2 )
{
v5 = a2 + 4;
v11 = (char *)realloc(v8, 8LL * (a2 + 4));
*a1 = v11;
v8 = v11;
if ( !v11 )
{
syslog(3, "Failed to realloc memory for more arguments!\n");
exit(1);
}
}
v9 = (char **)&v8[8 * v7];
if ( a4 )
*v9 = strdup(a4);
else
*v9 = 0LL;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(void **a1, int a2, int a3, const char *a4)
{
unsigned int v5; // er12
__int64 v7; // rbx
char *v8; // rdi
char **v9; // rbx
char *v11; // rax

v5 = a2;
v7 = a3;
v8 = (char *)*a1;
if ( a3 + 1 >= a2 )
{
v5 = a2 + 4;
v11 = (char *)realloc(v8, 8LL * (a2 + 4));
*a1 = v11;
v8 = v11;
if ( !v11 )
{
syslog(3, "Failed to realloc memory for more arguments!\n");
exit(1);
}
}
v9 = (char **)&v8[8 * v7];
if ( a4 )
*v9 = strdup(a4);
else
*v9 = 0LL;
return v5;
}

original_code:
int add_new_arg(char ***args_array, int array_size,
                int element_index, char *arg) {
  if (array_size <= element_index + 1) {
    int new_size = array_size + (4);
    *args_array = realloc(*args_array, new_size * sizeof(char *));
    if (*args_array == ((void *)0)) {
      syslog(3, "Failed to realloc memory for more arguments!\n");
      exit(1);
    }
    array_size = new_size;
  }
  if (arg != ((void *)0)) {
          (*args_array)[element_index] = strdup(arg);
  } else {
          (*args_array)[element_index] = ((void *)0);
  }
  return array_size;
}

variable_types:
arg
char *


decompiled_code:
__int64 __fastcall add_new_arg2(__int64 a1, int a2, int a3, const char *a4)
{
unsigned int v5; // er12
__int64 v7; // rbx
char *v8; // rdi
char **v9; // rbx
char *v11; // rax

v5 = a2;
v7 = a3;
v8 = *(char **)(a1 + 24);
if ( a3 + 1 >= a2 )
{
v5 = a2 + 4;
v11 = (char *)realloc(v8, 8LL * (a2 + 4));
*(_QWORD *)(a1 + 24) = v11;
v8 = v11;
if ( !v11 )
{
syslog(3, "Failed to realloc memory for more arguments!\n");
exit(1);
}
}
v9 = (char **)&v8[8 * v7];
if ( a4 )
*v9 = strdup(a4);
else
*v9 = 0LL;
++*(_DWORD *)(a1 + 32);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3, const char *a4)
{
unsigned int v5; // er12
__int64 v7; // rbx
char *v8; // rdi
char **v9; // rbx
char *v11; // rax

v5 = a2;
v7 = a3;
v8 = *(char **)(a1 + 24);
if ( a3 + 1 >= a2 )
{
v5 = a2 + 4;
v11 = (char *)realloc(v8, 8LL * (a2 + 4));
*(_QWORD *)(a1 + 24) = v11;
v8 = v11;
if ( !v11 )
{
syslog(3, "Failed to realloc memory for more arguments!\n");
exit(1);
}
}
v9 = (char **)&v8[8 * v7];
if ( a4 )
*v9 = strdup(a4);
else
*v9 = 0LL;
++*(_DWORD *)(a1 + 32);
return v5;
}

original_code:
int add_new_arg2(struct AppStruct *appstruct, int array_size,
                 int element_index, char *arg) {
  if (array_size <= element_index + 1) {
    int new_size = array_size + (4);
    appstruct->args = realloc(appstruct->args, new_size * sizeof(char *));
    if (appstruct->args == ((void *)0)) {
      syslog(3, "Failed to realloc memory for more arguments!\n");
      exit(1);
    }
    array_size = new_size;
  }
  if (arg != ((void *)0)) {
    appstruct->args[element_index] = strdup(arg);
  } else {
    appstruct->args[element_index] = ((void *)0);
  }
  appstruct->argnum += 1;
  return array_size;
}

variable_types: struct AppStruct { int port; char *user; char *app; char **args; int argnum; } *


original_code:
int add_new_appstruct(struct AppStruct **appstructs, int array_size,
                      int element_index, char *user, char *app, int port) {
  if (array_size <= element_index + 1) {
    int index, new_size;
    struct AppStruct *newstructs;
    struct AppStruct *oldstructs = *appstructs;
    new_size = (array_size > 0) ? 2 * array_size : (2);
    newstructs = calloc(new_size, sizeof(struct AppStruct));
    for (index = 0; index < element_index; index++) {
      newstructs[index] = oldstructs[index];
    }
    for (index = element_index; index < new_size; index++) {
      newstructs[index].args = calloc((2), sizeof(char *));
      newstructs[index].argnum = 0;
    }
    *appstructs = newstructs;
    array_size = new_size;
    if (oldstructs != ((void *)0)) free(oldstructs);
  }
  (*appstructs)[element_index].port = port;
  (*appstructs)[element_index].user = strdup(user);
  (*appstructs)[element_index].app = strdup(app);
  return array_size;
}

canonical_original_code:
int add_new_appstruct(struct AppStruct **appstructs, int array_size, int element_index, char *user, char *app, int port) {
  if (array_size <= element_index + 1) {
    int index; int new_size;
    struct AppStruct *newstructs;
    struct AppStruct *oldstructs = *appstructs;
    new_size = (array_size > 0) ? 2 * array_size : (2);
    newstructs = calloc(new_size, sizeof(struct AppStruct));
    for (index = 0; index < element_index; index++) {
      newstructs[index] = oldstructs[index];
    }
    for (index = element_index; index < new_size; index++) {
      newstructs[index].args = calloc((2), sizeof(char *));
      newstructs[index].argnum = 0;
    }
    *appstructs = newstructs;
    array_size = new_size;
    if (oldstructs != ((void *)0)) free(oldstructs);
  }
  (*appstructs)[element_index].port = port;
  (*appstructs)[element_index].user = strdup(user);
  (*appstructs)[element_index].app = strdup(app);
  return array_size;
}

variable_types: struct AppStruct { int port; char *user; char *app; char **args; int argnum; } **

variable_types:
user
char *

variable_types:
app
char *

variable_types: port int

variable_types: index int


decompiled_code:
__int64 __fastcall compare_appstruct(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *a8, char *s1, __int64 a10, int a11, int a12, char *a13, char *s2, __int64 a15, int a16)
{
unsigned int v16; // er12
__int64 i; // rbx

v16 = -1;
if ( a7 == a12 && !strcmp(s1, s2) && !strcmp(a8, a13) && a16 == a11 )
{
if ( a11 <= 1 )
{
LABEL_12:
v16 = 1;
}
else
{
for ( i = 0LL; !strcmp(*(const char **)(a10 + 8 * i), *(const char **)(a15 + 8 * i)); ++i )
{
if ( a11 - 2 == i )
goto LABEL_12;
}
v16 = -1;
}
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *a8, char *s1, __int64 a10, int a11, int a12, char *a13, char *s2, __int64 a15, int a16)
{
unsigned int v16; // er12
__int64 i; // rbx

v16 = -1;
if ( a7 == a12 && !strcmp(s1, s2) && !strcmp(a8, a13) && a16 == a11 )
{
if ( a11 <= 1 )
{
LABEL_12:
v16 = 1;
}
else
{
for ( i = 0LL; !strcmp(*(const char **)(a10 + 8 * i), *(const char **)(a15 + 8 * i)); ++i )
{
if ( a11 - 2 == i )
goto LABEL_12;
}
v16 = -1;
}
}
return v16;
}

original_code:
int compare_appstruct(struct AppStruct new_appstruct,
                      struct AppStruct old_appstruct) {
  int not_same = -1;
  int is_same = 1;
  if (new_appstruct.port != old_appstruct.port) {
    return not_same;
  }
  if (strcmp(new_appstruct.app, old_appstruct.app) != 0) {
    return not_same;
  }
  if (strcmp(new_appstruct.user, old_appstruct.user) != 0) {
    return not_same;
  }
  if (new_appstruct.argnum != old_appstruct.argnum) {
    return not_same;
  }
  int index;
  for (index = 0; index < new_appstruct.argnum - 1; index++) {
    if (strcmp(new_appstruct.args[index], old_appstruct.args[index]) != 0) {
      return not_same;
    }
  }
  return is_same;
}

variable_types: struct AppStruct { int port; char *user; char *app; char **args; int argnum; }


decompiled_code:
__int64 __fastcall search_for_port(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *a1 != a3 )
{
result = (unsigned int)(result + 1);
a1 += 10;
if ( a2 == (_DWORD)result )
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *a1 != a3 )
{
result = (unsigned int)(result + 1);
a1 += 10;
if ( a2 == (_DWORD)result )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int search_for_port(struct AppStruct *appstructs, int size, int port) {
  int index;
  int not_found = -1;
  for (index = 0; index < size; index++) {
    if (port == appstructs[index].port) {
      return index;
    }
  }
  return not_found;
}

variable_types: size int

user_defined_types: struct AppStruct { int port; char *user; char *app; char **args; int argnum; }


decompiled_code:
__int64 __fastcall search_for_inet(__int64 a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, char *s1)
{
__int64 v10; // rbx
unsigned int v11; // er12

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
v10 = a1 + 8;
v11 = 0;
while ( *(_DWORD *)v10 != a8 || strcmp(s1, *(const char **)(v10 + 16)) )
{
++v11;
v10 += 48LL;
if ( a2 == v11 )
return 0xFFFFFFFFLL;
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, char *s1)
{
__int64 v10; // rbx
unsigned int v11; // er12

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
v10 = a1 + 8;
v11 = 0;
while ( *(_DWORD *)v10 != a8 || strcmp(s1, *(const char **)(v10 + 16)) )
{
++v11;
v10 += 48LL;
if ( a2 == v11 )
return 0xFFFFFFFFLL;
}
return v11;
}

original_code:
int search_for_inet(struct InetStruct inetstruct,
                    struct InetStruct *inetstructs, int size) {
  int index;
  int not_found = -1;
  struct AppStruct source_app, target_app;
  source_app = inetstruct.app;
  for (index = 0; index < size; index++) {
    target_app = inetstructs[index].app;
    if (source_app.port == target_app.port &&
        strcmp(source_app.app, target_app.app) == 0) {
      return index;
    }
  }
  return not_found;
}

canonical_original_code:
int search_for_inet(struct InetStruct inetstruct, struct InetStruct *inetstructs, int size) {
  int index;
  int not_found = -1;
  struct AppStruct source_app; struct AppStruct target_app;
  source_app = inetstruct.app;
  for (index = 0; index < size; index++) {
    target_app = inetstructs[index].app;
    if (source_app.port == target_app.port &&
        strcmp(source_app.app, target_app.app) == 0) {
      return index;
    }
  }
  return not_found;
}

variable_types: struct InetStruct { int sock; struct AppStruct { int port; char *user; char *app; char **args; int argnum; } app; }

variable_types:
inetstructs
struct InetStruct *

user_defined_types: struct InetStruct { int sock; struct AppStruct app; }


original_code:
struct InetStruct *verify_inetstructs(struct InetStruct *new_inetstructs,
                                      struct InetStruct *old_inetstructs,
                                      int new_number_of_apps,
                                      int number_of_apps) {
  int new_index, old_index;
  struct InetStruct *inetstruct, *old;
  for (new_index = 0; new_index < new_number_of_apps; new_index++) {
    inetstruct = &(new_inetstructs[new_index]);
    old_index = search_for_inet(*inetstruct, old_inetstructs, number_of_apps);
    if (old_index != -1) {
      old = &(old_inetstructs[old_index]);
      if (compare_appstruct(inetstruct->app, old->app) > 0) {
        inetstruct->sock = old->sock;
        old->sock = -1;
        syslog(6, "Keep connected sock for app->%s, port->%d\n",
               inetstruct->app.app, inetstruct->app.port);
      }
    }
  }
  for (old_index = 0; old_index < number_of_apps; old_index++) {
    old = &(old_inetstructs[old_index]);
    if (old->sock != -1) {
      close(old->sock);
      old->sock = -1;
    }
  }
  return new_inetstructs;
}

canonical_original_code:
struct InetStruct *verify_inetstructs(struct InetStruct *new_inetstructs, struct InetStruct *old_inetstructs, int new_number_of_apps, int number_of_apps) {
  int new_index; int old_index;
  struct InetStruct *inetstruct; struct InetStruct *old;
  for (new_index = 0; new_index < new_number_of_apps; new_index++) {
    inetstruct = &(new_inetstructs[new_index]);
    old_index = search_for_inet(*inetstruct, old_inetstructs, number_of_apps);
    if (old_index != -1) {
      old = &(old_inetstructs[old_index]);
      if (compare_appstruct(inetstruct->app, old->app) > 0) {
        inetstruct->sock = old->sock;
        old->sock = -1;
        syslog(6, "Keep connected sock for app->%s, port->%d\n",
               inetstruct->app.app, inetstruct->app.port);
      }
    }
  }
  for (old_index = 0; old_index < number_of_apps; old_index++) {
    old = &(old_inetstructs[old_index]);
    if (old->sock != -1) {
      close(old->sock);
      old->sock = -1;
    }
  }
  return new_inetstructs;
}

variable_types: struct InetStruct { int sock; struct AppStruct { int port; char *user; char *app; char **args; int argnum; } app; } *


quit

decompiled_code:
void __fastcall __noreturn quit(int status)
{
SDL_Quit();
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
SDL_Quit();
exit(status);
}

original_code:
void quit (int rc) {
  SDL_Quit();
  exit(rc);
}

canonical_original_code:
void quit(int rc) {
  SDL_Quit();
  exit(rc);
}

variable_types: rc int


decompiled_code:
__int64 __fastcall get_color_rgb(int a1, __int16 a2)
{
return (a1 << 17) & 0xFF0000 | (unsigned __int8)(a1 + a2) | (unsigned int)(unsigned __int16)(768 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int16 a2)
{
return (a1 << 17) & 0xFF0000 | (unsigned __int8)(a1 + a2) | (unsigned int)(unsigned __int16)(768 * a2);
}

variable_types: u int

variable_types: v int


decompiled_code:
__int64 make_table()
{
int i; // ecx
__int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // r8

for ( i = 0; i != 256; ++i )
{
LOWORD(v1) = 0;
do
{
result = get_color_rgb(i, v1);
*(int *)((char *)&pattern[v3] + v4) = result;
v1 = v3 + 1;
}
while ( v1 != 256 );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int i; // ecx
__int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // r8

for ( i = 0; i != 256; ++i )
{
LOWORD(v1) = 0;
do
{
result = func1(i, v1);
*(int *)((char *)&pattern[v3] + v4) = result;
v1 = v3 + 1;
}
while ( v1 != 256 );
}
return result;
}

original_code:
void make_table(){
  int i,j;
  for (i = 0; i < 256; i++) {
    for (j = 0; j < 256; j++) {
      pattern[i][j] = get_color_rgb(i, j);
    }
  }
}

canonical_original_code:
void make_table(){
  int i; int j;
  for (i = 0; i < 256; i++) {
    for (j = 0; j < 256; j++) {
      pattern[i][j] = get_color_rgb(i, j);
    }
  }
}

variable_types: i int

variable_types: j int


original_code:
void draw_screen(int* scr, int pitch, int w, int h, int half_width, int half_height) {
  float ticks = SDL_GetTicks();
  float t1 = ticks * 0.00010f;
  float t2 = ticks * 0.00030f;
  float zoom = 4.0f + 2.0f * sinf(t2);
  float angle = 2.0 * 3.1415f * sinf(t1);
  float zoom_cosf = zoom * cosf(angle);
  float zoom_sinf = zoom * sinf(angle);
  float half_w_zoom_cosf = half_width * zoom_cosf;
  float half_w_zoom_sinf = half_width * zoom_sinf;
  float half_h_zoom_cosf = half_height * zoom_cosf;
  float half_h_zoom_sinf = half_height * zoom_sinf;
  float u_offset = half_w_zoom_cosf + half_h_zoom_sinf;
  float v_offset = half_w_zoom_sinf + half_h_zoom_cosf;
  int y;
  int x;
  float u, v;
  float temp_u = 0 - zoom_sinf - u_offset;
  float temp_v = 0 - zoom_cosf - v_offset;
  int one_fourth_pitch = pitch / 4;
  int y_pitch = 0 - one_fourth_pitch;
  for ( y = 0 ; y < h ; y++ ) {
    y_pitch += one_fourth_pitch;
    temp_u += zoom_sinf;
    temp_v += zoom_cosf;
    u = temp_u - zoom_cosf;
    v = temp_v + zoom_sinf;
    for ( x = 0 ; x < w ; x++ ) {
      u += zoom_cosf;
      v -= zoom_sinf;
      scr[x + y_pitch] = pattern[(int)u & 255][(int)v & 255];
    }
  }
}

canonical_original_code:
void draw_screen(int *scr, int pitch, int w, int h, int half_width, int half_height) {
  float ticks = SDL_GetTicks();
  float t1 = ticks * 0.00010f;
  float t2 = ticks * 0.00030f;
  float zoom = 4.0f + 2.0f * sinf(t2);
  float angle = 2.0 * 3.1415f * sinf(t1);
  float zoom_cosf = zoom * cosf(angle);
  float zoom_sinf = zoom * sinf(angle);
  float half_w_zoom_cosf = half_width * zoom_cosf;
  float half_w_zoom_sinf = half_width * zoom_sinf;
  float half_h_zoom_cosf = half_height * zoom_cosf;
  float half_h_zoom_sinf = half_height * zoom_sinf;
  float u_offset = half_w_zoom_cosf + half_h_zoom_sinf;
  float v_offset = half_w_zoom_sinf + half_h_zoom_cosf;
  int y;
  int x;
  float u; float v;
  float temp_u = 0 - zoom_sinf - u_offset;
  float temp_v = 0 - zoom_cosf - v_offset;
  int one_fourth_pitch = pitch / 4;
  int y_pitch = 0 - one_fourth_pitch;
  for ( y = 0 ; y < h ; y++ ) {
    y_pitch += one_fourth_pitch;
    temp_u += zoom_sinf;
    temp_v += zoom_cosf;
    u = temp_u - zoom_cosf;
    v = temp_v + zoom_sinf;
    for ( x = 0 ; x < w ; x++ ) {
      u += zoom_cosf;
      v -= zoom_sinf;
      scr[x + y_pitch] = pattern[(int)u & 255][(int)v & 255];
    }
  }
}

variable_types:
scr
int *

variable_types: pitch int

variable_types: w int

variable_types: h int

variable_types: ticks float

variable_types: zoom float

variable_types: angle float

variable_types: y int

variable_types: x int

variable_types: u float

variable_types: v float


decompiled_code:
void mark_reload_config()
{
got_a_sighup = 1;
}

canonical_decompiled_code:
void func0()
{
got_a_sighup = 1;
}

original_code:
void mark_reload_config(int signum) {
  got_a_sighup = 1;
}

variable_types: signum int


decompiled_code:
void __fastcall folk_and_forget(int fd, int a2, __int64 a3, char *path, char **argv, __int64 a6, __int64 a7, __int64 a8, char *patha, char **argva)
{
__pid_t v11; // eax
unsigned int v12; // er12
int *v13; // rax
char *v14; // rax
__int64 v15; // r12
int v16; // edi
int *v17; // rax
char *v18; // rax

v11 = fork();
if ( v11 < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
syslog(3, "fork: %s", v14);
close(fd);
}
else
{
if ( !v11 )
{
v15 = 3LL;
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
while ( sysconf(4) >= v15 )
{
v16 = v15++;
close(v16);
}
close(fd);
lower_privilege(a8);
execv(patha, argva);
v17 = _errno_location();
v18 = strerror(*v17);
syslog(3, "execv: %s", v18);
exit(1);
}
v12 = v11;
close(fd);
syslog(6, "Child with pid %d is forked.\n", v12);
}
}

canonical_decompiled_code:
void __fastcall func2(int fd, int a2, __int64 a3, char *path, char **argv, __int64 a6, __int64 a7, __int64 a8, char *patha, char **argva)
{
__pid_t v11; // eax
unsigned int v12; // er12
int *v13; // rax
char *v14; // rax
__int64 v15; // r12
int v16; // edi
int *v17; // rax
char *v18; // rax

v11 = fork();
if ( v11 < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
syslog(3, "fork: %s", v14);
close(fd);
}
else
{
if ( !v11 )
{
v15 = 3LL;
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
while ( sysconf(4) >= v15 )
{
v16 = v15++;
close(v16);
}
close(fd);
lower_privilege(a8);
execv(patha, argva);
v17 = _errno_location();
v18 = strerror(*v17);
syslog(3, "execv: %s", v18);
exit(1);
}
v12 = v11;
close(fd);
syslog(6, "Child with pid %d is forked.\n", v12);
}
}

original_code:
void folk_and_forget(int conn, struct AppStruct appstruct) {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    syslog(3, "fork: %s", strerror((*__errno_location ())));
    close(conn);
  } else if (pid > 0) {
    close(conn);
    syslog(6, "Child  with pid %d is forked.\n", pid);
  } else {
    int i;
    for (i = 0; i < 3; i++) {
      dup2(conn, i);
    }
    for (i = 3; i <= sysconf(_SC_OPEN_MAX); i++) {
      close(i);
    }
    close(conn);
    lower_privilege(appstruct.user);
    execv(appstruct.app, appstruct.args);
    syslog(3, "execv: %s", strerror((*__errno_location ())));
    _exit(1);
  }
}

canonical_original_code:
void folk_and_forget(int conn, struct AppStruct appstruct) {
  int pid;
  pid = fork();
  if (pid < 0) {
    syslog(3, "fork: %s", strerror((*__errno_location ())));
    close(conn);
  } else if (pid > 0) {
    close(conn);
    syslog(6, "Child  with pid %d is forked.\n", pid);
  } else {
    int i;
    for (i = 0; i < 3; i++) {
      dup2(conn, i);
    }
    for (i = 3; i <= sysconf(_SC_OPEN_MAX); i++) {
      close(i);
    }
    close(conn);
    lower_privilege(appstruct.user);
    execv(appstruct.app, appstruct.args);
    syslog(3, "execv: %s", strerror((*__errno_location ())));
    _exit(1);
  }
}

variable_types: conn int

variable_types: struct AppStruct { int port; char *user; char *app; char **args; int argnum; }

variable_types: pid int


decompiled_code:
__int64 __fastcall poll_listen_socks(struct pollfd a1, int a2)
{
void *v2; // rsp
int *v3; // rdx
__int16 *v4; // rax
int v5; // ecx
__int16 *v6; // rbx
struct pollfd v7; // r13
__int16 *v8; // r15
int v9; // edi
__int64 v10; // rdx
char *v11; // rcx
int v12; // edi
char **v13; // r8
__int64 v14; // r9
__int64 result; // rax
int *v16; // r15
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // [rsp+0h] [rbp-60h] BYREF
int v21[4]; // [rsp+Ch] [rbp-54h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-40h] BYREF

v20 = (int *)a1;
a1.fd = a2 - 1;
v2 = alloca(8LL * a2);
v21[0] = a2;
if ( a2 > 0 )
{
v3 = v20;
v4 = (__int16 *)&v20 + 2;
a1 = (struct pollfd)(unsigned int)(v21[0] - 1);
do
{
v5 = *v3;
v4 += 4;
v3 += 12;
*((_DWORD *)v4 - 3) = v5;
*(v4 - 4) = 1;
}
while ( v4 != (__int16 *)&v21[2 * *(_QWORD *)&a1] );
}
v6 = (__int16 *)&v20 + 4 * (unsigned int)a1.fd + 7;
while ( 1 )
{
while ( poll((struct pollfd *)&v20, a2, -1) >= 0 )
{
v7 = (struct pollfd)v20;
v8 = (__int16 *)&v20 + 3;
if ( v21[0] > 0 )
{
do
{
while ( (*(_BYTE *)v8 & 1) == 0 )
{
LABEL_8:
v8 += 4;
*(_QWORD *)&v7 += 48LL;
if ( v8 == v6 )
goto LABEL_12;
}
v9 = *(_DWORD *)(v8 - 3);
addr_len = 16;
v12 = accept(v9, &addr, &addr_len);
if ( v12 == -1 )
{
v18 = _errno_location();
v19 = strerror(*v18);
syslog(3, "accept: %s", v19);
goto LABEL_8;
}
v8 += 4;
*(_QWORD *)&v7 += 48LL;
folk_and_forget(
v12,
(int)&addr,
v10,
v11,
v13,
v14,
*(_QWORD *)(*(_QWORD *)&v7 - 40LL),
*(_QWORD *)(*(_QWORD *)&v7 - 32LL),
*(char **)(*(_QWORD *)&v7 - 24LL),
*(char ***)(*(_QWORD *)&v7 - 16LL));
}
while ( v8 != v6 );
}
LABEL_12:
result = (unsigned int)got_a_sighup;
if ( got_a_sighup )
return result;
}
v16 = _errno_location();
v17 = strerror(*v16);
syslog(3, "poll: %s", v17);
if ( *v16 == 4 )
{
result = (unsigned int)got_a_sighup;
if ( got_a_sighup )
return result;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func3(struct pollfd a1, int a2)
{
void *v2; // rsp
int *v3; // rdx
__int16 *v4; // rax
int v5; // ecx
__int16 *v6; // rbx
struct pollfd v7; // r13
__int16 *v8; // r15
int v9; // edi
__int64 v10; // rdx
char *v11; // rcx
int v12; // edi
char **v13; // r8
__int64 v14; // r9
__int64 result; // rax
int *v16; // r15
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // [rsp+0h] [rbp-60h] BYREF
int v21[4]; // [rsp+Ch] [rbp-54h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-40h] BYREF

v20 = (int *)a1;
a1.fd = a2 - 1;
v2 = alloca(8LL * a2);
v21[0] = a2;
if ( a2 > 0 )
{
v3 = v20;
v4 = (__int16 *)&v20 + 2;
a1 = (struct pollfd)(unsigned int)(v21[0] - 1);
do
{
v5 = *v3;
v4 += 4;
v3 += 12;
*((_DWORD *)v4 - 3) = v5;
*(v4 - 4) = 1;
}
while ( v4 != (__int16 *)&v21[2 * *(_QWORD *)&a1] );
}
v6 = (__int16 *)&v20 + 4 * (unsigned int)a1.fd + 7;
while ( 1 )
{
while ( poll((struct pollfd *)&v20, a2, -1) >= 0 )
{
v7 = (struct pollfd)v20;
v8 = (__int16 *)&v20 + 3;
if ( v21[0] > 0 )
{
do
{
while ( (*(_BYTE *)v8 & 1) == 0 )
{
LABEL_8:
v8 += 4;
*(_QWORD *)&v7 += 48LL;
if ( v8 == v6 )
goto LABEL_12;
}
v9 = *(_DWORD *)(v8 - 3);
addr_len = 16;
v12 = accept(v9, &addr, &addr_len);
if ( v12 == -1 )
{
v18 = _errno_location();
v19 = strerror(*v18);
syslog(3, "accept: %s", v19);
goto LABEL_8;
}
v8 += 4;
*(_QWORD *)&v7 += 48LL;
func2(
v12,
(int)&addr,
v10,
v11,
v13,
v14,
*(_QWORD *)(*(_QWORD *)&v7 - 40LL),
*(_QWORD *)(*(_QWORD *)&v7 - 32LL),
*(char **)(*(_QWORD *)&v7 - 24LL),
*(char ***)(*(_QWORD *)&v7 - 16LL));
}
while ( v8 != v6 );
}
LABEL_12:
result = (unsigned int)got_a_sighup;
if ( got_a_sighup )
return result;
}
v16 = _errno_location();
v17 = strerror(*v16);
syslog(3, "poll: %s", v17);
if ( *v16 == 4 )
{
result = (unsigned int)got_a_sighup;
if ( got_a_sighup )
return result;
}
}
}

original_code:
void poll_listen_socks(struct InetStruct *inetstructs, int number_of_apps) {
  int index;
  int conn;
  struct pollfd fds[number_of_apps];
  for (index = 0; index < number_of_apps; index++) {
    fds[index].fd = inetstructs[index].sock;
    fds[index].events = 0x001;
  }
  while (1) {
    if ((poll(fds, number_of_apps, -1)) < 0) {
      syslog(3, "poll: %s", strerror((*__errno_location ())));
      if (((*__errno_location ()) == 4) && (got_a_sighup != 0)) {
        break;
      } else {
        continue;
      }
    }
    for (index = 0; index < number_of_apps; index++) {
      struct pollfd *fd = &(fds[index]);
      if (fd->revents & 0x001) {
        struct sockaddr_in peer;
        socklen_t size = sizeof(peer);
        if ((conn = accept(fd->fd, (struct sockaddr *)&peer, &size)) == -1) {
          syslog(3, "accept: %s", strerror((*__errno_location ())));
        } else {
          folk_and_forget(conn, (inetstructs[index]).app);
        }
      }
    }
    if (got_a_sighup != 0) break;
  }
}

canonical_original_code:
void poll_listen_socks(struct InetStruct *inetstructs, int number_of_apps) {
  int index;
  int conn;
  struct pollfd fds[-1];
  for (index = 0; index < number_of_apps; index++) {
    fds[index].fd = inetstructs[index].sock;
    fds[index].events = 0x001;
  }
  while (1) {
    if ((poll(fds, number_of_apps, -1)) < 0) {
      syslog(3, "poll: %s", strerror((*__errno_location ())));
      if (((*__errno_location ()) == 4) && (got_a_sighup != 0)) {
        break;
      } else {
        continue;
      }
    }
    for (index = 0; index < number_of_apps; index++) {
      struct pollfd *fd = &(fds[index]);
      if (fd->revents & 0x001) {
        struct sockaddr_in peer;
        unsigned int size = sizeof(peer);
        if ((conn = accept(fd->fd, (struct sockaddr *)&peer, &size)) == -1) {
          syslog(3, "accept: %s", strerror((*__errno_location ())));
        } else {
          folk_and_forget(conn, (inetstructs[index]).app);
        }
      }
    }
    if (got_a_sighup != 0) break;
  }
}

variable_types: struct InetStruct { int sock; struct AppStruct { int port; char *user; char *app; char **args; int argnum; } app; } *

variable_types: index int

variable_types: struct pollfd { int fd; short events; short revents; } [-1]

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

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

variable_types:
size
unsigned int


decompiled_code:
__int64 __fastcall generate_a_socket(unsigned int a1, const char *a2)
{
struct protoent *v2; // rax
int v3; // eax
unsigned int v4; // er12
__int16 v5; // ax
socklen_t v6; // edx
char *v7; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v16; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v2 = getprotobyname("tcp");
v3 = socket(2, 1, v2->p_proto);
if ( v3 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
syslog(3, "socket: %s", v10);
syslog(3, "Failed to create socket for %s on port %d\n", a2, a1);
exit(1);
}
v4 = v3;
setsockopt(v3, 1, 2, &optval, 4u);
v16.sa_family = 2;
v5 = _bswap_16(a1);
*(_DWORD *)&v16.sa_data[2] = 0;
*(_WORD *)v16.sa_data = v5;
if ( bind(v4, &v16, v6) )
{
v13 = _errno_location();
v14 = strerror(*v13);
syslog(3, "bind: %s", v14);
syslog(3, "Failed to bind %d to %s\n", a1, a2);
exit(1);
}
if ( listen(v4, 2) )
{
v11 = _errno_location();
v12 = strerror(*v11);
syslog(3, "listen: %s", v12);
exit(1);
}
v7 = inet_ntoa(*(struct in_addr *)&v16.sa_data[2]);
syslog(6, "App->%s is listening %s:%d on fd %d\n", a2, v7, a1, v4);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, const char *a2)
{
struct protoent *v2; // rax
int v3; // eax
unsigned int v4; // er12
__int16 v5; // ax
socklen_t v6; // edx
char *v7; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v16; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v2 = getprotobyname("tcp");
v3 = socket(2, 1, v2->p_proto);
if ( v3 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
syslog(3, "socket: %s", v10);
syslog(3, "Failed to create socket for %s on port %d\n", a2, a1);
exit(1);
}
v4 = v3;
setsockopt(v3, 1, 2, &optval, 4u);
v16.sa_family = 2;
v5 = func1(a1);
*(_DWORD *)&v16.sa_data[2] = 0;
*(_WORD *)v16.sa_data = v5;
if ( bind(v4, &v16, v6) )
{
v13 = _errno_location();
v14 = strerror(*v13);
syslog(3, "bind: %s", v14);
syslog(3, "Failed to bind %d to %s\n", a1, a2);
exit(1);
}
if ( listen(v4, 2) )
{
v11 = _errno_location();
v12 = strerror(*v11);
syslog(3, "listen: %s", v12);
exit(1);
}
v7 = inet_ntoa(*(struct in_addr *)&v16.sa_data[2]);
syslog(6, "App->%s is listening %s:%d on fd %d\n", a2, v7, a1, v4);
return v4;
}

original_code:
int generate_a_socket(int port, char *app) {
  int sock;
  int optval = 1;
  struct sockaddr_in listen_addr;
  sock = socket(2, SOCK_STREAM, getprotobyname("tcp")->p_proto);
  if (sock == -1) {
    syslog(3, "socket: %s", strerror((*__errno_location ())));
    syslog(3, "Failed to create socket for %s on port %d\n", app, port);
    exit(1);
  }
  setsockopt(sock, 1, 2, (void*)&optval, sizeof(optval));
  listen_addr.sin_family = 2;
  listen_addr.sin_port = htons(port);
  listen_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  if (bind(sock, (struct sockaddr *)&listen_addr, sizeof(listen_addr)) != 0) {
    syslog(3, "bind: %s", strerror((*__errno_location ())));
    syslog(3, "Failed to bind %d to %s\n", port, app);
    exit(1);
  }
  if (listen(sock, 2) != 0) {
    syslog(3, "listen: %s", strerror((*__errno_location ())));
    exit(1);
  }
  syslog(6, "App->%s is listening %s:%d on fd %d\n", app,
         inet_ntoa(listen_addr.sin_addr), port, sock);
  return sock;
}

canonical_original_code:
int generate_a_socket(int port, char *app) {
  int sock;
  int optval = 1;
  struct sockaddr_in listen_addr;
  sock = socket(2, SOCK_STREAM, getprotobyname("tcp")->p_proto);
  if (sock == -1) {
    syslog(3, "socket: %s", strerror((*__errno_location ())));
    syslog(3, "Failed to create socket for %s on port %d\n", app, port);
    exit(1);
  }
  setsockopt(sock, 1, 2, (void *)&optval, sizeof(optval));
  listen_addr.sin_family = 2;
  listen_addr.sin_port = htons(port);
  listen_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
  if (bind(sock, (struct sockaddr *)&listen_addr, sizeof(listen_addr)) != 0) {
    syslog(3, "bind: %s", strerror((*__errno_location ())));
    syslog(3, "Failed to bind %d to %s\n", port, app);
    exit(1);
  }
  if (listen(sock, 2) != 0) {
    syslog(3, "listen: %s", strerror((*__errno_location ())));
    exit(1);
  }
  syslog(6, "App->%s is listening %s:%d on fd %d\n", app,
         inet_ntoa(listen_addr.sin_addr), port, sock);
  return sock;
}

variable_types: port int

variable_types:
app
char *

variable_types: sock int

variable_types: optval int


decompiled_code:
__int64 __fastcall generate_listen_socks(__int64 a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rbp
const char *v5; // rsi
unsigned int v6; // edi

v2 = a1;
if ( a2 > 0 )
{
v3 = a1;
v4 = a1 + 48LL * (unsigned int)(a2 - 1) + 48;
do
{
while ( *(_DWORD *)v3 != -1 )
{
v3 += 48LL;
if ( v3 == v4 )
return v2;
}
v5 = *(const char **)(v3 + 24);
v6 = *(_DWORD *)(v3 + 8);
v3 += 48LL;
*(_DWORD *)(v3 - 48) = generate_a_socket(v6, v5);
}
while ( v3 != v4 );
}
return v2;
}

original_code:
struct InetStruct *generate_listen_socks(struct InetStruct *inetstructs,
                                         int number_of_apps) {
  int i;
  struct AppStruct *appstruct;
  for (i = 0; i < number_of_apps; i++) {
    if (inetstructs[i].sock == -1) {
      appstruct = &((inetstructs[i]).app);
      inetstructs[i].sock = generate_a_socket(appstruct->port, appstruct->app);
    }
  }
  return inetstructs;
}

variable_types:
inetstructs
struct InetStruct *

variable_types: i int

variable_types: struct AppStruct { int port; char *user; char *app; char **args; int argnum; } *

return_type: struct InetStruct { int sock; struct AppStruct { int port; char *user; char *app; char **args; int argnum; } app; } *