decompiled_code:
int __fastcall do_client(char *cp, char *src)
{
int v2; // eax
int v3; // ebp
struct sockaddr v5; // [rsp+0h] [rbp-428h] BYREF
char dest[1048]; // [rsp+10h] [rbp-418h] BYREF

sleep(2u);
v2 = socket(2, 3, 17);
if ( v2 < 0 )
fatal("socket");
v3 = v2;
v5 = 0LL;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = _bswap_16(29811);
if ( !inet_aton(cp, (struct in_addr *)&v5.sa_data[2]) )
fatal("inet_aton");
strcpy(dest, src);
if ( (int)sendto(v3, dest, 0x400uLL, 0, &v5, 0x10u) < 0 )
fatal("sendto");
puts("\nPacket Sent");
return close(v3);
}

canonical_decompiled_code:
int __fastcall func15(char *cp, char *src)
{
int v2; // eax
int v3; // ebp
struct sockaddr v5; // [rsp+0h] [rbp-428h] BYREF
char dest[1048]; // [rsp+10h] [rbp-418h] BYREF

sleep(2u);
v2 = socket(2, 3, 17);
if ( v2 < 0 )
func9("socket");
v3 = v2;
v5 = 0LL;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = func7(29811);
if ( !inet_aton(cp, (struct in_addr *)&v5.sa_data[2]) )
func9("inet_aton");
strcpy(dest, src);
if ( (int)sendto(v3, dest, 0x400uLL, 0, &v5, 0x10u) < 0 )
func9("sendto");
puts("\nPacket Sent");
return close(v3);
}

original_code:
void do_client(char *dest, char *message) {
  struct sockaddr_in si;
  int s, e, slen=sizeof(si);
  char buf[1024];
  sleep(2);
  s = socket(2, SOCK_RAW, IPPROTO_UDP);
  if (s < 0) fatal("socket");
  memset((char *) &si, 0, sizeof(si));
  si.sin_family = 2;
  si.sin_port = htons(29811);
  if (inet_aton(dest, &si.sin_addr)==0) fatal("inet_aton");
  sprintf(buf, "%s", message);
  e = sendto(s, buf, 1024, 0, (struct sockaddr *) &si, slen);
  if (e < 0) fatal("sendto");
  printf("\nPacket Sent\n");
  close(s);
}

canonical_original_code:
void do_client(char *dest, char *message) {
  struct sockaddr_in si;
  int s; int e; int slen = sizeof(si);
  char buf[1024];
  sleep(2);
  s = socket(2, SOCK_RAW, IPPROTO_UDP);
  if (s < 0) fatal("socket");
  memset((char *) &si, 0, sizeof(si));
  si.sin_family = 2;
  si.sin_port = htons(29811);
  if (inet_aton(dest, &si.sin_addr)==0) fatal("inet_aton");
  sprintf(buf, "%s", message);
  e = sendto(s, buf, 1024, 0, (struct sockaddr *) &si, slen);
  if (e < 0) fatal("sendto");
  printf("\nPacket Sent\n");
  close(s);
}

variable_types:
dest
char *

variable_types:
message
char *

variable_types: s int

variable_types: e int

variable_types: slen int

variable_types:
buf
char [1024]

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


repo: guilhem/sslh

decompiled_code:
__int64 __fastcall defer_write(unsigned int *a1, const void *a2, signed int a3)
{
void *v4; // rax

if ( verbose )
fprintf(stderr, "**** writing defered on fd %d\n", *a1);
v4 = malloc(a3);
a1[6] = a3;
*((_QWORD *)a1 + 2) = v4;
*((_QWORD *)a1 + 1) = v4;
memcpy(v4, a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, const void *a2, signed int a3)
{
void *v4; // rax

if ( verbose )
fprintf(stderr, "**** writing defered on fd %d\n", *a1);
v4 = malloc(a3);
a1[6] = a3;
*((_QWORD *)a1 + 2) = v4;
*((_QWORD *)a1 + 1) = v4;
memcpy(v4, a2, a3);
return 0LL;
}

original_code:
int defer_write(struct queue *q, void* data, int data_size)
{
    if (verbose)
        fprintf(stderr, "**** writing defered on fd %d\n", q->fd);
    q->defered_data = malloc(data_size);
    q->begin_defered_data = q->defered_data;
    q->defered_data_size = data_size;
    memcpy(q->defered_data, data, data_size);
    return 0;
}

canonical_original_code:
int defer_write(struct queue *q, void *data, int data_size)
{
    if (verbose)
        fprintf(stderr, "**** writing defered on fd %d\n", q->fd);
    q->defered_data = malloc(data_size);
    q->begin_defered_data = q->defered_data;
    q->defered_data_size = data_size;
    memcpy(q->defered_data, data, data_size);
    return 0;
}

variable_types: struct queue { int fd; void *begin_defered_data; void *defered_data; int defered_data_size; } *

variable_types:
data
void *

return_type: int


decompiled_code:
ssize_t __fastcall flush_defered(unsigned int *a1)
{
ssize_t result; // rax
unsigned int v2; // edx
ssize_t v3; // [rsp+8h] [rbp-10h]

if ( verbose )
fprintf(stderr, "flushing defered data to fd %d\n", *a1);
result = write(*a1, *((const void **)a1 + 2), (int)a1[6]);
if ( (_DWORD)result != -1 )
{
v2 = a1[6];
if ( v2 == (_DWORD)result )
{
v3 = result;
free(*((void **)a1 + 1));
*((_QWORD *)a1 + 1) = 0LL;
result = v3;
*((_QWORD *)a1 + 2) = 0LL;
a1[6] = 0;
}
else
{
*((_QWORD *)a1 + 2) += (int)result;
a1[6] = v2 - result;
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(unsigned int *a1)
{
ssize_t result; // rax
unsigned int v2; // edx
ssize_t v3; // [rsp+8h] [rbp-10h]

if ( verbose )
fprintf(stderr, "flushing defered data to fd %d\n", *a1);
result = write(*a1, *((const void **)a1 + 2), (int)a1[6]);
if ( (_DWORD)result != -1 )
{
v2 = a1[6];
if ( v2 == (_DWORD)result )
{
v3 = result;
free(*((void **)a1 + 1));
*((_QWORD *)a1 + 1) = 0LL;
result = v3;
*((_QWORD *)a1 + 2) = 0LL;
a1[6] = 0;
}
else
{
*((_QWORD *)a1 + 2) += (int)result;
a1[6] = v2 - result;
}
}
return result;
}

original_code:
int flush_defered(struct queue *q)
{
    int n;
    if (verbose)
        fprintf(stderr, "flushing defered data to fd %d\n", q->fd);
    n = write(q->fd, q->defered_data, q->defered_data_size);
    if (n == -1)
        return n;
    if (n == q->defered_data_size) {
        free(q->begin_defered_data);
        q->begin_defered_data = ((void *)0);
        q->defered_data = ((void *)0);
        q->defered_data_size = 0;
    } else {
        q->defered_data += n;
        q->defered_data_size -= n;
    }
    return n;
}

variable_types: n int

user_defined_types: struct queue { int fd; void *begin_defered_data; void *defered_data; int defered_data_size; }


decompiled_code:
int __fastcall dump_connection(unsigned int *a1)
{
printf("state: %d\n", *a1);
printf("fd %d, %d defered\n", a1[4], a1[10]);
return printf("fd %d, %d defered\n", a1[12], a1[18]);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int *a1)
{
printf("state: %d\n", *a1);
printf("fd %d, %d defered\n", a1[4], a1[10]);
return printf("fd %d, %d defered\n", a1[12], a1[18]);
}

original_code:
void dump_connection(struct connection *cnx)
{
    printf("state: %d\n", cnx->state);
    printf("fd %d, %d defered\n", cnx->q[0].fd, cnx->q[0].defered_data_size);
    printf("fd %d, %d defered\n", cnx->q[1].fd, cnx->q[1].defered_data_size);
}

variable_types: struct connection { enum connection_state { ST_PROBING=1, ST_SHOVELING=2 } state; long probe_timeout; struct queue { int fd; void *begin_defered_data; void *defered_data; int defered_data_size; } q[2]; } *

return_type: void

user_defined_types: struct connection { enum connection_state state; long probe_timeout; struct queue q[2]; }


decompiled_code:
void log_message(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
if ( foreground )
vfprintf(stderr, a2, arg);
else
vsyslog(a1, a2, arg);
}

canonical_decompiled_code:
void func4(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
if ( foreground )
vfprintf(stderr, a2, arg);
else
vsyslog(a1, a2, arg);
}

original_code:
void log_message(int type, char* msg, ...)
{
    va_list ap;
    __builtin_va_start(ap,msg);
    if (foreground)
        vfprintf(stderr, msg, ap);
    else
        vsyslog(type, msg, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void log_message(int type, char *msg, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,msg);
    if (foreground)
        vfprintf(stderr, msg, ap);
    else
        vsyslog(type, msg, ap);
    __builtin_va_end(ap);
}

variable_types: type int

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall fd2fd(unsigned int *a1, int *a2)
{
unsigned int v2; // er13
int v3; // er14
signed int v4; // eax
unsigned int v5; // er12
signed int v6; // ebx
signed int v8; // eax
__int64 v9; // rcx
__int64 v10; // rcx
char v11[8232]; // [rsp+0h] [rbp-2028h] BYREF

v2 = *a2;
v3 = *a1;
v4 = read(*a2, v11, 0x2000uLL);
v5 = v4;
if ( v4 != -1 )
{
v6 = v4;
if ( !v4 )
return v5;
v8 = write(v3, v11, v4);
v5 = v8;
if ( v8 != -1 )
{
if ( v6 > v8 )
{
v5 = -2;
defer_write(a1, &v11[v8], v6 - v8);
}
return v5;
}
v10 = (unsigned int)*_errno_location();
if ( (_DWORD)v10 != 32 && (_DWORD)v10 != 104 )
{
if ( (_DWORD)v10 == 11 )
{
v5 = -2;
defer_write(a1, v11, v6);
}
else
{
v5 = -1;
log_message(2, "%s: %d\n", "write", v10);
}
return v5;
}
return 0;
}
v9 = (unsigned int)*_errno_location();
if ( (_DWORD)v9 == 32 || (_DWORD)v9 == 104 )
return 0;
if ( (_DWORD)v9 == 11 )
{
if ( verbose )
fprintf(stderr, "reading 0 from %d\n", v2);
}
else
{
log_message(2, "%s: %d\n", "read", v9);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, int *a2)
{
unsigned int v2; // er13
int v3; // er14
signed int v4; // eax
unsigned int v5; // er12
signed int v6; // ebx
signed int v8; // eax
__int64 v9; // rcx
__int64 v10; // rcx
char v11[8232]; // [rsp+0h] [rbp-2028h] BYREF

v2 = *a2;
v3 = *a1;
v4 = read(*a2, v11, 0x2000uLL);
v5 = v4;
if ( v4 != -1 )
{
v6 = v4;
if ( !v4 )
return v5;
v8 = write(v3, v11, v4);
v5 = v8;
if ( v8 != -1 )
{
if ( v6 > v8 )
{
v5 = -2;
func0(a1, &v11[v8], v6 - v8);
}
return v5;
}
v10 = (unsigned int)*_errno_location();
if ( (_DWORD)v10 != 32 && (_DWORD)v10 != 104 )
{
if ( (_DWORD)v10 == 11 )
{
v5 = -2;
func0(a1, v11, v6);
}
else
{
v5 = -1;
func4(2, "%s: %d\n", "write", v10);
}
return v5;
}
return 0;
}
v9 = (unsigned int)*_errno_location();
if ( (_DWORD)v9 == 32 || (_DWORD)v9 == 104 )
return 0;
if ( (_DWORD)v9 == 11 )
{
if ( verbose )
fprintf(stderr, "reading 0 from %d\n", v2);
}
else
{
func4(2, "%s: %d\n", "read", v9);
}
return v5;
}

original_code:
int fd2fd(struct queue *target_q, struct queue *from_q)
{
   char buffer[8192];
   int target, from, size_r, size_w;
   target = target_q->fd;
   from = from_q->fd;
   size_r = read(from, buffer, sizeof(buffer));
   if (size_r == -1) {
       switch ((*__errno_location ())) {
       case 11:
           if (verbose)
               fprintf(stderr, "reading 0 from %d\n", from);
           return -1;
       case 104:
       case 32:
           return 0;
       }
   }
   if (size_r == -1) { log_message(2, "%s: %d\n", "read", (*__errno_location ())); return size_r; };
   if (size_r == 0)
      return 0;
   size_w = write(target, buffer, size_r);
   if ((size_w == -1)) {
       switch ((*__errno_location ())) {
       case 11:
           defer_write(target_q, buffer, size_r);
           return -2;
       case 104:
       case 32:
           return 0;
       }
   } else if (size_w < size_r) {
       defer_write(target_q, buffer + size_w, size_r - size_w);
       return -2;
   }
   if (size_w == -1) { log_message(2, "%s: %d\n", "write", (*__errno_location ())); return size_w; };
   return size_w;
}

canonical_original_code:
int fd2fd(struct queue *target_q, struct queue *from_q)
{
   char buffer[8192];
   int target; int from; int size_r; int size_w;
   target = target_q->fd;
   from = from_q->fd;
   size_r = read(from, buffer, sizeof(buffer));
   if (size_r == -1) {
       switch ((*__errno_location ())) {
       case 11:
           if (verbose)
               fprintf(stderr, "reading 0 from %d\n", from);
           return -1;
       case 104:
       case 32:
           return 0;
       }
   }
   if (size_r == -1) { log_message(2, "%s: %d\n", "read", (*__errno_location ())); return size_r; };
   if (size_r == 0)
      return 0;
   size_w = write(target, buffer, size_r);
   if ((size_w == -1)) {
       switch ((*__errno_location ())) {
       case 11:
           defer_write(target_q, buffer, size_r);
           return -2;
       case 104:
       case 32:
           return 0;
       }
   } else if (size_w < size_r) {
       defer_write(target_q, buffer + size_w, size_r - size_w);
       return -2;
   }
   if (size_w == -1) { log_message(2, "%s: %d\n", "write", (*__errno_location ())); return size_w; };
   return size_w;
}

variable_types:
buffer
char [8192]

variable_types: target int

variable_types: from int


sprintaddr

decompiled_code:
char *__fastcall sprintaddr(char *s, size_t maxlen, __int64 a3)
{
int v4; // eax
int v5; // eax
const char *v7; // rax
int v8; // eax
const char *v9; // rax
char serv[2]; // [rsp+8h] [rbp-448h] BYREF
char host[2]; // [rsp+28h] [rbp-428h] BYREF

v4 = numeric;
if ( numeric )
v4 = 3;
v5 = getnameinfo(*(const struct sockaddr **)(a3 + 24), *(_DWORD *)(a3 + 16), host, 0x401u, serv, 0x20u, v4);
if ( v5 )
{
v7 = gai_strerror(v5);
log_message(3, "sprintaddr:getnameinfo: %s\n", v7);
v8 = getnameinfo(*(const struct sockaddr **)(a3 + 24), *(_DWORD *)(a3 + 16), host, 0x401u, serv, 0x20u, 3);
if ( v8 )
{
v9 = gai_strerror(v8);
log_message(3, "sprintaddr:getnameinfo(NUM): %s\n", v9);
strcpy(host, "?");
strcpy(serv, "?");
}
}
snprintf(s, maxlen, "%s:%s", host, serv);
return s;
}

canonical_decompiled_code:
char *__fastcall func6(char *s, size_t maxlen, __int64 a3)
{
int v4; // eax
int v5; // eax
const char *v7; // rax
int v8; // eax
const char *v9; // rax
char serv[2]; // [rsp+8h] [rbp-448h] BYREF
char host[2]; // [rsp+28h] [rbp-428h] BYREF

v4 = numeric;
if ( numeric )
v4 = 3;
v5 = getnameinfo(*(const struct sockaddr **)(a3 + 24), *(_DWORD *)(a3 + 16), host, 0x401u, serv, 0x20u, v4);
if ( v5 )
{
v7 = gai_strerror(v5);
func4(3, "sprintaddr:getnameinfo: %s\n", v7);
v8 = getnameinfo(*(const struct sockaddr **)(a3 + 24), *(_DWORD *)(a3 + 16), host, 0x401u, serv, 0x20u, 3);
if ( v8 )
{
v9 = gai_strerror(v8);
func4(3, "sprintaddr:getnameinfo(NUM): %s\n", v9);
strcpy(host, "?");
strcpy(serv, "?");
}
}
snprintf(s, maxlen, "%s:%s", host, serv);
return s;
}

original_code:
char* sprintaddr(char* buf, size_t size, struct addrinfo *a)
{
   char host[1025], serv[32];
   int res;
   res = getnameinfo(a->ai_addr, a->ai_addrlen,
               host, sizeof(host),
               serv, sizeof(serv),
               numeric ? 1 | 2 : 0 );
   if (res) {
       log_message(3, "sprintaddr:getnameinfo: %s\n", gai_strerror(res));
       res = getnameinfo(a->ai_addr, a->ai_addrlen,
                         host, sizeof(host),
                         serv, sizeof(serv),
                         1 | 2);
       if (res) {
           log_message(3, "sprintaddr:getnameinfo(NUM): %s\n", gai_strerror(res));
           strcpy(host, "?");
           strcpy(serv, "?");
       }
   }
   snprintf(buf, size, "%s:%s", host, serv);
   return buf;
}

canonical_original_code:
char *sprintaddr(char *buf, unsigned long size, struct addrinfo *a)
{
   char host[1025]; char serv[32];
   int res;
   res = getnameinfo(a->ai_addr, a->ai_addrlen,
               host, sizeof(host),
               serv, sizeof(serv),
               numeric ? 1 | 2 : 0 );
   if (res) {
       log_message(3, "sprintaddr:getnameinfo: %s\n", gai_strerror(res));
       res = getnameinfo(a->ai_addr, a->ai_addrlen,
                         host, sizeof(host),
                         serv, sizeof(serv),
                         1 | 2);
       if (res) {
           log_message(3, "sprintaddr:getnameinfo(NUM): %s\n", gai_strerror(res));
           strcpy(host, "?");
           strcpy(serv, "?");
       }
   }
   snprintf(buf, size, "%s:%s", host, serv);
   return buf;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

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:
host
char [1025]

variable_types:
serv
char [32]

variable_types: res int

return_type: char *

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


decompiled_code:
void __fastcall check_res_dumpdie(int a1, __int64 a2, const char *a3)
{
__int64 v3; // rbx
__int64 v4; // r12
int *v6; // rax
char *v7; // rbx
char *v8; // rax
char s[1048]; // [rsp+8h] [rbp-428h] BYREF
__int64 v10; // [rsp+420h] [rbp-10h]
__int64 v11; // [rsp+428h] [rbp-8h]

if ( a1 == -1 )
{
v11 = v4;
v10 = v3;
v6 = _errno_location();
v7 = strerror(*v6);
v8 = sprintaddr(s, 0x401uLL, a2);
fprintf(stderr, "%s:%s: %s\n", v8, a3, v7);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1, __int64 a2, const char *a3)
{
__int64 v3; // rbx
__int64 v4; // r12
int *v6; // rax
char *v7; // rbx
char *v8; // rax
char s[1048]; // [rsp+8h] [rbp-428h] BYREF
__int64 v10; // [rsp+420h] [rbp-10h]
__int64 v11; // [rsp+428h] [rbp-8h]

if ( a1 == -1 )
{
v11 = v4;
v10 = v3;
v6 = _errno_location();
v7 = strerror(*v6);
v8 = func6(s, 0x401uLL, a2);
fprintf(stderr, "%s:%s: %s\n", v8, a3, v7);
exit(1);
}
}

original_code:
void check_res_dumpdie(int res, struct addrinfo *addr, char* syscall)
{
    char buf[1025];
    if (res == -1) {
        fprintf(stderr, "%s:%s: %s\n",
                sprintaddr(buf, sizeof(buf), addr),
                syscall,
                strerror((*__errno_location ())));
        exit(1);
    }
}

canonical_original_code:
void check_res_dumpdie(int res, struct addrinfo *addr, char *syscall)
{
    char buf[1025];
    if (res == -1) {
        fprintf(stderr, "%s:%s: %s\n",
                sprintaddr(buf, sizeof(buf), addr),
                syscall,
                strerror((*__errno_location ())));
        exit(1);
    }
}

variable_types:
syscall
char *

variable_types:
buf
char [1025]


decompiled_code:
__int64 __fastcall start_listen_sockets(void **a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
int v4; // er13
__int64 v5; // rbp
_DWORD *v6; // rax
_DWORD *v7; // rax
int v8; // eax
int v9; // eax
int v10; // eax
bool v11; // dl
__int64 result; // rax
int optval[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a2 )
{
v2 = a2;
v3 = a2;
v4 = 0;
do
{
v3 = *(_QWORD *)(v3 + 40);
++v4;
}
while ( v3 );
if ( verbose )
fprintf(stderr, "listening to %d addresses\n", (unsigned int)v4);
v5 = 0LL;
v6 = malloc(4LL * v4);
for ( *a1 = v6; ; v6 = *a1 )
{
v6[v5] = socket(**(unsigned __int16 **)(v2 + 24), 1, 0);
check_res_dumpdie(*((_DWORD *)*a1 + v5), v2, "socket");
v7 = *a1;
optval[0] = 1;
v8 = setsockopt(v7[v5], 1, 2, optval, 4u);
check_res_dumpdie(v8, v2, "setsockopt");
v9 = bind(*((_DWORD *)*a1 + v5), *(const struct sockaddr **)(v2 + 24), *(_DWORD *)(v2 + 16));
check_res_dumpdie(v9, v2, "bind");
v10 = listen(*((_DWORD *)*a1 + v5), 50);
check_res_dumpdie(v10, v2, "listen");
v2 = *(_QWORD *)(v2 + 40);
v11 = v4 > (int)v5++ + 1;
if ( v2 == 0 || !v11 )
break;
}
result = (unsigned int)v4;
}
else
{
if ( verbose )
fprintf(stderr, "listening to %d addresses\n", 0LL);
*a1 = malloc(0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(void **a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
int v4; // er13
__int64 v5; // rbp
_DWORD *v6; // rax
_DWORD *v7; // rax
int v8; // eax
int v9; // eax
int v10; // eax
bool v11; // dl
__int64 result; // rax
int optval[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a2 )
{
v2 = a2;
v3 = a2;
v4 = 0;
do
{
v3 = *(_QWORD *)(v3 + 40);
++v4;
}
while ( v3 );
if ( verbose )
fprintf(stderr, "listening to %d addresses\n", (unsigned int)v4);
v5 = 0LL;
v6 = malloc(4LL * v4);
for ( *a1 = v6; ; v6 = *a1 )
{
v6[v5] = socket(**(unsigned __int16 **)(v2 + 24), 1, 0);
func7(*((_DWORD *)*a1 + v5), v2, "socket");
v7 = *a1;
optval[0] = 1;
v8 = setsockopt(v7[v5], 1, 2, optval, 4u);
func7(v8, v2, "setsockopt");
v9 = bind(*((_DWORD *)*a1 + v5), *(const struct sockaddr **)(v2 + 24), *(_DWORD *)(v2 + 16));
func7(v9, v2, "bind");
v10 = listen(*((_DWORD *)*a1 + v5), 50);
func7(v10, v2, "listen");
v2 = *(_QWORD *)(v2 + 40);
v11 = v4 > (int)v5++ + 1;
if ( v2 == 0 || !v11 )
break;
}
result = (unsigned int)v4;
}
else
{
if ( verbose )
fprintf(stderr, "listening to %d addresses\n", 0LL);
*a1 = malloc(0LL);
result = 0LL;
}
return result;
}

original_code:
int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list)
{
   struct sockaddr_storage *saddr;
   struct addrinfo *addr;
   int i, res, reuse;
   int num_addr = 0;
   for (addr = addr_list; addr; addr = addr->ai_next)
       num_addr++;
   if (verbose)
       fprintf(stderr, "listening to %d addresses\n", num_addr);
   *sockfd = malloc(num_addr * sizeof(*sockfd[0]));
   for (i = 0, addr = addr_list; i < num_addr && addr; i++, addr = addr->ai_next) {
       if (!addr) {
           fprintf(stderr, "FATAL: Inconsistent listen number. This should not happen.\n");
           exit(1);
       }
       saddr = (struct sockaddr_storage*)addr->ai_addr;
       (*sockfd)[i] = socket(saddr->ss_family, SOCK_STREAM, 0);
       check_res_dumpdie((*sockfd)[i], addr, "socket");
       reuse = 1;
       res = setsockopt((*sockfd)[i], 1, 2, (char*)&reuse, sizeof(reuse));
       check_res_dumpdie(res, addr, "setsockopt");
       res = bind((*sockfd)[i], addr->ai_addr, addr->ai_addrlen);
       check_res_dumpdie(res, addr, "bind");
       res = listen ((*sockfd)[i], 50);
       check_res_dumpdie(res, addr, "listen");
   }
   return num_addr;
}

canonical_original_code:
int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list)
{
   struct sockaddr_storage *saddr;
   struct addrinfo *addr;
   int i; int res; int reuse;
   int num_addr = 0;
   for (addr = addr_list; addr; addr = addr->ai_next)
       num_addr++;
   if (verbose)
       fprintf(stderr, "listening to %d addresses\n", num_addr);
   *sockfd = malloc(num_addr * sizeof(*sockfd[0]));
   for (i = 0, addr = addr_list; i < num_addr && addr; i++, addr = addr->ai_next) {
       if (!addr) {
           fprintf(stderr, "FATAL: Inconsistent listen number. This should not happen.\n");
           exit(1);
       }
       saddr = (struct sockaddr_storage *)addr->ai_addr;
       (*sockfd)[i] = socket(saddr->ss_family, SOCK_STREAM, 0);
       check_res_dumpdie((*sockfd)[i], addr, "socket");
       reuse = 1;
       res = setsockopt((*sockfd)[i], 1, 2, (char *)&reuse, sizeof(reuse));
       check_res_dumpdie(res, addr, "setsockopt");
       res = bind((*sockfd)[i], addr->ai_addr, addr->ai_addrlen);
       check_res_dumpdie(res, addr, "bind");
       res = listen ((*sockfd)[i], 50);
       check_res_dumpdie(res, addr, "listen");
   }
   return num_addr;
}

variable_types:
sockfd
int *[]

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

variable_types: i int

variable_types: reuse int


decompiled_code:
__int64 __fastcall connect_addr(__int64 a1, const char *a2)
{
__int64 v2; // rbx
int *v3; // rax
char *v4; // rax
int v5; // eax
unsigned int v6; // er12
int *v7; // rax
char *v8; // rax
unsigned int v10; // er13
unsigned int v11; // er12
char *v12; // rax
char v13[1080]; // [rsp+0h] [rbp-438h] BYREF

if ( a1 )
{
v2 = a1;
do
{
while ( 1 )
{
if ( verbose )
{
v10 = *(_DWORD *)(v2 + 16);
v11 = **(unsigned __int16 **)(v2 + 24);
v12 = sprintaddr(v13, 0x401uLL, v2);
fprintf(stderr, "connecting to %s family %d len %d\n", v12, v11, v10);
}
v5 = socket(*(_DWORD *)(v2 + 4), 1, 0);
v6 = v5;
if ( v5 != -1 )
break;
v7 = _errno_location();
v8 = strerror(*v7);
log_message(3, "forward to %s failed:socket: %s\n", a2, v8);
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return (unsigned int)-1;
}
if ( connect(v5, *(const struct sockaddr **)(v2 + 24), *(_DWORD *)(v2 + 16)) != -1 )
return v6;
v3 = _errno_location();
v4 = strerror(*v3);
log_message(3, "forward to %s failed:connect: %s\n", a2, v4);
v2 = *(_QWORD *)(v2 + 40);
}
while ( v2 );
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2)
{
__int64 v2; // rbx
int *v3; // rax
char *v4; // rax
int v5; // eax
unsigned int v6; // er12
int *v7; // rax
char *v8; // rax
unsigned int v10; // er13
unsigned int v11; // er12
char *v12; // rax
char v13[1080]; // [rsp+0h] [rbp-438h] BYREF

if ( a1 )
{
v2 = a1;
do
{
while ( 1 )
{
if ( verbose )
{
v10 = *(_DWORD *)(v2 + 16);
v11 = **(unsigned __int16 **)(v2 + 24);
v12 = func6(v13, 0x401uLL, v2);
fprintf(stderr, "connecting to %s family %d len %d\n", v12, v11, v10);
}
v5 = socket(*(_DWORD *)(v2 + 4), 1, 0);
v6 = v5;
if ( v5 != -1 )
break;
v7 = _errno_location();
v8 = strerror(*v7);
func4(3, "forward to %s failed:socket: %s\n", a2, v8);
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return (unsigned int)-1;
}
if ( connect(v5, *(const struct sockaddr **)(v2 + 24), *(_DWORD *)(v2 + 16)) != -1 )
return v6;
v3 = _errno_location();
v4 = strerror(*v3);
func4(3, "forward to %s failed:connect: %s\n", a2, v4);
v2 = *(_QWORD *)(v2 + 40);
}
while ( v2 );
}
return (unsigned int)-1;
}

original_code:
int connect_addr(struct addrinfo *addr, const char* cnx_name)
{
    struct addrinfo *a;
    char buf[1025];
    int fd, res;
    for (a = addr; a; a = a->ai_next) {
        if (verbose)
            fprintf(stderr, "connecting to %s family %d len %d\n",
                    sprintaddr(buf, sizeof(buf), a),
                    a->ai_addr->sa_family, a->ai_addrlen);
        fd = socket(a->ai_family, SOCK_STREAM, 0);
        if (fd == -1) {
            log_message(3, "forward to %s failed:socket: %s\n", cnx_name, strerror((*__errno_location ())));
        } else {
            res = connect(fd, a->ai_addr, a->ai_addrlen);
            if (res == -1) {
                log_message(3, "forward to %s failed:connect: %s\n",
                            cnx_name, strerror((*__errno_location ())));
            } else {
                return fd;
            }
        }
    }
    return -1;
}

canonical_original_code:
int connect_addr(struct addrinfo *addr, char *cnx_name)
{
    struct addrinfo *a;
    char buf[1025];
    int fd; int res;
    for (a = addr; a; a = a->ai_next) {
        if (verbose)
            fprintf(stderr, "connecting to %s family %d len %d\n",
                    sprintaddr(buf, sizeof(buf), a),
                    a->ai_addr->sa_family, a->ai_addrlen);
        fd = socket(a->ai_family, SOCK_STREAM, 0);
        if (fd == -1) {
            log_message(3, "forward to %s failed:socket: %s\n", cnx_name, strerror((*__errno_location ())));
        } else {
            res = connect(fd, a->ai_addr, a->ai_addrlen);
            if (res == -1) {
                log_message(3, "forward to %s failed:connect: %s\n",
                            cnx_name, strerror((*__errno_location ())));
            } else {
                return fd;
            }
        }
    }
    return -1;
}

variable_types: fd int


decompiled_code:
__int64 __fastcall resolve_split_name(struct addrinfo **pai, char *name, char *service)
{
int v4; // eax
unsigned int v5; // er12
const char *v7; // rax
struct addrinfo v8; // [rsp+0h] [rbp-48h] BYREF

*(_OWORD *)&v8.ai_flags = 0LL;
*(_OWORD *)&v8.ai_addrlen = 0LL;
v8.ai_socktype = 1;
*(_OWORD *)&v8.ai_canonname = 0LL;
v4 = getaddrinfo(name, service, &v8, pai);
v5 = v4;
if ( v4 )
{
v7 = gai_strerror(v4);
log_message(3, "%s `%s:%s'\n", v7, name, service);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(struct addrinfo **pai, char *name, char *service)
{
int v4; // eax
unsigned int v5; // er12
const char *v7; // rax
struct addrinfo v8; // [rsp+0h] [rbp-48h] BYREF

*(_OWORD *)&v8.ai_flags = 0LL;
*(_OWORD *)&v8.ai_addrlen = 0LL;
v8.ai_socktype = 1;
*(_OWORD *)&v8.ai_canonname = 0LL;
v4 = getaddrinfo(name, service, &v8, pai);
v5 = v4;
if ( v4 )
{
v7 = gai_strerror(v4);
func4(3, "%s `%s:%s'\n", v7, name, service);
}
return v5;
}

original_code:
int resolve_split_name(struct addrinfo **out, const char* host, const char* serv)
{
   struct addrinfo hint;
   int res;
   memset(&hint, 0, sizeof(hint));
   hint.ai_family = 0;
   hint.ai_socktype = SOCK_STREAM;
   res = getaddrinfo(host, serv, &hint, out);
   if (res)
      log_message(3, "%s `%s:%s'\n", gai_strerror(res), host, serv);
   return res;
}

canonical_original_code:
int resolve_split_name(struct addrinfo **out, char *host, char *serv)
{
   struct addrinfo hint;
   int res;
   memset(&hint, 0, sizeof(hint));
   hint.ai_family = 0;
   hint.ai_socktype = SOCK_STREAM;
   res = getaddrinfo(host, serv, &hint, out);
   if (res)
      log_message(3, "%s `%s:%s'\n", gai_strerror(res), host, serv);
   return res;
}

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:
host
char *

variable_types:
serv
char *


decompiled_code:
__int64 __fastcall resolve_name(struct addrinfo **pai, char *name)
{
char *v2; // rax
__int64 result; // rax
int v4; // ebp
const char *v5; // rax

v2 = strrchr(name, 58);
if ( !v2 )
{
fprintf(stderr, "%s: names must be fully specified as hostname:port\n", name);
exit(1);
}
*v2 = 0;
result = resolve_split_name(pai, name, v2 + 1);
v4 = result;
if ( (_DWORD)result )
{
v5 = gai_strerror(result);
fprintf(stderr, "%s `%s'\n", v5, name);
if ( v4 == -8 )
fwrite("(Check you have specified all ports)\n", 1uLL, 0x25uLL, stderr);
exit(4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(struct addrinfo **pai, char *name)
{
char *v2; // rax
__int64 result; // rax
int v4; // ebp
const char *v5; // rax

v2 = strrchr(name, 58);
if ( !v2 )
{
fprintf(stderr, "%s: names must be fully specified as hostname:port\n", name);
exit(1);
}
*v2 = 0;
result = func10(pai, name, v2 + 1);
v4 = result;
if ( (_DWORD)result )
{
v5 = gai_strerror(result);
fprintf(stderr, "%s `%s'\n", v5, name);
if ( v4 == -8 )
fwrite("(Check you have specified all ports)\n", 1uLL, 0x25uLL, stderr);
exit(4);
}
return result;
}

original_code:
void resolve_name(struct addrinfo **out, char* fullname)
{
   char *serv, *host;
   int res;
   char *sep = strrchr(fullname, ':');
   if (!sep)
   {
      fprintf(stderr, "%s: names must be fully specified as hostname:port\n", fullname);
      exit(1);
   }
   host = fullname;
   serv = sep+1;
   *sep = 0;
   res = resolve_split_name(out, host, serv);
   if (res) {
      fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname);
      if (res == -8)
         fprintf(stderr, "(Check you have specified all ports)\n");
      exit(4);
   }
}

canonical_original_code:
void resolve_name(struct addrinfo **out, char *fullname)
{
   char *serv; char *host;
   int res;
   char *sep = strrchr(fullname, ':');
   if (!sep)
   {
      fprintf(stderr, "%s: names must be fully specified as hostname:port\n", fullname);
      exit(1);
   }
   host = fullname;
   serv = sep+1;
   *sep = 0;
   res = resolve_split_name(out, host, serv);
   if (res) {
      fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname);
      if (res == -8)
         fprintf(stderr, "(Check you have specified all ports)\n");
      exit(4);
   }
}

variable_types:
fullname
char *

variable_types:
sep
char *


decompiled_code:
void __fastcall log_connection(__int64 a1)
{
int v2; // edi
int v3; // edi
int v4; // edi
int v5; // edi
_BYTE v6[16]; // [rsp+0h] [rbp-1178h] BYREF
socklen_t len; // [rsp+10h] [rbp-1168h] BYREF
struct sockaddr *v8; // [rsp+18h] [rbp-1160h]
struct sockaddr addr; // [rsp+30h] [rbp-1148h] BYREF
char s[1072]; // [rsp+B0h] [rbp-10C8h] BYREF
char v11[1072]; // [rsp+4E0h] [rbp-C98h] BYREF
char v12[1072]; // [rsp+910h] [rbp-868h] BYREF
char v13[1080]; // [rsp+D40h] [rbp-438h] BYREF

v2 = *(_DWORD *)(a1 + 16);
len = 128;
v8 = &addr;
if ( getpeername(v2, &addr, &len) != -1 )
{
sprintaddr(s, 0x422uLL, (__int64)v6);
v3 = *(_DWORD *)(a1 + 16);
len = 128;
if ( getsockname(v3, v8, &len) != -1 )
{
sprintaddr(v11, 0x422uLL, (__int64)v6);
v4 = *(_DWORD *)(a1 + 48);
len = 128;
if ( getpeername(v4, v8, &len) != -1 )
{
sprintaddr(v13, 0x422uLL, (__int64)v6);
v5 = *(_DWORD *)(a1 + 48);
len = 128;
if ( getsockname(v5, v8, &len) != -1 )
{
sprintaddr(v12, 0x422uLL, (__int64)v6);
log_message(6, "connection from %s to %s forwarded from %s to %s\n", s, v11, v12, v13);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
int v2; // edi
int v3; // edi
int v4; // edi
int v5; // edi
_BYTE v6[16]; // [rsp+0h] [rbp-1178h] BYREF
socklen_t len; // [rsp+10h] [rbp-1168h] BYREF
struct sockaddr *v8; // [rsp+18h] [rbp-1160h]
struct sockaddr addr; // [rsp+30h] [rbp-1148h] BYREF
char s[1072]; // [rsp+B0h] [rbp-10C8h] BYREF
char v11[1072]; // [rsp+4E0h] [rbp-C98h] BYREF
char v12[1072]; // [rsp+910h] [rbp-868h] BYREF
char v13[1080]; // [rsp+D40h] [rbp-438h] BYREF

v2 = *(_DWORD *)(a1 + 16);
len = 128;
v8 = &addr;
if ( getpeername(v2, &addr, &len) != -1 )
{
func6(s, 0x422uLL, (__int64)v6);
v3 = *(_DWORD *)(a1 + 16);
len = 128;
if ( getsockname(v3, v8, &len) != -1 )
{
func6(v11, 0x422uLL, (__int64)v6);
v4 = *(_DWORD *)(a1 + 48);
len = 128;
if ( getpeername(v4, v8, &len) != -1 )
{
func6(v13, 0x422uLL, (__int64)v6);
v5 = *(_DWORD *)(a1 + 48);
len = 128;
if ( getsockname(v5, v8, &len) != -1 )
{
func6(v12, 0x422uLL, (__int64)v6);
func4(6, "connection from %s to %s forwarded from %s to %s\n", s, v11, v12, v13);
}
}
}
}
}

original_code:
void log_connection(struct connection *cnx)
{
    struct addrinfo addr;
    struct sockaddr_storage ss;
    char peer[(1025 + 32 + 1)], service[(1025 + 32 + 1)],
        local[(1025 + 32 + 1)], target[(1025 + 32 + 1)];
    int res;
    addr.ai_addr = (struct sockaddr*)&ss;
    addr.ai_addrlen = sizeof(ss);
    res = getpeername(cnx->q[0].fd, addr.ai_addr, &addr.ai_addrlen);
    if (res == -1) return;
    sprintaddr(peer, sizeof(peer), &addr);
    addr.ai_addrlen = sizeof(ss);
    res = getsockname(cnx->q[0].fd, addr.ai_addr, &addr.ai_addrlen);
    if (res == -1) return;
    sprintaddr(service, sizeof(service), &addr);
    addr.ai_addrlen = sizeof(ss);
    res = getpeername(cnx->q[1].fd, addr.ai_addr, &addr.ai_addrlen);
    if (res == -1) return;
    sprintaddr(target, sizeof(target), &addr);
    addr.ai_addrlen = sizeof(ss);
    res = getsockname(cnx->q[1].fd, addr.ai_addr, &addr.ai_addrlen);
    if (res == -1) return;
    sprintaddr(local, sizeof(local), &addr);
    log_message(6, "connection from %s to %s forwarded from %s to %s\n",
                peer,
                service,
                local,
                target);
}

canonical_original_code:
void log_connection(struct connection *cnx)
{
    struct addrinfo addr;
    struct sockaddr_storage ss;
    char peer[-1]; char service[-1]; char local[-1]; char target[-1];
    int res;
    addr.ai_addr = (struct sockaddr *)&ss;
    addr.ai_addrlen = sizeof(ss);
    res = getpeername(cnx->q[0].fd, addr.ai_addr, &addr.ai_addrlen);
    if (res == -1) return;
    sprintaddr(peer, sizeof(peer), &addr);
    addr.ai_addrlen = sizeof(ss);
    res = getsockname(cnx->q[0].fd, addr.ai_addr, &addr.ai_addrlen);
    if (res == -1) return;
    sprintaddr(service, sizeof(service), &addr);
    addr.ai_addrlen = sizeof(ss);
    res = getpeername(cnx->q[1].fd, addr.ai_addr, &addr.ai_addrlen);
    if (res == -1) return;
    sprintaddr(target, sizeof(target), &addr);
    addr.ai_addrlen = sizeof(ss);
    res = getsockname(cnx->q[1].fd, addr.ai_addr, &addr.ai_addrlen);
    if (res == -1) return;
    sprintaddr(local, sizeof(local), &addr);
    log_message(6, "connection from %s to %s forwarded from %s to %s\n",
                peer,
                service,
                local,
                target);
}

variable_types: struct connection { enum connection_state { ST_PROBING=1, ST_SHOVELING=2 } state; long probe_timeout; struct queue { int fd; void *begin_defered_data; void *defered_data; int defered_data_size; } q[2]; } *

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: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
peer
char [-1]

variable_types:
service
char [-1]

variable_types:
local
char [-1]

variable_types:
target
char [-1]


decompiled_code:
__int64 check_access_rights()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
return 0LL;
}

original_code:
int check_access_rights(int in_socket, const char* service)
{
    return 0;
}

canonical_original_code:
int check_access_rights(int in_socket, char *service)
{
    return 0;
}

variable_types:
service
char *


decompiled_code:
int setup_signals()
{
int result; // eax
struct sigaction vars0; // [rsp+0h] [rbp+0h] BYREF

memset(&vars0, 0, sizeof(vars0));
vars0.sa_flags = 2;
if ( sigaction(17, &vars0, 0LL) == -1
|| (vars0.sa_handler = (__sighandler_t)&exit, memset(&vars0.sa_mask, 0, 0x90uLL), sigaction(15, &vars0, 0LL) == -1)
|| (vars0.sa_handler = (__sighandler_t)(defer_write + 1), result = sigaction(13, &vars0, 0LL), result == -1) )
{
perror("sigaction");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func14()
{
int result; // eax
struct sigaction vars0; // [rsp+0h] [rbp+0h] BYREF

memset(&vars0, 0, sizeof(vars0));
vars0.sa_flags = 2;
if ( sigaction(17, &vars0, 0LL) == -1
|| (vars0.sa_handler = (__sighandler_t)&exit, memset(&vars0.sa_mask, 0, 0x90uLL), sigaction(15, &vars0, 0LL) == -1)
|| (vars0.sa_handler = (__sighandler_t)(defer_write + 1), result = sigaction(13, &vars0, 0LL), result == -1) )
{
perror("sigaction");
exit(1);
}
return result;
}

original_code:
void setup_signals(void)
{
    int res;
    struct sigaction action;
    memset(&action, 0, sizeof(action));
    action.__sigaction_handler.sa_handler = ((void *)0);
    action.sa_flags = 2;
    res = sigaction(17, &action, ((void *)0));
    if (res == -1) { perror("sigaction"); exit(1); };
    memset(&action, 0, sizeof(action));
    action.__sigaction_handler.sa_handler = exit;
    res = sigaction(15, &action, ((void *)0));
    if (res == -1) { perror("sigaction"); exit(1); };
    action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
    res = sigaction(13, &action, ((void *)0));
    if (res == -1) { perror("sigaction"); exit(1); };
}

canonical_original_code:
void setup_signals()
{
    int res;
    struct sigaction action;
    memset(&action, 0, sizeof(action));
    action.__sigaction_handler.sa_handler = ((void *)0);
    action.sa_flags = 2;
    res = sigaction(17, &action, ((void *)0));
    if (res == -1) { perror("sigaction"); exit(1); };
    memset(&action, 0, sizeof(action));
    action.__sigaction_handler.sa_handler = exit;
    res = sigaction(15, &action, ((void *)0));
    if (res == -1) { perror("sigaction"); exit(1); };
    action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
    res = sigaction(13, &action, ((void *)0));
    if (res == -1) { perror("sigaction"); exit(1); };
}

variable_types: res int

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

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

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


decompiled_code:
void __fastcall setup_syslog(const char *a1)
{
char *v1; // rbp
unsigned int v2; // er12
char *v3; // rax
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v1 = strdup(a1);
v2 = getpid();
v3 = _xpg_basename(v1);
asprintf(&ptr, "%s[%d]", v3, v2);
openlog(ptr, 2, 32);
free(v1);
log_message(6, "%s %s started\n", server_type, "1.14");
}

canonical_decompiled_code:
void __fastcall func15(const char *a1)
{
char *v1; // rbp
unsigned int v2; // er12
char *v3; // rax
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v1 = strdup(a1);
v2 = getpid();
v3 = _xpg_basename(v1);
asprintf(&ptr, "%s[%d]", v3, v2);
openlog(ptr, 2, 32);
free(v1);
func4(6, "%s %s started\n", server_type, "1.14");
}

original_code:
void setup_syslog(const char* bin_name) {
    char *name1, *name2;
    name1 = strdup(bin_name);
    asprintf(&name2, "%s[%d]", __xpg_basename(name1), getpid());
    openlog(name2, 0x02, (4<<3));
    free(name1);
    log_message(6, "%s %s started\n", server_type, "1.14");
}

canonical_original_code:
void setup_syslog(char *bin_name) {
    char *name1; char *name2;
    name1 = strdup(bin_name);
    asprintf(&name2, "%s[%d]", __xpg_basename(name1), getpid());
    openlog(name2, 0x02, (4<<3));
    free(name1);
    log_message(6, "%s %s started\n", server_type, "1.14");
}


decompiled_code:
int __fastcall drop_privileges(const char *a1)
{
struct passwd *v1; // rax
struct passwd *v2; // rbx

v1 = getpwnam(a1);
if ( !v1 )
{
fprintf(stderr, "%s: not found\n", a1);
exit(2);
}
v2 = v1;
if ( verbose )
fprintf(stderr, "turning into %s\n", a1);
if ( setgid(v2->pw_gid) == -1 )
{
perror("setgid");
exit(1);
}
return setuid(v2->pw_uid);
}

canonical_decompiled_code:
int __fastcall func16(const char *a1)
{
struct passwd *v1; // rax
struct passwd *v2; // rbx

v1 = getpwnam(a1);
if ( !v1 )
{
fprintf(stderr, "%s: not found\n", a1);
exit(2);
}
v2 = v1;
if ( verbose )
fprintf(stderr, "turning into %s\n", a1);
if ( setgid(v2->pw_gid) == -1 )
{
perror("setgid");
exit(1);
}
return setuid(v2->pw_uid);
}

original_code:
void drop_privileges(const char* user_name)
{
    int res;
    struct passwd *pw = getpwnam(user_name);
    if (!pw) {
        fprintf(stderr, "%s: not found\n", user_name);
        exit(2);
    }
    if (verbose)
        fprintf(stderr, "turning into %s\n", user_name);
    res = setgid(pw->pw_gid);
    if (res == -1) { perror("setgid"); exit(1); };
    setuid(pw->pw_uid);
    if (res == -1) { perror("setuid"); exit(1); };
}

canonical_original_code:
void drop_privileges(char *user_name)
{
    int res;
    struct passwd *pw = getpwnam(user_name);
    if (!pw) {
        fprintf(stderr, "%s: not found\n", user_name);
        exit(2);
    }
    if (verbose)
        fprintf(stderr, "turning into %s\n", user_name);
    res = setgid(pw->pw_gid);
    if (res == -1) { perror("setgid"); exit(1); };
    setuid(pw->pw_uid);
    if (res == -1) { perror("setuid"); exit(1); };
}

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


decompiled_code:
int print_usage()
{
int v0; // ebp
const char **v1; // rbx
const char *v2; // rcx
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v0 = 0;
ptr = (char *)&unk_A8E;
v1 = (const char **)get_builtins();
while ( (int)get_num_builtins() > v0 )
{
v2 = *v1;
++v0;
v1 += 6;
asprintf(&ptr, "%s\t[--%s <addr>]\n", ptr, v2);
}
return fprintf(stderr, USAGE_STRING, ptr);
}

canonical_decompiled_code:
int func1()
{
int v0; // ebp
const char **v1; // rbx
const char *v2; // rcx
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v0 = 0;
ptr = (char *)&unk_A8E;
v1 = (const char **)get_builtins();
while ( (int)get_num_builtins() > v0 )
{
v2 = *v1;
++v0;
v1 += 6;
asprintf(&ptr, "%s\t[--%s <addr>]\n", ptr, v2);
}
return fprintf(stderr, USAGE_STRING, ptr);
}

original_code:
static void print_usage(void)
{
    struct proto *p;
    int i;
    char *prots = "";
    p = get_builtins();
    for (i = 0; i < get_num_builtins(); i++)
        asprintf(&prots, "%s\t[--%s <addr>]\n", prots, p[i].description);
    fprintf(stderr, USAGE_STRING, prots);
}

canonical_original_code:
static void print_usage()
{
    struct proto *p;
    int i;
    char *prots = "";
    p = get_builtins();
    for (i = 0; i < get_num_builtins(); i++)
        asprintf(&prots, "%s\t[--%s <addr>]\n", prots, p[i].description);
    fprintf(stderr, USAGE_STRING, prots);
}

variable_types: struct proto { char *description; char *service; 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; } *saddr; int (*probe)(char *, int, struct proto *); void *data; struct proto *next; } *

variable_types: i int

variable_types:
prots
char *

user_defined_types: struct proto { char *description; char *service; struct addrinfo *saddr; int (*probe)(char *, int, struct proto *); void *data; struct proto *next; }


printsettings

decompiled_code:
int printsettings()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v2; // rdx
const char *v3; // r12
unsigned int v4; // er13
__int64 v5; // r14
const char *v6; // rax
__int64 i; // rbx
const char *v8; // rax
const char **v9; // rax
_BYTE v11[1080]; // [rsp+0h] [rbp-438h] BYREF

v0 = get_first_protocol();
if ( v0 )
{
v1 = v0;
do
{
v2 = *(_QWORD *)(v1 + 16);
v3 = *(const char **)(v1 + 8);
v4 = *(_DWORD *)(v2 + 4);
v5 = **(unsigned __int16 **)(v2 + 24);
v6 = (const char *)sprintaddr(v11, 1025LL);
fprintf(stderr, "%s addr: %s. libwrap service: %s family %d %d\n", *(const char **)v1, v6, v3, v4, v5);
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
}
fwrite("listening on:\n", 1uLL, 0xEuLL, stderr);
for ( i = addr_listen; i; i = *(_QWORD *)(i + 40) )
{
v8 = (const char *)sprintaddr(v11, 1025LL);
fprintf(stderr, "\t%s\n", v8);
}
v9 = (const char **)timeout_protocol();
return fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout, *v9);
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v2; // rdx
const char *v3; // r12
unsigned int v4; // er13
__int64 v5; // r14
const char *v6; // rax
__int64 i; // rbx
const char *v8; // rax
const char **v9; // rax
_BYTE v11[1080]; // [rsp+0h] [rbp-438h] BYREF

v0 = get_first_protocol();
if ( v0 )
{
v1 = v0;
do
{
v2 = *(_QWORD *)(v1 + 16);
v3 = *(const char **)(v1 + 8);
v4 = *(_DWORD *)(v2 + 4);
v5 = **(unsigned __int16 **)(v2 + 24);
v6 = (const char *)sprintaddr(v11, 1025LL);
fprintf(stderr, "%s addr: %s. libwrap service: %s family %d %d\n", *(const char **)v1, v6, v3, v4, v5);
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
}
fwrite("listening on:\n", 1uLL, 0xEuLL, stderr);
for ( i = addr_listen; i; i = *(_QWORD *)(i + 40) )
{
v8 = (const char *)sprintaddr(v11, 1025LL);
fprintf(stderr, "\t%s\n", v8);
}
v9 = (const char **)timeout_protocol();
return fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout, *v9);
}

original_code:
static void printsettings(void)
{
    char buf[1025];
    struct addrinfo *a;
    struct proto *p;
    for (p = get_first_protocol(); p; p = p->next) {
        fprintf(stderr,
                "%s addr: %s. libwrap service: %s family %d %d\n",
                p->description,
                sprintaddr(buf, sizeof(buf), p->saddr),
                p->service,
                p->saddr->ai_family,
                p->saddr->ai_addr->sa_family);
    }
    fprintf(stderr, "listening on:\n");
    for (a = addr_listen; a; a = a->ai_next) {
        fprintf(stderr, "\t%s\n", sprintaddr(buf, sizeof(buf), a));
    }
    fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout,
            timeout_protocol()->description);
}

canonical_original_code:
static void printsettings()
{
    char buf[1025];
    struct addrinfo *a;
    struct proto *p;
    for (p = get_first_protocol(); p; p = p->next) {
        fprintf(stderr,
                "%s addr: %s. libwrap service: %s family %d %d\n",
                p->description,
                sprintaddr(buf, sizeof(buf), p->saddr),
                p->service,
                p->saddr->ai_family,
                p->saddr->ai_addr->sa_family);
    }
    fprintf(stderr, "listening on:\n");
    for (a = addr_listen; a; a = a->ai_next) {
        fprintf(stderr, "\t%s\n", sprintaddr(buf, sizeof(buf), a));
    }
    fprintf(stderr, "timeout: %d\non-timeout: %s\n", probing_timeout,
            timeout_protocol()->description);
}

variable_types:
buf
char [1025]

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


decompiled_code:
void make_alloptions()
{
int v0; // eax
int v1; // eax

builtins = get_builtins();
v0 = get_num_builtins();
all_options = (struct option *)calloc(v0 + 12LL, 0x20uLL);
qmemcpy(all_options, &const_options, 0x180uLL);
v1 = get_num_builtins();
append_protocols_constprop_0((__int64)all_options, (__int64 *)builtins, v1);
}

canonical_decompiled_code:
void func5()
{
int v0; // eax
int v1; // eax

builtins = get_builtins();
v0 = get_num_builtins();
all_options = (struct option *)calloc(v0 + 12LL, 0x20uLL);
qmemcpy(all_options, &const_options, 0x180uLL);
v1 = get_num_builtins();
func4((__int64)all_options, (__int64 *)builtins, v1);
}

original_code:
static void make_alloptions(void)
{
    builtins = get_builtins();
    all_options = calloc((sizeof(const_options) / sizeof(const_options[0])) + get_num_builtins(), sizeof(struct option));
    memcpy(all_options, const_options, sizeof(const_options));
    append_protocols(all_options, (sizeof(const_options) / sizeof(const_options[0])) - 1, builtins, get_num_builtins());
}

canonical_original_code:
static void make_alloptions()
{
    builtins = get_builtins();
    all_options = calloc((sizeof(const_options) / sizeof(const_options[0])) + get_num_builtins(), sizeof(struct option));
    memcpy(all_options, const_options, sizeof(const_options));
    append_protocols(all_options, (sizeof(const_options) / sizeof(const_options[0])) - 1, builtins, get_num_builtins());
}

user_defined_types: struct option { char *name; int has_arg; int *flag; int val; }


decompiled_code:
__int64 __fastcall parse_cmdline(int argc, char **argv, __m128i *a3)
{
const struct option *v6; // r13
int v7; // eax
__m128i *v8; // r14
__int64 v9; // r15
__m128i *v10; // r13
__int64 v11; // rax
void *v12; // rdi
__int64 v13; // rdi
__m128i *v14; // rax
char *v15; // rsi
__int64 result; // rax
__int64 v17; // [rsp+8h] [rbp-40h]

v6 = all_options;
optind = 1;
opterr = 1;
LABEL_2:
while ( 1 )
{
v7 = getopt_long_only(argc, argv, "vt:T:p:VP:F:", v6, 0LL);
if ( v7 == -1 )
break;
if ( v7 )
{
if ( v7 <= 999 )
{
if ( v7 <= 118 )
{
if ( v7 > 69 )
{
switch ( v7 )
{
case 'F':
continue;
case 'P':
pid_file = optarg;
continue;
case 'V':
printf("%s %s\n", server_type, "1.14");
exit(0);
case 'p':
v11 = addr_listen;
v12 = &addr_listen;
if ( addr_listen )
{
do
{
v13 = v11;
v11 = *(_QWORD *)(v11 + 40);
}
while ( v11 );
v12 = (void *)(v13 + 40);
}
resolve_name(v12, optarg);
v6 = all_options;
continue;
case 't':
probing_timeout = atoi(optarg);
continue;
case 'u':
user_name = optarg;
continue;
case 'v':
++verbose;
continue;
default:
break;
}
}
LABEL_31:
print_usage();
exit(2);
}
if ( v7 != 257 )
goto LABEL_31;
set_ontimeout(optarg);
v6 = all_options;
}
else
{
v8 = a3;
v17 = 48LL * v7 - 48000;
v9 = v17 + builtins;
if ( a3 )
{
while ( 1 )
{
v10 = v8;
v8 = (__m128i *)v8[2].m128i_i64[1];
if ( !v8 )
break;
if ( !strcmp((const char *)v10->m128i_i64[0], *(const char **)v9) )
{
resolve_name(&v10[1], optarg);
v10[1].m128i_i64[1] = *(_QWORD *)(builtins + v17 + 24);
v6 = all_options;
goto LABEL_2;
}
}
v14 = (__m128i *)calloc(1uLL, 0x30uLL);
v10[2].m128i_i64[1] = (__int64)v14;
}
else
{
v14 = (__m128i *)calloc(1uLL, 0x30uLL);
a3 = v14;
}
v15 = optarg;
*v14 = _mm_loadu_si128((const __m128i *)v9);
v14[1] = _mm_loadu_si128((const __m128i *)(v9 + 16));
v14[2] = _mm_loadu_si128((const __m128i *)(v9 + 32));
resolve_name(&v14[1], v15);
v6 = all_options;
}
}
}
if ( !a3 )
{
fwrite("At least one target protocol must be specified.\n", 1uLL, 0x30uLL, stderr);
exit(2);
}
result = set_protocol_list(a3);
if ( !addr_listen )
{
fwrite("No listening address specified; use at least one -p option\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
if ( background )
foreground = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv, __m128i *a3)
{
const struct option *v6; // r13
int v7; // eax
__m128i *v8; // r14
__int64 v9; // r15
__m128i *v10; // r13
__int64 v11; // rax
void *v12; // rdi
__int64 v13; // rdi
__m128i *v14; // rax
char *v15; // rsi
__int64 result; // rax
__int64 v17; // [rsp+8h] [rbp-40h]

v6 = all_options;
optind = 1;
opterr = 1;
LABEL_2:
while ( 1 )
{
v7 = getopt_long_only(argc, argv, "vt:T:p:VP:F:", v6, 0LL);
if ( v7 == -1 )
break;
if ( v7 )
{
if ( v7 <= 999 )
{
if ( v7 <= 118 )
{
if ( v7 > 69 )
{
switch ( v7 )
{
case 'F':
continue;
case 'P':
pid_file = optarg;
continue;
case 'V':
printf("%s %s\n", server_type, "1.14");
exit(0);
case 'p':
v11 = addr_listen;
v12 = &addr_listen;
if ( addr_listen )
{
do
{
v13 = v11;
v11 = *(_QWORD *)(v11 + 40);
}
while ( v11 );
v12 = (void *)(v13 + 40);
}
resolve_name(v12, optarg);
v6 = all_options;
continue;
case 't':
probing_timeout = atoi(optarg);
continue;
case 'u':
user_name = optarg;
continue;
case 'v':
++verbose;
continue;
default:
break;
}
}
LABEL_31:
func1();
exit(2);
}
if ( v7 != 257 )
goto LABEL_31;
set_ontimeout(optarg);
v6 = all_options;
}
else
{
v8 = a3;
v17 = 48LL * v7 - 48000;
v9 = v17 + builtins;
if ( a3 )
{
while ( 1 )
{
v10 = v8;
v8 = (__m128i *)v8[2].m128i_i64[1];
if ( !v8 )
break;
if ( !strcmp((const char *)v10->m128i_i64[0], *(const char **)v9) )
{
resolve_name(&v10[1], optarg);
v10[1].m128i_i64[1] = *(_QWORD *)(builtins + v17 + 24);
v6 = all_options;
goto LABEL_2;
}
}
v14 = (__m128i *)calloc(1uLL, 0x30uLL);
v10[2].m128i_i64[1] = (__int64)v14;
}
else
{
v14 = (__m128i *)calloc(1uLL, 0x30uLL);
a3 = v14;
}
v15 = optarg;
*v14 = _mm_loadu_si128((const __m128i *)v9);
v14[1] = _mm_loadu_si128((const __m128i *)(v9 + 16));
v14[2] = _mm_loadu_si128((const __m128i *)(v9 + 32));
resolve_name(&v14[1], v15);
v6 = all_options;
}
}
}
if ( !a3 )
{
fwrite("At least one target protocol must be specified.\n", 1uLL, 0x30uLL, stderr);
exit(2);
}
result = set_protocol_list(a3);
if ( !addr_listen )
{
fwrite("No listening address specified; use at least one -p option\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
if ( background )
foreground = 0;
return result;
}

original_code:
static void parse_cmdline(int argc, char* argv[], struct proto* prots)
{
    int c;
    struct addrinfo **a;
    struct proto *p;
    optind = 1;
    opterr = 1;
next_arg:
    while ((c = getopt_long_only(argc, argv, optstr, all_options, ((void *)0))) != -1) {
        if (c == 0) continue;
        if (c >= 1000) {
            if (prots)
                for (p = prots; p && p->next; p = p->next) {
                    if (!strcmp(p->description, builtins[c-1000].description)) {
                        resolve_name(&(p->saddr), optarg);
                        p->probe = builtins[c-1000].probe;
                        goto next_arg;
                    }
                }
            if (!prots) {
                p = prots = calloc(1, sizeof(*p));
            } else {
                p->next = calloc(1, sizeof(*p));
                p = p->next;
            }
            memcpy(p, &builtins[c-1000], sizeof(*p));
            resolve_name(&(p->saddr), optarg);
            continue;
        }
        switch (c) {
        case 'F':
            break;
        case 't':
             probing_timeout = atoi(optarg);
            break;
        case 257:
            set_ontimeout(optarg);
            break;
        case 'p':
            for (a = &addr_listen; *a; a = &((*a)->ai_next));
            resolve_name(a, optarg);
            break;
        case 'V':
            printf("%s %s\n", server_type, "1.14");
            exit(0);
        case 'u':
            user_name = optarg;
            break;
        case 'P':
            pid_file = optarg;
            break;
        case 'v':
            verbose++;
            break;
        default:
            print_usage();
            exit(2);
        }
    }
    if (!prots) {
        fprintf(stderr, "At least one target protocol must be specified.\n");
        exit(2);
    }
    set_protocol_list(prots);
    if (!addr_listen) {
        fprintf(stderr, "No listening address specified; use at least one -p option\n");
        exit(1);
    }
    if (background)
        foreground = 0;
}

canonical_original_code:
static void parse_cmdline(int argc, char *argv[], struct proto *prots)
{
    int c;
    struct addrinfo **a;
    struct proto *p;
    optind = 1;
    opterr = 1;
next_arg:
    while ((c = getopt_long_only(argc, argv, optstr, all_options, ((void *)0))) != -1) {
        if (c == 0) continue;
        if (c >= 1000) {
            if (prots)
                for (p = prots; p && p->next; p = p->next) {
                    if (!strcmp(p->description, builtins[c-1000].description)) {
                        resolve_name(&(p->saddr), optarg);
                        p->probe = builtins[c-1000].probe;
                        goto next_arg;
                    }
                }
            if (!prots) {
                p = prots = calloc(1, sizeof(*p));
            } else {
                p->next = calloc(1, sizeof(*p));
                p = p->next;
            }
            memcpy(p, &builtins[c-1000], sizeof(*p));
            resolve_name(&(p->saddr), optarg);
            continue;
        }
        switch (c) {
        case 'F':
            break;
        case 't':
             probing_timeout = atoi(optarg);
            break;
        case 257:
            set_ontimeout(optarg);
            break;
        case 'p':
            for (a = &addr_listen; *a; a = &((*a)->ai_next));
            resolve_name(a, optarg);
            break;
        case 'V':
            printf("%s %s\n", server_type, "1.14");
            exit(0);
        case 'u':
            user_name = optarg;
            break;
        case 'P':
            pid_file = optarg;
            break;
        case 'v':
            verbose++;
            break;
        default:
            print_usage();
            exit(2);
        }
    }
    if (!prots) {
        fprintf(stderr, "At least one target protocol must be specified.\n");
        exit(2);
    }
    set_protocol_list(prots);
    if (!addr_listen) {
        fprintf(stderr, "No listening address specified; use at least one -p option\n");
        exit(1);
    }
    if (background)
        foreground = 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__m128i *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

pid_file = 0LL;
v5 = 0LL;
user_name = 0LL;
cmdline_config_constprop_0(argc, (char **)argv, &v5);
parse_cmdline(argc, (char **)argv, v5);
if ( inetd )
{
verbose = 0;
start_shoveler(0LL);
exit(0);
}
if ( verbose )
printsettings();
v3 = start_listen_sockets(v6, addr_listen);
if ( !foreground )
{
if ( fork() > 0 )
exit(0);
if ( !getuid() && setsid() == -1 )
{
perror("setsid: already process leader");
exit(1);
}
}
setup_signals();
if ( pid_file )
write_pid_file();
if ( user_name )
drop_privileges();
setup_syslog(*argv);
main_loop(v6[0], v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__m128i *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

pid_file = 0LL;
v5 = 0LL;
user_name = 0LL;
func9(argc, (char **)argv, &v5);
func2(argc, (char **)argv, v5);
if ( inetd )
{
verbose = 0;
start_shoveler(0LL);
exit(0);
}
if ( verbose )
func3();
v3 = start_listen_sockets(v6, addr_listen);
if ( !foreground )
{
if ( fork() > 0 )
exit(0);
if ( !getuid() && setsid() == -1 )
{
perror("setsid: already process leader");
exit(1);
}
}
setup_signals();
if ( pid_file )
write_pid_file();
if ( user_name )
drop_privileges();
setup_syslog(*argv);
main_loop(v6[0], v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
   extern char *optarg;
   extern int optind;
   int res, num_addr_listen;
   struct proto* protocols = ((void *)0);
   int *listen_sockets;
   pid_file = ((void *)0);
   user_name = ((void *)0);
   cmdline_config(argc, argv, &protocols);
   parse_cmdline(argc, argv, protocols);
   if (inetd)
   {
       verbose = 0;
       start_shoveler(0);
       exit(0);
   }
   if (verbose)
       printsettings();
   num_addr_listen = start_listen_sockets(&listen_sockets, addr_listen);
   if (!foreground) {
       if (fork() > 0) exit(0);
       if (getuid() == 0) {
           res = setsid();
           if (res == -1) { perror("setsid: already process leader"); exit(1); };
       }
   }
   setup_signals();
   if (pid_file)
       write_pid_file(pid_file);
   if (user_name)
       drop_privileges(user_name);
   setup_syslog(argv[0]);
   main_loop(listen_sockets, num_addr_listen);
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   extern char *optarg;
   extern int optind;
   int res; int num_addr_listen;
   struct proto *protocols = ((void *)0);
   int *listen_sockets;
   pid_file = ((void *)0);
   user_name = ((void *)0);
   cmdline_config(argc, argv, &protocols);
   parse_cmdline(argc, argv, protocols);
   if (inetd)
   {
       verbose = 0;
       start_shoveler(0);
       exit(0);
   }
   if (verbose)
       printsettings();
   num_addr_listen = start_listen_sockets(&listen_sockets, addr_listen);
   if (!foreground) {
       if (fork() > 0) exit(0);
       if (getuid() == 0) {
           res = setsid();
           if (res == -1) { perror("setsid: already process leader"); exit(1); };
       }
   }
   setup_signals();
   if (pid_file)
       write_pid_file(pid_file);
   if (user_name)
       drop_privileges(user_name);
   setup_syslog(argv[0]);
   main_loop(listen_sockets, num_addr_listen);
   return 0;
}

variable_types:
optarg
char *

variable_types: optind int


decompiled_code:
__int64 is_true()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code: static int is_true(const char *p, int len, struct proto* proto) { return 1; }

canonical_original_code: static int is_true(char *p, int len, struct proto *proto) { return 1; }

variable_types:
p
char *

variable_types: len int


decompiled_code:
_BOOL8 __fastcall is_tls_protocol(_BYTE *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == 22 && a1[1] == 3 )
result = a1[2] <= 3u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_BYTE *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == 22 && a1[1] == 3 )
result = a1[2] <= 3u;
return result;
}

original_code:
static int is_tls_protocol(const char *p, int len, struct proto *proto)
{
    return p[0] == 0x16 && p[1] == 0x03 && ( p[2] >= 0 && p[2] <= 0x03);
}

canonical_original_code:
static int is_tls_protocol(char *p, int len, struct proto *proto)
{
    return p[0] == 0x16 && p[1] == 0x03 && ( p[2] >= 0 && p[2] <= 0x03);
}


decompiled_code:
_BOOL8 __fastcall is_xmpp_protocol(const char *a1)
{
return strstr(a1, "jabber") != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1)
{
return strstr(a1, "jabber") != 0LL;
}

original_code:
static int is_xmpp_protocol( const char *p, int len, struct proto *proto)
{
    return strstr(p, "jabber") ? 1 : 0;
}

canonical_original_code:
static int is_xmpp_protocol(char *p, int len, struct proto *proto)
{
    return strstr(p, "jabber") ? 1 : 0;
}


decompiled_code:
_BOOL8 __fastcall is_http_protocol(const char *a1)
{
return strstr(a1, "HTTP") != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
return strstr(a1, "HTTP") != 0LL;
}

original_code:
static int is_http_protocol(const char *p, int len, struct proto *proto)
{
    if (strstr(p, "HTTP"))
        return 1;
    probe_http_method(p, "OPTIONS");
    probe_http_method(p, "GET");
    probe_http_method(p, "HEAD");
    probe_http_method(p, "POST");
    probe_http_method(p, "PUT");
    probe_http_method(p, "DELETE");
    probe_http_method(p, "TRACE");
    probe_http_method(p, "CONNECT");
    return 0;
}

canonical_original_code:
static int is_http_protocol(char *p, int len, struct proto *proto)
{
    if (strstr(p, "HTTP"))
        return 1;
    probe_http_method(p, "OPTIONS");
    probe_http_method(p, "GET");
    probe_http_method(p, "HEAD");
    probe_http_method(p, "POST");
    probe_http_method(p, "PUT");
    probe_http_method(p, "DELETE");
    probe_http_method(p, "TRACE");
    probe_http_method(p, "CONNECT");
    return 0;
}


decompiled_code:
char **__fastcall get_protocol(char *s2)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcmp(builtins[6 * v1], s2) )
{
if ( ++v1 == 8 )
return 0LL;
}
return &builtins[6 * (int)v1];
}

canonical_decompiled_code:
char **__fastcall func4(char *s2)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcmp(builtins[6 * v1], s2) )
{
if ( ++v1 == 8 )
return 0LL;
}
return &builtins[6 * (int)v1];
}

original_code:
static struct proto* get_protocol(const char* description)
{
    int i;
    for (i = 0; i < (sizeof(builtins) / sizeof(builtins[0])); i++) {
        if (!strcmp(builtins[i].description, description)) {
            return &builtins[i];
        }
    }
    return ((void *)0);
}

canonical_original_code:
static struct proto *get_protocol(char *description)
{
    int i;
    for (i = 0; i < (sizeof(builtins) / sizeof(builtins[0])); i++) {
        if (!strcmp(builtins[i].description, description)) {
            return &builtins[i];
        }
    }
    return ((void *)0);
}

variable_types:
description
char *

return_type: struct proto { char *description; char *service; 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; } *saddr; int (*probe)(char *, int, struct proto *); void *data; struct proto *next; } *


decompiled_code:
_BOOL8 __fastcall is_tinc_protocol(unsigned __int8 *a1)
{
int v1; // eax

v1 = *a1 - 48;
if ( *a1 == 48 )
v1 = a1[1] - 32;
return v1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned __int8 *a1)
{
int v1; // eax

v1 = *a1 - 48;
if ( *a1 == 48 )
v1 = a1[1] - 32;
return v1 == 0;
}

original_code:
static int is_tinc_protocol( const char *p, int len, struct proto *proto)
{
    return !strncmp(p, "0 ", 2);
}

canonical_original_code:
static int is_tinc_protocol(char *p, int len, struct proto *proto)
{
    return !strncmp(p, "0 ", 2);
}


decompiled_code:
_BOOL8 __fastcall is_ssh_protocol(const void *a1)
{
return memcmp(a1, "SSH-", 4uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const void *a1)
{
return memcmp(a1, "SSH-", 4uLL) == 0;
}

original_code:
static int is_ssh_protocol(const char *p, int len, struct proto *proto)
{
    if (!strncmp(p, "SSH-", 4)) {
        return 1;
    }
    return 0;
}

canonical_original_code:
static int is_ssh_protocol(char *p, int len, struct proto *proto)
{
    if (!strncmp(p, "SSH-", 4)) {
        return 1;
    }
    return 0;
}


decompiled_code:
_BOOL8 __fastcall is_openvpn_protocol(__int16 *a1, int a2)
{
return a2 - 2 == (unsigned __int16)_bswap_16(*a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int16 *a1, int a2)
{
return a2 - 2 == (unsigned __int16)func7(*a1);
}

original_code:
static int is_openvpn_protocol (const char*p,int len, struct proto *proto)
{
    int packet_len = ntohs(*(uint16_t*)p);
    return packet_len == len - 2;
}

canonical_original_code:
static int is_openvpn_protocol(char *p, int len, struct proto *proto)
{
    int packet_len = ntohs(*(uint16_t*)p);
    return packet_len == len - 2;
}


decompiled_code:
char **get_builtins()
{
return builtins;
}

canonical_decompiled_code:
char **func10()
{
return builtins;
}

original_code:
struct proto* get_builtins(void) {
    return builtins;
}

canonical_original_code:
struct proto *get_builtins() {
    return builtins;
}


decompiled_code:
__int64 get_num_builtins()
{
return 8LL;
}

canonical_decompiled_code:
__int64 func11()
{
return 8LL;
}

original_code:
int get_num_builtins(void) {
    return (sizeof(builtins) / sizeof(builtins[0]));
}

canonical_original_code:
int get_num_builtins() {
    return (sizeof(builtins) / sizeof(builtins[0]));
}


decompiled_code:
int __fastcall set_ontimeout(const char *a1)
{
return asprintf(&on_timeout, "%s", a1);
}

canonical_decompiled_code:
int __fastcall func12(const char *a1)
{
return asprintf(&on_timeout, "%s", a1);
}

original_code:
void set_ontimeout(const char* name)
{
    asprintf(&on_timeout, "%s", name);
}

canonical_original_code:
void set_ontimeout(char *name)
{
    asprintf(&on_timeout, "%s", name);
}

variable_types:
name
char *


decompiled_code:
__int64 get_first_protocol()
{
return protocols;
}

canonical_decompiled_code:
__int64 func13()
{
return protocols;
}

original_code:
struct proto* get_first_protocol(void)
{
    return protocols;
}

canonical_original_code:
struct proto *get_first_protocol()
{
    return protocols;
}


decompiled_code:
__int64 timeout_protocol()
{
__int64 v0; // rax
__int64 v1; // r12
const char *v2; // rbp
__int64 v3; // rbx

v0 = get_first_protocol();
v1 = v0;
if ( v0 )
{
v2 = on_timeout;
v3 = v0;
while ( strcmp(*(const char **)v3, v2) )
{
v3 = *(_QWORD *)(v3 + 40);
if ( !v3 )
return v1;
}
v1 = v3;
}
return v1;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rax
__int64 v1; // r12
const char *v2; // rbp
__int64 v3; // rbx

v0 = func13();
v1 = v0;
if ( v0 )
{
v2 = on_timeout;
v3 = v0;
while ( strcmp(*(const char **)v3, v2) )
{
v3 = *(_QWORD *)(v3 + 40);
if ( !v3 )
return v1;
}
v1 = v3;
}
return v1;
}

original_code:
struct proto* timeout_protocol(void)
{
    struct proto* p = get_first_protocol();
    for (; p && strcmp(p->description, on_timeout); p = p->next);
    if (p) return p;
    return get_first_protocol();
}

canonical_original_code:
struct proto *timeout_protocol()
{
    struct proto *p = get_first_protocol();
    for (; p && strcmp(p->description, on_timeout); p = p->next);
    if (p) return p;
    return get_first_protocol();
}


decompiled_code:
void __fastcall set_protocol_list(__int64 a1)
{
protocols = a1;
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1)
{
protocols = a1;
}

original_code:
void set_protocol_list(struct proto* prots)
{
    protocols = prots;
}

canonical_original_code:
void set_protocol_list(struct proto *prots)
{
    protocols = prots;
}


hexdump

decompiled_code:
int __fastcall hexdump(__int64 a1, unsigned int a2)
{
int result; // eax
__int64 v3; // rbp
__int64 v4; // r15
int v5; // ebx
unsigned int v6; // ebx
int v7; // er13
const unsigned __int16 **v8; // rax
__int64 v9; // rdx

result = 16 - (a2 & 0xF);
if ( (a2 & 0xF) == 0 )
result = 0;
v3 = 0LL;
v4 = result + a2;
while ( v4 != v3 )
{
v5 = v3 & 0xF;
if ( (v3 & 0xF) == 0 )
printf("0x%06x: ", (unsigned int)v3);
if ( a2 > (unsigned int)v3 )
{
result = printf("%02x ", *(unsigned __int8 *)(a1 + v3));
if ( v5 != 15 )
goto LABEL_5;
}
else
{
result = printf(" ");
if ( v5 != 15 )
goto LABEL_5;
}
v6 = v3 - 15;
v7 = v3 + ((int)v3 + 1 < (unsigned int)(v3 - 14) ? 0xFFFFFFF1 : 0) + 1;
do
{
while ( 1 )
{
if ( a2 <= v6 )
{
putchar(32);
goto LABEL_13;
}
v8 = _ctype_b_loc();
v9 = *(char *)(a1 + v6);
if ( ((*v8)[v9] & 0x4000) == 0 )
break;
putchar((unsigned __int8)v9);
LABEL_13:
if ( v7 == ++v6 )
goto LABEL_17;
}
++v6;
putchar(46);
}
while ( v7 != v6 );
LABEL_17:
result = putchar(10);
LABEL_5:
++v3;
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, unsigned int a2)
{
int result; // eax
__int64 v3; // rbp
__int64 v4; // r15
int v5; // ebx
unsigned int v6; // ebx
int v7; // er13
const unsigned __int16 **v8; // rax
__int64 v9; // rdx

result = 16 - (a2 & 0xF);
if ( (a2 & 0xF) == 0 )
result = 0;
v3 = 0LL;
v4 = result + a2;
while ( v4 != v3 )
{
v5 = v3 & 0xF;
if ( (v3 & 0xF) == 0 )
printf("0x%06x: ", (unsigned int)v3);
if ( a2 > (unsigned int)v3 )
{
result = printf("%02x ", *(unsigned __int8 *)(a1 + v3));
if ( v5 != 15 )
goto LABEL_5;
}
else
{
result = printf(" ");
if ( v5 != 15 )
goto LABEL_5;
}
v6 = v3 - 15;
v7 = v3 + ((int)v3 + 1 < (unsigned int)(v3 - 14) ? 0xFFFFFFF1 : 0) + 1;
do
{
while ( 1 )
{
if ( a2 <= v6 )
{
putchar(32);
goto LABEL_13;
}
v8 = _ctype_b_loc();
v9 = *(char *)(a1 + v6);
if ( ((*v8)[v9] & 0x4000) == 0 )
break;
putchar((unsigned __int8)v9);
LABEL_13:
if ( v7 == ++v6 )
goto LABEL_17;
}
++v6;
putchar(46);
}
while ( v7 != v6 );
LABEL_17:
result = putchar(10);
LABEL_5:
++v3;
}
return result;
}

original_code:
void hexdump(const char *mem, unsigned int len)
{
    unsigned int i, j;
    for(i = 0; i < len + ((len % 16) ? (16 - len % 16) : 0); i++)
    {
        if(i % 16 == 0)
            printf("0x%06x: ", i);
        if(i < len)
            printf("%02x ", 0xFF & mem[i]);
        else
            printf("   ");
        if(i % 16 == (16 - 1)) {
            for(j = i - (16 - 1); j <= i; j++) {
                if(j >= len)
                    putchar(' ');
                else if(((*__ctype_b_loc ())[(int) ((mem[j]))] & (unsigned short int) _ISprint))
                    putchar(0xFF & mem[j]);
                else
                    putchar('.');
            }
            putchar('\n');
        }
    }
}

canonical_original_code:
void hexdump(char *mem, unsigned int len)
{
    unsigned int i; unsigned int j;
    for(i = 0; i < len + ((len % 16) ? (16 - len % 16) : 0); i++)
    {
        if(i % 16 == 0)
            printf("0x%06x: ", i);
        if(i < len)
            printf("%02x ", 0xFF & mem[i]);
        else
            printf("   ");
        if(i % 16 == (16 - 1)) {
            for(j = i - (16 - 1); j <= i; j++) {
                if(j >= len)
                    putchar(' ');
                else if(((*__ctype_b_loc ())[(int) ((mem[j]))] & (unsigned short) _ISprint))
                    putchar(0xFF & mem[j]);
                else
                    putchar('.');
            }
            putchar('\n');
        }
    }
}

variable_types:
mem
char *

variable_types:
len
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int


decompiled_code:
__int64 __fastcall probe_client_protocol(__int64 a1)
{
int v1; // eax
const char **v2; // r12
unsigned int v4; // ebx
const char *v5; // rax
_BYTE v6[8216]; // [rsp+0h] [rbp-2018h] BYREF

v1 = read(*(_DWORD *)(a1 + 16), v6, 0x2000uLL);
v2 = (const char **)protocols;
if ( v1 <= 0 || (v4 = v1, defer_write(a1 + 48, v6, (unsigned int)v1), (v2 = (const char **)protocols) == 0LL) )
{
LABEL_2:
if ( !verbose )
return (__int64)v2;
fprintf(stderr, "all probes failed, connecting to first protocol: %s\n", *v2);
return protocols;
}
while ( 1 )
{
v5 = v2[3];
if ( !v5 )
goto LABEL_7;
if ( verbose )
break;
if ( ((unsigned int (__fastcall *)(_BYTE *, _QWORD, const char **))v5)(v6, v4, v2) )
goto LABEL_11;
LABEL_7:
v2 = (const char **)v2[5];
if ( !v2 )
{
v2 = (const char **)protocols;
goto LABEL_2;
}
}
fprintf(stderr, "probing for %s\n", *v2);
if ( !((unsigned int (__fastcall *)(_BYTE *, _QWORD, const char **))v2[3])(v6, v4, v2) )
goto LABEL_7;
LABEL_11:
if ( verbose )
fprintf(stderr, "probe %s successful\n", *v2);
return (__int64)v2;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
int v1; // eax
const char **v2; // r12
unsigned int v4; // ebx
const char *v5; // rax
_BYTE v6[8216]; // [rsp+0h] [rbp-2018h] BYREF

v1 = read(*(_DWORD *)(a1 + 16), v6, 0x2000uLL);
v2 = (const char **)protocols;
if ( v1 <= 0 || (v4 = v1, defer_write(a1 + 48, v6, (unsigned int)v1), (v2 = (const char **)protocols) == 0LL) )
{
LABEL_2:
if ( !verbose )
return (__int64)v2;
fprintf(stderr, "all probes failed, connecting to first protocol: %s\n", *v2);
return protocols;
}
while ( 1 )
{
v5 = v2[3];
if ( !v5 )
goto LABEL_7;
if ( verbose )
break;
if ( ((unsigned int (__fastcall *)(_BYTE *, _QWORD, const char **))v5)(v6, v4, v2) )
goto LABEL_11;
LABEL_7:
v2 = (const char **)v2[5];
if ( !v2 )
{
v2 = (const char **)protocols;
goto LABEL_2;
}
}
fprintf(stderr, "probing for %s\n", *v2);
if ( !((unsigned int (__fastcall *)(_BYTE *, _QWORD, const char **))v2[3])(v6, v4, v2) )
goto LABEL_7;
LABEL_11:
if ( verbose )
fprintf(stderr, "probe %s successful\n", *v2);
return (__int64)v2;
}

original_code:
struct proto* probe_client_protocol(struct connection *cnx)
{
    char buffer[8192];
    struct proto *p;
    int n;
    n = read(cnx->q[0].fd, buffer, sizeof(buffer));
    if (n > 0) {
        defer_write(&cnx->q[1], buffer, n);
        for (p = protocols; p; p = p->next) {
            if (! p->probe) continue;
            if (verbose) fprintf(stderr, "probing for %s\n", p->description);
            if (p->probe(buffer, n, p)) {
                if (verbose) fprintf(stderr, "probe %s successful\n", p->description);
                return p;
            }
        }
    }
    if (verbose)
        fprintf(stderr,
                "all probes failed, connecting to first protocol: %s\n",
                protocols->description);
    return protocols;
}

canonical_original_code:
struct proto *probe_client_protocol(struct connection *cnx)
{
    char buffer[8192];
    struct proto *p;
    int n;
    n = read(cnx->q[0].fd, buffer, sizeof(buffer));
    if (n > 0) {
        defer_write(&cnx->q[1], buffer, n);
        for (p = protocols; p; p = p->next) {
            if (! p->probe) continue;
            if (verbose) fprintf(stderr, "probing for %s\n", p->description);
            if (p->probe(buffer, n, p)) {
                if (verbose) fprintf(stderr, "probe %s successful\n", p->description);
                return p;
            }
        }
    }
    if (verbose)
        fprintf(stderr,
                "all probes failed, connecting to first protocol: %s\n",
                protocols->description);
    return protocols;
}

variable_types: struct connection { enum connection_state { ST_PROBING=1, ST_SHOVELING=2 } state; long probe_timeout; struct queue { int fd; void *begin_defered_data; void *defered_data; int defered_data_size; } q[2]; } *

variable_types:
buffer
char [8192]

variable_types: struct proto { char *description; char *service; 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; } *saddr; int (*probe)(char *, int, struct proto *); void *data; struct proto *next; } *

variable_types: n int


decompiled_code:
void __fastcall stop_listeners(int sig)
{
__pid_t *v1; // rax
__int64 v2; // rbx
__int64 v3; // r12

if ( listener_pid_number > 0 )
{
v1 = (__pid_t *)listener_pid;
v2 = listener_pid + 4;
v3 = listener_pid + 4 + 4LL * (unsigned int)(listener_pid_number - 1);
while ( 1 )
{
kill(*v1, sig);
v1 = (__pid_t *)v2;
if ( v2 == v3 )
break;
v2 += 4LL;
}
}
}

canonical_decompiled_code:
void __fastcall func0(int sig)
{
__pid_t *v1; // rax
__int64 v2; // rbx
__int64 v3; // r12

if ( listener_pid_number > 0 )
{
v1 = (__pid_t *)listener_pid;
v2 = listener_pid + 4;
v3 = listener_pid + 4 + 4LL * (unsigned int)(listener_pid_number - 1);
while ( 1 )
{
kill(*v1, sig);
v1 = (__pid_t *)v2;
if ( v2 == v3 )
break;
v2 += 4LL;
}
}
}

original_code:
void stop_listeners(int sig)
{
    int i;
    for (i = 0; i < listener_pid_number; i++) {
        kill(listener_pid[i], sig);
    }
}

variable_types: sig int

variable_types: i int


shovel

original_code:
int shovel(struct connection *cnx)
{
   fd_set fds;
   int res, i;
   int max_fd = (((cnx->q[0].fd) > (cnx->q[1].fd)) ? (cnx->q[0].fd) : (cnx->q[1].fd)) + 1;
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
   while (1) {
      ((void) (((&fds)->fds_bits)[((cnx->q[0].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cnx->q[0].fd) % (8 * (int) sizeof (__fd_mask)))))));
      ((void) (((&fds)->fds_bits)[((cnx->q[1].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cnx->q[1].fd) % (8 * (int) sizeof (__fd_mask)))))));
      res = select(
                   max_fd,
                   &fds,
                   ((void *)0),
                   ((void *)0),
                   ((void *)0)
                  );
      if (res == -1) { perror("select"); exit(1); };
      for (i = 0; i < 2; i++) {
          if (((((&fds)->fds_bits)[((cnx->q[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cnx->q[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
              res = fd2fd(&cnx->q[1-i], &cnx->q[i]);
              if (!res) {
                  if (verbose)
                      fprintf(stderr, "%s %s", i ? "client" : "server", "socket closed\n");
                  return res;
              }
          }
      }
   }
}

canonical_original_code:
int shovel(struct connection *cnx)
{
   struct fd_set fds;
   int res; int i;
   int max_fd = (((cnx->q[0].fd) > (cnx->q[1].fd)) ? (cnx->q[0].fd) : (cnx->q[1].fd)) + 1;
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
   while (1) {
      ((void) (((&fds)->fds_bits)[((cnx->q[0].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cnx->q[0].fd) % (8 * (int) sizeof (__fd_mask)))))));
      ((void) (((&fds)->fds_bits)[((cnx->q[1].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cnx->q[1].fd) % (8 * (int) sizeof (__fd_mask)))))));
      res = select(
                   max_fd,
                   &fds,
                   ((void *)0),
                   ((void *)0),
                   ((void *)0)
                  );
      if (res == -1) { perror("select"); exit(1); };
      for (i = 0; i < 2; i++) {
          if (((((&fds)->fds_bits)[((cnx->q[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cnx->q[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
              res = fd2fd(&cnx->q[1-i], &cnx->q[i]);
              if (!res) {
                  if (verbose)
                      fprintf(stderr, "%s %s", i ? "client" : "server", "socket closed\n");
                  return res;
              }
          }
      }
   }
}

variable_types:
fds
struct fd_set { long fds_bits[-1]; }

variable_types: res int

user_defined_types: enum connection_state { ST_PROBING=1, ST_SHOVELING=2 }


decompiled_code:
void __fastcall __noreturn start_shoveler(int fd)
{
__int64 v1; // rbx
__time_t v2; // rax
__int64 v3; // r12
__fd_mask v4; // r12
_QWORD *v5; // rbx
__int64 v6; // r12
int v7; // eax
int v8; // er12
struct timeval v9; // [rsp+0h] [rbp-F8h] BYREF
char v10[16]; // [rsp+10h] [rbp-E8h] BYREF
int v11; // [rsp+20h] [rbp-D8h]
int v12[8]; // [rsp+40h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+60h] [rbp-98h] BYREF

init_cnx(v10);
memset(&readfds, 0, sizeof(readfds));
v9.tv_usec = 0LL;
v1 = fd / 64;
v2 = probing_timeout;
v3 = 1LL << (fd % 64);
readfds.fds_bits[v1] |= v3;
v9.tv_sec = v2;
if ( select(fd + 1, &readfds, 0LL, 0LL, &v9) == -1 )
perror("select");
v4 = readfds.fds_bits[v1] & v3;
v11 = fd;
if ( v4 )
v5 = (_QWORD *)probe_client_protocol(v10);
else
v5 = (_QWORD *)timeout_protocol();
v6 = v5[2];
if ( !v5[1] || !(unsigned int)check_access_rights((unsigned int)fd) )
{
v7 = connect_addr(v6, *v5);
v8 = v7;
if ( v7 == -1 )
{
perror("connect");
exit(1);
}
v12[0] = v7;
log_connection(v10);
flush_defered(v12);
shovel((__int64)v10);
close(fd);
close(v8);
if ( verbose )
fwrite("connection closed down\n", 1uLL, 0x17uLL, stderr);
}
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(int fd)
{
__int64 v1; // rbx
__time_t v2; // rax
__int64 v3; // r12
__fd_mask v4; // r12
_QWORD *v5; // rbx
__int64 v6; // r12
int v7; // eax
int v8; // er12
struct timeval v9; // [rsp+0h] [rbp-F8h] BYREF
char v10[16]; // [rsp+10h] [rbp-E8h] BYREF
int v11; // [rsp+20h] [rbp-D8h]
int v12[8]; // [rsp+40h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+60h] [rbp-98h] BYREF

init_cnx(v10);
memset(&readfds, 0, sizeof(readfds));
v9.tv_usec = 0LL;
v1 = fd / 64;
v2 = probing_timeout;
v3 = 1LL << (fd % 64);
readfds.fds_bits[v1] |= v3;
v9.tv_sec = v2;
if ( select(fd + 1, &readfds, 0LL, 0LL, &v9) == -1 )
perror("select");
v4 = readfds.fds_bits[v1] & v3;
v11 = fd;
if ( v4 )
v5 = (_QWORD *)probe_client_protocol(v10);
else
v5 = (_QWORD *)timeout_protocol();
v6 = v5[2];
if ( !v5[1] || !(unsigned int)check_access_rights((unsigned int)fd) )
{
v7 = connect_addr(v6, *v5);
v8 = v7;
if ( v7 == -1 )
{
perror("connect");
exit(1);
}
v12[0] = v7;
log_connection(v10);
flush_defered(v12);
func1((__int64)v10);
close(fd);
close(v8);
if ( verbose )
fwrite("connection closed down\n", 1uLL, 0x17uLL, stderr);
}
exit(0);
}

original_code:
void start_shoveler(int in_socket)
{
   fd_set fds;
   struct timeval tv;
   struct addrinfo *saddr;
   int res;
   int out_socket;
   struct connection cnx;
   struct proto *prot;
   init_cnx(&cnx);
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&fds)->fds_bits)[((in_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((in_socket) % (8 * (int) sizeof (__fd_mask)))))));
   memset(&tv, 0, sizeof(tv));
   tv.tv_sec = probing_timeout;
   res = select(in_socket + 1, &fds, ((void *)0), ((void *)0), &tv);
   if (res == -1)
      perror("select");
   cnx.q[0].fd = in_socket;
   if (((((&fds)->fds_bits)[((in_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((in_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
       prot = probe_client_protocol(&cnx);
   } else {
       prot = timeout_protocol();
   }
   saddr = prot->saddr;
   if (prot->service &&
       check_access_rights(in_socket, prot->service)) {
       exit(0);
   }
   out_socket = connect_addr(saddr, prot->description);
   if (out_socket == -1) { perror("connect"); exit(1); };
   cnx.q[1].fd = out_socket;
   log_connection(&cnx);
   flush_defered(&cnx.q[1]);
   shovel(&cnx);
   close(in_socket);
   close(out_socket);
   if (verbose)
      fprintf(stderr, "connection closed down\n");
   exit(0);
}

canonical_original_code:
void start_shoveler(int in_socket)
{
   struct fd_set fds;
   struct timeval tv;
   struct addrinfo *saddr;
   int res;
   int out_socket;
   struct connection cnx;
   struct proto *prot;
   init_cnx(&cnx);
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&fds)->fds_bits)[((in_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((in_socket) % (8 * (int) sizeof (__fd_mask)))))));
   memset(&tv, 0, sizeof(tv));
   tv.tv_sec = probing_timeout;
   res = select(in_socket + 1, &fds, ((void *)0), ((void *)0), &tv);
   if (res == -1)
      perror("select");
   cnx.q[0].fd = in_socket;
   if (((((&fds)->fds_bits)[((in_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((in_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
       prot = probe_client_protocol(&cnx);
   } else {
       prot = timeout_protocol();
   }
   saddr = prot->saddr;
   if (prot->service &&
       check_access_rights(in_socket, prot->service)) {
       exit(0);
   }
   out_socket = connect_addr(saddr, prot->description);
   if (out_socket == -1) { perror("connect"); exit(1); };
   cnx.q[1].fd = out_socket;
   log_connection(&cnx);
   flush_defered(&cnx.q[1]);
   shovel(&cnx);
   close(in_socket);
   close(out_socket);
   if (verbose)
      fprintf(stderr, "connection closed down\n");
   exit(0);
}

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

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: struct connection { enum connection_state { ST_PROBING=1, ST_SHOVELING=2 } state; long probe_timeout; struct queue { int fd; void *begin_defered_data; void *defered_data; int defered_data_size; } q[2]; }


decompiled_code:
__pid_t __fastcall main_loop(__int64 a1, int a2)
{
void *v2; // rax
__int64 v3; // rbp
__int64 i; // rbx
__pid_t v5; // eax
int *v7; // rbx
unsigned int v8; // ebp
struct sigaction v9; // [rsp+0h] [rbp-C8h] BYREF

listener_pid_number = a2;
v2 = malloc(4LL * a2);
listener_pid = (__int64)v2;
if ( a2 > 0 )
{
v3 = (__int64)v2;
for ( i = 0LL; ; i += 4LL )
{
v5 = fork();
*(_DWORD *)(v3 + i) = v5;
if ( !v5 )
{
v7 = (int *)(a1 + i);
while ( 1 )
{
v8 = accept(*v7, 0LL, 0LL);
if ( verbose )
fprintf(stderr, "accepted fd %d\n", v8);
if ( !fork() )
{
close(*v7);
start_shoveler(v8);
}
close(v8);
}
}
if ( 4LL * (unsigned int)(a2 - 1) == i )
break;
v3 = listener_pid;
}
}
v9.sa_handler = stop_listeners;
memset(&v9.sa_mask, 0, 0x90uLL);
if ( sigaction(15, &v9, 0LL) == -1 )
{
perror("sigaction");
exit(1);
}
return wait(0LL);
}

canonical_decompiled_code:
__pid_t __fastcall func3(__int64 a1, int a2)
{
void *v2; // rax
__int64 v3; // rbp
__int64 i; // rbx
__pid_t v5; // eax
int *v7; // rbx
unsigned int v8; // ebp
struct sigaction v9; // [rsp+0h] [rbp-C8h] BYREF

listener_pid_number = a2;
v2 = malloc(4LL * a2);
listener_pid = (__int64)v2;
if ( a2 > 0 )
{
v3 = (__int64)v2;
for ( i = 0LL; ; i += 4LL )
{
v5 = fork();
*(_DWORD *)(v3 + i) = v5;
if ( !v5 )
{
v7 = (int *)(a1 + i);
while ( 1 )
{
v8 = accept(*v7, 0LL, 0LL);
if ( verbose )
fprintf(stderr, "accepted fd %d\n", v8);
if ( !fork() )
{
close(*v7);
func2(v8);
}
close(v8);
}
}
if ( 4LL * (unsigned int)(a2 - 1) == i )
break;
v3 = listener_pid;
}
}
v9.sa_handler = stop_listeners;
memset(&v9.sa_mask, 0, 0x90uLL);
if ( sigaction(15, &v9, 0LL) == -1 )
{
perror("sigaction");
exit(1);
}
return wait(0LL);
}

original_code:
void main_loop(int listen_sockets[], int num_addr_listen)
{
    int in_socket, i, res;
    struct sigaction action;
    listener_pid_number = num_addr_listen;
    listener_pid = malloc(listener_pid_number * sizeof(listener_pid[0]));
    for (i = 0; i < num_addr_listen; i++) {
        if (!(listener_pid[i] = fork())) {
            while (1)
            {
                in_socket = accept(listen_sockets[i], 0, 0);
                if (verbose) fprintf(stderr, "accepted fd %d\n", in_socket);
                if (!fork())
                {
                    close(listen_sockets[i]);
                    start_shoveler(in_socket);
                    exit(0);
                }
                close(in_socket);
            }
        }
    }
    memset(&action, 0, sizeof(action));
    action.__sigaction_handler.sa_handler = stop_listeners;
    res = sigaction(15, &action, ((void *)0));
    if (res == -1) { perror("sigaction"); exit(1); };
    wait(((void *)0));
}

canonical_original_code:
void main_loop(int listen_sockets[], int num_addr_listen)
{
    int in_socket; int i; int res;
    struct sigaction action;
    listener_pid_number = num_addr_listen;
    listener_pid = malloc(listener_pid_number * sizeof(listener_pid[0]));
    for (i = 0; i < num_addr_listen; i++) {
        if (!(listener_pid[i] = fork())) {
            while (1)
            {
                in_socket = accept(listen_sockets[i], 0, 0);
                if (verbose) fprintf(stderr, "accepted fd %d\n", in_socket);
                if (!fork())
                {
                    close(listen_sockets[i]);
                    start_shoveler(in_socket);
                    exit(0);
                }
                close(in_socket);
            }
        }
    }
    memset(&action, 0, sizeof(action));
    action.__sigaction_handler.sa_handler = stop_listeners;
    res = sigaction(15, &action, ((void *)0));
    if (res == -1) { perror("sigaction"); exit(1); };
    wait(((void *)0));
}

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


freeMemory

repo: guillaumeBoufflers/malloc

decompiled_code:
int __fastcall freeMemory(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx

LODWORD(v1) = MALLOC_PTR_END;
if ( (_QWORD *)MALLOC_LIST != a1 || MALLOC_PTR_END )
{
if ( a1 == (_QWORD *)MALLOC_PTR_END )
{
v1 = (_QWORD *)a1[1];
if ( v1 )
{
v2 = v1[2];
*v1 = 0LL;
MALLOC_PTR_END = (__int64)v1;
LODWORD(v1) = brk((char *)v1 + v2 + 32);
}
}
}
else
{
LODWORD(v1) = brk(a1);
MALLOC_LIST = 0LL;
MALLOC_PTR_END = 0LL;
}
return (int)v1;
}

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

LODWORD(v1) = MALLOC_PTR_END;
if ( (_QWORD *)MALLOC_LIST != a1 || MALLOC_PTR_END )
{
if ( a1 == (_QWORD *)MALLOC_PTR_END )
{
v1 = (_QWORD *)a1[1];
if ( v1 )
{
v2 = v1[2];
*v1 = 0LL;
MALLOC_PTR_END = (__int64)v1;
LODWORD(v1) = brk((char *)v1 + v2 + 32);
}
}
}
else
{
LODWORD(v1) = brk(a1);
MALLOC_LIST = 0LL;
MALLOC_PTR_END = 0LL;
}
return (int)v1;
}

original_code:
static void freeMemory(t_malloc *tmp)
{
  if (tmp == MALLOC_LIST && !MALLOC_PTR_END)
    {
      brk(MALLOC_LIST);
      MALLOC_LIST = ((void *)0);
      MALLOC_PTR_END = ((void *)0);
    }
  else if (tmp == MALLOC_PTR_END && tmp->prev)
    {
      MALLOC_PTR_END = tmp->prev;
      MALLOC_PTR_END->next = ((void *)0);
      brk((void*)tmp->prev + MALLOC_BLOCK_SIZE + tmp->prev->size);
    }
}

canonical_original_code:
static void freeMemory(struct s_malloc *tmp)
{
  if (tmp == MALLOC_LIST && !MALLOC_PTR_END)
    {
      brk(MALLOC_LIST);
      MALLOC_LIST = ((void *)0);
      MALLOC_PTR_END = ((void *)0);
    }
  else if (tmp == MALLOC_PTR_END && tmp->prev)
    {
      MALLOC_PTR_END = tmp->prev;
      MALLOC_PTR_END->next = ((void *)0);
      brk((void *)tmp->prev + MALLOC_BLOCK_SIZE + tmp->prev->size);
    }
}

variable_types: struct s_malloc { struct s_malloc *next; struct s_malloc *prev; unsigned long size; char isFree; } *


malloc

decompiled_code:
char *__fastcall malloc(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // r12
_QWORD *v4; // r13
_QWORD *v5; // rax

v1 = (a1 - 1) & 0xFFFFFFFFFFFFFFFCLL;
pthread_mutex_lock(lock);
v2 = fitAllocatedSpace(v1 + 4);
if ( v2 )
return (char *)v2;
v4 = sbrk(0LL);
if ( sbrk(v1 + 36) == (void *)-1LL )
{
pthread_mutex_unlock(lock);
return (char *)v2;
}
v5 = (_QWORD *)MALLOC_PTR_END;
v4[2] = v1 + 4;
*((_BYTE *)v4 + 24) = 0;
*v4 = 0LL;
v4[1] = 0LL;
if ( v5 )
{
*v5 = v4;
v4[1] = v5;
}
else
{
MALLOC_LIST = (__int64)v4;
}
MALLOC_PTR_END = (__int64)v4;
pthread_mutex_unlock(lock);
return (char *)(v4 + 4);
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // r12
_QWORD *v4; // r13
_QWORD *v5; // rax

v1 = (a1 - 1) & 0xFFFFFFFFFFFFFFFCLL;
pthread_mutex_lock(lock);
v2 = func6(v1 + 4);
if ( v2 )
return (char *)v2;
v4 = sbrk(0LL);
if ( sbrk(v1 + 36) == (void *)-1LL )
{
pthread_mutex_unlock(lock);
return (char *)v2;
}
v5 = (_QWORD *)MALLOC_PTR_END;
v4[2] = v1 + 4;
*((_BYTE *)v4 + 24) = 0;
*v4 = 0LL;
v4[1] = 0LL;
if ( v5 )
{
*v5 = v4;
v4[1] = v5;
}
else
{
MALLOC_LIST = (__int64)v4;
}
MALLOC_PTR_END = (__int64)v4;
pthread_mutex_unlock(lock);
return (char *)(v4 + 4);
}

original_code:
void *malloc(size_t size)
{
  t_malloc *new;
  void *p;
  pthread_mutex_lock(&lock[0]);
  size = (((((size) -1)>>2)<<2)+4);
  if ((p = fitAllocatedSpace(size)) != ((void *)0))
    return (p);
  new = sbrk(0);
  if (sbrk(MALLOC_BLOCK_SIZE + size) == (void*) -1)
    {
      pthread_mutex_unlock(&lock[0]);
      return (((void *)0));
    }
  new->size = size;
  new->isFree = 0;
  new->next = ((void *)0);
  new->prev = ((void *)0);
  if (MALLOC_PTR_END == ((void *)0))
    MALLOC_LIST = new;
  else
    {
      MALLOC_PTR_END->next = new;
      new->prev = MALLOC_PTR_END;
    }
  MALLOC_PTR_END = new;
  pthread_mutex_unlock(&lock[0]);
  return ((void*)new + MALLOC_BLOCK_SIZE);
}

canonical_original_code:
void *malloc(unsigned long size)
{
  struct s_malloc *new;
  void *p;
  pthread_mutex_lock(&lock[0]);
  size = (((((size) -1)>>2)<<2)+4);
  if ((p = fitAllocatedSpace(size)) != ((void *)0))
    return (p);
  new = sbrk(0);
  if (sbrk(MALLOC_BLOCK_SIZE + size) == (void *) -1)
    {
      pthread_mutex_unlock(&lock[0]);
      return (((void *)0));
    }
  new->size = size;
  new->isFree = 0;
  new->next = ((void *)0);
  new->prev = ((void *)0);
  if (MALLOC_PTR_END == ((void *)0))
    MALLOC_LIST = new;
  else
    {
      MALLOC_PTR_END->next = new;
      new->prev = MALLOC_PTR_END;
    }
  MALLOC_PTR_END = new;
  pthread_mutex_unlock(&lock[0]);
  return ((void *)new + MALLOC_BLOCK_SIZE);
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *

user_defined_types: struct s_malloc { struct s_malloc *next; struct s_malloc *prev; unsigned long size; char isFree; }


calloc

decompiled_code:
void *__fastcall calloc(__int64 a1, __int64 a2)
{
return malloc(a2 * a1);
}

canonical_decompiled_code:
void *__fastcall func9(__int64 a1, __int64 a2)
{
return func8(a2 * a1);
}

original_code:
void *calloc(size_t nmemb, size_t size)
{
  return (malloc(nmemb * size));
}

canonical_original_code:
void *calloc(unsigned long nmemb, unsigned long size)
{
  return (malloc(nmemb * size));
}

variable_types:
nmemb
unsigned long